System.Data.SQLite

Login

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

Changes In Branch branch-1.0.105 Excluding Merge-Ins

This is equivalent to a diff from 27be81037c to 0fadcbe4d2

2017-06-11
02:58
Merge in applicable changes from the 1.0.105.2 release. check-in: 802962c8f3 user: mistachkin tags: trunk
02:44
Final updates for release 1.0.105.2. Leaf check-in: 0fadcbe4d2 user: mistachkin tags: release, release-1.0.105.2, branch-1.0.105
2017-06-10
17:51
Fix a merge conflict for the JSON1 extension. check-in: c8e059414e user: mistachkin tags: branch-1.0.105
2017-05-11
15:33
Cherrypick of [26a05172c42e3647] and [13a554277f979dd2], the web page fixes. check-in: 1c134c9690 user: mistachkin tags: branch-1.0.105
2017-04-09
18:16
Fix typo on a couple wiki pages. check-in: 26a05172c4 user: mistachkin tags: trunk
03:13
Final updates for release 1.0.105.0. check-in: 27be81037c user: mistachkin tags: trunk, release, release-1.0.105.0
2017-04-08
18:02
Update version history docs with the proposed release date for 1.0.105.0. check-in: 4ce2260591 user: mistachkin tags: trunk

Changes to Doc/Extra/Core/lang_createtrigger.html.

   285    285   restrictions apply:</p>
   286    286   
   287    287   <ul>
   288    288   <li><p>
   289    289     The name of the table to be modified in an <a href="lang_update.html">UPDATE</a>, <a href="lang_delete.html">DELETE</a>, or <a href="lang_insert.html">INSERT</a>
   290    290     statement must be an unqualified table name.  In other words, one must
   291    291     use just "<i>tablename</i>" not "<i>database</i><b>.</b><i>tablename</i>"
   292         -  when specifying the table.  The table to be modified must exist in the
          292  +  when specifying the table. </p></li>
          293  +
          294  +<li><p>
          295  + For non-TEMP triggers,
          296  +  the table to be modified or queried must exist in the
   293    297     same database as the table or view to which the trigger is attached.
          298  +  TEMP triggers are not subject to the same-database rule.  A TEMP
          299  +  trigger is allowed to query or modify any table in any <a href="lang_attach.html">ATTACH</a>-ed database.
   294    300     </p></li>
   295    301   
   296    302   <li><p>
   297    303     The "INSERT INTO <i>table</i> DEFAULT VALUES" form of the <a href="lang_insert.html">INSERT</a> statement
   298    304     is not supported.
   299    305     </p></li>
   300    306   

Changes to Doc/Extra/Core/pragma.html.

   751    751   
   752    752       <p>The foreign_key_check pragma checks the database, or the table
   753    753       called "<i>table-name</i>", for 
   754    754       <a href="foreignkeys.html">foreign key constraints</a> that are violated and returns one row of
   755    755       output for each violation.  There are four columns in each result row.
   756    756       The first column is the name of the table that contains the REFERENCES
   757    757       clause.  The second column is the <a href="lang_createtable.html#rowid">rowid</a> of the row that
   758         -    contains the invalid REFERENCES clause.  The third column is the name
          758  +    contains the invalid REFERENCES clause, or NULL if the child table is a
          759  +    <a href="withoutrowid.html">WITHOUT ROWID</a> table.  The third column is the name
   759    760       of the table that is referred to. The fourth column is the index of
   760    761       the specific foreign key constraint that failed.  The fourth column
   761    762       in the output of the foreign_key_check pragma is the same integer as
   762    763       the first column in the output of the <a href="pragma.html#pragma_foreign_key_list">foreign_key_list pragma</a>.
   763    764       When a "<i>table-name</i>" is specified, the only foreign key constraints
   764    765       checked are those created by REFERENCES clauses in the
   765    766       CREATE TABLE statement for <i>table-name</i>.</p>
................................................................................
  1267   1268   <h _id=pragma_page_size style="display:none"> PRAGMA page_size</h><hr>
  1268   1269      <p><b>PRAGMA </b><i>schema.</i><b>page_size;
  1269   1270          <br>PRAGMA </b><i>schema.</i><b>page_size = </b><i>bytes</i><b>;</b></p>
  1270   1271       <p>Query or set the page size of the database. The page
  1271   1272       size must be a power of two between 512 and 65536 inclusive.
  1272   1273       </p>
  1273   1274   
  1274         -    <p>When a new database is created, SQLite assigned a page size to
         1275  +    <p>When a new database is created, SQLite assigns a page size to
  1275   1276       the database based on platform and filesystem.  For many years,
  1276   1277       the default page size was almost always 1024 bytes, but beginning
  1277   1278       with SQLite <a href="releaselog/3_12_0.html">version 3.12.0</a> (2016-03-29), 
  1278         -    the default page size increased
  1279         -    to 4096.
         1279  +    the default page size increased to 4096.
         1280  +    The default page size is recommended for most applications.
  1280   1281   
  1281         -    <p>The page_size pragma will only set in the
  1282         -    page size if it is issued before any other SQL statements that
  1283         -    cause I/O against the database file.
  1284         -    SQL statements that cause I/O against the database file include
  1285         -    "CREATE", "SELECT", "BEGIN IMMEDIATE", and "PRAGMA journal_mode=WAL".
  1286         -    If the page_size pragma is
  1287         -    used to specify a new page size just prior to
  1288         -    running the <a href="lang_vacuum.html">VACUUM</a> command and if the database is not in
  1289         -    <a href="wal.html">WAL journal mode</a> then <a href="lang_vacuum.html">VACUUM</a> will change the page
  1290         -    size to the new value.</p>
         1282  +    <p>Specifying a new page size does not change the page size
         1283  +    immediately.  Instead, the new page size is remembered and is used
         1284  +    to set the page size when the database is first created, if it does
         1285  +    not already exist when the page_size pragma is issued, or at the
         1286  +    next <a href="lang_vacuum.html">VACUUM</a> command that is run on the same database connection
         1287  +    while not in <a href="wal.html">WAL mode</a>.</p>
  1291   1288   
  1292   1289       <p>The <a href="compile.html#default_page_size">SQLITE_DEFAULT_PAGE_SIZE</a> compile-time option can be used
  1293   1290       to change the default page size assigned to new databases.
  1294   1291   <a name="pragma_parser_trace"></a>
  1295   1292   <h _id=pragma_parser_trace style="display:none"> PRAGMA parser_trace</h><hr>
  1296   1293       <p><b>PRAGMA parser_trace = </b><i>boolean</i><b>; </b></p>
  1297   1294   
................................................................................
  1396   1393          <a href="fileformat2.html#database_header">database header</a>. 
  1397   1394   
  1398   1395   <p>    SQLite automatically increments the schema-version whenever the
  1399   1396          schema changes. As each SQL statement runs, the schema version is
  1400   1397          checked to ensure that the schema has not changed since the SQL
  1401   1398          statement was <a href="c3ref/prepare.html">prepared</a>.
  1402   1399          Subverting this mechanism by using "PRAGMA schema_version"
  1403         -       my cause SQL statement to run using an obsolete schema,
         1400  +       may cause SQL statement to run using an obsolete schema,
  1404   1401          which can lead to incorrect answers and/or
  1405   1402          <a href="howtocorrupt.html#cfgerr">database corruption</a>.
  1406   1403   
  1407   1404          
  1408   1405       <p><span style='background-color: #ffff60;'>
  1409   1406       <b>Warning:</b>
  1410   1407       Misuse of this pragma can result in <a href="howtocorrupt.html#cfgerr">database corruption</a>.

Changes to Doc/Extra/Core/syntax/column-name-list.html.

     1      1   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
     2      2   <html><head>
     3      3   <meta name="viewport" content="width=device-width, initial-scale=1.0">
     4      4   <meta http-equiv="content-type" content="text/html; charset=UTF-8">
     5      5   <link href="../sqlite.css" rel="stylesheet">
     6      6   <title>SQLite Syntax: column-name-list</title>
            7  +<!-- path=../ -->
     7      8   </head>
     8      9   <body>
     9     10   <div class=nosearch>
    10     11   <a href="../index.html">
    11     12   <img class="logo" src="../images/sqlite370_banner.gif" alt="SQLite" border="0">
    12     13   </a>
    13     14   <div><!-- IE hack to prevent disappearing logo --></div>
................................................................................
    34     35   <li><a href='../docs.html'>Documentation</a>
    35     36   <li><a href='../download.html'>Download</a>
    36     37   <li><a href='../support.html'>Support</a>
    37     38   <li><a href='../prosupport.html'>Purchase</a>
    38     39   </ul>
    39     40   </div>
    40     41   <div class="searchmenu" id="searchmenu">
    41         -<form method="GET" action="search">
           42  +<form method="GET" action="../search">
    42     43   <span class="desktoponly">Search for:</span> <input type="text" name="q">
    43     44   <input type="submit" value="Go">
    44     45   </form>
    45     46   </div>
    46     47   </div>
    47     48   <script>
    48     49   function toggle_div(nm) {
................................................................................
    53     54   w.style.display = "block";
    54     55   }
    55     56   }
    56     57   function div_off(nm){document.getElementById(nm).style.display="none";}
    57     58   window.onbeforeunload = function(e){div_off("submenu");}
    58     59   /* Disable the Search feature if we are not operating from CGI, since */
    59     60   /* Search is accomplished using CGI and will not work without it. */
    60         -if( !location.origin.match(/http/) ){
           61  +if( !location.origin.match || !location.origin.match(/http/) ){
    61     62   document.getElementById("search_menubutton").style.display = "none";
    62     63   }
    63     64   /* Used by the Hide/Show button beside syntax diagrams, to toggle the */
    64     65   function hideorshow(btn,obj){
    65     66   var x = document.getElementById(obj);
    66     67   var b = document.getElementById(btn);
    67     68   if( x.style.display!='none' ){

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

    81     81   &lt;configuration&gt;
    82     82     &lt;system.data&gt;
    83     83       &lt;DbProviderFactories&gt;
    84     84         &lt;remove invariant="System.Data.SQLite"/&gt;
    85     85         &lt;add name="SQLite Data Provider" invariant="System.Data.SQLite" 
    86     86              description=".NET Framework Data Provider for SQLite"
    87     87              type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite,
    88         -                 Version=1.0.105.0, Culture=neutral,
           88  +                 Version=1.0.105.2, Culture=neutral,
    89     89                    PublicKeyToken=db937bc2d44ff139"/&gt;
    90     90       &lt;/DbProviderFactories&gt;
    91     91     &lt;/system.data&gt;
    92     92   &lt;/configuration&gt;
    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.105.2 - June 12, 2017</b></p>
           47  +    <ul>
           48  +      <li>Updated to <a href="https://www.sqlite.org/releaselog/3_19_3.html">SQLite 3.19.3</a>.</li>
           49  +      <li>Fix issues that prevented SQLiteBlob creation from succeeding for tables that did not have an integer primary key.</li>
           50  +    </ul>
           51  +    <p><b>1.0.105.1 - May 15, 2017</b></p>
           52  +    <ul>
           53  +      <li>Prevent culture settings from negatively impacting integer connection string defaults.</li>
           54  +      <li>Make sure the &quot;No_SQLiteConnectionNewParser&quot; and &quot;DefaultFlags_SQLiteConnection&quot; setting values end up being cached.</li>
           55  +      <li>Cache the XML file name and assembly directory used by the configuration subsystem.</li>
           56  +    </ul>
    46     57       <p><b>1.0.105.0 - April 9, 2017</b></p>
    47     58       <ul>
    48     59         <li>Updated to <a href="https://www.sqlite.org/releaselog/3_18_0.html">SQLite 3.18.0</a>.</li>
    49     60         <li>Add experimental support for native sha1 extension.</li>
    50     61       </ul>
    51     62       <p><b>1.0.104.0 - December 16, 2016</b></p>
    52     63       <ul>

Changes to Doc/SQLite.NET.chm.

cannot compute difference between binary files

Changes to Doc/buildChm.tcl.

   419    419   
   420    420   set patterns(.html,7) \
   421    421       {"(System\.Data\.SQLite~System\.Data\.SQLite\.SQLiteModule\.Dispose)\.html"}
   422    422   
   423    423   set patterns(.html,8) \
   424    424       {"(System\.Data\.SQLite~System\.Data\.SQLite\.SQLiteVirtualTableCursor\.Dispose)\.html"}
   425    425   
          426  +set patterns(.html,9) \
          427  +    {"(System\.Data\.SQLite~System\.Data\.SQLite\.ISQLiteManagedModule\.[^(]+)\((?:[^)]+)\)\.html"}
          428  +
   426    429   set subSpecs(.hhc,1) [readFileAsSubSpec [file join $path SQLite.NET.hhc]]
   427    430   
   428    431   set subSpecs(.hhp,1) {Default topic=Provider\welcome.html}
   429    432   set subSpecs(.hhp,2) {"Provider\welcome.html","Provider\welcome.html",,,,,}
   430    433   
   431    434   set subSpecs(.html,1) {"System.Data.SQLite~\1.html"}
   432    435   set subSpecs(.html,2) {9eekhta0}
   433    436   set subSpecs(.html,3) {78dfe2yb}
   434    437   set subSpecs(.html,4) {"\1~Overloads.html"}
   435    438   set subSpecs(.html,5) {"\1~Overloads.html"}
   436    439   set subSpecs(.html,6) {"\1~Overloads.html"}
   437    440   set subSpecs(.html,7) {"\1~Overloads.html"}
   438    441   set subSpecs(.html,8) {"\1~Overloads.html"}
          442  +set subSpecs(.html,9) {"\1.html"}
   439    443   
   440    444   ###############################################################################
   441    445   
   442    446   set fileNames [list \
   443    447       [file join $temporaryPath SQLite.NET.hhp] \
   444    448       [file join $temporaryPath SQLite.NET.hhc]]
   445    449   

Changes to Doc/sync.eagle.

    50     50       [file join images sqlite370_banner.gif] \
    51     51       [file join images syntax alter-table-stmt.gif] \
    52     52       [file join images syntax analyze-stmt.gif] \
    53     53       [file join images syntax attach-stmt.gif] \
    54     54       [file join images syntax begin-stmt.gif] \
    55     55       [file join images syntax column-constraint.gif] \
    56     56       [file join images syntax column-def.gif] \
           57  +    [file join images syntax column-name-list.gif] \
    57     58       [file join images syntax comment-syntax.gif] \
    58     59       [file join images syntax commit-stmt.gif] \
    59     60       [file join images syntax common-table-expression.gif] \
    60     61       [file join images syntax compound-operator.gif] \
    61     62       [file join images syntax compound-select-stmt.gif] \
    62     63       [file join images syntax conflict-clause.gif] \
    63     64       [file join images syntax create-index-stmt.gif] \
................................................................................
   109    110       [file join images syntax with-clause.gif] \
   110    111       [file join syntax alter-table-stmt.html] \
   111    112       [file join syntax analyze-stmt.html] \
   112    113       [file join syntax attach-stmt.html] \
   113    114       [file join syntax begin-stmt.html] \
   114    115       [file join syntax column-constraint.html] \
   115    116       [file join syntax column-def.html] \
          117  +    [file join syntax column-name-list.html] \
   116    118       [file join syntax comment-syntax.html] \
   117    119       [file join syntax commit-stmt.html] \
   118    120       [file join syntax common-table-expression.html] \
   119    121       [file join syntax compound-operator.html] \
   120    122       [file join syntax compound-select-stmt.html] \
   121    123       [file join syntax conflict-clause.html] \
   122    124       [file join syntax create-index-stmt.html] \

Changes to NuGet/SQLite.Beta.nuspec.

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

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

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

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

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

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

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

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

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

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

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

Changes to NuGet/SQLite.Core.nuspec.

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

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

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

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

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

Changes to NuGet/SQLite.EF6.nuspec.

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

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

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

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

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

Changes to NuGet/SQLite.Linq.nuspec.

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

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

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

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

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

Changes to NuGet/SQLite.MSIL.nuspec.

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

Changes to NuGet/SQLite.Test.nuspec.

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

Changes to NuGet/SQLite.nuspec.

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

Changes to NuGet/SQLite.x64.nuspec.

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

Changes to NuGet/SQLite.x86.nuspec.

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

Changes to SQLite.Designer/AssemblyInfo.cs.

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

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

     1      1   <?xml version="1.0" encoding="utf-8"?>
     2      2   <Vsix Version="1.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2010">
     3      3     <Identifier Id="67b5f3a9-cde1-430f-a12b-af95bb064851">
     4      4       <Name>System.Data.SQLite Designer</Name>
     5      5       <Author>https://system.data.sqlite.org/</Author>
     6         -    <Version>1.0.105.0</Version>
            6  +    <Version>1.0.105.2</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.

    25     25   	<UserMacro
    26     26   		Name="INTEROP_LINKER_VERSION"
    27     27   		Value="1.0"
    28     28   		PerformEnvironmentSet="true"
    29     29   	/>
    30     30   	<UserMacro
    31     31   		Name="INTEROP_MANIFEST_VERSION"
    32         -		Value="1.0.105.0"
           32  +		Value="1.0.105.2"
    33     33   		PerformEnvironmentSet="true"
    34     34   	/>
    35     35   	<UserMacro
    36     36   		Name="INTEROP_RC_VERSION"
    37         -		Value="1,0,105,0"
           37  +		Value="1,0,105,2"
    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.

    25     25   	<UserMacro
    26     26   		Name="INTEROP_LINKER_VERSION"
    27     27   		Value="1.0"
    28     28   		PerformEnvironmentSet="true"
    29     29   	/>
    30     30   	<UserMacro
    31     31   		Name="INTEROP_MANIFEST_VERSION"
    32         -		Value="1.0.105.0"
           32  +		Value="1.0.105.2"
    33     33   		PerformEnvironmentSet="true"
    34     34   	/>
    35     35   	<UserMacro
    36     36   		Name="INTEROP_RC_VERSION"
    37         -		Value="1,0,105,0"
           37  +		Value="1,0,105,2"
    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.

     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     13       <INTEROP_BUILD_NUMBER>105</INTEROP_BUILD_NUMBER>
    14     14       <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION>
    15         -    <INTEROP_MANIFEST_VERSION>1.0.105.0</INTEROP_MANIFEST_VERSION>
    16         -    <INTEROP_RC_VERSION>1,0,105,0</INTEROP_RC_VERSION>
           15  +    <INTEROP_MANIFEST_VERSION>1.0.105.2</INTEROP_MANIFEST_VERSION>
           16  +    <INTEROP_RC_VERSION>1,0,105,2</INTEROP_RC_VERSION>
    17     17       <INTEROP_INCLUDE_DIRECTORIES>src\core</INTEROP_INCLUDE_DIRECTORIES>
    18     18       <INTEROP_LIBRARY_DIRECTORIES></INTEROP_LIBRARY_DIRECTORIES>
    19     19       <INTEROP_LIBRARY_DEPENDENCIES></INTEROP_LIBRARY_DEPENDENCIES>
    20     20       <INTEROP_DEBUG_DEFINES>INTEROP_DEBUG=0x31F;INTEROP_LOG=1;INTEROP_TEST_EXTENSION=1</INTEROP_DEBUG_DEFINES>
    21     21       <INTEROP_EXTRA_DEFINES>INTEROP_PLACEHOLDER=1;INTEROP_EXTENSION_FUNCTIONS=1;INTEROP_CODEC=1;INTEROP_VIRTUAL_TABLE=1;INTEROP_FTS5_EXTENSION=1;INTEROP_PERCENTILE_EXTENSION=1;INTEROP_TOTYPE_EXTENSION=1;INTEROP_REGEXP_EXTENSION=1;INTEROP_JSON1_EXTENSION=1;INTEROP_SHA1_EXTENSION=1</INTEROP_EXTRA_DEFINES>
    22     22       <INTEROP_ASSEMBLY_RESOURCES>/ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteCommand.bmp,System.Data.SQLite.SQLiteCommand.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteConnection.bmp,System.Data.SQLite.SQLiteConnection.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteDataAdapter.bmp,System.Data.SQLite.SQLiteDataAdapter.bmp</INTEROP_ASSEMBLY_RESOURCES>
    23     23       <INTEROP_KEY_FILE>$(ProjectDir)..\Keys\System.Data.SQLite.snk</INTEROP_KEY_FILE>

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

     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     13       <INTEROP_BUILD_NUMBER>105</INTEROP_BUILD_NUMBER>
    14     14       <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION>
    15         -    <INTEROP_MANIFEST_VERSION>1.0.105.0</INTEROP_MANIFEST_VERSION>
    16         -    <INTEROP_RC_VERSION>1,0,105,0</INTEROP_RC_VERSION>
           15  +    <INTEROP_MANIFEST_VERSION>1.0.105.2</INTEROP_MANIFEST_VERSION>
           16  +    <INTEROP_RC_VERSION>1,0,105,2</INTEROP_RC_VERSION>
    17     17       <INTEROP_INCLUDE_DIRECTORIES>src\core</INTEROP_INCLUDE_DIRECTORIES>
    18     18       <INTEROP_LIBRARY_DIRECTORIES></INTEROP_LIBRARY_DIRECTORIES>
    19     19       <INTEROP_LIBRARY_DEPENDENCIES></INTEROP_LIBRARY_DEPENDENCIES>
    20     20       <INTEROP_DEBUG_DEFINES>INTEROP_DEBUG=0x31F;INTEROP_LOG=1;INTEROP_TEST_EXTENSION=1</INTEROP_DEBUG_DEFINES>
    21     21       <INTEROP_EXTRA_DEFINES>INTEROP_PLACEHOLDER=1;INTEROP_EXTENSION_FUNCTIONS=1;INTEROP_CODEC=1;INTEROP_VIRTUAL_TABLE=1;INTEROP_FTS5_EXTENSION=1;INTEROP_PERCENTILE_EXTENSION=1;INTEROP_TOTYPE_EXTENSION=1;INTEROP_REGEXP_EXTENSION=1;INTEROP_JSON1_EXTENSION=1;INTEROP_SHA1_EXTENSION=1</INTEROP_EXTRA_DEFINES>
    22     22       <INTEROP_ASSEMBLY_RESOURCES>/ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteCommand.bmp,System.Data.SQLite.SQLiteCommand.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteConnection.bmp,System.Data.SQLite.SQLiteConnection.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteDataAdapter.bmp,System.Data.SQLite.SQLiteDataAdapter.bmp</INTEROP_ASSEMBLY_RESOURCES>
    23     23       <INTEROP_KEY_FILE>$(ProjectDir)..\Keys\System.Data.SQLite.snk</INTEROP_KEY_FILE>

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

     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     13       <INTEROP_BUILD_NUMBER>105</INTEROP_BUILD_NUMBER>
    14     14       <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION>
    15         -    <INTEROP_MANIFEST_VERSION>1.0.105.0</INTEROP_MANIFEST_VERSION>
    16         -    <INTEROP_RC_VERSION>1,0,105,0</INTEROP_RC_VERSION>
           15  +    <INTEROP_MANIFEST_VERSION>1.0.105.2</INTEROP_MANIFEST_VERSION>
           16  +    <INTEROP_RC_VERSION>1,0,105,2</INTEROP_RC_VERSION>
    17     17       <INTEROP_INCLUDE_DIRECTORIES>src\core</INTEROP_INCLUDE_DIRECTORIES>
    18     18       <INTEROP_LIBRARY_DIRECTORIES></INTEROP_LIBRARY_DIRECTORIES>
    19     19       <INTEROP_LIBRARY_DEPENDENCIES></INTEROP_LIBRARY_DEPENDENCIES>
    20     20       <INTEROP_DEBUG_DEFINES>INTEROP_DEBUG=0x31F;INTEROP_LOG=1;INTEROP_TEST_EXTENSION=1</INTEROP_DEBUG_DEFINES>
    21     21       <INTEROP_EXTRA_DEFINES>INTEROP_PLACEHOLDER=1;INTEROP_EXTENSION_FUNCTIONS=1;INTEROP_CODEC=1;INTEROP_VIRTUAL_TABLE=1;INTEROP_FTS5_EXTENSION=1;INTEROP_PERCENTILE_EXTENSION=1;INTEROP_TOTYPE_EXTENSION=1;INTEROP_REGEXP_EXTENSION=1;INTEROP_JSON1_EXTENSION=1;INTEROP_SHA1_EXTENSION=1</INTEROP_EXTRA_DEFINES>
    22     22       <INTEROP_ASSEMBLY_RESOURCES>/ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteCommand.bmp,System.Data.SQLite.SQLiteCommand.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteConnection.bmp,System.Data.SQLite.SQLiteConnection.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteDataAdapter.bmp,System.Data.SQLite.SQLiteDataAdapter.bmp</INTEROP_ASSEMBLY_RESOURCES>
    23     23       <INTEROP_KEY_FILE>$(ProjectDir)..\Keys\System.Data.SQLite.snk</INTEROP_KEY_FILE>

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

     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     13       <INTEROP_BUILD_NUMBER>105</INTEROP_BUILD_NUMBER>
    14     14       <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION>
    15         -    <INTEROP_MANIFEST_VERSION>1.0.105.0</INTEROP_MANIFEST_VERSION>
    16         -    <INTEROP_RC_VERSION>1,0,105,0</INTEROP_RC_VERSION>
           15  +    <INTEROP_MANIFEST_VERSION>1.0.105.2</INTEROP_MANIFEST_VERSION>
           16  +    <INTEROP_RC_VERSION>1,0,105,2</INTEROP_RC_VERSION>
    17     17       <INTEROP_INCLUDE_DIRECTORIES>src\core</INTEROP_INCLUDE_DIRECTORIES>
    18     18       <INTEROP_LIBRARY_DIRECTORIES></INTEROP_LIBRARY_DIRECTORIES>
    19     19       <INTEROP_LIBRARY_DEPENDENCIES></INTEROP_LIBRARY_DEPENDENCIES>
    20     20       <INTEROP_DEBUG_DEFINES>INTEROP_DEBUG=0x31F;INTEROP_LOG=1;INTEROP_TEST_EXTENSION=1</INTEROP_DEBUG_DEFINES>
    21     21       <INTEROP_EXTRA_DEFINES>INTEROP_PLACEHOLDER=1;INTEROP_EXTENSION_FUNCTIONS=1;INTEROP_CODEC=1;INTEROP_VIRTUAL_TABLE=1;INTEROP_FTS5_EXTENSION=1;INTEROP_PERCENTILE_EXTENSION=1;INTEROP_TOTYPE_EXTENSION=1;INTEROP_REGEXP_EXTENSION=1;INTEROP_JSON1_EXTENSION=1;INTEROP_SHA1_EXTENSION=1</INTEROP_EXTRA_DEFINES>
    22     22       <INTEROP_ASSEMBLY_RESOURCES>/ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteCommand.bmp,System.Data.SQLite.SQLiteCommand.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteConnection.bmp,System.Data.SQLite.SQLiteConnection.bmp /ASSEMBLYRESOURCE:..\System.Data.SQLite\Resources\SQLiteDataAdapter.bmp,System.Data.SQLite.SQLiteDataAdapter.bmp</INTEROP_ASSEMBLY_RESOURCES>
    23     23       <INTEROP_KEY_FILE>$(ProjectDir)..\Keys\System.Data.SQLite.snk</INTEROP_KEY_FILE>

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

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

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

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

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

     1      1   /******************************************************************************
     2      2   ** This file is an amalgamation of many separate C source files from SQLite
     3         -** version 3.18.0.  By combining all the individual C code files into this
            3  +** version 3.19.3.  By combining all the individual C code files into this
     4      4   ** single large file, the entire code can be compiled as a single translation
     5      5   ** unit.  This allows many compilers to do optimizations that would not be
     6      6   ** possible if the files were compiled separately.  Performance improvements
     7      7   ** of 5% or more are commonly seen when SQLite is compiled as a single
     8      8   ** translation unit.
     9      9   **
    10     10   ** This file is all you need to compile SQLite.  To use SQLite in other
................................................................................
   394    394   ** string contains the date and time of the check-in (UTC) and a SHA1
   395    395   ** or SHA3-256 hash of the entire source tree.
   396    396   **
   397    397   ** See also: [sqlite3_libversion()],
   398    398   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   399    399   ** [sqlite_version()] and [sqlite_source_id()].
   400    400   */
   401         -#define SQLITE_VERSION        "3.18.0"
   402         -#define SQLITE_VERSION_NUMBER 3018000
   403         -#define SQLITE_SOURCE_ID      "2017-03-28 18:48:43 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37"
          401  +#define SQLITE_VERSION        "3.19.3"
          402  +#define SQLITE_VERSION_NUMBER 3019003
          403  +#define SQLITE_SOURCE_ID      "2017-06-08 14:26:16 0ee482a1e0eae22e08edc8978c9733a96603d4509645f348ebf55b579e89636b"
   404    404   
   405    405   /*
   406    406   ** CAPI3REF: Run-Time Library Version Numbers
   407    407   ** KEYWORDS: sqlite3_version sqlite3_sourceid
   408    408   **
   409    409   ** These interfaces provide the same information as the [SQLITE_VERSION],
   410    410   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
  1130   1130   ** anti-virus programs.  By default, the windows VFS will retry file read,
  1131   1131   ** file write, and file delete operations up to 10 times, with a delay
  1132   1132   ** of 25 milliseconds before the first retry and with the delay increasing
  1133   1133   ** by an additional 25 milliseconds with each subsequent retry.  This
  1134   1134   ** opcode allows these two values (10 retries and 25 milliseconds of delay)
  1135   1135   ** to be adjusted.  The values are changed for all database connections
  1136   1136   ** within the same process.  The argument is a pointer to an array of two
  1137         -** integers where the first integer i the new retry count and the second
         1137  +** integers where the first integer is the new retry count and the second
  1138   1138   ** integer is the delay.  If either integer is negative, then the setting
  1139   1139   ** is not changed but instead the prior value of that setting is written
  1140   1140   ** into the array entry, allowing the current retry settings to be
  1141   1141   ** interrogated.  The zDbName parameter is ignored.
  1142   1142   **
  1143   1143   ** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
  1144   1144   ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
................................................................................
  2484   2484   ** running statements reaches zero are interrupted as if they had been
  2485   2485   ** running prior to the sqlite3_interrupt() call.  ^New SQL statements
  2486   2486   ** that are started after the running statement count reaches zero are
  2487   2487   ** not effected by the sqlite3_interrupt().
  2488   2488   ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
  2489   2489   ** SQL statements is a no-op and has no effect on SQL statements
  2490   2490   ** that are started after the sqlite3_interrupt() call returns.
  2491         -**
  2492         -** If the database connection closes while [sqlite3_interrupt()]
  2493         -** is running then bad things will likely happen.
  2494   2491   */
  2495   2492   SQLITE_API void sqlite3_interrupt(sqlite3*);
  2496   2493   
  2497   2494   /*
  2498   2495   ** CAPI3REF: Determine If An SQL Statement Is Complete
  2499   2496   **
  2500   2497   ** These routines are useful during command-line input to determine if the
................................................................................
  2949   2946   ** method.
  2950   2947   */
  2951   2948   SQLITE_API void sqlite3_randomness(int N, void *P);
  2952   2949   
  2953   2950   /*
  2954   2951   ** CAPI3REF: Compile-Time Authorization Callbacks
  2955   2952   ** METHOD: sqlite3
         2953  +** KEYWORDS: {authorizer callback}
  2956   2954   **
  2957   2955   ** ^This routine registers an authorizer callback with a particular
  2958   2956   ** [database connection], supplied in the first argument.
  2959   2957   ** ^The authorizer callback is invoked as SQL statements are being compiled
  2960   2958   ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
  2961   2959   ** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()].  ^At various
  2962   2960   ** points during the compilation process, as logic is being created
................................................................................
  2976   2974   ** authorizer will fail with an error message explaining that
  2977   2975   ** access is denied. 
  2978   2976   **
  2979   2977   ** ^The first parameter to the authorizer callback is a copy of the third
  2980   2978   ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
  2981   2979   ** to the callback is an integer [SQLITE_COPY | action code] that specifies
  2982   2980   ** the particular action to be authorized. ^The third through sixth parameters
  2983         -** to the callback are zero-terminated strings that contain additional
  2984         -** details about the action to be authorized.
         2981  +** to the callback are either NULL pointers or zero-terminated strings
         2982  +** that contain additional details about the action to be authorized.
         2983  +** Applications must always be prepared to encounter a NULL pointer in any
         2984  +** of the third through the sixth parameters of the authorization callback.
  2985   2985   **
  2986   2986   ** ^If the action code is [SQLITE_READ]
  2987   2987   ** and the callback returns [SQLITE_IGNORE] then the
  2988   2988   ** [prepared statement] statement is constructed to substitute
  2989   2989   ** a NULL value in place of the table column that would have
  2990   2990   ** been read if [SQLITE_OK] had been returned.  The [SQLITE_IGNORE]
  2991   2991   ** return can be used to deny an untrusted user access to individual
  2992   2992   ** columns of a table.
         2993  +** ^When a table is referenced by a [SELECT] but no column values are
         2994  +** extracted from that table (for example in a query like
         2995  +** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
         2996  +** is invoked once for that table with a column name that is an empty string.
  2993   2997   ** ^If the action code is [SQLITE_DELETE] and the callback returns
  2994   2998   ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
  2995   2999   ** [truncate optimization] is disabled and all rows are deleted individually.
  2996   3000   **
  2997   3001   ** An authorizer is used when [sqlite3_prepare | preparing]
  2998   3002   ** SQL statements from an untrusted source, to ensure that the SQL statements
  2999   3003   ** do not try to access data they are not allowed to see, or that they do not
................................................................................
  3978   3982   ** ^The sqlite3_value object returned by
  3979   3983   ** [sqlite3_column_value()] is unprotected.
  3980   3984   ** Unprotected sqlite3_value objects may only be used with
  3981   3985   ** [sqlite3_result_value()] and [sqlite3_bind_value()].
  3982   3986   ** The [sqlite3_value_blob | sqlite3_value_type()] family of
  3983   3987   ** interfaces require protected sqlite3_value objects.
  3984   3988   */
  3985         -typedef struct Mem sqlite3_value;
         3989  +typedef struct sqlite3_value sqlite3_value;
  3986   3990   
  3987   3991   /*
  3988   3992   ** CAPI3REF: SQL Function Context Object
  3989   3993   **
  3990   3994   ** The context in which an SQL function executes is stored in an
  3991   3995   ** sqlite3_context object.  ^A pointer to an sqlite3_context object
  3992   3996   ** is always first parameter to [application-defined SQL functions].
................................................................................
  5032   5036   ** of where this might be useful is in a regular-expression matching
  5033   5037   ** function. The compiled version of the regular expression can be stored as
  5034   5038   ** metadata associated with the pattern string.  
  5035   5039   ** Then as long as the pattern string remains the same,
  5036   5040   ** the compiled regular expression can be reused on multiple
  5037   5041   ** invocations of the same function.
  5038   5042   **
  5039         -** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
  5040         -** associated by the sqlite3_set_auxdata() function with the Nth argument
  5041         -** value to the application-defined function. ^If there is no metadata
  5042         -** associated with the function argument, this sqlite3_get_auxdata() interface
         5043  +** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata
         5044  +** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument
         5045  +** value to the application-defined function.  ^N is zero for the left-most
         5046  +** function argument.  ^If there is no metadata
         5047  +** associated with the function argument, the sqlite3_get_auxdata(C,N) interface
  5043   5048   ** returns a NULL pointer.
  5044   5049   **
  5045   5050   ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
  5046   5051   ** argument of the application-defined function.  ^Subsequent
  5047   5052   ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
  5048   5053   ** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or
  5049   5054   ** NULL if the metadata has been discarded.
................................................................................
  5065   5070   ** should be called near the end of the function implementation and the
  5066   5071   ** function implementation should not make any use of P after
  5067   5072   ** sqlite3_set_auxdata() has been called.
  5068   5073   **
  5069   5074   ** ^(In practice, metadata is preserved between function calls for
  5070   5075   ** function parameters that are compile-time constants, including literal
  5071   5076   ** values and [parameters] and expressions composed from the same.)^
         5077  +**
         5078  +** The value of the N parameter to these interfaces should be non-negative.
         5079  +** Future enhancements may make use of negative N values to define new
         5080  +** kinds of function caching behavior.
  5072   5081   **
  5073   5082   ** These routines must be called from the same thread in which
  5074   5083   ** the SQL function is running.
  5075   5084   */
  5076   5085   SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
  5077   5086   SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
  5078   5087   
................................................................................
  9660   9669   ** Any number of calls to add() and output() may be made between the calls to
  9661   9670   ** new() and delete(), and in any order.
  9662   9671   **
  9663   9672   ** As well as the regular sqlite3changegroup_add() and 
  9664   9673   ** sqlite3changegroup_output() functions, also available are the streaming
  9665   9674   ** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
  9666   9675   */
  9667         -int sqlite3changegroup_new(sqlite3_changegroup **pp);
         9676  +SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp);
  9668   9677   
  9669   9678   /*
  9670   9679   ** CAPI3REF: Add A Changeset To A Changegroup
  9671   9680   **
  9672   9681   ** Add all changes within the changeset (or patchset) in buffer pData (size
  9673   9682   ** nData bytes) to the changegroup. 
  9674   9683   **
................................................................................
  9737   9746   ** appears to be corrupt and the corruption is detected, SQLITE_CORRUPT is
  9738   9747   ** returned. Or, if an out-of-memory condition occurs during processing, this
  9739   9748   ** function returns SQLITE_NOMEM. In all cases, if an error occurs the
  9740   9749   ** final contents of the changegroup is undefined.
  9741   9750   **
  9742   9751   ** If no error occurs, SQLITE_OK is returned.
  9743   9752   */
  9744         -int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
         9753  +SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
  9745   9754   
  9746   9755   /*
  9747   9756   ** CAPI3REF: Obtain A Composite Changeset From A Changegroup
  9748   9757   **
  9749   9758   ** Obtain a buffer containing a changeset (or patchset) representing the
  9750   9759   ** current contents of the changegroup. If the inputs to the changegroup
  9751   9760   ** were themselves changesets, the output is a changeset. Or, if the
................................................................................
  9763   9772   ** If an error occurs, an SQLite error code is returned and the output
  9764   9773   ** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK
  9765   9774   ** is returned and the output variables are set to the size of and a 
  9766   9775   ** pointer to the output buffer, respectively. In this case it is the
  9767   9776   ** responsibility of the caller to eventually free the buffer using a
  9768   9777   ** call to sqlite3_free().
  9769   9778   */
  9770         -int sqlite3changegroup_output(
         9779  +SQLITE_API int sqlite3changegroup_output(
  9771   9780     sqlite3_changegroup*,
  9772   9781     int *pnData,                    /* OUT: Size of output buffer in bytes */
  9773   9782     void **ppData                   /* OUT: Pointer to output buffer */
  9774   9783   );
  9775   9784   
  9776   9785   /*
  9777   9786   ** CAPI3REF: Delete A Changegroup Object
  9778   9787   */
  9779         -void sqlite3changegroup_delete(sqlite3_changegroup*);
         9788  +SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*);
  9780   9789   
  9781   9790   /*
  9782   9791   ** CAPI3REF: Apply A Changeset To A Database
  9783   9792   **
  9784   9793   ** Apply a changeset to a database. This function attempts to update the
  9785   9794   ** "main" database attached to handle db with the changes found in the
  9786   9795   ** changeset passed via the second and third arguments.
................................................................................
 10161  10170     void *pOut
 10162  10171   );
 10163  10172   SQLITE_API int sqlite3session_patchset_strm(
 10164  10173     sqlite3_session *pSession,
 10165  10174     int (*xOutput)(void *pOut, const void *pData, int nData),
 10166  10175     void *pOut
 10167  10176   );
 10168         -int sqlite3changegroup_add_strm(sqlite3_changegroup*, 
        10177  +SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup*, 
 10169  10178       int (*xInput)(void *pIn, void *pData, int *pnData),
 10170  10179       void *pIn
 10171  10180   );
 10172         -int sqlite3changegroup_output_strm(sqlite3_changegroup*,
        10181  +SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*,
 10173  10182       int (*xOutput)(void *pOut, const void *pData, int nData), 
 10174  10183       void *pOut
 10175  10184   );
 10176  10185   
 10177  10186   
 10178  10187   /*
 10179  10188   ** Make sure we can call this stuff from C++.
................................................................................
 11449  11458   #define TK_EXISTS                          20
 11450  11459   #define TK_TEMP                            21
 11451  11460   #define TK_LP                              22
 11452  11461   #define TK_RP                              23
 11453  11462   #define TK_AS                              24
 11454  11463   #define TK_WITHOUT                         25
 11455  11464   #define TK_COMMA                           26
 11456         -#define TK_OR                              27
 11457         -#define TK_AND                             28
 11458         -#define TK_IS                              29
 11459         -#define TK_MATCH                           30
 11460         -#define TK_LIKE_KW                         31
 11461         -#define TK_BETWEEN                         32
 11462         -#define TK_IN                              33
 11463         -#define TK_ISNULL                          34
 11464         -#define TK_NOTNULL                         35
 11465         -#define TK_NE                              36
 11466         -#define TK_EQ                              37
 11467         -#define TK_GT                              38
 11468         -#define TK_LE                              39
 11469         -#define TK_LT                              40
 11470         -#define TK_GE                              41
 11471         -#define TK_ESCAPE                          42
 11472         -#define TK_BITAND                          43
 11473         -#define TK_BITOR                           44
 11474         -#define TK_LSHIFT                          45
 11475         -#define TK_RSHIFT                          46
 11476         -#define TK_PLUS                            47
 11477         -#define TK_MINUS                           48
 11478         -#define TK_STAR                            49
 11479         -#define TK_SLASH                           50
 11480         -#define TK_REM                             51
 11481         -#define TK_CONCAT                          52
 11482         -#define TK_COLLATE                         53
 11483         -#define TK_BITNOT                          54
 11484         -#define TK_ID                              55
 11485         -#define TK_INDEXED                         56
 11486         -#define TK_ABORT                           57
 11487         -#define TK_ACTION                          58
 11488         -#define TK_AFTER                           59
 11489         -#define TK_ANALYZE                         60
 11490         -#define TK_ASC                             61
 11491         -#define TK_ATTACH                          62
 11492         -#define TK_BEFORE                          63
 11493         -#define TK_BY                              64
 11494         -#define TK_CASCADE                         65
 11495         -#define TK_CAST                            66
 11496         -#define TK_COLUMNKW                        67
 11497         -#define TK_CONFLICT                        68
 11498         -#define TK_DATABASE                        69
 11499         -#define TK_DESC                            70
 11500         -#define TK_DETACH                          71
 11501         -#define TK_EACH                            72
 11502         -#define TK_FAIL                            73
 11503         -#define TK_FOR                             74
 11504         -#define TK_IGNORE                          75
 11505         -#define TK_INITIALLY                       76
 11506         -#define TK_INSTEAD                         77
 11507         -#define TK_NO                              78
 11508         -#define TK_KEY                             79
 11509         -#define TK_OF                              80
 11510         -#define TK_OFFSET                          81
 11511         -#define TK_PRAGMA                          82
 11512         -#define TK_RAISE                           83
 11513         -#define TK_RECURSIVE                       84
 11514         -#define TK_REPLACE                         85
 11515         -#define TK_RESTRICT                        86
 11516         -#define TK_ROW                             87
 11517         -#define TK_TRIGGER                         88
 11518         -#define TK_VACUUM                          89
 11519         -#define TK_VIEW                            90
 11520         -#define TK_VIRTUAL                         91
 11521         -#define TK_WITH                            92
 11522         -#define TK_REINDEX                         93
 11523         -#define TK_RENAME                          94
 11524         -#define TK_CTIME_KW                        95
 11525         -#define TK_ANY                             96
        11465  +#define TK_ID                              27
        11466  +#define TK_ABORT                           28
        11467  +#define TK_ACTION                          29
        11468  +#define TK_AFTER                           30
        11469  +#define TK_ANALYZE                         31
        11470  +#define TK_ASC                             32
        11471  +#define TK_ATTACH                          33
        11472  +#define TK_BEFORE                          34
        11473  +#define TK_BY                              35
        11474  +#define TK_CASCADE                         36
        11475  +#define TK_CAST                            37
        11476  +#define TK_COLUMNKW                        38
        11477  +#define TK_CONFLICT                        39
        11478  +#define TK_DATABASE                        40
        11479  +#define TK_DESC                            41
        11480  +#define TK_DETACH                          42
        11481  +#define TK_EACH                            43
        11482  +#define TK_FAIL                            44
        11483  +#define TK_FOR                             45
        11484  +#define TK_IGNORE                          46
        11485  +#define TK_INITIALLY                       47
        11486  +#define TK_INSTEAD                         48
        11487  +#define TK_LIKE_KW                         49
        11488  +#define TK_MATCH                           50
        11489  +#define TK_NO                              51
        11490  +#define TK_KEY                             52
        11491  +#define TK_OF                              53
        11492  +#define TK_OFFSET                          54
        11493  +#define TK_PRAGMA                          55
        11494  +#define TK_RAISE                           56
        11495  +#define TK_RECURSIVE                       57
        11496  +#define TK_REPLACE                         58
        11497  +#define TK_RESTRICT                        59
        11498  +#define TK_ROW                             60
        11499  +#define TK_TRIGGER                         61
        11500  +#define TK_VACUUM                          62
        11501  +#define TK_VIEW                            63
        11502  +#define TK_VIRTUAL                         64
        11503  +#define TK_WITH                            65
        11504  +#define TK_REINDEX                         66
        11505  +#define TK_RENAME                          67
        11506  +#define TK_CTIME_KW                        68
        11507  +#define TK_ANY                             69
        11508  +#define TK_OR                              70
        11509  +#define TK_AND                             71
        11510  +#define TK_IS                              72
        11511  +#define TK_BETWEEN                         73
        11512  +#define TK_IN                              74
        11513  +#define TK_ISNULL                          75
        11514  +#define TK_NOTNULL                         76
        11515  +#define TK_NE                              77
        11516  +#define TK_EQ                              78
        11517  +#define TK_GT                              79
        11518  +#define TK_LE                              80
        11519  +#define TK_LT                              81
        11520  +#define TK_GE                              82
        11521  +#define TK_ESCAPE                          83
        11522  +#define TK_BITAND                          84
        11523  +#define TK_BITOR                           85
        11524  +#define TK_LSHIFT                          86
        11525  +#define TK_RSHIFT                          87
        11526  +#define TK_PLUS                            88
        11527  +#define TK_MINUS                           89
        11528  +#define TK_STAR                            90
        11529  +#define TK_SLASH                           91
        11530  +#define TK_REM                             92
        11531  +#define TK_CONCAT                          93
        11532  +#define TK_COLLATE                         94
        11533  +#define TK_BITNOT                          95
        11534  +#define TK_INDEXED                         96
 11526  11535   #define TK_STRING                          97
 11527  11536   #define TK_JOIN_KW                         98
 11528  11537   #define TK_CONSTRAINT                      99
 11529  11538   #define TK_DEFAULT                        100
 11530  11539   #define TK_NULL                           101
 11531  11540   #define TK_PRIMARY                        102
 11532  11541   #define TK_UNIQUE                         103
................................................................................
 11582  11591   #define TK_AGG_FUNCTION                   153
 11583  11592   #define TK_AGG_COLUMN                     154
 11584  11593   #define TK_UMINUS                         155
 11585  11594   #define TK_UPLUS                          156
 11586  11595   #define TK_REGISTER                       157
 11587  11596   #define TK_VECTOR                         158
 11588  11597   #define TK_SELECT_COLUMN                  159
 11589         -#define TK_ASTERISK                       160
 11590         -#define TK_SPAN                           161
 11591         -#define TK_SPACE                          162
 11592         -#define TK_ILLEGAL                        163
        11598  +#define TK_IF_NULL_ROW                    160
        11599  +#define TK_ASTERISK                       161
        11600  +#define TK_SPAN                           162
        11601  +#define TK_SPACE                          163
        11602  +#define TK_ILLEGAL                        164
 11593  11603   
 11594  11604   /* The token codes above must all fit in 8 bits */
 11595  11605   #define TKFLG_MASK           0xff  
 11596  11606   
 11597  11607   /* Flags that can be added to a token code when it is not
 11598  11608   ** being stored in a u8: */
 11599  11609   #define TKFLG_DONTFOLD       0x100  /* Omit constant folding optimizations */
................................................................................
 12456  12466   ** organized and understandable, and it also helps the resulting code to
 12457  12467   ** run a little faster by using fewer registers for parameter passing.
 12458  12468   */
 12459  12469   struct BtreePayload {
 12460  12470     const void *pKey;       /* Key content for indexes.  NULL for tables */
 12461  12471     sqlite3_int64 nKey;     /* Size of pKey for indexes.  PRIMARY KEY for tabs */
 12462  12472     const void *pData;      /* Data for tables.  NULL for indexes */
 12463         -  struct Mem *aMem;       /* First of nMem value in the unpacked pKey */
        12473  +  sqlite3_value *aMem;    /* First of nMem value in the unpacked pKey */
 12464  12474     u16 nMem;               /* Number of aMem[] value.  Might be zero */
 12465  12475     int nData;              /* Size of pData.  0 if none. */
 12466  12476     int nZero;              /* Extra zero data appended after pData,nData */
 12467  12477   };
 12468  12478   
 12469  12479   SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
 12470  12480                          int flags, int seekResult);
................................................................................
 12586  12596   */
 12587  12597   typedef struct Vdbe Vdbe;
 12588  12598   
 12589  12599   /*
 12590  12600   ** The names of the following types declared in vdbeInt.h are required
 12591  12601   ** for the VdbeOp definition.
 12592  12602   */
 12593         -typedef struct Mem Mem;
        12603  +typedef struct sqlite3_value Mem;
 12594  12604   typedef struct SubProgram SubProgram;
 12595  12605   
 12596  12606   /*
 12597  12607   ** A single instruction of the virtual machine has an opcode
 12598  12608   ** and as many as three operands.  The instruction is recorded
 12599  12609   ** as an instance of the following structure:
 12600  12610   */
................................................................................
 12746  12756   #define OP_Yield          16
 12747  12757   #define OP_MustBeInt      17
 12748  12758   #define OP_Jump           18
 12749  12759   #define OP_Not            19 /* same as TK_NOT, synopsis: r[P2]= !r[P1]    */
 12750  12760   #define OP_Once           20
 12751  12761   #define OP_If             21
 12752  12762   #define OP_IfNot          22
 12753         -#define OP_SeekLT         23 /* synopsis: key=r[P3@P4]                     */
 12754         -#define OP_SeekLE         24 /* synopsis: key=r[P3@P4]                     */
 12755         -#define OP_SeekGE         25 /* synopsis: key=r[P3@P4]                     */
 12756         -#define OP_SeekGT         26 /* synopsis: key=r[P3@P4]                     */
 12757         -#define OP_Or             27 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
 12758         -#define OP_And            28 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
 12759         -#define OP_NoConflict     29 /* synopsis: key=r[P3@P4]                     */
 12760         -#define OP_NotFound       30 /* synopsis: key=r[P3@P4]                     */
 12761         -#define OP_Found          31 /* synopsis: key=r[P3@P4]                     */
 12762         -#define OP_SeekRowid      32 /* synopsis: intkey=r[P3]                     */
 12763         -#define OP_NotExists      33 /* synopsis: intkey=r[P3]                     */
 12764         -#define OP_IsNull         34 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
 12765         -#define OP_NotNull        35 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
 12766         -#define OP_Ne             36 /* same as TK_NE, synopsis: IF r[P3]!=r[P1]   */
 12767         -#define OP_Eq             37 /* same as TK_EQ, synopsis: IF r[P3]==r[P1]   */
 12768         -#define OP_Gt             38 /* same as TK_GT, synopsis: IF r[P3]>r[P1]    */
 12769         -#define OP_Le             39 /* same as TK_LE, synopsis: IF r[P3]<=r[P1]   */
 12770         -#define OP_Lt             40 /* same as TK_LT, synopsis: IF r[P3]<r[P1]    */
 12771         -#define OP_Ge             41 /* same as TK_GE, synopsis: IF r[P3]>=r[P1]   */
 12772         -#define OP_ElseNotEq      42 /* same as TK_ESCAPE                          */
 12773         -#define OP_BitAnd         43 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
 12774         -#define OP_BitOr          44 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
 12775         -#define OP_ShiftLeft      45 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
 12776         -#define OP_ShiftRight     46 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
 12777         -#define OP_Add            47 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
 12778         -#define OP_Subtract       48 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
 12779         -#define OP_Multiply       49 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
 12780         -#define OP_Divide         50 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
 12781         -#define OP_Remainder      51 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
 12782         -#define OP_Concat         52 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
 12783         -#define OP_Last           53
 12784         -#define OP_BitNot         54 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
 12785         -#define OP_IfSmaller      55
 12786         -#define OP_SorterSort     56
 12787         -#define OP_Sort           57
 12788         -#define OP_Rewind         58
 12789         -#define OP_IdxLE          59 /* synopsis: key=r[P3@P4]                     */
 12790         -#define OP_IdxGT          60 /* synopsis: key=r[P3@P4]                     */
 12791         -#define OP_IdxLT          61 /* synopsis: key=r[P3@P4]                     */
 12792         -#define OP_IdxGE          62 /* synopsis: key=r[P3@P4]                     */
 12793         -#define OP_RowSetRead     63 /* synopsis: r[P3]=rowset(P1)                 */
 12794         -#define OP_RowSetTest     64 /* synopsis: if r[P3] in rowset(P1) goto P2   */
 12795         -#define OP_Program        65
 12796         -#define OP_FkIfZero       66 /* synopsis: if fkctr[P1]==0 goto P2          */
 12797         -#define OP_IfPos          67 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
 12798         -#define OP_IfNotZero      68 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
 12799         -#define OP_DecrJumpZero   69 /* synopsis: if (--r[P1])==0 goto P2          */
 12800         -#define OP_IncrVacuum     70
 12801         -#define OP_VNext          71
 12802         -#define OP_Init           72 /* synopsis: Start at P2                      */
 12803         -#define OP_Return         73
 12804         -#define OP_EndCoroutine   74
 12805         -#define OP_HaltIfNull     75 /* synopsis: if r[P3]=null halt               */
 12806         -#define OP_Halt           76
 12807         -#define OP_Integer        77 /* synopsis: r[P2]=P1                         */
 12808         -#define OP_Int64          78 /* synopsis: r[P2]=P4                         */
 12809         -#define OP_String         79 /* synopsis: r[P2]='P4' (len=P1)              */
 12810         -#define OP_Null           80 /* synopsis: r[P2..P3]=NULL                   */
 12811         -#define OP_SoftNull       81 /* synopsis: r[P1]=NULL                       */
 12812         -#define OP_Blob           82 /* synopsis: r[P2]=P4 (len=P1)                */
 12813         -#define OP_Variable       83 /* synopsis: r[P2]=parameter(P1,P4)           */
 12814         -#define OP_Move           84 /* synopsis: r[P2@P3]=r[P1@P3]                */
 12815         -#define OP_Copy           85 /* synopsis: r[P2@P3+1]=r[P1@P3+1]            */
 12816         -#define OP_SCopy          86 /* synopsis: r[P2]=r[P1]                      */
 12817         -#define OP_IntCopy        87 /* synopsis: r[P2]=r[P1]                      */
 12818         -#define OP_ResultRow      88 /* synopsis: output=r[P1@P2]                  */
 12819         -#define OP_CollSeq        89
 12820         -#define OP_Function0      90 /* synopsis: r[P3]=func(r[P2@P5])             */
 12821         -#define OP_Function       91 /* synopsis: r[P3]=func(r[P2@P5])             */
 12822         -#define OP_AddImm         92 /* synopsis: r[P1]=r[P1]+P2                   */
 12823         -#define OP_RealAffinity   93
        12763  +#define OP_IfNullRow      23 /* synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
        12764  +#define OP_SeekLT         24 /* synopsis: key=r[P3@P4]                     */
        12765  +#define OP_SeekLE         25 /* synopsis: key=r[P3@P4]                     */
        12766  +#define OP_SeekGE         26 /* synopsis: key=r[P3@P4]                     */
        12767  +#define OP_SeekGT         27 /* synopsis: key=r[P3@P4]                     */
        12768  +#define OP_NoConflict     28 /* synopsis: key=r[P3@P4]                     */
        12769  +#define OP_NotFound       29 /* synopsis: key=r[P3@P4]                     */
        12770  +#define OP_Found          30 /* synopsis: key=r[P3@P4]                     */
        12771  +#define OP_SeekRowid      31 /* synopsis: intkey=r[P3]                     */
        12772  +#define OP_NotExists      32 /* synopsis: intkey=r[P3]                     */
        12773  +#define OP_Last           33
        12774  +#define OP_IfSmaller      34
        12775  +#define OP_SorterSort     35
        12776  +#define OP_Sort           36
        12777  +#define OP_Rewind         37
        12778  +#define OP_IdxLE          38 /* synopsis: key=r[P3@P4]                     */
        12779  +#define OP_IdxGT          39 /* synopsis: key=r[P3@P4]                     */
        12780  +#define OP_IdxLT          40 /* synopsis: key=r[P3@P4]                     */
        12781  +#define OP_IdxGE          41 /* synopsis: key=r[P3@P4]                     */
        12782  +#define OP_RowSetRead     42 /* synopsis: r[P3]=rowset(P1)                 */
        12783  +#define OP_RowSetTest     43 /* synopsis: if r[P3] in rowset(P1) goto P2   */
        12784  +#define OP_Program        44
        12785  +#define OP_FkIfZero       45 /* synopsis: if fkctr[P1]==0 goto P2          */
        12786  +#define OP_IfPos          46 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
        12787  +#define OP_IfNotZero      47 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
        12788  +#define OP_DecrJumpZero   48 /* synopsis: if (--r[P1])==0 goto P2          */
        12789  +#define OP_IncrVacuum     49
        12790  +#define OP_VNext          50
        12791  +#define OP_Init           51 /* synopsis: Start at P2                      */
        12792  +#define OP_Return         52
        12793  +#define OP_EndCoroutine   53
        12794  +#define OP_HaltIfNull     54 /* synopsis: if r[P3]=null halt               */
        12795  +#define OP_Halt           55
        12796  +#define OP_Integer        56 /* synopsis: r[P2]=P1                         */
        12797  +#define OP_Int64          57 /* synopsis: r[P2]=P4                         */
        12798  +#define OP_String         58 /* synopsis: r[P2]='P4' (len=P1)              */
        12799  +#define OP_Null           59 /* synopsis: r[P2..P3]=NULL                   */
        12800  +#define OP_SoftNull       60 /* synopsis: r[P1]=NULL                       */
        12801  +#define OP_Blob           61 /* synopsis: r[P2]=P4 (len=P1)                */
        12802  +#define OP_Variable       62 /* synopsis: r[P2]=parameter(P1,P4)           */
        12803  +#define OP_Move           63 /* synopsis: r[P2@P3]=r[P1@P3]                */
        12804  +#define OP_Copy           64 /* synopsis: r[P2@P3+1]=r[P1@P3+1]            */
        12805  +#define OP_SCopy          65 /* synopsis: r[P2]=r[P1]                      */
        12806  +#define OP_IntCopy        66 /* synopsis: r[P2]=r[P1]                      */
        12807  +#define OP_ResultRow      67 /* synopsis: output=r[P1@P2]                  */
        12808  +#define OP_CollSeq        68
        12809  +#define OP_Function0      69 /* synopsis: r[P3]=func(r[P2@P5])             */
        12810  +#define OP_Or             70 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
        12811  +#define OP_And            71 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
        12812  +#define OP_Function       72 /* synopsis: r[P3]=func(r[P2@P5])             */
        12813  +#define OP_AddImm         73 /* synopsis: r[P1]=r[P1]+P2                   */
        12814  +#define OP_RealAffinity   74
        12815  +#define OP_IsNull         75 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
        12816  +#define OP_NotNull        76 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
        12817  +#define OP_Ne             77 /* same as TK_NE, synopsis: IF r[P3]!=r[P1]   */
        12818  +#define OP_Eq             78 /* same as TK_EQ, synopsis: IF r[P3]==r[P1]   */
        12819  +#define OP_Gt             79 /* same as TK_GT, synopsis: IF r[P3]>r[P1]    */
        12820  +#define OP_Le             80 /* same as TK_LE, synopsis: IF r[P3]<=r[P1]   */
        12821  +#define OP_Lt             81 /* same as TK_LT, synopsis: IF r[P3]<r[P1]    */
        12822  +#define OP_Ge             82 /* same as TK_GE, synopsis: IF r[P3]>=r[P1]   */
        12823  +#define OP_ElseNotEq      83 /* same as TK_ESCAPE                          */
        12824  +#define OP_BitAnd         84 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
        12825  +#define OP_BitOr          85 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
        12826  +#define OP_ShiftLeft      86 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
        12827  +#define OP_ShiftRight     87 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
        12828  +#define OP_Add            88 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
        12829  +#define OP_Subtract       89 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
        12830  +#define OP_Multiply       90 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
        12831  +#define OP_Divide         91 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
        12832  +#define OP_Remainder      92 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
        12833  +#define OP_Concat         93 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
 12824  12834   #define OP_Cast           94 /* synopsis: affinity(r[P1])                  */
 12825         -#define OP_Permutation    95
 12826         -#define OP_Compare        96 /* synopsis: r[P1@P3] <-> r[P2@P3]            */
        12835  +#define OP_BitNot         95 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
        12836  +#define OP_Permutation    96
 12827  12837   #define OP_String8        97 /* same as TK_STRING, synopsis: r[P2]='P4'    */
 12828         -#define OP_Column         98 /* synopsis: r[P3]=PX                         */
 12829         -#define OP_Affinity       99 /* synopsis: affinity(r[P1@P2])               */
 12830         -#define OP_MakeRecord    100 /* synopsis: r[P3]=mkrec(r[P1@P2])            */
 12831         -#define OP_Count         101 /* synopsis: r[P2]=count()                    */
 12832         -#define OP_ReadCookie    102
 12833         -#define OP_SetCookie     103
 12834         -#define OP_ReopenIdx     104 /* synopsis: root=P2 iDb=P3                   */
 12835         -#define OP_OpenRead      105 /* synopsis: root=P2 iDb=P3                   */
 12836         -#define OP_OpenWrite     106 /* synopsis: root=P2 iDb=P3                   */
 12837         -#define OP_OpenAutoindex 107 /* synopsis: nColumn=P2                       */
 12838         -#define OP_OpenEphemeral 108 /* synopsis: nColumn=P2                       */
 12839         -#define OP_SorterOpen    109
 12840         -#define OP_SequenceTest  110 /* synopsis: if( cursor[P1].ctr++ ) pc = P2   */
 12841         -#define OP_OpenPseudo    111 /* synopsis: P3 columns in r[P2]              */
 12842         -#define OP_Close         112
 12843         -#define OP_ColumnsUsed   113
 12844         -#define OP_Sequence      114 /* synopsis: r[P2]=cursor[P1].ctr++           */
 12845         -#define OP_NewRowid      115 /* synopsis: r[P2]=rowid                      */
 12846         -#define OP_Insert        116 /* synopsis: intkey=r[P3] data=r[P2]          */
 12847         -#define OP_InsertInt     117 /* synopsis: intkey=P3 data=r[P2]             */
 12848         -#define OP_Delete        118
 12849         -#define OP_ResetCount    119
 12850         -#define OP_SorterCompare 120 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
 12851         -#define OP_SorterData    121 /* synopsis: r[P2]=data                       */
 12852         -#define OP_RowData       122 /* synopsis: r[P2]=data                       */
 12853         -#define OP_Rowid         123 /* synopsis: r[P2]=rowid                      */
 12854         -#define OP_NullRow       124
 12855         -#define OP_SorterInsert  125 /* synopsis: key=r[P2]                        */
 12856         -#define OP_IdxInsert     126 /* synopsis: key=r[P2]                        */
 12857         -#define OP_IdxDelete     127 /* synopsis: key=r[P2@P3]                     */
 12858         -#define OP_Seek          128 /* synopsis: Move P3 to P1.rowid              */
 12859         -#define OP_IdxRowid      129 /* synopsis: r[P2]=rowid                      */
 12860         -#define OP_Destroy       130
 12861         -#define OP_Clear         131
        12838  +#define OP_Compare        98 /* synopsis: r[P1@P3] <-> r[P2@P3]            */
        12839  +#define OP_Column         99 /* synopsis: r[P3]=PX                         */
        12840  +#define OP_Affinity      100 /* synopsis: affinity(r[P1@P2])               */
        12841  +#define OP_MakeRecord    101 /* synopsis: r[P3]=mkrec(r[P1@P2])            */
        12842  +#define OP_Count         102 /* synopsis: r[P2]=count()                    */
        12843  +#define OP_ReadCookie    103
        12844  +#define OP_SetCookie     104
        12845  +#define OP_ReopenIdx     105 /* synopsis: root=P2 iDb=P3                   */
        12846  +#define OP_OpenRead      106 /* synopsis: root=P2 iDb=P3                   */
        12847  +#define OP_OpenWrite     107 /* synopsis: root=P2 iDb=P3                   */
        12848  +#define OP_OpenDup       108
        12849  +#define OP_OpenAutoindex 109 /* synopsis: nColumn=P2                       */
        12850  +#define OP_OpenEphemeral 110 /* synopsis: nColumn=P2                       */
        12851  +#define OP_SorterOpen    111
        12852  +#define OP_SequenceTest  112 /* synopsis: if( cursor[P1].ctr++ ) pc = P2   */
        12853  +#define OP_OpenPseudo    113 /* synopsis: P3 columns in r[P2]              */
        12854  +#define OP_Close         114
        12855  +#define OP_ColumnsUsed   115
        12856  +#define OP_Sequence      116 /* synopsis: r[P2]=cursor[P1].ctr++           */
        12857  +#define OP_NewRowid      117 /* synopsis: r[P2]=rowid                      */
        12858  +#define OP_Insert        118 /* synopsis: intkey=r[P3] data=r[P2]          */
        12859  +#define OP_InsertInt     119 /* synopsis: intkey=P3 data=r[P2]             */
        12860  +#define OP_Delete        120
        12861  +#define OP_ResetCount    121
        12862  +#define OP_SorterCompare 122 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
        12863  +#define OP_SorterData    123 /* synopsis: r[P2]=data                       */
        12864  +#define OP_RowData       124 /* synopsis: r[P2]=data                       */
        12865  +#define OP_Rowid         125 /* synopsis: r[P2]=rowid                      */
        12866  +#define OP_NullRow       126
        12867  +#define OP_SorterInsert  127 /* synopsis: key=r[P2]                        */
        12868  +#define OP_IdxInsert     128 /* synopsis: key=r[P2]                        */
        12869  +#define OP_IdxDelete     129 /* synopsis: key=r[P2@P3]                     */
        12870  +#define OP_Seek          130 /* synopsis: Move P3 to P1.rowid              */
        12871  +#define OP_IdxRowid      131 /* synopsis: r[P2]=rowid                      */
 12862  12872   #define OP_Real          132 /* same as TK_FLOAT, synopsis: r[P2]=P4       */
 12863         -#define OP_ResetSorter   133
 12864         -#define OP_CreateIndex   134 /* synopsis: r[P2]=root iDb=P1                */
 12865         -#define OP_CreateTable   135 /* synopsis: r[P2]=root iDb=P1                */
 12866         -#define OP_SqlExec       136
 12867         -#define OP_ParseSchema   137
 12868         -#define OP_LoadAnalysis  138
 12869         -#define OP_DropTable     139
 12870         -#define OP_DropIndex     140
 12871         -#define OP_DropTrigger   141
 12872         -#define OP_IntegrityCk   142
 12873         -#define OP_RowSetAdd     143 /* synopsis: rowset(P1)=r[P2]                 */
 12874         -#define OP_Param         144
 12875         -#define OP_FkCounter     145 /* synopsis: fkctr[P1]+=P2                    */
 12876         -#define OP_MemMax        146 /* synopsis: r[P1]=max(r[P1],r[P2])           */
 12877         -#define OP_OffsetLimit   147 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
 12878         -#define OP_AggStep0      148 /* synopsis: accum=r[P3] step(r[P2@P5])       */
 12879         -#define OP_AggStep       149 /* synopsis: accum=r[P3] step(r[P2@P5])       */
 12880         -#define OP_AggFinal      150 /* synopsis: accum=r[P1] N=P2                 */
 12881         -#define OP_Expire        151
 12882         -#define OP_TableLock     152 /* synopsis: iDb=P1 root=P2 write=P3          */
 12883         -#define OP_VBegin        153
 12884         -#define OP_VCreate       154
 12885         -#define OP_VDestroy      155
 12886         -#define OP_VOpen         156
 12887         -#define OP_VColumn       157 /* synopsis: r[P3]=vcolumn(P2)                */
 12888         -#define OP_VRename       158
 12889         -#define OP_Pagecount     159
 12890         -#define OP_MaxPgcnt      160
 12891         -#define OP_CursorHint    161
 12892         -#define OP_Noop          162
 12893         -#define OP_Explain       163
        12873  +#define OP_Destroy       133
        12874  +#define OP_Clear         134
        12875  +#define OP_ResetSorter   135
        12876  +#define OP_CreateIndex   136 /* synopsis: r[P2]=root iDb=P1                */
        12877  +#define OP_CreateTable   137 /* synopsis: r[P2]=root iDb=P1                */
        12878  +#define OP_SqlExec       138
        12879  +#define OP_ParseSchema   139
        12880  +#define OP_LoadAnalysis  140
        12881  +#define OP_DropTable     141
        12882  +#define OP_DropIndex     142
        12883  +#define OP_DropTrigger   143
        12884  +#define OP_IntegrityCk   144
        12885  +#define OP_RowSetAdd     145 /* synopsis: rowset(P1)=r[P2]                 */
        12886  +#define OP_Param         146
        12887  +#define OP_FkCounter     147 /* synopsis: fkctr[P1]+=P2                    */
        12888  +#define OP_MemMax        148 /* synopsis: r[P1]=max(r[P1],r[P2])           */
        12889  +#define OP_OffsetLimit   149 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
        12890  +#define OP_AggStep0      150 /* synopsis: accum=r[P3] step(r[P2@P5])       */
        12891  +#define OP_AggStep       151 /* synopsis: accum=r[P3] step(r[P2@P5])       */
        12892  +#define OP_AggFinal      152 /* synopsis: accum=r[P1] N=P2                 */
        12893  +#define OP_Expire        153
        12894  +#define OP_TableLock     154 /* synopsis: iDb=P1 root=P2 write=P3          */
        12895  +#define OP_VBegin        155
        12896  +#define OP_VCreate       156
        12897  +#define OP_VDestroy      157
        12898  +#define OP_VOpen         158
        12899  +#define OP_VColumn       159 /* synopsis: r[P3]=vcolumn(P2)                */
        12900  +#define OP_VRename       160
        12901  +#define OP_Pagecount     161
        12902  +#define OP_MaxPgcnt      162
        12903  +#define OP_CursorHint    163
        12904  +#define OP_Noop          164
        12905  +#define OP_Explain       165
 12894  12906   
 12895  12907   /* Properties such as "out2" or "jump" that are specified in
 12896  12908   ** comments following the "case" for each opcode in the vdbe.c
 12897  12909   ** are encoded into bitvectors as follows:
 12898  12910   */
 12899  12911   #define OPFLG_JUMP        0x01  /* jump:  P2 holds jmp target */
 12900  12912   #define OPFLG_IN1         0x02  /* in1:   P1 is an input */
................................................................................
 12901  12913   #define OPFLG_IN2         0x04  /* in2:   P2 is an input */
 12902  12914   #define OPFLG_IN3         0x08  /* in3:   P3 is an input */
 12903  12915   #define OPFLG_OUT2        0x10  /* out2:  P2 is an output */
 12904  12916   #define OPFLG_OUT3        0x20  /* out3:  P3 is an output */
 12905  12917   #define OPFLG_INITIALIZER {\
 12906  12918   /*   0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
 12907  12919   /*   8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\
 12908         -/*  16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x09,\
 12909         -/*  24 */ 0x09, 0x09, 0x09, 0x26, 0x26, 0x09, 0x09, 0x09,\
 12910         -/*  32 */ 0x09, 0x09, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
 12911         -/*  40 */ 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26, 0x26,\
 12912         -/*  48 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x01, 0x12, 0x01,\
 12913         -/*  56 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x23,\
 12914         -/*  64 */ 0x0b, 0x01, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01,\
 12915         -/*  72 */ 0x01, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10,\
 12916         -/*  80 */ 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10,\
 12917         -/*  88 */ 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00,\
 12918         -/*  96 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
        12920  +/*  16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x01,\
        12921  +/*  24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
        12922  +/*  32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
        12923  +/*  40 */ 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01, 0x03, 0x03,\
        12924  +/*  48 */ 0x03, 0x01, 0x01, 0x01, 0x02, 0x02, 0x08, 0x00,\
        12925  +/*  56 */ 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00,\
        12926  +/*  64 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x26, 0x26,\
        12927  +/*  72 */ 0x00, 0x02, 0x02, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
        12928  +/*  80 */ 0x0b, 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26,\
        12929  +/*  88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x02, 0x12,\
        12930  +/*  96 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
 12919  12931   /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
 12920         -/* 112 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
 12921         -/* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00,\
 12922         -/* 128 */ 0x00, 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10,\
 12923         -/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\
 12924         -/* 144 */ 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00,\
 12925         -/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
 12926         -/* 160 */ 0x10, 0x00, 0x00, 0x00,}
        12932  +/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
        12933  +/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x04,\
        12934  +/* 128 */ 0x04, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
        12935  +/* 136 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
        12936  +/* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00,\
        12937  +/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
        12938  +/* 160 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,}
 12927  12939   
 12928  12940   /* The sqlite3P2Values() routine is able to run faster if it knows
 12929  12941   ** the value of the largest JUMP opcode.  The smaller the maximum
 12930  12942   ** JUMP opcode the better, so the mkopcodeh.tcl script that
 12931  12943   ** generated this include file strives to group all JUMP opcodes
 12932  12944   ** together near the beginning of the list.
 12933  12945   */
 12934         -#define SQLITE_MX_JUMP_OPCODE  72  /* Maximum JUMP opcode */
        12946  +#define SQLITE_MX_JUMP_OPCODE  83  /* Maximum JUMP opcode */
 12935  12947   
 12936  12948   /************** End of opcodes.h *********************************************/
 12937  12949   /************** Continuing where we left off in vdbe.h ***********************/
 12938  12950   
 12939  12951   /*
 12940  12952   ** Prototypes for the VDBE interface.  See comments on the implementation
 12941  12953   ** for a description of what each of these routines does.
................................................................................
 15207  15219   ** column expression as it exists in a SELECT statement.  However, if
 15208  15220   ** the bSpanIsTab flag is set, then zSpan is overloaded to mean the name
 15209  15221   ** of the result column in the form: DATABASE.TABLE.COLUMN.  This later
 15210  15222   ** form is used for name resolution with nested FROM clauses.
 15211  15223   */
 15212  15224   struct ExprList {
 15213  15225     int nExpr;             /* Number of expressions on the list */
        15226  +  int nAlloc;            /* Number of a[] slots allocated */
 15214  15227     struct ExprList_item { /* For each expression in the list */
 15215  15228       Expr *pExpr;            /* The parse tree for this expression */
 15216  15229       char *zName;            /* Token associated with this expression */
 15217  15230       char *zSpan;            /* Original text of the expression */
 15218  15231       u8 sortOrder;           /* 1 for DESC or 0 for ASC */
 15219  15232       unsigned done :1;       /* A flag to indicate when processing is finished */
 15220  15233       unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
................................................................................
 15222  15235       union {
 15223  15236         struct {
 15224  15237           u16 iOrderByCol;      /* For ORDER BY, column number in result set */
 15225  15238           u16 iAlias;           /* Index into Parse.aAlias[] for zName */
 15226  15239         } x;
 15227  15240         int iConstExprReg;      /* Register in which Expr value is cached */
 15228  15241       } u;
 15229         -  } *a;                  /* Alloc a power of two greater or equal to nExpr */
        15242  +  } a[1];                  /* One slot for each expression in the list */
 15230  15243   };
 15231  15244   
 15232  15245   /*
 15233  15246   ** An instance of this structure is used by the parser to record both
 15234  15247   ** the parse tree for an expression and the span of input text for an
 15235  15248   ** expression.
 15236  15249   */
................................................................................
 16079  16092     Parse *pParse;                            /* Parser context.  */
 16080  16093     int (*xExprCallback)(Walker*, Expr*);     /* Callback for expressions */
 16081  16094     int (*xSelectCallback)(Walker*,Select*);  /* Callback for SELECTs */
 16082  16095     void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */
 16083  16096     int walkerDepth;                          /* Number of subqueries */
 16084  16097     u8 eCode;                                 /* A small processing code */
 16085  16098     union {                                   /* Extra data for callback */
 16086         -    NameContext *pNC;                          /* Naming context */
 16087         -    int n;                                     /* A counter */
 16088         -    int iCur;                                  /* A cursor number */
 16089         -    SrcList *pSrcList;                         /* FROM clause */
 16090         -    struct SrcCount *pSrcCount;                /* Counting column references */
 16091         -    struct CCurHint *pCCurHint;                /* Used by codeCursorHint() */
 16092         -    int *aiCol;                                /* array of column indexes */
 16093         -    struct IdxCover *pIdxCover;                /* Check for index coverage */
        16099  +    NameContext *pNC;                         /* Naming context */
        16100  +    int n;                                    /* A counter */
        16101  +    int iCur;                                 /* A cursor number */
        16102  +    SrcList *pSrcList;                        /* FROM clause */
        16103  +    struct SrcCount *pSrcCount;               /* Counting column references */
        16104  +    struct CCurHint *pCCurHint;               /* Used by codeCursorHint() */
        16105  +    int *aiCol;                               /* array of column indexes */
        16106  +    struct IdxCover *pIdxCover;               /* Check for index coverage */
        16107  +    struct IdxExprTrans *pIdxTrans;           /* Convert indexed expr to column */
        16108  +    ExprList *pGroupBy;                       /* GROUP BY clause */
        16109  +    struct HavingToWhereCtx *pHavingCtx;      /* HAVING to WHERE clause ctx */
 16094  16110     } u;
 16095  16111   };
 16096  16112   
 16097  16113   /* Forward declarations */
 16098  16114   SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*);
 16099  16115   SQLITE_PRIVATE int sqlite3WalkExprList(Walker*, ExprList*);
 16100  16116   SQLITE_PRIVATE int sqlite3WalkSelect(Walker*, Select*);
................................................................................
 16240  16256   SQLITE_PRIVATE void *sqlite3DbMallocRawNN(sqlite3*, u64);
 16241  16257   SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3*,const char*);
 16242  16258   SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, u64);
 16243  16259   SQLITE_PRIVATE void *sqlite3Realloc(void*, u64);
 16244  16260   SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
 16245  16261   SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
 16246  16262   SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
        16263  +SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
 16247  16264   SQLITE_PRIVATE int sqlite3MallocSize(void*);
 16248  16265   SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*);
 16249  16266   SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
 16250  16267   SQLITE_PRIVATE void sqlite3ScratchFree(void*);
 16251  16268   SQLITE_PRIVATE void *sqlite3PageMalloc(int);
 16252  16269   SQLITE_PRIVATE void sqlite3PageFree(void*);
 16253  16270   SQLITE_PRIVATE void sqlite3MemSetDefault(void);
................................................................................
 16555  16572   SQLITE_PRIVATE void sqlite3RollbackTransaction(Parse*);
 16556  16573   SQLITE_PRIVATE void sqlite3Savepoint(Parse*, int, Token*);
 16557  16574   SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
 16558  16575   SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
 16559  16576   SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
 16560  16577   SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
 16561  16578   SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
        16579  +SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
 16562  16580   SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
 16563  16581   #ifdef SQLITE_ENABLE_CURSOR_HINTS
 16564  16582   SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
 16565  16583   #endif
 16566  16584   SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
 16567  16585   SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
 16568  16586   SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
................................................................................
 17264  17282   **
 17265  17283   ** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled
 17266  17284   ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
 17267  17285   **
 17268  17286   ** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally
 17269  17287   ** disabled. The default value may be changed by compiling with the
 17270  17288   ** SQLITE_USE_URI symbol defined.
        17289  +**
        17290  +** URI filenames are enabled by default if SQLITE_HAS_CODEC is
        17291  +** enabled.
 17271  17292   */
 17272  17293   #ifndef SQLITE_USE_URI
 17273         -# define  SQLITE_USE_URI 0
        17294  +# ifdef SQLITE_HAS_CODEC
        17295  +#  define SQLITE_USE_URI 1
        17296  +# else
        17297  +#  define SQLITE_USE_URI 0
        17298  +# endif
 17274  17299   #endif
 17275  17300   
 17276  17301   /* EVIDENCE-OF: R-38720-18127 The default setting is determined by the
 17277  17302   ** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if
 17278  17303   ** that compile-time option is omitted.
 17279  17304   */
 17280  17305   #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
................................................................................
 18090  18115   #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
 18091  18116   
 18092  18117   /*
 18093  18118   ** Internally, the vdbe manipulates nearly all SQL values as Mem
 18094  18119   ** structures. Each Mem struct may cache multiple representations (string,
 18095  18120   ** integer etc.) of the same value.
 18096  18121   */
 18097         -struct Mem {
        18122  +struct sqlite3_value {
 18098  18123     union MemValue {
 18099  18124       double r;           /* Real value used when MEM_Real is set in flags */
 18100  18125       i64 i;              /* Integer value used when MEM_Int is set in flags */
 18101  18126       int nZero;          /* Used when bit MEM_Zero is set in flags */
 18102  18127       FuncDef *pDef;      /* Used only when flags==MEM_Agg */
 18103  18128       RowSet *pRowSet;    /* Used only when flags==MEM_RowSet */
 18104  18129       VdbeFrame *pFrame;  /* Used when flags==MEM_Frame */
................................................................................
 18192  18217   ** Each auxiliary data pointer stored by a user defined function 
 18193  18218   ** implementation calling sqlite3_set_auxdata() is stored in an instance
 18194  18219   ** of this structure. All such structures associated with a single VM
 18195  18220   ** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed
 18196  18221   ** when the VM is halted (if not before).
 18197  18222   */
 18198  18223   struct AuxData {
 18199         -  int iOp;                        /* Instruction number of OP_Function opcode */
 18200         -  int iArg;                       /* Index of function argument. */
        18224  +  int iAuxOp;                     /* Instruction number of OP_Function opcode */
        18225  +  int iAuxArg;                    /* Index of function argument. */
 18201  18226     void *pAux;                     /* Aux data pointer */
 18202         -  void (*xDelete)(void *);        /* Destructor for the aux data */
 18203         -  AuxData *pNext;                 /* Next element in list */
        18227  +  void (*xDeleteAux)(void*);      /* Destructor for the aux data */
        18228  +  AuxData *pNextAux;              /* Next element in list */
 18204  18229   };
 18205  18230   
 18206  18231   /*
 18207  18232   ** The "context" argument for an installable function.  A pointer to an
 18208  18233   ** instance of this structure is the first argument to the routines used
 18209  18234   ** implement the SQL functions.
 18210  18235   **
................................................................................
 19220  19245   static void computeYMD(DateTime *p){
 19221  19246     int Z, A, B, C, D, E, X1;
 19222  19247     if( p->validYMD ) return;
 19223  19248     if( !p->validJD ){
 19224  19249       p->Y = 2000;
 19225  19250       p->M = 1;
 19226  19251       p->D = 1;
        19252  +  }else if( !validJulianDay(p->iJD) ){
        19253  +    datetimeError(p);
        19254  +    return;
 19227  19255     }else{
 19228         -    assert( validJulianDay(p->iJD) );
 19229  19256       Z = (int)((p->iJD + 43200000)/86400000);
 19230  19257       A = (int)((Z - 1867216.25)/36524.25);
 19231  19258       A = Z + 1 + A - (A/4);
 19232  19259       B = A + 1524;
 19233  19260       C = (int)((B - 122.1)/365.25);
 19234  19261       D = (36525*(C&32767))/100;
 19235  19262       E = (int)((B-D)/30.6001);
................................................................................
 24657  24684   */
 24658  24685   static SQLITE_NOINLINE void measureAllocationSize(sqlite3 *db, void *p){
 24659  24686     *db->pnBytesFreed += sqlite3DbMallocSize(db,p);
 24660  24687   }
 24661  24688   
 24662  24689   /*
 24663  24690   ** Free memory that might be associated with a particular database
 24664         -** connection.
        24691  +** connection.  Calling sqlite3DbFree(D,X) for X==0 is a harmless no-op.
        24692  +** The sqlite3DbFreeNN(D,X) version requires that X be non-NULL.
 24665  24693   */
 24666         -SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
        24694  +SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3 *db, void *p){
 24667  24695     assert( db==0 || sqlite3_mutex_held(db->mutex) );
 24668         -  if( p==0 ) return;
        24696  +  assert( p!=0 );
 24669  24697     if( db ){
 24670  24698       if( db->pnBytesFreed ){
 24671  24699         measureAllocationSize(db, p);
 24672  24700         return;
 24673  24701       }
 24674  24702       if( isLookaside(db, p) ){
 24675  24703         LookasideSlot *pBuf = (LookasideSlot*)p;
................................................................................
 24684  24712       }
 24685  24713     }
 24686  24714     assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
 24687  24715     assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
 24688  24716     assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
 24689  24717     sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
 24690  24718     sqlite3_free(p);
        24719  +}
        24720  +SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
        24721  +  assert( db==0 || sqlite3_mutex_held(db->mutex) );
        24722  +  if( p ) sqlite3DbFreeNN(db, p);
 24691  24723   }
 24692  24724   
 24693  24725   /*
 24694  24726   ** Change the size of an existing memory allocation
 24695  24727   */
 24696  24728   SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, u64 nBytes){
 24697  24729     int nOld, nNew, nDiff;
................................................................................
 26377  26409   
 26378  26410   /*
 26379  26411   ** Generate a human-readable explanation of an expression tree.
 26380  26412   */
 26381  26413   SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
 26382  26414     const char *zBinOp = 0;   /* Binary operator */
 26383  26415     const char *zUniOp = 0;   /* Unary operator */
 26384         -  char zFlgs[30];
        26416  +  char zFlgs[60];
 26385  26417     pView = sqlite3TreeViewPush(pView, moreToFollow);
 26386  26418     if( pExpr==0 ){
 26387  26419       sqlite3TreeViewLine(pView, "nil");
 26388  26420       sqlite3TreeViewPop(pView);
 26389  26421       return;
 26390  26422     }
 26391  26423     if( pExpr->flags ){
 26392         -    sqlite3_snprintf(sizeof(zFlgs),zFlgs,"  flags=0x%x",pExpr->flags);
        26424  +    if( ExprHasProperty(pExpr, EP_FromJoin) ){
        26425  +      sqlite3_snprintf(sizeof(zFlgs),zFlgs,"  flags=0x%x iRJT=%d",
        26426  +                       pExpr->flags, pExpr->iRightJoinTable);
        26427  +    }else{
        26428  +      sqlite3_snprintf(sizeof(zFlgs),zFlgs,"  flags=0x%x",pExpr->flags);
        26429  +    }
 26393  26430     }else{
 26394  26431       zFlgs[0] = 0;
 26395  26432     }
 26396  26433     switch( pExpr->op ){
 26397  26434       case TK_AGG_COLUMN: {
 26398  26435         sqlite3TreeViewLine(pView, "AGG{%d:%d}%s",
 26399  26436               pExpr->iTable, pExpr->iColumn, zFlgs);
................................................................................
 26603  26640         sqlite3TreeViewBareExprList(pView, pExpr->x.pList, "VECTOR");
 26604  26641         break;
 26605  26642       }
 26606  26643       case TK_SELECT_COLUMN: {
 26607  26644         sqlite3TreeViewLine(pView, "SELECT-COLUMN %d", pExpr->iColumn);
 26608  26645         sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
 26609  26646         break;
        26647  +    }
        26648  +    case TK_IF_NULL_ROW: {
        26649  +      sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable);
        26650  +      sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
        26651  +      break;
 26610  26652       }
 26611  26653       default: {
 26612  26654         sqlite3TreeViewLine(pView, "op=%d", pExpr->op);
 26613  26655         break;
 26614  26656       }
 26615  26657     }
 26616  26658     if( zBinOp ){
................................................................................
 28323  28365         memcpy(pValue, &u, 4);
 28324  28366         return 1;
 28325  28367       }else{
 28326  28368         return 0;
 28327  28369       }
 28328  28370     }
 28329  28371   #endif
        28372  +  if( !sqlite3Isdigit(zNum[0]) ) return 0;
 28330  28373     while( zNum[0]=='0' ) zNum++;
 28331  28374     for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
 28332  28375       v = v*10 + c;
 28333  28376     }
 28334  28377   
 28335  28378     /* The longest decimal representation of a 32 bit integer is 10 digits:
 28336  28379     **
................................................................................
 29486  29529       /*  16 */ "Yield"            OpHelp(""),
 29487  29530       /*  17 */ "MustBeInt"        OpHelp(""),
 29488  29531       /*  18 */ "Jump"             OpHelp(""),
 29489  29532       /*  19 */ "Not"              OpHelp("r[P2]= !r[P1]"),
 29490  29533       /*  20 */ "Once"             OpHelp(""),
 29491  29534       /*  21 */ "If"               OpHelp(""),
 29492  29535       /*  22 */ "IfNot"            OpHelp(""),
 29493         -    /*  23 */ "SeekLT"           OpHelp("key=r[P3@P4]"),
 29494         -    /*  24 */ "SeekLE"           OpHelp("key=r[P3@P4]"),
 29495         -    /*  25 */ "SeekGE"           OpHelp("key=r[P3@P4]"),
 29496         -    /*  26 */ "SeekGT"           OpHelp("key=r[P3@P4]"),
 29497         -    /*  27 */ "Or"               OpHelp("r[P3]=(r[P1] || r[P2])"),
 29498         -    /*  28 */ "And"              OpHelp("r[P3]=(r[P1] && r[P2])"),
 29499         -    /*  29 */ "NoConflict"       OpHelp("key=r[P3@P4]"),
 29500         -    /*  30 */ "NotFound"         OpHelp("key=r[P3@P4]"),
 29501         -    /*  31 */ "Found"            OpHelp("key=r[P3@P4]"),
 29502         -    /*  32 */ "SeekRowid"        OpHelp("intkey=r[P3]"),
 29503         -    /*  33 */ "NotExists"        OpHelp("intkey=r[P3]"),
 29504         -    /*  34 */ "IsNull"           OpHelp("if r[P1]==NULL goto P2"),
 29505         -    /*  35 */ "NotNull"          OpHelp("if r[P1]!=NULL goto P2"),
 29506         -    /*  36 */ "Ne"               OpHelp("IF r[P3]!=r[P1]"),
 29507         -    /*  37 */ "Eq"               OpHelp("IF r[P3]==r[P1]"),
 29508         -    /*  38 */ "Gt"               OpHelp("IF r[P3]>r[P1]"),
 29509         -    /*  39 */ "Le"               OpHelp("IF r[P3]<=r[P1]"),
 29510         -    /*  40 */ "Lt"               OpHelp("IF r[P3]<r[P1]"),
 29511         -    /*  41 */ "Ge"               OpHelp("IF r[P3]>=r[P1]"),
 29512         -    /*  42 */ "ElseNotEq"        OpHelp(""),
 29513         -    /*  43 */ "BitAnd"           OpHelp("r[P3]=r[P1]&r[P2]"),
 29514         -    /*  44 */ "BitOr"            OpHelp("r[P3]=r[P1]|r[P2]"),
 29515         -    /*  45 */ "ShiftLeft"        OpHelp("r[P3]=r[P2]<<r[P1]"),
 29516         -    /*  46 */ "ShiftRight"       OpHelp("r[P3]=r[P2]>>r[P1]"),
 29517         -    /*  47 */ "Add"              OpHelp("r[P3]=r[P1]+r[P2]"),
 29518         -    /*  48 */ "Subtract"         OpHelp("r[P3]=r[P2]-r[P1]"),
 29519         -    /*  49 */ "Multiply"         OpHelp("r[P3]=r[P1]*r[P2]"),
 29520         -    /*  50 */ "Divide"           OpHelp("r[P3]=r[P2]/r[P1]"),
 29521         -    /*  51 */ "Remainder"        OpHelp("r[P3]=r[P2]%r[P1]"),
 29522         -    /*  52 */ "Concat"           OpHelp("r[P3]=r[P2]+r[P1]"),
 29523         -    /*  53 */ "Last"             OpHelp(""),
 29524         -    /*  54 */ "BitNot"           OpHelp("r[P1]= ~r[P1]"),
 29525         -    /*  55 */ "IfSmaller"        OpHelp(""),
 29526         -    /*  56 */ "SorterSort"       OpHelp(""),
 29527         -    /*  57 */ "Sort"             OpHelp(""),
 29528         -    /*  58 */ "Rewind"           OpHelp(""),
 29529         -    /*  59 */ "IdxLE"            OpHelp("key=r[P3@P4]"),
 29530         -    /*  60 */ "IdxGT"            OpHelp("key=r[P3@P4]"),
 29531         -    /*  61 */ "IdxLT"            OpHelp("key=r[P3@P4]"),
 29532         -    /*  62 */ "IdxGE"            OpHelp("key=r[P3@P4]"),
 29533         -    /*  63 */ "RowSetRead"       OpHelp("r[P3]=rowset(P1)"),
 29534         -    /*  64 */ "RowSetTest"       OpHelp("if r[P3] in rowset(P1) goto P2"),
 29535         -    /*  65 */ "Program"          OpHelp(""),
 29536         -    /*  66 */ "FkIfZero"         OpHelp("if fkctr[P1]==0 goto P2"),
 29537         -    /*  67 */ "IfPos"            OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
 29538         -    /*  68 */ "IfNotZero"        OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
 29539         -    /*  69 */ "DecrJumpZero"     OpHelp("if (--r[P1])==0 goto P2"),
 29540         -    /*  70 */ "IncrVacuum"       OpHelp(""),
 29541         -    /*  71 */ "VNext"            OpHelp(""),
 29542         -    /*  72 */ "Init"             OpHelp("Start at P2"),
 29543         -    /*  73 */ "Return"           OpHelp(""),
 29544         -    /*  74 */ "EndCoroutine"     OpHelp(""),
 29545         -    /*  75 */ "HaltIfNull"       OpHelp("if r[P3]=null halt"),
 29546         -    /*  76 */ "Halt"             OpHelp(""),
 29547         -    /*  77 */ "Integer"          OpHelp("r[P2]=P1"),
 29548         -    /*  78 */ "Int64"            OpHelp("r[P2]=P4"),
 29549         -    /*  79 */ "String"           OpHelp("r[P2]='P4' (len=P1)"),
 29550         -    /*  80 */ "Null"             OpHelp("r[P2..P3]=NULL"),
 29551         -    /*  81 */ "SoftNull"         OpHelp("r[P1]=NULL"),
 29552         -    /*  82 */ "Blob"             OpHelp("r[P2]=P4 (len=P1)"),
 29553         -    /*  83 */ "Variable"         OpHelp("r[P2]=parameter(P1,P4)"),
 29554         -    /*  84 */ "Move"             OpHelp("r[P2@P3]=r[P1@P3]"),
 29555         -    /*  85 */ "Copy"             OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
 29556         -    /*  86 */ "SCopy"            OpHelp("r[P2]=r[P1]"),
 29557         -    /*  87 */ "IntCopy"          OpHelp("r[P2]=r[P1]"),
 29558         -    /*  88 */ "ResultRow"        OpHelp("output=r[P1@P2]"),
 29559         -    /*  89 */ "CollSeq"          OpHelp(""),
 29560         -    /*  90 */ "Function0"        OpHelp("r[P3]=func(r[P2@P5])"),
 29561         -    /*  91 */ "Function"         OpHelp("r[P3]=func(r[P2@P5])"),
 29562         -    /*  92 */ "AddImm"           OpHelp("r[P1]=r[P1]+P2"),
 29563         -    /*  93 */ "RealAffinity"     OpHelp(""),
        29536  +    /*  23 */ "IfNullRow"        OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
        29537  +    /*  24 */ "SeekLT"           OpHelp("key=r[P3@P4]"),
        29538  +    /*  25 */ "SeekLE"           OpHelp("key=r[P3@P4]"),
        29539  +    /*  26 */ "SeekGE"           OpHelp("key=r[P3@P4]"),
        29540  +    /*  27 */ "SeekGT"           OpHelp("key=r[P3@P4]"),
        29541  +    /*  28 */ "NoConflict"       OpHelp("key=r[P3@P4]"),
        29542  +    /*  29 */ "NotFound"         OpHelp("key=r[P3@P4]"),
        29543  +    /*  30 */ "Found"            OpHelp("key=r[P3@P4]"),
        29544  +    /*  31 */ "SeekRowid"        OpHelp("intkey=r[P3]"),
        29545  +    /*  32 */ "NotExists"        OpHelp("intkey=r[P3]"),
        29546  +    /*  33 */ "Last"             OpHelp(""),
        29547  +    /*  34 */ "IfSmaller"        OpHelp(""),
        29548  +    /*  35 */ "SorterSort"       OpHelp(""),
        29549  +    /*  36 */ "Sort"             OpHelp(""),
        29550  +    /*  37 */ "Rewind"           OpHelp(""),
        29551  +    /*  38 */ "IdxLE"            OpHelp("key=r[P3@P4]"),
        29552  +    /*  39 */ "IdxGT"            OpHelp("key=r[P3@P4]"),
        29553  +    /*  40 */ "IdxLT"            OpHelp("key=r[P3@P4]"),
        29554  +    /*  41 */ "IdxGE"            OpHelp("key=r[P3@P4]"),
        29555  +    /*  42 */ "RowSetRead"       OpHelp("r[P3]=rowset(P1)"),
        29556  +    /*  43 */ "RowSetTest"       OpHelp("if r[P3] in rowset(P1) goto P2"),
        29557  +    /*  44 */ "Program"          OpHelp(""),
        29558  +    /*  45 */ "FkIfZero"         OpHelp("if fkctr[P1]==0 goto P2"),
        29559  +    /*  46 */ "IfPos"            OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
        29560  +    /*  47 */ "IfNotZero"        OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
        29561  +    /*  48 */ "DecrJumpZero"     OpHelp("if (--r[P1])==0 goto P2"),
        29562  +    /*  49 */ "IncrVacuum"       OpHelp(""),
        29563  +    /*  50 */ "VNext"            OpHelp(""),
        29564  +    /*  51 */ "Init"             OpHelp("Start at P2"),
        29565  +    /*  52 */ "Return"           OpHelp(""),
        29566  +    /*  53 */ "EndCoroutine"     OpHelp(""),
        29567  +    /*  54 */ "HaltIfNull"       OpHelp("if r[P3]=null halt"),
        29568  +    /*  55 */ "Halt"             OpHelp(""),
        29569  +    /*  56 */ "Integer"          OpHelp("r[P2]=P1"),
        29570  +    /*  57 */ "Int64"            OpHelp("r[P2]=P4"),
        29571  +    /*  58 */ "String"           OpHelp("r[P2]='P4' (len=P1)"),
        29572  +    /*  59 */ "Null"             OpHelp("r[P2..P3]=NULL"),
        29573  +    /*  60 */ "SoftNull"         OpHelp("r[P1]=NULL"),
        29574  +    /*  61 */ "Blob"             OpHelp("r[P2]=P4 (len=P1)"),
        29575  +    /*  62 */ "Variable"         OpHelp("r[P2]=parameter(P1,P4)"),
        29576  +    /*  63 */ "Move"             OpHelp("r[P2@P3]=r[P1@P3]"),
        29577  +    /*  64 */ "Copy"             OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
        29578  +    /*  65 */ "SCopy"            OpHelp("r[P2]=r[P1]"),
        29579  +    /*  66 */ "IntCopy"          OpHelp("r[P2]=r[P1]"),
        29580  +    /*  67 */ "ResultRow"        OpHelp("output=r[P1@P2]"),
        29581  +    /*  68 */ "CollSeq"          OpHelp(""),
        29582  +    /*  69 */ "Function0"        OpHelp("r[P3]=func(r[P2@P5])"),
        29583  +    /*  70 */ "Or"               OpHelp("r[P3]=(r[P1] || r[P2])"),
        29584  +    /*  71 */ "And"              OpHelp("r[P3]=(r[P1] && r[P2])"),
        29585  +    /*  72 */ "Function"         OpHelp("r[P3]=func(r[P2@P5])"),
        29586  +    /*  73 */ "AddImm"           OpHelp("r[P1]=r[P1]+P2"),
        29587  +    /*  74 */ "RealAffinity"     OpHelp(""),
        29588  +    /*  75 */ "IsNull"           OpHelp("if r[P1]==NULL goto P2"),
        29589  +    /*  76 */ "NotNull"          OpHelp("if r[P1]!=NULL goto P2"),
        29590  +    /*  77 */ "Ne"               OpHelp("IF r[P3]!=r[P1]"),
        29591  +    /*  78 */ "Eq"               OpHelp("IF r[P3]==r[P1]"),
        29592  +    /*  79 */ "Gt"               OpHelp("IF r[P3]>r[P1]"),
        29593  +    /*  80 */ "Le"               OpHelp("IF r[P3]<=r[P1]"),
        29594  +    /*  81 */ "Lt"               OpHelp("IF r[P3]<r[P1]"),
        29595  +    /*  82 */ "Ge"               OpHelp("IF r[P3]>=r[P1]"),
        29596  +    /*  83 */ "ElseNotEq"        OpHelp(""),
        29597  +    /*  84 */ "BitAnd"           OpHelp("r[P3]=r[P1]&r[P2]"),
        29598  +    /*  85 */ "BitOr"            OpHelp("r[P3]=r[P1]|r[P2]"),
        29599  +    /*  86 */ "ShiftLeft"        OpHelp("r[P3]=r[P2]<<r[P1]"),
        29600  +    /*  87 */ "ShiftRight"       OpHelp("r[P3]=r[P2]>>r[P1]"),
        29601  +    /*  88 */ "Add"              OpHelp("r[P3]=r[P1]+r[P2]"),
        29602  +    /*  89 */ "Subtract"         OpHelp("r[P3]=r[P2]-r[P1]"),
        29603  +    /*  90 */ "Multiply"         OpHelp("r[P3]=r[P1]*r[P2]"),
        29604  +    /*  91 */ "Divide"           OpHelp("r[P3]=r[P2]/r[P1]"),
        29605  +    /*  92 */ "Remainder"        OpHelp("r[P3]=r[P2]%r[P1]"),
        29606  +    /*  93 */ "Concat"           OpHelp("r[P3]=r[P2]+r[P1]"),
 29564  29607       /*  94 */ "Cast"             OpHelp("affinity(r[P1])"),
 29565         -    /*  95 */ "Permutation"      OpHelp(""),
 29566         -    /*  96 */ "Compare"          OpHelp("r[P1@P3] <-> r[P2@P3]"),
        29608  +    /*  95 */ "BitNot"           OpHelp("r[P1]= ~r[P1]"),
        29609  +    /*  96 */ "Permutation"      OpHelp(""),
 29567  29610       /*  97 */ "String8"          OpHelp("r[P2]='P4'"),
 29568         -    /*  98 */ "Column"           OpHelp("r[P3]=PX"),
 29569         -    /*  99 */ "Affinity"         OpHelp("affinity(r[P1@P2])"),
 29570         -    /* 100 */ "MakeRecord"       OpHelp("r[P3]=mkrec(r[P1@P2])"),
 29571         -    /* 101 */ "Count"            OpHelp("r[P2]=count()"),
 29572         -    /* 102 */ "ReadCookie"       OpHelp(""),
 29573         -    /* 103 */ "SetCookie"        OpHelp(""),
 29574         -    /* 104 */ "ReopenIdx"        OpHelp("root=P2 iDb=P3"),
 29575         -    /* 105 */ "OpenRead"         OpHelp("root=P2 iDb=P3"),
 29576         -    /* 106 */ "OpenWrite"        OpHelp("root=P2 iDb=P3"),
 29577         -    /* 107 */ "OpenAutoindex"    OpHelp("nColumn=P2"),
 29578         -    /* 108 */ "OpenEphemeral"    OpHelp("nColumn=P2"),
 29579         -    /* 109 */ "SorterOpen"       OpHelp(""),
 29580         -    /* 110 */ "SequenceTest"     OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
 29581         -    /* 111 */ "OpenPseudo"       OpHelp("P3 columns in r[P2]"),
 29582         -    /* 112 */ "Close"            OpHelp(""),
 29583         -    /* 113 */ "ColumnsUsed"      OpHelp(""),
 29584         -    /* 114 */ "Sequence"         OpHelp("r[P2]=cursor[P1].ctr++"),
 29585         -    /* 115 */ "NewRowid"         OpHelp("r[P2]=rowid"),
 29586         -    /* 116 */ "Insert"           OpHelp("intkey=r[P3] data=r[P2]"),
 29587         -    /* 117 */ "InsertInt"        OpHelp("intkey=P3 data=r[P2]"),
 29588         -    /* 118 */ "Delete"           OpHelp(""),
 29589         -    /* 119 */ "ResetCount"       OpHelp(""),
 29590         -    /* 120 */ "SorterCompare"    OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
 29591         -    /* 121 */ "SorterData"       OpHelp("r[P2]=data"),
 29592         -    /* 122 */ "RowData"          OpHelp("r[P2]=data"),
 29593         -    /* 123 */ "Rowid"            OpHelp("r[P2]=rowid"),
 29594         -    /* 124 */ "NullRow"          OpHelp(""),
 29595         -    /* 125 */ "SorterInsert"     OpHelp("key=r[P2]"),
 29596         -    /* 126 */ "IdxInsert"        OpHelp("key=r[P2]"),
 29597         -    /* 127 */ "IdxDelete"        OpHelp("key=r[P2@P3]"),
 29598         -    /* 128 */ "Seek"             OpHelp("Move P3 to P1.rowid"),
 29599         -    /* 129 */ "IdxRowid"         OpHelp("r[P2]=rowid"),
 29600         -    /* 130 */ "Destroy"          OpHelp(""),
 29601         -    /* 131 */ "Clear"            OpHelp(""),
        29611  +    /*  98 */ "Compare"          OpHelp("r[P1@P3] <-> r[P2@P3]"),
        29612  +    /*  99 */ "Column"           OpHelp("r[P3]=PX"),
        29613  +    /* 100 */ "Affinity"         OpHelp("affinity(r[P1@P2])"),
        29614  +    /* 101 */ "MakeRecord"       OpHelp("r[P3]=mkrec(r[P1@P2])"),
        29615  +    /* 102 */ "Count"            OpHelp("r[P2]=count()"),
        29616  +    /* 103 */ "ReadCookie"       OpHelp(""),
        29617  +    /* 104 */ "SetCookie"        OpHelp(""),
        29618  +    /* 105 */ "ReopenIdx"        OpHelp("root=P2 iDb=P3"),
        29619  +    /* 106 */ "OpenRead"         OpHelp("root=P2 iDb=P3"),
        29620  +    /* 107 */ "OpenWrite"        OpHelp("root=P2 iDb=P3"),
        29621  +    /* 108 */ "OpenDup"          OpHelp(""),
        29622  +    /* 109 */ "OpenAutoindex"    OpHelp("nColumn=P2"),
        29623  +    /* 110 */ "OpenEphemeral"    OpHelp("nColumn=P2"),
        29624  +    /* 111 */ "SorterOpen"       OpHelp(""),
        29625  +    /* 112 */ "SequenceTest"     OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
        29626  +    /* 113 */ "OpenPseudo"       OpHelp("P3 columns in r[P2]"),
        29627  +    /* 114 */ "Close"            OpHelp(""),
        29628  +    /* 115 */ "ColumnsUsed"      OpHelp(""),
        29629  +    /* 116 */ "Sequence"         OpHelp("r[P2]=cursor[P1].ctr++"),
        29630  +    /* 117 */ "NewRowid"         OpHelp("r[P2]=rowid"),
        29631  +    /* 118 */ "Insert"           OpHelp("intkey=r[P3] data=r[P2]"),
        29632  +    /* 119 */ "InsertInt"        OpHelp("intkey=P3 data=r[P2]"),
        29633  +    /* 120 */ "Delete"           OpHelp(""),
        29634  +    /* 121 */ "ResetCount"       OpHelp(""),
        29635  +    /* 122 */ "SorterCompare"    OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
        29636  +    /* 123 */ "SorterData"       OpHelp("r[P2]=data"),
        29637  +    /* 124 */ "RowData"          OpHelp("r[P2]=data"),
        29638  +    /* 125 */ "Rowid"            OpHelp("r[P2]=rowid"),
        29639  +    /* 126 */ "NullRow"          OpHelp(""),
        29640  +    /* 127 */ "SorterInsert"     OpHelp("key=r[P2]"),
        29641  +    /* 128 */ "IdxInsert"        OpHelp("key=r[P2]"),
        29642  +    /* 129 */ "IdxDelete"        OpHelp("key=r[P2@P3]"),
        29643  +    /* 130 */ "Seek"             OpHelp("Move P3 to P1.rowid"),
        29644  +    /* 131 */ "IdxRowid"         OpHelp("r[P2]=rowid"),
 29602  29645       /* 132 */ "Real"             OpHelp("r[P2]=P4"),
 29603         -    /* 133 */ "ResetSorter"      OpHelp(""),
 29604         -    /* 134 */ "CreateIndex"      OpHelp("r[P2]=root iDb=P1"),
 29605         -    /* 135 */ "CreateTable"      OpHelp("r[P2]=root iDb=P1"),
 29606         -    /* 136 */ "SqlExec"          OpHelp(""),
 29607         -    /* 137 */ "ParseSchema"      OpHelp(""),
 29608         -    /* 138 */ "LoadAnalysis"     OpHelp(""),
 29609         -    /* 139 */ "DropTable"        OpHelp(""),
 29610         -    /* 140 */ "DropIndex"        OpHelp(""),
 29611         -    /* 141 */ "DropTrigger"      OpHelp(""),
 29612         -    /* 142 */ "IntegrityCk"      OpHelp(""),
 29613         -    /* 143 */ "RowSetAdd"        OpHelp("rowset(P1)=r[P2]"),
 29614         -    /* 144 */ "Param"            OpHelp(""),
 29615         -    /* 145 */ "FkCounter"        OpHelp("fkctr[P1]+=P2"),
 29616         -    /* 146 */ "MemMax"           OpHelp("r[P1]=max(r[P1],r[P2])"),
 29617         -    /* 147 */ "OffsetLimit"      OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
 29618         -    /* 148 */ "AggStep0"         OpHelp("accum=r[P3] step(r[P2@P5])"),
 29619         -    /* 149 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2@P5])"),
 29620         -    /* 150 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
 29621         -    /* 151 */ "Expire"           OpHelp(""),
 29622         -    /* 152 */ "TableLock"        OpHelp("iDb=P1 root=P2 write=P3"),
 29623         -    /* 153 */ "VBegin"           OpHelp(""),
 29624         -    /* 154 */ "VCreate"          OpHelp(""),
 29625         -    /* 155 */ "VDestroy"         OpHelp(""),
 29626         -    /* 156 */ "VOpen"            OpHelp(""),
 29627         -    /* 157 */ "VColumn"          OpHelp("r[P3]=vcolumn(P2)"),
 29628         -    /* 158 */ "VRename"          OpHelp(""),
 29629         -    /* 159 */ "Pagecount"        OpHelp(""),
 29630         -    /* 160 */ "MaxPgcnt"         OpHelp(""),
 29631         -    /* 161 */ "CursorHint"       OpHelp(""),
 29632         -    /* 162 */ "Noop"             OpHelp(""),
 29633         -    /* 163 */ "Explain"          OpHelp(""),
        29646  +    /* 133 */ "Destroy"          OpHelp(""),
        29647  +    /* 134 */ "Clear"            OpHelp(""),
        29648  +    /* 135 */ "ResetSorter"      OpHelp(""),
        29649  +    /* 136 */ "CreateIndex"      OpHelp("r[P2]=root iDb=P1"),
        29650  +    /* 137 */ "CreateTable"      OpHelp("r[P2]=root iDb=P1"),
        29651  +    /* 138 */ "SqlExec"          OpHelp(""),
        29652  +    /* 139 */ "ParseSchema"      OpHelp(""),
        29653  +    /* 140 */ "LoadAnalysis"     OpHelp(""),
        29654  +    /* 141 */ "DropTable"        OpHelp(""),
        29655  +    /* 142 */ "DropIndex"        OpHelp(""),
        29656  +    /* 143 */ "DropTrigger"      OpHelp(""),
        29657  +    /* 144 */ "IntegrityCk"      OpHelp(""),
        29658  +    /* 145 */ "RowSetAdd"        OpHelp("rowset(P1)=r[P2]"),
        29659  +    /* 146 */ "Param"            OpHelp(""),
        29660  +    /* 147 */ "FkCounter"        OpHelp("fkctr[P1]+=P2"),
        29661  +    /* 148 */ "MemMax"           OpHelp("r[P1]=max(r[P1],r[P2])"),
        29662  +    /* 149 */ "OffsetLimit"      OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
        29663  +    /* 150 */ "AggStep0"         OpHelp("accum=r[P3] step(r[P2@P5])"),
        29664  +    /* 151 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2@P5])"),
        29665  +    /* 152 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
        29666  +    /* 153 */ "Expire"           OpHelp(""),
        29667  +    /* 154 */ "TableLock"        OpHelp("iDb=P1 root=P2 write=P3"),
        29668  +    /* 155 */ "VBegin"           OpHelp(""),
        29669  +    /* 156 */ "VCreate"          OpHelp(""),
        29670  +    /* 157 */ "VDestroy"         OpHelp(""),
        29671  +    /* 158 */ "VOpen"            OpHelp(""),
        29672  +    /* 159 */ "VColumn"          OpHelp("r[P3]=vcolumn(P2)"),
        29673  +    /* 160 */ "VRename"          OpHelp(""),
        29674  +    /* 161 */ "Pagecount"        OpHelp(""),
        29675  +    /* 162 */ "MaxPgcnt"         OpHelp(""),
        29676  +    /* 163 */ "CursorHint"       OpHelp(""),
        29677  +    /* 164 */ "Noop"             OpHelp(""),
        29678  +    /* 165 */ "Explain"          OpHelp(""),
 29634  29679     };
 29635  29680     return azName[i];
 29636  29681   }
 29637  29682   #endif
 29638  29683   
 29639  29684   /************** End of opcodes.c *********************************************/
 29640  29685   /************** Begin file os_unix.c *****************************************/
................................................................................
 45241  45286     if( szBulk > pCache->szAlloc*(i64)pCache->nMax ){
 45242  45287       szBulk = pCache->szAlloc*(i64)pCache->nMax;
 45243  45288     }
 45244  45289     zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
 45245  45290     sqlite3EndBenignMalloc();
 45246  45291     if( zBulk ){
 45247  45292       int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
 45248         -    int i;
 45249         -    for(i=0; i<nBulk; i++){
        45293  +    do{
 45250  45294         PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
 45251  45295         pX->page.pBuf = zBulk;
 45252  45296         pX->page.pExtra = &pX[1];
 45253  45297         pX->isBulkLocal = 1;
 45254  45298         pX->isAnchor = 0;
 45255  45299         pX->pNext = pCache->pFree;
 45256  45300         pCache->pFree = pX;
 45257  45301         zBulk += pCache->szAlloc;
 45258         -    }
        45302  +    }while( --nBulk );
 45259  45303     }
 45260  45304     return pCache->pFree!=0;
 45261  45305   }
 45262  45306   
 45263  45307   /*
 45264  45308   ** Malloc function used within this file to allocate space from the buffer
 45265  45309   ** configured using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no 
................................................................................
 46167  46211   ** been released, the function returns. The return value is the total number 
 46168  46212   ** of bytes of memory released.
 46169  46213   */
 46170  46214   SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
 46171  46215     int nFree = 0;
 46172  46216     assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
 46173  46217     assert( sqlite3_mutex_notheld(pcache1.mutex) );
 46174         -  if( sqlite3GlobalConfig.nPage==0 ){
        46218  +  if( sqlite3GlobalConfig.pPage==0 ){
 46175  46219       PgHdr1 *p;
 46176  46220       pcache1EnterMutex(&pcache1.grp);
 46177  46221       while( (nReq<0 || nFree<nReq)
 46178  46222          &&  (p=pcache1.grp.lru.pLruPrev)!=0
 46179  46223          &&  p->isAnchor==0
 46180  46224       ){
 46181  46225         nFree += pcache1MemSize(p->page.pBuf);
................................................................................
 49127  49171     int rc;
 49128  49172     PgHdr *pPg;                   /* An existing page in the cache */
 49129  49173     Pgno pgno;                    /* The page number of a page in journal */
 49130  49174     u32 cksum;                    /* Checksum used for sanity checking */
 49131  49175     char *aData;                  /* Temporary storage for the page */
 49132  49176     sqlite3_file *jfd;            /* The file descriptor for the journal file */
 49133  49177     int isSynced;                 /* True if journal page is synced */
        49178  +#ifdef SQLITE_HAS_CODEC
        49179  +  /* The jrnlEnc flag is true if Journal pages should be passed through
        49180  +  ** the codec.  It is false for pure in-memory journals. */
        49181  +  const int jrnlEnc = (isMainJrnl || pPager->subjInMemory==0);
        49182  +#endif
 49134  49183   
 49135  49184     assert( (isMainJrnl&~1)==0 );      /* isMainJrnl is 0 or 1 */
 49136  49185     assert( (isSavepnt&~1)==0 );       /* isSavepnt is 0 or 1 */
 49137  49186     assert( isMainJrnl || pDone );     /* pDone always used on sub-journals */
 49138  49187     assert( isSavepnt || pDone==0 );   /* pDone never used on non-savepoint */
 49139  49188   
 49140  49189     aData = pPager->pTmpSpace;
................................................................................
 49250  49299     if( isOpen(pPager->fd)
 49251  49300      && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
 49252  49301      && isSynced
 49253  49302     ){
 49254  49303       i64 ofst = (pgno-1)*(i64)pPager->pageSize;
 49255  49304       testcase( !isSavepnt && pPg!=0 && (pPg->flags&PGHDR_NEED_SYNC)!=0 );
 49256  49305       assert( !pagerUseWal(pPager) );
        49306  +
        49307  +    /* Write the data read from the journal back into the database file.
        49308  +    ** This is usually safe even for an encrypted database - as the data
        49309  +    ** was encrypted before it was written to the journal file. The exception
        49310  +    ** is if the data was just read from an in-memory sub-journal. In that
        49311  +    ** case it must be encrypted here before it is copied into the database
        49312  +    ** file.  */
        49313  +#ifdef SQLITE_HAS_CODEC
        49314  +    if( !jrnlEnc ){
        49315  +      CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT, aData);
        49316  +      rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst);
        49317  +      CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT);
        49318  +    }else
        49319  +#endif
 49257  49320       rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst);
        49321  +
 49258  49322       if( pgno>pPager->dbFileSize ){
 49259  49323         pPager->dbFileSize = pgno;
 49260  49324       }
 49261  49325       if( pPager->pBackup ){
 49262         -      CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT);
        49326  +#ifdef SQLITE_HAS_CODEC
        49327  +      if( jrnlEnc ){
        49328  +        CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT);
        49329  +        sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData);
        49330  +        CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT,aData);
        49331  +      }else
        49332  +#endif
 49263  49333         sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData);
 49264         -      CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT, aData);
 49265  49334       }
 49266  49335     }else if( !isMainJrnl && pPg==0 ){
 49267  49336       /* If this is a rollback of a savepoint and data was not written to
 49268  49337       ** the database and the page is not in-memory, there is a potential
 49269  49338       ** problem. When the page is next fetched by the b-tree layer, it 
 49270  49339       ** will be read from the database file, which may or may not be 
 49271  49340       ** current. 
................................................................................
 49309  49378       /* If this was page 1, then restore the value of Pager.dbFileVers.
 49310  49379       ** Do this before any decoding. */
 49311  49380       if( pgno==1 ){
 49312  49381         memcpy(&pPager->dbFileVers, &((u8*)pData)[24],sizeof(pPager->dbFileVers));
 49313  49382       }
 49314  49383   
 49315  49384       /* Decode the page just read from disk */
 49316         -    CODEC1(pPager, pData, pPg->pgno, 3, rc=SQLITE_NOMEM_BKPT);
        49385  +#if SQLITE_HAS_CODEC
        49386  +    if( jrnlEnc ){ CODEC1(pPager, pData, pPg->pgno, 3, rc=SQLITE_NOMEM_BKPT); }
        49387  +#endif
 49317  49388       sqlite3PcacheRelease(pPg);
 49318  49389     }
 49319  49390     return rc;
 49320  49391   }
 49321  49392   
 49322  49393   /*
 49323  49394   ** Parameter zMaster is the name of a master journal file. A single journal
................................................................................
 51321  51392   
 51322  51393       /* If the sub-journal was opened successfully (or was already open),
 51323  51394       ** write the journal record into the file.  */
 51324  51395       if( rc==SQLITE_OK ){
 51325  51396         void *pData = pPg->pData;
 51326  51397         i64 offset = (i64)pPager->nSubRec*(4+pPager->pageSize);
 51327  51398         char *pData2;
 51328         -  
 51329         -      CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM_BKPT, pData2);
        51399  +
        51400  +#if SQLITE_HAS_CODEC   
        51401  +      if( !pPager->subjInMemory ){
        51402  +        CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM_BKPT, pData2);
        51403  +      }else
        51404  +#endif
        51405  +      pData2 = pData;
 51330  51406         PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
 51331  51407         rc = write32bits(pPager->sjfd, offset, pPg->pgno);
 51332  51408         if( rc==SQLITE_OK ){
 51333  51409           rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4);
 51334  51410         }
 51335  51411       }
 51336  51412     }
................................................................................
 58474  58550     u8 eState;                /* One of the CURSOR_XXX constants (see below) */
 58475  58551     u8 hints;                 /* As configured by CursorSetHints() */
 58476  58552     /* All fields above are zeroed when the cursor is allocated.  See
 58477  58553     ** sqlite3BtreeCursorZero().  Fields that follow must be manually
 58478  58554     ** initialized. */
 58479  58555     i8 iPage;                 /* Index of current page in apPage */
 58480  58556     u8 curIntKey;             /* Value of apPage[0]->intKey */
 58481         -  struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */
 58482         -  void *padding1;           /* Make object size a multiple of 16 */
 58483         -  u16 aiIdx[BTCURSOR_MAX_DEPTH];        /* Current index in apPage[i] */
 58484         -  MemPage *apPage[BTCURSOR_MAX_DEPTH];  /* Pages from root to current page */
        58557  +  u16 ix;                   /* Current index for apPage[iPage] */
        58558  +  u16 aiIdx[BTCURSOR_MAX_DEPTH-1];     /* Current index in apPage[i] */
        58559  +  struct KeyInfo *pKeyInfo;            /* Arg passed to comparison function */
        58560  +  MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */
 58485  58561   };
 58486  58562   
 58487  58563   /*
 58488  58564   ** Legal values for BtCursor.curFlags
 58489  58565   */
 58490  58566   #define BTCF_WriteFlag    0x01   /* True if a write cursor */
 58491  58567   #define BTCF_ValidNKey    0x02   /* True if info.nKey is valid */
................................................................................
 59453  59529   **
 59454  59530   ** Otherwise, if argument isClearTable is false, then the row with
 59455  59531   ** rowid iRow is being replaced or deleted. In this case invalidate
 59456  59532   ** only those incrblob cursors open on that specific row.
 59457  59533   */
 59458  59534   static void invalidateIncrblobCursors(
 59459  59535     Btree *pBtree,          /* The database file to check */
        59536  +  Pgno pgnoRoot,          /* The table that might be changing */
 59460  59537     i64 iRow,               /* The rowid that might be changing */
 59461  59538     int isClearTable        /* True if all rows are being deleted */
 59462  59539   ){
 59463  59540     BtCursor *p;
 59464  59541     if( pBtree->hasIncrblobCur==0 ) return;
 59465  59542     assert( sqlite3BtreeHoldsMutex(pBtree) );
 59466  59543     pBtree->hasIncrblobCur = 0;
 59467  59544     for(p=pBtree->pBt->pCursor; p; p=p->pNext){
 59468  59545       if( (p->curFlags & BTCF_Incrblob)!=0 ){
 59469  59546         pBtree->hasIncrblobCur = 1;
 59470         -      if( isClearTable || p->info.nKey==iRow ){
        59547  +      if( p->pgnoRoot==pgnoRoot && (isClearTable || p->info.nKey==iRow) ){
 59471  59548           p->eState = CURSOR_INVALID;
 59472  59549         }
 59473  59550       }
 59474  59551     }
 59475  59552   }
 59476  59553   
 59477  59554   #else
 59478  59555     /* Stub function when INCRBLOB is omitted */
 59479         -  #define invalidateIncrblobCursors(x,y,z)
        59556  +  #define invalidateIncrblobCursors(w,x,y,z)
 59480  59557   #endif /* SQLITE_OMIT_INCRBLOB */
 59481  59558   
 59482  59559   /*
 59483  59560   ** Set bit pgno of the BtShared.pHasContent bitvec. This is called 
 59484  59561   ** when a page that previously contained data becomes a free-list leaf 
 59485  59562   ** page.
 59486  59563   **
................................................................................
 63270  63347   ** Using this cache reduces the number of calls to btreeParseCell().
 63271  63348   */
 63272  63349   #ifndef NDEBUG
 63273  63350     static void assertCellInfo(BtCursor *pCur){
 63274  63351       CellInfo info;
 63275  63352       int iPage = pCur->iPage;
 63276  63353       memset(&info, 0, sizeof(info));
 63277         -    btreeParseCell(pCur->apPage[iPage], pCur->aiIdx[iPage], &info);
        63354  +    btreeParseCell(pCur->apPage[iPage], pCur->ix, &info);
 63278  63355       assert( CORRUPT_DB || memcmp(&info, &pCur->info, sizeof(info))==0 );
 63279  63356     }
 63280  63357   #else
 63281  63358     #define assertCellInfo(x)
 63282  63359   #endif
 63283  63360   static SQLITE_NOINLINE void getCellInfo(BtCursor *pCur){
 63284  63361     if( pCur->info.nSize==0 ){
 63285  63362       int iPage = pCur->iPage;
 63286  63363       pCur->curFlags |= BTCF_ValidNKey;
 63287         -    btreeParseCell(pCur->apPage[iPage],pCur->aiIdx[iPage],&pCur->info);
        63364  +    btreeParseCell(pCur->apPage[iPage],pCur->ix,&pCur->info);
 63288  63365     }else{
 63289  63366       assertCellInfo(pCur);
 63290  63367     }
 63291  63368   }
 63292  63369   
 63293  63370   #ifndef NDEBUG  /* The next routine used only within assert() statements */
 63294  63371   /*
................................................................................
 63487  63564   #ifdef SQLITE_DIRECT_OVERFLOW_READ
 63488  63565     unsigned char * const pBufStart = pBuf;     /* Start of original out buffer */
 63489  63566   #endif
 63490  63567   
 63491  63568     assert( pPage );
 63492  63569     assert( eOp==0 || eOp==1 );
 63493  63570     assert( pCur->eState==CURSOR_VALID );
 63494         -  assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
        63571  +  assert( pCur->ix<pPage->nCell );
 63495  63572     assert( cursorHoldsMutex(pCur) );
 63496  63573   
 63497  63574     getCellInfo(pCur);
 63498  63575     aPayload = pCur->info.pPayload;
 63499  63576     assert( offset+amt <= pCur->info.nPayload );
 63500  63577   
 63501  63578     assert( aPayload > pPage->aData );
................................................................................
 63674  63751   ** wrong.  An error is returned if "offset+amt" is larger than
 63675  63752   ** the available payload.
 63676  63753   */
 63677  63754   SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
 63678  63755     assert( cursorHoldsMutex(pCur) );
 63679  63756     assert( pCur->eState==CURSOR_VALID );
 63680  63757     assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
 63681         -  assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
        63758  +  assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
 63682  63759     return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
 63683  63760   }
 63684  63761   
 63685  63762   /*
 63686  63763   ** This variant of sqlite3BtreePayload() works even if the cursor has not
 63687  63764   ** in the CURSOR_VALID state.  It is only used by the sqlite3_blob_read()
 63688  63765   ** interface.
................................................................................
 63736  63813     u32 *pAmt            /* Write the number of available bytes here */
 63737  63814   ){
 63738  63815     u32 amt;
 63739  63816     assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
 63740  63817     assert( pCur->eState==CURSOR_VALID );
 63741  63818     assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
 63742  63819     assert( cursorOwnsBtShared(pCur) );
 63743         -  assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
        63820  +  assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
 63744  63821     assert( pCur->info.nSize>0 );
 63745  63822     assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB );
 63746  63823     assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB);
 63747  63824     amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload);
 63748  63825     if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
 63749  63826     *pAmt = amt;
 63750  63827     return (void*)pCur->info.pPayload;
................................................................................
 63787  63864     assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
 63788  63865     assert( pCur->iPage>=0 );
 63789  63866     if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
 63790  63867       return SQLITE_CORRUPT_BKPT;
 63791  63868     }
 63792  63869     pCur->info.nSize = 0;
 63793  63870     pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
 63794         -  pCur->iPage++;
 63795         -  pCur->aiIdx[pCur->iPage] = 0;
        63871  +  pCur->aiIdx[pCur->iPage++] = pCur->ix;
        63872  +  pCur->ix = 0;
 63796  63873     return getAndInitPage(pBt, newPgno, &pCur->apPage[pCur->iPage],
 63797  63874                           pCur, pCur->curPagerFlags);
 63798  63875   }
 63799  63876   
 63800  63877   #ifdef SQLITE_DEBUG
 63801  63878   /*
 63802  63879   ** Page pParent is an internal (non-leaf) tree page. This function 
................................................................................
 63836  63913       pCur->apPage[pCur->iPage-1], 
 63837  63914       pCur->aiIdx[pCur->iPage-1], 
 63838  63915       pCur->apPage[pCur->iPage]->pgno
 63839  63916     );
 63840  63917     testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell );
 63841  63918     pCur->info.nSize = 0;
 63842  63919     pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
        63920  +  pCur->ix = pCur->aiIdx[pCur->iPage-1];
 63843  63921     releasePageNotNull(pCur->apPage[pCur->iPage--]);
 63844  63922   }
 63845  63923   
 63846  63924   /*
 63847  63925   ** Move the cursor to point to the root page of its b-tree structure.
 63848  63926   **
 63849  63927   ** If the table has a virtual root page, then the cursor is moved to point
................................................................................
 63917  63995     ** (or the freelist).  */
 63918  63996     assert( pRoot->intKey==1 || pRoot->intKey==0 );
 63919  63997     if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
 63920  63998       return SQLITE_CORRUPT_BKPT;
 63921  63999     }
 63922  64000   
 63923  64001   skip_init:  
 63924         -  pCur->aiIdx[0] = 0;
        64002  +  pCur->ix = 0;
 63925  64003     pCur->info.nSize = 0;
 63926  64004     pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidNKey|BTCF_ValidOvfl);
 63927  64005   
 63928  64006     pRoot = pCur->apPage[0];
 63929  64007     if( pRoot->nCell>0 ){
 63930  64008       pCur->eState = CURSOR_VALID;
 63931  64009     }else if( !pRoot->leaf ){
................................................................................
 63951  64029     Pgno pgno;
 63952  64030     int rc = SQLITE_OK;
 63953  64031     MemPage *pPage;
 63954  64032   
 63955  64033     assert( cursorOwnsBtShared(pCur) );
 63956  64034     assert( pCur->eState==CURSOR_VALID );
 63957  64035     while( rc==SQLITE_OK && !(pPage = pCur->apPage[pCur->iPage])->leaf ){
 63958         -    assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
 63959         -    pgno = get4byte(findCell(pPage, pCur->aiIdx[pCur->iPage]));
        64036  +    assert( pCur->ix<pPage->nCell );
        64037  +    pgno = get4byte(findCell(pPage, pCur->ix));
 63960  64038       rc = moveToChild(pCur, pgno);
 63961  64039     }
 63962  64040     return rc;
 63963  64041   }
 63964  64042   
 63965  64043   /*
 63966  64044   ** Move the cursor down to the right-most leaf entry beneath the
................................................................................
 63977  64055     int rc = SQLITE_OK;
 63978  64056     MemPage *pPage = 0;
 63979  64057   
 63980  64058     assert( cursorOwnsBtShared(pCur) );
 63981  64059     assert( pCur->eState==CURSOR_VALID );
 63982  64060     while( !(pPage = pCur->apPage[pCur->iPage])->leaf ){
 63983  64061       pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
 63984         -    pCur->aiIdx[pCur->iPage] = pPage->nCell;
        64062  +    pCur->ix = pPage->nCell;
 63985  64063       rc = moveToChild(pCur, pgno);
 63986  64064       if( rc ) return rc;
 63987  64065     }
 63988         -  pCur->aiIdx[pCur->iPage] = pPage->nCell-1;
        64066  +  pCur->ix = pPage->nCell-1;
 63989  64067     assert( pCur->info.nSize==0 );
 63990  64068     assert( (pCur->curFlags & BTCF_ValidNKey)==0 );
 63991  64069     return SQLITE_OK;
 63992  64070   }
 63993  64071   
 63994  64072   /* Move the cursor to the first entry in the table.  Return SQLITE_OK
 63995  64073   ** on success.  Set *pRes to 0 if the cursor actually points to something
................................................................................
 64029  64107   #ifdef SQLITE_DEBUG
 64030  64108       /* This block serves to assert() that the cursor really does point 
 64031  64109       ** to the last entry in the b-tree. */
 64032  64110       int ii;
 64033  64111       for(ii=0; ii<pCur->iPage; ii++){
 64034  64112         assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell );
 64035  64113       }
 64036         -    assert( pCur->aiIdx[pCur->iPage]==pCur->apPage[pCur->iPage]->nCell-1 );
        64114  +    assert( pCur->ix==pCur->apPage[pCur->iPage]->nCell-1 );
 64037  64115       assert( pCur->apPage[pCur->iPage]->leaf );
 64038  64116   #endif
 64039  64117       return SQLITE_OK;
 64040  64118     }
 64041  64119   
 64042  64120     rc = moveToRoot(pCur);
 64043  64121     if( rc==SQLITE_OK ){
................................................................................
 64176  64254       ** a moveToChild() or moveToRoot() call would have detected corruption.  */
 64177  64255       assert( pPage->nCell>0 );
 64178  64256       assert( pPage->intKey==(pIdxKey==0) );
 64179  64257       lwr = 0;
 64180  64258       upr = pPage->nCell-1;
 64181  64259       assert( biasRight==0 || biasRight==1 );
 64182  64260       idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */
 64183         -    pCur->aiIdx[pCur->iPage] = (u16)idx;
        64261  +    pCur->ix = (u16)idx;
 64184  64262       if( xRecordCompare==0 ){
 64185  64263         for(;;){
 64186  64264           i64 nCellKey;
 64187  64265           pCell = findCellPastPtr(pPage, idx);
 64188  64266           if( pPage->intKeyLeaf ){
 64189  64267             while( 0x80 <= *(pCell++) ){
 64190  64268               if( pCell>=pPage->aDataEnd ) return SQLITE_CORRUPT_BKPT;
................................................................................
 64195  64273             lwr = idx+1;
 64196  64274             if( lwr>upr ){ c = -1; break; }
 64197  64275           }else if( nCellKey>intKey ){
 64198  64276             upr = idx-1;
 64199  64277             if( lwr>upr ){ c = +1; break; }
 64200  64278           }else{
 64201  64279             assert( nCellKey==intKey );
 64202         -          pCur->aiIdx[pCur->iPage] = (u16)idx;
        64280  +          pCur->ix = (u16)idx;
 64203  64281             if( !pPage->leaf ){
 64204  64282               lwr = idx;
 64205  64283               goto moveto_next_layer;
 64206  64284             }else{
 64207  64285               pCur->curFlags |= BTCF_ValidNKey;
 64208  64286               pCur->info.nKey = nCellKey;
 64209  64287               pCur->info.nSize = 0;
................................................................................
 64264  64342               goto moveto_finish;
 64265  64343             }
 64266  64344             pCellKey = sqlite3Malloc( nCell+18 );
 64267  64345             if( pCellKey==0 ){
 64268  64346               rc = SQLITE_NOMEM_BKPT;
 64269  64347               goto moveto_finish;
 64270  64348             }
 64271         -          pCur->aiIdx[pCur->iPage] = (u16)idx;
        64349  +          pCur->ix = (u16)idx;
 64272  64350             rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
 64273  64351             pCur->curFlags &= ~BTCF_ValidOvfl;
 64274  64352             if( rc ){
 64275  64353               sqlite3_free(pCellKey);
 64276  64354               goto moveto_finish;
 64277  64355             }
 64278  64356             c = xRecordCompare(nCell, pCellKey, pIdxKey);
................................................................................
 64286  64364             lwr = idx+1;
 64287  64365           }else if( c>0 ){
 64288  64366             upr = idx-1;
 64289  64367           }else{
 64290  64368             assert( c==0 );
 64291  64369             *pRes = 0;
 64292  64370             rc = SQLITE_OK;
 64293         -          pCur->aiIdx[pCur->iPage] = (u16)idx;
        64371  +          pCur->ix = (u16)idx;
 64294  64372             if( pIdxKey->errCode ) rc = SQLITE_CORRUPT;
 64295  64373             goto moveto_finish;
 64296  64374           }
 64297  64375           if( lwr>upr ) break;
 64298  64376           assert( lwr+upr>=0 );
 64299  64377           idx = (lwr+upr)>>1;  /* idx = (lwr+upr)/2 */
 64300  64378         }
 64301  64379       }
 64302  64380       assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
 64303  64381       assert( pPage->isInit );
 64304  64382       if( pPage->leaf ){
 64305         -      assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
 64306         -      pCur->aiIdx[pCur->iPage] = (u16)idx;
        64383  +      assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
        64384  +      pCur->ix = (u16)idx;
 64307  64385         *pRes = c;
 64308  64386         rc = SQLITE_OK;
 64309  64387         goto moveto_finish;
 64310  64388       }
 64311  64389   moveto_next_layer:
 64312  64390       if( lwr>=pPage->nCell ){
 64313  64391         chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
 64314  64392       }else{
 64315  64393         chldPg = get4byte(findCell(pPage, lwr));
 64316  64394       }
 64317         -    pCur->aiIdx[pCur->iPage] = (u16)lwr;
        64395  +    pCur->ix = (u16)lwr;
 64318  64396       rc = moveToChild(pCur, chldPg);
 64319  64397       if( rc ) break;
 64320  64398     }
 64321  64399   moveto_finish:
 64322  64400     pCur->info.nSize = 0;
 64323  64401     assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
 64324  64402     return rc;
................................................................................
 64411  64489           return SQLITE_OK;
 64412  64490         }
 64413  64491         pCur->skipNext = 0;
 64414  64492       }
 64415  64493     }
 64416  64494   
 64417  64495     pPage = pCur->apPage[pCur->iPage];
 64418         -  idx = ++pCur->aiIdx[pCur->iPage];
        64496  +  idx = ++pCur->ix;
 64419  64497     assert( pPage->isInit );
 64420  64498   
 64421  64499     /* If the database file is corrupt, it is possible for the value of idx 
 64422  64500     ** to be invalid here. This can only occur if a second cursor modifies
 64423  64501     ** the page while cursor pCur is holding a reference to it. Which can
 64424  64502     ** only happen if the database is corrupt in such a way as to link the
 64425  64503     ** page into more than one b-tree structure. */
................................................................................
 64435  64513         if( pCur->iPage==0 ){
 64436  64514           *pRes = 1;
 64437  64515           pCur->eState = CURSOR_INVALID;
 64438  64516           return SQLITE_OK;
 64439  64517         }
 64440  64518         moveToParent(pCur);
 64441  64519         pPage = pCur->apPage[pCur->iPage];
 64442         -    }while( pCur->aiIdx[pCur->iPage]>=pPage->nCell );
        64520  +    }while( pCur->ix>=pPage->nCell );
 64443  64521       if( pPage->intKey ){
 64444  64522         return sqlite3BtreeNext(pCur, pRes);
 64445  64523       }else{
 64446  64524         return SQLITE_OK;
 64447  64525       }
 64448  64526     }
 64449  64527     if( pPage->leaf ){
................................................................................
 64459  64537     assert( *pRes==0 || *pRes==1 );
 64460  64538     assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
 64461  64539     pCur->info.nSize = 0;
 64462  64540     pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
 64463  64541     *pRes = 0;
 64464  64542     if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur, pRes);
 64465  64543     pPage = pCur->apPage[pCur->iPage];
 64466         -  if( (++pCur->aiIdx[pCur->iPage])>=pPage->nCell ){
 64467         -    pCur->aiIdx[pCur->iPage]--;
        64544  +  if( (++pCur->ix)>=pPage->nCell ){
        64545  +    pCur->ix--;
 64468  64546       return btreeNext(pCur, pRes);
 64469  64547     }
 64470  64548     if( pPage->leaf ){
 64471  64549       return SQLITE_OK;
 64472  64550     }else{
 64473  64551       return moveToLeftmost(pCur);
 64474  64552     }
................................................................................
 64524  64602         pCur->skipNext = 0;
 64525  64603       }
 64526  64604     }
 64527  64605   
 64528  64606     pPage = pCur->apPage[pCur->iPage];
 64529  64607     assert( pPage->isInit );
 64530  64608     if( !pPage->leaf ){
 64531         -    int idx = pCur->aiIdx[pCur->iPage];
        64609  +    int idx = pCur->ix;
 64532  64610       rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
 64533  64611       if( rc ) return rc;
 64534  64612       rc = moveToRightmost(pCur);
 64535  64613     }else{
 64536         -    while( pCur->aiIdx[pCur->iPage]==0 ){
        64614  +    while( pCur->ix==0 ){
 64537  64615         if( pCur->iPage==0 ){
 64538  64616           pCur->eState = CURSOR_INVALID;
 64539  64617           *pRes = 1;
 64540  64618           return SQLITE_OK;
 64541  64619         }
 64542  64620         moveToParent(pCur);
 64543  64621       }
 64544  64622       assert( pCur->info.nSize==0 );
 64545  64623       assert( (pCur->curFlags & (BTCF_ValidOvfl))==0 );
 64546  64624   
 64547         -    pCur->aiIdx[pCur->iPage]--;
        64625  +    pCur->ix--;
 64548  64626       pPage = pCur->apPage[pCur->iPage];
 64549  64627       if( pPage->intKey && !pPage->leaf ){
 64550  64628         rc = sqlite3BtreePrevious(pCur, pRes);
 64551  64629       }else{
 64552  64630         rc = SQLITE_OK;
 64553  64631       }
 64554  64632     }
................................................................................
 64559  64637     assert( pRes!=0 );
 64560  64638     assert( *pRes==0 || *pRes==1 );
 64561  64639     assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
 64562  64640     *pRes = 0;
 64563  64641     pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey);
 64564  64642     pCur->info.nSize = 0;
 64565  64643     if( pCur->eState!=CURSOR_VALID
 64566         -   || pCur->aiIdx[pCur->iPage]==0
        64644  +   || pCur->ix==0
 64567  64645      || pCur->apPage[pCur->iPage]->leaf==0
 64568  64646     ){
 64569  64647       return btreePrevious(pCur, pRes);
 64570  64648     }
 64571         -  pCur->aiIdx[pCur->iPage]--;
        64649  +  pCur->ix--;
 64572  64650     return SQLITE_OK;
 64573  64651   }
 64574  64652   
 64575  64653   /*
 64576  64654   ** Allocate a new page from the database file.
 64577  64655   **
 64578  64656   ** The new page is marked as dirty.  (In other words, sqlite3PagerWrite()
................................................................................
 66886  66964           ** next iteration of the do-loop will balance the child page.
 66887  66965           */ 
 66888  66966           assert( balance_deeper_called==0 );
 66889  66967           VVA_ONLY( balance_deeper_called++ );
 66890  66968           rc = balance_deeper(pPage, &pCur->apPage[1]);
 66891  66969           if( rc==SQLITE_OK ){
 66892  66970             pCur->iPage = 1;
        66971  +          pCur->ix = 0;
 66893  66972             pCur->aiIdx[0] = 0;
 66894         -          pCur->aiIdx[1] = 0;
 66895  66973             assert( pCur->apPage[1]->nOverflow );
 66896  66974           }
 66897  66975         }else{
 66898  66976           break;
 66899  66977         }
 66900  66978       }else if( pPage->nOverflow==0 && pPage->nFree<=nMin ){
 66901  66979         break;
................................................................................
 67064  67142       if( rc ) return rc;
 67065  67143     }
 67066  67144   
 67067  67145     if( pCur->pKeyInfo==0 ){
 67068  67146       assert( pX->pKey==0 );
 67069  67147       /* If this is an insert into a table b-tree, invalidate any incrblob 
 67070  67148       ** cursors open on the row being replaced */
 67071         -    invalidateIncrblobCursors(p, pX->nKey, 0);
        67149  +    invalidateIncrblobCursors(p, pCur->pgnoRoot, pX->nKey, 0);
 67072  67150   
 67073  67151       /* If BTREE_SAVEPOSITION is set, the cursor must already be pointing 
 67074  67152       ** to a row with the same key as the new entry being inserted.  */
 67075  67153       assert( (flags & BTREE_SAVEPOSITION)==0 || 
 67076  67154               ((pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey) );
 67077  67155   
 67078  67156       /* If the cursor is currently on the last row and we are appending a
 67079  67157       ** new row onto the end, set the "loc" to avoid an unnecessary
 67080  67158       ** btreeMoveto() call */
 67081  67159       if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){
 67082  67160         loc = 0;
 67083         -    }else if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey>0
 67084         -               && pCur->info.nKey==pX->nKey-1 ){
 67085         -      loc = -1;
 67086  67161       }else if( loc==0 ){
 67087  67162         rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, flags!=0, &loc);
 67088  67163         if( rc ) return rc;
 67089  67164       }
 67090  67165     }else if( loc==0 && (flags & BTREE_SAVEPOSITION)==0 ){
 67091  67166       if( pX->nMem ){
 67092  67167         UnpackedRecord r;
................................................................................
 67116  67191     assert( pPage->isInit );
 67117  67192     newCell = pBt->pTmpSpace;
 67118  67193     assert( newCell!=0 );
 67119  67194     rc = fillInCell(pPage, newCell, pX, &szNew);
 67120  67195     if( rc ) goto end_insert;
 67121  67196     assert( szNew==pPage->xCellSize(pPage, newCell) );
 67122  67197     assert( szNew <= MX_CELL_SIZE(pBt) );
 67123         -  idx = pCur->aiIdx[pCur->iPage];
        67198  +  idx = pCur->ix;
 67124  67199     if( loc==0 ){
 67125  67200       CellInfo info;
 67126  67201       assert( idx<pPage->nCell );
 67127  67202       rc = sqlite3PagerWrite(pPage->pDbPage);
 67128  67203       if( rc ){
 67129  67204         goto end_insert;
 67130  67205       }
 67131  67206       oldCell = findCell(pPage, idx);
 67132  67207       if( !pPage->leaf ){
 67133  67208         memcpy(newCell, oldCell, 4);
 67134  67209       }
 67135  67210       rc = clearCell(pPage, oldCell, &info);
 67136         -    if( info.nSize==szNew && info.nLocal==info.nPayload ){
        67211  +    if( info.nSize==szNew && info.nLocal==info.nPayload 
        67212  +     && (!ISAUTOVACUUM || szNew<pPage->minLocal)
        67213  +    ){
 67137  67214         /* Overwrite the old cell with the new if they are the same size.
 67138  67215         ** We could also try to do this if the old cell is smaller, then add
 67139  67216         ** the leftover space to the free list.  But experiments show that
 67140  67217         ** doing that is no faster then skipping this optimization and just
 67141         -      ** calling dropCell() and insertCell(). */
        67218  +      ** calling dropCell() and insertCell(). 
        67219  +      **
        67220  +      ** This optimization cannot be used on an autovacuum database if the
        67221  +      ** new entry uses overflow pages, as the insertCell() call below is
        67222  +      ** necessary to add the PTRMAP_OVERFLOW1 pointer-map entry.  */
 67142  67223         assert( rc==SQLITE_OK ); /* clearCell never fails when nLocal==nPayload */
 67143  67224         if( oldCell+szNew > pPage->aDataEnd ) return SQLITE_CORRUPT_BKPT;
 67144  67225         memcpy(oldCell, newCell, szNew);
 67145  67226         return SQLITE_OK;
 67146  67227       }
 67147  67228       dropCell(pPage, idx, info.nSize, &rc);
 67148  67229       if( rc ) goto end_insert;
 67149  67230     }else if( loc<0 && pPage->nCell>0 ){
 67150  67231       assert( pPage->leaf );
 67151         -    idx = ++pCur->aiIdx[pCur->iPage];
        67232  +    idx = ++pCur->ix;
        67233  +    pCur->curFlags &= ~BTCF_ValidNKey;
 67152  67234     }else{
 67153  67235       assert( pPage->leaf );
 67154  67236     }
 67155  67237     insertCell(pPage, idx, newCell, szNew, 0, 0, &rc);
 67156  67238     assert( pPage->nOverflow==0 || rc==SQLITE_OK );
 67157  67239     assert( rc!=SQLITE_OK || pPage->nCell>0 || pPage->nOverflow>0 );
 67158  67240   
................................................................................
 67240  67322   
 67241  67323     assert( cursorOwnsBtShared(pCur) );
 67242  67324     assert( pBt->inTransaction==TRANS_WRITE );
 67243  67325     assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
 67244  67326     assert( pCur->curFlags & BTCF_WriteFlag );
 67245  67327     assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
 67246  67328     assert( !hasReadConflicts(p, pCur->pgnoRoot) );
 67247         -  assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
        67329  +  assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
 67248  67330     assert( pCur->eState==CURSOR_VALID );
 67249  67331     assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
 67250  67332   
 67251  67333     iCellDepth = pCur->iPage;
 67252         -  iCellIdx = pCur->aiIdx[iCellDepth];
        67334  +  iCellIdx = pCur->ix;
 67253  67335     pPage = pCur->apPage[iCellDepth];
 67254  67336     pCell = findCell(pPage, iCellIdx);
 67255  67337   
 67256  67338     /* If the bPreserve flag is set to true, then the cursor position must
 67257  67339     ** be preserved following this delete operation. If the current delete
 67258  67340     ** will cause a b-tree rebalance, then this is done by saving the cursor
 67259  67341     ** key and leaving the cursor in CURSOR_REQUIRESEEK state before 
................................................................................
 67294  67376       rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
 67295  67377       if( rc ) return rc;
 67296  67378     }
 67297  67379   
 67298  67380     /* If this is a delete operation to remove a row from a table b-tree,
 67299  67381     ** invalidate any incrblob cursors open on the row being deleted.  */
 67300  67382     if( pCur->pKeyInfo==0 ){
 67301         -    invalidateIncrblobCursors(p, pCur->info.nKey, 0);
        67383  +    invalidateIncrblobCursors(p, pCur->pgnoRoot, pCur->info.nKey, 0);
 67302  67384     }
 67303  67385   
 67304  67386     /* Make the page containing the entry to be deleted writable. Then free any
 67305  67387     ** overflow pages associated with the entry and finally remove the cell
 67306  67388     ** itself from within the page.  */
 67307  67389     rc = sqlite3PagerWrite(pPage->pDbPage);
 67308  67390     if( rc ) return rc;
................................................................................
 67362  67444       if( bSkipnext ){
 67363  67445         assert( bPreserve && (pCur->iPage==iCellDepth || CORRUPT_DB) );
 67364  67446         assert( pPage==pCur->apPage[pCur->iPage] || CORRUPT_DB );
 67365  67447         assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
 67366  67448         pCur->eState = CURSOR_SKIPNEXT;
 67367  67449         if( iCellIdx>=pPage->nCell ){
 67368  67450           pCur->skipNext = -1;
 67369         -        pCur->aiIdx[iCellDepth] = pPage->nCell-1;
        67451  +        pCur->ix = pPage->nCell-1;
 67370  67452         }else{
 67371  67453           pCur->skipNext = 1;
 67372  67454         }
 67373  67455       }else{
 67374  67456         rc = moveToRoot(pCur);
 67375  67457         if( bPreserve ){
 67376  67458           pCur->eState = CURSOR_REQUIRESEEK;
................................................................................
 67621  67703   
 67622  67704     rc = saveAllCursors(pBt, (Pgno)iTable, 0);
 67623  67705   
 67624  67706     if( SQLITE_OK==rc ){
 67625  67707       /* Invalidate all incrblob cursors open on table iTable (assuming iTable
 67626  67708       ** is the root of a table b-tree - if it is not, the following call is
 67627  67709       ** a no-op).  */
 67628         -    invalidateIncrblobCursors(p, 0, 1);
        67710  +    invalidateIncrblobCursors(p, (Pgno)iTable, 0, 1);
 67629  67711       rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
 67630  67712     }
 67631  67713     sqlite3BtreeLeave(p);
 67632  67714     return rc;
 67633  67715   }
 67634  67716   
 67635  67717   /*
................................................................................
 67875  67957         do {
 67876  67958           if( pCur->iPage==0 ){
 67877  67959             /* All pages of the b-tree have been visited. Return successfully. */
 67878  67960             *pnEntry = nEntry;
 67879  67961             return moveToRoot(pCur);
 67880  67962           }
 67881  67963           moveToParent(pCur);
 67882         -      }while ( pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell );
        67964  +      }while ( pCur->ix>=pCur->apPage[pCur->iPage]->nCell );
 67883  67965   
 67884         -      pCur->aiIdx[pCur->iPage]++;
        67966  +      pCur->ix++;
 67885  67967         pPage = pCur->apPage[pCur->iPage];
 67886  67968       }
 67887  67969   
 67888  67970       /* Descend to the child node of the cell that the cursor currently 
 67889  67971       ** points at. This is the right-child if (iIdx==pPage->nCell).
 67890  67972       */
 67891         -    iIdx = pCur->aiIdx[pCur->iPage];
        67973  +    iIdx = pCur->ix;
 67892  67974       if( iIdx==pPage->nCell ){
 67893  67975         rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
 67894  67976       }else{
 67895  67977         rc = moveToChild(pCur, get4byte(findCell(pPage, iIdx)));
 67896  67978       }
 67897  67979     }
 67898  67980   
................................................................................
 68269  68351   
 68270  68352       /* Check for integer primary key out of range */
 68271  68353       if( pPage->intKey ){
 68272  68354         if( keyCanBeEqual ? (info.nKey > maxKey) : (info.nKey >= maxKey) ){
 68273  68355           checkAppendMsg(pCheck, "Rowid %lld out of order", info.nKey);
 68274  68356         }
 68275  68357         maxKey = info.nKey;
        68358  +      keyCanBeEqual = 0;     /* Only the first key on the page may ==maxKey */
 68276  68359       }
 68277  68360   
 68278  68361       /* Check the content overflow list */
 68279  68362       if( info.nPayload>info.nLocal ){
 68280  68363         int nPage;       /* Number of pages on the overflow chain */
 68281  68364         Pgno pgnoOvfl;   /* First page of the overflow chain */
 68282  68365         assert( pc + info.nSize - 4 <= usableSize );
................................................................................
 69654  69737     ** Mem.z = Mem.zMalloc without having to check Mem.flags&MEM_Dyn.
 69655  69738     ** That saves a few cycles in inner loops. */
 69656  69739     assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
 69657  69740   
 69658  69741     /* Cannot be both MEM_Int and MEM_Real at the same time */
 69659  69742     assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
 69660  69743   
        69744  +  /* Cannot be both MEM_Null and some other type */
        69745  +  assert( (p->flags & MEM_Null)==0 ||
        69746  +          (p->flags & (MEM_Int|MEM_Real|MEM_Str|MEM_Blob))==0 );
        69747  +
 69661  69748     /* The szMalloc field holds the correct memory allocation size */
 69662  69749     assert( p->szMalloc==0
 69663  69750          || p->szMalloc==sqlite3DbMallocSize(p->db,p->zMalloc) );
 69664  69751   
 69665  69752     /* If p holds a string or blob, the Mem.z must point to exactly
 69666  69753     ** one of the following:
 69667  69754     **
................................................................................
 69739  69826     /* If the bPreserve flag is set to true, then the memory cell must already
 69740  69827     ** contain a valid string or blob value.  */
 69741  69828     assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
 69742  69829     testcase( bPreserve && pMem->z==0 );
 69743  69830   
 69744  69831     assert( pMem->szMalloc==0
 69745  69832          || pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) );
 69746         -  if( pMem->szMalloc<n ){
 69747         -    if( n<32 ) n = 32;
 69748         -    if( bPreserve && pMem->szMalloc>0 && pMem->z==pMem->zMalloc ){
 69749         -      pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
 69750         -      bPreserve = 0;
 69751         -    }else{
 69752         -      if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc);
 69753         -      pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
 69754         -    }
 69755         -    if( pMem->zMalloc==0 ){
 69756         -      sqlite3VdbeMemSetNull(pMem);
 69757         -      pMem->z = 0;
 69758         -      pMem->szMalloc = 0;
 69759         -      return SQLITE_NOMEM_BKPT;
 69760         -    }else{
 69761         -      pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
 69762         -    }
        69833  +  if( n<32 ) n = 32;
        69834  +  if( bPreserve && pMem->szMalloc>0 && pMem->z==pMem->zMalloc ){
        69835  +    pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
        69836  +    bPreserve = 0;
        69837  +  }else{
        69838  +    if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
        69839  +    pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
        69840  +  }
        69841  +  if( pMem->zMalloc==0 ){
        69842  +    sqlite3VdbeMemSetNull(pMem);
        69843  +    pMem->z = 0;
        69844  +    pMem->szMalloc = 0;
        69845  +    return SQLITE_NOMEM_BKPT;
        69846  +  }else{
        69847  +    pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
 69763  69848     }
 69764  69849   
 69765         -  if( bPreserve && pMem->z && pMem->z!=pMem->zMalloc ){
        69850  +  if( bPreserve && pMem->z && ALWAYS(pMem->z!=pMem->zMalloc) ){
 69766  69851       memcpy(pMem->zMalloc, pMem->z, pMem->n);
 69767  69852     }
 69768  69853     if( (pMem->flags&MEM_Dyn)!=0 ){
 69769  69854       assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
 69770  69855       pMem->xDel((void *)(pMem->z));
 69771  69856     }
 69772  69857   
................................................................................
 69955  70040       t.flags = MEM_Null;
 69956  70041       t.db = pMem->db;
 69957  70042       ctx.pOut = &t;
 69958  70043       ctx.pMem = pMem;
 69959  70044       ctx.pFunc = pFunc;
 69960  70045       pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */
 69961  70046       assert( (pMem->flags & MEM_Dyn)==0 );
 69962         -    if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc);
        70047  +    if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
 69963  70048       memcpy(pMem, &t, sizeof(t));
 69964  70049       rc = ctx.isError;
 69965  70050     }
 69966  70051     return rc;
 69967  70052   }
 69968  70053   
 69969  70054   /*
................................................................................
 70006  70091   ** to be freed.
 70007  70092   */
 70008  70093   static SQLITE_NOINLINE void vdbeMemClear(Mem *p){
 70009  70094     if( VdbeMemDynamic(p) ){
 70010  70095       vdbeMemClearExternAndSetNull(p);
 70011  70096     }
 70012  70097     if( p->szMalloc ){
 70013         -    sqlite3DbFree(p->db, p->zMalloc);
        70098  +    sqlite3DbFreeNN(p->db, p->zMalloc);
 70014  70099       p->szMalloc = 0;
 70015  70100     }
 70016  70101     p->z = 0;
 70017  70102   }
 70018  70103   
 70019  70104   /*
 70020  70105   ** Release any memory resources held by the Mem.  Both the memory that is
................................................................................
 70034  70119   }
 70035  70120   
 70036  70121   /*
 70037  70122   ** Convert a 64-bit IEEE double into a 64-bit signed integer.
 70038  70123   ** If the double is out of range of a 64-bit signed integer then
 70039  70124   ** return the closest available 64-bit signed integer.
 70040  70125   */
 70041         -static i64 doubleToInt64(double r){
        70126  +static SQLITE_NOINLINE i64 doubleToInt64(double r){
 70042  70127   #ifdef SQLITE_OMIT_FLOATING_POINT
 70043  70128     /* When floating-point is omitted, double and int64 are the same thing */
 70044  70129     return r;
 70045  70130   #else
 70046  70131     /*
 70047  70132     ** Many compilers we encounter do not define constants for the
 70048  70133     ** minimum and maximum 64-bit integers, or they define them
................................................................................
 70070  70155   ** a floating-point then the value returned is the integer part.
 70071  70156   ** If pMem is a string or blob, then we make an attempt to convert
 70072  70157   ** it into an integer and return that.  If pMem represents an
 70073  70158   ** an SQL-NULL value, return 0.
 70074  70159   **
 70075  70160   ** If pMem represents a string value, its encoding might be changed.
 70076  70161   */
        70162  +static SQLITE_NOINLINE i64 memIntValue(Mem *pMem){
        70163  +  i64 value = 0;
        70164  +  sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
        70165  +  return value;
        70166  +}
 70077  70167   SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem *pMem){
 70078  70168     int flags;
 70079  70169     assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
 70080  70170     assert( EIGHT_BYTE_ALIGNMENT(pMem) );
 70081  70171     flags = pMem->flags;
 70082  70172     if( flags & MEM_Int ){
 70083  70173       return pMem->u.i;
 70084  70174     }else if( flags & MEM_Real ){
 70085  70175       return doubleToInt64(pMem->u.r);
 70086  70176     }else if( flags & (MEM_Str|MEM_Blob) ){
 70087         -    i64 value = 0;
 70088  70177       assert( pMem->z || pMem->n==0 );
 70089         -    sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
 70090         -    return value;
        70178  +    return memIntValue(pMem);
 70091  70179     }else{
 70092  70180       return 0;
 70093  70181     }
 70094  70182   }
 70095  70183   
 70096  70184   /*
 70097  70185   ** Return the best representation of pMem that we can get into a
 70098  70186   ** double.  If pMem is already a double or an integer, return its
 70099  70187   ** value.  If it is a string or blob, try to convert it to a double.
 70100  70188   ** If it is a NULL, return 0.0.
 70101  70189   */
        70190  +static SQLITE_NOINLINE double memRealValue(Mem *pMem){
        70191  +  /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
        70192  +  double val = (double)0;
        70193  +  sqlite3AtoF(pMem->z, &val, pMem->n, pMem->enc);
        70194  +  return val;
        70195  +}
 70102  70196   SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){
 70103  70197     assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
 70104  70198     assert( EIGHT_BYTE_ALIGNMENT(pMem) );
 70105  70199     if( pMem->flags & MEM_Real ){
 70106  70200       return pMem->u.r;
 70107  70201     }else if( pMem->flags & MEM_Int ){
 70108  70202       return (double)pMem->u.i;
 70109  70203     }else if( pMem->flags & (MEM_Str|MEM_Blob) ){
 70110         -    /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
 70111         -    double val = (double)0;
 70112         -    sqlite3AtoF(pMem->z, &val, pMem->n, pMem->enc);
 70113         -    return val;
        70204  +    return memRealValue(pMem);
 70114  70205     }else{
 70115  70206       /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
 70116  70207       return (double)0;
 70117  70208     }
 70118  70209   }
 70119  70210   
 70120  70211   /*
................................................................................
 70731  70822             assert( pRec->pKeyInfo->enc==ENC(db) );
 70732  70823             pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
 70733  70824             for(i=0; i<nCol; i++){
 70734  70825               pRec->aMem[i].flags = MEM_Null;
 70735  70826               pRec->aMem[i].db = db;
 70736  70827             }
 70737  70828           }else{
 70738         -          sqlite3DbFree(db, pRec);
        70829  +          sqlite3DbFreeNN(db, pRec);
 70739  70830             pRec = 0;
 70740  70831           }
 70741  70832         }
 70742  70833         if( pRec==0 ) return 0;
 70743  70834         p->ppRec[0] = pRec;
 70744  70835       }
 70745  70836     
................................................................................
 70843  70934     if( rc!=SQLITE_OK ){
 70844  70935       pVal = 0;
 70845  70936     }
 70846  70937     if( apVal ){
 70847  70938       for(i=0; i<nVal; i++){
 70848  70939         sqlite3ValueFree(apVal[i]);
 70849  70940       }
 70850         -    sqlite3DbFree(db, apVal);
        70941  +    sqlite3DbFreeNN(db, apVal);
 70851  70942     }
 70852  70943   
 70853  70944     *ppVal = pVal;
 70854  70945     return rc;
 70855  70946   }
 70856  70947   #else
 70857  70948   # define valueFromFunction(a,b,c,d,e,f) SQLITE_OK
................................................................................
 71042  71133     if( aRet==0 ){
 71043  71134       sqlite3_result_error_nomem(context);
 71044  71135     }else{
 71045  71136       aRet[0] = nSerial+1;
 71046  71137       putVarint32(&aRet[1], iSerial);
 71047  71138       sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], iSerial);
 71048  71139       sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT);
 71049         -    sqlite3DbFree(db, aRet);
        71140  +    sqlite3DbFreeNN(db, aRet);
 71050  71141     }
 71051  71142   }
 71052  71143   
 71053  71144   /*
 71054  71145   ** Register built-in functions used to help read ANALYZE data.
 71055  71146   */
 71056  71147   SQLITE_PRIVATE void sqlite3AnalyzeFunctions(void){
................................................................................
 71269  71360       int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField;
 71270  71361       Mem *aMem = pRec->aMem;
 71271  71362       sqlite3 *db = aMem[0].db;
 71272  71363       for(i=0; i<nCol; i++){
 71273  71364         sqlite3VdbeMemRelease(&aMem[i]);
 71274  71365       }
 71275  71366       sqlite3KeyInfoUnref(pRec->pKeyInfo);
 71276         -    sqlite3DbFree(db, pRec);
        71367  +    sqlite3DbFreeNN(db, pRec);
 71277  71368     }
 71278  71369   }
 71279  71370   #endif /* ifdef SQLITE_ENABLE_STAT4 */
 71280  71371   
 71281  71372   /*
 71282  71373   ** Change the string value of an sqlite3_value object
 71283  71374   */
................................................................................
 71293  71384   
 71294  71385   /*
 71295  71386   ** Free an sqlite3_value object
 71296  71387   */
 71297  71388   SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value *v){
 71298  71389     if( !v ) return;
 71299  71390     sqlite3VdbeMemRelease((Mem *)v);
 71300         -  sqlite3DbFree(((Mem*)v)->db, v);
        71391  +  sqlite3DbFreeNN(((Mem*)v)->db, v);
 71301  71392   }
 71302  71393   
 71303  71394   /*
 71304  71395   ** The sqlite3ValueBytes() routine returns the number of bytes in the
 71305  71396   ** sqlite3_value object assuming that it uses the encoding "enc".
 71306  71397   ** The valueBytes() routine is a helper function.
 71307  71398   */
................................................................................
 72136  72227   
 72137  72228   /*
 72138  72229   ** If the input FuncDef structure is ephemeral, then free it.  If
 72139  72230   ** the FuncDef is not ephermal, then do nothing.
 72140  72231   */
 72141  72232   static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
 72142  72233     if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
 72143         -    sqlite3DbFree(db, pDef);
        72234  +    sqlite3DbFreeNN(db, pDef);
 72144  72235     }
 72145  72236   }
 72146  72237   
 72147  72238   static void vdbeFreeOpArray(sqlite3 *, Op *, int);
 72148  72239   
 72149  72240   /*
 72150  72241   ** Delete a P4 value if necessary.
 72151  72242   */
 72152  72243   static SQLITE_NOINLINE void freeP4Mem(sqlite3 *db, Mem *p){
 72153  72244     if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
 72154         -  sqlite3DbFree(db, p);
        72245  +  sqlite3DbFreeNN(db, p);
 72155  72246   }
 72156  72247   static SQLITE_NOINLINE void freeP4FuncCtx(sqlite3 *db, sqlite3_context *p){
 72157  72248     freeEphemeralFunction(db, p->pFunc);
 72158         -  sqlite3DbFree(db, p);
        72249  + sqlite3DbFreeNN(db, p);
 72159  72250   }
 72160  72251   static void freeP4(sqlite3 *db, int p4type, void *p4){
 72161  72252     assert( db );
 72162  72253     switch( p4type ){
 72163  72254       case P4_FUNCCTX: {
 72164  72255         freeP4FuncCtx(db, (sqlite3_context*)p4);
 72165  72256         break;
................................................................................
 72204  72295   ** Free the space allocated for aOp and any p4 values allocated for the
 72205  72296   ** opcodes contained within. If aOp is not NULL it is assumed to contain 
 72206  72297   ** nOp entries. 
 72207  72298   */
 72208  72299   static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
 72209  72300     if( aOp ){
 72210  72301       Op *pOp;
 72211         -    for(pOp=aOp; pOp<&aOp[nOp]; pOp++){
        72302  +    for(pOp=&aOp[nOp-1]; pOp>=aOp; pOp--){
 72212  72303         if( pOp->p4type ) freeP4(db, pOp->p4type, pOp->p4.p);
 72213  72304   #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
 72214  72305         sqlite3DbFree(db, pOp->zComment);
 72215  72306   #endif     
 72216  72307       }
        72308  +    sqlite3DbFreeNN(db, aOp);
 72217  72309     }
 72218         -  sqlite3DbFree(db, aOp);
 72219  72310   }
 72220  72311   
 72221  72312   /*
 72222  72313   ** Link the SubProgram object passed as the second argument into the linked
 72223  72314   ** list at Vdbe.pSubProgram. This list is used to delete all sub-program
 72224  72315   ** objects when the VM is no longer required.
 72225  72316   */
................................................................................
 72884  72975         testcase( p->flags & MEM_Agg );
 72885  72976         testcase( p->flags & MEM_Dyn );
 72886  72977         testcase( p->flags & MEM_Frame );
 72887  72978         testcase( p->flags & MEM_RowSet );
 72888  72979         if( p->flags&(MEM_Agg|MEM_Dyn|MEM_Frame|MEM_RowSet) ){
 72889  72980           sqlite3VdbeMemRelease(p);
 72890  72981         }else if( p->szMalloc ){
 72891         -        sqlite3DbFree(db, p->zMalloc);
        72982  +        sqlite3DbFreeNN(db, p->zMalloc);
 72892  72983           p->szMalloc = 0;
 72893  72984         }
 72894  72985   
 72895  72986         p->flags = MEM_Undefined;
 72896  72987       }while( (++p)<pEnd );
 72897  72988     }
 72898  72989   }
................................................................................
 73360  73451     assert( pCx->pBtx==0 || pCx->eCurType==CURTYPE_BTREE );
 73361  73452     switch( pCx->eCurType ){
 73362  73453       case CURTYPE_SORTER: {
 73363  73454         sqlite3VdbeSorterClose(p->db, pCx);
 73364  73455         break;
 73365  73456       }
 73366  73457       case CURTYPE_BTREE: {
 73367         -      if( pCx->pBtx ){
 73368         -        sqlite3BtreeClose(pCx->pBtx);
        73458  +      if( pCx->isEphemeral ){
        73459  +        if( pCx->pBtx ) sqlite3BtreeClose(pCx->pBtx);
 73369  73460           /* The pCx->pCursor will be close automatically, if it exists, by
 73370  73461           ** the call above. */
 73371  73462         }else{
 73372  73463           assert( pCx->uc.pCursor!=0 );
 73373  73464           sqlite3BtreeCloseCursor(pCx->uc.pCursor);
 73374  73465         }
 73375  73466         break;
................................................................................
 74255  74346           fprintf(out, "%s", zHdr);
 74256  74347           sqlite3VdbePrintOp(out, i, &p->aOp[i]);
 74257  74348         }
 74258  74349         fclose(out);
 74259  74350       }
 74260  74351     }
 74261  74352   #endif
 74262         -  p->iCurrentTime = 0;
 74263  74353     p->magic = VDBE_MAGIC_RESET;
 74264  74354     return p->rc & db->errMask;
 74265  74355   }
 74266  74356    
 74267  74357   /*
 74268  74358   ** Clean up and delete a VDBE after execution.  Return an integer which is
 74269  74359   ** the result code.  Write any error message text into *pzErrMsg.
................................................................................
 74294  74384   **    * the corresponding bit in argument mask is clear (where the first
 74295  74385   **      function parameter corresponds to bit 0 etc.).
 74296  74386   */
 74297  74387   SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(sqlite3 *db, AuxData **pp, int iOp, int mask){
 74298  74388     while( *pp ){
 74299  74389       AuxData *pAux = *pp;
 74300  74390       if( (iOp<0)
 74301         -     || (pAux->iOp==iOp && (pAux->iArg>31 || !(mask & MASKBIT32(pAux->iArg))))
        74391  +     || (pAux->iAuxOp==iOp
        74392  +          && pAux->iAuxArg>=0
        74393  +          && (pAux->iAuxArg>31 || !(mask & MASKBIT32(pAux->iAuxArg))))
 74302  74394       ){
 74303         -      testcase( pAux->iArg==31 );
 74304         -      if( pAux->xDelete ){
 74305         -        pAux->xDelete(pAux->pAux);
        74395  +      testcase( pAux->iAuxArg==31 );
        74396  +      if( pAux->xDeleteAux ){
        74397  +        pAux->xDeleteAux(pAux->pAux);
 74306  74398         }
 74307         -      *pp = pAux->pNext;
        74399  +      *pp = pAux->pNextAux;
 74308  74400         sqlite3DbFree(db, pAux);
 74309  74401       }else{
 74310         -      pp= &pAux->pNext;
        74402  +      pp= &pAux->pNextAux;
 74311  74403       }
 74312  74404     }
 74313  74405   }
 74314  74406   
 74315  74407   /*
 74316  74408   ** Free all memory associated with the Vdbe passed as the second argument,
 74317  74409   ** except for object itself, which is preserved.
................................................................................
 74365  74457       db->pVdbe = p->pNext;
 74366  74458     }
 74367  74459     if( p->pNext ){
 74368  74460       p->pNext->pPrev = p->pPrev;
 74369  74461     }
 74370  74462     p->magic = VDBE_MAGIC_DEAD;
 74371  74463     p->db = 0;
 74372         -  sqlite3DbFree(db, p);
        74464  +  sqlite3DbFreeNN(db, p);
 74373  74465   }
 74374  74466   
 74375  74467   /*
 74376  74468   ** The cursor "p" has a pending seek operation that has not yet been
 74377  74469   ** carried out.  Seek the cursor now.  If an error occurs, return
 74378  74470   ** the appropriate error code.
 74379  74471   */
................................................................................
 75924  76016   static void vdbeFreeUnpacked(sqlite3 *db, int nField, UnpackedRecord *p){
 75925  76017     if( p ){
 75926  76018       int i;
 75927  76019       for(i=0; i<nField; i++){
 75928  76020         Mem *pMem = &p->aMem[i];
 75929  76021         if( pMem->zMalloc ) sqlite3VdbeMemRelease(pMem);
 75930  76022       }
 75931         -    sqlite3DbFree(db, p);
        76023  +    sqlite3DbFreeNN(db, p);
 75932  76024     }
 75933  76025   }
 75934  76026   #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
 75935  76027   
 75936  76028   #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
 75937  76029   /*
 75938  76030   ** Invoke the pre-update hook. If this is an UPDATE or DELETE pre-update call,
................................................................................
 75991  76083     vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pUnpacked);
 75992  76084     vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pNewUnpacked);
 75993  76085     if( preupdate.aNew ){
 75994  76086       int i;
 75995  76087       for(i=0; i<pCsr->nField; i++){
 75996  76088         sqlite3VdbeMemRelease(&preupdate.aNew[i]);
 75997  76089       }
 75998         -    sqlite3DbFree(db, preupdate.aNew);
        76090  +    sqlite3DbFreeNN(db, preupdate.aNew);
 75999  76091     }
 76000  76092   }
 76001  76093   #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
 76002  76094   
 76003  76095   /************** End of vdbeaux.c *********************************************/
 76004  76096   /************** Begin file vdbeapi.c *****************************************/
 76005  76097   /*
................................................................................
 76804  76896       return (void*)p->pMem->z;
 76805  76897     }
 76806  76898   }
 76807  76899   
 76808  76900   /*
 76809  76901   ** Return the auxiliary data pointer, if any, for the iArg'th argument to
 76810  76902   ** the user-function defined by pCtx.
        76903  +**
        76904  +** The left-most argument is 0.
        76905  +**
        76906  +** Undocumented behavior:  If iArg is negative then access a cache of
        76907  +** auxiliary data pointers that is available to all functions within a
        76908  +** single prepared statement.  The iArg values must match.
 76811  76909   */
 76812  76910   SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
 76813  76911     AuxData *pAuxData;
 76814  76912   
 76815  76913     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 76816  76914   #if SQLITE_ENABLE_STAT3_OR_STAT4
 76817  76915     if( pCtx->pVdbe==0 ) return 0;
 76818  76916   #else
 76819  76917     assert( pCtx->pVdbe!=0 );
 76820  76918   #endif
 76821         -  for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
 76822         -    if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
        76919  +  for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNextAux){
        76920  +    if(  pAuxData->iAuxArg==iArg && (pAuxData->iAuxOp==pCtx->iOp || iArg<0) ){
        76921  +      return pAuxData->pAux;
        76922  +    }
 76823  76923     }
 76824         -
 76825         -  return (pAuxData ? pAuxData->pAux : 0);
        76924  +  return 0;
 76826  76925   }
 76827  76926   
 76828  76927   /*
 76829  76928   ** Set the auxiliary data pointer and delete function, for the iArg'th
 76830  76929   ** argument to the user-function defined by pCtx. Any previous value is
 76831  76930   ** deleted by calling the delete function specified when it was set.
        76931  +**
        76932  +** The left-most argument is 0.
        76933  +**
        76934  +** Undocumented behavior:  If iArg is negative then make the data available
        76935  +** to all functions within the current prepared statement using iArg as an
        76936  +** access code.
 76832  76937   */
 76833  76938   SQLITE_API void sqlite3_set_auxdata(
 76834  76939     sqlite3_context *pCtx, 
 76835  76940     int iArg, 
 76836  76941     void *pAux, 
 76837  76942     void (*xDelete)(void*)
 76838  76943   ){
 76839  76944     AuxData *pAuxData;
 76840  76945     Vdbe *pVdbe = pCtx->pVdbe;
 76841  76946   
 76842  76947     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 76843         -  if( iArg<0 ) goto failed;
 76844  76948   #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
 76845  76949     if( pVdbe==0 ) goto failed;
 76846  76950   #else
 76847  76951     assert( pVdbe!=0 );
 76848  76952   #endif
 76849  76953   
 76850         -  for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
 76851         -    if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
        76954  +  for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNextAux){
        76955  +    if( pAuxData->iAuxArg==iArg && (pAuxData->iAuxOp==pCtx->iOp || iArg<0) ){
        76956  +      break;
        76957  +    }
 76852  76958     }
 76853  76959     if( pAuxData==0 ){
 76854  76960       pAuxData = sqlite3DbMallocZero(pVdbe->db, sizeof(AuxData));
 76855  76961       if( !pAuxData ) goto failed;
 76856         -    pAuxData->iOp = pCtx->iOp;
 76857         -    pAuxData->iArg = iArg;
 76858         -    pAuxData->pNext = pVdbe->pAuxData;
        76962  +    pAuxData->iAuxOp = pCtx->iOp;
        76963  +    pAuxData->iAuxArg = iArg;
        76964  +    pAuxData->pNextAux = pVdbe->pAuxData;
 76859  76965       pVdbe->pAuxData = pAuxData;
 76860  76966       if( pCtx->fErrorOrAux==0 ){
 76861  76967         pCtx->isError = 0;
 76862  76968         pCtx->fErrorOrAux = 1;
 76863  76969       }
 76864         -  }else if( pAuxData->xDelete ){
 76865         -    pAuxData->xDelete(pAuxData->pAux);
        76970  +  }else if( pAuxData->xDeleteAux ){
        76971  +    pAuxData->xDeleteAux(pAuxData->pAux);
 76866  76972     }
 76867  76973   
 76868  76974     pAuxData->pAux = pAux;
 76869         -  pAuxData->xDelete = xDelete;
        76975  +  pAuxData->xDeleteAux = xDelete;
 76870  76976     return;
 76871  76977   
 76872  76978   failed:
 76873  76979     if( xDelete ){
 76874  76980       xDelete(pAux);
 76875  76981     }
 76876  76982   }
................................................................................
 78577  78683     }
 78578  78684     if( p->flags & MEM_Subtype ) printf(" subtype=0x%02x", p->eSubtype);
 78579  78685   }
 78580  78686   static void registerTrace(int iReg, Mem *p){
 78581  78687     printf("REG[%d] = ", iReg);
 78582  78688     memTracePrint(p);
 78583  78689     printf("\n");
        78690  +  sqlite3VdbeCheckMemInvariants(p);
 78584  78691   }
 78585  78692   #endif
 78586  78693   
 78587  78694   #ifdef SQLITE_DEBUG
 78588  78695   #  define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
 78589  78696   #else
 78590  78697   #  define REGISTER_TRACE(R,M)
................................................................................
 78943  79050   ** to the current line should be indented for EXPLAIN output.
 78944  79051   */
 78945  79052   case OP_Goto: {             /* jump */
 78946  79053   jump_to_p2_and_check_for_interrupt:
 78947  79054     pOp = &aOp[pOp->p2 - 1];
 78948  79055   
 78949  79056     /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
 78950         -  ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon
        79057  +  ** OP_VNext, or OP_SorterNext) all jump here upon
 78951  79058     ** completion.  Check to see if sqlite3_interrupt() has been called
 78952  79059     ** or if the progress callback needs to be invoked. 
 78953  79060     **
 78954  79061     ** This code uses unstructured "goto" statements and does not look clean.
 78955  79062     ** But that is not due to sloppy coding habits. The code is written this
 78956  79063     ** way for performance, to avoid having to run the interrupt and progress
 78957  79064     ** checks on every opcode.  This helps sqlite3_step() to run about 1.5%
................................................................................
 79331  79438   ** instruction, but do not free any string or blob memory associated with
 79332  79439   ** the register, so that if the value was a string or blob that was
 79333  79440   ** previously copied using OP_SCopy, the copies will continue to be valid.
 79334  79441   */
 79335  79442   case OP_SoftNull: {
 79336  79443     assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
 79337  79444     pOut = &aMem[pOp->p1];
 79338         -  pOut->flags = (pOut->flags|MEM_Null)&~MEM_Undefined;
        79445  +  pOut->flags = (pOut->flags&~(MEM_Undefined|MEM_AffMask))|MEM_Null;
 79339  79446     break;
 79340  79447   }
 79341  79448   
 79342  79449   /* Opcode: Blob P1 P2 * P4 *
 79343  79450   ** Synopsis: r[P2]=P4 (len=P1)
 79344  79451   **
 79345  79452   ** P4 points to a blob of data P1 bytes long.  Store this
................................................................................
 79674  79781   
 79675  79782     pIn1 = &aMem[pOp->p1];
 79676  79783     type1 = numericType(pIn1);
 79677  79784     pIn2 = &aMem[pOp->p2];
 79678  79785     type2 = numericType(pIn2);
 79679  79786     pOut = &aMem[pOp->p3];
 79680  79787     flags = pIn1->flags | pIn2->flags;
 79681         -  if( (flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
 79682  79788     if( (type1 & type2 & MEM_Int)!=0 ){
 79683  79789       iA = pIn1->u.i;
 79684  79790       iB = pIn2->u.i;
 79685  79791       bIntint = 1;
 79686  79792       switch( pOp->opcode ){
 79687  79793         case OP_Add:       if( sqlite3AddInt64(&iB,iA) ) goto fp_math;  break;
 79688  79794         case OP_Subtract:  if( sqlite3SubInt64(&iB,iA) ) goto fp_math;  break;
................................................................................
 79698  79804           if( iA==-1 ) iA = 1;
 79699  79805           iB %= iA;
 79700  79806           break;
 79701  79807         }
 79702  79808       }
 79703  79809       pOut->u.i = iB;
 79704  79810       MemSetTypeFlag(pOut, MEM_Int);
        79811  +  }else if( (flags & MEM_Null)!=0 ){
        79812  +    goto arithmetic_result_is_null;
 79705  79813     }else{
 79706  79814       bIntint = 0;
 79707  79815   fp_math:
 79708  79816       rA = sqlite3VdbeRealValue(pIn1);
 79709  79817       rB = sqlite3VdbeRealValue(pIn2);
 79710  79818       switch( pOp->opcode ){
 79711  79819         case OP_Add:         rB += rA;       break;
................................................................................
 79745  79853   arithmetic_result_is_null:
 79746  79854     sqlite3VdbeMemSetNull(pOut);
 79747  79855     break;
 79748  79856   }
 79749  79857   
 79750  79858   /* Opcode: CollSeq P1 * * P4
 79751  79859   **
 79752         -** P4 is a pointer to a CollSeq struct. If the next call to a user function
        79860  +** P4 is a pointer to a CollSeq object. If the next call to a user function
 79753  79861   ** or aggregate calls sqlite3GetFuncCollSeq(), this collation sequence will
 79754  79862   ** be returned. This is used by the built-in min(), max() and nullif()
 79755  79863   ** functions.
 79756  79864   **
 79757  79865   ** If P1 is not zero, then it is a register that a subsequent min() or
 79758  79866   ** max() aggregate will set to 1 if the current row is not the minimum or
 79759  79867   ** maximum.  The P1 register is initialized to 0 by this instruction.
................................................................................
 80026  80134   #ifndef SQLITE_OMIT_CAST
 80027  80135   /* Opcode: Cast P1 P2 * * *
 80028  80136   ** Synopsis: affinity(r[P1])
 80029  80137   **
 80030  80138   ** Force the value in register P1 to be the type defined by P2.
 80031  80139   ** 
 80032  80140   ** <ul>
 80033         -** <li value="97"> TEXT
 80034         -** <li value="98"> BLOB
 80035         -** <li value="99"> NUMERIC
 80036         -** <li value="100"> INTEGER
 80037         -** <li value="101"> REAL
        80141  +** <li> P2=='A' &rarr; BLOB
        80142  +** <li> P2=='B' &rarr; TEXT
        80143  +** <li> P2=='C' &rarr; NUMERIC
        80144  +** <li> P2=='D' &rarr; INTEGER
        80145  +** <li> P2=='E' &rarr; REAL
 80038  80146   ** </ul>
 80039  80147   **
 80040  80148   ** A NULL value is not changed by this routine.  It remains NULL.
 80041  80149   */
 80042  80150   case OP_Cast: {                  /* in1 */
 80043  80151     assert( pOp->p2>=SQLITE_AFF_BLOB && pOp->p2<=SQLITE_AFF_REAL );
 80044  80152     testcase( pOp->p2==SQLITE_AFF_TEXT );
................................................................................
 80608  80716     pIn1 = &aMem[pOp->p1];
 80609  80717     VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
 80610  80718     if( (pIn1->flags & MEM_Null)==0 ){
 80611  80719       goto jump_to_p2;
 80612  80720     }
 80613  80721     break;
 80614  80722   }
        80723  +
        80724  +/* Opcode: IfNullRow P1 P2 P3 * *
        80725  +** Synopsis: if P1.nullRow then r[P3]=NULL, goto P2
        80726  +**
        80727  +** Check the cursor P1 to see if it is currently pointing at a NULL row.
        80728  +** If it is, then set register P3 to NULL and jump immediately to P2.
        80729  +** If P1 is not on a NULL row, then fall through without making any
        80730  +** changes.
        80731  +*/
        80732  +case OP_IfNullRow: {         /* jump */
        80733  +  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
        80734  +  assert( p->apCsr[pOp->p1]!=0 );
        80735  +  if( p->apCsr[pOp->p1]->nullRow ){
        80736  +    sqlite3VdbeMemSetNull(aMem + pOp->p3);
        80737  +    goto jump_to_p2;
        80738  +  }
        80739  +  break;
        80740  +}
 80615  80741   
 80616  80742   /* Opcode: Column P1 P2 P3 P4 P5
 80617  80743   ** Synopsis: r[P3]=PX
 80618  80744   **
 80619  80745   ** Interpret the data that cursor P1 points to as a structure built using
 80620  80746   ** the MakeRecord instruction.  (See the MakeRecord opcode for additional
 80621  80747   ** information about the format of the data.)  Extract the P2-th column
 80622  80748   ** from this record.  If there are less that (P2+1) 
 80623  80749   ** values in the record, extract a NULL.
 80624  80750   **
 80625  80751   ** The value extracted is stored in register P3.
 80626  80752   **
 80627         -** If the column contains fewer than P2 fields, then extract a NULL.  Or,
        80753  +** If the record contains fewer than P2 fields, then extract a NULL.  Or,
 80628  80754   ** if the P4 argument is a P4_MEM use the value of the P4 argument as
 80629  80755   ** the result.
 80630  80756   **
 80631  80757   ** If the OPFLAG_CLEARCACHE bit is set on P5 and P1 is a pseudo-table cursor,
 80632  80758   ** then the cache of the cursor is reset prior to extracting the column.
 80633  80759   ** The first OP_Column against a pseudo-table after the value of the content
 80634  80760   ** register has changed should have this bit set.
 80635  80761   **
 80636         -** If the OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG bits are set on P5 when
        80762  +** If the OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG bits are set on P5 then
 80637  80763   ** the result is guaranteed to only be used as the argument of a length()
 80638  80764   ** or typeof() function, respectively.  The loading of large blobs can be
 80639  80765   ** skipped for length() and all content loading can be skipped for typeof().
 80640  80766   */
 80641  80767   case OP_Column: {
 80642  80768     int p2;            /* column number to retrieve */
 80643  80769     VdbeCursor *pC;    /* The VDBE cursor */
................................................................................
 80884  81010   }
 80885  81011   
 80886  81012   /* Opcode: Affinity P1 P2 * P4 *
 80887  81013   ** Synopsis: affinity(r[P1@P2])
 80888  81014   **
 80889  81015   ** Apply affinities to a range of P2 registers starting with P1.
 80890  81016   **
 80891         -** P4 is a string that is P2 characters long. The nth character of the
 80892         -** string indicates the column affinity that should be used for the nth
        81017  +** P4 is a string that is P2 characters long. The N-th character of the
        81018  +** string indicates the column affinity that should be used for the N-th
 80893  81019   ** memory cell in the range.
 80894  81020   */
 80895  81021   case OP_Affinity: {
 80896  81022     const char *zAffinity;   /* The affinity to be applied */
 80897         -  char cAff;               /* A single character of affinity */
 80898  81023   
 80899  81024     zAffinity = pOp->p4.z;
 80900  81025     assert( zAffinity!=0 );
        81026  +  assert( pOp->p2>0 );
 80901  81027     assert( zAffinity[pOp->p2]==0 );
 80902  81028     pIn1 = &aMem[pOp->p1];
 80903         -  while( (cAff = *(zAffinity++))!=0 ){
        81029  +  do{
 80904  81030       assert( pIn1 <= &p->aMem[(p->nMem+1 - p->nCursor)] );
 80905  81031       assert( memIsValid(pIn1) );
 80906         -    applyAffinity(pIn1, cAff, encoding);
        81032  +    applyAffinity(pIn1, *(zAffinity++), encoding);
 80907  81033       pIn1++;
 80908         -  }
        81034  +  }while( zAffinity[0] );
 80909  81035     break;
 80910  81036   }
 80911  81037   
 80912  81038   /* Opcode: MakeRecord P1 P2 P3 P4 *
 80913  81039   ** Synopsis: r[P3]=mkrec(r[P1@P2])
 80914  81040   **
 80915  81041   ** Convert P2 registers beginning with P1 into the [record format]
 80916  81042   ** use as a data record in a database table or as a key
 80917  81043   ** in an index.  The OP_Column opcode can decode the record later.
 80918  81044   **
 80919         -** P4 may be a string that is P2 characters long.  The nth character of the
 80920         -** string indicates the column affinity that should be used for the nth
        81045  +** P4 may be a string that is P2 characters long.  The N-th character of the
        81046  +** string indicates the column affinity that should be used for the N-th
 80921  81047   ** field of the index key.
 80922  81048   **
 80923  81049   ** The mapping from character to affinity is given by the SQLITE_AFF_
 80924  81050   ** macros defined in sqliteInt.h.
 80925  81051   **
 80926  81052   ** If P4 is NULL then all index fields have the affinity BLOB.
 80927  81053   */
................................................................................
 81072  81198     assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
 81073  81199     pOut->n = (int)nByte;
 81074  81200     pOut->flags = MEM_Blob;
 81075  81201     if( nZero ){
 81076  81202       pOut->u.nZero = nZero;
 81077  81203       pOut->flags |= MEM_Zero;
 81078  81204     }
 81079         -  pOut->enc = SQLITE_UTF8;  /* In case the blob is ever converted to text */
 81080  81205     REGISTER_TRACE(pOp->p3, pOut);
 81081  81206     UPDATE_MAX_BLOBSIZE(pOut);
 81082  81207     break;
 81083  81208   }
 81084  81209   
 81085  81210   /* Opcode: Count P1 P2 * * *
 81086  81211   ** Synopsis: r[P2]=count()
................................................................................
 81701  81826     testcase( pOp->p2 & OPFLAG_SEEKEQ );
 81702  81827   #endif
 81703  81828     sqlite3BtreeCursorHintFlags(pCur->uc.pCursor,
 81704  81829                                  (pOp->p5 & (OPFLAG_BULKCSR|OPFLAG_SEEKEQ)));
 81705  81830     if( rc ) goto abort_due_to_error;
 81706  81831     break;
 81707  81832   }
        81833  +
        81834  +/* Opcode: OpenDup P1 P2 * * *
        81835  +**
        81836  +** Open a new cursor P1 that points to the same ephemeral table as
        81837  +** cursor P2.  The P2 cursor must have been opened by a prior OP_OpenEphemeral
        81838  +** opcode.  Only ephemeral cursors may be duplicated.
        81839  +**
        81840  +** Duplicate ephemeral cursors are used for self-joins of materialized views.
        81841  +*/
        81842  +case OP_OpenDup: {
        81843  +  VdbeCursor *pOrig;    /* The original cursor to be duplicated */
        81844  +  VdbeCursor *pCx;      /* The new cursor */
        81845  +
        81846  +  pOrig = p->apCsr[pOp->p2];
        81847  +  assert( pOrig->pBtx!=0 );  /* Only ephemeral cursors can be duplicated */
        81848  +
        81849  +  pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE);
        81850  +  if( pCx==0 ) goto no_mem;
        81851  +  pCx->nullRow = 1;
        81852  +  pCx->isEphemeral = 1;
        81853  +  pCx->pKeyInfo = pOrig->pKeyInfo;
        81854  +  pCx->isTable = pOrig->isTable;
        81855  +  rc = sqlite3BtreeCursor(pOrig->pBtx, MASTER_ROOT, BTREE_WRCSR,
        81856  +                          pCx->pKeyInfo, pCx->uc.pCursor);
        81857  +  /* The sqlite3BtreeCursor() routine can only fail for the first cursor
        81858  +  ** opened for a database.  Since there is already an open cursor when this
        81859  +  ** opcode is run, the sqlite3BtreeCursor() cannot fail */
        81860  +  assert( rc==SQLITE_OK );
        81861  +  break;
        81862  +}
        81863  +
 81708  81864   
 81709  81865   /* Opcode: OpenEphemeral P1 P2 * P4 P5
 81710  81866   ** Synopsis: nColumn=P2
 81711  81867   **
 81712  81868   ** Open a new cursor P1 to a transient table.
 81713  81869   ** The cursor is always opened read/write even if 
 81714  81870   ** the main database is read-only.  The ephemeral
................................................................................
 82237  82393         assert( (r.aMem[ii].flags & MEM_Zero)==0 || r.aMem[ii].n==0 );
 82238  82394         if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
 82239  82395       }
 82240  82396   #endif
 82241  82397       pIdxKey = &r;
 82242  82398       pFree = 0;
 82243  82399     }else{
        82400  +    assert( pIn3->flags & MEM_Blob );
        82401  +    rc = ExpandBlob(pIn3);
        82402  +    assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
        82403  +    if( rc ) goto no_mem;
 82244  82404       pFree = pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo);
 82245  82405       if( pIdxKey==0 ) goto no_mem;
 82246         -    assert( pIn3->flags & MEM_Blob );
 82247         -    (void)ExpandBlob(pIn3);
 82248  82406       sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
 82249  82407     }
 82250  82408     pIdxKey->default_rc = 0;
 82251  82409     takeJump = 0;
 82252  82410     if( pOp->opcode==OP_NoConflict ){
 82253  82411       /* For the OP_NoConflict opcode, take the jump if any of the
 82254  82412       ** input fields are NULL, since any key with a NULL will not
................................................................................
 82257  82415         if( pIdxKey->aMem[ii].flags & MEM_Null ){
 82258  82416           takeJump = 1;
 82259  82417           break;
 82260  82418         }
 82261  82419       }
 82262  82420     }
 82263  82421     rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, pIdxKey, 0, 0, &res);
 82264         -  if( pFree ) sqlite3DbFree(db, pFree);
        82422  +  if( pFree ) sqlite3DbFreeNN(db, pFree);
 82265  82423     if( rc!=SQLITE_OK ){
 82266  82424       goto abort_due_to_error;
 82267  82425     }
 82268  82426     pC->seekResult = res;
 82269  82427     alreadyExists = (res==0);
 82270  82428     pC->nullRow = 1-alreadyExists;
 82271  82429     pC->deferredMoveto = 0;
................................................................................
 83567  83725   ** P3==1 then the table to be clear is in the auxiliary database file
 83568  83726   ** that is used to store tables create using CREATE TEMPORARY TABLE.
 83569  83727   **
 83570  83728   ** If AUTOVACUUM is enabled then it is possible that another root page
 83571  83729   ** might be moved into the newly deleted root page in order to keep all
 83572  83730   ** root pages contiguous at the beginning of the database.  The former
 83573  83731   ** value of the root page that moved - its value before the move occurred -
 83574         -** is stored in register P2.  If no page 
 83575         -** movement was required (because the table being dropped was already 
 83576         -** the last one in the database) then a zero is stored in register P2.
 83577         -** If AUTOVACUUM is disabled then a zero is stored in register P2.
        83732  +** is stored in register P2. If no page movement was required (because the
        83733  +** table being dropped was already the last one in the database) then a 
        83734  +** zero is stored in register P2.  If AUTOVACUUM is disabled then a zero 
        83735  +** is stored in register P2.
        83736  +**
        83737  +** This opcode throws an error if there are any active reader VMs when
        83738  +** it is invoked. This is done to avoid the difficulty associated with 
        83739  +** updating existing cursors when a root page is moved in an AUTOVACUUM 
        83740  +** database. This error is thrown even if the database is not an AUTOVACUUM 
        83741  +** db in order to avoid introducing an incompatibility between autovacuum 
        83742  +** and non-autovacuum modes.
 83578  83743   **
 83579  83744   ** See also: Clear
 83580  83745   */
 83581  83746   case OP_Destroy: {     /* out2 */
 83582  83747     int iMoved;
 83583  83748     int iDb;
 83584  83749   
................................................................................
 83775  83940       }else{
 83776  83941         assert( db->init.busy==0 );
 83777  83942         db->init.busy = 1;
 83778  83943         initData.rc = SQLITE_OK;
 83779  83944         assert( !db->mallocFailed );
 83780  83945         rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
 83781  83946         if( rc==SQLITE_OK ) rc = initData.rc;
 83782         -      sqlite3DbFree(db, zSql);
        83947  +      sqlite3DbFreeNN(db, zSql);
 83783  83948         db->init.busy = 0;
 83784  83949       }
 83785  83950     }
 83786  83951     if( rc ){
 83787  83952       sqlite3ResetAllSchemasOfConnection(db);
 83788  83953       if( rc==SQLITE_NOMEM ){
 83789  83954         goto no_mem;
................................................................................
 83903  84068     break;
 83904  84069   }
 83905  84070   #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
 83906  84071   
 83907  84072   /* Opcode: RowSetAdd P1 P2 * * *
 83908  84073   ** Synopsis: rowset(P1)=r[P2]
 83909  84074   **
 83910         -** Insert the integer value held by register P2 into a boolean index
        84075  +** Insert the integer value held by register P2 into a RowSet object
 83911  84076   ** held in register P1.
 83912  84077   **
 83913  84078   ** An assertion fails if P2 is not an integer.
 83914  84079   */
 83915  84080   case OP_RowSetAdd: {       /* in1, in2 */
 83916  84081     pIn1 = &aMem[pOp->p1];
 83917  84082     pIn2 = &aMem[pOp->p2];
................................................................................
 83923  84088     sqlite3RowSetInsert(pIn1->u.pRowSet, pIn2->u.i);
 83924  84089     break;
 83925  84090   }
 83926  84091   
 83927  84092   /* Opcode: RowSetRead P1 P2 P3 * *
 83928  84093   ** Synopsis: r[P3]=rowset(P1)
 83929  84094   **
 83930         -** Extract the smallest value from boolean index P1 and put that value into
 83931         -** register P3.  Or, if boolean index P1 is initially empty, leave P3
        84095  +** Extract the smallest value from the RowSet object in P1
        84096  +** and put that value into register P3.
        84097  +** Or, if RowSet object P1 is initially empty, leave P3
 83932  84098   ** unchanged and jump to instruction P2.
 83933  84099   */
 83934  84100   case OP_RowSetRead: {       /* jump, in1, out3 */
 83935  84101     i64 val;
 83936  84102   
 83937  84103     pIn1 = &aMem[pOp->p1];
 83938  84104     if( (pIn1->flags & MEM_RowSet)==0 
................................................................................
 83955  84121   **
 83956  84122   ** Register P3 is assumed to hold a 64-bit integer value. If register P1
 83957  84123   ** contains a RowSet object and that RowSet object contains
 83958  84124   ** the value held in P3, jump to register P2. Otherwise, insert the
 83959  84125   ** integer in P3 into the RowSet and continue on to the
 83960  84126   ** next opcode.
 83961  84127   **
 83962         -** The RowSet object is optimized for the case where successive sets
 83963         -** of integers, where each set contains no duplicates. Each set
 83964         -** of values is identified by a unique P4 value. The first set
 83965         -** must have P4==0, the final set P4=-1.  P4 must be either -1 or
 83966         -** non-negative.  For non-negative values of P4 only the lower 4
 83967         -** bits are significant.
        84128  +** The RowSet object is optimized for the case where sets of integers
        84129  +** are inserted in distinct phases, which each set contains no duplicates.
        84130  +** Each set is identified by a unique P4 value. The first set
        84131  +** must have P4==0, the final set must have P4==-1, and for all other sets
        84132  +** must have P4>0.
 83968  84133   **
 83969  84134   ** This allows optimizations: (a) when P4==0 there is no need to test
 83970         -** the rowset object for P3, as it is guaranteed not to contain it,
        84135  +** the RowSet object for P3, as it is guaranteed not to contain it,
 83971  84136   ** (b) when P4==-1 there is no need to insert the value, as it will
 83972  84137   ** never be tested for, and (c) when a value that is part of set X is
 83973  84138   ** inserted, there is no need to search to see if the same value was
 83974  84139   ** previously inserted as part of set X (only if it was previously
 83975  84140   ** inserted as part of some other set).
 83976  84141   */
 83977  84142   case OP_RowSetTest: {                     /* jump, in1, in3 */
................................................................................
 86703  86868     const u8 * const v1 = &p1[ p1[0] ];   /* Pointer to value 1 */
 86704  86869     const u8 * const v2 = &p2[ p2[0] ];   /* Pointer to value 2 */
 86705  86870     int res;                              /* Return value */
 86706  86871   
 86707  86872     assert( (s1>0 && s1<7) || s1==8 || s1==9 );
 86708  86873     assert( (s2>0 && s2<7) || s2==8 || s2==9 );
 86709  86874   
 86710         -  if( s1>7 && s2>7 ){
        86875  +  if( s1==s2 ){
        86876  +    /* The two values have the same sign. Compare using memcmp(). */
        86877  +    static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8, 0, 0, 0 };
        86878  +    const u8 n = aLen[s1];
        86879  +    int i;
        86880  +    res = 0;
        86881  +    for(i=0; i<n; i++){
        86882  +      if( (res = v1[i] - v2[i])!=0 ){
        86883  +        if( ((v1[0] ^ v2[0]) & 0x80)!=0 ){
        86884  +          res = v1[0] & 0x80 ? -1 : +1;
        86885  +        }
        86886  +        break;
        86887  +      }
        86888  +    }
        86889  +  }else if( s1>7 && s2>7 ){
 86711  86890       res = s1 - s2;
 86712  86891     }else{
 86713         -    if( s1==s2 ){
 86714         -      if( (*v1 ^ *v2) & 0x80 ){
 86715         -        /* The two values have different signs */
 86716         -        res = (*v1 & 0x80) ? -1 : +1;
 86717         -      }else{
 86718         -        /* The two values have the same sign. Compare using memcmp(). */
 86719         -        static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8 };
 86720         -        int i;
 86721         -        res = 0;
 86722         -        for(i=0; i<aLen[s1]; i++){
 86723         -          if( (res = v1[i] - v2[i]) ) break;
 86724         -        }
 86725         -      }
        86892  +    if( s2>7 ){
        86893  +      res = +1;
        86894  +    }else if( s1>7 ){
        86895  +      res = -1;
 86726  86896       }else{
 86727         -      if( s2>7 ){
 86728         -        res = +1;
 86729         -      }else if( s1>7 ){
 86730         -        res = -1;
 86731         -      }else{
 86732         -        res = s1 - s2;
 86733         -      }
 86734         -      assert( res!=0 );
        86897  +      res = s1 - s2;
        86898  +    }
        86899  +    assert( res!=0 );
 86735  86900   
 86736         -      if( res>0 ){
 86737         -        if( *v1 & 0x80 ) res = -1;
 86738         -      }else{
 86739         -        if( *v2 & 0x80 ) res = +1;
 86740         -      }
        86901  +    if( res>0 ){
        86902  +      if( *v1 & 0x80 ) res = -1;
        86903  +    }else{
        86904  +      if( *v2 & 0x80 ) res = +1;
 86741  86905       }
 86742  86906     }
 86743  86907   
 86744  86908     if( res==0 ){
 86745  86909       if( pTask->pSorter->pKeyInfo->nField>1 ){
 86746  86910         res = vdbeSorterCompareTail(
 86747  86911             pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
................................................................................
 90788  90952     if( op==TK_REGISTER ) op = pExpr->op2;
 90789  90953   #ifndef SQLITE_OMIT_CAST
 90790  90954     if( op==TK_CAST ){
 90791  90955       assert( !ExprHasProperty(pExpr, EP_IntValue) );
 90792  90956       return sqlite3AffinityType(pExpr->u.zToken, 0);
 90793  90957     }
 90794  90958   #endif
 90795         -  if( op==TK_AGG_COLUMN || op==TK_COLUMN ){
        90959  +  if( (op==TK_AGG_COLUMN || op==TK_COLUMN) && pExpr->pTab ){
 90796  90960       return sqlite3TableColumnAffinity(pExpr->pTab, pExpr->iColumn);
 90797  90961     }
 90798  90962     if( op==TK_SELECT_COLUMN ){
 90799  90963       assert( pExpr->pLeft->flags&EP_xIsSelect );
 90800  90964       return sqlite3ExprAffinity(
 90801  90965           pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
 90802  90966       );
................................................................................
 91082  91246     }else if( op==TK_SELECT ){
 91083  91247       return pExpr->x.pSelect->pEList->nExpr;
 91084  91248     }else{
 91085  91249       return 1;
 91086  91250     }
 91087  91251   }
 91088  91252   
 91089         -#ifndef SQLITE_OMIT_SUBQUERY
 91090  91253   /*
 91091  91254   ** Return a pointer to a subexpression of pVector that is the i-th
 91092  91255   ** column of the vector (numbered starting with 0).  The caller must
 91093  91256   ** ensure that i is within range.
 91094  91257   **
 91095  91258   ** If pVector is really a scalar (and "scalar" here includes subqueries
 91096  91259   ** that return a single column!) then return pVector unmodified.
................................................................................
 91110  91273         return pVector->x.pSelect->pEList->a[i].pExpr;
 91111  91274       }else{
 91112  91275         return pVector->x.pList->a[i].pExpr;
 91113  91276       }
 91114  91277     }
 91115  91278     return pVector;
 91116  91279   }
 91117         -#endif /* !defined(SQLITE_OMIT_SUBQUERY) */
 91118  91280   
 91119         -#ifndef SQLITE_OMIT_SUBQUERY
 91120  91281   /*
 91121  91282   ** Compute and return a new Expr object which when passed to
 91122  91283   ** sqlite3ExprCode() will generate all necessary code to compute
 91123  91284   ** the iField-th column of the vector expression pVector.
 91124  91285   **
 91125  91286   ** It is ok for pVector to be a scalar (as long as iField==0).  
 91126  91287   ** In that case, this routine works like sqlite3ExprDup().
................................................................................
 91170  91331       assert( pRet==0 || pRet->iTable==0 );
 91171  91332     }else{
 91172  91333       if( pVector->op==TK_VECTOR ) pVector = pVector->x.pList->a[iField].pExpr;
 91173  91334       pRet = sqlite3ExprDup(pParse->db, pVector, 0);
 91174  91335     }
 91175  91336     return pRet;
 91176  91337   }
 91177         -#endif /* !define(SQLITE_OMIT_SUBQUERY) */
 91178  91338   
 91179  91339   /*
 91180  91340   ** If expression pExpr is of type TK_SELECT, generate code to evaluate
 91181  91341   ** it. Return the register in which the result is stored (or, if the 
 91182  91342   ** sub-select returns more than one column, the first in an array
 91183  91343   ** of registers in which the result is stored).
 91184  91344   **
................................................................................
 91686  91846     ynVar x;
 91687  91847   
 91688  91848     if( pExpr==0 ) return;
 91689  91849     assert( !ExprHasProperty(pExpr, EP_IntValue|EP_Reduced|EP_TokenOnly) );
 91690  91850     z = pExpr->u.zToken;
 91691  91851     assert( z!=0 );
 91692  91852     assert( z[0]!=0 );
 91693         -  assert( n==sqlite3Strlen30(z) );
        91853  +  assert( n==(u32)sqlite3Strlen30(z) );
 91694  91854     if( z[1]==0 ){
 91695  91855       /* Wildcard of the form "?".  Assign the next variable number */
 91696  91856       assert( z[0]=='?' );
 91697  91857       x = (ynVar)(++pParse->nVar);
 91698  91858     }else{
 91699  91859       int doAdd = 0;
 91700  91860       if( z[0]=='?' ){
................................................................................
 91768  91928         sqlite3SelectDelete(db, p->x.pSelect);
 91769  91929       }else{
 91770  91930         sqlite3ExprListDelete(db, p->x.pList);
 91771  91931       }
 91772  91932     }
 91773  91933     if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken);
 91774  91934     if( !ExprHasProperty(p, EP_Static) ){
 91775         -    sqlite3DbFree(db, p);
        91935  +    sqlite3DbFreeNN(db, p);
 91776  91936     }
 91777  91937   }
 91778  91938   SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
 91779  91939     if( p ) sqlite3ExprDeleteNN(db, p);
 91780  91940   }
 91781  91941   
 91782  91942   /*
................................................................................
 92035  92195   SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
 92036  92196     ExprList *pNew;
 92037  92197     struct ExprList_item *pItem, *pOldItem;
 92038  92198     int i;
 92039  92199     Expr *pPriorSelectCol = 0;
 92040  92200     assert( db!=0 );
 92041  92201     if( p==0 ) return 0;
 92042         -  pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
        92202  +  pNew = sqlite3DbMallocRawNN(db, 
        92203  +             sizeof(*pNew)+sizeof(pNew->a[0])*(p->nExpr-1) );
 92043  92204     if( pNew==0 ) return 0;
 92044         -  pNew->nExpr = i = p->nExpr;
 92045         -  if( (flags & EXPRDUP_REDUCE)==0 ) for(i=1; i<p->nExpr; i+=i){}
 92046         -  pNew->a = pItem = sqlite3DbMallocRawNN(db,  i*sizeof(p->a[0]) );
 92047         -  if( pItem==0 ){
 92048         -    sqlite3DbFree(db, pNew);
 92049         -    return 0;
 92050         -  } 
        92205  +  pNew->nAlloc = pNew->nExpr = p->nExpr;
        92206  +  pItem = pNew->a;
 92051  92207     pOldItem = p->a;
 92052  92208     for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
 92053  92209       Expr *pOldExpr = pOldItem->pExpr;
 92054  92210       Expr *pNewExpr;
 92055  92211       pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
 92056  92212       if( pOldExpr 
 92057  92213        && pOldExpr->op==TK_SELECT_COLUMN
................................................................................
 92134  92290     assert( db!=0 );
 92135  92291     if( p==0 ) return 0;
 92136  92292     pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
 92137  92293     if( pNew==0 ) return 0;
 92138  92294     pNew->nId = p->nId;
 92139  92295     pNew->a = sqlite3DbMallocRawNN(db, p->nId*sizeof(p->a[0]) );
 92140  92296     if( pNew->a==0 ){
 92141         -    sqlite3DbFree(db, pNew);
        92297  +    sqlite3DbFreeNN(db, pNew);
 92142  92298       return 0;
 92143  92299     }
 92144  92300     /* Note that because the size of the allocation for p->a[] is not
 92145  92301     ** necessarily a power of two, sqlite3IdListAppend() may not be called
 92146  92302     ** on the duplicate created by this function. */
 92147  92303     for(i=0; i<p->nId; i++){
 92148  92304       struct IdList_item *pNewItem = &pNew->a[i];
................................................................................
 92205  92361   ** that the new entry was successfully appended.
 92206  92362   */
 92207  92363   SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(
 92208  92364     Parse *pParse,          /* Parsing context */
 92209  92365     ExprList *pList,        /* List to which to append. Might be NULL */
 92210  92366     Expr *pExpr             /* Expression to be appended. Might be NULL */
 92211  92367   ){
        92368  +  struct ExprList_item *pItem;
 92212  92369     sqlite3 *db = pParse->db;
 92213  92370     assert( db!=0 );
 92214  92371     if( pList==0 ){
 92215  92372       pList = sqlite3DbMallocRawNN(db, sizeof(ExprList) );
 92216  92373       if( pList==0 ){
 92217  92374         goto no_mem;
 92218  92375       }
 92219  92376       pList->nExpr = 0;
 92220         -    pList->a = sqlite3DbMallocRawNN(db, sizeof(pList->a[0]));
 92221         -    if( pList->a==0 ) goto no_mem;
 92222         -  }else if( (pList->nExpr & (pList->nExpr-1))==0 ){
 92223         -    struct ExprList_item *a;
 92224         -    assert( pList->nExpr>0 );
 92225         -    a = sqlite3DbRealloc(db, pList->a, pList->nExpr*2*sizeof(pList->a[0]));
 92226         -    if( a==0 ){
        92377  +    pList->nAlloc = 1;
        92378  +  }else if( pList->nExpr==pList->nAlloc ){
        92379  +    ExprList *pNew;
        92380  +    pNew = sqlite3DbRealloc(db, pList, 
        92381  +             sizeof(*pList)+(2*pList->nAlloc - 1)*sizeof(pList->a[0]));
        92382  +    if( pNew==0 ){
 92227  92383         goto no_mem;
 92228  92384       }
 92229         -    pList->a = a;
        92385  +    pList = pNew;
        92386  +    pList->nAlloc *= 2;
 92230  92387     }
 92231         -  assert( pList->a!=0 );
 92232         -  if( 1 ){
 92233         -    struct ExprList_item *pItem = &pList->a[pList->nExpr++];
 92234         -    memset(pItem, 0, sizeof(*pItem));
 92235         -    pItem->pExpr = pExpr;
 92236         -  }
        92388  +  pItem = &pList->a[pList->nExpr++];
        92389  +  memset(pItem, 0, sizeof(*pItem));
        92390  +  pItem->pExpr = pExpr;
 92237  92391     return pList;
 92238  92392   
 92239  92393   no_mem:     
 92240  92394     /* Avoid leaking memory if malloc has failed. */
 92241  92395     sqlite3ExprDelete(db, pExpr);
 92242  92396     sqlite3ExprListDelete(db, pList);
 92243  92397     return 0;
................................................................................
 92286  92440       if( pList ){
 92287  92441         assert( pList->nExpr==iFirst+i+1 );
 92288  92442         pList->a[pList->nExpr-1].zName = pColumns->a[i].zName;
 92289  92443         pColumns->a[i].zName = 0;
 92290  92444       }
 92291  92445     }
 92292  92446   
 92293         -  if( pExpr->op==TK_SELECT ){
 92294         -    if( pList && pList->a[iFirst].pExpr ){
 92295         -      Expr *pFirst = pList->a[iFirst].pExpr;
 92296         -      assert( pFirst->op==TK_SELECT_COLUMN );
        92447  +  if( !db->mallocFailed && pExpr->op==TK_SELECT && ALWAYS(pList!=0) ){
        92448  +    Expr *pFirst = pList->a[iFirst].pExpr;
        92449  +    assert( pFirst!=0 );
        92450  +    assert( pFirst->op==TK_SELECT_COLUMN );
 92297  92451        
 92298         -      /* Store the SELECT statement in pRight so it will be deleted when
 92299         -      ** sqlite3ExprListDelete() is called */
 92300         -      pFirst->pRight = pExpr;
 92301         -      pExpr = 0;
        92452  +    /* Store the SELECT statement in pRight so it will be deleted when
        92453  +    ** sqlite3ExprListDelete() is called */
        92454  +    pFirst->pRight = pExpr;
        92455  +    pExpr = 0;
 92302  92456   
 92303         -      /* Remember the size of the LHS in iTable so that we can check that
 92304         -      ** the RHS and LHS sizes match during code generation. */
 92305         -      pFirst->iTable = pColumns->nId;
 92306         -    }
        92457  +    /* Remember the size of the LHS in iTable so that we can check that
        92458  +    ** the RHS and LHS sizes match during code generation. */
        92459  +    pFirst->iTable = pColumns->nId;
 92307  92460     }
 92308  92461   
 92309  92462   vector_append_error:
 92310  92463     sqlite3ExprDelete(db, pExpr);
 92311  92464     sqlite3IdListDelete(db, pColumns);
 92312  92465     return pList;
 92313  92466   }
................................................................................
 92393  92546     }
 92394  92547   }
 92395  92548   
 92396  92549   /*
 92397  92550   ** Delete an entire expression list.
 92398  92551   */
 92399  92552   static SQLITE_NOINLINE void exprListDeleteNN(sqlite3 *db, ExprList *pList){
 92400         -  int i;
 92401         -  struct ExprList_item *pItem;
 92402         -  assert( pList->a!=0 || pList->nExpr==0 );
 92403         -  for(pItem=pList->a, i=0; i<pList->nExpr; i++, pItem++){
        92553  +  int i = pList->nExpr;
        92554  +  struct ExprList_item *pItem =  pList->a;
        92555  +  assert( pList->nExpr>0 );
        92556  +  do{
 92404  92557       sqlite3ExprDelete(db, pItem->pExpr);
 92405  92558       sqlite3DbFree(db, pItem->zName);
 92406  92559       sqlite3DbFree(db, pItem->zSpan);
 92407         -  }
 92408         -  sqlite3DbFree(db, pList->a);
 92409         -  sqlite3DbFree(db, pList);
        92560  +    pItem++;
        92561  +  }while( --i>0 );
        92562  +  sqlite3DbFreeNN(db, pList);
 92410  92563   }
 92411  92564   SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
 92412  92565     if( pList ) exprListDeleteNN(db, pList);
 92413  92566   }
 92414  92567   
 92415  92568   /*
 92416  92569   ** Return the bitwise-OR of all Expr.flags fields in the given
................................................................................
 92481  92634       case TK_AGG_COLUMN:
 92482  92635         testcase( pExpr->op==TK_ID );
 92483  92636         testcase( pExpr->op==TK_COLUMN );
 92484  92637         testcase( pExpr->op==TK_AGG_FUNCTION );
 92485  92638         testcase( pExpr->op==TK_AGG_COLUMN );
 92486  92639         if( pWalker->eCode==3 && pExpr->iTable==pWalker->u.iCur ){
 92487  92640           return WRC_Continue;
 92488         -      }else{
 92489         -        pWalker->eCode = 0;
 92490         -        return WRC_Abort;
 92491  92641         }
        92642  +      /* Fall through */
        92643  +    case TK_IF_NULL_ROW:
        92644  +      testcase( pExpr->op==TK_IF_NULL_ROW );
        92645  +      pWalker->eCode = 0;
        92646  +      return WRC_Abort;
 92492  92647       case TK_VARIABLE:
 92493  92648         if( pWalker->eCode==5 ){
 92494  92649           /* Silently convert bound parameters that appear inside of CREATE
 92495  92650           ** statements into a NULL when parsing the CREATE statement text out
 92496  92651           ** of the sqlite_master table */
 92497  92652           pExpr->op = TK_NULL;
 92498  92653         }else if( pWalker->eCode==4 ){
................................................................................
 92552  92707   ** expression must not refer to any non-deterministic function nor any
 92553  92708   ** table other than iCur.
 92554  92709   */
 92555  92710   SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
 92556  92711     return exprIsConst(p, 3, iCur);
 92557  92712   }
 92558  92713   
        92714  +
        92715  +/*
        92716  +** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
        92717  +*/
        92718  +static int exprNodeIsConstantOrGroupBy(Walker *pWalker, Expr *pExpr){
        92719  +  ExprList *pGroupBy = pWalker->u.pGroupBy;
        92720  +  int i;
        92721  +
        92722  +  /* Check if pExpr is identical to any GROUP BY term. If so, consider
        92723  +  ** it constant.  */
        92724  +  for(i=0; i<pGroupBy->nExpr; i++){
        92725  +    Expr *p = pGroupBy->a[i].pExpr;
        92726  +    if( sqlite3ExprCompare(pExpr, p, -1)<2 ){
        92727  +      CollSeq *pColl = sqlite3ExprCollSeq(pWalker->pParse, p);
        92728  +      if( pColl==0 || sqlite3_stricmp("BINARY", pColl->zName)==0 ){
        92729  +        return WRC_Prune;
        92730  +      }
        92731  +    }
        92732  +  }
        92733  +
        92734  +  /* Check if pExpr is a sub-select. If so, consider it variable. */
        92735  +  if( ExprHasProperty(pExpr, EP_xIsSelect) ){
        92736  +    pWalker->eCode = 0;
        92737  +    return WRC_Abort;
        92738  +  }
        92739  +
        92740  +  return exprNodeIsConstant(pWalker, pExpr);
        92741  +}
        92742  +
        92743  +/*
        92744  +** Walk the expression tree passed as the first argument. Return non-zero
        92745  +** if the expression consists entirely of constants or copies of terms 
        92746  +** in pGroupBy that sort with the BINARY collation sequence.
        92747  +**
        92748  +** This routine is used to determine if a term of the HAVING clause can
        92749  +** be promoted into the WHERE clause.  In order for such a promotion to work,
        92750  +** the value of the HAVING clause term must be the same for all members of
        92751  +** a "group".  The requirement that the GROUP BY term must be BINARY
        92752  +** assumes that no other collating sequence will have a finer-grained
        92753  +** grouping than binary.  In other words (A=B COLLATE binary) implies
        92754  +** A=B in every other collating sequence.  The requirement that the
        92755  +** GROUP BY be BINARY is stricter than necessary.  It would also work
        92756  +** to promote HAVING clauses that use the same alternative collating
        92757  +** sequence as the GROUP BY term, but that is much harder to check,
        92758  +** alternative collating sequences are uncommon, and this is only an
        92759  +** optimization, so we take the easy way out and simply require the
        92760  +** GROUP BY to use the BINARY collating sequence.
        92761  +*/
        92762  +SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse *pParse, Expr *p, ExprList *pGroupBy){
        92763  +  Walker w;
        92764  +  memset(&w, 0, sizeof(w));
        92765  +  w.eCode = 1;
        92766  +  w.xExprCallback = exprNodeIsConstantOrGroupBy;
        92767  +  w.u.pGroupBy = pGroupBy;
        92768  +  w.pParse = pParse;
        92769  +  sqlite3WalkExpr(&w, p);
        92770  +  return w.eCode;
        92771  +}
        92772  +
 92559  92773   /*
 92560  92774   ** Walk an expression tree.  Return non-zero if the expression is constant
 92561  92775   ** or a function call with constant arguments.  Return and 0 if there
 92562  92776   ** are any variables.
 92563  92777   **
 92564  92778   ** For the purposes of this function, a double-quoted string (ex: "abc")
 92565  92779   ** is considered a variable but a single-quoted string (ex: 'abc') is
................................................................................
 93929  94143   SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(
 93930  94144     Vdbe *v,        /* The VDBE under construction */
 93931  94145     Table *pTab,    /* The table containing the value */
 93932  94146     int iTabCur,    /* The table cursor.  Or the PK cursor for WITHOUT ROWID */
 93933  94147     int iCol,       /* Index of the column to extract */
 93934  94148     int regOut      /* Extract the value into this register */
 93935  94149   ){
        94150  +  if( pTab==0 ){
        94151  +    sqlite3VdbeAddOp3(v, OP_Column, iTabCur, iCol, regOut);
        94152  +    return;
        94153  +  }
 93936  94154     if( iCol<0 || iCol==pTab->iPKey ){
 93937  94155       sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
 93938  94156     }else{
 93939  94157       int op = IsVirtual(pTab) ? OP_VColumn : OP_Column;
 93940  94158       int x = iCol;
 93941  94159       if( !HasRowid(pTab) && !IsVirtual(pTab) ){
 93942  94160         x = sqlite3ColumnOfIndex(sqlite3PrimaryKeyIndex(pTab), iCol);
................................................................................
 94085  94303     int iResult;
 94086  94304     int nResult = sqlite3ExprVectorSize(p);
 94087  94305     if( nResult==1 ){
 94088  94306       iResult = sqlite3ExprCodeTemp(pParse, p, piFreeable);
 94089  94307     }else{
 94090  94308       *piFreeable = 0;
 94091  94309       if( p->op==TK_SELECT ){
        94310  +#if SQLITE_OMIT_SUBQUERY
        94311  +      iResult = 0;
        94312  +#else
 94092  94313         iResult = sqlite3CodeSubselect(pParse, p, 0, 0);
        94314  +#endif
 94093  94315       }else{
 94094  94316         int i;
 94095  94317         iResult = pParse->nMem+1;
 94096  94318         pParse->nMem += nResult;
 94097  94319         for(i=0; i<nResult; i++){
 94098  94320           sqlite3ExprCodeFactorable(pParse, p->x.pList->a[i].pExpr, i+iResult);
 94099  94321         }
................................................................................
 94621  94843         break;
 94622  94844       }
 94623  94845   
 94624  94846       case TK_VECTOR: {
 94625  94847         sqlite3ErrorMsg(pParse, "row value misused");
 94626  94848         break;
 94627  94849       }
        94850  +
        94851  +    case TK_IF_NULL_ROW: {
        94852  +      int addrINR;
        94853  +      addrINR = sqlite3VdbeAddOp1(v, OP_IfNullRow, pExpr->iTable);
        94854  +      sqlite3ExprCachePush(pParse);
        94855  +      inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
        94856  +      sqlite3ExprCachePop(pParse);
        94857  +      sqlite3VdbeJumpHere(v, addrINR);
        94858  +      sqlite3VdbeChangeP3(v, addrINR, inReg);
        94859  +      break;
        94860  +    }
 94628  94861   
 94629  94862       /*
 94630  94863       ** Form A:
 94631  94864       **   CASE x WHEN e1 THEN r1 WHEN e2 THEN r2 ... WHEN eN THEN rN ELSE y END
 94632  94865       **
 94633  94866       ** Form B:
 94634  94867       **   CASE WHEN e1 THEN r1 WHEN e2 THEN r2 ... WHEN eN THEN rN ELSE y END
................................................................................
 99399  99632     if( db->init.busy || IN_DECLARE_VTAB ){
 99400  99633       return SQLITE_OK;
 99401  99634     }
 99402  99635   
 99403  99636     if( db->xAuth==0 ){
 99404  99637       return SQLITE_OK;
 99405  99638     }
        99639  +
        99640  +  /* EVIDENCE-OF: R-43249-19882 The third through sixth parameters to the
        99641  +  ** callback are either NULL pointers or zero-terminated strings that
        99642  +  ** contain additional details about the action to be authorized.
        99643  +  **
        99644  +  ** The following testcase() macros show that any of the 3rd through 6th
        99645  +  ** parameters can be either NULL or a string. */
        99646  +  testcase( zArg1==0 );
        99647  +  testcase( zArg2==0 );
        99648  +  testcase( zArg3==0 );
        99649  +  testcase( pParse->zAuthContext==0 );
        99650  +
 99406  99651     rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext
 99407  99652   #ifdef SQLITE_USER_AUTHENTICATION
 99408  99653                    ,db->auth.zAuthUser
 99409  99654   #endif
 99410  99655                   );
 99411  99656     if( rc==SQLITE_DENY ){
 99412  99657       sqlite3ErrorMsg(pParse, "not authorized");
................................................................................
103070 103315   SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *db, IdList *pList){
103071 103316     int i;
103072 103317     if( pList==0 ) return;
103073 103318     for(i=0; i<pList->nId; i++){
103074 103319       sqlite3DbFree(db, pList->a[i].zName);
103075 103320     }
103076 103321     sqlite3DbFree(db, pList->a);
103077         -  sqlite3DbFree(db, pList);
       103322  +  sqlite3DbFreeNN(db, pList);
103078 103323   }
103079 103324   
103080 103325   /*
103081 103326   ** Return the index in pList of the identifier named zId.  Return -1
103082 103327   ** if not found.
103083 103328   */
103084 103329   SQLITE_PRIVATE int sqlite3IdListIndex(IdList *pList, const char *zName){
................................................................................
103260 103505       if( pItem->fg.isIndexedBy ) sqlite3DbFree(db, pItem->u1.zIndexedBy);
103261 103506       if( pItem->fg.isTabFunc ) sqlite3ExprListDelete(db, pItem->u1.pFuncArg);
103262 103507       sqlite3DeleteTable(db, pItem->pTab);
103263 103508       sqlite3SelectDelete(db, pItem->pSelect);
103264 103509       sqlite3ExprDelete(db, pItem->pOn);
103265 103510       sqlite3IdListDelete(db, pItem->pUsing);
103266 103511     }
103267         -  sqlite3DbFree(db, pList);
       103512  +  sqlite3DbFreeNN(db, pList);
103268 103513   }
103269 103514   
103270 103515   /*
103271 103516   ** This routine is called by the parser to add a new term to the
103272 103517   ** end of a growing FROM clause.  The "p" parameter is the part of
103273 103518   ** the FROM clause that has already been constructed.  "p" is NULL
103274 103519   ** if this is the first term of the FROM clause.  pTable and pDatabase
................................................................................
104734 104979       sqlite3VdbeAddOp2(v, OP_Integer, 0, memCnt);
104735 104980     }
104736 104981   
104737 104982   #ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
104738 104983     /* Special case: A DELETE without a WHERE clause deletes everything.
104739 104984     ** It is easier just to erase the whole table. Prior to version 3.6.5,
104740 104985     ** this optimization caused the row change count (the value returned by 
104741         -  ** API function sqlite3_count_changes) to be set incorrectly.  */
       104986  +  ** API function sqlite3_count_changes) to be set incorrectly.
       104987  +  **
       104988  +  ** The "rcauth==SQLITE_OK" terms is the
       104989  +  ** IMPLEMENATION-OF: R-17228-37124 If the action code is SQLITE_DELETE and
       104990  +  ** the callback returns SQLITE_IGNORE then the DELETE operation proceeds but
       104991  +  ** the truncate optimization is disabled and all rows are deleted
       104992  +  ** individually.
       104993  +  */
104742 104994     if( rcauth==SQLITE_OK
104743 104995      && pWhere==0
104744 104996      && !bComplex
104745 104997      && !IsVirtual(pTab)
104746 104998   #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
104747 104999      && db->xPreUpdateCallback==0
104748 105000   #endif
................................................................................
108244 108496   ** to an array of size N, where N is the number of columns in table pTab.
108245 108497   ** If the i'th column is not modified by the UPDATE, then the corresponding 
108246 108498   ** entry in the aChange[] array is set to -1. If the column is modified,
108247 108499   ** the value is 0 or greater. Parameter chngRowid is set to true if the
108248 108500   ** UPDATE statement modifies the rowid fields of the table.
108249 108501   **
108250 108502   ** If any foreign key processing will be required, this function returns
108251         -** true. If there is no foreign key related processing, this function 
108252         -** returns false.
       108503  +** non-zero. If there is no foreign key related processing, this function 
       108504  +** returns zero.
       108505  +**
       108506  +** For an UPDATE, this function returns 2 if:
       108507  +**
       108508  +**   * There are any FKs for which pTab is the child and the parent table, or
       108509  +**   * the UPDATE modifies one or more parent keys for which the action is
       108510  +**     not "NO ACTION" (i.e. is CASCADE, SET DEFAULT or SET NULL).
       108511  +**
       108512  +** Or, assuming some other foreign key processing is required, 1.
108253 108513   */
108254 108514   SQLITE_PRIVATE int sqlite3FkRequired(
108255 108515     Parse *pParse,                  /* Parse context */
108256 108516     Table *pTab,                    /* Table being modified */
108257 108517     int *aChange,                   /* Non-NULL for UPDATE operations */
108258 108518     int chngRowid                   /* True for UPDATE that affects rowid */
108259 108519   ){
       108520  +  int eRet = 0;
108260 108521     if( pParse->db->flags&SQLITE_ForeignKeys ){
108261 108522       if( !aChange ){
108262 108523         /* A DELETE operation. Foreign key processing is required if the 
108263 108524         ** table in question is either the child or parent table for any 
108264 108525         ** foreign key constraint.  */
108265         -      return (sqlite3FkReferences(pTab) || pTab->pFKey);
       108526  +      eRet = (sqlite3FkReferences(pTab) || pTab->pFKey);
108266 108527       }else{
108267 108528         /* This is an UPDATE. Foreign key processing is only required if the
108268 108529         ** operation modifies one or more child or parent key columns. */
108269 108530         FKey *p;
108270 108531   
108271 108532         /* Check if any child key columns are being modified. */
108272 108533         for(p=pTab->pFKey; p; p=p->pNextFrom){
108273         -        if( fkChildIsModified(pTab, p, aChange, chngRowid) ) return 1;
       108534  +        if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) return 2;
       108535  +        if( fkChildIsModified(pTab, p, aChange, chngRowid) ){
       108536  +          eRet = 1;
       108537  +        }
108274 108538         }
108275 108539   
108276 108540         /* Check if any parent key columns are being modified. */
108277 108541         for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
108278         -        if( fkParentIsModified(pTab, p, aChange, chngRowid) ) return 1;
       108542  +        if( fkParentIsModified(pTab, p, aChange, chngRowid) ){
       108543  +          if( p->aAction[1]!=OE_None ) return 2;
       108544  +          eRet = 1;
       108545  +        }
108279 108546         }
108280 108547       }
108281 108548     }
108282         -  return 0;
       108549  +  return eRet;
108283 108550   }
108284 108551   
108285 108552   /*
108286 108553   ** This function is called when an UPDATE or DELETE operation is being 
108287 108554   ** compiled on table pTab, which is the parent table of foreign-key pFKey.
108288 108555   ** If the current operation is an UPDATE, then the pChanges parameter is
108289 108556   ** passed a pointer to the list of columns being modified. If it is a
................................................................................
112785 113052     /* ePragTyp:  */ PragTyp_MMAP_SIZE,
112786 113053     /* ePragFlg:  */ 0,
112787 113054     /* ColNames:  */ 0, 0,
112788 113055     /* iArg:      */ 0 },
112789 113056   #endif
112790 113057    {/* zName:     */ "optimize",
112791 113058     /* ePragTyp:  */ PragTyp_OPTIMIZE,
112792         -  /* ePragFlg:  */ PragFlg_Result1,
       113059  +  /* ePragFlg:  */ PragFlg_Result1|PragFlg_NeedSchema,
112793 113060     /* ColNames:  */ 0, 0,
112794 113061     /* iArg:      */ 0 },
112795 113062   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112796 113063    {/* zName:     */ "page_count",
112797 113064     /* ePragTyp:  */ PragTyp_PAGE_COUNT,
112798 113065     /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
112799 113066     /* ColNames:  */ 0, 0,
................................................................................
114285 114552           pIdx = 0;
114286 114553           aiCols = 0;
114287 114554           if( pParent ){
114288 114555             x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols);
114289 114556             assert( x==0 );
114290 114557           }
114291 114558           addrOk = sqlite3VdbeMakeLabel(v);
114292         -        if( pParent && pIdx==0 ){
114293         -          int iKey = pFK->aCol[0].iFrom;
114294         -          assert( iKey>=0 && iKey<pTab->nCol );
114295         -          if( iKey!=pTab->iPKey ){
114296         -            sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow);
114297         -            sqlite3ColumnDefault(v, pTab, iKey, regRow);
114298         -            sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); VdbeCoverage(v);
114299         -          }else{
114300         -            sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow);
114301         -          }
114302         -          sqlite3VdbeAddOp3(v, OP_SeekRowid, i, 0, regRow); VdbeCoverage(v);
       114559  +
       114560  +        /* Generate code to read the child key values into registers
       114561  +        ** regRow..regRow+n. If any of the child key values are NULL, this 
       114562  +        ** row cannot cause an FK violation. Jump directly to addrOk in 
       114563  +        ** this case. */
       114564  +        for(j=0; j<pFK->nCol; j++){
       114565  +          int iCol = aiCols ? aiCols[j] : pFK->aCol[j].iFrom;
       114566  +          sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, iCol, regRow+j);
       114567  +          sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
       114568  +        }
       114569  +
       114570  +        /* Generate code to query the parent index for a matching parent
       114571  +        ** key. If a match is found, jump to addrOk. */
       114572  +        if( pIdx ){
       114573  +          sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
       114574  +              sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
       114575  +          sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
       114576  +          VdbeCoverage(v);
       114577  +        }else if( pParent ){
       114578  +          int jmp = sqlite3VdbeCurrentAddr(v)+2;
       114579  +          sqlite3VdbeAddOp3(v, OP_SeekRowid, i, jmp, regRow); VdbeCoverage(v);
114303 114580             sqlite3VdbeGoto(v, addrOk);
114304         -          sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
       114581  +          assert( pFK->nCol==1 );
       114582  +        }
       114583  +
       114584  +        /* Generate code to report an FK violation to the caller. */
       114585  +        if( HasRowid(pTab) ){
       114586  +          sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
114305 114587           }else{
114306         -          for(j=0; j<pFK->nCol; j++){
114307         -            sqlite3ExprCodeGetColumnOfTable(v, pTab, 0,
114308         -                            aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j);
114309         -            sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
114310         -          }
114311         -          if( pParent ){
114312         -            sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
114313         -                              sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
114314         -            sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
114315         -            VdbeCoverage(v);
114316         -          }
       114588  +          sqlite3VdbeAddOp2(v, OP_Null, 0, regResult+1);
114317 114589           }
114318         -        sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
114319 114590           sqlite3VdbeMultiLoad(v, regResult+2, "si", pFK->zTo, i-1);
114320 114591           sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
114321 114592           sqlite3VdbeResolveLabel(v, addrOk);
114322 114593           sqlite3DbFree(db, aiCols);
114323 114594         }
114324 114595         sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v);
114325 114596         sqlite3VdbeJumpHere(v, addrTop);
................................................................................
114497 114768                                 pTab->aCol[j].zName);
114498 114769             sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
114499 114770             integrityCheckResultRow(v, 3);
114500 114771             sqlite3VdbeJumpHere(v, jmp2);
114501 114772           }
114502 114773           /* Verify CHECK constraints */
114503 114774           if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
114504         -          int addrCkFault = sqlite3VdbeMakeLabel(v);
114505         -          int addrCkOk = sqlite3VdbeMakeLabel(v);
114506         -          ExprList *pCheck = pTab->pCheck;
114507         -          char *zErr;
114508         -          int k;
114509         -          pParse->iSelfTab = iDataCur;
114510         -          sqlite3ExprCachePush(pParse);
114511         -          for(k=pCheck->nExpr-1; k>0; k--){
114512         -            sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
114513         -          }
114514         -          sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk, 
114515         -                            SQLITE_JUMPIFNULL);
114516         -          sqlite3VdbeResolveLabel(v, addrCkFault);
114517         -          zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
114518         -                                pTab->zName);
114519         -          sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
114520         -          integrityCheckResultRow(v, 3);
114521         -          sqlite3VdbeResolveLabel(v, addrCkOk);
114522         -          sqlite3ExprCachePop(pParse);
       114775  +          ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0);
       114776  +          if( db->mallocFailed==0 ){
       114777  +            int addrCkFault = sqlite3VdbeMakeLabel(v);
       114778  +            int addrCkOk = sqlite3VdbeMakeLabel(v);
       114779  +            char *zErr;
       114780  +            int k;
       114781  +            pParse->iSelfTab = iDataCur;
       114782  +            sqlite3ExprCachePush(pParse);
       114783  +            for(k=pCheck->nExpr-1; k>0; k--){
       114784  +              sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
       114785  +            }
       114786  +            sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk, 
       114787  +                SQLITE_JUMPIFNULL);
       114788  +            sqlite3VdbeResolveLabel(v, addrCkFault);
       114789  +            zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
       114790  +                pTab->zName);
       114791  +            sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
       114792  +            integrityCheckResultRow(v, 3);
       114793  +            sqlite3VdbeResolveLabel(v, addrCkOk);
       114794  +            sqlite3ExprCachePop(pParse);
       114795  +          }
       114796  +          sqlite3ExprListDelete(db, pCheck);
114523 114797           }
114524 114798           /* Validate index entries for the current row */
114525 114799           for(j=0, pIdx=pTab->pIndex; pIdx && !isQuick; pIdx=pIdx->pNext, j++){
114526 114800             int jmp2, jmp3, jmp4, jmp5;
114527 114801             int ckUniq = sqlite3VdbeMakeLabel(v);
114528 114802             if( pPk==pIdx ) continue;
114529 114803             r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
................................................................................
116319 116593       sqlite3ExprDelete(db, p->pWhere);
116320 116594       sqlite3ExprListDelete(db, p->pGroupBy);
116321 116595       sqlite3ExprDelete(db, p->pHaving);
116322 116596       sqlite3ExprListDelete(db, p->pOrderBy);
116323 116597       sqlite3ExprDelete(db, p->pLimit);
116324 116598       sqlite3ExprDelete(db, p->pOffset);
116325 116599       if( p->pWith ) sqlite3WithDelete(db, p->pWith);
116326         -    if( bFree ) sqlite3DbFree(db, p);
       116600  +    if( bFree ) sqlite3DbFreeNN(db, p);
116327 116601       p = pPrior;
116328 116602       bFree = 1;
116329 116603     }
116330 116604   }
116331 116605   
116332 116606   /*
116333 116607   ** Initialize a SelectDest structure.
................................................................................
116355 116629     ExprList *pOrderBy,   /* the ORDER BY clause */
116356 116630     u32 selFlags,         /* Flag parameters, such as SF_Distinct */
116357 116631     Expr *pLimit,         /* LIMIT value.  NULL means not used */
116358 116632     Expr *pOffset         /* OFFSET value.  NULL means no offset */
116359 116633   ){
116360 116634     Select *pNew;
116361 116635     Select standin;
116362         -  sqlite3 *db = pParse->db;
116363         -  pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
       116636  +  pNew = sqlite3DbMallocRawNN(pParse->db, sizeof(*pNew) );
116364 116637     if( pNew==0 ){
116365         -    assert( db->mallocFailed );
       116638  +    assert( pParse->db->mallocFailed );
116366 116639       pNew = &standin;
116367 116640     }
116368 116641     if( pEList==0 ){
116369         -    pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db,TK_ASTERISK,0));
       116642  +    pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(pParse->db,TK_ASTERISK,0));
116370 116643     }
116371 116644     pNew->pEList = pEList;
116372 116645     pNew->op = TK_SELECT;
116373 116646     pNew->selFlags = selFlags;
116374 116647     pNew->iLimit = 0;
116375 116648     pNew->iOffset = 0;
116376 116649   #if SELECTTRACE_ENABLED
116377 116650     pNew->zSelName[0] = 0;
116378 116651   #endif
116379 116652     pNew->addrOpenEphm[0] = -1;
116380 116653     pNew->addrOpenEphm[1] = -1;
116381 116654     pNew->nSelectRow = 0;
116382         -  if( pSrc==0 ) pSrc = sqlite3DbMallocZero(db, sizeof(*pSrc));
       116655  +  if( pSrc==0 ) pSrc = sqlite3DbMallocZero(pParse->db, sizeof(*pSrc));
116383 116656     pNew->pSrc = pSrc;
116384 116657     pNew->pWhere = pWhere;
116385 116658     pNew->pGroupBy = pGroupBy;
116386 116659     pNew->pHaving = pHaving;
116387 116660     pNew->pOrderBy = pOrderBy;
116388 116661     pNew->pPrior = 0;
116389 116662     pNew->pNext = 0;
116390 116663     pNew->pLimit = pLimit;
116391 116664     pNew->pOffset = pOffset;
116392 116665     pNew->pWith = 0;
116393         -  assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || db->mallocFailed!=0 );
116394         -  if( db->mallocFailed ) {
116395         -    clearSelect(db, pNew, pNew!=&standin);
       116666  +  assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || pParse->db->mallocFailed!=0 );
       116667  +  if( pParse->db->mallocFailed ) {
       116668  +    clearSelect(pParse->db, pNew, pNew!=&standin);
116396 116669       pNew = 0;
116397 116670     }else{
116398 116671       assert( pNew->pSrc!=0 || pParse->nErr>0 );
116399 116672     }
116400 116673     assert( pNew!=&standin );
116401 116674     return pNew;
116402 116675   }
................................................................................
117298 117571   /*
117299 117572   ** Deallocate a KeyInfo object
117300 117573   */
117301 117574   SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo *p){
117302 117575     if( p ){
117303 117576       assert( p->nRef>0 );
117304 117577       p->nRef--;
117305         -    if( p->nRef==0 ) sqlite3DbFree(p->db, p);
       117578  +    if( p->nRef==0 ) sqlite3DbFreeNN(p->db, p);
117306 117579     }
117307 117580   }
117308 117581   
117309 117582   /*
117310 117583   ** Make a new pointer to a KeyInfo object
117311 117584   */
117312 117585   SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoRef(KeyInfo *p){
................................................................................
117773 118046   ){
117774 118047   #ifndef SQLITE_OMIT_DECLTYPE
117775 118048     Vdbe *v = pParse->pVdbe;
117776 118049     int i;
117777 118050     NameContext sNC;
117778 118051     sNC.pSrcList = pTabList;
117779 118052     sNC.pParse = pParse;
       118053  +  sNC.pNext = 0;
117780 118054     for(i=0; i<pEList->nExpr; i++){
117781 118055       Expr *p = pEList->a[i].pExpr;
117782 118056       const char *zType;
117783 118057   #ifdef SQLITE_ENABLE_COLUMN_METADATA
117784 118058       const char *zOrigDb = 0;
117785 118059       const char *zOrigTab = 0;
117786 118060       const char *zOrigCol = 0;
................................................................................
117796 118070   #else
117797 118071       zType = columnType(&sNC, p, 0, 0, 0, 0);
117798 118072   #endif
117799 118073       sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
117800 118074     }
117801 118075   #endif /* !defined(SQLITE_OMIT_DECLTYPE) */
117802 118076   }
       118077  +
       118078  +/*
       118079  +** Return the Table objecct in the SrcList that has cursor iCursor.
       118080  +** Or return NULL if no such Table object exists in the SrcList.
       118081  +*/
       118082  +static Table *tableWithCursor(SrcList *pList, int iCursor){
       118083  +  int j;
       118084  +  for(j=0; j<pList->nSrc; j++){
       118085  +    if( pList->a[j].iCursor==iCursor ) return pList->a[j].pTab;
       118086  +  }
       118087  +  return 0;
       118088  +}
       118089  +
117803 118090   
117804 118091   /*
117805 118092   ** Generate code that will tell the VDBE the names of columns
117806 118093   ** in the result set.  This information is used to provide the
117807 118094   ** azCol[] values in the callback.
117808 118095   */
117809 118096   static void generateColumnNames(
117810 118097     Parse *pParse,      /* Parser context */
117811 118098     SrcList *pTabList,  /* List of tables */
117812 118099     ExprList *pEList    /* Expressions defining the result set */
117813 118100   ){
117814 118101     Vdbe *v = pParse->pVdbe;
117815         -  int i, j;
       118102  +  int i;
       118103  +  Table *pTab;
117816 118104     sqlite3 *db = pParse->db;
117817 118105     int fullNames, shortNames;
117818 118106   
117819 118107   #ifndef SQLITE_OMIT_EXPLAIN
117820 118108     /* If this is an EXPLAIN, skip this step */
117821 118109     if( pParse->explain ){
117822 118110       return;
................................................................................
117833 118121     for(i=0; i<pEList->nExpr; i++){
117834 118122       Expr *p;
117835 118123       p = pEList->a[i].pExpr;
117836 118124       if( NEVER(p==0) ) continue;
117837 118125       if( pEList->a[i].zName ){
117838 118126         char *zName = pEList->a[i].zName;
117839 118127         sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
117840         -    }else if( p->op==TK_COLUMN || p->op==TK_AGG_COLUMN ){
117841         -      Table *pTab;
       118128  +    }else if( (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN)
       118129  +           && (pTab = tableWithCursor(pTabList, p->iTable))!=0
       118130  +    ){
117842 118131         char *zCol;
117843 118132         int iCol = p->iColumn;
117844         -      for(j=0; ALWAYS(j<pTabList->nSrc); j++){
117845         -        if( pTabList->a[j].iCursor==p->iTable ) break;
117846         -      }
117847         -      assert( j<pTabList->nSrc );
117848         -      pTab = pTabList->a[j].pTab;
117849 118133         if( iCol<0 ) iCol = pTab->iPKey;
117850 118134         assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
117851 118135         if( iCol<0 ){
117852 118136           zCol = "rowid";
117853 118137         }else{
117854 118138           zCol = pTab->aCol[iCol].zName;
117855 118139         }
................................................................................
117923 118207       }else{
117924 118208         Expr *pColExpr = p;  /* The expression that is the result column name */
117925 118209         Table *pTab;         /* Table associated with this expression */
117926 118210         while( pColExpr->op==TK_DOT ){
117927 118211           pColExpr = pColExpr->pRight;
117928 118212           assert( pColExpr!=0 );
117929 118213         }
117930         -      if( pColExpr->op==TK_COLUMN && ALWAYS(pColExpr->pTab!=0) ){
       118214  +      if( pColExpr->op==TK_COLUMN && pColExpr->pTab!=0 ){
117931 118215           /* For columns use the column name name */
117932 118216           int iCol = pColExpr->iColumn;
117933 118217           pTab = pColExpr->pTab;
117934 118218           if( iCol<0 ) iCol = pTab->iPKey;
117935 118219           zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
117936 118220         }else if( pColExpr->op==TK_ID ){
117937 118221           assert( !ExprHasProperty(pColExpr, EP_IntValue) );
................................................................................
119143 119427           if( pItem->u.x.iOrderByCol==i ) break;
119144 119428         }
119145 119429         if( j==nOrderBy ){
119146 119430           Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
119147 119431           if( pNew==0 ) return SQLITE_NOMEM_BKPT;
119148 119432           pNew->flags |= EP_IntValue;
119149 119433           pNew->u.iValue = i;
119150         -        pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
       119434  +        p->pOrderBy = pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
119151 119435           if( pOrderBy ) pOrderBy->a[nOrderBy++].u.x.iOrderByCol = (u16)i;
119152 119436         }
119153 119437       }
119154 119438     }
119155 119439   
119156 119440     /* Compute the comparison permutation and keyinfo that is used with
119157 119441     ** the permutation used to determine if the next
................................................................................
119377 119661     **** subqueries ****/
119378 119662     explainComposite(pParse, p->op, iSub1, iSub2, 0);
119379 119663     return pParse->nErr!=0;
119380 119664   }
119381 119665   #endif
119382 119666   
119383 119667   #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
       119668  +
       119669  +/* An instance of the SubstContext object describes an substitution edit
       119670  +** to be performed on a parse tree.
       119671  +**
       119672  +** All references to columns in table iTable are to be replaced by corresponding
       119673  +** expressions in pEList.
       119674  +*/
       119675  +typedef struct SubstContext {
       119676  +  Parse *pParse;            /* The parsing context */
       119677  +  int iTable;               /* Replace references to this table */
       119678  +  int iNewTable;            /* New table number */
       119679  +  int isLeftJoin;           /* Add TK_IF_NULL_ROW opcodes on each replacement */
       119680  +  ExprList *pEList;         /* Replacement expressions */
       119681  +} SubstContext;
       119682  +
119384 119683   /* Forward Declarations */
119385         -static void substExprList(Parse*, ExprList*, int, ExprList*);
119386         -static void substSelect(Parse*, Select *, int, ExprList*, int);
       119684  +static void substExprList(SubstContext*, ExprList*);
       119685  +static void substSelect(SubstContext*, Select*, int);
119387 119686   
119388 119687   /*
119389 119688   ** Scan through the expression pExpr.  Replace every reference to
119390 119689   ** a column in table number iTable with a copy of the iColumn-th
119391 119690   ** entry in pEList.  (But leave references to the ROWID column 
119392 119691   ** unchanged.)
119393 119692   **
119394 119693   ** This routine is part of the flattening procedure.  A subquery
119395 119694   ** whose result set is defined by pEList appears as entry in the
119396 119695   ** FROM clause of a SELECT such that the VDBE cursor assigned to that
119397         -** FORM clause entry is iTable.  This routine make the necessary 
       119696  +** FORM clause entry is iTable.  This routine makes the necessary 
119398 119697   ** changes to pExpr so that it refers directly to the source table
119399 119698   ** of the subquery rather the result set of the subquery.
119400 119699   */
119401 119700   static Expr *substExpr(
119402         -  Parse *pParse,      /* Report errors here */
119403         -  Expr *pExpr,        /* Expr in which substitution occurs */
119404         -  int iTable,         /* Table to be substituted */
119405         -  ExprList *pEList    /* Substitute expressions */
       119701  +  SubstContext *pSubst,  /* Description of the substitution */
       119702  +  Expr *pExpr            /* Expr in which substitution occurs */
119406 119703   ){
119407         -  sqlite3 *db = pParse->db;
119408 119704     if( pExpr==0 ) return 0;
119409         -  if( pExpr->op==TK_COLUMN && pExpr->iTable==iTable ){
       119705  +  if( ExprHasProperty(pExpr, EP_FromJoin) && pExpr->iRightJoinTable==pSubst->iTable ){
       119706  +    pExpr->iRightJoinTable = pSubst->iNewTable;
       119707  +  }
       119708  +  if( pExpr->op==TK_COLUMN && pExpr->iTable==pSubst->iTable ){
119410 119709       if( pExpr->iColumn<0 ){
119411 119710         pExpr->op = TK_NULL;
119412 119711       }else{
119413 119712         Expr *pNew;
119414         -      Expr *pCopy = pEList->a[pExpr->iColumn].pExpr;
119415         -      assert( pEList!=0 && pExpr->iColumn<pEList->nExpr );
       119713  +      Expr *pCopy = pSubst->pEList->a[pExpr->iColumn].pExpr;
       119714  +      Expr ifNullRow;
       119715  +      assert( pSubst->pEList!=0 && pExpr->iColumn<pSubst->pEList->nExpr );
119416 119716         assert( pExpr->pLeft==0 && pExpr->pRight==0 );
119417 119717         if( sqlite3ExprIsVector(pCopy) ){
119418         -        sqlite3VectorErrorMsg(pParse, pCopy);
       119718  +        sqlite3VectorErrorMsg(pSubst->pParse, pCopy);
119419 119719         }else{
       119720  +        sqlite3 *db = pSubst->pParse->db;
       119721  +        if( pSubst->isLeftJoin && pCopy->op!=TK_COLUMN ){
       119722  +          memset(&ifNullRow, 0, sizeof(ifNullRow));
       119723  +          ifNullRow.op = TK_IF_NULL_ROW;
       119724  +          ifNullRow.pLeft = pCopy;
       119725  +          ifNullRow.iTable = pSubst->iNewTable;
       119726  +          pCopy = &ifNullRow;
       119727  +        }
119420 119728           pNew = sqlite3ExprDup(db, pCopy, 0);
119421 119729           if( pNew && (pExpr->flags & EP_FromJoin) ){
119422 119730             pNew->iRightJoinTable = pExpr->iRightJoinTable;
119423 119731             pNew->flags |= EP_FromJoin;
119424 119732           }
119425 119733           sqlite3ExprDelete(db, pExpr);
119426 119734           pExpr = pNew;
119427 119735         }
119428 119736       }
119429 119737     }else{
119430         -    pExpr->pLeft = substExpr(pParse, pExpr->pLeft, iTable, pEList);
119431         -    pExpr->pRight = substExpr(pParse, pExpr->pRight, iTable, pEList);
       119738  +    if( pExpr->op==TK_IF_NULL_ROW && pExpr->iTable==pSubst->iTable ){
       119739  +      pExpr->iTable = pSubst->iNewTable;
       119740  +    }
       119741  +    pExpr->pLeft = substExpr(pSubst, pExpr->pLeft);
       119742  +    pExpr->pRight = substExpr(pSubst, pExpr->pRight);
119432 119743       if( ExprHasProperty(pExpr, EP_xIsSelect) ){
119433         -      substSelect(pParse, pExpr->x.pSelect, iTable, pEList, 1);
       119744  +      substSelect(pSubst, pExpr->x.pSelect, 1);
119434 119745       }else{
119435         -      substExprList(pParse, pExpr->x.pList, iTable, pEList);
       119746  +      substExprList(pSubst, pExpr->x.pList);
119436 119747       }
119437 119748     }
119438 119749     return pExpr;
119439 119750   }
119440 119751   static void substExprList(
119441         -  Parse *pParse,       /* Report errors here */
119442         -  ExprList *pList,     /* List to scan and in which to make substitutes */
119443         -  int iTable,          /* Table to be substituted */
119444         -  ExprList *pEList     /* Substitute values */
       119752  +  SubstContext *pSubst, /* Description of the substitution */
       119753  +  ExprList *pList       /* List to scan and in which to make substitutes */
119445 119754   ){
119446 119755     int i;
119447 119756     if( pList==0 ) return;
119448 119757     for(i=0; i<pList->nExpr; i++){
119449         -    pList->a[i].pExpr = substExpr(pParse, pList->a[i].pExpr, iTable, pEList);
       119758  +    pList->a[i].pExpr = substExpr(pSubst, pList->a[i].pExpr);
119450 119759     }
119451 119760   }
119452 119761   static void substSelect(
119453         -  Parse *pParse,       /* Report errors here */
119454         -  Select *p,           /* SELECT statement in which to make substitutions */
119455         -  int iTable,          /* Table to be replaced */
119456         -  ExprList *pEList,    /* Substitute values */
119457         -  int doPrior          /* Do substitutes on p->pPrior too */
       119762  +  SubstContext *pSubst, /* Description of the substitution */
       119763  +  Select *p,            /* SELECT statement in which to make substitutions */
       119764  +  int doPrior           /* Do substitutes on p->pPrior too */
119458 119765   ){
119459 119766     SrcList *pSrc;
119460 119767     struct SrcList_item *pItem;
119461 119768     int i;
119462 119769     if( !p ) return;
119463 119770     do{
119464         -    substExprList(pParse, p->pEList, iTable, pEList);
119465         -    substExprList(pParse, p->pGroupBy, iTable, pEList);
119466         -    substExprList(pParse, p->pOrderBy, iTable, pEList);
119467         -    p->pHaving = substExpr(pParse, p->pHaving, iTable, pEList);
119468         -    p->pWhere = substExpr(pParse, p->pWhere, iTable, pEList);
       119771  +    substExprList(pSubst, p->pEList);
       119772  +    substExprList(pSubst, p->pGroupBy);
       119773  +    substExprList(pSubst, p->pOrderBy);
       119774  +    p->pHaving = substExpr(pSubst, p->pHaving);
       119775  +    p->pWhere = substExpr(pSubst, p->pWhere);
119469 119776       pSrc = p->pSrc;
119470 119777       assert( pSrc!=0 );
119471 119778       for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
119472         -      substSelect(pParse, pItem->pSelect, iTable, pEList, 1);
       119779  +      substSelect(pSubst, pItem->pSelect, 1);
119473 119780         if( pItem->fg.isTabFunc ){
119474         -        substExprList(pParse, pItem->u1.pFuncArg, iTable, pEList);
       119781  +        substExprList(pSubst, pItem->u1.pFuncArg);
119475 119782         }
119476 119783       }
119477 119784     }while( doPrior && (p = p->pPrior)!=0 );
119478 119785   }
119479 119786   #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
119480 119787   
119481 119788   #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
................................................................................
119510 119817   **   (1)  The subquery and the outer query do not both use aggregates.
119511 119818   **
119512 119819   **   (2)  The subquery is not an aggregate or (2a) the outer query is not a join
119513 119820   **        and (2b) the outer query does not use subqueries other than the one
119514 119821   **        FROM-clause subquery that is a candidate for flattening.  (2b is
119515 119822   **        due to ticket [2f7170d73bf9abf80] from 2015-02-09.)
119516 119823   **
119517         -**   (3)  The subquery is not the right operand of a left outer join
119518         -**        (Originally ticket #306.  Strengthened by ticket #3300)
       119824  +**   (3)  The subquery is not the right operand of a LEFT JOIN
       119825  +**        or the subquery is not itself a join and the outer query is not
       119826  +**        an aggregate.
119519 119827   **
119520 119828   **   (4)  The subquery is not DISTINCT.
119521 119829   **
119522 119830   **  (**)  At one point restrictions (4) and (5) defined a subset of DISTINCT
119523 119831   **        sub-queries that were excluded from this optimization. Restriction 
119524 119832   **        (4) has since been expanded to exclude all DISTINCT subqueries.
119525 119833   **
119526 119834   **   (6)  The subquery does not use aggregates or the outer query is not
119527 119835   **        DISTINCT.
119528 119836   **
119529 119837   **   (7)  The subquery has a FROM clause.  TODO:  For subqueries without
119530         -**        A FROM clause, consider adding a FROM close with the special
       119838  +**        A FROM clause, consider adding a FROM clause with the special
119531 119839   **        table sqlite_once that consists of a single row containing a
119532 119840   **        single NULL.
119533 119841   **
119534 119842   **   (8)  The subquery does not use LIMIT or the outer query is not a join.
119535 119843   **
119536 119844   **   (9)  The subquery does not use LIMIT or the outer query does not use
119537 119845   **        aggregates.
................................................................................
119629 119937     Select *pParent;    /* Current UNION ALL term of the other query */
119630 119938     Select *pSub;       /* The inner query or "subquery" */
119631 119939     Select *pSub1;      /* Pointer to the rightmost select in sub-query */
119632 119940     SrcList *pSrc;      /* The FROM clause of the outer query */
119633 119941     SrcList *pSubSrc;   /* The FROM clause of the subquery */
119634 119942     ExprList *pList;    /* The result set of the outer query */
119635 119943     int iParent;        /* VDBE cursor number of the pSub result set temp table */
       119944  +  int iNewParent = -1;/* Replacement table for iParent */
       119945  +  int isLeftJoin = 0; /* True if pSub is the right side of a LEFT JOIN */    
119636 119946     int i;              /* Loop counter */
119637 119947     Expr *pWhere;                    /* The WHERE clause */
119638 119948     struct SrcList_item *pSubitem;   /* The subquery */
119639 119949     sqlite3 *db = pParse->db;
119640 119950   
119641 119951     /* Check to see if flattening is permitted.  Return 0 if not.
119642 119952     */
................................................................................
119655 119965       if( (p->pWhere && ExprHasProperty(p->pWhere,EP_Subquery))
119656 119966        || (sqlite3ExprListFlags(p->pEList) & EP_Subquery)!=0
119657 119967        || (sqlite3ExprListFlags(p->pOrderBy) & EP_Subquery)!=0
119658 119968       ){
119659 119969         return 0;                                          /* Restriction (2b)  */
119660 119970       }
119661 119971     }
119662         -    
       119972  +
119663 119973     pSubSrc = pSub->pSrc;
119664 119974     assert( pSubSrc );
119665 119975     /* Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants,
119666 119976     ** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET
119667 119977     ** because they could be computed at compile-time.  But when LIMIT and OFFSET
119668 119978     ** became arbitrary expressions, we were forced to add restrictions (13)
119669 119979     ** and (14). */
................................................................................
119693 120003     if( pSub->selFlags & (SF_Recursive|SF_MinMaxAgg) ){
119694 120004       return 0; /* Restrictions (22) and (24) */
119695 120005     }
119696 120006     if( (p->selFlags & SF_Recursive) && pSub->pPrior ){
119697 120007       return 0; /* Restriction (23) */
119698 120008     }
119699 120009   
119700         -  /* OBSOLETE COMMENT 1:
119701         -  ** Restriction 3:  If the subquery is a join, make sure the subquery is 
119702         -  ** not used as the right operand of an outer join.  Examples of why this
119703         -  ** is not allowed:
       120010  +  /*
       120011  +  ** If the subquery is the right operand of a LEFT JOIN, then the
       120012  +  ** subquery may not be a join itself.  Example of why this is not allowed:
119704 120013     **
119705 120014     **         t1 LEFT OUTER JOIN (t2 JOIN t3)
119706 120015     **
119707 120016     ** If we flatten the above, we would get
119708 120017     **
119709 120018     **         (t1 LEFT OUTER JOIN t2) JOIN t3
119710 120019     **
119711 120020     ** which is not at all the same thing.
119712 120021     **
119713         -  ** OBSOLETE COMMENT 2:
119714         -  ** Restriction 12:  If the subquery is the right operand of a left outer
119715         -  ** join, make sure the subquery has no WHERE clause.
119716         -  ** An examples of why this is not allowed:
       120022  +  ** If the subquery is the right operand of a LEFT JOIN, then the outer
       120023  +  ** query cannot be an aggregate.  This is an artifact of the way aggregates
       120024  +  ** are processed - there is not mechanism to determine if the LEFT JOIN
       120025  +  ** table should be all-NULL.
119717 120026     **
119718         -  **         t1 LEFT OUTER JOIN (SELECT * FROM t2 WHERE t2.x>0)
119719         -  **
119720         -  ** If we flatten the above, we would get
119721         -  **
119722         -  **         (t1 LEFT OUTER JOIN t2) WHERE t2.x>0
119723         -  **
119724         -  ** But the t2.x>0 test will always fail on a NULL row of t2, which
119725         -  ** effectively converts the OUTER JOIN into an INNER JOIN.
119726         -  **
119727         -  ** THIS OVERRIDES OBSOLETE COMMENTS 1 AND 2 ABOVE:
119728         -  ** Ticket #3300 shows that flattening the right term of a LEFT JOIN
119729         -  ** is fraught with danger.  Best to avoid the whole thing.  If the
119730         -  ** subquery is the right term of a LEFT JOIN, then do not flatten.
       120027  +  ** See also tickets #306, #350, and #3300.
119731 120028     */
119732 120029     if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
119733         -    return 0;
       120030  +    isLeftJoin = 1;
       120031  +    if( pSubSrc->nSrc>1 || isAgg ){
       120032  +      return 0; /* Restriction (3) */
       120033  +    }
119734 120034     }
       120035  +#ifdef SQLITE_EXTRA_IFNULLROW
       120036  +  else if( iFrom>0 && !isAgg ){
       120037  +    /* Setting isLeftJoin to -1 causes OP_IfNullRow opcodes to be generated for
       120038  +    ** every reference to any result column from subquery in a join, even though
       120039  +    ** they are not necessary.  This will stress-test the OP_IfNullRow opcode. */
       120040  +    isLeftJoin = -1;
       120041  +  }
       120042  +#endif
119735 120043   
119736 120044     /* Restriction 17: If the sub-query is a compound SELECT, then it must
119737 120045     ** use only the UNION ALL operator. And none of the simple select queries
119738 120046     ** that make up the compound SELECT are allowed to be aggregate or distinct
119739 120047     ** queries.
119740 120048     */
119741 120049     if( pSub->pPrior ){
................................................................................
119935 120243       /* Transfer the FROM clause terms from the subquery into the
119936 120244       ** outer query.
119937 120245       */
119938 120246       for(i=0; i<nSubSrc; i++){
119939 120247         sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
119940 120248         assert( pSrc->a[i+iFrom].fg.isTabFunc==0 );
119941 120249         pSrc->a[i+iFrom] = pSubSrc->a[i];
       120250  +      iNewParent = pSubSrc->a[i].iCursor;
119942 120251         memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
119943 120252       }
119944 120253       pSrc->a[iFrom].fg.jointype = jointype;
119945 120254     
119946 120255       /* Now begin substituting subquery result set expressions for 
119947 120256       ** references to the iParent in the outer query.
119948 120257       ** 
................................................................................
119980 120289         }
119981 120290         assert( pParent->pOrderBy==0 );
119982 120291         assert( pSub->pPrior==0 );
119983 120292         pParent->pOrderBy = pOrderBy;
119984 120293         pSub->pOrderBy = 0;
119985 120294       }
119986 120295       pWhere = sqlite3ExprDup(db, pSub->pWhere, 0);
       120296  +    if( isLeftJoin>0 ){
       120297  +      setJoinExpr(pWhere, iNewParent);
       120298  +    }
119987 120299       if( subqueryIsAgg ){
119988 120300         assert( pParent->pHaving==0 );
119989 120301         pParent->pHaving = pParent->pWhere;
119990 120302         pParent->pWhere = pWhere;
119991 120303         pParent->pHaving = sqlite3ExprAnd(db, 
119992 120304             sqlite3ExprDup(db, pSub->pHaving, 0), pParent->pHaving
119993 120305         );
119994 120306         assert( pParent->pGroupBy==0 );
119995 120307         pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
119996 120308       }else{
119997 120309         pParent->pWhere = sqlite3ExprAnd(db, pWhere, pParent->pWhere);
119998 120310       }
119999 120311       if( db->mallocFailed==0 ){
120000         -      substSelect(pParse, pParent, iParent, pSub->pEList, 0);
       120312  +      SubstContext x;
       120313  +      x.pParse = pParse;
       120314  +      x.iTable = iParent;
       120315  +      x.iNewTable = iNewParent;
       120316  +      x.isLeftJoin = isLeftJoin;
       120317  +      x.pEList = pSub->pEList;
       120318  +      substSelect(&x, pParent, 0);
120001 120319       }
120002 120320     
120003 120321       /* The flattened query is distinct if either the inner or the
120004 120322       ** outer query is distinct. 
120005 120323       */
120006 120324       pParent->selFlags |= pSub->selFlags & SF_Distinct;
120007 120325     
................................................................................
120096 120414       nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, iCursor);
120097 120415       pWhere = pWhere->pLeft;
120098 120416     }
120099 120417     if( ExprHasProperty(pWhere,EP_FromJoin) ) return 0; /* restriction 5 */
120100 120418     if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
120101 120419       nChng++;
120102 120420       while( pSubq ){
       120421  +      SubstContext x;
120103 120422         pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
120104         -      pNew = substExpr(pParse, pNew, iCursor, pSubq->pEList);
       120423  +      x.pParse = pParse;
       120424  +      x.iTable = iCursor;
       120425  +      x.iNewTable = iCursor;
       120426  +      x.isLeftJoin = 0;
       120427  +      x.pEList = pSubq->pEList;
       120428  +      pNew = substExpr(&x, pNew);
120105 120429         pSubq->pWhere = sqlite3ExprAnd(pParse->db, pSubq->pWhere, pNew);
120106 120430         pSubq = pSubq->pPrior;
120107 120431       }
120108 120432     }
120109 120433     return nChng;
120110 120434   }
120111 120435   #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
................................................................................
121088 121412           pParse->pVdbe, OP_Explain, pParse->iSelectId, 0, 0, zEqp, P4_DYNAMIC
121089 121413       );
121090 121414     }
121091 121415   }
121092 121416   #else
121093 121417   # define explainSimpleCount(a,b,c)
121094 121418   #endif
       121419  +
       121420  +/*
       121421  +** Context object for havingToWhereExprCb().
       121422  +*/
       121423  +struct HavingToWhereCtx {
       121424  +  Expr **ppWhere;
       121425  +  ExprList *pGroupBy;
       121426  +};
       121427  +
       121428  +/*
       121429  +** sqlite3WalkExpr() callback used by havingToWhere().
       121430  +**
       121431  +** If the node passed to the callback is a TK_AND node, return 
       121432  +** WRC_Continue to tell sqlite3WalkExpr() to iterate through child nodes.
       121433  +**
       121434  +** Otherwise, return WRC_Prune. In this case, also check if the 
       121435  +** sub-expression matches the criteria for being moved to the WHERE
       121436  +** clause. If so, add it to the WHERE clause and replace the sub-expression
       121437  +** within the HAVING expression with a constant "1".
       121438  +*/
       121439  +static int havingToWhereExprCb(Walker *pWalker, Expr *pExpr){
       121440  +  if( pExpr->op!=TK_AND ){
       121441  +    struct HavingToWhereCtx *p = pWalker->u.pHavingCtx;
       121442  +    if( sqlite3ExprIsConstantOrGroupBy(pWalker->pParse, pExpr, p->pGroupBy) ){
       121443  +      sqlite3 *db = pWalker->pParse->db;
       121444  +      Expr *pNew = sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[1], 0);
       121445  +      if( pNew ){
       121446  +        Expr *pWhere = *(p->ppWhere);
       121447  +        SWAP(Expr, *pNew, *pExpr);
       121448  +        pNew = sqlite3ExprAnd(db, pWhere, pNew);
       121449  +        *(p->ppWhere) = pNew;
       121450  +      }
       121451  +    }
       121452  +    return WRC_Prune;
       121453  +  }
       121454  +  return WRC_Continue;
       121455  +}
       121456  +
       121457  +/*
       121458  +** Transfer eligible terms from the HAVING clause of a query, which is
       121459  +** processed after grouping, to the WHERE clause, which is processed before
       121460  +** grouping. For example, the query:
       121461  +**
       121462  +**   SELECT * FROM <tables> WHERE a=? GROUP BY b HAVING b=? AND c=?
       121463  +**
       121464  +** can be rewritten as:
       121465  +**
       121466  +**   SELECT * FROM <tables> WHERE a=? AND b=? GROUP BY b HAVING c=?
       121467  +**
       121468  +** A term of the HAVING expression is eligible for transfer if it consists
       121469  +** entirely of constants and expressions that are also GROUP BY terms that
       121470  +** use the "BINARY" collation sequence.
       121471  +*/
       121472  +static void havingToWhere(
       121473  +  Parse *pParse,
       121474  +  ExprList *pGroupBy,
       121475  +  Expr *pHaving, 
       121476  +  Expr **ppWhere
       121477  +){
       121478  +  struct HavingToWhereCtx sCtx;
       121479  +  Walker sWalker;
       121480  +
       121481  +  sCtx.ppWhere = ppWhere;
       121482  +  sCtx.pGroupBy = pGroupBy;
       121483  +
       121484  +  memset(&sWalker, 0, sizeof(sWalker));
       121485  +  sWalker.pParse = pParse;
       121486  +  sWalker.xExprCallback = havingToWhereExprCb;
       121487  +  sWalker.u.pHavingCtx = &sCtx;
       121488  +  sqlite3WalkExpr(&sWalker, pHaving);
       121489  +}
       121490  +
       121491  +/*
       121492  +** Check to see if the pThis entry of pTabList is a self-join of a prior view.
       121493  +** If it is, then return the SrcList_item for the prior view.  If it is not,
       121494  +** then return 0.
       121495  +*/
       121496  +static struct SrcList_item *isSelfJoinView(
       121497  +  SrcList *pTabList,           /* Search for self-joins in this FROM clause */
       121498  +  struct SrcList_item *pThis   /* Search for prior reference to this subquery */
       121499  +){
       121500  +  struct SrcList_item *pItem;
       121501  +  for(pItem = pTabList->a; pItem<pThis; pItem++){
       121502  +    if( pItem->pSelect==0 ) continue;
       121503  +    if( pItem->fg.viaCoroutine ) continue;
       121504  +    if( pItem->zName==0 ) continue;
       121505  +    if( sqlite3_stricmp(pItem->zDatabase, pThis->zDatabase)!=0 ) continue;
       121506  +    if( sqlite3_stricmp(pItem->zName, pThis->zName)!=0 ) continue;
       121507  +    if( sqlite3ExprCompare(pThis->pSelect->pWhere, pItem->pSelect->pWhere, -1) ){
       121508  +      /* The view was modified by some other optimization such as
       121509  +      ** pushDownWhereTerms() */
       121510  +      continue;
       121511  +    }
       121512  +    return pItem;
       121513  +  }
       121514  +  return 0;
       121515  +}
121095 121516   
121096 121517   /*
121097 121518   ** Generate code for the SELECT statement given in the p argument.  
121098 121519   **
121099 121520   ** The results are returned according to the SelectDest structure.
121100 121521   ** See comments in sqliteInt.h for further information.
121101 121522   **
................................................................................
121228 121649       SELECTTRACE(1,pParse,p,("end compound-select processing\n"));
121229 121650       pParse->nSelectIndent--;
121230 121651   #endif
121231 121652       return rc;
121232 121653     }
121233 121654   #endif
121234 121655   
121235         -  /* Generate code for all sub-queries in the FROM clause
       121656  +  /* For each term in the FROM clause, do two things:
       121657  +  ** (1) Authorized unreferenced tables
       121658  +  ** (2) Generate code for all sub-queries
121236 121659     */
121237         -#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
121238 121660     for(i=0; i<pTabList->nSrc; i++){
121239 121661       struct SrcList_item *pItem = &pTabList->a[i];
121240 121662       SelectDest dest;
121241         -    Select *pSub = pItem->pSelect;
       121663  +    Select *pSub;
       121664  +
       121665  +    /* Issue SQLITE_READ authorizations with a fake column name for any tables that
       121666  +    ** are referenced but from which no values are extracted. Examples of where these
       121667  +    ** kinds of null SQLITE_READ authorizations would occur:
       121668  +    **
       121669  +    **     SELECT count(*) FROM t1;   -- SQLITE_READ t1.""
       121670  +    **     SELECT t1.* FROM t1, t2;   -- SQLITE_READ t2.""
       121671  +    **
       121672  +    ** The fake column name is an empty string.  It is possible for a table to
       121673  +    ** have a column named by the empty string, in which case there is no way to
       121674  +    ** distinguish between an unreferenced table and an actual reference to the
       121675  +    ** "" column.  The original design was for the fake column name to be a NULL,
       121676  +    ** which would be unambiguous.  But legacy authorization callbacks might
       121677  +    ** assume the column name is non-NULL and segfault.  The use of an empty string
       121678  +    ** for the fake column name seems safer.
       121679  +    */
       121680  +    if( pItem->colUsed==0 ){
       121681  +      sqlite3AuthCheck(pParse, SQLITE_READ, pItem->zName, "", pItem->zDatabase);
       121682  +    }
       121683  +
       121684  +#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
       121685  +    /* Generate code for all sub-queries in the FROM clause
       121686  +    */
       121687  +    pSub = pItem->pSelect;
121242 121688       if( pSub==0 ) continue;
121243 121689   
121244 121690       /* Sometimes the code for a subquery will be generated more than
121245 121691       ** once, if the subquery is part of the WHERE clause in a LEFT JOIN,
121246 121692       ** for example.  In that case, do not regenerate the code to manifest
121247 121693       ** a view or the co-routine to implement a view.  The first instance
121248 121694       ** is sufficient, though the subroutine to manifest the view does need
121249 121695       ** to be invoked again. */
121250 121696       if( pItem->addrFillSub ){
121251 121697         if( pItem->fg.viaCoroutine==0 ){
       121698  +        /* The subroutine that manifests the view might be a one-time routine,
       121699  +        ** or it might need to be rerun on each iteration because it
       121700  +        ** encodes a correlated subquery. */
       121701  +        testcase( sqlite3VdbeGetOp(v, pItem->addrFillSub)->opcode==OP_Once );
121252 121702           sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub);
121253 121703         }
121254 121704         continue;
121255 121705       }
121256 121706   
121257 121707       /* Increment Parse.nHeight by the height of the largest expression
121258 121708       ** tree referred to by this, the parent select. The child select
................................................................................
121319 121769         ** the content of this subquery.  pItem->addrFillSub will point
121320 121770         ** to the address of the generated subroutine.  pItem->regReturn
121321 121771         ** is a register allocated to hold the subroutine return address
121322 121772         */
121323 121773         int topAddr;
121324 121774         int onceAddr = 0;
121325 121775         int retAddr;
       121776  +      struct SrcList_item *pPrior;
       121777  +
121326 121778         assert( pItem->addrFillSub==0 );
121327 121779         pItem->regReturn = ++pParse->nMem;
121328 121780         topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
121329 121781         pItem->addrFillSub = topAddr+1;
121330 121782         if( pItem->fg.isCorrelated==0 ){
121331 121783           /* If the subquery is not correlated and if we are not inside of
121332 121784           ** a trigger, then we only need to compute the value of the subquery
121333 121785           ** once. */
121334 121786           onceAddr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
121335 121787           VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
121336 121788         }else{
121337 121789           VdbeNoopComment((v, "materialize \"%s\"", pItem->pTab->zName));
121338 121790         }
121339         -      sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
121340         -      explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
121341         -      sqlite3Select(pParse, pSub, &dest);
       121791  +      pPrior = isSelfJoinView(pTabList, pItem);
       121792  +      if( pPrior ){
       121793  +        sqlite3VdbeAddOp2(v, OP_OpenDup, pItem->iCursor, pPrior->iCursor);
       121794  +      }else{
       121795  +        sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
       121796  +        explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
       121797  +        sqlite3Select(pParse, pSub, &dest);
       121798  +      }
121342 121799         pItem->pTab->nRowLogEst = pSub->nSelectRow;
121343 121800         if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
121344 121801         retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn);
121345 121802         VdbeComment((v, "end %s", pItem->pTab->zName));
121346 121803         sqlite3VdbeChangeP1(v, topAddr, retAddr);
121347 121804         sqlite3ClearTempRegCache(pParse);
121348 121805       }
121349 121806       if( db->mallocFailed ) goto select_end;
121350 121807       pParse->nHeight -= sqlite3SelectExprHeight(p);
       121808  +#endif
121351 121809     }
121352         -#endif
121353 121810   
121354 121811     /* Various elements of the SELECT copied into local variables for
121355 121812     ** convenience */
121356 121813     pEList = p->pEList;
121357 121814     pWhere = p->pWhere;
121358 121815     pGroupBy = p->pGroupBy;
121359 121816     pHaving = p->pHaving;
................................................................................
121553 122010       sNC.pAggInfo = &sAggInfo;
121554 122011       sAggInfo.mnReg = pParse->nMem+1;
121555 122012       sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr : 0;
121556 122013       sAggInfo.pGroupBy = pGroupBy;
121557 122014       sqlite3ExprAnalyzeAggList(&sNC, pEList);
121558 122015       sqlite3ExprAnalyzeAggList(&sNC, sSort.pOrderBy);
121559 122016       if( pHaving ){
       122017  +      if( pGroupBy ){
       122018  +        assert( pWhere==p->pWhere );
       122019  +        havingToWhere(pParse, pGroupBy, pHaving, &p->pWhere);
       122020  +        pWhere = p->pWhere;
       122021  +      }
121560 122022         sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
121561 122023       }
121562 122024       sAggInfo.nAccumulator = sAggInfo.nColumn;
121563 122025       for(i=0; i<sAggInfo.nFunc; i++){
121564 122026         assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) );
121565 122027         sNC.ncFlags |= NC_InAggFunc;
121566 122028         sqlite3ExprAnalyzeAggList(&sNC, sAggInfo.aFunc[i].pExpr->x.pList);
................................................................................
123565 124027     ** being updated.  Fill in aRegIdx[] with a register number that will hold
123566 124028     ** the key for accessing each index.
123567 124029     **
123568 124030     ** FIXME:  Be smarter about omitting indexes that use expressions.
123569 124031     */
123570 124032     for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
123571 124033       int reg;
123572         -    if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
       124034  +    if( chngKey || hasFK>1 || pIdx->pPartIdxWhere || pIdx==pPk ){
123573 124035         reg = ++pParse->nMem;
123574 124036         pParse->nMem += pIdx->nColumn;
123575 124037       }else{
123576 124038         reg = 0;
123577 124039         for(i=0; i<pIdx->nKeyCol; i++){
123578 124040           i16 iIdxCol = pIdx->aiColumn[i];
123579 124041           if( iIdxCol<0 || aXRef[iIdxCol]>=0 ){
................................................................................
123920 124382       ** pre-update hook. If the caller invokes preupdate_new(), the returned
123921 124383       ** value is copied from memory cell (regNewRowid+1+iCol), where iCol
123922 124384       ** is the column index supplied by the user.
123923 124385       */
123924 124386       assert( regNew==regNewRowid+1 );
123925 124387   #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
123926 124388       sqlite3VdbeAddOp3(v, OP_Delete, iDataCur,
123927         -        OPFLAG_ISUPDATE | ((hasFK || chngKey) ? 0 : OPFLAG_ISNOOP),
       124389  +        OPFLAG_ISUPDATE | ((hasFK>1 || chngKey) ? 0 : OPFLAG_ISNOOP),
123928 124390           regNewRowid
123929 124391       );
123930 124392       if( eOnePass==ONEPASS_MULTI ){
123931 124393         assert( hasFK==0 && chngKey==0 );
123932 124394         sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION);
123933 124395       }
123934 124396       if( !pParse->nested ){
123935 124397         sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
123936 124398       }
123937 124399   #else
123938         -    if( hasFK || chngKey ){
       124400  +    if( hasFK>1 || chngKey ){
123939 124401         sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
123940 124402       }
123941 124403   #endif
123942 124404       if( bReplace || chngKey ){
123943 124405         sqlite3VdbeJumpHere(v, addr1);
123944 124406       }
123945 124407   
................................................................................
125574 126036     unsigned char *z;
125575 126037   
125576 126038   
125577 126039     /* Check to see the left operand is a column in a virtual table */
125578 126040     if( NEVER(pExpr==0) ) return pDef;
125579 126041     if( pExpr->op!=TK_COLUMN ) return pDef;
125580 126042     pTab = pExpr->pTab;
125581         -  if( NEVER(pTab==0) ) return pDef;
       126043  +  if( pTab==0 ) return pDef;
125582 126044     if( !IsVirtual(pTab) ) return pDef;
125583 126045     pVtab = sqlite3GetVTable(db, pTab)->pVtab;
125584 126046     assert( pVtab!=0 );
125585 126047     assert( pVtab->pModule!=0 );
125586 126048     pMod = (sqlite3_module *)pVtab->pModule;
125587 126049     if( pMod->xFindFunction==0 ) return pDef;
125588 126050    
................................................................................
125909 126371     LogEst rRun;          /* Cost of running each loop */
125910 126372     LogEst nOut;          /* Estimated number of output rows */
125911 126373     union {
125912 126374       struct {               /* Information for internal btree tables */
125913 126375         u16 nEq;               /* Number of equality constraints */
125914 126376         u16 nBtm;              /* Size of BTM vector */
125915 126377         u16 nTop;              /* Size of TOP vector */
       126378  +      u16 nIdxCol;           /* Index column used for ORDER BY */
125916 126379         Index *pIndex;         /* Index used, or NULL */
125917 126380       } btree;
125918 126381       struct {               /* Information for virtual tables */
125919 126382         int idxNum;            /* Index number */
125920 126383         u8 needFree;           /* True if sqlite3_free(idxStr) is needed */
125921 126384         i8 isOrdered;          /* True if satisfies ORDER BY */
125922 126385         u16 omitMask;          /* Terms that may be omitted */
................................................................................
126202 126665   ** planner.
126203 126666   */
126204 126667   struct WhereInfo {
126205 126668     Parse *pParse;            /* Parsing and code generating context */
126206 126669     SrcList *pTabList;        /* List of tables in the join */
126207 126670     ExprList *pOrderBy;       /* The ORDER BY clause or NULL */
126208 126671     ExprList *pResultSet;     /* Result set of the query */
       126672  +  Expr *pWhere;             /* The complete WHERE clause */
126209 126673     LogEst iLimit;            /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
126210 126674     int aiCurOnePass[2];      /* OP_OpenWrite cursors for the ONEPASS opt */
126211 126675     int iContinue;            /* Jump here to continue with next record */
126212 126676     int iBreak;               /* Jump here to break out of the loop */
126213 126677     int savedNQueryLoop;      /* pParse->nQueryLoop outside the WHERE loop */
126214 126678     u16 wctrlFlags;           /* Flags originally passed to sqlite3WhereBegin() */
126215 126679     u8 nLevel;                /* Number of nested loop */
................................................................................
127361 127825         }
127362 127826       }
127363 127827     }else{
127364 127828       assert( nReg==1 );
127365 127829       sqlite3ExprCode(pParse, p, iReg);
127366 127830     }
127367 127831   }
       127832  +
       127833  +/* An instance of the IdxExprTrans object carries information about a
       127834  +** mapping from an expression on table columns into a column in an index
       127835  +** down through the Walker.
       127836  +*/
       127837  +typedef struct IdxExprTrans {
       127838  +  Expr *pIdxExpr;    /* The index expression */
       127839  +  int iTabCur;       /* The cursor of the corresponding table */
       127840  +  int iIdxCur;       /* The cursor for the index */
       127841  +  int iIdxCol;       /* The column for the index */
       127842  +} IdxExprTrans;
       127843  +
       127844  +/* The walker node callback used to transform matching expressions into
       127845  +** a reference to an index column for an index on an expression.
       127846  +**
       127847  +** If pExpr matches, then transform it into a reference to the index column
       127848  +** that contains the value of pExpr.
       127849  +*/
       127850  +static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
       127851  +  IdxExprTrans *pX = p->u.pIdxTrans;
       127852  +  if( sqlite3ExprCompare(pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
       127853  +    pExpr->op = TK_COLUMN;
       127854  +    pExpr->iTable = pX->iIdxCur;
       127855  +    pExpr->iColumn = pX->iIdxCol;
       127856  +    pExpr->pTab = 0;
       127857  +    return WRC_Prune;
       127858  +  }else{
       127859  +    return WRC_Continue;
       127860  +  }
       127861  +}
       127862  +
       127863  +/*
       127864  +** For an indexes on expression X, locate every instance of expression X in pExpr
       127865  +** and change that subexpression into a reference to the appropriate column of
       127866  +** the index.
       127867  +*/
       127868  +static void whereIndexExprTrans(
       127869  +  Index *pIdx,      /* The Index */
       127870  +  int iTabCur,      /* Cursor of the table that is being indexed */
       127871  +  int iIdxCur,      /* Cursor of the index itself */
       127872  +  WhereInfo *pWInfo /* Transform expressions in this WHERE clause */
       127873  +){
       127874  +  int iIdxCol;               /* Column number of the index */
       127875  +  ExprList *aColExpr;        /* Expressions that are indexed */
       127876  +  Walker w;
       127877  +  IdxExprTrans x;
       127878  +  aColExpr = pIdx->aColExpr;
       127879  +  if( aColExpr==0 ) return;  /* Not an index on expressions */
       127880  +  memset(&w, 0, sizeof(w));
       127881  +  w.xExprCallback = whereIndexExprTransNode;
       127882  +  w.u.pIdxTrans = &x;
       127883  +  x.iTabCur = iTabCur;
       127884  +  x.iIdxCur = iIdxCur;
       127885  +  for(iIdxCol=0; iIdxCol<aColExpr->nExpr; iIdxCol++){
       127886  +    if( pIdx->aiColumn[iIdxCol]!=XN_EXPR ) continue;
       127887  +    assert( aColExpr->a[iIdxCol].pExpr!=0 );
       127888  +    x.iIdxCol = iIdxCol;
       127889  +    x.pIdxExpr = aColExpr->a[iIdxCol].pExpr;
       127890  +    sqlite3WalkExpr(&w, pWInfo->pWhere);
       127891  +    sqlite3WalkExprList(&w, pWInfo->pOrderBy);
       127892  +    sqlite3WalkExprList(&w, pWInfo->pResultSet);
       127893  +  }
       127894  +}
127368 127895   
127369 127896   /*
127370 127897   ** Generate code for the start of the iLevel-th loop in the WHERE clause
127371 127898   ** implementation described by pWInfo.
127372 127899   */
127373 127900   SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
127374 127901     WhereInfo *pWInfo,   /* Complete information about the WHERE clause */
................................................................................
127389 127916     Vdbe *v;                        /* The prepared stmt under constructions */
127390 127917     struct SrcList_item *pTabItem;  /* FROM clause term being coded */
127391 127918     int addrBrk;                    /* Jump here to break out of the loop */
127392 127919     int addrHalt;                   /* addrBrk for the outermost loop */
127393 127920     int addrCont;                   /* Jump here to continue with next cycle */
127394 127921     int iRowidReg = 0;        /* Rowid is stored in this register, if not zero */
127395 127922     int iReleaseReg = 0;      /* Temp register to free before returning */
       127923  +  Index *pIdx = 0;          /* Index used by loop (if any) */
       127924  +  int loopAgain;            /* True if constraint generator loop should repeat */
127396 127925   
127397 127926     pParse = pWInfo->pParse;
127398 127927     v = pParse->pVdbe;
127399 127928     pWC = &pWInfo->sWC;
127400 127929     db = pParse->db;
127401 127930     pLevel = &pWInfo->a[iLevel];
127402 127931     pLoop = pLevel->pWLoop;
................................................................................
127714 128243       int regBase;                 /* Base register holding constraint values */
127715 128244       WhereTerm *pRangeStart = 0;  /* Inequality constraint at range start */
127716 128245       WhereTerm *pRangeEnd = 0;    /* Inequality constraint at range end */
127717 128246       int startEq;                 /* True if range start uses ==, >= or <= */
127718 128247       int endEq;                   /* True if range end uses ==, >= or <= */
127719 128248       int start_constraints;       /* Start of range is constrained */
127720 128249       int nConstraint;             /* Number of constraint terms */
127721         -    Index *pIdx;                 /* The index we will be using */
127722 128250       int iIdxCur;                 /* The VDBE cursor for the index */
127723 128251       int nExtraReg = 0;           /* Number of extra registers needed */
127724 128252       int op;                      /* Instruction opcode */
127725 128253       char *zStartAff;             /* Affinity for start of range constraint */
127726 128254       char *zEndAff = 0;           /* Affinity for end of range constraint */
127727 128255       u8 bSeekPastNull = 0;        /* True to seek past initial nulls */
127728 128256       u8 bStopAtNull = 0;          /* Add condition to terminate at NULLs */
................................................................................
127942 128470         for(j=0; j<pPk->nKeyCol; j++){
127943 128471           k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
127944 128472           sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
127945 128473         }
127946 128474         sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont,
127947 128475                              iRowidReg, pPk->nKeyCol); VdbeCoverage(v);
127948 128476       }
       128477  +
       128478  +    /* If pIdx is an index on one or more expressions, then look through
       128479  +    ** all the expressions in pWInfo and try to transform matching expressions
       128480  +    ** into reference to index columns.
       128481  +    */
       128482  +    whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
       128483  +
127949 128484   
127950 128485       /* Record the instruction used to terminate the loop. */
127951 128486       if( pLoop->wsFlags & WHERE_ONEROW ){
127952 128487         pLevel->op = OP_Noop;
127953 128488       }else if( bRev ){
127954 128489         pLevel->op = OP_Prev;
127955 128490       }else{
................................................................................
127958 128493       pLevel->p1 = iIdxCur;
127959 128494       pLevel->p3 = (pLoop->wsFlags&WHERE_UNQ_WANTED)!=0 ? 1:0;
127960 128495       if( (pLoop->wsFlags & WHERE_CONSTRAINT)==0 ){
127961 128496         pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
127962 128497       }else{
127963 128498         assert( pLevel->p5==0 );
127964 128499       }
       128500  +    if( omitTable ) pIdx = 0;
127965 128501     }else
127966 128502   
127967 128503   #ifndef SQLITE_OMIT_OR_OPTIMIZATION
127968 128504     if( pLoop->wsFlags & WHERE_MULTI_OR ){
127969 128505       /* Case 5:  Two or more separately indexed terms connected by OR
127970 128506       **
127971 128507       ** Example:
................................................................................
128275 128811   
128276 128812   #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
128277 128813     pLevel->addrVisit = sqlite3VdbeCurrentAddr(v);
128278 128814   #endif
128279 128815   
128280 128816     /* Insert code to test every subexpression that can be completely
128281 128817     ** computed using the current set of tables.
128282         -  */
128283         -  for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
128284         -    Expr *pE;
128285         -    int skipLikeAddr = 0;
128286         -    testcase( pTerm->wtFlags & TERM_VIRTUAL );
128287         -    testcase( pTerm->wtFlags & TERM_CODED );
128288         -    if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
128289         -    if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
128290         -      testcase( pWInfo->untestedTerms==0
128291         -               && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 );
128292         -      pWInfo->untestedTerms = 1;
128293         -      continue;
128294         -    }
128295         -    pE = pTerm->pExpr;
128296         -    assert( pE!=0 );
128297         -    if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
128298         -      continue;
128299         -    }
128300         -    if( pTerm->wtFlags & TERM_LIKECOND ){
128301         -      /* If the TERM_LIKECOND flag is set, that means that the range search
128302         -      ** is sufficient to guarantee that the LIKE operator is true, so we
128303         -      ** can skip the call to the like(A,B) function.  But this only works
128304         -      ** for strings.  So do not skip the call to the function on the pass
128305         -      ** that compares BLOBs. */
       128818  +  **
       128819  +  ** This loop may run either once (pIdx==0) or twice (pIdx!=0). If
       128820  +  ** it is run twice, then the first iteration codes those sub-expressions
       128821  +  ** that can be computed using columns from pIdx only (without seeking
       128822  +  ** the main table cursor). 
       128823  +  */
       128824  +  do{
       128825  +    loopAgain = 0;
       128826  +    for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
       128827  +      Expr *pE;
       128828  +      int skipLikeAddr = 0;
       128829  +      testcase( pTerm->wtFlags & TERM_VIRTUAL );
       128830  +      testcase( pTerm->wtFlags & TERM_CODED );
       128831  +      if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
       128832  +      if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
       128833  +        testcase( pWInfo->untestedTerms==0
       128834  +            && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 );
       128835  +        pWInfo->untestedTerms = 1;
       128836  +        continue;
       128837  +      }
       128838  +      pE = pTerm->pExpr;
       128839  +      assert( pE!=0 );
       128840  +      if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
       128841  +        continue;
       128842  +      }
       128843  +      if( pIdx && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
       128844  +        loopAgain = 1;
       128845  +        continue;
       128846  +      }
       128847  +      if( pTerm->wtFlags & TERM_LIKECOND ){
       128848  +        /* If the TERM_LIKECOND flag is set, that means that the range search
       128849  +        ** is sufficient to guarantee that the LIKE operator is true, so we
       128850  +        ** can skip the call to the like(A,B) function.  But this only works
       128851  +        ** for strings.  So do not skip the call to the function on the pass
       128852  +        ** that compares BLOBs. */
128306 128853   #ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS
128307         -      continue;
       128854  +        continue;
128308 128855   #else
128309         -      u32 x = pLevel->iLikeRepCntr;
128310         -      assert( x>0 );
128311         -      skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)? OP_IfNot : OP_If, (int)(x>>1));
128312         -      VdbeCoverage(v);
       128856  +        u32 x = pLevel->iLikeRepCntr;
       128857  +        assert( x>0 );
       128858  +        skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)?OP_IfNot:OP_If, (int)(x>>1));
       128859  +        VdbeCoverage(v);
128313 128860   #endif
       128861  +      }
       128862  +      sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
       128863  +      if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
       128864  +      pTerm->wtFlags |= TERM_CODED;
128314 128865       }
128315         -    sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
128316         -    if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
128317         -    pTerm->wtFlags |= TERM_CODED;
128318         -  }
       128866  +    pIdx = 0;
       128867  +  }while( loopAgain );
128319 128868   
128320 128869     /* Insert code to test for implied constraints based on transitivity
128321 128870     ** of the "==" operator.
128322 128871     **
128323 128872     ** Example: If the WHERE clause contains "t1.a=t2.b" and "t2.b=123"
128324 128873     ** and we are coding the t1 loop and the t2 loop has not yet coded,
128325 128874     ** then we cannot use the "t1.a=t2.b" constraint, but we can code
................................................................................
129204 129753     return mask;
129205 129754   }
129206 129755   
129207 129756   /*
129208 129757   ** Expression pExpr is one operand of a comparison operator that might
129209 129758   ** be useful for indexing.  This routine checks to see if pExpr appears
129210 129759   ** in any index.  Return TRUE (1) if pExpr is an indexed term and return
129211         -** FALSE (0) if not.  If TRUE is returned, also set *piCur to the cursor
129212         -** number of the table that is indexed and *piColumn to the column number
       129760  +** FALSE (0) if not.  If TRUE is returned, also set aiCurCol[0] to the cursor
       129761  +** number of the table that is indexed and aiCurCol[1] to the column number
129213 129762   ** of the column that is indexed, or XN_EXPR (-2) if an expression is being
129214 129763   ** indexed.
129215 129764   **
129216 129765   ** If pExpr is a TK_COLUMN column reference, then this routine always returns
129217 129766   ** true even if that particular column is not indexed, because the column
129218 129767   ** might be added to an automatic index later.
129219 129768   */
129220         -static int exprMightBeIndexed(
       129769  +static SQLITE_NOINLINE int exprMightBeIndexed2(
129221 129770     SrcList *pFrom,        /* The FROM clause */
129222         -  int op,                /* The specific comparison operator */
129223 129771     Bitmask mPrereq,       /* Bitmask of FROM clause terms referenced by pExpr */
129224         -  Expr *pExpr,           /* An operand of a comparison operator */
129225         -  int *piCur,            /* Write the referenced table cursor number here */
129226         -  int *piColumn          /* Write the referenced table column number here */
       129772  +  int *aiCurCol,         /* Write the referenced table cursor and column here */
       129773  +  Expr *pExpr            /* An operand of a comparison operator */
129227 129774   ){
129228 129775     Index *pIdx;
129229 129776     int i;
129230 129777     int iCur;
129231         -
       129778  +  for(i=0; mPrereq>1; i++, mPrereq>>=1){}
       129779  +  iCur = pFrom->a[i].iCursor;
       129780  +  for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){
       129781  +    if( pIdx->aColExpr==0 ) continue;
       129782  +    for(i=0; i<pIdx->nKeyCol; i++){
       129783  +      if( pIdx->aiColumn[i]!=XN_EXPR ) continue;
       129784  +      if( sqlite3ExprCompareSkip(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
       129785  +        aiCurCol[0] = iCur;
       129786  +        aiCurCol[1] = XN_EXPR;
       129787  +        return 1;
       129788  +      }
       129789  +    }
       129790  +  }
       129791  +  return 0;
       129792  +}
       129793  +static int exprMightBeIndexed(
       129794  +  SrcList *pFrom,        /* The FROM clause */
       129795  +  Bitmask mPrereq,       /* Bitmask of FROM clause terms referenced by pExpr */
       129796  +  int *aiCurCol,         /* Write the referenced table cursor & column here */
       129797  +  Expr *pExpr,           /* An operand of a comparison operator */
       129798  +  int op                 /* The specific comparison operator */
       129799  +){
129232 129800     /* If this expression is a vector to the left or right of a 
129233 129801     ** inequality constraint (>, <, >= or <=), perform the processing 
129234 129802     ** on the first element of the vector.  */
129235 129803     assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE );
129236 129804     assert( TK_IS<TK_GE && TK_ISNULL<TK_GE && TK_IN<TK_GE );
129237 129805     assert( op<=TK_GE );
129238 129806     if( pExpr->op==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){
129239 129807       pExpr = pExpr->x.pList->a[0].pExpr;
129240 129808     }
129241 129809   
129242 129810     if( pExpr->op==TK_COLUMN ){
129243         -    *piCur = pExpr->iTable;
129244         -    *piColumn = pExpr->iColumn;
       129811  +    aiCurCol[0] = pExpr->iTable;
       129812  +    aiCurCol[1] = pExpr->iColumn;
129245 129813       return 1;
129246 129814     }
129247 129815     if( mPrereq==0 ) return 0;                 /* No table references */
129248 129816     if( (mPrereq&(mPrereq-1))!=0 ) return 0;   /* Refs more than one table */
129249         -  for(i=0; mPrereq>1; i++, mPrereq>>=1){}
129250         -  iCur = pFrom->a[i].iCursor;
129251         -  for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){
129252         -    if( pIdx->aColExpr==0 ) continue;
129253         -    for(i=0; i<pIdx->nKeyCol; i++){
129254         -      if( pIdx->aiColumn[i]!=XN_EXPR ) continue;
129255         -      if( sqlite3ExprCompareSkip(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
129256         -        *piCur = iCur;
129257         -        *piColumn = XN_EXPR;
129258         -        return 1;
129259         -      }
129260         -    }
129261         -  }
129262         -  return 0;
       129817  +  return exprMightBeIndexed2(pFrom,mPrereq,aiCurCol,pExpr);
129263 129818   }
129264 129819   
129265 129820   /*
129266 129821   ** The input to this routine is an WhereTerm structure with only the
129267 129822   ** "pExpr" field filled in.  The job of this routine is to analyze the
129268 129823   ** subexpression and populate all the other fields of the WhereTerm
129269 129824   ** structure.
................................................................................
129335 129890       }
129336 129891     }
129337 129892     pTerm->prereqAll = prereqAll;
129338 129893     pTerm->leftCursor = -1;
129339 129894     pTerm->iParent = -1;
129340 129895     pTerm->eOperator = 0;
129341 129896     if( allowedOp(op) ){
129342         -    int iCur, iColumn;
       129897  +    int aiCurCol[2];
129343 129898       Expr *pLeft = sqlite3ExprSkipCollate(pExpr->pLeft);
129344 129899       Expr *pRight = sqlite3ExprSkipCollate(pExpr->pRight);
129345 129900       u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
129346 129901   
129347 129902       if( pTerm->iField>0 ){
129348 129903         assert( op==TK_IN );
129349 129904         assert( pLeft->op==TK_VECTOR );
129350 129905         pLeft = pLeft->x.pList->a[pTerm->iField-1].pExpr;
129351 129906       }
129352 129907   
129353         -    if( exprMightBeIndexed(pSrc, op, prereqLeft, pLeft, &iCur, &iColumn) ){
129354         -      pTerm->leftCursor = iCur;
129355         -      pTerm->u.leftColumn = iColumn;
       129908  +    if( exprMightBeIndexed(pSrc, prereqLeft, aiCurCol, pLeft, op) ){
       129909  +      pTerm->leftCursor = aiCurCol[0];
       129910  +      pTerm->u.leftColumn = aiCurCol[1];
129356 129911         pTerm->eOperator = operatorMask(op) & opMask;
129357 129912       }
129358 129913       if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
129359 129914       if( pRight 
129360         -     && exprMightBeIndexed(pSrc, op, pTerm->prereqRight, pRight, &iCur,&iColumn)
       129915  +     && exprMightBeIndexed(pSrc, pTerm->prereqRight, aiCurCol, pRight, op)
129361 129916       ){
129362 129917         WhereTerm *pNew;
129363 129918         Expr *pDup;
129364 129919         u16 eExtraOp = 0;        /* Extra bits for pNew->eOperator */
129365 129920         assert( pTerm->iField==0 );
129366 129921         if( pTerm->leftCursor>=0 ){
129367 129922           int idxNew;
................................................................................
129383 129938             eExtraOp = WO_EQUIV;
129384 129939           }
129385 129940         }else{
129386 129941           pDup = pExpr;
129387 129942           pNew = pTerm;
129388 129943         }
129389 129944         exprCommute(pParse, pDup);
129390         -      pNew->leftCursor = iCur;
129391         -      pNew->u.leftColumn = iColumn;
       129945  +      pNew->leftCursor = aiCurCol[0];
       129946  +      pNew->u.leftColumn = aiCurCol[1];
129392 129947         testcase( (prereqLeft | extraRight) != prereqLeft );
129393 129948         pNew->prereqRight = prereqLeft | extraRight;
129394 129949         pNew->prereqAll = prereqAll;
129395 129950         pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
129396 129951       }
129397 129952     }
129398 129953   
................................................................................
129743 130298   ** a bitmask indicating which tables are used in that expression
129744 130299   ** tree.
129745 130300   */
129746 130301   SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
129747 130302     Bitmask mask;
129748 130303     if( p==0 ) return 0;
129749 130304     if( p->op==TK_COLUMN ){
129750         -    mask = sqlite3WhereGetMask(pMaskSet, p->iTable);
129751         -    return mask;
       130305  +    return sqlite3WhereGetMask(pMaskSet, p->iTable);
129752 130306     }
       130307  +  mask = (p->op==TK_IF_NULL_ROW) ? sqlite3WhereGetMask(pMaskSet, p->iTable) : 0;
129753 130308     assert( !ExprHasProperty(p, EP_TokenOnly) );
129754         -  mask = p->pRight ? sqlite3WhereExprUsage(pMaskSet, p->pRight) : 0;
       130309  +  if( p->pRight ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pRight);
129755 130310     if( p->pLeft ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft);
129756 130311     if( ExprHasProperty(p, EP_xIsSelect) ){
129757 130312       mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
129758 130313     }else if( p->x.pList ){
129759 130314       mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
129760 130315     }
129761 130316     return mask;
................................................................................
131616 132171     if( p->wsFlags & (WHERE_VIRTUALTABLE|WHERE_AUTO_INDEX) ){
131617 132172       if( (p->wsFlags & WHERE_VIRTUALTABLE)!=0 && p->u.vtab.needFree ){
131618 132173         sqlite3_free(p->u.vtab.idxStr);
131619 132174         p->u.vtab.needFree = 0;
131620 132175         p->u.vtab.idxStr = 0;
131621 132176       }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
131622 132177         sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
131623         -      sqlite3DbFree(db, p->u.btree.pIndex);
       132178  +      sqlite3DbFreeNN(db, p->u.btree.pIndex);
131624 132179         p->u.btree.pIndex = 0;
131625 132180       }
131626 132181     }
131627 132182   }
131628 132183   
131629 132184   /*
131630 132185   ** Deallocate internal memory used by a WhereLoop object
131631 132186   */
131632 132187   static void whereLoopClear(sqlite3 *db, WhereLoop *p){
131633         -  if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFree(db, p->aLTerm);
       132188  +  if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
131634 132189     whereLoopClearUnion(db, p);
131635 132190     whereLoopInit(p);
131636 132191   }
131637 132192   
131638 132193   /*
131639 132194   ** Increase the memory allocation for pLoop->aLTerm[] to be at least n.
131640 132195   */
................................................................................
131641 132196   static int whereLoopResize(sqlite3 *db, WhereLoop *p, int n){
131642 132197     WhereTerm **paNew;
131643 132198     if( p->nLSlot>=n ) return SQLITE_OK;
131644 132199     n = (n+7)&~7;
131645 132200     paNew = sqlite3DbMallocRawNN(db, sizeof(p->aLTerm[0])*n);
131646 132201     if( paNew==0 ) return SQLITE_NOMEM_BKPT;
131647 132202     memcpy(paNew, p->aLTerm, sizeof(p->aLTerm[0])*p->nLSlot);
131648         -  if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFree(db, p->aLTerm);
       132203  +  if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
131649 132204     p->aLTerm = paNew;
131650 132205     p->nLSlot = n;
131651 132206     return SQLITE_OK;
131652 132207   }
131653 132208   
131654 132209   /*
131655 132210   ** Transfer content from the second pLoop into the first.
................................................................................
131671 132226   }
131672 132227   
131673 132228   /*
131674 132229   ** Delete a WhereLoop object
131675 132230   */
131676 132231   static void whereLoopDelete(sqlite3 *db, WhereLoop *p){
131677 132232     whereLoopClear(db, p);
131678         -  sqlite3DbFree(db, p);
       132233  +  sqlite3DbFreeNN(db, p);
131679 132234   }
131680 132235   
131681 132236   /*
131682 132237   ** Free a WhereInfo structure
131683 132238   */
131684 132239   static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
131685 132240     if( ALWAYS(pWInfo) ){
................................................................................
131692 132247       }
131693 132248       sqlite3WhereClauseClear(&pWInfo->sWC);
131694 132249       while( pWInfo->pLoops ){
131695 132250         WhereLoop *p = pWInfo->pLoops;
131696 132251         pWInfo->pLoops = p->pNextLoop;
131697 132252         whereLoopDelete(db, p);
131698 132253       }
131699         -    sqlite3DbFree(db, pWInfo);
       132254  +    sqlite3DbFreeNN(db, pWInfo);
131700 132255     }
131701 132256   }
131702 132257   
131703 132258   /*
131704 132259   ** Return TRUE if all of the following are true:
131705 132260   **
131706 132261   **   (1)  X has the same or lower cost that Y
................................................................................
133083 133638         WHERETRACE(0x40, ("  VirtualOne: all disabled and w/o IN\n"));
133084 133639         rc = whereLoopAddVirtualOne(
133085 133640             pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn);
133086 133641       }
133087 133642     }
133088 133643   
133089 133644     if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr);
133090         -  sqlite3DbFree(pParse->db, p);
       133645  +  sqlite3DbFreeNN(pParse->db, p);
133091 133646     return rc;
133092 133647   }
133093 133648   #endif /* SQLITE_OMIT_VIRTUALTABLE */
133094 133649   
133095 133650   /*
133096 133651   ** Add WhereLoop entries to handle OR terms.  This works for either
133097 133652   ** btrees or virtual tables.
................................................................................
133267 133822     }
133268 133823   
133269 133824     whereLoopClear(db, pNew);
133270 133825     return rc;
133271 133826   }
133272 133827   
133273 133828   /*
133274         -** Examine a WherePath (with the addition of the extra WhereLoop of the 5th
       133829  +** Examine a WherePath (with the addition of the extra WhereLoop of the 6th
133275 133830   ** parameters) to see if it outputs rows in the requested ORDER BY
133276 133831   ** (or GROUP BY) without requiring a separate sort operation.  Return N:
133277 133832   ** 
133278 133833   **   N>0:   N terms of the ORDER BY clause are satisfied
133279 133834   **   N==0:  No terms of the ORDER BY clause are satisfied
133280 133835   **   N<0:   Unknown yet how many terms of ORDER BY might be satisfied.   
133281 133836   **
................................................................................
133362 133917         if( wctrlFlags & WHERE_ORDERBY_LIMIT ) continue;
133363 133918       }else{
133364 133919         pLoop = pLast;
133365 133920       }
133366 133921       if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){
133367 133922         if( pLoop->u.vtab.isOrdered ) obSat = obDone;
133368 133923         break;
       133924  +    }else{
       133925  +      pLoop->u.btree.nIdxCol = 0;
133369 133926       }
133370 133927       iCur = pWInfo->pTabList->a[pLoop->iTab].iCursor;
133371 133928   
133372 133929       /* Mark off any ORDER BY term X that is a column in the table of
133373 133930       ** the current loop for which there is term in the WHERE
133374 133931       ** clause of the form X IS NULL or X=? that reference only outer
133375 133932       ** loops.
................................................................................
133507 134064               }
133508 134065             }
133509 134066             if( iColumn>=0 ){
133510 134067               pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr);
133511 134068               if( !pColl ) pColl = db->pDfltColl;
133512 134069               if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
133513 134070             }
       134071  +          pLoop->u.btree.nIdxCol = j+1;
133514 134072             isMatch = 1;
133515 134073             break;
133516 134074           }
133517 134075           if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
133518 134076             /* Make sure the sort order is compatible in an ORDER BY clause.
133519 134077             ** Sort order is irrelevant for a GROUP BY clause. */
133520 134078             if( revSet ){
................................................................................
133938 134496       aTo = aFrom;
133939 134497       aFrom = pFrom;
133940 134498       nFrom = nTo;
133941 134499     }
133942 134500   
133943 134501     if( nFrom==0 ){
133944 134502       sqlite3ErrorMsg(pParse, "no query solution");
133945         -    sqlite3DbFree(db, pSpace);
       134503  +    sqlite3DbFreeNN(db, pSpace);
133946 134504       return SQLITE_ERROR;
133947 134505     }
133948 134506     
133949 134507     /* Find the lowest cost path.  pFrom will be left pointing to that path */
133950 134508     pFrom = aFrom;
133951 134509     for(ii=1; ii<nFrom; ii++){
133952 134510       if( pFrom->rCost>aFrom[ii].rCost ) pFrom = &aFrom[ii];
................................................................................
134014 134572       }
134015 134573     }
134016 134574   
134017 134575   
134018 134576     pWInfo->nRowOut = pFrom->nRow;
134019 134577   
134020 134578     /* Free temporary memory and return success */
134021         -  sqlite3DbFree(db, pSpace);
       134579  +  sqlite3DbFreeNN(db, pSpace);
134022 134580     return SQLITE_OK;
134023 134581   }
134024 134582   
134025 134583   /*
134026 134584   ** Most queries use only a single table (they are not joins) and have
134027 134585   ** simple == constraints against indexed fields.  This routine attempts
134028 134586   ** to plan those simple cases using much less ceremony than the
................................................................................
134092 134650         pLoop->rRun = 39;  /* 39==sqlite3LogEst(15) */
134093 134651         break;
134094 134652       }
134095 134653     }
134096 134654     if( pLoop->wsFlags ){
134097 134655       pLoop->nOut = (LogEst)1;
134098 134656       pWInfo->a[0].pWLoop = pLoop;
134099         -    pLoop->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur);
       134657  +    assert( pWInfo->sMaskSet.n==1 && iCur==pWInfo->sMaskSet.ix[0] );
       134658  +    pLoop->maskSelf = 1; /* sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur); */
134100 134659       pWInfo->a[0].iTabCur = iCur;
134101 134660       pWInfo->nRowOut = 1;
134102 134661       if( pWInfo->pOrderBy ) pWInfo->nOBSat =  pWInfo->pOrderBy->nExpr;
134103 134662       if( pWInfo->wctrlFlags & WHERE_WANT_DISTINCT ){
134104 134663         pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
134105 134664       }
134106 134665   #ifdef SQLITE_DEBUG
................................................................................
134276 134835       sqlite3DbFree(db, pWInfo);
134277 134836       pWInfo = 0;
134278 134837       goto whereBeginError;
134279 134838     }
134280 134839     pWInfo->pParse = pParse;
134281 134840     pWInfo->pTabList = pTabList;
134282 134841     pWInfo->pOrderBy = pOrderBy;
       134842  +  pWInfo->pWhere = pWhere;
134283 134843     pWInfo->pResultSet = pResultSet;
134284 134844     pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
134285 134845     pWInfo->nLevel = nTabList;
134286 134846     pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
134287 134847     pWInfo->wctrlFlags = wctrlFlags;
134288 134848     pWInfo->iLimit = iAuxArg;
134289 134849     pWInfo->savedNQueryLoop = pParse->nQueryLoop;
................................................................................
134586 135146         assert( iIndexCur>=0 );
134587 135147         if( op ){
134588 135148           sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
134589 135149           sqlite3VdbeSetP4KeyInfo(pParse, pIx);
134590 135150           if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=0
134591 135151            && (pLoop->wsFlags & (WHERE_COLUMN_RANGE|WHERE_SKIPSCAN))==0
134592 135152            && (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0
       135153  +         && pWInfo->eDistinct!=WHERE_DISTINCT_ORDERED
134593 135154           ){
134594 135155             sqlite3VdbeChangeP5(v, OPFLAG_SEEKEQ); /* Hint to COMDB2 */
134595 135156           }
134596 135157           VdbeComment((v, "%s", pIx->zName));
134597 135158   #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
134598 135159           {
134599 135160             u64 colUsed = 0;
................................................................................
134674 135235     */
134675 135236     VdbeModuleComment((v, "End WHERE-core"));
134676 135237     sqlite3ExprCacheClear(pParse);
134677 135238     for(i=pWInfo->nLevel-1; i>=0; i--){
134678 135239       int addr;
134679 135240       pLevel = &pWInfo->a[i];
134680 135241       pLoop = pLevel->pWLoop;
134681         -    sqlite3VdbeResolveLabel(v, pLevel->addrCont);
134682 135242       if( pLevel->op!=OP_Noop ){
       135243  +#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
       135244  +      int addrSeek = 0;
       135245  +      Index *pIdx;
       135246  +      int n;
       135247  +      if( pWInfo->eDistinct==WHERE_DISTINCT_ORDERED
       135248  +       && (pLoop->wsFlags & WHERE_INDEXED)!=0
       135249  +       && (pIdx = pLoop->u.btree.pIndex)->hasStat1
       135250  +       && (n = pLoop->u.btree.nIdxCol)>0
       135251  +       && pIdx->aiRowLogEst[n]>=36
       135252  +      ){
       135253  +        int r1 = pParse->nMem+1;
       135254  +        int j, op;
       135255  +        for(j=0; j<n; j++){
       135256  +          sqlite3VdbeAddOp3(v, OP_Column, pLevel->iIdxCur, j, r1+j);
       135257  +        }
       135258  +        pParse->nMem += n+1;
       135259  +        op = pLevel->op==OP_Prev ? OP_SeekLT : OP_SeekGT;
       135260  +        addrSeek = sqlite3VdbeAddOp4Int(v, op, pLevel->iIdxCur, 0, r1, n);
       135261  +        VdbeCoverageIf(v, op==OP_SeekLT);
       135262  +        VdbeCoverageIf(v, op==OP_SeekGT);
       135263  +        sqlite3VdbeAddOp2(v, OP_Goto, 1, pLevel->p2);
       135264  +      }
       135265  +#endif /* SQLITE_DISABLE_SKIPAHEAD_DISTINCT */
       135266  +      /* The common case: Advance to the next row */
       135267  +      sqlite3VdbeResolveLabel(v, pLevel->addrCont);
134683 135268         sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
134684 135269         sqlite3VdbeChangeP5(v, pLevel->p5);
134685 135270         VdbeCoverage(v);
134686 135271         VdbeCoverageIf(v, pLevel->op==OP_Next);
134687 135272         VdbeCoverageIf(v, pLevel->op==OP_Prev);
134688 135273         VdbeCoverageIf(v, pLevel->op==OP_VNext);
       135274  +#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
       135275  +      if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek);
       135276  +#endif
       135277  +    }else{
       135278  +      sqlite3VdbeResolveLabel(v, pLevel->addrCont);
134689 135279       }
134690 135280       if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
134691 135281         struct InLoop *pIn;
134692 135282         int j;
134693 135283         sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
134694 135284         for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
134695 135285           sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
................................................................................
134804 135394               pOp->p1 = pLevel->iIdxCur;
134805 135395             }
134806 135396             assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0 
134807 135397                 || pWInfo->eOnePass );
134808 135398           }else if( pOp->opcode==OP_Rowid ){
134809 135399             pOp->p1 = pLevel->iIdxCur;
134810 135400             pOp->opcode = OP_IdxRowid;
       135401  +        }else if( pOp->opcode==OP_IfNullRow ){
       135402  +          pOp->p1 = pLevel->iIdxCur;
134811 135403           }
134812 135404         }
134813 135405       }
134814 135406     }
134815 135407   
134816 135408     /* Final cleanup
134817 135409     */
................................................................................
135113 135705   #ifndef INTERFACE
135114 135706   # define INTERFACE 1
135115 135707   #endif
135116 135708   /************* Begin control #defines *****************************************/
135117 135709   #define YYCODETYPE unsigned char
135118 135710   #define YYNOCODE 252
135119 135711   #define YYACTIONTYPE unsigned short int
135120         -#define YYWILDCARD 96
       135712  +#define YYWILDCARD 69
135121 135713   #define sqlite3ParserTOKENTYPE Token
135122 135714   typedef union {
135123 135715     int yyinit;
135124 135716     sqlite3ParserTOKENTYPE yy0;
135125 135717     Expr* yy72;
135126 135718     TriggerStep* yy145;
135127 135719     ExprList* yy148;
................................................................................
135220 135812   **  yy_shift_ofst[]    For each state, the offset into yy_action for
135221 135813   **                     shifting terminals.
135222 135814   **  yy_reduce_ofst[]   For each state, the offset into yy_action for
135223 135815   **                     shifting non-terminals after a reduce.
135224 135816   **  yy_default[]       Default action for each state.
135225 135817   **
135226 135818   *********** Begin parsing tables **********************************************/
135227         -#define YY_ACTTAB_COUNT (1567)
       135819  +#define YY_ACTTAB_COUNT (1566)
135228 135820   static const YYACTIONTYPE yy_action[] = {
135229         - /*     0 */   325,  832,  351,  825,    5,  203,  203,  819,   99,  100,
135230         - /*    10 */    90,  978,  978,  853,  856,  845,  845,   97,   97,   98,
135231         - /*    20 */    98,   98,   98,  301,   96,   96,   96,   96,   95,   95,
135232         - /*    30 */    94,   94,   94,   93,  351,  325,  976,  976,  824,  824,
135233         - /*    40 */   826,  946,  354,   99,  100,   90,  978,  978,  853,  856,
135234         - /*    50 */   845,  845,   97,   97,   98,   98,   98,   98,  338,   96,
135235         - /*    60 */    96,   96,   96,   95,   95,   94,   94,   94,   93,  351,
135236         - /*    70 */    95,   95,   94,   94,   94,   93,  351,  791,  976,  976,
135237         - /*    80 */   325,   94,   94,   94,   93,  351,  792,   75,   99,  100,
135238         - /*    90 */    90,  978,  978,  853,  856,  845,  845,   97,   97,   98,
135239         - /*   100 */    98,   98,   98,  450,   96,   96,   96,   96,   95,   95,
135240         - /*   110 */    94,   94,   94,   93,  351, 1333,  155,  155,    2,  325,
135241         - /*   120 */   275,  146,  132,   52,   52,   93,  351,   99,  100,   90,
135242         - /*   130 */   978,  978,  853,  856,  845,  845,   97,   97,   98,   98,
135243         - /*   140 */    98,   98,  101,   96,   96,   96,   96,   95,   95,   94,
135244         - /*   150 */    94,   94,   93,  351,  957,  957,  325,  268,  428,  413,
135245         - /*   160 */   411,   61,  752,  752,   99,  100,   90,  978,  978,  853,
135246         - /*   170 */   856,  845,  845,   97,   97,   98,   98,   98,   98,   60,
135247         - /*   180 */    96,   96,   96,   96,   95,   95,   94,   94,   94,   93,
135248         - /*   190 */   351,  325,  270,  329,  273,  277,  958,  959,  250,   99,
135249         - /*   200 */   100,   90,  978,  978,  853,  856,  845,  845,   97,   97,
135250         - /*   210 */    98,   98,   98,   98,  301,   96,   96,   96,   96,   95,
135251         - /*   220 */    95,   94,   94,   94,   93,  351,  325,  937, 1326,  698,
135252         - /*   230 */   706, 1326,  242,  412,   99,  100,   90,  978,  978,  853,
135253         - /*   240 */   856,  845,  845,   97,   97,   98,   98,   98,   98,  347,
135254         - /*   250 */    96,   96,   96,   96,   95,   95,   94,   94,   94,   93,
135255         - /*   260 */   351,  325,  937, 1327,  384,  699, 1327,  381,  379,   99,
135256         - /*   270 */   100,   90,  978,  978,  853,  856,  845,  845,   97,   97,
135257         - /*   280 */    98,   98,   98,   98,  701,   96,   96,   96,   96,   95,
135258         - /*   290 */    95,   94,   94,   94,   93,  351,  325,   92,   89,  178,
135259         - /*   300 */   833,  935,  373,  700,   99,  100,   90,  978,  978,  853,
135260         - /*   310 */   856,  845,  845,   97,   97,   98,   98,   98,   98,  375,
135261         - /*   320 */    96,   96,   96,   96,   95,   95,   94,   94,   94,   93,
135262         - /*   330 */   351,  325, 1275,  946,  354,  818,  935,  739,  739,   99,
135263         - /*   340 */   100,   90,  978,  978,  853,  856,  845,  845,   97,   97,
135264         - /*   350 */    98,   98,   98,   98,  230,   96,   96,   96,   96,   95,
135265         - /*   360 */    95,   94,   94,   94,   93,  351,  325,  968,  227,   92,
135266         - /*   370 */    89,  178,  373,  300,   99,  100,   90,  978,  978,  853,
135267         - /*   380 */   856,  845,  845,   97,   97,   98,   98,   98,   98,  920,
135268         - /*   390 */    96,   96,   96,   96,   95,   95,   94,   94,   94,   93,
135269         - /*   400 */   351,  325,  449,  447,  447,  447,  147,  737,  737,   99,
135270         - /*   410 */   100,   90,  978,  978,  853,  856,  845,  845,   97,   97,
135271         - /*   420 */    98,   98,   98,   98,  296,   96,   96,   96,   96,   95,
135272         - /*   430 */    95,   94,   94,   94,   93,  351,  325,  419,  231,  957,
135273         - /*   440 */   957,  158,   25,  422,   99,  100,   90,  978,  978,  853,
135274         - /*   450 */   856,  845,  845,   97,   97,   98,   98,   98,   98,  450,
135275         - /*   460 */    96,   96,   96,   96,   95,   95,   94,   94,   94,   93,
135276         - /*   470 */   351,  443,  224,  224,  420,  957,  957,  961,  325,   52,
135277         - /*   480 */    52,  958,  959,  176,  415,   78,   99,  100,   90,  978,
135278         - /*   490 */   978,  853,  856,  845,  845,   97,   97,   98,   98,   98,
135279         - /*   500 */    98,  379,   96,   96,   96,   96,   95,   95,   94,   94,
135280         - /*   510 */    94,   93,  351,  325,  428,  418,  298,  958,  959,  961,
135281         - /*   520 */    81,   99,   88,   90,  978,  978,  853,  856,  845,  845,
135282         - /*   530 */    97,   97,   98,   98,   98,   98,  717,   96,   96,   96,
135283         - /*   540 */    96,   95,   95,   94,   94,   94,   93,  351,  325,  842,
135284         - /*   550 */   842,  854,  857,  996,  318,  343,  379,  100,   90,  978,
135285         - /*   560 */   978,  853,  856,  845,  845,   97,   97,   98,   98,   98,
135286         - /*   570 */    98,  450,   96,   96,   96,   96,   95,   95,   94,   94,
135287         - /*   580 */    94,   93,  351,  325,  350,  350,  350,  260,  377,  340,
135288         - /*   590 */   928,   52,   52,   90,  978,  978,  853,  856,  845,  845,
135289         - /*   600 */    97,   97,   98,   98,   98,   98,  361,   96,   96,   96,
135290         - /*   610 */    96,   95,   95,   94,   94,   94,   93,  351,   86,  445,
135291         - /*   620 */   846,    3, 1202,  361,  360,  378,  344,  813,  957,  957,
135292         - /*   630 */  1299,   86,  445,  729,    3,  212,  169,  287,  405,  282,
135293         - /*   640 */   404,  199,  232,  450,  300,  760,   83,   84,  280,  245,
135294         - /*   650 */   262,  365,  251,   85,  352,  352,   92,   89,  178,   83,
135295         - /*   660 */    84,  242,  412,   52,   52,  448,   85,  352,  352,  246,
135296         - /*   670 */   958,  959,  194,  455,  670,  402,  399,  398,  448,  243,
135297         - /*   680 */   221,  114,  434,  776,  361,  450,  397,  268,  747,  224,
135298         - /*   690 */   224,  132,  132,  198,  832,  434,  452,  451,  428,  427,
135299         - /*   700 */   819,  415,  734,  713,  132,   52,   52,  832,  268,  452,
135300         - /*   710 */   451,  734,  194,  819,  363,  402,  399,  398,  450, 1270,
135301         - /*   720 */  1270,   23,  957,  957,   86,  445,  397,    3,  228,  429,
135302         - /*   730 */   894,  824,  824,  826,  827,   19,  203,  720,   52,   52,
135303         - /*   740 */   428,  408,  439,  249,  824,  824,  826,  827,   19,  229,
135304         - /*   750 */   403,  153,   83,   84,  761,  177,  241,  450,  721,   85,
135305         - /*   760 */   352,  352,  120,  157,  958,  959,   58,  976,  409,  355,
135306         - /*   770 */   330,  448,  268,  428,  430,  320,  790,   32,   32,   86,
135307         - /*   780 */   445,  776,    3,  341,   98,   98,   98,   98,  434,   96,
135308         - /*   790 */    96,   96,   96,   95,   95,   94,   94,   94,   93,  351,
135309         - /*   800 */   832,  120,  452,  451,  813,  886,  819,   83,   84,  976,
135310         - /*   810 */   813,  132,  410,  919,   85,  352,  352,  132,  407,  789,
135311         - /*   820 */   957,  957,   92,   89,  178,  916,  448,  262,  370,  261,
135312         - /*   830 */    82,  913,   80,  262,  370,  261,  776,  824,  824,  826,
135313         - /*   840 */   827,   19,  933,  434,   96,   96,   96,   96,   95,   95,
135314         - /*   850 */    94,   94,   94,   93,  351,  832,   74,  452,  451,  957,
135315         - /*   860 */   957,  819,  958,  959,  120,   92,   89,  178,  944,    2,
135316         - /*   870 */   917,  964,  268,    1,  975,   76,  445,  762,    3,  708,
135317         - /*   880 */   900,  900,  387,  957,  957,  757,  918,  371,  740,  778,
135318         - /*   890 */   756,  257,  824,  824,  826,  827,   19,  417,  741,  450,
135319         - /*   900 */    24,  958,  959,   83,   84,  369,  957,  957,  177,  226,
135320         - /*   910 */    85,  352,  352,  884,  315,  314,  313,  215,  311,   10,
135321         - /*   920 */    10,  683,  448,  349,  348,  958,  959,  908,  777,  157,
135322         - /*   930 */   120,  957,  957,  337,  776,  416,  711,  310,  450,  434,
135323         - /*   940 */   450,  321,  450,  791,  103,  200,  175,  450,  958,  959,
135324         - /*   950 */   907,  832,  792,  452,  451,    9,    9,  819,   10,   10,
135325         - /*   960 */    52,   52,   51,   51,  180,  716,  248,   10,   10,  171,
135326         - /*   970 */   170,  167,  339,  958,  959,  247,  984,  702,  702,  450,
135327         - /*   980 */   715,  233,  686,  982,  888,  983,  182,  913,  824,  824,
135328         - /*   990 */   826,  827,   19,  183,  256,  423,  132,  181,  394,   10,
135329         - /*  1000 */    10,  888,  890,  749,  957,  957,  916,  268,  985,  198,
135330         - /*  1010 */   985,  349,  348,  425,  415,  299,  817,  832,  326,  825,
135331         - /*  1020 */   120,  332,  133,  819,  268,   98,   98,   98,   98,   91,
135332         - /*  1030 */    96,   96,   96,   96,   95,   95,   94,   94,   94,   93,
135333         - /*  1040 */   351,  157,  810,  371,  382,  359,  958,  959,  358,  268,
135334         - /*  1050 */   450,  917,  368,  324,  824,  824,  826,  450,  709,  450,
135335         - /*  1060 */   264,  380,  888,  450,  876,  746,  253,  918,  255,  433,
135336         - /*  1070 */    36,   36,  234,  450,  234,  120,  269,   37,   37,   12,
135337         - /*  1080 */    12,  334,  272,   27,   27,  450,  330,  118,  450,  162,
135338         - /*  1090 */   742,  280,  450,   38,   38,  450,  985,  356,  985,  450,
135339         - /*  1100 */   709, 1209,  450,  132,  450,   39,   39,  450,   40,   40,
135340         - /*  1110 */   450,  362,   41,   41,  450,   42,   42,  450,  254,   28,
135341         - /*  1120 */    28,  450,   29,   29,   31,   31,  450,   43,   43,  450,
135342         - /*  1130 */    44,   44,  450,  714,   45,   45,  450,   11,   11,  767,
135343         - /*  1140 */   450,   46,   46,  450,  268,  450,  105,  105,  450,   47,
135344         - /*  1150 */    47,  450,   48,   48,  450,  237,   33,   33,  450,  172,
135345         - /*  1160 */    49,   49,  450,   50,   50,   34,   34,  274,  122,  122,
135346         - /*  1170 */   450,  123,  123,  450,  124,  124,  450,  897,   56,   56,
135347         - /*  1180 */   450,  896,   35,   35,  450,  267,  450,  817,  450,  817,
135348         - /*  1190 */   106,  106,  450,   53,   53,  385,  107,  107,  450,  817,
135349         - /*  1200 */   108,  108,  817,  450,  104,  104,  121,  121,  119,  119,
135350         - /*  1210 */   450,  117,  112,  112,  450,  276,  450,  225,  111,  111,
135351         - /*  1220 */   450,  730,  450,  109,  109,  450,  673,  674,  675,  911,
135352         - /*  1230 */   110,  110,  317,  998,   55,   55,   57,   57,  692,  331,
135353         - /*  1240 */    54,   54,   26,   26,  696,   30,   30,  317,  936,  197,
135354         - /*  1250 */   196,  195,  335,  281,  336,  446,  331,  745,  689,  436,
135355         - /*  1260 */   440,  444,  120,   72,  386,  223,  175,  345,  757,  932,
135356         - /*  1270 */    20,  286,  319,  756,  815,  372,  374,  202,  202,  202,
135357         - /*  1280 */   263,  395,  285,   74,  208,   21,  696,  719,  718,  883,
135358         - /*  1290 */   120,  120,  120,  120,  120,  754,  278,  828,   77,   74,
135359         - /*  1300 */   726,  727,  785,  783,  879,  202,  999,  208,  893,  892,
135360         - /*  1310 */   893,  892,  694,  816,  763,  116,  774, 1289,  431,  432,
135361         - /*  1320 */   302,  999,  390,  303,  823,  697,  691,  680,  159,  289,
135362         - /*  1330 */   679,  883,  681,  951,  291,  218,  293,    7,  316,  828,
135363         - /*  1340 */   173,  805,  259,  364,  252,  910,  376,  713,  295,  435,
135364         - /*  1350 */   308,  168,  954,  993,  135,  400,  990,  284,  881,  880,
135365         - /*  1360 */   205,  927,  925,   59,  333,   62,  144,  156,  130,   72,
135366         - /*  1370 */   802,  366,  367,  393,  137,  185,  189,  160,  139,  383,
135367         - /*  1380 */    67,  895,  140,  141,  142,  148,  389,  812,  775,  266,
135368         - /*  1390 */   219,  190,  154,  391,  912,  875,  271,  406,  191,  322,
135369         - /*  1400 */   682,  733,  192,  342,  732,  724,  731,  711,  723,  421,
135370         - /*  1410 */   705,   71,  323,    6,  204,  771,  288,   79,  297,  346,
135371         - /*  1420 */   772,  704,  290,  283,  703,  770,  292,  294,  966,  239,
135372         - /*  1430 */   769,  102,  861,  438,  426,  240,  424,  442,   73,  213,
135373         - /*  1440 */   688,  238,   22,  453,  952,  214,  217,  216,  454,  677,
135374         - /*  1450 */   676,  671,  753,  125,  115,  235,  126,  669,  353,  166,
135375         - /*  1460 */   127,  244,  179,  357,  306,  304,  305,  307,  113,  891,
135376         - /*  1470 */   327,  889,  811,  328,  134,  128,  136,  138,  743,  258,
135377         - /*  1480 */   906,  184,  143,  129,  909,  186,   63,   64,  145,  187,
135378         - /*  1490 */   905,   65,    8,   66,   13,  188,  202,  898,  265,  149,
135379         - /*  1500 */   987,  388,  150,  685,  161,  392,  285,  193,  279,  396,
135380         - /*  1510 */   151,  401,   68,   14,   15,  722,   69,  236,  831,  131,
135381         - /*  1520 */   830,  859,   70,  751,   16,  414,  755,    4,  174,  220,
135382         - /*  1530 */   222,  784,  201,  152,  779,   77,   74,   17,   18,  874,
135383         - /*  1540 */   860,  858,  915,  863,  914,  207,  206,  941,  163,  437,
135384         - /*  1550 */   947,  942,  164,  209, 1002,  441,  862,  165,  210,  829,
135385         - /*  1560 */   695,   87,  312,  211, 1291, 1290,  309,
       135821  + /*     0 */   325,  411,  343,  752,  752,  203,  946,  354,  976,   98,
       135822  + /*    10 */    98,   98,   98,   91,   96,   96,   96,   96,   95,   95,
       135823  + /*    20 */    94,   94,   94,   93,  351, 1333,  155,  155,    2,  813,
       135824  + /*    30 */   978,  978,   98,   98,   98,   98,   20,   96,   96,   96,
       135825  + /*    40 */    96,   95,   95,   94,   94,   94,   93,  351,   92,   89,
       135826  + /*    50 */   178,   99,  100,   90,  853,  856,  845,  845,   97,   97,
       135827  + /*    60 */    98,   98,   98,   98,  351,   96,   96,   96,   96,   95,
       135828  + /*    70 */    95,   94,   94,   94,   93,  351,  325,  340,  976,  262,
       135829  + /*    80 */   365,  251,  212,  169,  287,  405,  282,  404,  199,  791,
       135830  + /*    90 */   242,  412,   21,  957,  379,  280,   93,  351,  792,   95,
       135831  + /*   100 */    95,   94,   94,   94,   93,  351,  978,  978,   96,   96,
       135832  + /*   110 */    96,   96,   95,   95,   94,   94,   94,   93,  351,  813,
       135833  + /*   120 */   329,  242,  412,  913,  832,  913,  132,   99,  100,   90,
       135834  + /*   130 */   853,  856,  845,  845,   97,   97,   98,   98,   98,   98,
       135835  + /*   140 */   450,   96,   96,   96,   96,   95,   95,   94,   94,   94,
       135836  + /*   150 */    93,  351,  325,  825,  349,  348,  120,  819,  120,   75,
       135837  + /*   160 */    52,   52,  957,  958,  959,  760,  984,  146,  361,  262,
       135838  + /*   170 */   370,  261,  957,  982,  961,  983,   92,   89,  178,  371,
       135839  + /*   180 */   230,  371,  978,  978,  817,  361,  360,  101,  824,  824,
       135840  + /*   190 */   826,  384,   24,  964,  381,  428,  413,  369,  985,  380,
       135841  + /*   200 */   985,  708,  325,   99,  100,   90,  853,  856,  845,  845,
       135842  + /*   210 */    97,   97,   98,   98,   98,   98,  373,   96,   96,   96,
       135843  + /*   220 */    96,   95,   95,   94,   94,   94,   93,  351,  957,  132,
       135844  + /*   230 */   897,  450,  978,  978,  896,   60,   94,   94,   94,   93,
       135845  + /*   240 */   351,  957,  958,  959,  961,  103,  361,  957,  385,  334,
       135846  + /*   250 */   702,   52,   52,   99,  100,   90,  853,  856,  845,  845,
       135847  + /*   260 */    97,   97,   98,   98,   98,   98,  698,   96,   96,   96,
       135848  + /*   270 */    96,   95,   95,   94,   94,   94,   93,  351,  325,  455,
       135849  + /*   280 */   670,  450,  227,   61,  157,  243,  344,  114,  701,  888,
       135850  + /*   290 */   147,  832,  957,  373,  747,  957,  320,  957,  958,  959,
       135851  + /*   300 */   194,   10,   10,  402,  399,  398,  888,  890,  978,  978,
       135852  + /*   310 */   762,  171,  170,  157,  397,  337,  957,  958,  959,  702,
       135853  + /*   320 */   825,  310,  153,  957,  819,  321,   82,   23,   80,   99,
       135854  + /*   330 */   100,   90,  853,  856,  845,  845,   97,   97,   98,   98,
       135855  + /*   340 */    98,   98,  894,   96,   96,   96,   96,   95,   95,   94,
       135856  + /*   350 */    94,   94,   93,  351,  325,  824,  824,  826,  277,  231,
       135857  + /*   360 */   300,  957,  958,  959,  957,  958,  959,  888,  194,   25,
       135858  + /*   370 */   450,  402,  399,  398,  957,  355,  300,  450,  957,   74,
       135859  + /*   380 */   450,    1,  397,  132,  978,  978,  957,  224,  224,  813,
       135860  + /*   390 */    10,   10,  957,  958,  959,  968,  132,   52,   52,  415,
       135861  + /*   400 */    52,   52,  739,  739,  339,   99,  100,   90,  853,  856,
       135862  + /*   410 */   845,  845,   97,   97,   98,   98,   98,   98,  790,   96,
       135863  + /*   420 */    96,   96,   96,   95,   95,   94,   94,   94,   93,  351,
       135864  + /*   430 */   325,  789,  428,  418,  706,  428,  427, 1270, 1270,  262,
       135865  + /*   440 */   370,  261,  957,  957,  958,  959,  757,  957,  958,  959,
       135866  + /*   450 */   450,  756,  450,  734,  713,  957,  958,  959,  443,  711,
       135867  + /*   460 */   978,  978,  734,  394,   92,   89,  178,  447,  447,  447,
       135868  + /*   470 */    51,   51,   52,   52,  439,  778,  700,   92,   89,  178,
       135869  + /*   480 */   172,   99,  100,   90,  853,  856,  845,  845,   97,   97,
       135870  + /*   490 */    98,   98,   98,   98,  198,   96,   96,   96,   96,   95,
       135871  + /*   500 */    95,   94,   94,   94,   93,  351,  325,  428,  408,  916,
       135872  + /*   510 */   699,  957,  958,  959,   92,   89,  178,  224,  224,  157,
       135873  + /*   520 */   241,  221,  419,  299,  776,  917,  416,  375,  450,  415,
       135874  + /*   530 */    58,  324,  737,  737,  920,  379,  978,  978,  379,  777,
       135875  + /*   540 */   449,  918,  363,  740,  296,  686,    9,    9,   52,   52,
       135876  + /*   550 */   234,  330,  234,  256,  417,  741,  280,   99,  100,   90,
       135877  + /*   560 */   853,  856,  845,  845,   97,   97,   98,   98,   98,   98,
       135878  + /*   570 */   450,   96,   96,   96,   96,   95,   95,   94,   94,   94,
       135879  + /*   580 */    93,  351,  325,  423,   72,  450,  833,  120,  368,  450,
       135880  + /*   590 */    10,   10,    5,  301,  203,  450,  177,  976,  253,  420,
       135881  + /*   600 */   255,  776,  200,  175,  233,   10,   10,  842,  842,   36,
       135882  + /*   610 */    36, 1299,  978,  978,  729,   37,   37,  349,  348,  425,
       135883  + /*   620 */   203,  260,  776,  976,  232,  937, 1326,  876,  338, 1326,
       135884  + /*   630 */   422,  854,  857,   99,  100,   90,  853,  856,  845,  845,
       135885  + /*   640 */    97,   97,   98,   98,   98,   98,  268,   96,   96,   96,
       135886  + /*   650 */    96,   95,   95,   94,   94,   94,   93,  351,  325,  846,
       135887  + /*   660 */   450,  985,  818,  985, 1209,  450,  916,  976,  720,  350,
       135888  + /*   670 */   350,  350,  935,  177,  450,  937, 1327,  254,  198, 1327,
       135889  + /*   680 */    12,   12,  917,  403,  450,   27,   27,  250,  978,  978,
       135890  + /*   690 */   118,  721,  162,  976,   38,   38,  268,  176,  918,  776,
       135891  + /*   700 */   433, 1275,  946,  354,   39,   39,  317,  998,  325,   99,
       135892  + /*   710 */   100,   90,  853,  856,  845,  845,   97,   97,   98,   98,
       135893  + /*   720 */    98,   98,  935,   96,   96,   96,   96,   95,   95,   94,
       135894  + /*   730 */    94,   94,   93,  351,  450,  330,  450,  358,  978,  978,
       135895  + /*   740 */   717,  317,  936,  341,  900,  900,  387,  673,  674,  675,
       135896  + /*   750 */   275,  996,  318,  999,   40,   40,   41,   41,  268,   99,
       135897  + /*   760 */   100,   90,  853,  856,  845,  845,   97,   97,   98,   98,
       135898  + /*   770 */    98,   98,  450,   96,   96,   96,   96,   95,   95,   94,
       135899  + /*   780 */    94,   94,   93,  351,  325,  450,  356,  450,  999,  450,
       135900  + /*   790 */   692,  331,   42,   42,  791,  270,  450,  273,  450,  228,
       135901  + /*   800 */   450,  298,  450,  792,  450,   28,   28,   29,   29,   31,
       135902  + /*   810 */    31,  450,  817,  450,  978,  978,   43,   43,   44,   44,
       135903  + /*   820 */    45,   45,   11,   11,   46,   46,  893,   78,  893,  268,
       135904  + /*   830 */   268,  105,  105,   47,   47,   99,  100,   90,  853,  856,
       135905  + /*   840 */   845,  845,   97,   97,   98,   98,   98,   98,  450,   96,
       135906  + /*   850 */    96,   96,   96,   95,   95,   94,   94,   94,   93,  351,
       135907  + /*   860 */   325,  450,  117,  450,  749,  158,  450,  696,   48,   48,
       135908  + /*   870 */   229,  919,  450,  928,  450,  415,  450,  335,  450,  245,
       135909  + /*   880 */   450,   33,   33,   49,   49,  450,   50,   50,  246,  817,
       135910  + /*   890 */   978,  978,   34,   34,  122,  122,  123,  123,  124,  124,
       135911  + /*   900 */    56,   56,  268,   81,  249,   35,   35,  197,  196,  195,
       135912  + /*   910 */   325,   99,  100,   90,  853,  856,  845,  845,   97,   97,
       135913  + /*   920 */    98,   98,   98,   98,  450,   96,   96,   96,   96,   95,
       135914  + /*   930 */    95,   94,   94,   94,   93,  351,  450,  696,  450,  817,
       135915  + /*   940 */   978,  978,  975,  884,  106,  106,  268,  886,  268,  944,
       135916  + /*   950 */     2,  892,  268,  892,  336,  716,   53,   53,  107,  107,
       135917  + /*   960 */   325,   99,  100,   90,  853,  856,  845,  845,   97,   97,
       135918  + /*   970 */    98,   98,   98,   98,  450,   96,   96,   96,   96,   95,
       135919  + /*   980 */    95,   94,   94,   94,   93,  351,  450,  746,  450,  742,
       135920  + /*   990 */   978,  978,  715,  267,  108,  108,  446,  331,  332,  133,
       135921  + /*  1000 */   223,  175,  301,  225,  386,  933,  104,  104,  121,  121,
       135922  + /*  1010 */   325,   99,   88,   90,  853,  856,  845,  845,   97,   97,
       135923  + /*  1020 */    98,   98,   98,   98,  817,   96,   96,   96,   96,   95,
       135924  + /*  1030 */    95,   94,   94,   94,   93,  351,  450,  347,  450,  167,
       135925  + /*  1040 */   978,  978,  932,  815,  372,  319,  202,  202,  374,  263,
       135926  + /*  1050 */   395,  202,   74,  208,  726,  727,  119,  119,  112,  112,
       135927  + /*  1060 */   325,  407,  100,   90,  853,  856,  845,  845,   97,   97,
       135928  + /*  1070 */    98,   98,   98,   98,  450,   96,   96,   96,   96,   95,
       135929  + /*  1080 */    95,   94,   94,   94,   93,  351,  450,  757,  450,  345,
       135930  + /*  1090 */   978,  978,  756,  278,  111,  111,   74,  719,  718,  709,
       135931  + /*  1100 */   286,  883,  754, 1289,  257,   77,  109,  109,  110,  110,
       135932  + /*  1110 */   908,  285,  810,   90,  853,  856,  845,  845,   97,   97,
       135933  + /*  1120 */    98,   98,   98,   98,  911,   96,   96,   96,   96,   95,
       135934  + /*  1130 */    95,   94,   94,   94,   93,  351,   86,  445,  450,    3,
       135935  + /*  1140 */  1202,  450,  745,  132,  352,  120,  689,   86,  445,  785,
       135936  + /*  1150 */     3,  767,  202,  377,  448,  352,  907,  120,   55,   55,
       135937  + /*  1160 */   450,   57,   57,  828,  879,  448,  450,  208,  450,  709,
       135938  + /*  1170 */   450,  883,  237,  434,  436,  120,  440,  429,  362,  120,
       135939  + /*  1180 */    54,   54,  132,  450,  434,  832,   52,   52,   26,   26,
       135940  + /*  1190 */    30,   30,  382,  132,  409,  444,  832,  694,  264,  390,
       135941  + /*  1200 */   116,  269,  272,   32,   32,   83,   84,  120,  274,  120,
       135942  + /*  1210 */   120,  276,   85,  352,  452,  451,   83,   84,  819,  730,
       135943  + /*  1220 */   714,  428,  430,   85,  352,  452,  451,  120,  120,  819,
       135944  + /*  1230 */   378,  218,  281,  828,  783,  816,   86,  445,  410,    3,
       135945  + /*  1240 */   763,  774,  431,  432,  352,  302,  303,  823,  697,  824,
       135946  + /*  1250 */   824,  826,  827,   19,  448,  691,  680,  679,  681,  951,
       135947  + /*  1260 */   824,  824,  826,  827,   19,  289,  159,  291,  293,    7,
       135948  + /*  1270 */   316,  173,  259,  434,  805,  364,  252,  910,  376,  713,
       135949  + /*  1280 */   295,  435,  168,  993,  400,  832,  284,  881,  880,  205,
       135950  + /*  1290 */   954,  308,  927,   86,  445,  990,    3,  925,  333,  144,
       135951  + /*  1300 */   130,  352,   72,  135,   59,   83,   84,  761,  137,  366,
       135952  + /*  1310 */   802,  448,   85,  352,  452,  451,  139,  226,  819,  140,
       135953  + /*  1320 */   156,   62,  315,  314,  313,  215,  311,  367,  393,  683,
       135954  + /*  1330 */   434,  185,  141,  912,  142,  160,  148,  812,  875,  383,
       135955  + /*  1340 */   189,   67,  832,  180,  389,  248,  895,  775,  219,  824,
       135956  + /*  1350 */   824,  826,  827,   19,  247,  190,  266,  154,  391,  271,
       135957  + /*  1360 */   191,  192,   83,   84,  682,  406,  733,  182,  322,   85,
       135958  + /*  1370 */   352,  452,  451,  732,  183,  819,  342,  132,  181,  711,
       135959  + /*  1380 */   731,  421,   76,  445,  705,    3,  323,  704,  283,  724,
       135960  + /*  1390 */   352,  771,  703,  966,  723,   71,  204,    6,  288,  290,
       135961  + /*  1400 */   448,  772,  770,  769,   79,  292,  824,  824,  826,  827,
       135962  + /*  1410 */    19,  294,  297,  438,  346,  442,  102,  861,  753,  434,
       135963  + /*  1420 */   238,  426,   73,  305,  239,  304,  326,  240,  424,  306,
       135964  + /*  1430 */   307,  832,  213,  688,   22,  952,  453,  214,  216,  217,
       135965  + /*  1440 */   454,  677,  115,  676,  671,  125,  126,  235,  127,  669,
       135966  + /*  1450 */   327,   83,   84,  359,  353,  244,  166,  328,   85,  352,
       135967  + /*  1460 */   452,  451,  134,  179,  819,  357,  113,  891,  811,  889,
       135968  + /*  1470 */   136,  128,  138,  743,  258,  184,  906,  143,  145,   63,
       135969  + /*  1480 */    64,   65,   66,  129,  909,  905,  187,  186,    8,   13,
       135970  + /*  1490 */   188,  265,  898,  149,  202,  824,  824,  826,  827,   19,
       135971  + /*  1500 */   388,  987,  150,  161,  285,  685,  392,  396,  151,  722,
       135972  + /*  1510 */   193,   68,   14,  401,  279,   15,   69,  236,  831,  830,
       135973  + /*  1520 */   131,  859,  751,   70,   16,  414,  755,    4,  784,  220,
       135974  + /*  1530 */   222,  174,  152,  437,  779,  201,   17,   77,   74,   18,
       135975  + /*  1540 */   874,  860,  858,  915,  863,  914,  207,  206,  941,  163,
       135976  + /*  1550 */   210,  942,  209,  164,  441,  862,  165,  211,  829,  695,
       135977  + /*  1560 */    87,  312,  309,  947, 1291, 1290,
135386 135978   };
135387 135979   static const YYCODETYPE yy_lookahead[] = {
135388         - /*     0 */    19,   95,   53,   97,   22,   24,   24,  101,   27,   28,
135389         - /*    10 */    29,   30,   31,   32,   33,   34,   35,   36,   37,   38,
135390         - /*    20 */    39,   40,   41,  152,   43,   44,   45,   46,   47,   48,
135391         - /*    30 */    49,   50,   51,   52,   53,   19,   55,   55,  132,  133,
135392         - /*    40 */   134,    1,    2,   27,   28,   29,   30,   31,   32,   33,
135393         - /*    50 */    34,   35,   36,   37,   38,   39,   40,   41,  187,   43,
135394         - /*    60 */    44,   45,   46,   47,   48,   49,   50,   51,   52,   53,
135395         - /*    70 */    47,   48,   49,   50,   51,   52,   53,   61,   97,   97,
135396         - /*    80 */    19,   49,   50,   51,   52,   53,   70,   26,   27,   28,
135397         - /*    90 */    29,   30,   31,   32,   33,   34,   35,   36,   37,   38,
135398         - /*   100 */    39,   40,   41,  152,   43,   44,   45,   46,   47,   48,
135399         - /*   110 */    49,   50,   51,   52,   53,  144,  145,  146,  147,   19,
135400         - /*   120 */    16,   22,   92,  172,  173,   52,   53,   27,   28,   29,
135401         - /*   130 */    30,   31,   32,   33,   34,   35,   36,   37,   38,   39,
135402         - /*   140 */    40,   41,   81,   43,   44,   45,   46,   47,   48,   49,
135403         - /*   150 */    50,   51,   52,   53,   55,   56,   19,  152,  207,  208,
135404         - /*   160 */   115,   24,  117,  118,   27,   28,   29,   30,   31,   32,
135405         - /*   170 */    33,   34,   35,   36,   37,   38,   39,   40,   41,   79,
135406         - /*   180 */    43,   44,   45,   46,   47,   48,   49,   50,   51,   52,
135407         - /*   190 */    53,   19,   88,  157,   90,   23,   97,   98,  193,   27,
135408         - /*   200 */    28,   29,   30,   31,   32,   33,   34,   35,   36,   37,
135409         - /*   210 */    38,   39,   40,   41,  152,   43,   44,   45,   46,   47,
135410         - /*   220 */    48,   49,   50,   51,   52,   53,   19,   22,   23,  172,
135411         - /*   230 */    23,   26,  119,  120,   27,   28,   29,   30,   31,   32,
135412         - /*   240 */    33,   34,   35,   36,   37,   38,   39,   40,   41,  187,
135413         - /*   250 */    43,   44,   45,   46,   47,   48,   49,   50,   51,   52,
135414         - /*   260 */    53,   19,   22,   23,  228,   23,   26,  231,  152,   27,
135415         - /*   270 */    28,   29,   30,   31,   32,   33,   34,   35,   36,   37,
135416         - /*   280 */    38,   39,   40,   41,  172,   43,   44,   45,   46,   47,
135417         - /*   290 */    48,   49,   50,   51,   52,   53,   19,  221,  222,  223,
135418         - /*   300 */    23,   96,  152,  172,   27,   28,   29,   30,   31,   32,
135419         - /*   310 */    33,   34,   35,   36,   37,   38,   39,   40,   41,  152,
135420         - /*   320 */    43,   44,   45,   46,   47,   48,   49,   50,   51,   52,
135421         - /*   330 */    53,   19,    0,    1,    2,   23,   96,  190,  191,   27,
135422         - /*   340 */    28,   29,   30,   31,   32,   33,   34,   35,   36,   37,
135423         - /*   350 */    38,   39,   40,   41,  238,   43,   44,   45,   46,   47,
135424         - /*   360 */    48,   49,   50,   51,   52,   53,   19,  185,  218,  221,
135425         - /*   370 */   222,  223,  152,  152,   27,   28,   29,   30,   31,   32,
135426         - /*   380 */    33,   34,   35,   36,   37,   38,   39,   40,   41,  241,
135427         - /*   390 */    43,   44,   45,   46,   47,   48,   49,   50,   51,   52,
135428         - /*   400 */    53,   19,  152,  168,  169,  170,   22,  190,  191,   27,
135429         - /*   410 */    28,   29,   30,   31,   32,   33,   34,   35,   36,   37,
135430         - /*   420 */    38,   39,   40,   41,  152,   43,   44,   45,   46,   47,
135431         - /*   430 */    48,   49,   50,   51,   52,   53,   19,   19,  218,   55,
135432         - /*   440 */    56,   24,   22,  152,   27,   28,   29,   30,   31,   32,
135433         - /*   450 */    33,   34,   35,   36,   37,   38,   39,   40,   41,  152,
135434         - /*   460 */    43,   44,   45,   46,   47,   48,   49,   50,   51,   52,
135435         - /*   470 */    53,  250,  194,  195,   56,   55,   56,   55,   19,  172,
135436         - /*   480 */   173,   97,   98,  152,  206,  138,   27,   28,   29,   30,
135437         - /*   490 */    31,   32,   33,   34,   35,   36,   37,   38,   39,   40,
135438         - /*   500 */    41,  152,   43,   44,   45,   46,   47,   48,   49,   50,
135439         - /*   510 */    51,   52,   53,   19,  207,  208,  152,   97,   98,   97,
135440         - /*   520 */   138,   27,   28,   29,   30,   31,   32,   33,   34,   35,
135441         - /*   530 */    36,   37,   38,   39,   40,   41,  181,   43,   44,   45,
135442         - /*   540 */    46,   47,   48,   49,   50,   51,   52,   53,   19,   30,
135443         - /*   550 */    31,   32,   33,  247,  248,   19,  152,   28,   29,   30,
135444         - /*   560 */    31,   32,   33,   34,   35,   36,   37,   38,   39,   40,
135445         - /*   570 */    41,  152,   43,   44,   45,   46,   47,   48,   49,   50,
135446         - /*   580 */    51,   52,   53,   19,  168,  169,  170,  238,   19,   53,
135447         - /*   590 */   152,  172,  173,   29,   30,   31,   32,   33,   34,   35,
135448         - /*   600 */    36,   37,   38,   39,   40,   41,  152,   43,   44,   45,
135449         - /*   610 */    46,   47,   48,   49,   50,   51,   52,   53,   19,   20,
135450         - /*   620 */   101,   22,   23,  169,  170,   56,  207,   85,   55,   56,
135451         - /*   630 */    23,   19,   20,   26,   22,   99,  100,  101,  102,  103,
135452         - /*   640 */   104,  105,  238,  152,  152,  210,   47,   48,  112,  152,
135453         - /*   650 */   108,  109,  110,   54,   55,   56,  221,  222,  223,   47,
135454         - /*   660 */    48,  119,  120,  172,  173,   66,   54,   55,   56,  152,
135455         - /*   670 */    97,   98,   99,  148,  149,  102,  103,  104,   66,  154,
135456         - /*   680 */    23,  156,   83,   26,  230,  152,  113,  152,  163,  194,
135457         - /*   690 */   195,   92,   92,   30,   95,   83,   97,   98,  207,  208,
135458         - /*   700 */   101,  206,  179,  180,   92,  172,  173,   95,  152,   97,
135459         - /*   710 */    98,  188,   99,  101,  219,  102,  103,  104,  152,  119,
135460         - /*   720 */   120,  196,   55,   56,   19,   20,  113,   22,  193,  163,
135461         - /*   730 */    11,  132,  133,  134,  135,  136,   24,   65,  172,  173,
135462         - /*   740 */   207,  208,  250,  152,  132,  133,  134,  135,  136,  193,
135463         - /*   750 */    78,   84,   47,   48,   49,   98,  199,  152,   86,   54,
135464         - /*   760 */    55,   56,  196,  152,   97,   98,  209,   55,  163,  244,
135465         - /*   770 */   107,   66,  152,  207,  208,  164,  175,  172,  173,   19,
135466         - /*   780 */    20,  124,   22,  111,   38,   39,   40,   41,   83,   43,
135467         - /*   790 */    44,   45,   46,   47,   48,   49,   50,   51,   52,   53,
135468         - /*   800 */    95,  196,   97,   98,   85,  152,  101,   47,   48,   97,
135469         - /*   810 */    85,   92,  207,  193,   54,   55,   56,   92,   49,  175,
135470         - /*   820 */    55,   56,  221,  222,  223,   12,   66,  108,  109,  110,
135471         - /*   830 */   137,  163,  139,  108,  109,  110,   26,  132,  133,  134,
135472         - /*   840 */   135,  136,  152,   83,   43,   44,   45,   46,   47,   48,
135473         - /*   850 */    49,   50,   51,   52,   53,   95,   26,   97,   98,   55,
135474         - /*   860 */    56,  101,   97,   98,  196,  221,  222,  223,  146,  147,
135475         - /*   870 */    57,  171,  152,   22,   26,   19,   20,   49,   22,  179,
135476         - /*   880 */   108,  109,  110,   55,   56,  116,   73,  219,   75,  124,
135477         - /*   890 */   121,  152,  132,  133,  134,  135,  136,  163,   85,  152,
135478         - /*   900 */   232,   97,   98,   47,   48,  237,   55,   56,   98,    5,
135479         - /*   910 */    54,   55,   56,  193,   10,   11,   12,   13,   14,  172,
135480         - /*   920 */   173,   17,   66,   47,   48,   97,   98,  152,  124,  152,
135481         - /*   930 */   196,   55,   56,  186,  124,  152,  106,  160,  152,   83,
135482         - /*   940 */   152,  164,  152,   61,   22,  211,  212,  152,   97,   98,
135483         - /*   950 */   152,   95,   70,   97,   98,  172,  173,  101,  172,  173,
135484         - /*   960 */   172,  173,  172,  173,   60,  181,   62,  172,  173,   47,
135485         - /*   970 */    48,  123,  186,   97,   98,   71,  100,   55,   56,  152,
135486         - /*   980 */   181,  186,   21,  107,  152,  109,   82,  163,  132,  133,
135487         - /*   990 */   134,  135,  136,   89,   16,  207,   92,   93,   19,  172,
135488         - /*  1000 */   173,  169,  170,  195,   55,   56,   12,  152,  132,   30,
135489         - /*  1010 */   134,   47,   48,  186,  206,  225,  152,   95,  114,   97,
135490         - /*  1020 */   196,  245,  246,  101,  152,   38,   39,   40,   41,   42,
135491         - /*  1030 */    43,   44,   45,   46,   47,   48,   49,   50,   51,   52,
135492         - /*  1040 */    53,  152,  163,  219,  152,  141,   97,   98,  193,  152,
135493         - /*  1050 */   152,   57,   91,  164,  132,  133,  134,  152,   55,  152,
135494         - /*  1060 */   152,  237,  230,  152,  103,  193,   88,   73,   90,   75,
135495         - /*  1070 */   172,  173,  183,  152,  185,  196,  152,  172,  173,  172,
135496         - /*  1080 */   173,  217,  152,  172,  173,  152,  107,   22,  152,   24,
135497         - /*  1090 */   193,  112,  152,  172,  173,  152,  132,  242,  134,  152,
135498         - /*  1100 */    97,  140,  152,   92,  152,  172,  173,  152,  172,  173,
135499         - /*  1110 */   152,  100,  172,  173,  152,  172,  173,  152,  140,  172,
135500         - /*  1120 */   173,  152,  172,  173,  172,  173,  152,  172,  173,  152,
135501         - /*  1130 */   172,  173,  152,  152,  172,  173,  152,  172,  173,  213,
135502         - /*  1140 */   152,  172,  173,  152,  152,  152,  172,  173,  152,  172,
135503         - /*  1150 */   173,  152,  172,  173,  152,  210,  172,  173,  152,   26,
135504         - /*  1160 */   172,  173,  152,  172,  173,  172,  173,  152,  172,  173,
135505         - /*  1170 */   152,  172,  173,  152,  172,  173,  152,   59,  172,  173,
135506         - /*  1180 */   152,   63,  172,  173,  152,  193,  152,  152,  152,  152,
135507         - /*  1190 */   172,  173,  152,  172,  173,   77,  172,  173,  152,  152,
135508         - /*  1200 */   172,  173,  152,  152,  172,  173,  172,  173,  172,  173,
135509         - /*  1210 */   152,   22,  172,  173,  152,  152,  152,   22,  172,  173,
135510         - /*  1220 */   152,  152,  152,  172,  173,  152,    7,    8,    9,  163,
135511         - /*  1230 */   172,  173,   22,   23,  172,  173,  172,  173,  166,  167,
135512         - /*  1240 */   172,  173,  172,  173,   55,  172,  173,   22,   23,  108,
135513         - /*  1250 */   109,  110,  217,  152,  217,  166,  167,  163,  163,  163,
135514         - /*  1260 */   163,  163,  196,  130,  217,  211,  212,  217,  116,   23,
135515         - /*  1270 */    22,  101,   26,  121,   23,   23,   23,   26,   26,   26,
135516         - /*  1280 */    23,   23,  112,   26,   26,   37,   97,  100,  101,   55,
135517         - /*  1290 */   196,  196,  196,  196,  196,   23,   23,   55,   26,   26,
135518         - /*  1300 */     7,    8,   23,  152,   23,   26,   96,   26,  132,  132,
135519         - /*  1310 */   134,  134,   23,  152,  152,   26,  152,  122,  152,  191,
135520         - /*  1320 */   152,   96,  234,  152,  152,  152,  152,  152,  197,  210,
135521         - /*  1330 */   152,   97,  152,  152,  210,  233,  210,  198,  150,   97,
135522         - /*  1340 */   184,  201,  239,  214,  214,  201,  239,  180,  214,  227,
135523         - /*  1350 */   200,  198,  155,   67,  243,  176,   69,  175,  175,  175,
135524         - /*  1360 */   122,  159,  159,  240,  159,  240,   22,  220,   27,  130,
135525         - /*  1370 */   201,   18,  159,   18,  189,  158,  158,  220,  192,  159,
135526         - /*  1380 */   137,  236,  192,  192,  192,  189,   74,  189,  159,  235,
135527         - /*  1390 */   159,  158,   22,  177,  201,  201,  159,  107,  158,  177,
135528         - /*  1400 */   159,  174,  158,   76,  174,  182,  174,  106,  182,  125,
135529         - /*  1410 */   174,  107,  177,   22,  159,  216,  215,  137,  159,   53,
135530         - /*  1420 */   216,  176,  215,  174,  174,  216,  215,  215,  174,  229,
135531         - /*  1430 */   216,  129,  224,  177,  126,  229,  127,  177,  128,   25,
135532         - /*  1440 */   162,  226,   26,  161,   13,  153,    6,  153,  151,  151,
135533         - /*  1450 */   151,  151,  205,  165,  178,  178,  165,    4,    3,   22,
135534         - /*  1460 */   165,  142,   15,   94,  202,  204,  203,  201,   16,   23,
135535         - /*  1470 */   249,   23,  120,  249,  246,  111,  131,  123,   20,   16,
135536         - /*  1480 */     1,  125,  123,  111,   56,   64,   37,   37,  131,  122,
135537         - /*  1490 */     1,   37,    5,   37,   22,  107,   26,   80,  140,   80,
135538         - /*  1500 */    87,   72,  107,   20,   24,   19,  112,  105,   23,   79,
135539         - /*  1510 */    22,   79,   22,   22,   22,   58,   22,   79,   23,   68,
135540         - /*  1520 */    23,   23,   26,  116,   22,   26,   23,   22,  122,   23,
135541         - /*  1530 */    23,   56,   64,   22,  124,   26,   26,   64,   64,   23,
135542         - /*  1540 */    23,   23,   23,   11,   23,   22,   26,   23,   22,   24,
135543         - /*  1550 */     1,   23,   22,   26,  251,   24,   23,   22,  122,   23,
135544         - /*  1560 */    23,   22,   15,  122,  122,  122,   23,
135545         -};
135546         -#define YY_SHIFT_USE_DFLT (1567)
       135980  + /*     0 */    19,  115,   19,  117,  118,   24,    1,    2,   27,   79,
       135981  + /*    10 */    80,   81,   82,   83,   84,   85,   86,   87,   88,   89,
       135982  + /*    20 */    90,   91,   92,   93,   94,  144,  145,  146,  147,   58,
       135983  + /*    30 */    49,   50,   79,   80,   81,   82,   22,   84,   85,   86,
       135984  + /*    40 */    87,   88,   89,   90,   91,   92,   93,   94,  221,  222,
       135985  + /*    50 */   223,   70,   71,   72,   73,   74,   75,   76,   77,   78,
       135986  + /*    60 */    79,   80,   81,   82,   94,   84,   85,   86,   87,   88,
       135987  + /*    70 */    89,   90,   91,   92,   93,   94,   19,   94,   97,  108,
       135988  + /*    80 */   109,  110,   99,  100,  101,  102,  103,  104,  105,   32,
       135989  + /*    90 */   119,  120,   78,   27,  152,  112,   93,   94,   41,   88,
       135990  + /*   100 */    89,   90,   91,   92,   93,   94,   49,   50,   84,   85,
       135991  + /*   110 */    86,   87,   88,   89,   90,   91,   92,   93,   94,   58,
       135992  + /*   120 */   157,  119,  120,  163,   68,  163,   65,   70,   71,   72,
       135993  + /*   130 */    73,   74,   75,   76,   77,   78,   79,   80,   81,   82,
       135994  + /*   140 */   152,   84,   85,   86,   87,   88,   89,   90,   91,   92,
       135995  + /*   150 */    93,   94,   19,   97,   88,   89,  196,  101,  196,   26,
       135996  + /*   160 */   172,  173,   96,   97,   98,  210,  100,   22,  152,  108,
       135997  + /*   170 */   109,  110,   27,  107,   27,  109,  221,  222,  223,  219,
       135998  + /*   180 */   238,  219,   49,   50,  152,  169,  170,   54,  132,  133,
       135999  + /*   190 */   134,  228,  232,  171,  231,  207,  208,  237,  132,  237,
       136000  + /*   200 */   134,  179,   19,   70,   71,   72,   73,   74,   75,   76,
       136001  + /*   210 */    77,   78,   79,   80,   81,   82,  152,   84,   85,   86,
       136002  + /*   220 */    87,   88,   89,   90,   91,   92,   93,   94,   27,   65,
       136003  + /*   230 */    30,  152,   49,   50,   34,   52,   90,   91,   92,   93,
       136004  + /*   240 */    94,   96,   97,   98,   97,   22,  230,   27,   48,  217,
       136005  + /*   250 */    27,  172,  173,   70,   71,   72,   73,   74,   75,   76,
       136006  + /*   260 */    77,   78,   79,   80,   81,   82,  172,   84,   85,   86,
       136007  + /*   270 */    87,   88,   89,   90,   91,   92,   93,   94,   19,  148,
       136008  + /*   280 */   149,  152,  218,   24,  152,  154,  207,  156,  172,  152,
       136009  + /*   290 */    22,   68,   27,  152,  163,   27,  164,   96,   97,   98,
       136010  + /*   300 */    99,  172,  173,  102,  103,  104,  169,  170,   49,   50,
       136011  + /*   310 */    90,   88,   89,  152,  113,  186,   96,   97,   98,   96,
       136012  + /*   320 */    97,  160,   57,   27,  101,  164,  137,  196,  139,   70,
       136013  + /*   330 */    71,   72,   73,   74,   75,   76,   77,   78,   79,   80,
       136014  + /*   340 */    81,   82,   11,   84,   85,   86,   87,   88,   89,   90,
       136015  + /*   350 */    91,   92,   93,   94,   19,  132,  133,  134,   23,  218,
       136016  + /*   360 */   152,   96,   97,   98,   96,   97,   98,  230,   99,   22,
       136017  + /*   370 */   152,  102,  103,  104,   27,  244,  152,  152,   27,   26,
       136018  + /*   380 */   152,   22,  113,   65,   49,   50,   27,  194,  195,   58,
       136019  + /*   390 */   172,  173,   96,   97,   98,  185,   65,  172,  173,  206,
       136020  + /*   400 */   172,  173,  190,  191,  186,   70,   71,   72,   73,   74,
       136021  + /*   410 */    75,   76,   77,   78,   79,   80,   81,   82,  175,   84,
       136022  + /*   420 */    85,   86,   87,   88,   89,   90,   91,   92,   93,   94,
       136023  + /*   430 */    19,  175,  207,  208,   23,  207,  208,  119,  120,  108,
       136024  + /*   440 */   109,  110,   27,   96,   97,   98,  116,   96,   97,   98,
       136025  + /*   450 */   152,  121,  152,  179,  180,   96,   97,   98,  250,  106,
       136026  + /*   460 */    49,   50,  188,   19,  221,  222,  223,  168,  169,  170,
       136027  + /*   470 */   172,  173,  172,  173,  250,  124,  172,  221,  222,  223,
       136028  + /*   480 */    26,   70,   71,   72,   73,   74,   75,   76,   77,   78,
       136029  + /*   490 */    79,   80,   81,   82,   50,   84,   85,   86,   87,   88,
       136030  + /*   500 */    89,   90,   91,   92,   93,   94,   19,  207,  208,   12,
       136031  + /*   510 */    23,   96,   97,   98,  221,  222,  223,  194,  195,  152,
       136032  + /*   520 */   199,   23,   19,  225,   26,   28,  152,  152,  152,  206,
       136033  + /*   530 */   209,  164,  190,  191,  241,  152,   49,   50,  152,  124,
       136034  + /*   540 */   152,   44,  219,   46,  152,   21,  172,  173,  172,  173,
       136035  + /*   550 */   183,  107,  185,   16,  163,   58,  112,   70,   71,   72,
       136036  + /*   560 */    73,   74,   75,   76,   77,   78,   79,   80,   81,   82,
       136037  + /*   570 */   152,   84,   85,   86,   87,   88,   89,   90,   91,   92,
       136038  + /*   580 */    93,   94,   19,  207,  130,  152,   23,  196,   64,  152,
       136039  + /*   590 */   172,  173,   22,  152,   24,  152,   98,   27,   61,   96,
       136040  + /*   600 */    63,   26,  211,  212,  186,  172,  173,   49,   50,  172,
       136041  + /*   610 */   173,   23,   49,   50,   26,  172,  173,   88,   89,  186,
       136042  + /*   620 */    24,  238,  124,   27,  238,   22,   23,  103,  187,   26,
       136043  + /*   630 */   152,   73,   74,   70,   71,   72,   73,   74,   75,   76,
       136044  + /*   640 */    77,   78,   79,   80,   81,   82,  152,   84,   85,   86,
       136045  + /*   650 */    87,   88,   89,   90,   91,   92,   93,   94,   19,  101,
       136046  + /*   660 */   152,  132,   23,  134,  140,  152,   12,   97,   36,  168,
       136047  + /*   670 */   169,  170,   69,   98,  152,   22,   23,  140,   50,   26,
       136048  + /*   680 */   172,  173,   28,   51,  152,  172,  173,  193,   49,   50,
       136049  + /*   690 */    22,   59,   24,   97,  172,  173,  152,  152,   44,  124,
       136050  + /*   700 */    46,    0,    1,    2,  172,  173,   22,   23,   19,   70,
       136051  + /*   710 */    71,   72,   73,   74,   75,   76,   77,   78,   79,   80,
       136052  + /*   720 */    81,   82,   69,   84,   85,   86,   87,   88,   89,   90,
       136053  + /*   730 */    91,   92,   93,   94,  152,  107,  152,  193,   49,   50,
       136054  + /*   740 */   181,   22,   23,  111,  108,  109,  110,    7,    8,    9,
       136055  + /*   750 */    16,  247,  248,   69,  172,  173,  172,  173,  152,   70,
       136056  + /*   760 */    71,   72,   73,   74,   75,   76,   77,   78,   79,   80,
       136057  + /*   770 */    81,   82,  152,   84,   85,   86,   87,   88,   89,   90,
       136058  + /*   780 */    91,   92,   93,   94,   19,  152,  242,  152,   69,  152,
       136059  + /*   790 */   166,  167,  172,  173,   32,   61,  152,   63,  152,  193,
       136060  + /*   800 */   152,  152,  152,   41,  152,  172,  173,  172,  173,  172,
       136061  + /*   810 */   173,  152,  152,  152,   49,   50,  172,  173,  172,  173,
       136062  + /*   820 */   172,  173,  172,  173,  172,  173,  132,  138,  134,  152,
       136063  + /*   830 */   152,  172,  173,  172,  173,   70,   71,   72,   73,   74,
       136064  + /*   840 */    75,   76,   77,   78,   79,   80,   81,   82,  152,   84,
       136065  + /*   850 */    85,   86,   87,   88,   89,   90,   91,   92,   93,   94,
       136066  + /*   860 */    19,  152,   22,  152,  195,   24,  152,   27,  172,  173,
       136067  + /*   870 */   193,  193,  152,  152,  152,  206,  152,  217,  152,  152,
       136068  + /*   880 */   152,  172,  173,  172,  173,  152,  172,  173,  152,  152,
       136069  + /*   890 */    49,   50,  172,  173,  172,  173,  172,  173,  172,  173,
       136070  + /*   900 */   172,  173,  152,  138,  152,  172,  173,  108,  109,  110,
       136071  + /*   910 */    19,   70,   71,   72,   73,   74,   75,   76,   77,   78,
       136072  + /*   920 */    79,   80,   81,   82,  152,   84,   85,   86,   87,   88,
       136073  + /*   930 */    89,   90,   91,   92,   93,   94,  152,   97,  152,  152,
       136074  + /*   940 */    49,   50,   26,  193,  172,  173,  152,  152,  152,  146,
       136075  + /*   950 */   147,  132,  152,  134,  217,  181,  172,  173,  172,  173,
       136076  + /*   960 */    19,   70,   71,   72,   73,   74,   75,   76,   77,   78,
       136077  + /*   970 */    79,   80,   81,   82,  152,   84,   85,   86,   87,   88,
       136078  + /*   980 */    89,   90,   91,   92,   93,   94,  152,  193,  152,  193,
       136079  + /*   990 */    49,   50,  181,  193,  172,  173,  166,  167,  245,  246,
       136080  + /*  1000 */   211,  212,  152,   22,  217,  152,  172,  173,  172,  173,
       136081  + /*  1010 */    19,   70,   71,   72,   73,   74,   75,   76,   77,   78,
       136082  + /*  1020 */    79,   80,   81,   82,  152,   84,   85,   86,   87,   88,
       136083  + /*  1030 */    89,   90,   91,   92,   93,   94,  152,  187,  152,  123,
       136084  + /*  1040 */    49,   50,   23,   23,   23,   26,   26,   26,   23,   23,
       136085  + /*  1050 */    23,   26,   26,   26,    7,    8,  172,  173,  172,  173,
       136086  + /*  1060 */    19,   90,   71,   72,   73,   74,   75,   76,   77,   78,
       136087  + /*  1070 */    79,   80,   81,   82,  152,   84,   85,   86,   87,   88,
       136088  + /*  1080 */    89,   90,   91,   92,   93,   94,  152,  116,  152,  217,
       136089  + /*  1090 */    49,   50,  121,   23,  172,  173,   26,  100,  101,   27,
       136090  + /*  1100 */   101,   27,   23,  122,  152,   26,  172,  173,  172,  173,
       136091  + /*  1110 */   152,  112,  163,   72,   73,   74,   75,   76,   77,   78,
       136092  + /*  1120 */    79,   80,   81,   82,  163,   84,   85,   86,   87,   88,
       136093  + /*  1130 */    89,   90,   91,   92,   93,   94,   19,   20,  152,   22,
       136094  + /*  1140 */    23,  152,  163,   65,   27,  196,  163,   19,   20,   23,
       136095  + /*  1150 */    22,  213,   26,   19,   37,   27,  152,  196,  172,  173,
       136096  + /*  1160 */   152,  172,  173,   27,   23,   37,  152,   26,  152,   97,
       136097  + /*  1170 */   152,   97,  210,   56,  163,  196,  163,  163,  100,  196,
       136098  + /*  1180 */   172,  173,   65,  152,   56,   68,  172,  173,  172,  173,
       136099  + /*  1190 */   172,  173,  152,   65,  163,  163,   68,   23,  152,  234,
       136100  + /*  1200 */    26,  152,  152,  172,  173,   88,   89,  196,  152,  196,
       136101  + /*  1210 */   196,  152,   95,   96,   97,   98,   88,   89,  101,  152,
       136102  + /*  1220 */   152,  207,  208,   95,   96,   97,   98,  196,  196,  101,
       136103  + /*  1230 */    96,  233,  152,   97,  152,  152,   19,   20,  207,   22,
       136104  + /*  1240 */   152,  152,  152,  191,   27,  152,  152,  152,  152,  132,
       136105  + /*  1250 */   133,  134,  135,  136,   37,  152,  152,  152,  152,  152,
       136106  + /*  1260 */   132,  133,  134,  135,  136,  210,  197,  210,  210,  198,
       136107  + /*  1270 */   150,  184,  239,   56,  201,  214,  214,  201,  239,  180,
       136108  + /*  1280 */   214,  227,  198,   38,  176,   68,  175,  175,  175,  122,
       136109  + /*  1290 */   155,  200,  159,   19,   20,   40,   22,  159,  159,   22,
       136110  + /*  1300 */    70,   27,  130,  243,  240,   88,   89,   90,  189,   18,
       136111  + /*  1310 */   201,   37,   95,   96,   97,   98,  192,    5,  101,  192,
       136112  + /*  1320 */   220,  240,   10,   11,   12,   13,   14,  159,   18,   17,
       136113  + /*  1330 */    56,  158,  192,  201,  192,  220,  189,  189,  201,  159,
       136114  + /*  1340 */   158,  137,   68,   31,   45,   33,  236,  159,  159,  132,
       136115  + /*  1350 */   133,  134,  135,  136,   42,  158,  235,   22,  177,  159,
       136116  + /*  1360 */   158,  158,   88,   89,  159,  107,  174,   55,  177,   95,
       136117  + /*  1370 */    96,   97,   98,  174,   62,  101,   47,   65,   66,  106,
       136118  + /*  1380 */   174,  125,   19,   20,  174,   22,  177,  176,  174,  182,
       136119  + /*  1390 */    27,  216,  174,  174,  182,  107,  159,   22,  215,  215,
       136120  + /*  1400 */    37,  216,  216,  216,  137,  215,  132,  133,  134,  135,
       136121  + /*  1410 */   136,  215,  159,  177,   94,  177,  129,  224,  205,   56,
       136122  + /*  1420 */   226,  126,  128,  203,  229,  204,  114,  229,  127,  202,
       136123  + /*  1430 */   201,   68,   25,  162,   26,   13,  161,  153,  153,    6,
       136124  + /*  1440 */   151,  151,  178,  151,  151,  165,  165,  178,  165,    4,
       136125  + /*  1450 */   249,   88,   89,  141,    3,  142,   22,  249,   95,   96,
       136126  + /*  1460 */    97,   98,  246,   15,  101,   67,   16,   23,  120,   23,
       136127  + /*  1470 */   131,  111,  123,   20,   16,  125,    1,  123,  131,   78,
       136128  + /*  1480 */    78,   78,   78,  111,   96,    1,  122,   35,    5,   22,
       136129  + /*  1490 */   107,  140,   53,   53,   26,  132,  133,  134,  135,  136,
       136130  + /*  1500 */    43,   60,  107,   24,  112,   20,   19,   52,   22,   29,
       136131  + /*  1510 */   105,   22,   22,   52,   23,   22,   22,   52,   23,   23,
       136132  + /*  1520 */    39,   23,  116,   26,   22,   26,   23,   22,   96,   23,
       136133  + /*  1530 */    23,  122,   22,   24,  124,   35,   35,   26,   26,   35,
       136134  + /*  1540 */    23,   23,   23,   23,   11,   23,   22,   26,   23,   22,
       136135  + /*  1550 */   122,   23,   26,   22,   24,   23,   22,  122,   23,   23,
       136136  + /*  1560 */    22,   15,   23,    1,  122,  122,
       136137  +};
       136138  +#define YY_SHIFT_USE_DFLT (1566)
135547 136139   #define YY_SHIFT_COUNT    (455)
135548         -#define YY_SHIFT_MIN      (-94)
135549         -#define YY_SHIFT_MAX      (1549)
       136140  +#define YY_SHIFT_MIN      (-114)
       136141  +#define YY_SHIFT_MAX      (1562)
135550 136142   static const short yy_shift_ofst[] = {
135551         - /*     0 */    40,  599,  904,  612,  760,  760,  760,  760,  725,  -19,
135552         - /*    10 */    16,   16,  100,  760,  760,  760,  760,  760,  760,  760,
135553         - /*    20 */   876,  876,  573,  542,  719,  600,   61,  137,  172,  207,
135554         - /*    30 */   242,  277,  312,  347,  382,  417,  459,  459,  459,  459,
135555         - /*    40 */   459,  459,  459,  459,  459,  459,  459,  459,  459,  459,
135556         - /*    50 */   459,  459,  459,  494,  459,  529,  564,  564,  705,  760,
135557         - /*    60 */   760,  760,  760,  760,  760,  760,  760,  760,  760,  760,
135558         - /*    70 */   760,  760,  760,  760,  760,  760,  760,  760,  760,  760,
135559         - /*    80 */   760,  760,  760,  760,  760,  760,  760,  760,  760,  760,
135560         - /*    90 */   856,  760,  760,  760,  760,  760,  760,  760,  760,  760,
135561         - /*   100 */   760,  760,  760,  760,  987,  746,  746,  746,  746,  746,
135562         - /*   110 */   801,   23,   32,  949,  961,  979,  964,  964,  949,   73,
135563         - /*   120 */   113,  -51, 1567, 1567, 1567,  536,  536,  536,   99,   99,
135564         - /*   130 */   813,  813,  667,  205,  240,  949,  949,  949,  949,  949,
135565         - /*   140 */   949,  949,  949,  949,  949,  949,  949,  949,  949,  949,
135566         - /*   150 */   949,  949,  949,  949,  949,  332, 1011,  422,  422,  113,
135567         - /*   160 */    30,   30,   30,   30,   30,   30, 1567, 1567, 1567,  922,
135568         - /*   170 */   -94,  -94,  384,  613,  828,  420,  765,  804,  851,  949,
135569         - /*   180 */   949,  949,  949,  949,  949,  949,  949,  949,  949,  949,
135570         - /*   190 */   949,  949,  949,  949,  949,  672,  672,  672,  949,  949,
135571         - /*   200 */   657,  949,  949,  949,  -18,  949,  949,  994,  949,  949,
135572         - /*   210 */   949,  949,  949,  949,  949,  949,  949,  949,  772, 1118,
135573         - /*   220 */   712,  712,  712,  810,   45,  769, 1219, 1133,  418,  418,
135574         - /*   230 */   569, 1133,  569,  830,  607,  663,  882,  418,  693,  882,
135575         - /*   240 */   882,  848, 1152, 1065, 1286, 1238, 1238, 1287, 1287, 1238,
135576         - /*   250 */  1344, 1341, 1239, 1353, 1353, 1353, 1353, 1238, 1355, 1239,
135577         - /*   260 */  1344, 1341, 1341, 1239, 1238, 1355, 1243, 1312, 1238, 1238,
135578         - /*   270 */  1355, 1370, 1238, 1355, 1238, 1355, 1370, 1290, 1290, 1290,
135579         - /*   280 */  1327, 1370, 1290, 1301, 1290, 1327, 1290, 1290, 1284, 1304,
135580         - /*   290 */  1284, 1304, 1284, 1304, 1284, 1304, 1238, 1391, 1238, 1280,
135581         - /*   300 */  1370, 1366, 1366, 1370, 1302, 1308, 1310, 1309, 1239, 1414,
135582         - /*   310 */  1416, 1431, 1431, 1440, 1440, 1440, 1440, 1567, 1567, 1567,
135583         - /*   320 */  1567, 1567, 1567, 1567, 1567,  519,  978, 1210, 1225,  104,
135584         - /*   330 */  1141, 1189, 1246, 1248, 1251, 1252, 1253, 1257, 1258, 1273,
135585         - /*   340 */  1003, 1187, 1293, 1170, 1272, 1279, 1234, 1281, 1176, 1177,
135586         - /*   350 */  1289, 1242, 1195, 1453, 1455, 1437, 1319, 1447, 1369, 1452,
135587         - /*   360 */  1446, 1448, 1352, 1345, 1364, 1354, 1458, 1356, 1463, 1479,
135588         - /*   370 */  1359, 1357, 1449, 1450, 1454, 1456, 1372, 1428, 1421, 1367,
135589         - /*   380 */  1489, 1487, 1472, 1388, 1358, 1417, 1470, 1419, 1413, 1429,
135590         - /*   390 */  1395, 1480, 1483, 1486, 1394, 1402, 1488, 1430, 1490, 1491,
135591         - /*   400 */  1485, 1492, 1432, 1457, 1494, 1438, 1451, 1495, 1497, 1498,
135592         - /*   410 */  1496, 1407, 1502, 1503, 1505, 1499, 1406, 1506, 1507, 1475,
135593         - /*   420 */  1468, 1511, 1410, 1509, 1473, 1510, 1474, 1516, 1509, 1517,
135594         - /*   430 */  1518, 1519, 1520, 1521, 1523, 1532, 1524, 1526, 1525, 1527,
135595         - /*   440 */  1528, 1530, 1531, 1527, 1533, 1535, 1536, 1537, 1539, 1436,
135596         - /*   450 */  1441, 1442, 1443, 1543, 1547, 1549,
135597         -};
135598         -#define YY_REDUCE_USE_DFLT (-130)
       136143  + /*     0 */     5, 1117, 1312, 1128, 1274, 1274, 1274, 1274,   61,  -19,
       136144  + /*    10 */    57,   57,  183, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
       136145  + /*    20 */    66,   66,  201,  -29,  331,  318,  133,  259,  335,  411,
       136146  + /*    30 */   487,  563,  639,  689,  765,  841,  891,  891,  891,  891,
       136147  + /*    40 */   891,  891,  891,  891,  891,  891,  891,  891,  891,  891,
       136148  + /*    50 */   891,  891,  891,  941,  891,  991, 1041, 1041, 1217, 1274,
       136149  + /*    60 */  1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
       136150  + /*    70 */  1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
       136151  + /*    80 */  1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
       136152  + /*    90 */  1363, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
       136153  + /*   100 */  1274, 1274, 1274, 1274,  -70,  -47,  -47,  -47,  -47,  -47,
       136154  + /*   110 */    24,   11,  146,  296,  524,  444,  529,  529,  296,    3,
       136155  + /*   120 */     2,  -30, 1566, 1566, 1566,  -17,  -17,  -17,  145,  145,
       136156  + /*   130 */   497,  497,  265,  603,  653,  296,  296,  296,  296,  296,
       136157  + /*   140 */   296,  296,  296,  296,  296,  296,  296,  296,  296,  296,
       136158  + /*   150 */   296,  296,  296,  296,  296,  701, 1078,  147,  147,    2,
       136159  + /*   160 */   164,  164,  164,  164,  164,  164, 1566, 1566, 1566,  223,
       136160  + /*   170 */    56,   56,  268,  269,  220,  347,  351,  415,  359,  296,
       136161  + /*   180 */   296,  296,  296,  296,  296,  296,  296,  296,  296,  296,
       136162  + /*   190 */   296,  296,  296,  296,  296,  632,  632,  632,  296,  296,
       136163  + /*   200 */   498,  296,  296,  296,  570,  296,  296,  654,  296,  296,
       136164  + /*   210 */   296,  296,  296,  296,  296,  296,  296,  296,  636,  200,
       136165  + /*   220 */   596,  596,  596,  575, -114,  971,  740,  454,  503,  503,
       136166  + /*   230 */  1134,  454, 1134,  353,  588,  628,  762,  503,  189,  762,
       136167  + /*   240 */   762,  916,  330,  668, 1245, 1167, 1167, 1255, 1255, 1167,
       136168  + /*   250 */  1277, 1230, 1172, 1291, 1291, 1291, 1291, 1167, 1310, 1172,
       136169  + /*   260 */  1277, 1230, 1230, 1172, 1167, 1310, 1204, 1299, 1167, 1167,
       136170  + /*   270 */  1310, 1335, 1167, 1310, 1167, 1310, 1335, 1258, 1258, 1258,
       136171  + /*   280 */  1329, 1335, 1258, 1273, 1258, 1329, 1258, 1258, 1256, 1288,
       136172  + /*   290 */  1256, 1288, 1256, 1288, 1256, 1288, 1167, 1375, 1167, 1267,
       136173  + /*   300 */  1335, 1320, 1320, 1335, 1287, 1295, 1294, 1301, 1172, 1407,
       136174  + /*   310 */  1408, 1422, 1422, 1433, 1433, 1433, 1433, 1566, 1566, 1566,
       136175  + /*   320 */  1566, 1566, 1566, 1566, 1566,  558,  537,  684,  719,  734,
       136176  + /*   330 */   799,  840, 1019,   14, 1020, 1021, 1025, 1026, 1027, 1070,
       136177  + /*   340 */  1072,  997, 1047,  999, 1079, 1126, 1074, 1141,  694,  819,
       136178  + /*   350 */  1174, 1136,  981, 1445, 1451, 1434, 1313, 1448, 1398, 1450,
       136179  + /*   360 */  1444, 1446, 1348, 1339, 1360, 1349, 1453, 1350, 1458, 1475,
       136180  + /*   370 */  1354, 1347, 1401, 1402, 1403, 1404, 1372, 1388, 1452, 1364,
       136181  + /*   380 */  1484, 1483, 1467, 1383, 1351, 1439, 1468, 1440, 1441, 1457,
       136182  + /*   390 */  1395, 1479, 1485, 1487, 1392, 1405, 1486, 1455, 1489, 1490,
       136183  + /*   400 */  1491, 1493, 1461, 1480, 1494, 1465, 1481, 1495, 1496, 1498,
       136184  + /*   410 */  1497, 1406, 1502, 1503, 1505, 1499, 1409, 1506, 1507, 1432,
       136185  + /*   420 */  1500, 1510, 1410, 1511, 1501, 1512, 1504, 1517, 1511, 1518,
       136186  + /*   430 */  1519, 1520, 1521, 1522, 1524, 1533, 1525, 1527, 1509, 1526,
       136187  + /*   440 */  1528, 1531, 1530, 1526, 1532, 1534, 1535, 1536, 1538, 1428,
       136188  + /*   450 */  1435, 1442, 1443, 1539, 1546, 1562,
       136189  +};
       136190  +#define YY_REDUCE_USE_DFLT (-174)
135599 136191   #define YY_REDUCE_COUNT (324)
135600         -#define YY_REDUCE_MIN   (-129)
135601         -#define YY_REDUCE_MAX   (1300)
       136192  +#define YY_REDUCE_MIN   (-173)
       136193  +#define YY_REDUCE_MAX   (1293)
135602 136194   static const short yy_reduce_ofst[] = {
135603         - /*     0 */   -29,  566,  525,  605,  -49,  307,  491,  533,  668,  435,
135604         - /*    10 */   601,  644,  148,  747,  786,  795,  419,  788,  827,  790,
135605         - /*    20 */   454,  832,  889,  495,  824,  734,   76,   76,   76,   76,
135606         - /*    30 */    76,   76,   76,   76,   76,   76,   76,   76,   76,   76,
135607         - /*    40 */    76,   76,   76,   76,   76,   76,   76,   76,   76,   76,
135608         - /*    50 */    76,   76,   76,   76,   76,   76,   76,   76,  783,  898,
135609         - /*    60 */   905,  907,  911,  921,  933,  936,  940,  943,  947,  950,
135610         - /*    70 */   952,  955,  958,  962,  965,  969,  974,  977,  980,  984,
135611         - /*    80 */   988,  991,  993,  996,  999, 1002, 1006, 1010, 1018, 1021,
135612         - /*    90 */  1024, 1028, 1032, 1034, 1036, 1040, 1046, 1051, 1058, 1062,
135613         - /*   100 */  1064, 1068, 1070, 1073,   76,   76,   76,   76,   76,   76,
135614         - /*   110 */    76,   76,   76,  855,   36,  523,  235,  416,  777,   76,
135615         - /*   120 */   278,   76,   76,   76,   76,  700,  700,  700,  150,  220,
135616         - /*   130 */   147,  217,  221,  306,  306,  611,    5,  535,  556,  620,
135617         - /*   140 */   720,  872,  897,  116,  864,  349, 1035, 1037,  404, 1047,
135618         - /*   150 */   992, -129, 1050,  492,   62,  722,  879, 1072, 1089,  808,
135619         - /*   160 */  1066, 1094, 1095, 1096, 1097, 1098,  776, 1054,  557,   57,
135620         - /*   170 */   112,  131,  167,  182,  250,  272,  291,  331,  364,  438,
135621         - /*   180 */   497,  517,  591,  653,  690,  739,  775,  798,  892,  908,
135622         - /*   190 */   924,  930, 1015, 1063, 1069,  355,  784,  799,  981, 1101,
135623         - /*   200 */   926, 1151, 1161, 1162,  945, 1164, 1166, 1128, 1168, 1171,
135624         - /*   210 */  1172,  250, 1173, 1174, 1175, 1178, 1180, 1181, 1088, 1102,
135625         - /*   220 */  1119, 1124, 1126,  926, 1131, 1139, 1188, 1140, 1129, 1130,
135626         - /*   230 */  1103, 1144, 1107, 1179, 1156, 1167, 1182, 1134, 1122, 1183,
135627         - /*   240 */  1184, 1150, 1153, 1197, 1111, 1202, 1203, 1123, 1125, 1205,
135628         - /*   250 */  1147, 1185, 1169, 1186, 1190, 1191, 1192, 1213, 1217, 1193,
135629         - /*   260 */  1157, 1196, 1198, 1194, 1220, 1218, 1145, 1154, 1229, 1231,
135630         - /*   270 */  1233, 1216, 1237, 1240, 1241, 1244, 1222, 1227, 1230, 1232,
135631         - /*   280 */  1223, 1235, 1236, 1245, 1249, 1226, 1250, 1254, 1199, 1201,
135632         - /*   290 */  1204, 1207, 1209, 1211, 1214, 1212, 1255, 1208, 1259, 1215,
135633         - /*   300 */  1256, 1200, 1206, 1260, 1247, 1261, 1263, 1262, 1266, 1278,
135634         - /*   310 */  1282, 1292, 1294, 1297, 1298, 1299, 1300, 1221, 1224, 1228,
135635         - /*   320 */  1288, 1291, 1276, 1277, 1295,
       136195  + /*     0 */  -119, 1014,  131, 1031,  -12,  225,  228,  300,  -40,  -45,
       136196  + /*    10 */   243,  256,  293,  129,  218,  418,   79,  376,  433,  298,
       136197  + /*    20 */    16,  137,  367,  323,  -38,  391, -173, -173, -173, -173,
       136198  + /*    30 */  -173, -173, -173, -173, -173, -173, -173, -173, -173, -173,
       136199  + /*    40 */  -173, -173, -173, -173, -173, -173, -173, -173, -173, -173,
       136200  + /*    50 */  -173, -173, -173, -173, -173, -173, -173, -173,  374,  437,
       136201  + /*    60 */   443,  508,  513,  522,  532,  582,  584,  620,  633,  635,
       136202  + /*    70 */   637,  644,  646,  648,  650,  652,  659,  661,  696,  709,
       136203  + /*    80 */   711,  714,  720,  722,  724,  726,  728,  733,  772,  784,
       136204  + /*    90 */   786,  822,  834,  836,  884,  886,  922,  934,  936,  986,
       136205  + /*   100 */   989, 1008, 1016, 1018, -173, -173, -173, -173, -173, -173,
       136206  + /*   110 */  -173, -173, -173,  544,  -37,  274,  299,  501,  161, -173,
       136207  + /*   120 */   193, -173, -173, -173, -173,   22,   22,   22,   64,  141,
       136208  + /*   130 */   212,  342,  208,  504,  504,  132,  494,  606,  677,  678,
       136209  + /*   140 */   750,  794,  796,  -58,   32,  383,  660,  737,  386,  787,
       136210  + /*   150 */   800,  441,  872,  224,  850,  803,  949,  624,  830,  669,
       136211  + /*   160 */   961,  979,  983, 1011, 1013, 1032,  753,  789,  321,   94,
       136212  + /*   170 */   116,  304,  375,  210,  388,  392,  478,  545,  649,  721,
       136213  + /*   180 */   727,  736,  752,  795,  853,  952,  958, 1004, 1040, 1046,
       136214  + /*   190 */  1049, 1050, 1056, 1059, 1067,  559,  774,  811, 1068, 1080,
       136215  + /*   200 */   938, 1082, 1083, 1088,  962, 1089, 1090, 1052, 1093, 1094,
       136216  + /*   210 */  1095,  388, 1096, 1103, 1104, 1105, 1106, 1107,  965,  998,
       136217  + /*   220 */  1055, 1057, 1058,  938, 1069, 1071, 1120, 1073, 1061, 1062,
       136218  + /*   230 */  1033, 1076, 1039, 1108, 1087, 1099, 1111, 1066, 1054, 1112,
       136219  + /*   240 */  1113, 1091, 1084, 1135, 1060, 1133, 1138, 1064, 1081, 1139,
       136220  + /*   250 */  1100, 1119, 1109, 1124, 1127, 1140, 1142, 1168, 1173, 1132,
       136221  + /*   260 */  1115, 1147, 1148, 1137, 1180, 1182, 1110, 1121, 1188, 1189,
       136222  + /*   270 */  1197, 1181, 1200, 1202, 1205, 1203, 1191, 1192, 1199, 1206,
       136223  + /*   280 */  1207, 1209, 1210, 1211, 1214, 1212, 1218, 1219, 1175, 1183,
       136224  + /*   290 */  1185, 1184, 1186, 1190, 1187, 1196, 1237, 1193, 1253, 1194,
       136225  + /*   300 */  1236, 1195, 1198, 1238, 1213, 1221, 1220, 1227, 1229, 1271,
       136226  + /*   310 */  1275, 1284, 1285, 1289, 1290, 1292, 1293, 1201, 1208, 1216,
       136227  + /*   320 */  1280, 1281, 1264, 1269, 1283,
135636 136228   };
135637 136229   static const YYACTIONTYPE yy_default[] = {
135638 136230    /*     0 */  1280, 1270, 1270, 1270, 1202, 1202, 1202, 1202, 1270, 1096,
135639 136231    /*    10 */  1125, 1125, 1254, 1332, 1332, 1332, 1332, 1332, 1332, 1201,
135640 136232    /*    20 */  1332, 1332, 1332, 1332, 1270, 1100, 1131, 1332, 1332, 1332,
135641 136233    /*    30 */  1332, 1203, 1204, 1332, 1332, 1332, 1253, 1255, 1141, 1140,
135642 136234    /*    40 */  1139, 1138, 1236, 1112, 1136, 1129, 1133, 1203, 1197, 1198,
................................................................................
135698 136290   ** to revert to identifiers if they keyword does not apply in the context where
135699 136291   ** it appears.
135700 136292   */
135701 136293   #ifdef YYFALLBACK
135702 136294   static const YYCODETYPE yyFallback[] = {
135703 136295       0,  /*          $ => nothing */
135704 136296       0,  /*       SEMI => nothing */
135705         -   55,  /*    EXPLAIN => ID */
135706         -   55,  /*      QUERY => ID */
135707         -   55,  /*       PLAN => ID */
135708         -   55,  /*      BEGIN => ID */
       136297  +   27,  /*    EXPLAIN => ID */
       136298  +   27,  /*      QUERY => ID */
       136299  +   27,  /*       PLAN => ID */
       136300  +   27,  /*      BEGIN => ID */
135709 136301       0,  /* TRANSACTION => nothing */
135710         -   55,  /*   DEFERRED => ID */
135711         -   55,  /*  IMMEDIATE => ID */
135712         -   55,  /*  EXCLUSIVE => ID */
       136302  +   27,  /*   DEFERRED => ID */
       136303  +   27,  /*  IMMEDIATE => ID */
       136304  +   27,  /*  EXCLUSIVE => ID */
135713 136305       0,  /*     COMMIT => nothing */
135714         -   55,  /*        END => ID */
135715         -   55,  /*   ROLLBACK => ID */
135716         -   55,  /*  SAVEPOINT => ID */
135717         -   55,  /*    RELEASE => ID */
       136306  +   27,  /*        END => ID */
       136307  +   27,  /*   ROLLBACK => ID */
       136308  +   27,  /*  SAVEPOINT => ID */
       136309  +   27,  /*    RELEASE => ID */
135718 136310       0,  /*         TO => nothing */
135719 136311       0,  /*      TABLE => nothing */
135720 136312       0,  /*     CREATE => nothing */
135721         -   55,  /*         IF => ID */
       136313  +   27,  /*         IF => ID */
135722 136314       0,  /*        NOT => nothing */
135723 136315       0,  /*     EXISTS => nothing */
135724         -   55,  /*       TEMP => ID */
       136316  +   27,  /*       TEMP => ID */
135725 136317       0,  /*         LP => nothing */
135726 136318       0,  /*         RP => nothing */
135727 136319       0,  /*         AS => nothing */
135728         -   55,  /*    WITHOUT => ID */
       136320  +   27,  /*    WITHOUT => ID */
135729 136321       0,  /*      COMMA => nothing */
135730         -    0,  /*         OR => nothing */
135731         -    0,  /*        AND => nothing */
135732         -    0,  /*         IS => nothing */
135733         -   55,  /*      MATCH => ID */
135734         -   55,  /*    LIKE_KW => ID */
135735         -    0,  /*    BETWEEN => nothing */
135736         -    0,  /*         IN => nothing */
135737         -    0,  /*     ISNULL => nothing */
135738         -    0,  /*    NOTNULL => nothing */
135739         -    0,  /*         NE => nothing */
135740         -    0,  /*         EQ => nothing */
135741         -    0,  /*         GT => nothing */
135742         -    0,  /*         LE => nothing */
135743         -    0,  /*         LT => nothing */
135744         -    0,  /*         GE => nothing */
135745         -    0,  /*     ESCAPE => nothing */
135746         -    0,  /*     BITAND => nothing */
135747         -    0,  /*      BITOR => nothing */
135748         -    0,  /*     LSHIFT => nothing */
135749         -    0,  /*     RSHIFT => nothing */
135750         -    0,  /*       PLUS => nothing */
135751         -    0,  /*      MINUS => nothing */
135752         -    0,  /*       STAR => nothing */
135753         -    0,  /*      SLASH => nothing */
135754         -    0,  /*        REM => nothing */
135755         -    0,  /*     CONCAT => nothing */
135756         -    0,  /*    COLLATE => nothing */
135757         -    0,  /*     BITNOT => nothing */
135758 136322       0,  /*         ID => nothing */
135759         -    0,  /*    INDEXED => nothing */
135760         -   55,  /*      ABORT => ID */
135761         -   55,  /*     ACTION => ID */
135762         -   55,  /*      AFTER => ID */
135763         -   55,  /*    ANALYZE => ID */
135764         -   55,  /*        ASC => ID */
135765         -   55,  /*     ATTACH => ID */
135766         -   55,  /*     BEFORE => ID */
135767         -   55,  /*         BY => ID */
135768         -   55,  /*    CASCADE => ID */
135769         -   55,  /*       CAST => ID */
135770         -   55,  /*   COLUMNKW => ID */
135771         -   55,  /*   CONFLICT => ID */
135772         -   55,  /*   DATABASE => ID */
135773         -   55,  /*       DESC => ID */
135774         -   55,  /*     DETACH => ID */
135775         -   55,  /*       EACH => ID */
135776         -   55,  /*       FAIL => ID */
135777         -   55,  /*        FOR => ID */
135778         -   55,  /*     IGNORE => ID */
135779         -   55,  /*  INITIALLY => ID */
135780         -   55,  /*    INSTEAD => ID */
135781         -   55,  /*         NO => ID */
135782         -   55,  /*        KEY => ID */
135783         -   55,  /*         OF => ID */
135784         -   55,  /*     OFFSET => ID */
135785         -   55,  /*     PRAGMA => ID */
135786         -   55,  /*      RAISE => ID */
135787         -   55,  /*  RECURSIVE => ID */
135788         -   55,  /*    REPLACE => ID */
135789         -   55,  /*   RESTRICT => ID */
135790         -   55,  /*        ROW => ID */
135791         -   55,  /*    TRIGGER => ID */
135792         -   55,  /*     VACUUM => ID */
135793         -   55,  /*       VIEW => ID */
135794         -   55,  /*    VIRTUAL => ID */
135795         -   55,  /*       WITH => ID */
135796         -   55,  /*    REINDEX => ID */
135797         -   55,  /*     RENAME => ID */
135798         -   55,  /*   CTIME_KW => ID */
       136323  +   27,  /*      ABORT => ID */
       136324  +   27,  /*     ACTION => ID */
       136325  +   27,  /*      AFTER => ID */
       136326  +   27,  /*    ANALYZE => ID */
       136327  +   27,  /*        ASC => ID */
       136328  +   27,  /*     ATTACH => ID */
       136329  +   27,  /*     BEFORE => ID */
       136330  +   27,  /*         BY => ID */
       136331  +   27,  /*    CASCADE => ID */
       136332  +   27,  /*       CAST => ID */
       136333  +   27,  /*   COLUMNKW => ID */
       136334  +   27,  /*   CONFLICT => ID */
       136335  +   27,  /*   DATABASE => ID */
       136336  +   27,  /*       DESC => ID */
       136337  +   27,  /*     DETACH => ID */
       136338  +   27,  /*       EACH => ID */
       136339  +   27,  /*       FAIL => ID */
       136340  +   27,  /*        FOR => ID */
       136341  +   27,  /*     IGNORE => ID */
       136342  +   27,  /*  INITIALLY => ID */
       136343  +   27,  /*    INSTEAD => ID */
       136344  +   27,  /*    LIKE_KW => ID */
       136345  +   27,  /*      MATCH => ID */
       136346  +   27,  /*         NO => ID */
       136347  +   27,  /*        KEY => ID */
       136348  +   27,  /*         OF => ID */
       136349  +   27,  /*     OFFSET => ID */
       136350  +   27,  /*     PRAGMA => ID */
       136351  +   27,  /*      RAISE => ID */
       136352  +   27,  /*  RECURSIVE => ID */
       136353  +   27,  /*    REPLACE => ID */
       136354  +   27,  /*   RESTRICT => ID */
       136355  +   27,  /*        ROW => ID */
       136356  +   27,  /*    TRIGGER => ID */
       136357  +   27,  /*     VACUUM => ID */
       136358  +   27,  /*       VIEW => ID */
       136359  +   27,  /*    VIRTUAL => ID */
       136360  +   27,  /*       WITH => ID */
       136361  +   27,  /*    REINDEX => ID */
       136362  +   27,  /*     RENAME => ID */
       136363  +   27,  /*   CTIME_KW => ID */
135799 136364   };
135800 136365   #endif /* YYFALLBACK */
135801 136366   
135802 136367   /* The following structure represents a single element of the
135803 136368   ** parser's stack.  Information stored includes:
135804 136369   **
135805 136370   **   +  The state number for the parser at this level of the stack.
................................................................................
135883 136448   static const char *const yyTokenName[] = { 
135884 136449     "$",             "SEMI",          "EXPLAIN",       "QUERY",       
135885 136450     "PLAN",          "BEGIN",         "TRANSACTION",   "DEFERRED",    
135886 136451     "IMMEDIATE",     "EXCLUSIVE",     "COMMIT",        "END",         
135887 136452     "ROLLBACK",      "SAVEPOINT",     "RELEASE",       "TO",          
135888 136453     "TABLE",         "CREATE",        "IF",            "NOT",         
135889 136454     "EXISTS",        "TEMP",          "LP",            "RP",          
135890         -  "AS",            "WITHOUT",       "COMMA",         "OR",          
135891         -  "AND",           "IS",            "MATCH",         "LIKE_KW",     
135892         -  "BETWEEN",       "IN",            "ISNULL",        "NOTNULL",     
135893         -  "NE",            "EQ",            "GT",            "LE",          
135894         -  "LT",            "GE",            "ESCAPE",        "BITAND",      
135895         -  "BITOR",         "LSHIFT",        "RSHIFT",        "PLUS",        
135896         -  "MINUS",         "STAR",          "SLASH",         "REM",         
135897         -  "CONCAT",        "COLLATE",       "BITNOT",        "ID",          
135898         -  "INDEXED",       "ABORT",         "ACTION",        "AFTER",       
135899         -  "ANALYZE",       "ASC",           "ATTACH",        "BEFORE",      
135900         -  "BY",            "CASCADE",       "CAST",          "COLUMNKW",    
135901         -  "CONFLICT",      "DATABASE",      "DESC",          "DETACH",      
135902         -  "EACH",          "FAIL",          "FOR",           "IGNORE",      
135903         -  "INITIALLY",     "INSTEAD",       "NO",            "KEY",         
135904         -  "OF",            "OFFSET",        "PRAGMA",        "RAISE",       
135905         -  "RECURSIVE",     "REPLACE",       "RESTRICT",      "ROW",         
135906         -  "TRIGGER",       "VACUUM",        "VIEW",          "VIRTUAL",     
135907         -  "WITH",          "REINDEX",       "RENAME",        "CTIME_KW",    
135908         -  "ANY",           "STRING",        "JOIN_KW",       "CONSTRAINT",  
       136455  +  "AS",            "WITHOUT",       "COMMA",         "ID",          
       136456  +  "ABORT",         "ACTION",        "AFTER",         "ANALYZE",     
       136457  +  "ASC",           "ATTACH",        "BEFORE",        "BY",          
       136458  +  "CASCADE",       "CAST",          "COLUMNKW",      "CONFLICT",    
       136459  +  "DATABASE",      "DESC",          "DETACH",        "EACH",        
       136460  +  "FAIL",          "FOR",           "IGNORE",        "INITIALLY",   
       136461  +  "INSTEAD",       "LIKE_KW",       "MATCH",         "NO",          
       136462  +  "KEY",           "OF",            "OFFSET",        "PRAGMA",      
       136463  +  "RAISE",         "RECURSIVE",     "REPLACE",       "RESTRICT",    
       136464  +  "ROW",           "TRIGGER",       "VACUUM",        "VIEW",        
       136465  +  "VIRTUAL",       "WITH",          "REINDEX",       "RENAME",      
       136466  +  "CTIME_KW",      "ANY",           "OR",            "AND",         
       136467  +  "IS",            "BETWEEN",       "IN",            "ISNULL",      
       136468  +  "NOTNULL",       "NE",            "EQ",            "GT",          
       136469  +  "LE",            "LT",            "GE",            "ESCAPE",      
       136470  +  "BITAND",        "BITOR",         "LSHIFT",        "RSHIFT",      
       136471  +  "PLUS",          "MINUS",         "STAR",          "SLASH",       
       136472  +  "REM",           "CONCAT",        "COLLATE",       "BITNOT",      
       136473  +  "INDEXED",       "STRING",        "JOIN_KW",       "CONSTRAINT",  
135909 136474     "DEFAULT",       "NULL",          "PRIMARY",       "UNIQUE",      
135910 136475     "CHECK",         "REFERENCES",    "AUTOINCR",      "ON",          
135911 136476     "INSERT",        "DELETE",        "UPDATE",        "SET",         
135912 136477     "DEFERRABLE",    "FOREIGN",       "DROP",          "UNION",       
135913 136478     "ALL",           "EXCEPT",        "INTERSECT",     "SELECT",      
135914 136479     "VALUES",        "DISTINCT",      "DOT",           "FROM",        
135915 136480     "JOIN",          "USING",         "ORDER",         "GROUP",       
................................................................................
139378 139943     void *pEngine;                  /* The LEMON-generated LALR(1) parser */
139379 139944     int n = 0;                      /* Length of the next token token */
139380 139945     int tokenType;                  /* type of the next token */
139381 139946     int lastTokenParsed = -1;       /* type of the previous token */
139382 139947     sqlite3 *db = pParse->db;       /* The database connection */
139383 139948     int mxSqlLen;                   /* Max length of an SQL string */
139384 139949   #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
139385         -  unsigned char zSpace[sizeof(yyParser)];  /* Space for parser engine object */
       139950  +  yyParser sEngine;    /* Space to hold the Lemon-generated Parser object */
139386 139951   #endif
139387 139952   
139388 139953     assert( zSql!=0 );
139389 139954     mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
139390 139955     if( db->nVdbeActive==0 ){
139391 139956       db->u1.isInterrupted = 0;
139392 139957     }
139393 139958     pParse->rc = SQLITE_OK;
139394 139959     pParse->zTail = zSql;
139395 139960     assert( pzErrMsg!=0 );
139396 139961     /* sqlite3ParserTrace(stdout, "parser: "); */
139397 139962   #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
139398         -  pEngine = zSpace;
       139963  +  pEngine = &sEngine;
139399 139964     sqlite3ParserInit(pEngine);
139400 139965   #else
139401 139966     pEngine = sqlite3ParserAlloc(sqlite3Malloc);
139402 139967     if( pEngine==0 ){
139403 139968       sqlite3OomFault(db);
139404 139969       return SQLITE_NOMEM_BKPT;
139405 139970     }
................................................................................
139500 140065   
139501 140066     if( pParse->pWithToFree ) sqlite3WithDelete(db, pParse->pWithToFree);
139502 140067     sqlite3DeleteTrigger(db, pParse->pNewTrigger);
139503 140068     sqlite3DbFree(db, pParse->pVList);
139504 140069     while( pParse->pAinc ){
139505 140070       AutoincInfo *p = pParse->pAinc;
139506 140071       pParse->pAinc = p->pNext;
139507         -    sqlite3DbFree(db, p);
       140072  +    sqlite3DbFreeNN(db, p);
139508 140073     }
139509 140074     while( pParse->pZombieTab ){
139510 140075       Table *p = pParse->pZombieTab;
139511 140076       pParse->pZombieTab = p->pNextZombie;
139512 140077       sqlite3DeleteTable(db, p);
139513 140078     }
139514 140079     assert( nErr==0 || pParse->rc!=SQLITE_OK );
................................................................................
142994 143559       /* Opening a db handle. Fourth parameter is passed 0. */
142995 143560       void *pArg = sqlite3GlobalConfig.pSqllogArg;
142996 143561       sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0);
142997 143562     }
142998 143563   #endif
142999 143564   #if defined(SQLITE_HAS_CODEC)
143000 143565     if( rc==SQLITE_OK ){
143001         -    const char *zHexKey = sqlite3_uri_parameter(zOpen, "hexkey");
143002         -    if( zHexKey && zHexKey[0] ){
       143566  +    const char *zKey;
       143567  +    if( (zKey = sqlite3_uri_parameter(zOpen, "hexkey"))!=0 && zKey[0] ){
143003 143568         u8 iByte;
143004 143569         int i;
143005         -      char zKey[40];
143006         -      for(i=0, iByte=0; i<sizeof(zKey)*2 && sqlite3Isxdigit(zHexKey[i]); i++){
143007         -        iByte = (iByte<<4) + sqlite3HexToInt(zHexKey[i]);
143008         -        if( (i&1)!=0 ) zKey[i/2] = iByte;
       143570  +      char zDecoded[40];
       143571  +      for(i=0, iByte=0; i<sizeof(zDecoded)*2 && sqlite3Isxdigit(zKey[i]); i++){
       143572  +        iByte = (iByte<<4) + sqlite3HexToInt(zKey[i]);
       143573  +        if( (i&1)!=0 ) zDecoded[i/2] = iByte;
143009 143574         }
143010         -      sqlite3_key_v2(db, 0, zKey, i/2);
       143575  +      sqlite3_key_v2(db, 0, zDecoded, i/2);
       143576  +    }else if( (zKey = sqlite3_uri_parameter(zOpen, "key"))!=0 ){
       143577  +      sqlite3_key_v2(db, 0, zKey, sqlite3Strlen30(zKey));
143011 143578       }
143012 143579     }
143013 143580   #endif
143014 143581     sqlite3_free(zOpen);
143015 143582     return rc & 0xff;
143016 143583   }
143017 143584   
................................................................................
145608 146175       if( (c & 0x80)==0 ) break;
145609 146176     }
145610 146177     *v = b;
145611 146178     return (int)(p - pStart);
145612 146179   }
145613 146180   
145614 146181   /*
145615         -** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to a
145616         -** 32-bit integer before it is returned.
       146182  +** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to 
       146183  +** a non-negative 32-bit integer before it is returned.
145617 146184   */
145618 146185   SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *p, int *pi){
145619 146186     u32 a;
145620 146187   
145621 146188   #ifndef fts3GetVarint32
145622 146189     GETVARINT_INIT(a, p, 0,  0x00,     0x80, *pi, 1);
145623 146190   #else
................................................................................
145625 146192     assert( a & 0x80 );
145626 146193   #endif
145627 146194   
145628 146195     GETVARINT_STEP(a, p, 7,  0x7F,     0x4000, *pi, 2);
145629 146196     GETVARINT_STEP(a, p, 14, 0x3FFF,   0x200000, *pi, 3);
145630 146197     GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *pi, 4);
145631 146198     a = (a & 0x0FFFFFFF );
145632         -  *pi = (int)(a | ((u32)(*p & 0x0F) << 28));
       146199  +  *pi = (int)(a | ((u32)(*p & 0x07) << 28));
       146200  +  assert( 0==(a & 0x80000000) );
       146201  +  assert( *pi>=0 );
145633 146202     return 5;
145634 146203   }
145635 146204   
145636 146205   /*
145637 146206   ** Return the number of bytes required to encode v as a varint
145638 146207   */
145639 146208   SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64 v){
................................................................................
146455 147024         }else{
146456 147025           for(iOpt=0; iOpt<SizeofArray(aFts4Opt); iOpt++){
146457 147026             struct Fts4Option *pOp = &aFts4Opt[iOpt];
146458 147027             if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){
146459 147028               break;
146460 147029             }
146461 147030           }
146462         -        if( iOpt==SizeofArray(aFts4Opt) ){
146463         -          sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z);
146464         -          rc = SQLITE_ERROR;
146465         -        }else{
146466         -          switch( iOpt ){
146467         -            case 0:               /* MATCHINFO */
146468         -              if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
146469         -                sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal);
146470         -                rc = SQLITE_ERROR;
146471         -              }
146472         -              bNoDocsize = 1;
146473         -              break;
146474         -
146475         -            case 1:               /* PREFIX */
146476         -              sqlite3_free(zPrefix);
146477         -              zPrefix = zVal;
146478         -              zVal = 0;
146479         -              break;
146480         -
146481         -            case 2:               /* COMPRESS */
146482         -              sqlite3_free(zCompress);
146483         -              zCompress = zVal;
146484         -              zVal = 0;
146485         -              break;
146486         -
146487         -            case 3:               /* UNCOMPRESS */
146488         -              sqlite3_free(zUncompress);
146489         -              zUncompress = zVal;
146490         -              zVal = 0;
146491         -              break;
146492         -
146493         -            case 4:               /* ORDER */
146494         -              if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3)) 
146495         -               && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4)) 
146496         -              ){
146497         -                sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal);
146498         -                rc = SQLITE_ERROR;
146499         -              }
146500         -              bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
146501         -              break;
146502         -
146503         -            case 5:              /* CONTENT */
146504         -              sqlite3_free(zContent);
146505         -              zContent = zVal;
146506         -              zVal = 0;
146507         -              break;
146508         -
146509         -            case 6:              /* LANGUAGEID */
146510         -              assert( iOpt==6 );
146511         -              sqlite3_free(zLanguageid);
146512         -              zLanguageid = zVal;
146513         -              zVal = 0;
146514         -              break;
146515         -
146516         -            case 7:              /* NOTINDEXED */
146517         -              azNotindexed[nNotindexed++] = zVal;
146518         -              zVal = 0;
146519         -              break;
146520         -          }
       147031  +        switch( iOpt ){
       147032  +          case 0:               /* MATCHINFO */
       147033  +            if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
       147034  +              sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal);
       147035  +              rc = SQLITE_ERROR;
       147036  +            }
       147037  +            bNoDocsize = 1;
       147038  +            break;
       147039  +
       147040  +          case 1:               /* PREFIX */
       147041  +            sqlite3_free(zPrefix);
       147042  +            zPrefix = zVal;
       147043  +            zVal = 0;
       147044  +            break;
       147045  +
       147046  +          case 2:               /* COMPRESS */
       147047  +            sqlite3_free(zCompress);
       147048  +            zCompress = zVal;
       147049  +            zVal = 0;
       147050  +            break;
       147051  +
       147052  +          case 3:               /* UNCOMPRESS */
       147053  +            sqlite3_free(zUncompress);
       147054  +            zUncompress = zVal;
       147055  +            zVal = 0;
       147056  +            break;
       147057  +
       147058  +          case 4:               /* ORDER */
       147059  +            if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3)) 
       147060  +             && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4)) 
       147061  +            ){
       147062  +              sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal);
       147063  +              rc = SQLITE_ERROR;
       147064  +            }
       147065  +            bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
       147066  +            break;
       147067  +
       147068  +          case 5:              /* CONTENT */
       147069  +            sqlite3_free(zContent);
       147070  +            zContent = zVal;
       147071  +            zVal = 0;
       147072  +            break;
       147073  +
       147074  +          case 6:              /* LANGUAGEID */
       147075  +            assert( iOpt==6 );
       147076  +            sqlite3_free(zLanguageid);
       147077  +            zLanguageid = zVal;
       147078  +            zVal = 0;
       147079  +            break;
       147080  +
       147081  +          case 7:              /* NOTINDEXED */
       147082  +            azNotindexed[nNotindexed++] = zVal;
       147083  +            zVal = 0;
       147084  +            break;
       147085  +
       147086  +          default:
       147087  +            assert( iOpt==SizeofArray(aFts4Opt) );
       147088  +            sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z);
       147089  +            rc = SQLITE_ERROR;
       147090  +            break;
146521 147091           }
146522 147092           sqlite3_free(zVal);
146523 147093         }
146524 147094       }
146525 147095   
146526 147096       /* Otherwise, the argument is a column name. */
146527 147097       else {
................................................................................
147082 147652       ** the size of zBuffer if required.  */
147083 147653       if( !isFirstTerm ){
147084 147654         zCsr += fts3GetVarint32(zCsr, &nPrefix);
147085 147655       }
147086 147656       isFirstTerm = 0;
147087 147657       zCsr += fts3GetVarint32(zCsr, &nSuffix);
147088 147658       
147089         -    if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
       147659  +    assert( nPrefix>=0 && nSuffix>=0 );
       147660  +    if( &zCsr[nSuffix]>zEnd ){
147090 147661         rc = FTS_CORRUPT_VTAB;
147091 147662         goto finish_scan;
147092 147663       }
147093 147664       if( nPrefix+nSuffix>nAlloc ){
147094 147665         char *zNew;
147095 147666         nAlloc = (nPrefix+nSuffix) * 2;
147096 147667         zNew = (char *)sqlite3_realloc(zBuffer, nAlloc);
................................................................................
147892 148463         nOut += sqlite3Fts3PutVarint(&pOut[nOut], iDelta);
147893 148464         pOut[nOut++] = 0x02;
147894 148465         bWritten = 1;
147895 148466       }
147896 148467       fts3ColumnlistCopy(0, &p);
147897 148468     }
147898 148469   
147899         -  while( p<pEnd && *p==0x01 ){
       148470  +  while( p<pEnd ){
147900 148471       sqlite3_int64 iCol;
147901 148472       p++;
147902 148473       p += sqlite3Fts3GetVarint(p, &iCol);
147903 148474       if( *p==0x02 ){
147904 148475         if( bWritten==0 ){
147905 148476           nOut += sqlite3Fts3PutVarint(&pOut[nOut], iDelta);
147906 148477           bWritten = 1;
................................................................................
148572 149143     int rc = SQLITE_OK;             /* Return Code */
148573 149144     Fts3Cursor *pCsr = (Fts3Cursor *) pCursor;
148574 149145     Fts3Table *p = (Fts3Table *)pCursor->pVtab;
148575 149146   
148576 149147     /* The column value supplied by SQLite must be in range. */
148577 149148     assert( iCol>=0 && iCol<=p->nColumn+2 );
148578 149149   
148579         -  if( iCol==p->nColumn+1 ){
148580         -    /* This call is a request for the "docid" column. Since "docid" is an 
148581         -    ** alias for "rowid", use the xRowid() method to obtain the value.
148582         -    */
148583         -    sqlite3_result_int64(pCtx, pCsr->iPrevId);
148584         -  }else if( iCol==p->nColumn ){
148585         -    /* The extra column whose name is the same as the table.
148586         -    ** Return a blob which is a pointer to the cursor.  */
148587         -    sqlite3_result_blob(pCtx, &pCsr, sizeof(pCsr), SQLITE_TRANSIENT);
148588         -  }else if( iCol==p->nColumn+2 && pCsr->pExpr ){
148589         -    sqlite3_result_int64(pCtx, pCsr->iLangid);
148590         -  }else{
148591         -    /* The requested column is either a user column (one that contains 
148592         -    ** indexed data), or the language-id column.  */
148593         -    rc = fts3CursorSeek(0, pCsr);
148594         -
148595         -    if( rc==SQLITE_OK ){
148596         -      if( iCol==p->nColumn+2 ){
148597         -        int iLangid = 0;
148598         -        if( p->zLanguageid ){
148599         -          iLangid = sqlite3_column_int(pCsr->pStmt, p->nColumn+1);
148600         -        }
148601         -        sqlite3_result_int(pCtx, iLangid);
148602         -      }else if( sqlite3_data_count(pCsr->pStmt)>(iCol+1) ){
       149150  +  switch( iCol-p->nColumn ){
       149151  +    case 0:
       149152  +      /* The special 'table-name' column */
       149153  +      sqlite3_result_blob(pCtx, &pCsr, sizeof(Fts3Cursor*), SQLITE_TRANSIENT);
       149154  +      sqlite3_result_subtype(pCtx, SQLITE_BLOB);
       149155  +      break;
       149156  +
       149157  +    case 1:
       149158  +      /* The docid column */
       149159  +      sqlite3_result_int64(pCtx, pCsr->iPrevId);
       149160  +      break;
       149161  +
       149162  +    case 2:
       149163  +      if( pCsr->pExpr ){
       149164  +        sqlite3_result_int64(pCtx, pCsr->iLangid);
       149165  +        break;
       149166  +      }else if( p->zLanguageid==0 ){
       149167  +        sqlite3_result_int(pCtx, 0);
       149168  +        break;
       149169  +      }else{
       149170  +        iCol = p->nColumn;
       149171  +        /* fall-through */
       149172  +      }
       149173  +
       149174  +    default:
       149175  +      /* A user column. Or, if this is a full-table scan, possibly the
       149176  +      ** language-id column. Seek the cursor. */
       149177  +      rc = fts3CursorSeek(0, pCsr);
       149178  +      if( rc==SQLITE_OK && sqlite3_data_count(pCsr->pStmt)-1>iCol ){
148603 149179           sqlite3_result_value(pCtx, sqlite3_column_value(pCsr->pStmt, iCol+1));
148604 149180         }
148605         -    }
       149181  +      break;
148606 149182     }
148607 149183   
148608 149184     assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
148609 149185     return rc;
148610 149186   }
148611 149187   
148612 149188   /* 
................................................................................
148678 149254   ** table (if p->bHasStat==2), attempt to determine this (set p->bHasStat
148679 149255   ** to 0 or 1). Return SQLITE_OK if successful, or an SQLite error code
148680 149256   ** if an error occurs.
148681 149257   */
148682 149258   static int fts3SetHasStat(Fts3Table *p){
148683 149259     int rc = SQLITE_OK;
148684 149260     if( p->bHasStat==2 ){
148685         -    const char *zFmt ="SELECT 1 FROM %Q.sqlite_master WHERE tbl_name='%q_stat'";
148686         -    char *zSql = sqlite3_mprintf(zFmt, p->zDb, p->zName);
148687         -    if( zSql ){
148688         -      sqlite3_stmt *pStmt = 0;
148689         -      rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
148690         -      if( rc==SQLITE_OK ){
148691         -        int bHasStat = (sqlite3_step(pStmt)==SQLITE_ROW);
148692         -        rc = sqlite3_finalize(pStmt);
148693         -        if( rc==SQLITE_OK ) p->bHasStat = (u8)bHasStat;
148694         -      }
148695         -      sqlite3_free(zSql);
       149261  +    char *zTbl = sqlite3_mprintf("%s_stat", p->zName);
       149262  +    if( zTbl ){
       149263  +      int res = sqlite3_table_column_metadata(p->db, p->zDb, zTbl, 0,0,0,0,0,0);
       149264  +      sqlite3_free(zTbl);
       149265  +      p->bHasStat = (res==SQLITE_OK);
148696 149266       }else{
148697 149267         rc = SQLITE_NOMEM;
148698 149268       }
148699 149269     }
148700 149270     return rc;
148701 149271   }
148702 149272   
................................................................................
148795 149365   */
148796 149366   static int fts3FunctionArg(
148797 149367     sqlite3_context *pContext,      /* SQL function call context */
148798 149368     const char *zFunc,              /* Function name */
148799 149369     sqlite3_value *pVal,            /* argv[0] passed to function */
148800 149370     Fts3Cursor **ppCsr              /* OUT: Store cursor handle here */
148801 149371   ){
148802         -  Fts3Cursor *pRet;
148803         -  if( sqlite3_value_type(pVal)!=SQLITE_BLOB 
148804         -   || sqlite3_value_bytes(pVal)!=sizeof(Fts3Cursor *)
148805         -  ){
       149372  +  int rc = SQLITE_OK;
       149373  +  if( sqlite3_value_subtype(pVal)==SQLITE_BLOB ){
       149374  +    *ppCsr = *(Fts3Cursor**)sqlite3_value_blob(pVal);
       149375  +  }else{
148806 149376       char *zErr = sqlite3_mprintf("illegal first argument to %s", zFunc);
148807 149377       sqlite3_result_error(pContext, zErr, -1);
148808 149378       sqlite3_free(zErr);
148809         -    return SQLITE_ERROR;
       149379  +    rc = SQLITE_ERROR;
148810 149380     }
148811         -  memcpy(&pRet, sqlite3_value_blob(pVal), sizeof(Fts3Cursor *));
148812         -  *ppCsr = pRet;
148813         -  return SQLITE_OK;
       149381  +  return rc;
148814 149382   }
148815 149383   
148816 149384   /*
148817 149385   ** Implementation of the snippet() function for FTS3
148818 149386   */
148819 149387   static void fts3SnippetFunc(
148820 149388     sqlite3_context *pContext,      /* SQLite function call context */
................................................................................
149193 149761   #ifdef SQLITE_TEST
149194 149762     if( rc==SQLITE_OK ){
149195 149763       rc = sqlite3Fts3ExprInitTestInterface(db);
149196 149764     }
149197 149765   #endif
149198 149766   
149199 149767     /* Create the virtual table wrapper around the hash-table and overload 
149200         -  ** the two scalar functions. If this is successful, register the
       149768  +  ** the four scalar functions. If this is successful, register the
149201 149769     ** module with sqlite.
149202 149770     */
149203 149771     if( SQLITE_OK==rc 
149204 149772      && SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
149205 149773      && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
149206 149774      && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
149207 149775      && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
................................................................................
149776 150344     Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab;
149777 150345     u8 bEof = 0;
149778 150346   
149779 150347     /* This is only called if it is guaranteed that the phrase has at least
149780 150348     ** one incremental token. In which case the bIncr flag is set. */
149781 150349     assert( p->bIncr==1 );
149782 150350   
149783         -  if( p->nToken==1 && p->bIncr ){
       150351  +  if( p->nToken==1 ){
149784 150352       rc = sqlite3Fts3MsrIncrNext(pTab, p->aToken[0].pSegcsr, 
149785 150353           &pDL->iDocid, &pDL->pList, &pDL->nList
149786 150354       );
149787 150355       if( pDL->pList==0 ) bEof = 1;
149788 150356     }else{
149789 150357       int bDescDoclist = pCsr->bDesc;
149790 150358       struct TokenDoclist a[MAX_INCR_PHRASE_TOKENS];
................................................................................
150009 150577   ** The average document size in pages is calculated by first calculating 
150010 150578   ** determining the average size in bytes, B. If B is less than the amount
150011 150579   ** of data that will fit on a single leaf page of an intkey table in
150012 150580   ** this database, then the average docsize is 1. Otherwise, it is 1 plus
150013 150581   ** the number of overflow pages consumed by a record B bytes in size.
150014 150582   */
150015 150583   static int fts3EvalAverageDocsize(Fts3Cursor *pCsr, int *pnPage){
       150584  +  int rc = SQLITE_OK;
150016 150585     if( pCsr->nRowAvg==0 ){
150017 150586       /* The average document size, which is required to calculate the cost
150018 150587       ** of each doclist, has not yet been determined. Read the required 
150019 150588       ** data from the %_stat table to calculate it.
150020 150589       **
150021 150590       ** Entry 0 of the %_stat table is a blob containing (nCol+1) FTS3 
150022 150591       ** varints, where nCol is the number of columns in the FTS3 table.
150023 150592       ** The first varint is the number of documents currently stored in
150024 150593       ** the table. The following nCol varints contain the total amount of
150025 150594       ** data stored in all rows of each column of the table, from left
150026 150595       ** to right.
150027 150596       */
150028         -    int rc;
150029 150597       Fts3Table *p = (Fts3Table*)pCsr->base.pVtab;
150030 150598       sqlite3_stmt *pStmt;
150031 150599       sqlite3_int64 nDoc = 0;
150032 150600       sqlite3_int64 nByte = 0;
150033 150601       const char *pEnd;
150034 150602       const char *a;
150035 150603   
................................................................................
150048 150616         return FTS_CORRUPT_VTAB;
150049 150617       }
150050 150618   
150051 150619       pCsr->nDoc = nDoc;
150052 150620       pCsr->nRowAvg = (int)(((nByte / nDoc) + p->nPgsz) / p->nPgsz);
150053 150621       assert( pCsr->nRowAvg>0 ); 
150054 150622       rc = sqlite3_reset(pStmt);
150055         -    if( rc!=SQLITE_OK ) return rc;
150056 150623     }
150057 150624   
150058 150625     *pnPage = pCsr->nRowAvg;
150059         -  return SQLITE_OK;
       150626  +  return rc;
150060 150627   }
150061 150628   
150062 150629   /*
150063 150630   ** This function is called to select the tokens (if any) that will be 
150064 150631   ** deferred. The array aTC[] has already been populated when this is
150065 150632   ** called.
150066 150633   **
................................................................................
150402 150969               }else{
150403 150970                 fts3EvalNextRow(pCsr, pRight, pRc);
150404 150971               }
150405 150972             }
150406 150973             pExpr->iDocid = pLeft->iDocid;
150407 150974             pExpr->bEof = (pLeft->bEof || pRight->bEof);
150408 150975             if( pExpr->eType==FTSQUERY_NEAR && pExpr->bEof ){
150409         -            if( pRight->pPhrase && pRight->pPhrase->doclist.aAll ){
       150976  +            assert( pRight->eType==FTSQUERY_PHRASE );
       150977  +            if( pRight->pPhrase->doclist.aAll ){
150410 150978                 Fts3Doclist *pDl = &pRight->pPhrase->doclist;
150411 150979                 while( *pRc==SQLITE_OK && pRight->bEof==0 ){
150412 150980                   memset(pDl->pList, 0, pDl->nList);
150413 150981                   fts3EvalNextRow(pCsr, pRight, pRc);
150414 150982                 }
150415 150983               }
150416 150984               if( pLeft->pPhrase && pLeft->pPhrase->doclist.aAll ){
................................................................................
150431 150999           sqlite3_int64 iCmp = DOCID_CMP(pLeft->iDocid, pRight->iDocid);
150432 151000   
150433 151001           assert( pLeft->bStart || pLeft->iDocid==pRight->iDocid );
150434 151002           assert( pRight->bStart || pLeft->iDocid==pRight->iDocid );
150435 151003   
150436 151004           if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){
150437 151005             fts3EvalNextRow(pCsr, pLeft, pRc);
150438         -        }else if( pLeft->bEof || (pRight->bEof==0 && iCmp>0) ){
       151006  +        }else if( pLeft->bEof || iCmp>0 ){
150439 151007             fts3EvalNextRow(pCsr, pRight, pRc);
150440 151008           }else{
150441 151009             fts3EvalNextRow(pCsr, pLeft, pRc);
150442 151010             fts3EvalNextRow(pCsr, pRight, pRc);
150443 151011           }
150444 151012   
150445 151013           pExpr->bEof = (pLeft->bEof && pRight->bEof);
................................................................................
150523 151091     **
150524 151092     ** The right-hand child of a NEAR node is always a phrase. The 
150525 151093     ** left-hand child may be either a phrase or a NEAR node. There are
150526 151094     ** no exceptions to this - it's the way the parser in fts3_expr.c works.
150527 151095     */
150528 151096     if( *pRc==SQLITE_OK 
150529 151097      && pExpr->eType==FTSQUERY_NEAR 
150530         -   && pExpr->bEof==0
150531 151098      && (pExpr->pParent==0 || pExpr->pParent->eType!=FTSQUERY_NEAR)
150532 151099     ){
150533 151100       Fts3Expr *p; 
150534 151101       int nTmp = 0;                 /* Bytes of temp space */
150535 151102       char *aTmp;                   /* Temp space for PoslistNearMerge() */
150536 151103   
150537 151104       /* Allocate temporary working space. */
150538 151105       for(p=pExpr; p->pLeft; p=p->pLeft){
       151106  +      assert( p->pRight->pPhrase->doclist.nList>0 );
150539 151107         nTmp += p->pRight->pPhrase->doclist.nList;
150540 151108       }
150541 151109       nTmp += p->pPhrase->doclist.nList;
150542         -    if( nTmp==0 ){
       151110  +    aTmp = sqlite3_malloc(nTmp*2);
       151111  +    if( !aTmp ){
       151112  +      *pRc = SQLITE_NOMEM;
150543 151113         res = 0;
150544 151114       }else{
150545         -      aTmp = sqlite3_malloc(nTmp*2);
150546         -      if( !aTmp ){
150547         -        *pRc = SQLITE_NOMEM;
150548         -        res = 0;
150549         -      }else{
150550         -        char *aPoslist = p->pPhrase->doclist.pList;
150551         -        int nToken = p->pPhrase->nToken;
150552         -
150553         -        for(p=p->pParent;res && p && p->eType==FTSQUERY_NEAR; p=p->pParent){
150554         -          Fts3Phrase *pPhrase = p->pRight->pPhrase;
150555         -          int nNear = p->nNear;
150556         -          res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
150557         -        }
150558         -
150559         -        aPoslist = pExpr->pRight->pPhrase->doclist.pList;
150560         -        nToken = pExpr->pRight->pPhrase->nToken;
150561         -        for(p=pExpr->pLeft; p && res; p=p->pLeft){
150562         -          int nNear;
150563         -          Fts3Phrase *pPhrase;
150564         -          assert( p->pParent && p->pParent->pLeft==p );
150565         -          nNear = p->pParent->nNear;
150566         -          pPhrase = (
150567         -              p->eType==FTSQUERY_NEAR ? p->pRight->pPhrase : p->pPhrase
150568         -              );
150569         -          res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
150570         -        }
150571         -      }
150572         -
150573         -      sqlite3_free(aTmp);
150574         -    }
       151115  +      char *aPoslist = p->pPhrase->doclist.pList;
       151116  +      int nToken = p->pPhrase->nToken;
       151117  +
       151118  +      for(p=p->pParent;res && p && p->eType==FTSQUERY_NEAR; p=p->pParent){
       151119  +        Fts3Phrase *pPhrase = p->pRight->pPhrase;
       151120  +        int nNear = p->nNear;
       151121  +        res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
       151122  +      }
       151123  +
       151124  +      aPoslist = pExpr->pRight->pPhrase->doclist.pList;
       151125  +      nToken = pExpr->pRight->pPhrase->nToken;
       151126  +      for(p=pExpr->pLeft; p && res; p=p->pLeft){
       151127  +        int nNear;
       151128  +        Fts3Phrase *pPhrase;
       151129  +        assert( p->pParent && p->pParent->pLeft==p );
       151130  +        nNear = p->pParent->nNear;
       151131  +        pPhrase = (
       151132  +            p->eType==FTSQUERY_NEAR ? p->pRight->pPhrase : p->pPhrase
       151133  +        );
       151134  +        res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
       151135  +      }
       151136  +    }
       151137  +
       151138  +    sqlite3_free(aTmp);
150575 151139     }
150576 151140   
150577 151141     return res;
150578 151142   }
150579 151143   
150580 151144   /*
150581 151145   ** This function is a helper function for sqlite3Fts3EvalTestDeferred().
................................................................................
166674 167238       "ALTER TABLE %Q.'%q_parent' RENAME TO \"%w_parent\";"
166675 167239       "ALTER TABLE %Q.'%q_rowid'  RENAME TO \"%w_rowid\";"
166676 167240       , pRtree->zDb, pRtree->zName, zNewName 
166677 167241       , pRtree->zDb, pRtree->zName, zNewName 
166678 167242       , pRtree->zDb, pRtree->zName, zNewName
166679 167243     );
166680 167244     if( zSql ){
       167245  +    nodeBlobReset(pRtree);
166681 167246       rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
166682 167247       sqlite3_free(zSql);
166683 167248     }
166684 167249     return rc;
166685 167250   }
166686 167251   
       167252  +/*
       167253  +** The xSavepoint method.
       167254  +**
       167255  +** This module does not need to do anything to support savepoints. However,
       167256  +** it uses this hook to close any open blob handle. This is done because a 
       167257  +** DROP TABLE command - which fortunately always opens a savepoint - cannot 
       167258  +** succeed if there are any open blob handles. i.e. if the blob handle were
       167259  +** not closed here, the following would fail:
       167260  +**
       167261  +**   BEGIN;
       167262  +**     INSERT INTO rtree...
       167263  +**     DROP TABLE <tablename>;    -- Would fail with SQLITE_LOCKED
       167264  +**   COMMIT;
       167265  +*/
       167266  +static int rtreeSavepoint(sqlite3_vtab *pVtab, int iSavepoint){
       167267  +  Rtree *pRtree = (Rtree *)pVtab;
       167268  +  int iwt = pRtree->inWrTrans;
       167269  +  UNUSED_PARAMETER(iSavepoint);
       167270  +  pRtree->inWrTrans = 0;
       167271  +  nodeBlobReset(pRtree);
       167272  +  pRtree->inWrTrans = iwt;
       167273  +  return SQLITE_OK;
       167274  +}
166687 167275   
166688 167276   /*
166689 167277   ** This function populates the pRtree->nRowEst variable with an estimate
166690 167278   ** of the number of rows in the virtual table. If possible, this is based
166691 167279   ** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST.
166692 167280   */
166693 167281   static int rtreeQueryStat1(sqlite3 *db, Rtree *pRtree){
................................................................................
166726 167314       sqlite3_free(zSql);
166727 167315     }
166728 167316   
166729 167317     return rc;
166730 167318   }
166731 167319   
166732 167320   static sqlite3_module rtreeModule = {
166733         -  0,                          /* iVersion */
       167321  +  2,                          /* iVersion */
166734 167322     rtreeCreate,                /* xCreate - create a table */
166735 167323     rtreeConnect,               /* xConnect - connect to an existing table */
166736 167324     rtreeBestIndex,             /* xBestIndex - Determine search strategy */
166737 167325     rtreeDisconnect,            /* xDisconnect - Disconnect from a table */
166738 167326     rtreeDestroy,               /* xDestroy - Drop a table */
166739 167327     rtreeOpen,                  /* xOpen - open a cursor */
166740 167328     rtreeClose,                 /* xClose - close a cursor */
................................................................................
166746 167334     rtreeUpdate,                /* xUpdate - write data */
166747 167335     rtreeBeginTransaction,      /* xBegin - begin transaction */
166748 167336     rtreeEndTransaction,        /* xSync - sync transaction */
166749 167337     rtreeEndTransaction,        /* xCommit - commit transaction */
166750 167338     rtreeEndTransaction,        /* xRollback - rollback transaction */
166751 167339     0,                          /* xFindFunction - function overloading */
166752 167340     rtreeRename,                /* xRename - rename the table */
166753         -  0,                          /* xSavepoint */
       167341  +  rtreeSavepoint,             /* xSavepoint */
166754 167342     0,                          /* xRelease */
166755 167343     0,                          /* xRollbackTo */
166756 167344   };
166757 167345   
166758 167346   static int rtreeSqlInit(
166759 167347     Rtree *pRtree, 
166760 167348     sqlite3 *db, 
................................................................................
178903 179491   #define safe_isspace(x) (jsonIsSpace[(unsigned char)x])
178904 179492   
178905 179493   #ifndef SQLITE_AMALGAMATION
178906 179494     /* Unsigned integer types.  These are already defined in the sqliteInt.h,
178907 179495     ** but the definitions need to be repeated for separate compilation. */
178908 179496     typedef sqlite3_uint64 u64;
178909 179497     typedef unsigned int u32;
       179498  +  typedef unsigned short int u16;
178910 179499     typedef unsigned char u8;
178911 179500   #endif
178912 179501   
178913 179502   /* Objects */
178914 179503   typedef struct JsonString JsonString;
178915 179504   typedef struct JsonNode JsonNode;
178916 179505   typedef struct JsonParse JsonParse;
................................................................................
178982 179571     u32 nNode;         /* Number of slots of aNode[] used */
178983 179572     u32 nAlloc;        /* Number of slots of aNode[] allocated */
178984 179573     JsonNode *aNode;   /* Array of nodes containing the parse */
178985 179574     const char *zJson; /* Original JSON string */
178986 179575     u32 *aUp;          /* Index of parent of each node */
178987 179576     u8 oom;            /* Set to true if out of memory */
178988 179577     u8 nErr;           /* Number of errors seen */
       179578  +  u16 iDepth;        /* Nesting depth */
       179579  +  int nJson;         /* Length of the zJson string in bytes */
178989 179580   };
178990 179581   
       179582  +/*
       179583  +** Maximum nesting depth of JSON for this implementation.
       179584  +**
       179585  +** This limit is needed to avoid a stack overflow in the recursive
       179586  +** descent parser.  A depth of 2000 is far deeper than any sane JSON
       179587  +** should go.
       179588  +*/
       179589  +#define JSON_MAX_DEPTH  2000
       179590  +
178991 179591   /**************************************************************************
178992 179592   ** Utility routines for dealing with JsonString objects
178993 179593   **************************************************************************/
178994 179594   
178995 179595   /* Set the JsonString object to an empty string
178996 179596   */
178997 179597   static void jsonZero(JsonString *p){
................................................................................
179214 179814     sqlite3_free(pParse->aNode);
179215 179815     pParse->aNode = 0;
179216 179816     pParse->nNode = 0;
179217 179817     pParse->nAlloc = 0;
179218 179818     sqlite3_free(pParse->aUp);
179219 179819     pParse->aUp = 0;
179220 179820   }
       179821  +
       179822  +/*
       179823  +** Free a JsonParse object that was obtained from sqlite3_malloc().
       179824  +*/
       179825  +static void jsonParseFree(JsonParse *pParse){
       179826  +  jsonParseReset(pParse);
       179827  +  sqlite3_free(pParse);
       179828  +}
179221 179829   
179222 179830   /*
179223 179831   ** Convert the JsonNode pNode into a pure JSON string and
179224 179832   ** append to pOut.  Subsubstructure is also included.  Return
179225 179833   ** the number of JsonNode objects that are encoded.
179226 179834   */
179227 179835   static void jsonRenderNode(
................................................................................
179540 180148   */
179541 180149   static int jsonParseValue(JsonParse *pParse, u32 i){
179542 180150     char c;
179543 180151     u32 j;
179544 180152     int iThis;
179545 180153     int x;
179546 180154     JsonNode *pNode;
179547         -  while( safe_isspace(pParse->zJson[i]) ){ i++; }
179548         -  if( (c = pParse->zJson[i])=='{' ){
       180155  +  const char *z = pParse->zJson;
       180156  +  while( safe_isspace(z[i]) ){ i++; }
       180157  +  if( (c = z[i])=='{' ){
179549 180158       /* Parse object */
179550 180159       iThis = jsonParseAddNode(pParse, JSON_OBJECT, 0, 0);
179551 180160       if( iThis<0 ) return -1;
179552 180161       for(j=i+1;;j++){
179553         -      while( safe_isspace(pParse->zJson[j]) ){ j++; }
       180162  +      while( safe_isspace(z[j]) ){ j++; }
       180163  +      if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
179554 180164         x = jsonParseValue(pParse, j);
179555 180165         if( x<0 ){
       180166  +        pParse->iDepth--;
179556 180167           if( x==(-2) && pParse->nNode==(u32)iThis+1 ) return j+1;
179557 180168           return -1;
179558 180169         }
179559 180170         if( pParse->oom ) return -1;
179560 180171         pNode = &pParse->aNode[pParse->nNode-1];
179561 180172         if( pNode->eType!=JSON_STRING ) return -1;
179562 180173         pNode->jnFlags |= JNODE_LABEL;
179563 180174         j = x;
179564         -      while( safe_isspace(pParse->zJson[j]) ){ j++; }
179565         -      if( pParse->zJson[j]!=':' ) return -1;
       180175  +      while( safe_isspace(z[j]) ){ j++; }
       180176  +      if( z[j]!=':' ) return -1;
179566 180177         j++;
179567 180178         x = jsonParseValue(pParse, j);
       180179  +      pParse->iDepth--;
179568 180180         if( x<0 ) return -1;
179569 180181         j = x;
179570         -      while( safe_isspace(pParse->zJson[j]) ){ j++; }
179571         -      c = pParse->zJson[j];
       180182  +      while( safe_isspace(z[j]) ){ j++; }
       180183  +      c = z[j];
179572 180184         if( c==',' ) continue;
179573 180185         if( c!='}' ) return -1;
179574 180186         break;
179575 180187       }
179576 180188       pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
179577 180189       return j+1;
179578 180190     }else if( c=='[' ){
179579 180191       /* Parse array */
179580 180192       iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0);
179581 180193       if( iThis<0 ) return -1;
179582 180194       for(j=i+1;;j++){
179583         -      while( safe_isspace(pParse->zJson[j]) ){ j++; }
       180195  +      while( safe_isspace(z[j]) ){ j++; }
       180196  +      if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
179584 180197         x = jsonParseValue(pParse, j);
       180198  +      pParse->iDepth--;
179585 180199         if( x<0 ){
179586 180200           if( x==(-3) && pParse->nNode==(u32)iThis+1 ) return j+1;
179587 180201           return -1;
179588 180202         }
179589 180203         j = x;
179590         -      while( safe_isspace(pParse->zJson[j]) ){ j++; }
179591         -      c = pParse->zJson[j];
       180204  +      while( safe_isspace(z[j]) ){ j++; }
       180205  +      c = z[j];
179592 180206         if( c==',' ) continue;
179593 180207         if( c!=']' ) return -1;
179594 180208         break;
179595 180209       }
179596 180210       pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
179597 180211       return j+1;
179598 180212     }else if( c=='"' ){
179599 180213       /* Parse string */
179600 180214       u8 jnFlags = 0;
179601 180215       j = i+1;
179602 180216       for(;;){
179603         -      c = pParse->zJson[j];
179604         -      if( c==0 ) return -1;
       180217  +      c = z[j];
       180218  +      if( (c & ~0x1f)==0 ){
       180219  +        /* Control characters are not allowed in strings */
       180220  +        return -1;
       180221  +      }
179605 180222         if( c=='\\' ){
179606         -        c = pParse->zJson[++j];
       180223  +        c = z[++j];
179607 180224           if( c=='"' || c=='\\' || c=='/' || c=='b' || c=='f'
179608 180225              || c=='n' || c=='r' || c=='t'
179609         -           || (c=='u' && jsonIs4Hex(pParse->zJson+j+1)) ){
       180226  +           || (c=='u' && jsonIs4Hex(z+j+1)) ){
179610 180227             jnFlags = JNODE_ESCAPE;
179611 180228           }else{
179612 180229             return -1;
179613 180230           }
179614 180231         }else if( c=='"' ){
179615 180232           break;
179616 180233         }
179617 180234         j++;
179618 180235       }
179619         -    jsonParseAddNode(pParse, JSON_STRING, j+1-i, &pParse->zJson[i]);
       180236  +    jsonParseAddNode(pParse, JSON_STRING, j+1-i, &z[i]);
179620 180237       if( !pParse->oom ) pParse->aNode[pParse->nNode-1].jnFlags = jnFlags;
179621 180238       return j+1;
179622 180239     }else if( c=='n'
179623         -         && strncmp(pParse->zJson+i,"null",4)==0
179624         -         && !safe_isalnum(pParse->zJson[i+4]) ){
       180240  +         && strncmp(z+i,"null",4)==0
       180241  +         && !safe_isalnum(z[i+4]) ){
179625 180242       jsonParseAddNode(pParse, JSON_NULL, 0, 0);
179626 180243       return i+4;
179627 180244     }else if( c=='t'
179628         -         && strncmp(pParse->zJson+i,"true",4)==0
179629         -         && !safe_isalnum(pParse->zJson[i+4]) ){
       180245  +         && strncmp(z+i,"true",4)==0
       180246  +         && !safe_isalnum(z[i+4]) ){
179630 180247       jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
179631 180248       return i+4;
179632 180249     }else if( c=='f'
179633         -         && strncmp(pParse->zJson+i,"false",5)==0
179634         -         && !safe_isalnum(pParse->zJson[i+5]) ){
       180250  +         && strncmp(z+i,"false",5)==0
       180251  +         && !safe_isalnum(z[i+5]) ){
179635 180252       jsonParseAddNode(pParse, JSON_FALSE, 0, 0);
179636 180253       return i+5;
179637 180254     }else if( c=='-' || (c>='0' && c<='9') ){
179638 180255       /* Parse number */
179639 180256       u8 seenDP = 0;
179640 180257       u8 seenE = 0;
       180258  +    assert( '-' < '0' );
       180259  +    if( c<='0' ){
       180260  +      j = c=='-' ? i+1 : i;
       180261  +      if( z[j]=='0' && z[j+1]>='0' && z[j+1]<='9' ) return -1;
       180262  +    }
179641 180263       j = i+1;
179642 180264       for(;; j++){
179643         -      c = pParse->zJson[j];
       180265  +      c = z[j];
179644 180266         if( c>='0' && c<='9' ) continue;
179645 180267         if( c=='.' ){
179646         -        if( pParse->zJson[j-1]=='-' ) return -1;
       180268  +        if( z[j-1]=='-' ) return -1;
179647 180269           if( seenDP ) return -1;
179648 180270           seenDP = 1;
179649 180271           continue;
179650 180272         }
179651 180273         if( c=='e' || c=='E' ){
179652         -        if( pParse->zJson[j-1]<'0' ) return -1;
       180274  +        if( z[j-1]<'0' ) return -1;
179653 180275           if( seenE ) return -1;
179654 180276           seenDP = seenE = 1;
179655         -        c = pParse->zJson[j+1];
       180277  +        c = z[j+1];
179656 180278           if( c=='+' || c=='-' ){
179657 180279             j++;
179658         -          c = pParse->zJson[j+1];
       180280  +          c = z[j+1];
179659 180281           }
179660 180282           if( c<'0' || c>'9' ) return -1;
179661 180283           continue;
179662 180284         }
179663 180285         break;
179664 180286       }
179665         -    if( pParse->zJson[j-1]<'0' ) return -1;
       180287  +    if( z[j-1]<'0' ) return -1;
179666 180288       jsonParseAddNode(pParse, seenDP ? JSON_REAL : JSON_INT,
179667         -                        j - i, &pParse->zJson[i]);
       180289  +                        j - i, &z[i]);
179668 180290       return j;
179669 180291     }else if( c=='}' ){
179670 180292       return -2;  /* End of {...} */
179671 180293     }else if( c==']' ){
179672 180294       return -3;  /* End of [...] */
179673 180295     }else if( c==0 ){
179674 180296       return 0;   /* End of file */
................................................................................
179692 180314     int i;
179693 180315     memset(pParse, 0, sizeof(*pParse));
179694 180316     if( zJson==0 ) return 1;
179695 180317     pParse->zJson = zJson;
179696 180318     i = jsonParseValue(pParse, 0);
179697 180319     if( pParse->oom ) i = -1;
179698 180320     if( i>0 ){
       180321  +    assert( pParse->iDepth==0 );
179699 180322       while( safe_isspace(zJson[i]) ) i++;
179700 180323       if( zJson[i] ) i = -1;
179701 180324     }
179702 180325     if( i<=0 ){
179703 180326       if( pCtx!=0 ){
179704 180327         if( pParse->oom ){
179705 180328           sqlite3_result_error_nomem(pCtx);
................................................................................
179750 180373     if( aUp==0 ){
179751 180374       pParse->oom = 1;
179752 180375       return SQLITE_NOMEM;
179753 180376     }
179754 180377     jsonParseFillInParentage(pParse, 0, 0);
179755 180378     return SQLITE_OK;
179756 180379   }
       180380  +
       180381  +/*
       180382  +** Magic number used for the JSON parse cache in sqlite3_get_auxdata()
       180383  +*/
       180384  +#define JSON_CACHE_ID  (-429938)
       180385  +
       180386  +/*
       180387  +** Obtain a complete parse of the JSON found in the first argument
       180388  +** of the argv array.  Use the sqlite3_get_auxdata() cache for this
       180389  +** parse if it is available.  If the cache is not available or if it
       180390  +** is no longer valid, parse the JSON again and return the new parse,
       180391  +** and also register the new parse so that it will be available for
       180392  +** future sqlite3_get_auxdata() calls.
       180393  +*/
       180394  +static JsonParse *jsonParseCached(
       180395  +  sqlite3_context *pCtx,
       180396  +  sqlite3_value **argv
       180397  +){
       180398  +  const char *zJson = (const char*)sqlite3_value_text(argv[0]);
       180399  +  int nJson = sqlite3_value_bytes(argv[0]);
       180400  +  JsonParse *p;
       180401  +  if( zJson==0 ) return 0;
       180402  +  p = (JsonParse*)sqlite3_get_auxdata(pCtx, JSON_CACHE_ID);
       180403  +  if( p && p->nJson==nJson && memcmp(p->zJson,zJson,nJson)==0 ){
       180404  +    p->nErr = 0;
       180405  +    return p; /* The cached entry matches, so return it */
       180406  +  }
       180407  +  p = sqlite3_malloc( sizeof(*p) + nJson + 1 );
       180408  +  if( p==0 ){
       180409  +    sqlite3_result_error_nomem(pCtx);
       180410  +    return 0;
       180411  +  }
       180412  +  memset(p, 0, sizeof(*p));
       180413  +  p->zJson = (char*)&p[1];
       180414  +  memcpy((char*)p->zJson, zJson, nJson+1);
       180415  +  if( jsonParse(p, pCtx, p->zJson) ){
       180416  +    sqlite3_free(p);
       180417  +    return 0;
       180418  +  }
       180419  +  p->nJson = nJson;
       180420  +  sqlite3_set_auxdata(pCtx, JSON_CACHE_ID, p, (void(*)(void*))jsonParseFree);
       180421  +  return (JsonParse*)sqlite3_get_auxdata(pCtx, JSON_CACHE_ID);
       180422  +}
179757 180423   
179758 180424   /*
179759 180425   ** Compare the OBJECT label at pNode against zKey,nKey.  Return true on
179760 180426   ** a match.
179761 180427   */
179762 180428   static int jsonLabelCompare(JsonNode *pNode, const char *zKey, u32 nKey){
179763 180429     if( pNode->jnFlags & JNODE_RAW ){
................................................................................
180116 180782   ** Return 0 if the input is not a well-formed JSON array.
180117 180783   */
180118 180784   static void jsonArrayLengthFunc(
180119 180785     sqlite3_context *ctx,
180120 180786     int argc,
180121 180787     sqlite3_value **argv
180122 180788   ){
180123         -  JsonParse x;          /* The parse */
       180789  +  JsonParse *p;          /* The parse */
180124 180790     sqlite3_int64 n = 0;
180125 180791     u32 i;
180126 180792     JsonNode *pNode;
180127 180793   
180128         -  if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return;
180129         -  assert( x.nNode );
       180794  +  p = jsonParseCached(ctx, argv);
       180795  +  if( p==0 ) return;
       180796  +  assert( p->nNode );
180130 180797     if( argc==2 ){
180131 180798       const char *zPath = (const char*)sqlite3_value_text(argv[1]);
180132         -    pNode = jsonLookup(&x, zPath, 0, ctx);
       180799  +    pNode = jsonLookup(p, zPath, 0, ctx);
180133 180800     }else{
180134         -    pNode = x.aNode;
       180801  +    pNode = p->aNode;
180135 180802     }
180136 180803     if( pNode==0 ){
180137         -    x.nErr = 1;
180138         -  }else if( pNode->eType==JSON_ARRAY ){
       180804  +    return;
       180805  +  }
       180806  +  if( pNode->eType==JSON_ARRAY ){
180139 180807       assert( (pNode->jnFlags & JNODE_APPEND)==0 );
180140 180808       for(i=1; i<=pNode->n; n++){
180141 180809         i += jsonNodeSize(&pNode[i]);
180142 180810       }
180143 180811     }
180144         -  if( x.nErr==0 ) sqlite3_result_int64(ctx, n);
180145         -  jsonParseReset(&x);
       180812  +  sqlite3_result_int64(ctx, n);
180146 180813   }
180147 180814   
180148 180815   /*
180149 180816   ** json_extract(JSON, PATH, ...)
180150 180817   **
180151 180818   ** Return the element described by PATH.  Return NULL if there is no
180152 180819   ** PATH element.  If there are multiple PATHs, then return a JSON array
................................................................................
180154 180821   ** is malformed.
180155 180822   */
180156 180823   static void jsonExtractFunc(
180157 180824     sqlite3_context *ctx,
180158 180825     int argc,
180159 180826     sqlite3_value **argv
180160 180827   ){
180161         -  JsonParse x;          /* The parse */
       180828  +  JsonParse *p;          /* The parse */
180162 180829     JsonNode *pNode;
180163 180830     const char *zPath;
180164 180831     JsonString jx;
180165 180832     int i;
180166 180833   
180167 180834     if( argc<2 ) return;
180168         -  if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return;
       180835  +  p = jsonParseCached(ctx, argv);
       180836  +  if( p==0 ) return;
180169 180837     jsonInit(&jx, ctx);
180170 180838     jsonAppendChar(&jx, '[');
180171 180839     for(i=1; i<argc; i++){
180172 180840       zPath = (const char*)sqlite3_value_text(argv[i]);
180173         -    pNode = jsonLookup(&x, zPath, 0, ctx);
180174         -    if( x.nErr ) break;
       180841  +    pNode = jsonLookup(p, zPath, 0, ctx);
       180842  +    if( p->nErr ) break;
180175 180843       if( argc>2 ){
180176 180844         jsonAppendSeparator(&jx);
180177 180845         if( pNode ){
180178 180846           jsonRenderNode(pNode, &jx, 0);
180179 180847         }else{
180180 180848           jsonAppendRaw(&jx, "null", 4);
180181 180849         }
................................................................................
180185 180853     }
180186 180854     if( argc>2 && i==argc ){
180187 180855       jsonAppendChar(&jx, ']');
180188 180856       jsonResult(&jx);
180189 180857       sqlite3_result_subtype(ctx, JSON_SUBTYPE);
180190 180858     }
180191 180859     jsonReset(&jx);
180192         -  jsonParseReset(&x);
180193 180860   }
180194 180861   
180195 180862   /* This is the RFC 7396 MergePatch algorithm.
180196 180863   */
180197 180864   static JsonNode *jsonMergePatch(
180198 180865     JsonParse *pParse,   /* The JSON parser that contains the TARGET */
180199         -  int iTarget,         /* Node of the TARGET in pParse */
       180866  +  u32 iTarget,         /* Node of the TARGET in pParse */
180200 180867     JsonNode *pPatch     /* The PATCH */
180201 180868   ){
180202 180869     u32 i, j;
180203 180870     u32 iRoot;
180204 180871     JsonNode *pTarget;
180205 180872     if( pPatch->eType!=JSON_OBJECT ){
180206 180873       return pPatch;
................................................................................
182201 182868     Fts5Index *p,                   /* Index to write to */
182202 182869     int bDelete,                    /* True if current operation is a delete */
182203 182870     i64 iDocid                      /* Docid to add or remove data from */
182204 182871   );
182205 182872   
182206 182873   /*
182207 182874   ** Flush any data stored in the in-memory hash tables to the database.
182208         -** If the bCommit flag is true, also close any open blob handles.
       182875  +** Also close any open blob handles.
182209 182876   */
182210         -static int sqlite3Fts5IndexSync(Fts5Index *p, int bCommit);
       182877  +static int sqlite3Fts5IndexSync(Fts5Index *p);
182211 182878   
182212 182879   /*
182213 182880   ** Discard any data stored in the in-memory hash tables. Do not write it
182214 182881   ** to the database. Additionally, assume that the contents of the %_data
182215 182882   ** table may have changed on disk. So any in-memory caches of %_data 
182216 182883   ** records must be invalidated.
182217 182884   */
................................................................................
182373 183040   static int sqlite3Fts5StorageStmt(Fts5Storage *p, int eStmt, sqlite3_stmt**, char**);
182374 183041   static void sqlite3Fts5StorageStmtRelease(Fts5Storage *p, int eStmt, sqlite3_stmt*);
182375 183042   
182376 183043   static int sqlite3Fts5StorageDocsize(Fts5Storage *p, i64 iRowid, int *aCol);
182377 183044   static int sqlite3Fts5StorageSize(Fts5Storage *p, int iCol, i64 *pnAvg);
182378 183045   static int sqlite3Fts5StorageRowCount(Fts5Storage *p, i64 *pnRow);
182379 183046   
182380         -static int sqlite3Fts5StorageSync(Fts5Storage *p, int bCommit);
       183047  +static int sqlite3Fts5StorageSync(Fts5Storage *p);
182381 183048   static int sqlite3Fts5StorageRollback(Fts5Storage *p);
182382 183049   
182383 183050   static int sqlite3Fts5StorageConfigValue(
182384 183051       Fts5Storage *p, const char*, sqlite3_value*, int
182385 183052   );
182386 183053   
182387 183054   static int sqlite3Fts5StorageDeleteAll(Fts5Storage *p);
................................................................................
182409 183076     const char *p;                  /* Token text (not NULL terminated) */
182410 183077     int n;                          /* Size of buffer p in bytes */
182411 183078   };
182412 183079   
182413 183080   /* Parse a MATCH expression. */
182414 183081   static int sqlite3Fts5ExprNew(
182415 183082     Fts5Config *pConfig, 
       183083  +  int iCol,                       /* Column on LHS of MATCH operator */
182416 183084     const char *zExpr,
182417 183085     Fts5Expr **ppNew, 
182418 183086     char **pzErr
182419 183087   );
182420 183088   
182421 183089   /*
182422 183090   ** for(rc = sqlite3Fts5ExprFirst(pExpr, pIdx, bDesc);
................................................................................
182493 183161   );
182494 183162   
182495 183163   static void sqlite3Fts5ParsePhraseFree(Fts5ExprPhrase*);
182496 183164   static void sqlite3Fts5ParseNearsetFree(Fts5ExprNearset*);
182497 183165   static void sqlite3Fts5ParseNodeFree(Fts5ExprNode*);
182498 183166   
182499 183167   static void sqlite3Fts5ParseSetDistance(Fts5Parse*, Fts5ExprNearset*, Fts5Token*);
182500         -static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNearset*, Fts5Colset*);
       183168  +static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNode*, Fts5Colset*);
182501 183169   static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse*, Fts5Colset*);
182502 183170   static void sqlite3Fts5ParseFinished(Fts5Parse *pParse, Fts5ExprNode *p);
182503 183171   static void sqlite3Fts5ParseNear(Fts5Parse *pParse, Fts5Token*);
182504 183172   
182505 183173   /*
182506 183174   ** End of interface to code in fts5_expr.c.
182507 183175   **************************************************************************/
................................................................................
182550 183218   #endif
182551 183219   
182552 183220   #define FTS5_OR                               1
182553 183221   #define FTS5_AND                              2
182554 183222   #define FTS5_NOT                              3
182555 183223   #define FTS5_TERM                             4
182556 183224   #define FTS5_COLON                            5
182557         -#define FTS5_LP                               6
182558         -#define FTS5_RP                               7
182559         -#define FTS5_MINUS                            8
182560         -#define FTS5_LCP                              9
182561         -#define FTS5_RCP                             10
182562         -#define FTS5_STRING                          11
       183225  +#define FTS5_MINUS                            6
       183226  +#define FTS5_LCP                              7
       183227  +#define FTS5_RCP                              8
       183228  +#define FTS5_STRING                           9
       183229  +#define FTS5_LP                              10
       183230  +#define FTS5_RP                              11
182563 183231   #define FTS5_COMMA                           12
182564 183232   #define FTS5_PLUS                            13
182565 183233   #define FTS5_STAR                            14
182566 183234   
182567 183235   /*
182568 183236   ** 2000-05-29
182569 183237   **
................................................................................
182691 183359   #ifndef fts5YYSTACKDEPTH
182692 183360   #define fts5YYSTACKDEPTH 100
182693 183361   #endif
182694 183362   #define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
182695 183363   #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
182696 183364   #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
182697 183365   #define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
182698         -#define fts5YYNSTATE             29
182699         -#define fts5YYNRULE              26
182700         -#define fts5YY_MAX_SHIFT         28
182701         -#define fts5YY_MIN_SHIFTREDUCE   45
182702         -#define fts5YY_MAX_SHIFTREDUCE   70
182703         -#define fts5YY_MIN_REDUCE        71
182704         -#define fts5YY_MAX_REDUCE        96
182705         -#define fts5YY_ERROR_ACTION      97
182706         -#define fts5YY_ACCEPT_ACTION     98
182707         -#define fts5YY_NO_ACTION         99
       183366  +#define fts5YYNSTATE             33
       183367  +#define fts5YYNRULE              27
       183368  +#define fts5YY_MAX_SHIFT         32
       183369  +#define fts5YY_MIN_SHIFTREDUCE   50
       183370  +#define fts5YY_MAX_SHIFTREDUCE   76
       183371  +#define fts5YY_MIN_REDUCE        77
       183372  +#define fts5YY_MAX_REDUCE        103
       183373  +#define fts5YY_ERROR_ACTION      104
       183374  +#define fts5YY_ACCEPT_ACTION     105
       183375  +#define fts5YY_NO_ACTION         106
182708 183376   /************* End control #defines *******************************************/
182709 183377   
182710 183378   /* Define the fts5yytestcase() macro to be a no-op if is not already defined
182711 183379   ** otherwise.
182712 183380   **
182713 183381   ** Applications can choose to define fts5yytestcase() in the %include section
182714 183382   ** to a macro that can assist in verifying code coverage.  For production
................................................................................
182772 183440   **  fts5yy_shift_ofst[]    For each state, the offset into fts5yy_action for
182773 183441   **                     shifting terminals.
182774 183442   **  fts5yy_reduce_ofst[]   For each state, the offset into fts5yy_action for
182775 183443   **                     shifting non-terminals after a reduce.
182776 183444   **  fts5yy_default[]       Default action for each state.
182777 183445   **
182778 183446   *********** Begin parsing tables **********************************************/
182779         -#define fts5YY_ACTTAB_COUNT (85)
       183447  +#define fts5YY_ACTTAB_COUNT (98)
182780 183448   static const fts5YYACTIONTYPE fts5yy_action[] = {
182781         - /*     0 */    98,   16,   51,    5,   53,   27,   83,    7,   26,   15,
182782         - /*    10 */    51,    5,   53,   27,   13,   69,   26,   48,   51,    5,
182783         - /*    20 */    53,   27,   19,   11,   26,    9,   20,   51,    5,   53,
182784         - /*    30 */    27,   13,   22,   26,   28,   51,    5,   53,   27,   68,
182785         - /*    40 */     1,   26,   19,   11,   17,    9,   52,   10,   53,   27,
182786         - /*    50 */    23,   24,   26,   54,    3,    4,    2,   26,    6,   21,
182787         - /*    60 */    49,   71,    3,    4,    2,    7,   56,   59,   55,   59,
182788         - /*    70 */     4,    2,   12,   69,   58,   60,   18,   67,   62,   69,
182789         - /*    80 */    25,   66,    8,   14,    2,
       183449  + /*     0 */   105,   19,   63,    6,   26,   66,   65,   24,   24,   17,
       183450  + /*    10 */    63,    6,   26,   16,   65,   54,   24,   18,   63,    6,
       183451  + /*    20 */    26,   10,   65,   12,   24,   75,   59,   63,    6,   26,
       183452  + /*    30 */    13,   65,   75,   24,   20,   63,    6,   26,   74,   65,
       183453  + /*    40 */    56,   24,   27,   63,    6,   26,   73,   65,   21,   24,
       183454  + /*    50 */    23,   15,   30,   11,    1,   64,   22,   25,    9,   65,
       183455  + /*    60 */     7,   24,    3,    4,    5,    3,    4,    5,    3,   77,
       183456  + /*    70 */     4,    5,    3,   61,   23,   15,   60,   11,   80,   12,
       183457  + /*    80 */     2,   13,   68,   10,   29,   52,   55,   75,   31,   32,
       183458  + /*    90 */     8,   28,    5,    3,   51,   55,   72,   14,
182790 183459   };
182791 183460   static const fts5YYCODETYPE fts5yy_lookahead[] = {
182792         - /*     0 */    16,   17,   18,   19,   20,   21,    5,    6,   24,   17,
182793         - /*    10 */    18,   19,   20,   21,   11,   14,   24,   17,   18,   19,
182794         - /*    20 */    20,   21,    8,    9,   24,   11,   17,   18,   19,   20,
182795         - /*    30 */    21,   11,   12,   24,   17,   18,   19,   20,   21,   26,
182796         - /*    40 */     6,   24,    8,    9,   22,   11,   18,   11,   20,   21,
182797         - /*    50 */    24,   25,   24,   20,    1,    2,    3,   24,   23,   24,
182798         - /*    60 */     7,    0,    1,    2,    3,    6,   10,   11,   10,   11,
182799         - /*    70 */     2,    3,    9,   14,   11,   11,   22,   26,    7,   14,
182800         - /*    80 */    13,   11,    5,   11,    3,
       183461  + /*     0 */    16,   17,   18,   19,   20,   22,   22,   24,   24,   17,
       183462  + /*    10 */    18,   19,   20,    7,   22,    9,   24,   17,   18,   19,
       183463  + /*    20 */    20,   10,   22,    9,   24,   14,   17,   18,   19,   20,
       183464  + /*    30 */     9,   22,   14,   24,   17,   18,   19,   20,   26,   22,
       183465  + /*    40 */     9,   24,   17,   18,   19,   20,   26,   22,   21,   24,
       183466  + /*    50 */     6,    7,   13,    9,   10,   18,   21,   20,    5,   22,
       183467  + /*    60 */     5,   24,    3,    1,    2,    3,    1,    2,    3,    0,
       183468  + /*    70 */     1,    2,    3,   11,    6,    7,   11,    9,    5,    9,
       183469  + /*    80 */    10,    9,   11,   10,   12,    8,    9,   14,   24,   25,
       183470  + /*    90 */    23,   24,    2,    3,    8,    9,    9,    9,
182801 183471   };
182802         -#define fts5YY_SHIFT_USE_DFLT (85)
182803         -#define fts5YY_SHIFT_COUNT    (28)
       183472  +#define fts5YY_SHIFT_USE_DFLT (98)
       183473  +#define fts5YY_SHIFT_COUNT    (32)
182804 183474   #define fts5YY_SHIFT_MIN      (0)
182805         -#define fts5YY_SHIFT_MAX      (81)
       183475  +#define fts5YY_SHIFT_MAX      (90)
182806 183476   static const unsigned char fts5yy_shift_ofst[] = {
182807         - /*     0 */    34,   34,   34,   34,   34,   14,   20,    3,   36,    1,
182808         - /*    10 */    59,   64,   64,   65,   65,   53,   61,   56,   58,   63,
182809         - /*    20 */    68,   67,   70,   67,   71,   72,   67,   77,   81,
       183477  + /*     0 */    44,   44,   44,   44,   44,   44,   68,   70,   72,   14,
       183478  + /*    10 */    21,   73,   11,   18,   18,   31,   31,   62,   65,   69,
       183479  + /*    20 */    90,   77,   86,    6,   39,   53,   55,   59,   39,   87,
       183480  + /*    30 */    88,   39,   71,
182810 183481   };
182811         -#define fts5YY_REDUCE_USE_DFLT (-17)
182812         -#define fts5YY_REDUCE_COUNT (14)
182813         -#define fts5YY_REDUCE_MIN   (-16)
182814         -#define fts5YY_REDUCE_MAX   (54)
       183482  +#define fts5YY_REDUCE_USE_DFLT (-18)
       183483  +#define fts5YY_REDUCE_COUNT (16)
       183484  +#define fts5YY_REDUCE_MIN   (-17)
       183485  +#define fts5YY_REDUCE_MAX   (67)
182815 183486   static const signed char fts5yy_reduce_ofst[] = {
182816         - /*     0 */   -16,   -8,    0,    9,   17,   28,   26,   35,   33,   13,
182817         - /*    10 */    13,   22,   54,   13,   51,
       183487  + /*     0 */   -16,   -8,    0,    9,   17,   25,   37,  -17,   64,  -17,
       183488  + /*    10 */    67,   12,   12,   12,   20,   27,   35,
182818 183489   };
182819 183490   static const fts5YYACTIONTYPE fts5yy_default[] = {
182820         - /*     0 */    97,   97,   97,   97,   97,   76,   91,   97,   97,   96,
182821         - /*    10 */    96,   97,   97,   96,   96,   97,   97,   97,   97,   97,
182822         - /*    20 */    73,   89,   97,   90,   97,   97,   87,   97,   72,
       183491  + /*     0 */   104,  104,  104,  104,  104,  104,   89,  104,   98,  104,
       183492  + /*    10 */   104,  103,  103,  103,  103,  104,  104,  104,  104,  104,
       183493  + /*    20 */    85,  104,  104,  104,   94,  104,  104,   84,   96,  104,
       183494  + /*    30 */   104,   97,  104,
182823 183495   };
182824 183496   /********** End of lemon-generated parsing tables *****************************/
182825 183497   
182826 183498   /* The next table maps tokens (terminal symbols) into fallback tokens.  
182827 183499   ** If a construct like the following:
182828 183500   ** 
182829 183501   **      %fallback ID X Y Z.
................................................................................
182921 183593   #endif /* NDEBUG */
182922 183594   
182923 183595   #ifndef NDEBUG
182924 183596   /* For tracing shifts, the names of all terminals and nonterminals
182925 183597   ** are required.  The following table supplies these names */
182926 183598   static const char *const fts5yyTokenName[] = { 
182927 183599     "$",             "OR",            "AND",           "NOT",         
182928         -  "TERM",          "COLON",         "LP",            "RP",          
182929         -  "MINUS",         "LCP",           "RCP",           "STRING",      
       183600  +  "TERM",          "COLON",         "MINUS",         "LCP",         
       183601  +  "RCP",           "STRING",        "LP",            "RP",          
182930 183602     "COMMA",         "PLUS",          "STAR",          "error",       
182931 183603     "input",         "expr",          "cnearset",      "exprlist",    
182932         -  "nearset",       "colset",        "colsetlist",    "nearphrases", 
       183604  +  "colset",        "colsetlist",    "nearset",       "nearphrases", 
182933 183605     "phrase",        "neardist_opt",  "star_opt",    
182934 183606   };
182935 183607   #endif /* NDEBUG */
182936 183608   
182937 183609   #ifndef NDEBUG
182938 183610   /* For tracing reduce actions, the names of all rules are required.
182939 183611   */
182940 183612   static const char *const fts5yyRuleName[] = {
182941 183613    /*   0 */ "input ::= expr",
182942         - /*   1 */ "expr ::= expr AND expr",
182943         - /*   2 */ "expr ::= expr OR expr",
182944         - /*   3 */ "expr ::= expr NOT expr",
182945         - /*   4 */ "expr ::= LP expr RP",
182946         - /*   5 */ "expr ::= exprlist",
182947         - /*   6 */ "exprlist ::= cnearset",
182948         - /*   7 */ "exprlist ::= exprlist cnearset",
182949         - /*   8 */ "cnearset ::= nearset",
182950         - /*   9 */ "cnearset ::= colset COLON nearset",
182951         - /*  10 */ "colset ::= MINUS LCP colsetlist RCP",
182952         - /*  11 */ "colset ::= LCP colsetlist RCP",
182953         - /*  12 */ "colset ::= STRING",
182954         - /*  13 */ "colset ::= MINUS STRING",
182955         - /*  14 */ "colsetlist ::= colsetlist STRING",
182956         - /*  15 */ "colsetlist ::= STRING",
182957         - /*  16 */ "nearset ::= phrase",
182958         - /*  17 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
182959         - /*  18 */ "nearphrases ::= phrase",
182960         - /*  19 */ "nearphrases ::= nearphrases phrase",
182961         - /*  20 */ "neardist_opt ::=",
182962         - /*  21 */ "neardist_opt ::= COMMA STRING",
182963         - /*  22 */ "phrase ::= phrase PLUS STRING star_opt",
182964         - /*  23 */ "phrase ::= STRING star_opt",
182965         - /*  24 */ "star_opt ::= STAR",
182966         - /*  25 */ "star_opt ::=",
       183614  + /*   1 */ "colset ::= MINUS LCP colsetlist RCP",
       183615  + /*   2 */ "colset ::= LCP colsetlist RCP",
       183616  + /*   3 */ "colset ::= STRING",
       183617  + /*   4 */ "colset ::= MINUS STRING",
       183618  + /*   5 */ "colsetlist ::= colsetlist STRING",
       183619  + /*   6 */ "colsetlist ::= STRING",
       183620  + /*   7 */ "expr ::= expr AND expr",
       183621  + /*   8 */ "expr ::= expr OR expr",
       183622  + /*   9 */ "expr ::= expr NOT expr",
       183623  + /*  10 */ "expr ::= colset COLON LP expr RP",
       183624  + /*  11 */ "expr ::= LP expr RP",
       183625  + /*  12 */ "expr ::= exprlist",
       183626  + /*  13 */ "exprlist ::= cnearset",
       183627  + /*  14 */ "exprlist ::= exprlist cnearset",
       183628  + /*  15 */ "cnearset ::= nearset",
       183629  + /*  16 */ "cnearset ::= colset COLON nearset",
       183630  + /*  17 */ "nearset ::= phrase",
       183631  + /*  18 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
       183632  + /*  19 */ "nearphrases ::= phrase",
       183633  + /*  20 */ "nearphrases ::= nearphrases phrase",
       183634  + /*  21 */ "neardist_opt ::=",
       183635  + /*  22 */ "neardist_opt ::= COMMA STRING",
       183636  + /*  23 */ "phrase ::= phrase PLUS STRING star_opt",
       183637  + /*  24 */ "phrase ::= STRING star_opt",
       183638  + /*  25 */ "star_opt ::= STAR",
       183639  + /*  26 */ "star_opt ::=",
182967 183640   };
182968 183641   #endif /* NDEBUG */
182969 183642   
182970 183643   
182971 183644   #if fts5YYSTACKDEPTH<=0
182972 183645   /*
182973 183646   ** Try to increase the size of the parser stack.  Return the number
................................................................................
183089 183762       case 17: /* expr */
183090 183763       case 18: /* cnearset */
183091 183764       case 19: /* exprlist */
183092 183765   {
183093 183766    sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy24)); 
183094 183767   }
183095 183768         break;
183096         -    case 20: /* nearset */
       183769  +    case 20: /* colset */
       183770  +    case 21: /* colsetlist */
       183771  +{
       183772  + sqlite3_free((fts5yypminor->fts5yy11)); 
       183773  +}
       183774  +      break;
       183775  +    case 22: /* nearset */
183097 183776       case 23: /* nearphrases */
183098 183777   {
183099 183778    sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy46)); 
183100 183779   }
183101         -      break;
183102         -    case 21: /* colset */
183103         -    case 22: /* colsetlist */
183104         -{
183105         - sqlite3_free((fts5yypminor->fts5yy11)); 
183106         -}
183107 183780         break;
183108 183781       case 24: /* phrase */
183109 183782   {
183110 183783    sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy53)); 
183111 183784   }
183112 183785         break;
183113 183786   /********* End destructor definitions *****************************************/
................................................................................
183358 184031   ** is used during the reduce.
183359 184032   */
183360 184033   static const struct {
183361 184034     fts5YYCODETYPE lhs;         /* Symbol on the left-hand side of the rule */
183362 184035     unsigned char nrhs;     /* Number of right-hand side symbols in the rule */
183363 184036   } fts5yyRuleInfo[] = {
183364 184037     { 16, 1 },
       184038  +  { 20, 4 },
       184039  +  { 20, 3 },
       184040  +  { 20, 1 },
       184041  +  { 20, 2 },
       184042  +  { 21, 2 },
       184043  +  { 21, 1 },
183365 184044     { 17, 3 },
183366 184045     { 17, 3 },
183367 184046     { 17, 3 },
       184047  +  { 17, 5 },
183368 184048     { 17, 3 },
183369 184049     { 17, 1 },
183370 184050     { 19, 1 },
183371 184051     { 19, 2 },
183372 184052     { 18, 1 },
183373 184053     { 18, 3 },
183374         -  { 21, 4 },
183375         -  { 21, 3 },
183376         -  { 21, 1 },
183377         -  { 21, 2 },
183378         -  { 22, 2 },
183379 184054     { 22, 1 },
183380         -  { 20, 1 },
183381         -  { 20, 5 },
       184055  +  { 22, 5 },
183382 184056     { 23, 1 },
183383 184057     { 23, 2 },
183384 184058     { 25, 0 },
183385 184059     { 25, 2 },
183386 184060     { 24, 4 },
183387 184061     { 24, 2 },
183388 184062     { 26, 1 },
................................................................................
183449 184123     **     break;
183450 184124     */
183451 184125   /********** Begin reduce actions **********************************************/
183452 184126           fts5YYMINORTYPE fts5yylhsminor;
183453 184127         case 0: /* input ::= expr */
183454 184128   { sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); }
183455 184129           break;
183456         -      case 1: /* expr ::= expr AND expr */
       184130  +      case 1: /* colset ::= MINUS LCP colsetlist RCP */
       184131  +{ 
       184132  +    fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
       184133  +}
       184134  +        break;
       184135  +      case 2: /* colset ::= LCP colsetlist RCP */
       184136  +{ fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; }
       184137  +        break;
       184138  +      case 3: /* colset ::= STRING */
       184139  +{
       184140  +  fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
       184141  +}
       184142  +  fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
       184143  +        break;
       184144  +      case 4: /* colset ::= MINUS STRING */
       184145  +{
       184146  +  fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
       184147  +  fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
       184148  +}
       184149  +        break;
       184150  +      case 5: /* colsetlist ::= colsetlist STRING */
       184151  +{ 
       184152  +  fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
       184153  +  fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
       184154  +        break;
       184155  +      case 6: /* colsetlist ::= STRING */
       184156  +{ 
       184157  +  fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0); 
       184158  +}
       184159  +  fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
       184160  +        break;
       184161  +      case 7: /* expr ::= expr AND expr */
183457 184162   {
183458 184163     fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
183459 184164   }
183460 184165     fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183461 184166           break;
183462         -      case 2: /* expr ::= expr OR expr */
       184167  +      case 8: /* expr ::= expr OR expr */
183463 184168   {
183464 184169     fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
183465 184170   }
183466 184171     fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183467 184172           break;
183468         -      case 3: /* expr ::= expr NOT expr */
       184173  +      case 9: /* expr ::= expr NOT expr */
183469 184174   {
183470 184175     fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
183471 184176   }
183472 184177     fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183473 184178           break;
183474         -      case 4: /* expr ::= LP expr RP */
       184179  +      case 10: /* expr ::= colset COLON LP expr RP */
       184180  +{
       184181  +  sqlite3Fts5ParseSetColset(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[-4].minor.fts5yy11);
       184182  +  fts5yylhsminor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;
       184183  +}
       184184  +  fts5yymsp[-4].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
       184185  +        break;
       184186  +      case 11: /* expr ::= LP expr RP */
183475 184187   {fts5yymsp[-2].minor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;}
183476 184188           break;
183477         -      case 5: /* expr ::= exprlist */
183478         -      case 6: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==6);
       184189  +      case 12: /* expr ::= exprlist */
       184190  +      case 13: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==13);
183479 184191   {fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;}
183480 184192     fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183481 184193           break;
183482         -      case 7: /* exprlist ::= exprlist cnearset */
       184194  +      case 14: /* exprlist ::= exprlist cnearset */
183483 184195   {
183484 184196     fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24);
183485 184197   }
183486 184198     fts5yymsp[-1].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183487 184199           break;
183488         -      case 8: /* cnearset ::= nearset */
       184200  +      case 15: /* cnearset ::= nearset */
183489 184201   { 
183490 184202     fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46); 
183491 184203   }
183492 184204     fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183493 184205           break;
183494         -      case 9: /* cnearset ::= colset COLON nearset */
       184206  +      case 16: /* cnearset ::= colset COLON nearset */
183495 184207   { 
183496         -  sqlite3Fts5ParseSetColset(pParse, fts5yymsp[0].minor.fts5yy46, fts5yymsp[-2].minor.fts5yy11);
183497 184208     fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46); 
       184209  +  sqlite3Fts5ParseSetColset(pParse, fts5yylhsminor.fts5yy24, fts5yymsp[-2].minor.fts5yy11);
183498 184210   }
183499 184211     fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183500 184212           break;
183501         -      case 10: /* colset ::= MINUS LCP colsetlist RCP */
183502         -{ 
183503         -    fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
183504         -}
183505         -        break;
183506         -      case 11: /* colset ::= LCP colsetlist RCP */
183507         -{ fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; }
183508         -        break;
183509         -      case 12: /* colset ::= STRING */
183510         -{
183511         -  fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
183512         -}
183513         -  fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
183514         -        break;
183515         -      case 13: /* colset ::= MINUS STRING */
183516         -{
183517         -  fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
183518         -  fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
183519         -}
183520         -        break;
183521         -      case 14: /* colsetlist ::= colsetlist STRING */
183522         -{ 
183523         -  fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
183524         -  fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
183525         -        break;
183526         -      case 15: /* colsetlist ::= STRING */
183527         -{ 
183528         -  fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0); 
183529         -}
183530         -  fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
183531         -        break;
183532         -      case 16: /* nearset ::= phrase */
       184213  +      case 17: /* nearset ::= phrase */
183533 184214   { fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); }
183534 184215     fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
183535 184216           break;
183536         -      case 17: /* nearset ::= STRING LP nearphrases neardist_opt RP */
       184217  +      case 18: /* nearset ::= STRING LP nearphrases neardist_opt RP */
183537 184218   {
183538 184219     sqlite3Fts5ParseNear(pParse, &fts5yymsp[-4].minor.fts5yy0);
183539 184220     sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy46, &fts5yymsp[-1].minor.fts5yy0);
183540 184221     fts5yylhsminor.fts5yy46 = fts5yymsp[-2].minor.fts5yy46;
183541 184222   }
183542 184223     fts5yymsp[-4].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
183543 184224           break;
183544         -      case 18: /* nearphrases ::= phrase */
       184225  +      case 19: /* nearphrases ::= phrase */
183545 184226   { 
183546 184227     fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); 
183547 184228   }
183548 184229     fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
183549 184230           break;
183550         -      case 19: /* nearphrases ::= nearphrases phrase */
       184231  +      case 20: /* nearphrases ::= nearphrases phrase */
183551 184232   {
183552 184233     fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy46, fts5yymsp[0].minor.fts5yy53);
183553 184234   }
183554 184235     fts5yymsp[-1].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
183555 184236           break;
183556         -      case 20: /* neardist_opt ::= */
       184237  +      case 21: /* neardist_opt ::= */
183557 184238   { fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
183558 184239           break;
183559         -      case 21: /* neardist_opt ::= COMMA STRING */
       184240  +      case 22: /* neardist_opt ::= COMMA STRING */
183560 184241   { fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
183561 184242           break;
183562         -      case 22: /* phrase ::= phrase PLUS STRING star_opt */
       184243  +      case 23: /* phrase ::= phrase PLUS STRING star_opt */
183563 184244   { 
183564 184245     fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy53, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
183565 184246   }
183566 184247     fts5yymsp[-3].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
183567 184248           break;
183568         -      case 23: /* phrase ::= STRING star_opt */
       184249  +      case 24: /* phrase ::= STRING star_opt */
183569 184250   { 
183570 184251     fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
183571 184252   }
183572 184253     fts5yymsp[-1].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
183573 184254           break;
183574         -      case 24: /* star_opt ::= STAR */
       184255  +      case 25: /* star_opt ::= STAR */
183575 184256   { fts5yymsp[0].minor.fts5yy4 = 1; }
183576 184257           break;
183577         -      case 25: /* star_opt ::= */
       184258  +      case 26: /* star_opt ::= */
183578 184259   { fts5yymsp[1].minor.fts5yy4 = 0; }
183579 184260           break;
183580 184261         default:
183581 184262           break;
183582 184263   /********** End reduce actions ************************************************/
183583 184264     };
183584 184265     assert( fts5yyruleno<sizeof(fts5yyRuleInfo)/sizeof(fts5yyRuleInfo[0]) );
................................................................................
184612 185293   static void sqlite3Fts5BufferAppendBlob(
184613 185294     int *pRc,
184614 185295     Fts5Buffer *pBuf, 
184615 185296     u32 nData, 
184616 185297     const u8 *pData
184617 185298   ){
184618 185299     assert_nc( *pRc || nData>=0 );
184619         -  if( fts5BufferGrow(pRc, pBuf, nData) ) return;
184620         -  memcpy(&pBuf->p[pBuf->n], pData, nData);
184621         -  pBuf->n += nData;
       185300  +  if( nData ){
       185301  +    if( fts5BufferGrow(pRc, pBuf, nData) ) return;
       185302  +    memcpy(&pBuf->p[pBuf->n], pData, nData);
       185303  +    pBuf->n += nData;
       185304  +  }
184622 185305   }
184623 185306   
184624 185307   /*
184625 185308   ** Append the nul-terminated string zStr to the buffer pBuf. This function
184626 185309   ** ensures that the byte following the buffer data is set to 0x00, even 
184627 185310   ** though this byte is not included in the pBuf->n count.
184628 185311   */
................................................................................
184791 185474     return SQLITE_OK;
184792 185475   }
184793 185476   
184794 185477   static void *sqlite3Fts5MallocZero(int *pRc, int nByte){
184795 185478     void *pRet = 0;
184796 185479     if( *pRc==SQLITE_OK ){
184797 185480       pRet = sqlite3_malloc(nByte);
184798         -    if( pRet==0 && nByte>0 ){
184799         -      *pRc = SQLITE_NOMEM;
       185481  +    if( pRet==0 ){
       185482  +      if( nByte>0 ) *pRc = SQLITE_NOMEM;
184800 185483       }else{
184801 185484         memset(pRet, 0, nByte);
184802 185485       }
184803 185486     }
184804 185487     return pRet;
184805 185488   }
184806 185489   
................................................................................
186113 186796   }
186114 186797   
186115 186798   static void *fts5ParseAlloc(u64 t){ return sqlite3_malloc((int)t); }
186116 186799   static void fts5ParseFree(void *p){ sqlite3_free(p); }
186117 186800   
186118 186801   static int sqlite3Fts5ExprNew(
186119 186802     Fts5Config *pConfig,            /* FTS5 Configuration */
       186803  +  int iCol,
186120 186804     const char *zExpr,              /* Expression text */
186121 186805     Fts5Expr **ppNew, 
186122 186806     char **pzErr
186123 186807   ){
186124 186808     Fts5Parse sParse;
186125 186809     Fts5Token token;
186126 186810     const char *z = zExpr;
................................................................................
186136 186820     sParse.pConfig = pConfig;
186137 186821   
186138 186822     do {
186139 186823       t = fts5ExprGetToken(&sParse, &z, &token);
186140 186824       sqlite3Fts5Parser(pEngine, t, token, &sParse);
186141 186825     }while( sParse.rc==SQLITE_OK && t!=FTS5_EOF );
186142 186826     sqlite3Fts5ParserFree(pEngine, fts5ParseFree);
       186827  +
       186828  +  /* If the LHS of the MATCH expression was a user column, apply the
       186829  +  ** implicit column-filter.  */
       186830  +  if( iCol<pConfig->nCol && sParse.pExpr && sParse.rc==SQLITE_OK ){
       186831  +    int n = sizeof(Fts5Colset);
       186832  +    Fts5Colset *pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&sParse.rc, n);
       186833  +    if( pColset ){
       186834  +      pColset->nCol = 1;
       186835  +      pColset->aiCol[0] = iCol;
       186836  +      sqlite3Fts5ParseSetColset(&sParse, sParse.pExpr, pColset);
       186837  +    }
       186838  +  }
186143 186839   
186144 186840     assert( sParse.rc!=SQLITE_OK || sParse.zErr==0 );
186145 186841     if( sParse.rc==SQLITE_OK ){
186146 186842       *ppNew = pNew = sqlite3_malloc(sizeof(Fts5Expr));
186147 186843       if( pNew==0 ){
186148 186844         sParse.rc = SQLITE_NOMEM;
186149 186845         sqlite3Fts5ParseNodeFree(sParse.pExpr);
................................................................................
187786 188482       assert( pParse->rc!=SQLITE_OK );
187787 188483       sqlite3_free(pColset);
187788 188484     }
187789 188485   
187790 188486     return pRet;
187791 188487   }
187792 188488   
       188489  +/*
       188490  +** If argument pOrig is NULL, or if (*pRc) is set to anything other than
       188491  +** SQLITE_OK when this function is called, NULL is returned. 
       188492  +**
       188493  +** Otherwise, a copy of (*pOrig) is made into memory obtained from
       188494  +** sqlite3Fts5MallocZero() and a pointer to it returned. If the allocation
       188495  +** fails, (*pRc) is set to SQLITE_NOMEM and NULL is returned.
       188496  +*/
       188497  +static Fts5Colset *fts5CloneColset(int *pRc, Fts5Colset *pOrig){
       188498  +  Fts5Colset *pRet;
       188499  +  if( pOrig ){
       188500  +    int nByte = sizeof(Fts5Colset) + (pOrig->nCol-1) * sizeof(int);
       188501  +    pRet = (Fts5Colset*)sqlite3Fts5MallocZero(pRc, nByte);
       188502  +    if( pRet ){ 
       188503  +      memcpy(pRet, pOrig, nByte);
       188504  +    }
       188505  +  }else{
       188506  +    pRet = 0;
       188507  +  }
       188508  +  return pRet;
       188509  +}
       188510  +
       188511  +/*
       188512  +** Remove from colset pColset any columns that are not also in colset pMerge.
       188513  +*/
       188514  +static void fts5MergeColset(Fts5Colset *pColset, Fts5Colset *pMerge){
       188515  +  int iIn = 0;          /* Next input in pColset */
       188516  +  int iMerge = 0;       /* Next input in pMerge */
       188517  +  int iOut = 0;         /* Next output slot in pColset */
       188518  +
       188519  +  while( iIn<pColset->nCol && iMerge<pMerge->nCol ){
       188520  +    int iDiff = pColset->aiCol[iIn] - pMerge->aiCol[iMerge];
       188521  +    if( iDiff==0 ){
       188522  +      pColset->aiCol[iOut++] = pMerge->aiCol[iMerge];
       188523  +      iMerge++;
       188524  +      iIn++;
       188525  +    }else if( iDiff>0 ){
       188526  +      iMerge++;
       188527  +    }else{
       188528  +      iIn++;
       188529  +    }
       188530  +  }
       188531  +  pColset->nCol = iOut;
       188532  +}
       188533  +
       188534  +/*
       188535  +** Recursively apply colset pColset to expression node pNode and all of
       188536  +** its decendents. If (*ppFree) is not NULL, it contains a spare copy
       188537  +** of pColset. This function may use the spare copy and set (*ppFree) to
       188538  +** zero, or it may create copies of pColset using fts5CloneColset().
       188539  +*/
       188540  +static void fts5ParseSetColset(
       188541  +  Fts5Parse *pParse, 
       188542  +  Fts5ExprNode *pNode, 
       188543  +  Fts5Colset *pColset,
       188544  +  Fts5Colset **ppFree
       188545  +){
       188546  +  if( pParse->rc==SQLITE_OK ){
       188547  +    assert( pNode->eType==FTS5_TERM || pNode->eType==FTS5_STRING 
       188548  +         || pNode->eType==FTS5_AND  || pNode->eType==FTS5_OR
       188549  +         || pNode->eType==FTS5_NOT  || pNode->eType==FTS5_EOF
       188550  +    );
       188551  +    if( pNode->eType==FTS5_STRING || pNode->eType==FTS5_TERM ){
       188552  +      Fts5ExprNearset *pNear = pNode->pNear;
       188553  +      if( pNear->pColset ){
       188554  +        fts5MergeColset(pNear->pColset, pColset);
       188555  +        if( pNear->pColset->nCol==0 ){
       188556  +          pNode->eType = FTS5_EOF;
       188557  +          pNode->xNext = 0;
       188558  +        }
       188559  +      }else if( *ppFree ){
       188560  +        pNear->pColset = pColset;
       188561  +        *ppFree = 0;
       188562  +      }else{
       188563  +        pNear->pColset = fts5CloneColset(&pParse->rc, pColset);
       188564  +      }
       188565  +    }else{
       188566  +      int i;
       188567  +      assert( pNode->eType!=FTS5_EOF || pNode->nChild==0 );
       188568  +      for(i=0; i<pNode->nChild; i++){
       188569  +        fts5ParseSetColset(pParse, pNode->apChild[i], pColset, ppFree);
       188570  +      }
       188571  +    }
       188572  +  }
       188573  +}
       188574  +
       188575  +/*
       188576  +** Apply colset pColset to expression node pExpr and all of its descendents.
       188577  +*/
187793 188578   static void sqlite3Fts5ParseSetColset(
187794 188579     Fts5Parse *pParse, 
187795         -  Fts5ExprNearset *pNear, 
       188580  +  Fts5ExprNode *pExpr, 
187796 188581     Fts5Colset *pColset 
187797 188582   ){
       188583  +  Fts5Colset *pFree = pColset;
187798 188584     if( pParse->pConfig->eDetail==FTS5_DETAIL_NONE ){
187799 188585       pParse->rc = SQLITE_ERROR;
187800 188586       pParse->zErr = sqlite3_mprintf(
187801 188587         "fts5: column queries are not supported (detail=none)"
187802 188588       );
187803         -    sqlite3_free(pColset);
187804         -    return;
       188589  +  }else{
       188590  +    fts5ParseSetColset(pParse, pExpr, pColset, &pFree);
187805 188591     }
187806         -
187807         -  if( pNear ){
187808         -    pNear->pColset = pColset;
187809         -  }else{
187810         -    sqlite3_free(pColset);
187811         -  }
       188592  +  sqlite3_free(pFree);
187812 188593   }
187813 188594   
187814 188595   static void fts5ExprAssignXNext(Fts5ExprNode *pNode){
187815 188596     switch( pNode->eType ){
187816 188597       case FTS5_STRING: {
187817 188598         Fts5ExprNearset *pNear = pNode->pNear;
187818 188599         if( pNear->nPhrase==1 && pNear->apPhrase[0]->nTerm==1 
................................................................................
188258 189039       azConfig[i++] = (const char*)sqlite3_value_text(apVal[iArg]);
188259 189040     }
188260 189041   
188261 189042     zExpr = (const char*)sqlite3_value_text(apVal[0]);
188262 189043   
188263 189044     rc = sqlite3Fts5ConfigParse(pGlobal, db, nConfig, azConfig, &pConfig, &zErr);
188264 189045     if( rc==SQLITE_OK ){
188265         -    rc = sqlite3Fts5ExprNew(pConfig, zExpr, &pExpr, &zErr);
       189046  +    rc = sqlite3Fts5ExprNew(pConfig, pConfig->nCol, zExpr, &pExpr, &zErr);
188266 189047     }
188267 189048     if( rc==SQLITE_OK ){
188268 189049       char *zText;
188269 189050       if( pExpr->pRoot->xNext==0 ){
188270 189051         zText = sqlite3_mprintf("");
188271 189052       }else if( bTcl ){
188272 189053         zText = fts5ExprPrintTcl(pConfig, zNearsetCmd, pExpr->pRoot);
................................................................................
188655 189436     int nSlot;                      /* Size of aSlot[] array */
188656 189437     Fts5HashEntry *pScan;           /* Current ordered scan item */
188657 189438     Fts5HashEntry **aSlot;          /* Array of hash slots */
188658 189439   };
188659 189440   
188660 189441   /*
188661 189442   ** Each entry in the hash table is represented by an object of the 
188662         -** following type. Each object, its key (zKey[]) and its current data
188663         -** are stored in a single memory allocation. The position list data 
188664         -** immediately follows the key data in memory.
       189443  +** following type. Each object, its key (a nul-terminated string) and 
       189444  +** its current data are stored in a single memory allocation. The 
       189445  +** key immediately follows the object in memory. The position list
       189446  +** data immediately follows the key data in memory.
188665 189447   **