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

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

Overview
Comment:Bump all version numbers to 1.0.99.0. 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: c1fc6af85eb1dcbe37f151861a17dff20cbe6788
User & Date: mistachkin 2015-09-09 23:34:29
Context
2015-09-09
23:40
Update version in one placed missed in the README file. check-in: b3122a99cc user: mistachkin tags: trunk
23:34
Bump all version numbers to 1.0.99.0. Update SQLite core library to the latest trunk code. check-in: c1fc6af85e user: mistachkin tags: trunk
2015-08-25
21:16
Remove duplicate (and incorrect for Visual Studio 2015) link from the download page. check-in: 463bcfb351 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.98.0, Culture=neutral,
           88  +                 Version=1.0.99.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.99.0 - October XX, 2015 <font color="red">(release scheduled)</font></b></p>
           47  +    <ul>
           48  +      <li>Updated to <a href="https://www.sqlite.org/draft/releaselog/3_8_12.html">SQLite 3.8.12</a>.</li>
           49  +    </ul>
    46     50       <p><b>1.0.98.0 - August 19, 2015</b></p>
    47     51       <ul>
    48     52         <li>Updated to <a href="https://www.sqlite.org/releaselog/3_8_11_1.html">SQLite 3.8.11.1</a>.</li>
    49     53         <li>Add full support for Visual Studio 2015 and the .NET Framework 4.6.</li>
    50     54         <li>Add support for creating custom SQL functions using delegates.</li>
    51     55         <li>Implement the Substring method for LINQ using the &quot;substr&quot; core SQL function.&nbsp;<b>** Potentially Incompatible Change **</b></li>
    52     56         <li>Prevent encrypted connections from being used with the connection pool. Pursuant to <a href="https://system.data.sqlite.org/index.html/info/89d3a159f1">[89d3a159f1]</a>.&nbsp;<b>** Potentially Incompatible Change **</b></li>

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;098&quot;).&nbsp; The
          163  +        the System.Data.SQLite library (e.g. &quot;099&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.98.1</version>
           14  +    <version>1.0.99.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.98.1" />
           25  +        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.99.0" />
    26     26         </group>
    27     27         <group targetFramework="net40">
    28         -        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.98.1" />
           28  +        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.99.0" />
    29     29         </group>
    30     30         <group targetFramework="net45">
    31         -        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.98.1" />
           31  +        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.99.0" />
    32     32         </group>
    33     33         <group targetFramework="net451">
    34         -        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.98.1" />
           34  +        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.99.0" />
    35     35         </group>
    36     36         <group targetFramework="net46">
    37         -        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.98.1" />
           37  +        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.99.0" />
    38     38         </group>
    39     39         <group targetFramework="net20">
    40         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
           40  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
    41     41         </group>
    42     42         <group targetFramework="net40">
    43         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
           43  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
    44     44         </group>
    45     45         <group targetFramework="net45">
    46         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
           46  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
    47     47         </group>
    48     48         <group targetFramework="net451">
    49         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
           49  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
    50     50         </group>
    51     51         <group targetFramework="net46">
    52         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
           52  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
    53     53         </group>
    54     54         <group targetFramework="net40">
    55         -        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.98.1" />
           55  +        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" />
    56     56         </group>
    57     57         <group targetFramework="net45">
    58         -        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.98.1" />
           58  +        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" />
    59     59         </group>
    60     60         <group targetFramework="net451">
    61         -        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.98.1" />
           61  +        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" />
    62     62         </group>
    63     63         <group targetFramework="net46">
    64         -        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.98.1" />
           64  +        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.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.98.1</version>
           14  +    <version>1.0.99.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.98.1</version>
           14  +    <version>1.0.99.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.98.1</version>
           14  +    <version>1.0.99.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.98.1</version>
           14  +    <version>1.0.99.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.98.1</version>
           14  +    <version>1.0.99.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.98.1</version>
           14  +    <version>1.0.99.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.98.1</version>
           14  +    <version>1.0.99.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.98.1</version>
           14  +    <version>1.0.99.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.98.1</version>
           14  +    <version>1.0.99.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.98.1</version>
           14  +    <version>1.0.99.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.98.1</version>
           14  +    <version>1.0.99.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.98.1</version>
           14  +    <version>1.0.99.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.98.1</version>
           14  +    <version>1.0.99.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.98.1" />
           25  +        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.99.0" />
    26     26         </group>
    27     27         <group targetFramework="net40">
    28         -        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.98.1" />
           28  +        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.99.0" />
    29     29         </group>
    30     30         <group targetFramework="net45">
    31         -        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.98.1" />
           31  +        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.99.0" />
    32     32         </group>
    33     33         <group targetFramework="net451">
    34         -        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.98.1" />
           34  +        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.99.0" />
    35     35         </group>
    36     36         <group targetFramework="net46">
    37         -        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.98.1" />
           37  +        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.99.0" />
    38     38         </group>
    39     39         <group targetFramework="net20">
    40         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
           40  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
    41     41         </group>
    42     42         <group targetFramework="net40">
    43         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
           43  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
    44     44         </group>
    45     45         <group targetFramework="net45">
    46         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
           46  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
    47     47         </group>
    48     48         <group targetFramework="net451">
    49         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
           49  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
    50     50         </group>
    51     51         <group targetFramework="net46">
    52         -        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
           52  +        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
    53     53         </group>
    54     54         <group targetFramework="net40">
    55         -        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.98.1" />
           55  +        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" />
    56     56         </group>
    57     57         <group targetFramework="net45">
    58         -        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.98.1" />
           58  +        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" />
    59     59         </group>
    60     60         <group targetFramework="net451">
    61         -        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.98.1" />
           61  +        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" />
    62     62         </group>
    63     63         <group targetFramework="net46">
    64         -        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.98.1" />
           64  +        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.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.98.1</version>
           14  +    <version>1.0.99.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.98.1" />
           25  +        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.99.0" />
    26     26         </group>
    27     27         <group targetFramework="net40">
    28         -        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.98.1" />
           28  +        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.99.0" />
    29     29         </group>
    30     30         <group targetFramework="net45">
    31         -        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.98.1" />
           31  +        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.99.0" />
    32     32         </group>
    33     33         <group targetFramework="net451">
    34         -        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.98.1" />
           34  +        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.99.0" />
    35     35         </group>
    36     36         <group targetFramework="net46">
    37         -        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.98.1" />
           37  +        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.99.0" />
    38     38         </group>
    39     39         <group targetFramework="net20">
    40         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
           40  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
    41     41         </group>
    42     42         <group targetFramework="net40">
    43         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
           43  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
    44     44         </group>
    45     45         <group targetFramework="net45">
    46         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
           46  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
    47     47         </group>
    48     48         <group targetFramework="net451">
    49         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
           49  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
    50     50         </group>
    51     51         <group targetFramework="net46">
    52         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
           52  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
    53     53         </group>
    54     54         <group targetFramework="net40">
    55         -        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.98.1" />
           55  +        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" />
    56     56         </group>
    57     57         <group targetFramework="net45">
    58         -        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.98.1" />
           58  +        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" />
    59     59         </group>
    60     60         <group targetFramework="net451">
    61         -        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.98.1" />
           61  +        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" />
    62     62         </group>
    63     63         <group targetFramework="net46">
    64         -        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.98.1" />
           64  +        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.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.98.1</version>
           14  +    <version>1.0.99.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.98.1" />
           25  +        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.99.0" />
    26     26         </group>
    27     27         <group targetFramework="net40">
    28         -        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.98.1" />
           28  +        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.99.0" />
    29     29         </group>
    30     30         <group targetFramework="net45">
    31         -        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.98.1" />
           31  +        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.99.0" />
    32     32         </group>
    33     33         <group targetFramework="net451">
    34         -        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.98.1" />
           34  +        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.99.0" />
    35     35         </group>
    36     36         <group targetFramework="net46">
    37         -        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.98.1" />
           37  +        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.99.0" />
    38     38         </group>
    39     39         <group targetFramework="net20">
    40         -        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
           40  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    41     41         </group>
    42     42         <group targetFramework="net40">
    43         -        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
           43  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    44     44         </group>
    45     45         <group targetFramework="net45">
    46         -        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
           46  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    47     47         </group>
    48     48         <group targetFramework="net451">
    49         -        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
           49  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    50     50         </group>
    51     51         <group targetFramework="net46">
    52         -        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
           52  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    53     53         </group>
    54     54         <group targetFramework="net40">
    55         -        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
           55  +        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
    56     56         </group>
    57     57         <group targetFramework="net45">
    58         -        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
           58  +        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
    59     59         </group>
    60     60         <group targetFramework="net451">
    61         -        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
           61  +        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
    62     62         </group>
    63     63         <group targetFramework="net46">
    64         -        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
           64  +        <dependency id="System.Data.SQLite.EF6" version="1.0.99.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.98.1</version>
           14  +    <version>1.0.99.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.98.1" />
           25  +        <dependency id="System.Data.SQLite.Core.Test" version="1.0.99.0" />
    26     26         </group>
    27     27         <group targetFramework="net40">
    28         -        <dependency id="System.Data.SQLite.Core.Test" version="1.0.98.1" />
           28  +        <dependency id="System.Data.SQLite.Core.Test" version="1.0.99.0" />
    29     29         </group>
    30     30         <group targetFramework="net45">
    31         -        <dependency id="System.Data.SQLite.Core.Test" version="1.0.98.1" />
           31  +        <dependency id="System.Data.SQLite.Core.Test" version="1.0.99.0" />
    32     32         </group>
    33     33         <group targetFramework="net451">
    34         -        <dependency id="System.Data.SQLite.Core.Test" version="1.0.98.1" />
           34  +        <dependency id="System.Data.SQLite.Core.Test" version="1.0.99.0" />
    35     35         </group>
    36     36         <group targetFramework="net46">
    37         -        <dependency id="System.Data.SQLite.Core.Test" version="1.0.98.1" />
           37  +        <dependency id="System.Data.SQLite.Core.Test" version="1.0.99.0" />
    38     38         </group>
    39     39         <group targetFramework="net20">
    40         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
           40  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
    41     41         </group>
    42     42         <group targetFramework="net40">
    43         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
           43  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
    44     44         </group>
    45     45         <group targetFramework="net45">
    46         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
           46  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
    47     47         </group>
    48     48         <group targetFramework="net451">
    49         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
           49  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
    50     50         </group>
    51     51         <group targetFramework="net46">
    52         -        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
           52  +        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
    53     53         </group>
    54     54         <group targetFramework="net40">
    55         -        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.98.1" />
           55  +        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" />
    56     56         </group>
    57     57         <group targetFramework="net45">
    58         -        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.98.1" />
           58  +        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" />
    59     59         </group>
    60     60         <group targetFramework="net451">
    61         -        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.98.1" />
           61  +        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" />
    62     62         </group>
    63     63         <group targetFramework="net46">
    64         -        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.98.1" />
           64  +        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.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.98.1</version>
           14  +    <version>1.0.99.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.98.1" />
           25  +        <dependency id="System.Data.SQLite.Core" version="1.0.99.0" />
    26     26         </group>
    27     27         <group targetFramework="net40">
    28         -        <dependency id="System.Data.SQLite.Core" version="1.0.98.1" />
           28  +        <dependency id="System.Data.SQLite.Core" version="1.0.99.0" />
    29     29         </group>
    30     30         <group targetFramework="net45">
    31         -        <dependency id="System.Data.SQLite.Core" version="1.0.98.1" />
           31  +        <dependency id="System.Data.SQLite.Core" version="1.0.99.0" />
    32     32         </group>
    33     33         <group targetFramework="net451">
    34         -        <dependency id="System.Data.SQLite.Core" version="1.0.98.1" />
           34  +        <dependency id="System.Data.SQLite.Core" version="1.0.99.0" />
    35     35         </group>
    36     36         <group targetFramework="net46">
    37         -        <dependency id="System.Data.SQLite.Core" version="1.0.98.1" />
           37  +        <dependency id="System.Data.SQLite.Core" version="1.0.99.0" />
    38     38         </group>
    39     39         <group targetFramework="net20">
    40         -        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
           40  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    41     41         </group>
    42     42         <group targetFramework="net40">
    43         -        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
           43  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    44     44         </group>
    45     45         <group targetFramework="net45">
    46         -        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
           46  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    47     47         </group>
    48     48         <group targetFramework="net451">
    49         -        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
           49  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    50     50         </group>
    51     51         <group targetFramework="net46">
    52         -        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
           52  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    53     53         </group>
    54     54         <group targetFramework="net40">
    55         -        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
           55  +        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
    56     56         </group>
    57     57         <group targetFramework="net45">
    58         -        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
           58  +        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
    59     59         </group>
    60     60         <group targetFramework="net451">
    61         -        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
           61  +        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
    62     62         </group>
    63     63         <group targetFramework="net46">
    64         -        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
           64  +        <dependency id="System.Data.SQLite.EF6" version="1.0.99.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.98.1</version>
           13  +    <version>1.0.99.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.98.1" />
           24  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    25     25         </group>
    26     26         <group targetFramework="net40">
    27         -        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
           27  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    28     28         </group>
    29     29         <group targetFramework="net45">
    30         -        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
           30  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    31     31         </group>
    32     32         <group targetFramework="net451">
    33         -        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
           33  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    34     34         </group>
    35     35         <group targetFramework="net46">
    36         -        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
           36  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    37     37         </group>
    38     38         <group targetFramework="net40">
    39         -        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
           39  +        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
    40     40         </group>
    41     41         <group targetFramework="net45">
    42         -        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
           42  +        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
    43     43         </group>
    44     44         <group targetFramework="net451">
    45         -        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
           45  +        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
    46     46         </group>
    47     47         <group targetFramework="net46">
    48         -        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
           48  +        <dependency id="System.Data.SQLite.EF6" version="1.0.99.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.98.1</version>
           13  +    <version>1.0.99.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.98.1" />
           24  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    25     25         </group>
    26     26         <group targetFramework="net40">
    27         -        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
           27  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    28     28         </group>
    29     29         <group targetFramework="net45">
    30         -        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
           30  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    31     31         </group>
    32     32         <group targetFramework="net451">
    33         -        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
           33  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    34     34         </group>
    35     35         <group targetFramework="net46">
    36         -        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
           36  +        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
    37     37         </group>
    38     38         <group targetFramework="net40">
    39         -        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
           39  +        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
    40     40         </group>
    41     41         <group targetFramework="net45">
    42         -        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
           42  +        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
    43     43         </group>
    44     44         <group targetFramework="net451">
    45         -        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
           45  +        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
    46     46         </group>
    47     47         <group targetFramework="net46">
    48         -        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
           48  +        <dependency id="System.Data.SQLite.EF6" version="1.0.99.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.98.0")]
    47         -[assembly: AssemblyFileVersion("1.0.98.0")]
           46  +[assembly: AssemblyVersion("1.0.99.0")]
           47  +[assembly: AssemblyFileVersion("1.0.99.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.98.0</Version>
            6  +    <Version>1.0.99.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="098"
           22  +		Value="099"
    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.98.0"
           32  +		Value="1.0.99.0"
    33     33   		PerformEnvironmentSet="true"
    34     34   	/>
    35     35   	<UserMacro
    36     36   		Name="INTEROP_RC_VERSION"
    37         -		Value="1,0,98,0"
           37  +		Value="1,0,99,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="098"
           22  +		Value="099"
    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.98.0"
           32  +		Value="1.0.99.0"
    33     33   		PerformEnvironmentSet="true"
    34     34   	/>
    35     35   	<UserMacro
    36     36   		Name="INTEROP_RC_VERSION"
    37         -		Value="1,0,98,0"
           37  +		Value="1,0,99,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>098</INTEROP_BUILD_NUMBER>
           13  +    <INTEROP_BUILD_NUMBER>099</INTEROP_BUILD_NUMBER>
    14     14       <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION>
    15         -    <INTEROP_MANIFEST_VERSION>1.0.98.0</INTEROP_MANIFEST_VERSION>
    16         -    <INTEROP_RC_VERSION>1,0,98,0</INTEROP_RC_VERSION>
           15  +    <INTEROP_MANIFEST_VERSION>1.0.99.0</INTEROP_MANIFEST_VERSION>
           16  +    <INTEROP_RC_VERSION>1,0,99,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_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>098</INTEROP_BUILD_NUMBER>
           13  +    <INTEROP_BUILD_NUMBER>099</INTEROP_BUILD_NUMBER>
    14     14       <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION>
    15         -    <INTEROP_MANIFEST_VERSION>1.0.98.0</INTEROP_MANIFEST_VERSION>
    16         -    <INTEROP_RC_VERSION>1,0,98,0</INTEROP_RC_VERSION>
           15  +    <INTEROP_MANIFEST_VERSION>1.0.99.0</INTEROP_MANIFEST_VERSION>
           16  +    <INTEROP_RC_VERSION>1,0,99,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_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>098</INTEROP_BUILD_NUMBER>
           13  +    <INTEROP_BUILD_NUMBER>099</INTEROP_BUILD_NUMBER>
    14     14       <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION>
    15         -    <INTEROP_MANIFEST_VERSION>1.0.98.0</INTEROP_MANIFEST_VERSION>
    16         -    <INTEROP_RC_VERSION>1,0,98,0</INTEROP_RC_VERSION>
           15  +    <INTEROP_MANIFEST_VERSION>1.0.99.0</INTEROP_MANIFEST_VERSION>
           16  +    <INTEROP_RC_VERSION>1,0,99,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_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>098</INTEROP_BUILD_NUMBER>
           13  +    <INTEROP_BUILD_NUMBER>099</INTEROP_BUILD_NUMBER>
    14     14       <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION>
    15         -    <INTEROP_MANIFEST_VERSION>1.0.98.0</INTEROP_MANIFEST_VERSION>
    16         -    <INTEROP_RC_VERSION>1,0,98,0</INTEROP_RC_VERSION>
           15  +    <INTEROP_MANIFEST_VERSION>1.0.99.0</INTEROP_MANIFEST_VERSION>
           16  +    <INTEROP_RC_VERSION>1,0,99,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_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.8.11.1</SQLITE_MANIFEST_VERSION>
    13         -    <SQLITE_RC_VERSION>3,8,11,1</SQLITE_RC_VERSION>
           12  +    <SQLITE_MANIFEST_VERSION>3.8.12.0</SQLITE_MANIFEST_VERSION>
           13  +    <SQLITE_RC_VERSION>3,8,12,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_FTS5=1;SQLITE_ENABLE_LOAD_EXTENSION=1;SQLITE_ENABLE_RTREE=1;SQLITE_SOUNDEX=1;SQLITE_ENABLE_MEMORY_MANAGEMENT=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.8.11.1"
           17  +		Value="3.8.12.0"
    18     18   		PerformEnvironmentSet="true"
    19     19   	/>
    20     20   	<UserMacro
    21     21   		Name="SQLITE_RC_VERSION"
    22         -		Value="3,8,11,1"
           22  +		Value="3,8,12,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_FTS5=1;SQLITE_ENABLE_LOAD_EXTENSION=1;SQLITE_ENABLE_RTREE=1;SQLITE_SOUNDEX=1;SQLITE_ENABLE_MEMORY_MANAGEMENT=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.8.11.1.  By combining all the individual C code files into this 
            3  +** version 3.8.12.  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
................................................................................
   321    321   ** string contains the date and time of the check-in (UTC) and an SHA1
   322    322   ** hash of the entire source tree.
   323    323   **
   324    324   ** See also: [sqlite3_libversion()],
   325    325   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   326    326   ** [sqlite_version()] and [sqlite_source_id()].
   327    327   */
   328         -#define SQLITE_VERSION        "3.8.11.1"
   329         -#define SQLITE_VERSION_NUMBER 3008011
   330         -#define SQLITE_SOURCE_ID      "2015-07-29 20:00:57 cf538e2783e468bbc25e7cb2a9ee64d3e0e80b2f"
          328  +#define SQLITE_VERSION        "3.8.12"
          329  +#define SQLITE_VERSION_NUMBER 3008012
          330  +#define SQLITE_SOURCE_ID      "2015-09-09 19:44:33 8d2ed150a7a15626965cf994ef48c3ab61eca6ec"
   331    331   
   332    332   /*
   333    333   ** CAPI3REF: Run-Time Library Version Numbers
   334    334   ** KEYWORDS: sqlite3_version, sqlite3_sourceid
   335    335   **
   336    336   ** These interfaces provide the same information as the [SQLITE_VERSION],
   337    337   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
   687    687   #define SQLITE_IOERR_SHMLOCK           (SQLITE_IOERR | (20<<8))
   688    688   #define SQLITE_IOERR_SHMMAP            (SQLITE_IOERR | (21<<8))
   689    689   #define SQLITE_IOERR_SEEK              (SQLITE_IOERR | (22<<8))
   690    690   #define SQLITE_IOERR_DELETE_NOENT      (SQLITE_IOERR | (23<<8))
   691    691   #define SQLITE_IOERR_MMAP              (SQLITE_IOERR | (24<<8))
   692    692   #define SQLITE_IOERR_GETTEMPPATH       (SQLITE_IOERR | (25<<8))
   693    693   #define SQLITE_IOERR_CONVPATH          (SQLITE_IOERR | (26<<8))
          694  +#define SQLITE_IOERR_VNODE             (SQLITE_IOERR | (27<<8))
   694    695   #define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED |  (1<<8))
   695    696   #define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
   696    697   #define SQLITE_BUSY_SNAPSHOT           (SQLITE_BUSY   |  (2<<8))
   697    698   #define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
   698    699   #define SQLITE_CANTOPEN_ISDIR          (SQLITE_CANTOPEN | (2<<8))
   699    700   #define SQLITE_CANTOPEN_FULLPATH       (SQLITE_CANTOPEN | (3<<8))
   700    701   #define SQLITE_CANTOPEN_CONVPATH       (SQLITE_CANTOPEN | (4<<8))
................................................................................
  3583   3584   
  3584   3585   /*
  3585   3586   ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
  3586   3587   ** METHOD: sqlite3_stmt
  3587   3588   **
  3588   3589   ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
  3589   3590   ** [prepared statement] S has been stepped at least once using 
  3590         -** [sqlite3_step(S)] but has not run to completion and/or has not 
         3591  +** [sqlite3_step(S)] but has neither run to completion (returned
         3592  +** [SQLITE_DONE] from [sqlite3_step(S)]) nor
  3591   3593   ** been reset using [sqlite3_reset(S)].  ^The sqlite3_stmt_busy(S)
  3592   3594   ** interface returns false if S is a NULL pointer.  If S is not a 
  3593   3595   ** NULL pointer and is not a pointer to a valid [prepared statement]
  3594   3596   ** object, then the behavior is undefined and probably undesirable.
  3595   3597   **
  3596   3598   ** This interface can be used in combination [sqlite3_next_stmt()]
  3597   3599   ** to locate all prepared statements associated with a database 
................................................................................
  8359   8361   #  define SQLITE_NOINLINE  __declspec(noinline)
  8360   8362   #else
  8361   8363   #  define SQLITE_NOINLINE
  8362   8364   #endif
  8363   8365   
  8364   8366   /*
  8365   8367   ** Make sure that the compiler intrinsics we desire are enabled when
  8366         -** compiling with an appropriate version of MSVC.
         8368  +** compiling with an appropriate version of MSVC unless prevented by
         8369  +** the SQLITE_DISABLE_INTRINSIC define.
  8367   8370   */
  8368         -#if defined(_MSC_VER) && _MSC_VER>=1300
  8369         -#  if !defined(_WIN32_WCE)
  8370         -#    include <intrin.h>
  8371         -#    pragma intrinsic(_byteswap_ushort)
  8372         -#    pragma intrinsic(_byteswap_ulong)
  8373         -#  else
  8374         -#    include <cmnintrin.h>
         8371  +#if !defined(SQLITE_DISABLE_INTRINSIC)
         8372  +#  if defined(_MSC_VER) && _MSC_VER>=1300
         8373  +#    if !defined(_WIN32_WCE)
         8374  +#      include <intrin.h>
         8375  +#      pragma intrinsic(_byteswap_ushort)
         8376  +#      pragma intrinsic(_byteswap_ulong)
         8377  +#    else
         8378  +#      include <cmnintrin.h>
         8379  +#    endif
  8375   8380   #  endif
  8376   8381   #endif
  8377   8382   
  8378   8383   /*
  8379   8384   ** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
  8380   8385   ** 0 means mutexes are permanently disable and the library is never
  8381   8386   ** threadsafe.  1 means the library is serialized which is the highest
................................................................................
 10048  10053   ** Prototypes for the VDBE interface.  See comments on the implementation
 10049  10054   ** for a description of what each of these routines does.
 10050  10055   */
 10051  10056   SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse*);
 10052  10057   SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe*,int);
 10053  10058   SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int);
 10054  10059   SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
        10060  +SQLITE_PRIVATE int sqlite3VdbeGoto(Vdbe*,int);
        10061  +SQLITE_PRIVATE int sqlite3VdbeLoadString(Vdbe*,int,const char*);
        10062  +SQLITE_PRIVATE void sqlite3VdbeMultiLoad(Vdbe*,int,const char*,...);
 10055  10063   SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
 10056  10064   SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
 10057  10065   SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(Vdbe*,int,int,int,int,const u8*,int);
 10058  10066   SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
 10059  10067   SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno);
 10060  10068   SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
        10069  +SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe*, u32 addr, u8);
 10061  10070   SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
 10062  10071   SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
 10063  10072   SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
 10064  10073   SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
 10065  10074   SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
 10066  10075   SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr);
 10067  10076   SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
................................................................................
 10911  10920   #define sqlite3_mutex_try(X)      SQLITE_OK
 10912  10921   #define sqlite3_mutex_leave(X)    
 10913  10922   #define sqlite3_mutex_held(X)     ((void)(X),1)
 10914  10923   #define sqlite3_mutex_notheld(X)  ((void)(X),1)
 10915  10924   #define sqlite3MutexAlloc(X)      ((sqlite3_mutex*)8)
 10916  10925   #define sqlite3MutexInit()        SQLITE_OK
 10917  10926   #define sqlite3MutexEnd()
        10927  +#define sqlite3MemoryBarrier()    
 10918  10928   #define MUTEX_LOGIC(X)
 10919  10929   #else
 10920  10930   #define MUTEX_LOGIC(X)            X
 10921  10931   #endif /* defined(SQLITE_MUTEX_OMIT) */
 10922  10932   
 10923  10933   /************** End of mutex.h ***********************************************/
 10924  10934   /************** Continuing where we left off in sqliteInt.h ******************/
................................................................................
 11331  11341   };
 11332  11342   
 11333  11343   /*
 11334  11344   ** Possible values for FuncDef.flags.  Note that the _LENGTH and _TYPEOF
 11335  11345   ** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG.  There
 11336  11346   ** are assert() statements in the code to verify this.
 11337  11347   */
 11338         -#define SQLITE_FUNC_ENCMASK  0x003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
 11339         -#define SQLITE_FUNC_LIKE     0x004 /* Candidate for the LIKE optimization */
 11340         -#define SQLITE_FUNC_CASE     0x008 /* Case-sensitive LIKE-type function */
 11341         -#define SQLITE_FUNC_EPHEM    0x010 /* Ephemeral.  Delete with VDBE */
 11342         -#define SQLITE_FUNC_NEEDCOLL 0x020 /* sqlite3GetFuncCollSeq() might be called */
 11343         -#define SQLITE_FUNC_LENGTH   0x040 /* Built-in length() function */
 11344         -#define SQLITE_FUNC_TYPEOF   0x080 /* Built-in typeof() function */
 11345         -#define SQLITE_FUNC_COUNT    0x100 /* Built-in count(*) aggregate */
 11346         -#define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
 11347         -#define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */
 11348         -#define SQLITE_FUNC_CONSTANT 0x800 /* Constant inputs give a constant output */
 11349         -#define SQLITE_FUNC_MINMAX  0x1000 /* True for min() and max() aggregates */
        11348  +#define SQLITE_FUNC_ENCMASK  0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
        11349  +#define SQLITE_FUNC_LIKE     0x0004 /* Candidate for the LIKE optimization */
        11350  +#define SQLITE_FUNC_CASE     0x0008 /* Case-sensitive LIKE-type function */
        11351  +#define SQLITE_FUNC_EPHEM    0x0010 /* Ephemeral.  Delete with VDBE */
        11352  +#define SQLITE_FUNC_NEEDCOLL 0x0020 /* sqlite3GetFuncCollSeq() might be called*/
        11353  +#define SQLITE_FUNC_LENGTH   0x0040 /* Built-in length() function */
        11354  +#define SQLITE_FUNC_TYPEOF   0x0080 /* Built-in typeof() function */
        11355  +#define SQLITE_FUNC_COUNT    0x0100 /* Built-in count(*) aggregate */
        11356  +#define SQLITE_FUNC_COALESCE 0x0200 /* Built-in coalesce() or ifnull() */
        11357  +#define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */
        11358  +#define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
        11359  +#define SQLITE_FUNC_MINMAX   0x1000 /* True for min() and max() aggregates */
        11360  +#define SQLITE_FUNC_SLOCHNG  0x2000 /* "Slow Change". Value constant during a
        11361  +                                    ** single query - might change over time */
 11350  11362   
 11351  11363   /*
 11352  11364   ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
 11353  11365   ** used to create the initializers for the FuncDef structures.
 11354  11366   **
 11355  11367   **   FUNCTION(zName, nArg, iArg, bNC, xFunc)
 11356  11368   **     Used to create a scalar function definition of a function zName 
................................................................................
 11357  11369   **     implemented by C function xFunc that accepts nArg arguments. The
 11358  11370   **     value passed as iArg is cast to a (void*) and made available
 11359  11371   **     as the user-data (sqlite3_user_data()) for the function. If 
 11360  11372   **     argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
 11361  11373   **
 11362  11374   **   VFUNCTION(zName, nArg, iArg, bNC, xFunc)
 11363  11375   **     Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag.
        11376  +**
        11377  +**   DFUNCTION(zName, nArg, iArg, bNC, xFunc)
        11378  +**     Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
        11379  +**     adds the SQLITE_FUNC_SLOCHNG flag.  Used for date & time functions
        11380  +**     and functions like sqlite_version() that can change, but not during
        11381  +**     a single query.
 11364  11382   **
 11365  11383   **   AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
 11366  11384   **     Used to create an aggregate function definition implemented by
 11367  11385   **     the C functions xStep and xFinal. The first four parameters
 11368  11386   **     are interpreted in the same way as the first 4 parameters to
 11369  11387   **     FUNCTION().
 11370  11388   **
................................................................................
 11378  11396   */
 11379  11397   #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
 11380  11398     {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
 11381  11399      SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
 11382  11400   #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
 11383  11401     {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
 11384  11402      SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
        11403  +#define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
        11404  +  {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
        11405  +   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
 11385  11406   #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
 11386  11407     {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
 11387  11408      SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
 11388  11409   #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
 11389         -  {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
        11410  +  {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
 11390  11411      pArg, 0, xFunc, 0, 0, #zName, 0, 0}
 11391  11412   #define LIKEFUNC(zName, nArg, arg, flags) \
 11392  11413     {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
 11393  11414      (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
 11394  11415   #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
 11395  11416     {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
 11396  11417      SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
................................................................................
 11426  11447   ** hash table.
 11427  11448   */
 11428  11449   struct Module {
 11429  11450     const sqlite3_module *pModule;       /* Callback pointers */
 11430  11451     const char *zName;                   /* Name passed to create_module() */
 11431  11452     void *pAux;                          /* pAux passed to create_module() */
 11432  11453     void (*xDestroy)(void *);            /* Module destructor function */
        11454  +  Table *pEpoTab;                      /* Eponymous table for this module */
 11433  11455   };
 11434  11456   
 11435  11457   /*
 11436  11458   ** information about each column of an SQL table is held in an instance
 11437  11459   ** of this structure.
 11438  11460   */
 11439  11461   struct Column {
................................................................................
 11471  11493   };
 11472  11494   
 11473  11495   /*
 11474  11496   ** A sort order can be either ASC or DESC.
 11475  11497   */
 11476  11498   #define SQLITE_SO_ASC       0  /* Sort in ascending order */
 11477  11499   #define SQLITE_SO_DESC      1  /* Sort in ascending order */
        11500  +#define SQLITE_SO_UNDEFINED -1 /* No sort order specified */
 11478  11501   
 11479  11502   /*
 11480  11503   ** Column affinity types.
 11481  11504   **
 11482  11505   ** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and
 11483  11506   ** 't' for SQLITE_AFF_TEXT.  But we can save a little space and improve
 11484  11507   ** the speed a little by numbering the values consecutively.  
................................................................................
 11577  11600   struct Table {
 11578  11601     char *zName;         /* Name of the table or view */
 11579  11602     Column *aCol;        /* Information about each column */
 11580  11603     Index *pIndex;       /* List of SQL indexes on this table. */
 11581  11604     Select *pSelect;     /* NULL for tables.  Points to definition if a view. */
 11582  11605     FKey *pFKey;         /* Linked list of all foreign keys in this table */
 11583  11606     char *zColAff;       /* String defining the affinity of each column */
 11584         -#ifndef SQLITE_OMIT_CHECK
 11585  11607     ExprList *pCheck;    /* All CHECK constraints */
 11586         -#endif
        11608  +                       /*   ... also used as column name list in a VIEW */
 11587  11609     int tnum;            /* Root BTree page for this table */
 11588  11610     i16 iPKey;           /* If not negative, use aCol[iPKey] as the rowid */
 11589  11611     i16 nCol;            /* Number of columns in this table */
 11590  11612     u16 nRef;            /* Number of pointers to this Table */
 11591  11613     LogEst nRowLogEst;   /* Estimated rows in table - from sqlite_stat1 table */
 11592  11614     LogEst szTabRow;     /* Estimated size of each table row in bytes */
 11593  11615   #ifdef SQLITE_ENABLE_COSTMULT
................................................................................
 11596  11618     u8 tabFlags;         /* Mask of TF_* values */
 11597  11619     u8 keyConf;          /* What to do in case of uniqueness conflict on iPKey */
 11598  11620   #ifndef SQLITE_OMIT_ALTERTABLE
 11599  11621     int addColOffset;    /* Offset in CREATE TABLE stmt to add a new column */
 11600  11622   #endif
 11601  11623   #ifndef SQLITE_OMIT_VIRTUALTABLE
 11602  11624     int nModuleArg;      /* Number of arguments to the module */
 11603         -  char **azModuleArg;  /* Text of all module args. [0] is module name */
        11625  +  char **azModuleArg;  /* 0: module 1: schema 2: vtab name 3...: args */
 11604  11626     VTable *pVTable;     /* List of VTable objects. */
 11605  11627   #endif
 11606  11628     Trigger *pTrigger;   /* List of triggers stored in pSchema */
 11607  11629     Schema *pSchema;     /* Schema that contains this table */
 11608  11630     Table *pNextZombie;  /* Next on the Parse.pZombieTab list */
 11609  11631   };
 11610  11632   
................................................................................
 11817  11839     Table *pTable;           /* The SQL table being indexed */
 11818  11840     char *zColAff;           /* String defining the affinity of each column */
 11819  11841     Index *pNext;            /* The next index associated with the same table */
 11820  11842     Schema *pSchema;         /* Schema containing this index */
 11821  11843     u8 *aSortOrder;          /* for each column: True==DESC, False==ASC */
 11822  11844     char **azColl;           /* Array of collation sequence names for index */
 11823  11845     Expr *pPartIdxWhere;     /* WHERE clause for partial indices */
        11846  +  ExprList *aColExpr;      /* Column expressions */
 11824  11847     int tnum;                /* DB Page containing root of this index */
 11825  11848     LogEst szIdxRow;         /* Estimated average row size in bytes */
 11826  11849     u16 nKeyCol;             /* Number of columns forming the key */
 11827  11850     u16 nColumn;             /* Number of columns stored in the index */
 11828  11851     u8 onError;              /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
 11829  11852     unsigned idxType:2;      /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */
 11830  11853     unsigned bUnordered:1;   /* Use this index for == or IN queries only */
................................................................................
 12066  12089   #define EP_Skip      0x001000 /* COLLATE, AS, or UNLIKELY */
 12067  12090   #define EP_Reduced   0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
 12068  12091   #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
 12069  12092   #define EP_Static    0x008000 /* Held in memory not obtained from malloc() */
 12070  12093   #define EP_MemToken  0x010000 /* Need to sqlite3DbFree() Expr.zToken */
 12071  12094   #define EP_NoReduce  0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
 12072  12095   #define EP_Unlikely  0x040000 /* unlikely() or likelihood() function */
 12073         -#define EP_ConstFunc 0x080000 /* Node is a SQLITE_FUNC_CONSTANT function */
        12096  +#define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
 12074  12097   #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
 12075  12098   #define EP_Subquery  0x200000 /* Tree contains a TK_SELECT operator */
        12099  +#define EP_Alias     0x400000 /* Is an alias for a result set column */
 12076  12100   
 12077  12101   /*
 12078  12102   ** Combinations of two or more EP_* flags
 12079  12103   */
 12080  12104   #define EP_Propagate (EP_Collate|EP_Subquery) /* Propagate these bits up tree */
 12081  12105   
 12082  12106   /*
................................................................................
 12231  12255       char *zName;      /* Name of the table */
 12232  12256       char *zAlias;     /* The "B" part of a "A AS B" phrase.  zName is the "A" */
 12233  12257       Table *pTab;      /* An SQL table corresponding to zName */
 12234  12258       Select *pSelect;  /* A SELECT statement used in place of a table name */
 12235  12259       int addrFillSub;  /* Address of subroutine to manifest a subquery */
 12236  12260       int regReturn;    /* Register holding return address of addrFillSub */
 12237  12261       int regResult;    /* Registers holding results of a co-routine */
 12238         -    u8 jointype;      /* Type of join between this able and the previous */
 12239         -    unsigned notIndexed :1;    /* True if there is a NOT INDEXED clause */
 12240         -    unsigned isCorrelated :1;  /* True if sub-query is correlated */
 12241         -    unsigned viaCoroutine :1;  /* Implemented as a co-routine */
 12242         -    unsigned isRecursive :1;   /* True for recursive reference in WITH */
        12262  +    struct {
        12263  +      u8 jointype;      /* Type of join between this able and the previous */
        12264  +      unsigned notIndexed :1;    /* True if there is a NOT INDEXED clause */
        12265  +      unsigned isIndexedBy :1;   /* True if there is an INDEXED BY clause */
        12266  +      unsigned isTabFunc :1;     /* True if table-valued-function syntax */
        12267  +      unsigned isCorrelated :1;  /* True if sub-query is correlated */
        12268  +      unsigned viaCoroutine :1;  /* Implemented as a co-routine */
        12269  +      unsigned isRecursive :1;   /* True for recursive reference in WITH */
        12270  +    } fg;
 12243  12271   #ifndef SQLITE_OMIT_EXPLAIN
 12244  12272       u8 iSelectId;     /* If pSelect!=0, the id of the sub-select in EQP */
 12245  12273   #endif
 12246  12274       int iCursor;      /* The VDBE cursor number used to access this table */
 12247  12275       Expr *pOn;        /* The ON clause of a join */
 12248  12276       IdList *pUsing;   /* The USING clause of a join */
 12249  12277       Bitmask colUsed;  /* Bit N (1<<N) set if column N of pTab is used */
 12250         -    char *zIndexedBy; /* Identifier from "INDEXED BY <zIndex>" clause */
 12251         -    Index *pIndex;    /* Index structure corresponding to zIndex, if any */
        12278  +    union {
        12279  +      char *zIndexedBy;    /* Identifier from "INDEXED BY <zIndex>" clause */
        12280  +      ExprList *pFuncArg;  /* Arguments to table-valued-function */
        12281  +    } u1;
        12282  +    Index *pIBIndex;  /* Index structure corresponding to u1.zIndexedBy */
 12252  12283     } a[1];             /* One entry for each identifier on the list */
 12253  12284   };
 12254  12285   
 12255  12286   /*
 12256  12287   ** Permitted values of the SrcList.a.jointype field
 12257  12288   */
 12258  12289   #define JT_INNER     0x0001    /* Any kind of inner or cross join */
................................................................................
 12330  12361   ** 
 12331  12362   */
 12332  12363   #define NC_AllowAgg  0x0001  /* Aggregate functions are allowed here */
 12333  12364   #define NC_HasAgg    0x0002  /* One or more aggregate functions seen */
 12334  12365   #define NC_IsCheck   0x0004  /* True if resolving names in a CHECK constraint */
 12335  12366   #define NC_InAggFunc 0x0008  /* True if analyzing arguments to an agg func */
 12336  12367   #define NC_PartIdx   0x0010  /* True if resolving a partial index WHERE */
        12368  +#define NC_IdxExpr   0x0020  /* True if resolving columns of CREATE INDEX */
 12337  12369   #define NC_MinMaxAgg 0x1000  /* min/max aggregates seen.  See note above */
 12338  12370   
 12339  12371   /*
 12340  12372   ** An instance of the following structure contains all information
 12341  12373   ** needed to generate code for a single SELECT statement.
 12342  12374   **
 12343  12375   ** nLimit is set to -1 if there is no LIMIT clause.  nOffset is set to 0.
................................................................................
 12599  12631     int nTab;            /* Number of previously allocated VDBE cursors */
 12600  12632     int nMem;            /* Number of memory cells used so far */
 12601  12633     int nSet;            /* Number of sets used so far */
 12602  12634     int nOnce;           /* Number of OP_Once instructions so far */
 12603  12635     int nOpAlloc;        /* Number of slots allocated for Vdbe.aOp[] */
 12604  12636     int iFixedOp;        /* Never back out opcodes iFixedOp-1 or earlier */
 12605  12637     int ckBase;          /* Base register of data during check constraints */
 12606         -  int iPartIdxTab;     /* Table corresponding to a partial index */
        12638  +  int iSelfTab;        /* Table of an index whose exprs are being coded */
 12607  12639     int iCacheLevel;     /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
 12608  12640     int iCacheCnt;       /* Counter used to generate aColCache[].lru values */
 12609  12641     int nLabel;          /* Number of labels used */
 12610  12642     int *aLabel;         /* Space to hold the labels */
 12611  12643     struct yColCache {
 12612  12644       int iTable;           /* Table cursor number */
 12613  12645       i16 iColumn;          /* Table column number */
................................................................................
 12969  13001   struct With {
 12970  13002     int nCte;                       /* Number of CTEs in the WITH clause */
 12971  13003     With *pOuter;                   /* Containing WITH clause, or NULL */
 12972  13004     struct Cte {                    /* For each CTE in the WITH clause.... */
 12973  13005       char *zName;                    /* Name of this CTE */
 12974  13006       ExprList *pCols;                /* List of explicit column names, or NULL */
 12975  13007       Select *pSelect;                /* The definition of this CTE */
 12976         -    const char *zErr;               /* Error message for circular references */
        13008  +    const char *zCteErr;            /* Error message for circular references */
 12977  13009     } a[1];
 12978  13010   };
 12979  13011   
 12980  13012   #ifdef SQLITE_DEBUG
 12981  13013   /*
 12982  13014   ** An instance of the TreeView object is used for printing the content of
 12983  13015   ** data structures on sqlite3DebugPrintf() using a tree-like view.
................................................................................
 13116  13148   
 13117  13149   #ifndef SQLITE_MUTEX_OMIT
 13118  13150   SQLITE_PRIVATE   sqlite3_mutex_methods const *sqlite3DefaultMutex(void);
 13119  13151   SQLITE_PRIVATE   sqlite3_mutex_methods const *sqlite3NoopMutex(void);
 13120  13152   SQLITE_PRIVATE   sqlite3_mutex *sqlite3MutexAlloc(int);
 13121  13153   SQLITE_PRIVATE   int sqlite3MutexInit(void);
 13122  13154   SQLITE_PRIVATE   int sqlite3MutexEnd(void);
        13155  +SQLITE_PRIVATE   void sqlite3MemoryBarrier(void);
 13123  13156   #endif
 13124  13157   
 13125  13158   SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int);
 13126  13159   SQLITE_PRIVATE void sqlite3StatusUp(int, int);
 13127  13160   SQLITE_PRIVATE void sqlite3StatusDown(int, int);
 13128  13161   SQLITE_PRIVATE void sqlite3StatusSet(int, int);
 13129  13162   
................................................................................
 13183  13216   SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
 13184  13217   SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
 13185  13218   SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
 13186  13219   SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
 13187  13220   SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*);
 13188  13221   SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
 13189  13222   SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
        13223  +SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int);
 13190  13224   SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
 13191  13225   SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
 13192  13226   SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
 13193  13227   SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
 13194  13228   SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
 13195  13229   SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
 13196  13230   SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
 13197  13231   SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*);
 13198  13232   SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
 13199  13233   SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
 13200  13234   SQLITE_PRIVATE void sqlite3BeginParse(Parse*,int);
 13201  13235   SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
        13236  +SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*);
        13237  +SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**);
 13202  13238   SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*);
 13203  13239   SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int);
 13204  13240   SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*);
 13205  13241   SQLITE_PRIVATE i16 sqlite3ColumnOfIndex(Index*, i16);
 13206  13242   SQLITE_PRIVATE void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
 13207  13243   SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*);
 13208  13244   SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int);
................................................................................
 13236  13272   
 13237  13273   SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3*, void*, unsigned int);
 13238  13274   SQLITE_PRIVATE void sqlite3RowSetClear(RowSet*);
 13239  13275   SQLITE_PRIVATE void sqlite3RowSetInsert(RowSet*, i64);
 13240  13276   SQLITE_PRIVATE int sqlite3RowSetTest(RowSet*, int iBatch, i64);
 13241  13277   SQLITE_PRIVATE int sqlite3RowSetNext(RowSet*, i64*);
 13242  13278   
 13243         -SQLITE_PRIVATE void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int,int);
        13279  +SQLITE_PRIVATE void sqlite3CreateView(Parse*,Token*,Token*,Token*,ExprList*,Select*,int,int);
 13244  13280   
 13245  13281   #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
 13246  13282   SQLITE_PRIVATE   int sqlite3ViewGetColumnNames(Parse*,Table*);
 13247  13283   #else
 13248  13284   # define sqlite3ViewGetColumnNames(A,B) 0
 13249  13285   #endif
 13250  13286   
................................................................................
 13266  13302   SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
 13267  13303   SQLITE_PRIVATE int sqlite3IdListIndex(IdList*,const char*);
 13268  13304   SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
 13269  13305   SQLITE_PRIVATE SrcList *sqlite3SrcListAppend(sqlite3*, SrcList*, Token*, Token*);
 13270  13306   SQLITE_PRIVATE SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*,
 13271  13307                                         Token*, Select*, Expr*, IdList*);
 13272  13308   SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token *);
        13309  +SQLITE_PRIVATE void sqlite3SrcListFuncArgs(Parse*, SrcList*, ExprList*);
 13273  13310   SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
 13274  13311   SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList*);
 13275  13312   SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse*, SrcList*);
 13276  13313   SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*);
 13277  13314   SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*);
 13278  13315   SQLITE_PRIVATE Index *sqlite3AllocateIndexObject(sqlite3*,i16,int,char**);
 13279  13316   SQLITE_PRIVATE Index *sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
................................................................................
 13296  13333   SQLITE_PRIVATE u64 sqlite3WhereOutputRowCount(WhereInfo*);
 13297  13334   SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*);
 13298  13335   SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
 13299  13336   SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo*);
 13300  13337   SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*);
 13301  13338   SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*);
 13302  13339   SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*, int*);
        13340  +SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int);
 13303  13341   SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
 13304  13342   SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
 13305  13343   SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
 13306  13344   SQLITE_PRIVATE void sqlite3ExprCacheStore(Parse*, int, int, int);
 13307  13345   SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
 13308  13346   SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*);
 13309  13347   SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
................................................................................
 13311  13349   SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
 13312  13350   SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
 13313  13351   SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
 13314  13352   SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
 13315  13353   SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
 13316  13354   SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
 13317  13355   SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
 13318         -SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, u8);
        13356  +SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8);
 13319  13357   #define SQLITE_ECEL_DUP      0x01  /* Deep, not shallow copies */
 13320  13358   #define SQLITE_ECEL_FACTOR   0x02  /* Factor out constant terms */
        13359  +#define SQLITE_ECEL_REF      0x04  /* Use ExprList.u.x.iOrderByCol */
 13321  13360   SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
 13322  13361   SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
 13323  13362   SQLITE_PRIVATE void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int);
 13324  13363   SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
 13325  13364   SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
 13326  13365   SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *);
 13327  13366   SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
................................................................................
 13485  13524   #define putVarint32(A,B)  \
 13486  13525     (u8)(((u32)(B)<(u32)0x80)?(*(A)=(unsigned char)(B)),1:\
 13487  13526     sqlite3PutVarint((A),(B)))
 13488  13527   #define getVarint    sqlite3GetVarint
 13489  13528   #define putVarint    sqlite3PutVarint
 13490  13529   
 13491  13530   
 13492         -SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *, Index *);
        13531  +SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(sqlite3*, Index*);
 13493  13532   SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
 13494  13533   SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
 13495  13534   SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
 13496  13535   SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
 13497  13536   SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
 13498  13537   SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char*, i64*);
 13499  13538   SQLITE_PRIVATE void sqlite3ErrorWithMsg(sqlite3*, int, const char*,...);
................................................................................
 13557  13596   SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
 13558  13597   SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*);
 13559  13598   SQLITE_PRIVATE int sqlite3CodeSubselect(Parse *, Expr *, int, int);
 13560  13599   SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
 13561  13600   SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
 13562  13601   SQLITE_PRIVATE int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
 13563  13602   SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*);
        13603  +SQLITE_PRIVATE int sqlite3ResolveExprListNames(NameContext*, ExprList*);
 13564  13604   SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
 13565  13605   SQLITE_PRIVATE void sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
 13566  13606   SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
 13567  13607   SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
 13568  13608   SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *, Token *);
 13569  13609   SQLITE_PRIVATE void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
 13570  13610   SQLITE_PRIVATE CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*);
................................................................................
 13665  13705   SQLITE_PRIVATE    void sqlite3VtabUnlock(VTable *);
 13666  13706   SQLITE_PRIVATE    void sqlite3VtabUnlockList(sqlite3*);
 13667  13707   SQLITE_PRIVATE    int sqlite3VtabSavepoint(sqlite3 *, int, int);
 13668  13708   SQLITE_PRIVATE    void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*);
 13669  13709   SQLITE_PRIVATE    VTable *sqlite3GetVTable(sqlite3*, Table*);
 13670  13710   #  define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
 13671  13711   #endif
        13712  +SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*);
        13713  +SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3*,Module*);
 13672  13714   SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
 13673  13715   SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int);
 13674  13716   SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse*, Token*);
 13675  13717   SQLITE_PRIVATE void sqlite3VtabArgInit(Parse*);
 13676  13718   SQLITE_PRIVATE void sqlite3VtabArgExtend(Parse*, Token*);
 13677  13719   SQLITE_PRIVATE int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **);
 13678  13720   SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse*, Table*);
................................................................................
 16544  16586   ** This function registered all of the above C functions as SQL
 16545  16587   ** functions.  This should be the only routine in this file with
 16546  16588   ** external linkage.
 16547  16589   */
 16548  16590   SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void){
 16549  16591     static SQLITE_WSD FuncDef aDateTimeFuncs[] = {
 16550  16592   #ifndef SQLITE_OMIT_DATETIME_FUNCS
 16551         -    FUNCTION(julianday,        -1, 0, 0, juliandayFunc ),
 16552         -    FUNCTION(date,             -1, 0, 0, dateFunc      ),
 16553         -    FUNCTION(time,             -1, 0, 0, timeFunc      ),
 16554         -    FUNCTION(datetime,         -1, 0, 0, datetimeFunc  ),
 16555         -    FUNCTION(strftime,         -1, 0, 0, strftimeFunc  ),
 16556         -    FUNCTION(current_time,      0, 0, 0, ctimeFunc     ),
 16557         -    FUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
 16558         -    FUNCTION(current_date,      0, 0, 0, cdateFunc     ),
        16593  +    DFUNCTION(julianday,        -1, 0, 0, juliandayFunc ),
        16594  +    DFUNCTION(date,             -1, 0, 0, dateFunc      ),
        16595  +    DFUNCTION(time,             -1, 0, 0, timeFunc      ),
        16596  +    DFUNCTION(datetime,         -1, 0, 0, datetimeFunc  ),
        16597  +    DFUNCTION(strftime,         -1, 0, 0, strftimeFunc  ),
        16598  +    DFUNCTION(current_time,      0, 0, 0, ctimeFunc     ),
        16599  +    DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
        16600  +    DFUNCTION(current_date,      0, 0, 0, cdateFunc     ),
 16559  16601   #else
 16560  16602       STR_FUNCTION(current_time,      0, "%H:%M:%S",          0, currentTimeFunc),
 16561  16603       STR_FUNCTION(current_date,      0, "%Y-%m-%d",          0, currentTimeFunc),
 16562  16604       STR_FUNCTION(current_timestamp, 0, "%Y-%m-%d %H:%M:%S", 0, currentTimeFunc),
 16563  16605   #endif
 16564  16606     };
 16565  16607     int i;
................................................................................
 19271  19313       pTo->xMutexEnd = pFrom->xMutexEnd;
 19272  19314       pTo->xMutexFree = pFrom->xMutexFree;
 19273  19315       pTo->xMutexEnter = pFrom->xMutexEnter;
 19274  19316       pTo->xMutexTry = pFrom->xMutexTry;
 19275  19317       pTo->xMutexLeave = pFrom->xMutexLeave;
 19276  19318       pTo->xMutexHeld = pFrom->xMutexHeld;
 19277  19319       pTo->xMutexNotheld = pFrom->xMutexNotheld;
        19320  +    sqlite3MemoryBarrier();
 19278  19321       pTo->xMutexAlloc = pFrom->xMutexAlloc;
 19279  19322     }
 19280  19323     rc = sqlite3GlobalConfig.mutex.xMutexInit();
 19281  19324   
 19282  19325   #ifdef SQLITE_DEBUG
 19283  19326     GLOBAL(int, mutexIsInit) = 1;
 19284  19327   #endif
................................................................................
 19677  19720   static int pthreadMutexHeld(sqlite3_mutex *p){
 19678  19721     return (p->nRef!=0 && pthread_equal(p->owner, pthread_self()));
 19679  19722   }
 19680  19723   static int pthreadMutexNotheld(sqlite3_mutex *p){
 19681  19724     return p->nRef==0 || pthread_equal(p->owner, pthread_self())==0;
 19682  19725   }
 19683  19726   #endif
        19727  +
        19728  +/*
        19729  +** Try to provide a memory barrier operation, needed for initialization only.
        19730  +*/
        19731  +SQLITE_PRIVATE void sqlite3MemoryBarrier(void){
        19732  +#if defined(SQLITE_MEMORY_BARRIER)
        19733  +  SQLITE_MEMORY_BARRIER;
        19734  +#elif defined(__GNUC__)
        19735  +  __sync_synchronize();
        19736  +#endif
        19737  +}
 19684  19738   
 19685  19739   /*
 19686  19740   ** Initialize and deinitialize the mutex subsystem.
 19687  19741   */
 19688  19742   static int pthreadMutexInit(void){ return SQLITE_OK; }
 19689  19743   static int pthreadMutexEnd(void){ return SQLITE_OK; }
 19690  19744   
................................................................................
 20339  20393   }
 20340  20394   
 20341  20395   static int winMutexNotheld(sqlite3_mutex *p){
 20342  20396     DWORD tid = GetCurrentThreadId();
 20343  20397     return winMutexNotheld2(p, tid);
 20344  20398   }
 20345  20399   #endif
        20400  +
        20401  +/*
        20402  +** Try to provide a memory barrier operation, needed for initialization only.
        20403  +*/
        20404  +SQLITE_PRIVATE void sqlite3MemoryBarrier(void){
        20405  +#if defined(SQLITE_MEMORY_BARRIER)
        20406  +  SQLITE_MEMORY_BARRIER;
        20407  +#elif defined(__GNUC__)
        20408  +  __sync_synchronize();
        20409  +#else
        20410  +  MemoryBarrier();
        20411  +#endif
        20412  +}
 20346  20413   
 20347  20414   /*
 20348  20415   ** Initialize and deinitialize the mutex subsystem.
 20349  20416   */
 20350  20417   static sqlite3_mutex winMutex_staticMutexes[] = {
 20351  20418     SQLITE3_MUTEX_INITIALIZER,
 20352  20419     SQLITE3_MUTEX_INITIALIZER,
................................................................................
 20693  20760   } ScratchFreeslot;
 20694  20761   
 20695  20762   /*
 20696  20763   ** State information local to the memory allocation subsystem.
 20697  20764   */
 20698  20765   static SQLITE_WSD struct Mem0Global {
 20699  20766     sqlite3_mutex *mutex;         /* Mutex to serialize access */
 20700         -
 20701         -  /*
 20702         -  ** The alarm callback and its arguments.  The mem0.mutex lock will
 20703         -  ** be held while the callback is running.  Recursive calls into
 20704         -  ** the memory subsystem are allowed, but no new callbacks will be
 20705         -  ** issued.
 20706         -  */
 20707         -  sqlite3_int64 alarmThreshold;
 20708         -  void (*alarmCallback)(void*, sqlite3_int64,int);
 20709         -  void *alarmArg;
        20767  +  sqlite3_int64 alarmThreshold;  /* The soft heap limit */
 20710  20768   
 20711  20769     /*
 20712  20770     ** Pointers to the end of sqlite3GlobalConfig.pScratch memory
 20713  20771     ** (so that a range test can be used to determine if an allocation
 20714  20772     ** being freed came from pScratch) and a pointer to the list of
 20715  20773     ** unused scratch allocations.
 20716  20774     */
................................................................................
 20719  20777     u32 nScratchFree;
 20720  20778   
 20721  20779     /*
 20722  20780     ** True if heap is nearly "full" where "full" is defined by the
 20723  20781     ** sqlite3_soft_heap_limit() setting.
 20724  20782     */
 20725  20783     int nearlyFull;
 20726         -} mem0 = { 0, 0, 0, 0, 0, 0, 0, 0 };
        20784  +} mem0 = { 0, 0, 0, 0, 0, 0 };
 20727  20785   
 20728  20786   #define mem0 GLOBAL(struct Mem0Global, mem0)
 20729  20787   
 20730  20788   /*
 20731  20789   ** Return the memory allocator mutex. sqlite3_status() needs it.
 20732  20790   */
 20733  20791   SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void){
 20734  20792     return mem0.mutex;
 20735  20793   }
 20736  20794   
 20737  20795   /*
 20738         -** This routine runs when the memory allocator sees that the
 20739         -** total memory allocation is about to exceed the soft heap
 20740         -** limit.
        20796  +** Return the amount of memory currently in use.
 20741  20797   */
 20742         -static void softHeapLimitEnforcer(
 20743         -  void *NotUsed, 
 20744         -  sqlite3_int64 NotUsed2,
 20745         -  int allocSize
 20746         -){
 20747         -  UNUSED_PARAMETER2(NotUsed, NotUsed2);
 20748         -  sqlite3_release_memory(allocSize);
        20798  +static sqlite3_int64 memInUse(void){
        20799  +  assert( sqlite3_mutex_held(mem0.mutex) );
        20800  +  return sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
 20749  20801   }
 20750  20802   
 20751  20803   /*
 20752         -** Change the alarm callback
        20804  +** Called when the soft heap limit is exceeded for an allocation
        20805  +** of nBytes.
 20753  20806   */
 20754         -static int sqlite3MemoryAlarm(
 20755         -  void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
 20756         -  void *pArg,
 20757         -  sqlite3_int64 iThreshold
 20758         -){
 20759         -  sqlite3_int64 nUsed;
        20807  +#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
        20808  +static void sqlite3HeapLimitExceeded(int nByte){
        20809  +  sqlite3_int64 excess = memInUse() + nByte - mem0.alarmThreshold;
        20810  +  sqlite3_mutex_leave(mem0.mutex);
        20811  +  sqlite3_release_memory((int)(excess & 0x7fffffff));
 20760  20812     sqlite3_mutex_enter(mem0.mutex);
 20761         -  mem0.alarmCallback = xCallback;
 20762         -  mem0.alarmArg = pArg;
 20763         -  mem0.alarmThreshold = iThreshold;
 20764         -  nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
 20765         -  mem0.nearlyFull = (iThreshold>0 && iThreshold<=nUsed);
 20766         -  sqlite3_mutex_leave(mem0.mutex);
 20767         -  return SQLITE_OK;
        20813  +}
        20814  +#else
        20815  +# define sqlite3HeapLimitExceeded(X)  /* no-op */
        20816  +#endif
        20817  +
        20818  +/*
        20819  +** Check to see if increasing the total memory usage by nNew bytes
        20820  +** will exceed the soft heap limit.  
        20821  +**
        20822  +** If the soft heap limit is exceeded, set the mem0.nearlyFull flag
        20823  +** and invoke sqlite3HeapLimitExceeded() to try to free up some
        20824  +** memory.
        20825  +*/
        20826  +static void sqlite3CheckSoftHeapLimit(int nNew){
        20827  +  assert( sqlite3_mutex_held(mem0.mutex) );
        20828  +  if( mem0.alarmThreshold>0 ){
        20829  +    if( mem0.alarmThreshold-nNew >= memInUse() ){
        20830  +      mem0.nearlyFull = 1;
        20831  +      sqlite3HeapLimitExceeded(nNew);
        20832  +    }else{
        20833  +      mem0.nearlyFull = 0;
        20834  +    }
        20835  +  }
 20768  20836   }
 20769  20837   
 20770  20838   #ifndef SQLITE_OMIT_DEPRECATED
 20771  20839   /*
 20772         -** Deprecated external interface.  Internal/core SQLite code
 20773         -** should call sqlite3MemoryAlarm.
        20840  +** Deprecated external interface.  First deprecated 2007-11-05.  Changed
        20841  +** into a no-op on 2015-09-02.
 20774  20842   */
 20775  20843   SQLITE_API int SQLITE_STDCALL sqlite3_memory_alarm(
 20776  20844     void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
 20777  20845     void *pArg,
 20778  20846     sqlite3_int64 iThreshold
 20779  20847   ){
 20780         -  return sqlite3MemoryAlarm(xCallback, pArg, iThreshold);
        20848  +  return SQLITE_OK;
 20781  20849   }
 20782  20850   #endif
 20783  20851   
 20784  20852   /*
 20785  20853   ** Set the soft heap-size limit for the library. Passing a zero or 
 20786  20854   ** negative value indicates no limit.
 20787  20855   */
 20788  20856   SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_soft_heap_limit64(sqlite3_int64 n){
 20789  20857     sqlite3_int64 priorLimit;
 20790         -  sqlite3_int64 excess;
 20791  20858   #ifndef SQLITE_OMIT_AUTOINIT
 20792  20859     int rc = sqlite3_initialize();
 20793  20860     if( rc ) return -1;
 20794  20861   #endif
 20795  20862     sqlite3_mutex_enter(mem0.mutex);
 20796  20863     priorLimit = mem0.alarmThreshold;
 20797         -  sqlite3_mutex_leave(mem0.mutex);
 20798         -  if( n<0 ) return priorLimit;
 20799  20864     if( n>0 ){
 20800         -    sqlite3MemoryAlarm(softHeapLimitEnforcer, 0, n);
 20801         -  }else{
 20802         -    sqlite3MemoryAlarm(0, 0, 0);
        20865  +    mem0.alarmThreshold = n;
        20866  +    sqlite3CheckSoftHeapLimit(0);
        20867  +  }else if( n==0 ){
        20868  +    mem0.alarmThreshold = 0;
        20869  +    mem0.nearlyFull = 0;
 20803  20870     }
 20804         -  excess = sqlite3_memory_used() - n;
 20805         -  if( excess>0 ) sqlite3_release_memory((int)(excess & 0x7fffffff));
        20871  +  sqlite3_mutex_leave(mem0.mutex);
 20806  20872     return priorLimit;
 20807  20873   }
 20808  20874   SQLITE_API void SQLITE_STDCALL sqlite3_soft_heap_limit(int n){
 20809  20875     if( n<0 ) n = 0;
 20810  20876     sqlite3_soft_heap_limit64(n);
 20811  20877   }
 20812  20878   
................................................................................
 20889  20955   */
 20890  20956   SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_highwater(int resetFlag){
 20891  20957     sqlite3_int64 res, mx;
 20892  20958     sqlite3_status64(SQLITE_STATUS_MEMORY_USED, &res, &mx, resetFlag);
 20893  20959     return mx;
 20894  20960   }
 20895  20961   
 20896         -/*
 20897         -** Trigger the alarm 
 20898         -*/
 20899         -static void sqlite3MallocAlarm(int nByte){
 20900         -  void (*xCallback)(void*,sqlite3_int64,int);
 20901         -  sqlite3_int64 nowUsed;
 20902         -  void *pArg;
 20903         -  if( mem0.alarmCallback==0 ) return;
 20904         -  xCallback = mem0.alarmCallback;
 20905         -  nowUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
 20906         -  pArg = mem0.alarmArg;
 20907         -  mem0.alarmCallback = 0;
 20908         -  sqlite3_mutex_leave(mem0.mutex);
 20909         -  xCallback(pArg, nowUsed, nByte);
 20910         -  sqlite3_mutex_enter(mem0.mutex);
 20911         -  mem0.alarmCallback = xCallback;
 20912         -  mem0.alarmArg = pArg;
 20913         -}
 20914         -
 20915  20962   /*
 20916  20963   ** Do a memory allocation with statistics and alarms.  Assume the
 20917  20964   ** lock is already held.
 20918  20965   */
 20919  20966   static int mallocWithAlarm(int n, void **pp){
 20920  20967     int nFull;
 20921  20968     void *p;
 20922  20969     assert( sqlite3_mutex_held(mem0.mutex) );
 20923  20970     nFull = sqlite3GlobalConfig.m.xRoundup(n);
 20924  20971     sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n);
 20925         -  if( mem0.alarmCallback!=0 ){
 20926         -    sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
 20927         -    if( nUsed >= mem0.alarmThreshold - nFull ){
 20928         -      mem0.nearlyFull = 1;
 20929         -      sqlite3MallocAlarm(nFull);
 20930         -    }else{
 20931         -      mem0.nearlyFull = 0;
 20932         -    }
 20933         -  }
        20972  +  sqlite3CheckSoftHeapLimit(nFull);
 20934  20973     p = sqlite3GlobalConfig.m.xMalloc(nFull);
 20935  20974   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
 20936         -  if( p==0 && mem0.alarmCallback ){
 20937         -    sqlite3MallocAlarm(nFull);
        20975  +  if( p==0 && mem0.alarmThreshold ){
        20976  +    sqlite3HeapLimitExceeded(nFull);
 20938  20977       p = sqlite3GlobalConfig.m.xMalloc(nFull);
 20939  20978     }
 20940  20979   #endif
 20941  20980     if( p ){
 20942  20981       nFull = sqlite3MallocSize(p);
 20943  20982       sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nFull);
 20944  20983       sqlite3StatusUp(SQLITE_STATUS_MALLOC_COUNT, 1);
................................................................................
 21104  21143   ** sqlite3Malloc() or sqlite3_malloc().
 21105  21144   */
 21106  21145   SQLITE_PRIVATE int sqlite3MallocSize(void *p){
 21107  21146     assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
 21108  21147     return sqlite3GlobalConfig.m.xSize(p);
 21109  21148   }
 21110  21149   SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
 21111         -  if( db==0 ){
 21112         -    assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
 21113         -    assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
 21114         -    return sqlite3MallocSize(p);
 21115         -  }else{
 21116         -    assert( sqlite3_mutex_held(db->mutex) );
 21117         -    if( isLookaside(db, p) ){
 21118         -      return db->lookaside.sz;
        21150  +  if( db==0 || !isLookaside(db,p) ){
        21151  +#if SQLITE_DEBUG
        21152  +    if( db==0 ){
        21153  +      assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
        21154  +      assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
 21119  21155       }else{
 21120  21156         assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
 21121  21157         assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
 21122         -      return sqlite3GlobalConfig.m.xSize(p);
 21123  21158       }
        21159  +#endif
        21160  +    return sqlite3GlobalConfig.m.xSize(p);
        21161  +  }else{
        21162  +    assert( sqlite3_mutex_held(db->mutex) );
        21163  +    return db->lookaside.sz;
 21124  21164     }
 21125  21165   }
 21126  21166   SQLITE_API sqlite3_uint64 SQLITE_STDCALL sqlite3_msize(void *p){
 21127  21167     assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
 21128  21168     assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
 21129  21169     return (sqlite3_uint64)sqlite3GlobalConfig.m.xSize(p);
 21130  21170   }
................................................................................
 21212  21252     nNew = sqlite3GlobalConfig.m.xRoundup((int)nBytes);
 21213  21253     if( nOld==nNew ){
 21214  21254       pNew = pOld;
 21215  21255     }else if( sqlite3GlobalConfig.bMemstat ){
 21216  21256       sqlite3_mutex_enter(mem0.mutex);
 21217  21257       sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, (int)nBytes);
 21218  21258       nDiff = nNew - nOld;
 21219         -    if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= 
 21220         -          mem0.alarmThreshold-nDiff ){
 21221         -      sqlite3MallocAlarm(nDiff);
 21222         -    }
        21259  +    sqlite3CheckSoftHeapLimit(nDiff);
 21223  21260       pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
 21224         -    if( pNew==0 && mem0.alarmCallback ){
 21225         -      sqlite3MallocAlarm((int)nBytes);
        21261  +#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
        21262  +    if( pNew==0 && mem0.alarmThreshold ){
        21263  +      sqlite3HeapLimitExceeded((int)nBytes);
 21226  21264         pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
 21227  21265       }
        21266  +#endif
 21228  21267       if( pNew ){
 21229  21268         nNew = sqlite3MallocSize(pNew);
 21230  21269         sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nNew-nOld);
 21231  21270       }
 21232  21271       sqlite3_mutex_leave(mem0.mutex);
 21233  21272     }else{
 21234  21273       pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
................................................................................
 21931  21970             bufpt = "NaN";
 21932  21971             length = 3;
 21933  21972             break;
 21934  21973           }
 21935  21974           if( realvalue>0.0 ){
 21936  21975             LONGDOUBLE_TYPE scale = 1.0;
 21937  21976             while( realvalue>=1e100*scale && exp<=350 ){ scale *= 1e100;exp+=100;}
 21938         -          while( realvalue>=1e64*scale && exp<=350 ){ scale *= 1e64; exp+=64; }
 21939         -          while( realvalue>=1e8*scale && exp<=350 ){ scale *= 1e8; exp+=8; }
        21977  +          while( realvalue>=1e10*scale && exp<=350 ){ scale *= 1e10; exp+=10; }
 21940  21978             while( realvalue>=10.0*scale && exp<=350 ){ scale *= 10.0; exp++; }
 21941  21979             realvalue /= scale;
 21942  21980             while( realvalue<1e-8 ){ realvalue *= 1e8; exp-=8; }
 21943  21981             while( realvalue<1.0 ){ realvalue *= 10.0; exp--; }
 21944  21982             if( exp>350 ){
 21945         -            if( prefix=='-' ){
 21946         -              bufpt = "-Inf";
 21947         -            }else if( prefix=='+' ){
 21948         -              bufpt = "+Inf";
 21949         -            }else{
 21950         -              bufpt = "Inf";
 21951         -            }
 21952         -            length = sqlite3Strlen30(bufpt);
        21983  +            bufpt = buf;
        21984  +            buf[0] = prefix;
        21985  +            memcpy(buf+(prefix!=0),"Inf",4);
        21986  +            length = 3+(prefix!=0);
 21953  21987               break;
 21954  21988             }
 21955  21989           }
 21956  21990           bufpt = buf;
 21957  21991           /*
 21958  21992           ** If the field type is etGENERIC, then convert to either etEXP
 21959  21993           ** or etFLOAT, as appropriate.
................................................................................
 22094  22128           buf[0] = c;
 22095  22129           bufpt = buf;
 22096  22130           break;
 22097  22131         case etSTRING:
 22098  22132         case etDYNSTRING:
 22099  22133           if( bArgList ){
 22100  22134             bufpt = getTextArg(pArgList);
        22135  +          xtype = etSTRING;
 22101  22136           }else{
 22102  22137             bufpt = va_arg(ap,char*);
 22103  22138           }
 22104  22139           if( bufpt==0 ){
 22105  22140             bufpt = "";
 22106         -        }else if( xtype==etDYNSTRING && !bArgList ){
        22141  +        }else if( xtype==etDYNSTRING ){
 22107  22142             zExtra = bufpt;
 22108  22143           }
 22109  22144           if( precision>=0 ){
 22110  22145             for(length=0; length<precision && bufpt[length]; length++){}
 22111  22146           }else{
 22112  22147             length = sqlite3Strlen30(bufpt);
 22113  22148           }
 22114  22149           break;
 22115         -      case etSQLESCAPE:
 22116         -      case etSQLESCAPE2:
 22117         -      case etSQLESCAPE3: {
        22150  +      case etSQLESCAPE:           /* Escape ' characters */
        22151  +      case etSQLESCAPE2:          /* Escape ' and enclose in '...' */
        22152  +      case etSQLESCAPE3: {        /* Escape " characters */
 22118  22153           int i, j, k, n, isnull;
 22119  22154           int needQuote;
 22120  22155           char ch;
 22121  22156           char q = ((xtype==etSQLESCAPE3)?'"':'\'');   /* Quote character */
 22122  22157           char *escarg;
 22123  22158   
 22124  22159           if( bArgList ){
................................................................................
 22129  22164           isnull = escarg==0;
 22130  22165           if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
 22131  22166           k = precision;
 22132  22167           for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){
 22133  22168             if( ch==q )  n++;
 22134  22169           }
 22135  22170           needQuote = !isnull && xtype==etSQLESCAPE2;
 22136         -        n += i + 1 + needQuote*2;
        22171  +        n += i + 3;
 22137  22172           if( n>etBUFSIZE ){
 22138  22173             bufpt = zExtra = sqlite3Malloc( n );
 22139  22174             if( bufpt==0 ){
 22140  22175               setStrAccumError(pAccum, STRACCUM_NOMEM);
 22141  22176               return;
 22142  22177             }
 22143  22178           }else{
................................................................................
 22525  22560     fprintf(stdout,"%s", zBuf);
 22526  22561     fflush(stdout);
 22527  22562   }
 22528  22563   #endif
 22529  22564   
 22530  22565   
 22531  22566   /*
 22532         -** variable-argument wrapper around sqlite3VXPrintf().
        22567  +** variable-argument wrapper around sqlite3VXPrintf().  The bFlags argument
        22568  +** can contain the bit SQLITE_PRINTF_INTERNAL enable internal formats.
 22533  22569   */
 22534  22570   SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, u32 bFlags, const char *zFormat, ...){
 22535  22571     va_list ap;
 22536  22572     va_start(ap,zFormat);
 22537  22573     sqlite3VXPrintf(p, bFlags, zFormat, ap);
 22538  22574     va_end(ap);
 22539  22575   }
................................................................................
 22623  22659   
 22624  22660   
 22625  22661   /*
 22626  22662   ** Generate a human-readable description of a the Select object.
 22627  22663   */
 22628  22664   SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
 22629  22665     int n = 0;
        22666  +  int cnt = 0;
 22630  22667     pView = sqlite3TreeViewPush(pView, moreToFollow);
 22631         -  sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x",
 22632         -    ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
 22633         -    ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags
 22634         -  );
 22635         -  if( p->pSrc && p->pSrc->nSrc ) n++;
 22636         -  if( p->pWhere ) n++;
 22637         -  if( p->pGroupBy ) n++;
 22638         -  if( p->pHaving ) n++;
 22639         -  if( p->pOrderBy ) n++;
 22640         -  if( p->pLimit ) n++;
 22641         -  if( p->pOffset ) n++;
 22642         -  if( p->pPrior ) n++;
 22643         -  sqlite3TreeViewExprList(pView, p->pEList, (n--)>0, "result-set");
 22644         -  if( p->pSrc && p->pSrc->nSrc ){
 22645         -    int i;
 22646         -    pView = sqlite3TreeViewPush(pView, (n--)>0);
 22647         -    sqlite3TreeViewLine(pView, "FROM");
 22648         -    for(i=0; i<p->pSrc->nSrc; i++){
 22649         -      struct SrcList_item *pItem = &p->pSrc->a[i];
 22650         -      StrAccum x;
 22651         -      char zLine[100];
 22652         -      sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
 22653         -      sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor);
 22654         -      if( pItem->zDatabase ){
 22655         -        sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName);
 22656         -      }else if( pItem->zName ){
 22657         -        sqlite3XPrintf(&x, 0, " %s", pItem->zName);
 22658         -      }
 22659         -      if( pItem->pTab ){
 22660         -        sqlite3XPrintf(&x, 0, " tabname=%Q", pItem->pTab->zName);
 22661         -      }
 22662         -      if( pItem->zAlias ){
 22663         -        sqlite3XPrintf(&x, 0, " (AS %s)", pItem->zAlias);
 22664         -      }
 22665         -      if( pItem->jointype & JT_LEFT ){
 22666         -        sqlite3XPrintf(&x, 0, " LEFT-JOIN");
 22667         -      }
 22668         -      sqlite3StrAccumFinish(&x);
 22669         -      sqlite3TreeViewItem(pView, zLine, i<p->pSrc->nSrc-1); 
 22670         -      if( pItem->pSelect ){
 22671         -        sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
 22672         -      }
        22668  +  do{
        22669  +    sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x",
        22670  +      ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
        22671  +      ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags
        22672  +    );
        22673  +    if( cnt++ ) sqlite3TreeViewPop(pView);
        22674  +    if( p->pPrior ){
        22675  +      n = 1000;
        22676  +    }else{
        22677  +      n = 0;
        22678  +      if( p->pSrc && p->pSrc->nSrc ) n++;
        22679  +      if( p->pWhere ) n++;
        22680  +      if( p->pGroupBy ) n++;
        22681  +      if( p->pHaving ) n++;
        22682  +      if( p->pOrderBy ) n++;
        22683  +      if( p->pLimit ) n++;
        22684  +      if( p->pOffset ) n++;
        22685  +    }
        22686  +    sqlite3TreeViewExprList(pView, p->pEList, (n--)>0, "result-set");
        22687  +    if( p->pSrc && p->pSrc->nSrc ){
        22688  +      int i;
        22689  +      pView = sqlite3TreeViewPush(pView, (n--)>0);
        22690  +      sqlite3TreeViewLine(pView, "FROM");
        22691  +      for(i=0; i<p->pSrc->nSrc; i++){
        22692  +        struct SrcList_item *pItem = &p->pSrc->a[i];
        22693  +        StrAccum x;
        22694  +        char zLine[100];
        22695  +        sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
        22696  +        sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor);
        22697  +        if( pItem->zDatabase ){
        22698  +          sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName);
        22699  +        }else if( pItem->zName ){
        22700  +          sqlite3XPrintf(&x, 0, " %s", pItem->zName);
        22701  +        }
        22702  +        if( pItem->pTab ){
        22703  +          sqlite3XPrintf(&x, 0, " tabname=%Q", pItem->pTab->zName);
        22704  +        }
        22705  +        if( pItem->zAlias ){
        22706  +          sqlite3XPrintf(&x, 0, " (AS %s)", pItem->zAlias);
        22707  +        }
        22708  +        if( pItem->fg.jointype & JT_LEFT ){
        22709  +          sqlite3XPrintf(&x, 0, " LEFT-JOIN");
        22710  +        }
        22711  +        sqlite3StrAccumFinish(&x);
        22712  +        sqlite3TreeViewItem(pView, zLine, i<p->pSrc->nSrc-1); 
        22713  +        if( pItem->pSelect ){
        22714  +          sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
        22715  +        }
        22716  +        if( pItem->fg.isTabFunc ){
        22717  +          sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
        22718  +        }
        22719  +        sqlite3TreeViewPop(pView);
        22720  +      }
        22721  +      sqlite3TreeViewPop(pView);
        22722  +    }
        22723  +    if( p->pWhere ){
        22724  +      sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
        22725  +      sqlite3TreeViewExpr(pView, p->pWhere, 0);
        22726  +      sqlite3TreeViewPop(pView);
        22727  +    }
        22728  +    if( p->pGroupBy ){
        22729  +      sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY");
        22730  +    }
        22731  +    if( p->pHaving ){
        22732  +      sqlite3TreeViewItem(pView, "HAVING", (n--)>0);
        22733  +      sqlite3TreeViewExpr(pView, p->pHaving, 0);
        22734  +      sqlite3TreeViewPop(pView);
        22735  +    }
        22736  +    if( p->pOrderBy ){
        22737  +      sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY");
        22738  +    }
        22739  +    if( p->pLimit ){
        22740  +      sqlite3TreeViewItem(pView, "LIMIT", (n--)>0);
        22741  +      sqlite3TreeViewExpr(pView, p->pLimit, 0);
        22742  +      sqlite3TreeViewPop(pView);
        22743  +    }
        22744  +    if( p->pOffset ){
        22745  +      sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
        22746  +      sqlite3TreeViewExpr(pView, p->pOffset, 0);
 22673  22747         sqlite3TreeViewPop(pView);
 22674  22748       }
 22675         -    sqlite3TreeViewPop(pView);
 22676         -  }
 22677         -  if( p->pWhere ){
 22678         -    sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
 22679         -    sqlite3TreeViewExpr(pView, p->pWhere, 0);
 22680         -    sqlite3TreeViewPop(pView);
 22681         -  }
 22682         -  if( p->pGroupBy ){
 22683         -    sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY");
 22684         -  }
 22685         -  if( p->pHaving ){
 22686         -    sqlite3TreeViewItem(pView, "HAVING", (n--)>0);
 22687         -    sqlite3TreeViewExpr(pView, p->pHaving, 0);
 22688         -    sqlite3TreeViewPop(pView);
 22689         -  }
 22690         -  if( p->pOrderBy ){
 22691         -    sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY");
 22692         -  }
 22693         -  if( p->pLimit ){
 22694         -    sqlite3TreeViewItem(pView, "LIMIT", (n--)>0);
 22695         -    sqlite3TreeViewExpr(pView, p->pLimit, 0);
 22696         -    sqlite3TreeViewPop(pView);
 22697         -  }
 22698         -  if( p->pOffset ){
 22699         -    sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
 22700         -    sqlite3TreeViewExpr(pView, p->pOffset, 0);
 22701         -    sqlite3TreeViewPop(pView);
 22702         -  }
 22703         -  if( p->pPrior ){
 22704         -    const char *zOp = "UNION";
 22705         -    switch( p->op ){
 22706         -      case TK_ALL:         zOp = "UNION ALL";  break;
 22707         -      case TK_INTERSECT:   zOp = "INTERSECT";  break;
 22708         -      case TK_EXCEPT:      zOp = "EXCEPT";     break;
 22709         -    }
 22710         -    sqlite3TreeViewItem(pView, zOp, (n--)>0);
 22711         -    sqlite3TreeViewSelect(pView, p->pPrior, 0);
 22712         -    sqlite3TreeViewPop(pView);
 22713         -  }
        22749  +    if( p->pPrior ){
        22750  +      const char *zOp = "UNION";
        22751  +      switch( p->op ){
        22752  +        case TK_ALL:         zOp = "UNION ALL";  break;
        22753  +        case TK_INTERSECT:   zOp = "INTERSECT";  break;
        22754  +        case TK_EXCEPT:      zOp = "EXCEPT";     break;
        22755  +      }
        22756  +      sqlite3TreeViewItem(pView, zOp, 1);
        22757  +    }
        22758  +    p = p->pPrior;
        22759  +  }while( p!=0 );
 22714  22760     sqlite3TreeViewPop(pView);
 22715  22761   }
 22716  22762   
 22717  22763   /*
 22718  22764   ** Generate a human-readable explanation of an expression tree.
 22719  22765   */
 22720  22766   SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
................................................................................
 22781  22827                             pExpr->u.zToken, pExpr->iColumn);
 22782  22828         break;
 22783  22829       }
 22784  22830       case TK_REGISTER: {
 22785  22831         sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable);
 22786  22832         break;
 22787  22833       }
 22788         -    case TK_AS: {
 22789         -      sqlite3TreeViewLine(pView,"AS %Q", pExpr->u.zToken);
 22790         -      sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
 22791         -      break;
 22792         -    }
 22793  22834       case TK_ID: {
 22794  22835         sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
 22795  22836         break;
 22796  22837       }
 22797  22838   #ifndef SQLITE_OMIT_CAST
 22798  22839       case TK_CAST: {
 22799  22840         /* Expressions of the form:   CAST(pLeft AS token) */
................................................................................
 22960  23001     pView = sqlite3TreeViewPush(pView, moreToFollow);
 22961  23002     if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST";
 22962  23003     if( pList==0 ){
 22963  23004       sqlite3TreeViewLine(pView, "%s (empty)", zLabel);
 22964  23005     }else{
 22965  23006       sqlite3TreeViewLine(pView, "%s", zLabel);
 22966  23007       for(i=0; i<pList->nExpr; i++){
        23008  +      int j = pList->a[i].u.x.iOrderByCol;
        23009  +      if( j ){
        23010  +        sqlite3TreeViewPush(pView, 0);
        23011  +        sqlite3TreeViewLine(pView, "iOrderByCol=%d", j);
        23012  +      }
 22967  23013         sqlite3TreeViewExpr(pView, pList->a[i].pExpr, i<pList->nExpr-1);
        23014  +      if( j ) sqlite3TreeViewPop(pView);
 22968  23015       }
 22969  23016     }
 22970  23017     sqlite3TreeViewPop(pView);
 22971  23018   }
 22972  23019   
 22973  23020   #endif /* SQLITE_DEBUG */
 22974  23021   
................................................................................
 24975  25022   }
 24976  25023   
 24977  25024   /*
 24978  25025   ** Return the number of bytes that will be needed to store the given
 24979  25026   ** 64-bit integer.
 24980  25027   */
 24981  25028   SQLITE_PRIVATE int sqlite3VarintLen(u64 v){
 24982         -  int i = 0;
 24983         -  do{
 24984         -    i++;
 24985         -    v >>= 7;
 24986         -  }while( v!=0 && ALWAYS(i<9) );
        25029  +  int i;
        25030  +  for(i=1; (v >>= 7)!=0; i++){ assert( i<9 ); }
 24987  25031     return i;
 24988  25032   }
 24989  25033   
 24990  25034   
 24991  25035   /*
 24992  25036   ** Read or write a four-byte big-endian integer value.
 24993  25037   */
 24994  25038   SQLITE_PRIVATE u32 sqlite3Get4byte(const u8 *p){
 24995  25039   #if SQLITE_BYTEORDER==4321
 24996  25040     u32 x;
 24997  25041     memcpy(&x,p,4);
 24998  25042     return x;
 24999         -#elif SQLITE_BYTEORDER==1234 && defined(__GNUC__) && GCC_VERSION>=4003000
        25043  +#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
        25044  +    && defined(__GNUC__) && GCC_VERSION>=4003000
 25000  25045     u32 x;
 25001  25046     memcpy(&x,p,4);
 25002  25047     return __builtin_bswap32(x);
 25003         -#elif SQLITE_BYTEORDER==1234 && defined(_MSC_VER) && _MSC_VER>=1300
        25048  +#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
        25049  +    && defined(_MSC_VER) && _MSC_VER>=1300
 25004  25050     u32 x;
 25005  25051     memcpy(&x,p,4);
 25006  25052     return _byteswap_ulong(x);
 25007  25053   #else
 25008  25054     testcase( p[0]&0x80 );
 25009  25055     return ((unsigned)p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
 25010  25056   #endif
................................................................................
 29101  29147     int prior = 0;
 29102  29148   #if (!defined(USE_PREAD) && !defined(USE_PREAD64))
 29103  29149     i64 newOffset;
 29104  29150   #endif
 29105  29151     TIMER_START;
 29106  29152     assert( cnt==(cnt&0x1ffff) );
 29107  29153     assert( id->h>2 );
 29108         -  cnt &= 0x1ffff;
 29109  29154     do{
 29110  29155   #if defined(USE_PREAD)
 29111  29156       got = osPread(id->h, pBuf, cnt, offset);
 29112  29157       SimulateIOError( got = -1 );
 29113  29158   #elif defined(USE_PREAD64)
 29114  29159       got = osPread64(id->h, pBuf, cnt, offset);
 29115  29160       SimulateIOError( got = -1 );
................................................................................
 29318  29363         memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, nCopy);
 29319  29364         pBuf = &((u8 *)pBuf)[nCopy];
 29320  29365         amt -= nCopy;
 29321  29366         offset += nCopy;
 29322  29367       }
 29323  29368     }
 29324  29369   #endif
 29325         -
 29326         -  while( amt>0 && (wrote = seekAndWrite(pFile, offset, pBuf, amt))>0 ){
        29370  + 
        29371  +  while( (wrote = seekAndWrite(pFile, offset, pBuf, amt))<amt && wrote>0 ){
 29327  29372       amt -= wrote;
 29328  29373       offset += wrote;
 29329  29374       pBuf = &((char*)pBuf)[wrote];
 29330  29375     }
 29331  29376     SimulateIOError(( wrote=(-1), amt=1 ));
 29332  29377     SimulateDiskfullError(( wrote=0, amt=1 ));
 29333  29378   
 29334         -  if( amt>0 ){
        29379  +  if( amt>wrote ){
 29335  29380       if( wrote<0 && pFile->lastErrno!=ENOSPC ){
 29336  29381         /* lastErrno set by seekAndWrite */
 29337  29382         return SQLITE_IOERR_WRITE;
 29338  29383       }else{
 29339  29384         storeLastErrno(pFile, 0); /* not a system error */
 29340  29385         return SQLITE_FULL;
 29341  29386       }
................................................................................
 39796  39841   
 39797  39842   /*
 39798  39843   ** A complete page cache is an instance of this structure.
 39799  39844   */
 39800  39845   struct PCache {
 39801  39846     PgHdr *pDirty, *pDirtyTail;         /* List of dirty pages in LRU order */
 39802  39847     PgHdr *pSynced;                     /* Last synced page in dirty page list */
 39803         -  int nRef;                           /* Number of referenced pages */
        39848  +  int nRefSum;                        /* Sum of ref counts over all pages */
 39804  39849     int szCache;                        /* Configured cache size */
 39805  39850     int szPage;                         /* Size of every page in this cache */
 39806  39851     int szExtra;                        /* Size of extra space for each page */
 39807  39852     u8 bPurgeable;                      /* True if pages are on backing store */
 39808  39853     u8 eCreate;                         /* eCreate value for for xFetch() */
 39809  39854     int (*xStress)(void*,PgHdr*);       /* Call to try make a page clean */
 39810  39855     void *pStress;                      /* Argument to xStress */
................................................................................
 39961  40006   }
 39962  40007   
 39963  40008   /*
 39964  40009   ** Change the page size for PCache object. The caller must ensure that there
 39965  40010   ** are no outstanding page references when this function is called.
 39966  40011   */
 39967  40012   SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
 39968         -  assert( pCache->nRef==0 && pCache->pDirty==0 );
        40013  +  assert( pCache->nRefSum==0 && pCache->pDirty==0 );
 39969  40014     if( pCache->szPage ){
 39970  40015       sqlite3_pcache *pNew;
 39971  40016       pNew = sqlite3GlobalConfig.pcache2.xCreate(
 39972  40017                   szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
 39973  40018                   pCache->bPurgeable
 39974  40019       );
 39975  40020       if( pNew==0 ) return SQLITE_NOMEM;
................................................................................
 40128  40173   
 40129  40174     assert( pPage!=0 );
 40130  40175     pPgHdr = (PgHdr *)pPage->pExtra;
 40131  40176   
 40132  40177     if( !pPgHdr->pPage ){
 40133  40178       return pcacheFetchFinishWithInit(pCache, pgno, pPage);
 40134  40179     }
 40135         -  if( 0==pPgHdr->nRef ){
 40136         -    pCache->nRef++;
 40137         -  }
        40180  +  pCache->nRefSum++;
 40138  40181     pPgHdr->nRef++;
 40139  40182     return pPgHdr;
 40140  40183   }
 40141  40184   
 40142  40185   /*
 40143  40186   ** Decrement the reference count on a page. If the page is clean and the
 40144  40187   ** reference count drops to 0, then it is made eligible for recycling.
 40145  40188   */
 40146  40189   SQLITE_PRIVATE void SQLITE_NOINLINE sqlite3PcacheRelease(PgHdr *p){
 40147  40190     assert( p->nRef>0 );
 40148         -  p->nRef--;
 40149         -  if( p->nRef==0 ){
 40150         -    p->pCache->nRef--;
        40191  +  p->pCache->nRefSum--;
        40192  +  if( (--p->nRef)==0 ){
 40151  40193       if( p->flags&PGHDR_CLEAN ){
 40152  40194         pcacheUnpin(p);
 40153  40195       }else if( p->pDirtyPrev!=0 ){
 40154  40196         /* Move the page to the head of the dirty list. */
 40155  40197         pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
 40156  40198       }
 40157  40199     }
................................................................................
 40159  40201   
 40160  40202   /*
 40161  40203   ** Increase the reference count of a supplied page by 1.
 40162  40204   */
 40163  40205   SQLITE_PRIVATE void sqlite3PcacheRef(PgHdr *p){
 40164  40206     assert(p->nRef>0);
 40165  40207     p->nRef++;
        40208  +  p->pCache->nRefSum++;
 40166  40209   }
 40167  40210   
 40168  40211   /*
 40169  40212   ** Drop a page from the cache. There must be exactly one reference to the
 40170  40213   ** page. This function deletes that reference, so after it returns the
 40171  40214   ** page pointed to by p is invalid.
 40172  40215   */
 40173  40216   SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr *p){
 40174  40217     assert( p->nRef==1 );
 40175  40218     if( p->flags&PGHDR_DIRTY ){
 40176  40219       pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
 40177  40220     }
 40178         -  p->pCache->nRef--;
        40221  +  p->pCache->nRefSum--;
 40179  40222     sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
 40180  40223   }
 40181  40224   
 40182  40225   /*
 40183  40226   ** Make sure the page is marked as dirty. If it isn't dirty already,
 40184  40227   ** make it so.
 40185  40228   */
................................................................................
 40267  40310         */
 40268  40311         assert( p->pgno>0 );
 40269  40312         if( ALWAYS(p->pgno>pgno) ){
 40270  40313           assert( p->flags&PGHDR_DIRTY );
 40271  40314           sqlite3PcacheMakeClean(p);
 40272  40315         }
 40273  40316       }
 40274         -    if( pgno==0 && pCache->nRef ){
        40317  +    if( pgno==0 && pCache->nRefSum ){
 40275  40318         sqlite3_pcache_page *pPage1;
 40276  40319         pPage1 = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache,1,0);
 40277  40320         if( ALWAYS(pPage1) ){  /* Page 1 is always available in cache, because
 40278         -                             ** pCache->nRef>0 */
        40321  +                             ** pCache->nRefSum>0 */
 40279  40322           memset(pPage1->pBuf, 0, pCache->szPage);
 40280  40323           pgno = 1;
 40281  40324         }
 40282  40325       }
 40283  40326       sqlite3GlobalConfig.pcache2.xTruncate(pCache->pCache, pgno+1);
 40284  40327     }
 40285  40328   }
................................................................................
 40377  40420     for(p=pCache->pDirty; p; p=p->pDirtyNext){
 40378  40421       p->pDirty = p->pDirtyNext;
 40379  40422     }
 40380  40423     return pcacheSortDirtyList(pCache->pDirty);
 40381  40424   }
 40382  40425   
 40383  40426   /* 
 40384         -** Return the total number of referenced pages held by the cache.
        40427  +** Return the total number of references to all pages held by the cache.
        40428  +**
        40429  +** This is not the total number of pages referenced, but the sum of the
        40430  +** reference count for all pages.
 40385  40431   */
 40386  40432   SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
 40387         -  return pCache->nRef;
        40433  +  return pCache->nRefSum;
 40388  40434   }
 40389  40435   
 40390  40436   /*
 40391  40437   ** Return the number of references to the page supplied as an argument.
 40392  40438   */
 40393  40439   SQLITE_PRIVATE int sqlite3PcachePageRefcount(PgHdr *p){
 40394  40440     return p->nRef;
................................................................................
 40515  40561   **         SQLITE_CONFIG_PAGECACHE.
 40516  40562   **    (3)  PCache-local bulk allocation.
 40517  40563   **
 40518  40564   ** The third case is a chunk of heap memory (defaulting to 100 pages worth)
 40519  40565   ** that is allocated when the page cache is created.  The size of the local
 40520  40566   ** bulk allocation can be adjusted using 
 40521  40567   **
 40522         -**     sqlite3_config(SQLITE_CONFIG_PCACHE, 0, 0, N).
        40568  +**     sqlite3_config(SQLITE_CONFIG_PAGECACHE, 0, 0, N).
 40523  40569   **
 40524  40570   ** If N is positive, then N pages worth of memory are allocated using a single
 40525  40571   ** sqlite3Malloc() call and that memory is used for the first N pages allocated.
 40526  40572   ** Or if N is negative, then -1024*N bytes of memory are allocated and used
 40527  40573   ** for as many pages as can be accomodated.
 40528  40574   **
 40529  40575   ** Only one of (2) or (3) can be used.  Once the memory available to (2) or
................................................................................
 40536  40582   */
 40537  40583   /* #include "sqliteInt.h" */
 40538  40584   
 40539  40585   typedef struct PCache1 PCache1;
 40540  40586   typedef struct PgHdr1 PgHdr1;
 40541  40587   typedef struct PgFreeslot PgFreeslot;
 40542  40588   typedef struct PGroup PGroup;
        40589  +
        40590  +/*
        40591  +** Each cache entry is represented by an instance of the following 
        40592  +** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
        40593  +** PgHdr1.pCache->szPage bytes is allocated directly before this structure 
        40594  +** in memory.
        40595  +*/
        40596  +struct PgHdr1 {
        40597  +  sqlite3_pcache_page page;      /* Base class. Must be first. pBuf & pExtra */
        40598  +  unsigned int iKey;             /* Key value (page number) */
        40599  +  u8 isPinned;                   /* Page in use, not on the LRU list */
        40600  +  u8 isBulkLocal;                /* This page from bulk local storage */
        40601  +  u8 isAnchor;                   /* This is the PGroup.lru element */
        40602  +  PgHdr1 *pNext;                 /* Next in hash table chain */
        40603  +  PCache1 *pCache;               /* Cache that currently owns this page */
        40604  +  PgHdr1 *pLruNext;              /* Next in LRU list of unpinned pages */
        40605  +  PgHdr1 *pLruPrev;              /* Previous in LRU list of unpinned pages */
        40606  +};
 40543  40607   
 40544  40608   /* Each page cache (or PCache) belongs to a PGroup.  A PGroup is a set 
 40545  40609   ** of one or more PCaches that are able to recycle each other's unpinned
 40546  40610   ** pages when they are under memory pressure.  A PGroup is an instance of
 40547  40611   ** the following object.
 40548  40612   **
 40549  40613   ** This page cache implementation works in one of two modes:
................................................................................
 40565  40629   */
 40566  40630   struct PGroup {
 40567  40631     sqlite3_mutex *mutex;          /* MUTEX_STATIC_LRU or NULL */
 40568  40632     unsigned int nMaxPage;         /* Sum of nMax for purgeable caches */
 40569  40633     unsigned int nMinPage;         /* Sum of nMin for purgeable caches */
 40570  40634     unsigned int mxPinned;         /* nMaxpage + 10 - nMinPage */
 40571  40635     unsigned int nCurrentPage;     /* Number of purgeable pages allocated */
 40572         -  PgHdr1 *pLruHead, *pLruTail;   /* LRU list of unpinned pages */
        40636  +  PgHdr1 lru;                    /* The beginning and end of the LRU list */
 40573  40637   };
 40574  40638   
 40575  40639   /* Each page cache is an instance of the following object.  Every
 40576  40640   ** open database file (including each in-memory database and each
 40577  40641   ** temporary or transient database) has a single page cache which
 40578  40642   ** is an instance of this object.
 40579  40643   **
................................................................................
 40603  40667     unsigned int nPage;                 /* Total number of pages in apHash */
 40604  40668     unsigned int nHash;                 /* Number of slots in apHash[] */
 40605  40669     PgHdr1 **apHash;                    /* Hash table for fast lookup by key */
 40606  40670     PgHdr1 *pFree;                      /* List of unused pcache-local pages */
 40607  40671     void *pBulk;                        /* Bulk memory used by pcache-local */
 40608  40672   };
 40609  40673   
 40610         -/*
 40611         -** Each cache entry is represented by an instance of the following 
 40612         -** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
 40613         -** PgHdr1.pCache->szPage bytes is allocated directly before this structure 
 40614         -** in memory.
 40615         -*/
 40616         -struct PgHdr1 {
 40617         -  sqlite3_pcache_page page;
 40618         -  unsigned int iKey;             /* Key value (page number) */
 40619         -  u8 isPinned;                   /* Page in use, not on the LRU list */
 40620         -  u8 isBulkLocal;                /* This page from bulk local storage */
 40621         -  PgHdr1 *pNext;                 /* Next in hash table chain */
 40622         -  PCache1 *pCache;               /* Cache that currently owns this page */
 40623         -  PgHdr1 *pLruNext;              /* Next in LRU list of unpinned pages */
 40624         -  PgHdr1 *pLruPrev;              /* Previous in LRU list of unpinned pages */
 40625         -};
 40626         -
 40627  40674   /*
 40628  40675   ** Free slots in the allocator used to divide up the global page cache
 40629  40676   ** buffer provided using the SQLITE_CONFIG_PAGECACHE mechanism.
 40630  40677   */
 40631  40678   struct PgFreeslot {
 40632  40679     PgFreeslot *pNext;  /* Next free slot */
 40633  40680   };
................................................................................
 40679  40726   # define pcache1EnterMutex(X) sqlite3_mutex_enter((X)->mutex)
 40680  40727   # define pcache1LeaveMutex(X) sqlite3_mutex_leave((X)->mutex)
 40681  40728   # define PCACHE1_MIGHT_USE_GROUP_MUTEX 1
 40682  40729   #endif
 40683  40730   
 40684  40731   /******************************************************************************/
 40685  40732   /******** Page Allocation/SQLITE_CONFIG_PCACHE Related Functions **************/
        40733  +
 40686  40734   
 40687  40735   /*
 40688  40736   ** This function is called during initialization if a static buffer is 
 40689  40737   ** supplied to use for the page-cache by passing the SQLITE_CONFIG_PAGECACHE
 40690  40738   ** verb to sqlite3_config(). Parameter pBuf points to an allocation large
 40691  40739   ** enough to contain 'n' buffers of 'sz' bytes each.
 40692  40740   **
................................................................................
 40739  40787       int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
 40740  40788       int i;
 40741  40789       for(i=0; i<nBulk; i++){
 40742  40790         PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
 40743  40791         pX->page.pBuf = zBulk;
 40744  40792         pX->page.pExtra = &pX[1];
 40745  40793         pX->isBulkLocal = 1;
        40794  +      pX->isAnchor = 0;
 40746  40795         pX->pNext = pCache->pFree;
 40747  40796         pCache->pFree = pX;
 40748  40797         zBulk += pCache->szAlloc;
 40749  40798       }
 40750  40799     }
 40751  40800     return pCache->pFree!=0;
 40752  40801   }
................................................................................
 40842  40891     }
 40843  40892   }
 40844  40893   #endif /* SQLITE_ENABLE_MEMORY_MANAGEMENT */
 40845  40894   
 40846  40895   /*
 40847  40896   ** Allocate a new page object initially associated with cache pCache.
 40848  40897   */
 40849         -static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
        40898  +static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){
 40850  40899     PgHdr1 *p = 0;
 40851  40900     void *pPg;
 40852  40901   
 40853  40902     assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
 40854  40903     if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){
 40855  40904       p = pCache->pFree;
 40856  40905       pCache->pFree = p->pNext;
................................................................................
 40860  40909       /* The group mutex must be released before pcache1Alloc() is called. This
 40861  40910       ** is because it might call sqlite3_release_memory(), which assumes that 
 40862  40911       ** this mutex is not held. */
 40863  40912       assert( pcache1.separateCache==0 );
 40864  40913       assert( pCache->pGroup==&pcache1.grp );
 40865  40914       pcache1LeaveMutex(pCache->pGroup);
 40866  40915   #endif
        40916  +    if( benignMalloc ) sqlite3BeginBenignMalloc();
 40867  40917   #ifdef SQLITE_PCACHE_SEPARATE_HEADER
 40868  40918       pPg = pcache1Alloc(pCache->szPage);
 40869  40919       p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
 40870  40920       if( !pPg || !p ){
 40871  40921         pcache1Free(pPg);
 40872  40922         sqlite3_free(p);
 40873  40923         pPg = 0;
 40874  40924       }
 40875  40925   #else
 40876  40926       pPg = pcache1Alloc(pCache->szAlloc);
 40877  40927       p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
 40878  40928   #endif
        40929  +    if( benignMalloc ) sqlite3EndBenignMalloc();
 40879  40930   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
 40880  40931       pcache1EnterMutex(pCache->pGroup);
 40881  40932   #endif
 40882  40933       if( pPg==0 ) return 0;
 40883  40934       p->page.pBuf = pPg;
 40884  40935       p->page.pExtra = &p[1];
 40885  40936       p->isBulkLocal = 0;
        40937  +    p->isAnchor = 0;
 40886  40938     }
 40887  40939     if( pCache->bPurgeable ){
 40888  40940       pCache->pGroup->nCurrentPage++;
 40889  40941     }
 40890  40942     return p;
 40891  40943   }
 40892  40944   
................................................................................
 41005  41057   */
 41006  41058   static PgHdr1 *pcache1PinPage(PgHdr1 *pPage){
 41007  41059     PCache1 *pCache;
 41008  41060   
 41009  41061     assert( pPage!=0 );
 41010  41062     assert( pPage->isPinned==0 );
 41011  41063     pCache = pPage->pCache;
 41012         -  assert( pPage->pLruNext || pPage==pCache->pGroup->pLruTail );
 41013         -  assert( pPage->pLruPrev || pPage==pCache->pGroup->pLruHead );
        41064  +  assert( pPage->pLruNext );
        41065  +  assert( pPage->pLruPrev );
 41014  41066     assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
 41015         -  if( pPage->pLruPrev ){
 41016         -    pPage->pLruPrev->pLruNext = pPage->pLruNext;
 41017         -  }else{
 41018         -    pCache->pGroup->pLruHead = pPage->pLruNext;
 41019         -  }
 41020         -  if( pPage->pLruNext ){
 41021         -    pPage->pLruNext->pLruPrev = pPage->pLruPrev;
 41022         -  }else{
 41023         -    pCache->pGroup->pLruTail = pPage->pLruPrev;
 41024         -  }
        41067  +  pPage->pLruPrev->pLruNext = pPage->pLruNext;
        41068  +  pPage->pLruNext->pLruPrev = pPage->pLruPrev;
 41025  41069     pPage->pLruNext = 0;
 41026  41070     pPage->pLruPrev = 0;
 41027  41071     pPage->isPinned = 1;
        41072  +  assert( pPage->isAnchor==0 );
        41073  +  assert( pCache->pGroup->lru.isAnchor==1 );
 41028  41074     pCache->nRecyclable--;
 41029  41075     return pPage;
 41030  41076   }
 41031  41077   
 41032  41078   
 41033  41079   /*
 41034  41080   ** Remove the page supplied as an argument from the hash table 
................................................................................
 41053  41099   
 41054  41100   /*
 41055  41101   ** If there are currently more than nMaxPage pages allocated, try
 41056  41102   ** to recycle pages to reduce the number allocated to nMaxPage.
 41057  41103   */
 41058  41104   static void pcache1EnforceMaxPage(PCache1 *pCache){
 41059  41105     PGroup *pGroup = pCache->pGroup;
        41106  +  PgHdr1 *p;
 41060  41107     assert( sqlite3_mutex_held(pGroup->mutex) );
 41061         -  while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){
 41062         -    PgHdr1 *p = pGroup->pLruTail;
        41108  +  while( pGroup->nCurrentPage>pGroup->nMaxPage
        41109  +      && (p=pGroup->lru.pLruPrev)->isAnchor==0
        41110  +  ){
 41063  41111       assert( p->pCache->pGroup==pGroup );
 41064  41112       assert( p->isPinned==0 );
 41065  41113       pcache1PinPage(p);
 41066  41114       pcache1RemoveFromHash(p, 1);
 41067  41115     }
 41068  41116     if( pCache->nPage==0 && pCache->pBulk ){
 41069  41117       sqlite3_free(pCache->pBulk);
................................................................................
 41189  41237     if( pCache ){
 41190  41238       if( pcache1.separateCache ){
 41191  41239         pGroup = (PGroup*)&pCache[1];
 41192  41240         pGroup->mxPinned = 10;
 41193  41241       }else{
 41194  41242         pGroup = &pcache1.grp;
 41195  41243       }
        41244  +    if( pGroup->lru.isAnchor==0 ){
        41245  +      pGroup->lru.isAnchor = 1;
        41246  +      pGroup->lru.pLruPrev = pGroup->lru.pLruNext = &pGroup->lru;
        41247  +    }
 41196  41248       pCache->pGroup = pGroup;
 41197  41249       pCache->szPage = szPage;
 41198  41250       pCache->szExtra = szExtra;
 41199  41251       pCache->szAlloc = szPage + szExtra + ROUND8(sizeof(PgHdr1));
 41200  41252       pCache->bPurgeable = (bPurgeable ? 1 : 0);
 41201  41253       pcache1EnterMutex(pGroup);
 41202  41254       pcache1ResizeHash(pCache);
................................................................................
 41296  41348     }
 41297  41349   
 41298  41350     if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
 41299  41351     assert( pCache->nHash>0 && pCache->apHash );
 41300  41352   
 41301  41353     /* Step 4. Try to recycle a page. */
 41302  41354     if( pCache->bPurgeable
 41303         -   && pGroup->pLruTail
        41355  +   && !pGroup->lru.pLruPrev->isAnchor
 41304  41356      && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
 41305  41357     ){
 41306  41358       PCache1 *pOther;
 41307         -    pPage = pGroup->pLruTail;
        41359  +    pPage = pGroup->lru.pLruPrev;
 41308  41360       assert( pPage->isPinned==0 );
 41309  41361       pcache1RemoveFromHash(pPage, 0);
 41310  41362       pcache1PinPage(pPage);
 41311  41363       pOther = pPage->pCache;
 41312  41364       if( pOther->szAlloc != pCache->szAlloc ){
 41313  41365         pcache1FreePage(pPage);
 41314  41366         pPage = 0;
................................................................................
 41317  41369       }
 41318  41370     }
 41319  41371   
 41320  41372     /* Step 5. If a usable page buffer has still not been found, 
 41321  41373     ** attempt to allocate a new one. 
 41322  41374     */
 41323  41375     if( !pPage ){
 41324         -    if( createFlag==1 ){ sqlite3BeginBenignMalloc(); }
 41325         -    pPage = pcache1AllocPage(pCache);
 41326         -    if( createFlag==1 ){ sqlite3EndBenignMalloc(); }
        41376  +    pPage = pcache1AllocPage(pCache, createFlag==1);
 41327  41377     }
 41328  41378   
 41329  41379     if( pPage ){
 41330  41380       unsigned int h = iKey % pCache->nHash;
 41331  41381       pCache->nPage++;
 41332  41382       pPage->iKey = iKey;
 41333  41383       pPage->pNext = pCache->apHash[h];
................................................................................
 41411  41461     PCache1 *pCache = (PCache1 *)p;
 41412  41462     PgHdr1 *pPage = 0;
 41413  41463   
 41414  41464     /* Step 1: Search the hash table for an existing entry. */
 41415  41465     pPage = pCache->apHash[iKey % pCache->nHash];
 41416  41466     while( pPage && pPage->iKey!=iKey ){ pPage = pPage->pNext; }
 41417  41467   
 41418         -  /* Step 2: Abort if no existing page is found and createFlag is 0 */
        41468  +  /* Step 2: If the page was found in the hash table, then return it.
        41469  +  ** If the page was not in the hash table and createFlag is 0, abort.
        41470  +  ** Otherwise (page not in hash and createFlag!=0) continue with
        41471  +  ** subsequent steps to try to create the page. */
 41419  41472     if( pPage ){
 41420  41473       if( !pPage->isPinned ){
 41421  41474         return pcache1PinPage(pPage);
 41422  41475       }else{
 41423  41476         return pPage;
 41424  41477       }
 41425  41478     }else if( createFlag ){
................................................................................
 41488  41541     assert( pPage->pCache==pCache );
 41489  41542     pcache1EnterMutex(pGroup);
 41490  41543   
 41491  41544     /* It is an error to call this function if the page is already 
 41492  41545     ** part of the PGroup LRU list.
 41493  41546     */
 41494  41547     assert( pPage->pLruPrev==0 && pPage->pLruNext==0 );
 41495         -  assert( pGroup->pLruHead!=pPage && pGroup->pLruTail!=pPage );
 41496  41548     assert( pPage->isPinned==1 );
 41497  41549   
 41498  41550     if( reuseUnlikely || pGroup->nCurrentPage>pGroup->nMaxPage ){
 41499  41551       pcache1RemoveFromHash(pPage, 1);
 41500  41552     }else{
 41501  41553       /* Add the page to the PGroup LRU list. */
 41502         -    if( pGroup->pLruHead ){
 41503         -      pGroup->pLruHead->pLruPrev = pPage;
 41504         -      pPage->pLruNext = pGroup->pLruHead;
 41505         -      pGroup->pLruHead = pPage;
 41506         -    }else{
 41507         -      pGroup->pLruTail = pPage;
 41508         -      pGroup->pLruHead = pPage;
 41509         -    }
        41554  +    PgHdr1 **ppFirst = &pGroup->lru.pLruNext;
        41555  +    pPage->pLruPrev = &pGroup->lru;
        41556  +    (pPage->pLruNext = *ppFirst)->pLruPrev = pPage;
        41557  +    *ppFirst = pPage;
 41510  41558       pCache->nRecyclable++;
 41511  41559       pPage->isPinned = 0;
 41512  41560     }
 41513  41561   
 41514  41562     pcache1LeaveMutex(pCache->pGroup);
 41515  41563   }
 41516  41564   
................................................................................
 41640  41688   SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
 41641  41689     int nFree = 0;
 41642  41690     assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
 41643  41691     assert( sqlite3_mutex_notheld(pcache1.mutex) );
 41644  41692     if( sqlite3GlobalConfig.nPage==0 ){
 41645  41693       PgHdr1 *p;
 41646  41694       pcache1EnterMutex(&pcache1.grp);
 41647         -    while( (nReq<0 || nFree<nReq) && ((p=pcache1.grp.pLruTail)!=0) ){
        41695  +    while( (nReq<0 || nFree<nReq)
        41696  +       &&  (p=pcache1.grp.lru.pLruPrev)!=0
        41697  +       &&  p->isAnchor==0
        41698  +    ){
 41648  41699         nFree += pcache1MemSize(p->page.pBuf);
 41649  41700   #ifdef SQLITE_PCACHE_SEPARATE_HEADER
 41650  41701         nFree += sqlite3MemSize(p);
 41651  41702   #endif
 41652  41703         assert( p->isPinned==0 );
 41653  41704         pcache1PinPage(p);
 41654  41705         pcache1RemoveFromHash(p, 1);
................................................................................
 41668  41719     int *pnCurrent,      /* OUT: Total number of pages cached */
 41669  41720     int *pnMax,          /* OUT: Global maximum cache size */
 41670  41721     int *pnMin,          /* OUT: Sum of PCache1.nMin for purgeable caches */
 41671  41722     int *pnRecyclable    /* OUT: Total number of pages available for recycling */
 41672  41723   ){
 41673  41724     PgHdr1 *p;
 41674  41725     int nRecyclable = 0;
 41675         -  for(p=pcache1.grp.pLruHead; p; p=p->pLruNext){
        41726  +  for(p=pcache1.grp.lru.pLruNext; !p->isAnchor; p=p->pLruNext){
 41676  41727       assert( p->isPinned==0 );
 41677  41728       nRecyclable++;
 41678  41729     }
 41679  41730     *pnCurrent = pcache1.grp.nCurrentPage;
 41680  41731     *pnMax = (int)pcache1.grp.nMaxPage;
 41681  41732     *pnMin = (int)pcache1.grp.nMinPage;
 41682  41733     *pnRecyclable = nRecyclable;
................................................................................
 42982  43033     u8 eState;                  /* Pager state (OPEN, READER, WRITER_LOCKED..) */
 42983  43034     u8 eLock;                   /* Current lock held on database file */
 42984  43035     u8 changeCountDone;         /* Set after incrementing the change-counter */
 42985  43036     u8 setMaster;               /* True if a m-j name has been written to jrnl */
 42986  43037     u8 doNotSpill;              /* Do not spill the cache when non-zero */
 42987  43038     u8 subjInMemory;            /* True to use in-memory sub-journals */
 42988  43039     u8 bUseFetch;               /* True to use xFetch() */
 42989         -  u8 hasBeenUsed;             /* True if any content previously read */
        43040  +  u8 hasHeldSharedLock;       /* True if a shared lock has ever been held */
 42990  43041     Pgno dbSize;                /* Number of pages in the database */
 42991  43042     Pgno dbOrigSize;            /* dbSize before the current transaction */
 42992  43043     Pgno dbFileSize;            /* Number of pages in the database file */
 42993  43044     Pgno dbHintSize;            /* Value passed to FCNTL_SIZE_HINT call */
 42994  43045     int errCode;                /* One of several kinds of errors */
 42995  43046     int nRec;                   /* Pages journalled since last j-header written */
 42996  43047     u32 cksumInit;              /* Quasi-random value added to every checksum */
................................................................................
 47432  47483   
 47433  47484         assert( pPager->eState==PAGER_OPEN );
 47434  47485         assert( (pPager->eLock==SHARED_LOCK)
 47435  47486              || (pPager->exclusiveMode && pPager->eLock>SHARED_LOCK)
 47436  47487         );
 47437  47488       }
 47438  47489   
 47439         -    if( !pPager->tempFile && pPager->hasBeenUsed ){
        47490  +    if( !pPager->tempFile && pPager->hasHeldSharedLock ){
 47440  47491         /* The shared-lock has just been acquired then check to
 47441  47492         ** see if the database has been modified.  If the database has changed,
 47442         -      ** flush the cache.  The pPager->hasBeenUsed flag prevents this from
        47493  +      ** flush the cache.  The hasHeldSharedLock flag prevents this from
 47443  47494         ** occurring on the very first access to a file, in order to save a
 47444  47495         ** single unnecessary sqlite3OsRead() call at the start-up.
 47445  47496         **
 47446  47497         ** Database changes are detected by looking at 15 bytes beginning
 47447  47498         ** at offset 24 into the file.  The first 4 of these 16 bytes are
 47448  47499         ** a 32-bit counter that is incremented with each change.  The
 47449  47500         ** other bytes change randomly with each file change when
................................................................................
 47505  47556    failed:
 47506  47557     if( rc!=SQLITE_OK ){
 47507  47558       assert( !MEMDB );
 47508  47559       pager_unlock(pPager);
 47509  47560       assert( pPager->eState==PAGER_OPEN );
 47510  47561     }else{
 47511  47562       pPager->eState = PAGER_READER;
        47563  +    pPager->hasHeldSharedLock = 1;
 47512  47564     }
 47513  47565     return rc;
 47514  47566   }
 47515  47567   
 47516  47568   /*
 47517  47569   ** If the reference count has reached zero, rollback any active
 47518  47570   ** transaction and unlock the pager.
................................................................................
 47588  47640     u32 iFrame = 0;                 /* Frame to read from WAL file */
 47589  47641     const int noContent = (flags & PAGER_GET_NOCONTENT);
 47590  47642   
 47591  47643     /* It is acceptable to use a read-only (mmap) page for any page except
 47592  47644     ** page 1 if there is no write-transaction open or the ACQUIRE_READONLY
 47593  47645     ** flag was specified by the caller. And so long as the db is not a 
 47594  47646     ** temporary or in-memory database.  */
 47595         -  const int bMmapOk = (pgno!=1 && USEFETCH(pPager)
        47647  +  const int bMmapOk = (pgno>1 && USEFETCH(pPager)
 47596  47648      && (pPager->eState==PAGER_READER || (flags & PAGER_GET_READONLY))
 47597  47649   #ifdef SQLITE_HAS_CODEC
 47598  47650      && pPager->xCodec==0
 47599  47651   #endif
 47600  47652     );
 47601  47653   
        47654  +  /* Optimization note:  Adding the "pgno<=1" term before "pgno==0" here
        47655  +  ** allows the compiler optimizer to reuse the results of the "pgno>1"
        47656  +  ** test in the previous statement, and avoid testing pgno==0 in the
        47657  +  ** common case where pgno is large. */
        47658  +  if( pgno<=1 && pgno==0 ){
        47659  +    return SQLITE_CORRUPT_BKPT;
        47660  +  }
 47602  47661     assert( pPager->eState>=PAGER_READER );
 47603  47662     assert( assert_pager_state(pPager) );
 47604  47663     assert( noContent==0 || bMmapOk==0 );
 47605  47664   
 47606         -  if( pgno==0 ){
 47607         -    return SQLITE_CORRUPT_BKPT;
 47608         -  }
 47609         -  pPager->hasBeenUsed = 1;
        47665  +  assert( pPager->hasHeldSharedLock==1 );
 47610  47666   
 47611  47667     /* If the pager is in the error state, return an error immediately. 
 47612  47668     ** Otherwise, request the page from the PCache layer. */
 47613  47669     if( pPager->errCode!=SQLITE_OK ){
 47614  47670       rc = pPager->errCode;
 47615  47671     }else{
 47616  47672       if( bMmapOk && pagerUseWal(pPager) ){
................................................................................
 47757  47813   */
 47758  47814   SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno){
 47759  47815     sqlite3_pcache_page *pPage;
 47760  47816     assert( pPager!=0 );
 47761  47817     assert( pgno!=0 );
 47762  47818     assert( pPager->pPCache!=0 );
 47763  47819     pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
 47764         -  assert( pPage==0 || pPager->hasBeenUsed );
        47820  +  assert( pPage==0 || pPager->hasHeldSharedLock );
 47765  47821     if( pPage==0 ) return 0;
 47766  47822     return sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pPage);
 47767  47823   }
 47768  47824   
 47769  47825   /*
 47770  47826   ** Release a page reference.
 47771  47827   **
................................................................................
 48724  48780   */
 48725  48781   SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager *pPager){
 48726  48782     return pPager->readOnly;
 48727  48783   }
 48728  48784   
 48729  48785   #ifdef SQLITE_DEBUG
 48730  48786   /*
 48731         -** Return the number of references to the pager.
        48787  +** Return the sum of the reference counts for all pages held by pPager.
 48732  48788   */
 48733  48789   SQLITE_PRIVATE int sqlite3PagerRefcount(Pager *pPager){
 48734  48790     return sqlite3PcacheRefCount(pPager->pPCache);
 48735  48791   }
 48736  48792   #endif
 48737  48793   
 48738  48794   /*
................................................................................
 50036  50092     u8 writeLock;              /* True if in a write transaction */
 50037  50093     u8 ckptLock;               /* True if holding a checkpoint lock */
 50038  50094     u8 readOnly;               /* WAL_RDWR, WAL_RDONLY, or WAL_SHM_RDONLY */
 50039  50095     u8 truncateOnCommit;       /* True to truncate WAL file on commit */
 50040  50096     u8 syncHeader;             /* Fsync the WAL header if true */
 50041  50097     u8 padToSectorBoundary;    /* Pad transactions out to the next sector */
 50042  50098     WalIndexHdr hdr;           /* Wal-index header for current transaction */
        50099  +  u32 minFrame;              /* Ignore wal frames before this one */
 50043  50100     const char *zWalName;      /* Name of WAL file */
 50044  50101     u32 nCkpt;                 /* Checkpoint sequence counter in the wal-header */
 50045  50102   #ifdef SQLITE_DEBUG
 50046  50103     u8 lockError;              /* True if a locking error has occurred */
 50047  50104   #endif
 50048  50105   };
 50049  50106   
................................................................................
 51904  51961       ** that the log file may have been wrapped by a writer, or that frames
 51905  51962       ** that occur later in the log than pWal->hdr.mxFrame may have been
 51906  51963       ** copied into the database by a checkpointer. If either of these things
 51907  51964       ** happened, then reading the database with the current value of
 51908  51965       ** pWal->hdr.mxFrame risks reading a corrupted snapshot. So, retry
 51909  51966       ** instead.
 51910  51967       **
 51911         -    ** This does not guarantee that the copy of the wal-index header is up to
 51912         -    ** date before proceeding. That would not be possible without somehow
 51913         -    ** blocking writers. It only guarantees that a dangerous checkpoint or 
 51914         -    ** log-wrap (either of which would require an exclusive lock on
 51915         -    ** WAL_READ_LOCK(mxI)) has not occurred since the snapshot was valid.
        51968  +    ** Before checking that the live wal-index header has not changed
        51969  +    ** since it was read, set Wal.minFrame to the first frame in the wal
        51970  +    ** file that has not yet been checkpointed. This client will not need
        51971  +    ** to read any frames earlier than minFrame from the wal file - they
        51972  +    ** can be safely read directly from the database file.
        51973  +    **
        51974  +    ** Because a ShmBarrier() call is made between taking the copy of 
        51975  +    ** nBackfill and checking that the wal-header in shared-memory still
        51976  +    ** matches the one cached in pWal->hdr, it is guaranteed that the 
        51977  +    ** checkpointer that set nBackfill was not working with a wal-index
        51978  +    ** header newer than that cached in pWal->hdr. If it were, that could
        51979  +    ** cause a problem. The checkpointer could omit to checkpoint
        51980  +    ** a version of page X that lies before pWal->minFrame (call that version
        51981  +    ** A) on the basis that there is a newer version (version B) of the same
        51982  +    ** page later in the wal file. But if version B happens to like past
        51983  +    ** frame pWal->hdr.mxFrame - then the client would incorrectly assume
        51984  +    ** that it can read version A from the database file. However, since
        51985  +    ** we can guarantee that the checkpointer that set nBackfill could not
        51986  +    ** see any pages past pWal->hdr.mxFrame, this problem does not come up.
 51916  51987       */
        51988  +    pWal->minFrame = pInfo->nBackfill+1;
 51917  51989       walShmBarrier(pWal);
 51918  51990       if( pInfo->aReadMark[mxI]!=mxReadMark
 51919  51991        || memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr))
 51920  51992       ){
 51921  51993         walUnlockShared(pWal, WAL_READ_LOCK(mxI));
 51922  51994         return WAL_RETRY;
 51923  51995       }else{
................................................................................
 51980  52052     Wal *pWal,                      /* WAL handle */
 51981  52053     Pgno pgno,                      /* Database page number to read data for */
 51982  52054     u32 *piRead                     /* OUT: Frame number (or zero) */
 51983  52055   ){
 51984  52056     u32 iRead = 0;                  /* If !=0, WAL frame to return data from */
 51985  52057     u32 iLast = pWal->hdr.mxFrame;  /* Last page in WAL for this reader */
 51986  52058     int iHash;                      /* Used to loop through N hash tables */
        52059  +  int iMinHash;
 51987  52060   
 51988  52061     /* This routine is only be called from within a read transaction. */
 51989  52062     assert( pWal->readLock>=0 || pWal->lockError );
 51990  52063   
 51991  52064     /* If the "last page" field of the wal-index header snapshot is 0, then
 51992  52065     ** no data will be read from the wal under any circumstances. Return early
 51993  52066     ** in this case as an optimization.  Likewise, if pWal->readLock==0, 
................................................................................
 52020  52093     **   (aPgno[iFrame]==pgno): 
 52021  52094     **     This condition filters out normal hash-table collisions.
 52022  52095     **
 52023  52096     **   (iFrame<=iLast): 
 52024  52097     **     This condition filters out entries that were added to the hash
 52025  52098     **     table after the current read-transaction had started.
 52026  52099     */
 52027         -  for(iHash=walFramePage(iLast); iHash>=0 && iRead==0; iHash--){
        52100  +  iMinHash = walFramePage(pWal->minFrame);
        52101  +  for(iHash=walFramePage(iLast); iHash>=iMinHash && iRead==0; iHash--){
 52028  52102       volatile ht_slot *aHash;      /* Pointer to hash table */
 52029  52103       volatile u32 *aPgno;          /* Pointer to array of page numbers */
 52030  52104       u32 iZero;                    /* Frame number corresponding to aPgno[0] */
 52031  52105       int iKey;                     /* Hash slot index */
 52032  52106       int nCollide;                 /* Number of hash collisions remaining */
 52033  52107       int rc;                       /* Error code */
 52034  52108   
................................................................................
 52035  52109       rc = walHashGet(pWal, iHash, &aHash, &aPgno, &iZero);
 52036  52110       if( rc!=SQLITE_OK ){
 52037  52111         return rc;
 52038  52112       }
 52039  52113       nCollide = HASHTABLE_NSLOT;
 52040  52114       for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){
 52041  52115         u32 iFrame = aHash[iKey] + iZero;
 52042         -      if( iFrame<=iLast && aPgno[aHash[iKey]]==pgno ){
        52116  +      if( iFrame<=iLast && iFrame>=pWal->minFrame && aPgno[aHash[iKey]]==pgno ){
 52043  52117           assert( iFrame>iRead || CORRUPT_DB );
 52044  52118           iRead = iFrame;
 52045  52119         }
 52046  52120         if( (nCollide--)==0 ){
 52047  52121           return SQLITE_CORRUPT_BKPT;
 52048  52122         }
 52049  52123       }
................................................................................
 52052  52126   #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
 52053  52127     /* If expensive assert() statements are available, do a linear search
 52054  52128     ** of the wal-index file content. Make sure the results agree with the
 52055  52129     ** result obtained using the hash indexes above.  */
 52056  52130     {
 52057  52131       u32 iRead2 = 0;
 52058  52132       u32 iTest;
 52059         -    for(iTest=iLast; iTest>0; iTest--){
        52133  +    assert( pWal->minFrame>0 );
        52134  +    for(iTest=iLast; iTest>=pWal->minFrame; iTest--){
 52060  52135         if( walFramePgno(pWal, iTest)==pgno ){
 52061  52136           iRead2 = iTest;
 52062  52137           break;
 52063  52138         }
 52064  52139       }
 52065  52140       assert( iRead==iRead2 );
 52066  52141     }
................................................................................
 53492  53567   /*
 53493  53568   ** get2byteAligned(), unlike get2byte(), requires that its argument point to a
 53494  53569   ** two-byte aligned address.  get2bytea() is only used for accessing the
 53495  53570   ** cell addresses in a btree header.
 53496  53571   */
 53497  53572   #if SQLITE_BYTEORDER==4321
 53498  53573   # define get2byteAligned(x)  (*(u16*)(x))
 53499         -#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4008000
        53574  +#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
        53575  +    && GCC_VERSION>=4008000
 53500  53576   # define get2byteAligned(x)  __builtin_bswap16(*(u16*)(x))
 53501         -#elif SQLITE_BYTEORDER==1234 && defined(_MSC_VER) && _MSC_VER>=1300
        53577  +#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
        53578  +    && defined(_MSC_VER) && _MSC_VER>=1300
 53502  53579   # define get2byteAligned(x)  _byteswap_ushort(*(u16*)(x))
 53503  53580   #else
 53504  53581   # define get2byteAligned(x)  ((x)[0]<<8 | (x)[1])
 53505  53582   #endif
 53506  53583   
 53507  53584   /************** End of btreeInt.h ********************************************/
 53508  53585   /************** Continuing where we left off in btmutex.c ********************/
................................................................................
 62490  62567   */
 62491  62568   static void checkAppendMsg(
 62492  62569     IntegrityCk *pCheck,
 62493  62570     const char *zFormat,
 62494  62571     ...
 62495  62572   ){
 62496  62573     va_list ap;
 62497         -  char zBuf[200];
 62498  62574     if( !pCheck->mxErr ) return;
 62499  62575     pCheck->mxErr--;
 62500  62576     pCheck->nErr++;
 62501  62577     va_start(ap, zFormat);
 62502  62578     if( pCheck->errMsg.nChar ){
 62503  62579       sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1);
 62504  62580     }
 62505  62581     if( pCheck->zPfx ){
 62506         -    sqlite3_snprintf(sizeof(zBuf), zBuf, pCheck->zPfx, pCheck->v1, pCheck->v2);
 62507         -    sqlite3StrAccumAppendAll(&pCheck->errMsg, zBuf);
        62582  +    sqlite3XPrintf(&pCheck->errMsg, 0, pCheck->zPfx, pCheck->v1, pCheck->v2);
 62508  62583     }
 62509  62584     sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
 62510  62585     va_end(ap);
 62511  62586     if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
 62512  62587       pCheck->mallocFailed = 1;
 62513  62588     }
 62514  62589   }
................................................................................
 65325  65400   }
 65326  65401   
 65327  65402   /*
 65328  65403   ** The expression object indicated by the second argument is guaranteed
 65329  65404   ** to be a scalar SQL function. If
 65330  65405   **
 65331  65406   **   * all function arguments are SQL literals,
 65332         -**   * the SQLITE_FUNC_CONSTANT function flag is set, and
        65407  +**   * one of the SQLITE_FUNC_CONSTANT or _SLOCHNG function flags is set, and
 65333  65408   **   * the SQLITE_FUNC_NEEDCOLL function flag is not set,
 65334  65409   **
 65335  65410   ** then this routine attempts to invoke the SQL function. Assuming no
 65336  65411   ** error occurs, output parameter (*ppVal) is set to point to a value 
 65337  65412   ** object containing the result before returning SQLITE_OK.
 65338  65413   **
 65339  65414   ** Affinity aff is applied to the result of the function before returning.
................................................................................
 65366  65441     assert( pCtx!=0 );
 65367  65442     assert( (p->flags & EP_TokenOnly)==0 );
 65368  65443     pList = p->x.pList;
 65369  65444     if( pList ) nVal = pList->nExpr;
 65370  65445     nName = sqlite3Strlen30(p->u.zToken);
 65371  65446     pFunc = sqlite3FindFunction(db, p->u.zToken, nName, nVal, enc, 0);
 65372  65447     assert( pFunc );
 65373         -  if( (pFunc->funcFlags & SQLITE_FUNC_CONSTANT)==0 
        65448  +  if( (pFunc->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0 
 65374  65449      || (pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
 65375  65450     ){
 65376  65451       return SQLITE_OK;
 65377  65452     }
 65378  65453   
 65379  65454     if( pList ){
 65380  65455       apVal = (sqlite3_value**)sqlite3DbMallocZero(db, sizeof(apVal[0]) * nVal);
................................................................................
 65960  66035   }
 65961  66036   
 65962  66037   /*
 65963  66038   ** Return the SQL associated with a prepared statement
 65964  66039   */
 65965  66040   SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt){
 65966  66041     Vdbe *p = (Vdbe *)pStmt;
 65967         -  return (p && p->isPrepareV2) ? p->zSql : 0;
        66042  +  return p ? p->zSql : 0;
 65968  66043   }
 65969  66044   
 65970  66045   /*
 65971  66046   ** Swap all content between two VDBE structures.
 65972  66047   */
 65973  66048   SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe *pA, Vdbe *pB){
 65974  66049     Vdbe tmp, *pTmp;
................................................................................
 66107  66182   SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe *p, int op, int p1){
 66108  66183     return sqlite3VdbeAddOp3(p, op, p1, 0, 0);
 66109  66184   }
 66110  66185   SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe *p, int op, int p1, int p2){
 66111  66186     return sqlite3VdbeAddOp3(p, op, p1, p2, 0);
 66112  66187   }
 66113  66188   
        66189  +/* Generate code for an unconditional jump to instruction iDest
        66190  +*/
        66191  +SQLITE_PRIVATE int sqlite3VdbeGoto(Vdbe *p, int iDest){
        66192  +  return sqlite3VdbeAddOp3(p, OP_Goto, 0, iDest, 0);
        66193  +}
        66194  +
        66195  +/* Generate code to cause the string zStr to be loaded into
        66196  +** register iDest
        66197  +*/
        66198  +SQLITE_PRIVATE int sqlite3VdbeLoadString(Vdbe *p, int iDest, const char *zStr){
        66199  +  return sqlite3VdbeAddOp4(p, OP_String8, 0, iDest, 0, zStr, 0);
        66200  +}
        66201  +
        66202  +/*
        66203  +** Generate code that initializes multiple registers to string or integer
        66204  +** constants.  The registers begin with iDest and increase consecutively.
        66205  +** One register is initialized for each characgter in zTypes[].  For each
        66206  +** "s" character in zTypes[], the register is a string if the argument is
        66207  +** not NULL, or OP_Null if the value is a null pointer.  For each "i" character
        66208  +** in zTypes[], the register is initialized to an integer.
        66209  +*/
        66210  +SQLITE_PRIVATE void sqlite3VdbeMultiLoad(Vdbe *p, int iDest, const char *zTypes, ...){
        66211  +  va_list ap;
        66212  +  int i;
        66213  +  char c;
        66214  +  va_start(ap, zTypes);
        66215  +  for(i=0; (c = zTypes[i])!=0; i++){
        66216  +    if( c=='s' ){
        66217  +      const char *z = va_arg(ap, const char*);
        66218  +      int addr = sqlite3VdbeAddOp2(p, z==0 ? OP_Null : OP_String8, 0, iDest++);
        66219  +      if( z ) sqlite3VdbeChangeP4(p, addr, z, 0);
        66220  +    }else{
        66221  +      assert( c=='i' );
        66222  +      sqlite3VdbeAddOp2(p, OP_Integer, va_arg(ap, int), iDest++);
        66223  +    }
        66224  +  }
        66225  +  va_end(ap);
        66226  +}
 66114  66227   
 66115  66228   /*
 66116  66229   ** Add an opcode that includes the p4 value as a pointer.
 66117  66230   */
 66118  66231   SQLITE_PRIVATE int sqlite3VdbeAddOp4(
 66119  66232     Vdbe *p,            /* Add the opcode to this VM */
 66120  66233     int op,             /* The new opcode */
................................................................................
 66126  66239   ){
 66127  66240     int addr = sqlite3VdbeAddOp3(p, op, p1, p2, p3);
 66128  66241     sqlite3VdbeChangeP4(p, addr, zP4, p4type);
 66129  66242     return addr;
 66130  66243   }
 66131  66244   
 66132  66245   /*
 66133         -** Add an opcode that includes the p4 value with a P4_INT64 type.
        66246  +** Add an opcode that includes the p4 value with a P4_INT64 or
        66247  +** P4_REAL type.
 66134  66248   */
 66135  66249   SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(
 66136  66250     Vdbe *p,            /* Add the opcode to this VM */
 66137  66251     int op,             /* The new opcode */
 66138  66252     int p1,             /* The P1 operand */
 66139  66253     int p2,             /* The P2 operand */
 66140  66254     int p3,             /* The P3 operand */
................................................................................
 66211  66325   ** a prior call to sqlite3VdbeMakeLabel().
 66212  66326   */
 66213  66327   SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){
 66214  66328     Parse *p = v->pParse;
 66215  66329     int j = -1-x;
 66216  66330     assert( v->magic==VDBE_MAGIC_INIT );
 66217  66331     assert( j<p->nLabel );
 66218         -  if( ALWAYS(j>=0) && p->aLabel ){
        66332  +  assert( j>=0 );
        66333  +  if( p->aLabel ){
 66219  66334       p->aLabel[j] = v->nOp;
 66220  66335     }
 66221  66336     p->iFixedOp = v->nOp - 1;
 66222  66337   }
 66223  66338   
 66224  66339   /*
 66225  66340   ** Mark the VDBE as one that can only be run one time.
................................................................................
 66355  66470     ** from failing.  */
 66356  66471     return ( v->db->mallocFailed || hasAbort==mayAbort || hasFkCounter
 66357  66472                 || (hasCreateTable && hasInitCoroutine) );
 66358  66473   }
 66359  66474   #endif /* SQLITE_DEBUG - the sqlite3AssertMayAbort() function */
 66360  66475   
 66361  66476   /*
 66362         -** Loop through the program looking for P2 values that are negative
 66363         -** on jump instructions.  Each such value is a label.  Resolve the
 66364         -** label by setting the P2 value to its correct non-zero value.
        66477  +** This routine is called after all opcodes have been inserted.  It loops
        66478  +** through all the opcodes and fixes up some details.
 66365  66479   **
 66366         -** This routine is called once after all opcodes have been inserted.
        66480  +** (1) For each jump instruction with a negative P2 value (a label)
        66481  +**     resolve the P2 value to an actual address.
 66367  66482   **
 66368         -** Variable *pMaxFuncArgs is set to the maximum value of any P2 argument 
 66369         -** to an OP_Function, OP_AggStep or OP_VFilter opcode. This is used by 
 66370         -** sqlite3VdbeMakeReady() to size the Vdbe.apArg[] array.
        66483  +** (2) Compute the maximum number of arguments used by any SQL function
        66484  +**     and store that value in *pMaxFuncArgs.
 66371  66485   **
 66372         -** The Op.opflags field is set on all opcodes.
        66486  +** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately
        66487  +**     indicate what the prepared statement actually does.
        66488  +**
        66489  +** (4) Initialize the p4.xAdvance pointer on opcodes that use it.
        66490  +**
        66491  +** (5) Reclaim the memory allocated for storing labels.
 66373  66492   */
 66374  66493   static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
 66375  66494     int i;
 66376  66495     int nMaxArgs = *pMaxFuncArgs;
 66377  66496     Op *pOp;
 66378  66497     Parse *pParse = p->pParse;
 66379  66498     int *aLabel = pParse->aLabel;
................................................................................
 66478  66597   }
 66479  66598   
 66480  66599   /*
 66481  66600   ** Add a whole list of operations to the operation stack.  Return the
 66482  66601   ** address of the first operation added.
 66483  66602   */
 66484  66603   SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp, int iLineno){
 66485         -  int addr;
        66604  +  int addr, i;
        66605  +  VdbeOp *pOut;
        66606  +  assert( nOp>0 );
 66486  66607     assert( p->magic==VDBE_MAGIC_INIT );
 66487  66608     if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p, nOp) ){
 66488  66609       return 0;
 66489  66610     }
 66490  66611     addr = p->nOp;
 66491         -  if( ALWAYS(nOp>0) ){
 66492         -    int i;
 66493         -    VdbeOpList const *pIn = aOp;
 66494         -    for(i=0; i<nOp; i++, pIn++){
 66495         -      int p2 = pIn->p2;
 66496         -      VdbeOp *pOut = &p->aOp[i+addr];
 66497         -      pOut->opcode = pIn->opcode;
 66498         -      pOut->p1 = pIn->p1;
 66499         -      if( p2<0 ){
 66500         -        assert( sqlite3OpcodeProperty[pOut->opcode] & OPFLG_JUMP );
 66501         -        pOut->p2 = addr + ADDR(p2);
 66502         -      }else{
 66503         -        pOut->p2 = p2;
 66504         -      }
 66505         -      pOut->p3 = pIn->p3;
 66506         -      pOut->p4type = P4_NOTUSED;
 66507         -      pOut->p4.p = 0;
 66508         -      pOut->p5 = 0;
        66612  +  pOut = &p->aOp[addr];
        66613  +  for(i=0; i<nOp; i++, aOp++, pOut++){
        66614  +    int p2 = aOp->p2;
        66615  +    pOut->opcode = aOp->opcode;
        66616  +    pOut->p1 = aOp->p1;
        66617  +    if( p2<0 ){
        66618  +      assert( sqlite3OpcodeProperty[pOut->opcode] & OPFLG_JUMP );
        66619  +      pOut->p2 = addr + ADDR(p2);
        66620  +    }else{
        66621  +      pOut->p2 = p2;
        66622  +    }
        66623  +    pOut->p3 = aOp->p3;
        66624  +    pOut->p4type = P4_NOTUSED;
        66625  +    pOut->p4.p = 0;
        66626  +    pOut->p5 = 0;
 66509  66627   #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
 66510         -      pOut->zComment = 0;
        66628  +    pOut->zComment = 0;
 66511  66629   #endif
 66512  66630   #ifdef SQLITE_VDBE_COVERAGE
 66513         -      pOut->iSrcLine = iLineno+i;
        66631  +    pOut->iSrcLine = iLineno+i;
 66514  66632   #else
 66515         -      (void)iLineno;
        66633  +    (void)iLineno;
 66516  66634   #endif
 66517  66635   #ifdef SQLITE_DEBUG
 66518         -      if( p->db->flags & SQLITE_VdbeAddopTrace ){
 66519         -        sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]);
 66520         -      }
        66636  +    if( p->db->flags & SQLITE_VdbeAddopTrace ){
        66637  +      sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]);
        66638  +    }
 66521  66639   #endif
 66522         -    }
 66523         -    p->nOp += nOp;
 66524  66640     }
        66641  +  p->nOp += nOp;
 66525  66642     return addr;
 66526  66643   }
 66527  66644   
 66528  66645   #if defined(SQLITE_ENABLE_STMT_SCANSTATUS)
 66529  66646   /*
 66530  66647   ** Add an entry to the array of counters managed by sqlite3_stmt_scanstatus().
 66531  66648   */
................................................................................
 66550  66667       p->aScan = aNew;
 66551  66668     }
 66552  66669   }
 66553  66670   #endif
 66554  66671   
 66555  66672   
 66556  66673   /*
 66557         -** Change the value of the P1 operand for a specific instruction.
 66558         -** This routine is useful when a large program is loaded from a
 66559         -** static array using sqlite3VdbeAddOpList but we want to make a
 66560         -** few minor changes to the program.
        66674  +** Change the value of the opcode, or P1, P2, P3, or P5 operands
        66675  +** for a specific instruction.
 66561  66676   */
        66677  +SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe *p, u32 addr, u8 iNewOpcode){
        66678  +  sqlite3VdbeGetOp(p,addr)->opcode = iNewOpcode;
        66679  +}
 66562  66680   SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe *p, u32 addr, int val){
 66563         -  assert( p!=0 );
 66564         -  if( ((u32)p->nOp)>addr ){
 66565         -    p->aOp[addr].p1 = val;
 66566         -  }
        66681  +  sqlite3VdbeGetOp(p,addr)->p1 = val;
 66567  66682   }
 66568         -
 66569         -/*
 66570         -** Change the value of the P2 operand for a specific instruction.
 66571         -** This routine is useful for setting a jump destination.
 66572         -*/
 66573  66683   SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe *p, u32 addr, int val){
 66574         -  assert( p!=0 );
 66575         -  if( ((u32)p->nOp)>addr ){
 66576         -    p->aOp[addr].p2 = val;
 66577         -  }
        66684  +  sqlite3VdbeGetOp(p,addr)->p2 = val;
 66578  66685   }
 66579         -
 66580         -/*
 66581         -** Change the value of the P3 operand for a specific instruction.
 66582         -*/
 66583  66686   SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, u32 addr, int val){
 66584         -  assert( p!=0 );
 66585         -  if( ((u32)p->nOp)>addr ){
 66586         -    p->aOp[addr].p3 = val;
 66587         -  }
        66687  +  sqlite3VdbeGetOp(p,addr)->p3 = val;
 66588  66688   }
 66589         -
 66590         -/*
 66591         -** Change the value of the P5 operand for the most recently
 66592         -** added operation.
 66593         -*/
 66594         -SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u8 val){
 66595         -  assert( p!=0 );
 66596         -  if( p->aOp ){
 66597         -    assert( p->nOp>0 );
 66598         -    p->aOp[p->nOp-1].p5 = val;
 66599         -  }
        66689  +SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u8 p5){
        66690  +  sqlite3VdbeGetOp(p,-1)->p5 = p5;
 66600  66691   }
 66601  66692   
 66602  66693   /*
 66603  66694   ** Change the P2 operand of instruction addr so that it points to
 66604  66695   ** the address of the next instruction to be coded.
 66605  66696   */
 66606  66697   SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe *p, int addr){
 66607         -  sqlite3VdbeChangeP2(p, addr, p->nOp);
 66608  66698     p->pParse->iFixedOp = p->nOp - 1;
        66699  +  sqlite3VdbeChangeP2(p, addr, p->nOp);
 66609  66700   }
 66610  66701   
 66611  66702   
 66612  66703   /*
 66613  66704   ** If the input FuncDef structure is ephemeral, then free it.  If
 66614  66705   ** the FuncDef is not ephermal, then do nothing.
 66615  66706   */
................................................................................
 66986  67077           CollSeq *pColl = pKeyInfo->aColl[j];
 66987  67078           const char *zColl = pColl ? pColl->zName : "nil";
 66988  67079           int n = sqlite3Strlen30(zColl);
 66989  67080           if( n==6 && memcmp(zColl,"BINARY",6)==0 ){
 66990  67081             zColl = "B";
 66991  67082             n = 1;
 66992  67083           }
 66993         -        if( i+n>nTemp-6 ){
        67084  +        if( i+n>nTemp-7 ){
 66994  67085             memcpy(&zTemp[i],",...",4);
        67086  +          i += 4;
 66995  67087             break;
 66996  67088           }
 66997  67089           zTemp[i++] = ',';
 66998  67090           if( pKeyInfo->aSortOrder[j] ){
 66999  67091             zTemp[i++] = '-';
 67000  67092           }
 67001  67093           memcpy(&zTemp[i], zColl, n+1);
................................................................................
 70752  70844     ** returned if this statement was compiled using the legacy 
 70753  70845     ** sqlite3_prepare() interface. According to the docs, this can only
 70754  70846     ** be one of the values in the first assert() below. Variable p->rc 
 70755  70847     ** contains the value that would be returned if sqlite3_finalize() 
 70756  70848     ** were called on statement p.
 70757  70849     */
 70758  70850     assert( rc==SQLITE_ROW  || rc==SQLITE_DONE   || rc==SQLITE_ERROR 
 70759         -       || rc==SQLITE_BUSY || rc==SQLITE_MISUSE
        70851  +       || (rc&0xff)==SQLITE_BUSY || rc==SQLITE_MISUSE
 70760  70852     );
 70761  70853     assert( (p->rc!=SQLITE_ROW && p->rc!=SQLITE_DONE) || p->rc==p->rcApp );
 70762  70854     if( p->isPrepareV2 && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){
 70763  70855       /* If this statement was prepared using sqlite3_prepare_v2(), and an
 70764  70856       ** error has occurred, then return the error code in p->rc to the
 70765  70857       ** caller. Set the error code in the database handle to the same value.
 70766  70858       */ 
................................................................................
 70837  70929   ** IMPLEMENTATION-OF: R-46798-50301 The sqlite3_context_db_handle() interface
 70838  70930   ** returns a copy of the pointer to the database connection (the 1st
 70839  70931   ** parameter) of the sqlite3_create_function() and
 70840  70932   ** sqlite3_create_function16() routines that originally registered the
 70841  70933   ** application defined function.
 70842  70934   */
 70843  70935   SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context *p){
 70844         -  assert( p && p->pFunc );
        70936  +  assert( p && p->pOut );
 70845  70937     return p->pOut->db;
 70846  70938   }
 70847  70939   
 70848  70940   /*
 70849  70941   ** Return the current time for a statement.  If the current time
 70850  70942   ** is requested more than once within the same run of a single prepared
 70851  70943   ** statement, the exact same time is returned for each invocation regardless
................................................................................
 72655  72747     assert( p->magic==VDBE_MAGIC_RUN );  /* sqlite3_step() verifies this */
 72656  72748     sqlite3VdbeEnter(p);
 72657  72749     if( p->rc==SQLITE_NOMEM ){
 72658  72750       /* This happens if a malloc() inside a call to sqlite3_column_text() or
 72659  72751       ** sqlite3_column_text16() failed.  */
 72660  72752       goto no_mem;
 72661  72753     }
 72662         -  assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY );
        72754  +  assert( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_BUSY );
 72663  72755     assert( p->bIsReader || p->readOnly!=0 );
 72664  72756     p->rc = SQLITE_OK;
 72665  72757     p->iCurrentTime = 0;
 72666  72758     assert( p->explain==0 );
 72667  72759     p->pResultSet = 0;
 72668  72760     db->busyHandler.nBusy = 0;
 72669  72761     if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
................................................................................
 75092  75184         assert( desiredAutoCommit==1 );
 75093  75185         sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
 75094  75186         db->autoCommit = 1;
 75095  75187       }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
 75096  75188         goto vdbe_return;
 75097  75189       }else{
 75098  75190         db->autoCommit = (u8)desiredAutoCommit;
 75099         -      if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
 75100         -        p->pc = (int)(pOp - aOp);
 75101         -        db->autoCommit = (u8)(1-desiredAutoCommit);
 75102         -        p->rc = rc = SQLITE_BUSY;
 75103         -        goto vdbe_return;
 75104         -      }
        75191  +    }
        75192  +    if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
        75193  +      p->pc = (int)(pOp - aOp);
        75194  +      db->autoCommit = (u8)(1-desiredAutoCommit);
        75195  +      p->rc = rc = SQLITE_BUSY;
        75196  +      goto vdbe_return;
 75105  75197       }
 75106  75198       assert( db->nStatement==0 );
 75107  75199       sqlite3CloseSavepoints(db);
 75108  75200       if( p->rc==SQLITE_OK ){
 75109  75201         rc = SQLITE_DONE;
 75110  75202       }else{
 75111  75203         rc = SQLITE_ERROR;
................................................................................
 75169  75261       rc = SQLITE_READONLY;
 75170  75262       goto abort_due_to_error;
 75171  75263     }
 75172  75264     pBt = db->aDb[pOp->p1].pBt;
 75173  75265   
 75174  75266     if( pBt ){
 75175  75267       rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
 75176         -    if( rc==SQLITE_BUSY ){
        75268  +    testcase( rc==SQLITE_BUSY_SNAPSHOT );
        75269  +    testcase( rc==SQLITE_BUSY_RECOVERY );
        75270  +    if( (rc&0xff)==SQLITE_BUSY ){
 75177  75271         p->pc = (int)(pOp - aOp);
 75178         -      p->rc = rc = SQLITE_BUSY;
        75272  +      p->rc = rc;
 75179  75273         goto vdbe_return;
 75180  75274       }
 75181  75275       if( rc!=SQLITE_OK ){
 75182  75276         goto abort_due_to_error;
 75183  75277       }
 75184  75278   
 75185  75279       if( pOp->p2 && p->usesStmtJournal 
................................................................................
 79007  79101             }
 79008  79102           }
 79009  79103         }
 79010  79104   #endif
 79011  79105         for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
 79012  79106           int j;
 79013  79107           for(j=0; j<pIdx->nKeyCol; j++){
 79014         -          if( pIdx->aiColumn[j]==iCol ){
        79108  +          /* FIXME: Be smarter about indexes that use expressions */
        79109  +          if( pIdx->aiColumn[j]==iCol || pIdx->aiColumn[j]==(-2) ){
 79015  79110               zFault = "indexed";
 79016  79111             }
 79017  79112           }
 79018  79113         }
 79019  79114         if( zFault ){
 79020  79115           sqlite3DbFree(db, zErr);
 79021  79116           zErr = sqlite3MPrintf(db, "cannot open %s column for writing", zFault);
................................................................................
 82588  82683   
 82589  82684     pSrc = p->pSrc;
 82590  82685     if( ALWAYS(pSrc) ){
 82591  82686       for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
 82592  82687         if( sqlite3WalkSelect(pWalker, pItem->pSelect) ){
 82593  82688           return WRC_Abort;
 82594  82689         }
        82690  +      if( pItem->fg.isTabFunc
        82691  +       && sqlite3WalkExprList(pWalker, pItem->u1.pFuncArg)
        82692  +      ){
        82693  +        return WRC_Abort;
        82694  +      }
 82595  82695       }
 82596  82696     }
 82597  82697     return WRC_Continue;
 82598  82698   } 
 82599  82699   
 82600  82700   /*
 82601  82701   ** Call sqlite3WalkExpr() for every expression in Select statement p.
................................................................................
 82685  82785     }
 82686  82786   }
 82687  82787   
 82688  82788   /*
 82689  82789   ** Turn the pExpr expression into an alias for the iCol-th column of the
 82690  82790   ** result set in pEList.
 82691  82791   **
 82692         -** If the result set column is a simple column reference, then this routine
 82693         -** makes an exact copy.  But for any other kind of expression, this
 82694         -** routine make a copy of the result set column as the argument to the
 82695         -** TK_AS operator.  The TK_AS operator causes the expression to be
 82696         -** evaluated just once and then reused for each alias.
 82697         -**
 82698         -** The reason for suppressing the TK_AS term when the expression is a simple
 82699         -** column reference is so that the column reference will be recognized as
 82700         -** usable by indices within the WHERE clause processing logic. 
 82701         -**
 82702         -** The TK_AS operator is inhibited if zType[0]=='G'.  This means
 82703         -** that in a GROUP BY clause, the expression is evaluated twice.  Hence:
 82704         -**
 82705         -**     SELECT random()%5 AS x, count(*) FROM tab GROUP BY x
 82706         -**
 82707         -** Is equivalent to:
 82708         -**
 82709         -**     SELECT random()%5 AS x, count(*) FROM tab GROUP BY random()%5
 82710         -**
 82711         -** The result of random()%5 in the GROUP BY clause is probably different
 82712         -** from the result in the result-set.  On the other hand Standard SQL does
 82713         -** not allow the GROUP BY clause to contain references to result-set columns.
 82714         -** So this should never come up in well-formed queries.
 82715         -**
 82716  82792   ** If the reference is followed by a COLLATE operator, then make sure
 82717  82793   ** the COLLATE operator is preserved.  For example:
 82718  82794   **
 82719  82795   **     SELECT a+b, c+d FROM t1 ORDER BY 1 COLLATE nocase;
 82720  82796   **
 82721  82797   ** Should be transformed into:
 82722  82798   **
................................................................................
 82742  82818   
 82743  82819     assert( iCol>=0 && iCol<pEList->nExpr );
 82744  82820     pOrig = pEList->a[iCol].pExpr;
 82745  82821     assert( pOrig!=0 );
 82746  82822     db = pParse->db;
 82747  82823     pDup = sqlite3ExprDup(db, pOrig, 0);
 82748  82824     if( pDup==0 ) return;
 82749         -  if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
 82750         -    incrAggFunctionDepth(pDup, nSubquery);
 82751         -    pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
 82752         -    if( pDup==0 ) return;
 82753         -    ExprSetProperty(pDup, EP_Skip);
 82754         -    if( pEList->a[iCol].u.x.iAlias==0 ){
 82755         -      pEList->a[iCol].u.x.iAlias = (u16)(++pParse->nAlias);
 82756         -    }
 82757         -    pDup->iTable = pEList->a[iCol].u.x.iAlias;
 82758         -  }
        82825  +  if( zType[0]!='G' ) incrAggFunctionDepth(pDup, nSubquery);
 82759  82826     if( pExpr->op==TK_COLLATE ){
 82760  82827       pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
 82761  82828     }
        82829  +  ExprSetProperty(pDup, EP_Alias);
 82762  82830   
 82763  82831     /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This 
 82764  82832     ** prevents ExprDelete() from deleting the Expr structure itself,
 82765  82833     ** allowing it to be repopulated by the memcpy() on the following line.
 82766  82834     ** The pExpr->u.zToken might point into memory that will be freed by the
 82767  82835     ** sqlite3DbFree(db, pDup) on the last line of this block, so be sure to
 82768  82836     ** make a copy of the token before doing the sqlite3DbFree().
................................................................................
 82946  83014           for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
 82947  83015             if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
 82948  83016               /* If there has been exactly one prior match and this match
 82949  83017               ** is for the right-hand table of a NATURAL JOIN or is in a 
 82950  83018               ** USING clause, then skip this match.
 82951  83019               */
 82952  83020               if( cnt==1 ){
 82953         -              if( pItem->jointype & JT_NATURAL ) continue;
        83021  +              if( pItem->fg.jointype & JT_NATURAL ) continue;
 82954  83022                 if( nameInUsingClause(pItem->pUsing, zCol) ) continue;
 82955  83023               }
 82956  83024               cnt++;
 82957  83025               pMatch = pItem;
 82958  83026               /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
 82959  83027               pExpr->iColumn = j==pTab->iPKey ? -1 : (i16)j;
 82960  83028               break;
................................................................................
 82961  83029             }
 82962  83030           }
 82963  83031         }
 82964  83032         if( pMatch ){
 82965  83033           pExpr->iTable = pMatch->iCursor;
 82966  83034           pExpr->pTab = pMatch->pTab;
 82967  83035           /* RIGHT JOIN not (yet) supported */
 82968         -        assert( (pMatch->jointype & JT_RIGHT)==0 );
 82969         -        if( (pMatch->jointype & JT_LEFT)!=0 ){
        83036  +        assert( (pMatch->fg.jointype & JT_RIGHT)==0 );
        83037  +        if( (pMatch->fg.jointype & JT_LEFT)!=0 ){
 82970  83038             ExprSetProperty(pExpr, EP_CanBeNull);
 82971  83039           }
 82972  83040           pSchema = pExpr->pTab->pSchema;
 82973  83041         }
 82974  83042       } /* if( pSrcList ) */
 82975  83043   
 82976  83044   #ifndef SQLITE_OMIT_TRIGGER
................................................................................
 83047  83115       **
 83048  83116       ** In cases like this, replace pExpr with a copy of the expression that
 83049  83117       ** forms the result set entry ("a+b" in the example) and return immediately.
 83050  83118       ** Note that the expression in the result set should have already been
 83051  83119       ** resolved by the time the WHERE clause is resolved.
 83052  83120       **
 83053  83121       ** The ability to use an output result-set column in the WHERE, GROUP BY,
 83054         -    ** or HAVING clauses, or as part of a larger expression in the ORDRE BY
        83122  +    ** or HAVING clauses, or as part of a larger expression in the ORDER BY
 83055  83123       ** clause is not standard SQL.  This is a (goofy) SQLite extension, that
 83056         -    ** is supported for backwards compatibility only.  TO DO: Issue a warning
        83124  +    ** is supported for backwards compatibility only. Hence, we issue a warning
 83057  83125       ** on sqlite3_log() whenever the capability is used.
 83058  83126       */
 83059  83127       if( (pEList = pNC->pEList)!=0
 83060  83128        && zTab==0
 83061  83129        && cnt==0
 83062  83130       ){
 83063  83131         for(j=0; j<pEList->nExpr; j++){
................................................................................
 83146  83214     pExpr->pLeft = 0;
 83147  83215     sqlite3ExprDelete(db, pExpr->pRight);
 83148  83216     pExpr->pRight = 0;
 83149  83217     pExpr->op = (isTrigger ? TK_TRIGGER : TK_COLUMN);
 83150  83218   lookupname_end:
 83151  83219     if( cnt==1 ){
 83152  83220       assert( pNC!=0 );
 83153         -    if( pExpr->op!=TK_AS ){
        83221  +    if( !ExprHasProperty(pExpr, EP_Alias) ){
 83154  83222         sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList);
 83155  83223       }
 83156  83224       /* Increment the nRef value on all name contexts from TopNC up to
 83157  83225       ** the point where the name matched. */
 83158  83226       for(;;){
 83159  83227         assert( pTopNC!=0 );
 83160  83228         pTopNC->nRef++;
................................................................................
 83187  83255       }
 83188  83256       ExprSetProperty(p, EP_Resolved);
 83189  83257     }
 83190  83258     return p;
 83191  83259   }
 83192  83260   
 83193  83261   /*
 83194         -** Report an error that an expression is not valid for a partial index WHERE
 83195         -** clause.
        83262  +** Report an error that an expression is not valid for some set of
        83263  +** pNC->ncFlags values determined by validMask.
 83196  83264   */
 83197         -static void notValidPartIdxWhere(
        83265  +static void notValid(
 83198  83266     Parse *pParse,       /* Leave error message here */
 83199  83267     NameContext *pNC,    /* The name context */
 83200         -  const char *zMsg     /* Type of error */
        83268  +  const char *zMsg,    /* Type of error */
        83269  +  int validMask        /* Set of contexts for which prohibited */
 83201  83270   ){
 83202         -  if( (pNC->ncFlags & NC_PartIdx)!=0 ){
 83203         -    sqlite3ErrorMsg(pParse, "%s prohibited in partial index WHERE clauses",
 83204         -                    zMsg);
 83205         -  }
 83206         -}
 83207         -
        83271  +  assert( (validMask&~(NC_IsCheck|NC_PartIdx|NC_IdxExpr))==0 );
        83272  +  if( (pNC->ncFlags & validMask)!=0 ){
        83273  +    const char *zIn = "partial index WHERE clauses";
        83274  +    if( pNC->ncFlags & NC_IdxExpr )      zIn = "index expressions";
 83208  83275   #ifndef SQLITE_OMIT_CHECK
 83209         -/*
 83210         -** Report an error that an expression is not valid for a CHECK constraint.
 83211         -*/
 83212         -static void notValidCheckConstraint(
 83213         -  Parse *pParse,       /* Leave error message here */
 83214         -  NameContext *pNC,    /* The name context */
 83215         -  const char *zMsg     /* Type of error */
 83216         -){
 83217         -  if( (pNC->ncFlags & NC_IsCheck)!=0 ){
 83218         -    sqlite3ErrorMsg(pParse,"%s prohibited in CHECK constraints", zMsg);
        83276  +    else if( pNC->ncFlags & NC_IsCheck ) zIn = "CHECK constraints";
        83277  +#endif
        83278  +    sqlite3ErrorMsg(pParse, "%s prohibited in %s", zMsg, zIn);
 83219  83279     }
 83220  83280   }
 83221         -#else
 83222         -# define notValidCheckConstraint(P,N,M)
 83223         -#endif
 83224  83281   
 83225  83282   /*
 83226  83283   ** Expression p should encode a floating point value between 1.0 and 0.0.
 83227  83284   ** Return 1024 times this value.  Or return -1 if p is not a floating point
 83228  83285   ** value between 1.0 and 0.0.
 83229  83286   */
 83230  83287   static int exprProbability(Expr *p){
................................................................................
 83301  83358       case TK_DOT: {
 83302  83359         const char *zColumn;
 83303  83360         const char *zTable;
 83304  83361         const char *zDb;
 83305  83362         Expr *pRight;
 83306  83363   
 83307  83364         /* if( pSrcList==0 ) break; */
        83365  +      notValid(pParse, pNC, "the \".\" operator", NC_IdxExpr);
        83366  +      /*notValid(pParse, pNC, "the \".\" operator", NC_PartIdx|NC_IsCheck, 1);*/
 83308  83367         pRight = pExpr->pRight;
 83309  83368         if( pRight->op==TK_ID ){
 83310  83369           zDb = 0;
 83311  83370           zTable = pExpr->pLeft->u.zToken;
 83312  83371           zColumn = pRight->u.zToken;
 83313  83372         }else{
 83314  83373           assert( pRight->op==TK_DOT );
................................................................................
 83330  83389         int auth;                   /* Authorization to use the function */
 83331  83390         int nId;                    /* Number of characters in function name */
 83332  83391         const char *zId;            /* The function name. */
 83333  83392         FuncDef *pDef;              /* Information about the function */
 83334  83393         u8 enc = ENC(pParse->db);   /* The database encoding */
 83335  83394   
 83336  83395         assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
 83337         -      notValidPartIdxWhere(pParse, pNC, "functions");
        83396  +      notValid(pParse, pNC, "functions", NC_PartIdx);
 83338  83397         zId = pExpr->u.zToken;
 83339  83398         nId = sqlite3Strlen30(zId);
 83340  83399         pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
 83341  83400         if( pDef==0 ){
 83342  83401           pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0);
 83343  83402           if( pDef==0 ){
 83344  83403             no_such_func = 1;
................................................................................
 83378  83437                                       pDef->zName);
 83379  83438               pNC->nErr++;
 83380  83439             }
 83381  83440             pExpr->op = TK_NULL;
 83382  83441             return WRC_Prune;
 83383  83442           }
 83384  83443   #endif
 83385         -        if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ){
        83444  +        if( pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG) ){
        83445  +          /* For the purposes of the EP_ConstFunc flag, date and time
        83446  +          ** functions and other functions that change slowly are considered
        83447  +          ** constant because they are constant for the duration of one query */
 83386  83448             ExprSetProperty(pExpr,EP_ConstFunc);
 83387  83449           }
        83450  +        if( (pDef->funcFlags & SQLITE_FUNC_CONSTANT)==0 ){
        83451  +          /* Date/time functions that use 'now', and other functions like
        83452  +          ** sqlite_version() that might change over time cannot be used
        83453  +          ** in an index. */
        83454  +          notValid(pParse, pNC, "non-deterministic functions", NC_IdxExpr);
        83455  +        }
 83388  83456         }
 83389  83457         if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
 83390  83458           sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
 83391  83459           pNC->nErr++;
 83392  83460           is_agg = 0;
 83393  83461         }else if( no_such_func && pParse->db->init.busy==0 ){
 83394  83462           sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId);
................................................................................
 83426  83494       case TK_SELECT:
 83427  83495       case TK_EXISTS:  testcase( pExpr->op==TK_EXISTS );
 83428  83496   #endif
 83429  83497       case TK_IN: {
 83430  83498         testcase( pExpr->op==TK_IN );
 83431  83499         if( ExprHasProperty(pExpr, EP_xIsSelect) ){
 83432  83500           int nRef = pNC->nRef;
 83433         -        notValidCheckConstraint(pParse, pNC, "subqueries");
 83434         -        notValidPartIdxWhere(pParse, pNC, "subqueries");
        83501  +        notValid(pParse, pNC, "subqueries", NC_IsCheck|NC_PartIdx|NC_IdxExpr);
 83435  83502           sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
 83436  83503           assert( pNC->nRef>=nRef );
 83437  83504           if( nRef!=pNC->nRef ){
 83438  83505             ExprSetProperty(pExpr, EP_VarSelect);
 83439  83506           }
 83440  83507         }
 83441  83508         break;
 83442  83509       }
 83443  83510       case TK_VARIABLE: {
 83444         -      notValidCheckConstraint(pParse, pNC, "parameters");
 83445         -      notValidPartIdxWhere(pParse, pNC, "parameters");
        83511  +      notValid(pParse, pNC, "parameters", NC_IsCheck|NC_PartIdx|NC_IdxExpr);
 83446  83512         break;
 83447  83513       }
 83448  83514     }
 83449  83515     return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue;
 83450  83516   }
 83451  83517   
 83452  83518   /*
................................................................................
 83782  83848   */
 83783  83849   static int resolveSelectStep(Walker *pWalker, Select *p){
 83784  83850     NameContext *pOuterNC;  /* Context that contains this SELECT */
 83785  83851     NameContext sNC;        /* Name context of this SELECT */
 83786  83852     int isCompound;         /* True if p is a compound select */
 83787  83853     int nCompound;          /* Number of compound terms processed so far */
 83788  83854     Parse *pParse;          /* Parsing context */
 83789         -  ExprList *pEList;       /* Result set expression list */
 83790  83855     int i;                  /* Loop counter */
 83791  83856     ExprList *pGroupBy;     /* The GROUP BY clause */
 83792  83857     Select *pLeftmost;      /* Left-most of SELECT of a compound */
 83793  83858     sqlite3 *db;            /* Database connection */
 83794  83859     
 83795  83860   
 83796  83861     assert( p!=0 );
................................................................................
 83855  83920           int nRef = 0;             /* Refcount for pOuterNC and outer contexts */
 83856  83921           const char *zSavedContext = pParse->zAuthContext;
 83857  83922   
 83858  83923           /* Count the total number of references to pOuterNC and all of its
 83859  83924           ** parent contexts. After resolving references to expressions in
 83860  83925           ** pItem->pSelect, check if this value has changed. If so, then
 83861  83926           ** SELECT statement pItem->pSelect must be correlated. Set the
 83862         -        ** pItem->isCorrelated flag if this is the case. */
        83927  +        ** pItem->fg.isCorrelated flag if this is the case. */
 83863  83928           for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef += pNC->nRef;
 83864  83929   
 83865  83930           if( pItem->zName ) pParse->zAuthContext = pItem->zName;
 83866  83931           sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC);
 83867  83932           pParse->zAuthContext = zSavedContext;
 83868  83933           if( pParse->nErr || db->mallocFailed ) return WRC_Abort;
 83869  83934   
 83870  83935           for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef -= pNC->nRef;
 83871         -        assert( pItem->isCorrelated==0 && nRef<=0 );
 83872         -        pItem->isCorrelated = (nRef!=0);
        83936  +        assert( pItem->fg.isCorrelated==0 && nRef<=0 );
        83937  +        pItem->fg.isCorrelated = (nRef!=0);
 83873  83938         }
 83874  83939       }
 83875  83940     
 83876  83941       /* Set up the local name-context to pass to sqlite3ResolveExprNames() to
 83877  83942       ** resolve the result-set expression list.
 83878  83943       */
 83879  83944       sNC.ncFlags = NC_AllowAgg;
 83880  83945       sNC.pSrcList = p->pSrc;
 83881  83946       sNC.pNext = pOuterNC;
 83882  83947     
 83883  83948       /* Resolve names in the result set. */
 83884         -    pEList = p->pEList;
 83885         -    assert( pEList!=0 );
 83886         -    for(i=0; i<pEList->nExpr; i++){
 83887         -      Expr *pX = pEList->a[i].pExpr;
 83888         -      if( sqlite3ResolveExprNames(&sNC, pX) ){
 83889         -        return WRC_Abort;
 83890         -      }
 83891         -    }
        83949  +    if( sqlite3ResolveExprListNames(&sNC, p->pEList) ) return WRC_Abort;
 83892  83950     
 83893  83951       /* If there are no aggregate functions in the result-set, and no GROUP BY 
 83894  83952       ** expression, do not allow aggregates in any of the other expressions.
 83895  83953       */
 83896  83954       assert( (p->selFlags & SF_Aggregate)==0 );
 83897  83955       pGroupBy = p->pGroupBy;
 83898  83956       if( pGroupBy || (sNC.ncFlags & NC_HasAgg)!=0 ){
................................................................................
 83916  83974       **
 83917  83975       ** Minor point: If this is the case, then the expression will be
 83918  83976       ** re-evaluated for each reference to it.
 83919  83977       */
 83920  83978       sNC.pEList = p->pEList;
 83921  83979       if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;
 83922  83980       if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort;
        83981  +
        83982  +    /* Resolve names in table-valued-function arguments */
        83983  +    for(i=0; i<p->pSrc->nSrc; i++){
        83984  +      struct SrcList_item *pItem = &p->pSrc->a[i];
        83985  +      if( pItem->fg.isTabFunc
        83986  +       && sqlite3ResolveExprListNames(&sNC, pItem->u1.pFuncArg) 
        83987  +      ){
        83988  +        return WRC_Abort;
        83989  +      }
        83990  +    }
 83923  83991   
 83924  83992       /* The ORDER BY and GROUP BY clauses may not refer to terms in
 83925  83993       ** outer queries 
 83926  83994       */
 83927  83995       sNC.pNext = 0;
 83928  83996       sNC.ncFlags |= NC_AllowAgg;
 83929  83997   
................................................................................
 84080  84148     if( pNC->ncFlags & NC_HasAgg ){
 84081  84149       ExprSetProperty(pExpr, EP_Agg);
 84082  84150     }
 84083  84151     pNC->ncFlags |= savedHasAgg;
 84084  84152     return ExprHasProperty(pExpr, EP_Error);
 84085  84153   }
 84086  84154   
        84155  +/*
        84156  +** Resolve all names for all expression in an expression list.  This is
        84157  +** just like sqlite3ResolveExprNames() except that it works for an expression
        84158  +** list rather than a single expression.
        84159  +*/
        84160  +SQLITE_PRIVATE int sqlite3ResolveExprListNames( 
        84161  +  NameContext *pNC,       /* Namespace to resolve expressions in. */
        84162  +  ExprList *pList         /* The expression list to be analyzed. */
        84163  +){
        84164  +  int i;
        84165  +  assert( pList!=0 );
        84166  +  for(i=0; i<pList->nExpr; i++){
        84167  +    if( sqlite3ResolveExprNames(pNC, pList->a[i].pExpr) ) return WRC_Abort;
        84168  +  }
        84169  +  return WRC_Continue;
        84170  +}
 84087  84171   
 84088  84172   /*
 84089  84173   ** Resolve all names in all expressions of a SELECT and in all
 84090  84174   ** decendents of the SELECT, including compounds off of p->pPrior,
 84091  84175   ** subqueries in expressions, and subqueries used as FROM clause
 84092  84176   ** terms.
 84093  84177   **
................................................................................
 84123  84207   ** is set to -1 and the Expr.iColumn value is set to the column number.
 84124  84208   **
 84125  84209   ** Any errors cause an error message to be set in pParse.
 84126  84210   */
 84127  84211   SQLITE_PRIVATE void sqlite3ResolveSelfReference(
 84128  84212     Parse *pParse,      /* Parsing context */
 84129  84213     Table *pTab,        /* The table being referenced */
 84130         -  int type,           /* NC_IsCheck or NC_PartIdx */
        84214  +  int type,           /* NC_IsCheck or NC_PartIdx or NC_IdxExpr */
 84131  84215     Expr *pExpr,        /* Expression to resolve.  May be NULL. */
 84132  84216     ExprList *pList     /* Expression list to resolve.  May be NUL. */
 84133  84217   ){
 84134  84218     SrcList sSrc;                   /* Fake SrcList for pParse->pNewTable */
 84135  84219     NameContext sNC;                /* Name context for pParse->pNewTable */
 84136         -  int i;                          /* Loop counter */
 84137  84220   
 84138         -  assert( type==NC_IsCheck || type==NC_PartIdx );
        84221  +  assert( type==NC_IsCheck || type==NC_PartIdx || type==NC_IdxExpr );
 84139  84222     memset(&sNC, 0, sizeof(sNC));
 84140  84223     memset(&sSrc, 0, sizeof(sSrc));
 84141  84224     sSrc.nSrc = 1;
 84142  84225     sSrc.a[0].zName = pTab->zName;
 84143  84226     sSrc.a[0].pTab = pTab;
 84144  84227     sSrc.a[0].iCursor = -1;
 84145  84228     sNC.pParse = pParse;
 84146  84229     sNC.pSrcList = &sSrc;
 84147  84230     sNC.ncFlags = type;
 84148  84231     if( sqlite3ResolveExprNames(&sNC, pExpr) ) return;
 84149         -  if( pList ){
 84150         -    for(i=0; i<pList->nExpr; i++){
 84151         -      if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){
 84152         -        return;
 84153         -      }
 84154         -    }
 84155         -  }
        84232  +  if( pList ) sqlite3ResolveExprListNames(&sNC, pList);
 84156  84233   }
 84157  84234   
 84158  84235   /************** End of resolve.c *********************************************/
 84159  84236   /************** Begin file expr.c ********************************************/
 84160  84237   /*
 84161  84238   ** 2001 September 15
 84162  84239   **
................................................................................
 84246  84323     assert( zC!=0 );
 84247  84324     s.z = zC;
 84248  84325     s.n = sqlite3Strlen30(s.z);
 84249  84326     return sqlite3ExprAddCollateToken(pParse, pExpr, &s, 0);
 84250  84327   }
 84251  84328   
 84252  84329   /*
 84253         -** Skip over any TK_COLLATE or TK_AS operators and any unlikely()
        84330  +** Skip over any TK_COLLATE operators and any unlikely()
 84254  84331   ** or likelihood() function at the root of an expression.
 84255  84332   */
 84256  84333   SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr *pExpr){
 84257  84334     while( pExpr && ExprHasProperty(pExpr, EP_Skip) ){
 84258  84335       if( ExprHasProperty(pExpr, EP_Unlikely) ){
 84259  84336         assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
 84260  84337         assert( pExpr->x.pList->nExpr>0 );
 84261  84338         assert( pExpr->op==TK_FUNCTION );
 84262  84339         pExpr = pExpr->x.pList->a[0].pExpr;
 84263  84340       }else{
 84264         -      assert( pExpr->op==TK_COLLATE || pExpr->op==TK_AS );
        84341  +      assert( pExpr->op==TK_COLLATE );
 84265  84342         pExpr = pExpr->pLeft;
 84266  84343       }
 84267  84344     }   
 84268  84345     return pExpr;
 84269  84346   }
 84270  84347   
 84271  84348   /*
................................................................................
 84588  84665   **
 84589  84666   ** Construct a new expression node and return a pointer to it.  Memory
 84590  84667   ** for this node and for the pToken argument is a single allocation
 84591  84668   ** obtained from sqlite3DbMalloc().  The calling function
 84592  84669   ** is responsible for making sure the node eventually gets freed.
 84593  84670   **
 84594  84671   ** If dequote is true, then the token (if it exists) is dequoted.
 84595         -** If dequote is false, no dequoting is performance.  The deQuote
        84672  +** If dequote is false, no dequoting is performed.  The deQuote
 84596  84673   ** parameter is ignored if pToken is NULL or if the token does not
 84597  84674   ** appear to be quoted.  If the quotes were of the form "..." (double-quotes)
 84598  84675   ** then the EP_DblQuoted flag is set on the expression node.
 84599  84676   **
 84600  84677   ** Special case:  If op==TK_INTEGER and pToken points to a string that
 84601  84678   ** can be translated into a 32-bit integer, then the token is not
 84602  84679   ** stored in u.zToken.  Instead, the integer values is written
................................................................................
 85189  85266       struct SrcList_item *pNewItem = &pNew->a[i];
 85190  85267       struct SrcList_item *pOldItem = &p->a[i];
 85191  85268       Table *pTab;
 85192  85269       pNewItem->pSchema = pOldItem->pSchema;
 85193  85270       pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase);
 85194  85271       pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
 85195  85272       pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias);
 85196         -    pNewItem->jointype = pOldItem->jointype;
        85273  +    pNewItem->fg = pOldItem->fg;
 85197  85274       pNewItem->iCursor = pOldItem->iCursor;
 85198  85275       pNewItem->addrFillSub = pOldItem->addrFillSub;
 85199  85276       pNewItem->regReturn = pOldItem->regReturn;
 85200         -    pNewItem->isCorrelated = pOldItem->isCorrelated;
 85201         -    pNewItem->viaCoroutine = pOldItem->viaCoroutine;
 85202         -    pNewItem->isRecursive = pOldItem->isRecursive;
 85203         -    pNewItem->zIndexedBy = sqlite3DbStrDup(db, pOldItem->zIndexedBy);
 85204         -    pNewItem->notIndexed = pOldItem->notIndexed;
 85205         -    pNewItem->pIndex = pOldItem->pIndex;
        85277  +    if( pNewItem->fg.isIndexedBy ){
        85278  +      pNewItem->u1.zIndexedBy = sqlite3DbStrDup(db, pOldItem->u1.zIndexedBy);
        85279  +    }
        85280  +    pNewItem->pIBIndex = pOldItem->pIBIndex;
        85281  +    if( pNewItem->fg.isTabFunc ){
        85282  +      pNewItem->u1.pFuncArg = 
        85283  +          sqlite3ExprListDup(db, pOldItem->u1.pFuncArg, flags);
        85284  +    }
 85206  85285       pTab = pNewItem->pTab = pOldItem->pTab;
 85207  85286       if( pTab ){
 85208  85287         pTab->nRef++;
 85209  85288       }
 85210  85289       pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
 85211  85290       pNewItem->pOn = sqlite3ExprDup(db, pOldItem->pOn, flags);
 85212  85291       pNewItem->pUsing = sqlite3IdListDup(db, pOldItem->pUsing);
................................................................................
 85312  85391   
 85313  85392   no_mem:     
 85314  85393     /* Avoid leaking memory if malloc has failed. */
 85315  85394     sqlite3ExprDelete(db, pExpr);
 85316  85395     sqlite3ExprListDelete(db, pList);
 85317  85396     return 0;
 85318  85397   }
        85398  +
        85399  +/*
        85400  +** Set the sort order for the last element on the given ExprList.
        85401  +*/
        85402  +SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList *p, int iSortOrder){
        85403  +  if( p==0 ) return;
        85404  +  assert( SQLITE_SO_UNDEFINED<0 && SQLITE_SO_ASC>=0 && SQLITE_SO_DESC>0 );
        85405  +  assert( p->nExpr>0 );
        85406  +  if( iSortOrder<0 ){
        85407  +    assert( p->a[p->nExpr-1].sortOrder==SQLITE_SO_ASC );
        85408  +    return;
        85409  +  }
        85410  +  p->a[p->nExpr-1].sortOrder = (u8)iSortOrder;
        85411  +}
 85319  85412   
 85320  85413   /*
 85321  85414   ** Set the ExprList.a[].zName element of the most recently added item
 85322  85415   ** on the expression list.
 85323  85416   **
 85324  85417   ** pList might be NULL following an OOM error.  But pName should never be
 85325  85418   ** NULL.  If a memory allocation fails, the pParse->db->mallocFailed flag
................................................................................
 86284  86377                             (void*)pColl, P4_COLLSEQ); VdbeCoverage(v);
 86285  86378           sqlite3VdbeChangeP5(v, affinity | SQLITE_JUMPIFNULL);
 86286  86379         }
 86287  86380         sqlite3ReleaseTempReg(pParse, regToFree);
 86288  86381       }
 86289  86382       if( regCkNull ){
 86290  86383         sqlite3VdbeAddOp2(v, OP_IsNull, regCkNull, destIfNull); VdbeCoverage(v);
 86291         -      sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
        86384  +      sqlite3VdbeGoto(v, destIfFalse);
 86292  86385       }
 86293  86386       sqlite3VdbeResolveLabel(v, labelOk);
 86294  86387       sqlite3ReleaseTempReg(pParse, regCkNull);
 86295  86388     }else{
 86296  86389     
 86297  86390       /* If the LHS is NULL, then the result is either false or NULL depending
 86298  86391       ** on whether the RHS is empty or not, respectively.
................................................................................
 86302  86395           /* Shortcut for the common case where the false and NULL outcomes are
 86303  86396           ** the same. */
 86304  86397           sqlite3VdbeAddOp2(v, OP_IsNull, r1, destIfNull); VdbeCoverage(v);
 86305  86398         }else{
 86306  86399           int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, r1); VdbeCoverage(v);
 86307  86400           sqlite3VdbeAddOp2(v, OP_Rewind, pExpr->iTable, destIfFalse);
 86308  86401           VdbeCoverage(v);
 86309         -        sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
        86402  +        sqlite3VdbeGoto(v, destIfNull);
 86310  86403           sqlite3VdbeJumpHere(v, addr1);
 86311  86404         }
 86312  86405       }
 86313  86406     
 86314  86407       if( eType==IN_INDEX_ROWID ){
 86315  86408         /* In this case, the RHS is the ROWID of table b-tree
 86316  86409         */
................................................................................
 86352  86445           ** answer is NULL if the RHS contains NULLs and the answer is
 86353  86446           ** FALSE if the RHS is NULL-free.
 86354  86447           */
 86355  86448           j1 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, r1, 1);
 86356  86449           VdbeCoverage(v);
 86357  86450           sqlite3VdbeAddOp2(v, OP_IsNull, rRhsHasNull, destIfNull);
 86358  86451           VdbeCoverage(v);
 86359         -        sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
        86452  +        sqlite3VdbeGoto(v, destIfFalse);
 86360  86453           sqlite3VdbeJumpHere(v, j1);
 86361  86454         }
 86362  86455       }
 86363  86456     }
 86364  86457     sqlite3ReleaseTempReg(pParse, r1);
 86365  86458     sqlite3ExprCachePop(pParse);
 86366  86459     VdbeComment((v, "end IN expr"));
................................................................................
 86570  86663     struct yColCache *p;
 86571  86664     for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
 86572  86665       if( p->iReg==iReg ){
 86573  86666         p->tempReg = 0;
 86574  86667       }
 86575  86668     }
 86576  86669   }
        86670  +
        86671  +/* Generate code that will load into register regOut a value that is
        86672  +** appropriate for the iIdxCol-th column of index pIdx.
        86673  +*/
        86674  +SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(
        86675  +  Parse *pParse,  /* The parsing context */
        86676  +  Index *pIdx,    /* The index whose column is to be loaded */
        86677  +  int iTabCur,    /* Cursor pointing to a table row */
        86678  +  int iIdxCol,    /* The column of the index to be loaded */
        86679  +  int regOut      /* Store the index column value in this register */
        86680  +){
        86681  +  i16 iTabCol = pIdx->aiColumn[iIdxCol];
        86682  +  if( iTabCol>=(-1) ){
        86683  +    sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pIdx->pTable, iTabCur,
        86684  +                                    iTabCol, regOut);
        86685  +    return;
        86686  +  }
        86687  +  assert( pIdx->aColExpr );
        86688  +  assert( pIdx->aColExpr->nExpr>iIdxCol );
        86689  +  pParse->iSelfTab = iTabCur;
        86690  +  sqlite3ExprCode(pParse, pIdx->aColExpr->a[iIdxCol].pExpr, regOut);
        86691  +}
 86577  86692   
 86578  86693   /*
 86579  86694   ** Generate code to extract the value of the iCol-th column of a table.
 86580  86695   */
 86581  86696   SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(
 86582  86697     Vdbe *v,        /* The VDBE under construction */
 86583  86698     Table *pTab,    /* The table containing the value */
................................................................................
 86756  86871         int iTab = pExpr->iTable;
 86757  86872         if( iTab<0 ){
 86758  86873           if( pParse->ckBase>0 ){
 86759  86874             /* Generating CHECK constraints or inserting into partial index */
 86760  86875             inReg = pExpr->iColumn + pParse->ckBase;
 86761  86876             break;
 86762  86877           }else{
 86763         -          /* Deleting from a partial index */
 86764         -          iTab = pParse->iPartIdxTab;
        86878  +          /* Coding an expression that is part of an index where column names
        86879  +          ** in the index refer to the table to which the index belongs */
        86880  +          iTab = pParse->iSelfTab;
 86765  86881           }
 86766  86882         }
 86767  86883         inReg = sqlite3ExprCodeGetColumn(pParse, pExpr->pTab,
 86768  86884                                  pExpr->iColumn, iTab, target,
 86769  86885                                  pExpr->op2);
 86770  86886         break;
 86771  86887       }
................................................................................
 86778  86894         assert( !ExprHasProperty(pExpr, EP_IntValue) );
 86779  86895         codeReal(v, pExpr->u.zToken, 0, target);
 86780  86896         break;
 86781  86897       }
 86782  86898   #endif
 86783  86899       case TK_STRING: {
 86784  86900         assert( !ExprHasProperty(pExpr, EP_IntValue) );
 86785         -      sqlite3VdbeAddOp4(v, OP_String8, 0, target, 0, pExpr->u.zToken, 0);
        86901  +      sqlite3VdbeLoadString(v, target, pExpr->u.zToken);
 86786  86902         break;
 86787  86903       }
 86788  86904       case TK_NULL: {
 86789  86905         sqlite3VdbeAddOp2(v, OP_Null, 0, target);
 86790  86906         break;
 86791  86907       }
 86792  86908   #ifndef SQLITE_OMIT_BLOB_LITERAL
................................................................................
 86817  86933         }
 86818  86934         break;
 86819  86935       }
 86820  86936       case TK_REGISTER: {
 86821  86937         inReg = pExpr->iTable;
 86822  86938         break;
 86823  86939       }
 86824         -    case TK_AS: {
 86825         -      inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
 86826         -      break;
 86827         -    }
 86828  86940   #ifndef SQLITE_OMIT_CAST
 86829  86941       case TK_CAST: {
 86830  86942         /* Expressions of the form:   CAST(pLeft AS token) */
 86831  86943         inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
 86832  86944         if( inReg!=target ){
 86833  86945           sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
 86834  86946           inReg = target;
................................................................................
 87051  87163               testcase( pDef->funcFlags & OPFLAG_LENGTHARG );
 87052  87164               pFarg->a[0].pExpr->op2 = 
 87053  87165                     pDef->funcFlags & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG);
 87054  87166             }
 87055  87167           }
 87056  87168   
 87057  87169           sqlite3ExprCachePush(pParse);     /* Ticket 2ea2425d34be */
 87058         -        sqlite3ExprCodeExprList(pParse, pFarg, r1,
        87170  +        sqlite3ExprCodeExprList(pParse, pFarg, r1, 0,
 87059  87171                                   SQLITE_ECEL_DUP|SQLITE_ECEL_FACTOR);
 87060  87172           sqlite3ExprCachePop(pParse);      /* Ticket 2ea2425d34be */
 87061  87173         }else{
 87062  87174           r1 = 0;
 87063  87175         }
 87064  87176   #ifndef SQLITE_OMIT_VIRTUALTABLE
 87065  87177         /* Possibly overload the function if the first argument is
................................................................................
 87275  87387             pTest = aListelem[i].pExpr;
 87276  87388           }
 87277  87389           nextCase = sqlite3VdbeMakeLabel(v);
 87278  87390           testcase( pTest->op==TK_COLUMN );
 87279  87391           sqlite3ExprIfFalse(pParse, pTest, nextCase, SQLITE_JUMPIFNULL);
 87280  87392           testcase( aListelem[i+1].pExpr->op==TK_COLUMN );
 87281  87393           sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
 87282         -        sqlite3VdbeAddOp2(v, OP_Goto, 0, endLabel);
        87394  +        sqlite3VdbeGoto(v, endLabel);
 87283  87395           sqlite3ExprCachePop(pParse);
 87284  87396           sqlite3VdbeResolveLabel(v, nextCase);
 87285  87397         }
 87286  87398         if( (nExpr&1)!=0 ){
 87287  87399           sqlite3ExprCachePush(pParse);
 87288  87400           sqlite3ExprCode(pParse, pEList->a[nExpr-1].pExpr, target);
 87289  87401           sqlite3ExprCachePop(pParse);
................................................................................
 87467  87579   ** The SQLITE_ECEL_FACTOR argument allows constant arguments to be
 87468  87580   ** factored out into initialization code.
 87469  87581   */
 87470  87582   SQLITE_PRIVATE int sqlite3ExprCodeExprList(
 87471  87583     Parse *pParse,     /* Parsing context */
 87472  87584     ExprList *pList,   /* The expression list to be coded */
 87473  87585     int target,        /* Where to write results */
        87586  +  int srcReg,        /* Source registers if SQLITE_ECEL_REF */
 87474  87587     u8 flags           /* SQLITE_ECEL_* flags */
 87475  87588   ){
 87476  87589     struct ExprList_item *pItem;
 87477         -  int i, n;
        87590  +  int i, j, n;
 87478  87591     u8 copyOp = (flags & SQLITE_ECEL_DUP) ? OP_Copy : OP_SCopy;
        87592  +  Vdbe *v = pParse->pVdbe;
 87479  87593     assert( pList!=0 );
 87480  87594     assert( target>0 );
 87481  87595     assert( pParse->pVdbe!=0 );  /* Never gets this far otherwise */
 87482  87596     n = pList->nExpr;
 87483  87597     if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
 87484  87598     for(pItem=pList->a, i=0; i<n; i++, pItem++){
 87485  87599       Expr *pExpr = pItem->pExpr;
 87486         -    if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
        87600  +    if( (flags & SQLITE_ECEL_REF)!=0 && (j = pList->a[i].u.x.iOrderByCol)>0 ){
        87601  +      sqlite3VdbeAddOp2(v, copyOp, j+srcReg-1, target+i);
        87602  +    }else if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
 87487  87603         sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0);
 87488  87604       }else{
 87489  87605         int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
 87490  87606         if( inReg!=target+i ){
 87491  87607           VdbeOp *pOp;
 87492         -        Vdbe *v = pParse->pVdbe;
 87493  87608           if( copyOp==OP_Copy
 87494  87609            && (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy
 87495  87610            && pOp->p1+pOp->p3+1==inReg
 87496  87611            && pOp->p2+pOp->p3+1==target+i
 87497  87612           ){
 87498  87613             pOp->p3++;
 87499  87614           }else{
................................................................................
 87662  87777         break;
 87663  87778       }
 87664  87779   #ifndef SQLITE_OMIT_SUBQUERY
 87665  87780       case TK_IN: {
 87666  87781         int destIfFalse = sqlite3VdbeMakeLabel(v);
 87667  87782         int destIfNull = jumpIfNull ? dest : destIfFalse;
 87668  87783         sqlite3ExprCodeIN(pParse, pExpr, destIfFalse, destIfNull);
 87669         -      sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
        87784  +      sqlite3VdbeGoto(v, dest);
 87670  87785         sqlite3VdbeResolveLabel(v, destIfFalse);
 87671  87786         break;
 87672  87787       }
 87673  87788   #endif
 87674  87789       default: {
 87675  87790         if( exprAlwaysTrue(pExpr) ){
 87676         -        sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
        87791  +        sqlite3VdbeGoto(v, dest);
 87677  87792         }else if( exprAlwaysFalse(pExpr) ){
 87678  87793           /* No-op */
 87679  87794         }else{
 87680  87795           r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
 87681  87796           sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
 87682  87797           VdbeCoverage(v);
 87683  87798           testcase( regFree1==0 );
................................................................................
 87825  87940           sqlite3VdbeResolveLabel(v, destIfNull);
 87826  87941         }
 87827  87942         break;
 87828  87943       }
 87829  87944   #endif
 87830  87945       default: {
 87831  87946         if( exprAlwaysFalse(pExpr) ){
 87832         -        sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
        87947  +        sqlite3VdbeGoto(v, dest);
 87833  87948         }else if( exprAlwaysTrue(pExpr) ){
 87834  87949           /* no-op */
 87835  87950         }else{
 87836  87951           r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
 87837  87952           sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
 87838  87953           VdbeCoverage(v);
 87839  87954           testcase( regFree1==0 );
................................................................................
 87901  88016       }
 87902  88017       if( pB->op==TK_COLLATE && sqlite3ExprCompare(pA, pB->pLeft, iTab)<2 ){
 87903  88018         return 1;
 87904  88019       }
 87905  88020       return 2;
 87906  88021     }
 87907  88022     if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken ){
 87908         -    if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
        88023  +    if( pA->op==TK_FUNCTION ){
        88024  +      if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
        88025  +    }else if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
 87909  88026         return pA->op==TK_COLLATE ? 1 : 2;
 87910  88027       }
 87911  88028     }
 87912  88029     if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;
 87913  88030     if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
 87914  88031       if( combinedFlags & EP_xIsSelect ) return 2;
 87915  88032       if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
................................................................................
 88809  88926     ** one is defined. The xRename() callback will modify the names
 88810  88927     ** of any resources used by the v-table implementation (including other
 88811  88928     ** SQLite tables) that are identified by the name of the virtual table.
 88812  88929     */
 88813  88930   #ifndef SQLITE_OMIT_VIRTUALTABLE
 88814  88931     if( pVTab ){
 88815  88932       int i = ++pParse->nMem;
 88816         -    sqlite3VdbeAddOp4(v, OP_String8, 0, i, 0, zName, 0);
        88933  +    sqlite3VdbeLoadString(v, i, zName);
 88817  88934       sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
 88818  88935       sqlite3MayAbort(pParse);
 88819  88936     }
 88820  88937   #endif
 88821  88938   
 88822  88939     /* figure out how many UTF-8 characters are in zName */
 88823  88940     zTabName = pTab->zName;
................................................................................
 90167  90284     ** to use for scanning indexes (iIdxCur). No index cursor is opened at
 90168  90285     ** this time though.  */
 90169  90286     sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
 90170  90287     iTabCur = iTab++;
 90171  90288     iIdxCur = iTab++;
 90172  90289     pParse->nTab = MAX(pParse->nTab, iTab);
 90173  90290     sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
 90174         -  sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
        90291  +  sqlite3VdbeLoadString(v, regTabname, pTab->zName);
 90175  90292   
 90176  90293     for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
 90177  90294       int nCol;                     /* Number of columns in pIdx. "N" */
 90178  90295       int addrRewind;               /* Address of "OP_Rewind iIdxCur" */
 90179  90296       int addrNextRow;              /* Address of "next_row:" */
 90180  90297       const char *zIdxName;         /* Name of the index */
 90181  90298       int nColTest;                 /* Number of columns to test for changes */
................................................................................
 90189  90306       }else{
 90190  90307         nCol = pIdx->nColumn;
 90191  90308         zIdxName = pIdx->zName;
 90192  90309         nColTest = pIdx->uniqNotNull ? pIdx->nKeyCol-1 : nCol-1;
 90193  90310       }
 90194  90311   
 90195  90312       /* Populate the register containing the index name. */
 90196         -    sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, zIdxName, 0);
        90313  +    sqlite3VdbeLoadString(v, regIdxname, zIdxName);
 90197  90314       VdbeComment((v, "Analysis for %s.%s", pTab->zName, zIdxName));
 90198  90315   
 90199  90316       /*
 90200  90317       ** Pseudo-code for loop that calls stat_push():
 90201  90318       **
 90202  90319       **   Rewind csr
 90203  90320       **   if eof(csr) goto end_of_scan;
................................................................................
 90303  90420           sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp);
 90304  90421           aGotoChng[i] = 
 90305  90422           sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
 90306  90423           sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
 90307  90424           VdbeCoverage(v);
 90308  90425         }
 90309  90426         sqlite3VdbeAddOp2(v, OP_Integer, nColTest, regChng);
 90310         -      sqlite3VdbeAddOp2(v, OP_Goto, 0, endDistinctTest);
        90427  +      sqlite3VdbeGoto(v, endDistinctTest);
 90311  90428     
 90312  90429     
 90313  90430         /*
 90314  90431         **  chng_addr_0:
 90315  90432         **   regPrev(0) = idx(0)
 90316  90433         **  chng_addr_1:
 90317  90434         **   regPrev(1) = idx(1)
................................................................................
 90339  90456         sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, regRowid);
 90340  90457       }else{
 90341  90458         Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
 90342  90459         int j, k, regKey;
 90343  90460         regKey = sqlite3GetTempRange(pParse, pPk->nKeyCol);
 90344  90461         for(j=0; j<pPk->nKeyCol; j++){
 90345  90462           k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
        90463  +        assert( k>=0 && k<pTab->nCol );
 90346  90464           sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, regKey+j);
 90347  90465           VdbeComment((v, "%s", pTab->aCol[pPk->aiColumn[j]].zName));
 90348  90466         }
 90349  90467         sqlite3VdbeAddOp3(v, OP_MakeRecord, regKey, pPk->nKeyCol, regRowid);
 90350  90468         sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol);
 90351  90469       }
 90352  90470   #endif
................................................................................
 90388  90506         callStatGet(v, regStat4, STAT_GET_NDLT, regDLt);
 90389  90507         sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0);
 90390  90508         /* We know that the regSampleRowid row exists because it was read by
 90391  90509         ** the previous loop.  Thus the not-found jump of seekOp will never
 90392  90510         ** be taken */
 90393  90511         VdbeCoverageNeverTaken(v);
 90394  90512   #ifdef SQLITE_ENABLE_STAT3
 90395         -      sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, 
 90396         -                                      pIdx->aiColumn[0], regSample);
        90513  +      sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iTabCur, 0, regSample);
 90397  90514   #else
 90398  90515         for(i=0; i<nCol; i++){
 90399         -        i16 iCol = pIdx->aiColumn[i];
 90400         -        sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, iCol, regCol+i);
        90516  +        sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iTabCur, i, regCol+i);
 90401  90517         }
 90402  90518         sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, nCol, regSample);
 90403  90519   #endif
 90404  90520         sqlite3VdbeAddOp3(v, OP_MakeRecord, regTabname, 6, regTemp);
 90405  90521         sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regNewRowid);
 90406  90522         sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regTemp, regNewRowid);
 90407  90523         sqlite3VdbeAddOp2(v, OP_Goto, 1, addrNext); /* P1==1 for end-of-loop */
................................................................................
 92119  92235           pParse->okConstFactor = 0;
 92120  92236           for(i=0; i<pEL->nExpr; i++){
 92121  92237             sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
 92122  92238           }
 92123  92239         }
 92124  92240   
 92125  92241         /* Finally, jump back to the beginning of the executable code. */
 92126         -      sqlite3VdbeAddOp2(v, OP_Goto, 0, 1);
        92242  +      sqlite3VdbeGoto(v, 1);
 92127  92243       }
 92128  92244     }
 92129  92245   
 92130  92246   
 92131  92247     /* Get the VDBE program ready for execution
 92132  92248     */
 92133  92249     if( v && pParse->nErr==0 && !db->mallocFailed ){
................................................................................
 92254  92370     if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
 92255  92371       return 0;
 92256  92372     }
 92257  92373   
 92258  92374     p = sqlite3FindTable(pParse->db, zName, zDbase);
 92259  92375     if( p==0 ){
 92260  92376       const char *zMsg = isView ? "no such view" : "no such table";
        92377  +#ifndef SQLITE_OMIT_VIRTUALTABLE
        92378  +    if( sqlite3FindDbName(pParse->db, zDbase)<1 ){
        92379  +      /* If zName is the not the name of a table in the schema created using
        92380  +      ** CREATE, then check to see if it is the name of an virtual table that
        92381  +      ** can be an eponymous virtual table. */
        92382  +      Module *pMod = (Module*)sqlite3HashFind(&pParse->db->aModule, zName);
        92383  +      if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){
        92384  +        return pMod->pEpoTab;
        92385  +      }
        92386  +    }
        92387  +#endif
 92261  92388       if( zDbase ){
 92262  92389         sqlite3ErrorMsg(pParse, "%s: %s.%s", zMsg, zDbase, zName);
 92263  92390       }else{
 92264  92391         sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName);
 92265  92392       }
 92266  92393       pParse->checkSchema = 1;
 92267  92394     }
................................................................................
 92332  92459   ** Reclaim the memory used by an index
 92333  92460   */
 92334  92461   static void freeIndex(sqlite3 *db, Index *p){
 92335  92462   #ifndef SQLITE_OMIT_ANALYZE
 92336  92463     sqlite3DeleteIndexSamples(db, p);
 92337  92464   #endif
 92338  92465     sqlite3ExprDelete(db, p->pPartIdxWhere);
        92466  +  sqlite3ExprListDelete(db, p->aColExpr);
 92339  92467     sqlite3DbFree(db, p->zColAff);
 92340  92468     if( p->isResized ) sqlite3DbFree(db, p->azColl);
 92341  92469   #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
 92342  92470     sqlite3_free(p->aiRowEst);
 92343  92471   #endif
 92344  92472     sqlite3DbFree(db, p);
 92345  92473   }
................................................................................
 92458  92586     db->flags &= ~SQLITE_InternChanges;
 92459  92587   }
 92460  92588   
 92461  92589   /*
 92462  92590   ** Delete memory allocated for the column names of a table or view (the
 92463  92591   ** Table.aCol[] array).
 92464  92592   */
 92465         -static void sqliteDeleteColumnNames(sqlite3 *db, Table *pTable){
        92593  +SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3 *db, Table *pTable){
 92466  92594     int i;
 92467  92595     Column *pCol;
 92468  92596     assert( pTable!=0 );
 92469  92597     if( (pCol = pTable->aCol)!=0 ){
 92470  92598       for(i=0; i<pTable->nCol; i++, pCol++){
 92471  92599         sqlite3DbFree(db, pCol->zName);
 92472  92600         sqlite3ExprDelete(db, pCol->pDflt);
................................................................................
 92525  92653     }
 92526  92654   
 92527  92655     /* Delete any foreign keys attached to this table. */
 92528  92656     sqlite3FkDelete(db, pTable);
 92529  92657   
 92530  92658     /* Delete the Table structure itself.
 92531  92659     */
 92532         -  sqliteDeleteColumnNames(db, pTable);
        92660  +  sqlite3DeleteColumnNames(db, pTable);
 92533  92661     sqlite3DbFree(db, pTable->zName);
 92534  92662     sqlite3DbFree(db, pTable->zColAff);
 92535  92663     sqlite3SelectDelete(db, pTable->pSelect);
 92536         -#ifndef SQLITE_OMIT_CHECK
 92537  92664     sqlite3ExprListDelete(db, pTable->pCheck);
 92538         -#endif
 92539  92665   #ifndef SQLITE_OMIT_VIRTUALTABLE
 92540  92666     sqlite3VtabClear(db, pTable);
 92541  92667   #endif
 92542  92668     sqlite3DbFree(db, pTable);
 92543  92669   
 92544  92670     /* Verify that no lookaside memory was used by schema tables */
 92545  92671     assert( nLookaside==0 || nLookaside==db->lookaside.nOut );
................................................................................
 92874  93000     ** indices.  Hence, the record number for the table must be allocated
 92875  93001     ** now.
 92876  93002     */
 92877  93003     if( !db->init.busy && (v = sqlite3GetVdbe(pParse))!=0 ){
 92878  93004       int j1;
 92879  93005       int fileFormat;
 92880  93006       int reg1, reg2, reg3;
        93007  +    /* nullRow[] is an OP_Record encoding of a row containing 5 NULLs */
        93008  +    static const char nullRow[] = { 6, 0, 0, 0, 0, 0 };
 92881  93009       sqlite3BeginWriteOperation(pParse, 1, iDb);
 92882  93010   
 92883  93011   #ifndef SQLITE_OMIT_VIRTUALTABLE
 92884  93012       if( isVirtual ){
 92885  93013         sqlite3VdbeAddOp0(v, OP_VBegin);
 92886  93014       }
 92887  93015   #endif
................................................................................
 92918  93046       }else
 92919  93047   #endif
 92920  93048       {
 92921  93049         pParse->addrCrTab = sqlite3VdbeAddOp2(v, OP_CreateTable, iDb, reg2);
 92922  93050       }
 92923  93051       sqlite3OpenMasterTable(pParse, iDb);
 92924  93052       sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
 92925         -    sqlite3VdbeAddOp2(v, OP_Null, 0, reg3);
        93053  +    sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
 92926  93054       sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
 92927  93055       sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
 92928  93056       sqlite3VdbeAddOp0(v, OP_Close);
 92929  93057     }
 92930  93058   
 92931  93059     /* Normal (non-error) return. */
 92932  93060     return;
................................................................................
 93199  93327       iCol = pTab->nCol - 1;
 93200  93328       pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
 93201  93329       zType = pTab->aCol[iCol].zType;
 93202  93330       nTerm = 1;
 93203  93331     }else{
 93204  93332       nTerm = pList->nExpr;
 93205  93333       for(i=0; i<nTerm; i++){
 93206         -      for(iCol=0; iCol<pTab->nCol; iCol++){
 93207         -        if( sqlite3StrICmp(pList->a[i].zName, pTab->aCol[iCol].zName)==0 ){
 93208         -          pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
 93209         -          zType = pTab->aCol[iCol].zType;
 93210         -          break;
        93334  +      Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
        93335  +      assert( pCExpr!=0 );
        93336  +      if( pCExpr->op==TK_ID ){
        93337  +        const char *zCName = pCExpr->u.zToken;
        93338  +        for(iCol=0; iCol<pTab->nCol; iCol++){
        93339  +          if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zName)==0 ){
        93340  +            pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
        93341  +            zType = pTab->aCol[iCol].zType;
        93342  +            break;
        93343  +          }
 93211  93344           }
 93212  93345         }
 93213  93346       }
 93214  93347     }
 93215  93348     if( nTerm==1
 93216  93349      && zType && sqlite3StrICmp(zType, "INTEGER")==0
 93217         -   && sortOrder==SQLITE_SO_ASC
        93350  +   && sortOrder!=SQLITE_SO_DESC
 93218  93351     ){
 93219  93352       pTab->iPKey = iCol;
 93220  93353       pTab->keyConf = (u8)onError;
 93221  93354       assert( autoInc==0 || autoInc==1 );
 93222  93355       pTab->tabFlags |= autoInc*TF_Autoincrement;
 93223  93356       if( pList ) pParse->iPkSortOrder = pList->a[0].sortOrder;
 93224  93357     }else if( autoInc ){
................................................................................
 93577  93710   
 93578  93711     /* Convert the OP_CreateTable opcode that would normally create the
 93579  93712     ** root-page for the table into an OP_CreateIndex opcode.  The index
 93580  93713     ** created will become the PRIMARY KEY index.
 93581  93714     */
 93582  93715     if( pParse->addrCrTab ){
 93583  93716       assert( v );
 93584         -    sqlite3VdbeGetOp(v, pParse->addrCrTab)->opcode = OP_CreateIndex;
        93717  +    sqlite3VdbeChangeOpcode(v, pParse->addrCrTab, OP_CreateIndex);
 93585  93718     }
 93586  93719   
 93587  93720     /* Locate the PRIMARY KEY index.  Or, if this table was originally
 93588  93721     ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index. 
 93589  93722     */
 93590  93723     if( pTab->iPKey>=0 ){
 93591  93724       ExprList *pList;
 93592         -    pList = sqlite3ExprListAppend(pParse, 0, 0);
        93725  +    Token ipkToken;
        93726  +    ipkToken.z = pTab->aCol[pTab->iPKey].zName;
        93727  +    ipkToken.n = sqlite3Strlen30(ipkToken.z);
        93728  +    pList = sqlite3ExprListAppend(pParse, 0, 
        93729  +                  sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
 93593  93730       if( pList==0 ) return;
 93594         -    pList->a[0].zName = sqlite3DbStrDup(pParse->db,
 93595         -                                        pTab->aCol[pTab->iPKey].zName);
 93596  93731       pList->a[0].sortOrder = pParse->iPkSortOrder;
 93597  93732       assert( pParse->pNewTable==pTab );
 93598  93733       pPk = sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0);
 93599  93734       if( pPk==0 ) return;
 93600  93735       pPk->idxType = SQLITE_IDXTYPE_PRIMARYKEY;
 93601  93736       pTab->iPKey = -1;
 93602  93737     }else{
................................................................................
 93604  93739   
 93605  93740       /* Bypass the creation of the PRIMARY KEY btree and the sqlite_master
 93606  93741       ** table entry. This is only required if currently generating VDBE
 93607  93742       ** code for a CREATE TABLE (not when parsing one as part of reading
 93608  93743       ** a database schema).  */
 93609  93744       if( v ){
 93610  93745         assert( db->init.busy==0 );
 93611         -      sqlite3VdbeGetOp(v, pPk->tnum)->opcode = OP_Goto;
        93746  +      sqlite3VdbeChangeOpcode(v, pPk->tnum, OP_Goto);
 93612  93747       }
 93613  93748   
 93614  93749       /*
 93615  93750       ** Remove all redundant columns from the PRIMARY KEY.  For example, change
 93616  93751       ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)".  Later
 93617  93752       ** code assumes the PRIMARY KEY contains no repeated columns.
 93618  93753       */
................................................................................
 93714  93849     Select *pSelect         /* Select from a "CREATE ... AS SELECT" */
 93715  93850   ){
 93716  93851     Table *p;                 /* The new table */
 93717  93852     sqlite3 *db = pParse->db; /* The database connection */
 93718  93853     int iDb;                  /* Database in which the table lives */
 93719  93854     Index *pIdx;              /* An implied index of the table */
 93720  93855   
 93721         -  if( (pEnd==0 && pSelect==0) || db->mallocFailed ){
        93856  +  if( pEnd==0 && pSelect==0 ){
 93722  93857       return;
 93723  93858     }
        93859  +  assert( !db->mallocFailed );
 93724  93860     p = pParse->pNewTable;
 93725  93861     if( p==0 ) return;
 93726  93862   
 93727  93863     assert( !db->init.busy || !pSelect );
 93728  93864   
 93729  93865     /* If the db->init.busy is 1 it means we are reading the SQL off the
 93730  93866     ** "sqlite_master" or "sqlite_temp_master" table on the disk.
................................................................................
 93847  93983         sqlite3DeleteTable(db, pSelTab);
 93848  93984         addrInsLoop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
 93849  93985         VdbeCoverage(v);
 93850  93986         sqlite3VdbeAddOp3(v, OP_MakeRecord, dest.iSdst, dest.nSdst, regRec);
 93851  93987         sqlite3TableAffinity(v, p, 0);
 93852  93988         sqlite3VdbeAddOp2(v, OP_NewRowid, 1, regRowid);
 93853  93989         sqlite3VdbeAddOp3(v, OP_Insert, 1, regRec, regRowid);
 93854         -      sqlite3VdbeAddOp2(v, OP_Goto, 0, addrInsLoop);
        93990  +      sqlite3VdbeGoto(v, addrInsLoop);
 93855  93991         sqlite3VdbeJumpHere(v, addrInsLoop);
 93856  93992         sqlite3VdbeAddOp1(v, OP_Close, 1);
 93857  93993       }
 93858  93994   
 93859  93995       /* Compute the complete text of the CREATE statement */
 93860  93996       if( pSelect ){
 93861  93997         zStmt = createTableStmt(db, p);
................................................................................
 93944  94080   ** The parser calls this routine in order to create a new VIEW
 93945  94081   */
 93946  94082   SQLITE_PRIVATE void sqlite3CreateView(
 93947  94083     Parse *pParse,     /* The parsing context */
 93948  94084     Token *pBegin,     /* The CREATE token that begins the statement */
 93949  94085     Token *pName1,     /* The token that holds the name of the view */
 93950  94086     Token *pName2,     /* The token that holds the name of the view */
        94087  +  ExprList *pCNames, /* Optional list of view column names */
 93951  94088     Select *pSelect,   /* A SELECT statement that will become the new view */
 93952  94089     int isTemp,        /* TRUE for a TEMPORARY view */
 93953  94090     int noErr          /* Suppress error messages if VIEW already exists */
 93954  94091   ){
 93955  94092     Table *p;
 93956  94093     int n;
 93957  94094     const char *z;
................................................................................
 93964  94101     if( pParse->nVar>0 ){
 93965  94102       sqlite3ErrorMsg(pParse, "parameters are not allowed in views");
 93966  94103       sqlite3SelectDelete(db, pSelect);
 93967  94104       return;
 93968  94105     }
 93969  94106     sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr);
 93970  94107     p = pParse->pNewTable;
 93971         -  if( p==0 || pParse->nErr ){
 93972         -    sqlite3SelectDelete(db, pSelect);
 93973         -    return;
 93974         -  }
        94108  +  if( p==0 || pParse->nErr ) goto create_view_fail;
 93975  94109     sqlite3TwoPartName(pParse, pName1, pName2, &pName);
 93976  94110     iDb = sqlite3SchemaToIndex(db, p->pSchema);
 93977  94111     sqlite3FixInit(&sFix, pParse, iDb, "view", pName);
 93978         -  if( sqlite3FixSelect(&sFix, pSelect) ){
 93979         -    sqlite3SelectDelete(db, pSelect);
 93980         -    return;
 93981         -  }
        94112  +  if( sqlite3FixSelect(&sFix, pSelect) ) goto create_view_fail;
 93982  94113   
 93983  94114     /* Make a copy of the entire SELECT statement that defines the view.
 93984  94115     ** This will force all the Expr.token.z values to be dynamically
 93985  94116     ** allocated rather than point to the input string - which means that
 93986  94117     ** they will persist after the current sqlite3_exec() call returns.
 93987  94118     */
 93988  94119     p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
 93989         -  sqlite3SelectDelete(db, pSelect);
 93990         -  if( db->mallocFailed ){
 93991         -    return;
 93992         -  }
 93993         -  if( !db->init.busy ){
 93994         -    sqlite3ViewGetColumnNames(pParse, p);
 93995         -  }
        94120  +  p->pCheck = sqlite3ExprListDup(db, pCNames, EXPRDUP_REDUCE);
        94121  +  if( db->mallocFailed ) goto create_view_fail;
 93996  94122   
 93997  94123     /* Locate the end of the CREATE VIEW statement.  Make sEnd point to
 93998  94124     ** the end.
 93999  94125     */
 94000  94126     sEnd = pParse->sLastToken;
 94001         -  if( ALWAYS(sEnd.z[0]!=0) && sEnd.z[0]!=';' ){
        94127  +  assert( sEnd.z[0]!=0 );
        94128  +  if( sEnd.z[0]!=';' ){
 94002  94129       sEnd.z += sEnd.n;
 94003  94130     }
 94004  94131     sEnd.n = 0;
 94005  94132     n = (int)(sEnd.z - pBegin->z);
        94133  +  assert( n>0 );
 94006  94134     z = pBegin->z;
 94007         -  while( ALWAYS(n>0) && sqlite3Isspace(z[n-1]) ){ n--; }
        94135  +  while( sqlite3Isspace(z[n-1]) ){ n--; }
 94008  94136     sEnd.z = &z[n-1];
 94009  94137     sEnd.n = 1;
 94010  94138   
 94011  94139     /* Use sqlite3EndTable() to add the view to the SQLITE_MASTER table */
 94012  94140     sqlite3EndTable(pParse, 0, &sEnd, 0, 0);
        94141  +
        94142  +create_view_fail:
        94143  +  sqlite3SelectDelete(db, pSelect);
        94144  +  sqlite3ExprListDelete(db, pCNames);
 94013  94145     return;
 94014  94146   }
 94015  94147   #endif /* SQLITE_OMIT_VIEW */
 94016  94148   
 94017  94149   #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
 94018  94150   /*
 94019  94151   ** The Table structure pTable is really a VIEW.  Fill in the names of
................................................................................
 94023  94155   SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
 94024  94156     Table *pSelTab;   /* A fake table from which we get the result set */
 94025  94157     Select *pSel;     /* Copy of the SELECT that implements the view */
 94026  94158     int nErr = 0;     /* Number of errors encountered */
 94027  94159     int n;            /* Temporarily holds the number of cursors assigned */
 94028  94160     sqlite3 *db = pParse->db;  /* Database connection for malloc errors */
 94029  94161     sqlite3_xauth xAuth;       /* Saved xAuth pointer */
        94162  +  u8 bEnabledLA;             /* Saved db->lookaside.bEnabled state */
 94030  94163   
 94031  94164     assert( pTable );
 94032  94165   
 94033  94166   #ifndef SQLITE_OMIT_VIRTUALTABLE
 94034  94167     if( sqlite3VtabCallConnect(pParse, pTable) ){
 94035  94168       return SQLITE_ERROR;
 94036  94169     }
................................................................................
 94068  94201     ** Note that the call to sqlite3ResultSetOfSelect() will expand any
 94069  94202     ** "*" elements in the results set of the view and will assign cursors
 94070  94203     ** to the elements of the FROM clause.  But we do not want these changes
 94071  94204     ** to be permanent.  So the computation is done on a copy of the SELECT
 94072  94205     ** statement that defines the view.
 94073  94206     */
 94074  94207     assert( pTable->pSelect );
 94075         -  pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
 94076         -  if( pSel ){
 94077         -    u8 enableLookaside = db->lookaside.bEnabled;
 94078         -    n = pParse->nTab;
 94079         -    sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
 94080         -    pTable->nCol = -1;
        94208  +  bEnabledLA = db->lookaside.bEnabled;
        94209  +  if( pTable->pCheck ){
 94081  94210       db->lookaside.bEnabled = 0;
 94082         -#ifndef SQLITE_OMIT_AUTHORIZATION
 94083         -    xAuth = db->xAuth;
 94084         -    db->xAuth = 0;
 94085         -    pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
 94086         -    db->xAuth = xAuth;
 94087         -#else
 94088         -    pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
 94089         -#endif
 94090         -    db->lookaside.bEnabled = enableLookaside;
 94091         -    pParse->nTab = n;
 94092         -    if( pSelTab ){
 94093         -      assert( pTable->aCol==0 );
 94094         -      pTable->nCol = pSelTab->nCol;
 94095         -      pTable->aCol = pSelTab->aCol;
 94096         -      pSelTab->nCol = 0;
 94097         -      pSelTab->aCol = 0;
 94098         -      sqlite3DeleteTable(db, pSelTab);
 94099         -      assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
 94100         -      pTable->pSchema->schemaFlags |= DB_UnresetViews;
 94101         -    }else{
 94102         -      pTable->nCol = 0;
        94211  +    sqlite3ColumnsFromExprList(pParse, pTable->pCheck, 
        94212  +                               &pTable->nCol, &pTable->aCol);
        94213  +  }else{
        94214  +    pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
        94215  +    if( pSel ){
        94216  +      n = pParse->nTab;
        94217  +      sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
        94218  +      pTable->nCol = -1;
        94219  +      db->lookaside.bEnabled = 0;
        94220  +#ifndef SQLITE_OMIT_AUTHORIZATION
        94221  +      xAuth = db->xAuth;
        94222  +      db->xAuth = 0;
        94223  +      pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
        94224  +      db->xAuth = xAuth;
        94225  +#else
        94226  +      pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
        94227  +#endif
        94228  +      pParse->nTab = n;
        94229  +      if( pSelTab ){
        94230  +        assert( pTable->aCol==0 );
        94231  +        pTable->nCol = pSelTab->nCol;
        94232  +        pTable->aCol = pSelTab->aCol;
        94233  +        pSelTab->nCol = 0;
        94234  +        pSelTab->aCol = 0;
        94235  +        sqlite3DeleteTable(db, pSelTab);
        94236  +        assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
        94237  +      }else{
        94238  +        pTable->nCol = 0;
        94239  +        nErr++;
        94240  +      }
        94241  +      sqlite3SelectDelete(db, pSel);
        94242  +    } else {
 94103  94243         nErr++;
 94104  94244       }
 94105         -    sqlite3SelectDelete(db, pSel);
 94106         -  } else {
 94107         -    nErr++;
 94108  94245     }
        94246  +  db->lookaside.bEnabled = bEnabledLA;
        94247  +  pTable->pSchema->schemaFlags |= DB_UnresetViews;
 94109  94248   #endif /* SQLITE_OMIT_VIEW */
 94110  94249     return nErr;  
 94111  94250   }
 94112  94251   #endif /* !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) */
 94113  94252   
 94114  94253   #ifndef SQLITE_OMIT_VIEW
 94115  94254   /*
................................................................................
 94118  94257   static void sqliteViewResetAll(sqlite3 *db, int idx){
 94119  94258     HashElem *i;
 94120  94259     assert( sqlite3SchemaMutexHeld(db, idx, 0) );
 94121  94260     if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
 94122  94261     for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
 94123  94262       Table *pTab = sqliteHashData(i);
 94124  94263       if( pTab->pSelect ){
 94125         -      sqliteDeleteColumnNames(db, pTab);
        94264  +      sqlite3DeleteColumnNames(db, pTab);
 94126  94265         pTab->aCol = 0;
 94127  94266         pTab->nCol = 0;
 94128  94267       }
 94129  94268     }
 94130  94269     DbClearProperty(db, idx, DB_UnresetViews);
 94131  94270   }
 94132  94271   #else
................................................................................
 94673  94812                       (char *)pKey, P4_KEYINFO);
 94674  94813     sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
 94675  94814   
 94676  94815     addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v);
 94677  94816     assert( pKey!=0 || db->mallocFailed || pParse->nErr );
 94678  94817     if( IsUniqueIndex(pIndex) && pKey!=0 ){
 94679  94818       int j2 = sqlite3VdbeCurrentAddr(v) + 3;
 94680         -    sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
        94819  +    sqlite3VdbeGoto(v, j2);
 94681  94820       addr2 = sqlite3VdbeCurrentAddr(v);
 94682  94821       sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
 94683  94822                            pIndex->nKeyCol); VdbeCoverage(v);
 94684  94823       sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
 94685  94824     }else{
 94686  94825       addr2 = sqlite3VdbeCurrentAddr(v);
 94687  94826     }
................................................................................
 94728  94867       p->aSortOrder = (u8*)pExtra;
 94729  94868       p->nColumn = nCol;
 94730  94869       p->nKeyCol = nCol - 1;
 94731  94870       *ppExtra = ((char*)p) + nByte;
 94732  94871     }
 94733  94872     return p;
 94734  94873   }
        94874  +
        94875  +/*
        94876  +** Backwards Compatibility Hack:
        94877  +** 
        94878  +** Historical versions of SQLite accepted strings as column names in
        94879  +** indexes and PRIMARY KEY constraints and in UNIQUE constraints.  Example:
        94880  +**
        94881  +**     CREATE TABLE xyz(a,b,c,d,e,PRIMARY KEY('a'),UNIQUE('b','c' COLLATE trim)
        94882  +**     CREATE INDEX abc ON xyz('c','d' DESC,'e' COLLATE nocase DESC);
        94883  +**
        94884  +** This is goofy.  But to preserve backwards compatibility we continue to
        94885  +** accept it.  This routine does the necessary conversion.  It converts
        94886  +** the expression given in its argument from a TK_STRING into a TK_ID
        94887  +** if the expression is just a TK_STRING with an optional COLLATE clause.
        94888  +** If the epxression is anything other than TK_STRING, the expression is
        94889  +** unchanged.
        94890  +*/
        94891  +static void sqlite3StringToId(Expr *p){
        94892  +  if( p->op==TK_STRING ){
        94893  +    p->op = TK_ID;
        94894  +  }else if( p->op==TK_COLLATE && p->pLeft->op==TK_STRING ){
        94895  +    p->pLeft->op = TK_ID;
        94896  +  }
        94897  +}
 94735  94898   
 94736  94899   /*
 94737  94900   ** Create a new index for an SQL table.  pName1.pName2 is the name of the index 
 94738  94901   ** and pTblList is the name of the table that is to be indexed.  Both will 
 94739  94902   ** be NULL for a primary key or an index that is created to satisfy a
 94740  94903   ** UNIQUE constraint.  If pTable and pIndex are NULL, use pParse->pNewTable
 94741  94904   ** as the table to be indexed.  pParse->pNewTable is a table that is
................................................................................
 94770  94933     DbFixer sFix;        /* For assigning database names to pTable */
 94771  94934     int sortOrderMask;   /* 1 to honor DESC in index.  0 to ignore. */
 94772  94935     sqlite3 *db = pParse->db;
 94773  94936     Db *pDb;             /* The specific table containing the indexed database */
 94774  94937     int iDb;             /* Index of the database that is being written */
 94775  94938     Token *pName = 0;    /* Unqualified name of the index to create */
 94776  94939     struct ExprList_item *pListItem; /* For looping over pList */
 94777         -  const Column *pTabCol;           /* A column in the table */
 94778  94940     int nExtra = 0;                  /* Space allocated for zExtra[] */
 94779  94941     int nExtraCol;                   /* Number of extra columns needed */
 94780  94942     char *zExtra = 0;                /* Extra space after the Index object */
 94781  94943     Index *pPk = 0;      /* PRIMARY KEY index for WITHOUT ROWID tables */
 94782  94944   
 94783  94945     if( db->mallocFailed || IN_DECLARE_VTAB || pParse->nErr>0 ){
 94784  94946       goto exit_create_index;
................................................................................
 94925  95087   #endif
 94926  95088   
 94927  95089     /* If pList==0, it means this routine was called to make a primary
 94928  95090     ** key out of the last column added to the table under construction.
 94929  95091     ** So create a fake list to simulate this.
 94930  95092     */
 94931  95093     if( pList==0 ){
 94932         -    pList = sqlite3ExprListAppend(pParse, 0, 0);
        95094  +    Token prevCol;
        95095  +    prevCol.z = pTab->aCol[pTab->nCol-1].zName;
        95096  +    prevCol.n = sqlite3Strlen30(prevCol.z);
        95097  +    pList = sqlite3ExprListAppend(pParse, 0,
        95098  +              sqlite3ExprAlloc(db, TK_ID, &prevCol, 0));
 94933  95099       if( pList==0 ) goto exit_create_index;
 94934         -    pList->a[0].zName = sqlite3DbStrDup(pParse->db,
 94935         -                                        pTab->aCol[pTab->nCol-1].zName);
 94936         -    pList->a[0].sortOrder = (u8)sortOrder;
        95100  +    assert( pList->nExpr==1 );
        95101  +    sqlite3ExprListSetSortOrder(pList, sortOrder);
        95102  +  }else{
        95103  +    sqlite3ExprListCheckLength(pParse, pList, "index");
 94937  95104     }
 94938  95105   
 94939  95106     /* Figure out how many bytes of space are required to store explicitly
 94940  95107     ** specified collation sequence names.
 94941  95108     */
 94942  95109     for(i=0; i<pList->nExpr; i++){
 94943  95110       Expr *pExpr = pList->a[i].pExpr;
 94944         -    if( pExpr ){
 94945         -      assert( pExpr->op==TK_COLLATE );
        95111  +    assert( pExpr!=0 );
        95112  +    if( pExpr->op==TK_COLLATE ){
 94946  95113         nExtra += (1 + sqlite3Strlen30(pExpr->u.zToken));
 94947  95114       }
 94948  95115     }
 94949  95116   
 94950  95117     /* 
 94951  95118     ** Allocate the index structure. 
 94952  95119     */
................................................................................
 94979  95146     */
 94980  95147     if( pDb->pSchema->file_format>=4 ){
 94981  95148       sortOrderMask = -1;   /* Honor DESC */
 94982  95149     }else{
 94983  95150       sortOrderMask = 0;    /* Ignore DESC */
 94984  95151     }
 94985  95152   
 94986         -  /* Scan the names of the columns of the table to be indexed and
 94987         -  ** load the column indices into the Index structure.  Report an error
 94988         -  ** if any column is not found.
        95153  +  /* Analyze the list of expressions that form the terms of the index and
        95154  +  ** report any errors.  In the common case where the expression is exactly
        95155  +  ** a table column, store that column in aiColumn[].  For general expressions,
        95156  +  ** populate pIndex->aColExpr and store -2 in aiColumn[].
 94989  95157     **
 94990         -  ** TODO:  Add a test to make sure that the same column is not named
 94991         -  ** more than once within the same index.  Only the first instance of
 94992         -  ** the column will ever be used by the optimizer.  Note that using the
 94993         -  ** same column more than once cannot be an error because that would 
 94994         -  ** break backwards compatibility - it needs to be a warning.
        95158  +  ** TODO: Issue a warning if two or more columns of the index are identical.
        95159  +  ** TODO: Issue a warning if the table primary key is used as part of the
        95160  +  ** index key.
 94995  95161     */
 94996  95162     for(i=0, pListItem=pList->a; i<pList->nExpr; i++, pListItem++){
 94997         -    const char *zColName = pListItem->zName;
 94998         -    int requestedSortOrder;
        95163  +    Expr *pCExpr;                  /* The i-th index expression */
        95164  +    int requestedSortOrder;        /* ASC or DESC on the i-th expression */
 94999  95165       char *zColl;                   /* Collation sequence name */
 95000  95166   
 95001         -    for(j=0, pTabCol=pTab->aCol; j<pTab->nCol; j++, pTabCol++){
 95002         -      if( sqlite3StrICmp(zColName, pTabCol->zName)==0 ) break;
 95003         -    }
 95004         -    if( j>=pTab->nCol ){
 95005         -      sqlite3ErrorMsg(pParse, "table %s has no column named %s",
 95006         -        pTab->zName, zColName);
 95007         -      pParse->checkSchema = 1;
 95008         -      goto exit_create_index;
 95009         -    }
 95010         -    assert( j<=0x7fff );
 95011         -    pIndex->aiColumn[i] = (i16)j;
 95012         -    if( pListItem->pExpr ){
 95013         -      int nColl;
 95014         -      assert( pListItem->pExpr->op==TK_COLLATE );
        95167  +    sqlite3StringToId(pListItem->pExpr);
        95168  +    sqlite3ResolveSelfReference(pParse, pTab, NC_IdxExpr, pListItem->pExpr, 0);
        95169  +    if( pParse->nErr ) goto exit_create_index;
        95170  +    pCExpr = sqlite3ExprSkipCollate(pListItem->pExpr);
        95171  +    if( pCExpr->op!=TK_COLUMN ){
        95172  +      if( pTab==pParse->pNewTable ){
        95173  +        sqlite3ErrorMsg(pParse, "expressions prohibited in PRIMARY KEY and "
        95174  +                                "UNIQUE constraints");
        95175  +        goto exit_create_index;
        95176  +      }
        95177  +      if( pIndex->aColExpr==0 ){
        95178  +        ExprList *pCopy = sqlite3ExprListDup(db, pList, 0);
        95179  +        pIndex->aColExpr = pCopy;
        95180  +        if( !db->mallocFailed ){
        95181  +          assert( pCopy!=0 );
        95182  +          pListItem = &pCopy->a[i];
        95183  +        }
        95184  +      }
        95185  +      j = -2;
        95186  +      pIndex->aiColumn[i] = -2;
        95187  +      pIndex->uniqNotNull = 0;
        95188  +    }else{
        95189  +      j = pCExpr->iColumn;
        95190  +      assert( j<=0x7fff );
        95191  +      if( j<0 ){
        95192  +        j = pTab->iPKey;
        95193  +      }else if( pTab->aCol[j].notNull==0 ){
        95194  +        pIndex->uniqNotNull = 0;
        95195  +      }
        95196  +      pIndex->aiColumn[i] = (i16)j;
        95197  +    }
        95198  +    zColl = 0;
        95199  +    if( pListItem->pExpr->op==TK_COLLATE ){
        95200  +      int nColl;
 95015  95201         zColl = pListItem->pExpr->u.zToken;
 95016  95202         nColl = sqlite3Strlen30(zColl) + 1;
 95017  95203         assert( nExtra>=nColl );
 95018  95204         memcpy(zExtra, zColl, nColl);
 95019  95205         zColl = zExtra;
 95020  95206         zExtra += nColl;
 95021  95207         nExtra -= nColl;
 95022         -    }else{
        95208  +    }else if( j>=0 ){
 95023  95209         zColl = pTab->aCol[j].zColl;
 95024         -      if( !zColl ) zColl = "BINARY";
 95025  95210       }
        95211  +    if( !zColl ) zColl = "BINARY";
 95026  95212       if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
 95027  95213         goto exit_create_index;
 95028  95214       }
 95029  95215       pIndex->azColl[i] = zColl;
 95030  95216       requestedSortOrder = pListItem->sortOrder & sortOrderMask;
 95031  95217       pIndex->aSortOrder[i] = (u8)requestedSortOrder;
 95032         -    if( pTab->aCol[j].notNull==0 ) pIndex->uniqNotNull = 0;
 95033  95218     }
        95219  +
        95220  +  /* Append the table key to the end of the index.  For WITHOUT ROWID
        95221  +  ** tables (when pPk!=0) this will be the declared PRIMARY KEY.  For
        95222  +  ** normal tables (when pPk==0) this will be the rowid.
        95223  +  */
 95034  95224     if( pPk ){
 95035  95225       for(j=0; j<pPk->nKeyCol; j++){
 95036  95226         int x = pPk->aiColumn[j];
        95227  +      assert( x>=0 );
 95037  95228         if( hasColumn(pIndex->aiColumn, pIndex->nKeyCol, x) ){
 95038  95229           pIndex->nColumn--; 
 95039  95230         }else{
 95040  95231           pIndex->aiColumn[i] = x;
 95041  95232           pIndex->azColl[i] = pPk->azColl[j];
 95042  95233           pIndex->aSortOrder[i] = pPk->aSortOrder[j];
 95043  95234           i++;
................................................................................
 95080  95271         assert( pIdx->idxType!=SQLITE_IDXTYPE_APPDEF );
 95081  95272         assert( IsUniqueIndex(pIndex) );
 95082  95273   
 95083  95274         if( pIdx->nKeyCol!=pIndex->nKeyCol ) continue;
 95084  95275         for(k=0; k<pIdx->nKeyCol; k++){
 95085  95276           const char *z1;
 95086  95277           const char *z2;
        95278  +        assert( pIdx->aiColumn[k]>=0 );
 95087  95279           if( pIdx->aiColumn[k]!=pIndex->aiColumn[k] ) break;
 95088  95280           z1 = pIdx->azColl[k];
 95089  95281           z2 = pIndex->azColl[k];
 95090  95282           if( z1!=z2 && sqlite3StrICmp(z1, z2) ) break;
 95091  95283         }
 95092  95284         if( k==pIdx->nKeyCol ){
 95093  95285           if( pIdx->onError!=pIndex->onError ){
................................................................................
 95111  95303         }
 95112  95304       }
 95113  95305     }
 95114  95306   
 95115  95307     /* Link the new Index structure to its table and to the other
 95116  95308     ** in-memory database structures. 
 95117  95309     */
        95310  +  assert( pParse->nErr==0 );
 95118  95311     if( db->init.busy ){
 95119  95312       Index *p;
 95120  95313       assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
 95121  95314       p = sqlite3HashInsert(&pIndex->pSchema->idxHash, 
 95122  95315                             pIndex->zName, pIndex);
 95123  95316       if( p ){
 95124  95317         assert( p==pIndex );  /* Malloc must have failed */
................................................................................
 95140  95333     ** of a WITHOUT ROWID table.
 95141  95334     **
 95142  95335     ** If pTblName==0 it means this index is generated as an implied PRIMARY KEY
 95143  95336     ** or UNIQUE index in a CREATE TABLE statement.  Since the table
 95144  95337     ** has just been created, it contains no data and the index initialization
 95145  95338     ** step can be skipped.
 95146  95339     */
 95147         -  else if( pParse->nErr==0 && (HasRowid(pTab) || pTblName!=0) ){
        95340  +  else if( HasRowid(pTab) || pTblName!=0 ){
 95148  95341       Vdbe *v;
 95149  95342       char *zStmt;
 95150  95343       int iMem = ++pParse->nMem;
 95151  95344   
 95152  95345       v = sqlite3GetVdbe(pParse);
 95153  95346       if( v==0 ) goto exit_create_index;
 95154  95347   
................................................................................
 95600  95793     int i;
 95601  95794     struct SrcList_item *pItem;
 95602  95795     if( pList==0 ) return;
 95603  95796     for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
 95604  95797       sqlite3DbFree(db, pItem->zDatabase);
 95605  95798       sqlite3DbFree(db, pItem->zName);
 95606  95799       sqlite3DbFree(db, pItem->zAlias);
 95607         -    sqlite3DbFree(db, pItem->zIndexedBy);
        95800  +    if( pItem->fg.isIndexedBy ) sqlite3DbFree(db, pItem->u1.zIndexedBy);
        95801  +    if( pItem->fg.isTabFunc ) sqlite3ExprListDelete(db, pItem->u1.pFuncArg);
 95608  95802       sqlite3DeleteTable(db, pItem->pTab);
 95609  95803       sqlite3SelectDelete(db, pItem->pSelect);
 95610  95804       sqlite3ExprDelete(db, pItem->pOn);
 95611  95805       sqlite3IdListDelete(db, pItem->pUsing);
 95612  95806     }
 95613  95807     sqlite3DbFree(db, pList);
 95614  95808   }
................................................................................
 95673  95867   ** Add an INDEXED BY or NOT INDEXED clause to the most recently added 
 95674  95868   ** element of the source-list passed as the second argument.
 95675  95869   */
 95676  95870   SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *pParse, SrcList *p, Token *pIndexedBy){
 95677  95871     assert( pIndexedBy!=0 );
 95678  95872     if( p && ALWAYS(p->nSrc>0) ){
 95679  95873       struct SrcList_item *pItem = &p->a[p->nSrc-1];
 95680         -    assert( pItem->notIndexed==0 && pItem->zIndexedBy==0 );
        95874  +    assert( pItem->fg.notIndexed==0 );
        95875  +    assert( pItem->fg.isIndexedBy==0 );
        95876  +    assert( pItem->fg.isTabFunc==0 );
 95681  95877       if( pIndexedBy->n==1 && !pIndexedBy->z ){
 95682  95878         /* A "NOT INDEXED" clause was supplied. See parse.y 
 95683  95879         ** construct "indexed_opt" for details. */
 95684         -      pItem->notIndexed = 1;
        95880  +      pItem->fg.notIndexed = 1;
 95685  95881       }else{
 95686         -      pItem->zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy);
        95882  +      pItem->u1.zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy);
        95883  +      pItem->fg.isIndexedBy = (pItem->u1.zIndexedBy!=0);
 95687  95884       }
 95688  95885     }
 95689  95886   }
        95887  +
        95888  +/*
        95889  +** Add the list of function arguments to the SrcList entry for a
        95890  +** table-valued-function.
        95891  +*/
        95892  +SQLITE_PRIVATE void sqlite3SrcListFuncArgs(Parse *pParse, SrcList *p, ExprList *pList){
        95893  +  if( p && pList ){
        95894  +    struct SrcList_item *pItem = &p->a[p->nSrc-1];
        95895  +    assert( pItem->fg.notIndexed==0 );
        95896  +    assert( pItem->fg.isIndexedBy==0 );
        95897  +    assert( pItem->fg.isTabFunc==0 );
        95898  +    pItem->u1.pFuncArg = pList;
        95899  +    pItem->fg.isTabFunc = 1;
        95900  +  }else{
        95901  +    sqlite3ExprListDelete(pParse->db, pList);
        95902  +  }
        95903  +}
 95690  95904   
 95691  95905   /*
 95692  95906   ** When building up a FROM clause in the parser, the join operator
 95693  95907   ** is initially attached to the left operand.  But the code generator
 95694  95908   ** expects the join operator to be on the right operand.  This routine
 95695  95909   ** Shifts all join operators from left to right for an entire FROM
 95696  95910   ** clause.
................................................................................
 95703  95917   ** in p->a[0] and p->a[1], respectively.  The parser initially stores the
 95704  95918   ** operator with A.  This routine shifts that operator over to B.
 95705  95919   */
 95706  95920   SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *p){
 95707  95921     if( p ){
 95708  95922       int i;
 95709  95923       for(i=p->nSrc-1; i>0; i--){
 95710         -      p->a[i].jointype = p->a[i-1].jointype;
        95924  +      p->a[i].fg.jointype = p->a[i-1].fg.jointype;
 95711  95925       }
 95712         -    p->a[0].jointype = 0;
        95926  +    p->a[0].fg.jointype = 0;
 95713  95927     }
 95714  95928   }
 95715  95929   
 95716  95930   /*
 95717  95931   ** Begin a transaction
 95718  95932   */
 95719  95933   SQLITE_PRIVATE void sqlite3BeginTransaction(Parse *pParse, int type){
................................................................................
 95949  96163   ){
 95950  96164     char *zErr;
 95951  96165     int j;
 95952  96166     StrAccum errMsg;
 95953  96167     Table *pTab = pIdx->pTable;
 95954  96168   
 95955  96169     sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
 95956         -  for(j=0; j<pIdx->nKeyCol; j++){
 95957         -    char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
 95958         -    if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
 95959         -    sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
 95960         -    sqlite3StrAccumAppend(&errMsg, ".", 1);
 95961         -    sqlite3StrAccumAppendAll(&errMsg, zCol);
        96170  +  if( pIdx->aColExpr ){
        96171  +    sqlite3XPrintf(&errMsg, 0, "index '%q'", pIdx->zName);
        96172  +  }else{
        96173  +    for(j=0; j<pIdx->nKeyCol; j++){
        96174  +      char *zCol;
        96175  +      assert( pIdx->aiColumn[j]>=0 );
        96176  +      zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
        96177  +      if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
        96178  +      sqlite3XPrintf(&errMsg, 0, "%s.%s", pTab->zName, zCol);
        96179  +    }
 95962  96180     }
 95963  96181     zErr = sqlite3StrAccumFinish(&errMsg);
 95964  96182     sqlite3HaltConstraint(pParse, 
 95965  96183       IsPrimaryKeyIndex(pIdx) ? SQLITE_CONSTRAINT_PRIMARYKEY 
 95966  96184                               : SQLITE_CONSTRAINT_UNIQUE,
 95967  96185       onError, zErr, P4_DYNAMIC, P5_ConstraintUnique);
 95968  96186   }
................................................................................
 96199  96417       sqlite3SelectDelete(db, pQuery);
 96200  96418       sqlite3DbFree(db, zName);
 96201  96419       pNew = pWith;
 96202  96420     }else{
 96203  96421       pNew->a[pNew->nCte].pSelect = pQuery;
 96204  96422       pNew->a[pNew->nCte].pCols = pArglist;
 96205  96423       pNew->a[pNew->nCte].zName = zName;
 96206         -    pNew->a[pNew->nCte].zErr = 0;
        96424  +    pNew->a[pNew->nCte].zCteErr = 0;
 96207  96425       pNew->nCte++;
 96208  96426     }
 96209  96427   
 96210  96428     return pNew;
 96211  96429   }
 96212  96430   
 96213  96431   /*
................................................................................
 97118  97336       if( db->flags & SQLITE_CountRows ){
 97119  97337         sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
 97120  97338       }
 97121  97339     
 97122  97340       /* Extract the rowid or primary key for the current row */
 97123  97341       if( pPk ){
 97124  97342         for(i=0; i<nPk; i++){
        97343  +        assert( pPk->aiColumn[i]>=(-1) );
 97125  97344           sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
 97126  97345                                           pPk->aiColumn[i], iPk+i);
 97127  97346         }
 97128  97347         iKey = iPk;
 97129  97348       }else{
 97130  97349         iKey = pParse->nMem + 1;
 97131  97350         iKey = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iTabCur, iKey, 0);
................................................................................
 97150  97369         if( addrEphOpen ) sqlite3VdbeChangeToNoop(v, addrEphOpen);
 97151  97370         addrDelete = sqlite3VdbeAddOp0(v, OP_Goto); /* Jump to DELETE logic */
 97152  97371       }else if( pPk ){
 97153  97372         /* Construct a composite key for the row to be deleted and remember it */
 97154  97373         iKey = ++pParse->nMem;
 97155  97374         nKey = 0;   /* Zero tells OP_Found to use a composite key */
 97156  97375         sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
 97157         -                        sqlite3IndexAffinityStr(v, pPk), nPk);
        97376  +                        sqlite3IndexAffinityStr(pParse->db, pPk), nPk);
 97158  97377         sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey);
 97159  97378       }else{
 97160  97379         /* Get the rowid of the row to be deleted and remember it in the RowSet */
 97161  97380         nKey = 1;  /* OP_Seek always uses a single rowid */
 97162  97381         sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
 97163  97382       }
 97164  97383     
 97165  97384       /* End of the WHERE loop */
 97166  97385       sqlite3WhereEnd(pWInfo);
 97167  97386       if( okOnePass ){
 97168  97387         /* Bypass the delete logic below if the WHERE loop found zero rows */
 97169  97388         addrBypass = sqlite3VdbeMakeLabel(v);
 97170         -      sqlite3VdbeAddOp2(v, OP_Goto, 0, addrBypass);
        97389  +      sqlite3VdbeGoto(v, addrBypass);
 97171  97390         sqlite3VdbeJumpHere(v, addrDelete);
 97172  97391       }
 97173  97392     
 97174  97393       /* Unless this is a view, open cursors for the table we are 
 97175  97394       ** deleting from and all its indices. If this is a view, then the
 97176  97395       ** only effect this statement has is to fire the INSTEAD OF 
 97177  97396       ** triggers.
................................................................................
 97225  97444       /* End of the loop over all rowids/primary-keys. */
 97226  97445       if( okOnePass ){
 97227  97446         sqlite3VdbeResolveLabel(v, addrBypass);
 97228  97447       }else if( pPk ){
 97229  97448         sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); VdbeCoverage(v);
 97230  97449         sqlite3VdbeJumpHere(v, addrLoop);
 97231  97450       }else{
 97232         -      sqlite3VdbeAddOp2(v, OP_Goto, 0, addrLoop);
        97451  +      sqlite3VdbeGoto(v, addrLoop);
 97233  97452         sqlite3VdbeJumpHere(v, addrLoop);
 97234  97453       }     
 97235  97454     
 97236  97455       /* Close the cursors open on the table and its indexes. */
 97237  97456       if( !isView && !IsVirtual(pTab) ){
 97238  97457         if( !pPk ) sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
 97239  97458         for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
................................................................................
 97496  97715     int prefixOnly,      /* Compute only a unique prefix of the key */
 97497  97716     int *piPartIdxLabel, /* OUT: Jump to this label to skip partial index */
 97498  97717     Index *pPrior,       /* Previously generated index key */
 97499  97718     int regPrior         /* Register holding previous generated key */
 97500  97719   ){
 97501  97720     Vdbe *v = pParse->pVdbe;
 97502  97721     int j;
 97503         -  Table *pTab = pIdx->pTable;
 97504  97722     int regBase;
 97505  97723     int nCol;
 97506  97724   
 97507  97725     if( piPartIdxLabel ){
 97508  97726       if( pIdx->pPartIdxWhere ){
 97509  97727         *piPartIdxLabel = sqlite3VdbeMakeLabel(v);
 97510         -      pParse->iPartIdxTab = iDataCur;
        97728  +      pParse->iSelfTab = iDataCur;
 97511  97729         sqlite3ExprCachePush(pParse);
 97512  97730         sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel, 
 97513  97731                               SQLITE_JUMPIFNULL);
 97514  97732       }else{
 97515  97733         *piPartIdxLabel = 0;
 97516  97734       }
 97517  97735     }
 97518  97736     nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
 97519  97737     regBase = sqlite3GetTempRange(pParse, nCol);
 97520  97738     if( pPrior && (regBase!=regPrior || pPrior->pPartIdxWhere) ) pPrior = 0;
 97521  97739     for(j=0; j<nCol; j++){
 97522         -    if( pPrior && pPrior->aiColumn[j]==pIdx->aiColumn[j] ) continue;
 97523         -    sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pIdx->aiColumn[j],
 97524         -                                    regBase+j);
        97740  +    if( pPrior
        97741  +     && pPrior->aiColumn[j]==pIdx->aiColumn[j]
        97742  +     && pPrior->aiColumn[j]>=(-1)
        97743  +    ){
        97744  +      /* This column was already computed by the previous index */
        97745  +      continue;
        97746  +    }
        97747  +    sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iDataCur, j, regBase+j);
 97525  97748       /* If the column affinity is REAL but the number is an integer, then it
 97526  97749       ** might be stored in the table as an integer (using a compact
 97527  97750       ** representation) then converted to REAL by an OP_RealAffinity opcode.
 97528  97751       ** But we are getting ready to store this value back into an index, where
 97529  97752       ** it should be converted by to INTEGER again.  So omit the OP_RealAffinity
 97530  97753       ** opcode if it is present */
 97531  97754       sqlite3VdbeDeletePriorOpcode(v, OP_RealAffinity);
................................................................................
 99286  99509       FUNCTION2(ifnull,            2, 0, 0, noopFunc,  SQLITE_FUNC_COALESCE),
 99287  99510       FUNCTION2(unlikely,          1, 0, 0, noopFunc,  SQLITE_FUNC_UNLIKELY),
 99288  99511       FUNCTION2(likelihood,        2, 0, 0, noopFunc,  SQLITE_FUNC_UNLIKELY),
 99289  99512       FUNCTION2(likely,            1, 0, 0, noopFunc,  SQLITE_FUNC_UNLIKELY),
 99290  99513       VFUNCTION(random,            0, 0, 0, randomFunc       ),
 99291  99514       VFUNCTION(randomblob,        1, 0, 0, randomBlob       ),
 99292  99515       FUNCTION(nullif,             2, 0, 1, nullifFunc       ),
 99293         -    FUNCTION(sqlite_version,     0, 0, 0, versionFunc      ),
 99294         -    FUNCTION(sqlite_source_id,   0, 0, 0, sourceidFunc     ),
        99516  +    DFUNCTION(sqlite_version,    0, 0, 0, versionFunc      ),
        99517  +    DFUNCTION(sqlite_source_id,  0, 0, 0, sourceidFunc     ),
 99295  99518       FUNCTION(sqlite_log,         2, 0, 0, errlogFunc       ),
 99296  99519   #if SQLITE_USER_AUTHENTICATION
 99297  99520       FUNCTION(sqlite_crypt,       2, 0, 0, sqlite3CryptFunc ),
 99298  99521   #endif
 99299  99522   #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
 99300         -    FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc  ),
 99301         -    FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc  ),
        99523  +    DFUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc  ),
        99524  +    DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc  ),
 99302  99525   #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
 99303  99526       FUNCTION(quote,              1, 0, 0, quoteFunc        ),
 99304  99527       VFUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid),
 99305  99528       VFUNCTION(changes,           0, 0, 0, changes          ),
 99306  99529       VFUNCTION(total_changes,     0, 0, 0, total_changes    ),
 99307  99530       FUNCTION(replace,            3, 0, 0, replaceFunc      ),
 99308  99531       FUNCTION(zeroblob,           1, 0, 0, zeroblobFunc     ),
 99309  99532     #ifdef SQLITE_SOUNDEX
 99310  99533       FUNCTION(soundex,            1, 0, 0, soundexFunc      ),
 99311  99534     #endif
 99312  99535     #ifndef SQLITE_OMIT_LOAD_EXTENSION
 99313         -    FUNCTION(load_extension,     1, 0, 0, loadExt          ),
 99314         -    FUNCTION(load_extension,     2, 0, 0, loadExt          ),
        99536  +    VFUNCTION(load_extension,    1, 0, 0, loadExt          ),
        99537  +    VFUNCTION(load_extension,    2, 0, 0, loadExt          ),
 99315  99538     #endif
 99316  99539       AGGREGATE(sum,               1, 0, 0, sumStep,         sumFinalize    ),
 99317  99540       AGGREGATE(total,             1, 0, 0, sumStep,         totalFinalize    ),
 99318  99541       AGGREGATE(avg,               1, 0, 0, sumStep,         avgFinalize    ),
 99319  99542       AGGREGATE2(count,            0, 0, 0, countStep,       countFinalize,
 99320  99543                  SQLITE_FUNC_COUNT  ),
 99321  99544       AGGREGATE(count,             1, 0, 0, countStep,       countFinalize  ),
................................................................................
 99722  99945         if( pTab==pFKey->pFrom && nIncr==1 ){
 99723  99946           sqlite3VdbeAddOp3(v, OP_Eq, regData, iOk, regTemp); VdbeCoverage(v);
 99724  99947           sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
 99725  99948         }
 99726  99949     
 99727  99950         sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
 99728  99951         sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp); VdbeCoverage(v);
 99729         -      sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
        99952  +      sqlite3VdbeGoto(v, iOk);
 99730  99953         sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
 99731  99954         sqlite3VdbeJumpHere(v, iMustBeInt);
 99732  99955         sqlite3ReleaseTempReg(pParse, regTemp);
 99733  99956       }else{
 99734  99957         int nCol = pFKey->nCol;
 99735  99958         int regTemp = sqlite3GetTempRange(pParse, nCol);
 99736  99959         int regRec = sqlite3GetTempReg(pParse);
................................................................................
 99760  99983             if( pIdx->aiColumn[i]==pTab->iPKey ){
 99761  99984               /* The parent key is a composite key that includes the IPK column */
 99762  99985               iParent = regData;
 99763  99986             }
 99764  99987             sqlite3VdbeAddOp3(v, OP_Ne, iChild, iJump, iParent); VdbeCoverage(v);
 99765  99988             sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
 99766  99989           }
 99767         -        sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
        99990  +        sqlite3VdbeGoto(v, iOk);
 99768  99991         }
 99769  99992     
 99770  99993         sqlite3VdbeAddOp4(v, OP_MakeRecord, regTemp, nCol, regRec,
 99771         -                        sqlite3IndexAffinityStr(v,pIdx), nCol);
        99994  +                        sqlite3IndexAffinityStr(pParse->db,pIdx), nCol);
 99772  99995         sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); VdbeCoverage(v);
 99773  99996     
 99774  99997         sqlite3ReleaseTempReg(pParse, regRec);
 99775  99998         sqlite3ReleaseTempRange(pParse, regTemp, nCol);
 99776  99999       }
 99777 100000     }
 99778 100001   
................................................................................
100821 101044   ** An extra 'D' is appended to the end of the string to cover the
100822 101045   ** rowid that appears as the last column in every index.
100823 101046   **
100824 101047   ** Memory for the buffer containing the column index affinity string
100825 101048   ** is managed along with the rest of the Index structure. It will be
100826 101049   ** released when sqlite3DeleteIndex() is called.
100827 101050   */
100828         -SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *v, Index *pIdx){
       101051  +SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(sqlite3 *db, Index *pIdx){
100829 101052     if( !pIdx->zColAff ){
100830 101053       /* The first time a column affinity string for a particular index is
100831 101054       ** required, it is allocated and populated here. It is then stored as
100832 101055       ** a member of the Index structure for subsequent use.
100833 101056       **
100834 101057       ** The column affinity string will eventually be deleted by
100835 101058       ** sqliteDeleteIndex() when the Index structure itself is cleaned
100836 101059       ** up.
100837 101060       */
100838 101061       int n;
100839 101062       Table *pTab = pIdx->pTable;
100840         -    sqlite3 *db = sqlite3VdbeDb(v);
100841 101063       pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+1);
100842 101064       if( !pIdx->zColAff ){
100843 101065         db->mallocFailed = 1;
100844 101066         return 0;
100845 101067       }
100846 101068       for(n=0; n<pIdx->nColumn; n++){
100847 101069         i16 x = pIdx->aiColumn[n];
100848         -      pIdx->zColAff[n] = x<0 ? SQLITE_AFF_INTEGER : pTab->aCol[x].affinity;
       101070  +      if( x>=0 ){
       101071  +        pIdx->zColAff[n] = pTab->aCol[x].affinity;
       101072  +      }else if( x==(-1) ){
       101073  +        pIdx->zColAff[n] = SQLITE_AFF_INTEGER;
       101074  +      }else{
       101075  +        char aff;
       101076  +        assert( x==(-2) );
       101077  +        assert( pIdx->aColExpr!=0 );
       101078  +        aff = sqlite3ExprAffinity(pIdx->aColExpr->a[n].pExpr);
       101079  +        if( aff==0 ) aff = SQLITE_AFF_BLOB;
       101080  +        pIdx->zColAff[n] = aff;
       101081  +      }
100849 101082       }
100850 101083       pIdx->zColAff[n] = 0;
100851 101084     }
100852 101085    
100853 101086     return pIdx->zColAff;
100854 101087   }
100855 101088   
................................................................................
101012 101245     for(p = pParse->pAinc; p; p = p->pNext){
101013 101246       pDb = &db->aDb[p->iDb];
101014 101247       memId = p->regCtr;
101015 101248       assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
101016 101249       sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
101017 101250       sqlite3VdbeAddOp3(v, OP_Null, 0, memId, memId+1);
101018 101251       addr = sqlite3VdbeCurrentAddr(v);
101019         -    sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, p->pTab->zName, 0);
       101252  +    sqlite3VdbeLoadString(v, memId-1, p->pTab->zName);
101020 101253       sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9); VdbeCoverage(v);
101021 101254       sqlite3VdbeAddOp3(v, OP_Column, 0, 0, memId);
101022 101255       sqlite3VdbeAddOp3(v, OP_Ne, memId-1, addr+7, memId); VdbeCoverage(v);
101023 101256       sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
101024 101257       sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1);
101025 101258       sqlite3VdbeAddOp3(v, OP_Column, 0, 1, memId);
101026         -    sqlite3VdbeAddOp2(v, OP_Goto, 0, addr+9);
       101259  +    sqlite3VdbeGoto(v, addr+9);
101027 101260       sqlite3VdbeAddOp2(v, OP_Next, 0, addr+2); VdbeCoverage(v);
101028 101261       sqlite3VdbeAddOp2(v, OP_Integer, 0, memId);
101029 101262       sqlite3VdbeAddOp0(v, OP_Close);
101030 101263     }
101031 101264   }
101032 101265   
101033 101266   /*
................................................................................
101443 101676         regRec = sqlite3GetTempReg(pParse);
101444 101677         regTempRowid = sqlite3GetTempReg(pParse);
101445 101678         sqlite3VdbeAddOp2(v, OP_OpenEphemeral, srcTab, nColumn);
101446 101679         addrL = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); VdbeCoverage(v);
101447 101680         sqlite3VdbeAddOp3(v, OP_MakeRecord, regFromSelect, nColumn, regRec);
101448 101681         sqlite3VdbeAddOp2(v, OP_NewRowid, srcTab, regTempRowid);
101449 101682         sqlite3VdbeAddOp3(v, OP_Insert, srcTab, regRec, regTempRowid);
101450         -      sqlite3VdbeAddOp2(v, OP_Goto, 0, addrL);
       101683  +      sqlite3VdbeGoto(v, addrL);
101451 101684         sqlite3VdbeJumpHere(v, addrL);
101452 101685         sqlite3ReleaseTempReg(pParse, regRec);
101453 101686         sqlite3ReleaseTempReg(pParse, regTempRowid);
101454 101687       }
101455 101688     }else{
101456 101689       /* This is the case if the data for the INSERT is coming from a 
101457 101690       ** single-row VALUES clause
101458 101691       */
101459 101692       NameContext sNC;
101460 101693       memset(&sNC, 0, sizeof(sNC));
101461 101694       sNC.pParse = pParse;
101462 101695       srcTab = -1;
101463 101696       assert( useTempTable==0 );
101464         -    nColumn = pList ? pList->nExpr : 0;
101465         -    for(i=0; i<nColumn; i++){
101466         -      if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){
       101697  +    if( pList ){
       101698  +      nColumn = pList->nExpr;
       101699  +      if( sqlite3ResolveExprListNames(&sNC, pList) ){
101467 101700           goto insert_cleanup;
101468 101701         }
       101702  +    }else{
       101703  +      nColumn = 0;
101469 101704       }
101470 101705     }
101471 101706   
101472 101707     /* If there is no IDLIST term but the table has an integer primary
101473 101708     ** key, the set the ipkColumn variable to the integer primary key 
101474 101709     ** column index in the original table definition.
101475 101710     */
................................................................................
101742 101977     */
101743 101978     sqlite3VdbeResolveLabel(v, endOfLoop);
101744 101979     if( useTempTable ){
101745 101980       sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont); VdbeCoverage(v);
101746 101981       sqlite3VdbeJumpHere(v, addrInsTop);
101747 101982       sqlite3VdbeAddOp1(v, OP_Close, srcTab);
101748 101983     }else if( pSelect ){
101749         -    sqlite3VdbeAddOp2(v, OP_Goto, 0, addrCont);
       101984  +    sqlite3VdbeGoto(v, addrCont);
101750 101985       sqlite3VdbeJumpHere(v, addrInsTop);
101751 101986     }
101752 101987   
101753 101988     if( !IsVirtual(pTab) && !isView ){
101754 101989       /* Close all tables opened */
101755 101990       if( iDataCur<iIdxCur ) sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
101756 101991       for(idx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
................................................................................
101989 102224       ExprList *pCheck = pTab->pCheck;
101990 102225       pParse->ckBase = regNewData+1;
101991 102226       onError = overrideError!=OE_Default ? overrideError : OE_Abort;
101992 102227       for(i=0; i<pCheck->nExpr; i++){
101993 102228         int allOk = sqlite3VdbeMakeLabel(v);
101994 102229         sqlite3ExprIfTrue(pParse, pCheck->a[i].pExpr, allOk, SQLITE_JUMPIFNULL);
101995 102230         if( onError==OE_Ignore ){
101996         -        sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
       102231  +        sqlite3VdbeGoto(v, ignoreDest);
101997 102232         }else{
101998 102233           char *zName = pCheck->a[i].zName;
101999 102234           if( zName==0 ) zName = pTab->zName;
102000 102235           if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */
102001 102236           sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_CHECK,
102002 102237                                 onError, zName, P4_TRANSIENT,
102003 102238                                 P5_ConstraintCheck);
................................................................................
102097 102332             sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, 0);
102098 102333           }
102099 102334           seenReplace = 1;
102100 102335           break;
102101 102336         }
102102 102337         case OE_Ignore: {
102103 102338           /*assert( seenReplace==0 );*/
102104         -        sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
       102339  +        sqlite3VdbeGoto(v, ignoreDest);
102105 102340           break;
102106 102341         }
102107 102342       }
102108 102343       sqlite3VdbeResolveLabel(v, addrRowidOk);
102109 102344       if( ipkTop ){
102110 102345         ipkBottom = sqlite3VdbeAddOp0(v, OP_Goto);
102111 102346         sqlite3VdbeJumpHere(v, ipkTop);
................................................................................
102145 102380       /* Create a record for this index entry as it should appear after
102146 102381       ** the insert or update.  Store that record in the aRegIdx[ix] register
102147 102382       */
102148 102383       regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn);
102149 102384       for(i=0; i<pIdx->nColumn; i++){
102150 102385         int iField = pIdx->aiColumn[i];
102151 102386         int x;
102152         -      if( iField<0 || iField==pTab->iPKey ){
102153         -        if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */
102154         -        x = regNewData;
102155         -        regRowid =  pIdx->pPartIdxWhere ? -1 : regIdx+i;
       102387  +      if( iField==(-2) ){
       102388  +        pParse->ckBase = regNewData+1;
       102389  +        sqlite3ExprCode(pParse, pIdx->aColExpr->a[i].pExpr, regIdx+i);
       102390  +        pParse->ckBase = 0;
       102391  +        VdbeComment((v, "%s column %d", pIdx->zName, i));
102156 102392         }else{
102157         -        x = iField + regNewData + 1;
       102393  +        if( iField==(-1) || iField==pTab->iPKey ){
       102394  +          if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */
       102395  +          x = regNewData;
       102396  +          regRowid =  pIdx->pPartIdxWhere ? -1 : regIdx+i;
       102397  +        }else{
       102398  +          x = iField + regNewData + 1;
       102399  +        }
       102400  +        sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
       102401  +        VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
102158 102402         }
102159         -      sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
102160         -      VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
102161 102403       }
102162 102404       sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
102163 102405       VdbeComment((v, "for %s", pIdx->zName));
102164 102406       sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn);
102165 102407   
102166 102408       /* In an UPDATE operation, if this index is the PRIMARY KEY index 
102167 102409       ** of a WITHOUT ROWID table and there has been no change the
................................................................................
102250 102492         case OE_Rollback:
102251 102493         case OE_Abort:
102252 102494         case OE_Fail: {
102253 102495           sqlite3UniqueConstraint(pParse, onError, pIdx);
102254 102496           break;
102255 102497         }
102256 102498         case OE_Ignore: {
102257         -        sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
       102499  +        sqlite3VdbeGoto(v, ignoreDest);
102258 102500           break;
102259 102501         }
102260 102502         default: {
102261 102503           Trigger *pTrigger = 0;
102262 102504           assert( onError==OE_Replace );
102263 102505           sqlite3MultiWrite(pParse);
102264 102506           if( db->flags&SQLITE_RecTriggers ){
................................................................................
102271 102513         }
102272 102514       }
102273 102515       sqlite3VdbeResolveLabel(v, addrUniqueOk);
102274 102516       sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn);
102275 102517       if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField);
102276 102518     }
102277 102519     if( ipkTop ){
102278         -    sqlite3VdbeAddOp2(v, OP_Goto, 0, ipkTop+1);
       102520  +    sqlite3VdbeGoto(v, ipkTop+1);
102279 102521       sqlite3VdbeJumpHere(v, ipkBottom);
102280 102522     }
102281 102523     
102282 102524     *pbMayReplace = seenReplace;
102283 102525     VdbeModuleComment((v, "END: GenCnstCks(%d)", seenReplace));
102284 102526   }
102285 102527   
................................................................................
102473 102715     }
102474 102716     if( pDest->onError!=pSrc->onError ){
102475 102717       return 0;   /* Different conflict resolution strategies */
102476 102718     }
102477 102719     for(i=0; i<pSrc->nKeyCol; i++){
102478 102720       if( pSrc->aiColumn[i]!=pDest->aiColumn[i] ){
102479 102721         return 0;   /* Different columns indexed */
       102722  +    }
       102723  +    if( pSrc->aiColumn[i]==(-2) ){
       102724  +      assert( pSrc->aColExpr!=0 && pDest->aColExpr!=0 );
       102725  +      if( sqlite3ExprCompare(pSrc->aColExpr->a[i].pExpr,
       102726  +                             pDest->aColExpr->a[i].pExpr, -1)!=0 ){
       102727  +        return 0;   /* Different expressions in the index */
       102728  +      }
102480 102729       }
102481 102730       if( pSrc->aSortOrder[i]!=pDest->aSortOrder[i] ){
102482 102731         return 0;   /* Different sort orders */
102483 102732       }
102484 102733       if( !xferCompatibleCollation(pSrc->azColl[i],pDest->azColl[i]) ){
102485 102734         return 0;   /* Different collating sequences */
102486 102735       }
................................................................................
102717 102966       **
102718 102967       ** (2) The destination has a unique index.  (The xfer optimization 
102719 102968       **     is unable to test uniqueness.)
102720 102969       **
102721 102970       ** (3) onError is something other than OE_Abort and OE_Rollback.
102722 102971       */
102723 102972       addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); VdbeCoverage(v);
102724         -    emptyDestTest = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
       102973  +    emptyDestTest = sqlite3VdbeAddOp0(v, OP_Goto);
102725 102974       sqlite3VdbeJumpHere(v, addr1);
102726 102975     }
102727 102976     if( HasRowid(pSrc) ){
102728 102977       sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
102729 102978       emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
102730 102979       if( pDest->iPKey>=0 ){
102731 102980         addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
................................................................................
103394 103643   #define sqlite3_value_numeric_type     sqlite3_api->value_numeric_type
103395 103644   #define sqlite3_value_text             sqlite3_api->value_text
103396 103645   #define sqlite3_value_text16           sqlite3_api->value_text16
103397 103646   #define sqlite3_value_text16be         sqlite3_api->value_text16be
103398 103647   #define sqlite3_value_text16le         sqlite3_api->value_text16le
103399 103648   #define sqlite3_value_type             sqlite3_api->value_type
103400 103649   #define sqlite3_vmprintf               sqlite3_api->vmprintf
       103650  +#define sqlite3_vsnprintf              sqlite3_api->vsnprintf
103401 103651   #define sqlite3_overload_function      sqlite3_api->overload_function
103402 103652   #define sqlite3_prepare_v2             sqlite3_api->prepare_v2
103403 103653   #define sqlite3_prepare16_v2           sqlite3_api->prepare16_v2
103404 103654   #define sqlite3_clear_bindings         sqlite3_api->clear_bindings
103405 103655   #define sqlite3_bind_zeroblob          sqlite3_api->bind_zeroblob
103406 103656   #define sqlite3_blob_bytes             sqlite3_api->blob_bytes
103407 103657   #define sqlite3_blob_close             sqlite3_api->blob_close
................................................................................
104896 105146     if( invalidateTempStorage( pParse ) != SQLITE_OK ){
104897 105147       return SQLITE_ERROR;
104898 105148     }
104899 105149     db->temp_store = (u8)ts;
104900 105150     return SQLITE_OK;
104901 105151   }
104902 105152   #endif /* SQLITE_PAGER_PRAGMAS */
       105153  +
       105154  +/*
       105155  +** Set the names of the first N columns to the values in azCol[]
       105156  +*/
       105157  +static void setAllColumnNames(
       105158  +  Vdbe *v,               /* The query under construction */
       105159  +  int N,                 /* Number of columns */
       105160  +  const char **azCol     /* Names of columns */
       105161  +){
       105162  +  int i;
       105163  +  sqlite3VdbeSetNumCols(v, N);
       105164  +  for(i=0; i<N; i++){
       105165  +    sqlite3VdbeSetColName(v, i, COLNAME_NAME, azCol[i], SQLITE_STATIC);
       105166  +  }
       105167  +}
       105168  +static void setOneColumnName(Vdbe *v, const char *z){
       105169  +  setAllColumnNames(v, 1, &z);
       105170  +}
104903 105171   
104904 105172   /*
104905 105173   ** Generate code to return a single integer value.
104906 105174   */
104907         -static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){
104908         -  Vdbe *v = sqlite3GetVdbe(pParse);
104909         -  int nMem = ++pParse->nMem;
104910         -  i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
104911         -  if( pI64 ){
104912         -    memcpy(pI64, &value, sizeof(value));
       105175  +static void returnSingleInt(Vdbe *v, const char *zLabel, i64 value){
       105176  +  sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, 1, 0, (const u8*)&value, P4_INT64);
       105177  +  setOneColumnName(v, zLabel);
       105178  +  sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
       105179  +}
       105180  +
       105181  +/*
       105182  +** Generate code to return a single text value.
       105183  +*/
       105184  +static void returnSingleText(
       105185  +  Vdbe *v,                /* Prepared statement under construction */
       105186  +  const char *zLabel,     /* Name of the result column */
       105187  +  const char *zValue      /* Value to be returned */
       105188  +){
       105189  +  if( zValue ){
       105190  +    sqlite3VdbeLoadString(v, 1, (const char*)zValue);
       105191  +    setOneColumnName(v, zLabel);
       105192  +    sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
104913 105193     }
104914         -  sqlite3VdbeAddOp4(v, OP_Int64, 0, nMem, 0, (char*)pI64, P4_INT64);
104915         -  sqlite3VdbeSetNumCols(v, 1);
104916         -  sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
104917         -  sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
104918 105194   }
104919 105195   
104920 105196   
104921 105197   /*
104922 105198   ** Set the safety_level and pager flags for pager iDb.  Or if iDb<0
104923 105199   ** set these values for all pagers.
104924 105200   */
................................................................................
105074 105350     aFcntl[0] = 0;
105075 105351     aFcntl[1] = zLeft;
105076 105352     aFcntl[2] = zRight;
105077 105353     aFcntl[3] = 0;
105078 105354     db->busyHandler.nBusy = 0;
105079 105355     rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
105080 105356     if( rc==SQLITE_OK ){
105081         -    if( aFcntl[0] ){
105082         -      int nMem = ++pParse->nMem;
105083         -      sqlite3VdbeAddOp4(v, OP_String8, 0, nMem, 0, aFcntl[0], 0);
105084         -      sqlite3VdbeSetNumCols(v, 1);
105085         -      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC);
105086         -      sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
105087         -      sqlite3_free(aFcntl[0]);
105088         -    }
       105357  +    returnSingleText(v, "result", aFcntl[0]);
       105358  +    sqlite3_free(aFcntl[0]);
105089 105359       goto pragma_out;
105090 105360     }
105091 105361     if( rc!=SQLITE_NOTFOUND ){
105092 105362       if( aFcntl[0] ){
105093 105363         sqlite3ErrorMsg(pParse, "%s", aFcntl[0]);
105094 105364         sqlite3_free(aFcntl[0]);
105095 105365       }
................................................................................
105151 105421         { OP_Integer,     0, 1,        0},                         /* 6 */
105152 105422         { OP_Noop,        0, 0,        0},
105153 105423         { OP_ResultRow,   1, 1,        0},
105154 105424       };
105155 105425       int addr;
105156 105426       sqlite3VdbeUsesBtree(v, iDb);
105157 105427       if( !zRight ){
105158         -      sqlite3VdbeSetNumCols(v, 1);
105159         -      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC);
       105428  +      setOneColumnName(v, "cache_size");
105160 105429         pParse->nMem += 2;
105161 105430         addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize,iLn);
105162 105431         sqlite3VdbeChangeP1(v, addr, iDb);
105163 105432         sqlite3VdbeChangeP1(v, addr+1, iDb);
105164 105433         sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
105165 105434       }else{
105166 105435         int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
................................................................................
105186 105455     ** the database has not yet been created.
105187 105456     */
105188 105457     case PragTyp_PAGE_SIZE: {
105189 105458       Btree *pBt = pDb->pBt;
105190 105459       assert( pBt!=0 );
105191 105460       if( !zRight ){
105192 105461         int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
105193         -      returnSingleInt(pParse, "page_size", size);
       105462  +      returnSingleInt(v, "page_size", size);
105194 105463       }else{
105195 105464         /* Malloc may fail when setting the page-size, as there is an internal
105196 105465         ** buffer that the pager module resizes using sqlite3_realloc().
105197 105466         */
105198 105467         db->nextPagesize = sqlite3Atoi(zRight);
105199 105468         if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){
105200 105469           db->mallocFailed = 1;
................................................................................
105221 105490       if( pId2->n==0 && b>=0 ){
105222 105491         int ii;
105223 105492         for(ii=0; ii<db->nDb; ii++){
105224 105493           sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
105225 105494         }
105226 105495       }
105227 105496       b = sqlite3BtreeSecureDelete(pBt, b);
105228         -    returnSingleInt(pParse, "secure_delete", b);
       105497  +    returnSingleInt(v, "secure_delete", b);
105229 105498       break;
105230 105499     }
105231 105500   
105232 105501     /*
105233 105502     **  PRAGMA [database.]max_page_count
105234 105503     **  PRAGMA [database.]max_page_count=N
105235 105504     **
................................................................................
105300 105569       }
105301 105570   
105302 105571       assert( eMode==PAGER_LOCKINGMODE_NORMAL
105303 105572               || eMode==PAGER_LOCKINGMODE_EXCLUSIVE );
105304 105573       if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
105305 105574         zRet = "exclusive";
105306 105575       }
105307         -    sqlite3VdbeSetNumCols(v, 1);
105308         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", SQLITE_STATIC);
105309         -    sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zRet, 0);
105310         -    sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
       105576  +    returnSingleText(v, "locking_mode", zRet);
105311 105577       break;
105312 105578     }
105313 105579   
105314 105580     /*
105315 105581     **  PRAGMA [database.]journal_mode
105316 105582     **  PRAGMA [database.]journal_mode =
105317 105583     **                      (delete|persist|off|truncate|memory|wal|off)
105318 105584     */
105319 105585     case PragTyp_JOURNAL_MODE: {
105320 105586       int eMode;        /* One of the PAGER_JOURNALMODE_XXX symbols */
105321 105587       int ii;           /* Loop counter */
105322 105588   
105323         -    sqlite3VdbeSetNumCols(v, 1);
105324         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC);
105325         -
       105589  +    setOneColumnName(v, "journal_mode");
105326 105590       if( zRight==0 ){
105327 105591         /* If there is no "=MODE" part of the pragma, do a query for the
105328 105592         ** current mode */
105329 105593         eMode = PAGER_JOURNALMODE_QUERY;
105330 105594       }else{
105331 105595         const char *zMode;
105332 105596         int n = sqlite3Strlen30(zRight);
................................................................................
105364 105628       Pager *pPager = sqlite3BtreePager(pDb->pBt);
105365 105629       i64 iLimit = -2;
105366 105630       if( zRight ){
105367 105631         sqlite3DecOrHexToI64(zRight, &iLimit);
105368 105632         if( iLimit<-1 ) iLimit = -1;
105369 105633       }
105370 105634       iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
105371         -    returnSingleInt(pParse, "journal_size_limit", iLimit);
       105635  +    returnSingleInt(v, "journal_size_limit", iLimit);
105372 105636       break;
105373 105637     }
105374 105638   
105375 105639   #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
105376 105640   
105377 105641     /*
105378 105642     **  PRAGMA [database.]auto_vacuum
................................................................................
105382 105646     ** The value is one of:  0 NONE 1 FULL 2 INCREMENTAL
105383 105647     */
105384 105648   #ifndef SQLITE_OMIT_AUTOVACUUM
105385 105649     case PragTyp_AUTO_VACUUM: {
105386 105650       Btree *pBt = pDb->pBt;
105387 105651       assert( pBt!=0 );
105388 105652       if( !zRight ){
105389         -      returnSingleInt(pParse, "auto_vacuum", sqlite3BtreeGetAutoVacuum(pBt));
       105653  +      returnSingleInt(v, "auto_vacuum", sqlite3BtreeGetAutoVacuum(pBt));
105390 105654       }else{
105391 105655         int eAuto = getAutoVacuum(zRight);
105392 105656         assert( eAuto>=0 && eAuto<=2 );
105393 105657         db->nextAutovac = (u8)eAuto;
105394 105658         /* Call SetAutoVacuum() to set initialize the internal auto and
105395 105659         ** incr-vacuum flags. This is required in case this connection
105396 105660         ** creates the database file. It is important that it is created
................................................................................
105460 105724     ** number of pages is adjusted so that the cache uses -N kibibytes
105461 105725     ** of memory.
105462 105726     */
105463 105727     case PragTyp_CACHE_SIZE: {
105464 105728       assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
105465 105729       if( !zRight ){
105466 105730         if( sqlite3ReadSchema(pParse) ) goto pragma_out;
105467         -      returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
       105731  +      returnSingleInt(v, "cache_size", pDb->pSchema->cache_size);
105468 105732       }else{
105469 105733         int size = sqlite3Atoi(zRight);
105470 105734         pDb->pSchema->cache_size = size;
105471 105735         sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
105472 105736         if( sqlite3ReadSchema(pParse) ) goto pragma_out;
105473 105737       }
105474 105738       break;
................................................................................
105506 105770       sz = -1;
105507 105771       rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_MMAP_SIZE, &sz);
105508 105772   #else
105509 105773       sz = 0;
105510 105774       rc = SQLITE_OK;
105511 105775   #endif
105512 105776       if( rc==SQLITE_OK ){
105513         -      returnSingleInt(pParse, "mmap_size", sz);
       105777  +      returnSingleInt(v, "mmap_size", sz);
105514 105778       }else if( rc!=SQLITE_NOTFOUND ){
105515 105779         pParse->nErr++;
105516 105780         pParse->rc = rc;
105517 105781       }
105518 105782       break;
105519 105783     }
105520 105784   
................................................................................
105527 105791     ** value will be restored the next time the database is opened.
105528 105792     **
105529 105793     ** Note that it is possible for the library compile-time options to
105530 105794     ** override this setting
105531 105795     */
105532 105796     case PragTyp_TEMP_STORE: {
105533 105797       if( !zRight ){
105534         -      returnSingleInt(pParse, "temp_store", db->temp_store);
       105798  +      returnSingleInt(v, "temp_store", db->temp_store);
105535 105799       }else{
105536 105800         changeTempStorage(pParse, zRight);
105537 105801       }
105538 105802       break;
105539 105803     }
105540 105804   
105541 105805     /*
................................................................................
105546 105810     ** the value sets a specific directory to be used for temporary files.
105547 105811     ** Setting to a null string reverts to the default temporary directory search.
105548 105812     ** If temporary directory is changed, then invalidateTempStorage.
105549 105813     **
105550 105814     */
105551 105815     case PragTyp_TEMP_STORE_DIRECTORY: {
105552 105816       if( !zRight ){
105553         -      if( sqlite3_temp_directory ){
105554         -        sqlite3VdbeSetNumCols(v, 1);
105555         -        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, 
105556         -            "temp_store_directory", SQLITE_STATIC);
105557         -        sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_temp_directory, 0);
105558         -        sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
105559         -      }
       105817  +      returnSingleText(v, "temp_store_directory", sqlite3_temp_directory);
105560 105818       }else{
105561 105819   #ifndef SQLITE_OMIT_WSD
105562 105820         if( zRight[0] ){
105563 105821           int res;
105564 105822           rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
105565 105823           if( rc!=SQLITE_OK || res==0 ){
105566 105824             sqlite3ErrorMsg(pParse, "not a writable directory");
................................................................................
105596 105854     ** a relative path will probably be based on the current directory for the
105597 105855     ** process.  Database file specified with an absolute path are not impacted
105598 105856     ** by this setting, regardless of its value.
105599 105857     **
105600 105858     */
105601 105859     case PragTyp_DATA_STORE_DIRECTORY: {
105602 105860       if( !zRight ){
105603         -      if( sqlite3_data_directory ){
105604         -        sqlite3VdbeSetNumCols(v, 1);
105605         -        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, 
105606         -            "data_store_directory", SQLITE_STATIC);
105607         -        sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_data_directory, 0);
105608         -        sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
105609         -      }
       105861  +      returnSingleText(v, "data_store_directory", sqlite3_data_directory);
105610 105862       }else{
105611 105863   #ifndef SQLITE_OMIT_WSD
105612 105864         if( zRight[0] ){
105613 105865           int res;
105614 105866           rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
105615 105867           if( rc!=SQLITE_OK || res==0 ){
105616 105868             sqlite3ErrorMsg(pParse, "not a writable directory");
................................................................................
105641 105893     case PragTyp_LOCK_PROXY_FILE: {
105642 105894       if( !zRight ){
105643 105895         Pager *pPager = sqlite3BtreePager(pDb->pBt);
105644 105896         char *proxy_file_path = NULL;
105645 105897         sqlite3_file *pFile = sqlite3PagerFile(pPager);
105646 105898         sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE, 
105647 105899                              &proxy_file_path);
105648         -      
105649         -      if( proxy_file_path ){
105650         -        sqlite3VdbeSetNumCols(v, 1);
105651         -        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, 
105652         -                              "lock_proxy_file", SQLITE_STATIC);
105653         -        sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, proxy_file_path, 0);
105654         -        sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
105655         -      }
       105900  +      returnSingleText(v, "lock_proxy_file", proxy_file_path);
105656 105901       }else{
105657 105902         Pager *pPager = sqlite3BtreePager(pDb->pBt);
105658 105903         sqlite3_file *pFile = sqlite3PagerFile(pPager);
105659 105904         int res;
105660 105905         if( zRight[0] ){
105661 105906           res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE, 
105662 105907                                        zRight);
................................................................................
105680 105925     ** Return or set the local value of the synchronous flag.  Changing
105681 105926     ** the local value does not make changes to the disk file and the
105682 105927     ** default value will be restored the next time the database is
105683 105928     ** opened.
105684 105929     */
105685 105930     case PragTyp_SYNCHRONOUS: {
105686 105931       if( !zRight ){
105687         -      returnSingleInt(pParse, "synchronous", pDb->safety_level-1);
       105932  +      returnSingleInt(v, "synchronous", pDb->safety_level-1);
105688 105933       }else{
105689 105934         if( !db->autoCommit ){
105690 105935           sqlite3ErrorMsg(pParse, 
105691 105936               "Safety level may not be changed inside a transaction");
105692 105937         }else{
105693 105938           int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK;
105694 105939           if( iLevel==0 ) iLevel = 1;
................................................................................
105699 105944       break;
105700 105945     }
105701 105946   #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
105702 105947   
105703 105948   #ifndef SQLITE_OMIT_FLAG_PRAGMAS
105704 105949     case PragTyp_FLAG: {
105705 105950       if( zRight==0 ){
105706         -      returnSingleInt(pParse, pPragma->zName, (db->flags & pPragma->iArg)!=0 );
       105951  +      returnSingleInt(v, pPragma->zName, (db->flags & pPragma->iArg)!=0 );
105707 105952       }else{
105708 105953         int mask = pPragma->iArg;    /* Mask of bits to set or clear. */
105709 105954         if( db->autoCommit==0 ){
105710 105955           /* Foreign key support may not be enabled or disabled while not
105711 105956           ** in auto-commit mode.  */
105712 105957           mask &= ~(SQLITE_ForeignKeys);
105713 105958         }
................................................................................
105749 105994     ** notnull:    True if 'NOT NULL' is part of column declaration
105750 105995     ** dflt_value: The default value for the column, if any.
105751 105996     */
105752 105997     case PragTyp_TABLE_INFO: if( zRight ){
105753 105998       Table *pTab;
105754 105999       pTab = sqlite3FindTable(db, zRight, zDb);
105755 106000       if( pTab ){
       106001  +      static const char *azCol[] = {
       106002  +         "cid", "name", "type", "notnull", "dflt_value", "pk"
       106003  +      };
105756 106004         int i, k;
105757 106005         int nHidden = 0;
105758 106006         Column *pCol;
105759 106007         Index *pPk = sqlite3PrimaryKeyIndex(pTab);
105760         -      sqlite3VdbeSetNumCols(v, 6);
105761 106008         pParse->nMem = 6;
105762 106009         sqlite3CodeVerifySchema(pParse, iDb);
105763         -      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC);
105764         -      sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
105765         -      sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", SQLITE_STATIC);
105766         -      sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", SQLITE_STATIC);
105767         -      sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", SQLITE_STATIC);
105768         -      sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", SQLITE_STATIC);
       106010  +      setAllColumnNames(v, 6, azCol); assert( 6==ArraySize(azCol) );
105769 106011         sqlite3ViewGetColumnNames(pParse, pTab);
105770 106012         for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
105771 106013           if( IsHiddenColumn(pCol) ){
105772 106014             nHidden++;
105773 106015             continue;
105774 106016           }
105775         -        sqlite3VdbeAddOp2(v, OP_Integer, i-nHidden, 1);
105776         -        sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pCol->zName, 0);
105777         -        sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
105778         -           pCol->zType ? pCol->zType : "", 0);
105779         -        sqlite3VdbeAddOp2(v, OP_Integer, (pCol->notNull ? 1 : 0), 4);
105780         -        if( pCol->zDflt ){
105781         -          sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pCol->zDflt, 0);
105782         -        }else{
105783         -          sqlite3VdbeAddOp2(v, OP_Null, 0, 5);
105784         -        }
105785 106017           if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
105786 106018             k = 0;
105787 106019           }else if( pPk==0 ){
105788 106020             k = 1;
105789 106021           }else{
105790 106022             for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
105791 106023           }
105792         -        sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
       106024  +        sqlite3VdbeMultiLoad(v, 1, "issisi",
       106025  +               i-nHidden,
       106026  +               pCol->zName,
       106027  +               pCol->zType ? pCol->zType : "",
       106028  +               pCol->notNull ? 1 : 0,
       106029  +               pCol->zDflt,
       106030  +               k);
105793 106031           sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
105794 106032         }
105795 106033       }
105796 106034     }
105797 106035     break;
105798 106036   
105799 106037     case PragTyp_STATS: {
       106038  +    static const char *azCol[] = { "table", "index", "width", "height" };
105800 106039       Index *pIdx;
105801 106040       HashElem *i;
105802 106041       v = sqlite3GetVdbe(pParse);
105803         -    sqlite3VdbeSetNumCols(v, 4);
105804 106042       pParse->nMem = 4;
105805 106043       sqlite3CodeVerifySchema(pParse, iDb);
105806         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC);
105807         -    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "index", SQLITE_STATIC);
105808         -    sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "width", SQLITE_STATIC);
105809         -    sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "height", SQLITE_STATIC);
       106044  +    setAllColumnNames(v, 4, azCol);  assert( 4==ArraySize(azCol) );
105810 106045       for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){
105811 106046         Table *pTab = sqliteHashData(i);
105812         -      sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, pTab->zName, 0);
105813         -      sqlite3VdbeAddOp2(v, OP_Null, 0, 2);
105814         -      sqlite3VdbeAddOp2(v, OP_Integer,
105815         -                           (int)sqlite3LogEstToInt(pTab->szTabRow), 3);
105816         -      sqlite3VdbeAddOp2(v, OP_Integer, 
105817         -          (int)sqlite3LogEstToInt(pTab->nRowLogEst), 4);
       106047  +      sqlite3VdbeMultiLoad(v, 1, "ssii",
       106048  +           pTab->zName,
       106049  +           0,
       106050  +           (int)sqlite3LogEstToInt(pTab->szTabRow),
       106051  +           (int)sqlite3LogEstToInt(pTab->nRowLogEst));
105818 106052         sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4);
105819 106053         for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
105820         -        sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0);
105821         -        sqlite3VdbeAddOp2(v, OP_Integer,
105822         -                             (int)sqlite3LogEstToInt(pIdx->szIdxRow), 3);
105823         -        sqlite3VdbeAddOp2(v, OP_Integer, 
105824         -            (int)sqlite3LogEstToInt(pIdx->aiRowLogEst[0]), 4);
       106054  +        sqlite3VdbeMultiLoad(v, 2, "sii",
       106055  +           pIdx->zName,
       106056  +           (int)sqlite3LogEstToInt(pIdx->szIdxRow),
       106057  +           (int)sqlite3LogEstToInt(pIdx->aiRowLogEst[0]));
105825 106058           sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4);
105826 106059         }
105827 106060       }
105828 106061     }
105829 106062     break;
105830 106063   
105831 106064     case PragTyp_INDEX_INFO: if( zRight ){
105832 106065       Index *pIdx;
105833 106066       Table *pTab;
105834 106067       pIdx = sqlite3FindIndex(db, zRight, zDb);
105835 106068       if( pIdx ){
       106069  +      static const char *azCol[] = {
       106070  +         "seqno", "cid", "name", "desc", "coll", "key"
       106071  +      };
105836 106072         int i;
105837 106073         int mx;
105838 106074         if( pPragma->iArg ){
105839 106075           /* PRAGMA index_xinfo (newer version with more rows and columns) */
105840 106076           mx = pIdx->nColumn;
105841 106077           pParse->nMem = 6;
105842 106078         }else{
105843 106079           /* PRAGMA index_info (legacy version) */
105844 106080           mx = pIdx->nKeyCol;
105845 106081           pParse->nMem = 3;
105846 106082         }
105847 106083         pTab = pIdx->pTable;
105848         -      sqlite3VdbeSetNumCols(v, pParse->nMem);
105849 106084         sqlite3CodeVerifySchema(pParse, iDb);
105850         -      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC);
105851         -      sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC);
105852         -      sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC);
105853         -      if( pPragma->iArg ){
105854         -        sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "desc", SQLITE_STATIC);
105855         -        sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "coll", SQLITE_STATIC);
105856         -        sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "key", SQLITE_STATIC);
105857         -      }
       106085  +      assert( pParse->nMem<=ArraySize(azCol) );
       106086  +      setAllColumnNames(v, pParse->nMem, azCol);
105858 106087         for(i=0; i<mx; i++){
105859 106088           i16 cnum = pIdx->aiColumn[i];
105860         -        sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
105861         -        sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2);
105862         -        if( cnum<0 ){
105863         -          sqlite3VdbeAddOp2(v, OP_Null, 0, 3);
105864         -        }else{
105865         -          sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
105866         -        }
       106089  +        sqlite3VdbeMultiLoad(v, 1, "iis", i, cnum,
       106090  +                             cnum<0 ? 0 : pTab->aCol[cnum].zName);
105867 106091           if( pPragma->iArg ){
105868         -          sqlite3VdbeAddOp2(v, OP_Integer, pIdx->aSortOrder[i], 4);
105869         -          sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, pIdx->azColl[i], 0);
105870         -          sqlite3VdbeAddOp2(v, OP_Integer, i<pIdx->nKeyCol, 6);
       106092  +          sqlite3VdbeMultiLoad(v, 4, "isi",
       106093  +            pIdx->aSortOrder[i],
       106094  +            pIdx->azColl[i],
       106095  +            i<pIdx->nKeyCol);
105871 106096           }
105872 106097           sqlite3VdbeAddOp2(v, OP_ResultRow, 1, pParse->nMem);
105873 106098         }
105874 106099       }
105875 106100     }
105876 106101     break;
105877 106102   
105878 106103     case PragTyp_INDEX_LIST: if( zRight ){
105879 106104       Index *pIdx;
105880 106105       Table *pTab;
105881 106106       int i;
105882 106107       pTab = sqlite3FindTable(db, zRight, zDb);
105883 106108       if( pTab ){
       106109  +      static const char *azCol[] = {
       106110  +        "seq", "name", "unique", "origin", "partial"
       106111  +      };
105884 106112         v = sqlite3GetVdbe(pParse);
105885         -      sqlite3VdbeSetNumCols(v, 5);
105886 106113         pParse->nMem = 5;
105887 106114         sqlite3CodeVerifySchema(pParse, iDb);
105888         -      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
105889         -      sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
105890         -      sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC);
105891         -      sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "origin", SQLITE_STATIC);
105892         -      sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "partial", SQLITE_STATIC);
       106115  +      setAllColumnNames(v, 5, azCol);  assert( 5==ArraySize(azCol) );
105893 106116         for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
105894 106117           const char *azOrigin[] = { "c", "u", "pk" };
105895         -        sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
105896         -        sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0);
105897         -        sqlite3VdbeAddOp2(v, OP_Integer, IsUniqueIndex(pIdx), 3);
105898         -        sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, azOrigin[pIdx->idxType], 0);
105899         -        sqlite3VdbeAddOp2(v, OP_Integer, pIdx->pPartIdxWhere!=0, 5);
       106118  +        sqlite3VdbeMultiLoad(v, 1, "isisi",
       106119  +           i,
       106120  +           pIdx->zName,
       106121  +           IsUniqueIndex(pIdx),
       106122  +           azOrigin[pIdx->idxType],
       106123  +           pIdx->pPartIdxWhere!=0);
105900 106124           sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 5);
105901 106125         }
105902 106126       }
105903 106127     }
105904 106128     break;
105905 106129   
105906 106130     case PragTyp_DATABASE_LIST: {
       106131  +    static const char *azCol[] = { "seq", "name", "file" };
105907 106132       int i;
105908         -    sqlite3VdbeSetNumCols(v, 3);
105909 106133       pParse->nMem = 3;
105910         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
105911         -    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
105912         -    sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", SQLITE_STATIC);
       106134  +    setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
105913 106135       for(i=0; i<db->nDb; i++){
105914 106136         if( db->aDb[i].pBt==0 ) continue;
105915 106137         assert( db->aDb[i].zName!=0 );
105916         -      sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
105917         -      sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0);
105918         -      sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
105919         -           sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
       106138  +      sqlite3VdbeMultiLoad(v, 1, "iss",
       106139  +         i,
       106140  +         db->aDb[i].zName,
       106141  +         sqlite3BtreeGetFilename(db->aDb[i].pBt));
105920 106142         sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
105921 106143       }
105922 106144     }
105923 106145     break;
105924 106146   
105925 106147     case PragTyp_COLLATION_LIST: {
       106148  +    static const char *azCol[] = { "seq", "name" };
105926 106149       int i = 0;
105927 106150       HashElem *p;
105928         -    sqlite3VdbeSetNumCols(v, 2);
105929 106151       pParse->nMem = 2;
105930         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
105931         -    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
       106152  +    setAllColumnNames(v, 2, azCol); assert( 2==ArraySize(azCol) );
105932 106153       for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
105933 106154         CollSeq *pColl = (CollSeq *)sqliteHashData(p);
105934         -      sqlite3VdbeAddOp2(v, OP_Integer, i++, 1);
105935         -      sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pColl->zName, 0);
       106155  +      sqlite3VdbeMultiLoad(v, 1, "is", i++, pColl->zName);
105936 106156         sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
105937 106157       }
105938 106158     }
105939 106159     break;
105940 106160   #endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */
105941 106161   
105942 106162   #ifndef SQLITE_OMIT_FOREIGN_KEY
................................................................................
105944 106164       FKey *pFK;
105945 106165       Table *pTab;
105946 106166       pTab = sqlite3FindTable(db, zRight, zDb);
105947 106167       if( pTab ){
105948 106168         v = sqlite3GetVdbe(pParse);
105949 106169         pFK = pTab->pFKey;
105950 106170         if( pFK ){
       106171  +        static const char *azCol[] = {
       106172  +           "id", "seq", "table", "from", "to", "on_update", "on_delete",
       106173  +           "match"
       106174  +        };
105951 106175           int i = 0; 
105952         -        sqlite3VdbeSetNumCols(v, 8);
105953 106176           pParse->nMem = 8;
105954 106177           sqlite3CodeVerifySchema(pParse, iDb);
105955         -        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", SQLITE_STATIC);
105956         -        sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", SQLITE_STATIC);
105957         -        sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", SQLITE_STATIC);
105958         -        sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", SQLITE_STATIC);
105959         -        sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", SQLITE_STATIC);
105960         -        sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "on_update", SQLITE_STATIC);
105961         -        sqlite3VdbeSetColName(v, 6, COLNAME_NAME, "on_delete", SQLITE_STATIC);
105962         -        sqlite3VdbeSetColName(v, 7, COLNAME_NAME, "match", SQLITE_STATIC);
       106178  +        setAllColumnNames(v, 8, azCol); assert( 8==ArraySize(azCol) );
105963 106179           while(pFK){
105964 106180             int j;
105965 106181             for(j=0; j<pFK->nCol; j++){
105966         -            char *zCol = pFK->aCol[j].zCol;
105967         -            char *zOnDelete = (char *)actionName(pFK->aAction[0]);
105968         -            char *zOnUpdate = (char *)actionName(pFK->aAction[1]);
105969         -            sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
105970         -            sqlite3VdbeAddOp2(v, OP_Integer, j, 2);
105971         -            sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pFK->zTo, 0);
105972         -            sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0,
105973         -                              pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
105974         -            sqlite3VdbeAddOp4(v, zCol ? OP_String8 : OP_Null, 0, 5, 0, zCol, 0);
105975         -            sqlite3VdbeAddOp4(v, OP_String8, 0, 6, 0, zOnUpdate, 0);
105976         -            sqlite3VdbeAddOp4(v, OP_String8, 0, 7, 0, zOnDelete, 0);
105977         -            sqlite3VdbeAddOp4(v, OP_String8, 0, 8, 0, "NONE", 0);
       106182  +            sqlite3VdbeMultiLoad(v, 1, "iissssss",
       106183  +                   i,
       106184  +                   j,
       106185  +                   pFK->zTo,
       106186  +                   pTab->aCol[pFK->aCol[j].iFrom].zName,
       106187  +                   pFK->aCol[j].zCol,
       106188  +                   actionName(pFK->aAction[1]),  /* ON UPDATE */
       106189  +                   actionName(pFK->aAction[0]),  /* ON DELETE */
       106190  +                   "NONE");
105978 106191               sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 8);
105979 106192             }
105980 106193             ++i;
105981 106194             pFK = pFK->pNextFrom;
105982 106195           }
105983 106196         }
105984 106197       }
................................................................................
105999 106212       int x;                 /* result variable */
106000 106213       int regResult;         /* 3 registers to hold a result row */
106001 106214       int regKey;            /* Register to hold key for checking the FK */
106002 106215       int regRow;            /* Registers to hold a row from pTab */
106003 106216       int addrTop;           /* Top of a loop checking foreign keys */
106004 106217       int addrOk;            /* Jump here if the key is OK */
106005 106218       int *aiCols;           /* child to parent column mapping */
       106219  +    static const char *azCol[] = { "table", "rowid", "parent", "fkid" };
106006 106220   
106007 106221       regResult = pParse->nMem+1;
106008 106222       pParse->nMem += 4;
106009 106223       regKey = ++pParse->nMem;
106010 106224       regRow = ++pParse->nMem;
106011 106225       v = sqlite3GetVdbe(pParse);
106012         -    sqlite3VdbeSetNumCols(v, 4);
106013         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC);
106014         -    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "rowid", SQLITE_STATIC);
106015         -    sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "parent", SQLITE_STATIC);
106016         -    sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "fkid", SQLITE_STATIC);
       106226  +    setAllColumnNames(v, 4, azCol); assert( 4==ArraySize(azCol) );
106017 106227       sqlite3CodeVerifySchema(pParse, iDb);
106018 106228       k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash);
106019 106229       while( k ){
106020 106230         if( zRight ){
106021 106231           pTab = sqlite3LocateTable(pParse, 0, zRight, zDb);
106022 106232           k = 0;
106023 106233         }else{
................................................................................
106024 106234           pTab = (Table*)sqliteHashData(k);
106025 106235           k = sqliteHashNext(k);
106026 106236         }
106027 106237         if( pTab==0 || pTab->pFKey==0 ) continue;
106028 106238         sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
106029 106239         if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow;
106030 106240         sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
106031         -      sqlite3VdbeAddOp4(v, OP_String8, 0, regResult, 0, pTab->zName,
106032         -                        P4_TRANSIENT);
       106241  +      sqlite3VdbeLoadString(v, regResult, pTab->zName);
106033 106242         for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
106034 106243           pParent = sqlite3FindTable(db, pFK->zTo, zDb);
106035 106244           if( pParent==0 ) continue;
106036 106245           pIdx = 0;
106037 106246           sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
106038 106247           x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0);
106039 106248           if( x==0 ){
................................................................................
106070 106279               sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); VdbeCoverage(v);
106071 106280               sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow, 
106072 106281                  sqlite3VdbeCurrentAddr(v)+3); VdbeCoverage(v);
106073 106282             }else{
106074 106283               sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow);
106075 106284             }
106076 106285             sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow); VdbeCoverage(v);
106077         -          sqlite3VdbeAddOp2(v, OP_Goto, 0, addrOk);
       106286  +          sqlite3VdbeGoto(v, addrOk);
106078 106287             sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
106079 106288           }else{
106080 106289             for(j=0; j<pFK->nCol; j++){
106081 106290               sqlite3ExprCodeGetColumnOfTable(v, pTab, 0,
106082 106291                               aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j);
106083 106292               sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
106084 106293             }
106085 106294             if( pParent ){
106086 106295               sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
106087         -                              sqlite3IndexAffinityStr(v,pIdx), pFK->nCol);
       106296  +                              sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
106088 106297               sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
106089 106298               VdbeCoverage(v);
106090 106299             }
106091 106300           }
106092 106301           sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
106093         -        sqlite3VdbeAddOp4(v, OP_String8, 0, regResult+2, 0, 
106094         -                          pFK->zTo, P4_TRANSIENT);
106095         -        sqlite3VdbeAddOp2(v, OP_Integer, i-1, regResult+3);
       106302  +        sqlite3VdbeMultiLoad(v, regResult+2, "si", pFK->zTo, i-1);
106096 106303           sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
106097 106304           sqlite3VdbeResolveLabel(v, addrOk);
106098 106305           sqlite3DbFree(db, aiCols);
106099 106306         }
106100 106307         sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v);
106101 106308         sqlite3VdbeJumpHere(v, addrTop);
106102 106309       }
................................................................................
106164 106371       ** of all attached databases.  */
106165 106372       assert( iDb>=0 );
106166 106373       assert( iDb==0 || pId2->z );
106167 106374       if( pId2->z==0 ) iDb = -1;
106168 106375   
106169 106376       /* Initialize the VDBE program */
106170 106377       pParse->nMem = 6;
106171         -    sqlite3VdbeSetNumCols(v, 1);
106172         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", SQLITE_STATIC);
       106378  +    setOneColumnName(v, "integrity_check");
106173 106379   
106174 106380       /* Set the maximum error count */
106175 106381       mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
106176 106382       if( zRight ){
106177 106383         sqlite3GetInt32(zRight, &mxErr);
106178 106384         if( mxErr<=0 ){
106179 106385           mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
................................................................................
106287 106493                                          pPrior, r1);
106288 106494             pPrior = pIdx;
106289 106495             sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1);  /* increment entry count */
106290 106496             /* Verify that an index entry exists for the current table row */
106291 106497             jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
106292 106498                                         pIdx->nColumn); VdbeCoverage(v);
106293 106499             sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
106294         -          sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, "row ", P4_STATIC);
       106500  +          sqlite3VdbeLoadString(v, 3, "row ");
106295 106501             sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
106296         -          sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, 
106297         -                            " missing from index ", P4_STATIC);
       106502  +          sqlite3VdbeLoadString(v, 4, " missing from index ");
106298 106503             sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
106299         -          jmp5 = sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0,
106300         -                                   pIdx->zName, P4_TRANSIENT);
       106504  +          jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName);
106301 106505             sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
106302 106506             sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
106303 106507             jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v);
106304 106508             sqlite3VdbeAddOp0(v, OP_Halt);
106305 106509             sqlite3VdbeJumpHere(v, jmp2);
106306 106510             /* For UNIQUE indexes, verify that only one entry exists with the
106307 106511             ** current key.  The entry is unique if (1) any column is NULL
................................................................................
106314 106518                 int iCol = pIdx->aiColumn[kk];
106315 106519                 assert( iCol>=0 && iCol<pTab->nCol );
106316 106520                 if( pTab->aCol[iCol].notNull ) continue;
106317 106521                 sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);
106318 106522                 VdbeCoverage(v);
106319 106523               }
106320 106524               jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v);
106321         -            sqlite3VdbeAddOp2(v, OP_Goto, 0, uniqOk);
       106525  +            sqlite3VdbeGoto(v, uniqOk);
106322 106526               sqlite3VdbeJumpHere(v, jmp6);
106323 106527               sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1,
106324 106528                                    pIdx->nKeyCol); VdbeCoverage(v);
106325 106529               sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
106326         -            sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
106327         -                              "non-unique entry in index ", P4_STATIC);
106328         -            sqlite3VdbeAddOp2(v, OP_Goto, 0, jmp5);
       106530  +            sqlite3VdbeLoadString(v, 3, "non-unique entry in index ");
       106531  +            sqlite3VdbeGoto(v, jmp5);
106329 106532               sqlite3VdbeResolveLabel(v, uniqOk);
106330 106533             }
106331 106534             sqlite3VdbeJumpHere(v, jmp4);
106332 106535             sqlite3ResolvePartIdxLabel(pParse, jmp3);
106333 106536           }
106334 106537           sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
106335 106538           sqlite3VdbeJumpHere(v, loopTop-1);
106336 106539   #ifndef SQLITE_OMIT_BTREECOUNT
106337         -        sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, 
106338         -                     "wrong # of entries in index ", P4_STATIC);
       106540  +        sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
106339 106541           for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
106340 106542             if( pPk==pIdx ) continue;
106341 106543             addr = sqlite3VdbeCurrentAddr(v);
106342 106544             sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); VdbeCoverage(v);
106343 106545             sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
106344 106546             sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
106345 106547             sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v);
106346 106548             sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
106347 106549             sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
106348         -          sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pIdx->zName, P4_TRANSIENT);
       106550  +          sqlite3VdbeLoadString(v, 3, pIdx->zName);
106349 106551             sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
106350 106552             sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1);
106351 106553           }
106352 106554   #endif /* SQLITE_OMIT_BTREECOUNT */
106353 106555         } 
106354 106556       }
106355 106557       addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
................................................................................
106397 106599         { "UTF-16",   0                  }, /* SQLITE_UTF16NATIVE */
106398 106600         { "UTF16",    0                  }, /* SQLITE_UTF16NATIVE */
106399 106601         { 0, 0 }
106400 106602       };
106401 106603       const struct EncName *pEnc;
106402 106604       if( !zRight ){    /* "PRAGMA encoding" */
106403 106605         if( sqlite3ReadSchema(pParse) ) goto pragma_out;
106404         -      sqlite3VdbeSetNumCols(v, 1);
106405         -      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", SQLITE_STATIC);
106406         -      sqlite3VdbeAddOp2(v, OP_String8, 0, 1);
106407 106606         assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 );
106408 106607         assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE );
106409 106608         assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE );
106410         -      sqlite3VdbeChangeP4(v, -1, encnames[ENC(pParse->db)].zName, P4_STATIC);
106411         -      sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
       106609  +      returnSingleText(v, "encoding", encnames[ENC(pParse->db)].zName);
106412 106610       }else{                        /* "PRAGMA encoding = XXX" */
106413 106611         /* Only change the value of sqlite.enc if the database handle is not
106414 106612         ** initialized. If the main database exists, the new sqlite.enc value
106415 106613         ** will be overwritten when the schema is next loaded. If it does not
106416 106614         ** already exists, it will be created to use the new encoding value.
106417 106615         */
106418 106616         if( 
................................................................................
106505 106703     **
106506 106704     ** Return the names of all compile-time options used in this build,
106507 106705     ** one option per row.
106508 106706     */
106509 106707     case PragTyp_COMPILE_OPTIONS: {
106510 106708       int i = 0;
106511 106709       const char *zOpt;
106512         -    sqlite3VdbeSetNumCols(v, 1);
106513 106710       pParse->nMem = 1;
106514         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "compile_option", SQLITE_STATIC);
       106711  +    setOneColumnName(v, "compile_option");
106515 106712       while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){
106516         -      sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zOpt, 0);
       106713  +      sqlite3VdbeLoadString(v, 1, zOpt);
106517 106714         sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
106518 106715       }
106519 106716     }
106520 106717     break;
106521 106718   #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
106522 106719   
106523 106720   #ifndef SQLITE_OMIT_WAL
106524 106721     /*
106525 106722     **   PRAGMA [database.]wal_checkpoint = passive|full|restart|truncate
106526 106723     **
106527 106724     ** Checkpoint the database.
106528 106725     */
106529 106726     case PragTyp_WAL_CHECKPOINT: {
       106727  +    static const char *azCol[] = { "busy", "log", "checkpointed" };
106530 106728       int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
106531 106729       int eMode = SQLITE_CHECKPOINT_PASSIVE;
106532 106730       if( zRight ){
106533 106731         if( sqlite3StrICmp(zRight, "full")==0 ){
106534 106732           eMode = SQLITE_CHECKPOINT_FULL;
106535 106733         }else if( sqlite3StrICmp(zRight, "restart")==0 ){
106536 106734           eMode = SQLITE_CHECKPOINT_RESTART;
106537 106735         }else if( sqlite3StrICmp(zRight, "truncate")==0 ){
106538 106736           eMode = SQLITE_CHECKPOINT_TRUNCATE;
106539 106737         }
106540 106738       }
106541         -    sqlite3VdbeSetNumCols(v, 3);
       106739  +    setAllColumnNames(v, 3, azCol);  assert( 3==ArraySize(azCol) );
106542 106740       pParse->nMem = 3;
106543         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "busy", SQLITE_STATIC);
106544         -    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "log", SQLITE_STATIC);
106545         -    sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "checkpointed", SQLITE_STATIC);
106546         -
106547 106741       sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1);
106548 106742       sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
106549 106743     }
106550 106744     break;
106551 106745   
106552 106746     /*
106553 106747     **   PRAGMA wal_autocheckpoint
................................................................................
106557 106751     ** after accumulating N frames in the log. Or query for the current value
106558 106752     ** of N.
106559 106753     */
106560 106754     case PragTyp_WAL_AUTOCHECKPOINT: {
106561 106755       if( zRight ){
106562 106756         sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
106563 106757       }
106564         -    returnSingleInt(pParse, "wal_autocheckpoint", 
       106758  +    returnSingleInt(v, "wal_autocheckpoint", 
106565 106759          db->xWalCallback==sqlite3WalDefaultHook ? 
106566 106760              SQLITE_PTR_TO_INT(db->pWalArg) : 0);
106567 106761     }
106568 106762     break;
106569 106763   #endif
106570 106764   
106571 106765     /*
................................................................................
106590 106784     ** disables the timeout.
106591 106785     */
106592 106786     /*case PragTyp_BUSY_TIMEOUT*/ default: {
106593 106787       assert( pPragma->ePragTyp==PragTyp_BUSY_TIMEOUT );
106594 106788       if( zRight ){
106595 106789         sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
106596 106790       }
106597         -    returnSingleInt(pParse, "timeout",  db->busyTimeout);
       106791  +    returnSingleInt(v, "timeout",  db->busyTimeout);
106598 106792       break;
106599 106793     }
106600 106794   
106601 106795     /*
106602 106796     **   PRAGMA soft_heap_limit
106603 106797     **   PRAGMA soft_heap_limit = N
106604 106798     **
................................................................................
106610 106804     ** sqlite3_soft_heap_limit64(-1) C-language function.
106611 106805     */
106612 106806     case PragTyp_SOFT_HEAP_LIMIT: {
106613 106807       sqlite3_int64 N;
106614 106808       if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
106615 106809         sqlite3_soft_heap_limit64(N);
106616 106810       }
106617         -    returnSingleInt(pParse, "soft_heap_limit",  sqlite3_soft_heap_limit64(-1));
       106811  +    returnSingleInt(v, "soft_heap_limit",  sqlite3_soft_heap_limit64(-1));
106618 106812       break;
106619 106813     }
106620 106814   
106621 106815     /*
106622 106816     **   PRAGMA threads
106623 106817     **   PRAGMA threads = N
106624 106818     **
................................................................................
106629 106823       sqlite3_int64 N;
106630 106824       if( zRight
106631 106825        && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK
106632 106826        && N>=0
106633 106827       ){
106634 106828         sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff));
106635 106829       }
106636         -    returnSingleInt(pParse, "threads",
       106830  +    returnSingleInt(v, "threads",
106637 106831                       sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, -1));
106638 106832       break;
106639 106833     }
106640 106834   
106641 106835   #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
106642 106836     /*
106643 106837     ** Report the current state of file logs for all databases
106644 106838     */
106645 106839     case PragTyp_LOCK_STATUS: {
106646 106840       static const char *const azLockName[] = {
106647 106841         "unlocked", "shared", "reserved", "pending", "exclusive"
106648 106842       };
       106843  +    static const char *azCol[] = { "database", "status" };
106649 106844       int i;
106650         -    sqlite3VdbeSetNumCols(v, 2);
       106845  +    setAllColumnNames(v, 2, azCol); assert( 2==ArraySize(azCol) );
106651 106846       pParse->nMem = 2;
106652         -    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", SQLITE_STATIC);
106653         -    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", SQLITE_STATIC);
106654 106847       for(i=0; i<db->nDb; i++){
106655 106848         Btree *pBt;
106656 106849         const char *zState = "unknown";
106657 106850         int j;
106658 106851         if( db->aDb[i].zName==0 ) continue;
106659         -      sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, db->aDb[i].zName, P4_STATIC);
106660 106852         pBt = db->aDb[i].pBt;
106661 106853         if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
106662 106854           zState = "closed";
106663 106855         }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0, 
106664 106856                                        SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
106665 106857            zState = azLockName[j];
106666 106858         }
106667         -      sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, zState, P4_STATIC);
       106859  +      sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zName, zState);
106668 106860         sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
106669 106861       }
106670 106862       break;
106671 106863     }
106672 106864   #endif
106673 106865   
106674 106866   #ifdef SQLITE_HAS_CODEC
................................................................................
108025 108217     pRight = &pLeft[1];
108026 108218     for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
108027 108219       Table *pLeftTab = pLeft->pTab;
108028 108220       Table *pRightTab = pRight->pTab;
108029 108221       int isOuter;
108030 108222   
108031 108223       if( NEVER(pLeftTab==0 || pRightTab==0) ) continue;
108032         -    isOuter = (pRight->jointype & JT_OUTER)!=0;
       108224  +    isOuter = (pRight->fg.jointype & JT_OUTER)!=0;
108033 108225   
108034 108226       /* When the NATURAL keyword is present, add WHERE clause terms for
108035 108227       ** every column that the two tables have in common.
108036 108228       */
108037         -    if( pRight->jointype & JT_NATURAL ){
       108229  +    if( pRight->fg.jointype & JT_NATURAL ){
108038 108230         if( pRight->pOn || pRight->pUsing ){
108039 108231           sqlite3ErrorMsg(pParse, "a NATURAL join may not have "
108040 108232              "an ON or USING clause", 0);
108041 108233           return 1;
108042 108234         }
108043 108235         for(j=0; j<pRightTab->nCol; j++){
108044 108236           char *zName;   /* Name of column in the right table */
................................................................................
108115 108307   ** through regData+nData-1 onto the sorter.
108116 108308   */
108117 108309   static void pushOntoSorter(
108118 108310     Parse *pParse,         /* Parser context */
108119 108311     SortCtx *pSort,        /* Information about the ORDER BY clause */
108120 108312     Select *pSelect,       /* The whole SELECT statement */
108121 108313     int regData,           /* First register holding data to be sorted */
       108314  +  int regOrigData,       /* First register holding data before packing */
108122 108315     int nData,             /* Number of elements in the data array */
108123 108316     int nPrefixReg         /* No. of reg prior to regData available for use */
108124 108317   ){
108125 108318     Vdbe *v = pParse->pVdbe;                         /* Stmt under construction */
108126 108319     int bSeq = ((pSort->sortFlags & SORTFLAG_UseSorter)==0);
108127 108320     int nExpr = pSort->pOrderBy->nExpr;              /* No. of ORDER BY terms */
108128 108321     int nBase = nExpr + bSeq + nData;                /* Fields in sorter record */
108129 108322     int regBase;                                     /* Regs for sorter record */
108130 108323     int regRecord = ++pParse->nMem;                  /* Assembled sorter record */
108131 108324     int nOBSat = pSort->nOBSat;                      /* ORDER BY terms to skip */
108132 108325     int op;                            /* Opcode to add sorter record to sorter */
108133 108326   
108134 108327     assert( bSeq==0 || bSeq==1 );
       108328  +  assert( nData==1 || regData==regOrigData );
108135 108329     if( nPrefixReg ){
108136 108330       assert( nPrefixReg==nExpr+bSeq );
108137 108331       regBase = regData - nExpr - bSeq;
108138 108332     }else{
108139 108333       regBase = pParse->nMem + 1;
108140 108334       pParse->nMem += nBase;
108141 108335     }
108142         -  sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, SQLITE_ECEL_DUP);
       108336  +  sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, regOrigData,
       108337  +                          SQLITE_ECEL_DUP|SQLITE_ECEL_REF);
108143 108338     if( bSeq ){
108144 108339       sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr);
108145 108340     }
108146 108341     if( nPrefixReg==0 ){
108147 108342       sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+bSeq, nData);
108148 108343     }
108149 108344   
................................................................................
108213 108408     Vdbe *v,          /* Generate code into this VM */
108214 108409     int iOffset,      /* Register holding the offset counter */
108215 108410     int iContinue     /* Jump here to skip the current record */
108216 108411   ){
108217 108412     if( iOffset>0 ){
108218 108413       int addr;
108219 108414       addr = sqlite3VdbeAddOp3(v, OP_IfNeg, iOffset, 0, -1); VdbeCoverage(v);
108220         -    sqlite3VdbeAddOp2(v, OP_Goto, 0, iContinue);
       108415  +    sqlite3VdbeGoto(v, iContinue);
108221 108416       VdbeComment((v, "skip OFFSET records"));
108222 108417       sqlite3VdbeJumpHere(v, addr);
108223 108418     }
108224 108419   }
108225 108420   
108226 108421   /*
108227 108422   ** Add code that will check to make sure the N registers starting at iMem
................................................................................
108345 108540       */
108346 108541       u8 ecelFlags;
108347 108542       if( eDest==SRT_Mem || eDest==SRT_Output || eDest==SRT_Coroutine ){
108348 108543         ecelFlags = SQLITE_ECEL_DUP;
108349 108544       }else{
108350 108545         ecelFlags = 0;
108351 108546       }
108352         -    sqlite3ExprCodeExprList(pParse, pEList, regResult, ecelFlags);
       108547  +    sqlite3ExprCodeExprList(pParse, pEList, regResult, 0, ecelFlags);
108353 108548     }
108354 108549   
108355 108550     /* If the DISTINCT keyword was present on the SELECT statement
108356 108551     ** and this row has been seen before, then do not make this row
108357 108552     ** part of the result.
108358 108553     */
108359 108554     if( hasDistinct ){
................................................................................
108461 108656           sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0);
108462 108657           VdbeCoverage(v);
108463 108658           sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r1);
108464 108659           assert( pSort==0 );
108465 108660         }
108466 108661   #endif
108467 108662         if( pSort ){
108468         -        pushOntoSorter(pParse, pSort, p, r1+nPrefixReg, 1, nPrefixReg);
       108663  +        pushOntoSorter(pParse, pSort, p, r1+nPrefixReg,regResult,1,nPrefixReg);
108469 108664         }else{
108470 108665           int r2 = sqlite3GetTempReg(pParse);
108471 108666           sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, r2);
108472 108667           sqlite3VdbeAddOp3(v, OP_Insert, iParm, r1, r2);
108473 108668           sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
108474 108669           sqlite3ReleaseTempReg(pParse, r2);
108475 108670         }
................................................................................
108487 108682         pDest->affSdst =
108488 108683                     sqlite3CompareAffinity(pEList->a[0].pExpr, pDest->affSdst);
108489 108684         if( pSort ){
108490 108685           /* At first glance you would think we could optimize out the
108491 108686           ** ORDER BY in this case since the order of entries in the set
108492 108687           ** does not matter.  But there might be a LIMIT clause, in which
108493 108688           ** case the order does matter */
108494         -        pushOntoSorter(pParse, pSort, p, regResult, 1, nPrefixReg);
       108689  +        pushOntoSorter(pParse, pSort, p, regResult, regResult, 1, nPrefixReg);
108495 108690         }else{
108496 108691           int r1 = sqlite3GetTempReg(pParse);
108497 108692           sqlite3VdbeAddOp4(v, OP_MakeRecord, regResult,1,r1, &pDest->affSdst, 1);
108498 108693           sqlite3ExprCacheAffinityChange(pParse, regResult, 1);
108499 108694           sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1);
108500 108695           sqlite3ReleaseTempReg(pParse, r1);
108501 108696         }
................................................................................
108513 108708       /* If this is a scalar select that is part of an expression, then
108514 108709       ** store the results in the appropriate memory cell and break out
108515 108710       ** of the scan loop.
108516 108711       */
108517 108712       case SRT_Mem: {
108518 108713         assert( nResultCol==1 );
108519 108714         if( pSort ){
108520         -        pushOntoSorter(pParse, pSort, p, regResult, 1, nPrefixReg);
       108715  +        pushOntoSorter(pParse, pSort, p, regResult, regResult, 1, nPrefixReg);
108521 108716         }else{
108522 108717           assert( regResult==iParm );
108523 108718           /* The LIMIT clause will jump out of the loop for us */
108524 108719         }
108525 108720         break;
108526 108721       }
108527 108722   #endif /* #ifndef SQLITE_OMIT_SUBQUERY */
108528 108723   
108529 108724       case SRT_Coroutine:       /* Send data to a co-routine */
108530 108725       case SRT_Output: {        /* Return the results */
108531 108726         testcase( eDest==SRT_Coroutine );
108532 108727         testcase( eDest==SRT_Output );
108533 108728         if( pSort ){
108534         -        pushOntoSorter(pParse, pSort, p, regResult, nResultCol, nPrefixReg);
       108729  +        pushOntoSorter(pParse, pSort, p, regResult, regResult, nResultCol,
       108730  +                       nPrefixReg);
108535 108731         }else if( eDest==SRT_Coroutine ){
108536 108732           sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
108537 108733         }else{
108538 108734           sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, nResultCol);
108539 108735           sqlite3ExprCacheAffinityChange(pParse, regResult, nResultCol);
108540 108736         }
108541 108737         break;
................................................................................
108821 109017     int bSeq;                       /* True if sorter record includes seq. no. */
108822 109018   #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
108823 109019     struct ExprList_item *aOutEx = p->pEList->a;
108824 109020   #endif
108825 109021   
108826 109022     if( pSort->labelBkOut ){
108827 109023       sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
108828         -    sqlite3VdbeAddOp2(v, OP_Goto, 0, addrBreak);
       109024  +    sqlite3VdbeGoto(v, addrBreak);
108829 109025       sqlite3VdbeResolveLabel(v, pSort->labelBkOut);
108830 109026     }
108831 109027     iTab = pSort->iECursor;
108832 109028     if( eDest==SRT_Output || eDest==SRT_Coroutine ){
108833 109029       regRowid = 0;
108834 109030       regRow = pDest->iSdst;
108835 109031       nSortData = nColumn;
................................................................................
109206 109402   **
109207 109403   ** Only the column names are computed.  Column.zType, Column.zColl,
109208 109404   ** and other fields of Column are zeroed.
109209 109405   **
109210 109406   ** Return SQLITE_OK on success.  If a memory allocation error occurs,
109211 109407   ** store NULL in *paCol and 0 in *pnCol and return SQLITE_NOMEM.
109212 109408   */
109213         -static int selectColumnsFromExprList(
       109409  +SQLITE_PRIVATE int sqlite3ColumnsFromExprList(
109214 109410     Parse *pParse,          /* Parsing context */
109215 109411     ExprList *pEList,       /* Expr list from which to derive column names */
109216 109412     i16 *pnCol,             /* Write the number of columns here */
109217 109413     Column **paCol          /* Write the new column list here */
109218 109414   ){
109219 109415     sqlite3 *db = pParse->db;   /* Database connection */
109220 109416     int i, j;                   /* Loop counters */
................................................................................
109373 109569     }
109374 109570     /* The sqlite3ResultSetOfSelect() is only used n contexts where lookaside
109375 109571     ** is disabled */
109376 109572     assert( db->lookaside.bEnabled==0 );
109377 109573     pTab->nRef = 1;
109378 109574     pTab->zName = 0;
109379 109575     pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
109380         -  selectColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
       109576  +  sqlite3ColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
109381 109577     selectAddColumnTypeAndCollation(pParse, pTab, pSelect);
109382 109578     pTab->iPKey = -1;
109383 109579     if( db->mallocFailed ){
109384 109580       sqlite3DeleteTable(db, pTab);
109385 109581       return 0;
109386 109582     }
109387 109583     return pTab;
................................................................................
109449 109645       p->iLimit = iLimit = ++pParse->nMem;
109450 109646       v = sqlite3GetVdbe(pParse);
109451 109647       assert( v!=0 );
109452 109648       if( sqlite3ExprIsInteger(p->pLimit, &n) ){
109453 109649         sqlite3VdbeAddOp2(v, OP_Integer, n, iLimit);
109454 109650         VdbeComment((v, "LIMIT counter"));
109455 109651         if( n==0 ){
109456         -        sqlite3VdbeAddOp2(v, OP_Goto, 0, iBreak);
       109652  +        sqlite3VdbeGoto(v, iBreak);
109457 109653         }else if( n>=0 && p->nSelectRow>(u64)n ){
109458 109654           p->nSelectRow = n;
109459 109655         }
109460 109656       }else{
109461 109657         sqlite3ExprCode(pParse, p->pLimit, iLimit);
109462 109658         sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); VdbeCoverage(v);
109463 109659         VdbeComment((v, "LIMIT counter"));
................................................................................
109552 109748   **
109553 109749   **   <recursive-table> AS (<setup-query> UNION [ALL] <recursive-query>)
109554 109750   **                         \___________/             \_______________/
109555 109751   **                           p->pPrior                      p
109556 109752   **
109557 109753   **
109558 109754   ** There is exactly one reference to the recursive-table in the FROM clause
109559         -** of recursive-query, marked with the SrcList->a[].isRecursive flag.
       109755  +** of recursive-query, marked with the SrcList->a[].fg.isRecursive flag.
109560 109756   **
109561 109757   ** The setup-query runs once to generate an initial set of rows that go
109562 109758   ** into a Queue table.  Rows are extracted from the Queue table one by
109563 109759   ** one.  Each row extracted from Queue is output to pDest.  Then the single
109564 109760   ** extracted row (now in the iCurrent table) becomes the content of the
109565 109761   ** recursive-table for a recursive-query run.  The output of the recursive-query
109566 109762   ** is added back into the Queue table.  Then another row is extracted from Queue
................................................................................
109617 109813     regOffset = p->iOffset;
109618 109814     p->pLimit = p->pOffset = 0;
109619 109815     p->iLimit = p->iOffset = 0;
109620 109816     pOrderBy = p->pOrderBy;
109621 109817   
109622 109818     /* Locate the cursor number of the Current table */
109623 109819     for(i=0; ALWAYS(i<pSrc->nSrc); i++){
109624         -    if( pSrc->a[i].isRecursive ){
       109820  +    if( pSrc->a[i].fg.isRecursive ){
109625 109821         iCurrent = pSrc->a[i].iCursor;
109626 109822         break;
109627 109823       }
109628 109824     }
109629 109825   
109630 109826     /* Allocate cursors numbers for Queue and Distinct.  The cursor number for
109631 109827     ** the Distinct table must be exactly one greater than Queue in order
................................................................................
109697 109893       p->pPrior = 0;
109698 109894       sqlite3Select(pParse, p, &destQueue);
109699 109895       assert( p->pPrior==0 );
109700 109896       p->pPrior = pSetup;
109701 109897     }
109702 109898   
109703 109899     /* Keep running the loop until the Queue is empty */
109704         -  sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
       109900  +  sqlite3VdbeGoto(v, addrTop);
109705 109901     sqlite3VdbeResolveLabel(v, addrBreak);
109706 109902   
109707 109903   end_of_recursive_query:
109708 109904     sqlite3ExprListDelete(pParse->db, p->pOrderBy);
109709 109905     p->pOrderBy = pOrderBy;
109710 109906     p->pLimit = pLimit;
109711 109907     p->pOffset = pOffset;
................................................................................
110606 110802     if( op==TK_EXCEPT || op==TK_INTERSECT ){
110607 110803       addrEofA_noB = addrEofA = labelEnd;
110608 110804     }else{  
110609 110805       VdbeNoopComment((v, "eof-A subroutine"));
110610 110806       addrEofA = sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
110611 110807       addrEofA_noB = sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, labelEnd);
110612 110808                                        VdbeCoverage(v);
110613         -    sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofA);
       110809  +    sqlite3VdbeGoto(v, addrEofA);
110614 110810       p->nSelectRow += pPrior->nSelectRow;
110615 110811     }
110616 110812   
110617 110813     /* Generate a subroutine to run when the results from select B
110618 110814     ** are exhausted and only data in select A remains.
110619 110815     */
110620 110816     if( op==TK_INTERSECT ){
110621 110817       addrEofB = addrEofA;
110622 110818       if( p->nSelectRow > pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow;
110623 110819     }else{  
110624 110820       VdbeNoopComment((v, "eof-B subroutine"));
110625 110821       addrEofB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
110626 110822       sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, labelEnd); VdbeCoverage(v);
110627         -    sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofB);
       110823  +    sqlite3VdbeGoto(v, addrEofB);
110628 110824     }
110629 110825   
110630 110826     /* Generate code to handle the case of A<B
110631 110827     */
110632 110828     VdbeNoopComment((v, "A-lt-B subroutine"));
110633 110829     addrAltB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
110634 110830     sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
110635         -  sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
       110831  +  sqlite3VdbeGoto(v, labelCmpr);
110636 110832   
110637 110833     /* Generate code to handle the case of A==B
110638 110834     */
110639 110835     if( op==TK_ALL ){
110640 110836       addrAeqB = addrAltB;
110641 110837     }else if( op==TK_INTERSECT ){
110642 110838       addrAeqB = addrAltB;
110643 110839       addrAltB++;
110644 110840     }else{
110645 110841       VdbeNoopComment((v, "A-eq-B subroutine"));
110646 110842       addrAeqB =
110647 110843       sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
110648         -    sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
       110844  +    sqlite3VdbeGoto(v, labelCmpr);
110649 110845     }
110650 110846   
110651 110847     /* Generate code to handle the case of A>B
110652 110848     */
110653 110849     VdbeNoopComment((v, "A-gt-B subroutine"));
110654 110850     addrAgtB = sqlite3VdbeCurrentAddr(v);
110655 110851     if( op==TK_ALL || op==TK_UNION ){
110656 110852       sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
110657 110853     }
110658 110854     sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
110659         -  sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
       110855  +  sqlite3VdbeGoto(v, labelCmpr);
110660 110856   
110661 110857     /* This code runs once to initialize everything.
110662 110858     */
110663 110859     sqlite3VdbeJumpHere(v, j1);
110664 110860     sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA_noB); VdbeCoverage(v);
110665 110861     sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
110666 110862   
................................................................................
111032 111228     ** effectively converts the OUTER JOIN into an INNER JOIN.
111033 111229     **
111034 111230     ** THIS OVERRIDES OBSOLETE COMMENTS 1 AND 2 ABOVE:
111035 111231     ** Ticket #3300 shows that flattening the right term of a LEFT JOIN
111036 111232     ** is fraught with danger.  Best to avoid the whole thing.  If the
111037 111233     ** subquery is the right term of a LEFT JOIN, then do not flatten.
111038 111234     */
111039         -  if( (pSubitem->jointype & JT_OUTER)!=0 ){
       111235  +  if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
111040 111236       return 0;
111041 111237     }
111042 111238   
111043 111239     /* Restriction 17: If the sub-query is a compound SELECT, then it must
111044 111240     ** use only the UNION ALL operator. And none of the simple select queries
111045 111241     ** that make up the compound SELECT are allowed to be aggregate or distinct
111046 111242     ** queries.
................................................................................
111203 111399       u8 jointype = 0;
111204 111400       pSubSrc = pSub->pSrc;     /* FROM clause of subquery */
111205 111401       nSubSrc = pSubSrc->nSrc;  /* Number of terms in subquery FROM clause */
111206 111402       pSrc = pParent->pSrc;     /* FROM clause of the outer query */
111207 111403   
111208 111404       if( pSrc ){
111209 111405         assert( pParent==p );  /* First time through the loop */
111210         -      jointype = pSubitem->jointype;
       111406  +      jointype = pSubitem->fg.jointype;
111211 111407       }else{
111212 111408         assert( pParent!=p );  /* 2nd and subsequent times through the loop */
111213 111409         pSrc = pParent->pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
111214 111410         if( pSrc==0 ){
111215 111411           assert( db->mallocFailed );
111216 111412           break;
111217 111413         }
................................................................................
111243 111439       ** outer query.
111244 111440       */
111245 111441       for(i=0; i<nSubSrc; i++){
111246 111442         sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
111247 111443         pSrc->a[i+iFrom] = pSubSrc->a[i];
111248 111444         memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
111249 111445       }
111250         -    pSrc->a[iFrom].jointype = jointype;
       111446  +    pSrc->a[iFrom].fg.jointype = jointype;
111251 111447     
111252 111448       /* Now begin substituting subquery result set expressions for 
111253 111449       ** references to the iParent in the outer query.
111254 111450       ** 
111255 111451       ** Example:
111256 111452       **
111257 111453       **   SELECT a+5, b*10 FROM (SELECT x*3 AS a, y+10 AS b FROM t1) WHERE a>b;
................................................................................
111375 111571   **
111376 111572   **   (3) The inner query has a LIMIT clause (since the changes to the WHERE
111377 111573   **       close would change the meaning of the LIMIT).
111378 111574   **
111379 111575   **   (4) The inner query is the right operand of a LEFT JOIN.  (The caller
111380 111576   **       enforces this restriction since this routine does not have enough
111381 111577   **       information to know.)
       111578  +**
       111579  +**   (5) The WHERE clause expression originates in the ON or USING clause
       111580  +**       of a LEFT JOIN.
111382 111581   **
111383 111582   ** Return 0 if no changes are made and non-zero if one or more WHERE clause
111384 111583   ** terms are duplicated into the subquery.
111385 111584   */
111386 111585   static int pushDownWhereTerms(
111387 111586     sqlite3 *db,          /* The database connection (for malloc()) */
111388 111587     Select *pSubq,        /* The subquery whose WHERE clause is to be augmented */
................................................................................
111398 111597     if( pSubq->pLimit!=0 ){
111399 111598        return 0; /* restriction (3) */
111400 111599     }
111401 111600     while( pWhere->op==TK_AND ){
111402 111601       nChng += pushDownWhereTerms(db, pSubq, pWhere->pRight, iCursor);
111403 111602       pWhere = pWhere->pLeft;
111404 111603     }
       111604  +  if( ExprHasProperty(pWhere,EP_FromJoin) ) return 0; /* restriction 5 */
111405 111605     if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
111406 111606       nChng++;
111407 111607       while( pSubq ){
111408 111608         pNew = sqlite3ExprDup(db, pWhere, 0);
111409 111609         pNew = substExpr(db, pNew, iCursor, pSubq->pEList);
111410 111610         pSubq->pWhere = sqlite3ExprAnd(db, pSubq->pWhere, pNew);
111411 111611         pSubq = pSubq->pPrior;
................................................................................
111494 111694   ** If the source-list item passed as an argument was augmented with an
111495 111695   ** INDEXED BY clause, then try to locate the specified index. If there
111496 111696   ** was such a clause and the named index cannot be found, return 
111497 111697   ** SQLITE_ERROR and leave an error in pParse. Otherwise, populate 
111498 111698   ** pFrom->pIndex and return SQLITE_OK.
111499 111699   */
111500 111700   SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *pParse, struct SrcList_item *pFrom){
111501         -  if( pFrom->pTab && pFrom->zIndexedBy ){
       111701  +  if( pFrom->pTab && pFrom->fg.isIndexedBy ){
111502 111702       Table *pTab = pFrom->pTab;
111503         -    char *zIndexedBy = pFrom->zIndexedBy;
       111703  +    char *zIndexedBy = pFrom->u1.zIndexedBy;
111504 111704       Index *pIdx;
111505 111705       for(pIdx=pTab->pIndex; 
111506 111706           pIdx && sqlite3StrICmp(pIdx->zName, zIndexedBy); 
111507 111707           pIdx=pIdx->pNext
111508 111708       );
111509 111709       if( !pIdx ){
111510 111710         sqlite3ErrorMsg(pParse, "no such index: %s", zIndexedBy, 0);
111511 111711         pParse->checkSchema = 1;
111512 111712         return SQLITE_ERROR;
111513 111713       }
111514         -    pFrom->pIndex = pIdx;
       111714  +    pFrom->pIBIndex = pIdx;
111515 111715     }
111516 111716     return SQLITE_OK;
111517 111717   }
111518 111718   /*
111519 111719   ** Detect compound SELECT statements that use an ORDER BY clause with 
111520 111720   ** an alternative collating sequence.
111521 111721   **
................................................................................
111668 111868       Table *pTab;
111669 111869       ExprList *pEList;
111670 111870       Select *pSel;
111671 111871       Select *pLeft;                /* Left-most SELECT statement */
111672 111872       int bMayRecursive;            /* True if compound joined by UNION [ALL] */
111673 111873       With *pSavedWith;             /* Initial value of pParse->pWith */
111674 111874   
111675         -    /* If pCte->zErr is non-NULL at this point, then this is an illegal
       111875  +    /* If pCte->zCteErr is non-NULL at this point, then this is an illegal
111676 111876       ** recursive reference to CTE pCte. Leave an error in pParse and return
111677         -    ** early. If pCte->zErr is NULL, then this is not a recursive reference.
       111877  +    ** early. If pCte->zCteErr is NULL, then this is not a recursive reference.
111678 111878       ** In this case, proceed.  */
111679         -    if( pCte->zErr ){
111680         -      sqlite3ErrorMsg(pParse, pCte->zErr, pCte->zName);
       111879  +    if( pCte->zCteErr ){
       111880  +      sqlite3ErrorMsg(pParse, pCte->zCteErr, pCte->zName);
111681 111881         return SQLITE_ERROR;
111682 111882       }
111683 111883   
111684 111884       assert( pFrom->pTab==0 );
111685 111885       pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
111686 111886       if( pTab==0 ) return WRC_Abort;
111687 111887       pTab->nRef = 1;
................................................................................
111702 111902         for(i=0; i<pSrc->nSrc; i++){
111703 111903           struct SrcList_item *pItem = &pSrc->a[i];
111704 111904           if( pItem->zDatabase==0 
111705 111905            && pItem->zName!=0 
111706 111906            && 0==sqlite3StrICmp(pItem->zName, pCte->zName)
111707 111907             ){
111708 111908             pItem->pTab = pTab;
111709         -          pItem->isRecursive = 1;
       111909  +          pItem->fg.isRecursive = 1;
111710 111910             pTab->nRef++;
111711 111911             pSel->selFlags |= SF_Recursive;
111712 111912           }
111713 111913         }
111714 111914       }
111715 111915   
111716 111916       /* Only one recursive reference is permitted. */ 
................................................................................
111718 111918         sqlite3ErrorMsg(
111719 111919             pParse, "multiple references to recursive table: %s", pCte->zName
111720 111920         );
111721 111921         return SQLITE_ERROR;
111722 111922       }
111723 111923       assert( pTab->nRef==1 || ((pSel->selFlags&SF_Recursive) && pTab->nRef==2 ));
111724 111924   
111725         -    pCte->zErr = "circular reference: %s";
       111925  +    pCte->zCteErr = "circular reference: %s";
111726 111926       pSavedWith = pParse->pWith;
111727 111927       pParse->pWith = pWith;
111728 111928       sqlite3WalkSelect(pWalker, bMayRecursive ? pSel->pPrior : pSel);
111729 111929   
111730 111930       for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior);
111731 111931       pEList = pLeft->pEList;
111732 111932       if( pCte->pCols ){
................................................................................
111736 111936           );
111737 111937           pParse->pWith = pSavedWith;
111738 111938           return SQLITE_ERROR;
111739 111939         }
111740 111940         pEList = pCte->pCols;
111741 111941       }
111742 111942   
111743         -    selectColumnsFromExprList(pParse, pEList, &pTab->nCol, &pTab->aCol);
       111943  +    sqlite3ColumnsFromExprList(pParse, pEList, &pTab->nCol, &pTab->aCol);
111744 111944       if( bMayRecursive ){
111745 111945         if( pSel->selFlags & SF_Recursive ){
111746         -        pCte->zErr = "multiple recursive references: %s";
       111946  +        pCte->zCteErr = "multiple recursive references: %s";
111747 111947         }else{
111748         -        pCte->zErr = "recursive reference in a subquery: %s";
       111948  +        pCte->zCteErr = "recursive reference in a subquery: %s";
111749 111949         }
111750 111950         sqlite3WalkSelect(pWalker, pSel);
111751 111951       }
111752         -    pCte->zErr = 0;
       111952  +    pCte->zCteErr = 0;
111753 111953       pParse->pWith = pSavedWith;
111754 111954     }
111755 111955   
111756 111956     return SQLITE_OK;
111757 111957   }
111758 111958   #endif
111759 111959   
................................................................................
111832 112032   
111833 112033     /* Look up every table named in the FROM clause of the select.  If
111834 112034     ** an entry of the FROM clause is a subquery instead of a table or view,
111835 112035     ** then create a transient table structure to describe the subquery.
111836 112036     */
111837 112037     for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
111838 112038       Table *pTab;
111839         -    assert( pFrom->isRecursive==0 || pFrom->pTab );
111840         -    if( pFrom->isRecursive ) continue;
       112039  +    assert( pFrom->fg.isRecursive==0 || pFrom->pTab );
       112040  +    if( pFrom->fg.isRecursive ) continue;
111841 112041       if( pFrom->pTab!=0 ){
111842 112042         /* This statement has already been prepared.  There is no need
111843 112043         ** to go further. */
111844 112044         assert( i==0 );
111845 112045   #ifndef SQLITE_OMIT_CTE
111846 112046         selectPopWith(pWalker, p);
111847 112047   #endif
................................................................................
111859 112059         assert( pFrom->pTab==0 );
111860 112060         if( sqlite3WalkSelect(pWalker, pSel) ) return WRC_Abort;
111861 112061         pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
111862 112062         if( pTab==0 ) return WRC_Abort;
111863 112063         pTab->nRef = 1;
111864 112064         pTab->zName = sqlite3MPrintf(db, "sqlite_sq_%p", (void*)pTab);
111865 112065         while( pSel->pPrior ){ pSel = pSel->pPrior; }
111866         -      selectColumnsFromExprList(pParse, pSel->pEList, &pTab->nCol, &pTab->aCol);
       112066  +      sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
111867 112067         pTab->iPKey = -1;
111868 112068         pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
111869 112069         pTab->tabFlags |= TF_Ephemeral;
111870 112070   #endif
111871 112071       }else{
111872 112072         /* An ordinary table or view name in the FROM clause */
111873 112073         assert( pFrom->pTab==0 );
................................................................................
111996 112196               if( IsHiddenColumn(&pTab->aCol[j]) ){
111997 112197                 assert(IsVirtual(pTab));
111998 112198                 continue;
111999 112199               }
112000 112200               tableSeen = 1;
112001 112201   
112002 112202               if( i>0 && zTName==0 ){
112003         -              if( (pFrom->jointype & JT_NATURAL)!=0
       112203  +              if( (pFrom->fg.jointype & JT_NATURAL)!=0
112004 112204                   && tableAndColumnIndex(pTabList, i, zName, 0, 0)
112005 112205                 ){
112006 112206                   /* In a NATURAL join, omit the join columns from the 
112007 112207                   ** table to the right of the join */
112008 112208                   continue;
112009 112209                 }
112010 112210                 if( sqlite3IdListIndex(pFrom->pUsing, zName)>=0 ){
................................................................................
112282 112482       int addrNext = 0;
112283 112483       int regAgg;
112284 112484       ExprList *pList = pF->pExpr->x.pList;
112285 112485       assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
112286 112486       if( pList ){
112287 112487         nArg = pList->nExpr;
112288 112488         regAgg = sqlite3GetTempRange(pParse, nArg);
112289         -      sqlite3ExprCodeExprList(pParse, pList, regAgg, SQLITE_ECEL_DUP);
       112489  +      sqlite3ExprCodeExprList(pParse, pList, regAgg, 0, SQLITE_ECEL_DUP);
112290 112490       }else{
112291 112491         nArg = 0;
112292 112492         regAgg = 0;
112293 112493       }
112294 112494       if( pF->iDistinct>=0 ){
112295 112495         addrNext = sqlite3VdbeMakeLabel(v);
112296 112496         testcase( nArg==0 );  /* Error condition */
................................................................................
112523 112723       /* Sometimes the code for a subquery will be generated more than
112524 112724       ** once, if the subquery is part of the WHERE clause in a LEFT JOIN,
112525 112725       ** for example.  In that case, do not regenerate the code to manifest
112526 112726       ** a view or the co-routine to implement a view.  The first instance
112527 112727       ** is sufficient, though the subroutine to manifest the view does need
112528 112728       ** to be invoked again. */
112529 112729       if( pItem->addrFillSub ){
112530         -      if( pItem->viaCoroutine==0 ){
       112730  +      if( pItem->fg.viaCoroutine==0 ){
112531 112731           sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub);
112532 112732         }
112533 112733         continue;
112534 112734       }
112535 112735   
112536 112736       /* Increment Parse.nHeight by the height of the largest expression
112537 112737       ** tree referred to by this, the parent select. The child select
................................................................................
112541 112741       ** an exact limit.
112542 112742       */
112543 112743       pParse->nHeight += sqlite3SelectExprHeight(p);
112544 112744   
112545 112745       /* Make copies of constant WHERE-clause terms in the outer query down
112546 112746       ** inside the subquery.  This can help the subquery to run more efficiently.
112547 112747       */
112548         -    if( (pItem->jointype & JT_OUTER)==0
       112748  +    if( (pItem->fg.jointype & JT_OUTER)==0
112549 112749        && pushDownWhereTerms(db, pSub, p->pWhere, pItem->iCursor)
112550 112750       ){
112551 112751   #if SELECTTRACE_ENABLED
112552 112752         if( sqlite3SelectTrace & 0x100 ){
112553 112753           SELECTTRACE(0x100,pParse,p,("After WHERE-clause push-down:\n"));
112554 112754           sqlite3TreeViewSelect(0, p, 0);
112555 112755         }
................................................................................
112570 112770         sqlite3VdbeAddOp3(v, OP_InitCoroutine, pItem->regReturn, 0, addrTop);
112571 112771         VdbeComment((v, "%s", pItem->pTab->zName));
112572 112772         pItem->addrFillSub = addrTop;
112573 112773         sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn);
112574 112774         explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
112575 112775         sqlite3Select(pParse, pSub, &dest);
112576 112776         pItem->pTab->nRowLogEst = sqlite3LogEst(pSub->nSelectRow);
112577         -      pItem->viaCoroutine = 1;
       112777  +      pItem->fg.viaCoroutine = 1;
112578 112778         pItem->regResult = dest.iSdst;
112579 112779         sqlite3VdbeAddOp1(v, OP_EndCoroutine, pItem->regReturn);
112580 112780         sqlite3VdbeJumpHere(v, addrTop-1);
112581 112781         sqlite3ClearTempRegCache(pParse);
112582 112782       }else{
112583 112783         /* Generate a subroutine that will fill an ephemeral table with
112584 112784         ** the content of this subquery.  pItem->addrFillSub will point
................................................................................
112588 112788         int topAddr;
112589 112789         int onceAddr = 0;
112590 112790         int retAddr;
112591 112791         assert( pItem->addrFillSub==0 );
112592 112792         pItem->regReturn = ++pParse->nMem;
112593 112793         topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
112594 112794         pItem->addrFillSub = topAddr+1;
112595         -      if( pItem->isCorrelated==0 ){
       112795  +      if( pItem->fg.isCorrelated==0 ){
112596 112796           /* If the subquery is not correlated and if we are not inside of
112597 112797           ** a trigger, then we only need to compute the value of the subquery
112598 112798           ** once. */
112599 112799           onceAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
112600 112800           VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
112601 112801         }else{
112602 112802           VdbeNoopComment((v, "materialize \"%s\"", pItem->pTab->zName));
................................................................................
112686 112886   
112687 112887     /* Set the limiter.
112688 112888     */
112689 112889     iEnd = sqlite3VdbeMakeLabel(v);
112690 112890     p->nSelectRow = LARGEST_INT64;
112691 112891     computeLimitRegisters(pParse, p, iEnd);
112692 112892     if( p->iLimit==0 && sSort.addrSortIndex>=0 ){
112693         -    sqlite3VdbeGetOp(v, sSort.addrSortIndex)->opcode = OP_SorterOpen;
       112893  +    sqlite3VdbeChangeOpcode(v, sSort.addrSortIndex, OP_SorterOpen);
112694 112894       sSort.sortFlags |= SORTFLAG_UseSorter;
112695 112895     }
112696 112896   
112697 112897     /* Open an ephemeral index to use for the distinct set.
112698 112898     */
112699 112899     if( p->selFlags & SF_Distinct ){
112700 112900       sDistinct.tabTnct = pParse->nTab++;
................................................................................
112902 113102             if( sAggInfo.aCol[i].iSorterColumn>=j ){
112903 113103               nCol++;
112904 113104               j++;
112905 113105             }
112906 113106           }
112907 113107           regBase = sqlite3GetTempRange(pParse, nCol);
112908 113108           sqlite3ExprCacheClear(pParse);
112909         -        sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0);
       113109  +        sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0, 0);
112910 113110           j = nGroupBy;
112911 113111           for(i=0; i<sAggInfo.nColumn; i++){
112912 113112             struct AggInfo_col *pCol = &sAggInfo.aCol[i];
112913 113113             if( pCol->iSorterColumn>=j ){
112914 113114               int r1 = j + regBase;
112915 113115               int r2;
112916 113116   
................................................................................
113014 113214         /* Output the final row of result
113015 113215         */
113016 113216         sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
113017 113217         VdbeComment((v, "output final row"));
113018 113218   
113019 113219         /* Jump over the subroutines
113020 113220         */
113021         -      sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEnd);
       113221  +      sqlite3VdbeGoto(v, addrEnd);
113022 113222   
113023 113223         /* Generate a subroutine that outputs a single row of the result
113024 113224         ** set.  This subroutine first looks at the iUseFlag.  If iUseFlag
113025 113225         ** is less than or equal to zero, the subroutine is a no-op.  If
113026 113226         ** the processing calls for the query to abort, this subroutine
113027 113227         ** increments the iAbortFlag memory location before returning in
113028 113228         ** order to signal the caller to abort.
................................................................................
113168 113368           if( pWInfo==0 ){
113169 113369             sqlite3ExprListDelete(db, pDel);
113170 113370             goto select_end;
113171 113371           }
113172 113372           updateAccumulator(pParse, &sAggInfo);
113173 113373           assert( pMinMax==0 || pMinMax->nExpr==1 );
113174 113374           if( sqlite3WhereIsOrdered(pWInfo)>0 ){
113175         -          sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3WhereBreakLabel(pWInfo));
       113375  +          sqlite3VdbeGoto(v, sqlite3WhereBreakLabel(pWInfo));
113176 113376             VdbeComment((v, "%s() by index",
113177 113377                   (flag==WHERE_ORDERBY_MIN?"min":"max")));
113178 113378           }
113179 113379           sqlite3WhereEnd(pWInfo);
113180 113380           finalizeAggFunctions(pParse, &sAggInfo);
113181 113381         }
113182 113382   
................................................................................
114829 115029     */
114830 115030     pTabList->a[0].colUsed = 0;
114831 115031   
114832 115032     hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngKey);
114833 115033   
114834 115034     /* There is one entry in the aRegIdx[] array for each index on the table
114835 115035     ** being updated.  Fill in aRegIdx[] with a register number that will hold
114836         -  ** the key for accessing each index.  
       115036  +  ** the key for accessing each index.
       115037  +  **
       115038  +  ** FIXME:  Be smarter about omitting indexes that use expressions.
114837 115039     */
114838 115040     for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
114839 115041       int reg;
114840 115042       if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
114841 115043         reg = ++pParse->nMem;
114842 115044       }else{
114843 115045         reg = 0;
114844 115046         for(i=0; i<pIdx->nKeyCol; i++){
114845         -        if( aXRef[pIdx->aiColumn[i]]>=0 ){
       115047  +        i16 iIdxCol = pIdx->aiColumn[i];
       115048  +        if( iIdxCol<0 || aXRef[iIdxCol]>=0 ){
114846 115049             reg = ++pParse->nMem;
114847 115050             break;
114848 115051           }
114849 115052         }
114850 115053       }
114851 115054       if( reg==0 ) aToOpen[j+1] = 0;
114852 115055       aRegIdx[j] = reg;
................................................................................
114938 115141       addrOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, nPk);
114939 115142       sqlite3VdbeSetP4KeyInfo(pParse, pPk);
114940 115143       pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, 
114941 115144                                  WHERE_ONEPASS_DESIRED, iIdxCur);
114942 115145       if( pWInfo==0 ) goto update_cleanup;
114943 115146       okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
114944 115147       for(i=0; i<nPk; i++){
       115148  +      assert( pPk->aiColumn[i]>=(-1) );
114945 115149         sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pPk->aiColumn[i],
114946 115150                                         iPk+i);
114947 115151       }
114948 115152       if( okOnePass ){
114949 115153         sqlite3VdbeChangeToNoop(v, addrOpen);
114950 115154         nKey = nPk;
114951 115155         regKey = iPk;
114952 115156       }else{
114953 115157         sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
114954         -                        sqlite3IndexAffinityStr(v, pPk), nPk);
       115158  +                        sqlite3IndexAffinityStr(db, pPk), nPk);
114955 115159         sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, regKey);
114956 115160       }
114957 115161       sqlite3WhereEnd(pWInfo);
114958 115162     }
114959 115163   
114960 115164     /* Initialize the count of updated rows
114961 115165     */
................................................................................
115184 115388     */
115185 115389     if( okOnePass ){
115186 115390       /* Nothing to do at end-of-loop for a single-pass */
115187 115391     }else if( pPk ){
115188 115392       sqlite3VdbeResolveLabel(v, labelContinue);
115189 115393       sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v);
115190 115394     }else{
115191         -    sqlite3VdbeAddOp2(v, OP_Goto, 0, labelContinue);
       115395  +    sqlite3VdbeGoto(v, labelContinue);
115192 115396     }
115193 115397     sqlite3VdbeResolveLabel(v, labelBreak);
115194 115398   
115195 115399     /* Close all tables */
115196 115400     for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
115197 115401       assert( aRegIdx );
115198 115402       if( aToOpen[i+1] ){
................................................................................
115766 115970         Module *pDel;
115767 115971         char *zCopy = (char *)(&pMod[1]);
115768 115972         memcpy(zCopy, zName, nName+1);
115769 115973         pMod->zName = zCopy;
115770 115974         pMod->pModule = pModule;
115771 115975         pMod->pAux = pAux;
115772 115976         pMod->xDestroy = xDestroy;
       115977  +      pMod->pEpoTab = 0;
115773 115978         pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,(void*)pMod);
115774 115979         assert( pDel==0 || pDel==pMod );
115775 115980         if( pDel ){
115776 115981           db->mallocFailed = 1;
115777 115982           sqlite3DbFree(db, pDel);
115778 115983         }
115779 115984       }
................................................................................
115993 116198   /*
115994 116199   ** Add a new module argument to pTable->azModuleArg[].
115995 116200   ** The string is not copied - the pointer is stored.  The
115996 116201   ** string will be freed automatically when the table is
115997 116202   ** deleted.
115998 116203   */
115999 116204   static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
116000         -  int i = pTable->nModuleArg++;
116001         -  int nBytes = sizeof(char *)*(1+pTable->nModuleArg);
       116205  +  int nBytes = sizeof(char *)*(2+pTable->nModuleArg);
116002 116206     char **azModuleArg;
116003 116207     azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
116004 116208     if( azModuleArg==0 ){
116005         -    int j;
116006         -    for(j=0; j<i; j++){
116007         -      sqlite3DbFree(db, pTable->azModuleArg[j]);
116008         -    }
116009 116209       sqlite3DbFree(db, zArg);
116010         -    sqlite3DbFree(db, pTable->azModuleArg);
116011         -    pTable->nModuleArg = 0;
116012 116210     }else{
       116211  +    int i = pTable->nModuleArg++;
116013 116212       azModuleArg[i] = zArg;
116014 116213       azModuleArg[i+1] = 0;
       116214  +    pTable->azModuleArg = azModuleArg;
116015 116215     }
116016         -  pTable->azModuleArg = azModuleArg;
116017 116216   }
116018 116217   
116019 116218   /*
116020 116219   ** The parser calls this routine when it first sees a CREATE VIRTUAL TABLE
116021 116220   ** statement.  The module name has been parsed, but the optional list
116022 116221   ** of parameters that follow the module name are still pending.
116023 116222   */
................................................................................
116136 116335       sqlite3ChangeCookie(pParse, iDb);
116137 116336   
116138 116337       sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
116139 116338       zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
116140 116339       sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere);
116141 116340   
116142 116341       iReg = ++pParse->nMem;
116143         -    sqlite3VdbeAddOp4(v, OP_String8, 0, iReg, 0, pTab->zName, 0);
       116342  +    sqlite3VdbeLoadString(v, iReg, pTab->zName);
116144 116343       sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg);
116145 116344     }
116146 116345   
116147 116346     /* If we are rereading the sqlite_master table create the in-memory
116148 116347     ** record of the table. The xConnect() method is not called until
116149 116348     ** the first time the virtual table is used in an SQL statement. This
116150 116349     ** allows a schema that contains virtual tables to be loaded before
................................................................................
116412 116611     zMod = pTab->azModuleArg[0];
116413 116612     pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
116414 116613   
116415 116614     /* If the module has been registered and includes a Create method, 
116416 116615     ** invoke it now. If the module has not been registered, return an 
116417 116616     ** error. Otherwise, do nothing.
116418 116617     */
116419         -  if( !pMod ){
       116618  +  if( pMod==0 || pMod->pModule->xCreate==0 || pMod->pModule->xDestroy==0 ){
116420 116619       *pzErr = sqlite3MPrintf(db, "no such module: %s", zMod);
116421 116620       rc = SQLITE_ERROR;
116422 116621     }else{
116423 116622       rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xCreate, pzErr);
116424 116623     }
116425 116624   
116426 116625     /* Justification of ALWAYS():  The xConstructor method is required to
................................................................................
116514 116713   SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
116515 116714     int rc = SQLITE_OK;
116516 116715     Table *pTab;
116517 116716   
116518 116717     pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
116519 116718     if( ALWAYS(pTab!=0 && pTab->pVTable!=0) ){
116520 116719       VTable *p;
       116720  +    int (*xDestroy)(sqlite3_vtab *);
116521 116721       for(p=pTab->pVTable; p; p=p->pNext){
116522 116722         assert( p->pVtab );
116523 116723         if( p->pVtab->nRef>0 ){
116524 116724           return SQLITE_LOCKED;
116525 116725         }
116526 116726       }
116527 116727       p = vtabDisconnectAll(db, pTab);
116528         -    rc = p->pMod->pModule->xDestroy(p->pVtab);
       116728  +    xDestroy = p->pMod->pModule->xDestroy;
       116729  +    assert( xDestroy!=0 );  /* Checked before the virtual table is created */
       116730  +    rc = xDestroy(p->pVtab);
116529 116731       /* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */
116530 116732       if( rc==SQLITE_OK ){
116531 116733         assert( pTab->pVTable==p && p->pNext==0 );
116532 116734         p->pVtab = 0;
116533 116735         pTab->pVTable = 0;
116534 116736         sqlite3VtabUnlock(p);
116535 116737       }
................................................................................
116799 117001     if( apVtabLock ){
116800 117002       pToplevel->apVtabLock = apVtabLock;
116801 117003       pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab;
116802 117004     }else{
116803 117005       pToplevel->db->mallocFailed = 1;
116804 117006     }
116805 117007   }
       117008  +
       117009  +/*
       117010  +** Check to see if virtual tale module pMod can be have an eponymous
       117011  +** virtual table instance.  If it can, create one if one does not already
       117012  +** exist. Return non-zero if the eponymous virtual table instance exists
       117013  +** when this routine returns, and return zero if it does not exist.
       117014  +**
       117015  +** An eponymous virtual table instance is one that is named after its
       117016  +** module, and more importantly, does not require a CREATE VIRTUAL TABLE
       117017  +** statement in order to come into existance.  Eponymous virtual table
       117018  +** instances always exist.  They cannot be DROP-ed.
       117019  +**
       117020  +** Any virtual table module for which xConnect and xCreate are the same
       117021  +** method can have an eponymous virtual table instance.
       117022  +*/
       117023  +SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse *pParse, Module *pMod){
       117024  +  const sqlite3_module *pModule = pMod->pModule;
       117025  +  Table *pTab;
       117026  +  char *zErr = 0;
       117027  +  int nName;
       117028  +  int rc;
       117029  +  sqlite3 *db = pParse->db;
       117030  +  if( pMod->pEpoTab ) return 1;
       117031  +  if( pModule->xCreate!=0 && pModule->xCreate!=pModule->xConnect ) return 0;
       117032  +  nName = sqlite3Strlen30(pMod->zName) + 1;
       117033  +  pTab = sqlite3DbMallocZero(db, sizeof(Table) + nName);
       117034  +  if( pTab==0 ) return 0;
       117035  +  pMod->pEpoTab = pTab;
       117036  +  pTab->zName = (char*)&pTab[1];
       117037  +  memcpy(pTab->zName, pMod->zName, nName);
       117038  +  pTab->nRef = 1;
       117039  +  pTab->pSchema = db->aDb[0].pSchema;
       117040  +  pTab->tabFlags |= TF_Virtual;
       117041  +  pTab->nModuleArg = 0;
       117042  +  pTab->iPKey = -1;
       117043  +  addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
       117044  +  addModuleArgument(db, pTab, 0);
       117045  +  addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
       117046  +  rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
       117047  +  if( rc ){
       117048  +    sqlite3ErrorMsg(pParse, "%s", zErr);
       117049  +    sqlite3DbFree(db, zErr);
       117050  +    sqlite3VtabEponymousTableClear(db, pMod);
       117051  +    return 0;
       117052  +  }
       117053  +  return 1;
       117054  +}
       117055  +
       117056  +/*
       117057  +** Erase the eponymous virtual table instance associated with
       117058  +** virtual table module pMod, if it exists.
       117059  +*/
       117060  +SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3 *db, Module *pMod){
       117061  +  Table *pTab = pMod->pEpoTab;
       117062  +  if( (pTab = pMod->pEpoTab)!=0 ){
       117063  +    sqlite3DeleteColumnNames(db, pTab);
       117064  +    sqlite3VtabClear(db, pTab);
       117065  +    sqlite3DbFree(db, pTab);
       117066  +    pMod->pEpoTab = 0;
       117067  +  }
       117068  +}
116806 117069   
116807 117070   /*
116808 117071   ** Return the ON CONFLICT resolution mode in effect for the virtual
116809 117072   ** table update operation currently in progress.
116810 117073   **
116811 117074   ** The results of this routine are undefined unless it is called from
116812 117075   ** within an xUpdate method.
................................................................................
117170 117433   ** An instance of the WhereScan object is used as an iterator for locating
117171 117434   ** terms in the WHERE clause that are useful to the query planner.
117172 117435   */
117173 117436   struct WhereScan {
117174 117437     WhereClause *pOrigWC;      /* Original, innermost WhereClause */
117175 117438     WhereClause *pWC;          /* WhereClause currently being scanned */
117176 117439     char *zCollName;           /* Required collating sequence, if not NULL */
       117440  +  Expr *pIdxExpr;            /* Search for this index expression */
117177 117441     char idxaff;               /* Must match this affinity, if zCollName!=NULL */
117178 117442     unsigned char nEquiv;      /* Number of entries in aEquiv[] */
117179 117443     unsigned char iEquiv;      /* Next unused slot in aEquiv[] */
117180 117444     u32 opMask;                /* Acceptable operators */
117181 117445     int k;                     /* Resume scanning at this->pWC->a[this->k] */
117182         -  int aEquiv[22];            /* Cursor,Column pairs for equivalence classes */
       117446  +  int aiCur[11];             /* Cursors in the equivalence class */
       117447  +  i16 aiColumn[11];          /* Corresponding column number in the eq-class */
117183 117448   };
117184 117449   
117185 117450   /*
117186 117451   ** An instance of the following structure holds all information about a
117187 117452   ** WHERE clause.  Mostly this is a container for one or more WhereTerms.
117188 117453   **
117189 117454   ** Explanation of pOuter:  For a WHERE clause of the form
................................................................................
117359 117624   /* whereexpr.c: */
117360 117625   SQLITE_PRIVATE void sqlite3WhereClauseInit(WhereClause*,WhereInfo*);
117361 117626   SQLITE_PRIVATE void sqlite3WhereClauseClear(WhereClause*);
117362 117627   SQLITE_PRIVATE void sqlite3WhereSplit(WhereClause*,Expr*,u8);
117363 117628   SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet*, Expr*);
117364 117629   SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet*, ExprList*);
117365 117630   SQLITE_PRIVATE void sqlite3WhereExprAnalyze(SrcList*, WhereClause*);
       117631  +SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(Parse*, struct SrcList_item*, WhereClause*);
117366 117632   
117367 117633   
117368 117634   
117369 117635   
117370 117636   
117371 117637   /*
117372 117638   ** Bitmasks for the operators on WhereTerm objects.  These are all
................................................................................
117435 117701     const char *zOp             /* Name of the operator */
117436 117702   ){
117437 117703     if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5);
117438 117704     sqlite3StrAccumAppendAll(pStr, zColumn);
117439 117705     sqlite3StrAccumAppend(pStr, zOp, 1);
117440 117706     sqlite3StrAccumAppend(pStr, "?", 1);
117441 117707   }
       117708  +
       117709  +/*
       117710  +** Return the name of the i-th column of the pIdx index.
       117711  +*/
       117712  +static const char *explainIndexColumnName(Index *pIdx, int i){
       117713  +  i = pIdx->aiColumn[i];
       117714  +  if( i==(-2) ) return "<expr>";
       117715  +  if( i==(-1) ) return "rowid";
       117716  +  return pIdx->pTable->aCol[i].zName;
       117717  +}
117442 117718   
117443 117719   /*
117444 117720   ** Argument pLevel describes a strategy for scanning table pTab. This 
117445 117721   ** function appends text to pStr that describes the subset of table
117446 117722   ** rows scanned by the strategy in the form of an SQL expression.
117447 117723   **
117448 117724   ** For example, if the query:
................................................................................
117455 117731   **   "a=? AND b>?"
117456 117732   */
117457 117733   static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
117458 117734     Index *pIndex = pLoop->u.btree.pIndex;
117459 117735     u16 nEq = pLoop->u.btree.nEq;
117460 117736     u16 nSkip = pLoop->nSkip;
117461 117737     int i, j;
117462         -  Column *aCol = pTab->aCol;
117463         -  i16 *aiColumn = pIndex->aiColumn;
117464 117738   
117465 117739     if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
117466 117740     sqlite3StrAccumAppend(pStr, " (", 2);
117467 117741     for(i=0; i<nEq; i++){
117468         -    char *z = aiColumn[i] < 0 ? "rowid" : aCol[aiColumn[i]].zName;
117469         -    if( i>=nSkip ){
117470         -      explainAppendTerm(pStr, i, z, "=");
117471         -    }else{
117472         -      if( i ) sqlite3StrAccumAppend(pStr, " AND ", 5);
117473         -      sqlite3XPrintf(pStr, 0, "ANY(%s)", z);
117474         -    }
       117742  +    const char *z = explainIndexColumnName(pIndex, i);
       117743  +    if( i ) sqlite3StrAccumAppend(pStr, " AND ", 5);
       117744  +    sqlite3XPrintf(pStr, 0, i>=nSkip ? "%s=?" : "ANY(%s)", z);
117475 117745     }
117476 117746   
117477 117747     j = i;
117478 117748     if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
117479         -    char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
       117749  +    const char *z = explainIndexColumnName(pIndex, i);
117480 117750       explainAppendTerm(pStr, i++, z, ">");
117481 117751     }
117482 117752     if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
117483         -    char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
       117753  +    const char *z = explainIndexColumnName(pIndex, j);
117484 117754       explainAppendTerm(pStr, i, z, "<");
117485 117755     }
117486 117756     sqlite3StrAccumAppend(pStr, ")", 1);
117487 117757   }
117488 117758   
117489 117759   /*
117490 117760   ** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
................................................................................
117560 117830         }
117561 117831         if( zFmt ){
117562 117832           sqlite3StrAccumAppend(&str, " USING ", 7);
117563 117833           sqlite3XPrintf(&str, 0, zFmt, pIdx->zName);
117564 117834           explainIndexRange(&str, pLoop, pItem->pTab);
117565 117835         }
117566 117836       }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
117567         -      const char *zRange;
       117837  +      const char *zRangeOp;
117568 117838         if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){
117569         -        zRange = "(rowid=?)";
       117839  +        zRangeOp = "=";
117570 117840         }else if( (flags&WHERE_BOTH_LIMIT)==WHERE_BOTH_LIMIT ){
117571         -        zRange = "(rowid>? AND rowid<?)";
       117841  +        zRangeOp = ">? AND rowid<";
117572 117842         }else if( flags&WHERE_BTM_LIMIT ){
117573         -        zRange = "(rowid>?)";
       117843  +        zRangeOp = ">";
117574 117844         }else{
117575 117845           assert( flags&WHERE_TOP_LIMIT);
117576         -        zRange = "(rowid<?)";
       117846  +        zRangeOp = "<";
117577 117847         }
117578         -      sqlite3StrAccumAppendAll(&str, " USING INTEGER PRIMARY KEY ");
117579         -      sqlite3StrAccumAppendAll(&str, zRange);
       117848  +      sqlite3XPrintf(&str, 0, " USING INTEGER PRIMARY KEY (rowid%s?)",zRangeOp);
117580 117849       }
117581 117850   #ifndef SQLITE_OMIT_VIRTUALTABLE
117582 117851       else if( (flags & WHERE_VIRTUALTABLE)!=0 ){
117583 117852         sqlite3XPrintf(&str, 0, " VIRTUAL TABLE INDEX %d:%s",
117584 117853                     pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr);
117585 117854       }
117586 117855   #endif
................................................................................
117887 118156   
117888 118157     /* Figure out how many memory cells we will need then allocate them.
117889 118158     */
117890 118159     regBase = pParse->nMem + 1;
117891 118160     nReg = pLoop->u.btree.nEq + nExtraReg;
117892 118161     pParse->nMem += nReg;
117893 118162   
117894         -  zAff = sqlite3DbStrDup(pParse->db, sqlite3IndexAffinityStr(v, pIdx));
       118163  +  zAff = sqlite3DbStrDup(pParse->db,sqlite3IndexAffinityStr(pParse->db,pIdx));
117895 118164     if( !zAff ){
117896 118165       pParse->db->mallocFailed = 1;
117897 118166     }
117898 118167   
117899 118168     if( nSkip ){
117900 118169       int iIdxCur = pLevel->iIdxCur;
117901 118170       sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur);
................................................................................
118041 118310     addrBrk = pLevel->addrBrk = pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
118042 118311     addrCont = pLevel->addrCont = sqlite3VdbeMakeLabel(v);
118043 118312   
118044 118313     /* If this is the right table of a LEFT OUTER JOIN, allocate and
118045 118314     ** initialize a memory cell that records if this table matches any
118046 118315     ** row of the left table of the join.
118047 118316     */
118048         -  if( pLevel->iFrom>0 && (pTabItem[0].jointype & JT_LEFT)!=0 ){
       118317  +  if( pLevel->iFrom>0 && (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){
118049 118318       pLevel->iLeftJoin = ++pParse->nMem;
118050 118319       sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
118051 118320       VdbeComment((v, "init LEFT JOIN no-match flag"));
118052 118321     }
118053 118322   
118054 118323     /* Special case of a FROM clause subquery implemented as a co-routine */
118055         -  if( pTabItem->viaCoroutine ){
       118324  +  if( pTabItem->fg.viaCoroutine ){
118056 118325       int regYield = pTabItem->regReturn;
118057 118326       sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
118058 118327       pLevel->p2 =  sqlite3VdbeAddOp2(v, OP_Yield, regYield, addrBrk);
118059 118328       VdbeCoverage(v);
118060 118329       VdbeComment((v, "next row of \"%s\"", pTabItem->pTab->zName));
118061 118330       pLevel->op = OP_Goto;
118062 118331     }else
................................................................................
118775 119044       pLevel->u.pCovidx = pCov;
118776 119045       if( pCov ) pLevel->iIdxCur = iCovCur;
118777 119046       if( pAndExpr ){
118778 119047         pAndExpr->pLeft = 0;
118779 119048         sqlite3ExprDelete(db, pAndExpr);
118780 119049       }
118781 119050       sqlite3VdbeChangeP1(v, iRetInit, sqlite3VdbeCurrentAddr(v));
118782         -    sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrBrk);
       119051  +    sqlite3VdbeGoto(v, pLevel->addrBrk);
118783 119052       sqlite3VdbeResolveLabel(v, iLoopBody);
118784 119053   
118785 119054       if( pWInfo->nLevel>1 ) sqlite3StackFree(db, pOrTab);
118786 119055       if( !untestedTerms ) disableTerm(pLevel, pTerm);
118787 119056     }else
118788 119057   #endif /* SQLITE_OMIT_OR_OPTIMIZATION */
118789 119058   
................................................................................
118790 119059     {
118791 119060       /* Case 6:  There is no usable index.  We must do a complete
118792 119061       **          scan of the entire table.
118793 119062       */
118794 119063       static const u8 aStep[] = { OP_Next, OP_Prev };
118795 119064       static const u8 aStart[] = { OP_Rewind, OP_Last };
118796 119065       assert( bRev==0 || bRev==1 );
118797         -    if( pTabItem->isRecursive ){
       119066  +    if( pTabItem->fg.isRecursive ){
118798 119067         /* Tables marked isRecursive have only a single row that is stored in
118799 119068         ** a pseudo-cursor.  No need to Rewind or Next such cursors. */
118800 119069         pLevel->op = OP_Noop;
118801 119070       }else{
118802 119071         pLevel->op = aStep[bRev];
118803 119072         pLevel->p1 = iCur;
118804 119073         pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
................................................................................
119697 119966           mask |= sqlite3WhereExprUsage(pMaskSet, pSrc->a[i].pOn);
119698 119967         }
119699 119968       }
119700 119969       pS = pS->pPrior;
119701 119970     }
119702 119971     return mask;
119703 119972   }
       119973  +
       119974  +/*
       119975  +** Expression pExpr is one operand of a comparison operator that might
       119976  +** be useful for indexing.  This routine checks to see if pExpr appears
       119977  +** in any index.  Return TRUE (1) if pExpr is an indexed term and return
       119978  +** FALSE (0) if not.  If TRUE is returned, also set *piCur to the cursor
       119979  +** number of the table that is indexed and *piColumn to the column number
       119980  +** of the column that is indexed, or -2 if an expression is being indexed.
       119981  +**
       119982  +** If pExpr is a TK_COLUMN column reference, then this routine always returns
       119983  +** true even if that particular column is not indexed, because the column
       119984  +** might be added to an automatic index later.
       119985  +*/
       119986  +static int exprMightBeIndexed(
       119987  +  SrcList *pFrom,        /* The FROM clause */
       119988  +  Bitmask mPrereq,       /* Bitmask of FROM clause terms referenced by pExpr */
       119989  +  Expr *pExpr,           /* An operand of a comparison operator */
       119990  +  int *piCur,            /* Write the referenced table cursor number here */
       119991  +  int *piColumn          /* Write the referenced table column number here */
       119992  +){
       119993  +  Index *pIdx;
       119994  +  int i;
       119995  +  int iCur;
       119996  +  if( pExpr->op==TK_COLUMN ){
       119997  +    *piCur = pExpr->iTable;
       119998  +    *piColumn = pExpr->iColumn;
       119999  +    return 1;
       120000  +  }
       120001  +  if( mPrereq==0 ) return 0;                 /* No table references */
       120002  +  if( (mPrereq&(mPrereq-1))!=0 ) return 0;   /* Refs more than one table */
       120003  +  for(i=0; mPrereq>1; i++, mPrereq>>=1){}
       120004  +  iCur = pFrom->a[i].iCursor;
       120005  +  for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){
       120006  +    if( pIdx->aColExpr==0 ) continue;
       120007  +    for(i=0; i<pIdx->nKeyCol; i++){
       120008  +      if( pIdx->aiColumn[i]!=(-2) ) continue;
       120009  +      if( sqlite3ExprCompare(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
       120010  +        *piCur = iCur;
       120011  +        *piColumn = -2;
       120012  +        return 1;
       120013  +      }
       120014  +    }
       120015  +  }
       120016  +  return 0;
       120017  +}
119704 120018   
119705 120019   /*
119706 120020   ** The input to this routine is an WhereTerm structure with only the
119707 120021   ** "pExpr" field filled in.  The job of this routine is to analyze the
119708 120022   ** subexpression and populate all the other fields of the WhereTerm
119709 120023   ** structure.
119710 120024   **
................................................................................
119768 120082                          ** on left table of a LEFT JOIN.  Ticket #3015 */
119769 120083     }
119770 120084     pTerm->prereqAll = prereqAll;
119771 120085     pTerm->leftCursor = -1;
119772 120086     pTerm->iParent = -1;
119773 120087     pTerm->eOperator = 0;
119774 120088     if( allowedOp(op) ){
       120089  +    int iCur, iColumn;
119775 120090       Expr *pLeft = sqlite3ExprSkipCollate(pExpr->pLeft);
119776 120091       Expr *pRight = sqlite3ExprSkipCollate(pExpr->pRight);
119777 120092       u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
119778         -    if( pLeft->op==TK_COLUMN ){
119779         -      pTerm->leftCursor = pLeft->iTable;
119780         -      pTerm->u.leftColumn = pLeft->iColumn;
       120093  +    if( exprMightBeIndexed(pSrc, prereqLeft, pLeft, &iCur, &iColumn) ){
       120094  +      pTerm->leftCursor = iCur;
       120095  +      pTerm->u.leftColumn = iColumn;
119781 120096         pTerm->eOperator = operatorMask(op) & opMask;
119782 120097       }
119783 120098       if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
119784         -    if( pRight && pRight->op==TK_COLUMN ){
       120099  +    if( pRight 
       120100  +     && exprMightBeIndexed(pSrc, pTerm->prereqRight, pRight, &iCur, &iColumn)
       120101  +    ){
119785 120102         WhereTerm *pNew;
119786 120103         Expr *pDup;
119787 120104         u16 eExtraOp = 0;        /* Extra bits for pNew->eOperator */
119788 120105         if( pTerm->leftCursor>=0 ){
119789 120106           int idxNew;
119790 120107           pDup = sqlite3ExprDup(db, pExpr, 0);
119791 120108           if( db->mallocFailed ){
................................................................................
119806 120123           }
119807 120124         }else{
119808 120125           pDup = pExpr;
119809 120126           pNew = pTerm;
119810 120127         }
119811 120128         exprCommute(pParse, pDup);
119812 120129         pLeft = sqlite3ExprSkipCollate(pDup->pLeft);
119813         -      pNew->leftCursor = pLeft->iTable;
119814         -      pNew->u.leftColumn = pLeft->iColumn;
       120130  +      pNew->leftCursor = iCur;
       120131  +      pNew->u.leftColumn = iColumn;
119815 120132         testcase( (prereqLeft | extraRight) != prereqLeft );
119816 120133         pNew->prereqRight = prereqLeft | extraRight;
119817 120134         pNew->prereqAll = prereqAll;
119818 120135         pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
119819 120136       }
119820 120137     }
119821 120138   
................................................................................
120150 120467     WhereClause *pWC         /* the WHERE clause to be analyzed */
120151 120468   ){
120152 120469     int i;
120153 120470     for(i=pWC->nTerm-1; i>=0; i--){
120154 120471       exprAnalyze(pTabList, pWC, i);
120155 120472     }
120156 120473   }
       120474  +
       120475  +/*
       120476  +** For table-valued-functions, transform the function arguments into
       120477  +** new WHERE clause terms.  
       120478  +**
       120479  +** Each function argument translates into an equality constraint against
       120480  +** a HIDDEN column in the table.
       120481  +*/
       120482  +SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(
       120483  +  Parse *pParse,                    /* Parsing context */
       120484  +  struct SrcList_item *pItem,       /* The FROM clause term to process */
       120485  +  WhereClause *pWC                  /* Xfer function arguments to here */
       120486  +){
       120487  +  Table *pTab;
       120488  +  int j, k;
       120489  +  ExprList *pArgs;
       120490  +  Expr *pColRef;
       120491  +  Expr *pTerm;
       120492  +  if( pItem->fg.isTabFunc==0 ) return;
       120493  +  pTab = pItem->pTab;
       120494  +  assert( pTab!=0 );
       120495  +  pArgs = pItem->u1.pFuncArg;
       120496  +  assert( pArgs!=0 );
       120497  +  for(j=k=0; j<pArgs->nExpr; j++){
       120498  +    while( k<pTab->nCol && (pTab->aCol[k].colFlags & COLFLAG_HIDDEN)==0 ){ k++; }
       120499  +    if( k>=pTab->nCol ){
       120500  +      sqlite3ErrorMsg(pParse, "too many arguments on %s() - max %d",
       120501  +                      pTab->zName, j);
       120502  +      return;
       120503  +    }
       120504  +    pColRef = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
       120505  +    if( pColRef==0 ) return;
       120506  +    pColRef->iTable = pItem->iCursor;
       120507  +    pColRef->iColumn = k++;
       120508  +    pColRef->pTab = pTab;
       120509  +    pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef,
       120510  +                         sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
       120511  +    whereClauseInsert(pWC, pTerm, TERM_DYNAMIC);
       120512  +  }
       120513  +}
120157 120514   
120158 120515   /************** End of whereexpr.c *******************************************/
120159 120516   /************** Begin file where.c *******************************************/
120160 120517   /*
120161 120518   ** 2001 September 15
120162 120519   **
120163 120520   ** The author disclaims copyright to this source code.  In place of
................................................................................
120326 120683   /*
120327 120684   ** Advance to the next WhereTerm that matches according to the criteria
120328 120685   ** established when the pScan object was initialized by whereScanInit().
120329 120686   ** Return NULL if there are no more matching WhereTerms.
120330 120687   */
120331 120688   static WhereTerm *whereScanNext(WhereScan *pScan){
120332 120689     int iCur;            /* The cursor on the LHS of the term */
120333         -  int iColumn;         /* The column on the LHS of the term.  -1 for IPK */
       120690  +  i16 iColumn;         /* The column on the LHS of the term.  -1 for IPK */
120334 120691     Expr *pX;            /* An expression being tested */
120335 120692     WhereClause *pWC;    /* Shorthand for pScan->pWC */
120336 120693     WhereTerm *pTerm;    /* The term being tested */
120337 120694     int k = pScan->k;    /* Where to start scanning */
120338 120695   
120339 120696     while( pScan->iEquiv<=pScan->nEquiv ){
120340         -    iCur = pScan->aEquiv[pScan->iEquiv-2];
120341         -    iColumn = pScan->aEquiv[pScan->iEquiv-1];
       120697  +    iCur = pScan->aiCur[pScan->iEquiv-1];
       120698  +    iColumn = pScan->aiColumn[pScan->iEquiv-1];
       120699  +    assert( iColumn!=(-2) || pScan->pIdxExpr!=0 );
120342 120700       while( (pWC = pScan->pWC)!=0 ){
120343 120701         for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
120344 120702           if( pTerm->leftCursor==iCur
120345 120703            && pTerm->u.leftColumn==iColumn
120346         -         && (pScan->iEquiv<=2 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
       120704  +         && (iColumn!=(-2)
       120705  +               || sqlite3ExprCompare(pTerm->pExpr->pLeft,pScan->pIdxExpr,iCur)==0)
       120706  +         && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
120347 120707           ){
120348 120708             if( (pTerm->eOperator & WO_EQUIV)!=0
120349         -           && pScan->nEquiv<ArraySize(pScan->aEquiv)
       120709  +           && pScan->nEquiv<ArraySize(pScan->aiCur)
120350 120710             ){
120351 120711               int j;
120352 120712               pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight);
120353 120713               assert( pX->op==TK_COLUMN );
120354         -            for(j=0; j<pScan->nEquiv; j+=2){
120355         -              if( pScan->aEquiv[j]==pX->iTable
120356         -               && pScan->aEquiv[j+1]==pX->iColumn ){
       120714  +            for(j=0; j<pScan->nEquiv; j++){
       120715  +              if( pScan->aiCur[j]==pX->iTable
       120716  +               && pScan->aiColumn[j]==pX->iColumn ){
120357 120717                     break;
120358 120718                 }
120359 120719               }
120360 120720               if( j==pScan->nEquiv ){
120361         -              pScan->aEquiv[j] = pX->iTable;
120362         -              pScan->aEquiv[j+1] = pX->iColumn;
120363         -              pScan->nEquiv += 2;
       120721  +              pScan->aiCur[j] = pX->iTable;
       120722  +              pScan->aiColumn[j] = pX->iColumn;
       120723  +              pScan->nEquiv++;
120364 120724               }
120365 120725             }
120366 120726             if( (pTerm->eOperator & pScan->opMask)!=0 ){
120367 120727               /* Verify the affinity and collating sequence match */
120368 120728               if( pScan->zCollName && (pTerm->eOperator & WO_ISNULL)==0 ){
120369 120729                 CollSeq *pColl;
120370 120730                 Parse *pParse = pWC->pWInfo->pParse;
................................................................................
120378 120738                 if( pColl==0 ) pColl = pParse->db->pDfltColl;
120379 120739                 if( sqlite3StrICmp(pColl->zName, pScan->zCollName) ){
120380 120740                   continue;
120381 120741                 }
120382 120742               }
120383 120743               if( (pTerm->eOperator & (WO_EQ|WO_IS))!=0
120384 120744                && (pX = pTerm->pExpr->pRight)->op==TK_COLUMN
120385         -             && pX->iTable==pScan->aEquiv[0]
120386         -             && pX->iColumn==pScan->aEquiv[1]
       120745  +             && pX->iTable==pScan->aiCur[0]
       120746  +             && pX->iColumn==pScan->aiColumn[0]
120387 120747               ){
120388 120748                 testcase( pTerm->eOperator & WO_IS );
120389 120749                 continue;
120390 120750               }
120391 120751               pScan->k = k+1;
120392 120752               return pTerm;
120393 120753             }
................................................................................
120394 120754           }
120395 120755         }
120396 120756         pScan->pWC = pScan->pWC->pOuter;
120397 120757         k = 0;
120398 120758       }
120399 120759       pScan->pWC = pScan->pOrigWC;
120400 120760       k = 0;
120401         -    pScan->iEquiv += 2;
       120761  +    pScan->iEquiv++;
120402 120762     }
120403 120763     return 0;
120404 120764   }
120405 120765   
120406 120766   /*
120407 120767   ** Initialize a WHERE clause scanner object.  Return a pointer to the
120408 120768   ** first match.  Return NULL if there are no matches.
................................................................................
120423 120783     WhereScan *pScan,       /* The WhereScan object being initialized */
120424 120784     WhereClause *pWC,       /* The WHERE clause to be scanned */
120425 120785     int iCur,               /* Cursor to scan for */
120426 120786     int iColumn,            /* Column to scan for */
120427 120787     u32 opMask,             /* Operator(s) to scan for */
120428 120788     Index *pIdx             /* Must be compatible with this index */
120429 120789   ){
120430         -  int j;
       120790  +  int j = 0;
120431 120791   
120432 120792     /* memset(pScan, 0, sizeof(*pScan)); */
120433 120793     pScan->pOrigWC = pWC;
120434 120794     pScan->pWC = pWC;
       120795  +  pScan->pIdxExpr = 0;
       120796  +  if( pIdx ){
       120797  +    j = iColumn;
       120798  +    iColumn = pIdx->aiColumn[j];
       120799  +    if( iColumn==(-2) ) pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr;
       120800  +  }
120435 120801     if( pIdx && iColumn>=0 ){
120436 120802       pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
120437         -    for(j=0; pIdx->aiColumn[j]!=iColumn; j++){
120438         -      if( NEVER(j>pIdx->nColumn) ) return 0;
120439         -    }
120440 120803       pScan->zCollName = pIdx->azColl[j];
120441 120804     }else{
120442 120805       pScan->idxaff = 0;
120443 120806       pScan->zCollName = 0;
120444 120807     }
120445 120808     pScan->opMask = opMask;
120446 120809     pScan->k = 0;
120447         -  pScan->aEquiv[0] = iCur;
120448         -  pScan->aEquiv[1] = iColumn;
120449         -  pScan->nEquiv = 2;
120450         -  pScan->iEquiv = 2;
       120810  +  pScan->aiCur[0] = iCur;
       120811  +  pScan->aiColumn[0] = iColumn;
       120812  +  pScan->nEquiv = 1;
       120813  +  pScan->iEquiv = 1;
120451 120814     return whereScanNext(pScan);
120452 120815   }
120453 120816   
120454 120817   /*
120455 120818   ** Search for a term in the WHERE clause that is of the form "X <op> <expr>"
120456 120819   ** where X is a reference to the iColumn of table iCur and <op> is one of
120457 120820   ** the WO_xx operator codes specified by the op parameter.
120458 120821   ** Return a pointer to the term.  Return 0 if not found.
       120822  +**
       120823  +** If pIdx!=0 then search for terms matching the iColumn-th column of pIdx
       120824  +** rather than the iColumn-th column of table iCur.
120459 120825   **
120460 120826   ** The term returned might by Y=<expr> if there is another constraint in
120461 120827   ** the WHERE clause that specifies that X=Y.  Any such constraints will be
120462 120828   ** identified by the WO_EQUIV bit in the pTerm->eOperator field.  The
120463         -** aEquiv[] array holds X and all its equivalents, with each SQL variable
120464         -** taking up two slots in aEquiv[].  The first slot is for the cursor number
120465         -** and the second is for the column number.  There are 22 slots in aEquiv[]
120466         -** so that means we can look for X plus up to 10 other equivalent values.
120467         -** Hence a search for X will return <expr> if X=A1 and A1=A2 and A2=A3
120468         -** and ... and A9=A10 and A10=<expr>.
       120829  +** aiCur[]/iaColumn[] arrays hold X and all its equivalents. There are 11
       120830  +** slots in aiCur[]/aiColumn[] so that means we can look for X plus up to 10
       120831  +** other equivalent values.  Hence a search for X will return <expr> if X=A1
       120832  +** and A1=A2 and A2=A3 and ... and A9=A10 and A10=<expr>.
120469 120833   **
120470 120834   ** If there are multiple terms in the WHERE clause of the form "X <op> <expr>"
120471 120835   ** then try for the one with no dependencies on <expr> - in other words where
120472 120836   ** <expr> is a constant expression of some kind.  Only return entries of
120473 120837   ** the form "X <op> Y" where Y is a column in another table if no terms of
120474 120838   ** the form "X <op> <const-expr>" exist.   If no terms with a constant RHS
120475 120839   ** exist, try to return a term that does not use WO_EQUIV.
................................................................................
120529 120893           return i;
120530 120894         }
120531 120895       }
120532 120896     }
120533 120897   
120534 120898     return -1;
120535 120899   }
       120900  +
       120901  +/*
       120902  +** Return TRUE if the iCol-th column of index pIdx is NOT NULL
       120903  +*/
       120904  +static int indexColumnNotNull(Index *pIdx, int iCol){
       120905  +  int j;
       120906  +  assert( pIdx!=0 );
       120907  +  assert( iCol>=0 && iCol<pIdx->nColumn );
       120908  +  j = pIdx->aiColumn[iCol];
       120909  +  if( j>=0 ){
       120910  +    return pIdx->pTable->aCol[j].notNull;
       120911  +  }else if( j==(-1) ){
       120912  +    return 1;
       120913  +  }else{
       120914  +    assert( j==(-2) );
       120915  +    return 0;  /* Assume an indexed expression can always yield a NULL */
       120916  +
       120917  +  }
       120918  +}
120536 120919   
120537 120920   /*
120538 120921   ** Return true if the DISTINCT expression-list passed as the third argument
120539 120922   ** is redundant.
120540 120923   **
120541 120924   ** A DISTINCT list is redundant if any subset of the columns in the
120542 120925   ** DISTINCT list are collectively unique and individually non-null.
................................................................................
120580 120963     **
120581 120964     **   3. All of those index columns for which the WHERE clause does not
120582 120965     **      contain a "col=X" term are subject to a NOT NULL constraint.
120583 120966     */
120584 120967     for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
120585 120968       if( !IsUniqueIndex(pIdx) ) continue;
120586 120969       for(i=0; i<pIdx->nKeyCol; i++){
120587         -      i16 iCol = pIdx->aiColumn[i];
120588         -      if( 0==sqlite3WhereFindTerm(pWC, iBase, iCol, ~(Bitmask)0, WO_EQ, pIdx) ){
120589         -        int iIdxCol = findIndexCol(pParse, pDistinct, iBase, pIdx, i);
120590         -        if( iIdxCol<0 || pTab->aCol[iCol].notNull==0 ){
120591         -          break;
120592         -        }
       120970  +      if( 0==sqlite3WhereFindTerm(pWC, iBase, i, ~(Bitmask)0, WO_EQ, pIdx) ){
       120971  +        if( findIndexCol(pParse, pDistinct, iBase, pIdx, i)<0 ) break;
       120972  +        if( indexColumnNotNull(pIdx, i)==0 ) break;
120593 120973         }
120594 120974       }
120595 120975       if( i==pIdx->nKeyCol ){
120596 120976         /* This index implies that the DISTINCT qualifier is redundant. */
120597 120977         return 1;
120598 120978       }
120599 120979     }
................................................................................
120864 121244     sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
120865 121245     sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
120866 121246     VdbeComment((v, "for %s", pTable->zName));
120867 121247   
120868 121248     /* Fill the automatic index with content */
120869 121249     sqlite3ExprCachePush(pParse);
120870 121250     pTabItem = &pWC->pWInfo->pTabList->a[pLevel->iFrom];
120871         -  if( pTabItem->viaCoroutine ){
       121251  +  if( pTabItem->fg.viaCoroutine ){
120872 121252       int regYield = pTabItem->regReturn;
120873 121253       sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
120874 121254       addrTop =  sqlite3VdbeAddOp1(v, OP_Yield, regYield);
120875 121255       VdbeCoverage(v);
120876 121256       VdbeComment((v, "next row of \"%s\"", pTabItem->pTab->zName));
120877 121257     }else{
120878 121258       addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
................................................................................
120883 121263       pLoop->wsFlags |= WHERE_PARTIALIDX;
120884 121264     }
120885 121265     regRecord = sqlite3GetTempReg(pParse);
120886 121266     sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0);
120887 121267     sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
120888 121268     sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
120889 121269     if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
120890         -  if( pTabItem->viaCoroutine ){
       121270  +  if( pTabItem->fg.viaCoroutine ){
120891 121271       translateColumnToCopy(v, addrTop, pLevel->iTabCur, pTabItem->regResult);
120892         -    sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
120893         -    pTabItem->viaCoroutine = 0;
       121272  +    sqlite3VdbeGoto(v, addrTop);
       121273  +    pTabItem->fg.viaCoroutine = 0;
120894 121274     }else{
120895 121275       sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
120896 121276     }
120897 121277     sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
120898 121278     sqlite3VdbeJumpHere(v, addrTop);
120899 121279     sqlite3ReleaseTempReg(pParse, regRecord);
120900 121280     sqlite3ExprCachePop(pParse);
................................................................................
120937 121317       assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
120938 121318       testcase( pTerm->eOperator & WO_IN );
120939 121319       testcase( pTerm->eOperator & WO_ISNULL );
120940 121320       testcase( pTerm->eOperator & WO_IS );
120941 121321       testcase( pTerm->eOperator & WO_ALL );
120942 121322       if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV|WO_IS))==0 ) continue;
120943 121323       if( pTerm->wtFlags & TERM_VNULL ) continue;
       121324  +    assert( pTerm->u.leftColumn>=(-1) );
120944 121325       nTerm++;
120945 121326     }
120946 121327   
120947 121328     /* If the ORDER BY clause contains only columns in the current 
120948 121329     ** virtual table then allocate space for the aOrderBy part of
120949 121330     ** the sqlite3_index_info structure.
120950 121331     */
................................................................................
120992 121373       assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
120993 121374       testcase( pTerm->eOperator & WO_IN );
120994 121375       testcase( pTerm->eOperator & WO_IS );
120995 121376       testcase( pTerm->eOperator & WO_ISNULL );
120996 121377       testcase( pTerm->eOperator & WO_ALL );
120997 121378       if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV|WO_IS))==0 ) continue;
120998 121379       if( pTerm->wtFlags & TERM_VNULL ) continue;
       121380  +    assert( pTerm->u.leftColumn>=(-1) );
120999 121381       pIdxCons[j].iColumn = pTerm->u.leftColumn;
121000 121382       pIdxCons[j].iTermOffset = i;
121001 121383       op = (u8)pTerm->eOperator & WO_ALL;
121002 121384       if( op==WO_IN ) op = WO_EQ;
121003 121385       pIdxCons[j].op = op;
121004 121386       /* The direct assignment in the previous line is possible only because
121005 121387       ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical.  The
................................................................................
121281 121663         nRet += pTerm->truthProb;
121282 121664       }else if( (pTerm->wtFlags & TERM_VNULL)==0 ){
121283 121665         nRet -= 20;        assert( 20==sqlite3LogEst(4) );
121284 121666       }
121285 121667     }
121286 121668     return nRet;
121287 121669   }
       121670  +
       121671  +
       121672  +#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
       121673  +/*
       121674  +** Return the affinity for a single column of an index.
       121675  +*/
       121676  +static char sqlite3IndexColumnAffinity(sqlite3 *db, Index *pIdx, int iCol){
       121677  +  if( !pIdx->zColAff ){
       121678  +    if( sqlite3IndexAffinityStr(db, pIdx)==0 ) return SQLITE_AFF_BLOB;
       121679  +  }
       121680  +  return pIdx->zColAff[iCol];
       121681  +}
       121682  +#endif
       121683  +
121288 121684   
121289 121685   #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
121290 121686   /* 
121291 121687   ** This function is called to estimate the number of rows visited by a
121292 121688   ** range-scan on a skip-scan index. For example:
121293 121689   **
121294 121690   **   CREATE INDEX i1 ON t1(a, b, c);
................................................................................
121332 121728     Index *p = pLoop->u.btree.pIndex;
121333 121729     int nEq = pLoop->u.btree.nEq;
121334 121730     sqlite3 *db = pParse->db;
121335 121731     int nLower = -1;
121336 121732     int nUpper = p->nSample+1;
121337 121733     int rc = SQLITE_OK;
121338 121734     int iCol = p->aiColumn[nEq];
121339         -  u8 aff = iCol>=0 ? p->pTable->aCol[iCol].affinity : SQLITE_AFF_INTEGER;
       121735  +  u8 aff = sqlite3IndexColumnAffinity(db, p, iCol);
121340 121736     CollSeq *pColl;
121341 121737     
121342 121738     sqlite3_value *p1 = 0;          /* Value extracted from pLower */
121343 121739     sqlite3_value *p2 = 0;          /* Value extracted from pUpper */
121344 121740     sqlite3_value *pVal = 0;        /* Value extracted from record */
121345 121741   
121346 121742     pColl = sqlite3LocateCollSeq(pParse, p->azColl[nEq]);
................................................................................
121480 121876         int iLwrIdx = -2;   /* aSample[] for the lower bound */
121481 121877         int iUprIdx = -1;   /* aSample[] for the upper bound */
121482 121878   
121483 121879         if( pRec ){
121484 121880           testcase( pRec->nField!=pBuilder->nRecValid );
121485 121881           pRec->nField = pBuilder->nRecValid;
121486 121882         }
121487         -      if( nEq==p->nKeyCol ){
121488         -        aff = SQLITE_AFF_INTEGER;
121489         -      }else{
121490         -        aff = p->pTable->aCol[p->aiColumn[nEq]].affinity;
121491         -      }
       121883  +      aff = sqlite3IndexColumnAffinity(pParse->db, p, nEq);
       121884  +      assert( nEq!=p->nKeyCol || aff==SQLITE_AFF_INTEGER );
121492 121885         /* Determine iLower and iUpper using ($P) only. */
121493 121886         if( nEq==0 ){
121494 121887           iLower = 0;
121495 121888           iUpper = p->nRowEst0;
121496 121889         }else{
121497 121890           /* Note: this call could be optimized away - since the same values must 
121498 121891           ** have been requested when testing key $P in whereEqualScanEst().  */
................................................................................
121642 122035     /* This is an optimization only. The call to sqlite3Stat4ProbeSetValue()
121643 122036     ** below would return the same value.  */
121644 122037     if( nEq>=p->nColumn ){
121645 122038       *pnRow = 1;
121646 122039       return SQLITE_OK;
121647 122040     }
121648 122041   
121649         -  aff = p->pTable->aCol[p->aiColumn[nEq-1]].affinity;
       122042  +  aff = sqlite3IndexColumnAffinity(pParse->db, p, nEq-1);
121650 122043     rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq-1, &bOk);
121651 122044     pBuilder->pRec = pRec;
121652 122045     if( rc!=SQLITE_OK ) return rc;
121653 122046     if( bOk==0 ) return SQLITE_NOTFOUND;
121654 122047     pBuilder->nRecValid = nEq;
121655 122048   
121656 122049     whereKeyStats(pParse, p, pRec, 0, a);
................................................................................
122069 122462     WhereInfo *pWInfo = pBuilder->pWInfo;
122070 122463     sqlite3 *db = pWInfo->pParse->db;
122071 122464   
122072 122465     /* If pBuilder->pOrSet is defined, then only keep track of the costs
122073 122466     ** and prereqs.
122074 122467     */
122075 122468     if( pBuilder->pOrSet!=0 ){
       122469  +    if( pTemplate->nLTerm ){
122076 122470   #if WHERETRACE_ENABLED
122077         -    u16 n = pBuilder->pOrSet->n;
122078         -    int x =
       122471  +      u16 n = pBuilder->pOrSet->n;
       122472  +      int x =
122079 122473   #endif
122080         -    whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
       122474  +      whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
122081 122475                                       pTemplate->nOut);
122082 122476   #if WHERETRACE_ENABLED /* 0x8 */
122083         -    if( sqlite3WhereTrace & 0x8 ){
122084         -      sqlite3DebugPrintf(x?"   or-%d:  ":"   or-X:  ", n);
122085         -      whereLoopPrint(pTemplate, pBuilder->pWC);
       122477  +      if( sqlite3WhereTrace & 0x8 ){
       122478  +        sqlite3DebugPrintf(x?"   or-%d:  ":"   or-X:  ", n);
       122479  +        whereLoopPrint(pTemplate, pBuilder->pWC);
       122480  +      }
       122481  +#endif
122086 122482       }
122087         -#endif
122088 122483       return SQLITE_OK;
122089 122484     }
122090 122485   
122091 122486     /* Look for an existing WhereLoop to replace with pTemplate
122092 122487     */
122093 122488     whereLoopAdjustCost(pWInfo->pLoops, pTemplate);
122094 122489     ppPrev = whereLoopFindLesser(&pWInfo->pLoops, pTemplate);
................................................................................
122270 122665     WhereScan scan;                 /* Iterator for WHERE terms */
122271 122666     Bitmask saved_prereq;           /* Original value of pNew->prereq */
122272 122667     u16 saved_nLTerm;               /* Original value of pNew->nLTerm */
122273 122668     u16 saved_nEq;                  /* Original value of pNew->u.btree.nEq */
122274 122669     u16 saved_nSkip;                /* Original value of pNew->nSkip */
122275 122670     u32 saved_wsFlags;              /* Original value of pNew->wsFlags */
122276 122671     LogEst saved_nOut;              /* Original value of pNew->nOut */
122277         -  int iCol;                       /* Index of the column in the table */
122278 122672     int rc = SQLITE_OK;             /* Return code */
122279 122673     LogEst rSize;                   /* Number of rows in the table */
122280 122674     LogEst rLogSize;                /* Logarithm of table size */
122281 122675     WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
122282 122676   
122283 122677     pNew = pBuilder->pNew;
122284 122678     if( db->mallocFailed ) return SQLITE_NOMEM;
122285 122679   
122286 122680     assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
122287 122681     assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 );
122288 122682     if( pNew->wsFlags & WHERE_BTM_LIMIT ){
122289 122683       opMask = WO_LT|WO_LE;
122290         -  }else if( /*pProbe->tnum<=0 ||*/ (pSrc->jointype & JT_LEFT)!=0 ){
       122684  +  }else if( /*pProbe->tnum<=0 ||*/ (pSrc->fg.jointype & JT_LEFT)!=0 ){
122291 122685       opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE;
122292 122686     }else{
122293 122687       opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE|WO_ISNULL|WO_IS;
122294 122688     }
122295 122689     if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE);
122296 122690   
122297 122691     assert( pNew->u.btree.nEq<pProbe->nColumn );
122298         -  iCol = pProbe->aiColumn[pNew->u.btree.nEq];
122299 122692   
122300         -  pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol,
122301         -                        opMask, pProbe);
122302 122693     saved_nEq = pNew->u.btree.nEq;
122303 122694     saved_nSkip = pNew->nSkip;
122304 122695     saved_nLTerm = pNew->nLTerm;
122305 122696     saved_wsFlags = pNew->wsFlags;
122306 122697     saved_prereq = pNew->prereq;
122307 122698     saved_nOut = pNew->nOut;
       122699  +  pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, saved_nEq,
       122700  +                        opMask, pProbe);
122308 122701     pNew->rSetup = 0;
122309 122702     rSize = pProbe->aiRowLogEst[0];
122310 122703     rLogSize = estLog(rSize);
122311 122704     for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
122312 122705       u16 eOp = pTerm->eOperator;   /* Shorthand for pTerm->eOperator */
122313 122706       LogEst rCostIdx;
122314 122707       LogEst nOutUnadjusted;        /* nOut before IN() and WHERE adjustments */
122315 122708       int nIn = 0;
122316 122709   #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
122317 122710       int nRecValid = pBuilder->nRecValid;
122318 122711   #endif
122319 122712       if( (eOp==WO_ISNULL || (pTerm->wtFlags&TERM_VNULL)!=0)
122320         -     && (iCol<0 || pSrc->pTab->aCol[iCol].notNull)
       122713  +     && indexColumnNotNull(pProbe, saved_nEq)
122321 122714       ){
122322 122715         continue; /* ignore IS [NOT] NULL constraints on NOT NULL columns */
122323 122716       }
122324 122717       if( pTerm->prereqRight & pNew->maskSelf ) continue;
122325 122718   
122326 122719       /* Do not allow the upper bound of a LIKE optimization range constraint
122327 122720       ** to mix with a lower range bound from some other source */
................................................................................
122350 122743           /* "x IN (value, value, ...)" */
122351 122744           nIn = sqlite3LogEst(pExpr->x.pList->nExpr);
122352 122745         }
122353 122746         assert( nIn>0 );  /* RHS always has 2 or more terms...  The parser
122354 122747                           ** changes "x IN (?)" into "x=?". */
122355 122748   
122356 122749       }else if( eOp & (WO_EQ|WO_IS) ){
       122750  +      int iCol = pProbe->aiColumn[saved_nEq];
122357 122751         pNew->wsFlags |= WHERE_COLUMN_EQ;
122358         -      if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){
       122752  +      assert( saved_nEq==pNew->u.btree.nEq );
       122753  +      if( iCol==(-1) || (iCol>0 && nInMul==0 && saved_nEq==pProbe->nKeyCol-1) ){
122359 122754           if( iCol>=0 && pProbe->uniqNotNull==0 ){
122360 122755             pNew->wsFlags |= WHERE_UNQ_WANTED;
122361 122756           }else{
122362 122757             pNew->wsFlags |= WHERE_ONEROW;
122363 122758           }
122364 122759         }
122365 122760       }else if( eOp & WO_ISNULL ){
................................................................................
122402 122797         ** data, using some other estimate.  */
122403 122798         whereRangeScanEst(pParse, pBuilder, pBtm, pTop, pNew);
122404 122799       }else{
122405 122800         int nEq = ++pNew->u.btree.nEq;
122406 122801         assert( eOp & (WO_ISNULL|WO_EQ|WO_IN|WO_IS) );
122407 122802   
122408 122803         assert( pNew->nOut==saved_nOut );
122409         -      if( pTerm->truthProb<=0 && iCol>=0 ){
       122804  +      if( pTerm->truthProb<=0 && pProbe->aiColumn[saved_nEq]>=0 ){
122410 122805           assert( (eOp & WO_IN) || nIn==0 );
122411 122806           testcase( eOp & WO_IN );
122412 122807           pNew->nOut += pTerm->truthProb;
122413 122808           pNew->nOut -= nIn;
122414 122809         }else{
122415 122810   #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
122416 122811           tRowcnt nOut = 0;
................................................................................
122578 122973   
122579 122974   /* Check to see if a partial index with pPartIndexWhere can be used
122580 122975   ** in the current query.  Return true if it can be and false if not.
122581 122976   */
122582 122977   static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){
122583 122978     int i;
122584 122979     WhereTerm *pTerm;
       122980  +  while( pWhere->op==TK_AND ){
       122981  +    if( !whereUsablePartialIndex(iTab,pWC,pWhere->pLeft) ) return 0;
       122982  +    pWhere = pWhere->pRight;
       122983  +  }
122585 122984     for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
122586 122985       Expr *pExpr = pTerm->pExpr;
122587 122986       if( sqlite3ExprImpliesExpr(pExpr, pWhere, iTab) 
122588 122987        && (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab)
122589 122988       ){
122590 122989         return 1;
122591 122990       }
................................................................................
122653 123052     pWInfo = pBuilder->pWInfo;
122654 123053     pTabList = pWInfo->pTabList;
122655 123054     pSrc = pTabList->a + pNew->iTab;
122656 123055     pTab = pSrc->pTab;
122657 123056     pWC = pBuilder->pWC;
122658 123057     assert( !IsVirtual(pSrc->pTab) );
122659 123058   
122660         -  if( pSrc->pIndex ){
       123059  +  if( pSrc->pIBIndex ){
122661 123060       /* An INDEXED BY clause specifies a particular index to use */
122662         -    pProbe = pSrc->pIndex;
       123061  +    pProbe = pSrc->pIBIndex;
122663 123062     }else if( !HasRowid(pTab) ){
122664 123063       pProbe = pTab->pIndex;
122665 123064     }else{
122666 123065       /* There is no INDEXED BY clause.  Create a fake Index object in local
122667 123066       ** variable sPk to represent the rowid primary key index.  Make this
122668 123067       ** fake index the first in a chain of Index objects with all of the real
122669 123068       ** indices to follow */
................................................................................
122675 123074       sPk.aiRowLogEst = aiRowEstPk;
122676 123075       sPk.onError = OE_Replace;
122677 123076       sPk.pTable = pTab;
122678 123077       sPk.szIdxRow = pTab->szTabRow;
122679 123078       aiRowEstPk[0] = pTab->nRowLogEst;
122680 123079       aiRowEstPk[1] = 0;
122681 123080       pFirst = pSrc->pTab->pIndex;
122682         -    if( pSrc->notIndexed==0 ){
       123081  +    if( pSrc->fg.notIndexed==0 ){
122683 123082         /* The real indices of the table are only considered if the
122684 123083         ** NOT INDEXED qualifier is omitted from the FROM clause */
122685 123084         sPk.pNext = pFirst;
122686 123085       }
122687 123086       pProbe = &sPk;
122688 123087     }
122689 123088     rSize = pTab->nRowLogEst;
122690 123089     rLogSize = estLog(rSize);
122691 123090   
122692 123091   #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
122693 123092     /* Automatic indexes */
122694         -  if( !pBuilder->pOrSet   /* Not part of an OR optimization */
       123093  +  if( !pBuilder->pOrSet      /* Not part of an OR optimization */
122695 123094      && (pWInfo->wctrlFlags & WHERE_NO_AUTOINDEX)==0
122696 123095      && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
122697         -   && pSrc->pIndex==0     /* Has no INDEXED BY clause */
122698         -   && !pSrc->notIndexed   /* Has no NOT INDEXED clause */
122699         -   && HasRowid(pTab)      /* Is not a WITHOUT ROWID table. (FIXME: Why not?) */
122700         -   && !pSrc->isCorrelated /* Not a correlated subquery */
122701         -   && !pSrc->isRecursive  /* Not a recursive common table expression. */
       123096  +   && pSrc->pIBIndex==0      /* Has no INDEXED BY clause */
       123097  +   && !pSrc->fg.notIndexed   /* Has no NOT INDEXED clause */
       123098  +   && HasRowid(pTab)         /* Is not a WITHOUT ROWID table. (FIXME: Why not?) */
       123099  +   && !pSrc->fg.isCorrelated /* Not a correlated subquery */
       123100  +   && !pSrc->fg.isRecursive  /* Not a recursive common table expression. */
122702 123101     ){
122703 123102       /* Generate auto-index WhereLoops */
122704 123103       WhereTerm *pTerm;
122705 123104       WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
122706 123105       for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
122707 123106         if( pTerm->prereqRight & pNew->maskSelf ) continue;
122708 123107         if( termCanDriveIndex(pTerm, pSrc, 0) ){
................................................................................
122815 123214       sqlite3Stat4ProbeFree(pBuilder->pRec);
122816 123215       pBuilder->nRecValid = 0;
122817 123216       pBuilder->pRec = 0;
122818 123217   #endif
122819 123218   
122820 123219       /* If there was an INDEXED BY clause, then only that one index is
122821 123220       ** considered. */
122822         -    if( pSrc->pIndex ) break;
       123221  +    if( pSrc->pIBIndex ) break;
122823 123222     }
122824 123223     return rc;
122825 123224   }
122826 123225   
122827 123226   #ifndef SQLITE_OMIT_VIRTUALTABLE
122828 123227   /*
122829 123228   ** Add all WhereLoop objects for a table of the join identified by
................................................................................
123161 123560     /* Loop over the tables in the join, from left to right */
123162 123561     pNew = pBuilder->pNew;
123163 123562     whereLoopInit(pNew);
123164 123563     for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
123165 123564       Bitmask mUnusable = 0;
123166 123565       pNew->iTab = iTab;
123167 123566       pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
123168         -    if( ((pItem->jointype|priorJointype) & (JT_LEFT|JT_CROSS))!=0 ){
       123567  +    if( ((pItem->fg.jointype|priorJointype) & (JT_LEFT|JT_CROSS))!=0 ){
123169 123568         /* This condition is true when pItem is the FROM clause term on the
123170 123569         ** right-hand-side of a LEFT or CROSS JOIN.  */
123171 123570         mExtra = mPrior;
123172 123571       }
123173         -    priorJointype = pItem->jointype;
       123572  +    priorJointype = pItem->fg.jointype;
123174 123573       if( IsVirtual(pItem->pTab) ){
123175 123574         struct SrcList_item *p;
123176 123575         for(p=&pItem[1]; p<pEnd; p++){
123177         -        if( mUnusable || (p->jointype & (JT_LEFT|JT_CROSS)) ){
       123576  +        if( mUnusable || (p->fg.jointype & (JT_LEFT|JT_CROSS)) ){
123178 123577             mUnusable |= sqlite3WhereGetMask(&pWInfo->sMaskSet, p->iCursor);
123179 123578           }
123180 123579         }
123181 123580         rc = whereLoopAddVirtual(pBuilder, mExtra, mUnusable);
123182 123581       }else{
123183 123582         rc = whereLoopAddBtree(pBuilder, mExtra);
123184 123583       }
................................................................................
123900 124299     
123901 124300     pWInfo = pBuilder->pWInfo;
123902 124301     if( pWInfo->wctrlFlags & WHERE_FORCE_TABLE ) return 0;
123903 124302     assert( pWInfo->pTabList->nSrc>=1 );
123904 124303     pItem = pWInfo->pTabList->a;
123905 124304     pTab = pItem->pTab;
123906 124305     if( IsVirtual(pTab) ) return 0;
123907         -  if( pItem->zIndexedBy ) return 0;
       124306  +  if( pItem->fg.isIndexedBy ) return 0;
123908 124307     iCur = pItem->iCursor;
123909 124308     pWC = &pWInfo->sWC;
123910 124309     pLoop = pBuilder->pNew;
123911 124310     pLoop->wsFlags = 0;
123912 124311     pLoop->nSkip = 0;
123913 124312     pTerm = sqlite3WhereFindTerm(pWC, iCur, -1, 0, WO_EQ|WO_IS, 0);
123914 124313     if( pTerm ){
................................................................................
123925 124324         assert( pLoop->aLTermSpace==pLoop->aLTerm );
123926 124325         if( !IsUniqueIndex(pIdx)
123927 124326          || pIdx->pPartIdxWhere!=0 
123928 124327          || pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace) 
123929 124328         ) continue;
123930 124329         opMask = pIdx->uniqNotNull ? (WO_EQ|WO_IS) : WO_EQ;
123931 124330         for(j=0; j<pIdx->nKeyCol; j++){
123932         -        pTerm = sqlite3WhereFindTerm(pWC, iCur, pIdx->aiColumn[j], 0, opMask, pIdx);
       124331  +        pTerm = sqlite3WhereFindTerm(pWC, iCur, j, 0, opMask, pIdx);
123933 124332           if( pTerm==0 ) break;
123934 124333           testcase( pTerm->eOperator & WO_IS );
123935 124334           pLoop->aLTerm[j] = pTerm;
123936 124335         }
123937 124336         if( j!=pIdx->nKeyCol ) continue;
123938 124337         pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_ONEROW|WHERE_INDEXED;
123939 124338         if( pIdx->isCovering || (pItem->colUsed & ~columnsInIndex(pIdx))==0 ){
................................................................................
124165 124564       if( wctrlFlags & WHERE_WANT_DISTINCT ){
124166 124565         pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
124167 124566       }
124168 124567     }
124169 124568   
124170 124569     /* Assign a bit from the bitmask to every term in the FROM clause.
124171 124570     **
124172         -  ** When assigning bitmask values to FROM clause cursors, it must be
124173         -  ** the case that if X is the bitmask for the N-th FROM clause term then
124174         -  ** the bitmask for all FROM clause terms to the left of the N-th term
124175         -  ** is (X-1).   An expression from the ON clause of a LEFT JOIN can use
124176         -  ** its Expr.iRightJoinTable value to find the bitmask of the right table
124177         -  ** of the join.  Subtracting one from the right table bitmask gives a
124178         -  ** bitmask for all tables to the left of the join.  Knowing the bitmask
124179         -  ** for all tables to the left of a left join is important.  Ticket #3015.
       124571  +  ** The N-th term of the FROM clause is assigned a bitmask of 1<<N.
       124572  +  **
       124573  +  ** The rule of the previous sentence ensures thta if X is the bitmask for
       124574  +  ** a table T, then X-1 is the bitmask for all other tables to the left of T.
       124575  +  ** Knowing the bitmask for all tables to the left of a left join is
       124576  +  ** important.  Ticket #3015.
124180 124577     **
124181 124578     ** Note that bitmasks are created for all pTabList->nSrc tables in
124182 124579     ** pTabList, not just the first nTabList tables.  nTabList is normally
124183 124580     ** equal to pTabList->nSrc but might be shortened to 1 if the
124184 124581     ** WHERE_ONETABLE_ONLY flag is set.
124185 124582     */
124186 124583     for(ii=0; ii<pTabList->nSrc; ii++){
124187 124584       createMask(pMaskSet, pTabList->a[ii].iCursor);
       124585  +    sqlite3WhereTabFuncArgs(pParse, &pTabList->a[ii], &pWInfo->sWC);
124188 124586     }
124189         -#ifndef NDEBUG
124190         -  {
124191         -    Bitmask toTheLeft = 0;
124192         -    for(ii=0; ii<pTabList->nSrc; ii++){
124193         -      Bitmask m = sqlite3WhereGetMask(pMaskSet, pTabList->a[ii].iCursor);
124194         -      assert( (m-1)==toTheLeft );
124195         -      toTheLeft |= m;
124196         -    }
       124587  +#ifdef SQLITE_DEBUG
       124588  +  for(ii=0; ii<pTabList->nSrc; ii++){
       124589  +    Bitmask m = sqlite3WhereGetMask(pMaskSet, pTabList->a[ii].iCursor);
       124590  +    assert( m==MASKBIT(ii) );
124197 124591     }
124198 124592   #endif
124199 124593   
124200 124594     /* Analyze all of the subexpressions. */
124201 124595     sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
124202 124596     if( db->mallocFailed ) goto whereBeginError;
124203 124597   
................................................................................
124287 124681       Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet);
124288 124682       if( sWLB.pOrderBy ){
124289 124683         tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy);
124290 124684       }
124291 124685       while( pWInfo->nLevel>=2 ){
124292 124686         WhereTerm *pTerm, *pEnd;
124293 124687         pLoop = pWInfo->a[pWInfo->nLevel-1].pWLoop;
124294         -      if( (pWInfo->pTabList->a[pLoop->iTab].jointype & JT_LEFT)==0 ) break;
       124688  +      if( (pWInfo->pTabList->a[pLoop->iTab].fg.jointype & JT_LEFT)==0 ) break;
124295 124689         if( (wctrlFlags & WHERE_WANT_DISTINCT)==0
124296 124690          && (pLoop->wsFlags & WHERE_ONEROW)==0
124297 124691         ){
124298 124692           break;
124299 124693         }
124300 124694         if( (tabUsed & pLoop->maskSelf)!=0 ) break;
124301 124695         pEnd = sWLB.pWC->a + sWLB.pWC->nTerm;
................................................................................
124525 124919           VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen);
124526 124920           VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen);
124527 124921           sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
124528 124922         }
124529 124923       }
124530 124924       sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
124531 124925       if( pLevel->addrSkip ){
124532         -      sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
       124926  +      sqlite3VdbeGoto(v, pLevel->addrSkip);
124533 124927         VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
124534 124928         sqlite3VdbeJumpHere(v, pLevel->addrSkip);
124535 124929         sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
124536 124930       }
124537 124931       if( pLevel->addrLikeRep ){
124538 124932         int op;
124539 124933         if( sqlite3VdbeGetOp(v, pLevel->addrLikeRep-1)->p1 ){
................................................................................
124553 124947         }
124554 124948         if( pLoop->wsFlags & WHERE_INDEXED ){
124555 124949           sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur);
124556 124950         }
124557 124951         if( pLevel->op==OP_Return ){
124558 124952           sqlite3VdbeAddOp2(v, OP_Gosub, pLevel->p1, pLevel->addrFirst);
124559 124953         }else{
124560         -        sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrFirst);
       124954  +        sqlite3VdbeGoto(v, pLevel->addrFirst);
124561 124955         }
124562 124956         sqlite3VdbeJumpHere(v, addr);
124563 124957       }
124564 124958       VdbeModuleComment((v, "End WHERE-loop%d: %s", i,
124565 124959                        pWInfo->pTabList->a[pLevel->iFrom].pTab->zName));
124566 124960     }
124567 124961   
................................................................................
124580 124974       assert( pTab!=0 );
124581 124975       pLoop = pLevel->pWLoop;
124582 124976   
124583 124977       /* For a co-routine, change all OP_Column references to the table of
124584 124978       ** the co-routine into OP_Copy of result contained in a register.
124585 124979       ** OP_Rowid becomes OP_Null.
124586 124980       */
124587         -    if( pTabItem->viaCoroutine && !db->mallocFailed ){
       124981  +    if( pTabItem->fg.viaCoroutine && !db->mallocFailed ){
124588 124982         translateColumnToCopy(v, pLevel->addrBody, pLevel->iTabCur,
124589 124983                               pTabItem->regResult);
124590 124984         continue;
124591 124985       }
124592 124986   
124593 124987       /* Close all of the cursors that were opened by sqlite3WhereBegin.
124594 124988       ** Except, do not close cursors that will be reused by the OR optimization
................................................................................
124814 125208       ExprSpan *pOperand,    /* The operand */
124815 125209       Token *pPreOp         /* The operand token for setting the span */
124816 125210     ){
124817 125211       pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0);
124818 125212       pOut->zStart = pPreOp->z;
124819 125213       pOut->zEnd = pOperand->zEnd;
124820 125214     }
       125215  +
       125216  +  /* Add a single new term to an ExprList that is used to store a
       125217  +  ** list of identifiers.  Report an error if the ID list contains
       125218  +  ** a COLLATE clause or an ASC or DESC keyword, except ignore the
       125219  +  ** error while parsing a legacy schema.
       125220  +  */
       125221  +  static ExprList *parserAddExprIdListTerm(
       125222  +    Parse *pParse,
       125223  +    ExprList *pPrior,
       125224  +    Token *pIdToken,
       125225  +    int hasCollate,
       125226  +    int sortOrder
       125227  +  ){
       125228  +    ExprList *p = sqlite3ExprListAppend(pParse, pPrior, 0);
       125229  +    if( (hasCollate || sortOrder!=SQLITE_SO_UNDEFINED)
       125230  +        && pParse->db->init.busy==0
       125231  +    ){
       125232  +      sqlite3ErrorMsg(pParse, "syntax error after column name \"%.*s\"",
       125233  +                         pIdToken->n, pIdToken->z);
       125234  +    }
       125235  +    sqlite3ExprListSetName(pParse, p, pIdToken, 1);
       125236  +    return p;
       125237  +  }
124821 125238   /* Next is all token values, in a form suitable for use by makeheaders.
124822 125239   ** This section will be null unless lemon is run with the -m switch.
124823 125240   */
124824 125241   /* 
124825 125242   ** These constants (all generated automatically by the parser generator)
124826 125243   ** specify the various kinds of tokens (terminals) that the parser
124827 125244   ** understands. 
................................................................................
124858 125275   **                       for base tokens is called "yy0".
124859 125276   **    YYSTACKDEPTH       is the maximum depth of the parser's stack.  If
124860 125277   **                       zero the stack is dynamically sized using realloc()
124861 125278   **    sqlite3ParserARG_SDECL     A static variable declaration for the %extra_argument
124862 125279   **    sqlite3ParserARG_PDECL     A parameter declaration for the %extra_argument
124863 125280   **    sqlite3ParserARG_STORE     Code to store %extra_argument into yypParser
124864 125281   **    sqlite3ParserARG_FETCH     Code to extract %extra_argument from yypParser
       125282  +**    YYERRORSYMBOL      is the code number of the error symbol.  If not
       125283  +**                       defined, then do no error processing.
124865 125284   **    YYNSTATE           the combined number of states.
124866 125285   **    YYNRULE            the number of rules in the grammar
124867         -**    YYERRORSYMBOL      is the code number of the error symbol.  If not
124868         -**                       defined, then do no error processing.
       125286  +**    YY_MAX_SHIFT       Maximum value for shift actions
       125287  +**    YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
       125288  +**    YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
       125289  +**    YY_MIN_REDUCE      Maximum value for reduce actions
       125290  +**    YY_ERROR_ACTION    The yy_action[] code for syntax error
       125291  +**    YY_ACCEPT_ACTION   The yy_action[] code for accept
       125292  +**    YY_NO_ACTION       The yy_action[] code for no-op
124869 125293   */
124870 125294   #define YYCODETYPE unsigned char
124871 125295   #define YYNOCODE 254
124872 125296   #define YYACTIONTYPE unsigned short int
124873 125297   #define YYWILDCARD 70
124874 125298   #define sqlite3ParserTOKENTYPE Token
124875 125299   typedef union {
................................................................................
124894 125318   #ifndef YYSTACKDEPTH
124895 125319   #define YYSTACKDEPTH 100
124896 125320   #endif
124897 125321   #define sqlite3ParserARG_SDECL Parse *pParse;
124898 125322   #define sqlite3ParserARG_PDECL ,Parse *pParse
124899 125323   #define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse
124900 125324   #define sqlite3ParserARG_STORE yypParser->pParse = pParse
124901         -#define YYNSTATE 642
124902         -#define YYNRULE 327
124903 125325   #define YYFALLBACK 1
124904         -#define YY_NO_ACTION      (YYNSTATE+YYNRULE+2)
124905         -#define YY_ACCEPT_ACTION  (YYNSTATE+YYNRULE+1)
124906         -#define YY_ERROR_ACTION   (YYNSTATE+YYNRULE)
       125326  +#define YYNSTATE             436
       125327  +#define YYNRULE              328
       125328  +#define YY_MAX_SHIFT         435
       125329  +#define YY_MIN_SHIFTREDUCE   649
       125330  +#define YY_MAX_SHIFTREDUCE   976
       125331  +#define YY_MIN_REDUCE        977
       125332  +#define YY_MAX_REDUCE        1304
       125333  +#define YY_ERROR_ACTION      1305
       125334  +#define YY_ACCEPT_ACTION     1306
       125335  +#define YY_NO_ACTION         1307
124907 125336   
124908 125337   /* The yyzerominor constant is used to initialize instances of
124909 125338   ** YYMINORTYPE objects to zero. */
124910 125339   static const YYMINORTYPE yyzerominor = { 0 };
124911 125340   
124912 125341   /* Define the yytestcase() macro to be a no-op if is not already defined
124913 125342   ** otherwise.
................................................................................
124926 125355   ** current state and lookahead token.  These tables are used to implement
124927 125356   ** functions that take a state number and lookahead value and return an
124928 125357   ** action integer.  
124929 125358   **
124930 125359   ** Suppose the action integer is N.  Then the action is determined as
124931 125360   ** follows
124932 125361   **
124933         -**   0 <= N < YYNSTATE                  Shift N.  That is, push the lookahead
       125362  +**   0 <= N <= YY_MAX_SHIFT             Shift N.  That is, push the lookahead
124934 125363   **                                      token onto the stack and goto state N.
124935 125364   **
124936         -**   YYNSTATE <= N < YYNSTATE+YYNRULE   Reduce by rule N-YYNSTATE.
       125365  +**   N between YY_MIN_SHIFTREDUCE       Shift to an arbitrary state then
       125366  +**     and YY_MAX_SHIFTREDUCE           reduce by rule N-YY_MIN_SHIFTREDUCE.
124937 125367   **
124938         -**   N == YYNSTATE+YYNRULE              A syntax error has occurred.
       125368  +**   N between YY_MIN_REDUCE            Reduce by rule N-YY_MIN_REDUCE
       125369  +**     and YY_MAX_REDUCE
       125370  +
       125371  +**   N == YY_ERROR_ACTION               A syntax error has occurred.
124939 125372   **
124940         -**   N == YYNSTATE+YYNRULE+1            The parser accepts its input.
       125373  +**   N == YY_ACCEPT_ACTION              The parser accepts its input.
124941 125374   **
124942         -**   N == YYNSTATE+YYNRULE+2            No such action.  Denotes unused
       125375  +**   N == YY_NO_ACTION                  No such action.  Denotes unused
124943 125376   **                                      slots in the yy_action[] table.
124944 125377   **
124945 125378   ** The action table is constructed as a single large table named yy_action[].
124946 125379   ** Given state S and lookahead X, the action is computed as
124947 125380   **
124948 125381   **      yy_action[ yy_shift_ofst[S] + X ]
124949 125382   **
................................................................................
124965 125398   **                     yy_action.  Used to detect hash collisions.
124966 125399   **  yy_shift_ofst[]    For each state, the offset into yy_action for
124967 125400   **                     shifting terminals.
124968 125401   **  yy_reduce_ofst[]   For each state, the offset into yy_action for
124969 125402   **                     shifting non-terminals after a reduce.
124970 125403   **  yy_default[]       Default action for each state.
124971 125404   */
124972         -#define YY_ACTTAB_COUNT (1497)
       125405  +#define YY_ACTTAB_COUNT (1501)
124973 125406   static const YYACTIONTYPE yy_action[] = {
124974         - /*     0 */   306,  212,  432,  955,  639,  191,  955,  295,  559,   88,
124975         - /*    10 */    88,   88,   88,   81,   86,   86,   86,   86,   85,   85,
124976         - /*    20 */    84,   84,   84,   83,  330,  185,  184,  183,  635,  635,
124977         - /*    30 */   292,  606,  606,   88,   88,   88,   88,  683,   86,   86,
124978         - /*    40 */    86,   86,   85,   85,   84,   84,   84,   83,  330,   16,
124979         - /*    50 */   436,  597,   89,   90,   80,  600,  599,  601,  601,   87,
124980         - /*    60 */    87,   88,   88,   88,   88,  684,   86,   86,   86,   86,
124981         - /*    70 */    85,   85,   84,   84,   84,   83,  330,  306,  559,   84,
124982         - /*    80 */    84,   84,   83,  330,   65,   86,   86,   86,   86,   85,
124983         - /*    90 */    85,   84,   84,   84,   83,  330,  635,  635,  634,  633,
124984         - /*   100 */   182,  682,  550,  379,  376,  375,   17,  322,  606,  606,
124985         - /*   110 */   371,  198,  479,   91,  374,   82,   79,  165,   85,   85,
124986         - /*   120 */    84,   84,   84,   83,  330,  598,  635,  635,  107,   89,
124987         - /*   130 */    90,   80,  600,  599,  601,  601,   87,   87,   88,   88,
124988         - /*   140 */    88,   88,  186,   86,   86,   86,   86,   85,   85,   84,
124989         - /*   150 */    84,   84,   83,  330,  306,  594,  594,  142,  328,  327,
124990         - /*   160 */   484,  249,  344,  238,  635,  635,  634,  633,  585,  448,
124991         - /*   170 */   526,  525,  229,  388,    1,  394,  450,  584,  449,  635,
124992         - /*   180 */   635,  635,  635,  319,  395,  606,  606,  199,  157,  273,
124993         - /*   190 */   382,  268,  381,  187,  635,  635,  634,  633,  311,  555,
124994         - /*   200 */   266,  593,  593,  266,  347,  588,   89,   90,   80,  600,
124995         - /*   210 */   599,  601,  601,   87,   87,   88,   88,   88,   88,  478,
124996         - /*   220 */    86,   86,   86,   86,   85,   85,   84,   84,   84,   83,
124997         - /*   230 */   330,  306,  272,  536,  634,  633,  146,  610,  197,  310,
124998         - /*   240 */   575,  182,  482,  271,  379,  376,  375,  506,   21,  634,
124999         - /*   250 */   633,  634,  633,  635,  635,  374,  611,  574,  548,  440,
125000         - /*   260 */   111,  563,  606,  606,  634,  633,  324,  479,  608,  608,
125001         - /*   270 */   608,  300,  435,  573,  119,  407,  210,  162,  562,  883,
125002         - /*   280 */   592,  592,  306,   89,   90,   80,  600,  599,  601,  601,
125003         - /*   290 */    87,   87,   88,   88,   88,   88,  506,   86,   86,   86,
125004         - /*   300 */    86,   85,   85,   84,   84,   84,   83,  330,  620,  111,
125005         - /*   310 */   635,  635,  361,  606,  606,  358,  249,  349,  248,  433,
125006         - /*   320 */   243,  479,  586,  634,  633,  195,  611,   93,  119,  221,
125007         - /*   330 */   575,  497,  534,  534,   89,   90,   80,  600,  599,  601,
125008         - /*   340 */   601,   87,   87,   88,   88,   88,   88,  574,   86,   86,
125009         - /*   350 */    86,   86,   85,   85,   84,   84,   84,   83,  330,  306,
125010         - /*   360 */    77,  429,  638,  573,  589,  530,  240,  230,  242,  105,
125011         - /*   370 */   249,  349,  248,  515,  588,  208,  460,  529,  564,  173,
125012         - /*   380 */   634,  633,  970,  144,  430,    2,  424,  228,  380,  557,
125013         - /*   390 */   606,  606,  190,  153,  159,  158,  514,   51,  632,  631,
125014         - /*   400 */   630,   71,  536,  432,  954,  196,  610,  954,  614,   45,
125015         - /*   410 */    18,   89,   90,   80,  600,  599,  601,  601,   87,   87,
125016         - /*   420 */    88,   88,   88,   88,  261,   86,   86,   86,   86,   85,
125017         - /*   430 */    85,   84,   84,   84,   83,  330,  306,  608,  608,  608,
125018         - /*   440 */   542,  424,  402,  385,  241,  506,  451,  320,  211,  543,
125019         - /*   450 */   164,  436,  386,  293,  451,  587,  108,  496,  111,  334,
125020         - /*   460 */   391,  591,  424,  614,   27,  452,  453,  606,  606,   72,
125021         - /*   470 */   257,   70,  259,  452,  339,  342,  564,  582,   68,  415,
125022         - /*   480 */   469,  328,  327,   62,  614,   45,  110,  393,   89,   90,
125023         - /*   490 */    80,  600,  599,  601,  601,   87,   87,   88,   88,   88,
125024         - /*   500 */    88,  152,   86,   86,   86,   86,   85,   85,   84,   84,
125025         - /*   510 */    84,   83,  330,  306,  110,  499,  520,  538,  402,  389,
125026         - /*   520 */   424,  110,  566,  500,  593,  593,  454,   82,   79,  165,
125027         - /*   530 */   424,  591,  384,  564,  340,  615,  188,  162,  424,  350,
125028         - /*   540 */   616,  424,  614,   44,  606,  606,  445,  582,  300,  434,
125029         - /*   550 */   151,   19,  614,    9,  568,  580,  348,  615,  469,  567,
125030         - /*   560 */   614,   26,  616,  614,   45,   89,   90,   80,  600,  599,
125031         - /*   570 */   601,  601,   87,   87,   88,   88,   88,   88,  411,   86,
125032         - /*   580 */    86,   86,   86,   85,   85,   84,   84,   84,   83,  330,
125033         - /*   590 */   306,  579,  110,  578,  521,  282,  433,  398,  400,  255,
125034         - /*   600 */   486,   82,   79,  165,  487,  164,   82,   79,  165,  488,
125035         - /*   610 */   488,  364,  387,  424,  544,  544,  509,  350,  362,  155,
125036         - /*   620 */   191,  606,  606,  559,  642,  640,  333,   82,   79,  165,
125037         - /*   630 */   305,  564,  507,  312,  357,  614,   45,  329,  596,  595,
125038         - /*   640 */   194,  337,   89,   90,   80,  600,  599,  601,  601,   87,
125039         - /*   650 */    87,   88,   88,   88,   88,  424,   86,   86,   86,   86,
125040         - /*   660 */    85,   85,   84,   84,   84,   83,  330,  306,   20,  323,
125041         - /*   670 */   150,  263,  211,  543,  421,  596,  595,  614,   22,  424,
125042         - /*   680 */   193,  424,  284,  424,  391,  424,  509,  424,  577,  424,
125043         - /*   690 */   186,  335,  424,  559,  424,  313,  120,  546,  606,  606,
125044         - /*   700 */    67,  614,   47,  614,   50,  614,   48,  614,  100,  614,
125045         - /*   710 */    99,  614,  101,  576,  614,  102,  614,  109,  326,   89,
125046         - /*   720 */    90,   80,  600,  599,  601,  601,   87,   87,   88,   88,
125047         - /*   730 */    88,   88,  424,   86,   86,   86,   86,   85,   85,   84,
125048         - /*   740 */    84,   84,   83,  330,  306,  424,  311,  424,  585,   54,
125049         - /*   750 */   424,  516,  517,  590,  614,  112,  424,  584,  424,  572,
125050         - /*   760 */   424,  195,  424,  571,  424,   67,  424,  614,   94,  614,
125051         - /*   770 */    98,  424,  614,   97,  264,  606,  606,  195,  614,   46,
125052         - /*   780 */   614,   96,  614,   30,  614,   49,  614,  115,  614,  114,
125053         - /*   790 */   418,  229,  388,  614,  113,  306,   89,   90,   80,  600,
125054         - /*   800 */   599,  601,  601,   87,   87,   88,   88,   88,   88,  424,
125055         - /*   810 */    86,   86,   86,   86,   85,   85,   84,   84,   84,   83,
125056         - /*   820 */   330,  119,  424,  590,  110,  372,  606,  606,  195,   53,
125057         - /*   830 */   250,  614,   29,  195,  472,  438,  729,  190,  302,  498,
125058         - /*   840 */    14,  523,  641,    2,  614,   43,  306,   89,   90,   80,
125059         - /*   850 */   600,  599,  601,  601,   87,   87,   88,   88,   88,   88,
125060         - /*   860 */   424,   86,   86,   86,   86,   85,   85,   84,   84,   84,
125061         - /*   870 */    83,  330,  424,  613,  964,  964,  354,  606,  606,  420,
125062         - /*   880 */   312,   64,  614,   42,  391,  355,  283,  437,  301,  255,
125063         - /*   890 */   414,  410,  495,  492,  614,   28,  471,  306,   89,   90,
125064         - /*   900 */    80,  600,  599,  601,  601,   87,   87,   88,   88,   88,
125065         - /*   910 */    88,  424,   86,   86,   86,   86,   85,   85,   84,   84,
125066         - /*   920 */    84,   83,  330,  424,  110,  110,  110,  110,  606,  606,
125067         - /*   930 */   110,  254,   13,  614,   41,  532,  531,  283,  481,  531,
125068         - /*   940 */   457,  284,  119,  561,  356,  614,   40,  284,  306,   89,
125069         - /*   950 */    78,   80,  600,  599,  601,  601,   87,   87,   88,   88,
125070         - /*   960 */    88,   88,  424,   86,   86,   86,   86,   85,   85,   84,
125071         - /*   970 */    84,   84,   83,  330,  110,  424,  341,  220,  555,  606,
125072         - /*   980 */   606,  351,  555,  318,  614,   95,  413,  255,   83,  330,
125073         - /*   990 */   284,  284,  255,  640,  333,  356,  255,  614,   39,  306,
125074         - /*  1000 */   356,   90,   80,  600,  599,  601,  601,   87,   87,   88,
125075         - /*  1010 */    88,   88,   88,  424,   86,   86,   86,   86,   85,   85,
125076         - /*  1020 */    84,   84,   84,   83,  330,  424,  317,  316,  141,  465,
125077         - /*  1030 */   606,  606,  219,  619,  463,  614,   10,  417,  462,  255,
125078         - /*  1040 */   189,  510,  553,  351,  207,  363,  161,  614,   38,  315,
125079         - /*  1050 */   218,  255,  255,   80,  600,  599,  601,  601,   87,   87,
125080         - /*  1060 */    88,   88,   88,   88,  424,   86,   86,   86,   86,   85,
125081         - /*  1070 */    85,   84,   84,   84,   83,  330,   76,  419,  255,    3,
125082         - /*  1080 */   878,  461,  424,  247,  331,  331,  614,   37,  217,   76,
125083         - /*  1090 */   419,  390,    3,  216,  215,  422,    4,  331,  331,  424,
125084         - /*  1100 */   547,   12,  424,  545,  614,   36,  424,  541,  422,  424,
125085         - /*  1110 */   540,  424,  214,  424,  408,  424,  539,  403,  605,  605,
125086         - /*  1120 */   237,  614,   25,  119,  614,   24,  588,  408,  614,   45,
125087         - /*  1130 */   118,  614,   35,  614,   34,  614,   33,  614,   23,  588,
125088         - /*  1140 */    60,  223,  603,  602,  513,  378,   73,   74,  140,  139,
125089         - /*  1150 */   424,  110,  265,   75,  426,  425,   59,  424,  610,   73,
125090         - /*  1160 */    74,  549,  402,  404,  424,  373,   75,  426,  425,  604,
125091         - /*  1170 */   138,  610,  614,   11,  392,   76,  419,  181,    3,  614,
125092         - /*  1180 */    32,  271,  369,  331,  331,  493,  614,   31,  149,  608,
125093         - /*  1190 */   608,  608,  607,   15,  422,  365,  614,    8,  137,  489,
125094         - /*  1200 */   136,  190,  608,  608,  608,  607,   15,  485,  176,  135,
125095         - /*  1210 */     7,  252,  477,  408,  174,  133,  175,  474,   57,   56,
125096         - /*  1220 */   132,  130,  119,   76,  419,  588,    3,  468,  245,  464,
125097         - /*  1230 */   171,  331,  331,  125,  123,  456,  447,  122,  446,  104,
125098         - /*  1240 */   336,  231,  422,  166,  154,   73,   74,  332,  116,  431,
125099         - /*  1250 */   121,  309,   75,  426,  425,  222,  106,  610,  308,  637,
125100         - /*  1260 */   204,  408,  629,  627,  628,    6,  200,  428,  427,  290,
125101         - /*  1270 */   203,  622,  201,  588,   62,   63,  289,   66,  419,  399,
125102         - /*  1280 */     3,  401,  288,   92,  143,  331,  331,  287,  608,  608,
125103         - /*  1290 */   608,  607,   15,   73,   74,  227,  422,  325,   69,  416,
125104         - /*  1300 */    75,  426,  425,  612,  412,  610,  192,   61,  569,  209,
125105         - /*  1310 */   396,  226,  278,  225,  383,  408,  527,  558,  276,  533,
125106         - /*  1320 */   552,  528,  321,  523,  370,  508,  180,  588,  494,  179,
125107         - /*  1330 */   366,  117,  253,  269,  522,  503,  608,  608,  608,  607,
125108         - /*  1340 */    15,  551,  502,   58,  274,  524,  178,   73,   74,  304,
125109         - /*  1350 */   501,  368,  303,  206,   75,  426,  425,  491,  360,  610,
125110         - /*  1360 */   213,  177,  483,  131,  345,  298,  297,  296,  202,  294,
125111         - /*  1370 */   480,  490,  466,  134,  172,  129,  444,  346,  470,  128,
125112         - /*  1380 */   314,  459,  103,  127,  126,  148,  124,  167,  443,  235,
125113         - /*  1390 */   608,  608,  608,  607,   15,  442,  439,  623,  234,  299,
125114         - /*  1400 */   145,  583,  291,  377,  581,  160,  119,  156,  270,  636,
125115         - /*  1410 */   971,  169,  279,  626,  520,  625,  473,  624,  170,  621,
125116         - /*  1420 */   618,  119,  168,   55,  409,  423,  537,  609,  286,  285,
125117         - /*  1430 */   405,  570,  560,  556,    5,   52,  458,  554,  147,  267,
125118         - /*  1440 */   519,  504,  518,  406,  262,  239,  260,  512,  343,  511,
125119         - /*  1450 */   258,  353,  565,  256,  224,  251,  359,  277,  275,  476,
125120         - /*  1460 */   475,  246,  352,  244,  467,  455,  236,  233,  232,  307,
125121         - /*  1470 */   441,  281,  205,  163,  397,  280,  535,  505,  330,  617,
125122         - /*  1480 */   971,  971,  971,  971,  367,  971,  971,  971,  971,  971,
125123         - /*  1490 */   971,  971,  971,  971,  971,  971,  338,
       125407  + /*     0 */   311, 1306,  145,  651,    2,  192,  652,  338,  780,   92,
       125408  + /*    10 */    92,   92,   92,   85,   90,   90,   90,   90,   89,   89,
       125409  + /*    20 */    88,   88,   88,   87,  335,   88,   88,   88,   87,  335,
       125410  + /*    30 */   327,  856,  856,   92,   92,   92,   92,  776,   90,   90,
       125411  + /*    40 */    90,   90,   89,   89,   88,   88,   88,   87,  335,   86,
       125412  + /*    50 */    83,  166,   93,   94,   84,  868,  871,  860,  860,   91,
       125413  + /*    60 */    91,   92,   92,   92,   92,  335,   90,   90,   90,   90,
       125414  + /*    70 */    89,   89,   88,   88,   88,   87,  335,  311,  780,   90,
       125415  + /*    80 */    90,   90,   90,   89,   89,   88,   88,   88,   87,  335,
       125416  + /*    90 */   123,  808,  689,  689,  689,  689,  112,  230,  430,  257,
       125417  + /*   100 */   809,  698,  430,   86,   83,  166,  324,   55,  856,  856,
       125418  + /*   110 */   201,  158,  276,  387,  271,  386,  188,  689,  689,  828,
       125419  + /*   120 */   833,   49,  944,  269,  833,   49,  123,   87,  335,   93,
       125420  + /*   130 */    94,   84,  868,  871,  860,  860,   91,   91,   92,   92,
       125421  + /*   140 */    92,   92,  342,   90,   90,   90,   90,   89,   89,   88,
       125422  + /*   150 */    88,   88,   87,  335,  311,  328,  333,  332,  701,  408,
       125423  + /*   160 */   394,   69,  690,  691,  690,  691,  715,  910,  251,  354,
       125424  + /*   170 */   250,  698,  704,  430,  908,  430,  909,   89,   89,   88,
       125425  + /*   180 */    88,   88,   87,  335,  391,  856,  856,  690,  691,  183,
       125426  + /*   190 */    95,  340,  384,  381,  380,  833,   31,  833,   49,  912,
       125427  + /*   200 */   912,  333,  332,  379,  123,  311,   93,   94,   84,  868,
       125428  + /*   210 */   871,  860,  860,   91,   91,   92,   92,   92,   92,  114,
       125429  + /*   220 */    90,   90,   90,   90,   89,   89,   88,   88,   88,   87,
       125430  + /*   230 */   335,  430,  408,  399,  435,  657,  856,  856,  346,   57,
       125431  + /*   240 */   232,  828,  109,   20,  912,  912,  231,  393,  937,  760,
       125432  + /*   250 */    97,  751,  752,  833,   49,  708,  708,   93,   94,   84,
       125433  + /*   260 */   868,  871,  860,  860,   91,   91,   92,   92,   92,   92,
       125434  + /*   270 */   707,   90,   90,   90,   90,   89,   89,   88,   88,   88,
       125435  + /*   280 */    87,  335,  311,  114,   22,  706,  688,   58,  408,  390,
       125436  + /*   290 */   251,  349,  240,  749,  752,  689,  689,  847,  685,  115,
       125437  + /*   300 */    21,  231,  393,  689,  689,  697,  183,  355,  430,  384,
       125438  + /*   310 */   381,  380,  192,  856,  856,  780,  123,  160,  159,  223,
       125439  + /*   320 */   379,  738,   25,  315,  362,  841,  143,  689,  689,  835,
       125440  + /*   330 */   833,   48,  339,  937,   93,   94,   84,  868,  871,  860,
       125441  + /*   340 */   860,   91,   91,   92,   92,   92,   92,  914,   90,   90,
       125442  + /*   350 */    90,   90,   89,   89,   88,   88,   88,   87,  335,  311,
       125443  + /*   360 */   840,  840,  840,  266,  430,  690,  691,  778,  114, 1300,
       125444  + /*   370 */  1300,  430,    1,  690,  691,  697,  688,  689,  689,  689,
       125445  + /*   380 */   689,  689,  689,  287,  298,  780,  833,   10,  686,  115,
       125446  + /*   390 */   856,  856,  355,  833,   10,  828,  366,  690,  691,  363,
       125447  + /*   400 */   321,   76,  123,   74,   23,  737,  807,  323,  356,  353,
       125448  + /*   410 */   847,   93,   94,   84,  868,  871,  860,  860,   91,   91,
       125449  + /*   420 */    92,   92,   92,   92,  940,   90,   90,   90,   90,   89,
       125450  + /*   430 */    89,   88,   88,   88,   87,  335,  311,  806,  841,  429,
       125451  + /*   440 */   713,  941,  835,  430,  251,  354,  250,  690,  691,  690,
       125452  + /*   450 */   691,  690,  691,   86,   83,  166,   24,  942,  151,  753,
       125453  + /*   460 */   285,  907,  403,  907,  164,  833,   10,  856,  856,  965,
       125454  + /*   470 */   306,  754,  679,  840,  840,  840,  795,  216,  794,  222,
       125455  + /*   480 */   906,  344,  906,  904,   86,   83,  166,  286,   93,   94,
       125456  + /*   490 */    84,  868,  871,  860,  860,   91,   91,   92,   92,   92,
       125457  + /*   500 */    92,  430,   90,   90,   90,   90,   89,   89,   88,   88,
       125458  + /*   510 */    88,   87,  335,  311,  430,  724,  352,  705,  427,  699,
       125459  + /*   520 */   700,  376,  210,  833,   49,  793,  397,  857,  857,  940,
       125460  + /*   530 */   213,  762,  727,  334,  699,  700,  833,   10,   86,   83,
       125461  + /*   540 */   166,  345,  396,  902,  856,  856,  941,  385,  833,    9,
       125462  + /*   550 */   406,  869,  872,  187,  890,  728,  347,  398,  404,  977,
       125463  + /*   560 */   652,  338,  942,  954,  413,   93,   94,   84,  868,  871,
       125464  + /*   570 */   860,  860,   91,   91,   92,   92,   92,   92,  861,   90,
       125465  + /*   580 */    90,   90,   90,   89,   89,   88,   88,   88,   87,  335,
       125466  + /*   590 */   311, 1219,  114,  430,  834,  430,    5,  165,  192,  688,
       125467  + /*   600 */   832,  780,  430,  723,  430,  234,  325,  189,  163,  316,
       125468  + /*   610 */   356,  955,  115,  235,  269,  833,   35,  833,   36,  747,
       125469  + /*   620 */   720,  856,  856,  793,  833,   12,  833,   27,  745,  174,
       125470  + /*   630 */   968, 1290,  968, 1291, 1290,  310, 1291,  693,  317,  245,
       125471  + /*   640 */   264,  311,   93,   94,   84,  868,  871,  860,  860,   91,
       125472  + /*   650 */    91,   92,   92,   92,   92,  832,   90,   90,   90,   90,
       125473  + /*   660 */    89,   89,   88,   88,   88,   87,  335,  430,  320,  213,
       125474  + /*   670 */   762,  780,  856,  856,  920,  920,  369,  257,  966,  220,
       125475  + /*   680 */   966,  396,  663,  664,  665,  242,  259,  244,  262,  833,
       125476  + /*   690 */    37,  650,    2,   93,   94,   84,  868,  871,  860,  860,
       125477  + /*   700 */    91,   91,   92,   92,   92,   92,  430,   90,   90,   90,
       125478  + /*   710 */    90,   89,   89,   88,   88,   88,   87,  335,  311,  430,
       125479  + /*   720 */   239,  430,  917,  368,  430,  238,  916,  793,  833,   38,
       125480  + /*   730 */   430,  825,  430,   66,  430,  392,  430,  766,  766,  430,
       125481  + /*   740 */   367,  833,   39,  833,   28,  430,  833,   29,   68,  856,
       125482  + /*   750 */   856,  900,  833,   40,  833,   41,  833,   42,  833,   11,
       125483  + /*   760 */    72,  833,   43,  243,  305,  970,  114,  833,   99,  961,
       125484  + /*   770 */    93,   94,   84,  868,  871,  860,  860,   91,   91,   92,
       125485  + /*   780 */    92,   92,   92,  430,   90,   90,   90,   90,   89,   89,
       125486  + /*   790 */    88,   88,   88,   87,  335,  311,  430,  361,  430,  165,
       125487  + /*   800 */   147,  430,  186,  185,  184,  833,   44,  430,  289,  430,
       125488  + /*   810 */   246,  430,  971,  430,  212,  163,  430,  357,  833,   45,
       125489  + /*   820 */   833,   32,  932,  833,   46,  793,  856,  856,  718,  833,
       125490  + /*   830 */    47,  833,   33,  833,  117,  833,  118,   75,  833,  119,
       125491  + /*   840 */   288,  305,  967,  214,  935,  322,  311,   93,   94,   84,
       125492  + /*   850 */   868,  871,  860,  860,   91,   91,   92,   92,   92,   92,
       125493  + /*   860 */   430,   90,   90,   90,   90,   89,   89,   88,   88,   88,
       125494  + /*   870 */    87,  335,  430,  832,  426,  317,  288,  856,  856,  114,
       125495  + /*   880 */   763,  257,  833,   53,  930,  219,  364,  257,  257,  971,
       125496  + /*   890 */   361,  396,  257,  257,  833,   34,  257,  311,   93,   94,
       125497  + /*   900 */    84,  868,  871,  860,  860,   91,   91,   92,   92,   92,
       125498  + /*   910 */    92,  430,   90,   90,   90,   90,   89,   89,   88,   88,
       125499  + /*   920 */    88,   87,  335,  430,  217,  318,  124,  253,  856,  856,
       125500  + /*   930 */   218,  943,  257,  833,  100,  898,  759,  774,  361,  755,
       125501  + /*   940 */   423,  329,  758, 1017,  289,  833,   50,  682,  311,   93,
       125502  + /*   950 */    82,   84,  868,  871,  860,  860,   91,   91,   92,   92,
       125503  + /*   960 */    92,   92,  430,   90,   90,   90,   90,   89,   89,   88,
       125504  + /*   970 */    88,   88,   87,  335,  430,  256,  419,  114,  249,  856,
       125505  + /*   980 */   856,  331,  114,  400,  833,  101,  359,  187, 1064,  726,
       125506  + /*   990 */   725,  739,  401,  416,  420,  360,  833,  102,  424,  311,
       125507  + /*  1000 */   258,   94,   84,  868,  871,  860,  860,   91,   91,   92,
       125508  + /*  1010 */    92,   92,   92,  430,   90,   90,   90,   90,   89,   89,
       125509  + /*  1020 */    88,   88,   88,   87,  335,  430,  221,  261,  114,  114,
       125510  + /*  1030 */   856,  856,  808,  114,  156,  833,   98,  772,  733,  734,
       125511  + /*  1040 */   275,  809,  771,  316,  263,  265,  960,  833,  116,  307,
       125512  + /*  1050 */   741,  274,  722,   84,  868,  871,  860,  860,   91,   91,
       125513  + /*  1060 */    92,   92,   92,   92,  430,   90,   90,   90,   90,   89,
       125514  + /*  1070 */    89,   88,   88,   88,   87,  335,   80,  425,  830,    3,
       125515  + /*  1080 */  1214,  191,  430,  721,  336,  336,  833,  113,  252,   80,
       125516  + /*  1090 */   425,   68,    3,  913,  913,  428,  270,  336,  336,  430,
       125517  + /*  1100 */   377,  784,  430,  197,  833,  106,  430,  716,  428,  430,
       125518  + /*  1110 */   267,  430,  897,   68,  414,  430,  769,  409,  430,   71,
       125519  + /*  1120 */   430,  833,  105,  123,  833,  103,  847,  414,  833,   49,
       125520  + /*  1130 */   843,  833,  104,  833,   52,  800,  123,  833,   54,  847,
       125521  + /*  1140 */   833,   51,  833,   26,  831,  802,   77,   78,  191,  389,
       125522  + /*  1150 */   430,  372,  114,   79,  432,  431,  911,  911,  835,   77,
       125523  + /*  1160 */    78,  779,  893,  408,  410,  197,   79,  432,  431,  791,
       125524  + /*  1170 */   226,  835,  833,   30,  772,   80,  425,  716,    3,  771,
       125525  + /*  1180 */   411,  412,  897,  336,  336,  290,  291,  839,  703,  840,
       125526  + /*  1190 */   840,  840,  842,   19,  428,  695,  684,  672,  111,  671,
       125527  + /*  1200 */   843,  673,  840,  840,  840,  842,   19,  207,  661,  278,
       125528  + /*  1210 */   148,  304,  280,  414,  282,    6,  822,  348,  248,  241,
       125529  + /*  1220 */   358,  934,  720,   80,  425,  847,    3,  161,  382,  273,
       125530  + /*  1230 */   284,  336,  336,  415,  296,  958,  895,  894,  157,  674,
       125531  + /*  1240 */   107,  194,  428,  948,  135,   77,   78,  777,  953,  951,
       125532  + /*  1250 */    56,  319,   79,  432,  431,  121,   66,  835,   59,  128,
       125533  + /*  1260 */   146,  414,  350,  130,  351,  819,  131,  132,  133,  375,
       125534  + /*  1270 */   173,  149,  138,  847,  936,  365,  178,   70,  425,  827,
       125535  + /*  1280 */     3,  889,   62,  371,  915,  336,  336,  792,  840,  840,
       125536  + /*  1290 */   840,  842,   19,   77,   78,  208,  428,  144,  179,  373,
       125537  + /*  1300 */    79,  432,  431,  255,  180,  835,  260,  675,  181,  308,
       125538  + /*  1310 */   388,  744,  326,  743,  742,  414,  731,  718,  712,  402,
       125539  + /*  1320 */   309,  711,  788,   65,  277,  272,  789,  847,  730,  710,
       125540  + /*  1330 */   709,  279,  193,  787,  281,  876,  840,  840,  840,  842,
       125541  + /*  1340 */    19,  786,  283,   73,  418,  330,  422,   77,   78,  227,
       125542  + /*  1350 */    96,  407,   67,  405,   79,  432,  431,  292,  228,  835,
       125543  + /*  1360 */   215,  202,  229,  293,  767,  303,  302,  301,  204,  299,
       125544  + /*  1370 */   294,  295,  676,    7,  681,  433,  669,  206,  110,  224,
       125545  + /*  1380 */   203,  205,  434,  667,  666,  658,  120,  168,  656,  237,
       125546  + /*  1390 */   840,  840,  840,  842,   19,  337,  155,  233,  236,  341,
       125547  + /*  1400 */   167,  905,  108,  313,  903,  826,  314,  125,  126,  127,
       125548  + /*  1410 */   129,  170,  247,  756,  172,  928,  134,  136,  171,   60,
       125549  + /*  1420 */    61,  123,  169,  137,  175,  933,  176,  927,    8,   13,
       125550  + /*  1430 */   177,  254,  191,  918,  139,  370,  924,  140,  678,  150,
       125551  + /*  1440 */   374,  274,  182,  378,  141,  122,   63,   14,  383,  729,
       125552  + /*  1450 */   268,   15,   64,  225,  846,  845,  874,   16,  765,  770,
       125553  + /*  1460 */     4,  162,  209,  395,  211,  142,  878,  796,  801,  312,
       125554  + /*  1470 */   190,   71,   68,  875,  873,  939,  199,  938,   17,  195,
       125555  + /*  1480 */    18,  196,  417,  975,  152,  653,  976,  198,  153,  421,
       125556  + /*  1490 */   877,  154,  200,  844,  696,   81,  343,  297, 1019, 1018,
       125557  + /*  1500 */   300,
125124 125558   };
125125 125559   static const YYCODETYPE yy_lookahead[] = {
125126         - /*     0 */    19,   22,   22,   23,    1,   24,   26,   15,   27,   80,
       125560  + /*     0 */    19,  144,  145,  146,  147,   24,    1,    2,   27,   80,
125127 125561    /*    10 */    81,   82,   83,   84,   85,   86,   87,   88,   89,   90,
125128         - /*    20 */    91,   92,   93,   94,   95,  108,  109,  110,   27,   28,
125129         - /*    30 */    23,   50,   51,   80,   81,   82,   83,  122,   85,   86,
125130         - /*    40 */    87,   88,   89,   90,   91,   92,   93,   94,   95,   22,
125131         - /*    50 */    70,   23,   71,   72,   73,   74,   75,   76,   77,   78,
125132         - /*    60 */    79,   80,   81,   82,   83,  122,   85,   86,   87,   88,
125133         - /*    70 */    89,   90,   91,   92,   93,   94,   95,   19,   97,   91,
125134         - /*    80 */    92,   93,   94,   95,   26,   85,   86,   87,   88,   89,
125135         - /*    90 */    90,   91,   92,   93,   94,   95,   27,   28,   97,   98,
125136         - /*   100 */    99,  122,  211,  102,  103,  104,   79,   19,   50,   51,
125137         - /*   110 */    19,  122,   59,   55,  113,  224,  225,  226,   89,   90,
125138         - /*   120 */    91,   92,   93,   94,   95,   23,   27,   28,   26,   71,
       125562  + /*    20 */    91,   92,   93,   94,   95,   91,   92,   93,   94,   95,
       125563  + /*    30 */    19,   50,   51,   80,   81,   82,   83,  212,   85,   86,
       125564  + /*    40 */    87,   88,   89,   90,   91,   92,   93,   94,   95,  224,
       125565  + /*    50 */   225,  226,   71,   72,   73,   74,   75,   76,   77,   78,
       125566  + /*    60 */    79,   80,   81,   82,   83,   95,   85,   86,   87,   88,
       125567  + /*    70 */    89,   90,   91,   92,   93,   94,   95,   19,   97,   85,
       125568  + /*    80 */    86,   87,   88,   89,   90,   91,   92,   93,   94,   95,
       125569  + /*    90 */    66,   33,   27,   28,   27,   28,   22,  201,  152,  152,
       125570  + /*   100 */    42,   27,  152,  224,  225,  226,   95,  211,   50,   51,
       125571  + /*   110 */    99,  100,  101,  102,  103,  104,  105,   27,   28,   59,
       125572  + /*   120 */   174,  175,  243,  112,  174,  175,   66,   94,   95,   71,
125139 125573    /*   130 */    72,   73,   74,   75,   76,   77,   78,   79,   80,   81,
125140         - /*   140 */    82,   83,   51,   85,   86,   87,   88,   89,   90,   91,
125141         - /*   150 */    92,   93,   94,   95,   19,  132,  133,   58,   89,   90,
125142         - /*   160 */    21,  108,  109,  110,   27,   28,   97,   98,   33,  100,
125143         - /*   170 */     7,    8,  119,  120,   22,   19,  107,   42,  109,   27,
125144         - /*   180 */    28,   27,   28,   95,   28,   50,   51,   99,  100,  101,
125145         - /*   190 */   102,  103,  104,  105,   27,   28,   97,   98,  107,  152,
125146         - /*   200 */   112,  132,  133,  112,   65,   69,   71,   72,   73,   74,
125147         - /*   210 */    75,   76,   77,   78,   79,   80,   81,   82,   83,   11,
       125574  + /*   140 */    82,   83,  195,   85,   86,   87,   88,   89,   90,   91,
       125575  + /*   150 */    92,   93,   94,   95,   19,  209,   89,   90,  173,  209,
       125576  + /*   160 */   210,   26,   97,   98,   97,   98,  181,  100,  108,  109,
       125577  + /*   170 */   110,   97,  174,  152,  107,  152,  109,   89,   90,   91,
       125578  + /*   180 */    92,   93,   94,   95,  163,   50,   51,   97,   98,   99,
       125579  + /*   190 */    55,  244,  102,  103,  104,  174,  175,  174,  175,  132,
       125580  + /*   200 */   133,   89,   90,  113,   66,   19,   71,   72,   73,   74,
       125581  + /*   210 */    75,   76,   77,   78,   79,   80,   81,   82,   83,  198,
125148 125582    /*   220 */    85,   86,   87,   88,   89,   90,   91,   92,   93,   94,
125149         - /*   230 */    95,   19,  101,   97,   97,   98,   24,  101,  122,  157,
125150         - /*   240 */    12,   99,  103,  112,  102,  103,  104,  152,   22,   97,
125151         - /*   250 */    98,   97,   98,   27,   28,  113,   27,   29,   91,  164,
125152         - /*   260 */   165,  124,   50,   51,   97,   98,  219,   59,  132,  133,
125153         - /*   270 */   134,   22,   23,   45,   66,   47,  212,  213,  124,  140,
125154         - /*   280 */   132,  133,   19,   71,   72,   73,   74,   75,   76,   77,
125155         - /*   290 */    78,   79,   80,   81,   82,   83,  152,   85,   86,   87,
125156         - /*   300 */    88,   89,   90,   91,   92,   93,   94,   95,  164,  165,
125157         - /*   310 */    27,   28,  230,   50,   51,  233,  108,  109,  110,   70,
125158         - /*   320 */    16,   59,   23,   97,   98,   26,   97,   22,   66,  185,
125159         - /*   330 */    12,  187,   27,   28,   71,   72,   73,   74,   75,   76,
125160         - /*   340 */    77,   78,   79,   80,   81,   82,   83,   29,   85,   86,
       125583  + /*   230 */    95,  152,  209,  210,  148,  149,   50,   51,  100,   53,
       125584  + /*   240 */   154,   59,  156,   22,  132,  133,  119,  120,  163,  163,
       125585  + /*   250 */    22,  192,  193,  174,  175,   27,   28,   71,   72,   73,
       125586  + /*   260 */    74,   75,   76,   77,   78,   79,   80,   81,   82,   83,
       125587  + /*   270 */   174,   85,   86,   87,   88,   89,   90,   91,   92,   93,
       125588  + /*   280 */    94,   95,   19,  198,  198,  174,  152,   24,  209,  210,
       125589  + /*   290 */   108,  109,  110,  192,  193,   27,   28,   69,  164,  165,
       125590  + /*   300 */    79,  119,  120,   27,   28,   27,   99,  222,  152,  102,
       125591  + /*   310 */   103,  104,   24,   50,   51,   27,   66,   89,   90,  185,
       125592  + /*   320 */   113,  187,   22,  157,  239,   97,   58,   27,   28,  101,
       125593  + /*   330 */   174,  175,  246,  163,   71,   72,   73,   74,   75,   76,
       125594  + /*   340 */    77,   78,   79,   80,   81,   82,   83,   11,   85,   86,
125161 125595    /*   350 */    87,   88,   89,   90,   91,   92,   93,   94,   95,   19,
125162         - /*   360 */    22,  148,  149,   45,   23,   47,   62,  154,   64,  156,
125163         - /*   370 */   108,  109,  110,   37,   69,   23,  163,   59,   26,   26,
125164         - /*   380 */    97,   98,  144,  145,  146,  147,  152,  200,   52,   23,
125165         - /*   390 */    50,   51,   26,   22,   89,   90,   60,  210,    7,    8,
125166         - /*   400 */     9,  138,   97,   22,   23,   26,  101,   26,  174,  175,
125167         - /*   410 */   197,   71,   72,   73,   74,   75,   76,   77,   78,   79,
125168         - /*   420 */    80,   81,   82,   83,   16,   85,   86,   87,   88,   89,
125169         - /*   430 */    90,   91,   92,   93,   94,   95,   19,  132,  133,  134,
125170         - /*   440 */    23,  152,  208,  209,  140,  152,  152,  111,  195,  196,
125171         - /*   450 */    98,   70,  163,  160,  152,   23,   22,  164,  165,  246,
125172         - /*   460 */   207,   27,  152,  174,  175,  171,  172,   50,   51,  137,
125173         - /*   470 */    62,  139,   64,  171,  172,  222,  124,   27,  138,   24,
125174         - /*   480 */   163,   89,   90,  130,  174,  175,  197,  163,   71,   72,
       125596  + /*   360 */   132,  133,  134,   23,  152,   97,   98,   91,  198,  119,
       125597  + /*   370 */   120,  152,   22,   97,   98,   97,  152,   27,   28,   27,
       125598  + /*   380 */    28,   27,   28,  227,  160,   97,  174,  175,  164,  165,
       125599  + /*   390 */    50,   51,  222,  174,  175,   59,  230,   97,   98,  233,
       125600  + /*   400 */   188,  137,   66,  139,  234,  187,  177,  188,  152,  239,
       125601  + /*   410 */    69,   71,   72,   73,   74,   75,   76,   77,   78,   79,
       125602  + /*   420 */    80,   81,   82,   83,   12,   85,   86,   87,   88,   89,
       125603  + /*   430 */    90,   91,   92,   93,   94,   95,   19,  177,   97,  152,
       125604  + /*   440 */    23,   29,  101,  152,  108,  109,  110,   97,   98,   97,
       125605  + /*   450 */    98,   97,   98,  224,  225,  226,   22,   45,   24,   47,
       125606  + /*   460 */   152,  152,  152,  152,  152,  174,  175,   50,   51,  249,
       125607  + /*   470 */   250,   59,   21,  132,  133,  134,  124,  221,  124,  188,
       125608  + /*   480 */   171,  172,  171,  172,  224,  225,  226,  152,   71,   72,
125175 125609    /*   490 */    73,   74,   75,   76,   77,   78,   79,   80,   81,   82,
125176         - /*   500 */    83,   22,   85,   86,   87,   88,   89,   90,   91,   92,
125177         - /*   510 */    93,   94,   95,   19,  197,  181,  182,   23,  208,  209,
125178         - /*   520 */   152,  197,   26,  189,  132,  133,  232,  224,  225,  226,
125179         - /*   530 */   152,   97,   91,   26,  232,  116,  212,  213,  152,  222,
125180         - /*   540 */   121,  152,  174,  175,   50,   51,  243,   97,   22,   23,
125181         - /*   550 */    22,  234,  174,  175,  177,   23,  239,  116,  163,  177,
125182         - /*   560 */   174,  175,  121,  174,  175,   71,   72,   73,   74,   75,
125183         - /*   570 */    76,   77,   78,   79,   80,   81,   82,   83,   24,   85,
       125610  + /*   500 */    83,  152,   85,   86,   87,   88,   89,   90,   91,   92,
       125611  + /*   510 */    93,   94,   95,   19,  152,  183,   65,   23,  170,  171,
       125612  + /*   520 */   172,   19,   23,  174,  175,   26,  152,   50,   51,   12,
       125613  + /*   530 */   196,  197,   37,  170,  171,  172,  174,  175,  224,  225,
       125614  + /*   540 */   226,  232,  208,  232,   50,   51,   29,   52,  174,  175,
       125615  + /*   550 */   188,   74,   75,   51,  103,   60,  222,  163,  209,    0,
       125616  + /*   560 */     1,    2,   45,  152,   47,   71,   72,   73,   74,   75,
       125617  + /*   570 */    76,   77,   78,   79,   80,   81,   82,   83,  101,   85,
125184 125618    /*   580 */    86,   87,   88,   89,   90,   91,   92,   93,   94,   95,
125185         - /*   590 */    19,   23,  197,   11,   23,  227,   70,  208,  220,  152,
125186         - /*   600 */    31,  224,  225,  226,   35,   98,  224,  225,  226,  108,
125187         - /*   610 */   109,  110,  115,  152,  117,  118,   27,  222,   49,  123,
125188         - /*   620 */    24,   50,   51,   27,    0,    1,    2,  224,  225,  226,
125189         - /*   630 */   166,  124,  168,  169,  239,  174,  175,  170,  171,  172,
125190         - /*   640 */    22,  194,   71,   72,   73,   74,   75,   76,   77,   78,
       125619  + /*   590 */    19,  140,  198,  152,   23,  152,   22,   98,   24,  152,
       125620  + /*   600 */   152,   27,  152,  183,  152,  152,  111,  213,  214,  107,
       125621  + /*   610 */   152,  164,  165,  152,  112,  174,  175,  174,  175,  181,
       125622  + /*   620 */   182,   50,   51,  124,  174,  175,  174,  175,  190,   26,
       125623  + /*   630 */    22,   23,   22,   23,   26,  166,   26,  168,  169,   16,
       125624  + /*   640 */    16,   19,   71,   72,   73,   74,   75,   76,   77,   78,
125191 125625    /*   650 */    79,   80,   81,   82,   83,  152,   85,   86,   87,   88,
125192         - /*   660 */    89,   90,   91,   92,   93,   94,   95,   19,   22,  208,
125193         - /*   670 */    24,   23,  195,  196,  170,  171,  172,  174,  175,  152,
125194         - /*   680 */    26,  152,  152,  152,  207,  152,   97,  152,   23,  152,
125195         - /*   690 */    51,  244,  152,   97,  152,  247,  248,   23,   50,   51,
125196         - /*   700 */    26,  174,  175,  174,  175,  174,  175,  174,  175,  174,
125197         - /*   710 */   175,  174,  175,   23,  174,  175,  174,  175,  188,   71,
125198         - /*   720 */    72,   73,   74,   75,   76,   77,   78,   79,   80,   81,
125199         - /*   730 */    82,   83,  152,   85,   86,   87,   88,   89,   90,   91,
125200         - /*   740 */    92,   93,   94,   95,   19,  152,  107,  152,   33,   24,
125201         - /*   750 */   152,  100,  101,   27,  174,  175,  152,   42,  152,   23,
125202         - /*   760 */   152,   26,  152,   23,  152,   26,  152,  174,  175,  174,
125203         - /*   770 */   175,  152,  174,  175,   23,   50,   51,   26,  174,  175,
125204         - /*   780 */   174,  175,  174,  175,  174,  175,  174,  175,  174,  175,
125205         - /*   790 */   163,  119,  120,  174,  175,   19,   71,   72,   73,   74,
125206         - /*   800 */    75,   76,   77,   78,   79,   80,   81,   82,   83,  152,
125207         - /*   810 */    85,   86,   87,   88,   89,   90,   91,   92,   93,   94,
125208         - /*   820 */    95,   66,  152,   97,  197,   23,   50,   51,   26,   53,
125209         - /*   830 */    23,  174,  175,   26,   23,   23,   23,   26,   26,   26,
125210         - /*   840 */    36,  106,  146,  147,  174,  175,   19,   71,   72,   73,
       125626  + /*   660 */    89,   90,   91,   92,   93,   94,   95,  152,  220,  196,
       125627  + /*   670 */   197,   97,   50,   51,  108,  109,  110,  152,   70,  221,
       125628  + /*   680 */    70,  208,    7,    8,    9,   62,   62,   64,   64,  174,
       125629  + /*   690 */   175,  146,  147,   71,   72,   73,   74,   75,   76,   77,
       125630  + /*   700 */    78,   79,   80,   81,   82,   83,  152,   85,   86,   87,
       125631  + /*   710 */    88,   89,   90,   91,   92,   93,   94,   95,   19,  152,
       125632  + /*   720 */   195,  152,   31,  220,  152,  152,   35,   26,  174,  175,
       125633  + /*   730 */   152,  163,  152,  130,  152,  115,  152,  117,  118,  152,
       125634  + /*   740 */    49,  174,  175,  174,  175,  152,  174,  175,   26,   50,
       125635  + /*   750 */    51,  152,  174,  175,  174,  175,  174,  175,  174,  175,
       125636  + /*   760 */   138,  174,  175,  140,   22,   23,  198,  174,  175,  152,
       125637  + /*   770 */    71,   72,   73,   74,   75,   76,   77,   78,   79,   80,
       125638  + /*   780 */    81,   82,   83,  152,   85,   86,   87,   88,   89,   90,
       125639  + /*   790 */    91,   92,   93,   94,   95,   19,  152,  152,  152,   98,
       125640  + /*   800 */    24,  152,  108,  109,  110,  174,  175,  152,  152,  152,
       125641  + /*   810 */   152,  152,   70,  152,  213,  214,  152,  152,  174,  175,
       125642  + /*   820 */   174,  175,  152,  174,  175,  124,   50,   51,  106,  174,
       125643  + /*   830 */   175,  174,  175,  174,  175,  174,  175,  138,  174,  175,
       125644  + /*   840 */   152,   22,   23,   22,  163,  189,   19,   71,   72,   73,
125211 125645    /*   850 */    74,   75,   76,   77,   78,   79,   80,   81,   82,   83,
125212 125646    /*   860 */   152,   85,   86,   87,   88,   89,   90,   91,   92,   93,
125213         - /*   870 */    94,   95,  152,  196,  119,  120,   19,   50,   51,  168,
125214         - /*   880 */   169,   26,  174,  175,  207,   28,  152,  249,  250,  152,
125215         - /*   890 */   163,  163,  163,  163,  174,  175,  163,   19,   71,   72,
       125647  + /*   870 */    94,   95,  152,  152,  168,  169,  152,   50,   51,  198,
       125648  + /*   880 */   197,  152,  174,  175,  152,  240,  152,  152,  152,   70,
       125649  + /*   890 */   152,  208,  152,  152,  174,  175,  152,   19,   71,   72,
125216 125650    /*   900 */    73,   74,   75,   76,   77,   78,   79,   80,   81,   82,
125217 125651    /*   910 */    83,  152,   85,   86,   87,   88,   89,   90,   91,   92,
125218         - /*   920 */    93,   94,   95,  152,  197,  197,  197,  197,   50,   51,
125219         - /*   930 */   197,  194,   36,  174,  175,  191,  192,  152,  191,  192,
125220         - /*   940 */   163,  152,   66,  124,  152,  174,  175,  152,   19,   71,
       125652  + /*   920 */    93,   94,   95,  152,  195,  247,  248,  152,   50,   51,
       125653  + /*   930 */   195,  195,  152,  174,  175,  195,  195,   26,  152,  195,
       125654  + /*   940 */   252,  220,  163,  122,  152,  174,  175,  163,   19,   71,
125221 125655    /*   950 */    72,   73,   74,   75,   76,   77,   78,   79,   80,   81,
125222 125656    /*   960 */    82,   83,  152,   85,   86,   87,   88,   89,   90,   91,
125223         - /*   970 */    92,   93,   94,   95,  197,  152,  100,  188,  152,   50,
125224         - /*   980 */    51,  152,  152,  188,  174,  175,  252,  152,   94,   95,
125225         - /*   990 */   152,  152,  152,    1,    2,  152,  152,  174,  175,   19,
       125657  + /*   970 */    92,   93,   94,   95,  152,  195,  252,  198,  240,   50,
       125658  + /*   980 */    51,  189,  198,   19,  174,  175,   19,   51,   23,  100,
       125659  + /*   990 */   101,   26,   28,  163,  163,   28,  174,  175,  163,   19,
125226 125660    /*  1000 */   152,   72,   73,   74,   75,   76,   77,   78,   79,   80,
125227 125661    /*  1010 */    81,   82,   83,  152,   85,   86,   87,   88,   89,   90,
125228         - /*  1020 */    91,   92,   93,   94,   95,  152,  188,  188,   22,  194,
125229         - /*  1030 */    50,   51,  240,  173,  194,  174,  175,  252,  194,  152,
125230         - /*  1040 */    36,  181,   28,  152,   23,  219,  122,  174,  175,  219,
125231         - /*  1050 */   221,  152,  152,   73,   74,   75,   76,   77,   78,   79,
       125662  + /*  1020 */    91,   92,   93,   94,   95,  152,  240,  152,  198,  198,
       125663  + /*  1030 */    50,   51,   33,  198,  123,  174,  175,  116,    7,    8,
       125664  + /*  1040 */   101,   42,  121,  107,  152,  152,   23,  174,  175,   26,
       125665  + /*  1050 */   152,  112,  183,   73,   74,   75,   76,   77,   78,   79,
125232 125666    /*  1060 */    80,   81,   82,   83,  152,   85,   86,   87,   88,   89,
125233         - /*  1070 */    90,   91,   92,   93,   94,   95,   19,   20,  152,   22,
125234         - /*  1080 */    23,  194,  152,  240,   27,   28,  174,  175,  240,   19,
125235         - /*  1090 */    20,   26,   22,  194,  194,   38,   22,   27,   28,  152,
125236         - /*  1100 */    23,   22,  152,  116,  174,  175,  152,   23,   38,  152,
125237         - /*  1110 */    23,  152,  221,  152,   57,  152,   23,  163,   50,   51,
125238         - /*  1120 */   194,  174,  175,   66,  174,  175,   69,   57,  174,  175,
125239         - /*  1130 */    40,  174,  175,  174,  175,  174,  175,  174,  175,   69,
125240         - /*  1140 */    22,   53,   74,   75,   30,   53,   89,   90,   22,   22,
125241         - /*  1150 */   152,  197,   23,   96,   97,   98,   22,  152,  101,   89,
125242         - /*  1160 */    90,   91,  208,  209,  152,   53,   96,   97,   98,  101,
125243         - /*  1170 */    22,  101,  174,  175,  152,   19,   20,  105,   22,  174,
125244         - /*  1180 */   175,  112,   19,   27,   28,   20,  174,  175,   24,  132,
125245         - /*  1190 */   133,  134,  135,  136,   38,   44,  174,  175,  107,   61,
125246         - /*  1200 */    54,   26,  132,  133,  134,  135,  136,   54,  107,   22,
125247         - /*  1210 */     5,  140,    1,   57,   36,  111,  122,   28,   79,   79,
125248         - /*  1220 */   131,  123,   66,   19,   20,   69,   22,    1,   16,   20,
125249         - /*  1230 */   125,   27,   28,  123,  111,  120,   23,  131,   23,   16,
125250         - /*  1240 */    68,  142,   38,   15,   22,   89,   90,    3,  167,    4,
125251         - /*  1250 */   248,  251,   96,   97,   98,  180,  180,  101,  251,  151,
125252         - /*  1260 */     6,   57,  151,   13,  151,   26,   25,  151,  161,  202,
125253         - /*  1270 */   153,  162,  153,   69,  130,  128,  203,   19,   20,  127,
125254         - /*  1280 */    22,  126,  204,  129,   22,   27,   28,  205,  132,  133,
125255         - /*  1290 */   134,  135,  136,   89,   90,  231,   38,   95,  137,  179,
125256         - /*  1300 */    96,   97,   98,  206,  179,  101,  122,  107,  159,  159,
125257         - /*  1310 */   125,  231,  216,  228,  107,   57,  184,  217,  216,  176,
125258         - /*  1320 */   217,  176,   48,  106,   18,  184,  158,   69,  159,  158,
125259         - /*  1330 */    46,   71,  237,  176,  176,  176,  132,  133,  134,  135,
125260         - /*  1340 */   136,  217,  176,  137,  216,  178,  158,   89,   90,  179,
125261         - /*  1350 */   176,  159,  179,  159,   96,   97,   98,  159,  159,  101,
125262         - /*  1360 */     5,  158,  202,   22,   18,   10,   11,   12,   13,   14,
125263         - /*  1370 */   190,  238,   17,  190,  158,  193,   41,  159,  202,  193,
125264         - /*  1380 */   159,  202,  245,  193,  193,  223,  190,   32,  159,   34,
125265         - /*  1390 */   132,  133,  134,  135,  136,  159,   39,  155,   43,  150,
125266         - /*  1400 */   223,  177,  201,  178,  177,  186,   66,  199,  177,  152,
125267         - /*  1410 */   253,   56,  215,  152,  182,  152,  202,  152,   63,  152,
125268         - /*  1420 */   152,   66,   67,  242,  229,  152,  174,  152,  152,  152,
125269         - /*  1430 */   152,  152,  152,  152,  199,  242,  202,  152,  198,  152,
125270         - /*  1440 */   152,  152,  183,  192,  152,  215,  152,  183,  215,  183,
125271         - /*  1450 */   152,  241,  214,  152,  211,  152,  152,  211,  211,  152,
125272         - /*  1460 */   152,  241,  152,  152,  152,  152,  152,  152,  152,  114,
125273         - /*  1470 */   152,  152,  235,  152,  152,  152,  174,  187,   95,  174,
125274         - /*  1480 */   253,  253,  253,  253,  236,  253,  253,  253,  253,  253,
125275         - /*  1490 */   253,  253,  253,  253,  253,  253,  141,
125276         -};
125277         -#define YY_SHIFT_USE_DFLT (-86)
125278         -#define YY_SHIFT_COUNT (429)
125279         -#define YY_SHIFT_MIN   (-85)
125280         -#define YY_SHIFT_MAX   (1383)
       125667  + /*  1070 */    90,   91,   92,   93,   94,   95,   19,   20,   23,   22,
       125668  + /*  1080 */    23,   26,  152,  152,   27,   28,  174,  175,   23,   19,
       125669  + /*  1090 */    20,   26,   22,  132,  133,   38,  152,   27,   28,  152,
       125670  + /*  1100 */    23,  215,  152,   26,  174,  175,  152,   27,   38,  152,
       125671  + /*  1110 */    23,  152,   27,   26,   57,  152,   23,  163,  152,   26,
       125672  + /*  1120 */   152,  174,  175,   66,  174,  175,   69,   57,  174,  175,
       125673  + /*  1130 */    27,  174,  175,  174,  175,  152,   66,  174,  175,   69,
       125674  + /*  1140 */   174,  175,  174,  175,  152,   23,   89,   90,   26,   91,
       125675  + /*  1150 */   152,  236,  198,   96,   97,   98,  132,  133,  101,   89,
       125676  + /*  1160 */    90,  152,   23,  209,  210,   26,   96,   97,   98,  152,
       125677  + /*  1170 */   212,  101,  174,  175,  116,   19,   20,   97,   22,  121,
       125678  + /*  1180 */   152,  193,   97,   27,   28,  152,  152,  152,  152,  132,
       125679  + /*  1190 */   133,  134,  135,  136,   38,   23,  152,  152,   26,  152,
       125680  + /*  1200 */    97,  152,  132,  133,  134,  135,  136,  235,  152,  212,
       125681  + /*  1210 */   199,  150,  212,   57,  212,  200,  203,  216,  241,  216,
       125682  + /*  1220 */   241,  203,  182,   19,   20,   69,   22,  186,  178,  177,
       125683  + /*  1230 */   216,   27,   28,  229,  202,   39,  177,  177,  200,  155,
       125684  + /*  1240 */   245,  122,   38,   41,   22,   89,   90,   91,  159,  159,
       125685  + /*  1250 */   242,  159,   96,   97,   98,   71,  130,  101,  242,  191,
       125686  + /*  1260 */   223,   57,   18,  194,  159,  203,  194,  194,  194,   18,
       125687  + /*  1270 */   158,  223,  191,   69,  203,  159,  158,   19,   20,  191,
       125688  + /*  1280 */    22,  203,  137,   46,  238,   27,   28,  159,  132,  133,
       125689  + /*  1290 */   134,  135,  136,   89,   90,  159,   38,   22,  158,  179,
       125690  + /*  1300 */    96,   97,   98,  237,  158,  101,  159,  159,  158,  179,
       125691  + /*  1310 */   107,  176,   48,  176,  176,   57,  184,  106,  176,  125,
       125692  + /*  1320 */   179,  178,  218,  107,  217,  176,  218,   69,  184,  176,
       125693  + /*  1330 */   176,  217,  159,  218,  217,  159,  132,  133,  134,  135,
       125694  + /*  1340 */   136,  218,  217,  137,  179,   95,  179,   89,   90,  228,
       125695  + /*  1350 */   129,  126,  128,  127,   96,   97,   98,  206,  231,  101,
       125696  + /*  1360 */     5,   25,  231,  205,  207,   10,   11,   12,   13,   14,
       125697  + /*  1370 */   204,  203,   17,   26,  162,  161,   13,    6,  180,  180,
       125698  + /*  1380 */   153,  153,  151,  151,  151,  151,  167,   32,    4,   34,
       125699  + /*  1390 */   132,  133,  134,  135,  136,    3,   22,  142,   43,   68,
       125700  + /*  1400 */    15,   23,   16,  251,   23,  120,  251,  248,  131,  111,
       125701  + /*  1410 */   123,   56,   16,   20,  125,    1,  123,  131,   63,   79,
       125702  + /*  1420 */    79,   66,   67,  111,   36,   28,  122,    1,    5,   22,
       125703  + /*  1430 */   107,  140,   26,   54,   54,   44,   61,  107,   20,   24,
       125704  + /*  1440 */    19,  112,  105,   53,   22,   40,   22,   22,   53,   30,
       125705  + /*  1450 */    23,   22,   22,   53,   23,   23,   23,   22,  116,   23,
       125706  + /*  1460 */    22,  122,   23,   26,   23,   22,   11,  124,   28,  114,
       125707  + /*  1470 */    36,   26,   26,   23,   23,   23,  122,   23,   36,   26,
       125708  + /*  1480 */    36,   22,   24,   23,   22,    1,   23,   26,   22,   24,
       125709  + /*  1490 */    23,   22,  122,   23,   23,   22,  141,   23,  122,  122,
       125710  + /*  1500 */    15,
       125711  +};
       125712  +#define YY_SHIFT_USE_DFLT (-72)
       125713  +#define YY_SHIFT_COUNT (435)
       125714  +#define YY_SHIFT_MIN   (-71)
       125715  +#define YY_SHIFT_MAX   (1485)
125281 125716   static const short yy_shift_ofst[] = {
125282         - /*     0 */   992, 1057, 1355, 1156, 1204, 1204,    1,  262,  -19,  135,
125283         - /*    10 */   135,  776, 1204, 1204, 1204, 1204,   69,   69,   53,  208,
125284         - /*    20 */   283,  755,   58,  725,  648,  571,  494,  417,  340,  263,
125285         - /*    30 */   212,  827,  827,  827,  827,  827,  827,  827,  827,  827,
125286         - /*    40 */   827,  827,  827,  827,  827,  827,  878,  827,  929,  980,
125287         - /*    50 */   980, 1070, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
       125717  + /*     0 */     5, 1057, 1355, 1070, 1204, 1204, 1204,   90,   60,  -19,
       125718  + /*    10 */    58,   58,  186, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
       125719  + /*    20 */    67,   67,  182,  336,   65,  250,  135,  263,  340,  417,
       125720  + /*    30 */   494,  571,  622,  699,  776,  827,  827,  827,  827,  827,
       125721  + /*    40 */   827,  827,  827,  827,  827,  827,  827,  827,  827,  827,
       125722  + /*    50 */   878,  827,  929,  980,  980, 1156, 1204, 1204, 1204, 1204,
125288 125723    /*    60 */  1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
125289 125724    /*    70 */  1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
125290         - /*    80 */  1258, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
125291         - /*    90 */  1204, 1204, 1204, 1204,  -71,  -47,  -47,  -47,  -47,  -47,
125292         - /*   100 */     0,   29,  -12,  283,  283,  139,   91,  392,  392,  894,
125293         - /*   110 */   672,  726, 1383,  -86,  -86,  -86,   88,  318,  318,   99,
125294         - /*   120 */   381,  -20,  283,  283,  283,  283,  283,  283,  283,  283,
125295         - /*   130 */   283,  283,  283,  283,  283,  283,  283,  283,  283,  283,
125296         - /*   140 */   283,  283,  283,  283,  624,  876,  726,  672, 1340, 1340,
125297         - /*   150 */  1340, 1340, 1340, 1340,  -86,  -86,  -86,  305,  136,  136,
125298         - /*   160 */   142,  167,  226,  154,  137,  152,  283,  283,  283,  283,
125299         - /*   170 */   283,  283,  283,  283,  283,  283,  283,  283,  283,  283,
125300         - /*   180 */   283,  283,  283,  336,  336,  336,  283,  283,  352,  283,
125301         - /*   190 */   283,  283,  283,  283,  228,  283,  283,  283,  283,  283,
125302         - /*   200 */   283,  283,  283,  283,  283,  501,  569,  596,  596,  596,
125303         - /*   210 */   507,  497,  441,  391,  353,  156,  156,  857,  353,  857,
125304         - /*   220 */   735,  813,  639,  715,  156,  332,  715,  715,  496,  419,
125305         - /*   230 */   646, 1357, 1184, 1184, 1335, 1335, 1184, 1341, 1260, 1144,
125306         - /*   240 */  1346, 1346, 1346, 1346, 1184, 1306, 1144, 1341, 1260, 1260,
125307         - /*   250 */  1144, 1184, 1306, 1206, 1284, 1184, 1184, 1306, 1184, 1306,
125308         - /*   260 */  1184, 1306, 1262, 1207, 1207, 1207, 1274, 1262, 1207, 1217,
125309         - /*   270 */  1207, 1274, 1207, 1207, 1185, 1200, 1185, 1200, 1185, 1200,
125310         - /*   280 */  1184, 1184, 1161, 1262, 1202, 1202, 1262, 1154, 1155, 1147,
125311         - /*   290 */  1152, 1144, 1241, 1239, 1250, 1250, 1254, 1254, 1254, 1254,
125312         - /*   300 */   -86,  -86,  -86,  -86,  -86,  -86, 1068,  304,  526,  249,
125313         - /*   310 */   408,  -83,  434,  812,   27,  811,  807,  802,  751,  589,
125314         - /*   320 */   651,  163,  131,  674,  366,  450,  299,  148,   23,  102,
125315         - /*   330 */   229,  -21, 1245, 1244, 1222, 1099, 1228, 1172, 1223, 1215,
125316         - /*   340 */  1213, 1115, 1106, 1123, 1110, 1209, 1105, 1212, 1226, 1098,
125317         - /*   350 */  1089, 1140, 1139, 1104, 1189, 1178, 1094, 1211, 1205, 1187,
125318         - /*   360 */  1101, 1071, 1153, 1175, 1146, 1138, 1151, 1091, 1164, 1165,
125319         - /*   370 */  1163, 1069, 1072, 1148, 1112, 1134, 1127, 1129, 1126, 1092,
125320         - /*   380 */  1114, 1118, 1088, 1090, 1093, 1087, 1084,  987, 1079, 1077,
125321         - /*   390 */  1074, 1065,  924, 1021, 1014, 1004, 1006,  819,  739,  896,
125322         - /*   400 */   855,  804,  739,  740,  736,  690,  654,  665,  618,  582,
125323         - /*   410 */   568,  528,  554,  379,  532,  479,  455,  379,  432,  371,
125324         - /*   420 */   341,   28,  338,  116,  -11,  -57,  -85,    7,   -8,    3,
125325         -};
125326         -#define YY_REDUCE_USE_DFLT (-110)
125327         -#define YY_REDUCE_COUNT (305)
125328         -#define YY_REDUCE_MIN   (-109)
125329         -#define YY_REDUCE_MAX   (1323)
       125725  + /*    80 */  1204, 1204, 1204, 1204, 1258, 1204, 1204, 1204, 1204, 1204,
       125726  + /*    90 */  1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,  -71,  -47,
       125727  + /*   100 */   -47,  -47,  -47,  -47,   -6,   88,  -66,   65,   65,  451,
       125728  + /*   110 */   502,  112,  112,   33,  127,  278,  -30,  -72,  -72,  -72,
       125729  + /*   120 */    11,  412,  412,  268,  608,  610,   65,   65,   65,   65,
       125730  + /*   130 */    65,   65,   65,   65,   65,   65,   65,   65,   65,   65,
       125731  + /*   140 */    65,   65,   65,   65,   65,  559,  138,  278,  127,   24,
       125732  + /*   150 */    24,   24,   24,   24,   24,  -72,  -72,  -72,  228,  341,
       125733  + /*   160 */   341,  207,  276,  300,  352,  354,  350,   65,   65,   65,
       125734  + /*   170 */    65,   65,   65,   65,   65,   65,   65,   65,   65,   65,
       125735  + /*   180 */    65,   65,   65,   65,  495,  495,  495,   65,   65,  499,
       125736  + /*   190 */    65,   65,   65,  574,   65,   65,  517,   65,   65,   65,
       125737  + /*   200 */    65,   65,   65,   65,   65,   65,   65,  566,  691,  288,
       125738  + /*   210 */   288,  288,  701,  620, 1058,  675,  603,  964,  964,  967,
       125739  + /*   220 */   603,  967,  722,  965,  936,  999,  964,  264,  999,  999,
       125740  + /*   230 */   911,  921,  434, 1196, 1119, 1119, 1202, 1202, 1119, 1222,
       125741  + /*   240 */  1184, 1126, 1244, 1244, 1244, 1244, 1119, 1251, 1126, 1222,
       125742  + /*   250 */  1184, 1184, 1126, 1119, 1251, 1145, 1237, 1119, 1119, 1251,
       125743  + /*   260 */  1275, 1119, 1251, 1119, 1251, 1275, 1203, 1203, 1203, 1264,
       125744  + /*   270 */  1275, 1203, 1211, 1203, 1264, 1203, 1203, 1194, 1216, 1194,
       125745  + /*   280 */  1216, 1194, 1216, 1194, 1216, 1119, 1119, 1206, 1275, 1250,
       125746  + /*   290 */  1250, 1275, 1221, 1225, 1224, 1226, 1126, 1336, 1347, 1363,
       125747  + /*   300 */  1363, 1371, 1371, 1371, 1371,  -72,  -72,  -72,  -72,  -72,
       125748  + /*   310 */   -72,  477,  623,  742,  819,  624,  694,   74, 1023,  221,
       125749  + /*   320 */  1055, 1065, 1077, 1087, 1080,  889, 1031,  939, 1093, 1122,
       125750  + /*   330 */  1085, 1139,  961, 1024, 1172, 1103,  821, 1384, 1392, 1374,
       125751  + /*   340 */  1255, 1385, 1331, 1386, 1378, 1381, 1285, 1277, 1298, 1287,
       125752  + /*   350 */  1393, 1289, 1396, 1414, 1293, 1286, 1340, 1341, 1312, 1397,
       125753  + /*   360 */  1388, 1304, 1426, 1423, 1407, 1323, 1291, 1379, 1406, 1380,
       125754  + /*   370 */  1375, 1391, 1330, 1415, 1418, 1421, 1329, 1337, 1422, 1390,
       125755  + /*   380 */  1424, 1425, 1427, 1429, 1395, 1419, 1430, 1400, 1405, 1431,
       125756  + /*   390 */  1432, 1433, 1342, 1435, 1436, 1438, 1437, 1339, 1439, 1441,
       125757  + /*   400 */  1440, 1434, 1443, 1343, 1445, 1442, 1446, 1444, 1445, 1450,
       125758  + /*   410 */  1451, 1452, 1453, 1454, 1459, 1455, 1460, 1462, 1458, 1461,
       125759  + /*   420 */  1463, 1466, 1465, 1461, 1467, 1469, 1470, 1471, 1473, 1354,
       125760  + /*   430 */  1370, 1376, 1377, 1474, 1485, 1484,
       125761  +};
       125762  +#define YY_REDUCE_USE_DFLT (-176)
       125763  +#define YY_REDUCE_COUNT (310)
       125764  +#define YY_REDUCE_MIN   (-175)
       125765  +#define YY_REDUCE_MAX   (1234)
125330 125766   static const short yy_reduce_ofst[] = {
125331         - /*     0 */   238,  954,  213,  289,  310,  234,  144,  317, -109,  382,
125332         - /*    10 */   377,  303,  461,  389,  378,  368,  302,  294,  253,  395,
125333         - /*    20 */   293,  324,  403,  403,  403,  403,  403,  403,  403,  403,
125334         - /*    30 */   403,  403,  403,  403,  403,  403,  403,  403,  403,  403,
125335         - /*    40 */   403,  403,  403,  403,  403,  403,  403,  403,  403,  403,
125336         - /*    50 */   403, 1022, 1012, 1005,  998,  963,  961,  959,  957,  950,
125337         - /*    60 */   947,  930,  912,  873,  861,  823,  810,  771,  759,  720,
125338         - /*    70 */   708,  670,  657,  619,  614,  612,  610,  608,  606,  604,
125339         - /*    80 */   598,  595,  593,  580,  542,  540,  537,  535,  533,  531,
125340         - /*    90 */   529,  527,  503,  386,  403,  403,  403,  403,  403,  403,
125341         - /*   100 */   403,  403,  403,   95,  447,   82,  334,  504,  467,  403,
125342         - /*   110 */   477,  464,  403,  403,  403,  403,  860,  747,  744,  785,
125343         - /*   120 */   638,  638,  926,  891,  900,  899,  887,  844,  840,  835,
125344         - /*   130 */   848,  830,  843,  829,  792,  839,  826,  737,  838,  795,
125345         - /*   140 */   789,   47,  734,  530,  696,  777,  711,  677,  733,  730,
125346         - /*   150 */   729,  728,  727,  627,  448,   64,  187, 1305, 1302, 1252,
125347         - /*   160 */  1290, 1273, 1323, 1322, 1321, 1319, 1318, 1316, 1315, 1314,
125348         - /*   170 */  1313, 1312, 1311, 1310, 1308, 1307, 1304, 1303, 1301, 1298,
125349         - /*   180 */  1294, 1292, 1289, 1266, 1264, 1259, 1288, 1287, 1238, 1285,
125350         - /*   190 */  1281, 1280, 1279, 1278, 1251, 1277, 1276, 1275, 1273, 1268,
125351         - /*   200 */  1267, 1265, 1263, 1261, 1257, 1248, 1237, 1247, 1246, 1243,
125352         - /*   210 */  1238, 1240, 1235, 1249, 1234, 1233, 1230, 1220, 1214, 1210,
125353         - /*   220 */  1225, 1219, 1232, 1231, 1197, 1195, 1227, 1224, 1201, 1208,
125354         - /*   230 */  1242, 1137, 1236, 1229, 1193, 1181, 1221, 1177, 1196, 1179,
125355         - /*   240 */  1191, 1190, 1186, 1182, 1218, 1216, 1176, 1162, 1183, 1180,
125356         - /*   250 */  1160, 1199, 1203, 1133, 1095, 1198, 1194, 1188, 1192, 1171,
125357         - /*   260 */  1169, 1168, 1173, 1174, 1166, 1159, 1141, 1170, 1158, 1167,
125358         - /*   270 */  1157, 1132, 1145, 1143, 1124, 1128, 1103, 1102, 1100, 1096,
125359         - /*   280 */  1150, 1149, 1085, 1125, 1080, 1064, 1120, 1097, 1082, 1078,
125360         - /*   290 */  1073, 1067, 1109, 1107, 1119, 1117, 1116, 1113, 1111, 1108,
125361         - /*   300 */  1007, 1000, 1002, 1076, 1075, 1081,
       125767  + /*     0 */  -143,  954,   86,   21,  -50,   23,   79,  134,  170, -175,
       125768  + /*    10 */   229,  260, -121,  212,  219,  291,  -54,  349,  362,  156,
       125769  + /*    20 */   309,  311,  334,   85,  224,  394,  314,  314,  314,  314,
       125770  + /*    30 */   314,  314,  314,  314,  314,  314,  314,  314,  314,  314,
       125771  + /*    40 */   314,  314,  314,  314,  314,  314,  314,  314,  314,  314,
       125772  + /*    50 */   314,  314,  314,  314,  314,  374,  441,  443,  450,  452,
       125773  + /*    60 */   515,  554,  567,  569,  572,  578,  580,  582,  584,  587,
       125774  + /*    70 */   593,  631,  644,  646,  649,  655,  657,  659,  661,  664,
       125775  + /*    80 */   708,  720,  759,  771,  810,  822,  861,  873,  912,  930,
       125776  + /*    90 */   947,  950,  957,  959,  963,  966,  968,  998,  314,  314,
       125777  + /*   100 */   314,  314,  314,  314,  314,  314,  314,  447,  -53,  166,
       125778  + /*   110 */   438,  348,  363,  314,  473,  469,  314,  314,  314,  314,
       125779  + /*   120 */   -15,   59,  101,  688,  220,  220,  525,  256,  729,  735,
       125780  + /*   130 */   736,  740,  741,  744,  645,  448,  738,  458,  786,  503,
       125781  + /*   140 */   780,  656,  721,  724,  792,  545,  568,  706,  683,  681,
       125782  + /*   150 */   779,  784,  830,  831,  835,  678,  601, -104,   -2,   96,
       125783  + /*   160 */   111,  218,  287,  308,  310,  312,  335,  411,  453,  461,
       125784  + /*   170 */   573,  599,  617,  658,  665,  670,  732,  734,  775,  848,
       125785  + /*   180 */   875,  892,  893,  898,  332,  420,  869,  931,  944,  886,
       125786  + /*   190 */   983,  992, 1009,  958, 1017, 1028,  988, 1033, 1034, 1035,
       125787  + /*   200 */   287, 1036, 1044, 1045, 1047, 1049, 1056,  915,  972,  997,
       125788  + /*   210 */  1000, 1002,  886, 1011, 1015, 1061, 1013, 1001, 1003,  977,
       125789  + /*   220 */  1018,  979, 1050, 1041, 1040, 1052, 1014, 1004, 1059, 1060,
       125790  + /*   230 */  1032, 1038, 1084,  995, 1089, 1090, 1008, 1016, 1092, 1037,
       125791  + /*   240 */  1068, 1062, 1069, 1072, 1073, 1074, 1105, 1112, 1071, 1048,
       125792  + /*   250 */  1081, 1088, 1078, 1116, 1118, 1046, 1066, 1128, 1136, 1140,
       125793  + /*   260 */  1120, 1147, 1146, 1148, 1150, 1130, 1135, 1137, 1138, 1132,
       125794  + /*   270 */  1141, 1142, 1143, 1149, 1144, 1153, 1154, 1104, 1107, 1108,
       125795  + /*   280 */  1114, 1115, 1117, 1123, 1125, 1173, 1176, 1121, 1165, 1127,
       125796  + /*   290 */  1131, 1167, 1157, 1151, 1158, 1166, 1168, 1212, 1214, 1227,
       125797  + /*   300 */  1228, 1231, 1232, 1233, 1234, 1152, 1155, 1159, 1198, 1199,
       125798  + /*   310 */  1219,
125362 125799   };
125363 125800   static const YYACTIONTYPE yy_default[] = {
125364         - /*     0 */   647,  964,  964,  964,  878,  878,  969,  964,  774,  802,
125365         - /*    10 */   802,  938,  969,  969,  969,  876,  969,  969,  969,  964,
125366         - /*    20 */   969,  778,  808,  969,  969,  969,  969,  969,  969,  969,
125367         - /*    30 */   969,  937,  939,  816,  815,  918,  789,  813,  806,  810,
125368         - /*    40 */   879,  872,  873,  871,  875,  880,  969,  809,  841,  856,
125369         - /*    50 */   840,  969,  969,  969,  969,  969,  969,  969,  969,  969,
125370         - /*    60 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
125371         - /*    70 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
125372         - /*    80 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
125373         - /*    90 */   969,  969,  969,  969,  850,  855,  862,  854,  851,  843,
125374         - /*   100 */   842,  844,  845,  969,  969,  673,  739,  969,  969,  846,
125375         - /*   110 */   969,  685,  847,  859,  858,  857,  680,  969,  969,  969,
125376         - /*   120 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
125377         - /*   130 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
125378         - /*   140 */   969,  969,  969,  969,  647,  964,  969,  969,  964,  964,
125379         - /*   150 */   964,  964,  964,  964,  956,  778,  768,  969,  969,  969,
125380         - /*   160 */   969,  969,  969,  969,  969,  969,  969,  944,  942,  969,
125381         - /*   170 */   891,  969,  969,  969,  969,  969,  969,  969,  969,  969,
125382         - /*   180 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
125383         - /*   190 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
125384         - /*   200 */   969,  969,  969,  969,  653,  969,  911,  774,  774,  774,
125385         - /*   210 */   776,  754,  766,  655,  812,  791,  791,  923,  812,  923,
125386         - /*   220 */   710,  733,  707,  802,  791,  874,  802,  802,  775,  766,
125387         - /*   230 */   969,  949,  782,  782,  941,  941,  782,  821,  743,  812,
125388         - /*   240 */   750,  750,  750,  750,  782,  670,  812,  821,  743,  743,
125389         - /*   250 */   812,  782,  670,  917,  915,  782,  782,  670,  782,  670,
125390         - /*   260 */   782,  670,  884,  741,  741,  741,  725,  884,  741,  710,
125391         - /*   270 */   741,  725,  741,  741,  795,  790,  795,  790,  795,  790,
125392         - /*   280 */   782,  782,  969,  884,  888,  888,  884,  807,  796,  805,
125393         - /*   290 */   803,  812,  676,  728,  663,  663,  652,  652,  652,  652,
125394         - /*   300 */   961,  961,  956,  712,  712,  695,  969,  969,  969,  969,
125395         - /*   310 */   969,  969,  687,  969,  893,  969,  969,  969,  969,  969,
125396         - /*   320 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
125397         - /*   330 */   969,  828,  969,  648,  951,  969,  969,  948,  969,  969,
125398         - /*   340 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
125399         - /*   350 */   969,  969,  969,  969,  969,  969,  921,  969,  969,  969,
125400         - /*   360 */   969,  969,  969,  914,  913,  969,  969,  969,  969,  969,
125401         - /*   370 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
125402         - /*   380 */   969,  969,  969,  969,  969,  969,  969,  757,  969,  969,
125403         - /*   390 */   969,  761,  969,  969,  969,  969,  969,  969,  804,  969,
125404         - /*   400 */   797,  969,  877,  969,  969,  969,  969,  969,  969,  969,
125405         - /*   410 */   969,  969,  969,  966,  969,  969,  969,  965,  969,  969,
125406         - /*   420 */   969,  969,  969,  830,  969,  829,  833,  969,  661,  969,
125407         - /*   430 */   644,  649,  960,  963,  962,  959,  958,  957,  952,  950,
125408         - /*   440 */   947,  946,  945,  943,  940,  936,  897,  895,  902,  901,
125409         - /*   450 */   900,  899,  898,  896,  894,  892,  818,  817,  814,  811,
125410         - /*   460 */   753,  935,  890,  752,  749,  748,  669,  953,  920,  929,
125411         - /*   470 */   928,  927,  822,  926,  925,  924,  922,  919,  906,  820,
125412         - /*   480 */   819,  744,  882,  881,  672,  910,  909,  908,  912,  916,
125413         - /*   490 */   907,  784,  751,  671,  668,  675,  679,  731,  732,  740,
125414         - /*   500 */   738,  737,  736,  735,  734,  730,  681,  686,  724,  709,
125415         - /*   510 */   708,  717,  716,  722,  721,  720,  719,  718,  715,  714,
125416         - /*   520 */   713,  706,  705,  711,  704,  727,  726,  723,  703,  747,
125417         - /*   530 */   746,  745,  742,  702,  701,  700,  833,  699,  698,  838,
125418         - /*   540 */   837,  866,  826,  755,  759,  758,  762,  763,  771,  770,
125419         - /*   550 */   769,  780,  781,  793,  792,  824,  823,  794,  779,  773,
125420         - /*   560 */   772,  788,  787,  786,  785,  777,  767,  799,  798,  868,
125421         - /*   570 */   783,  867,  865,  934,  933,  932,  931,  930,  870,  967,
125422         - /*   580 */   968,  887,  889,  886,  801,  800,  885,  869,  839,  836,
125423         - /*   590 */   690,  691,  905,  904,  903,  693,  692,  689,  688,  863,
125424         - /*   600 */   860,  852,  864,  861,  853,  849,  848,  834,  832,  831,
125425         - /*   610 */   827,  835,  760,  756,  825,  765,  764,  697,  696,  694,
125426         - /*   620 */   678,  677,  674,  667,  665,  664,  666,  662,  660,  659,
125427         - /*   630 */   658,  657,  656,  684,  683,  682,  654,  651,  650,  646,
125428         - /*   640 */   645,  643,
       125801  + /*     0 */   982, 1300, 1300, 1300, 1214, 1214, 1214, 1305, 1300, 1109,
       125802  + /*    10 */  1138, 1138, 1274, 1305, 1305, 1305, 1305, 1305, 1305, 1212,
       125803  + /*    20 */  1305, 1305, 1305, 1300, 1305, 1113, 1144, 1305, 1305, 1305,
       125804  + /*    30 */  1305, 1305, 1305, 1305, 1305, 1273, 1275, 1152, 1151, 1254,
       125805  + /*    40 */  1125, 1149, 1142, 1146, 1215, 1208, 1209, 1207, 1211, 1216,
       125806  + /*    50 */  1305, 1145, 1177, 1192, 1176, 1305, 1305, 1305, 1305, 1305,
       125807  + /*    60 */  1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
       125808  + /*    70 */  1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
       125809  + /*    80 */  1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
       125810  + /*    90 */  1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1186, 1191,
       125811  + /*   100 */  1198, 1190, 1187, 1179, 1178, 1180, 1181, 1305, 1305, 1008,
       125812  + /*   110 */  1074, 1305, 1305, 1182, 1305, 1020, 1183, 1195, 1194, 1193,
       125813  + /*   120 */  1015, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
       125814  + /*   130 */  1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
       125815  + /*   140 */  1305, 1305, 1305, 1305, 1305,  982, 1300, 1305, 1305, 1300,
       125816