System.Data.SQLite
Check-in [98361f4a6b]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added interop project to streamlined build system. Updated SQLite to version 3.7.5. Fixed several warnings about unused local variables in extension-functions.c and interop.c. Group the source files by their origin (for clarity). Heavily revised the RC file for consistency and to centralize version information. Unfortunately, VS2008 / VS2010 use entirely different schemas for their property files; therefore, two sets of property files are required. Deleted the extraneous resource.h file.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 98361f4a6b461db098b6d98b02c81bc7e16b449f
User & Date: mistachkin 2011-02-26 10:21:50
Context
2011-02-26
10:24
Move RC file (missed in previous commit). check-in: 0e372ed8f9 user: mistachkin tags: trunk
10:21
Added interop project to streamlined build system. Updated SQLite to version 3.7.5. Fixed several warnings about unused local variables in extension-functions.c and interop.c. Group the source files by their origin (for clarity). Heavily revised the RC file for consistency and to centralize version information. Unfortunately, VS2008 / VS2010 use entirely different schemas for their property files; therefore, two sets of property files are required. Deleted the extraneous resource.h file. check-in: 98361f4a6b user: mistachkin tags: trunk
2011-02-17
08:41
Add test project to streamlined build system. Remove hard-coded supportedRuntime element from the test project app.config file as it is not necessary and prevents the test project from working correctly with the .NET Framework 2.0. Remove unnecessary using statements from test project. check-in: 921761a566 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Added SQLite.Interop/SQLite.Interop.2008.vcproj.

            1  +<?xml version="1.0" encoding="Windows-1252"?>
            2  +<!--
            3  + *
            4  + * SQLite.Interop.2008.vcproj -
            5  + *
            6  + * Written by Joe Mistachkin.
            7  + * Released to the public domain, use at your own risk!
            8  + *
            9  +-->
           10  +<VisualStudioProject
           11  +	ProjectType="Visual C++"
           12  +	Version="9.00"
           13  +	Name="SQLite.Interop"
           14  +	ProjectGUID="{53784BC1-A8BC-4AC8-8A3E-158D6807345A}"
           15  +	RootNamespace="SQLite.Interop"
           16  +	Keyword="Win32Proj"
           17  +	TargetFrameworkVersion="131072"
           18  +	>
           19  +	<Platforms>
           20  +		<Platform
           21  +			Name="Win32"
           22  +		/>
           23  +	</Platforms>
           24  +	<ToolFiles>
           25  +	</ToolFiles>
           26  +	<Configurations>
           27  +		<Configuration
           28  +			Name="Debug|Win32"
           29  +			OutputDirectory="$(ProjectDir)..\bin\$(PlatformName)\$(ConfigurationName)"
           30  +			IntermediateDirectory="..\obj\$(PlatformName)\$(ConfigurationName)"
           31  +			ConfigurationType="2"
           32  +			InheritedPropertySheets=".\props\sqlite3.vsprops;.\props\SQLite.Interop.vsprops"
           33  +			CharacterSet="1"
           34  +			>
           35  +			<Tool
           36  +				Name="VCPreBuildEventTool"
           37  +			/>
           38  +			<Tool
           39  +				Name="VCCustomBuildTool"
           40  +			/>
           41  +			<Tool
           42  +				Name="VCXMLDataGeneratorTool"
           43  +			/>
           44  +			<Tool
           45  +				Name="VCWebServiceProxyGeneratorTool"
           46  +			/>
           47  +			<Tool
           48  +				Name="VCMIDLTool"
           49  +			/>
           50  +			<Tool
           51  +				Name="VCCLCompilerTool"
           52  +				Optimization="0"
           53  +				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;$(SQLITE_COMMON_DEFINES);$(SQLITE_DEBUG_DEFINES)"
           54  +				MinimalRebuild="false"
           55  +				ExceptionHandling="0"
           56  +				BasicRuntimeChecks="0"
           57  +				RuntimeLibrary="3"
           58  +				UsePrecompiledHeader="0"
           59  +				BrowseInformation="1"
           60  +				WarningLevel="4"
           61  +				DebugInformationFormat="3"
           62  +				CompileAs="0"
           63  +				DisableSpecificWarnings="$(SQLITE_DISABLE_WARNINGS)"
           64  +			/>
           65  +			<Tool
           66  +				Name="VCManagedResourceCompilerTool"
           67  +			/>
           68  +			<Tool
           69  +				Name="VCResourceCompilerTool"
           70  +				PreprocessorDefinitions="_UNICODE;UNICODE;&quot;INTEROP_RC_VERSION=$(INTEROP_RC_VERSION)&quot;"
           71  +			/>
           72  +			<Tool
           73  +				Name="VCPreLinkEventTool"
           74  +			/>
           75  +			<Tool
           76  +				Name="VCLinkerTool"
           77  +				AdditionalOptions="/ASSEMBLYRESOURCE:$(INTEROP_ASSEMBLY_RESOURCES)"
           78  +				AdditionalDependencies="$(ProjectDir)..\bin\$(ConfigurationName)Module\bin\System.Data.SQLite.netmodule"
           79  +				Version="$(INTEROP_MANIFEST_VERSION)"
           80  +				LinkIncremental="1"
           81  +				ModuleDefinitionFile="src\core\sqlite3.def"
           82  +				GenerateDebugInformation="true"
           83  +				AssemblyDebug="1"
           84  +				GenerateMapFile="true"
           85  +				MapExports="true"
           86  +				SubSystem="2"
           87  +				OptimizeReferences="2"
           88  +				EnableCOMDATFolding="2"
           89  +				LinkTimeCodeGeneration="1"
           90  +				TargetMachine="1"
           91  +				CLRUnmanagedCodeCheck="true"
           92  +				KeyFile="$(INTEROP_KEY_FILE)"
           93  +			/>
           94  +			<Tool
           95  +				Name="VCALinkTool"
           96  +			/>
           97  +			<Tool
           98  +				Name="VCManifestTool"
           99  +				VerboseOutput="true"
          100  +				AssemblyIdentity="$(ProjectName), processorArchitecture=x86, version=$(INTEROP_MANIFEST_VERSION), type=win32"
          101  +				UpdateFileHashes="true"
          102  +			/>
          103  +			<Tool
          104  +				Name="VCXDCMakeTool"
          105  +			/>
          106  +			<Tool
          107  +				Name="VCBscMakeTool"
          108  +			/>
          109  +			<Tool
          110  +				Name="VCFxCopTool"
          111  +			/>
          112  +			<Tool
          113  +				Name="VCAppVerifierTool"
          114  +			/>
          115  +			<Tool
          116  +				Name="VCPostBuildEventTool"
          117  +			/>
          118  +		</Configuration>
          119  +		<Configuration
          120  +			Name="Release|Win32"
          121  +			OutputDirectory="$(ProjectDir)..\bin\$(PlatformName)\$(ConfigurationName)"
          122  +			IntermediateDirectory="..\obj\$(PlatformName)\$(ConfigurationName)"
          123  +			ConfigurationType="2"
          124  +			InheritedPropertySheets=".\props\sqlite3.vsprops;.\props\SQLite.Interop.vsprops"
          125  +			CharacterSet="1"
          126  +			WholeProgramOptimization="1"
          127  +			>
          128  +			<Tool
          129  +				Name="VCPreBuildEventTool"
          130  +			/>
          131  +			<Tool
          132  +				Name="VCCustomBuildTool"
          133  +			/>
          134  +			<Tool
          135  +				Name="VCXMLDataGeneratorTool"
          136  +			/>
          137  +			<Tool
          138  +				Name="VCWebServiceProxyGeneratorTool"
          139  +			/>
          140  +			<Tool
          141  +				Name="VCMIDLTool"
          142  +			/>
          143  +			<Tool
          144  +				Name="VCCLCompilerTool"
          145  +				Optimization="3"
          146  +				EnableIntrinsicFunctions="true"
          147  +				FavorSizeOrSpeed="1"
          148  +				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;$(SQLITE_COMMON_DEFINES)"
          149  +				StringPooling="true"
          150  +				ExceptionHandling="0"
          151  +				RuntimeLibrary="2"
          152  +				UsePrecompiledHeader="0"
          153  +				BrowseInformation="1"
          154  +				WarningLevel="4"
          155  +				DebugInformationFormat="3"
          156  +				CompileAs="0"
          157  +				DisableSpecificWarnings="$(SQLITE_DISABLE_WARNINGS)"
          158  +			/>
          159  +			<Tool
          160  +				Name="VCManagedResourceCompilerTool"
          161  +			/>
          162  +			<Tool
          163  +				Name="VCResourceCompilerTool"
          164  +				PreprocessorDefinitions="_UNICODE;UNICODE;&quot;INTEROP_RC_VERSION=$(INTEROP_RC_VERSION)&quot;"
          165  +			/>
          166  +			<Tool
          167  +				Name="VCPreLinkEventTool"
          168  +			/>
          169  +			<Tool
          170  +				Name="VCLinkerTool"
          171  +				AdditionalOptions="/ASSEMBLYRESOURCE:$(INTEROP_ASSEMBLY_RESOURCES)"
          172  +				AdditionalDependencies="$(ProjectDir)..\bin\$(ConfigurationName)Module\bin\System.Data.SQLite.netmodule"
          173  +				Version="$(INTEROP_MANIFEST_VERSION)"
          174  +				LinkIncremental="1"
          175  +				ModuleDefinitionFile="src\core\sqlite3.def"
          176  +				GenerateDebugInformation="true"
          177  +				GenerateMapFile="true"
          178  +				MapExports="true"
          179  +				SubSystem="2"
          180  +				LargeAddressAware="0"
          181  +				OptimizeReferences="2"
          182  +				EnableCOMDATFolding="2"
          183  +				LinkTimeCodeGeneration="1"
          184  +				TargetMachine="1"
          185  +				CLRUnmanagedCodeCheck="true"
          186  +				KeyFile="$(INTEROP_KEY_FILE)"
          187  +			/>
          188  +			<Tool
          189  +				Name="VCALinkTool"
          190  +			/>
          191  +			<Tool
          192  +				Name="VCManifestTool"
          193  +				VerboseOutput="true"
          194  +				AssemblyIdentity="$(ProjectName), processorArchitecture=x86, version=$(INTEROP_MANIFEST_VERSION), type=win32"
          195  +				UpdateFileHashes="true"
          196  +			/>
          197  +			<Tool
          198  +				Name="VCXDCMakeTool"
          199  +			/>
          200  +			<Tool
          201  +				Name="VCBscMakeTool"
          202  +			/>
          203  +			<Tool
          204  +				Name="VCFxCopTool"
          205  +			/>
          206  +			<Tool
          207  +				Name="VCAppVerifierTool"
          208  +			/>
          209  +			<Tool
          210  +				Name="VCPostBuildEventTool"
          211  +			/>
          212  +		</Configuration>
          213  +	</Configurations>
          214  +	<References>
          215  +	</References>
          216  +	<Files>
          217  +		<Filter
          218  +			Name="Source Files"
          219  +			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
          220  +			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
          221  +			>
          222  +			<File
          223  +				RelativePath=".\src\win\AssemblyInfo.cpp"
          224  +				>
          225  +				<FileConfiguration
          226  +					Name="Debug|Win32"
          227  +					ExcludedFromBuild="true"
          228  +					>
          229  +					<Tool
          230  +						Name="VCCLCompilerTool"
          231  +					/>
          232  +				</FileConfiguration>
          233  +				<FileConfiguration
          234  +					Name="Release|Win32"
          235  +					ExcludedFromBuild="true"
          236  +					>
          237  +					<Tool
          238  +						Name="VCCLCompilerTool"
          239  +					/>
          240  +				</FileConfiguration>
          241  +			</File>
          242  +			<File
          243  +				RelativePath=".\src\win\crypt.c"
          244  +				>
          245  +				<FileConfiguration
          246  +					Name="Debug|Win32"
          247  +					ExcludedFromBuild="true"
          248  +					>
          249  +					<Tool
          250  +						Name="VCCLCompilerTool"
          251  +					/>
          252  +				</FileConfiguration>
          253  +				<FileConfiguration
          254  +					Name="Release|Win32"
          255  +					ExcludedFromBuild="true"
          256  +					>
          257  +					<Tool
          258  +						Name="VCCLCompilerTool"
          259  +					/>
          260  +				</FileConfiguration>
          261  +			</File>
          262  +			<File
          263  +				RelativePath=".\src\contrib\extension-functions.c"
          264  +				>
          265  +				<FileConfiguration
          266  +					Name="Debug|Win32"
          267  +					ExcludedFromBuild="true"
          268  +					>
          269  +					<Tool
          270  +						Name="VCCLCompilerTool"
          271  +					/>
          272  +				</FileConfiguration>
          273  +				<FileConfiguration
          274  +					Name="Release|Win32"
          275  +					ExcludedFromBuild="true"
          276  +					>
          277  +					<Tool
          278  +						Name="VCCLCompilerTool"
          279  +					/>
          280  +				</FileConfiguration>
          281  +			</File>
          282  +			<File
          283  +				RelativePath=".\src\win\interop.c"
          284  +				>
          285  +			</File>
          286  +			<File
          287  +				RelativePath=".\src\core\sqlite3.c"
          288  +				>
          289  +				<FileConfiguration
          290  +					Name="Debug|Win32"
          291  +					ExcludedFromBuild="true"
          292  +					>
          293  +					<Tool
          294  +						Name="VCCLCompilerTool"
          295  +					/>
          296  +				</FileConfiguration>
          297  +				<FileConfiguration
          298  +					Name="Release|Win32"
          299  +					ExcludedFromBuild="true"
          300  +					>
          301  +					<Tool
          302  +						Name="VCCLCompilerTool"
          303  +					/>
          304  +				</FileConfiguration>
          305  +			</File>
          306  +			<File
          307  +				RelativePath=".\src\core\sqlite3.def"
          308  +				>
          309  +			</File>
          310  +		</Filter>
          311  +		<Filter
          312  +			Name="Header Files"
          313  +			Filter="h;hpp;hxx;hm;inl;inc;xsd"
          314  +			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
          315  +			>
          316  +			<File
          317  +				RelativePath=".\src\core\sqlite3.h"
          318  +				>
          319  +			</File>
          320  +			<File
          321  +				RelativePath=".\src\core\sqlite3ext.h"
          322  +				>
          323  +			</File>
          324  +		</Filter>
          325  +		<Filter
          326  +			Name="Resource Files"
          327  +			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
          328  +			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
          329  +			>
          330  +			<File
          331  +				RelativePath=".\src\win\SQLite.Interop.rc"
          332  +				>
          333  +			</File>
          334  +			<File
          335  +				RelativePath="..\System.Data.SQLite\SR.resx"
          336  +				>
          337  +				<FileConfiguration
          338  +					Name="Debug|Win32"
          339  +					>
          340  +					<Tool
          341  +						Name="VCManagedResourceCompilerTool"
          342  +						ResourceFileName="$(IntDir)\System.Data.SQLite.$(InputName).resources"
          343  +					/>
          344  +				</FileConfiguration>
          345  +				<FileConfiguration
          346  +					Name="Release|Win32"
          347  +					>
          348  +					<Tool
          349  +						Name="VCManagedResourceCompilerTool"
          350  +						ResourceFileName="$(IntDir)\System.Data.SQLite.$(InputName).resources"
          351  +					/>
          352  +				</FileConfiguration>
          353  +			</File>
          354  +		</Filter>
          355  +	</Files>
          356  +	<Globals>
          357  +	</Globals>
          358  +</VisualStudioProject>

Added SQLite.Interop/SQLite.Interop.2010.vcxproj.filters.

            1  +<?xml version="1.0" encoding="utf-8"?>
            2  +<!--
            3  + *
            4  + * SQLite.Interop.2010.vcxproj.filters -
            5  + *
            6  + * Written by Joe Mistachkin.
            7  + * Released to the public domain, use at your own risk!
            8  + *
            9  +-->
           10  +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
           11  +  <ItemGroup>
           12  +    <Filter Include="Source Files">
           13  +      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
           14  +      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
           15  +    </Filter>
           16  +    <Filter Include="Header Files">
           17  +      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
           18  +      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
           19  +    </Filter>
           20  +    <Filter Include="Resource Files">
           21  +      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
           22  +      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
           23  +    </Filter>
           24  +  </ItemGroup>
           25  +  <ItemGroup>
           26  +    <ClCompile Include="src\core\sqlite3.c">
           27  +      <Filter>Source Files</Filter>
           28  +    </ClCompile>
           29  +  </ItemGroup>
           30  +  <ItemGroup>
           31  +    <None Include="src\core\sqlite3.def">
           32  +      <Filter>Source Files</Filter>
           33  +    </None>
           34  +  </ItemGroup>
           35  +  <ItemGroup>
           36  +    <ClInclude Include="src\core\sqlite3.h">
           37  +      <Filter>Header Files</Filter>
           38  +    </ClInclude>
           39  +    <ClInclude Include="src\core\sqlite3ext.h">
           40  +      <Filter>Header Files</Filter>
           41  +    </ClInclude>
           42  +  </ItemGroup>
           43  +  <ItemGroup>
           44  +    <ResourceCompile Include="src\win\SQLite.Interop.rc">
           45  +      <Filter>Resource Files</Filter>
           46  +    </ResourceCompile>
           47  +  </ItemGroup>
           48  +</Project>

Changes to SQLite.Interop/SQLite.Interop.vcproj.

    20     20   	</ToolFiles>
    21     21   	<Configurations>
    22     22   		<Configuration
    23     23   			Name="Release|Win32"
    24     24   			OutputDirectory="$(ConfigurationName)"
    25     25   			IntermediateDirectory="$(ConfigurationName)"
    26     26   			ConfigurationType="2"
           27  +			InheritedPropertySheets=".\props\sqlite3.vsprops;.\props\SQLite.Interop.vsprops"
    27     28   			CharacterSet="2"
    28     29   			ManagedExtensions="0"
    29     30   			WholeProgramOptimization="1"
    30     31   			>
    31     32   			<Tool
    32     33   				Name="VCPreBuildEventTool"
    33     34   				CommandLine=""
................................................................................
    55     56   			/>
    56     57   			<Tool
    57     58   				Name="VCManagedResourceCompilerTool"
    58     59   				ResourceFileName="$(IntDir)\System.Data.SQLite.$(InputName).resources"
    59     60   			/>
    60     61   			<Tool
    61     62   				Name="VCResourceCompilerTool"
           63  +				PreprocessorDefinitions="&quot;INTEROP_RC_VERSION=$(INTEROP_RC_VERSION)&quot;"
    62     64   			/>
    63     65   			<Tool
    64     66   				Name="VCPreLinkEventTool"
    65     67   			/>
    66     68   			<Tool
    67     69   				Name="VCLinkerTool"
    68     70   				AdditionalOptions="/ASSEMBLYRESOURCE:..\System.Data.SQLite\SQLiteCommand.bmp,System.Data.SQLite.SQLiteCommand.bmp&#x0D;&#x0A;/ASSEMBLYRESOURCE:..\System.Data.SQLite\SQLiteConnection.bmp,System.Data.SQLite.SQLiteConnection.bmp&#x0D;&#x0A;/ASSEMBLYRESOURCE:..\System.Data.SQLite\SQLiteDataAdapter.bmp,System.Data.SQLite.SQLiteDataAdapter.bmp"
................................................................................
   105    107   			/>
   106    108   		</Configuration>
   107    109   		<Configuration
   108    110   			Name="Release|x64"
   109    111   			OutputDirectory="x64\$(ConfigurationName)"
   110    112   			IntermediateDirectory="x64\$(ConfigurationName)"
   111    113   			ConfigurationType="2"
          114  +			InheritedPropertySheets=".\props\sqlite3.vsprops;.\props\SQLite.Interop.vsprops"
   112    115   			CharacterSet="2"
   113    116   			ManagedExtensions="0"
   114    117   			WholeProgramOptimization="1"
   115    118   			>
   116    119   			<Tool
   117    120   				Name="VCPreBuildEventTool"
   118    121   				CommandLine=""
................................................................................
   144    147   			/>
   145    148   			<Tool
   146    149   				Name="VCManagedResourceCompilerTool"
   147    150   				ResourceFileName="$(IntDir)\System.Data.SQLite.$(InputName).resources"
   148    151   			/>
   149    152   			<Tool
   150    153   				Name="VCResourceCompilerTool"
          154  +				PreprocessorDefinitions="&quot;INTEROP_RC_VERSION=$(INTEROP_RC_VERSION)&quot;"
   151    155   			/>
   152    156   			<Tool
   153    157   				Name="VCPreLinkEventTool"
   154    158   			/>
   155    159   			<Tool
   156    160   				Name="VCLinkerTool"
   157    161   				AdditionalOptions="/ASSEMBLYRESOURCE:..\System.Data.SQLite\SQLiteCommand.bmp,System.Data.SQLite.SQLiteCommand.bmp&#x0D;&#x0A;/ASSEMBLYRESOURCE:..\System.Data.SQLite\SQLiteConnection.bmp,System.Data.SQLite.SQLiteConnection.bmp&#x0D;&#x0A;/ASSEMBLYRESOURCE:..\System.Data.SQLite\SQLiteDataAdapter.bmp,System.Data.SQLite.SQLiteDataAdapter.bmp"
................................................................................
   192    196   			/>
   193    197   		</Configuration>
   194    198   		<Configuration
   195    199   			Name="Debug|Win32"
   196    200   			OutputDirectory="$(ConfigurationName)"
   197    201   			IntermediateDirectory="$(ConfigurationName)"
   198    202   			ConfigurationType="2"
          203  +			InheritedPropertySheets=".\props\sqlite3.vsprops;.\props\SQLite.Interop.vsprops"
   199    204   			CharacterSet="2"
   200    205   			ManagedExtensions="0"
   201    206   			WholeProgramOptimization="0"
   202    207   			>
   203    208   			<Tool
   204    209   				Name="VCPreBuildEventTool"
   205    210   				CommandLine=""
................................................................................
   227    232   				DebugInformationFormat="3"
   228    233   			/>
   229    234   			<Tool
   230    235   				Name="VCManagedResourceCompilerTool"
   231    236   			/>
   232    237   			<Tool
   233    238   				Name="VCResourceCompilerTool"
          239  +				PreprocessorDefinitions="&quot;INTEROP_RC_VERSION=$(INTEROP_RC_VERSION)&quot;"
   234    240   			/>
   235    241   			<Tool
   236    242   				Name="VCPreLinkEventTool"
   237    243   			/>
   238    244   			<Tool
   239    245   				Name="VCLinkerTool"
   240    246   				OutputFile="../bin/$(InputName).DLL"
................................................................................
   270    276   			/>
   271    277   		</Configuration>
   272    278   		<Configuration
   273    279   			Name="Debug|x64"
   274    280   			OutputDirectory="$(PlatformName)\$(ConfigurationName)"
   275    281   			IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
   276    282   			ConfigurationType="2"
          283  +			InheritedPropertySheets=".\props\sqlite3.vsprops;.\props\SQLite.Interop.vsprops"
   277    284   			CharacterSet="2"
   278    285   			ManagedExtensions="0"
   279    286   			WholeProgramOptimization="0"
   280    287   			>
   281    288   			<Tool
   282    289   				Name="VCPreBuildEventTool"
   283    290   				CommandLine=""
................................................................................
   305    312   				DebugInformationFormat="3"
   306    313   			/>
   307    314   			<Tool
   308    315   				Name="VCManagedResourceCompilerTool"
   309    316   			/>
   310    317   			<Tool
   311    318   				Name="VCResourceCompilerTool"
          319  +				PreprocessorDefinitions="&quot;INTEROP_RC_VERSION=$(INTEROP_RC_VERSION)&quot;"
   312    320   			/>
   313    321   			<Tool
   314    322   				Name="VCPreLinkEventTool"
   315    323   			/>
   316    324   			<Tool
   317    325   				Name="VCLinkerTool"
   318    326   				OutputFile="../bin/x64/$(InputName).DLL"
................................................................................
   350    358   			/>
   351    359   		</Configuration>
   352    360   		<Configuration
   353    361   			Name="StockDebug|Win32"
   354    362   			OutputDirectory="$(ConfigurationName)"
   355    363   			IntermediateDirectory="$(ConfigurationName)"
   356    364   			ConfigurationType="2"
          365  +			InheritedPropertySheets=".\props\sqlite3.vsprops;.\props\SQLite.Interop.vsprops"
   357    366   			CharacterSet="2"
   358    367   			ManagedExtensions="0"
   359    368   			WholeProgramOptimization="0"
   360    369   			>
   361    370   			<Tool
   362    371   				Name="VCPreBuildEventTool"
   363    372   				CommandLine=""
................................................................................
   384    393   				DebugInformationFormat="3"
   385    394   			/>
   386    395   			<Tool
   387    396   				Name="VCManagedResourceCompilerTool"
   388    397   			/>
   389    398   			<Tool
   390    399   				Name="VCResourceCompilerTool"
          400  +				PreprocessorDefinitions="&quot;INTEROP_RC_VERSION=$(INTEROP_RC_VERSION)&quot;"
   391    401   			/>
   392    402   			<Tool
   393    403   				Name="VCPreLinkEventTool"
   394    404   			/>
   395    405   			<Tool
   396    406   				Name="VCLinkerTool"
   397    407   				OutputFile="../bin/sqlite3.dll"
................................................................................
   431    441   			/>
   432    442   		</Configuration>
   433    443   		<Configuration
   434    444   			Name="StockDebug|x64"
   435    445   			OutputDirectory="$(PlatformName)\$(ConfigurationName)"
   436    446   			IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
   437    447   			ConfigurationType="2"
          448  +			InheritedPropertySheets=".\props\sqlite3.vsprops;.\props\SQLite.Interop.vsprops"
   438    449   			CharacterSet="2"
   439    450   			ManagedExtensions="0"
   440    451   			WholeProgramOptimization="0"
   441    452   			>
   442    453   			<Tool
   443    454   				Name="VCPreBuildEventTool"
   444    455   				CommandLine=""
................................................................................
   466    477   				DebugInformationFormat="3"
   467    478   			/>
   468    479   			<Tool
   469    480   				Name="VCManagedResourceCompilerTool"
   470    481   			/>
   471    482   			<Tool
   472    483   				Name="VCResourceCompilerTool"
          484  +				PreprocessorDefinitions="&quot;INTEROP_RC_VERSION=$(INTEROP_RC_VERSION)&quot;"
   473    485   			/>
   474    486   			<Tool
   475    487   				Name="VCPreLinkEventTool"
   476    488   			/>
   477    489   			<Tool
   478    490   				Name="VCLinkerTool"
   479    491   				OutputFile="../bin/x64/$(InputName).DLL"
................................................................................
   516    528   	<Files>
   517    529   		<Filter
   518    530   			Name="Header Files"
   519    531   			Filter="h;hpp;hxx;hm;inl;inc;xsd"
   520    532   			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
   521    533   			>
   522    534   			<File
   523         -				RelativePath=".\resource.h"
   524         -				>
   525         -			</File>
   526         -			<File
   527         -				RelativePath=".\src\sqlite3.h"
          535  +				RelativePath=".\src\core\sqlite3.h"
   528    536   				>
   529    537   			</File>
   530    538   		</Filter>
   531    539   		<Filter
   532    540   			Name="Extras"
   533    541   			>
   534    542   			<File
   535         -				RelativePath=".\interop.c"
          543  +				RelativePath=".\src\win\interop.c"
   536    544   				>
   537    545   			</File>
   538    546   		</Filter>
   539    547   		<Filter
   540    548   			Name="Managed Resources"
   541    549   			>
   542    550   			<File
................................................................................
   592    600   				</FileConfiguration>
   593    601   			</File>
   594    602   		</Filter>
   595    603   		<Filter
   596    604   			Name="Resources"
   597    605   			>
   598    606   			<File
   599         -				RelativePath=".\SQLite.Interop.rc"
          607  +				RelativePath=".\src\win\SQLite.Interop.rc"
   600    608   				>
   601    609   			</File>
   602    610   		</Filter>
   603    611   	</Files>
   604    612   	<Globals>
   605    613   	</Globals>
   606    614   </VisualStudioProject>

Changes to SQLite.Interop/SQLite.Interop.vcxproj.

    65     65     <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    66     66       <ConfigurationType>DynamicLibrary</ConfigurationType>
    67     67       <CharacterSet>MultiByte</CharacterSet>
    68     68       <CLRSupport>false</CLRSupport>
    69     69       <WholeProgramOptimization>true</WholeProgramOptimization>
    70     70     </PropertyGroup>
    71     71     <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
           72  +  <Import Project="props\sqlite3.props" />
           73  +  <Import Project="props\SQLite.Interop.props" />
    72     74     <ImportGroup Label="ExtensionSettings">
    73     75     </ImportGroup>
    74     76     <ImportGroup Condition="'$(Configuration)|$(Platform)'=='StockDebug|Win32'" Label="PropertySheets">
    75     77       <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    76     78     </ImportGroup>
    77     79     <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
    78     80       <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
................................................................................
   156    158       <Link>
   157    159         <AdditionalOptions>/ASSEMBLYRESOURCE:..\System.Data.SQLite\SQLiteCommand.bmp,System.Data.SQLite.SQLiteCommand.bmp
   158    160   /ASSEMBLYRESOURCE:..\System.Data.SQLite\SQLiteConnection.bmp,System.Data.SQLite.SQLiteConnection.bmp
   159    161   /ASSEMBLYRESOURCE:..\System.Data.SQLite\SQLiteDataAdapter.bmp,System.Data.SQLite.SQLiteDataAdapter.bmp %(AdditionalOptions)</AdditionalOptions>
   160    162         <AdditionalDependencies>..\System.Data.SQLite\bin\System.Data.SQLite.netmodule;%(AdditionalDependencies)</AdditionalDependencies>
   161    163         <OutputFile>../bin/System.Data.SQLite.DLL</OutputFile>
   162    164         <IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
   163         -      <ModuleDefinitionFile>src\sqlite3.def</ModuleDefinitionFile>
          165  +      <ModuleDefinitionFile>src\core\sqlite3.def</ModuleDefinitionFile>
   164    166         <EmbedManagedResourceFile>%(EmbedManagedResourceFile)</EmbedManagedResourceFile>
   165    167         <DelayLoadDLLs>advapi32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
   166    168         <RandomizedBaseAddress>false</RandomizedBaseAddress>
   167    169         <DataExecutionPrevention>
   168    170         </DataExecutionPrevention>
   169    171         <ImportLibrary>
   170    172         </ImportLibrary>
................................................................................
   172    174         <KeyFile>..\System.Data.SQLite\System.Data.SQLite.snk</KeyFile>
   173    175         <CLRUnmanagedCodeCheck>true</CLRUnmanagedCodeCheck>
   174    176         <DelaySign>true</DelaySign>
   175    177       </Link>
   176    178       <PostBuildEvent>
   177    179         <Command>"$(FrameworkSDKDir)Bin\sn.exe" -R "$(TargetPath)" "$(SolutionDir)System.Data.SQLite\System.Data.SQLite.snk"</Command>
   178    180       </PostBuildEvent>
          181  +    <ResourceCompile>
          182  +      <PreprocessorDefinitions>&quot;INTEROP_RC_VERSION=$(INTEROP_RC_VERSION)&quot;</PreprocessorDefinitions>
          183  +    </ResourceCompile>
   179    184     </ItemDefinitionGroup>
   180    185     <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
   181    186       <PreBuildEvent>
   182    187         <Command>
   183    188         </Command>
   184    189       </PreBuildEvent>
   185    190       <Midl>
................................................................................
   202    207       </EmbeddedResource>
   203    208       <Link>
   204    209         <AdditionalOptions>/ASSEMBLYRESOURCE:..\System.Data.SQLite\SQLiteCommand.bmp,System.Data.SQLite.SQLiteCommand.bmp
   205    210   /ASSEMBLYRESOURCE:..\System.Data.SQLite\SQLiteConnection.bmp,System.Data.SQLite.SQLiteConnection.bmp
   206    211   /ASSEMBLYRESOURCE:..\System.Data.SQLite\SQLiteDataAdapter.bmp,System.Data.SQLite.SQLiteDataAdapter.bmp %(AdditionalOptions)</AdditionalOptions>
   207    212         <AdditionalDependencies>..\System.Data.SQLite\bin\System.Data.SQLite.netmodule;%(AdditionalDependencies)</AdditionalDependencies>
   208    213         <OutputFile>../bin/x64/System.Data.SQLite.DLL</OutputFile>
   209         -      <ModuleDefinitionFile>src\sqlite3.def</ModuleDefinitionFile>
          214  +      <ModuleDefinitionFile>src\core\sqlite3.def</ModuleDefinitionFile>
   210    215         <EmbedManagedResourceFile>%(EmbedManagedResourceFile)</EmbedManagedResourceFile>
   211    216         <DelayLoadDLLs>advapi32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
   212    217         <RandomizedBaseAddress>false</RandomizedBaseAddress>
   213    218         <DataExecutionPrevention>
   214    219         </DataExecutionPrevention>
   215    220         <ImportLibrary>
   216    221         </ImportLibrary>
................................................................................
   234    239         <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;NO_TCL;THREADSAFE=1;SQLITE_HAS_CODEC;SQLITE_ENABLE_COLUMN_METADATA;SQLITE_ENABLE_FTS3;SQLITE_ENABLE_RTREE;SQLITE_ENABLE_LOAD_EXTENSION;SQLITE_SOUNDEX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
   235    240         <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
   236    241         <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
   237    242         <RuntimeTypeInfo>false</RuntimeTypeInfo>
   238    243         <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
   239    244       </ClCompile>
   240    245       <Link>
   241         -      <ModuleDefinitionFile>src\sqlite3.def</ModuleDefinitionFile>
          246  +      <ModuleDefinitionFile>src\core\sqlite3.def</ModuleDefinitionFile>
   242    247         <EmbedManagedResourceFile>%(EmbedManagedResourceFile)</EmbedManagedResourceFile>
   243    248         <DelayLoadDLLs>advapi32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
   244    249         <GenerateDebugInformation>true</GenerateDebugInformation>
   245    250         <ImportLibrary>
   246    251         </ImportLibrary>
   247    252       </Link>
   248    253       <PostBuildEvent>
   249    254         <Command>"$(FrameworkSDKDir)Bin\sn.exe" -R "$(TargetPath)" "$(SolutionDir)System.Data.SQLite\System.Data.SQLite.snk"</Command>
   250    255       </PostBuildEvent>
          256  +    <ResourceCompile>
          257  +      <PreprocessorDefinitions>&quot;INTEROP_RC_VERSION=$(INTEROP_RC_VERSION)&quot;</PreprocessorDefinitions>
          258  +    </ResourceCompile>
   251    259     </ItemDefinitionGroup>
   252    260     <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
   253    261       <PreBuildEvent>
   254    262         <Command>
   255    263         </Command>
   256    264       </PreBuildEvent>
   257    265       <Midl>
................................................................................
   263    271         <PreprocessorDefinitions>SQLITE_DEBUG;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;NO_TCL;THREADSAFE=1;WIN64;SQLITE_HAS_CODEC;SQLITE_ENABLE_COLUMN_METADATA;SQLITE_ENABLE_FTS3;SQLITE_ENABLE_RTREE;SQLITE_ENABLE_LOAD_EXTENSION;SQLITE_SOUNDEX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
   264    272         <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
   265    273         <RuntimeTypeInfo>false</RuntimeTypeInfo>
   266    274         <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
   267    275       </ClCompile>
   268    276       <Link>
   269    277         <OutputFile>../bin/x64/$(ProjectName).DLL</OutputFile>
   270         -      <ModuleDefinitionFile>src\sqlite3.def</ModuleDefinitionFile>
          278  +      <ModuleDefinitionFile>src\core\sqlite3.def</ModuleDefinitionFile>
   271    279         <EmbedManagedResourceFile>%(EmbedManagedResourceFile)</EmbedManagedResourceFile>
   272    280         <DelayLoadDLLs>advapi32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
   273    281         <GenerateDebugInformation>true</GenerateDebugInformation>
   274    282         <RandomizedBaseAddress>false</RandomizedBaseAddress>
   275    283         <DataExecutionPrevention>
   276    284         </DataExecutionPrevention>
   277    285         <ImportLibrary>
................................................................................
   294    302         <PreprocessorDefinitions>WIN32;SQLITE_DEBUG;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;NO_TCL;THREADSAFE=1;SQLITE_HAS_CODEC;SQLITE_ENABLE_COLUMN_METADATA;SQLITE_ENABLE_FTS3;SQLITE_ENABLE_RTREE;SQLITE_ENABLE_LOAD_EXTENSION;SQLITE_SOUNDEX;SQLITE_CORE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
   295    303         <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
   296    304         <RuntimeTypeInfo>false</RuntimeTypeInfo>
   297    305         <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
   298    306       </ClCompile>
   299    307       <Link>
   300    308         <OutputFile>../bin/sqlite3.dll</OutputFile>
   301         -      <ModuleDefinitionFile>src\sqlite3.def</ModuleDefinitionFile>
          309  +      <ModuleDefinitionFile>src\core\sqlite3.def</ModuleDefinitionFile>
   302    310         <EmbedManagedResourceFile>%(EmbedManagedResourceFile)</EmbedManagedResourceFile>
   303    311         <DelayLoadDLLs>advapi32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
   304    312         <GenerateDebugInformation>true</GenerateDebugInformation>
   305    313         <RandomizedBaseAddress>false</RandomizedBaseAddress>
   306    314         <DataExecutionPrevention>
   307    315         </DataExecutionPrevention>
   308    316         <ImportLibrary>
................................................................................
   310    318         <TargetMachine>MachineX86</TargetMachine>
   311    319         <KeyFile>..\System.Data.SQLite\System.Data.SQLite.snk</KeyFile>
   312    320         <DelaySign>true</DelaySign>
   313    321       </Link>
   314    322       <PostBuildEvent>
   315    323         <Command>"$(FrameworkSDKDir)Bin\sn.exe" -R "$(TargetPath)" "$(SolutionDir)System.Data.SQLite\System.Data.SQLite.snk"</Command>
   316    324       </PostBuildEvent>
          325  +    <ResourceCompile>
          326  +      <PreprocessorDefinitions>&quot;INTEROP_RC_VERSION=$(INTEROP_RC_VERSION)&quot;</PreprocessorDefinitions>
          327  +    </ResourceCompile>
   317    328     </ItemDefinitionGroup>
   318    329     <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='StockDebug|x64'">
   319    330       <PreBuildEvent>
   320    331         <Command>
   321    332         </Command>
   322    333       </PreBuildEvent>
   323    334       <Midl>
................................................................................
   329    340         <PreprocessorDefinitions>SQLITE_DEBUG;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;NO_TCL;THREADSAFE=1;WIN64;SQLITE_HAS_CODEC;SQLITE_ENABLE_COLUMN_METADATA;SQLITE_ENABLE_FTS3;SQLITE_ENABLE_RTREE;SQLITE_ENABLE_LOAD_EXTENSION;SQLITE_SOUNDEX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
   330    341         <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
   331    342         <RuntimeTypeInfo>false</RuntimeTypeInfo>
   332    343         <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
   333    344       </ClCompile>
   334    345       <Link>
   335    346         <OutputFile>../bin/x64/$(ProjectName).DLL</OutputFile>
   336         -      <ModuleDefinitionFile>src\sqlite3.def</ModuleDefinitionFile>
          347  +      <ModuleDefinitionFile>src\core\sqlite3.def</ModuleDefinitionFile>
   337    348         <EmbedManagedResourceFile>%(EmbedManagedResourceFile)</EmbedManagedResourceFile>
   338    349         <DelayLoadDLLs>advapi32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
   339    350         <GenerateDebugInformation>true</GenerateDebugInformation>
   340    351         <RandomizedBaseAddress>false</RandomizedBaseAddress>
   341    352         <DataExecutionPrevention>
   342    353         </DataExecutionPrevention>
   343    354         <ImportLibrary>
................................................................................
   347    358         <DelaySign>true</DelaySign>
   348    359       </Link>
   349    360       <PostBuildEvent>
   350    361         <Command>"$(FrameworkSDKDir).\Bin\sn.exe" -R "$(TargetPath)" "..\System.Data.SQLite\System.Data.SQLite.snk"</Command>
   351    362       </PostBuildEvent>
   352    363     </ItemDefinitionGroup>
   353    364     <ItemGroup>
   354         -    <ClInclude Include="resource.h" />
   355         -    <ClInclude Include="src\sqlite3.h" />
          365  +    <ClInclude Include="src\core\sqlite3.h" />
   356    366     </ItemGroup>
   357    367     <ItemGroup>
   358         -    <ClCompile Include="interop.c" />
          368  +    <ClCompile Include="src\win\interop.c" />
   359    369     </ItemGroup>
   360    370     <ItemGroup>
   361    371       <EmbeddedResource Include="..\System.Data.SQLite\SR.resx">
   362    372         <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
   363    373         <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
   364    374         <LogicalName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">System.Data.SQLite.%(Filename).resources</LogicalName>
   365    375         <LogicalName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">System.Data.SQLite.%(Filename).resources</LogicalName>
   366    376         <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='StockDebug|Win32'">true</ExcludedFromBuild>
   367    377         <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='StockDebug|x64'">true</ExcludedFromBuild>
   368    378       </EmbeddedResource>
   369    379     </ItemGroup>
   370    380     <ItemGroup>
   371         -    <ResourceCompile Include="SQLite.Interop.rc" />
          381  +    <ResourceCompile Include="src\win\SQLite.Interop.rc" />
   372    382     </ItemGroup>
   373    383     <ItemGroup>
   374    384       <ProjectReference Include="..\System.Data.SQLite\System.Data.SQLite - ManagedOnly.csproj">
   375    385         <Project>{ac139952-261a-4463-b6fa-aebc25283a66}</Project>
   376    386         <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
   377    387       </ProjectReference>
   378    388       <ProjectReference Include="..\System.Data.SQLite\System.Data.SQLite - Netmodule.csproj">

Added SQLite.Interop/props/SQLite.Interop.props.

            1  +<?xml version="1.0" encoding="utf-8"?>
            2  +<!--
            3  + *
            4  + * SQLite.Interop.props -
            5  + *
            6  + * Written by Joe Mistachkin.
            7  + * Released to the public domain, use at your own risk!
            8  + *
            9  +-->
           10  +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
           11  +  <PropertyGroup Label="UserMacros">
           12  +    <INTEROP_MANIFEST_VERSION>1.0.67.0</INTEROP_MANIFEST_VERSION>
           13  +    <INTEROP_RC_VERSION>1,0,67,0</INTEROP_RC_VERSION>
           14  +    <INTEROP_ASSEMBLY_RESOURCES>..\System.Data.SQLite\SQLiteCommand.bmp,System.Data.SQLite.SQLiteCommand.bmp&#x0D;&#x0A;/ASSEMBLYRESOURCE:..\System.Data.SQLite\SQLiteConnection.bmp,System.Data.SQLite.SQLiteConnection.bmp&#x0D;&#x0A;/ASSEMBLYRESOURCE:..\System.Data.SQLite\SQLiteDataAdapter.bmp,System.Data.SQLite.SQLiteDataAdapter.bmp</INTEROP_ASSEMBLY_RESOURCES>
           15  +    <INTEROP_KEY_FILE>..\System.Data.SQLite\System.Data.SQLite.snk</INTEROP_KEY_FILE>
           16  +  </PropertyGroup>
           17  +  <PropertyGroup>
           18  +    <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
           19  +  </PropertyGroup>
           20  +  <ItemGroup>
           21  +    <BuildMacro Include="INTEROP_MANIFEST_VERSION">
           22  +      <Value>$(INTEROP_MANIFEST_VERSION)</Value>
           23  +      <EnvironmentVariable>true</EnvironmentVariable>
           24  +    </BuildMacro>
           25  +    <BuildMacro Include="INTEROP_RC_VERSION">
           26  +      <Value>$(INTEROP_RC_VERSION)</Value>
           27  +      <EnvironmentVariable>true</EnvironmentVariable>
           28  +    </BuildMacro>
           29  +    <BuildMacro Include="INTEROP_ASSEMBLY_RESOURCES">
           30  +      <Value>$(INTEROP_ASSEMBLY_RESOURCES)</Value>
           31  +      <EnvironmentVariable>true</EnvironmentVariable>
           32  +    </BuildMacro>
           33  +    <BuildMacro Include="INTEROP_KEY_FILE">
           34  +      <Value>$(INTEROP_KEY_FILE)</Value>
           35  +      <EnvironmentVariable>true</EnvironmentVariable>
           36  +    </BuildMacro>
           37  +  </ItemGroup>
           38  +</Project>

Added SQLite.Interop/props/SQLite.Interop.vsprops.

            1  +<?xml version="1.0" encoding="Windows-1252"?>
            2  +<!--
            3  + *
            4  + * SQLite.Interop.vsprops -
            5  + *
            6  + * Written by Joe Mistachkin.
            7  + * Released to the public domain, use at your own risk!
            8  + *
            9  +-->
           10  +<VisualStudioPropertySheet
           11  +	ProjectType="Visual C++"
           12  +	Version="8.00"
           13  +	Name="SQLite.Interop"
           14  +	>
           15  +	<UserMacro
           16  +		Name="INTEROP_MANIFEST_VERSION"
           17  +		Value="1.0.67.0"
           18  +		PerformEnvironmentSet="true"
           19  +	/>
           20  +	<UserMacro
           21  +		Name="INTEROP_RC_VERSION"
           22  +		Value="1,0,67,0"
           23  +		PerformEnvironmentSet="true"
           24  +	/>
           25  +	<UserMacro
           26  +		Name="INTEROP_ASSEMBLY_RESOURCES"
           27  +		Value="..\System.Data.SQLite\SQLiteCommand.bmp,System.Data.SQLite.SQLiteCommand.bmp&#x0D;&#x0A;/ASSEMBLYRESOURCE:..\System.Data.SQLite\SQLiteConnection.bmp,System.Data.SQLite.SQLiteConnection.bmp&#x0D;&#x0A;/ASSEMBLYRESOURCE:..\System.Data.SQLite\SQLiteDataAdapter.bmp,System.Data.SQLite.SQLiteDataAdapter.bmp"
           28  +		PerformEnvironmentSet="true"
           29  +	/>
           30  +	<UserMacro
           31  +		Name="INTEROP_KEY_FILE"
           32  +		Value="..\System.Data.SQLite\System.Data.SQLite.snk"
           33  +		PerformEnvironmentSet="true"
           34  +	/>
           35  +</VisualStudioPropertySheet>

Added SQLite.Interop/props/sqlite3.props.

            1  +<?xml version="1.0" encoding="utf-8"?>
            2  +<!--
            3  + *
            4  + * sqlite3.props -
            5  + *
            6  + * Written by Joe Mistachkin.
            7  + * Released to the public domain, use at your own risk!
            8  + *
            9  +-->
           10  +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
           11  +  <PropertyGroup Label="UserMacros">
           12  +    <SQLITE_MANIFEST_VERSION>3.7.5.0</SQLITE_MANIFEST_VERSION>
           13  +    <SQLITE_RC_VERSION>3,7,5,0</SQLITE_RC_VERSION>
           14  +    <SQLITE_COMMON_DEFINES>SQLITE_THREADSAFE=1;SQLITE_HAS_CODEC=1;SQLITE_ENABLE_COLUMN_METADATA=1;SQLITE_ENABLE_FTS3=1;SQLITE_ENABLE_FTS3_PARENTHESIS=1;SQLITE_ENABLE_LOAD_EXTENSION=1;SQLITE_ENABLE_MEMORY_MANAGEMENT=1;SQLITE_ENABLE_RTREE=1;SQLITE_ENABLE_STAT2=1;SQLITE_ENABLE_UPDATE_DELETE_LIMIT=1;SQLITE_SOUNDEX=1</SQLITE_COMMON_DEFINES>
           15  +    <SQLITE_DEBUG_DEFINES>SQLITE_DEBUG=1;SQLITE_MEMDEBUG=1</SQLITE_DEBUG_DEFINES>
           16  +    <SQLITE_DISABLE_WARNINGS>4018;4055;4090;4100;4127;4132;4146;4152;4210;4244;4245;4389;4701;4706;4996</SQLITE_DISABLE_WARNINGS>
           17  +  </PropertyGroup>
           18  +  <PropertyGroup>
           19  +    <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
           20  +  </PropertyGroup>
           21  +  <ItemGroup>
           22  +    <BuildMacro Include="SQLITE_MANIFEST_VERSION">
           23  +      <Value>$(SQLITE_MANIFEST_VERSION)</Value>
           24  +      <EnvironmentVariable>true</EnvironmentVariable>
           25  +    </BuildMacro>
           26  +    <BuildMacro Include="SQLITE_RC_VERSION">
           27  +      <Value>$(SQLITE_RC_VERSION)</Value>
           28  +      <EnvironmentVariable>true</EnvironmentVariable>
           29  +    </BuildMacro>
           30  +    <BuildMacro Include="SQLITE_COMMON_DEFINES">
           31  +      <Value>$(SQLITE_COMMON_DEFINES)</Value>
           32  +      <EnvironmentVariable>true</EnvironmentVariable>
           33  +    </BuildMacro>
           34  +    <BuildMacro Include="SQLITE_DEBUG_DEFINES">
           35  +      <Value>$(SQLITE_DEBUG_DEFINES)</Value>
           36  +      <EnvironmentVariable>true</EnvironmentVariable>
           37  +    </BuildMacro>
           38  +    <BuildMacro Include="SQLITE_DISABLE_WARNINGS">
           39  +      <Value>$(SQLITE_DISABLE_WARNINGS)</Value>
           40  +      <EnvironmentVariable>true</EnvironmentVariable>
           41  +    </BuildMacro>
           42  +  </ItemGroup>
           43  +</Project>

Added SQLite.Interop/props/sqlite3.vsprops.

            1  +<?xml version="1.0" encoding="Windows-1252"?>
            2  +<!--
            3  + *
            4  + * sqlite3.vsprops -
            5  + *
            6  + * Written by Joe Mistachkin.
            7  + * Released to the public domain, use at your own risk!
            8  + *
            9  +-->
           10  +<VisualStudioPropertySheet
           11  +	ProjectType="Visual C++"
           12  +	Version="8.00"
           13  +	Name="sqlite3"
           14  +	>
           15  +	<UserMacro
           16  +		Name="SQLITE_MANIFEST_VERSION"
           17  +		Value="3.7.5.0"
           18  +		PerformEnvironmentSet="true"
           19  +	/>
           20  +	<UserMacro
           21  +		Name="SQLITE_RC_VERSION"
           22  +		Value="3,7,5,0"
           23  +		PerformEnvironmentSet="true"
           24  +	/>
           25  +	<UserMacro
           26  +		Name="SQLITE_COMMON_DEFINES"
           27  +		Value="SQLITE_THREADSAFE=1;SQLITE_HAS_CODEC=1;SQLITE_ENABLE_COLUMN_METADATA=1;SQLITE_ENABLE_FTS3=1;SQLITE_ENABLE_FTS3_PARENTHESIS=1;SQLITE_ENABLE_LOAD_EXTENSION=1;SQLITE_ENABLE_MEMORY_MANAGEMENT=1;SQLITE_ENABLE_RTREE=1;SQLITE_ENABLE_STAT2=1;SQLITE_ENABLE_UPDATE_DELETE_LIMIT=1;SQLITE_SOUNDEX=1"
           28  +		PerformEnvironmentSet="true"
           29  +	/>
           30  +	<UserMacro
           31  +		Name="SQLITE_DEBUG_DEFINES"
           32  +		Value="SQLITE_DEBUG=1;SQLITE_MEMDEBUG=1"
           33  +		PerformEnvironmentSet="true"
           34  +	/>
           35  +	<UserMacro
           36  +		Name="SQLITE_DISABLE_WARNINGS"
           37  +		Value="4018;4055;4090;4100;4127;4132;4146;4152;4210;4244;4245;4389;4701;4706;4996"
           38  +		PerformEnvironmentSet="true"
           39  +	/>
           40  +</VisualStudioPropertySheet>

Deleted SQLite.Interop/resource.h.

     1         -//{{NO_DEPENDENCIES}}
     2         -// Microsoft Visual C++ generated include file.
     3         -// Used by SQLite.Interop.rc
     4         -
     5         -// Next default values for new objects
     6         -// 
     7         -#ifdef APSTUDIO_INVOKED
     8         -#ifndef APSTUDIO_READONLY_SYMBOLS
     9         -#define _APS_NEXT_RESOURCE_VALUE        101
    10         -#define _APS_NEXT_COMMAND_VALUE         40001
    11         -#define _APS_NEXT_CONTROL_VALUE         1001
    12         -#define _APS_NEXT_SYMED_VALUE           101
    13         -#endif
    14         -#endif

Name change from SQLite.Interop/extension-functions.c to SQLite.Interop/src/contrib/extension-functions.c.

   101    101   #define HAVE_TANH 1
   102    102   #define HAVE_LOG10 1
   103    103   //#define HAVE_ISBLANK 1
   104    104   #define SQLITE_SOUNDEX 1
   105    105   #define HAVE_TRIM 1		/* LMH 2007-03-25 if sqlite has trim functions */
   106    106   
   107    107   #ifdef COMPILE_SQLITE_EXTENSIONS_AS_LOADABLE_MODULE
   108         -#include "sqlite3ext.h"
          108  +#include "../core/sqlite3ext.h"
   109    109   SQLITE_EXTENSION_INIT1
   110    110   #else
   111         -#include "src/sqlite3.h"
          111  +#include "../core/sqlite3.h"
   112    112   #endif
   113    113   
   114    114   #include <ctype.h>
   115    115   /* relicoder */
   116    116   #include <math.h>
   117    117   #include <string.h>
   118    118   #include <stdio.h>
................................................................................
   588    588   
   589    589   
   590    590   /*
   591    591   ** smallest integer value not less than argument
   592    592   */
   593    593   static void ceilFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
   594    594     double rVal=0.0;
   595         -  i64 iVal=0;
   596    595     assert( argc==1 );
   597    596     switch( sqlite3_value_type(argv[0]) ){
   598    597       case SQLITE_INTEGER: {
   599    598         i64 iVal = sqlite3_value_int64(argv[0]);
   600    599         sqlite3_result_int64(context, iVal);
   601    600         break;
   602    601       }
................................................................................
   613    612   }
   614    613   
   615    614   /*
   616    615   ** largest integer value not greater than argument
   617    616   */
   618    617   static void floorFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
   619    618     double rVal=0.0;
   620         -  i64 iVal=0;
   621    619     assert( argc==1 );
   622    620     switch( sqlite3_value_type(argv[0]) ){
   623    621       case SQLITE_INTEGER: {
   624    622         i64 iVal = sqlite3_value_int64(argv[0]);
   625    623         sqlite3_result_int64(context, iVal);
   626    624         break;
   627    625       }

Name change from SQLite.Interop/src/sqlite3.c to SQLite.Interop/src/core/sqlite3.c.

     1      1   /******************************************************************************
     2      2   ** This file is an amalgamation of many separate C source files from SQLite
     3         -** version 3.7.4.  By combining all the individual C code files into this 
            3  +** version 3.7.5.  By combining all the individual C code files into this 
     4      4   ** single large file, the entire code can be compiled as a one translation
     5      5   ** unit.  This allows many compilers to do optimizations that would not be
     6      6   ** possible if the files were compiled separately.  Performance improvements
     7      7   ** of 5% or more are commonly seen when SQLite is compiled as a single
     8      8   ** translation unit.
     9      9   **
    10     10   ** This file is all you need to compile SQLite.  To use SQLite in other
................................................................................
   646    646   ** string contains the date and time of the check-in (UTC) and an SHA1
   647    647   ** hash of the entire source tree.
   648    648   **
   649    649   ** See also: [sqlite3_libversion()],
   650    650   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   651    651   ** [sqlite_version()] and [sqlite_source_id()].
   652    652   */
   653         -#define SQLITE_VERSION        "3.7.4"
   654         -#define SQLITE_VERSION_NUMBER 3007004
   655         -#define SQLITE_SOURCE_ID      "2010-12-07 20:14:09 a586a4deeb25330037a49df295b36aaf624d0f45"
          653  +#define SQLITE_VERSION        "3.7.5"
          654  +#define SQLITE_VERSION_NUMBER 3007005
          655  +#define SQLITE_SOURCE_ID      "2011-01-28 17:03:50 ed759d5a9edb3bba5f48f243df47be29e3fe8cd7"
   656    656   
   657    657   /*
   658    658   ** CAPI3REF: Run-Time Library Version Numbers
   659    659   ** KEYWORDS: sqlite3_version, sqlite3_sourceid
   660    660   **
   661    661   ** These interfaces provide the same information as the [SQLITE_VERSION],
   662    662   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
   929    929   #define SQLITE_BUSY         5   /* The database file is locked */
   930    930   #define SQLITE_LOCKED       6   /* A table in the database is locked */
   931    931   #define SQLITE_NOMEM        7   /* A malloc() failed */
   932    932   #define SQLITE_READONLY     8   /* Attempt to write a readonly database */
   933    933   #define SQLITE_INTERRUPT    9   /* Operation terminated by sqlite3_interrupt()*/
   934    934   #define SQLITE_IOERR       10   /* Some kind of disk I/O error occurred */
   935    935   #define SQLITE_CORRUPT     11   /* The database disk image is malformed */
   936         -#define SQLITE_NOTFOUND    12   /* NOT USED. Table or record not found */
          936  +#define SQLITE_NOTFOUND    12   /* Unknown opcode in sqlite3_file_control() */
   937    937   #define SQLITE_FULL        13   /* Insertion failed because database is full */
   938    938   #define SQLITE_CANTOPEN    14   /* Unable to open the database file */
   939    939   #define SQLITE_PROTOCOL    15   /* Database lock protocol error */
   940    940   #define SQLITE_EMPTY       16   /* Database is empty */
   941    941   #define SQLITE_SCHEMA      17   /* The database schema changed */
   942    942   #define SQLITE_TOOBIG      18   /* String or BLOB exceeds size limit */
   943    943   #define SQLITE_CONSTRAINT  19   /* Abort due to constraint violation */
................................................................................
  1161   1161   ** write return values.  Potential uses for xFileControl() might be
  1162   1162   ** functions to enable blocking locks with timeouts, to change the
  1163   1163   ** locking strategy (for example to use dot-file locks), to inquire
  1164   1164   ** about the status of a lock, or to break stale locks.  The SQLite
  1165   1165   ** core reserves all opcodes less than 100 for its own use.
  1166   1166   ** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available.
  1167   1167   ** Applications that define a custom xFileControl method should use opcodes
  1168         -** greater than 100 to avoid conflicts.
         1168  +** greater than 100 to avoid conflicts.  VFS implementations should
         1169  +** return [SQLITE_NOTFOUND] for file control opcodes that they do not
         1170  +** recognize.
  1169   1171   **
  1170   1172   ** The xSectorSize() method returns the sector size of the
  1171   1173   ** device that underlies the file.  The sector size is the
  1172   1174   ** minimum write that can be performed without disturbing
  1173   1175   ** other bytes in the file.  The xDeviceCharacteristics()
  1174   1176   ** method returns a bit vector describing behaviors of the
  1175   1177   ** underlying device:
................................................................................
  1254   1256   ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
  1255   1257   ** extends and truncates the database file in chunks of a size specified
  1256   1258   ** by the user. The fourth argument to [sqlite3_file_control()] should 
  1257   1259   ** point to an integer (type int) containing the new chunk-size to use
  1258   1260   ** for the nominated database. Allocating database file space in large
  1259   1261   ** chunks (say 1MB at a time), may reduce file-system fragmentation and
  1260   1262   ** improve performance on some systems.
         1263  +**
         1264  +** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
         1265  +** to the [sqlite3_file] object associated with a particular database
         1266  +** connection.  See the [sqlite3_file_control()] documentation for
         1267  +** additional information.
         1268  +**
         1269  +** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by
         1270  +** SQLite and sent to all VFSes in place of a call to the xSync method
         1271  +** when the database connection has [PRAGMA synchronous] set to OFF.)^
         1272  +** Some specialized VFSes need this signal in order to operate correctly
         1273  +** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most 
         1274  +** VFSes do not need this signal and should silently ignore this opcode.
         1275  +** Applications should not call [sqlite3_file_control()] with this
         1276  +** opcode as doing so may disrupt the operation of the specilized VFSes
         1277  +** that do require it.  
  1261   1278   */
  1262   1279   #define SQLITE_FCNTL_LOCKSTATE        1
  1263   1280   #define SQLITE_GET_LOCKPROXYFILE      2
  1264   1281   #define SQLITE_SET_LOCKPROXYFILE      3
  1265   1282   #define SQLITE_LAST_ERRNO             4
  1266   1283   #define SQLITE_FCNTL_SIZE_HINT        5
  1267   1284   #define SQLITE_FCNTL_CHUNK_SIZE       6
  1268   1285   #define SQLITE_FCNTL_FILE_POINTER     7
         1286  +#define SQLITE_FCNTL_SYNC_OMITTED     8
  1269   1287   
  1270   1288   
  1271   1289   /*
  1272   1290   ** CAPI3REF: Mutex Handle
  1273   1291   **
  1274   1292   ** The mutex module within SQLite defines [sqlite3_mutex] to be an
  1275   1293   ** abstract type for a mutex object.  The SQLite core never looks
................................................................................
  2381   2399   ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
  2382   2400   ** results into memory obtained from [sqlite3_malloc()].
  2383   2401   ** The strings returned by these two routines should be
  2384   2402   ** released by [sqlite3_free()].  ^Both routines return a
  2385   2403   ** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
  2386   2404   ** memory to hold the resulting string.
  2387   2405   **
  2388         -** ^(In sqlite3_snprintf() routine is similar to "snprintf()" from
         2406  +** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from
  2389   2407   ** the standard C library.  The result is written into the
  2390   2408   ** buffer supplied as the second parameter whose size is given by
  2391   2409   ** the first parameter. Note that the order of the
  2392   2410   ** first two parameters is reversed from snprintf().)^  This is an
  2393   2411   ** historical accident that cannot be fixed without breaking
  2394   2412   ** backwards compatibility.  ^(Note also that sqlite3_snprintf()
  2395   2413   ** returns a pointer to its buffer instead of the number of
................................................................................
  2399   2417   ** now without breaking compatibility.
  2400   2418   **
  2401   2419   ** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
  2402   2420   ** guarantees that the buffer is always zero-terminated.  ^The first
  2403   2421   ** parameter "n" is the total size of the buffer, including space for
  2404   2422   ** the zero terminator.  So the longest string that can be completely
  2405   2423   ** written will be n-1 characters.
         2424  +**
         2425  +** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
  2406   2426   **
  2407   2427   ** These routines all implement some additional formatting
  2408   2428   ** options that are useful for constructing SQL statements.
  2409   2429   ** All of the usual printf() formatting options apply.  In addition, there
  2410   2430   ** is are "%q", "%Q", and "%z" options.
  2411   2431   **
  2412   2432   ** ^(The %q option works like %s in that it substitutes a null-terminated
................................................................................
  2463   2483   ** ^(The "%z" formatting option works like "%s" but with the
  2464   2484   ** addition that after the string has been read and copied into
  2465   2485   ** the result, [sqlite3_free()] is called on the input string.)^
  2466   2486   */
  2467   2487   SQLITE_API char *sqlite3_mprintf(const char*,...);
  2468   2488   SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
  2469   2489   SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
         2490  +SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
  2470   2491   
  2471   2492   /*
  2472   2493   ** CAPI3REF: Memory Allocation Subsystem
  2473   2494   **
  2474   2495   ** The SQLite core uses these three routines for all of its own
  2475   2496   ** internal memory allocation needs. "Core" in the previous sentence
  2476   2497   ** does not include operating-system specific VFS implementation.  The
................................................................................
  2840   2861   **
  2841   2862   ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
  2842   2863   ** <dd>The database is opened for reading and writing if possible, or reading
  2843   2864   ** only if the file is write protected by the operating system.  In either
  2844   2865   ** case the database must already exist, otherwise an error is returned.</dd>)^
  2845   2866   **
  2846   2867   ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
  2847         -** <dd>The database is opened for reading and writing, and is creates it if
         2868  +** <dd>The database is opened for reading and writing, and is created if
  2848   2869   ** it does not already exist. This is the behavior that is always used for
  2849   2870   ** sqlite3_open() and sqlite3_open16().</dd>)^
  2850   2871   ** </dl>
  2851   2872   **
  2852   2873   ** If the 3rd parameter to sqlite3_open_v2() is not one of the
  2853   2874   ** combinations shown above or one of the combinations shown above combined
  2854   2875   ** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX],
................................................................................
  3189   3210   ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
  3190   3211   */
  3191   3212   SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
  3192   3213   
  3193   3214   /*
  3194   3215   ** CAPI3REF: Determine If An SQL Statement Writes The Database
  3195   3216   **
  3196         -** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
  3197         -** the [prepared statement] X is [SELECT] statement and false (zero) if
  3198         -** X is an [INSERT], [UPDATE], [DELETE], CREATE, DROP, [ANALYZE],
  3199         -** [ALTER], or [REINDEX] statement.
  3200         -** If X is a NULL pointer or any other kind of statement, including but
  3201         -** not limited to [ATTACH], [DETACH], [COMMIT], [ROLLBACK], [RELEASE],
  3202         -** [SAVEPOINT], [PRAGMA], or [VACUUM] the result of sqlite3_stmt_readonly(X) is
  3203         -** undefined.
         3217  +** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if 
         3218  +** and only if the [prepared statement] X makes no direct changes to
         3219  +** the content of the database file.
         3220  +**
         3221  +** Note that [application-defined SQL functions] or
         3222  +** [virtual tables] might change the database indirectly as a side effect.  
         3223  +** ^(For example, if an application defines a function "eval()" that 
         3224  +** calls [sqlite3_exec()], then the following SQL statement would
         3225  +** change the database file through side-effects:
         3226  +**
         3227  +** <blockquote><pre>
         3228  +**    SELECT eval('DELETE FROM t1') FROM t2;
         3229  +** </pre></blockquote>
         3230  +**
         3231  +** But because the [SELECT] statement does not change the database file
         3232  +** directly, sqlite3_stmt_readonly() would still return true.)^
         3233  +**
         3234  +** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
         3235  +** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
         3236  +** since the statements themselves do not actually modify the database but
         3237  +** rather they control the timing of when other statements modify the 
         3238  +** database.  ^The [ATTACH] and [DETACH] statements also cause
         3239  +** sqlite3_stmt_readonly() to return true since, while those statements
         3240  +** change the configuration of a database connection, they do not make 
         3241  +** changes to the content of the database files on disk.
  3204   3242   */
  3205   3243   SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
  3206   3244   
  3207   3245   /*
  3208   3246   ** CAPI3REF: Dynamically Typed Value Object
  3209   3247   ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
  3210   3248   **
................................................................................
  3590   3628   ** [SQLITE_MISUSE] means that the this routine was called inappropriately.
  3591   3629   ** Perhaps it was called on a [prepared statement] that has
  3592   3630   ** already been [sqlite3_finalize | finalized] or on one that had
  3593   3631   ** previously returned [SQLITE_ERROR] or [SQLITE_DONE].  Or it could
  3594   3632   ** be the case that the same database connection is being used by two or
  3595   3633   ** more threads at the same moment in time.
  3596   3634   **
  3597         -** For all versions of SQLite up to and including 3.6.23.1, it was required
  3598         -** after sqlite3_step() returned anything other than [SQLITE_ROW] that
  3599         -** [sqlite3_reset()] be called before any subsequent invocation of
  3600         -** sqlite3_step().  Failure to invoke [sqlite3_reset()] in this way would
  3601         -** result in an [SQLITE_MISUSE] return from sqlite3_step().  But after
  3602         -** version 3.6.23.1, sqlite3_step() began calling [sqlite3_reset()] 
  3603         -** automatically in this circumstance rather than returning [SQLITE_MISUSE].  
         3635  +** For all versions of SQLite up to and including 3.6.23.1, a call to
         3636  +** [sqlite3_reset()] was required after sqlite3_step() returned anything
         3637  +** other than [SQLITE_ROW] before any subsequent invocation of
         3638  +** sqlite3_step().  Failure to reset the prepared statement using 
         3639  +** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
         3640  +** sqlite3_step().  But after version 3.6.23.1, sqlite3_step() began
         3641  +** calling [sqlite3_reset()] automatically in this circumstance rather
         3642  +** than returning [SQLITE_MISUSE].  This is not considered a compatibility
         3643  +** break because any application that ever receives an SQLITE_MISUSE error
         3644  +** is broken by definition.  The [SQLITE_OMIT_AUTORESET] compile-time option
         3645  +** can be used to restore the legacy behavior.
  3604   3646   **
  3605   3647   ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
  3606   3648   ** API always returns a generic error code, [SQLITE_ERROR], following any
  3607   3649   ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE].  You must call
  3608   3650   ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
  3609   3651   ** specific [error codes] that better describes the error.
  3610   3652   ** We admit that this is a goofy design.  The problem has been fixed
................................................................................
  3933   3975   ** will pick the one that involves the least amount of data conversion.
  3934   3976   ** If there is only a single implementation which does not care what text
  3935   3977   ** encoding is used, then the fourth argument should be [SQLITE_ANY].
  3936   3978   **
  3937   3979   ** ^(The fifth parameter is an arbitrary pointer.  The implementation of the
  3938   3980   ** function can gain access to this pointer using [sqlite3_user_data()].)^
  3939   3981   **
  3940         -** ^The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
         3982  +** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
  3941   3983   ** pointers to C-language functions that implement the SQL function or
  3942   3984   ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
  3943   3985   ** callback only; NULL pointers must be passed as the xStep and xFinal
  3944   3986   ** parameters. ^An aggregate SQL function requires an implementation of xStep
  3945   3987   ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
  3946   3988   ** SQL function or aggregate, pass NULL poiners for all three function
  3947   3989   ** callbacks.
  3948   3990   **
  3949         -** ^(If the tenth parameter to sqlite3_create_function_v2() is not NULL,
         3991  +** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL,
  3950   3992   ** then it is destructor for the application data pointer. 
  3951   3993   ** The destructor is invoked when the function is deleted, either by being
  3952   3994   ** overloaded or when the database connection closes.)^
  3953   3995   ** ^The destructor is also invoked if the call to
  3954   3996   ** sqlite3_create_function_v2() fails.
  3955   3997   ** ^When the destructor callback of the tenth parameter is invoked, it
  3956   3998   ** is passed a single argument which is a copy of the application data 
................................................................................
  4046   4088   ** The C-language implementation of SQL functions and aggregates uses
  4047   4089   ** this set of interface routines to access the parameter values on
  4048   4090   ** the function or aggregate.
  4049   4091   **
  4050   4092   ** The xFunc (for scalar functions) or xStep (for aggregates) parameters
  4051   4093   ** to [sqlite3_create_function()] and [sqlite3_create_function16()]
  4052   4094   ** define callbacks that implement the SQL functions and aggregates.
  4053         -** The 4th parameter to these callbacks is an array of pointers to
         4095  +** The 3rd parameter to these callbacks is an array of pointers to
  4054   4096   ** [protected sqlite3_value] objects.  There is one [sqlite3_value] object for
  4055   4097   ** each parameter to the SQL function.  These routines are used to
  4056   4098   ** extract values from the [sqlite3_value] objects.
  4057   4099   **
  4058   4100   ** These routines work only with [protected sqlite3_value] objects.
  4059   4101   ** Any attempt to use these routines on an [unprotected sqlite3_value]
  4060   4102   ** object results in undefined behavior.
................................................................................
  5774   5816   #define SQLITE_MUTEX_RECURSIVE        1
  5775   5817   #define SQLITE_MUTEX_STATIC_MASTER    2
  5776   5818   #define SQLITE_MUTEX_STATIC_MEM       3  /* sqlite3_malloc() */
  5777   5819   #define SQLITE_MUTEX_STATIC_MEM2      4  /* NOT USED */
  5778   5820   #define SQLITE_MUTEX_STATIC_OPEN      4  /* sqlite3BtreeOpen() */
  5779   5821   #define SQLITE_MUTEX_STATIC_PRNG      5  /* sqlite3_random() */
  5780   5822   #define SQLITE_MUTEX_STATIC_LRU       6  /* lru page list */
  5781         -#define SQLITE_MUTEX_STATIC_LRU2      7  /* lru page list */
         5823  +#define SQLITE_MUTEX_STATIC_LRU2      7  /* NOT USED */
         5824  +#define SQLITE_MUTEX_STATIC_PMEM      7  /* sqlite3PageMalloc() */
  5782   5825   
  5783   5826   /*
  5784   5827   ** CAPI3REF: Retrieve the mutex for a database connection
  5785   5828   **
  5786   5829   ** ^This interface returns a pointer the [sqlite3_mutex] object that 
  5787   5830   ** serializes access to the [database connection] given in the argument
  5788   5831   ** when the [threading mode] is Serialized.
................................................................................
  5925   5968   ** <dd>This parameter records the largest memory allocation request
  5926   5969   ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
  5927   5970   ** internal equivalents).  Only the value returned in the
  5928   5971   ** *pHighwater parameter to [sqlite3_status()] is of interest.  
  5929   5972   ** The value written into the *pCurrent parameter is undefined.</dd>)^
  5930   5973   **
  5931   5974   ** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
  5932         -** <dd>This parameter records the number of separate memory allocations.</dd>)^
         5975  +** <dd>This parameter records the number of separate memory allocations
         5976  +** currently checked out.</dd>)^
  5933   5977   **
  5934   5978   ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
  5935   5979   ** <dd>This parameter returns the number of pages used out of the
  5936   5980   ** [pagecache memory allocator] that was configured using 
  5937   5981   ** [SQLITE_CONFIG_PAGECACHE].  The
  5938   5982   ** value returned is in pages, not in bytes.</dd>)^
  5939   5983   **
................................................................................
  6030   6074   ** The [sqlite3_db_status()] interface will return a non-zero error code
  6031   6075   ** if a discontinued or unsupported verb is invoked.
  6032   6076   **
  6033   6077   ** <dl>
  6034   6078   ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
  6035   6079   ** <dd>This parameter returns the number of lookaside memory slots currently
  6036   6080   ** checked out.</dd>)^
         6081  +**
         6082  +** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
         6083  +** <dd>This parameter returns the number malloc attempts that were 
         6084  +** satisfied using lookaside memory. Only the high-water value is meaningful;
         6085  +** the current value is always zero.
         6086  +** checked out.</dd>)^
         6087  +**
         6088  +** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
         6089  +** <dd>This parameter returns the number malloc attempts that might have
         6090  +** been satisfied using lookaside memory but failed due to the amount of
         6091  +** memory requested being larger than the lookaside slot size.
         6092  +** Only the high-water value is meaningful;
         6093  +** the current value is always zero.
         6094  +** checked out.</dd>)^
         6095  +**
         6096  +** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
         6097  +** <dd>This parameter returns the number malloc attempts that might have
         6098  +** been satisfied using lookaside memory but failed due to all lookaside
         6099  +** memory already being in use.
         6100  +** Only the high-water value is meaningful;
         6101  +** the current value is always zero.
         6102  +** checked out.</dd>)^
  6037   6103   **
  6038   6104   ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
  6039   6105   ** <dd>This parameter returns the approximate number of of bytes of heap
  6040   6106   ** memory used by all pager caches associated with the database connection.)^
  6041   6107   ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
  6042   6108   **
  6043   6109   ** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
................................................................................
  6053   6119   ** <dd>This parameter returns the approximate number of of bytes of heap
  6054   6120   ** and lookaside memory used by all prepared statements associated with
  6055   6121   ** the database connection.)^
  6056   6122   ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
  6057   6123   ** </dd>
  6058   6124   ** </dl>
  6059   6125   */
  6060         -#define SQLITE_DBSTATUS_LOOKASIDE_USED     0
  6061         -#define SQLITE_DBSTATUS_CACHE_USED         1
  6062         -#define SQLITE_DBSTATUS_SCHEMA_USED        2
  6063         -#define SQLITE_DBSTATUS_STMT_USED          3
  6064         -#define SQLITE_DBSTATUS_MAX                3   /* Largest defined DBSTATUS */
         6126  +#define SQLITE_DBSTATUS_LOOKASIDE_USED       0
         6127  +#define SQLITE_DBSTATUS_CACHE_USED           1
         6128  +#define SQLITE_DBSTATUS_SCHEMA_USED          2
         6129  +#define SQLITE_DBSTATUS_STMT_USED            3
         6130  +#define SQLITE_DBSTATUS_LOOKASIDE_HIT        4
         6131  +#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE  5
         6132  +#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL  6
         6133  +#define SQLITE_DBSTATUS_MAX                  6   /* Largest defined DBSTATUS */
  6065   6134   
  6066   6135   
  6067   6136   /*
  6068   6137   ** CAPI3REF: Prepared Statement Status
  6069   6138   **
  6070   6139   ** ^(Each prepared statement maintains various
  6071   6140   ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
................................................................................
  6185   6254   **
  6186   6255   ** ^SQLite invokes the xCreate() method to construct a new cache instance.
  6187   6256   ** SQLite will typically create one cache instance for each open database file,
  6188   6257   ** though this is not guaranteed. ^The
  6189   6258   ** first parameter, szPage, is the size in bytes of the pages that must
  6190   6259   ** be allocated by the cache.  ^szPage will not be a power of two.  ^szPage
  6191   6260   ** will the page size of the database file that is to be cached plus an
  6192         -** increment (here called "R") of about 100 or 200.  SQLite will use the
         6261  +** increment (here called "R") of less than 250.  SQLite will use the
  6193   6262   ** extra R bytes on each page to store metadata about the underlying
  6194   6263   ** database page on disk.  The value of R depends
  6195   6264   ** on the SQLite version, the target platform, and how SQLite was compiled.
  6196         -** ^R is constant for a particular build of SQLite.  ^The second argument to
         6265  +** ^(R is constant for a particular build of SQLite. Except, there are two
         6266  +** distinct values of R when SQLite is compiled with the proprietary
         6267  +** ZIPVFS extension.)^  ^The second argument to
  6197   6268   ** xCreate(), bPurgeable, is true if the cache being created will
  6198   6269   ** be used to cache database pages of a file stored on disk, or
  6199   6270   ** false if it is used for an in-memory database. The cache implementation
  6200   6271   ** does not have to do anything special based with the value of bPurgeable;
  6201   6272   ** it is purely advisory.  ^On a cache where bPurgeable is false, SQLite will
  6202   6273   ** never invoke xUnpin() except to deliberately delete a page.
  6203   6274   ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
................................................................................
  6221   6292   ** 8-byte boundary. The page to be fetched is determined by the key. ^The
  6222   6293   ** mimimum key value is 1.  After it has been retrieved using xFetch, the page 
  6223   6294   ** is considered to be "pinned".
  6224   6295   **
  6225   6296   ** If the requested page is already in the page cache, then the page cache
  6226   6297   ** implementation must return a pointer to the page buffer with its content
  6227   6298   ** intact.  If the requested page is not already in the cache, then the
  6228         -** behavior of the cache implementation should use the value of the createFlag
         6299  +** cache implementation should use the value of the createFlag
  6229   6300   ** parameter to help it determined what action to take:
  6230   6301   **
  6231   6302   ** <table border=1 width=85% align=center>
  6232   6303   ** <tr><th> createFlag <th> Behaviour when page is not already in cache
  6233   6304   ** <tr><td> 0 <td> Do not allocate a new page.  Return NULL.
  6234   6305   ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
  6235   6306   **                 Otherwise return NULL.
................................................................................
  6305   6376   **
  6306   6377   ** The backup API copies the content of one database into another.
  6307   6378   ** It is useful either for creating backups of databases or
  6308   6379   ** for copying in-memory databases to or from persistent files. 
  6309   6380   **
  6310   6381   ** See Also: [Using the SQLite Online Backup API]
  6311   6382   **
  6312         -** ^Exclusive access is required to the destination database for the 
  6313         -** duration of the operation. ^However the source database is only
  6314         -** read-locked while it is actually being read; it is not locked
  6315         -** continuously for the entire backup operation. ^Thus, the backup may be
  6316         -** performed on a live source database without preventing other users from
         6383  +** ^SQLite holds a write transaction open on the destination database file
         6384  +** for the duration of the backup operation.
         6385  +** ^The source database is read-locked only while it is being read;
         6386  +** it is not locked continuously for the entire backup operation.
         6387  +** ^Thus, the backup may be performed on a live source database without
         6388  +** preventing other database connections from
  6317   6389   ** reading or writing to the source database while the backup is underway.
  6318   6390   ** 
  6319   6391   ** ^(To perform a backup operation: 
  6320   6392   **   <ol>
  6321   6393   **     <li><b>sqlite3_backup_init()</b> is called once to initialize the
  6322   6394   **         backup, 
  6323   6395   **     <li><b>sqlite3_backup_step()</b> is called one or more times to transfer 
................................................................................
  6336   6408   ** ^The database name is "main" for the main database, "temp" for the
  6337   6409   ** temporary database, or the name specified after the AS keyword in
  6338   6410   ** an [ATTACH] statement for an attached database.
  6339   6411   ** ^The S and M arguments passed to 
  6340   6412   ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
  6341   6413   ** and database name of the source database, respectively.
  6342   6414   ** ^The source and destination [database connections] (parameters S and D)
  6343         -** must be different or else sqlite3_backup_init(D,N,S,M) will file with
         6415  +** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
  6344   6416   ** an error.
  6345   6417   **
  6346   6418   ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
  6347         -** returned and an error code and error message are store3d in the
         6419  +** returned and an error code and error message are stored in the
  6348   6420   ** destination [database connection] D.
  6349   6421   ** ^The error code and message for the failed call to sqlite3_backup_init()
  6350   6422   ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
  6351   6423   ** [sqlite3_errmsg16()] functions.
  6352   6424   ** ^A successful call to sqlite3_backup_init() returns a pointer to an
  6353   6425   ** [sqlite3_backup] object.
  6354   6426   ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
................................................................................
  6357   6429   **
  6358   6430   ** <b>sqlite3_backup_step()</b>
  6359   6431   **
  6360   6432   ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between 
  6361   6433   ** the source and destination databases specified by [sqlite3_backup] object B.
  6362   6434   ** ^If N is negative, all remaining source pages are copied. 
  6363   6435   ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
  6364         -** are still more pages to be copied, then the function resturns [SQLITE_OK].
         6436  +** are still more pages to be copied, then the function returns [SQLITE_OK].
  6365   6437   ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
  6366   6438   ** from source to destination, then it returns [SQLITE_DONE].
  6367   6439   ** ^If an error occurs while running sqlite3_backup_step(B,N),
  6368   6440   ** then an [error code] is returned. ^As well as [SQLITE_OK] and
  6369   6441   ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
  6370   6442   ** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an
  6371   6443   ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.
  6372   6444   **
  6373   6445   ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
  6374   6446   ** <ol>
  6375   6447   ** <li> the destination database was opened read-only, or
  6376   6448   ** <li> the destination database is using write-ahead-log journaling
  6377   6449   ** and the destination and source page sizes differ, or
  6378         -** <li> The destination database is an in-memory database and the
         6450  +** <li> the destination database is an in-memory database and the
  6379   6451   ** destination and source page sizes differ.
  6380   6452   ** </ol>)^
  6381   6453   **
  6382   6454   ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
  6383   6455   ** the [sqlite3_busy_handler | busy-handler function]
  6384   6456   ** is invoked (if one is specified). ^If the 
  6385   6457   ** busy-handler returns non-zero before the lock is available, then 
................................................................................
  6702   6774   ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
  6703   6775   ** configured by this function.
  6704   6776   **
  6705   6777   ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
  6706   6778   ** from SQL.
  6707   6779   **
  6708   6780   ** ^Every new [database connection] defaults to having the auto-checkpoint
  6709         -** enabled with a threshold of 1000 pages.  The use of this interface
         6781  +** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
         6782  +** pages.  The use of this interface
  6710   6783   ** is only necessary if the default setting is found to be suboptimal
  6711   6784   ** for a particular application.
  6712   6785   */
  6713   6786   SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
  6714   6787   
  6715   6788   /*
  6716   6789   ** CAPI3REF: Checkpoint a database
................................................................................
  8873   8946   */
  8874   8947   struct Lookaside {
  8875   8948     u16 sz;                 /* Size of each buffer in bytes */
  8876   8949     u8 bEnabled;            /* False to disable new lookaside allocations */
  8877   8950     u8 bMalloced;           /* True if pStart obtained from sqlite3_malloc() */
  8878   8951     int nOut;               /* Number of buffers currently checked out */
  8879   8952     int mxOut;              /* Highwater mark for nOut */
         8953  +  int anStat[3];          /* 0: hits.  1: size misses.  2: full misses */
  8880   8954     LookasideSlot *pFree;   /* List of available buffers */
  8881   8955     void *pStart;           /* First byte of available memory space */
  8882   8956     void *pEnd;             /* First byte past end of available space */
  8883   8957   };
  8884   8958   struct LookasideSlot {
  8885   8959     LookasideSlot *pNext;    /* Next buffer in the list of free buffers */
  8886   8960   };
................................................................................
  8951   9025       u8 orphanTrigger;           /* Last statement is orphaned TEMP trigger */
  8952   9026     } init;
  8953   9027     int nExtension;               /* Number of loaded extensions */
  8954   9028     void **aExtension;            /* Array of shared library handles */
  8955   9029     struct Vdbe *pVdbe;           /* List of active virtual machines */
  8956   9030     int activeVdbeCnt;            /* Number of VDBEs currently executing */
  8957   9031     int writeVdbeCnt;             /* Number of active VDBEs that are writing */
         9032  +  int vdbeExecCnt;              /* Number of nested calls to VdbeExec() */
  8958   9033     void (*xTrace)(void*,const char*);        /* Trace function */
  8959   9034     void *pTraceArg;                          /* Argument to the trace function */
  8960   9035     void (*xProfile)(void*,const char*,u64);  /* Profiling function */
  8961   9036     void *pProfileArg;                        /* Argument to profile function */
  8962   9037     void *pCommitArg;                 /* Argument to xCommitCallback() */   
  8963   9038     int (*xCommitCallback)(void*);    /* Invoked at every commit. */
  8964   9039     void *pRollbackArg;               /* Argument to xRollbackCallback() */   
................................................................................
 11722  11797     "OMIT_AUTOINCREMENT",
 11723  11798   #endif
 11724  11799   #ifdef SQLITE_OMIT_AUTOINIT
 11725  11800     "OMIT_AUTOINIT",
 11726  11801   #endif
 11727  11802   #ifdef SQLITE_OMIT_AUTOMATIC_INDEX
 11728  11803     "OMIT_AUTOMATIC_INDEX",
        11804  +#endif
        11805  +#ifdef SQLITE_OMIT_AUTORESET
        11806  +  "OMIT_AUTORESET",
 11729  11807   #endif
 11730  11808   #ifdef SQLITE_OMIT_AUTOVACUUM
 11731  11809     "OMIT_AUTOVACUUM",
 11732  11810   #endif
 11733  11811   #ifdef SQLITE_OMIT_BETWEEN_OPTIMIZATION
 11734  11812     "OMIT_BETWEEN_OPTIMIZATION",
 11735  11813   #endif
................................................................................
 11998  12076   ** The cursor can seek to a BTree entry with a particular key, or
 11999  12077   ** loop over all entries of the Btree.  You can also insert new BTree
 12000  12078   ** entries or retrieve the key or data from the entry that the cursor
 12001  12079   ** is currently pointing to.
 12002  12080   ** 
 12003  12081   ** Every cursor that the virtual machine has open is represented by an
 12004  12082   ** instance of the following structure.
 12005         -**
 12006         -** If the VdbeCursor.isTriggerRow flag is set it means that this cursor is
 12007         -** really a single row that represents the NEW or OLD pseudo-table of
 12008         -** a row trigger.  The data for the row is stored in VdbeCursor.pData and
 12009         -** the rowid is in VdbeCursor.iKey.
 12010  12083   */
 12011  12084   struct VdbeCursor {
 12012  12085     BtCursor *pCursor;    /* The cursor structure of the backend */
        12086  +  Btree *pBt;           /* Separate file holding temporary table */
        12087  +  KeyInfo *pKeyInfo;    /* Info about index keys needed by index cursors */
 12013  12088     int iDb;              /* Index of cursor database in db->aDb[] (or -1) */
 12014         -  i64 lastRowid;        /* Last rowid from a Next or NextIdx operation */
        12089  +  int pseudoTableReg;   /* Register holding pseudotable content. */
        12090  +  int nField;           /* Number of fields in the header */
 12015  12091     Bool zeroed;          /* True if zeroed out and ready for reuse */
 12016  12092     Bool rowidIsValid;    /* True if lastRowid is valid */
 12017  12093     Bool atFirst;         /* True if pointing to first entry */
 12018  12094     Bool useRandomRowid;  /* Generate new record numbers semi-randomly */
 12019  12095     Bool nullRow;         /* True if pointing to a row with no data */
 12020  12096     Bool deferredMoveto;  /* A call to sqlite3BtreeMoveto() is needed */
 12021  12097     Bool isTable;         /* True if a table requiring integer keys */
 12022  12098     Bool isIndex;         /* True if an index containing keys only - no data */
 12023  12099     Bool isOrdered;       /* True if the underlying table is BTREE_UNORDERED */
 12024         -  i64 movetoTarget;     /* Argument to the deferred sqlite3BtreeMoveto() */
 12025         -  Btree *pBt;           /* Separate file holding temporary table */
 12026         -  int pseudoTableReg;   /* Register holding pseudotable content. */
 12027         -  KeyInfo *pKeyInfo;    /* Info about index keys needed by index cursors */
 12028         -  int nField;           /* Number of fields in the header */
 12029         -  i64 seqCount;         /* Sequence counter */
 12030  12100     sqlite3_vtab_cursor *pVtabCursor;  /* The cursor for a virtual table */
 12031  12101     const sqlite3_module *pModule;     /* Module for cursor pVtabCursor */
        12102  +  i64 seqCount;         /* Sequence counter */
        12103  +  i64 movetoTarget;     /* Argument to the deferred sqlite3BtreeMoveto() */
        12104  +  i64 lastRowid;        /* Last rowid from a Next or NextIdx operation */
 12032  12105   
 12033  12106     /* Result of last sqlite3BtreeMoveto() done by an OP_NotExists or 
 12034  12107     ** OP_IsUnique opcode on this cursor. */
 12035  12108     int seekResult;
 12036  12109   
 12037  12110     /* Cached information about the header for the data record that the
 12038  12111     ** cursor is currently pointing to.  Only valid if cacheStatus matches
................................................................................
 12096  12169   ** A value for VdbeCursor.cacheValid that means the cache is always invalid.
 12097  12170   */
 12098  12171   #define CACHE_STALE 0
 12099  12172   
 12100  12173   /*
 12101  12174   ** Internally, the vdbe manipulates nearly all SQL values as Mem
 12102  12175   ** structures. Each Mem struct may cache multiple representations (string,
 12103         -** integer etc.) of the same value.  A value (and therefore Mem structure)
 12104         -** has the following properties:
 12105         -**
 12106         -** Each value has a manifest type. The manifest type of the value stored
 12107         -** in a Mem struct is returned by the MemType(Mem*) macro. The type is
 12108         -** one of SQLITE_NULL, SQLITE_INTEGER, SQLITE_REAL, SQLITE_TEXT or
 12109         -** SQLITE_BLOB.
        12176  +** integer etc.) of the same value.
 12110  12177   */
 12111  12178   struct Mem {
        12179  +  sqlite3 *db;        /* The associated database connection */
        12180  +  char *z;            /* String or BLOB value */
        12181  +  double r;           /* Real value */
 12112  12182     union {
 12113         -    i64 i;              /* Integer value. */
        12183  +    i64 i;              /* Integer value used when MEM_Int is set in flags */
 12114  12184       int nZero;          /* Used when bit MEM_Zero is set in flags */
 12115  12185       FuncDef *pDef;      /* Used only when flags==MEM_Agg */
 12116  12186       RowSet *pRowSet;    /* Used only when flags==MEM_RowSet */
 12117  12187       VdbeFrame *pFrame;  /* Used when flags==MEM_Frame */
 12118  12188     } u;
 12119         -  double r;           /* Real value */
 12120         -  sqlite3 *db;        /* The associated database connection */
 12121         -  char *z;            /* String or BLOB value */
 12122  12189     int n;              /* Number of characters in string value, excluding '\0' */
 12123  12190     u16 flags;          /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
 12124  12191     u8  type;           /* One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc */
 12125  12192     u8  enc;            /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
 12126  12193   #ifdef SQLITE_DEBUG
 12127  12194     Mem *pScopyFrom;    /* This Mem is a shallow copy of pScopyFrom */
 12128  12195     void *pFiller;      /* So that sizeof(Mem) is a multiple of 8 */
................................................................................
 12138  12205   ** No other flags may be set in this case.
 12139  12206   **
 12140  12207   ** If the MEM_Str flag is set then Mem.z points at a string representation.
 12141  12208   ** Usually this is encoded in the same unicode encoding as the main
 12142  12209   ** database (see below for exceptions). If the MEM_Term flag is also
 12143  12210   ** set, then the string is nul terminated. The MEM_Int and MEM_Real 
 12144  12211   ** flags may coexist with the MEM_Str flag.
 12145         -**
 12146         -** Multiple of these values can appear in Mem.flags.  But only one
 12147         -** at a time can appear in Mem.type.
 12148  12212   */
 12149  12213   #define MEM_Null      0x0001   /* Value is NULL */
 12150  12214   #define MEM_Str       0x0002   /* Value is a string */
 12151  12215   #define MEM_Int       0x0004   /* Value is an integer */
 12152  12216   #define MEM_Real      0x0008   /* Value is a real number */
 12153  12217   #define MEM_Blob      0x0010   /* Value is a BLOB */
 12154  12218   #define MEM_RowSet    0x0020   /* Value is a RowSet object */
................................................................................
 12223  12287     VdbeFunc *pVdbeFunc;  /* Auxilary data, if created. */
 12224  12288     Mem s;                /* The return value is stored here */
 12225  12289     Mem *pMem;            /* Memory cell used to store aggregate context */
 12226  12290     int isError;          /* Error code returned by the function. */
 12227  12291     CollSeq *pColl;       /* Collating sequence */
 12228  12292   };
 12229  12293   
 12230         -/*
 12231         -** A Set structure is used for quick testing to see if a value
 12232         -** is part of a small set.  Sets are used to implement code like
 12233         -** this:
 12234         -**            x.y IN ('hi','hoo','hum')
 12235         -*/
 12236         -typedef struct Set Set;
 12237         -struct Set {
 12238         -  Hash hash;             /* A set is just a hash table */
 12239         -  HashElem *prev;        /* Previously accessed hash elemen */
 12240         -};
 12241         -
 12242  12294   /*
 12243  12295   ** An instance of the virtual machine.  This structure contains the complete
 12244  12296   ** state of the virtual machine.
 12245  12297   **
 12246         -** The "sqlite3_stmt" structure pointer that is returned by sqlite3_compile()
        12298  +** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
 12247  12299   ** is really a pointer to an instance of this structure.
 12248  12300   **
 12249  12301   ** The Vdbe.inVtabMethod variable is set to non-zero for the duration of
 12250  12302   ** any virtual table method invocations made by the vdbe program. It is
 12251  12303   ** set to 2 for xDestroy method calls and 1 for all other methods. This
 12252  12304   ** variable is used for two purposes: to allow xDestroy methods to execute
 12253  12305   ** "DROP TABLE" statements and to prevent some nasty side effects of
 12254  12306   ** malloc failure when SQLite is invoked recursively by a virtual table 
 12255  12307   ** method function.
 12256  12308   */
 12257  12309   struct Vdbe {
 12258  12310     sqlite3 *db;            /* The database connection that owns this statement */
 12259         -  Vdbe *pPrev,*pNext;     /* Linked list of VDBEs with the same Vdbe.db */
 12260         -  int nOp;                /* Number of instructions in the program */
 12261         -  int nOpAlloc;           /* Number of slots allocated for aOp[] */
 12262  12311     Op *aOp;                /* Space to hold the virtual machine's program */
 12263         -  int nLabel;             /* Number of labels used */
 12264         -  int nLabelAlloc;        /* Number of slots allocated in aLabel[] */
 12265         -  int *aLabel;            /* Space to hold the labels */
        12312  +  Mem *aMem;              /* The memory locations */
 12266  12313     Mem **apArg;            /* Arguments to currently executing user function */
 12267  12314     Mem *aColName;          /* Column names to return */
 12268  12315     Mem *pResultSet;        /* Pointer to an array of results */
        12316  +  int nMem;               /* Number of memory locations currently allocated */
        12317  +  int nOp;                /* Number of instructions in the program */
        12318  +  int nOpAlloc;           /* Number of slots allocated for aOp[] */
        12319  +  int nLabel;             /* Number of labels used */
        12320  +  int nLabelAlloc;        /* Number of slots allocated in aLabel[] */
        12321  +  int *aLabel;            /* Space to hold the labels */
 12269  12322     u16 nResColumn;         /* Number of columns in one row of the result set */
 12270  12323     u16 nCursor;            /* Number of slots in apCsr[] */
        12324  +  u32 magic;              /* Magic number for sanity checking */
        12325  +  char *zErrMsg;          /* Error message written here */
        12326  +  Vdbe *pPrev,*pNext;     /* Linked list of VDBEs with the same Vdbe.db */
 12271  12327     VdbeCursor **apCsr;     /* One element of this array for each open cursor */
 12272         -  u8 errorAction;         /* Recovery action to do in case of an error */
 12273         -  u8 okVar;               /* True if azVar[] has been initialized */
 12274         -  ynVar nVar;             /* Number of entries in aVar[] */
 12275  12328     Mem *aVar;              /* Values for the OP_Variable opcode. */
 12276  12329     char **azVar;           /* Name of variables */
 12277         -  u32 magic;              /* Magic number for sanity checking */
 12278         -  int nMem;               /* Number of memory locations currently allocated */
 12279         -  Mem *aMem;              /* The memory locations */
        12330  +  ynVar nVar;             /* Number of entries in aVar[] */
 12280  12331     u32 cacheCtr;           /* VdbeCursor row cache generation counter */
 12281  12332     int pc;                 /* The program counter */
 12282  12333     int rc;                 /* Value to return */
 12283         -  char *zErrMsg;          /* Error message written here */
        12334  +  u8 errorAction;         /* Recovery action to do in case of an error */
        12335  +  u8 okVar;               /* True if azVar[] has been initialized */
 12284  12336     u8 explain;             /* True if EXPLAIN present on SQL command */
 12285  12337     u8 changeCntOn;         /* True to update the change-counter */
 12286  12338     u8 expired;             /* True if the VM needs to be recompiled */
 12287  12339     u8 runOnlyOnce;         /* Automatically expire on reset */
 12288  12340     u8 minWriteFileFormat;  /* Minimum file format for writable database files */
 12289  12341     u8 inVtabMethod;        /* See comments above */
 12290  12342     u8 usesStmtJournal;     /* True if uses a statement journal */
 12291  12343     u8 readOnly;            /* True for read-only statements */
 12292  12344     u8 isPrepareV2;         /* True if prepared with prepare_v2() */
 12293  12345     int nChange;            /* Number of db changes made since last reset */
 12294  12346     int btreeMask;          /* Bitmask of db->aDb[] entries referenced */
 12295         -  i64 startTime;          /* Time when query started - used for profiling */
 12296         -  BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
        12347  +  int iStatement;         /* Statement number (or 0 if has not opened stmt) */
 12297  12348     int aCounter[3];        /* Counters used by sqlite3_stmt_status() */
 12298         -  char *zSql;             /* Text of the SQL statement that generated this */
 12299         -  void *pFree;            /* Free this when deleting the vdbe */
        12349  +  BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
        12350  +#ifndef SQLITE_OMIT_TRACE
        12351  +  i64 startTime;          /* Time when query started - used for profiling */
        12352  +#endif
 12300  12353     i64 nFkConstraint;      /* Number of imm. FK constraints this VM */
 12301  12354     i64 nStmtDefCons;       /* Number of def. constraints when stmt started */
 12302         -  int iStatement;         /* Statement number (or 0 if has not opened stmt) */
        12355  +  char *zSql;             /* Text of the SQL statement that generated this */
        12356  +  void *pFree;            /* Free this when deleting the vdbe */
 12303  12357   #ifdef SQLITE_DEBUG
 12304  12358     FILE *trace;            /* Write an execution trace here, if not NULL */
 12305  12359   #endif
 12306  12360     VdbeFrame *pFrame;      /* Parent frame */
 12307  12361     VdbeFrame *pDelFrame;   /* List of frame objects to free on VM reset */
 12308  12362     int nFrame;             /* Number of frames in pFrame list */
 12309  12363     u32 expmask;            /* Binding to these vars invalidates VM */
................................................................................
 12504  12558         *pCurrent = db->lookaside.nOut;
 12505  12559         *pHighwater = db->lookaside.mxOut;
 12506  12560         if( resetFlag ){
 12507  12561           db->lookaside.mxOut = db->lookaside.nOut;
 12508  12562         }
 12509  12563         break;
 12510  12564       }
        12565  +
        12566  +    case SQLITE_DBSTATUS_LOOKASIDE_HIT:
        12567  +    case SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE:
        12568  +    case SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL: {
        12569  +      testcase( op==SQLITE_DBSTATUS_LOOKASIDE_HIT );
        12570  +      testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE );
        12571  +      testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL );
        12572  +      assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)>=0 );
        12573  +      assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)<3 );
        12574  +      *pCurrent = 0;
        12575  +      *pHighwater = db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT];
        12576  +      if( resetFlag ){
        12577  +        db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT] = 0;
        12578  +      }
        12579  +      break;
        12580  +    }
 12511  12581   
 12512  12582       /* 
 12513  12583       ** Return an approximation for the amount of memory currently used
 12514  12584       ** by all pagers associated with the given database connection.  The
 12515  12585       ** highwater mark is meaningless and is returned as zero.
 12516  12586       */
 12517  12587       case SQLITE_DBSTATUS_CACHE_USED: {
................................................................................
 16863  16933   ** <li>  SQLITE_MUTEX_FAST
 16864  16934   ** <li>  SQLITE_MUTEX_RECURSIVE
 16865  16935   ** <li>  SQLITE_MUTEX_STATIC_MASTER
 16866  16936   ** <li>  SQLITE_MUTEX_STATIC_MEM
 16867  16937   ** <li>  SQLITE_MUTEX_STATIC_MEM2
 16868  16938   ** <li>  SQLITE_MUTEX_STATIC_PRNG
 16869  16939   ** <li>  SQLITE_MUTEX_STATIC_LRU
 16870         -** <li>  SQLITE_MUTEX_STATIC_LRU2
        16940  +** <li>  SQLITE_MUTEX_STATIC_PMEM
 16871  16941   ** </ul>
 16872  16942   **
 16873  16943   ** The first two constants cause sqlite3_mutex_alloc() to create
 16874  16944   ** a new mutex.  The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
 16875  16945   ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
 16876  16946   ** The mutex implementation does not need to make a distinction
 16877  16947   ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
................................................................................
 17273  17343   ** <li>  SQLITE_MUTEX_FAST
 17274  17344   ** <li>  SQLITE_MUTEX_RECURSIVE
 17275  17345   ** <li>  SQLITE_MUTEX_STATIC_MASTER
 17276  17346   ** <li>  SQLITE_MUTEX_STATIC_MEM
 17277  17347   ** <li>  SQLITE_MUTEX_STATIC_MEM2
 17278  17348   ** <li>  SQLITE_MUTEX_STATIC_PRNG
 17279  17349   ** <li>  SQLITE_MUTEX_STATIC_LRU
 17280         -** <li>  SQLITE_MUTEX_STATIC_LRU2
        17350  +** <li>  SQLITE_MUTEX_STATIC_PMEM
 17281  17351   ** </ul>
 17282  17352   **
 17283  17353   ** The first two constants cause sqlite3_mutex_alloc() to create
 17284  17354   ** a new mutex.  The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
 17285  17355   ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
 17286  17356   ** The mutex implementation does not need to make a distinction
 17287  17357   ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
................................................................................
 18066  18136     assert( db==0 || db->pnBytesFreed==0 );
 18067  18137   #ifndef SQLITE_OMIT_LOOKASIDE
 18068  18138     if( db ){
 18069  18139       LookasideSlot *pBuf;
 18070  18140       if( db->mallocFailed ){
 18071  18141         return 0;
 18072  18142       }
 18073         -    if( db->lookaside.bEnabled && n<=db->lookaside.sz
 18074         -         && (pBuf = db->lookaside.pFree)!=0 ){
 18075         -      db->lookaside.pFree = pBuf->pNext;
 18076         -      db->lookaside.nOut++;
 18077         -      if( db->lookaside.nOut>db->lookaside.mxOut ){
 18078         -        db->lookaside.mxOut = db->lookaside.nOut;
        18143  +    if( db->lookaside.bEnabled ){
        18144  +      if( n>db->lookaside.sz ){
        18145  +        db->lookaside.anStat[1]++;
        18146  +      }else if( (pBuf = db->lookaside.pFree)==0 ){
        18147  +        db->lookaside.anStat[2]++;
        18148  +      }else{
        18149  +        db->lookaside.pFree = pBuf->pNext;
        18150  +        db->lookaside.nOut++;
        18151  +        db->lookaside.anStat[0]++;
        18152  +        if( db->lookaside.nOut>db->lookaside.mxOut ){
        18153  +          db->lookaside.mxOut = db->lookaside.nOut;
        18154  +        }
        18155  +        return (void*)pBuf;
 18079  18156         }
 18080         -      return (void*)pBuf;
 18081  18157       }
 18082  18158     }
 18083  18159   #else
 18084  18160     if( db && db->mallocFailed ){
 18085  18161       return 0;
 18086  18162     }
 18087  18163   #endif
................................................................................
 18985  19061       if( !p->useMalloc ){
 18986  19062         p->tooBig = 1;
 18987  19063         N = p->nAlloc - p->nChar - 1;
 18988  19064         if( N<=0 ){
 18989  19065           return;
 18990  19066         }
 18991  19067       }else{
        19068  +      char *zOld = (p->zText==p->zBase ? 0 : p->zText);
 18992  19069         i64 szNew = p->nChar;
 18993  19070         szNew += N + 1;
 18994  19071         if( szNew > p->mxAlloc ){
 18995  19072           sqlite3StrAccumReset(p);
 18996  19073           p->tooBig = 1;
 18997  19074           return;
 18998  19075         }else{
 18999  19076           p->nAlloc = (int)szNew;
 19000  19077         }
 19001  19078         if( p->useMalloc==1 ){
 19002         -        zNew = sqlite3DbMallocRaw(p->db, p->nAlloc );
        19079  +        zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
 19003  19080         }else{
 19004         -        zNew = sqlite3_malloc(p->nAlloc);
        19081  +        zNew = sqlite3_realloc(zOld, p->nAlloc);
 19005  19082         }
 19006  19083         if( zNew ){
 19007         -        memcpy(zNew, p->zText, p->nChar);
 19008         -        sqlite3StrAccumReset(p);
        19084  +        if( zOld==0 ) memcpy(zNew, p->zText, p->nChar);
 19009  19085           p->zText = zNew;
 19010  19086         }else{
 19011  19087           p->mallocFailed = 1;
 19012  19088           sqlite3StrAccumReset(p);
 19013  19089           return;
 19014  19090         }
 19015  19091       }
................................................................................
 19156  19232   }
 19157  19233   
 19158  19234   /*
 19159  19235   ** sqlite3_snprintf() works like snprintf() except that it ignores the
 19160  19236   ** current locale settings.  This is important for SQLite because we
 19161  19237   ** are not able to use a "," as the decimal point in place of "." as
 19162  19238   ** specified by some locales.
        19239  +**
        19240  +** Oops:  The first two arguments of sqlite3_snprintf() are backwards
        19241  +** from the snprintf() standard.  Unfortunately, it is too late to change
        19242  +** this without breaking compatibility, so we just have to live with the
        19243  +** mistake.
        19244  +**
        19245  +** sqlite3_vsnprintf() is the varargs version.
 19163  19246   */
        19247  +SQLITE_API char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){
        19248  +  StrAccum acc;
        19249  +  if( n<=0 ) return zBuf;
        19250  +  sqlite3StrAccumInit(&acc, zBuf, n, 0);
        19251  +  acc.useMalloc = 0;
        19252  +  sqlite3VXPrintf(&acc, 0, zFormat, ap);
        19253  +  return sqlite3StrAccumFinish(&acc);
        19254  +}
 19164  19255   SQLITE_API char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
 19165  19256     char *z;
 19166  19257     va_list ap;
 19167         -  StrAccum acc;
 19168         -
 19169         -  if( n<=0 ){
 19170         -    return zBuf;
 19171         -  }
 19172         -  sqlite3StrAccumInit(&acc, zBuf, n, 0);
 19173         -  acc.useMalloc = 0;
 19174  19258     va_start(ap,zFormat);
 19175         -  sqlite3VXPrintf(&acc, 0, zFormat, ap);
        19259  +  z = sqlite3_vsnprintf(n, zBuf, zFormat, ap);
 19176  19260     va_end(ap);
 19177         -  z = sqlite3StrAccumFinish(&acc);
 19178  19261     return z;
 19179  19262   }
 19180  19263   
 19181  19264   /*
 19182  19265   ** This is the routine that actually formats the sqlite3_log() message.
 19183  19266   ** We house it in a separate routine from sqlite3_log() to avoid using
 19184  19267   ** stack space on small-stack systems when logging is disabled.
................................................................................
 22185  22268       case SQLITE_FCNTL_LOCKSTATE: {
 22186  22269         *(int*)pArg = ((os2File*)id)->locktype;
 22187  22270         OSTRACE(( "FCNTL_LOCKSTATE %d lock=%d\n",
 22188  22271                   ((os2File*)id)->h, ((os2File*)id)->locktype ));
 22189  22272         return SQLITE_OK;
 22190  22273       }
 22191  22274     }
 22192         -  return SQLITE_ERROR;
        22275  +  return SQLITE_NOTFOUND;
 22193  22276   }
 22194  22277   
 22195  22278   /*
 22196  22279   ** Return the sector size in bytes of the underlying block device for
 22197  22280   ** the specified file. This is almost always 512 bytes, but may be
 22198  22281   ** larger for some devices.
 22199  22282   **
................................................................................
 22901  22984   */
 22902  22985   #include <sys/types.h>
 22903  22986   #include <sys/stat.h>
 22904  22987   #include <fcntl.h>
 22905  22988   #include <unistd.h>
 22906  22989   #include <sys/time.h>
 22907  22990   #include <errno.h>
        22991  +#ifndef SQLITE_OMIT_WAL
 22908  22992   #include <sys/mman.h>
        22993  +#endif
 22909  22994   
 22910  22995   #if SQLITE_ENABLE_LOCKING_STYLE
 22911  22996   # include <sys/ioctl.h>
 22912  22997   # if OS_VXWORKS
 22913  22998   #  include <semaphore.h>
 22914  22999   #  include <limits.h>
 22915  23000   # else
................................................................................
 26119  26204   #endif
 26120  26205   #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
 26121  26206       case SQLITE_SET_LOCKPROXYFILE:
 26122  26207       case SQLITE_GET_LOCKPROXYFILE: {
 26123  26208         return proxyFileControl(id,op,pArg);
 26124  26209       }
 26125  26210   #endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */
        26211  +    case SQLITE_FCNTL_SYNC_OMITTED: {
        26212  +      return SQLITE_OK;  /* A no-op */
        26213  +    }
 26126  26214     }
 26127         -  return SQLITE_ERROR;
        26215  +  return SQLITE_NOTFOUND;
 26128  26216   }
 26129  26217   
 26130  26218   /*
 26131  26219   ** Return the sector size in bytes of the underlying block device for
 26132  26220   ** the specified file. This is almost always 512 bytes, but may be
 26133  26221   ** larger for some devices.
 26134  26222   **
................................................................................
 28389  28477   /* Not always defined in the headers as it ought to be */
 28390  28478   extern int gethostuuid(uuid_t id, const struct timespec *wait);
 28391  28479   
 28392  28480   /* get the host ID via gethostuuid(), pHostID must point to PROXY_HOSTIDLEN 
 28393  28481   ** bytes of writable memory.
 28394  28482   */
 28395  28483   static int proxyGetHostID(unsigned char *pHostID, int *pError){
 28396         -  struct timespec timeout = {1, 0}; /* 1 sec timeout */
 28397         -  
 28398  28484     assert(PROXY_HOSTIDLEN == sizeof(uuid_t));
 28399  28485     memset(pHostID, 0, PROXY_HOSTIDLEN);
 28400  28486   #if defined(__MAX_OS_X_VERSION_MIN_REQUIRED)\
 28401  28487                  && __MAC_OS_X_VERSION_MIN_REQUIRED<1050
 28402         -  if( gethostuuid(pHostID, &timeout) ){
 28403         -    int err = errno;
 28404         -    if( pError ){
 28405         -      *pError = err;
        28488  +  {
        28489  +    static const struct timespec timeout = {1, 0}; /* 1 sec timeout */
        28490  +    if( gethostuuid(pHostID, &timeout) ){
        28491  +      int err = errno;
        28492  +      if( pError ){
        28493  +        *pError = err;
        28494  +      }
        28495  +      return SQLITE_IOERR;
 28406  28496       }
 28407         -    return SQLITE_IOERR;
 28408  28497     }
 28409  28498   #endif
 28410  28499   #ifdef SQLITE_TEST
 28411  28500     /* simulate multiple hosts by creating unique hostid file paths */
 28412  28501     if( sqlite3_hostid_num != 0){
 28413  28502       pHostID[0] = (char)(pHostID[0] + (char)(sqlite3_hostid_num & 0xFF));
 28414  28503     }
................................................................................
 30706  30795       case SQLITE_FCNTL_SIZE_HINT: {
 30707  30796         sqlite3_int64 sz = *(sqlite3_int64*)pArg;
 30708  30797         SimulateIOErrorBenign(1);
 30709  30798         winTruncate(id, sz);
 30710  30799         SimulateIOErrorBenign(0);
 30711  30800         return SQLITE_OK;
 30712  30801       }
        30802  +    case SQLITE_FCNTL_SYNC_OMITTED: {
        30803  +      return SQLITE_OK;
        30804  +    }
 30713  30805     }
 30714         -  return SQLITE_ERROR;
        30806  +  return SQLITE_NOTFOUND;
 30715  30807   }
 30716  30808   
 30717  30809   /*
 30718  30810   ** Return the sector size in bytes of the underlying block device for
 30719  30811   ** the specified file. This is almost always 512 bytes, but may be
 30720  30812   ** larger for some devices.
 30721  30813   **
................................................................................
 33327  33419   ** these two features are available.
 33328  33420   */
 33329  33421   
 33330  33422   
 33331  33423   typedef struct PCache1 PCache1;
 33332  33424   typedef struct PgHdr1 PgHdr1;
 33333  33425   typedef struct PgFreeslot PgFreeslot;
        33426  +typedef struct PGroup PGroup;
        33427  +
        33428  +/* Each page cache (or PCache) belongs to a PGroup.  A PGroup is a set 
        33429  +** of one or more PCaches that are able to recycle each others unpinned
        33430  +** pages when they are under memory pressure.  A PGroup is an instance of
        33431  +** the following object.
        33432  +**
        33433  +** This page cache implementation works in one of two modes:
        33434  +**
        33435  +**   (1)  Every PCache is the sole member of its own PGroup.  There is
        33436  +**        one PGroup per PCache.
        33437  +**
        33438  +**   (2)  There is a single global PGroup that all PCaches are a member
        33439  +**        of.
        33440  +**
        33441  +** Mode 1 uses more memory (since PCache instances are not able to rob
        33442  +** unused pages from other PCaches) but it also operates without a mutex,
        33443  +** and is therefore often faster.  Mode 2 requires a mutex in order to be
        33444  +** threadsafe, but is able recycle pages more efficient.
        33445  +**
        33446  +** For mode (1), PGroup.mutex is NULL.  For mode (2) there is only a single
        33447  +** PGroup which is the pcache1.grp global variable and its mutex is
        33448  +** SQLITE_MUTEX_STATIC_LRU.
        33449  +*/
        33450  +struct PGroup {
        33451  +  sqlite3_mutex *mutex;          /* MUTEX_STATIC_LRU or NULL */
        33452  +  int nMaxPage;                  /* Sum of nMax for purgeable caches */
        33453  +  int nMinPage;                  /* Sum of nMin for purgeable caches */
        33454  +  int mxPinned;                  /* nMaxpage + 10 - nMinPage */
        33455  +  int nCurrentPage;              /* Number of purgeable pages allocated */
        33456  +  PgHdr1 *pLruHead, *pLruTail;   /* LRU list of unpinned pages */
        33457  +};
 33334  33458   
 33335  33459   /* Each page cache is an instance of the following object.  Every
 33336  33460   ** open database file (including each in-memory database and each
 33337  33461   ** temporary or transient database) has a single page cache which
 33338  33462   ** is an instance of this object.
 33339  33463   **
 33340  33464   ** Pointers to structures of this type are cast and returned as 
 33341  33465   ** opaque sqlite3_pcache* handles.
 33342  33466   */
 33343  33467   struct PCache1 {
 33344  33468     /* Cache configuration parameters. Page size (szPage) and the purgeable
 33345  33469     ** flag (bPurgeable) are set when the cache is created. nMax may be 
 33346  33470     ** modified at any time by a call to the pcache1CacheSize() method.
 33347         -  ** The global mutex must be held when accessing nMax.
        33471  +  ** The PGroup mutex must be held when accessing nMax.
 33348  33472     */
        33473  +  PGroup *pGroup;                     /* PGroup this cache belongs to */
 33349  33474     int szPage;                         /* Size of allocated pages in bytes */
 33350  33475     int bPurgeable;                     /* True if cache is purgeable */
 33351  33476     unsigned int nMin;                  /* Minimum number of pages reserved */
 33352  33477     unsigned int nMax;                  /* Configured "cache_size" value */
        33478  +  unsigned int n90pct;                /* nMax*9/10 */
 33353  33479   
 33354  33480     /* Hash table of all pages. The following variables may only be accessed
 33355         -  ** when the accessor is holding the global mutex (see pcache1EnterMutex() 
 33356         -  ** and pcache1LeaveMutex()).
        33481  +  ** when the accessor is holding the PGroup mutex.
 33357  33482     */
 33358  33483     unsigned int nRecyclable;           /* Number of pages in the LRU list */
 33359  33484     unsigned int nPage;                 /* Total number of pages in apHash */
 33360  33485     unsigned int nHash;                 /* Number of slots in apHash[] */
 33361  33486     PgHdr1 **apHash;                    /* Hash table for fast lookup by key */
 33362  33487   
 33363  33488     unsigned int iMaxKey;               /* Largest key seen since xTruncate() */
................................................................................
 33385  33510     PgFreeslot *pNext;  /* Next free slot */
 33386  33511   };
 33387  33512   
 33388  33513   /*
 33389  33514   ** Global data used by this cache.
 33390  33515   */
 33391  33516   static SQLITE_WSD struct PCacheGlobal {
 33392         -  sqlite3_mutex *mutex;               /* static mutex MUTEX_STATIC_LRU */
        33517  +  PGroup grp;                    /* The global PGroup for mode (2) */
 33393  33518   
 33394         -  int nMaxPage;                       /* Sum of nMaxPage for purgeable caches */
 33395         -  int nMinPage;                       /* Sum of nMinPage for purgeable caches */
 33396         -  int nCurrentPage;                   /* Number of purgeable pages allocated */
 33397         -  PgHdr1 *pLruHead, *pLruTail;        /* LRU list of unpinned pages */
 33398         -
 33399         -  /* Variables related to SQLITE_CONFIG_PAGECACHE settings. */
 33400         -  int szSlot;                         /* Size of each free slot */
 33401         -  int nSlot;                          /* The number of pcache slots */
 33402         -  int nFreeSlot;                      /* Number of unused pcache slots */
 33403         -  int nReserve;                       /* Try to keep nFreeSlot above this */
 33404         -  void *pStart, *pEnd;                /* Bounds of pagecache malloc range */
 33405         -  PgFreeslot *pFree;                  /* Free page blocks */
 33406         -  int isInit;                         /* True if initialized */
        33519  +  /* Variables related to SQLITE_CONFIG_PAGECACHE settings.  The
        33520  +  ** szSlot, nSlot, pStart, pEnd, nReserve, and isInit values are all
        33521  +  ** fixed at sqlite3_initialize() time and do not require mutex protection.
        33522  +  ** The nFreeSlot and pFree values do require mutex protection.
        33523  +  */
        33524  +  int isInit;                    /* True if initialized */
        33525  +  int szSlot;                    /* Size of each free slot */
        33526  +  int nSlot;                     /* The number of pcache slots */
        33527  +  int nReserve;                  /* Try to keep nFreeSlot above this */
        33528  +  void *pStart, *pEnd;           /* Bounds of pagecache malloc range */
        33529  +  /* Above requires no mutex.  Use mutex below for variable that follow. */
        33530  +  sqlite3_mutex *mutex;          /* Mutex for accessing the following: */
        33531  +  int nFreeSlot;                 /* Number of unused pcache slots */
        33532  +  PgFreeslot *pFree;             /* Free page blocks */
        33533  +  /* The following value requires a mutex to change.  We skip the mutex on
        33534  +  ** reading because (1) most platforms read a 32-bit integer atomically and
        33535  +  ** (2) even if an incorrect value is read, no great harm is done since this
        33536  +  ** is really just an optimization. */
        33537  +  int bUnderPressure;            /* True if low on PAGECACHE memory */
 33407  33538   } pcache1_g;
 33408  33539   
 33409  33540   /*
 33410  33541   ** All code in this file should access the global structure above via the
 33411  33542   ** alias "pcache1". This ensures that the WSD emulation is used when
 33412  33543   ** compiling for systems that do not support real WSD.
 33413  33544   */
................................................................................
 33425  33556   **
 33426  33557   **   assert( PGHDR1_TO_PAGE(PAGE_TO_PGHDR1(pCache, X))==X );
 33427  33558   */
 33428  33559   #define PGHDR1_TO_PAGE(p)    (void*)(((char*)p) - p->pCache->szPage)
 33429  33560   #define PAGE_TO_PGHDR1(c, p) (PgHdr1*)(((char*)p) + c->szPage)
 33430  33561   
 33431  33562   /*
 33432         -** Macros to enter and leave the global LRU mutex.
        33563  +** Macros to enter and leave the PCache LRU mutex.
 33433  33564   */
 33434         -#define pcache1EnterMutex() sqlite3_mutex_enter(pcache1.mutex)
 33435         -#define pcache1LeaveMutex() sqlite3_mutex_leave(pcache1.mutex)
        33565  +#define pcache1EnterMutex(X) sqlite3_mutex_enter((X)->mutex)
        33566  +#define pcache1LeaveMutex(X) sqlite3_mutex_leave((X)->mutex)
 33436  33567   
 33437  33568   /******************************************************************************/
 33438  33569   /******** Page Allocation/SQLITE_CONFIG_PCACHE Related Functions **************/
 33439  33570   
 33440  33571   /*
 33441  33572   ** This function is called during initialization if a static buffer is 
 33442  33573   ** supplied to use for the page-cache by passing the SQLITE_CONFIG_PAGECACHE
 33443  33574   ** verb to sqlite3_config(). Parameter pBuf points to an allocation large
 33444  33575   ** enough to contain 'n' buffers of 'sz' bytes each.
        33576  +**
        33577  +** This routine is called from sqlite3_initialize() and so it is guaranteed
        33578  +** to be serialized already.  There is no need for further mutexing.
 33445  33579   */
 33446  33580   SQLITE_PRIVATE void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){
 33447  33581     if( pcache1.isInit ){
 33448  33582       PgFreeslot *p;
 33449  33583       sz = ROUNDDOWN8(sz);
 33450  33584       pcache1.szSlot = sz;
 33451  33585       pcache1.nSlot = pcache1.nFreeSlot = n;
 33452  33586       pcache1.nReserve = n>90 ? 10 : (n/10 + 1);
 33453  33587       pcache1.pStart = pBuf;
 33454  33588       pcache1.pFree = 0;
        33589  +    pcache1.bUnderPressure = 0;
 33455  33590       while( n-- ){
 33456  33591         p = (PgFreeslot*)pBuf;
 33457  33592         p->pNext = pcache1.pFree;
 33458  33593         pcache1.pFree = p;
 33459  33594         pBuf = (void*)&((char*)pBuf)[sz];
 33460  33595       }
 33461  33596       pcache1.pEnd = pBuf;
................................................................................
 33463  33598   }
 33464  33599   
 33465  33600   /*
 33466  33601   ** Malloc function used within this file to allocate space from the buffer
 33467  33602   ** configured using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no 
 33468  33603   ** such buffer exists or there is no space left in it, this function falls 
 33469  33604   ** back to sqlite3Malloc().
        33605  +**
        33606  +** Multiple threads can run this routine at the same time.  Global variables
        33607  +** in pcache1 need to be protected via mutex.
 33470  33608   */
 33471  33609   static void *pcache1Alloc(int nByte){
 33472         -  void *p;
 33473         -  assert( sqlite3_mutex_held(pcache1.mutex) );
        33610  +  void *p = 0;
        33611  +  assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
 33474  33612     sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
 33475         -  if( nByte<=pcache1.szSlot && pcache1.pFree ){
 33476         -    assert( pcache1.isInit );
        33613  +  if( nByte<=pcache1.szSlot ){
        33614  +    sqlite3_mutex_enter(pcache1.mutex);
 33477  33615       p = (PgHdr1 *)pcache1.pFree;
 33478         -    pcache1.pFree = pcache1.pFree->pNext;
 33479         -    pcache1.nFreeSlot--;
 33480         -    assert( pcache1.nFreeSlot>=0 );
 33481         -    sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1);
 33482         -  }else{
 33483         -
 33484         -    /* Allocate a new buffer using sqlite3Malloc. Before doing so, exit the
 33485         -    ** global pcache mutex and unlock the pager-cache object pCache. This is 
 33486         -    ** so that if the attempt to allocate a new buffer causes the the 
 33487         -    ** configured soft-heap-limit to be breached, it will be possible to
 33488         -    ** reclaim memory from this pager-cache.
        33616  +    if( p ){
        33617  +      pcache1.pFree = pcache1.pFree->pNext;
        33618  +      pcache1.nFreeSlot--;
        33619  +      pcache1.bUnderPressure = pcache1.nFreeSlot<pcache1.nReserve;
        33620  +      assert( pcache1.nFreeSlot>=0 );
        33621  +      sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1);
        33622  +    }
        33623  +    sqlite3_mutex_leave(pcache1.mutex);
        33624  +  }
        33625  +  if( p==0 ){
        33626  +    /* Memory is not available in the SQLITE_CONFIG_PAGECACHE pool.  Get
        33627  +    ** it from sqlite3Malloc instead.
 33489  33628       */
 33490         -    pcache1LeaveMutex();
 33491  33629       p = sqlite3Malloc(nByte);
 33492         -    pcache1EnterMutex();
 33493  33630       if( p ){
 33494  33631         int sz = sqlite3MallocSize(p);
        33632  +      sqlite3_mutex_enter(pcache1.mutex);
 33495  33633         sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
        33634  +      sqlite3_mutex_leave(pcache1.mutex);
 33496  33635       }
 33497  33636       sqlite3MemdebugSetType(p, MEMTYPE_PCACHE);
 33498  33637     }
 33499  33638     return p;
 33500  33639   }
 33501  33640   
 33502  33641   /*
 33503  33642   ** Free an allocated buffer obtained from pcache1Alloc().
 33504  33643   */
 33505  33644   static void pcache1Free(void *p){
 33506         -  assert( sqlite3_mutex_held(pcache1.mutex) );
 33507  33645     if( p==0 ) return;
 33508  33646     if( p>=pcache1.pStart && p<pcache1.pEnd ){
 33509  33647       PgFreeslot *pSlot;
        33648  +    sqlite3_mutex_enter(pcache1.mutex);
 33510  33649       sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1);
 33511  33650       pSlot = (PgFreeslot*)p;
 33512  33651       pSlot->pNext = pcache1.pFree;
 33513  33652       pcache1.pFree = pSlot;
 33514  33653       pcache1.nFreeSlot++;
        33654  +    pcache1.bUnderPressure = pcache1.nFreeSlot<pcache1.nReserve;
 33515  33655       assert( pcache1.nFreeSlot<=pcache1.nSlot );
        33656  +    sqlite3_mutex_leave(pcache1.mutex);
 33516  33657     }else{
 33517  33658       int iSize;
 33518  33659       assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) );
 33519  33660       sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
 33520  33661       iSize = sqlite3MallocSize(p);
        33662  +    sqlite3_mutex_enter(pcache1.mutex);
 33521  33663       sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize);
        33664  +    sqlite3_mutex_leave(pcache1.mutex);
 33522  33665       sqlite3_free(p);
 33523  33666     }
 33524  33667   }
 33525  33668   
 33526  33669   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
 33527  33670   /*
 33528  33671   ** Return the size of a pcache allocation
 33529  33672   */
 33530  33673   static int pcache1MemSize(void *p){
 33531         -  assert( sqlite3_mutex_held(pcache1.mutex) );
 33532  33674     if( p>=pcache1.pStart && p<pcache1.pEnd ){
 33533  33675       return pcache1.szSlot;
 33534  33676     }else{
 33535  33677       int iSize;
 33536  33678       assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) );
 33537  33679       sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
 33538  33680       iSize = sqlite3MallocSize(p);
................................................................................
 33548  33690   static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
 33549  33691     int nByte = sizeof(PgHdr1) + pCache->szPage;
 33550  33692     void *pPg = pcache1Alloc(nByte);
 33551  33693     PgHdr1 *p;
 33552  33694     if( pPg ){
 33553  33695       p = PAGE_TO_PGHDR1(pCache, pPg);
 33554  33696       if( pCache->bPurgeable ){
 33555         -      pcache1.nCurrentPage++;
        33697  +      pCache->pGroup->nCurrentPage++;
 33556  33698       }
 33557  33699     }else{
 33558  33700       p = 0;
 33559  33701     }
 33560  33702     return p;
 33561  33703   }
 33562  33704   
................................................................................
 33565  33707   **
 33566  33708   ** The pointer is allowed to be NULL, which is prudent.  But it turns out
 33567  33709   ** that the current implementation happens to never call this routine
 33568  33710   ** with a NULL pointer, so we mark the NULL test with ALWAYS().
 33569  33711   */
 33570  33712   static void pcache1FreePage(PgHdr1 *p){
 33571  33713     if( ALWAYS(p) ){
 33572         -    if( p->pCache->bPurgeable ){
 33573         -      pcache1.nCurrentPage--;
        33714  +    PCache1 *pCache = p->pCache;
        33715  +    if( pCache->bPurgeable ){
        33716  +      pCache->pGroup->nCurrentPage--;
 33574  33717       }
 33575  33718       pcache1Free(PGHDR1_TO_PAGE(p));
 33576  33719     }
 33577  33720   }
 33578  33721   
 33579  33722   /*
 33580  33723   ** Malloc function used by SQLite to obtain space from the buffer configured
 33581  33724   ** using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no such buffer
 33582  33725   ** exists, this function falls back to sqlite3Malloc().
 33583  33726   */
 33584  33727   SQLITE_PRIVATE void *sqlite3PageMalloc(int sz){
 33585         -  void *p;
 33586         -  pcache1EnterMutex();
 33587         -  p = pcache1Alloc(sz);
 33588         -  pcache1LeaveMutex();
 33589         -  return p;
        33728  +  return pcache1Alloc(sz);
 33590  33729   }
 33591  33730   
 33592  33731   /*
 33593  33732   ** Free an allocated buffer obtained from sqlite3PageMalloc().
 33594  33733   */
 33595  33734   SQLITE_PRIVATE void sqlite3PageFree(void *p){
 33596         -  pcache1EnterMutex();
 33597  33735     pcache1Free(p);
 33598         -  pcache1LeaveMutex();
 33599  33736   }
 33600  33737   
 33601  33738   
 33602  33739   /*
 33603  33740   ** Return true if it desirable to avoid allocating a new page cache
 33604  33741   ** entry.
 33605  33742   **
................................................................................
 33612  33749   **
 33613  33750   ** Or, the heap is used for all page cache memory put the heap is
 33614  33751   ** under memory pressure, then again it is desirable to avoid
 33615  33752   ** allocating a new page cache entry in order to avoid stressing
 33616  33753   ** the heap even further.
 33617  33754   */
 33618  33755   static int pcache1UnderMemoryPressure(PCache1 *pCache){
 33619         -  assert( sqlite3_mutex_held(pcache1.mutex) );
 33620  33756     if( pcache1.nSlot && pCache->szPage<=pcache1.szSlot ){
 33621         -    return pcache1.nFreeSlot<pcache1.nReserve;
        33757  +    return pcache1.bUnderPressure;
 33622  33758     }else{
 33623  33759       return sqlite3HeapNearlyFull();
 33624  33760     }
 33625  33761   }
 33626  33762   
 33627  33763   /******************************************************************************/
 33628  33764   /******** General Implementation Functions ************************************/
 33629  33765   
 33630  33766   /*
 33631  33767   ** This function is used to resize the hash table used by the cache passed
 33632  33768   ** as the first argument.
 33633  33769   **
 33634         -** The global mutex must be held when this function is called.
        33770  +** The PCache mutex must be held when this function is called.
 33635  33771   */
 33636  33772   static int pcache1ResizeHash(PCache1 *p){
 33637  33773     PgHdr1 **apNew;
 33638  33774     unsigned int nNew;
 33639  33775     unsigned int i;
 33640  33776   
 33641         -  assert( sqlite3_mutex_held(pcache1.mutex) );
        33777  +  assert( sqlite3_mutex_held(p->pGroup->mutex) );
 33642  33778   
 33643  33779     nNew = p->nHash*2;
 33644  33780     if( nNew<256 ){
 33645  33781       nNew = 256;
 33646  33782     }
 33647  33783   
 33648         -  pcache1LeaveMutex();
        33784  +  pcache1LeaveMutex(p->pGroup);
 33649  33785     if( p->nHash ){ sqlite3BeginBenignMalloc(); }
 33650  33786     apNew = (PgHdr1 **)sqlite3_malloc(sizeof(PgHdr1 *)*nNew);
 33651  33787     if( p->nHash ){ sqlite3EndBenignMalloc(); }
 33652         -  pcache1EnterMutex();
        33788  +  pcache1EnterMutex(p->pGroup);
 33653  33789     if( apNew ){
 33654  33790       memset(apNew, 0, sizeof(PgHdr1 *)*nNew);
 33655  33791       for(i=0; i<p->nHash; i++){
 33656  33792         PgHdr1 *pPage;
 33657  33793         PgHdr1 *pNext = p->apHash[i];
 33658  33794         while( (pPage = pNext)!=0 ){
 33659  33795           unsigned int h = pPage->iKey % nNew;
................................................................................
 33668  33804     }
 33669  33805   
 33670  33806     return (p->apHash ? SQLITE_OK : SQLITE_NOMEM);
 33671  33807   }
 33672  33808   
 33673  33809   /*
 33674  33810   ** This function is used internally to remove the page pPage from the 
 33675         -** global LRU list, if is part of it. If pPage is not part of the global
        33811  +** PGroup LRU list, if is part of it. If pPage is not part of the PGroup
 33676  33812   ** LRU list, then this function is a no-op.
 33677  33813   **
 33678         -** The global mutex must be held when this function is called.
        33814  +** The PGroup mutex must be held when this function is called.
        33815  +**
        33816  +** If pPage is NULL then this routine is a no-op.
 33679  33817   */
 33680  33818   static void pcache1PinPage(PgHdr1 *pPage){
 33681         -  assert( sqlite3_mutex_held(pcache1.mutex) );
 33682         -  if( pPage && (pPage->pLruNext || pPage==pcache1.pLruTail) ){
        33819  +  PCache1 *pCache;
        33820  +  PGroup *pGroup;
        33821  +
        33822  +  if( pPage==0 ) return;
        33823  +  pCache = pPage->pCache;
        33824  +  pGroup = pCache->pGroup;
        33825  +  assert( sqlite3_mutex_held(pGroup->mutex) );
        33826  +  if( pPage->pLruNext || pPage==pGroup->pLruTail ){
 33683  33827       if( pPage->pLruPrev ){
 33684  33828         pPage->pLruPrev->pLruNext = pPage->pLruNext;
 33685  33829       }
 33686  33830       if( pPage->pLruNext ){
 33687  33831         pPage->pLruNext->pLruPrev = pPage->pLruPrev;
 33688  33832       }
 33689         -    if( pcache1.pLruHead==pPage ){
 33690         -      pcache1.pLruHead = pPage->pLruNext;
        33833  +    if( pGroup->pLruHead==pPage ){
        33834  +      pGroup->pLruHead = pPage->pLruNext;
 33691  33835       }
 33692         -    if( pcache1.pLruTail==pPage ){
 33693         -      pcache1.pLruTail = pPage->pLruPrev;
        33836  +    if( pGroup->pLruTail==pPage ){
        33837  +      pGroup->pLruTail = pPage->pLruPrev;
 33694  33838       }
 33695  33839       pPage->pLruNext = 0;
 33696  33840       pPage->pLruPrev = 0;
 33697  33841       pPage->pCache->nRecyclable--;
 33698  33842     }
 33699  33843   }
 33700  33844   
 33701  33845   
 33702  33846   /*
 33703  33847   ** Remove the page supplied as an argument from the hash table 
 33704  33848   ** (PCache1.apHash structure) that it is currently stored in.
 33705  33849   **
 33706         -** The global mutex must be held when this function is called.
        33850  +** The PGroup mutex must be held when this function is called.
 33707  33851   */
 33708  33852   static void pcache1RemoveFromHash(PgHdr1 *pPage){
 33709  33853     unsigned int h;
 33710  33854     PCache1 *pCache = pPage->pCache;
 33711  33855     PgHdr1 **pp;
 33712  33856   
        33857  +  assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
 33713  33858     h = pPage->iKey % pCache->nHash;
 33714  33859     for(pp=&pCache->apHash[h]; (*pp)!=pPage; pp=&(*pp)->pNext);
 33715  33860     *pp = (*pp)->pNext;
 33716  33861   
 33717  33862     pCache->nPage--;
 33718  33863   }
 33719  33864   
 33720  33865   /*
 33721         -** If there are currently more than pcache.nMaxPage pages allocated, try
 33722         -** to recycle pages to reduce the number allocated to pcache.nMaxPage.
        33866  +** If there are currently more than nMaxPage pages allocated, try
        33867  +** to recycle pages to reduce the number allocated to nMaxPage.
 33723  33868   */
 33724         -static void pcache1EnforceMaxPage(void){
 33725         -  assert( sqlite3_mutex_held(pcache1.mutex) );
 33726         -  while( pcache1.nCurrentPage>pcache1.nMaxPage && pcache1.pLruTail ){
 33727         -    PgHdr1 *p = pcache1.pLruTail;
        33869  +static void pcache1EnforceMaxPage(PGroup *pGroup){
        33870  +  assert( sqlite3_mutex_held(pGroup->mutex) );
        33871  +  while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){
        33872  +    PgHdr1 *p = pGroup->pLruTail;
        33873  +    assert( p->pCache->pGroup==pGroup );
 33728  33874       pcache1PinPage(p);
 33729  33875       pcache1RemoveFromHash(p);
 33730  33876       pcache1FreePage(p);
 33731  33877     }
 33732  33878   }
 33733  33879   
 33734  33880   /*
 33735  33881   ** Discard all pages from cache pCache with a page number (key value) 
 33736  33882   ** greater than or equal to iLimit. Any pinned pages that meet this 
 33737  33883   ** criteria are unpinned before they are discarded.
 33738  33884   **
 33739         -** The global mutex must be held when this function is called.
        33885  +** The PCache mutex must be held when this function is called.
 33740  33886   */
 33741  33887   static void pcache1TruncateUnsafe(
 33742         -  PCache1 *pCache, 
 33743         -  unsigned int iLimit 
        33888  +  PCache1 *pCache,             /* The cache to truncate */
        33889  +  unsigned int iLimit          /* Drop pages with this pgno or larger */
 33744  33890   ){
 33745         -  TESTONLY( unsigned int nPage = 0; )      /* Used to assert pCache->nPage is correct */
        33891  +  TESTONLY( unsigned int nPage = 0; )  /* To assert pCache->nPage is correct */
 33746  33892     unsigned int h;
 33747         -  assert( sqlite3_mutex_held(pcache1.mutex) );
        33893  +  assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
 33748  33894     for(h=0; h<pCache->nHash; h++){
 33749  33895       PgHdr1 **pp = &pCache->apHash[h]; 
 33750  33896       PgHdr1 *pPage;
 33751  33897       while( (pPage = *pp)!=0 ){
 33752  33898         if( pPage->iKey>=iLimit ){
 33753  33899           pCache->nPage--;
 33754  33900           *pp = pPage->pNext;
................................................................................
 33770  33916   ** Implementation of the sqlite3_pcache.xInit method.
 33771  33917   */
 33772  33918   static int pcache1Init(void *NotUsed){
 33773  33919     UNUSED_PARAMETER(NotUsed);
 33774  33920     assert( pcache1.isInit==0 );
 33775  33921     memset(&pcache1, 0, sizeof(pcache1));
 33776  33922     if( sqlite3GlobalConfig.bCoreMutex ){
 33777         -    pcache1.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU);
        33923  +    pcache1.grp.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU);
        33924  +    pcache1.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PMEM);
 33778  33925     }
        33926  +  pcache1.grp.mxPinned = 10;
 33779  33927     pcache1.isInit = 1;
 33780  33928     return SQLITE_OK;
 33781  33929   }
 33782  33930   
 33783  33931   /*
 33784  33932   ** Implementation of the sqlite3_pcache.xShutdown method.
 33785  33933   ** Note that the static mutex allocated in xInit does 
................................................................................
 33793  33941   
 33794  33942   /*
 33795  33943   ** Implementation of the sqlite3_pcache.xCreate method.
 33796  33944   **
 33797  33945   ** Allocate a new cache.
 33798  33946   */
 33799  33947   static sqlite3_pcache *pcache1Create(int szPage, int bPurgeable){
 33800         -  PCache1 *pCache;
        33948  +  PCache1 *pCache;      /* The newly created page cache */
        33949  +  PGroup *pGroup;       /* The group the new page cache will belong to */
        33950  +  int sz;               /* Bytes of memory required to allocate the new cache */
 33801  33951   
 33802         -  pCache = (PCache1 *)sqlite3_malloc(sizeof(PCache1));
        33952  +  /*
        33953  +  ** The seperateCache variable is true if each PCache has its own private
        33954  +  ** PGroup.  In other words, separateCache is true for mode (1) where no
        33955  +  ** mutexing is required.
        33956  +  **
        33957  +  **   *  Always use a unified cache (mode-2) if ENABLE_MEMORY_MANAGEMENT
        33958  +  **
        33959  +  **   *  Always use a unified cache in single-threaded applications
        33960  +  **
        33961  +  **   *  Otherwise (if multi-threaded and ENABLE_MEMORY_MANAGEMENT is off)
        33962  +  **      use separate caches (mode-1)
        33963  +  */
        33964  +#if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) || SQLITE_THREADSAFE==0
        33965  +  const int separateCache = 0;
        33966  +#else
        33967  +  int separateCache = sqlite3GlobalConfig.bCoreMutex>0;
        33968  +#endif
        33969  +
        33970  +  sz = sizeof(PCache1) + sizeof(PGroup)*separateCache;
        33971  +  pCache = (PCache1 *)sqlite3_malloc(sz);
 33803  33972     if( pCache ){
 33804         -    memset(pCache, 0, sizeof(PCache1));
        33973  +    memset(pCache, 0, sz);
        33974  +    if( separateCache ){
        33975  +      pGroup = (PGroup*)&pCache[1];
        33976  +      pGroup->mxPinned = 10;
        33977  +    }else{
        33978  +      pGroup = &pcache1_g.grp;
        33979  +    }
        33980  +    pCache->pGroup = pGroup;
 33805  33981       pCache->szPage = szPage;
 33806  33982       pCache->bPurgeable = (bPurgeable ? 1 : 0);
 33807  33983       if( bPurgeable ){
 33808  33984         pCache->nMin = 10;
 33809         -      pcache1EnterMutex();
 33810         -      pcache1.nMinPage += pCache->nMin;
 33811         -      pcache1LeaveMutex();
        33985  +      pcache1EnterMutex(pGroup);
        33986  +      pGroup->nMinPage += pCache->nMin;
        33987  +      pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
        33988  +      pcache1LeaveMutex(pGroup);
 33812  33989       }
 33813  33990     }
 33814  33991     return (sqlite3_pcache *)pCache;
 33815  33992   }
 33816  33993   
 33817  33994   /*
 33818  33995   ** Implementation of the sqlite3_pcache.xCachesize method. 
 33819  33996   **
 33820  33997   ** Configure the cache_size limit for a cache.
 33821  33998   */
 33822  33999   static void pcache1Cachesize(sqlite3_pcache *p, int nMax){
 33823  34000     PCache1 *pCache = (PCache1 *)p;
 33824  34001     if( pCache->bPurgeable ){
 33825         -    pcache1EnterMutex();
 33826         -    pcache1.nMaxPage += (nMax - pCache->nMax);
        34002  +    PGroup *pGroup = pCache->pGroup;
        34003  +    pcache1EnterMutex(pGroup);
        34004  +    pGroup->nMaxPage += (nMax - pCache->nMax);
        34005  +    pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
 33827  34006       pCache->nMax = nMax;
 33828         -    pcache1EnforceMaxPage();
 33829         -    pcache1LeaveMutex();
        34007  +    pCache->n90pct = pCache->nMax*9/10;
        34008  +    pcache1EnforceMaxPage(pGroup);
        34009  +    pcache1LeaveMutex(pGroup);
 33830  34010     }
 33831  34011   }
 33832  34012   
 33833  34013   /*
 33834  34014   ** Implementation of the sqlite3_pcache.xPagecount method. 
 33835  34015   */
 33836  34016   static int pcache1Pagecount(sqlite3_pcache *p){
 33837  34017     int n;
 33838         -  pcache1EnterMutex();
 33839         -  n = ((PCache1 *)p)->nPage;
 33840         -  pcache1LeaveMutex();
        34018  +  PCache1 *pCache = (PCache1*)p;
        34019  +  pcache1EnterMutex(pCache->pGroup);
        34020  +  n = pCache->nPage;
        34021  +  pcache1LeaveMutex(pCache->pGroup);
 33841  34022     return n;
 33842  34023   }
 33843  34024   
 33844  34025   /*
 33845  34026   ** Implementation of the sqlite3_pcache.xFetch method. 
 33846  34027   **
 33847  34028   ** Fetch a page by key value.
................................................................................
 33892  34073   **      then attempt to recycle a page from the LRU list. If it is the right
 33893  34074   **      size, return the recycled buffer. Otherwise, free the buffer and
 33894  34075   **      proceed to step 5. 
 33895  34076   **
 33896  34077   **   5. Otherwise, allocate and return a new page buffer.
 33897  34078   */
 33898  34079   static void *pcache1Fetch(sqlite3_pcache *p, unsigned int iKey, int createFlag){
 33899         -  unsigned int nPinned;
        34080  +  int nPinned;
 33900  34081     PCache1 *pCache = (PCache1 *)p;
        34082  +  PGroup *pGroup;
 33901  34083     PgHdr1 *pPage = 0;
 33902  34084   
 33903  34085     assert( pCache->bPurgeable || createFlag!=1 );
 33904         -  pcache1EnterMutex();
 33905         -  if( createFlag==1 ) sqlite3BeginBenignMalloc();
        34086  +  assert( pCache->bPurgeable || pCache->nMin==0 );
        34087  +  assert( pCache->bPurgeable==0 || pCache->nMin==10 );
        34088  +  assert( pCache->nMin==0 || pCache->bPurgeable );
        34089  +  pcache1EnterMutex(pGroup = pCache->pGroup);
 33906  34090   
 33907         -  /* Search the hash table for an existing entry. */
        34091  +  /* Step 1: Search the hash table for an existing entry. */
 33908  34092     if( pCache->nHash>0 ){
 33909  34093       unsigned int h = iKey % pCache->nHash;
 33910  34094       for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext);
 33911  34095     }
 33912  34096   
        34097  +  /* Step 2: Abort if no existing page is found and createFlag is 0 */
 33913  34098     if( pPage || createFlag==0 ){
 33914  34099       pcache1PinPage(pPage);
 33915  34100       goto fetch_out;
 33916  34101     }
 33917  34102   
 33918         -  /* Step 3 of header comment. */
        34103  +  /* The pGroup local variable will normally be initialized by the
        34104  +  ** pcache1EnterMutex() macro above.  But if SQLITE_MUTEX_OMIT is defined,
        34105  +  ** then pcache1EnterMutex() is a no-op, so we have to initialize the
        34106  +  ** local variable here.  Delaying the initialization of pGroup is an
        34107  +  ** optimization:  The common case is to exit the module before reaching
        34108  +  ** this point.
        34109  +  */
        34110  +#ifdef SQLITE_MUTEX_OMIT
        34111  +  pGroup = pCache->pGroup;
        34112  +#endif
        34113  +
        34114  +
        34115  +  /* Step 3: Abort if createFlag is 1 but the cache is nearly full */
 33919  34116     nPinned = pCache->nPage - pCache->nRecyclable;
        34117  +  assert( nPinned>=0 );
        34118  +  assert( pGroup->mxPinned == pGroup->nMaxPage + 10 - pGroup->nMinPage );
        34119  +  assert( pCache->n90pct == pCache->nMax*9/10 );
 33920  34120     if( createFlag==1 && (
 33921         -        nPinned>=(pcache1.nMaxPage+pCache->nMin-pcache1.nMinPage)
 33922         -     || nPinned>=(pCache->nMax * 9 / 10)
        34121  +        nPinned>=pGroup->mxPinned
        34122  +     || nPinned>=(int)pCache->n90pct
 33923  34123        || pcache1UnderMemoryPressure(pCache)
 33924  34124     )){
 33925  34125       goto fetch_out;
 33926  34126     }
 33927  34127   
 33928  34128     if( pCache->nPage>=pCache->nHash && pcache1ResizeHash(pCache) ){
 33929  34129       goto fetch_out;
 33930  34130     }
 33931  34131   
 33932         -  /* Step 4. Try to recycle a page buffer if appropriate. */
 33933         -  if( pCache->bPurgeable && pcache1.pLruTail && (
        34132  +  /* Step 4. Try to recycle a page. */
        34133  +  if( pCache->bPurgeable && pGroup->pLruTail && (
 33934  34134            (pCache->nPage+1>=pCache->nMax)
 33935         -      || pcache1.nCurrentPage>=pcache1.nMaxPage
        34135  +      || pGroup->nCurrentPage>=pGroup->nMaxPage
 33936  34136         || pcache1UnderMemoryPressure(pCache)
 33937  34137     )){
 33938         -    pPage = pcache1.pLruTail;
        34138  +    PCache1 *pOtherCache;
        34139  +    pPage = pGroup->pLruTail;
 33939  34140       pcache1RemoveFromHash(pPage);
 33940  34141       pcache1PinPage(pPage);
 33941         -    if( pPage->pCache->szPage!=pCache->szPage ){
        34142  +    if( (pOtherCache = pPage->pCache)->szPage!=pCache->szPage ){
 33942  34143         pcache1FreePage(pPage);
 33943  34144         pPage = 0;
 33944  34145       }else{
 33945         -      pcache1.nCurrentPage -= (pPage->pCache->bPurgeable - pCache->bPurgeable);
        34146  +      pGroup->nCurrentPage -= 
        34147  +               (pOtherCache->bPurgeable - pCache->bPurgeable);
 33946  34148       }
 33947  34149     }
 33948  34150   
 33949  34151     /* Step 5. If a usable page buffer has still not been found, 
 33950  34152     ** attempt to allocate a new one. 
 33951  34153     */
 33952  34154     if( !pPage ){
        34155  +    if( createFlag==1 ) sqlite3BeginBenignMalloc();
        34156  +    pcache1LeaveMutex(pGroup);
 33953  34157       pPage = pcache1AllocPage(pCache);
        34158  +    pcache1EnterMutex(pGroup);
        34159  +    if( createFlag==1 ) sqlite3EndBenignMalloc();
 33954  34160     }
 33955  34161   
 33956  34162     if( pPage ){
 33957  34163       unsigned int h = iKey % pCache->nHash;
 33958  34164       pCache->nPage++;
 33959  34165       pPage->iKey = iKey;
 33960  34166       pPage->pNext = pCache->apHash[h];
................................................................................
 33965  34171       pCache->apHash[h] = pPage;
 33966  34172     }
 33967  34173   
 33968  34174   fetch_out:
 33969  34175     if( pPage && iKey>pCache->iMaxKey ){
 33970  34176       pCache->iMaxKey = iKey;
 33971  34177     }
 33972         -  if( createFlag==1 ) sqlite3EndBenignMalloc();
 33973         -  pcache1LeaveMutex();
        34178  +  pcache1LeaveMutex(pGroup);
 33974  34179     return (pPage ? PGHDR1_TO_PAGE(pPage) : 0);
 33975  34180   }
 33976  34181   
 33977  34182   
 33978  34183   /*
 33979  34184   ** Implementation of the sqlite3_pcache.xUnpin method.
 33980  34185   **
 33981  34186   ** Mark a page as unpinned (eligible for asynchronous recycling).
 33982  34187   */
 33983  34188   static void pcache1Unpin(sqlite3_pcache *p, void *pPg, int reuseUnlikely){
 33984  34189     PCache1 *pCache = (PCache1 *)p;
 33985  34190     PgHdr1 *pPage = PAGE_TO_PGHDR1(pCache, pPg);
        34191  +  PGroup *pGroup = pCache->pGroup;
 33986  34192    
 33987  34193     assert( pPage->pCache==pCache );
 33988         -  pcache1EnterMutex();
        34194  +  pcache1EnterMutex(pGroup);
 33989  34195   
 33990  34196     /* It is an error to call this function if the page is already 
 33991         -  ** part of the global LRU list.
        34197  +  ** part of the PGroup LRU list.
 33992  34198     */
 33993  34199     assert( pPage->pLruPrev==0 && pPage->pLruNext==0 );
 33994         -  assert( pcache1.pLruHead!=pPage && pcache1.pLruTail!=pPage );
        34200  +  assert( pGroup->pLruHead!=pPage && pGroup->pLruTail!=pPage );
 33995  34201   
 33996         -  if( reuseUnlikely || pcache1.nCurrentPage>pcache1.nMaxPage ){
        34202  +  if( reuseUnlikely || pGroup->nCurrentPage>pGroup->nMaxPage ){
 33997  34203       pcache1RemoveFromHash(pPage);
 33998  34204       pcache1FreePage(pPage);
 33999  34205     }else{
 34000         -    /* Add the page to the global LRU list. Normally, the page is added to
 34001         -    ** the head of the list (last page to be recycled). However, if the 
 34002         -    ** reuseUnlikely flag passed to this function is true, the page is added
 34003         -    ** to the tail of the list (first page to be recycled).
 34004         -    */
 34005         -    if( pcache1.pLruHead ){
 34006         -      pcache1.pLruHead->pLruPrev = pPage;
 34007         -      pPage->pLruNext = pcache1.pLruHead;
 34008         -      pcache1.pLruHead = pPage;
        34206  +    /* Add the page to the PGroup LRU list. */
        34207  +    if( pGroup->pLruHead ){
        34208  +      pGroup->pLruHead->pLruPrev = pPage;
        34209  +      pPage->pLruNext = pGroup->pLruHead;
        34210  +      pGroup->pLruHead = pPage;
 34009  34211       }else{
 34010         -      pcache1.pLruTail = pPage;
 34011         -      pcache1.pLruHead = pPage;
        34212  +      pGroup->pLruTail = pPage;
        34213  +      pGroup->pLruHead = pPage;
 34012  34214       }
 34013  34215       pCache->nRecyclable++;
 34014  34216     }
 34015  34217   
 34016         -  pcache1LeaveMutex();
        34218  +  pcache1LeaveMutex(pCache->pGroup);
 34017  34219   }
 34018  34220   
 34019  34221   /*
 34020  34222   ** Implementation of the sqlite3_pcache.xRekey method. 
 34021  34223   */
 34022  34224   static void pcache1Rekey(
 34023  34225     sqlite3_pcache *p,
................................................................................
 34028  34230     PCache1 *pCache = (PCache1 *)p;
 34029  34231     PgHdr1 *pPage = PAGE_TO_PGHDR1(pCache, pPg);
 34030  34232     PgHdr1 **pp;
 34031  34233     unsigned int h; 
 34032  34234     assert( pPage->iKey==iOld );
 34033  34235     assert( pPage->pCache==pCache );
 34034  34236   
 34035         -  pcache1EnterMutex();
        34237  +  pcache1EnterMutex(pCache->pGroup);
 34036  34238   
 34037  34239     h = iOld%pCache->nHash;
 34038  34240     pp = &pCache->apHash[h];
 34039  34241     while( (*pp)!=pPage ){
 34040  34242       pp = &(*pp)->pNext;
 34041  34243     }
 34042  34244     *pp = pPage->pNext;
................................................................................
 34045  34247     pPage->iKey = iNew;
 34046  34248     pPage->pNext = pCache->apHash[h];
 34047  34249     pCache->apHash[h] = pPage;
 34048  34250     if( iNew>pCache->iMaxKey ){
 34049  34251       pCache->iMaxKey = iNew;
 34050  34252     }
 34051  34253   
 34052         -  pcache1LeaveMutex();
        34254  +  pcache1LeaveMutex(pCache->pGroup);
 34053  34255   }
 34054  34256   
 34055  34257   /*
 34056  34258   ** Implementation of the sqlite3_pcache.xTruncate method. 
 34057  34259   **
 34058  34260   ** Discard all unpinned pages in the cache with a page number equal to
 34059  34261   ** or greater than parameter iLimit. Any pinned pages with a page number
 34060  34262   ** equal to or greater than iLimit are implicitly unpinned.
 34061  34263   */
 34062  34264   static void pcache1Truncate(sqlite3_pcache *p, unsigned int iLimit){
 34063  34265     PCache1 *pCache = (PCache1 *)p;
 34064         -  pcache1EnterMutex();
        34266  +  pcache1EnterMutex(pCache->pGroup);
 34065  34267     if( iLimit<=pCache->iMaxKey ){
 34066  34268       pcache1TruncateUnsafe(pCache, iLimit);
 34067  34269       pCache->iMaxKey = iLimit-1;
 34068  34270     }
 34069         -  pcache1LeaveMutex();
        34271  +  pcache1LeaveMutex(pCache->pGroup);
 34070  34272   }
 34071  34273   
 34072  34274   /*
 34073  34275   ** Implementation of the sqlite3_pcache.xDestroy method. 
 34074  34276   **
 34075  34277   ** Destroy a cache allocated using pcache1Create().
 34076  34278   */
 34077  34279   static void pcache1Destroy(sqlite3_pcache *p){
 34078  34280     PCache1 *pCache = (PCache1 *)p;
        34281  +  PGroup *pGroup = pCache->pGroup;
 34079  34282     assert( pCache->bPurgeable || (pCache->nMax==0 && pCache->nMin==0) );
 34080         -  pcache1EnterMutex();
        34283  +  pcache1EnterMutex(pGroup);
 34081  34284     pcache1TruncateUnsafe(pCache, 0);
 34082         -  pcache1.nMaxPage -= pCache->nMax;
 34083         -  pcache1.nMinPage -= pCache->nMin;
 34084         -  pcache1EnforceMaxPage();
 34085         -  pcache1LeaveMutex();
        34285  +  pGroup->nMaxPage -= pCache->nMax;
        34286  +  pGroup->nMinPage -= pCache->nMin;
        34287  +  pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
        34288  +  pcache1EnforceMaxPage(pGroup);
        34289  +  pcache1LeaveMutex(pGroup);
 34086  34290     sqlite3_free(pCache->apHash);
 34087  34291     sqlite3_free(pCache);
 34088  34292   }
 34089  34293   
 34090  34294   /*
 34091  34295   ** This function is called during initialization (sqlite3_initialize()) to
 34092  34296   ** install the default pluggable cache module, assuming the user has not
................................................................................
 34117  34321   **
 34118  34322   ** nReq is the number of bytes of memory required. Once this much has
 34119  34323   ** been released, the function returns. The return value is the total number 
 34120  34324   ** of bytes of memory released.
 34121  34325   */
 34122  34326   SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
 34123  34327     int nFree = 0;
        34328  +  assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
        34329  +  assert( sqlite3_mutex_notheld(pcache1.mutex) );
 34124  34330     if( pcache1.pStart==0 ){
 34125  34331       PgHdr1 *p;
 34126         -    pcache1EnterMutex();
 34127         -    while( (nReq<0 || nFree<nReq) && ((p=pcache1.pLruTail)!=0) ){
        34332  +    pcache1EnterMutex(&pcache1.grp);
        34333  +    while( (nReq<0 || nFree<nReq) && ((p=pcache1.grp.pLruTail)!=0) ){
 34128  34334         nFree += pcache1MemSize(PGHDR1_TO_PAGE(p));
 34129  34335         pcache1PinPage(p);
 34130  34336         pcache1RemoveFromHash(p);
 34131  34337         pcache1FreePage(p);
 34132  34338       }
 34133         -    pcache1LeaveMutex();
        34339  +    pcache1LeaveMutex(&pcache1.grp);
 34134  34340     }
 34135  34341     return nFree;
 34136  34342   }
 34137  34343   #endif /* SQLITE_ENABLE_MEMORY_MANAGEMENT */
 34138  34344   
 34139  34345   #ifdef SQLITE_TEST
 34140  34346   /*
................................................................................
 34145  34351     int *pnCurrent,      /* OUT: Total number of pages cached */
 34146  34352     int *pnMax,          /* OUT: Global maximum cache size */
 34147  34353     int *pnMin,          /* OUT: Sum of PCache1.nMin for purgeable caches */
 34148  34354     int *pnRecyclable    /* OUT: Total number of pages available for recycling */
 34149  34355   ){
 34150  34356     PgHdr1 *p;
 34151  34357     int nRecyclable = 0;
 34152         -  for(p=pcache1.pLruHead; p; p=p->pLruNext){
        34358  +  for(p=pcache1.grp.pLruHead; p; p=p->pLruNext){
 34153  34359       nRecyclable++;
 34154  34360     }
 34155         -  *pnCurrent = pcache1.nCurrentPage;
 34156         -  *pnMax = pcache1.nMaxPage;
 34157         -  *pnMin = pcache1.nMinPage;
        34361  +  *pnCurrent = pcache1.grp.nCurrentPage;
        34362  +  *pnMax = pcache1.grp.nMaxPage;
        34363  +  *pnMin = pcache1.grp.nMinPage;
 34158  34364     *pnRecyclable = nRecyclable;
 34159  34365   }
 34160  34366   #endif
 34161  34367   
 34162  34368   /************** End of pcache1.c *********************************************/
 34163  34369   /************** Begin file rowset.c ******************************************/
 34164  34370   /*
................................................................................
 37175  37381     assert( pPager->eState!=PAGER_ERROR );
 37176  37382     assert( pPager->eState!=PAGER_READER );
 37177  37383     
 37178  37384     if( isOpen(pPager->fd) 
 37179  37385      && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN) 
 37180  37386     ){
 37181  37387       i64 currentSize, newSize;
        37388  +    int szPage = pPager->pageSize;
 37182  37389       assert( pPager->eLock==EXCLUSIVE_LOCK );
 37183  37390       /* TODO: Is it safe to use Pager.dbFileSize here? */
 37184  37391       rc = sqlite3OsFileSize(pPager->fd, &currentSize);
 37185         -    newSize = pPager->pageSize*(i64)nPage;
        37392  +    newSize = szPage*(i64)nPage;
 37186  37393       if( rc==SQLITE_OK && currentSize!=newSize ){
 37187  37394         if( currentSize>newSize ){
 37188  37395           rc = sqlite3OsTruncate(pPager->fd, newSize);
 37189  37396         }else{
 37190         -        rc = sqlite3OsWrite(pPager->fd, "", 1, newSize-1);
        37397  +        char *pTmp = pPager->pTmpSpace;
        37398  +        memset(pTmp, 0, szPage);
        37399  +        testcase( (newSize-szPage) <  currentSize );
        37400  +        testcase( (newSize-szPage) == currentSize );
        37401  +        testcase( (newSize-szPage) >  currentSize );
        37402  +        rc = sqlite3OsWrite(pPager->fd, pTmp, szPage, newSize-szPage);
 37191  37403         }
 37192  37404         if( rc==SQLITE_OK ){
 37193  37405           pPager->dbFileSize = nPage;
 37194  37406         }
 37195  37407       }
 37196  37408     }
 37197  37409     return rc;
................................................................................
 37447  37659     pPager->changeCountDone = pPager->tempFile;
 37448  37660   
 37449  37661     if( rc==SQLITE_OK ){
 37450  37662       zMaster = pPager->pTmpSpace;
 37451  37663       rc = readMasterJournal(pPager->jfd, zMaster, pPager->pVfs->mxPathname+1);
 37452  37664       testcase( rc!=SQLITE_OK );
 37453  37665     }
 37454         -  if( rc==SQLITE_OK && !pPager->noSync 
        37666  +  if( rc==SQLITE_OK
 37455  37667      && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
 37456  37668     ){
 37457         -    rc = sqlite3OsSync(pPager->fd, pPager->syncFlags);
        37669  +    rc = sqlite3PagerSync(pPager);
 37458  37670     }
 37459  37671     if( rc==SQLITE_OK ){
 37460  37672       rc = pager_end_transaction(pPager, zMaster[0]!='\0');
 37461  37673       testcase( rc!=SQLITE_OK );
 37462  37674     }
 37463  37675     if( rc==SQLITE_OK && zMaster[0] && res ){
 37464  37676       /* If there was a master journal and this routine will return success,
................................................................................
 37613  37825       rc = pagerUndoCallback((void *)pPager, pList->pgno);
 37614  37826       pList = pNext;
 37615  37827     }
 37616  37828   
 37617  37829     return rc;
 37618  37830   }
 37619  37831   
        37832  +
        37833  +/*
        37834  +** Update the value of the change-counter at offsets 24 and 92 in
        37835  +** the header and the sqlite version number at offset 96.
        37836  +**
        37837  +** This is an unconditional update.  See also the pager_incr_changecounter()
        37838  +** routine which only updates the change-counter if the update is actually
        37839  +** needed, as determined by the pPager->changeCountDone state variable.
        37840  +*/
        37841  +static void pager_write_changecounter(PgHdr *pPg){
        37842  +  u32 change_counter;
        37843  +
        37844  +  /* Increment the value just read and write it back to byte 24. */
        37845  +  change_counter = sqlite3Get4byte((u8*)pPg->pPager->dbFileVers)+1;
        37846  +  put32bits(((char*)pPg->pData)+24, change_counter);
        37847  +
        37848  +  /* Also store the SQLite version number in bytes 96..99 and in
        37849  +  ** bytes 92..95 store the change counter for which the version number
        37850  +  ** is valid. */
        37851  +  put32bits(((char*)pPg->pData)+92, change_counter);
        37852  +  put32bits(((char*)pPg->pData)+96, SQLITE_VERSION_NUMBER);
        37853  +}
        37854  +
 37620  37855   /*
 37621  37856   ** This function is a wrapper around sqlite3WalFrames(). As well as logging
 37622  37857   ** the contents of the list of pages headed by pList (connected by pDirty),
 37623  37858   ** this function notifies any active backup processes that the pages have
 37624         -** changed. 
        37859  +** changed.
        37860  +**
        37861  +** The list of pages passed into this routine is always sorted by page number.
        37862  +** Hence, if page 1 appears anywhere on the list, it will be the first page.
 37625  37863   */ 
 37626  37864   static int pagerWalFrames(
 37627  37865     Pager *pPager,                  /* Pager object */
 37628  37866     PgHdr *pList,                   /* List of frames to log */
 37629  37867     Pgno nTruncate,                 /* Database size after this commit */
 37630  37868     int isCommit,                   /* True if this is a commit */
 37631  37869     int syncFlags                   /* Flags to pass to OsSync() (or 0) */
 37632  37870   ){
 37633  37871     int rc;                         /* Return code */
        37872  +#if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES)
        37873  +  PgHdr *p;                       /* For looping over pages */
        37874  +#endif
 37634  37875   
 37635  37876     assert( pPager->pWal );
        37877  +#ifdef SQLITE_DEBUG
        37878  +  /* Verify that the page list is in accending order */
        37879  +  for(p=pList; p && p->pDirty; p=p->pDirty){
        37880  +    assert( p->pgno < p->pDirty->pgno );
        37881  +  }
        37882  +#endif
        37883  +
        37884  +  if( pList->pgno==1 ) pager_write_changecounter(pList);
 37636  37885     rc = sqlite3WalFrames(pPager->pWal, 
 37637  37886         pPager->pageSize, pList, nTruncate, isCommit, syncFlags
 37638  37887     );
 37639  37888     if( rc==SQLITE_OK && pPager->pBackup ){
 37640  37889       PgHdr *p;
 37641  37890       for(p=pList; p; p=p->pDirty){
 37642  37891         sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData);
 37643  37892       }
 37644  37893     }
 37645  37894   
 37646  37895   #ifdef SQLITE_CHECK_PAGES
 37647         -  {
 37648         -    PgHdr *p;
 37649         -    for(p=pList; p; p=p->pDirty) pager_set_pagehash(p);
        37896  +  for(p=pList; p; p=p->pDirty){
        37897  +    pager_set_pagehash(p);
 37650  37898     }
 37651  37899   #endif
 37652  37900   
 37653  37901     return rc;
 37654  37902   }
 37655  37903   
 37656  37904   /*
................................................................................
 38667  38915       ** set (set by sqlite3PagerDontWrite()).
 38668  38916       */
 38669  38917       if( pgno<=pPager->dbSize && 0==(pList->flags&PGHDR_DONT_WRITE) ){
 38670  38918         i64 offset = (pgno-1)*(i64)pPager->pageSize;   /* Offset to write */
 38671  38919         char *pData;                                   /* Data to write */    
 38672  38920   
 38673  38921         assert( (pList->flags&PGHDR_NEED_SYNC)==0 );
        38922  +      if( pList->pgno==1 ) pager_write_changecounter(pList);
 38674  38923   
 38675  38924         /* Encode the database */
 38676  38925         CODEC2(pPager, pList->pData, pgno, 6, return SQLITE_NOMEM, pData);
 38677  38926   
 38678  38927         /* Write out the page data. */
 38679  38928         rc = sqlite3OsWrite(pPager->fd, pData, pPager->pageSize, offset);
 38680  38929   
................................................................................
 40187  40436       pager_set_pagehash(pPg);
 40188  40437     }
 40189  40438   }
 40190  40439   
 40191  40440   /*
 40192  40441   ** This routine is called to increment the value of the database file 
 40193  40442   ** change-counter, stored as a 4-byte big-endian integer starting at 
 40194         -** byte offset 24 of the pager file.
        40443  +** byte offset 24 of the pager file.  The secondary change counter at
        40444  +** 92 is also updated, as is the SQLite version number at offset 96.
        40445  +**
        40446  +** But this only happens if the pPager->changeCountDone flag is false.
        40447  +** To avoid excess churning of page 1, the update only happens once.
        40448  +** See also the pager_write_changecounter() routine that does an 
        40449  +** unconditional update of the change counters.
 40195  40450   **
 40196  40451   ** If the isDirectMode flag is zero, then this is done by calling 
 40197  40452   ** sqlite3PagerWrite() on page 1, then modifying the contents of the
 40198  40453   ** page data. In this case the file will be updated when the current
 40199  40454   ** transaction is committed.
 40200  40455   **
 40201  40456   ** The isDirectMode flag may only be non-zero if the library was compiled
................................................................................
 40228  40483     UNUSED_PARAMETER(isDirectMode);
 40229  40484   #else
 40230  40485   # define DIRECT_MODE isDirectMode
 40231  40486   #endif
 40232  40487   
 40233  40488     if( !pPager->changeCountDone && pPager->dbSize>0 ){
 40234  40489       PgHdr *pPgHdr;                /* Reference to page 1 */
 40235         -    u32 change_counter;           /* Initial value of change-counter field */
 40236  40490   
 40237  40491       assert( !pPager->tempFile && isOpen(pPager->fd) );
 40238  40492   
 40239  40493       /* Open page 1 of the file for writing. */
 40240  40494       rc = sqlite3PagerGet(pPager, 1, &pPgHdr);
 40241  40495       assert( pPgHdr==0 || rc==SQLITE_OK );
 40242  40496   
................................................................................
 40246  40500       ** above is always successful - hence the ALWAYS on rc==SQLITE_OK.
 40247  40501       */
 40248  40502       if( !DIRECT_MODE && ALWAYS(rc==SQLITE_OK) ){
 40249  40503         rc = sqlite3PagerWrite(pPgHdr);
 40250  40504       }
 40251  40505   
 40252  40506       if( rc==SQLITE_OK ){
 40253         -      /* Increment the value just read and write it back to byte 24. */
 40254         -      change_counter = sqlite3Get4byte((u8*)pPager->dbFileVers);
 40255         -      change_counter++;
 40256         -      put32bits(((char*)pPgHdr->pData)+24, change_counter);
 40257         -
 40258         -      /* Also store the SQLite version number in bytes 96..99 and in
 40259         -      ** bytes 92..95 store the change counter for which the version number
 40260         -      ** is valid. */
 40261         -      put32bits(((char*)pPgHdr->pData)+92, change_counter);
 40262         -      put32bits(((char*)pPgHdr->pData)+96, SQLITE_VERSION_NUMBER);
        40507  +      /* Actually do the update of the change counter */
        40508  +      pager_write_changecounter(pPgHdr);
 40263  40509   
 40264  40510         /* If running in direct mode, write the contents of page 1 to the file. */
 40265  40511         if( DIRECT_MODE ){
 40266  40512           const void *zBuf;
 40267  40513           assert( pPager->dbFileSize>0 );
 40268  40514           CODEC2(pPager, pPgHdr->pData, 1, 6, rc=SQLITE_NOMEM, zBuf);
 40269  40515           if( rc==SQLITE_OK ){
................................................................................
 40287  40533   ** Sync the database file to disk. This is a no-op for in-memory databases
 40288  40534   ** or pages with the Pager.noSync flag set.
 40289  40535   **
 40290  40536   ** If successful, or if called on a pager for which it is a no-op, this
 40291  40537   ** function returns SQLITE_OK. Otherwise, an IO error code is returned.
 40292  40538   */
 40293  40539   SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager){
 40294         -  int rc;                              /* Return code */
 40295         -  assert( !MEMDB );
 40296         -  if( pPager->noSync ){
 40297         -    rc = SQLITE_OK;
 40298         -  }else{
        40540  +  int rc = SQLITE_OK;
        40541  +  if( !pPager->noSync ){
        40542  +    assert( !MEMDB );
 40299  40543       rc = sqlite3OsSync(pPager->fd, pPager->syncFlags);
        40544  +  }else if( isOpen(pPager->fd) ){
        40545  +    assert( !MEMDB );
        40546  +    sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC_OMITTED, (void *)&rc);
 40300  40547     }
 40301  40548     return rc;
 40302  40549   }
 40303  40550   
 40304  40551   /*
 40305  40552   ** This function may only be called while a write-transaction is active in
 40306  40553   ** rollback. If the connection is in WAL mode, this call is a no-op. 
................................................................................
 40511  40758           Pgno nNew = pPager->dbSize - (pPager->dbSize==PAGER_MJ_PGNO(pPager));
 40512  40759           assert( pPager->eState==PAGER_WRITER_DBMOD );
 40513  40760           rc = pager_truncate(pPager, nNew);
 40514  40761           if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
 40515  40762         }
 40516  40763     
 40517  40764         /* Finally, sync the database file. */
 40518         -      if( !pPager->noSync && !noSync ){
 40519         -        rc = sqlite3OsSync(pPager->fd, pPager->syncFlags);
        40765  +      if( !noSync ){
        40766  +        rc = sqlite3PagerSync(pPager);
 40520  40767         }
 40521  40768         IOTRACE(("DBSYNC %p\n", pPager))
 40522  40769       }
 40523  40770     }
 40524  40771   
 40525  40772   commit_phase_one_exit:
 40526  40773     if( rc==SQLITE_OK && !pagerUseWal(pPager) ){
................................................................................
 40624  40871   
 40625  40872     if( pagerUseWal(pPager) ){
 40626  40873       int rc2;
 40627  40874       rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_ROLLBACK, -1);
 40628  40875       rc2 = pager_end_transaction(pPager, pPager->setMaster);
 40629  40876       if( rc==SQLITE_OK ) rc = rc2;
 40630  40877     }else if( !isOpen(pPager->jfd) || pPager->eState==PAGER_WRITER_LOCKED ){
        40878  +    int eState = pPager->eState;
 40631  40879       rc = pager_end_transaction(pPager, 0);
        40880  +    if( !MEMDB && eState>PAGER_WRITER_LOCKED ){
        40881  +      /* This can happen using journal_mode=off. Move the pager to the error 
        40882  +      ** state to indicate that the contents of the cache may not be trusted.
        40883  +      ** Any active readers will get SQLITE_ABORT.
        40884  +      */
        40885  +      pPager->errCode = SQLITE_ABORT;
        40886  +      pPager->eState = PAGER_ERROR;
        40887  +      return rc;
        40888  +    }
 40632  40889     }else{
 40633  40890       rc = pager_playback(pPager, 0);
 40634  40891     }
 40635  40892   
 40636  40893     assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK );
 40637  40894     assert( rc==SQLITE_OK || rc==SQLITE_FULL || (rc&0xFF)==SQLITE_IOERR );
 40638  40895   
................................................................................
 41894  42151   **   walIteratorNext() - Step an iterator,
 41895  42152   **   walIteratorFree() - Free an iterator.
 41896  42153   **
 41897  42154   ** This functionality is used by the checkpoint code (see walCheckpoint()).
 41898  42155   */
 41899  42156   struct WalIterator {
 41900  42157     int iPrior;                     /* Last result returned from the iterator */
 41901         -  int nSegment;                   /* Size of the aSegment[] array */
        42158  +  int nSegment;                   /* Number of entries in aSegment[] */
 41902  42159     struct WalSegment {
 41903  42160       int iNext;                    /* Next slot in aIndex[] not yet returned */
 41904  42161       ht_slot *aIndex;              /* i0, i1, i2... such that aPgno[iN] ascend */
 41905  42162       u32 *aPgno;                   /* Array of page numbers. */
 41906         -    int nEntry;                   /* Max size of aPgno[] and aIndex[] arrays */
        42163  +    int nEntry;                   /* Nr. of entries in aPgno[] and aIndex[] */
 41907  42164       int iZero;                    /* Frame number associated with aPgno[0] */
 41908         -  } aSegment[1];                  /* One for every 32KB page in the WAL */
        42165  +  } aSegment[1];                  /* One for every 32KB page in the wal-index */
 41909  42166   };
 41910  42167   
 41911  42168   /*
 41912  42169   ** Define the parameters of the hash tables in the wal-index file. There
 41913  42170   ** is a hash-table following every HASHTABLE_NPAGE page numbers in the
 41914  42171   ** wal-index.
 41915  42172   **
................................................................................
 42765  43022   
 42766  43023     *piPage = p->iPrior = iRet;
 42767  43024     return (iRet==0xFFFFFFFF);
 42768  43025   }
 42769  43026   
 42770  43027   /*
 42771  43028   ** This function merges two sorted lists into a single sorted list.
        43029  +**
        43030  +** aLeft[] and aRight[] are arrays of indices.  The sort key is
        43031  +** aContent[aLeft[]] and aContent[aRight[]].  Upon entry, the following
        43032  +** is guaranteed for all J<K:
        43033  +**
        43034  +**        aContent[aLeft[J]] < aContent[aLeft[K]]
        43035  +**        aContent[aRight[J]] < aContent[aRight[K]]
        43036  +**
        43037  +** This routine overwrites aRight[] with a new (probably longer) sequence
        43038  +** of indices such that the aRight[] contains every index that appears in
        43039  +** either aLeft[] or the old aRight[] and such that the second condition
        43040  +** above is still met.
        43041  +**
        43042  +** The aContent[aLeft[X]] values will be unique for all X.  And the
        43043  +** aContent[aRight[X]] values will be unique too.  But there might be
        43044  +** one or more combinations of X and Y such that
        43045  +**
        43046  +**      aLeft[X]!=aRight[Y]  &&  aContent[aLeft[X]] == aContent[aRight[Y]]
        43047  +**
        43048  +** When that happens, omit the aLeft[X] and use the aRight[Y] index.
 42772  43049   */
 42773  43050   static void walMerge(
 42774         -  u32 *aContent,                  /* Pages in wal */
        43051  +  const u32 *aContent,            /* Pages in wal - keys for the sort */
 42775  43052     ht_slot *aLeft,                 /* IN: Left hand input list */
 42776  43053     int nLeft,                      /* IN: Elements in array *paLeft */
 42777  43054     ht_slot **paRight,              /* IN/OUT: Right hand input list */
 42778  43055     int *pnRight,                   /* IN/OUT: Elements in *paRight */
 42779  43056     ht_slot *aTmp                   /* Temporary buffer */
 42780  43057   ){
 42781  43058     int iLeft = 0;                  /* Current index in aLeft */
................................................................................
 42807  43084   
 42808  43085     *paRight = aLeft;
 42809  43086     *pnRight = iOut;
 42810  43087     memcpy(aLeft, aTmp, sizeof(aTmp[0])*iOut);
 42811  43088   }
 42812  43089   
 42813  43090   /*
 42814         -** Sort the elements in list aList, removing any duplicates.
        43091  +** Sort the elements in list aList using aContent[] as the sort key.
        43092  +** Remove elements with duplicate keys, preferring to keep the
        43093  +** larger aList[] values.
        43094  +**
        43095  +** The aList[] entries are indices into aContent[].  The values in
        43096  +** aList[] are to be sorted so that for all J<K:
        43097  +**
        43098  +**      aContent[aList[J]] < aContent[aList[K]]
        43099  +**
        43100  +** For any X and Y such that
        43101  +**
        43102  +**      aContent[aList[X]] == aContent[aList[Y]]
        43103  +**
        43104  +** Keep the larger of the two values aList[X] and aList[Y] and discard
        43105  +** the smaller.
 42815  43106   */
 42816  43107   static void walMergesort(
 42817         -  u32 *aContent,                  /* Pages in wal */
        43108  +  const u32 *aContent,            /* Pages in wal */
 42818  43109     ht_slot *aBuffer,               /* Buffer of at least *pnList items to use */
 42819  43110     ht_slot *aList,                 /* IN/OUT: List to sort */
 42820  43111     int *pnList                     /* IN/OUT: Number of elements in aList[] */
 42821  43112   ){
 42822  43113     struct Sublist {
 42823  43114       int nList;                    /* Number of elements in aList */
 42824  43115       ht_slot *aList;               /* Pointer to sub-list content */
................................................................................
 42875  43166   static void walIteratorFree(WalIterator *p){
 42876  43167     sqlite3ScratchFree(p);
 42877  43168   }
 42878  43169   
 42879  43170   /*
 42880  43171   ** Construct a WalInterator object that can be used to loop over all 
 42881  43172   ** pages in the WAL in ascending order. The caller must hold the checkpoint
        43173  +** lock.
 42882  43174   **
 42883  43175   ** On success, make *pp point to the newly allocated WalInterator object
 42884  43176   ** return SQLITE_OK. Otherwise, return an error code. If this routine
 42885  43177   ** returns an error, the value of *pp is undefined.
 42886  43178   **
 42887  43179   ** The calling routine should invoke walIteratorFree() to destroy the
 42888  43180   ** WalIterator object when it has finished with it.
................................................................................
 43009  43301     u32 mxPage;                     /* Max database page to write */
 43010  43302     int i;                          /* Loop counter */
 43011  43303     volatile WalCkptInfo *pInfo;    /* The checkpoint status information */
 43012  43304   
 43013  43305     szPage = (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
 43014  43306     testcase( szPage<=32768 );
 43015  43307     testcase( szPage>=65536 );
 43016         -  if( pWal->hdr.mxFrame==0 ) return SQLITE_OK;
        43308  +  pInfo = walCkptInfo(pWal);
        43309  +  if( pInfo->nBackfill>=pWal->hdr.mxFrame ) return SQLITE_OK;
 43017  43310   
 43018  43311     /* Allocate the iterator */
 43019  43312     rc = walIteratorInit(pWal, &pIter);
 43020  43313     if( rc!=SQLITE_OK ){
 43021  43314       return rc;
 43022  43315     }
 43023  43316     assert( pIter );
................................................................................
 43031  43324     /* Compute in mxSafeFrame the index of the last frame of the WAL that is
 43032  43325     ** safe to write into the database.  Frames beyond mxSafeFrame might
 43033  43326     ** overwrite database pages that are in use by active readers and thus
 43034  43327     ** cannot be backfilled from the WAL.
 43035  43328     */
 43036  43329     mxSafeFrame = pWal->hdr.mxFrame;
 43037  43330     mxPage = pWal->hdr.nPage;
 43038         -  pInfo = walCkptInfo(pWal);
 43039  43331     for(i=1; i<WAL_NREADER; i++){
 43040  43332       u32 y = pInfo->aReadMark[i];
 43041  43333       if( mxSafeFrame>=y ){
 43042  43334         assert( y<=pWal->hdr.mxFrame );
 43043  43335         rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
 43044  43336         if( rc==SQLITE_OK ){
 43045  43337           pInfo->aReadMark[i] = READMARK_NOT_USED;
................................................................................
 44621  44913     u8 secureDelete;      /* True if secure_delete is enabled */
 44622  44914     u8 initiallyEmpty;    /* Database is empty at start of transaction */
 44623  44915     u8 openFlags;         /* Flags to sqlite3BtreeOpen() */
 44624  44916   #ifndef SQLITE_OMIT_AUTOVACUUM
 44625  44917     u8 autoVacuum;        /* True if auto-vacuum is enabled */
 44626  44918     u8 incrVacuum;        /* True if incr-vacuum is enabled */
 44627  44919   #endif
        44920  +  u8 inTransaction;     /* Transaction state */
        44921  +  u8 doNotUseWAL;       /* If true, do not open write-ahead-log file */
 44628  44922     u16 maxLocal;         /* Maximum local payload in non-LEAFDATA tables */
 44629  44923     u16 minLocal;         /* Minimum local payload in non-LEAFDATA tables */
 44630  44924     u16 maxLeaf;          /* Maximum local payload in a LEAFDATA table */
 44631  44925     u16 minLeaf;          /* Minimum local payload in a LEAFDATA table */
 44632         -  u8 inTransaction;     /* Transaction state */
 44633         -  u8 doNotUseWAL;       /* If true, do not open write-ahead-log file */
 44634  44926     u32 pageSize;         /* Total number of bytes on a page */
 44635  44927     u32 usableSize;       /* Number of usable bytes on each page */
 44636  44928     int nTransaction;     /* Number of open transactions (read + write) */
 44637  44929     u32 nPage;            /* Number of pages in the database */
 44638  44930     void *pSchema;        /* Pointer to space allocated by sqlite3BtreeSchema() */
 44639  44931     void (*xFreeSchema)(void*);  /* Destructor for BtShared.pSchema */
 44640  44932     sqlite3_mutex *mutex; /* Non-recursive mutex required to access this struct */
................................................................................
 44653  44945   /*
 44654  44946   ** An instance of the following structure is used to hold information
 44655  44947   ** about a cell.  The parseCellPtr() function fills in this structure
 44656  44948   ** based on information extract from the raw disk page.
 44657  44949   */
 44658  44950   typedef struct CellInfo CellInfo;
 44659  44951   struct CellInfo {
 44660         -  u8 *pCell;     /* Pointer to the start of cell content */
 44661  44952     i64 nKey;      /* The key for INTKEY tables, or number of bytes in key */
        44953  +  u8 *pCell;     /* Pointer to the start of cell content */
 44662  44954     u32 nData;     /* Number of bytes of data */
 44663  44955     u32 nPayload;  /* Total amount of payload */
 44664  44956     u16 nHeader;   /* Size of the cell content header in bytes */
 44665  44957     u16 nLocal;    /* Amount of payload held locally */
 44666  44958     u16 iOverflow; /* Offset to overflow page number.  Zero if no overflow */
 44667  44959     u16 nSize;     /* Size of the cell content on the main b-tree page */
 44668  44960   };
................................................................................
 44696  44988     Btree *pBtree;            /* The Btree to which this cursor belongs */
 44697  44989     BtShared *pBt;            /* The BtShared this cursor points to */
 44698  44990     BtCursor *pNext, *pPrev;  /* Forms a linked list of all cursors */
 44699  44991     struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */
 44700  44992     Pgno pgnoRoot;            /* The root page of this tree */
 44701  44993     sqlite3_int64 cachedRowid; /* Next rowid cache.  0 means not valid */
 44702  44994     CellInfo info;            /* A parse of the cell we are pointing at */
        44995  +  i64 nKey;        /* Size of pKey, or last integer key */
        44996  +  void *pKey;      /* Saved key that was cursor's last known position */
        44997  +  int skipNext;    /* Prev() is noop if negative. Next() is noop if positive */
 44703  44998     u8 wrFlag;                /* True if writable */
 44704  44999     u8 atLast;                /* Cursor pointing to the last entry */
 44705  45000     u8 validNKey;             /* True if info.nKey is valid */
 44706  45001     u8 eState;                /* One of the CURSOR_XXX constants (see below) */
 44707         -  void *pKey;      /* Saved key that was cursor's last known position */
 44708         -  i64 nKey;        /* Size of pKey, or last integer key */
 44709         -  int skipNext;    /* Prev() is noop if negative. Next() is noop if positive */
 44710  45002   #ifndef SQLITE_OMIT_INCRBLOB
 44711         -  u8 isIncrblobHandle;      /* True if this cursor is an incr. io handle */
 44712  45003     Pgno *aOverflow;          /* Cache of overflow page locations */
        45004  +  u8 isIncrblobHandle;      /* True if this cursor is an incr. io handle */
 44713  45005   #endif
 44714  45006     i16 iPage;                            /* Index of current page in apPage */
 44715         -  MemPage *apPage[BTCURSOR_MAX_DEPTH];  /* Pages from root to current page */
 44716  45007     u16 aiIdx[BTCURSOR_MAX_DEPTH];        /* Current index in apPage[i] */
        45008  +  MemPage *apPage[BTCURSOR_MAX_DEPTH];  /* Pages from root to current page */
 44717  45009   };
 44718  45010   
 44719  45011   /*
 44720  45012   ** Potential values for BtCursor.eState.
 44721  45013   **
 44722  45014   ** CURSOR_VALID:
 44723  45015   **   Cursor points to a valid entry. getPayload() etc. may be called.
................................................................................
 46113  46405     pInfo->nHeader = n;
 46114  46406     testcase( nPayload==pPage->maxLocal );
 46115  46407     testcase( nPayload==pPage->maxLocal+1 );
 46116  46408     if( likely(nPayload<=pPage->maxLocal) ){
 46117  46409       /* This is the (easy) common case where the entire payload fits
 46118  46410       ** on the local page.  No overflow is required.
 46119  46411       */
 46120         -    int nSize;          /* Total size of cell content in bytes */
 46121         -    nSize = nPayload + n;
        46412  +    if( (pInfo->nSize = (u16)(n+nPayload))<4 ) pInfo->nSize = 4;
 46122  46413       pInfo->nLocal = (u16)nPayload;
 46123  46414       pInfo->iOverflow = 0;
 46124         -    if( (nSize & ~3)==0 ){
 46125         -      nSize = 4;        /* Minimum cell size is 4 */
 46126         -    }
 46127         -    pInfo->nSize = (u16)nSize;
 46128  46415     }else{
 46129  46416       /* If the payload will not fit completely on the local page, we have
 46130  46417       ** to decide how much to store locally and how much to spill onto
 46131  46418       ** overflow pages.  The strategy is to minimize the amount of unused
 46132  46419       ** space on overflow pages while keeping the amount of local storage
 46133  46420       ** in between minLocal and maxLocal.
 46134  46421       **
................................................................................
 47581  47868         pBt->usableSize = usableSize;
 47582  47869         pBt->pageSize = pageSize;
 47583  47870         freeTempSpace(pBt);
 47584  47871         rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
 47585  47872                                      pageSize-usableSize);
 47586  47873         return rc;
 47587  47874       }
 47588         -    if( nPageHeader>nPageFile ){
        47875  +    if( (pBt->db->flags & SQLITE_RecoveryMode)==0 && nPageHeader>nPageFile ){
 47589  47876         rc = SQLITE_CORRUPT_BKPT;
 47590  47877         goto page1_init_failed;
 47591  47878       }
 47592  47879       if( usableSize<480 ){
 47593  47880         goto page1_init_failed;
 47594  47881       }
 47595  47882       pBt->pageSize = pageSize;
................................................................................
 53452  53739     if( i<0 ){
 53453  53740       sqlite3Error(pErrorDb, SQLITE_ERROR, "unknown database %s", zDb);
 53454  53741       return 0;
 53455  53742     }
 53456  53743   
 53457  53744     return pDb->aDb[i].pBt;
 53458  53745   }
        53746  +
        53747  +/*
        53748  +** Attempt to set the page size of the destination to match the page size
        53749  +** of the source.
        53750  +*/
        53751  +static int setDestPgsz(sqlite3_backup *p){
        53752  +  int rc;
        53753  +  rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),-1,0);
        53754  +  return rc;
        53755  +}
 53459  53756   
 53460  53757   /*
 53461  53758   ** Create an sqlite3_backup process to copy the contents of zSrcDb from
 53462  53759   ** connection handle pSrcDb to zDestDb in pDestDb. If successful, return
 53463  53760   ** a pointer to the new sqlite3_backup object.
 53464  53761   **
 53465  53762   ** If an error occurs, NULL is returned and an error code and error message
................................................................................
 53506  53803       p->pSrc = findBtree(pDestDb, pSrcDb, zSrcDb);
 53507  53804       p->pDest = findBtree(pDestDb, pDestDb, zDestDb);
 53508  53805       p->pDestDb = pDestDb;
 53509  53806       p->pSrcDb = pSrcDb;
 53510  53807       p->iNext = 1;
 53511  53808       p->isAttached = 0;
 53512  53809   
 53513         -    if( 0==p->pSrc || 0==p->pDest ){
 53514         -      /* One (or both) of the named databases did not exist. An error has
 53515         -      ** already been written into the pDestDb handle. All that is left
 53516         -      ** to do here is free the sqlite3_backup structure.
        53810  +    if( 0==p->pSrc || 0==p->pDest || setDestPgsz(p)==SQLITE_NOMEM ){
        53811  +      /* One (or both) of the named databases did not exist or an OOM
        53812  +      ** error was hit.  The error has already been written into the
        53813  +      ** pDestDb handle.  All that is left to do here is free the
        53814  +      ** sqlite3_backup structure.
 53517  53815         */
 53518  53816         sqlite3_free(p);
 53519  53817         p = 0;
 53520  53818       }
 53521  53819     }
 53522  53820     if( p ){
 53523  53821       p->pSrc->nBackup++;
................................................................................
 53766  54064           **
 53767  54065           **   * Data stored on the pages immediately following the 
 53768  54066           **     pending-byte page in the source database may need to be
 53769  54067           **     copied into the destination database.
 53770  54068           */
 53771  54069           const i64 iSize = (i64)pgszSrc * (i64)nSrcPage;
 53772  54070           sqlite3_file * const pFile = sqlite3PagerFile(pDestPager);
        54071  +        i64 iOff;
        54072  +        i64 iEnd;
 53773  54073   
 53774  54074           assert( pFile );
 53775  54075           assert( (i64)nDestTruncate*(i64)pgszDest >= iSize || (
 53776  54076                 nDestTruncate==(int)(PENDING_BYTE_PAGE(p->pDest->pBt)-1)
 53777  54077              && iSize>=PENDING_BYTE && iSize<=PENDING_BYTE+pgszDest
 53778  54078           ));
 53779         -        if( SQLITE_OK==(rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 1))
 53780         -         && SQLITE_OK==(rc = backupTruncateFile(pFile, iSize))
 53781         -         && SQLITE_OK==(rc = sqlite3PagerSync(pDestPager))
        54079  +
        54080  +        /* This call ensures that all data required to recreate the original
        54081  +        ** database has been stored in the journal for pDestPager and the
        54082  +        ** journal synced to disk. So at this point we may safely modify
        54083  +        ** the database file in any way, knowing that if a power failure
        54084  +        ** occurs, the original database will be reconstructed from the 
        54085  +        ** journal file.  */
        54086  +        rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 1);
        54087  +
        54088  +        /* Write the extra pages and truncate the database file as required. */
        54089  +        iEnd = MIN(PENDING_BYTE + pgszDest, iSize);
        54090  +        for(
        54091  +          iOff=PENDING_BYTE+pgszSrc; 
        54092  +          rc==SQLITE_OK && iOff<iEnd; 
        54093  +          iOff+=pgszSrc
 53782  54094           ){
 53783         -          i64 iOff;
 53784         -          i64 iEnd = MIN(PENDING_BYTE + pgszDest, iSize);
 53785         -          for(
 53786         -            iOff=PENDING_BYTE+pgszSrc; 
 53787         -            rc==SQLITE_OK && iOff<iEnd; 
 53788         -            iOff+=pgszSrc
 53789         -          ){
 53790         -            PgHdr *pSrcPg = 0;
 53791         -            const Pgno iSrcPg = (Pgno)((iOff/pgszSrc)+1);
 53792         -            rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg);
 53793         -            if( rc==SQLITE_OK ){
 53794         -              u8 *zData = sqlite3PagerGetData(pSrcPg);
 53795         -              rc = sqlite3OsWrite(pFile, zData, pgszSrc, iOff);
 53796         -            }
 53797         -            sqlite3PagerUnref(pSrcPg);
        54095  +          PgHdr *pSrcPg = 0;
        54096  +          const Pgno iSrcPg = (Pgno)((iOff/pgszSrc)+1);
        54097  +          rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg);
        54098  +          if( rc==SQLITE_OK ){
        54099  +            u8 *zData = sqlite3PagerGetData(pSrcPg);
        54100  +            rc = sqlite3OsWrite(pFile, zData, pgszSrc, iOff);
 53798  54101             }
        54102  +          sqlite3PagerUnref(pSrcPg);
        54103  +        }
        54104  +        if( rc==SQLITE_OK ){
        54105  +          rc = backupTruncateFile(pFile, iSize);
        54106  +        }
        54107  +
        54108  +        /* Sync the database file to disk. */
        54109  +        if( rc==SQLITE_OK ){
        54110  +          rc = sqlite3PagerSync(pDestPager);
 53799  54111           }
 53800  54112         }else{
 53801  54113           rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
 53802  54114         }
 53803  54115     
 53804  54116         /* Finish committing the transaction to the destination database. */
 53805  54117         if( SQLITE_OK==rc
................................................................................
 55554  55866     p->readOnly = 1;
 55555  55867     for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
 55556  55868       u8 opcode = pOp->opcode;
 55557  55869   
 55558  55870       pOp->opflags = sqlite3OpcodeProperty[opcode];
 55559  55871       if( opcode==OP_Function || opcode==OP_AggStep ){
 55560  55872         if( pOp->p5>nMaxArgs ) nMaxArgs = pOp->p5;
 55561         -    }else if( opcode==OP_Transaction && pOp->p2!=0 ){
        55873  +    }else if( (opcode==OP_Transaction && pOp->p2!=0) || opcode==OP_Vacuum ){
 55562  55874         p->readOnly = 0;
 55563  55875   #ifndef SQLITE_OMIT_VIRTUALTABLE
 55564  55876       }else if( opcode==OP_VUpdate ){
 55565  55877         if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
 55566  55878       }else if( opcode==OP_VFilter ){
 55567  55879         int n;
 55568  55880         assert( p->nOp - i >= 3 );
................................................................................
 58651  58963   static int sqlite3Step(Vdbe *p){
 58652  58964     sqlite3 *db;
 58653  58965     int rc;
 58654  58966   
 58655  58967     assert(p);
 58656  58968     if( p->magic!=VDBE_MAGIC_RUN ){
 58657  58969       /* We used to require that sqlite3_reset() be called before retrying
 58658         -    ** sqlite3_step() after any error.  But after 3.6.23, we changed this
 58659         -    ** so that sqlite3_reset() would be called automatically instead of
 58660         -    ** throwing the error.
        58970  +    ** sqlite3_step() after any error or after SQLITE_DONE.  But beginning
        58971  +    ** with version 3.7.0, we changed this so that sqlite3_reset() would
        58972  +    ** be called automatically instead of throwing the SQLITE_MISUSE error.
        58973  +    ** This "automatic-reset" change is not technically an incompatibility, 
        58974  +    ** since any application that receives an SQLITE_MISUSE is broken by
        58975  +    ** definition.
        58976  +    **
        58977  +    ** Nevertheless, some published applications that were originally written
        58978  +    ** for version 3.6.23 or earlier do in fact depend on SQLITE_MISUSE 
        58979  +    ** returns, and the so were broken by the automatic-reset change.  As a
        58980  +    ** a work-around, the SQLITE_OMIT_AUTORESET compile-time restores the
        58981  +    ** legacy behavior of returning SQLITE_MISUSE for cases where the 
        58982  +    ** previous sqlite3_step() returned something other than a SQLITE_LOCKED
        58983  +    ** or SQLITE_BUSY error.
 58661  58984       */
        58985  +#ifdef SQLITE_OMIT_AUTORESET
        58986  +    if( p->rc==SQLITE_BUSY || p->rc==SQLITE_LOCKED ){
        58987  +      sqlite3_reset((sqlite3_stmt*)p);
        58988  +    }else{
        58989  +      return SQLITE_MISUSE_BKPT;
        58990  +    }
        58991  +#else
 58662  58992       sqlite3_reset((sqlite3_stmt*)p);
        58993  +#endif
 58663  58994     }
 58664  58995   
 58665  58996     /* Check that malloc() has not failed. If it has, return early. */
 58666  58997     db = p->db;
 58667  58998     if( db->mallocFailed ){
 58668  58999       p->rc = SQLITE_NOMEM;
 58669  59000       return SQLITE_NOMEM;
................................................................................
 58697  59028     }
 58698  59029   #ifndef SQLITE_OMIT_EXPLAIN
 58699  59030     if( p->explain ){
 58700  59031       rc = sqlite3VdbeList(p);
 58701  59032     }else
 58702  59033   #endif /* SQLITE_OMIT_EXPLAIN */
 58703  59034     {
        59035  +    db->vdbeExecCnt++;
 58704  59036       rc = sqlite3VdbeExec(p);
        59037  +    db->vdbeExecCnt--;
 58705  59038     }
 58706  59039   
 58707  59040   #ifndef SQLITE_OMIT_TRACE
 58708  59041     /* Invoke the profile callback if there is one
 58709  59042     */
 58710  59043     if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy && p->zSql ){
 58711  59044       sqlite3_int64 iNow;
................................................................................
 58991  59324       ** this assert() from failing, when building with SQLITE_DEBUG defined
 58992  59325       ** using gcc, force nullMem to be 8-byte aligned using the magical
 58993  59326       ** __attribute__((aligned(8))) macro.  */
 58994  59327       static const Mem nullMem 
 58995  59328   #if defined(SQLITE_DEBUG) && defined(__GNUC__)
 58996  59329         __attribute__((aligned(8))) 
 58997  59330   #endif
 58998         -      = {{0}, (double)0, 0, "", 0, MEM_Null, SQLITE_NULL, 0, 0, 0 };
        59331  +      = {0, "", (double)0, {0}, 0, MEM_Null, SQLITE_NULL, 0, 0, 0 };
 58999  59332   
 59000  59333       if( pVm && ALWAYS(pVm->db) ){
 59001  59334         sqlite3_mutex_enter(pVm->db->mutex);
 59002  59335         sqlite3Error(pVm->db, SQLITE_RANGE, 0);
 59003  59336       }
 59004  59337       pOut = (Mem*)&nullMem;
 59005  59338     }
................................................................................
 59654  59987       nTotal += n;
 59655  59988       zSql += n;
 59656  59989     }
 59657  59990     return nTotal;
 59658  59991   }
 59659  59992   
 59660  59993   /*
 59661         -** Return a pointer to a string in memory obtained form sqlite3DbMalloc() which
 59662         -** holds a copy of zRawSql but with host parameters expanded to their
 59663         -** current bindings.
        59994  +** This function returns a pointer to a nul-terminated string in memory
        59995  +** obtained from sqlite3DbMalloc(). If sqlite3.vdbeExecCnt is 1, then the
        59996  +** string contains a copy of zRawSql but with host parameters expanded to 
        59997  +** their current bindings. Or, if sqlite3.vdbeExecCnt is greater than 1, 
        59998  +** then the returned string holds a copy of zRawSql with "-- " prepended
        59999  +** to each line of text.
 59664  60000   **
 59665  60001   ** The calling function is responsible for making sure the memory returned
 59666  60002   ** is eventually freed.
 59667  60003   **
 59668  60004   ** ALGORITHM:  Scan the input string looking for host parameters in any of
 59669  60005   ** these forms:  ?, ?N, $A, @A, :A.  Take care to avoid text within
 59670  60006   ** string literals, quoted identifier names, and comments.  For text forms,
................................................................................
 59687  60023     StrAccum out;            /* Accumulate the output here */
 59688  60024     char zBase[100];         /* Initial working space */
 59689  60025   
 59690  60026     db = p->db;
 59691  60027     sqlite3StrAccumInit(&out, zBase, sizeof(zBase), 
 59692  60028                         db->aLimit[SQLITE_LIMIT_LENGTH]);
 59693  60029     out.db = db;
 59694         -  while( zRawSql[0] ){
 59695         -    n = findNextHostParameter(zRawSql, &nToken);
 59696         -    assert( n>0 );
 59697         -    sqlite3StrAccumAppend(&out, zRawSql, n);
 59698         -    zRawSql += n;
 59699         -    assert( zRawSql[0] || nToken==0 );
 59700         -    if( nToken==0 ) break;
 59701         -    if( zRawSql[0]=='?' ){
 59702         -      if( nToken>1 ){
 59703         -        assert( sqlite3Isdigit(zRawSql[1]) );
 59704         -        sqlite3GetInt32(&zRawSql[1], &idx);
 59705         -      }else{
 59706         -        idx = nextIndex;
 59707         -      }
 59708         -    }else{
 59709         -      assert( zRawSql[0]==':' || zRawSql[0]=='$' || zRawSql[0]=='@' );
 59710         -      testcase( zRawSql[0]==':' );
 59711         -      testcase( zRawSql[0]=='$' );
 59712         -      testcase( zRawSql[0]=='@' );
 59713         -      idx = sqlite3VdbeParameterIndex(p, zRawSql, nToken);
 59714         -      assert( idx>0 );
 59715         -    }
 59716         -    zRawSql += nToken;
 59717         -    nextIndex = idx + 1;
 59718         -    assert( idx>0 && idx<=p->nVar );
 59719         -    pVar = &p->aVar[idx-1];
 59720         -    if( pVar->flags & MEM_Null ){
 59721         -      sqlite3StrAccumAppend(&out, "NULL", 4);
 59722         -    }else if( pVar->flags & MEM_Int ){
 59723         -      sqlite3XPrintf(&out, "%lld", pVar->u.i);
 59724         -    }else if( pVar->flags & MEM_Real ){
 59725         -      sqlite3XPrintf(&out, "%!.15g", pVar->r);
 59726         -    }else if( pVar->flags & MEM_Str ){
 59727         -#ifndef SQLITE_OMIT_UTF16
 59728         -      u8 enc = ENC(db);
 59729         -      if( enc!=SQLITE_UTF8 ){
 59730         -        Mem utf8;
 59731         -        memset(&utf8, 0, sizeof(utf8));
 59732         -        utf8.db = db;
 59733         -        sqlite3VdbeMemSetStr(&utf8, pVar->z, pVar->n, enc, SQLITE_STATIC);
 59734         -        sqlite3VdbeChangeEncoding(&utf8, SQLITE_UTF8);
 59735         -        sqlite3XPrintf(&out, "'%.*q'", utf8.n, utf8.z);
 59736         -        sqlite3VdbeMemRelease(&utf8);
 59737         -      }else
 59738         -#endif
 59739         -      {
 59740         -        sqlite3XPrintf(&out, "'%.*q'", pVar->n, pVar->z);
 59741         -      }
 59742         -    }else if( pVar->flags & MEM_Zero ){
 59743         -      sqlite3XPrintf(&out, "zeroblob(%d)", pVar->u.nZero);
 59744         -    }else{
 59745         -      assert( pVar->flags & MEM_Blob );
 59746         -      sqlite3StrAccumAppend(&out, "x'", 2);
 59747         -      for(i=0; i<pVar->n; i++){
 59748         -        sqlite3XPrintf(&out, "%02x", pVar->z[i]&0xff);
 59749         -      }
 59750         -      sqlite3StrAccumAppend(&out, "'", 1);
        60030  +  if( db->vdbeExecCnt>1 ){
        60031  +    while( *zRawSql ){
        60032  +      const char *zStart = zRawSql;
        60033  +      while( *(zRawSql++)!='\n' && *zRawSql );
        60034  +      sqlite3StrAccumAppend(&out, "-- ", 3);
        60035  +      sqlite3StrAccumAppend(&out, zStart, zRawSql-zStart);
        60036  +    }
        60037  +  }else{
        60038  +    while( zRawSql[0] ){
        60039  +      n = findNextHostParameter(zRawSql, &nToken);
        60040  +      assert( n>0 );
        60041  +      sqlite3StrAccumAppend(&out, zRawSql, n);
        60042  +      zRawSql += n;
        60043  +      assert( zRawSql[0] || nToken==0 );
        60044  +      if( nToken==0 ) break;
        60045  +      if( zRawSql[0]=='?' ){
        60046  +        if( nToken>1 ){
        60047  +          assert( sqlite3Isdigit(zRawSql[1]) );
        60048  +          sqlite3GetInt32(&zRawSql[1], &idx);
        60049  +        }else{
        60050  +          idx = nextIndex;
        60051  +        }
        60052  +      }else{
        60053  +        assert( zRawSql[0]==':' || zRawSql[0]=='$' || zRawSql[0]=='@' );
        60054  +        testcase( zRawSql[0]==':' );
        60055  +        testcase( zRawSql[0]=='$' );
        60056  +        testcase( zRawSql[0]=='@' );
        60057  +        idx = sqlite3VdbeParameterIndex(p, zRawSql, nToken);
        60058  +        assert( idx>0 );
        60059  +      }
        60060  +      zRawSql += nToken;
        60061  +      nextIndex = idx + 1;
        60062  +      assert( idx>0 && idx<=p->nVar );
        60063  +      pVar = &p->aVar[idx-1];
        60064  +      if( pVar->flags & MEM_Null ){
        60065  +        sqlite3StrAccumAppend(&out, "NULL", 4);
        60066  +      }else if( pVar->flags & MEM_Int ){
        60067  +        sqlite3XPrintf(&out, "%lld", pVar->u.i);
        60068  +      }else if( pVar->flags & MEM_Real ){
        60069  +        sqlite3XPrintf(&out, "%!.15g", pVar->r);
        60070  +      }else if( pVar->flags & MEM_Str ){
        60071  +#ifndef SQLITE_OMIT_UTF16
        60072  +        u8 enc = ENC(db);
        60073  +        if( enc!=SQLITE_UTF8 ){
        60074  +          Mem utf8;
        60075  +          memset(&utf8, 0, sizeof(utf8));
        60076  +          utf8.db = db;
        60077  +          sqlite3VdbeMemSetStr(&utf8, pVar->z, pVar->n, enc, SQLITE_STATIC);
        60078  +          sqlite3VdbeChangeEncoding(&utf8, SQLITE_UTF8);
        60079  +          sqlite3XPrintf(&out, "'%.*q'", utf8.n, utf8.z);
        60080  +          sqlite3VdbeMemRelease(&utf8);
        60081  +        }else
        60082  +#endif
        60083  +        {
        60084  +          sqlite3XPrintf(&out, "'%.*q'", pVar->n, pVar->z);
        60085  +        }
        60086  +      }else if( pVar->flags & MEM_Zero ){
        60087  +        sqlite3XPrintf(&out, "zeroblob(%d)", pVar->u.nZero);
        60088  +      }else{
        60089  +        assert( pVar->flags & MEM_Blob );
        60090  +        sqlite3StrAccumAppend(&out, "x'", 2);
        60091  +        for(i=0; i<pVar->n; i++){
        60092  +          sqlite3XPrintf(&out, "%02x", pVar->z[i]&0xff);
        60093  +        }
        60094  +        sqlite3StrAccumAppend(&out, "'", 1);
        60095  +      }
 59751  60096       }
 59752  60097     }
 59753  60098     return sqlite3StrAccumFinish(&out);
 59754  60099   }
 59755  60100   
 59756  60101   #endif /* #ifndef SQLITE_OMIT_TRACE */
 59757  60102   
................................................................................
 73438  73783       ** the index b-tree.  */
 73439  73784       endOfLoop = sqlite3VdbeMakeLabel(v);
 73440  73785       sqlite3VdbeAddOp2(v, OP_Rewind, iIdxCur, endOfLoop);
 73441  73786       topOfLoop = sqlite3VdbeCurrentAddr(v);
 73442  73787       sqlite3VdbeAddOp2(v, OP_AddImm, iMem, 1);
 73443  73788   
 73444  73789       for(i=0; i<nCol; i++){
        73790  +      CollSeq *pColl;
 73445  73791         sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regCol);
 73446         -#ifdef SQLITE_ENABLE_STAT2
 73447  73792         if( i==0 ){
        73793  +#ifdef SQLITE_ENABLE_STAT2
 73448  73794           /* Check if the record that cursor iIdxCur points to contains a
 73449  73795           ** value that should be stored in the sqlite_stat2 table. If so,
 73450  73796           ** store it.  */
 73451  73797           int ne = sqlite3VdbeAddOp3(v, OP_Ne, regRecno, 0, regSamplerecno);
 73452  73798           assert( regTabname+1==regIdxname 
 73453  73799                && regTabname+2==regSampleno
 73454  73800                && regTabname+3==regCol
................................................................................
 73469  73815           sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_INDEX_SAMPLES, regTemp2);
 73470  73816           sqlite3VdbeAddOp3(v, OP_Subtract, regSampleno, regTemp2, regTemp2);
 73471  73817           sqlite3VdbeAddOp3(v, OP_Divide, regTemp2, regTemp, regTemp);
 73472  73818           sqlite3VdbeAddOp3(v, OP_Add, regSamplerecno, regTemp, regSamplerecno);
 73473  73819   
 73474  73820           sqlite3VdbeJumpHere(v, ne);
 73475  73821           sqlite3VdbeAddOp2(v, OP_AddImm, regRecno, 1);
 73476         -      }
 73477  73822   #endif
 73478  73823   
 73479         -      sqlite3VdbeAddOp3(v, OP_Ne, regCol, 0, iMem+nCol+i+1);
 73480         -      /**** TODO:  add collating sequence *****/
 73481         -      sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
        73824  +        /* Always record the very first row */
        73825  +        sqlite3VdbeAddOp1(v, OP_IfNot, iMem+1);
        73826  +      }
        73827  +      assert( pIdx->azColl!=0 );
        73828  +      assert( pIdx->azColl[i]!=0 );
        73829  +      pColl = sqlite3LocateCollSeq(pParse, pIdx->azColl[i]);
        73830  +      sqlite3VdbeAddOp4(v, OP_Ne, regCol, 0, iMem+nCol+i+1,
        73831  +                       (char*)pColl, P4_COLLSEQ);
        73832  +      sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
 73482  73833       }
 73483  73834       if( db->mallocFailed ){
 73484  73835         /* If a malloc failure has occurred, then the result of the expression 
 73485  73836         ** passed as the second argument to the call to sqlite3VdbeJumpHere() 
 73486  73837         ** below may be negative. Which causes an assert() to fail (or an
 73487  73838         ** out-of-bounds write if SQLITE_DEBUG is not defined).  */
 73488  73839         return;
 73489  73840       }
 73490  73841       sqlite3VdbeAddOp2(v, OP_Goto, 0, endOfLoop);
 73491  73842       for(i=0; i<nCol; i++){
 73492         -      sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-(nCol*2));
        73843  +      int addr2 = sqlite3VdbeCurrentAddr(v) - (nCol*2);
        73844  +      if( i==0 ){
        73845  +        sqlite3VdbeJumpHere(v, addr2-1);  /* Set jump dest for the OP_IfNot */
        73846  +      }
        73847  +      sqlite3VdbeJumpHere(v, addr2);      /* Set jump dest for the OP_Ne */
 73493  73848         sqlite3VdbeAddOp2(v, OP_AddImm, iMem+i+1, 1);
 73494  73849         sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, iMem+nCol+i+1);
 73495  73850       }
 73496  73851   
 73497  73852       /* End of the analysis loop. */
 73498  73853       sqlite3VdbeResolveLabel(v, endOfLoop);
 73499  73854       sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, topOfLoop);
................................................................................
 73831  74186       }else{
 73832  74187         rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
 73833  74188         sqlite3DbFree(db, zSql);
 73834  74189       }
 73835  74190   
 73836  74191       if( rc==SQLITE_OK ){
 73837  74192         while( sqlite3_step(pStmt)==SQLITE_ROW ){
 73838         -        char *zIndex = (char *)sqlite3_column_text(pStmt, 0);
 73839         -        Index *pIdx = sqlite3FindIndex(db, zIndex, sInfo.zDatabase);
        74193  +        char *zIndex;   /* Index name */
        74194  +        Index *pIdx;    /* Pointer to the index object */
        74195  +
        74196  +        zIndex = (char *)sqlite3_column_text(pStmt, 0);
        74197  +        pIdx = zIndex ? sqlite3FindIndex(db, zIndex, sInfo.zDatabase) : 0;
 73840  74198           if( pIdx ){
 73841  74199             int iSample = sqlite3_column_int(pStmt, 1);
 73842  74200             if( iSample<SQLITE_INDEX_SAMPLES && iSample>=0 ){
 73843  74201               int eType = sqlite3_column_type(pStmt, 2);
 73844  74202   
 73845  74203               if( pIdx->aSample==0 ){
 73846  74204                 static const int sz = sizeof(IndexSample)*SQLITE_INDEX_SAMPLES;
................................................................................
 80919  81277   SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3 *db, int caseSensitive){
 80920  81278     struct compareInfo *pInfo;
 80921  81279     if( caseSensitive ){
 80922  81280       pInfo = (struct compareInfo*)&likeInfoAlt;
 80923  81281     }else{
 80924  81282       pInfo = (struct compareInfo*)&likeInfoNorm;
 80925  81283     }
 80926         -  sqlite3CreateFunc(db, "like", 2, SQLITE_ANY, pInfo, likeFunc, 0, 0, 0);
 80927         -  sqlite3CreateFunc(db, "like", 3, SQLITE_ANY, pInfo, likeFunc, 0, 0, 0);
 80928         -  sqlite3CreateFunc(db, "glob", 2, SQLITE_ANY, 
        81284  +  sqlite3CreateFunc(db, "like", 2, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
        81285  +  sqlite3CreateFunc(db, "like", 3, SQLITE_UTF8, pInfo, likeFunc, 0, 0, 0);
        81286  +  sqlite3CreateFunc(db, "glob", 2, SQLITE_UTF8, 
 80929  81287         (struct compareInfo*)&globInfo, likeFunc, 0, 0, 0);
 80930  81288     setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
 80931  81289     setLikeOptFlag(db, "like", 
 80932  81290         caseSensitive ? (SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE) : SQLITE_FUNC_LIKE);
 80933  81291   }
 80934  81292   
 80935  81293   /*
................................................................................
 87600  87958   
 87601  87959   #ifndef SQLITE_OMIT_UTF16
 87602  87960   /*
 87603  87961   ** Compile the UTF-16 encoded SQL statement zSql into a statement handle.
 87604  87962   */
 87605  87963   static int sqlite3Prepare16(
 87606  87964     sqlite3 *db,              /* Database handle. */ 
 87607         -  const void *zSql,         /* UTF-8 encoded SQL statement. */
        87965  +  const void *zSql,         /* UTF-16 encoded SQL statement. */
 87608  87966     int nBytes,               /* Length of zSql in bytes. */
 87609  87967     int saveSqlFlag,          /* True to save SQL text into the sqlite3_stmt */
 87610  87968     sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
 87611  87969     const void **pzTail       /* OUT: End of parsed string */
 87612  87970   ){
 87613  87971     /* This function currently works by first transforming the UTF-16
 87614  87972     ** encoded string to UTF-8, then invoking sqlite3_prepare(). The
................................................................................
 87650  88008   ** and so if a schema change occurs, SQLITE_SCHEMA is returned by
 87651  88009   ** sqlite3_step().  In the new version, the original SQL text is retained
 87652  88010   ** and the statement is automatically recompiled if an schema change
 87653  88011   ** occurs.
 87654  88012   */
 87655  88013   SQLITE_API int sqlite3_prepare16(
 87656  88014     sqlite3 *db,              /* Database handle. */ 
 87657         -  const void *zSql,         /* UTF-8 encoded SQL statement. */
        88015  +  const void *zSql,         /* UTF-16 encoded SQL statement. */
 87658  88016     int nBytes,               /* Length of zSql in bytes. */
 87659  88017     sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
 87660  88018     const void **pzTail       /* OUT: End of parsed string */
 87661  88019   ){
 87662  88020     int rc;
 87663  88021     rc = sqlite3Prepare16(db,zSql,nBytes,0,ppStmt,pzTail);
 87664  88022     assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 );  /* VERIFY: F13021 */
 87665  88023     return rc;
 87666  88024   }
 87667  88025   SQLITE_API int sqlite3_prepare16_v2(
 87668  88026     sqlite3 *db,              /* Database handle. */ 
 87669         -  const void *zSql,         /* UTF-8 encoded SQL statement. */
        88027  +  const void *zSql,         /* UTF-16 encoded SQL statement. */
 87670  88028     int nBytes,               /* Length of zSql in bytes. */
 87671  88029     sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
 87672  88030     const void **pzTail       /* OUT: End of parsed string */
 87673  88031   ){
 87674  88032     int rc;
 87675  88033     rc = sqlite3Prepare16(db,zSql,nBytes,1,ppStmt,pzTail);
 87676  88034     assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 );  /* VERIFY: F13021 */
................................................................................
 97671  98029   #ifdef SQLITE_ENABLE_STAT2
 97672  98030   static int valueFromExpr(
 97673  98031     Parse *pParse, 
 97674  98032     Expr *pExpr, 
 97675  98033     u8 aff, 
 97676  98034     sqlite3_value **pp
 97677  98035   ){
 97678         -  /* The evalConstExpr() function will have already converted any TK_VARIABLE
 97679         -  ** expression involved in an comparison into a TK_REGISTER. */
 97680         -  assert( pExpr->op!=TK_VARIABLE );
 97681         -  if( pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE ){
        98036  +  if( pExpr->op==TK_VARIABLE
        98037  +   || (pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE)
        98038  +  ){
 97682  98039       int iVar = pExpr->iColumn;
 97683  98040       sqlite3VdbeSetVarmask(pParse->pVdbe, iVar); /* IMP: R-23257-02778 */
 97684  98041       *pp = sqlite3VdbeGetValue(pParse->pReprepare, iVar, aff);
 97685  98042       return SQLITE_OK;
 97686  98043     }
 97687  98044     return sqlite3ValueFromExpr(pParse->db, pExpr, SQLITE_UTF8, aff, pp);
 97688  98045   }
................................................................................
105462 105819       /* SQLITE_BUSY        */ "database is locked",
105463 105820       /* SQLITE_LOCKED      */ "database table is locked",
105464 105821       /* SQLITE_NOMEM       */ "out of memory",
105465 105822       /* SQLITE_READONLY    */ "attempt to write a readonly database",
105466 105823       /* SQLITE_INTERRUPT   */ "interrupted",
105467 105824       /* SQLITE_IOERR       */ "disk I/O error",
105468 105825       /* SQLITE_CORRUPT     */ "database disk image is malformed",
105469         -    /* SQLITE_NOTFOUND    */ 0,
       105826  +    /* SQLITE_NOTFOUND    */ "unknown operation",
105470 105827       /* SQLITE_FULL        */ "database or disk is full",
105471 105828       /* SQLITE_CANTOPEN    */ "unable to open database file",
105472 105829       /* SQLITE_PROTOCOL    */ "locking protocol",
105473 105830       /* SQLITE_EMPTY       */ "table contains no data",
105474 105831       /* SQLITE_SCHEMA      */ "database schema has changed",
105475 105832       /* SQLITE_TOOBIG      */ "string or blob too big",
105476 105833       /* SQLITE_CONSTRAINT  */ "constraint failed",
................................................................................
106468 106825   #endif
106469 106826   #ifdef SQLITE_ENABLE_LOAD_EXTENSION
106470 106827                    | SQLITE_LoadExtension
106471 106828   #endif
106472 106829   #if SQLITE_DEFAULT_RECURSIVE_TRIGGERS
106473 106830                    | SQLITE_RecTriggers
106474 106831   #endif
       106832  +#if defined(SQLITE_DEFAULT_FOREIGN_KEYS) && SQLITE_DEFAULT_FOREIGN_KEYS
       106833  +                 | SQLITE_ForeignKeys
       106834  +#endif
106475 106835         ;
106476 106836     sqlite3HashInit(&db->aCollSeq);
106477 106837   #ifndef SQLITE_OMIT_VIRTUALTABLE
106478 106838     sqlite3HashInit(&db->aModule);
106479 106839   #endif
106480 106840   
106481 106841     db->pVfs = sqlite3_vfs_find(zVfs);
................................................................................
107007 107367         fd = sqlite3PagerFile(pPager);
107008 107368         assert( fd!=0 );
107009 107369         if( op==SQLITE_FCNTL_FILE_POINTER ){
107010 107370           *(sqlite3_file**)pArg = fd;
107011 107371           rc = SQLITE_OK;
107012 107372         }else if( fd->pMethods ){
107013 107373           rc = sqlite3OsFileControl(fd, op, pArg);
       107374  +      }else{
       107375  +        rc = SQLITE_NOTFOUND;
107014 107376         }
107015 107377         sqlite3BtreeLeave(pBtree);
107016 107378       }
107017 107379     }
107018 107380     sqlite3_mutex_leave(db->mutex);
107019 107381     return rc;   
107020 107382   }
................................................................................
111305 111667     Fts3Expr *pExpr,                /* Access this expressions doclist */
111306 111668     sqlite3_int64 iDocid,           /* Docid associated with requested pos-list */
111307 111669     int iCol                        /* Column of requested pos-list */
111308 111670   ){
111309 111671     assert( pExpr->isLoaded );
111310 111672     if( pExpr->aDoclist ){
111311 111673       char *pEnd = &pExpr->aDoclist[pExpr->nDoclist];
111312         -    char *pCsr = pExpr->pCurrent;
       111674  +    char *pCsr;
111313 111675   
       111676  +    if( pExpr->pCurrent==0 ){
       111677  +      pExpr->pCurrent = pExpr->aDoclist;
       111678  +      pExpr->iCurrent = 0;
       111679  +      pExpr->pCurrent += sqlite3Fts3GetVarint(pExpr->pCurrent,&pExpr->iCurrent);
       111680  +    }
       111681  +    pCsr = pExpr->pCurrent;
111314 111682       assert( pCsr );
       111683  +
111315 111684       while( pCsr<pEnd ){
111316 111685         if( pExpr->iCurrent<iDocid ){
111317 111686           fts3PoslistCopy(0, &pCsr);
111318 111687           if( pCsr<pEnd ){
111319 111688             fts3GetDeltaVarint(&pCsr, &pExpr->iCurrent);
111320 111689           }
111321 111690           pExpr->pCurrent = pCsr;
................................................................................
115496 115865         ** varints, where nCol is the number of columns in the FTS3 table.
115497 115866         ** The first varint is the number of documents currently stored in
115498 115867         ** the table. The following nCol varints contain the total amount of
115499 115868         ** data stored in all rows of each column of the table, from left
115500 115869         ** to right.
115501 115870         */
115502 115871         sqlite3_stmt *pStmt;
115503         -      rc = fts3SqlStmt(p, SQL_SELECT_DOCTOTAL, &pStmt, 0);
       115872  +      sqlite3_int64 nDoc = 0;
       115873  +      sqlite3_int64 nByte = 0;
       115874  +      const char *a;
       115875  +      rc = sqlite3Fts3SelectDoctotal(p, &pStmt);
115504 115876         if( rc ) return rc;
115505         -      if( sqlite3_step(pStmt)==SQLITE_ROW ){
115506         -        sqlite3_int64 nDoc = 0;
115507         -        sqlite3_int64 nByte = 0;
115508         -        const char *a = sqlite3_column_blob(pStmt, 0);
115509         -        if( a ){
115510         -          const char *pEnd = &a[sqlite3_column_bytes(pStmt, 0)];
115511         -          a += sqlite3Fts3GetVarint(a, &nDoc);
115512         -          while( a<pEnd ){
115513         -            a += sqlite3Fts3GetVarint(a, &nByte);
115514         -          }
       115877  +      a = sqlite3_column_blob(pStmt, 0);
       115878  +      if( a ){
       115879  +        const char *pEnd = &a[sqlite3_column_bytes(pStmt, 0)];
       115880  +        a += sqlite3Fts3GetVarint(a, &nDoc);
       115881  +        while( a<pEnd ){
       115882  +          a += sqlite3Fts3GetVarint(a, &nByte);
115515 115883           }
       115884  +      }
       115885  +      if( nDoc==0 || nByte==0 ){
       115886  +        sqlite3_reset(pStmt);
       115887  +        return SQLITE_CORRUPT;
       115888  +      }
115516 115889   
115517         -        pCsr->nRowAvg = (int)(((nByte / nDoc) + pgsz - 1) / pgsz);
115518         -      }
       115890  +      pCsr->nRowAvg = (int)(((nByte / nDoc) + pgsz) / pgsz);
       115891  +      assert( pCsr->nRowAvg>0 ); 
115519 115892         rc = sqlite3_reset(pStmt);
115520         -      if( rc!=SQLITE_OK || pCsr->nRowAvg==0 ) return rc;
       115893  +      if( rc!=SQLITE_OK ) return rc;
115521 115894       }
115522 115895   
115523 115896       /* Assume that a blob flows over onto overflow pages if it is larger
115524 115897       ** than (pgsz-35) bytes in size (the file-format documentation
115525 115898       ** confirms this).
115526 115899       */
115527 115900       for(iBlock=pReader->iStartBlock; iBlock<=pReader->iLeafEndBlock; iBlock++){
................................................................................
116634 117007             fts3ColumnFilter(pFilter->iCol, &pList, &nList);
116635 117008           }
116636 117009   
116637 117010           if( !isIgnoreEmpty || nList>0 ){
116638 117011             nByte = sqlite3Fts3VarintLen(iDocid-iPrev) + (isRequirePos?nList+1:0);
116639 117012             if( nDoclist+nByte>nAlloc ){
116640 117013               char *aNew;
116641         -            nAlloc = nDoclist+nByte*2;
       117014  +            nAlloc = (nDoclist+nByte)*2;
116642 117015               aNew = sqlite3_realloc(aBuffer, nAlloc);
116643 117016               if( !aNew ){
116644 117017                 rc = SQLITE_NOMEM;
116645 117018                 goto finished;
116646 117019               }
116647 117020               aBuffer = aNew;
116648 117021             }
................................................................................
117511 117884   }
117512 117885   
117513 117886   /*
117514 117887   ** This is an fts3ExprIterate() callback used while loading the doclists
117515 117888   ** for each phrase into Fts3Expr.aDoclist[]/nDoclist. See also
117516 117889   ** fts3ExprLoadDoclists().
117517 117890   */
117518         -static int fts3ExprLoadDoclistsCb1(Fts3Expr *pExpr, int iPhrase, void *ctx){
       117891  +static int fts3ExprLoadDoclistsCb(Fts3Expr *pExpr, int iPhrase, void *ctx){
117519 117892     int rc = SQLITE_OK;
117520 117893     LoadDoclistCtx *p = (LoadDoclistCtx *)ctx;
117521 117894   
117522 117895     UNUSED_PARAMETER(iPhrase);
117523 117896   
117524 117897     p->nPhrase++;
117525 117898     p->nToken += pExpr->pPhrase->nToken;
................................................................................
117531 117904         rc = fts3ExprNearTrim(pExpr);
117532 117905       }
117533 117906     }
117534 117907   
117535 117908     return rc;
117536 117909   }
117537 117910   
117538         -/*
117539         -** This is an fts3ExprIterate() callback used while loading the doclists
117540         -** for each phrase into Fts3Expr.aDoclist[]/nDoclist. See also
117541         -** fts3ExprLoadDoclists().
117542         -*/
117543         -static int fts3ExprLoadDoclistsCb2(Fts3Expr *pExpr, int iPhrase, void *ctx){
117544         -  UNUSED_PARAMETER(iPhrase);
117545         -  UNUSED_PARAMETER(ctx);
117546         -  if( pExpr->aDoclist ){
117547         -    pExpr->pCurrent = pExpr->aDoclist;
117548         -    pExpr->iCurrent = 0;
117549         -    pExpr->pCurrent += sqlite3Fts3GetVarint(pExpr->pCurrent, &pExpr->iCurrent);
117550         -  }
117551         -  return SQLITE_OK;
117552         -}
117553         -
117554 117911   /*
117555 117912   ** Load the doclists for each phrase in the query associated with FTS3 cursor
117556 117913   ** pCsr. 
117557 117914   **
117558 117915   ** If pnPhrase is not NULL, then *pnPhrase is set to the number of matchable 
117559 117916   ** phrases in the expression (all phrases except those directly or 
117560 117917   ** indirectly descended from the right-hand-side of a NOT operator). If 
................................................................................
117565 117922     Fts3Cursor *pCsr,               /* Fts3 cursor for current query */
117566 117923     int *pnPhrase,                  /* OUT: Number of phrases in query */
117567 117924     int *pnToken                    /* OUT: Number of tokens in query */
117568 117925   ){
117569 117926     int rc;                         /* Return Code */
117570 117927     LoadDoclistCtx sCtx = {0,0,0};  /* Context for fts3ExprIterate() */
117571 117928     sCtx.pCsr = pCsr;
117572         -  rc = fts3ExprIterate(pCsr->pExpr, fts3ExprLoadDoclistsCb1, (void *)&sCtx);
117573         -  if( rc==SQLITE_OK ){
117574         -    (void)fts3ExprIterate(pCsr->pExpr, fts3ExprLoadDoclistsCb2, 0);
117575         -  }
       117929  +  rc = fts3ExprIterate(pCsr->pExpr, fts3ExprLoadDoclistsCb, (void *)&sCtx);
117576 117930     if( pnPhrase ) *pnPhrase = sCtx.nPhrase;
117577 117931     if( pnToken ) *pnToken = sCtx.nToken;
117578 117932     return rc;
117579 117933   }
117580 117934   
117581 117935   static int fts3ExprPhraseCountCb(Fts3Expr *pExpr, int iPhrase, void *ctx){
117582 117936     (*(int *)ctx)++;
................................................................................
118260 118614     sqlite3_int64 nDoc;
118261 118615   
118262 118616     if( !*ppStmt ){
118263 118617       int rc = sqlite3Fts3SelectDoctotal(pTab, ppStmt);
118264 118618       if( rc!=SQLITE_OK ) return rc;
118265 118619     }
118266 118620     pStmt = *ppStmt;
       118621  +  assert( sqlite3_data_count(pStmt)==1 );
118267 118622   
118268 118623     a = sqlite3_column_blob(pStmt, 0);
118269 118624     a += sqlite3Fts3GetVarint(a, &nDoc);
118270 118625     *pnDoc = (u32)nDoc;
118271 118626   
118272 118627     if( paLen ) *paLen = a;
118273 118628     return SQLITE_OK;

Name change from SQLite.Interop/src/sqlite3.def to SQLite.Interop/src/core/sqlite3.def.

   181    181   sqlite3_value_text16le
   182    182   sqlite3_value_type
   183    183   sqlite3_version
   184    184   sqlite3_vfs_find
   185    185   sqlite3_vfs_register
   186    186   sqlite3_vfs_unregister
   187    187   sqlite3_vmprintf
          188  +sqlite3_vsnprintf
   188    189   sqlite3_wal_autocheckpoint
   189    190   sqlite3_wal_checkpoint
   190    191   sqlite3_wal_hook
   191    192   sqlite3_win32_mbcs_to_utf8

Name change from SQLite.Interop/src/sqlite3.h to SQLite.Interop/src/core/sqlite3.h.

   103    103   ** string contains the date and time of the check-in (UTC) and an SHA1
   104    104   ** hash of the entire source tree.
   105    105   **
   106    106   ** See also: [sqlite3_libversion()],
   107    107   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   108    108   ** [sqlite_version()] and [sqlite_source_id()].
   109    109   */
   110         -#define SQLITE_VERSION        "3.7.4"
   111         -#define SQLITE_VERSION_NUMBER 3007004
   112         -#define SQLITE_SOURCE_ID      "2010-12-07 20:14:09 a586a4deeb25330037a49df295b36aaf624d0f45"
          110  +#define SQLITE_VERSION        "3.7.5"
          111  +#define SQLITE_VERSION_NUMBER 3007005
          112  +#define SQLITE_SOURCE_ID      "2011-01-28 17:03:50 ed759d5a9edb3bba5f48f243df47be29e3fe8cd7"
   113    113   
   114    114   /*
   115    115   ** CAPI3REF: Run-Time Library Version Numbers
   116    116   ** KEYWORDS: sqlite3_version, sqlite3_sourceid
   117    117   **
   118    118   ** These interfaces provide the same information as the [SQLITE_VERSION],
   119    119   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
   386    386   #define SQLITE_BUSY         5   /* The database file is locked */
   387    387   #define SQLITE_LOCKED       6   /* A table in the database is locked */
   388    388   #define SQLITE_NOMEM        7   /* A malloc() failed */
   389    389   #define SQLITE_READONLY     8   /* Attempt to write a readonly database */
   390    390   #define SQLITE_INTERRUPT    9   /* Operation terminated by sqlite3_interrupt()*/
   391    391   #define SQLITE_IOERR       10   /* Some kind of disk I/O error occurred */
   392    392   #define SQLITE_CORRUPT     11   /* The database disk image is malformed */
   393         -#define SQLITE_NOTFOUND    12   /* NOT USED. Table or record not found */
          393  +#define SQLITE_NOTFOUND    12   /* Unknown opcode in sqlite3_file_control() */
   394    394   #define SQLITE_FULL        13   /* Insertion failed because database is full */
   395    395   #define SQLITE_CANTOPEN    14   /* Unable to open the database file */
   396    396   #define SQLITE_PROTOCOL    15   /* Database lock protocol error */
   397    397   #define SQLITE_EMPTY       16   /* Database is empty */
   398    398   #define SQLITE_SCHEMA      17   /* The database schema changed */
   399    399   #define SQLITE_TOOBIG      18   /* String or BLOB exceeds size limit */
   400    400   #define SQLITE_CONSTRAINT  19   /* Abort due to constraint violation */
................................................................................
   618    618   ** write return values.  Potential uses for xFileControl() might be
   619    619   ** functions to enable blocking locks with timeouts, to change the
   620    620   ** locking strategy (for example to use dot-file locks), to inquire
   621    621   ** about the status of a lock, or to break stale locks.  The SQLite
   622    622   ** core reserves all opcodes less than 100 for its own use.
   623    623   ** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available.
   624    624   ** Applications that define a custom xFileControl method should use opcodes
   625         -** greater than 100 to avoid conflicts.
          625  +** greater than 100 to avoid conflicts.  VFS implementations should
          626  +** return [SQLITE_NOTFOUND] for file control opcodes that they do not
          627  +** recognize.
   626    628   **
   627    629   ** The xSectorSize() method returns the sector size of the
   628    630   ** device that underlies the file.  The sector size is the
   629    631   ** minimum write that can be performed without disturbing
   630    632   ** other bytes in the file.  The xDeviceCharacteristics()
   631    633   ** method returns a bit vector describing behaviors of the
   632    634   ** underlying device:
................................................................................
   711    713   ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
   712    714   ** extends and truncates the database file in chunks of a size specified
   713    715   ** by the user. The fourth argument to [sqlite3_file_control()] should 
   714    716   ** point to an integer (type int) containing the new chunk-size to use
   715    717   ** for the nominated database. Allocating database file space in large
   716    718   ** chunks (say 1MB at a time), may reduce file-system fragmentation and
   717    719   ** improve performance on some systems.
          720  +**
          721  +** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
          722  +** to the [sqlite3_file] object associated with a particular database
          723  +** connection.  See the [sqlite3_file_control()] documentation for
          724  +** additional information.
          725  +**
          726  +** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by
          727  +** SQLite and sent to all VFSes in place of a call to the xSync method
          728  +** when the database connection has [PRAGMA synchronous] set to OFF.)^
          729  +** Some specialized VFSes need this signal in order to operate correctly
          730  +** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most 
          731  +** VFSes do not need this signal and should silently ignore this opcode.
          732  +** Applications should not call [sqlite3_file_control()] with this
          733  +** opcode as doing so may disrupt the operation of the specilized VFSes
          734  +** that do require it.  
   718    735   */
   719    736   #define SQLITE_FCNTL_LOCKSTATE        1
   720    737   #define SQLITE_GET_LOCKPROXYFILE      2
   721    738   #define SQLITE_SET_LOCKPROXYFILE      3
   722    739   #define SQLITE_LAST_ERRNO             4
   723    740   #define SQLITE_FCNTL_SIZE_HINT        5
   724    741   #define SQLITE_FCNTL_CHUNK_SIZE       6
   725    742   #define SQLITE_FCNTL_FILE_POINTER     7
          743  +#define SQLITE_FCNTL_SYNC_OMITTED     8
   726    744   
   727    745   
   728    746   /*
   729    747   ** CAPI3REF: Mutex Handle
   730    748   **
   731    749   ** The mutex module within SQLite defines [sqlite3_mutex] to be an
   732    750   ** abstract type for a mutex object.  The SQLite core never looks
................................................................................
  1838   1856   ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
  1839   1857   ** results into memory obtained from [sqlite3_malloc()].
  1840   1858   ** The strings returned by these two routines should be
  1841   1859   ** released by [sqlite3_free()].  ^Both routines return a
  1842   1860   ** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
  1843   1861   ** memory to hold the resulting string.
  1844   1862   **
  1845         -** ^(In sqlite3_snprintf() routine is similar to "snprintf()" from
         1863  +** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from
  1846   1864   ** the standard C library.  The result is written into the
  1847   1865   ** buffer supplied as the second parameter whose size is given by
  1848   1866   ** the first parameter. Note that the order of the
  1849   1867   ** first two parameters is reversed from snprintf().)^  This is an
  1850   1868   ** historical accident that cannot be fixed without breaking
  1851   1869   ** backwards compatibility.  ^(Note also that sqlite3_snprintf()
  1852   1870   ** returns a pointer to its buffer instead of the number of
................................................................................
  1856   1874   ** now without breaking compatibility.
  1857   1875   **
  1858   1876   ** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
  1859   1877   ** guarantees that the buffer is always zero-terminated.  ^The first
  1860   1878   ** parameter "n" is the total size of the buffer, including space for
  1861   1879   ** the zero terminator.  So the longest string that can be completely
  1862   1880   ** written will be n-1 characters.
         1881  +**
         1882  +** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
  1863   1883   **
  1864   1884   ** These routines all implement some additional formatting
  1865   1885   ** options that are useful for constructing SQL statements.
  1866   1886   ** All of the usual printf() formatting options apply.  In addition, there
  1867   1887   ** is are "%q", "%Q", and "%z" options.
  1868   1888   **
  1869   1889   ** ^(The %q option works like %s in that it substitutes a null-terminated
................................................................................
  1920   1940   ** ^(The "%z" formatting option works like "%s" but with the
  1921   1941   ** addition that after the string has been read and copied into
  1922   1942   ** the result, [sqlite3_free()] is called on the input string.)^
  1923   1943   */
  1924   1944   SQLITE_API char *sqlite3_mprintf(const char*,...);
  1925   1945   SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
  1926   1946   SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
         1947  +SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
  1927   1948   
  1928   1949   /*
  1929   1950   ** CAPI3REF: Memory Allocation Subsystem
  1930   1951   **
  1931   1952   ** The SQLite core uses these three routines for all of its own
  1932   1953   ** internal memory allocation needs. "Core" in the previous sentence
  1933   1954   ** does not include operating-system specific VFS implementation.  The
................................................................................
  2297   2318   **
  2298   2319   ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
  2299   2320   ** <dd>The database is opened for reading and writing if possible, or reading
  2300   2321   ** only if the file is write protected by the operating system.  In either
  2301   2322   ** case the database must already exist, otherwise an error is returned.</dd>)^
  2302   2323   **
  2303   2324   ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
  2304         -** <dd>The database is opened for reading and writing, and is creates it if
         2325  +** <dd>The database is opened for reading and writing, and is created if
  2305   2326   ** it does not already exist. This is the behavior that is always used for
  2306   2327   ** sqlite3_open() and sqlite3_open16().</dd>)^
  2307   2328   ** </dl>
  2308   2329   **
  2309   2330   ** If the 3rd parameter to sqlite3_open_v2() is not one of the
  2310   2331   ** combinations shown above or one of the combinations shown above combined
  2311   2332   ** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX],
................................................................................
  2646   2667   ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
  2647   2668   */
  2648   2669   SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
  2649   2670   
  2650   2671   /*
  2651   2672   ** CAPI3REF: Determine If An SQL Statement Writes The Database
  2652   2673   **
  2653         -** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
  2654         -** the [prepared statement] X is [SELECT] statement and false (zero) if
  2655         -** X is an [INSERT], [UPDATE], [DELETE], CREATE, DROP, [ANALYZE],
  2656         -** [ALTER], or [REINDEX] statement.
  2657         -** If X is a NULL pointer or any other kind of statement, including but
  2658         -** not limited to [ATTACH], [DETACH], [COMMIT], [ROLLBACK], [RELEASE],
  2659         -** [SAVEPOINT], [PRAGMA], or [VACUUM] the result of sqlite3_stmt_readonly(X) is
  2660         -** undefined.
         2674  +** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if 
         2675  +** and only if the [prepared statement] X makes no direct changes to
         2676  +** the content of the database file.
         2677  +**
         2678  +** Note that [application-defined SQL functions] or
         2679  +** [virtual tables] might change the database indirectly as a side effect.  
         2680  +** ^(For example, if an application defines a function "eval()" that 
         2681  +** calls [sqlite3_exec()], then the following SQL statement would
         2682  +** change the database file through side-effects:
         2683  +**
         2684  +** <blockquote><pre>
         2685  +**    SELECT eval('DELETE FROM t1') FROM t2;
         2686  +** </pre></blockquote>
         2687  +**
         2688  +** But because the [SELECT] statement does not change the database file
         2689  +** directly, sqlite3_stmt_readonly() would still return true.)^
         2690  +**
         2691  +** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
         2692  +** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
         2693  +** since the statements themselves do not actually modify the database but
         2694  +** rather they control the timing of when other statements modify the 
         2695  +** database.  ^The [ATTACH] and [DETACH] statements also cause
         2696  +** sqlite3_stmt_readonly() to return true since, while those statements
         2697  +** change the configuration of a database connection, they do not make 
         2698  +** changes to the content of the database files on disk.
  2661   2699   */
  2662   2700   SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
  2663   2701   
  2664   2702   /*
  2665   2703   ** CAPI3REF: Dynamically Typed Value Object
  2666   2704   ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
  2667   2705   **
................................................................................
  3047   3085   ** [SQLITE_MISUSE] means that the this routine was called inappropriately.
  3048   3086   ** Perhaps it was called on a [prepared statement] that has
  3049   3087   ** already been [sqlite3_finalize | finalized] or on one that had
  3050   3088   ** previously returned [SQLITE_ERROR] or [SQLITE_DONE].  Or it could
  3051   3089   ** be the case that the same database connection is being used by two or
  3052   3090   ** more threads at the same moment in time.
  3053   3091   **
  3054         -** For all versions of SQLite up to and including 3.6.23.1, it was required
  3055         -** after sqlite3_step() returned anything other than [SQLITE_ROW] that
  3056         -** [sqlite3_reset()] be called before any subsequent invocation of
  3057         -** sqlite3_step().  Failure to invoke [sqlite3_reset()] in this way would
  3058         -** result in an [SQLITE_MISUSE] return from sqlite3_step().  But after
  3059         -** version 3.6.23.1, sqlite3_step() began calling [sqlite3_reset()] 
  3060         -** automatically in this circumstance rather than returning [SQLITE_MISUSE].  
         3092  +** For all versions of SQLite up to and including 3.6.23.1, a call to
         3093  +** [sqlite3_reset()] was required after sqlite3_step() returned anything
         3094  +** other than [SQLITE_ROW] before any subsequent invocation of
         3095  +** sqlite3_step().  Failure to reset the prepared statement using 
         3096  +** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
         3097  +** sqlite3_step().  But after version 3.6.23.1, sqlite3_step() began
         3098  +** calling [sqlite3_reset()] automatically in this circumstance rather
         3099  +** than returning [SQLITE_MISUSE].  This is not considered a compatibility
         3100  +** break because any application that ever receives an SQLITE_MISUSE error
         3101  +** is broken by definition.  The [SQLITE_OMIT_AUTORESET] compile-time option
         3102  +** can be used to restore the legacy behavior.
  3061   3103   **
  3062   3104   ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
  3063   3105   ** API always returns a generic error code, [SQLITE_ERROR], following any
  3064   3106   ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE].  You must call
  3065   3107   ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
  3066   3108   ** specific [error codes] that better describes the error.
  3067   3109   ** We admit that this is a goofy design.  The problem has been fixed
................................................................................
  3390   3432   ** will pick the one that involves the least amount of data conversion.
  3391   3433   ** If there is only a single implementation which does not care what text
  3392   3434   ** encoding is used, then the fourth argument should be [SQLITE_ANY].
  3393   3435   **
  3394   3436   ** ^(The fifth parameter is an arbitrary pointer.  The implementation of the
  3395   3437   ** function can gain access to this pointer using [sqlite3_user_data()].)^
  3396   3438   **
  3397         -** ^The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
         3439  +** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
  3398   3440   ** pointers to C-language functions that implement the SQL function or
  3399   3441   ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
  3400   3442   ** callback only; NULL pointers must be passed as the xStep and xFinal
  3401   3443   ** parameters. ^An aggregate SQL function requires an implementation of xStep
  3402   3444   ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
  3403   3445   ** SQL function or aggregate, pass NULL poiners for all three function
  3404   3446   ** callbacks.
  3405   3447   **
  3406         -** ^(If the tenth parameter to sqlite3_create_function_v2() is not NULL,
         3448  +** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL,
  3407   3449   ** then it is destructor for the application data pointer. 
  3408   3450   ** The destructor is invoked when the function is deleted, either by being
  3409   3451   ** overloaded or when the database connection closes.)^
  3410   3452   ** ^The destructor is also invoked if the call to
  3411   3453   ** sqlite3_create_function_v2() fails.
  3412   3454   ** ^When the destructor callback of the tenth parameter is invoked, it
  3413   3455   ** is passed a single argument which is a copy of the application data 
................................................................................
  3503   3545   ** The C-language implementation of SQL functions and aggregates uses
  3504   3546   ** this set of interface routines to access the parameter values on
  3505   3547   ** the function or aggregate.
  3506   3548   **
  3507   3549   ** The xFunc (for scalar functions) or xStep (for aggregates) parameters
  3508   3550   ** to [sqlite3_create_function()] and [sqlite3_create_function16()]
  3509   3551   ** define callbacks that implement the SQL functions and aggregates.
  3510         -** The 4th parameter to these callbacks is an array of pointers to
         3552  +** The 3rd parameter to these callbacks is an array of pointers to
  3511   3553   ** [protected sqlite3_value] objects.  There is one [sqlite3_value] object for
  3512   3554   ** each parameter to the SQL function.  These routines are used to
  3513   3555   ** extract values from the [sqlite3_value] objects.
  3514   3556   **
  3515   3557   ** These routines work only with [protected sqlite3_value] objects.
  3516   3558   ** Any attempt to use these routines on an [unprotected sqlite3_value]
  3517   3559   ** object results in undefined behavior.
................................................................................
  5231   5273   #define SQLITE_MUTEX_RECURSIVE        1
  5232   5274   #define SQLITE_MUTEX_STATIC_MASTER    2
  5233   5275   #define SQLITE_MUTEX_STATIC_MEM       3  /* sqlite3_malloc() */
  5234   5276   #define SQLITE_MUTEX_STATIC_MEM2      4  /* NOT USED */
  5235   5277   #define SQLITE_MUTEX_STATIC_OPEN      4  /* sqlite3BtreeOpen() */
  5236   5278   #define SQLITE_MUTEX_STATIC_PRNG      5  /* sqlite3_random() */
  5237   5279   #define SQLITE_MUTEX_STATIC_LRU       6  /* lru page list */
  5238         -#define SQLITE_MUTEX_STATIC_LRU2      7  /* lru page list */
         5280  +#define SQLITE_MUTEX_STATIC_LRU2      7  /* NOT USED */
         5281  +#define SQLITE_MUTEX_STATIC_PMEM      7  /* sqlite3PageMalloc() */
  5239   5282   
  5240   5283   /*
  5241   5284   ** CAPI3REF: Retrieve the mutex for a database connection
  5242   5285   **
  5243   5286   ** ^This interface returns a pointer the [sqlite3_mutex] object that 
  5244   5287   ** serializes access to the [database connection] given in the argument
  5245   5288   ** when the [threading mode] is Serialized.
................................................................................
  5382   5425   ** <dd>This parameter records the largest memory allocation request
  5383   5426   ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
  5384   5427   ** internal equivalents).  Only the value returned in the
  5385   5428   ** *pHighwater parameter to [sqlite3_status()] is of interest.  
  5386   5429   ** The value written into the *pCurrent parameter is undefined.</dd>)^
  5387   5430   **
  5388   5431   ** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
  5389         -** <dd>This parameter records the number of separate memory allocations.</dd>)^
         5432  +** <dd>This parameter records the number of separate memory allocations
         5433  +** currently checked out.</dd>)^
  5390   5434   **
  5391   5435   ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
  5392   5436   ** <dd>This parameter returns the number of pages used out of the
  5393   5437   ** [pagecache memory allocator] that was configured using 
  5394   5438   ** [SQLITE_CONFIG_PAGECACHE].  The
  5395   5439   ** value returned is in pages, not in bytes.</dd>)^
  5396   5440   **
................................................................................
  5487   5531   ** The [sqlite3_db_status()] interface will return a non-zero error code
  5488   5532   ** if a discontinued or unsupported verb is invoked.
  5489   5533   **
  5490   5534   ** <dl>
  5491   5535   ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
  5492   5536   ** <dd>This parameter returns the number of lookaside memory slots currently
  5493   5537   ** checked out.</dd>)^
         5538  +**
         5539  +** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
         5540  +** <dd>This parameter returns the number malloc attempts that were 
         5541  +** satisfied using lookaside memory. Only the high-water value is meaningful;
         5542  +** the current value is always zero.
         5543  +** checked out.</dd>)^
         5544  +**
         5545  +** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
         5546  +** <dd>This parameter returns the number malloc attempts that might have
         5547  +** been satisfied using lookaside memory but failed due to the amount of
         5548  +** memory requested being larger than the lookaside slot size.
         5549  +** Only the high-water value is meaningful;
         5550  +** the current value is always zero.
         5551  +** checked out.</dd>)^
         5552  +**
         5553  +** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
         5554  +** <dd>This parameter returns the number malloc attempts that might have
         5555  +** been satisfied using lookaside memory but failed due to all lookaside
         5556  +** memory already being in use.
         5557  +** Only the high-water value is meaningful;
         5558  +** the current value is always zero.
         5559  +** checked out.</dd>)^
  5494   5560   **
  5495   5561   ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
  5496   5562   ** <dd>This parameter returns the approximate number of of bytes of heap
  5497   5563   ** memory used by all pager caches associated with the database connection.)^
  5498   5564   ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
  5499   5565   **
  5500   5566   ** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
................................................................................
  5510   5576   ** <dd>This parameter returns the approximate number of of bytes of heap
  5511   5577   ** and lookaside memory used by all prepared statements associated with
  5512   5578   ** the database connection.)^
  5513   5579   ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
  5514   5580   ** </dd>
  5515   5581   ** </dl>
  5516   5582   */
  5517         -#define SQLITE_DBSTATUS_LOOKASIDE_USED     0
  5518         -#define SQLITE_DBSTATUS_CACHE_USED         1
  5519         -#define SQLITE_DBSTATUS_SCHEMA_USED        2
  5520         -#define SQLITE_DBSTATUS_STMT_USED          3
  5521         -#define SQLITE_DBSTATUS_MAX                3   /* Largest defined DBSTATUS */
         5583  +#define SQLITE_DBSTATUS_LOOKASIDE_USED       0
         5584  +#define SQLITE_DBSTATUS_CACHE_USED           1
         5585  +#define SQLITE_DBSTATUS_SCHEMA_USED          2
         5586  +#define SQLITE_DBSTATUS_STMT_USED            3
         5587  +#define SQLITE_DBSTATUS_LOOKASIDE_HIT        4
         5588  +#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE  5
         5589  +#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL  6
         5590  +#define SQLITE_DBSTATUS_MAX                  6   /* Largest defined DBSTATUS */
  5522   5591   
  5523   5592   
  5524   5593   /*
  5525   5594   ** CAPI3REF: Prepared Statement Status
  5526   5595   **
  5527   5596   ** ^(Each prepared statement maintains various
  5528   5597   ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
................................................................................
  5642   5711   **
  5643   5712   ** ^SQLite invokes the xCreate() method to construct a new cache instance.
  5644   5713   ** SQLite will typically create one cache instance for each open database file,
  5645   5714   ** though this is not guaranteed. ^The
  5646   5715   ** first parameter, szPage, is the size in bytes of the pages that must
  5647   5716   ** be allocated by the cache.  ^szPage will not be a power of two.  ^szPage
  5648   5717   ** will the page size of the database file that is to be cached plus an
  5649         -** increment (here called "R") of about 100 or 200.  SQLite will use the
         5718  +** increment (here called "R") of less than 250.  SQLite will use the
  5650   5719   ** extra R bytes on each page to store metadata about the underlying
  5651   5720   ** database page on disk.  The value of R depends
  5652   5721   ** on the SQLite version, the target platform, and how SQLite was compiled.
  5653         -** ^R is constant for a particular build of SQLite.  ^The second argument to
         5722  +** ^(R is constant for a particular build of SQLite. Except, there are two
         5723  +** distinct values of R when SQLite is compiled with the proprietary
         5724  +** ZIPVFS extension.)^  ^The second argument to
  5654   5725   ** xCreate(), bPurgeable, is true if the cache being created will
  5655   5726   ** be used to cache database pages of a file stored on disk, or
  5656   5727   ** false if it is used for an in-memory database. The cache implementation
  5657   5728   ** does not have to do anything special based with the value of bPurgeable;
  5658   5729   ** it is purely advisory.  ^On a cache where bPurgeable is false, SQLite will
  5659   5730   ** never invoke xUnpin() except to deliberately delete a page.
  5660   5731   ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
................................................................................
  5678   5749   ** 8-byte boundary. The page to be fetched is determined by the key. ^The
  5679   5750   ** mimimum key value is 1.  After it has been retrieved using xFetch, the page 
  5680   5751   ** is considered to be "pinned".
  5681   5752   **
  5682   5753   ** If the requested page is already in the page cache, then the page cache
  5683   5754   ** implementation must return a pointer to the page buffer with its content
  5684   5755   ** intact.  If the requested page is not already in the cache, then the
  5685         -** behavior of the cache implementation should use the value of the createFlag
         5756  +** cache implementation should use the value of the createFlag
  5686   5757   ** parameter to help it determined what action to take:
  5687   5758   **
  5688   5759   ** <table border=1 width=85% align=center>
  5689   5760   ** <tr><th> createFlag <th> Behaviour when page is not already in cache
  5690   5761   ** <tr><td> 0 <td> Do not allocate a new page.  Return NULL.
  5691   5762   ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
  5692   5763   **                 Otherwise return NULL.
................................................................................
  5762   5833   **
  5763   5834   ** The backup API copies the content of one database into another.
  5764   5835   ** It is useful either for creating backups of databases or
  5765   5836   ** for copying in-memory databases to or from persistent files. 
  5766   5837   **
  5767   5838   ** See Also: [Using the SQLite Online Backup API]
  5768   5839   **
  5769         -** ^Exclusive access is required to the destination database for the 
  5770         -** duration of the operation. ^However the source database is only
  5771         -** read-locked while it is actually being read; it is not locked
  5772         -** continuously for the entire backup operation. ^Thus, the backup may be
  5773         -** performed on a live source database without preventing other users from
         5840  +** ^SQLite holds a write transaction open on the destination database file
         5841  +** for the duration of the backup operation.
         5842  +** ^The source database is read-locked only while it is being read;
         5843  +** it is not locked continuously for the entire backup operation.
         5844  +** ^Thus, the backup may be performed on a live source database without
         5845  +** preventing other database connections from
  5774   5846   ** reading or writing to the source database while the backup is underway.
  5775   5847   ** 
  5776   5848   ** ^(To perform a backup operation: 
  5777   5849   **   <ol>
  5778   5850   **     <li><b>sqlite3_backup_init()</b> is called once to initialize the
  5779   5851   **         backup, 
  5780   5852   **     <li><b>sqlite3_backup_step()</b> is called one or more times to transfer 
................................................................................
  5793   5865   ** ^The database name is "main" for the main database, "temp" for the
  5794   5866   ** temporary database, or the name specified after the AS keyword in
  5795   5867   ** an [ATTACH] statement for an attached database.
  5796   5868   ** ^The S and M arguments passed to 
  5797   5869   ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
  5798   5870   ** and database name of the source database, respectively.
  5799   5871   ** ^The source and destination [database connections] (parameters S and D)
  5800         -** must be different or else sqlite3_backup_init(D,N,S,M) will file with
         5872  +** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
  5801   5873   ** an error.
  5802   5874   **
  5803   5875   ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
  5804         -** returned and an error code and error message are store3d in the
         5876  +** returned and an error code and error message are stored in the
  5805   5877   ** destination [database connection] D.
  5806   5878   ** ^The error code and message for the failed call to sqlite3_backup_init()
  5807   5879   ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
  5808   5880   ** [sqlite3_errmsg16()] functions.
  5809   5881   ** ^A successful call to sqlite3_backup_init() returns a pointer to an
  5810   5882   ** [sqlite3_backup] object.
  5811   5883   ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
................................................................................
  5814   5886   **
  5815   5887   ** <b>sqlite3_backup_step()</b>
  5816   5888   **
  5817   5889   ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between 
  5818   5890   ** the source and destination databases specified by [sqlite3_backup] object B.
  5819   5891   ** ^If N is negative, all remaining source pages are copied. 
  5820   5892   ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
  5821         -** are still more pages to be copied, then the function resturns [SQLITE_OK].
         5893  +** are still more pages to be copied, then the function returns [SQLITE_OK].
  5822   5894   ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
  5823   5895   ** from source to destination, then it returns [SQLITE_DONE].
  5824   5896   ** ^If an error occurs while running sqlite3_backup_step(B,N),
  5825   5897   ** then an [error code] is returned. ^As well as [SQLITE_OK] and
  5826   5898   ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
  5827   5899   ** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an
  5828   5900   ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.
  5829   5901   **
  5830   5902   ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
  5831   5903   ** <ol>
  5832   5904   ** <li> the destination database was opened read-only, or
  5833   5905   ** <li> the destination database is using write-ahead-log journaling
  5834   5906   ** and the destination and source page sizes differ, or
  5835         -** <li> The destination database is an in-memory database and the
         5907  +** <li> the destination database is an in-memory database and the
  5836   5908   ** destination and source page sizes differ.
  5837   5909   ** </ol>)^
  5838   5910   **
  5839   5911   ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
  5840   5912   ** the [sqlite3_busy_handler | busy-handler function]
  5841   5913   ** is invoked (if one is specified). ^If the 
  5842   5914   ** busy-handler returns non-zero before the lock is available, then 
................................................................................
  6159   6231   ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
  6160   6232   ** configured by this function.
  6161   6233   **
  6162   6234   ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
  6163   6235   ** from SQL.
  6164   6236   **
  6165   6237   ** ^Every new [database connection] defaults to having the auto-checkpoint
  6166         -** enabled with a threshold of 1000 pages.  The use of this interface
         6238  +** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
         6239  +** pages.  The use of this interface
  6167   6240   ** is only necessary if the default setting is found to be suboptimal
  6168   6241   ** for a particular application.
  6169   6242   */
  6170   6243   SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
  6171   6244   
  6172   6245   /*
  6173   6246   ** CAPI3REF: Checkpoint a database

Name change from SQLite.Interop/src/sqlite3ext.h to SQLite.Interop/src/core/sqlite3ext.h.


Name change from SQLite.Interop/AssemblyInfo.cpp to SQLite.Interop/src/win/AssemblyInfo.cpp.

     1      1   using namespace System::Reflection;
     2         -using namespace System::Runtime::CompilerServices;
            2  +using namespace System::Resources;
     3      3   using namespace System::Runtime::InteropServices;
     4      4   
     5         -//
     6         -// General Information about an assembly is controlled through the following
     7         -// set of attributes. Change these attribute values to modify the information
     8         -// associated with an assembly.
     9         -//
    10         -[assembly:AssemblyTitleAttribute("System.Data.SQLite")];
    11         -[assembly:AssemblyDescriptionAttribute("http://sourceforge.net/projects/sqlite-dotnet2")];
    12         -[assembly:AssemblyConfigurationAttribute("")];
    13         -[assembly:AssemblyCompanyAttribute("")];
            5  +#include "interop.h"
            6  +
            7  +[assembly:AssemblyTitleAttribute("SQLite.Interop")];
            8  +[assembly:AssemblyCompanyAttribute("Robert Simpson, et al.")];
            9  +[assembly:AssemblyDescriptionAttribute("System.Data.SQLite Interop Assembly")];
    14     10   [assembly:AssemblyProductAttribute("System.Data.SQLite")];
    15         -[assembly:AssemblyCopyrightAttribute("Released to the public domain")];
    16         -[assembly:AssemblyTrademarkAttribute("")];
    17         -[assembly:AssemblyCultureAttribute("")];
           11  +[assembly:AssemblyCopyrightAttribute("Public Domain")];
           12  +[assembly:AssemblyVersionAttribute(INTEROP_VERSION)];
           13  +[assembly:AssemblyFileVersionAttribute(INTEROP_VERSION)];
    18     14   
    19         -//
    20         -// Version information for an assembly consists of the following four values:
    21         -//
    22         -//      Major Version
    23         -//      Minor Version
    24         -//      Build Number
    25         -//      Revision
    26         -//
    27         -// You can specify all the value or you can default the Revision and Build Numbers
    28         -// by using the '*' as shown below:
           15  +#if DEBUG
           16  +[assembly:AssemblyConfiguration("Debug")];
           17  +#else
           18  +[assembly:AssemblyConfiguration("Release")];
           19  +#endif
    29     20   
    30         -[assembly:AssemblyVersionAttribute("1.0.17.0")];
    31         -[assembly:AssemblyFileVersionAttribute("1.0.17.0")];
    32         -
    33         -//
    34         -// In order to sign your assembly you must specify a key to use. Refer to the
    35         -// Microsoft CLR Framework documentation for more information on assembly signing.
    36         -//
    37         -// You can use the attributes below to control which key is used for signing.
    38         -// You can also use the project property page for signing under Common Properties
    39         -// to set the same information.
    40         -//
    41         -// Notes:
    42         -//   (*) If no key is specified, the assembly is not signed.
    43         -//   (*) KeyName refers to a key that has been installed in the Crypto Service
    44         -//       Provider (CSP) on your machine. KeyFile refers to a file which contains
    45         -//       a key.
    46         -//   (*) If the KeyFile and the KeyName values are both specified, the
    47         -//       following processing occurs:
    48         -//       (1) If the KeyName can be found in the CSP, that key is used.
    49         -//       (2) If the KeyName does not exist and the KeyFile does exist, the key
    50         -//           in the KeyFile is installed into the CSP and used.
    51         -//   (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
    52         -//        When specifying the KeyFile, the location of the KeyFile should be
    53         -//        relative to the project directory.
    54         -//   (*) Delay Signing is an advanced option - see the Microsoft CLR Framework
    55         -//       documentation for more information on this.
    56         -//
    57         -[assembly:AssemblyDelaySignAttribute(false)];
    58         -
    59         -#ifdef _WIN64
    60         -#ifdef _M_IA64 // Itanium
    61         -[assembly:AssemblyKeyFileAttribute("..\\System.Data.SQLite\\System.Data.SQLite.IA64.snk")];
    62         -#else // AMD64
    63         -[assembly:AssemblyKeyFileAttribute("..\\System.Data.SQLite\\System.Data.SQLite.X64.snk")];
    64         -#endif
    65         -#else
    66         -[assembly:AssemblyKeyFileAttribute("..\\System.Data.SQLite\\System.Data.SQLite.snk")];
    67         -#endif
    68         -[assembly:AssemblyKeyNameAttribute("")];
    69         -
           21  +[assembly:NeutralResourcesLanguage("en-US")];
    70     22   [assembly:ComVisible(false)];
    71         -

Name change from SQLite.Interop/crypt.c to SQLite.Interop/src/win/crypt.c.


Name change from SQLite.Interop/interop.c to SQLite.Interop/src/win/interop.c.

     1         -#include "src/sqlite3.c"
     2         -#include "extension-functions.c"
            1  +#include "../core/sqlite3.c"
            2  +#include "../contrib/extension-functions.c"
     3      3   #include "crypt.c"
     4      4   
     5      5   extern int RegisterExtensionFunctions(sqlite3 *db);
     6      6   
     7      7   #ifdef SQLITE_OS_WIN
     8      8   
     9      9   // Additional open flags, we use this one privately
................................................................................
   359    359     return n;
   360    360   }
   361    361   
   362    362   __declspec(dllexport) int WINAPI sqlite3_index_column_info_interop(sqlite3 *db, const char *zDb, const char *zIndexName, const char *zColumnName, int *sortOrder, int *onError, char **pzColl, int *plen)
   363    363   {
   364    364     Index *pIdx;
   365    365     Table *pTab;
   366         -  char *zErrMsg = 0;
   367    366     int n;
   368    367     pIdx = sqlite3FindIndex(db, zIndexName, zDb);
   369    368     if (!pIdx) return SQLITE_ERROR;
   370    369   
   371    370     pTab = pIdx->pTable;
   372    371     for (n = 0; n < pIdx->nColumn; n++)
   373    372     {
................................................................................
   408    407     return ret;
   409    408   }
   410    409   
   411    410   __declspec(dllexport) int WINAPI sqlite3_cursor_rowid(sqlite3_stmt *pstmt, int cursor, sqlite_int64 *prowid)
   412    411   {
   413    412     Vdbe *p = (Vdbe *)pstmt;
   414    413     sqlite3 *db = (p == NULL) ? NULL : p->db;
   415         -  int rc = 0;
   416    414     VdbeCursor *pC;
   417    415     int ret = 0;
   418    416   
   419    417     sqlite3_mutex_enter(db->mutex);
   420    418     while (1)
   421    419     {
   422    420       if (cursor < 0 || cursor >= p->nCursor)

Added SQLite.Interop/src/win/interop.h.

            1  +/*
            2  + *
            3  + * interop.h -
            4  + *
            5  + * Written by Joe Mistachkin.
            6  + * Released to the public domain, use at your own risk!
            7  + *
            8  + */
            9  +
           10  +#ifndef INTEROP_VERSION
           11  +#define INTEROP_VERSION       "1.0.67.0"
           12  +#endif

Changes to SQLite.NET.2008.sln.

     4      4   EndProject
     5      5   Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Data.SQLite.Module.2008", "System.Data.SQLite\System.Data.SQLite.Module.2008.csproj", "{AC139952-261A-4463-B6FA-AEBC25284A66}"
     6      6   EndProject
     7      7   Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Data.SQLite.Compact.2008", "System.Data.SQLite\System.Data.SQLite.Compact.2008.csproj", "{AC139951-261A-4463-B6FA-AEBC25283A66}"
     8      8   EndProject
     9      9   Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test.2008", "test\test.2008.csproj", "{E27B1B1E-19C0-45E8-AA74-B6E1C041A130}"
    10     10   EndProject
           11  +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SQLite.Interop", "SQLite.Interop\SQLite.Interop.2008.vcproj", "{53784BC1-A8BC-4AC8-8A3E-158D6807345A}"
           12  +	ProjectSection(ProjectDependencies) = postProject
           13  +		{AC139952-261A-4463-B6FA-AEBC25284A66} = {AC139952-261A-4463-B6FA-AEBC25284A66}
           14  +	EndProjectSection
           15  +EndProject
    11     16   Global
    12     17   	GlobalSection(SolutionConfigurationPlatforms) = preSolution
    13     18   		Debug|Any CPU = Debug|Any CPU
           19  +		Debug|Mixed Platforms = Debug|Mixed Platforms
           20  +		Debug|Win32 = Debug|Win32
    14     21   		Release|Any CPU = Release|Any CPU
           22  +		Release|Mixed Platforms = Release|Mixed Platforms
           23  +		Release|Win32 = Release|Win32
    15     24   	EndGlobalSection
    16     25   	GlobalSection(ProjectConfigurationPlatforms) = postSolution
    17     26   		{AC139952-261A-4463-B6FA-AEBC25283A66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    18     27   		{AC139952-261A-4463-B6FA-AEBC25283A66}.Debug|Any CPU.Build.0 = Debug|Any CPU
           28  +		{AC139952-261A-4463-B6FA-AEBC25283A66}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
           29  +		{AC139952-261A-4463-B6FA-AEBC25283A66}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
           30  +		{AC139952-261A-4463-B6FA-AEBC25283A66}.Debug|Win32.ActiveCfg = Debug|Any CPU
    19     31   		{AC139952-261A-4463-B6FA-AEBC25283A66}.Release|Any CPU.ActiveCfg = Release|Any CPU
    20     32   		{AC139952-261A-4463-B6FA-AEBC25283A66}.Release|Any CPU.Build.0 = Release|Any CPU
           33  +		{AC139952-261A-4463-B6FA-AEBC25283A66}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
           34  +		{AC139952-261A-4463-B6FA-AEBC25283A66}.Release|Mixed Platforms.Build.0 = Release|Any CPU
           35  +		{AC139952-261A-4463-B6FA-AEBC25283A66}.Release|Win32.ActiveCfg = Release|Any CPU
    21     36   		{AC139952-261A-4463-B6FA-AEBC25284A66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    22     37   		{AC139952-261A-4463-B6FA-AEBC25284A66}.Debug|Any CPU.Build.0 = Debug|Any CPU
           38  +		{AC139952-261A-4463-B6FA-AEBC25284A66}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
           39  +		{AC139952-261A-4463-B6FA-AEBC25284A66}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
           40  +		{AC139952-261A-4463-B6FA-AEBC25284A66}.Debug|Win32.ActiveCfg = Debug|Any CPU
    23     41   		{AC139952-261A-4463-B6FA-AEBC25284A66}.Release|Any CPU.ActiveCfg = Release|Any CPU
    24     42   		{AC139952-261A-4463-B6FA-AEBC25284A66}.Release|Any CPU.Build.0 = Release|Any CPU
           43  +		{AC139952-261A-4463-B6FA-AEBC25284A66}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
           44  +		{AC139952-261A-4463-B6FA-AEBC25284A66}.Release|Mixed Platforms.Build.0 = Release|Any CPU
           45  +		{AC139952-261A-4463-B6FA-AEBC25284A66}.Release|Win32.ActiveCfg = Release|Any CPU
    25     46   		{AC139951-261A-4463-B6FA-AEBC25283A66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    26     47   		{AC139951-261A-4463-B6FA-AEBC25283A66}.Debug|Any CPU.Build.0 = Debug|Any CPU
           48  +		{AC139951-261A-4463-B6FA-AEBC25283A66}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
           49  +		{AC139951-261A-4463-B6FA-AEBC25283A66}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
           50  +		{AC139951-261A-4463-B6FA-AEBC25283A66}.Debug|Win32.ActiveCfg = Debug|Any CPU
    27     51   		{AC139951-261A-4463-B6FA-AEBC25283A66}.Release|Any CPU.ActiveCfg = Release|Any CPU
    28     52   		{AC139951-261A-4463-B6FA-AEBC25283A66}.Release|Any CPU.Build.0 = Release|Any CPU
           53  +		{AC139951-261A-4463-B6FA-AEBC25283A66}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
           54  +		{AC139951-261A-4463-B6FA-AEBC25283A66}.Release|Mixed Platforms.Build.0 = Release|Any CPU
           55  +		{AC139951-261A-4463-B6FA-AEBC25283A66}.Release|Win32.ActiveCfg = Release|Any CPU
    29     56   		{E27B1B1E-19C0-45E8-AA74-B6E1C041A130}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    30     57   		{E27B1B1E-19C0-45E8-AA74-B6E1C041A130}.Debug|Any CPU.Build.0 = Debug|Any CPU
           58  +		{E27B1B1E-19C0-45E8-AA74-B6E1C041A130}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
           59  +		{E27B1B1E-19C0-45E8-AA74-B6E1C041A130}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
           60  +		{E27B1B1E-19C0-45E8-AA74-B6E1C041A130}.Debug|Win32.ActiveCfg = Debug|Any CPU
    31     61   		{E27B1B1E-19C0-45E8-AA74-B6E1C041A130}.Release|Any CPU.ActiveCfg = Release|Any CPU
    32     62   		{E27B1B1E-19C0-45E8-AA74-B6E1C041A130}.Release|Any CPU.Build.0 = Release|Any CPU
           63  +		{E27B1B1E-19C0-45E8-AA74-B6E1C041A130}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
           64  +		{E27B1B1E-19C0-45E8-AA74-B6E1C041A130}.Release|Mixed Platforms.Build.0 = Release|Any CPU
           65  +		{E27B1B1E-19C0-45E8-AA74-B6E1C041A130}.Release|Win32.ActiveCfg = Release|Any CPU
           66  +		{53784BC1-A8BC-4AC8-8A3E-158D6807345A}.Debug|Any CPU.ActiveCfg = Debug|Win32
           67  +		{53784BC1-A8BC-4AC8-8A3E-158D6807345A}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
           68  +		{53784BC1-A8BC-4AC8-8A3E-158D6807345A}.Debug|Mixed Platforms.Build.0 = Debug|Win32
           69  +		{53784BC1-A8BC-4AC8-8A3E-158D6807345A}.Debug|Win32.ActiveCfg = Debug|Win32
           70  +		{53784BC1-A8BC-4AC8-8A3E-158D6807345A}.Debug|Win32.Build.0 = Debug|Win32
           71  +		{53784BC1-A8BC-4AC8-8A3E-158D6807345A}.Release|Any CPU.ActiveCfg = Release|Win32
           72  +		{53784BC1-A8BC-4AC8-8A3E-158D6807345A}.Release|Mixed Platforms.ActiveCfg = Release|Win32
           73  +		{53784BC1-A8BC-4AC8-8A3E-158D6807345A}.Release|Mixed Platforms.Build.0 = Release|Win32
           74  +		{53784BC1-A8BC-4AC8-8A3E-158D6807345A}.Release|Win32.ActiveCfg = Release|Win32
           75  +		{53784BC1-A8BC-4AC8-8A3E-158D6807345A}.Release|Win32.Build.0 = Release|Win32
    33     76   	EndGlobalSection
    34     77   	GlobalSection(SolutionProperties) = preSolution
    35     78   		HideSolutionNode = FALSE
    36     79   	EndGlobalSection
    37     80   EndGlobal

Changes to SQLite.NET.Settings.targets.

    78     78       -->
    79     79       <ConfigurationSuffix Condition="'$(ConfigurationSuffix)' == ''"></ConfigurationSuffix>
    80     80   
    81     81       <!--
    82     82           NOTE: For interaction with the native SQLite implementation, use the
    83     83                 custom build interop DLL (i.e. "SQLite.Interop.DLL")?  By default,
    84     84                 this is disabled.  This property is mutually exclusive with the
    85         -              "UseSqliteStandard" one, below.
           85  +              "UseSqliteStandard" one, below.  This should always be disabled in
           86  +              the project file that builds the NetModule target.
    86     87       -->
    87     88       <UseInteropDll Condition="'$(UseInteropDll)' == ''">false</UseInteropDll>
    88     89   
    89     90       <!--
    90     91           NOTE: For interaction with the native SQLite implementation, use the
    91     92                 standard DLL (i.e. "sqlite3.dll")?  By default, this is enabled.
    92     93                 This property is mutually exclusive with the "UseInteropDll" one,
    93         -              above.
           94  +              above.  This should always be disabled in the project file that
           95  +              builds the NetModule target.
    94     96       -->
    95     97       <UseSqliteStandard Condition="'$(UseSqliteStandard)' == ''">true</UseSqliteStandard>
    96     98   
    97     99       <!--
    98    100           NOTE: Is the project being built to support the .NET Compact Framework?
    99    101       -->
   100    102       <IsCompactFramework Condition="'$(IsCompactFramework)' == ''">false</IsCompactFramework>

Changes to System.Data.SQLite/System.Data.SQLite.Module.2008.csproj.

    19     19       <RootNamespace>System.Data.SQLite</RootNamespace>
    20     20       <AssemblyName>System.Data.SQLite</AssemblyName>
    21     21       <OldToolsVersion>2.0</OldToolsVersion>
    22     22       <SignAssembly>false</SignAssembly>
    23     23       <SQLiteNetDir>$(MSBuildProjectDirectory)\..</SQLiteNetDir>
    24     24       <NetFx20>true</NetFx20>
    25     25       <ConfigurationSuffix>Module</ConfigurationSuffix>
           26  +    <UseInteropDll>false</UseInteropDll>
           27  +    <UseSqliteStandard>false</UseSqliteStandard>
    26     28     </PropertyGroup>
    27     29     <Import Project="$(SQLiteNetDir)\SQLite.NET.Settings.targets" />
    28     30     <PropertyGroup Condition="'$(BinaryOutputPath)' != ''">
    29     31       <OutputPath>$(BinaryOutputPath)</OutputPath>
    30     32       <DocumentationFile>$(BinaryOutputPath)System.Data.SQLite.xml</DocumentationFile>
    31     33     </PropertyGroup>
    32     34     <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

Changes to System.Data.SQLite/System.Data.SQLite.Module.2010.csproj.

    18     18       <AppDesignerFolder>Properties</AppDesignerFolder>
    19     19       <RootNamespace>System.Data.SQLite</RootNamespace>
    20     20       <AssemblyName>System.Data.SQLite</AssemblyName>
    21     21       <OldToolsVersion>3.5</OldToolsVersion>
    22     22       <SignAssembly>false</SignAssembly>
    23     23       <SQLiteNetDir>$(MSBuildProjectDirectory)\..</SQLiteNetDir>
    24     24       <ConfigurationSuffix>Module</ConfigurationSuffix>
           25  +    <UseInteropDll>false</UseInteropDll>
           26  +    <UseSqliteStandard>false</UseSqliteStandard>
    25     27     </PropertyGroup>
    26     28     <Import Project="$(SQLiteNetDir)\SQLite.NET.Settings.targets" />
    27     29     <PropertyGroup Condition="'$(BinaryOutputPath)' != ''">
    28     30       <OutputPath>$(BinaryOutputPath)</OutputPath>
    29     31       <DocumentationFile>$(BinaryOutputPath)System.Data.SQLite.xml</DocumentationFile>
    30     32     </PropertyGroup>
    31     33     <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">