System.Data.SQLite
Check-in [e552f5ffad]
Not logged in

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

Overview
Comment:Bump version to 1.0.106.0. Update version history docs. Update SQLite core library to the latest trunk code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e552f5ffadb0e52d692f82de4953b1544b30bfe8
User & Date: mistachkin 2017-05-10 16:53:55
Context
2017-05-11
01:23
Make sure the 'No_SQLiteConnectionNewParser' and 'DefaultFlags_SQLiteConnection' setting values end up being cached. check-in: cee7126f56 user: mistachkin tags: trunk
2017-05-10
16:53
Bump version to 1.0.106.0. Update version history docs. Update SQLite core library to the latest trunk code. check-in: e552f5ffad user: mistachkin tags: trunk
2017-05-08
19:15
Add test for the fix in check-in [9b146be3f9aef0c3]. check-in: ece910dd8d user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Doc/Extra/Provider/dbfactorysupport.html.

    81     81   <configuration>
    82     82     <system.data>
    83     83       <DbProviderFactories>
    84     84         <remove invariant="System.Data.SQLite"/>
    85     85         <add name="SQLite Data Provider" invariant="System.Data.SQLite" 
    86     86              description=".NET Framework Data Provider for SQLite"
    87     87              type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite,
    88         -                 Version=1.0.105.0, Culture=neutral,
           88  +                 Version=1.0.106.0, Culture=neutral,
    89     89                    PublicKeyToken=db937bc2d44ff139"/>
    90     90       </DbProviderFactories>
    91     91     </system.data>
    92     92   </configuration>
    93     93   </pre>
    94     94         </div>
    95     95         <p>

Changes to Doc/Extra/Provider/version.html.

    39     39             </td>
    40     40           </tr>
    41     41         </table>
    42     42       </div>
    43     43       <div id="mainSection">
    44     44       <div id="mainBody">
    45     45       <h1 class="heading">Version History</h1>
           46  +    <p><b>1.0.106.0 - June XX, 2017 <font color="red">(release scheduled)</font></b></p>
           47  +    <ul>
           48  +      <li>Updated to <a href="https://www.sqlite.org/draft/releaselog/3_19_0.html">SQLite 3.19.0</a>.</li>
           49  +      <li>Prevent culture settings from negatively impacting integer connection string defaults.</li>
           50  +    </ul>
    46     51       <p><b>1.0.105.0 - April 9, 2017</b></p>
    47     52       <ul>
    48     53         <li>Updated to <a href="https://www.sqlite.org/releaselog/3_18_0.html">SQLite 3.18.0</a>.</li>
    49     54         <li>Add experimental support for native sha1 extension.</li>
    50     55       </ul>
    51     56       <p><b>1.0.104.0 - December 16, 2016</b></p>
    52     57       <ul>

Changes to Doc/Extra/Provider/welcome.html.

   156    156           <font color="red">
   157    157             Itanium processor support not currently included.
   158    158           </font>
   159    159         </p>
   160    160         <h1 class="heading">Distributing the Binaries (Compact Framework)</h1>
   161    161         <p>Both the <b>System.Data.SQLite.DLL </b>and <b>SQLite.Interop.XXX.DLL</b> files
   162    162           must be deployed on the Compact Framework.&nbsp; The XXX is the build number of
   163         -        the System.Data.SQLite library (e.g. &quot;105&quot;).&nbsp; The
          163  +        the System.Data.SQLite library (e.g. &quot;106&quot;).&nbsp; The
   164    164           <b>SQLite.Interop.XXX.DLL</b> file is a fully native assembly compiled for
   165    165           the ARM processor, and System.Data.SQLite is the fully-managed Compact
   166    166           Framework assembly.</p>
   167    167         <hr />
   168    168         <div id="footer">
   169    169           <p>
   170    170             <a href="mailto:sqlite-users@mailinglists.sqlite.org?subject=SQLite.NET%20Class%20Library%20Documentation%20Feedback:%20Welcome">
   171    171             Send comments on this topic.<!--[if gte IE 5]><tool:tip element="seeAlsoToolTip" avoidmouse="false" /><tool:tip element="languageFilterToolTip" avoidmouse="false" /><![endif]-->    </div>
   172    172       </div>
   173    173     </body>
   174    174   </html>

Changes to NuGet/SQLite.Beta.nuspec.

     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite.Beta</id>
    13     13       <title>System.Data.SQLite (x86/x64) Beta</title>
    14         -    <version>1.0.105.0</version>
           14  +    <version>1.0.106.0</version>
    15     15       <authors>SQLite Development Team</authors>
    16     16       <description>This is a &quot;beta&quot; package and is not intended for production use.  The official SQLite database engine for both x86 and x64 along with the ADO.NET provider.  This package includes support for LINQ and Entity Framework 6.</description>
    17     17       <language>en-US</language>
    18     18       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    19     19       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    20     20       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    21     21       <tags>sqlite database ado.net provider interop</tags>
    22     22       <copyright>Public Domain</copyright>
    23     23       <dependencies>
    24     24         <group targetFramework="net20">
    25         -        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.105.0" />
           25  +        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.106.0" />
    26     26         </group>
    27     27         <group targetFramework="net40">
    28         -        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.105.0" />
           28  +        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.106.0" />
    29     29         </group>
    30     30         <group targetFramework="net45">
    31         -        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.105.0" />
           31  +        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.106.0" />
    32     32         </group>
    33     33         <group targetFramework="net451">
    34         -        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.105.0" />
           34  +        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.106.0" />
    35     35         </group>
    36     36         <group targetFramework="net46">
    37         -        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.105.0" />
           37  +        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.106.0" />
    38     38         </group>
    39     39         <group targetFramework="net20">
    40         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.105.0" />
           40  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.106.0" />
    41     41         </group>
    42     42         <group targetFramework="net40">
    43         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.105.0" />
           43  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.106.0" />
    44     44         </group>
    45     45         <group targetFramework="net45">
    46         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.105.0" />
           46  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.106.0" />
    47     47         </group>
    48     48         <group targetFramework="net451">
    49         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.105.0" />
           49  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.106.0" />
    50     50         </group>
    51     51         <group targetFramework="net46">
    52         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.105.0" />
           52  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.106.0" />
    53     53         </group>
    54     54         <group targetFramework="net40">
    55         -        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.105.0" />
           55  +        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.106.0" />
    56     56         </group>
    57     57         <group targetFramework="net45">
    58         -        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.105.0" />
           58  +        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.106.0" />
    59     59         </group>
    60     60         <group targetFramework="net451">
    61         -        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.105.0" />
           61  +        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.106.0" />
    62     62         </group>
    63     63         <group targetFramework="net46">
    64         -        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.105.0" />
           64  +        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.106.0" />
    65     65         </group>
    66     66       </dependencies>
    67     67     </metadata>
    68     68     <files />
    69     69   </package>

Changes to NuGet/SQLite.Core.Beta.nuspec.

     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite.Core.Beta</id>
    13     13       <title>System.Data.SQLite Core (x86/x64) Beta</title>
    14         -    <version>1.0.105.0</version>
           14  +    <version>1.0.106.0</version>
    15     15       <authors>SQLite Development Team</authors>
    16     16       <description>This is a &quot;beta&quot; package and is not intended for production use.  The official SQLite database engine for both x86 and x64 along with the ADO.NET provider.</description>
    17     17       <language>en-US</language>
    18     18       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    19     19       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    20     20       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    21     21       <tags>sqlite database ado.net provider interop</tags>

Changes to NuGet/SQLite.Core.MSIL.Beta.nuspec.

     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite.Core.MSIL.Beta</id>
    13     13       <title>System.Data.SQLite (MSIL) Beta</title>
    14         -    <version>1.0.105.0</version>
           14  +    <version>1.0.106.0</version>
    15     15       <authors>SQLite Development Team</authors>
    16     16       <description>This is a &quot;beta&quot; package and is not intended for production use.  An ADO.NET provider for SQLite (managed-only).</description>
    17     17       <language>en-US</language>
    18     18       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    19     19       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    20     20       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    21     21       <tags>sqlite database ado.net provider interop</tags>

Changes to NuGet/SQLite.Core.MSIL.Test.nuspec.

     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite.Core.MSIL.Test</id>
    13     13       <title>System.Data.SQLite (MSIL) Test</title>
    14         -    <version>1.0.105.0</version>
           14  +    <version>1.0.106.0</version>
    15     15       <authors>SQLite Development Team</authors>
    16     16       <description>This is a pre-release package and is not intended for production use.  An ADO.NET provider for SQLite (managed-only).</description>
    17     17       <language>en-US</language>
    18     18       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    19     19       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    20     20       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    21     21       <tags>sqlite database ado.net provider interop</tags>

Changes to NuGet/SQLite.Core.MSIL.nuspec.

     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite.Core.MSIL</id>
    13     13       <title>System.Data.SQLite Core (MSIL)</title>
    14         -    <version>1.0.105.0</version>
           14  +    <version>1.0.106.0</version>
    15     15       <authors>SQLite Development Team</authors>
    16     16       <description>An ADO.NET provider for SQLite (managed-only).</description>
    17     17       <language>en-US</language>
    18     18       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    19     19       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    20     20       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    21     21       <tags>sqlite database ado.net provider interop</tags>

Changes to NuGet/SQLite.Core.Test.nuspec.

     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite.Core.Test</id>
    13     13       <title>System.Data.SQLite Core (x86/x64) Test</title>
    14         -    <version>1.0.105.0</version>
           14  +    <version>1.0.106.0</version>
    15     15       <authors>SQLite Development Team</authors>
    16     16       <description>This is a pre-release package and is not intended for production use.  The official SQLite database engine for both x86 and x64 along with the ADO.NET provider.</description>
    17     17       <language>en-US</language>
    18     18       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    19     19       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    20     20       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    21     21       <tags>sqlite database ado.net provider interop</tags>

Changes to NuGet/SQLite.Core.nuspec.

     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite.Core</id>
    13     13       <title>System.Data.SQLite Core (x86/x64)</title>
    14         -    <version>1.0.105.0</version>
           14  +    <version>1.0.106.0</version>
    15     15       <authors>SQLite Development Team</authors>
    16     16       <description>The official SQLite database engine for both x86 and x64 along with the ADO.NET provider.</description>
    17     17       <language>en-US</language>
    18     18       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    19     19       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    20     20       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    21     21       <tags>sqlite database ado.net provider interop</tags>

Changes to NuGet/SQLite.EF6.Beta.nuspec.

     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite.EF6.Beta</id>
    13     13       <title>System.Data.SQLite EF6 Beta</title>
    14         -    <version>1.0.105.0</version>
           14  +    <version>1.0.106.0</version>
    15     15       <authors>SQLite Development Team</authors>
    16     16       <description>This is a &quot;beta&quot; package and is not intended for production use.  Support for Entity Framework 6 using System.Data.SQLite.</description>
    17     17       <language>en-US</language>
    18     18       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    19     19       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    20     20       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    21     21       <tags>sqlite database ado.net provider interop</tags>

Changes to NuGet/SQLite.EF6.Test.nuspec.

     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite.EF6.Test</id>
    13     13       <title>System.Data.SQLite EF6 Test</title>
    14         -    <version>1.0.105.0</version>
           14  +    <version>1.0.106.0</version>
    15     15       <authors>SQLite Development Team</authors>
    16     16       <description>This is a pre-release package and is not intended for production use.  Support for Entity Framework 6 using System.Data.SQLite.</description>
    17     17       <language>en-US</language>
    18     18       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    19     19       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    20     20       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    21     21       <tags>sqlite database ado.net provider interop</tags>

Changes to NuGet/SQLite.EF6.nuspec.

     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite.EF6</id>
    13     13       <title>System.Data.SQLite EF6</title>
    14         -    <version>1.0.105.0</version>
           14  +    <version>1.0.106.0</version>
    15     15       <authors>SQLite Development Team</authors>
    16     16       <description>Support for Entity Framework 6 using System.Data.SQLite.</description>
    17     17       <language>en-US</language>
    18     18       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    19     19       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    20     20       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    21     21       <tags>sqlite database ado.net provider interop</tags>

Changes to NuGet/SQLite.Linq.Beta.nuspec.

     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite.Linq.Beta</id>
    13     13       <title>System.Data.SQLite LINQ Beta</title>
    14         -    <version>1.0.105.0</version>
           14  +    <version>1.0.106.0</version>
    15     15       <authors>SQLite Development Team</authors>
    16     16       <description>This is a &quot;beta&quot; package and is not intended for production use.  Support for LINQ using System.Data.SQLite.</description>
    17     17       <language>en-US</language>
    18     18       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    19     19       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    20     20       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    21     21       <tags>sqlite database ado.net provider interop</tags>

Changes to NuGet/SQLite.Linq.Test.nuspec.

     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite.Linq.Test</id>
    13     13       <title>System.Data.SQLite LINQ Test</title>
    14         -    <version>1.0.105.0</version>
           14  +    <version>1.0.106.0</version>
    15     15       <authors>SQLite Development Team</authors>
    16     16       <description>This is a pre-release package and is not intended for production use.  Support for LINQ using System.Data.SQLite.</description>
    17     17       <language>en-US</language>
    18     18       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    19     19       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    20     20       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    21     21       <tags>sqlite database ado.net provider interop</tags>

Changes to NuGet/SQLite.Linq.nuspec.

     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite.Linq</id>
    13     13       <title>System.Data.SQLite LINQ</title>
    14         -    <version>1.0.105.0</version>
           14  +    <version>1.0.106.0</version>
    15     15       <authors>SQLite Development Team</authors>
    16     16       <description>Support for LINQ using System.Data.SQLite.</description>
    17     17       <language>en-US</language>
    18     18       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    19     19       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    20     20       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    21     21       <tags>sqlite database ado.net provider interop</tags>

Changes to NuGet/SQLite.MSIL.Beta.nuspec.

     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite.MSIL.Beta</id>
    13     13       <title>System.Data.SQLite (MSIL) Beta</title>
    14         -    <version>1.0.105.0</version>
           14  +    <version>1.0.106.0</version>
    15     15       <authors>SQLite Development Team</authors>
    16     16       <description>This is a &quot;beta&quot; package and is not intended for production use.  This is a legacy package; if possible, please use either the &quot;System.Data.SQLite.Beta&quot; or &quot;System.Data.SQLite.Core.Beta&quot; package instead.  An ADO.NET provider for SQLite (managed-only).</description>
    17     17       <language>en-US</language>
    18     18       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    19     19       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    20     20       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    21     21       <tags>sqlite database ado.net provider interop</tags>
    22     22       <copyright>Public Domain</copyright>
    23     23       <dependencies>
    24     24         <group targetFramework="net20">
    25         -        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.105.0" />
           25  +        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.106.0" />
    26     26         </group>
    27     27         <group targetFramework="net40">
    28         -        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.105.0" />
           28  +        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.106.0" />
    29     29         </group>
    30     30         <group targetFramework="net45">
    31         -        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.105.0" />
           31  +        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.106.0" />
    32     32         </group>
    33     33         <group targetFramework="net451">
    34         -        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.105.0" />
           34  +        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.106.0" />
    35     35         </group>
    36     36         <group targetFramework="net46">
    37         -        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.105.0" />
           37  +        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.106.0" />
    38     38         </group>
    39     39         <group targetFramework="net20">
    40         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.105.0" />
           40  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.106.0" />
    41     41         </group>
    42     42         <group targetFramework="net40">
    43         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.105.0" />
           43  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.106.0" />
    44     44         </group>
    45     45         <group targetFramework="net45">
    46         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.105.0" />
           46  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.106.0" />
    47     47         </group>
    48     48         <group targetFramework="net451">
    49         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.105.0" />
           49  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.106.0" />
    50     50         </group>
    51     51         <group targetFramework="net46">
    52         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.105.0" />
           52  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.106.0" />
    53     53         </group>
    54     54         <group targetFramework="net40">
    55         -        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.105.0" />
           55  +        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.106.0" />
    56     56         </group>
    57     57         <group targetFramework="net45">
    58         -        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.105.0" />
           58  +        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.106.0" />
    59     59         </group>
    60     60         <group targetFramework="net451">
    61         -        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.105.0" />
           61  +        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.106.0" />
    62     62         </group>
    63     63         <group targetFramework="net46">
    64         -        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.105.0" />
           64  +        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.106.0" />
    65     65         </group>
    66     66       </dependencies>
    67     67     </metadata>
    68     68     <files />
    69     69   </package>

Changes to NuGet/SQLite.MSIL.Test.nuspec.

     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite.MSIL.Test</id>
    13     13       <title>System.Data.SQLite (MSIL) Test</title>
    14         -    <version>1.0.105.0</version>
           14  +    <version>1.0.106.0</version>
    15     15       <authors>SQLite Development Team</authors>
    16     16       <description>This is a pre-release package and is not intended for production use.  This is a legacy package; if possible, please use either the &quot;System.Data.SQLite.Test&quot; or &quot;System.Data.SQLite.Core.Test&quot; package instead.  An ADO.NET provider for SQLite (managed-only).</description>
    17     17       <language>en-US</language>
    18     18       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    19     19       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    20     20       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    21     21       <tags>sqlite database ado.net provider interop</tags>
    22     22       <copyright>Public Domain</copyright>
    23     23       <dependencies>
    24     24         <group targetFramework="net20">
    25         -        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.105.0" />
           25  +        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.106.0" />
    26     26         </group>
    27     27         <group targetFramework="net40">
    28         -        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.105.0" />
           28  +        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.106.0" />
    29     29         </group>
    30     30         <group targetFramework="net45">
    31         -        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.105.0" />
           31  +        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.106.0" />
    32     32         </group>
    33     33         <group targetFramework="net451">
    34         -        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.105.0" />
           34  +        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.106.0" />
    35     35         </group>
    36     36         <group targetFramework="net46">
    37         -        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.105.0" />
           37  +        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.106.0" />
    38     38         </group>
    39     39         <group targetFramework="net20">
    40         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.105.0" />
           40  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.106.0" />
    41     41         </group>
    42     42         <group targetFramework="net40">
    43         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.105.0" />
           43  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.106.0" />
    44     44         </group>
    45     45         <group targetFramework="net45">
    46         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.105.0" />
           46  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.106.0" />
    47     47         </group>
    48     48         <group targetFramework="net451">
    49         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.105.0" />
           49  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.106.0" />
    50     50         </group>
    51     51         <group targetFramework="net46">
    52         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.105.0" />
           52  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.106.0" />
    53     53         </group>
    54     54         <group targetFramework="net40">
    55         -        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.105.0" />
           55  +        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.106.0" />
    56     56         </group>
    57     57         <group targetFramework="net45">
    58         -        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.105.0" />
           58  +        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.106.0" />
    59     59         </group>
    60     60         <group targetFramework="net451">
    61         -        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.105.0" />
           61  +        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.106.0" />
    62     62         </group>
    63     63         <group targetFramework="net46">
    64         -        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.105.0" />
           64  +        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.106.0" />
    65     65         </group>
    66     66       </dependencies>
    67     67     </metadata>
    68     68     <files />
    69     69   </package>

Changes to NuGet/SQLite.MSIL.nuspec.

     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite.MSIL</id>
    13     13       <title>System.Data.SQLite (MSIL)</title>
    14         -    <version>1.0.105.0</version>
           14  +    <version>1.0.106.0</version>
    15     15       <authors>SQLite Development Team</authors>
    16     16       <description>This is a legacy package; if possible, please use either the &quot;System.Data.SQLite&quot; or &quot;System.Data.SQLite.Core&quot; package instead.  An ADO.NET provider for SQLite (managed-only).</description>
    17     17       <language>en-US</language>
    18     18       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    19     19       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    20     20       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    21     21       <tags>sqlite database ado.net provider interop</tags>
    22     22       <copyright>Public Domain</copyright>
    23     23       <dependencies>
    24     24         <group targetFramework="net20">
    25         -        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.105.0" />
           25  +        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.106.0" />
    26     26         </group>
    27     27         <group targetFramework="net40">
    28         -        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.105.0" />
           28  +        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.106.0" />
    29     29         </group>
    30     30         <group targetFramework="net45">
    31         -        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.105.0" />
           31  +        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.106.0" />
    32     32         </group>
    33     33         <group targetFramework="net451">
    34         -        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.105.0" />
           34  +        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.106.0" />
    35     35         </group>
    36     36         <group targetFramework="net46">
    37         -        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.105.0" />
           37  +        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.106.0" />
    38     38         </group>
    39     39         <group targetFramework="net20">
    40         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           40  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    41     41         </group>
    42     42         <group targetFramework="net40">
    43         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           43  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    44     44         </group>
    45     45         <group targetFramework="net45">
    46         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           46  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    47     47         </group>
    48     48         <group targetFramework="net451">
    49         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           49  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    50     50         </group>
    51     51         <group targetFramework="net46">
    52         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           52  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    53     53         </group>
    54     54         <group targetFramework="net40">
    55         -        <dependency id="System.Data.SQLite.EF6" version="1.0.105.0" />
           55  +        <dependency id="System.Data.SQLite.EF6" version="1.0.106.0" />
    56     56         </group>
    57     57         <group targetFramework="net45">
    58         -        <dependency id="System.Data.SQLite.EF6" version="1.0.105.0" />
           58  +        <dependency id="System.Data.SQLite.EF6" version="1.0.106.0" />
    59     59         </group>
    60     60         <group targetFramework="net451">
    61         -        <dependency id="System.Data.SQLite.EF6" version="1.0.105.0" />
           61  +        <dependency id="System.Data.SQLite.EF6" version="1.0.106.0" />
    62     62         </group>
    63     63         <group targetFramework="net46">
    64         -        <dependency id="System.Data.SQLite.EF6" version="1.0.105.0" />
           64  +        <dependency id="System.Data.SQLite.EF6" version="1.0.106.0" />
    65     65         </group>
    66     66       </dependencies>
    67     67     </metadata>
    68     68     <files />
    69     69   </package>

Changes to NuGet/SQLite.Test.nuspec.

     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite.Test</id>
    13     13       <title>System.Data.SQLite (x86/x64) Test</title>
    14         -    <version>1.0.105.0</version>
           14  +    <version>1.0.106.0</version>
    15     15       <authors>SQLite Development Team</authors>
    16     16       <description>This is a pre-release package and is not intended for production use.  The official SQLite database engine for both x86 and x64 along with the ADO.NET provider.  This package includes support for LINQ and Entity Framework 6.</description>
    17     17       <language>en-US</language>
    18     18       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    19     19       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    20     20       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    21     21       <tags>sqlite database ado.net provider interop</tags>
    22     22       <copyright>Public Domain</copyright>
    23     23       <dependencies>
    24     24         <group targetFramework="net20">
    25         -        <dependency id="System.Data.SQLite.Core.Test" version="1.0.105.0" />
           25  +        <dependency id="System.Data.SQLite.Core.Test" version="1.0.106.0" />
    26     26         </group>
    27     27         <group targetFramework="net40">
    28         -        <dependency id="System.Data.SQLite.Core.Test" version="1.0.105.0" />
           28  +        <dependency id="System.Data.SQLite.Core.Test" version="1.0.106.0" />
    29     29         </group>
    30     30         <group targetFramework="net45">
    31         -        <dependency id="System.Data.SQLite.Core.Test" version="1.0.105.0" />
           31  +        <dependency id="System.Data.SQLite.Core.Test" version="1.0.106.0" />
    32     32         </group>
    33     33         <group targetFramework="net451">
    34         -        <dependency id="System.Data.SQLite.Core.Test" version="1.0.105.0" />
           34  +        <dependency id="System.Data.SQLite.Core.Test" version="1.0.106.0" />
    35     35         </group>
    36     36         <group targetFramework="net46">
    37         -        <dependency id="System.Data.SQLite.Core.Test" version="1.0.105.0" />
           37  +        <dependency id="System.Data.SQLite.Core.Test" version="1.0.106.0" />
    38     38         </group>
    39     39         <group targetFramework="net20">
    40         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.105.0" />
           40  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.106.0" />
    41     41         </group>
    42     42         <group targetFramework="net40">
    43         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.105.0" />
           43  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.106.0" />
    44     44         </group>
    45     45         <group targetFramework="net45">
    46         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.105.0" />
           46  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.106.0" />
    47     47         </group>
    48     48         <group targetFramework="net451">
    49         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.105.0" />
           49  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.106.0" />
    50     50         </group>
    51     51         <group targetFramework="net46">
    52         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.105.0" />
           52  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.106.0" />
    53     53         </group>
    54     54         <group targetFramework="net40">
    55         -        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.105.0" />
           55  +        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.106.0" />
    56     56         </group>
    57     57         <group targetFramework="net45">
    58         -        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.105.0" />
           58  +        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.106.0" />
    59     59         </group>
    60     60         <group targetFramework="net451">
    61         -        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.105.0" />
           61  +        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.106.0" />
    62     62         </group>
    63     63         <group targetFramework="net46">
    64         -        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.105.0" />
           64  +        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.106.0" />
    65     65         </group>
    66     66       </dependencies>
    67     67     </metadata>
    68     68     <files />
    69     69   </package>

Changes to NuGet/SQLite.nuspec.

     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite</id>
    13     13       <title>System.Data.SQLite (x86/x64)</title>
    14         -    <version>1.0.105.0</version>
           14  +    <version>1.0.106.0</version>
    15     15       <authors>SQLite Development Team</authors>
    16     16       <description>The official SQLite database engine for both x86 and x64 along with the ADO.NET provider.  This package includes support for LINQ and Entity Framework 6.</description>
    17     17       <language>en-US</language>
    18     18       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    19     19       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    20     20       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    21     21       <tags>sqlite database ado.net provider interop</tags>
    22     22       <copyright>Public Domain</copyright>
    23     23       <dependencies>
    24     24         <group targetFramework="net20">
    25         -        <dependency id="System.Data.SQLite.Core" version="1.0.105.0" />
           25  +        <dependency id="System.Data.SQLite.Core" version="1.0.106.0" />
    26     26         </group>
    27     27         <group targetFramework="net40">
    28         -        <dependency id="System.Data.SQLite.Core" version="1.0.105.0" />
           28  +        <dependency id="System.Data.SQLite.Core" version="1.0.106.0" />
    29     29         </group>
    30     30         <group targetFramework="net45">
    31         -        <dependency id="System.Data.SQLite.Core" version="1.0.105.0" />
           31  +        <dependency id="System.Data.SQLite.Core" version="1.0.106.0" />
    32     32         </group>
    33     33         <group targetFramework="net451">
    34         -        <dependency id="System.Data.SQLite.Core" version="1.0.105.0" />
           34  +        <dependency id="System.Data.SQLite.Core" version="1.0.106.0" />
    35     35         </group>
    36     36         <group targetFramework="net46">
    37         -        <dependency id="System.Data.SQLite.Core" version="1.0.105.0" />
           37  +        <dependency id="System.Data.SQLite.Core" version="1.0.106.0" />
    38     38         </group>
    39     39         <group targetFramework="net20">
    40         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           40  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    41     41         </group>
    42     42         <group targetFramework="net40">
    43         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           43  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    44     44         </group>
    45     45         <group targetFramework="net45">
    46         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           46  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    47     47         </group>
    48     48         <group targetFramework="net451">
    49         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           49  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    50     50         </group>
    51     51         <group targetFramework="net46">
    52         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           52  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    53     53         </group>
    54     54         <group targetFramework="net40">
    55         -        <dependency id="System.Data.SQLite.EF6" version="1.0.105.0" />
           55  +        <dependency id="System.Data.SQLite.EF6" version="1.0.106.0" />
    56     56         </group>
    57     57         <group targetFramework="net45">
    58         -        <dependency id="System.Data.SQLite.EF6" version="1.0.105.0" />
           58  +        <dependency id="System.Data.SQLite.EF6" version="1.0.106.0" />
    59     59         </group>
    60     60         <group targetFramework="net451">
    61         -        <dependency id="System.Data.SQLite.EF6" version="1.0.105.0" />
           61  +        <dependency id="System.Data.SQLite.EF6" version="1.0.106.0" />
    62     62         </group>
    63     63         <group targetFramework="net46">
    64         -        <dependency id="System.Data.SQLite.EF6" version="1.0.105.0" />
           64  +        <dependency id="System.Data.SQLite.EF6" version="1.0.106.0" />
    65     65         </group>
    66     66       </dependencies>
    67     67     </metadata>
    68     68     <files />
    69     69   </package>

Changes to NuGet/SQLite.x64.nuspec.

     6      6    * Written by Joe Mistachkin.
     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite.x64</id>
    13         -    <version>1.0.105.0</version>
           13  +    <version>1.0.106.0</version>
    14     14       <authors>SQLite Development Team</authors>
    15     15       <description>This is a legacy package; if possible, please use either the &quot;System.Data.SQLite&quot; or &quot;System.Data.SQLite.Core&quot; package instead.  The official SQLite database engine combined with a complete ADO.NET provider all rolled into a single mixed-mode assembly for x64.</description>
    16     16       <language>en-US</language>
    17     17       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    18     18       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    19     19       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    20     20       <tags>sqlite database ado.net provider interop</tags>
    21     21       <copyright>Public Domain</copyright>
    22     22       <dependencies>
    23     23         <group targetFramework="net20">
    24         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           24  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    25     25         </group>
    26     26         <group targetFramework="net40">
    27         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           27  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    28     28         </group>
    29     29         <group targetFramework="net45">
    30         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           30  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    31     31         </group>
    32     32         <group targetFramework="net451">
    33         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           33  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    34     34         </group>
    35     35         <group targetFramework="net46">
    36         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           36  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    37     37         </group>
    38     38         <group targetFramework="net40">
    39         -        <dependency id="System.Data.SQLite.EF6" version="1.0.105.0" />
           39  +        <dependency id="System.Data.SQLite.EF6" version="1.0.106.0" />
    40     40         </group>
    41     41         <group targetFramework="net45">
    42         -        <dependency id="System.Data.SQLite.EF6" version="1.0.105.0" />
           42  +        <dependency id="System.Data.SQLite.EF6" version="1.0.106.0" />
    43     43         </group>
    44     44         <group targetFramework="net451">
    45         -        <dependency id="System.Data.SQLite.EF6" version="1.0.105.0" />
           45  +        <dependency id="System.Data.SQLite.EF6" version="1.0.106.0" />
    46     46         </group>
    47     47         <group targetFramework="net46">
    48         -        <dependency id="System.Data.SQLite.EF6" version="1.0.105.0" />
           48  +        <dependency id="System.Data.SQLite.EF6" version="1.0.106.0" />
    49     49         </group>
    50     50       </dependencies>
    51     51     </metadata>
    52     52     <files>
    53     53       <file src="..\bin\2008\x64\ReleaseStatic\System.Data.SQLite.dll" target="lib\net20" />
    54     54       <file src="..\bin\2008\Release\bin\System.Data.SQLite.xml" target="lib\net20" />
    55     55       <file src="..\bin\2010\x64\ReleaseStatic\System.Data.SQLite.dll" target="lib\net40" />

Changes to NuGet/SQLite.x86.nuspec.

     6      6    * Written by Joe Mistachkin.
     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <package>
    11     11     <metadata>
    12     12       <id>System.Data.SQLite.x86</id>
    13         -    <version>1.0.105.0</version>
           13  +    <version>1.0.106.0</version>
    14     14       <authors>SQLite Development Team</authors>
    15     15       <description>This is a legacy package; if possible, please use either the &quot;System.Data.SQLite&quot; or &quot;System.Data.SQLite.Core&quot; package instead.  The official SQLite database engine combined with a complete ADO.NET provider all rolled into a single mixed-mode assembly for x86.</description>
    16     16       <language>en-US</language>
    17     17       <projectUrl>https://system.data.sqlite.org/</projectUrl>
    18     18       <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    19     19       <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    20     20       <tags>sqlite database ado.net provider interop</tags>
    21     21       <copyright>Public Domain</copyright>
    22     22       <dependencies>
    23     23         <group targetFramework="net20">
    24         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           24  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    25     25         </group>
    26     26         <group targetFramework="net40">
    27         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           27  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    28     28         </group>
    29     29         <group targetFramework="net45">
    30         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           30  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    31     31         </group>
    32     32         <group targetFramework="net451">
    33         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           33  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    34     34         </group>
    35     35         <group targetFramework="net46">
    36         -        <dependency id="System.Data.SQLite.Linq" version="1.0.105.0" />
           36  +        <dependency id="System.Data.SQLite.Linq" version="1.0.106.0" />
    37     37         </group>
    38     38         <group targetFramework="net40">
    39         -        <dependency id="System.Data.SQLite.EF6" version="1.0.105.0" />
           39  +        <dependency id="System.Data.SQLite.EF6" version="1.0.106.0" />
    40     40         </group>
    41     41         <group targetFramework="net45">
    42         -        <dependency id="System.Data.SQLite.EF6" version="1.0.105.0" />
           42  +        <dependency id="System.Data.SQLite.EF6" version="1.0.106.0" />
    43     43         </group>
    44     44         <group targetFramework="net451">
    45         -        <dependency id="System.Data.SQLite.EF6" version="1.0.105.0" />
           45  +        <dependency id="System.Data.SQLite.EF6" version="1.0.106.0" />
    46     46         </group>
    47     47         <group targetFramework="net46">
    48         -        <dependency id="System.Data.SQLite.EF6" version="1.0.105.0" />
           48  +        <dependency id="System.Data.SQLite.EF6" version="1.0.106.0" />
    49     49         </group>
    50     50       </dependencies>
    51     51     </metadata>
    52     52     <files>
    53     53       <file src="..\bin\2008\Win32\ReleaseStatic\System.Data.SQLite.dll" target="lib\net20" />
    54     54       <file src="..\bin\2008\Release\bin\System.Data.SQLite.xml" target="lib\net20" />
    55     55       <file src="..\bin\2010\Win32\ReleaseStatic\System.Data.SQLite.dll" target="lib\net40" />

Changes to SQLite.Designer/AssemblyInfo.cs.

    39     39   //      Major Version
    40     40   //      Minor Version 
    41     41   //      Build Number
    42     42   //      Revision
    43     43   //
    44     44   // You can specify all the values or you can default the Revision and Build Numbers 
    45     45   // by using the '*' as shown below:
    46         -[assembly: AssemblyVersion("1.0.105.0")]
    47         -[assembly: AssemblyFileVersion("1.0.105.0")]
           46  +[assembly: AssemblyVersion("1.0.106.0")]
           47  +[assembly: AssemblyFileVersion("1.0.106.0")]

Changes to SQLite.Designer/source.extension.vsixmanifest.

     1      1   <?xml version="1.0" encoding="utf-8"?>
     2      2   <Vsix Version="1.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2010">
     3      3     <Identifier Id="67b5f3a9-cde1-430f-a12b-af95bb064851">
     4      4       <Name>System.Data.SQLite Designer</Name>
     5      5       <Author>https://system.data.sqlite.org/</Author>
     6         -    <Version>1.0.105.0</Version>
            6  +    <Version>1.0.106.0</Version>
     7      7       <Description>ADO.NET Data Designer for SQLite</Description>
     8      8       <Locale>1033</Locale>
     9      9       <InstalledByMsi>false</InstalledByMsi>
    10     10       <SupportedProducts>
    11     11         <VisualStudio Version="10.0">
    12     12           <Edition>Pro</Edition>
    13     13         </VisualStudio>

Changes to SQLite.Interop/props/SQLite.Interop.2005.vsprops.

    15     15   	<UserMacro
    16     16   		Name="ConfigurationYear"
    17     17   		Value="2005"
    18     18   		PerformEnvironmentSet="true"
    19     19   	/>
    20     20   	<UserMacro
    21     21   		Name="INTEROP_BUILD_NUMBER"
    22         -		Value="105"
           22  +		Value="106"
    23     23   		PerformEnvironmentSet="true"
    24     24   	/>
    25     25   	<UserMacro
    26     26   		Name="INTEROP_LINKER_VERSION"
    27     27   		Value="1.0"
    28     28   		PerformEnvironmentSet="true"
    29     29   	/>
    30     30   	<UserMacro
    31     31   		Name="INTEROP_MANIFEST_VERSION"
    32         -		Value="1.0.105.0"
           32  +		Value="1.0.106.0"
    33     33   		PerformEnvironmentSet="true"
    34     34   	/>
    35     35   	<UserMacro
    36     36   		Name="INTEROP_RC_VERSION"
    37         -		Value="1,0,105,0"
           37  +		Value="1,0,106,0"
    38     38   		PerformEnvironmentSet="true"
    39     39   	/>
    40     40   	<UserMacro
    41     41   		Name="INTEROP_INCLUDE_DIRECTORIES"
    42     42   		Value="src\core"
    43     43   		PerformEnvironmentSet="true"
    44     44   	/>

Changes to SQLite.Interop/props/SQLite.Interop.2008.vsprops.

    15     15   	<UserMacro
    16     16   		Name="ConfigurationYear"
    17     17   		Value="2008"
    18     18   		PerformEnvironmentSet="true"
    19     19   	/>
    20     20   	<UserMacro
    21     21   		Name="INTEROP_BUILD_NUMBER"
    22         -		Value="105"
           22  +		Value="106"
    23     23   		PerformEnvironmentSet="true"
    24     24   	/>
    25     25   	<UserMacro
    26     26   		Name="INTEROP_LINKER_VERSION"
    27     27   		Value="1.0"
    28     28   		PerformEnvironmentSet="true"
    29     29   	/>
    30     30   	<UserMacro
    31     31   		Name="INTEROP_MANIFEST_VERSION"
    32         -		Value="1.0.105.0"
           32  +		Value="1.0.106.0"
    33     33   		PerformEnvironmentSet="true"
    34     34   	/>
    35     35   	<UserMacro
    36     36   		Name="INTEROP_RC_VERSION"
    37         -		Value="1,0,105,0"
           37  +		Value="1,0,106,0"
    38     38   		PerformEnvironmentSet="true"
    39     39   	/>
    40     40   	<UserMacro
    41     41   		Name="INTEROP_INCLUDE_DIRECTORIES"
    42     42   		Value="src\core"
    43     43   		PerformEnvironmentSet="true"
    44     44   	/>

Changes to SQLite.Interop/props/SQLite.Interop.2010.props.

     6      6    * Written by Joe Mistachkin.
     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
    11     11     <PropertyGroup Label="UserMacros">
    12     12       <ConfigurationYear>2010</ConfigurationYear>
    13         -    <INTEROP_BUILD_NUMBER>105</INTEROP_BUILD_NUMBER>
           13  +    <INTEROP_BUILD_NUMBER>106</INTEROP_BUILD_NUMBER>
    14     14       <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION>
    15         -    <INTEROP_MANIFEST_VERSION>1.0.105.0</INTEROP_MANIFEST_VERSION>
    16         -    <INTEROP_RC_VERSION>1,0,105,0</INTEROP_RC_VERSION>
           15  +    <INTEROP_MANIFEST_VERSION>1.0.106.0</INTEROP_MANIFEST_VERSION>
           16  +    <INTEROP_RC_VERSION>1,0,106,0</INTEROP_RC_VERSION>
    17     17       <INTEROP_INCLUDE_DIRECTORIES>src\core</INTEROP_INCLUDE_DIRECTORIES>
    18     18       <INTEROP_LIBRARY_DIRECTORIES></INTEROP_LIBRARY_DIRECTORIES>
    19     19       <INTEROP_LIBRARY_DEPENDENCIES></INTEROP_LIBRARY_DEPENDENCIES>
    20     20       <INTEROP_DEBUG_DEFINES>INTEROP_DEBUG=0x31F;INTEROP_LOG=1;INTEROP_TEST_EXTENSION=1</INTEROP_DEBUG_DEFINES>
    21     21       <INTEROP_EXTRA_DEFINES>INTEROP_PLACEHOLDER=1;INTEROP_EXTENSION_FUNCTIONS=1;INTEROP_CODEC=1;INTEROP_VIRTUAL_TABLE=1;INTEROP_FTS5_EXTENSION=1;INTEROP_PERCENTILE_EXTENSION=1;INTEROP_TOTYPE_EXTENSION=1;INTEROP_REGEXP_EXTENSION=1;INTEROP_JSON1_EXTENSION=1;INTEROP_SHA1_EXTENSION=1</INTEROP_EXTRA_DEFINES>
    22     22       <INTEROP_ASSEMBLY_RESOURCES>/ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteCommand.bmp,System.Data.SQLite.SQLiteCommand.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteConnection.bmp,System.Data.SQLite.SQLiteConnection.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteDataAdapter.bmp,System.Data.SQLite.SQLiteDataAdapter.bmp</INTEROP_ASSEMBLY_RESOURCES>
    23     23       <INTEROP_KEY_FILE>$(ProjectDir)..\Keys\System.Data.SQLite.snk</INTEROP_KEY_FILE>

Changes to SQLite.Interop/props/SQLite.Interop.2012.props.

     6      6    * Written by Joe Mistachkin.
     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
    11     11     <PropertyGroup Label="UserMacros">
    12     12       <ConfigurationYear>2012</ConfigurationYear>
    13         -    <INTEROP_BUILD_NUMBER>105</INTEROP_BUILD_NUMBER>
           13  +    <INTEROP_BUILD_NUMBER>106</INTEROP_BUILD_NUMBER>
    14     14       <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION>
    15         -    <INTEROP_MANIFEST_VERSION>1.0.105.0</INTEROP_MANIFEST_VERSION>
    16         -    <INTEROP_RC_VERSION>1,0,105,0</INTEROP_RC_VERSION>
           15  +    <INTEROP_MANIFEST_VERSION>1.0.106.0</INTEROP_MANIFEST_VERSION>
           16  +    <INTEROP_RC_VERSION>1,0,106,0</INTEROP_RC_VERSION>
    17     17       <INTEROP_INCLUDE_DIRECTORIES>src\core</INTEROP_INCLUDE_DIRECTORIES>
    18     18       <INTEROP_LIBRARY_DIRECTORIES></INTEROP_LIBRARY_DIRECTORIES>
    19     19       <INTEROP_LIBRARY_DEPENDENCIES></INTEROP_LIBRARY_DEPENDENCIES>
    20     20       <INTEROP_DEBUG_DEFINES>INTEROP_DEBUG=0x31F;INTEROP_LOG=1;INTEROP_TEST_EXTENSION=1</INTEROP_DEBUG_DEFINES>
    21     21       <INTEROP_EXTRA_DEFINES>INTEROP_PLACEHOLDER=1;INTEROP_EXTENSION_FUNCTIONS=1;INTEROP_CODEC=1;INTEROP_VIRTUAL_TABLE=1;INTEROP_FTS5_EXTENSION=1;INTEROP_PERCENTILE_EXTENSION=1;INTEROP_TOTYPE_EXTENSION=1;INTEROP_REGEXP_EXTENSION=1;INTEROP_JSON1_EXTENSION=1;INTEROP_SHA1_EXTENSION=1</INTEROP_EXTRA_DEFINES>
    22     22       <INTEROP_ASSEMBLY_RESOURCES>/ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteCommand.bmp,System.Data.SQLite.SQLiteCommand.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteConnection.bmp,System.Data.SQLite.SQLiteConnection.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteDataAdapter.bmp,System.Data.SQLite.SQLiteDataAdapter.bmp</INTEROP_ASSEMBLY_RESOURCES>
    23     23       <INTEROP_KEY_FILE>$(ProjectDir)..\Keys\System.Data.SQLite.snk</INTEROP_KEY_FILE>

Changes to SQLite.Interop/props/SQLite.Interop.2013.props.

     6      6    * Written by Joe Mistachkin.
     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
    11     11     <PropertyGroup Label="UserMacros">
    12     12       <ConfigurationYear>2013</ConfigurationYear>
    13         -    <INTEROP_BUILD_NUMBER>105</INTEROP_BUILD_NUMBER>
           13  +    <INTEROP_BUILD_NUMBER>106</INTEROP_BUILD_NUMBER>
    14     14       <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION>
    15         -    <INTEROP_MANIFEST_VERSION>1.0.105.0</INTEROP_MANIFEST_VERSION>
    16         -    <INTEROP_RC_VERSION>1,0,105,0</INTEROP_RC_VERSION>
           15  +    <INTEROP_MANIFEST_VERSION>1.0.106.0</INTEROP_MANIFEST_VERSION>
           16  +    <INTEROP_RC_VERSION>1,0,106,0</INTEROP_RC_VERSION>
    17     17       <INTEROP_INCLUDE_DIRECTORIES>src\core</INTEROP_INCLUDE_DIRECTORIES>
    18     18       <INTEROP_LIBRARY_DIRECTORIES></INTEROP_LIBRARY_DIRECTORIES>
    19     19       <INTEROP_LIBRARY_DEPENDENCIES></INTEROP_LIBRARY_DEPENDENCIES>
    20     20       <INTEROP_DEBUG_DEFINES>INTEROP_DEBUG=0x31F;INTEROP_LOG=1;INTEROP_TEST_EXTENSION=1</INTEROP_DEBUG_DEFINES>
    21     21       <INTEROP_EXTRA_DEFINES>INTEROP_PLACEHOLDER=1;INTEROP_EXTENSION_FUNCTIONS=1;INTEROP_CODEC=1;INTEROP_VIRTUAL_TABLE=1;INTEROP_FTS5_EXTENSION=1;INTEROP_PERCENTILE_EXTENSION=1;INTEROP_TOTYPE_EXTENSION=1;INTEROP_REGEXP_EXTENSION=1;INTEROP_JSON1_EXTENSION=1;INTEROP_SHA1_EXTENSION=1</INTEROP_EXTRA_DEFINES>
    22     22       <INTEROP_ASSEMBLY_RESOURCES>/ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteCommand.bmp,System.Data.SQLite.SQLiteCommand.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteConnection.bmp,System.Data.SQLite.SQLiteConnection.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteDataAdapter.bmp,System.Data.SQLite.SQLiteDataAdapter.bmp</INTEROP_ASSEMBLY_RESOURCES>
    23     23       <INTEROP_KEY_FILE>$(ProjectDir)..\Keys\System.Data.SQLite.snk</INTEROP_KEY_FILE>

Changes to SQLite.Interop/props/SQLite.Interop.2015.props.

     6      6    * Written by Joe Mistachkin.
     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
    11     11     <PropertyGroup Label="UserMacros">
    12     12       <ConfigurationYear>2015</ConfigurationYear>
    13         -    <INTEROP_BUILD_NUMBER>105</INTEROP_BUILD_NUMBER>
           13  +    <INTEROP_BUILD_NUMBER>106</INTEROP_BUILD_NUMBER>
    14     14       <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION>
    15         -    <INTEROP_MANIFEST_VERSION>1.0.105.0</INTEROP_MANIFEST_VERSION>
    16         -    <INTEROP_RC_VERSION>1,0,105,0</INTEROP_RC_VERSION>
           15  +    <INTEROP_MANIFEST_VERSION>1.0.106.0</INTEROP_MANIFEST_VERSION>
           16  +    <INTEROP_RC_VERSION>1,0,106,0</INTEROP_RC_VERSION>
    17     17       <INTEROP_INCLUDE_DIRECTORIES>src\core</INTEROP_INCLUDE_DIRECTORIES>
    18     18       <INTEROP_LIBRARY_DIRECTORIES></INTEROP_LIBRARY_DIRECTORIES>
    19     19       <INTEROP_LIBRARY_DEPENDENCIES></INTEROP_LIBRARY_DEPENDENCIES>
    20     20       <INTEROP_DEBUG_DEFINES>INTEROP_DEBUG=0x31F;INTEROP_LOG=1;INTEROP_TEST_EXTENSION=1</INTEROP_DEBUG_DEFINES>
    21     21       <INTEROP_EXTRA_DEFINES>INTEROP_PLACEHOLDER=1;INTEROP_EXTENSION_FUNCTIONS=1;INTEROP_CODEC=1;INTEROP_VIRTUAL_TABLE=1;INTEROP_FTS5_EXTENSION=1;INTEROP_PERCENTILE_EXTENSION=1;INTEROP_TOTYPE_EXTENSION=1;INTEROP_REGEXP_EXTENSION=1;INTEROP_JSON1_EXTENSION=1;INTEROP_SHA1_EXTENSION=1</INTEROP_EXTRA_DEFINES>
    22     22       <INTEROP_ASSEMBLY_RESOURCES>/ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteCommand.bmp,System.Data.SQLite.SQLiteCommand.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteConnection.bmp,System.Data.SQLite.SQLiteConnection.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteDataAdapter.bmp,System.Data.SQLite.SQLiteDataAdapter.bmp</INTEROP_ASSEMBLY_RESOURCES>
    23     23       <INTEROP_KEY_FILE>$(ProjectDir)..\Keys\System.Data.SQLite.snk</INTEROP_KEY_FILE>

Changes to SQLite.Interop/props/sqlite3.props.

     5      5    *
     6      6    * Written by Joe Mistachkin.
     7      7    * Released to the public domain, use at your own risk!
     8      8    *
     9      9   -->
    10     10   <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
    11     11     <PropertyGroup Label="UserMacros">
    12         -    <SQLITE_MANIFEST_VERSION>3.18.0.0</SQLITE_MANIFEST_VERSION>
    13         -    <SQLITE_RC_VERSION>3,18,0,0</SQLITE_RC_VERSION>
           12  +    <SQLITE_MANIFEST_VERSION>3.19.0.0</SQLITE_MANIFEST_VERSION>
           13  +    <SQLITE_RC_VERSION>3,19,0,0</SQLITE_RC_VERSION>
    14     14       <SQLITE_COMMON_DEFINES>_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;SQLITE_THREADSAFE=1;SQLITE_USE_URI=1;SQLITE_ENABLE_COLUMN_METADATA=1;SQLITE_ENABLE_STAT4=1;SQLITE_ENABLE_FTS3=1;SQLITE_ENABLE_LOAD_EXTENSION=1;SQLITE_ENABLE_RTREE=1;SQLITE_SOUNDEX=1;SQLITE_ENABLE_MEMORY_MANAGEMENT=1;SQLITE_ENABLE_API_ARMOR=1;SQLITE_ENABLE_DBSTAT_VTAB=1</SQLITE_COMMON_DEFINES>
    15     15       <SQLITE_EXTRA_DEFINES>SQLITE_PLACEHOLDER=1;SQLITE_HAS_CODEC=1</SQLITE_EXTRA_DEFINES>
    16     16       <SQLITE_WINCE_200X_DEFINES>SQLITE_OMIT_WAL=1</SQLITE_WINCE_200X_DEFINES>
    17     17       <SQLITE_WINCE_2013_DEFINES>HAVE_ERRNO_H=1;SQLITE_MSVC_LOCALTIME_API=1</SQLITE_WINCE_2013_DEFINES>
    18     18       <SQLITE_DEBUG_DEFINES>SQLITE_DEBUG=1;SQLITE_MEMDEBUG=1;SQLITE_ENABLE_EXPENSIVE_ASSERT=1</SQLITE_DEBUG_DEFINES>
    19     19       <SQLITE_RELEASE_DEFINES>SQLITE_WIN32_MALLOC=1</SQLITE_RELEASE_DEFINES>
    20     20       <SQLITE_DISABLE_WARNINGS>4055;4100;4127;4146;4210;4232;4244;4245;4267;4306;4389;4701;4703;4706</SQLITE_DISABLE_WARNINGS>

Changes to SQLite.Interop/props/sqlite3.vsprops.

    10     10   <VisualStudioPropertySheet
    11     11   	ProjectType="Visual C++"
    12     12   	Version="8.00"
    13     13   	Name="sqlite3"
    14     14   	>
    15     15   	<UserMacro
    16     16   		Name="SQLITE_MANIFEST_VERSION"
    17         -		Value="3.18.0.0"
           17  +		Value="3.19.0.0"
    18     18   		PerformEnvironmentSet="true"
    19     19   	/>
    20     20   	<UserMacro
    21     21   		Name="SQLITE_RC_VERSION"
    22         -		Value="3,18,0,0"
           22  +		Value="3,19,0,0"
    23     23   		PerformEnvironmentSet="true"
    24     24   	/>
    25     25   	<UserMacro
    26     26   		Name="SQLITE_COMMON_DEFINES"
    27     27   		Value="_CRT_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;SQLITE_THREADSAFE=1;SQLITE_USE_URI=1;SQLITE_ENABLE_COLUMN_METADATA=1;SQLITE_ENABLE_STAT4=1;SQLITE_ENABLE_FTS3=1;SQLITE_ENABLE_LOAD_EXTENSION=1;SQLITE_ENABLE_RTREE=1;SQLITE_SOUNDEX=1;SQLITE_ENABLE_MEMORY_MANAGEMENT=1;SQLITE_ENABLE_API_ARMOR=1;SQLITE_ENABLE_DBSTAT_VTAB=1"
    28     28   		PerformEnvironmentSet="true"
    29     29   	/>

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

     1      1   /******************************************************************************
     2      2   ** This file is an amalgamation of many separate C source files from SQLite
     3         -** version 3.18.0.  By combining all the individual C code files into this
            3  +** version 3.19.0.  By combining all the individual C code files into this
     4      4   ** single large file, the entire code can be compiled as a single translation
     5      5   ** unit.  This allows many compilers to do optimizations that would not be
     6      6   ** possible if the files were compiled separately.  Performance improvements
     7      7   ** of 5% or more are commonly seen when SQLite is compiled as a single
     8      8   ** translation unit.
     9      9   **
    10     10   ** This file is all you need to compile SQLite.  To use SQLite in other
................................................................................
   394    394   ** string contains the date and time of the check-in (UTC) and a SHA1
   395    395   ** or SHA3-256 hash of the entire source tree.
   396    396   **
   397    397   ** See also: [sqlite3_libversion()],
   398    398   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   399    399   ** [sqlite_version()] and [sqlite_source_id()].
   400    400   */
   401         -#define SQLITE_VERSION        "3.18.0"
   402         -#define SQLITE_VERSION_NUMBER 3018000
   403         -#define SQLITE_SOURCE_ID      "2017-03-28 18:48:43 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37"
          401  +#define SQLITE_VERSION        "3.19.0"
          402  +#define SQLITE_VERSION_NUMBER 3019000
          403  +#define SQLITE_SOURCE_ID      "2017-05-10 16:33:48 92c5ea7047323d10f762877c5f56d20a3e609e8b55efcfe4880ef3048821ac1f"
   404    404   
   405    405   /*
   406    406   ** CAPI3REF: Run-Time Library Version Numbers
   407    407   ** KEYWORDS: sqlite3_version sqlite3_sourceid
   408    408   **
   409    409   ** These interfaces provide the same information as the [SQLITE_VERSION],
   410    410   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
  1130   1130   ** anti-virus programs.  By default, the windows VFS will retry file read,
  1131   1131   ** file write, and file delete operations up to 10 times, with a delay
  1132   1132   ** of 25 milliseconds before the first retry and with the delay increasing
  1133   1133   ** by an additional 25 milliseconds with each subsequent retry.  This
  1134   1134   ** opcode allows these two values (10 retries and 25 milliseconds of delay)
  1135   1135   ** to be adjusted.  The values are changed for all database connections
  1136   1136   ** within the same process.  The argument is a pointer to an array of two
  1137         -** integers where the first integer i the new retry count and the second
         1137  +** integers where the first integer is the new retry count and the second
  1138   1138   ** integer is the delay.  If either integer is negative, then the setting
  1139   1139   ** is not changed but instead the prior value of that setting is written
  1140   1140   ** into the array entry, allowing the current retry settings to be
  1141   1141   ** interrogated.  The zDbName parameter is ignored.
  1142   1142   **
  1143   1143   ** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
  1144   1144   ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
................................................................................
  2484   2484   ** running statements reaches zero are interrupted as if they had been
  2485   2485   ** running prior to the sqlite3_interrupt() call.  ^New SQL statements
  2486   2486   ** that are started after the running statement count reaches zero are
  2487   2487   ** not effected by the sqlite3_interrupt().
  2488   2488   ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
  2489   2489   ** SQL statements is a no-op and has no effect on SQL statements
  2490   2490   ** that are started after the sqlite3_interrupt() call returns.
  2491         -**
  2492         -** If the database connection closes while [sqlite3_interrupt()]
  2493         -** is running then bad things will likely happen.
  2494   2491   */
  2495   2492   SQLITE_API void sqlite3_interrupt(sqlite3*);
  2496   2493   
  2497   2494   /*
  2498   2495   ** CAPI3REF: Determine If An SQL Statement Is Complete
  2499   2496   **
  2500   2497   ** These routines are useful during command-line input to determine if the
................................................................................
  2949   2946   ** method.
  2950   2947   */
  2951   2948   SQLITE_API void sqlite3_randomness(int N, void *P);
  2952   2949   
  2953   2950   /*
  2954   2951   ** CAPI3REF: Compile-Time Authorization Callbacks
  2955   2952   ** METHOD: sqlite3
         2953  +** KEYWORDS: {authorizer callback}
  2956   2954   **
  2957   2955   ** ^This routine registers an authorizer callback with a particular
  2958   2956   ** [database connection], supplied in the first argument.
  2959   2957   ** ^The authorizer callback is invoked as SQL statements are being compiled
  2960   2958   ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
  2961   2959   ** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()].  ^At various
  2962   2960   ** points during the compilation process, as logic is being created
................................................................................
  2986   2984   ** ^If the action code is [SQLITE_READ]
  2987   2985   ** and the callback returns [SQLITE_IGNORE] then the
  2988   2986   ** [prepared statement] statement is constructed to substitute
  2989   2987   ** a NULL value in place of the table column that would have
  2990   2988   ** been read if [SQLITE_OK] had been returned.  The [SQLITE_IGNORE]
  2991   2989   ** return can be used to deny an untrusted user access to individual
  2992   2990   ** columns of a table.
         2991  +** ^When a table is referenced by a [SELECT] but no column values are
         2992  +** extracted from that table (for example in a query like
         2993  +** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
         2994  +** is invoked once for that table with a NULL column name.
  2993   2995   ** ^If the action code is [SQLITE_DELETE] and the callback returns
  2994   2996   ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
  2995   2997   ** [truncate optimization] is disabled and all rows are deleted individually.
  2996   2998   **
  2997   2999   ** An authorizer is used when [sqlite3_prepare | preparing]
  2998   3000   ** SQL statements from an untrusted source, to ensure that the SQL statements
  2999   3001   ** do not try to access data they are not allowed to see, or that they do not
................................................................................
  3978   3980   ** ^The sqlite3_value object returned by
  3979   3981   ** [sqlite3_column_value()] is unprotected.
  3980   3982   ** Unprotected sqlite3_value objects may only be used with
  3981   3983   ** [sqlite3_result_value()] and [sqlite3_bind_value()].
  3982   3984   ** The [sqlite3_value_blob | sqlite3_value_type()] family of
  3983   3985   ** interfaces require protected sqlite3_value objects.
  3984   3986   */
  3985         -typedef struct Mem sqlite3_value;
         3987  +typedef struct sqlite3_value sqlite3_value;
  3986   3988   
  3987   3989   /*
  3988   3990   ** CAPI3REF: SQL Function Context Object
  3989   3991   **
  3990   3992   ** The context in which an SQL function executes is stored in an
  3991   3993   ** sqlite3_context object.  ^A pointer to an sqlite3_context object
  3992   3994   ** is always first parameter to [application-defined SQL functions].
................................................................................
 11449  11451   #define TK_EXISTS                          20
 11450  11452   #define TK_TEMP                            21
 11451  11453   #define TK_LP                              22
 11452  11454   #define TK_RP                              23
 11453  11455   #define TK_AS                              24
 11454  11456   #define TK_WITHOUT                         25
 11455  11457   #define TK_COMMA                           26
 11456         -#define TK_OR                              27
 11457         -#define TK_AND                             28
 11458         -#define TK_IS                              29
 11459         -#define TK_MATCH                           30
 11460         -#define TK_LIKE_KW                         31
 11461         -#define TK_BETWEEN                         32
 11462         -#define TK_IN                              33
 11463         -#define TK_ISNULL                          34
 11464         -#define TK_NOTNULL                         35
 11465         -#define TK_NE                              36
 11466         -#define TK_EQ                              37
 11467         -#define TK_GT                              38
 11468         -#define TK_LE                              39
 11469         -#define TK_LT                              40
 11470         -#define TK_GE                              41
 11471         -#define TK_ESCAPE                          42
 11472         -#define TK_BITAND                          43
 11473         -#define TK_BITOR                           44
 11474         -#define TK_LSHIFT                          45
 11475         -#define TK_RSHIFT                          46
 11476         -#define TK_PLUS                            47
 11477         -#define TK_MINUS                           48
 11478         -#define TK_STAR                            49
 11479         -#define TK_SLASH                           50
 11480         -#define TK_REM                             51
 11481         -#define TK_CONCAT                          52
 11482         -#define TK_COLLATE                         53
 11483         -#define TK_BITNOT                          54
 11484         -#define TK_ID                              55
 11485         -#define TK_INDEXED                         56
 11486         -#define TK_ABORT                           57
 11487         -#define TK_ACTION                          58
 11488         -#define TK_AFTER                           59
 11489         -#define TK_ANALYZE                         60
 11490         -#define TK_ASC                             61
 11491         -#define TK_ATTACH                          62
 11492         -#define TK_BEFORE                          63
 11493         -#define TK_BY                              64
 11494         -#define TK_CASCADE                         65
 11495         -#define TK_CAST                            66
 11496         -#define TK_COLUMNKW                        67
 11497         -#define TK_CONFLICT                        68
 11498         -#define TK_DATABASE                        69
 11499         -#define TK_DESC                            70
 11500         -#define TK_DETACH                          71
 11501         -#define TK_EACH                            72
 11502         -#define TK_FAIL                            73
 11503         -#define TK_FOR                             74
 11504         -#define TK_IGNORE                          75
 11505         -#define TK_INITIALLY                       76
 11506         -#define TK_INSTEAD                         77
 11507         -#define TK_NO                              78
 11508         -#define TK_KEY                             79
 11509         -#define TK_OF                              80
 11510         -#define TK_OFFSET                          81
 11511         -#define TK_PRAGMA                          82
 11512         -#define TK_RAISE                           83
 11513         -#define TK_RECURSIVE                       84
 11514         -#define TK_REPLACE                         85
 11515         -#define TK_RESTRICT                        86
 11516         -#define TK_ROW                             87
 11517         -#define TK_TRIGGER                         88
 11518         -#define TK_VACUUM                          89
 11519         -#define TK_VIEW                            90
 11520         -#define TK_VIRTUAL                         91
 11521         -#define TK_WITH                            92
 11522         -#define TK_REINDEX                         93
 11523         -#define TK_RENAME                          94
 11524         -#define TK_CTIME_KW                        95
 11525         -#define TK_ANY                             96
        11458  +#define TK_ID                              27
        11459  +#define TK_ABORT                           28
        11460  +#define TK_ACTION                          29
        11461  +#define TK_AFTER                           30
        11462  +#define TK_ANALYZE                         31
        11463  +#define TK_ASC                             32
        11464  +#define TK_ATTACH                          33
        11465  +#define TK_BEFORE                          34
        11466  +#define TK_BY                              35
        11467  +#define TK_CASCADE                         36
        11468  +#define TK_CAST                            37
        11469  +#define TK_COLUMNKW                        38
        11470  +#define TK_CONFLICT                        39
        11471  +#define TK_DATABASE                        40
        11472  +#define TK_DESC                            41
        11473  +#define TK_DETACH                          42
        11474  +#define TK_EACH                            43
        11475  +#define TK_FAIL                            44
        11476  +#define TK_FOR                             45
        11477  +#define TK_IGNORE                          46
        11478  +#define TK_INITIALLY                       47
        11479  +#define TK_INSTEAD                         48
        11480  +#define TK_LIKE_KW                         49
        11481  +#define TK_MATCH                           50
        11482  +#define TK_NO                              51
        11483  +#define TK_KEY                             52
        11484  +#define TK_OF                              53
        11485  +#define TK_OFFSET                          54
        11486  +#define TK_PRAGMA                          55
        11487  +#define TK_RAISE                           56
        11488  +#define TK_RECURSIVE                       57
        11489  +#define TK_REPLACE                         58
        11490  +#define TK_RESTRICT                        59
        11491  +#define TK_ROW                             60
        11492  +#define TK_TRIGGER                         61
        11493  +#define TK_VACUUM                          62
        11494  +#define TK_VIEW                            63
        11495  +#define TK_VIRTUAL                         64
        11496  +#define TK_WITH                            65
        11497  +#define TK_REINDEX                         66
        11498  +#define TK_RENAME                          67
        11499  +#define TK_CTIME_KW                        68
        11500  +#define TK_ANY                             69
        11501  +#define TK_OR                              70
        11502  +#define TK_AND                             71
        11503  +#define TK_IS                              72
        11504  +#define TK_BETWEEN                         73
        11505  +#define TK_IN                              74
        11506  +#define TK_ISNULL                          75
        11507  +#define TK_NOTNULL                         76
        11508  +#define TK_NE                              77
        11509  +#define TK_EQ                              78
        11510  +#define TK_GT                              79
        11511  +#define TK_LE                              80
        11512  +#define TK_LT                              81
        11513  +#define TK_GE                              82
        11514  +#define TK_ESCAPE                          83
        11515  +#define TK_BITAND                          84
        11516  +#define TK_BITOR                           85
        11517  +#define TK_LSHIFT                          86
        11518  +#define TK_RSHIFT                          87
        11519  +#define TK_PLUS                            88
        11520  +#define TK_MINUS                           89
        11521  +#define TK_STAR                            90
        11522  +#define TK_SLASH                           91
        11523  +#define TK_REM                             92
        11524  +#define TK_CONCAT                          93
        11525  +#define TK_COLLATE                         94
        11526  +#define TK_BITNOT                          95
        11527  +#define TK_INDEXED                         96
 11526  11528   #define TK_STRING                          97
 11527  11529   #define TK_JOIN_KW                         98
 11528  11530   #define TK_CONSTRAINT                      99
 11529  11531   #define TK_DEFAULT                        100
 11530  11532   #define TK_NULL                           101
 11531  11533   #define TK_PRIMARY                        102
 11532  11534   #define TK_UNIQUE                         103
................................................................................
 11582  11584   #define TK_AGG_FUNCTION                   153
 11583  11585   #define TK_AGG_COLUMN                     154
 11584  11586   #define TK_UMINUS                         155
 11585  11587   #define TK_UPLUS                          156
 11586  11588   #define TK_REGISTER                       157
 11587  11589   #define TK_VECTOR                         158
 11588  11590   #define TK_SELECT_COLUMN                  159
 11589         -#define TK_ASTERISK                       160
 11590         -#define TK_SPAN                           161
 11591         -#define TK_SPACE                          162
 11592         -#define TK_ILLEGAL                        163
        11591  +#define TK_IF_NULL_ROW                    160
        11592  +#define TK_ASTERISK                       161
        11593  +#define TK_SPAN                           162
        11594  +#define TK_SPACE                          163
        11595  +#define TK_ILLEGAL                        164
 11593  11596   
 11594  11597   /* The token codes above must all fit in 8 bits */
 11595  11598   #define TKFLG_MASK           0xff  
 11596  11599   
 11597  11600   /* Flags that can be added to a token code when it is not
 11598  11601   ** being stored in a u8: */
 11599  11602   #define TKFLG_DONTFOLD       0x100  /* Omit constant folding optimizations */
................................................................................
 12456  12459   ** organized and understandable, and it also helps the resulting code to
 12457  12460   ** run a little faster by using fewer registers for parameter passing.
 12458  12461   */
 12459  12462   struct BtreePayload {
 12460  12463     const void *pKey;       /* Key content for indexes.  NULL for tables */
 12461  12464     sqlite3_int64 nKey;     /* Size of pKey for indexes.  PRIMARY KEY for tabs */
 12462  12465     const void *pData;      /* Data for tables.  NULL for indexes */
 12463         -  struct Mem *aMem;       /* First of nMem value in the unpacked pKey */
        12466  +  sqlite3_value *aMem;    /* First of nMem value in the unpacked pKey */
 12464  12467     u16 nMem;               /* Number of aMem[] value.  Might be zero */
 12465  12468     int nData;              /* Size of pData.  0 if none. */
 12466  12469     int nZero;              /* Extra zero data appended after pData,nData */
 12467  12470   };
 12468  12471   
 12469  12472   SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
 12470  12473                          int flags, int seekResult);
................................................................................
 12586  12589   */
 12587  12590   typedef struct Vdbe Vdbe;
 12588  12591   
 12589  12592   /*
 12590  12593   ** The names of the following types declared in vdbeInt.h are required
 12591  12594   ** for the VdbeOp definition.
 12592  12595   */
 12593         -typedef struct Mem Mem;
        12596  +typedef struct sqlite3_value Mem;
 12594  12597   typedef struct SubProgram SubProgram;
 12595  12598   
 12596  12599   /*
 12597  12600   ** A single instruction of the virtual machine has an opcode
 12598  12601   ** and as many as three operands.  The instruction is recorded
 12599  12602   ** as an instance of the following structure:
 12600  12603   */
................................................................................
 12746  12749   #define OP_Yield          16
 12747  12750   #define OP_MustBeInt      17
 12748  12751   #define OP_Jump           18
 12749  12752   #define OP_Not            19 /* same as TK_NOT, synopsis: r[P2]= !r[P1]    */
 12750  12753   #define OP_Once           20
 12751  12754   #define OP_If             21
 12752  12755   #define OP_IfNot          22
 12753         -#define OP_SeekLT         23 /* synopsis: key=r[P3@P4]                     */
 12754         -#define OP_SeekLE         24 /* synopsis: key=r[P3@P4]                     */
 12755         -#define OP_SeekGE         25 /* synopsis: key=r[P3@P4]                     */
 12756         -#define OP_SeekGT         26 /* synopsis: key=r[P3@P4]                     */
 12757         -#define OP_Or             27 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
 12758         -#define OP_And            28 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
 12759         -#define OP_NoConflict     29 /* synopsis: key=r[P3@P4]                     */
 12760         -#define OP_NotFound       30 /* synopsis: key=r[P3@P4]                     */
 12761         -#define OP_Found          31 /* synopsis: key=r[P3@P4]                     */
 12762         -#define OP_SeekRowid      32 /* synopsis: intkey=r[P3]                     */
 12763         -#define OP_NotExists      33 /* synopsis: intkey=r[P3]                     */
 12764         -#define OP_IsNull         34 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
 12765         -#define OP_NotNull        35 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
 12766         -#define OP_Ne             36 /* same as TK_NE, synopsis: IF r[P3]!=r[P1]   */
 12767         -#define OP_Eq             37 /* same as TK_EQ, synopsis: IF r[P3]==r[P1]   */
 12768         -#define OP_Gt             38 /* same as TK_GT, synopsis: IF r[P3]>r[P1]    */
 12769         -#define OP_Le             39 /* same as TK_LE, synopsis: IF r[P3]<=r[P1]   */
 12770         -#define OP_Lt             40 /* same as TK_LT, synopsis: IF r[P3]<r[P1]    */
 12771         -#define OP_Ge             41 /* same as TK_GE, synopsis: IF r[P3]>=r[P1]   */
 12772         -#define OP_ElseNotEq      42 /* same as TK_ESCAPE                          */
 12773         -#define OP_BitAnd         43 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
 12774         -#define OP_BitOr          44 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
 12775         -#define OP_ShiftLeft      45 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
 12776         -#define OP_ShiftRight     46 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
 12777         -#define OP_Add            47 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
 12778         -#define OP_Subtract       48 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
 12779         -#define OP_Multiply       49 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
 12780         -#define OP_Divide         50 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
 12781         -#define OP_Remainder      51 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
 12782         -#define OP_Concat         52 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
 12783         -#define OP_Last           53
 12784         -#define OP_BitNot         54 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
 12785         -#define OP_IfSmaller      55
 12786         -#define OP_SorterSort     56
 12787         -#define OP_Sort           57
 12788         -#define OP_Rewind         58
 12789         -#define OP_IdxLE          59 /* synopsis: key=r[P3@P4]                     */
 12790         -#define OP_IdxGT          60 /* synopsis: key=r[P3@P4]                     */
 12791         -#define OP_IdxLT          61 /* synopsis: key=r[P3@P4]                     */
 12792         -#define OP_IdxGE          62 /* synopsis: key=r[P3@P4]                     */
 12793         -#define OP_RowSetRead     63 /* synopsis: r[P3]=rowset(P1)                 */
 12794         -#define OP_RowSetTest     64 /* synopsis: if r[P3] in rowset(P1) goto P2   */
 12795         -#define OP_Program        65
 12796         -#define OP_FkIfZero       66 /* synopsis: if fkctr[P1]==0 goto P2          */
 12797         -#define OP_IfPos          67 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
 12798         -#define OP_IfNotZero      68 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
 12799         -#define OP_DecrJumpZero   69 /* synopsis: if (--r[P1])==0 goto P2          */
 12800         -#define OP_IncrVacuum     70
 12801         -#define OP_VNext          71
 12802         -#define OP_Init           72 /* synopsis: Start at P2                      */
 12803         -#define OP_Return         73
 12804         -#define OP_EndCoroutine   74
 12805         -#define OP_HaltIfNull     75 /* synopsis: if r[P3]=null halt               */
 12806         -#define OP_Halt           76
 12807         -#define OP_Integer        77 /* synopsis: r[P2]=P1                         */
 12808         -#define OP_Int64          78 /* synopsis: r[P2]=P4                         */
 12809         -#define OP_String         79 /* synopsis: r[P2]='P4' (len=P1)              */
 12810         -#define OP_Null           80 /* synopsis: r[P2..P3]=NULL                   */
 12811         -#define OP_SoftNull       81 /* synopsis: r[P1]=NULL                       */
 12812         -#define OP_Blob           82 /* synopsis: r[P2]=P4 (len=P1)                */
 12813         -#define OP_Variable       83 /* synopsis: r[P2]=parameter(P1,P4)           */
 12814         -#define OP_Move           84 /* synopsis: r[P2@P3]=r[P1@P3]                */
 12815         -#define OP_Copy           85 /* synopsis: r[P2@P3+1]=r[P1@P3+1]            */
 12816         -#define OP_SCopy          86 /* synopsis: r[P2]=r[P1]                      */
 12817         -#define OP_IntCopy        87 /* synopsis: r[P2]=r[P1]                      */
 12818         -#define OP_ResultRow      88 /* synopsis: output=r[P1@P2]                  */
 12819         -#define OP_CollSeq        89
 12820         -#define OP_Function0      90 /* synopsis: r[P3]=func(r[P2@P5])             */
 12821         -#define OP_Function       91 /* synopsis: r[P3]=func(r[P2@P5])             */
 12822         -#define OP_AddImm         92 /* synopsis: r[P1]=r[P1]+P2                   */
 12823         -#define OP_RealAffinity   93
        12756  +#define OP_IfNullRow      23 /* synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
        12757  +#define OP_SeekLT         24 /* synopsis: key=r[P3@P4]                     */
        12758  +#define OP_SeekLE         25 /* synopsis: key=r[P3@P4]                     */
        12759  +#define OP_SeekGE         26 /* synopsis: key=r[P3@P4]                     */
        12760  +#define OP_SeekGT         27 /* synopsis: key=r[P3@P4]                     */
        12761  +#define OP_NoConflict     28 /* synopsis: key=r[P3@P4]                     */
        12762  +#define OP_NotFound       29 /* synopsis: key=r[P3@P4]                     */
        12763  +#define OP_Found          30 /* synopsis: key=r[P3@P4]                     */
        12764  +#define OP_SeekRowid      31 /* synopsis: intkey=r[P3]                     */
        12765  +#define OP_NotExists      32 /* synopsis: intkey=r[P3]                     */
        12766  +#define OP_Last           33
        12767  +#define OP_IfSmaller      34
        12768  +#define OP_SorterSort     35
        12769  +#define OP_Sort           36
        12770  +#define OP_Rewind         37
        12771  +#define OP_IdxLE          38 /* synopsis: key=r[P3@P4]                     */
        12772  +#define OP_IdxGT          39 /* synopsis: key=r[P3@P4]                     */
        12773  +#define OP_IdxLT          40 /* synopsis: key=r[P3@P4]                     */
        12774  +#define OP_IdxGE          41 /* synopsis: key=r[P3@P4]                     */
        12775  +#define OP_RowSetRead     42 /* synopsis: r[P3]=rowset(P1)                 */
        12776  +#define OP_RowSetTest     43 /* synopsis: if r[P3] in rowset(P1) goto P2   */
        12777  +#define OP_Program        44
        12778  +#define OP_FkIfZero       45 /* synopsis: if fkctr[P1]==0 goto P2          */
        12779  +#define OP_IfPos          46 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
        12780  +#define OP_IfNotZero      47 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
        12781  +#define OP_DecrJumpZero   48 /* synopsis: if (--r[P1])==0 goto P2          */
        12782  +#define OP_IncrVacuum     49
        12783  +#define OP_VNext          50
        12784  +#define OP_Init           51 /* synopsis: Start at P2                      */
        12785  +#define OP_Return         52
        12786  +#define OP_EndCoroutine   53
        12787  +#define OP_HaltIfNull     54 /* synopsis: if r[P3]=null halt               */
        12788  +#define OP_Halt           55
        12789  +#define OP_Integer        56 /* synopsis: r[P2]=P1                         */
        12790  +#define OP_Int64          57 /* synopsis: r[P2]=P4                         */
        12791  +#define OP_String         58 /* synopsis: r[P2]='P4' (len=P1)              */
        12792  +#define OP_Null           59 /* synopsis: r[P2..P3]=NULL                   */
        12793  +#define OP_SoftNull       60 /* synopsis: r[P1]=NULL                       */
        12794  +#define OP_Blob           61 /* synopsis: r[P2]=P4 (len=P1)                */
        12795  +#define OP_Variable       62 /* synopsis: r[P2]=parameter(P1,P4)           */
        12796  +#define OP_Move           63 /* synopsis: r[P2@P3]=r[P1@P3]                */
        12797  +#define OP_Copy           64 /* synopsis: r[P2@P3+1]=r[P1@P3+1]            */
        12798  +#define OP_SCopy          65 /* synopsis: r[P2]=r[P1]                      */
        12799  +#define OP_IntCopy        66 /* synopsis: r[P2]=r[P1]                      */
        12800  +#define OP_ResultRow      67 /* synopsis: output=r[P1@P2]                  */
        12801  +#define OP_CollSeq        68
        12802  +#define OP_Function0      69 /* synopsis: r[P3]=func(r[P2@P5])             */
        12803  +#define OP_Or             70 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
        12804  +#define OP_And            71 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
        12805  +#define OP_Function       72 /* synopsis: r[P3]=func(r[P2@P5])             */
        12806  +#define OP_AddImm         73 /* synopsis: r[P1]=r[P1]+P2                   */
        12807  +#define OP_RealAffinity   74
        12808  +#define OP_IsNull         75 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
        12809  +#define OP_NotNull        76 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
        12810  +#define OP_Ne             77 /* same as TK_NE, synopsis: IF r[P3]!=r[P1]   */
        12811  +#define OP_Eq             78 /* same as TK_EQ, synopsis: IF r[P3]==r[P1]   */
        12812  +#define OP_Gt             79 /* same as TK_GT, synopsis: IF r[P3]>r[P1]    */
        12813  +#define OP_Le             80 /* same as TK_LE, synopsis: IF r[P3]<=r[P1]   */
        12814  +#define OP_Lt             81 /* same as TK_LT, synopsis: IF r[P3]<r[P1]    */
        12815  +#define OP_Ge             82 /* same as TK_GE, synopsis: IF r[P3]>=r[P1]   */
        12816  +#define OP_ElseNotEq      83 /* same as TK_ESCAPE                          */
        12817  +#define OP_BitAnd         84 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
        12818  +#define OP_BitOr          85 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
        12819  +#define OP_ShiftLeft      86 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
        12820  +#define OP_ShiftRight     87 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
        12821  +#define OP_Add            88 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
        12822  +#define OP_Subtract       89 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
        12823  +#define OP_Multiply       90 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
        12824  +#define OP_Divide         91 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
        12825  +#define OP_Remainder      92 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
        12826  +#define OP_Concat         93 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
 12824  12827   #define OP_Cast           94 /* synopsis: affinity(r[P1])                  */
 12825         -#define OP_Permutation    95
 12826         -#define OP_Compare        96 /* synopsis: r[P1@P3] <-> r[P2@P3]            */
        12828  +#define OP_BitNot         95 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
        12829  +#define OP_Permutation    96
 12827  12830   #define OP_String8        97 /* same as TK_STRING, synopsis: r[P2]='P4'    */
 12828         -#define OP_Column         98 /* synopsis: r[P3]=PX                         */
 12829         -#define OP_Affinity       99 /* synopsis: affinity(r[P1@P2])               */
 12830         -#define OP_MakeRecord    100 /* synopsis: r[P3]=mkrec(r[P1@P2])            */
 12831         -#define OP_Count         101 /* synopsis: r[P2]=count()                    */
 12832         -#define OP_ReadCookie    102
 12833         -#define OP_SetCookie     103
 12834         -#define OP_ReopenIdx     104 /* synopsis: root=P2 iDb=P3                   */
 12835         -#define OP_OpenRead      105 /* synopsis: root=P2 iDb=P3                   */
 12836         -#define OP_OpenWrite     106 /* synopsis: root=P2 iDb=P3                   */
 12837         -#define OP_OpenAutoindex 107 /* synopsis: nColumn=P2                       */
 12838         -#define OP_OpenEphemeral 108 /* synopsis: nColumn=P2                       */
 12839         -#define OP_SorterOpen    109
 12840         -#define OP_SequenceTest  110 /* synopsis: if( cursor[P1].ctr++ ) pc = P2   */
 12841         -#define OP_OpenPseudo    111 /* synopsis: P3 columns in r[P2]              */
 12842         -#define OP_Close         112
 12843         -#define OP_ColumnsUsed   113
 12844         -#define OP_Sequence      114 /* synopsis: r[P2]=cursor[P1].ctr++           */
 12845         -#define OP_NewRowid      115 /* synopsis: r[P2]=rowid                      */
 12846         -#define OP_Insert        116 /* synopsis: intkey=r[P3] data=r[P2]          */
 12847         -#define OP_InsertInt     117 /* synopsis: intkey=P3 data=r[P2]             */
 12848         -#define OP_Delete        118
 12849         -#define OP_ResetCount    119
 12850         -#define OP_SorterCompare 120 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
 12851         -#define OP_SorterData    121 /* synopsis: r[P2]=data                       */
 12852         -#define OP_RowData       122 /* synopsis: r[P2]=data                       */
 12853         -#define OP_Rowid         123 /* synopsis: r[P2]=rowid                      */
 12854         -#define OP_NullRow       124
 12855         -#define OP_SorterInsert  125 /* synopsis: key=r[P2]                        */
 12856         -#define OP_IdxInsert     126 /* synopsis: key=r[P2]                        */
 12857         -#define OP_IdxDelete     127 /* synopsis: key=r[P2@P3]                     */
 12858         -#define OP_Seek          128 /* synopsis: Move P3 to P1.rowid              */
 12859         -#define OP_IdxRowid      129 /* synopsis: r[P2]=rowid                      */
 12860         -#define OP_Destroy       130
 12861         -#define OP_Clear         131
        12831  +#define OP_Compare        98 /* synopsis: r[P1@P3] <-> r[P2@P3]            */
        12832  +#define OP_Column         99 /* synopsis: r[P3]=PX                         */
        12833  +#define OP_Affinity      100 /* synopsis: affinity(r[P1@P2])               */
        12834  +#define OP_MakeRecord    101 /* synopsis: r[P3]=mkrec(r[P1@P2])            */
        12835  +#define OP_Count         102 /* synopsis: r[P2]=count()                    */
        12836  +#define OP_ReadCookie    103
        12837  +#define OP_SetCookie     104
        12838  +#define OP_ReopenIdx     105 /* synopsis: root=P2 iDb=P3                   */
        12839  +#define OP_OpenRead      106 /* synopsis: root=P2 iDb=P3                   */
        12840  +#define OP_OpenWrite     107 /* synopsis: root=P2 iDb=P3                   */
        12841  +#define OP_OpenDup       108
        12842  +#define OP_OpenAutoindex 109 /* synopsis: nColumn=P2                       */
        12843  +#define OP_OpenEphemeral 110 /* synopsis: nColumn=P2                       */
        12844  +#define OP_SorterOpen    111
        12845  +#define OP_SequenceTest  112 /* synopsis: if( cursor[P1].ctr++ ) pc = P2   */
        12846  +#define OP_OpenPseudo    113 /* synopsis: P3 columns in r[P2]              */
        12847  +#define OP_Close         114
        12848  +#define OP_ColumnsUsed   115
        12849  +#define OP_Sequence      116 /* synopsis: r[P2]=cursor[P1].ctr++           */
        12850  +#define OP_NewRowid      117 /* synopsis: r[P2]=rowid                      */
        12851  +#define OP_Insert        118 /* synopsis: intkey=r[P3] data=r[P2]          */
        12852  +#define OP_InsertInt     119 /* synopsis: intkey=P3 data=r[P2]             */
        12853  +#define OP_Delete        120
        12854  +#define OP_ResetCount    121
        12855  +#define OP_SorterCompare 122 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
        12856  +#define OP_SorterData    123 /* synopsis: r[P2]=data                       */
        12857  +#define OP_RowData       124 /* synopsis: r[P2]=data                       */
        12858  +#define OP_Rowid         125 /* synopsis: r[P2]=rowid                      */
        12859  +#define OP_NullRow       126
        12860  +#define OP_SorterInsert  127 /* synopsis: key=r[P2]                        */
        12861  +#define OP_IdxInsert     128 /* synopsis: key=r[P2]                        */
        12862  +#define OP_IdxDelete     129 /* synopsis: key=r[P2@P3]                     */
        12863  +#define OP_Seek          130 /* synopsis: Move P3 to P1.rowid              */
        12864  +#define OP_IdxRowid      131 /* synopsis: r[P2]=rowid                      */
 12862  12865   #define OP_Real          132 /* same as TK_FLOAT, synopsis: r[P2]=P4       */
 12863         -#define OP_ResetSorter   133
 12864         -#define OP_CreateIndex   134 /* synopsis: r[P2]=root iDb=P1                */
 12865         -#define OP_CreateTable   135 /* synopsis: r[P2]=root iDb=P1                */
 12866         -#define OP_SqlExec       136
 12867         -#define OP_ParseSchema   137
 12868         -#define OP_LoadAnalysis  138
 12869         -#define OP_DropTable     139
 12870         -#define OP_DropIndex     140
 12871         -#define OP_DropTrigger   141
 12872         -#define OP_IntegrityCk   142
 12873         -#define OP_RowSetAdd     143 /* synopsis: rowset(P1)=r[P2]                 */
 12874         -#define OP_Param         144
 12875         -#define OP_FkCounter     145 /* synopsis: fkctr[P1]+=P2                    */
 12876         -#define OP_MemMax        146 /* synopsis: r[P1]=max(r[P1],r[P2])           */
 12877         -#define OP_OffsetLimit   147 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
 12878         -#define OP_AggStep0      148 /* synopsis: accum=r[P3] step(r[P2@P5])       */
 12879         -#define OP_AggStep       149 /* synopsis: accum=r[P3] step(r[P2@P5])       */
 12880         -#define OP_AggFinal      150 /* synopsis: accum=r[P1] N=P2                 */
 12881         -#define OP_Expire        151
 12882         -#define OP_TableLock     152 /* synopsis: iDb=P1 root=P2 write=P3          */
 12883         -#define OP_VBegin        153
 12884         -#define OP_VCreate       154
 12885         -#define OP_VDestroy      155
 12886         -#define OP_VOpen         156
 12887         -#define OP_VColumn       157 /* synopsis: r[P3]=vcolumn(P2)                */
 12888         -#define OP_VRename       158
 12889         -#define OP_Pagecount     159
 12890         -#define OP_MaxPgcnt      160
 12891         -#define OP_CursorHint    161
 12892         -#define OP_Noop          162
 12893         -#define OP_Explain       163
        12866  +#define OP_Destroy       133
        12867  +#define OP_Clear         134
        12868  +#define OP_ResetSorter   135
        12869  +#define OP_CreateIndex   136 /* synopsis: r[P2]=root iDb=P1                */
        12870  +#define OP_CreateTable   137 /* synopsis: r[P2]=root iDb=P1                */
        12871  +#define OP_SqlExec       138
        12872  +#define OP_ParseSchema   139
        12873  +#define OP_LoadAnalysis  140
        12874  +#define OP_DropTable     141
        12875  +#define OP_DropIndex     142
        12876  +#define OP_DropTrigger   143
        12877  +#define OP_IntegrityCk   144
        12878  +#define OP_RowSetAdd     145 /* synopsis: rowset(P1)=r[P2]                 */
        12879  +#define OP_Param         146
        12880  +#define OP_FkCounter     147 /* synopsis: fkctr[P1]+=P2                    */
        12881  +#define OP_MemMax        148 /* synopsis: r[P1]=max(r[P1],r[P2])           */
        12882  +#define OP_OffsetLimit   149 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
        12883  +#define OP_AggStep0      150 /* synopsis: accum=r[P3] step(r[P2@P5])       */
        12884  +#define OP_AggStep       151 /* synopsis: accum=r[P3] step(r[P2@P5])       */
        12885  +#define OP_AggFinal      152 /* synopsis: accum=r[P1] N=P2                 */
        12886  +#define OP_Expire        153
        12887  +#define OP_TableLock     154 /* synopsis: iDb=P1 root=P2 write=P3          */
        12888  +#define OP_VBegin        155
        12889  +#define OP_VCreate       156
        12890  +#define OP_VDestroy      157
        12891  +#define OP_VOpen         158
        12892  +#define OP_VColumn       159 /* synopsis: r[P3]=vcolumn(P2)                */
        12893  +#define OP_VRename       160
        12894  +#define OP_Pagecount     161
        12895  +#define OP_MaxPgcnt      162
        12896  +#define OP_CursorHint    163
        12897  +#define OP_Noop          164
        12898  +#define OP_Explain       165
 12894  12899   
 12895  12900   /* Properties such as "out2" or "jump" that are specified in
 12896  12901   ** comments following the "case" for each opcode in the vdbe.c
 12897  12902   ** are encoded into bitvectors as follows:
 12898  12903   */
 12899  12904   #define OPFLG_JUMP        0x01  /* jump:  P2 holds jmp target */
 12900  12905   #define OPFLG_IN1         0x02  /* in1:   P1 is an input */
................................................................................
 12901  12906   #define OPFLG_IN2         0x04  /* in2:   P2 is an input */
 12902  12907   #define OPFLG_IN3         0x08  /* in3:   P3 is an input */
 12903  12908   #define OPFLG_OUT2        0x10  /* out2:  P2 is an output */
 12904  12909   #define OPFLG_OUT3        0x20  /* out3:  P3 is an output */
 12905  12910   #define OPFLG_INITIALIZER {\
 12906  12911   /*   0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
 12907  12912   /*   8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\
 12908         -/*  16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x09,\
 12909         -/*  24 */ 0x09, 0x09, 0x09, 0x26, 0x26, 0x09, 0x09, 0x09,\
 12910         -/*  32 */ 0x09, 0x09, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
 12911         -/*  40 */ 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26, 0x26,\
 12912         -/*  48 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x01, 0x12, 0x01,\
 12913         -/*  56 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x23,\
 12914         -/*  64 */ 0x0b, 0x01, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01,\
 12915         -/*  72 */ 0x01, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10,\
 12916         -/*  80 */ 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10,\
 12917         -/*  88 */ 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00,\
 12918         -/*  96 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
        12913  +/*  16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x01,\
        12914  +/*  24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
        12915  +/*  32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
        12916  +/*  40 */ 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01, 0x03, 0x03,\
        12917  +/*  48 */ 0x03, 0x01, 0x01, 0x01, 0x02, 0x02, 0x08, 0x00,\
        12918  +/*  56 */ 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00,\
        12919  +/*  64 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x26, 0x26,\
        12920  +/*  72 */ 0x00, 0x02, 0x02, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
        12921  +/*  80 */ 0x0b, 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26,\
        12922  +/*  88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x02, 0x12,\
        12923  +/*  96 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
 12919  12924   /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
 12920         -/* 112 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
 12921         -/* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00,\
 12922         -/* 128 */ 0x00, 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10,\
 12923         -/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\
 12924         -/* 144 */ 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00,\
 12925         -/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
 12926         -/* 160 */ 0x10, 0x00, 0x00, 0x00,}
        12925  +/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
        12926  +/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x04,\
        12927  +/* 128 */ 0x04, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
        12928  +/* 136 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
        12929  +/* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00,\
        12930  +/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
        12931  +/* 160 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,}
 12927  12932   
 12928  12933   /* The sqlite3P2Values() routine is able to run faster if it knows
 12929  12934   ** the value of the largest JUMP opcode.  The smaller the maximum
 12930  12935   ** JUMP opcode the better, so the mkopcodeh.tcl script that
 12931  12936   ** generated this include file strives to group all JUMP opcodes
 12932  12937   ** together near the beginning of the list.
 12933  12938   */
 12934         -#define SQLITE_MX_JUMP_OPCODE  72  /* Maximum JUMP opcode */
        12939  +#define SQLITE_MX_JUMP_OPCODE  83  /* Maximum JUMP opcode */
 12935  12940   
 12936  12941   /************** End of opcodes.h *********************************************/
 12937  12942   /************** Continuing where we left off in vdbe.h ***********************/
 12938  12943   
 12939  12944   /*
 12940  12945   ** Prototypes for the VDBE interface.  See comments on the implementation
 12941  12946   ** for a description of what each of these routines does.
................................................................................
 15207  15212   ** column expression as it exists in a SELECT statement.  However, if
 15208  15213   ** the bSpanIsTab flag is set, then zSpan is overloaded to mean the name
 15209  15214   ** of the result column in the form: DATABASE.TABLE.COLUMN.  This later
 15210  15215   ** form is used for name resolution with nested FROM clauses.
 15211  15216   */
 15212  15217   struct ExprList {
 15213  15218     int nExpr;             /* Number of expressions on the list */
        15219  +  int nAlloc;            /* Number of a[] slots allocated */
 15214  15220     struct ExprList_item { /* For each expression in the list */
 15215  15221       Expr *pExpr;            /* The parse tree for this expression */
 15216  15222       char *zName;            /* Token associated with this expression */
 15217  15223       char *zSpan;            /* Original text of the expression */
 15218  15224       u8 sortOrder;           /* 1 for DESC or 0 for ASC */
 15219  15225       unsigned done :1;       /* A flag to indicate when processing is finished */
 15220  15226       unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
................................................................................
 15222  15228       union {
 15223  15229         struct {
 15224  15230           u16 iOrderByCol;      /* For ORDER BY, column number in result set */
 15225  15231           u16 iAlias;           /* Index into Parse.aAlias[] for zName */
 15226  15232         } x;
 15227  15233         int iConstExprReg;      /* Register in which Expr value is cached */
 15228  15234       } u;
 15229         -  } *a;                  /* Alloc a power of two greater or equal to nExpr */
        15235  +  } a[1];                  /* One slot for each expression in the list */
 15230  15236   };
 15231  15237   
 15232  15238   /*
 15233  15239   ** An instance of this structure is used by the parser to record both
 15234  15240   ** the parse tree for an expression and the span of input text for an
 15235  15241   ** expression.
 15236  15242   */
................................................................................
 16079  16085     Parse *pParse;                            /* Parser context.  */
 16080  16086     int (*xExprCallback)(Walker*, Expr*);     /* Callback for expressions */
 16081  16087     int (*xSelectCallback)(Walker*,Select*);  /* Callback for SELECTs */
 16082  16088     void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */
 16083  16089     int walkerDepth;                          /* Number of subqueries */
 16084  16090     u8 eCode;                                 /* A small processing code */
 16085  16091     union {                                   /* Extra data for callback */
 16086         -    NameContext *pNC;                          /* Naming context */
 16087         -    int n;                                     /* A counter */
 16088         -    int iCur;                                  /* A cursor number */
 16089         -    SrcList *pSrcList;                         /* FROM clause */
 16090         -    struct SrcCount *pSrcCount;                /* Counting column references */
 16091         -    struct CCurHint *pCCurHint;                /* Used by codeCursorHint() */
 16092         -    int *aiCol;                                /* array of column indexes */
 16093         -    struct IdxCover *pIdxCover;                /* Check for index coverage */
        16092  +    NameContext *pNC;                         /* Naming context */
        16093  +    int n;                                    /* A counter */
        16094  +    int iCur;                                 /* A cursor number */
        16095  +    SrcList *pSrcList;                        /* FROM clause */
        16096  +    struct SrcCount *pSrcCount;               /* Counting column references */
        16097  +    struct CCurHint *pCCurHint;               /* Used by codeCursorHint() */
        16098  +    int *aiCol;                               /* array of column indexes */
        16099  +    struct IdxCover *pIdxCover;               /* Check for index coverage */
        16100  +    struct IdxExprTrans *pIdxTrans;           /* Convert indexed expr to column */
        16101  +    ExprList *pGroupBy;                       /* GROUP BY clause */
        16102  +    struct HavingToWhereCtx *pHavingCtx;      /* HAVING to WHERE clause ctx */
 16094  16103     } u;
 16095  16104   };
 16096  16105   
 16097  16106   /* Forward declarations */
 16098  16107   SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*);
 16099  16108   SQLITE_PRIVATE int sqlite3WalkExprList(Walker*, ExprList*);
 16100  16109   SQLITE_PRIVATE int sqlite3WalkSelect(Walker*, Select*);
................................................................................
 16240  16249   SQLITE_PRIVATE void *sqlite3DbMallocRawNN(sqlite3*, u64);
 16241  16250   SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3*,const char*);
 16242  16251   SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, u64);
 16243  16252   SQLITE_PRIVATE void *sqlite3Realloc(void*, u64);
 16244  16253   SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
 16245  16254   SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
 16246  16255   SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
        16256  +SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
 16247  16257   SQLITE_PRIVATE int sqlite3MallocSize(void*);
 16248  16258   SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*);
 16249  16259   SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
 16250  16260   SQLITE_PRIVATE void sqlite3ScratchFree(void*);
 16251  16261   SQLITE_PRIVATE void *sqlite3PageMalloc(int);
 16252  16262   SQLITE_PRIVATE void sqlite3PageFree(void*);
 16253  16263   SQLITE_PRIVATE void sqlite3MemSetDefault(void);
................................................................................
 16555  16565   SQLITE_PRIVATE void sqlite3RollbackTransaction(Parse*);
 16556  16566   SQLITE_PRIVATE void sqlite3Savepoint(Parse*, int, Token*);
 16557  16567   SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
 16558  16568   SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
 16559  16569   SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
 16560  16570   SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
 16561  16571   SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
        16572  +SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
 16562  16573   SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
 16563  16574   #ifdef SQLITE_ENABLE_CURSOR_HINTS
 16564  16575   SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
 16565  16576   #endif
 16566  16577   SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
 16567  16578   SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
 16568  16579   SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
................................................................................
 17264  17275   **
 17265  17276   ** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled
 17266  17277   ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
 17267  17278   **
 17268  17279   ** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally
 17269  17280   ** disabled. The default value may be changed by compiling with the
 17270  17281   ** SQLITE_USE_URI symbol defined.
        17282  +**
        17283  +** URI filenames are enabled by default if SQLITE_HAS_CODEC is
        17284  +** enabled.
 17271  17285   */
 17272  17286   #ifndef SQLITE_USE_URI
 17273         -# define  SQLITE_USE_URI 0
        17287  +# ifdef SQLITE_HAS_CODEC
        17288  +#  define SQLITE_USE_URI 1
        17289  +# else
        17290  +#  define SQLITE_USE_URI 0
        17291  +# endif
 17274  17292   #endif
 17275  17293   
 17276  17294   /* EVIDENCE-OF: R-38720-18127 The default setting is determined by the
 17277  17295   ** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if
 17278  17296   ** that compile-time option is omitted.
 17279  17297   */
 17280  17298   #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
................................................................................
 18090  18108   #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
 18091  18109   
 18092  18110   /*
 18093  18111   ** Internally, the vdbe manipulates nearly all SQL values as Mem
 18094  18112   ** structures. Each Mem struct may cache multiple representations (string,
 18095  18113   ** integer etc.) of the same value.
 18096  18114   */
 18097         -struct Mem {
        18115  +struct sqlite3_value {
 18098  18116     union MemValue {
 18099  18117       double r;           /* Real value used when MEM_Real is set in flags */
 18100  18118       i64 i;              /* Integer value used when MEM_Int is set in flags */
 18101  18119       int nZero;          /* Used when bit MEM_Zero is set in flags */
 18102  18120       FuncDef *pDef;      /* Used only when flags==MEM_Agg */
 18103  18121       RowSet *pRowSet;    /* Used only when flags==MEM_RowSet */
 18104  18122       VdbeFrame *pFrame;  /* Used when flags==MEM_Frame */
................................................................................
 19220  19238   static void computeYMD(DateTime *p){
 19221  19239     int Z, A, B, C, D, E, X1;
 19222  19240     if( p->validYMD ) return;
 19223  19241     if( !p->validJD ){
 19224  19242       p->Y = 2000;
 19225  19243       p->M = 1;
 19226  19244       p->D = 1;
        19245  +  }else if( !validJulianDay(p->iJD) ){
        19246  +    datetimeError(p);
        19247  +    return;
 19227  19248     }else{
 19228         -    assert( validJulianDay(p->iJD) );
 19229  19249       Z = (int)((p->iJD + 43200000)/86400000);
 19230  19250       A = (int)((Z - 1867216.25)/36524.25);
 19231  19251       A = Z + 1 + A - (A/4);
 19232  19252       B = A + 1524;
 19233  19253       C = (int)((B - 122.1)/365.25);
 19234  19254       D = (36525*(C&32767))/100;
 19235  19255       E = (int)((B-D)/30.6001);
................................................................................
 24657  24677   */
 24658  24678   static SQLITE_NOINLINE void measureAllocationSize(sqlite3 *db, void *p){
 24659  24679     *db->pnBytesFreed += sqlite3DbMallocSize(db,p);
 24660  24680   }
 24661  24681   
 24662  24682   /*
 24663  24683   ** Free memory that might be associated with a particular database
 24664         -** connection.
        24684  +** connection.  Calling sqlite3DbFree(D,X) for X==0 is a harmless no-op.
        24685  +** The sqlite3DbFreeNN(D,X) version requires that X be non-NULL.
 24665  24686   */
 24666         -SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
        24687  +SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3 *db, void *p){
 24667  24688     assert( db==0 || sqlite3_mutex_held(db->mutex) );
 24668         -  if( p==0 ) return;
        24689  +  assert( p!=0 );
 24669  24690     if( db ){
 24670  24691       if( db->pnBytesFreed ){
 24671  24692         measureAllocationSize(db, p);
 24672  24693         return;
 24673  24694       }
 24674  24695       if( isLookaside(db, p) ){
 24675  24696         LookasideSlot *pBuf = (LookasideSlot*)p;
................................................................................
 24684  24705       }
 24685  24706     }
 24686  24707     assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
 24687  24708     assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
 24688  24709     assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
 24689  24710     sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
 24690  24711     sqlite3_free(p);
        24712  +}
        24713  +SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
        24714  +  assert( db==0 || sqlite3_mutex_held(db->mutex) );
        24715  +  if( p ) sqlite3DbFreeNN(db, p);
 24691  24716   }
 24692  24717   
 24693  24718   /*
 24694  24719   ** Change the size of an existing memory allocation
 24695  24720   */
 24696  24721   SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, u64 nBytes){
 24697  24722     int nOld, nNew, nDiff;
................................................................................
 26377  26402   
 26378  26403   /*
 26379  26404   ** Generate a human-readable explanation of an expression tree.
 26380  26405   */
 26381  26406   SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
 26382  26407     const char *zBinOp = 0;   /* Binary operator */
 26383  26408     const char *zUniOp = 0;   /* Unary operator */
 26384         -  char zFlgs[30];
        26409  +  char zFlgs[60];
 26385  26410     pView = sqlite3TreeViewPush(pView, moreToFollow);
 26386  26411     if( pExpr==0 ){
 26387  26412       sqlite3TreeViewLine(pView, "nil");
 26388  26413       sqlite3TreeViewPop(pView);
 26389  26414       return;
 26390  26415     }
 26391  26416     if( pExpr->flags ){
 26392         -    sqlite3_snprintf(sizeof(zFlgs),zFlgs,"  flags=0x%x",pExpr->flags);
        26417  +    if( ExprHasProperty(pExpr, EP_FromJoin) ){
        26418  +      sqlite3_snprintf(sizeof(zFlgs),zFlgs,"  flags=0x%x iRJT=%d",
        26419  +                       pExpr->flags, pExpr->iRightJoinTable);
        26420  +    }else{
        26421  +      sqlite3_snprintf(sizeof(zFlgs),zFlgs,"  flags=0x%x",pExpr->flags);
        26422  +    }
 26393  26423     }else{
 26394  26424       zFlgs[0] = 0;
 26395  26425     }
 26396  26426     switch( pExpr->op ){
 26397  26427       case TK_AGG_COLUMN: {
 26398  26428         sqlite3TreeViewLine(pView, "AGG{%d:%d}%s",
 26399  26429               pExpr->iTable, pExpr->iColumn, zFlgs);
................................................................................
 26603  26633         sqlite3TreeViewBareExprList(pView, pExpr->x.pList, "VECTOR");
 26604  26634         break;
 26605  26635       }
 26606  26636       case TK_SELECT_COLUMN: {
 26607  26637         sqlite3TreeViewLine(pView, "SELECT-COLUMN %d", pExpr->iColumn);
 26608  26638         sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
 26609  26639         break;
        26640  +    }
        26641  +    case TK_IF_NULL_ROW: {
        26642  +      sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable);
        26643  +      sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
        26644  +      break;
 26610  26645       }
 26611  26646       default: {
 26612  26647         sqlite3TreeViewLine(pView, "op=%d", pExpr->op);
 26613  26648         break;
 26614  26649       }
 26615  26650     }
 26616  26651     if( zBinOp ){
................................................................................
 28323  28358         memcpy(pValue, &u, 4);
 28324  28359         return 1;
 28325  28360       }else{
 28326  28361         return 0;
 28327  28362       }
 28328  28363     }
 28329  28364   #endif
        28365  +  if( !sqlite3Isdigit(zNum[0]) ) return 0;
 28330  28366     while( zNum[0]=='0' ) zNum++;
 28331  28367     for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
 28332  28368       v = v*10 + c;
 28333  28369     }
 28334  28370   
 28335  28371     /* The longest decimal representation of a 32 bit integer is 10 digits:
 28336  28372     **
................................................................................
 29486  29522       /*  16 */ "Yield"            OpHelp(""),
 29487  29523       /*  17 */ "MustBeInt"        OpHelp(""),
 29488  29524       /*  18 */ "Jump"             OpHelp(""),
 29489  29525       /*  19 */ "Not"              OpHelp("r[P2]= !r[P1]"),
 29490  29526       /*  20 */ "Once"             OpHelp(""),
 29491  29527       /*  21 */ "If"               OpHelp(""),
 29492  29528       /*  22 */ "IfNot"            OpHelp(""),
 29493         -    /*  23 */ "SeekLT"           OpHelp("key=r[P3@P4]"),
 29494         -    /*  24 */ "SeekLE"           OpHelp("key=r[P3@P4]"),
 29495         -    /*  25 */ "SeekGE"           OpHelp("key=r[P3@P4]"),
 29496         -    /*  26 */ "SeekGT"           OpHelp("key=r[P3@P4]"),
 29497         -    /*  27 */ "Or"               OpHelp("r[P3]=(r[P1] || r[P2])"),
 29498         -    /*  28 */ "And"              OpHelp("r[P3]=(r[P1] && r[P2])"),
 29499         -    /*  29 */ "NoConflict"       OpHelp("key=r[P3@P4]"),
 29500         -    /*  30 */ "NotFound"         OpHelp("key=r[P3@P4]"),
 29501         -    /*  31 */ "Found"            OpHelp("key=r[P3@P4]"),
 29502         -    /*  32 */ "SeekRowid"        OpHelp("intkey=r[P3]"),
 29503         -    /*  33 */ "NotExists"        OpHelp("intkey=r[P3]"),
 29504         -    /*  34 */ "IsNull"           OpHelp("if r[P1]==NULL goto P2"),
 29505         -    /*  35 */ "NotNull"          OpHelp("if r[P1]!=NULL goto P2"),
 29506         -    /*  36 */ "Ne"               OpHelp("IF r[P3]!=r[P1]"),
 29507         -    /*  37 */ "Eq"               OpHelp("IF r[P3]==r[P1]"),
 29508         -    /*  38 */ "Gt"               OpHelp("IF r[P3]>r[P1]"),
 29509         -    /*  39 */ "Le"               OpHelp("IF r[P3]<=r[P1]"),
 29510         -    /*  40 */ "Lt"               OpHelp("IF r[P3]<r[P1]"),
 29511         -    /*  41 */ "Ge"               OpHelp("IF r[P3]>=r[P1]"),
 29512         -    /*  42 */ "ElseNotEq"        OpHelp(""),
 29513         -    /*  43 */ "BitAnd"           OpHelp("r[P3]=r[P1]&r[P2]"),
 29514         -    /*  44 */ "BitOr"            OpHelp("r[P3]=r[P1]|r[P2]"),
 29515         -    /*  45 */ "ShiftLeft"        OpHelp("r[P3]=r[P2]<<r[P1]"),
 29516         -    /*  46 */ "ShiftRight"       OpHelp("r[P3]=r[P2]>>r[P1]"),
 29517         -    /*  47 */ "Add"              OpHelp("r[P3]=r[P1]+r[P2]"),
 29518         -    /*  48 */ "Subtract"         OpHelp("r[P3]=r[P2]-r[P1]"),
 29519         -    /*  49 */ "Multiply"         OpHelp("r[P3]=r[P1]*r[P2]"),
 29520         -    /*  50 */ "Divide"           OpHelp("r[P3]=r[P2]/r[P1]"),
 29521         -    /*  51 */ "Remainder"        OpHelp("r[P3]=r[P2]%r[P1]"),
 29522         -    /*  52 */ "Concat"           OpHelp("r[P3]=r[P2]+r[P1]"),
 29523         -    /*  53 */ "Last"             OpHelp(""),
 29524         -    /*  54 */ "BitNot"           OpHelp("r[P1]= ~r[P1]"),
 29525         -    /*  55 */ "IfSmaller"        OpHelp(""),
 29526         -    /*  56 */ "SorterSort"       OpHelp(""),
 29527         -    /*  57 */ "Sort"             OpHelp(""),
 29528         -    /*  58 */ "Rewind"           OpHelp(""),
 29529         -    /*  59 */ "IdxLE"            OpHelp("key=r[P3@P4]"),
 29530         -    /*  60 */ "IdxGT"            OpHelp("key=r[P3@P4]"),
 29531         -    /*  61 */ "IdxLT"            OpHelp("key=r[P3@P4]"),
 29532         -    /*  62 */ "IdxGE"            OpHelp("key=r[P3@P4]"),
 29533         -    /*  63 */ "RowSetRead"       OpHelp("r[P3]=rowset(P1)"),
 29534         -    /*  64 */ "RowSetTest"       OpHelp("if r[P3] in rowset(P1) goto P2"),
 29535         -    /*  65 */ "Program"          OpHelp(""),
 29536         -    /*  66 */ "FkIfZero"         OpHelp("if fkctr[P1]==0 goto P2"),
 29537         -    /*  67 */ "IfPos"            OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
 29538         -    /*  68 */ "IfNotZero"        OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
 29539         -    /*  69 */ "DecrJumpZero"     OpHelp("if (--r[P1])==0 goto P2"),
 29540         -    /*  70 */ "IncrVacuum"       OpHelp(""),
 29541         -    /*  71 */ "VNext"            OpHelp(""),
 29542         -    /*  72 */ "Init"             OpHelp("Start at P2"),
 29543         -    /*  73 */ "Return"           OpHelp(""),
 29544         -    /*  74 */ "EndCoroutine"     OpHelp(""),
 29545         -    /*  75 */ "HaltIfNull"       OpHelp("if r[P3]=null halt"),
 29546         -    /*  76 */ "Halt"             OpHelp(""),
 29547         -    /*  77 */ "Integer"          OpHelp("r[P2]=P1"),
 29548         -    /*  78 */ "Int64"            OpHelp("r[P2]=P4"),
 29549         -    /*  79 */ "String"           OpHelp("r[P2]='P4' (len=P1)"),
 29550         -    /*  80 */ "Null"             OpHelp("r[P2..P3]=NULL"),
 29551         -    /*  81 */ "SoftNull"         OpHelp("r[P1]=NULL"),
 29552         -    /*  82 */ "Blob"             OpHelp("r[P2]=P4 (len=P1)"),
 29553         -    /*  83 */ "Variable"         OpHelp("r[P2]=parameter(P1,P4)"),
 29554         -    /*  84 */ "Move"             OpHelp("r[P2@P3]=r[P1@P3]"),
 29555         -    /*  85 */ "Copy"             OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
 29556         -    /*  86 */ "SCopy"            OpHelp("r[P2]=r[P1]"),
 29557         -    /*  87 */ "IntCopy"          OpHelp("r[P2]=r[P1]"),
 29558         -    /*  88 */ "ResultRow"        OpHelp("output=r[P1@P2]"),
 29559         -    /*  89 */ "CollSeq"          OpHelp(""),
 29560         -    /*  90 */ "Function0"        OpHelp("r[P3]=func(r[P2@P5])"),
 29561         -    /*  91 */ "Function"         OpHelp("r[P3]=func(r[P2@P5])"),
 29562         -    /*  92 */ "AddImm"           OpHelp("r[P1]=r[P1]+P2"),
 29563         -    /*  93 */ "RealAffinity"     OpHelp(""),
        29529  +    /*  23 */ "IfNullRow"        OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
        29530  +    /*  24 */ "SeekLT"           OpHelp("key=r[P3@P4]"),
        29531  +    /*  25 */ "SeekLE"           OpHelp("key=r[P3@P4]"),
        29532  +    /*  26 */ "SeekGE"           OpHelp("key=r[P3@P4]"),
        29533  +    /*  27 */ "SeekGT"           OpHelp("key=r[P3@P4]"),
        29534  +    /*  28 */ "NoConflict"       OpHelp("key=r[P3@P4]"),
        29535  +    /*  29 */ "NotFound"         OpHelp("key=r[P3@P4]"),
        29536  +    /*  30 */ "Found"            OpHelp("key=r[P3@P4]"),
        29537  +    /*  31 */ "SeekRowid"        OpHelp("intkey=r[P3]"),
        29538  +    /*  32 */ "NotExists"        OpHelp("intkey=r[P3]"),
        29539  +    /*  33 */ "Last"             OpHelp(""),
        29540  +    /*  34 */ "IfSmaller"        OpHelp(""),
        29541  +    /*  35 */ "SorterSort"       OpHelp(""),
        29542  +    /*  36 */ "Sort"             OpHelp(""),
        29543  +    /*  37 */ "Rewind"           OpHelp(""),
        29544  +    /*  38 */ "IdxLE"            OpHelp("key=r[P3@P4]"),
        29545  +    /*  39 */ "IdxGT"            OpHelp("key=r[P3@P4]"),
        29546  +    /*  40 */ "IdxLT"            OpHelp("key=r[P3@P4]"),
        29547  +    /*  41 */ "IdxGE"            OpHelp("key=r[P3@P4]"),
        29548  +    /*  42 */ "RowSetRead"       OpHelp("r[P3]=rowset(P1)"),
        29549  +    /*  43 */ "RowSetTest"       OpHelp("if r[P3] in rowset(P1) goto P2"),
        29550  +    /*  44 */ "Program"          OpHelp(""),
        29551  +    /*  45 */ "FkIfZero"         OpHelp("if fkctr[P1]==0 goto P2"),
        29552  +    /*  46 */ "IfPos"            OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
        29553  +    /*  47 */ "IfNotZero"        OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
        29554  +    /*  48 */ "DecrJumpZero"     OpHelp("if (--r[P1])==0 goto P2"),
        29555  +    /*  49 */ "IncrVacuum"       OpHelp(""),
        29556  +    /*  50 */ "VNext"            OpHelp(""),
        29557  +    /*  51 */ "Init"             OpHelp("Start at P2"),
        29558  +    /*  52 */ "Return"           OpHelp(""),
        29559  +    /*  53 */ "EndCoroutine"     OpHelp(""),
        29560  +    /*  54 */ "HaltIfNull"       OpHelp("if r[P3]=null halt"),
        29561  +    /*  55 */ "Halt"             OpHelp(""),
        29562  +    /*  56 */ "Integer"          OpHelp("r[P2]=P1"),
        29563  +    /*  57 */ "Int64"            OpHelp("r[P2]=P4"),
        29564  +    /*  58 */ "String"           OpHelp("r[P2]='P4' (len=P1)"),
        29565  +    /*  59 */ "Null"             OpHelp("r[P2..P3]=NULL"),
        29566  +    /*  60 */ "SoftNull"         OpHelp("r[P1]=NULL"),
        29567  +    /*  61 */ "Blob"             OpHelp("r[P2]=P4 (len=P1)"),
        29568  +    /*  62 */ "Variable"         OpHelp("r[P2]=parameter(P1,P4)"),
        29569  +    /*  63 */ "Move"             OpHelp("r[P2@P3]=r[P1@P3]"),
        29570  +    /*  64 */ "Copy"             OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
        29571  +    /*  65 */ "SCopy"            OpHelp("r[P2]=r[P1]"),
        29572  +    /*  66 */ "IntCopy"          OpHelp("r[P2]=r[P1]"),
        29573  +    /*  67 */ "ResultRow"        OpHelp("output=r[P1@P2]"),
        29574  +    /*  68 */ "CollSeq"          OpHelp(""),
        29575  +    /*  69 */ "Function0"        OpHelp("r[P3]=func(r[P2@P5])"),
        29576  +    /*  70 */ "Or"               OpHelp("r[P3]=(r[P1] || r[P2])"),
        29577  +    /*  71 */ "And"              OpHelp("r[P3]=(r[P1] && r[P2])"),
        29578  +    /*  72 */ "Function"         OpHelp("r[P3]=func(r[P2@P5])"),
        29579  +    /*  73 */ "AddImm"           OpHelp("r[P1]=r[P1]+P2"),
        29580  +    /*  74 */ "RealAffinity"     OpHelp(""),
        29581  +    /*  75 */ "IsNull"           OpHelp("if r[P1]==NULL goto P2"),
        29582  +    /*  76 */ "NotNull"          OpHelp("if r[P1]!=NULL goto P2"),
        29583  +    /*  77 */ "Ne"               OpHelp("IF r[P3]!=r[P1]"),
        29584  +    /*  78 */ "Eq"               OpHelp("IF r[P3]==r[P1]"),
        29585  +    /*  79 */ "Gt"               OpHelp("IF r[P3]>r[P1]"),
        29586  +    /*  80 */ "Le"               OpHelp("IF r[P3]<=r[P1]"),
        29587  +    /*  81 */ "Lt"               OpHelp("IF r[P3]<r[P1]"),
        29588  +    /*  82 */ "Ge"               OpHelp("IF r[P3]>=r[P1]"),
        29589  +    /*  83 */ "ElseNotEq"        OpHelp(""),
        29590  +    /*  84 */ "BitAnd"           OpHelp("r[P3]=r[P1]&r[P2]"),
        29591  +    /*  85 */ "BitOr"            OpHelp("r[P3]=r[P1]|r[P2]"),
        29592  +    /*  86 */ "ShiftLeft"        OpHelp("r[P3]=r[P2]<<r[P1]"),
        29593  +    /*  87 */ "ShiftRight"       OpHelp("r[P3]=r[P2]>>r[P1]"),
        29594  +    /*  88 */ "Add"              OpHelp("r[P3]=r[P1]+r[P2]"),
        29595  +    /*  89 */ "Subtract"         OpHelp("r[P3]=r[P2]-r[P1]"),
        29596  +    /*  90 */ "Multiply"         OpHelp("r[P3]=r[P1]*r[P2]"),
        29597  +    /*  91 */ "Divide"           OpHelp("r[P3]=r[P2]/r[P1]"),
        29598  +    /*  92 */ "Remainder"        OpHelp("r[P3]=r[P2]%r[P1]"),
        29599  +    /*  93 */ "Concat"           OpHelp("r[P3]=r[P2]+r[P1]"),
 29564  29600       /*  94 */ "Cast"             OpHelp("affinity(r[P1])"),
 29565         -    /*  95 */ "Permutation"      OpHelp(""),
 29566         -    /*  96 */ "Compare"          OpHelp("r[P1@P3] <-> r[P2@P3]"),
        29601  +    /*  95 */ "BitNot"           OpHelp("r[P1]= ~r[P1]"),
        29602  +    /*  96 */ "Permutation"      OpHelp(""),
 29567  29603       /*  97 */ "String8"          OpHelp("r[P2]='P4'"),
 29568         -    /*  98 */ "Column"           OpHelp("r[P3]=PX"),
 29569         -    /*  99 */ "Affinity"         OpHelp("affinity(r[P1@P2])"),
 29570         -    /* 100 */ "MakeRecord"       OpHelp("r[P3]=mkrec(r[P1@P2])"),
 29571         -    /* 101 */ "Count"            OpHelp("r[P2]=count()"),
 29572         -    /* 102 */ "ReadCookie"       OpHelp(""),
 29573         -    /* 103 */ "SetCookie"        OpHelp(""),
 29574         -    /* 104 */ "ReopenIdx"        OpHelp("root=P2 iDb=P3"),
 29575         -    /* 105 */ "OpenRead"         OpHelp("root=P2 iDb=P3"),
 29576         -    /* 106 */ "OpenWrite"        OpHelp("root=P2 iDb=P3"),
 29577         -    /* 107 */ "OpenAutoindex"    OpHelp("nColumn=P2"),
 29578         -    /* 108 */ "OpenEphemeral"    OpHelp("nColumn=P2"),
 29579         -    /* 109 */ "SorterOpen"       OpHelp(""),
 29580         -    /* 110 */ "SequenceTest"     OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
 29581         -    /* 111 */ "OpenPseudo"       OpHelp("P3 columns in r[P2]"),
 29582         -    /* 112 */ "Close"            OpHelp(""),
 29583         -    /* 113 */ "ColumnsUsed"      OpHelp(""),
 29584         -    /* 114 */ "Sequence"         OpHelp("r[P2]=cursor[P1].ctr++"),
 29585         -    /* 115 */ "NewRowid"         OpHelp("r[P2]=rowid"),
 29586         -    /* 116 */ "Insert"           OpHelp("intkey=r[P3] data=r[P2]"),
 29587         -    /* 117 */ "InsertInt"        OpHelp("intkey=P3 data=r[P2]"),
 29588         -    /* 118 */ "Delete"           OpHelp(""),
 29589         -    /* 119 */ "ResetCount"       OpHelp(""),
 29590         -    /* 120 */ "SorterCompare"    OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
 29591         -    /* 121 */ "SorterData"       OpHelp("r[P2]=data"),
 29592         -    /* 122 */ "RowData"          OpHelp("r[P2]=data"),
 29593         -    /* 123 */ "Rowid"            OpHelp("r[P2]=rowid"),
 29594         -    /* 124 */ "NullRow"          OpHelp(""),
 29595         -    /* 125 */ "SorterInsert"     OpHelp("key=r[P2]"),
 29596         -    /* 126 */ "IdxInsert"        OpHelp("key=r[P2]"),
 29597         -    /* 127 */ "IdxDelete"        OpHelp("key=r[P2@P3]"),
 29598         -    /* 128 */ "Seek"             OpHelp("Move P3 to P1.rowid"),
 29599         -    /* 129 */ "IdxRowid"         OpHelp("r[P2]=rowid"),
 29600         -    /* 130 */ "Destroy"          OpHelp(""),
 29601         -    /* 131 */ "Clear"            OpHelp(""),
        29604  +    /*  98 */ "Compare"          OpHelp("r[P1@P3] <-> r[P2@P3]"),
        29605  +    /*  99 */ "Column"           OpHelp("r[P3]=PX"),
        29606  +    /* 100 */ "Affinity"         OpHelp("affinity(r[P1@P2])"),
        29607  +    /* 101 */ "MakeRecord"       OpHelp("r[P3]=mkrec(r[P1@P2])"),
        29608  +    /* 102 */ "Count"            OpHelp("r[P2]=count()"),
        29609  +    /* 103 */ "ReadCookie"       OpHelp(""),
        29610  +    /* 104 */ "SetCookie"        OpHelp(""),
        29611  +    /* 105 */ "ReopenIdx"        OpHelp("root=P2 iDb=P3"),
        29612  +    /* 106 */ "OpenRead"         OpHelp("root=P2 iDb=P3"),
        29613  +    /* 107 */ "OpenWrite"        OpHelp("root=P2 iDb=P3"),
        29614  +    /* 108 */ "OpenDup"          OpHelp(""),
        29615  +    /* 109 */ "OpenAutoindex"    OpHelp("nColumn=P2"),
        29616  +    /* 110 */ "OpenEphemeral"    OpHelp("nColumn=P2"),
        29617  +    /* 111 */ "SorterOpen"       OpHelp(""),
        29618  +    /* 112 */ "SequenceTest"     OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
        29619  +    /* 113 */ "OpenPseudo"       OpHelp("P3 columns in r[P2]"),
        29620  +    /* 114 */ "Close"            OpHelp(""),
        29621  +    /* 115 */ "ColumnsUsed"      OpHelp(""),
        29622  +    /* 116 */ "Sequence"         OpHelp("r[P2]=cursor[P1].ctr++"),
        29623  +    /* 117 */ "NewRowid"         OpHelp("r[P2]=rowid"),
        29624  +    /* 118 */ "Insert"           OpHelp("intkey=r[P3] data=r[P2]"),
        29625  +    /* 119 */ "InsertInt"        OpHelp("intkey=P3 data=r[P2]"),
        29626  +    /* 120 */ "Delete"           OpHelp(""),
        29627  +    /* 121 */ "ResetCount"       OpHelp(""),
        29628  +    /* 122 */ "SorterCompare"    OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
        29629  +    /* 123 */ "SorterData"       OpHelp("r[P2]=data"),
        29630  +    /* 124 */ "RowData"          OpHelp("r[P2]=data"),
        29631  +    /* 125 */ "Rowid"            OpHelp("r[P2]=rowid"),
        29632  +    /* 126 */ "NullRow"          OpHelp(""),
        29633  +    /* 127 */ "SorterInsert"     OpHelp("key=r[P2]"),
        29634  +    /* 128 */ "IdxInsert"        OpHelp("key=r[P2]"),
        29635  +    /* 129 */ "IdxDelete"        OpHelp("key=r[P2@P3]"),
        29636  +    /* 130 */ "Seek"             OpHelp("Move P3 to P1.rowid"),
        29637  +    /* 131 */ "IdxRowid"         OpHelp("r[P2]=rowid"),
 29602  29638       /* 132 */ "Real"             OpHelp("r[P2]=P4"),
 29603         -    /* 133 */ "ResetSorter"      OpHelp(""),
 29604         -    /* 134 */ "CreateIndex"      OpHelp("r[P2]=root iDb=P1"),
 29605         -    /* 135 */ "CreateTable"      OpHelp("r[P2]=root iDb=P1"),
 29606         -    /* 136 */ "SqlExec"          OpHelp(""),
 29607         -    /* 137 */ "ParseSchema"      OpHelp(""),
 29608         -    /* 138 */ "LoadAnalysis"     OpHelp(""),
 29609         -    /* 139 */ "DropTable"        OpHelp(""),
 29610         -    /* 140 */ "DropIndex"        OpHelp(""),
 29611         -    /* 141 */ "DropTrigger"      OpHelp(""),
 29612         -    /* 142 */ "IntegrityCk"      OpHelp(""),
 29613         -    /* 143 */ "RowSetAdd"        OpHelp("rowset(P1)=r[P2]"),
 29614         -    /* 144 */ "Param"            OpHelp(""),
 29615         -    /* 145 */ "FkCounter"        OpHelp("fkctr[P1]+=P2"),
 29616         -    /* 146 */ "MemMax"           OpHelp("r[P1]=max(r[P1],r[P2])"),
 29617         -    /* 147 */ "OffsetLimit"      OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
 29618         -    /* 148 */ "AggStep0"         OpHelp("accum=r[P3] step(r[P2@P5])"),
 29619         -    /* 149 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2@P5])"),
 29620         -    /* 150 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
 29621         -    /* 151 */ "Expire"           OpHelp(""),
 29622         -    /* 152 */ "TableLock"        OpHelp("iDb=P1 root=P2 write=P3"),
 29623         -    /* 153 */ "VBegin"           OpHelp(""),
 29624         -    /* 154 */ "VCreate"          OpHelp(""),
 29625         -    /* 155 */ "VDestroy"         OpHelp(""),
 29626         -    /* 156 */ "VOpen"            OpHelp(""),
 29627         -    /* 157 */ "VColumn"          OpHelp("r[P3]=vcolumn(P2)"),
 29628         -    /* 158 */ "VRename"          OpHelp(""),
 29629         -    /* 159 */ "Pagecount"        OpHelp(""),
 29630         -    /* 160 */ "MaxPgcnt"         OpHelp(""),
 29631         -    /* 161 */ "CursorHint"       OpHelp(""),
 29632         -    /* 162 */ "Noop"             OpHelp(""),
 29633         -    /* 163 */ "Explain"          OpHelp(""),
        29639  +    /* 133 */ "Destroy"          OpHelp(""),
        29640  +    /* 134 */ "Clear"            OpHelp(""),
        29641  +    /* 135 */ "ResetSorter"      OpHelp(""),
        29642  +    /* 136 */ "CreateIndex"      OpHelp("r[P2]=root iDb=P1"),
        29643  +    /* 137 */ "CreateTable"      OpHelp("r[P2]=root iDb=P1"),
        29644  +    /* 138 */ "SqlExec"          OpHelp(""),
        29645  +    /* 139 */ "ParseSchema"      OpHelp(""),
        29646  +    /* 140 */ "LoadAnalysis"     OpHelp(""),
        29647  +    /* 141 */ "DropTable"        OpHelp(""),
        29648  +    /* 142 */ "DropIndex"        OpHelp(""),
        29649  +    /* 143 */ "DropTrigger"      OpHelp(""),
        29650  +    /* 144 */ "IntegrityCk"      OpHelp(""),
        29651  +    /* 145 */ "RowSetAdd"        OpHelp("rowset(P1)=r[P2]"),
        29652  +    /* 146 */ "Param"            OpHelp(""),
        29653  +    /* 147 */ "FkCounter"        OpHelp("fkctr[P1]+=P2"),
        29654  +    /* 148 */ "MemMax"           OpHelp("r[P1]=max(r[P1],r[P2])"),
        29655  +    /* 149 */ "OffsetLimit"      OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
        29656  +    /* 150 */ "AggStep0"         OpHelp("accum=r[P3] step(r[P2@P5])"),
        29657  +    /* 151 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2@P5])"),
        29658  +    /* 152 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
        29659  +    /* 153 */ "Expire"           OpHelp(""),
        29660  +    /* 154 */ "TableLock"        OpHelp("iDb=P1 root=P2 write=P3"),
        29661  +    /* 155 */ "VBegin"           OpHelp(""),
        29662  +    /* 156 */ "VCreate"          OpHelp(""),
        29663  +    /* 157 */ "VDestroy"         OpHelp(""),
        29664  +    /* 158 */ "VOpen"            OpHelp(""),
        29665  +    /* 159 */ "VColumn"          OpHelp("r[P3]=vcolumn(P2)"),
        29666  +    /* 160 */ "VRename"          OpHelp(""),
        29667  +    /* 161 */ "Pagecount"        OpHelp(""),
        29668  +    /* 162 */ "MaxPgcnt"         OpHelp(""),
        29669  +    /* 163 */ "CursorHint"       OpHelp(""),
        29670  +    /* 164 */ "Noop"             OpHelp(""),
        29671  +    /* 165 */ "Explain"          OpHelp(""),
 29634  29672     };
 29635  29673     return azName[i];
 29636  29674   }
 29637  29675   #endif
 29638  29676   
 29639  29677   /************** End of opcodes.c *********************************************/
 29640  29678   /************** Begin file os_unix.c *****************************************/
................................................................................
 45241  45279     if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){
 45242  45280       szBulk = pCache->szAlloc*(i64)pCache->nMax;
 45243  45281     }
 45244  45282     zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
 45245  45283     sqlite3EndBenignMalloc();
 45246  45284     if( zBulk ){
 45247  45285       int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
 45248         -    int i;
 45249         -    for(i=0; i<nBulk; i++){
        45286  +    do{
 45250  45287         PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
 45251  45288         pX->page.pBuf = zBulk;
 45252  45289         pX->page.pExtra = &pX[1];
 45253  45290         pX->isBulkLocal = 1;
 45254  45291         pX->isAnchor = 0;
 45255  45292         pX->pNext = pCache->pFree;
 45256  45293         pCache->pFree = pX;
 45257  45294         zBulk += pCache->szAlloc;
 45258         -    }
        45295  +    }while( --nBulk );
 45259  45296     }
 45260  45297     return pCache->pFree!=0;
 45261  45298   }
 45262  45299   
 45263  45300   /*
 45264  45301   ** Malloc function used within this file to allocate space from the buffer
 45265  45302   ** configured using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no 
................................................................................
 46167  46204   ** been released, the function returns. The return value is the total number 
 46168  46205   ** of bytes of memory released.
 46169  46206   */
 46170  46207   SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
 46171  46208     int nFree = 0;
 46172  46209     assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
 46173  46210     assert( sqlite3_mutex_notheld(pcache1.mutex) );
 46174         -  if( sqlite3GlobalConfig.nPage==0 ){
        46211  +  if( sqlite3GlobalConfig.pPage==0 ){
 46175  46212       PgHdr1 *p;
 46176  46213       pcache1EnterMutex(&pcache1.grp);
 46177  46214       while( (nReq<0 || nFree<nReq)
 46178  46215          &&  (p=pcache1.grp.lru.pLruPrev)!=0
 46179  46216          &&  p->isAnchor==0
 46180  46217       ){
 46181  46218         nFree += pcache1MemSize(p->page.pBuf);
................................................................................
 49127  49164     int rc;
 49128  49165     PgHdr *pPg;                   /* An existing page in the cache */
 49129  49166     Pgno pgno;                    /* The page number of a page in journal */
 49130  49167     u32 cksum;                    /* Checksum used for sanity checking */
 49131  49168     char *aData;                  /* Temporary storage for the page */
 49132  49169     sqlite3_file *jfd;            /* The file descriptor for the journal file */
 49133  49170     int isSynced;                 /* True if journal page is synced */
        49171  +#ifdef SQLITE_HAS_CODEC
        49172  +  /* The jrnlEnc flag is true if Journal pages should be passed through
        49173  +  ** the codec.  It is false for pure in-memory journals. */
        49174  +  const int jrnlEnc = (isMainJrnl || pPager->subjInMemory==0);
        49175  +#endif
 49134  49176   
 49135  49177     assert( (isMainJrnl&~1)==0 );      /* isMainJrnl is 0 or 1 */
 49136  49178     assert( (isSavepnt&~1)==0 );       /* isSavepnt is 0 or 1 */
 49137  49179     assert( isMainJrnl || pDone );     /* pDone always used on sub-journals */
 49138  49180     assert( isSavepnt || pDone==0 );   /* pDone never used on non-savepoint */
 49139  49181   
 49140  49182     aData = pPager->pTmpSpace;
................................................................................
 49250  49292     if( isOpen(pPager->fd)
 49251  49293      && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
 49252  49294      && isSynced
 49253  49295     ){
 49254  49296       i64 ofst = (pgno-1)*(i64)pPager->pageSize;
 49255  49297       testcase( !isSavepnt && pPg!=0 && (pPg->flags&PGHDR_NEED_SYNC)!=0 );
 49256  49298       assert( !pagerUseWal(pPager) );
        49299  +
        49300  +    /* Write the data read from the journal back into the database file.
        49301  +    ** This is usually safe even for an encrypted database - as the data
        49302  +    ** was encrypted before it was written to the journal file. The exception
        49303  +    ** is if the data was just read from an in-memory sub-journal. In that
        49304  +    ** case it must be encrypted here before it is copied into the database
        49305  +    ** file.  */
        49306  +#ifdef SQLITE_HAS_CODEC
        49307  +    if( !jrnlEnc ){
        49308  +      CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT, aData);
        49309  +      rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst);
        49310  +      CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT);
        49311  +    }else
        49312  +#endif
 49257  49313       rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst);
        49314  +
 49258  49315       if( pgno>pPager->dbFileSize ){
 49259  49316         pPager->dbFileSize = pgno;
 49260  49317       }
 49261  49318       if( pPager->pBackup ){
 49262         -      CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT);
        49319  +#ifdef SQLITE_HAS_CODEC
        49320  +      if( jrnlEnc ){
        49321  +        CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT);
        49322  +        sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData);
        49323  +        CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT,aData);
        49324  +      }else
        49325  +#endif
 49263  49326         sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData);
 49264         -      CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT, aData);
 49265  49327       }
 49266  49328     }else if( !isMainJrnl && pPg==0 ){
 49267  49329       /* If this is a rollback of a savepoint and data was not written to
 49268  49330       ** the database and the page is not in-memory, there is a potential
 49269  49331       ** problem. When the page is next fetched by the b-tree layer, it 
 49270  49332       ** will be read from the database file, which may or may not be 
 49271  49333       ** current. 
................................................................................
 49309  49371       /* If this was page 1, then restore the value of Pager.dbFileVers.
 49310  49372       ** Do this before any decoding. */
 49311  49373       if( pgno==1 ){
 49312  49374         memcpy(&pPager->dbFileVers, &((u8*)pData)[24],sizeof(pPager->dbFileVers));
 49313  49375       }
 49314  49376   
 49315  49377       /* Decode the page just read from disk */
 49316         -    CODEC1(pPager, pData, pPg->pgno, 3, rc=SQLITE_NOMEM_BKPT);
        49378  +#if SQLITE_HAS_CODEC
        49379  +    if( jrnlEnc ){ CODEC1(pPager, pData, pPg->pgno, 3, rc=SQLITE_NOMEM_BKPT); }
        49380  +#endif
 49317  49381       sqlite3PcacheRelease(pPg);
 49318  49382     }
 49319  49383     return rc;
 49320  49384   }
 49321  49385   
 49322  49386   /*
 49323  49387   ** Parameter zMaster is the name of a master journal file. A single journal
................................................................................
 51321  51385   
 51322  51386       /* If the sub-journal was opened successfully (or was already open),
 51323  51387       ** write the journal record into the file.  */
 51324  51388       if( rc==SQLITE_OK ){
 51325  51389         void *pData = pPg->pData;
 51326  51390         i64 offset = (i64)pPager->nSubRec*(4+pPager->pageSize);
 51327  51391         char *pData2;
 51328         -  
 51329         -      CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM_BKPT, pData2);
        51392  +
        51393  +#if SQLITE_HAS_CODEC   
        51394  +      if( !pPager->subjInMemory ){
        51395  +        CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM_BKPT, pData2);
        51396  +      }else
        51397  +#endif
        51398  +      pData2 = pData;
 51330  51399         PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
 51331  51400         rc = write32bits(pPager->sjfd, offset, pPg->pgno);
 51332  51401         if( rc==SQLITE_OK ){
 51333  51402           rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4);
 51334  51403         }
 51335  51404       }
 51336  51405     }
................................................................................
 58474  58543     u8 eState;                /* One of the CURSOR_XXX constants (see below) */
 58475  58544     u8 hints;                 /* As configured by CursorSetHints() */
 58476  58545     /* All fields above are zeroed when the cursor is allocated.  See
 58477  58546     ** sqlite3BtreeCursorZero().  Fields that follow must be manually
 58478  58547     ** initialized. */
 58479  58548     i8 iPage;                 /* Index of current page in apPage */
 58480  58549     u8 curIntKey;             /* Value of apPage[0]->intKey */
 58481         -  struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */
 58482         -  void *padding1;           /* Make object size a multiple of 16 */
 58483         -  u16 aiIdx[BTCURSOR_MAX_DEPTH];        /* Current index in apPage[i] */
 58484         -  MemPage *apPage[BTCURSOR_MAX_DEPTH];  /* Pages from root to current page */
        58550  +  u16 ix;                   /* Current index for apPage[iPage] */
        58551  +  u16 aiIdx[BTCURSOR_MAX_DEPTH-1];     /* Current index in apPage[i] */
        58552  +  struct KeyInfo *pKeyInfo;            /* Arg passed to comparison function */
        58553  +  MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */
 58485  58554   };
 58486  58555   
 58487  58556   /*
 58488  58557   ** Legal values for BtCursor.curFlags
 58489  58558   */
 58490  58559   #define BTCF_WriteFlag    0x01   /* True if a write cursor */
 58491  58560   #define BTCF_ValidNKey    0x02   /* True if info.nKey is valid */
................................................................................
 59453  59522   **
 59454  59523   ** Otherwise, if argument isClearTable is false, then the row with
 59455  59524   ** rowid iRow is being replaced or deleted. In this case invalidate
 59456  59525   ** only those incrblob cursors open on that specific row.
 59457  59526   */
 59458  59527   static void invalidateIncrblobCursors(
 59459  59528     Btree *pBtree,          /* The database file to check */
        59529  +  Pgno pgnoRoot,          /* The table that might be changing */
 59460  59530     i64 iRow,               /* The rowid that might be changing */
 59461  59531     int isClearTable        /* True if all rows are being deleted */
 59462  59532   ){
 59463  59533     BtCursor *p;
 59464  59534     if( pBtree->hasIncrblobCur==0 ) return;
 59465  59535     assert( sqlite3BtreeHoldsMutex(pBtree) );
 59466  59536     pBtree->hasIncrblobCur = 0;
 59467  59537     for(p=pBtree->pBt->pCursor; p; p=p->pNext){
 59468  59538       if( (p->curFlags & BTCF_Incrblob)!=0 ){
 59469  59539         pBtree->hasIncrblobCur = 1;
 59470         -      if( isClearTable || p->info.nKey==iRow ){
        59540  +      if( p->pgnoRoot==pgnoRoot && (isClearTable || p->info.nKey==iRow) ){
 59471  59541           p->eState = CURSOR_INVALID;
 59472  59542         }
 59473  59543       }
 59474  59544     }
 59475  59545   }
 59476  59546   
 59477  59547   #else
 59478  59548     /* Stub function when INCRBLOB is omitted */
 59479         -  #define invalidateIncrblobCursors(x,y,z)
        59549  +  #define invalidateIncrblobCursors(w,x,y,z)
 59480  59550   #endif /* SQLITE_OMIT_INCRBLOB */
 59481  59551   
 59482  59552   /*
 59483  59553   ** Set bit pgno of the BtShared.pHasContent bitvec. This is called 
 59484  59554   ** when a page that previously contained data becomes a free-list leaf 
 59485  59555   ** page.
 59486  59556   **
................................................................................
 63270  63340   ** Using this cache reduces the number of calls to btreeParseCell().
 63271  63341   */
 63272  63342   #ifndef NDEBUG
 63273  63343     static void assertCellInfo(BtCursor *pCur){
 63274  63344       CellInfo info;
 63275  63345       int iPage = pCur->iPage;
 63276  63346       memset(&info, 0, sizeof(info));
 63277         -    btreeParseCell(pCur->apPage[iPage], pCur->aiIdx[iPage], &info);
        63347  +    btreeParseCell(pCur->apPage[iPage], pCur->ix, &info);
 63278  63348       assert( CORRUPT_DB || memcmp(&info, &pCur->info, sizeof(info))==0 );
 63279  63349     }
 63280  63350   #else
 63281  63351     #define assertCellInfo(x)
 63282  63352   #endif
 63283  63353   static SQLITE_NOINLINE void getCellInfo(BtCursor *pCur){
 63284  63354     if( pCur->info.nSize==0 ){
 63285  63355       int iPage = pCur->iPage;
 63286  63356       pCur->curFlags |= BTCF_ValidNKey;
 63287         -    btreeParseCell(pCur->apPage[iPage],pCur->aiIdx[iPage],&pCur->info);
        63357  +    btreeParseCell(pCur->apPage[iPage],pCur->ix,&pCur->info);
 63288  63358     }else{
 63289  63359       assertCellInfo(pCur);
 63290  63360     }
 63291  63361   }
 63292  63362   
 63293  63363   #ifndef NDEBUG  /* The next routine used only within assert() statements */
 63294  63364   /*
................................................................................
 63487  63557   #ifdef SQLITE_DIRECT_OVERFLOW_READ
 63488  63558     unsigned char * const pBufStart = pBuf;     /* Start of original out buffer */
 63489  63559   #endif
 63490  63560   
 63491  63561     assert( pPage );
 63492  63562     assert( eOp==0 || eOp==1 );
 63493  63563     assert( pCur->eState==CURSOR_VALID );
 63494         -  assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
        63564  +  assert( pCur->ix<pPage->nCell );
 63495  63565     assert( cursorHoldsMutex(pCur) );
 63496  63566   
 63497  63567     getCellInfo(pCur);
 63498  63568     aPayload = pCur->info.pPayload;
 63499  63569     assert( offset+amt <= pCur->info.nPayload );
 63500  63570   
 63501  63571     assert( aPayload > pPage->aData );
................................................................................
 63674  63744   ** wrong.  An error is returned if "offset+amt" is larger than
 63675  63745   ** the available payload.
 63676  63746   */
 63677  63747   SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
 63678  63748     assert( cursorHoldsMutex(pCur) );
 63679  63749     assert( pCur->eState==CURSOR_VALID );
 63680  63750     assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
 63681         -  assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
        63751  +  assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
 63682  63752     return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
 63683  63753   }
 63684  63754   
 63685  63755   /*
 63686  63756   ** This variant of sqlite3BtreePayload() works even if the cursor has not
 63687  63757   ** in the CURSOR_VALID state.  It is only used by the sqlite3_blob_read()
 63688  63758   ** interface.
................................................................................
 63736  63806     u32 *pAmt            /* Write the number of available bytes here */
 63737  63807   ){
 63738  63808     u32 amt;
 63739  63809     assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
 63740  63810     assert( pCur->eState==CURSOR_VALID );
 63741  63811     assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
 63742  63812     assert( cursorOwnsBtShared(pCur) );
 63743         -  assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
        63813  +  assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
 63744  63814     assert( pCur->info.nSize>0 );
 63745  63815     assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB );
 63746  63816     assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB);
 63747  63817     amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload);
 63748  63818     if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
 63749  63819     *pAmt = amt;
 63750  63820     return (void*)pCur->info.pPayload;
................................................................................
 63787  63857     assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
 63788  63858     assert( pCur->iPage>=0 );
 63789  63859     if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
 63790  63860       return SQLITE_CORRUPT_BKPT;
 63791  63861     }
 63792  63862     pCur->info.nSize = 0;
 63793  63863     pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
 63794         -  pCur->iPage++;
 63795         -  pCur->aiIdx[pCur->iPage] = 0;
        63864  +  pCur->aiIdx[pCur->iPage++] = pCur->ix;
        63865  +  pCur->ix = 0;
 63796  63866     return getAndInitPage(pBt, newPgno, &pCur->apPage[pCur->iPage],
 63797  63867                           pCur, pCur->curPagerFlags);
 63798  63868   }
 63799  63869   
 63800  63870   #ifdef SQLITE_DEBUG
 63801  63871   /*
 63802  63872   ** Page pParent is an internal (non-leaf) tree page. This function 
................................................................................
 63836  63906       pCur->apPage[pCur->iPage-1], 
 63837  63907       pCur->aiIdx[pCur->iPage-1], 
 63838  63908       pCur->apPage[pCur->iPage]->pgno
 63839  63909     );
 63840  63910     testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell );
 63841  63911     pCur->info.nSize = 0;
 63842  63912     pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
        63913  +  pCur->ix = pCur->aiIdx[pCur->iPage-1];
 63843  63914     releasePageNotNull(pCur->apPage[pCur->iPage--]);
 63844  63915   }
 63845  63916   
 63846  63917   /*
 63847  63918   ** Move the cursor to point to the root page of its b-tree structure.
 63848  63919   **
 63849  63920   ** If the table has a virtual root page, then the cursor is moved to point
................................................................................
 63917  63988     ** (or the freelist).  */
 63918  63989     assert( pRoot->intKey==1 || pRoot->intKey==0 );
 63919  63990     if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
 63920  63991       return SQLITE_CORRUPT_BKPT;
 63921  63992     }
 63922  63993   
 63923  63994   skip_init:  
 63924         -  pCur->aiIdx[0] = 0;
        63995  +  pCur->ix = 0;
 63925  63996     pCur->info.nSize = 0;
 63926  63997     pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidNKey|BTCF_ValidOvfl);
 63927  63998   
 63928  63999     pRoot = pCur->apPage[0];
 63929  64000     if( pRoot->nCell>0 ){
 63930  64001       pCur->eState = CURSOR_VALID;
 63931  64002     }else if( !pRoot->leaf ){
................................................................................
 63951  64022     Pgno pgno;
 63952  64023     int rc = SQLITE_OK;
 63953  64024     MemPage *pPage;
 63954  64025   
 63955  64026     assert( cursorOwnsBtShared(pCur) );
 63956  64027     assert( pCur->eState==CURSOR_VALID );
 63957  64028     while( rc==SQLITE_OK && !(pPage = pCur->apPage[pCur->iPage])->leaf ){
 63958         -    assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
 63959         -    pgno = get4byte(findCell(pPage, pCur->aiIdx[pCur->iPage]));
        64029  +    assert( pCur->ix<pPage->nCell );
        64030  +    pgno = get4byte(findCell(pPage, pCur->ix));
 63960  64031       rc = moveToChild(pCur, pgno);
 63961  64032     }
 63962  64033     return rc;
 63963  64034   }
 63964  64035   
 63965  64036   /*
 63966  64037   ** Move the cursor down to the right-most leaf entry beneath the
................................................................................
 63977  64048     int rc = SQLITE_OK;
 63978  64049     MemPage *pPage = 0;
 63979  64050   
 63980  64051     assert( cursorOwnsBtShared(pCur) );
 63981  64052     assert( pCur->eState==CURSOR_VALID );
 63982  64053     while( !(pPage = pCur->apPage[pCur->iPage])->leaf ){
 63983  64054       pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
 63984         -    pCur->aiIdx[pCur->iPage] = pPage->nCell;
        64055  +    pCur->ix = pPage->nCell;
 63985  64056       rc = moveToChild(pCur, pgno);
 63986  64057       if( rc ) return rc;
 63987  64058     }
 63988         -  pCur->aiIdx[pCur->iPage] = pPage->nCell-1;
        64059  +  pCur->ix = pPage->nCell-1;
 63989  64060     assert( pCur->info.nSize==0 );
 63990  64061     assert( (pCur->curFlags & BTCF_ValidNKey)==0 );
 63991  64062     return SQLITE_OK;
 63992  64063   }
 63993  64064   
 63994  64065   /* Move the cursor to the first entry in the table.  Return SQLITE_OK
 63995  64066   ** on success.  Set *pRes to 0 if the cursor actually points to something
................................................................................
 64029  64100   #ifdef SQLITE_DEBUG
 64030  64101       /* This block serves to assert() that the cursor really does point 
 64031  64102       ** to the last entry in the b-tree. */
 64032  64103       int ii;
 64033  64104       for(ii=0; ii<pCur->iPage; ii++){
 64034  64105         assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell );
 64035  64106       }
 64036         -    assert( pCur->aiIdx[pCur->iPage]==pCur->apPage[pCur->iPage]->nCell-1 );
        64107  +    assert( pCur->ix==pCur->apPage[pCur->iPage]->nCell-1 );
 64037  64108       assert( pCur->apPage[pCur->iPage]->leaf );
 64038  64109   #endif
 64039  64110       return SQLITE_OK;
 64040  64111     }
 64041  64112   
 64042  64113     rc = moveToRoot(pCur);
 64043  64114     if( rc==SQLITE_OK ){
................................................................................
 64176  64247       ** a moveToChild() or moveToRoot() call would have detected corruption.  */
 64177  64248       assert( pPage->nCell>0 );
 64178  64249       assert( pPage->intKey==(pIdxKey==0) );
 64179  64250       lwr = 0;
 64180  64251       upr = pPage->nCell-1;
 64181  64252       assert( biasRight==0 || biasRight==1 );
 64182  64253       idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */
 64183         -    pCur->aiIdx[pCur->iPage] = (u16)idx;
        64254  +    pCur->ix = (u16)idx;
 64184  64255       if( xRecordCompare==0 ){
 64185  64256         for(;;){
 64186  64257           i64 nCellKey;
 64187  64258           pCell = findCellPastPtr(pPage, idx);
 64188  64259           if( pPage->intKeyLeaf ){
 64189  64260             while( 0x80 <= *(pCell++) ){
 64190  64261               if( pCell>=pPage->aDataEnd ) return SQLITE_CORRUPT_BKPT;
................................................................................
 64195  64266             lwr = idx+1;
 64196  64267             if( lwr>upr ){ c = -1; break; }
 64197  64268           }else if( nCellKey>intKey ){
 64198  64269             upr = idx-1;
 64199  64270             if( lwr>upr ){ c = +1; break; }
 64200  64271           }else{
 64201  64272             assert( nCellKey==intKey );
 64202         -          pCur->aiIdx[pCur->iPage] = (u16)idx;
        64273  +          pCur->ix = (u16)idx;
 64203  64274             if( !pPage->leaf ){
 64204  64275               lwr = idx;
 64205  64276               goto moveto_next_layer;
 64206  64277             }else{
 64207  64278               pCur->curFlags |= BTCF_ValidNKey;
 64208  64279               pCur->info.nKey = nCellKey;
 64209  64280               pCur->info.nSize = 0;
................................................................................
 64264  64335               goto moveto_finish;
 64265  64336             }
 64266  64337             pCellKey = sqlite3Malloc( nCell+18 );
 64267  64338             if( pCellKey==0 ){
 64268  64339               rc = SQLITE_NOMEM_BKPT;
 64269  64340               goto moveto_finish;
 64270  64341             }
 64271         -          pCur->aiIdx[pCur->iPage] = (u16)idx;
        64342  +          pCur->ix = (u16)idx;
 64272  64343             rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
 64273  64344             pCur->curFlags &= ~BTCF_ValidOvfl;
 64274  64345             if( rc ){
 64275  64346               sqlite3_free(pCellKey);
 64276  64347               goto moveto_finish;
 64277  64348             }
 64278  64349             c = xRecordCompare(nCell, pCellKey, pIdxKey);
................................................................................
 64286  64357             lwr = idx+1;
 64287  64358           }else if( c>0 ){
 64288  64359             upr = idx-1;
 64289  64360           }else{
 64290  64361             assert( c==0 );
 64291  64362             *pRes = 0;
 64292  64363             rc = SQLITE_OK;
 64293         -          pCur->aiIdx[pCur->iPage] = (u16)idx;
        64364  +          pCur->ix = (u16)idx;
 64294  64365             if( pIdxKey->errCode ) rc = SQLITE_CORRUPT;
 64295  64366             goto moveto_finish;
 64296  64367           }
 64297  64368           if( lwr>upr ) break;
 64298  64369           assert( lwr+upr>=0 );
 64299  64370           idx = (lwr+upr)>>1;  /* idx = (lwr+upr)/2 */
 64300  64371         }
 64301  64372       }
 64302  64373       assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
 64303  64374       assert( pPage->isInit );
 64304  64375       if( pPage->leaf ){
 64305         -      assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
 64306         -      pCur->aiIdx[pCur->iPage] = (u16)idx;
        64376  +      assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
        64377  +      pCur->ix = (u16)idx;
 64307  64378         *pRes = c;
 64308  64379         rc = SQLITE_OK;
 64309  64380         goto moveto_finish;
 64310  64381       }
 64311  64382   moveto_next_layer:
 64312  64383       if( lwr>=pPage->nCell ){
 64313  64384         chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
 64314  64385       }else{
 64315  64386         chldPg = get4byte(findCell(pPage, lwr));
 64316  64387       }
 64317         -    pCur->aiIdx[pCur->iPage] = (u16)lwr;
        64388  +    pCur->ix = (u16)lwr;
 64318  64389       rc = moveToChild(pCur, chldPg);
 64319  64390       if( rc ) break;
 64320  64391     }
 64321  64392   moveto_finish:
 64322  64393     pCur->info.nSize = 0;
 64323  64394     assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
 64324  64395     return rc;
................................................................................
 64411  64482           return SQLITE_OK;
 64412  64483         }
 64413  64484         pCur->skipNext = 0;
 64414  64485       }
 64415  64486     }
 64416  64487   
 64417  64488     pPage = pCur->apPage[pCur->iPage];
 64418         -  idx = ++pCur->aiIdx[pCur->iPage];
        64489  +  idx = ++pCur->ix;
 64419  64490     assert( pPage->isInit );
 64420  64491   
 64421  64492     /* If the database file is corrupt, it is possible for the value of idx 
 64422  64493     ** to be invalid here. This can only occur if a second cursor modifies
 64423  64494     ** the page while cursor pCur is holding a reference to it. Which can
 64424  64495     ** only happen if the database is corrupt in such a way as to link the
 64425  64496     ** page into more than one b-tree structure. */
................................................................................
 64435  64506         if( pCur->iPage==0 ){
 64436  64507           *pRes = 1;
 64437  64508           pCur->eState = CURSOR_INVALID;
 64438  64509           return SQLITE_OK;
 64439  64510         }
 64440  64511         moveToParent(pCur);
 64441  64512         pPage = pCur->apPage[pCur->iPage];
 64442         -    }while( pCur->aiIdx[pCur->iPage]>=pPage->nCell );
        64513  +    }while( pCur->ix>=pPage->nCell );
 64443  64514       if( pPage->intKey ){
 64444  64515         return sqlite3BtreeNext(pCur, pRes);
 64445  64516       }else{
 64446  64517         return SQLITE_OK;
 64447  64518       }
 64448  64519     }
 64449  64520     if( pPage->leaf ){
................................................................................
 64459  64530     assert( *pRes==0 || *pRes==1 );
 64460  64531     assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
 64461  64532     pCur->info.nSize = 0;
 64462  64533     pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
 64463  64534     *pRes = 0;
 64464  64535     if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur, pRes);
 64465  64536     pPage = pCur->apPage[pCur->iPage];
 64466         -  if( (++pCur->aiIdx[pCur->iPage])>=pPage->nCell ){
 64467         -    pCur->aiIdx[pCur->iPage]--;
        64537  +  if( (++pCur->ix)>=pPage->nCell ){
        64538  +    pCur->ix--;
 64468  64539       return btreeNext(pCur, pRes);
 64469  64540     }
 64470  64541     if( pPage->leaf ){
 64471  64542       return SQLITE_OK;
 64472  64543     }else{
 64473  64544       return moveToLeftmost(pCur);
 64474  64545     }
................................................................................
 64524  64595         pCur->skipNext = 0;
 64525  64596       }
 64526  64597     }
 64527  64598   
 64528  64599     pPage = pCur->apPage[pCur->iPage];
 64529  64600     assert( pPage->isInit );
 64530  64601     if( !pPage->leaf ){
 64531         -    int idx = pCur->aiIdx[pCur->iPage];
        64602  +    int idx = pCur->ix;
 64532  64603       rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
 64533  64604       if( rc ) return rc;
 64534  64605       rc = moveToRightmost(pCur);
 64535  64606     }else{
 64536         -    while( pCur->aiIdx[pCur->iPage]==0 ){
        64607  +    while( pCur->ix==0 ){
 64537  64608         if( pCur->iPage==0 ){
 64538  64609           pCur->eState = CURSOR_INVALID;
 64539  64610           *pRes = 1;
 64540  64611           return SQLITE_OK;
 64541  64612         }
 64542  64613         moveToParent(pCur);
 64543  64614       }
 64544  64615       assert( pCur->info.nSize==0 );
 64545  64616       assert( (pCur->curFlags & (BTCF_ValidOvfl))==0 );
 64546  64617   
 64547         -    pCur->aiIdx[pCur->iPage]--;
        64618  +    pCur->ix--;
 64548  64619       pPage = pCur->apPage[pCur->iPage];
 64549  64620       if( pPage->intKey && !pPage->leaf ){
 64550  64621         rc = sqlite3BtreePrevious(pCur, pRes);
 64551  64622       }else{
 64552  64623         rc = SQLITE_OK;
 64553  64624       }
 64554  64625     }
................................................................................
 64559  64630     assert( pRes!=0 );
 64560  64631     assert( *pRes==0 || *pRes==1 );
 64561  64632     assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
 64562  64633     *pRes = 0;
 64563  64634     pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey);
 64564  64635     pCur->info.nSize = 0;
 64565  64636     if( pCur->eState!=CURSOR_VALID
 64566         -   || pCur->aiIdx[pCur->iPage]==0
        64637  +   || pCur->ix==0
 64567  64638      || pCur->apPage[pCur->iPage]->leaf==0
 64568  64639     ){
 64569  64640       return btreePrevious(pCur, pRes);
 64570  64641     }
 64571         -  pCur->aiIdx[pCur->iPage]--;
        64642  +  pCur->ix--;
 64572  64643     return SQLITE_OK;
 64573  64644   }
 64574  64645   
 64575  64646   /*
 64576  64647   ** Allocate a new page from the database file.
 64577  64648   **
 64578  64649   ** The new page is marked as dirty.  (In other words, sqlite3PagerWrite()
................................................................................
 66886  66957           ** next iteration of the do-loop will balance the child page.
 66887  66958           */ 
 66888  66959           assert( balance_deeper_called==0 );
 66889  66960           VVA_ONLY( balance_deeper_called++ );
 66890  66961           rc = balance_deeper(pPage, &pCur->apPage[1]);
 66891  66962           if( rc==SQLITE_OK ){
 66892  66963             pCur->iPage = 1;
        66964  +          pCur->ix = 0;
 66893  66965             pCur->aiIdx[0] = 0;
 66894         -          pCur->aiIdx[1] = 0;
 66895  66966             assert( pCur->apPage[1]->nOverflow );
 66896  66967           }
 66897  66968         }else{
 66898  66969           break;
 66899  66970         }
 66900  66971       }else if( pPage->nOverflow==0 && pPage->nFree<=nMin ){
 66901  66972         break;
................................................................................
 67064  67135       if( rc ) return rc;
 67065  67136     }
 67066  67137   
 67067  67138     if( pCur->pKeyInfo==0 ){
 67068  67139       assert( pX->pKey==0 );
 67069  67140       /* If this is an insert into a table b-tree, invalidate any incrblob 
 67070  67141       ** cursors open on the row being replaced */
 67071         -    invalidateIncrblobCursors(p, pX->nKey, 0);
        67142  +    invalidateIncrblobCursors(p, pCur->pgnoRoot, pX->nKey, 0);
 67072  67143   
 67073  67144       /* If BTREE_SAVEPOSITION is set, the cursor must already be pointing 
 67074  67145       ** to a row with the same key as the new entry being inserted.  */
 67075  67146       assert( (flags & BTREE_SAVEPOSITION)==0 || 
 67076  67147               ((pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey) );
 67077  67148   
 67078  67149       /* If the cursor is currently on the last row and we are appending a
 67079  67150       ** new row onto the end, set the "loc" to avoid an unnecessary
 67080  67151       ** btreeMoveto() call */
 67081  67152       if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){
 67082  67153         loc = 0;
 67083         -    }else if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey>0
 67084         -               && pCur->info.nKey==pX->nKey-1 ){
 67085         -      loc = -1;
 67086  67154       }else if( loc==0 ){
 67087  67155         rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, flags!=0, &loc);
 67088  67156         if( rc ) return rc;
 67089  67157       }
 67090  67158     }else if( loc==0 && (flags & BTREE_SAVEPOSITION)==0 ){
 67091  67159       if( pX->nMem ){
 67092  67160         UnpackedRecord r;
................................................................................
 67116  67184     assert( pPage->isInit );
 67117  67185     newCell = pBt->pTmpSpace;
 67118  67186     assert( newCell!=0 );
 67119  67187     rc = fillInCell(pPage, newCell, pX, &szNew);
 67120  67188     if( rc ) goto end_insert;
 67121  67189     assert( szNew==pPage->xCellSize(pPage, newCell) );
 67122  67190     assert( szNew <= MX_CELL_SIZE(pBt) );
 67123         -  idx = pCur->aiIdx[pCur->iPage];
        67191  +  idx = pCur->ix;
 67124  67192     if( loc==0 ){
 67125  67193       CellInfo info;
 67126  67194       assert( idx<pPage->nCell );
 67127  67195       rc = sqlite3PagerWrite(pPage->pDbPage);
 67128  67196       if( rc ){
 67129  67197         goto end_insert;
 67130  67198       }
................................................................................
 67144  67212         memcpy(oldCell, newCell, szNew);
 67145  67213         return SQLITE_OK;
 67146  67214       }
 67147  67215       dropCell(pPage, idx, info.nSize, &rc);
 67148  67216       if( rc ) goto end_insert;
 67149  67217     }else if( loc<0 && pPage->nCell>0 ){
 67150  67218       assert( pPage->leaf );
 67151         -    idx = ++pCur->aiIdx[pCur->iPage];
        67219  +    idx = ++pCur->ix;
        67220  +    pCur->curFlags &= ~BTCF_ValidNKey;
 67152  67221     }else{
 67153  67222       assert( pPage->leaf );
 67154  67223     }
 67155  67224     insertCell(pPage, idx, newCell, szNew, 0, 0, &rc);
 67156  67225     assert( pPage->nOverflow==0 || rc==SQLITE_OK );
 67157  67226     assert( rc!=SQLITE_OK || pPage->nCell>0 || pPage->nOverflow>0 );
 67158  67227   
................................................................................
 67240  67309   
 67241  67310     assert( cursorOwnsBtShared(pCur) );
 67242  67311     assert( pBt->inTransaction==TRANS_WRITE );
 67243  67312     assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
 67244  67313     assert( pCur->curFlags & BTCF_WriteFlag );
 67245  67314     assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
 67246  67315     assert( !hasReadConflicts(p, pCur->pgnoRoot) );
 67247         -  assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
        67316  +  assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
 67248  67317     assert( pCur->eState==CURSOR_VALID );
 67249  67318     assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
 67250  67319   
 67251  67320     iCellDepth = pCur->iPage;
 67252         -  iCellIdx = pCur->aiIdx[iCellDepth];
        67321  +  iCellIdx = pCur->ix;
 67253  67322     pPage = pCur->apPage[iCellDepth];
 67254  67323     pCell = findCell(pPage, iCellIdx);
 67255  67324   
 67256  67325     /* If the bPreserve flag is set to true, then the cursor position must
 67257  67326     ** be preserved following this delete operation. If the current delete
 67258  67327     ** will cause a b-tree rebalance, then this is done by saving the cursor
 67259  67328     ** key and leaving the cursor in CURSOR_REQUIRESEEK state before 
................................................................................
 67294  67363       rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
 67295  67364       if( rc ) return rc;
 67296  67365     }
 67297  67366   
 67298  67367     /* If this is a delete operation to remove a row from a table b-tree,
 67299  67368     ** invalidate any incrblob cursors open on the row being deleted.  */
 67300  67369     if( pCur->pKeyInfo==0 ){
 67301         -    invalidateIncrblobCursors(p, pCur->info.nKey, 0);
        67370  +    invalidateIncrblobCursors(p, pCur->pgnoRoot, pCur->info.nKey, 0);
 67302  67371     }
 67303  67372   
 67304  67373     /* Make the page containing the entry to be deleted writable. Then free any
 67305  67374     ** overflow pages associated with the entry and finally remove the cell
 67306  67375     ** itself from within the page.  */
 67307  67376     rc = sqlite3PagerWrite(pPage->pDbPage);
 67308  67377     if( rc ) return rc;
................................................................................
 67362  67431       if( bSkipnext ){
 67363  67432         assert( bPreserve && (pCur->iPage==iCellDepth || CORRUPT_DB) );
 67364  67433         assert( pPage==pCur->apPage[pCur->iPage] || CORRUPT_DB );
 67365  67434         assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
 67366  67435         pCur->eState = CURSOR_SKIPNEXT;
 67367  67436         if( iCellIdx>=pPage->nCell ){
 67368  67437           pCur->skipNext = -1;
 67369         -        pCur->aiIdx[iCellDepth] = pPage->nCell-1;
        67438  +        pCur->ix = pPage->nCell-1;
 67370  67439         }else{
 67371  67440           pCur->skipNext = 1;
 67372  67441         }
 67373  67442       }else{
 67374  67443         rc = moveToRoot(pCur);
 67375  67444         if( bPreserve ){
 67376  67445           pCur->eState = CURSOR_REQUIRESEEK;
................................................................................
 67621  67690   
 67622  67691     rc = saveAllCursors(pBt, (Pgno)iTable, 0);
 67623  67692   
 67624  67693     if( SQLITE_OK==rc ){
 67625  67694       /* Invalidate all incrblob cursors open on table iTable (assuming iTable
 67626  67695       ** is the root of a table b-tree - if it is not, the following call is
 67627  67696       ** a no-op).  */
 67628         -    invalidateIncrblobCursors(p, 0, 1);
        67697  +    invalidateIncrblobCursors(p, (Pgno)iTable, 0, 1);
 67629  67698       rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
 67630  67699     }
 67631  67700     sqlite3BtreeLeave(p);
 67632  67701     return rc;
 67633  67702   }
 67634  67703   
 67635  67704   /*
................................................................................
 67875  67944         do {
 67876  67945           if( pCur->iPage==0 ){
 67877  67946             /* All pages of the b-tree have been visited. Return successfully. */
 67878  67947             *pnEntry = nEntry;
 67879  67948             return moveToRoot(pCur);
 67880  67949           }
 67881  67950           moveToParent(pCur);
 67882         -      }while ( pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell );
        67951  +      }while ( pCur->ix>=pCur->apPage[pCur->iPage]->nCell );
 67883  67952   
 67884         -      pCur->aiIdx[pCur->iPage]++;
        67953  +      pCur->ix++;
 67885  67954         pPage = pCur->apPage[pCur->iPage];
 67886  67955       }
 67887  67956   
 67888  67957       /* Descend to the child node of the cell that the cursor currently 
 67889  67958       ** points at. This is the right-child if (iIdx==pPage->nCell).
 67890  67959       */
 67891         -    iIdx = pCur->aiIdx[pCur->iPage];
        67960  +    iIdx = pCur->ix;
 67892  67961       if( iIdx==pPage->nCell ){
 67893  67962         rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
 67894  67963       }else{
 67895  67964         rc = moveToChild(pCur, get4byte(findCell(pPage, iIdx)));
 67896  67965       }
 67897  67966     }
 67898  67967   
................................................................................
 68269  68338   
 68270  68339       /* Check for integer primary key out of range */
 68271  68340       if( pPage->intKey ){
 68272  68341         if( keyCanBeEqual ? (info.nKey > maxKey) : (info.nKey >= maxKey) ){
 68273  68342           checkAppendMsg(pCheck, "Rowid %lld out of order", info.nKey);
 68274  68343         }
 68275  68344         maxKey = info.nKey;
        68345  +      keyCanBeEqual = 0;     /* Only the first key on the page may ==maxKey */
 68276  68346       }
 68277  68347   
 68278  68348       /* Check the content overflow list */
 68279  68349       if( info.nPayload>info.nLocal ){
 68280  68350         int nPage;       /* Number of pages on the overflow chain */
 68281  68351         Pgno pgnoOvfl;   /* First page of the overflow chain */
 68282  68352         assert( pc + info.nSize - 4 <= usableSize );
................................................................................
 69654  69724     ** Mem.z = Mem.zMalloc without having to check Mem.flags&MEM_Dyn.
 69655  69725     ** That saves a few cycles in inner loops. */
 69656  69726     assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
 69657  69727   
 69658  69728     /* Cannot be both MEM_Int and MEM_Real at the same time */
 69659  69729     assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
 69660  69730   
        69731  +  /* Cannot be both MEM_Null and some other type */
        69732  +  assert( (p->flags & MEM_Null)==0 ||
        69733  +          (p->flags & (MEM_Int|MEM_Real|MEM_Str|MEM_Blob))==0 );
        69734  +
 69661  69735     /* The szMalloc field holds the correct memory allocation size */
 69662  69736     assert( p->szMalloc==0
 69663  69737          || p->szMalloc==sqlite3DbMallocSize(p->db,p->zMalloc) );
 69664  69738   
 69665  69739     /* If p holds a string or blob, the Mem.z must point to exactly
 69666  69740     ** one of the following:
 69667  69741     **
................................................................................
 69739  69813     /* If the bPreserve flag is set to true, then the memory cell must already
 69740  69814     ** contain a valid string or blob value.  */
 69741  69815     assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
 69742  69816     testcase( bPreserve && pMem->z==0 );
 69743  69817   
 69744  69818     assert( pMem->szMalloc==0
 69745  69819          || pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) );
 69746         -  if( pMem->szMalloc<n ){
 69747         -    if( n<32 ) n = 32;
 69748         -    if( bPreserve && pMem->szMalloc>0 && pMem->z==pMem->zMalloc ){
 69749         -      pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
 69750         -      bPreserve = 0;
 69751         -    }else{
 69752         -      if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc);
 69753         -      pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
 69754         -    }
 69755         -    if( pMem->zMalloc==0 ){
 69756         -      sqlite3VdbeMemSetNull(pMem);
 69757         -      pMem->z = 0;
 69758         -      pMem->szMalloc = 0;
 69759         -      return SQLITE_NOMEM_BKPT;
 69760         -    }else{
 69761         -      pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
 69762         -    }
        69820  +  if( n<32 ) n = 32;
        69821  +  if( bPreserve && pMem->szMalloc>0 && pMem->z==pMem->zMalloc ){
        69822  +    pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
        69823  +    bPreserve = 0;
        69824  +  }else{
        69825  +    if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
        69826  +    pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
        69827  +  }
        69828  +  if( pMem->zMalloc==0 ){
        69829  +    sqlite3VdbeMemSetNull(pMem);
        69830  +    pMem->z = 0;
        69831  +    pMem->szMalloc = 0;
        69832  +    return SQLITE_NOMEM_BKPT;
        69833  +  }else{
        69834  +    pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
 69763  69835     }
 69764  69836   
 69765         -  if( bPreserve && pMem->z && pMem->z!=pMem->zMalloc ){
        69837  +  if( bPreserve && pMem->z && ALWAYS(pMem->z!=pMem->zMalloc) ){
 69766  69838       memcpy(pMem->zMalloc, pMem->z, pMem->n);
 69767  69839     }
 69768  69840     if( (pMem->flags&MEM_Dyn)!=0 ){
 69769  69841       assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
 69770  69842       pMem->xDel((void *)(pMem->z));
 69771  69843     }
 69772  69844   
................................................................................
 69955  70027       t.flags = MEM_Null;
 69956  70028       t.db = pMem->db;
 69957  70029       ctx.pOut = &t;
 69958  70030       ctx.pMem = pMem;
 69959  70031       ctx.pFunc = pFunc;
 69960  70032       pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */
 69961  70033       assert( (pMem->flags & MEM_Dyn)==0 );
 69962         -    if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc);
        70034  +    if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
 69963  70035       memcpy(pMem, &t, sizeof(t));
 69964  70036       rc = ctx.isError;
 69965  70037     }
 69966  70038     return rc;
 69967  70039   }
 69968  70040   
 69969  70041   /*
................................................................................
 70006  70078   ** to be freed.
 70007  70079   */
 70008  70080   static SQLITE_NOINLINE void vdbeMemClear(Mem *p){
 70009  70081     if( VdbeMemDynamic(p) ){
 70010  70082       vdbeMemClearExternAndSetNull(p);
 70011  70083     }
 70012  70084     if( p->szMalloc ){
 70013         -    sqlite3DbFree(p->db, p->zMalloc);
        70085  +    sqlite3DbFreeNN(p->db, p->zMalloc);
 70014  70086       p->szMalloc = 0;
 70015  70087     }
 70016  70088     p->z = 0;
 70017  70089   }
 70018  70090   
 70019  70091   /*
 70020  70092   ** Release any memory resources held by the Mem.  Both the memory that is
................................................................................
 70034  70106   }
 70035  70107   
 70036  70108   /*
 70037  70109   ** Convert a 64-bit IEEE double into a 64-bit signed integer.
 70038  70110   ** If the double is out of range of a 64-bit signed integer then
 70039  70111   ** return the closest available 64-bit signed integer.
 70040  70112   */
 70041         -static i64 doubleToInt64(double r){
        70113  +static SQLITE_NOINLINE i64 doubleToInt64(double r){
 70042  70114   #ifdef SQLITE_OMIT_FLOATING_POINT
 70043  70115     /* When floating-point is omitted, double and int64 are the same thing */
 70044  70116     return r;
 70045  70117   #else
 70046  70118     /*
 70047  70119     ** Many compilers we encounter do not define constants for the
 70048  70120     ** minimum and maximum 64-bit integers, or they define them
................................................................................
 70070  70142   ** a floating-point then the value returned is the integer part.
 70071  70143   ** If pMem is a string or blob, then we make an attempt to convert
 70072  70144   ** it into an integer and return that.  If pMem represents an
 70073  70145   ** an SQL-NULL value, return 0.
 70074  70146   **
 70075  70147   ** If pMem represents a string value, its encoding might be changed.
 70076  70148   */
        70149  +static SQLITE_NOINLINE i64 memIntValue(Mem *pMem){
        70150  +  i64 value = 0;
        70151  +  sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
        70152  +  return value;
        70153  +}
 70077  70154   SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem *pMem){
 70078  70155     int flags;
 70079  70156     assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
 70080  70157     assert( EIGHT_BYTE_ALIGNMENT(pMem) );
 70081  70158     flags = pMem->flags;
 70082  70159     if( flags & MEM_Int ){
 70083  70160       return pMem->u.i;
 70084  70161     }else if( flags & MEM_Real ){
 70085  70162       return doubleToInt64(pMem->u.r);
 70086  70163     }else if( flags & (MEM_Str|MEM_Blob) ){
 70087         -    i64 value = 0;
 70088  70164       assert( pMem->z || pMem->n==0 );
 70089         -    sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
 70090         -    return value;
        70165  +    return memIntValue(pMem);
 70091  70166     }else{
 70092  70167       return 0;
 70093  70168     }
 70094  70169   }
 70095  70170   
 70096  70171   /*
 70097  70172   ** Return the best representation of pMem that we can get into a
 70098  70173   ** double.  If pMem is already a double or an integer, return its
 70099  70174   ** value.  If it is a string or blob, try to convert it to a double.
 70100  70175   ** If it is a NULL, return 0.0.
 70101  70176   */
        70177  +static SQLITE_NOINLINE double memRealValue(Mem *pMem){
        70178  +  /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
        70179  +  double val = (double)0;
        70180  +  sqlite3AtoF(pMem->z, &val, pMem->n, pMem->enc);
        70181  +  return val;
        70182  +}
 70102  70183   SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){
 70103  70184     assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
 70104  70185     assert( EIGHT_BYTE_ALIGNMENT(pMem) );
 70105  70186     if( pMem->flags & MEM_Real ){
 70106  70187       return pMem->u.r;
 70107  70188     }else if( pMem->flags & MEM_Int ){
 70108  70189       return (double)pMem->u.i;
 70109  70190     }else if( pMem->flags & (MEM_Str|MEM_Blob) ){
 70110         -    /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
 70111         -    double val = (double)0;
 70112         -    sqlite3AtoF(pMem->z, &val, pMem->n, pMem->enc);
 70113         -    return val;
        70191  +    return memRealValue(pMem);
 70114  70192     }else{
 70115  70193       /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
 70116  70194       return (double)0;
 70117  70195     }
 70118  70196   }
 70119  70197   
 70120  70198   /*
................................................................................
 70731  70809             assert( pRec->pKeyInfo->enc==ENC(db) );
 70732  70810             pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
 70733  70811             for(i=0; i<nCol; i++){
 70734  70812               pRec->aMem[i].flags = MEM_Null;
 70735  70813               pRec->aMem[i].db = db;
 70736  70814             }
 70737  70815           }else{
 70738         -          sqlite3DbFree(db, pRec);
        70816  +          sqlite3DbFreeNN(db, pRec);
 70739  70817             pRec = 0;
 70740  70818           }
 70741  70819         }
 70742  70820         if( pRec==0 ) return 0;
 70743  70821         p->ppRec[0] = pRec;
 70744  70822       }
 70745  70823     
................................................................................
 70843  70921     if( rc!=SQLITE_OK ){
 70844  70922       pVal = 0;
 70845  70923     }
 70846  70924     if( apVal ){
 70847  70925       for(i=0; i<nVal; i++){
 70848  70926         sqlite3ValueFree(apVal[i]);
 70849  70927       }
 70850         -    sqlite3DbFree(db, apVal);
        70928  +    sqlite3DbFreeNN(db, apVal);
 70851  70929     }
 70852  70930   
 70853  70931     *ppVal = pVal;
 70854  70932     return rc;
 70855  70933   }
 70856  70934   #else
 70857  70935   # define valueFromFunction(a,b,c,d,e,f) SQLITE_OK
................................................................................
 71042  71120     if( aRet==0 ){
 71043  71121       sqlite3_result_error_nomem(context);
 71044  71122     }else{
 71045  71123       aRet[0] = nSerial+1;
 71046  71124       putVarint32(&aRet[1], iSerial);
 71047  71125       sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], iSerial);
 71048  71126       sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT);
 71049         -    sqlite3DbFree(db, aRet);
        71127  +    sqlite3DbFreeNN(db, aRet);
 71050  71128     }
 71051  71129   }
 71052  71130   
 71053  71131   /*
 71054  71132   ** Register built-in functions used to help read ANALYZE data.
 71055  71133   */
 71056  71134   SQLITE_PRIVATE void sqlite3AnalyzeFunctions(void){
................................................................................
 71269  71347       int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField;
 71270  71348       Mem *aMem = pRec->aMem;
 71271  71349       sqlite3 *db = aMem[0].db;
 71272  71350       for(i=0; i<nCol; i++){
 71273  71351         sqlite3VdbeMemRelease(&aMem[i]);
 71274  71352       }
 71275  71353       sqlite3KeyInfoUnref(pRec->pKeyInfo);
 71276         -    sqlite3DbFree(db, pRec);
        71354  +    sqlite3DbFreeNN(db, pRec);
 71277  71355     }
 71278  71356   }
 71279  71357   #endif /* ifdef SQLITE_ENABLE_STAT4 */
 71280  71358   
 71281  71359   /*
 71282  71360   ** Change the string value of an sqlite3_value object
 71283  71361   */
................................................................................
 71293  71371   
 71294  71372   /*
 71295  71373   ** Free an sqlite3_value object
 71296  71374   */
 71297  71375   SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value *v){
 71298  71376     if( !v ) return;
 71299  71377     sqlite3VdbeMemRelease((Mem *)v);
 71300         -  sqlite3DbFree(((Mem*)v)->db, v);
        71378  +  sqlite3DbFreeNN(((Mem*)v)->db, v);
 71301  71379   }
 71302  71380   
 71303  71381   /*
 71304  71382   ** The sqlite3ValueBytes() routine returns the number of bytes in the
 71305  71383   ** sqlite3_value object assuming that it uses the encoding "enc".
 71306  71384   ** The valueBytes() routine is a helper function.
 71307  71385   */
................................................................................
 72136  72214   
 72137  72215   /*
 72138  72216   ** If the input FuncDef structure is ephemeral, then free it.  If
 72139  72217   ** the FuncDef is not ephermal, then do nothing.
 72140  72218   */
 72141  72219   static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
 72142  72220     if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
 72143         -    sqlite3DbFree(db, pDef);
        72221  +    sqlite3DbFreeNN(db, pDef);
 72144  72222     }
 72145  72223   }
 72146  72224   
 72147  72225   static void vdbeFreeOpArray(sqlite3 *, Op *, int);
 72148  72226   
 72149  72227   /*
 72150  72228   ** Delete a P4 value if necessary.
 72151  72229   */
 72152  72230   static SQLITE_NOINLINE void freeP4Mem(sqlite3 *db, Mem *p){
 72153  72231     if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
 72154         -  sqlite3DbFree(db, p);
        72232  +  sqlite3DbFreeNN(db, p);
 72155  72233   }
 72156  72234   static SQLITE_NOINLINE void freeP4FuncCtx(sqlite3 *db, sqlite3_context *p){
 72157  72235     freeEphemeralFunction(db, p->pFunc);
 72158         -  sqlite3DbFree(db, p);
        72236  + sqlite3DbFreeNN(db, p);
 72159  72237   }
 72160  72238   static void freeP4(sqlite3 *db, int p4type, void *p4){
 72161  72239     assert( db );
 72162  72240     switch( p4type ){
 72163  72241       case P4_FUNCCTX: {
 72164  72242         freeP4FuncCtx(db, (sqlite3_context*)p4);
 72165  72243         break;
................................................................................
 72204  72282   ** Free the space allocated for aOp and any p4 values allocated for the
 72205  72283   ** opcodes contained within. If aOp is not NULL it is assumed to contain 
 72206  72284   ** nOp entries. 
 72207  72285   */
 72208  72286   static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
 72209  72287     if( aOp ){
 72210  72288       Op *pOp;
 72211         -    for(pOp=aOp; pOp<&aOp[nOp]; pOp++){
        72289  +    for(pOp=&aOp[nOp-1]; pOp>=aOp; pOp--){
 72212  72290         if( pOp->p4type ) freeP4(db, pOp->p4type, pOp->p4.p);
 72213  72291   #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
 72214  72292         sqlite3DbFree(db, pOp->zComment);
 72215  72293   #endif     
 72216  72294       }
        72295  +    sqlite3DbFreeNN(db, aOp);
 72217  72296     }
 72218         -  sqlite3DbFree(db, aOp);
 72219  72297   }
 72220  72298   
 72221  72299   /*
 72222  72300   ** Link the SubProgram object passed as the second argument into the linked
 72223  72301   ** list at Vdbe.pSubProgram. This list is used to delete all sub-program
 72224  72302   ** objects when the VM is no longer required.
 72225  72303   */
................................................................................
 72884  72962         testcase( p->flags & MEM_Agg );
 72885  72963         testcase( p->flags & MEM_Dyn );
 72886  72964         testcase( p->flags & MEM_Frame );
 72887  72965         testcase( p->flags & MEM_RowSet );
 72888  72966         if( p->flags&(MEM_Agg|MEM_Dyn|MEM_Frame|MEM_RowSet) ){
 72889  72967           sqlite3VdbeMemRelease(p);
 72890  72968         }else if( p->szMalloc ){
 72891         -        sqlite3DbFree(db, p->zMalloc);
        72969  +        sqlite3DbFreeNN(db, p->zMalloc);
 72892  72970           p->szMalloc = 0;
 72893  72971         }
 72894  72972   
 72895  72973         p->flags = MEM_Undefined;
 72896  72974       }while( (++p)<pEnd );
 72897  72975     }
 72898  72976   }
................................................................................
 73360  73438     assert( pCx->pBtx==0 || pCx->eCurType==CURTYPE_BTREE );
 73361  73439     switch( pCx->eCurType ){
 73362  73440       case CURTYPE_SORTER: {
 73363  73441         sqlite3VdbeSorterClose(p->db, pCx);
 73364  73442         break;
 73365  73443       }
 73366  73444       case CURTYPE_BTREE: {
 73367         -      if( pCx->pBtx ){
 73368         -        sqlite3BtreeClose(pCx->pBtx);
        73445  +      if( pCx->isEphemeral ){
        73446  +        if( pCx->pBtx ) sqlite3BtreeClose(pCx->pBtx);
 73369  73447           /* The pCx->pCursor will be close automatically, if it exists, by
 73370  73448           ** the call above. */
 73371  73449         }else{
 73372  73450           assert( pCx->uc.pCursor!=0 );
 73373  73451           sqlite3BtreeCloseCursor(pCx->uc.pCursor);
 73374  73452         }
 73375  73453         break;
................................................................................
 74255  74333           fprintf(out, "%s", zHdr);
 74256  74334           sqlite3VdbePrintOp(out, i, &p->aOp[i]);
 74257  74335         }
 74258  74336         fclose(out);
 74259  74337       }
 74260  74338     }
 74261  74339   #endif
 74262         -  p->iCurrentTime = 0;
 74263  74340     p->magic = VDBE_MAGIC_RESET;
 74264  74341     return p->rc & db->errMask;
 74265  74342   }
 74266  74343    
 74267  74344   /*
 74268  74345   ** Clean up and delete a VDBE after execution.  Return an integer which is
 74269  74346   ** the result code.  Write any error message text into *pzErrMsg.
................................................................................
 74365  74442       db->pVdbe = p->pNext;
 74366  74443     }
 74367  74444     if( p->pNext ){
 74368  74445       p->pNext->pPrev = p->pPrev;
 74369  74446     }
 74370  74447     p->magic = VDBE_MAGIC_DEAD;
 74371  74448     p->db = 0;
 74372         -  sqlite3DbFree(db, p);
        74449  +  sqlite3DbFreeNN(db, p);
 74373  74450   }
 74374  74451   
 74375  74452   /*
 74376  74453   ** The cursor "p" has a pending seek operation that has not yet been
 74377  74454   ** carried out.  Seek the cursor now.  If an error occurs, return
 74378  74455   ** the appropriate error code.
 74379  74456   */
................................................................................
 75924  76001   static void vdbeFreeUnpacked(sqlite3 *db, int nField, UnpackedRecord *p){
 75925  76002     if( p ){
 75926  76003       int i;
 75927  76004       for(i=0; i<nField; i++){
 75928  76005         Mem *pMem = &p->aMem[i];
 75929  76006         if( pMem->zMalloc ) sqlite3VdbeMemRelease(pMem);
 75930  76007       }
 75931         -    sqlite3DbFree(db, p);
        76008  +    sqlite3DbFreeNN(db, p);
 75932  76009     }
 75933  76010   }
 75934  76011   #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
 75935  76012   
 75936  76013   #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
 75937  76014   /*
 75938  76015   ** Invoke the pre-update hook. If this is an UPDATE or DELETE pre-update call,
................................................................................
 75991  76068     vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pUnpacked);
 75992  76069     vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pNewUnpacked);
 75993  76070     if( preupdate.aNew ){
 75994  76071       int i;
 75995  76072       for(i=0; i<pCsr->nField; i++){
 75996  76073         sqlite3VdbeMemRelease(&preupdate.aNew[i]);
 75997  76074       }
 75998         -    sqlite3DbFree(db, preupdate.aNew);
        76075  +    sqlite3DbFreeNN(db, preupdate.aNew);
 75999  76076     }
 76000  76077   }
 76001  76078   #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
 76002  76079   
 76003  76080   /************** End of vdbeaux.c *********************************************/
 76004  76081   /************** Begin file vdbeapi.c *****************************************/
 76005  76082   /*
................................................................................
 78577  78654     }
 78578  78655     if( p->flags & MEM_Subtype ) printf(" subtype=0x%02x", p->eSubtype);
 78579  78656   }
 78580  78657   static void registerTrace(int iReg, Mem *p){
 78581  78658     printf("REG[%d] = ", iReg);
 78582  78659     memTracePrint(p);
 78583  78660     printf("\n");
        78661  +  sqlite3VdbeCheckMemInvariants(p);
 78584  78662   }
 78585  78663   #endif
 78586  78664   
 78587  78665   #ifdef SQLITE_DEBUG
 78588  78666   #  define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
 78589  78667   #else
 78590  78668   #  define REGISTER_TRACE(R,M)
................................................................................
 78943  79021   ** to the current line should be indented for EXPLAIN output.
 78944  79022   */
 78945  79023   case OP_Goto: {             /* jump */
 78946  79024   jump_to_p2_and_check_for_interrupt:
 78947  79025     pOp = &aOp[pOp->p2 - 1];
 78948  79026   
 78949  79027     /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
 78950         -  ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon
        79028  +  ** OP_VNext, or OP_SorterNext) all jump here upon
 78951  79029     ** completion.  Check to see if sqlite3_interrupt() has been called
 78952  79030     ** or if the progress callback needs to be invoked. 
 78953  79031     **
 78954  79032     ** This code uses unstructured "goto" statements and does not look clean.
 78955  79033     ** But that is not due to sloppy coding habits. The code is written this
 78956  79034     ** way for performance, to avoid having to run the interrupt and progress
 78957  79035     ** checks on every opcode.  This helps sqlite3_step() to run about 1.5%
................................................................................
 79331  79409   ** instruction, but do not free any string or blob memory associated with
 79332  79410   ** the register, so that if the value was a string or blob that was
 79333  79411   ** previously copied using OP_SCopy, the copies will continue to be valid.
 79334  79412   */
 79335  79413   case OP_SoftNull: {
 79336  79414     assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
 79337  79415     pOut = &aMem[pOp->p1];
 79338         -  pOut->flags = (pOut->flags|MEM_Null)&~MEM_Undefined;
        79416  +  pOut->flags = (pOut->flags&~(MEM_Undefined|MEM_AffMask))|MEM_Null;
 79339  79417     break;
 79340  79418   }
 79341  79419   
 79342  79420   /* Opcode: Blob P1 P2 * P4 *
 79343  79421   ** Synopsis: r[P2]=P4 (len=P1)
 79344  79422   **
 79345  79423   ** P4 points to a blob of data P1 bytes long.  Store this
................................................................................
 79674  79752   
 79675  79753     pIn1 = &aMem[pOp->p1];
 79676  79754     type1 = numericType(pIn1);
 79677  79755     pIn2 = &aMem[pOp->p2];
 79678  79756     type2 = numericType(pIn2);
 79679  79757     pOut = &aMem[pOp->p3];
 79680  79758     flags = pIn1->flags | pIn2->flags;
 79681         -  if( (flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
 79682  79759     if( (type1 & type2 & MEM_Int)!=0 ){
 79683  79760       iA = pIn1->u.i;
 79684  79761       iB = pIn2->u.i;
 79685  79762       bIntint = 1;
 79686  79763       switch( pOp->opcode ){
 79687  79764         case OP_Add:       if( sqlite3AddInt64(&iB,iA) ) goto fp_math;  break;
 79688  79765         case OP_Subtract:  if( sqlite3SubInt64(&iB,iA) ) goto fp_math;  break;
................................................................................
 79698  79775           if( iA==-1 ) iA = 1;
 79699  79776           iB %= iA;
 79700  79777           break;
 79701  79778         }
 79702  79779       }
 79703  79780       pOut->u.i = iB;
 79704  79781       MemSetTypeFlag(pOut, MEM_Int);
        79782  +  }else if( (flags & MEM_Null)!=0 ){
        79783  +    goto arithmetic_result_is_null;
 79705  79784     }else{
 79706  79785       bIntint = 0;
 79707  79786   fp_math:
 79708  79787       rA = sqlite3VdbeRealValue(pIn1);
 79709  79788       rB = sqlite3VdbeRealValue(pIn2);
 79710  79789       switch( pOp->opcode ){
 79711  79790         case OP_Add:         rB += rA;       break;
................................................................................
 79745  79824   arithmetic_result_is_null:
 79746  79825     sqlite3VdbeMemSetNull(pOut);
 79747  79826     break;
 79748  79827   }
 79749  79828   
 79750  79829   /* Opcode: CollSeq P1 * * P4
 79751  79830   **
 79752         -** P4 is a pointer to a CollSeq struct. If the next call to a user function
        79831  +** P4 is a pointer to a CollSeq object. If the next call to a user function
 79753  79832   ** or aggregate calls sqlite3GetFuncCollSeq(), this collation sequence will
 79754  79833   ** be returned. This is used by the built-in min(), max() and nullif()
 79755  79834   ** functions.
 79756  79835   **
 79757  79836   ** If P1 is not zero, then it is a register that a subsequent min() or
 79758  79837   ** max() aggregate will set to 1 if the current row is not the minimum or
 79759  79838   ** maximum.  The P1 register is initialized to 0 by this instruction.
................................................................................
 80026  80105   #ifndef SQLITE_OMIT_CAST
 80027  80106   /* Opcode: Cast P1 P2 * * *
 80028  80107   ** Synopsis: affinity(r[P1])
 80029  80108   **
 80030  80109   ** Force the value in register P1 to be the type defined by P2.
 80031  80110   ** 
 80032  80111   ** <ul>
 80033         -** <li value="97"> TEXT
 80034         -** <li value="98"> BLOB
 80035         -** <li value="99"> NUMERIC
 80036         -** <li value="100"> INTEGER
 80037         -** <li value="101"> REAL
        80112  +** <li> P2=='A' &rarr; BLOB
        80113  +** <li> P2=='B' &rarr; TEXT
        80114  +** <li> P2=='C' &rarr; NUMERIC
        80115  +** <li> P2=='D' &rarr; INTEGER
        80116  +** <li> P2=='E' &rarr; REAL
 80038  80117   ** </ul>
 80039  80118   **
 80040  80119   ** A NULL value is not changed by this routine.  It remains NULL.
 80041  80120   */
 80042  80121   case OP_Cast: {                  /* in1 */
 80043  80122     assert( pOp->p2>=SQLITE_AFF_BLOB && pOp->p2<=SQLITE_AFF_REAL );
 80044  80123     testcase( pOp->p2==SQLITE_AFF_TEXT );
................................................................................
 80608  80687     pIn1 = &aMem[pOp->p1];
 80609  80688     VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
 80610  80689     if( (pIn1->flags & MEM_Null)==0 ){
 80611  80690       goto jump_to_p2;
 80612  80691     }
 80613  80692     break;
 80614  80693   }
        80694  +
        80695  +/* Opcode: IfNullRow P1 P2 P3 * *
        80696  +** Synopsis: if P1.nullRow then r[P3]=NULL, goto P2
        80697  +**
        80698  +** Check the cursor P1 to see if it is currently pointing at a NULL row.
        80699  +** If it is, then set register P3 to NULL and jump immediately to P2.
        80700  +** If P1 is not on a NULL row, then fall through without making any
        80701  +** changes.
        80702  +*/
        80703  +case OP_IfNullRow: {         /* jump */
        80704  +  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
        80705  +  if( p->apCsr[pOp->p1]->nullRow ){
        80706  +    sqlite3VdbeMemSetNull(aMem + pOp->p3);
        80707  +    goto jump_to_p2;
        80708  +  }
        80709  +  break;
        80710  +}
 80615  80711   
 80616  80712   /* Opcode: Column P1 P2 P3 P4 P5
 80617  80713   ** Synopsis: r[P3]=PX
 80618  80714   **
 80619  80715   ** Interpret the data that cursor P1 points to as a structure built using
 80620  80716   ** the MakeRecord instruction.  (See the MakeRecord opcode for additional
 80621  80717   ** information about the format of the data.)  Extract the P2-th column
 80622  80718   ** from this record.  If there are less that (P2+1) 
 80623  80719   ** values in the record, extract a NULL.
 80624  80720   **
 80625  80721   ** The value extracted is stored in register P3.
 80626  80722   **
 80627         -** If the column contains fewer than P2 fields, then extract a NULL.  Or,
        80723  +** If the record contains fewer than P2 fields, then extract a NULL.  Or,
 80628  80724   ** if the P4 argument is a P4_MEM use the value of the P4 argument as
 80629  80725   ** the result.
 80630  80726   **
 80631  80727   ** If the OPFLAG_CLEARCACHE bit is set on P5 and P1 is a pseudo-table cursor,
 80632  80728   ** then the cache of the cursor is reset prior to extracting the column.
 80633  80729   ** The first OP_Column against a pseudo-table after the value of the content
 80634  80730   ** register has changed should have this bit set.
 80635  80731   **
 80636         -** If the OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG bits are set on P5 when
        80732  +** If the OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG bits are set on P5 then
 80637  80733   ** the result is guaranteed to only be used as the argument of a length()
 80638  80734   ** or typeof() function, respectively.  The loading of large blobs can be
 80639  80735   ** skipped for length() and all content loading can be skipped for typeof().
 80640  80736   */
 80641  80737   case OP_Column: {
 80642  80738     int p2;            /* column number to retrieve */
 80643  80739     VdbeCursor *pC;    /* The VDBE cursor */
................................................................................
 80884  80980   }
 80885  80981   
 80886  80982   /* Opcode: Affinity P1 P2 * P4 *
 80887  80983   ** Synopsis: affinity(r[P1@P2])
 80888  80984   **
 80889  80985   ** Apply affinities to a range of P2 registers starting with P1.
 80890  80986   **
 80891         -** P4 is a string that is P2 characters long. The nth character of the
 80892         -** string indicates the column affinity that should be used for the nth
        80987  +** P4 is a string that is P2 characters long. The N-th character of the
        80988  +** string indicates the column affinity that should be used for the N-th
 80893  80989   ** memory cell in the range.
 80894  80990   */
 80895  80991   case OP_Affinity: {
 80896  80992     const char *zAffinity;   /* The affinity to be applied */
 80897         -  char cAff;               /* A single character of affinity */
 80898  80993   
 80899  80994     zAffinity = pOp->p4.z;
 80900  80995     assert( zAffinity!=0 );
        80996  +  assert( pOp->p2>0 );
 80901  80997     assert( zAffinity[pOp->p2]==0 );
 80902  80998     pIn1 = &aMem[pOp->p1];
 80903         -  while( (cAff = *(zAffinity++))!=0 ){
        80999  +  do{
 80904  81000       assert( pIn1 <= &p->aMem[(p->nMem+1 - p->nCursor)] );
 80905  81001       assert( memIsValid(pIn1) );
 80906         -    applyAffinity(pIn1, cAff, encoding);
        81002  +    applyAffinity(pIn1, *(zAffinity++), encoding);
 80907  81003       pIn1++;
 80908         -  }
        81004  +  }while( zAffinity[0] );
 80909  81005     break;
 80910  81006   }
 80911  81007   
 80912  81008   /* Opcode: MakeRecord P1 P2 P3 P4 *
 80913  81009   ** Synopsis: r[P3]=mkrec(r[P1@P2])
 80914  81010   **
 80915  81011   ** Convert P2 registers beginning with P1 into the [record format]
 80916  81012   ** use as a data record in a database table or as a key
 80917  81013   ** in an index.  The OP_Column opcode can decode the record later.
 80918  81014   **
 80919         -** P4 may be a string that is P2 characters long.  The nth character of the
 80920         -** string indicates the column affinity that should be used for the nth
        81015  +** P4 may be a string that is P2 characters long.  The N-th character of the
        81016  +** string indicates the column affinity that should be used for the N-th
 80921  81017   ** field of the index key.
 80922  81018   **
 80923  81019   ** The mapping from character to affinity is given by the SQLITE_AFF_
 80924  81020   ** macros defined in sqliteInt.h.
 80925  81021   **
 80926  81022   ** If P4 is NULL then all index fields have the affinity BLOB.
 80927  81023   */
................................................................................
 81072  81168     assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
 81073  81169     pOut->n = (int)nByte;
 81074  81170     pOut->flags = MEM_Blob;
 81075  81171     if( nZero ){
 81076  81172       pOut->u.nZero = nZero;
 81077  81173       pOut->flags |= MEM_Zero;
 81078  81174     }
 81079         -  pOut->enc = SQLITE_UTF8;  /* In case the blob is ever converted to text */
 81080  81175     REGISTER_TRACE(pOp->p3, pOut);
 81081  81176     UPDATE_MAX_BLOBSIZE(pOut);
 81082  81177     break;
 81083  81178   }
 81084  81179   
 81085  81180   /* Opcode: Count P1 P2 * * *
 81086  81181   ** Synopsis: r[P2]=count()
................................................................................
 81701  81796     testcase( pOp->p2 & OPFLAG_SEEKEQ );
 81702  81797   #endif
 81703  81798     sqlite3BtreeCursorHintFlags(pCur->uc.pCursor,
 81704  81799                                  (pOp->p5 & (OPFLAG_BULKCSR|OPFLAG_SEEKEQ)));
 81705  81800     if( rc ) goto abort_due_to_error;
 81706  81801     break;
 81707  81802   }
        81803  +
        81804  +/* Opcode: OpenDup P1 P2 * * *
        81805  +**
        81806  +** Open a new cursor P1 that points to the same ephemeral table as
        81807  +** cursor P2.  The P2 cursor must have been opened by a prior OP_OpenEphemeral
        81808  +** opcode.  Only ephemeral cursors may be duplicated.
        81809  +**
        81810  +** Duplicate ephemeral cursors are used for self-joins of materialized views.
        81811  +*/
        81812  +case OP_OpenDup: {
        81813  +  VdbeCursor *pOrig;    /* The original cursor to be duplicated */
        81814  +  VdbeCursor *pCx;      /* The new cursor */
        81815  +
        81816  +  pOrig = p->apCsr[pOp->p2];
        81817  +  assert( pOrig->pBtx!=0 );  /* Only ephemeral cursors can be duplicated */
        81818  +
        81819  +  pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE);
        81820  +  if( pCx==0 ) goto no_mem;
        81821  +  pCx->nullRow = 1;
        81822  +  pCx->isEphemeral = 1;
        81823  +  pCx->pKeyInfo = pOrig->pKeyInfo;
        81824  +  pCx->isTable = pOrig->isTable;
        81825  +  rc = sqlite3BtreeCursor(pOrig->pBtx, MASTER_ROOT, BTREE_WRCSR,
        81826  +                          pCx->pKeyInfo, pCx->uc.pCursor);
        81827  +  /* The sqlite3BtreeCursor() routine can only fail for the first cursor
        81828  +  ** opened for a database.  Since there is already an open cursor when this
        81829  +  ** opcode is run, the sqlite3BtreeCursor() cannot fail */
        81830  +  assert( rc==SQLITE_OK );
        81831  +  break;
        81832  +}
        81833  +
 81708  81834   
 81709  81835   /* Opcode: OpenEphemeral P1 P2 * P4 P5
 81710  81836   ** Synopsis: nColumn=P2
 81711  81837   **
 81712  81838   ** Open a new cursor P1 to a transient table.
 81713  81839   ** The cursor is always opened read/write even if 
 81714  81840   ** the main database is read-only.  The ephemeral
................................................................................
 82257  82383         if( pIdxKey->aMem[ii].flags & MEM_Null ){
 82258  82384           takeJump = 1;
 82259  82385           break;
 82260  82386         }
 82261  82387       }
 82262  82388     }
 82263  82389     rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, pIdxKey, 0, 0, &res);
 82264         -  if( pFree ) sqlite3DbFree(db, pFree);
        82390  +  if( pFree ) sqlite3DbFreeNN(db, pFree);
 82265  82391     if( rc!=SQLITE_OK ){
 82266  82392       goto abort_due_to_error;
 82267  82393     }
 82268  82394     pC->seekResult = res;
 82269  82395     alreadyExists = (res==0);
 82270  82396     pC->nullRow = 1-alreadyExists;
 82271  82397     pC->deferredMoveto = 0;
................................................................................
 83567  83693   ** P3==1 then the table to be clear is in the auxiliary database file
 83568  83694   ** that is used to store tables create using CREATE TEMPORARY TABLE.
 83569  83695   **
 83570  83696   ** If AUTOVACUUM is enabled then it is possible that another root page
 83571  83697   ** might be moved into the newly deleted root page in order to keep all
 83572  83698   ** root pages contiguous at the beginning of the database.  The former
 83573  83699   ** value of the root page that moved - its value before the move occurred -
 83574         -** is stored in register P2.  If no page 
 83575         -** movement was required (because the table being dropped was already 
 83576         -** the last one in the database) then a zero is stored in register P2.
 83577         -** If AUTOVACUUM is disabled then a zero is stored in register P2.
        83700  +** is stored in register P2. If no page movement was required (because the
        83701  +** table being dropped was already the last one in the database) then a 
        83702  +** zero is stored in register P2.  If AUTOVACUUM is disabled then a zero 
        83703  +** is stored in register P2.
        83704  +**
        83705  +** This opcode throws an error if there are any active reader VMs when
        83706  +** it is invoked. This is done to avoid the difficulty associated with 
        83707  +** updating existing cursors when a root page is moved in an AUTOVACUUM 
        83708  +** database. This error is thrown even if the database is not an AUTOVACUUM 
        83709  +** db in order to avoid introducing an incompatibility between autovacuum 
        83710  +** and non-autovacuum modes.
 83578  83711   **
 83579  83712   ** See also: Clear
 83580  83713   */
 83581  83714   case OP_Destroy: {     /* out2 */
 83582  83715     int iMoved;
 83583  83716     int iDb;
 83584  83717   
................................................................................
 83775  83908       }else{
 83776  83909         assert( db->init.busy==0 );
 83777  83910         db->init.busy = 1;
 83778  83911         initData.rc = SQLITE_OK;
 83779  83912         assert( !db->mallocFailed );
 83780  83913         rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
 83781  83914         if( rc==SQLITE_OK ) rc = initData.rc;
 83782         -      sqlite3DbFree(db, zSql);
        83915  +      sqlite3DbFreeNN(db, zSql);
 83783  83916         db->init.busy = 0;
 83784  83917       }
 83785  83918     }
 83786  83919     if( rc ){
 83787  83920       sqlite3ResetAllSchemasOfConnection(db);
 83788  83921       if( rc==SQLITE_NOMEM ){
 83789  83922         goto no_mem;
................................................................................
 83903  84036     break;
 83904  84037   }
 83905  84038   #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
 83906  84039   
 83907  84040   /* Opcode: RowSetAdd P1 P2 * * *
 83908  84041   ** Synopsis: rowset(P1)=r[P2]
 83909  84042   **
 83910         -** Insert the integer value held by register P2 into a boolean index
        84043  +** Insert the integer value held by register P2 into a RowSet object
 83911  84044   ** held in register P1.
 83912  84045   **
 83913  84046   ** An assertion fails if P2 is not an integer.
 83914  84047   */
 83915  84048   case OP_RowSetAdd: {       /* in1, in2 */
 83916  84049     pIn1 = &aMem[pOp->p1];
 83917  84050     pIn2 = &aMem[pOp->p2];
................................................................................
 83923  84056     sqlite3RowSetInsert(pIn1->u.pRowSet, pIn2->u.i);
 83924  84057     break;
 83925  84058   }
 83926  84059   
 83927  84060   /* Opcode: RowSetRead P1 P2 P3 * *
 83928  84061   ** Synopsis: r[P3]=rowset(P1)
 83929  84062   **
 83930         -** Extract the smallest value from boolean index P1 and put that value into
 83931         -** register P3.  Or, if boolean index P1 is initially empty, leave P3
        84063  +** Extract the smallest value from the RowSet object in P1
        84064  +** and put that value into register P3.
        84065  +** Or, if RowSet object P1 is initially empty, leave P3
 83932  84066   ** unchanged and jump to instruction P2.
 83933  84067   */
 83934  84068   case OP_RowSetRead: {       /* jump, in1, out3 */
 83935  84069     i64 val;
 83936  84070   
 83937  84071     pIn1 = &aMem[pOp->p1];
 83938  84072     if( (pIn1->flags & MEM_RowSet)==0 
................................................................................
 83955  84089   **
 83956  84090   ** Register P3 is assumed to hold a 64-bit integer value. If register P1
 83957  84091   ** contains a RowSet object and that RowSet object contains
 83958  84092   ** the value held in P3, jump to register P2. Otherwise, insert the
 83959  84093   ** integer in P3 into the RowSet and continue on to the
 83960  84094   ** next opcode.
 83961  84095   **
 83962         -** The RowSet object is optimized for the case where successive sets
 83963         -** of integers, where each set contains no duplicates. Each set
 83964         -** of values is identified by a unique P4 value. The first set
 83965         -** must have P4==0, the final set P4=-1.  P4 must be either -1 or
 83966         -** non-negative.  For non-negative values of P4 only the lower 4
 83967         -** bits are significant.
        84096  +** The RowSet object is optimized for the case where sets of integers
        84097  +** are inserted in distinct phases, which each set contains no duplicates.
        84098  +** Each set is identified by a unique P4 value. The first set
        84099  +** must have P4==0, the final set must have P4==-1, and for all other sets
        84100  +** must have P4>0.
 83968  84101   **
 83969  84102   ** This allows optimizations: (a) when P4==0 there is no need to test
 83970         -** the rowset object for P3, as it is guaranteed not to contain it,
        84103  +** the RowSet object for P3, as it is guaranteed not to contain it,
 83971  84104   ** (b) when P4==-1 there is no need to insert the value, as it will
 83972  84105   ** never be tested for, and (c) when a value that is part of set X is
 83973  84106   ** inserted, there is no need to search to see if the same value was
 83974  84107   ** previously inserted as part of set X (only if it was previously
 83975  84108   ** inserted as part of some other set).
 83976  84109   */
 83977  84110   case OP_RowSetTest: {                     /* jump, in1, in3 */
................................................................................
 86703  86836     const u8 * const v1 = &p1[ p1[0] ];   /* Pointer to value 1 */
 86704  86837     const u8 * const v2 = &p2[ p2[0] ];   /* Pointer to value 2 */
 86705  86838     int res;                              /* Return value */
 86706  86839   
 86707  86840     assert( (s1>0 && s1<7) || s1==8 || s1==9 );
 86708  86841     assert( (s2>0 && s2<7) || s2==8 || s2==9 );
 86709  86842   
 86710         -  if( s1>7 && s2>7 ){
        86843  +  if( s1==s2 ){
        86844  +    /* The two values have the same sign. Compare using memcmp(). */
        86845  +    static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8, 0, 0, 0 };
        86846  +    const u8 n = aLen[s1];
        86847  +    int i;
        86848  +    res = 0;
        86849  +    for(i=0; i<n; i++){
        86850  +      if( (res = v1[i] - v2[i])!=0 ){
        86851  +        if( ((v1[0] ^ v2[0]) & 0x80)!=0 ){
        86852  +          res = v1[0] & 0x80 ? -1 : +1;
        86853  +        }
        86854  +        break;
        86855  +      }
        86856  +    }
        86857  +  }else if( s1>7 && s2>7 ){
 86711  86858       res = s1 - s2;
 86712  86859     }else{
 86713         -    if( s1==s2 ){
 86714         -      if( (*v1 ^ *v2) & 0x80 ){
 86715         -        /* The two values have different signs */
 86716         -        res = (*v1 & 0x80) ? -1 : +1;
 86717         -      }else{
 86718         -        /* The two values have the same sign. Compare using memcmp(). */
 86719         -        static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8 };
 86720         -        int i;
 86721         -        res = 0;
 86722         -        for(i=0; i<aLen[s1]; i++){
 86723         -          if( (res = v1[i] - v2[i]) ) break;
 86724         -        }
 86725         -      }
        86860  +    if( s2>7 ){
        86861  +      res = +1;
        86862  +    }else if( s1>7 ){
        86863  +      res = -1;
 86726  86864       }else{
 86727         -      if( s2>7 ){
 86728         -        res = +1;
 86729         -      }else if( s1>7 ){
 86730         -        res = -1;
 86731         -      }else{
 86732         -        res = s1 - s2;
 86733         -      }
 86734         -      assert( res!=0 );
        86865  +      res = s1 - s2;
        86866  +    }
        86867  +    assert( res!=0 );
 86735  86868   
 86736         -      if( res>0 ){
 86737         -        if( *v1 & 0x80 ) res = -1;
 86738         -      }else{
 86739         -        if( *v2 & 0x80 ) res = +1;
 86740         -      }
        86869  +    if( res>0 ){
        86870  +      if( *v1 & 0x80 ) res = -1;
        86871  +    }else{
        86872  +      if( *v2 & 0x80 ) res = +1;
 86741  86873       }
 86742  86874     }
 86743  86875   
 86744  86876     if( res==0 ){
 86745  86877       if( pTask->pSorter->pKeyInfo->nField>1 ){
 86746  86878         res = vdbeSorterCompareTail(
 86747  86879             pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
................................................................................
 90788  90920     if( op==TK_REGISTER ) op = pExpr->op2;
 90789  90921   #ifndef SQLITE_OMIT_CAST
 90790  90922     if( op==TK_CAST ){
 90791  90923       assert( !ExprHasProperty(pExpr, EP_IntValue) );
 90792  90924       return sqlite3AffinityType(pExpr->u.zToken, 0);
 90793  90925     }
 90794  90926   #endif
 90795         -  if( op==TK_AGG_COLUMN || op==TK_COLUMN ){
        90927  +  if( (op==TK_AGG_COLUMN || op==TK_COLUMN) && pExpr->pTab ){
 90796  90928       return sqlite3TableColumnAffinity(pExpr->pTab, pExpr->iColumn);
 90797  90929     }
 90798  90930     if( op==TK_SELECT_COLUMN ){
 90799  90931       assert( pExpr->pLeft->flags&EP_xIsSelect );
 90800  90932       return sqlite3ExprAffinity(
 90801  90933           pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
 90802  90934       );
................................................................................
 91686  91818     ynVar x;
 91687  91819   
 91688  91820     if( pExpr==0 ) return;
 91689  91821     assert( !ExprHasProperty(pExpr, EP_IntValue|EP_Reduced|EP_TokenOnly) );
 91690  91822     z = pExpr->u.zToken;
 91691  91823     assert( z!=0 );
 91692  91824     assert( z[0]!=0 );
 91693         -  assert( n==sqlite3Strlen30(z) );
        91825  +  assert( n==(u32)sqlite3Strlen30(z) );
 91694  91826     if( z[1]==0 ){
 91695  91827       /* Wildcard of the form "?".  Assign the next variable number */
 91696  91828       assert( z[0]=='?' );
 91697  91829       x = (ynVar)(++pParse->nVar);
 91698  91830     }else{
 91699  91831       int doAdd = 0;
 91700  91832       if( z[0]=='?' ){
................................................................................
 91768  91900         sqlite3SelectDelete(db, p->x.pSelect);
 91769  91901       }else{
 91770  91902         sqlite3ExprListDelete(db, p->x.pList);
 91771  91903       }
 91772  91904     }
 91773  91905     if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken);
 91774  91906     if( !ExprHasProperty(p, EP_Static) ){
 91775         -    sqlite3DbFree(db, p);
        91907  +    sqlite3DbFreeNN(db, p);
 91776  91908     }
 91777  91909   }
 91778  91910   SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
 91779  91911     if( p ) sqlite3ExprDeleteNN(db, p);
 91780  91912   }
 91781  91913   
 91782  91914   /*
................................................................................
 92035  92167   SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
 92036  92168     ExprList *pNew;
 92037  92169     struct ExprList_item *pItem, *pOldItem;
 92038  92170     int i;
 92039  92171     Expr *pPriorSelectCol = 0;
 92040  92172     assert( db!=0 );
 92041  92173     if( p==0 ) return 0;
 92042         -  pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
        92174  +  pNew = sqlite3DbMallocRawNN(db, 
        92175  +             sizeof(*pNew)+sizeof(pNew->a[0])*(p->nExpr-1) );
 92043  92176     if( pNew==0 ) return 0;
 92044         -  pNew->nExpr = i = p->nExpr;
 92045         -  if( (flags & EXPRDUP_REDUCE)==0 ) for(i=1; i<p->nExpr; i+=i){}
 92046         -  pNew->a = pItem = sqlite3DbMallocRawNN(db,  i*sizeof(p->a[0]) );
 92047         -  if( pItem==0 ){
 92048         -    sqlite3DbFree(db, pNew);
 92049         -    return 0;
 92050         -  } 
        92177  +  pNew->nAlloc = pNew->nExpr = p->nExpr;
        92178  +  pItem = pNew->a;
 92051  92179     pOldItem = p->a;
 92052  92180     for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
 92053  92181       Expr *pOldExpr = pOldItem->pExpr;
 92054  92182       Expr *pNewExpr;
 92055  92183       pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
 92056  92184       if( pOldExpr 
 92057  92185        && pOldExpr->op==TK_SELECT_COLUMN
................................................................................
 92134  92262     assert( db!=0 );
 92135  92263     if( p==0 ) return 0;
 92136  92264     pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
 92137  92265     if( pNew==0 ) return 0;
 92138  92266     pNew->nId = p->nId;
 92139  92267     pNew->a = sqlite3DbMallocRawNN(db, p->nId*sizeof(p->a[0]) );
 92140  92268     if( pNew->a==0 ){
 92141         -    sqlite3DbFree(db, pNew);
        92269  +    sqlite3DbFreeNN(db, pNew);
 92142  92270       return 0;
 92143  92271     }
 92144  92272     /* Note that because the size of the allocation for p->a[] is not
 92145  92273     ** necessarily a power of two, sqlite3IdListAppend() may not be called
 92146  92274     ** on the duplicate created by this function. */
 92147  92275     for(i=0; i<p->nId; i++){
 92148  92276       struct IdList_item *pNewItem = &pNew->a[i];
................................................................................
 92205  92333   ** that the new entry was successfully appended.
 92206  92334   */
 92207  92335   SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(
 92208  92336     Parse *pParse,          /* Parsing context */
 92209  92337     ExprList *pList,        /* List to which to append. Might be NULL */
 92210  92338     Expr *pExpr             /* Expression to be appended. Might be NULL */
 92211  92339   ){
        92340  +  struct ExprList_item *pItem;
 92212  92341     sqlite3 *db = pParse->db;
 92213  92342     assert( db!=0 );
 92214  92343     if( pList==0 ){
 92215  92344       pList = sqlite3DbMallocRawNN(db, sizeof(ExprList) );
 92216  92345       if( pList==0 ){
 92217  92346         goto no_mem;
 92218  92347       }
 92219  92348       pList->nExpr = 0;
 92220         -    pList->a = sqlite3DbMallocRawNN(db, sizeof(pList->a[0]));
 92221         -    if( pList->a==0 ) goto no_mem;
 92222         -  }else if( (pList->nExpr & (pList->nExpr-1))==0 ){
 92223         -    struct ExprList_item *a;
 92224         -    assert( pList->nExpr>0 );
 92225         -    a = sqlite3DbRealloc(db, pList->a, pList->nExpr*2*sizeof(pList->a[0]));
 92226         -    if( a==0 ){
        92349  +    pList->nAlloc = 1;
        92350  +  }else if( pList->nExpr==pList->nAlloc ){
        92351  +    ExprList *pNew;
        92352  +    pNew = sqlite3DbRealloc(db, pList, 
        92353  +             sizeof(*pList)+(2*pList->nAlloc - 1)*sizeof(pList->a[0]));
        92354  +    if( pNew==0 ){
 92227  92355         goto no_mem;
 92228  92356       }
 92229         -    pList->a = a;
        92357  +    pList = pNew;
        92358  +    pList->nAlloc *= 2;
 92230  92359     }
 92231         -  assert( pList->a!=0 );
 92232         -  if( 1 ){
 92233         -    struct ExprList_item *pItem = &pList->a[pList->nExpr++];
 92234         -    memset(pItem, 0, sizeof(*pItem));
 92235         -    pItem->pExpr = pExpr;
 92236         -  }
        92360  +  pItem = &pList->a[pList->nExpr++];
        92361  +  memset(pItem, 0, sizeof(*pItem));
        92362  +  pItem->pExpr = pExpr;
 92237  92363     return pList;
 92238  92364   
 92239  92365   no_mem:     
 92240  92366     /* Avoid leaking memory if malloc has failed. */
 92241  92367     sqlite3ExprDelete(db, pExpr);
 92242  92368     sqlite3ExprListDelete(db, pList);
 92243  92369     return 0;
................................................................................
 92286  92412       if( pList ){
 92287  92413         assert( pList->nExpr==iFirst+i+1 );
 92288  92414         pList->a[pList->nExpr-1].zName = pColumns->a[i].zName;
 92289  92415         pColumns->a[i].zName = 0;
 92290  92416       }
 92291  92417     }
 92292  92418   
 92293         -  if( pExpr->op==TK_SELECT ){
 92294         -    if( pList && pList->a[iFirst].pExpr ){
 92295         -      Expr *pFirst = pList->a[iFirst].pExpr;
 92296         -      assert( pFirst->op==TK_SELECT_COLUMN );
        92419  +  if( !db->mallocFailed && pExpr->op==TK_SELECT && ALWAYS(pList!=0) ){
        92420  +    Expr *pFirst = pList->a[iFirst].pExpr;
        92421  +    assert( pFirst!=0 );
        92422  +    assert( pFirst->op==TK_SELECT_COLUMN );
 92297  92423        
 92298         -      /* Store the SELECT statement in pRight so it will be deleted when
 92299         -      ** sqlite3ExprListDelete() is called */
 92300         -      pFirst->pRight = pExpr;
 92301         -      pExpr = 0;
        92424  +    /* Store the SELECT statement in pRight so it will be deleted when
        92425  +    ** sqlite3ExprListDelete() is called */
        92426  +    pFirst->pRight = pExpr;
        92427  +    pExpr = 0;
 92302  92428   
 92303         -      /* Remember the size of the LHS in iTable so that we can check that
 92304         -      ** the RHS and LHS sizes match during code generation. */
 92305         -      pFirst->iTable = pColumns->nId;
 92306         -    }
        92429  +    /* Remember the size of the LHS in iTable so that we can check that
        92430  +    ** the RHS and LHS sizes match during code generation. */
        92431  +    pFirst->iTable = pColumns->nId;
 92307  92432     }
 92308  92433   
 92309  92434   vector_append_error:
 92310  92435     sqlite3ExprDelete(db, pExpr);
 92311  92436     sqlite3IdListDelete(db, pColumns);
 92312  92437     return pList;
 92313  92438   }
................................................................................
 92393  92518     }
 92394  92519   }
 92395  92520   
 92396  92521   /*
 92397  92522   ** Delete an entire expression list.
 92398  92523   */
 92399  92524   static SQLITE_NOINLINE void exprListDeleteNN(sqlite3 *db, ExprList *pList){
 92400         -  int i;
 92401         -  struct ExprList_item *pItem;
 92402         -  assert( pList->a!=0 || pList->nExpr==0 );
 92403         -  for(pItem=pList->a, i=0; i<pList->nExpr; i++, pItem++){
        92525  +  int i = pList->nExpr;
        92526  +  struct ExprList_item *pItem =  pList->a;
        92527  +  assert( pList->nExpr>0 );
        92528  +  do{
 92404  92529       sqlite3ExprDelete(db, pItem->pExpr);
 92405  92530       sqlite3DbFree(db, pItem->zName);
 92406  92531       sqlite3DbFree(db, pItem->zSpan);
 92407         -  }
 92408         -  sqlite3DbFree(db, pList->a);
 92409         -  sqlite3DbFree(db, pList);
        92532  +    pItem++;
        92533  +  }while( --i>0 );
        92534  +  sqlite3DbFreeNN(db, pList);
 92410  92535   }
 92411  92536   SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
 92412  92537     if( pList ) exprListDeleteNN(db, pList);
 92413  92538   }
 92414  92539   
 92415  92540   /*
 92416  92541   ** Return the bitwise-OR of all Expr.flags fields in the given
................................................................................
 92552  92677   ** expression must not refer to any non-deterministic function nor any
 92553  92678   ** table other than iCur.
 92554  92679   */
 92555  92680   SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
 92556  92681     return exprIsConst(p, 3, iCur);
 92557  92682   }
 92558  92683   
        92684  +
        92685  +/*
        92686  +** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
        92687  +*/
        92688  +static int exprNodeIsConstantOrGroupBy(Walker *pWalker, Expr *pExpr){
        92689  +  ExprList *pGroupBy = pWalker->u.pGroupBy;
        92690  +  int i;
        92691  +
        92692  +  /* Check if pExpr is identical to any GROUP BY term. If so, consider
        92693  +  ** it constant.  */
        92694  +  for(i=0; i<pGroupBy->nExpr; i++){
        92695  +    Expr *p = pGroupBy->a[i].pExpr;
        92696  +    if( sqlite3ExprCompare(pExpr, p, -1)<2 ){
        92697  +      CollSeq *pColl = sqlite3ExprCollSeq(pWalker->pParse, p);
        92698  +      if( pColl==0 || sqlite3_stricmp("BINARY", pColl->zName)==0 ){
        92699  +        return WRC_Prune;
        92700  +      }
        92701  +    }
        92702  +  }
        92703  +
        92704  +  /* Check if pExpr is a sub-select. If so, consider it variable. */
        92705  +  if( ExprHasProperty(pExpr, EP_xIsSelect) ){
        92706  +    pWalker->eCode = 0;
        92707  +    return WRC_Abort;
        92708  +  }
        92709  +
        92710  +  return exprNodeIsConstant(pWalker, pExpr);
        92711  +}
        92712  +
        92713  +/*
        92714  +** Walk the expression tree passed as the first argument. Return non-zero
        92715  +** if the expression consists entirely of constants or copies of terms 
        92716  +** in pGroupBy that sort with the BINARY collation sequence.
        92717  +**
        92718  +** This routine is used to determine if a term of the HAVING clause can
        92719  +** be promoted into the WHERE clause.  In order for such a promotion to work,
        92720  +** the value of the HAVING clause term must be the same for all members of
        92721  +** a "group".  The requirement that the GROUP BY term must be BINARY
        92722  +** assumes that no other collating sequence will have a finer-grained
        92723  +** grouping than binary.  In other words (A=B COLLATE binary) implies
        92724  +** A=B in every other collating sequence.  The requirement that the
        92725  +** GROUP BY be BINARY is stricter than necessary.  It would also work
        92726  +** to promote HAVING clauses that use the same alternative collating
        92727  +** sequence as the GROUP BY term, but that is much harder to check,
        92728  +** alternative collating sequences are uncommon, and this is only an
        92729  +** optimization, so we take the easy way out and simply require the
        92730  +** GROUP BY to use the BINARY collating sequence.
        92731  +*/
        92732  +SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse *pParse, Expr *p, ExprList *pGroupBy){
        92733  +  Walker w;
        92734  +  memset(&w, 0, sizeof(w));
        92735  +  w.eCode = 1;
        92736  +  w.xExprCallback = exprNodeIsConstantOrGroupBy;
        92737  +  w.u.pGroupBy = pGroupBy;
        92738  +  w.pParse = pParse;
        92739  +  sqlite3WalkExpr(&w, p);
        92740  +  return w.eCode;
        92741  +}
        92742  +
 92559  92743   /*
 92560  92744   ** Walk an expression tree.  Return non-zero if the expression is constant
 92561  92745   ** or a function call with constant arguments.  Return and 0 if there
 92562  92746   ** are any variables.
 92563  92747   **
 92564  92748   ** For the purposes of this function, a double-quoted string (ex: "abc")
 92565  92749   ** is considered a variable but a single-quoted string (ex: 'abc') is
................................................................................
 93929  94113   SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(
 93930  94114     Vdbe *v,        /* The VDBE under construction */
 93931  94115     Table *pTab,    /* The table containing the value */
 93932  94116     int iTabCur,    /* The table cursor.  Or the PK cursor for WITHOUT ROWID */
 93933  94117     int iCol,       /* Index of the column to extract */
 93934  94118     int regOut      /* Extract the value into this register */
 93935  94119   ){
        94120  +  if( pTab==0 ){
        94121  +    sqlite3VdbeAddOp3(v, OP_Column, iTabCur, iCol, regOut);
        94122  +    return;
        94123  +  }
 93936  94124     if( iCol<0 || iCol==pTab->iPKey ){
 93937  94125       sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
 93938  94126     }else{
 93939  94127       int op = IsVirtual(pTab) ? OP_VColumn : OP_Column;
 93940  94128       int x = iCol;
 93941  94129       if( !HasRowid(pTab) && !IsVirtual(pTab) ){
 93942  94130         x = sqlite3ColumnOfIndex(sqlite3PrimaryKeyIndex(pTab), iCol);
................................................................................
 94621  94809         break;
 94622  94810       }
 94623  94811   
 94624  94812       case TK_VECTOR: {
 94625  94813         sqlite3ErrorMsg(pParse, "row value misused");
 94626  94814         break;
 94627  94815       }
        94816  +
        94817  +    case TK_IF_NULL_ROW: {
        94818  +      int addrINR;
        94819  +      addrINR = sqlite3VdbeAddOp1(v, OP_IfNullRow, pExpr->iTable);
        94820  +      sqlite3ExprCachePush(pParse);
        94821  +      inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
        94822  +      sqlite3ExprCachePop(pParse);
        94823  +      sqlite3VdbeJumpHere(v, addrINR);
        94824  +      sqlite3VdbeChangeP3(v, addrINR, inReg);
        94825  +      break;
        94826  +    }
 94628  94827   
 94629  94828       /*
 94630  94829       ** Form A:
 94631  94830       **   CASE x WHEN e1 THEN r1 WHEN e2 THEN r2 ... WHEN eN THEN rN ELSE y END
 94632  94831       **
 94633  94832       ** Form B:
 94634  94833       **   CASE WHEN e1 THEN r1 WHEN e2 THEN r2 ... WHEN eN THEN rN ELSE y END
................................................................................
103070 103269   SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *db, IdList *pList){
103071 103270     int i;
103072 103271     if( pList==0 ) return;
103073 103272     for(i=0; i<pList->nId; i++){
103074 103273       sqlite3DbFree(db, pList->a[i].zName);
103075 103274     }
103076 103275     sqlite3DbFree(db, pList->a);
103077         -  sqlite3DbFree(db, pList);
       103276  +  sqlite3DbFreeNN(db, pList);
103078 103277   }
103079 103278   
103080 103279   /*
103081 103280   ** Return the index in pList of the identifier named zId.  Return -1
103082 103281   ** if not found.
103083 103282   */
103084 103283   SQLITE_PRIVATE int sqlite3IdListIndex(IdList *pList, const char *zName){
................................................................................
103260 103459       if( pItem->fg.isIndexedBy ) sqlite3DbFree(db, pItem->u1.zIndexedBy);
103261 103460       if( pItem->fg.isTabFunc ) sqlite3ExprListDelete(db, pItem->u1.pFuncArg);
103262 103461       sqlite3DeleteTable(db, pItem->pTab);
103263 103462       sqlite3SelectDelete(db, pItem->pSelect);
103264 103463       sqlite3ExprDelete(db, pItem->pOn);
103265 103464       sqlite3IdListDelete(db, pItem->pUsing);
103266 103465     }
103267         -  sqlite3DbFree(db, pList);
       103466  +  sqlite3DbFreeNN(db, pList);
103268 103467   }
103269 103468   
103270 103469   /*
103271 103470   ** This routine is called by the parser to add a new term to the
103272 103471   ** end of a growing FROM clause.  The "p" parameter is the part of
103273 103472   ** the FROM clause that has already been constructed.  "p" is NULL
103274 103473   ** if this is the first term of the FROM clause.  pTable and pDatabase
................................................................................
108244 108443   ** to an array of size N, where N is the number of columns in table pTab.
108245 108444   ** If the i'th column is not modified by the UPDATE, then the corresponding 
108246 108445   ** entry in the aChange[] array is set to -1. If the column is modified,
108247 108446   ** the value is 0 or greater. Parameter chngRowid is set to true if the
108248 108447   ** UPDATE statement modifies the rowid fields of the table.
108249 108448   **
108250 108449   ** If any foreign key processing will be required, this function returns
108251         -** true. If there is no foreign key related processing, this function 
108252         -** returns false.
       108450  +** non-zero. If there is no foreign key related processing, this function 
       108451  +** returns zero.
       108452  +**
       108453  +** For an UPDATE, this function returns 2 if:
       108454  +**
       108455  +**   * There are any FKs for which pTab is the child and the parent table, or
       108456  +**   * the UPDATE modifies one or more parent keys for which the action is
       108457  +**     not "NO ACTION" (i.e. is CASCADE, SET DEFAULT or SET NULL).
       108458  +**
       108459  +** Or, assuming some other foreign key processing is required, 1.
108253 108460   */
108254 108461   SQLITE_PRIVATE int sqlite3FkRequired(
108255 108462     Parse *pParse,                  /* Parse context */
108256 108463     Table *pTab,                    /* Table being modified */
108257 108464     int *aChange,                   /* Non-NULL for UPDATE operations */
108258 108465     int chngRowid                   /* True for UPDATE that affects rowid */
108259 108466   ){
       108467  +  int eRet = 0;
108260 108468     if( pParse->db->flags&SQLITE_ForeignKeys ){
108261 108469       if( !aChange ){
108262 108470         /* A DELETE operation. Foreign key processing is required if the 
108263 108471         ** table in question is either the child or parent table for any 
108264 108472         ** foreign key constraint.  */
108265         -      return (sqlite3FkReferences(pTab) || pTab->pFKey);
       108473  +      eRet = (sqlite3FkReferences(pTab) || pTab->pFKey);
108266 108474       }else{
108267 108475         /* This is an UPDATE. Foreign key processing is only required if the
108268 108476         ** operation modifies one or more child or parent key columns. */
108269 108477         FKey *p;
108270 108478   
108271 108479         /* Check if any child key columns are being modified. */
108272 108480         for(p=pTab->pFKey; p; p=p->pNextFrom){
108273         -        if( fkChildIsModified(pTab, p, aChange, chngRowid) ) return 1;
       108481  +        if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) return 2;
       108482  +        if( fkChildIsModified(pTab, p, aChange, chngRowid) ){
       108483  +          eRet = 1;
       108484  +        }
108274 108485         }
108275 108486   
108276 108487         /* Check if any parent key columns are being modified. */
108277 108488         for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
108278         -        if( fkParentIsModified(pTab, p, aChange, chngRowid) ) return 1;
       108489  +        if( fkParentIsModified(pTab, p, aChange, chngRowid) ){
       108490  +          if( p->aAction[1]!=OE_None ) return 2;
       108491  +          eRet = 1;
       108492  +        }
108279 108493         }
108280 108494       }
108281 108495     }
108282         -  return 0;
       108496  +  return eRet;
108283 108497   }
108284 108498   
108285 108499   /*
108286 108500   ** This function is called when an UPDATE or DELETE operation is being 
108287 108501   ** compiled on table pTab, which is the parent table of foreign-key pFKey.
108288 108502   ** If the current operation is an UPDATE, then the pChanges parameter is
108289 108503   ** passed a pointer to the list of columns being modified. If it is a
................................................................................
112785 112999     /* ePragTyp:  */ PragTyp_MMAP_SIZE,
112786 113000     /* ePragFlg:  */ 0,
112787 113001     /* ColNames:  */ 0, 0,
112788 113002     /* iArg:      */ 0 },
112789 113003   #endif
112790 113004    {/* zName:     */ "optimize",
112791 113005     /* ePragTyp:  */ PragTyp_OPTIMIZE,
112792         -  /* ePragFlg:  */ PragFlg_Result1,
       113006  +  /* ePragFlg:  */ PragFlg_Result1|PragFlg_NeedSchema,
112793 113007     /* ColNames:  */ 0, 0,
112794 113008     /* iArg:      */ 0 },
112795 113009   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112796 113010    {/* zName:     */ "page_count",
112797 113011     /* ePragTyp:  */ PragTyp_PAGE_COUNT,
112798 113012     /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
112799 113013     /* ColNames:  */ 0, 0,
................................................................................
114285 114499           pIdx = 0;
114286 114500           aiCols = 0;
114287 114501           if( pParent ){
114288 114502             x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols);
114289 114503             assert( x==0 );
114290 114504           }
114291 114505           addrOk = sqlite3VdbeMakeLabel(v);
114292         -        if( pParent && pIdx==0 ){
114293         -          int iKey = pFK->aCol[0].iFrom;
114294         -          assert( iKey>=0 && iKey<pTab->nCol );
114295         -          if( iKey!=pTab->iPKey ){
114296         -            sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow);
114297         -            sqlite3ColumnDefault(v, pTab, iKey, regRow);
114298         -            sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); VdbeCoverage(v);
114299         -          }else{
114300         -            sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow);
114301         -          }
114302         -          sqlite3VdbeAddOp3(v, OP_SeekRowid, i, 0, regRow); VdbeCoverage(v);
       114506  +
       114507  +        /* Generate code to read the child key values into registers
       114508  +        ** regRow..regRow+n. If any of the child key values are NULL, this 
       114509  +        ** row cannot cause an FK violation. Jump directly to addrOk in 
       114510  +        ** this case. */
       114511  +        for(j=0; j<pFK->nCol; j++){
       114512  +          int iCol = aiCols ? aiCols[j] : pFK->aCol[j].iFrom;
       114513  +          sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, iCol, regRow+j);
       114514  +          sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
       114515  +        }
       114516  +
       114517  +        /* Generate code to query the parent index for a matching parent
       114518  +        ** key. If a match is found, jump to addrOk. */
       114519  +        if( pIdx ){
       114520  +          sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
       114521  +              sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
       114522  +          sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
       114523  +          VdbeCoverage(v);
       114524  +        }else if( pParent ){
       114525  +          int jmp = sqlite3VdbeCurrentAddr(v)+2;
       114526  +          sqlite3VdbeAddOp3(v, OP_SeekRowid, i, jmp, regRow); VdbeCoverage(v);
114303 114527             sqlite3VdbeGoto(v, addrOk);
114304         -          sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
       114528  +          assert( pFK->nCol==1 );
       114529  +        }
       114530  +
       114531  +        /* Generate code to report an FK violation to the caller. */
       114532  +        if( HasRowid(pTab) ){
       114533  +          sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
114305 114534           }else{
114306         -          for(j=0; j<pFK->nCol; j++){
114307         -            sqlite3ExprCodeGetColumnOfTable(v, pTab, 0,
114308         -                            aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j);
114309         -            sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
114310         -          }
114311         -          if( pParent ){
114312         -            sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
114313         -                              sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
114314         -            sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
114315         -            VdbeCoverage(v);
114316         -          }
       114535  +          sqlite3VdbeAddOp2(v, OP_Null, 0, regResult+1);
114317 114536           }
114318         -        sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
114319 114537           sqlite3VdbeMultiLoad(v, regResult+2, "si", pFK->zTo, i-1);
114320 114538           sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
114321 114539           sqlite3VdbeResolveLabel(v, addrOk);
114322 114540           sqlite3DbFree(db, aiCols);
114323 114541         }
114324 114542         sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v);
114325 114543         sqlite3VdbeJumpHere(v, addrTop);
................................................................................
114497 114715                                 pTab->aCol[j].zName);
114498 114716             sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
114499 114717             integrityCheckResultRow(v, 3);
114500 114718             sqlite3VdbeJumpHere(v, jmp2);
114501 114719           }
114502 114720           /* Verify CHECK constraints */
114503 114721           if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
114504         -          int addrCkFault = sqlite3VdbeMakeLabel(v);
114505         -          int addrCkOk = sqlite3VdbeMakeLabel(v);
114506         -          ExprList *pCheck = pTab->pCheck;
114507         -          char *zErr;
114508         -          int k;
114509         -          pParse->iSelfTab = iDataCur;
114510         -          sqlite3ExprCachePush(pParse);
114511         -          for(k=pCheck->nExpr-1; k>0; k--){
114512         -            sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
114513         -          }
114514         -          sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk, 
114515         -                            SQLITE_JUMPIFNULL);
114516         -          sqlite3VdbeResolveLabel(v, addrCkFault);
114517         -          zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
114518         -                                pTab->zName);
114519         -          sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
114520         -          integrityCheckResultRow(v, 3);
114521         -          sqlite3VdbeResolveLabel(v, addrCkOk);
114522         -          sqlite3ExprCachePop(pParse);
       114722  +          ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0);
       114723  +          if( db->mallocFailed==0 ){
       114724  +            int addrCkFault = sqlite3VdbeMakeLabel(v);
       114725  +            int addrCkOk = sqlite3VdbeMakeLabel(v);
       114726  +            char *zErr;
       114727  +            int k;
       114728  +            pParse->iSelfTab = iDataCur;
       114729  +            sqlite3ExprCachePush(pParse);
       114730  +            for(k=pCheck->nExpr-1; k>0; k--){
       114731  +              sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
       114732  +            }
       114733  +            sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk, 
       114734  +                SQLITE_JUMPIFNULL);
       114735  +            sqlite3VdbeResolveLabel(v, addrCkFault);
       114736  +            zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
       114737  +                pTab->zName);
       114738  +            sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
       114739  +            integrityCheckResultRow(v, 3);
       114740  +            sqlite3VdbeResolveLabel(v, addrCkOk);
       114741  +            sqlite3ExprCachePop(pParse);
       114742  +          }
       114743  +          sqlite3ExprListDelete(db, pCheck);
114523 114744           }
114524 114745           /* Validate index entries for the current row */
114525 114746           for(j=0, pIdx=pTab->pIndex; pIdx && !isQuick; pIdx=pIdx->pNext, j++){
114526 114747             int jmp2, jmp3, jmp4, jmp5;
114527 114748             int ckUniq = sqlite3VdbeMakeLabel(v);
114528 114749             if( pPk==pIdx ) continue;
114529 114750             r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
................................................................................
116319 116540       sqlite3ExprDelete(db, p->pWhere);
116320 116541       sqlite3ExprListDelete(db, p->pGroupBy);
116321 116542       sqlite3ExprDelete(db, p->pHaving);
116322 116543       sqlite3ExprListDelete(db, p->pOrderBy);
116323 116544       sqlite3ExprDelete(db, p->pLimit);
116324 116545       sqlite3ExprDelete(db, p->pOffset);
116325 116546       if( p->pWith ) sqlite3WithDelete(db, p->pWith);
116326         -    if( bFree ) sqlite3DbFree(db, p);
       116547  +    if( bFree ) sqlite3DbFreeNN(db, p);
116327 116548       p = pPrior;
116328 116549       bFree = 1;
116329 116550     }
116330 116551   }
116331 116552   
116332 116553   /*
116333 116554   ** Initialize a SelectDest structure.
................................................................................
116355 116576     ExprList *pOrderBy,   /* the ORDER BY clause */
116356 116577     u32 selFlags,         /* Flag parameters, such as SF_Distinct */
116357 116578     Expr *pLimit,         /* LIMIT value.  NULL means not used */
116358 116579     Expr *pOffset         /* OFFSET value.  NULL means no offset */
116359 116580   ){
116360 116581     Select *pNew;
116361 116582     Select standin;
116362         -  sqlite3 *db = pParse->db;
116363         -  pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
       116583  +  pNew = sqlite3DbMallocRawNN(pParse->db, sizeof(*pNew) );
116364 116584     if( pNew==0 ){
116365         -    assert( db->mallocFailed );
       116585  +    assert( pParse->db->mallocFailed );
116366 116586       pNew = &standin;
116367 116587     }
116368 116588     if( pEList==0 ){
116369         -    pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db,TK_ASTERISK,0));
       116589  +    pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(pParse->db,TK_ASTERISK,0));
116370 116590     }
116371 116591     pNew->pEList = pEList;
116372 116592     pNew->op = TK_SELECT;
116373 116593     pNew->selFlags = selFlags;
116374 116594     pNew->iLimit = 0;
116375 116595     pNew->iOffset = 0;
116376 116596   #if SELECTTRACE_ENABLED
116377 116597     pNew->zSelName[0] = 0;
116378 116598   #endif
116379 116599     pNew->addrOpenEphm[0] = -1;
116380 116600     pNew->addrOpenEphm[1] = -1;
116381 116601     pNew->nSelectRow = 0;
116382         -  if( pSrc==0 ) pSrc = sqlite3DbMallocZero(db, sizeof(*pSrc));
       116602  +  if( pSrc==0 ) pSrc = sqlite3DbMallocZero(pParse->db, sizeof(*pSrc));
116383 116603     pNew->pSrc = pSrc;
116384 116604     pNew->pWhere = pWhere;
116385 116605     pNew->pGroupBy = pGroupBy;
116386 116606     pNew->pHaving = pHaving;
116387 116607     pNew->pOrderBy = pOrderBy;
116388 116608     pNew->pPrior = 0;
116389 116609     pNew->pNext = 0;
116390 116610     pNew->pLimit = pLimit;
116391 116611     pNew->pOffset = pOffset;
116392 116612     pNew->pWith = 0;
116393         -  assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || db->mallocFailed!=0 );
116394         -  if( db->mallocFailed ) {
116395         -    clearSelect(db, pNew, pNew!=&standin);
       116613  +  assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || pParse->db->mallocFailed!=0 );
       116614  +  if( pParse->db->mallocFailed ) {
       116615  +    clearSelect(pParse->db, pNew, pNew!=&standin);
116396 116616       pNew = 0;
116397 116617     }else{
116398 116618       assert( pNew->pSrc!=0 || pParse->nErr>0 );
116399 116619     }
116400 116620     assert( pNew!=&standin );
116401 116621     return pNew;
116402 116622   }
................................................................................
117298 117518   /*
117299 117519   ** Deallocate a KeyInfo object
117300 117520   */
117301 117521   SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo *p){
117302 117522     if( p ){
117303 117523       assert( p->nRef>0 );
117304 117524       p->nRef--;
117305         -    if( p->nRef==0 ) sqlite3DbFree(p->db, p);
       117525  +    if( p->nRef==0 ) sqlite3DbFreeNN(p->db, p);
117306 117526     }
117307 117527   }
117308 117528   
117309 117529   /*
117310 117530   ** Make a new pointer to a KeyInfo object
117311 117531   */
117312 117532   SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoRef(KeyInfo *p){
................................................................................
117773 117993   ){
117774 117994   #ifndef SQLITE_OMIT_DECLTYPE
117775 117995     Vdbe *v = pParse->pVdbe;
117776 117996     int i;
117777 117997     NameContext sNC;
117778 117998     sNC.pSrcList = pTabList;
117779 117999     sNC.pParse = pParse;
       118000  +  sNC.pNext = 0;
117780 118001     for(i=0; i<pEList->nExpr; i++){
117781 118002       Expr *p = pEList->a[i].pExpr;
117782 118003       const char *zType;
117783 118004   #ifdef SQLITE_ENABLE_COLUMN_METADATA
117784 118005       const char *zOrigDb = 0;
117785 118006       const char *zOrigTab = 0;
117786 118007       const char *zOrigCol = 0;
................................................................................
117796 118017   #else
117797 118018       zType = columnType(&sNC, p, 0, 0, 0, 0);
117798 118019   #endif
117799 118020       sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
117800 118021     }
117801 118022   #endif /* !defined(SQLITE_OMIT_DECLTYPE) */
117802 118023   }
       118024  +
       118025  +/*
       118026  +** Return the Table objecct in the SrcList that has cursor iCursor.
       118027  +** Or return NULL if no such Table object exists in the SrcList.
       118028  +*/
       118029  +static Table *tableWithCursor(SrcList *pList, int iCursor){
       118030  +  int j;
       118031  +  for(j=0; j<pList->nSrc; j++){
       118032  +    if( pList->a[j].iCursor==iCursor ) return pList->a[j].pTab;
       118033  +  }
       118034  +  return 0;
       118035  +}
       118036  +
117803 118037   
117804 118038   /*
117805 118039   ** Generate code that will tell the VDBE the names of columns
117806 118040   ** in the result set.  This information is used to provide the
117807 118041   ** azCol[] values in the callback.
117808 118042   */
117809 118043   static void generateColumnNames(
117810 118044     Parse *pParse,      /* Parser context */
117811 118045     SrcList *pTabList,  /* List of tables */
117812 118046     ExprList *pEList    /* Expressions defining the result set */
117813 118047   ){
117814 118048     Vdbe *v = pParse->pVdbe;
117815         -  int i, j;
       118049  +  int i;
       118050  +  Table *pTab;
117816 118051     sqlite3 *db = pParse->db;
117817 118052     int fullNames, shortNames;
117818 118053   
117819 118054   #ifndef SQLITE_OMIT_EXPLAIN
117820 118055     /* If this is an EXPLAIN, skip this step */
117821 118056     if( pParse->explain ){
117822 118057       return;
................................................................................
117833 118068     for(i=0; i<pEList->nExpr; i++){
117834 118069       Expr *p;
117835 118070       p = pEList->a[i].pExpr;
117836 118071       if( NEVER(p==0) ) continue;
117837 118072       if( pEList->a[i].zName ){
117838 118073         char *zName = pEList->a[i].zName;
117839 118074         sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
117840         -    }else if( p->op==TK_COLUMN || p->op==TK_AGG_COLUMN ){
117841         -      Table *pTab;
       118075  +    }else if( (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN)
       118076  +           && (pTab = tableWithCursor(pTabList, p->iTable))!=0
       118077  +    ){
117842 118078         char *zCol;
117843 118079         int iCol = p->iColumn;
117844         -      for(j=0; ALWAYS(j<pTabList->nSrc); j++){
117845         -        if( pTabList->a[j].iCursor==p->iTable ) break;
117846         -      }
117847         -      assert( j<pTabList->nSrc );
117848         -      pTab = pTabList->a[j].pTab;
117849 118080         if( iCol<0 ) iCol = pTab->iPKey;
117850 118081         assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
117851 118082         if( iCol<0 ){
117852 118083           zCol = "rowid";
117853 118084         }else{
117854 118085           zCol = pTab->aCol[iCol].zName;
117855 118086         }
................................................................................
117923 118154       }else{
117924 118155         Expr *pColExpr = p;  /* The expression that is the result column name */
117925 118156         Table *pTab;         /* Table associated with this expression */
117926 118157         while( pColExpr->op==TK_DOT ){
117927 118158           pColExpr = pColExpr->pRight;
117928 118159           assert( pColExpr!=0 );
117929 118160         }
117930         -      if( pColExpr->op==TK_COLUMN && ALWAYS(pColExpr->pTab!=0) ){
       118161  +      if( pColExpr->op==TK_COLUMN && pColExpr->pTab!=0 ){
117931 118162           /* For columns use the column name name */
117932 118163           int iCol = pColExpr->iColumn;
117933 118164           pTab = pColExpr->pTab;
117934 118165           if( iCol<0 ) iCol = pTab->iPKey;
117935 118166           zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
117936 118167         }else if( pColExpr->op==TK_ID ){
117937 118168           assert( !ExprHasProperty(pColExpr, EP_IntValue) );
................................................................................
119143 119374           if( pItem->u.x.iOrderByCol==i ) break;
119144 119375         }
119145 119376         if( j==nOrderBy ){
119146 119377           Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
119147 119378           if( pNew==0 ) return SQLITE_NOMEM_BKPT;
119148 119379           pNew->flags |= EP_IntValue;
119149 119380           pNew->u.iValue = i;
119150         -        pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
       119381  +        p->pOrderBy = pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
119151 119382           if( pOrderBy ) pOrderBy->a[nOrderBy++].u.x.iOrderByCol = (u16)i;
119152 119383         }
119153 119384       }
119154 119385     }
119155 119386   
119156 119387     /* Compute the comparison permutation and keyinfo that is used with
119157 119388     ** the permutation used to determine if the next
................................................................................
119377 119608     **** subqueries ****/
119378 119609     explainComposite(pParse, p->op, iSub1, iSub2, 0);
119379 119610     return pParse->nErr!=0;
119380 119611   }
119381 119612   #endif
119382 119613   
119383 119614   #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
       119615  +
       119616  +/* An instance of the SubstContext object describes an substitution edit
       119617  +** to be performed on a parse tree.
       119618  +**
       119619  +** All references to columns in table iTable are to be replaced by corresponding
       119620  +** expressions in pEList.
       119621  +*/
       119622  +typedef struct SubstContext {
       119623  +  Parse *pParse;            /* The parsing context */
       119624  +  int iTable;               /* Replace references to this table */
       119625  +  int iNewTable;            /* New table number */
       119626  +  int isLeftJoin;           /* Add TK_IF_NULL_ROW opcodes on each replacement */
       119627  +  ExprList *pEList;         /* Replacement expressions */
       119628  +} SubstContext;
       119629  +
119384 119630   /* Forward Declarations */
119385         -static void substExprList(Parse*, ExprList*, int, ExprList*);
119386         -static void substSelect(Parse*, Select *, int, ExprList*, int);
       119631  +static void substExprList(SubstContext*, ExprList*);
       119632  +static void substSelect(SubstContext*, Select*, int);
119387 119633   
119388 119634   /*
119389 119635   ** Scan through the expression pExpr.  Replace every reference to
119390 119636   ** a column in table number iTable with a copy of the iColumn-th
119391 119637   ** entry in pEList.  (But leave references to the ROWID column 
119392 119638   ** unchanged.)
119393 119639   **
119394 119640   ** This routine is part of the flattening procedure.  A subquery
119395 119641   ** whose result set is defined by pEList appears as entry in the
119396 119642   ** FROM clause of a SELECT such that the VDBE cursor assigned to that
119397         -** FORM clause entry is iTable.  This routine make the necessary 
       119643  +** FORM clause entry is iTable.  This routine makes the necessary 
119398 119644   ** changes to pExpr so that it refers directly to the source table
119399 119645   ** of the subquery rather the result set of the subquery.
119400 119646   */
119401 119647   static Expr *substExpr(
119402         -  Parse *pParse,      /* Report errors here */
119403         -  Expr *pExpr,        /* Expr in which substitution occurs */
119404         -  int iTable,         /* Table to be substituted */
119405         -  ExprList *pEList    /* Substitute expressions */
       119648  +  SubstContext *pSubst,  /* Description of the substitution */
       119649  +  Expr *pExpr            /* Expr in which substitution occurs */
119406 119650   ){
119407         -  sqlite3 *db = pParse->db;
119408 119651     if( pExpr==0 ) return 0;
119409         -  if( pExpr->op==TK_COLUMN && pExpr->iTable==iTable ){
       119652  +  if( ExprHasProperty(pExpr, EP_FromJoin) && pExpr->iRightJoinTable==pSubst->iTable ){
       119653  +    pExpr->iRightJoinTable = pSubst->iNewTable;
       119654  +  }
       119655  +  if( pExpr->op==TK_COLUMN && pExpr->iTable==pSubst->iTable ){
119410 119656       if( pExpr->iColumn<0 ){
119411 119657         pExpr->op = TK_NULL;
119412 119658       }else{
119413 119659         Expr *pNew;
119414         -      Expr *pCopy = pEList->a[pExpr->iColumn].pExpr;
119415         -      assert( pEList!=0 && pExpr->iColumn<pEList->nExpr );
       119660  +      Expr *pCopy = pSubst->pEList->a[pExpr->iColumn].pExpr;
       119661  +      Expr ifNullRow;
       119662  +      assert( pSubst->pEList!=0 && pExpr->iColumn<pSubst->pEList->nExpr );
119416 119663         assert( pExpr->pLeft==0 && pExpr->pRight==0 );
119417 119664         if( sqlite3ExprIsVector(pCopy) ){
119418         -        sqlite3VectorErrorMsg(pParse, pCopy);
       119665  +        sqlite3VectorErrorMsg(pSubst->pParse, pCopy);
119419 119666         }else{
       119667  +        sqlite3 *db = pSubst->pParse->db;
       119668  +        if( pSubst->isLeftJoin && pCopy->op!=TK_COLUMN ){
       119669  +          memset(&ifNullRow, 0, sizeof(ifNullRow));
       119670  +          ifNullRow.op = TK_IF_NULL_ROW;
       119671  +          ifNullRow.pLeft = pCopy;
       119672  +          ifNullRow.iTable = pSubst->iNewTable;
       119673  +          pCopy = &ifNullRow;
       119674  +        }
119420 119675           pNew = sqlite3ExprDup(db, pCopy, 0);
119421 119676           if( pNew && (pExpr->flags & EP_FromJoin) ){
119422 119677             pNew->iRightJoinTable = pExpr->iRightJoinTable;
119423 119678             pNew->flags |= EP_FromJoin;
119424 119679           }
119425 119680           sqlite3ExprDelete(db, pExpr);
119426 119681           pExpr = pNew;
119427 119682         }
119428 119683       }
119429 119684     }else{
119430         -    pExpr->pLeft = substExpr(pParse, pExpr->pLeft, iTable, pEList);
119431         -    pExpr->pRight = substExpr(pParse, pExpr->pRight, iTable, pEList);
       119685  +    pExpr->pLeft = substExpr(pSubst, pExpr->pLeft);
       119686  +    pExpr->pRight = substExpr(pSubst, pExpr->pRight);
119432 119687       if( ExprHasProperty(pExpr, EP_xIsSelect) ){
119433         -      substSelect(pParse, pExpr->x.pSelect, iTable, pEList, 1);
       119688  +      substSelect(pSubst, pExpr->x.pSelect, 1);
119434 119689       }else{
119435         -      substExprList(pParse, pExpr->x.pList, iTable, pEList);
       119690  +      substExprList(pSubst, pExpr->x.pList);
119436 119691       }
119437 119692     }
119438 119693     return pExpr;
119439 119694   }
119440 119695   static void substExprList(
119441         -  Parse *pParse,       /* Report errors here */
119442         -  ExprList *pList,     /* List to scan and in which to make substitutes */
119443         -  int iTable,          /* Table to be substituted */
119444         -  ExprList *pEList     /* Substitute values */
       119696  +  SubstContext *pSubst, /* Description of the substitution */
       119697  +  ExprList *pList       /* List to scan and in which to make substitutes */
119445 119698   ){
119446 119699     int i;
119447 119700     if( pList==0 ) return;
119448 119701     for(i=0; i<pList->nExpr; i++){
119449         -    pList->a[i].pExpr = substExpr(pParse, pList->a[i].pExpr, iTable, pEList);
       119702  +    pList->a[i].pExpr = substExpr(pSubst, pList->a[i].pExpr);
119450 119703     }
119451 119704   }
119452 119705   static void substSelect(
119453         -  Parse *pParse,       /* Report errors here */
119454         -  Select *p,           /* SELECT statement in which to make substitutions */
119455         -  int iTable,          /* Table to be replaced */
119456         -  ExprList *pEList,    /* Substitute values */
119457         -  int doPrior          /* Do substitutes on p->pPrior too */
       119706  +  SubstContext *pSubst, /* Description of the substitution */
       119707  +  Select *p,            /* SELECT statement in which to make substitutions */
       119708  +  int doPrior           /* Do substitutes on p->pPrior too */
119458 119709   ){
119459 119710     SrcList *pSrc;
119460 119711     struct SrcList_item *pItem;
119461 119712     int i;
119462 119713     if( !p ) return;
119463 119714     do{
119464         -    substExprList(pParse, p->pEList, iTable, pEList);
119465         -    substExprList(pParse, p->pGroupBy, iTable, pEList);
119466         -    substExprList(pParse, p->pOrderBy, iTable, pEList);
119467         -    p->pHaving = substExpr(pParse, p->pHaving, iTable, pEList);
119468         -    p->pWhere = substExpr(pParse, p->pWhere, iTable, pEList);
       119715  +    substExprList(pSubst, p->pEList);
       119716  +    substExprList(pSubst, p->pGroupBy);
       119717  +    substExprList(pSubst, p->pOrderBy);
       119718  +    p->pHaving = substExpr(pSubst, p->pHaving);
       119719  +    p->pWhere = substExpr(pSubst, p->pWhere);
119469 119720       pSrc = p->pSrc;
119470 119721       assert( pSrc!=0 );
119471 119722       for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
119472         -      substSelect(pParse, pItem->pSelect, iTable, pEList, 1);
       119723  +      substSelect(pSubst, pItem->pSelect, 1);
119473 119724         if( pItem->fg.isTabFunc ){
119474         -        substExprList(pParse, pItem->u1.pFuncArg, iTable, pEList);
       119725  +        substExprList(pSubst, pItem->u1.pFuncArg);
119475 119726         }
119476 119727       }
119477 119728     }while( doPrior && (p = p->pPrior)!=0 );
119478 119729   }
119479 119730   #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
119480 119731   
119481 119732   #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
................................................................................
119510 119761   **   (1)  The subquery and the outer query do not both use aggregates.
119511 119762   **
119512 119763   **   (2)  The subquery is not an aggregate or (2a) the outer query is not a join
119513 119764   **        and (2b) the outer query does not use subqueries other than the one
119514 119765   **        FROM-clause subquery that is a candidate for flattening.  (2b is
119515 119766   **        due to ticket [2f7170d73bf9abf80] from 2015-02-09.)
119516 119767   **
119517         -**   (3)  The subquery is not the right operand of a left outer join
119518         -**        (Originally ticket #306.  Strengthened by ticket #3300)
       119768  +**   (3)  The subquery is not the right operand of a LEFT JOIN
       119769  +**        or the subquery is not itself a join.
119519 119770   **
119520 119771   **   (4)  The subquery is not DISTINCT.
119521 119772   **
119522 119773   **  (**)  At one point restrictions (4) and (5) defined a subset of DISTINCT
119523 119774   **        sub-queries that were excluded from this optimization. Restriction 
119524 119775   **        (4) has since been expanded to exclude all DISTINCT subqueries.
119525 119776   **
119526 119777   **   (6)  The subquery does not use aggregates or the outer query is not
119527 119778   **        DISTINCT.
119528 119779   **
119529 119780   **   (7)  The subquery has a FROM clause.  TODO:  For subqueries without
119530         -**        A FROM clause, consider adding a FROM close with the special
       119781  +**        A FROM clause, consider adding a FROM clause with the special
119531 119782   **        table sqlite_once that consists of a single row containing a
119532 119783   **        single NULL.
119533 119784   **
119534 119785   **   (8)  The subquery does not use LIMIT or the outer query is not a join.
119535 119786   **
119536 119787   **   (9)  The subquery does not use LIMIT or the outer query does not use
119537 119788   **        aggregates.
................................................................................
119629 119880     Select *pParent;    /* Current UNION ALL term of the other query */
119630 119881     Select *pSub;       /* The inner query or "subquery" */
119631 119882     Select *pSub1;      /* Pointer to the rightmost select in sub-query */
119632 119883     SrcList *pSrc;      /* The FROM clause of the outer query */
119633 119884     SrcList *pSubSrc;   /* The FROM clause of the subquery */
119634 119885     ExprList *pList;    /* The result set of the outer query */
119635 119886     int iParent;        /* VDBE cursor number of the pSub result set temp table */
       119887  +  int iNewParent = -1;/* Replacement table for iParent */
       119888  +  int isLeftJoin = 0; /* True if pSub is the right side of a LEFT JOIN */    
119636 119889     int i;              /* Loop counter */
119637 119890     Expr *pWhere;                    /* The WHERE clause */
119638 119891     struct SrcList_item *pSubitem;   /* The subquery */
119639 119892     sqlite3 *db = pParse->db;
119640 119893   
119641 119894     /* Check to see if flattening is permitted.  Return 0 if not.
119642 119895     */
................................................................................
119655 119908       if( (p->pWhere && ExprHasProperty(p->pWhere,EP_Subquery))
119656 119909        || (sqlite3ExprListFlags(p->pEList) & EP_Subquery)!=0
119657 119910        || (sqlite3ExprListFlags(p->pOrderBy) & EP_Subquery)!=0
119658 119911       ){
119659 119912         return 0;                                          /* Restriction (2b)  */
119660 119913       }
119661 119914     }
119662         -    
       119915  +
119663 119916     pSubSrc = pSub->pSrc;
119664 119917     assert( pSubSrc );
119665 119918     /* Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants,
119666 119919     ** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET
119667 119920     ** because they could be computed at compile-time.  But when LIMIT and OFFSET
119668 119921     ** became arbitrary expressions, we were forced to add restrictions (13)
119669 119922     ** and (14). */
................................................................................
119693 119946     if( pSub->selFlags & (SF_Recursive|SF_MinMaxAgg) ){
119694 119947       return 0; /* Restrictions (22) and (24) */
119695 119948     }
119696 119949     if( (p->selFlags & SF_Recursive) && pSub->pPrior ){
119697 119950       return 0; /* Restriction (23) */
119698 119951     }
119699 119952   
119700         -  /* OBSOLETE COMMENT 1:
119701         -  ** Restriction 3:  If the subquery is a join, make sure the subquery is 
119702         -  ** not used as the right operand of an outer join.  Examples of why this
119703         -  ** is not allowed:
       119953  +  /*
       119954  +  ** If the subquery is the right operand of a LEFT JOIN, then the
       119955  +  ** subquery may not be a join itself.  Example of why this is not allowed:
119704 119956     **
119705 119957     **         t1 LEFT OUTER JOIN (t2 JOIN t3)
119706 119958     **
119707 119959     ** If we flatten the above, we would get
119708 119960     **
119709 119961     **         (t1 LEFT OUTER JOIN t2) JOIN t3
119710 119962     **
119711 119963     ** which is not at all the same thing.
119712 119964     **
119713         -  ** OBSOLETE COMMENT 2:
119714         -  ** Restriction 12:  If the subquery is the right operand of a left outer
119715         -  ** join, make sure the subquery has no WHERE clause.
119716         -  ** An examples of why this is not allowed:
119717         -  **
119718         -  **         t1 LEFT OUTER JOIN (SELECT * FROM t2 WHERE t2.x>0)
119719         -  **
119720         -  ** If we flatten the above, we would get
119721         -  **
119722         -  **         (t1 LEFT OUTER JOIN t2) WHERE t2.x>0
119723         -  **
119724         -  ** But the t2.x>0 test will always fail on a NULL row of t2, which
119725         -  ** effectively converts the OUTER JOIN into an INNER JOIN.
119726         -  **
119727         -  ** THIS OVERRIDES OBSOLETE COMMENTS 1 AND 2 ABOVE:
119728         -  ** Ticket #3300 shows that flattening the right term of a LEFT JOIN
119729         -  ** is fraught with danger.  Best to avoid the whole thing.  If the
119730         -  ** subquery is the right term of a LEFT JOIN, then do not flatten.
       119965  +  ** See also tickets #306, #350, and #3300.
119731 119966     */
119732 119967     if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
119733         -    return 0;
       119968  +    isLeftJoin = 1;
       119969  +    if( pSubSrc->nSrc>1 ){
       119970  +      return 0; /* Restriction (3) */
       119971  +    }
119734 119972     }
119735 119973   
119736 119974     /* Restriction 17: If the sub-query is a compound SELECT, then it must
119737 119975     ** use only the UNION ALL operator. And none of the simple select queries
119738 119976     ** that make up the compound SELECT are allowed to be aggregate or distinct
119739 119977     ** queries.
119740 119978     */
................................................................................
119935 120173       /* Transfer the FROM clause terms from the subquery into the
119936 120174       ** outer query.
119937 120175       */
119938 120176       for(i=0; i<nSubSrc; i++){
119939 120177         sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
119940 120178         assert( pSrc->a[i+iFrom].fg.isTabFunc==0 );
119941 120179         pSrc->a[i+iFrom] = pSubSrc->a[i];
       120180  +      iNewParent = pSubSrc->a[i].iCursor;
119942 120181         memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
119943 120182       }
119944 120183       pSrc->a[iFrom].fg.jointype = jointype;
119945 120184     
119946 120185       /* Now begin substituting subquery result set expressions for 
119947 120186       ** references to the iParent in the outer query.
119948 120187       ** 
................................................................................
119980 120219         }
119981 120220         assert( pParent->pOrderBy==0 );
119982 120221         assert( pSub->pPrior==0 );
119983 120222         pParent->pOrderBy = pOrderBy;
119984 120223         pSub->pOrderBy = 0;
119985 120224       }
119986 120225       pWhere = sqlite3ExprDup(db, pSub->pWhere, 0);
       120226  +    if( isLeftJoin ){
       120227  +      setJoinExpr(pWhere, iNewParent);
       120228  +    }
119987 120229       if( subqueryIsAgg ){
119988 120230         assert( pParent->pHaving==0 );
119989 120231         pParent->pHaving = pParent->pWhere;
119990 120232         pParent->pWhere = pWhere;
119991 120233         pParent->pHaving = sqlite3ExprAnd(db, 
119992 120234             sqlite3ExprDup(db, pSub->pHaving, 0), pParent->pHaving
119993 120235         );
119994 120236         assert( pParent->pGroupBy==0 );
119995 120237         pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
119996 120238       }else{
119997 120239         pParent->pWhere = sqlite3ExprAnd(db, pWhere, pParent->pWhere);
119998 120240       }
119999 120241       if( db->mallocFailed==0 ){
120000         -      substSelect(pParse, pParent, iParent, pSub->pEList, 0);
       120242  +      SubstContext x;
       120243  +      x.pParse = pParse;
       120244  +      x.iTable = iParent;
       120245  +      x.iNewTable = iNewParent;
       120246  +      x.isLeftJoin = isLeftJoin;
       120247  +      x.pEList = pSub->pEList;
       120248  +      substSelect(&x, pParent, 0);
120001 120249       }
120002 120250     
120003 120251       /* The flattened query is distinct if either the inner or the
120004 120252       ** outer query is distinct. 
120005 120253       */
120006 120254       pParent->selFlags |= pSub->selFlags & SF_Distinct;
120007 120255     
................................................................................
120096 120344       nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, iCursor);
120097 120345       pWhere = pWhere->pLeft;
120098 120346     }
120099 120347     if( ExprHasProperty(pWhere,EP_FromJoin) ) return 0; /* restriction 5 */
120100 120348     if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
120101 120349       nChng++;
120102 120350       while( pSubq ){
       120351  +      SubstContext x;
120103 120352         pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
120104         -      pNew = substExpr(pParse, pNew, iCursor, pSubq->pEList);
       120353  +      x.pParse = pParse;
       120354  +      x.iTable = iCursor;
       120355  +      x.iNewTable = iCursor;
       120356  +      x.isLeftJoin = 0;
       120357  +      x.pEList = pSubq->pEList;
       120358  +      pNew = substExpr(&x, pNew);
120105 120359         pSubq->pWhere = sqlite3ExprAnd(pParse->db, pSubq->pWhere, pNew);
120106 120360         pSubq = pSubq->pPrior;
120107 120361       }
120108 120362     }
120109 120363     return nChng;
120110 120364   }
120111 120365   #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
................................................................................
121088 121342           pParse->pVdbe, OP_Explain, pParse->iSelectId, 0, 0, zEqp, P4_DYNAMIC
121089 121343       );
121090 121344     }
121091 121345   }
121092 121346   #else
121093 121347   # define explainSimpleCount(a,b,c)
121094 121348   #endif
       121349  +
       121350  +/*
       121351  +** Context object for havingToWhereExprCb().
       121352  +*/
       121353  +struct HavingToWhereCtx {
       121354  +  Expr **ppWhere;
       121355  +  ExprList *pGroupBy;
       121356  +};
       121357  +
       121358  +/*
       121359  +** sqlite3WalkExpr() callback used by havingToWhere().
       121360  +**
       121361  +** If the node passed to the callback is a TK_AND node, return 
       121362  +** WRC_Continue to tell sqlite3WalkExpr() to iterate through child nodes.
       121363  +**
       121364  +** Otherwise, return WRC_Prune. In this case, also check if the 
       121365  +** sub-expression matches the criteria for being moved to the WHERE
       121366  +** clause. If so, add it to the WHERE clause and replace the sub-expression
       121367  +** within the HAVING expression with a constant "1".
       121368  +*/
       121369  +static int havingToWhereExprCb(Walker *pWalker, Expr *pExpr){
       121370  +  if( pExpr->op!=TK_AND ){
       121371  +    struct HavingToWhereCtx *p = pWalker->u.pHavingCtx;
       121372  +    if( sqlite3ExprIsConstantOrGroupBy(pWalker->pParse, pExpr, p->pGroupBy) ){
       121373  +      sqlite3 *db = pWalker->pParse->db;
       121374  +      Expr *pNew = sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[1], 0);
       121375  +      if( pNew ){
       121376  +        Expr *pWhere = *(p->ppWhere);
       121377  +        SWAP(Expr, *pNew, *pExpr);
       121378  +        pNew = sqlite3ExprAnd(db, pWhere, pNew);
       121379  +        *(p->ppWhere) = pNew;
       121380  +      }
       121381  +    }
       121382  +    return WRC_Prune;
       121383  +  }
       121384  +  return WRC_Continue;
       121385  +}
       121386  +
       121387  +/*
       121388  +** Transfer eligible terms from the HAVING clause of a query, which is
       121389  +** processed after grouping, to the WHERE clause, which is processed before
       121390  +** grouping. For example, the query:
       121391  +**
       121392  +**   SELECT * FROM <tables> WHERE a=? GROUP BY b HAVING b=? AND c=?
       121393  +**
       121394  +** can be rewritten as:
       121395  +**
       121396  +**   SELECT * FROM <tables> WHERE a=? AND b=? GROUP BY b HAVING c=?
       121397  +**
       121398  +** A term of the HAVING expression is eligible for transfer if it consists
       121399  +** entirely of constants and expressions that are also GROUP BY terms that
       121400  +** use the "BINARY" collation sequence.
       121401  +*/
       121402  +static void havingToWhere(
       121403  +  Parse *pParse,
       121404  +  ExprList *pGroupBy,
       121405  +  Expr *pHaving, 
       121406  +  Expr **ppWhere
       121407  +){
       121408  +  struct HavingToWhereCtx sCtx;
       121409  +  Walker sWalker;
       121410  +
       121411  +  sCtx.ppWhere = ppWhere;
       121412  +  sCtx.pGroupBy = pGroupBy;
       121413  +
       121414  +  memset(&sWalker, 0, sizeof(sWalker));
       121415  +  sWalker.pParse = pParse;
       121416  +  sWalker.xExprCallback = havingToWhereExprCb;
       121417  +  sWalker.u.pHavingCtx = &sCtx;
       121418  +  sqlite3WalkExpr(&sWalker, pHaving);
       121419  +}
       121420  +
       121421  +/*
       121422  +** Check to see if the pThis entry of pTabList is a self-join of a prior view.
       121423  +** If it is, then return the SrcList_item for the prior view.  If it is not,
       121424  +** then return 0.
       121425  +*/
       121426  +static struct SrcList_item *isSelfJoinView(
       121427  +  SrcList *pTabList,           /* Search for self-joins in this FROM clause */
       121428  +  struct SrcList_item *pThis   /* Search for prior reference to this subquery */
       121429  +){
       121430  +  struct SrcList_item *pItem;
       121431  +  for(pItem = pTabList->a; pItem<pThis; pItem++){
       121432  +    if( pItem->pSelect==0 ) continue;
       121433  +    if( pItem->fg.viaCoroutine ) continue;
       121434  +    if( pItem->zName==0 ) continue;
       121435  +    if( sqlite3_stricmp(pItem->zDatabase, pThis->zDatabase)!=0 ) continue;
       121436  +    if( sqlite3_stricmp(pItem->zName, pThis->zName)!=0 ) continue;
       121437  +    if( sqlite3ExprCompare(pThis->pSelect->pWhere, pItem->pSelect->pWhere, -1) ){
       121438  +      /* The view was modified by some other optimization such as
       121439  +      ** pushDownWhereTerms() */
       121440  +      continue;
       121441  +    }
       121442  +    return pItem;
       121443  +  }
       121444  +  return 0;
       121445  +}
121095 121446   
121096 121447   /*
121097 121448   ** Generate code for the SELECT statement given in the p argument.  
121098 121449   **
121099 121450   ** The results are returned according to the SelectDest structure.
121100 121451   ** See comments in sqliteInt.h for further information.
121101 121452   **
................................................................................
121228 121579       SELECTTRACE(1,pParse,p,("end compound-select processing\n"));
121229 121580       pParse->nSelectIndent--;
121230 121581   #endif
121231 121582       return rc;
121232 121583     }
121233 121584   #endif
121234 121585   
121235         -  /* Generate code for all sub-queries in the FROM clause
       121586  +  /* For each term in the FROM clause, do two things:
       121587  +  ** (1) Authorized unreferenced tables
       121588  +  ** (2) Generate code for all sub-queries
121236 121589     */
121237         -#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
121238 121590     for(i=0; i<pTabList->nSrc; i++){
121239 121591       struct SrcList_item *pItem = &pTabList->a[i];
121240 121592       SelectDest dest;
121241         -    Select *pSub = pItem->pSelect;
       121593  +    Select *pSub;
       121594  +
       121595  +    /* Issue SQLITE_READ authorizations with a NULL column name for any tables that
       121596  +    ** are referenced but from which no values are extracted. Examples of where these
       121597  +    ** kinds of null SQLITE_READ authorizations would occur:
       121598  +    **
       121599  +    **     SELECT count(*) FROM t1;   -- SQLITE_READ t1 null
       121600  +    **     SELECT t1.* FROM t1, t2;   -- SQLITE_READ t2 null
       121601  +    */
       121602  +    if( pItem->colUsed==0 ){
       121603  +      sqlite3AuthCheck(pParse, SQLITE_READ, pItem->zName, pItem->zDatabase, 0);
       121604  +    }
       121605  +
       121606  +#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
       121607  +    /* Generate code for all sub-queries in the FROM clause
       121608  +    */
       121609  +    pSub = pItem->pSelect;
121242 121610       if( pSub==0 ) continue;
121243 121611   
121244 121612       /* Sometimes the code for a subquery will be generated more than
121245 121613       ** once, if the subquery is part of the WHERE clause in a LEFT JOIN,
121246 121614       ** for example.  In that case, do not regenerate the code to manifest
121247 121615       ** a view or the co-routine to implement a view.  The first instance
121248 121616       ** is sufficient, though the subroutine to manifest the view does need
121249 121617       ** to be invoked again. */
121250 121618       if( pItem->addrFillSub ){
121251 121619         if( pItem->fg.viaCoroutine==0 ){
       121620  +        /* The subroutine that manifests the view might be a one-time routine,
       121621  +        ** or it might need to be rerun on each iteration because it
       121622  +        ** encodes a correlated subquery. */
       121623  +        testcase( sqlite3VdbeGetOp(v, pItem->addrFillSub)->opcode==OP_Once );
121252 121624           sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub);
121253 121625         }
121254 121626         continue;
121255 121627       }
121256 121628   
121257 121629       /* Increment Parse.nHeight by the height of the largest expression
121258 121630       ** tree referred to by this, the parent select. The child select
................................................................................
121319 121691         ** the content of this subquery.  pItem->addrFillSub will point
121320 121692         ** to the address of the generated subroutine.  pItem->regReturn
121321 121693         ** is a register allocated to hold the subroutine return address
121322 121694         */
121323 121695         int topAddr;
121324 121696         int onceAddr = 0;
121325 121697         int retAddr;
       121698  +      struct SrcList_item *pPrior;
       121699  +
121326 121700         assert( pItem->addrFillSub==0 );
121327 121701         pItem->regReturn = ++pParse->nMem;
121328 121702         topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
121329 121703         pItem->addrFillSub = topAddr+1;
121330 121704         if( pItem->fg.isCorrelated==0 ){
121331 121705           /* If the subquery is not correlated and if we are not inside of
121332 121706           ** a trigger, then we only need to compute the value of the subquery
121333 121707           ** once. */
121334 121708           onceAddr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
121335 121709           VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
121336 121710         }else{
121337 121711           VdbeNoopComment((v, "materialize \"%s\"", pItem->pTab->zName));
121338 121712         }
121339         -      sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
121340         -      explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
121341         -      sqlite3Select(pParse, pSub, &dest);
       121713  +      pPrior = isSelfJoinView(pTabList, pItem);
       121714  +      if( pPrior ){
       121715  +        sqlite3VdbeAddOp2(v, OP_OpenDup, pItem->iCursor, pPrior->iCursor);
       121716  +      }else{
       121717  +        sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
       121718  +        explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
       121719  +        sqlite3Select(pParse, pSub, &dest);
       121720  +      }
121342 121721         pItem->pTab->nRowLogEst = pSub->nSelectRow;
121343 121722         if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
121344 121723         retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn);
121345 121724         VdbeComment((v, "end %s", pItem->pTab->zName));
121346 121725         sqlite3VdbeChangeP1(v, topAddr, retAddr);
121347 121726         sqlite3ClearTempRegCache(pParse);
121348 121727       }
121349 121728       if( db->mallocFailed ) goto select_end;
121350 121729       pParse->nHeight -= sqlite3SelectExprHeight(p);
       121730  +#endif
121351 121731     }
121352         -#endif
121353 121732   
121354 121733     /* Various elements of the SELECT copied into local variables for
121355 121734     ** convenience */
121356 121735     pEList = p->pEList;
121357 121736     pWhere = p->pWhere;
121358 121737     pGroupBy = p->pGroupBy;
121359 121738     pHaving = p->pHaving;
................................................................................
121553 121932       sNC.pAggInfo = &sAggInfo;
121554 121933       sAggInfo.mnReg = pParse->nMem+1;
121555 121934       sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr : 0;
121556 121935       sAggInfo.pGroupBy = pGroupBy;
121557 121936       sqlite3ExprAnalyzeAggList(&sNC, pEList);
121558 121937       sqlite3ExprAnalyzeAggList(&sNC, sSort.pOrderBy);
121559 121938       if( pHaving ){
       121939  +      if( pGroupBy ){
       121940  +        assert( pWhere==p->pWhere );
       121941  +        havingToWhere(pParse, pGroupBy, pHaving, &p->pWhere);
       121942  +        pWhere = p->pWhere;
       121943  +      }
121560 121944         sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
121561 121945       }
121562 121946       sAggInfo.nAccumulator = sAggInfo.nColumn;
121563 121947       for(i=0; i<sAggInfo.nFunc; i++){
121564 121948         assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) );
121565 121949         sNC.ncFlags |= NC_InAggFunc;
121566 121950         sqlite3ExprAnalyzeAggList(&sNC, sAggInfo.aFunc[i].pExpr->x.pList);
................................................................................
123565 123949     ** being updated.  Fill in aRegIdx[] with a register number that will hold
123566 123950     ** the key for accessing each index.
123567 123951     **
123568 123952     ** FIXME:  Be smarter about omitting indexes that use expressions.
123569 123953     */
123570 123954     for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
123571 123955       int reg;
123572         -    if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
       123956  +    if( chngKey || hasFK>1 || pIdx->pPartIdxWhere || pIdx==pPk ){
123573 123957         reg = ++pParse->nMem;
123574 123958         pParse->nMem += pIdx->nColumn;
123575 123959       }else{
123576 123960         reg = 0;
123577 123961         for(i=0; i<pIdx->nKeyCol; i++){
123578 123962           i16 iIdxCol = pIdx->aiColumn[i];
123579 123963           if( iIdxCol<0 || aXRef[iIdxCol]>=0 ){
................................................................................
123920 124304       ** pre-update hook. If the caller invokes preupdate_new(), the returned
123921 124305       ** value is copied from memory cell (regNewRowid+1+iCol), where iCol
123922 124306       ** is the column index supplied by the user.
123923 124307       */
123924 124308       assert( regNew==regNewRowid+1 );
123925 124309   #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
123926 124310       sqlite3VdbeAddOp3(v, OP_Delete, iDataCur,
123927         -        OPFLAG_ISUPDATE | ((hasFK || chngKey) ? 0 : OPFLAG_ISNOOP),
       124311  +        OPFLAG_ISUPDATE | ((hasFK>1 || chngKey) ? 0 : OPFLAG_ISNOOP),
123928 124312           regNewRowid
123929 124313       );
123930 124314       if( eOnePass==ONEPASS_MULTI ){
123931 124315         assert( hasFK==0 && chngKey==0 );
123932 124316         sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION);
123933 124317       }
123934 124318       if( !pParse->nested ){
123935 124319         sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
123936 124320       }
123937 124321   #else
123938         -    if( hasFK || chngKey ){
       124322  +    if( hasFK>1 || chngKey ){
123939 124323         sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
123940 124324       }
123941 124325   #endif
123942 124326       if( bReplace || chngKey ){
123943 124327         sqlite3VdbeJumpHere(v, addr1);
123944 124328       }
123945 124329   
................................................................................
125574 125958     unsigned char *z;
125575 125959   
125576 125960   
125577 125961     /* Check to see the left operand is a column in a virtual table */
125578 125962     if( NEVER(pExpr==0) ) return pDef;
125579 125963     if( pExpr->op!=TK_COLUMN ) return pDef;
125580 125964     pTab = pExpr->pTab;
125581         -  if( NEVER(pTab==0) ) return pDef;
       125965  +  if( pTab==0 ) return pDef;
125582 125966     if( !IsVirtual(pTab) ) return pDef;
125583 125967     pVtab = sqlite3GetVTable(db, pTab)->pVtab;
125584 125968     assert( pVtab!=0 );
125585 125969     assert( pVtab->pModule!=0 );
125586 125970     pMod = (sqlite3_module *)pVtab->pModule;
125587 125971     if( pMod->xFindFunction==0 ) return pDef;
125588 125972    
................................................................................
125909 126293     LogEst rRun;          /* Cost of running each loop */
125910 126294     LogEst nOut;          /* Estimated number of output rows */
125911 126295     union {
125912 126296       struct {               /* Information for internal btree tables */
125913 126297         u16 nEq;               /* Number of equality constraints */
125914 126298         u16 nBtm;              /* Size of BTM vector */
125915 126299         u16 nTop;              /* Size of TOP vector */
       126300  +      u16 nIdxCol;           /* Index column used for ORDER BY */
125916 126301         Index *pIndex;         /* Index used, or NULL */
125917 126302       } btree;
125918 126303       struct {               /* Information for virtual tables */
125919 126304         int idxNum;            /* Index number */
125920 126305         u8 needFree;           /* True if sqlite3_free(idxStr) is needed */
125921 126306         i8 isOrdered;          /* True if satisfies ORDER BY */
125922 126307         u16 omitMask;          /* Terms that may be omitted */
................................................................................
126202 126587   ** planner.
126203 126588   */
126204 126589   struct WhereInfo {
126205 126590     Parse *pParse;            /* Parsing and code generating context */
126206 126591     SrcList *pTabList;        /* List of tables in the join */
126207 126592     ExprList *pOrderBy;       /* The ORDER BY clause or NULL */
126208 126593     ExprList *pResultSet;     /* Result set of the query */
       126594  +  Expr *pWhere;             /* The complete WHERE clause */
126209 126595     LogEst iLimit;            /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
126210 126596     int aiCurOnePass[2];      /* OP_OpenWrite cursors for the ONEPASS opt */
126211 126597     int iContinue;            /* Jump here to continue with next record */
126212 126598     int iBreak;               /* Jump here to break out of the loop */
126213 126599     int savedNQueryLoop;      /* pParse->nQueryLoop outside the WHERE loop */
126214 126600     u16 wctrlFlags;           /* Flags originally passed to sqlite3WhereBegin() */
126215 126601     u8 nLevel;                /* Number of nested loop */
................................................................................
127361 127747         }
127362 127748       }
127363 127749     }else{
127364 127750       assert( nReg==1 );
127365 127751       sqlite3ExprCode(pParse, p, iReg);
127366 127752     }
127367 127753   }
       127754  +
       127755  +/* An instance of the IdxExprTrans object carries information about a
       127756  +** mapping from an expression on table columns into a column in an index
       127757  +** down through the Walker.
       127758  +*/
       127759  +typedef struct IdxExprTrans {
       127760  +  Expr *pIdxExpr;    /* The index expression */
       127761  +  int iTabCur;       /* The cursor of the corresponding table */
       127762  +  int iIdxCur;       /* The cursor for the index */
       127763  +  int iIdxCol;       /* The column for the index */
       127764  +} IdxExprTrans;
       127765  +
       127766  +/* The walker node callback used to transform matching expressions into
       127767  +** a reference to an index column for an index on an expression.
       127768  +**
       127769  +** If pExpr matches, then transform it into a reference to the index column
       127770  +** that contains the value of pExpr.
       127771  +*/
       127772  +static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
       127773  +  IdxExprTrans *pX = p->u.pIdxTrans;
       127774  +  if( sqlite3ExprCompare(pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
       127775  +    pExpr->op = TK_COLUMN;
       127776  +    pExpr->iTable = pX->iIdxCur;
       127777  +    pExpr->iColumn = pX->iIdxCol;
       127778  +    pExpr->pTab = 0;
       127779  +    return WRC_Prune;
       127780  +  }else{
       127781  +    return WRC_Continue;
       127782  +  }
       127783  +}
       127784  +
       127785  +/*
       127786  +** For an indexes on expression X, locate every instance of expression X in pExpr
       127787  +** and change that subexpression into a reference to the appropriate column of
       127788  +** the index.
       127789  +*/
       127790  +static void whereIndexExprTrans(
       127791  +  Index *pIdx,      /* The Index */
       127792  +  int iTabCur,      /* Cursor of the table that is being indexed */
       127793  +  int iIdxCur,      /* Cursor of the index itself */
       127794  +  WhereInfo *pWInfo /* Transform expressions in this WHERE clause */
       127795  +){
       127796  +  int iIdxCol;               /* Column number of the index */
       127797  +  ExprList *aColExpr;        /* Expressions that are indexed */
       127798  +  Walker w;
       127799  +  IdxExprTrans x;
       127800  +  aColExpr = pIdx->aColExpr;
       127801  +  if( aColExpr==0 ) return;  /* Not an index on expressions */
       127802  +  memset(&w, 0, sizeof(w));
       127803  +  w.xExprCallback = whereIndexExprTransNode;
       127804  +  w.u.pIdxTrans = &x;
       127805  +  x.iTabCur = iTabCur;
       127806  +  x.iIdxCur = iIdxCur;
       127807  +  for(iIdxCol=0; iIdxCol<aColExpr->nExpr; iIdxCol++){
       127808  +    if( pIdx->aiColumn[iIdxCol]!=XN_EXPR ) continue;
       127809  +    assert( aColExpr->a[iIdxCol].pExpr!=0 );
       127810  +    x.iIdxCol = iIdxCol;
       127811  +    x.pIdxExpr = aColExpr->a[iIdxCol].pExpr;
       127812  +    sqlite3WalkExpr(&w, pWInfo->pWhere);
       127813  +    sqlite3WalkExprList(&w, pWInfo->pOrderBy);
       127814  +    sqlite3WalkExprList(&w, pWInfo->pResultSet);
       127815  +  }
       127816  +}
127368 127817   
127369 127818   /*
127370 127819   ** Generate code for the start of the iLevel-th loop in the WHERE clause
127371 127820   ** implementation described by pWInfo.
127372 127821   */
127373 127822   SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
127374 127823     WhereInfo *pWInfo,   /* Complete information about the WHERE clause */
................................................................................
127389 127838     Vdbe *v;                        /* The prepared stmt under constructions */
127390 127839     struct SrcList_item *pTabItem;  /* FROM clause term being coded */
127391 127840     int addrBrk;                    /* Jump here to break out of the loop */
127392 127841     int addrHalt;                   /* addrBrk for the outermost loop */
127393 127842     int addrCont;                   /* Jump here to continue with next cycle */
127394 127843     int iRowidReg = 0;        /* Rowid is stored in this register, if not zero */
127395 127844     int iReleaseReg = 0;      /* Temp register to free before returning */
       127845  +  Index *pIdx = 0;          /* Index used by loop (if any) */
       127846  +  int loopAgain;            /* True if constraint generator loop should repeat */
127396 127847   
127397 127848     pParse = pWInfo->pParse;
127398 127849     v = pParse->pVdbe;
127399 127850     pWC = &pWInfo->sWC;
127400 127851     db = pParse->db;
127401 127852     pLevel = &pWInfo->a[iLevel];
127402 127853     pLoop = pLevel->pWLoop;
................................................................................
127714 128165       int regBase;                 /* Base register holding constraint values */
127715 128166       WhereTerm *pRangeStart = 0;  /* Inequality constraint at range start */
127716 128167       WhereTerm *pRangeEnd = 0;    /* Inequality constraint at range end */
127717 128168       int startEq;                 /* True if range start uses ==, >= or <= */
127718 128169       int endEq;                   /* True if range end uses ==, >= or <= */
127719 128170       int start_constraints;       /* Start of range is constrained */
127720 128171       int nConstraint;             /* Number of constraint terms */
127721         -    Index *pIdx;                 /* The index we will be using */
127722 128172       int iIdxCur;                 /* The VDBE cursor for the index */
127723 128173       int nExtraReg = 0;           /* Number of extra registers needed */
127724 128174       int op;                      /* Instruction opcode */
127725 128175       char *zStartAff;             /* Affinity for start of range constraint */
127726 128176       char *zEndAff = 0;           /* Affinity for end of range constraint */
127727 128177       u8 bSeekPastNull = 0;        /* True to seek past initial nulls */
127728 128178       u8 bStopAtNull = 0;          /* Add condition to terminate at NULLs */
................................................................................
127942 128392         for(j=0; j<pPk->nKeyCol; j++){
127943 128393           k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
127944 128394           sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
127945 128395         }
127946 128396         sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont,
127947 128397                              iRowidReg, pPk->nKeyCol); VdbeCoverage(v);
127948 128398       }
       128399  +
       128400  +    /* If pIdx is an index on one or more expressions, then look through
       128401  +    ** all the expressions in pWInfo and try to transform matching expressions
       128402  +    ** into reference to index columns.
       128403  +    */
       128404  +    whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
       128405  +
127949 128406   
127950 128407       /* Record the instruction used to terminate the loop. */
127951 128408       if( pLoop->wsFlags & WHERE_ONEROW ){
127952 128409         pLevel->op = OP_Noop;
127953 128410       }else if( bRev ){
127954 128411         pLevel->op = OP_Prev;
127955 128412       }else{
................................................................................
127958 128415       pLevel->p1 = iIdxCur;
127959 128416       pLevel->p3 = (pLoop->wsFlags&WHERE_UNQ_WANTED)!=0 ? 1:0;
127960 128417       if( (pLoop->wsFlags & WHERE_CONSTRAINT)==0 ){
127961 128418         pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
127962 128419       }else{
127963 128420         assert( pLevel->p5==0 );
127964 128421       }
       128422  +    if( omitTable ) pIdx = 0;
127965 128423     }else
127966 128424   
127967 128425   #ifndef SQLITE_OMIT_OR_OPTIMIZATION
127968 128426     if( pLoop->wsFlags & WHERE_MULTI_OR ){
127969 128427       /* Case 5:  Two or more separately indexed terms connected by OR
127970 128428       **
127971 128429       ** Example:
................................................................................
128275 128733   
128276 128734   #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
128277 128735     pLevel->addrVisit = sqlite3VdbeCurrentAddr(v);
128278 128736   #endif
128279 128737   
128280 128738     /* Insert code to test every subexpression that can be completely
128281 128739     ** computed using the current set of tables.
128282         -  */
128283         -  for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
128284         -    Expr *pE;
128285         -    int skipLikeAddr = 0;
128286         -    testcase( pTerm->wtFlags & TERM_VIRTUAL );
128287         -    testcase( pTerm->wtFlags & TERM_CODED );
128288         -    if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
128289         -    if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
128290         -      testcase( pWInfo->untestedTerms==0
128291         -               && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 );
128292         -      pWInfo->untestedTerms = 1;
128293         -      continue;
128294         -    }
128295         -    pE = pTerm->pExpr;
128296         -    assert( pE!=0 );
128297         -    if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
128298         -      continue;
128299         -    }
128300         -    if( pTerm->wtFlags & TERM_LIKECOND ){
128301         -      /* If the TERM_LIKECOND flag is set, that means that the range search
128302         -      ** is sufficient to guarantee that the LIKE operator is true, so we
128303         -      ** can skip the call to the like(A,B) function.  But this only works
128304         -      ** for strings.  So do not skip the call to the function on the pass
128305         -      ** that compares BLOBs. */
       128740  +  **
       128741  +  ** This loop may run either once (pIdx==0) or twice (pIdx!=0). If
       128742  +  ** it is run twice, then the first iteration codes those sub-expressions
       128743  +  ** that can be computed using columns from pIdx only (without seeking
       128744  +  ** the main table cursor). 
       128745  +  */
       128746  +  do{
       128747  +    loopAgain = 0;
       128748  +    for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
       128749  +      Expr *pE;
       128750  +      int skipLikeAddr = 0;
       128751  +      testcase( pTerm->wtFlags & TERM_VIRTUAL );
       128752  +      testcase( pTerm->wtFlags & TERM_CODED );
       128753  +      if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
       128754  +      if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
       128755  +        testcase( pWInfo->untestedTerms==0
       128756  +            && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 );
       128757  +        pWInfo->untestedTerms = 1;
       128758  +        continue;
       128759  +      }
       128760  +      pE = pTerm->pExpr;
       128761  +      assert( pE!=0 );
       128762  +      if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
       128763  +        continue;
       128764  +      }
       128765  +      if( pIdx && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
       128766  +        loopAgain = 1;
       128767  +        continue;
       128768  +      }
       128769  +      if( pTerm->wtFlags & TERM_LIKECOND ){
       128770  +        /* If the TERM_LIKECOND flag is set, that means that the range search
       128771  +        ** is sufficient to guarantee that the LIKE operator is true, so we
       128772  +        ** can skip the call to the like(A,B) function.  But this only works
       128773  +        ** for strings.  So do not skip the call to the function on the pass
       128774  +        ** that compares BLOBs. */
128306 128775   #ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS
128307         -      continue;
       128776  +        continue;
128308 128777   #else
128309         -      u32 x = pLevel->iLikeRepCntr;
128310         -      assert( x>0 );
128311         -      skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)? OP_IfNot : OP_If, (int)(x>>1));
128312         -      VdbeCoverage(v);
       128778  +        u32 x = pLevel->iLikeRepCntr;
       128779  +        assert( x>0 );
       128780  +        skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)?OP_IfNot:OP_If, (int)(x>>1));
       128781  +        VdbeCoverage(v);
128313 128782   #endif
       128783  +      }
       128784  +      sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
       128785  +      if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
       128786  +      pTerm->wtFlags |= TERM_CODED;
128314 128787       }
128315         -    sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
128316         -    if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
128317         -    pTerm->wtFlags |= TERM_CODED;
128318         -  }
       128788  +    pIdx = 0;
       128789  +  }while( loopAgain );
128319 128790   
128320 128791     /* Insert code to test for implied constraints based on transitivity
128321 128792     ** of the "==" operator.
128322 128793     **
128323 128794     ** Example: If the WHERE clause contains "t1.a=t2.b" and "t2.b=123"
128324 128795     ** and we are coding the t1 loop and the t2 loop has not yet coded,
128325 128796     ** then we cannot use the "t1.a=t2.b" constraint, but we can code
................................................................................
129204 129675     return mask;
129205 129676   }
129206 129677   
129207 129678   /*
129208 129679   ** Expression pExpr is one operand of a comparison operator that might
129209 129680   ** be useful for indexing.  This routine checks to see if pExpr appears
129210 129681   ** in any index.  Return TRUE (1) if pExpr is an indexed term and return
129211         -** FALSE (0) if not.  If TRUE is returned, also set *piCur to the cursor
129212         -** number of the table that is indexed and *piColumn to the column number
       129682  +** FALSE (0) if not.  If TRUE is returned, also set aiCurCol[0] to the cursor
       129683  +** number of the table that is indexed and aiCurCol[1] to the column number
129213 129684   ** of the column that is indexed, or XN_EXPR (-2) if an expression is being
129214 129685   ** indexed.
129215 129686   **
129216 129687   ** If pExpr is a TK_COLUMN column reference, then this routine always returns
129217 129688   ** true even if that particular column is not indexed, because the column
129218 129689   ** might be added to an automatic index later.
129219 129690   */
129220         -static int exprMightBeIndexed(
       129691  +static SQLITE_NOINLINE int exprMightBeIndexed2(
129221 129692     SrcList *pFrom,        /* The FROM clause */
129222         -  int op,                /* The specific comparison operator */
129223 129693     Bitmask mPrereq,       /* Bitmask of FROM clause terms referenced by pExpr */
129224         -  Expr *pExpr,           /* An operand of a comparison operator */
129225         -  int *piCur,            /* Write the referenced table cursor number here */
129226         -  int *piColumn          /* Write the referenced table column number here */
       129694  +  int *aiCurCol,         /* Write the referenced table cursor and column here */
       129695  +  Expr *pExpr            /* An operand of a comparison operator */
129227 129696   ){
129228 129697     Index *pIdx;
129229 129698     int i;
129230 129699     int iCur;
129231         -
       129700  +  for(i=0; mPrereq>1; i++, mPrereq>>=1){}
       129701  +  iCur = pFrom->a[i].iCursor;
       129702  +  for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){
       129703  +    if( pIdx->aColExpr==0 ) continue;
       129704  +    for(i=0; i<pIdx->nKeyCol; i++){
       129705  +      if( pIdx->aiColumn[i]!=XN_EXPR ) continue;
       129706  +      if( sqlite3ExprCompareSkip(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
       129707  +        aiCurCol[0] = iCur;
       129708  +        aiCurCol[1] = XN_EXPR;
       129709  +        return 1;
       129710  +      }
       129711  +    }
       129712  +  }
       129713  +  return 0;
       129714  +}
       129715  +static int exprMightBeIndexed(
       129716  +  SrcList *pFrom,        /* The FROM clause */
       129717  +  Bitmask mPrereq,       /* Bitmask of FROM clause terms referenced by pExpr */
       129718  +  int *aiCurCol,         /* Write the referenced table cursor & column here */
       129719  +  Expr *pExpr,           /* An operand of a comparison operator */
       129720  +  int op                 /* The specific comparison operator */
       129721  +){
129232 129722     /* If this expression is a vector to the left or right of a 
129233 129723     ** inequality constraint (>, <, >= or <=), perform the processing 
129234 129724     ** on the first element of the vector.  */
129235 129725     assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE );
129236 129726     assert( TK_IS<TK_GE && TK_ISNULL<TK_GE && TK_IN<TK_GE );
129237 129727     assert( op<=TK_GE );
129238 129728     if( pExpr->op==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){
129239 129729       pExpr = pExpr->x.pList->a[0].pExpr;
129240 129730     }
129241 129731   
129242 129732     if( pExpr->op==TK_COLUMN ){
129243         -    *piCur = pExpr->iTable;
129244         -    *piColumn = pExpr->iColumn;
       129733  +    aiCurCol[0] = pExpr->iTable;
       129734  +    aiCurCol[1] = pExpr->iColumn;
129245 129735       return 1;
129246 129736     }
129247 129737     if( mPrereq==0 ) return 0;                 /* No table references */
129248 129738     if( (mPrereq&(mPrereq-1))!=0 ) return 0;   /* Refs more than one table */
129249         -  for(i=0; mPrereq>1; i++, mPrereq>>=1){}
129250         -  iCur = pFrom->a[i].iCursor;
129251         -  for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){
129252         -    if( pIdx->aColExpr==0 ) continue;
129253         -    for(i=0; i<pIdx->nKeyCol; i++){
129254         -      if( pIdx->aiColumn[i]!=XN_EXPR ) continue;
129255         -      if( sqlite3ExprCompareSkip(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
129256         -        *piCur = iCur;
129257         -        *piColumn = XN_EXPR;
129258         -        return 1;
129259         -      }
129260         -    }
129261         -  }
129262         -  return 0;
       129739  +  return exprMightBeIndexed2(pFrom,mPrereq,aiCurCol,pExpr);
129263 129740   }
129264 129741   
129265 129742   /*
129266 129743   ** The input to this routine is an WhereTerm structure with only the
129267 129744   ** "pExpr" field filled in.  The job of this routine is to analyze the
129268 129745   ** subexpression and populate all the other fields of the WhereTerm
129269 129746   ** structure.
................................................................................
129335 129812       }
129336 129813     }
129337 129814     pTerm->prereqAll = prereqAll;
129338 129815     pTerm->leftCursor = -1;
129339 129816     pTerm->iParent = -1;
129340 129817     pTerm->eOperator = 0;
129341 129818     if( allowedOp(op) ){
129342         -    int iCur, iColumn;
       129819  +    int aiCurCol[2];
129343 129820       Expr *pLeft = sqlite3ExprSkipCollate(pExpr->pLeft);
129344 129821       Expr *pRight = sqlite3ExprSkipCollate(pExpr->pRight);
129345 129822       u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
129346 129823   
129347 129824       if( pTerm->iField>0 ){
129348 129825         assert( op==TK_IN );
129349 129826         assert( pLeft->op==TK_VECTOR );
129350 129827         pLeft = pLeft->x.pList->a[pTerm->iField-1].pExpr;
129351 129828       }
129352 129829   
129353         -    if( exprMightBeIndexed(pSrc, op, prereqLeft, pLeft, &iCur, &iColumn) ){
129354         -      pTerm->leftCursor = iCur;
129355         -      pTerm->u.leftColumn = iColumn;
       129830  +    if( exprMightBeIndexed(pSrc, prereqLeft, aiCurCol, pLeft, op) ){
       129831  +      pTerm->leftCursor = aiCurCol[0];
       129832  +      pTerm->u.leftColumn = aiCurCol[1];
129356 129833         pTerm->eOperator = operatorMask(op) & opMask;
129357 129834       }
129358 129835       if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
129359 129836       if( pRight 
129360         -     && exprMightBeIndexed(pSrc, op, pTerm->prereqRight, pRight, &iCur,&iColumn)
       129837  +     && exprMightBeIndexed(pSrc, pTerm->prereqRight, aiCurCol, pRight, op)
129361 129838       ){
129362 129839         WhereTerm *pNew;
129363 129840         Expr *pDup;
129364 129841         u16 eExtraOp = 0;        /* Extra bits for pNew->eOperator */
129365 129842         assert( pTerm->iField==0 );
129366 129843         if( pTerm->leftCursor>=0 ){
129367 129844           int idxNew;
................................................................................
129383 129860             eExtraOp = WO_EQUIV;
129384 129861           }
129385 129862         }else{
129386 129863           pDup = pExpr;
129387 129864           pNew = pTerm;
129388 129865         }
129389 129866         exprCommute(pParse, pDup);
129390         -      pNew->leftCursor = iCur;
129391         -      pNew->u.leftColumn = iColumn;
       129867  +      pNew->leftCursor = aiCurCol[0];
       129868  +      pNew->u.leftColumn = aiCurCol[1];
129392 129869         testcase( (prereqLeft | extraRight) != prereqLeft );
129393 129870         pNew->prereqRight = prereqLeft | extraRight;
129394 129871         pNew->prereqAll = prereqAll;
129395 129872         pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
129396 129873       }
129397 129874     }
129398 129875   
................................................................................
131616 132093     if( p->wsFlags & (WHERE_VIRTUALTABLE|WHERE_AUTO_INDEX) ){
131617 132094       if( (p->wsFlags & WHERE_VIRTUALTABLE)!=0 && p->u.vtab.needFree ){
131618 132095         sqlite3_free(p->u.vtab.idxStr);
131619 132096         p->u.vtab.needFree = 0;
131620 132097         p->u.vtab.idxStr = 0;
131621 132098       }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
131622 132099         sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
131623         -      sqlite3DbFree(db, p->u.btree.pIndex);
       132100  +      sqlite3DbFreeNN(db, p->u.btree.pIndex);
131624 132101         p->u.btree.pIndex = 0;
131625 132102       }
131626 132103     }
131627 132104   }
131628 132105   
131629 132106   /*
131630 132107   ** Deallocate internal memory used by a WhereLoop object
131631 132108   */
131632 132109   static void whereLoopClear(sqlite3 *db, WhereLoop *p){
131633         -  if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFree(db, p->aLTerm);
       132110  +  if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
131634 132111     whereLoopClearUnion(db, p);
131635 132112     whereLoopInit(p);
131636 132113   }
131637 132114   
131638 132115   /*
131639 132116   ** Increase the memory allocation for pLoop->aLTerm[] to be at least n.
131640 132117   */
................................................................................
131641 132118   static int whereLoopResize(sqlite3 *db, WhereLoop *p, int n){
131642 132119     WhereTerm **paNew;
131643 132120     if( p->nLSlot>=n ) return SQLITE_OK;
131644 132121     n = (n+7)&~7;
131645 132122     paNew = sqlite3DbMallocRawNN(db, sizeof(p->aLTerm[0])*n);
131646 132123     if( paNew==0 ) return SQLITE_NOMEM_BKPT;
131647 132124     memcpy(paNew, p->aLTerm, sizeof(p->aLTerm[0])*p->nLSlot);
131648         -  if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFree(db, p->aLTerm);
       132125  +  if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
131649 132126     p->aLTerm = paNew;
131650 132127     p->nLSlot = n;
131651 132128     return SQLITE_OK;
131652 132129   }
131653 132130   
131654 132131   /*
131655 132132   ** Transfer content from the second pLoop into the first.
................................................................................
131671 132148   }
131672 132149   
131673 132150   /*
131674 132151   ** Delete a WhereLoop object
131675 132152   */
131676 132153   static void whereLoopDelete(sqlite3 *db, WhereLoop *p){
131677 132154     whereLoopClear(db, p);
131678         -  sqlite3DbFree(db, p);
       132155  +  sqlite3DbFreeNN(db, p);
131679 132156   }
131680 132157   
131681 132158   /*
131682 132159   ** Free a WhereInfo structure
131683 132160   */
131684 132161   static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
131685 132162     if( ALWAYS(pWInfo) ){
................................................................................
131692 132169       }
131693 132170       sqlite3WhereClauseClear(&pWInfo->sWC);
131694 132171       while( pWInfo->pLoops ){
131695 132172         WhereLoop *p = pWInfo->pLoops;
131696 132173         pWInfo->pLoops = p->pNextLoop;
131697 132174         whereLoopDelete(db, p);
131698 132175       }
131699         -    sqlite3DbFree(db, pWInfo);
       132176  +    sqlite3DbFreeNN(db, pWInfo);
131700 132177     }
131701 132178   }
131702 132179   
131703 132180   /*
131704 132181   ** Return TRUE if all of the following are true:
131705 132182   **
131706 132183   **   (1)  X has the same or lower cost that Y
................................................................................
133083 133560         WHERETRACE(0x40, ("  VirtualOne: all disabled and w/o IN\n"));
133084 133561         rc = whereLoopAddVirtualOne(
133085 133562             pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn);
133086 133563       }
133087 133564     }
133088 133565   
133089 133566     if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr);
133090         -  sqlite3DbFree(pParse->db, p);
       133567  +  sqlite3DbFreeNN(pParse->db, p);
133091 133568     return rc;
133092 133569   }
133093 133570   #endif /* SQLITE_OMIT_VIRTUALTABLE */
133094 133571   
133095 133572   /*
133096 133573   ** Add WhereLoop entries to handle OR terms.  This works for either
133097 133574   ** btrees or virtual tables.
................................................................................
133267 133744     }
133268 133745   
133269 133746     whereLoopClear(db, pNew);
133270 133747     return rc;
133271 133748   }
133272 133749   
133273 133750   /*
133274         -** Examine a WherePath (with the addition of the extra WhereLoop of the 5th
       133751  +** Examine a WherePath (with the addition of the extra WhereLoop of the 6th
133275 133752   ** parameters) to see if it outputs rows in the requested ORDER BY
133276 133753   ** (or GROUP BY) without requiring a separate sort operation.  Return N:
133277 133754   ** 
133278 133755   **   N>0:   N terms of the ORDER BY clause are satisfied
133279 133756   **   N==0:  No terms of the ORDER BY clause are satisfied
133280 133757   **   N<0:   Unknown yet how many terms of ORDER BY might be satisfied.   
133281 133758   **
................................................................................
133362 133839         if( wctrlFlags & WHERE_ORDERBY_LIMIT ) continue;
133363 133840       }else{
133364 133841         pLoop = pLast;
133365 133842       }
133366 133843       if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){
133367 133844         if( pLoop->u.vtab.isOrdered ) obSat = obDone;
133368 133845         break;
       133846  +    }else{
       133847  +      pLoop->u.btree.nIdxCol = 0;
133369 133848       }
133370 133849       iCur = pWInfo->pTabList->a[pLoop->iTab].iCursor;
133371 133850   
133372 133851       /* Mark off any ORDER BY term X that is a column in the table of
133373 133852       ** the current loop for which there is term in the WHERE
133374 133853       ** clause of the form X IS NULL or X=? that reference only outer
133375 133854       ** loops.
................................................................................
133507 133986               }
133508 133987             }
133509 133988             if( iColumn>=0 ){
133510 133989               pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr);
133511 133990               if( !pColl ) pColl = db->pDfltColl;
133512 133991               if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
133513 133992             }
       133993  +          pLoop->u.btree.nIdxCol = j+1;
133514 133994             isMatch = 1;
133515 133995             break;
133516 133996           }
133517 133997           if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
133518 133998             /* Make sure the sort order is compatible in an ORDER BY clause.
133519 133999             ** Sort order is irrelevant for a GROUP BY clause. */
133520 134000             if( revSet ){
................................................................................
133938 134418       aTo = aFrom;
133939 134419       aFrom = pFrom;
133940 134420       nFrom = nTo;
133941 134421     }
133942 134422   
133943 134423     if( nFrom==0 ){
133944 134424       sqlite3ErrorMsg(pParse, "no query solution");
133945         -    sqlite3DbFree(db, pSpace);
       134425  +    sqlite3DbFreeNN(db, pSpace);
133946 134426       return SQLITE_ERROR;
133947 134427     }
133948 134428     
133949 134429     /* Find the lowest cost path.  pFrom will be left pointing to that path */
133950 134430     pFrom = aFrom;
133951 134431     for(ii=1; ii<nFrom; ii++){
133952 134432       if( pFrom->rCost>aFrom[ii].rCost ) pFrom = &aFrom[ii];
................................................................................
134014 134494       }
134015 134495     }
134016 134496   
134017 134497   
134018 134498     pWInfo->nRowOut = pFrom->nRow;
134019 134499   
134020 134500     /* Free temporary memory and return success */
134021         -  sqlite3DbFree(db, pSpace);
       134501  +  sqlite3DbFreeNN(db, pSpace);
134022 134502     return SQLITE_OK;
134023 134503   }
134024 134504   
134025 134505   /*
134026 134506   ** Most queries use only a single table (they are not joins) and have
134027 134507   ** simple == constraints against indexed fields.  This routine attempts
134028 134508   ** to plan those simple cases using much less ceremony than the
................................................................................
134092 134572         pLoop->rRun = 39;  /* 39==sqlite3LogEst(15) */
134093 134573         break;
134094 134574       }
134095 134575     }
134096 134576     if( pLoop->wsFlags ){
134097 134577       pLoop->nOut = (LogEst)1;
134098 134578       pWInfo->a[0].pWLoop = pLoop;
134099         -    pLoop->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur);
       134579  +    assert( pWInfo->sMaskSet.n==1 && iCur==pWInfo->sMaskSet.ix[0] );
       134580  +    pLoop->maskSelf = 1; /* sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur); */
134100 134581       pWInfo->a[0].iTabCur = iCur;
134101 134582       pWInfo->nRowOut = 1;
134102 134583       if( pWInfo->pOrderBy ) pWInfo->nOBSat =  pWInfo->pOrderBy->nExpr;
134103 134584       if( pWInfo->wctrlFlags & WHERE_WANT_DISTINCT ){
134104 134585         pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
134105 134586       }
134106 134587   #ifdef SQLITE_DEBUG
................................................................................
134276 134757       sqlite3DbFree(db, pWInfo);
134277 134758       pWInfo = 0;
134278 134759       goto whereBeginError;
134279 134760     }
134280 134761     pWInfo->pParse = pParse;
134281 134762     pWInfo->pTabList = pTabList;
134282 134763     pWInfo->pOrderBy = pOrderBy;
       134764  +  pWInfo->pWhere = pWhere;
134283 134765     pWInfo->pResultSet = pResultSet;
134284 134766     pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
134285 134767     pWInfo->nLevel = nTabList;
134286 134768     pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
134287 134769     pWInfo->wctrlFlags = wctrlFlags;
134288 134770     pWInfo->iLimit = iAuxArg;
134289 134771     pWInfo->savedNQueryLoop = pParse->nQueryLoop;
................................................................................
134586 135068         assert( iIndexCur>=0 );
134587 135069         if( op ){
134588 135070           sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
134589 135071           sqlite3VdbeSetP4KeyInfo(pParse, pIx);
134590 135072           if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=0
134591 135073            && (pLoop->wsFlags & (WHERE_COLUMN_RANGE|WHERE_SKIPSCAN))==0
134592 135074            && (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0
       135075  +         && pWInfo->eDistinct!=WHERE_DISTINCT_ORDERED
134593 135076           ){
134594 135077             sqlite3VdbeChangeP5(v, OPFLAG_SEEKEQ); /* Hint to COMDB2 */
134595 135078           }
134596 135079           VdbeComment((v, "%s", pIx->zName));
134597 135080   #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
134598 135081           {
134599 135082             u64 colUsed = 0;
................................................................................
134674 135157     */
134675 135158     VdbeModuleComment((v, "End WHERE-core"));
134676 135159     sqlite3ExprCacheClear(pParse);
134677 135160     for(i=pWInfo->nLevel-1; i>=0; i--){
134678 135161       int addr;
134679 135162       pLevel = &pWInfo->a[i];
134680 135163       pLoop = pLevel->pWLoop;
134681         -    sqlite3VdbeResolveLabel(v, pLevel->addrCont);
134682 135164       if( pLevel->op!=OP_Noop ){
       135165  +#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
       135166  +      int addrSeek = 0;
       135167  +      Index *pIdx;
       135168  +      int n;
       135169  +      if( pWInfo->eDistinct==WHERE_DISTINCT_ORDERED
       135170  +       && (pLoop->wsFlags & WHERE_INDEXED)!=0
       135171  +       && (pIdx = pLoop->u.btree.pIndex)->hasStat1
       135172  +       && (n = pLoop->u.btree.nIdxCol)>0
       135173  +       && pIdx->aiRowLogEst[n]>=36
       135174  +      ){
       135175  +        int r1 = pParse->nMem+1;
       135176  +        int j, op;
       135177  +        for(j=0; j<n; j++){
       135178  +          sqlite3VdbeAddOp3(v, OP_Column, pLevel->iIdxCur, j, r1+j);
       135179  +        }
       135180  +        pParse->nMem += n+1;
       135181  +        op = pLevel->op==OP_Prev ? OP_SeekLT : OP_SeekGT;
       135182  +        addrSeek = sqlite3VdbeAddOp4Int(v, op, pLevel->iIdxCur, 0, r1, n);
       135183  +        VdbeCoverageIf(v, op==OP_SeekLT);
       135184  +        VdbeCoverageIf(v, op==OP_SeekGT);
       135185  +        sqlite3VdbeAddOp2(v, OP_Goto, 1, pLevel->p2);
       135186  +      }
       135187  +#endif /* SQLITE_DISABLE_SKIPAHEAD_DISTINCT */
       135188  +      /* The common case: Advance to the next row */
       135189  +      sqlite3VdbeResolveLabel(v, pLevel->addrCont);
134683 135190         sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
134684 135191         sqlite3VdbeChangeP5(v, pLevel->p5);
134685 135192         VdbeCoverage(v);
134686 135193         VdbeCoverageIf(v, pLevel->op==OP_Next);
134687 135194         VdbeCoverageIf(v, pLevel->op==OP_Prev);
134688 135195         VdbeCoverageIf(v, pLevel->op==OP_VNext);
       135196  +#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
       135197  +      if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek);
       135198  +#endif
       135199  +    }else{
       135200  +      sqlite3VdbeResolveLabel(v, pLevel->addrCont);
134689 135201       }
134690 135202       if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
134691 135203         struct InLoop *pIn;
134692 135204         int j;
134693 135205         sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
134694 135206         for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
134695 135207           sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
................................................................................
134804 135316               pOp->p1 = pLevel->iIdxCur;
134805 135317             }
134806 135318             assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0 
134807 135319                 || pWInfo->eOnePass );
134808 135320           }else if( pOp->opcode==OP_Rowid ){
134809 135321             pOp->p1 = pLevel->iIdxCur;
134810 135322             pOp->opcode = OP_IdxRowid;
       135323  +        }else if( pOp->opcode==OP_IfNullRow ){
       135324  +          pOp->p1 = pLevel->iIdxCur;
134811 135325           }
134812 135326         }
134813 135327       }
134814 135328     }
134815 135329   
134816 135330     /* Final cleanup
134817 135331     */
................................................................................
135113 135627   #ifndef INTERFACE
135114 135628   # define INTERFACE 1
135115 135629   #endif
135116 135630   /************* Begin control #defines *****************************************/
135117 135631   #define YYCODETYPE unsigned char
135118 135632   #define YYNOCODE 252
135119 135633   #define YYACTIONTYPE unsigned short int
135120         -#define YYWILDCARD 96
       135634  +#define YYWILDCARD 69
135121 135635   #define sqlite3ParserTOKENTYPE Token
135122 135636   typedef union {
135123 135637     int yyinit;
135124 135638     sqlite3ParserTOKENTYPE yy0;
135125 135639     Expr* yy72;
135126 135640     TriggerStep* yy145;
135127 135641     ExprList* yy148;
................................................................................
135220 135734   **  yy_shift_ofst[]    For each state, the offset into yy_action for
135221 135735   **                     shifting terminals.
135222 135736   **  yy_reduce_ofst[]   For each state, the offset into yy_action for
135223 135737   **                     shifting non-terminals after a reduce.
135224 135738   **  yy_default[]       Default action for each state.
135225 135739   **
135226 135740   *********** Begin parsing tables **********************************************/
135227         -#define YY_ACTTAB_COUNT (1567)
       135741  +#define YY_ACTTAB_COUNT (1566)
135228 135742   static const YYACTIONTYPE yy_action[] = {
135229         - /*     0 */   325,  832,  351,  825,    5,  203,  203,  819,   99,  100,
135230         - /*    10 */    90,  978,  978,  853,  856,  845,  845,   97,   97,   98,
135231         - /*    20 */    98,   98,   98,  301,   96,   96,   96,   96,   95,   95,
135232         - /*    30 */    94,   94,   94,   93,  351,  325,  976,  976,  824,  824,
135233         - /*    40 */   826,  946,  354,   99,  100,   90,  978,  978,  853,  856,
135234         - /*    50 */   845,  845,   97,   97,   98,   98,   98,   98,  338,   96,
135235         - /*    60 */    96,   96,   96,   95,   95,   94,   94,   94,   93,  351,
135236         - /*    70 */    95,   95,   94,   94,   94,   93,  351,  791,  976,  976,
135237         - /*    80 */   325,   94,   94,   94,   93,  351,  792,   75,   99,  100,
135238         - /*    90 */    90,  978,  978,  853,  856,  845,  845,   97,   97,   98,
135239         - /*   100 */    98,   98,   98,  450,   96,   96,   96,   96,   95,   95,
135240         - /*   110 */    94,   94,   94,   93,  351, 1333,  155,  155,    2,  325,
135241         - /*   120 */   275,  146,  132,   52,   52,   93,  351,   99,  100,   90,
135242         - /*   130 */   978,  978,  853,  856,  845,  845,   97,   97,   98,   98,
135243         - /*   140 */    98,   98,  101,   96,   96,   96,   96,   95,   95,   94,
135244         - /*   150 */    94,   94,   93,  351,  957,  957,  325,  268,  428,  413,
135245         - /*   160 */   411,   61,  752,  752,   99,  100,   90,  978,  978,  853,
135246         - /*   170 */   856,  845,  845,   97,   97,   98,   98,   98,   98,   60,
135247         - /*   180 */    96,   96,   96,   96,   95,   95,   94,   94,   94,   93,
135248         - /*   190 */   351,  325,  270,  329,  273,  277,  958,  959,  250,   99,
135249         - /*   200 */   100,   90,  978,  978,  853,  856,  845,  845,   97,   97,
135250         - /*   210 */    98,   98,   98,   98,  301,   96,   96,   96,   96,   95,
135251         - /*   220 */    95,   94,   94,   94,   93,  351,  325,  937, 1326,  698,
135252         - /*   230 */   706, 1326,  242,  412,   99,  100,   90,  978,  978,  853,
135253         - /*   240 */   856,  845,  845,   97,   97,   98,   98,   98,   98,  347,
135254         - /*   250 */    96,   96,   96,   96,   95,   95,   94,   94,   94,   93,
135255         - /*   260 */   351,  325,  937, 1327,  384,  699, 1327,  381,  379,   99,
135256         - /*   270 */   100,   90,  978,  978,  853,  856,  845,  845,   97,   97,
135257         - /*   280 */    98,   98,   98,   98,  701,   96,   96,   96,   96,   95,
135258         - /*   290 */    95,   94,   94,   94,   93,  351,  325,   92,   89,  178,
135259         - /*   300 */   833,  935,  373,  700,   99,  100,   90,  978,  978,  853,
135260         - /*   310 */   856,  845,  845,   97,   97,   98,   98,   98,   98,  375,
135261         - /*   320 */    96,   96,   96,   96,   95,   95,   94,   94,   94,   93,
135262         - /*   330 */   351,  325, 1275,  946,  354,  818,  935,  739,  739,   99,
135263         - /*   340 */   100,   90,  978,  978,  853,  856,  845,  845,   97,   97,
135264         - /*   350 */    98,   98,   98,   98,  230,   96,   96,   96,   96,   95,
135265         - /*   360 */    95,   94,   94,   94,   93,  351,  325,  968,  227,   92,
135266         - /*   370 */    89,  178,  373,  300,   99,  100,   90,  978,  978,  853,
135267         - /*   380 */   856,  845,  845,   97,   97,   98,   98,   98,   98,  920,
135268         - /*   390 */    96,   96,   96,   96,   95,   95,   94,   94,   94,   93,
135269         - /*   400 */   351,  325,  449,  447,  447,  447,  147,  737,  737,   99,
135270         - /*   410 */   100,   90,  978,  978,  853,  856,  845,  845,   97,   97,
135271         - /*   420 */    98,   98,   98,   98,  296,   96,   96,   96,   96,   95,
135272         - /*   430 */    95,   94,   94,   94,   93,  351,  325,  419,  231,  957,
135273         - /*   440 */   957,  158,   25,  422,   99,  100,   90,  978,  978,  853,
135274         - /*   450 */   856,  845,  845,   97,   97,   98,   98,   98,   98,  450,
135275         - /*   460 */    96,   96,   96,   96,   95,   95,   94,   94,   94,   93,
135276         - /*   470 */   351,  443,  224,  224,  420,  957,  957,  961,  325,   52,
135277         - /*   480 */    52,  958,  959,  176,  415,   78,   99,  100,   90,  978,
135278         - /*   490 */   978,  853,  856,  845,  845,   97,   97,   98,   98,   98,
135279         - /*   500 */    98,  379,   96,   96,   96,   96,   95,   95,   94,   94,
135280         - /*   510 */    94,   93,  351,  325,  428,  418,  298,  958,  959,  961,
135281         - /*   520 */    81,   99,   88,   90,  978,  978,  853,  856,  845,  845,
135282         - /*   530 */    97,   97,   98,   98,   98,   98,  717,   96,   96,   96,
135283         - /*   540 */    96,   95,   95,   94,   94,   94,   93,  351,  325,  842,
135284         - /*   550 */   842,  854,  857,  996,  318,  343,  379,  100,   90,  978,
135285         - /*   560 */   978,  853,  856,  845,  845,   97,   97,   98,   98,   98,
135286         - /*   570 */    98,  450,   96,   96,   96,   96,   95,   95,   94,   94,
135287         - /*   580 */    94,   93,  351,  325,  350,  350,  350,  260,  377,  340,
135288         - /*   590 */   928,   52,   52,   90,  978,  978,  853,  856,  845,  845,
135289         - /*   600 */    97,   97,   98,   98,   98,   98,  361,   96,   96,   96,
135290         - /*   610 */    96,   95,   95,   94,   94,   94,   93,  351,   86,  445,
135291         - /*   620 */   846,    3, 1202,  361,  360,  378,  344,  813,  957,  957,
135292         - /*   630 */  1299,   86,  445,  729,    3,  212,  169,  287,  405,  282,
135293         - /*   640 */   404,  199,  232,  450,  300,  760,   83,   84,  280,  245,
135294         - /*   650 */   262,  365,  251,   85,  352,  352,   92,   89,  178,   83,
135295         - /*   660 */    84,  242,  412,   52,   52,  448,   85,  352,  352,  246,
135296         - /*   670 */   958,  959,  194,  455,  670,  402,  399,  398,  448,  243,
135297         - /*   680 */   221,  114,  434,  776,  361,  450,  397,  268,  747,  224,
135298         - /*   690 */   224,  132,  132,  198,  832,  434,  452,  451,  428,  427,
135299         - /*   700 */   819,  415,  734,  713,  132,   52,   52,  832,  268,  452,
135300         - /*   710 */   451,  734,  194,  819,  363,  402,  399,  398,  450, 1270,
135301         - /*   720 */  1270,   23,  957,  957,   86,  445,  397,    3,  228,  429,
135302         - /*   730 */   894,  824,  824,  826,  827,   19,  203,  720,   52,   52,
135303         - /*   740 */   428,  408,  439,  249,  824,  824,  826,  827,   19,  229,
135304         - /*   750 */   403,  153,   83,   84,  761,  177,  241,  450,  721,   85,
135305         - /*   760 */   352,  352,  120,  157,  958,  959,   58,  976,  409,  355,
135306         - /*   770 */   330,  448,  268,  428,  430,  320,  790,   32,   32,   86,
135307         - /*   780 */   445,  776,    3,  341,   98,   98,   98,   98,  434,   96,
135308         - /*   790 */    96,   96,   96,   95,   95,   94,   94,   94,   93,  351,
135309         - /*   800 */   832,  120,  452,  451,  813,  886,  819,   83,   84,  976,
135310         - /*   810 */   813,  132,  410,  919,   85,  352,  352,  132,  407,  789,
135311         - /*   820 */   957,  957,   92,   89,  178,  916,  448,  262,  370,  261,
135312         - /*   830 */    82,  913,   80,  262,  370,  261,  776,  824,  824,  826,
135313         - /*   840 */   827,   19,  933,  434,   96,   96,   96,   96,   95,   95,
135314         - /*   850 */    94,   94,   94,   93,  351,  832,   74,  452,  451,  957,
135315         - /*   860 */   957,  819,  958,  959,  120,   92,   89,  178,  944,    2,
135316         - /*   870 */   917,  964,  268,    1,  975,   76,  445,  762,    3,  708,
135317         - /*   880 */   900,  900,  387,  957,  957,  757,  918,  371,  740,  778,
135318         - /*   890 */   756,  257,  824,  824,  826,  827,   19,  417,  741,  450,
135319         - /*   900 */    24,  958,  959,   83,   84,  369,  957,  957,  177,  226,
135320         - /*   910 */    85,  352,  352,  884,  315,  314,  313,  215,  311,   10,
135321         - /*   920 */    10,  683,  448,  349,  348,  958,  959,  908,  777,  157,
135322         - /*   930 */   120,  957,  957,  337,  776,  416,  711,  310,  450,  434,
135323         - /*   940 */   450,  321,  450,  791,  103,  200,  175,  450,  958,  959,
135324         - /*   950 */   907,  832,  792,  452,  451,    9,    9,  819,   10,   10,
135325         - /*   960 */    52,   52,   51,   51,  180,  716,  248,   10,   10,  171,
135326         - /*   970 */   170,  167,  339,  958,  959,  247,  984,  702,  702,  450,
135327         - /*   980 */   715,  233,  686,  982,  888,  983,  182,  913,  824,  824,
135328         - /*   990 */   826,  827,   19,  183,  256,  423,  132,  181,  394,   10,
135329         - /*  1000 */    10,  888,  890,  749,  957,  957,  916,  268,  985,  198,
135330         - /*  1010 */   985,  349,  348,  425,  415,  299,  817,  832,  326,  825,
135331         - /*  1020 */   120,  332,  133,  819,  268,   98,   98,   98,   98,   91,
135332         - /*  1030 */    96,   96,   96,   96,   95,   95,   94,   94,   94,   93,
135333         - /*  1040 */   351,  157,  810,  371,  382,  359,  958,  959,  358,  268,
135334         - /*  1050 */   450,  917,  368,  324,  824,  824,  826,  450,  709,  450,
135335         - /*  1060 */   264,  380,  888,  450,  876,  746,  253,  918,  255,  433,
135336         - /*  1070 */    36,   36,  234,  450,  234,  120,  269,   37,   37,   12,
135337         - /*  1080 */    12,  334,  272,   27,   27,  450,  330,  118,  450,  162,
135338         - /*  1090 */   742,  280,  450,   38,   38,  450,  985,  356,  985,  450,
135339         - /*  1100 */   709, 1209,  450,  132,  450,   39,   39,  450,   40,   40,
135340         - /*  1110 */   450,  362,   41,   41,  450,   42,   42,  450,  254,   28,
135341         - /*  1120 */    28,  450,   29,   29,   31,   31,  450,   43,   43,  450,
135342         - /*  1130 */    44,   44,  450,  714,   45,   45,  450,   11,   11,  767,
135343         - /*  1140 */   450,   46,   46,  450,  268,  450,  105,  105,  450,   47,
135344         - /*  1150 */    47,  450,   48,   48,  450,  237,   33,   33,  450,  172,
135345         - /*  1160 */    49,   49,  450,   50,   50,   34,   34,  274,  122,  122,
135346         - /*  1170 */   450,  123,  123,  450,  124,  124,  450,  897,   56,   56,
135347         - /*  1180 */   450,  896,   35,   35,  450,  267,  450,  817,  450,  817,
135348         - /*  1190 */   106,  106,  450,   53,   53,  385,  107,  107,  450,  817,
135349         - /*  1200 */   108,  108,  817,  450,  104,  104,  121,  121,  119,  119,
135350         - /*  1210 */   450,  117,  112,  112,  450,  276,  450,  225,  111,  111,
135351         - /*  1220 */   450,  730,  450,  109,  109,  450,  673,  674,  675,  911,
135352         - /*  1230 */   110,  110,  317,  998,   55,   55,   57,   57,  692,  331,
135353         - /*  1240 */    54,   54,   26,   26,  696,   30,   30,  317,  936,  197,
135354         - /*  1250 */   196,  195,  335,  281,  336,  446,  331,  745,  689,  436,
135355         - /*  1260 */   440,  444,  120,   72,  386,  223,  175,  345,  757,  932,
135356         - /*  1270 */    20,  286,  319,  756,  815,  372,  374,  202,  202,  202,
135357         - /*  1280 */   263,  395,  285,   74,  208,   21,  696,  719,  718,  883,
135358         - /*  1290 */   120,  120,  120,  120,  120,  754,  278,  828,   77,   74,
135359         - /*  1300 */   726,  727,  785,  783,  879,  202,  999,  208,  893,  892,
135360         - /*  1310 */   893,  892,  694,  816,  763,  116,  774, 1289,  431,  432,
135361         - /*  1320 */   302,  999,  390,  303,  823,  697,  691,  680,  159,  289,
135362         - /*  1330 */   679,  883,  681,  951,  291,  218,  293,    7,  316,  828,
135363         - /*  1340 */   173,  805,  259,  364,  252,  910,  376,  713,  295,  435,
135364         - /*  1350 */   308,  168,  954,  993,  135,  400,  990,  284,  881,  880,
135365         - /*  1360 */   205,  927,  925,   59,  333,   62,  144,  156,  130,   72,
135366         - /*  1370 */   802,  366,  367,  393,  137,  185,  189,  160,  139,  383,
135367         - /*  1380 */    67,  895,  140,  141,  142,  148,  389,  812,  775,  266,
135368         - /*  1390 */   219,  190,  154,  391,  912,  875,  271,  406,  191,  322,
135369         - /*  1400 */   682,  733,  192,  342,  732,  724,  731,  711,  723,  421,
135370         - /*  1410 */   705,   71,  323,    6,  204,  771,  288,   79,  297,  346,
135371         - /*  1420 */   772,  704,  290,  283,  703,  770,  292,  294,  966,  239,
135372         - /*  1430 */   769,  102,  861,  438,  426,  240,  424,  442,   73,  213,
135373         - /*  1440 */   688,  238,   22,  453,  952,  214,  217,  216,  454,  677,
135374         - /*  1450 */   676,  671,  753,  125,  115,  235,  126,  669,  353,  166,
135375         - /*  1460 */   127,  244,  179,  357,  306,  304,  305,  307,  113,  891,
135376         - /*  1470 */   327,  889,  811,  328,  134,  128,  136,  138,  743,  258,
135377         - /*  1480 */   906,  184,  143,  129,  909,  186,   63,   64,  145,  187,
135378         - /*  1490 */   905,   65,    8,   66,   13,  188,  202,  898,  265,  149,
135379         - /*  1500 */   987,  388,  150,  685,  161,  392,  285,  193,  279,  396,
135380         - /*  1510 */   151,  401,   68,   14,   15,  722,   69,  236,  831,  131,
135381         - /*  1520 */   830,  859,   70,  751,   16,  414,  755,    4,  174,  220,
135382         - /*  1530 */   222,  784,  201,  152,  779,   77,   74,   17,   18,  874,
135383         - /*  1540 */   860,  858,  915,  863,  914,  207,  206,  941,  163,  437,
135384         - /*  1550 */   947,  942,  164,  209, 1002,  441,  862,  165,  210,  829,
135385         - /*  1560 */   695,   87,  312,  211, 1291, 1290,  309,
       135743  + /*     0 */   325,  411,  343,  752,  752,  203,  946,  354,  976,   98,
       135744  + /*    10 */    98,   98,   98,   91,   96,   96,   96,   96,   95,   95,
       135745  + /*    20 */    94,   94,   94,   93,  351, 1333,  155,  155,    2,  813,
       135746  + /*    30 */   978,  978,   98,   98,   98,   98,   20,   96,   96,   96,
       135747  + /*    40 */    96,   95,   95,   94,   94,   94,   93,  351,   92,   89,
       135748  + /*    50 */   178,   99,  100,   90,  853,  856,  845,  845,   97,   97,
       135749  + /*    60 */    98,   98,   98,   98,  351,   96,   96,   96,   96,   95,
       135750  + /*    70 */    95,   94,   94,   94,   93,  351,  325,  340,  976,  262,
       135751  + /*    80 */   365,  251,  212,  169,  287,  405,  282,  404,  199,  791,
       135752  + /*    90 */   242,  412,   21,  957,  379,  280,   93,  351,  792,   95,
       135753  + /*   100 */    95,   94,   94,   94,   93,  351,  978,  978,   96,   96,
       135754  + /*   110 */    96,   96,   95,   95,   94,   94,   94,   93,  351,  813,
       135755  + /*   120 */   329,  242,  412,  913,  832,  913,  132,   99,  100,   90,
       135756  + /*   130 */   853,  856,  845,  845,   97,   97,   98,   98,   98,   98,
       135757  + /*   140 */   450,   96,   96,   96,   96,   95,   95,   94,   94,   94,
       135758  + /*   150 */    93,  351,  325,  825,  349,  348,  120,  819,  120,   75,
       135759  + /*   160 */    52,   52,  957,  958,  959,  760,  984,  146,  361,  262,
       135760  + /*   170 */   370,  261,  957,  982,  961,  983,   92,   89,  178,  371,
       135761  + /*   180 */   230,  371,  978,  978,  817,  361,  360,  101,  824,  824,
       135762  + /*   190 */   826,  384,   24,  964,  381,  428,  413,  369,  985,  380,
       135763  + /*   200 */   985,  708,  325,   99,  100,   90,  853,  856,  845,  845,
       135764  + /*   210 */    97,   97,   98,   98,   98,   98,  373,   96,   96,   96,
       135765  + /*   220 */    96,   95,   95,   94,   94,   94,   93,  351,  957,  132,
       135766  + /*   230 */   897,  450,  978,  978,  896,   60,   94,   94,   94,   93,
       135767  + /*   240 */   351,  957,  958,  959,  961,  103,  361,  957,  385,  334,
       135768  + /*   250 */   702,   52,   52,   99,  100,   90,  853,  856,  845,  845,
       135769  + /*   260 */    97,   97,   98,   98,   98,   98,  698,   96,   96,   96,
       135770  + /*   270 */    96,   95,   95,   94,   94,   94,   93,  351,  325,  455,
       135771  + /*   280 */   670,  450,  227,   61,  157,  243,  344,  114,  701,  888,
       135772  + /*   290 */   147,  832,  957,  373,  747,  957,  320,  957,  958,  959,
       135773  + /*   300 */   194,   10,   10,  402,  399,  398,  888,  890,  978,  978,
       135774  + /*   310 */   762,  171,  170,  157,  397,  337,  957,  958,  959,  702,
       135775  + /*   320 */   825,  310,  153,  957,  819,  321,   82,   23,   80,   99,
       135776  + /*   330 */   100,   90,  853,  856,  845,  845,   97,   97,   98,   98,
       135777  + /*   340 */    98,   98,  894,   96,   96,   96,   96,   95,   95,   94,
       135778  + /*   350 */    94,   94,   93,  351,  325,  824,  824,  826,  277,  231,
       135779  + /*   360 */   300,  957,  958,  959,  957,  958,  959,  888,  194,   25,
       135780  + /*   370 */   450,  402,  399,  398,  957,  355,  300,  450,  957,   74,
       135781  + /*   380 */   450,    1,  397,  132,  978,  978,  957,  224,  224,  813,
       135782  + /*   390 */    10,   10,  957,  958,  959,  968,  132,   52,   52,  415,
       135783  + /*   400 */    52,   52,  739,  739,  339,   99,  100,   90,  853,  856,
       135784  + /*   410 */   845,  845,   97,   97,   98,   98,   98,   98,  790,   96,
       135785  + /*   420 */    96,   96,   96,   95,   95,   94,   94,   94,   93,  351,
       135786  + /*   430 */   325,  789,  428,  418,  706,  428,  427, 1270, 1270,  262,
       135787  + /*   440 */   370,  261,  957,  957,  958,  959,  757,  957,  958,  959,
       135788  + /*   450 */   450,  756,  450,  734,  713,  957,  958,  959,  443,  711,
       135789  + /*   460 */   978,  978,  734,  394,   92,   89,  178,  447,  447,  447,
       135790  + /*   470 */    51,   51,   52,   52,  439,  778,  700,   92,   89,  178,
       135791  + /*   480 */   172,   99,  100,   90,  853,  856,  845,  845,   97,   97,
       135792  + /*   490 */    98,   98,   98,   98,  198,   96,   96,   96,   96,   95,
       135793  + /*   500 */    95,   94,   94,   94,   93,  351,  325,  428,  408,  916,
       135794  + /*   510 */   699,  957,  958,  959,   92,   89,  178,  224,  224,  157,
       135795  + /*   520 */   241,  221,  419,  299,  776,  917,  416,  375,  450,  415,
       135796  + /*   530 */    58,  324,  737,  737,  920,  379,  978,  978,  379,  777,
       135797  + /*   540 */   449,  918,  363,  740,  296,  686,    9,    9,   52,   52,
       135798  + /*   550 */   234,  330,  234,  256,  417,  741,  280,   99,  100,   90,
       135799  + /*   560 */   853,  856,  845,  845,   97,   97,   98,   98,   98,   98,
       135800  + /*   570 */   450,   96,   96,   96,   96,   95,   95,   94,   94,   94,
       135801  + /*   580 */    93,  351,  325,  423,   72,  450,  833,  120,  368,  450,
       135802  + /*   590 */    10,   10,    5,  301,  203,  450,  177,  976,  253,  420,
       135803  + /*   600 */   255,  776,  200,  175,  233,   10,   10,  842,  842,   36,
       135804  + /*   610 */    36, 1299,  978,  978,  729,   37,   37,  349,  348,  425,
       135805  + /*   620 */   203,  260,  776,  976,  232,  937, 1326,  876,  338, 1326,
       135806  + /*   630 */   422,  854,  857,   99,  100,   90,  853,  856,  845,  845,
       135807  + /*   640 */    97,   97,   98,   98,   98,   98,  268,   96,   96,   96,
       135808  + /*   650 */    96,   95,   95,   94,   94,   94,   93,  351,  325,  846,
       135809  + /*   660 */   450,  985,  818,  985, 1209,  450,  916,  976,  720,  350,
       135810  + /*   670 */   350,  350,  935,  177,  450,  937, 1327,  254,  198, 1327,
       135811  + /*   680 */    12,   12,  917,  403,  450,   27,   27,  250,  978,  978,
       135812  + /*   690 */   118,  721,  162,  976,   38,   38,  268,  176,  918,  776,
       135813  + /*   700 */   433, 1275,  946,  354,   39,   39,  317,  998,  325,   99,
       135814  + /*   710 */   100,   90,  853,  856,  845,  845,   97,   97,   98,   98,
       135815  + /*   720 */    98,   98,  935,   96,   96,   96,   96,   95,   95,   94,
       135816  + /*   730 */    94,   94,   93,  351,  450,  330,  450,  358,  978,  978,
       135817  + /*   740 */   717,  317,  936,  341,  900,  900,  387,  673,  674,  675,
       135818  + /*   750 */   275,  996,  318,  999,   40,   40,   41,   41,  268,   99,
       135819  + /*   760 */   100,   90,  853,  856,  845,  845,   97,   97,   98,   98,
       135820  + /*   770 */    98,   98,  450,   96,   96,   96,   96,   95,   95,   94,
       135821  + /*   780 */    94,   94,   93,  351,  325,  450,  356,  450,  999,  450,
       135822  + /*   790 */   692,  331,   42,   42,  791,  270,  450,  273,  450,  228,
       135823  + /*   800 */   450,  298,  450,  792,  450,   28,   28,   29,   29,   31,
       135824  + /*   810 */    31,  450,  817,  450,  978,  978,   43,   43,   44,   44,
       135825  + /*   820 */    45,   45,   11,   11,   46,   46,  893,   78,  893,  268,
       135826  + /*   830 */   268,  105,  105,   47,   47,   99,  100,   90,  853,  856,
       135827  + /*   840 */   845,  845,   97,   97,   98,   98,   98,   98,  450,   96,
       135828  + /*   850 */    96,   96,   96,   95,   95,   94,   94,   94,   93,  351,
       135829  + /*   860 */   325,  450,  117,  450,  749,  158,  450,  696,   48,   48,
       135830  + /*   870 */   229,  919,  450,  928,  450,  415,  450,  335,  450,  245,
       135831  + /*   880 */   450,   33,   33,   49,   49,  450,   50,   50,  246,  817,
       135832  + /*   890 */   978,  978,   34,   34,  122,  122,  123,  123,  124,  124,
       135833  + /*   900 */    56,   56,  268,   81,  249,   35,   35,  197,  196,  195,
       135834  + /*   910 */   325,   99,  100,   90,  853,  856,  845,  845,   97,   97,
       135835  + /*   920 */    98,   98,   98,   98,  450,   96,   96,   96,   96,   95,
       135836  + /*   930 */    95,   94,   94,   94,   93,  351,  450,  696,  450,  817,
       135837  + /*   940 */   978,  978,  975,  884,  106,  106,  268,  886,  268,  944,
       135838  + /*   950 */     2,  892,  268,  892,  336,  716,   53,   53,  107,  107,
       135839  + /*   960 */   325,   99,  100,   90,  853,  856,  845,  845,   97,   97,
       135840  + /*   970 */    98,   98,   98,   98,  450,   96,   96,   96,   96,   95,
       135841  + /*   980 */    95,   94,   94,   94,   93,  351,  450,  746,  450,  742,
       135842  + /*   990 */   978,  978,  715,  267,  108,  108,  446,  331,  332,  133,
       135843  + /*  1000 */   223,  175,  301,  225,  386,  933,  104,  104,  121,  121,
       135844  + /*  1010 */   325,   99,   88,   90,  853,  856,  845,  845,   97,   97,
       135845  + /*  1020 */    98,   98,   98,   98,  817,   96,   96,   96,   96,   95,
       135846  + /*  1030 */    95,   94,   94,   94,   93,  351,  450,  347,  450,  167,
       135847  + /*  1040 */   978,  978,  932,  815,  372,  319,  202,  202,  374,  263,
       135848  + /*  1050 */   395,  202,   74,  208,  726,  727,  119,  119,  112,  112,
       135849  + /*  1060 */   325,  407,  100,   90,  853,  856,  845,  845,   97,   97,
       135850  + /*  1070 */    98,   98,   98,   98,  450,   96,   96,   96,   96,   95,
       135851  + /*  1080 */    95,   94,   94,   94,   93,  351,  450,  757,  450,  345,
       135852  + /*  1090 */   978,  978,  756,  278,  111,  111,   74,  719,  718,  709,
       135853  + /*  1100 */   286,  883,  754, 1289,  257,   77,  109,  109,  110,  110,
       135854  + /*  1110 */   908,  285,  810,   90,  853,  856,  845,  845,   97,   97,
       135855  + /*  1120 */    98,   98,   98,   98,  911,   96,   96,   96,   96,   95,
       135856  + /*  1130 */    95,   94,   94,   94,   93,  351,   86,  445,  450,    3,
       135857  + /*  1140 */  1202,  450,  745,  132,  352,  120,  689,   86,  445,  785,
       135858  + /*  1150 */     3,  767,  202,  377,  448,  352,  907,  120,   55,   55,
       135859  + /*  1160 */   450,   57,   57,  828,  879,  448,  450,  208,  450,  709,
       135860  + /*  1170 */   450,  883,  237,  434,  436,  120,  440,  429,  362,  120,
       135861  + /*  1180 */    54,   54,  132,  450,  434,  832,   52,   52,   26,   26,
       135862  + /*  1190 */    30,   30,  382,  132,  409,  444,  832,  694,  264,  390,
       135863  + /*  1200 */   116,  269,  272,   32,   32,   83,   84,  120,  274,  120,
       135864  + /*  1210 */   120,  276,   85,  352,  452,  451,   83,   84,  819,  730,
       135865  + /*  1220 */   714,  428,  430,   85,  352,  452,  451,  120,  120,  819,
       135866  + /*  1230 */   378,  218,  281,  828,  783,  816,   86,  445,  410,    3,
       135867  + /*  1240 */   763,  774,  431,  432,  352,  302,  303,  823,  697,  824,
       135868  + /*  1250 */   824,  826,  827,   19,  448,  691,  680,  679,  681,  951,
       135869  + /*  1260 */   824,  824,  826,  827,   19,  289,  159,  291,  293,    7,
       135870  + /*  1270 */   316,  173,  259,  434,  805,  364,  252,  910,  376,  713,
       135871  + /*  1280 */   295,  435,  168,  993,  400,  832,  284,  881,  880,  205,
       135872  + /*  1290 */   954,  308,  927,   86,  445,  990,    3,  925,  333,  144,
       135873  + /*  1300 */   130,  352,   72,  135,   59,   83,   84,  761,  137,  366,
       135874  + /*  1310 */   802,  448,   85,  352,  452,  451,  139,  226,  819,  140,
       135875  + /*  1320 */   156,   62,  315,  314,  313,  215,  311,  367,  393,  683,
       135876  + /*  1330 */   434,  185,  141,  912,  142,  160,  148,  812,  875,  383,
       135877  + /*  1340 */   189,   67,  832,  180,  389,  248,  895,  775,  219,  824,
       135878  + /*  1350 */   824,  826,  827,   19,  247,  190,  266,  154,  391,  271,
       135879  + /*  1360 */   191,  192,   83,   84,  682,  406,  733,  182,  322,   85,
       135880  + /*  1370 */   352,  452,  451,  732,  183,  819,  342,  132,  181,  711,
       135881  + /*  1380 */   731,  421,   76,  445,  705,    3,  323,  704,  283,  724,
       135882  + /*  1390 */   352,  771,  703,  966,  723,   71,  204,    6,  288,  290,
       135883  + /*  1400 */   448,  772,  770,  769,   79,  292,  824,  824,  826,  827,
       135884  + /*  1410 */    19,  294,  297,  438,  346,  442,  102,  861,  753,  434,
       135885  + /*  1420 */   238,  426,   73,  305,  239,  304,  326,  240,  424,  306,
       135886  + /*  1430 */   307,  832,  213,  688,   22,  952,  453,  214,  216,  217,
       135887  + /*  1440 */   454,  677,  115,  676,  671,  125,  126,  235,  127,  669,
       135888  + /*  1450 */   327,   83,   84,  359,  353,  244,  166,  328,   85,  352,
       135889  + /*  1460 */   452,  451,  134,  179,  819,  357,  113,  891,  811,  889,
       135890  + /*  1470 */   136,  128,  138,  743,  258,  184,  906,  143,  145,   63,
       135891  + /*  1480 */    64,   65,   66,  129,  909,  905,  187,  186,    8,   13,
       135892  + /*  1490 */   188,  265,  898,  149,  202,  824,  824,  826,  827,   19,
       135893  + /*  1500 */   388,  987,  150,  161,  285,  685,  392,  396,  151,  722,
       135894  + /*  1510 */   193,   68,   14,  401,  279,   15,   69,  236,  831,  830,
       135895  + /*  1520 */   131,  859,  751,   70,   16,  414,  755,    4,  784,  220,
       135896  + /*  1530 */   222,  174,  152,  437,  779,  201,   17,   77,   74,   18,
       135897  + /*  1540 */   874,  860,  858,  915,  863,  914,  207,  206,  941,  163,
       135898  + /*  1550 */   210,  942,  209,  164,  441,  862,  165,  211,  829,  695,
       135899  + /*  1560 */    87,  312,  309,  947, 1291, 1290,
135386 135900   };
135387 135901   static const YYCODETYPE yy_lookahead[] = {
135388         - /*     0 */    19,   95,   53,   97,   22,   24,   24,  101,   27,   28,
135389         - /*    10 */    29,   30,   31,   32,   33,   34,   35,   36,   37,   38,
135390         - /*    20 */    39,   40,   41,  152,   43,   44,   45,   46,   47,   48,
135391         - /*    30 */    49,   50,   51,   52,   53,   19,   55,   55,  132,  133,
135392         - /*    40 */   134,    1,    2,   27,   28,   29,   30,   31,   32,   33,
135393         - /*    50 */    34,   35,   36,   37,   38,   39,   40,   41,  187,   43,
135394         - /*    60 */    44,   45,   46,   47,   48,   49,   50,   51,   52,   53,
135395         - /*    70 */    47,   48,   49,   50,   51,   52,   53,   61,   97,   97,
135396         - /*    80 */    19,   49,   50,   51,   52,   53,   70,   26,   27,   28,
135397         - /*    90 */    29,   30,   31,   32,   33,   34,   35,   36,   37,   38,
135398         - /*   100 */    39,   40,   41,  152,   43,   44,   45,   46,   47,   48,
135399         - /*   110 */    49,   50,   51,   52,   53,  144,  145,  146,  147,   19,
135400         - /*   120 */    16,   22,   92,  172,  173,   52,   53,   27,   28,   29,
135401         - /*   130 */    30,   31,   32,   33,   34,   35,   36,   37,   38,   39,
135402         - /*   140 */    40,   41,   81,   43,   44,   45,   46,   47,   48,   49,
135403         - /*   150 */    50,   51,   52,   53,   55,   56,   19,  152,  207,  208,
135404         - /*   160 */   115,   24,  117,  118,   27,   28,   29,   30,   31,   32,
135405         - /*   170 */    33,   34,   35,   36,   37,   38,   39,   40,   41,   79,
135406         - /*   180 */    43,   44,   45,   46,   47,   48,   49,   50,   51,   52,
135407         - /*   190 */    53,   19,   88,  157,   90,   23,   97,   98,  193,   27,
135408         - /*   200 */    28,   29,   30,   31,   32,   33,   34,   35,   36,   37,
135409         - /*   210 */    38,   39,   40,   41,  152,   43,   44,   45,   46,   47,
135410         - /*   220 */    48,   49,   50,   51,   52,   53,   19,   22,   23,  172,
135411         - /*   230 */    23,   26,  119,  120,   27,   28,   29,   30,   31,   32,
135412         - /*   240 */    33,   34,   35,   36,   37,   38,   39,   40,   41,  187,
135413         - /*   250 */    43,   44,   45,   46,   47,   48,   49,   50,   51,   52,
135414         - /*   260 */    53,   19,   22,   23,  228,   23,   26,  231,  152,   27,
135415         - /*   270 */    28,   29,   30,   31,   32,   33,   34,   35,   36,   37,
135416         - /*   280 */    38,   39,   40,   41,  172,   43,   44,   45,   46,   47,
135417         - /*   290 */    48,   49,   50,   51,   52,   53,   19,  221,  222,  223,
135418         - /*   300 */    23,   96,  152,  172,   27,   28,   29,   30,   31,   32,
135419         - /*   310 */    33,   34,   35,   36,   37,   38,   39,   40,   41,  152,
135420         - /*   320 */    43,   44,   45,   46,   47,   48,   49,   50,   51,   52,
135421         - /*   330 */    53,   19,    0,    1,    2,   23,   96,  190,  191,   27,
135422         - /*   340 */    28,   29,   30,   31,   32,   33,   34,   35,   36,   37,
135423         - /*   350 */    38,   39,   40,   41,  238,   43,   44,   45,   46,   47,
135424         - /*   360 */    48,   49,   50,   51,   52,   53,   19,  185,  218,  221,
135425         - /*   370 */   222,  223,  152,  152,   27,   28,   29,   30,   31,   32,
135426         - /*   380 */    33,   34,   35,   36,   37,   38,   39,   40,   41,  241,
135427         - /*   390 */    43,   44,   45,   46,   47,   48,   49,   50,   51,   52,
135428         - /*   400 */    53,   19,  152,  168,  169,  170,   22,  190,  191,   27,
135429         - /*   410 */    28,   29,   30,   31,   32,   33,   34,   35,   36,   37,
135430         - /*   420 */    38,   39,   40,   41,  152,   43,   44,   45,   46,   47,
135431         - /*   430 */    48,   49,   50,   51,   52,   53,   19,   19,  218,   55,
135432         - /*   440 */    56,   24,   22,  152,   27,   28,   29,   30,   31,   32,
135433         - /*   450 */    33,   34,   35,   36,   37,   38,   39,   40,   41,  152,
135434         - /*   460 */    43,   44,   45,   46,   47,   48,   49,   50,   51,   52,
135435         - /*   470 */    53,  250,  194,  195,   56,   55,   56,   55,   19,  172,
135436         - /*   480 */   173,   97,   98,  152,  206,  138,   27,   28,   29,   30,
135437         - /*   490 */    31,   32,   33,   34,   35,   36,   37,   38,   39,   40,
135438         - /*   500 */    41,  152,   43,   44,   45,   46,   47,   48,   49,   50,
135439         - /*   510 */    51,   52,   53,   19,  207,  208,  152,   97,   98,   97,
135440         - /*   520 */   138,   27,   28,   29,   30,   31,   32,   33,   34,   35,
135441         - /*   530 */    36,   37,   38,   39,   40,   41,  181,   43,   44,   45,
135442         - /*   540 */    46,   47,   48,   49,   50,   51,   52,   53,   19,   30,
135443         - /*   550 */    31,   32,   33,  247,  248,   19,  152,   28,   29,   30,
135444         - /*   560 */    31,   32,   33,   34,   35,   36,   37,   38,   39,   40,
135445         - /*   570 */    41,  152,   43,   44,   45,   46,   47,   48,   49,   50,
135446         - /*   580 */    51,   52,   53,   19,  168,  169,  170,  238,   19,   53,
135447         - /*   590 */   152,  172,  173,   29,   30,   31,   32,   33,   34,   35,
135448         - /*   600 */    36,   37,   38,   39,   40,   41,  152,   43,   44,   45,
135449         - /*   610 */    46,   47,   48,   49,   50,   51,   52,   53,   19,   20,
135450         - /*   620 */   101,   22,   23,  169,  170,   56,  207,   85,   55,   56,
135451         - /*   630 */    23,   19,   20,   26,   22,   99,  100,  101,  102,  103,
135452         - /*   640 */   104,  105,  238,  152,  152,  210,   47,   48,  112,  152,
135453         - /*   650 */   108,  109,  110,   54,   55,   56,  221,  222,  223,   47,
135454         - /*   660 */    48,  119,  120,  172,  173,   66,   54,   55,   56,  152,
135455         - /*   670 */    97,   98,   99,  148,  149,  102,  103,  104,   66,  154,
135456         - /*   680 */    23,  156,   83,   26,  230,  152,  113,  152,  163,  194,
135457         - /*   690 */   195,   92,   92,   30,   95,   83,   97,   98,  207,  208,
135458         - /*   700 */   101,  206,  179,  180,   92,  172,  173,   95,  152,   97,
135459         - /*   710 */    98,  188,   99,  101,  219,  102,  103,  104,  152,  119,
135460         - /*   720 */   120,  196,   55,   56,   19,   20,  113,   22,  193,  163,
135461         - /*   730 */    11,  132,  133,  134,  135,  136,   24,   65,  172,  173,
135462         - /*   740 */   207,  208,  250,  152,  132,  133,  134,  135,  136,  193,
135463         - /*   750 */    78,   84,   47,   48,   49,   98,  199,  152,   86,   54,
135464         - /*   760 */    55,   56,  196,  152,   97,   98,  209,   55,  163,  244,
135465         - /*   770 */   107,   66,  152,  207,  208,  164,  175,  172,  173,   19,
135466         - /*   780 */    20,  124,   22,  111,   38,   39,   40,   41,   83,   43,
135467         - /*   790 */    44,   45,   46,   47,   48,   49,   50,   51,   52,   53,
135468         - /*   800 */    95,  196,   97,   98,   85,  152,  101,   47,   48,   97,
135469         - /*   810 */    85,   92,  207,  193,   54,   55,   56,   92,   49,  175,
135470         - /*   820 */    55,   56,  221,  222,  223,   12,   66,  108,  109,  110,
135471         - /*   830 */   137,  163,  139,  108,  109,  110,   26,  132,  133,  134,
135472         - /*   840 */   135,  136,  152,   83,   43,   44,   45,   46,   47,   48,
135473         - /*   850 */    49,   50,   51,   52,   53,   95,   26,   97,   98,   55,
135474         - /*   860 */    56,  101,   97,   98,  196,  221,  222,  223,  146,  147,
135475         - /*   870 */    57,  171,  152,   22,   26,   19,   20,   49,   22,  179,
135476         - /*   880 */   108,  109,  110,   55,   56,  116,   73,  219,   75,  124,
135477         - /*   890 */   121,  152,  132,  133,  134,  135,  136,  163,   85,  152,
135478         - /*   900 */   232,   97,   98,   47,   48,  237,   55,   56,   98,    5,
135479         - /*   910 */    54,   55,   56,  193,   10,   11,   12,   13,   14,  172,
135480         - /*   920 */   173,   17,   66,   47,   48,   97,   98,  152,  124,  152,
135481         - /*   930 */   196,   55,   56,  186,  124,  152,  106,  160,  152,   83,
135482         - /*   940 */   152,  164,  152,   61,   22,  211,  212,  152,   97,   98,
135483         - /*   950 */   152,   95,   70,   97,   98,  172,  173,  101,  172,  173,
135484         - /*   960 */   172,  173,  172,  173,   60,  181,   62,  172,  173,   47,
135485         - /*   970 */    48,  123,  186,   97,   98,   71,  100,   55,   56,  152,
135486         - /*   980 */   181,  186,   21,  107,  152,  109,   82,  163,  132,  133,
135487         - /*   990 */   134,  135,  136,   89,   16,  207,   92,   93,   19,  172,
135488         - /*  1000 */   173,  169,  170,  195,   55,   56,   12,  152,  132,   30,
135489         - /*  1010 */   134,   47,   48,  186,  206,  225,  152,   95,  114,   97,
135490         - /*  1020 */   196,  245,  246,  101,  152,   38,   39,   40,   41,   42,
135491         - /*  1030 */    43,   44,   45,   46,   47,   48,   49,   50,   51,   52,
135492         - /*  1040 */    53,  152,  163,  219,  152,  141,   97,   98,  193,  152,
135493         - /*  1050 */   152,   57,   91,  164,  132,  133,  134,  152,   55,  152,
135494         - /*  1060 */   152,  237,  230,  152,  103,  193,   88,   73,   90,   75,
135495         - /*  1070 */   172,  173,  183,  152,  185,  196,  152,  172,  173,  172,
135496         - /*  1080 */   173,  217,  152,  172,  173,  152,  107,   22,  152,   24,
135497         - /*  1090 */   193,  112,  152,  172,  173,  152,  132,  242,  134,  152,
135498         - /*  1100 */    97,  140,  152,   92,  152,  172,  173,  152,  172,  173,
135499         - /*  1110 */   152,  100,  172,  173,  152,  172,  173,  152,  140,  172,
135500         - /*  1120 */   173,  152,  172,  173,  172,  173,  152,  172,  173,  152,
135501         - /*  1130 */   172,  173,  152,  152,  172,  173,  152,  172,  173,  213,
135502         - /*  1140 */   152,  172,  173,  152,  152,  152,  172,  173,  152,  172,
135503         - /*  1150 */   173,  152,  172,  173,  152,  210,  172,  173,  152,   26,
135504         - /*  1160 */   172,  173,  152,  172,  173,  172,  173,  152,  172,  173,
135505         - /*  1170 */   152,  172,  173,  152,  172,  173,  152,   59,  172,  173,
135506         - /*  1180 */   152,   63,  172,  173,  152,  193,  152,  152,  152,  152,
135507         - /*  1190 */   172,  173,  152,  172,  173,   77,  172,  173,  152,  152,
135508         - /*  1200 */   172,  173,  152,  152,  172,  173,  172,  173,  172,  173,
135509         - /*  1210 */   152,   22,  172,  173,  152,  152,  152,   22,  172,  173,
135510         - /*  1220 */   152,  152,  152,  172,  173,  152,    7,    8,    9,  163,
135511         - /*  1230 */   172,  173,   22,   23,  172,  173,  172,  173,  166,  167,
135512         - /*  1240 */   172,  173,  172,  173,   55,  172,  173,   22,   23,  108,
135513         - /*  1250 */   109,  110,  217,  152,  217,  166,  167,  163,  163,  163,
135514         - /*  1260 */   163,  163,  196,  130,  217,  211,  212,  217,  116,   23,
135515         - /*  1270 */    22,  101,   26,  121,   23,   23,   23,   26,   26,   26,
135516         - /*  1280 */    23,   23,  112,   26,   26,   37,   97,  100,  101,   55,
135517         - /*  1290 */   196,  196,  196,  196,  196,   23,   23,   55,   26,   26,
135518         - /*  1300 */     7,    8,   23,  152,   23,   26,   96,   26,  132,  132,
135519         - /*  1310 */   134,  134,   23,  152,  152,   26,  152,  122,  152,  191,
135520         - /*  1320 */   152,   96,  234,  152,  152,  152,  152,  152,  197,  210,
135521         - /*  1330 */   152,   97,  152,  152,  210,  233,  210,  198,  150,   97,
135522         - /*  1340 */   184,  201,  239,  214,  214,  201,  239,  180,  214,  227,
135523         - /*  1350 */   200,  198,  155,   67,  243,  176,   69,  175,  175,  175,
135524         - /*  1360 */   122,  159,  159,  240,  159,  240,   22,  220,   27,  130,
135525         - /*  1370 */   201,   18,  159,   18,  189,  158,  158,  220,  192,  159,
135526         - /*  1380 */   137,  236,  192,  192,  192,  189,   74,  189,  159,  235,
135527         - /*  1390 */   159,  158,   22,  177,  201,  201,  159,  107,  158,  177,
135528         - /*  1400 */   159,  174,  158,   76,  174,  182,  174,  106,  182,  125,
135529         - /*  1410 */   174,  107,  177,   22,  159,  216,  215,  137,  159,   53,
135530         - /*  1420 */   216,  176,  215,  174,  174,  216,  215,  215,  174,  229,
135531         - /*  1430 */   216,  129,  224,  177,  126,  229,  127,  177,  128,   25,
135532         - /*  1440 */   162,  226,   26,  161,   13,  153,    6,  153,  151,  151,
135533         - /*  1450 */   151,  151,  205,  165,  178,  178,  165,    4,    3,   22,
135534         - /*  1460 */   165,  142,   15,   94,  202,  204,  203,  201,   16,   23,
135535         - /*  1470 */   249,   23,  120,  249,  246,  111,  131,  123,   20,   16,
135536         - /*  1480 */     1,  125,  123,  111,   56,   64,   37,   37,  131,  122,
135537         - /*  1490 */     1,   37,    5,   37,   22,  107,   26,   80,  140,   80,
135538         - /*  1500 */    87,   72,  107,   20,   24,   19,  112,  105,   23,   79,
135539         - /*  1510 */    22,   79,   22,   22,   22,   58,   22,   79,   23,   68,
135540         - /*  1520 */    23,   23,   26,  116,   22,   26,   23,   22,  122,   23,
135541         - /*  1530 */    23,   56,   64,   22,  124,   26,   26,   64,   64,   23,
135542         - /*  1540 */    23,   23,   23,   11,   23,   22,   26,   23,   22,   24,
135543         - /*  1550 */     1,   23,   22,   26,  251,   24,   23,   22,  122,   23,
135544         - /*  1560 */    23,   22,   15,  122,  122,  122,   23,
135545         -};
135546         -#define YY_SHIFT_USE_DFLT (1567)
       135902  + /*     0 */    19,  115,   19,  117,  118,   24,    1,    2,   27,   79,
       135903  + /*    10 */    80,   81,   82,   83,   84,   85,   86,   87,   88,   89,
       135904  + /*    20 */    90,   91,   92,   93,   94,  144,  145,  146,  147,   58,
       135905  + /*    30 */    49,   50,   79,   80,   81,   82,   22,   84,   85,   86,
       135906  + /*    40 */    87,   88,   89,   90,   91,   92,   93,   94,  221,  222,
       135907  + /*    50 */   223,   70,   71,   72,   73,   74,   75,   76,   77,   78,
       135908  + /*    60 */    79,   80,   81,   82,   94,   84,   85,   86,   87,   88,
       135909  + /*    70 */    89,   90,   91,   92,   93,   94,   19,   94,   97,  108,
       135910  + /*    80 */   109,  110,   99,  100,  101,  102,  103,  104,  105,   32,
       135911  + /*    90 */   119,  120,   78,   27,  152,  112,   93,   94,   41,   88,
       135912  + /*   100 */    89,   90,   91,   92,   93,   94,   49,   50,   84,   85,
       135913  + /*   110 */    86,   87,   88,   89,   90,   91,   92,   93,   94,   58,
       135914  + /*   120 */   157,  119,  120,  163,   68,  163,   65,   70,   71,   72,
       135915  + /*   130 */    73,   74,   75,   76,   77,   78,   79,   80,   81,   82,
       135916  + /*   140 */   152,   84,   85,   86,   87,   88,   89,   90,   91,   92,
       135917  + /*   150 */    93,   94,   19,   97,   88,   89,  196,  101,  196,   26,
       135918  + /*   160 */   172,  173,   96,   97,   98,  210,  100,   22,  152,  108,
       135919  + /*   170 */   109,  110,   27,  107,   27,  109,  221,  222,  223,  219,
       135920  + /*   180 */   238,  219,   49,   50,  152,  169,  170,   54,  132,  133,
       135921  + /*   190 */   134,  228,  232,  171,  231,  207,  208,  237,  132,  237,
       135922  + /*   200 */   134,  179,   19,   70,   71,   72,   73,   74,   75,   76,
       135923  + /*   210 */    77,   78,   79,   80,   81,   82,  152,   84,   85,   86,
       135924  + /*   220 */    87,   88,   89,   90,   91,   92,   93,   94,   27,   65,
       135925  + /*   230 */    30,  152,   49,   50,   34,   52,   90,   91,   92,   93,
       135926  + /*   240 */    94,   96,   97,   98,   97,   22,  230,   27,   48,  217,
       135927  + /*   250 */    27,  172,  173,   70,   71,   72,   73,   74,   75,   76,
       135928  + /*   260 */    77,   78,   79,   80,   81,   82,  172,   84,   85,   86,
       135929  + /*   270 */    87,   88,   89,   90,   91,   92,   93,   94,   19,  148,
       135930  + /*   280 */   149,  152,  218,   24,  152,  154,  207,  156,  172,  152,
       135931  + /*   290 */    22,   68,   27,  152,  163,   27,  164,   96,   97,   98,
       135932  + /*   300 */    99,  172,  173,  102,  103,  104,  169,  170,   49,   50,
       135933  + /*   310 */    90,   88,   89,  152,  113,  186,   96,   97,   98,   96,
       135934  + /*   320 */    97,  160,   57,   27,  101,  164,  137,  196,  139,   70,
       135935  + /*   330 */    71,   72,   73,   74,   75,   76,   77,   78,   79,   80,
       135936  + /*   340 */    81,   82,   11,   84,   85,   86,   87,   88,   89,   90,
       135937  + /*   350 */    91,   92,   93,   94,   19,  132,  133,  134,   23,  218,
       135938  + /*   360 */   152,   96,   97,   98,   96,   97,   98,  230,   99,   22,
       135939  + /*   370 */   152,  102,  103,  104,   27,  244,  152,  152,   27,   26,
       135940  + /*   380 */   152,   22,  113,   65,   49,   50,   27,  194,  195,   58,
       135941  + /*   390 */   172,  173,   96,   97,   98,  185,   65,  172,  173,  206,
       135942  + /*   400 */   172,  173,  190,  191,  186,   70,   71,   72,   73,   74,
       135943  + /*   410 */    75,   76,   77,   78,   79,   80,   81,   82,  175,   84,
       135944  + /*   420 */    85,   86,   87,   88,   89,   90,   91,   92,   93,   94,
       135945  + /*   430 */    19,  175,  207,  208,   23,  207,  208,  119,  120,  108,
       135946  + /*   440 */   109,  110,   27,   96,   97,   98,  116,   96,   97,   98,
       135947  + /*   450 */   152,  121,  152,  179,  180,   96,   97,   98,  250,  106,
       135948  + /*   460 */    49,   50,  188,   19,  221,  222,  223,  168,  169,  170,
       135949  + /*   470 */   172,  173,  172,  173,  250,  124,  172,  221,  222,  223,
       135950  + /*   480 */    26,   70,   71,   72,   73,   74,   75,   76,   77,   78,
       135951  + /*   490 */    79,   80,   81,   82,   50,   84,   85,   86,   87,   88,
       135952  + /*   500 */    89,   90,   91,   92,   93,   94,   19,  207,  208,   12,
       135953  + /*   510 */    23,   96,   97,   98,  221,  222,  223,  194,  195,  152,
       135954  + /*   520 */   199,   23,   19,  225,   26,   28,  152,  152,  152,  206,
       135955  + /*   530 */   209,  164,  190,  191,  241,  152,   49,   50,  152,  124,
       135956  + /*   540 */   152,   44,  219,   46,  152,   21,  172,  173,  172,  173,
       135957  + /*   550 */   183,  107,  185,   16,  163,   58,  112,   70,   71,   72,
       135958  + /*   560 */    73,   74,   75,   76,   77,   78,   79,   80,   81,   82,
       135959  + /*   570 */   152,   84,   85,   86,   87,   88,   89,   90,   91,   92,
       135960  + /*   580 */    93,   94,   19,  207,  130,  152,   23,  196,   64,  152,
       135961  + /*   590 */   172,  173,   22,  152,   24,  152,   98,   27,   61,   96,
       135962  + /*   600 */    63,   26,  211,  212,  186,  172,  173,   49,   50,  172,
       135963  + /*   610 */   173,   23,   49,   50,   26,  172,  173,   88,   89,  186,
       135964  + /*   620 */    24,  238,  124,   27,  238,   22,   23,  103,  187,   26,
       135965  + /*   630 */   152,   73,   74,   70,   71,   72,   73,   74,   75,   76,
       135966  + /*   640 */    77,   78,   79,   80,   81,   82,  152,   84,   85,   86,
       135967  + /*   650 */    87,   88,   89,   90,   91,   92,   93,   94,   19,  101,
       135968  + /*   660 */   152,  132,   23,  134,  140,  152,   12,   97,   36,  168,
       135969  + /*   670 */   169,  170,   69,   98,  152,   22,   23,  140,   50,   26,
       135970  + /*   680 */   172,  173,   28,   51,  152,  172,  173,  193,   49,   50,
       135971  + /*   690 */    22,   59,   24,   97,  172,  173,  152,  152,   44,  124,
       135972  + /*   700 */    46,    0,    1,    2,  172,  173,   22,   23,   19,   70,
       135973  + /*   710 */    71,   72,   73,   74,   75,   76,   77,   78,   79,   80,
       135974  + /*   720 */    81,   82,   69,   84,   85,   86,   87,   88,   89,   90,
       135975  + /*   730 */    91,   92,   93,   94,  152,  107,  152,  193,   49,   50,
       135976  + /*   740 */   181,   22,   23,  111,  108,  109,  110,    7,    8,    9,
       135977  + /*   750 */    16,  247,  248,   69,  172,  173,  172,  173,  152,   70,
       135978  + /*   760 */    71,   72,   73,   74,   75,   76,   77,   78,   79,   80,
       135979  + /*   770 */    81,   82,  152,   84,   85,   86,   87,   88,   89,   90,
       135980  + /*   780 */    91,   92,   93,   94,   19,  152,  242,  152,   69,  152,
       135981  + /*   790 */   166,  167,  172,  173,   32,   61,  152,   63,  152,  193,
       135982  + /*   800 */   152,  152,  152,   41,  152,  172,  173,  172,  173,  172,
       135983  + /*   810 */   173,  152,  152,  152,   49,   50,  172,  173,  172,  173,
       135984  + /*   820 */   172,  173,  172,  173,  172,  173,  132,  138,  134,  152,
       135985  + /*   830 */   152,  172,  173,  172,  173,   70,   71,   72,   73,   74,
       135986  + /*   840 */    75,   76,   77,   78,   79,   80,   81,   82,  152,   84,
       135987  + /*   850 */    85,   86,   87,   88,   89,   90,   91,   92,   93,   94,
       135988  + /*   860 */    19,  152,   22,  152,  195,   24,  152,   27,  172,  173,
       135989  + /*   870 */   193,  193,  152,  152,  152,  206,  152,  217,  152,  152,
       135990  + /*   880 */   152,  172,  173,  172,  173,  152,  172,  173,  152,  152,
       135991  + /*   890 */    49,   50,  172,  173,  172,  173,  172,  173,  172,  173,
       135992  + /*   900 */   172,  173,  152,  138,  152,  172,  173,  108,  109,  110,
       135993  + /*   910 */    19,   70,   71,   72,   73,   74,   75,   76,   77,   78,
       135994  + /*   920 */    79,   80,   81,   82,  152,   84,   85,   86,   87,   88,
       135995  + /*   930 */    89,   90,   91,   92,   93,   94,  152,   97,  152,  152,
       135996  + /*   940 */    49,   50,   26,  193,  172,  173,  152,  152,  152,  146,
       135997  + /*   950 */   147,  132,  152,  134,  217,  181,  172,  173,  172,  173,
       135998  + /*   960 */    19,   70,   71,   72,   73,   74,   75,   76,   77,   78,
       135999  + /*   970 */    79,   80,   81,   82,  152,   84,   85,   86,   87,   88,
       136000  + /*   980 */    89,   90,   91,   92,   93,   94,  152,  193,  152,  193,
       136001  + /*   990 */    49,   50,  181,  193,  172,  173,  166,  167,  245,  246,
       136002  + /*  1000 */   211,  212,  152,   22,  217,  152,  172,  173,  172,  173,
       136003  + /*  1010 */    19,   70,   71,   72,   73,   74,   75,   76,   77,   78,
       136004  + /*  1020 */    79,   80,   81,   82,  152,   84,   85,   86,   87,   88,
       136005  + /*  1030 */    89,   90,   91,   92,   93,   94,  152,  187,  152,  123,
       136006  + /*  1040 */    49,   50,   23,   23,   23,   26,   26,   26,   23,   23,
       136007  + /*  1050 */    23,   26,   26,   26,    7,    8,  172,  173,  172,  173,
       136008  + /*  1060 */    19,   90,   71,   72,   73,   74,   75,   76,   77,   78,
       136009  + /*  1070 */    79,   80,   81,   82,  152,   84,   85,   86,   87,   88,
       136010  + /*  1080 */    89,   90,   91,   92,   93,   94,  152,  116,  152,  217,
       136011  + /*  1090 */    49,   50,  121,   23,  172,  173,   26,  100,  101,   27,
       136012  + /*  1100 */   101,   27,   23,  122,  152,   26,  172,  173,  172,  173,
       136013  + /*  1110 */   152,  112,  163,   72,   73,   74,   75,   76,   77,   78,
       136014  + /*  1120 */    79,   80,   81,   82,  163,   84,   85,   86,   87,   88,
       136015  + /*  1130 */    89,   90,   91,   92,   93,   94,   19,   20,  152,   22,
       136016  + /*  1140 */    23,  152,  163,   65,   27,  196,  163,   19,   20,   23,
       136017  + /*  1150 */    22,  213,   26,   19,   37,   27,  152,  196,  172,  173,
       136018  + /*  1160 */   152,  172,  173,   27,   23,   37,  152,   26,  152,   97,
       136019  + /*  1170 */   152,   97,  210,   56,  163,  196,  163,  163,  100,  196,
       136020  + /*  1180 */   172,  173,   65,  152,   56,   68,  172,  173,  172,  173,
       136021  + /*  1190 */   172,  173,  152,   65,  163,  163,   68,   23,  152,  234,
       136022  + /*  1200 */    26,  152,  152,  172,  173,   88,   89,  196,  152,  196,
       136023  + /*  1210 */   196,  152,   95,   96,   97,   98,   88,   89,  101,  152,
       136024  + /*  1220 */   152,  207,  208,   95,   96,   97,   98,  196,  196,  101,
       136025  + /*  1230 */    96,  233,  152,   97,  152,  152,   19,   20,  207,   22,
       136026  + /*  1240 */   152,  152,  152,  191,   27,  152,  152,  152,  152,  132,
       136027  + /*  1250 */   133,  134,  135,  136,   37,  152,  152,  152,  152,  152,
       136028  + /*  1260 */   132,  133,  134,  135,  136,  210,  197,  210,  210,  198,
       136029  + /*  1270 */   150,  184,  239,   56,  201,  214,  214,  201,  239,  180,
       136030  + /*  1280 */   214,  227,  198,   38,  176,   68,  175,  175,  175,  122,
       136031  + /*  1290 */   155,  200,  159,   19,   20,   40,   22,  159,  159,   22,
       136032  + /*  1300 */    70,   27,  130,  243,  240,   88,   89,   90,  189,   18,
       136033  + /*  1310 */   201,   37,   95,   96,   97,   98,  192,    5,  101,  192,
       136034  + /*  1320 */   220,  240,   10,   11,   12,   13,   14,  159,   18,   17,
       136035  + /*  1330 */    56,  158,  192,  201,  192,  220,  189,  189,  201,  159,
       136036  + /*  1340 */   158,  137,   68,   31,   45,   33,  236,  159,  159,  132,
       136037  + /*  1350 */   133,  134,  135,  136,   42,  158,  235,   22,  177,  159,
       136038  + /*  1360 */   158,  158,   88,   89,  159,  107,  174,   55,  177,   95,
       136039  + /*  1370 */    96,   97,   98,  174,   62,  101,   47,   65,   66,  106,
       136040  + /*  1380 */   174,  125,   19,   20,  174,   22,  177,  176,  174,  182,
       136041  + /*  1390 */    27,  216,  174,  174,  182,  107,  159,   22,  215,  215,
       136042  + /*  1400 */    37,  216,  216,  216,  137,  215,  132,  133,  134,  135,
       136043  + /*  1410 */   136,  215,  159,  177,   94,  177,  129,  224,  205,   56,
       136044  + /*  1420 */   226,  126,  128,  203,  229,  204,  114,  229,  127,  202,
       136045  + /*  1430 */   201,   68,   25,  162,   26,   13,  161,  153,  153,    6,
       136046  + /*  1440 */   151,  151,  178,  151,  151,  165,  165,  178,  165,    4,
       136047  + /*  1450 */   249,   88,   89,  141,    3,  142,   22,  249,   95,   96,
       136048  + /*  1460 */    97,   98,  246,   15,  101,   67,   16,   23,  120,   23,
       136049  + /*  1470 */   131,  111,  123,   20,   16,  125,    1,  123,  131,   78,
       136050  + /*  1480 */    78,   78,   78,  111,   96,    1,  122,   35,    5,   22,
       136051  + /*  1490 */   107,  140,   53,   53,   26,  132,  133,  134,  135,  136,
       136052  + /*  1500 */    43,   60,  107,   24,  112,   20,   19,   52,   22,   29,
       136053  + /*  1510 */   105,   22,   22,   52,   23,   22,   22,   52,   23,   23,
       136054  + /*  1520 */    39,   23,  116,   26,   22,   26,   23,   22,   96,   23,
       136055  + /*  1530 */    23,  122,   22,   24,  124,   35,   35,   26,   26,   35,
       136056  + /*  1540 */    23,   23,   23,   23,   11,   23,   22,   26,   23,   22,
       136057  + /*  1550 */   122,   23,   26,   22,   24,   23,   22,  122,   23,   23,
       136058  + /*  1560 */    22,   15,   23,    1,  122,  122,
       136059  +};
       136060  +#define YY_SHIFT_USE_DFLT (1566)
135547 136061   #define YY_SHIFT_COUNT    (455)
135548         -#define YY_SHIFT_MIN      (-94)
135549         -#define YY_SHIFT_MAX      (1549)
       136062  +#define YY_SHIFT_MIN      (-114)
       136063  +#define YY_SHIFT_MAX      (1562)
135550 136064   static const short yy_shift_ofst[] = {
135551         - /*     0 */    40,  599,  904,  612,  760,  760,  760,  760,  725,  -19,
135552         - /*    10 */    16,   16,  100,  760,  760,  760,  760,  760,  760,  760,
135553         - /*    20 */   876,  876,  573,  542,  719,  600,   61,  137,  172,  207,
135554         - /*    30 */   242,  277,  312,  347,  382,  417,  459,  459,  459,  459,
135555         - /*    40 */   459,  459,  459,  459,  459,  459,  459,  459,  459,  459,
135556         - /*    50 */   459,  459,  459,  494,  459,  529,  564,  564,  705,  760,
135557         - /*    60 */   760,  760,  760,  760,  760,  760,  760,  760,  760,  760,
135558         - /*    70 */   760,  760,  760,  760,  760,  760,  760,  760,  760,  760,
135559         - /*    80 */   760,  760,  760,  760,  760,  760,  760,  760,  760,  760,
135560         - /*    90 */   856,  760,  760,  760,  760,  760,  760,  760,  760,  760,
135561         - /*   100 */   760,  760,  760,  760,  987,  746,  746,  746,  746,  746,
135562         - /*   110 */   801,   23,   32,  949,  961,  979,  964,  964,  949,   73,
135563         - /*   120 */   113,  -51, 1567, 1567, 1567,  536,  536,  536,   99,   99,
135564         - /*   130 */   813,  813,  667,  205,  240,  949,  949,  949,  949,  949,
135565         - /*   140 */   949,  949,  949,  949,  949,  949,  949,  949,  949,  949,
135566         - /*   150 */   949,  949,  949,  949,  949,  332, 1011,  422,  422,  113,
135567         - /*   160 */    30,   30,   30,   30,   30,   30, 1567, 1567, 1567,  922,
135568         - /*   170 */   -94,  -94,  384,  613,  828,  420,  765,  804,  851,  949,
135569         - /*   180 */   949,  949,  949,  949,  949,  949,  949,  949,  949,  949,
135570         - /*   190 */   949,  949,  949,  949,  949,  672,  672,  672,  949,  949,
135571         - /*   200 */   657,  949,  949,  949,  -18,  949,  949,  994,  949,  949,
135572         - /*   210 */   949,  949,  949,  949,  949,  949,  949,  949,  772, 1118,
135573         - /*   220 */   712,  712,  712,  810,   45,  769, 1219, 1133,  418,  418,
135574         - /*   230 */   569, 1133,  569,  830,  607,  663,  882,  418,  693,  882,
135575         - /*   240 */   882,  848, 1152, 1065, 1286, 1238, 1238, 1287, 1287, 1238,
135576         - /*   250 */  1344, 1341, 1239, 1353, 1353, 1353, 1353, 1238, 1355, 1239,
135577         - /*   260 */  1344, 1341, 1341, 1239, 1238, 1355, 1243, 1312, 1238, 1238,
135578         - /*   270 */  1355, 1370, 1238, 1355, 1238, 1355, 1370, 1290, 1290, 1290,
135579         - /*   280 */  1327, 1370, 1290, 1301, 1290, 1327, 1290, 1290, 1284, 1304,
135580         - /*   290 */  1284, 1304, 1284, 1304, 1284, 1304, 1238, 1391, 1238, 1280,
135581         - /*   300 */  1370, 1366, 1366, 1370, 1302, 1308, 1310, 1309, 1239, 1414,
135582         - /*   310 */  1416, 1431, 1431, 1440, 1440, 1440, 1440, 1567, 1567, 1567,
135583         - /*   320 */  1567, 1567, 1567, 1567, 1567,  519,  978, 1210, 1225,  104,
135584         - /*   330 */  1141, 1189, 1246, 1248, 1251, 1252, 1253, 1257, 1258, 1273,
135585         - /*   340 */  1003, 1187, 1293, 1170, 1272, 1279, 1234, 1281, 1176, 1177,
135586         - /*   350 */  1289, 1242, 1195, 1453, 1455, 1437, 1319, 1447, 1369, 1452,
135587         - /*   360 */  1446, 1448, 1352, 1345, 1364, 1354, 1458, 1356, 1463, 1479,
135588         - /*   370 */  1359, 1357, 1449, 1450, 1454, 1456, 1372, 1428, 1421, 1367,
135589         - /*   380 */  1489, 1487, 1472, 1388, 1358, 1417, 1470, 1419, 1413, 1429,
135590         - /*   390 */  1395, 1480, 1483, 1486, 1394, 1402, 1488, 1430, 1490, 1491,
135591         - /*   400 */  1485, 1492, 1432, 1457, 1494, 1438, 1451, 1495, 1497, 1498,
135592         - /*   410 */  1496, 1407, 1502, 1503, 1505, 1499, 1406, 1506, 1507, 1475,
135593         - /*   420 */  1468, 1511, 1410, 1509, 1473, 1510, 1474, 1516, 1509, 1517,
135594         - /*   430 */  1518, 1519, 1520, 1521, 1523, 1532, 1524, 1526, 1525, 1527,
135595         - /*   440 */  1528, 1530, 1531, 1527, 1533, 1535, 1536, 1537, 1539, 1436,
135596         - /*   450 */  1441, 1442, 1443, 1543, 1547, 1549,
135597         -};
135598         -#define YY_REDUCE_USE_DFLT (-130)
       136065  + /*     0 */     5, 1117, 1312, 1128, 1274, 1274, 1274, 1274,   61,  -19,
       136066  + /*    10 */    57,   57,  183, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
       136067  + /*    20 */    66,   66,  201,  -29,  331,  318,  133,  259,  335,  411,
       136068  + /*    30 */   487,  563,  639,  689,  765,  841,  891,  891,  891,  891,
       136069  + /*    40 */   891,  891,  891,  891,  891,  891,  891,  891,  891,  891,
       136070  + /*    50 */   891,  891,  891,  941,  891,  991, 1041, 1041, 1217, 1274,
       136071  + /*    60 */  1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
       136072  + /*    70 */  1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
       136073  + /*    80 */  1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
       136074  + /*    90 */  1363, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
       136075  + /*   100 */  1274, 1274, 1274, 1274,  -70,  -47,  -47,  -47,  -47,  -47,
       136076  + /*   110 */    24,   11,  146,  296,  524,  444,  529,  529,  296,    3,
       136077  + /*   120 */     2,  -30, 1566, 1566, 1566,  -17,  -17,  -17,  145,  145,
       136078  + /*   130 */   497,  497,  265,  603,  653,  296,  296,  296,  296,  296,
       136079  + /*   140 */   296,  296,  296,  296,  296,  296,  296,  296,  296,  296,
       136080  + /*   150 */   296,  296,  296,  296,  296,  701, 1078,  147,  147,    2,
       136081  + /*   160 */   164,  164,  164,  164,  164,  164, 1566, 1566, 1566,  223,
       136082  + /*   170 */    56,   56,  268,  269,  220,  347,  351,  415,  359,  296,
       136083  + /*   180 */   296,  296,  296,  296,  296,  296,  296,  296,  296,  296,
       136084  + /*   190 */   296,  296,  296,  296,  296,  632,  632,  632,  296,  296,
       136085  + /*   200 */   498,  296,  296,  296,  570,  296,  296,  654,  296,  296,
       136086  + /*   210 */   296,  296,  296,  296,  296,  296,  296,  296,  636,  200,
       136087  + /*   220 */   596,  596,  596,  575, -114,  971,  740,  454,  503,  503,
       136088  + /*   230 */  1134,  454, 1134,  353,  588,  628,  762,  503,  189,  762,
       136089  + /*   240 */   762,  916,  330,  668, 1245, 1167, 1167, 1255, 1255, 1167,
       136090  + /*   250 */  1277, 1230, 1172, 1291, 1291, 1291, 1291, 1167, 1310, 1172,
       136091  + /*   260 */  1277, 1230, 1230, 1172, 1167, 1310, 1204, 1299, 1167, 1167,
       136092  + /*   270 */  1310, 1335, 1167, 1310, 1167, 1310, 1335, 1258, 1258, 1258,
       136093  + /*   280 */  1329, 1335, 1258, 1273, 1258, 1329, 1258, 1258, 1256, 1288,
       136094  + /*   290 */  1256, 1288, 1256, 1288, 1256, 1288, 1167, 1375, 1167, 1267,
       136095  + /*   300 */  1335, 1320, 1320, 1335, 1287, 1295, 1294, 1301, 1172, 1407,
       136096  + /*   310 */  1408, 1422, 1422, 1433, 1433, 1433, 1433, 1566, 1566, 1566,
       136097  + /*   320 */  1566, 1566, 1566, 1566, 1566,  558,  537,  684,  719,  734,
       136098  + /*   330 */   799,  840, 1019,   14, 1020, 1021, 1025, 1026, 1027, 1070,
       136099  + /*   340 */  1072,  997, 1047,  999, 1079, 1126, 1074, 1141,  694,  819,
       136100  + /*   350 */  1174, 1136,  981, 1445, 1451, 1434, 1313, 1448, 1398, 1450,
       136101  + /*   360 */  1444, 1446, 1348, 1339, 1360, 1349, 1453, 1350, 1458, 1475,
       136102  + /*   370 */  1354, 1347, 1401, 1402, 1403, 1404, 1372, 1388, 1452, 1364,
       136103  + /*   380 */  1484, 1483, 1467, 1383, 1351, 1439, 1468, 1440, 1441, 1457,
       136104  + /*   390 */  1395, 1479, 1485, 1487, 1392, 1405, 1486, 1455, 1489, 1490,
       136105  + /*   400 */  1491, 1493, 1461, 1480, 1494, 1465, 1481, 1495, 1496, 1498,
       136106  + /*   410 */  1497, 1406, 1502, 1503, 1505, 1499, 1409, 1506, 1507, 1432,
       136107  + /*   420 */  1500, 1510, 1410, 1511, 1501, 1512, 1504, 1517, 1511, 1518,
       136108  + /*   430 */  1519, 1520, 1521, 1522, 1524, 1533, 1525, 1527, 1509, 1526,
       136109  + /*   440 */  1528, 1531, 1530, 1526, 1532, 1534, 1535, 1536, 1538, 1428,
       136110  + /*   450 */  1435, 1442, 1443, 1539, 1546, 1562,
       136111  +};
       136112  +#define YY_REDUCE_USE_DFLT (-174)
135599 136113   #define YY_REDUCE_COUNT (324)
135600         -#define YY_REDUCE_MIN   (-129)
135601         -#define YY_REDUCE_MAX   (1300)
       136114  +#define YY_REDUCE_MIN   (-173)
       136115  +#define YY_REDUCE_MAX   (1293)
135602 136116   static const short yy_reduce_ofst[] = {
135603         - /*     0 */   -29,  566,  525,  605,  -49,  307,  491,  533,  668,  435,
135604         - /*    10 */   601,  644,  148,  747,  786,  795,  419,  788,  827,  790,
135605         - /*    20 */   454,  832,  889,  495,  824,  734,   76,   76,   76,   76,
135606         - /*    30 */    76,   76,   76,   76,   76,   76,   76,   76,   76,   76,
135607         - /*    40 */    76,   76,   76,   76,   76,   76,   76,   76,   76,   76,
135608         - /*    50 */    76,   76,   76,   76,   76,   76,   76,   76,  783,  898,
135609         - /*    60 */   905,  907,  911,  921,  933,  936,  940,  943,  947,  950,
135610         - /*    70 */   952,  955,  958,  962,  965,  969,  974,  977,  980,  984,
135611         - /*    80 */   988,  991,  993,  996,  999, 1002, 1006, 1010, 1018, 1021,
135612         - /*    90 */  1024, 1028, 1032, 1034, 1036, 1040, 1046, 1051, 1058, 1062,
135613         - /*   100 */  1064, 1068, 1070, 1073,   76,   76,   76,   76,   76,   76,
135614         - /*   110 */    76,   76,   76,  855,   36,  523,  235,  416,  777,   76,
135615         - /*   120 */   278,   76,   76,   76,   76,  700,  700,  700,  150,  220,
135616         - /*   130 */   147,  217,  221,  306,  306,  611,    5,  535,  556,  620,
135617         - /*   140 */   720,  872,  897,  116,  864,  349, 1035, 1037,  404, 1047,
135618         - /*   150 */   992, -129, 1050,  492,   62,  722,  879, 1072, 1089,  808,
135619         - /*   160 */  1066, 1094, 1095, 1096, 1097, 1098,  776, 1054,  557,   57,
135620         - /*   170 */   112,  131,  167,  182,  250,  272,  291,  331,  364,  438,
135621         - /*   180 */   497,  517,  591,  653,  690,  739,  775,  798,  892,  908,
135622         - /*   190 */   924,  930, 1015, 1063, 1069,  355,  784,  799,  981, 1101,
135623         - /*   200 */   926, 1151, 1161, 1162,  945, 1164, 1166, 1128, 1168, 1171,
135624         - /*   210 */  1172,  250, 1173, 1174, 1175, 1178, 1180, 1181, 1088, 1102,
135625         - /*   220 */  1119, 1124, 1126,  926, 1131, 1139, 1188, 1140, 1129, 1130,
135626         - /*   230 */  1103, 1144, 1107, 1179, 1156, 1167, 1182, 1134, 1122, 1183,
135627         - /*   240 */  1184, 1150, 1153, 1197, 1111, 1202, 1203, 1123, 1125, 1205,
135628         - /*   250 */  1147, 1185, 1169, 1186, 1190, 1191, 1192, 1213, 1217, 1193,
135629         - /*   260 */  1157, 1196, 1198, 1194, 1220, 1218, 1145, 1154, 1229, 1231,
135630         - /*   270 */  1233, 1216, 1237, 1240, 1241, 1244, 1222, 1227, 1230, 1232,
135631         - /*   280 */  1223, 1235, 1236, 1245, 1249, 1226, 1250, 1254, 1199, 1201,
135632         - /*   290 */  1204, 1207, 1209, 1211, 1214, 1212, 1255, 1208, 1259, 1215,
135633         - /*   300 */  1256, 1200, 1206, 1260, 1247, 1261, 1263, 1262, 1266, 1278,
135634         - /*   310 */  1282, 1292, 1294, 1297, 1298, 1299, 1300, 1221, 1224, 1228,
135635         - /*   320 */  1288, 1291, 1276, 1277, 1295,
       136117  + /*     0 */  -119, 1014,  131, 1031,  -12,  225,  228,  300,  -40,  -45,
       136118  + /*    10 */   243,  256,  293,  129,  218,  418,   79,  376,  433,  298,
       136119  + /*    20 */    16,  137,  367,  323,  -38,  391, -173, -173, -173, -173,
       136120  + /*    30 */  -173, -173, -173, -173, -173, -173, -173, -173, -173, -173,
       136121  + /*    40 */  -173, -173, -173, -173, -173, -173, -173, -173, -173, -173,
       136122  + /*    50 */  -173, -173, -173, -173, -173, -173, -173, -173,  374,  437,
       136123  + /*    60 */   443,  508,  513,  522,  532,  582,  584,  620,  633,  635,
       136124  + /*    70 */   637,  644,  646,  648,  650,  652,  659,  661,  696,  709,
       136125  + /*    80 */   711,  714,  720,  722,  724,  726,  728,  733,  772,  784,
       136126  + /*    90 */   786,  822,  834,  836,  884,  886,  922,  934,  936,  986,
       136127  + /*   100 */   989, 1008, 1016, 1018, -173, -173, -173, -173, -173, -173,
       136128  + /*   110 */  -173, -173, -173,  544,  -37,  274,  299,  501,  161, -173,
       136129  + /*   120 */   193, -173, -173, -173, -173,   22,   22,   22,   64,  141,
       136130  + /*   130 */   212,  342,  208,  504,  504,  132,  494,  606,  677,  678,
       136131  + /*   140 */   750,  794,  796,  -58,   32,  383,  660,  737,  386,  787,
       136132  + /*   150 */   800,  441,  872,  224,  850,  803,  949,  624,  830,  669,
       136133  + /*   160 */   961,  979,  983, 1011, 1013, 1032,  753,  789,  321,   94,
       136134  + /*   170 */   116,  304,  375,  210,  388,  392,  478,  545,  649,  721,
       136135  + /*   180 */   727,  736,  752,  795,  853,  952,  958, 1004, 1040, 1046,
       136136  + /*   190 */  1049, 1050, 1056, 1059, 1067,  559,  774,  811, 1068, 1080,
       136137  + /*   200 */   938, 1082, 1083, 1088,  962, 1089, 1090, 1052, 1093, 1094,
       136138  + /*   210 */  1095,  388, 1096, 1103, 1104, 1105, 1106, 1107,  965,  998,
       136139  + /*   220 */  1055, 1057, 1058,  938, 1069, 1071, 1120, 1073, 1061, 1062,
       136140  + /*   230 */  1033, 1076, 1039, 1108, 1087, 1099, 1111, 1066, 1054, 1112,
       136141  + /*   240 */  1113, 1091, 1084, 1135, 1060, 1133, 1138, 1064, 1081, 1139,
       136142  + /*   250 */  1100, 1119, 1109, 1124, 1127, 1140, 1142, 1168, 1173, 1132,
       136143  + /*   260 */  1115, 1147, 1148, 1137, 1180, 1182, 1110, 1121, 1188, 1189,
       136144  + /*   270 */  1197, 1181, 1200, 1202, 1205, 1203, 1191, 1192, 1199, 1206,
       136145  + /*   280 */  1207, 1209, 1210, 1211, 1214, 1212, 1218, 1219, 1175, 1183,
       136146  + /*   290 */  1185, 1184, 1186, 1190, 1187, 1196, 1237, 1193, 1253, 1194,
       136147  + /*   300 */  1236, 1195, 1198, 1238, 1213, 1221, 1220, 1227, 1229, 1271,
       136148  + /*   310 */  1275, 1284, 1285, 1289, 1290, 1292, 1293, 1201, 1208, 1216,
       136149  + /*   320 */  1280, 1281, 1264, 1269, 1283,
135636 136150   };
135637 136151   static const YYACTIONTYPE yy_default[] = {
135638 136152    /*     0 */  1280, 1270, 1270, 1270, 1202, 1202, 1202, 1202, 1270, 1096,
135639 136153    /*    10 */  1125, 1125, 1254, 1332, 1332, 1332, 1332, 1332, 1332, 1201,
135640 136154    /*    20 */  1332, 1332, 1332, 1332, 1270, 1100, 1131, 1332, 1332, 1332,
135641 136155    /*    30 */  1332, 1203, 1204, 1332, 1332, 1332, 1253, 1255, 1141, 1140,
135642 136156    /*    40 */  1139, 1138, 1236, 1112, 1136, 1129, 1133, 1203, 1197, 1198,
................................................................................
135698 136212   ** to revert to identifiers if they keyword does not apply in the context where
135699 136213   ** it appears.
135700 136214   */
135701 136215   #ifdef YYFALLBACK
135702 136216   static const YYCODETYPE yyFallback[] = {
135703 136217       0,  /*          $ => nothing */
135704 136218       0,  /*       SEMI => nothing */
135705         -   55,  /*    EXPLAIN => ID */
135706         -   55,  /*      QUERY => ID */
135707         -   55,  /*       PLAN => ID */
135708         -   55,  /*      BEGIN => ID */
       136219  +   27,  /*    EXPLAIN => ID */
       136220  +   27,  /*      QUERY => ID */
       136221  +   27,  /*       PLAN => ID */
       136222  +   27,  /*      BEGIN => ID */
135709 136223       0,  /* TRANSACTION => nothing */
135710         -   55,  /*   DEFERRED => ID */
135711         -   55,  /*  IMMEDIATE => ID */
135712         -   55,  /*  EXCLUSIVE => ID */
       136224  +   27,  /*   DEFERRED => ID */
       136225  +   27,  /*  IMMEDIATE => ID */
       136226  +   27,  /*  EXCLUSIVE => ID */
135713 136227       0,  /*     COMMIT => nothing */
135714         -   55,  /*        END => ID */
135715         -   55,  /*   ROLLBACK => ID */
135716         -   55,  /*  SAVEPOINT => ID */
135717         -   55,  /*    RELEASE => ID */
       136228  +   27,  /*        END => ID */
       136229  +   27,  /*   ROLLBACK => ID */
       136230  +   27,  /*  SAVEPOINT => ID */
       136231  +   27,  /*    RELEASE => ID */
135718 136232       0,  /*         TO => nothing */
135719 136233       0,  /*      TABLE => nothing */
135720 136234       0,  /*     CREATE => nothing */
135721         -   55,  /*         IF => ID */
       136235  +   27,  /*         IF => ID */
135722 136236       0,  /*        NOT => nothing */
135723 136237       0,  /*     EXISTS => nothing */
135724         -   55,  /*       TEMP => ID */
       136238  +   27,  /*       TEMP => ID */
135725 136239       0,  /*         LP => nothing */
135726 136240       0,  /*         RP => nothing */
135727 136241       0,  /*         AS => nothing */
135728         -   55,  /*    WITHOUT => ID */
       136242  +   27,  /*    WITHOUT => ID */
135729 136243       0,  /*      COMMA => nothing */
135730         -    0,  /*         OR => nothing */
135731         -    0,  /*        AND => nothing */
135732         -    0,  /*         IS => nothing */
135733         -   55,  /*      MATCH => ID */
135734         -   55,  /*    LIKE_KW => ID */
135735         -    0,  /*    BETWEEN => nothing */
135736         -    0,  /*         IN => nothing */
135737         -    0,  /*     ISNULL => nothing */
135738         -    0,  /*    NOTNULL => nothing */
135739         -    0,  /*         NE => nothing */
135740         -    0,  /*         EQ => nothing */
135741         -    0,  /*         GT => nothing */
135742         -    0,  /*         LE => nothing */
135743         -    0,  /*         LT => nothing */
135744         -    0,  /*         GE => nothing */
135745         -    0,  /*     ESCAPE => nothing */
135746         -    0,  /*     BITAND => nothing */
135747         -    0,  /*      BITOR => nothing */
135748         -    0,  /*     LSHIFT => nothing */
135749         -    0,  /*     RSHIFT => nothing */
135750         -    0,  /*       PLUS => nothing */
135751         -    0,  /*      MINUS => nothing */
135752         -    0,  /*       STAR => nothing */
135753         -    0,  /*      SLASH => nothing */
135754         -    0,  /*        REM => nothing */
135755         -    0,  /*     CONCAT => nothing */
135756         -    0,  /*    COLLATE => nothing */
135757         -    0,  /*     BITNOT => nothing */
135758 136244       0,  /*         ID => nothing */
135759         -    0,  /*    INDEXED => nothing */
135760         -   55,  /*      ABORT => ID */
135761         -   55,  /*     ACTION => ID */
135762         -   55,  /*      AFTER => ID */
135763         -   55,  /*    ANALYZE => ID */
135764         -   55,  /*        ASC => ID */
135765         -   55,  /*     ATTACH => ID */
135766         -   55,  /*     BEFORE => ID */
135767         -   55,  /*         BY => ID */
135768         -   55,  /*    CASCADE => ID */
135769         -   55,  /*       CAST => ID */
135770         -   55,  /*   COLUMNKW => ID */
135771         -   55,  /*   CONFLICT => ID */
135772         -   55,  /*   DATABASE => ID */
135773         -   55,  /*       DESC => ID */
135774         -   55,  /*     DETACH => ID */
135775         -   55,  /*       EACH => ID */
135776         -   55,  /*       FAIL => ID */
135777         -   55,  /*        FOR => ID */
135778         -   55,  /*     IGNORE => ID */
135779         -   55,  /*  INITIALLY => ID */
135780         -   55,  /*    INSTEAD => ID */
135781         -   55,  /*         NO => ID */
135782         -   55,  /*        KEY => ID */
135783         -   55,  /*         OF => ID */
135784         -   55,  /*     OFFSET => ID */
135785         -   55,  /*     PRAGMA => ID */
135786         -   55,  /*      RAISE => ID */
135787         -   55,  /*  RECURSIVE => ID */
135788         -   55,  /*    REPLACE => ID */
135789         -   55,  /*   RESTRICT => ID */
135790         -   55,  /*        ROW => ID */
135791         -   55,  /*    TRIGGER => ID */
135792         -   55,  /*     VACUUM => ID */
135793         -   55,  /*       VIEW => ID */
135794         -   55,  /*    VIRTUAL => ID */
135795         -   55,  /*       WITH => ID */
135796         -   55,  /*    REINDEX => ID */
135797         -   55,  /*     RENAME => ID */
135798         -   55,  /*   CTIME_KW => ID */
       136245  +   27,  /*      ABORT => ID */
       136246  +   27,  /*     ACTION => ID */
       136247  +   27,  /*      AFTER => ID */
       136248  +   27,  /*    ANALYZE => ID */
       136249  +   27,  /*        ASC => ID */
       136250  +   27,  /*     ATTACH => ID */
       136251  +   27,  /*     BEFORE => ID */
       136252  +   27,  /*         BY => ID */
       136253  +   27,  /*    CASCADE => ID */
       136254  +   27,  /*       CAST => ID */
       136255  +   27,  /*   COLUMNKW => ID */
       136256  +   27,  /*   CONFLICT => ID */
       136257  +   27,  /*   DATABASE => ID */
       136258  +   27,  /*       DESC => ID */
       136259  +   27,  /*     DETACH => ID */
       136260  +   27,  /*       EACH => ID */
       136261  +   27,  /*       FAIL => ID */
       136262  +   27,  /*        FOR => ID */
       136263  +   27,  /*     IGNORE => ID */
       136264  +   27,  /*  INITIALLY => ID */
       136265  +   27,  /*    INSTEAD => ID */
       136266  +   27,  /*    LIKE_KW => ID */
       136267  +   27,  /*      MATCH => ID */
       136268  +   27,  /*         NO => ID */
       136269  +   27,  /*        KEY => ID */
       136270  +   27,  /*         OF => ID */
       136271  +   27,  /*     OFFSET => ID */
       136272  +   27,  /*     PRAGMA => ID */
       136273  +   27,  /*      RAISE => ID */
       136274  +   27,  /*  RECURSIVE => ID */
       136275  +   27,  /*    REPLACE => ID */
       136276  +   27,  /*   RESTRICT => ID */
       136277  +   27,  /*        ROW => ID */
       136278  +   27,  /*    TRIGGER => ID */
       136279  +   27,  /*     VACUUM => ID */
       136280  +   27,  /*       VIEW => ID */
       136281  +   27,  /*    VIRTUAL => ID */
       136282  +   27,  /*       WITH => ID */
       136283  +   27,  /*    REINDEX => ID */
       136284  +   27,  /*     RENAME => ID */
       136285  +   27,  /*   CTIME_KW => ID */
135799 136286   };
135800 136287   #endif /* YYFALLBACK */
135801 136288   
135802 136289   /* The following structure represents a single element of the
135803 136290   ** parser's stack.  Information stored includes:
135804 136291   **
135805 136292   **   +  The state number for the parser at this level of the stack.
................................................................................
135883 136370   static const char *const yyTokenName[] = { 
135884 136371     "$",             "SEMI",          "EXPLAIN",       "QUERY",       
135885 136372     "PLAN",          "BEGIN",         "TRANSACTION",   "DEFERRED",    
135886 136373     "IMMEDIATE",     "EXCLUSIVE",     "COMMIT",        "END",         
135887 136374     "ROLLBACK",      "SAVEPOINT",     "RELEASE",       "TO",          
135888 136375     "TABLE",         "CREATE",        "IF",            "NOT",         
135889 136376     "EXISTS",        "TEMP",          "LP",            "RP",          
135890         -  "AS",            "WITHOUT",       "COMMA",         "OR",          
135891         -  "AND",           "IS",            "MATCH",         "LIKE_KW",     
135892         -  "BETWEEN",       "IN",            "ISNULL",        "NOTNULL",     
135893         -  "NE",            "EQ",            "GT",            "LE",          
135894         -  "LT",            "GE",            "ESCAPE",        "BITAND",      
135895         -  "BITOR",         "LSHIFT",        "RSHIFT",        "PLUS",        
135896         -  "MINUS",         "STAR",          "SLASH",         "REM",         
135897         -  "CONCAT",        "COLLATE",       "BITNOT",        "ID",          
135898         -  "INDEXED",       "ABORT",         "ACTION",        "AFTER",       
135899         -  "ANALYZE",       "ASC",           "ATTACH",        "BEFORE",      
135900         -  "BY",            "CASCADE",       "CAST",          "COLUMNKW",    
135901         -  "CONFLICT",      "DATABASE",      "DESC",          "DETACH",      
135902         -  "EACH",          "FAIL",          "FOR",           "IGNORE",      
135903         -  "INITIALLY",     "INSTEAD",       "NO",            "KEY",         
135904         -  "OF",            "OFFSET",        "PRAGMA",        "RAISE",       
135905         -  "RECURSIVE",     "REPLACE",       "RESTRICT",      "ROW",         
135906         -  "TRIGGER",       "VACUUM",        "VIEW",          "VIRTUAL",     
135907         -  "WITH",          "REINDEX",       "RENAME",        "CTIME_KW",    
135908         -  "ANY",           "STRING",        "JOIN_KW",       "CONSTRAINT",  
       136377  +  "AS",            "WITHOUT",       "COMMA",         "ID",          
       136378  +  "ABORT",         "ACTION",        "AFTER",         "ANALYZE",     
       136379  +  "ASC",           "ATTACH",        "BEFORE",        "BY",          
       136380  +  "CASCADE",       "CAST",          "COLUMNKW",      "CONFLICT",    
       136381  +  "DATABASE",      "DESC",          "DETACH",        "EACH",        
       136382  +  "FAIL",          "FOR",           "IGNORE",        "INITIALLY",   
       136383  +  "INSTEAD",       "LIKE_KW",       "MATCH",         "NO",          
       136384  +  "KEY",           "OF",            "OFFSET",        "PRAGMA",      
       136385  +  "RAISE",         "RECURSIVE",     "REPLACE",       "RESTRICT",    
       136386  +  "ROW",           "TRIGGER",       "VACUUM",        "VIEW",        
       136387  +  "VIRTUAL",       "WITH",          "REINDEX",       "RENAME",      
       136388  +  "CTIME_KW",      "ANY",           "OR",            "AND",         
       136389  +  "IS",            "BETWEEN",       "IN",            "ISNULL",      
       136390  +  "NOTNULL",       "NE",            "EQ",            "GT",          
       136391  +  "LE",            "LT",            "GE",            "ESCAPE",      
       136392  +  "BITAND",        "BITOR",         "LSHIFT",        "RSHIFT",      
       136393  +  "PLUS",          "MINUS",         "STAR",          "SLASH",       
       136394  +  "REM",           "CONCAT",        "COLLATE",       "BITNOT",      
       136395  +  "INDEXED",       "STRING",        "JOIN_KW",       "CONSTRAINT",  
135909 136396     "DEFAULT",       "NULL",          "PRIMARY",       "UNIQUE",      
135910 136397     "CHECK",         "REFERENCES",    "AUTOINCR",      "ON",          
135911 136398     "INSERT",        "DELETE",        "UPDATE",        "SET",         
135912 136399     "DEFERRABLE",    "FOREIGN",       "DROP",          "UNION",       
135913 136400     "ALL",           "EXCEPT",        "INTERSECT",     "SELECT",      
135914 136401     "VALUES",        "DISTINCT",      "DOT",           "FROM",        
135915 136402     "JOIN",          "USING",         "ORDER",         "GROUP",       
................................................................................
139378 139865     void *pEngine;                  /* The LEMON-generated LALR(1) parser */
139379 139866     int n = 0;                      /* Length of the next token token */
139380 139867     int tokenType;                  /* type of the next token */
139381 139868     int lastTokenParsed = -1;       /* type of the previous token */
139382 139869     sqlite3 *db = pParse->db;       /* The database connection */
139383 139870     int mxSqlLen;                   /* Max length of an SQL string */
139384 139871   #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
139385         -  unsigned char zSpace[sizeof(yyParser)];  /* Space for parser engine object */
       139872  +  yyParser sEngine;    /* Space to hold the Lemon-generated Parser object */
139386 139873   #endif
139387 139874   
139388 139875     assert( zSql!=0 );
139389 139876     mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
139390 139877     if( db->nVdbeActive==0 ){
139391 139878       db->u1.isInterrupted = 0;
139392 139879     }
139393 139880     pParse->rc = SQLITE_OK;
139394 139881     pParse->zTail = zSql;
139395 139882     assert( pzErrMsg!=0 );
139396 139883     /* sqlite3ParserTrace(stdout, "parser: "); */
139397 139884   #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
139398         -  pEngine = zSpace;
       139885  +  pEngine = &sEngine;
139399 139886     sqlite3ParserInit(pEngine);
139400 139887   #else
139401 139888     pEngine = sqlite3ParserAlloc(sqlite3Malloc);
139402 139889     if( pEngine==0 ){
139403 139890       sqlite3OomFault(db);
139404 139891       return SQLITE_NOMEM_BKPT;
139405 139892     }
................................................................................
139500 139987   
139501 139988     if( pParse->pWithToFree ) sqlite3WithDelete(db, pParse->pWithToFree);
139502 139989     sqlite3DeleteTrigger(db, pParse->pNewTrigger);
139503 139990     sqlite3DbFree(db, pParse->pVList);
139504 139991     while( pParse->pAinc ){
139505 139992       AutoincInfo *p = pParse->pAinc;
139506 139993       pParse->pAinc = p->pNext;
139507         -    sqlite3DbFree(db, p);
       139994  +    sqlite3DbFreeNN(db, p);
139508 139995     }
139509 139996     while( pParse->pZombieTab ){
139510 139997       Table *p = pParse->pZombieTab;
139511 139998       pParse->pZombieTab = p->pNextZombie;
139512 139999       sqlite3DeleteTable(db, p);
139513 140000     }
139514 140001     assert( nErr==0 || pParse->rc!=SQLITE_OK );
................................................................................
142994 143481       /* Opening a db handle. Fourth parameter is passed 0. */
142995 143482       void *pArg = sqlite3GlobalConfig.pSqllogArg;
142996 143483       sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0);
142997 143484     }
142998 143485   #endif
142999 143486   #if defined(SQLITE_HAS_CODEC)
143000 143487     if( rc==SQLITE_OK ){
143001         -    const char *zHexKey = sqlite3_uri_parameter(zOpen, "hexkey");
143002         -    if( zHexKey && zHexKey[0] ){
       143488  +    const char *zKey;
       143489  +    if( (zKey = sqlite3_uri_parameter(zOpen, "hexkey"))!=0 && zKey[0] ){;
143003 143490         u8 iByte;
143004 143491         int i;
143005         -      char zKey[40];
143006         -      for(i=0, iByte=0; i<sizeof(zKey)*2 && sqlite3Isxdigit(zHexKey[i]); i++){
143007         -        iByte = (iByte<<4) + sqlite3HexToInt(zHexKey[i]);
143008         -        if( (i&1)!=0 ) zKey[i/2] = iByte;
       143492  +      char zDecoded[40];
       143493  +      for(i=0, iByte=0; i<sizeof(zDecoded)*2 && sqlite3Isxdigit(zKey[i]); i++){
       143494  +        iByte = (iByte<<4) + sqlite3HexToInt(zKey[i]);
       143495  +        if( (i&1)!=0 ) zDecoded[i/2] = iByte;
143009 143496         }
143010         -      sqlite3_key_v2(db, 0, zKey, i/2);
       143497  +      sqlite3_key_v2(db, 0, zDecoded, i/2);
       143498  +    }else if( (zKey = sqlite3_uri_parameter(zOpen, "key"))!=0 ){
       143499  +      sqlite3_key_v2(db, 0, zKey, sqlite3Strlen30(zKey));
143011 143500       }
143012 143501     }
143013 143502   #endif
143014 143503     sqlite3_free(zOpen);
143015 143504     return rc & 0xff;
143016 143505   }
143017 143506   
................................................................................
145608 146097       if( (c & 0x80)==0 ) break;
145609 146098     }
145610 146099     *v = b;
145611 146100     return (int)(p - pStart);
145612 146101   }
145613 146102   
145614 146103   /*
145615         -** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to a
145616         -** 32-bit integer before it is returned.
       146104  +** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to 
       146105  +** a non-negative 32-bit integer before it is returned.
145617 146106   */
145618 146107   SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *p, int *pi){
145619 146108     u32 a;
145620 146109   
145621 146110   #ifndef fts3GetVarint32
145622 146111     GETVARINT_INIT(a, p, 0,  0x00,     0x80, *pi, 1);
145623 146112   #else
................................................................................
145625 146114     assert( a & 0x80 );
145626 146115   #endif
145627 146116   
145628 146117     GETVARINT_STEP(a, p, 7,  0x7F,     0x4000, *pi, 2);
145629 146118     GETVARINT_STEP(a, p, 14, 0x3FFF,   0x200000, *pi, 3);
145630 146119     GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *pi, 4);
145631 146120     a = (a & 0x0FFFFFFF );
145632         -  *pi = (int)(a | ((u32)(*p & 0x0F) << 28));
       146121  +  *pi = (int)(a | ((u32)(*p & 0x07) << 28));
       146122  +  assert( 0==(a & 0x80000000) );
       146123  +  assert( *pi>=0 );
145633 146124     return 5;
145634 146125   }
145635 146126   
145636 146127   /*
145637 146128   ** Return the number of bytes required to encode v as a varint
145638 146129   */
145639 146130   SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64 v){
................................................................................
146455 146946         }else{
146456 146947           for(iOpt=0; iOpt<SizeofArray(aFts4Opt); iOpt++){
146457 146948             struct Fts4Option *pOp = &aFts4Opt[iOpt];
146458 146949             if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){
146459 146950               break;
146460 146951             }
146461 146952           }
146462         -        if( iOpt==SizeofArray(aFts4Opt) ){
146463         -          sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z);
146464         -          rc = SQLITE_ERROR;
146465         -        }else{
146466         -          switch( iOpt ){
146467         -            case 0:               /* MATCHINFO */
146468         -              if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
146469         -                sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal);
146470         -                rc = SQLITE_ERROR;
146471         -              }
146472         -              bNoDocsize = 1;
146473         -              break;
146474         -
146475         -            case 1:               /* PREFIX */
146476         -              sqlite3_free(zPrefix);
146477         -              zPrefix = zVal;
146478         -              zVal = 0;
146479         -              break;
146480         -
146481         -            case 2:               /* COMPRESS */
146482         -              sqlite3_free(zCompress);
146483         -              zCompress = zVal;
146484         -              zVal = 0;
146485         -              break;
146486         -
146487         -            case 3:               /* UNCOMPRESS */
146488         -              sqlite3_free(zUncompress);
146489         -              zUncompress = zVal;
146490         -              zVal = 0;
146491         -              break;
146492         -
146493         -            case 4:               /* ORDER */
146494         -              if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3)) 
146495         -               && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4)) 
146496         -              ){
146497         -                sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal);
146498         -                rc = SQLITE_ERROR;
146499         -              }
146500         -              bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
146501         -              break;
146502         -
146503         -            case 5:              /* CONTENT */
146504         -              sqlite3_free(zContent);
146505         -              zContent = zVal;
146506         -              zVal = 0;
146507         -              break;
146508         -
146509         -            case 6:              /* LANGUAGEID */
146510         -              assert( iOpt==6 );
146511         -              sqlite3_free(zLanguageid);
146512         -              zLanguageid = zVal;
146513         -              zVal = 0;
146514         -              break;
146515         -
146516         -            case 7:              /* NOTINDEXED */
146517         -              azNotindexed[nNotindexed++] = zVal;
146518         -              zVal = 0;
146519         -              break;
146520         -          }
       146953  +        switch( iOpt ){
       146954  +          case 0:               /* MATCHINFO */
       146955  +            if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
       146956  +              sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal);
       146957  +              rc = SQLITE_ERROR;
       146958  +            }
       146959  +            bNoDocsize = 1;
       146960  +            break;
       146961  +
       146962  +          case 1:               /* PREFIX */
       146963  +            sqlite3_free(zPrefix);
       146964  +            zPrefix = zVal;
       146965  +            zVal = 0;
       146966  +            break;
       146967  +
       146968  +          case 2:               /* COMPRESS */
       146969  +            sqlite3_free(zCompress);
       146970  +            zCompress = zVal;
       146971  +            zVal = 0;
       146972  +            break;
       146973  +
       146974  +          case 3:               /* UNCOMPRESS */
       146975  +            sqlite3_free(zUncompress);
       146976  +            zUncompress = zVal;
       146977  +            zVal = 0;
       146978  +            break;
       146979  +
       146980  +          case 4:               /* ORDER */
       146981  +            if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3)) 
       146982  +             && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4)) 
       146983  +            ){
       146984  +              sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal);
       146985  +              rc = SQLITE_ERROR;
       146986  +            }
       146987  +            bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
       146988  +            break;
       146989  +
       146990  +          case 5:              /* CONTENT */
       146991  +            sqlite3_free(zContent);
       146992  +            zContent = zVal;
       146993  +            zVal = 0;
       146994  +            break;
       146995  +
       146996  +          case 6:              /* LANGUAGEID */
       146997  +            assert( iOpt==6 );
       146998  +            sqlite3_free(zLanguageid);
       146999  +            zLanguageid = zVal;
       147000  +            zVal = 0;
       147001  +            break;
       147002  +
       147003  +          case 7:              /* NOTINDEXED */
       147004  +            azNotindexed[nNotindexed++] = zVal;
       147005  +            zVal = 0;
       147006  +            break;
       147007  +
       147008  +          default:
       147009  +            assert( iOpt==SizeofArray(aFts4Opt) );
       147010  +            sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z);
       147011  +            rc = SQLITE_ERROR;
       147012  +            break;
146521 147013           }
146522 147014           sqlite3_free(zVal);
146523 147015         }
146524 147016       }
146525 147017   
146526 147018       /* Otherwise, the argument is a column name. */
146527 147019       else {
................................................................................
147082 147574       ** the size of zBuffer if required.  */
147083 147575       if( !isFirstTerm ){
147084 147576         zCsr += fts3GetVarint32(zCsr, &nPrefix);
147085 147577       }
147086 147578       isFirstTerm = 0;
147087 147579       zCsr += fts3GetVarint32(zCsr, &nSuffix);
147088 147580       
147089         -    if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
       147581  +    assert( nPrefix>=0 && nSuffix>=0 );
       147582  +    if( &zCsr[nSuffix]>zEnd ){
147090 147583         rc = FTS_CORRUPT_VTAB;
147091 147584         goto finish_scan;
147092 147585       }
147093 147586       if( nPrefix+nSuffix>nAlloc ){
147094 147587         char *zNew;
147095 147588         nAlloc = (nPrefix+nSuffix) * 2;
147096 147589         zNew = (char *)sqlite3_realloc(zBuffer, nAlloc);
................................................................................
147892 148385         nOut += sqlite3Fts3PutVarint(&pOut[nOut], iDelta);
147893 148386         pOut[nOut++] = 0x02;
147894 148387         bWritten = 1;
147895 148388       }
147896 148389       fts3ColumnlistCopy(0, &p);
147897 148390     }
147898 148391   
147899         -  while( p<pEnd && *p==0x01 ){
       148392  +  while( p<pEnd ){
147900 148393       sqlite3_int64 iCol;
147901 148394       p++;
147902 148395       p += sqlite3Fts3GetVarint(p, &iCol);
147903 148396       if( *p==0x02 ){
147904 148397         if( bWritten==0 ){
147905 148398           nOut += sqlite3Fts3PutVarint(&pOut[nOut], iDelta);
147906 148399           bWritten = 1;
................................................................................
148572 149065     int rc = SQLITE_OK;             /* Return Code */
148573 149066     Fts3Cursor *pCsr = (Fts3Cursor *) pCursor;
148574 149067     Fts3Table *p = (Fts3Table *)pCursor->pVtab;
148575 149068   
148576 149069     /* The column value supplied by SQLite must be in range. */
148577 149070     assert( iCol>=0 && iCol<=p->nColumn+2 );
148578 149071   
148579         -  if( iCol==p->nColumn+1 ){
148580         -    /* This call is a request for the "docid" column. Since "docid" is an 
148581         -    ** alias for "rowid", use the xRowid() method to obtain the value.
148582         -    */
148583         -    sqlite3_result_int64(pCtx, pCsr->iPrevId);
148584         -  }else if( iCol==p->nColumn ){
148585         -    /* The extra column whose name is the same as the table.
148586         -    ** Return a blob which is a pointer to the cursor.  */
148587         -    sqlite3_result_blob(pCtx, &pCsr, sizeof(pCsr), SQLITE_TRANSIENT);
148588         -  }else if( iCol==p->nColumn+2 && pCsr->pExpr ){
148589         -    sqlite3_result_int64(pCtx, pCsr->iLangid);
148590         -  }else{
148591         -    /* The requested column is either a user column (one that contains 
148592         -    ** indexed data), or the language-id column.  */
148593         -    rc = fts3CursorSeek(0, pCsr);
148594         -
148595         -    if( rc==SQLITE_OK ){
148596         -      if( iCol==p->nColumn+2 ){
148597         -        int iLangid = 0;
148598         -        if( p->zLanguageid ){
148599         -          iLangid = sqlite3_column_int(pCsr->pStmt, p->nColumn+1);
148600         -        }
148601         -        sqlite3_result_int(pCtx, iLangid);
148602         -      }else if( sqlite3_data_count(pCsr->pStmt)>(iCol+1) ){
       149072  +  switch( iCol-p->nColumn ){
       149073  +    case 0:
       149074  +      /* The special 'table-name' column */
       149075  +      sqlite3_result_blob(pCtx, &pCsr, sizeof(Fts3Cursor*), SQLITE_TRANSIENT);
       149076  +      sqlite3_result_subtype(pCtx, SQLITE_BLOB);
       149077  +      break;
       149078  +
       149079  +    case 1:
       149080  +      /* The docid column */
       149081  +      sqlite3_result_int64(pCtx, pCsr->iPrevId);
       149082  +      break;
       149083  +
       149084  +    case 2:
       149085  +      if( pCsr->pExpr ){
       149086  +        sqlite3_result_int64(pCtx, pCsr->iLangid);
       149087  +        break;
       149088  +      }else if( p->zLanguageid==0 ){
       149089  +        sqlite3_result_int(pCtx, 0);
       149090  +        break;
       149091  +      }else{
       149092  +        iCol = p->nColumn;
       149093  +        /* fall-through */
       149094  +      }
       149095  +
       149096  +    default:
       149097  +      /* A user column. Or, if this is a full-table scan, possibly the
       149098  +      ** language-id column. Seek the cursor. */
       149099  +      rc = fts3CursorSeek(0, pCsr);
       149100  +      if( rc==SQLITE_OK && sqlite3_data_count(pCsr->pStmt)-1>iCol ){
148603 149101           sqlite3_result_value(pCtx, sqlite3_column_value(pCsr->pStmt, iCol+1));
148604 149102         }
148605         -    }
       149103  +      break;
148606 149104     }
148607 149105   
148608 149106     assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
148609 149107     return rc;
148610 149108   }
148611 149109   
148612 149110   /* 
................................................................................
148678 149176   ** table (if p->bHasStat==2), attempt to determine this (set p->bHasStat
148679 149177   ** to 0 or 1). Return SQLITE_OK if successful, or an SQLite error code
148680 149178   ** if an error occurs.
148681 149179   */
148682 149180   static int fts3SetHasStat(Fts3Table *p){
148683 149181     int rc = SQLITE_OK;
148684 149182     if( p->bHasStat==2 ){
148685         -    const char *zFmt ="SELECT 1 FROM %Q.sqlite_master WHERE tbl_name='%q_stat'";
148686         -    char *zSql = sqlite3_mprintf(zFmt, p->zDb, p->zName);
148687         -    if( zSql ){
148688         -      sqlite3_stmt *pStmt = 0;
148689         -      rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
148690         -      if( rc==SQLITE_OK ){
148691         -        int bHasStat = (sqlite3_step(pStmt)==SQLITE_ROW);
148692         -        rc = sqlite3_finalize(pStmt);
148693         -        if( rc==SQLITE_OK ) p->bHasStat = (u8)bHasStat;
148694         -      }
148695         -      sqlite3_free(zSql);
       149183  +    char *zTbl = sqlite3_mprintf("%s_stat", p->zName);
       149184  +    if( zTbl ){
       149185  +      int res = sqlite3_table_column_metadata(p->db, p->zDb, zTbl, 0,0,0,0,0,0);
       149186  +      sqlite3_free(zTbl);
       149187  +      p->bHasStat = (res==SQLITE_OK);
148696 149188       }else{
148697 149189         rc = SQLITE_NOMEM;
148698 149190       }
148699 149191     }
148700 149192     return rc;
148701 149193   }
148702 149194   
................................................................................
148795 149287   */
148796 149288   static int fts3FunctionArg(
148797 149289     sqlite3_context *pContext,      /* SQL function call context */
148798 149290     const char *zFunc,              /* Function name */
148799 149291     sqlite3_value *pVal,            /* argv[0] passed to function */
148800 149292     Fts3Cursor **ppCsr              /* OUT: Store cursor handle here */
148801 149293   ){
148802         -  Fts3Cursor *pRet;
148803         -  if( sqlite3_value_type(pVal)!=SQLITE_BLOB 
148804         -   || sqlite3_value_bytes(pVal)!=sizeof(Fts3Cursor *)
148805         -  ){
       149294  +  int rc = SQLITE_OK;
       149295  +  if( sqlite3_value_subtype(pVal)==SQLITE_BLOB ){
       149296  +    *ppCsr = *(Fts3Cursor**)sqlite3_value_blob(pVal);
       149297  +  }else{
148806 149298       char *zErr = sqlite3_mprintf("illegal first argument to %s", zFunc);
148807 149299       sqlite3_result_error(pContext, zErr, -1);
148808 149300       sqlite3_free(zErr);
148809         -    return SQLITE_ERROR;
       149301  +    rc = SQLITE_ERROR;
148810 149302     }
148811         -  memcpy(&pRet, sqlite3_value_blob(pVal), sizeof(Fts3Cursor *));
148812         -  *ppCsr = pRet;
148813         -  return SQLITE_OK;
       149303  +  return rc;
148814 149304   }
148815 149305   
148816 149306   /*
148817 149307   ** Implementation of the snippet() function for FTS3
148818 149308   */
148819 149309   static void fts3SnippetFunc(
148820 149310     sqlite3_context *pContext,      /* SQLite function call context */
................................................................................
149193 149683   #ifdef SQLITE_TEST
149194 149684     if( rc==SQLITE_OK ){
149195 149685       rc = sqlite3Fts3ExprInitTestInterface(db);
149196 149686     }
149197 149687   #endif
149198 149688   
149199 149689     /* Create the virtual table wrapper around the hash-table and overload 
149200         -  ** the two scalar functions. If this is successful, register the
       149690  +  ** the four scalar functions. If this is successful, register the
149201 149691     ** module with sqlite.
149202 149692     */
149203 149693     if( SQLITE_OK==rc 
149204 149694      && SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
149205 149695      && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
149206 149696      && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
149207 149697      && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
................................................................................
149776 150266     Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab;
149777 150267     u8 bEof = 0;
149778 150268   
149779 150269     /* This is only called if it is guaranteed that the phrase has at least
149780 150270     ** one incremental token. In which case the bIncr flag is set. */
149781 150271     assert( p->bIncr==1 );
149782 150272   
149783         -  if( p->nToken==1 && p->bIncr ){
       150273  +  if( p->nToken==1 ){
149784 150274       rc = sqlite3Fts3MsrIncrNext(pTab, p->aToken[0].pSegcsr, 
149785 150275           &pDL->iDocid, &pDL->pList, &pDL->nList
149786 150276       );
149787 150277       if( pDL->pList==0 ) bEof = 1;
149788 150278     }else{
149789 150279       int bDescDoclist = pCsr->bDesc;
149790 150280       struct TokenDoclist a[MAX_INCR_PHRASE_TOKENS];
................................................................................
150009 150499   ** The average document size in pages is calculated by first calculating 
150010 150500   ** determining the average size in bytes, B. If B is less than the amount
150011 150501   ** of data that will fit on a single leaf page of an intkey table in
150012 150502   ** this database, then the average docsize is 1. Otherwise, it is 1 plus
150013 150503   ** the number of overflow pages consumed by a record B bytes in size.
150014 150504   */
150015 150505   static int fts3EvalAverageDocsize(Fts3Cursor *pCsr, int *pnPage){
       150506  +  int rc = SQLITE_OK;
150016 150507     if( pCsr->nRowAvg==0 ){
150017 150508       /* The average document size, which is required to calculate the cost
150018 150509       ** of each doclist, has not yet been determined. Read the required 
150019 150510       ** data from the %_stat table to calculate it.
150020 150511       **
150021 150512       ** Entry 0 of the %_stat table is a blob containing (nCol+1) FTS3 
150022 150513       ** varints, where nCol is the number of columns in the FTS3 table.
150023 150514       ** The first varint is the number of documents currently stored in
150024 150515       ** the table. The following nCol varints contain the total amount of
150025 150516       ** data stored in all rows of each column of the table, from left
150026 150517       ** to right.
150027 150518       */
150028         -    int rc;
150029 150519       Fts3Table *p = (Fts3Table*)pCsr->base.pVtab;
150030 150520       sqlite3_stmt *pStmt;
150031 150521       sqlite3_int64 nDoc = 0;
150032 150522       sqlite3_int64 nByte = 0;
150033 150523       const char *pEnd;
150034 150524       const char *a;
150035 150525   
................................................................................
150048 150538         return FTS_CORRUPT_VTAB;
150049 150539       }
150050 150540   
150051 150541       pCsr->nDoc = nDoc;
150052 150542       pCsr->nRowAvg = (int)(((nByte / nDoc) + p->nPgsz) / p->nPgsz);
150053 150543       assert( pCsr->nRowAvg>0 ); 
150054 150544       rc = sqlite3_reset(pStmt);
150055         -    if( rc!=SQLITE_OK ) return rc;
150056 150545     }
150057 150546   
150058 150547     *pnPage = pCsr->nRowAvg;
150059         -  return SQLITE_OK;
       150548  +  return rc;
150060 150549   }
150061 150550   
150062 150551   /*
150063 150552   ** This function is called to select the tokens (if any) that will be 
150064 150553   ** deferred. The array aTC[] has already been populated when this is
150065 150554   ** called.
150066 150555   **
................................................................................
150402 150891               }else{
150403 150892                 fts3EvalNextRow(pCsr, pRight, pRc);
150404 150893               }
150405 150894             }
150406 150895             pExpr->iDocid = pLeft->iDocid;
150407 150896             pExpr->bEof = (pLeft->bEof || pRight->bEof);
150408 150897             if( pExpr->eType==FTSQUERY_NEAR && pExpr->bEof ){
150409         -            if( pRight->pPhrase && pRight->pPhrase->doclist.aAll ){
       150898  +            assert( pRight->eType==FTSQUERY_PHRASE );
       150899  +            if( pRight->pPhrase->doclist.aAll ){
150410 150900                 Fts3Doclist *pDl = &pRight->pPhrase->doclist;
150411 150901                 while( *pRc==SQLITE_OK && pRight->bEof==0 ){
150412 150902                   memset(pDl->pList, 0, pDl->nList);
150413 150903                   fts3EvalNextRow(pCsr, pRight, pRc);
150414 150904                 }
150415 150905               }
150416 150906               if( pLeft->pPhrase && pLeft->pPhrase->doclist.aAll ){
................................................................................
150431 150921           sqlite3_int64 iCmp = DOCID_CMP(pLeft->iDocid, pRight->iDocid);
150432 150922   
150433 150923           assert( pLeft->bStart || pLeft->iDocid==pRight->iDocid );
150434 150924           assert( pRight->bStart || pLeft->iDocid==pRight->iDocid );
150435 150925   
150436 150926           if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){
150437 150927             fts3EvalNextRow(pCsr, pLeft, pRc);
150438         -        }else if( pLeft->bEof || (pRight->bEof==0 && iCmp>0) ){
       150928  +        }else if( pLeft->bEof || iCmp>0 ){
150439 150929             fts3EvalNextRow(pCsr, pRight, pRc);
150440 150930           }else{
150441 150931             fts3EvalNextRow(pCsr, pLeft, pRc);
150442 150932             fts3EvalNextRow(pCsr, pRight, pRc);
150443 150933           }
150444 150934   
150445 150935           pExpr->bEof = (pLeft->bEof && pRight->bEof);
................................................................................
150523 151013     **
150524 151014     ** The right-hand child of a NEAR node is always a phrase. The 
150525 151015     ** left-hand child may be either a phrase or a NEAR node. There are
150526 151016     ** no exceptions to this - it's the way the parser in fts3_expr.c works.
150527 151017     */
150528 151018     if( *pRc==SQLITE_OK 
150529 151019      && pExpr->eType==FTSQUERY_NEAR 
150530         -   && pExpr->bEof==0
150531 151020      && (pExpr->pParent==0 || pExpr->pParent->eType!=FTSQUERY_NEAR)
150532 151021     ){
150533 151022       Fts3Expr *p; 
150534 151023       int nTmp = 0;                 /* Bytes of temp space */
150535 151024       char *aTmp;                   /* Temp space for PoslistNearMerge() */
150536 151025   
150537 151026       /* Allocate temporary working space. */
150538 151027       for(p=pExpr; p->pLeft; p=p->pLeft){
       151028  +      assert( p->pRight->pPhrase->doclist.nList>0 );
150539 151029         nTmp += p->pRight->pPhrase->doclist.nList;
150540 151030       }
150541 151031       nTmp += p->pPhrase->doclist.nList;
150542         -    if( nTmp==0 ){
       151032  +    aTmp = sqlite3_malloc(nTmp*2);
       151033  +    if( !aTmp ){
       151034  +      *pRc = SQLITE_NOMEM;
150543 151035         res = 0;
150544 151036       }else{
150545         -      aTmp = sqlite3_malloc(nTmp*2);
150546         -      if( !aTmp ){
150547         -        *pRc = SQLITE_NOMEM;
150548         -        res = 0;
150549         -      }else{
150550         -        char *aPoslist = p->pPhrase->doclist.pList;
150551         -        int nToken = p->pPhrase->nToken;
150552         -
150553         -        for(p=p->pParent;res && p && p->eType==FTSQUERY_NEAR; p=p->pParent){
150554         -          Fts3Phrase *pPhrase = p->pRight->pPhrase;
150555         -          int nNear = p->nNear;
150556         -          res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
150557         -        }
150558         -
150559         -        aPoslist = pExpr->pRight->pPhrase->doclist.pList;
150560         -        nToken = pExpr->pRight->pPhrase->nToken;
150561         -        for(p=pExpr->pLeft; p && res; p=p->pLeft){
150562         -          int nNear;
150563         -          Fts3Phrase *pPhrase;
150564         -          assert( p->pParent && p->pParent->pLeft==p );
150565         -          nNear = p->pParent->nNear;
150566         -          pPhrase = (
150567         -              p->eType==FTSQUERY_NEAR ? p->pRight->pPhrase : p->pPhrase
150568         -              );
150569         -          res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
150570         -        }
150571         -      }
150572         -
150573         -      sqlite3_free(aTmp);
150574         -    }
       151037  +      char *aPoslist = p->pPhrase->doclist.pList;
       151038  +      int nToken = p->pPhrase->nToken;
       151039  +
       151040  +      for(p=p->pParent;res && p && p->eType==FTSQUERY_NEAR; p=p->pParent){
       151041  +        Fts3Phrase *pPhrase = p->pRight->pPhrase;
       151042  +        int nNear = p->nNear;
       151043  +        res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
       151044  +      }
       151045  +
       151046  +      aPoslist = pExpr->pRight->pPhrase->doclist.pList;
       151047  +      nToken = pExpr->pRight->pPhrase->nToken;
       151048  +      for(p=pExpr->pLeft; p && res; p=p->pLeft){
       151049  +        int nNear;
       151050  +        Fts3Phrase *pPhrase;
       151051  +        assert( p->pParent && p->pParent->pLeft==p );
       151052  +        nNear = p->pParent->nNear;
       151053  +        pPhrase = (
       151054  +            p->eType==FTSQUERY_NEAR ? p->pRight->pPhrase : p->pPhrase
       151055  +        );
       151056  +        res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
       151057  +      }
       151058  +    }
       151059  +
       151060  +    sqlite3_free(aTmp);
150575 151061     }
150576 151062   
150577 151063     return res;
150578 151064   }
150579 151065   
150580 151066   /*
150581 151067   ** This function is a helper function for sqlite3Fts3EvalTestDeferred().
................................................................................
166674 167160       "ALTER TABLE %Q.'%q_parent' RENAME TO \"%w_parent\";"
166675 167161       "ALTER TABLE %Q.'%q_rowid'  RENAME TO \"%w_rowid\";"
166676 167162       , pRtree->zDb, pRtree->zName, zNewName 
166677 167163       , pRtree->zDb, pRtree->zName, zNewName 
166678 167164       , pRtree->zDb, pRtree->zName, zNewName
166679 167165     );
166680 167166     if( zSql ){
       167167  +    nodeBlobReset(pRtree);
166681 167168       rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
166682 167169       sqlite3_free(zSql);
166683 167170     }
166684 167171     return rc;
166685 167172   }
166686 167173   
       167174  +/*
       167175  +** The xSavepoint method.
       167176  +**
       167177  +** This module does not need to do anything to support savepoints. However,
       167178  +** it uses this hook to close any open blob handle. This is done because a 
       167179  +** DROP TABLE command - which fortunately always opens a savepoint - cannot 
       167180  +** succeed if there are any open blob handles. i.e. if the blob handle were
       167181  +** not closed here, the following would fail:
       167182  +**
       167183  +**   BEGIN;
       167184  +**     INSERT INTO rtree...
       167185  +**     DROP TABLE <tablename>;    -- Would fail with SQLITE_LOCKED
       167186  +**   COMMIT;
       167187  +*/
       167188  +static int rtreeSavepoint(sqlite3_vtab *pVtab, int iSavepoint){
       167189  +  Rtree *pRtree = (Rtree *)pVtab;
       167190  +  int iwt = pRtree->inWrTrans;
       167191  +  UNUSED_PARAMETER(iSavepoint);
       167192  +  pRtree->inWrTrans = 0;
       167193  +  nodeBlobReset(pRtree);
       167194  +  pRtree->inWrTrans = iwt;
       167195  +  return SQLITE_OK;
       167196  +}
166687 167197   
166688 167198   /*
166689 167199   ** This function populates the pRtree->nRowEst variable with an estimate
166690 167200   ** of the number of rows in the virtual table. If possible, this is based
166691 167201   ** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST.
166692 167202   */
166693 167203   static int rtreeQueryStat1(sqlite3 *db, Rtree *pRtree){
................................................................................
166726 167236       sqlite3_free(zSql);
166727 167237     }
166728 167238   
166729 167239     return rc;
166730 167240   }
166731 167241   
166732 167242   static sqlite3_module rtreeModule = {
166733         -  0,                          /* iVersion */
       167243  +  2,                          /* iVersion */
166734 167244     rtreeCreate,                /* xCreate - create a table */
166735 167245     rtreeConnect,               /* xConnect - connect to an existing table */
166736 167246     rtreeBestIndex,             /* xBestIndex - Determine search strategy */
166737 167247     rtreeDisconnect,            /* xDisconnect - Disconnect from a table */
166738 167248     rtreeDestroy,               /* xDestroy - Drop a table */
166739 167249     rtreeOpen,                  /* xOpen - open a cursor */
166740 167250     rtreeClose,                 /* xClose - close a cursor */
................................................................................
166746 167256     rtreeUpdate,                /* xUpdate - write data */
166747 167257     rtreeBeginTransaction,      /* xBegin - begin transaction */
166748 167258     rtreeEndTransaction,        /* xSync - sync transaction */
166749 167259     rtreeEndTransaction,        /* xCommit - commit transaction */
166750 167260     rtreeEndTransaction,        /* xRollback - rollback transaction */
166751 167261     0,                          /* xFindFunction - function overloading */
166752 167262     rtreeRename,                /* xRename - rename the table */
166753         -  0,                          /* xSavepoint */
       167263  +  rtreeSavepoint,             /* xSavepoint */
166754 167264     0,                          /* xRelease */
166755 167265     0,                          /* xRollbackTo */
166756 167266   };
166757 167267   
166758 167268   static int rtreeSqlInit(
166759 167269     Rtree *pRtree, 
166760 167270     sqlite3 *db, 
................................................................................
178903 179413   #define safe_isspace(x) (jsonIsSpace[(unsigned char)x])
178904 179414   
178905 179415   #ifndef SQLITE_AMALGAMATION
178906 179416     /* Unsigned integer types.  These are already defined in the sqliteInt.h,
178907 179417     ** but the definitions need to be repeated for separate compilation. */
178908 179418     typedef sqlite3_uint64 u64;
178909 179419     typedef unsigned int u32;
       179420  +  typedef unsigned short int u16;
178910 179421     typedef unsigned char u8;
178911 179422   #endif
178912 179423   
178913 179424   /* Objects */
178914 179425   typedef struct JsonString JsonString;
178915 179426   typedef struct JsonNode JsonNode;
178916 179427   typedef struct JsonParse JsonParse;
................................................................................
178982 179493     u32 nNode;         /* Number of slots of aNode[] used */
178983 179494     u32 nAlloc;        /* Number of slots of aNode[] allocated */
178984 179495     JsonNode *aNode;   /* Array of nodes containing the parse */
178985 179496     const char *zJson; /* Original JSON string */
178986 179497     u32 *aUp;          /* Index of parent of each node */
178987 179498     u8 oom;            /* Set to true if out of memory */
178988 179499     u8 nErr;           /* Number of errors seen */
       179500  +  u16 iDepth;        /* Nesting depth */
178989 179501   };
178990 179502   
       179503  +/*
       179504  +** Maximum nesting depth of JSON for this implementation.
       179505  +**
       179506  +** This limit is needed to avoid a stack overflow in the recursive
       179507  +** descent parser.  A depth of 2000 is far deeper than any sane JSON
       179508  +** should go.
       179509  +*/
       179510  +#define JSON_MAX_DEPTH  2000
       179511  +
178991 179512   /**************************************************************************
178992 179513   ** Utility routines for dealing with JsonString objects
178993 179514   **************************************************************************/
178994 179515   
178995 179516   /* Set the JsonString object to an empty string
178996 179517   */
178997 179518   static void jsonZero(JsonString *p){
................................................................................
179540 180061   */
179541 180062   static int jsonParseValue(JsonParse *pParse, u32 i){
179542 180063     char c;
179543 180064     u32 j;
179544 180065     int iThis;
179545 180066     int x;
179546 180067     JsonNode *pNode;
179547         -  while( safe_isspace(pParse->zJson[i]) ){ i++; }
179548         -  if( (c = pParse->zJson[i])=='{' ){
       180068  +  const char *z = pParse->zJson;
       180069  +  while( safe_isspace(z[i]) ){ i++; }
       180070  +  if( (c = z[i])=='{' ){
179549 180071       /* Parse object */
179550 180072       iThis = jsonParseAddNode(pParse, JSON_OBJECT, 0, 0);
179551 180073       if( iThis<0 ) return -1;
179552 180074       for(j=i+1;;j++){
179553         -      while( safe_isspace(pParse->zJson[j]) ){ j++; }
       180075  +      while( safe_isspace(z[j]) ){ j++; }
       180076  +      if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
179554 180077         x = jsonParseValue(pParse, j);
179555 180078         if( x<0 ){
       180079  +        pParse->iDepth--;
179556 180080           if( x==(-2) && pParse->nNode==(u32)iThis+1 ) return j+1;
179557 180081           return -1;
179558 180082         }
179559 180083         if( pParse->oom ) return -1;
179560 180084         pNode = &pParse->aNode[pParse->nNode-1];
179561 180085         if( pNode->eType!=JSON_STRING ) return -1;
179562 180086         pNode->jnFlags |= JNODE_LABEL;
179563 180087         j = x;
179564         -      while( safe_isspace(pParse->zJson[j]) ){ j++; }
179565         -      if( pParse->zJson[j]!=':' ) return -1;
       180088  +      while( safe_isspace(z[j]) ){ j++; }
       180089  +      if( z[j]!=':' ) return -1;
179566 180090         j++;
179567 180091         x = jsonParseValue(pParse, j);
       180092  +      pParse->iDepth--;
179568 180093         if( x<0 ) return -1;
179569 180094         j = x;
179570         -      while( safe_isspace(pParse->zJson[j]) ){ j++; }
179571         -      c = pParse->zJson[j];
       180095  +      while( safe_isspace(z[j]) ){ j++; }
       180096  +      c = z[j];
179572 180097         if( c==',' ) continue;
179573 180098         if( c!='}' ) return -1;
179574 180099         break;
179575 180100       }
179576 180101       pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
179577 180102       return j+1;
179578 180103     }else if( c=='[' ){
179579 180104       /* Parse array */
179580 180105       iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0);
179581 180106       if( iThis<0 ) return -1;
179582 180107       for(j=i+1;;j++){
179583         -      while( safe_isspace(pParse->zJson[j]) ){ j++; }
       180108  +      while( safe_isspace(z[j]) ){ j++; }
       180109  +      if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
179584 180110         x = jsonParseValue(pParse, j);
       180111  +      pParse->iDepth--;
179585 180112         if( x<0 ){
179586 180113           if( x==(-3) && pParse->nNode==(u32)iThis+1 ) return j+1;
179587 180114           return -1;
179588 180115         }
179589 180116         j = x;
179590         -      while( safe_isspace(pParse->zJson[j]) ){ j++; }
179591         -      c = pParse->zJson[j];
       180117  +      while( safe_isspace(z[j]) ){ j++; }
       180118  +      c = z[j];
179592 180119         if( c==',' ) continue;
179593 180120         if( c!=']' ) return -1;
179594 180121         break;
179595 180122       }
179596 180123       pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
179597 180124       return j+1;
179598 180125     }else if( c=='"' ){
179599 180126       /* Parse string */
179600 180127       u8 jnFlags = 0;
179601 180128       j = i+1;
179602 180129       for(;;){
179603         -      c = pParse->zJson[j];
179604         -      if( c==0 ) return -1;
       180130  +      c = z[j];
       180131  +      if( (c & ~0x1f)==0 ){
       180132  +        /* Control characters are not allowed in strings */
       180133  +        return -1;
       180134  +      }
179605 180135         if( c=='\\' ){
179606         -        c = pParse->zJson[++j];
       180136  +        c = z[++j];
179607 180137           if( c=='"' || c=='\\' || c=='/' || c=='b' || c=='f'
179608 180138              || c=='n' || c=='r' || c=='t'
179609         -           || (c=='u' && jsonIs4Hex(pParse->zJson+j+1)) ){
       180139  +           || (c=='u' && jsonIs4Hex(z+j+1)) ){
179610 180140             jnFlags = JNODE_ESCAPE;
179611 180141           }else{
179612 180142             return -1;
179613 180143           }
179614 180144         }else if( c=='"' ){
179615 180145           break;
179616 180146         }
179617 180147         j++;
179618 180148       }
179619         -    jsonParseAddNode(pParse, JSON_STRING, j+1-i, &pParse->zJson[i]);
       180149  +    jsonParseAddNode(pParse, JSON_STRING, j+1-i, &z[i]);
179620 180150       if( !pParse->oom ) pParse->aNode[pParse->nNode-1].jnFlags = jnFlags;
179621 180151       return j+1;
179622 180152     }else if( c=='n'
179623         -         && strncmp(pParse->zJson+i,"null",4)==0
179624         -         && !safe_isalnum(pParse->zJson[i+4]) ){
       180153  +         && strncmp(z+i,"null",4)==0
       180154  +         && !safe_isalnum(z[i+4]) ){
179625 180155       jsonParseAddNode(pParse, JSON_NULL, 0, 0);
179626 180156       return i+4;
179627 180157     }else if( c=='t'
179628         -         && strncmp(pParse->zJson+i,"true",4)==0
179629         -         && !safe_isalnum(pParse->zJson[i+4]) ){
       180158  +         && strncmp(z+i,"true",4)==0
       180159  +         && !safe_isalnum(z[i+4]) ){
179630 180160       jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
179631 180161       return i+4;
179632 180162     }else if( c=='f'
179633         -         && strncmp(pParse->zJson+i,"false",5)==0
179634         -         && !safe_isalnum(pParse->zJson[i+5]) ){
       180163  +         && strncmp(z+i,"false",5)==0
       180164  +         && !safe_isalnum(z[i+5]) ){
179635 180165       jsonParseAddNode(pParse, JSON_FALSE, 0, 0);
179636 180166       return i+5;
179637 180167     }else if( c=='-' || (c>='0' && c<='9') ){
179638 180168       /* Parse number */
179639 180169       u8 seenDP = 0;
179640 180170       u8 seenE = 0;
       180171  +    assert( '-' < '0' );
       180172  +    if( c<='0' ){
       180173  +      j = c=='-' ? i+1 : i;
       180174  +      if( z[j]=='0' && z[j+1]>='0' && z[j+1]<='9' ) return -1;
       180175  +    }
179641 180176       j = i+1;
179642 180177       for(;; j++){
179643         -      c = pParse->zJson[j];
       180178  +      c = z[j];
179644 180179         if( c>='0' && c<='9' ) continue;
179645 180180         if( c=='.' ){
179646         -        if( pParse->zJson[j-1]=='-' ) return -1;
       180181  +        if( z[j-1]=='-' ) return -1;
179647 180182           if( seenDP ) return -1;
179648 180183           seenDP = 1;
179649 180184           continue;
179650 180185         }
179651 180186         if( c=='e' || c=='E' ){
179652         -        if( pParse->zJson[j-1]<'0' ) return -1;
       180187  +        if( z[j-1]<'0' ) return -1;
179653 180188           if( seenE ) return -1;
179654 180189           seenDP = seenE = 1;
179655         -        c = pParse->zJson[j+1];
       180190  +        c = z[j+1];
179656 180191           if( c=='+' || c=='-' ){
179657 180192             j++;
179658         -          c = pParse->zJson[j+1];
       180193  +          c = z[j+1];
179659 180194           }
179660 180195           if( c<'0' || c>'9' ) return -1;
179661 180196           continue;
179662 180197         }
179663 180198         break;
179664 180199       }
179665         -    if( pParse->zJson[j-1]<'0' ) return -1;
       180200  +    if( z[j-1]<'0' ) return -1;
179666 180201       jsonParseAddNode(pParse, seenDP ? JSON_REAL : JSON_INT,
179667         -                        j - i, &pParse->zJson[i]);
       180202  +                        j - i, &z[i]);
179668 180203       return j;
179669 180204     }else if( c=='}' ){
179670 180205       return -2;  /* End of {...} */
179671 180206     }else if( c==']' ){
179672 180207       return -3;  /* End of [...] */
179673 180208     }else if( c==0 ){
179674 180209       return 0;   /* End of file */
................................................................................
179692 180227     int i;
179693 180228     memset(pParse, 0, sizeof(*pParse));
179694 180229     if( zJson==0 ) return 1;
179695 180230     pParse->zJson = zJson;
179696 180231     i = jsonParseValue(pParse, 0);
179697 180232     if( pParse->oom ) i = -1;
179698 180233     if( i>0 ){
       180234  +    assert( pParse->iDepth==0 );
179699 180235       while( safe_isspace(zJson[i]) ) i++;
179700 180236       if( zJson[i] ) i = -1;
179701 180237     }
179702 180238     if( i<=0 ){
179703 180239       if( pCtx!=0 ){
179704 180240         if( pParse->oom ){
179705 180241           sqlite3_result_error_nomem(pCtx);
................................................................................
180192 180728     jsonParseReset(&x);
180193 180729   }
180194 180730   
180195 180731   /* This is the RFC 7396 MergePatch algorithm.
180196 180732   */
180197 180733   static JsonNode *jsonMergePatch(
180198 180734     JsonParse *pParse,   /* The JSON parser that contains the TARGET */
180199         -  int iTarget,         /* Node of the TARGET in pParse */
       180735  +  u32 iTarget,         /* Node of the TARGET in pParse */
180200 180736     JsonNode *pPatch     /* The PATCH */
180201 180737   ){
180202 180738     u32 i, j;
180203 180739     u32 iRoot;
180204 180740     JsonNode *pTarget;
180205 180741     if( pPatch->eType!=JSON_OBJECT ){
180206 180742       return pPatch;
................................................................................
182201 182737     Fts5Index *p,                   /* Index to write to */
182202 182738     int bDelete,                    /* True if current operation is a delete */
182203 182739     i64 iDocid                      /* Docid to add or remove data from */
182204 182740   );
182205 182741   
182206 182742   /*
182207 182743   ** Flush any data stored in the in-memory hash tables to the database.
182208         -** If the bCommit flag is true, also close any open blob handles.
       182744  +** Also close any open blob handles.
182209 182745   */
182210         -static int sqlite3Fts5IndexSync(Fts5Index *p, int bCommit);
       182746  +static int sqlite3Fts5IndexSync(Fts5Index *p);
182211 182747   
182212 182748   /*
182213 182749   ** Discard any data stored in the in-memory hash tables. Do not write it
182214 182750   ** to the database. Additionally, assume that the contents of the %_data
182215 182751   ** table may have changed on disk. So any in-memory caches of %_data 
182216 182752   ** records must be invalidated.
182217 182753   */
................................................................................
182373 182909   static int sqlite3Fts5StorageStmt(Fts5Storage *p, int eStmt, sqlite3_stmt**, char**);
182374 182910   static void sqlite3Fts5StorageStmtRelease(Fts5Storage *p, int eStmt, sqlite3_stmt*);
182375 182911   
182376 182912   static int sqlite3Fts5StorageDocsize(Fts5Storage *p, i64 iRowid, int *aCol);
182377 182913   static int sqlite3Fts5StorageSize(Fts5Storage *p, int iCol, i64 *pnAvg);
182378 182914   static int sqlite3Fts5StorageRowCount(Fts5Storage *p, i64 *pnRow);
182379 182915   
182380         -static int sqlite3Fts5StorageSync(Fts5Storage *p, int bCommit);
       182916  +static int sqlite3Fts5StorageSync(Fts5Storage *p);
182381 182917   static int sqlite3Fts5StorageRollback(Fts5Storage *p);
182382 182918   
182383 182919   static int sqlite3Fts5StorageConfigValue(
182384 182920       Fts5Storage *p, const char*, sqlite3_value*, int
182385 182921   );
182386 182922   
182387 182923   static int sqlite3Fts5StorageDeleteAll(Fts5Storage *p);
................................................................................
182409 182945     const char *p;                  /* Token text (not NULL terminated) */
182410 182946     int n;                          /* Size of buffer p in bytes */
182411 182947   };
182412 182948   
182413 182949   /* Parse a MATCH expression. */
182414 182950   static int sqlite3Fts5ExprNew(
182415 182951     Fts5Config *pConfig, 
       182952  +  int iCol,                       /* Column on LHS of MATCH operator */
182416 182953     const char *zExpr,
182417 182954     Fts5Expr **ppNew, 
182418 182955     char **pzErr
182419 182956   );
182420 182957   
182421 182958   /*
182422 182959   ** for(rc = sqlite3Fts5ExprFirst(pExpr, pIdx, bDesc);
................................................................................
182493 183030   );
182494 183031   
182495 183032   static void sqlite3Fts5ParsePhraseFree(Fts5ExprPhrase*);
182496 183033   static void sqlite3Fts5ParseNearsetFree(Fts5ExprNearset*);
182497 183034   static void sqlite3Fts5ParseNodeFree(Fts5ExprNode*);
182498 183035   
182499 183036   static void sqlite3Fts5ParseSetDistance(Fts5Parse*, Fts5ExprNearset*, Fts5Token*);
182500         -static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNearset*, Fts5Colset*);
       183037  +static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNode*, Fts5Colset*);
182501 183038   static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse*, Fts5Colset*);
182502 183039   static void sqlite3Fts5ParseFinished(Fts5Parse *pParse, Fts5ExprNode *p);
182503 183040   static void sqlite3Fts5ParseNear(Fts5Parse *pParse, Fts5Token*);
182504 183041   
182505 183042   /*
182506 183043   ** End of interface to code in fts5_expr.c.
182507 183044   **************************************************************************/
................................................................................
182550 183087   #endif
182551 183088   
182552 183089   #define FTS5_OR                               1
182553 183090   #define FTS5_AND                              2
182554 183091   #define FTS5_NOT                              3
182555 183092   #define FTS5_TERM                             4
182556 183093   #define FTS5_COLON                            5
182557         -#define FTS5_LP                               6
182558         -#define FTS5_RP                               7
182559         -#define FTS5_MINUS                            8
182560         -#define FTS5_LCP                              9
182561         -#define FTS5_RCP                             10
182562         -#define FTS5_STRING                          11
       183094  +#define FTS5_MINUS                            6
       183095  +#define FTS5_LCP                              7
       183096  +#define FTS5_RCP                              8
       183097  +#define FTS5_STRING                           9
       183098  +#define FTS5_LP                              10
       183099  +#define FTS5_RP                              11
182563 183100   #define FTS5_COMMA                           12
182564 183101   #define FTS5_PLUS                            13
182565 183102   #define FTS5_STAR                            14
182566 183103   
182567 183104   /*
182568 183105   ** 2000-05-29
182569 183106   **
................................................................................
182691 183228   #ifndef fts5YYSTACKDEPTH
182692 183229   #define fts5YYSTACKDEPTH 100
182693 183230   #endif
182694 183231   #define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
182695 183232   #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
182696 183233   #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
182697 183234   #define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
182698         -#define fts5YYNSTATE             29
182699         -#define fts5YYNRULE              26
182700         -#define fts5YY_MAX_SHIFT         28
182701         -#define fts5YY_MIN_SHIFTREDUCE   45
182702         -#define fts5YY_MAX_SHIFTREDUCE   70
182703         -#define fts5YY_MIN_REDUCE        71
182704         -#define fts5YY_MAX_REDUCE        96
182705         -#define fts5YY_ERROR_ACTION      97
182706         -#define fts5YY_ACCEPT_ACTION     98
182707         -#define fts5YY_NO_ACTION         99
       183235  +#define fts5YYNSTATE             33
       183236  +#define fts5YYNRULE              27
       183237  +#define fts5YY_MAX_SHIFT         32
       183238  +#define fts5YY_MIN_SHIFTREDUCE   50
       183239  +#define fts5YY_MAX_SHIFTREDUCE   76
       183240  +#define fts5YY_MIN_REDUCE        77
       183241  +#define fts5YY_MAX_REDUCE        103
       183242  +#define fts5YY_ERROR_ACTION      104
       183243  +#define fts5YY_ACCEPT_ACTION     105
       183244  +#define fts5YY_NO_ACTION         106
182708 183245   /************* End control #defines *******************************************/
182709 183246   
182710 183247   /* Define the fts5yytestcase() macro to be a no-op if is not already defined
182711 183248   ** otherwise.
182712 183249   **
182713 183250   ** Applications can choose to define fts5yytestcase() in the %include section
182714 183251   ** to a macro that can assist in verifying code coverage.  For production
................................................................................
182772 183309   **  fts5yy_shift_ofst[]    For each state, the offset into fts5yy_action for
182773 183310   **                     shifting terminals.
182774 183311   **  fts5yy_reduce_ofst[]   For each state, the offset into fts5yy_action for
182775 183312   **                     shifting non-terminals after a reduce.
182776 183313   **  fts5yy_default[]       Default action for each state.
182777 183314   **
182778 183315   *********** Begin parsing tables **********************************************/
182779         -#define fts5YY_ACTTAB_COUNT (85)
       183316  +#define fts5YY_ACTTAB_COUNT (98)
182780 183317   static const fts5YYACTIONTYPE fts5yy_action[] = {
182781         - /*     0 */    98,   16,   51,    5,   53,   27,   83,    7,   26,   15,
182782         - /*    10 */    51,    5,   53,   27,   13,   69,   26,   48,   51,    5,
182783         - /*    20 */    53,   27,   19,   11,   26,    9,   20,   51,    5,   53,
182784         - /*    30 */    27,   13,   22,   26,   28,   51,    5,   53,   27,   68,
182785         - /*    40 */     1,   26,   19,   11,   17,    9,   52,   10,   53,   27,
182786         - /*    50 */    23,   24,   26,   54,    3,    4,    2,   26,    6,   21,
182787         - /*    60 */    49,   71,    3,    4,    2,    7,   56,   59,   55,   59,
182788         - /*    70 */     4,    2,   12,   69,   58,   60,   18,   67,   62,   69,
182789         - /*    80 */    25,   66,    8,   14,    2,
       183318  + /*     0 */   105,   19,   63,    6,   26,   66,   65,   24,   24,   17,
       183319  + /*    10 */    63,    6,   26,   16,   65,   54,   24,   18,   63,    6,
       183320  + /*    20 */    26,   10,   65,   12,   24,   75,   59,   63,    6,   26,
       183321  + /*    30 */    13,   65,   75,   24,   20,   63,    6,   26,   74,   65,
       183322  + /*    40 */    56,   24,   27,   63,    6,   26,   73,   65,   21,   24,
       183323  + /*    50 */    23,   15,   30,   11,    1,   64,   22,   25,    9,   65,
       183324  + /*    60 */     7,   24,    3,    4,    5,    3,    4,    5,    3,   77,
       183325  + /*    70 */     4,    5,    3,   61,   23,   15,   60,   11,   80,   12,
       183326  + /*    80 */     2,   13,   68,   10,   29,   52,   55,   75,   31,   32,
       183327  + /*    90 */     8,   28,    5,    3,   51,   55,   72,   14,
182790 183328   };
182791 183329   static const fts5YYCODETYPE fts5yy_lookahead[] = {
182792         - /*     0 */    16,   17,   18,   19,   20,   21,    5,    6,   24,   17,
182793         - /*    10 */    18,   19,   20,   21,   11,   14,   24,   17,   18,   19,
182794         - /*    20 */    20,   21,    8,    9,   24,   11,   17,   18,   19,   20,
182795         - /*    30 */    21,   11,   12,   24,   17,   18,   19,   20,   21,   26,
182796         - /*    40 */     6,   24,    8,    9,   22,   11,   18,   11,   20,   21,
182797         - /*    50 */    24,   25,   24,   20,    1,    2,    3,   24,   23,   24,
182798         - /*    60 */     7,    0,    1,    2,    3,    6,   10,   11,   10,   11,
182799         - /*    70 */     2,    3,    9,   14,   11,   11,   22,   26,    7,   14,
182800         - /*    80 */    13,   11,    5,   11,    3,
       183330  + /*     0 */    16,   17,   18,   19,   20,   22,   22,   24,   24,   17,
       183331  + /*    10 */    18,   19,   20,    7,   22,    9,   24,   17,   18,   19,
       183332  + /*    20 */    20,   10,   22,    9,   24,   14,   17,   18,   19,   20,
       183333  + /*    30 */     9,   22,   14,   24,   17,   18,   19,   20,   26,   22,
       183334  + /*    40 */     9,   24,   17,   18,   19,   20,   26,   22,   21,   24,
       183335  + /*    50 */     6,    7,   13,    9,   10,   18,   21,   20,    5,   22,
       183336  + /*    60 */     5,   24,    3,    1,    2,    3,    1,    2,    3,    0,
       183337  + /*    70 */     1,    2,    3,   11,    6,    7,   11,    9,    5,    9,
       183338  + /*    80 */    10,    9,   11,   10,   12,    8,    9,   14,   24,   25,
       183339  + /*    90 */    23,   24,    2,    3,    8,    9,    9,    9,
182801 183340   };
182802         -#define fts5YY_SHIFT_USE_DFLT (85)
182803         -#define fts5YY_SHIFT_COUNT    (28)
       183341  +#define fts5YY_SHIFT_USE_DFLT (98)
       183342  +#define fts5YY_SHIFT_COUNT    (32)
182804 183343   #define fts5YY_SHIFT_MIN      (0)
182805         -#define fts5YY_SHIFT_MAX      (81)
       183344  +#define fts5YY_SHIFT_MAX      (90)
182806 183345   static const unsigned char fts5yy_shift_ofst[] = {
182807         - /*     0 */    34,   34,   34,   34,   34,   14,   20,    3,   36,    1,
182808         - /*    10 */    59,   64,   64,   65,   65,   53,   61,   56,   58,   63,
182809         - /*    20 */    68,   67,   70,   67,   71,   72,   67,   77,   81,
       183346  + /*     0 */    44,   44,   44,   44,   44,   44,   68,   70,   72,   14,
       183347  + /*    10 */    21,   73,   11,   18,   18,   31,   31,   62,   65,   69,
       183348  + /*    20 */    90,   77,   86,    6,   39,   53,   55,   59,   39,   87,
       183349  + /*    30 */    88,   39,   71,
182810 183350   };
182811         -#define fts5YY_REDUCE_USE_DFLT (-17)
182812         -#define fts5YY_REDUCE_COUNT (14)
182813         -#define fts5YY_REDUCE_MIN   (-16)
182814         -#define fts5YY_REDUCE_MAX   (54)
       183351  +#define fts5YY_REDUCE_USE_DFLT (-18)
       183352  +#define fts5YY_REDUCE_COUNT (16)
       183353  +#define fts5YY_REDUCE_MIN   (-17)
       183354  +#define fts5YY_REDUCE_MAX   (67)
182815 183355   static const signed char fts5yy_reduce_ofst[] = {
182816         - /*     0 */   -16,   -8,    0,    9,   17,   28,   26,   35,   33,   13,
182817         - /*    10 */    13,   22,   54,   13,   51,
       183356  + /*     0 */   -16,   -8,    0,    9,   17,   25,   37,  -17,   64,  -17,
       183357  + /*    10 */    67,   12,   12,   12,   20,   27,   35,
182818 183358   };
182819 183359   static const fts5YYACTIONTYPE fts5yy_default[] = {
182820         - /*     0 */    97,   97,   97,   97,   97,   76,   91,   97,   97,   96,
182821         - /*    10 */    96,   97,   97,   96,   96,   97,   97,   97,   97,   97,
182822         - /*    20 */    73,   89,   97,   90,   97,   97,   87,   97,   72,
       183360  + /*     0 */   104,  104,  104,  104,  104,  104,   89,  104,   98,  104,
       183361  + /*    10 */   104,  103,  103,  103,  103,  104,  104,  104,  104,  104,
       183362  + /*    20 */    85,  104,  104,  104,   94,  104,  104,   84,   96,  104,
       183363  + /*    30 */   104,   97,  104,
182823 183364   };
182824 183365   /********** End of lemon-generated parsing tables *****************************/
182825 183366   
182826 183367   /* The next table maps tokens (terminal symbols) into fallback tokens.  
182827 183368   ** If a construct like the following:
182828 183369   ** 
182829 183370   **      %fallback ID X Y Z.
................................................................................
182921 183462   #endif /* NDEBUG */
182922 183463   
182923 183464   #ifndef NDEBUG
182924 183465   /* For tracing shifts, the names of all terminals and nonterminals
182925 183466   ** are required.  The following table supplies these names */
182926 183467   static const char *const fts5yyTokenName[] = { 
182927 183468     "$",             "OR",            "AND",           "NOT",         
182928         -  "TERM",          "COLON",         "LP",            "RP",          
182929         -  "MINUS",         "LCP",           "RCP",           "STRING",      
       183469  +  "TERM",          "COLON",         "MINUS",         "LCP",         
       183470  +  "RCP",           "STRING",        "LP",            "RP",          
182930 183471     "COMMA",         "PLUS",          "STAR",          "error",       
182931 183472     "input",         "expr",          "cnearset",      "exprlist",    
182932         -  "nearset",       "colset",        "colsetlist",    "nearphrases", 
       183473  +  "colset",        "colsetlist",    "nearset",       "nearphrases", 
182933 183474     "phrase",        "neardist_opt",  "star_opt",    
182934 183475   };
182935 183476   #endif /* NDEBUG */
182936 183477   
182937 183478   #ifndef NDEBUG
182938 183479   /* For tracing reduce actions, the names of all rules are required.
182939 183480   */
182940 183481   static const char *const fts5yyRuleName[] = {
182941 183482    /*   0 */ "input ::= expr",
182942         - /*   1 */ "expr ::= expr AND expr",
182943         - /*   2 */ "expr ::= expr OR expr",
182944         - /*   3 */ "expr ::= expr NOT expr",
182945         - /*   4 */ "expr ::= LP expr RP",
182946         - /*   5 */ "expr ::= exprlist",
182947         - /*   6 */ "exprlist ::= cnearset",
182948         - /*   7 */ "exprlist ::= exprlist cnearset",
182949         - /*   8 */ "cnearset ::= nearset",
182950         - /*   9 */ "cnearset ::= colset COLON nearset",
182951         - /*  10 */ "colset ::= MINUS LCP colsetlist RCP",
182952         - /*  11 */ "colset ::= LCP colsetlist RCP",
182953         - /*  12 */ "colset ::= STRING",
182954         - /*  13 */ "colset ::= MINUS STRING",
182955         - /*  14 */ "colsetlist ::= colsetlist STRING",
182956         - /*  15 */ "colsetlist ::= STRING",
182957         - /*  16 */ "nearset ::= phrase",
182958         - /*  17 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
182959         - /*  18 */ "nearphrases ::= phrase",
182960         - /*  19 */ "nearphrases ::= nearphrases phrase",
182961         - /*  20 */ "neardist_opt ::=",
182962         - /*  21 */ "neardist_opt ::= COMMA STRING",
182963         - /*  22 */ "phrase ::= phrase PLUS STRING star_opt",
182964         - /*  23 */ "phrase ::= STRING star_opt",
182965         - /*  24 */ "star_opt ::= STAR",
182966         - /*  25 */ "star_opt ::=",
       183483  + /*   1 */ "colset ::= MINUS LCP colsetlist RCP",
       183484  + /*   2 */ "colset ::= LCP colsetlist RCP",
       183485  + /*   3 */ "colset ::= STRING",
       183486  + /*   4 */ "colset ::= MINUS STRING",
       183487  + /*   5 */ "colsetlist ::= colsetlist STRING",
       183488  + /*   6 */ "colsetlist ::= STRING",
       183489  + /*   7 */ "expr ::= expr AND expr",
       183490  + /*   8 */ "expr ::= expr OR expr",
       183491  + /*   9 */ "expr ::= expr NOT expr",
       183492  + /*  10 */ "expr ::= colset COLON LP expr RP",
       183493  + /*  11 */ "expr ::= LP expr RP",
       183494  + /*  12 */ "expr ::= exprlist",
       183495  + /*  13 */ "exprlist ::= cnearset",
       183496  + /*  14 */ "exprlist ::= exprlist cnearset",
       183497  + /*  15 */ "cnearset ::= nearset",
       183498  + /*  16 */ "cnearset ::= colset COLON nearset",
       183499  + /*  17 */ "nearset ::= phrase",
       183500  + /*  18 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
       183501  + /*  19 */ "nearphrases ::= phrase",
       183502  + /*  20 */ "nearphrases ::= nearphrases phrase",
       183503  + /*  21 */ "neardist_opt ::=",
       183504  + /*  22 */ "neardist_opt ::= COMMA STRING",
       183505  + /*  23 */ "phrase ::= phrase PLUS STRING star_opt",
       183506  + /*  24 */ "phrase ::= STRING star_opt",
       183507  + /*  25 */ "star_opt ::= STAR",
       183508  + /*  26 */ "star_opt ::=",
182967 183509   };
182968 183510   #endif /* NDEBUG */
182969 183511   
182970 183512   
182971 183513   #if fts5YYSTACKDEPTH<=0
182972 183514   /*
182973 183515   ** Try to increase the size of the parser stack.  Return the number
................................................................................
183089 183631       case 17: /* expr */
183090 183632       case 18: /* cnearset */
183091 183633       case 19: /* exprlist */
183092 183634   {
183093 183635    sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy24)); 
183094 183636   }
183095 183637         break;
183096         -    case 20: /* nearset */
       183638  +    case 20: /* colset */
       183639  +    case 21: /* colsetlist */
       183640  +{
       183641  + sqlite3_free((fts5yypminor->fts5yy11)); 
       183642  +}
       183643  +      break;
       183644  +    case 22: /* nearset */
183097 183645       case 23: /* nearphrases */
183098 183646   {
183099 183647    sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy46)); 
183100 183648   }
183101         -      break;
183102         -    case 21: /* colset */
183103         -    case 22: /* colsetlist */
183104         -{
183105         - sqlite3_free((fts5yypminor->fts5yy11)); 
183106         -}
183107 183649         break;
183108 183650       case 24: /* phrase */
183109 183651   {
183110 183652    sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy53)); 
183111 183653   }
183112 183654         break;
183113 183655   /********* End destructor definitions *****************************************/
................................................................................
183358 183900   ** is used during the reduce.
183359 183901   */
183360 183902   static const struct {
183361 183903     fts5YYCODETYPE lhs;         /* Symbol on the left-hand side of the rule */
183362 183904     unsigned char nrhs;     /* Number of right-hand side symbols in the rule */
183363 183905   } fts5yyRuleInfo[] = {
183364 183906     { 16, 1 },
       183907  +  { 20, 4 },
       183908  +  { 20, 3 },
       183909  +  { 20, 1 },
       183910  +  { 20, 2 },
       183911  +  { 21, 2 },
       183912  +  { 21, 1 },
183365 183913     { 17, 3 },
183366 183914     { 17, 3 },
183367 183915     { 17, 3 },
       183916  +  { 17, 5 },
183368 183917     { 17, 3 },
183369 183918     { 17, 1 },
183370 183919     { 19, 1 },
183371 183920     { 19, 2 },
183372 183921     { 18, 1 },
183373 183922     { 18, 3 },
183374         -  { 21, 4 },
183375         -  { 21, 3 },
183376         -  { 21, 1 },
183377         -  { 21, 2 },
183378         -  { 22, 2 },
183379 183923     { 22, 1 },
183380         -  { 20, 1 },
183381         -  { 20, 5 },
       183924  +  { 22, 5 },
183382 183925     { 23, 1 },
183383 183926     { 23, 2 },
183384 183927     { 25, 0 },
183385 183928     { 25, 2 },
183386 183929     { 24, 4 },
183387 183930     { 24, 2 },
183388 183931     { 26, 1 },
................................................................................
183449 183992     **     break;
183450 183993     */
183451 183994   /********** Begin reduce actions **********************************************/
183452 183995           fts5YYMINORTYPE fts5yylhsminor;
183453 183996         case 0: /* input ::= expr */
183454 183997   { sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); }
183455 183998           break;
183456         -      case 1: /* expr ::= expr AND expr */
       183999  +      case 1: /* colset ::= MINUS LCP colsetlist RCP */
       184000  +{ 
       184001  +    fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
       184002  +}
       184003  +        break;
       184004  +      case 2: /* colset ::= LCP colsetlist RCP */
       184005  +{ fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; }
       184006  +        break;
       184007  +      case 3: /* colset ::= STRING */
       184008  +{
       184009  +  fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
       184010  +}
       184011  +  fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
       184012  +        break;
       184013  +      case 4: /* colset ::= MINUS STRING */
       184014  +{
       184015  +  fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
       184016  +  fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
       184017  +}
       184018  +        break;
       184019  +      case 5: /* colsetlist ::= colsetlist STRING */
       184020  +{ 
       184021  +  fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
       184022  +  fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
       184023  +        break;
       184024  +      case 6: /* colsetlist ::= STRING */
       184025  +{ 
       184026  +  fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0); 
       184027  +}
       184028  +  fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
       184029  +        break;
       184030  +      case 7: /* expr ::= expr AND expr */
183457 184031   {
183458 184032     fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
183459 184033   }
183460 184034     fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183461 184035           break;
183462         -      case 2: /* expr ::= expr OR expr */
       184036  +      case 8: /* expr ::= expr OR expr */
183463 184037   {
183464 184038     fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
183465 184039   }
183466 184040     fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183467 184041           break;
183468         -      case 3: /* expr ::= expr NOT expr */
       184042  +      case 9: /* expr ::= expr NOT expr */
183469 184043   {
183470 184044     fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
183471 184045   }
183472 184046     fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183473 184047           break;
183474         -      case 4: /* expr ::= LP expr RP */
       184048  +      case 10: /* expr ::= colset COLON LP expr RP */
       184049  +{
       184050  +  sqlite3Fts5ParseSetColset(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[-4].minor.fts5yy11);
       184051  +  fts5yylhsminor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;
       184052  +}
       184053  +  fts5yymsp[-4].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
       184054  +        break;
       184055  +      case 11: /* expr ::= LP expr RP */
183475 184056   {fts5yymsp[-2].minor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;}
183476 184057           break;
183477         -      case 5: /* expr ::= exprlist */
183478         -      case 6: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==6);
       184058  +      case 12: /* expr ::= exprlist */
       184059  +      case 13: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==13);
183479 184060   {fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;}
183480 184061     fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183481 184062           break;
183482         -      case 7: /* exprlist ::= exprlist cnearset */
       184063  +      case 14: /* exprlist ::= exprlist cnearset */
183483 184064   {
183484 184065     fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24);
183485 184066   }
183486 184067     fts5yymsp[-1].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183487 184068           break;
183488         -      case 8: /* cnearset ::= nearset */
       184069  +      case 15: /* cnearset ::= nearset */
183489 184070   { 
183490 184071     fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46); 
183491 184072   }
183492 184073     fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183493 184074           break;
183494         -      case 9: /* cnearset ::= colset COLON nearset */
       184075  +      case 16: /* cnearset ::= colset COLON nearset */
183495 184076   { 
183496         -  sqlite3Fts5ParseSetColset(pParse, fts5yymsp[0].minor.fts5yy46, fts5yymsp[-2].minor.fts5yy11);
183497 184077     fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46); 
       184078  +  sqlite3Fts5ParseSetColset(pParse, fts5yylhsminor.fts5yy24, fts5yymsp[-2].minor.fts5yy11);
183498 184079   }
183499 184080     fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183500 184081           break;
183501         -      case 10: /* colset ::= MINUS LCP colsetlist RCP */
183502         -{ 
183503         -    fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
183504         -}
183505         -        break;
183506         -      case 11: /* colset ::= LCP colsetlist RCP */
183507         -{ fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; }
183508         -        break;
183509         -      case 12: /* colset ::= STRING */
183510         -{
183511         -  fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
183512         -}
183513         -  fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
183514         -        break;
183515         -      case 13: /* colset ::= MINUS STRING */
183516         -{
183517         -  fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
183518         -  fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
183519         -}
183520         -        break;
183521         -      case 14: /* colsetlist ::= colsetlist STRING */
183522         -{ 
183523         -  fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
183524         -  fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
183525         -        break;
183526         -      case 15: /* colsetlist ::= STRING */
183527         -{ 
183528         -  fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0); 
183529         -}
183530         -  fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
183531         -        break;
183532         -      case 16: /* nearset ::= phrase */
       184082  +      case 17: /* nearset ::= phrase */
183533 184083   { fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); }
183534 184084     fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
183535 184085           break;
183536         -      case 17: /* nearset ::= STRING LP nearphrases neardist_opt RP */
       184086  +      case 18: /* nearset ::= STRING LP nearphrases neardist_opt RP */
183537 184087   {
183538 184088     sqlite3Fts5ParseNear(pParse, &fts5yymsp[-4].minor.fts5yy0);
183539 184089     sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy46, &fts5yymsp[-1].minor.fts5yy0);
183540 184090     fts5yylhsminor.fts5yy46 = fts5yymsp[-2].minor.fts5yy46;
183541 184091   }
183542 184092     fts5yymsp[-4].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
183543 184093           break;
183544         -      case 18: /* nearphrases ::= phrase */
       184094  +      case 19: /* nearphrases ::= phrase */
183545 184095   { 
183546 184096     fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); 
183547 184097   }
183548 184098     fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
183549 184099           break;
183550         -      case 19: /* nearphrases ::= nearphrases phrase */
       184100  +      case 20: /* nearphrases ::= nearphrases phrase */
183551 184101   {
183552 184102     fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy46, fts5yymsp[0].minor.fts5yy53);
183553 184103   }
183554 184104     fts5yymsp[-1].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
183555 184105           break;
183556         -      case 20: /* neardist_opt ::= */
       184106  +      case 21: /* neardist_opt ::= */
183557 184107   { fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
183558 184108           break;
183559         -      case 21: /* neardist_opt ::= COMMA STRING */
       184109  +      case 22: /* neardist_opt ::= COMMA STRING */
183560 184110   { fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
183561 184111           break;
183562         -      case 22: /* phrase ::= phrase PLUS STRING star_opt */
       184112  +      case 23: /* phrase ::= phrase PLUS STRING star_opt */
183563 184113   { 
183564 184114     fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy53, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
183565 184115   }
183566 184116     fts5yymsp[-3].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
183567 184117           break;
183568         -      case 23: /* phrase ::= STRING star_opt */
       184118  +      case 24: /* phrase ::= STRING star_opt */
183569 184119   { 
183570 184120     fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
183571 184121   }
183572 184122     fts5yymsp[-1].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
183573 184123           break;
183574         -      case 24: /* star_opt ::= STAR */
       184124  +      case 25: /* star_opt ::= STAR */
183575 184125   { fts5yymsp[0].minor.fts5yy4 = 1; }
183576 184126           break;
183577         -      case 25: /* star_opt ::= */
       184127  +      case 26: /* star_opt ::= */
183578 184128   { fts5yymsp[1].minor.fts5yy4 = 0; }
183579 184129           break;
183580 184130         default:
183581 184131           break;
183582 184132   /********** End reduce actions ************************************************/
183583 184133     };
183584 184134     assert( fts5yyruleno<sizeof(fts5yyRuleInfo)/sizeof(fts5yyRuleInfo[0]) );
................................................................................
186113 186663   }
186114 186664   
186115 186665   static void *fts5ParseAlloc(u64 t){ return sqlite3_malloc((int)t); }
186116 186666   static void fts5ParseFree(void *p){ sqlite3_free(p); }
186117 186667   
186118 186668   static int sqlite3Fts5ExprNew(
186119 186669     Fts5Config *pConfig,            /* FTS5 Configuration */
       186670  +  int iCol,
186120 186671     const char *zExpr,              /* Expression text */
186121 186672     Fts5Expr **ppNew, 
186122 186673     char **pzErr
186123 186674   ){
186124 186675     Fts5Parse sParse;
186125 186676     Fts5Token token;
186126 186677     const char *z = zExpr;
................................................................................
186136 186687     sParse.pConfig = pConfig;
186137 186688   
186138 186689     do {
186139 186690       t = fts5ExprGetToken(&sParse, &z, &token);
186140 186691       sqlite3Fts5Parser(pEngine, t, token, &sParse);
186141 186692     }while( sParse.rc==SQLITE_OK && t!=FTS5_EOF );
186142 186693     sqlite3Fts5ParserFree(pEngine, fts5ParseFree);
       186694  +
       186695  +  /* If the LHS of the MATCH expression was a user column, apply the
       186696  +  ** implicit column-filter.  */
       186697  +  if( iCol<pConfig->nCol && sParse.pExpr && sParse.rc==SQLITE_OK ){
       186698  +    int n = sizeof(Fts5Colset);
       186699  +    Fts5Colset *pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&sParse.rc, n);
       186700  +    if( pColset ){
       186701  +      pColset->nCol = 1;
       186702  +      pColset->aiCol[0] = iCol;
       186703  +      sqlite3Fts5ParseSetColset(&sParse, sParse.pExpr, pColset);
       186704  +    }
       186705  +  }
186143 186706   
186144 186707     assert( sParse.rc!=SQLITE_OK || sParse.zErr==0 );
186145 186708     if( sParse.rc==SQLITE_OK ){
186146 186709       *ppNew = pNew = sqlite3_malloc(sizeof(Fts5Expr));
186147 186710       if( pNew==0 ){
186148 186711         sParse.rc = SQLITE_NOMEM;
186149 186712         sqlite3Fts5ParseNodeFree(sParse.pExpr);
................................................................................
187786 188349       assert( pParse->rc!=SQLITE_OK );
187787 188350       sqlite3_free(pColset);
187788 188351     }
187789 188352   
187790 188353     return pRet;
187791 188354   }
187792 188355   
       188356  +/*
       188357  +** If argument pOrig is NULL, or if (*pRc) is set to anything other than
       188358  +** SQLITE_OK when this function is called, NULL is returned. 
       188359  +**
       188360  +** Otherwise, a copy of (*pOrig) is made into memory obtained from
       188361  +** sqlite3Fts5MallocZero() and a pointer to it returned. If the allocation
       188362  +** fails, (*pRc) is set to SQLITE_NOMEM and NULL is returned.
       188363  +*/
       188364  +static Fts5Colset *fts5CloneColset(int *pRc, Fts5Colset *pOrig){
       188365  +  Fts5Colset *pRet;
       188366  +  if( pOrig ){
       188367  +    int nByte = sizeof(Fts5Colset) + (pOrig->nCol-1) * sizeof(int);
       188368  +    pRet = (Fts5Colset*)sqlite3Fts5MallocZero(pRc, nByte);
       188369  +    if( pRet ){ 
       188370  +      memcpy(pRet, pOrig, nByte);
       188371  +    }
       188372  +  }else{
       188373  +    pRet = 0;
       188374  +  }
       188375  +  return pRet;
       188376  +}
       188377  +
       188378  +/*
       188379  +** Remove from colset pColset any columns that are not also in colset pMerge.
       188380  +*/
       188381  +static void fts5MergeColset(Fts5Colset *pColset, Fts5Colset *pMerge){
       188382  +  int iIn = 0;          /* Next input in pColset */
       188383  +  int iMerge = 0;       /* Next input in pMerge */
       188384  +  int iOut = 0;         /* Next output slot in pColset */
       188385  +
       188386  +  while( iIn<pColset->nCol && iMerge<pMerge->nCol ){
       188387  +    int iDiff = pColset->aiCol[iIn] - pMerge->aiCol[iMerge];
       188388  +    if( iDiff==0 ){
       188389  +      pColset->aiCol[iOut++] = pMerge->aiCol[iMerge];
       188390  +      iMerge++;
       188391  +      iIn++;
       188392  +    }else if( iDiff>0 ){
       188393  +      iMerge++;
       188394  +    }else{
       188395  +      iIn++;
       188396  +    }
       188397  +  }
       188398  +  pColset->nCol = iOut;
       188399  +}
       188400  +
       188401  +/*
       188402  +** Recursively apply colset pColset to expression node pNode and all of
       188403  +** its decendents. If (*ppFree) is not NULL, it contains a spare copy
       188404  +** of pColset. This function may use the spare copy and set (*ppFree) to
       188405  +** zero, or it may create copies of pColset using fts5CloneColset().
       188406  +*/
       188407  +static void fts5ParseSetColset(
       188408  +  Fts5Parse *pParse, 
       188409  +  Fts5ExprNode *pNode, 
       188410  +  Fts5Colset *pColset,
       188411  +  Fts5Colset **ppFree
       188412  +){
       188413  +  if( pParse->rc==SQLITE_OK ){
       188414  +    assert( pNode->eType==FTS5_TERM || pNode->eType==FTS5_STRING 
       188415  +         || pNode->eType==FTS5_AND  || pNode->eType==FTS5_OR
       188416  +         || pNode->eType==FTS5_NOT  || pNode->eType==FTS5_EOF
       188417  +    );
       188418  +    if( pNode->eType==FTS5_STRING || pNode->eType==FTS5_TERM ){
       188419  +      Fts5ExprNearset *pNear = pNode->pNear;
       188420  +      if( pNear->pColset ){
       188421  +        fts5MergeColset(pNear->pColset, pColset);
       188422  +        if( pNear->pColset->nCol==0 ){
       188423  +          pNode->eType = FTS5_EOF;
       188424  +          pNode->xNext = 0;
       188425  +        }
       188426  +      }else if( *ppFree ){
       188427  +        pNear->pColset = pColset;
       188428  +        *ppFree = 0;
       188429  +      }else{
       188430  +        pNear->pColset = fts5CloneColset(&pParse->rc, pColset);
       188431  +      }
       188432  +    }else{
       188433  +      int i;
       188434  +      assert( pNode->eType!=FTS5_EOF || pNode->nChild==0 );
       188435  +      for(i=0; i<pNode->nChild; i++){
       188436  +        fts5ParseSetColset(pParse, pNode->apChild[i], pColset, ppFree);
       188437  +      }
       188438  +    }
       188439  +  }
       188440  +}
       188441  +
       188442  +/*
       188443  +** Apply colset pColset to expression node pExpr and all of its descendents.
       188444  +*/
187793 188445   static void sqlite3Fts5ParseSetColset(
187794 188446     Fts5Parse *pParse, 
187795         -  Fts5ExprNearset *pNear, 
       188447  +  Fts5ExprNode *pExpr, 
187796 188448     Fts5Colset *pColset 
187797 188449   ){
       188450  +  Fts5Colset *pFree = pColset;
187798 188451     if( pParse->pConfig->eDetail==FTS5_DETAIL_NONE ){
187799 188452       pParse->rc = SQLITE_ERROR;
187800 188453       pParse->zErr = sqlite3_mprintf(
187801 188454         "fts5: column queries are not supported (detail=none)"
187802 188455       );
187803         -    sqlite3_free(pColset);
187804         -    return;
       188456  +  }else{
       188457  +    fts5ParseSetColset(pParse, pExpr, pColset, &pFree);
187805 188458     }
187806         -
187807         -  if( pNear ){
187808         -    pNear->pColset = pColset;
187809         -  }else{
187810         -    sqlite3_free(pColset);
187811         -  }
       188459  +  sqlite3_free(pFree);
187812 188460   }
187813 188461   
187814 188462   static void fts5ExprAssignXNext(Fts5ExprNode *pNode){
187815 188463     switch( pNode->eType ){
187816 188464       case FTS5_STRING: {
187817 188465         Fts5ExprNearset *pNear = pNode->pNear;
187818 188466         if( pNear->nPhrase==1 && pNear->apPhrase[0]->nTerm==1 
................................................................................
188258 188906       azConfig[i++] = (const char*)sqlite3_value_text(apVal[iArg]);
188259 188907     }
188260 188908   
188261 188909     zExpr = (const char*)sqlite3_value_text(apVal[0]);
188262 188910   
188263 188911     rc = sqlite3Fts5ConfigParse(pGlobal, db, nConfig, azConfig, &pConfig, &zErr);
188264 188912     if( rc==SQLITE_OK ){
188265         -    rc = sqlite3Fts5ExprNew(pConfig, zExpr, &pExpr, &zErr);
       188913  +    rc = sqlite3Fts5ExprNew(pConfig, pConfig->nCol, zExpr, &pExpr, &zErr);
188266 188914     }
188267 188915     if( rc==SQLITE_OK ){
188268 188916       char *zText;
188269 188917       if( pExpr->pRoot->xNext==0 ){
188270 188918         zText = sqlite3_mprintf("");
188271 188919       }else if( bTcl ){
188272 188920         zText = fts5ExprPrintTcl(pConfig, zNearsetCmd, pExpr->pRoot);
................................................................................
189774 190422   static void fts5CloseReader(Fts5Index *p){
189775 190423     if( p->pReader ){
189776 190424       sqlite3_blob *pReader = p->pReader;
189777 190425       p->pReader = 0;
189778 190426       sqlite3_blob_close(pReader);
189779 190427     }
189780 190428   }
189781         -
189782 190429   
189783 190430   /*
189784 190431   ** Retrieve a record from the %_data table.
189785 190432   **
189786 190433   ** If an error occurs, NULL is returned and an error left in the 
189787 190434   ** Fts5Index object.
189788 190435   */
................................................................................
192026 192673   static void fts5MultiIterNext2(
192027 192674     Fts5Index *p, 
192028 192675     Fts5Iter *pIter,
192029 192676     int *pbNewTerm                  /* OUT: True if *might* be new term */
192030 192677   ){
192031 192678     assert( pIter->bSkipEmpty );
192032 192679     if( p->rc==SQLITE_OK ){
192033         -    do {
       192680  +    *pbNewTerm = 0;
       192681  +    do{
192034 192682         int iFirst = pIter->aFirst[1].iFirst;
192035 192683         Fts5SegIter *pSeg = &pIter->aSeg[iFirst];
192036 192684         int bNewTerm = 0;
192037 192685   
192038 192686         assert( p->rc==SQLITE_OK );
192039 192687         pSeg->xNext(p, pSeg, &bNewTerm);
192040 192688         if( pSeg->pLeaf==0 || bNewTerm 
192041 192689          || fts5MultiIterAdvanceRowid(pIter, iFirst, &pSeg)
192042 192690         ){
192043 192691           fts5MultiIterAdvanced(p, pIter, iFirst, 1);
192044 192692           fts5MultiIterSetEof(pIter);
192045 192693           *pbNewTerm = 1;
192046         -      }else{
192047         -        *pbNewTerm = 0;
192048 192694         }
192049 192695         fts5AssertMultiIterSetup(p, pIter);
192050 192696   
192051 192697       }while( fts5MultiIterIsEmpty(p, pIter) );
192052 192698     }
192053 192699   }
192054 192700   
................................................................................
192306 192952     while( p<pEnd && *p!=0x01 ){
192307 192953       while( *p++ & 0x80 );
192308 192954     }
192309 192955   
192310 192956     return p - (*pa);
192311 192957   }
192312 192958   
192313         -static int fts5IndexExtractColset (
       192959  +static void fts5IndexExtractColset(
       192960  +  int *pRc,
192314 192961     Fts5Colset *pColset,            /* Colset to filter on */
192315 192962     const u8 *pPos, int nPos,       /* Position list */
192316 192963     Fts5Buffer *pBuf                /* Output buffer */
192317 192964   ){
192318         -  int rc = SQLITE_OK;
192319         -  int i;
192320         -
192321         -  fts5BufferZero(pBuf);
192322         -  for(i=0; i<pColset->nCol; i++){
192323         -    const u8 *pSub = pPos;
192324         -    int nSub = fts5IndexExtractCol(&pSub, nPos, pColset->aiCol[i]);
192325         -    if( nSub ){
192326         -      fts5BufferAppendBlob(&rc, pBuf, nSub, pSub);
       192965  +  if( *pRc==SQLITE_OK ){
       192966  +    int i;
       192967  +    fts5BufferZero(pBuf);
       192968  +    for(i=0; i<pColset->nCol; i++){
       192969  +      const u8 *pSub = pPos;
       192970  +      int nSub = fts5IndexExtractCol(&pSub, nPos, pColset->aiCol[i]);
       192971  +      if( nSub ){
       192972  +        fts5BufferAppendBlob(pRc, pBuf, nSub, pSub);
       192973  +      }
192327 192974       }
192328 192975     }
192329         -  return rc;
192330 192976   }
192331 192977   
192332 192978   /*
192333 192979   ** xSetOutputs callback used by detail=none tables.
192334 192980   */
192335 192981   static void fts5IterSetOutputs_None(Fts5Iter *pIter, Fts5SegIter *pSeg){
192336 192982     assert( pIter->pIndex->pConfig->eDetail==FTS5_DETAIL_NONE );
................................................................................
192446 193092       /* All data is stored on the current page. Populate the output 
192447 193093       ** variables to point into the body of the page object. */
192448 193094       const u8 *a = &pSeg->pLeaf->p[pSeg->iLeafOffset];
192449 193095       if( pColset->nCol==1 ){
192450 193096         pIter->base.nData = fts5IndexExtractCol(&a, pSeg->nPos,pColset->aiCol[0]);
192451 193097         pIter->base.pData = a;
192452 193098       }else{
       193099  +      int *pRc = &pIter->pIndex->rc;
192453 193100         fts5BufferZero(&pIter->poslist);
192454         -      fts5IndexExtractColset(pColset, a, pSeg->nPos, &pIter->poslist);
       193101  +      fts5IndexExtractColset(pRc, pColset, a, pSeg->nPos, &pIter->poslist);
192455 193102         pIter->base.pData = pIter->poslist.p;
192456 193103         pIter->base.nData = pIter->poslist.n;
192457 193104       }
192458 193105     }else{
192459 193106       /* The data is distributed over two or more pages. Copy it into the
192460 193107       ** Fts5Iter.poslist buffer and then set the output pointer to point
192461 193108       ** to this buffer.  */
................................................................................
192992 193639   }
192993 193640   
192994 193641   static void fts5WriteFlushLeaf(Fts5Index *p, Fts5SegWriter *pWriter){
192995 193642     static const u8 zero[] = { 0x00, 0x00, 0x00, 0x00 };
192996 193643     Fts5PageWriter *pPage = &pWriter->writer;
192997 193644     i64 iRowid;
192998 193645   
192999         -static int nCall = 0;
193000         -nCall++;
193001         -
193002 193646     assert( (pPage->pgidx.n==0)==(pWriter->bFirstTermInPage) );
193003 193647   
193004 193648     /* Set the szLeaf header field. */
193005 193649     assert( 0==fts5GetU16(&pPage->buf.p[2]) );
193006 193650     fts5PutU16(&pPage->buf.p[2], (u16)pPage->buf.n);
193007 193651   
193008 193652     if( pWriter->bFirstTermInPage ){
................................................................................
194278 194922     p->bDelete = bDelete;
194279 194923     return fts5IndexReturn(p);
194280 194924   }
194281 194925   
194282 194926   /*
194283 194927   ** Commit data to disk.
194284 194928   */
194285         -static int sqlite3Fts5IndexSync(Fts5Index *p, int bCommit){
       194929  +static int sqlite3Fts5IndexSync(Fts5Index *p){
194286 194930     assert( p->rc==SQLITE_OK );
194287 194931     fts5IndexFlush(p);
194288         -  if( bCommit ) fts5CloseReader(p);
       194932  +  fts5CloseReader(p);
194289 194933     return fts5IndexReturn(p);
194290 194934   }
194291 194935   
194292 194936   /*
194293 194937   ** Discard any data stored in the in-memory hash tables. Do not write it
194294 194938   ** to the database. Additionally, assume that the contents of the %_data
194295 194939   ** table may have changed on disk. So any in-memory caches of %_data 
................................................................................
196145 196789   **       * An == rowid constraint:       cost=10.0
196146 196790   **
196147 196791   ** Costs are not modified by the ORDER BY clause.
196148 196792   */
196149 196793   static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
196150 196794     Fts5Table *pTab = (Fts5Table*)pVTab;
196151 196795     Fts5Config *pConfig = pTab->pConfig;
       196796  +  const int nCol = pConfig->nCol;
196152 196797     int idxFlags = 0;               /* Parameter passed through to xFilter() */
196153 196798     int bHasMatch;
196154 196799     int iNext;
196155 196800     int i;
196156 196801   
196157 196802     struct Constraint {
196158 196803       int op;                       /* Mask against sqlite3_index_constraint.op */
................................................................................
196170 196815                                       FTS5_BI_ROWID_LE, 0, 0, -1},
196171 196816       {SQLITE_INDEX_CONSTRAINT_GT|SQLITE_INDEX_CONSTRAINT_GE, 
196172 196817                                       FTS5_BI_ROWID_GE, 0, 0, -1},
196173 196818     };
196174 196819   
196175 196820     int aColMap[3];
196176 196821     aColMap[0] = -1;
196177         -  aColMap[1] = pConfig->nCol;
196178         -  aColMap[2] = pConfig->nCol+1;
       196822  +  aColMap[1] = nCol;
       196823  +  aColMap[2] = nCol+1;
196179 196824   
196180 196825     /* Set idxFlags flags for all WHERE clause terms that will be used. */
196181 196826     for(i=0; i<pInfo->nConstraint; i++){
196182 196827       struct sqlite3_index_constraint *p = &pInfo->aConstraint[i];
196183         -    int j;
196184         -    for(j=0; j<ArraySize(aConstraint); j++){
196185         -      struct Constraint *pC = &aConstraint[j];
196186         -      if( p->iColumn==aColMap[pC->iCol] && p->op & pC->op ){
196187         -        if( p->usable ){
       196828  +    int iCol = p->iColumn;
       196829  +
       196830  +    if( (p->op==SQLITE_INDEX_CONSTRAINT_MATCH && iCol>=0 && iCol<=nCol)
       196831  +     || (p->op==SQLITE_INDEX_CONSTRAINT_EQ && iCol==nCol)
       196832  +    ){
       196833  +      /* A MATCH operator or equivalent */
       196834  +      if( p->usable ){
       196835  +        idxFlags = (idxFlags & 0xFFFF) | FTS5_BI_MATCH | (iCol << 16);
       196836  +        aConstraint[0].iConsIndex = i;
       196837  +      }else{
       196838  +        /* As there exists an unusable MATCH constraint this is an 
       196839  +        ** unusable plan. Set a prohibitively high cost. */
       196840  +        pInfo->estimatedCost = 1e50;
       196841  +        return SQLITE_OK;
       196842  +      }
       196843  +    }else{
       196844  +      int j;
       196845  +      for(j=1; j<ArraySize(aConstraint); j++){
       196846  +        struct Constraint *pC = &aConstraint[j];
       196847  +        if( iCol==aColMap[pC->iCol] && p->op & pC->op && p->usable ){
196188 196848             pC->iConsIndex = i;
196189 196849             idxFlags |= pC->fts5op;
196190         -        }else if( j==0 ){
196191         -          /* As there exists an unusable MATCH constraint this is an 
196192         -          ** unusable plan. Set a prohibitively high cost. */
196193         -          pInfo->estimatedCost = 1e50;
196194         -          return SQLITE_OK;
196195 196850           }
196196 196851         }
196197 196852       }
196198 196853     }
196199 196854   
196200 196855     /* Set idxFlags flags for the ORDER BY clause */
196201 196856     if( pInfo->nOrderBy==1 ){
................................................................................
196762 197417     int bDesc;                      /* True if ORDER BY [rank|rowid] DESC */
196763 197418     int bOrderByRank;               /* True if ORDER BY rank */
196764 197419     sqlite3_value *pMatch = 0;      /* <tbl> MATCH ? expression (or NULL) */
196765 197420     sqlite3_value *pRank = 0;       /* rank MATCH ? expression (or NULL) */
196766 197421     sqlite3_value *pRowidEq = 0;    /* rowid = ? expression (or NULL) */
196767 197422     sqlite3_value *pRowidLe = 0;    /* rowid <= ? expression (or NULL) */
196768 197423     sqlite3_value *pRowidGe = 0;    /* rowid >= ? expression (or NULL) */
       197424  +  int iCol;                       /* Column on LHS of MATCH operator */
196769 197425     char **pzErrmsg = pConfig->pzErrmsg;
196770 197426   
196771 197427     UNUSED_PARAM(zUnused);
196772 197428     UNUSED_PARAM(nVal);
196773 197429   
196774 197430     if( pCsr->ePlan ){
196775 197431       fts5FreeCursorComponents(pCsr);
................................................................................
196792 197448     ** order as the corresponding entries in the struct at the top of
196793 197449     ** fts5BestIndexMethod().  */
196794 197450     if( BitFlagTest(idxNum, FTS5_BI_MATCH) ) pMatch = apVal[iVal++];
196795 197451     if( BitFlagTest(idxNum, FTS5_BI_RANK) ) pRank = apVal[iVal++];
196796 197452     if( BitFlagTest(idxNum, FTS5_BI_ROWID_EQ) ) pRowidEq = apVal[iVal++];
196797 197453     if( BitFlagTest(idxNum, FTS5_BI_ROWID_LE) ) pRowidLe = apVal[iVal++];
196798 197454     if( BitFlagTest(idxNum, FTS5_BI_ROWID_GE) ) pRowidGe = apVal[iVal++];
       197455  +  iCol = (idxNum>>16);
       197456  +  assert( iCol>=0 && iCol<=pConfig->nCol );
196799 197457     assert( iVal==nVal );
196800 197458     bOrderByRank = ((idxNum & FTS5_BI_ORDER_RANK) ? 1 : 0);
196801 197459     pCsr->bDesc = bDesc = ((idxNum & FTS5_BI_ORDER_DESC) ? 1 : 0);
196802 197460   
196803 197461     /* Set the cursor upper and lower rowid limits. Only some strategies 
196804 197462     ** actually use them. This is ok, as the xBestIndex() method leaves the
196805 197463     ** sqlite3_index_constraint.omit flag clear for range constraints
................................................................................
196838 197496         if( zExpr[0]=='*' ){
196839 197497           /* The user has issued a query of the form "MATCH '*...'". This
196840 197498           ** indicates that the MATCH expression is not a full text query,
196841 197499           ** but a request for an internal parameter.  */
196842 197500           rc = fts5SpecialMatch(pTab, pCsr, &zExpr[1]);
196843 197501         }else{
196844 197502           char **pzErr = &pTab->base.zErrMsg;
196845         -        rc = sqlite3Fts5ExprNew(pConfig, zExpr, &pCsr->pExpr, pzErr);
       197503  +        rc = sqlite3Fts5ExprNew(pConfig, iCol, zExpr, &pCsr->pExpr, pzErr);
196846 197504           if( rc==SQLITE_OK ){
196847 197505             if( bOrderByRank ){
196848 197506               pCsr->ePlan = FTS5_PLAN_SORTED_MATCH;
196849 197507               rc = fts5CursorFirstSorted(pTab, pCsr, bDesc);
196850 197508             }else{
196851 197509               pCsr->ePlan = FTS5_PLAN_MATCH;
196852 197510               rc = fts5CursorFirst(pTab, pCsr, bDesc);
................................................................................
197218 197876   */
197219 197877   static int fts5SyncMethod(sqlite3_vtab *pVtab){
197220 197878     int rc;
197221 197879     Fts5Table *pTab = (Fts5Table*)pVtab;
197222 197880     fts5CheckTransactionState(pTab, FTS5_SYNC, 0);
197223 197881     pTab->pConfig->pzErrmsg = &pTab->base.zErrMsg;
197224 197882     fts5TripCursors(pTab);
197225         -  rc = sqlite3Fts5StorageSync(pTab->pStorage, 1);
       197883  +  rc = sqlite3Fts5StorageSync(pTab->pStorage);
197226 197884     pTab->pConfig->pzErrmsg = 0;
197227 197885     return rc;
197228 197886   }
197229 197887   
197230 197888   /*
197231 197889   ** Implementation of xBegin() method. 
197232 197890   */
................................................................................
198029 198687   ** Flush the contents of the pending-terms table to disk.
198030 198688   */
198031 198689   static int fts5SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){
198032 198690     Fts5Table *pTab = (Fts5Table*)pVtab;
198033 198691     UNUSED_PARAM(iSavepoint);  /* Call below is a no-op for NDEBUG builds */
198034 198692     fts5CheckTransactionState(pTab, FTS5_SAVEPOINT, iSavepoint);
198035 198693     fts5TripCursors(pTab);
198036         -  return sqlite3Fts5StorageSync(pTab->pStorage, 0);
       198694  +  return sqlite3Fts5StorageSync(pTab->pStorage);
198037 198695   }
198038 198696   
198039 198697   /*
198040 198698   ** The xRelease() method.
198041 198699   **
198042 198700   ** This is a no-op.
198043 198701   */
198044 198702   static int fts5ReleaseMethod(sqlite3_vtab *pVtab, int iSavepoint){
198045 198703     Fts5Table *pTab = (Fts5Table*)pVtab;
198046 198704     UNUSED_PARAM(iSavepoint);  /* Call below is a no-op for NDEBUG builds */
198047 198705     fts5CheckTransactionState(pTab, FTS5_RELEASE, iSavepoint);
198048 198706     fts5TripCursors(pTab);
198049         -  return sqlite3Fts5StorageSync(pTab->pStorage, 0);
       198707  +  return sqlite3Fts5StorageSync(pTab->pStorage);
198050 198708   }
198051 198709   
198052 198710   /*
198053 198711   ** The xRollbackTo() method.
198054 198712   **
198055 198713   ** Discard the contents of the pending terms table.
198056 198714   */
................................................................................
198253 198911   static void fts5SourceIdFunc(
198254 198912     sqlite3_context *pCtx,          /* Function call context */
198255 198913     int nArg,                       /* Number of args */
198256 198914     sqlite3_value **apUnused        /* Function arguments */
198257 198915   ){
198258 198916     assert( nArg==0 );
198259 198917     UNUSED_PARAM2(nArg, apUnused);
198260         -  sqlite3_result_text(pCtx, "fts5: 2017-03-28 18:48:43 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37", -1, SQLITE_TRANSIENT);
       198918  +  sqlite3_result_text(pCtx, "fts5: 2017-05-10 16:33:48 92c5ea7047323d10f762877c5f56d20a3e609e8b55efcfe4880ef3048821ac1f", -1, SQLITE_TRANSIENT);
198261 198919   }
198262 198920   
198263 198921   static int fts5Init(sqlite3 *db){
198264 198922     static const sqlite3_module fts5Mod = {
198265 198923       /* iVersion      */ 2,
198266 198924       /* xCreate       */ fts5CreateMethod,
198267 198925       /* xConnect      */ fts5ConnectMethod,
................................................................................
198589 199247           pConfig->zDb, pConfig->zName, zTail, zName, zTail
198590 199248       );
198591 199249     }
198592 199250   }
198593 199251   
198594 199252   static int sqlite3Fts5StorageRename(Fts5Storage *pStorage, const char *zName){
198595 199253     Fts5Config *pConfig = pStorage->pConfig;
198596         -  int rc = sqlite3Fts5StorageSync(pStorage, 1);
       199254  +  int rc = sqlite3Fts5StorageSync(pStorage);
198597 199255   
198598 199256     fts5StorageRenameOne(pConfig, &rc, "data", zName);
198599 199257     fts5StorageRenameOne(pConfig, &rc, "idx", zName);
198600 199258     fts5StorageRenameOne(pConfig, &rc, "config", zName);
198601 199259     if( pConfig->bColumnsize ){
198602 199260       fts5StorageRenameOne(pConfig, &rc, "docsize", zName);
198603 199261     }
................................................................................
199452 200110     }
199453 200111     return rc;
199454 200112   }
199455 200113   
199456 200114   /*
199457 200115   ** Flush any data currently held in-memory to disk.
199458 200116   */
199459         -static int sqlite3Fts5StorageSync(Fts5Storage *p, int bCommit){
       200117  +static int sqlite3Fts5StorageSync(Fts5Storage *p){
199460 200118     int rc = SQLITE_OK;
199461 200119     i64 iLastRowid = sqlite3_last_insert_rowid(p->pConfig->db);
199462 200120     if( p->bTotalsValid ){
199463 200121       rc = fts5StorageSaveTotals(p);
199464         -    if( bCommit ) p->bTotalsValid = 0;
       200122  +    p->bTotalsValid = 0;
199465 200123     }
199466 200124     if( rc==SQLITE_OK ){
199467         -    rc = sqlite3Fts5IndexSync(p->pIndex, bCommit);
       200125  +    rc = sqlite3Fts5IndexSync(p->pIndex);
199468 200126     }
199469 200127     sqlite3_set_last_insert_rowid(p->pConfig->db, iLastRowid);
199470 200128     return rc;
199471 200129   }
199472 200130   
199473 200131   static int sqlite3Fts5StorageRollback(Fts5Storage *p){
199474 200132     p->bTotalsValid = 0;

Changes to SQLite.Interop/src/core/sqlite3.h.

   117    117   ** string contains the date and time of the check-in (UTC) and a SHA1
   118    118   ** or SHA3-256 hash of the entire source tree.
   119    119   **
   120    120   ** See also: [sqlite3_libversion()],
   121    121   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   122    122   ** [sqlite_version()] and [sqlite_source_id()].
   123    123   */
   124         -#define SQLITE_VERSION        "3.18.0"
   125         -#define SQLITE_VERSION_NUMBER 3018000
   126         -#define SQLITE_SOURCE_ID      "2017-03-28 18:48:43 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37"
          124  +#define SQLITE_VERSION        "3.19.0"
          125  +#define SQLITE_VERSION_NUMBER 3019000
          126  +#define SQLITE_SOURCE_ID      "2017-05-10 16:33:48 92c5ea7047323d10f762877c5f56d20a3e609e8b55efcfe4880ef3048821ac1f"
   127    127   
   128    128   /*
   129    129   ** CAPI3REF: Run-Time Library Version Numbers
   130    130   ** KEYWORDS: sqlite3_version sqlite3_sourceid
   131    131   **
   132    132   ** These interfaces provide the same information as the [SQLITE_VERSION],
   133    133   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
   853    853   ** anti-virus programs.  By default, the windows VFS will retry file read,
   854    854   ** file write, and file delete operations up to 10 times, with a delay
   855    855   ** of 25 milliseconds before the first retry and with the delay increasing
   856    856   ** by an additional 25 milliseconds with each subsequent retry.  This
   857    857   ** opcode allows these two values (10 retries and 25 milliseconds of delay)
   858    858   ** to be adjusted.  The values are changed for all database connections
   859    859   ** within the same process.  The argument is a pointer to an array of two
   860         -** integers where the first integer i the new retry count and the second
          860  +** integers where the first integer is the new retry count and the second
   861    861   ** integer is the delay.  If either integer is negative, then the setting
   862    862   ** is not changed but instead the prior value of that setting is written
   863    863   ** into the array entry, allowing the current retry settings to be
   864    864   ** interrogated.  The zDbName parameter is ignored.
   865    865   **
   866    866   ** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
   867    867   ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
................................................................................
  2207   2207   ** running statements reaches zero are interrupted as if they had been
  2208   2208   ** running prior to the sqlite3_interrupt() call.  ^New SQL statements
  2209   2209   ** that are started after the running statement count reaches zero are
  2210   2210   ** not effected by the sqlite3_interrupt().
  2211   2211   ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
  2212   2212   ** SQL statements is a no-op and has no effect on SQL statements
  2213   2213   ** that are started after the sqlite3_interrupt() call returns.
  2214         -**
  2215         -** If the database connection closes while [sqlite3_interrupt()]
  2216         -** is running then bad things will likely happen.
  2217   2214   */
  2218   2215   SQLITE_API void sqlite3_interrupt(sqlite3*);
  2219   2216   
  2220   2217   /*
  2221   2218   ** CAPI3REF: Determine If An SQL Statement Is Complete
  2222   2219   **
  2223   2220   ** These routines are useful during command-line input to determine if the
................................................................................
  2672   2669   ** method.
  2673   2670   */
  2674   2671   SQLITE_API void sqlite3_randomness(int N, void *P);
  2675   2672   
  2676   2673   /*
  2677   2674   ** CAPI3REF: Compile-Time Authorization Callbacks
  2678   2675   ** METHOD: sqlite3
         2676  +** KEYWORDS: {authorizer callback}
  2679   2677   **
  2680   2678   ** ^This routine registers an authorizer callback with a particular
  2681   2679   ** [database connection], supplied in the first argument.
  2682   2680   ** ^The authorizer callback is invoked as SQL statements are being compiled
  2683   2681   ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
  2684   2682   ** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()].  ^At various
  2685   2683   ** points during the compilation process, as logic is being created
................................................................................
  2709   2707   ** ^If the action code is [SQLITE_READ]
  2710   2708   ** and the callback returns [SQLITE_IGNORE] then the
  2711   2709   ** [prepared statement] statement is constructed to substitute
  2712   2710   ** a NULL value in place of the table column that would have
  2713   2711   ** been read if [SQLITE_OK] had been returned.  The [SQLITE_IGNORE]
  2714   2712   ** return can be used to deny an untrusted user access to individual
  2715   2713   ** columns of a table.
         2714  +** ^When a table is referenced by a [SELECT] but no column values are
         2715  +** extracted from that table (for example in a query like
         2716  +** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
         2717  +** is invoked once for that table with a NULL column name.
  2716   2718   ** ^If the action code is [SQLITE_DELETE] and the callback returns
  2717   2719   ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
  2718   2720   ** [truncate optimization] is disabled and all rows are deleted individually.
  2719   2721   **
  2720   2722   ** An authorizer is used when [sqlite3_prepare | preparing]
  2721   2723   ** SQL statements from an untrusted source, to ensure that the SQL statements
  2722   2724   ** do not try to access data they are not allowed to see, or that they do not
................................................................................
  3701   3703   ** ^The sqlite3_value object returned by
  3702   3704   ** [sqlite3_column_value()] is unprotected.
  3703   3705   ** Unprotected sqlite3_value objects may only be used with
  3704   3706   ** [sqlite3_result_value()] and [sqlite3_bind_value()].
  3705   3707   ** The [sqlite3_value_blob | sqlite3_value_type()] family of
  3706   3708   ** interfaces require protected sqlite3_value objects.
  3707   3709   */
  3708         -typedef struct Mem sqlite3_value;
         3710  +typedef struct sqlite3_value sqlite3_value;
  3709   3711   
  3710   3712   /*
  3711   3713   ** CAPI3REF: SQL Function Context Object
  3712   3714   **
  3713   3715   ** The context in which an SQL function executes is stored in an
  3714   3716   ** sqlite3_context object.  ^A pointer to an sqlite3_context object
  3715   3717   ** is always first parameter to [application-defined SQL functions].

Changes to SQLite.Interop/src/ext/fts5.c.

  1035   1035     Fts5Index *p,                   /* Index to write to */
  1036   1036     int bDelete,                    /* True if current operation is a delete */
  1037   1037     i64 iDocid                      /* Docid to add or remove data from */
  1038   1038   );
  1039   1039   
  1040   1040   /*
  1041   1041   ** Flush any data stored in the in-memory hash tables to the database.
  1042         -** If the bCommit flag is true, also close any open blob handles.
         1042  +** Also close any open blob handles.
  1043   1043   */
  1044         -static int sqlite3Fts5IndexSync(Fts5Index *p, int bCommit);
         1044  +static int sqlite3Fts5IndexSync(Fts5Index *p);
  1045   1045   
  1046   1046   /*
  1047   1047   ** Discard any data stored in the in-memory hash tables. Do not write it
  1048   1048   ** to the database. Additionally, assume that the contents of the %_data
  1049   1049   ** table may have changed on disk. So any in-memory caches of %_data 
  1050   1050   ** records must be invalidated.
  1051   1051   */
................................................................................
  1207   1207   static int sqlite3Fts5StorageStmt(Fts5Storage *p, int eStmt, sqlite3_stmt**, char**);
  1208   1208   static void sqlite3Fts5StorageStmtRelease(Fts5Storage *p, int eStmt, sqlite3_stmt*);
  1209   1209   
  1210   1210   static int sqlite3Fts5StorageDocsize(Fts5Storage *p, i64 iRowid, int *aCol);
  1211   1211   static int sqlite3Fts5StorageSize(Fts5Storage *p, int iCol, i64 *pnAvg);
  1212   1212   static int sqlite3Fts5StorageRowCount(Fts5Storage *p, i64 *pnRow);
  1213   1213   
  1214         -static int sqlite3Fts5StorageSync(Fts5Storage *p, int bCommit);
         1214  +static int sqlite3Fts5StorageSync(Fts5Storage *p);
  1215   1215   static int sqlite3Fts5StorageRollback(Fts5Storage *p);
  1216   1216   
  1217   1217   static int sqlite3Fts5StorageConfigValue(
  1218   1218       Fts5Storage *p, const char*, sqlite3_value*, int
  1219   1219   );
  1220   1220   
  1221   1221   static int sqlite3Fts5StorageDeleteAll(Fts5Storage *p);
................................................................................
  1243   1243     const char *p;                  /* Token text (not NULL terminated) */
  1244   1244     int n;                          /* Size of buffer p in bytes */
  1245   1245   };
  1246   1246   
  1247   1247   /* Parse a MATCH expression. */
  1248   1248   static int sqlite3Fts5ExprNew(
  1249   1249     Fts5Config *pConfig, 
         1250  +  int iCol,                       /* Column on LHS of MATCH operator */
  1250   1251     const char *zExpr,
  1251   1252     Fts5Expr **ppNew, 
  1252   1253     char **pzErr
  1253   1254   );
  1254   1255   
  1255   1256   /*
  1256   1257   ** for(rc = sqlite3Fts5ExprFirst(pExpr, pIdx, bDesc);
................................................................................
  1327   1328   );
  1328   1329   
  1329   1330   static void sqlite3Fts5ParsePhraseFree(Fts5ExprPhrase*);
  1330   1331   static void sqlite3Fts5ParseNearsetFree(Fts5ExprNearset*);
  1331   1332   static void sqlite3Fts5ParseNodeFree(Fts5ExprNode*);
  1332   1333   
  1333   1334   static void sqlite3Fts5ParseSetDistance(Fts5Parse*, Fts5ExprNearset*, Fts5Token*);
  1334         -static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNearset*, Fts5Colset*);
         1335  +static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNode*, Fts5Colset*);
  1335   1336   static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse*, Fts5Colset*);
  1336   1337   static void sqlite3Fts5ParseFinished(Fts5Parse *pParse, Fts5ExprNode *p);
  1337   1338   static void sqlite3Fts5ParseNear(Fts5Parse *pParse, Fts5Token*);
  1338   1339   
  1339   1340   /*
  1340   1341   ** End of interface to code in fts5_expr.c.
  1341   1342   **************************************************************************/
................................................................................
  1385   1386   
  1386   1387   #line 1 "fts5parse.h"
  1387   1388   #define FTS5_OR                               1
  1388   1389   #define FTS5_AND                              2
  1389   1390   #define FTS5_NOT                              3
  1390   1391   #define FTS5_TERM                             4
  1391   1392   #define FTS5_COLON                            5
  1392         -#define FTS5_LP                               6
  1393         -#define FTS5_RP                               7
  1394         -#define FTS5_MINUS                            8
  1395         -#define FTS5_LCP                              9
  1396         -#define FTS5_RCP                             10
  1397         -#define FTS5_STRING                          11
         1393  +#define FTS5_MINUS                            6
         1394  +#define FTS5_LCP                              7
         1395  +#define FTS5_RCP                              8
         1396  +#define FTS5_STRING                           9
         1397  +#define FTS5_LP                              10
         1398  +#define FTS5_RP                              11
  1398   1399   #define FTS5_COMMA                           12
  1399   1400   #define FTS5_PLUS                            13
  1400   1401   #define FTS5_STAR                            14
  1401   1402   
  1402   1403   #line 1 "fts5parse.c"
  1403   1404   /*
  1404   1405   ** 2000-05-29
................................................................................
  1529   1530   #ifndef fts5YYSTACKDEPTH
  1530   1531   #define fts5YYSTACKDEPTH 100
  1531   1532   #endif
  1532   1533   #define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
  1533   1534   #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
  1534   1535   #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
  1535   1536   #define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
  1536         -#define fts5YYNSTATE             29
  1537         -#define fts5YYNRULE              26
  1538         -#define fts5YY_MAX_SHIFT         28
  1539         -#define fts5YY_MIN_SHIFTREDUCE   45
  1540         -#define fts5YY_MAX_SHIFTREDUCE   70
  1541         -#define fts5YY_MIN_REDUCE        71
  1542         -#define fts5YY_MAX_REDUCE        96
  1543         -#define fts5YY_ERROR_ACTION      97
  1544         -#define fts5YY_ACCEPT_ACTION     98
  1545         -#define fts5YY_NO_ACTION         99
         1537  +#define fts5YYNSTATE             33
         1538  +#define fts5YYNRULE              27
         1539  +#define fts5YY_MAX_SHIFT         32
         1540  +#define fts5YY_MIN_SHIFTREDUCE   50
         1541  +#define fts5YY_MAX_SHIFTREDUCE   76
         1542  +#define fts5YY_MIN_REDUCE        77
         1543  +#define fts5YY_MAX_REDUCE        103
         1544  +#define fts5YY_ERROR_ACTION      104
         1545  +#define fts5YY_ACCEPT_ACTION     105
         1546  +#define fts5YY_NO_ACTION         106
  1546   1547   /************* End control #defines *******************************************/
  1547   1548   
  1548   1549   /* Define the fts5yytestcase() macro to be a no-op if is not already defined
  1549   1550   ** otherwise.
  1550   1551   **
  1551   1552   ** Applications can choose to define fts5yytestcase() in the %include section
  1552   1553   ** to a macro that can assist in verifying code coverage.  For production
................................................................................
  1610   1611   **  fts5yy_shift_ofst[]    For each state, the offset into fts5yy_action for
  1611   1612   **                     shifting terminals.
  1612   1613   **  fts5yy_reduce_ofst[]   For each state, the offset into fts5yy_action for
  1613   1614   **                     shifting non-terminals after a reduce.
  1614   1615   **  fts5yy_default[]       Default action for each state.
  1615   1616   **
  1616   1617   *********** Begin parsing tables **********************************************/
  1617         -#define fts5YY_ACTTAB_COUNT (85)
         1618  +#define fts5YY_ACTTAB_COUNT (98)
  1618   1619   static const fts5YYACTIONTYPE fts5yy_action[] = {
  1619         - /*     0 */    98,   16,   51,    5,   53,   27,   83,    7,   26,   15,
  1620         - /*    10 */    51,    5,   53,   27,   13,   69,   26,   48,   51,    5,
  1621         - /*    20 */    53,   27,   19,   11,   26,    9,   20,   51,    5,   53,
  1622         - /*    30 */    27,   13,   22,   26,   28,   51,    5,   53,   27,   68,
  1623         - /*    40 */     1,   26,   19,   11,   17,    9,   52,   10,   53,   27,
  1624         - /*    50 */    23,   24,   26,   54,    3,    4,    2,   26,    6,   21,
  1625         - /*    60 */    49,   71,    3,    4,    2,    7,   56,   59,   55,   59,
  1626         - /*    70 */     4,    2,   12,   69,   58,   60,   18,   67,   62,   69,
  1627         - /*    80 */    25,   66,    8,   14,    2,
         1620  + /*     0 */   105,   19,   63,    6,   26,   66,   65,   24,   24,   17,
         1621  + /*    10 */    63,    6,   26,   16,   65,   54,   24,   18,   63,    6,
         1622  + /*    20 */    26,   10,   65,   12,   24,   75,   59,   63,    6,   26,
         1623  + /*    30 */    13,   65,   75,   24,   20,   63,    6,   26,   74,   65,
         1624  + /*    40 */    56,   24,   27,   63,    6,   26,   73,   65,   21,   24,
         1625  + /*    50 */    23,   15,   30,   11,    1,   64,   22,   25,    9,   65,
         1626  + /*    60 */     7,   24,    3,    4,    5,    3,    4,    5,    3,   77,
         1627  + /*    70 */     4,    5,    3,   61,   23,   15,   60,   11,   80,   12,
         1628  + /*    80 */     2,   13,   68,   10,   29,   52,   55,   75,   31,   32,
         1629  + /*    90 */     8,   28,    5,    3,   51,   55,   72,   14,
  1628   1630   };
  1629   1631   static const fts5YYCODETYPE fts5yy_lookahead[] = {
  1630         - /*     0 */    16,   17,   18,   19,   20,   21,    5,    6,   24,   17,
  1631         - /*    10 */    18,   19,   20,   21,   11,   14,   24,   17,   18,   19,
  1632         - /*    20 */    20,   21,    8,    9,   24,   11,   17,   18,   19,   20,
  1633         - /*    30 */    21,   11,   12,   24,   17,   18,   19,   20,   21,   26,
  1634         - /*    40 */     6,   24,    8,    9,   22,   11,   18,   11,   20,   21,
  1635         - /*    50 */    24,   25,   24,   20,    1,    2,    3,   24,   23,   24,
  1636         - /*    60 */     7,    0,    1,    2,    3,    6,   10,   11,   10,   11,
  1637         - /*    70 */     2,    3,    9,   14,   11,   11,   22,   26,    7,   14,
  1638         - /*    80 */    13,   11,    5,   11,    3,
         1632  + /*     0 */    16,   17,   18,   19,   20,   22,   22,   24,   24,   17,
         1633  + /*    10 */    18,   19,   20,    7,   22,    9,   24,   17,   18,   19,
         1634  + /*    20 */    20,   10,   22,    9,   24,   14,   17,   18,   19,   20,
         1635  + /*    30 */     9,   22,   14,   24,   17,   18,   19,   20,   26,   22,
         1636  + /*    40 */     9,   24,   17,   18,   19,   20,   26,   22,   21,   24,
         1637  + /*    50 */     6,    7,   13,    9,   10,   18,   21,   20,    5,   22,
         1638  + /*    60 */     5,   24,    3,    1,    2,    3,    1,    2,    3,    0,
         1639  + /*    70 */     1,    2,    3,   11,    6,    7,   11,    9,    5,    9,
         1640  + /*    80 */    10,    9,   11,   10,   12,    8,    9,   14,   24,   25,
         1641  + /*    90 */    23,   24,    2,    3,    8,    9,    9,    9,
  1639   1642   };
  1640         -#define fts5YY_SHIFT_USE_DFLT (85)
  1641         -#define fts5YY_SHIFT_COUNT    (28)
         1643  +#define fts5YY_SHIFT_USE_DFLT (98)
         1644  +#define fts5YY_SHIFT_COUNT    (32)
  1642   1645   #define fts5YY_SHIFT_MIN      (0)
  1643         -#define fts5YY_SHIFT_MAX      (81)
         1646  +#define fts5YY_SHIFT_MAX      (90)
  1644   1647   static const unsigned char fts5yy_shift_ofst[] = {
  1645         - /*     0 */    34,   34,   34,   34,   34,   14,   20,    3,   36,    1,
  1646         - /*    10 */    59,   64,   64,   65,   65,   53,   61,   56,   58,   63,
  1647         - /*    20 */    68,   67,   70,   67,   71,   72,   67,   77,   81,
         1648  + /*     0 */    44,   44,   44,   44,   44,   44,   68,   70,   72,   14,
         1649  + /*    10 */    21,   73,   11,   18,   18,   31,   31,   62,   65,   69,
         1650  + /*    20 */    90,   77,   86,    6,   39,   53,   55,   59,   39,   87,
         1651  + /*    30 */    88,   39,   71,
  1648   1652   };
  1649         -#define fts5YY_REDUCE_USE_DFLT (-17)
  1650         -#define fts5YY_REDUCE_COUNT (14)
  1651         -#define fts5YY_REDUCE_MIN   (-16)
  1652         -#define fts5YY_REDUCE_MAX   (54)
         1653  +#define fts5YY_REDUCE_USE_DFLT (-18)
         1654  +#define fts5YY_REDUCE_COUNT (16)
         1655  +#define fts5YY_REDUCE_MIN   (-17)
         1656  +#define fts5YY_REDUCE_MAX   (67)
  1653   1657   static const signed char fts5yy_reduce_ofst[] = {
  1654         - /*     0 */   -16,   -8,    0,    9,   17,   28,   26,   35,   33,   13,
  1655         - /*    10 */    13,   22,   54,   13,   51,
         1658  + /*     0 */   -16,   -8,    0,    9,   17,   25,   37,  -17,   64,  -17,
         1659  + /*    10 */    67,   12,   12,   12,   20,   27,   35,
  1656   1660   };
  1657   1661   static const fts5YYACTIONTYPE fts5yy_default[] = {
  1658         - /*     0 */    97,   97,   97,   97,   97,   76,   91,   97,   97,   96,
  1659         - /*    10 */    96,   97,   97,   96,   96,   97,   97,   97,   97,   97,
  1660         - /*    20 */    73,   89,   97,   90,   97,   97,   87,   97,   72,
         1662  + /*     0 */   104,  104,  104,  104,  104,  104,   89,  104,   98,  104,
         1663  + /*    10 */   104,  103,  103,  103,  103,  104,  104,  104,  104,  104,
         1664  + /*    20 */    85,  104,  104,  104,   94,  104,  104,   84,   96,  104,
         1665  + /*    30 */   104,   97,  104,
  1661   1666   };
  1662   1667   /********** End of lemon-generated parsing tables *****************************/
  1663   1668   
  1664   1669   /* The next table maps tokens (terminal symbols) into fallback tokens.  
  1665   1670   ** If a construct like the following:
  1666   1671   ** 
  1667   1672   **      %fallback ID X Y Z.
................................................................................
  1759   1764   #endif /* NDEBUG */
  1760   1765   
  1761   1766   #ifndef NDEBUG
  1762   1767   /* For tracing shifts, the names of all terminals and nonterminals
  1763   1768   ** are required.  The following table supplies these names */
  1764   1769   static const char *const fts5yyTokenName[] = { 
  1765   1770     "$",             "OR",            "AND",           "NOT",         
  1766         -  "TERM",          "COLON",         "LP",            "RP",          
  1767         -  "MINUS",         "LCP",           "RCP",           "STRING",      
         1771  +  "TERM",          "COLON",         "MINUS",         "LCP",         
         1772  +  "RCP",           "STRING",        "LP",            "RP",          
  1768   1773     "COMMA",         "PLUS",          "STAR",          "error",       
  1769   1774     "input",         "expr",          "cnearset",      "exprlist",    
  1770         -  "nearset",       "colset",        "colsetlist",    "nearphrases", 
         1775  +  "colset",        "colsetlist",    "nearset",       "nearphrases", 
  1771   1776     "phrase",        "neardist_opt",  "star_opt",    
  1772   1777   };
  1773   1778   #endif /* NDEBUG */
  1774   1779   
  1775   1780   #ifndef NDEBUG
  1776   1781   /* For tracing reduce actions, the names of all rules are required.
  1777   1782   */
  1778   1783   static const char *const fts5yyRuleName[] = {
  1779   1784    /*   0 */ "input ::= expr",
  1780         - /*   1 */ "expr ::= expr AND expr",
  1781         - /*   2 */ "expr ::= expr OR expr",
  1782         - /*   3 */ "expr ::= expr NOT expr",
  1783         - /*   4 */ "expr ::= LP expr RP",
  1784         - /*   5 */ "expr ::= exprlist",
  1785         - /*   6 */ "exprlist ::= cnearset",
  1786         - /*   7 */ "exprlist ::= exprlist cnearset",
  1787         - /*   8 */ "cnearset ::= nearset",
  1788         - /*   9 */ "cnearset ::= colset COLON nearset",
  1789         - /*  10 */ "colset ::= MINUS LCP colsetlist RCP",
  1790         - /*  11 */ "colset ::= LCP colsetlist RCP",
  1791         - /*  12 */ "colset ::= STRING",
  1792         - /*  13 */ "colset ::= MINUS STRING",
  1793         - /*  14 */ "colsetlist ::= colsetlist STRING",
  1794         - /*  15 */ "colsetlist ::= STRING",
  1795         - /*  16 */ "nearset ::= phrase",
  1796         - /*  17 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
  1797         - /*  18 */ "nearphrases ::= phrase",
  1798         - /*  19 */ "nearphrases ::= nearphrases phrase",
  1799         - /*  20 */ "neardist_opt ::=",
  1800         - /*  21 */ "neardist_opt ::= COMMA STRING",
  1801         - /*  22 */ "phrase ::= phrase PLUS STRING star_opt",
  1802         - /*  23 */ "phrase ::= STRING star_opt",
  1803         - /*  24 */ "star_opt ::= STAR",
  1804         - /*  25 */ "star_opt ::=",
         1785  + /*   1 */ "colset ::= MINUS LCP colsetlist RCP",
         1786  + /*   2 */ "colset ::= LCP colsetlist RCP",
         1787  + /*   3 */ "colset ::= STRING",
         1788  + /*   4 */ "colset ::= MINUS STRING",
         1789  + /*   5 */ "colsetlist ::= colsetlist STRING",
         1790  + /*   6 */ "colsetlist ::= STRING",
         1791  + /*   7 */ "expr ::= expr AND expr",
         1792  + /*   8 */ "expr ::= expr OR expr",
         1793  + /*   9 */ "expr ::= expr NOT expr",
         1794  + /*  10 */ "expr ::= colset COLON LP expr RP",
         1795  + /*  11 */ "expr ::= LP expr RP",
         1796  + /*  12 */ "expr ::= exprlist",
         1797  + /*  13 */ "exprlist ::= cnearset",
         1798  + /*  14 */ "exprlist ::= exprlist cnearset",
         1799  + /*  15 */ "cnearset ::= nearset",
         1800  + /*  16 */ "cnearset ::= colset COLON nearset",
         1801  + /*  17 */ "nearset ::= phrase",
         1802  + /*  18 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
         1803  + /*  19 */ "nearphrases ::= phrase",
         1804  + /*  20 */ "nearphrases ::= nearphrases phrase",
         1805  + /*  21 */ "neardist_opt ::=",
         1806  + /*  22 */ "neardist_opt ::= COMMA STRING",
         1807  + /*  23 */ "phrase ::= phrase PLUS STRING star_opt",
         1808  + /*  24 */ "phrase ::= STRING star_opt",
         1809  + /*  25 */ "star_opt ::= STAR",
         1810  + /*  26 */ "star_opt ::=",
  1805   1811   };
  1806   1812   #endif /* NDEBUG */
  1807   1813   
  1808   1814   
  1809   1815   #if fts5YYSTACKDEPTH<=0
  1810   1816   /*
  1811   1817   ** Try to increase the size of the parser stack.  Return the number
................................................................................
  1919   1925       ** inside the C code.
  1920   1926       */
  1921   1927   /********* Begin destructor definitions ***************************************/
  1922   1928       case 16: /* input */
  1923   1929   {
  1924   1930   #line 83 "fts5parse.y"
  1925   1931    (void)pParse; 
  1926         -#line 525 "fts5parse.c"
         1932  +#line 530 "fts5parse.c"
  1927   1933   }
  1928   1934         break;
  1929   1935       case 17: /* expr */
  1930   1936       case 18: /* cnearset */
  1931   1937       case 19: /* exprlist */
  1932   1938   {
  1933   1939   #line 89 "fts5parse.y"
  1934   1940    sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy24)); 
  1935         -#line 534 "fts5parse.c"
         1941  +#line 539 "fts5parse.c"
  1936   1942   }
  1937   1943         break;
  1938         -    case 20: /* nearset */
         1944  +    case 20: /* colset */
         1945  +    case 21: /* colsetlist */
         1946  +{
         1947  +#line 93 "fts5parse.y"
         1948  + sqlite3_free((fts5yypminor->fts5yy11)); 
         1949  +#line 547 "fts5parse.c"
         1950  +}
         1951  +      break;
         1952  +    case 22: /* nearset */
  1939   1953       case 23: /* nearphrases */
  1940   1954   {
  1941         -#line 143 "fts5parse.y"
         1955  +#line 148 "fts5parse.y"
  1942   1956    sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy46)); 
  1943         -#line 542 "fts5parse.c"
  1944         -}
  1945         -      break;
  1946         -    case 21: /* colset */
  1947         -    case 22: /* colsetlist */
  1948         -{
  1949         -#line 119 "fts5parse.y"
  1950         - sqlite3_free((fts5yypminor->fts5yy11)); 
  1951         -#line 550 "fts5parse.c"
         1957  +#line 555 "fts5parse.c"
  1952   1958   }
  1953   1959         break;
  1954   1960       case 24: /* phrase */
  1955   1961   {
  1956         -#line 174 "fts5parse.y"
         1962  +#line 179 "fts5parse.y"
  1957   1963    sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy53)); 
  1958         -#line 557 "fts5parse.c"
         1964  +#line 562 "fts5parse.c"
  1959   1965   }
  1960   1966         break;
  1961   1967   /********* End destructor definitions *****************************************/
  1962   1968       default:  break;   /* If no destructor action specified: do nothing */
  1963   1969     }
  1964   1970   }
  1965   1971   
................................................................................
  2133   2139      while( fts5yypParser->fts5yytos>fts5yypParser->fts5yystack ) fts5yy_pop_parser_stack(fts5yypParser);
  2134   2140      /* Here code is inserted which will execute if the parser
  2135   2141      ** stack every overflows */
  2136   2142   /******** Begin %stack_overflow code ******************************************/
  2137   2143   #line 36 "fts5parse.y"
  2138   2144   
  2139   2145     sqlite3Fts5ParseError(pParse, "fts5: parser stack overflow");
  2140         -#line 739 "fts5parse.c"
         2146  +#line 744 "fts5parse.c"
  2141   2147   /******** End %stack_overflow code ********************************************/
  2142   2148      sqlite3Fts5ParserARG_STORE; /* Suppress warning about unused %extra_argument var */
  2143   2149   }
  2144   2150   
  2145   2151   /*
  2146   2152   ** Print tracing information for a SHIFT action
  2147   2153   */
................................................................................
  2208   2214   ** is used during the reduce.
  2209   2215   */
  2210   2216   static const struct {
  2211   2217     fts5YYCODETYPE lhs;         /* Symbol on the left-hand side of the rule */
  2212   2218     unsigned char nrhs;     /* Number of right-hand side symbols in the rule */
  2213   2219   } fts5yyRuleInfo[] = {
  2214   2220     { 16, 1 },
         2221  +  { 20, 4 },
         2222  +  { 20, 3 },
         2223  +  { 20, 1 },
         2224  +  { 20, 2 },
         2225  +  { 21, 2 },
         2226  +  { 21, 1 },
  2215   2227     { 17, 3 },
  2216   2228     { 17, 3 },
  2217   2229     { 17, 3 },
         2230  +  { 17, 5 },
  2218   2231     { 17, 3 },
  2219   2232     { 17, 1 },
  2220   2233     { 19, 1 },
  2221   2234     { 19, 2 },
  2222   2235     { 18, 1 },
  2223   2236     { 18, 3 },
  2224         -  { 21, 4 },
  2225         -  { 21, 3 },
  2226         -  { 21, 1 },
  2227         -  { 21, 2 },
  2228         -  { 22, 2 },
  2229   2237     { 22, 1 },
  2230         -  { 20, 1 },
  2231         -  { 20, 5 },
         2238  +  { 22, 5 },
  2232   2239     { 23, 1 },
  2233   2240     { 23, 2 },
  2234   2241     { 25, 0 },
  2235   2242     { 25, 2 },
  2236   2243     { 24, 4 },
  2237   2244     { 24, 2 },
  2238   2245     { 26, 1 },
................................................................................
  2299   2306     **     break;
  2300   2307     */
  2301   2308   /********** Begin reduce actions ***************