System.Data.SQLite
Check-in [44ad7c70f0]
Not logged in

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

Overview
Comment:Update SQLite core library to the 3.19.1 release.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 44ad7c70f0c3b3667b031d79d4a7afcf07d344a7
User & Date: mistachkin 2017-05-24 19:24:58
Context
2017-06-10
17:38
Merge updates from trunk. check-in: 091bc3a48a user: mistachkin tags: branch-1.0.105
2017-05-24
19:25
Pickup the SQLite core library 3.19.1 docs from upstream. check-in: f453665b94 user: mistachkin tags: trunk
19:24
Update SQLite core library to the 3.19.1 release. check-in: 44ad7c70f0 user: mistachkin tags: trunk
2017-05-13
05:42
Merge in applicable changes from the 1.0.105.1 release. check-in: c2adf5a112 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

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

    39     39             </td>
    40     40           </tr>
    41     41         </table>
    42     42       </div>
    43     43       <div id="mainSection">
    44     44       <div id="mainBody">
    45     45       <h1 class="heading">Version History</h1>
    46         -    <p><b>1.0.106.0 - June XX, 2017 <font color="red">(release scheduled)</font></b></p>
           46  +    <p><b>1.0.106.0 - July XX, 2017 <font color="red">(release scheduled)</font></b></p>
    47     47       <ul>
    48         -      <li>Updated to <a href="https://www.sqlite.org/draft/releaselog/3_19_0.html">SQLite 3.19.0</a>.</li>
           48  +      <li>Updated to <a href="https://www.sqlite.org/releaselog/3_19_1.html">SQLite 3.19.1</a>.</li>
    49     49       </ul>
    50     50       <p><b>1.0.105.1 - May 15, 2017</b></p>
    51     51       <ul>
    52     52         <li>Prevent culture settings from negatively impacting integer connection string defaults.</li>
    53     53         <li>Make sure the &quot;No_SQLiteConnectionNewParser&quot; and &quot;DefaultFlags_SQLiteConnection&quot; setting values end up being cached.</li>
    54     54         <li>Cache the XML file name and assembly directory used by the configuration subsystem.</li>
    55     55       </ul>

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.19.0.0</SQLITE_MANIFEST_VERSION>
    13         -    <SQLITE_RC_VERSION>3,19,0,0</SQLITE_RC_VERSION>
           12  +    <SQLITE_MANIFEST_VERSION>3.19.1.0</SQLITE_MANIFEST_VERSION>
           13  +    <SQLITE_RC_VERSION>3,19,1,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.19.0.0"
           17  +		Value="3.19.1.0"
    18     18   		PerformEnvironmentSet="true"
    19     19   	/>
    20     20   	<UserMacro
    21     21   		Name="SQLITE_RC_VERSION"
    22         -		Value="3,19,0,0"
           22  +		Value="3,19,1,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.19.0.  By combining all the individual C code files into this
            3  +** version 3.19.1.  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.19.0"
   402         -#define SQLITE_VERSION_NUMBER 3019000
   403         -#define SQLITE_SOURCE_ID      "2017-05-10 16:33:48 92c5ea7047323d10f762877c5f56d20a3e609e8b55efcfe4880ef3048821ac1f"
          401  +#define SQLITE_VERSION        "3.19.1"
          402  +#define SQLITE_VERSION_NUMBER 3019001
          403  +#define SQLITE_SOURCE_ID      "2017-05-24 13:08:33 f6d7b988f40217821a382bc298180e9e6794f3ed79a83c6ef5cae048989b3f86"
   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
................................................................................
  2974   2974   ** authorizer will fail with an error message explaining that
  2975   2975   ** access is denied. 
  2976   2976   **
  2977   2977   ** ^The first parameter to the authorizer callback is a copy of the third
  2978   2978   ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
  2979   2979   ** to the callback is an integer [SQLITE_COPY | action code] that specifies
  2980   2980   ** the particular action to be authorized. ^The third through sixth parameters
  2981         -** to the callback are zero-terminated strings that contain additional
  2982         -** 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.
  2983   2985   **
  2984   2986   ** ^If the action code is [SQLITE_READ]
  2985   2987   ** and the callback returns [SQLITE_IGNORE] then the
  2986   2988   ** [prepared statement] statement is constructed to substitute
  2987   2989   ** a NULL value in place of the table column that would have
  2988   2990   ** been read if [SQLITE_OK] had been returned.  The [SQLITE_IGNORE]
  2989   2991   ** return can be used to deny an untrusted user access to individual
  2990   2992   ** columns of a table.
  2991   2993   ** ^When a table is referenced by a [SELECT] but no column values are
  2992   2994   ** extracted from that table (for example in a query like
  2993   2995   ** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
  2994         -** is invoked once for that table with a NULL column name.
         2996  +** is invoked once for that table with a column name that is an empty string.
  2995   2997   ** ^If the action code is [SQLITE_DELETE] and the callback returns
  2996   2998   ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
  2997   2999   ** [truncate optimization] is disabled and all rows are deleted individually.
  2998   3000   **
  2999   3001   ** An authorizer is used when [sqlite3_prepare | preparing]
  3000   3002   ** SQL statements from an untrusted source, to ensure that the SQL statements
  3001   3003   ** do not try to access data they are not allowed to see, or that they do not
................................................................................
  5034   5036   ** of where this might be useful is in a regular-expression matching
  5035   5037   ** function. The compiled version of the regular expression can be stored as
  5036   5038   ** metadata associated with the pattern string.  
  5037   5039   ** Then as long as the pattern string remains the same,
  5038   5040   ** the compiled regular expression can be reused on multiple
  5039   5041   ** invocations of the same function.
  5040   5042   **
  5041         -** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
  5042         -** associated by the sqlite3_set_auxdata() function with the Nth argument
  5043         -** value to the application-defined function. ^If there is no metadata
  5044         -** 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
  5045   5048   ** returns a NULL pointer.
  5046   5049   **
  5047   5050   ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
  5048   5051   ** argument of the application-defined function.  ^Subsequent
  5049   5052   ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
  5050   5053   ** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or
  5051   5054   ** NULL if the metadata has been discarded.
................................................................................
  5067   5070   ** should be called near the end of the function implementation and the
  5068   5071   ** function implementation should not make any use of P after
  5069   5072   ** sqlite3_set_auxdata() has been called.
  5070   5073   **
  5071   5074   ** ^(In practice, metadata is preserved between function calls for
  5072   5075   ** function parameters that are compile-time constants, including literal
  5073   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.
  5074   5081   **
  5075   5082   ** These routines must be called from the same thread in which
  5076   5083   ** the SQL function is running.
  5077   5084   */
  5078   5085   SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
  5079   5086   SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
  5080   5087   
................................................................................
  9662   9669   ** Any number of calls to add() and output() may be made between the calls to
  9663   9670   ** new() and delete(), and in any order.
  9664   9671   **
  9665   9672   ** As well as the regular sqlite3changegroup_add() and 
  9666   9673   ** sqlite3changegroup_output() functions, also available are the streaming
  9667   9674   ** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
  9668   9675   */
  9669         -int sqlite3changegroup_new(sqlite3_changegroup **pp);
         9676  +SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp);
  9670   9677   
  9671   9678   /*
  9672   9679   ** CAPI3REF: Add A Changeset To A Changegroup
  9673   9680   **
  9674   9681   ** Add all changes within the changeset (or patchset) in buffer pData (size
  9675   9682   ** nData bytes) to the changegroup. 
  9676   9683   **
................................................................................
  9739   9746   ** appears to be corrupt and the corruption is detected, SQLITE_CORRUPT is
  9740   9747   ** returned. Or, if an out-of-memory condition occurs during processing, this
  9741   9748   ** function returns SQLITE_NOMEM. In all cases, if an error occurs the
  9742   9749   ** final contents of the changegroup is undefined.
  9743   9750   **
  9744   9751   ** If no error occurs, SQLITE_OK is returned.
  9745   9752   */
  9746         -int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
         9753  +SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
  9747   9754   
  9748   9755   /*
  9749   9756   ** CAPI3REF: Obtain A Composite Changeset From A Changegroup
  9750   9757   **
  9751   9758   ** Obtain a buffer containing a changeset (or patchset) representing the
  9752   9759   ** current contents of the changegroup. If the inputs to the changegroup
  9753   9760   ** were themselves changesets, the output is a changeset. Or, if the
................................................................................
  9765   9772   ** If an error occurs, an SQLite error code is returned and the output
  9766   9773   ** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK
  9767   9774   ** is returned and the output variables are set to the size of and a 
  9768   9775   ** pointer to the output buffer, respectively. In this case it is the
  9769   9776   ** responsibility of the caller to eventually free the buffer using a
  9770   9777   ** call to sqlite3_free().
  9771   9778   */
  9772         -int sqlite3changegroup_output(
         9779  +SQLITE_API int sqlite3changegroup_output(
  9773   9780     sqlite3_changegroup*,
  9774   9781     int *pnData,                    /* OUT: Size of output buffer in bytes */
  9775   9782     void **ppData                   /* OUT: Pointer to output buffer */
  9776   9783   );
  9777   9784   
  9778   9785   /*
  9779   9786   ** CAPI3REF: Delete A Changegroup Object
  9780   9787   */
  9781         -void sqlite3changegroup_delete(sqlite3_changegroup*);
         9788  +SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*);
  9782   9789   
  9783   9790   /*
  9784   9791   ** CAPI3REF: Apply A Changeset To A Database
  9785   9792   **
  9786   9793   ** Apply a changeset to a database. This function attempts to update the
  9787   9794   ** "main" database attached to handle db with the changes found in the
  9788   9795   ** changeset passed via the second and third arguments.
................................................................................
 10163  10170     void *pOut
 10164  10171   );
 10165  10172   SQLITE_API int sqlite3session_patchset_strm(
 10166  10173     sqlite3_session *pSession,
 10167  10174     int (*xOutput)(void *pOut, const void *pData, int nData),
 10168  10175     void *pOut
 10169  10176   );
 10170         -int sqlite3changegroup_add_strm(sqlite3_changegroup*, 
        10177  +SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup*, 
 10171  10178       int (*xInput)(void *pIn, void *pData, int *pnData),
 10172  10179       void *pIn
 10173  10180   );
 10174         -int sqlite3changegroup_output_strm(sqlite3_changegroup*,
        10181  +SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*,
 10175  10182       int (*xOutput)(void *pOut, const void *pData, int nData), 
 10176  10183       void *pOut
 10177  10184   );
 10178  10185   
 10179  10186   
 10180  10187   /*
 10181  10188   ** Make sure we can call this stuff from C++.
................................................................................
 18210  18217   ** Each auxiliary data pointer stored by a user defined function 
 18211  18218   ** implementation calling sqlite3_set_auxdata() is stored in an instance
 18212  18219   ** of this structure. All such structures associated with a single VM
 18213  18220   ** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed
 18214  18221   ** when the VM is halted (if not before).
 18215  18222   */
 18216  18223   struct AuxData {
 18217         -  int iOp;                        /* Instruction number of OP_Function opcode */
 18218         -  int iArg;                       /* Index of function argument. */
        18224  +  int iAuxOp;                     /* Instruction number of OP_Function opcode */
        18225  +  int iAuxArg;                    /* Index of function argument. */
 18219  18226     void *pAux;                     /* Aux data pointer */
 18220         -  void (*xDelete)(void *);        /* Destructor for the aux data */
 18221         -  AuxData *pNext;                 /* Next element in list */
        18227  +  void (*xDeleteAux)(void*);      /* Destructor for the aux data */
        18228  +  AuxData *pNextAux;              /* Next element in list */
 18222  18229   };
 18223  18230   
 18224  18231   /*
 18225  18232   ** The "context" argument for an installable function.  A pointer to an
 18226  18233   ** instance of this structure is the first argument to the routines used
 18227  18234   ** implement the SQL functions.
 18228  18235   **
................................................................................
 74371  74378   **    * the corresponding bit in argument mask is clear (where the first
 74372  74379   **      function parameter corresponds to bit 0 etc.).
 74373  74380   */
 74374  74381   SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(sqlite3 *db, AuxData **pp, int iOp, int mask){
 74375  74382     while( *pp ){
 74376  74383       AuxData *pAux = *pp;
 74377  74384       if( (iOp<0)
 74378         -     || (pAux->iOp==iOp && (pAux->iArg>31 || !(mask & MASKBIT32(pAux->iArg))))
        74385  +     || (pAux->iAuxOp==iOp
        74386  +          && pAux->iAuxArg>=0
        74387  +          && (pAux->iAuxArg>31 || !(mask & MASKBIT32(pAux->iAuxArg))))
 74379  74388       ){
 74380         -      testcase( pAux->iArg==31 );
 74381         -      if( pAux->xDelete ){
 74382         -        pAux->xDelete(pAux->pAux);
        74389  +      testcase( pAux->iAuxArg==31 );
        74390  +      if( pAux->xDeleteAux ){
        74391  +        pAux->xDeleteAux(pAux->pAux);
 74383  74392         }
 74384         -      *pp = pAux->pNext;
        74393  +      *pp = pAux->pNextAux;
 74385  74394         sqlite3DbFree(db, pAux);
 74386  74395       }else{
 74387         -      pp= &pAux->pNext;
        74396  +      pp= &pAux->pNextAux;
 74388  74397       }
 74389  74398     }
 74390  74399   }
 74391  74400   
 74392  74401   /*
 74393  74402   ** Free all memory associated with the Vdbe passed as the second argument,
 74394  74403   ** except for object itself, which is preserved.
................................................................................
 76881  76890       return (void*)p->pMem->z;
 76882  76891     }
 76883  76892   }
 76884  76893   
 76885  76894   /*
 76886  76895   ** Return the auxiliary data pointer, if any, for the iArg'th argument to
 76887  76896   ** the user-function defined by pCtx.
        76897  +**
        76898  +** The left-most argument is 0.
        76899  +**
        76900  +** Undocumented behavior:  If iArg is negative then access a cache of
        76901  +** auxiliary data pointers that is available to all functions within a
        76902  +** single prepared statement.  The iArg values must match.
 76888  76903   */
 76889  76904   SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
 76890  76905     AuxData *pAuxData;
 76891  76906   
 76892  76907     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 76893  76908   #if SQLITE_ENABLE_STAT3_OR_STAT4
 76894  76909     if( pCtx->pVdbe==0 ) return 0;
 76895  76910   #else
 76896  76911     assert( pCtx->pVdbe!=0 );
 76897  76912   #endif
 76898         -  for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
 76899         -    if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
        76913  +  for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNextAux){
        76914  +    if(  pAuxData->iAuxArg==iArg && (pAuxData->iAuxOp==pCtx->iOp || iArg<0) ){
        76915  +      return pAuxData->pAux;
        76916  +    }
 76900  76917     }
 76901         -
 76902         -  return (pAuxData ? pAuxData->pAux : 0);
        76918  +  return 0;
 76903  76919   }
 76904  76920   
 76905  76921   /*
 76906  76922   ** Set the auxiliary data pointer and delete function, for the iArg'th
 76907  76923   ** argument to the user-function defined by pCtx. Any previous value is
 76908  76924   ** deleted by calling the delete function specified when it was set.
        76925  +**
        76926  +** The left-most argument is 0.
        76927  +**
        76928  +** Undocumented behavior:  If iArg is negative then make the data available
        76929  +** to all functions within the current prepared statement using iArg as an
        76930  +** access code.
 76909  76931   */
 76910  76932   SQLITE_API void sqlite3_set_auxdata(
 76911  76933     sqlite3_context *pCtx, 
 76912  76934     int iArg, 
 76913  76935     void *pAux, 
 76914  76936     void (*xDelete)(void*)
 76915  76937   ){
 76916  76938     AuxData *pAuxData;
 76917  76939     Vdbe *pVdbe = pCtx->pVdbe;
 76918  76940   
 76919  76941     assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 76920         -  if( iArg<0 ) goto failed;
 76921  76942   #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
 76922  76943     if( pVdbe==0 ) goto failed;
 76923  76944   #else
 76924  76945     assert( pVdbe!=0 );
 76925  76946   #endif
 76926  76947   
 76927         -  for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
 76928         -    if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
        76948  +  for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNextAux){
        76949  +    if( pAuxData->iAuxArg==iArg && (pAuxData->iAuxOp==pCtx->iOp || iArg<0) ){
        76950  +      break;
        76951  +    }
 76929  76952     }
 76930  76953     if( pAuxData==0 ){
 76931  76954       pAuxData = sqlite3DbMallocZero(pVdbe->db, sizeof(AuxData));
 76932  76955       if( !pAuxData ) goto failed;
 76933         -    pAuxData->iOp = pCtx->iOp;
 76934         -    pAuxData->iArg = iArg;
 76935         -    pAuxData->pNext = pVdbe->pAuxData;
        76956  +    pAuxData->iAuxOp = pCtx->iOp;
        76957  +    pAuxData->iAuxArg = iArg;
        76958  +    pAuxData->pNextAux = pVdbe->pAuxData;
 76936  76959       pVdbe->pAuxData = pAuxData;
 76937  76960       if( pCtx->fErrorOrAux==0 ){
 76938  76961         pCtx->isError = 0;
 76939  76962         pCtx->fErrorOrAux = 1;
 76940  76963       }
 76941         -  }else if( pAuxData->xDelete ){
 76942         -    pAuxData->xDelete(pAuxData->pAux);
        76964  +  }else if( pAuxData->xDeleteAux ){
        76965  +    pAuxData->xDeleteAux(pAuxData->pAux);
 76943  76966     }
 76944  76967   
 76945  76968     pAuxData->pAux = pAux;
 76946         -  pAuxData->xDelete = xDelete;
        76969  +  pAuxData->xDeleteAux = xDelete;
 76947  76970     return;
 76948  76971   
 76949  76972   failed:
 76950  76973     if( xDelete ){
 76951  76974       xDelete(pAux);
 76952  76975     }
 76953  76976   }
................................................................................
 80698  80721   ** Check the cursor P1 to see if it is currently pointing at a NULL row.
 80699  80722   ** If it is, then set register P3 to NULL and jump immediately to P2.
 80700  80723   ** If P1 is not on a NULL row, then fall through without making any
 80701  80724   ** changes.
 80702  80725   */
 80703  80726   case OP_IfNullRow: {         /* jump */
 80704  80727     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
        80728  +  assert( p->apCsr[pOp->p1]!=0 );
 80705  80729     if( p->apCsr[pOp->p1]->nullRow ){
 80706  80730       sqlite3VdbeMemSetNull(aMem + pOp->p3);
 80707  80731       goto jump_to_p2;
 80708  80732     }
 80709  80733     break;
 80710  80734   }
 80711  80735   
................................................................................
 82363  82387         assert( (r.aMem[ii].flags & MEM_Zero)==0 || r.aMem[ii].n==0 );
 82364  82388         if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
 82365  82389       }
 82366  82390   #endif
 82367  82391       pIdxKey = &r;
 82368  82392       pFree = 0;
 82369  82393     }else{
        82394  +    assert( pIn3->flags & MEM_Blob );
        82395  +    rc = ExpandBlob(pIn3);
        82396  +    assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
        82397  +    if( rc ) goto no_mem;
 82370  82398       pFree = pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo);
 82371  82399       if( pIdxKey==0 ) goto no_mem;
 82372         -    assert( pIn3->flags & MEM_Blob );
 82373         -    (void)ExpandBlob(pIn3);
 82374  82400       sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
 82375  82401     }
 82376  82402     pIdxKey->default_rc = 0;
 82377  82403     takeJump = 0;
 82378  82404     if( pOp->opcode==OP_NoConflict ){
 82379  82405       /* For the OP_NoConflict opcode, take the jump if any of the
 82380  82406       ** input fields are NULL, since any key with a NULL will not
................................................................................
 91214  91240     }else if( op==TK_SELECT ){
 91215  91241       return pExpr->x.pSelect->pEList->nExpr;
 91216  91242     }else{
 91217  91243       return 1;
 91218  91244     }
 91219  91245   }
 91220  91246   
 91221         -#ifndef SQLITE_OMIT_SUBQUERY
 91222  91247   /*
 91223  91248   ** Return a pointer to a subexpression of pVector that is the i-th
 91224  91249   ** column of the vector (numbered starting with 0).  The caller must
 91225  91250   ** ensure that i is within range.
 91226  91251   **
 91227  91252   ** If pVector is really a scalar (and "scalar" here includes subqueries
 91228  91253   ** that return a single column!) then return pVector unmodified.
................................................................................
 91242  91267         return pVector->x.pSelect->pEList->a[i].pExpr;
 91243  91268       }else{
 91244  91269         return pVector->x.pList->a[i].pExpr;
 91245  91270       }
 91246  91271     }
 91247  91272     return pVector;
 91248  91273   }
 91249         -#endif /* !defined(SQLITE_OMIT_SUBQUERY) */
 91250  91274   
 91251         -#ifndef SQLITE_OMIT_SUBQUERY
 91252  91275   /*
 91253  91276   ** Compute and return a new Expr object which when passed to
 91254  91277   ** sqlite3ExprCode() will generate all necessary code to compute
 91255  91278   ** the iField-th column of the vector expression pVector.
 91256  91279   **
 91257  91280   ** It is ok for pVector to be a scalar (as long as iField==0).  
 91258  91281   ** In that case, this routine works like sqlite3ExprDup().
................................................................................
 91302  91325       assert( pRet==0 || pRet->iTable==0 );
 91303  91326     }else{
 91304  91327       if( pVector->op==TK_VECTOR ) pVector = pVector->x.pList->a[iField].pExpr;
 91305  91328       pRet = sqlite3ExprDup(pParse->db, pVector, 0);
 91306  91329     }
 91307  91330     return pRet;
 91308  91331   }
 91309         -#endif /* !define(SQLITE_OMIT_SUBQUERY) */
 91310  91332   
 91311  91333   /*
 91312  91334   ** If expression pExpr is of type TK_SELECT, generate code to evaluate
 91313  91335   ** it. Return the register in which the result is stored (or, if the 
 91314  91336   ** sub-select returns more than one column, the first in an array
 91315  91337   ** of registers in which the result is stored).
 91316  91338   **
................................................................................
 94273  94295     int iResult;
 94274  94296     int nResult = sqlite3ExprVectorSize(p);
 94275  94297     if( nResult==1 ){
 94276  94298       iResult = sqlite3ExprCodeTemp(pParse, p, piFreeable);
 94277  94299     }else{
 94278  94300       *piFreeable = 0;
 94279  94301       if( p->op==TK_SELECT ){
        94302  +#if SQLITE_OMIT_SUBQUERY
        94303  +      iResult = 0;
        94304  +#else
 94280  94305         iResult = sqlite3CodeSubselect(pParse, p, 0, 0);
        94306  +#endif
 94281  94307       }else{
 94282  94308         int i;
 94283  94309         iResult = pParse->nMem+1;
 94284  94310         pParse->nMem += nResult;
 94285  94311         for(i=0; i<nResult; i++){
 94286  94312           sqlite3ExprCodeFactorable(pParse, p->x.pList->a[i].pExpr, i+iResult);
 94287  94313         }
................................................................................
 99598  99624     if( db->init.busy || IN_DECLARE_VTAB ){
 99599  99625       return SQLITE_OK;
 99600  99626     }
 99601  99627   
 99602  99628     if( db->xAuth==0 ){
 99603  99629       return SQLITE_OK;
 99604  99630     }
        99631  +
        99632  +  /* EVIDENCE-OF: R-43249-19882 The third through sixth parameters to the
        99633  +  ** callback are either NULL pointers or zero-terminated strings that
        99634  +  ** contain additional details about the action to be authorized.
        99635  +  **
        99636  +  ** The following testcase() macros show that any of the 3rd through 6th
        99637  +  ** parameters can be either NULL or a string. */
        99638  +  testcase( zArg1==0 );
        99639  +  testcase( zArg2==0 );
        99640  +  testcase( zArg3==0 );
        99641  +  testcase( pParse->zAuthContext==0 );
        99642  +
 99605  99643     rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext
 99606  99644   #ifdef SQLITE_USER_AUTHENTICATION
 99607  99645                    ,db->auth.zAuthUser
 99608  99646   #endif
 99609  99647                   );
 99610  99648     if( rc==SQLITE_DENY ){
 99611  99649       sqlite3ErrorMsg(pParse, "not authorized");
................................................................................
104933 104971       sqlite3VdbeAddOp2(v, OP_Integer, 0, memCnt);
104934 104972     }
104935 104973   
104936 104974   #ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
104937 104975     /* Special case: A DELETE without a WHERE clause deletes everything.
104938 104976     ** It is easier just to erase the whole table. Prior to version 3.6.5,
104939 104977     ** this optimization caused the row change count (the value returned by 
104940         -  ** API function sqlite3_count_changes) to be set incorrectly.  */
       104978  +  ** API function sqlite3_count_changes) to be set incorrectly.
       104979  +  **
       104980  +  ** The "rcauth==SQLITE_OK" terms is the
       104981  +  ** IMPLEMENATION-OF: R-17228-37124 If the action code is SQLITE_DELETE and
       104982  +  ** the callback returns SQLITE_IGNORE then the DELETE operation proceeds but
       104983  +  ** the truncate optimization is disabled and all rows are deleted
       104984  +  ** individually.
       104985  +  */
104941 104986     if( rcauth==SQLITE_OK
104942 104987      && pWhere==0
104943 104988      && !bComplex
104944 104989      && !IsVirtual(pTab)
104945 104990   #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
104946 104991      && db->xPreUpdateCallback==0
104947 104992   #endif
................................................................................
119678 119723             pNew->flags |= EP_FromJoin;
119679 119724           }
119680 119725           sqlite3ExprDelete(db, pExpr);
119681 119726           pExpr = pNew;
119682 119727         }
119683 119728       }
119684 119729     }else{
       119730  +    if( pExpr->op==TK_IF_NULL_ROW && pExpr->iTable==pSubst->iTable ){
       119731  +      pExpr->iTable = pSubst->iNewTable;
       119732  +    }
119685 119733       pExpr->pLeft = substExpr(pSubst, pExpr->pLeft);
119686 119734       pExpr->pRight = substExpr(pSubst, pExpr->pRight);
119687 119735       if( ExprHasProperty(pExpr, EP_xIsSelect) ){
119688 119736         substSelect(pSubst, pExpr->x.pSelect, 1);
119689 119737       }else{
119690 119738         substExprList(pSubst, pExpr->x.pList);
119691 119739       }
................................................................................
119762 119810   **
119763 119811   **   (2)  The subquery is not an aggregate or (2a) the outer query is not a join
119764 119812   **        and (2b) the outer query does not use subqueries other than the one
119765 119813   **        FROM-clause subquery that is a candidate for flattening.  (2b is
119766 119814   **        due to ticket [2f7170d73bf9abf80] from 2015-02-09.)
119767 119815   **
119768 119816   **   (3)  The subquery is not the right operand of a LEFT JOIN
119769         -**        or the subquery is not itself a join.
       119817  +**        or the subquery is not itself a join and the outer query is not
       119818  +**        an aggregate.
119770 119819   **
119771 119820   **   (4)  The subquery is not DISTINCT.
119772 119821   **
119773 119822   **  (**)  At one point restrictions (4) and (5) defined a subset of DISTINCT
119774 119823   **        sub-queries that were excluded from this optimization. Restriction 
119775 119824   **        (4) has since been expanded to exclude all DISTINCT subqueries.
119776 119825   **
................................................................................
119957 120006     **         t1 LEFT OUTER JOIN (t2 JOIN t3)
119958 120007     **
119959 120008     ** If we flatten the above, we would get
119960 120009     **
119961 120010     **         (t1 LEFT OUTER JOIN t2) JOIN t3
119962 120011     **
119963 120012     ** which is not at all the same thing.
       120013  +  **
       120014  +  ** If the subquery is the right operand of a LEFT JOIN, then the outer
       120015  +  ** query cannot be an aggregate.  This is an artifact of the way aggregates
       120016  +  ** are processed - there is not mechanism to determine if the LEFT JOIN
       120017  +  ** table should be all-NULL.
119964 120018     **
119965 120019     ** See also tickets #306, #350, and #3300.
119966 120020     */
119967 120021     if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
119968 120022       isLeftJoin = 1;
119969         -    if( pSubSrc->nSrc>1 ){
       120023  +    if( pSubSrc->nSrc>1 || isAgg ){
119970 120024         return 0; /* Restriction (3) */
119971 120025       }
119972 120026     }
119973 120027   
119974 120028     /* Restriction 17: If the sub-query is a compound SELECT, then it must
119975 120029     ** use only the UNION ALL operator. And none of the simple select queries
119976 120030     ** that make up the compound SELECT are allowed to be aggregate or distinct
................................................................................
121588 121642     ** (2) Generate code for all sub-queries
121589 121643     */
121590 121644     for(i=0; i<pTabList->nSrc; i++){
121591 121645       struct SrcList_item *pItem = &pTabList->a[i];
121592 121646       SelectDest dest;
121593 121647       Select *pSub;
121594 121648   
121595         -    /* Issue SQLITE_READ authorizations with a NULL column name for any tables that
       121649  +    /* Issue SQLITE_READ authorizations with a fake column name for any tables that
121596 121650       ** are referenced but from which no values are extracted. Examples of where these
121597 121651       ** kinds of null SQLITE_READ authorizations would occur:
121598 121652       **
121599         -    **     SELECT count(*) FROM t1;   -- SQLITE_READ t1 null
121600         -    **     SELECT t1.* FROM t1, t2;   -- SQLITE_READ t2 null
       121653  +    **     SELECT count(*) FROM t1;   -- SQLITE_READ t1.""
       121654  +    **     SELECT t1.* FROM t1, t2;   -- SQLITE_READ t2.""
       121655  +    **
       121656  +    ** The fake column name is an empty string.  It is possible for a table to
       121657  +    ** have a column named by the empty string, in which case there is no way to
       121658  +    ** distinguish between an unreferenced table and an actual reference to the
       121659  +    ** "" column.  The original design was for the fake column name to be a NULL,
       121660  +    ** which would be unambiguous.  But legacy authorization callbacks might
       121661  +    ** assume the column name is non-NULL and segfault.  The use of an empty string
       121662  +    ** for the fake column name seems safer.
121601 121663       */
121602 121664       if( pItem->colUsed==0 ){
121603         -      sqlite3AuthCheck(pParse, SQLITE_READ, pItem->zName, pItem->zDatabase, 0);
       121665  +      sqlite3AuthCheck(pParse, SQLITE_READ, pItem->zName, "", pItem->zDatabase);
121604 121666       }
121605 121667   
121606 121668   #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
121607 121669       /* Generate code for all sub-queries in the FROM clause
121608 121670       */
121609 121671       pSub = pItem->pSelect;
121610 121672       if( pSub==0 ) continue;
................................................................................
143482 143544       void *pArg = sqlite3GlobalConfig.pSqllogArg;
143483 143545       sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0);
143484 143546     }
143485 143547   #endif
143486 143548   #if defined(SQLITE_HAS_CODEC)
143487 143549     if( rc==SQLITE_OK ){
143488 143550       const char *zKey;
143489         -    if( (zKey = sqlite3_uri_parameter(zOpen, "hexkey"))!=0 && zKey[0] ){;
       143551  +    if( (zKey = sqlite3_uri_parameter(zOpen, "hexkey"))!=0 && zKey[0] ){
143490 143552         u8 iByte;
143491 143553         int i;
143492 143554         char zDecoded[40];
143493 143555         for(i=0, iByte=0; i<sizeof(zDecoded)*2 && sqlite3Isxdigit(zKey[i]); i++){
143494 143556           iByte = (iByte<<4) + sqlite3HexToInt(zKey[i]);
143495 143557           if( (i&1)!=0 ) zDecoded[i/2] = iByte;
143496 143558         }
................................................................................
179494 179556     u32 nAlloc;        /* Number of slots of aNode[] allocated */
179495 179557     JsonNode *aNode;   /* Array of nodes containing the parse */
179496 179558     const char *zJson; /* Original JSON string */
179497 179559     u32 *aUp;          /* Index of parent of each node */
179498 179560     u8 oom;            /* Set to true if out of memory */
179499 179561     u8 nErr;           /* Number of errors seen */
179500 179562     u16 iDepth;        /* Nesting depth */
       179563  +  int nJson;         /* Length of the zJson string in bytes */
179501 179564   };
179502 179565   
179503 179566   /*
179504 179567   ** Maximum nesting depth of JSON for this implementation.
179505 179568   **
179506 179569   ** This limit is needed to avoid a stack overflow in the recursive
179507 179570   ** descent parser.  A depth of 2000 is far deeper than any sane JSON
................................................................................
179735 179798     sqlite3_free(pParse->aNode);
179736 179799     pParse->aNode = 0;
179737 179800     pParse->nNode = 0;
179738 179801     pParse->nAlloc = 0;
179739 179802     sqlite3_free(pParse->aUp);
179740 179803     pParse->aUp = 0;
179741 179804   }
       179805  +
       179806  +/*
       179807  +** Free a JsonParse object that was obtained from sqlite3_malloc().
       179808  +*/
       179809  +static void jsonParseFree(JsonParse *pParse){
       179810  +  jsonParseReset(pParse);
       179811  +  sqlite3_free(pParse);
       179812  +}
179742 179813   
179743 179814   /*
179744 179815   ** Convert the JsonNode pNode into a pure JSON string and
179745 179816   ** append to pOut.  Subsubstructure is also included.  Return
179746 179817   ** the number of JsonNode objects that are encoded.
179747 179818   */
179748 179819   static void jsonRenderNode(
................................................................................
180286 180357     if( aUp==0 ){
180287 180358       pParse->oom = 1;
180288 180359       return SQLITE_NOMEM;
180289 180360     }
180290 180361     jsonParseFillInParentage(pParse, 0, 0);
180291 180362     return SQLITE_OK;
180292 180363   }
       180364  +
       180365  +/*
       180366  +** Magic number used for the JSON parse cache in sqlite3_get_auxdata()
       180367  +*/
       180368  +#define JSON_CACHE_ID  (-429938)
       180369  +
       180370  +/*
       180371  +** Obtain a complete parse of the JSON found in the first argument
       180372  +** of the argv array.  Use the sqlite3_get_auxdata() cache for this
       180373  +** parse if it is available.  If the cache is not available or if it
       180374  +** is no longer valid, parse the JSON again and return the new parse,
       180375  +** and also register the new parse so that it will be available for
       180376  +** future sqlite3_get_auxdata() calls.
       180377  +*/
       180378  +static JsonParse *jsonParseCached(
       180379  +  sqlite3_context *pCtx,
       180380  +  sqlite3_value **argv
       180381  +){
       180382  +  const char *zJson = (const char*)sqlite3_value_text(argv[0]);
       180383  +  int nJson = sqlite3_value_bytes(argv[0]);
       180384  +  JsonParse *p;
       180385  +  if( zJson==0 ) return 0;
       180386  +  p = (JsonParse*)sqlite3_get_auxdata(pCtx, JSON_CACHE_ID);
       180387  +  if( p && p->nJson==nJson && memcmp(p->zJson,zJson,nJson)==0 ){
       180388  +    p->nErr = 0;
       180389  +    return p; /* The cached entry matches, so return it */
       180390  +  }
       180391  +  p = sqlite3_malloc( sizeof(*p) + nJson + 1 );
       180392  +  if( p==0 ){
       180393  +    sqlite3_result_error_nomem(pCtx);
       180394  +    return 0;
       180395  +  }
       180396  +  memset(p, 0, sizeof(*p));
       180397  +  p->zJson = (char*)&p[1];
       180398  +  memcpy((char*)p->zJson, zJson, nJson+1);
       180399  +  if( jsonParse(p, pCtx, p->zJson) ){
       180400  +    sqlite3_free(p);
       180401  +    return 0;
       180402  +  }
       180403  +  p->nJson = nJson;
       180404  +  sqlite3_set_auxdata(pCtx, JSON_CACHE_ID, p, (void(*)(void*))jsonParseFree);
       180405  +  return (JsonParse*)sqlite3_get_auxdata(pCtx, JSON_CACHE_ID);
       180406  +}
180293 180407   
180294 180408   /*
180295 180409   ** Compare the OBJECT label at pNode against zKey,nKey.  Return true on
180296 180410   ** a match.
180297 180411   */
180298 180412   static int jsonLabelCompare(JsonNode *pNode, const char *zKey, u32 nKey){
180299 180413     if( pNode->jnFlags & JNODE_RAW ){
................................................................................
180652 180766   ** Return 0 if the input is not a well-formed JSON array.
180653 180767   */
180654 180768   static void jsonArrayLengthFunc(
180655 180769     sqlite3_context *ctx,
180656 180770     int argc,
180657 180771     sqlite3_value **argv
180658 180772   ){
180659         -  JsonParse x;          /* The parse */
       180773  +  JsonParse *p;          /* The parse */
180660 180774     sqlite3_int64 n = 0;
180661 180775     u32 i;
180662 180776     JsonNode *pNode;
180663 180777   
180664         -  if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return;
180665         -  assert( x.nNode );
       180778  +  p = jsonParseCached(ctx, argv);
       180779  +  if( p==0 ) return;
       180780  +  assert( p->nNode );
180666 180781     if( argc==2 ){
180667 180782       const char *zPath = (const char*)sqlite3_value_text(argv[1]);
180668         -    pNode = jsonLookup(&x, zPath, 0, ctx);
       180783  +    pNode = jsonLookup(p, zPath, 0, ctx);
180669 180784     }else{
180670         -    pNode = x.aNode;
       180785  +    pNode = p->aNode;
180671 180786     }
180672 180787     if( pNode==0 ){
180673         -    x.nErr = 1;
180674         -  }else if( pNode->eType==JSON_ARRAY ){
       180788  +    return;
       180789  +  }
       180790  +  if( pNode->eType==JSON_ARRAY ){
180675 180791       assert( (pNode->jnFlags & JNODE_APPEND)==0 );
180676 180792       for(i=1; i<=pNode->n; n++){
180677 180793         i += jsonNodeSize(&pNode[i]);
180678 180794       }
180679 180795     }
180680         -  if( x.nErr==0 ) sqlite3_result_int64(ctx, n);
180681         -  jsonParseReset(&x);
       180796  +  sqlite3_result_int64(ctx, n);
180682 180797   }
180683 180798   
180684 180799   /*
180685 180800   ** json_extract(JSON, PATH, ...)
180686 180801   **
180687 180802   ** Return the element described by PATH.  Return NULL if there is no
180688 180803   ** PATH element.  If there are multiple PATHs, then return a JSON array
................................................................................
180690 180805   ** is malformed.
180691 180806   */
180692 180807   static void jsonExtractFunc(
180693 180808     sqlite3_context *ctx,
180694 180809     int argc,
180695 180810     sqlite3_value **argv
180696 180811   ){
180697         -  JsonParse x;          /* The parse */
       180812  +  JsonParse *p;          /* The parse */
180698 180813     JsonNode *pNode;
180699 180814     const char *zPath;
180700 180815     JsonString jx;
180701 180816     int i;
180702 180817   
180703 180818     if( argc<2 ) return;
180704         -  if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return;
       180819  +  p = jsonParseCached(ctx, argv);
       180820  +  if( p==0 ) return;
180705 180821     jsonInit(&jx, ctx);
180706 180822     jsonAppendChar(&jx, '[');
180707 180823     for(i=1; i<argc; i++){
180708 180824       zPath = (const char*)sqlite3_value_text(argv[i]);
180709         -    pNode = jsonLookup(&x, zPath, 0, ctx);
180710         -    if( x.nErr ) break;
       180825  +    pNode = jsonLookup(p, zPath, 0, ctx);
       180826  +    if( p->nErr ) break;
180711 180827       if( argc>2 ){
180712 180828         jsonAppendSeparator(&jx);
180713 180829         if( pNode ){
180714 180830           jsonRenderNode(pNode, &jx, 0);
180715 180831         }else{
180716 180832           jsonAppendRaw(&jx, "null", 4);
180717 180833         }
................................................................................
180721 180837     }
180722 180838     if( argc>2 && i==argc ){
180723 180839       jsonAppendChar(&jx, ']');
180724 180840       jsonResult(&jx);
180725 180841       sqlite3_result_subtype(ctx, JSON_SUBTYPE);
180726 180842     }
180727 180843     jsonReset(&jx);
180728         -  jsonParseReset(&x);
180729 180844   }
180730 180845   
180731 180846   /* This is the RFC 7396 MergePatch algorithm.
180732 180847   */
180733 180848   static JsonNode *jsonMergePatch(
180734 180849     JsonParse *pParse,   /* The JSON parser that contains the TARGET */
180735 180850     u32 iTarget,         /* Node of the TARGET in pParse */
................................................................................
185162 185277   static void sqlite3Fts5BufferAppendBlob(
185163 185278     int *pRc,
185164 185279     Fts5Buffer *pBuf, 
185165 185280     u32 nData, 
185166 185281     const u8 *pData
185167 185282   ){
185168 185283     assert_nc( *pRc || nData>=0 );
185169         -  if( fts5BufferGrow(pRc, pBuf, nData) ) return;
185170         -  memcpy(&pBuf->p[pBuf->n], pData, nData);
185171         -  pBuf->n += nData;
       185284  +  if( nData ){
       185285  +    if( fts5BufferGrow(pRc, pBuf, nData) ) return;
       185286  +    memcpy(&pBuf->p[pBuf->n], pData, nData);
       185287  +    pBuf->n += nData;
       185288  +  }
185172 185289   }
185173 185290   
185174 185291   /*
185175 185292   ** Append the nul-terminated string zStr to the buffer pBuf. This function
185176 185293   ** ensures that the byte following the buffer data is set to 0x00, even 
185177 185294   ** though this byte is not included in the pBuf->n count.
185178 185295   */
................................................................................
185341 185458     return SQLITE_OK;
185342 185459   }
185343 185460   
185344 185461   static void *sqlite3Fts5MallocZero(int *pRc, int nByte){
185345 185462     void *pRet = 0;
185346 185463     if( *pRc==SQLITE_OK ){
185347 185464       pRet = sqlite3_malloc(nByte);
185348         -    if( pRet==0 && nByte>0 ){
185349         -      *pRc = SQLITE_NOMEM;
       185465  +    if( pRet==0 ){
       185466  +      if( nByte>0 ) *pRc = SQLITE_NOMEM;
185350 185467       }else{
185351 185468         memset(pRet, 0, nByte);
185352 185469       }
185353 185470     }
185354 185471     return pRet;
185355 185472   }
185356 185473   
................................................................................
189303 189420     int nSlot;                      /* Size of aSlot[] array */
189304 189421     Fts5HashEntry *pScan;           /* Current ordered scan item */
189305 189422     Fts5HashEntry **aSlot;          /* Array of hash slots */
189306 189423   };
189307 189424   
189308 189425   /*
189309 189426   ** Each entry in the hash table is represented by an object of the 
189310         -** following type. Each object, its key (zKey[]) and its current data
189311         -** are stored in a single memory allocation. The position list data 
189312         -** immediately follows the key data in memory.
       189427  +** following type. Each object, its key (a nul-terminated string) and 
       189428  +** its current data are stored in a single memory allocation. The 
       189429  +** key immediately follows the object in memory. The position list
       189430  +** data immediately follows the key data in memory.
189313 189431   **
189314 189432   ** The data that follows the key is in a similar, but not identical format
189315 189433   ** to the doclist data stored in the database. It is:
189316 189434   **
189317 189435   **   * Rowid, as a varint
189318 189436   **   * Position list, without 0x00 terminator.
189319 189437   **   * Size of previous position list and rowid, as a 4 byte
................................................................................
189329 189447   struct Fts5HashEntry {
189330 189448     Fts5HashEntry *pHashNext;       /* Next hash entry with same hash-key */
189331 189449     Fts5HashEntry *pScanNext;       /* Next entry in sorted order */
189332 189450     
189333 189451     int nAlloc;                     /* Total size of allocation */
189334 189452     int iSzPoslist;                 /* Offset of space for 4-byte poslist size */
189335 189453     int nData;                      /* Total bytes of data (incl. structure) */
189336         -  int nKey;                       /* Length of zKey[] in bytes */
       189454  +  int nKey;                       /* Length of key in bytes */
189337 189455     u8 bDel;                        /* Set delete-flag @ iSzPoslist */
189338 189456     u8 bContent;                    /* Set content-flag (detail=none mode) */
189339 189457     i16 iCol;                       /* Column of last value written */
189340 189458     int iPos;                       /* Position of last value written */
189341 189459     i64 iRowid;                     /* Rowid of last value written */
189342         -  char zKey[8];                   /* Nul-terminated entry key */
189343 189460   };
189344 189461   
189345 189462   /*
189346         -** Size of Fts5HashEntry without the zKey[] array.
       189463  +** Eqivalent to:
       189464  +**
       189465  +**   char *fts5EntryKey(Fts5HashEntry *pEntry){ return zKey; }
189347 189466   */
189348         -#define FTS5_HASHENTRYSIZE (sizeof(Fts5HashEntry)-8)
189349         -
       189467  +#define fts5EntryKey(p) ( ((char *)(&(p)[1])) )
189350 189468   
189351 189469   
189352 189470   /*
189353 189471   ** Allocate a new hash table.
189354 189472   */
189355 189473   static int sqlite3Fts5HashNew(Fts5Config *pConfig, Fts5Hash **ppNew, int *pnByte){
189356 189474     int rc = SQLITE_OK;
................................................................................
189440 189558     memset(apNew, 0, nNew*sizeof(Fts5HashEntry*));
189441 189559   
189442 189560     for(i=0; i<pHash->nSlot; i++){
189443 189561       while( apOld[i] ){
189444 189562         int iHash;
189445 189563         Fts5HashEntry *p = apOld[i];
189446 189564         apOld[i] = p->pHashNext;
189447         -      iHash = fts5HashKey(nNew, (u8*)p->zKey, (int)strlen(p->zKey));
       189565  +      iHash = fts5HashKey(nNew, (u8*)fts5EntryKey(p), strlen(fts5EntryKey(p)));
189448 189566         p->pHashNext = apNew[iHash];
189449 189567         apNew[iHash] = p;
189450 189568       }
189451 189569     }
189452 189570   
189453 189571     sqlite3_free(apOld);
189454 189572     pHash->nSlot = nNew;
................................................................................
189511 189629     int bNew;                       /* If non-delete entry should be written */
189512 189630     
189513 189631     bNew = (pHash->eDetail==FTS5_DETAIL_FULL);
189514 189632   
189515 189633     /* Attempt to locate an existing hash entry */
189516 189634     iHash = fts5HashKey2(pHash->nSlot, (u8)bByte, (const u8*)pToken, nToken);
189517 189635     for(p=pHash->aSlot[iHash]; p; p=p->pHashNext){
189518         -    if( p->zKey[0]==bByte 
       189636  +    char *zKey = fts5EntryKey(p);
       189637  +    if( zKey[0]==bByte 
189519 189638        && p->nKey==nToken
189520         -     && memcmp(&p->zKey[1], pToken, nToken)==0 
       189639  +     && memcmp(&zKey[1], pToken, nToken)==0 
189521 189640       ){
189522 189641         break;
189523 189642       }
189524 189643     }
189525 189644   
189526 189645     /* If an existing hash entry cannot be found, create a new one. */
189527 189646     if( p==0 ){
189528 189647       /* Figure out how much space to allocate */
189529         -    int nByte = FTS5_HASHENTRYSIZE + (nToken+1) + 1 + 64;
       189648  +    char *zKey;
       189649  +    int nByte = sizeof(Fts5HashEntry) + (nToken+1) + 1 + 64;
189530 189650       if( nByte<128 ) nByte = 128;
189531 189651   
189532 189652       /* Grow the Fts5Hash.aSlot[] array if necessary. */
189533 189653       if( (pHash->nEntry*2)>=pHash->nSlot ){
189534 189654         int rc = fts5HashResize(pHash);
189535 189655         if( rc!=SQLITE_OK ) return rc;
189536 189656         iHash = fts5HashKey2(pHash->nSlot, (u8)bByte, (const u8*)pToken, nToken);
189537 189657       }
189538 189658   
189539 189659       /* Allocate new Fts5HashEntry and add it to the hash table. */
189540 189660       p = (Fts5HashEntry*)sqlite3_malloc(nByte);
189541 189661       if( !p ) return SQLITE_NOMEM;
189542         -    memset(p, 0, FTS5_HASHENTRYSIZE);
       189662  +    memset(p, 0, sizeof(Fts5HashEntry));
189543 189663       p->nAlloc = nByte;
189544         -    p->zKey[0] = bByte;
189545         -    memcpy(&p->zKey[1], pToken, nToken);
189546         -    assert( iHash==fts5HashKey(pHash->nSlot, (u8*)p->zKey, nToken+1) );
       189664  +    zKey = fts5EntryKey(p);
       189665  +    zKey[0] = bByte;
       189666  +    memcpy(&zKey[1], pToken, nToken);
       189667  +    assert( iHash==fts5HashKey(pHash->nSlot, (u8*)zKey, nToken+1) );
189547 189668       p->nKey = nToken;
189548         -    p->zKey[nToken+1] = '\0';
189549         -    p->nData = nToken+1 + 1 + FTS5_HASHENTRYSIZE;
       189669  +    zKey[nToken+1] = '\0';
       189670  +    p->nData = nToken+1 + 1 + sizeof(Fts5HashEntry);
189550 189671       p->pHashNext = pHash->aSlot[iHash];
189551 189672       pHash->aSlot[iHash] = p;
189552 189673       pHash->nEntry++;
189553 189674   
189554 189675       /* Add the first rowid field to the hash-entry */
189555 189676       p->nData += sqlite3Fts5PutVarint(&((u8*)p)[p->nData], iRowid);
189556 189677       p->iRowid = iRowid;
................................................................................
189660 189781         *ppOut = p2;
189661 189782         p2 = 0;
189662 189783       }else if( p2==0 ){
189663 189784         *ppOut = p1;
189664 189785         p1 = 0;
189665 189786       }else{
189666 189787         int i = 0;
189667         -      while( p1->zKey[i]==p2->zKey[i] ) i++;
       189788  +      char *zKey1 = fts5EntryKey(p1);
       189789  +      char *zKey2 = fts5EntryKey(p2);
       189790  +      while( zKey1[i]==zKey2[i] ) i++;
189668 189791   
189669         -      if( ((u8)p1->zKey[i])>((u8)p2->zKey[i]) ){
       189792  +      if( ((u8)zKey1[i])>((u8)zKey2[i]) ){
189670 189793           /* p2 is smaller */
189671 189794           *ppOut = p2;
189672 189795           ppOut = &p2->pScanNext;
189673 189796           p2 = p2->pScanNext;
189674 189797         }else{
189675 189798           /* p1 is smaller */
189676 189799           *ppOut = p1;
................................................................................
189705 189828     ap = sqlite3_malloc(sizeof(Fts5HashEntry*) * nMergeSlot);
189706 189829     if( !ap ) return SQLITE_NOMEM;
189707 189830     memset(ap, 0, sizeof(Fts5HashEntry*) * nMergeSlot);
189708 189831   
189709 189832     for(iSlot=0; iSlot<pHash->nSlot; iSlot++){
189710 189833       Fts5HashEntry *pIter;
189711 189834       for(pIter=pHash->aSlot[iSlot]; pIter; pIter=pIter->pHashNext){
189712         -      if( pTerm==0 || 0==memcmp(pIter->zKey, pTerm, nTerm) ){
       189835  +      if( pTerm==0 || 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm) ){
189713 189836           Fts5HashEntry *pEntry = pIter;
189714 189837           pEntry->pScanNext = 0;
189715 189838           for(i=0; ap[i]; i++){
189716 189839             pEntry = fts5HashEntryMerge(pEntry, ap[i]);
189717 189840             ap[i] = 0;
189718 189841           }
189719 189842           ap[i] = pEntry;
................................................................................
189738 189861   static int sqlite3Fts5HashQuery(
189739 189862     Fts5Hash *pHash,                /* Hash table to query */
189740 189863     const char *pTerm, int nTerm,   /* Query term */
189741 189864     const u8 **ppDoclist,           /* OUT: Pointer to doclist for pTerm */
189742 189865     int *pnDoclist                  /* OUT: Size of doclist in bytes */
189743 189866   ){
189744 189867     unsigned int iHash = fts5HashKey(pHash->nSlot, (const u8*)pTerm, nTerm);
       189868  +  char *zKey;
189745 189869     Fts5HashEntry *p;
189746 189870   
189747 189871     for(p=pHash->aSlot[iHash]; p; p=p->pHashNext){
189748         -    if( memcmp(p->zKey, pTerm, nTerm)==0 && p->zKey[nTerm]==0 ) break;
       189872  +    zKey = fts5EntryKey(p);
       189873  +    if( memcmp(zKey, pTerm, nTerm)==0 && zKey[nTerm]==0 ) break;
189749 189874     }
189750 189875   
189751 189876     if( p ){
189752 189877       fts5HashAddPoslistSize(pHash, p);
189753         -    *ppDoclist = (const u8*)&p->zKey[nTerm+1];
189754         -    *pnDoclist = p->nData - (FTS5_HASHENTRYSIZE + nTerm + 1);
       189878  +    *ppDoclist = (const u8*)&zKey[nTerm+1];
       189879  +    *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
189755 189880     }else{
189756 189881       *ppDoclist = 0;
189757 189882       *pnDoclist = 0;
189758 189883     }
189759 189884   
189760 189885     return SQLITE_OK;
189761 189886   }
................................................................................
189780 189905     Fts5Hash *pHash,
189781 189906     const char **pzTerm,            /* OUT: term (nul-terminated) */
189782 189907     const u8 **ppDoclist,           /* OUT: pointer to doclist */
189783 189908     int *pnDoclist                  /* OUT: size of doclist in bytes */
189784 189909   ){
189785 189910     Fts5HashEntry *p;
189786 189911     if( (p = pHash->pScan) ){
189787         -    int nTerm = (int)strlen(p->zKey);
       189912  +    char *zKey = fts5EntryKey(p);
       189913  +    int nTerm = (int)strlen(zKey);
189788 189914       fts5HashAddPoslistSize(pHash, p);
189789         -    *pzTerm = p->zKey;
189790         -    *ppDoclist = (const u8*)&p->zKey[nTerm+1];
189791         -    *pnDoclist = p->nData - (FTS5_HASHENTRYSIZE + nTerm + 1);
       189915  +    *pzTerm = zKey;
       189916  +    *ppDoclist = (const u8*)&zKey[nTerm+1];
       189917  +    *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
189792 189918     }else{
189793 189919       *pzTerm = 0;
189794 189920       *ppDoclist = 0;
189795 189921       *pnDoclist = 0;
189796 189922     }
189797 189923   }
189798 189924   
................................................................................
193987 194113     int nInput;                     /* Number of input segments */
193988 194114     Fts5SegWriter writer;           /* Writer object */
193989 194115     Fts5StructureSegment *pSeg;     /* Output segment */
193990 194116     Fts5Buffer term;
193991 194117     int bOldest;                    /* True if the output segment is the oldest */
193992 194118     int eDetail = p->pConfig->eDetail;
193993 194119     const int flags = FTS5INDEX_QUERY_NOOUTPUT;
       194120  +  int bTermWritten = 0;           /* True if current term already output */
193994 194121   
193995 194122     assert( iLvl<pStruct->nLevel );
193996 194123     assert( pLvl->nMerge<=pLvl->nSeg );
193997 194124   
193998 194125     memset(&writer, 0, sizeof(Fts5SegWriter));
193999 194126     memset(&term, 0, sizeof(Fts5Buffer));
194000 194127     if( pLvl->nMerge ){
................................................................................
194040 194167         fts5MultiIterNext(p, pIter, 0, 0)
194041 194168     ){
194042 194169       Fts5SegIter *pSegIter = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
194043 194170       int nPos;                     /* position-list size field value */
194044 194171       int nTerm;
194045 194172       const u8 *pTerm;
194046 194173   
194047         -    /* Check for key annihilation. */
194048         -    if( pSegIter->nPos==0 && (bOldest || pSegIter->bDel==0) ) continue;
194049         -
194050 194174       pTerm = fts5MultiIterTerm(pIter, &nTerm);
194051 194175       if( nTerm!=term.n || memcmp(pTerm, term.p, nTerm) ){
194052 194176         if( pnRem && writer.nLeafWritten>nRem ){
194053 194177           break;
194054 194178         }
       194179  +      fts5BufferSet(&p->rc, &term, nTerm, pTerm);
       194180  +      bTermWritten =0;
       194181  +    }
194055 194182   
       194183  +    /* Check for key annihilation. */
       194184  +    if( pSegIter->nPos==0 && (bOldest || pSegIter->bDel==0) ) continue;
       194185  +
       194186  +    if( p->rc==SQLITE_OK && bTermWritten==0 ){
194056 194187         /* This is a new term. Append a term to the output segment. */
194057 194188         fts5WriteAppendTerm(p, &writer, nTerm, pTerm);
194058         -      fts5BufferSet(&p->rc, &term, nTerm, pTerm);
       194189  +      bTermWritten = 1;
194059 194190       }
194060 194191   
194061 194192       /* Append the rowid to the output */
194062 194193       /* WRITEPOSLISTSIZE */
194063 194194       fts5WriteAppendRowid(p, &writer, fts5MultiIterRowid(pIter));
194064 194195   
194065 194196       if( eDetail==FTS5_DETAIL_NONE ){
................................................................................
194883 195014       }
194884 195015       fts5MultiIterFree(p1);
194885 195016   
194886 195017       pData = fts5IdxMalloc(p, sizeof(Fts5Data) + doclist.n);
194887 195018       if( pData ){
194888 195019         pData->p = (u8*)&pData[1];
194889 195020         pData->nn = pData->szLeaf = doclist.n;
194890         -      memcpy(pData->p, doclist.p, doclist.n);
       195021  +      if( doclist.n ) memcpy(pData->p, doclist.p, doclist.n);
194891 195022         fts5MultiIterNew2(p, pData, bDesc, ppIter);
194892 195023       }
194893 195024       fts5BufferFree(&doclist);
194894 195025     }
194895 195026   
194896 195027     fts5StructureRelease(pStruct);
194897 195028     sqlite3_free(aBuf);
................................................................................
195122 195253     Fts5Buffer buf = {0, 0, 0};
195123 195254   
195124 195255     /* If the QUERY_SCAN flag is set, all other flags must be clear. */
195125 195256     assert( (flags & FTS5INDEX_QUERY_SCAN)==0 || flags==FTS5INDEX_QUERY_SCAN );
195126 195257   
195127 195258     if( sqlite3Fts5BufferSize(&p->rc, &buf, nToken+1)==0 ){
195128 195259       int iIdx = 0;                 /* Index to search */
195129         -    memcpy(&buf.p[1], pToken, nToken);
       195260  +    if( nToken ) memcpy(&buf.p[1], pToken, nToken);
195130 195261   
195131 195262       /* Figure out which index to search and set iIdx accordingly. If this
195132 195263       ** is a prefix query for which there is no prefix index, set iIdx to
195133 195264       ** greater than pConfig->nPrefix to indicate that the query will be
195134 195265       ** satisfied by scanning multiple terms in the main index.
195135 195266       **
195136 195267       ** If the QUERY_TEST_NOIDX flag was specified, then this must be a
................................................................................
195171 195302         if( p->rc==SQLITE_OK ){
195172 195303           Fts5SegIter *pSeg = &pRet->aSeg[pRet->aFirst[1].iFirst];
195173 195304           if( pSeg->pLeaf ) pRet->xSetOutputs(pRet, pSeg);
195174 195305         }
195175 195306       }
195176 195307   
195177 195308       if( p->rc ){
195178         -      sqlite3Fts5IterClose(&pRet->base);
       195309  +      sqlite3Fts5IterClose((Fts5IndexIter*)pRet);
195179 195310         pRet = 0;
195180 195311         fts5CloseReader(p);
195181 195312       }
195182 195313   
195183 195314       *ppIter = &pRet->base;
195184 195315       sqlite3Fts5BufferFree(&buf);
195185 195316     }
................................................................................
198911 199042   static void fts5SourceIdFunc(
198912 199043     sqlite3_context *pCtx,          /* Function call context */
198913 199044     int nArg,                       /* Number of args */
198914 199045     sqlite3_value **apUnused        /* Function arguments */
198915 199046   ){
198916 199047     assert( nArg==0 );
198917 199048     UNUSED_PARAM2(nArg, apUnused);
198918         -  sqlite3_result_text(pCtx, "fts5: 2017-05-10 16:33:48 92c5ea7047323d10f762877c5f56d20a3e609e8b55efcfe4880ef3048821ac1f", -1, SQLITE_TRANSIENT);
       199049  +  sqlite3_result_text(pCtx, "fts5: 2017-05-24 13:08:33 f6d7b988f40217821a382bc298180e9e6794f3ed79a83c6ef5cae048989b3f86", -1, SQLITE_TRANSIENT);
198919 199050   }
198920 199051   
198921 199052   static int fts5Init(sqlite3 *db){
198922 199053     static const sqlite3_module fts5Mod = {
198923 199054       /* iVersion      */ 2,
198924 199055       /* xCreate       */ fts5CreateMethod,
198925 199056       /* xConnect      */ fts5ConnectMethod,

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

   117    117   ** string contains the date and time of the check-in (UTC) and a SHA1
   118    118   ** or SHA3-256 hash of the entire source tree.
   119    119   **
   120    120   ** See also: [sqlite3_libversion()],
   121    121   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   122    122   ** [sqlite_version()] and [sqlite_source_id()].
   123    123   */
   124         -#define SQLITE_VERSION        "3.19.0"
   125         -#define SQLITE_VERSION_NUMBER 3019000
   126         -#define SQLITE_SOURCE_ID      "2017-05-10 16:33:48 92c5ea7047323d10f762877c5f56d20a3e609e8b55efcfe4880ef3048821ac1f"
          124  +#define SQLITE_VERSION        "3.19.1"
          125  +#define SQLITE_VERSION_NUMBER 3019001
          126  +#define SQLITE_SOURCE_ID      "2017-05-24 13:08:33 f6d7b988f40217821a382bc298180e9e6794f3ed79a83c6ef5cae048989b3f86"
   127    127   
   128    128   /*
   129    129   ** CAPI3REF: Run-Time Library Version Numbers
   130    130   ** KEYWORDS: sqlite3_version sqlite3_sourceid
   131    131   **
   132    132   ** These interfaces provide the same information as the [SQLITE_VERSION],
   133    133   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
  2697   2697   ** authorizer will fail with an error message explaining that
  2698   2698   ** access is denied. 
  2699   2699   **
  2700   2700   ** ^The first parameter to the authorizer callback is a copy of the third
  2701   2701   ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
  2702   2702   ** to the callback is an integer [SQLITE_COPY | action code] that specifies
  2703   2703   ** the particular action to be authorized. ^The third through sixth parameters
  2704         -** to the callback are zero-terminated strings that contain additional
  2705         -** details about the action to be authorized.
         2704  +** to the callback are either NULL pointers or zero-terminated strings
         2705  +** that contain additional details about the action to be authorized.
         2706  +** Applications must always be prepared to encounter a NULL pointer in any
         2707  +** of the third through the sixth parameters of the authorization callback.
  2706   2708   **
  2707   2709   ** ^If the action code is [SQLITE_READ]
  2708   2710   ** and the callback returns [SQLITE_IGNORE] then the
  2709   2711   ** [prepared statement] statement is constructed to substitute
  2710   2712   ** a NULL value in place of the table column that would have
  2711   2713   ** been read if [SQLITE_OK] had been returned.  The [SQLITE_IGNORE]
  2712   2714   ** return can be used to deny an untrusted user access to individual
  2713   2715   ** columns of a table.
  2714   2716   ** ^When a table is referenced by a [SELECT] but no column values are
  2715   2717   ** extracted from that table (for example in a query like
  2716   2718   ** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
  2717         -** is invoked once for that table with a NULL column name.
         2719  +** is invoked once for that table with a column name that is an empty string.
  2718   2720   ** ^If the action code is [SQLITE_DELETE] and the callback returns
  2719   2721   ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
  2720   2722   ** [truncate optimization] is disabled and all rows are deleted individually.
  2721   2723   **
  2722   2724   ** An authorizer is used when [sqlite3_prepare | preparing]
  2723   2725   ** SQL statements from an untrusted source, to ensure that the SQL statements
  2724   2726   ** do not try to access data they are not allowed to see, or that they do not
................................................................................
  4757   4759   ** of where this might be useful is in a regular-expression matching
  4758   4760   ** function. The compiled version of the regular expression can be stored as
  4759   4761   ** metadata associated with the pattern string.  
  4760   4762   ** Then as long as the pattern string remains the same,
  4761   4763   ** the compiled regular expression can be reused on multiple
  4762   4764   ** invocations of the same function.
  4763   4765   **
  4764         -** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
  4765         -** associated by the sqlite3_set_auxdata() function with the Nth argument
  4766         -** value to the application-defined function. ^If there is no metadata
  4767         -** associated with the function argument, this sqlite3_get_auxdata() interface
         4766  +** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata
         4767  +** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument
         4768  +** value to the application-defined function.  ^N is zero for the left-most
         4769  +** function argument.  ^If there is no metadata
         4770  +** associated with the function argument, the sqlite3_get_auxdata(C,N) interface
  4768   4771   ** returns a NULL pointer.
  4769   4772   **
  4770   4773   ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
  4771   4774   ** argument of the application-defined function.  ^Subsequent
  4772   4775   ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
  4773   4776   ** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or
  4774   4777   ** NULL if the metadata has been discarded.
................................................................................
  4790   4793   ** should be called near the end of the function implementation and the
  4791   4794   ** function implementation should not make any use of P after
  4792   4795   ** sqlite3_set_auxdata() has been called.
  4793   4796   **
  4794   4797   ** ^(In practice, metadata is preserved between function calls for
  4795   4798   ** function parameters that are compile-time constants, including literal
  4796   4799   ** values and [parameters] and expressions composed from the same.)^
         4800  +**
         4801  +** The value of the N parameter to these interfaces should be non-negative.
         4802  +** Future enhancements may make use of negative N values to define new
         4803  +** kinds of function caching behavior.
  4797   4804   **
  4798   4805   ** These routines must be called from the same thread in which
  4799   4806   ** the SQL function is running.
  4800   4807   */
  4801   4808   SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
  4802   4809   SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
  4803   4810   
................................................................................
  9385   9392   ** Any number of calls to add() and output() may be made between the calls to
  9386   9393   ** new() and delete(), and in any order.
  9387   9394   **
  9388   9395   ** As well as the regular sqlite3changegroup_add() and 
  9389   9396   ** sqlite3changegroup_output() functions, also available are the streaming
  9390   9397   ** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
  9391   9398   */
  9392         -int sqlite3changegroup_new(sqlite3_changegroup **pp);
         9399  +SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp);
  9393   9400   
  9394   9401   /*
  9395   9402   ** CAPI3REF: Add A Changeset To A Changegroup
  9396   9403   **
  9397   9404   ** Add all changes within the changeset (or patchset) in buffer pData (size
  9398   9405   ** nData bytes) to the changegroup. 
  9399   9406   **
................................................................................
  9462   9469   ** appears to be corrupt and the corruption is detected, SQLITE_CORRUPT is
  9463   9470   ** returned. Or, if an out-of-memory condition occurs during processing, this
  9464   9471   ** function returns SQLITE_NOMEM. In all cases, if an error occurs the
  9465   9472   ** final contents of the changegroup is undefined.
  9466   9473   **
  9467   9474   ** If no error occurs, SQLITE_OK is returned.
  9468   9475   */
  9469         -int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
         9476  +SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
  9470   9477   
  9471   9478   /*
  9472   9479   ** CAPI3REF: Obtain A Composite Changeset From A Changegroup
  9473   9480   **
  9474   9481   ** Obtain a buffer containing a changeset (or patchset) representing the
  9475   9482   ** current contents of the changegroup. If the inputs to the changegroup
  9476   9483   ** were themselves changesets, the output is a changeset. Or, if the
................................................................................
  9488   9495   ** If an error occurs, an SQLite error code is returned and the output
  9489   9496   ** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK
  9490   9497   ** is returned and the output variables are set to the size of and a 
  9491   9498   ** pointer to the output buffer, respectively. In this case it is the
  9492   9499   ** responsibility of the caller to eventually free the buffer using a
  9493   9500   ** call to sqlite3_free().
  9494   9501   */
  9495         -int sqlite3changegroup_output(
         9502  +SQLITE_API int sqlite3changegroup_output(
  9496   9503     sqlite3_changegroup*,
  9497   9504     int *pnData,                    /* OUT: Size of output buffer in bytes */
  9498   9505     void **ppData                   /* OUT: Pointer to output buffer */
  9499   9506   );
  9500   9507   
  9501   9508   /*
  9502   9509   ** CAPI3REF: Delete A Changegroup Object
  9503   9510   */
  9504         -void sqlite3changegroup_delete(sqlite3_changegroup*);
         9511  +SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*);
  9505   9512   
  9506   9513   /*
  9507   9514   ** CAPI3REF: Apply A Changeset To A Database
  9508   9515   **
  9509   9516   ** Apply a changeset to a database. This function attempts to update the
  9510   9517   ** "main" database attached to handle db with the changes found in the
  9511   9518   ** changeset passed via the second and third arguments.
................................................................................
  9886   9893     void *pOut
  9887   9894   );
  9888   9895   SQLITE_API int sqlite3session_patchset_strm(
  9889   9896     sqlite3_session *pSession,
  9890   9897     int (*xOutput)(void *pOut, const void *pData, int nData),
  9891   9898     void *pOut
  9892   9899   );
  9893         -int sqlite3changegroup_add_strm(sqlite3_changegroup*, 
         9900  +SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup*, 
  9894   9901       int (*xInput)(void *pIn, void *pData, int *pnData),
  9895   9902       void *pIn
  9896   9903   );
  9897         -int sqlite3changegroup_output_strm(sqlite3_changegroup*,
         9904  +SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*,
  9898   9905       int (*xOutput)(void *pOut, const void *pData, int nData), 
  9899   9906       void *pOut
  9900   9907   );
  9901   9908   
  9902   9909   
  9903   9910   /*
  9904   9911   ** Make sure we can call this stuff from C++.

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

  3532   3532   static void sqlite3Fts5BufferAppendBlob(
  3533   3533     int *pRc,
  3534   3534     Fts5Buffer *pBuf, 
  3535   3535     u32 nData, 
  3536   3536     const u8 *pData
  3537   3537   ){
  3538   3538     assert_nc( *pRc || nData>=0 );
  3539         -  if( fts5BufferGrow(pRc, pBuf, nData) ) return;
  3540         -  memcpy(&pBuf->p[pBuf->n], pData, nData);
  3541         -  pBuf->n += nData;
         3539  +  if( nData ){
         3540  +    if( fts5BufferGrow(pRc, pBuf, nData) ) return;
         3541  +    memcpy(&pBuf->p[pBuf->n], pData, nData);
         3542  +    pBuf->n += nData;
         3543  +  }
  3542   3544   }
  3543   3545   
  3544   3546   /*
  3545   3547   ** Append the nul-terminated string zStr to the buffer pBuf. This function
  3546   3548   ** ensures that the byte following the buffer data is set to 0x00, even 
  3547   3549   ** though this byte is not included in the pBuf->n count.
  3548   3550   */
................................................................................
  3711   3713     return SQLITE_OK;
  3712   3714   }
  3713   3715   
  3714   3716   static void *sqlite3Fts5MallocZero(int *pRc, int nByte){
  3715   3717     void *pRet = 0;
  3716   3718     if( *pRc==SQLITE_OK ){
  3717   3719       pRet = sqlite3_malloc(nByte);
  3718         -    if( pRet==0 && nByte>0 ){
  3719         -      *pRc = SQLITE_NOMEM;
         3720  +    if( pRet==0 ){
         3721  +      if( nByte>0 ) *pRc = SQLITE_NOMEM;
  3720   3722       }else{
  3721   3723         memset(pRet, 0, nByte);
  3722   3724       }
  3723   3725     }
  3724   3726     return pRet;
  3725   3727   }
  3726   3728   
................................................................................
  7676   7678     int nSlot;                      /* Size of aSlot[] array */
  7677   7679     Fts5HashEntry *pScan;           /* Current ordered scan item */
  7678   7680     Fts5HashEntry **aSlot;          /* Array of hash slots */
  7679   7681   };
  7680   7682   
  7681   7683   /*
  7682   7684   ** Each entry in the hash table is represented by an object of the 
  7683         -** following type. Each object, its key (zKey[]) and its current data
  7684         -** are stored in a single memory allocation. The position list data 
  7685         -** immediately follows the key data in memory.
         7685  +** following type. Each object, its key (a nul-terminated string) and 
         7686  +** its current data are stored in a single memory allocation. The 
         7687  +** key immediately follows the object in memory. The position list
         7688  +** data immediately follows the key data in memory.
  7686   7689   **
  7687   7690   ** The data that follows the key is in a similar, but not identical format
  7688   7691   ** to the doclist data stored in the database. It is:
  7689   7692   **
  7690   7693   **   * Rowid, as a varint
  7691   7694   **   * Position list, without 0x00 terminator.
  7692   7695   **   * Size of previous position list and rowid, as a 4 byte
................................................................................
  7702   7705   struct Fts5HashEntry {
  7703   7706     Fts5HashEntry *pHashNext;       /* Next hash entry with same hash-key */
  7704   7707     Fts5HashEntry *pScanNext;       /* Next entry in sorted order */
  7705   7708     
  7706   7709     int nAlloc;                     /* Total size of allocation */
  7707   7710     int iSzPoslist;                 /* Offset of space for 4-byte poslist size */
  7708   7711     int nData;                      /* Total bytes of data (incl. structure) */
  7709         -  int nKey;                       /* Length of zKey[] in bytes */
         7712  +  int nKey;                       /* Length of key in bytes */
  7710   7713     u8 bDel;                        /* Set delete-flag @ iSzPoslist */
  7711   7714     u8 bContent;                    /* Set content-flag (detail=none mode) */
  7712   7715     i16 iCol;                       /* Column of last value written */
  7713   7716     int iPos;                       /* Position of last value written */
  7714   7717     i64 iRowid;                     /* Rowid of last value written */
  7715         -  char zKey[8];                   /* Nul-terminated entry key */
  7716   7718   };
  7717   7719   
  7718   7720   /*
  7719         -** Size of Fts5HashEntry without the zKey[] array.
         7721  +** Eqivalent to:
         7722  +**
         7723  +**   char *fts5EntryKey(Fts5HashEntry *pEntry){ return zKey; }
  7720   7724   */
  7721         -#define FTS5_HASHENTRYSIZE (sizeof(Fts5HashEntry)-8)
  7722         -
         7725  +#define fts5EntryKey(p) ( ((char *)(&(p)[1])) )
  7723   7726   
  7724   7727   
  7725   7728   /*
  7726   7729   ** Allocate a new hash table.
  7727   7730   */
  7728   7731   static int sqlite3Fts5HashNew(Fts5Config *pConfig, Fts5Hash **ppNew, int *pnByte){
  7729   7732     int rc = SQLITE_OK;
................................................................................
  7813   7816     memset(apNew, 0, nNew*sizeof(Fts5HashEntry*));
  7814   7817   
  7815   7818     for(i=0; i<pHash->nSlot; i++){
  7816   7819       while( apOld[i] ){
  7817   7820         int iHash;
  7818   7821         Fts5HashEntry *p = apOld[i];
  7819   7822         apOld[i] = p->pHashNext;
  7820         -      iHash = fts5HashKey(nNew, (u8*)p->zKey, (int)strlen(p->zKey));
         7823  +      iHash = fts5HashKey(nNew, (u8*)fts5EntryKey(p), strlen(fts5EntryKey(p)));
  7821   7824         p->pHashNext = apNew[iHash];
  7822   7825         apNew[iHash] = p;
  7823   7826       }
  7824   7827     }
  7825   7828   
  7826   7829     sqlite3_free(apOld);
  7827   7830     pHash->nSlot = nNew;
................................................................................
  7884   7887     int bNew;                       /* If non-delete entry should be written */
  7885   7888     
  7886   7889     bNew = (pHash->eDetail==FTS5_DETAIL_FULL);
  7887   7890   
  7888   7891     /* Attempt to locate an existing hash entry */
  7889   7892     iHash = fts5HashKey2(pHash->nSlot, (u8)bByte, (const u8*)pToken, nToken);
  7890   7893     for(p=pHash->aSlot[iHash]; p; p=p->pHashNext){
  7891         -    if( p->zKey[0]==bByte 
         7894  +    char *zKey = fts5EntryKey(p);
         7895  +    if( zKey[0]==bByte 
  7892   7896        && p->nKey==nToken
  7893         -     && memcmp(&p->zKey[1], pToken, nToken)==0 
         7897  +     && memcmp(&zKey[1], pToken, nToken)==0 
  7894   7898       ){
  7895   7899         break;
  7896   7900       }
  7897   7901     }
  7898   7902   
  7899   7903     /* If an existing hash entry cannot be found, create a new one. */
  7900   7904     if( p==0 ){
  7901   7905       /* Figure out how much space to allocate */
  7902         -    int nByte = FTS5_HASHENTRYSIZE + (nToken+1) + 1 + 64;
         7906  +    char *zKey;
         7907  +    int nByte = sizeof(Fts5HashEntry) + (nToken+1) + 1 + 64;
  7903   7908       if( nByte<128 ) nByte = 128;
  7904   7909   
  7905   7910       /* Grow the Fts5Hash.aSlot[] array if necessary. */
  7906   7911       if( (pHash->nEntry*2)>=pHash->nSlot ){
  7907   7912         int rc = fts5HashResize(pHash);
  7908   7913         if( rc!=SQLITE_OK ) return rc;
  7909   7914         iHash = fts5HashKey2(pHash->nSlot, (u8)bByte, (const u8*)pToken, nToken);
  7910   7915       }
  7911   7916   
  7912   7917       /* Allocate new Fts5HashEntry and add it to the hash table. */
  7913   7918       p = (Fts5HashEntry*)sqlite3_malloc(nByte);
  7914   7919       if( !p ) return SQLITE_NOMEM;
  7915         -    memset(p, 0, FTS5_HASHENTRYSIZE);
         7920  +    memset(p, 0, sizeof(Fts5HashEntry));
  7916   7921       p->nAlloc = nByte;
  7917         -    p->zKey[0] = bByte;
  7918         -    memcpy(&p->zKey[1], pToken, nToken);
  7919         -    assert( iHash==fts5HashKey(pHash->nSlot, (u8*)p->zKey, nToken+1) );
         7922  +    zKey = fts5EntryKey(p);
         7923  +    zKey[0] = bByte;
         7924  +    memcpy(&zKey[1], pToken, nToken);
         7925  +    assert( iHash==fts5HashKey(pHash->nSlot, (u8*)zKey, nToken+1) );
  7920   7926       p->nKey = nToken;
  7921         -    p->zKey[nToken+1] = '\0';
  7922         -    p->nData = nToken+1 + 1 + FTS5_HASHENTRYSIZE;
         7927  +    zKey[nToken+1] = '\0';
         7928  +    p->nData = nToken+1 + 1 + sizeof(Fts5HashEntry);
  7923   7929       p->pHashNext = pHash->aSlot[iHash];
  7924   7930       pHash->aSlot[iHash] = p;
  7925   7931       pHash->nEntry++;
  7926   7932   
  7927   7933       /* Add the first rowid field to the hash-entry */
  7928   7934       p->nData += sqlite3Fts5PutVarint(&((u8*)p)[p->nData], iRowid);
  7929   7935       p->iRowid = iRowid;
................................................................................
  8033   8039         *ppOut = p2;
  8034   8040         p2 = 0;
  8035   8041       }else if( p2==0 ){
  8036   8042         *ppOut = p1;
  8037   8043         p1 = 0;
  8038   8044       }else{
  8039   8045         int i = 0;
  8040         -      while( p1->zKey[i]==p2->zKey[i] ) i++;
         8046  +      char *zKey1 = fts5EntryKey(p1);
         8047  +      char *zKey2 = fts5EntryKey(p2);
         8048  +      while( zKey1[i]==zKey2[i] ) i++;
  8041   8049   
  8042         -      if( ((u8)p1->zKey[i])>((u8)p2->zKey[i]) ){
         8050  +      if( ((u8)zKey1[i])>((u8)zKey2[i]) ){
  8043   8051           /* p2 is smaller */
  8044   8052           *ppOut = p2;
  8045   8053           ppOut = &p2->pScanNext;
  8046   8054           p2 = p2->pScanNext;
  8047   8055         }else{
  8048   8056           /* p1 is smaller */
  8049   8057           *ppOut = p1;
................................................................................
  8078   8086     ap = sqlite3_malloc(sizeof(Fts5HashEntry*) * nMergeSlot);
  8079   8087     if( !ap ) return SQLITE_NOMEM;
  8080   8088     memset(ap, 0, sizeof(Fts5HashEntry*) * nMergeSlot);
  8081   8089   
  8082   8090     for(iSlot=0; iSlot<pHash->nSlot; iSlot++){
  8083   8091       Fts5HashEntry *pIter;
  8084   8092       for(pIter=pHash->aSlot[iSlot]; pIter; pIter=pIter->pHashNext){
  8085         -      if( pTerm==0 || 0==memcmp(pIter->zKey, pTerm, nTerm) ){
         8093  +      if( pTerm==0 || 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm) ){
  8086   8094           Fts5HashEntry *pEntry = pIter;
  8087   8095           pEntry->pScanNext = 0;
  8088   8096           for(i=0; ap[i]; i++){
  8089   8097             pEntry = fts5HashEntryMerge(pEntry, ap[i]);
  8090   8098             ap[i] = 0;
  8091   8099           }
  8092   8100           ap[i] = pEntry;
................................................................................
  8111   8119   static int sqlite3Fts5HashQuery(
  8112   8120     Fts5Hash *pHash,                /* Hash table to query */
  8113   8121     const char *pTerm, int nTerm,   /* Query term */
  8114   8122     const u8 **ppDoclist,           /* OUT: Pointer to doclist for pTerm */
  8115   8123     int *pnDoclist                  /* OUT: Size of doclist in bytes */
  8116   8124   ){
  8117   8125     unsigned int iHash = fts5HashKey(pHash->nSlot, (const u8*)pTerm, nTerm);
         8126  +  char *zKey;
  8118   8127     Fts5HashEntry *p;
  8119   8128   
  8120   8129     for(p=pHash->aSlot[iHash]; p; p=p->pHashNext){
  8121         -    if( memcmp(p->zKey, pTerm, nTerm)==0 && p->zKey[nTerm]==0 ) break;
         8130  +    zKey = fts5EntryKey(p);
         8131  +    if( memcmp(zKey, pTerm, nTerm)==0 && zKey[nTerm]==0 ) break;
  8122   8132     }
  8123   8133   
  8124   8134     if( p ){
  8125   8135       fts5HashAddPoslistSize(pHash, p);
  8126         -    *ppDoclist = (const u8*)&p->zKey[nTerm+1];
  8127         -    *pnDoclist = p->nData - (FTS5_HASHENTRYSIZE + nTerm + 1);
         8136  +    *ppDoclist = (const u8*)&zKey[nTerm+1];
         8137  +    *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
  8128   8138     }else{
  8129   8139       *ppDoclist = 0;
  8130   8140       *pnDoclist = 0;
  8131   8141     }
  8132   8142   
  8133   8143     return SQLITE_OK;
  8134   8144   }
................................................................................
  8153   8163     Fts5Hash *pHash,
  8154   8164     const char **pzTerm,            /* OUT: term (nul-terminated) */
  8155   8165     const u8 **ppDoclist,           /* OUT: pointer to doclist */
  8156   8166     int *pnDoclist                  /* OUT: size of doclist in bytes */
  8157   8167   ){
  8158   8168     Fts5HashEntry *p;
  8159   8169     if( (p = pHash->pScan) ){
  8160         -    int nTerm = (int)strlen(p->zKey);
         8170  +    char *zKey = fts5EntryKey(p);
         8171  +    int nTerm = (int)strlen(zKey);
  8161   8172       fts5HashAddPoslistSize(pHash, p);
  8162         -    *pzTerm = p->zKey;
  8163         -    *ppDoclist = (const u8*)&p->zKey[nTerm+1];
  8164         -    *pnDoclist = p->nData - (FTS5_HASHENTRYSIZE + nTerm + 1);
         8173  +    *pzTerm = zKey;
         8174  +    *ppDoclist = (const u8*)&zKey[nTerm+1];
         8175  +    *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
  8165   8176     }else{
  8166   8177       *pzTerm = 0;
  8167   8178       *ppDoclist = 0;
  8168   8179       *pnDoclist = 0;
  8169   8180     }
  8170   8181   }
  8171   8182   
................................................................................
 12361  12372     int nInput;                     /* Number of input segments */
 12362  12373     Fts5SegWriter writer;           /* Writer object */
 12363  12374     Fts5StructureSegment *pSeg;     /* Output segment */
 12364  12375     Fts5Buffer term;
 12365  12376     int bOldest;                    /* True if the output segment is the oldest */
 12366  12377     int eDetail = p->pConfig->eDetail;
 12367  12378     const int flags = FTS5INDEX_QUERY_NOOUTPUT;
        12379  +  int bTermWritten = 0;           /* True if current term already output */
 12368  12380   
 12369  12381     assert( iLvl<pStruct->nLevel );
 12370  12382     assert( pLvl->nMerge<=pLvl->nSeg );
 12371  12383   
 12372  12384     memset(&writer, 0, sizeof(Fts5SegWriter));
 12373  12385     memset(&term, 0, sizeof(Fts5Buffer));
 12374  12386     if( pLvl->nMerge ){
................................................................................
 12414  12426         fts5MultiIterNext(p, pIter, 0, 0)
 12415  12427     ){
 12416  12428       Fts5SegIter *pSegIter = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
 12417  12429       int nPos;                     /* position-list size field value */
 12418  12430       int nTerm;
 12419  12431       const u8 *pTerm;
 12420  12432   
 12421         -    /* Check for key annihilation. */
 12422         -    if( pSegIter->nPos==0 && (bOldest || pSegIter->bDel==0) ) continue;
 12423         -
 12424  12433       pTerm = fts5MultiIterTerm(pIter, &nTerm);
 12425  12434       if( nTerm!=term.n || memcmp(pTerm, term.p, nTerm) ){
 12426  12435         if( pnRem && writer.nLeafWritten>nRem ){
 12427  12436           break;
 12428  12437         }
        12438  +      fts5BufferSet(&p->rc, &term, nTerm, pTerm);
        12439  +      bTermWritten =0;
        12440  +    }
 12429  12441   
        12442  +    /* Check for key annihilation. */
        12443  +    if( pSegIter->nPos==0 && (bOldest || pSegIter->bDel==0) ) continue;
        12444  +
        12445  +    if( p->rc==SQLITE_OK && bTermWritten==0 ){
 12430  12446         /* This is a new term. Append a term to the output segment. */
 12431  12447         fts5WriteAppendTerm(p, &writer, nTerm, pTerm);
 12432         -      fts5BufferSet(&p->rc, &term, nTerm, pTerm);
        12448  +      bTermWritten = 1;
 12433  12449       }
 12434  12450   
 12435  12451       /* Append the rowid to the output */
 12436  12452       /* WRITEPOSLISTSIZE */
 12437  12453       fts5WriteAppendRowid(p, &writer, fts5MultiIterRowid(pIter));
 12438  12454   
 12439  12455       if( eDetail==FTS5_DETAIL_NONE ){
................................................................................
 13257  13273       }
 13258  13274       fts5MultiIterFree(p1);
 13259  13275   
 13260  13276       pData = fts5IdxMalloc(p, sizeof(Fts5Data) + doclist.n);
 13261  13277       if( pData ){
 13262  13278         pData->p = (u8*)&pData[1];
 13263  13279         pData->nn = pData->szLeaf = doclist.n;
 13264         -      memcpy(pData->p, doclist.p, doclist.n);
        13280  +      if( doclist.n ) memcpy(pData->p, doclist.p, doclist.n);
 13265  13281         fts5MultiIterNew2(p, pData, bDesc, ppIter);
 13266  13282       }
 13267  13283       fts5BufferFree(&doclist);
 13268  13284     }
 13269  13285   
 13270  13286     fts5StructureRelease(pStruct);
 13271  13287     sqlite3_free(aBuf);
................................................................................
 13496  13512     Fts5Buffer buf = {0, 0, 0};
 13497  13513   
 13498  13514     /* If the QUERY_SCAN flag is set, all other flags must be clear. */
 13499  13515     assert( (flags & FTS5INDEX_QUERY_SCAN)==0 || flags==FTS5INDEX_QUERY_SCAN );
 13500  13516   
 13501  13517     if( sqlite3Fts5BufferSize(&p->rc, &buf, nToken+1)==0 ){
 13502  13518       int iIdx = 0;                 /* Index to search */
 13503         -    memcpy(&buf.p[1], pToken, nToken);
        13519  +    if( nToken ) memcpy(&buf.p[1], pToken, nToken);
 13504  13520   
 13505  13521       /* Figure out which index to search and set iIdx accordingly. If this
 13506  13522       ** is a prefix query for which there is no prefix index, set iIdx to
 13507  13523       ** greater than pConfig->nPrefix to indicate that the query will be
 13508  13524       ** satisfied by scanning multiple terms in the main index.
 13509  13525       **
 13510  13526       ** If the QUERY_TEST_NOIDX flag was specified, then this must be a
................................................................................
 13545  13561         if( p->rc==SQLITE_OK ){
 13546  13562           Fts5SegIter *pSeg = &pRet->aSeg[pRet->aFirst[1].iFirst];
 13547  13563           if( pSeg->pLeaf ) pRet->xSetOutputs(pRet, pSeg);
 13548  13564         }
 13549  13565       }
 13550  13566   
 13551  13567       if( p->rc ){
 13552         -      sqlite3Fts5IterClose(&pRet->base);
        13568  +      sqlite3Fts5IterClose((Fts5IndexIter*)pRet);
 13553  13569         pRet = 0;
 13554  13570         fts5CloseReader(p);
 13555  13571       }
 13556  13572   
 13557  13573       *ppIter = &pRet->base;
 13558  13574       sqlite3Fts5BufferFree(&buf);
 13559  13575     }
................................................................................
 17286  17302   static void fts5SourceIdFunc(
 17287  17303     sqlite3_context *pCtx,          /* Function call context */
 17288  17304     int nArg,                       /* Number of args */
 17289  17305     sqlite3_value **apUnused        /* Function arguments */
 17290  17306   ){
 17291  17307     assert( nArg==0 );
 17292  17308     UNUSED_PARAM2(nArg, apUnused);
 17293         -  sqlite3_result_text(pCtx, "fts5: 2017-05-10 16:33:48 92c5ea7047323d10f762877c5f56d20a3e609e8b55efcfe4880ef3048821ac1f", -1, SQLITE_TRANSIENT);
        17309  +  sqlite3_result_text(pCtx, "fts5: 2017-05-24 13:08:33 f6d7b988f40217821a382bc298180e9e6794f3ed79a83c6ef5cae048989b3f86", -1, SQLITE_TRANSIENT);
 17294  17310   }
 17295  17311   
 17296  17312   static int fts5Init(sqlite3 *db){
 17297  17313     static const sqlite3_module fts5Mod = {
 17298  17314       /* iVersion      */ 2,
 17299  17315       /* xCreate       */ fts5CreateMethod,
 17300  17316       /* xConnect      */ fts5ConnectMethod,

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

   167    167     u32 nAlloc;        /* Number of slots of aNode[] allocated */
   168    168     JsonNode *aNode;   /* Array of nodes containing the parse */
   169    169     const char *zJson; /* Original JSON string */
   170    170     u32 *aUp;          /* Index of parent of each node */
   171    171     u8 oom;            /* Set to true if out of memory */
   172    172     u8 nErr;           /* Number of errors seen */
   173    173     u16 iDepth;        /* Nesting depth */
          174  +  int nJson;         /* Length of the zJson string in bytes */
   174    175   };
   175    176   
   176    177   /*
   177    178   ** Maximum nesting depth of JSON for this implementation.
   178    179   **
   179    180   ** This limit is needed to avoid a stack overflow in the recursive
   180    181   ** descent parser.  A depth of 2000 is far deeper than any sane JSON
................................................................................
   408    409     sqlite3_free(pParse->aNode);
   409    410     pParse->aNode = 0;
   410    411     pParse->nNode = 0;
   411    412     pParse->nAlloc = 0;
   412    413     sqlite3_free(pParse->aUp);
   413    414     pParse->aUp = 0;
   414    415   }
          416  +
          417  +/*
          418  +** Free a JsonParse object that was obtained from sqlite3_malloc().
          419  +*/
          420  +static void jsonParseFree(JsonParse *pParse){
          421  +  jsonParseReset(pParse);
          422  +  sqlite3_free(pParse);
          423  +}
   415    424   
   416    425   /*
   417    426   ** Convert the JsonNode pNode into a pure JSON string and
   418    427   ** append to pOut.  Subsubstructure is also included.  Return
   419    428   ** the number of JsonNode objects that are encoded.
   420    429   */
   421    430   static void jsonRenderNode(
................................................................................
   959    968     if( aUp==0 ){
   960    969       pParse->oom = 1;
   961    970       return SQLITE_NOMEM;
   962    971     }
   963    972     jsonParseFillInParentage(pParse, 0, 0);
   964    973     return SQLITE_OK;
   965    974   }
          975  +
          976  +/*
          977  +** Magic number used for the JSON parse cache in sqlite3_get_auxdata()
          978  +*/
          979  +#define JSON_CACHE_ID  (-429938)
          980  +
          981  +/*
          982  +** Obtain a complete parse of the JSON found in the first argument
          983  +** of the argv array.  Use the sqlite3_get_auxdata() cache for this
          984  +** parse if it is available.  If the cache is not available or if it
          985  +** is no longer valid, parse the JSON again and return the new parse,
          986  +** and also register the new parse so that it will be available for
          987  +** future sqlite3_get_auxdata() calls.
          988  +*/
          989  +static JsonParse *jsonParseCached(
          990  +  sqlite3_context *pCtx,
          991  +  sqlite3_value **argv
          992  +){
          993  +  const char *zJson = (const char*)sqlite3_value_text(argv[0]);
          994  +  int nJson = sqlite3_value_bytes(argv[0]);
          995  +  JsonParse *p;
          996  +  if( zJson==0 ) return 0;
          997  +  p = (JsonParse*)sqlite3_get_auxdata(pCtx, JSON_CACHE_ID);
          998  +  if( p && p->nJson==nJson && memcmp(p->zJson,zJson,nJson)==0 ){
          999  +    p->nErr = 0;
         1000  +    return p; /* The cached entry matches, so return it */
         1001  +  }
         1002  +  p = sqlite3_malloc( sizeof(*p) + nJson + 1 );
         1003  +  if( p==0 ){
         1004  +    sqlite3_result_error_nomem(pCtx);
         1005  +    return 0;
         1006  +  }
         1007  +  memset(p, 0, sizeof(*p));
         1008  +  p->zJson = (char*)&p[1];
         1009  +  memcpy((char*)p->zJson, zJson, nJson+1);
         1010  +  if( jsonParse(p, pCtx, p->zJson) ){
         1011  +    sqlite3_free(p);
         1012  +    return 0;
         1013  +  }
         1014  +  p->nJson = nJson;
         1015  +  sqlite3_set_auxdata(pCtx, JSON_CACHE_ID, p, (void(*)(void*))jsonParseFree);
         1016  +  return (JsonParse*)sqlite3_get_auxdata(pCtx, JSON_CACHE_ID);
         1017  +}
   966   1018   
   967   1019   /*
   968   1020   ** Compare the OBJECT label at pNode against zKey,nKey.  Return true on
   969   1021   ** a match.
   970   1022   */
   971   1023   static int jsonLabelCompare(JsonNode *pNode, const char *zKey, u32 nKey){
   972   1024     if( pNode->jnFlags & JNODE_RAW ){
................................................................................
  1325   1377   ** Return 0 if the input is not a well-formed JSON array.
  1326   1378   */
  1327   1379   static void jsonArrayLengthFunc(
  1328   1380     sqlite3_context *ctx,
  1329   1381     int argc,
  1330   1382     sqlite3_value **argv
  1331   1383   ){
  1332         -  JsonParse x;          /* The parse */
         1384  +  JsonParse *p;          /* The parse */
  1333   1385     sqlite3_int64 n = 0;
  1334   1386     u32 i;
  1335   1387     JsonNode *pNode;
  1336   1388   
  1337         -  if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return;
  1338         -  assert( x.nNode );
         1389  +  p = jsonParseCached(ctx, argv);
         1390  +  if( p==0 ) return;
         1391  +  assert( p->nNode );
  1339   1392     if( argc==2 ){
  1340   1393       const char *zPath = (const char*)sqlite3_value_text(argv[1]);
  1341         -    pNode = jsonLookup(&x, zPath, 0, ctx);
         1394  +    pNode = jsonLookup(p, zPath, 0, ctx);
  1342   1395     }else{
  1343         -    pNode = x.aNode;
         1396  +    pNode = p->aNode;
  1344   1397     }
  1345   1398     if( pNode==0 ){
  1346         -    x.nErr = 1;
  1347         -  }else if( pNode->eType==JSON_ARRAY ){
         1399  +    return;
         1400  +  }
         1401  +  if( pNode->eType==JSON_ARRAY ){
  1348   1402       assert( (pNode->jnFlags & JNODE_APPEND)==0 );
  1349   1403       for(i=1; i<=pNode->n; n++){
  1350   1404         i += jsonNodeSize(&pNode[i]);
  1351   1405       }
  1352   1406     }
  1353         -  if( x.nErr==0 ) sqlite3_result_int64(ctx, n);
  1354         -  jsonParseReset(&x);
         1407  +  sqlite3_result_int64(ctx, n);
  1355   1408   }
  1356   1409   
  1357   1410   /*
  1358   1411   ** json_extract(JSON, PATH, ...)
  1359   1412   **
  1360   1413   ** Return the element described by PATH.  Return NULL if there is no
  1361   1414   ** PATH element.  If there are multiple PATHs, then return a JSON array
................................................................................
  1363   1416   ** is malformed.
  1364   1417   */
  1365   1418   static void jsonExtractFunc(
  1366   1419     sqlite3_context *ctx,
  1367   1420     int argc,
  1368   1421     sqlite3_value **argv
  1369   1422   ){
  1370         -  JsonParse x;          /* The parse */
         1423  +  JsonParse *p;          /* The parse */
  1371   1424     JsonNode *pNode;
  1372   1425     const char *zPath;
  1373   1426     JsonString jx;
  1374   1427     int i;
  1375   1428   
  1376   1429     if( argc<2 ) return;
  1377         -  if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return;
         1430  +  p = jsonParseCached(ctx, argv);
         1431  +  if( p==0 ) return;
  1378   1432     jsonInit(&jx, ctx);
  1379   1433     jsonAppendChar(&jx, '[');
  1380   1434     for(i=1; i<argc; i++){
  1381   1435       zPath = (const char*)sqlite3_value_text(argv[i]);
  1382         -    pNode = jsonLookup(&x, zPath, 0, ctx);
  1383         -    if( x.nErr ) break;
         1436  +    pNode = jsonLookup(p, zPath, 0, ctx);
         1437  +    if( p->nErr ) break;
  1384   1438       if( argc>2 ){
  1385   1439         jsonAppendSeparator(&jx);
  1386   1440         if( pNode ){
  1387   1441           jsonRenderNode(pNode, &jx, 0);
  1388   1442         }else{
  1389   1443           jsonAppendRaw(&jx, "null", 4);
  1390   1444         }
................................................................................
  1394   1448     }
  1395   1449     if( argc>2 && i==argc ){
  1396   1450       jsonAppendChar(&jx, ']');
  1397   1451       jsonResult(&jx);
  1398   1452       sqlite3_result_subtype(ctx, JSON_SUBTYPE);
  1399   1453     }
  1400   1454     jsonReset(&jx);
  1401         -  jsonParseReset(&x);
  1402   1455   }
  1403   1456   
  1404   1457   /* This is the RFC 7396 MergePatch algorithm.
  1405   1458   */
  1406   1459   static JsonNode *jsonMergePatch(
  1407   1460     JsonParse *pParse,   /* The JSON parser that contains the TARGET */
  1408   1461     u32 iTarget,         /* Node of the TARGET in pParse */

Changes to readme.htm.

     1      1   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
     2      2   <html>
     3      3   <head>
     4      4   <title></title>
     5      5   </head>
     6      6   <body>
     7      7   ADO.NET SQLite Data Provider<br />
     8         -Version 1.0.106.0 - June XX, 2017 <font color="red">(release scheduled)</font><br />
     9         -Using <a href="https://www.sqlite.org/draft/releaselog/3_19_0.html">SQLite 3.19.0</a><br />Originally written by Robert Simpson<br />
            8  +Version 1.0.106.0 - July XX, 2017 <font color="red">(release scheduled)</font><br />
            9  +Using <a href="https://www.sqlite.org/releaselog/3_19_1.html">SQLite 3.19.1</a><br />Originally written by Robert Simpson<br />
    10     10   Released to the public domain, use at your own risk!<br />
    11     11   Official provider website:&nbsp;<a href="https://system.data.sqlite.org/">https://system.data.sqlite.org/</a><br />
    12     12   Legacy versions:&nbsp;<a href="https://sourceforge.net/projects/sqlite-dotnet2/">https://sourceforge.net/projects/sqlite-dotnet2/</a><br />
    13     13   <br />
    14     14   The current development version can be downloaded from <a href="https://system.data.sqlite.org/index.html/timeline?y=ci">
    15     15   https://system.data.sqlite.org/index.html/timeline?y=ci</a>
    16     16   <br />
................................................................................
   204    204   designed for robustness and maximum backward compatibility with previously
   205    205   released versions of System.Data.SQLite.
   206    206   </p>
   207    207   
   208    208   <h2><b>Version History</b></h2>
   209    209   
   210    210   <p>
   211         -    <b>1.0.106.0 - June XX, 2017 <font color="red">(release scheduled)</font></b>
          211  +    <b>1.0.106.0 - July XX, 2017 <font color="red">(release scheduled)</font></b>
   212    212   </p>
   213    213   <ul>
   214         -    <li>Updated to <a href="https://www.sqlite.org/draft/releaselog/3_19_0.html">SQLite 3.19.0</a>.</li>
          214  +    <li>Updated to <a href="https://www.sqlite.org/releaselog/3_19_1.html">SQLite 3.19.1</a>.</li>
   215    215   </ul>
   216    216   <p>
   217    217       <b>1.0.105.1 - May 15, 2017</b>
   218    218   </p>
   219    219   <ul>
   220    220       <li>Prevent culture settings from negatively impacting integer connection string defaults.</li>
   221    221       <li>Make sure the &quot;No_SQLiteConnectionNewParser&quot; and &quot;DefaultFlags_SQLiteConnection&quot; setting values end up being cached.</li>

Changes to www/news.wiki.

    41     41       Access to archived release packages will be granted on a case-by-case basis.
    42     42     </li>
    43     43   </ul>
    44     44   
    45     45   <div align="center"><h2><b>Version History</b></h2></div>
    46     46   
    47     47   <p>
    48         -    <b>1.0.106.0 - June XX, 2017 <font color="red">(release scheduled)</font></b>
           48  +    <b>1.0.106.0 - July XX, 2017 <font color="red">(release scheduled)</font></b>
    49     49   </p>
    50     50   <ul>
    51         -    <li>Updated to [https://www.sqlite.org/draft/releaselog/3_19_0.html|SQLite 3.19.0].</li>
           51  +    <li>Updated to [https://www.sqlite.org/releaselog/3_19_1.html|SQLite 3.19.1].</li>
    52     52   </ul>
    53     53   <p>
    54     54       <b>1.0.105.1 - May 15, 2017</b>
    55     55   </p>
    56     56   <ul>
    57     57       <li>Prevent culture settings from negatively impacting integer connection string defaults.</li>
    58     58       <li>Make sure the &quot;No_SQLiteConnectionNewParser&quot; and &quot;DefaultFlags_SQLiteConnection&quot; setting values end up being cached.</li>