System.Data.SQLite
Check-in [7b0eeb3816]
Not logged in

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

Overview
Comment:1.0.44.0
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sourceforge
Files: files | file ages | folders
SHA1: 7b0eeb381651a99fc30c20d5fcf4009fbb9cbfc8
User & Date: rmsimpson 2007-07-21 08:46:09
Context
2007-07-21
08:46
1.0.44.0 check-in: d189b55f98 user: rmsimpson tags: sourceforge
08:46
1.0.44.0 check-in: 7b0eeb3816 user: rmsimpson tags: sourceforge
2007-06-19
22:42
Code merge with SQLite 3.4.0 check-in: d9903df39e user: rmsimpson tags: sourceforge
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Doc/Extra/dbfactorysupport.html.

    93     93   <configuration>
    94     94     <system.data>
    95     95       <DbProviderFactories>
    96     96         <remove invariant="System.Data.SQLite"/>
    97     97         <add name="SQLite Data Provider" invariant="System.Data.SQLite" 
    98     98              description=".Net Framework Data Provider for SQLite"
    99     99              type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite,
   100         -                 Version=1.0.42.0, Culture=neutral,
          100  +                 Version=1.0.44.0, Culture=neutral,
   101    101                    PublicKeyToken=db937bc2d44ff139"/>
   102    102       </DbProviderFactories>
   103    103     </system.data>
   104    104   </configuration>
   105    105   </pre>
   106    106         </div>
   107    107         <p>

Changes to Doc/Extra/lang_analyze.html.

    96     96           with that one table are analyzed.</p>
    97     97         <p>
    98     98           The initial implementation stores all statistics in a single table named <b>sqlite_stat1</b>.
    99     99           Future enhancements may create additional tables with the same name pattern except
   100    100           with the "1" changed to a different digit. The <b>sqlite_stat1</b> table cannot be <a href="lang_droptable.html">DROP</a>ped, but all the content can be <a href="lang_delete.html">
   101    101             DELETE</a>d which has the same effect.</p>
   102    102         <p>
   103         -      <hr>
   104    103           &nbsp;</p>
          104  +      <hr>
   105    105         <div id="footer">
   106    106           <p>
   107    107             &nbsp;</p>
   108    108           <p>
   109    109           </p>
   110    110         </div>
   111    111       </div>
   112    112       </div>
   113    113     </body>
   114    114   </html>

Changes to Doc/Extra/lang_explain.html.

    76     76           of actually executing the command, the SQLite library will report back the sequence
    77     77           of virtual machine instructions it would have used to execute the command had the
    78     78           EXPLAIN keyword not been present. For additional information about virtual machine
    79     79           instructions see the <a href="http://www.sqlite.org/arch.html">architecture description</a>
    80     80           or the documentation on <a href="http://www.sqlite.org/opcode.html">available opcodes</a>
    81     81           for the virtual machine.</p>
    82     82         <p>
    83         -      <hr>
    84     83           &nbsp;</p>
           84  +      <hr>
    85     85         <div id="footer">
    86     86           <p>
    87     87             &nbsp;</p>
    88     88           <p>
    89     89           </p>
    90     90         </div>
    91     91       </div>
    92     92       </div>
    93     93     </body>
    94     94   </html>

Changes to Doc/Extra/lang_select.html.

   238    238           UNION ALL operators combine the results of the SELECTs to the right and left into
   239    239           a single big table. The difference is that in UNION all result rows are distinct
   240    240           where in UNION ALL there may be duplicates. The INTERSECT operator takes the intersection
   241    241           of the results of the left and right SELECTs. EXCEPT takes the result of left SELECT
   242    242           after removing the results of the right SELECT. When three or more SELECTs are connected
   243    243           into a compound, they group from left to right.</p>
   244    244         <p>
   245         -      <hr>
   246    245           &nbsp;</p>
          246  +      <hr>
   247    247         <div id="footer">
   248    248           <p>
   249    249             &nbsp;</p>
   250    250           <p>
   251    251           </p>
   252    252         </div>
   253    253       </div>
   254    254       </div>
   255    255     </body>
   256    256   </html>

Added Doc/Extra/lang_types.html.

            1  +<html dir="LTR" xmlns="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:MSHelp="http://msdn.microsoft.com/mshelp" xmlns:tool="http://www.microsoft.com/tooltip" xmlns:ndoc="urn:ndoc-preprocess">
            2  +  <head>
            3  +    <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252" />
            4  +    <title>TYPES</title>
            5  +    <link rel="stylesheet" type="text/css" href="ndoc.css"> </link>
            6  +    <link rel="stylesheet" type="text/css" href="user.css"> </link>
            7  +    <script type="text/javascript" src="ndoc.js"> </script>
            8  +  </head>
            9  +  <body style="display: none;">
           10  +    <input type="hidden" id="userDataCache" class="userDataStyle" />
           11  +    <input type="hidden" id="hiddenScrollOffset" />
           12  +    <img id="dropDownImage" style="display:none; height:0; width:0;" src="drpdown.gif" />
           13  +    <img id="dropDownHoverImage" style="display:none; height:0; width:0;" src="drpdown_orange.gif" />
           14  +    <img id="collapseImage" style="display:none; height:0; width:0;" src="collapse.gif" />
           15  +    <img id="expandImage" style="display:none; height:0; width:0;" src="exp.gif" />
           16  +    <img id="collapseAllImage" style="display:none; height:0; width:0;" src="collall.gif" />
           17  +    <img id="expandAllImage" style="display:none; height:0; width:0;" src="expall.gif" />
           18  +    <img id="copyImage" style="display:none; height:0; width:0;" src="copycode.gif" />
           19  +    <img id="copyHoverImage" style="display:none; height:0; width:0;" src="copycodeHighlight.gif" />
           20  +    <div id="header">
           21  +      <table width="100%" id="topTable">
           22  +        <tr id="headerTableRow1">
           23  +          <td align="left">
           24  +            TYPES&nbsp;</td>
           25  +        </tr>
           26  +        <tr id="headerTableRow2">
           27  +          <td align="left">
           28  +            <span id="nsrTitle">SQLite Language Reference Documentation</span>
           29  +          </td>
           30  +        </tr>
           31  +        <tr id="headerTableRow3" style="display:none">
           32  +          <td>
           33  +            <a id="seeAlsoSectionLink" href="#seeAlsoToggle" onclick="OpenSection(seeAlsoToggle)">See Also</a>
           34  +            <a id="exampleSectionLink" href="#codeExampleToggle" onclick="OpenSection(codeExampleToggle)">Example</a>
           35  +          </td>
           36  +        </tr>
           37  +     </table>
           38  +      <table width="100%" id="bottomTable" cellspacing="0" cellpadding="0" style="display:none">
           39  +        <tr>
           40  +          <td>
           41  +            <span onclick="ExpandCollapseAll(toggleAllImage)" style="cursor:default;" onkeypress="ExpandCollapseAll_CheckKey(toggleAllImage)" tabindex="0">
           42  +              <img ID="toggleAllImage" class="toggleAll" src="collall.gif" />
           43  +              <label id="collapseAllLabel" for="toggleAllImage" style="display: none;">
           44  +							Collapse All
           45  +						</label>
           46  +              <label id="expandAllLabel" for="toggleAllImage" style="display: none;">
           47  +							Expand All
           48  +						</label>
           49  +            </span>
           50  +          </td>
           51  +        </tr>
           52  +      </table>
           53  +    </div>
           54  +    <div id="mainSection">
           55  +    <div id="mainBody">
           56  +      <h1 class="heading">
           57  +        SQL As Understood By SQLite (sortof)</h1>
           58  +      <h4>
           59  +        TYPES</h4>
           60  +      <p>
           61  +        <table cellpadding="10">
           62  +          <tr>
           63  +            <td align="right" width="1%" nowrap>
           64  +              <i><font color="#ff3434">sql-statement</font></i> ::=</td>
           65  +            <td>
           66  +              <b><font color="#2c2cf0">TYPES </font></b>[<b><font color="#2c2cf0"></font></b><i><font
           67  +                color="#ff3434">datatype name</font></i><b><font color="#2c2cf0"></font></b>][,<b><font color="#2c2cf0"></font></b><i><font
           68  +                color="#ff3434">datatype name</font></i><b><font color="#2c2cf0"></font></b>][,<b><font color="#2c2cf0"></font></b><i><font
           69  +                color="#ff3434">datatype
           70  +                      name</font></i><b><font color="#2c2cf0"></font></b>][,<b><font color="#2c2cf0"></font></b><i><font
           71  +                color="#ff3434">...</font></i>] ; <em><span style="color: #ff3434">select-stmt</span></em></td>            
           72  +          </tr>
           73  +          <tr>
           74  +          <td align="right" width="1%" nowrap>
           75  +          <i><font color="#ff3434">select-stmt</font></i> ::=</td>
           76  +          <td>
           77  +            see <a href="lang_select.html">SELECT</a></td>
           78  +          </tr>
           79  +        </table>
           80  +      </p>
           81  +      <p>
           82  +        Use the TYPES keyword before a SELECT statement to provide the SQLite ADO.NET provider
           83  +        a list of return datatypes to expect from the subsequent SELECT statement.&nbsp;
           84  +      </p>
           85  +      <p>
           86  +        This is a language extension (aka <strong>hack</strong>) to SQLite specifically for the ADO.NET data
           87  +        provider.&nbsp; It is a pseudo-statement, meaning only the ADO.NET provider understands
           88  +        it.</p>
           89  +      <h3>
           90  +        Background</h3>
           91  +      <p>
           92  +        Due to SQLite's typeless nature, there are certain kinds of queries for which the
           93  +        ADO.NET provider cannot determine the proper return data type.&nbsp; Scalar and
           94  +        aggregate functions pose a particular problem because
           95  +        there is no requirement for a given scalar or aggregate function to return any particular
           96  +        datatype.&nbsp; As a matter of fact, scalar functions could theoretically return
           97  +        a different datatype for every row or column in a query and this is perfectly legal
           98  +        from SQLite's point of view.</p>
           99  +      <p>
          100  +        Since ADO.NET is designed around a typed system and we're shoe-horning SQLite into
          101  +        it, this keyword helps the provider out in cases where the return type cannot be easily determined.</p>
          102  +      <p>
          103  +        This command must be used in conjunction with a SELECT statement.&nbsp; It only
          104  +        works when both the TYPES keyword and its value(s) are passed along with a SELECT
          105  +        statement as a single semi-colon separated unit.</p>
          106  +      <h3>
          107  +        Examples</h3>
          108  +      <p>
          109  +        <strong><span style="color: #2c2cf0">TYPES</span> [bigint], [int], [smallint], [tinyint];<br />
          110  +          <span style="color: #2c2cf0">SELECT</span> 1, 2, 3, 4;</strong></p>
          111  +      <p>
          112  +        The above query would return the columns as types System.Int64, System.Int32, System.Int16
          113  +        and System.Byte respectively.</p>
          114  +      <p>
          115  +        <strong><span style="color: #2c2cf0">TYPES</span> [bigint], [int], , [tinyint];<br />
          116  +          <span style="color: #2c2cf0">SELECT</span> 1, 2, 3, 4;</strong></p>
          117  +      <p>
          118  +        In this sample, only columns 1, 2 and 4 would have explicit typing.&nbsp; Column
          119  +        3's datatype would pass though the system and be discovered normally.</p>
          120  +      <p>
          121  +        <strong><span style="color: #2c2cf0">TYPES</span> real;<br />
          122  +          <span style="color: #2c2cf0">SELECT</span> SUM(Cost) FROM [Products];</strong></p>
          123  +      <p>
          124  +        The above query explicitly tells the provider that the SUM aggregate function returns
          125  +        a System.Double.</p>
          126  +      <h3>
          127  +        Usage Notes</h3>
          128  +      <ul>
          129  +        <li>You cannot use parameters in the TYPES statement.</li>
          130  +        <li>The TYPES statement must be immediately followed by a SELECT statement.</li>
          131  +        <li>It is legal to pass multiple TYPES and SELECT statements in a multi-statement
          132  +          command.</li>
          133  +        <li>You may enclose datatypes in quotes <strong>""</strong> or brackets <strong>[]</strong>
          134  +          or those <strong>``</strong> thingies if you want.<br />
          135  +        </li>
          136  +      </ul>
          137  +      <hr>
          138  +      <div id="footer">
          139  +        <p>
          140  +          &nbsp;</p>
          141  +        <p>
          142  +        </p>
          143  +      </div>
          144  +    </div>
          145  +    </div>
          146  +  </body>
          147  +</html>

Changes to Doc/Extra/lang_vacuum.html.

     1      1   <html dir="LTR" xmlns="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:MSHelp="http://msdn.microsoft.com/mshelp" xmlns:tool="http://www.microsoft.com/tooltip" xmlns:ndoc="urn:ndoc-preprocess">
     2      2     <head>
     3      3       <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252" />
     4         -    <title>VACUUM</title>
            4  +    <title>TYPES</title>
     5      5       <link rel="stylesheet" type="text/css" href="ndoc.css"> </link>
     6      6       <link rel="stylesheet" type="text/css" href="user.css"> </link>
     7      7       <script type="text/javascript" src="ndoc.js"> </script>
     8      8     </head>
     9      9     <body style="display: none;">
    10     10       <input type="hidden" id="userDataCache" class="userDataStyle" />
    11     11       <input type="hidden" id="hiddenScrollOffset" />
................................................................................
    17     17       <img id="expandAllImage" style="display:none; height:0; width:0;" src="expall.gif" />
    18     18       <img id="copyImage" style="display:none; height:0; width:0;" src="copycode.gif" />
    19     19       <img id="copyHoverImage" style="display:none; height:0; width:0;" src="copycodeHighlight.gif" />
    20     20       <div id="header">
    21     21         <table width="100%" id="topTable">
    22     22           <tr id="headerTableRow1">
    23     23             <td align="left">
    24         -            VACUUM&nbsp;</td>
           24  +            TYPES&nbsp;</td>
    25     25           </tr>
    26     26           <tr id="headerTableRow2">
    27     27             <td align="left">
    28     28               <span id="nsrTitle">SQLite Language Reference Documentation</span>
    29     29             </td>
    30     30           </tr>
    31     31           <tr id="headerTableRow3" style="display:none">
................................................................................
    52     52         </table>
    53     53       </div>
    54     54       <div id="mainSection">
    55     55       <div id="mainBody">
    56     56         <h1 class="heading">
    57     57           SQL As Understood By SQLite</h1>
    58     58         <h4>
    59         -        VACUUM</h4>
           59  +        TYPES</h4>
    60     60         <p>
    61     61           <table cellpadding="10">
    62     62             <tr>
    63     63               <td align="right" width="1%" nowrap>
    64     64                 <i><font color="#ff3434">sql-statement</font></i> ::=</td>
    65     65               <td>
    66         -              <b><font color="#2c2cf0">VACUUM </font></b>[<b><font color="#2c2cf0"></font></b><i><font
    67         -                color="#ff3434">index-or-table-name</font></i><b><font color="#2c2cf0"></font></b>]<b><font
    68         -                  color="#2c2cf0"></font></b></td>
           66  +              <b><font color="#2c2cf0">TYPES </font></b>[<b><font color="#2c2cf0"></font></b><i><font
           67  +                color="#ff3434">datatype name</font></i><b><font color="#2c2cf0"></font></b>][,<b><font color="#2c2cf0"></font></b><i><font
           68  +                color="#ff3434">datatype name</font></i><b><font color="#2c2cf0"></font></b>][,<b><font color="#2c2cf0"></font></b><i><font
           69  +                color="#ff3434">datatype
           70  +                      name</font></i><b><font color="#2c2cf0"></font></b>][,<b><font color="#2c2cf0"></font></b><i><font
           71  +                color="#ff3434">...</font></i>] ; <em><span style="color: #ff3434">select stmt</span></em></td>
    69     72             </tr>
    70     73           </table>
    71     74         </p>
    72     75         <p>
    73     76           The VACUUM command is an SQLite extension modeled after a similar command found
    74     77           in PostgreSQL. If VACUUM is invoked with the name of a table or index then it is
    75     78           suppose to clean up the named table or index. In version 1.0 of SQLite, the VACUUM
................................................................................
    91     94         <p>
    92     95           This command will fail if there is an active transaction. This command has no effect
    93     96           on an in-memory database.</p>
    94     97         <p>
    95     98           As of SQLite version 3.1, an alternative to using the VACUUM command is auto-vacuum
    96     99           mode, enabled using the <a href="pragma.html#pragma_auto_vacuum">auto_vacuum pragma</a>.</p>
    97    100         <p>
    98         -      <hr>
    99    101           &nbsp;</p>
          102  +      <hr>
   100    103         <div id="footer">
   101    104           <p>
   102    105             &nbsp;</p>
   103    106           <p>
   104    107           </p>
   105    108         </div>
   106    109       </div>
   107    110       </div>
   108    111     </body>
   109    112   </html>

Changes to Doc/Extra/version.html.

    52     52           </tr>
    53     53         </table>
    54     54       </div>
    55     55       <div id="mainSection">
    56     56       <div id="mainBody">
    57     57   
    58     58         <h1 class="heading">Version History</h1>
           59  +    <p><b>1.0.44.0 - July 22, 2007</b></p>
           60  +    <ul>
           61  +    <li>Code merge with SQLite 3.4.1</li>
           62  +      <li>Fixed a bug in SQLiteConnection.Open() which threw the wrong kind of error in
           63  +        the wrong kind of way when a database file could not be opened or created.&nbsp;</li>
           64  +      <li>Small enhancements to the TYPES keyword, and added documentation for it in the
           65  +        help file.</li>
           66  +      <li>Hopefully fixed the occasional SQLITE_BUSY errors that cropped up when starting
           67  +        a transaction.&nbsp; Usually occurred in high-contention scenarios, and the underlying
           68  +        SQLite engine bypasses the busy handler in this scenario to return immediately.</li>
           69  +    </ul>
           70  +    <p><b>1.0.43.0 - June 21, 2007</b></p>
           71  +    <ul>
           72  +    <li>Code merge with SQLite 3.4.0</li>
           73  +      <li>Fixed a reuse bug in the SQLiteDataAdapter in conjunction with the SQLiteCommandBuilder.&nbsp;
           74  +      It's been there unnoticed for more than a year, so it looks like most folks never
           75  +      encountered it. </li>
           76  +      <li>Fixed an event handler bug in SQLiteCommandBuilder in which it could fail to unlatch
           77  +        from the DataAdapter when reused.&nbsp; Relates to the previous bugfix.</li>
           78  +      <li>Fixed a double-dispose bug in SQLiteStatement that triggered a SQLiteException.&nbsp;</li>
           79  +    </ul>
    59     80       <p><b>1.0.42.0 - June 1, 2007</b></p>
    60     81       <ul>
    61     82       <li>Code merge with SQLite 3.3.17</li>
    62     83         <li>Changed the SQLiteFunction static constructor so it only enumerates loaded modules
    63     84           that have referenced the SQLite assembly, which hopefully should cut down dramatically
    64     85           the time it takes for that function to execute.&nbsp;</li>
    65     86         <li>Added the FTS2 full-text search extension to the project.&nbsp; Look for FTS1

Changes to Doc/SQLite.NET.chm.

cannot compute difference between binary files

Changes to SQLite.Designer/AssemblyInfo.cs.

    28     28   //      Major Version
    29     29   //      Minor Version 
    30     30   //      Build Number
    31     31   //      Revision
    32     32   //
    33     33   // You can specify all the values or you can default the Revision and Build Numbers 
    34     34   // by using the '*' as shown below:
    35         -[assembly: AssemblyVersion("1.0.31.0")]
    36         -[assembly: AssemblyFileVersion("1.0.31.0")]
           35  +[assembly: AssemblyVersion("1.0.32.0")]
           36  +[assembly: AssemblyFileVersion("1.0.32.0")]
    37     37   [assembly: AssemblyDelaySignAttribute(false)]
    38     38   [assembly: AssemblyKeyFileAttribute("..\\System.Data.SQLite\\System.Data.SQLite.snk")]
    39     39   [assembly: AssemblyKeyNameAttribute("")]

Changes to SQLite.Designer/SQLite.Designer.csproj.

   148    148       <None Include="CtcComponents\PkgCmdID.h" />
   149    149     </ItemGroup>
   150    150     <ItemGroup>
   151    151       <Folder Include="Properties\" />
   152    152       <Folder Include="Resources\" />
   153    153     </ItemGroup>
   154    154     <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   155         -  <Import Project="C:\Program Files (x86)\Visual Studio 2005 SDK\2006.09\VisualStudioIntegration\Tools\Build\Microsoft.VsSDK.targets" />
          155  +  <Import Project="C:\Program Files (x86)\Visual Studio 2005 SDK\2007.02\VisualStudioIntegration\Tools\Build\Microsoft.VsSDK.targets" />
   156    156     <PropertyGroup>
   157    157       <PostBuildEvent>
   158    158       </PostBuildEvent>
   159    159     </PropertyGroup>
   160    160   </Project>

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

    46     46   			<Tool
    47     47   				Name="VCMIDLTool"
    48     48   			/>
    49     49   			<Tool
    50     50   				Name="VCCLCompilerTool"
    51     51   				Optimization="0"
    52     52   				AdditionalIncludeDirectories="..\src"
    53         -				PreprocessorDefinitions="WIN32;_DEBUG;_LIB;SQLITE_ENABLE_FTS1"
           53  +				PreprocessorDefinitions="WIN32;_DEBUG;_LIB;SQLITE_ENABLE_FTS1;SQLITE_CORE"
    54     54   				RuntimeLibrary="3"
    55     55   				RuntimeTypeInfo="false"
    56     56   				UsePrecompiledHeader="0"
    57     57   				DebugInformationFormat="3"
    58     58   			/>
    59     59   			<Tool
    60     60   				Name="VCManagedResourceCompilerTool"
................................................................................
   109    109   			/>
   110    110   			<Tool
   111    111   				Name="VCCLCompilerTool"
   112    112   				ExecutionBucket="7"
   113    113   				AdditionalOptions="/GS-"
   114    114   				Optimization="0"
   115    115   				AdditionalIncludeDirectories="..\src"
   116         -				PreprocessorDefinitions="WIN32;_DEBUG;_LIB;SQLITE_ENABLE_FTS1"
          116  +				PreprocessorDefinitions="WIN32;_DEBUG;_LIB;SQLITE_ENABLE_FTS1;SQLITE_CORE"
   117    117   				RuntimeTypeInfo="false"
   118    118   				UsePrecompiledHeader="0"
   119    119   				DebugInformationFormat="3"
   120    120   			/>
   121    121   			<Tool
   122    122   				Name="VCManagedResourceCompilerTool"
   123    123   			/>
................................................................................
   177    177   				Name="VCMIDLTool"
   178    178   				TargetEnvironment="2"
   179    179   			/>
   180    180   			<Tool
   181    181   				Name="VCCLCompilerTool"
   182    182   				Optimization="0"
   183    183   				AdditionalIncludeDirectories="..\src"
   184         -				PreprocessorDefinitions="WIN32;_DEBUG;_LIB;SQLITE_ENABLE_FTS1"
          184  +				PreprocessorDefinitions="WIN64;_DEBUG;_LIB;SQLITE_ENABLE_FTS1;SQLITE_CORE"
   185    185   				RuntimeLibrary="3"
   186    186   				RuntimeTypeInfo="false"
   187    187   				UsePrecompiledHeader="0"
   188    188   				DebugInformationFormat="3"
   189    189   			/>
   190    190   			<Tool
   191    191   				Name="VCManagedResourceCompilerTool"
................................................................................
   238    238   				Name="VCMIDLTool"
   239    239   				TargetEnvironment="3"
   240    240   			/>
   241    241   			<Tool
   242    242   				Name="VCCLCompilerTool"
   243    243   				Optimization="0"
   244    244   				AdditionalIncludeDirectories="..\src"
   245         -				PreprocessorDefinitions="WIN32;_DEBUG;_LIB;SQLITE_ENABLE_FTS1"
          245  +				PreprocessorDefinitions="WIN64;_DEBUG;_LIB;SQLITE_ENABLE_FTS1;SQLITE_CORE"
   246    246   				RuntimeLibrary="3"
   247    247   				RuntimeTypeInfo="false"
   248    248   				UsePrecompiledHeader="0"
   249    249   				DebugInformationFormat="3"
   250    250   			/>
   251    251   			<Tool
   252    252   				Name="VCManagedResourceCompilerTool"
................................................................................
   299    299   			<Tool
   300    300   				Name="VCMIDLTool"
   301    301   			/>
   302    302   			<Tool
   303    303   				Name="VCCLCompilerTool"
   304    304   				FavorSizeOrSpeed="1"
   305    305   				AdditionalIncludeDirectories="..\src"
   306         -				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;SQLITE_ENABLE_FTS1"
          306  +				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;SQLITE_ENABLE_FTS1;SQLITE_CORE"
   307    307   				StringPooling="true"
   308    308   				ExceptionHandling="0"
   309    309   				BufferSecurityCheck="false"
   310    310   				EnableFunctionLevelLinking="true"
   311    311   				RuntimeTypeInfo="false"
   312    312   				UsePrecompiledHeader="0"
   313    313   			/>
................................................................................
   364    364   				TargetEnvironment="1"
   365    365   			/>
   366    366   			<Tool
   367    367   				Name="VCCLCompilerTool"
   368    368   				ExecutionBucket="7"
   369    369   				FavorSizeOrSpeed="1"
   370    370   				AdditionalIncludeDirectories="..\src"
   371         -				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;SQLITE_ENABLE_FTS1"
          371  +				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;SQLITE_ENABLE_FTS1;SQLITE_CORE"
   372    372   				StringPooling="true"
   373    373   				ExceptionHandling="0"
   374    374   				BufferSecurityCheck="false"
   375    375   				EnableFunctionLevelLinking="true"
   376    376   				RuntimeTypeInfo="false"
   377    377   				UsePrecompiledHeader="0"
   378    378   			/>
................................................................................
   436    436   				Name="VCMIDLTool"
   437    437   				TargetEnvironment="2"
   438    438   			/>
   439    439   			<Tool
   440    440   				Name="VCCLCompilerTool"
   441    441   				FavorSizeOrSpeed="1"
   442    442   				AdditionalIncludeDirectories="..\src"
   443         -				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;SQLITE_ENABLE_FTS1"
          443  +				PreprocessorDefinitions="WIN64;NDEBUG;_LIB;SQLITE_ENABLE_FTS1;SQLITE_CORE"
   444    444   				StringPooling="true"
   445    445   				ExceptionHandling="0"
   446    446   				BufferSecurityCheck="false"
   447    447   				EnableFunctionLevelLinking="true"
   448    448   				RuntimeTypeInfo="false"
   449    449   				UsePrecompiledHeader="0"
   450    450   			/>
................................................................................
   500    500   				Name="VCMIDLTool"
   501    501   				TargetEnvironment="3"
   502    502   			/>
   503    503   			<Tool
   504    504   				Name="VCCLCompilerTool"
   505    505   				FavorSizeOrSpeed="1"
   506    506   				AdditionalIncludeDirectories="..\src"
   507         -				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;SQLITE_ENABLE_FTS1"
          507  +				PreprocessorDefinitions="WIN64;NDEBUG;_LIB;SQLITE_ENABLE_FTS1;SQLITE_CORE"
   508    508   				StringPooling="true"
   509    509   				ExceptionHandling="0"
   510    510   				BufferSecurityCheck="false"
   511    511   				EnableFunctionLevelLinking="true"
   512    512   				RuntimeTypeInfo="false"
   513    513   				UsePrecompiledHeader="0"
   514    514   			/>

Changes to SQLite.Interop/FTS1/fts1.c.

  1560   1560         return 0;
  1561   1561       }
  1562   1562       case ' ': case '\t': case '\n': case '\f': case '\r': {
  1563   1563         for(i=1; safe_isspace(z[i]); i++){}
  1564   1564         *tokenType = TOKEN_SPACE;
  1565   1565         return i;
  1566   1566       }
         1567  +    case '`':
  1567   1568       case '\'':
  1568   1569       case '"': {
  1569   1570         int delim = z[0];
  1570   1571         for(i=1; (c=z[i])!=0; i++){
  1571   1572           if( c==delim ){
  1572   1573             if( z[i+1]==delim ){
  1573   1574               i++;

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

    46     46   			<Tool
    47     47   				Name="VCMIDLTool"
    48     48   			/>
    49     49   			<Tool
    50     50   				Name="VCCLCompilerTool"
    51     51   				Optimization="0"
    52     52   				AdditionalIncludeDirectories="..\src"
    53         -				PreprocessorDefinitions="WIN32;_DEBUG;_LIB;SQLITE_ENABLE_FTS2"
           53  +				PreprocessorDefinitions="WIN32;_DEBUG;_LIB;SQLITE_ENABLE_FTS2;SQLITE_CORE"
    54     54   				RuntimeLibrary="3"
    55     55   				RuntimeTypeInfo="false"
    56     56   				UsePrecompiledHeader="0"
    57     57   				DebugInformationFormat="3"
    58     58   			/>
    59     59   			<Tool
    60     60   				Name="VCManagedResourceCompilerTool"
................................................................................
   109    109   			/>
   110    110   			<Tool
   111    111   				Name="VCCLCompilerTool"
   112    112   				ExecutionBucket="7"
   113    113   				AdditionalOptions="/GS-"
   114    114   				Optimization="0"
   115    115   				AdditionalIncludeDirectories="..\src"
   116         -				PreprocessorDefinitions="WIN32;_DEBUG;_LIB;SQLITE_ENABLE_FTS2"
          116  +				PreprocessorDefinitions="WIN32;_DEBUG;_LIB;SQLITE_ENABLE_FTS2;SQLITE_CORE"
   117    117   				RuntimeTypeInfo="false"
   118    118   				UsePrecompiledHeader="0"
   119    119   				DebugInformationFormat="3"
   120    120   			/>
   121    121   			<Tool
   122    122   				Name="VCManagedResourceCompilerTool"
   123    123   			/>
................................................................................
   177    177   				Name="VCMIDLTool"
   178    178   				TargetEnvironment="2"
   179    179   			/>
   180    180   			<Tool
   181    181   				Name="VCCLCompilerTool"
   182    182   				Optimization="0"
   183    183   				AdditionalIncludeDirectories="..\src"
   184         -				PreprocessorDefinitions="WIN32;_DEBUG;_LIB;SQLITE_ENABLE_FTS2"
          184  +				PreprocessorDefinitions="WIN64;_DEBUG;_LIB;SQLITE_ENABLE_FTS2;SQLITE_CORE"
   185    185   				RuntimeLibrary="3"
   186    186   				RuntimeTypeInfo="false"
   187    187   				UsePrecompiledHeader="0"
   188    188   				DebugInformationFormat="3"
   189    189   			/>
   190    190   			<Tool
   191    191   				Name="VCManagedResourceCompilerTool"
................................................................................
   238    238   				Name="VCMIDLTool"
   239    239   				TargetEnvironment="3"
   240    240   			/>
   241    241   			<Tool
   242    242   				Name="VCCLCompilerTool"
   243    243   				Optimization="0"
   244    244   				AdditionalIncludeDirectories="..\src"
   245         -				PreprocessorDefinitions="WIN32;_DEBUG;_LIB;SQLITE_ENABLE_FTS2"
          245  +				PreprocessorDefinitions="WIN64;_DEBUG;_LIB;SQLITE_ENABLE_FTS2;SQLITE_CORE"
   246    246   				RuntimeLibrary="3"
   247    247   				RuntimeTypeInfo="false"
   248    248   				UsePrecompiledHeader="0"
   249    249   				DebugInformationFormat="3"
   250    250   			/>
   251    251   			<Tool
   252    252   				Name="VCManagedResourceCompilerTool"
................................................................................
   299    299   			<Tool
   300    300   				Name="VCMIDLTool"
   301    301   			/>
   302    302   			<Tool
   303    303   				Name="VCCLCompilerTool"
   304    304   				FavorSizeOrSpeed="1"
   305    305   				AdditionalIncludeDirectories="..\src"
   306         -				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;SQLITE_ENABLE_FTS2"
          306  +				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;SQLITE_ENABLE_FTS2;SQLITE_CORE"
   307    307   				StringPooling="true"
   308    308   				ExceptionHandling="0"
   309    309   				BufferSecurityCheck="false"
   310    310   				EnableFunctionLevelLinking="true"
   311    311   				RuntimeTypeInfo="false"
   312    312   				UsePrecompiledHeader="0"
   313    313   			/>
................................................................................
   362    362   			<Tool
   363    363   				Name="VCMIDLTool"
   364    364   				TargetEnvironment="1"
   365    365   			/>
   366    366   			<Tool
   367    367   				Name="VCCLCompilerTool"
   368    368   				ExecutionBucket="7"
   369         -				FavorSizeOrSpeed="1"
          369  +				Optimization="1"
   370    370   				AdditionalIncludeDirectories="..\src"
   371         -				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;SQLITE_ENABLE_FTS2"
          371  +				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;SQLITE_ENABLE_FTS2;SQLITE_CORE"
   372    372   				StringPooling="true"
   373    373   				ExceptionHandling="0"
   374    374   				BufferSecurityCheck="false"
   375    375   				EnableFunctionLevelLinking="true"
   376    376   				RuntimeTypeInfo="false"
   377    377   				UsePrecompiledHeader="0"
   378    378   			/>
................................................................................
   436    436   				Name="VCMIDLTool"
   437    437   				TargetEnvironment="2"
   438    438   			/>
   439    439   			<Tool
   440    440   				Name="VCCLCompilerTool"
   441    441   				FavorSizeOrSpeed="1"
   442    442   				AdditionalIncludeDirectories="..\src"
   443         -				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;SQLITE_ENABLE_FTS2"
          443  +				PreprocessorDefinitions="WIN64;NDEBUG;_LIB;SQLITE_ENABLE_FTS2;SQLITE_CORE"
   444    444   				StringPooling="true"
   445    445   				ExceptionHandling="0"
   446    446   				BufferSecurityCheck="false"
   447    447   				EnableFunctionLevelLinking="true"
   448    448   				RuntimeTypeInfo="false"
   449    449   				UsePrecompiledHeader="0"
   450    450   			/>
................................................................................
   500    500   				Name="VCMIDLTool"
   501    501   				TargetEnvironment="3"
   502    502   			/>
   503    503   			<Tool
   504    504   				Name="VCCLCompilerTool"
   505    505   				FavorSizeOrSpeed="1"
   506    506   				AdditionalIncludeDirectories="..\src"
   507         -				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;SQLITE_ENABLE_FTS2"
          507  +				PreprocessorDefinitions="WIN64;NDEBUG;_LIB;SQLITE_ENABLE_FTS2;SQLITE_CORE"
   508    508   				StringPooling="true"
   509    509   				ExceptionHandling="0"
   510    510   				BufferSecurityCheck="false"
   511    511   				EnableFunctionLevelLinking="true"
   512    512   				RuntimeTypeInfo="false"
   513    513   				UsePrecompiledHeader="0"
   514    514   			/>
................................................................................
   556    556   			<File
   557    557   				RelativePath=".\fts2_hash.c"
   558    558   				>
   559    559   			</File>
   560    560   			<File
   561    561   				RelativePath=".\fts2_porter.c"
   562    562   				>
          563  +			</File>
          564  +			<File
          565  +				RelativePath=".\fts2_tokenizer.c"
          566  +				>
   563    567   			</File>
   564    568   			<File
   565    569   				RelativePath=".\fts2_tokenizer1.c"
   566    570   				>
   567    571   			</File>
   568    572   		</Filter>
   569    573   		<Filter

Changes to SQLite.Interop/FTS2/fts2.c.

     1         -/* The author disclaims copyright to this source code.
     2         - *
     3         - * This is an SQLite module implementing full-text search.
     4         - */
            1  +/*
            2  +** 2006 Oct 10
            3  +**
            4  +** The author disclaims copyright to this source code.  In place of
            5  +** a legal notice, here is a blessing:
            6  +**
            7  +**    May you do good and not evil.
            8  +**    May you find forgiveness for yourself and forgive others.
            9  +**    May you share freely, never taking more than you give.
           10  +**
           11  +******************************************************************************
           12  +**
           13  +** This is an SQLite module implementing full-text search.
           14  +*/
     5     15   
     6     16   /*
     7     17   ** The code in this file is only compiled if:
     8     18   **
     9     19   **     * The FTS2 module is being built as an extension
    10     20   **       (in which case SQLITE_CORE is not defined), or
    11     21   **
................................................................................
  1843   1853     DLReader reader;                 /* Result reader if result not empty */
  1844   1854   } fulltext_cursor;
  1845   1855   
  1846   1856   static struct fulltext_vtab *cursor_vtab(fulltext_cursor *c){
  1847   1857     return (fulltext_vtab *) c->base.pVtab;
  1848   1858   }
  1849   1859   
  1850         -static const sqlite3_module fulltextModule;   /* forward declaration */
         1860  +static const sqlite3_module fts2Module;   /* forward declaration */
  1851   1861   
  1852   1862   /* Return a dynamically generated statement of the form
  1853   1863    *   insert into %_content (rowid, ...) values (?, ...)
  1854   1864    */
  1855   1865   static const char *contentInsertStatement(fulltext_vtab *v){
  1856   1866     StringBuffer sb;
  1857   1867     int i;
................................................................................
  1933   1943   
  1934   1944     while( (rc=sqlite3_step(s))!=SQLITE_DONE && rc!=SQLITE_ROW ){
  1935   1945       sqlite3_stmt *pNewStmt;
  1936   1946   
  1937   1947       if( rc==SQLITE_BUSY ) continue;
  1938   1948       if( rc!=SQLITE_ERROR ) return rc;
  1939   1949   
  1940         -    rc = sqlite3_reset(s);
  1941         -    if( rc!=SQLITE_SCHEMA ) return SQLITE_ERROR;
  1942         -
  1943         -    v->pFulltextStatements[iStmt] = NULL;   /* Still in s */
  1944         -    rc = sql_get_statement(v, iStmt, &pNewStmt);
  1945         -    if( rc!=SQLITE_OK ) goto err;
  1946         -    *ppStmt = pNewStmt;
  1947         -
  1948         -    rc = sqlite3_transfer_bindings(s, pNewStmt);
  1949         -    if( rc!=SQLITE_OK ) goto err;
  1950         -
         1950  +    /* If an SQLITE_SCHEMA error has occured, then finalizing this
         1951  +     * statement is going to delete the fulltext_vtab structure. If
         1952  +     * the statement just executed is in the pFulltextStatements[]
         1953  +     * array, it will be finalized twice. So remove it before
         1954  +     * calling sqlite3_finalize().
         1955  +     */
         1956  +    v->pFulltextStatements[iStmt] = NULL;
  1951   1957       rc = sqlite3_finalize(s);
  1952         -    if( rc!=SQLITE_OK ) return rc;
  1953         -    s = pNewStmt;
         1958  +    break;
  1954   1959     }
  1955   1960     return rc;
  1956   1961   
  1957   1962    err:
  1958   1963     sqlite3_finalize(s);
  1959   1964     return rc;
  1960   1965   }
................................................................................
  2004   2009   
  2005   2010     while( (rc=sqlite3_step(s))!=SQLITE_DONE && rc!=SQLITE_ROW ){
  2006   2011       sqlite3_stmt *pNewStmt;
  2007   2012   
  2008   2013       if( rc==SQLITE_BUSY ) continue;
  2009   2014       if( rc!=SQLITE_ERROR ) return rc;
  2010   2015   
  2011         -    rc = sqlite3_reset(s);
  2012         -    if( rc!=SQLITE_SCHEMA ) return SQLITE_ERROR;
  2013         -
  2014         -    v->pLeafSelectStmts[idx] = NULL;   /* Still in s */
  2015         -    rc = sql_get_leaf_statement(v, idx, &pNewStmt);
  2016         -    if( rc!=SQLITE_OK ) goto err;
  2017         -    *ppStmt = pNewStmt;
  2018         -
  2019         -    rc = sqlite3_transfer_bindings(s, pNewStmt);
  2020         -    if( rc!=SQLITE_OK ) goto err;
  2021         -
         2016  +    /* If an SQLITE_SCHEMA error has occured, then finalizing this
         2017  +     * statement is going to delete the fulltext_vtab structure. If
         2018  +     * the statement just executed is in the pLeafSelectStmts[]
         2019  +     * array, it will be finalized twice. So remove it before
         2020  +     * calling sqlite3_finalize().
         2021  +     */
         2022  +    v->pLeafSelectStmts[idx] = NULL;
  2022   2023       rc = sqlite3_finalize(s);
  2023         -    if( rc!=SQLITE_OK ) return rc;
  2024         -    s = pNewStmt;
         2024  +    break;
  2025   2025     }
  2026         -  return rc;
  2027   2026   
  2028         - err:
  2029         -  sqlite3_finalize(s);
  2030   2027     return rc;
  2031   2028   }
  2032   2029   
  2033   2030   /* insert into %_content (rowid, ...) values ([rowid], [pValues]) */
  2034   2031   static int content_insert(fulltext_vtab *v, sqlite3_value *rowid,
  2035   2032                             sqlite3_value **pValues){
  2036   2033     sqlite3_stmt *s;
................................................................................
  2398   2395         return 0;
  2399   2396       }
  2400   2397       case ' ': case '\t': case '\n': case '\f': case '\r': {
  2401   2398         for(i=1; safe_isspace(z[i]); i++){}
  2402   2399         *tokenType = TOKEN_SPACE;
  2403   2400         return i;
  2404   2401       }
         2402  +    case '`':
  2405   2403       case '\'':
  2406   2404       case '"': {
  2407   2405         int delim = z[0];
  2408   2406         for(i=1; (c=z[i])!=0; i++){
  2409   2407           if( c==delim ){
  2410   2408             if( z[i+1]==delim ){
  2411   2409               i++;
................................................................................
  2757   2755   
  2758   2756   /*
  2759   2757   ** Build a new sqlite3_vtab structure that will describe the
  2760   2758   ** fulltext index defined by spec.
  2761   2759   */
  2762   2760   static int constructVtab(
  2763   2761     sqlite3 *db,              /* The SQLite database connection */
         2762  +  fts2Hash *pHash,          /* Hash table containing tokenizers */
  2764   2763     TableSpec *spec,          /* Parsed spec information from parseSpec() */
  2765   2764     sqlite3_vtab **ppVTab,    /* Write the resulting vtab structure here */
  2766   2765     char **pzErr              /* Write any error message here */
  2767   2766   ){
  2768   2767     int rc;
  2769   2768     int n;
  2770   2769     fulltext_vtab *v = 0;
  2771   2770     const sqlite3_tokenizer_module *m = NULL;
  2772   2771     char *schema;
         2772  +
         2773  +  char const *zTok;         /* Name of tokenizer to use for this fts table */
         2774  +  int nTok;                 /* Length of zTok, including nul terminator */
  2773   2775   
  2774   2776     v = (fulltext_vtab *) malloc(sizeof(fulltext_vtab));
  2775   2777     if( v==0 ) return SQLITE_NOMEM;
  2776   2778     CLEAR(v);
  2777   2779     /* sqlite will initialize v->base */
  2778   2780     v->db = db;
  2779   2781     v->zDb = spec->zDb;       /* Freed when azColumn is freed */
................................................................................
  2783   2785     spec->azContentColumn = 0;
  2784   2786     v->azColumn = spec->azColumn;
  2785   2787     spec->azColumn = 0;
  2786   2788   
  2787   2789     if( spec->azTokenizer==0 ){
  2788   2790       return SQLITE_NOMEM;
  2789   2791     }
  2790         -  /* TODO(shess) For now, add new tokenizers as else if clauses. */
  2791         -  if( spec->azTokenizer[0]==0 || startsWith(spec->azTokenizer[0], "simple") ){
  2792         -    sqlite3Fts2SimpleTokenizerModule(&m);
  2793         -  }else if( startsWith(spec->azTokenizer[0], "porter") ){
  2794         -    sqlite3Fts2PorterTokenizerModule(&m);
  2795         -  }else{
         2792  +
         2793  +  zTok = spec->azTokenizer[0]; 
         2794  +  if( !zTok ){
         2795  +    zTok = "simple";
         2796  +  }
         2797  +  nTok = strlen(zTok)+1;
         2798  +
         2799  +  m = (sqlite3_tokenizer_module *)sqlite3Fts2HashFind(pHash, zTok, nTok);
         2800  +  if( !m ){
  2796   2801       *pzErr = sqlite3_mprintf("unknown tokenizer: %s", spec->azTokenizer[0]);
  2797   2802       rc = SQLITE_ERROR;
  2798   2803       goto err;
  2799   2804     }
         2805  +
  2800   2806     for(n=0; spec->azTokenizer[n]; n++){}
  2801   2807     if( n ){
  2802   2808       rc = m->xCreate(n-1, (const char*const*)&spec->azTokenizer[1],
  2803   2809                       &v->pTokenizer);
  2804   2810     }else{
  2805   2811       rc = m->xCreate(0, 0, &v->pTokenizer);
  2806   2812     }
................................................................................
  2837   2843     sqlite3_vtab **ppVTab,
  2838   2844     char **pzErr
  2839   2845   ){
  2840   2846     TableSpec spec;
  2841   2847     int rc = parseSpec(&spec, argc, argv, pzErr);
  2842   2848     if( rc!=SQLITE_OK ) return rc;
  2843   2849   
  2844         -  rc = constructVtab(db, &spec, ppVTab, pzErr);
         2850  +  rc = constructVtab(db, (fts2Hash *)pAux, &spec, ppVTab, pzErr);
  2845   2851     clearTableSpec(&spec);
  2846   2852     return rc;
  2847   2853   }
  2848   2854   
  2849   2855   /* The %_content table holds the text of each document, with
  2850   2856   ** the rowid used as the docid.
  2851   2857   */
................................................................................
  2883   2889                   "  leaves_end_block integer,"
  2884   2890                   "  end_block integer,"
  2885   2891                   "  root blob,"
  2886   2892                   "  primary key(level, idx)"
  2887   2893                   ");");
  2888   2894     if( rc!=SQLITE_OK ) goto out;
  2889   2895   
  2890         -  rc = constructVtab(db, &spec, ppVTab, pzErr);
         2896  +  rc = constructVtab(db, (fts2Hash *)pAux, &spec, ppVTab, pzErr);
  2891   2897   
  2892   2898   out:
  2893   2899     clearTableSpec(&spec);
  2894   2900     return rc;
  2895   2901   }
  2896   2902   
  2897   2903   /* Decide how to handle an SQL query. */
................................................................................
  3101   3107     int iFirst, iLast;
  3102   3108     fulltext_vtab *pFts;
  3103   3109   
  3104   3110     if( p->snippet.nMatch ) return;
  3105   3111     if( p->q.nTerms==0 ) return;
  3106   3112     pFts = p->q.pFts;
  3107   3113     nColumn = pFts->nColumn;
  3108         -  iColumn = p->iCursorType;
         3114  +  iColumn = (p->iCursorType - QUERY_FULLTEXT);
  3109   3115     if( iColumn<0 || iColumn>=nColumn ){
  3110   3116       iFirst = 0;
  3111   3117       iLast = nColumn-1;
  3112   3118     }else{
  3113   3119       iFirst = iColumn;
  3114   3120       iLast = iColumn;
  3115   3121     }
................................................................................
  5829   5835     }else if( strcmp(zName,"offsets")==0 ){
  5830   5836       *pxFunc = snippetOffsetsFunc;
  5831   5837       return 1;
  5832   5838     }
  5833   5839     return 0;
  5834   5840   }
  5835   5841   
  5836         -static const sqlite3_module fulltextModule = {
         5842  +/*
         5843  +** Rename an fts2 table.
         5844  +*/
         5845  +static int fulltextRename(
         5846  +  sqlite3_vtab *pVtab,
         5847  +  const char *zName
         5848  +){
         5849  +  fulltext_vtab *p = (fulltext_vtab *)pVtab;
         5850  +  int rc = SQLITE_NOMEM;
         5851  +  char *zSql = sqlite3_mprintf(
         5852  +    "ALTER TABLE %Q.'%q_content'  RENAME TO '%q_content';"
         5853  +    "ALTER TABLE %Q.'%q_segments' RENAME TO '%q_segments';"
         5854  +    "ALTER TABLE %Q.'%q_segdir'   RENAME TO '%q_segdir';"
         5855  +    , p->zDb, p->zName, zName 
         5856  +    , p->zDb, p->zName, zName 
         5857  +    , p->zDb, p->zName, zName
         5858  +  );
         5859  +  if( zSql ){
         5860  +    rc = sqlite3_exec(p->db, zSql, 0, 0, 0);
         5861  +    sqlite3_free(zSql);
         5862  +  }
         5863  +  return rc;
         5864  +}
         5865  +
         5866  +static const sqlite3_module fts2Module = {
  5837   5867     /* iVersion      */ 0,
  5838   5868     /* xCreate       */ fulltextCreate,
  5839   5869     /* xConnect      */ fulltextConnect,
  5840   5870     /* xBestIndex    */ fulltextBestIndex,
  5841   5871     /* xDisconnect   */ fulltextDisconnect,
  5842   5872     /* xDestroy      */ fulltextDestroy,
  5843   5873     /* xOpen         */ fulltextOpen,
................................................................................
  5849   5879     /* xRowid        */ fulltextRowid,
  5850   5880     /* xUpdate       */ fulltextUpdate,
  5851   5881     /* xBegin        */ fulltextBegin,
  5852   5882     /* xSync         */ fulltextSync,
  5853   5883     /* xCommit       */ fulltextCommit,
  5854   5884     /* xRollback     */ fulltextRollback,
  5855   5885     /* xFindFunction */ fulltextFindFunction,
         5886  +  /* xRename */       fulltextRename,
  5856   5887   };
  5857   5888   
         5889  +static void hashDestroy(void *p){
         5890  +  fts2Hash *pHash = (fts2Hash *)p;
         5891  +  sqlite3Fts2HashClear(pHash);
         5892  +  sqlite3_free(pHash);
         5893  +}
         5894  +
         5895  +/*
         5896  +** The fts2 built-in tokenizers - "simple" and "porter" - are implemented
         5897  +** in files fts2_tokenizer1.c and fts2_porter.c respectively. The following
         5898  +** two forward declarations are for functions declared in these files
         5899  +** used to retrieve the respective implementations.
         5900  +**
         5901  +** Calling sqlite3Fts2SimpleTokenizerModule() sets the value pointed
         5902  +** to by the argument to point a the "simple" tokenizer implementation.
         5903  +** Function ...PorterTokenizerModule() sets *pModule to point to the
         5904  +** porter tokenizer/stemmer implementation.
         5905  +*/
         5906  +void sqlite3Fts2SimpleTokenizerModule(sqlite3_tokenizer_module const**ppModule);
         5907  +void sqlite3Fts2PorterTokenizerModule(sqlite3_tokenizer_module const**ppModule);
         5908  +void sqlite3Fts2IcuTokenizerModule(sqlite3_tokenizer_module const**ppModule);
         5909  +
         5910  +int sqlite3Fts2InitHashTable(sqlite3 *, fts2Hash *, const char *);
         5911  +
         5912  +/*
         5913  +** Initialise the fts2 extension. If this extension is built as part
         5914  +** of the sqlite library, then this function is called directly by
         5915  +** SQLite. If fts2 is built as a dynamically loadable extension, this
         5916  +** function is called by the sqlite3_extension_init() entry point.
         5917  +*/
  5858   5918   int sqlite3Fts2Init(sqlite3 *db){
  5859         -  sqlite3_overload_function(db, "snippet", -1);
  5860         -  sqlite3_overload_function(db, "offsets", -1);
  5861         -  return sqlite3_create_module(db, "fts2", &fulltextModule, 0);
         5919  +  int rc = SQLITE_OK;
         5920  +  fts2Hash *pHash = 0;
         5921  +  const sqlite3_tokenizer_module *pSimple = 0;
         5922  +  const sqlite3_tokenizer_module *pPorter = 0;
         5923  +  const sqlite3_tokenizer_module *pIcu = 0;
         5924  +
         5925  +  sqlite3Fts2SimpleTokenizerModule(&pSimple);
         5926  +  sqlite3Fts2PorterTokenizerModule(&pPorter);
         5927  +#ifdef SQLITE_ENABLE_ICU
         5928  +  sqlite3Fts2IcuTokenizerModule(&pIcu);
         5929  +#endif
         5930  +
         5931  +  /* Allocate and initialise the hash-table used to store tokenizers. */
         5932  +  pHash = sqlite3_malloc(sizeof(fts2Hash));
         5933  +  if( !pHash ){
         5934  +    rc = SQLITE_NOMEM;
         5935  +  }else{
         5936  +    sqlite3Fts2HashInit(pHash, FTS2_HASH_STRING, 1);
         5937  +  }
         5938  +
         5939  +  /* Load the built-in tokenizers into the hash table */
         5940  +  if( rc==SQLITE_OK ){
         5941  +    if( sqlite3Fts2HashInsert(pHash, "simple", 7, (void *)pSimple)
         5942  +     || sqlite3Fts2HashInsert(pHash, "porter", 7, (void *)pPorter) 
         5943  +     || (pIcu && sqlite3Fts2HashInsert(pHash, "icu", 4, (void *)pIcu))
         5944  +    ){
         5945  +      rc = SQLITE_NOMEM;
         5946  +    }
         5947  +  }
         5948  +
         5949  +  /* Create the virtual table wrapper around the hash-table and overload 
         5950  +  ** the two scalar functions. If this is successful, register the
         5951  +  ** module with sqlite.
         5952  +  */
         5953  +  if( SQLITE_OK==rc 
         5954  +   && SQLITE_OK==(rc = sqlite3Fts2InitHashTable(db, pHash, "fts2_tokenizer"))
         5955  +   && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
         5956  +   && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", -1))
         5957  +  ){
         5958  +    return sqlite3_create_module_v2(
         5959  +        db, "fts2", &fts2Module, (void *)pHash, hashDestroy
         5960  +    );
         5961  +  }
         5962  +
         5963  +  /* An error has occured. Delete the hash table and return the error code. */
         5964  +  assert( rc!=SQLITE_OK );
         5965  +  if( pHash ){
         5966  +    sqlite3Fts2HashClear(pHash);
         5967  +    sqlite3_free(pHash);
         5968  +  }
         5969  +  return rc;
  5862   5970   }
  5863   5971   
  5864   5972   #if !SQLITE_CORE
  5865         -int sqlite3_extension_init(sqlite3 *db, char **pzErrMsg,
  5866         -                           const sqlite3_api_routines *pApi){
         5973  +int sqlite3_extension_init(
         5974  +  sqlite3 *db, 
         5975  +  char **pzErrMsg,
         5976  +  const sqlite3_api_routines *pApi
         5977  +){
  5867   5978     SQLITE_EXTENSION_INIT2(pApi)
  5868   5979     return sqlite3Fts2Init(db);
  5869   5980   }
  5870   5981   #endif
  5871   5982   
  5872   5983   #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS2) */

Changes to SQLite.Interop/FTS2/fts2.h.

     1      1   /*
            2  +** 2006 Oct 10
            3  +**
            4  +** The author disclaims copyright to this source code.  In place of
            5  +** a legal notice, here is a blessing:
            6  +**
            7  +**    May you do good and not evil.
            8  +**    May you find forgiveness for yourself and forgive others.
            9  +**    May you share freely, never taking more than you give.
           10  +**
           11  +******************************************************************************
           12  +**
     2     13   ** This header file is used by programs that want to link against the
     3     14   ** FTS2 library.  All it does is declare the sqlite3Fts2Init() interface.
     4     15   */
     5     16   #include "sqlite3.h"
     6     17   
     7     18   #ifdef __cplusplus
     8     19   extern "C" {

Changes to SQLite.Interop/FTS2/fts2_hash.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This is the implementation of generic hash-tables used in SQLite.
    13     13   ** We've modified it slightly to serve as a standalone hash table
    14     14   ** implementation for the full-text indexing module.
    15     15   */
    16         -#include <assert.h>
    17         -#include <stdlib.h>
    18         -#include <string.h>
    19     16   
    20     17   /*
    21     18   ** The code in this file is only compiled if:
    22     19   **
    23     20   **     * The FTS2 module is being built as an extension
    24     21   **       (in which case SQLITE_CORE is not defined), or
    25     22   **
    26     23   **     * The FTS2 module is being built into the core of
    27     24   **       SQLite (in which case SQLITE_ENABLE_FTS2 is defined).
    28     25   */
    29     26   #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS2)
    30     27   
           28  +#include <assert.h>
           29  +#include <stdlib.h>
           30  +#include <string.h>
    31     31   
    32     32   #include "fts2_hash.h"
    33     33   
    34     34   static void *malloc_and_zero(int n){
    35     35     void *p = malloc(n);
    36     36     if( p ){
    37     37       memset(p, 0, n);

Added SQLite.Interop/FTS2/fts2_tokenizer.c.

            1  +/*
            2  +** 2007 June 22
            3  +**
            4  +** The author disclaims copyright to this source code.  In place of
            5  +** a legal notice, here is a blessing:
            6  +**
            7  +**    May you do good and not evil.
            8  +**    May you find forgiveness for yourself and forgive others.
            9  +**    May you share freely, never taking more than you give.
           10  +**
           11  +******************************************************************************
           12  +**
           13  +** This is part of an SQLite module implementing full-text search.
           14  +** This particular file implements the generic tokenizer interface.
           15  +*/
           16  +
           17  +/*
           18  +** The code in this file is only compiled if:
           19  +**
           20  +**     * The FTS2 module is being built as an extension
           21  +**       (in which case SQLITE_CORE is not defined), or
           22  +**
           23  +**     * The FTS2 module is being built into the core of
           24  +**       SQLite (in which case SQLITE_ENABLE_FTS2 is defined).
           25  +*/
           26  +#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS2)
           27  +
           28  +
           29  +#include "sqlite3.h"
           30  +#include "sqlite3ext.h"
           31  +SQLITE_EXTENSION_INIT1
           32  +
           33  +#include "fts2_hash.h"
           34  +#include "fts2_tokenizer.h"
           35  +#include <assert.h>
           36  +
           37  +/*
           38  +** Implementation of the SQL scalar function for accessing the underlying 
           39  +** hash table. This function may be called as follows:
           40  +**
           41  +**   SELECT <function-name>(<key-name>);
           42  +**   SELECT <function-name>(<key-name>, <pointer>);
           43  +**
           44  +** where <function-name> is the name passed as the second argument
           45  +** to the sqlite3Fts2InitHashTable() function (e.g. 'fts2_tokenizer').
           46  +**
           47  +** If the <pointer> argument is specified, it must be a blob value
           48  +** containing a pointer to be stored as the hash data corresponding
           49  +** to the string <key-name>. If <pointer> is not specified, then
           50  +** the string <key-name> must already exist in the has table. Otherwise,
           51  +** an error is returned.
           52  +**
           53  +** Whether or not the <pointer> argument is specified, the value returned
           54  +** is a blob containing the pointer stored as the hash data corresponding
           55  +** to string <key-name> (after the hash-table is updated, if applicable).
           56  +*/
           57  +static void scalarFunc(
           58  +  sqlite3_context *context,
           59  +  int argc,
           60  +  sqlite3_value **argv
           61  +){
           62  +  fts2Hash *pHash;
           63  +  void *pPtr = 0;
           64  +  const unsigned char *zName;
           65  +  int nName;
           66  +
           67  +  assert( argc==1 || argc==2 );
           68  +
           69  +  pHash = (fts2Hash *)sqlite3_user_data(context);
           70  +
           71  +  zName = sqlite3_value_text(argv[0]);
           72  +  nName = sqlite3_value_bytes(argv[0])+1;
           73  +
           74  +  if( argc==2 ){
           75  +    void *pOld;
           76  +    int n = sqlite3_value_bytes(argv[1]);
           77  +    if( n!=sizeof(pPtr) ){
           78  +      sqlite3_result_error(context, "argument type mismatch", -1);
           79  +      return;
           80  +    }
           81  +    pPtr = *(void **)sqlite3_value_blob(argv[1]);
           82  +    pOld = sqlite3Fts2HashInsert(pHash, (void *)zName, nName, pPtr);
           83  +    if( pOld==pPtr ){
           84  +      sqlite3_result_error(context, "out of memory", -1);
           85  +      return;
           86  +    }
           87  +  }else{
           88  +    pPtr = sqlite3Fts2HashFind(pHash, zName, nName);
           89  +    if( !pPtr ){
           90  +      char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
           91  +      sqlite3_result_error(context, zErr, -1);
           92  +      sqlite3_free(zErr);
           93  +      return;
           94  +    }
           95  +  }
           96  +
           97  +  sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT);
           98  +}
           99  +
          100  +#ifdef SQLITE_TEST
          101  +
          102  +#include <tcl.h>
          103  +#include <string.h>
          104  +
          105  +/*
          106  +** Implementation of a special SQL scalar function for testing tokenizers 
          107  +** designed to be used in concert with the Tcl testing framework. This
          108  +** function must be called with two arguments:
          109  +**
          110  +**   SELECT <function-name>(<key-name>, <input-string>);
          111  +**   SELECT <function-name>(<key-name>, <pointer>);
          112  +**
          113  +** where <function-name> is the name passed as the second argument
          114  +** to the sqlite3Fts2InitHashTable() function (e.g. 'fts2_tokenizer')
          115  +** concatenated with the string '_test' (e.g. 'fts2_tokenizer_test').
          116  +**
          117  +** The return value is a string that may be interpreted as a Tcl
          118  +** list. For each token in the <input-string>, three elements are
          119  +** added to the returned list. The first is the token position, the 
          120  +** second is the token text (folded, stemmed, etc.) and the third is the
          121  +** substring of <input-string> associated with the token. For example, 
          122  +** using the built-in "simple" tokenizer:
          123  +**
          124  +**   SELECT fts_tokenizer_test('simple', 'I don't see how');
          125  +**
          126  +** will return the string:
          127  +**
          128  +**   "{0 i I 1 dont don't 2 see see 3 how how}"
          129  +**   
          130  +*/
          131  +static void testFunc(
          132  +  sqlite3_context *context,
          133  +  int argc,
          134  +  sqlite3_value **argv
          135  +){
          136  +  fts2Hash *pHash;
          137  +  sqlite3_tokenizer_module *p;
          138  +  sqlite3_tokenizer *pTokenizer = 0;
          139  +  sqlite3_tokenizer_cursor *pCsr = 0;
          140  +
          141  +  const char *zErr = 0;
          142  +
          143  +  const char *zName;
          144  +  int nName;
          145  +  const char *zInput;
          146  +  int nInput;
          147  +
          148  +  const char *zArg = 0;
          149  +
          150  +  const char *zToken;
          151  +  int nToken;
          152  +  int iStart;
          153  +  int iEnd;
          154  +  int iPos;
          155  +
          156  +  Tcl_Obj *pRet;
          157  +
          158  +  assert( argc==2 || argc==3 );
          159  +
          160  +  nName = sqlite3_value_bytes(argv[0]);
          161  +  zName = (const char *)sqlite3_value_text(argv[0]);
          162  +  nInput = sqlite3_value_bytes(argv[argc-1]);
          163  +  zInput = (const char *)sqlite3_value_text(argv[argc-1]);
          164  +
          165  +  if( argc==3 ){
          166  +    zArg = (const char *)sqlite3_value_text(argv[1]);
          167  +  }
          168  +
          169  +  pHash = (fts2Hash *)sqlite3_user_data(context);
          170  +  p = (sqlite3_tokenizer_module *)sqlite3Fts2HashFind(pHash, zName, nName+1);
          171  +
          172  +  if( !p ){
          173  +    char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
          174  +    sqlite3_result_error(context, zErr, -1);
          175  +    sqlite3_free(zErr);
          176  +    return;
          177  +  }
          178  +
          179  +  pRet = Tcl_NewObj();
          180  +  Tcl_IncrRefCount(pRet);
          181  +
          182  +  if( SQLITE_OK!=p->xCreate(zArg ? 1 : 0, &zArg, &pTokenizer) ){
          183  +    zErr = "error in xCreate()";
          184  +    goto finish;
          185  +  }
          186  +  pTokenizer->pModule = p;
          187  +  if( SQLITE_OK!=p->xOpen(pTokenizer, zInput, nInput, &pCsr) ){
          188  +    zErr = "error in xOpen()";
          189  +    goto finish;
          190  +  }
          191  +  pCsr->pTokenizer = pTokenizer;
          192  +
          193  +  while( SQLITE_OK==p->xNext(pCsr, &zToken, &nToken, &iStart, &iEnd, &iPos) ){
          194  +    Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(iPos));
          195  +    Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zToken, nToken));
          196  +    zToken = &zInput[iStart];
          197  +    nToken = iEnd-iStart;
          198  +    Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zToken, nToken));
          199  +  }
          200  +
          201  +  if( SQLITE_OK!=p->xClose(pCsr) ){
          202  +    zErr = "error in xClose()";
          203  +    goto finish;
          204  +  }
          205  +  if( SQLITE_OK!=p->xDestroy(pTokenizer) ){
          206  +    zErr = "error in xDestroy()";
          207  +    goto finish;
          208  +  }
          209  +
          210  +finish:
          211  +  if( zErr ){
          212  +    sqlite3_result_error(context, zErr, -1);
          213  +  }else{
          214  +    sqlite3_result_text(context, Tcl_GetString(pRet), -1, SQLITE_TRANSIENT);
          215  +  }
          216  +  Tcl_DecrRefCount(pRet);
          217  +}
          218  +
          219  +static
          220  +int registerTokenizer(
          221  +  sqlite3 *db, 
          222  +  char *zName, 
          223  +  const sqlite3_tokenizer_module *p
          224  +){
          225  +  int rc;
          226  +  sqlite3_stmt *pStmt;
          227  +  const char zSql[] = "SELECT fts2_tokenizer(?, ?)";
          228  +
          229  +  rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
          230  +  if( rc!=SQLITE_OK ){
          231  +    return rc;
          232  +  }
          233  +
          234  +  sqlite3_bind_text(pStmt, 1, zName, -1, SQLITE_STATIC);
          235  +  sqlite3_bind_blob(pStmt, 2, &p, sizeof(p), SQLITE_STATIC);
          236  +  sqlite3_step(pStmt);
          237  +
          238  +  return sqlite3_finalize(pStmt);
          239  +}
          240  +
          241  +static
          242  +int queryTokenizer(
          243  +  sqlite3 *db, 
          244  +  char *zName,  
          245  +  const sqlite3_tokenizer_module **pp
          246  +){
          247  +  int rc;
          248  +  sqlite3_stmt *pStmt;
          249  +  const char zSql[] = "SELECT fts2_tokenizer(?)";
          250  +
          251  +  *pp = 0;
          252  +  rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
          253  +  if( rc!=SQLITE_OK ){
          254  +    return rc;
          255  +  }
          256  +
          257  +  sqlite3_bind_text(pStmt, 1, zName, -1, SQLITE_STATIC);
          258  +  if( SQLITE_ROW==sqlite3_step(pStmt) ){
          259  +    if( sqlite3_column_type(pStmt, 0)==SQLITE_BLOB ){
          260  +      memcpy(pp, sqlite3_column_blob(pStmt, 0), sizeof(*pp));
          261  +    }
          262  +  }
          263  +
          264  +  return sqlite3_finalize(pStmt);
          265  +}
          266  +
          267  +void sqlite3Fts2SimpleTokenizerModule(sqlite3_tokenizer_module const**ppModule);
          268  +
          269  +/*
          270  +** Implementation of the scalar function fts2_tokenizer_internal_test().
          271  +** This function is used for testing only, it is not included in the
          272  +** build unless SQLITE_TEST is defined.
          273  +**
          274  +** The purpose of this is to test that the fts2_tokenizer() function
          275  +** can be used as designed by the C-code in the queryTokenizer and
          276  +** registerTokenizer() functions above. These two functions are repeated
          277  +** in the README.tokenizer file as an example, so it is important to
          278  +** test them.
          279  +**
          280  +** To run the tests, evaluate the fts2_tokenizer_internal_test() scalar
          281  +** function with no arguments. An assert() will fail if a problem is
          282  +** detected. i.e.:
          283  +**
          284  +**     SELECT fts2_tokenizer_internal_test();
          285  +**
          286  +*/
          287  +static void intTestFunc(
          288  +  sqlite3_context *context,
          289  +  int argc,
          290  +  sqlite3_value **argv
          291  +){
          292  +  int rc;
          293  +  const sqlite3_tokenizer_module *p1;
          294  +  const sqlite3_tokenizer_module *p2;
          295  +  sqlite3 *db = (sqlite3 *)sqlite3_user_data(context);
          296  +
          297  +  /* Test the query function */
          298  +  sqlite3Fts2SimpleTokenizerModule(&p1);
          299  +  rc = queryTokenizer(db, "simple", &p2);
          300  +  assert( rc==SQLITE_OK );
          301  +  assert( p1==p2 );
          302  +  rc = queryTokenizer(db, "nosuchtokenizer", &p2);
          303  +  assert( rc==SQLITE_ERROR );
          304  +  assert( p2==0 );
          305  +  assert( 0==strcmp(sqlite3_errmsg(db), "unknown tokenizer: nosuchtokenizer") );
          306  +
          307  +  /* Test the storage function */
          308  +  rc = registerTokenizer(db, "nosuchtokenizer", p1);
          309  +  assert( rc==SQLITE_OK );
          310  +  rc = queryTokenizer(db, "nosuchtokenizer", &p2);
          311  +  assert( rc==SQLITE_OK );
          312  +  assert( p2==p1 );
          313  +
          314  +  sqlite3_result_text(context, "ok", -1, SQLITE_STATIC);
          315  +}
          316  +
          317  +#endif
          318  +
          319  +/*
          320  +** Set up SQL objects in database db used to access the contents of
          321  +** the hash table pointed to by argument pHash. The hash table must
          322  +** been initialised to use string keys, and to take a private copy 
          323  +** of the key when a value is inserted. i.e. by a call similar to:
          324  +**
          325  +**    sqlite3Fts2HashInit(pHash, FTS2_HASH_STRING, 1);
          326  +**
          327  +** This function adds a scalar function (see header comment above
          328  +** scalarFunc() in this file for details) and, if ENABLE_TABLE is
          329  +** defined at compilation time, a temporary virtual table (see header 
          330  +** comment above struct HashTableVtab) to the database schema. Both 
          331  +** provide read/write access to the contents of *pHash.
          332  +**
          333  +** The third argument to this function, zName, is used as the name
          334  +** of both the scalar and, if created, the virtual table.
          335  +*/
          336  +int sqlite3Fts2InitHashTable(
          337  +  sqlite3 *db, 
          338  +  fts2Hash *pHash, 
          339  +  const char *zName
          340  +){
          341  +  int rc = SQLITE_OK;
          342  +  void *p = (void *)pHash;
          343  +  const int any = SQLITE_ANY;
          344  +  char *zTest = 0;
          345  +  char *zTest2 = 0;
          346  +
          347  +#ifdef SQLITE_TEST
          348  +  void *pdb = (void *)db;
          349  +  zTest = sqlite3_mprintf("%s_test", zName);
          350  +  zTest2 = sqlite3_mprintf("%s_internal_test", zName);
          351  +  if( !zTest || !zTest2 ){
          352  +    rc = SQLITE_NOMEM;
          353  +  }
          354  +#endif
          355  +
          356  +  if( rc!=SQLITE_OK
          357  +   || (rc = sqlite3_create_function(db, zName, 1, any, p, scalarFunc, 0, 0))
          358  +   || (rc = sqlite3_create_function(db, zName, 2, any, p, scalarFunc, 0, 0))
          359  +#ifdef SQLITE_TEST
          360  +   || (rc = sqlite3_create_function(db, zTest, 2, any, p, testFunc, 0, 0))
          361  +   || (rc = sqlite3_create_function(db, zTest, 3, any, p, testFunc, 0, 0))
          362  +   || (rc = sqlite3_create_function(db, zTest2, 0, any, pdb, intTestFunc, 0, 0))
          363  +#endif
          364  +  );
          365  +
          366  +  sqlite3_free(zTest);
          367  +  sqlite3_free(zTest2);
          368  +  return rc;
          369  +}
          370  +
          371  +#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS2) */

Changes to SQLite.Interop/FTS2/fts2_tokenizer.h.

    23     23   /* TODO(shess) Only used for SQLITE_OK and SQLITE_DONE at this time.
    24     24   ** If tokenizers are to be allowed to call sqlite3_*() functions, then
    25     25   ** we will need a way to register the API consistently.
    26     26   */
    27     27   #include "sqlite3.h"
    28     28   
    29     29   /*
    30         -** Structures used by the tokenizer interface.
           30  +** Structures used by the tokenizer interface. When a new tokenizer
           31  +** implementation is registered, the caller provides a pointer to
           32  +** an sqlite3_tokenizer_module containing pointers to the callback
           33  +** functions that make up an implementation.
           34  +**
           35  +** When an fts2 table is created, it passes any arguments passed to
           36  +** the tokenizer clause of the CREATE VIRTUAL TABLE statement to the
           37  +** sqlite3_tokenizer_module.xCreate() function of the requested tokenizer
           38  +** implementation. The xCreate() function in turn returns an 
           39  +** sqlite3_tokenizer structure representing the specific tokenizer to
           40  +** be used for the fts2 table (customized by the tokenizer clause arguments).
           41  +**
           42  +** To tokenize an input buffer, the sqlite3_tokenizer_module.xOpen()
           43  +** method is called. It returns an sqlite3_tokenizer_cursor object
           44  +** that may be used to tokenize a specific input buffer based on
           45  +** the tokenization rules supplied by a specific sqlite3_tokenizer
           46  +** object.
    31     47   */
           48  +typedef struct sqlite3_tokenizer_module sqlite3_tokenizer_module;
    32     49   typedef struct sqlite3_tokenizer sqlite3_tokenizer;
    33     50   typedef struct sqlite3_tokenizer_cursor sqlite3_tokenizer_cursor;
    34         -typedef struct sqlite3_tokenizer_module sqlite3_tokenizer_module;
    35     51   
    36     52   struct sqlite3_tokenizer_module {
    37         -  int iVersion;                  /* currently 0 */
           53  +
           54  +  /*
           55  +  ** Structure version. Should always be set to 0.
           56  +  */
           57  +  int iVersion;
           58  +
           59  +  /*
           60  +  ** Create a new tokenizer. The values in the argv[] array are the
           61  +  ** arguments passed to the "tokenizer" clause of the CREATE VIRTUAL
           62  +  ** TABLE statement that created the fts2 table. For example, if
           63  +  ** the following SQL is executed:
           64  +  **
           65  +  **   CREATE .. USING fts2( ... , tokenizer <tokenizer-name> arg1 arg2)
           66  +  **
           67  +  ** then argc is set to 2, and the argv[] array contains pointers
           68  +  ** to the strings "arg1" and "arg2".
           69  +  **
           70  +  ** This method should return either SQLITE_OK (0), or an SQLite error 
           71  +  ** code. If SQLITE_OK is returned, then *ppTokenizer should be set
           72  +  ** to point at the newly created tokenizer structure. The generic
           73  +  ** sqlite3_tokenizer.pModule variable should not be initialised by
           74  +  ** this callback. The caller will do so.
           75  +  */
           76  +  int (*xCreate)(
           77  +    int argc,                           /* Size of argv array */
           78  +    const char *const*argv,             /* Tokenizer argument strings */
           79  +    sqlite3_tokenizer **ppTokenizer     /* OUT: Created tokenizer */
           80  +  );
    38     81   
    39     82     /*
    40         -  ** Create and destroy a tokenizer.  argc/argv are passed down from
    41         -  ** the fulltext virtual table creation to allow customization.
           83  +  ** Destroy an existing tokenizer. The fts2 module calls this method
           84  +  ** exactly once for each successful call to xCreate().
    42     85     */
    43         -  int (*xCreate)(int argc, const char *const*argv,
    44         -                 sqlite3_tokenizer **ppTokenizer);
    45     86     int (*xDestroy)(sqlite3_tokenizer *pTokenizer);
    46     87   
    47     88     /*
    48         -  ** Tokenize a particular input.  Call xOpen() to prepare to
    49         -  ** tokenize, xNext() repeatedly until it returns SQLITE_DONE, then
    50         -  ** xClose() to free any internal state.  The pInput passed to
    51         -  ** xOpen() must exist until the cursor is closed.  The ppToken
    52         -  ** result from xNext() is only valid until the next call to xNext()
    53         -  ** or until xClose() is called.
           89  +  ** Create a tokenizer cursor to tokenize an input buffer. The caller
           90  +  ** is responsible for ensuring that the input buffer remains valid
           91  +  ** until the cursor is closed (using the xClose() method). 
           92  +  */
           93  +  int (*xOpen)(
           94  +    sqlite3_tokenizer *pTokenizer,       /* Tokenizer object */
           95  +    const char *pInput, int nBytes,      /* Input buffer */
           96  +    sqlite3_tokenizer_cursor **ppCursor  /* OUT: Created tokenizer cursor */
           97  +  );
           98  +
           99  +  /*
          100  +  ** Destroy an existing tokenizer cursor. The fts2 module calls this 
          101  +  ** method exactly once for each successful call to xOpen().
          102  +  */
          103  +  int (*xClose)(sqlite3_tokenizer_cursor *pCursor);
          104  +
          105  +  /*
          106  +  ** Retrieve the next token from the tokenizer cursor pCursor. This
          107  +  ** method should either return SQLITE_OK and set the values of the
          108  +  ** "OUT" variables identified below, or SQLITE_DONE to indicate that
          109  +  ** the end of the buffer has been reached, or an SQLite error code.
          110  +  **
          111  +  ** *ppToken should be set to point at a buffer containing the 
          112  +  ** normalized version of the token (i.e. after any case-folding and/or
          113  +  ** stemming has been performed). *pnBytes should be set to the length
          114  +  ** of this buffer in bytes. The input text that generated the token is
          115  +  ** identified by the byte offsets returned in *piStartOffset and
          116  +  ** *piEndOffset.
          117  +  **
          118  +  ** The buffer *ppToken is set to point at is managed by the tokenizer
          119  +  ** implementation. It is only required to be valid until the next call
          120  +  ** to xNext() or xClose(). 
    54    121     */
    55    122     /* TODO(shess) current implementation requires pInput to be
    56    123     ** nul-terminated.  This should either be fixed, or pInput/nBytes
    57    124     ** should be converted to zInput.
    58    125     */
    59         -  int (*xOpen)(sqlite3_tokenizer *pTokenizer,
    60         -               const char *pInput, int nBytes,
    61         -               sqlite3_tokenizer_cursor **ppCursor);
    62         -  int (*xClose)(sqlite3_tokenizer_cursor *pCursor);
    63         -  int (*xNext)(sqlite3_tokenizer_cursor *pCursor,
    64         -               const char **ppToken, int *pnBytes,
    65         -               int *piStartOffset, int *piEndOffset, int *piPosition);
          126  +  int (*xNext)(
          127  +    sqlite3_tokenizer_cursor *pCursor,   /* Tokenizer cursor */
          128  +    const char **ppToken, int *pnBytes,  /* OUT: Normalized text for token */
          129  +    int *piStartOffset,  /* OUT: Byte offset of token in input buffer */
          130  +    int *piEndOffset,    /* OUT: Byte offset of end of token in input buffer */
          131  +    int *piPosition      /* OUT: Number of tokens returned before this one */
          132  +  );
    66    133   };
    67    134   
    68    135   struct sqlite3_tokenizer {
    69    136     const sqlite3_tokenizer_module *pModule;  /* The module for this tokenizer */
    70    137     /* Tokenizer implementations will typically add additional fields */
    71    138   };
    72    139   
    73    140   struct sqlite3_tokenizer_cursor {
    74    141     sqlite3_tokenizer *pTokenizer;       /* Tokenizer for this cursor. */
    75    142     /* Tokenizer implementations will typically add additional fields */
    76    143   };
    77    144   
    78         -/*
    79         -** Get the module for a tokenizer which generates tokens based on a
    80         -** set of non-token characters.  The default is to break tokens at any
    81         -** non-alnum character, though the set of delimiters can also be
    82         -** specified by the first argv argument to xCreate().
    83         -*/
    84         -/* TODO(shess) This doesn't belong here.  Need some sort of
    85         -** registration process.
    86         -*/
    87         -void sqlite3Fts2SimpleTokenizerModule(sqlite3_tokenizer_module const**ppModule);
    88         -void sqlite3Fts2PorterTokenizerModule(sqlite3_tokenizer_module const**ppModule);
    89         -
    90    145   #endif /* _FTS2_TOKENIZER_H_ */

Changes to SQLite.Interop/FTS2/fts2_tokenizer1.c.

     1      1   /*
     2         -** The author disclaims copyright to this source code.
            2  +** 2006 Oct 10
            3  +**
            4  +** The author disclaims copyright to this source code.  In place of
            5  +** a legal notice, here is a blessing:
            6  +**
            7  +**    May you do good and not evil.
            8  +**    May you find forgiveness for yourself and forgive others.
            9  +**    May you share freely, never taking more than you give.
     3     10   **
     4         -*************************************************************************
           11  +******************************************************************************
           12  +**
     5     13   ** Implementation of the "simple" full-text-search tokenizer.
     6     14   */
     7     15   
     8     16   /*
     9     17   ** The code in this file is only compiled if:
    10     18   **
    11     19   **     * The FTS2 module is being built as an extension

Changes to SQLite.Interop/SQLite.Interop.rc.

    49     49   
    50     50   /////////////////////////////////////////////////////////////////////////////
    51     51   //
    52     52   // Version
    53     53   //
    54     54   
    55     55   VS_VERSION_INFO VERSIONINFO
    56         - FILEVERSION 1,0,42,0
           56  + FILEVERSION 1,0,44,0
    57     57    PRODUCTVERSION 1,0,0,0
    58     58    FILEFLAGSMASK 0x17L
    59     59   #ifdef _DEBUG
    60     60    FILEFLAGS 0x1L
    61     61   #else
    62     62    FILEFLAGS 0x0L
    63     63   #endif
................................................................................
    67     67   BEGIN
    68     68       BLOCK "StringFileInfo"
    69     69       BEGIN
    70     70           BLOCK "040904b0"
    71     71           BEGIN
    72     72               VALUE "Comments", "http://sqlite.phxsoftware.com"
    73     73               VALUE "FileDescription", "System.Data.SQLite Interop Library"
    74         -            VALUE "FileVersion", "1.0.42.0"
           74  +            VALUE "FileVersion", "1.0.44.0"
    75     75               VALUE "InternalName", "SQLite.Interop.DLL"
    76     76               VALUE "LegalCopyright", "Released to the public domain"
    77         -            VALUE "OriginalFilename", "SQLite3.DLL 3.3.17"
           77  +            VALUE "OriginalFilename", "SQLite3.DLL 3.4.1"
    78     78               VALUE "ProductName", "System.Data.SQLite"
    79     79               VALUE "ProductVersion", "1.0"
    80     80           END
    81     81       END
    82     82       BLOCK "VarFileInfo"
    83     83       BEGIN
    84     84           VALUE "Translation", 0x409, 1200

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

    68     68   				Name="VCResourceCompilerTool"
    69     69   			/>
    70     70   			<Tool
    71     71   				Name="VCPreLinkEventTool"
    72     72   			/>
    73     73   			<Tool
    74     74   				Name="VCLinkerTool"
    75         -				AdditionalDependencies="advapi32.lib fts1/$(ConfigurationName)/SQLite.Interop.FTS1.lib fts2/$(ConfigurationName)/SQLite.Interop.FTS2.lib $(NOINHERIT)"
           75  +				AdditionalDependencies="advapi32.lib &quot;fts1/$(ConfigurationName)/SQLite.Interop.FTS1.lib&quot; &quot;fts2/$(ConfigurationName)/SQLite.Interop.FTS2.lib&quot; $(NOINHERIT)"
    76     76   				OutputFile="../bin/System.Data.SQLite.DLL"
    77     77   				GenerateManifest="false"
    78     78   				IgnoreDefaultLibraryNames=""
    79     79   				ModuleDefinitionFile="src\sqlite3.def"
    80     80   				EmbedManagedResourceFile=""
    81     81   				DelayLoadDLLs="advapi32.dll"
    82     82   				OptimizeForWindows98="1"
................................................................................
   135    135   			/>
   136    136   			<Tool
   137    137   				Name="VCMIDLTool"
   138    138   			/>
   139    139   			<Tool
   140    140   				Name="VCCLCompilerTool"
   141    141   				ExecutionBucket="7"
   142         -				InlineFunctionExpansion="1"
   143         -				PreprocessorDefinitions="_WIN32_WCE=$(CEVER);UNDER_CE=$(CEVER);WINCE;$(PLATFORMDEFINES);NDEBUG;_WINDOWS;_USRDLL;CPPSMART_EXPORTS;$(ARCHFAM);$(_ARCHFAM_);UNICODE;_UNICODE;SQLITE_HAS_CODEC;SQLITE_ENABLE_COLUMN_METADATA;SQLITE_ENABLE_FTS1;SQLITE_ENABLE_FTS2;SQLITE_OMIT_TRACE"
          142  +				Optimization="1"
          143  +				PreprocessorDefinitions="_WIN32_WCE=$(CEVER);UNDER_CE=$(CEVER);WINCE;$(PLATFORMDEFINES);NDEBUG;_WINDOWS;_USRDLL;CPPSMART_EXPORTS;$(ARCHFAM);$(_ARCHFAM_);UNICODE;_UNICODE;SQLITE_HAS_CODEC;SQLITE_ENABLE_COLUMN_METADATA;SQLITE_ENABLE_FTS2;SQLITE_OMIT_TRACE"
   144    144   				StringPooling="true"
   145    145   				ExceptionHandling="0"
   146    146   				BufferSecurityCheck="false"
   147    147   				EnableFunctionLevelLinking="true"
   148    148   			/>
   149    149   			<Tool
   150    150   				Name="VCManagedResourceCompilerTool"
................................................................................
   157    157   			/>
   158    158   			<Tool
   159    159   				Name="VCPreLinkEventTool"
   160    160   			/>
   161    161   			<Tool
   162    162   				Name="VCLinkerTool"
   163    163   				IgnoreImportLibrary="true"
   164         -				AdditionalDependencies="fts1/$(ConfigurationName)/SQLite.Interop.FTS1.lib fts2/$(ConfigurationName)/SQLite.Interop.FTS2.lib"
          164  +				AdditionalDependencies="&quot;fts2/$(PlatformName)/$(ConfigurationName)/SQLite.Interop.FTS2.lib&quot;"
   165    165   				OutputFile="../bin/CompactFramework/System.Data.SQLite.DLL"
   166    166   				AdditionalLibraryDirectories=""
   167    167   				IgnoreDefaultLibraryNames=""
   168    168   				ModuleDefinitionFile="src\sqlite3.def"
   169    169   				AddModuleNamesToAssembly=""
   170    170   				EmbedManagedResourceFile=""
   171    171   				SubSystem="9"
................................................................................
   243    243   				Name="VCResourceCompilerTool"
   244    244   			/>
   245    245   			<Tool
   246    246   				Name="VCPreLinkEventTool"
   247    247   			/>
   248    248   			<Tool
   249    249   				Name="VCLinkerTool"
   250         -				AdditionalDependencies="advapi32.lib fts1/$(ConfigurationName)/SQLite.Interop.FTS1.lib fts2/$(ConfigurationName)/SQLite.Interop.FTS2.lib $(NOINHERIT)"
          250  +				AdditionalDependencies="advapi32.lib &quot;fts1/$(PlatformName)/$(ConfigurationName)/SQLite.Interop.FTS1.lib&quot; &quot;fts2/$(PlatformName)/$(ConfigurationName)/SQLite.Interop.FTS2.lib&quot; $(NOINHERIT)"
   251    251   				OutputFile="../bin/Itanium/System.Data.SQLite.DLL"
   252    252   				ModuleDefinitionFile="src\sqlite3.def"
   253    253   				EmbedManagedResourceFile=""
   254    254   				DelayLoadDLLs="advapi32.dll"
   255    255   				OptimizeForWindows98="1"
   256    256   				ImportLibrary=""
   257    257   				TargetMachine="5"
................................................................................
   330    330   				Name="VCResourceCompilerTool"
   331    331   			/>
   332    332   			<Tool
   333    333   				Name="VCPreLinkEventTool"
   334    334   			/>
   335    335   			<Tool
   336    336   				Name="VCLinkerTool"
   337         -				AdditionalDependencies="advapi32.lib fts1/$(ConfigurationName)/SQLite.Interop.FTS1.lib fts2/$(ConfigurationName)/SQLite.Interop.FTS2.lib $(NOINHERIT)"
          337  +				AdditionalDependencies="advapi32.lib &quot;fts1/$(PlatformName)/$(ConfigurationName)/SQLite.Interop.FTS1.lib&quot; &quot;fts2/$(PlatformName)/$(ConfigurationName)/SQLite.Interop.FTS2.lib&quot; $(NOINHERIT)"
   338    338   				OutputFile="../bin/x64/System.Data.SQLite.DLL"
   339    339   				ModuleDefinitionFile="src\sqlite3.def"
   340    340   				EmbedManagedResourceFile=""
   341    341   				DelayLoadDLLs="advapi32.dll"
   342    342   				OptimizeForWindows98="1"
   343    343   				ImportLibrary=""
   344    344   				TargetMachine="17"
................................................................................
   397    397   			<Tool
   398    398   				Name="VCMIDLTool"
   399    399   			/>
   400    400   			<Tool
   401    401   				Name="VCCLCompilerTool"
   402    402   				AdditionalOptions="/GS-"
   403    403   				Optimization="0"
   404         -				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;NO_TCL;THREADSAFE=1;SQLITE_HAS_CODEC;SQLITE_ENABLE_COLUMN_METADATA;SQLITE_ENABLE_FTS1;SQLITE_ENABLE_FTS2;SQLITE_OMIT_TRACE"
          404  +				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;NO_TCL;THREADSAFE=1;SQLITE_HAS_CODEC;SQLITE_ENABLE_COLUMN_METADATA;SQLITE_ENABLE_FTS2;SQLITE_OMIT_TRACE"
   405    405   				RuntimeLibrary="3"
   406    406   				RuntimeTypeInfo="false"
   407    407   				DebugInformationFormat="3"
   408    408   			/>
   409    409   			<Tool
   410    410   				Name="VCManagedResourceCompilerTool"
   411    411   			/>
................................................................................
   413    413   				Name="VCResourceCompilerTool"
   414    414   			/>
   415    415   			<Tool
   416    416   				Name="VCPreLinkEventTool"
   417    417   			/>
   418    418   			<Tool
   419    419   				Name="VCLinkerTool"
   420         -				AdditionalDependencies="advapi32.lib fts1/$(ConfigurationName)/SQLite.Interop.FTS1.lib fts2/$(ConfigurationName)/SQLite.Interop.FTS2.lib $(NOINHERIT)"
          420  +				AdditionalDependencies="advapi32.lib &quot;fts1/$(ConfigurationName)/SQLite.Interop.FTS1.lib&quot; &quot;fts2/$(ConfigurationName)/SQLite.Interop.FTS2.lib&quot; $(NOINHERIT)"
   421    421   				OutputFile="../bin/$(InputName).DLL"
          422  +				LinkIncremental="1"
   422    423   				ModuleDefinitionFile="src\sqlite3.def"
   423    424   				EmbedManagedResourceFile=""
   424    425   				DelayLoadDLLs="advapi32.dll"
   425    426   				GenerateDebugInformation="true"
   426    427   				ImportLibrary=""
   427    428   				TargetMachine="1"
   428    429   				KeyFile="..\System.Data.SQLite\System.Data.SQLite.snk"
................................................................................
   499    500   			<Tool
   500    501   				Name="VCPreLinkEventTool"
   501    502   			/>
   502    503   			<Tool
   503    504   				Name="VCLinkerTool"
   504    505   				IgnoreImportLibrary="true"
   505    506   				AdditionalOptions=" /subsystem:windowsce,4.20 /machine:ARM /ARMPADCODE"
   506         -				AdditionalDependencies="fts1/$(ConfigurationName)/SQLite.Interop.FTS1.lib fts2/$(ConfigurationName)/SQLite.Interop.FTS2.lib"
          507  +				AdditionalDependencies="&quot;fts1/$(PlatformName)/$(ConfigurationName)/SQLite.Interop.FTS1.lib&quot; &quot;fts2/$(PlatformName)/$(ConfigurationName)/SQLite.Interop.FTS2.lib&quot;"
   507    508   				OutputFile="../bin/CompactFramework/$(InputName).DLL"
   508    509   				AdditionalLibraryDirectories=""
   509    510   				IgnoreDefaultLibraryNames=""
   510    511   				ModuleDefinitionFile="src\sqlite3.def"
   511    512   				AddModuleNamesToAssembly=""
   512    513   				EmbedManagedResourceFile=""
   513    514   				GenerateDebugInformation="true"
................................................................................
   580    581   				Name="VCResourceCompilerTool"
   581    582   			/>
   582    583   			<Tool
   583    584   				Name="VCPreLinkEventTool"
   584    585   			/>
   585    586   			<Tool
   586    587   				Name="VCLinkerTool"
   587         -				AdditionalDependencies="advapi32.lib fts1/$(ConfigurationName)/SQLite.Interop.FTS1.lib fts2/$(ConfigurationName)/SQLite.Interop.FTS2.lib $(NOINHERIT)"
          588  +				AdditionalDependencies="advapi32.lib &quot;fts1/$(PlatformName)/$(ConfigurationName)/SQLite.Interop.FTS1.lib&quot; &quot;fts2/$(PlatformName)/$(ConfigurationName)/SQLite.Interop.FTS2.lib&quot; $(NOINHERIT)"
   588    589   				OutputFile="../bin/Itanium/$(InputName).DLL"
   589    590   				ModuleDefinitionFile="src\sqlite3.def"
   590    591   				EmbedManagedResourceFile=""
   591    592   				DelayLoadDLLs="advapi32.dll"
   592    593   				GenerateDebugInformation="true"
   593    594   				ImportLibrary=""
   594    595   				TargetMachine="5"
................................................................................
   662    663   				Name="VCResourceCompilerTool"
   663    664   			/>
   664    665   			<Tool
   665    666   				Name="VCPreLinkEventTool"
   666    667   			/>
   667    668   			<Tool
   668    669   				Name="VCLinkerTool"
   669         -				AdditionalDependencies="advapi32.lib fts1/$(ConfigurationName)/SQLite.Interop.FTS1.lib fts2/$(ConfigurationName)/SQLite.Interop.FTS2.lib $(NOINHERIT)"
          670  +				AdditionalDependencies="advapi32.lib &quot;fts1/$(PlatformName)/$(ConfigurationName)/SQLite.Interop.FTS1.lib&quot; &quot;fts2/$(PlatformName)/$(ConfigurationName)/SQLite.Interop.FTS2.lib&quot; $(NOINHERIT)"
   670    671   				OutputFile="../bin/x64/$(InputName).DLL"
   671    672   				ModuleDefinitionFile="src\sqlite3.def"
   672    673   				EmbedManagedResourceFile=""
   673    674   				DelayLoadDLLs="advapi32.dll"
   674    675   				GenerateDebugInformation="true"
   675    676   				ImportLibrary=""
   676    677   				TargetMachine="17"

Changes to SQLite.Interop/merge.h.

     1      1   // This code was automatically generated from assembly
     2      2   // C:\Src\SQLite.NET\System.Data.SQLite\bin\CompactFramework\System.Data.SQLite.dll
     3      3   
     4      4   #include <windef.h>
     5      5   
     6      6   #pragma data_seg(".clr")
     7      7   #pragma comment(linker, "/SECTION:.clr,ER")
     8         -  char __ph[130956] = {0}; // The number of bytes to reserve
            8  +  char __ph[130872] = {0}; // The number of bytes to reserve
     9      9   #pragma data_seg()
    10     10   
    11     11   typedef BOOL (WINAPI *DLLMAIN)(HANDLE, DWORD, LPVOID);
    12     12   typedef struct EXTRA_STUFF
    13     13   {
    14     14     DWORD dwNativeEntryPoint;
    15     15   } EXTRA_STUFF, *LPEXTRA_STUFF;

Changes to SQLite.Interop/merge_full.h.

     1      1   // This code was automatically generated from assembly
     2      2   // C:\Src\SQLite.NET\System.Data.SQLite\bin\System.Data.SQLite.dll
     3      3   
     4      4   #include <windef.h>
     5      5   
     6      6   #pragma data_seg(".clr")
     7      7   #pragma comment(linker, "/SECTION:.clr,ER")
     8         -  char __ph[140144] = {0}; // The number of bytes to reserve
            8  +  char __ph[140088] = {0}; // The number of bytes to reserve
     9      9   #pragma data_seg()
    10     10   
    11     11   typedef BOOL (WINAPI *DLLMAIN)(HANDLE, DWORD, LPVOID);
    12     12   typedef struct EXTRA_STUFF
    13     13   {
    14     14     DWORD dwNativeEntryPoint;
    15     15   } EXTRA_STUFF, *LPEXTRA_STUFF;

Changes to SQLite.Interop/src/sqlite3.c.

     1      1   /******************************************************************************
     2      2   ** This file is an amalgamation of many separate C source files from SQLite
     3         -** version 3.4.0.  By combining all the individual C code files into this 
            3  +** version 3.4.1.  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% are 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
    11     11   ** programs, you need this file and the "sqlite3.h" header file that defines
    12     12   ** the programming interface to the SQLite library.  (If you do not have 
    13     13   ** the "sqlite3.h" header file at hand, you will find a copy in the first
    14         -** 2679 lines past this header comment.)  Additional code files may be
           14  +** 2702 lines past this header comment.)  Additional code files may be
    15     15   ** needed if you want a wrapper to interface SQLite with your choice of
    16     16   ** programming language.  The code for the "sqlite3" command-line shell
    17     17   ** is also in a separate file.  This file contains only code for the core
    18     18   ** SQLite library.
    19     19   **
    20         -** This amalgamation was generated on 2007-06-18 17:44:42 UTC.
           20  +** This amalgamation was generated on 2007-07-20 11:05:39 UTC.
    21     21   */
    22     22   #define SQLITE_AMALGAMATION 1
           23  +#ifndef SQLITE_PRIVATE
           24  +# define SQLITE_PRIVATE static
           25  +#endif
           26  +#ifndef SQLITE_API
           27  +# define SQLITE_API
           28  +#endif
    23     29   /************** Begin file sqlite3.h *****************************************/
    24     30   /*
    25     31   ** 2001 September 15
    26     32   **
    27     33   ** The author disclaims copyright to this source code.  In place of
    28     34   ** a legal notice, here is a blessing:
    29     35   **
................................................................................
    49     55   ** on how SQLite interfaces are suppose to operate.
    50     56   **
    51     57   ** The name of this file under configuration management is "sqlite.h.in".
    52     58   ** The makefile makes some minor changes to this file (such as inserting
    53     59   ** the version number) and changes its name to "sqlite3.h" as
    54     60   ** part of the build process.
    55     61   **
    56         -** @(#) $Id: sqlite3.c,v 1.3 2007/06/19 22:43:23 rmsimpson Exp $
           62  +** @(#) $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
    57     63   */
    58     64   #ifndef _SQLITE3_H_
    59     65   #define _SQLITE3_H_
    60     66   #include <stdarg.h>     /* Needed for the definition of va_list */
    61     67   
    62     68   /*
    63     69   ** Make sure we can call this stuff from C++.
................................................................................
   100    106   ** (X*1000000 + Y*1000 + Z). For example, for version "3.1.1beta", 
   101    107   ** SQLITE_VERSION_NUMBER is set to 3001001. To detect if they are using 
   102    108   ** version 3.1.1 or greater at compile time, programs may use the test 
   103    109   ** (SQLITE_VERSION_NUMBER>=3001001).
   104    110   **
   105    111   ** See also: [sqlite3_libversion()] and [sqlite3_libversion_number()].
   106    112   */
   107         -#define SQLITE_VERSION         "3.4.0"
   108         -#define SQLITE_VERSION_NUMBER 3004000
          113  +#define SQLITE_VERSION         "3.4.1"
          114  +#define SQLITE_VERSION_NUMBER 3004001
   109    115   
   110    116   /*
   111    117   ** CAPI3REF: Run-Time Library Version Numbers
   112    118   **
   113    119   ** These routines return values equivalent to the header constants
   114    120   ** [SQLITE_VERSION] and [SQLITE_VERSION_NUMBER].  The values returned
   115    121   ** by this routines should only be different from the header values
................................................................................
   120    126   ** The sqlite3_version[] string constant contains the text of the
   121    127   ** [SQLITE_VERSION] string.  The sqlite3_libversion() function returns
   122    128   ** a poiner to the sqlite3_version[] string constant.  The function
   123    129   ** is provided for DLL users who can only access functions and not
   124    130   ** constants within the DLL.
   125    131   */
   126    132   extern const char sqlite3_version[];
   127         -const char *sqlite3_libversion(void);
          133  +SQLITE_API const char *sqlite3_libversion(void);
   128    134   int sqlite3_libversion_number(void);
   129    135   
   130    136   /*
   131    137   ** CAPI3REF: Database Connection Handle
   132    138   **
   133    139   ** Each open SQLite database is represented by pointer to an instance of the
   134    140   ** opaque structure named "sqlite3".  It is useful to think of an sqlite3
................................................................................
   177    183   ** closed.
   178    184   **
   179    185   ** All SQL statements prepared using [sqlite3_prepare_v2()] or
   180    186   ** [sqlite3_prepare16_v2()] must be destroyed using [sqlite3_finalize()]
   181    187   ** before this routine is called. Otherwise, SQLITE_BUSY is returned and the
   182    188   ** database connection remains open.
   183    189   */
   184         -int sqlite3_close(sqlite3 *);
          190  +SQLITE_API int sqlite3_close(sqlite3 *);
   185    191   
   186    192   /*
   187    193   ** The type for a callback function.
   188    194   ** This is legacy and deprecated.  It is included for historical
   189    195   ** compatibility and is not documented.
   190    196   */
   191    197   typedef int (*sqlite3_callback)(void*,int,char**, char**);
................................................................................
   230    236   ** then no error message is ever written.
   231    237   **
   232    238   ** The return value is is SQLITE_OK if there are no errors and
   233    239   ** some other [SQLITE_OK | return code] if there is an error.  
   234    240   ** The particular return value depends on the type of error. 
   235    241   **
   236    242   */
   237         -int sqlite3_exec(
          243  +SQLITE_API int sqlite3_exec(
   238    244     sqlite3*,                                  /* An open database */
   239    245     const char *sql,                           /* SQL to be evaluted */
   240    246     int (*callback)(void*,int,char**,char**),  /* Callback function */
   241    247     void *,                                    /* 1st argument to callback */
   242    248     char **errmsg                              /* Error msg written here */
   243    249   );
   244    250   
................................................................................
   388    394   **
   389    395   ** If a callback invokes [sqlite3_exec()] or [sqlite3_step()] recursively,
   390    396   ** then the changes in the inner, recursive call are counted together
   391    397   ** with the changes in the outer call.
   392    398   **
   393    399   ** SQLite implements the command "DELETE FROM table" without a WHERE clause
   394    400   ** by dropping and recreating the table.  (This is much faster than going
   395         -** through and deleting individual elements form the table.)  Because of
          401  +** through and deleting individual elements from the table.)  Because of
   396    402   ** this optimization, the change count for "DELETE FROM table" will be
   397    403   ** zero regardless of the number of elements that were originally in the
   398    404   ** table. To get an accurate count of the number of rows deleted, use
   399    405   ** "DELETE FROM table WHERE 1" instead.
   400    406   */
   401         -int sqlite3_changes(sqlite3*);
          407  +SQLITE_API int sqlite3_changes(sqlite3*);
   402    408   
   403    409   /*
   404    410   ** CAPI3REF: Total Number Of Rows Modified
   405    411   ***
   406    412   ** This function returns the number of database rows that have been
   407    413   ** modified by INSERT, UPDATE or DELETE statements since the database handle
   408    414   ** was opened. This includes UPDATE, INSERT and DELETE statements executed
................................................................................
   435    441   ** thread that is currently running the database operation.
   436    442   **
   437    443   ** The SQL operation that is interrupted will return [SQLITE_INTERRUPT].
   438    444   ** If an interrupted operation was an update that is inside an
   439    445   ** explicit transaction, then the entire transaction will be rolled
   440    446   ** back automatically.
   441    447   */
   442         -void sqlite3_interrupt(sqlite3*);
          448  +SQLITE_API void sqlite3_interrupt(sqlite3*);
   443    449   
   444    450   /*
   445    451   ** CAPI3REF: Determine If An SQL Statement Is Complete
   446    452   **
   447    453   ** These functions return true if the given input string comprises
   448    454   ** one or more complete SQL statements. For the sqlite3_complete() call,
   449    455   ** the parameter must be a nul-terminated UTF-8 string. For
................................................................................
   455    461   ** if additional input is needed before sending the statements into
   456    462   ** SQLite for parsing. The algorithm is simple.  If the 
   457    463   ** last token other than spaces and comments is a semicolon, then return 
   458    464   ** true.  Actually, the algorithm is a little more complicated than that
   459    465   ** in order to deal with triggers, but the basic idea is the same:  the
   460    466   ** statement is not complete unless it ends in a semicolon.
   461    467   */
   462         -int sqlite3_complete(const char *sql);
   463         -int sqlite3_complete16(const void *sql);
          468  +SQLITE_API int sqlite3_complete(const char *sql);
          469  +SQLITE_API int sqlite3_complete16(const void *sql);
   464    470   
   465    471   /*
   466    472   ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
   467    473   **
   468    474   ** This routine identifies a callback function that might be invoked
   469    475   ** whenever an attempt is made to open a database table 
   470    476   ** that another thread or process has locked.
................................................................................
   689    695   **  sqlite3_exec(db, zSQL, 0, 0, 0);
   690    696   **  sqlite3_free(zSQL);
   691    697   ** </pre></blockquote>
   692    698   **
   693    699   ** The code above will render a correct SQL statement in the zSQL
   694    700   ** variable even if the zText variable is a NULL pointer.
   695    701   */
   696         -char *sqlite3_mprintf(const char*,...);
   697         -char *sqlite3_vmprintf(const char*, va_list);
   698         -char *sqlite3_snprintf(int,char*,const char*, ...);
          702  +SQLITE_API char *sqlite3_mprintf(const char*,...);
          703  +SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
          704  +SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
   699    705   
   700    706   /*
   701    707   ** CAPI3REF: Memory Allocation Functions
   702    708   **
   703    709   ** SQLite uses its own memory allocator.  On some installations, this
   704    710   ** memory allocator is identical to the standard malloc()/realloc()/free()
   705    711   ** and can be used interchangable.  On others, the implementations are
   706    712   ** different.  For maximum portability, it is best not to mix calls
   707    713   ** to the standard malloc/realloc/free with the sqlite versions.
   708    714   */
   709         -void *sqlite3_malloc(int);
   710         -void *sqlite3_realloc(void*, int);
   711         -void sqlite3_free(void*);
          715  +SQLITE_API void *sqlite3_malloc(int);
          716  +SQLITE_API void *sqlite3_realloc(void*, int);
          717  +SQLITE_API void sqlite3_free(void*);
   712    718   
   713    719   /*
   714    720   ** CAPI3REF: Compile-Time Authorization Callbacks
   715    721   ***
   716    722   ** This routine registers a authorizer callback with the SQLite library.  
   717    723   ** The authorizer callback is invoked as SQL statements are being compiled
   718    724   ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
................................................................................
   844    850   ** The callback function registered by sqlite3_profile() is invoked
   845    851   ** as each SQL statement finishes and includes
   846    852   ** information on how long that statement ran.
   847    853   **
   848    854   ** The sqlite3_profile() API is currently considered experimental and
   849    855   ** is subject to change.
   850    856   */
   851         -void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
   852         -void *sqlite3_profile(sqlite3*,
          857  +SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
          858  +SQLITE_API void *sqlite3_profile(sqlite3*,
   853    859      void(*xProfile)(void*,const char*,sqlite_uint64), void*);
   854    860   
   855    861   /*
   856    862   ** CAPI3REF: Query Progress Callbacks
   857    863   **
   858    864   ** This routine configures a callback function - the progress callback - that
   859    865   ** is invoked periodically during long running calls to [sqlite3_exec()],
................................................................................
   905    911   ** sqlite3_close() when it is no longer required.
   906    912   **
   907    913   ** Note to windows users:  The encoding used for the filename argument
   908    914   ** of sqlite3_open() must be UTF-8, not whatever codepage is currently
   909    915   ** defined.  Filenames containing international characters must be converted
   910    916   ** to UTF-8 prior to passing them into sqlite3_open().
   911    917   */
   912         -int sqlite3_open(
          918  +SQLITE_API int sqlite3_open(
   913    919     const char *filename,   /* Database filename (UTF-8) */
   914    920     sqlite3 **ppDb          /* OUT: SQLite db handle */
   915    921   );
   916         -int sqlite3_open16(
          922  +SQLITE_API int sqlite3_open16(
   917    923     const void *filename,   /* Database filename (UTF-16) */
   918    924     sqlite3 **ppDb          /* OUT: SQLite db handle */
   919    925   );
   920    926   
   921    927   /*
   922    928   ** CAPI3REF: Error Codes And Messages
   923    929   **
................................................................................
   942    948   ** an error code (examples: [sqlite3_data_count()] or [sqlite3_mprintf()]) do
   943    949   ** not change the error code returned by this routine.
   944    950   **
   945    951   ** Assuming no other intervening sqlite3_* API calls are made, the error
   946    952   ** code returned by this function is associated with the same error as
   947    953   ** the strings returned by [sqlite3_errmsg()] and [sqlite3_errmsg16()].
   948    954   */
   949         -int sqlite3_errcode(sqlite3 *db);
   950         -const char *sqlite3_errmsg(sqlite3*);
   951         -const void *sqlite3_errmsg16(sqlite3*);
          955  +SQLITE_API int sqlite3_errcode(sqlite3 *db);
          956  +SQLITE_API const char *sqlite3_errmsg(sqlite3*);
          957  +SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
   952    958   
   953    959   /*
   954    960   ** CAPI3REF: SQL Statement Object
   955    961   **
   956    962   ** Instance of this object represent single SQL statements.  This
   957    963   ** is variously known as a "prepared statement" or a 
   958    964   ** "compiled SQL statement" or simply as a "statement".
................................................................................
   982    988   ** program using one of these routines. 
   983    989   **
   984    990   ** The first argument "db" is an [sqlite3 | SQLite database handle] 
   985    991   ** obtained from a prior call to [sqlite3_open()] or [sqlite3_open16()].
   986    992   ** The second argument "zSql" is the statement to be compiled, encoded
   987    993   ** as either UTF-8 or UTF-16.  The sqlite3_prepare() and sqlite3_prepare_v2()
   988    994   ** interfaces uses UTF-8 and sqlite3_prepare16() and sqlite3_prepare16_v2()
   989         -** use UTF-16. If the next argument, "nBytes", is less
          995  +** use UTF-16.
          996  +**
          997  +** If the nByte argument is less
   990    998   ** than zero, then zSql is read up to the first zero terminator.  If
   991         -** "nBytes" is not less than zero, then it is the length of the string zSql
   992         -** in bytes (not characters).
          999  +** nByte is non-negative, then it is the maximum number of 
         1000  +** bytes read from zSql.  When nByte is non-negative, the
         1001  +** zSql string ends at either the first '\000' character or 
         1002  +** until the nByte-th byte, whichever comes first.
   993   1003   **
   994   1004   ** *pzTail is made to point to the first byte past the end of the first
   995   1005   ** SQL statement in zSql.  This routine only compiles the first statement
   996   1006   ** in zSql, so *pzTail is left pointing to what remains uncompiled.
   997   1007   **
   998   1008   ** *ppStmt is left pointing to a compiled 
   999   1009   ** [sqlite3_stmt | SQL statement structure] that can be
................................................................................
  1035   1045   ** [SQLITE_ERROR] result code and you would have to make a second call to
  1036   1046   ** [sqlite3_reset()] in order to find the underlying cause of the problem.
  1037   1047   ** With the "v2" prepare interfaces, the underlying reason for the error is
  1038   1048   ** returned immediately.
  1039   1049   ** </li>
  1040   1050   ** </ol>
  1041   1051   */
  1042         -int sqlite3_prepare(
         1052  +SQLITE_API int sqlite3_prepare(
  1043   1053     sqlite3 *db,            /* Database handle */
  1044   1054     const char *zSql,       /* SQL statement, UTF-8 encoded */
  1045         -  int nBytes,             /* Length of zSql in bytes. */
         1055  +  int nByte,              /* Maximum length of zSql in bytes. */
  1046   1056     sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  1047   1057     const char **pzTail     /* OUT: Pointer to unused portion of zSql */
  1048   1058   );
  1049   1059   int sqlite3_prepare_v2(
  1050   1060     sqlite3 *db,            /* Database handle */
  1051   1061     const char *zSql,       /* SQL statement, UTF-8 encoded */
  1052         -  int nBytes,             /* Length of zSql in bytes. */
         1062  +  int nByte,              /* Maximum length of zSql in bytes. */
  1053   1063     sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  1054   1064     const char **pzTail     /* OUT: Pointer to unused portion of zSql */
  1055   1065   );
  1056         -int sqlite3_prepare16(
         1066  +SQLITE_API int sqlite3_prepare16(
  1057   1067     sqlite3 *db,            /* Database handle */
  1058   1068     const void *zSql,       /* SQL statement, UTF-16 encoded */
  1059         -  int nBytes,             /* Length of zSql in bytes. */
         1069  +  int nByte,              /* Maximum length of zSql in bytes. */
  1060   1070     sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  1061   1071     const void **pzTail     /* OUT: Pointer to unused portion of zSql */
  1062   1072   );
  1063   1073   int sqlite3_prepare16_v2(
  1064   1074     sqlite3 *db,            /* Database handle */
  1065   1075     const void *zSql,       /* SQL statement, UTF-16 encoded */
  1066         -  int nBytes,             /* Length of zSql in bytes. */
         1076  +  int nByte,              /* Maximum length of zSql in bytes. */
  1067   1077     sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  1068   1078     const void **pzTail     /* OUT: Pointer to unused portion of zSql */
  1069   1079   );
  1070   1080   
  1071   1081   /*
  1072   1082   ** CAPI3REF:  Dynamically Typed Value Object
  1073   1083   **
................................................................................
  1256   1266   
  1257   1267   /*
  1258   1268   ** CAPI3REF: Source Of Data In A Query Result
  1259   1269   **
  1260   1270   ** These routines provide a means to determine what column of what
  1261   1271   ** table in which database a result of a SELECT statement comes from.
  1262   1272   ** The name of the database or table or column can be returned as
  1263         -** either a UTF8 or UTF16 string.  The returned string is valid until
         1273  +** either a UTF8 or UTF16 string.  The _database_ routines return
         1274  +** the database name, the _table_ routines return the table name, and
         1275  +** the origin_ routines return the column name.
         1276  +** The returned string is valid until
  1264   1277   ** the [sqlite3_stmt | prepared statement] is destroyed using
  1265   1278   ** [sqlite3_finalize()] or until the same information is requested
  1266         -** again about the same column.
         1279  +** again in a different encoding.
         1280  +**
         1281  +** The names returned are the original un-aliased names of the
         1282  +** database, table, and column.
  1267   1283   **
  1268   1284   ** The first argument to the following calls is a 
  1269   1285   ** [sqlite3_stmt | compiled SQL statement].
  1270   1286   ** These functions return information about the Nth column returned by 
  1271   1287   ** the statement, where N is the second function argument.
  1272   1288   **
  1273   1289   ** If the Nth column returned by the statement is an expression
................................................................................
  1387   1403   ** We admit that this is a goofy design.  The problem has been fixed
  1388   1404   ** with the "v2" interface.  If you prepare all of your SQL statements
  1389   1405   ** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead
  1390   1406   ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()], then the 
  1391   1407   ** more specific [SQLITE_ERROR | result codes] are returned directly
  1392   1408   ** by sqlite3_step().  The use of the "v2" interface is recommended.
  1393   1409   */
  1394         -int sqlite3_step(sqlite3_stmt*);
         1410  +SQLITE_API int sqlite3_step(sqlite3_stmt*);
  1395   1411   
  1396   1412   /*
  1397   1413   ** CAPI3REF:
  1398   1414   **
  1399   1415   ** Return the number of values in the current row of the result set.
  1400   1416   **
  1401   1417   ** After a call to [sqlite3_step()] that returns [SQLITE_ROW], this routine
................................................................................
  1459   1475   ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].  The value
  1460   1476   ** returned by sqlite3_column_type() is only meaningful if no type
  1461   1477   ** conversions have occurred as described below.  After a type conversion,
  1462   1478   ** the value returned by sqlite3_column_type() is undefined.  Future
  1463   1479   ** versions of SQLite may change the behavior of sqlite3_column_type()
  1464   1480   ** following a type conversion.
  1465   1481   **
  1466         -*** The sqlite3_column_nm
  1467         -**
  1468   1482   ** If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes() 
  1469   1483   ** routine returns the number of bytes in that BLOB or string.
  1470   1484   ** If the result is a UTF-16 string, then sqlite3_column_bytes() converts
  1471   1485   ** the string to UTF-8 and then returns the number of bytes.
  1472   1486   ** If the result is a numeric value then sqlite3_column_bytes() uses
  1473   1487   ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
  1474   1488   ** the number of bytes in that string.
................................................................................
  1583   1597   ** [sqlite3_stmt | virtual machine].  If the virtual machine has not 
  1584   1598   ** completed execution when this routine is called, that is like
  1585   1599   ** encountering an error or an interrupt.  (See [sqlite3_interrupt()].) 
  1586   1600   ** Incomplete updates may be rolled back and transactions cancelled,  
  1587   1601   ** depending on the circumstances, and the 
  1588   1602   ** [SQLITE_ERROR | result code] returned will be [SQLITE_ABORT].
  1589   1603   */
  1590         -int sqlite3_finalize(sqlite3_stmt *pStmt);
         1604  +SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
  1591   1605   
  1592   1606   /*
  1593   1607   ** CAPI3REF: Reset A Prepared Statement Object
  1594   1608   **
  1595   1609   ** The sqlite3_reset() function is called to reset a 
  1596   1610   ** [sqlite_stmt | compiled SQL statement] object.
  1597   1611   ** back to it's initial state, ready to be re-executed.
  1598   1612   ** Any SQL statement variables that had values bound to them using
  1599   1613   ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
  1600   1614   ** Use [sqlite3_clear_bindings()] to reset the bindings.
  1601   1615   */
  1602         -int sqlite3_reset(sqlite3_stmt *pStmt);
         1616  +SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
  1603   1617   
  1604   1618   /*
  1605   1619   ** CAPI3REF: Create Or Redefine SQL Functions
  1606   1620   **
  1607   1621   ** The following two functions are used to add SQL functions or aggregates
  1608   1622   ** or to redefine the behavior of existing SQL functions or aggregates.  The
  1609   1623   ** difference only between the two is that the second parameter, the
................................................................................
  1699   1713   ** These functions are all now obsolete.  In order to maintain
  1700   1714   ** backwards compatibility with older code, we continue to support
  1701   1715   ** these functions.  However, new development projects should avoid
  1702   1716   ** the use of these functions.  To help encourage people to avoid
  1703   1717   ** using these functions, we are not going to tell you want they do.
  1704   1718   */
  1705   1719   int sqlite3_aggregate_count(sqlite3_context*);
  1706         -int sqlite3_expired(sqlite3_stmt*);
         1720  +SQLITE_API int sqlite3_expired(sqlite3_stmt*);
  1707   1721   int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
  1708   1722   int sqlite3_global_recover(void);
  1709   1723   
  1710   1724   
  1711   1725   /*
  1712   1726   ** CAPI3REF: Obtaining SQL Function Parameter Values
  1713   1727   **
................................................................................
  1986   2000   /*
  1987   2001   ** Specify the key for an encrypted database.  This routine should be
  1988   2002   ** called right after sqlite3_open().
  1989   2003   **
  1990   2004   ** The code to implement this API is not available in the public release
  1991   2005   ** of SQLite.
  1992   2006   */
  1993         -int sqlite3_key(
         2007  +SQLITE_API int sqlite3_key(
  1994   2008     sqlite3 *db,                   /* Database to be rekeyed */
  1995   2009     const void *pKey, int nKey     /* The key */
  1996   2010   );
  1997   2011   
  1998   2012   /*
  1999   2013   ** Change the key on an open database.  If the current database is not
  2000   2014   ** encrypted, this routine will encrypt it.  If pNew==0 or nNew==0, the
  2001   2015   ** database is decrypted.
  2002   2016   **
  2003   2017   ** The code to implement this API is not available in the public release
  2004   2018   ** of SQLite.
  2005   2019   */
  2006         -int sqlite3_rekey(
         2020  +SQLITE_API int sqlite3_rekey(
  2007   2021     sqlite3 *db,                   /* Database to be rekeyed */
  2008   2022     const void *pKey, int nKey     /* The new key */
  2009   2023   );
  2010   2024   
  2011   2025   /*
  2012   2026   ** CAPI3REF:  Suspend Execution For A Short Time
  2013   2027   **
  2014         -** This function causes the current thread to suspect execution
         2028  +** This function causes the current thread to suspend execution
  2015   2029   ** a number of milliseconds specified in its parameter.
  2016   2030   **
  2017   2031   ** If the operating system does not support sleep requests with 
  2018   2032   ** millisecond time resolution, then the time will be rounded up to 
  2019   2033   ** the nearest second. The number of milliseconds of sleep actually 
  2020   2034   ** requested from the operating system is returned.
  2021   2035   */
  2022         -int sqlite3_sleep(int);
         2036  +SQLITE_API int sqlite3_sleep(int);
  2023   2037   
  2024   2038   /*
  2025   2039   ** CAPI3REF:  Name Of The Folder Holding Temporary Files
  2026   2040   **
  2027   2041   ** If this global variable is made to point to a string which is
  2028   2042   ** the name of a folder (a.ka. directory), then all temporary files
  2029   2043   ** created by SQLite will be placed in that directory.  If this variable
................................................................................
  2418   2432     int (*xBegin)(sqlite3_vtab *pVTab);
  2419   2433     int (*xSync)(sqlite3_vtab *pVTab);
  2420   2434     int (*xCommit)(sqlite3_vtab *pVTab);
  2421   2435     int (*xRollback)(sqlite3_vtab *pVTab);
  2422   2436     int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
  2423   2437                          void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
  2424   2438                          void **ppArg);
         2439  +
         2440  +  int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
  2425   2441   };
  2426   2442   
  2427   2443   /*
  2428   2444   ** The sqlite3_index_info structure and its substructures is used to
  2429   2445   ** pass information into and receive the reply from the xBestIndex
  2430   2446   ** method of an sqlite3_module.  The fields under **Inputs** are the
  2431   2447   ** inputs to xBestIndex and are read-only.  xBestIndex inserts its
................................................................................
  2511   2527   */
  2512   2528   int sqlite3_create_module(
  2513   2529     sqlite3 *db,               /* SQLite connection to register module with */
  2514   2530     const char *zName,         /* Name of the module */
  2515   2531     const sqlite3_module *,    /* Methods for the module */
  2516   2532     void *                     /* Client data for xCreate/xConnect */
  2517   2533   );
         2534  +
         2535  +/*
         2536  +** This routine is identical to the sqlite3_create_module() method above,
         2537  +** except that it allows a destructor function to be specified. It is
         2538  +** even more experimental than the rest of the virtual tables API.
         2539  +*/
         2540  +int sqlite3_create_module_v2(
         2541  +  sqlite3 *db,               /* SQLite connection to register module with */
         2542  +  const char *zName,         /* Name of the module */
         2543  +  const sqlite3_module *,    /* Methods for the module */
         2544  +  void *,                    /* Client data for xCreate/xConnect */
         2545  +  void(*xDestroy)(void*)     /* Module destructor function */
         2546  +);
  2518   2547   
  2519   2548   /*
  2520   2549   ** Every module implementation uses a subclass of the following structure
  2521   2550   ** to describe a particular instance of the module.  Each subclass will
  2522   2551   ** be taylored to the specific needs of the module implementation.   The
  2523   2552   ** purpose of this superclass is to define certain fields that are common
  2524   2553   ** to all module implementations.
................................................................................
  2717   2746   ** This file contains the C functions that implement date and time
  2718   2747   ** functions for SQLite.  
  2719   2748   **
  2720   2749   ** There is only one exported symbol in this file - the function
  2721   2750   ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
  2722   2751   ** All other code has file scope.
  2723   2752   **
  2724         -** $Id: sqlite3.c,v 1.3 2007/06/19 22:43:23 rmsimpson Exp $
         2753  +** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
  2725   2754   **
  2726   2755   ** SQLite processes all times and dates as Julian Day numbers.  The
  2727   2756   ** dates and times are stored as the number of days since noon
  2728   2757   ** in Greenwich on November 24, 4714 B.C. according to the Gregorian
  2729   2758   ** calendar system. 
  2730   2759   **
  2731   2760   ** 1970-01-01 00:00:00 is JD 2440587.5
................................................................................
  2761   2790   **    May you do good and not evil.
  2762   2791   **    May you find forgiveness for yourself and forgive others.
  2763   2792   **    May you share freely, never taking more than you give.
  2764   2793   **
  2765   2794   *************************************************************************
  2766   2795   ** Internal interface definitions for SQLite.
  2767   2796   **
  2768         -** @(#) $Id: sqlite3.c,v 1.3 2007/06/19 22:43:23 rmsimpson Exp $
         2797  +** @(#) $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
  2769   2798   */
  2770   2799   #ifndef _SQLITEINT_H_
  2771   2800   #define _SQLITEINT_H_
  2772         -/************** Include limits.h in the middle of sqliteInt.h ****************/
  2773         -/************** Begin file limits.h ******************************************/
         2801  +/************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/
         2802  +/************** Begin file sqliteLimit.h *************************************/
  2774   2803   /*
  2775   2804   ** 2007 May 7
  2776   2805   **
  2777   2806   ** The author disclaims copyright to this source code.  In place of
  2778   2807   ** a legal notice, here is a blessing:
  2779   2808   **
  2780   2809   **    May you do good and not evil.
................................................................................
  2781   2810   **    May you find forgiveness for yourself and forgive others.
  2782   2811   **    May you share freely, never taking more than you give.
  2783   2812   **
  2784   2813   *************************************************************************
  2785   2814   ** 
  2786   2815   ** This file defines various limits of what SQLite can process.
  2787   2816   **
  2788         -** @(#) $Id: sqlite3.c,v 1.3 2007/06/19 22:43:23 rmsimpson Exp $
         2817  +** @(#) $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
  2789   2818   */
  2790   2819   
  2791   2820   /*
  2792   2821   ** The maximum length of a TEXT or BLOB in bytes.   This also
  2793   2822   ** limits the size of a row in a table or index.
  2794   2823   **
  2795   2824   ** The hard limit is the ability of a 32-bit signed integer
................................................................................
  2926   2955   ** Maximum length (in bytes) of the pattern in a LIKE or GLOB
  2927   2956   ** operator.
  2928   2957   */
  2929   2958   #ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH
  2930   2959   # define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000
  2931   2960   #endif
  2932   2961   
  2933         -/************** End of limits.h **********************************************/
         2962  +/************** End of sqliteLimit.h *****************************************/
  2934   2963   /************** Continuing where we left off in sqliteInt.h ******************/
  2935   2964   
  2936   2965   
  2937   2966   #if defined(SQLITE_TCL) || defined(TCLSH)
  2938   2967   # include <tcl.h>
  2939   2968   #endif
  2940   2969   
................................................................................
  2984   3013   **    May you find forgiveness for yourself and forgive others.
  2985   3014   **    May you share freely, never taking more than you give.
  2986   3015   **
  2987   3016   *************************************************************************
  2988   3017   ** This is the header file for the generic hash-table implemenation
  2989   3018   ** used in SQLite.
  2990   3019   **
  2991         -** $Id: sqlite3.c,v 1.3 2007/06/19 22:43:23 rmsimpson Exp $
         3020  +** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
  2992   3021   */
  2993   3022   #ifndef _SQLITE_HASH_H_
  2994   3023   #define _SQLITE_HASH_H_
  2995   3024   
  2996   3025   /* Forward declarations of structures. */
  2997   3026   typedef struct Hash Hash;
  2998   3027   typedef struct HashElem HashElem;
................................................................................
  3052   3081   /* #define SQLITE_HASH_POINTER   2 // NOT USED */
  3053   3082   #define SQLITE_HASH_STRING    3
  3054   3083   #define SQLITE_HASH_BINARY    4
  3055   3084   
  3056   3085   /*
  3057   3086   ** Access routines.  To delete, insert a NULL pointer.
  3058   3087   */
  3059         -static void sqlite3HashInit(Hash*, int keytype, int copyKey);
  3060         -static void *sqlite3HashInsert(Hash*, const void *pKey, int nKey, void *pData);
  3061         -static void *sqlite3HashFind(const Hash*, const void *pKey, int nKey);
  3062         -static void sqlite3HashClear(Hash*);
         3088  +SQLITE_PRIVATE void sqlite3HashInit(Hash*, int keytype, int copyKey);
         3089  +SQLITE_PRIVATE void *sqlite3HashInsert(Hash*, const void *pKey, int nKey, void *pData);
         3090  +SQLITE_PRIVATE void *sqlite3HashFind(const Hash*, const void *pKey, int nKey);
         3091  +SQLITE_PRIVATE void sqlite3HashClear(Hash*);
  3063   3092   
  3064   3093   /*
  3065   3094   ** Macros for looping over all elements of a hash table.  The idiom is
  3066   3095   ** like this:
  3067   3096   **
  3068   3097   **   Hash h;
  3069   3098   **   HashElem *p;
................................................................................
  3247   3276   /************** Continuing where we left off in sqliteInt.h ******************/
  3248   3277   #include <stdio.h>
  3249   3278   #include <stdlib.h>
  3250   3279   #include <string.h>
  3251   3280   #include <assert.h>
  3252   3281   #include <stddef.h>
  3253   3282   
  3254         -#if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
  3255         -# define isnan(X)  ((X)!=(X))
  3256         -#endif
         3283  +#define sqlite3_isnan(X)  ((X)!=(X))
  3257   3284   
  3258   3285   /*
  3259   3286   ** If compiling for a processor that lacks floating point support,
  3260   3287   ** substitute integer for floating-point
  3261   3288   */
  3262   3289   #ifdef SQLITE_OMIT_FLOATING_POINT
  3263   3290   # define double sqlite_int64
................................................................................
  3418   3445   *************************************************************************
  3419   3446   ** Header file for the Virtual DataBase Engine (VDBE)
  3420   3447   **
  3421   3448   ** This header defines the interface to the virtual database engine
  3422   3449   ** or VDBE.  The VDBE implements an abstract machine that runs a
  3423   3450   ** simple program to access and modify the underlying database.
  3424   3451   **
  3425         -** $Id: sqlite3.c,v 1.3 2007/06/19 22:43:23 rmsimpson Exp $
         3452  +** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
  3426   3453   */
  3427   3454   #ifndef _SQLITE_VDBE_H_
  3428   3455   #define _SQLITE_VDBE_H_
  3429   3456   
  3430   3457   /*
  3431   3458   ** A single VDBE is an opaque structure named "Vdbe".  Only routines
  3432   3459   ** in the source file sqliteVdbe.c are allowed to see the insides
................................................................................
  3549   3576   #define OP_Remainder                           82   /* same as TK_REM      */
  3550   3577   #define OP_NewRowid                            23
  3551   3578   #define OP_Multiply                            80   /* same as TK_STAR     */
  3552   3579   #define OP_IfMemNeg                            24
  3553   3580   #define OP_Variable                            25
  3554   3581   #define OP_String                              26
  3555   3582   #define OP_RealAffinity                        27
  3556         -#define OP_ParseSchema                         28
  3557         -#define OP_VOpen                               29
  3558         -#define OP_Close                               30
  3559         -#define OP_CreateIndex                         31
  3560         -#define OP_IsUnique                            32
  3561         -#define OP_NotFound                            33
  3562         -#define OP_Int64                               34
  3563         -#define OP_MustBeInt                           35
  3564         -#define OP_Halt                                36
  3565         -#define OP_Rowid                               37
  3566         -#define OP_IdxLT                               38
  3567         -#define OP_AddImm                              39
  3568         -#define OP_Statement                           40
  3569         -#define OP_RowData                             41
  3570         -#define OP_MemMax                              42
  3571         -#define OP_Push                                43
         3583  +#define OP_VRename                             28
         3584  +#define OP_ParseSchema                         29
         3585  +#define OP_VOpen                               30
         3586  +#define OP_Close                               31
         3587  +#define OP_CreateIndex                         32
         3588  +#define OP_IsUnique                            33
         3589  +#define OP_NotFound                            34
         3590  +#define OP_Int64                               35
         3591  +#define OP_MustBeInt                           36
         3592  +#define OP_Halt                                37
         3593  +#define OP_Rowid                               38
         3594  +#define OP_IdxLT                               39
         3595  +#define OP_AddImm                              40
         3596  +#define OP_Statement                           41
         3597  +#define OP_RowData                             42
         3598  +#define OP_MemMax                              43
         3599  +#define OP_Push                                44
  3572   3600   #define OP_Or                                  60   /* same as TK_OR       */
  3573         -#define OP_NotExists                           44
  3574         -#define OP_MemIncr                             45
  3575         -#define OP_Gosub                               46
         3601  +#define OP_NotExists                           45
         3602  +#define OP_MemIncr                             46
         3603  +#define OP_Gosub                               47
  3576   3604   #define OP_Divide                              81   /* same as TK_SLASH    */
  3577         -#define OP_Integer                             47
         3605  +#define OP_Integer                             48
  3578   3606   #define OP_ToNumeric                          140   /* same as TK_TO_NUMERIC*/
  3579         -#define OP_MemInt                              48
  3580         -#define OP_Prev                                49
         3607  +#define OP_MemInt                              49
         3608  +#define OP_Prev                                50
  3581   3609   #define OP_Concat                              83   /* same as TK_CONCAT   */
  3582   3610   #define OP_BitAnd                              74   /* same as TK_BITAND   */
  3583         -#define OP_VColumn                             50
  3584         -#define OP_CreateTable                         51
  3585         -#define OP_Last                                52
         3611  +#define OP_VColumn                             51
         3612  +#define OP_CreateTable                         52
         3613  +#define OP_Last                                53
  3586   3614   #define OP_IsNull                              65   /* same as TK_ISNULL   */
  3587         -#define OP_IncrVacuum                          53
  3588         -#define OP_IdxRowid                            54
  3589         -#define OP_MakeIdxRec                          55
         3615  +#define OP_IncrVacuum                          54
         3616  +#define OP_IdxRowid                            55
         3617  +#define OP_MakeIdxRec                          56
  3590   3618   #define OP_ShiftRight                          77   /* same as TK_RSHIFT   */
  3591         -#define OP_ResetCount                          56
  3592         -#define OP_FifoWrite                           57
  3593         -#define OP_Callback                            58
  3594         -#define OP_ContextPush                         59
  3595         -#define OP_DropTrigger                         62
  3596         -#define OP_DropIndex                           63
  3597         -#define OP_IdxGE                               64
  3598         -#define OP_IdxDelete                           73
  3599         -#define OP_Vacuum                              84
  3600         -#define OP_MoveLe                              86
  3601         -#define OP_IfNot                               89
  3602         -#define OP_DropTable                           90
  3603         -#define OP_MakeRecord                          91
         3619  +#define OP_ResetCount                          57
         3620  +#define OP_FifoWrite                           58
         3621  +#define OP_Callback                            59
         3622  +#define OP_ContextPush                         62
         3623  +#define OP_DropTrigger                         63
         3624  +#define OP_DropIndex                           64
         3625  +#define OP_IdxGE                               73
         3626  +#define OP_IdxDelete                           84
         3627  +#define OP_Vacuum                              86
         3628  +#define OP_MoveLe                              89
         3629  +#define OP_IfNot                               90
         3630  +#define OP_DropTable                           91
         3631  +#define OP_MakeRecord                          92
  3604   3632   #define OP_ToBlob                             139   /* same as TK_TO_BLOB  */
  3605         -#define OP_Delete                              92
  3606         -#define OP_AggFinal                            93
         3633  +#define OP_Delete                              93
         3634  +#define OP_AggFinal                            94
  3607   3635   #define OP_ShiftLeft                           76   /* same as TK_LSHIFT   */
  3608         -#define OP_Dup                                 94
  3609         -#define OP_Goto                                95
  3610         -#define OP_TableLock                           96
  3611         -#define OP_FifoRead                            97
  3612         -#define OP_Clear                               98
  3613         -#define OP_IdxGT                               99
  3614         -#define OP_MoveLt                             100
         3636  +#define OP_Dup                                 95
         3637  +#define OP_Goto                                96
         3638  +#define OP_TableLock                           97
         3639  +#define OP_FifoRead                            98
         3640  +#define OP_Clear                               99
         3641  +#define OP_IdxGT                              100
         3642  +#define OP_MoveLt                             101
  3615   3643   #define OP_Le                                  70   /* same as TK_LE       */
  3616         -#define OP_VerifyCookie                       101
  3617         -#define OP_AggStep                            102
  3618         -#define OP_Pull                               103
         3644  +#define OP_VerifyCookie                       102
         3645  +#define OP_AggStep                            103
         3646  +#define OP_Pull                               104
  3619   3647   #define OP_ToText                             138   /* same as TK_TO_TEXT  */
  3620   3648   #define OP_Not                                 16   /* same as TK_NOT      */
  3621   3649   #define OP_ToReal                             142   /* same as TK_TO_REAL  */
  3622         -#define OP_SetNumColumns                      104
  3623         -#define OP_AbsValue                           105
  3624         -#define OP_Transaction                        106
  3625         -#define OP_VFilter                            107
         3650  +#define OP_SetNumColumns                      105
         3651  +#define OP_AbsValue                           106
         3652  +#define OP_Transaction                        107
         3653  +#define OP_VFilter                            108
  3626   3654   #define OP_Negative                            85   /* same as TK_UMINUS   */
  3627   3655   #define OP_Ne                                  67   /* same as TK_NE       */
  3628         -#define OP_VDestroy                           108
  3629         -#define OP_ContextPop                         109
         3656  +#define OP_VDestroy                           109
         3657  +#define OP_ContextPop                         110
  3630   3658   #define OP_BitOr                               75   /* same as TK_BITOR    */
  3631         -#define OP_Next                               110
  3632         -#define OP_IdxInsert                          111
  3633         -#define OP_Distinct                           112
         3659  +#define OP_Next                               111
         3660  +#define OP_IdxInsert                          112
         3661  +#define OP_Distinct                           113
  3634   3662   #define OP_Lt                                  71   /* same as TK_LT       */
  3635         -#define OP_Insert                             113
  3636         -#define OP_Destroy                            114
  3637         -#define OP_ReadCookie                         115
  3638         -#define OP_ForceInt                           116
  3639         -#define OP_LoadAnalysis                       117
  3640         -#define OP_Explain                            118
  3641         -#define OP_IfMemZero                          119
  3642         -#define OP_OpenPseudo                         120
  3643         -#define OP_OpenEphemeral                      121
  3644         -#define OP_Null                               122
  3645         -#define OP_Blob                               123
         3663  +#define OP_Insert                             114
         3664  +#define OP_Destroy                            115
         3665  +#define OP_ReadCookie                         116
         3666  +#define OP_ForceInt                           117
         3667  +#define OP_LoadAnalysis                       118
         3668  +#define OP_Explain                            119
         3669  +#define OP_IfMemZero                          120
         3670  +#define OP_OpenPseudo                         121
         3671  +#define OP_OpenEphemeral                      122
         3672  +#define OP_Null                               123
         3673  +#define OP_Blob                               124
  3646   3674   #define OP_Add                                 78   /* same as TK_PLUS     */
  3647         -#define OP_MemStore                           124
  3648         -#define OP_Rewind                             127
  3649         -#define OP_MoveGe                             128
  3650         -#define OP_VBegin                             129
  3651         -#define OP_VUpdate                            130
         3675  +#define OP_MemStore                           127
         3676  +#define OP_Rewind                             128
         3677  +#define OP_MoveGe                             129
         3678  +#define OP_VBegin                             130
         3679  +#define OP_VUpdate                            131
  3652   3680   #define OP_BitNot                              87   /* same as TK_BITNOT   */
  3653         -#define OP_VCreate                            131
  3654         -#define OP_MemMove                            132
  3655         -#define OP_MemNull                            133
  3656         -#define OP_Found                              134
  3657         -#define OP_NullRow                            135
         3681  +#define OP_VCreate                            132
         3682  +#define OP_MemMove                            133
         3683  +#define OP_MemNull                            134
         3684  +#define OP_Found                              135
         3685  +#define OP_NullRow                            136
  3658   3686   
  3659   3687   /* The following opcode values are never used */
  3660         -#define OP_NotUsed_136                        136
  3661   3688   #define OP_NotUsed_137                        137
  3662   3689   
  3663   3690   /* Opcodes that are guaranteed to never push a value onto the stack
  3664   3691   ** contain a 1 their corresponding position of the following mask
  3665   3692   ** set.  See the opcodeNoPush() function in vdbeaux.c  */
  3666   3693   #define NOPUSH_MASK_0 0xeeb4
  3667         -#define NOPUSH_MASK_1 0x796b
  3668         -#define NOPUSH_MASK_2 0x7ddb
  3669         -#define NOPUSH_MASK_3 0xff32
         3694  +#define NOPUSH_MASK_1 0xf96b
         3695  +#define NOPUSH_MASK_2 0xfbb6
         3696  +#define NOPUSH_MASK_3 0xfe64
  3670   3697   #define NOPUSH_MASK_4 0xffff
  3671         -#define NOPUSH_MASK_5 0xb6f7
  3672         -#define NOPUSH_MASK_6 0xfdfd
  3673         -#define NOPUSH_MASK_7 0x93b3
  3674         -#define NOPUSH_MASK_8 0x7ccf
         3698  +#define NOPUSH_MASK_5 0x6ef7
         3699  +#define NOPUSH_MASK_6 0xfbfb
         3700  +#define NOPUSH_MASK_7 0x8767
         3701  +#define NOPUSH_MASK_8 0x7d9f
  3675   3702   #define NOPUSH_MASK_9 0x0000
  3676   3703   
  3677   3704   /************** End of opcodes.h *********************************************/
  3678   3705   /************** Continuing where we left off in vdbe.h ***********************/
  3679   3706   
  3680   3707   /*
  3681   3708   ** Prototypes for the VDBE interface.  See comments on the implementation
  3682   3709   ** for a description of what each of these routines does.
  3683   3710   */
  3684         -static Vdbe *sqlite3VdbeCreate(sqlite3*);
  3685         -static int sqlite3VdbeAddOp(Vdbe*,int,int,int);
  3686         -static int sqlite3VdbeOp3(Vdbe*,int,int,int,const char *zP3,int);
  3687         -static int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
  3688         -static void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
  3689         -static void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
  3690         -static void sqlite3VdbeJumpHere(Vdbe*, int addr);
  3691         -static void sqlite3VdbeChangeToNoop(Vdbe*, int addr, int N);
  3692         -static void sqlite3VdbeChangeP3(Vdbe*, int addr, const char *zP1, int N);
  3693         -static VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
  3694         -static int sqlite3VdbeMakeLabel(Vdbe*);
  3695         -static void sqlite3VdbeDelete(Vdbe*);
  3696         -static void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int);
  3697         -static int sqlite3VdbeFinalize(Vdbe*);
  3698         -static void sqlite3VdbeResolveLabel(Vdbe*, int);
  3699         -static int sqlite3VdbeCurrentAddr(Vdbe*);
  3700         -#ifdef SQLITE_DEBUG
  3701         -static   void sqlite3VdbeTrace(Vdbe*,FILE*);
  3702         -#endif
  3703         -static void sqlite3VdbeResetStepResult(Vdbe*);
  3704         -static int sqlite3VdbeReset(Vdbe*);
  3705         -static void sqlite3VdbeSetNumCols(Vdbe*,int);
  3706         -static int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, int);
  3707         -static void sqlite3VdbeCountChanges(Vdbe*);
  3708         -static sqlite3 *sqlite3VdbeDb(Vdbe*);
  3709         -static void sqlite3VdbeSetSql(Vdbe*, const char *z, int n);
  3710         -static const char *sqlite3VdbeGetSql(Vdbe*);
  3711         -static void sqlite3VdbeSwap(Vdbe*,Vdbe*);
  3712         -
  3713         -#ifndef NDEBUG
  3714         -static   void sqlite3VdbeComment(Vdbe*, const char*, ...);
         3711  +SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(sqlite3*);
         3712  +SQLITE_PRIVATE int sqlite3VdbeAddOp(Vdbe*,int,int,int);
         3713  +SQLITE_PRIVATE int sqlite3VdbeOp3(Vdbe*,int,int,int,const char *zP3,int);
         3714  +SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
         3715  +SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
         3716  +SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
         3717  +SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
         3718  +SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr, int N);
         3719  +SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, int addr, const char *zP1, int N);
         3720  +SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
         3721  +SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
         3722  +SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe*);
         3723  +SQLITE_PRIVATE void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int);
         3724  +SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*);
         3725  +SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int);
         3726  +SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe*);
         3727  +#ifdef SQLITE_DEBUG
         3728  +SQLITE_PRIVATE   void sqlite3VdbeTrace(Vdbe*,FILE*);
         3729  +#endif
         3730  +SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe*);
         3731  +SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*);
         3732  +SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe*,int);
         3733  +SQLITE_PRIVATE int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, int);
         3734  +SQLITE_PRIVATE void sqlite3VdbeCountChanges(Vdbe*);
         3735  +SQLITE_PRIVATE sqlite3 *sqlite3VdbeDb(Vdbe*);
         3736  +SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe*, const char *z, int n);
         3737  +SQLITE_PRIVATE const char *sqlite3VdbeGetSql(Vdbe*);
         3738  +SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe*,Vdbe*);
         3739  +
         3740  +#ifndef NDEBUG
         3741  +SQLITE_PRIVATE   void sqlite3VdbeComment(Vdbe*, const char*, ...);
  3715   3742   # define VdbeComment(X)  sqlite3VdbeComment X
  3716   3743   #else
  3717   3744   # define VdbeComment(X)
  3718   3745   #endif
  3719   3746   
  3720   3747   #endif
  3721   3748   
................................................................................
  3734   3761   **    May you share freely, never taking more than you give.
  3735   3762   **
  3736   3763   *************************************************************************
  3737   3764   ** This header file defines the interface that the sqlite B-Tree file
  3738   3765   ** subsystem.  See comments in the source code for a detailed description
  3739   3766   ** of what each interface routine does.
  3740   3767   **
  3741         -** @(#) $Id: sqlite3.c,v 1.3 2007/06/19 22:43:23 rmsimpson Exp $
         3768  +** @(#) $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
  3742   3769   */
  3743   3770   #ifndef _BTREE_H_
  3744   3771   #define _BTREE_H_
  3745   3772   
  3746   3773   /* TODO: This definition is just included so other modules compile. It
  3747   3774   ** needs to be revisited.
  3748   3775   */
................................................................................
  3764   3791   ** Forward declarations of structure
  3765   3792   */
  3766   3793   typedef struct Btree Btree;
  3767   3794   typedef struct BtCursor BtCursor;
  3768   3795   typedef struct BtShared BtShared;
  3769   3796   
  3770   3797   
  3771         -static int sqlite3BtreeOpen(
         3798  +SQLITE_PRIVATE int sqlite3BtreeOpen(
  3772   3799     const char *zFilename,   /* Name of database file to open */
  3773   3800     sqlite3 *db,             /* Associated database connection */
  3774   3801     Btree **,                /* Return open Btree* here */
  3775   3802     int flags                /* Flags */
  3776   3803   );
  3777   3804   
  3778   3805   /* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the
................................................................................
  3781   3808   ** NOTE:  These values must match the corresponding PAGER_ values in
  3782   3809   ** pager.h.
  3783   3810   */
  3784   3811   #define BTREE_OMIT_JOURNAL  1  /* Do not use journal.  No argument */
  3785   3812   #define BTREE_NO_READLOCK   2  /* Omit readlocks on readonly files */
  3786   3813   #define BTREE_MEMORY        4  /* In-memory DB.  No argument */
  3787   3814   
  3788         -static int sqlite3BtreeClose(Btree*);
  3789         -static int sqlite3BtreeSetBusyHandler(Btree*,BusyHandler*);
  3790         -static int sqlite3BtreeSetCacheSize(Btree*,int);
  3791         -static int sqlite3BtreeSetSafetyLevel(Btree*,int,int);
  3792         -static int sqlite3BtreeSyncDisabled(Btree*);
  3793         -static int sqlite3BtreeSetPageSize(Btree*,int,int);
  3794         -static int sqlite3BtreeGetPageSize(Btree*);
  3795         -static int sqlite3BtreeMaxPageCount(Btree*,int);
  3796         -static int sqlite3BtreeGetReserve(Btree*);
  3797         -static int sqlite3BtreeSetAutoVacuum(Btree *, int);
  3798         -static int sqlite3BtreeGetAutoVacuum(Btree *);
  3799         -static int sqlite3BtreeBeginTrans(Btree*,int);
  3800         -static int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
  3801         -static int sqlite3BtreeCommitPhaseTwo(Btree*);
  3802         -static int sqlite3BtreeCommit(Btree*);
  3803         -static int sqlite3BtreeRollback(Btree*);
  3804         -static int sqlite3BtreeBeginStmt(Btree*);
  3805         -static int sqlite3BtreeCommitStmt(Btree*);
  3806         -static int sqlite3BtreeRollbackStmt(Btree*);
  3807         -static int sqlite3BtreeCreateTable(Btree*, int*, int flags);
  3808         -static int sqlite3BtreeIsInTrans(Btree*);
  3809         -static int sqlite3BtreeIsInStmt(Btree*);
  3810         -static int sqlite3BtreeIsInReadTrans(Btree*);
  3811         -static void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
  3812         -static int sqlite3BtreeSchemaLocked(Btree *);
  3813         -static int sqlite3BtreeLockTable(Btree *, int, u8);
  3814         -
  3815         -static const char *sqlite3BtreeGetFilename(Btree *);
  3816         -static const char *sqlite3BtreeGetDirname(Btree *);
  3817         -static const char *sqlite3BtreeGetJournalname(Btree *);
  3818         -static int sqlite3BtreeCopyFile(Btree *, Btree *);
  3819         -
  3820         -static int sqlite3BtreeIncrVacuum(Btree *);
         3815  +SQLITE_PRIVATE int sqlite3BtreeClose(Btree*);
         3816  +SQLITE_PRIVATE int sqlite3BtreeSetBusyHandler(Btree*,BusyHandler*);
         3817  +SQLITE_PRIVATE int sqlite3BtreeSetCacheSize(Btree*,int);
         3818  +SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(Btree*,int,int);
         3819  +SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree*);
         3820  +SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree*,int,int);
         3821  +SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*);
         3822  +SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int);
         3823  +SQLITE_PRIVATE int sqlite3BtreeGetReserve(Btree*);
         3824  +SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
         3825  +SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
         3826  +SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int);
         3827  +SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
         3828  +SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*);
         3829  +SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*);
         3830  +SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*);
         3831  +SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*);
         3832  +SQLITE_PRIVATE int sqlite3BtreeCommitStmt(Btree*);
         3833  +SQLITE_PRIVATE int sqlite3BtreeRollbackStmt(Btree*);
         3834  +SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags);
         3835  +SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*);
         3836  +SQLITE_PRIVATE int sqlite3BtreeIsInStmt(Btree*);
         3837  +SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*);
         3838  +SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
         3839  +SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *);
         3840  +SQLITE_PRIVATE int sqlite3BtreeLockTable(Btree *, int, u8);
         3841  +
         3842  +SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *);
         3843  +SQLITE_PRIVATE const char *sqlite3BtreeGetDirname(Btree *);
         3844  +SQLITE_PRIVATE const char *sqlite3BtreeGetJournalname(Btree *);
         3845  +SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *, Btree *);
         3846  +
         3847  +SQLITE_PRIVATE int sqlite3BtreeIncrVacuum(Btree *);
  3821   3848   
  3822   3849   /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
  3823   3850   ** of the following flags:
  3824   3851   */
  3825   3852   #define BTREE_INTKEY     1    /* Table has only 64-bit signed integer keys */
  3826   3853   #define BTREE_ZERODATA   2    /* Table has keys only - no data */
  3827   3854   #define BTREE_LEAFDATA   4    /* Data stored in leaves only.  Implies INTKEY */
  3828   3855   
  3829         -static int sqlite3BtreeDropTable(Btree*, int, int*);
  3830         -static int sqlite3BtreeClearTable(Btree*, int);
  3831         -static int sqlite3BtreeGetMeta(Btree*, int idx, u32 *pValue);
  3832         -static int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
         3856  +SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree*, int, int*);
         3857  +SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree*, int);
         3858  +SQLITE_PRIVATE int sqlite3BtreeGetMeta(Btree*, int idx, u32 *pValue);
         3859  +SQLITE_PRIVATE int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
  3833   3860   
  3834         -static int sqlite3BtreeCursor(
         3861  +SQLITE_PRIVATE int sqlite3BtreeCursor(
  3835   3862     Btree*,                              /* BTree containing table to open */
  3836   3863     int iTable,                          /* Index of root page */
  3837   3864     int wrFlag,                          /* 1 for writing.  0 for read-only */
  3838   3865     int(*)(void*,int,const void*,int,const void*),  /* Key comparison function */
  3839   3866     void*,                               /* First argument to compare function */
  3840   3867     BtCursor **ppCursor                  /* Returned cursor */
  3841   3868   );
  3842   3869   
  3843         -static int sqlite3BtreeCloseCursor(BtCursor*);
  3844         -static int sqlite3BtreeMoveto(BtCursor*,const void *pKey,i64 nKey,int bias,int *pRes);
  3845         -static int sqlite3BtreeDelete(BtCursor*);
  3846         -static int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
         3870  +SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor*);
         3871  +SQLITE_PRIVATE int sqlite3BtreeMoveto(BtCursor*,const void *pKey,i64 nKey,int bias,int *pRes);
         3872  +SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*);
         3873  +SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
  3847   3874                                     const void *pData, int nData,
  3848   3875                                     int nZero, int bias);
  3849         -static int sqlite3BtreeFirst(BtCursor*, int *pRes);
  3850         -static int sqlite3BtreeLast(BtCursor*, int *pRes);
  3851         -static int sqlite3BtreeNext(BtCursor*, int *pRes);
  3852         -static int sqlite3BtreeEof(BtCursor*);
  3853         -static int sqlite3BtreeFlags(BtCursor*);
  3854         -static int sqlite3BtreePrevious(BtCursor*, int *pRes);
  3855         -static int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
  3856         -static int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
  3857         -static const void *sqlite3BtreeKeyFetch(BtCursor*, int *pAmt);
  3858         -static const void *sqlite3BtreeDataFetch(BtCursor*, int *pAmt);
  3859         -static int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
  3860         -static int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
  3861         -
  3862         -static char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
  3863         -static struct Pager *sqlite3BtreePager(Btree*);
  3864         -
  3865         -static int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
  3866         -static void sqlite3BtreeCacheOverflow(BtCursor *);
  3867         -
  3868         -#ifdef SQLITE_TEST
  3869         -static int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
  3870         -static void sqlite3BtreeCursorList(Btree*);
  3871         -static int sqlite3BtreePageDump(Btree*, int, int recursive);
         3876  +SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
         3877  +SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
         3878  +SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
         3879  +SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
         3880  +SQLITE_PRIVATE int sqlite3BtreeFlags(BtCursor*);
         3881  +SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
         3882  +SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
         3883  +SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
         3884  +SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, int *pAmt);
         3885  +SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, int *pAmt);
         3886  +SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
         3887  +SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
         3888  +
         3889  +SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
         3890  +SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
         3891  +
         3892  +SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
         3893  +SQLITE_PRIVATE void sqlite3BtreeCacheOverflow(BtCursor *);
         3894  +
         3895  +#ifdef SQLITE_TEST
         3896  +SQLITE_PRIVATE int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
         3897  +SQLITE_PRIVATE void sqlite3BtreeCursorList(Btree*);
         3898  +SQLITE_PRIVATE int sqlite3BtreePageDump(Btree*, int, int recursive);
  3872   3899   #endif
  3873   3900   
  3874   3901   #endif /* _BTREE_H_ */
  3875   3902   
  3876   3903   /************** End of btree.h ***********************************************/
  3877   3904   /************** Continuing where we left off in sqliteInt.h ******************/
  3878   3905   /************** Include pager.h in the middle of sqliteInt.h *****************/
................................................................................
  3888   3915   **    May you share freely, never taking more than you give.
  3889   3916   **
  3890   3917   *************************************************************************
  3891   3918   ** This header file defines the interface that the sqlite page cache
  3892   3919   ** subsystem.  The page cache subsystem reads and writes a file a page
  3893   3920   ** at a time and provides a journal for rollback.
  3894   3921   **
  3895         -** @(#) $Id: sqlite3.c,v 1.3 2007/06/19 22:43:23 rmsimpson Exp $
         3922  +** @(#) $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
  3896   3923   */
  3897   3924   
  3898   3925   #ifndef _PAGER_H_
  3899   3926   #define _PAGER_H_
  3900   3927   
  3901   3928   /*
  3902   3929   ** The type used to represent a page number.  The first page in a file
................................................................................
  3929   3956   #define PAGER_LOCKINGMODE_NORMAL      0
  3930   3957   #define PAGER_LOCKINGMODE_EXCLUSIVE   1
  3931   3958   
  3932   3959   /*
  3933   3960   ** See source code comments for a detailed description of the following
  3934   3961   ** routines:
  3935   3962   */
  3936         -static int sqlite3PagerOpen(Pager **ppPager, const char *zFilename,
         3963  +SQLITE_PRIVATE int sqlite3PagerOpen(Pager **ppPager, const char *zFilename,
  3937   3964                        int nExtra, int flags);
  3938         -static void sqlite3PagerSetBusyhandler(Pager*, BusyHandler *pBusyHandler);
  3939         -static void sqlite3PagerSetDestructor(Pager*, void(*)(DbPage*,int));
  3940         -static void sqlite3PagerSetReiniter(Pager*, void(*)(DbPage*,int));
  3941         -static int sqlite3PagerSetPagesize(Pager*, int);
  3942         -static int sqlite3PagerMaxPageCount(Pager*, int);
  3943         -static int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
  3944         -static void sqlite3PagerSetCachesize(Pager*, int);
  3945         -static int sqlite3PagerClose(Pager *pPager);
  3946         -static int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
         3965  +SQLITE_PRIVATE void sqlite3PagerSetBusyhandler(Pager*, BusyHandler *pBusyHandler);
         3966  +SQLITE_PRIVATE void sqlite3PagerSetDestructor(Pager*, void(*)(DbPage*,int));
         3967  +SQLITE_PRIVATE void sqlite3PagerSetReiniter(Pager*, void(*)(DbPage*,int));
         3968  +SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, int);
         3969  +SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int);
         3970  +SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
         3971  +SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int);
         3972  +SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager);
         3973  +SQLITE_PRIVATE int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
  3947   3974   #define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0)
  3948         -static DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
  3949         -static int sqlite3PagerRef(DbPage*);
  3950         -static int sqlite3PagerUnref(DbPage*);
  3951         -static int sqlite3PagerWrite(DbPage*);
  3952         -static int sqlite3PagerOverwrite(Pager *pPager, Pgno pgno, void*);
  3953         -static int sqlite3PagerPagecount(Pager*);
  3954         -static int sqlite3PagerTruncate(Pager*,Pgno);
  3955         -static int sqlite3PagerBegin(DbPage*, int exFlag);
  3956         -static int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, Pgno);
  3957         -static int sqlite3PagerCommitPhaseTwo(Pager*);
  3958         -static int sqlite3PagerRollback(Pager*);
  3959         -static int sqlite3PagerIsreadonly(Pager*);
  3960         -static int sqlite3PagerStmtBegin(Pager*);
  3961         -static int sqlite3PagerStmtCommit(Pager*);
  3962         -static int sqlite3PagerStmtRollback(Pager*);
  3963         -static void sqlite3PagerDontRollback(DbPage*);
  3964         -static void sqlite3PagerDontWrite(DbPage*);
  3965         -static int sqlite3PagerRefcount(Pager*);
  3966         -static void sqlite3PagerSetSafetyLevel(Pager*,int,int);
  3967         -static const char *sqlite3PagerFilename(Pager*);
  3968         -static const char *sqlite3PagerDirname(Pager*);
  3969         -static const char *sqlite3PagerJournalname(Pager*);
  3970         -static int sqlite3PagerNosync(Pager*);
  3971         -static int sqlite3PagerMovepage(Pager*,DbPage*,Pgno);
  3972         -static void *sqlite3PagerGetData(DbPage *); 
  3973         -static void *sqlite3PagerGetExtra(DbPage *); 
  3974         -static int sqlite3PagerLockingMode(Pager *, int);
         3975  +SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
         3976  +SQLITE_PRIVATE int sqlite3PagerRef(DbPage*);
         3977  +SQLITE_PRIVATE int sqlite3PagerUnref(DbPage*);
         3978  +SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
         3979  +SQLITE_PRIVATE int sqlite3PagerOverwrite(Pager *pPager, Pgno pgno, void*);
         3980  +SQLITE_PRIVATE int sqlite3PagerPagecount(Pager*);
         3981  +SQLITE_PRIVATE int sqlite3PagerTruncate(Pager*,Pgno);
         3982  +SQLITE_PRIVATE int sqlite3PagerBegin(DbPage*, int exFlag);
         3983  +SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, Pgno);
         3984  +SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
         3985  +SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
         3986  +SQLITE_PRIVATE int sqlite3PagerIsreadonly(Pager*);
         3987  +SQLITE_PRIVATE int sqlite3PagerStmtBegin(Pager*);
         3988  +SQLITE_PRIVATE int sqlite3PagerStmtCommit(Pager*);
         3989  +SQLITE_PRIVATE int sqlite3PagerStmtRollback(Pager*);
         3990  +SQLITE_PRIVATE void sqlite3PagerDontRollback(DbPage*);
         3991  +SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*);
         3992  +SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
         3993  +SQLITE_PRIVATE void sqlite3PagerSetSafetyLevel(Pager*,int,int);
         3994  +SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*);
         3995  +SQLITE_PRIVATE const char *sqlite3PagerDirname(Pager*);
         3996  +SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
         3997  +SQLITE_PRIVATE int sqlite3PagerNosync(Pager*);
         3998  +SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno);
         3999  +SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *); 
         4000  +SQLITE_PRIVATE void *sqlite3PagerGetExtra(DbPage *); 
         4001  +SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int);
  3975   4002   
  3976   4003   #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO)
  3977         -static   int sqlite3PagerReleaseMemory(int);
         4004  +SQLITE_PRIVATE   int sqlite3PagerReleaseMemory(int);
  3978   4005   #endif
  3979   4006   
  3980   4007   #ifdef SQLITE_HAS_CODEC
  3981         -static   void sqlite3PagerSetCodec(Pager*,void*(*)(void*,void*,Pgno,int),void*);
         4008  +SQLITE_PRIVATE   void sqlite3PagerSetCodec(Pager*,void*(*)(void*,void*,Pgno,int),void*);
  3982   4009   #endif
  3983   4010   
  3984   4011   #if !defined(NDEBUG) || defined(SQLITE_TEST)
  3985         -static   Pgno sqlite3PagerPagenumber(DbPage*);
  3986         -static   int sqlite3PagerIswriteable(DbPage*);
         4012  +SQLITE_PRIVATE   Pgno sqlite3PagerPagenumber(DbPage*);
         4013  +SQLITE_PRIVATE   int sqlite3PagerIswriteable(DbPage*);
  3987   4014   #endif
  3988   4015   
  3989   4016   #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
  3990         -static   int sqlite3PagerLockstate(Pager*);
         4017  +SQLITE_PRIVATE   int sqlite3PagerLockstate(Pager*);
  3991   4018   #endif
  3992   4019   
  3993   4020   #ifdef SQLITE_TEST
  3994         -static   int *sqlite3PagerStats(Pager*);
  3995         -static   void sqlite3PagerRefdump(Pager*);
         4021  +SQLITE_PRIVATE   int *sqlite3PagerStats(Pager*);
         4022  +SQLITE_PRIVATE   void sqlite3PagerRefdump(Pager*);
  3996   4023     int pager3_refinfo_enable;
  3997   4024   #endif
  3998   4025   
  3999   4026   #ifdef SQLITE_TEST
  4000   4027   void disable_simulated_io_errors(void);
  4001   4028   void enable_simulated_io_errors(void);
  4002   4029   #else
................................................................................
  4174   4201   #if !defined(OS_UNIX) && !defined(OS_OTHER)
  4175   4202   # define OS_OTHER 0
  4176   4203   # ifndef OS_WIN
  4177   4204   #   if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
  4178   4205   #     define OS_WIN 1
  4179   4206   #     define OS_UNIX 0
  4180   4207   #     define OS_OS2 0
  4181         -#   elif defined(_EMX_) || defined(_OS2) || defined(OS2) || defined(_OS2_) || defined(__OS2__)
         4208  +#   elif defined(__EMX__) || defined(_OS2) || defined(OS2) || defined(_OS2_) || defined(__OS2__)
  4182   4209   #     define OS_WIN 0
  4183   4210   #     define OS_UNIX 0
  4184   4211   #     define OS_OS2 1
  4185   4212   #   else
  4186   4213   #     define OS_WIN 0
  4187   4214   #     define OS_UNIX 1
  4188   4215   #     define OS_OS2 0
................................................................................
  4201   4228   /*
  4202   4229   ** Define the maximum size of a temporary filename
  4203   4230   */
  4204   4231   #if OS_WIN
  4205   4232   # include <windows.h>
  4206   4233   # define SQLITE_TEMPNAME_SIZE (MAX_PATH+50)
  4207   4234   #elif OS_OS2
         4235  +# if (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3) && defined(OS2_HIGH_MEMORY)
         4236  +#  include <os2safe.h> /* has to be included before os2.h for linking to work */
         4237  +# endif
  4208   4238   # define INCL_DOSDATETIME
  4209   4239   # define INCL_DOSFILEMGR
  4210   4240   # define INCL_DOSERRORS
  4211   4241   # define INCL_DOSMISC
  4212   4242   # define INCL_DOSPROCESS
         4243  +# define INCL_DOSMODULEMGR
  4213   4244   # include <os2.h>
  4214   4245   # define SQLITE_TEMPNAME_SIZE (CCHMAXPATHCOMP)
  4215   4246   #else
  4216   4247   # define SQLITE_TEMPNAME_SIZE 200
  4217   4248   #endif
  4218   4249   
  4219   4250   /* If the SET_FULLSYNC macro is not defined above, then make it
................................................................................
  4478   4509   #define RESERVED_BYTE     (PENDING_BYTE+1)
  4479   4510   #define SHARED_FIRST      (PENDING_BYTE+2)
  4480   4511   #define SHARED_SIZE       510
  4481   4512   
  4482   4513   /*
  4483   4514   ** Prototypes for operating system interface routines.
  4484   4515   */
  4485         -static int sqlite3OsClose(OsFile**);
  4486         -static int sqlite3OsOpenDirectory(OsFile*, const char*);
  4487         -static int sqlite3OsRead(OsFile*, void*, int amt);
  4488         -static int sqlite3OsWrite(OsFile*, const void*, int amt);
  4489         -static int sqlite3OsSeek(OsFile*, i64 offset);
  4490         -static int sqlite3OsTruncate(OsFile*, i64 size);
  4491         -static int sqlite3OsSync(OsFile*, int);
  4492         -static void sqlite3OsSetFullSync(OsFile *id, int setting);
  4493         -static int sqlite3OsFileSize(OsFile*, i64 *pSize);
  4494         -static int sqlite3OsLock(OsFile*, int);
  4495         -static int sqlite3OsUnlock(OsFile*, int);
  4496         -static int sqlite3OsCheckReservedLock(OsFile *id);
  4497         -static int sqlite3OsOpenReadWrite(const char*, OsFile**, int*);
  4498         -static int sqlite3OsOpenExclusive(const char*, OsFile**, int);
  4499         -static int sqlite3OsOpenReadOnly(const char*, OsFile**);
  4500         -static int sqlite3OsDelete(const char*);
  4501         -static int sqlite3OsFileExists(const char*);
  4502         -static char *sqlite3OsFullPathname(const char*);
  4503         -static int sqlite3OsIsDirWritable(char*);
  4504         -static int sqlite3OsSyncDirectory(const char*);
  4505         -static int sqlite3OsSectorSize(OsFile *id);
  4506         -static int sqlite3OsTempFileName(char*);
  4507         -static int sqlite3OsRandomSeed(char*);
  4508         -static int sqlite3OsSleep(int ms);
  4509         -static int sqlite3OsCurrentTime(double*);
  4510         -static void sqlite3OsEnterMutex(void);
  4511         -static void sqlite3OsLeaveMutex(void);
  4512         -static int sqlite3OsInMutex(int);
  4513         -static ThreadData *sqlite3OsThreadSpecificData(int);
  4514         -static void *sqlite3OsMalloc(int);
  4515         -static void *sqlite3OsRealloc(void *, int);
  4516         -static void sqlite3OsFree(void *);
  4517         -static int sqlite3OsAllocationSize(void *);
  4518         -static void *sqlite3OsDlopen(const char*);
  4519         -static void *sqlite3OsDlsym(void*, const char*);
  4520         -static int sqlite3OsDlclose(void*);
         4516  +SQLITE_PRIVATE int sqlite3OsClose(OsFile**);
         4517  +SQLITE_PRIVATE int sqlite3OsOpenDirectory(OsFile*, const char*);
         4518  +SQLITE_PRIVATE int sqlite3OsRead(OsFile*, void*, int amt);
         4519  +SQLITE_PRIVATE int sqlite3OsWrite(OsFile*, const void*, int amt);
         4520  +SQLITE_PRIVATE int sqlite3OsSeek(OsFile*, i64 offset);
         4521  +SQLITE_PRIVATE int sqlite3OsTruncate(OsFile*, i64 size);
         4522  +SQLITE_PRIVATE int sqlite3OsSync(OsFile*, int);
         4523  +SQLITE_PRIVATE void sqlite3OsSetFullSync(OsFile *id, int setting);
         4524  +SQLITE_PRIVATE int sqlite3OsFileSize(OsFile*, i64 *pSize);
         4525  +SQLITE_PRIVATE int sqlite3OsLock(OsFile*, int);
         4526  +SQLITE_PRIVATE int sqlite3OsUnlock(OsFile*, int);
         4527  +SQLITE_PRIVATE int sqlite3OsCheckReservedLock(OsFile *id);
         4528  +SQLITE_PRIVATE int sqlite3OsOpenReadWrite(const char*, OsFile**, int*);
         4529  +SQLITE_PRIVATE int sqlite3OsOpenExclusive(const char*, OsFile**, int);
         4530  +SQLITE_PRIVATE int sqlite3OsOpenReadOnly(const char*, OsFile**);
         4531  +SQLITE_PRIVATE int sqlite3OsDelete(const char*);
         4532  +SQLITE_PRIVATE int sqlite3OsFileExists(const char*);
         4533  +SQLITE_PRIVATE char *sqlite3OsFullPathname(const char*);
         4534  +SQLITE_PRIVATE int sqlite3OsIsDirWritable(char*);
         4535  +SQLITE_PRIVATE int sqlite3OsSyncDirectory(const char*);
         4536  +SQLITE_PRIVATE int sqlite3OsSectorSize(OsFile *id);
         4537  +SQLITE_PRIVATE int sqlite3OsTempFileName(char*);
         4538  +SQLITE_PRIVATE int sqlite3OsRandomSeed(char*);
         4539  +SQLITE_PRIVATE int sqlite3OsSleep(int ms);
         4540  +SQLITE_PRIVATE int sqlite3OsCurrentTime(double*);
         4541  +SQLITE_PRIVATE void sqlite3OsEnterMutex(void);
         4542  +SQLITE_PRIVATE void sqlite3OsLeaveMutex(void);
         4543  +SQLITE_PRIVATE int sqlite3OsInMutex(int);
         4544  +SQLITE_PRIVATE ThreadData *sqlite3OsThreadSpecificData(int);
         4545  +SQLITE_PRIVATE void *sqlite3OsMalloc(int);
         4546  +SQLITE_PRIVATE void *sqlite3OsRealloc(void *, int);
         4547  +SQLITE_PRIVATE void sqlite3OsFree(void *);
         4548  +SQLITE_PRIVATE int sqlite3OsAllocationSize(void *);
         4549  +SQLITE_PRIVATE void *sqlite3OsDlopen(const char*);
         4550  +SQLITE_PRIVATE void *sqlite3OsDlsym(void*, const char*);
         4551  +SQLITE_PRIVATE int sqlite3OsDlclose(void*);
  4521   4552   
  4522   4553   #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
  4523         -static   int sqlite3OsFileHandle(OsFile *id);
  4524         -static   int sqlite3OsLockState(OsFile *id);
         4554  +SQLITE_PRIVATE   int sqlite3OsFileHandle(OsFile *id);
         4555  +SQLITE_PRIVATE   int sqlite3OsLockState(OsFile *id);
  4525   4556   #endif
  4526   4557   
  4527   4558   /*
  4528   4559   ** If the SQLITE_ENABLE_REDEF_IO macro is defined, then the OS-layer
  4529   4560   ** interface routines are not called directly but are invoked using
  4530   4561   ** pointers to functions.  This allows the implementation of various
  4531   4562   ** OS-layer interface routines to be modified at run-time.  There are
................................................................................
  4918   4949   ** instance of the following structure, stored in the sqlite3.aModule
  4919   4950   ** hash table.
  4920   4951   */
  4921   4952   struct Module {
  4922   4953     const sqlite3_module *pModule;       /* Callback pointers */
  4923   4954     const char *zName;                   /* Name passed to create_module() */
  4924   4955     void *pAux;                          /* pAux passed to create_module() */
         4956  +  void (*xDestroy)(void *);            /* Module destructor function */
  4925   4957   };
  4926   4958   
  4927   4959   /*
  4928   4960   ** Possible values for FuncDef.flags
  4929   4961   */
  4930   4962   #define SQLITE_FUNC_LIKE   0x01  /* Candidate for the LIKE optimization */
  4931   4963   #define SQLITE_FUNC_CASE   0x02  /* Case-sensitive LIKE-type function */
................................................................................
  4939   4971     char *zName;     /* Name of this column */
  4940   4972     Expr *pDflt;     /* Default value of this column */
  4941   4973     char *zType;     /* Data type for this column */
  4942   4974     char *zColl;     /* Collating sequence.  If NULL, use the default */
  4943   4975     u8 notNull;      /* True if there is a NOT NULL constraint */
  4944   4976     u8 isPrimKey;    /* True if this column is part of the PRIMARY KEY */
  4945   4977     char affinity;   /* One of the SQLITE_AFF_... values */
         4978  +#ifndef SQLITE_OMIT_VIRTUALTABLE
         4979  +  u8 isHidden;     /* True if this column is 'hidden' */
         4980  +#endif
  4946   4981   };
  4947   4982   
  4948   4983   /*
  4949   4984   ** A "Collating Sequence" is defined by an instance of the following
  4950   4985   ** structure. Conceptually, a collating sequence consists of a name and
  4951   4986   ** a comparison routine that defines the order of that sequence.
  4952   4987   **
................................................................................
  5077   5112   
  5078   5113   /*
  5079   5114   ** Test to see whether or not a table is a virtual table.  This is
  5080   5115   ** done as a macro so that it will be optimized out when virtual
  5081   5116   ** table support is omitted from the build.
  5082   5117   */
  5083   5118   #ifndef SQLITE_OMIT_VIRTUALTABLE
  5084         -#  define IsVirtual(X) ((X)->isVirtual)
         5119  +#  define IsVirtual(X)      ((X)->isVirtual)
         5120  +#  define IsHiddenColumn(X) ((X)->isHidden)
  5085   5121   #else
  5086         -#  define IsVirtual(X) 0
         5122  +#  define IsVirtual(X)      0
         5123  +#  define IsHiddenColumn(X) 0
  5087   5124   #endif
  5088   5125   
  5089   5126   /*
  5090   5127   ** Each foreign key constraint is an instance of the following structure.
  5091   5128   **
  5092   5129   ** A foreign key is associated with two tables.  The "from" table is
  5093   5130   ** the table that contains the REFERENCES clause that creates the foreign
................................................................................
  5947   5984   /*
  5948   5985   ** The SQLITE_CORRUPT_BKPT macro can be either a constant (for production
  5949   5986   ** builds) or a function call (for debugging).  If it is a function call,
  5950   5987   ** it allows the operator to set a breakpoint at the spot where database
  5951   5988   ** corruption is first detected.
  5952   5989   */
  5953   5990   #ifdef SQLITE_DEBUG
  5954         -static   int sqlite3Corrupt(void);
         5991  +SQLITE_PRIVATE   int sqlite3Corrupt(void);
  5955   5992   # define SQLITE_CORRUPT_BKPT sqlite3Corrupt()
  5956   5993   #else
  5957   5994   # define SQLITE_CORRUPT_BKPT SQLITE_CORRUPT
  5958   5995   #endif
  5959   5996   
  5960   5997   /*
  5961   5998   ** Internal function prototypes
  5962   5999   */
  5963         -static int sqlite3StrICmp(const char *, const char *);
  5964         -static int sqlite3StrNICmp(const char *, const char *, int);
  5965         -static int sqlite3IsNumber(const char*, int*, u8);
         6000  +SQLITE_PRIVATE int sqlite3StrICmp(const char *, const char *);
         6001  +SQLITE_PRIVATE int sqlite3StrNICmp(const char *, const char *, int);
         6002  +SQLITE_PRIVATE int sqlite3IsNumber(const char*, int*, u8);
  5966   6003   
  5967         -static void *sqlite3Malloc(int,int);
  5968         -static void *sqlite3MallocRaw(int,int);
  5969         -static void *sqlite3Realloc(void*,int);
  5970         -static char *sqlite3StrDup(const char*);
  5971         -static char *sqlite3StrNDup(const char*, int);
         6004  +SQLITE_PRIVATE void *sqlite3Malloc(int,int);
         6005  +SQLITE_PRIVATE void *sqlite3MallocRaw(int,int);
         6006  +SQLITE_PRIVATE void *sqlite3Realloc(void*,int);
         6007  +SQLITE_PRIVATE char *sqlite3StrDup(const char*);
         6008  +SQLITE_PRIVATE char *sqlite3StrNDup(const char*, int);
  5972   6009   # define sqlite3CheckMemory(a,b)
  5973         -static void *sqlite3ReallocOrFree(void*,int);
  5974         -static void sqlite3FreeX(void*);
  5975         -static void *sqlite3MallocX(int);
         6010  +SQLITE_PRIVATE void *sqlite3ReallocOrFree(void*,int);
         6011  +SQLITE_PRIVATE void sqlite3FreeX(void*);
         6012  +SQLITE_PRIVATE void *sqlite3MallocX(int);
  5976   6013   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
  5977         -static   int sqlite3AllocSize(void *);
         6014  +SQLITE_PRIVATE   int sqlite3AllocSize(void *);
  5978   6015   #endif
  5979   6016   
  5980         -static char *sqlite3MPrintf(const char*, ...);
  5981         -static char *sqlite3VMPrintf(const char*, va_list);
         6017  +SQLITE_PRIVATE char *sqlite3MPrintf(const char*, ...);
         6018  +SQLITE_PRIVATE char *sqlite3VMPrintf(const char*, va_list);
  5982   6019   #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
  5983         -static   void sqlite3DebugPrintf(const char*, ...);
  5984         -static   void *sqlite3TextToPtr(const char*);
  5985         -#endif
  5986         -static void sqlite3SetString(char **, ...);
  5987         -static void sqlite3ErrorMsg(Parse*, const char*, ...);
  5988         -static void sqlite3ErrorClear(Parse*);
  5989         -static void sqlite3Dequote(char*);
  5990         -static void sqlite3DequoteExpr(Expr*);
  5991         -static int sqlite3KeywordCode(const unsigned char*, int);
  5992         -static int sqlite3RunParser(Parse*, const char*, char **);
  5993         -static void sqlite3FinishCoding(Parse*);
  5994         -static Expr *sqlite3Expr(int, Expr*, Expr*, const Token*);
  5995         -static Expr *sqlite3ExprOrFree(int, Expr*, Expr*, const Token*);
  5996         -static Expr *sqlite3RegisterExpr(Parse*,Token*);
  5997         -static Expr *sqlite3ExprAnd(Expr*, Expr*);
  5998         -static void sqlite3ExprSpan(Expr*,Token*,Token*);
  5999         -static Expr *sqlite3ExprFunction(ExprList*, Token*);
  6000         -static void sqlite3ExprAssignVarNumber(Parse*, Expr*);
  6001         -static void sqlite3ExprDelete(Expr*);
  6002         -static ExprList *sqlite3ExprListAppend(ExprList*,Expr*,Token*);
  6003         -static void sqlite3ExprListDelete(ExprList*);
  6004         -static int sqlite3Init(sqlite3*, char**);
  6005         -static int sqlite3InitCallback(void*, int, char**, char**);
  6006         -static void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
  6007         -static void sqlite3ResetInternalSchema(sqlite3*, int);
  6008         -static void sqlite3BeginParse(Parse*,int);
  6009         -static void sqlite3CommitInternalChanges(sqlite3*);
  6010         -static Table *sqlite3ResultSetOfSelect(Parse*,char*,Select*);
  6011         -static void sqlite3OpenMasterTable(Parse *, int);
  6012         -static void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
  6013         -static void sqlite3AddColumn(Parse*,Token*);
  6014         -static void sqlite3AddNotNull(Parse*, int);
  6015         -static void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
  6016         -static void sqlite3AddCheckConstraint(Parse*, Expr*);
  6017         -static void sqlite3AddColumnType(Parse*,Token*);
  6018         -static void sqlite3AddDefaultValue(Parse*,Expr*);
  6019         -static void sqlite3AddCollateType(Parse*, const char*, int);
  6020         -static void sqlite3EndTable(Parse*,Token*,Token*,Select*);
  6021         -
  6022         -static void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int,int);
         6020  +SQLITE_PRIVATE   void sqlite3DebugPrintf(const char*, ...);
         6021  +SQLITE_PRIVATE   void *sqlite3TextToPtr(const char*);
         6022  +#endif
         6023  +SQLITE_PRIVATE void sqlite3SetString(char **, ...);
         6024  +SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
         6025  +SQLITE_PRIVATE void sqlite3ErrorClear(Parse*);
         6026  +SQLITE_PRIVATE void sqlite3Dequote(char*);
         6027  +SQLITE_PRIVATE void sqlite3DequoteExpr(Expr*);
         6028  +SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int);
         6029  +SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **);
         6030  +SQLITE_PRIVATE void sqlite3FinishCoding(Parse*);
         6031  +SQLITE_PRIVATE Expr *sqlite3Expr(int, Expr*, Expr*, const Token*);
         6032  +SQLITE_PRIVATE Expr *sqlite3ExprOrFree(int, Expr*, Expr*, const Token*);
         6033  +SQLITE_PRIVATE Expr *sqlite3RegisterExpr(Parse*,Token*);
         6034  +SQLITE_PRIVATE Expr *sqlite3ExprAnd(Expr*, Expr*);
         6035  +SQLITE_PRIVATE void sqlite3ExprSpan(Expr*,Token*,Token*);
         6036  +SQLITE_PRIVATE Expr *sqlite3ExprFunction(ExprList*, Token*);
         6037  +SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*);
         6038  +SQLITE_PRIVATE void sqlite3ExprDelete(Expr*);
         6039  +SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(ExprList*,Expr*,Token*);
         6040  +SQLITE_PRIVATE void sqlite3ExprListDelete(ExprList*);
         6041  +SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
         6042  +SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
         6043  +SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
         6044  +SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3*, int);
         6045  +SQLITE_PRIVATE void sqlite3BeginParse(Parse*,int);
         6046  +SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
         6047  +SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,char*,Select*);
         6048  +SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int);
         6049  +SQLITE_PRIVATE void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
         6050  +SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*);
         6051  +SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int);
         6052  +SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
         6053  +SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*);
         6054  +SQLITE_PRIVATE void sqlite3AddColumnType(Parse*,Token*);
         6055  +SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*);
         6056  +SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, const char*, int);
         6057  +SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,Select*);
         6058  +
         6059  +SQLITE_PRIVATE void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int,int);
  6023   6060   
  6024   6061   #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
  6025         -static   int sqlite3ViewGetColumnNames(Parse*,Table*);
         6062  +SQLITE_PRIVATE   int sqlite3ViewGetColumnNames(Parse*,Table*);
  6026   6063   #else
  6027   6064   # define sqlite3ViewGetColumnNames(A,B) 0
  6028   6065   #endif
  6029   6066   
  6030         -static void sqlite3DropTable(Parse*, SrcList*, int, int);
  6031         -static void sqlite3DeleteTable(Table*);
  6032         -static void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
  6033         -static void *sqlite3ArrayAllocate(void*,int,int,int*,int*,int*);
  6034         -static IdList *sqlite3IdListAppend(IdList*, Token*);
  6035         -static int sqlite3IdListIndex(IdList*,const char*);
  6036         -static SrcList *sqlite3SrcListAppend(SrcList*, Token*, Token*);
  6037         -static SrcList *sqlite3SrcListAppendFromTerm(SrcList*, Token*, Token*, Token*,
         6067  +SQLITE_PRIVATE void sqlite3DropTable(Parse*, SrcList*, int, int);
         6068  +SQLITE_PRIVATE void sqlite3DeleteTable(Table*);
         6069  +SQLITE_PRIVATE void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int);
         6070  +SQLITE_PRIVATE void *sqlite3ArrayAllocate(void*,int,int,int*,int*,int*);
         6071  +SQLITE_PRIVATE IdList *sqlite3IdListAppend(IdList*, Token*);
         6072  +SQLITE_PRIVATE int sqlite3IdListIndex(IdList*,const char*);
         6073  +SQLITE_PRIVATE SrcList *sqlite3SrcListAppend(SrcList*, Token*, Token*);
         6074  +SQLITE_PRIVATE SrcList *sqlite3SrcListAppendFromTerm(SrcList*, Token*, Token*, Token*,
  6038   6075                                         Select*, Expr*, IdList*);
  6039         -static void sqlite3SrcListShiftJoinType(SrcList*);
  6040         -static void sqlite3SrcListAssignCursors(Parse*, SrcList*);
  6041         -static void sqlite3IdListDelete(IdList*);
  6042         -static void sqlite3SrcListDelete(SrcList*);
  6043         -static void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
         6076  +SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList*);
         6077  +SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse*, SrcList*);
         6078  +SQLITE_PRIVATE void sqlite3IdListDelete(IdList*);
         6079  +SQLITE_PRIVATE void sqlite3SrcListDelete(SrcList*);
         6080  +SQLITE_PRIVATE void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
  6044   6081                           Token*, int, int);
  6045         -static void sqlite3DropIndex(Parse*, SrcList*, int);
  6046         -static int sqlite3Select(Parse*, Select*, int, int, Select*, int, int*, char *aff);
  6047         -static Select *sqlite3SelectNew(ExprList*,SrcList*,Expr*,ExprList*,Expr*,ExprList*,
         6082  +SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
         6083  +SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, int, int, Select*, int, int*, char *aff);
         6084  +SQLITE_PRIVATE Select *sqlite3SelectNew(ExprList*,SrcList*,Expr*,ExprList*,Expr*,ExprList*,
  6048   6085                           int,Expr*,Expr*);
  6049         -static void sqlite3SelectDelete(Select*);
  6050         -static Table *sqlite3SrcListLookup(Parse*, SrcList*);
  6051         -static int sqlite3IsReadOnly(Parse*, Table*, int);
  6052         -static void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
  6053         -static void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
  6054         -static void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
  6055         -static WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**);
  6056         -static void sqlite3WhereEnd(WhereInfo*);
  6057         -static void sqlite3ExprCodeGetColumn(Vdbe*, Table*, int, int);
  6058         -static void sqlite3ExprCode(Parse*, Expr*);
  6059         -static void sqlite3ExprCodeAndCache(Parse*, Expr*);
  6060         -static int sqlite3ExprCodeExprList(Parse*, ExprList*);
  6061         -static void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
  6062         -static void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
  6063         -static Table *sqlite3FindTable(sqlite3*,const char*, const char*);
  6064         -static Table *sqlite3LocateTable(Parse*,const char*, const char*);
  6065         -static Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
  6066         -static void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
  6067         -static void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
  6068         -static void sqlite3Vacuum(Parse*);
  6069         -static int sqlite3RunVacuum(char**, sqlite3*);
  6070         -static char *sqlite3NameFromToken(Token*);
  6071         -static int sqlite3ExprCompare(Expr*, Expr*);
         6086  +SQLITE_PRIVATE void sqlite3SelectDelete(Select*);
         6087  +SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*);
         6088  +SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, int);
         6089  +SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
         6090  +SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
         6091  +SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
         6092  +SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**);
         6093  +SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*);
         6094  +SQLITE_PRIVATE void sqlite3ExprCodeGetColumn(Vdbe*, Table*, int, int);
         6095  +SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*);
         6096  +SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*);
         6097  +SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*);
         6098  +SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
         6099  +SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
         6100  +SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
         6101  +SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,const char*, const char*);
         6102  +SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
         6103  +SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
         6104  +SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
         6105  +SQLITE_PRIVATE void sqlite3Vacuum(Parse*);
         6106  +SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*);
         6107  +SQLITE_PRIVATE char *sqlite3NameFromToken(Token*);
         6108  +SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*);
  6072   6109   int sqliteFuncId(Token*);
  6073         -static int sqlite3ExprResolveNames(NameContext *, Expr *);
  6074         -static int sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
  6075         -static int sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
  6076         -static Vdbe *sqlite3GetVdbe(Parse*);
  6077         -static Expr *sqlite3CreateIdExpr(const char*);
  6078         -static void sqlite3Randomness(int, void*);
  6079         -static void sqlite3RollbackAll(sqlite3*);
  6080         -static void sqlite3CodeVerifySchema(Parse*, int);
  6081         -static void sqlite3BeginTransaction(Parse*, int);
  6082         -static void sqlite3CommitTransaction(Parse*);
  6083         -static void sqlite3RollbackTransaction(Parse*);
  6084         -static int sqlite3ExprIsConstant(Expr*);
  6085         -static int sqlite3ExprIsConstantNotJoin(Expr*);
  6086         -static int sqlite3ExprIsConstantOrFunction(Expr*);
  6087         -static int sqlite3ExprIsInteger(Expr*, int*);
  6088         -static int sqlite3IsRowid(const char*);
  6089         -static void sqlite3GenerateRowDelete(sqlite3*, Vdbe*, Table*, int, int);
  6090         -static void sqlite3GenerateRowIndexDelete(Vdbe*, Table*, int, char*);
  6091         -static void sqlite3GenerateIndexKey(Vdbe*, Index*, int);
  6092         -static void sqlite3GenerateConstraintChecks(Parse*,Table*,int,char*,int,int,int,int);
  6093         -static void sqlite3CompleteInsertion(Parse*, Table*, int, char*, int, int, int, int);
  6094         -static void sqlite3OpenTableAndIndices(Parse*, Table*, int, int);
  6095         -static void sqlite3BeginWriteOperation(Parse*, int, int);
  6096         -static Expr *sqlite3ExprDup(Expr*);
  6097         -static void sqlite3TokenCopy(Token*, Token*);
  6098         -static ExprList *sqlite3ExprListDup(ExprList*);
  6099         -static SrcList *sqlite3SrcListDup(SrcList*);
  6100         -static IdList *sqlite3IdListDup(IdList*);
  6101         -static Select *sqlite3SelectDup(Select*);
  6102         -static FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,int);
  6103         -static void sqlite3RegisterBuiltinFunctions(sqlite3*);
  6104         -static void sqlite3RegisterDateTimeFunctions(sqlite3*);
  6105         -static int sqlite3SafetyOn(sqlite3*);
  6106         -static int sqlite3SafetyOff(sqlite3*);
  6107         -static int sqlite3SafetyCheck(sqlite3*);
  6108         -static void sqlite3ChangeCookie(sqlite3*, Vdbe*, int);
  6109         -
  6110         -#ifndef SQLITE_OMIT_TRIGGER
  6111         -static   void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,SrcList*,
         6110  +SQLITE_PRIVATE int sqlite3ExprResolveNames(NameContext *, Expr *);
         6111  +SQLITE_PRIVATE int sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
         6112  +SQLITE_PRIVATE int sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
         6113  +SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
         6114  +SQLITE_PRIVATE Expr *sqlite3CreateIdExpr(const char*);
         6115  +SQLITE_PRIVATE void sqlite3Randomness(int, void*);
         6116  +SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*);
         6117  +SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int);
         6118  +SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int);
         6119  +SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*);
         6120  +SQLITE_PRIVATE void sqlite3RollbackTransaction(Parse*);
         6121  +SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
         6122  +SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
         6123  +SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*);
         6124  +SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
         6125  +SQLITE_PRIVATE int sqlite3IsRowid(const char*);
         6126  +SQLITE_PRIVATE void sqlite3GenerateRowDelete(sqlite3*, Vdbe*, Table*, int, int);
         6127  +SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Vdbe*, Table*, int, char*);
         6128  +SQLITE_PRIVATE void sqlite3GenerateIndexKey(Vdbe*, Index*, int);
         6129  +SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int,char*,int,int,int,int);
         6130  +SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*, Table*, int, char*, int, int, int, int);
         6131  +SQLITE_PRIVATE void sqlite3OpenTableAndIndices(Parse*, Table*, int, int);
         6132  +SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int);
         6133  +SQLITE_PRIVATE Expr *sqlite3ExprDup(Expr*);
         6134  +SQLITE_PRIVATE void sqlite3TokenCopy(Token*, Token*);
         6135  +SQLITE_PRIVATE ExprList *sqlite3ExprListDup(ExprList*);
         6136  +SQLITE_PRIVATE SrcList *sqlite3SrcListDup(SrcList*);
         6137  +SQLITE_PRIVATE IdList *sqlite3IdListDup(IdList*);
         6138  +SQLITE_PRIVATE Select *sqlite3SelectDup(Select*);
         6139  +SQLITE_PRIVATE FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,int);
         6140  +SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(sqlite3*);
         6141  +SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(sqlite3*);
         6142  +SQLITE_PRIVATE int sqlite3SafetyOn(sqlite3*);
         6143  +SQLITE_PRIVATE int sqlite3SafetyOff(sqlite3*);
         6144  +SQLITE_PRIVATE int sqlite3SafetyCheck(sqlite3*);
         6145  +SQLITE_PRIVATE void sqlite3ChangeCookie(sqlite3*, Vdbe*, int);
         6146  +
         6147  +#ifndef SQLITE_OMIT_TRIGGER
         6148  +SQLITE_PRIVATE   void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,SrcList*,
  6112   6149                              Expr*,int, int);
  6113         -static   void sqlite3FinishTrigger(Parse*, TriggerStep*, Token*);
  6114         -static   void sqlite3DropTrigger(Parse*, SrcList*, int);
  6115         -static   void sqlite3DropTriggerPtr(Parse*, Trigger*);
  6116         -static   int sqlite3TriggersExist(Parse*, Table*, int, ExprList*);
  6117         -static   int sqlite3CodeRowTrigger(Parse*, int, ExprList*, int, Table *, int, int, 
         6150  +SQLITE_PRIVATE   void sqlite3FinishTrigger(Parse*, TriggerStep*, Token*);
         6151  +SQLITE_PRIVATE   void sqlite3DropTrigger(Parse*, SrcList*, int);
         6152  +SQLITE_PRIVATE   void sqlite3DropTriggerPtr(Parse*, Trigger*);
         6153  +SQLITE_PRIVATE   int sqlite3TriggersExist(Parse*, Table*, int, ExprList*);
         6154  +SQLITE_PRIVATE   int sqlite3CodeRowTrigger(Parse*, int, ExprList*, int, Table *, int, int, 
  6118   6155                              int, int);
  6119   6156     void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
  6120         -static   void sqlite3DeleteTriggerStep(TriggerStep*);
  6121         -static   TriggerStep *sqlite3TriggerSelectStep(Select*);
  6122         -static   TriggerStep *sqlite3TriggerInsertStep(Token*, IdList*, ExprList*,Select*,int);
  6123         -static   TriggerStep *sqlite3TriggerUpdateStep(Token*, ExprList*, Expr*, int);
  6124         -static   TriggerStep *sqlite3TriggerDeleteStep(Token*, Expr*);
  6125         -static   void sqlite3DeleteTrigger(Trigger*);
  6126         -static   void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*);
         6157  +SQLITE_PRIVATE   void sqlite3DeleteTriggerStep(TriggerStep*);
         6158  +SQLITE_PRIVATE   TriggerStep *sqlite3TriggerSelectStep(Select*);
         6159  +SQLITE_PRIVATE   TriggerStep *sqlite3TriggerInsertStep(Token*, IdList*, ExprList*,Select*,int);
         6160  +SQLITE_PRIVATE   TriggerStep *sqlite3TriggerUpdateStep(Token*, ExprList*, Expr*, int);
         6161  +SQLITE_PRIVATE   TriggerStep *sqlite3TriggerDeleteStep(Token*, Expr*);
         6162  +SQLITE_PRIVATE   void sqlite3DeleteTrigger(Trigger*);
         6163  +SQLITE_PRIVATE   void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*);
  6127   6164   #else
  6128   6165   # define sqlite3TriggersExist(A,B,C,D,E,F) 0
  6129   6166   # define sqlite3DeleteTrigger(A)
  6130   6167   # define sqlite3DropTriggerPtr(A,B)
  6131   6168   # define sqlite3UnlinkAndDeleteTrigger(A,B,C)
  6132   6169   # define sqlite3CodeRowTrigger(A,B,C,D,E,F,G,H,I) 0
  6133   6170   #endif
  6134   6171   
  6135         -static int sqlite3JoinType(Parse*, Token*, Token*, Token*);
  6136         -static void sqlite3CreateForeignKey(Parse*, ExprList*, Token*, ExprList*, int);
  6137         -static void sqlite3DeferForeignKey(Parse*, int);
         6172  +SQLITE_PRIVATE int sqlite3JoinType(Parse*, Token*, Token*, Token*);
         6173  +SQLITE_PRIVATE void sqlite3CreateForeignKey(Parse*, ExprList*, Token*, ExprList*, int);
         6174  +SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse*, int);
  6138   6175   #ifndef SQLITE_OMIT_AUTHORIZATION
  6139         -static   void sqlite3AuthRead(Parse*,Expr*,SrcList*);
  6140         -static   int sqlite3AuthCheck(Parse*,int, const char*, const char*, const char*);
  6141         -static   void sqlite3AuthContextPush(Parse*, AuthContext*, const char*);
  6142         -static   void sqlite3AuthContextPop(AuthContext*);
         6176  +SQLITE_PRIVATE   void sqlite3AuthRead(Parse*,Expr*,SrcList*);
         6177  +SQLITE_PRIVATE   int sqlite3AuthCheck(Parse*,int, const char*, const char*, const char*);
         6178  +SQLITE_PRIVATE   void sqlite3AuthContextPush(Parse*, AuthContext*, const char*);
         6179  +SQLITE_PRIVATE   void sqlite3AuthContextPop(AuthContext*);
  6143   6180   #else
  6144   6181   # define sqlite3AuthRead(a,b,c)
  6145   6182   # define sqlite3AuthCheck(a,b,c,d,e)    SQLITE_OK
  6146   6183   # define sqlite3AuthContextPush(a,b,c)
  6147   6184   # define sqlite3AuthContextPop(a)  ((void)(a))
  6148   6185   #endif
  6149         -static void sqlite3Attach(Parse*, Expr*, Expr*, Expr*);
  6150         -static void sqlite3Detach(Parse*, Expr*);
  6151         -static int sqlite3BtreeFactory(const sqlite3 *db, const char *zFilename,
         6186  +SQLITE_PRIVATE void sqlite3Attach(Parse*, Expr*, Expr*, Expr*);
         6187  +SQLITE_PRIVATE void sqlite3Detach(Parse*, Expr*);
         6188  +SQLITE_PRIVATE int sqlite3BtreeFactory(const sqlite3 *db, const char *zFilename,
  6152   6189                          int omitJournal, int nCache, Btree **ppBtree);
  6153         -static int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*);
  6154         -static int sqlite3FixSrcList(DbFixer*, SrcList*);
  6155         -static int sqlite3FixSelect(DbFixer*, Select*);
  6156         -static int sqlite3FixExpr(DbFixer*, Expr*);
  6157         -static int sqlite3FixExprList(DbFixer*, ExprList*);
  6158         -static int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
  6159         -static int sqlite3AtoF(const char *z, double*);
  6160         -char *sqlite3_snprintf(int,char*,const char*,...);
  6161         -static int sqlite3GetInt32(const char *, int*);
  6162         -static int sqlite3FitsIn64Bits(const char *);
  6163         -static int sqlite3Utf16ByteLen(const void *pData, int nChar);
  6164         -static int sqlite3Utf8CharLen(const char *pData, int nByte);
  6165         -static u32 sqlite3ReadUtf8(const unsigned char *);
  6166         -static int sqlite3PutVarint(unsigned char *, u64);
  6167         -static int sqlite3GetVarint(const unsigned char *, u64 *);
  6168         -static int sqlite3GetVarint32(const unsigned char *, u32 *);
  6169         -static int sqlite3VarintLen(u64 v);
  6170         -static void sqlite3IndexAffinityStr(Vdbe *, Index *);
  6171         -static void sqlite3TableAffinityStr(Vdbe *, Table *);
  6172         -static char sqlite3CompareAffinity(Expr *pExpr, char aff2);
  6173         -static int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
  6174         -static char sqlite3ExprAffinity(Expr *pExpr);
  6175         -static int sqlite3Atoi64(const char*, i64*);
  6176         -static void sqlite3Error(sqlite3*, int, const char*,...);
  6177         -static void *sqlite3HexToBlob(const char *z);
  6178         -static int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
  6179         -static const char *sqlite3ErrStr(int);
  6180         -static int sqlite3ReadSchema(Parse *pParse);
  6181         -static CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char *,int,int);
  6182         -static CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName);
  6183         -static CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr);
  6184         -static Expr *sqlite3ExprSetColl(Parse *pParse, Expr *, Token *);
  6185         -static int sqlite3CheckCollSeq(Parse *, CollSeq *);
  6186         -static int sqlite3CheckObjectName(Parse *, const char *);
  6187         -static void sqlite3VdbeSetChanges(sqlite3 *, int);
  6188         -static void sqlite3Utf16Substr(sqlite3_context *,int,sqlite3_value **);
  6189         -
  6190         -static const void *sqlite3ValueText(sqlite3_value*, u8);
  6191         -static int sqlite3ValueBytes(sqlite3_value*, u8);
  6192         -static void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, void(*)(void*));
  6193         -static void sqlite3ValueFree(sqlite3_value*);
  6194         -static sqlite3_value *sqlite3ValueNew(void);
  6195         -static char *sqlite3Utf16to8(const void*, int);
  6196         -static int sqlite3ValueFromExpr(Expr *, u8, u8, sqlite3_value **);
  6197         -static void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
         6190  +SQLITE_PRIVATE int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*);
         6191  +SQLITE_PRIVATE int sqlite3FixSrcList(DbFixer*, SrcList*);
         6192  +SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*);
         6193  +SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*);
         6194  +SQLITE_PRIVATE int sqlite3FixExprList(DbFixer*, ExprList*);
         6195  +SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
         6196  +SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*);
         6197  +SQLITE_API char *sqlite3_snprintf(int,char*,const char*,...);
         6198  +SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
         6199  +SQLITE_PRIVATE int sqlite3FitsIn64Bits(const char *);
         6200  +SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nChar);
         6201  +SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte);
         6202  +SQLITE_PRIVATE u32 sqlite3ReadUtf8(const unsigned char *);
         6203  +SQLITE_PRIVATE int sqlite3PutVarint(unsigned char *, u64);
         6204  +SQLITE_PRIVATE int sqlite3GetVarint(const unsigned char *, u64 *);
         6205  +SQLITE_PRIVATE int sqlite3GetVarint32(const unsigned char *, u32 *);
         6206  +SQLITE_PRIVATE int sqlite3VarintLen(u64 v);
         6207  +SQLITE_PRIVATE void sqlite3IndexAffinityStr(Vdbe *, Index *);
         6208  +SQLITE_PRIVATE void sqlite3TableAffinityStr(Vdbe *, Table *);
         6209  +SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
         6210  +SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
         6211  +SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
         6212  +SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*);
         6213  +SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...);
         6214  +SQLITE_PRIVATE void *sqlite3HexToBlob(const char *z);
         6215  +SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
         6216  +SQLITE_PRIVATE const char *sqlite3ErrStr(int);
         6217  +SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
         6218  +SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char *,int,int);
         6219  +SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName);
         6220  +SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr);
         6221  +SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Parse *pParse, Expr *, Token *);
         6222  +SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *);
         6223  +SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *);
         6224  +SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int);
         6225  +SQLITE_PRIVATE void sqlite3Utf16Substr(sqlite3_context *,int,sqlite3_value **);
         6226  +
         6227  +SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
         6228  +SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
         6229  +SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, void(*)(void*));
         6230  +SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*);
         6231  +SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(void);
         6232  +SQLITE_PRIVATE char *sqlite3Utf16to8(const void*, int);
         6233  +SQLITE_PRIVATE int sqlite3ValueFromExpr(Expr *, u8, u8, sqlite3_value **);
         6234  +SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
  6198   6235   extern const unsigned char sqlite3UpperToLower[];
  6199         -static void sqlite3RootPageMoved(Db*, int, int);
  6200         -static void sqlite3Reindex(Parse*, Token*, Token*);
  6201         -static void sqlite3AlterFunctions(sqlite3*);
  6202         -static void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
  6203         -static int sqlite3GetToken(const unsigned char *, int *);
  6204         -static void sqlite3NestedParse(Parse*, const char*, ...);
  6205         -static void sqlite3ExpirePreparedStatements(sqlite3*);
  6206         -static void sqlite3CodeSubselect(Parse *, Expr *);
  6207         -static int sqlite3SelectResolve(Parse *, Select *, NameContext *);
  6208         -static void sqlite3ColumnDefault(Vdbe *, Table *, int);
  6209         -static void sqlite3AlterFinishAddColumn(Parse *, Token *);
  6210         -static void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
  6211         -static CollSeq *sqlite3GetCollSeq(sqlite3*, CollSeq *, const char *, int);
  6212         -static char sqlite3AffinityType(const Token*);
  6213         -static void sqlite3Analyze(Parse*, Token*, Token*);
  6214         -static int sqlite3InvokeBusyHandler(BusyHandler*);
  6215         -static int sqlite3FindDb(sqlite3*, Token*);
  6216         -static int sqlite3AnalysisLoad(sqlite3*,int iDB);
  6217         -static void sqlite3DefaultRowEst(Index*);
  6218         -static void sqlite3RegisterLikeFunctions(sqlite3*, int);
  6219         -static int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
  6220         -static ThreadData *sqlite3ThreadData(void);
  6221         -static const ThreadData *sqlite3ThreadDataReadOnly(void);
  6222         -static void sqlite3ReleaseThreadData(void);
  6223         -static void sqlite3AttachFunctions(sqlite3 *);
  6224         -static void sqlite3MinimumFileFormat(Parse*, int, int);
  6225         -static void sqlite3SchemaFree(void *);
  6226         -static Schema *sqlite3SchemaGet(Btree *);
  6227         -static int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
  6228         -static KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *);
  6229         -static int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *, 
         6236  +SQLITE_PRIVATE void sqlite3RootPageMoved(Db*, int, int);
         6237  +SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*);
         6238  +SQLITE_PRIVATE void sqlite3AlterFunctions(sqlite3*);
         6239  +SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
         6240  +SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *);
         6241  +SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
         6242  +SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*);
         6243  +SQLITE_PRIVATE void sqlite3CodeSubselect(Parse *, Expr *);
         6244  +SQLITE_PRIVATE int sqlite3SelectResolve(Parse *, Select *, NameContext *);
         6245  +SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *, Table *, int);
         6246  +SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *, Token *);
         6247  +SQLITE_PRIVATE void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
         6248  +SQLITE_PRIVATE CollSeq *sqlite3GetCollSeq(sqlite3*, CollSeq *, const char *, int);
         6249  +SQLITE_PRIVATE char sqlite3AffinityType(const Token*);
         6250  +SQLITE_PRIVATE void sqlite3Analyze(Parse*, Token*, Token*);
         6251  +SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler*);
         6252  +SQLITE_PRIVATE int sqlite3FindDb(sqlite3*, Token*);
         6253  +SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3*,int iDB);
         6254  +SQLITE_PRIVATE void sqlite3DefaultRowEst(Index*);
         6255  +SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3*, int);
         6256  +SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*);
         6257  +SQLITE_PRIVATE ThreadData *sqlite3ThreadData(void);
         6258  +SQLITE_PRIVATE const ThreadData *sqlite3ThreadDataReadOnly(void);
         6259  +SQLITE_PRIVATE void sqlite3ReleaseThreadData(void);
         6260  +SQLITE_PRIVATE void sqlite3AttachFunctions(sqlite3 *);
         6261  +SQLITE_PRIVATE void sqlite3MinimumFileFormat(Parse*, int, int);
         6262  +SQLITE_PRIVATE void sqlite3SchemaFree(void *);
         6263  +SQLITE_PRIVATE Schema *sqlite3SchemaGet(Btree *);
         6264  +SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *);
         6265  +SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *);
         6266  +SQLITE_PRIVATE int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *, 
  6230   6267     void (*)(sqlite3_context*,int,sqlite3_value **),
  6231   6268     void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*));
  6232         -static int sqlite3ApiExit(sqlite3 *db, int);
  6233         -static void sqlite3FailedMalloc(void);
  6234         -static void sqlite3AbortOtherActiveVdbes(sqlite3 *, Vdbe *);
  6235         -static int sqlite3OpenTempDatabase(Parse *);
         6269  +SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
         6270  +SQLITE_PRIVATE void sqlite3FailedMalloc(void);
         6271  +SQLITE_PRIVATE void sqlite3AbortOtherActiveVdbes(sqlite3 *, Vdbe *);
         6272  +SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
  6236   6273   
  6237   6274   #ifndef SQLITE_OMIT_LOAD_EXTENSION
  6238         -static   void sqlite3CloseExtensions(sqlite3*);
  6239         -static   int sqlite3AutoLoadExtensions(sqlite3*);
         6275  +SQLITE_PRIVATE   void sqlite3CloseExtensions(sqlite3*);
         6276  +SQLITE_PRIVATE   int sqlite3AutoLoadExtensions(sqlite3*);
  6240   6277   #else
  6241   6278   # define sqlite3CloseExtensions(X)
  6242   6279   # define sqlite3AutoLoadExtensions(X)  SQLITE_OK
  6243   6280   #endif
  6244   6281   
  6245   6282   #ifndef SQLITE_OMIT_SHARED_CACHE
  6246         -static   void sqlite3TableLock(Parse *, int, int, u8, const char *);
         6283  +SQLITE_PRIVATE   void sqlite3TableLock(Parse *, int, int, u8, const char *);
  6247   6284   #else
  6248   6285     #define sqlite3TableLock(v,w,x,y,z)
  6249   6286   #endif
  6250   6287   
  6251   6288   #ifdef SQLITE_TEST
  6252         -static   int sqlite3Utf8To8(unsigned char*);
         6289  +SQLITE_PRIVATE   int sqlite3Utf8To8(unsigned char*);
  6253   6290   #endif
  6254   6291   
  6255   6292   #ifdef SQLITE_MEMDEBUG
  6256         -static   void sqlite3MallocDisallow(void);
  6257         -static   void sqlite3MallocAllow(void);
  6258         -static   int sqlite3TestMallocFail(void);
         6293  +SQLITE_PRIVATE   void sqlite3MallocDisallow(void);
         6294  +SQLITE_PRIVATE   void sqlite3MallocAllow(void);
         6295  +SQLITE_PRIVATE   int sqlite3TestMallocFail(void);
  6259   6296   #else
  6260   6297     #define sqlite3TestMallocFail() 0
  6261   6298     #define sqlite3MallocDisallow()
  6262   6299     #define sqlite3MallocAllow()
  6263   6300   #endif
  6264   6301   
  6265   6302   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
  6266         -static   void *sqlite3ThreadSafeMalloc(int);
  6267         -static   void sqlite3ThreadSafeFree(void *);
         6303  +SQLITE_PRIVATE   void *sqlite3ThreadSafeMalloc(int);
         6304  +SQLITE_PRIVATE   void sqlite3ThreadSafeFree(void *);
  6268   6305   #else
  6269   6306     #define sqlite3ThreadSafeMalloc sqlite3MallocX
  6270   6307     #define sqlite3ThreadSafeFree sqlite3FreeX
  6271   6308   #endif
  6272   6309   
  6273   6310   #ifdef SQLITE_OMIT_VIRTUALTABLE
  6274   6311   #  define sqlite3VtabClear(X)
  6275   6312   #  define sqlite3VtabSync(X,Y) (Y)
  6276   6313   #  define sqlite3VtabRollback(X)
  6277   6314   #  define sqlite3VtabCommit(X)
  6278   6315   #else
  6279         -static    void sqlite3VtabClear(Table*);
  6280         -static    int sqlite3VtabSync(sqlite3 *db, int rc);
  6281         -static    int sqlite3VtabRollback(sqlite3 *db);
  6282         -static    int sqlite3VtabCommit(sqlite3 *db);
         6316  +SQLITE_PRIVATE    void sqlite3VtabClear(Table*);
         6317  +SQLITE_PRIVATE    int sqlite3VtabSync(sqlite3 *db, int rc);
         6318  +SQLITE_PRIVATE    int sqlite3VtabRollback(sqlite3 *db);
         6319  +SQLITE_PRIVATE    int sqlite3VtabCommit(sqlite3 *db);
  6283   6320   #endif
  6284         -static void sqlite3VtabLock(sqlite3_vtab*);
  6285         -static void sqlite3VtabUnlock(sqlite3*, sqlite3_vtab*);
  6286         -static void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*);
  6287         -static void sqlite3VtabFinishParse(Parse*, Token*);
  6288         -static void sqlite3VtabArgInit(Parse*);
  6289         -static void sqlite3VtabArgExtend(Parse*, Token*);
  6290         -static int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **);
  6291         -static int sqlite3VtabCallConnect(Parse*, Table*);
  6292         -static int sqlite3VtabCallDestroy(sqlite3*, int, const char *);
  6293         -static int sqlite3VtabBegin(sqlite3 *, sqlite3_vtab *);
  6294         -static FuncDef *sqlite3VtabOverloadFunction(FuncDef*, int nArg, Expr*);
  6295         -static void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
  6296         -static int sqlite3Reprepare(Vdbe*);
  6297         -static void sqlite3ExprListCheckLength(Parse*, ExprList*, int, const char*);
         6321  +SQLITE_PRIVATE void sqlite3VtabLock(sqlite3_vtab*);
         6322  +SQLITE_PRIVATE void sqlite3VtabUnlock(sqlite3*, sqlite3_vtab*);
         6323  +SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*);
         6324  +SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse*, Token*);
         6325  +SQLITE_PRIVATE void sqlite3VtabArgInit(Parse*);
         6326  +SQLITE_PRIVATE void sqlite3VtabArgExtend(Parse*, Token*);
         6327  +SQLITE_PRIVATE int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **);
         6328  +SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse*, Table*);
         6329  +SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3*, int, const char *);
         6330  +SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, sqlite3_vtab *);
         6331  +SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(FuncDef*, int nArg, Expr*);
         6332  +SQLITE_PRIVATE void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
         6333  +SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
         6334  +SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, int, const char*);
  6298   6335   CollSeq* sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
  6299   6336   
  6300   6337   #if SQLITE_MAX_EXPR_DEPTH>0
  6301         -static   void sqlite3ExprSetHeight(Expr *);
  6302         -static   int sqlite3SelectExprHeight(Select *);
         6338  +SQLITE_PRIVATE   void sqlite3ExprSetHeight(Expr *);
         6339  +SQLITE_PRIVATE   int sqlite3SelectExprHeight(Select *);
  6303   6340   #else
  6304   6341     #define sqlite3ExprSetHeight(x)
  6305   6342   #endif
  6306   6343   
  6307         -static u32 sqlite3Get2byte(const u8*);
  6308         -static u32 sqlite3Get4byte(const u8*);
  6309         -static void sqlite3Put2byte(u8*, u32);
  6310         -static void sqlite3Put4byte(u8*, u32);
         6344  +SQLITE_PRIVATE u32 sqlite3Get2byte(const u8*);
         6345  +SQLITE_PRIVATE u32 sqlite3Get4byte(const u8*);
         6346  +SQLITE_PRIVATE void sqlite3Put2byte(u8*, u32);
         6347  +SQLITE_PRIVATE void sqlite3Put4byte(u8*, u32);
  6311   6348   
  6312   6349   #ifdef SQLITE_SSE
  6313   6350   #include "sseInt.h"
  6314   6351   #endif
  6315   6352   
  6316   6353   #ifdef SQLITE_DEBUG
  6317         -static   void sqlite3ParserTrace(FILE*, char *);
         6354  +SQLITE_PRIVATE   void sqlite3ParserTrace(FILE*, char *);
  6318   6355   #endif
  6319   6356   
  6320   6357   /*
  6321   6358   ** If the SQLITE_ENABLE IOTRACE exists then the global variable
  6322   6359   ** sqlite3_io_trace is a pointer to a printf-like routine used to
  6323   6360   ** print I/O tracing messages. 
  6324   6361   */
  6325   6362   #ifdef SQLITE_ENABLE_IOTRACE
  6326   6363   # define IOTRACE(A)  if( sqlite3_io_trace ){ sqlite3_io_trace A; }
  6327         -static   void sqlite3VdbeIOTraceSql(Vdbe*);
         6364  +SQLITE_PRIVATE   void sqlite3VdbeIOTraceSql(Vdbe*);
  6328   6365   #else
  6329   6366   # define IOTRACE(A)
  6330   6367   # define sqlite3VdbeIOTraceSql(X)
  6331   6368   #endif
  6332   6369   extern void (*sqlite3_io_trace)(const char*,...);
  6333   6370   
  6334   6371   #endif
................................................................................
  7277   7314   #endif
  7278   7315   
  7279   7316   /*
  7280   7317   ** This function registered all of the above C functions as SQL
  7281   7318   ** functions.  This should be the only routine in this file with
  7282   7319   ** external linkage.
  7283   7320   */
  7284         -static void sqlite3RegisterDateTimeFunctions(sqlite3 *db){
         7321  +SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(sqlite3 *db){
  7285   7322   #ifndef SQLITE_OMIT_DATETIME_FUNCS
  7286   7323     static const struct {
  7287   7324        char *zName;
  7288   7325        int nArg;
  7289   7326        void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
  7290   7327     } aFuncs[] = {
  7291   7328       { "julianday", -1, juliandayFunc   },
................................................................................
  7343   7380   
  7344   7381   /*
  7345   7382   ** The following routines are convenience wrappers around methods
  7346   7383   ** of the OsFile object.  This is mostly just syntactic sugar.  All
  7347   7384   ** of this would be completely automatic if SQLite were coded using
  7348   7385   ** C++ instead of plain old C.
  7349   7386   */
  7350         -static int sqlite3OsClose(OsFile **pId){
         7387  +SQLITE_PRIVATE int sqlite3OsClose(OsFile **pId){
  7351   7388     OsFile *id;
  7352   7389     if( pId!=0 && (id = *pId)!=0 ){
  7353   7390       return id->pMethod->xClose(pId);
  7354   7391     }else{
  7355   7392       return SQLITE_OK;
  7356   7393     }
  7357   7394   }
  7358         -static int sqlite3OsOpenDirectory(OsFile *id, const char *zName){
         7395  +SQLITE_PRIVATE int sqlite3OsOpenDirectory(OsFile *id, const char *zName){
  7359   7396     return id->pMethod->xOpenDirectory(id, zName);
  7360   7397   }
  7361         -static int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
         7398  +SQLITE_PRIVATE int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
  7362   7399     return id->pMethod->xRead(id, pBuf, amt);
  7363   7400   }
  7364         -static int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
         7401  +SQLITE_PRIVATE int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
  7365   7402     return id->pMethod->xWrite(id, pBuf, amt);
  7366   7403   }
  7367         -static int sqlite3OsSeek(OsFile *id, i64 offset){
         7404  +SQLITE_PRIVATE int sqlite3OsSeek(OsFile *id, i64 offset){
  7368   7405     return id->pMethod->xSeek(id, offset);
  7369   7406   }
  7370         -static int sqlite3OsTruncate(OsFile *id, i64 size){
         7407  +SQLITE_PRIVATE int sqlite3OsTruncate(OsFile *id, i64 size){
  7371   7408     return id->pMethod->xTruncate(id, size);
  7372   7409   }
  7373         -static int sqlite3OsSync(OsFile *id, int fullsync){
         7410  +SQLITE_PRIVATE int sqlite3OsSync(OsFile *id, int fullsync){
  7374   7411     return id->pMethod->xSync(id, fullsync);
  7375   7412   }
  7376         -static void sqlite3OsSetFullSync(OsFile *id, int value){
         7413  +SQLITE_PRIVATE void sqlite3OsSetFullSync(OsFile *id, int value){
  7377   7414     id->pMethod->xSetFullSync(id, value);
  7378   7415   }
  7379         -static int sqlite3OsFileSize(OsFile *id, i64 *pSize){
         7416  +SQLITE_PRIVATE int sqlite3OsFileSize(OsFile *id, i64 *pSize){
  7380   7417     return id->pMethod->xFileSize(id, pSize);
  7381   7418   }
  7382         -static int sqlite3OsLock(OsFile *id, int lockType){
         7419  +SQLITE_PRIVATE int sqlite3OsLock(OsFile *id, int lockType){
  7383   7420     return id->pMethod->xLock(id, lockType);
  7384   7421   }
  7385         -static int sqlite3OsUnlock(OsFile *id, int lockType){
         7422  +SQLITE_PRIVATE int sqlite3OsUnlock(OsFile *id, int lockType){
  7386   7423     return id->pMethod->xUnlock(id, lockType);
  7387   7424   }
  7388         -static int sqlite3OsCheckReservedLock(OsFile *id){
         7425  +SQLITE_PRIVATE int sqlite3OsCheckReservedLock(OsFile *id){
  7389   7426     return id->pMethod->xCheckReservedLock(id);
  7390   7427   }
  7391         -static int sqlite3OsSectorSize(OsFile *id){
         7428  +SQLITE_PRIVATE int sqlite3OsSectorSize(OsFile *id){
  7392   7429     int (*xSectorSize)(OsFile*) = id->pMethod->xSectorSize;
  7393   7430     return xSectorSize ? xSectorSize(id) : SQLITE_DEFAULT_SECTOR_SIZE;
  7394   7431   }
  7395   7432   
  7396   7433   #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
  7397   7434     /* These methods are currently only used for testing and debugging. */
  7398   7435     int sqlite3OsFileHandle(OsFile *id){
................................................................................
  7430   7467   **    May you find forgiveness for yourself and forgive others.
  7431   7468   **    May you share freely, never taking more than you give.
  7432   7469   **
  7433   7470   *************************************************************************
  7434   7471   ** Memory allocation functions used throughout sqlite.
  7435   7472   **
  7436   7473   **
  7437         -** $Id: sqlite3.c,v 1.3 2007/06/19 22:43:23 rmsimpson Exp $
         7474  +** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
  7438   7475   */
  7439   7476   
  7440   7477   /*
  7441   7478   ** MALLOC WRAPPER ARCHITECTURE
  7442   7479   **
  7443   7480   ** The sqlite code accesses dynamic memory allocation/deallocation by invoking
  7444   7481   ** the following six APIs (which may be implemented as macros).
................................................................................
  7623   7660   int sqlite3_iLine = 0;            /* Line number for debug info */
  7624   7661   int sqlite3_mallocfail_trace = 0; /* Print a msg on malloc fail if true */
  7625   7662   
  7626   7663   /*
  7627   7664   ** Check for a simulated memory allocation failure.  Return true if
  7628   7665   ** the failure should be simulated.  Return false to proceed as normal.
  7629   7666   */
  7630         -static int sqlite3TestMallocFail(){
         7667  +SQLITE_PRIVATE int sqlite3TestMallocFail(){
  7631   7668     if( sqlite3_isFail ){
  7632   7669       return 1;
  7633   7670     }
  7634   7671     if( sqlite3_iMallocFail>=0 ){
  7635   7672       sqlite3_iMallocFail--;
  7636   7673       if( sqlite3_iMallocFail==0 ){
  7637   7674         sqlite3_iMallocFail = sqlite3_iMallocReset;
................................................................................
  7809   7846   **     * The value of the sqlite3_malloc_id variable ...
  7810   7847   **     * The output of backtrace() (if available) ...
  7811   7848   **
  7812   7849   ** Todo: We could have a version of this function that outputs to stdout, 
  7813   7850   ** to debug memory leaks when Tcl is not available.
  7814   7851   */
  7815   7852   #if defined(TCLSH) && defined(SQLITE_DEBUG) && SQLITE_MEMDEBUG>1
  7816         -static int sqlite3OutstandingMallocs(Tcl_Interp *interp){
         7853  +SQLITE_PRIVATE int sqlite3OutstandingMallocs(Tcl_Interp *interp){
  7817   7854     void *p;
  7818   7855     Tcl_Obj *pRes = Tcl_NewObj();
  7819   7856     Tcl_IncrRefCount(pRes);
  7820   7857   
  7821   7858   
  7822   7859     for(p=sqlite3_pFirst; p; p=((void **)p)[1]){
  7823   7860       Tcl_Obj *pEntry = Tcl_NewObj();
................................................................................
  7999   8036   #endif
  8000   8037   
  8001   8038   /*
  8002   8039   ** Allocate and return N bytes of uninitialised memory by calling
  8003   8040   ** sqlite3OsMalloc(). If the Malloc() call fails, attempt to free memory 
  8004   8041   ** by calling sqlite3_release_memory().
  8005   8042   */
  8006         -static void *sqlite3MallocRaw(int n, int doMemManage){
         8043  +SQLITE_PRIVATE void *sqlite3MallocRaw(int n, int doMemManage){
  8007   8044     void *p = 0;
  8008   8045     if( n>0 && !sqlite3MallocFailed() && (!doMemManage || enforceSoftLimit(n)) ){
  8009   8046       while( (p = OSMALLOC(n))==0 && sqlite3_release_memory(n) ){}
  8010   8047       if( !p ){
  8011   8048         sqlite3FailedMalloc();
  8012   8049         OSMALLOC_FAILED();
  8013   8050       }else if( doMemManage ){
................................................................................
  8018   8055   }
  8019   8056   
  8020   8057   /*
  8021   8058   ** Resize the allocation at p to n bytes by calling sqlite3OsRealloc(). The
  8022   8059   ** pointer to the new allocation is returned.  If the Realloc() call fails,
  8023   8060   ** attempt to free memory by calling sqlite3_release_memory().
  8024   8061   */
  8025         -static void *sqlite3Realloc(void *p, int n){
         8062  +SQLITE_PRIVATE void *sqlite3Realloc(void *p, int n){
  8026   8063     if( sqlite3MallocFailed() ){
  8027   8064       return 0;
  8028   8065     }
  8029   8066   
  8030   8067     if( !p ){
  8031   8068       return sqlite3Malloc(n, 1);
  8032   8069     }else{
................................................................................
  8047   8084     }
  8048   8085   }
  8049   8086   
  8050   8087   /*
  8051   8088   ** Free the memory pointed to by p. p must be either a NULL pointer or a 
  8052   8089   ** value returned by a previous call to sqlite3Malloc() or sqlite3Realloc().
  8053   8090   */
  8054         -static void sqlite3FreeX(void *p){
         8091  +SQLITE_PRIVATE void sqlite3FreeX(void *p){
  8055   8092     if( p ){
  8056   8093       updateMemoryUsedCount(0 - OSSIZEOF(p));
  8057   8094       OSFREE(p);
  8058   8095     }
  8059   8096   }
  8060   8097   
  8061   8098   /*
  8062   8099   ** A version of sqliteMalloc() that is always a function, not a macro.
  8063   8100   ** Currently, this is used only to alloc to allocate the parser engine.
  8064   8101   */
  8065         -static void *sqlite3MallocX(int n){
         8102  +SQLITE_PRIVATE void *sqlite3MallocX(int n){
  8066   8103     return sqliteMalloc(n);
  8067   8104   }
  8068   8105   
  8069   8106   /*
  8070   8107   ** sqlite3Malloc
  8071   8108   ** sqlite3ReallocOrFree
  8072   8109   **
  8073   8110   ** These two are implemented as wrappers around sqlite3MallocRaw(), 
  8074   8111   ** sqlite3Realloc() and sqlite3Free().
  8075   8112   */ 
  8076         -static void *sqlite3Malloc(int n, int doMemManage){
         8113  +SQLITE_PRIVATE void *sqlite3Malloc(int n, int doMemManage){
  8077   8114     void *p = sqlite3MallocRaw(n, doMemManage);
  8078   8115     if( p ){
  8079   8116       memset(p, 0, n);
  8080   8117     }
  8081   8118     return p;
  8082   8119   }
  8083         -static void *sqlite3ReallocOrFree(void *p, int n){
         8120  +SQLITE_PRIVATE void *sqlite3ReallocOrFree(void *p, int n){
  8084   8121     void *pNew;
  8085   8122     pNew = sqlite3Realloc(p, n);
  8086   8123     if( !pNew ){
  8087   8124       sqlite3FreeX(p);
  8088   8125     }
  8089   8126     return pNew;
  8090   8127   }
................................................................................
  8099   8136   **     respect to the soft-heap-limit, and
  8100   8137   **
  8101   8138   **   * sqlite3ThreadSafeMalloc() must be matched with ThreadSafeFree(),
  8102   8139   **     not sqlite3Free(). Calling sqlite3Free() on memory obtained from
  8103   8140   **     ThreadSafeMalloc() will cause an error somewhere down the line.
  8104   8141   */
  8105   8142   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
  8106         -static void *sqlite3ThreadSafeMalloc(int n){
         8143  +SQLITE_PRIVATE void *sqlite3ThreadSafeMalloc(int n){
  8107   8144     (void)ENTER_MALLOC;
  8108   8145     return sqlite3Malloc(n, 0);
  8109   8146   }
  8110         -static void sqlite3ThreadSafeFree(void *p){
         8147  +SQLITE_PRIVATE void sqlite3ThreadSafeFree(void *p){
  8111   8148     (void)ENTER_MALLOC;
  8112   8149     if( p ){
  8113   8150       OSFREE(p);
  8114   8151     }
  8115   8152   }
  8116   8153   #endif
  8117   8154   
................................................................................
  8123   8160   **
  8124   8161   ** The number of bytes allocated does not include any overhead inserted by 
  8125   8162   ** any malloc() wrapper functions that may be called. So the value returned
  8126   8163   ** is the number of bytes that were available to SQLite using pointer p, 
  8127   8164   ** regardless of how much memory was actually allocated.
  8128   8165   */
  8129   8166   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
  8130         -static int sqlite3AllocSize(void *p){
         8167  +SQLITE_PRIVATE int sqlite3AllocSize(void *p){
  8131   8168     return OSSIZEOF(p);
  8132   8169   }
  8133   8170   #endif
  8134   8171   
  8135   8172   /*
  8136   8173   ** Make a copy of a string in memory obtained from sqliteMalloc(). These 
  8137   8174   ** functions call sqlite3MallocRaw() directly instead of sqliteMalloc(). This
  8138   8175   ** is because when memory debugging is turned on, these two functions are 
  8139   8176   ** called via macros that record the current file and line number in the
  8140   8177   ** ThreadData structure.
  8141   8178   */
  8142         -static char *sqlite3StrDup(const char *z){
         8179  +SQLITE_PRIVATE char *sqlite3StrDup(const char *z){
  8143   8180     char *zNew;
  8144   8181     int n;
  8145   8182     if( z==0 ) return 0;
  8146   8183     n = strlen(z)+1;
  8147   8184     zNew = sqlite3MallocRaw(n, 1);
  8148   8185     if( zNew ) memcpy(zNew, z, n);
  8149   8186     return zNew;
  8150   8187   }
  8151         -static char *sqlite3StrNDup(const char *z, int n){
         8188  +SQLITE_PRIVATE char *sqlite3StrNDup(const char *z, int n){
  8152   8189     char *zNew;
  8153   8190     if( z==0 ) return 0;
  8154   8191     zNew = sqlite3MallocRaw(n+1, 1);
  8155   8192     if( zNew ){
  8156   8193       memcpy(zNew, z, n);
  8157   8194       zNew[n] = 0;
  8158   8195     }
................................................................................
  8162   8199   /*
  8163   8200   ** Create a string from the 2nd and subsequent arguments (up to the
  8164   8201   ** first NULL argument), store the string in memory obtained from
  8165   8202   ** sqliteMalloc() and make the pointer indicated by the 1st argument
  8166   8203   ** point to that string.  The 1st argument must either be NULL or 
  8167   8204   ** point to memory obtained from sqliteMalloc().
  8168   8205   */
  8169         -static void sqlite3SetString(char **pz, ...){
         8206  +SQLITE_PRIVATE void sqlite3SetString(char **pz, ...){
  8170   8207     va_list ap;
  8171   8208     int nByte;
  8172   8209     const char *z;
  8173   8210     char *zResult;
  8174   8211   
  8175   8212     assert( pz!=0 );
  8176   8213     nByte = 1;
................................................................................
  8206   8243   ** invocation SQLITE_NOMEM is returned instead. 
  8207   8244   **
  8208   8245   ** If the first argument, db, is not NULL and a malloc() error has occured,
  8209   8246   ** then the connection error-code (the value returned by sqlite3_errcode())
  8210   8247   ** is set to SQLITE_NOMEM.
  8211   8248   */
  8212   8249   int sqlite3_mallocHasFailed = 0;
  8213         -static int sqlite3ApiExit(sqlite3* db, int rc){
         8250  +SQLITE_PRIVATE int sqlite3ApiExit(sqlite3* db, int rc){
  8214   8251     if( sqlite3MallocFailed() ){
  8215   8252       sqlite3_mallocHasFailed = 0;
  8216   8253       sqlite3OsLeaveMutex();
  8217   8254       sqlite3Error(db, SQLITE_NOMEM, 0);
  8218   8255       rc = SQLITE_NOMEM;
  8219   8256     }
  8220   8257     return rc & (db ? db->errMask : 0xff);
  8221   8258   }
  8222   8259   
  8223   8260   /* 
  8224   8261   ** Set the "malloc has failed" condition to true for this thread.
  8225   8262   */
  8226         -static void sqlite3FailedMalloc(){
         8263  +SQLITE_PRIVATE void sqlite3FailedMalloc(){
  8227   8264     if( !sqlite3MallocFailed() ){
  8228   8265       sqlite3OsEnterMutex();
  8229   8266       assert( sqlite3_mallocHasFailed==0 );
  8230   8267       sqlite3_mallocHasFailed = 1;
  8231   8268     }
  8232   8269   }
  8233   8270   
  8234   8271   #ifdef SQLITE_MEMDEBUG
  8235   8272   /*
  8236   8273   ** This function sets a flag in the thread-specific-data structure that will
  8237   8274   ** cause an assert to fail if sqliteMalloc() or sqliteRealloc() is called.
  8238   8275   */
  8239         -static void sqlite3MallocDisallow(){
         8276  +SQLITE_PRIVATE void sqlite3MallocDisallow(){
  8240   8277     assert( sqlite3_mallocDisallowed>=0 );
  8241   8278     sqlite3_mallocDisallowed++;
  8242   8279   }
  8243   8280   
  8244   8281   /*
  8245   8282   ** This function clears the flag set in the thread-specific-data structure set
  8246   8283   ** by sqlite3MallocDisallow().
  8247   8284   */
  8248         -static void sqlite3MallocAllow(){
         8285  +SQLITE_PRIVATE void sqlite3MallocAllow(){
  8249   8286     assert( sqlite3_mallocDisallowed>0 );
  8250   8287     sqlite3_mallocDisallowed--;
  8251   8288   }
  8252   8289   #endif
  8253   8290   
  8254   8291   /************** End of malloc.c **********************************************/
  8255   8292   /************** Begin file printf.c ******************************************/
................................................................................
  8324   8361   #define etCHARLIT    10 /* Literal characters.  %' */
  8325   8362   #define etSQLESCAPE  11 /* Strings with '\'' doubled.  %q */
  8326   8363   #define etSQLESCAPE2 12 /* Strings with '\'' doubled and enclosed in '',
  8327   8364                             NULL pointers replaced by SQL NULL.  %Q */
  8328   8365   #define etTOKEN      13 /* a pointer to a Token structure */
  8329   8366   #define etSRCLIST    14 /* a pointer to a SrcList */
  8330   8367   #define etPOINTER    15 /* The %p conversion */
         8368  +#define etSQLESCAPE3 16 /* %w -> Strings with '\"' doubled */
  8331   8369   
  8332   8370   
  8333   8371   /*
  8334   8372   ** An "etByte" is an 8-bit unsigned value.
  8335   8373   */
  8336   8374   typedef unsigned char etByte;
  8337   8375   
................................................................................
  8365   8403   static const et_info fmtinfo[] = {
  8366   8404     {  'd', 10, 1, etRADIX,      0,  0 },
  8367   8405     {  's',  0, 4, etSTRING,     0,  0 },
  8368   8406     {  'g',  0, 1, etGENERIC,    30, 0 },
  8369   8407     {  'z',  0, 6, etDYNSTRING,  0,  0 },
  8370   8408     {  'q',  0, 4, etSQLESCAPE,  0,  0 },
  8371   8409     {  'Q',  0, 4, etSQLESCAPE2, 0,  0 },
         8410  +  {  'w',  0, 4, etSQLESCAPE3, 0,  0 },
  8372   8411     {  'c',  0, 0, etCHARX,      0,  0 },
  8373   8412     {  'o',  8, 0, etRADIX,      0,  2 },
  8374   8413     {  'u', 10, 0, etRADIX,      0,  0 },
  8375   8414     {  'x', 16, 0, etRADIX,      16, 1 },
  8376   8415     {  'X', 16, 0, etRADIX,      0,  4 },
  8377   8416   #ifndef SQLITE_OMIT_FLOATING_POINT
  8378   8417     {  'f',  0, 1, etFLOAT,      0,  0 },
................................................................................
  8704   8743   #else
  8705   8744           /* It makes more sense to use 0.5 */
  8706   8745           for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1){}
  8707   8746   #endif
  8708   8747           if( xtype==etFLOAT ) realvalue += rounder;
  8709   8748           /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
  8710   8749           exp = 0;
  8711         -        if( isnan(realvalue) ){
         8750  +        if( sqlite3_isnan(realvalue) ){
  8712   8751             bufpt = "NaN";
  8713   8752             length = 3;
  8714   8753             break;
  8715   8754           }
  8716   8755           if( realvalue>0.0 ){
  8717   8756             while( realvalue>=1e32 && exp<=350 ){ realvalue *= 1e-32; exp+=32; }
  8718   8757             while( realvalue>=1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; }
................................................................................
  8861   8900           }else if( xtype==etDYNSTRING ){
  8862   8901             zExtra = bufpt;
  8863   8902           }
  8864   8903           length = strlen(bufpt);
  8865   8904           if( precision>=0 && precision<length ) length = precision;
  8866   8905           break;
  8867   8906         case etSQLESCAPE:
  8868         -      case etSQLESCAPE2: {
         8907  +      case etSQLESCAPE2:
         8908  +      case etSQLESCAPE3: {
  8869   8909           int i, j, n, ch, isnull;
  8870   8910           int needQuote;
         8911  +        char q = ((xtype==etSQLESCAPE3)?'"':'\'');   /* Quote character */
  8871   8912           char *escarg = va_arg(ap,char*);
  8872   8913           isnull = escarg==0;
  8873   8914           if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
  8874   8915           for(i=n=0; (ch=escarg[i])!=0; i++){
  8875         -          if( ch=='\'' )  n++;
         8916  +          if( ch==q )  n++;
  8876   8917           }
  8877   8918           needQuote = !isnull && xtype==etSQLESCAPE2;
  8878   8919           n += i + 1 + needQuote*2;
  8879   8920           if( n>etBUFSIZE ){
  8880   8921             bufpt = zExtra = sqliteMalloc( n );
  8881   8922             if( bufpt==0 ) return -1;
  8882   8923           }else{
  8883   8924             bufpt = buf;
  8884   8925           }
  8885   8926           j = 0;
  8886         -        if( needQuote ) bufpt[j++] = '\'';
         8927  +        if( needQuote ) bufpt[j++] = q;
  8887   8928           for(i=0; (ch=escarg[i])!=0; i++){
  8888   8929             bufpt[j++] = ch;
  8889         -          if( ch=='\'' ) bufpt[j++] = ch;
         8930  +          if( ch==q ) bufpt[j++] = ch;
  8890   8931           }
  8891         -        if( needQuote ) bufpt[j++] = '\'';
         8932  +        if( needQuote ) bufpt[j++] = q;
  8892   8933           bufpt[j] = 0;
  8893   8934           length = j;
  8894   8935           /* The precision is ignored on %q and %Q */
  8895   8936           /* if( precision>=0 && precision<length ) length = precision; */
  8896   8937           break;
  8897   8938         }
  8898   8939         case etTOKEN: {
................................................................................
  9051   9092     return sqliteRealloc(old,size);
  9052   9093   }
  9053   9094   
  9054   9095   /*
  9055   9096   ** Print into memory obtained from sqliteMalloc().  Use the internal
  9056   9097   ** %-conversion extensions.
  9057   9098   */
  9058         -static char *sqlite3VMPrintf(const char *zFormat, va_list ap){
         9099  +SQLITE_PRIVATE char *sqlite3VMPrintf(const char *zFormat, va_list ap){
  9059   9100     char zBase[SQLITE_PRINT_BUF_SIZE];
  9060   9101     return base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
  9061   9102   }
  9062   9103   
  9063   9104   /*
  9064   9105   ** Print into memory obtained from sqliteMalloc().  Use the internal
  9065   9106   ** %-conversion extensions.
  9066   9107   */
  9067         -static char *sqlite3MPrintf(const char *zFormat, ...){
         9108  +SQLITE_PRIVATE char *sqlite3MPrintf(const char *zFormat, ...){
  9068   9109     va_list ap;
  9069   9110     char *z;
  9070   9111     char zBase[SQLITE_PRINT_BUF_SIZE];
  9071   9112     va_start(ap, zFormat);
  9072   9113     z = base_vprintf(printf_realloc, 1, zBase, sizeof(zBase), zFormat, ap);
  9073   9114     va_end(ap);
  9074   9115     return z;
  9075   9116   }
  9076   9117   
  9077   9118   /*
  9078   9119   ** Print into memory obtained from sqlite3_malloc().  Omit the internal
  9079   9120   ** %-conversion extensions.
  9080   9121   */
  9081         -char *sqlite3_vmprintf(const char *zFormat, va_list ap){
         9122  +SQLITE_API char *sqlite3_vmprintf(const char *zFormat, va_list ap){
  9082   9123     char zBase[SQLITE_PRINT_BUF_SIZE];
  9083   9124     return base_vprintf(sqlite3_realloc, 0, zBase, sizeof(zBase), zFormat, ap);
  9084   9125   }
  9085   9126   
  9086   9127   /*
  9087   9128   ** Print into memory obtained from sqlite3_malloc()().  Omit the internal
  9088   9129   ** %-conversion extensions.
  9089   9130   */
  9090         -char *sqlite3_mprintf(const char *zFormat, ...){
         9131  +SQLITE_API char *sqlite3_mprintf(const char *zFormat, ...){
  9091   9132     va_list ap;
  9092   9133     char *z;
  9093   9134     va_start(ap, zFormat);
  9094   9135     z = sqlite3_vmprintf(zFormat, ap);
  9095   9136     va_end(ap);
  9096   9137     return z;
  9097   9138   }
................................................................................
  9098   9139   
  9099   9140   /*
  9100   9141   ** sqlite3_snprintf() works like snprintf() except that it ignores the
  9101   9142   ** current locale settings.  This is important for SQLite because we
  9102   9143   ** are not able to use a "," as the decimal point in place of "." as
  9103   9144   ** specified by some locales.
  9104   9145   */
  9105         -char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
         9146  +SQLITE_API char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
  9106   9147     char *z;
  9107   9148     va_list ap;
  9108   9149   
  9109   9150     if( n<=0 ){
  9110   9151       return zBuf;
  9111   9152     }
  9112   9153     zBuf[0] = 0;
................................................................................
  9118   9159   
  9119   9160   #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) || defined(SQLITE_MEMDEBUG)
  9120   9161   /*
  9121   9162   ** A version of printf() that understands %lld.  Used for debugging.
  9122   9163   ** The printf() built into some versions of windows does not understand %lld
  9123   9164   ** and segfaults if you give it a long long int.
  9124   9165   */
  9125         -static void sqlite3DebugPrintf(const char *zFormat, ...){
         9166  +SQLITE_PRIVATE void sqlite3DebugPrintf(const char *zFormat, ...){
  9126   9167     extern int getpid(void);
  9127   9168     va_list ap;
  9128   9169     char zBuf[500];
  9129   9170     va_start(ap, zFormat);
  9130   9171     base_vprintf(0, 0, zBuf, sizeof(zBuf), zFormat, ap);
  9131   9172     va_end(ap);
  9132   9173     fprintf(stdout,"%s", zBuf);
................................................................................
  9149   9190   *************************************************************************
  9150   9191   ** This file contains code to implement a pseudo-random number
  9151   9192   ** generator (PRNG) for SQLite.
  9152   9193   **
  9153   9194   ** Random numbers are used by some of the database backends in order
  9154   9195   ** to generate random integer keys for tables or random filenames.
  9155   9196   **
  9156         -** $Id: sqlite3.c,v 1.3 2007/06/19 22:43:23 rmsimpson Exp $
         9197  +** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
  9157   9198   */
  9158   9199   
  9159   9200   
  9160   9201   /*
  9161   9202   ** Get a single 8-bit random value from the RC4 PRNG.  The Mutex
  9162   9203   ** must be held while executing this routine.
  9163   9204   **
................................................................................
  9222   9263     t += prng.s[prng.i];
  9223   9264     return prng.s[t];
  9224   9265   }
  9225   9266   
  9226   9267   /*
  9227   9268   ** Return N random bytes.
  9228   9269   */
  9229         -static void sqlite3Randomness(int N, void *pBuf){
         9270  +SQLITE_PRIVATE void sqlite3Randomness(int N, void *pBuf){
  9230   9271     unsigned char *zBuf = pBuf;
  9231   9272     sqlite3OsEnterMutex();
  9232   9273     while( N-- ){
  9233   9274       *(zBuf++) = randomByte();
  9234   9275     }
  9235   9276     sqlite3OsLeaveMutex();
  9236   9277   }
................................................................................
  9247   9288   **    May you find forgiveness for yourself and forgive others.
  9248   9289   **    May you share freely, never taking more than you give.
  9249   9290   **
  9250   9291   *************************************************************************
  9251   9292   ** This file contains routines used to translate between UTF-8, 
  9252   9293   ** UTF-16, UTF-16BE, and UTF-16LE.
  9253   9294   **
  9254         -** $Id: sqlite3.c,v 1.3 2007/06/19 22:43:23 rmsimpson Exp $
         9295  +** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
  9255   9296   **
  9256   9297   ** Notes on UTF-8:
  9257   9298   **
  9258   9299   **   Byte-0    Byte-1    Byte-2    Byte-3    Value
  9259   9300   **  0xxxxxxx                                 00000000 00000000 0xxxxxxx
  9260   9301   **  110yyyyy  10xxxxxx                       00000000 00000yyy yyxxxxxx
  9261   9302   **  1110zzzz  10yyyyyy  10xxxxxx             00000000 zzzzyyyy yyxxxxxx
................................................................................
  9617   9658     int nChange;            /* Number of db changes made since last reset */
  9618   9659     i64 startTime;          /* Time when query started - used for profiling */
  9619   9660     int nSql;             /* Number of bytes in zSql */
  9620   9661     char *zSql;           /* Text of the SQL statement that generated this */
  9621   9662   #ifdef SQLITE_DEBUG
  9622   9663     FILE *trace;        /* Write an execution trace here, if not NULL */
  9623   9664   #endif
         9665  +  int openedStatement;  /* True if this VM has opened a statement journal */
  9624   9666   #ifdef SQLITE_SSE
  9625   9667     int fetchId;          /* Statement number used by sqlite3_fetch_statement */
  9626   9668     int lru;              /* Counter used for LRU cache replacement */
  9627   9669   #endif
  9628   9670   };
  9629   9671   
  9630   9672   /*
................................................................................
  9634   9676   #define VDBE_MAGIC_RUN      0xbdf20da3    /* VDBE is ready to execute */
  9635   9677   #define VDBE_MAGIC_HALT     0x519c2973    /* VDBE has completed execution */
  9636   9678   #define VDBE_MAGIC_DEAD     0xb606c3c8    /* The VDBE has been deallocated */
  9637   9679   
  9638   9680   /*
  9639   9681   ** Function prototypes
  9640   9682   */
  9641         -static void sqlite3VdbeFreeCursor(Vdbe *, Cursor*);
         9683  +SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, Cursor*);
  9642   9684   void sqliteVdbePopStack(Vdbe*,int);
  9643         -static int sqlite3VdbeCursorMoveto(Cursor*);
         9685  +SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(Cursor*);
  9644   9686   #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
  9645         -static void sqlite3VdbePrintOp(FILE*, int, Op*);
         9687  +SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
  9646   9688   #endif
  9647         -static int sqlite3VdbeSerialTypeLen(u32);
  9648         -static u32 sqlite3VdbeSerialType(Mem*, int);
  9649         -static int sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int);
  9650         -static int sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
  9651         -static void sqlite3VdbeDeleteAuxData(VdbeFunc*, int);
         9689  +SQLITE_PRIVATE int sqlite3VdbeSerialTypeLen(u32);
         9690  +SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
         9691  +SQLITE_PRIVATE int sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int);
         9692  +SQLITE_PRIVATE int sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
         9693  +SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(VdbeFunc*, int);
  9652   9694   
  9653   9695   int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
  9654         -static int sqlite3VdbeIdxKeyCompare(Cursor*, int , const unsigned char*, int*);
  9655         -static int sqlite3VdbeIdxRowid(BtCursor *, i64 *);
  9656         -static int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
  9657         -static int sqlite3VdbeRecordCompare(void*,int,const void*,int, const void*);
  9658         -static int sqlite3VdbeIdxRowidLen(const u8*);
  9659         -static int sqlite3VdbeExec(Vdbe*);
  9660         -static int sqlite3VdbeList(Vdbe*);
  9661         -static int sqlite3VdbeHalt(Vdbe*);
  9662         -static int sqlite3VdbeChangeEncoding(Mem *, int);
  9663         -static int sqlite3VdbeMemTooBig(Mem*);
  9664         -static int sqlite3VdbeMemCopy(Mem*, const Mem*);
  9665         -static void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int);
  9666         -static int sqlite3VdbeMemMove(Mem*, Mem*);
  9667         -static int sqlite3VdbeMemNulTerminate(Mem*);
  9668         -static int sqlite3VdbeMemSetStr(Mem*, const char*, int, u8, void(*)(void*));
  9669         -static void sqlite3VdbeMemSetInt64(Mem*, i64);
  9670         -static void sqlite3VdbeMemSetDouble(Mem*, double);
  9671         -static void sqlite3VdbeMemSetNull(Mem*);
  9672         -static void sqlite3VdbeMemSetZeroBlob(Mem*,int);
  9673         -static int sqlite3VdbeMemMakeWriteable(Mem*);
  9674         -static int sqlite3VdbeMemDynamicify(Mem*);
  9675         -static int sqlite3VdbeMemStringify(Mem*, int);
  9676         -static i64 sqlite3VdbeIntValue(Mem*);
  9677         -static int sqlite3VdbeMemIntegerify(Mem*);
  9678         -static double sqlite3VdbeRealValue(Mem*);
  9679         -static void sqlite3VdbeIntegerAffinity(Mem*);
  9680         -static int sqlite3VdbeMemRealify(Mem*);
  9681         -static int sqlite3VdbeMemNumerify(Mem*);
  9682         -static int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*);
  9683         -static void sqlite3VdbeMemRelease(Mem *p);
  9684         -static int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
  9685         -#ifndef NDEBUG
  9686         -static   void sqlite3VdbeMemSanity(Mem*);
  9687         -static   int sqlite3VdbeOpcodeNoPush(u8);
  9688         -#endif
  9689         -static int sqlite3VdbeMemTranslate(Mem*, u8);
  9690         -#ifdef SQLITE_DEBUG
  9691         -static   void sqlite3VdbePrintSql(Vdbe*);
  9692         -static   void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf);
  9693         -#endif
  9694         -static int sqlite3VdbeMemHandleBom(Mem *pMem);
  9695         -static void sqlite3VdbeFifoInit(Fifo*);
  9696         -static int sqlite3VdbeFifoPush(Fifo*, i64);
  9697         -static int sqlite3VdbeFifoPop(Fifo*, i64*);
  9698         -static void sqlite3VdbeFifoClear(Fifo*);
         9696  +SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(Cursor*, int , const unsigned char*, int*);
         9697  +SQLITE_PRIVATE int sqlite3VdbeIdxRowid(BtCursor *, i64 *);
         9698  +SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
         9699  +SQLITE_PRIVATE int sqlite3VdbeRecordCompare(void*,int,const void*,int, const void*);
         9700  +SQLITE_PRIVATE int sqlite3VdbeIdxRowidLen(const u8*);
         9701  +SQLITE_PRIVATE int sqlite3VdbeExec(Vdbe*);
         9702  +SQLITE_PRIVATE int sqlite3VdbeList(Vdbe*);
         9703  +SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe*);
         9704  +SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *, int);
         9705  +SQLITE_PRIVATE int sqlite3VdbeMemTooBig(Mem*);
         9706  +SQLITE_PRIVATE int sqlite3VdbeMemCopy(Mem*, const Mem*);
         9707  +SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int);
         9708  +SQLITE_PRIVATE int sqlite3VdbeMemMove(Mem*, Mem*);
         9709  +SQLITE_PRIVATE int sqlite3VdbeMemNulTerminate(Mem*);
         9710  +SQLITE_PRIVATE int sqlite3VdbeMemSetStr(Mem*, const char*, int, u8, void(*)(void*));
         9711  +SQLITE_PRIVATE void sqlite3VdbeMemSetInt64(Mem*, i64);
         9712  +SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem*, double);
         9713  +SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem*);
         9714  +SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem*,int);
         9715  +SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*);
         9716  +SQLITE_PRIVATE int sqlite3VdbeMemDynamicify(Mem*);
         9717  +SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, int);
         9718  +SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem*);
         9719  +SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
         9720  +SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
         9721  +SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
         9722  +SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
         9723  +SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
         9724  +SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*);
         9725  +SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
         9726  +SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
         9727  +#ifndef NDEBUG
         9728  +SQLITE_PRIVATE   void sqlite3VdbeMemSanity(Mem*);
         9729  +SQLITE_PRIVATE   int sqlite3VdbeOpcodeNoPush(u8);
         9730  +#endif
         9731  +SQLITE_PRIVATE int sqlite3VdbeMemTranslate(Mem*, u8);
         9732  +#ifdef SQLITE_DEBUG
         9733  +SQLITE_PRIVATE   void sqlite3VdbePrintSql(Vdbe*);
         9734  +SQLITE_PRIVATE   void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf);
         9735  +#endif
         9736  +SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem);
         9737  +SQLITE_PRIVATE void sqlite3VdbeFifoInit(Fifo*);
         9738  +SQLITE_PRIVATE int sqlite3VdbeFifoPush(Fifo*, i64);
         9739  +SQLITE_PRIVATE int sqlite3VdbeFifoPop(Fifo*, i64*);
         9740  +SQLITE_PRIVATE void sqlite3VdbeFifoClear(Fifo*);
  9699   9741   
  9700   9742   #ifndef SQLITE_OMIT_INCRBLOB
  9701         -static   int sqlite3VdbeMemExpandBlob(Mem *);
         9743  +SQLITE_PRIVATE   int sqlite3VdbeMemExpandBlob(Mem *);
  9702   9744   #else
  9703   9745     #define sqlite3VdbeMemExpandBlob(x) SQLITE_OK
  9704   9746   #endif
  9705   9747   
  9706   9748   #endif /* !defined(_VDBEINT_H_) */
  9707   9749   
  9708   9750   /************** End of vdbeInt.h *********************************************/
................................................................................
  9803   9845   
  9804   9846   #ifndef SQLITE_OMIT_UTF16
  9805   9847   /*
  9806   9848   ** This routine transforms the internal text encoding used by pMem to
  9807   9849   ** desiredEnc. It is an error if the string is already of the desired
  9808   9850   ** encoding, or if *pMem does not contain a string value.
  9809   9851   */
  9810         -static int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
         9852  +SQLITE_PRIVATE int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
  9811   9853     unsigned char zShort[NBFS]; /* Temporary short output buffer */
  9812   9854     int len;                    /* Maximum length of output string in bytes */
  9813   9855     unsigned char *zOut;                  /* Output buffer */
  9814   9856     unsigned char *zIn;                   /* Input iterator */
  9815   9857     unsigned char *zTerm;                 /* End of input */
  9816   9858     unsigned char *z;                     /* Output iterator */
  9817   9859     unsigned int c;
................................................................................
 10014  10056   ** UTF-16 string stored in *pMem. If one is present, it is removed and
 10015  10057   ** the encoding of the Mem adjusted. This routine does not do any
 10016  10058   ** byte-swapping, it just sets Mem.enc appropriately.
 10017  10059   **
 10018  10060   ** The allocation (static, dynamic etc.) and encoding of the Mem may be
 10019  10061   ** changed by this function.
 10020  10062   */
 10021         -static int sqlite3VdbeMemHandleBom(Mem *pMem){
        10063  +SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem){
 10022  10064     int rc = SQLITE_OK;
 10023  10065     u8 bom = 0;
 10024  10066   
 10025  10067     if( pMem->n<0 || pMem->n>1 ){
 10026  10068       u8 b1 = *(u8 *)pMem->z;
 10027  10069       u8 b2 = *(((u8 *)pMem->z) + 1);
 10028  10070       if( b1==0xFE && b2==0xFF ){
................................................................................
 10060  10102   /*
 10061  10103   ** pZ is a UTF-8 encoded unicode string. If nByte is less than zero,
 10062  10104   ** return the number of unicode characters in pZ up to (but not including)
 10063  10105   ** the first 0x00 byte. If nByte is not less than zero, return the
 10064  10106   ** number of unicode characters in the first nByte of pZ (or up to 
 10065  10107   ** the first 0x00, whichever comes first).
 10066  10108   */
 10067         -static int sqlite3Utf8CharLen(const char *zIn, int nByte){
        10109  +SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *zIn, int nByte){
 10068  10110     int r = 0;
 10069  10111     const u8 *z = (const u8*)zIn;
 10070  10112     const u8 *zTerm;
 10071  10113     if( nByte>=0 ){
 10072  10114       zTerm = &z[nByte];
 10073  10115     }else{
 10074  10116       zTerm = (const u8*)(-1);
................................................................................
 10085  10127   /*
 10086  10128   ** Convert a UTF-16 string in the native encoding into a UTF-8 string.
 10087  10129   ** Memory to hold the UTF-8 string is obtained from malloc and must be
 10088  10130   ** freed by the calling function.
 10089  10131   **
 10090  10132   ** NULL is returned if there is an allocation error.
 10091  10133   */
 10092         -static char *sqlite3Utf16to8(const void *z, int nByte){
        10134  +SQLITE_PRIVATE char *sqlite3Utf16to8(const void *z, int nByte){
 10093  10135     Mem m;
 10094  10136     memset(&m, 0, sizeof(m));
 10095  10137     sqlite3VdbeMemSetStr(&m, z, nByte, SQLITE_UTF16NATIVE, SQLITE_STATIC);
 10096  10138     sqlite3VdbeChangeEncoding(&m, SQLITE_UTF8);
 10097  10139     assert( (m.flags & MEM_Term)!=0 || sqlite3MallocFailed() );
 10098  10140     assert( (m.flags & MEM_Str)!=0 || sqlite3MallocFailed() );
 10099  10141     return (m.flags & MEM_Dyn)!=0 ? m.z : sqliteStrDup(m.z);
................................................................................
 10102  10144   /*
 10103  10145   ** pZ is a UTF-16 encoded unicode string. If nChar is less than zero,
 10104  10146   ** return the number of bytes up to (but not including), the first pair
 10105  10147   ** of consecutive 0x00 bytes in pZ. If nChar is not less than zero,
 10106  10148   ** then return the number of bytes in the first nChar unicode characters
 10107  10149   ** in pZ (or up until the first pair of 0x00 bytes, whichever comes first).
 10108  10150   */
 10109         -static int sqlite3Utf16ByteLen(const void *zIn, int nChar){
        10151  +SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *zIn, int nChar){
 10110  10152     unsigned int c = 1;
 10111  10153     char const *z = zIn;
 10112  10154     int n = 0;
 10113  10155     if( SQLITE_UTF16NATIVE==SQLITE_UTF16BE ){
 10114  10156       /* Using an "if (SQLITE_UTF16NATIVE==SQLITE_UTF16BE)" construct here
 10115  10157       ** and in other parts of this file means that at one branch will
 10116  10158       ** not be covered by coverage testing on any single host. But coverage
................................................................................
 10139  10181   **
 10140  10182   ** This has the effect of making sure that the string is well-formed
 10141  10183   ** UTF-8.  Miscoded characters are removed.
 10142  10184   **
 10143  10185   ** The translation is done in-place (since it is impossible for the
 10144  10186   ** correct UTF-8 encoding to be longer than a malformed encoding).
 10145  10187   */
 10146         -static int sqlite3Utf8To8(unsigned char *zIn){
        10188  +SQLITE_PRIVATE int sqlite3Utf8To8(unsigned char *zIn){
 10147  10189     unsigned char *zOut = zIn;
 10148  10190     unsigned char *zStart = zIn;
 10149  10191     int c;
 10150  10192   
 10151  10193     while(1){
 10152  10194       SQLITE_READ_UTF8(zIn, c);
 10153  10195       if( c==0 ) break;
................................................................................
 10162  10204   
 10163  10205   #if defined(SQLITE_TEST)
 10164  10206   /*
 10165  10207   ** This routine is called from the TCL test function "translate_selftest".
 10166  10208   ** It checks that the primitives for serializing and deserializing
 10167  10209   ** characters in each encoding are inverses of each other.
 10168  10210   */
 10169         -static void sqlite3UtfSelfTest(){
        10211  +SQLITE_PRIVATE void sqlite3UtfSelfTest(){
 10170  10212     unsigned int i, t;
 10171  10213     unsigned char zBuf[20];
 10172  10214     unsigned char *z;
 10173  10215     int n;
 10174  10216     unsigned int c;
 10175  10217   
 10176  10218     for(i=0; i<0x00110000; i++){
................................................................................
 10226  10268   **
 10227  10269   *************************************************************************
 10228  10270   ** Utility functions used throughout sqlite.
 10229  10271   **
 10230  10272   ** This file contains functions for allocating memory, comparing
 10231  10273   ** strings, and stuff like that.
 10232  10274   **
 10233         -** $Id: sqlite3.c,v 1.3 2007/06/19 22:43:23 rmsimpson Exp $
        10275  +** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
 10234  10276   */
 10235  10277   
 10236  10278   
 10237  10279   /*
 10238  10280   ** Set the most recent error code and error string for the sqlite
 10239  10281   ** handle "db". The error code is set to "err_code".
 10240  10282   **
................................................................................
 10251  10293   ** zFormat and any string tokens that follow it are assumed to be
 10252  10294   ** encoded in UTF-8.
 10253  10295   **
 10254  10296   ** To clear the most recent error for sqlite handle "db", sqlite3Error
 10255  10297   ** should be called with err_code set to SQLITE_OK and zFormat set
 10256  10298   ** to NULL.
 10257  10299   */
 10258         -static void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){
        10300  +SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){
 10259  10301     if( db && (db->pErr || (db->pErr = sqlite3ValueNew())!=0) ){
 10260  10302       db->errCode = err_code;
 10261  10303       if( zFormat ){
 10262  10304         char *z;
 10263  10305         va_list ap;
 10264  10306         va_start(ap, zFormat);
 10265  10307         z = sqlite3VMPrintf(zFormat, ap);
................................................................................
 10284  10326   ** This function should be used to report any error that occurs whilst
 10285  10327   ** compiling an SQL statement (i.e. within sqlite3_prepare()). The
 10286  10328   ** last thing the sqlite3_prepare() function does is copy the error
 10287  10329   ** stored by this function into the database handle using sqlite3Error().
 10288  10330   ** Function sqlite3Error() should be used during statement execution
 10289  10331   ** (sqlite3_step() etc.).
 10290  10332   */
 10291         -static void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){
        10333  +SQLITE_PRIVATE void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){
 10292  10334     va_list ap;
 10293  10335     pParse->nErr++;
 10294  10336     sqliteFree(pParse->zErrMsg);
 10295  10337     va_start(ap, zFormat);
 10296  10338     pParse->zErrMsg = sqlite3VMPrintf(zFormat, ap);
 10297  10339     va_end(ap);
 10298  10340     if( pParse->rc==SQLITE_OK ){
................................................................................
 10299  10341       pParse->rc = SQLITE_ERROR;
 10300  10342     }
 10301  10343   }
 10302  10344   
 10303  10345   /*
 10304  10346   ** Clear the error message in pParse, if any
 10305  10347   */
 10306         -static void sqlite3ErrorClear(Parse *pParse){
        10348  +SQLITE_PRIVATE void sqlite3ErrorClear(Parse *pParse){
 10307  10349     sqliteFree(pParse->zErrMsg);
 10308  10350     pParse->zErrMsg = 0;
 10309  10351     pParse->nErr = 0;
 10310  10352   }
 10311  10353   
 10312  10354   /*
 10313  10355   ** Convert an SQL-style quoted string into a normal string by removing
................................................................................
 10315  10357   ** input does not begin with a quote character, then this routine
 10316  10358   ** is a no-op.
 10317  10359   **
 10318  10360   ** 2002-Feb-14: This routine is extended to remove MS-Access style
 10319  10361   ** brackets from around identifers.  For example:  "[a-b-c]" becomes
 10320  10362   ** "a-b-c".
 10321  10363   */
 10322         -static void sqlite3Dequote(char *z){
        10364  +SQLITE_PRIVATE void sqlite3Dequote(char *z){
 10323  10365     int quote;
 10324  10366     int i, j;
 10325  10367     if( z==0 ) return;
 10326  10368     quote = z[0];
 10327  10369     switch( quote ){
 10328  10370       case '\'':  break;
 10329  10371       case '"':   break;
................................................................................
 10388  10430   };
 10389  10431   #define UpperToLower sqlite3UpperToLower
 10390  10432   
 10391  10433   /*
 10392  10434   ** Some systems have stricmp().  Others have strcasecmp().  Because
 10393  10435   ** there is no consistency, we will define our own.
 10394  10436   */
 10395         -static int sqlite3StrICmp(const char *zLeft, const char *zRight){
        10437  +SQLITE_PRIVATE int sqlite3StrICmp(const char *zLeft, const char *zRight){
 10396  10438     register unsigned char *a, *b;
 10397  10439     a = (unsigned char *)zLeft;
 10398  10440     b = (unsigned char *)zRight;
 10399  10441     while( *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
 10400  10442     return UpperToLower[*a] - UpperToLower[*b];
 10401  10443   }
 10402         -static int sqlite3StrNICmp(const char *zLeft, const char *zRight, int N){
        10444  +SQLITE_PRIVATE int sqlite3StrNICmp(const char *zLeft, const char *zRight, int N){
 10403  10445     register unsigned char *a, *b;
 10404  10446     a = (unsigned char *)zLeft;
 10405  10447     b = (unsigned char *)zRight;
 10406  10448     while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
 10407  10449     return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
 10408  10450   }
 10409  10451   
................................................................................
 10411  10453   ** Return TRUE if z is a pure numeric string.  Return FALSE if the
 10412  10454   ** string contains any character which is not part of a number. If
 10413  10455   ** the string is numeric and contains the '.' character, set *realnum
 10414  10456   ** to TRUE (otherwise FALSE).
 10415  10457   **
 10416  10458   ** An empty string is considered non-numeric.
 10417  10459   */
 10418         -static int sqlite3IsNumber(const char *z, int *realnum, u8 enc){
        10460  +SQLITE_PRIVATE int sqlite3IsNumber(const char *z, int *realnum, u8 enc){
 10419  10461     int incr = (enc==SQLITE_UTF8?1:2);
 10420  10462     if( enc==SQLITE_UTF16BE ) z++;
 10421  10463     if( *z=='-' || *z=='+' ) z += incr;
 10422  10464     if( !isdigit(*(u8*)z) ){
 10423  10465       return 0;
 10424  10466     }
 10425  10467     z += incr;
................................................................................
 10449  10491   ** is not, the result is undefined.
 10450  10492   **
 10451  10493   ** This routine is used instead of the library atof() function because
 10452  10494   ** the library atof() might want to use "," as the decimal point instead
 10453  10495   ** of "." depending on how locale is set.  But that would cause problems
 10454  10496   ** for SQL.  So this routine always uses "." regardless of locale.
 10455  10497   */
 10456         -static int sqlite3AtoF(const char *z, double *pResult){
        10498  +SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult){
 10457  10499   #ifndef SQLITE_OMIT_FLOATING_POINT
 10458  10500     int sign = 1;
 10459  10501     const char *zBegin = z;
 10460  10502     LONGDOUBLE_TYPE v1 = 0.0;
 10461  10503     while( isspace(*(u8*)z) ) z++;
 10462  10504     if( *z=='-' ){
 10463  10505       sign = -1;
................................................................................
 10506  10548     }
 10507  10549     *pResult = sign<0 ? -v1 : v1;
 10508  10550     return z - zBegin;
 10509  10551   #else
 10510  10552     return sqlite3Atoi64(z, pResult);
 10511  10553   #endif /* SQLITE_OMIT_FLOATING_POINT */
 10512  10554   }
        10555  +
        10556  +/*
        10557  +** Compare the 19-character string zNum against the text representation
        10558  +** value 2^63:  9223372036854775808.  Return negative, zero, or positive
        10559  +** if zNum is less than, equal to, or greater than the string.
        10560  +**
        10561  +** Unlike memcmp() this routine is guaranteed to return the difference
        10562  +** in the values of the last digit if the only difference is in the
        10563  +** last digit.  So, for example,
        10564  +**
        10565  +**      compare2pow63("9223372036854775800")
        10566  +**
        10567  +** will return -8.
        10568  +*/
        10569  +static int compare2pow63(const char *zNum){
        10570  +  int c;
        10571  +  c = memcmp(zNum,"922337203685477580",18);
        10572  +  if( c==0 ){
        10573  +    c = zNum[18] - '8';
        10574  +  }
        10575  +  return c;
        10576  +}
        10577  +
 10513  10578   
 10514  10579   /*
 10515  10580   ** Return TRUE if zNum is a 64-bit signed integer and write
 10516  10581   ** the value of the integer into *pNum.  If zNum is not an integer
 10517  10582   ** or is an integer that is too large to be expressed with 64 bits,
 10518         -** then return false.  If n>0 and the integer is string is not
 10519         -** exactly n bytes long, return false.
        10583  +** then return false.
 10520  10584   **
 10521  10585   ** When this routine was originally written it dealt with only
 10522  10586   ** 32-bit numbers.  At that time, it was much faster than the
 10523  10587   ** atoi() library routine in RedHat 7.2.
 10524  10588   */
 10525         -static int sqlite3Atoi64(const char *zNum, i64 *pNum){
        10589  +SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum){
 10526  10590     i64 v = 0;
 10527  10591     int neg;
 10528  10592     int i, c;
 10529  10593     while( isspace(*(u8*)zNum) ) zNum++;
 10530  10594     if( *zNum=='-' ){
 10531  10595       neg = 1;
 10532  10596       zNum++;
 10533  10597     }else if( *zNum=='+' ){
 10534  10598       neg = 0;
 10535  10599       zNum++;
 10536  10600     }else{
 10537  10601       neg = 0;
 10538  10602     }
        10603  +  while( zNum[0]=='0' ){ zNum++; } /* Skip over leading zeros. Ticket #2454 */
 10539  10604     for(i=0; (c=zNum[i])>='0' && c<='9'; i++){
 10540  10605       v = v*10 + c - '0';
 10541  10606     }
 10542  10607     *pNum = neg ? -v : v;
 10543         -  return c==0 && i>0 && 
 10544         -      (i<19 || (i==19 && memcmp(zNum,"9223372036854775807",19)<=0));
 10545         -}
 10546         -
 10547         -/*
 10548         -** The string zNum represents an integer.  There might be some other
 10549         -** information following the integer too, but that part is ignored.
 10550         -** If the integer that the prefix of zNum represents will fit in a
 10551         -** 32-bit signed integer, return TRUE.  Otherwise return FALSE.
 10552         -**
 10553         -** This routine returns FALSE for the string -2147483648 even that
 10554         -** that number will in fact fit in a 32-bit integer.  But positive
 10555         -** 2147483648 will not fit in 32 bits.  So it seems safer to return
 10556         -** false.
 10557         -*/
 10558         -static int sqlite3FitsIn32Bits(const char *zNum){
 10559         -  int i, c;
 10560         -  if( *zNum=='-' || *zNum=='+' ) zNum++;
 10561         -  for(i=0; (c=zNum[i])>='0' && c<='9'; i++){}
 10562         -  return i<10 || (i==10 && memcmp(zNum,"2147483647",10)<=0);
 10563         -}
 10564         -
 10565         -/*
 10566         -** If zNum represents an integer that will fit in 32-bits, then set
 10567         -** *pValue to that integer and return true.  Otherwise return false.
 10568         -*/
 10569         -static int sqlite3GetInt32(const char *zNum, int *pValue){
 10570         -  if( sqlite3FitsIn32Bits(zNum) ){
 10571         -    *pValue = atoi(zNum);
 10572         -    return 1;
 10573         -  }
 10574         -  return 0;
        10608  +  if( c!=0 || i==0 || i>19 ){
        10609  +    /* zNum is empty or contains non-numeric text or is longer
        10610  +    ** than 19 digits (thus guaranting that it is too large) */
        10611  +    return 0;
        10612  +  }else if( i<19 ){
        10613  +    /* Less than 19 digits, so we know that it fits in 64 bits */
        10614  +    return 1;
        10615  +  }else{
        10616  +    /* 19-digit numbers must be no larger than 9223372036854775807 if positive
        10617  +    ** or 9223372036854775808 if negative.  Note that 9223372036854665808
        10618  +    ** is 2^63. */
        10619  +    return compare2pow63(zNum)<neg;
        10620  +  }
 10575  10621   }
 10576  10622   
 10577  10623   /*
 10578  10624   ** The string zNum represents an integer.  There might be some other
 10579  10625   ** information following the integer too, but that part is ignored.
 10580  10626   ** If the integer that the prefix of zNum represents will fit in a
 10581  10627   ** 64-bit signed integer, return TRUE.  Otherwise return FALSE.
 10582  10628   **
 10583  10629   ** This routine returns FALSE for the string -9223372036854775808 even that
 10584  10630   ** that number will, in theory fit in a 64-bit integer.  Positive
 10585  10631   ** 9223373036854775808 will not fit in 64 bits.  So it seems safer to return
 10586  10632   ** false.
 10587  10633   */
 10588         -static int sqlite3FitsIn64Bits(const char *zNum){
        10634  +SQLITE_PRIVATE int sqlite3FitsIn64Bits(const char *zNum){
 10589  10635     int i, c;
 10590         -  if( *zNum=='-' || *zNum=='+' ) zNum++;
        10636  +  int neg = 0;
        10637  +  if( *zNum=='-' ){
        10638  +    neg = 1;
        10639  +    zNum++;
        10640  +  }else if( *zNum=='+' ){
        10641  +    zNum++;
        10642  +  }
        10643  +  while( *zNum=='0' ){
        10644  +    zNum++;   /* Skip leading zeros.  Ticket #2454 */
        10645  +  }
 10591  10646     for(i=0; (c=zNum[i])>='0' && c<='9'; i++){}
 10592         -  return i<19 || (i==19 && memcmp(zNum,"9223372036854775807",19)<=0);
        10647  +  if( i<19 ){
        10648  +    /* Guaranteed to fit if less than 19 digits */
        10649  +    return 1;
        10650  +  }else if( i>19 ){
        10651  +    /* Guaranteed to be too big if greater than 19 digits */
        10652  +    return 0;
        10653  +  }else{
        10654  +    /* Compare against 2^63. */
        10655  +    return compare2pow63(zNum)<neg;
        10656  +  }
 10593  10657   }
 10594  10658   
        10659  +/*
        10660  +** If zNum represents an integer that will fit in 32-bits, then set
        10661  +** *pValue to that integer and return true.  Otherwise return false.
        10662  +**
        10663  +** Any non-numeric characters that following zNum are ignored.
        10664  +** This is different from sqlite3Atoi64() which requires the
        10665  +** input number to be zero-terminated.
        10666  +*/
        10667  +SQLITE_PRIVATE int sqlite3GetInt32(const char *zNum, int *pValue){
        10668  +  sqlite_int64 v = 0;
        10669  +  int i, c;
        10670  +  int neg = 0;
        10671  +  if( zNum[0]=='-' ){
        10672  +    neg = 1;
        10673  +    zNum++;
        10674  +  }else if( zNum[0]=='+' ){
        10675  +    zNum++;
        10676  +  }
        10677  +  while( zNum[0]=='0' ) zNum++;
        10678  +  for(i=0; i<10 && (c = zNum[i] - '0')>=0 && c<=9; i++){
        10679  +    v = v*10 + c;
        10680  +  }
        10681  +  if( i>9 ){
        10682  +    return 0;
        10683  +  }
        10684  +  if( v-neg>2147483647 ){
        10685  +    return 0;
        10686  +  }
        10687  +  if( neg ){
        10688  +    v = -v;
        10689  +  }
        10690  +  *pValue = (int)v;
        10691  +  return 1;
        10692  +}
 10595  10693   
 10596  10694   /*
 10597  10695   ** Check to make sure we have a valid db pointer.  This test is not
 10598  10696   ** foolproof but it does provide some measure of protection against
 10599  10697   ** misuse of the interface such as passing in db pointers that are
 10600  10698   ** NULL or which have been previously closed.  If this routine returns
 10601  10699   ** TRUE it means that the db pointer is invalid and should not be
 10602  10700   ** dereferenced for any reason.  The calling function should invoke
 10603  10701   ** SQLITE_MISUSE immediately.
 10604  10702   */
 10605         -static int sqlite3SafetyCheck(sqlite3 *db){
        10703  +SQLITE_PRIVATE int sqlite3SafetyCheck(sqlite3 *db){
 10606  10704     int magic;
 10607  10705     if( db==0 ) return 1;
 10608  10706     magic = db->magic;
 10609  10707     if( magic!=SQLITE_MAGIC_CLOSED &&
 10610  10708            magic!=SQLITE_MAGIC_OPEN &&
 10611  10709            magic!=SQLITE_MAGIC_BUSY ) return 1;
 10612  10710     return 0;
................................................................................
 10637  10735   ** of bytes written is returned.
 10638  10736   **
 10639  10737   ** A variable-length integer consists of the lower 7 bits of each byte
 10640  10738   ** for all bytes that have the 8th bit set and one byte with the 8th
 10641  10739   ** bit clear.  Except, if we get to the 9th byte, it stores the full
 10642  10740   ** 8 bits and is the last byte.
 10643  10741   */
 10644         -static int sqlite3PutVarint(unsigned char *p, u64 v){
        10742  +SQLITE_PRIVATE int sqlite3PutVarint(unsigned char *p, u64 v){
 10645  10743     int i, j, n;
 10646  10744     u8 buf[10];
 10647  10745     if( v & (((u64)0xff000000)<<32) ){
 10648  10746       p[8] = v;
 10649  10747       v >>= 8;
 10650  10748       for(i=7; i>=0; i--){
 10651  10749         p[i] = (v & 0x7f) | 0x80;
................................................................................
 10666  10764     return n;
 10667  10765   }
 10668  10766   
 10669  10767   /*
 10670  10768   ** Read a 64-bit variable-length integer from memory starting at p[0].
 10671  10769   ** Return the number of bytes read.  The value is stored in *v.
 10672  10770   */
 10673         -static int sqlite3GetVarint(const unsigned char *p, u64 *v){
        10771  +SQLITE_PRIVATE int sqlite3GetVarint(const unsigned char *p, u64 *v){
 10674  10772     u32 x;
 10675  10773     u64 x64;
 10676  10774     int n;
 10677  10775     unsigned char c;
 10678  10776     if( ((c = p[0]) & 0x80)==0 ){
 10679  10777       *v = c;
 10680  10778       return 1;
................................................................................
 10708  10806     return n;
 10709  10807   }
 10710  10808   
 10711  10809   /*
 10712  10810   ** Read a 32-bit variable-length integer from memory starting at p[0].
 10713  10811   ** Return the number of bytes read.  The value is stored in *v.
 10714  10812   */
 10715         -static int sqlite3GetVarint32(const unsigned char *p, u32 *v){
        10813  +SQLITE_PRIVATE int sqlite3GetVarint32(const unsigned char *p, u32 *v){
 10716  10814     u32 x;
 10717  10815     int n;
 10718  10816     unsigned char c;
 10719  10817     if( ((signed char*)p)[0]>=0 ){
 10720  10818       *v = p[0];
 10721  10819       return 1;
 10722  10820     }
................................................................................
 10734  10832     return n;
 10735  10833   }
 10736  10834   
 10737  10835   /*
 10738  10836   ** Return the number of bytes that will be needed to store the given
 10739  10837   ** 64-bit integer.
 10740  10838   */
 10741         -static int sqlite3VarintLen(u64 v){
        10839  +SQLITE_PRIVATE int sqlite3VarintLen(u64 v){
 10742  10840     int i = 0;
 10743  10841     do{
 10744  10842       i++;
 10745  10843       v >>= 7;
 10746  10844     }while( v!=0 && i<9 );
 10747  10845     return i;
 10748  10846   }
 10749  10847   
 10750  10848   
 10751  10849   /*
 10752  10850   ** Read or write a four-byte big-endian integer value.
 10753  10851   */
 10754         -static u32 sqlite3Get4byte(const u8 *p){
        10852  +SQLITE_PRIVATE u32 sqlite3Get4byte(const u8 *p){
 10755  10853     return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
 10756  10854   }
 10757         -static void sqlite3Put4byte(unsigned char *p, u32 v){
        10855  +SQLITE_PRIVATE void sqlite3Put4byte(unsigned char *p, u32 v){
 10758  10856     p[0] = v>>24;
 10759  10857     p[1] = v>>16;
 10760  10858     p[2] = v>>8;
 10761  10859     p[3] = v;
 10762  10860   }
 10763  10861   
 10764  10862   
................................................................................
 10783  10881   #if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC)
 10784  10882   /*
 10785  10883   ** Convert a BLOB literal of the form "x'hhhhhh'" into its binary
 10786  10884   ** value.  Return a pointer to its binary value.  Space to hold the
 10787  10885   ** binary value has been obtained from malloc and must be freed by
 10788  10886   ** the calling routine.
 10789  10887   */
 10790         -static void *sqlite3HexToBlob(const char *z){
        10888  +SQLITE_PRIVATE void *sqlite3HexToBlob(const char *z){
 10791  10889     char *zBlob;
 10792  10890     int i;
 10793  10891     int n = strlen(z);
 10794  10892     if( n%2 ) return 0;
 10795  10893   
 10796  10894     zBlob = (char *)sqliteMalloc(n/2);
 10797  10895     if( zBlob ){
................................................................................
 10825  10923   **
 10826  10924   ** Ticket #202:  If db->magic is not a valid open value, take care not
 10827  10925   ** to modify the db structure at all.  It could be that db is a stale
 10828  10926   ** pointer.  In other words, it could be that there has been a prior
 10829  10927   ** call to sqlite3_close(db) and db has been deallocated.  And we do
 10830  10928   ** not want to write into deallocated memory.
 10831  10929   */
 10832         -static int sqlite3SafetyOn(sqlite3 *db){
        10930  +SQLITE_PRIVATE int sqlite3SafetyOn(sqlite3 *db){
 10833  10931     if( db->magic==SQLITE_MAGIC_OPEN ){
 10834  10932       db->magic = SQLITE_MAGIC_BUSY;
 10835  10933       return 0;
 10836  10934     }else if( db->magic==SQLITE_MAGIC_BUSY ){
 10837  10935       db->magic = SQLITE_MAGIC_ERROR;
 10838  10936       db->u1.isInterrupted = 1;
 10839  10937     }
................................................................................
 10841  10939   }
 10842  10940   
 10843  10941   /*
 10844  10942   ** Change the magic from SQLITE_MAGIC_BUSY to SQLITE_MAGIC_OPEN.
 10845  10943   ** Return an error (non-zero) if the magic was not SQLITE_MAGIC_BUSY
 10846  10944   ** when this routine is called.
 10847  10945   */
 10848         -static int sqlite3SafetyOff(sqlite3 *db){
        10946  +SQLITE_PRIVATE int sqlite3SafetyOff(sqlite3 *db){
 10849  10947     if( db->magic==SQLITE_MAGIC_BUSY ){
 10850  10948       db->magic = SQLITE_MAGIC_OPEN;
 10851  10949       return 0;
 10852  10950     }else {
 10853  10951       db->magic = SQLITE_MAGIC_ERROR;
 10854  10952       db->u1.isInterrupted = 1;
 10855  10953       return 1;
 10856  10954     }
 10857  10955   }
 10858  10956   
 10859  10957   /*
 10860  10958   ** Return a pointer to the ThreadData associated with the calling thread.
 10861  10959   */
 10862         -static ThreadData *sqlite3ThreadData(){
        10960  +SQLITE_PRIVATE ThreadData *sqlite3ThreadData(){
 10863  10961     ThreadData *p = (ThreadData*)sqlite3OsThreadSpecificData(1);
 10864  10962     if( !p ){
 10865  10963       sqlite3FailedMalloc();
 10866  10964     }
 10867  10965     return p;
 10868  10966   }
 10869  10967   
 10870  10968   /*
 10871  10969   ** Return a pointer to the ThreadData associated with the calling thread.
 10872  10970   ** If no ThreadData has been allocated to this thread yet, return a pointer
 10873  10971   ** to a substitute ThreadData structure that is all zeros. 
 10874  10972   */
 10875         -static const ThreadData *sqlite3ThreadDataReadOnly(){
        10973  +SQLITE_PRIVATE const ThreadData *sqlite3ThreadDataReadOnly(){
 10876  10974     static const ThreadData zeroData = {0};  /* Initializer to silence warnings
 10877  10975                                              ** from broken compilers */
 10878  10976     const ThreadData *pTd = sqlite3OsThreadSpecificData(0);
 10879  10977     return pTd ? pTd : &zeroData;
 10880  10978   }
 10881  10979   
 10882  10980   /*
 10883  10981   ** Check to see if the ThreadData for this thread is all zero.  If it
 10884  10982   ** is, then deallocate it. 
 10885  10983   */
 10886         -static void sqlite3ReleaseThreadData(){
        10984  +SQLITE_PRIVATE void sqlite3ReleaseThreadData(){
 10887  10985     sqlite3OsThreadSpecificData(-1);
 10888  10986   }
 10889  10987   
 10890  10988   /************** End of util.c ************************************************/
 10891  10989   /************** Begin file hash.c ********************************************/
 10892  10990   /*
 10893  10991   ** 2001 September 22
................................................................................
 10899  10997   **    May you find forgiveness for yourself and forgive others.
 10900  10998   **    May you share freely, never taking more than you give.
 10901  10999   **
 10902  11000   *************************************************************************
 10903  11001   ** This is the implementation of generic hash-tables
 10904  11002   ** used in SQLite.
 10905  11003   **
 10906         -** $Id: sqlite3.c,v 1.3 2007/06/19 22:43:23 rmsimpson Exp $
        11004  +** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
 10907  11005   */
 10908  11006   
 10909  11007   /* Turn bulk memory into a hash table object by initializing the
 10910  11008   ** fields of the Hash structure.
 10911  11009   **
 10912  11010   ** "pNew" is a pointer to the hash table that is to be initialized.
 10913  11011   ** keyClass is one of the constants SQLITE_HASH_INT, SQLITE_HASH_POINTER,
................................................................................
 10914  11012   ** SQLITE_HASH_BINARY, or SQLITE_HASH_STRING.  The value of keyClass 
 10915  11013   ** determines what kind of key the hash table will use.  "copyKey" is
 10916  11014   ** true if the hash table should make its own private copy of keys and
 10917  11015   ** false if it should just use the supplied pointer.  CopyKey only makes
 10918  11016   ** sense for SQLITE_HASH_STRING and SQLITE_HASH_BINARY and is ignored
 10919  11017   ** for other key classes.
 10920  11018   */
 10921         -static void sqlite3HashInit(Hash *pNew, int keyClass, int copyKey){
        11019  +SQLITE_PRIVATE void sqlite3HashInit(Hash *pNew, int keyClass, int copyKey){
 10922  11020     assert( pNew!=0 );
 10923  11021     assert( keyClass>=SQLITE_HASH_STRING && keyClass<=SQLITE_HASH_BINARY );
 10924  11022     pNew->keyClass = keyClass;
 10925  11023   #if 0
 10926  11024     if( keyClass==SQLITE_HASH_POINTER || keyClass==SQLITE_HASH_INT ) copyKey = 0;
 10927  11025   #endif
 10928  11026     pNew->copyKey = copyKey;
................................................................................
 10934  11032     pNew->xFree = sqlite3FreeX;
 10935  11033   }
 10936  11034   
 10937  11035   /* Remove all entries from a hash table.  Reclaim all memory.
 10938  11036   ** Call this routine to delete a hash table or to reset a hash table
 10939  11037   ** to the empty state.
 10940  11038   */
 10941         -static void sqlite3HashClear(Hash *pH){
        11039  +SQLITE_PRIVATE void sqlite3HashClear(Hash *pH){
 10942  11040     HashElem *elem;         /* For looping over all elements of the table */
 10943  11041   
 10944  11042     assert( pH!=0 );
 10945  11043     elem = pH->first;
 10946  11044     pH->first = 0;
 10947  11045     if( pH->ht ) pH->xFree(pH->ht);
 10948  11046     pH->ht = 0;
................................................................................
 11192  11290     }
 11193  11291   }
 11194  11292   
 11195  11293   /* Attempt to locate an element of the hash table pH with a key
 11196  11294   ** that matches pKey,nKey.  Return the data for this element if it is
 11197  11295   ** found, or NULL if there is no match.
 11198  11296   */
 11199         -static void *sqlite3HashFind(const Hash *pH, const void *pKey, int nKey){
        11297  +SQLITE_PRIVATE void *sqlite3HashFind(const Hash *pH, const void *pKey, int nKey){
 11200  11298     int h;             /* A hash on key */
 11201  11299     HashElem *elem;    /* The element that matches key */
 11202  11300     int (*xHash)(const void*,int);  /* The hash function */
 11203  11301   
 11204  11302     if( pH==0 || pH->ht==0 ) return 0;
 11205  11303     xHash = hashFunction(pH->keyClass);
 11206  11304     assert( xHash!=0 );
................................................................................
 11221  11319   ** new data replaces the old data and the old data is returned.
 11222  11320   ** The key is not copied in this instance.  If a malloc fails, then
 11223  11321   ** the new data is returned and the hash table is unchanged.
 11224  11322   **
 11225  11323   ** If the "data" parameter to this function is NULL, then the
 11226  11324   ** element corresponding to "key" is removed from the hash table.
 11227  11325   */
 11228         -static void *sqlite3HashInsert(Hash *pH, const void *pKey, int nKey, void *data){
        11326  +SQLITE_PRIVATE void *sqlite3HashInsert(Hash *pH, const void *pKey, int nKey, void *data){
 11229  11327     int hraw;             /* Raw hash value of the key */
 11230  11328     int h;                /* the hash of the key modulo hash table size */
 11231  11329     HashElem *elem;       /* Used to loop thru the element list */
 11232  11330     HashElem *new_elem;   /* New element added to the pH */
 11233  11331     int (*xHash)(const void*,int);  /* The hash function */
 11234  11332   
 11235  11333     assert( pH!=0 );
................................................................................
 11314  11412    /*  21 */ "Noop",
 11315  11413    /*  22 */ "Return",
 11316  11414    /*  23 */ "NewRowid",
 11317  11415    /*  24 */ "IfMemNeg",
 11318  11416    /*  25 */ "Variable",
 11319  11417    /*  26 */ "String",
 11320  11418    /*  27 */ "RealAffinity",
 11321         - /*  28 */ "ParseSchema",
 11322         - /*  29 */ "VOpen",
 11323         - /*  30 */ "Close",
 11324         - /*  31 */ "CreateIndex",
 11325         - /*  32 */ "IsUnique",
 11326         - /*  33 */ "NotFound",
 11327         - /*  34 */ "Int64",
 11328         - /*  35 */ "MustBeInt",
 11329         - /*  36 */ "Halt",
 11330         - /*  37 */ "Rowid",
 11331         - /*  38 */ "IdxLT",
 11332         - /*  39 */ "AddImm",
 11333         - /*  40 */ "Statement",
 11334         - /*  41 */ "RowData",
 11335         - /*  42 */ "MemMax",
 11336         - /*  43 */ "Push",
 11337         - /*  44 */ "NotExists",
 11338         - /*  45 */ "MemIncr",
 11339         - /*  46 */ "Gosub",
 11340         - /*  47 */ "Integer",
 11341         - /*  48 */ "MemInt",
 11342         - /*  49 */ "Prev",
 11343         - /*  50 */ "VColumn",
 11344         - /*  51 */ "CreateTable",
 11345         - /*  52 */ "Last",
 11346         - /*  53 */ "IncrVacuum",
 11347         - /*  54 */ "IdxRowid",
 11348         - /*  55 */ "MakeIdxRec",
 11349         - /*  56 */ "ResetCount",
 11350         - /*  57 */ "FifoWrite",
 11351         - /*  58 */ "Callback",
 11352         - /*  59 */ "ContextPush",
        11419  + /*  28 */ "VRename",
        11420  + /*  29 */ "ParseSchema",
        11421  + /*  30 */ "VOpen",
        11422  + /*  31 */ "Close",
        11423  + /*  32 */ "CreateIndex",
        11424  + /*  33 */ "IsUnique",
        11425  + /*  34 */ "NotFound",
        11426  + /*  35 */ "Int64",
        11427  + /*  36 */ "MustBeInt",
        11428  + /*  37 */ "Halt",
        11429  + /*  38 */ "Rowid",
        11430  + /*  39 */ "IdxLT",
        11431  + /*  40 */ "AddImm",
        11432  + /*  41 */ "Statement",
        11433  + /*  42 */ "RowData",
        11434  + /*  43 */ "MemMax",
        11435  + /*  44 */ "Push",
        11436  + /*  45 */ "NotExists",
        11437  + /*  46 */ "MemIncr",
        11438  + /*  47 */ "Gosub",
        11439  + /*  48 */ "Integer",
        11440  + /*  49 */ "MemInt",
        11441  + /*  50 */ "Prev",
        11442  + /*  51 */ "VColumn",
        11443  + /*  52 */ "CreateTable",
        11444  + /*  53 */ "Last",
        11445  + /*  54 */ "IncrVacuum",
        11446  + /*  55 */ "IdxRowid",
        11447  + /*  56 */ "MakeIdxRec",
        11448  + /*  57 */ "ResetCount",
        11449  + /*  58 */ "FifoWrite",
        11450  + /*  59 */ "Callback",
 11353  11451    /*  60 */ "Or",
 11354  11452    /*  61 */ "And",
 11355         - /*  62 */ "DropTrigger",
 11356         - /*  63 */ "DropIndex",
 11357         - /*  64 */ "IdxGE",
        11453  + /*  62 */ "ContextPush",
        11454  + /*  63 */ "DropTrigger",
        11455  + /*  64 */ "DropIndex",
 11358  11456    /*  65 */ "IsNull",
 11359  11457    /*  66 */ "NotNull",
 11360  11458    /*  67 */ "Ne",
 11361  11459    /*  68 */ "Eq",
 11362  11460    /*  69 */ "Gt",
 11363  11461    /*  70 */ "Le",
 11364  11462    /*  71 */ "Lt",
 11365  11463    /*  72 */ "Ge",
 11366         - /*  73 */ "IdxDelete",
        11464  + /*  73 */ "IdxGE",
 11367  11465    /*  74 */ "BitAnd",
 11368  11466    /*  75 */ "BitOr",
 11369  11467    /*  76 */ "ShiftLeft",
 11370  11468    /*  77 */ "ShiftRight",
 11371  11469    /*  78 */ "Add",
 11372  11470    /*  79 */ "Subtract",
 11373  11471    /*  80 */ "Multiply",
 11374  11472    /*  81 */ "Divide",
 11375  11473    /*  82 */ "Remainder",
 11376  11474    /*  83 */ "Concat",
 11377         - /*  84 */ "Vacuum",
        11475  + /*  84 */ "IdxDelete",
 11378  11476    /*  85 */ "Negative",
 11379         - /*  86 */ "MoveLe",
        11477  + /*  86 */ "Vacuum",
 11380  11478    /*  87 */ "BitNot",
 11381  11479    /*  88 */ "String8",
 11382         - /*  89 */ "IfNot",
 11383         - /*  90 */ "DropTable",
 11384         - /*  91 */ "MakeRecord",
 11385         - /*  92 */ "Delete",
 11386         - /*  93 */ "AggFinal",
 11387         - /*  94 */ "Dup",
 11388         - /*  95 */ "Goto",
 11389         - /*  96 */ "TableLock",
 11390         - /*  97 */ "FifoRead",
 11391         - /*  98 */ "Clear",
 11392         - /*  99 */ "IdxGT",
 11393         - /* 100 */ "MoveLt",
 11394         - /* 101 */ "VerifyCookie",
 11395         - /* 102 */ "AggStep",
 11396         - /* 103 */ "Pull",
 11397         - /* 104 */ "SetNumColumns",
 11398         - /* 105 */ "AbsValue",
 11399         - /* 106 */ "Transaction",
 11400         - /* 107 */ "VFilter",
 11401         - /* 108 */ "VDestroy",
 11402         - /* 109 */ "ContextPop",
 11403         - /* 110 */ "Next",
 11404         - /* 111 */ "IdxInsert",
 11405         - /* 112 */ "Distinct",
 11406         - /* 113 */ "Insert",
 11407         - /* 114 */ "Destroy",
 11408         - /* 115 */ "ReadCookie",
 11409         - /* 116 */ "ForceInt",
 11410         - /* 117 */ "LoadAnalysis",
 11411         - /* 118 */ "Explain",
 11412         - /* 119 */ "IfMemZero",
 11413         - /* 120 */ "OpenPseudo",
 11414         - /* 121 */ "OpenEphemeral",
 11415         - /* 122 */ "Null",
 11416         - /* 123 */ "Blob",
 11417         - /* 124 */ "MemStore",
        11480  + /*  89 */ "MoveLe",
        11481  + /*  90 */ "IfNot",
        11482  + /*  91 */ "DropTable",
        11483  + /*  92 */ "MakeRecord",
        11484  + /*  93 */ "Delete",
        11485  + /*  94 */ "AggFinal",
        11486  + /*  95 */ "Dup",
        11487  + /*  96 */ "Goto",
        11488  + /*  97 */ "TableLock",
        11489  + /*  98 */ "FifoRead",
        11490  + /*  99 */ "Clear",
        11491  + /* 100 */ "IdxGT",
        11492  + /* 101 */ "MoveLt",
        11493  + /* 102 */ "VerifyCookie",
        11494  + /* 103 */ "AggStep",
        11495  + /* 104 */ "Pull",
        11496  + /* 105 */ "SetNumColumns",
        11497  + /* 106 */ "AbsValue",
        11498  + /* 107 */ "Transaction",
        11499  + /* 108 */ "VFilter",
        11500  + /* 109 */ "VDestroy",
        11501  + /* 110 */ "ContextPop",
        11502  + /* 111 */ "Next",
        11503  + /* 112 */ "IdxInsert",
        11504  + /* 113 */ "Distinct",
        11505  + /* 114 */ "Insert",
        11506  + /* 115 */ "Destroy",
        11507  + /* 116 */ "ReadCookie",
        11508  + /* 117 */ "ForceInt",
        11509  + /* 118 */ "LoadAnalysis",
        11510  + /* 119 */ "Explain",
        11511  + /* 120 */ "IfMemZero",
        11512  + /* 121 */ "OpenPseudo",
        11513  + /* 122 */ "OpenEphemeral",
        11514  + /* 123 */ "Null",
        11515  + /* 124 */ "Blob",
 11418  11516    /* 125 */ "Real",
 11419  11517    /* 126 */ "HexBlob",
 11420         - /* 127 */ "Rewind",
 11421         - /* 128 */ "MoveGe",
 11422         - /* 129 */ "VBegin",
 11423         - /* 130 */ "VUpdate",
 11424         - /* 131 */ "VCreate",
 11425         - /* 132 */ "MemMove",
 11426         - /* 133 */ "MemNull",
 11427         - /* 134 */ "Found",
 11428         - /* 135 */ "NullRow",
 11429         - /* 136 */ "NotUsed_136",
        11518  + /* 127 */ "MemStore",
        11519  + /* 128 */ "Rewind",
        11520  + /* 129 */ "MoveGe",
        11521  + /* 130 */ "VBegin",
        11522  + /* 131 */ "VUpdate",
        11523  + /* 132 */ "VCreate",
        11524  + /* 133 */ "MemMove",
        11525  + /* 134 */ "MemNull",
        11526  + /* 135 */ "Found",
        11527  + /* 136 */ "NullRow",
 11430  11528    /* 137 */ "NotUsed_137",
 11431  11529    /* 138 */ "ToText",
 11432  11530    /* 139 */ "ToBlob",
 11433  11531    /* 140 */ "ToNumeric",
 11434  11532    /* 141 */ "ToInt",
 11435  11533    /* 142 */ "ToReal",
 11436  11534   };
................................................................................
 11449  11547   **    May you share freely, never taking more than you give.
 11450  11548   **
 11451  11549   ******************************************************************************
 11452  11550   **
 11453  11551   ** This file contains code that is specific to OS/2.
 11454  11552   */
 11455  11553   
 11456         -#if (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 3) && defined(OS2_HIGH_MEMORY)
 11457         -/* os2safe.h has to be included before os2.h, needed for high mem */
 11458         -#include <os2safe.h>
 11459         -#endif
 11460         -
 11461  11554   
 11462  11555   #if OS_OS2
 11463  11556   
 11464  11557   /*
 11465  11558   ** Macros used to determine whether or not to use threads.
 11466  11559   */
 11467  11560   #if defined(THREADSAFE) && THREADSAFE
................................................................................
 11616  11709   ** enabled. This version allocates an extra 8-bytes at the beginning of each
 11617  11710   ** block and stores the size of the allocation there.
 11618  11711   **
 11619  11712   ** If neither memory-management or debugging is enabled, the second
 11620  11713   ** set of implementations is used instead.
 11621  11714   */
 11622  11715   #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) || defined (SQLITE_MEMDEBUG)
 11623         -static void *sqlite3GenericMalloc(int n){
        11716  +SQLITE_PRIVATE void *sqlite3GenericMalloc(int n){
 11624  11717     char *p = (char *)malloc(n+8);
 11625  11718     assert(n>0);
 11626  11719     assert(sizeof(int)<=8);
 11627  11720     if( p ){
 11628  11721       *(int *)p = n;
 11629  11722       p += 8;
 11630  11723     }
 11631  11724     return (void *)p;
 11632  11725   }
 11633         -static void *sqlite3GenericRealloc(void *p, int n){
        11726  +SQLITE_PRIVATE void *sqlite3GenericRealloc(void *p, int n){
 11634  11727     char *p2 = ((char *)p - 8);
 11635  11728     assert(n>0);
 11636  11729     p2 = (char*)realloc(p2, n+8);
 11637  11730     if( p2 ){
 11638  11731       *(int *)p2 = n;
 11639  11732       p2 += 8;
 11640  11733     }
 11641  11734     return (void *)p2;
 11642  11735   }
 11643         -static void sqlite3GenericFree(void *p){
        11736  +SQLITE_PRIVATE void sqlite3GenericFree(void *p){
 11644  11737     assert(p);
 11645  11738     free((void *)((char *)p - 8));
 11646  11739   }
 11647         -static int sqlite3GenericAllocationSize(void *p){
        11740  +SQLITE_PRIVATE int sqlite3GenericAllocationSize(void *p){
 11648  11741     return p ? *(int *)((char *)p - 8) : 0;
 11649  11742   }
 11650  11743   #else
 11651         -static void *sqlite3GenericMalloc(int n){
        11744  +SQLITE_PRIVATE void *sqlite3GenericMalloc(int n){
 11652  11745     char *p = (char *)malloc(n);
 11653  11746     return (void *)p;
 11654  11747   }
 11655         -static void *sqlite3GenericRealloc(void *p, int n){
        11748  +SQLITE_PRIVATE void *sqlite3GenericRealloc(void *p, int n){
 11656  11749     assert(n>0);
 11657  11750     p = realloc(p, n);
 11658  11751     return p;
 11659  11752   }
 11660         -static void sqlite3GenericFree(void *p){
        11753  +SQLITE_PRIVATE void sqlite3GenericFree(void *p){
 11661  11754     assert(p);
 11662  11755     free(p);
 11663  11756   }
 11664  11757   /* Never actually used, but needed for the linker */
 11665         -static int sqlite3GenericAllocationSize(void *p){ return 0; }
        11758  +SQLITE_PRIVATE int sqlite3GenericAllocationSize(void *p){ return 0; }
 11666  11759   #endif
 11667  11760   
 11668  11761   /*
 11669  11762   ** The default size of a disk sector
 11670  11763   */
 11671  11764   #ifndef PAGER_SECTOR_SIZE
 11672  11765   # define PAGER_SECTOR_SIZE 512
................................................................................
 11694  11787   ** will be in-memory only)
 11695  11788   */
 11696  11789   #ifndef SQLITE_OMIT_DISKIO
 11697  11790   
 11698  11791   /*
 11699  11792   ** Delete the named file
 11700  11793   */
 11701         -static int sqlite3Os2Delete( const char *zFilename ){
        11794  +SQLITE_PRIVATE int sqlite3Os2Delete( const char *zFilename ){
 11702  11795     APIRET rc = NO_ERROR;
 11703  11796   
 11704  11797     rc = DosDelete( (PSZ)zFilename );
 11705  11798     OSTRACE2( "DELETE \"%s\"\n", zFilename );
 11706  11799     return rc == NO_ERROR ? SQLITE_OK : SQLITE_IOERR;
 11707  11800   }
 11708  11801   
 11709  11802   /*
 11710  11803   ** Return TRUE if the named file exists.
 11711  11804   */
 11712         -static int sqlite3Os2FileExists( const char *zFilename ){
        11805  +SQLITE_PRIVATE int sqlite3Os2FileExists( const char *zFilename ){
 11713  11806     FILESTATUS3 fsts3ConfigInfo;
 11714  11807     memset(&fsts3ConfigInfo, 0, sizeof(fsts3ConfigInfo));
 11715  11808     return DosQueryPathInfo( (PSZ)zFilename, FIL_STANDARD,
 11716  11809           &fsts3ConfigInfo, sizeof(FILESTATUS3) ) == NO_ERROR;
 11717  11810   }
 11718  11811   
 11719  11812   /* Forward declaration */
................................................................................
 11728  11821   ** and *pReadonly is set to 0 if the file was opened for reading and
 11729  11822   ** writing or 1 if the file was opened read-only.  The function returns
 11730  11823   ** SQLITE_OK.
 11731  11824   **
 11732  11825   ** On failure, the function returns SQLITE_CANTOPEN and leaves
 11733  11826   ** *id and *pReadonly unchanged.
 11734  11827   */
 11735         -static int sqlite3Os2OpenReadWrite(
        11828  +SQLITE_PRIVATE int sqlite3Os2OpenReadWrite(
 11736  11829     const char *zFilename,
 11737  11830     OsFile **pld,
 11738  11831     int *pReadonly
 11739  11832   ){
 11740  11833     os2File  f;
 11741  11834     HFILE    hf;
 11742  11835     ULONG    ulAction;
................................................................................
 11782  11875   ** If delFlag is true, then make arrangements to automatically delete
 11783  11876   ** the file when it is closed.
 11784  11877   **
 11785  11878   ** On success, write the file handle into *id and return SQLITE_OK.
 11786  11879   **
 11787  11880   ** On failure, return SQLITE_CANTOPEN.
 11788  11881   */
 11789         -static int sqlite3Os2OpenExclusive( const char *zFilename, OsFile **pld, int delFlag ){
        11882  +SQLITE_PRIVATE int sqlite3Os2OpenExclusive( const char *zFilename, OsFile **pld, int delFlag ){
 11790  11883     os2File  f;
 11791  11884     HFILE    hf;
 11792  11885     ULONG    ulAction;
 11793  11886     APIRET   rc = NO_ERROR;
 11794  11887   
 11795  11888     assert( *pld == 0 );
 11796  11889     rc = DosOpen( (PSZ)zFilename, &hf, &ulAction, 0L, FILE_NORMAL,
................................................................................
 11802  11895     }
 11803  11896   
 11804  11897     f.h = hf;
 11805  11898     f.locktype = NO_LOCK;
 11806  11899     f.delOnClose = delFlag ? 1 : 0;
 11807  11900     f.pathToDel = delFlag ? sqlite3OsFullPathname( zFilename ) : NULL;
 11808  11901     OpenCounter( +1 );
 11809         -  if( delFlag ) DosForceDelete( sqlite3OsFullPathname( zFilename ) );
        11902  +  if( delFlag ) DosForceDelete( (PSZ)sqlite3OsFullPathname( zFilename ) );
 11810  11903     OSTRACE3( "OPEN EX %d \"%s\"\n", hf, sqlite3OsFullPathname ( zFilename ) );
 11811  11904     return allocateOs2File( &f, pld );
 11812  11905   }
 11813  11906   
 11814  11907   /*
 11815  11908   ** Attempt to open a new file for read-only access.
 11816  11909   **
 11817  11910   ** On success, write the file handle into *id and return SQLITE_OK.
 11818  11911   **
 11819  11912   ** On failure, return SQLITE_CANTOPEN.
 11820  11913   */
 11821         -static int sqlite3Os2OpenReadOnly( const char *zFilename, OsFile **pld ){
        11914  +SQLITE_PRIVATE int sqlite3Os2OpenReadOnly( const char *zFilename, OsFile **pld ){
 11822  11915     os2File  f;
 11823  11916     HFILE    hf;
 11824  11917     ULONG    ulAction;
 11825  11918     APIRET   rc = NO_ERROR;
 11826  11919   
 11827  11920     assert( *pld == 0 );
 11828  11921     rc = DosOpen( (PSZ)zFilename, &hf, &ulAction, 0L,
................................................................................
 11864  11957     return SQLITE_OK;
 11865  11958   }
 11866  11959   
 11867  11960   /*
 11868  11961   ** Create a temporary file name in zBuf.  zBuf must be big enough to
 11869  11962   ** hold at least SQLITE_TEMPNAME_SIZE characters.
 11870  11963   */
 11871         -static int sqlite3Os2TempFileName( char *zBuf ){
        11964  +SQLITE_PRIVATE int sqlite3Os2TempFileName( char *zBuf ){
 11872  11965     static const unsigned char zChars[] =
 11873  11966       "abcdefghijklmnopqrstuvwxyz"
 11874  11967       "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 11875  11968       "0123456789";
 11876  11969     int i, j;
 11877  11970     PSZ zTempPath = 0;
 11878         -  if( DosScanEnv( "TEMP", &zTempPath ) ){
 11879         -    if( DosScanEnv( "TMP", &zTempPath ) ){
 11880         -      if( DosScanEnv( "TMPDIR", &zTempPath ) ){
        11971  +  if( DosScanEnv( (PSZ)"TEMP", &zTempPath ) ){
        11972  +    if( DosScanEnv( (PSZ)"TMP", &zTempPath ) ){
        11973  +      if( DosScanEnv( (PSZ)"TMPDIR", &zTempPath ) ){
 11881  11974              ULONG ulDriveNum = 0, ulDriveMap = 0;
 11882  11975              DosQueryCurrentDisk( &ulDriveNum, &ulDriveMap );
 11883         -           sprintf( zTempPath, "%c:", (char)( 'A' + ulDriveNum - 1 ) );
        11976  +           sprintf( (char*)zTempPath, "%c:", (char)( 'A' + ulDriveNum - 1 ) );
 11884  11977         }
 11885  11978       }
 11886  11979     }
 11887  11980     for(;;){
 11888  11981         sprintf( zBuf, "%s\\"TEMP_FILE_PREFIX, zTempPath );
 11889  11982         j = strlen( zBuf );
 11890  11983         sqlite3Randomness( 15, &zBuf[j] );
................................................................................
 11905  11998     os2File *pFile;
 11906  11999     APIRET rc = NO_ERROR;
 11907  12000     if( pld && (pFile = (os2File*)*pld) != 0 ){
 11908  12001       OSTRACE2( "CLOSE %d\n", pFile->h );
 11909  12002       rc = DosClose( pFile->h );
 11910  12003       pFile->locktype = NO_LOCK;
 11911  12004       if( pFile->delOnClose != 0 ){
 11912         -        rc = DosForceDelete( pFile->pathToDel );
        12005  +        rc = DosForceDelete( (PSZ)pFile->pathToDel );
 11913  12006       }
 11914  12007       *pld = 0;
 11915  12008       OpenCounter( -1 );
 11916  12009     }
 11917  12010   
 11918  12011     return rc == NO_ERROR ? SQLITE_OK : SQLITE_IOERR;
 11919  12012   }
................................................................................
 11927  12020     ULONG got;
 11928  12021     assert( id!=0 );
 11929  12022     SimulateIOError( return SQLITE_IOERR );
 11930  12023     OSTRACE3( "READ %d lock=%d\n", ((os2File*)id)->h, ((os2File*)id)->locktype );
 11931  12024     DosRead( ((os2File*)id)->h, pBuf, amt, &got );
 11932  12025     if (got == (ULONG)amt)
 11933  12026       return SQLITE_OK;
 11934         -  else if (got < 0)
        12027  +  else if (got == 0)
 11935  12028       return SQLITE_IOERR_READ;
 11936  12029     else {
 11937  12030       memset(&((char*)pBuf)[got], 0, amt-got);
 11938  12031       return SQLITE_IOERR_SHORT_READ;
 11939  12032     }
 11940  12033   }
 11941  12034   
................................................................................
 11980  12073     return DosResetBuffer( ((os2File*)id)->h ) == NO_ERROR ? SQLITE_OK : SQLITE_IOERR;
 11981  12074   }
 11982  12075   
 11983  12076   /*
 11984  12077   ** Sync the directory zDirname. This is a no-op on operating systems other
 11985  12078   ** than UNIX.
 11986  12079   */
 11987         -static int sqlite3Os2SyncDirectory( const char *zDirname ){
        12080  +SQLITE_PRIVATE int sqlite3Os2SyncDirectory( const char *zDirname ){
 11988  12081     SimulateIOError( return SQLITE_IOERR );
 11989  12082     return SQLITE_OK;
 11990  12083   }
 11991  12084   
 11992  12085   /*
 11993  12086   ** Truncate an open file to a specified size
 11994  12087   */
................................................................................
 12056  12149   }
 12057  12150   
 12058  12151   #ifndef SQLITE_OMIT_PAGER_PRAGMAS
 12059  12152   /*
 12060  12153   ** Check that a given pathname is a directory and is writable
 12061  12154   **
 12062  12155   */
 12063         -static int sqlite3Os2IsDirWritable( char *zDirname ){
        12156  +SQLITE_PRIVATE int sqlite3Os2IsDirWritable( char *zDirname ){
 12064  12157     FILESTATUS3 fsts3ConfigInfo;
 12065  12158     APIRET rc = NO_ERROR;
 12066  12159     memset(&fsts3ConfigInfo, 0, sizeof(fsts3ConfigInfo));
 12067  12160     if( zDirname==0 ) return 0;
 12068  12161     if( strlen(zDirname)>CCHMAXPATH ) return 0;
 12069  12162     rc = DosQueryPathInfo( (PSZ)zDirname, FIL_STANDARD, &fsts3ConfigInfo, sizeof(FILESTATUS3) );
 12070  12163     if( rc != NO_ERROR ) return 0;
................................................................................
 12318  12411   
 12319  12412   /*
 12320  12413   ** Turn a relative pathname into a full pathname.  Return a pointer
 12321  12414   ** to the full pathname stored in space obtained from sqliteMalloc().
 12322  12415   ** The calling function is responsible for freeing this space once it
 12323  12416   ** is no longer needed.
 12324  12417   */
 12325         -static char *sqlite3Os2FullPathname( const char *zRelative ){
        12418  +SQLITE_PRIVATE char *sqlite3Os2FullPathname( const char *zRelative ){
 12326  12419     char *zFull = 0;
 12327  12420     if( strchr(zRelative, ':') ){
 12328  12421       sqlite3SetString( &zFull, zRelative, (char*)0 );
 12329  12422     }else{
 12330         -    char zBuff[SQLITE_TEMPNAME_SIZE - 2] = {0};
 12331         -    char zDrive[1] = {0};
 12332         -    ULONG cbzFullLen = SQLITE_TEMPNAME_SIZE;
 12333  12423       ULONG ulDriveNum = 0;
 12334  12424       ULONG ulDriveMap = 0;
 12335         -    DosQueryCurrentDisk( &ulDriveNum, &ulDriveMap );
 12336         -    DosQueryCurrentDir( 0L, zBuff, &cbzFullLen );
 12337         -    zFull = sqliteMalloc( cbzFullLen );
 12338         -    sprintf( zDrive, "%c", (char)('A' + ulDriveNum - 1) );
 12339         -    sqlite3SetString( &zFull, zDrive, ":\\", zBuff, "\\", zRelative, (char*)0 );
        12425  +    ULONG cbzBufLen = SQLITE_TEMPNAME_SIZE;
        12426  +    char zDrive[2];
        12427  +    char *zBuff;
        12428  +
        12429  +    zBuff = sqliteMalloc( cbzBufLen );
        12430  +    if( zBuff != 0 ){
        12431  +      DosQueryCurrentDisk( &ulDriveNum, &ulDriveMap );
        12432  +      if( DosQueryCurrentDir( ulDriveNum, (PBYTE)zBuff, &cbzBufLen ) == NO_ERROR ){
        12433  +        sprintf( zDrive, "%c", (char)('A' + ulDriveNum - 1) );
        12434  +        sqlite3SetString( &zFull, zDrive, ":\\", zBuff,
        12435  +                          "\\", zRelative, (char*)0 );
        12436  +      }
        12437  +      sqliteFree( zBuff );
        12438  +    }
 12340  12439     }
 12341  12440     return zFull;
 12342  12441   }
 12343  12442   
 12344  12443   /*
 12345  12444   ** The fullSync option is meaningless on os2, or correct me if I'm wrong.  This is a no-op.
 12346  12445   ** From os_unix.c: Change the value of the fullsync flag in the given file descriptor.
................................................................................
 12430  12529   ****************************************************************************/
 12431  12530   
 12432  12531   #ifndef SQLITE_OMIT_LOAD_EXTENSION
 12433  12532   /*
 12434  12533   ** Interfaces for opening a shared library, finding entry points
 12435  12534   ** within the shared library, and closing the shared library.
 12436  12535   */
 12437         -static void *sqlite3Os2Dlopen(const char *zFilename){
        12536  +SQLITE_PRIVATE void *sqlite3Os2Dlopen(const char *zFilename){
 12438  12537     UCHAR loadErr[256];
 12439  12538     HMODULE hmod;
 12440  12539     APIRET rc;
 12441         -  rc = DosLoadModule(loadErr, sizeof(loadErr), zFilename, &hmod);
        12540  +  rc = DosLoadModule((PSZ)loadErr, sizeof(loadErr), zFilename, &hmod);
 12442  12541     if (rc != NO_ERROR) return 0;
 12443  12542     return (void*)hmod;
 12444  12543   }
 12445         -static void *sqlite3Os2Dlsym(void *pHandle, const char *zSymbol){
        12544  +SQLITE_PRIVATE void *sqlite3Os2Dlsym(void *pHandle, const char *zSymbol){
 12446  12545     PFN pfn;
 12447  12546     APIRET rc;
 12448  12547     rc = DosQueryProcAddr((HMODULE)pHandle, 0L, zSymbol, &pfn);
 12449  12548     if (rc != NO_ERROR) {
 12450  12549       /* if the symbol itself was not found, search again for the same
 12451  12550        * symbol with an extra underscore, that might be needed depending
 12452  12551        * on the calling convention */
 12453  12552       char _zSymbol[256] = "_";
 12454  12553       strncat(_zSymbol, zSymbol, 255);
 12455  12554       rc = DosQueryProcAddr((HMODULE)pHandle, 0L, _zSymbol, &pfn);
 12456  12555     }
 12457  12556     if (rc != NO_ERROR) return 0;
 12458         -  return pfn;
        12557  +  return (void *)pfn;
 12459  12558   }
 12460         -static int sqlite3Os2Dlclose(void *pHandle){
        12559  +SQLITE_PRIVATE int sqlite3Os2Dlclose(void *pHandle){
 12461  12560     return DosFreeModule((HMODULE)pHandle);
 12462  12561   }
 12463  12562   #endif /* SQLITE_OMIT_LOAD_EXTENSION */
 12464  12563   
 12465  12564   
 12466  12565   /*
 12467  12566   ** Get information to seed the random number generator.  The seed
 12468  12567   ** is written into the buffer zBuf[256].  The calling function must
 12469  12568   ** supply a sufficiently large buffer.
 12470  12569   */
 12471         -static int sqlite3Os2RandomSeed( char *zBuf ){
        12570  +SQLITE_PRIVATE int sqlite3Os2RandomSeed( char *zBuf ){
 12472  12571     /* We have to initialize zBuf to prevent valgrind from reporting
 12473  12572     ** errors.  The reports issued by valgrind are incorrect - we would
 12474  12573     ** prefer that the randomness be increased by making use of the
 12475  12574     ** uninitialized space in zBuf - but valgrind errors tend to worry
 12476  12575     ** some users.  Rather than argue, it seems easier just to initialize
 12477  12576     ** the whole array and silence valgrind, even if that means less randomness
 12478  12577     ** in the random seed.
................................................................................
 12485  12584     DosGetDateTime( (PDATETIME)zBuf );
 12486  12585     return SQLITE_OK;
 12487  12586   }
 12488  12587   
 12489  12588   /*
 12490  12589   ** Sleep for a little while.  Return the amount of time slept.
 12491  12590   */
 12492         -static int sqlite3Os2Sleep( int ms ){
        12591  +SQLITE_PRIVATE int sqlite3Os2Sleep( int ms ){
 12493  12592     DosSleep( ms );
 12494  12593     return ms;
 12495  12594   }
 12496  12595   
 12497  12596   /*
 12498  12597   ** Static variables used for thread synchronization
 12499  12598   */
................................................................................
 12506  12605   ** The following pair of routines implement mutual exclusion for
 12507  12606   ** multi-threaded processes.  Only a single thread is allowed to
 12508  12607   ** executed code that is surrounded by EnterMutex() and LeaveMutex().
 12509  12608   **
 12510  12609   ** SQLite uses only a single Mutex.  There is not much critical
 12511  12610   ** code and what little there is executes quickly and without blocking.
 12512  12611   */
 12513         -static void sqlite3Os2EnterMutex(){
 12514         -  PTIB ptib;
        12612  +SQLITE_PRIVATE void sqlite3Os2EnterMutex(){
 12515  12613   #ifdef SQLITE_OS2_THREADS
        12614  +  PTIB ptib;
 12516  12615     DosEnterCritSec();
 12517  12616     DosGetInfoBlocks( &ptib, NULL );
 12518  12617     mutexOwner = ptib->tib_ptib2->tib2_ultid;
 12519  12618   #endif
 12520  12619     assert( !inMutex );
 12521  12620     inMutex = 1;
 12522  12621   }
 12523         -static void sqlite3Os2LeaveMutex(){
        12622  +SQLITE_PRIVATE void sqlite3Os2LeaveMutex(){
        12623  +#ifdef SQLITE_OS2_THREADS
 12524  12624     PTIB ptib;
        12625  +#endif
 12525  12626     assert( inMutex );
 12526  12627     inMutex = 0;
 12527  12628   #ifdef SQLITE_OS2_THREADS
 12528  12629     DosGetInfoBlocks( &ptib, NULL );
 12529  12630     assert( mutexOwner == ptib->tib_ptib2->tib2_ultid );
 12530  12631     DosExitCritSec();
 12531  12632   #endif
................................................................................
 12534  12635   /*
 12535  12636   ** Return TRUE if the mutex is currently held.
 12536  12637   **
 12537  12638   ** If the thisThreadOnly parameter is true, return true if and only if the
 12538  12639   ** calling thread holds the mutex.  If the parameter is false, return
 12539  12640   ** true if any thread holds the mutex.
 12540  12641   */
 12541         -static int sqlite3Os2InMutex( int thisThreadOnly ){
        12642  +SQLITE_PRIVATE int sqlite3Os2InMutex( int thisThreadOnly ){
 12542  12643   #ifdef SQLITE_OS2_THREADS
 12543  12644     PTIB ptib;
 12544  12645     DosGetInfoBlocks( &ptib, NULL );
 12545  12646     return inMutex>0 && (thisThreadOnly==0 || mutexOwner==ptib->tib_ptib2->tib2_ultid);
 12546  12647   #else
 12547  12648     return inMutex>0;
 12548  12649   #endif
................................................................................
 12557  12658   #endif
 12558  12659   
 12559  12660   /*
 12560  12661   ** Find the current time (in Universal Coordinated Time).  Write the
 12561  12662   ** current time and date as a Julian Day number into *prNow and
 12562  12663   ** return 0.  Return 1 if the time and date cannot be found.
 12563  12664   */
 12564         -static int sqlite3Os2CurrentTime( double *prNow ){
        12665  +SQLITE_PRIVATE int sqlite3Os2CurrentTime( double *prNow ){
 12565  12666     double now;
 12566  12667     USHORT second, minute, hour,
 12567  12668            day, month, year;
 12568  12669     DATETIME dt;
 12569  12670     DosGetDateTime( &dt );
 12570  12671     second = (USHORT)dt.seconds;
 12571  12672     minute = (USHORT)dt.minutes + dt.timezone;
................................................................................
 12619  12720   ** then return NULL.
 12620  12721   **
 12621  12722   ** If called with allocateFlag<0, check to see if the thread specific
 12622  12723   ** data is allocated and is all zero.  If it is then deallocate it.
 12623  12724   ** Return a pointer to the thread specific data or NULL if it is
 12624  12725   ** unallocated or gets deallocated.
 12625  12726   */
 12626         -static ThreadData *sqlite3Os2ThreadSpecificData( int allocateFlag ){
        12727  +SQLITE_PRIVATE ThreadData *sqlite3Os2ThreadSpecificData( int allocateFlag ){
 12627  12728     static ThreadData **s_ppTsd = NULL;
 12628  12729     static const ThreadData zeroData = {0, 0, 0};
 12629  12730     ThreadData *pTsd;
 12630  12731   
 12631  12732     if( !s_ppTsd ){
 12632  12733       sqlite3OsEnterMutex();
 12633  12734       if( !s_ppTsd ){
................................................................................
 12927  13028   ** enabled. This version allocates an extra 8-bytes at the beginning of each
 12928  13029   ** block and stores the size of the allocation there.
 12929  13030   **
 12930  13031   ** If neither memory-management or debugging is enabled, the second
 12931  13032   ** set of implementations is used instead.
 12932  13033   */
 12933  13034   #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) || defined (SQLITE_MEMDEBUG)
 12934         -static void *sqlite3GenericMalloc(int n){
        13035  +SQLITE_PRIVATE void *sqlite3GenericMalloc(int n){
 12935  13036     char *p = (char *)malloc(n+8);
 12936  13037     assert(n>0);
 12937  13038     assert(sizeof(int)<=8);
 12938  13039     if( p ){
 12939  13040       *(int *)p = n;
 12940  13041       p += 8;
 12941  13042     }
 12942  13043     return (void *)p;
 12943  13044   }
 12944         -static void *sqlite3GenericRealloc(void *p, int n){
        13045  +SQLITE_PRIVATE void *sqlite3GenericRealloc(void *p, int n){
 12945  13046     char *p2 = ((char *)p - 8);
 12946  13047     assert(n>0);
 12947  13048     p2 = (char*)realloc(p2, n+8);
 12948  13049     if( p2 ){
 12949  13050       *(int *)p2 = n;
 12950  13051       p2 += 8;
 12951  13052     }
 12952  13053     return (void *)p2;
 12953  13054   }
 12954         -static void sqlite3GenericFree(void *p){
        13055  +SQLITE_PRIVATE void sqlite3GenericFree(void *p){
 12955  13056     assert(p);
 12956  13057     free((void *)((char *)p - 8));
 12957  13058   }
 12958         -static int sqlite3GenericAllocationSize(void *p){
        13059  +SQLITE_PRIVATE int sqlite3GenericAllocationSize(void *p){
 12959  13060     return p ? *(int *)((char *)p - 8) : 0;
 12960  13061   }
 12961  13062   #else
 12962         -static void *sqlite3GenericMalloc(int n){
        13063  +SQLITE_PRIVATE void *sqlite3GenericMalloc(int n){
 12963  13064     char *p = (char *)malloc(n);
 12964  13065     return (void *)p;
 12965  13066   }
 12966         -static void *sqlite3GenericRealloc(void *p, int n){
        13067  +SQLITE_PRIVATE void *sqlite3GenericRealloc(void *p, int n){
 12967  13068     assert(n>0);
 12968  13069     p = realloc(p, n);
 12969  13070     return p;
 12970  13071   }
 12971         -static void sqlite3GenericFree(void *p){
        13072  +SQLITE_PRIVATE void sqlite3GenericFree(void *p){
 12972  13073     assert(p);
 12973  13074     free(p);
 12974  13075   }
 12975  13076   /* Never actually used, but needed for the linker */
 12976         -static int sqlite3GenericAllocationSize(void *p){ return 0; }
        13077  +SQLITE_PRIVATE int sqlite3GenericAllocationSize(void *p){ return 0; }
 12977  13078   #endif
 12978  13079   
 12979  13080   /*
 12980  13081   ** The default size of a disk sector
 12981  13082   */
 12982  13083   #ifndef PAGER_SECTOR_SIZE
 12983  13084   # define PAGER_SECTOR_SIZE 512
................................................................................
 13646  13747     /* On single-threaded builds, ownership transfer is a no-op */
 13647  13748   # define transferOwnership(X) SQLITE_OK
 13648  13749   #endif
 13649  13750   
 13650  13751   /*
 13651  13752   ** Delete the named file
 13652  13753   */
 13653         -static int sqlite3UnixDelete(const char *zFilename){
        13754  +SQLITE_PRIVATE int sqlite3UnixDelete(const char *zFilename){
 13654  13755     SimulateIOError(return SQLITE_IOERR_DELETE);
 13655  13756     unlink(zFilename);
 13656  13757     return SQLITE_OK;
 13657  13758   }
 13658  13759   
 13659  13760   /*
 13660  13761   ** Return TRUE if the named file exists.
 13661  13762   */
 13662         -static int sqlite3UnixFileExists(const char *zFilename){
        13763  +SQLITE_PRIVATE int sqlite3UnixFileExists(const char *zFilename){
 13663  13764     return access(zFilename, 0)==0;
 13664  13765   }
 13665  13766   
 13666  13767   /* Forward declaration */
 13667  13768   static int allocateUnixFile(
 13668  13769     int h,                    /* File descriptor of the open file */
 13669  13770     OsFile **pId,             /* Write the real file descriptor here */
................................................................................
 13680  13781   ** and *pReadonly is set to 0 if the file was opened for reading and
 13681  13782   ** writing or 1 if the file was opened read-only.  The function returns
 13682  13783   ** SQLITE_OK.
 13683  13784   **
 13684  13785   ** On failure, the function returns SQLITE_CANTOPEN and leaves
 13685  13786   ** *id and *pReadonly unchanged.
 13686  13787   */
 13687         -static int sqlite3UnixOpenReadWrite(
        13788  +SQLITE_PRIVATE int sqlite3UnixOpenReadWrite(
 13688  13789     const char *zFilename,
 13689  13790     OsFile **pId,
 13690  13791     int *pReadonly
 13691  13792   ){
 13692  13793     int h;
 13693  13794     
 13694  13795     CRASH_TEST_OVERRIDE(sqlite3CrashOpenReadWrite, zFilename, pId, pReadonly);
................................................................................
 13723  13824   ** If delFlag is true, then make arrangements to automatically delete
 13724  13825   ** the file when it is closed.
 13725  13826   **
 13726  13827   ** On success, write the file handle into *id and return SQLITE_OK.
 13727  13828   **
 13728  13829   ** On failure, return SQLITE_CANTOPEN.
 13729  13830   */
 13730         -static int sqlite3UnixOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){
        13831  +SQLITE_PRIVATE int sqlite3UnixOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){
 13731  13832     int h;
 13732  13833   
 13733  13834     CRASH_TEST_OVERRIDE(sqlite3CrashOpenExclusive, zFilename, pId, delFlag);
 13734  13835     assert( 0==*pId );
 13735  13836     h = open(zFilename,
 13736  13837                   O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW|O_LARGEFILE|O_BINARY,
 13737  13838                   delFlag ? 0600 : SQLITE_DEFAULT_FILE_PERMISSIONS);
................................................................................
 13744  13845   /*
 13745  13846   ** Attempt to open a new file for read-only access.
 13746  13847   **
 13747  13848   ** On success, write the file handle into *id and return SQLITE_OK.
 13748  13849   **
 13749  13850   ** On failure, return SQLITE_CANTOPEN.
 13750  13851   */
 13751         -static int sqlite3UnixOpenReadOnly(const char *zFilename, OsFile **pId){
        13852  +SQLITE_PRIVATE int sqlite3UnixOpenReadOnly(const char *zFilename, OsFile **pId){
 13752  13853     int h;
 13753  13854     
 13754  13855     CRASH_TEST_OVERRIDE(sqlite3CrashOpenReadOnly, zFilename, pId, 0);
 13755  13856     assert( 0==*pId );
 13756  13857     h = open(zFilename, O_RDONLY|O_LARGEFILE|O_BINARY);
 13757  13858     if( h<0 ){
 13758  13859       return SQLITE_CANTOPEN;
................................................................................
 13779  13880   ** On failure, the function returns SQLITE_CANTOPEN and leaves
 13780  13881   ** *id unchanged.
 13781  13882   */
 13782  13883   static int unixOpenDirectory(
 13783  13884     OsFile *id,
 13784  13885     const char *zDirname
 13785  13886   ){
        13887  +  int h;
 13786  13888     unixFile *pFile = (unixFile*)id;
 13787  13889     assert( pFile!=0 );
 13788  13890     SET_THREADID(pFile);
 13789  13891     assert( pFile->dirfd<0 );
 13790         -  pFile->dirfd = open(zDirname, O_RDONLY|O_BINARY, 0);
 13791         -  if( pFile->dirfd<0 ){
        13892  +  pFile->dirfd = h = open(zDirname, O_RDONLY|O_BINARY, 0);
        13893  +  if( h<0 ){
 13792  13894       return SQLITE_CANTOPEN; 
 13793  13895     }
 13794         -  OSTRACE3("OPENDIR %-3d %s\n", pFile->dirfd, zDirname);
        13896  +#ifdef FD_CLOEXEC
        13897  +  fcntl(h, F_SETFD, fcntl(h, F_GETFD, 0) | FD_CLOEXEC);
        13898  +#endif
        13899  +  OSTRACE3("OPENDIR %-3d %s\n", h, zDirname);
 13795  13900     return SQLITE_OK;
 13796  13901   }
 13797  13902   
 13798  13903   /*
 13799  13904   ** Create a temporary file name in zBuf.  zBuf must be big enough to
 13800  13905   ** hold at least SQLITE_TEMPNAME_SIZE characters.
 13801  13906   */
 13802         -static int sqlite3UnixTempFileName(char *zBuf){
        13907  +SQLITE_PRIVATE int sqlite3UnixTempFileName(char *zBuf){
 13803  13908     static const char *azDirs[] = {
 13804  13909        0,
 13805  13910        "/var/tmp",
 13806  13911        "/usr/tmp",
 13807  13912        "/tmp",
 13808  13913        ".",
 13809  13914     };
................................................................................
 13835  13940     return SQLITE_OK; 
 13836  13941   }
 13837  13942   
 13838  13943   /*
 13839  13944   ** Check that a given pathname is a directory and is writable 
 13840  13945   **
 13841  13946   */
 13842         -static int sqlite3UnixIsDirWritable(char *zBuf){
        13947  +SQLITE_PRIVATE int sqlite3UnixIsDirWritable(char *zBuf){
 13843  13948   #ifndef SQLITE_OMIT_PAGER_PRAGMAS
 13844  13949     struct stat buf;
 13845  13950     if( zBuf==0 ) return 0;
 13846  13951     if( zBuf[0]==0 ) return 0;
 13847  13952     if( stat(zBuf, &buf) ) return 0;
 13848  13953     if( !S_ISDIR(buf.st_mode) ) return 0;
 13849  13954     if( access(zBuf, 07) ) return 0;
................................................................................
 14104  14209   ** Sync the directory zDirname. This is a no-op on operating systems other
 14105  14210   ** than UNIX.
 14106  14211   **
 14107  14212   ** This is used to make sure the master journal file has truely been deleted
 14108  14213   ** before making changes to individual journals on a multi-database commit.
 14109  14214   ** The F_FULLFSYNC option is not needed here.
 14110  14215   */
 14111         -static int sqlite3UnixSyncDirectory(const char *zDirname){
        14216  +SQLITE_PRIVATE int sqlite3UnixSyncDirectory(const char *zDirname){
 14112  14217   #ifdef SQLITE_DISABLE_DIRSYNC
 14113  14218     return SQLITE_OK;
 14114  14219   #else
 14115  14220     int fd;
 14116  14221     int r;
 14117  14222     fd = open(zDirname, O_RDONLY|O_BINARY, 0);
 14118  14223     OSTRACE3("DIRSYNC %-3d (%s)\n", fd, zDirname);
................................................................................
 14132  14237   
 14133  14238   /*
 14134  14239   ** Truncate an open file to a specified size
 14135  14240   */
 14136  14241   static int unixTruncate(OsFile *id, i64 nByte){
 14137  14242     int rc;
 14138  14243     assert( id );
 14139         -  rc = ftruncate(((unixFile*)id)->h, nByte);
        14244  +  rc = ftruncate(((unixFile*)id)->h, (off_t)nByte);
 14140  14245     SimulateIOError( rc=1 );
 14141  14246     if( rc ){
 14142  14247       return SQLITE_IOERR_TRUNCATE;
 14143  14248     }else{
 14144  14249       return SQLITE_OK;
 14145  14250     }
 14146  14251   }
................................................................................
 15129  15234   
 15130  15235   /*
 15131  15236   ** Turn a relative pathname into a full pathname.  Return a pointer
 15132  15237   ** to the full pathname stored in space obtained from sqliteMalloc().
 15133  15238   ** The calling function is responsible for freeing this space once it
 15134  15239   ** is no longer needed.
 15135  15240   */
 15136         -static char *sqlite3UnixFullPathname(const char *zRelative){
        15241  +SQLITE_PRIVATE char *sqlite3UnixFullPathname(const char *zRelative){
 15137  15242     char *zFull = 0;
 15138  15243     if( zRelative[0]=='/' ){
 15139  15244       sqlite3SetString(&zFull, zRelative, (char*)0);
 15140  15245     }else{
 15141  15246       char *zBuf = sqliteMalloc(5000);
 15142  15247       if( zBuf==0 ){
 15143  15248         return 0;
................................................................................
 15438  15543     const char *zFilename, /* Name of the file being opened */
 15439  15544     int delFlag            /* If true, delete the file on or before closing */
 15440  15545   ){
 15441  15546     unixFile *pNew;
 15442  15547     unixFile f;
 15443  15548     int rc;
 15444  15549   
        15550  +#ifdef FD_CLOEXEC
        15551  +  fcntl(h, F_SETFD, fcntl(h, F_GETFD, 0) | FD_CLOEXEC);
        15552  +#endif
 15445  15553     memset(&f, 0, sizeof(f));
 15446  15554     sqlite3OsEnterMutex();
 15447  15555     rc = findLockInfo(h, &f.pLock, &f.pOpen);
 15448  15556     sqlite3OsLeaveMutex();
 15449  15557     if( delFlag ){
 15450  15558       unlink(zFilename);
 15451  15559     }
................................................................................
 15485  15593   
 15486  15594   #ifndef SQLITE_OMIT_LOAD_EXTENSION
 15487  15595   /*
 15488  15596   ** Interfaces for opening a shared library, finding entry points
 15489  15597   ** within the shared library, and closing the shared library.
 15490  15598   */
 15491  15599   #include <dlfcn.h>
 15492         -static void *sqlite3UnixDlopen(const char *zFilename){
        15600  +SQLITE_PRIVATE void *sqlite3UnixDlopen(const char *zFilename){
 15493  15601     return dlopen(zFilename, RTLD_NOW | RTLD_GLOBAL);
 15494  15602   }
 15495         -static void *sqlite3UnixDlsym(void *pHandle, const char *zSymbol){
        15603  +SQLITE_PRIVATE void *sqlite3UnixDlsym(void *pHandle, const char *zSymbol){
 15496  15604     return dlsym(pHandle, zSymbol);
 15497  15605   }
 15498         -static int sqlite3UnixDlclose(void *pHandle){
        15606  +SQLITE_PRIVATE int sqlite3UnixDlclose(void *pHandle){
 15499  15607     return dlclose(pHandle);
 15500  15608   }
 15501  15609   #endif /* SQLITE_OMIT_LOAD_EXTENSION */
 15502  15610   
 15503  15611   /*
 15504  15612   ** Get information to seed the random number generator.  The seed
 15505  15613   ** is written into the buffer zBuf[256].  The calling function must
 15506  15614   ** supply a sufficiently large buffer.
 15507  15615   */
 15508         -static int sqlite3UnixRandomSeed(char *zBuf){
        15616  +SQLITE_PRIVATE int sqlite3UnixRandomSeed(char *zBuf){
 15509  15617     /* We have to initialize zBuf to prevent valgrind from reporting
 15510  15618     ** errors.  The reports issued by valgrind are incorrect - we would
 15511  15619     ** prefer that the randomness be increased by making use of the
 15512  15620     ** uninitialized space in zBuf - but valgrind errors tend to worry
 15513  15621     ** some users.  Rather than argue, it seems easier just to initialize
 15514  15622     ** the whole array and silence valgrind, even if that means less randomness
 15515  15623     ** in the random seed.
................................................................................
 15538  15646     return SQLITE_OK;
 15539  15647   }
 15540  15648   
 15541  15649   /*
 15542  15650   ** Sleep for a little while.  Return the amount of time slept.
 15543  15651   ** The argument is the number of milliseconds we want to sleep.
 15544  15652   */
 15545         -static int sqlite3UnixSleep(int ms){
        15653  +SQLITE_PRIVATE int sqlite3UnixSleep(int ms){
 15546  15654   #if defined(HAVE_USLEEP) && HAVE_USLEEP
 15547  15655     usleep(ms*1000);
 15548  15656     return ms;
 15549  15657   #else
 15550  15658     sleep((ms+999)/1000);
 15551  15659     return 1000*((ms+999)/1000);
 15552  15660   #endif
................................................................................
 15597  15705   ** executed code that is surrounded by EnterMutex() and LeaveMutex().
 15598  15706   **
 15599  15707   ** SQLite uses only a single Mutex.  There is not much critical
 15600  15708   ** code and what little there is executes quickly and without blocking.
 15601  15709   **
 15602  15710   ** As of version 3.3.2, this mutex must be recursive.
 15603  15711   */
 15604         -static void sqlite3UnixEnterMutex(){
        15712  +SQLITE_PRIVATE void sqlite3UnixEnterMutex(){
 15605  15713   #ifdef SQLITE_UNIX_THREADS
 15606  15714     pthread_mutex_lock(&mutexAux);
 15607  15715     if( !mutexOwnerValid || !pthread_equal(mutexOwner, pthread_self()) ){
 15608  15716       pthread_mutex_unlock(&mutexAux);
 15609  15717       pthread_mutex_lock(&mutexMain);
 15610  15718       assert( inMutex==0 );
 15611  15719       assert( !mutexOwnerValid );
................................................................................
 15615  15723     }
 15616  15724     inMutex++;
 15617  15725     pthread_mutex_unlock(&mutexAux);
 15618  15726   #else
 15619  15727     inMutex++;
 15620  15728   #endif
 15621  15729   }
 15622         -static void sqlite3UnixLeaveMutex(){
        15730  +SQLITE_PRIVATE void sqlite3UnixLeaveMutex(){
 15623  15731     assert( inMutex>0 );
 15624  15732   #ifdef SQLITE_UNIX_THREADS
 15625  15733     pthread_mutex_lock(&mutexAux);
 15626  15734     inMutex--;
 15627  15735     assert( pthread_equal(mutexOwner, pthread_self()) );
 15628  15736     if( inMutex==0 ){
 15629  15737       assert( mutexOwnerValid );
................................................................................
 15639  15747   /*
 15640  15748   ** Return TRUE if the mutex is currently held.
 15641  15749   **
 15642  15750   ** If the thisThrd parameter is true, return true only if the
 15643  15751   ** calling thread holds the mutex.  If the parameter is false, return
 15644  15752   ** true if any thread holds the mutex.
 15645  15753   */
 15646         -static int sqlite3UnixInMutex(int thisThrd){
        15754  +SQLITE_PRIVATE int sqlite3UnixInMutex(int thisThrd){
 15647  15755   #ifdef SQLITE_UNIX_THREADS
 15648  15756     int rc;
 15649  15757     pthread_mutex_lock(&mutexAux);
 15650  15758     rc = inMutex>0 && (thisThrd==0 || pthread_equal(mutexOwner,pthread_self()));
 15651  15759     pthread_mutex_unlock(&mutexAux);
 15652  15760     return rc;
 15653  15761   #else
................................................................................
 15685  15793   ** then return NULL.
 15686  15794   **
 15687  15795   ** If called with allocateFlag<0, check to see if the thread specific
 15688  15796   ** data is allocated and is all zero.  If it is then deallocate it.
 15689  15797   ** Return a pointer to the thread specific data or NULL if it is
 15690  15798   ** unallocated or gets deallocated.
 15691  15799   */
 15692         -static ThreadData *sqlite3UnixThreadSpecificData(int allocateFlag){
        15800  +SQLITE_PRIVATE ThreadData *sqlite3UnixThreadSpecificData(int allocateFlag){
 15693  15801     static const ThreadData zeroData = {0};  /* Initializer to silence warnings
 15694  15802                                              ** from broken compilers */
 15695  15803   #ifdef SQLITE_UNIX_THREADS
 15696  15804     static pthread_key_t key;
 15697  15805     static int keyInit = 0;
 15698  15806     ThreadData *pTsd;
 15699  15807   
................................................................................
 15768  15876   #endif
 15769  15877   
 15770  15878   /*
 15771  15879   ** Find the current time (in Universal Coordinated Time).  Write the
 15772  15880   ** current time and date as a Julian Day number into *prNow and
 15773  15881   ** return 0.  Return 1 if the time and date cannot be found.
 15774  15882   */
 15775         -static int sqlite3UnixCurrentTime(double *prNow){
        15883  +SQLITE_PRIVATE int sqlite3UnixCurrentTime(double *prNow){
 15776  15884   #ifdef NO_GETTOD
 15777  15885     time_t t;
 15778  15886     time(&t);
 15779  15887     *prNow = t/86400.0 + 2440587.5;
 15780  15888   #else
 15781  15889     struct timeval sNow;
 15782  15890     gettimeofday(&sNow, 0);
................................................................................
 15971  16079   ** enabled. This version allocates an extra 8-bytes at the beginning of each
 15972  16080   ** block and stores the size of the allocation there.
 15973  16081   **
 15974  16082   ** If neither memory-management or debugging is enabled, the second
 15975  16083   ** set of implementations is used instead.
 15976  16084   */
 15977  16085   #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) || defined (SQLITE_MEMDEBUG)
 15978         -static void *sqlite3GenericMalloc(int n){
        16086  +SQLITE_PRIVATE void *sqlite3GenericMalloc(int n){
 15979  16087     char *p = (char *)malloc(n+8);
 15980  16088     assert(n>0);
 15981  16089     assert(sizeof(int)<=8);
 15982  16090     if( p ){
 15983  16091       *(int *)p = n;
 15984  16092       p += 8;
 15985  16093     }
 15986  16094     return (void *)p;
 15987  16095   }
 15988         -static void *sqlite3GenericRealloc(void *p, int n){
        16096  +SQLITE_PRIVATE void *sqlite3GenericRealloc(void *p, int n){
 15989  16097     char *p2 = ((char *)p - 8);
 15990  16098     assert(n>0);
 15991  16099     p2 = (char*)realloc(p2, n+8);
 15992  16100     if( p2 ){
 15993  16101       *(int *)p2 = n;
 15994  16102       p2 += 8;
 15995  16103     }
 15996  16104     return (void *)p2;
 15997  16105   }
 15998         -static void sqlite3GenericFree(void *p){
        16106  +SQLITE_PRIVATE void sqlite3GenericFree(void *p){
 15999  16107     assert(p);
 16000  16108     free((void *)((char *)p - 8));
 16001  16109   }
 16002         -static int sqlite3GenericAllocationSize(void *p){
        16110  +SQLITE_PRIVATE int sqlite3GenericAllocationSize(void *p){
 16003  16111     return p ? *(int *)((char *)p - 8) : 0;
 16004  16112   }
 16005  16113   #else
 16006         -static void *sqlite3GenericMalloc(int n){
        16114  +SQLITE_PRIVATE void *sqlite3GenericMalloc(int n){
 16007  16115     char *p = (char *)malloc(n);
 16008  16116     return (void *)p;
 16009  16117   }
 16010         -static void *sqlite3GenericRealloc(void *p, int n){
        16118  +SQLITE_PRIVATE void *sqlite3GenericRealloc(void *p, int n){
 16011  16119     assert(n>0);
 16012  16120     p = realloc(p, n);
 16013  16121     return p;
 16014  16122   }
 16015         -static void sqlite3GenericFree(void *p){
        16123  +SQLITE_PRIVATE void sqlite3GenericFree(void *p){
 16016  16124     assert(p);
 16017  16125     free(p);
 16018  16126   }
 16019  16127   /* Never actually used, but needed for the linker */
 16020         -static int sqlite3GenericAllocationSize(void *p){ return 0; }
        16128  +SQLITE_PRIVATE int sqlite3GenericAllocationSize(void *p){ return 0; }
 16021  16129   #endif
 16022  16130   
 16023  16131   /*
 16024  16132   ** The default size of a disk sector
 16025  16133   */
 16026  16134   #ifndef PAGER_SECTOR_SIZE
 16027  16135   # define PAGER_SECTOR_SIZE 512
................................................................................
 16586  16694   ** whatever it is it does.  While this other process is holding the
 16587  16695   ** file open, we will be unable to delete it.  To work around this
 16588  16696   ** problem, we delay 100 milliseconds and try to delete again.  Up
 16589  16697   ** to MX_DELETION_ATTEMPTs deletion attempts are run before giving
 16590  16698   ** up and returning an error.
 16591  16699   */
 16592  16700   #define MX_DELETION_ATTEMPTS 3
 16593         -static int sqlite3WinDelete(const char *zFilename){
        16701  +SQLITE_PRIVATE int sqlite3WinDelete(const char *zFilename){
 16594  16702     int cnt = 0;
 16595  16703     int rc;
 16596  16704     void *zConverted = convertUtf8Filename(zFilename);
 16597  16705     if( zConverted==0 ){
 16598  16706       return SQLITE_NOMEM;
 16599  16707     }
 16600  16708     SimulateIOError(return SQLITE_IOERR_DELETE);
................................................................................
 16617  16725     OSTRACE2("DELETE \"%s\"\n", zFilename);
 16618  16726     return rc!=0 ? SQLITE_OK : SQLITE_IOERR;
 16619  16727   }
 16620  16728   
 16621  16729   /*
 16622  16730   ** Return TRUE if the named file exists.
 16623  16731   */
 16624         -static int sqlite3WinFileExists(const char *zFilename){
        16732  +SQLITE_PRIVATE int sqlite3WinFileExists(const char *zFilename){
 16625  16733     int exists = 0;
 16626  16734     void *zConverted = convertUtf8Filename(zFilename);
 16627  16735     if( zConverted==0 ){
 16628  16736       return SQLITE_NOMEM;
 16629  16737     }
 16630  16738     if( isNT() ){
 16631  16739       exists = GetFileAttributesW((WCHAR*)zConverted) != 0xffffffff;
................................................................................
 16652  16760   ** and *pReadonly is set to 0 if the file was opened for reading and
 16653  16761   ** writing or 1 if the file was opened read-only.  The function returns
 16654  16762   ** SQLITE_OK.
 16655  16763   **
 16656  16764   ** On failure, the function returns SQLITE_CANTOPEN and leaves
 16657  16765   ** *id and *pReadonly unchanged.
 16658  16766   */
 16659         -static int sqlite3WinOpenReadWrite(
        16767  +SQLITE_PRIVATE int sqlite3WinOpenReadWrite(
 16660  16768     const char *zFilename,
 16661  16769     OsFile **pId,
 16662  16770     int *pReadonly
 16663  16771   ){
 16664  16772     winFile f;
 16665  16773     HANDLE h;
 16666  16774     void *zConverted = convertUtf8Filename(zFilename);
................................................................................
 16761  16869   **
 16762  16870   ** Sometimes if we have just deleted a prior journal file, windows
 16763  16871   ** will fail to open a new one because there is a "pending delete".
 16764  16872   ** To work around this bug, we pause for 100 milliseconds and attempt
 16765  16873   ** a second open after the first one fails.  The whole operation only
 16766  16874   ** fails if both open attempts are unsuccessful.
 16767  16875   */
 16768         -static int sqlite3WinOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){
        16876  +SQLITE_PRIVATE int sqlite3WinOpenExclusive(const char *zFilename, OsFile **pId, int delFlag){
 16769  16877     winFile f;
 16770  16878     HANDLE h;
 16771  16879     DWORD fileflags;
 16772  16880     void *zConverted = convertUtf8Filename(zFilename);
 16773  16881     if( zConverted==0 ){
 16774  16882       return SQLITE_NOMEM;
 16775  16883     }
................................................................................
 16828  16936   /*
 16829  16937   ** Attempt to open a new file for read-only access.
 16830  16938   **
 16831  16939   ** On success, write the file handle into *id and return SQLITE_OK.
 16832  16940   **
 16833  16941   ** On failure, return SQLITE_CANTOPEN.
 16834  16942   */
 16835         -static int sqlite3WinOpenReadOnly(const char *zFilename, OsFile **pId){
        16943  +SQLITE_PRIVATE int sqlite3WinOpenReadOnly(const char *zFilename, OsFile **pId){
 16836  16944     winFile f;
 16837  16945     HANDLE h;
 16838  16946     void *zConverted = convertUtf8Filename(zFilename);
 16839  16947     if( zConverted==0 ){
 16840  16948       return SQLITE_NOMEM;
 16841  16949     }
 16842  16950     assert( *pId==0 );
................................................................................
 16899  17007     return SQLITE_OK;
 16900  17008   }
 16901  17009   
 16902  17010   /*
 16903  17011   ** Create a temporary file name in zBuf.  zBuf must be big enough to
 16904  17012   ** hold at least SQLITE_TEMPNAME_SIZE characters.
 16905  17013   */
 16906         -static int sqlite3WinTempFileName(char *zBuf){
        17014  +SQLITE_PRIVATE int sqlite3WinTempFileName(char *zBuf){
 16907  17015     static char zChars[] =
 16908  17016       "abcdefghijklmnopqrstuvwxyz"
 16909  17017       "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 16910  17018       "0123456789";
 16911  17019     int i, j;
 16912  17020     char zTempPath[SQLITE_TEMPNAME_SIZE];
 16913  17021     if( sqlite3_temp_directory ){
................................................................................
 17068  17176     }
 17069  17177   }
 17070  17178   
 17071  17179   /*
 17072  17180   ** Sync the directory zDirname. This is a no-op on operating systems other
 17073  17181   ** than UNIX.
 17074  17182   */
 17075         -static int sqlite3WinSyncDirectory(const char *zDirname){
        17183  +SQLITE_PRIVATE int sqlite3WinSyncDirectory(const char *zDirname){
 17076  17184     SimulateIOError(return SQLITE_IOERR_READ);
 17077  17185     return SQLITE_OK;
 17078  17186   }
 17079  17187   
 17080  17188   /*
 17081  17189   ** Truncate an open file to a specified size
 17082  17190   */
................................................................................
 17145  17253   }
 17146  17254   
 17147  17255   #ifndef SQLITE_OMIT_PAGER_PRAGMAS
 17148  17256   /*
 17149  17257   ** Check that a given pathname is a directory and is writable 
 17150  17258   **
 17151  17259   */
 17152         -static int sqlite3WinIsDirWritable(char *zDirname){
        17260  +SQLITE_PRIVATE int sqlite3WinIsDirWritable(char *zDirname){
 17153  17261     int fileAttr;
 17154  17262     void *zConverted;
 17155  17263     if( zDirname==0 ) return 0;
 17156  17264     if( !isNT() && strlen(zDirname)>MAX_PATH ) return 0;
 17157  17265   
 17158  17266     zConverted = convertUtf8Filename(zDirname);
 17159  17267     if( zConverted==0 ){
................................................................................
 17376  17484   
 17377  17485   /*
 17378  17486   ** Turn a relative pathname into a full pathname.  Return a pointer
 17379  17487   ** to the full pathname stored in space obtained from sqliteMalloc().
 17380  17488   ** The calling function is responsible for freeing this space once it
 17381  17489   ** is no longer needed.
 17382  17490   */
 17383         -static char *sqlite3WinFullPathname(const char *zRelative){
        17491  +SQLITE_PRIVATE char *sqlite3WinFullPathname(const char *zRelative){
 17384  17492     char *zFull;
 17385  17493   #if defined(__CYGWIN__)
 17386  17494     int nByte;
 17387  17495     nByte = strlen(zRelative) + MAX_PATH + 1001;
 17388  17496     zFull = sqliteMalloc( nByte );
 17389  17497     if( zFull==0 ) return 0;
 17390  17498     if( cygwin_conv_to_full_win32_path(zRelative, zFull) ) return 0;
................................................................................
 17516  17624   ****************************************************************************/
 17517  17625   
 17518  17626   #if !defined(SQLITE_OMIT_LOAD_EXTENSION)
 17519  17627   /*
 17520  17628   ** Interfaces for opening a shared library, finding entry points
 17521  17629   ** within the shared library, and closing the shared library.
 17522  17630   */
 17523         -static void *sqlite3WinDlopen(const char *zFilename){
        17631  +SQLITE_PRIVATE void *sqlite3WinDlopen(const char *zFilename){
 17524  17632     HANDLE h;
 17525  17633     void *zConverted = convertUtf8Filename(zFilename);
 17526  17634     if( zConverted==0 ){
 17527  17635       return 0;
 17528  17636     }
 17529  17637     if( isNT() ){
 17530  17638       h = LoadLibraryW((WCHAR*)zConverted);
................................................................................
 17535  17643       h = LoadLibraryA((char*)zConverted);
 17536  17644   #endif
 17537  17645     }
 17538  17646     sqliteFree(zConverted);
 17539  17647     return (void*)h;
 17540  17648     
 17541  17649   }
 17542         -static void *sqlite3WinDlsym(void *pHandle, const char *zSymbol){
        17650  +SQLITE_PRIVATE void *sqlite3WinDlsym(void *pHandle, const char *zSymbol){
 17543  17651   #if OS_WINCE
 17544  17652     /* The GetProcAddressA() routine is only available on wince. */
 17545  17653     return GetProcAddressA((HANDLE)pHandle, zSymbol);
 17546  17654   #else
 17547  17655     /* All other windows platforms expect GetProcAddress() to take
 17548  17656     ** an Ansi string regardless of the _UNICODE setting */
 17549  17657     return GetProcAddress((HANDLE)pHandle, zSymbol);
 17550  17658   #endif
 17551  17659   }
 17552         -static int sqlite3WinDlclose(void *pHandle){
        17660  +SQLITE_PRIVATE int sqlite3WinDlclose(void *pHandle){
 17553  17661     return FreeLibrary((HANDLE)pHandle);
 17554  17662   }
 17555  17663   #endif /* !SQLITE_OMIT_LOAD_EXTENSION */
 17556  17664   
 17557  17665   /*
 17558  17666   ** Get information to seed the random number generator.  The seed
 17559  17667   ** is written into the buffer zBuf[256].  The calling function must
 17560  17668   ** supply a sufficiently large buffer.
 17561  17669   */
 17562         -static int sqlite3WinRandomSeed(char *zBuf){
        17670  +SQLITE_PRIVATE int sqlite3WinRandomSeed(char *zBuf){
 17563  17671     /* We have to initialize zBuf to prevent valgrind from reporting
 17564  17672     ** errors.  The reports issued by valgrind are incorrect - we would
 17565  17673     ** prefer that the randomness be increased by making use of the
 17566  17674     ** uninitialized space in zBuf - but valgrind errors tend to worry
 17567  17675     ** some users.  Rather than argue, it seems easier just to initialize
 17568  17676     ** the whole array and silence valgrind, even if that means less randomness
 17569  17677     ** in the random seed.
................................................................................
 17576  17684     GetSystemTime((LPSYSTEMTIME)zBuf);
 17577  17685     return SQLITE_OK;
 17578  17686   }
 17579  17687   
 17580  17688   /*
 17581  17689   ** Sleep for a little while.  Return the amount of time slept.
 17582  17690   */
 17583         -static int sqlite3WinSleep(int ms){
        17691  +SQLITE_PRIVATE int sqlite3WinSleep(int ms){
 17584  17692     Sleep(ms);
 17585  17693     return ms;
 17586  17694   }
 17587  17695   
 17588  17696   /*
 17589  17697   ** Static variables used for thread synchronization
 17590  17698   */
................................................................................
 17601  17709   **
 17602  17710   ** SQLite uses only a single Mutex.  There is not much critical
 17603  17711   ** code and what little there is executes quickly and without blocking.
 17604  17712   **
 17605  17713   ** Version 3.3.1 and earlier used a simple mutex.  Beginning with
 17606  17714   ** version 3.3.2, a recursive mutex is required.
 17607  17715   */
 17608         -static void sqlite3WinEnterMutex(){
        17716  +SQLITE_PRIVATE void sqlite3WinEnterMutex(){
 17609  17717   #ifdef SQLITE_W32_THREADS
 17610  17718     static int isInit = 0;
 17611  17719     while( !isInit ){
 17612  17720       static long lock = 0;
 17613  17721       if( InterlockedIncrement(&lock)==1 ){
 17614  17722         InitializeCriticalSection(&cs);
 17615  17723         isInit = 1;
................................................................................
 17618  17726       }
 17619  17727     }
 17620  17728     EnterCriticalSection(&cs);
 17621  17729     mutexOwner = GetCurrentThreadId();
 17622  17730   #endif
 17623  17731     inMutex++;
 17624  17732   }
 17625         -static void sqlite3WinLeaveMutex(){
        17733  +SQLITE_PRIVATE void sqlite3WinLeaveMutex(){
 17626  17734     assert( inMutex );
 17627  17735     inMutex--;
 17628  17736   #ifdef SQLITE_W32_THREADS
 17629  17737     assert( mutexOwner==GetCurrentThreadId() );
 17630  17738     LeaveCriticalSection(&cs);
 17631  17739   #endif
 17632  17740   }
................................................................................
 17634  17742   /*
 17635  17743   ** Return TRUE if the mutex is currently held.
 17636  17744   **
 17637  17745   ** If the thisThreadOnly parameter is true, return true if and only if the
 17638  17746   ** calling thread holds the mutex.  If the parameter is false, return
 17639  17747   ** true if any thread holds the mutex.
 17640  17748   */
 17641         -static int sqlite3WinInMutex(int thisThreadOnly){
        17749  +SQLITE_PRIVATE int sqlite3WinInMutex(int thisThreadOnly){
 17642  17750   #ifdef SQLITE_W32_THREADS
 17643  17751     return inMutex>0 && (thisThreadOnly==0 || mutexOwner==GetCurrentThreadId());
 17644  17752   #else
 17645  17753     return inMutex>0;
 17646  17754   #endif
 17647  17755   }
 17648  17756   
................................................................................
 17656  17764   #endif
 17657  17765   
 17658  17766   /*
 17659  17767   ** Find the current time (in Universal Coordinated Time).  Write the
 17660  17768   ** current time and date as a Julian Day number into *prNow and
 17661  17769   ** return 0.  Return 1 if the time and date cannot be found.
 17662  17770   */
 17663         -static int sqlite3WinCurrentTime(double *prNow){
        17771  +SQLITE_PRIVATE int sqlite3WinCurrentTime(double *prNow){
 17664  17772     FILETIME ft;
 17665  17773     /* FILETIME structure is a 64-bit value representing the number of 
 17666  17774        100-nanosecond intervals since January 1, 1601 (= JD 2305813.5). 
 17667  17775     */
 17668  17776     double now;
 17669  17777   #if OS_WINCE
 17670  17778     SYSTEMTIME time;
................................................................................
 17709  17817   ** then return NULL.
 17710  17818   **
 17711  17819   ** If called with allocateFlag<0, check to see if the thread specific
 17712  17820   ** data is allocated and is all zero.  If it is then deallocate it.
 17713  17821   ** Return a pointer to the thread specific data or NULL if it is
 17714  17822   ** unallocated or gets deallocated.
 17715  17823   */
 17716         -static ThreadData *sqlite3WinThreadSpecificData(int allocateFlag){
        17824  +SQLITE_PRIVATE ThreadData *sqlite3WinThreadSpecificData(int allocateFlag){
 17717  17825     static int key;
 17718  17826     static int keyInit = 0;
 17719  17827     static const ThreadData zeroData = {0};
 17720  17828     ThreadData *pTsd;
 17721  17829   
 17722  17830     if( !keyInit ){
 17723  17831       sqlite3OsEnterMutex();
................................................................................
 17770  17878   ** The pager is used to access a database disk file.  It implements
 17771  17879   ** atomic commit and rollback through the use of a journal file that
 17772  17880   ** is separate from the database file.  The pager also implements file
 17773  17881   ** locking to prevent two processes from writing the same database
 17774  17882   ** file simultaneously, or one process from reading the database while
 17775  17883   ** another is writing.
 17776  17884   **
 17777         -** @(#) $Id: sqlite3.c,v 1.3 2007/06/19 22:43:23 rmsimpson Exp $
        17885  +** @(#) $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
 17778  17886   */
 17779  17887   #ifndef SQLITE_OMIT_DISKIO
 17780  17888   
 17781  17889   /*
 17782  17890   ** Macros for troubleshooting.  Normally turned off
 17783  17891   */
 17784  17892   #if 0
................................................................................
 18296  18404   ** on success or an error code is something goes wrong.
 18297  18405   */
 18298  18406   static int write32bits(OsFile *fd, u32 val){
 18299  18407     char ac[4];
 18300  18408     put32bits(ac, val);
 18301  18409     return sqlite3OsWrite(fd, ac, 4);
 18302  18410   }
 18303         -
 18304         -/*
 18305         -** Read a 32-bit integer at offset 'offset' from the page identified by
 18306         -** page header 'p'.
 18307         -*/
 18308         -static u32 retrieve32bits(PgHdr *p, int offset){
 18309         -  unsigned char *ac;
 18310         -  ac = &((unsigned char*)PGHDR_TO_DATA(p))[offset];
 18311         -  return sqlite3Get4byte(ac);
 18312         -}
 18313         -
 18314  18411   
 18315  18412   /*
 18316  18413   ** This function should be called when an error occurs within the pager
 18317  18414   ** code. The first argument is a pointer to the pager structure, the
 18318  18415   ** second the error-code about to be returned by a pager API function. 
 18319  18416   ** The value returned is a copy of the second argument to this function. 
 18320  18417   **
................................................................................
 19381  19478     }
 19382  19479     return rc;
 19383  19480   }
 19384  19481   
 19385  19482   /*
 19386  19483   ** Change the maximum number of in-memory pages that are allowed.
 19387  19484   */
 19388         -static void sqlite3PagerSetCachesize(Pager *pPager, int mxPage){
        19485  +SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager *pPager, int mxPage){
 19389  19486     if( mxPage>10 ){
 19390  19487       pPager->mxPage = mxPage;
 19391  19488     }else{
 19392  19489       pPager->mxPage = 10;
 19393  19490     }
 19394  19491   }
 19395  19492   
................................................................................
 19416  19513   **              assurance that the journal will not be corrupted to the
 19417  19514   **              point of causing damage to the database during rollback.
 19418  19515   **
 19419  19516   ** Numeric values associated with these states are OFF==1, NORMAL=2,
 19420  19517   ** and FULL=3.
 19421  19518   */
 19422  19519   #ifndef SQLITE_OMIT_PAGER_PRAGMAS
 19423         -static void sqlite3PagerSetSafetyLevel(Pager *pPager, int level, int full_fsync){
        19520  +SQLITE_PRIVATE void sqlite3PagerSetSafetyLevel(Pager *pPager, int level, int full_fsync){
 19424  19521     pPager->noSync =  level==1 || pPager->tempFile;
 19425  19522     pPager->fullSync = level==3 && !pPager->tempFile;
 19426  19523     pPager->full_fsync = full_fsync;
 19427  19524     if( pPager->noSync ) pPager->needSync = 0;
 19428  19525   }
 19429  19526   #endif
 19430  19527   
................................................................................
 19473  19570   ** and used as the file to be cached.  The file will be deleted
 19474  19571   ** automatically when it is closed.
 19475  19572   **
 19476  19573   ** If zFilename is ":memory:" then all information is held in cache.
 19477  19574   ** It is never written to disk.  This can be used to implement an
 19478  19575   ** in-memory database.
 19479  19576   */
 19480         -static int sqlite3PagerOpen(
        19577  +SQLITE_PRIVATE int sqlite3PagerOpen(
 19481  19578     Pager **ppPager,         /* Return the Pager structure here */
 19482  19579     const char *zFilename,   /* Name of the database file to open */
 19483  19580     int nExtra,              /* Extra bytes append to each in-memory page */
 19484  19581     int flags                /* flags controlling this file */
 19485  19582   ){
 19486  19583     Pager *pPager = 0;
 19487  19584     char *zFullPathname = 0;
................................................................................
 19624  19721   #endif
 19625  19722     return SQLITE_OK;
 19626  19723   }
 19627  19724   
 19628  19725   /*
 19629  19726   ** Set the busy handler function.
 19630  19727   */
 19631         -static void sqlite3PagerSetBusyhandler(Pager *pPager, BusyHandler *pBusyHandler){
        19728  +SQLITE_PRIVATE void sqlite3PagerSetBusyhandler(Pager *pPager, BusyHandler *pBusyHandler){
 19632  19729     pPager->pBusyHandler = pBusyHandler;
 19633  19730   }
 19634  19731   
 19635  19732   /*
 19636  19733   ** Set the destructor for this pager.  If not NULL, the destructor is called
 19637  19734   ** when the reference count on each page reaches zero.  The destructor can
 19638  19735   ** be used to clean up information in the extra segment appended to each page.
 19639  19736   **
 19640  19737   ** The destructor is not called as a result sqlite3PagerClose().  
 19641  19738   ** Destructors are only called by sqlite3PagerUnref().
 19642  19739   */
 19643         -static void sqlite3PagerSetDestructor(Pager *pPager, void (*xDesc)(DbPage*,int)){
        19740  +SQLITE_PRIVATE void sqlite3PagerSetDestructor(Pager *pPager, void (*xDesc)(DbPage*,int)){
 19644  19741     pPager->xDestructor = xDesc;
 19645  19742   }
 19646  19743   
 19647  19744   /*
 19648  19745   ** Set the reinitializer for this pager.  If not NULL, the reinitializer
 19649  19746   ** is called when the content of a page in cache is restored to its original
 19650  19747   ** value as a result of a rollback.  The callback gives higher-level code
 19651  19748   ** an opportunity to restore the EXTRA section to agree with the restored
 19652  19749   ** page data.
 19653  19750   */
 19654         -static void sqlite3PagerSetReiniter(Pager *pPager, void (*xReinit)(DbPage*,int)){
        19751  +SQLITE_PRIVATE void sqlite3PagerSetReiniter(Pager *pPager, void (*xReinit)(DbPage*,int)){
 19655  19752     pPager->xReiniter = xReinit;
 19656  19753   }
 19657  19754   
 19658  19755   /*
 19659  19756   ** Set the page size.  Return the new size.  If the suggest new page
 19660  19757   ** size is inappropriate, then an alternative page size is selected
 19661  19758   ** and returned.
 19662  19759   */
 19663         -static int sqlite3PagerSetPagesize(Pager *pPager, int pageSize){
        19760  +SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager *pPager, int pageSize){
 19664  19761     assert( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE );
 19665  19762     if( !pPager->memDb && pPager->nRef==0 ){
 19666  19763       pager_reset(pPager);
 19667  19764       pPager->pageSize = pageSize;
 19668  19765       pPager->pTmpSpace = sqlite3ReallocOrFree(pPager->pTmpSpace, pageSize);
 19669  19766     }
 19670  19767     return pPager->pageSize;
................................................................................
 19673  19770   /*
 19674  19771   ** Attempt to set the maximum database page count if mxPage is positive. 
 19675  19772   ** Make no changes if mxPage is zero or negative.  And never reduce the
 19676  19773   ** maximum page count below the current size of the database.
 19677  19774   **
 19678  19775   ** Regardless of mxPage, return the current maximum page count.
 19679  19776   */
 19680         -static int sqlite3PagerMaxPageCount(Pager *pPager, int mxPage){
        19777  +SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager *pPager, int mxPage){
 19681  19778     if( mxPage>0 ){
 19682  19779       pPager->mxPgno = mxPage;
 19683  19780     }
 19684  19781     sqlite3PagerPagecount(pPager);
 19685  19782     return pPager->mxPgno;
 19686  19783   }
 19687  19784   
................................................................................
 19715  19812   **
 19716  19813   ** No error checking is done. The rational for this is that this function 
 19717  19814   ** may be called even if the file does not exist or contain a header. In 
 19718  19815   ** these cases sqlite3OsRead() will return an error, to which the correct 
 19719  19816   ** response is to zero the memory at pDest and continue.  A real IO error 
 19720  19817   ** will presumably recur and be picked up later (Todo: Think about this).
 19721  19818   */
 19722         -static int sqlite3PagerReadFileheader(Pager *pPager, int N, unsigned char *pDest){
        19819  +SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager *pPager, int N, unsigned char *pDest){
 19723  19820     int rc = SQLITE_OK;
 19724  19821     memset(pDest, 0, N);
 19725  19822     if( MEMDB==0 ){
 19726  19823       disable_simulated_io_errors();
 19727  19824       sqlite3OsSeek(pPager->fd, 0);
 19728  19825       enable_simulated_io_errors();
 19729  19826       IOTRACE(("DBHDR %p 0 %d\n", pPager, N))
................................................................................
 19740  19837   ** pPager. 
 19741  19838   **
 19742  19839   ** If the PENDING_BYTE lies on the page directly after the end of the
 19743  19840   ** file, then consider this page part of the file too. For example, if
 19744  19841   ** PENDING_BYTE is byte 4096 (the first byte of page 5) and the size of the
 19745  19842   ** file is 4096 bytes, 5 is returned instead of 4.
 19746  19843   */
 19747         -static int sqlite3PagerPagecount(Pager *pPager){
        19844  +SQLITE_PRIVATE int sqlite3PagerPagecount(Pager *pPager){
 19748  19845     i64 n;
 19749  19846     int rc;
 19750  19847     assert( pPager!=0 );
 19751  19848     if( pPager->errCode ){
 19752  19849       return 0;
 19753  19850     }
 19754  19851     if( pPager->dbSize>=0 ){
................................................................................
 19925  20022     }
 19926  20023     return rc;
 19927  20024   }
 19928  20025   
 19929  20026   /*
 19930  20027   ** Truncate the file to the number of pages specified.
 19931  20028   */
 19932         -static int sqlite3PagerTruncate(Pager *pPager, Pgno nPage){
        20029  +SQLITE_PRIVATE int sqlite3PagerTruncate(Pager *pPager, Pgno nPage){
 19933  20030     int rc;
 19934  20031     assert( pPager->state>=PAGER_SHARED || MEMDB );
 19935  20032     sqlite3PagerPagecount(pPager);
 19936  20033     if( pPager->errCode ){
 19937  20034       rc = pPager->errCode;
 19938  20035       return rc;
 19939  20036     }
................................................................................
 19970  20067   ** result in a coredump.
 19971  20068   **
 19972  20069   ** This function always succeeds. If a transaction is active an attempt
 19973  20070   ** is made to roll it back. If an error occurs during the rollback 
 19974  20071   ** a hot journal may be left in the filesystem but no error is returned
 19975  20072   ** to the caller.
 19976  20073   */
 19977         -static int sqlite3PagerClose(Pager *pPager){
        20074  +SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager){
 19978  20075   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
 19979  20076     /* A malloc() cannot fail in sqlite3ThreadData() as one or more calls to 
 19980  20077     ** malloc() must have already been made by this thread before it gets
 19981  20078     ** to this point. This means the ThreadData must have been allocated already
 19982  20079     ** so that ThreadData.nAlloc can be set.
 19983  20080     */
 19984  20081     ThreadData *pTsd = sqlite3ThreadData();
................................................................................
 20027  20124     return SQLITE_OK;
 20028  20125   }
 20029  20126   
 20030  20127   #if !defined(NDEBUG) || defined(SQLITE_TEST)
 20031  20128   /*
 20032  20129   ** Return the page number for the given page data.
 20033  20130   */
 20034         -static Pgno sqlite3PagerPagenumber(DbPage *p){
        20131  +SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage *p){
 20035  20132     return p->pgno;
 20036  20133   }
 20037  20134   #endif
 20038  20135   
 20039  20136   /*
 20040  20137   ** The page_ref() function increments the reference count for a page.
 20041  20138   ** If the page is currently on the freelist (the reference count is zero) then
................................................................................
 20081  20178   # define page_ref(P)   ((P)->nRef==0?_page_ref(P):(void)(P)->nRef++)
 20082  20179   #endif
 20083  20180   
 20084  20181   /*
 20085  20182   ** Increment the reference count for a page.  The input pointer is
 20086  20183   ** a reference to the page data.
 20087  20184   */
 20088         -static int sqlite3PagerRef(DbPage *pPg){
        20185  +SQLITE_PRIVATE int sqlite3PagerRef(DbPage *pPg){
 20089  20186     page_ref(pPg);
 20090  20187     return SQLITE_OK;
 20091  20188   }
 20092  20189   
 20093  20190   /*
 20094  20191   ** Sync the journal.  In other words, make sure all the pages that have
 20095  20192   ** been written to the journal have actually reached the surface of the
................................................................................
 20459  20556   **
 20460  20557   ** nReq is the number of bytes of memory required. Once this much has
 20461  20558   ** been released, the function returns. A negative value for nReq means
 20462  20559   ** free as much memory as possible. The return value is the total number 
 20463  20560   ** of bytes of memory released.
 20464  20561   */
 20465  20562   #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO)
 20466         -static int sqlite3PagerReleaseMemory(int nReq){
        20563  +SQLITE_PRIVATE int sqlite3PagerReleaseMemory(int nReq){
 20467  20564     const ThreadData *pTsdro = sqlite3ThreadDataReadOnly();
 20468  20565     int nReleased = 0;
 20469  20566     int i;
 20470  20567   
 20471  20568     /* If the the global mutex is held, this subroutine becomes a
 20472  20569     ** o-op; zero bytes of memory are freed.  This is because
 20473  20570     ** some of the code invoked by this function may also
................................................................................
 20840  20937   ** of the page at this time, so do not do a disk read.  Just fill in the
 20841  20938   ** page content with zeros.  But mark the fact that we have not read the
 20842  20939   ** content by setting the PgHdr.needRead flag.  Later on, if 
 20843  20940   ** sqlite3PagerWrite() is called on this page or if this routine is
 20844  20941   ** called again with noContent==0, that means that the content is needed
 20845  20942   ** and the disk read should occur at that point.
 20846  20943   */
 20847         -static int sqlite3PagerAcquire(
        20944  +SQLITE_PRIVATE int sqlite3PagerAcquire(
 20848  20945     Pager *pPager,      /* The pager open on the database file */
 20849  20946     Pgno pgno,          /* Page number to fetch */
 20850  20947     DbPage **ppPage,    /* Write a pointer to the page here */
 20851  20948     int noContent       /* Do not bother reading content from disk if true */
 20852  20949   ){
 20853  20950     PgHdr *pPg;
 20854  20951     int rc;
................................................................................
 20975  21072   **
 20976  21073   ** See also sqlite3PagerGet().  The difference between this routine
 20977  21074   ** and sqlite3PagerGet() is that _get() will go to the disk and read
 20978  21075   ** in the page if the page is not already in cache.  This routine
 20979  21076   ** returns NULL if the page is not in cache or if a disk I/O error 
 20980  21077   ** has ever happened.
 20981  21078   */
 20982         -static DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno){
        21079  +SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno){
 20983  21080     PgHdr *pPg;
 20984  21081   
 20985  21082     assert( pPager!=0 );
 20986  21083     assert( pgno!=0 );
 20987  21084   
 20988  21085     if( pPager->state==PAGER_UNLOCK ){
 20989  21086       assert( !pPager->pAll || pPager->exclusiveMode );
................................................................................
 21002  21099   ** Release a page.
 21003  21100   **
 21004  21101   ** If the number of references to the page drop to zero, then the
 21005  21102   ** page is added to the LRU list.  When all references to all pages
 21006  21103   ** are released, a rollback occurs and the lock on the database is
 21007  21104   ** removed.
 21008  21105   */
 21009         -static int sqlite3PagerUnref(DbPage *pPg){
        21106  +SQLITE_PRIVATE int sqlite3PagerUnref(DbPage *pPg){
 21010  21107   
 21011  21108     /* Decrement the reference count for this page
 21012  21109     */
 21013  21110     assert( pPg->nRef>0 );
 21014  21111     pPg->nRef--;
 21015  21112     REFINFO(pPg);
 21016  21113   
................................................................................
 21137  21234   **
 21138  21235   ** If the database is already reserved for writing, this routine is a no-op.
 21139  21236   **
 21140  21237   ** If exFlag is true, go ahead and get an EXCLUSIVE lock on the file
 21141  21238   ** immediately instead of waiting until we try to flush the cache.  The
 21142  21239   ** exFlag is ignored if a transaction is already active.
 21143  21240   */
 21144         -static int sqlite3PagerBegin(DbPage *pPg, int exFlag){
        21241  +SQLITE_PRIVATE int sqlite3PagerBegin(DbPage *pPg, int exFlag){
 21145  21242     Pager *pPager = pPg->pPager;
 21146  21243     int rc = SQLITE_OK;
 21147  21244     assert( pPg->nRef>0 );
 21148  21245     assert( pPager->state!=PAGER_UNLOCK );
 21149  21246     if( pPager->state==PAGER_SHARED ){
 21150  21247       assert( pPager->aInJournal==0 );
 21151  21248       if( MEMDB ){
................................................................................
 21419  21516   ** and write the page *pData to the journal.
 21420  21517   **
 21421  21518   ** The difference between this function and pager_write() is that this
 21422  21519   ** function also deals with the special case where 2 or more pages
 21423  21520   ** fit on a single disk sector. In this case all co-resident pages
 21424  21521   ** must have been written to the journal file before returning.
 21425  21522   */
 21426         -static int sqlite3PagerWrite(DbPage *pDbPage){
        21523  +SQLITE_PRIVATE int sqlite3PagerWrite(DbPage *pDbPage){
 21427  21524     int rc = SQLITE_OK;
 21428  21525   
 21429  21526     PgHdr *pPg = pDbPage;
 21430  21527     Pager *pPager = pPg->pPager;
 21431  21528     Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize);
 21432  21529   
 21433  21530     if( !MEMDB && nPagePerSector>1 ){
................................................................................
 21486  21583   
 21487  21584   /*
 21488  21585   ** Return TRUE if the page given in the argument was previously passed
 21489  21586   ** to sqlite3PagerWrite().  In other words, return TRUE if it is ok
 21490  21587   ** to change the content of the page.
 21491  21588   */
 21492  21589   #ifndef NDEBUG
 21493         -static int sqlite3PagerIswriteable(DbPage *pPg){
        21590  +SQLITE_PRIVATE int sqlite3PagerIswriteable(DbPage *pPg){
 21494  21591     return pPg->dirty;
 21495  21592   }
 21496  21593   #endif
 21497  21594   
 21498  21595   #ifndef SQLITE_OMIT_VACUUM
 21499  21596   /*
 21500  21597   ** Replace the content of a single page with the information in the third
 21501  21598   ** argument.
 21502  21599   */
 21503         -static int sqlite3PagerOverwrite(Pager *pPager, Pgno pgno, void *pData){
        21600  +SQLITE_PRIVATE int sqlite3PagerOverwrite(Pager *pPager, Pgno pgno, void *pData){
 21504  21601     PgHdr *pPg;
 21505  21602     int rc;
 21506  21603   
 21507  21604     rc = sqlite3PagerGet(pPager, pgno, &pPg);
 21508  21605     if( rc==SQLITE_OK ){
 21509  21606       rc = sqlite3PagerWrite(pPg);
 21510  21607       if( rc==SQLITE_OK ){
................................................................................
 21536  21633   ** a transaction then removed from the freelist during a later part
 21537  21634   ** of the same transaction and reused for some other purpose.  When it
 21538  21635   ** is first added to the freelist, this routine is called.  When reused,
 21539  21636   ** the sqlite3PagerDontRollback() routine is called.  But because the
 21540  21637   ** page contains critical data, we still need to be sure it gets
 21541  21638   ** rolled back in spite of the sqlite3PagerDontRollback() call.
 21542  21639   */
 21543         -static void sqlite3PagerDontWrite(DbPage *pDbPage){
        21640  +SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage *pDbPage){
 21544  21641     PgHdr *pPg = pDbPage;
 21545  21642     Pager *pPager = pPg->pPager;
 21546  21643   
 21547  21644     if( MEMDB ) return;
 21548  21645     pPg->alwaysRollback = 1;
 21549  21646     if( pPg->dirty && !pPager->stmtInUse ){
 21550  21647       assert( pPager->state>=PAGER_SHARED );
................................................................................
 21575  21672   ** rollback journal.
 21576  21673   **
 21577  21674   ** If we have not yet actually read the content of this page (if
 21578  21675   ** the PgHdr.needRead flag is set) then this routine acts as a promise
 21579  21676   ** that we will never need to read the page content in the future.
 21580  21677   ** so the needRead flag can be cleared at this point.
 21581  21678   */
 21582         -static void sqlite3PagerDontRollback(DbPage *pPg){
        21679  +SQLITE_PRIVATE void sqlite3PagerDontRollback(DbPage *pPg){
 21583  21680     Pager *pPager = pPg->pPager;
 21584  21681   
 21585  21682     assert( pPager->state>=PAGER_RESERVED );
 21586  21683     if( pPager->journalOpen==0 ) return;
 21587  21684     if( pPg->alwaysRollback || pPager->alwaysRollback || MEMDB ) return;
 21588  21685     if( !pPg->inJournal && (int)pPg->pgno <= pPager->origDbSize ){
 21589  21686       assert( pPager->aInJournal!=0 );
................................................................................
 21619  21716     if( !pPager->changeCountDone ){
 21620  21717       /* Open page 1 of the file for writing. */
 21621  21718       rc = sqlite3PagerGet(pPager, 1, &pPgHdr);
 21622  21719       if( rc!=SQLITE_OK ) return rc;
 21623  21720       rc = sqlite3PagerWrite(pPgHdr);
 21624  21721       if( rc!=SQLITE_OK ) return rc;
 21625  21722     
 21626         -    /* Read the current value at byte 24. */
 21627         -    change_counter = retrieve32bits(pPgHdr, 24);
 21628         -  
 21629  21723       /* Increment the value just read and write it back to byte 24. */
        21724  +    change_counter = sqlite3Get4byte((u8*)pPager->dbFileVers);
 21630  21725       change_counter++;
 21631  21726       put32bits(((char*)PGHDR_TO_DATA(pPgHdr))+24, change_counter);
 21632         -  
 21633  21727       /* Release the page reference. */
 21634  21728       sqlite3PagerUnref(pPgHdr);
 21635  21729       pPager->changeCountDone = 1;
 21636  21730     }
 21637  21731     return SQLITE_OK;
 21638  21732   }
 21639  21733   
................................................................................
 21650  21744   **
 21651  21745   ** Note that if zMaster==NULL, this does not overwrite a previous value
 21652  21746   ** passed to an sqlite3PagerCommitPhaseOne() call.
 21653  21747   **
 21654  21748   ** If parameter nTrunc is non-zero, then the pager file is truncated to
 21655  21749   ** nTrunc pages (this is used by auto-vacuum databases).
 21656  21750   */
 21657         -static int sqlite3PagerCommitPhaseOne(Pager *pPager, const char *zMaster, Pgno nTrunc){
        21751  +SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager *pPager, const char *zMaster, Pgno nTrunc){
 21658  21752     int rc = SQLITE_OK;
 21659  21753   
 21660  21754     PAGERTRACE4("DATABASE SYNC: File=%s zMaster=%s nTrunc=%d\n", 
 21661  21755         pPager->zFilename, zMaster, nTrunc);
 21662  21756   
 21663  21757     /* If this is an in-memory db, or no pages have been written to, or this
 21664  21758     ** function has already been called, it is a no-op.
................................................................................
 21741  21835   /*
 21742  21836   ** Commit all changes to the database and release the write lock.
 21743  21837   **
 21744  21838   ** If the commit fails for any reason, a rollback attempt is made
 21745  21839   ** and an error code is returned.  If the commit worked, SQLITE_OK
 21746  21840   ** is returned.
 21747  21841   */
 21748         -static int sqlite3PagerCommitPhaseTwo(Pager *pPager){
        21842  +SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager *pPager){
 21749  21843     int rc;
 21750  21844     PgHdr *pPg;
 21751  21845   
 21752  21846     if( pPager->errCode ){
 21753  21847       return pPager->errCode;
 21754  21848     }
 21755  21849     if( pPager->state<PAGER_RESERVED ){
................................................................................
 21795  21889   ** This routine cannot fail unless some other process is not following
 21796  21890   ** the correct locking protocol or unless some other
 21797  21891   ** process is writing trash into the journal file (SQLITE_CORRUPT) or
 21798  21892   ** unless a prior malloc() failed (SQLITE_NOMEM).  Appropriate error
 21799  21893   ** codes are returned for all these occasions.  Otherwise,
 21800  21894   ** SQLITE_OK is returned.
 21801  21895   */
 21802         -static int sqlite3PagerRollback(Pager *pPager){
        21896  +SQLITE_PRIVATE int sqlite3PagerRollback(Pager *pPager){
 21803  21897     int rc;
 21804  21898     PAGERTRACE2("ROLLBACK %d\n", PAGERID(pPager));
 21805  21899     if( MEMDB ){
 21806  21900       PgHdr *p;
 21807  21901       for(p=pPager->pAll; p; p=p->pNextAll){
 21808  21902         PgHistory *pHist;
 21809  21903         assert( !p->alwaysRollback );
................................................................................
 21869  21963     return pager_error(pPager, rc);
 21870  21964   }
 21871  21965   
 21872  21966   /*
 21873  21967   ** Return TRUE if the database file is opened read-only.  Return FALSE
 21874  21968   ** if the database is (in theory) writable.
 21875  21969   */
 21876         -static int sqlite3PagerIsreadonly(Pager *pPager){
        21970  +SQLITE_PRIVATE int sqlite3PagerIsreadonly(Pager *pPager){
 21877  21971     return pPager->readOnly;
 21878  21972   }
 21879  21973   
 21880  21974   /*
 21881  21975   ** Return the number of references to the pager.
 21882  21976   */
 21883         -static int sqlite3PagerRefcount(Pager *pPager){
        21977  +SQLITE_PRIVATE int sqlite3PagerRefcount(Pager *pPager){
 21884  21978     return pPager->nRef;
 21885  21979   }
 21886  21980   
 21887  21981   #ifdef SQLITE_TEST
 21888  21982   /*
 21889  21983   ** This routine is used for testing and analysis only.
 21890  21984   */
 21891         -static int *sqlite3PagerStats(Pager *pPager){
        21985  +SQLITE_PRIVATE int *sqlite3PagerStats(Pager *pPager){
 21892  21986     static int a[11];
 21893  21987     a[0] = pPager->nRef;
 21894  21988     a[1] = pPager->nPage;
 21895  21989     a[2] = pPager->mxPage;
 21896  21990     a[3] = pPager->dbSize;
 21897  21991     a[4] = pPager->state;
 21898  21992     a[5] = pPager->errCode;
................................................................................
 21908  22002   /*
 21909  22003   ** Set the statement rollback point.
 21910  22004   **
 21911  22005   ** This routine should be called with the transaction journal already
 21912  22006   ** open.  A new statement journal is created that can be used to rollback
 21913  22007   ** changes of a single SQL command within a larger transaction.
 21914  22008   */
 21915         -static int sqlite3PagerStmtBegin(Pager *pPager){
        22009  +SQLITE_PRIVATE int sqlite3PagerStmtBegin(Pager *pPager){
 21916  22010     int rc;
 21917  22011     assert( !pPager->stmtInUse );
 21918  22012     assert( pPager->state>=PAGER_SHARED );
 21919  22013     assert( pPager->dbSize>=0 );
 21920  22014     PAGERTRACE2("STMT-BEGIN %d\n", PAGERID(pPager));
 21921  22015     if( MEMDB ){
 21922  22016       pPager->stmtInUse = 1;
................................................................................
 21958  22052     }
 21959  22053     return rc;
 21960  22054   }
 21961  22055   
 21962  22056   /*
 21963  22057   ** Commit a statement.
 21964  22058   */
 21965         -static int sqlite3PagerStmtCommit(Pager *pPager){
        22059  +SQLITE_PRIVATE int sqlite3PagerStmtCommit(Pager *pPager){
 21966  22060     if( pPager->stmtInUse ){
 21967  22061       PgHdr *pPg, *pNext;
 21968  22062       PAGERTRACE2("STMT-COMMIT %d\n", PAGERID(pPager));
 21969  22063       if( !MEMDB ){
 21970  22064         sqlite3OsSeek(pPager->stfd, 0);
 21971  22065         /* sqlite3OsTruncate(pPager->stfd, 0); */
 21972  22066         sqliteFree( pPager->aInStmt );
................................................................................
 21989  22083     pPager->stmtAutoopen = 0;
 21990  22084     return SQLITE_OK;
 21991  22085   }
 21992  22086   
 21993  22087   /*
 21994  22088   ** Rollback a statement.
 21995  22089   */
 21996         -static int sqlite3PagerStmtRollback(Pager *pPager){
        22090  +SQLITE_PRIVATE int sqlite3PagerStmtRollback(Pager *pPager){
 21997  22091     int rc;
 21998  22092     if( pPager->stmtInUse ){
 21999  22093       PAGERTRACE2("STMT-ROLLBACK %d\n", PAGERID(pPager));
 22000  22094       if( MEMDB ){
 22001  22095         PgHdr *pPg;
 22002  22096         PgHistory *pHist;
 22003  22097         for(pPg=pPager->pStmt; pPg; pPg=pHist->pNextStmt){
................................................................................
 22021  22115     pPager->stmtAutoopen = 0;
 22022  22116     return rc;
 22023  22117   }
 22024  22118   
 22025  22119   /*
 22026  22120   ** Return the full pathname of the database file.
 22027  22121   */
 22028         -static const char *sqlite3PagerFilename(Pager *pPager){
        22122  +SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager *pPager){
 22029  22123     return pPager->zFilename;
 22030  22124   }
 22031  22125   
 22032  22126   /*
 22033  22127   ** Return the directory of the database file.
 22034  22128   */
 22035         -static const char *sqlite3PagerDirname(Pager *pPager){
        22129  +SQLITE_PRIVATE const char *sqlite3PagerDirname(Pager *pPager){
 22036  22130     return pPager->zDirectory;
 22037  22131   }
 22038  22132   
 22039  22133   /*
 22040  22134   ** Return the full pathname of the journal file.
 22041  22135   */
 22042         -static const char *sqlite3PagerJournalname(Pager *pPager){
        22136  +SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager *pPager){
 22043  22137     return pPager->zJournal;
 22044  22138   }
 22045  22139   
 22046  22140   /*
 22047  22141   ** Return true if fsync() calls are disabled for this pager.  Return FALSE
 22048  22142   ** if fsync()s are executed normally.
 22049  22143   */
 22050         -static int sqlite3PagerNosync(Pager *pPager){
        22144  +SQLITE_PRIVATE int sqlite3PagerNosync(Pager *pPager){
 22051  22145     return pPager->noSync;
 22052  22146   }
 22053  22147   
 22054  22148   #ifdef SQLITE_HAS_CODEC
 22055  22149   /*
 22056  22150   ** Set the codec for this pager
 22057  22151   */
 22058         -static void sqlite3PagerSetCodec(
        22152  +SQLITE_PRIVATE void sqlite3PagerSetCodec(
 22059  22153     Pager *pPager,
 22060  22154     void *(*xCodec)(void*,void*,Pgno,int),
 22061  22155     void *pCodecArg
 22062  22156   ){
 22063  22157     pPager->xCodec = xCodec;
 22064  22158     pPager->pCodecArg = pCodecArg;
 22065  22159   }
................................................................................
 22079  22173   ** allocated along with the page) is the responsibility of the caller.
 22080  22174   **
 22081  22175   ** A transaction must be active when this routine is called. It used to be
 22082  22176   ** required that a statement transaction was not active, but this restriction
 22083  22177   ** has been removed (CREATE INDEX needs to move a page when a statement
 22084  22178   ** transaction is active).
 22085  22179   */
 22086         -static int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno){
        22180  +SQLITE_PRIVATE int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno){
 22087  22181     PgHdr *pPgOld;  /* The page being overwritten. */
 22088  22182     int h;
 22089  22183     Pgno needSyncPgno = 0;
 22090  22184   
 22091  22185     assert( pPg->nRef>0 );
 22092  22186   
 22093  22187     PAGERTRACE5("MOVE %d page %d (needSync=%d) moves to %d\n", 
................................................................................
 22167  22261     return SQLITE_OK;
 22168  22262   }
 22169  22263   #endif
 22170  22264   
 22171  22265   /*
 22172  22266   ** Return a pointer to the data for the specified page.
 22173  22267   */
 22174         -static void *sqlite3PagerGetData(DbPage *pPg){
        22268  +SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *pPg){
 22175  22269     return PGHDR_TO_DATA(pPg);
 22176  22270   }
 22177  22271   
 22178  22272   /*
 22179  22273   ** Return a pointer to the Pager.nExtra bytes of "extra" space 
 22180  22274   ** allocated along with the specified page.
 22181  22275   */
 22182         -static void *sqlite3PagerGetExtra(DbPage *pPg){
        22276  +SQLITE_PRIVATE void *sqlite3PagerGetExtra(DbPage *pPg){
 22183  22277     Pager *pPager = pPg->pPager;
 22184  22278     return (pPager?PGHDR_TO_EXTRA(pPg, pPager):0);
 22185  22279   }
 22186  22280   
 22187  22281   /*
 22188  22282   ** Get/set the locking-mode for this pager. Parameter eMode must be one
 22189  22283   ** of PAGER_LOCKINGMODE_QUERY, PAGER_LOCKINGMODE_NORMAL or 
................................................................................
 22190  22284   ** PAGER_LOCKINGMODE_EXCLUSIVE. If the parameter is not _QUERY, then
 22191  22285   ** the locking-mode is set to the value specified.
 22192  22286   **
 22193  22287   ** The returned value is either PAGER_LOCKINGMODE_NORMAL or
 22194  22288   ** PAGER_LOCKINGMODE_EXCLUSIVE, indicating the current (possibly updated)
 22195  22289   ** locking-mode.
 22196  22290   */
 22197         -static int sqlite3PagerLockingMode(Pager *pPager, int eMode){
        22291  +SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *pPager, int eMode){
 22198  22292     assert( eMode==PAGER_LOCKINGMODE_QUERY
 22199  22293               || eMode==PAGER_LOCKINGMODE_NORMAL
 22200  22294               || eMode==PAGER_LOCKINGMODE_EXCLUSIVE );
 22201  22295     assert( PAGER_LOCKINGMODE_QUERY<0 );
 22202  22296     assert( PAGER_LOCKINGMODE_NORMAL>=0 && PAGER_LOCKINGMODE_EXCLUSIVE>=0 );
 22203  22297     if( eMode>=0 && !pPager->tempFile ){
 22204  22298       pPager->exclusiveMode = eMode;
................................................................................
 22208  22302   
 22209  22303   #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
 22210  22304   /*
 22211  22305   ** Return the current state of the file lock for the given pager.
 22212  22306   ** The return value is one of NO_LOCK, SHARED_LOCK, RESERVED_LOCK,
 22213  22307   ** PENDING_LOCK, or EXCLUSIVE_LOCK.
 22214  22308   */
 22215         -static int sqlite3PagerLockstate(Pager *pPager){
        22309  +SQLITE_PRIVATE int sqlite3PagerLockstate(Pager *pPager){
 22216  22310     return sqlite3OsLockState(pPager->fd);
 22217  22311   }
 22218  22312   #endif
 22219  22313   
 22220  22314   #ifdef SQLITE_DEBUG
 22221  22315   /*
 22222  22316   ** Print a listing of all referenced pages and their ref count.
 22223  22317   */
 22224         -static void sqlite3PagerRefdump(Pager *pPager){
        22318  +SQLITE_PRIVATE void sqlite3PagerRefdump(Pager *pPager){
 22225  22319     PgHdr *pPg;
 22226  22320     for(pPg=pPager->pAll; pPg; pPg=pPg->pNextAll){
 22227  22321       if( pPg->nRef<=0 ) continue;
 22228  22322       sqlite3DebugPrintf("PAGE %3d addr=%p nRef=%d\n", 
 22229  22323          pPg->pgno, PGHDR_TO_DATA(pPg), pPg->nRef);
 22230  22324     }
 22231  22325   }
................................................................................
 22242  22336   ** a legal notice, here is a blessing:
 22243  22337   **
 22244  22338   **    May you do good and not evil.
 22245  22339   **    May you find forgiveness for yourself and forgive others.
 22246  22340   **    May you share freely, never taking more than you give.
 22247  22341   **
 22248  22342   *************************************************************************
 22249         -** $Id: sqlite3.c,v 1.3 2007/06/19 22:43:23 rmsimpson Exp $
        22343  +** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
 22250  22344   **
 22251  22345   ** This file implements a external (disk-based) database using BTrees.
 22252  22346   ** See the header comment on "btreeInt.h" for additional information.
 22253  22347   ** Including a description of file format and an overview of operation.
 22254  22348   */
 22255  22349   /************** Include btreeInt.h in the middle of btree.c ******************/
 22256  22350   /************** Begin file btreeInt.h ****************************************/
................................................................................
 22261  22355   ** a legal notice, here is a blessing:
 22262  22356   **
 22263  22357   **    May you do good and not evil.
 22264  22358   **    May you find forgiveness for yourself and forgive others.
 22265  22359   **    May you share freely, never taking more than you give.
 22266  22360   **
 22267  22361   *************************************************************************
 22268         -** $Id: sqlite3.c,v 1.3 2007/06/19 22:43:23 rmsimpson Exp $
        22362  +** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
 22269  22363   **
 22270  22364   ** This file implements a external (disk-based) database using BTrees.
 22271  22365   ** For a detailed discussion of BTrees, refer to
 22272  22366   **
 22273  22367   **     Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
 22274  22368   **     "Sorting And Searching", pages 473-480. Addison-Wesley
 22275  22369   **     Publishing Company, Reading, Massachusetts.
................................................................................
 22823  22917   #define put2byte(p,v) ((p)[0] = (v)>>8, (p)[1] = (v))
 22824  22918   #define get4byte sqlite3Get4byte
 22825  22919   #define put4byte sqlite3Put4byte
 22826  22920   
 22827  22921   /*
 22828  22922   ** Internal routines that should be accessed by the btree layer only.
 22829  22923   */
 22830         -static int sqlite3BtreeGetPage(BtShared*, Pgno, MemPage**, int);
 22831         -static int sqlite3BtreeInitPage(MemPage *pPage, MemPage *pParent);
 22832         -static void sqlite3BtreeParseCellPtr(MemPage*, u8*, CellInfo*);
 22833         -static void sqlite3BtreeParseCell(MemPage*, int, CellInfo*);
 22834         -static u8 *sqlite3BtreeFindCell(MemPage *pPage, int iCell);
 22835         -static int sqlite3BtreeRestoreOrClearCursorPosition(BtCursor *pCur);
 22836         -static void sqlite3BtreeGetTempCursor(BtCursor *pCur, BtCursor *pTempCur);
 22837         -static void sqlite3BtreeReleaseTempCursor(BtCursor *pCur);
 22838         -static int sqlite3BtreeIsRootPage(MemPage *pPage);
 22839         -static void sqlite3BtreeMoveToParent(BtCursor *pCur);
        22924  +SQLITE_PRIVATE int sqlite3BtreeGetPage(BtShared*, Pgno, MemPage**, int);
        22925  +SQLITE_PRIVATE int sqlite3BtreeInitPage(MemPage *pPage, MemPage *pParent);
        22926  +SQLITE_PRIVATE void sqlite3BtreeParseCellPtr(MemPage*, u8*, CellInfo*);
        22927  +SQLITE_PRIVATE void sqlite3BtreeParseCell(MemPage*, int, CellInfo*);
        22928  +SQLITE_PRIVATE u8 *sqlite3BtreeFindCell(MemPage *pPage, int iCell);
        22929  +SQLITE_PRIVATE int sqlite3BtreeRestoreOrClearCursorPosition(BtCursor *pCur);
        22930  +SQLITE_PRIVATE void sqlite3BtreeGetTempCursor(BtCursor *pCur, BtCursor *pTempCur);
        22931  +SQLITE_PRIVATE void sqlite3BtreeReleaseTempCursor(BtCursor *pCur);
        22932  +SQLITE_PRIVATE int sqlite3BtreeIsRootPage(MemPage *pPage);
        22933  +SQLITE_PRIVATE void sqlite3BtreeMoveToParent(BtCursor *pCur);
 22840  22934   
 22841  22935   /************** End of btreeInt.h ********************************************/
 22842  22936   /************** Continuing where we left off in btree.c **********************/
 22843  22937   
 22844  22938   /*
 22845  22939   ** The header string that appears at the beginning of every
 22846  22940   ** SQLite database.
................................................................................
 23118  23212   ** at most one effective restoreOrClearCursorPosition() call after each 
 23119  23213   ** saveCursorPosition().
 23120  23214   **
 23121  23215   ** If the second argument argument - doSeek - is false, then instead of 
 23122  23216   ** returning the cursor to it's saved position, any saved position is deleted
 23123  23217   ** and the cursor state set to CURSOR_INVALID.
 23124  23218   */
 23125         -static int sqlite3BtreeRestoreOrClearCursorPosition(BtCursor *pCur){
        23219  +SQLITE_PRIVATE int sqlite3BtreeRestoreOrClearCursorPosition(BtCursor *pCur){
 23126  23220     int rc;
 23127  23221     assert( pCur->eState==CURSOR_REQUIRESEEK );
 23128  23222   #ifndef SQLITE_OMIT_INCRBLOB
 23129  23223     if( pCur->isIncrblobHandle ){
 23130  23224       return SQLITE_ABORT;
 23131  23225     }
 23132  23226   #endif
................................................................................
 23241  23335   ** the page, 1 means the second cell, and so forth) return a pointer
 23242  23336   ** to the cell content.
 23243  23337   **
 23244  23338   ** This routine works only for pages that do not contain overflow cells.
 23245  23339   */
 23246  23340   #define findCell(pPage, iCell) \
 23247  23341     ((pPage)->aData + get2byte(&(pPage)->aData[(pPage)->cellOffset+2*(iCell)]))
 23248         -static u8 *sqlite3BtreeFindCell(MemPage *pPage, int iCell){
 23249         -  u8 *data = pPage->aData;
        23342  +SQLITE_PRIVATE u8 *sqlite3BtreeFindCell(MemPage *pPage, int iCell){
 23250  23343     assert( iCell>=0 );
 23251         -  assert( iCell<get2byte(&data[pPage->hdrOffset+3]) );
        23344  +  assert( iCell<get2byte(&pPage->aData[pPage->hdrOffset+3]) );
 23252  23345     return findCell(pPage, iCell);
 23253  23346   }
 23254  23347   
 23255  23348   /*
 23256  23349   ** This a more complex version of sqlite3BtreeFindCell() that works for
 23257  23350   ** pages that do contain overflow cells.  See insert
 23258  23351   */
................................................................................
 23278  23371   ** are two versions of this function.  sqlite3BtreeParseCell() takes a 
 23279  23372   ** cell index as the second argument and sqlite3BtreeParseCellPtr() 
 23280  23373   ** takes a pointer to the body of the cell as its second argument.
 23281  23374   **
 23282  23375   ** Within this file, the parseCell() macro can be called instead of
 23283  23376   ** sqlite3BtreeParseCellPtr(). Using some compilers, this will be faster.
 23284  23377   */
 23285         -static void sqlite3BtreeParseCellPtr(
        23378  +SQLITE_PRIVATE void sqlite3BtreeParseCellPtr(
 23286  23379     MemPage *pPage,         /* Page containing the cell */
 23287  23380     u8 *pCell,              /* Pointer to the cell text. */
 23288  23381     CellInfo *pInfo         /* Fill in this structure */
 23289  23382   ){
 23290  23383     int n;                  /* Number bytes in cell content header */
 23291  23384     u32 nPayload;           /* Number of bytes of cell payload */
 23292  23385   
................................................................................
 23346  23439       }
 23347  23440       pInfo->iOverflow = pInfo->nLocal + n;
 23348  23441       pInfo->nSize = pInfo->iOverflow + 4;
 23349  23442     }
 23350  23443   }
 23351  23444   #define parseCell(pPage, iCell, pInfo) \
 23352  23445     sqlite3BtreeParseCellPtr((pPage), findCell((pPage), (iCell)), (pInfo))
 23353         -static void sqlite3BtreeParseCell(
        23446  +SQLITE_PRIVATE void sqlite3BtreeParseCell(
 23354  23447     MemPage *pPage,         /* Page containing the cell */
 23355  23448     int iCell,              /* The cell index.  First cell is 0 */
 23356  23449     CellInfo *pInfo         /* Fill in this structure */
 23357  23450   ){
 23358  23451     parseCell(pPage, iCell, pInfo);
 23359  23452   }
 23360  23453   
................................................................................
 23631  23724   **
 23632  23725   ** Return SQLITE_OK on success.  If we see that the page does
 23633  23726   ** not contain a well-formed database page, then return 
 23634  23727   ** SQLITE_CORRUPT.  Note that a return of SQLITE_OK does not
 23635  23728   ** guarantee that the page is well-formed.  It only shows that
 23636  23729   ** we failed to detect any corruption.
 23637  23730   */
 23638         -static int sqlite3BtreeInitPage(
        23731  +SQLITE_PRIVATE int sqlite3BtreeInitPage(
 23639  23732     MemPage *pPage,        /* The page to be initialized */
 23640  23733     MemPage *pParent       /* The parent.  Might be NULL */
 23641  23734   ){
 23642  23735     int pc;            /* Address of a freeblock within pPage->aData[] */
 23643  23736     int hdr;           /* Offset to beginning of page header */
 23644  23737     u8 *data;          /* Equal to pPage->aData */
 23645  23738     BtShared *pBt;        /* The main btree structure */
................................................................................
 23744  23837   ** If the noContent flag is set, it means that we do not care about
 23745  23838   ** the content of the page at this time.  So do not go to the disk
 23746  23839   ** to fetch the content.  Just fill in the content with zeros for now.
 23747  23840   ** If in the future we call sqlite3PagerWrite() on this page, that
 23748  23841   ** means we have started to be concerned about content and the disk
 23749  23842   ** read should occur at that point.
 23750  23843   */
 23751         -static int sqlite3BtreeGetPage(
        23844  +SQLITE_PRIVATE int sqlite3BtreeGetPage(
 23752  23845     BtShared *pBt,       /* The btree */
 23753  23846     Pgno pgno,           /* Number of the page to fetch */
 23754  23847     MemPage **ppPage,    /* Return the page in this parameter */
 23755  23848     int noContent        /* Do not load page content if true */
 23756  23849   ){
 23757  23850     int rc;
 23758  23851     MemPage *pPage;
................................................................................
 23843  23936   /*
 23844  23937   ** Open a database file.
 23845  23938   ** 
 23846  23939   ** zFilename is the name of the database file.  If zFilename is NULL
 23847  23940   ** a new database with a random name is created.  This randomly named
 23848  23941   ** database file will be deleted when sqlite3BtreeClose() is called.
 23849  23942   */
 23850         -static int sqlite3BtreeOpen(
        23943  +SQLITE_PRIVATE int sqlite3BtreeOpen(
 23851  23944     const char *zFilename,  /* Name of the file containing the BTree database */
 23852  23945     sqlite3 *pSqlite,       /* Associated database handle */
 23853  23946     Btree **ppBtree,        /* Pointer to new Btree object written here */
 23854  23947     int flags               /* Options */
 23855  23948   ){
 23856  23949     BtShared *pBt;          /* Shared part of btree structure */
 23857  23950     Btree *p;               /* Handle to return */
................................................................................
 23959  24052       nReserve = zDbHeader[20];
 23960  24053       pBt->maxEmbedFrac = zDbHeader[21];
 23961  24054       pBt->minEmbedFrac = zDbHeader[22];
 23962  24055       pBt->minLeafFrac = zDbHeader[23];
 23963  24056       pBt->pageSizeFixed = 1;
 23964  24057   #ifndef SQLITE_OMIT_AUTOVACUUM
 23965  24058       pBt->autoVacuum = (get4byte(&zDbHeader[36 + 4*4])?1:0);
        24059  +    pBt->incrVacuum = (get4byte(&zDbHeader[36 + 7*4])?1:0);
 23966  24060   #endif
 23967  24061     }
 23968  24062     pBt->usableSize = pBt->pageSize - nReserve;
 23969  24063     assert( (pBt->pageSize & 7)==0 );  /* 8-byte alignment of pageSize */
 23970  24064     sqlite3PagerSetPagesize(pBt->pPager, pBt->pageSize);
 23971  24065   
 23972  24066   #if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
................................................................................
 23994  24088     }
 23995  24089     return rc;
 23996  24090   }
 23997  24091   
 23998  24092   /*
 23999  24093   ** Close an open database and invalidate all cursors.
 24000  24094   */
 24001         -static int sqlite3BtreeClose(Btree *p){
        24095  +SQLITE_PRIVATE int sqlite3BtreeClose(Btree *p){
 24002  24096     BtShared *pBt = p->pBt;
 24003  24097     BtCursor *pCur;
 24004  24098   
 24005  24099   #ifndef SQLITE_OMIT_SHARED_CACHE
 24006  24100     ThreadData *pTsd;
 24007  24101   #endif
 24008  24102   
................................................................................
 24062  24156     sqliteFree(pBt);
 24063  24157     return SQLITE_OK;
 24064  24158   }
 24065  24159   
 24066  24160   /*
 24067  24161   ** Change the busy handler callback function.
 24068  24162   */
 24069         -static int sqlite3BtreeSetBusyHandler(Btree *p, BusyHandler *pHandler){
        24163  +SQLITE_PRIVATE int sqlite3BtreeSetBusyHandler(Btree *p, BusyHandler *pHandler){
 24070  24164     BtShared *pBt = p->pBt;
 24071  24165     pBt->pBusyHandler = pHandler;
 24072  24166     sqlite3PagerSetBusyhandler(pBt->pPager, pHandler);
 24073  24167     return SQLITE_OK;
 24074  24168   }
 24075  24169   
 24076  24170   /*
................................................................................
 24084  24178   ** and the database cannot be corrupted if this program
 24085  24179   ** crashes.  But if the operating system crashes or there is
 24086  24180   ** an abrupt power failure when synchronous is off, the database
 24087  24181   ** could be left in an inconsistent and unrecoverable state.
 24088  24182   ** Synchronous is on by default so database corruption is not
 24089  24183   ** normally a worry.
 24090  24184   */
 24091         -static int sqlite3BtreeSetCacheSize(Btree *p, int mxPage){
        24185  +SQLITE_PRIVATE int sqlite3BtreeSetCacheSize(Btree *p, int mxPage){
 24092  24186     BtShared *pBt = p->pBt;
 24093  24187     sqlite3PagerSetCachesize(pBt->pPager, mxPage);
 24094  24188     return SQLITE_OK;
 24095  24189   }
 24096  24190   
 24097  24191   /*
 24098  24192   ** Change the way data is synced to disk in order to increase or decrease
................................................................................
 24099  24193   ** how well the database resists damage due to OS crashes and power
 24100  24194   ** failures.  Level 1 is the same as asynchronous (no syncs() occur and
 24101  24195   ** there is a high probability of damage)  Level 2 is the default.  There
 24102  24196   ** is a very low but non-zero probability of damage.  Level 3 reduces the
 24103  24197   ** probability of damage to near zero but with a write performance reduction.
 24104  24198   */
 24105  24199   #ifndef SQLITE_OMIT_PAGER_PRAGMAS
 24106         -static int sqlite3BtreeSetSafetyLevel(Btree *p, int level, int fullSync){
        24200  +SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(Btree *p, int level, int fullSync){
 24107  24201     BtShared *pBt = p->pBt;
 24108  24202     sqlite3PagerSetSafetyLevel(pBt->pPager, level, fullSync);
 24109  24203     return SQLITE_OK;
 24110  24204   }
 24111  24205   #endif
 24112  24206   
 24113  24207   /*
 24114  24208   ** Return TRUE if the given btree is set to safety level 1.  In other
 24115  24209   ** words, return TRUE if no sync() occurs on the disk files.
 24116  24210   */
 24117         -static int sqlite3BtreeSyncDisabled(Btree *p){
        24211  +SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree *p){
 24118  24212     BtShared *pBt = p->pBt;
 24119  24213     assert( pBt && pBt->pPager );
 24120  24214     return sqlite3PagerNosync(pBt->pPager);
 24121  24215   }
 24122  24216   
 24123  24217   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) || !defined(SQLITE_OMIT_VACUUM)
 24124  24218   /*
................................................................................
 24132  24226   ** of the database file used for locking (beginning at PENDING_BYTE,
 24133  24227   ** the first byte past the 1GB boundary, 0x40000000) needs to occur
 24134  24228   ** at the beginning of a page.
 24135  24229   **
 24136  24230   ** If parameter nReserve is less than zero, then the number of reserved
 24137  24231   ** bytes per page is left unchanged.
 24138  24232   */
 24139         -static int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve){
        24233  +SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve){
 24140  24234     BtShared *pBt = p->pBt;
 24141  24235     if( pBt->pageSizeFixed ){
 24142  24236       return SQLITE_READONLY;
 24143  24237     }
 24144  24238     if( nReserve<0 ){
 24145  24239       nReserve = pBt->pageSize - pBt->usableSize;
 24146  24240     }
................................................................................
 24153  24247     pBt->usableSize = pBt->pageSize - nReserve;
 24154  24248     return SQLITE_OK;
 24155  24249   }
 24156  24250   
 24157  24251   /*
 24158  24252   ** Return the currently defined page size
 24159  24253   */
 24160         -static int sqlite3BtreeGetPageSize(Btree *p){
        24254  +SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree *p){
 24161  24255     return p->pBt->pageSize;
 24162  24256   }
 24163         -static int sqlite3BtreeGetReserve(Btree *p){
        24257  +SQLITE_PRIVATE int sqlite3BtreeGetReserve(Btree *p){
 24164  24258     return p->pBt->pageSize - p->pBt->usableSize;
 24165  24259   }
 24166  24260   
 24167  24261   /*
 24168  24262   ** Set the maximum page count for a database if mxPage is positive.
 24169  24263   ** No changes are made if mxPage is 0 or negative.
 24170  24264   ** Regardless of the value of mxPage, return the maximum page count.
 24171  24265   */
 24172         -static int sqlite3BtreeMaxPageCount(Btree *p, int mxPage){
        24266  +SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree *p, int mxPage){
 24173  24267     return sqlite3PagerMaxPageCount(p->pBt->pPager, mxPage);
 24174  24268   }
 24175  24269   #endif /* !defined(SQLITE_OMIT_PAGER_PRAGMAS) || !defined(SQLITE_OMIT_VACUUM) */
 24176  24270   
 24177  24271   /*
 24178  24272   ** Change the 'auto-vacuum' property of the database. If the 'autoVacuum'
 24179  24273   ** parameter is non-zero, then auto-vacuum mode is enabled. If zero, it
 24180  24274   ** is disabled. The default value for the auto-vacuum property is 
 24181  24275   ** determined by the SQLITE_DEFAULT_AUTOVACUUM macro.
 24182  24276   */
 24183         -static int sqlite3BtreeSetAutoVacuum(Btree *p, int autoVacuum){
        24277  +SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *p, int autoVacuum){
 24184  24278   #ifdef SQLITE_OMIT_AUTOVACUUM
 24185  24279     return SQLITE_READONLY;
 24186  24280   #else
 24187  24281     BtShared *pBt = p->pBt;
 24188  24282     int av = (autoVacuum?1:0);
 24189         -  int iv = (autoVacuum==BTREE_AUTOVACUUM_INCR?1:0);
 24190  24283     if( pBt->pageSizeFixed && av!=pBt->autoVacuum ){
 24191  24284       return SQLITE_READONLY;
 24192  24285     }
 24193  24286     pBt->autoVacuum = av;
 24194         -  pBt->incrVacuum = iv;
 24195  24287     return SQLITE_OK;
 24196  24288   #endif
 24197  24289   }
 24198  24290   
 24199  24291   /*
 24200  24292   ** Return the value of the 'auto-vacuum' property. If auto-vacuum is 
 24201  24293   ** enabled 1 is returned. Otherwise 0.
 24202  24294   */
 24203         -static int sqlite3BtreeGetAutoVacuum(Btree *p){
        24295  +SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *p){
 24204  24296   #ifdef SQLITE_OMIT_AUTOVACUUM
 24205  24297     return BTREE_AUTOVACUUM_NONE;
 24206  24298   #else
 24207  24299     return (
 24208  24300       (!p->pBt->autoVacuum)?BTREE_AUTOVACUUM_NONE:
 24209  24301       (!p->pBt->incrVacuum)?BTREE_AUTOVACUUM_FULL:
 24210  24302       BTREE_AUTOVACUUM_INCR
................................................................................
 24256  24348         goto page1_init_failed;
 24257  24349       }
 24258  24350       pBt->maxEmbedFrac = page1[21];
 24259  24351       pBt->minEmbedFrac = page1[22];
 24260  24352       pBt->minLeafFrac = page1[23];
 24261  24353   #ifndef SQLITE_OMIT_AUTOVACUUM
 24262  24354       pBt->autoVacuum = (get4byte(&page1[36 + 4*4])?1:0);
        24355  +    pBt->incrVacuum = (get4byte(&page1[36 + 7*4])?1:0);
 24263  24356   #endif
 24264  24357     }
 24265  24358   
 24266  24359     /* maxLocal is the maximum amount of payload to store locally for
 24267  24360     ** a cell.  Make sure it is small enough so that at least minFanout
 24268  24361     ** cells can will fit on one page.  We assume a 10-byte page header.
 24269  24362     ** Besides the payload, the cell must store:
................................................................................
 24364  24457     data[22] = pBt->minEmbedFrac;
 24365  24458     data[23] = pBt->minLeafFrac;
 24366  24459     memset(&data[24], 0, 100-24);
 24367  24460     zeroPage(pP1, PTF_INTKEY|PTF_LEAF|PTF_LEAFDATA );
 24368  24461     pBt->pageSizeFixed = 1;
 24369  24462   #ifndef SQLITE_OMIT_AUTOVACUUM
 24370  24463     assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 );
        24464  +  assert( pBt->incrVacuum==1 || pBt->incrVacuum==0 );
 24371  24465     put4byte(&data[36 + 4*4], pBt->autoVacuum);
        24466  +  put4byte(&data[36 + 7*4], pBt->incrVacuum);
 24372  24467   #endif
 24373  24468     return SQLITE_OK;
 24374  24469   }
 24375  24470   
 24376  24471   /*
 24377  24472   ** Attempt to start a new transaction. A write-transaction
 24378  24473   ** is started if the second argument is nonzero, otherwise a read-
................................................................................
 24404  24499   ** a reserved lock.  B tries to promote to exclusive but is blocked because
 24405  24500   ** of A's read lock.  A tries to promote to reserved but is blocked by B.
 24406  24501   ** One or the other of the two processes must give way or there can be
 24407  24502   ** no progress.  By returning SQLITE_BUSY and not invoking the busy callback
 24408  24503   ** when A already has a read lock, we encourage A to give up and let B
 24409  24504   ** proceed.
 24410  24505   */
 24411         -static int sqlite3BtreeBeginTrans(Btree *p, int wrflag){
        24506  +SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree *p, int wrflag){
 24412  24507     BtShared *pBt = p->pBt;
 24413  24508     int rc = SQLITE_OK;
 24414  24509   
 24415  24510     btreeIntegrity(p);
 24416  24511   
 24417  24512     /* If the btree is already in a write-transaction, or it
 24418  24513     ** is already in a read-transaction and a read-transaction
................................................................................
 24767  24862   ** A write-transaction must be opened before calling this function.
 24768  24863   ** It performs a single unit of work towards an incremental vacuum.
 24769  24864   **
 24770  24865   ** If the incremental vacuum is finished after this function has run,
 24771  24866   ** SQLITE_DONE is returned. If it is not finished, but no error occured,
 24772  24867   ** SQLITE_OK is returned. Otherwise an SQLite error code. 
 24773  24868   */
 24774         -static int sqlite3BtreeIncrVacuum(Btree *p){
        24869  +SQLITE_PRIVATE int sqlite3BtreeIncrVacuum(Btree *p){
 24775  24870     BtShared *pBt = p->pBt;
 24776  24871     assert( pBt->inTransaction==TRANS_WRITE && p->inTrans==TRANS_WRITE );
 24777  24872     if( !pBt->autoVacuum ){
 24778  24873       return SQLITE_DONE;
 24779  24874     }
 24780  24875     invalidateAllOverflowCache(pBt);
 24781  24876     return incrVacuumStep(pBt, 0);
................................................................................
 24875  24970   **
 24876  24971   ** When this is called, the master journal should already have been
 24877  24972   ** created, populated with this journal pointer and synced to disk.
 24878  24973   **
 24879  24974   ** Once this is routine has returned, the only thing required to commit
 24880  24975   ** the write-transaction for this database file is to delete the journal.
 24881  24976   */
 24882         -static int sqlite3BtreeCommitPhaseOne(Btree *p, const char *zMaster){
        24977  +SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree *p, const char *zMaster){
 24883  24978     int rc = SQLITE_OK;
 24884  24979     if( p->inTrans==TRANS_WRITE ){
 24885  24980       BtShared *pBt = p->pBt;
 24886  24981       Pgno nTrunc = 0;
 24887  24982   #ifndef SQLITE_OMIT_AUTOVACUUM
 24888  24983       if( pBt->autoVacuum ){
 24889  24984         rc = autoVacuumCommit(pBt, &nTrunc); 
................................................................................
 24907  25002   ** contents so that they are written onto the disk platter.  All this
 24908  25003   ** routine has to do is delete or truncate the rollback journal
 24909  25004   ** (which causes the transaction to commit) and drop locks.
 24910  25005   **
 24911  25006   ** This will release the write lock on the database file.  If there
 24912  25007   ** are no active cursors, it also releases the read lock.
 24913  25008   */
 24914         -static int sqlite3BtreeCommitPhaseTwo(Btree *p){
        25009  +SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree *p){
 24915  25010     BtShared *pBt = p->pBt;
 24916  25011   
 24917  25012     btreeIntegrity(p);
 24918  25013   
 24919  25014     /* If the handle has a write-transaction open, commit the shared-btrees 
 24920  25015     ** transaction and set the shared state to TRANS_READ.
 24921  25016     */
................................................................................
 24953  25048     btreeIntegrity(p);
 24954  25049     return SQLITE_OK;
 24955  25050   }
 24956  25051   
 24957  25052   /*
 24958  25053   ** Do both phases of a commit.
 24959  25054   */
 24960         -static int sqlite3BtreeCommit(Btree *p){
        25055  +SQLITE_PRIVATE int sqlite3BtreeCommit(Btree *p){
 24961  25056     int rc;
 24962  25057     rc = sqlite3BtreeCommitPhaseOne(p, 0);
 24963  25058     if( rc==SQLITE_OK ){
 24964  25059       rc = sqlite3BtreeCommitPhaseTwo(p);
 24965  25060     }
 24966  25061     return rc;
 24967  25062   }
................................................................................
 24987  25082   ** invalided by this operation.  Any attempt to use a cursor
 24988  25083   ** that was open at the beginning of this operation will result
 24989  25084   ** in an error.
 24990  25085   **
 24991  25086   ** This will release the write lock on the database file.  If there
 24992  25087   ** are no active cursors, it also releases the read lock.
 24993  25088   */
 24994         -static int sqlite3BtreeRollback(Btree *p){
        25089  +SQLITE_PRIVATE int sqlite3BtreeRollback(Btree *p){
 24995  25090     int rc;
 24996  25091     BtShared *pBt = p->pBt;
 24997  25092     MemPage *pPage1;
 24998  25093   
 24999  25094     rc = saveAllCursors(pBt, 0, 0);
 25000  25095   #ifndef SQLITE_OMIT_SHARED_CACHE
 25001  25096     if( rc!=SQLITE_OK ){
................................................................................
 25067  25162   ** to start a new subtransaction if another subtransaction is already active.
 25068  25163   **
 25069  25164   ** Statement subtransactions are used around individual SQL statements
 25070  25165   ** that are contained within a BEGIN...COMMIT block.  If a constraint
 25071  25166   ** error occurs within the statement, the effect of that one statement
 25072  25167   ** can be rolled back without having to rollback the entire transaction.
 25073  25168   */
 25074         -static int sqlite3BtreeBeginStmt(Btree *p){
        25169  +SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree *p){
 25075  25170     int rc;
 25076  25171     BtShared *pBt = p->pBt;
 25077  25172     if( (p->inTrans!=TRANS_WRITE) || pBt->inStmt ){
 25078  25173       return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
 25079  25174     }
 25080  25175     assert( pBt->inTransaction==TRANS_WRITE );
 25081  25176     rc = pBt->readOnly ? SQLITE_OK : sqlite3PagerStmtBegin(pBt->pPager);
................................................................................
 25084  25179   }
 25085  25180   
 25086  25181   
 25087  25182   /*
 25088  25183   ** Commit the statment subtransaction currently in progress.  If no
 25089  25184   ** subtransaction is active, this is a no-op.
 25090  25185   */
 25091         -static int sqlite3BtreeCommitStmt(Btree *p){
        25186  +SQLITE_PRIVATE int sqlite3BtreeCommitStmt(Btree *p){
 25092  25187     int rc;
 25093  25188     BtShared *pBt = p->pBt;
 25094  25189     if( pBt->inStmt && !pBt->readOnly ){
 25095  25190       rc = sqlite3PagerStmtCommit(pBt->pPager);
 25096  25191     }else{
 25097  25192       rc = SQLITE_OK;
 25098  25193     }
................................................................................
 25104  25199   ** Rollback the active statement subtransaction.  If no subtransaction
 25105  25200   ** is active this routine is a no-op.
 25106  25201   **
 25107  25202   ** All cursors will be invalidated by this operation.  Any attempt
 25108  25203   ** to use a cursor that was open at the beginning of this operation
 25109  25204   ** will result in an error.
 25110  25205   */
 25111         -static int sqlite3BtreeRollbackStmt(Btree *p){
        25206  +SQLITE_PRIVATE int sqlite3BtreeRollbackStmt(Btree *p){
 25112  25207     int rc = SQLITE_OK;
 25113  25208     BtShared *pBt = p->pBt;
 25114  25209     sqlite3MallocDisallow();
 25115  25210     if( pBt->inStmt && !pBt->readOnly ){
 25116  25211       rc = sqlite3PagerStmtRollback(pBt->pPager);
 25117  25212       assert( countWriteCursors(pBt)==0 );
 25118  25213       pBt->inStmt = 0;
................................................................................
 25167  25262   **
 25168  25263   ** The comparison function must be logically the same for every cursor
 25169  25264   ** on a particular table.  Changing the comparison function will result
 25170  25265   ** in incorrect operations.  If the comparison function is NULL, a
 25171  25266   ** default comparison function is used.  The comparison function is
 25172  25267   ** always ignored for INTKEY tables.
 25173  25268   */
 25174         -static int sqlite3BtreeCursor(
        25269  +SQLITE_PRIVATE int sqlite3BtreeCursor(
 25175  25270     Btree *p,                                   /* The btree */
 25176  25271     int iTable,                                 /* Root page of table to open */
 25177  25272     int wrFlag,                                 /* 1 to write. 0 read-only */
 25178  25273     int (*xCmp)(void*,int,const void*,int,const void*), /* Key Comparison func */
 25179  25274     void *pArg,                                 /* First arg to xCompare() */
 25180  25275     BtCursor **ppCur                            /* Write new cursor here */
 25181  25276   ){
................................................................................
 25243  25338     return rc;
 25244  25339   }
 25245  25340   
 25246  25341   /*
 25247  25342   ** Close a cursor.  The read lock on the database file is released
 25248  25343   ** when the last cursor is closed.
 25249  25344   */
 25250         -static int sqlite3BtreeCloseCursor(BtCursor *pCur){
        25345  +SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor *pCur){
 25251  25346     BtShared *pBt = pCur->pBtree->pBt;
 25252  25347     clearCursorPosition(pCur);
 25253  25348     if( pCur->pPrev ){
 25254  25349       pCur->pPrev->pNext = pCur->pNext;
 25255  25350     }else{
 25256  25351       pBt->pCursor = pCur->pNext;
 25257  25352     }
................................................................................
 25265  25360     return SQLITE_OK;
 25266  25361   }
 25267  25362   
 25268  25363   /*
 25269  25364   ** Make a temporary cursor by filling in the fields of pTempCur.
 25270  25365   ** The temporary cursor is not on the cursor list for the Btree.
 25271  25366   */
 25272         -static void sqlite3BtreeGetTempCursor(BtCursor *pCur, BtCursor *pTempCur){
        25367  +SQLITE_PRIVATE void sqlite3BtreeGetTempCursor(BtCursor *pCur, BtCursor *pTempCur){
 25273  25368     memcpy(pTempCur, pCur, sizeof(*pCur));
 25274  25369     pTempCur->pNext = 0;
 25275  25370     pTempCur->pPrev = 0;
 25276  25371     if( pTempCur->pPage ){
 25277  25372       sqlite3PagerRef(pTempCur->pPage->pDbPage);
 25278  25373     }
 25279  25374   }
 25280  25375   
 25281  25376   /*
 25282  25377   ** Delete a temporary cursor such as was made by the CreateTemporaryCursor()
 25283  25378   ** function above.
 25284  25379   */
 25285         -static void sqlite3BtreeReleaseTempCursor(BtCursor *pCur){
        25380  +SQLITE_PRIVATE void sqlite3BtreeReleaseTempCursor(BtCursor *pCur){
 25286  25381     if( pCur->pPage ){
 25287  25382       sqlite3PagerUnref(pCur->pPage->pDbPage);
 25288  25383     }
 25289  25384   }
 25290  25385   
 25291  25386   /*
 25292         -** The GET_CELL_INFO() macro. Takes one argument, a pointer to a valid
 25293         -** btree cursor (type BtCursor*).  This macro makes sure the BtCursor.info
 25294         -** field of the given cursor is valid.  If it is not already valid, call
        25387  +** Make sure the BtCursor* given in the argument has a valid
        25388  +** BtCursor.info structure.  If it is not already valid, call
 25295  25389   ** sqlite3BtreeParseCell() to fill it in.
 25296  25390   **
 25297  25391   ** BtCursor.info is a cache of the information in the current cell.
 25298  25392   ** Using this cache reduces the number of calls to sqlite3BtreeParseCell().
        25393  +**
        25394  +** 2007-06-25:  There is a bug in some versions of MSVC that cause the
        25395  +** compiler to crash when getCellInfo() is implemented as a macro.
        25396  +** But there is a measureable speed advantage to using the macro on gcc
        25397  +** (when less compiler optimizations like -Os or -O0 are used and the
        25398  +** compiler is not doing agressive inlining.)  So we use a real function
        25399  +** for MSVC and a macro for everything else.  Ticket #2457.
 25299  25400   */
 25300  25401   #ifndef NDEBUG
 25301  25402     static void assertCellInfo(BtCursor *pCur){
 25302  25403       CellInfo info;
 25303  25404       memset(&info, 0, sizeof(info));
 25304  25405       sqlite3BtreeParseCell(pCur->pPage, pCur->idx, &info);
 25305  25406       assert( memcmp(&info, &pCur->info, sizeof(info))==0 );
 25306  25407     }
 25307  25408   #else
 25308  25409     #define assertCellInfo(x)
 25309  25410   #endif
 25310         -
 25311         -#define GET_CELL_INFO(pCur)                                             \
 25312         -  if( pCur->info.nSize==0 )                                             \
        25411  +#ifdef _MSC_VER
        25412  +  /* Use a real function in MSVC to work around bugs in that compiler. */
        25413  +  static void getCellInfo(BtCursor *pCur){
        25414  +    if( pCur->info.nSize==0 ){
        25415  +      sqlite3BtreeParseCell(pCur->pPage, pCur->idx, &pCur->info);
        25416  +    }else{
        25417  +      assertCellInfo(pCur);
        25418  +    }
        25419  +  }
        25420  +#else /* if not _MSC_VER */
        25421  +  /* Use a macro in all other compilers so that the function is inlined */
        25422  +#define getCellInfo(pCur)                                               \
        25423  +  if( pCur->info.nSize==0 ){                                            \
 25313  25424       sqlite3BtreeParseCell(pCur->pPage, pCur->idx, &pCur->info);         \
 25314         -  else                                                                  \
 25315         -    assertCellInfo(pCur);
 25316         -   
        25425  +  }else{                                                                \
        25426  +    assertCellInfo(pCur);                                               \
        25427  +  }
        25428  +#endif /* _MSC_VER */
 25317  25429   
 25318  25430   /*
 25319  25431   ** Set *pSize to the size of the buffer needed to hold the value of
 25320  25432   ** the key for the current entry.  If the cursor is not pointing
 25321  25433   ** to a valid entry, *pSize is set to 0. 
 25322  25434   **
 25323  25435   ** For a table with the INTKEY flag set, this routine returns the key
 25324  25436   ** itself, not the number of bytes in the key.
 25325  25437   */
 25326         -static int sqlite3BtreeKeySize(BtCursor *pCur, i64 *pSize){
        25438  +SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor *pCur, i64 *pSize){
 25327  25439     int rc = restoreOrClearCursorPosition(pCur);
 25328  25440     if( rc==SQLITE_OK ){
 25329  25441       assert( pCur->eState==CURSOR_INVALID || pCur->eState==CURSOR_VALID );
 25330  25442       if( pCur->eState==CURSOR_INVALID ){
 25331  25443         *pSize = 0;
 25332  25444       }else{
 25333         -      GET_CELL_INFO(pCur);
        25445  +      getCellInfo(pCur);
 25334  25446         *pSize = pCur->info.nKey;
 25335  25447       }
 25336  25448     }
 25337  25449     return rc;
 25338  25450   }
 25339  25451   
 25340  25452   /*
 25341  25453   ** Set *pSize to the number of bytes of data in the entry the
 25342  25454   ** cursor currently points to.  Always return SQLITE_OK.
 25343  25455   ** Failure is not possible.  If the cursor is not currently
 25344  25456   ** pointing to an entry (which can happen, for example, if
 25345  25457   ** the database is empty) then *pSize is set to 0.
 25346  25458   */
 25347         -static int sqlite3BtreeDataSize(BtCursor *pCur, u32 *pSize){
        25459  +SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor *pCur, u32 *pSize){
 25348  25460     int rc = restoreOrClearCursorPosition(pCur);
 25349  25461     if( rc==SQLITE_OK ){
 25350  25462       assert( pCur->eState==CURSOR_INVALID || pCur->eState==CURSOR_VALID );
 25351  25463       if( pCur->eState==CURSOR_INVALID ){
 25352  25464         /* Not pointing at a valid entry - set *pSize to 0. */
 25353  25465         *pSize = 0;
 25354  25466       }else{
 25355         -      GET_CELL_INFO(pCur);
        25467  +      getCellInfo(pCur);
 25356  25468         *pSize = pCur->info.nData;
 25357  25469       }
 25358  25470     }
 25359  25471     return rc;
 25360  25472   }
 25361  25473   
 25362  25474   /*
................................................................................
 25521  25633     BtShared *pBt = pCur->pBtree->pBt;   /* Btree this cursor belongs to */
 25522  25634   
 25523  25635     assert( pPage );
 25524  25636     assert( pCur->eState==CURSOR_VALID );
 25525  25637     assert( pCur->idx>=0 && pCur->idx<pPage->nCell );
 25526  25638     assert( offset>=0 );
 25527  25639   
 25528         -  GET_CELL_INFO(pCur);
        25640  +  getCellInfo(pCur);
 25529  25641     aPayload = pCur->info.pCell + pCur->info.nHeader;
 25530  25642     nKey = (pPage->intKey ? 0 : pCur->info.nKey);
 25531  25643   
 25532  25644     if( skipKey ){
 25533  25645       offset += nKey;
 25534  25646     }
 25535  25647     if( offset+amt > nKey+pCur->info.nData ){
................................................................................
 25642  25754   ** "amt" bytes will be transfered into pBuf[].  The transfer
 25643  25755   ** begins at "offset".
 25644  25756   **
 25645  25757   ** Return SQLITE_OK on success or an error code if anything goes
 25646  25758   ** wrong.  An error is returned if "offset+amt" is larger than
 25647  25759   ** the available payload.
 25648  25760   */
 25649         -static int sqlite3BtreeKey(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
        25761  +SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
 25650  25762     int rc = restoreOrClearCursorPosition(pCur);
 25651  25763     if( rc==SQLITE_OK ){
 25652  25764       assert( pCur->eState==CURSOR_VALID );
 25653  25765       assert( pCur->pPage!=0 );
 25654  25766       if( pCur->pPage->intKey ){
 25655  25767         return SQLITE_CORRUPT_BKPT;
 25656  25768       }
................................................................................
 25666  25778   ** "amt" bytes will be transfered into pBuf[].  The transfer
 25667  25779   ** begins at "offset".
 25668  25780   **
 25669  25781   ** Return SQLITE_OK on success or an error code if anything goes
 25670  25782   ** wrong.  An error is returned if "offset+amt" is larger than
 25671  25783   ** the available payload.
 25672  25784   */
 25673         -static int sqlite3BtreeData(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
        25785  +SQLITE_PRIVATE int sqlite3BtreeData(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
 25674  25786     int rc = restoreOrClearCursorPosition(pCur);
 25675  25787     if( rc==SQLITE_OK ){
 25676  25788       assert( pCur->eState==CURSOR_VALID );
 25677  25789       assert( pCur->pPage!=0 );
 25678  25790       assert( pCur->idx>=0 && pCur->idx<pCur->pPage->nCell );
 25679  25791       rc = accessPayload(pCur, offset, amt, pBuf, 1, 0);
 25680  25792     }
................................................................................
 25710  25822     u32 nKey;
 25711  25823     int nLocal;
 25712  25824   
 25713  25825     assert( pCur!=0 && pCur->pPage!=0 );
 25714  25826     assert( pCur->eState==CURSOR_VALID );
 25715  25827     pPage = pCur->pPage;
 25716  25828     assert( pCur->idx>=0 && pCur->idx<pPage->nCell );
 25717         -  GET_CELL_INFO(pCur);
        25829  +  getCellInfo(pCur);
 25718  25830     aPayload = pCur->info.pCell;
 25719  25831     aPayload += pCur->info.nHeader;
 25720  25832     if( pPage->intKey ){
 25721  25833       nKey = 0;
 25722  25834     }else{
 25723  25835       nKey = pCur->info.nKey;
 25724  25836     }
................................................................................
 25743  25855   **
 25744  25856   ** The pointer returned is ephemeral.  The key/data may move
 25745  25857   ** or be destroyed on the next call to any Btree routine.
 25746  25858   **
 25747  25859   ** These routines is used to get quick access to key and data
 25748  25860   ** in the common case where no overflow pages are used.
 25749  25861   */
 25750         -static const void *sqlite3BtreeKeyFetch(BtCursor *pCur, int *pAmt){
        25862  +SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, int *pAmt){
 25751  25863     if( pCur->eState==CURSOR_VALID ){
 25752  25864       return (const void*)fetchPayload(pCur, pAmt, 0);
 25753  25865     }
 25754  25866     return 0;
 25755  25867   }
 25756         -static const void *sqlite3BtreeDataFetch(BtCursor *pCur, int *pAmt){
        25868  +SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, int *pAmt){
 25757  25869     if( pCur->eState==CURSOR_VALID ){
 25758  25870       return (const void*)fetchPayload(pCur, pAmt, 1);
 25759  25871     }
 25760  25872     return 0;
 25761  25873   }
 25762  25874   
 25763  25875   
................................................................................
 25792  25904   **
 25793  25905   ** The virtual root page is the root page for most tables.  But
 25794  25906   ** for the table rooted on page 1, sometime the real root page
 25795  25907   ** is empty except for the right-pointer.  In such cases the
 25796  25908   ** virtual root page is the page that the right-pointer of page
 25797  25909   ** 1 is pointing to.
 25798  25910   */
 25799         -static int sqlite3BtreeIsRootPage(MemPage *pPage){
        25911  +SQLITE_PRIVATE int sqlite3BtreeIsRootPage(MemPage *pPage){
 25800  25912     MemPage *pParent = pPage->pParent;
 25801  25913     if( pParent==0 ) return 1;
 25802  25914     if( pParent->pgno>1 ) return 0;
 25803  25915     if( get2byte(&pParent->aData[pParent->hdrOffset+3])==0 ) return 1;
 25804  25916     return 0;
 25805  25917   }
 25806  25918   
................................................................................
 25808  25920   ** Move the cursor up to the parent page.
 25809  25921   **
 25810  25922   ** pCur->idx is set to the cell index that contains the pointer
 25811  25923   ** to the page we are coming from.  If we are coming from the
 25812  25924   ** right-most child page then pCur->idx is set to one more than
 25813  25925   ** the largest cell index.
 25814  25926   */
 25815         -static void sqlite3BtreeMoveToParent(BtCursor *pCur){
        25927  +SQLITE_PRIVATE void sqlite3BtreeMoveToParent(BtCursor *pCur){
 25816  25928     MemPage *pParent;
 25817  25929     MemPage *pPage;
 25818  25930     int idxParent;
 25819  25931   
 25820  25932     assert( pCur->eState==CURSOR_VALID );
 25821  25933     pPage = pCur->pPage;
 25822  25934     assert( pPage!=0 );
................................................................................
 25919  26031     return SQLITE_OK;
 25920  26032   }
 25921  26033   
 25922  26034   /* Move the cursor to the first entry in the table.  Return SQLITE_OK
 25923  26035   ** on success.  Set *pRes to 0 if the cursor actually points to something
 25924  26036   ** or set *pRes to 1 if the table is empty.
 25925  26037   */
 25926         -static int sqlite3BtreeFirst(BtCursor *pCur, int *pRes){
        26038  +SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor *pCur, int *pRes){
 25927  26039     int rc;
 25928  26040     rc = moveToRoot(pCur);
 25929  26041     if( rc ) return rc;
 25930  26042     if( pCur->eState==CURSOR_INVALID ){
 25931  26043       assert( pCur->pPage->nCell==0 );
 25932  26044       *pRes = 1;
 25933  26045       return SQLITE_OK;
................................................................................
 25938  26050     return rc;
 25939  26051   }
 25940  26052   
 25941  26053   /* Move the cursor to the last entry in the table.  Return SQLITE_OK
 25942  26054   ** on success.  Set *pRes to 0 if the cursor actually points to something
 25943  26055   ** or set *pRes to 1 if the table is empty.
 25944  26056   */
 25945         -static int sqlite3BtreeLast(BtCursor *pCur, int *pRes){
        26057  +SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor *pCur, int *pRes){
 25946  26058     int rc;
 25947  26059     rc = moveToRoot(pCur);
 25948  26060     if( rc ) return rc;
 25949  26061     if( CURSOR_INVALID==pCur->eState ){
 25950  26062       assert( pCur->pPage->nCell==0 );
 25951  26063       *pRes = 1;
 25952  26064       return SQLITE_OK;
................................................................................
 25980  26092   **
 25981  26093   **     *pRes==0     The cursor is left pointing at an entry that
 25982  26094   **                  exactly matches pKey.
 25983  26095   **
 25984  26096   **     *pRes>0      The cursor is left pointing at an entry that
 25985  26097   **                  is larger than pKey.
 25986  26098   */
 25987         -static int sqlite3BtreeMoveto(
        26099  +SQLITE_PRIVATE int sqlite3BtreeMoveto(
 25988  26100     BtCursor *pCur,        /* The cursor to be moved */
 25989  26101     const void *pKey,      /* The key content for indices.  Not used by tables */
 25990  26102     i64 nKey,              /* Size of pKey.  Or the key for tables */
 25991  26103     int biasRight,         /* If true, bias the search to the high end */
 25992  26104     int *pRes              /* Search result flag */
 25993  26105   ){
 25994  26106     int rc;
................................................................................
 26097  26209   /*
 26098  26210   ** Return TRUE if the cursor is not pointing at an entry of the table.
 26099  26211   **
 26100  26212   ** TRUE will be returned after a call to sqlite3BtreeNext() moves
 26101  26213   ** past the last entry in the table or sqlite3BtreePrev() moves past
 26102  26214   ** the first entry.  TRUE is also returned if the table is empty.
 26103  26215   */
 26104         -static int sqlite3BtreeEof(BtCursor *pCur){
        26216  +SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor *pCur){
 26105  26217     /* TODO: What if the cursor is in CURSOR_REQUIRESEEK but all table entries
 26106  26218     ** have been deleted? This API will need to change to return an error code
 26107  26219     ** as well as the boolean result value.
 26108  26220     */
 26109  26221     return (CURSOR_VALID!=pCur->eState);
 26110  26222   }
 26111  26223   
 26112  26224   /*
 26113  26225   ** Advance the cursor to the next entry in the database.  If
 26114  26226   ** successful then set *pRes=0.  If the cursor
 26115  26227   ** was already pointing to the last entry in the database before
 26116  26228   ** this routine was called, then set *pRes=1.
 26117  26229   */
 26118         -static int sqlite3BtreeNext(BtCursor *pCur, int *pRes){
        26230  +SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int *pRes){
 26119  26231     int rc;
 26120  26232     MemPage *pPage;
 26121  26233   
 26122  26234     rc = restoreOrClearCursorPosition(pCur);
 26123  26235     if( rc!=SQLITE_OK ){
 26124  26236       return rc;
 26125  26237     }
................................................................................
 26176  26288   
 26177  26289   /*
 26178  26290   ** Step the cursor to the back to the previous entry in the database.  If
 26179  26291   ** successful then set *pRes=0.  If the cursor
 26180  26292   ** was already pointing to the first entry in the database before
 26181  26293   ** this routine was called, then set *pRes=1.
 26182  26294   */
 26183         -static int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){
        26295  +SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){
 26184  26296     int rc;
 26185  26297     Pgno pgno;
 26186  26298     MemPage *pPage;
 26187  26299   
 26188  26300     rc = restoreOrClearCursorPosition(pCur);
 26189  26301     if( rc!=SQLITE_OK ){
 26190  26302       return rc;
................................................................................
 27907  28019   ** and the data is given by (pData,nData).  The cursor is used only to
 27908  28020   ** define what table the record should be inserted into.  The cursor
 27909  28021   ** is left pointing at a random location.
 27910  28022   **
 27911  28023   ** For an INTKEY table, only the nKey value of the key is used.  pKey is
 27912  28024   ** ignored.  For a ZERODATA table, the pData and nData are both ignored.
 27913  28025   */
 27914         -static int sqlite3BtreeInsert(
        28026  +SQLITE_PRIVATE int sqlite3BtreeInsert(
 27915  28027     BtCursor *pCur,                /* Insert data into the table of this cursor */
 27916  28028     const void *pKey, i64 nKey,    /* The key of the new record */
 27917  28029     const void *pData, int nData,  /* The data of the new record */
 27918  28030     int nZero,                     /* Number of extra 0 bytes to append to data */
 27919  28031     int appendBias                 /* True if this is likely an append */
 27920  28032   ){
 27921  28033     int rc;
................................................................................
 27993  28105     return rc;
 27994  28106   }
 27995  28107   
 27996  28108   /*
 27997  28109   ** Delete the entry that the cursor is pointing to.  The cursor
 27998  28110   ** is left pointing at a random location.
 27999  28111   */
 28000         -static int sqlite3BtreeDelete(BtCursor *pCur){
        28112  +SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur){
 28001  28113     MemPage *pPage = pCur->pPage;
 28002  28114     unsigned char *pCell;
 28003  28115     int rc;
 28004  28116     Pgno pgnoChild = 0;
 28005  28117     BtShared *pBt = pCur->pBtree->pBt;
 28006  28118   
 28007  28119     assert( pPage->isInit );
................................................................................
 28109  28221   ** The type of type is determined by the flags parameter.  Only the
 28110  28222   ** following values of flags are currently in use.  Other values for
 28111  28223   ** flags might not work:
 28112  28224   **
 28113  28225   **     BTREE_INTKEY|BTREE_LEAFDATA     Used for SQL tables with rowid keys
 28114  28226   **     BTREE_ZERODATA                  Used for SQL indices
 28115  28227   */
 28116         -static int sqlite3BtreeCreateTable(Btree *p, int *piTable, int flags){
        28228  +SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree *p, int *piTable, int flags){
 28117  28229     BtShared *pBt = p->pBt;
 28118  28230     MemPage *pRoot;
 28119  28231     Pgno pgnoRoot;
 28120  28232     int rc;
 28121  28233     if( pBt->inTransaction!=TRANS_WRITE ){
 28122  28234       /* Must start a transaction first */
 28123  28235       return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
................................................................................
 28288  28400   ** the page number of the root of the table.  After this routine returns,
 28289  28401   ** the root page is empty, but still exists.
 28290  28402   **
 28291  28403   ** This routine will fail with SQLITE_LOCKED if there are any open
 28292  28404   ** read cursors on the table.  Open write cursors are moved to the
 28293  28405   ** root of the table.
 28294  28406   */
 28295         -static int sqlite3BtreeClearTable(Btree *p, int iTable){
        28407  +SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree *p, int iTable){
 28296  28408     int rc;
 28297  28409     BtShared *pBt = p->pBt;
 28298  28410     if( p->inTrans!=TRANS_WRITE ){
 28299  28411       return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
 28300  28412     }
 28301  28413     rc = checkReadLocks(p, iTable, 0);
 28302  28414     if( rc ){
................................................................................
 28327  28439   ** root pages are kept at the beginning of the database file, which
 28328  28440   ** is necessary for AUTOVACUUM to work right.  *piMoved is set to the 
 28329  28441   ** page number that used to be the last root page in the file before
 28330  28442   ** the move.  If no page gets moved, *piMoved is set to 0.
 28331  28443   ** The last root page is recorded in meta[3] and the value of
 28332  28444   ** meta[3] is updated by this procedure.
 28333  28445   */
 28334         -static int sqlite3BtreeDropTable(Btree *p, int iTable, int *piMoved){
        28446  +SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree *p, int iTable, int *piMoved){
 28335  28447     int rc;
 28336  28448     MemPage *pPage = 0;
 28337  28449     BtShared *pBt = p->pBt;
 28338  28450   
 28339  28451     if( p->inTrans!=TRANS_WRITE ){
 28340  28452       return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
 28341  28453     }
................................................................................
 28445  28557   ** through meta[15] are available for use by higher layers.  Meta[0]
 28446  28558   ** is read-only, the others are read/write.
 28447  28559   ** 
 28448  28560   ** The schema layer numbers meta values differently.  At the schema
 28449  28561   ** layer (and the SetCookie and ReadCookie opcodes) the number of
 28450  28562   ** free pages is not visible.  So Cookie[0] is the same as Meta[1].
 28451  28563   */
 28452         -static int sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){
        28564  +SQLITE_PRIVATE int sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){
 28453  28565     DbPage *pDbPage;
 28454  28566     int rc;
 28455  28567     unsigned char *pP1;
 28456  28568     BtShared *pBt = p->pBt;
 28457  28569   
 28458  28570     /* Reading a meta-data value requires a read-lock on page 1 (and hence
 28459  28571     ** the sqlite_master table. We grab this lock regardless of whether or
................................................................................
 28484  28596     return rc;
 28485  28597   }
 28486  28598   
 28487  28599   /*
 28488  28600   ** Write meta-information back into the database.  Meta[0] is
 28489  28601   ** read-only and may not be written.
 28490  28602   */
 28491         -static int sqlite3BtreeUpdateMeta(Btree *p, int idx, u32 iMeta){
        28603  +SQLITE_PRIVATE int sqlite3BtreeUpdateMeta(Btree *p, int idx, u32 iMeta){
 28492  28604     BtShared *pBt = p->pBt;
 28493  28605     unsigned char *pP1;
 28494  28606     int rc;
 28495  28607     assert( idx>=1 && idx<=15 );
 28496  28608     if( p->inTrans!=TRANS_WRITE ){
 28497  28609       return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
 28498  28610     }
 28499  28611     assert( pBt->pPage1!=0 );
 28500  28612     pP1 = pBt->pPage1->aData;
 28501  28613     rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
 28502  28614     if( rc ) return rc;
 28503  28615     put4byte(&pP1[36 + idx*4], iMeta);
        28616  +  if( idx==7 ){
        28617  +    assert( pBt->autoVacuum || iMeta==0 );
        28618  +    assert( iMeta==0 || iMeta==1 );
        28619  +    pBt->incrVacuum = iMeta;
        28620  +  }
 28504  28621     return SQLITE_OK;
 28505  28622   }
 28506  28623   
 28507  28624   /*
 28508  28625   ** Return the flag byte at the beginning of the page that the cursor
 28509  28626   ** is currently pointing to.
 28510  28627   */
 28511         -static int sqlite3BtreeFlags(BtCursor *pCur){
        28628  +SQLITE_PRIVATE int sqlite3BtreeFlags(BtCursor *pCur){
 28512  28629     /* TODO: What about CURSOR_REQUIRESEEK state? Probably need to call
 28513  28630     ** restoreOrClearCursorPosition() here.
 28514  28631     */
 28515  28632     MemPage *pPage = pCur->pPage;
 28516  28633     return pPage ? pPage->aData[pPage->hdrOffset] : 0;
 28517  28634   }
 28518  28635   
 28519  28636   
 28520  28637   /*
 28521  28638   ** Return the pager associated with a BTree.  This routine is used for
 28522  28639   ** testing and debugging only.
 28523  28640   */
 28524         -static Pager *sqlite3BtreePager(Btree *p){
        28641  +SQLITE_PRIVATE Pager *sqlite3BtreePager(Btree *p){
 28525  28642     return p->pBt->pPager;
 28526  28643   }
 28527  28644   
 28528  28645   #ifndef SQLITE_OMIT_INTEGRITY_CHECK
 28529  28646   /*
 28530  28647   ** Append a message to the error message string.
 28531  28648   */
................................................................................
 28852  28969   ** a table.  nRoot is the number of entries in aRoot.
 28853  28970   **
 28854  28971   ** If everything checks out, this routine returns NULL.  If something is
 28855  28972   ** amiss, an error message is written into memory obtained from malloc()
 28856  28973   ** and a pointer to that error message is returned.  The calling function
 28857  28974   ** is responsible for freeing the error message when it is done.
 28858  28975   */
 28859         -static char *sqlite3BtreeIntegrityCheck(
        28976  +SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(
 28860  28977     Btree *p,     /* The btree to be checked */
 28861  28978     int *aRoot,   /* An array of root pages numbers for individual trees */
 28862  28979     int nRoot,    /* Number of entries in aRoot[] */
 28863  28980     int mxErr,    /* Stop reporting errors after this many */
 28864  28981     int *pnErr    /* Write number of errors seen to this variable */
 28865  28982   ){
 28866  28983     int i;
................................................................................
 28957  29074     return sCheck.zErrMsg;
 28958  29075   }
 28959  29076   #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
 28960  29077   
 28961  29078   /*
 28962  29079   ** Return the full pathname of the underlying database file.
 28963  29080   */
 28964         -static const char *sqlite3BtreeGetFilename(Btree *p){
        29081  +SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *p){
 28965  29082     assert( p->pBt->pPager!=0 );
 28966  29083     return sqlite3PagerFilename(p->pBt->pPager);
 28967  29084   }
 28968  29085   
 28969  29086   /*
 28970  29087   ** Return the pathname of the directory that contains the database file.
 28971  29088   */
 28972         -static const char *sqlite3BtreeGetDirname(Btree *p){
        29089  +SQLITE_PRIVATE const char *sqlite3BtreeGetDirname(Btree *p){
 28973  29090     assert( p->pBt->pPager!=0 );
 28974  29091     return sqlite3PagerDirname(p->pBt->pPager);
 28975  29092   }
 28976  29093   
 28977  29094   /*
 28978  29095   ** Return the pathname of the journal file for this database. The return
 28979  29096   ** value of this routine is the same regardless of whether the journal file
 28980  29097   ** has been created or not.
 28981  29098   */
 28982         -static const char *sqlite3BtreeGetJournalname(Btree *p){
        29099  +SQLITE_PRIVATE const char *sqlite3BtreeGetJournalname(Btree *p){
 28983  29100     assert( p->pBt->pPager!=0 );
 28984  29101     return sqlite3PagerJournalname(p->pBt->pPager);
 28985  29102   }
 28986  29103   
 28987  29104   #ifndef SQLITE_OMIT_VACUUM
 28988  29105   /*
 28989  29106   ** Copy the complete content of pBtFrom into pBtTo.  A transaction
 28990  29107   ** must be active for both files.
 28991  29108   **
 28992  29109   ** The size of file pBtFrom may be reduced by this operation.
 28993  29110   ** If anything goes wrong, the transaction on pBtFrom is rolled back.
 28994  29111   */
 28995         -static int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
        29112  +SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
 28996  29113     int rc = SQLITE_OK;
 28997  29114     Pgno i, nPage, nToPage, iSkip;
 28998  29115   
 28999  29116     BtShared *pBtTo = pTo->pBt;
 29000  29117     BtShared *pBtFrom = pFrom->pBt;
 29001  29118   
 29002  29119     if( pTo->inTrans!=TRANS_WRITE || pFrom->inTrans!=TRANS_WRITE ){
................................................................................
 29045  29162     return rc;  
 29046  29163   }
 29047  29164   #endif /* SQLITE_OMIT_VACUUM */
 29048  29165   
 29049  29166   /*
 29050  29167   ** Return non-zero if a transaction is active.
 29051  29168   */
 29052         -static int sqlite3BtreeIsInTrans(Btree *p){
        29169  +SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree *p){
 29053  29170     return (p && (p->inTrans==TRANS_WRITE));
 29054  29171   }
 29055  29172   
 29056  29173   /*
 29057  29174   ** Return non-zero if a statement transaction is active.
 29058  29175   */
 29059         -static int sqlite3BtreeIsInStmt(Btree *p){
        29176  +SQLITE_PRIVATE int sqlite3BtreeIsInStmt(Btree *p){
 29060  29177     return (p->pBt && p->pBt->inStmt);
 29061  29178   }
 29062  29179   
 29063  29180   /*
 29064  29181   ** Return non-zero if a read (or write) transaction is active.
 29065  29182   */
 29066         -static int sqlite3BtreeIsInReadTrans(Btree *p){
        29183  +SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree *p){
 29067  29184     return (p && (p->inTrans!=TRANS_NONE));
 29068  29185   }
 29069  29186   
 29070  29187   /*
 29071  29188   ** This function returns a pointer to a blob of memory associated with
 29072  29189   ** a single shared-btree. The memory is used by client code for it's own
 29073  29190   ** purposes (for example, to store a high-level schema associated with 
................................................................................
 29079  29196   ** of memory returned. 
 29080  29197   **
 29081  29198   ** Just before the shared-btree is closed, the function passed as the 
 29082  29199   ** xFree argument when the memory allocation was made is invoked on the 
 29083  29200   ** blob of allocated memory. This function should not call sqliteFree()
 29084  29201   ** on the memory, the btree layer does that.
 29085  29202   */
 29086         -static void *sqlite3BtreeSchema(Btree *p, int nBytes, void(*xFree)(void *)){
        29203  +SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *p, int nBytes, void(*xFree)(void *)){
 29087  29204     BtShared *pBt = p->pBt;
 29088  29205     if( !pBt->pSchema ){
 29089  29206       pBt->pSchema = sqliteMalloc(nBytes);
 29090  29207       pBt->xFreeSchema = xFree;
 29091  29208     }
 29092  29209     return pBt->pSchema;
 29093  29210   }
 29094  29211   
 29095  29212   /*
 29096  29213   ** Return true if another user of the same shared btree as the argument
 29097  29214   ** handle holds an exclusive lock on the sqlite_master table.
 29098  29215   */
 29099         -static int sqlite3BtreeSchemaLocked(Btree *p){
        29216  +SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *p){
 29100  29217     return (queryTableLock(p, MASTER_ROOT, READ_LOCK)!=SQLITE_OK);
 29101  29218   }
 29102  29219   
 29103  29220   
 29104  29221   #ifndef SQLITE_OMIT_SHARED_CACHE
 29105  29222   /*
 29106  29223   ** Obtain a lock on the table whose root page is iTab.  The
 29107  29224   ** lock is a write lock if isWritelock is true or a read lock
 29108  29225   ** if it is false.
 29109  29226   */
 29110         -static int sqlite3BtreeLockTable(Btree *p, int iTab, u8 isWriteLock){
        29227  +SQLITE_PRIVATE int sqlite3BtreeLockTable(Btree *p, int iTab, u8 isWriteLock){
 29111  29228     int rc = SQLITE_OK;
 29112  29229     u8 lockType = (isWriteLock?WRITE_LOCK:READ_LOCK);
 29113  29230     rc = queryTableLock(p, iTab, lockType);
 29114  29231     if( rc==SQLITE_OK ){
 29115  29232       rc = lockTable(p, iTab, lockType);
 29116  29233     }
 29117  29234     return rc;
................................................................................
 29122  29239   /*
 29123  29240   ** Argument pCsr must be a cursor opened for writing on an 
 29124  29241   ** INTKEY table currently pointing at a valid table entry. 
 29125  29242   ** This function modifies the data stored as part of that entry.
 29126  29243   ** Only the data content may only be modified, it is not possible
 29127  29244   ** to change the length of the data stored.
 29128  29245   */
 29129         -static int sqlite3BtreePutData(BtCursor *pCsr, u32 offset, u32 amt, void *z){
        29246  +SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor *pCsr, u32 offset, u32 amt, void *z){
 29130  29247   
 29131  29248     assert(pCsr->isIncrblobHandle);
 29132  29249     if( pCsr->eState==CURSOR_REQUIRESEEK ){
 29133  29250       return SQLITE_ABORT;
 29134  29251     }
 29135  29252   
 29136  29253     /* Check some preconditions: 
................................................................................
 29159  29276   ** for incremental blob IO only.
 29160  29277   **
 29161  29278   ** This function sets a flag only. The actual page location cache
 29162  29279   ** (stored in BtCursor.aOverflow[]) is allocated and used by function
 29163  29280   ** accessPayload() (the worker function for sqlite3BtreeData() and
 29164  29281   ** sqlite3BtreePutData()).
 29165  29282   */
 29166         -static void sqlite3BtreeCacheOverflow(BtCursor *pCur){
        29283  +SQLITE_PRIVATE void sqlite3BtreeCacheOverflow(BtCursor *pCur){
 29167  29284     assert(!pCur->isIncrblobHandle);
 29168  29285     assert(!pCur->aOverflow);
 29169  29286     pCur->isIncrblobHandle = 1;
 29170  29287   }
 29171  29288   #endif
 29172  29289   
 29173  29290   /************** End of btree.c ***********************************************/
................................................................................
 29205  29322     }
 29206  29323     return pPage;
 29207  29324   }
 29208  29325   
 29209  29326   /*
 29210  29327   ** Initialize a Fifo structure.
 29211  29328   */
 29212         -static void sqlite3VdbeFifoInit(Fifo *pFifo){
        29329  +SQLITE_PRIVATE void sqlite3VdbeFifoInit(Fifo *pFifo){
 29213  29330     memset(pFifo, 0, sizeof(*pFifo));
 29214  29331   }
 29215  29332   
 29216  29333   /*
 29217  29334   ** Push a single 64-bit integer value into the Fifo.  Return SQLITE_OK
 29218  29335   ** normally.   SQLITE_NOMEM is returned if we are unable to allocate
 29219  29336   ** memory.
 29220  29337   */
 29221         -static int sqlite3VdbeFifoPush(Fifo *pFifo, i64 val){
        29338  +SQLITE_PRIVATE int sqlite3VdbeFifoPush(Fifo *pFifo, i64 val){
 29222  29339     FifoPage *pPage;
 29223  29340     pPage = pFifo->pLast;
 29224  29341     if( pPage==0 ){
 29225  29342       pPage = pFifo->pLast = pFifo->pFirst = allocateFifoPage(20);
 29226  29343       if( pPage==0 ){
 29227  29344         return SQLITE_NOMEM;
 29228  29345       }
................................................................................
 29239  29356   }
 29240  29357   
 29241  29358   /*
 29242  29359   ** Extract a single 64-bit integer value from the Fifo.  The integer
 29243  29360   ** extracted is the one least recently inserted.  If the Fifo is empty
 29244  29361   ** return SQLITE_DONE.
 29245  29362   */
 29246         -static int sqlite3VdbeFifoPop(Fifo *pFifo, i64 *pVal){
        29363  +SQLITE_PRIVATE int sqlite3VdbeFifoPop(Fifo *pFifo, i64 *pVal){
 29247  29364     FifoPage *pPage;
 29248  29365     if( pFifo->nEntry==0 ){
 29249  29366       return SQLITE_DONE;
 29250  29367     }
 29251  29368     assert( pFifo->nEntry>0 );
 29252  29369     pPage = pFifo->pFirst;
 29253  29370     assert( pPage!=0 );
................................................................................
 29272  29389     return SQLITE_OK;
 29273  29390   }
 29274  29391   
 29275  29392   /*
 29276  29393   ** Delete all information from a Fifo object.   Free all memory held
 29277  29394   ** by the Fifo.
 29278  29395   */
 29279         -static void sqlite3VdbeFifoClear(Fifo *pFifo){
        29396  +SQLITE_PRIVATE void sqlite3VdbeFifoClear(Fifo *pFifo){
 29280  29397     FifoPage *pPage, *pNextPage;
 29281  29398     for(pPage=pFifo->pFirst; pPage; pPage=pNextPage){
 29282  29399       pNextPage = pPage->pNext;
 29283  29400       sqliteFree(pPage);
 29284  29401     }
 29285  29402     sqlite3VdbeFifoInit(pFifo);
 29286  29403   }
................................................................................
 29320  29437   ** representation is already stored using the requested encoding, then this
 29321  29438   ** routine is a no-op.
 29322  29439   **
 29323  29440   ** SQLITE_OK is returned if the conversion is successful (or not required).
 29324  29441   ** SQLITE_NOMEM may be returned if a malloc() fails during conversion
 29325  29442   ** between formats.
 29326  29443   */
 29327         -static int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){
        29444  +SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){
 29328  29445     int rc;
 29329  29446     if( !(pMem->flags&MEM_Str) || pMem->enc==desiredEnc ){
 29330  29447       return SQLITE_OK;
 29331  29448     }
 29332  29449   #ifdef SQLITE_OMIT_UTF16
 29333  29450     return SQLITE_ERROR;
 29334  29451   #else
................................................................................
 29346  29463   }
 29347  29464   
 29348  29465   /*
 29349  29466   ** Make the given Mem object MEM_Dyn.
 29350  29467   **
 29351  29468   ** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails.
 29352  29469   */
 29353         -static int sqlite3VdbeMemDynamicify(Mem *pMem){
        29470  +SQLITE_PRIVATE int sqlite3VdbeMemDynamicify(Mem *pMem){
 29354  29471     int n;
 29355  29472     u8 *z;
 29356  29473     expandBlob(pMem);
 29357  29474     if( (pMem->flags & (MEM_Ephem|MEM_Static|MEM_Short))==0 ){
 29358  29475       return SQLITE_OK;
 29359  29476     }
 29360  29477     assert( (pMem->flags & MEM_Dyn)==0 );
................................................................................
 29375  29492   }
 29376  29493   
 29377  29494   /*
 29378  29495   ** If the given Mem* has a zero-filled tail, turn it into an ordinary
 29379  29496   ** blob stored in dynamically allocated space.
 29380  29497   */
 29381  29498   #ifndef SQLITE_OMIT_INCRBLOB
 29382         -static int sqlite3VdbeMemExpandBlob(Mem *pMem){
        29499  +SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *pMem){
 29383  29500     if( pMem->flags & MEM_Zero ){
 29384  29501       char *pNew;
 29385  29502       int nByte;
 29386  29503       assert( (pMem->flags & MEM_Blob)!=0 );
 29387  29504       nByte = pMem->n + pMem->u.i;
 29388  29505       if( nByte<=0 ) nByte = 1;
 29389  29506       pNew = sqliteMalloc(nByte);
................................................................................
 29406  29523   
 29407  29524   /*
 29408  29525   ** Make the given Mem object either MEM_Short or MEM_Dyn so that bytes
 29409  29526   ** of the Mem.z[] array can be modified.
 29410  29527   **
 29411  29528   ** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails.
 29412  29529   */
 29413         -static int sqlite3VdbeMemMakeWriteable(Mem *pMem){
        29530  +SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem *pMem){
 29414  29531     int n;
 29415  29532     u8 *z;
 29416  29533     expandBlob(pMem);
 29417  29534     if( (pMem->flags & (MEM_Ephem|MEM_Static))==0 ){
 29418  29535       return SQLITE_OK;
 29419  29536     }
 29420  29537     assert( (pMem->flags & MEM_Dyn)==0 );
................................................................................
 29438  29555     assert(0==(1&(int)pMem->z));
 29439  29556     return SQLITE_OK;
 29440  29557   }
 29441  29558   
 29442  29559   /*
 29443  29560   ** Make sure the given Mem is \u0000 terminated.
 29444  29561   */
 29445         -static int sqlite3VdbeMemNulTerminate(Mem *pMem){
        29562  +SQLITE_PRIVATE int sqlite3VdbeMemNulTerminate(Mem *pMem){
 29446  29563     if( (pMem->flags & MEM_Term)!=0 || (pMem->flags & MEM_Str)==0 ){
 29447  29564       return SQLITE_OK;   /* Nothing to do */
 29448  29565     }
 29449  29566     if( pMem->flags & (MEM_Static|MEM_Ephem) ){
 29450  29567       return sqlite3VdbeMemMakeWriteable(pMem);
 29451  29568     }else{
 29452  29569       char *z; 
................................................................................
 29478  29595   **
 29479  29596   ** A MEM_Null value will never be passed to this function. This function is
 29480  29597   ** used for converting values to text for returning to the user (i.e. via
 29481  29598   ** sqlite3_value_text()), or for ensuring that values to be used as btree
 29482  29599   ** keys are strings. In the former case a NULL pointer is returned the
 29483  29600   ** user and the later is an internal programming error.
 29484  29601   */
 29485         -static int sqlite3VdbeMemStringify(Mem *pMem, int enc){
        29602  +SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem *pMem, int enc){
 29486  29603     int rc = SQLITE_OK;
 29487  29604     int fg = pMem->flags;
 29488  29605     char *z = pMem->zShort;
 29489  29606   
 29490  29607     assert( !(fg&MEM_Zero) );
 29491  29608     assert( !(fg&(MEM_Str|MEM_Blob)) );
 29492  29609     assert( fg&(MEM_Int|MEM_Real) );
................................................................................
 29515  29632   ** Memory cell pMem contains the context of an aggregate function.
 29516  29633   ** This routine calls the finalize method for that function.  The
 29517  29634   ** result of the aggregate is stored back into pMem.
 29518  29635   **
 29519  29636   ** Return SQLITE_ERROR if the finalizer reports an error.  SQLITE_OK
 29520  29637   ** otherwise.
 29521  29638   */
 29522         -static int sqlite3VdbeMemFinalize(Mem *pMem, FuncDef *pFunc){
        29639  +SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem *pMem, FuncDef *pFunc){
 29523  29640     int rc = SQLITE_OK;
 29524  29641     if( pFunc && pFunc->xFinalize ){
 29525  29642       sqlite3_context ctx;
 29526  29643       assert( (pMem->flags & MEM_Null)!=0 || pFunc==pMem->u.pDef );
 29527  29644       ctx.s.flags = MEM_Null;
 29528  29645       ctx.s.z = pMem->zShort;
 29529  29646       ctx.pMem = pMem;
................................................................................
 29545  29662   }
 29546  29663   
 29547  29664   /*
 29548  29665   ** Release any memory held by the Mem. This may leave the Mem in an
 29549  29666   ** inconsistent state, for example with (Mem.z==0) and
 29550  29667   ** (Mem.type==SQLITE_TEXT).
 29551  29668   */
 29552         -static void sqlite3VdbeMemRelease(Mem *p){
        29669  +SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
 29553  29670     if( p->flags & (MEM_Dyn|MEM_Agg) ){
 29554  29671       if( p->xDel ){
 29555  29672         if( p->flags & MEM_Agg ){
 29556  29673           sqlite3VdbeMemFinalize(p, p->u.pDef);
 29557  29674           assert( (p->flags & MEM_Agg)==0 );
 29558  29675           sqlite3VdbeMemRelease(p);
 29559  29676         }else{
................................................................................
 29573  29690   ** If pMem is an integer, then the value is exact.  If pMem is
 29574  29691   ** a floating-point then the value returned is the integer part.
 29575  29692   ** If pMem is a string or blob, then we make an attempt to convert
 29576  29693   ** it into a integer and return that.  If pMem is NULL, return 0.
 29577  29694   **
 29578  29695   ** If pMem is a string, its encoding might be changed.
 29579  29696   */
 29580         -static i64 sqlite3VdbeIntValue(Mem *pMem){
        29697  +SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem *pMem){
 29581  29698     int flags = pMem->flags;
 29582  29699     if( flags & MEM_Int ){
 29583  29700       return pMem->u.i;
 29584  29701     }else if( flags & MEM_Real ){
 29585  29702       return (i64)pMem->r;
 29586  29703     }else if( flags & (MEM_Str|MEM_Blob) ){
 29587  29704       i64 value;
................................................................................
 29600  29717   
 29601  29718   /*
 29602  29719   ** Return the best representation of pMem that we can get into a
 29603  29720   ** double.  If pMem is already a double or an integer, return its
 29604  29721   ** value.  If it is a string or blob, try to convert it to a double.
 29605  29722   ** If it is a NULL, return 0.0.
 29606  29723   */
 29607         -static double sqlite3VdbeRealValue(Mem *pMem){
        29724  +SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){
 29608  29725     if( pMem->flags & MEM_Real ){
 29609  29726       return pMem->r;
 29610  29727     }else if( pMem->flags & MEM_Int ){
 29611  29728       return (double)pMem->u.i;
 29612  29729     }else if( pMem->flags & (MEM_Str|MEM_Blob) ){
 29613  29730       double val = 0.0;
 29614  29731       pMem->flags |= MEM_Str;
................................................................................
 29624  29741     }
 29625  29742   }
 29626  29743   
 29627  29744   /*
 29628  29745   ** The MEM structure is already a MEM_Real.  Try to also make it a
 29629  29746   ** MEM_Int if we can.
 29630  29747   */
 29631         -static void sqlite3VdbeIntegerAffinity(Mem *pMem){
        29748  +SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem *pMem){
 29632  29749     assert( pMem->flags & MEM_Real );
 29633  29750     pMem->u.i = pMem->r;
 29634  29751     if( ((double)pMem->u.i)==pMem->r ){
 29635  29752       pMem->flags |= MEM_Int;
 29636  29753     }
 29637  29754   }
 29638  29755   
 29639  29756   /*
 29640  29757   ** Convert pMem to type integer.  Invalidate any prior representations.
 29641  29758   */
 29642         -static int sqlite3VdbeMemIntegerify(Mem *pMem){
        29759  +SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem *pMem){
 29643  29760     pMem->u.i = sqlite3VdbeIntValue(pMem);
 29644  29761     sqlite3VdbeMemRelease(pMem);
 29645  29762     pMem->flags = MEM_Int;
 29646  29763     return SQLITE_OK;
 29647  29764   }
 29648  29765   
 29649  29766   /*
 29650  29767   ** Convert pMem so that it is of type MEM_Real.
 29651  29768   ** Invalidate any prior representations.
 29652  29769   */
 29653         -static int sqlite3VdbeMemRealify(Mem *pMem){
        29770  +SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem *pMem){
 29654  29771     pMem->r = sqlite3VdbeRealValue(pMem);
 29655  29772     sqlite3VdbeMemRelease(pMem);
 29656  29773     pMem->flags = MEM_Real;
 29657  29774     return SQLITE_OK;
 29658  29775   }
 29659  29776   
 29660  29777   /*
 29661  29778   ** Convert pMem so that it has types MEM_Real or MEM_Int or both.
 29662  29779   ** Invalidate any prior representations.
 29663  29780   */
 29664         -static int sqlite3VdbeMemNumerify(Mem *pMem){
        29781  +SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem *pMem){
 29665  29782     double r1, r2;
 29666  29783     i64 i;
 29667  29784     assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))==0 );
 29668  29785     assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
 29669  29786     r1 = sqlite3VdbeRealValue(pMem);
 29670  29787     i = (i64)r1;
 29671  29788     r2 = (double)i;
................................................................................
 29678  29795     }
 29679  29796     return SQLITE_OK;
 29680  29797   }
 29681  29798   
 29682  29799   /*
 29683  29800   ** Delete any previous value and set the value stored in *pMem to NULL.
 29684  29801   */
 29685         -static void sqlite3VdbeMemSetNull(Mem *pMem){
        29802  +SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem *pMem){
 29686  29803     sqlite3VdbeMemRelease(pMem);
 29687  29804     pMem->flags = MEM_Null;
 29688  29805     pMem->type = SQLITE_NULL;
 29689  29806     pMem->n = 0;
 29690  29807   }
 29691  29808   
 29692  29809   /*
 29693  29810   ** Delete any previous value and set the value to be a BLOB of length
 29694  29811   ** n containing all zeros.
 29695  29812   */
 29696         -static void sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){
        29813  +SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){
 29697  29814     sqlite3VdbeMemRelease(pMem);
 29698  29815     pMem->flags = MEM_Blob|MEM_Zero|MEM_Short;
 29699  29816     pMem->type = SQLITE_BLOB;
 29700  29817     pMem->n = 0;
 29701  29818     if( n<0 ) n = 0;
 29702  29819     pMem->u.i = n;
 29703  29820     pMem->z = pMem->zShort;
................................................................................
 29704  29821     pMem->enc = SQLITE_UTF8;
 29705  29822   }
 29706  29823   
 29707  29824   /*
 29708  29825   ** Delete any previous value and set the value stored in *pMem to val,
 29709  29826   ** manifest type INTEGER.
 29710  29827   */
 29711         -static void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){
        29828  +SQLITE_PRIVATE void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){
 29712  29829     sqlite3VdbeMemRelease(pMem);
 29713  29830     pMem->u.i = val;
 29714  29831     pMem->flags = MEM_Int;
 29715  29832     pMem->type = SQLITE_INTEGER;
 29716  29833   }
 29717  29834   
 29718  29835   /*
 29719  29836   ** Delete any previous value and set the value stored in *pMem to val,
 29720  29837   ** manifest type REAL.
 29721  29838   */
 29722         -static void sqlite3VdbeMemSetDouble(Mem *pMem, double val){
 29723         -  if( isnan(val) ){
        29839  +SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem *pMem, double val){
        29840  +  if( sqlite3_isnan(val) ){
 29724  29841       sqlite3VdbeMemSetNull(pMem);
 29725  29842     }else{
 29726  29843       sqlite3VdbeMemRelease(pMem);
 29727  29844       pMem->r = val;
 29728  29845       pMem->flags = MEM_Real;
 29729  29846       pMem->type = SQLITE_FLOAT;
 29730  29847     }
 29731  29848   }
 29732  29849   
 29733  29850   /*
 29734  29851   ** Return true if the Mem object contains a TEXT or BLOB that is
 29735  29852   ** too large - whose size exceeds SQLITE_MAX_LENGTH.
 29736  29853   */
 29737         -static int sqlite3VdbeMemTooBig(Mem *p){
        29854  +SQLITE_PRIVATE int sqlite3VdbeMemTooBig(Mem *p){
 29738  29855     if( p->flags & (MEM_Str|MEM_Blob) ){
 29739  29856       int n = p->n;
 29740  29857       if( p->flags & MEM_Zero ){
 29741  29858         n += p->u.i;
 29742  29859       }
 29743  29860       return n>SQLITE_MAX_LENGTH;
 29744  29861     }
................................................................................
 29747  29864   
 29748  29865   /*
 29749  29866   ** Make an shallow copy of pFrom into pTo.  Prior contents of
 29750  29867   ** pTo are overwritten.  The pFrom->z field is not duplicated.  If
 29751  29868   ** pFrom->z is used, then pTo->z points to the same thing as pFrom->z
 29752  29869   ** and flags gets srcType (either MEM_Ephem or MEM_Static).
 29753  29870   */
 29754         -static void sqlite3VdbeMemShallowCopy(Mem *pTo, const Mem *pFrom, int srcType){
        29871  +SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy(Mem *pTo, const Mem *pFrom, int srcType){
 29755  29872     memcpy(pTo, pFrom, sizeof(*pFrom)-sizeof(pFrom->zShort));
 29756  29873     pTo->xDel = 0;
 29757  29874     if( pTo->flags & (MEM_Str|MEM_Blob) ){
 29758  29875       pTo->flags &= ~(MEM_Dyn|MEM_Static|MEM_Short|MEM_Ephem);
 29759  29876       assert( srcType==MEM_Ephem || srcType==MEM_Static );
 29760  29877       pTo->flags |= srcType;
 29761  29878     }
 29762  29879   }
 29763  29880   
 29764  29881   /*
 29765  29882   ** Make a full copy of pFrom into pTo.  Prior contents of pTo are
 29766  29883   ** freed before the copy is made.
 29767  29884   */
 29768         -static int sqlite3VdbeMemCopy(Mem *pTo, const Mem *pFrom){
        29885  +SQLITE_PRIVATE int sqlite3VdbeMemCopy(Mem *pTo, const Mem *pFrom){
 29769  29886     int rc;
 29770  29887     if( pTo->flags & MEM_Dyn ){
 29771  29888       sqlite3VdbeMemRelease(pTo);
 29772  29889     }
 29773  29890     sqlite3VdbeMemShallowCopy(pTo, pFrom, MEM_Ephem);
 29774  29891     if( pTo->flags & MEM_Ephem ){
 29775  29892       rc = sqlite3VdbeMemMakeWriteable(pTo);
................................................................................
 29783  29900   ** Transfer the contents of pFrom to pTo. Any existing value in pTo is
 29784  29901   ** freed. If pFrom contains ephemeral data, a copy is made.
 29785  29902   **
 29786  29903   ** pFrom contains an SQL NULL when this routine returns.  SQLITE_NOMEM
 29787  29904   ** might be returned if pFrom held ephemeral data and we were unable
 29788  29905   ** to allocate enough space to make a copy.
 29789  29906   */
 29790         -static int sqlite3VdbeMemMove(Mem *pTo, Mem *pFrom){
        29907  +SQLITE_PRIVATE int sqlite3VdbeMemMove(Mem *pTo, Mem *pFrom){
 29791  29908     int rc;
 29792  29909     if( pTo->flags & MEM_Dyn ){
 29793  29910       sqlite3VdbeMemRelease(pTo);
 29794  29911     }
 29795  29912     memcpy(pTo, pFrom, sizeof(Mem));
 29796  29913     if( pFrom->flags & MEM_Short ){
 29797  29914       pTo->z = pTo->zShort;
................................................................................
 29805  29922     }
 29806  29923     return rc;
 29807  29924   }
 29808  29925   
 29809  29926   /*
 29810  29927   ** Change the value of a Mem to be a string or a BLOB.
 29811  29928   */
 29812         -static int sqlite3VdbeMemSetStr(
        29929  +SQLITE_PRIVATE int sqlite3VdbeMemSetStr(
 29813  29930     Mem *pMem,          /* Memory cell to set to string value */
 29814  29931     const char *z,      /* String pointer */
 29815  29932     int n,              /* Bytes in string, or negative */
 29816  29933     u8 enc,             /* Encoding of z.  0 for BLOBs */
 29817  29934     void (*xDel)(void*) /* Destructor function */
 29818  29935   ){
 29819  29936     sqlite3VdbeMemRelease(pMem);
................................................................................
 29877  29994   ** negative, zero or positive if pMem1 is less than, equal to, or greater
 29878  29995   ** than pMem2. Sorting order is NULL's first, followed by numbers (integers
 29879  29996   ** and reals) sorted numerically, followed by text ordered by the collating
 29880  29997   ** sequence pColl and finally blob's ordered by memcmp().
 29881  29998   **
 29882  29999   ** Two NULL values are considered equal by this function.
 29883  30000   */
 29884         -static int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
        30001  +SQLITE_PRIVATE int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
 29885  30002     int rc;
 29886  30003     int f1, f2;
 29887  30004     int combined_flags;
 29888  30005   
 29889  30006     /* Interchange pMem1 and pMem2 if the collating sequence specifies
 29890  30007     ** DESC order.
 29891  30008     */
................................................................................
 30002  30119   **
 30003  30120   ** The pMem structure is assumed to be uninitialized.  Any prior content
 30004  30121   ** is overwritten without being freed.
 30005  30122   **
 30006  30123   ** If this routine fails for any reason (malloc returns NULL or unable
 30007  30124   ** to read from the disk) then the pMem is left in an inconsistent state.
 30008  30125   */
 30009         -static int sqlite3VdbeMemFromBtree(
        30126  +SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(
 30010  30127     BtCursor *pCur,   /* Cursor pointing at record to retrieve. */
 30011  30128     int offset,       /* Offset from the start of data to return bytes from. */
 30012  30129     int amt,          /* Number of bytes to return. */
 30013  30130     int key,          /* If true, retrieve from the btree key, not data. */
 30014  30131     Mem *pMem         /* OUT: Return data in this Mem structure. */
 30015  30132   ){
 30016  30133     char *zData;       /* Data from the btree layer */
................................................................................
 30068  30185   }
 30069  30186   
 30070  30187   #ifndef NDEBUG
 30071  30188   /*
 30072  30189   ** Perform various checks on the memory cell pMem. An assert() will
 30073  30190   ** fail if pMem is internally inconsistent.
 30074  30191   */
 30075         -static void sqlite3VdbeMemSanity(Mem *pMem){
        30192  +SQLITE_PRIVATE void sqlite3VdbeMemSanity(Mem *pMem){
 30076  30193     int flags = pMem->flags;
 30077  30194     assert( flags!=0 );  /* Must define some type */
 30078  30195     if( flags & (MEM_Str|MEM_Blob) ){
 30079  30196       int x = flags & (MEM_Static|MEM_Dyn|MEM_Ephem|MEM_Short);
 30080  30197       assert( x!=0 );            /* Strings must define a string subtype */
 30081  30198       assert( (x & (x-1))==0 );  /* Only one string subtype can be defined */
 30082  30199       assert( pMem->z!=0 );      /* Strings must have a value */
................................................................................
 30122  30239   ** parameter, which must be one of SQLITE_UTF16BE, SQLITE_UTF16LE or
 30123  30240   ** SQLITE_UTF8.
 30124  30241   **
 30125  30242   ** (2006-02-16:)  The enc value can be or-ed with SQLITE_UTF16_ALIGNED.
 30126  30243   ** If that is the case, then the result must be aligned on an even byte
 30127  30244   ** boundary.
 30128  30245   */
 30129         -static const void *sqlite3ValueText(sqlite3_value* pVal, u8 enc){
        30246  +SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value* pVal, u8 enc){
 30130  30247     if( !pVal ) return 0;
 30131  30248     assert( (enc&3)==(enc&~SQLITE_UTF16_ALIGNED) );
 30132  30249   
 30133  30250     if( pVal->flags&MEM_Null ){
 30134  30251       return 0;
 30135  30252     }
 30136  30253     assert( (MEM_Blob>>3) == MEM_Str );
................................................................................
 30157  30274       return 0;
 30158  30275     }
 30159  30276   }
 30160  30277   
 30161  30278   /*
 30162  30279   ** Create a new sqlite3_value object.
 30163  30280   */
 30164         -static sqlite3_value *sqlite3ValueNew(void){
        30281  +SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(void){
 30165  30282     Mem *p = sqliteMalloc(sizeof(*p));
 30166  30283     if( p ){
 30167  30284       p->flags = MEM_Null;
 30168  30285       p->type = SQLITE_NULL;
 30169  30286     }
 30170  30287     return p;
 30171  30288   }
................................................................................
 30176  30293   ** This only works for very simple expressions that consist of one constant
 30177  30294   ** token (i.e. "5", "5.1", "NULL", "'a string'"). If the expression can
 30178  30295   ** be converted directly into a value, then the value is allocated and
 30179  30296   ** a pointer written to *ppVal. The caller is responsible for deallocating
 30180  30297   ** the value by passing it to sqlite3ValueFree() later on. If the expression
 30181  30298   ** cannot be converted to a value, then *ppVal is set to NULL.
 30182  30299   */
 30183         -static int sqlite3ValueFromExpr(
        30300  +SQLITE_PRIVATE int sqlite3ValueFromExpr(
 30184  30301     Expr *pExpr, 
 30185  30302     u8 enc, 
 30186  30303     u8 affinity,
 30187  30304     sqlite3_value **ppVal
 30188  30305   ){
 30189  30306     int op;
 30190  30307     char *zVal = 0;
................................................................................
 30235  30352     *ppVal = 0;
 30236  30353     return SQLITE_NOMEM;
 30237  30354   }
 30238  30355   
 30239  30356   /*
 30240  30357   ** Change the string value of an sqlite3_value object
 30241  30358   */
 30242         -static void sqlite3ValueSetStr(
        30359  +SQLITE_PRIVATE void sqlite3ValueSetStr(
 30243  30360     sqlite3_value *v, 
 30244  30361     int n, 
 30245  30362     const void *z, 
 30246  30363     u8 enc,
 30247  30364     void (*xDel)(void*)
 30248  30365   ){
 30249  30366     if( v ) sqlite3VdbeMemSetStr((Mem *)v, z, n, enc, xDel);
 30250  30367   }
 30251  30368   
 30252  30369   /*
 30253  30370   ** Free an sqlite3_value object
 30254  30371   */
 30255         -static void sqlite3ValueFree(sqlite3_value *v){
        30372  +SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value *v){
 30256  30373     if( !v ) return;
 30257  30374     sqlite3ValueSetStr(v, 0, 0, SQLITE_UTF8, SQLITE_STATIC);
 30258  30375     sqliteFree(v);
 30259  30376   }
 30260  30377   
 30261  30378   /*
 30262  30379   ** Return the number of bytes in the sqlite3_value object assuming
 30263  30380   ** that it uses the encoding "enc"
 30264  30381   */
 30265         -static int sqlite3ValueBytes(sqlite3_value *pVal, u8 enc){
        30382  +SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value *pVal, u8 enc){
 30266  30383     Mem *p = (Mem*)pVal;
 30267  30384     if( (p->flags & MEM_Blob)!=0 || sqlite3ValueText(pVal, enc) ){
 30268  30385       if( p->flags & MEM_Zero ){
 30269  30386         return p->n+p->u.i;
 30270  30387       }else{
 30271  30388         return p->n;
 30272  30389       }
................................................................................
 30303  30420   int sqlite3_vdbe_addop_trace = 0;
 30304  30421   #endif
 30305  30422   
 30306  30423   
 30307  30424   /*
 30308  30425   ** Create a new virtual database engine.
 30309  30426   */
 30310         -static Vdbe *sqlite3VdbeCreate(sqlite3 *db){
        30427  +SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(sqlite3 *db){
 30311  30428     Vdbe *p;
 30312  30429     p = sqliteMalloc( sizeof(Vdbe) );
 30313  30430     if( p==0 ) return 0;
 30314  30431     p->db = db;
 30315  30432     if( db->pVdbe ){
 30316  30433       db->pVdbe->pPrev = p;
 30317  30434     }
................................................................................
 30321  30438     p->magic = VDBE_MAGIC_INIT;
 30322  30439     return p;
 30323  30440   }
 30324  30441   
 30325  30442   /*
 30326  30443   ** Remember the SQL string for a prepared statement.
 30327  30444   */
 30328         -static void sqlite3VdbeSetSql(Vdbe *p, const char *z, int n){
        30445  +SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe *p, const char *z, int n){
 30329  30446     if( p==0 ) return;
 30330  30447     assert( p->zSql==0 );
 30331  30448     p->zSql = sqlite3StrNDup(z, n);
 30332  30449   }
 30333  30450   
 30334  30451   /*
 30335  30452   ** Return the SQL associated with a prepared statement
 30336  30453   */
 30337         -static const char *sqlite3VdbeGetSql(Vdbe *p){
        30454  +SQLITE_PRIVATE const char *sqlite3VdbeGetSql(Vdbe *p){
 30338  30455     return p->zSql;
 30339  30456   }
 30340  30457   
 30341  30458   /*
 30342  30459   ** Swap all content between two VDBE structures.
 30343  30460   */
 30344         -static void sqlite3VdbeSwap(Vdbe *pA, Vdbe *pB){
        30461  +SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe *pA, Vdbe *pB){
 30345  30462     Vdbe tmp, *pTmp;
 30346  30463     char *zTmp;
 30347  30464     int nTmp;
 30348  30465     tmp = *pA;
 30349  30466     *pA = *pB;
 30350  30467     *pB = tmp;
 30351  30468     pTmp = pA->pNext;
................................................................................
 30362  30479     pB->nSql = nTmp;
 30363  30480   }
 30364  30481   
 30365  30482   #ifdef SQLITE_DEBUG
 30366  30483   /*
 30367  30484   ** Turn tracing on or off
 30368  30485   */
 30369         -static void sqlite3VdbeTrace(Vdbe *p, FILE *trace){
        30486  +SQLITE_PRIVATE void sqlite3VdbeTrace(Vdbe *p, FILE *trace){
 30370  30487     p->trace = trace;
 30371  30488   }
 30372  30489   #endif
 30373  30490   
 30374  30491   /*
 30375  30492   ** Resize the Vdbe.aOp array so that it contains at least N
 30376  30493   ** elements. If the Vdbe is in VDBE_MAGIC_RUN state, then
................................................................................
 30412  30529   **
 30413  30530   **    p1, p2          First two of the three possible operands.
 30414  30531   **
 30415  30532   ** Use the sqlite3VdbeResolveLabel() function to fix an address and
 30416  30533   ** the sqlite3VdbeChangeP3() function to change the value of the P3
 30417  30534   ** operand.
 30418  30535   */
 30419         -static int sqlite3VdbeAddOp(Vdbe *p, int op, int p1, int p2){
        30536  +SQLITE_PRIVATE int sqlite3VdbeAddOp(Vdbe *p, int op, int p1, int p2){
 30420  30537     int i;
 30421  30538     VdbeOp *pOp;
 30422  30539   
 30423  30540     i = p->nOp;
 30424  30541     assert( p->magic==VDBE_MAGIC_INIT );
 30425  30542     if( p->nOpAlloc<=i ){
 30426  30543       resizeOpArray(p, i+1);
................................................................................
 30441  30558   #endif
 30442  30559     return i;
 30443  30560   }
 30444  30561   
 30445  30562   /*
 30446  30563   ** Add an opcode that includes the p3 value.
 30447  30564   */
 30448         -static int sqlite3VdbeOp3(Vdbe *p, int op, int p1, int p2, const char *zP3,int p3type){
        30565  +SQLITE_PRIVATE int sqlite3VdbeOp3(Vdbe *p, int op, int p1, int p2, const char *zP3,int p3type){
 30449  30566     int addr = sqlite3VdbeAddOp(p, op, p1, p2);
 30450  30567     sqlite3VdbeChangeP3(p, addr, zP3, p3type);
 30451  30568     return addr;
 30452  30569   }
 30453  30570   
 30454  30571   /*
 30455  30572   ** Create a new symbolic label for an instruction that has yet to be
................................................................................
 30461  30578   **
 30462  30579   ** The VDBE knows that a P2 value is a label because labels are
 30463  30580   ** always negative and P2 values are suppose to be non-negative.
 30464  30581   ** Hence, a negative P2 value is a label that has yet to be resolved.
 30465  30582   **
 30466  30583   ** Zero is returned if a malloc() fails.
 30467  30584   */
 30468         -static int sqlite3VdbeMakeLabel(Vdbe *p){
        30585  +SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe *p){
 30469  30586     int i;
 30470  30587     i = p->nLabel++;
 30471  30588     assert( p->magic==VDBE_MAGIC_INIT );
 30472  30589     if( i>=p->nLabelAlloc ){
 30473  30590       p->nLabelAlloc = p->nLabelAlloc*2 + 10;
 30474  30591       p->aLabel = sqliteReallocOrFree(p->aLabel,
 30475  30592                                       p->nLabelAlloc*sizeof(p->aLabel[0]));
................................................................................
 30481  30598   }
 30482  30599   
 30483  30600   /*
 30484  30601   ** Resolve label "x" to be the address of the next instruction to
 30485  30602   ** be inserted.  The parameter "x" must have been obtained from
 30486  30603   ** a prior call to sqlite3VdbeMakeLabel().
 30487  30604   */
 30488         -static void sqlite3VdbeResolveLabel(Vdbe *p, int x){
        30605  +SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *p, int x){
 30489  30606     int j = -1-x;
 30490  30607     assert( p->magic==VDBE_MAGIC_INIT );
 30491  30608     assert( j>=0 && j<p->nLabel );
 30492  30609     if( p->aLabel ){
 30493  30610       p->aLabel[j] = p->nOp;
 30494  30611     }
 30495  30612   }
................................................................................
 30527  30644       NOPUSH_MASK_8 + (((unsigned)NOPUSH_MASK_9)<<16)
 30528  30645     };
 30529  30646     assert( op<32*5 );
 30530  30647     return (masks[op>>5] & (1<<(op&0x1F)));
 30531  30648   }
 30532  30649   
 30533  30650   #ifndef NDEBUG
 30534         -static int sqlite3VdbeOpcodeNoPush(u8 op){
        30651  +SQLITE_PRIVATE int sqlite3VdbeOpcodeNoPush(u8 op){
 30535  30652     return opcodeNoPush(op);
 30536  30653   }
 30537  30654   #endif
 30538  30655   
 30539  30656   /*
 30540  30657   ** Loop through the program looking for P2 values that are negative.
 30541  30658   ** Each such value is a label.  Resolve the label by setting the P2
................................................................................
 30569  30686   
 30570  30687       if( opcode==OP_Function || opcode==OP_AggStep 
 30571  30688   #ifndef SQLITE_OMIT_VIRTUALTABLE
 30572  30689           || opcode==OP_VUpdate
 30573  30690   #endif
 30574  30691       ){
 30575  30692         if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
 30576         -    }else if( opcode==OP_Halt ){
        30693  +    }
        30694  +    if( opcode==OP_Halt ){
 30577  30695         if( pOp->p1==SQLITE_CONSTRAINT && pOp->p2==OE_Abort ){
 30578  30696           doesStatementRollback = 1;
 30579  30697         }
 30580  30698       }else if( opcode==OP_Statement ){
 30581  30699         hasStatementBegin = 1;
        30700  +#ifndef SQLITE_OMIT_VIRTUALTABLE
        30701  +    }else if( opcode==OP_VUpdate || opcode==OP_VRename ){
        30702  +      doesStatementRollback = 1;
 30582  30703       }else if( opcode==OP_VFilter ){
 30583  30704         int n;
 30584  30705         assert( p->nOp - i >= 3 );
 30585  30706         assert( pOp[-2].opcode==OP_Integer );
 30586  30707         n = pOp[-2].p1;
 30587  30708         if( n>nMaxArgs ) nMaxArgs = n;
        30709  +#endif
 30588  30710       }
 30589  30711       if( opcodeNoPush(opcode) ){
 30590  30712         nMaxStack--;
 30591  30713       }
 30592  30714   
 30593  30715       if( pOp->p2>=0 ) continue;
 30594  30716       assert( -1-pOp->p2<p->nLabel );
................................................................................
 30613  30735       }
 30614  30736     }
 30615  30737   }
 30616  30738   
 30617  30739   /*
 30618  30740   ** Return the address of the next instruction to be inserted.
 30619  30741   */
 30620         -static int sqlite3VdbeCurrentAddr(Vdbe *p){
        30742  +SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){
 30621  30743     assert( p->magic==VDBE_MAGIC_INIT );
 30622  30744     return p->nOp;
 30623  30745   }
 30624  30746   
 30625  30747   /*
 30626  30748   ** Add a whole list of operations to the operation stack.  Return the
 30627  30749   ** address of the first operation added.
 30628  30750   */
 30629         -static int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){
        30751  +SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){
 30630  30752     int addr;
 30631  30753     assert( p->magic==VDBE_MAGIC_INIT );
 30632  30754     resizeOpArray(p, p->nOp + nOp);
 30633  30755     if( sqlite3MallocFailed() ){
 30634  30756       return 0;
 30635  30757     }
 30636  30758     addr = p->nOp;
................................................................................
 30658  30780   
 30659  30781   /*
 30660  30782   ** Change the value of the P1 operand for a specific instruction.
 30661  30783   ** This routine is useful when a large program is loaded from a
 30662  30784   ** static array using sqlite3VdbeAddOpList but we want to make a
 30663  30785   ** few minor changes to the program.
 30664  30786   */
 30665         -static void sqlite3VdbeChangeP1(Vdbe *p, int addr, int val){
        30787  +SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe *p, int addr, int val){
 30666  30788     assert( p==0 || p->magic==VDBE_MAGIC_INIT );
 30667  30789     if( p && addr>=0 && p->nOp>addr && p->aOp ){
 30668  30790       p->aOp[addr].p1 = val;
 30669  30791     }
 30670  30792   }
 30671  30793   
 30672  30794   /*
 30673  30795   ** Change the value of the P2 operand for a specific instruction.
 30674  30796   ** This routine is useful for setting a jump destination.
 30675  30797   */
 30676         -static void sqlite3VdbeChangeP2(Vdbe *p, int addr, int val){
        30798  +SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe *p, int addr, int val){
 30677  30799     assert( val>=0 );
 30678  30800     assert( p==0 || p->magic==VDBE_MAGIC_INIT );
 30679  30801     if( p && addr>=0 && p->nOp>addr && p->aOp ){
 30680  30802       p->aOp[addr].p2 = val;
 30681  30803     }
 30682  30804   }
 30683  30805   
 30684  30806   /*
 30685  30807   ** Change the P2 operand of instruction addr so that it points to
 30686  30808   ** the address of the next instruction to be coded.
 30687  30809   */
 30688         -static void sqlite3VdbeJumpHere(Vdbe *p, int addr){
        30810  +SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe *p, int addr){
 30689  30811     sqlite3VdbeChangeP2(p, addr, p->nOp);
 30690  30812   }
 30691  30813   
 30692  30814   
 30693  30815   /*
 30694  30816   ** If the input FuncDef structure is ephemeral, then free it.  If
 30695  30817   ** the FuncDef is not ephermal, then do nothing.
................................................................................
 30735  30857     }
 30736  30858   }
 30737  30859   
 30738  30860   
 30739  30861   /*
 30740  30862   ** Change N opcodes starting at addr to No-ops.
 30741  30863   */
 30742         -static void sqlite3VdbeChangeToNoop(Vdbe *p, int addr, int N){
        30864  +SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe *p, int addr, int N){
 30743  30865     if( p && p->aOp ){
 30744  30866       VdbeOp *pOp = &p->aOp[addr];
 30745  30867       while( N-- ){
 30746  30868         freeP3(pOp->p3type, pOp->p3);
 30747  30869         memset(pOp, 0, sizeof(pOp[0]));
 30748  30870         pOp->opcode = OP_Noop;
 30749  30871         pOp++;
................................................................................
 30772  30894   ** 
 30773  30895   ** Other values of n (P3_STATIC, P3_COLLSEQ etc.) indicate that zP3 points
 30774  30896   ** to a string or structure that is guaranteed to exist for the lifetime of
 30775  30897   ** the Vdbe. In these cases we can just copy the pointer.
 30776  30898   **
 30777  30899   ** If addr<0 then change P3 on the most recently inserted instruction.
 30778  30900   */
 30779         -static void sqlite3VdbeChangeP3(Vdbe *p, int addr, const char *zP3, int n){
        30901  +SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, int addr, const char *zP3, int n){
 30780  30902     Op *pOp;
 30781  30903     assert( p==0 || p->magic==VDBE_MAGIC_INIT );
 30782  30904     if( p==0 || p->aOp==0 || sqlite3MallocFailed() ){
 30783  30905       if (n != P3_KEYINFO) {
 30784  30906         freeP3(n, (void*)*(char**)&zP3);
 30785  30907       }
 30786  30908       return;
................................................................................
 30829  30951   }
 30830  30952   
 30831  30953   #ifndef NDEBUG
 30832  30954   /*
 30833  30955   ** Replace the P3 field of the most recently coded instruction with
 30834  30956   ** comment text.
 30835  30957   */
 30836         -static void sqlite3VdbeComment(Vdbe *p, const char *zFormat, ...){
        30958  +SQLITE_PRIVATE void sqlite3VdbeComment(Vdbe *p, const char *zFormat, ...){
 30837  30959     va_list ap;
 30838  30960     assert( p->nOp>0 || p->aOp==0 );
 30839  30961     assert( p->aOp==0 || p->aOp[p->nOp-1].p3==0 || sqlite3MallocFailed() );
 30840  30962     va_start(ap, zFormat);
 30841  30963     sqlite3VdbeChangeP3(p, -1, sqlite3VMPrintf(zFormat, ap), P3_DYNAMIC);
 30842  30964     va_end(ap);
 30843  30965   }
 30844  30966   #endif
 30845  30967   
 30846  30968   /*
 30847  30969   ** Return the opcode for a given address.
 30848  30970   */
 30849         -static VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
        30971  +SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
 30850  30972     assert( p->magic==VDBE_MAGIC_INIT );
 30851  30973     assert( (addr>=0 && addr<p->nOp) || sqlite3MallocFailed() );
 30852  30974     return ((addr>=0 && addr<p->nOp)?(&p->aOp[addr]):0);
 30853  30975   }
 30854  30976   
 30855  30977   #if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) \
 30856  30978        || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
................................................................................
 30925  31047   #endif
 30926  31048   
 30927  31049   
 30928  31050   #if defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
 30929  31051   /*
 30930  31052   ** Print a single opcode.  This routine is used for debugging only.
 30931  31053   */
 30932         -static void sqlite3VdbePrintOp(FILE *pOut, int pc, Op *pOp){
        31054  +SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE *pOut, int pc, Op *pOp){
 30933  31055     char *zP3;
 30934  31056     char zPtr[50];
 30935  31057     static const char *zFormat1 = "%4d %-13s %4d %4d %s\n";
 30936  31058     if( pOut==0 ) pOut = stdout;
 30937  31059     zP3 = displayP3(pOp, zPtr, sizeof(zPtr));
 30938  31060     fprintf(pOut, zFormat1,
 30939  31061         pc, sqlite3OpcodeNames[pOp->opcode], pOp->p1, pOp->p2, zP3);
................................................................................
 30956  31078   /*
 30957  31079   ** Give a listing of the program in the virtual machine.
 30958  31080   **
 30959  31081   ** The interface is the same as sqlite3VdbeExec().  But instead of
 30960  31082   ** running the code, it invokes the callback once for each instruction.
 30961  31083   ** This feature is used to implement "EXPLAIN".
 30962  31084   */
 30963         -static int sqlite3VdbeList(
        31085  +SQLITE_PRIVATE int sqlite3VdbeList(
 30964  31086     Vdbe *p                   /* The VDBE */
 30965  31087   ){
 30966  31088     sqlite3 *db = p->db;
 30967  31089     int i;
 30968  31090     int rc = SQLITE_OK;
 30969  31091   
 30970  31092     assert( p->explain );
................................................................................
 31034  31156   }
 31035  31157   #endif /* SQLITE_OMIT_EXPLAIN */
 31036  31158   
 31037  31159   #ifdef SQLITE_DEBUG
 31038  31160   /*
 31039  31161   ** Print the SQL that was used to generate a VDBE program.
 31040  31162   */
 31041         -static void sqlite3VdbePrintSql(Vdbe *p){
        31163  +SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe *p){
 31042  31164     int nOp = p->nOp;
 31043  31165     VdbeOp *pOp;
 31044  31166     if( nOp<1 ) return;
 31045  31167     pOp = &p->aOp[nOp-1];
 31046  31168     if( pOp->opcode==OP_Noop && pOp->p3!=0 ){
 31047  31169       const char *z = pOp->p3;
 31048  31170       while( isspace(*(u8*)z) ) z++;
................................................................................
 31051  31173   }
 31052  31174   #endif
 31053  31175   
 31054  31176   #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
 31055  31177   /*
 31056  31178   ** Print an IOTRACE message showing SQL content.
 31057  31179   */
 31058         -static void sqlite3VdbeIOTraceSql(Vdbe *p){
        31180  +SQLITE_PRIVATE void sqlite3VdbeIOTraceSql(Vdbe *p){
 31059  31181     int nOp = p->nOp;
 31060  31182     VdbeOp *pOp;
 31061  31183     if( sqlite3_io_trace==0 ) return;
 31062  31184     if( nOp<1 ) return;
 31063  31185     pOp = &p->aOp[nOp-1];
 31064  31186     if( pOp->opcode==OP_Noop && pOp->p3!=0 ){
 31065  31187       char *z = sqlite3StrDup(pOp->p3);
................................................................................
 31087  31209   ** as allocating stack space and initializing the program counter.
 31088  31210   ** After the VDBE has be prepped, it can be executed by one or more
 31089  31211   ** calls to sqlite3VdbeExec().  
 31090  31212   **
 31091  31213   ** This is the only way to move a VDBE from VDBE_MAGIC_INIT to
 31092  31214   ** VDBE_MAGIC_RUN.
 31093  31215   */
 31094         -static void sqlite3VdbeMakeReady(
        31216  +SQLITE_PRIVATE void sqlite3VdbeMakeReady(
 31095  31217     Vdbe *p,                       /* The VDBE */
 31096  31218     int nVar,                      /* Number of '?' see in the SQL statement */
 31097  31219     int nMem,                      /* Number of memory cells to allocate */
 31098  31220     int nCursor,                   /* Number of cursors to allocate */
 31099  31221     int isExplain                  /* True if the EXPLAIN keywords is present */
 31100  31222   ){
 31101  31223     int n;
................................................................................
 31168  31290     p->errorAction = OE_Abort;
 31169  31291     p->popStack =  0;
 31170  31292     p->explain |= isExplain;
 31171  31293     p->magic = VDBE_MAGIC_RUN;
 31172  31294     p->nChange = 0;
 31173  31295     p->cacheCtr = 1;
 31174  31296     p->minWriteFileFormat = 255;
        31297  +  p->openedStatement = 0;
 31175  31298   #ifdef VDBE_PROFILE
 31176  31299     {
 31177  31300       int i;
 31178  31301       for(i=0; i<p->nOp; i++){
 31179  31302         p->aOp[i].cnt = 0;
 31180  31303         p->aOp[i].cycles = 0;
 31181  31304       }
................................................................................
 31183  31306   #endif
 31184  31307   }
 31185  31308   
 31186  31309   /*
 31187  31310   ** Close a cursor and release all the resources that cursor happens
 31188  31311   ** to hold.
 31189  31312   */
 31190         -static void sqlite3VdbeFreeCursor(Vdbe *p, Cursor *pCx){
        31313  +SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *p, Cursor *pCx){
 31191  31314     if( pCx==0 ){
 31192  31315       return;
 31193  31316     }
 31194  31317     if( pCx->pCursor ){
 31195  31318       sqlite3BtreeCloseCursor(pCx->pCursor);
 31196  31319     }
 31197  31320     if( pCx->pBt ){
................................................................................
 31250  31373       sqliteFree(p->contextStack);
 31251  31374     }
 31252  31375     p->contextStack = 0;
 31253  31376     p->contextStackDepth = 0;
 31254  31377     p->contextStackTop = 0;
 31255  31378     sqliteFree(p->zErrMsg);
 31256  31379     p->zErrMsg = 0;
        31380  +  p->resOnStack = 0;
 31257  31381   }
 31258  31382   
 31259  31383   /*
 31260  31384   ** Set the number of result columns that will be returned by this SQL
 31261  31385   ** statement. This is now set at compile time, rather than during
 31262  31386   ** execution of the vdbe program so that sqlite3_column_count() can
 31263  31387   ** be called on an SQL statement before sqlite3_step().
 31264  31388   */
 31265         -static void sqlite3VdbeSetNumCols(Vdbe *p, int nResColumn){
        31389  +SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe *p, int nResColumn){
 31266  31390     Mem *pColName;
 31267  31391     int n;
 31268  31392     releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
 31269  31393     sqliteFree(p->aColName);
 31270  31394     n = nResColumn*COLNAME_N;
 31271  31395     p->nResColumn = nResColumn;
 31272  31396     p->aColName = pColName = (Mem*)sqliteMalloc( sizeof(Mem)*n );
................................................................................
 31283  31407   ** This call must be made after a call to sqlite3VdbeSetNumCols().
 31284  31408   **
 31285  31409   ** If N==P3_STATIC  it means that zName is a pointer to a constant static
 31286  31410   ** string and we can just copy the pointer. If it is P3_DYNAMIC, then 
 31287  31411   ** the string is freed using sqliteFree() when the vdbe is finished with
 31288  31412   ** it. Otherwise, N bytes of zName are copied.
 31289  31413   */
 31290         -static int sqlite3VdbeSetColName(Vdbe *p, int idx, int var, const char *zName, int N){
        31414  +SQLITE_PRIVATE int sqlite3VdbeSetColName(Vdbe *p, int idx, int var, const char *zName, int N){
 31291  31415     int rc;
 31292  31416     Mem *pColName;
 31293  31417     assert( idx<p->nResColumn );
 31294  31418     assert( var<COLNAME_N );
 31295  31419     if( sqlite3MallocFailed() ) return SQLITE_NOMEM;
 31296  31420     assert( p->aColName!=0 );
 31297  31421     pColName = &(p->aColName[idx+var*p->nResColumn]);
................................................................................
 31551  31675   /*
 31552  31676   ** Find every active VM other than pVdbe and change its status to
 31553  31677   ** aborted.  This happens when one VM causes a rollback due to an
 31554  31678   ** ON CONFLICT ROLLBACK clause (for example).  The other VMs must be
 31555  31679   ** aborted so that they do not have data rolled out from underneath
 31556  31680   ** them leading to a segfault.
 31557  31681   */
 31558         -static void sqlite3AbortOtherActiveVdbes(sqlite3 *db, Vdbe *pExcept){
        31682  +SQLITE_PRIVATE void sqlite3AbortOtherActiveVdbes(sqlite3 *db, Vdbe *pExcept){
 31559  31683     Vdbe *pOther;
 31560  31684     for(pOther=db->pVdbe; pOther; pOther=pOther->pNext){
 31561  31685       if( pOther==pExcept ) continue;
 31562  31686       if( pOther->magic!=VDBE_MAGIC_RUN || pOther->pc<0 ) continue;
 31563  31687       checkActiveVdbeCnt(db);
 31564  31688       closeAllCursors(pOther);
 31565  31689       checkActiveVdbeCnt(db);
................................................................................
 31575  31699   ** This routine is the only way to move the state of a VM from
 31576  31700   ** SQLITE_MAGIC_RUN to SQLITE_MAGIC_HALT.
 31577  31701   **
 31578  31702   ** Return an error code.  If the commit could not complete because of
 31579  31703   ** lock contention, return SQLITE_BUSY.  If SQLITE_BUSY is returned, it
 31580  31704   ** means the close did not happen and needs to be repeated.
 31581  31705   */
 31582         -static int sqlite3VdbeHalt(Vdbe *p){
        31706  +SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe *p){
 31583  31707     sqlite3 *db = p->db;
 31584  31708     int i;
 31585  31709     int (*xFunc)(Btree *pBt) = 0;  /* Function to call on each btree backend */
 31586  31710     int isSpecialError;            /* Set to true if SQLITE_NOMEM or IOERR */
 31587  31711   
 31588  31712     /* This function contains the logic that determines if a statement or
 31589  31713     ** transaction will be committed or rolled back as a result of the
................................................................................
 31716  31840             sqlite3CommitInternalChanges(db);
 31717  31841           }
 31718  31842         }else{
 31719  31843           sqlite3RollbackAll(db);
 31720  31844         }
 31721  31845       }else if( !xFunc ){
 31722  31846         if( p->rc==SQLITE_OK || p->errorAction==OE_Fail ){
 31723         -        xFunc = sqlite3BtreeCommitStmt;
        31847  +        if( p->openedStatement ){
        31848  +          xFunc = sqlite3BtreeCommitStmt;
        31849  +        } 
 31724  31850         }else if( p->errorAction==OE_Abort ){
 31725  31851           xFunc = sqlite3BtreeRollbackStmt;
 31726  31852         }else{
 31727  31853           sqlite3AbortOtherActiveVdbes(db, p);
 31728  31854           sqlite3RollbackAll(db);
 31729  31855           db->autoCommit = 1;
 31730  31856         }
................................................................................
 31780  31906     return SQLITE_OK;
 31781  31907   }
 31782  31908   
 31783  31909   /*
 31784  31910   ** Each VDBE holds the result of the most recent sqlite3_step() call
 31785  31911   ** in p->rc.  This routine sets that result back to SQLITE_OK.
 31786  31912   */
 31787         -static void sqlite3VdbeResetStepResult(Vdbe *p){
        31913  +SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe *p){
 31788  31914     p->rc = SQLITE_OK;
 31789  31915   }
 31790  31916   
 31791  31917   /*
 31792  31918   ** Clean up a VDBE after execution but do not delete the VDBE just yet.
 31793  31919   ** Write any error messages into *pzErrMsg.  Return the result code.
 31794  31920   **
................................................................................
 31795  31921   ** After this routine is run, the VDBE should be ready to be executed
 31796  31922   ** again.
 31797  31923   **
 31798  31924   ** To look at it another way, this routine resets the state of the
 31799  31925   ** virtual machine from VDBE_MAGIC_RUN or VDBE_MAGIC_HALT back to
 31800  31926   ** VDBE_MAGIC_INIT.
 31801  31927   */
 31802         -static int sqlite3VdbeReset(Vdbe *p){
        31928  +SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){
 31803  31929     sqlite3 *db;
 31804  31930     db = p->db;
 31805  31931   
 31806  31932     /* If the VM did not run to completion or if it encountered an
 31807  31933     ** error, then it might not have been halted properly.  So halt
 31808  31934     ** it now.
 31809  31935     */
................................................................................
 31871  31997     return p->rc & db->errMask;
 31872  31998   }
 31873  31999    
 31874  32000   /*
 31875  32001   ** Clean up and delete a VDBE after execution.  Return an integer which is
 31876  32002   ** the result code.  Write any error message text into *pzErrMsg.
 31877  32003   */
 31878         -static int sqlite3VdbeFinalize(Vdbe *p){
        32004  +SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe *p){
 31879  32005     int rc = SQLITE_OK;
 31880  32006     if( p->magic==VDBE_MAGIC_RUN || p->magic==VDBE_MAGIC_HALT ){
 31881  32007       rc = sqlite3VdbeReset(p);
 31882  32008       assert( (rc & p->db->errMask)==rc );
 31883  32009     }else if( p->magic!=VDBE_MAGIC_INIT ){
 31884  32010       return SQLITE_MISUSE;
 31885  32011     }
................................................................................
 31889  32015   
 31890  32016   /*
 31891  32017   ** Call the destructor for each auxdata entry in pVdbeFunc for which
 31892  32018   ** the corresponding bit in mask is clear.  Auxdata entries beyond 31
 31893  32019   ** are always destroyed.  To destroy all auxdata entries, call this
 31894  32020   ** routine with mask==0.
 31895  32021   */
 31896         -static void sqlite3VdbeDeleteAuxData(VdbeFunc *pVdbeFunc, int mask){
        32022  +SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(VdbeFunc *pVdbeFunc, int mask){
 31897  32023     int i;
 31898  32024     for(i=0; i<pVdbeFunc->nAux; i++){
 31899  32025       struct AuxData *pAux = &pVdbeFunc->apAux[i];
 31900  32026       if( (i>31 || !(mask&(1<<i))) && pAux->pAux ){
 31901  32027         if( pAux->xDelete ){
 31902  32028           pAux->xDelete(pAux->pAux);
 31903  32029         }
................................................................................
 31905  32031       }
 31906  32032     }
 31907  32033   }
 31908  32034   
 31909  32035   /*
 31910  32036   ** Delete an entire VDBE.
 31911  32037   */
 31912         -static void sqlite3VdbeDelete(Vdbe *p){
        32038  +SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe *p){
 31913  32039     int i;
 31914  32040     if( p==0 ) return;
 31915  32041     Cleanup(p);
 31916  32042     if( p->pPrev ){
 31917  32043       p->pPrev->pNext = p->pNext;
 31918  32044     }else{
 31919  32045       assert( p->db->pVdbe==p );
................................................................................
 31940  32066   }
 31941  32067   
 31942  32068   /*
 31943  32069   ** If a MoveTo operation is pending on the given cursor, then do that
 31944  32070   ** MoveTo now.  Return an error code.  If no MoveTo is pending, this
 31945  32071   ** routine does nothing and returns SQLITE_OK.
 31946  32072   */
 31947         -static int sqlite3VdbeCursorMoveto(Cursor *p){
        32073  +SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(Cursor *p){
 31948  32074     if( p->deferredMoveto ){
 31949  32075       int res, rc;
 31950  32076   #ifdef SQLITE_TEST
 31951  32077       extern int sqlite3_search_count;
 31952  32078   #endif
 31953  32079       assert( p->isTable );
 31954  32080       rc = sqlite3BtreeMoveto(p->pCursor, 0, p->movetoTarget, 0, &res);
................................................................................
 32010  32136   ** The 8 and 9 types were added in 3.3.0, file format 4.  Prior versions
 32011  32137   ** of SQLite will not understand those serial types.
 32012  32138   */
 32013  32139   
 32014  32140   /*
 32015  32141   ** Return the serial-type for the value stored in pMem.
 32016  32142   */
 32017         -static u32 sqlite3VdbeSerialType(Mem *pMem, int file_format){
        32143  +SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem *pMem, int file_format){
 32018  32144     int flags = pMem->flags;
 32019  32145     int n;
 32020  32146   
 32021  32147     if( flags&MEM_Null ){
 32022  32148       return 0;
 32023  32149     }
 32024  32150     if( flags&MEM_Int ){
................................................................................
 32048  32174     assert( n>=0 );
 32049  32175     return ((n*2) + 12 + ((flags&MEM_Str)!=0));
 32050  32176   }
 32051  32177   
 32052  32178   /*
 32053  32179   ** Return the length of the data corresponding to the supplied serial-type.
 32054  32180   */
 32055         -static int sqlite3VdbeSerialTypeLen(u32 serial_type){
        32181  +SQLITE_PRIVATE int sqlite3VdbeSerialTypeLen(u32 serial_type){
 32056  32182     if( serial_type>=12 ){
 32057  32183       return (serial_type-12)/2;
 32058  32184     }else{
 32059  32185       static const u8 aSize[] = { 0, 1, 2, 3, 4, 6, 8, 8, 0, 0, 0, 0 };
 32060  32186       return aSize[serial_type];
 32061  32187     }
 32062  32188   }
................................................................................
 32115  32241   ** prefix and the tail then write the prefix and set the tail to all
 32116  32242   ** zeros.
 32117  32243   **
 32118  32244   ** Return the number of bytes actually written into buf[].  The number
 32119  32245   ** of bytes in the zero-filled tail is included in the return value only
 32120  32246   ** if those bytes were zeroed in buf[].
 32121  32247   */ 
 32122         -static int sqlite3VdbeSerialPut(u8 *buf, int nBuf, Mem *pMem, int file_format){
        32248  +SQLITE_PRIVATE int sqlite3VdbeSerialPut(u8 *buf, int nBuf, Mem *pMem, int file_format){
 32123  32249     u32 serial_type = sqlite3VdbeSerialType(pMem, file_format);
 32124  32250     int len;
 32125  32251   
 32126  32252     /* Integer and Real */
 32127  32253     if( serial_type<=7 && serial_type>0 ){
 32128  32254       u64 v;
 32129  32255       int i;
................................................................................
 32164  32290     return 0;
 32165  32291   }
 32166  32292   
 32167  32293   /*
 32168  32294   ** Deserialize the data blob pointed to by buf as serial type serial_type
 32169  32295   ** and store the result in pMem.  Return the number of bytes read.
 32170  32296   */ 
 32171         -static int sqlite3VdbeSerialGet(
        32297  +SQLITE_PRIVATE int sqlite3VdbeSerialGet(
 32172  32298     const unsigned char *buf,     /* Buffer to deserialize from */
 32173  32299     u32 serial_type,              /* Serial type to deserialize */
 32174  32300     Mem *pMem                     /* Memory cell to write value into */
 32175  32301   ){
 32176  32302     switch( serial_type ){
 32177  32303       case 10:   /* Reserved for future use */
 32178  32304       case 11:   /* Reserved for future use */
................................................................................
 32281  32407   /*
 32282  32408   ** This function compares the two table rows or index records specified by 
 32283  32409   ** {nKey1, pKey1} and {nKey2, pKey2}, returning a negative, zero
 32284  32410   ** or positive integer if {nKey1, pKey1} is less than, equal to or 
 32285  32411   ** greater than {nKey2, pKey2}.  Both Key1 and Key2 must be byte strings
 32286  32412   ** composed by the OP_MakeRecord opcode of the VDBE.
 32287  32413   */
 32288         -static int sqlite3VdbeRecordCompare(
        32414  +SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
 32289  32415     void *userData,
 32290  32416     int nKey1, const void *pKey1, 
 32291  32417     int nKey2, const void *pKey2
 32292  32418   ){
 32293  32419     KeyInfo *pKeyInfo = (KeyInfo*)userData;
 32294  32420     u32 d1, d2;          /* Offset into aKey[] of next data element */
 32295  32421     u32 idx1, idx2;      /* Offset into aKey[] of next header element */
................................................................................
 32358  32484   
 32359  32485   /*
 32360  32486   ** The argument is an index entry composed using the OP_MakeRecord opcode.
 32361  32487   ** The last entry in this record should be an integer (specifically
 32362  32488   ** an integer rowid).  This routine returns the number of bytes in
 32363  32489   ** that integer.
 32364  32490   */
 32365         -static int sqlite3VdbeIdxRowidLen(const u8 *aKey){
        32491  +SQLITE_PRIVATE int sqlite3VdbeIdxRowidLen(const u8 *aKey){
 32366  32492     u32 szHdr;        /* Size of the header */
 32367  32493     u32 typeRowid;    /* Serial type of the rowid */
 32368  32494   
 32369  32495     sqlite3GetVarint32(aKey, &szHdr);
 32370  32496     sqlite3GetVarint32(&aKey[szHdr-1], &typeRowid);
 32371  32497     return sqlite3VdbeSerialTypeLen(typeRowid);
 32372  32498   }
................................................................................
 32373  32499     
 32374  32500   
 32375  32501   /*
 32376  32502   ** pCur points at an index entry created using the OP_MakeRecord opcode.
 32377  32503   ** Read the rowid (the last field in the record) and store it in *rowid.
 32378  32504   ** Return SQLITE_OK if everything works, or an error code otherwise.
 32379  32505   */
 32380         -static int sqlite3VdbeIdxRowid(BtCursor *pCur, i64 *rowid){
        32506  +SQLITE_PRIVATE int sqlite3VdbeIdxRowid(BtCursor *pCur, i64 *rowid){
 32381  32507     i64 nCellKey = 0;
 32382  32508     int rc;
 32383  32509     u32 szHdr;        /* Size of the header */
 32384  32510     u32 typeRowid;    /* Serial type of the rowid */
 32385  32511     u32 lenRowid;     /* Size of the rowid */
 32386  32512     Mem m, v;
 32387  32513   
................................................................................
 32408  32534   ** that is negative, zero, or positive if pC is less than, equal to,
 32409  32535   ** or greater than pKey.  Return SQLITE_OK on success.
 32410  32536   **
 32411  32537   ** pKey is either created without a rowid or is truncated so that it
 32412  32538   ** omits the rowid at the end.  The rowid at the end of the index entry
 32413  32539   ** is ignored as well.
 32414  32540   */
 32415         -static int sqlite3VdbeIdxKeyCompare(
        32541  +SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(
 32416  32542     Cursor *pC,                 /* The cursor to compare against */
 32417  32543     int nKey, const u8 *pKey,   /* The key to compare */
 32418  32544     int *res                    /* Write the comparison result here */
 32419  32545   ){
 32420  32546     i64 nCellKey = 0;
 32421  32547     int rc;
 32422  32548     BtCursor *pCur = pC->pCursor;
................................................................................
 32438  32564     return SQLITE_OK;
 32439  32565   }
 32440  32566   
 32441  32567   /*
 32442  32568   ** This routine sets the value to be returned by subsequent calls to
 32443  32569   ** sqlite3_changes() on the database handle 'db'. 
 32444  32570   */
 32445         -static void sqlite3VdbeSetChanges(sqlite3 *db, int nChange){
        32571  +SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *db, int nChange){
 32446  32572     db->nChange = nChange;
 32447  32573     db->nTotalChange += nChange;
 32448  32574   }
 32449  32575   
 32450  32576   /*
 32451  32577   ** Set a flag in the vdbe to update the change counter when it is finalised
 32452  32578   ** or reset.
 32453  32579   */
 32454         -static void sqlite3VdbeCountChanges(Vdbe *v){
        32580  +SQLITE_PRIVATE void sqlite3VdbeCountChanges(Vdbe *v){
 32455  32581     v->changeCntOn = 1;
 32456  32582   }
 32457  32583   
 32458  32584   /*
 32459  32585   ** Mark every prepared statement associated with a database connection
 32460  32586   ** as expired.
 32461  32587   **
 32462  32588   ** An expired statement means that recompilation of the statement is
 32463  32589   ** recommend.  Statements expire when things happen that make their
 32464  32590   ** programs obsolete.  Removing user-defined functions or collating
 32465  32591   ** sequences, or changing an authorization function are the types of
 32466  32592   ** things that make prepared statements obsolete.
 32467  32593   */
 32468         -static void sqlite3ExpirePreparedStatements(sqlite3 *db){
        32594  +SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3 *db){
 32469  32595     Vdbe *p;
 32470  32596     for(p = db->pVdbe; p; p=p->pNext){
 32471  32597       p->expired = 1;
 32472  32598     }
 32473  32599   }
 32474  32600   
 32475  32601   /*
 32476  32602   ** Return the database associated with the Vdbe.
 32477  32603   */
 32478         -static sqlite3 *sqlite3VdbeDb(Vdbe *v){
        32604  +SQLITE_PRIVATE sqlite3 *sqlite3VdbeDb(Vdbe *v){
 32479  32605     return v->db;
 32480  32606   }
 32481  32607   
 32482  32608   /************** End of vdbeaux.c *********************************************/
 32483  32609   /************** Begin file vdbeapi.c *****************************************/
 32484  32610   /*
 32485  32611   ** 2004 May 26
................................................................................
 32501  32627   ** Return TRUE (non-zero) of the statement supplied as an argument needs
 32502  32628   ** to be recompiled.  A statement needs to be recompiled whenever the
 32503  32629   ** execution environment changes in a way that would alter the program
 32504  32630   ** that sqlite3_prepare() generates.  For example, if new functions or
 32505  32631   ** collating sequences are registered or if an authorizer function is
 32506  32632   ** added or changed.
 32507  32633   */
 32508         -int sqlite3_expired(sqlite3_stmt *pStmt){
        32634  +SQLITE_API int sqlite3_expired(sqlite3_stmt *pStmt){
 32509  32635     Vdbe *p = (Vdbe*)pStmt;
 32510  32636     return p==0 || p->expired;
 32511  32637   }
 32512  32638   
 32513  32639   /**************************** sqlite3_value_  *******************************
 32514  32640   ** The following routines extract information from a Mem or sqlite3_value
 32515  32641   ** structure.
................................................................................
 32751  32877     sqlite3Error(p->db, rc, 0);
 32752  32878     p->rc = sqlite3ApiExit(p->db, p->rc);
 32753  32879   end_of_step:
 32754  32880     assert( (rc&0xff)==rc );
 32755  32881     if( p->zSql && (rc&0xff)<SQLITE_ROW ){
 32756  32882       /* This behavior occurs if sqlite3_prepare_v2() was used to build
 32757  32883       ** the prepared statement.  Return error codes directly */
        32884  +    sqlite3Error(p->db, p->rc, 0);
 32758  32885       return p->rc;
 32759  32886     }else{
 32760  32887       /* This is for legacy sqlite3_prepare() builds and when the code
 32761  32888       ** is SQLITE_ROW or SQLITE_DONE */
 32762  32889       return rc;
 32763  32890     }
 32764  32891   }
................................................................................
 32765  32892   
 32766  32893   /*
 32767  32894   ** This is the top-level implementation of sqlite3_step().  Call
 32768  32895   ** sqlite3Step() to do most of the work.  If a schema error occurs,
 32769  32896   ** call sqlite3Reprepare() and try again.
 32770  32897   */
 32771  32898   #ifdef SQLITE_OMIT_PARSER
 32772         -int sqlite3_step(sqlite3_stmt *pStmt){
        32899  +SQLITE_API int sqlite3_step(sqlite3_stmt *pStmt){
 32773  32900     return sqlite3Step((Vdbe*)pStmt);
 32774  32901   }
 32775  32902   #else
 32776         -int sqlite3_step(sqlite3_stmt *pStmt){
        32903  +SQLITE_API int sqlite3_step(sqlite3_stmt *pStmt){
 32777  32904     int cnt = 0;
 32778  32905     int rc;
 32779  32906     Vdbe *v = (Vdbe*)pStmt;
 32780  32907     while( (rc = sqlite3Step(v))==SQLITE_SCHEMA
 32781  32908            && cnt++ < 5
 32782  32909            && sqlite3Reprepare(v) ){
 32783  32910       sqlite3_reset(pStmt);
................................................................................
 32800  32927   ** The following is the implementation of an SQL function that always
 32801  32928   ** fails with an error message stating that the function is used in the
 32802  32929   ** wrong context.  The sqlite3_overload_function() API might construct
 32803  32930   ** SQL function that use this routine so that the functions will exist
 32804  32931   ** for name resolution but are actually overloaded by the xFindFunction
 32805  32932   ** method of virtual tables.
 32806  32933   */
 32807         -static void sqlite3InvalidFunction(
        32934  +SQLITE_PRIVATE void sqlite3InvalidFunction(
 32808  32935     sqlite3_context *context,  /* The function calling context */
 32809  32936     int argc,                  /* Number of arguments to the function */
 32810  32937     sqlite3_value **argv       /* Value of each argument */
 32811  32938   ){
 32812  32939     const char *zName = context->pFunc->zName;
 32813  32940     char *zErr;
 32814  32941     zErr = sqlite3MPrintf(
................................................................................
 32929  33056   ** it is, return a pointer to the Mem for the value of that column.
 32930  33057   ** If iCol is not valid, return a pointer to a Mem which has a value
 32931  33058   ** of NULL.
 32932  33059   */
 32933  33060   static Mem *columnMem(sqlite3_stmt *pStmt, int i){
 32934  33061     Vdbe *pVm = (Vdbe *)pStmt;
 32935  33062     int vals = sqlite3_data_count(pStmt);
 32936         -  if( i>=vals || i<0 ){
        33063  +  if( pVm==0 || pVm->resOnStack==0 || i>=pVm->nResColumn || i<0 ){
 32937  33064       static const Mem nullMem = {{0}, 0.0, "", 0, MEM_Null, SQLITE_NULL };
 32938  33065       sqlite3Error(pVm->db, SQLITE_RANGE, 0);
 32939  33066       return (Mem*)&nullMem;
 32940  33067     }
 32941  33068     return &pVm->pTos[(1-vals)+i];
 32942  33069   }
 32943  33070   
................................................................................
 33435  33562   **
 33436  33563   ** Various scripts scan this source file in order to generate HTML
 33437  33564   ** documentation, headers files, or other derived files.  The formatting
 33438  33565   ** of the code in this file is, therefore, important.  See other comments
 33439  33566   ** in this file for details.  If in doubt, do not deviate from existing
 33440  33567   ** commenting and indentation practices when changing or adding code.
 33441  33568   **
 33442         -** $Id: sqlite3.c,v 1.3 2007/06/19 22:43:23 rmsimpson Exp $
        33569  +** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
 33443  33570   */
 33444  33571   
 33445  33572   /*
 33446  33573   ** The following global variable is incremented every time a cursor
 33447  33574   ** moves, either by the OP_MoveXX, OP_Next, or OP_Prev opcodes.  The test
 33448  33575   ** procedures use this information to make sure that indices are
 33449  33576   ** working correctly.  This variable has no function other than to
................................................................................
 33682  33809     return pMem->type;
 33683  33810   }
 33684  33811   
 33685  33812   /*
 33686  33813   ** Exported version of applyAffinity(). This one works on sqlite3_value*, 
 33687  33814   ** not the internal Mem* type.
 33688  33815   */
 33689         -static void sqlite3ValueApplyAffinity(sqlite3_value *pVal, u8 affinity, u8 enc){
        33816  +SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *pVal, u8 affinity, u8 enc){
 33690  33817     applyAffinity((Mem *)pVal, affinity, enc);
 33691  33818   }
 33692  33819   
 33693  33820   #ifdef SQLITE_DEBUG
 33694  33821   /*
 33695  33822   ** Write a nice string representation of the contents of cell pMem
 33696  33823   ** into buffer zBuf, length nBuf.
 33697  33824   */
 33698         -static void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf){
        33825  +SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf){
 33699  33826     char *zCsr = zBuf;
 33700  33827     int f = pMem->flags;
 33701  33828   
 33702  33829     static const char *const encnames[] = {"(X)", "(8)", "(16LE)", "(16BE)"};
 33703  33830   
 33704  33831     if( f&MEM_Blob ){
 33705  33832       int i;
................................................................................
 33831  33958   ** routine to return SQLITE_ERROR.
 33832  33959   **
 33833  33960   ** Other fatal errors return SQLITE_ERROR.
 33834  33961   **
 33835  33962   ** After this routine has finished, sqlite3VdbeFinalize() should be
 33836  33963   ** used to clean up the mess that was left behind.
 33837  33964   */
 33838         -static int sqlite3VdbeExec(
        33965  +SQLITE_PRIVATE int sqlite3VdbeExec(
 33839  33966     Vdbe *p                    /* The VDBE */
 33840  33967   ){
 33841  33968     int pc;                    /* The program counter */
 33842  33969     Op *pOp;                   /* Current operation */
 33843  33970     int rc = SQLITE_OK;        /* Value to return */
 33844  33971     sqlite3 *db = p->db;       /* The database */
 33845  33972     u8 encoding = ENC(db);     /* The database encoding */
................................................................................
 34540  34667       b = pNos->u.i;
 34541  34668       switch( pOp->opcode ){
 34542  34669         case OP_Add:         b += a;       break;
 34543  34670         case OP_Subtract:    b -= a;       break;
 34544  34671         case OP_Multiply:    b *= a;       break;
 34545  34672         case OP_Divide: {
 34546  34673           if( a==0 ) goto divide_by_zero;
        34674  +        /* Dividing the largest possible negative 64-bit integer (1<<63) by 
        34675  +        ** -1 returns an integer to large to store in a 64-bit data-type. On
        34676  +        ** some architectures, the value overflows to (1<<63). On others,
        34677  +        ** a SIGFPE is issued. The following statement normalizes this
        34678  +        ** behaviour so that all architectures behave as if integer 
        34679  +        ** overflow occured.
        34680  +        */
        34681  +        if( a==-1 && b==(((i64)1)<<63) ) a = 1;
 34547  34682           b /= a;
 34548  34683           break;
 34549  34684         }
 34550  34685         default: {
 34551  34686           if( a==0 ) goto divide_by_zero;
        34687  +        if( a==-1 ) a = 1;
 34552  34688           b %= a;
 34553  34689           break;
 34554  34690         }
 34555  34691       }
 34556  34692       Release(pTos);
 34557  34693       pTos--;
 34558  34694       Release(pTos);
................................................................................
 34571  34707           b /= a;
 34572  34708           break;
 34573  34709         }
 34574  34710         default: {
 34575  34711           i64 ia = (i64)a;
 34576  34712           i64 ib = (i64)b;
 34577  34713           if( ia==0 ) goto divide_by_zero;
        34714  +        if( ia==-1 ) ia = 1;
 34578  34715           b = ib % ia;
 34579  34716           break;
 34580  34717         }
 34581  34718       }
 34582         -    if( isnan(b) ){
        34719  +    if( sqlite3_isnan(b) ){
 34583  34720         goto divide_by_zero;
 34584  34721       }
 34585  34722       Release(pTos);
 34586  34723       pTos--;
 34587  34724       Release(pTos);
 34588  34725       pTos->r = b;
 34589  34726       pTos->flags = MEM_Real;
................................................................................
 35785  35922   case OP_Statement: {       /* no-push */
 35786  35923     int i = pOp->p1;
 35787  35924     Btree *pBt;
 35788  35925     if( i>=0 && i<db->nDb && (pBt = db->aDb[i].pBt)!=0 && !(db->autoCommit) ){
 35789  35926       assert( sqlite3BtreeIsInTrans(pBt) );
 35790  35927       if( !sqlite3BtreeIsInStmt(pBt) ){
 35791  35928         rc = sqlite3BtreeBeginStmt(pBt);
        35929  +      p->openedStatement = 1;
 35792  35930       }
 35793  35931     }
 35794  35932     break;
 35795  35933   }
 35796  35934   
 35797  35935   /* Opcode: AutoCommit P1 P2 *
 35798  35936   **
................................................................................
 35896  36034   **
 35897  36035   ** Read cookie number P2 from database P1 and push it onto the stack.
 35898  36036   ** P2==0 is the schema version.  P2==1 is the database format.
 35899  36037   ** P2==2 is the recommended pager cache size, and so forth.  P1==0 is
 35900  36038   ** the main database file and P1==1 is the database file used to store
 35901  36039   ** temporary tables.
 35902  36040   **
        36041  +** If P1 is negative, then this is a request to read the size of a
        36042  +** databases free-list. P2 must be set to 1 in this case. The actual
        36043  +** database accessed is ((P1+1)*-1). For example, a P1 parameter of -1
        36044  +** corresponds to database 0 ("main"), a P1 of -2 is database 1 ("temp").
        36045  +**
 35903  36046   ** There must be a read-lock on the database (either a transaction
 35904  36047   ** must be started or there must be an open cursor) before
 35905  36048   ** executing this instruction.
 35906  36049   */
 35907  36050   case OP_ReadCookie: {
 35908  36051     int iMeta;
        36052  +  int iDb = pOp->p1;
        36053  +  int iCookie = pOp->p2;
        36054  +
 35909  36055     assert( pOp->p2<SQLITE_N_BTREE_META );
 35910         -  assert( pOp->p1>=0 && pOp->p1<db->nDb );
 35911         -  assert( db->aDb[pOp->p1].pBt!=0 );
        36056  +  if( iDb<0 ){
        36057  +    iDb = (-1*(iDb+1));
        36058  +    iCookie *= -1;
        36059  +  }
        36060  +  assert( iDb>=0 && iDb<db->nDb );
        36061  +  assert( db->aDb[iDb].pBt!=0 );
 35912  36062     /* The indexing of meta values at the schema layer is off by one from
 35913  36063     ** the indexing in the btree layer.  The btree considers meta[0] to
 35914  36064     ** be the number of free pages in the database (a read-only value)
 35915  36065     ** and meta[1] to be the schema cookie.  The schema layer considers
 35916  36066     ** meta[1] to be the schema cookie.  So we have to shift the index
 35917  36067     ** by one in the following statement.
 35918  36068     */
 35919         -  rc = sqlite3BtreeGetMeta(db->aDb[pOp->p1].pBt, 1 + pOp->p2, (u32 *)&iMeta);
        36069  +  rc = sqlite3BtreeGetMeta(db->aDb[iDb].pBt, 1 + iCookie, (u32 *)&iMeta);
 35920  36070     pTos++;
 35921  36071     pTos->u.i = iMeta;
 35922  36072     pTos->flags = MEM_Int;
 35923  36073     break;
 35924  36074   }
 35925  36075   
 35926  36076   /* Opcode: SetCookie P1 P2 *
................................................................................
 37670  37820     aRoot = sqliteMallocRaw( sizeof(int*)*(nRoot+1) );
 37671  37821     if( aRoot==0 ) goto no_mem;
 37672  37822     j = pOp->p1;
 37673  37823     assert( j>=0 && j<p->nMem );
 37674  37824     pnErr = &p->aMem[j];
 37675  37825     assert( (pnErr->flags & MEM_Int)!=0 );
 37676  37826     for(j=0; j<nRoot; j++){
 37677         -    Mem *pMem = &pTos[-j];
 37678         -    aRoot[j] = pMem->u.i;
        37827  +    aRoot[j] = pTos[-j].u.i;
 37679  37828     }
 37680  37829     aRoot[j] = 0;
 37681  37830     popStack(&pTos, nRoot);
 37682  37831     pTos++;
 37683  37832     z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p2].pBt, aRoot, nRoot,
 37684  37833                                    pnErr->u.i, &nErr);
 37685  37834     pnErr->u.i -= nErr;
................................................................................
 38364  38513       }
 38365  38514     }
 38366  38515   
 38367  38516     break;
 38368  38517   }
 38369  38518   #endif /* SQLITE_OMIT_VIRTUALTABLE */
 38370  38519   
        38520  +#ifndef SQLITE_OMIT_VIRTUALTABLE
        38521  +/* Opcode: VRename * * P3
        38522  +**
        38523  +** P3 is a pointer to a virtual table object, an sqlite3_vtab structure.
        38524  +** This opcode invokes the corresponding xRename method. The value
        38525  +** on the top of the stack is popped and passed as the zName argument
        38526  +** to the xRename method.
        38527  +*/
        38528  +case OP_VRename: {   /* no-push */
        38529  +  sqlite3_vtab *pVtab = (sqlite3_vtab *)(pOp->p3);
        38530  +  assert( pVtab->pModule->xRename );
        38531  +
        38532  +  Stringify(pTos, encoding);
        38533  +
        38534  +  if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse;
        38535  +  sqlite3VtabLock(pVtab);
        38536  +  rc = pVtab->pModule->xRename(pVtab, pTos->z);
        38537  +  sqlite3VtabUnlock(db, pVtab);
        38538  +  if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse;
        38539  +
        38540  +  popStack(&pTos, 1);
        38541  +  break;
        38542  +}
        38543  +#endif
 38371  38544   
 38372  38545   #ifndef SQLITE_OMIT_VIRTUALTABLE
 38373  38546   /* Opcode: VUpdate P1 P2 P3
 38374  38547   **
 38375  38548   ** P3 is a pointer to a virtual table object, an sqlite3_vtab structure.
 38376  38549   ** This opcode invokes the corresponding xUpdate method. P2 values
 38377  38550   ** are taken from the stack to pass to the xUpdate invocation. The
................................................................................
 38581  38754   **    May you find forgiveness for yourself and forgive others.
 38582  38755   **    May you share freely, never taking more than you give.
 38583  38756   **
 38584  38757   *************************************************************************
 38585  38758   **
 38586  38759   ** This file contains code used to implement incremental BLOB I/O.
 38587  38760   **
 38588         -** $Id: sqlite3.c,v 1.3 2007/06/19 22:43:23 rmsimpson Exp $
        38761  +** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
 38589  38762   */
 38590  38763   
 38591  38764   
 38592  38765   #ifndef SQLITE_OMIT_INCRBLOB
 38593  38766   
 38594  38767   /*
 38595  38768   ** Valid sqlite3_blob* handles point to Incrblob structures.
................................................................................
 38845  39018     */
 38846  39019     db = v->db;
 38847  39020     rc = xCall(p->pCsr, iOffset+p->iOffset, n, z);
 38848  39021     if( rc==SQLITE_ABORT ){
 38849  39022       sqlite3VdbeFinalize(v);
 38850  39023       p->pStmt = 0;
 38851  39024     }else{
        39025  +    db->errCode = rc;
 38852  39026       v->rc = rc;
 38853  39027     }
 38854  39028   
 38855  39029     return sqlite3ApiExit(db, rc);
 38856  39030   }
 38857  39031   
 38858  39032   /*
................................................................................
 38891  39065   **    May you find forgiveness for yourself and forgive others.
 38892  39066   **    May you share freely, never taking more than you give.
 38893  39067   **
 38894  39068   *************************************************************************
 38895  39069   ** This file contains routines used for analyzing expressions and
 38896  39070   ** for generating VDBE code that evaluates expressions in SQLite.
 38897  39071   **
 38898         -** $Id: sqlite3.c,v 1.3 2007/06/19 22:43:23 rmsimpson Exp $
        39072  +** $Id: sqlite3.c,v 1.4 2007/07/21 08:51:43 rmsimpson Exp $
 38899  39073   */
 38900  39074   
 38901  39075   /*
 38902  39076   ** Return the 'affinity' of the expression pExpr if any.
 38903  39077   **
 38904  39078   ** If pExpr is a column, a reference to a column via an 'AS' alias,
 38905  39079   ** or a sub-select with a column as the return value, then the 
................................................................................
 38910  39084   ** have an affinity:
 38911  39085   **
 38912  39086   ** CREATE TABLE t1(a);
 38913  39087   ** SELECT * FROM t1 WHERE a;
 38914  39088   ** SELECT a AS b FROM t1 WHERE b;
 38915  39089   ** SELECT * FROM t1 WHERE (select a from t1);
 38916  39090   */
 38917         -static char sqlite3ExprAffinity(Expr *pExpr){
        39091  +SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr){
 38918  39092     int op = pExpr->op;
 38919  39093     if( op==TK_SELECT ){
 38920  39094       return sqlite3ExprAffinity(pExpr->pSelect->pEList->a[0].pExpr);
 38921  39095     }
 38922  39096   #ifndef SQLITE_OMIT_CAST
 38923  39097     if( op==TK_CAST ){
 38924  39098       return sqlite3AffinityType(&pExpr->token);
................................................................................
 38930  39104   /*
 38931  39105   ** Set the collating sequence for expression pExpr to be the collating
 38932  39106   ** sequence named by pToken.   Return a pointer to the revised expression.
 38933  39107   ** The collating sequence is marked as "explicit" using the EP_ExpCollate
 38934  39108   ** flag.  An explicit collating sequence will override implicit
 38935  39109   ** collating sequences.
 38936  39110   */
 38937         -static Expr *sqlite3ExprSetColl(Parse *pParse, Expr *pExpr, Token *pName){
        39111  +SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Parse *pParse, Expr *pExpr, Token *pName){
 38938  39112     CollSeq *pColl;
 38939  39113     if( pExpr==0 ) return 0;
 38940  39114     pColl = sqlite3LocateCollSeq(pParse, (char*)pName->z, pName->n);
 38941  39115     if( pColl ){
 38942  39116       pExpr->pColl = pColl;
 38943  39117       pExpr->flags |= EP_ExpCollate;
 38944  39118     }
................................................................................
 38945  39119     return pExpr;
 38946  39120   }
 38947  39121   
 38948  39122   /*
 38949  39123   ** Return the default collation sequence for the expression pExpr. If
 38950  39124   ** there is no default collation type, return 0.
 38951  39125   */
 38952         -static CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr){
        39126  +SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr){
 38953  39127     CollSeq *pColl = 0;
 38954  39128     if( pExpr ){
        39129  +    int op;
 38955  39130       pColl = pExpr->pColl;
 38956         -    if( pExpr->op==TK_CAST && !pColl ){
        39131  +    op = pExpr->op;
        39132  +    if( (op==TK_CAST || op==TK_UPLUS) && !pColl ){
 38957  39133         return sqlite3ExprCollSeq(pParse, pExpr->pLeft);
 38958  39134       }
 38959  39135     }
 38960  39136     if( sqlite3CheckCollSeq(pParse, pColl) ){ 
 38961  39137       pColl = 0;
 38962  39138     }
 38963  39139     return pColl;
................................................................................
 38964  39140   }
 38965  39141   
 38966  39142   /*
 38967  39143   ** pExpr is an operand of a comparison operator.  aff2 is the
 38968  39144   ** type affinity of the other operand.  This routine returns the
 38969  39145   ** type affinity that should be used for the comparison operator.
 38970  39146   */
 38971         -static char sqlite3CompareAffinity(Expr *pExpr, char aff2){
        39147  +SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2){
 38972  39148     char aff1 = sqlite3ExprAffinity(pExpr);
 38973  39149     if( aff1 && aff2 ){
 38974  39150       /* Both sides of the comparison are columns. If one has numeric
 38975  39151       ** affinity, use that. Otherwise use no affinity.
 38976  39152       */
 38977  39153       if( sqlite3IsNumericAffinity(aff1) || sqlite3IsNumericAffinity(aff2) ){
 38978  39154         return SQLITE_AFF_NUMERIC;
................................................................................
 39016  39192   
 39017  39193   /*
 39018  39194   ** pExpr is a comparison expression, eg. '=', '<', IN(...) etc.
 39019  39195   ** idx_affinity is the affinity of an indexed column. Return true
 39020  39196   ** if the index with affinity idx_affinity may be used to implement
 39021  39197   ** the comparison in pExpr.
 39022  39198   */
 39023         -static int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity){
        39199  +SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity){
 39024  39200     char aff = comparisonAffinity(pExpr);
 39025  39201     switch( aff ){
 39026  39202       case SQLITE_AFF_NONE:
 39027  39203         return 1;
 39028  39204       case SQLITE_AFF_TEXT:
 39029  39205         return idx_affinity==SQLITE_AFF_TEXT;
 39030  39206       default:
................................................................................
 39095  39271   }
 39096  39272   
 39097  39273   /*
 39098  39274   ** Construct a new expression node and return a pointer to it.  Memory
 39099  39275   ** for this node is obtained from sqliteMalloc().  The calling function
 39100  39276   ** is responsible for making sure the node eventually gets freed.
 39101  39277   */
 39102         -static Expr *sqlite3Expr(int op, Expr *pLeft, Expr *pRight, const Token *pToken){
        39278  +SQLITE_PRIVATE Expr *sqlite3Expr(int op, Expr *pLeft, Expr *pRight, const Token *pToken){
 39103  39279     Expr *pNew;
 39104  39280     pNew = sqliteMalloc( sizeof(Expr) );
 39105  39281     if( pNew==0 ){
 39106  39282       /* When malloc fails, delete pLeft and pRight. Expressions passed to 
 39107  39283       ** this function must always be allocated with sqlite3Expr() for this 
 39108  39284       ** reason. 
 39109  39285       */
................................................................................
 39136  39312     return pNew;
 39137  39313   }
 39138  39314   
 39139  39315   /*
 39140  39316   ** Works like sqlite3Expr() but frees its pLeft and pRight arguments
 39141  39317   ** if it fails due to a malloc problem.
 39142  39318   */
 39143         -static Expr *sqlite3ExprOrFree(int op, Expr *pLeft, Expr *pRight, const Token *pToken){
        39319  +SQLITE_PRIVATE Expr *sqlite3ExprOrFree(int op, Expr *pLeft, Expr *pRight, const Token *pToken){
 39144  39320     Expr *pNew = sqlite3Expr(op, pLeft, pRight, pToken);
 39145  39321     if( pNew==0 ){
 39146  39322       sqlite3ExprDelete(pLeft);
 39147  39323       sqlite3ExprDelete(pRight);
 39148  39324     }
 39149  39325     return pNew;
 39150  39326   }
................................................................................
 39156  39332   ** "#1" means the next down on the stack.  And so forth.
 39157  39333   **
 39158  39334   ** This routine is called by the parser to deal with on of those terms.
 39159  39335   ** It immediately generates code to store the value in a memory location.
 39160  39336   ** The returns an expression that will code to extract the value from
 39161  39337   ** that memory location as needed.
 39162  39338   */
 39163         -static Expr *sqlite3RegisterExpr(Parse *pParse, Token *pToken){
        39339  +SQLITE_PRIVATE Expr *sqlite3RegisterExpr(Parse *pParse, Token *pToken){
 39164  39340     Vdbe *v = pParse->pVdbe;
 39165  39341     Expr *p;
 39166  39342     int depth;
 39167  39343     if( pParse->nested==0 ){
 39168  39344       sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", pToken);
 39169  39345       return sqlite3Expr(TK_NULL, 0, 0, 0);
 39170  39346     }
................................................................................
 39180  39356     return p;
 39181  39357   }
 39182  39358   
 39183  39359   /*
 39184  39360   ** Join two expressions using an AND operator.  If either expression is
 39185  39361   ** NULL, then just return the other expression.
 39186  39362   */
 39187         -static Expr *sqlite3ExprAnd(Expr *pLeft, Expr *pRight){
        39363  +SQLITE_PRIVATE Expr *sqlite3ExprAnd(Expr *pLeft, Expr *pRight){
 39188  39364     if( pLeft==0 ){
 39189  39365       return pRight;
 39190  39366     }else if( pRight==0 ){
 39191  39367       return pLeft;
 39192  39368     }else{
 39193  39369       return sqlite3Expr(TK_AND, pLeft, pRight, 0);
 39194  39370     }
 39195  39371   }
 39196  39372   
 39197  39373   /*
 39198  39374   ** Set the Expr.span field of the given expression to span all
 39199  39375   ** text between the two given tokens.
 39200  39376   */
 39201         -static void sqlite3ExprSpan(Expr *pExpr, Token *pLeft, Token *pRight){
        39377  +SQLITE_PRIVATE void sqlite3ExprSpan(Expr *pExpr, Token *pLeft, Token *pRight){
 39202  39378     assert( pRight!=0 );
 39203  39379     assert( pLeft!=0 );
 39204  39380     if( !sqlite3MallocFailed() && pRight->z && pLeft->z ){
 39205  39381       assert( pLeft->dyn==0 || pLeft->z[pLeft->n]==0 );
 39206  39382       if( pLeft->dyn==0 && pRight->dyn==0 ){
 39207  39383         pExpr->span.z = pLeft->z;
 39208  39384         pExpr->span.n = pRight->n + (pRight->z - pLeft->z);
................................................................................
 39212  39388     }
 39213  39389   }
 39214  39390   
 39215  39391   /*
 39216  39392   ** Construct a new expression node for a function with multiple
 39217  39393   ** arguments.
 39218  39394   */
 39219         -static Expr *sqlite3ExprFunction(ExprList *pList, Token *pToken){
        39395  +SQLITE_PRIVATE Expr *sqlite3ExprFunction(ExprList *pList, Token *pToken){
 39220  39396     Expr *pNew;
 39221  39397     assert( pToken );
 39222  39398     pNew = sqliteMalloc( sizeof(Expr) );
 39223  39399     if( pNew==0 ){
 39224  39400       sqlite3ExprListDelete(pList); /* Avoid leaking memory when malloc fails */
 39225  39401       return 0;
 39226  39402     }
................................................................................
 39246  39422   ** the SQL statement comes from an external source.
 39247  39423   **
 39248  39424   ** Wildcards of the form ":aaa" or "$aaa" are assigned the same number
 39249  39425   ** as the previous instance of the same wildcard.  Or if this is the first
 39250  39426   ** instance of the wildcard, the next sequenial variable number is
 39251  39427   ** assigned.
 39252  39428   */
 39253         -static void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
        39429  +SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
 39254  39430     Token *pToken;
 39255  39431     if( pExpr==0 ) return;
 39256  39432     pToken = &pExpr->token;
 39257  39433     assert( pToken->n>=1 );
 39258  39434     assert( pToken->z!=0 );
 39259  39435     assert( pToken->z[0]!=0 );
 39260  39436     if( pToken->n==1 ){
................................................................................
 39305  39481       sqlite3ErrorMsg(pParse, "too many SQL variables");
 39306  39482     }
 39307  39483   }
 39308  39484   
 39309  39485   /*
 39310  39486   ** Recursively delete an expression tree.
 39311  39487   */
 39312         -static void sqlite3ExprDelete(Expr *p){
        39488  +SQLITE_PRIVATE void sqlite3ExprDelete(Expr *p){
 39313  39489     if( p==0 ) return;
 39314  39490     if( p->span.dyn ) sqliteFree((char*)p->span.z);
 39315  39491     if( p->token.dyn ) sqliteFree((char*)p->token.z);
 39316  39492     sqlite3ExprDelete(p->pLeft);
 39317  39493     sqlite3ExprDelete(p->pRight);
 39318  39494     sqlite3ExprListDelete(p->pList);
 39319  39495     sqlite3SelectDelete(p->pSelect);
................................................................................
 39320  39496     sqliteFree(p);
 39321  39497   }
 39322  39498   
 39323  39499   /*
 39324  39500   ** The Expr.token field might be a string literal that is quoted.
 39325  39501   ** If so, remove the quotation marks.
 39326  39502   */
 39327         -static void sqlite3DequoteExpr(Expr *p){
        39503  +SQLITE_PRIVATE void sqlite3DequoteExpr(Expr *p){
 39328  39504     if( ExprHasAnyProperty(p, EP_Dequoted) ){
 39329  39505       return;
 39330  39506     }
 39331  39507     ExprSetProperty(p, EP_Dequoted);
 39332  39508     if( p->token.dyn==0 ){
 39333  39509       sqlite3TokenCopy(&p->token, &p->token);
 39334  39510     }
................................................................................
 39344  39520   **
 39345  39521   ** The expression list, ID, and source lists return by sqlite3ExprListDup(),
 39346  39522   ** sqlite3IdListDup(), and sqlite3SrcListDup() can not be further expanded 
 39347  39523   ** by subsequent calls to sqlite*ListAppend() routines.
 39348  39524   **
 39349  39525   ** Any tables that the SrcList might point to are not duplicated.
 39350  39526   */
 39351         -static Expr *sqlite3ExprDup(Expr *p){
        39527  +SQLITE_PRIVATE Expr *sqlite3ExprDup(Expr *p){
 39352  39528     Expr *pNew;
 39353  39529     if( p==0 ) return 0;
 39354  39530     pNew = sqliteMallocRaw( sizeof(*p) );
 39355  39531     if( pNew==0 ) return 0;
 39356  39532     memcpy(pNew, p, sizeof(*pNew));
 39357  39533     if( p->token.z!=0 ){
 39358  39534       pNew->token.z = (u8*)sqliteStrNDup((char*)p->token.z, p->token.n);
................................................................................
 39363  39539     pNew->span.z = 0;
 39364  39540     pNew->pLeft = sqlite3ExprDup(p->pLeft);
 39365  39541     pNew->pRight = sqlite3ExprDup(p->pRight);
 39366  39542     pNew->pList = sqlite3ExprListDup(p->pList);
 39367  39543     pNew->pSelect = sqlite3SelectDup(p->pSelect);
 39368  39544     return pNew;
 39369  39545   }
 39370         -static void sqlite3TokenCopy(Token *pTo, Token *pFrom){
        39546  +SQLITE_PRIVATE void sqlite3TokenCopy(Token *pTo, Token *pFrom){
 39371  39547     if( pTo->dyn ) sqliteFree((char*)pTo->z);
 39372  39548     if( pFrom->z ){
 39373  39549       pTo->n = pFrom->n;
 39374  39550       pTo->z = (u8*)sqliteStrNDup((char*)pFrom->z, pFrom->n);
 39375  39551       pTo->dyn = 1;
 39376  39552     }else{
 39377  39553       pTo->z = 0;
 39378  39554     }
 39379  39555   }
 39380         -static ExprList *sqlite3ExprListDup(ExprList *p){
        39556  +SQLITE_PRIVATE ExprList *sqlite3ExprListDup(ExprList *p){
 39381  39557     ExprList *pNew;
 39382  39558     struct ExprList_item *pItem, *pOldItem;
 39383  39559     int i;
 39384  39560     if( p==0 ) return 0;
 39385  39561     pNew = sqliteMalloc( sizeof(*pNew) );
 39386  39562     if( pNew==0 ) return 0;
 39387  39563     pNew->nExpr = pNew->nAlloc = p->nExpr;
................................................................................
 39415  39591   ** If cursors, triggers, views and subqueries are all omitted from
 39416  39592   ** the build, then none of the following routines, except for 
 39417  39593   ** sqlite3SelectDup(), can be called. sqlite3SelectDup() is sometimes
 39418  39594   ** called with a NULL argument.
 39419  39595   */
 39420  39596   #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER) \
 39421  39597    || !defined(SQLITE_OMIT_SUBQUERY)
 39422         -static SrcList *sqlite3SrcListDup(SrcList *p){
        39598  +SQLITE_PRIVATE SrcList *sqlite3SrcListDup(SrcList *p){
 39423  39599     SrcList *pNew;
 39424  39600     int i;
 39425  39601     int nByte;
 39426  39602     if( p==0 ) return 0;
 39427  39603     nByte = sizeof(*p) + (p->nSrc>0 ? sizeof(p->a[0]) * (p->nSrc-1) : 0);
 39428  39604     pNew = sqliteMallocRaw( nByte );
 39429  39605     if( pNew==0 ) return 0;
................................................................................
 39445  39621       pNewItem->pSelect = sqlite3SelectDup(pOldItem->pSelect);
 39446  39622       pNewItem->pOn = sqlite3ExprDup(pOldItem->pOn);
 39447  39623       pNewItem->pUsing = sqlite3IdListDup(pOldItem->pUsing);
 39448  39624       pNewItem->colUsed = pOldItem->colUsed;
 39449  39625     }
 39450  39626     return pNew;
 39451  39627   }
 39452         -static IdList *sqlite3IdListDup(IdList *p){
        39628  +SQLITE_PRIVATE IdList *sqlite3IdListDup(IdList *p){
 39453  39629     IdList *pNew;
 39454  39630     int i;
 39455  39631     if( p==0 ) return 0;
 39456  39632     pNew = sqliteMallocRaw( sizeof(*pNew) );
 39457  39633     if( pNew==0 ) return 0;
 39458  39634     pNew->nId = pNew->nAlloc = p->nId;
 39459  39635     pNew->a = sqliteMallocRaw( p->nId*sizeof(p->a[0]) );
................................................................................
 39465  39641       struct IdList_item *pNewItem = &pNew->a[i];
 39466  39642       struct IdList_item *pOldItem = &p->a[i];
 39467  39643       pNewItem->zName = sqliteStrDup(pOldItem->zName);
 39468  39644       pNewItem->idx = pOldItem->idx;
 39469  39645     }
 39470  39646     return pNew;
 39471  39647   }
 39472         -static Select *sqlite3SelectDup(Select *p){
        39648  +SQLITE_PRIVATE Select *sqlite3SelectDup(Select *p){
 39473  39649     Select *pNew;
 39474  39650     if( p==0 ) return 0;
 39475  39651     pNew = sqliteMallocRaw( sizeof(*p) );
 39476  39652     if( pNew==0 ) return 0;
 39477  39653     pNew->isDistinct = p->isDistinct;
 39478  39654     pNew->pEList = sqlite3ExprListDup(p->pEList);
 39479  39655     pNew->pSrc = sqlite3SrcListDup(p->pSrc);
................................................................................
 39494  39670     pNew->pRightmost = 0;
 39495  39671     pNew->addrOpenEphm[0] = -1;
 39496  39672     pNew->addrOpenEphm[1] = -1;
 39497  39673     pNew->addrOpenEphm[2] = -1;
 39498  39674     return pNew;
 39499  39675   }
 39500  39676   #else
 39501         -static Select *sqlite3SelectDup(Select *p){
        39677  +SQLITE_PRIVATE Select *sqlite3SelectDup(Select *p){
 39502  39678     assert( p==0 );
 39503  39679     return 0;
 39504  39680   }
 39505  39681   #endif
 39506  39682   
 39507  39683   
 39508  39684   /*
 39509  39685   ** Add a new element to the end of an expression list.  If pList is
 39510  39686   ** initially NULL, then create a new expression list.
 39511  39687   */
 39512         -static ExprList *sqlite3ExprListAppend(ExprList *pList, Expr *pExpr, Token *pName){
        39688  +SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(ExprList *pList, Expr *pExpr, Token *pName){
 39513  39689     if( pList==0 ){
 39514  39690       pList = sqliteMalloc( sizeof(ExprList) );
 39515  39691       if( pList==0 ){
 39516  39692         goto no_mem;
 39517  39693       }
 39518  39694       assert( pList->nAlloc==0 );
 39519  39695     }
................................................................................
 39543  39719     return 0;
 39544  39720   }
 39545  39721   
 39546  39722   /*
 39547  39723   ** If the expression list pEList contains more than iLimit elements,
 39548  39724   ** leave an error message in pParse.
 39549  39725   */
 39550         -static void sqlite3ExprListCheckLength(
        39726  +