Fossil SCM

Update the built-in SQLite to the latest 3.31.0 alpha version, for testing.

drh 2019-12-26 01:26 trunk
Commit 9258d7462e677cd37df90179c5e4ba4bf699da883b839a05b58a456eeaf7d396
3 files changed +5 -5 +1330 -718 +88 -88
+5 -5
--- src/shell.c
+++ src/shell.c
@@ -5206,11 +5206,10 @@
52065206
rc = SQLITE_NOMEM;
52075207
}else{
52085208
int res;
52095209
str.next_out = aOut;
52105210
str.avail_out = nAlloc;
5211
- deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
52125211
res = deflate(&str, Z_FINISH);
52135212
if( res==Z_STREAM_END ){
52145213
*ppOut = aOut;
52155214
*pnOut = (int)str.total_out;
52165215
}else{
@@ -5826,10 +5825,11 @@
58265825
rc = zipfileGetMode(apVal[3], bIsDir, &mode, &pTab->base.zErrMsg);
58275826
}
58285827
58295828
if( rc==SQLITE_OK ){
58305829
zPath = (const char*)sqlite3_value_text(apVal[2]);
5830
+ if( zPath==0 ) zPath = "";
58315831
nPath = (int)strlen(zPath);
58325832
mTime = zipfileGetTime(apVal[4]);
58335833
}
58345834
58355835
if( rc==SQLITE_OK && bIsDir ){
@@ -5839,11 +5839,11 @@
58395839
** otherwise. */
58405840
if( zPath[nPath-1]!='/' ){
58415841
zFree = sqlite3_mprintf("%s/", zPath);
58425842
if( zFree==0 ){ rc = SQLITE_NOMEM; }
58435843
zPath = (const char*)zFree;
5844
- nPath++;
5844
+ nPath = (int)strlen(zPath);
58455845
}
58465846
}
58475847
58485848
/* Check that we're not inserting a duplicate entry -OR- updating an
58495849
** entry with a path, thereby making it into a duplicate. */
@@ -6232,23 +6232,23 @@
62326232
62336233
/* If this is a directory entry, ensure that there is exactly one '/'
62346234
** at the end of the path. Or, if this is not a directory and the path
62356235
** ends in '/' it is an error. */
62366236
if( bIsDir==0 ){
6237
- if( zName[nName-1]=='/' ){
6237
+ if( nName>0 && zName[nName-1]=='/' ){
62386238
zErr = sqlite3_mprintf("non-directory name must not end with /");
62396239
rc = SQLITE_ERROR;
62406240
goto zipfile_step_out;
62416241
}
62426242
}else{
6243
- if( zName[nName-1]!='/' ){
6243
+ if( nName==0 || zName[nName-1]!='/' ){
62446244
zName = zFree = sqlite3_mprintf("%s/", zName);
6245
- nName++;
62466245
if( zName==0 ){
62476246
rc = SQLITE_NOMEM;
62486247
goto zipfile_step_out;
62496248
}
6249
+ nName = (int)strlen(zName);
62506250
}else{
62516251
while( nName>1 && zName[nName-2]=='/' ) nName--;
62526252
}
62536253
}
62546254
62556255
--- src/shell.c
+++ src/shell.c
@@ -5206,11 +5206,10 @@
5206 rc = SQLITE_NOMEM;
5207 }else{
5208 int res;
5209 str.next_out = aOut;
5210 str.avail_out = nAlloc;
5211 deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
5212 res = deflate(&str, Z_FINISH);
5213 if( res==Z_STREAM_END ){
5214 *ppOut = aOut;
5215 *pnOut = (int)str.total_out;
5216 }else{
@@ -5826,10 +5825,11 @@
5826 rc = zipfileGetMode(apVal[3], bIsDir, &mode, &pTab->base.zErrMsg);
5827 }
5828
5829 if( rc==SQLITE_OK ){
5830 zPath = (const char*)sqlite3_value_text(apVal[2]);
 
5831 nPath = (int)strlen(zPath);
5832 mTime = zipfileGetTime(apVal[4]);
5833 }
5834
5835 if( rc==SQLITE_OK && bIsDir ){
@@ -5839,11 +5839,11 @@
5839 ** otherwise. */
5840 if( zPath[nPath-1]!='/' ){
5841 zFree = sqlite3_mprintf("%s/", zPath);
5842 if( zFree==0 ){ rc = SQLITE_NOMEM; }
5843 zPath = (const char*)zFree;
5844 nPath++;
5845 }
5846 }
5847
5848 /* Check that we're not inserting a duplicate entry -OR- updating an
5849 ** entry with a path, thereby making it into a duplicate. */
@@ -6232,23 +6232,23 @@
6232
6233 /* If this is a directory entry, ensure that there is exactly one '/'
6234 ** at the end of the path. Or, if this is not a directory and the path
6235 ** ends in '/' it is an error. */
6236 if( bIsDir==0 ){
6237 if( zName[nName-1]=='/' ){
6238 zErr = sqlite3_mprintf("non-directory name must not end with /");
6239 rc = SQLITE_ERROR;
6240 goto zipfile_step_out;
6241 }
6242 }else{
6243 if( zName[nName-1]!='/' ){
6244 zName = zFree = sqlite3_mprintf("%s/", zName);
6245 nName++;
6246 if( zName==0 ){
6247 rc = SQLITE_NOMEM;
6248 goto zipfile_step_out;
6249 }
 
6250 }else{
6251 while( nName>1 && zName[nName-2]=='/' ) nName--;
6252 }
6253 }
6254
6255
--- src/shell.c
+++ src/shell.c
@@ -5206,11 +5206,10 @@
5206 rc = SQLITE_NOMEM;
5207 }else{
5208 int res;
5209 str.next_out = aOut;
5210 str.avail_out = nAlloc;
 
5211 res = deflate(&str, Z_FINISH);
5212 if( res==Z_STREAM_END ){
5213 *ppOut = aOut;
5214 *pnOut = (int)str.total_out;
5215 }else{
@@ -5826,10 +5825,11 @@
5825 rc = zipfileGetMode(apVal[3], bIsDir, &mode, &pTab->base.zErrMsg);
5826 }
5827
5828 if( rc==SQLITE_OK ){
5829 zPath = (const char*)sqlite3_value_text(apVal[2]);
5830 if( zPath==0 ) zPath = "";
5831 nPath = (int)strlen(zPath);
5832 mTime = zipfileGetTime(apVal[4]);
5833 }
5834
5835 if( rc==SQLITE_OK && bIsDir ){
@@ -5839,11 +5839,11 @@
5839 ** otherwise. */
5840 if( zPath[nPath-1]!='/' ){
5841 zFree = sqlite3_mprintf("%s/", zPath);
5842 if( zFree==0 ){ rc = SQLITE_NOMEM; }
5843 zPath = (const char*)zFree;
5844 nPath = (int)strlen(zPath);
5845 }
5846 }
5847
5848 /* Check that we're not inserting a duplicate entry -OR- updating an
5849 ** entry with a path, thereby making it into a duplicate. */
@@ -6232,23 +6232,23 @@
6232
6233 /* If this is a directory entry, ensure that there is exactly one '/'
6234 ** at the end of the path. Or, if this is not a directory and the path
6235 ** ends in '/' it is an error. */
6236 if( bIsDir==0 ){
6237 if( nName>0 && zName[nName-1]=='/' ){
6238 zErr = sqlite3_mprintf("non-directory name must not end with /");
6239 rc = SQLITE_ERROR;
6240 goto zipfile_step_out;
6241 }
6242 }else{
6243 if( nName==0 || zName[nName-1]!='/' ){
6244 zName = zFree = sqlite3_mprintf("%s/", zName);
 
6245 if( zName==0 ){
6246 rc = SQLITE_NOMEM;
6247 goto zipfile_step_out;
6248 }
6249 nName = (int)strlen(zName);
6250 }else{
6251 while( nName>1 && zName[nName-2]=='/' ) nName--;
6252 }
6253 }
6254
6255
+1330 -718
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1165,11 +1165,11 @@
11651165
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11661166
** [sqlite_version()] and [sqlite_source_id()].
11671167
*/
11681168
#define SQLITE_VERSION "3.31.0"
11691169
#define SQLITE_VERSION_NUMBER 3031000
1170
-#define SQLITE_SOURCE_ID "2019-11-20 13:31:52 a0f6d526baecd061a5e2bec5eb698fb5dfb10122ac79c853d7b3f4a48bc9f49b"
1170
+#define SQLITE_SOURCE_ID "2019-12-26 01:10:17 f482a4cdfa768941e22c399de8ec29a55e729529eeae86d3832077ad1bef22f3"
11711171
11721172
/*
11731173
** CAPI3REF: Run-Time Library Version Numbers
11741174
** KEYWORDS: sqlite3_version sqlite3_sourceid
11751175
**
@@ -1581,10 +1581,11 @@
15811581
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
15821582
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
15831583
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
15841584
#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
15851585
#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
1586
+#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8))
15861587
15871588
/*
15881589
** CAPI3REF: Flags For File Open Operations
15891590
**
15901591
** These bit values are intended for use in the
@@ -2021,20 +2022,20 @@
20212022
**
20222023
** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
20232024
** ^The [SQLITE_FCNTL_BUSYHANDLER]
20242025
** file-control may be invoked by SQLite on the database file handle
20252026
** shortly after it is opened in order to provide a custom VFS with access
2026
-** to the connections busy-handler callback. The argument is of type (void **)
2027
+** to the connection's busy-handler callback. The argument is of type (void**)
20272028
** - an array of two (void *) values. The first (void *) actually points
2028
-** to a function of type (int (*)(void *)). In order to invoke the connections
2029
+** to a function of type (int (*)(void *)). In order to invoke the connection's
20292030
** busy-handler, this function should be invoked with the second (void *) in
20302031
** the array as the only argument. If it returns non-zero, then the operation
20312032
** should be retried. If it returns zero, the custom VFS should abandon the
20322033
** current operation.
20332034
**
20342035
** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
2035
-** ^Application can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
2036
+** ^Applications can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
20362037
** to have SQLite generate a
20372038
** temporary filename using the same algorithm that is followed to generate
20382039
** temporary filenames for TEMP tables and other internal uses. The
20392040
** argument should be a char** which will be filled with the filename
20402041
** written into memory obtained from [sqlite3_malloc()]. The caller should
@@ -2143,11 +2144,11 @@
21432144
** interface can be used to find if any database on the connection has changed,
21442145
** but that interface responds to changes on TEMP as well as MAIN and does
21452146
** not provide a mechanism to detect changes to MAIN only. Also, the
21462147
** [sqlite3_total_changes()] interface responds to internal changes only and
21472148
** omits changes made by other database connections. The
2148
-** [PRAGMA data_version] command provide a mechanism to detect changes to
2149
+** [PRAGMA data_version] command provides a mechanism to detect changes to
21492150
** a single attached database that occur due to other database connections,
21502151
** but omits changes implemented by the database connection on which it is
21512152
** called. This file control is the only mechanism to detect changes that
21522153
** happen either internally or externally and that are associated with
21532154
** a particular attached database.
@@ -2231,14 +2232,14 @@
22312232
** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
22322233
** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
22332234
** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6]. Additional fields
22342235
** may be appended to the sqlite3_vfs object and the iVersion value
22352236
** may increase again in future versions of SQLite.
2236
-** Note that the structure
2237
-** of the sqlite3_vfs object changes in the transition from
2237
+** Note that due to an oversight, the structure
2238
+** of the sqlite3_vfs object changed in the transition from
22382239
** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
2239
-** and yet the iVersion field was not modified.
2240
+** and yet the iVersion field was not increased.
22402241
**
22412242
** The szOsFile field is the size of the subclassed [sqlite3_file]
22422243
** structure used by this VFS. mxPathname is the maximum length of
22432244
** a pathname in this VFS.
22442245
**
@@ -2325,11 +2326,11 @@
23252326
** be created, and that it is an error if it already exists.
23262327
** It is <i>not</i> used to indicate the file should be opened
23272328
** for exclusive access.
23282329
**
23292330
** ^At least szOsFile bytes of memory are allocated by SQLite
2330
-** to hold the [sqlite3_file] structure passed as the third
2331
+** to hold the [sqlite3_file] structure passed as the third
23312332
** argument to xOpen. The xOpen method does not have to
23322333
** allocate the structure; it should just fill it in. Note that
23332334
** the xOpen method must set the sqlite3_file.pMethods to either
23342335
** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
23352336
** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
@@ -2448,11 +2449,10 @@
24482449
** SQLite.
24492450
*/
24502451
#define SQLITE_ACCESS_EXISTS 0
24512452
#define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */
24522453
#define SQLITE_ACCESS_READ 2 /* Unused */
2453
-#define SQLITE_ACCESS_SYMLINK 3 /* Test if file is symbolic link */
24542454
24552455
/*
24562456
** CAPI3REF: Flags for the xShmLock VFS method
24572457
**
24582458
** These integer constants define the various locking operations
@@ -2663,11 +2663,11 @@
26632663
** Every memory allocation request coming in through [sqlite3_malloc()]
26642664
** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
26652665
** that causes the corresponding memory allocation to fail.
26662666
**
26672667
** The xInit method initializes the memory allocator. For example,
2668
-** it might allocate any require mutexes or initialize internal data
2668
+** it might allocate any required mutexes or initialize internal data
26692669
** structures. The xShutdown method is invoked (indirectly) by
26702670
** [sqlite3_shutdown()] and should deallocate any resources acquired
26712671
** by xInit. The pAppData pointer is used as the only parameter to
26722672
** xInit and xShutdown.
26732673
**
@@ -2804,11 +2804,11 @@
28042804
**
28052805
** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
28062806
** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
28072807
** that SQLite can use for the database page cache with the default page
28082808
** cache implementation.
2809
-** This configuration option is a no-op if an application-define page
2809
+** This configuration option is a no-op if an application-defined page
28102810
** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2].
28112811
** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
28122812
** 8-byte aligned memory (pMem), the size of each page cache line (sz),
28132813
** and the number of cache lines (N).
28142814
** The sz argument should be the size of the largest database page
@@ -3289,11 +3289,11 @@
32893289
** </dd>
32903290
**
32913291
** [[SQLITE_DBCONFIG_DQS_DML]]
32923292
** <dt>SQLITE_DBCONFIG_DQS_DML</td>
32933293
** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
3294
-** the legacy [double-quoted string literal] misfeature for DML statement
3294
+** the legacy [double-quoted string literal] misfeature for DML statements
32953295
** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The
32963296
** default value of this setting is determined by the [-DSQLITE_DQS]
32973297
** compile-time option.
32983298
** </dd>
32993299
**
@@ -3550,11 +3550,11 @@
35503550
** will be rolled back automatically.
35513551
**
35523552
** ^The sqlite3_interrupt(D) call is in effect until all currently running
35533553
** SQL statements on [database connection] D complete. ^Any new SQL statements
35543554
** that are started after the sqlite3_interrupt() call and before the
3555
-** running statements reaches zero are interrupted as if they had been
3555
+** running statement count reaches zero are interrupted as if they had been
35563556
** running prior to the sqlite3_interrupt() call. ^New SQL statements
35573557
** that are started after the running statement count reaches zero are
35583558
** not effected by the sqlite3_interrupt().
35593559
** ^A call to sqlite3_interrupt(D) that occurs when there are no running
35603560
** SQL statements is a no-op and has no effect on SQL statements
@@ -3718,13 +3718,13 @@
37183718
** Alice | 43
37193719
** Bob | 28
37203720
** Cindy | 21
37213721
** </pre></blockquote>
37223722
**
3723
-** There are two column (M==2) and three rows (N==3). Thus the
3723
+** There are two columns (M==2) and three rows (N==3). Thus the
37243724
** result table has 8 entries. Suppose the result table is stored
3725
-** in an array names azResult. Then azResult holds this content:
3725
+** in an array named azResult. Then azResult holds this content:
37263726
**
37273727
** <blockquote><pre>
37283728
** azResult&#91;0] = "Name";
37293729
** azResult&#91;1] = "Age";
37303730
** azResult&#91;2] = "Alice";
@@ -3874,23 +3874,10 @@
38743874
** sqlite3_malloc64(), and sqlite3_realloc64()
38753875
** is always aligned to at least an 8 byte boundary, or to a
38763876
** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
38773877
** option is used.
38783878
**
3879
-** In SQLite version 3.5.0 and 3.5.1, it was possible to define
3880
-** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
3881
-** implementation of these routines to be omitted. That capability
3882
-** is no longer provided. Only built-in memory allocators can be used.
3883
-**
3884
-** Prior to SQLite version 3.7.10, the Windows OS interface layer called
3885
-** the system malloc() and free() directly when converting
3886
-** filenames between the UTF-8 encoding used by SQLite
3887
-** and whatever filename encoding is used by the particular Windows
3888
-** installation. Memory allocation errors were detected, but
3889
-** they were reported back as [SQLITE_CANTOPEN] or
3890
-** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
3891
-**
38923879
** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
38933880
** must be either NULL or else pointers obtained from a prior
38943881
** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
38953882
** not yet been released.
38963883
**
@@ -3935,11 +3922,11 @@
39353922
** CAPI3REF: Pseudo-Random Number Generator
39363923
**
39373924
** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
39383925
** select random [ROWID | ROWIDs] when inserting new records into a table that
39393926
** already uses the largest possible [ROWID]. The PRNG is also used for
3940
-** the build-in random() and randomblob() SQL functions. This interface allows
3927
+** the built-in random() and randomblob() SQL functions. This interface allows
39413928
** applications to access the same PRNG for other purposes.
39423929
**
39433930
** ^A call to this routine stores N bytes of randomness into buffer P.
39443931
** ^The P parameter can be a NULL pointer.
39453932
**
@@ -4536,11 +4523,11 @@
45364523
** a VFS implementation when the flags parameter to xOpen() has one or
45374524
** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and
45384525
** P is the name of the query parameter, then
45394526
** sqlite3_uri_parameter(F,P) returns the value of the P
45404527
** parameter if it exists or a NULL pointer if P does not appear as a
4541
-** query parameter on F. If P is a query parameter of F
4528
+** query parameter on F. If P is a query parameter of F and it
45424529
** has no explicit value, then sqlite3_uri_parameter(F,P) returns
45434530
** a pointer to an empty string.
45444531
**
45454532
** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
45464533
** parameter and returns true (1) or false (0) according to the value
@@ -4548,11 +4535,11 @@
45484535
** value of query parameter P is one of "yes", "true", or "on" in any
45494536
** case or if the value begins with a non-zero number. The
45504537
** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
45514538
** query parameter P is one of "no", "false", or "off" in any case or
45524539
** if the value begins with a numeric zero. If P is not a query
4553
-** parameter on F or if the value of P is does not match any of the
4540
+** parameter on F or if the value of P does not match any of the
45544541
** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
45554542
**
45564543
** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
45574544
** 64-bit signed integer and returns that integer, or D if P does not
45584545
** exist. If the value of P is something other than an integer, then
@@ -4885,16 +4872,16 @@
48854872
** in order to find the underlying cause of the problem. With the "v2" prepare
48864873
** interfaces, the underlying reason for the error is returned immediately.
48874874
** </li>
48884875
**
48894876
** <li>
4890
-** ^If the specific value bound to [parameter | host parameter] in the
4877
+** ^If the specific value bound to a [parameter | host parameter] in the
48914878
** WHERE clause might influence the choice of query plan for a statement,
48924879
** then the statement will be automatically recompiled, as if there had been
4893
-** a schema change, on the first [sqlite3_step()] call following any change
4880
+** a schema change, on the first [sqlite3_step()] call following any change
48944881
** to the [sqlite3_bind_text | bindings] of that [parameter].
4895
-** ^The specific value of WHERE-clause [parameter] might influence the
4882
+** ^The specific value of a WHERE-clause [parameter] might influence the
48964883
** choice of query plan if the parameter is the left-hand side of a [LIKE]
48974884
** or [GLOB] operator or if the parameter is compared to an indexed column
48984885
** and the [SQLITE_ENABLE_STAT4] compile-time option is enabled.
48994886
** </li>
49004887
** </ol>
@@ -5399,24 +5386,20 @@
53995386
** the statement, where N is the second function argument.
54005387
** ^The left-most column is column 0 for these routines.
54015388
**
54025389
** ^If the Nth column returned by the statement is an expression or
54035390
** subquery and is not a column value, then all of these functions return
5404
-** NULL. ^These routine might also return NULL if a memory allocation error
5391
+** NULL. ^These routines might also return NULL if a memory allocation error
54055392
** occurs. ^Otherwise, they return the name of the attached database, table,
54065393
** or column that query result column was extracted from.
54075394
**
54085395
** ^As with all other SQLite APIs, those whose names end with "16" return
54095396
** UTF-16 encoded strings and the other functions return UTF-8.
54105397
**
54115398
** ^These APIs are only available if the library was compiled with the
54125399
** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
54135400
**
5414
-** If two or more threads call one or more of these routines against the same
5415
-** prepared statement and column at the same time then the results are
5416
-** undefined.
5417
-**
54185401
** If two or more threads call one or more
54195402
** [sqlite3_column_database_name | column metadata interfaces]
54205403
** for the same [prepared statement] and result column
54215404
** at the same time then the results are undefined.
54225405
*/
@@ -5549,11 +5532,11 @@
55495532
** METHOD: sqlite3_stmt
55505533
**
55515534
** ^The sqlite3_data_count(P) interface returns the number of columns in the
55525535
** current row of the result set of [prepared statement] P.
55535536
** ^If prepared statement P does not have results ready to return
5554
-** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
5537
+** (via calls to the [sqlite3_column_int | sqlite3_column()] family of
55555538
** interfaces) then sqlite3_data_count(P) returns 0.
55565539
** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
55575540
** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
55585541
** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
55595542
** will return non-zero if previous call to [sqlite3_step](P) returned
@@ -6051,13 +6034,16 @@
60516034
** These constants may be ORed together with the
60526035
** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
60536036
** to [sqlite3_create_function()], [sqlite3_create_function16()], or
60546037
** [sqlite3_create_function_v2()].
60556038
**
6056
-** The SQLITE_DETERMINISTIC flag means that the new function will always
6057
-** maps the same inputs into the same output. The abs() function is
6058
-** deterministic, for example, but randomblob() is not.
6039
+** The SQLITE_DETERMINISTIC flag means that the new function always gives
6040
+** the same output when the input parameters are the same. The abs() function
6041
+** is deterministic, for example, but randomblob() is not. Functions must
6042
+** be deterministic in order to be used in certain contexts such as
6043
+** [CHECK constraints] or [generated columns]. SQLite might also optimize
6044
+** deterministic functions by factoring them out of inner loops.
60596045
**
60606046
** The SQLITE_DIRECTONLY flag means that the function may only be invoked
60616047
** from top-level SQL, and cannot be used in VIEWs or TRIGGERs. This is
60626048
** a security feature which is recommended for all
60636049
** [application-defined SQL functions] that have side-effects. This flag
@@ -6132,12 +6118,12 @@
61326118
**
61336119
** <b>Details:</b>
61346120
**
61356121
** These routines extract type, size, and content information from
61366122
** [protected sqlite3_value] objects. Protected sqlite3_value objects
6137
-** are used to pass parameter information into implementation of
6138
-** [application-defined SQL functions] and [virtual tables].
6123
+** are used to pass parameter information into the functions that
6124
+** implement [application-defined SQL functions] and [virtual tables].
61396125
**
61406126
** These routines work only with [protected sqlite3_value] objects.
61416127
** Any attempt to use these routines on an [unprotected sqlite3_value]
61426128
** is not threadsafe.
61436129
**
@@ -6190,11 +6176,11 @@
61906176
** the return value is arbitrary and meaningless.
61916177
**
61926178
** ^The sqlite3_value_frombind(X) interface returns non-zero if the
61936179
** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()]
61946180
** interfaces. ^If X comes from an SQL literal value, or a table column,
6195
-** and expression, then sqlite3_value_frombind(X) returns zero.
6181
+** or an expression, then sqlite3_value_frombind(X) returns zero.
61966182
**
61976183
** Please pay particular attention to the fact that the pointer returned
61986184
** from [sqlite3_value_blob()], [sqlite3_value_text()], or
61996185
** [sqlite3_value_text16()] can be invalidated by a subsequent call to
62006186
** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
@@ -6276,12 +6262,12 @@
62766262
**
62776263
** Implementations of aggregate SQL functions use this
62786264
** routine to allocate memory for storing their state.
62796265
**
62806266
** ^The first time the sqlite3_aggregate_context(C,N) routine is called
6281
-** for a particular aggregate function, SQLite
6282
-** allocates N of memory, zeroes out that memory, and returns a pointer
6267
+** for a particular aggregate function, SQLite allocates
6268
+** N bytes of memory, zeroes out that memory, and returns a pointer
62836269
** to the new memory. ^On second and subsequent calls to
62846270
** sqlite3_aggregate_context() for the same aggregate function instance,
62856271
** the same buffer is returned. Sqlite3_aggregate_context() is normally
62866272
** called once for each invocation of the xStep callback and then one
62876273
** last time when the xFinal callback is invoked. ^(When no rows match
@@ -6294,11 +6280,11 @@
62946280
** when first called if N is less than or equal to zero or if a memory
62956281
** allocate error occurs.
62966282
**
62976283
** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
62986284
** determined by the N parameter on first successful call. Changing the
6299
-** value of N in subsequent call to sqlite3_aggregate_context() within
6285
+** value of N in any subsequents call to sqlite3_aggregate_context() within
63006286
** the same aggregate function instance will not resize the memory
63016287
** allocation.)^ Within the xFinal callback, it is customary to set
63026288
** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
63036289
** pointless memory allocations occur.
63046290
**
@@ -6642,11 +6628,11 @@
66426628
** <li> If A&lt;B THEN B&gt;A.
66436629
** <li> If A&lt;B and B&lt;C then A&lt;C.
66446630
** </ol>
66456631
**
66466632
** If a collating function fails any of the above constraints and that
6647
-** collating function is registered and used, then the behavior of SQLite
6633
+** collating function is registered and used, then the behavior of SQLite
66486634
** is undefined.
66496635
**
66506636
** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
66516637
** with the addition that the xDestroy callback is invoked on pArg when
66526638
** the collating function is deleted.
@@ -6969,15 +6955,19 @@
69696955
69706956
/*
69716957
** CAPI3REF: Return The Filename For A Database Connection
69726958
** METHOD: sqlite3
69736959
**
6974
-** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
6975
-** associated with database N of connection D. ^The main database file
6976
-** has the name "main". If there is no attached database N on the database
6960
+** ^The sqlite3_db_filename(D,N) interface returns a pointer to the filename
6961
+** associated with database N of connection D.
6962
+** ^If there is no attached database N on the database
69776963
** connection D, or if database N is a temporary or in-memory database, then
69786964
** this function will return either a NULL pointer or an empty string.
6965
+**
6966
+** ^The string value returned by this routine is owned and managed by
6967
+** the database connection. ^The value will be valid until the database N
6968
+** is [DETACH]-ed or until the database connection closes.
69796969
**
69806970
** ^The filename returned by this function is the output of the
69816971
** xFullPathname method of the [VFS]. ^In other words, the filename
69826972
** will be an absolute pathname, even if the filename used
69836973
** to open the database originally was a URI or relative pathname.
@@ -7128,19 +7118,23 @@
71287118
** In prior versions of SQLite,
71297119
** sharing was enabled or disabled for each thread separately.
71307120
**
71317121
** ^(The cache sharing mode set by this interface effects all subsequent
71327122
** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
7133
-** Existing database connections continue use the sharing mode
7123
+** Existing database connections continue to use the sharing mode
71347124
** that was in effect at the time they were opened.)^
71357125
**
71367126
** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
71377127
** successfully. An [error code] is returned otherwise.)^
71387128
**
7139
-** ^Shared cache is disabled by default. But this might change in
7140
-** future releases of SQLite. Applications that care about shared
7141
-** cache setting should set it explicitly.
7129
+** ^Shared cache is disabled by default. It is recommended that it stay
7130
+** that way. In other words, do not use this routine. This interface
7131
+** continues to be provided for historical compatibility, but its use is
7132
+** discouraged. Any use of shared cache is discouraged. If shared cache
7133
+** must be used, it is recommended that shared cache only be enabled for
7134
+** individual database connections using the [sqlite3_open_v2()] interface
7135
+** with the [SQLITE_OPEN_SHAREDCACHE] flag.
71427136
**
71437137
** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0
71447138
** and will always return SQLITE_MISUSE. On those systems,
71457139
** shared cache mode should be enabled per-database connection via
71467140
** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
@@ -7269,11 +7263,11 @@
72697263
** information about column C of table T in database D
72707264
** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
72717265
** interface returns SQLITE_OK and fills in the non-NULL pointers in
72727266
** the final five arguments with appropriate values if the specified
72737267
** column exists. ^The sqlite3_table_column_metadata() interface returns
7274
-** SQLITE_ERROR and if the specified column does not exist.
7268
+** SQLITE_ERROR if the specified column does not exist.
72757269
** ^If the column-name parameter to sqlite3_table_column_metadata() is a
72767270
** NULL pointer, then this routine simply checks for the existence of the
72777271
** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
72787272
** does not. If the table name parameter T in a call to
72797273
** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is
@@ -7411,11 +7405,11 @@
74117405
** [sqlite3_load_extension()] and the SQL function [load_extension()].
74127406
** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
74137407
** to enable or disable only the C-API.)^
74147408
**
74157409
** <b>Security warning:</b> It is recommended that extension loading
7416
-** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
7410
+** be enabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
74177411
** rather than this interface, so the [load_extension()] SQL function
74187412
** remains disabled. This will prevent SQL injections from giving attackers
74197413
** access to extension loading capabilities.
74207414
*/
74217415
SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
@@ -7498,11 +7492,11 @@
74987492
/*
74997493
** CAPI3REF: Virtual Table Object
75007494
** KEYWORDS: sqlite3_module {virtual table module}
75017495
**
75027496
** This structure, sometimes called a "virtual table module",
7503
-** defines the implementation of a [virtual tables].
7497
+** defines the implementation of a [virtual table].
75047498
** This structure consists mostly of methods for the module.
75057499
**
75067500
** ^A virtual table module is created by filling in a persistent
75077501
** instance of this structure and passing a pointer to that instance
75087502
** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
@@ -7595,11 +7589,17 @@
75957589
** The [xBestIndex] method must fill aConstraintUsage[] with information
75967590
** about what parameters to pass to xFilter. ^If argvIndex>0 then
75977591
** the right-hand side of the corresponding aConstraint[] is evaluated
75987592
** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
75997593
** is true, then the constraint is assumed to be fully handled by the
7600
-** virtual table and is not checked again by SQLite.)^
7594
+** virtual table and might not be checked again by the byte code.)^ ^(The
7595
+** aConstraintUsage[].omit flag is an optimization hint. When the omit flag
7596
+** is left in its default setting of false, the constraint will always be
7597
+** checked separately in byte code. If the omit flag is change to true, then
7598
+** the constraint may or may not be checked in byte code. In other words,
7599
+** when the omit flag is true there is no guarantee that the constraint will
7600
+** not be checked again using byte code.)^
76017601
**
76027602
** ^The idxNum and idxPtr values are recorded and passed into the
76037603
** [xFilter] method.
76047604
** ^[sqlite3_free()] is used to free idxPtr if and only if
76057605
** needToFreeIdxPtr is true.
@@ -7635,11 +7635,11 @@
76357635
** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
76367636
** structure for SQLite [version 3.8.2] ([dateof:3.8.2]).
76377637
** If a virtual table extension is
76387638
** used with an SQLite version earlier than 3.8.2, the results of attempting
76397639
** to read or write the estimatedRows field are undefined (but are likely
7640
-** to included crashing the application). The estimatedRows field should
7640
+** to include crashing the application). The estimatedRows field should
76417641
** therefore only be used if [sqlite3_libversion_number()] returns a
76427642
** value greater than or equal to 3008002. Similarly, the idxFlags field
76437643
** was added for [version 3.9.0] ([dateof:3.9.0]).
76447644
** It may therefore only be used if
76457645
** sqlite3_libversion_number() returns a value greater than or equal to
@@ -7687,11 +7687,11 @@
76877687
#define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */
76887688
76897689
/*
76907690
** CAPI3REF: Virtual Table Constraint Operator Codes
76917691
**
7692
-** These macros defined the allowed values for the
7692
+** These macros define the allowed values for the
76937693
** [sqlite3_index_info].aConstraint[].op field. Each value represents
76947694
** an operator that is part of a constraint term in the wHERE clause of
76957695
** a query that uses a [virtual table].
76967696
*/
76977697
#define SQLITE_INDEX_CONSTRAINT_EQ 2
@@ -8297,11 +8297,11 @@
82978297
** </ul>)^
82988298
**
82998299
** The only difference is that the public sqlite3_XXX functions enumerated
83008300
** above silently ignore any invocations that pass a NULL pointer instead
83018301
** of a valid mutex handle. The implementations of the methods defined
8302
-** by this structure are not required to handle this case, the results
8302
+** by this structure are not required to handle this case. The results
83038303
** of passing a NULL pointer instead of a valid mutex handle are undefined
83048304
** (i.e. it is acceptable to provide an implementation that segfaults if
83058305
** it is passed a NULL pointer).
83068306
**
83078307
** The xMutexInit() method must be threadsafe. It must be harmless to
@@ -8770,11 +8770,11 @@
87708770
** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
87718771
** no space was left in the page cache.</dd>)^
87728772
**
87738773
** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
87748774
** <dd>This parameter records the largest memory allocation request
8775
-** handed to [pagecache memory allocator]. Only the value returned in the
8775
+** handed to the [pagecache memory allocator]. Only the value returned in the
87768776
** *pHighwater parameter to [sqlite3_status()] is of interest.
87778777
** The value written into the *pCurrent parameter is undefined.</dd>)^
87788778
**
87798779
** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt>
87808780
** <dd>No longer used.</dd>
@@ -8846,11 +8846,11 @@
88468846
** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
88478847
** <dd>This parameter returns the number of lookaside memory slots currently
88488848
** checked out.</dd>)^
88498849
**
88508850
** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
8851
-** <dd>This parameter returns the number malloc attempts that were
8851
+** <dd>This parameter returns the number of malloc attempts that were
88528852
** satisfied using lookaside memory. Only the high-water value is meaningful;
88538853
** the current value is always zero.)^
88548854
**
88558855
** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
88568856
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
@@ -8928,11 +8928,11 @@
89288928
** <dd>This parameter returns the number of dirty cache entries that have
89298929
** been written to disk in the middle of a transaction due to the page
89308930
** cache overflowing. Transactions are more efficient if they are written
89318931
** to disk all at once. When pages spill mid-transaction, that introduces
89328932
** additional overhead. This parameter can be used help identify
8933
-** inefficiencies that can be resolve by increasing the cache size.
8933
+** inefficiencies that can be resolved by increasing the cache size.
89348934
** </dd>
89358935
**
89368936
** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
89378937
** <dd>This parameter returns zero for the current value if and only if
89388938
** all foreign key constraints (deferred or immediate) have been
@@ -9017,11 +9017,11 @@
90179017
** If the number of virtual machine operations exceeds 2147483647
90189018
** then the value returned by this statement status code is undefined.
90199019
**
90209020
** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
90219021
** <dd>^This is the number of times that the prepare statement has been
9022
-** automatically regenerated due to schema changes or change to
9022
+** automatically regenerated due to schema changes or changes to
90239023
** [bound parameters] that might affect the query plan.
90249024
**
90259025
** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
90269026
** <dd>^This is the number of times that the prepared statement has
90279027
** been run. A single "run" for the purposes of this counter is one
@@ -9188,11 +9188,11 @@
91889188
** NULL if allocating a new page is effectively impossible.
91899189
** </table>
91909190
**
91919191
** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
91929192
** will only use a createFlag of 2 after a prior call with a createFlag of 1
9193
-** failed.)^ In between the to xFetch() calls, SQLite may
9193
+** failed.)^ In between the xFetch() calls, SQLite may
91949194
** attempt to unpin one or more cache pages by spilling the content of
91959195
** pinned pages to disk and synching the operating system disk cache.
91969196
**
91979197
** [[the xUnpin() page cache method]]
91989198
** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
@@ -9506,11 +9506,11 @@
95069506
** application receives an SQLITE_LOCKED error, it may call the
95079507
** sqlite3_unlock_notify() method with the blocked connection handle as
95089508
** the first argument to register for a callback that will be invoked
95099509
** when the blocking connections current transaction is concluded. ^The
95109510
** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
9511
-** call that concludes the blocking connections transaction.
9511
+** call that concludes the blocking connection's transaction.
95129512
**
95139513
** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
95149514
** there is a chance that the blocking connection will have already
95159515
** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
95169516
** If this happens, then the specified callback is invoked immediately,
@@ -9544,11 +9544,11 @@
95449544
** However, the signature of the callback function allows SQLite to pass
95459545
** it an array of void* context pointers. The first argument passed to
95469546
** an unlock-notify callback is a pointer to an array of void* pointers,
95479547
** and the second is the number of entries in the array.
95489548
**
9549
-** When a blocking connections transaction is concluded, there may be
9549
+** When a blocking connection's transaction is concluded, there may be
95509550
** more than one blocked connection that has registered for an unlock-notify
95519551
** callback. ^If two or more such blocked connections have specified the
95529552
** same callback function, then instead of invoking the callback function
95539553
** multiple times, it is invoked once with the set of void* context pointers
95549554
** specified by the blocked connections bundled together into an array.
@@ -10018,37 +10018,37 @@
1001810018
** managed by the prepared statement S and will be automatically freed when
1001910019
** S is finalized.
1002010020
**
1002110021
** <dl>
1002210022
** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
10023
-** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
10023
+** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be
1002410024
** set to the total number of times that the X-th loop has run.</dd>
1002510025
**
1002610026
** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
10027
-** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set
10027
+** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be set
1002810028
** to the total number of rows examined by all iterations of the X-th loop.</dd>
1002910029
**
1003010030
** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
10031
-** <dd>^The "double" variable pointed to by the T parameter will be set to the
10031
+** <dd>^The "double" variable pointed to by the V parameter will be set to the
1003210032
** query planner's estimate for the average number of rows output from each
1003310033
** iteration of the X-th loop. If the query planner's estimates was accurate,
1003410034
** then this value will approximate the quotient NVISIT/NLOOP and the
1003510035
** product of this value for all prior loops with the same SELECTID will
1003610036
** be the NLOOP value for the current loop.
1003710037
**
1003810038
** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
10039
-** <dd>^The "const char *" variable pointed to by the T parameter will be set
10039
+** <dd>^The "const char *" variable pointed to by the V parameter will be set
1004010040
** to a zero-terminated UTF-8 string containing the name of the index or table
1004110041
** used for the X-th loop.
1004210042
**
1004310043
** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
10044
-** <dd>^The "const char *" variable pointed to by the T parameter will be set
10044
+** <dd>^The "const char *" variable pointed to by the V parameter will be set
1004510045
** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
1004610046
** description for the X-th loop.
1004710047
**
1004810048
** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
10049
-** <dd>^The "int" variable pointed to by the T parameter will be set to the
10049
+** <dd>^The "int" variable pointed to by the V parameter will be set to the
1005010050
** "select-id" for the X-th loop. The select-id identifies which query or
1005110051
** subquery the loop is part of. The main query has a select-id of zero.
1005210052
** The select-id is the same value as is output in the first column
1005310053
** of an [EXPLAIN QUERY PLAN] query.
1005410054
** </dl>
@@ -10899,11 +10899,11 @@
1089910899
** METHOD: sqlite3_session
1090010900
**
1090110901
** The second argument (xFilter) is the "filter callback". For changes to rows
1090210902
** in tables that are not attached to the Session object, the filter is called
1090310903
** to determine whether changes to the table's rows should be tracked or not.
10904
-** If xFilter returns 0, changes is not tracked. Note that once a table is
10904
+** If xFilter returns 0, changes are not tracked. Note that once a table is
1090510905
** attached, xFilter will not be called again.
1090610906
*/
1090710907
SQLITE_API void sqlite3session_table_filter(
1090810908
sqlite3_session *pSession, /* Session object */
1090910909
int(*xFilter)(
@@ -11073,11 +11073,11 @@
1107311073
** identical.
1107411074
**
1107511075
** It an error if database zFrom does not exist or does not contain the
1107611076
** required compatible table.
1107711077
**
11078
-** If the operation successful, SQLITE_OK is returned. Otherwise, an SQLite
11078
+** If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite
1107911079
** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
1108011080
** may be set to point to a buffer containing an English language error
1108111081
** message. It is the responsibility of the caller to free this buffer using
1108211082
** sqlite3_free().
1108311083
*/
@@ -11210,11 +11210,11 @@
1121011210
1121111211
/*
1121211212
** CAPI3REF: Advance A Changeset Iterator
1121311213
** METHOD: sqlite3_changeset_iter
1121411214
**
11215
-** This function may only be used with iterators created by function
11215
+** This function may only be used with iterators created by the function
1121611216
** [sqlite3changeset_start()]. If it is called on an iterator passed to
1121711217
** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE
1121811218
** is returned and the call has no effect.
1121911219
**
1122011220
** Immediately after an iterator is created by sqlite3changeset_start(), it
@@ -11626,12 +11626,12 @@
1162611626
** in the changegroup, then the number of columns and the position of the
1162711627
** primary key columns for the table must be consistent. If this is not the
1162811628
** case, this function fails with SQLITE_SCHEMA. If the input changeset
1162911629
** appears to be corrupt and the corruption is detected, SQLITE_CORRUPT is
1163011630
** returned. Or, if an out-of-memory condition occurs during processing, this
11631
-** function returns SQLITE_NOMEM. In all cases, if an error occurs the
11632
-** final contents of the changegroup is undefined.
11631
+** function returns SQLITE_NOMEM. In all cases, if an error occurs the state
11632
+** of the final contents of the changegroup is undefined.
1163311633
**
1163411634
** If no error occurs, SQLITE_OK is returned.
1163511635
*/
1163611636
SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
1163711637
@@ -11802,11 +11802,11 @@
1180211802
** [SQLITE_CHANGESET_REPLACE].
1180311803
** </dl>
1180411804
**
1180511805
** It is safe to execute SQL statements, including those that write to the
1180611806
** table that the callback related to, from within the xConflict callback.
11807
-** This can be used to further customize the applications conflict
11807
+** This can be used to further customize the application's conflict
1180811808
** resolution strategy.
1180911809
**
1181011810
** All changes made by these functions are enclosed in a savepoint transaction.
1181111811
** If any other error (aside from a constraint failure when attempting to
1181211812
** write to the target database) occurs, then the savepoint transaction is
@@ -12112,11 +12112,11 @@
1211212112
** CAPI3REF: Rebase a changeset
1211312113
** EXPERIMENTAL
1211412114
**
1211512115
** Argument pIn must point to a buffer containing a changeset nIn bytes
1211612116
** in size. This function allocates and populates a buffer with a copy
12117
-** of the changeset rebased rebased according to the configuration of the
12117
+** of the changeset rebased according to the configuration of the
1211812118
** rebaser object passed as the first argument. If successful, (*ppOut)
1211912119
** is set to point to the new buffer containing the rebased changeset and
1212012120
** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
1212112121
** responsibility of the caller to eventually free the new buffer using
1212212122
** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
@@ -12520,11 +12520,11 @@
1252012520
** the callback, an SQLite error code is returned.
1252112521
**
1252212522
**
1252312523
** xSetAuxdata(pFts5, pAux, xDelete)
1252412524
**
12525
-** Save the pointer passed as the second argument as the extension functions
12525
+** Save the pointer passed as the second argument as the extension function's
1252612526
** "auxiliary data". The pointer may then be retrieved by the current or any
1252712527
** future invocation of the same fts5 extension function made as part of
1252812528
** the same MATCH query using the xGetAuxdata() API.
1252912529
**
1253012530
** Each extension function is allocated a single auxiliary data slot for
@@ -12762,12 +12762,12 @@
1276212762
** all instances of "first place" or "1st place" regardless of which form
1276312763
** the user specified in the MATCH query text.
1276412764
**
1276512765
** There are several ways to approach this in FTS5:
1276612766
**
12767
-** <ol><li> By mapping all synonyms to a single token. In this case, the
12768
-** In the above example, this means that the tokenizer returns the
12767
+** <ol><li> By mapping all synonyms to a single token. In this case, using
12768
+** the above example, this means that the tokenizer returns the
1276912769
** same token for inputs "first" and "1st". Say that token is in
1277012770
** fact "first", so that when the user inserts the document "I won
1277112771
** 1st place" entries are added to the index for tokens "i", "won",
1277212772
** "first" and "place". If the user then queries for '1st + place',
1277312773
** the tokenizer substitutes "first" for "1st" and the query works
@@ -13435,10 +13435,30 @@
1343513435
#else
1343613436
# define ALWAYS(X) (X)
1343713437
# define NEVER(X) (X)
1343813438
#endif
1343913439
13440
+/*
13441
+** The harmless(X) macro indicates that expression X is usually false
13442
+** but can be true without causing any problems, but we don't know of
13443
+** any way to cause X to be true.
13444
+**
13445
+** In debugging and testing builds, this macro will abort if X is ever
13446
+** true. In this way, developers are alerted to a possible test case
13447
+** that causes X to be true. If a harmless macro ever fails, that is
13448
+** an opportunity to change the macro into a testcase() and add a new
13449
+** test case to the test suite.
13450
+**
13451
+** For normal production builds, harmless(X) is a no-op, since it does
13452
+** not matter whether expression X is true or false.
13453
+*/
13454
+#ifdef SQLITE_DEBUG
13455
+# define harmless(X) assert(!(X));
13456
+#else
13457
+# define harmless(X)
13458
+#endif
13459
+
1344013460
/*
1344113461
** Some conditionals are optimizations only. In other words, if the
1344213462
** conditionals are replaced with a constant 1 (true) or 0 (false) then
1344313463
** the correct answer is still obtained, though perhaps not as quickly.
1344413464
**
@@ -15149,13 +15169,14 @@
1514915169
#define OP_VRename 163
1515015170
#define OP_Pagecount 164
1515115171
#define OP_MaxPgcnt 165
1515215172
#define OP_Trace 166
1515315173
#define OP_CursorHint 167
15154
-#define OP_Noop 168
15155
-#define OP_Explain 169
15156
-#define OP_Abortable 170
15174
+#define OP_ReleaseReg 168 /* synopsis: release r[P1@P2] mask P3 */
15175
+#define OP_Noop 169
15176
+#define OP_Explain 170
15177
+#define OP_Abortable 171
1515715178
1515815179
/* Properties such as "out2" or "jump" that are specified in
1515915180
** comments following the "case" for each opcode in the vdbe.c
1516015181
** are encoded into bitvectors as follows:
1516115182
*/
@@ -15185,11 +15206,11 @@
1518515206
/* 128 */ 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x10, 0x00,\
1518615207
/* 136 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
1518715208
/* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x10, 0x00,\
1518815209
/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
1518915210
/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
15190
-/* 168 */ 0x00, 0x00, 0x00,}
15211
+/* 168 */ 0x00, 0x00, 0x00, 0x00,}
1519115212
1519215213
/* The sqlite3P2Values() routine is able to run faster if it knows
1519315214
** the value of the largest JUMP opcode. The smaller the maximum
1519415215
** JUMP opcode the better, so the mkopcodeh.tcl script that
1519515216
** generated this include file strives to group all JUMP opcodes
@@ -15262,10 +15283,15 @@
1526215283
SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3);
1526315284
SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
1526415285
SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
1526515286
SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
1526615287
SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
15288
+#ifdef SQLITE_DEBUG
15289
+SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(Parse*,int addr, int n, u32 mask);
15290
+#else
15291
+# define sqlite3VdbeReleaseRegisters(P,A,N,M)
15292
+#endif
1526715293
SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
1526815294
SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
1526915295
SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
1527015296
SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
1527115297
SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
@@ -16841,16 +16867,10 @@
1684116867
{nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1684216868
pArg, 0, xFunc, 0, 0, 0, #zName, }
1684316869
#define LIKEFUNC(zName, nArg, arg, flags) \
1684416870
{nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
1684516871
(void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} }
16846
-#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue) \
16847
- {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
16848
- SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,0,#zName, {0}}
16849
-#define AGGREGATE2(zName, nArg, arg, nc, xStep, xFinal, extraFlags) \
16850
- {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
16851
- SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xFinal,0,#zName, {0}}
1685216872
#define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f) \
1685316873
{nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \
1685416874
SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,xInverse,#zName, {0}}
1685516875
#define INTERNAL_FUNCTION(zName, nArg, xFunc) \
1685616876
{nArg, SQLITE_FUNC_INTERNAL|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
@@ -17978,17 +17998,17 @@
1797817998
** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences
1797917999
** for the result set. The KeyInfo for addrOpenEphm[2] contains collating
1798018000
** sequences for the ORDER BY clause.
1798118001
*/
1798218002
struct Select {
17983
- ExprList *pEList; /* The fields of the result */
1798418003
u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
1798518004
LogEst nSelectRow; /* Estimated number of result rows */
1798618005
u32 selFlags; /* Various SF_* values */
1798718006
int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */
1798818007
u32 selId; /* Unique identifier number for this SELECT */
1798918008
int addrOpenEphm[2]; /* OP_OpenEphem opcodes related to this select */
18009
+ ExprList *pEList; /* The fields of the result */
1799018010
SrcList *pSrc; /* The FROM clause */
1799118011
Expr *pWhere; /* The WHERE clause */
1799218012
ExprList *pGroupBy; /* The GROUP BY clause */
1799318013
Expr *pHaving; /* The HAVING clause */
1799418014
ExprList *pOrderBy; /* The ORDER BY clause */
@@ -18030,10 +18050,11 @@
1803018050
#define SF_Converted 0x0010000 /* By convertCompoundSelectToSubquery() */
1803118051
#define SF_IncludeHidden 0x0020000 /* Include hidden columns in output */
1803218052
#define SF_ComplexResult 0x0040000 /* Result contains subquery or function */
1803318053
#define SF_WhereBegin 0x0080000 /* Really a WhereBegin() call. Debug Only */
1803418054
#define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */
18055
+#define SF_View 0x0200000 /* SELECT statement is a view */
1803518056
1803618057
/*
1803718058
** The results of a SELECT can be distributed in several ways, as defined
1803818059
** by one of the following macros. The "SRT" prefix means "SELECT Result
1803918060
** Type".
@@ -18309,12 +18330,12 @@
1830918330
#endif
1831018331
};
1831118332
1831218333
#define PARSE_MODE_NORMAL 0
1831318334
#define PARSE_MODE_DECLARE_VTAB 1
18314
-#define PARSE_MODE_RENAME_COLUMN 2
18315
-#define PARSE_MODE_RENAME_TABLE 3
18335
+#define PARSE_MODE_RENAME 2
18336
+#define PARSE_MODE_UNMAP 3
1831618337
1831718338
/*
1831818339
** Sizes and pointers of various parts of the Parse object.
1831918340
*/
1832018341
#define PARSE_HDR_SZ offsetof(Parse,aTempReg) /* Recursive part w/o aColCache*/
@@ -18332,11 +18353,11 @@
1833218353
#endif
1833318354
1833418355
#if defined(SQLITE_OMIT_ALTERTABLE)
1833518356
#define IN_RENAME_OBJECT 0
1833618357
#else
18337
- #define IN_RENAME_OBJECT (pParse->eParseMode>=PARSE_MODE_RENAME_COLUMN)
18358
+ #define IN_RENAME_OBJECT (pParse->eParseMode>=PARSE_MODE_RENAME)
1833818359
#endif
1833918360
1834018361
#if defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_OMIT_ALTERTABLE)
1834118362
#define IN_SPECIAL_PARSE 0
1834218363
#else
@@ -19151,10 +19172,11 @@
1915119172
SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
1915219173
SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
1915319174
SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
1915419175
Expr*,ExprList*,u32,Expr*);
1915519176
SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3*, Select*);
19177
+SQLITE_PRIVATE void sqlite3SelectReset(Parse*, Select*);
1915619178
SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*);
1915719179
SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, int);
1915819180
SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
1915919181
#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
1916019182
SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,char*);
@@ -20734,11 +20756,11 @@
2073420756
SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
2073520757
SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem*, int ifNull);
2073620758
SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
2073720759
SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
2073820760
SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
20739
-SQLITE_PRIVATE void sqlite3VdbeMemCast(Mem*,u8,u8);
20761
+SQLITE_PRIVATE int sqlite3VdbeMemCast(Mem*,u8,u8);
2074020762
SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);
2074120763
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
2074220764
SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
2074320765
#ifndef SQLITE_OMIT_WINDOWFUNC
2074420766
SQLITE_PRIVATE int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*);
@@ -22654,11 +22676,11 @@
2265422676
DO_OS_MALLOC_TEST(0);
2265522677
/* 0x87f7f is a mask of SQLITE_OPEN_ flags that are valid to be passed
2265622678
** down into the VFS layer. Some SQLITE_OPEN_ flags (for example,
2265722679
** SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_SHAREDCACHE) are blocked before
2265822680
** reaching the VFS. */
22659
- rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x87f7f, pFlagsOut);
22681
+ rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x1087f7f, pFlagsOut);
2266022682
assert( rc==SQLITE_OK || pFile->pMethods==0 );
2266122683
return rc;
2266222684
}
2266322685
SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
2266422686
DO_OS_MALLOC_TEST(0);
@@ -29289,12 +29311,13 @@
2928929311
zOp2[0] = 0;
2929029312
}
2929129313
sqlite3TreeViewLine(pView, "COLUMN(%d)%s%s",
2929229314
pExpr->iColumn, zFlgs, zOp2);
2929329315
}else{
29294
- sqlite3TreeViewLine(pView, "{%d:%d}%s",
29295
- pExpr->iTable, pExpr->iColumn, zFlgs);
29316
+ sqlite3TreeViewLine(pView, "{%d:%d} pTab=%p%s",
29317
+ pExpr->iTable, pExpr->iColumn,
29318
+ pExpr->y.pTab, zFlgs);
2929629319
}
2929729320
if( ExprHasProperty(pExpr, EP_FixedCol) ){
2929829321
sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
2929929322
}
2930029323
break;
@@ -30961,11 +30984,11 @@
3096130984
#pragma warning(disable : 4756)
3096230985
#endif
3096330986
SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){
3096430987
#ifndef SQLITE_OMIT_FLOATING_POINT
3096530988
int incr;
30966
- const char *zEnd = z + length;
30989
+ const char *zEnd;
3096730990
/* sign * significand * (10 ^ (esign * exponent)) */
3096830991
int sign = 1; /* sign of significand */
3096930992
i64 s = 0; /* significand */
3097030993
int d = 0; /* adjust exponent for shifting decimal point */
3097130994
int esign = 1; /* sign of exponent */
@@ -30975,13 +30998,15 @@
3097530998
int nDigit = 0; /* Number of digits processed */
3097630999
int eType = 1; /* 1: pure integer, 2+: fractional -1 or less: bad UTF16 */
3097731000
3097831001
assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
3097931002
*pResult = 0.0; /* Default return value, in case of an error */
31003
+ if( length==0 ) return 0;
3098031004
3098131005
if( enc==SQLITE_UTF8 ){
3098231006
incr = 1;
31007
+ zEnd = z + length;
3098331008
}else{
3098431009
int i;
3098531010
incr = 2;
3098631011
assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
3098731012
testcase( enc==SQLITE_UTF16LE );
@@ -32660,13 +32685,14 @@
3266032685
/* 163 */ "VRename" OpHelp(""),
3266132686
/* 164 */ "Pagecount" OpHelp(""),
3266232687
/* 165 */ "MaxPgcnt" OpHelp(""),
3266332688
/* 166 */ "Trace" OpHelp(""),
3266432689
/* 167 */ "CursorHint" OpHelp(""),
32665
- /* 168 */ "Noop" OpHelp(""),
32666
- /* 169 */ "Explain" OpHelp(""),
32667
- /* 170 */ "Abortable" OpHelp(""),
32690
+ /* 168 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
32691
+ /* 169 */ "Noop" OpHelp(""),
32692
+ /* 170 */ "Explain" OpHelp(""),
32693
+ /* 171 */ "Abortable" OpHelp(""),
3266832694
};
3266932695
return azName[i];
3267032696
}
3267132697
#endif
3267232698
@@ -36555,11 +36581,11 @@
3655536581
zDirname[ii] = '\0';
3655636582
}else{
3655736583
if( zDirname[0]!='/' ) zDirname[0] = '.';
3655836584
zDirname[1] = 0;
3655936585
}
36560
- fd = robust_open(zDirname, O_RDONLY|O_BINARY, 0);
36586
+ fd = robust_open(zDirname, O_RDONLY|O_BINARY|O_NOFOLLOW, 0);
3656136587
if( fd>=0 ){
3656236588
OSTRACE(("OPENDIR %-3d %s\n", fd, zDirname));
3656336589
}
3656436590
*pFd = fd;
3656536591
if( fd>=0 ) return SQLITE_OK;
@@ -37446,14 +37472,16 @@
3744637472
}
3744737473
}
3744837474
3744937475
if( pInode->bProcessLock==0 ){
3745037476
if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
37451
- pShmNode->hShm = robust_open(zShm, O_RDWR|O_CREAT,(sStat.st_mode&0777));
37477
+ pShmNode->hShm = robust_open(zShm, O_RDWR|O_CREAT|O_NOFOLLOW,
37478
+ (sStat.st_mode&0777));
3745237479
}
3745337480
if( pShmNode->hShm<0 ){
37454
- pShmNode->hShm = robust_open(zShm, O_RDONLY, (sStat.st_mode&0777));
37481
+ pShmNode->hShm = robust_open(zShm, O_RDONLY|O_NOFOLLOW,
37482
+ (sStat.st_mode&0777));
3745537483
if( pShmNode->hShm<0 ){
3745637484
rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShm);
3745737485
goto shm_open_err;
3745837486
}
3745937487
pShmNode->isReadonly = 1;
@@ -38799,11 +38827,11 @@
3879938827
int *pOutFlags /* Output flags returned to SQLite core */
3880038828
){
3880138829
unixFile *p = (unixFile *)pFile;
3880238830
int fd = -1; /* File descriptor returned by open() */
3880338831
int openFlags = 0; /* Flags to pass to open() */
38804
- int eType = flags&0xFFFFFF00; /* Type of file to open */
38832
+ int eType = flags&0x0FFF00; /* Type of file to open */
3880538833
int noLock; /* True to omit locking primitives */
3880638834
int rc = SQLITE_OK; /* Function Return Code */
3880738835
int ctrlFlags = 0; /* UNIXFILE_* flags */
3880838836
3880938837
int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE);
@@ -38909,11 +38937,11 @@
3890938937
** 'conch file' locking functions later on. */
3891038938
if( isReadonly ) openFlags |= O_RDONLY;
3891138939
if( isReadWrite ) openFlags |= O_RDWR;
3891238940
if( isCreate ) openFlags |= O_CREAT;
3891338941
if( isExclusive ) openFlags |= (O_EXCL|O_NOFOLLOW);
38914
- openFlags |= (O_LARGEFILE|O_BINARY);
38942
+ openFlags |= (O_LARGEFILE|O_BINARY|O_NOFOLLOW);
3891538943
3891638944
if( fd<0 ){
3891738945
mode_t openMode; /* Permissions to create file with */
3891838946
uid_t uid; /* Userid for the file */
3891938947
gid_t gid; /* Groupid for the file */
@@ -39121,29 +39149,20 @@
3912139149
){
3912239150
UNUSED_PARAMETER(NotUsed);
3912339151
SimulateIOError( return SQLITE_IOERR_ACCESS; );
3912439152
assert( pResOut!=0 );
3912539153
39126
- /* The spec says there are four possible values for flags. But the
39127
- ** SQLITE_ACCESS_READ flag is never used */
39128
- assert( flags==SQLITE_ACCESS_EXISTS
39129
- || flags==SQLITE_ACCESS_READWRITE
39130
- || flags==SQLITE_ACCESS_SYMLINK );
39154
+ /* The spec says there are three possible values for flags. But only
39155
+ ** two of them are actually used */
39156
+ assert( flags==SQLITE_ACCESS_EXISTS || flags==SQLITE_ACCESS_READWRITE );
3913139157
3913239158
if( flags==SQLITE_ACCESS_EXISTS ){
3913339159
struct stat buf;
39134
- *pResOut = (0==osStat(zPath, &buf) && buf.st_size>0);
39135
- }else if( flags==SQLITE_ACCESS_READWRITE ){
39160
+ *pResOut = 0==osStat(zPath, &buf) &&
39161
+ (S_ISDIR(buf.st_mode) || buf.st_size>0);
39162
+ }else{
3913639163
*pResOut = osAccess(zPath, W_OK|R_OK)==0;
39137
- }else{
39138
-#if !defined(HAVE_LSTAT)
39139
- *pResOut = 0;
39140
-#else
39141
- struct stat buf;
39142
- *pResOut = (0==osLstat(zPath, &buf) && S_ISLNK(buf.st_mode));
39143
-#endif
39144
- assert( flags==SQLITE_ACCESS_SYMLINK );
3914539164
}
3914639165
return SQLITE_OK;
3914739166
}
3914839167
3914939168
/*
@@ -39191,11 +39210,11 @@
3919139210
#if !defined(HAVE_READLINK) || !defined(HAVE_LSTAT)
3919239211
return mkFullPathname(zPath, zOut, nOut);
3919339212
#else
3919439213
int rc = SQLITE_OK;
3919539214
int nByte;
39196
- int nLink = 1; /* Number of symbolic links followed so far */
39215
+ int nLink = 0; /* Number of symbolic links followed so far */
3919739216
const char *zIn = zPath; /* Input path for each iteration of loop */
3919839217
char *zDel = 0;
3919939218
3920039219
assert( pVfs->mxPathname==MAX_PATHNAME );
3920139220
UNUSED_PARAMETER(pVfs);
@@ -39220,14 +39239,15 @@
3922039239
}else{
3922139240
bLink = S_ISLNK(buf.st_mode);
3922239241
}
3922339242
3922439243
if( bLink ){
39244
+ nLink++;
3922539245
if( zDel==0 ){
3922639246
zDel = sqlite3_malloc(nOut);
3922739247
if( zDel==0 ) rc = SQLITE_NOMEM_BKPT;
39228
- }else if( ++nLink>SQLITE_MAX_SYMLINKS ){
39248
+ }else if( nLink>=SQLITE_MAX_SYMLINKS ){
3922939249
rc = SQLITE_CANTOPEN_BKPT;
3923039250
}
3923139251
3923239252
if( rc==SQLITE_OK ){
3923339253
nByte = osReadlink(zIn, zDel, nOut-1);
@@ -39259,10 +39279,11 @@
3925939279
if( bLink==0 ) break;
3926039280
zIn = zOut;
3926139281
}while( rc==SQLITE_OK );
3926239282
3926339283
sqlite3_free(zDel);
39284
+ if( rc==SQLITE_OK && nLink ) rc = SQLITE_OK_SYMLINK;
3926439285
return rc;
3926539286
#endif /* HAVE_READLINK && HAVE_LSTAT */
3926639287
}
3926739288
3926839289
@@ -39744,11 +39765,11 @@
3974439765
int islockfile /* if non zero missing dirs will be created */
3974539766
) {
3974639767
int fd = -1;
3974739768
unixFile *pNew;
3974839769
int rc = SQLITE_OK;
39749
- int openFlags = O_RDWR | O_CREAT;
39770
+ int openFlags = O_RDWR | O_CREAT | O_NOFOLLOW;
3975039771
sqlite3_vfs dummyVfs;
3975139772
int terrno = 0;
3975239773
UnixUnusedFd *pUnused = NULL;
3975339774
3975439775
/* 1. first try to open/create the file
@@ -39774,11 +39795,11 @@
3977439795
fd = robust_open(path, openFlags, 0);
3977539796
}
3977639797
}
3977739798
}
3977839799
if( fd<0 ){
39779
- openFlags = O_RDONLY;
39800
+ openFlags = O_RDONLY | O_NOFOLLOW;
3978039801
fd = robust_open(path, openFlags, 0);
3978139802
terrno = errno;
3978239803
}
3978339804
if( fd<0 ){
3978439805
if( islockfile ){
@@ -39900,11 +39921,11 @@
3990039921
if( readLen<PROXY_PATHINDEX ){
3990139922
sqlite3_snprintf(sizeof(errmsg),errmsg,"read error (len %d)",(int)readLen);
3990239923
goto end_breaklock;
3990339924
}
3990439925
/* write it out to the temporary break file */
39905
- fd = robust_open(tPath, (O_RDWR|O_CREAT|O_EXCL), 0);
39926
+ fd = robust_open(tPath, (O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW), 0);
3990639927
if( fd<0 ){
3990739928
sqlite3_snprintf(sizeof(errmsg), errmsg, "create failed (%d)", errno);
3990839929
goto end_breaklock;
3990939930
}
3991039931
if( osPwrite(fd, buf, readLen, 0) != (ssize_t)readLen ){
@@ -41060,18 +41081,10 @@
4106041081
4106141082
#ifndef NTDDI_WINTHRESHOLD
4106241083
# define NTDDI_WINTHRESHOLD 0x06040000
4106341084
#endif
4106441085
41065
-/*
41066
-** This constant is needed by the winAccess function; therefore, define
41067
-** it when it is missing from the SDK header files.
41068
-*/
41069
-#ifndef FILE_ATTRIBUTE_REPARSE_POINT
41070
-# define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
41071
-#endif
41072
-
4107341086
/*
4107441087
** Check to see if the GetVersionEx[AW] functions are deprecated on the
4107541088
** target system. GetVersionEx was first deprecated in Win8.1.
4107641089
*/
4107741090
#ifndef SQLITE_WIN32_GETVERSIONEX
@@ -46460,14 +46473,10 @@
4646046473
break;
4646146474
case SQLITE_ACCESS_READWRITE:
4646246475
rc = attr!=INVALID_FILE_ATTRIBUTES &&
4646346476
(attr & FILE_ATTRIBUTE_READONLY)==0;
4646446477
break;
46465
- case SQLITE_ACCESS_SYMLINK:
46466
- rc = attr!=INVALID_FILE_ATTRIBUTES &&
46467
- (attr & FILE_ATTRIBUTE_REPARSE_POINT)!=0;
46468
- break;
4646946478
default:
4647046479
assert(!"Invalid flags argument");
4647146480
}
4647246481
*pResOut = rc;
4647346482
OSTRACE(("ACCESS name=%s, pResOut=%p, *pResOut=%d, rc=SQLITE_OK\n",
@@ -49503,17 +49512,19 @@
4950349512
sqlite3_free(p);
4950449513
pPg = 0;
4950549514
}
4950649515
#else
4950749516
pPg = pcache1Alloc(pCache->szAlloc);
49508
- p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
4950949517
#endif
4951049518
if( benignMalloc ){ sqlite3EndBenignMalloc(); }
4951149519
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
4951249520
pcache1EnterMutex(pCache->pGroup);
4951349521
#endif
4951449522
if( pPg==0 ) return 0;
49523
+#ifndef SQLITE_PCACHE_SEPARATE_HEADER
49524
+ p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
49525
+#endif
4951549526
p->page.pBuf = pPg;
4951649527
p->page.pExtra = &p[1];
4951749528
p->isBulkLocal = 0;
4951849529
p->isAnchor = 0;
4951949530
}
@@ -55782,31 +55793,34 @@
5578255793
** to by zPathname, length nPathname. Or, if this is a temporary file,
5578355794
** leave both nPathname and zPathname set to 0.
5578455795
*/
5578555796
if( zFilename && zFilename[0] ){
5578655797
const char *z;
55787
- if( (vfsFlags & SQLITE_OPEN_NOFOLLOW)!=0 ){
55788
- int isLink = 0;
55789
- int rc = sqlite3OsAccess(pVfs, zFilename, SQLITE_ACCESS_SYMLINK, &isLink);
55790
- if( rc==SQLITE_OK && isLink ) rc = SQLITE_CANTOPEN_SYMLINK;
55791
- if( rc ) return rc;
55792
- }
5579355798
nPathname = pVfs->mxPathname+1;
5579455799
zPathname = sqlite3DbMallocRaw(0, nPathname*2);
5579555800
if( zPathname==0 ){
5579655801
return SQLITE_NOMEM_BKPT;
5579755802
}
5579855803
zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
5579955804
rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
55805
+ if( rc!=SQLITE_OK ){
55806
+ if( rc==SQLITE_OK_SYMLINK ){
55807
+ if( vfsFlags & SQLITE_OPEN_NOFOLLOW ){
55808
+ rc = SQLITE_CANTOPEN_SYMLINK;
55809
+ }else{
55810
+ rc = SQLITE_OK;
55811
+ }
55812
+ }
55813
+ }
5580055814
nPathname = sqlite3Strlen30(zPathname);
5580155815
z = zUri = &zFilename[sqlite3Strlen30(zFilename)+1];
5580255816
while( *z ){
5580355817
z += strlen(z)+1;
5580455818
z += strlen(z)+1;
5580555819
nUri++;
5580655820
}
55807
- nUriByte = (int)(&z[2] - zUri);
55821
+ nUriByte = (int)(&z[1] - zUri);
5580855822
assert( nUriByte>=1 );
5580955823
if( rc==SQLITE_OK && nPathname+8>pVfs->mxPathname ){
5581055824
/* This branch is taken when the journal path required by
5581155825
** the database being opened will be more than pVfs->mxPathname
5581255826
** bytes in length. This means the database cannot be opened,
@@ -57616,10 +57630,11 @@
5761657630
5761757631
/* This routine should not be called if a prior error has occurred.
5761857632
** But if (due to a coding error elsewhere in the system) it does get
5761957633
** called, just return the same error code without doing anything. */
5762057634
if( NEVER(pPager->errCode) ) return pPager->errCode;
57635
+ pPager->iDataVersion++;
5762157636
5762257637
assert( pPager->eState==PAGER_WRITER_LOCKED
5762357638
|| pPager->eState==PAGER_WRITER_FINISHED
5762457639
|| (pagerUseWal(pPager) && pPager->eState==PAGER_WRITER_CACHEMOD)
5762557640
);
@@ -57644,11 +57659,10 @@
5764457659
pPager->eState = PAGER_READER;
5764557660
return SQLITE_OK;
5764657661
}
5764757662
5764857663
PAGERTRACE(("COMMIT %d\n", PAGERID(pPager)));
57649
- pPager->iDataVersion++;
5765057664
rc = pager_end_transaction(pPager, pPager->setMaster, 1);
5765157665
return pager_error(pPager, rc);
5765257666
}
5765357667
5765457668
/*
@@ -60565,11 +60579,23 @@
6056560579
** of the aReadMark[] slot. The assumption here is that if that is
6056660580
** happening, the other client may only be increasing the value,
6056760581
** not decreasing it. So assuming either that either the "old" or
6056860582
** "new" version of the value is read, and not some arbitrary value
6056960583
** that would never be written by a real client, things are still
60570
- ** safe. */
60584
+ ** safe.
60585
+ **
60586
+ ** Astute readers have pointed out that the assumption stated in the
60587
+ ** last sentence of the previous paragraph is not guaranteed to be
60588
+ ** true for all conforming systems. However, the assumption is true
60589
+ ** for all compilers and architectures in common use today (circa
60590
+ ** 2019-11-27) and the alternatives are both slow and complex, and
60591
+ ** so we will continue to go with the current design for now. If this
60592
+ ** bothers you, or if you really are running on a system where aligned
60593
+ ** 32-bit reads and writes are not atomic, then you can simply avoid
60594
+ ** the use of WAL mode, or only use WAL mode together with
60595
+ ** PRAGMA locking_mode=EXCLUSIVE and all will be well.
60596
+ */
6057160597
u32 y = pInfo->aReadMark[i];
6057260598
if( mxSafeFrame>y ){
6057360599
assert( y<=pWal->hdr.mxFrame );
6057460600
rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1);
6057560601
if( rc==SQLITE_OK ){
@@ -66021,13 +66047,17 @@
6602166047
memcpy(zFullPathname, zFilename, nFilename);
6602266048
}else{
6602366049
rc = sqlite3OsFullPathname(pVfs, zFilename,
6602466050
nFullPathname, zFullPathname);
6602566051
if( rc ){
66026
- sqlite3_free(zFullPathname);
66027
- sqlite3_free(p);
66028
- return rc;
66052
+ if( rc==SQLITE_OK_SYMLINK ){
66053
+ rc = SQLITE_OK;
66054
+ }else{
66055
+ sqlite3_free(zFullPathname);
66056
+ sqlite3_free(p);
66057
+ return rc;
66058
+ }
6602966059
}
6603066060
}
6603166061
#if SQLITE_THREADSAFE
6603266062
mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN);
6603366063
sqlite3_mutex_enter(mutexOpen);
@@ -69332,12 +69362,15 @@
6933269362
6933369363
/* If the database file is corrupt, it is possible for the value of idx
6933469364
** to be invalid here. This can only occur if a second cursor modifies
6933569365
** the page while cursor pCur is holding a reference to it. Which can
6933669366
** only happen if the database is corrupt in such a way as to link the
69337
- ** page into more than one b-tree structure. */
69338
- testcase( idx>pPage->nCell );
69367
+ ** page into more than one b-tree structure.
69368
+ **
69369
+ ** Update 2019-12-23: appears to long longer be possible after the
69370
+ ** addition of anotherValidCursor() condition on balance_deeper(). */
69371
+ harmless( idx>pPage->nCell );
6933969372
6934069373
if( idx>=pPage->nCell ){
6934169374
if( !pPage->leaf ){
6934269375
rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
6934369376
if( rc ) return rc;
@@ -71921,10 +71954,34 @@
7192171954
put4byte(&pRoot->aData[pRoot->hdrOffset+8], pgnoChild);
7192271955
7192371956
*ppChild = pChild;
7192471957
return SQLITE_OK;
7192571958
}
71959
+
71960
+/*
71961
+** Return SQLITE_CORRUPT if any cursor other than pCur is currently valid
71962
+** on the same B-tree as pCur.
71963
+**
71964
+** This can if a database is corrupt with two or more SQL tables
71965
+** pointing to the same b-tree. If an insert occurs on one SQL table
71966
+** and causes a BEFORE TRIGGER to do a secondary insert on the other SQL
71967
+** table linked to the same b-tree. If the secondary insert causes a
71968
+** rebalance, that can change content out from under the cursor on the
71969
+** first SQL table, violating invariants on the first insert.
71970
+*/
71971
+static int anotherValidCursor(BtCursor *pCur){
71972
+ BtCursor *pOther;
71973
+ for(pOther=pCur->pBt->pCursor; pOther; pOther=pOther->pNext){
71974
+ if( pOther!=pCur
71975
+ && pOther->eState==CURSOR_VALID
71976
+ && pOther->pPage==pCur->pPage
71977
+ ){
71978
+ return SQLITE_CORRUPT_BKPT;
71979
+ }
71980
+ }
71981
+ return SQLITE_OK;
71982
+}
7192671983
7192771984
/*
7192871985
** The page that pCur currently points to has just been modified in
7192971986
** some way. This function figures out if this modification means the
7193071987
** tree needs to be balanced, and if so calls the appropriate balancing
@@ -71949,11 +72006,11 @@
7194972006
7195072007
if( NEVER(pPage->nFree<0) && btreeComputeFreeSpace(pPage) ) break;
7195172008
if( pPage->nOverflow==0 && pPage->nFree<=nMin ){
7195272009
break;
7195372010
}else if( (iPage = pCur->iPage)==0 ){
71954
- if( pPage->nOverflow ){
72011
+ if( pPage->nOverflow && (rc = anotherValidCursor(pCur))==SQLITE_OK ){
7195572012
/* The root page of the b-tree is overfull. In this case call the
7195672013
** balance_deeper() function to create a new child for the root-page
7195772014
** and copy the current contents of the root-page to it. The
7195872015
** next iteration of the do-loop will balance the child page.
7195972016
*/
@@ -72320,11 +72377,13 @@
7232072377
return btreeOverwriteCell(pCur, &x2);
7232172378
}
7232272379
}
7232372380
7232472381
}
72325
- assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
72382
+ assert( pCur->eState==CURSOR_VALID
72383
+ || (pCur->eState==CURSOR_INVALID && loc)
72384
+ || CORRUPT_DB );
7232672385
7232772386
pPage = pCur->pPage;
7232872387
assert( pPage->intKey || pX->nKey>=0 );
7232972388
assert( pPage->leaf || !pPage->intKey );
7233072389
if( pPage->nFree<0 ){
@@ -75489,12 +75548,11 @@
7548975548
if( flags & (MEM_Int|MEM_IntReal) ){
7549075549
testcase( flags & MEM_IntReal );
7549175550
return pMem->u.i;
7549275551
}else if( flags & MEM_Real ){
7549375552
return doubleToInt64(pMem->u.r);
75494
- }else if( flags & (MEM_Str|MEM_Blob) ){
75495
- assert( pMem->z || pMem->n==0 );
75553
+ }else if( (flags & (MEM_Str|MEM_Blob))!=0 && pMem->z!=0 ){
7549675554
return memIntValue(pMem);
7549775555
}else{
7549875556
return 0;
7549975557
}
7550075558
}
@@ -75647,12 +75705,12 @@
7564775705
** "aff". Casting is different from applying affinity in that a cast
7564875706
** is forced. In other words, the value is converted into the desired
7564975707
** affinity even if that results in loss of data. This routine is
7565075708
** used (for example) to implement the SQL "cast()" operator.
7565175709
*/
75652
-SQLITE_PRIVATE void sqlite3VdbeMemCast(Mem *pMem, u8 aff, u8 encoding){
75653
- if( pMem->flags & MEM_Null ) return;
75710
+SQLITE_PRIVATE int sqlite3VdbeMemCast(Mem *pMem, u8 aff, u8 encoding){
75711
+ if( pMem->flags & MEM_Null ) return SQLITE_OK;
7565475712
switch( aff ){
7565575713
case SQLITE_AFF_BLOB: { /* Really a cast to BLOB */
7565675714
if( (pMem->flags & MEM_Blob)==0 ){
7565775715
sqlite3ValueApplyAffinity(pMem, SQLITE_AFF_TEXT, encoding);
7565875716
assert( pMem->flags & MEM_Str || pMem->db->mallocFailed );
@@ -75679,13 +75737,14 @@
7567975737
assert( MEM_Str==(MEM_Blob>>3) );
7568075738
pMem->flags |= (pMem->flags&MEM_Blob)>>3;
7568175739
sqlite3ValueApplyAffinity(pMem, SQLITE_AFF_TEXT, encoding);
7568275740
assert( pMem->flags & MEM_Str || pMem->db->mallocFailed );
7568375741
pMem->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal|MEM_Blob|MEM_Zero);
75684
- break;
75742
+ return sqlite3VdbeChangeEncoding(pMem, encoding);
7568575743
}
7568675744
}
75745
+ return SQLITE_OK;
7568775746
}
7568875747
7568975748
/*
7569075749
** Initialize bulk memory to be a consistent Mem object.
7569175750
**
@@ -77454,10 +77513,11 @@
7745477513
**
7745577514
** * OP_Halt with P1=SQLITE_CONSTRAINT and P2=OE_Abort.
7745677515
** * OP_HaltIfNull with P1=SQLITE_CONSTRAINT and P2=OE_Abort.
7745777516
** * OP_Destroy
7745877517
** * OP_VUpdate
77518
+** * OP_VCreate
7745977519
** * OP_VRename
7746077520
** * OP_FkCounter with P2==0 (immediate foreign key constraint)
7746177521
** * OP_CreateBtree/BTREE_INTKEY and OP_InitCoroutine
7746277522
** (for CREATE TABLE AS SELECT ...)
7746377523
**
@@ -77481,10 +77541,11 @@
7748177541
7748277542
while( (pOp = opIterNext(&sIter))!=0 ){
7748377543
int opcode = pOp->opcode;
7748477544
if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
7748577545
|| opcode==OP_VDestroy
77546
+ || opcode==OP_VCreate
7748677547
|| (opcode==OP_ParseSchema && pOp->p4.z==0)
7748777548
|| ((opcode==OP_Halt || opcode==OP_HaltIfNull)
7748877549
&& ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
7748977550
){
7749077551
hasAbort = 1;
@@ -77970,10 +78031,33 @@
7797078031
return sqlite3VdbeChangeToNoop(p, p->nOp-1);
7797178032
}else{
7797278033
return 0;
7797378034
}
7797478035
}
78036
+
78037
+#ifdef SQLITE_DEBUG
78038
+/*
78039
+** Generate an OP_ReleaseReg opcode to indicate that a range of
78040
+** registers, except any identified by mask, are no longer in use.
78041
+*/
78042
+SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(Parse *pParse, int iFirst, int N, u32 mask){
78043
+ assert( pParse->pVdbe );
78044
+ while( N>0 && (mask&1)!=0 ){
78045
+ mask >>= 1;
78046
+ iFirst++;
78047
+ N--;
78048
+ }
78049
+ while( N>0 && N<=32 && (mask & MASKBIT32(N-1))!=0 ){
78050
+ mask &= ~MASKBIT32(N-1);
78051
+ N--;
78052
+ }
78053
+ if( N>0 ){
78054
+ sqlite3VdbeAddOp3(pParse->pVdbe, OP_ReleaseReg, iFirst, N, *(int*)&mask);
78055
+ }
78056
+}
78057
+#endif /* SQLITE_DEBUG */
78058
+
7797578059
7797678060
/*
7797778061
** Change the value of the P4 operand for a specific instruction.
7797878062
** This routine is useful when a large program is loaded from a
7797978063
** static array using sqlite3VdbeAddOpList but we want to make a
@@ -78088,11 +78172,12 @@
7808878172
** makes the code easier to read during debugging. None of this happens
7808978173
** in a production build.
7809078174
*/
7809178175
static void vdbeVComment(Vdbe *p, const char *zFormat, va_list ap){
7809278176
assert( p->nOp>0 || p->aOp==0 );
78093
- assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed );
78177
+ assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed
78178
+ || p->pParse->nErr>0 );
7809478179
if( p->nOp ){
7809578180
assert( p->aOp );
7809678181
sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment);
7809778182
p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap);
7809878183
}
@@ -86128,13 +86213,15 @@
8612886213
testcase( pOp->p2==SQLITE_AFF_INTEGER );
8612986214
testcase( pOp->p2==SQLITE_AFF_REAL );
8613086215
pIn1 = &aMem[pOp->p1];
8613186216
memAboutToChange(p, pIn1);
8613286217
rc = ExpandBlob(pIn1);
86133
- sqlite3VdbeMemCast(pIn1, pOp->p2, encoding);
86218
+ if( rc ) goto abort_due_to_error;
86219
+ rc = sqlite3VdbeMemCast(pIn1, pOp->p2, encoding);
86220
+ if( rc ) goto abort_due_to_error;
8613486221
UPDATE_MAX_BLOBSIZE(pIn1);
86135
- if( rc ) goto abort_due_to_error;
86222
+ REGISTER_TRACE(pOp->p1, pIn1);
8613686223
break;
8613786224
}
8613886225
#endif /* SQLITE_OMIT_CAST */
8613986226
8614086227
/* Opcode: Eq P1 P2 P3 P4 P5
@@ -86289,16 +86376,11 @@
8628986376
affinity = pOp->p5 & SQLITE_AFF_MASK;
8629086377
if( affinity>=SQLITE_AFF_NUMERIC ){
8629186378
if( (flags1 | flags3)&MEM_Str ){
8629286379
if( (flags1 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
8629386380
applyNumericAffinity(pIn1,0);
86294
- assert( flags3==pIn3->flags );
86295
- /* testcase( flags3!=pIn3->flags );
86296
- ** this used to be possible with pIn1==pIn3, but not since
86297
- ** the column cache was removed. The following assignment
86298
- ** is essentially a no-op. But, it provides defense-in-depth
86299
- ** in case our analysis is incorrect, so it is left in. */
86381
+ testcase( flags3!=pIn3->flags );
8630086382
flags3 = pIn3->flags;
8630186383
}
8630286384
if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
8630386385
applyNumericAffinity(pIn3,0);
8630486386
}
@@ -86317,11 +86399,11 @@
8631786399
testcase( pIn1->flags & MEM_Real );
8631886400
testcase( pIn1->flags & MEM_IntReal );
8631986401
sqlite3VdbeMemStringify(pIn1, encoding, 1);
8632086402
testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
8632186403
flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
86322
- assert( pIn1!=pIn3 );
86404
+ if( pIn1==pIn3 ) flags3 = flags1 | MEM_Str;
8632386405
}
8632486406
if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
8632586407
testcase( pIn3->flags & MEM_Int );
8632686408
testcase( pIn3->flags & MEM_Real );
8632786409
testcase( pIn3->flags & MEM_IntReal );
@@ -86352,14 +86434,14 @@
8635286434
static const unsigned char aGTb[] = { 1, 0, 1, 0, 0, 1 };
8635386435
res2 = aGTb[pOp->opcode - OP_Ne];
8635486436
}
8635586437
8635686438
/* Undo any changes made by applyAffinity() to the input registers. */
86439
+ assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
86440
+ pIn3->flags = flags3;
8635786441
assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
8635886442
pIn1->flags = flags1;
86359
- assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
86360
- pIn3->flags = flags3;
8636186443
8636286444
if( pOp->p5 & SQLITE_STOREP2 ){
8636386445
pOut = &aMem[pOp->p2];
8636486446
iCompare = res;
8636586447
if( (pOp->p5 & SQLITE_KEEPNULL)!=0 ){
@@ -86391,20 +86473,35 @@
8639186473
break;
8639286474
}
8639386475
8639486476
/* Opcode: ElseNotEq * P2 * * *
8639586477
**
86396
-** This opcode must immediately follow an OP_Lt or OP_Gt comparison operator.
86397
-** If result of an OP_Eq comparison on the same two operands
86398
-** would have be NULL or false (0), then then jump to P2.
86399
-** If the result of an OP_Eq comparison on the two previous operands
86400
-** would have been true (1), then fall through.
86478
+** This opcode must follow an OP_Lt or OP_Gt comparison operator. There
86479
+** can be zero or more OP_ReleaseReg opcodes intervening, but no other
86480
+** opcodes are allowed to occur between this instruction and the previous
86481
+** OP_Lt or OP_Gt. Furthermore, the prior OP_Lt or OP_Gt must have the
86482
+** SQLITE_STOREP2 bit set in the P5 field.
86483
+**
86484
+** If result of an OP_Eq comparison on the same two operands as the
86485
+** prior OP_Lt or OP_Gt would have been NULL or false (0), then then
86486
+** jump to P2. If the result of an OP_Eq comparison on the two previous
86487
+** operands would have been true (1), then fall through.
8640186488
*/
8640286489
case OP_ElseNotEq: { /* same as TK_ESCAPE, jump */
86403
- assert( pOp>aOp );
86404
- assert( pOp[-1].opcode==OP_Lt || pOp[-1].opcode==OP_Gt );
86405
- assert( pOp[-1].p5 & SQLITE_STOREP2 );
86490
+
86491
+#ifdef SQLITE_DEBUG
86492
+ /* Verify the preconditions of this opcode - that it follows an OP_Lt or
86493
+ ** OP_Gt with the SQLITE_STOREP2 flag set, with zero or more intervening
86494
+ ** OP_ReleaseReg opcodes */
86495
+ int iAddr;
86496
+ for(iAddr = (int)(pOp - aOp) - 1; ALWAYS(iAddr>=0); iAddr--){
86497
+ if( aOp[iAddr].opcode==OP_ReleaseReg ) continue;
86498
+ assert( aOp[iAddr].opcode==OP_Lt || aOp[iAddr].opcode==OP_Gt );
86499
+ assert( aOp[iAddr].p5 & SQLITE_STOREP2 );
86500
+ break;
86501
+ }
86502
+#endif /* SQLITE_DEBUG */
8640686503
VdbeBranchTaken(iCompare!=0, 2);
8640786504
if( iCompare!=0 ) goto jump_to_p2;
8640886505
break;
8640986506
}
8641086507
@@ -86811,11 +86908,13 @@
8681186908
const u8 *zEndHdr; /* Pointer to first byte after the header */
8681286909
u64 offset64; /* 64-bit offset */
8681386910
u32 t; /* A type code from the record header */
8681486911
Mem *pReg; /* PseudoTable input register */
8681586912
86913
+ assert( pOp->p1>=0 && pOp->p1<p->nCursor );
8681686914
pC = p->apCsr[pOp->p1];
86915
+ assert( pC!=0 );
8681786916
p2 = pOp->p2;
8681886917
8681986918
/* If the cursor cache is stale (meaning it is not currently point at
8682086919
** the correct row) then bring it up-to-date by doing the necessary
8682186920
** B-Tree seek. */
@@ -86823,11 +86922,10 @@
8682386922
if( rc ) goto abort_due_to_error;
8682486923
8682586924
assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
8682686925
pDest = &aMem[pOp->p3];
8682786926
memAboutToChange(p, pDest);
86828
- assert( pOp->p1>=0 && pOp->p1<p->nCursor );
8682986927
assert( pC!=0 );
8683086928
assert( p2<pC->nField );
8683186929
aOffset = pC->aOffset;
8683286930
assert( pC->eCurType!=CURTYPE_VTAB );
8683386931
assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow );
@@ -87080,11 +87178,11 @@
8708087178
assert( pOp->p2>0 );
8708187179
assert( zAffinity[pOp->p2]==0 );
8708287180
pIn1 = &aMem[pOp->p1];
8708387181
while( 1 /*exit-by-break*/ ){
8708487182
assert( pIn1 <= &p->aMem[(p->nMem+1 - p->nCursor)] );
87085
- assert( memIsValid(pIn1) );
87183
+ assert( zAffinity[0]==SQLITE_AFF_NONE || memIsValid(pIn1) );
8708687184
applyAffinity(pIn1, zAffinity[0], encoding);
8708787185
if( zAffinity[0]==SQLITE_AFF_REAL && (pIn1->flags & MEM_Int)!=0 ){
8708887186
/* When applying REAL affinity, if the result is still an MEM_Int
8708987187
** that will fit in 6 bytes, then change the type to MEM_IntReal
8709087188
** so that we keep the high-resolution integer value but know that
@@ -87526,12 +87624,16 @@
8752687624
p->pc = (int)(pOp - aOp);
8752787625
db->autoCommit = 0;
8752887626
p->rc = rc = SQLITE_BUSY;
8752987627
goto vdbe_return;
8753087628
}
87531
- db->isTransactionSavepoint = 0;
8753287629
rc = p->rc;
87630
+ if( rc ){
87631
+ db->autoCommit = 0;
87632
+ }else{
87633
+ db->isTransactionSavepoint = 0;
87634
+ }
8753387635
}else{
8753487636
int isSchemaChange;
8753587637
iSavepoint = db->nSavepoint - iSavepoint - 1;
8753687638
if( p1==SAVEPOINT_ROLLBACK ){
8753787639
isSchemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0;
@@ -87555,10 +87657,11 @@
8755587657
sqlite3ExpirePreparedStatements(db, 0);
8755687658
sqlite3ResetAllSchemasOfConnection(db);
8755787659
db->mDbFlags |= DBFLAG_SchemaChange;
8755887660
}
8755987661
}
87662
+ if( rc ) goto abort_due_to_error;
8756087663
8756187664
/* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
8756287665
** savepoints nested inside of the savepoint being operated on. */
8756387666
while( db->pSavepoint!=pSavepoint ){
8756487667
pTmp = db->pSavepoint;
@@ -88050,10 +88153,11 @@
8805088153
case OP_OpenDup: {
8805188154
VdbeCursor *pOrig; /* The original cursor to be duplicated */
8805288155
VdbeCursor *pCx; /* The new cursor */
8805388156
8805488157
pOrig = p->apCsr[pOp->p2];
88158
+ assert( pOrig );
8805588159
assert( pOrig->pBtx!=0 ); /* Only ephemeral cursors can be duplicated */
8805688160
8805788161
pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE);
8805888162
if( pCx==0 ) goto no_mem;
8805988163
pCx->nullRow = 1;
@@ -91479,11 +91583,11 @@
9147991583
pVtab = pCur->uc.pVCur->pVtab;
9148091584
pModule = pVtab->pModule;
9148191585
assert( pModule->xColumn );
9148291586
memset(&sContext, 0, sizeof(sContext));
9148391587
sContext.pOut = pDest;
91484
- testcase( (pOp->p5 & OPFLAG_NOCHNG)==0 && pOp->p5!=0 );
91588
+ assert( pOp->p5==OPFLAG_NOCHNG || pOp->p5==0 );
9148591589
if( pOp->p5 & OPFLAG_NOCHNG ){
9148691590
sqlite3VdbeMemSetNull(pDest);
9148791591
pDest->flags = MEM_Null|MEM_Zero;
9148891592
pDest->u.nZero = 0;
9148991593
}else{
@@ -91939,10 +92043,57 @@
9193992043
case OP_Abortable: {
9194092044
sqlite3VdbeAssertAbortable(p);
9194192045
break;
9194292046
}
9194392047
#endif
92048
+
92049
+#ifdef SQLITE_DEBUG
92050
+/* Opcode: ReleaseReg P1 P2 P3 * *
92051
+** Synopsis: release r[P1@P2] mask P3
92052
+**
92053
+** Release registers from service. Any content that was in the
92054
+** the registers is unreliable after this opcode completes.
92055
+**
92056
+** The registers released will be the P2 registers starting at P1,
92057
+** except if bit ii of P3 set, then do not release register P1+ii.
92058
+** In other words, P3 is a mask of registers to preserve.
92059
+**
92060
+** Releasing a register clears the Mem.pScopyFrom pointer. That means
92061
+** that if the content of the released register was set using OP_SCopy,
92062
+** a change to the value of the source register for the OP_SCopy will no longer
92063
+** generate an assertion fault in sqlite3VdbeMemAboutToChange().
92064
+**
92065
+** TODO: Released registers ought to also have their datatype set to
92066
+** MEM_Undefined so that any subsequent attempt to read the released
92067
+** register (before it is reinitialized) will generate an assertion fault.
92068
+** However, there are places in the code generator which release registers
92069
+** before their are used, under the (valid) assumption that the registers
92070
+** will not be reallocated for some other purpose before they are used and
92071
+** hence are safe to release.
92072
+**
92073
+** This opcode is only available in testing and debugging builds. It is
92074
+** not generated for release builds. The purpose of this opcode is to help
92075
+** validate the generated bytecode. This opcode does not actually contribute
92076
+** to computing an answer.
92077
+*/
92078
+case OP_ReleaseReg: {
92079
+ Mem *pMem;
92080
+ int i;
92081
+ u32 constMask;
92082
+ assert( pOp->p1>0 );
92083
+ assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 );
92084
+ pMem = &aMem[pOp->p1];
92085
+ constMask = pOp->p3;
92086
+ for(i=0; i<pOp->p2; i++, pMem++){
92087
+ if( i>=32 || (constMask & MASKBIT32(i))==0 ){
92088
+ pMem->pScopyFrom = 0;
92089
+ /* MemSetTypeFlag(pMem, MEM_Undefined); // See the TODO */
92090
+ }
92091
+ }
92092
+ break;
92093
+}
92094
+#endif
9194492095
9194592096
/* Opcode: Noop * * * * *
9194692097
**
9194792098
** Do nothing. This instruction is often useful as a jump
9194892099
** destination.
@@ -95849,12 +96000,12 @@
9584996000
testcase( ExprHasProperty(pExpr, EP_Reduced) );
9585096001
while(1){
9585196002
rc = pWalker->xExprCallback(pWalker, pExpr);
9585296003
if( rc ) return rc & WRC_Abort;
9585396004
if( !ExprHasProperty(pExpr,(EP_TokenOnly|EP_Leaf)) ){
96005
+ assert( pExpr->x.pList==0 || pExpr->pRight==0 );
9585496006
if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
95855
- assert( pExpr->x.pList==0 || pExpr->pRight==0 );
9585696007
if( pExpr->pRight ){
9585796008
assert( !ExprHasProperty(pExpr, EP_WinFunc) );
9585896009
pExpr = pExpr->pRight;
9585996010
continue;
9586096011
}else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
@@ -96538,22 +96689,39 @@
9653896689
pTopNC->nErr++;
9653996690
}
9654096691
9654196692
/* If a column from a table in pSrcList is referenced, then record
9654296693
** this fact in the pSrcList.a[].colUsed bitmask. Column 0 causes
96543
- ** bit 0 to be set. Column 1 sets bit 1. And so forth. If the
96544
- ** column number is greater than the number of bits in the bitmask
96545
- ** then set the high-order bit of the bitmask.
96694
+ ** bit 0 to be set. Column 1 sets bit 1. And so forth. Bit 63 is
96695
+ ** set if the 63rd or any subsequent column is used.
96696
+ **
96697
+ ** The colUsed mask is an optimization used to help determine if an
96698
+ ** index is a covering index. The correct answer is still obtained
96699
+ ** if the mask contains extra set bits. However, it is important to
96700
+ ** avoid setting bits beyond the maximum column number of the table.
96701
+ ** (See ticket [b92e5e8ec2cdbaa1]).
96702
+ **
96703
+ ** If a generated column is referenced, set bits for every column
96704
+ ** of the table.
9654696705
*/
9654796706
if( pExpr->iColumn>=0 && pMatch!=0 ){
9654896707
int n = pExpr->iColumn;
96549
- testcase( n==BMS-1 );
96550
- if( n>=BMS ){
96551
- n = BMS-1;
96552
- }
96708
+ Table *pExTab = pExpr->y.pTab;
96709
+ assert( pExTab!=0 );
9655396710
assert( pMatch->iCursor==pExpr->iTable );
96554
- pMatch->colUsed |= ((Bitmask)1)<<n;
96711
+ if( (pExTab->tabFlags & TF_HasGenerated)!=0
96712
+ && (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0
96713
+ ){
96714
+ testcase( pExTab->nCol==BMS-1 );
96715
+ testcase( pExTab->nCol==BMS );
96716
+ pMatch->colUsed = pExTab->nCol>=BMS ? ALLBITS : MASKBIT(pExTab->nCol)-1;
96717
+ }else{
96718
+ testcase( n==BMS-1 );
96719
+ testcase( n==BMS );
96720
+ if( n>=BMS ) n = BMS-1;
96721
+ pMatch->colUsed |= ((Bitmask)1)<<n;
96722
+ }
9655596723
}
9655696724
9655796725
/* Clean up and return
9655896726
*/
9655996727
sqlite3ExprDelete(db, pExpr->pLeft);
@@ -96588,47 +96756,68 @@
9658896756
*/
9658996757
SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
9659096758
Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
9659196759
if( p ){
9659296760
struct SrcList_item *pItem = &pSrc->a[iSrc];
96593
- p->y.pTab = pItem->pTab;
96761
+ Table *pTab = p->y.pTab = pItem->pTab;
9659496762
p->iTable = pItem->iCursor;
9659596763
if( p->y.pTab->iPKey==iCol ){
9659696764
p->iColumn = -1;
9659796765
}else{
9659896766
p->iColumn = (ynVar)iCol;
96599
- testcase( iCol==BMS );
96600
- testcase( iCol==BMS-1 );
96601
- pItem->colUsed |= ((Bitmask)1)<<(iCol>=BMS ? BMS-1 : iCol);
96767
+ if( (pTab->tabFlags & TF_HasGenerated)!=0
96768
+ && (pTab->aCol[iCol].colFlags & COLFLAG_GENERATED)!=0
96769
+ ){
96770
+ testcase( pTab->nCol==63 );
96771
+ testcase( pTab->nCol==64 );
96772
+ pItem->colUsed = pTab->nCol>=64 ? ALLBITS : MASKBIT(pTab->nCol)-1;
96773
+ }else{
96774
+ testcase( iCol==BMS );
96775
+ testcase( iCol==BMS-1 );
96776
+ pItem->colUsed |= ((Bitmask)1)<<(iCol>=BMS ? BMS-1 : iCol);
96777
+ }
9660296778
}
9660396779
}
9660496780
return p;
9660596781
}
9660696782
9660796783
/*
9660896784
** Report an error that an expression is not valid for some set of
9660996785
** pNC->ncFlags values determined by validMask.
96786
+**
96787
+** static void notValid(
96788
+** Parse *pParse, // Leave error message here
96789
+** NameContext *pNC, // The name context
96790
+** const char *zMsg, // Type of error
96791
+** int validMask, // Set of contexts for which prohibited
96792
+** Expr *pExpr // Invalidate this expression on error
96793
+** ){...}
96794
+**
96795
+** As an optimization, since the conditional is almost always false
96796
+** (because errors are rare), the conditional is moved outside of the
96797
+** function call using a macro.
9661096798
*/
96611
-static void notValid(
96612
- Parse *pParse, /* Leave error message here */
96613
- NameContext *pNC, /* The name context */
96614
- const char *zMsg, /* Type of error */
96615
- int validMask /* Set of contexts for which prohibited */
96799
+static void notValidImpl(
96800
+ Parse *pParse, /* Leave error message here */
96801
+ NameContext *pNC, /* The name context */
96802
+ const char *zMsg, /* Type of error */
96803
+ Expr *pExpr /* Invalidate this expression on error */
9661696804
){
96617
- assert( (validMask&~(NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol))==0 );
96618
- if( (pNC->ncFlags & validMask)!=0 ){
96619
- const char *zIn = "partial index WHERE clauses";
96620
- if( pNC->ncFlags & NC_IdxExpr ) zIn = "index expressions";
96805
+ const char *zIn = "partial index WHERE clauses";
96806
+ if( pNC->ncFlags & NC_IdxExpr ) zIn = "index expressions";
9662196807
#ifndef SQLITE_OMIT_CHECK
96622
- else if( pNC->ncFlags & NC_IsCheck ) zIn = "CHECK constraints";
96808
+ else if( pNC->ncFlags & NC_IsCheck ) zIn = "CHECK constraints";
9662396809
#endif
9662496810
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
96625
- else if( pNC->ncFlags & NC_GenCol ) zIn = "generated columns";
96811
+ else if( pNC->ncFlags & NC_GenCol ) zIn = "generated columns";
9662696812
#endif
96627
- sqlite3ErrorMsg(pParse, "%s prohibited in %s", zMsg, zIn);
96628
- }
96813
+ sqlite3ErrorMsg(pParse, "%s prohibited in %s", zMsg, zIn);
96814
+ if( pExpr ) pExpr->op = TK_NULL;
9662996815
}
96816
+#define sqlite3ResolveNotValid(P,N,M,X,E) \
96817
+ assert( ((X)&~(NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol))==0 ); \
96818
+ if( ((N)->ncFlags & (X))!=0 ) notValidImpl(P,N,M,E);
9663096819
9663196820
/*
9663296821
** Expression p should encode a floating point value between 1.0 and 0.0.
9663396822
** Return 1024 times this value. Or return -1 if p is not a floating point
9663496823
** value between 1.0 and 0.0.
@@ -96713,11 +96902,14 @@
9671396902
zDb = 0;
9671496903
zTable = 0;
9671596904
zColumn = pExpr->u.zToken;
9671696905
}else{
9671796906
Expr *pLeft = pExpr->pLeft;
96718
- notValid(pParse, pNC, "the \".\" operator", NC_IdxExpr|NC_GenCol);
96907
+ testcase( pNC->ncFlags & NC_IdxExpr );
96908
+ testcase( pNC->ncFlags & NC_GenCol );
96909
+ sqlite3ResolveNotValid(pParse, pNC, "the \".\" operator",
96910
+ NC_IdxExpr|NC_GenCol, 0);
9671996911
pRight = pExpr->pRight;
9672096912
if( pRight->op==TK_ID ){
9672196913
zDb = 0;
9672296914
}else{
9672396915
assert( pRight->op==TK_DOT );
@@ -96810,11 +97002,12 @@
9681097002
}
9681197003
if( (pDef->funcFlags & SQLITE_FUNC_CONSTANT)==0 ){
9681297004
/* Date/time functions that use 'now', and other functions like
9681397005
** sqlite_version() that might change over time cannot be used
9681497006
** in an index. */
96815
- notValid(pParse, pNC, "non-deterministic functions", NC_SelfRef);
97007
+ sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions",
97008
+ NC_SelfRef, 0);
9681697009
}else{
9681797010
assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
9681897011
pExpr->op2 = pNC->ncFlags & NC_SelfRef;
9681997012
}
9682097013
if( (pDef->funcFlags & SQLITE_FUNC_INTERNAL)!=0
@@ -96912,11 +97105,11 @@
9691297105
#ifndef SQLITE_OMIT_WINDOWFUNC
9691397106
if( pWin ){
9691497107
Select *pSel = pNC->pWinSelect;
9691597108
assert( pWin==pExpr->y.pWin );
9691697109
if( IN_RENAME_OBJECT==0 ){
96917
- sqlite3WindowUpdate(pParse, pSel->pWinDefn, pWin, pDef);
97110
+ sqlite3WindowUpdate(pParse, pSel ? pSel->pWinDefn : 0, pWin, pDef);
9691897111
}
9691997112
sqlite3WalkExprList(pWalker, pWin->pPartition);
9692097113
sqlite3WalkExprList(pWalker, pWin->pOrderBy);
9692197114
sqlite3WalkExpr(pWalker, pWin->pFilter);
9692297115
sqlite3WindowLink(pSel, pWin);
@@ -96957,12 +97150,16 @@
9695797150
#endif
9695897151
case TK_IN: {
9695997152
testcase( pExpr->op==TK_IN );
9696097153
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
9696197154
int nRef = pNC->nRef;
96962
- notValid(pParse, pNC, "subqueries",
96963
- NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol);
97155
+ testcase( pNC->ncFlags & NC_IsCheck );
97156
+ testcase( pNC->ncFlags & NC_PartIdx );
97157
+ testcase( pNC->ncFlags & NC_IdxExpr );
97158
+ testcase( pNC->ncFlags & NC_GenCol );
97159
+ sqlite3ResolveNotValid(pParse, pNC, "subqueries",
97160
+ NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol, pExpr);
9696497161
sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
9696597162
assert( pNC->nRef>=nRef );
9696697163
if( nRef!=pNC->nRef ){
9696797164
ExprSetProperty(pExpr, EP_VarSelect);
9696897165
pNC->ncFlags |= NC_VarSelect;
@@ -96969,12 +97166,16 @@
9696997166
}
9697097167
}
9697197168
break;
9697297169
}
9697397170
case TK_VARIABLE: {
96974
- notValid(pParse, pNC, "parameters",
96975
- NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol);
97171
+ testcase( pNC->ncFlags & NC_IsCheck );
97172
+ testcase( pNC->ncFlags & NC_PartIdx );
97173
+ testcase( pNC->ncFlags & NC_IdxExpr );
97174
+ testcase( pNC->ncFlags & NC_GenCol );
97175
+ sqlite3ResolveNotValid(pParse, pNC, "parameters",
97176
+ NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol, pExpr);
9697697177
break;
9697797178
}
9697897179
case TK_IS:
9697997180
case TK_ISNOT: {
9698097181
Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight);
@@ -98203,10 +98404,11 @@
9820398404
){
9820498405
int p5;
9820598406
int addr;
9820698407
CollSeq *p4;
9820798408
98409
+ if( pParse->nErr ) return 0;
9820898410
if( isCommuted ){
9820998411
p4 = sqlite3BinaryCompareCollSeq(pParse, pRight, pLeft);
9821098412
}else{
9821198413
p4 = sqlite3BinaryCompareCollSeq(pParse, pLeft, pRight);
9821298414
}
@@ -98420,10 +98622,11 @@
9842098622
int regRight = 0;
9842198623
u8 opx = op;
9842298624
int addrDone = sqlite3VdbeMakeLabel(pParse);
9842398625
int isCommuted = ExprHasProperty(pExpr,EP_Commuted);
9842498626
98627
+ if( pParse->nErr ) return;
9842598628
if( nLeft!=sqlite3ExprVectorSize(pRight) ){
9842698629
sqlite3ErrorMsg(pParse, "row value misused");
9842798630
return;
9842898631
}
9842998632
assert( pExpr->op==TK_EQ || pExpr->op==TK_NE
@@ -99768,11 +99971,13 @@
9976899971
switch( pExpr->op ){
9976999972
/* Consider functions to be constant if all their arguments are constant
9977099973
** and either pWalker->eCode==4 or 5 or the function has the
9977199974
** SQLITE_FUNC_CONST flag. */
9977299975
case TK_FUNCTION:
99773
- if( pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_ConstFunc) ){
99976
+ if( (pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_ConstFunc))
99977
+ && !ExprHasProperty(pExpr, EP_WinFunc)
99978
+ ){
9977499979
return WRC_Continue;
9977599980
}else{
9977699981
pWalker->eCode = 0;
9977799982
return WRC_Abort;
9977899983
}
@@ -100031,11 +100236,13 @@
100031100236
case TK_BLOB:
100032100237
return 0;
100033100238
case TK_COLUMN:
100034100239
return ExprHasProperty(p, EP_CanBeNull) ||
100035100240
p->y.pTab==0 || /* Reference to column of index on expression */
100036
- (p->iColumn>=0 && p->y.pTab->aCol[p->iColumn].notNull==0);
100241
+ (p->iColumn>=0
100242
+ && ALWAYS(p->y.pTab->aCol!=0) /* Defense against OOM problems */
100243
+ && p->y.pTab->aCol[p->iColumn].notNull==0);
100037100244
default:
100038100245
return 1;
100039100246
}
100040100247
}
100041100248
@@ -100508,12 +100715,14 @@
100508100715
** message of the form:
100509100716
**
100510100717
** "sub-select returns N columns - expected M"
100511100718
*/
100512100719
SQLITE_PRIVATE void sqlite3SubselectError(Parse *pParse, int nActual, int nExpect){
100513
- const char *zFmt = "sub-select returns %d columns - expected %d";
100514
- sqlite3ErrorMsg(pParse, zFmt, nActual, nExpect);
100720
+ if( pParse->nErr==0 ){
100721
+ const char *zFmt = "sub-select returns %d columns - expected %d";
100722
+ sqlite3ErrorMsg(pParse, zFmt, nActual, nExpect);
100723
+ }
100515100724
}
100516100725
#endif
100517100726
100518100727
/*
100519100728
** Expression pExpr is a vector that has been used in a context where
@@ -101011,19 +101220,25 @@
101011101220
}
101012101221
if( regCkNull && sqlite3ExprCanBeNull(pList->a[ii].pExpr) ){
101013101222
sqlite3VdbeAddOp3(v, OP_BitAnd, regCkNull, r2, regCkNull);
101014101223
}
101015101224
if( ii<pList->nExpr-1 || destIfNull!=destIfFalse ){
101016
- sqlite3VdbeAddOp4(v, OP_Eq, rLhs, labelOk, r2,
101225
+ int op = rLhs!=r2 ? OP_Eq : OP_NotNull;
101226
+ sqlite3VdbeAddOp4(v, op, rLhs, labelOk, r2,
101017101227
(void*)pColl, P4_COLLSEQ);
101018
- VdbeCoverageIf(v, ii<pList->nExpr-1);
101019
- VdbeCoverageIf(v, ii==pList->nExpr-1);
101228
+ VdbeCoverageIf(v, ii<pList->nExpr-1 && op==OP_Eq);
101229
+ VdbeCoverageIf(v, ii==pList->nExpr-1 && op==OP_Eq);
101230
+ VdbeCoverageIf(v, ii<pList->nExpr-1 && op==OP_NotNull);
101231
+ VdbeCoverageIf(v, ii==pList->nExpr-1 && op==OP_NotNull);
101020101232
sqlite3VdbeChangeP5(v, zAff[0]);
101021101233
}else{
101234
+ int op = rLhs!=r2 ? OP_Ne : OP_IsNull;
101022101235
assert( destIfNull==destIfFalse );
101023
- sqlite3VdbeAddOp4(v, OP_Ne, rLhs, destIfFalse, r2,
101024
- (void*)pColl, P4_COLLSEQ); VdbeCoverage(v);
101236
+ sqlite3VdbeAddOp4(v, op, rLhs, destIfFalse, r2,
101237
+ (void*)pColl, P4_COLLSEQ);
101238
+ VdbeCoverageIf(v, op==OP_Ne);
101239
+ VdbeCoverageIf(v, op==OP_IsNull);
101025101240
sqlite3VdbeChangeP5(v, zAff[0] | SQLITE_JUMPIFNULL);
101026101241
}
101027101242
sqlite3ReleaseTempReg(pParse, regToFree);
101028101243
}
101029101244
if( regCkNull ){
@@ -101042,10 +101257,11 @@
101042101257
if( destIfNull==destIfFalse ){
101043101258
destStep2 = destIfFalse;
101044101259
}else{
101045101260
destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
101046101261
}
101262
+ if( pParse->nErr ) goto sqlite3ExprCodeIN_finished;
101047101263
for(i=0; i<nVector; i++){
101048101264
Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
101049101265
if( sqlite3ExprCanBeNull(p) ){
101050101266
sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
101051101267
VdbeCoverage(v);
@@ -101233,15 +101449,24 @@
101233101449
SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(
101234101450
Parse *pParse,
101235101451
Column *pCol,
101236101452
int regOut
101237101453
){
101454
+ int iAddr;
101455
+ Vdbe *v = pParse->pVdbe;
101456
+ assert( v!=0 );
101457
+ assert( pParse->iSelfTab!=0 );
101458
+ if( pParse->iSelfTab>0 ){
101459
+ iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut);
101460
+ }else{
101461
+ iAddr = 0;
101462
+ }
101238101463
sqlite3ExprCode(pParse, pCol->pDflt, regOut);
101239101464
if( pCol->affinity>=SQLITE_AFF_TEXT ){
101240
- sqlite3VdbeAddOp4(pParse->pVdbe, OP_Affinity, regOut, 1, 0,
101241
- &pCol->affinity, 1);
101465
+ sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1);
101242101466
}
101467
+ if( iAddr ) sqlite3VdbeJumpHere(v, iAddr);
101243101468
}
101244101469
#endif /* SQLITE_OMIT_GENERATED_COLUMNS */
101245101470
101246101471
/*
101247101472
** Generate code to extract the value of the iCol-th column of a table.
@@ -101312,21 +101537,21 @@
101312101537
u8 p5 /* P5 value for OP_Column + FLAGS */
101313101538
){
101314101539
assert( pParse->pVdbe!=0 );
101315101540
sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pTab, iTable, iColumn, iReg);
101316101541
if( p5 ){
101317
- sqlite3VdbeChangeP5(pParse->pVdbe, p5);
101542
+ VdbeOp *pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1);
101543
+ if( pOp->opcode==OP_Column ) pOp->p5 = p5;
101318101544
}
101319101545
return iReg;
101320101546
}
101321101547
101322101548
/*
101323101549
** Generate code to move content from registers iFrom...iFrom+nReg-1
101324101550
** over to iTo..iTo+nReg-1.
101325101551
*/
101326101552
SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse *pParse, int iFrom, int iTo, int nReg){
101327
- assert( iFrom>=iTo+nReg || iFrom+nReg<=iTo );
101328101553
sqlite3VdbeAddOp3(pParse->pVdbe, OP_Move, iFrom, iTo, nReg);
101329101554
}
101330101555
101331101556
/*
101332101557
** Convert a scalar expression node to a TK_REGISTER referencing
@@ -101424,19 +101649,25 @@
101424101649
}
101425101650
/* Otherwise, fall thru into the TK_COLUMN case */
101426101651
}
101427101652
case TK_COLUMN: {
101428101653
int iTab = pExpr->iTable;
101654
+ int iReg;
101429101655
if( ExprHasProperty(pExpr, EP_FixedCol) ){
101430101656
/* This COLUMN expression is really a constant due to WHERE clause
101431101657
** constraints, and that constant is coded by the pExpr->pLeft
101432101658
** expresssion. However, make sure the constant has the correct
101433101659
** datatype by applying the Affinity of the table column to the
101434101660
** constant.
101435101661
*/
101436
- int iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target);
101437
- int aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
101662
+ int aff;
101663
+ iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target);
101664
+ if( pExpr->y.pTab ){
101665
+ aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
101666
+ }else{
101667
+ aff = pExpr->affExpr;
101668
+ }
101438101669
if( aff>SQLITE_AFF_BLOB ){
101439101670
static const char zAff[] = "B\000C\000D\000E";
101440101671
assert( SQLITE_AFF_BLOB=='A' );
101441101672
assert( SQLITE_AFF_TEXT=='B' );
101442101673
if( iReg!=target ){
@@ -101460,11 +101691,11 @@
101460101691
Table *pTab = pExpr->y.pTab;
101461101692
int iSrc;
101462101693
int iCol = pExpr->iColumn;
101463101694
assert( pTab!=0 );
101464101695
assert( iCol>=XN_ROWID );
101465
- assert( iCol<pExpr->y.pTab->nCol );
101696
+ assert( iCol<pTab->nCol );
101466101697
if( iCol<0 ){
101467101698
return -1-pParse->iSelfTab;
101468101699
}
101469101700
pCol = pTab->aCol + iCol;
101470101701
testcase( iCol!=sqlite3TableColumnToStorage(pTab,iCol) );
@@ -101495,13 +101726,17 @@
101495101726
/* Coding an expression that is part of an index where column names
101496101727
** in the index refer to the table to which the index belongs */
101497101728
iTab = pParse->iSelfTab - 1;
101498101729
}
101499101730
}
101500
- return sqlite3ExprCodeGetColumn(pParse, pExpr->y.pTab,
101731
+ iReg = sqlite3ExprCodeGetColumn(pParse, pExpr->y.pTab,
101501101732
pExpr->iColumn, iTab, target,
101502101733
pExpr->op2);
101734
+ if( pExpr->y.pTab==0 && pExpr->affExpr==SQLITE_AFF_REAL ){
101735
+ sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
101736
+ }
101737
+ return iReg;
101503101738
}
101504101739
case TK_INTEGER: {
101505101740
codeInteger(pParse, pExpr, 0, target);
101506101741
return target;
101507101742
}
@@ -101519,11 +101754,16 @@
101519101754
case TK_STRING: {
101520101755
assert( !ExprHasProperty(pExpr, EP_IntValue) );
101521101756
sqlite3VdbeLoadString(v, target, pExpr->u.zToken);
101522101757
return target;
101523101758
}
101524
- case TK_NULL: {
101759
+ default: {
101760
+ /* Make NULL the default case so that if a bug causes an illegal
101761
+ ** Expr node to be passed into this function, it will be handled
101762
+ ** sanely and not crash. But keep the assert() to bring the problem
101763
+ ** to the attention of the developers. */
101764
+ assert( op==TK_NULL );
101525101765
sqlite3VdbeAddOp2(v, OP_Null, 0, target);
101526101766
return target;
101527101767
}
101528101768
#ifndef SQLITE_OMIT_BLOB_LITERAL
101529101769
case TK_BLOB: {
@@ -101546,11 +101786,11 @@
101546101786
assert( pExpr->u.zToken!=0 );
101547101787
assert( pExpr->u.zToken[0]!=0 );
101548101788
sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target);
101549101789
if( pExpr->u.zToken[1]!=0 ){
101550101790
const char *z = sqlite3VListNumToName(pParse->pVList, pExpr->iColumn);
101551
- assert( pExpr->u.zToken[0]=='?' || strcmp(pExpr->u.zToken, z)==0 );
101791
+ assert( pExpr->u.zToken[0]=='?' || (z && !strcmp(pExpr->u.zToken, z)) );
101552101792
pParse->pVList[0] = 0; /* Indicate VList may no longer be enlarged */
101553101793
sqlite3VdbeAppendP4(v, (char*)z, P4_STATIC);
101554101794
}
101555101795
return target;
101556101796
}
@@ -101859,12 +102099,16 @@
101859102099
#endif
101860102100
{
101861102101
sqlite3VdbeAddFunctionCall(pParse, constMask, r1, target, nFarg,
101862102102
pDef, pExpr->op2);
101863102103
}
101864
- if( nFarg && constMask==0 ){
101865
- sqlite3ReleaseTempRange(pParse, r1, nFarg);
102104
+ if( nFarg ){
102105
+ if( constMask==0 ){
102106
+ sqlite3ReleaseTempRange(pParse, r1, nFarg);
102107
+ }else{
102108
+ sqlite3VdbeReleaseRegisters(pParse, r1, nFarg, constMask);
102109
+ }
101866102110
}
101867102111
return target;
101868102112
}
101869102113
#ifndef SQLITE_OMIT_SUBQUERY
101870102114
case TK_EXISTS:
@@ -101956,11 +102200,11 @@
101956102200
** p1==2 -> old.b p1==5 -> new.b
101957102201
*/
101958102202
Table *pTab = pExpr->y.pTab;
101959102203
int iCol = pExpr->iColumn;
101960102204
int p1 = pExpr->iTable * (pTab->nCol+1) + 1
101961
- + (iCol>=0 ? sqlite3TableColumnToStorage(pTab, iCol) : -1);
102205
+ + sqlite3TableColumnToStorage(pTab, iCol);
101962102206
101963102207
assert( pExpr->iTable==0 || pExpr->iTable==1 );
101964102208
assert( iCol>=-1 && iCol<pTab->nCol );
101965102209
assert( pTab->iPKey<0 || iCol!=pTab->iPKey );
101966102210
assert( p1>=0 && p1<(pTab->nCol*2+2) );
@@ -102030,11 +102274,11 @@
102030102274
**
102031102275
** The result of the expression is the Ri for the first matching Ei,
102032102276
** or if there is no matching Ei, the ELSE term Y, or if there is
102033102277
** no ELSE term, NULL.
102034102278
*/
102035
- default: assert( op==TK_CASE ); {
102279
+ case TK_CASE: {
102036102280
int endLabel; /* GOTO label for end of CASE stmt */
102037102281
int nextCase; /* GOTO label for next WHEN clause */
102038102282
int nExpr; /* 2x number of WHEN terms */
102039102283
int i; /* Loop counter */
102040102284
ExprList *pEList; /* List of WHEN terms */
@@ -103087,11 +103331,14 @@
103087103331
sqlite3WalkExpr(pWalker, pExpr->pRight);
103088103332
}
103089103333
return WRC_Prune;
103090103334
103091103335
case TK_BETWEEN:
103092
- sqlite3WalkExpr(pWalker, pExpr->pLeft);
103336
+ if( sqlite3WalkExpr(pWalker, pExpr->pLeft)==WRC_Abort ){
103337
+ assert( pWalker->eCode );
103338
+ return WRC_Abort;
103339
+ }
103093103340
return WRC_Prune;
103094103341
103095103342
/* Virtual tables are allowed to use constraints like x=NULL. So
103096103343
** a term of the form x=y does not prove that y is not null if x
103097103344
** is the column of a virtual table */
@@ -103501,12 +103748,15 @@
103501103748
/*
103502103749
** Deallocate a register, making available for reuse for some other
103503103750
** purpose.
103504103751
*/
103505103752
SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse *pParse, int iReg){
103506
- if( iReg && pParse->nTempReg<ArraySize(pParse->aTempReg) ){
103507
- pParse->aTempReg[pParse->nTempReg++] = iReg;
103753
+ if( iReg ){
103754
+ sqlite3VdbeReleaseRegisters(pParse, iReg, 1, 0);
103755
+ if( pParse->nTempReg<ArraySize(pParse->aTempReg) ){
103756
+ pParse->aTempReg[pParse->nTempReg++] = iReg;
103757
+ }
103508103758
}
103509103759
}
103510103760
103511103761
/*
103512103762
** Allocate or deallocate a block of nReg consecutive registers.
@@ -103528,10 +103778,11 @@
103528103778
SQLITE_PRIVATE void sqlite3ReleaseTempRange(Parse *pParse, int iReg, int nReg){
103529103779
if( nReg==1 ){
103530103780
sqlite3ReleaseTempReg(pParse, iReg);
103531103781
return;
103532103782
}
103783
+ sqlite3VdbeReleaseRegisters(pParse, iReg, nReg, 0);
103533103784
if( nReg>pParse->nRangeReg ){
103534103785
pParse->nRangeReg = nReg;
103535103786
pParse->iRangeReg = iReg;
103536103787
}
103537103788
}
@@ -104271,16 +104522,18 @@
104271104522
*/
104272104523
SQLITE_PRIVATE void *sqlite3RenameTokenMap(Parse *pParse, void *pPtr, Token *pToken){
104273104524
RenameToken *pNew;
104274104525
assert( pPtr || pParse->db->mallocFailed );
104275104526
renameTokenCheckAll(pParse, pPtr);
104276
- pNew = sqlite3DbMallocZero(pParse->db, sizeof(RenameToken));
104277
- if( pNew ){
104278
- pNew->p = pPtr;
104279
- pNew->t = *pToken;
104280
- pNew->pNext = pParse->pRename;
104281
- pParse->pRename = pNew;
104527
+ if( pParse->eParseMode!=PARSE_MODE_UNMAP ){
104528
+ pNew = sqlite3DbMallocZero(pParse->db, sizeof(RenameToken));
104529
+ if( pNew ){
104530
+ pNew->p = pPtr;
104531
+ pNew->t = *pToken;
104532
+ pNew->pNext = pParse->pRename;
104533
+ pParse->pRename = pNew;
104534
+ }
104282104535
}
104283104536
104284104537
return pPtr;
104285104538
}
104286104539
@@ -104306,17 +104559,39 @@
104306104559
static int renameUnmapExprCb(Walker *pWalker, Expr *pExpr){
104307104560
Parse *pParse = pWalker->pParse;
104308104561
sqlite3RenameTokenRemap(pParse, 0, (void*)pExpr);
104309104562
return WRC_Continue;
104310104563
}
104564
+
104565
+/*
104566
+** Iterate through the Select objects that are part of WITH clauses attached
104567
+** to select statement pSelect.
104568
+*/
104569
+static void renameWalkWith(Walker *pWalker, Select *pSelect){
104570
+ With *pWith = pSelect->pWith;
104571
+ if( pWith ){
104572
+ int i;
104573
+ for(i=0; i<pWith->nCte; i++){
104574
+ Select *p = pWith->a[i].pSelect;
104575
+ NameContext sNC;
104576
+ memset(&sNC, 0, sizeof(sNC));
104577
+ sNC.pParse = pWalker->pParse;
104578
+ sqlite3SelectPrep(sNC.pParse, p, &sNC);
104579
+ sqlite3WalkSelect(pWalker, p);
104580
+ sqlite3RenameExprlistUnmap(pWalker->pParse, pWith->a[i].pCols);
104581
+ }
104582
+ }
104583
+}
104311104584
104312104585
/*
104313104586
** Walker callback used by sqlite3RenameExprUnmap().
104314104587
*/
104315104588
static int renameUnmapSelectCb(Walker *pWalker, Select *p){
104316104589
Parse *pParse = pWalker->pParse;
104317104590
int i;
104591
+ if( pParse->nErr ) return WRC_Abort;
104592
+ if( NEVER(p->selFlags & SF_View) ) return WRC_Prune;
104318104593
if( ALWAYS(p->pEList) ){
104319104594
ExprList *pList = p->pEList;
104320104595
for(i=0; i<pList->nExpr; i++){
104321104596
if( pList->a[i].zName ){
104322104597
sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zName);
@@ -104325,25 +104600,31 @@
104325104600
}
104326104601
if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
104327104602
SrcList *pSrc = p->pSrc;
104328104603
for(i=0; i<pSrc->nSrc; i++){
104329104604
sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName);
104605
+ if( sqlite3WalkExpr(pWalker, pSrc->a[i].pOn) ) return WRC_Abort;
104330104606
}
104331104607
}
104608
+
104609
+ renameWalkWith(pWalker, p);
104332104610
return WRC_Continue;
104333104611
}
104334104612
104335104613
/*
104336104614
** Remove all nodes that are part of expression pExpr from the rename list.
104337104615
*/
104338104616
SQLITE_PRIVATE void sqlite3RenameExprUnmap(Parse *pParse, Expr *pExpr){
104617
+ u8 eMode = pParse->eParseMode;
104339104618
Walker sWalker;
104340104619
memset(&sWalker, 0, sizeof(Walker));
104341104620
sWalker.pParse = pParse;
104342104621
sWalker.xExprCallback = renameUnmapExprCb;
104343104622
sWalker.xSelectCallback = renameUnmapSelectCb;
104623
+ pParse->eParseMode = PARSE_MODE_UNMAP;
104344104624
sqlite3WalkExpr(&sWalker, pExpr);
104625
+ pParse->eParseMode = eMode;
104345104626
}
104346104627
104347104628
/*
104348104629
** Remove all nodes that are part of expression-list pEList from the
104349104630
** rename list.
@@ -104393,34 +104674,17 @@
104393104674
break;
104394104675
}
104395104676
}
104396104677
}
104397104678
104398
-/*
104399
-** Iterate through the Select objects that are part of WITH clauses attached
104400
-** to select statement pSelect.
104401
-*/
104402
-static void renameWalkWith(Walker *pWalker, Select *pSelect){
104403
- if( pSelect->pWith ){
104404
- int i;
104405
- for(i=0; i<pSelect->pWith->nCte; i++){
104406
- Select *p = pSelect->pWith->a[i].pSelect;
104407
- NameContext sNC;
104408
- memset(&sNC, 0, sizeof(sNC));
104409
- sNC.pParse = pWalker->pParse;
104410
- sqlite3SelectPrep(sNC.pParse, p, &sNC);
104411
- sqlite3WalkSelect(pWalker, p);
104412
- }
104413
- }
104414
-}
104415
-
104416104679
/*
104417104680
** This is a Walker select callback. It does nothing. It is only required
104418104681
** because without a dummy callback, sqlite3WalkExpr() and similar do not
104419104682
** descend into sub-select statements.
104420104683
*/
104421104684
static int renameColumnSelectCb(Walker *pWalker, Select *p){
104685
+ if( p->selFlags & SF_View ) return WRC_Prune;
104422104686
renameWalkWith(pWalker, p);
104423104687
return WRC_Continue;
104424104688
}
104425104689
104426104690
/*
@@ -104547,11 +104811,10 @@
104547104811
** is initialized by this function before it is used.
104548104812
*/
104549104813
static int renameParseSql(
104550104814
Parse *p, /* Memory to use for Parse object */
104551104815
const char *zDb, /* Name of schema SQL belongs to */
104552
- int bTable, /* 1 -> RENAME TABLE, 0 -> RENAME COLUMN */
104553104816
sqlite3 *db, /* Database handle */
104554104817
const char *zSql, /* SQL to parse */
104555104818
int bTemp /* True if SQL is from temp schema */
104556104819
){
104557104820
int rc;
@@ -104561,11 +104824,11 @@
104561104824
104562104825
/* Parse the SQL statement passed as the first argument. If no error
104563104826
** occurs and the parse does not result in a new table, index or
104564104827
** trigger object, the database must be corrupt. */
104565104828
memset(p, 0, sizeof(Parse));
104566
- p->eParseMode = (bTable ? PARSE_MODE_RENAME_TABLE : PARSE_MODE_RENAME_COLUMN);
104829
+ p->eParseMode = PARSE_MODE_RENAME;
104567104830
p->db = db;
104568104831
p->nQueryLoop = 1;
104569104832
rc = sqlite3RunParser(p, zSql, &zErr);
104570104833
assert( p->zErrMsg==0 );
104571104834
assert( rc!=SQLITE_OK || zErr==0 );
@@ -104868,11 +105131,11 @@
104868105131
sCtx.iCol = ((iCol==pTab->iPKey) ? -1 : iCol);
104869105132
104870105133
#ifndef SQLITE_OMIT_AUTHORIZATION
104871105134
db->xAuth = 0;
104872105135
#endif
104873
- rc = renameParseSql(&sParse, zDb, 0, db, zSql, bTemp);
105136
+ rc = renameParseSql(&sParse, zDb, db, zSql, bTemp);
104874105137
104875105138
/* Find tokens that need to be replaced. */
104876105139
memset(&sWalker, 0, sizeof(Walker));
104877105140
sWalker.pParse = &sParse;
104878105141
sWalker.xExprCallback = renameColumnExprCb;
@@ -104882,12 +105145,13 @@
104882105145
sCtx.pTab = pTab;
104883105146
if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
104884105147
if( sParse.pNewTable ){
104885105148
Select *pSelect = sParse.pNewTable->pSelect;
104886105149
if( pSelect ){
105150
+ pSelect->selFlags &= ~SF_View;
104887105151
sParse.rc = SQLITE_OK;
104888
- sqlite3SelectPrep(&sParse, sParse.pNewTable->pSelect, 0);
105152
+ sqlite3SelectPrep(&sParse, pSelect, 0);
104889105153
rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc);
104890105154
if( rc==SQLITE_OK ){
104891105155
sqlite3WalkSelect(&sWalker, pSelect);
104892105156
}
104893105157
if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
@@ -105000,10 +105264,11 @@
105000105264
*/
105001105265
static int renameTableSelectCb(Walker *pWalker, Select *pSelect){
105002105266
int i;
105003105267
RenameCtx *p = pWalker->u.pRename;
105004105268
SrcList *pSrc = pSelect->pSrc;
105269
+ if( pSelect->selFlags & SF_View ) return WRC_Prune;
105005105270
if( pSrc==0 ){
105006105271
assert( pWalker->pParse->db->mallocFailed );
105007105272
return WRC_Abort;
105008105273
}
105009105274
for(i=0; i<pSrc->nSrc; i++){
@@ -105070,26 +105335,32 @@
105070105335
sWalker.pParse = &sParse;
105071105336
sWalker.xExprCallback = renameTableExprCb;
105072105337
sWalker.xSelectCallback = renameTableSelectCb;
105073105338
sWalker.u.pRename = &sCtx;
105074105339
105075
- rc = renameParseSql(&sParse, zDb, 1, db, zInput, bTemp);
105340
+ rc = renameParseSql(&sParse, zDb, db, zInput, bTemp);
105076105341
105077105342
if( rc==SQLITE_OK ){
105078105343
int isLegacy = (db->flags & SQLITE_LegacyAlter);
105079105344
if( sParse.pNewTable ){
105080105345
Table *pTab = sParse.pNewTable;
105081105346
105082105347
if( pTab->pSelect ){
105083105348
if( isLegacy==0 ){
105349
+ Select *pSelect = pTab->pSelect;
105084105350
NameContext sNC;
105085105351
memset(&sNC, 0, sizeof(sNC));
105086105352
sNC.pParse = &sParse;
105087105353
105354
+ assert( pSelect->selFlags & SF_View );
105355
+ pSelect->selFlags &= ~SF_View;
105088105356
sqlite3SelectPrep(&sParse, pTab->pSelect, &sNC);
105089
- if( sParse.nErr ) rc = sParse.rc;
105090
- sqlite3WalkSelect(&sWalker, pTab->pSelect);
105357
+ if( sParse.nErr ){
105358
+ rc = sParse.rc;
105359
+ }else{
105360
+ sqlite3WalkSelect(&sWalker, pTab->pSelect);
105361
+ }
105091105362
}
105092105363
}else{
105093105364
/* Modify any FK definitions to point to the new table. */
105094105365
#ifndef SQLITE_OMIT_FOREIGN_KEY
105095105366
if( isLegacy==0 || (db->flags & SQLITE_ForeignKeys) ){
@@ -105206,11 +105477,11 @@
105206105477
105207105478
UNUSED_PARAMETER(NotUsed);
105208105479
if( zDb && zInput ){
105209105480
int rc;
105210105481
Parse sParse;
105211
- rc = renameParseSql(&sParse, zDb, 1, db, zInput, bTemp);
105482
+ rc = renameParseSql(&sParse, zDb, db, zInput, bTemp);
105212105483
if( rc==SQLITE_OK ){
105213105484
if( isLegacy==0 && sParse.pNewTable && sParse.pNewTable->pSelect ){
105214105485
NameContext sNC;
105215105486
memset(&sNC, 0, sizeof(sNC));
105216105487
sNC.pParse = &sParse;
@@ -108999,17 +109270,19 @@
108999109270
**
109000109271
** So, in other words, this routine shifts all the virtual columns to
109001109272
** the end.
109002109273
**
109003109274
** If SQLITE_OMIT_GENERATED_COLUMNS then there are no virtual columns and
109004
-** this routine is a no-op macro.
109275
+** this routine is a no-op macro. If the pTab does not have any virtual
109276
+** columns, then this routine is no-op that always return iCol. If iCol
109277
+** is negative (indicating the ROWID column) then this routine return iCol.
109005109278
*/
109006109279
SQLITE_PRIVATE i16 sqlite3TableColumnToStorage(Table *pTab, i16 iCol){
109007109280
int i;
109008109281
i16 n;
109009109282
assert( iCol<pTab->nCol );
109010
- if( (pTab->tabFlags & TF_HasVirtual)==0 ) return iCol;
109283
+ if( (pTab->tabFlags & TF_HasVirtual)==0 || iCol<0 ) return iCol;
109011109284
for(i=0, n=0; i<iCol; i++){
109012109285
if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ) n++;
109013109286
}
109014109287
if( pTab->aCol[i].colFlags & COLFLAG_VIRTUAL ){
109015109288
/* iCol is a virtual column itself */
@@ -109597,10 +109870,11 @@
109597109870
pTab->iPKey = iCol;
109598109871
pTab->keyConf = (u8)onError;
109599109872
assert( autoInc==0 || autoInc==1 );
109600109873
pTab->tabFlags |= autoInc*TF_Autoincrement;
109601109874
if( pList ) pParse->iPkSortOrder = pList->a[0].sortFlags;
109875
+ (void)sqlite3HasExplicitNulls(pParse, pList);
109602109876
}else if( autoInc ){
109603109877
#ifndef SQLITE_OMIT_AUTOINCREMENT
109604109878
sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
109605109879
"INTEGER PRIMARY KEY");
109606109880
#endif
@@ -109681,11 +109955,14 @@
109681109955
SQLITE_PRIVATE void sqlite3AddGenerated(Parse *pParse, Expr *pExpr, Token *pType){
109682109956
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
109683109957
u8 eType = COLFLAG_VIRTUAL;
109684109958
Table *pTab = pParse->pNewTable;
109685109959
Column *pCol;
109686
- if( NEVER(pTab==0) ) goto generated_done;
109960
+ if( pTab==0 ){
109961
+ /* generated column in an CREATE TABLE IF NOT EXISTS that already exists */
109962
+ goto generated_done;
109963
+ }
109687109964
pCol = &(pTab->aCol[pTab->nCol-1]);
109688109965
if( IN_DECLARE_VTAB ){
109689109966
sqlite3ErrorMsg(pParse, "virtual tables cannot use computed columns");
109690109967
goto generated_done;
109691109968
}
@@ -110289,10 +110566,16 @@
110289110566
#ifndef SQLITE_OMIT_CHECK
110290110567
/* Resolve names in all CHECK constraint expressions.
110291110568
*/
110292110569
if( p->pCheck ){
110293110570
sqlite3ResolveSelfReference(pParse, p, NC_IsCheck, 0, p->pCheck);
110571
+ if( pParse->nErr ){
110572
+ /* If errors are seen, delete the CHECK constraints now, else they might
110573
+ ** actually be used if PRAGMA writable_schema=ON is set. */
110574
+ sqlite3ExprListDelete(db, p->pCheck);
110575
+ p->pCheck = 0;
110576
+ }
110294110577
}
110295110578
#endif /* !defined(SQLITE_OMIT_CHECK) */
110296110579
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
110297110580
if( p->tabFlags & TF_HasGenerated ){
110298110581
int ii, nNG = 0;
@@ -110299,14 +110582,23 @@
110299110582
testcase( p->tabFlags & TF_HasVirtual );
110300110583
testcase( p->tabFlags & TF_HasStored );
110301110584
for(ii=0; ii<p->nCol; ii++){
110302110585
u32 colFlags = p->aCol[ii].colFlags;
110303110586
if( (colFlags & COLFLAG_GENERATED)!=0 ){
110587
+ Expr *pX = p->aCol[ii].pDflt;
110304110588
testcase( colFlags & COLFLAG_VIRTUAL );
110305110589
testcase( colFlags & COLFLAG_STORED );
110306
- sqlite3ResolveSelfReference(pParse, p, NC_GenCol,
110307
- p->aCol[ii].pDflt, 0);
110590
+ if( sqlite3ResolveSelfReference(pParse, p, NC_GenCol, pX, 0) ){
110591
+ /* If there are errors in resolving the expression, change the
110592
+ ** expression to a NULL. This prevents code generators that operate
110593
+ ** on the expression from inserting extra parts into the expression
110594
+ ** tree that have been allocated from lookaside memory, which is
110595
+ ** illegal in a schema and will lead to errors heap corruption when
110596
+ ** the database connection closes. */
110597
+ sqlite3ExprDelete(db, pX);
110598
+ p->aCol[ii].pDflt = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
110599
+ }
110308110600
}else{
110309110601
nNG++;
110310110602
}
110311110603
}
110312110604
if( nNG==0 ){
@@ -110532,10 +110824,11 @@
110532110824
/* Make a copy of the entire SELECT statement that defines the view.
110533110825
** This will force all the Expr.token.z values to be dynamically
110534110826
** allocated rather than point to the input string - which means that
110535110827
** they will persist after the current sqlite3_exec() call returns.
110536110828
*/
110829
+ pSelect->selFlags |= SF_View;
110537110830
if( IN_RENAME_OBJECT ){
110538110831
p->pSelect = pSelect;
110539110832
pSelect = 0;
110540110833
}else{
110541110834
p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
@@ -111958,30 +112251,13 @@
111958112251
}
111959112252
111960112253
sqlite3VdbeJumpHere(v, pIndex->tnum);
111961112254
}
111962112255
}
111963
-
111964
- /* When adding an index to the list of indices for a table, make
111965
- ** sure all indices labeled OE_Replace come after all those labeled
111966
- ** OE_Ignore. This is necessary for the correct constraint check
111967
- ** processing (in sqlite3GenerateConstraintChecks()) as part of
111968
- ** UPDATE and INSERT statements.
111969
- */
111970112256
if( db->init.busy || pTblName==0 ){
111971
- if( onError!=OE_Replace || pTab->pIndex==0
111972
- || pTab->pIndex->onError==OE_Replace){
111973
- pIndex->pNext = pTab->pIndex;
111974
- pTab->pIndex = pIndex;
111975
- }else{
111976
- Index *pOther = pTab->pIndex;
111977
- while( pOther->pNext && pOther->pNext->onError!=OE_Replace ){
111978
- pOther = pOther->pNext;
111979
- }
111980
- pIndex->pNext = pOther->pNext;
111981
- pOther->pNext = pIndex;
111982
- }
112257
+ pIndex->pNext = pTab->pIndex;
112258
+ pTab->pIndex = pIndex;
111983112259
pIndex = 0;
111984112260
}
111985112261
else if( IN_RENAME_OBJECT ){
111986112262
assert( pParse->pNewIndex==0 );
111987112263
pParse->pNewIndex = pIndex;
@@ -111989,10 +112265,25 @@
111989112265
}
111990112266
111991112267
/* Clean up before exiting */
111992112268
exit_create_index:
111993112269
if( pIndex ) sqlite3FreeIndex(db, pIndex);
112270
+ if( pTab ){ /* Ensure all REPLACE indexes are at the end of the list */
112271
+ Index **ppFrom = &pTab->pIndex;
112272
+ Index *pThis;
112273
+ for(ppFrom=&pTab->pIndex; (pThis = *ppFrom)!=0; ppFrom=&pThis->pNext){
112274
+ Index *pNext;
112275
+ if( pThis->onError!=OE_Replace ) continue;
112276
+ while( (pNext = pThis->pNext)!=0 && pNext->onError!=OE_Replace ){
112277
+ *ppFrom = pNext;
112278
+ pThis->pNext = pNext->pNext;
112279
+ pNext->pNext = pThis;
112280
+ ppFrom = &pNext->pNext;
112281
+ }
112282
+ break;
112283
+ }
112284
+ }
111994112285
sqlite3ExprDelete(db, pPIWhere);
111995112286
sqlite3ExprListDelete(db, pList);
111996112287
sqlite3SrcListDelete(db, pTblName);
111997112288
sqlite3DbFree(db, zName);
111998112289
}
@@ -118231,14 +118522,15 @@
118231118522
}
118232118523
return 0;
118233118524
}
118234118525
118235118526
/* This walker callback will compute the union of colFlags flags for all
118236
-** references columns in a CHECK constraint or generated column expression.
118527
+** referenced columns in a CHECK constraint or generated column expression.
118237118528
*/
118238118529
static int exprColumnFlagUnion(Walker *pWalker, Expr *pExpr){
118239
- if( pExpr->op==TK_COLUMN ){
118530
+ if( pExpr->op==TK_COLUMN && pExpr->iColumn>=0 ){
118531
+ assert( pExpr->iColumn < pWalker->u.pTab->nCol );
118240118532
pWalker->eCode |= pWalker->u.pTab->aCol[pExpr->iColumn].colFlags;
118241118533
}
118242118534
return WRC_Continue;
118243118535
}
118244118536
@@ -118257,10 +118549,40 @@
118257118549
){
118258118550
int i;
118259118551
Walker w;
118260118552
Column *pRedo;
118261118553
int eProgress;
118554
+ VdbeOp *pOp;
118555
+
118556
+ assert( pTab->tabFlags & TF_HasGenerated );
118557
+ testcase( pTab->tabFlags & TF_HasVirtual );
118558
+ testcase( pTab->tabFlags & TF_HasStored );
118559
+
118560
+ /* Before computing generated columns, first go through and make sure
118561
+ ** that appropriate affinity has been applied to the regular columns
118562
+ */
118563
+ sqlite3TableAffinity(pParse->pVdbe, pTab, iRegStore);
118564
+ if( (pTab->tabFlags & TF_HasStored)!=0
118565
+ && (pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1))->opcode==OP_Affinity
118566
+ ){
118567
+ /* Change the OP_Affinity argument to '@' (NONE) for all stored
118568
+ ** columns. '@' is the no-op affinity and those columns have not
118569
+ ** yet been computed. */
118570
+ int ii, jj;
118571
+ char *zP4 = pOp->p4.z;
118572
+ assert( zP4!=0 );
118573
+ assert( pOp->p4type==P4_DYNAMIC );
118574
+ for(ii=jj=0; zP4[jj]; ii++){
118575
+ if( pTab->aCol[ii].colFlags & COLFLAG_VIRTUAL ){
118576
+ continue;
118577
+ }
118578
+ if( pTab->aCol[ii].colFlags & COLFLAG_STORED ){
118579
+ zP4[jj] = SQLITE_AFF_NONE;
118580
+ }
118581
+ jj++;
118582
+ }
118583
+ }
118262118584
118263118585
/* Because there can be multiple generated columns that refer to one another,
118264118586
** this is a two-pass algorithm. On the first pass, mark all generated
118265118587
** columns as "not available".
118266118588
*/
@@ -118977,10 +119299,14 @@
118977119299
if( IsVirtual(pTab) ){
118978119300
sqlite3ErrorMsg(pParse, "UPSERT not implemented for virtual table \"%s\"",
118979119301
pTab->zName);
118980119302
goto insert_cleanup;
118981119303
}
119304
+ if( pTab->pSelect ){
119305
+ sqlite3ErrorMsg(pParse, "cannot UPSERT a view");
119306
+ goto insert_cleanup;
119307
+ }
118982119308
if( sqlite3HasExplicitNulls(pParse, pUpsert->pUpsertTarget) ){
118983119309
goto insert_cleanup;
118984119310
}
118985119311
pTabList->a[0].iCursor = iDataCur;
118986119312
pUpsert->pUpsertSrc = pTabList;
@@ -119211,14 +119537,12 @@
119211119537
119212119538
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
119213119539
/* Compute the new value for generated columns after all other
119214119540
** columns have already been computed. This must be done after
119215119541
** computing the ROWID in case one of the generated columns
119216
- ** refers to the ROWID. */
119542
+ ** is derived from the INTEGER PRIMARY KEY. */
119217119543
if( pTab->tabFlags & TF_HasGenerated ){
119218
- testcase( pTab->tabFlags & TF_HasVirtual );
119219
- testcase( pTab->tabFlags & TF_HasStored );
119220119544
sqlite3ComputeGeneratedColumns(pParse, regRowid+1, pTab);
119221119545
}
119222119546
#endif
119223119547
119224119548
/* Generate code to check constraints and generate index keys and
@@ -120246,10 +120570,14 @@
120246120570
120247120571
v = sqlite3GetVdbe(pParse);
120248120572
assert( v!=0 );
120249120573
assert( pTab->pSelect==0 ); /* This table is not a VIEW */
120250120574
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
120575
+ /* All REPLACE indexes are at the end of the list */
120576
+ assert( pIdx->onError!=OE_Replace
120577
+ || pIdx->pNext==0
120578
+ || pIdx->pNext->onError==OE_Replace );
120251120579
if( aRegIdx[i]==0 ) continue;
120252120580
if( pIdx->pPartIdxWhere ){
120253120581
sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
120254120582
VdbeCoverage(v);
120255120583
}
@@ -124713,11 +125041,13 @@
124713125041
char *zErr;
124714125042
int jmp2;
124715125043
if( j==pTab->iPKey ) continue;
124716125044
if( pTab->aCol[j].notNull==0 ) continue;
124717125045
sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3);
124718
- sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
125046
+ if( sqlite3VdbeGetOp(v,-1)->opcode==OP_Column ){
125047
+ sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
125048
+ }
124719125049
jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
124720125050
zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
124721125051
pTab->aCol[j].zName);
124722125052
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
124723125053
integrityCheckResultRow(v);
@@ -126679,11 +127009,14 @@
126679127009
};
126680127010
#define SORTFLAG_UseSorter 0x01 /* Use SorterOpen instead of OpenEphemeral */
126681127011
126682127012
/*
126683127013
** Delete all the content of a Select structure. Deallocate the structure
126684
-** itself only if bFree is true.
127014
+** itself depending on the value of bFree
127015
+**
127016
+** If bFree==1, call sqlite3DbFree() on the p object.
127017
+** If bFree==0, Leave the first Select object unfreed
126685127018
*/
126686127019
static void clearSelect(sqlite3 *db, Select *p, int bFree){
126687127020
while( p ){
126688127021
Select *pPrior = p->pPrior;
126689127022
sqlite3ExprListDelete(db, p->pEList);
@@ -126782,10 +127115,24 @@
126782127115
** Delete the given Select structure and all of its substructures.
126783127116
*/
126784127117
SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
126785127118
if( OK_IF_ALWAYS_TRUE(p) ) clearSelect(db, p, 1);
126786127119
}
127120
+
127121
+/*
127122
+** Delete all the substructure for p, but keep p allocated. Redefine
127123
+** p to be a single SELECT where every column of the result set has a
127124
+** value of NULL.
127125
+*/
127126
+SQLITE_PRIVATE void sqlite3SelectReset(Parse *pParse, Select *p){
127127
+ if( ALWAYS(p) ){
127128
+ clearSelect(pParse->db, p, 0);
127129
+ memset(&p->iLimit, 0, sizeof(Select) - offsetof(Select,iLimit));
127130
+ p->pEList = sqlite3ExprListAppend(pParse, 0,
127131
+ sqlite3ExprAlloc(pParse->db,TK_NULL,0,0));
127132
+ }
127133
+}
126787127134
126788127135
/*
126789127136
** Return a pointer to the right-most SELECT statement in a compound.
126790127137
*/
126791127138
static Select *findRightmost(Select *p){
@@ -129069,10 +129416,11 @@
129069129416
assert( p->selFlags & SF_MultiValue );
129070129417
do{
129071129418
assert( p->selFlags & SF_Values );
129072129419
assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
129073129420
assert( p->pNext==0 || p->pEList->nExpr==p->pNext->pEList->nExpr );
129421
+ if( p->pWin ) return -1;
129074129422
if( p->pPrior==0 ) break;
129075129423
assert( p->pPrior->pNext==p );
129076129424
p = p->pPrior;
129077129425
nRow += bShowAll;
129078129426
}while(1);
@@ -129159,11 +129507,12 @@
129159129507
129160129508
/* Special handling for a compound-select that originates as a VALUES clause.
129161129509
*/
129162129510
if( p->selFlags & SF_MultiValue ){
129163129511
rc = multiSelectValues(pParse, p, &dest);
129164
- goto multi_select_end;
129512
+ if( rc>=0 ) goto multi_select_end;
129513
+ rc = SQLITE_OK;
129165129514
}
129166129515
129167129516
/* Make sure all SELECTs in the statement have the same number of elements
129168129517
** in their result sets.
129169129518
*/
@@ -129304,13 +129653,13 @@
129304129653
129305129654
/* Convert the data in the temporary table into whatever form
129306129655
** it is that we currently need.
129307129656
*/
129308129657
assert( unionTab==dest.iSDParm || dest.eDest!=priorOp );
129309
- if( dest.eDest!=priorOp ){
129658
+ assert( p->pEList || db->mallocFailed );
129659
+ if( dest.eDest!=priorOp && db->mallocFailed==0 ){
129310129660
int iCont, iBreak, iStart;
129311
- assert( p->pEList );
129312129661
iBreak = sqlite3VdbeMakeLabel(pParse);
129313129662
iCont = sqlite3VdbeMakeLabel(pParse);
129314129663
computeLimitRegisters(pParse, p, iBreak);
129315129664
sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
129316129665
iStart = sqlite3VdbeCurrentAddr(v);
@@ -129402,10 +129751,11 @@
129402129751
if( p->pNext==0 ){
129403129752
ExplainQueryPlanPop(pParse);
129404129753
}
129405129754
#endif
129406129755
}
129756
+ if( pParse->nErr ) goto multi_select_end;
129407129757
129408129758
/* Compute collating sequences used by
129409129759
** temporary tables needed to implement the compound select.
129410129760
** Attach the KeyInfo structure to all temporary tables.
129411129761
**
@@ -130193,10 +130543,11 @@
130193130543
** (3) If the subquery is the right operand of a LEFT JOIN then
130194130544
** (3a) the subquery may not be a join and
130195130545
** (3b) the FROM clause of the subquery may not contain a virtual
130196130546
** table and
130197130547
** (3c) the outer query may not be an aggregate.
130548
+** (3d) the outer query may not be DISTINCT.
130198130549
**
130199130550
** (4) The subquery can not be DISTINCT.
130200130551
**
130201130552
** (**) At one point restrictions (4) and (5) defined a subset of DISTINCT
130202130553
** sub-queries that were excluded from this optimization. Restriction
@@ -130389,12 +130740,15 @@
130389130740
**
130390130741
** See also tickets #306, #350, and #3300.
130391130742
*/
130392130743
if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
130393130744
isLeftJoin = 1;
130394
- if( pSubSrc->nSrc>1 || isAgg || IsVirtual(pSubSrc->a[0].pTab) ){
130395
- /* (3a) (3c) (3b) */
130745
+ if( pSubSrc->nSrc>1 /* (3a) */
130746
+ || isAgg /* (3b) */
130747
+ || IsVirtual(pSubSrc->a[0].pTab) /* (3c) */
130748
+ || (p->selFlags & SF_Distinct)!=0 /* (3d) */
130749
+ ){
130396130750
return 0;
130397130751
}
130398130752
}
130399130753
#ifdef SQLITE_EXTRA_IFNULLROW
130400130754
else if( iFrom>0 && !isAgg ){
@@ -131164,10 +131518,13 @@
131164131518
pNew->pHaving = 0;
131165131519
pNew->pOrderBy = 0;
131166131520
p->pPrior = 0;
131167131521
p->pNext = 0;
131168131522
p->pWith = 0;
131523
+#ifndef SQLITE_OMIT_WINDOWFUNC
131524
+ p->pWinDefn = 0;
131525
+#endif
131169131526
p->selFlags &= ~SF_Compound;
131170131527
assert( (p->selFlags & SF_Converted)==0 );
131171131528
p->selFlags |= SF_Converted;
131172131529
assert( pNew->pPrior!=0 );
131173131530
pNew->pPrior->pNext = pNew;
@@ -132323,11 +132680,13 @@
132323132680
if( pDest->eDest==SRT_Output ){
132324132681
generateColumnNames(pParse, p);
132325132682
}
132326132683
132327132684
#ifndef SQLITE_OMIT_WINDOWFUNC
132328
- if( sqlite3WindowRewrite(pParse, p) ){
132685
+ rc = sqlite3WindowRewrite(pParse, p);
132686
+ if( rc ){
132687
+ assert( db->mallocFailed || pParse->nErr>0 );
132329132688
goto select_end;
132330132689
}
132331132690
#if SELECTTRACE_ENABLED
132332132691
if( p->pWin && (sqlite3SelectTrace & 0x108)!=0 ){
132333132692
SELECTTRACE(0x104,pParse,p, ("after window rewrite:\n"));
@@ -132659,10 +133018,11 @@
132659133018
** written the query must use a temp-table for at least one of the ORDER
132660133019
** BY and DISTINCT, and an index or separate temp-table for the other.
132661133020
*/
132662133021
if( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct
132663133022
&& sqlite3ExprListCompare(sSort.pOrderBy, pEList, -1)==0
133023
+ && p->pWin==0
132664133024
){
132665133025
p->selFlags &= ~SF_Distinct;
132666133026
pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
132667133027
/* Notice that even thought SF_Distinct has been cleared from p->selFlags,
132668133028
** the sDistinct.isTnct is still set. Hence, isTnct represents the
@@ -134182,12 +134542,16 @@
134182134542
if( ALWAYS(pTrigger) ){
134183134543
if( pTrigger->pSchema==pTrigger->pTabSchema ){
134184134544
Table *pTab = tableOfTrigger(pTrigger);
134185134545
if( pTab ){
134186134546
Trigger **pp;
134187
- for(pp=&pTab->pTrigger; *pp!=pTrigger; pp=&((*pp)->pNext));
134188
- *pp = (*pp)->pNext;
134547
+ for(pp=&pTab->pTrigger; *pp; pp=&((*pp)->pNext)){
134548
+ if( *pp==pTrigger ){
134549
+ *pp = (*pp)->pNext;
134550
+ break;
134551
+ }
134552
+ }
134189134553
}
134190134554
}
134191134555
sqlite3DeleteTrigger(db, pTrigger);
134192134556
db->mDbFlags |= DBFLAG_SchemaChange;
134193134557
}
@@ -136913,10 +137277,12 @@
136913137277
char *zStmt;
136914137278
char *zWhere;
136915137279
int iDb;
136916137280
int iReg;
136917137281
Vdbe *v;
137282
+
137283
+ sqlite3MayAbort(pParse);
136918137284
136919137285
/* Compute the complete text of the CREATE VIRTUAL TABLE statement */
136920137286
if( pEnd ){
136921137287
pParse->sNameToken.n = (int)(pEnd->z - pParse->sNameToken.z) + pEnd->n;
136922137288
}
@@ -136939,17 +137305,17 @@
136939137305
pTab->zName,
136940137306
pTab->zName,
136941137307
zStmt,
136942137308
pParse->regRowid
136943137309
);
136944
- sqlite3DbFree(db, zStmt);
136945137310
v = sqlite3GetVdbe(pParse);
136946137311
sqlite3ChangeCookie(pParse, iDb);
136947137312
136948137313
sqlite3VdbeAddOp0(v, OP_Expire);
136949
- zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
137314
+ zWhere = sqlite3MPrintf(db, "name=%Q AND sql=%Q", pTab->zName, zStmt);
136950137315
sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere);
137316
+ sqlite3DbFree(db, zStmt);
136951137317
136952137318
iReg = ++pParse->nMem;
136953137319
sqlite3VdbeLoadString(v, iReg, pTab->zName);
136954137320
sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg);
136955137321
}
@@ -137347,11 +137713,12 @@
137347137713
return SQLITE_LOCKED;
137348137714
}
137349137715
}
137350137716
p = vtabDisconnectAll(db, pTab);
137351137717
xDestroy = p->pMod->pModule->xDestroy;
137352
- assert( xDestroy!=0 ); /* Checked before the virtual table is created */
137718
+ if( xDestroy==0 ) xDestroy = p->pMod->pModule->xDisconnect;
137719
+ assert( xDestroy!=0 );
137353137720
pTab->nTabRef++;
137354137721
rc = xDestroy(p->pVtab);
137355137722
/* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */
137356137723
if( rc==SQLITE_OK ){
137357137724
assert( pTab->pVTable==p && p->pNext==0 );
@@ -138776,11 +139143,12 @@
138776139143
int iEq, /* Look at loop terms starting here */
138777139144
WhereLoop *pLoop, /* The current loop */
138778139145
Expr *pX /* The IN expression to be reduced */
138779139146
){
138780139147
sqlite3 *db = pParse->db;
138781
- Expr *pNew = sqlite3ExprDup(db, pX, 0);
139148
+ Expr *pNew;
139149
+ pNew = sqlite3ExprDup(db, pX, 0);
138782139150
if( db->mallocFailed==0 ){
138783139151
ExprList *pOrigRhs = pNew->x.pSelect->pEList; /* Original unmodified RHS */
138784139152
ExprList *pOrigLhs = pNew->pLeft->x.pList; /* Original unmodified LHS */
138785139153
ExprList *pRhs = 0; /* New RHS after modifications */
138786139154
ExprList *pLhs = 0; /* New LHS after mods */
@@ -139488,10 +139856,13 @@
139488139856
pExpr->affExpr = sqlite3ExprAffinity(pExpr);
139489139857
pExpr->op = TK_COLUMN;
139490139858
pExpr->iTable = pX->iIdxCur;
139491139859
pExpr->iColumn = pX->iIdxCol;
139492139860
pExpr->y.pTab = 0;
139861
+ testcase( ExprHasProperty(pExpr, EP_Skip) );
139862
+ testcase( ExprHasProperty(pExpr, EP_Unlikely) );
139863
+ ExprClearProperty(pExpr, EP_Skip|EP_Unlikely);
139493139864
return WRC_Prune;
139494139865
}else{
139495139866
return WRC_Continue;
139496139867
}
139497139868
}
@@ -139502,10 +139873,12 @@
139502139873
*/
139503139874
static int whereIndexExprTransColumn(Walker *p, Expr *pExpr){
139504139875
if( pExpr->op==TK_COLUMN ){
139505139876
IdxExprTrans *pX = p->u.pIdxTrans;
139506139877
if( pExpr->iTable==pX->iTabCur && pExpr->iColumn==pX->iTabCol ){
139878
+ assert( pExpr->y.pTab!=0 );
139879
+ pExpr->affExpr = sqlite3TableColumnAffinity(pExpr->y.pTab,pExpr->iColumn);
139507139880
pExpr->iTable = pX->iIdxCur;
139508139881
pExpr->iColumn = pX->iIdxCol;
139509139882
pExpr->y.pTab = 0;
139510139883
}
139511139884
}
@@ -139547,13 +139920,24 @@
139547139920
for(iIdxCol=0; iIdxCol<pIdx->nColumn; iIdxCol++){
139548139921
i16 iRef = pIdx->aiColumn[iIdxCol];
139549139922
if( iRef==XN_EXPR ){
139550139923
assert( aColExpr->a[iIdxCol].pExpr!=0 );
139551139924
x.pIdxExpr = aColExpr->a[iIdxCol].pExpr;
139925
+ if( sqlite3ExprIsConstant(x.pIdxExpr) ) continue;
139552139926
w.xExprCallback = whereIndexExprTransNode;
139553139927
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
139554
- }else if( iRef>=0 && (pTab->aCol[iRef].colFlags & COLFLAG_VIRTUAL)!=0 ){
139928
+ }else if( iRef>=0
139929
+ && (pTab->aCol[iRef].colFlags & COLFLAG_VIRTUAL)!=0
139930
+ && (pTab->aCol[iRef].zColl==0
139931
+ || sqlite3StrICmp(pTab->aCol[iRef].zColl, sqlite3StrBINARY)==0)
139932
+ ){
139933
+ /* Check to see if there are direct references to generated columns
139934
+ ** that are contained in the index. Pulling the generated column
139935
+ ** out of the index is an optimization only - the main table is always
139936
+ ** available if the index cannot be used. To avoid unnecessary
139937
+ ** complication, omit this optimization if the collating sequence for
139938
+ ** the column is non-standard */
139555139939
x.iTabCol = iRef;
139556139940
w.xExprCallback = whereIndexExprTransColumn;
139557139941
#endif /* SQLITE_OMIT_GENERATED_COLUMNS */
139558139942
}else{
139559139943
continue;
@@ -140213,14 +140597,14 @@
140213140597
omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
140214140598
&& (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0;
140215140599
if( omitTable ){
140216140600
/* pIdx is a covering index. No need to access the main table. */
140217140601
}else if( HasRowid(pIdx->pTable) ){
140218
- if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE) || (
140219
- (pWInfo->wctrlFlags & WHERE_SEEK_UNIQ_TABLE)
140220
- && (pWInfo->eOnePass==ONEPASS_SINGLE)
140221
- )){
140602
+ if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE)
140603
+ || ( (pWInfo->wctrlFlags & WHERE_SEEK_UNIQ_TABLE)!=0
140604
+ && (pWInfo->eOnePass==ONEPASS_SINGLE || pLoop->nLTerm==0) )
140605
+ ){
140222140606
iRowidReg = ++pParse->nMem;
140223140607
sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
140224140608
sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg);
140225140609
VdbeCoverage(v);
140226140610
}else{
@@ -142055,10 +142439,11 @@
142055142439
Expr *pNewExpr;
142056142440
pNewExpr = sqlite3PExpr(pParse, TK_MATCH,
142057142441
0, sqlite3ExprDup(db, pRight, 0));
142058142442
if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){
142059142443
ExprSetProperty(pNewExpr, EP_FromJoin);
142444
+ pNewExpr->iRightJoinTable = pExpr->iRightJoinTable;
142060142445
}
142061142446
idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
142062142447
testcase( idxNew==0 );
142063142448
pNewTerm = &pWC->a[idxNew];
142064142449
pNewTerm->prereqRight = prereqExpr;
@@ -142111,15 +142496,19 @@
142111142496
** a virtual term for each vector component. The expression object
142112142497
** used by each such virtual term is pExpr (the full vector IN(...)
142113142498
** expression). The WhereTerm.iField variable identifies the index within
142114142499
** the vector on the LHS that the virtual term represents.
142115142500
**
142116
- ** This only works if the RHS is a simple SELECT, not a compound
142501
+ ** This only works if the RHS is a simple SELECT (not a compound) that does
142502
+ ** not use window functions.
142117142503
*/
142118142504
if( pWC->op==TK_AND && pExpr->op==TK_IN && pTerm->iField==0
142119142505
&& pExpr->pLeft->op==TK_VECTOR
142120142506
&& pExpr->x.pSelect->pPrior==0
142507
+#ifndef SQLITE_OMIT_WINDOWFUNC
142508
+ && pExpr->x.pSelect->pWin==0
142509
+#endif
142121142510
){
142122142511
int i;
142123142512
for(i=0; i<sqlite3ExprVectorSize(pExpr->pLeft); i++){
142124142513
int idxNew;
142125142514
idxNew = whereClauseInsert(pWC, pExpr, TERM_VIRTUAL);
@@ -142273,13 +142662,14 @@
142273142662
mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
142274142663
}else if( p->x.pList ){
142275142664
mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
142276142665
}
142277142666
#ifndef SQLITE_OMIT_WINDOWFUNC
142278
- if( p->op==TK_FUNCTION && p->y.pWin ){
142667
+ if( (p->op==TK_FUNCTION || p->op==TK_AGG_FUNCTION) && p->y.pWin ){
142279142668
mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition);
142280142669
mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy);
142670
+ mask |= sqlite3WhereExprUsage(pMaskSet, p->y.pWin->pFilter);
142281142671
}
142282142672
#endif
142283142673
return mask;
142284142674
}
142285142675
SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
@@ -143163,11 +143553,12 @@
143163143553
if( (idxCols & cMask)==0 ){
143164143554
Expr *pX = pTerm->pExpr;
143165143555
idxCols |= cMask;
143166143556
pIdx->aiColumn[n] = pTerm->u.leftColumn;
143167143557
pColl = sqlite3ExprCompareCollSeq(pParse, pX);
143168
- pIdx->azColl[n] = ALWAYS(pColl) ? pColl->zName : sqlite3StrBINARY;
143558
+ assert( pColl!=0 || pParse->nErr>0 ); /* TH3 collate01.800 */
143559
+ pIdx->azColl[n] = pColl ? pColl->zName : sqlite3StrBINARY;
143169143560
n++;
143170143561
}
143171143562
}
143172143563
}
143173143564
assert( (u32)n==pLoop->u.btree.nEq );
@@ -143341,22 +143732,17 @@
143341143732
testcase( pTerm->eOperator & WO_IS );
143342143733
testcase( pTerm->eOperator & WO_ISNULL );
143343143734
testcase( pTerm->eOperator & WO_ALL );
143344143735
if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
143345143736
if( pTerm->wtFlags & TERM_VNULL ) continue;
143737
+
143738
+ /* tag-20191211-002: WHERE-clause constraints are not useful to the
143739
+ ** right-hand table of a LEFT JOIN. See tag-20191211-001 for the
143740
+ ** equivalent restriction for ordinary tables. */
143346143741
if( (pSrc->fg.jointype & JT_LEFT)!=0
143347143742
&& !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
143348
- && (pTerm->eOperator & (WO_IS|WO_ISNULL))
143349143743
){
143350
- /* An "IS" term in the WHERE clause where the virtual table is the rhs
143351
- ** of a LEFT JOIN. Do not pass this term to the virtual table
143352
- ** implementation, as this can lead to incorrect results from SQL such
143353
- ** as:
143354
- **
143355
- ** "LEFT JOIN vtab WHERE vtab.col IS NULL" */
143356
- testcase( pTerm->eOperator & WO_ISNULL );
143357
- testcase( pTerm->eOperator & WO_IS );
143358143744
continue;
143359143745
}
143360143746
assert( pTerm->u.leftColumn>=(-1) );
143361143747
pIdxCons[j].iColumn = pTerm->u.leftColumn;
143362143748
pIdxCons[j].iTermOffset = i;
@@ -143383,11 +143769,12 @@
143383143769
assert( pTerm->eOperator&(WO_IN|WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_AUX) );
143384143770
143385143771
if( op & (WO_LT|WO_LE|WO_GT|WO_GE)
143386143772
&& sqlite3ExprIsVector(pTerm->pExpr->pRight)
143387143773
){
143388
- if( i<16 ) mNoOmit |= (1 << i);
143774
+ testcase( j!=i );
143775
+ if( j<16 ) mNoOmit |= (1 << j);
143389143776
if( op==WO_LT ) pIdxCons[j].op = WO_LE;
143390143777
if( op==WO_GT ) pIdxCons[j].op = WO_GE;
143391143778
}
143392143779
}
143393143780
@@ -144128,14 +144515,16 @@
144128144515
sqlite3DebugPrintf(
144129144516
"TERM-%-3d %p %s %-12s prob=%-3d op=0x%03x wtFlags=0x%04x",
144130144517
iTerm, pTerm, zType, zLeft, pTerm->truthProb,
144131144518
pTerm->eOperator, pTerm->wtFlags);
144132144519
if( pTerm->iField ){
144133
- sqlite3DebugPrintf(" iField=%d\n", pTerm->iField);
144134
- }else{
144135
- sqlite3DebugPrintf("\n");
144520
+ sqlite3DebugPrintf(" iField=%d", pTerm->iField);
144136144521
}
144522
+ if( pTerm->iParent>=0 ){
144523
+ sqlite3DebugPrintf(" iParent=%d", pTerm->iParent);
144524
+ }
144525
+ sqlite3DebugPrintf("\n");
144137144526
sqlite3TreeViewExpr(0, pTerm->pExpr, 0);
144138144527
}
144139144528
}
144140144529
#endif
144141144530
@@ -144178,11 +144567,11 @@
144178144567
sqlite3DebugPrintf("%20s","");
144179144568
}
144180144569
}else{
144181144570
char *z;
144182144571
if( p->u.vtab.idxStr ){
144183
- z = sqlite3_mprintf("(%d,\"%s\",%x)",
144572
+ z = sqlite3_mprintf("(%d,\"%s\",%#x)",
144184144573
p->u.vtab.idxNum, p->u.vtab.idxStr, p->u.vtab.omitMask);
144185144574
}else{
144186144575
z = sqlite3_mprintf("(%d,%x)", p->u.vtab.idxNum, p->u.vtab.omitMask);
144187144576
}
144188144577
sqlite3DebugPrintf(" %-19s", z);
@@ -144833,13 +145222,13 @@
144833145222
144834145223
/* Do not allow the upper bound of a LIKE optimization range constraint
144835145224
** to mix with a lower range bound from some other source */
144836145225
if( pTerm->wtFlags & TERM_LIKEOPT && pTerm->eOperator==WO_LT ) continue;
144837145226
144838
- /* Do not allow constraints from the WHERE clause to be used by the
144839
- ** right table of a LEFT JOIN. Only constraints in the ON clause are
144840
- ** allowed */
145227
+ /* tag-20191211-001: Do not allow constraints from the WHERE clause to
145228
+ ** be used by the right table of a LEFT JOIN. Only constraints in the
145229
+ ** ON clause are allowed. See tag-20191211-002 for the vtab equivalent. */
144841145230
if( (pSrc->fg.jointype & JT_LEFT)!=0
144842145231
&& !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
144843145232
){
144844145233
continue;
144845145234
}
@@ -145152,23 +145541,29 @@
145152145541
}
145153145542
145154145543
/* Check to see if a partial index with pPartIndexWhere can be used
145155145544
** in the current query. Return true if it can be and false if not.
145156145545
*/
145157
-static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){
145546
+static int whereUsablePartialIndex(
145547
+ int iTab, /* The table for which we want an index */
145548
+ int isLeft, /* True if iTab is the right table of a LEFT JOIN */
145549
+ WhereClause *pWC, /* The WHERE clause of the query */
145550
+ Expr *pWhere /* The WHERE clause from the partial index */
145551
+){
145158145552
int i;
145159145553
WhereTerm *pTerm;
145160145554
Parse *pParse = pWC->pWInfo->pParse;
145161145555
while( pWhere->op==TK_AND ){
145162
- if( !whereUsablePartialIndex(iTab,pWC,pWhere->pLeft) ) return 0;
145556
+ if( !whereUsablePartialIndex(iTab,isLeft,pWC,pWhere->pLeft) ) return 0;
145163145557
pWhere = pWhere->pRight;
145164145558
}
145165145559
if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0;
145166145560
for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
145167145561
Expr *pExpr;
145168145562
pExpr = pTerm->pExpr;
145169145563
if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab)
145564
+ && (isLeft==0 || ExprHasProperty(pExpr, EP_FromJoin))
145170145565
&& sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)
145171145566
){
145172145567
return 1;
145173145568
}
145174145569
}
@@ -145327,12 +145722,15 @@
145327145722
/* Loop over all indices. If there was an INDEXED BY clause, then only
145328145723
** consider index pProbe. */
145329145724
for(; rc==SQLITE_OK && pProbe;
145330145725
pProbe=(pSrc->pIBIndex ? 0 : pProbe->pNext), iSortIdx++
145331145726
){
145727
+ int isLeft = (pSrc->fg.jointype & JT_OUTER)!=0;
145332145728
if( pProbe->pPartIdxWhere!=0
145333
- && !whereUsablePartialIndex(pSrc->iCursor, pWC, pProbe->pPartIdxWhere) ){
145729
+ && !whereUsablePartialIndex(pSrc->iCursor, isLeft, pWC,
145730
+ pProbe->pPartIdxWhere)
145731
+ ){
145334145732
testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */
145335145733
continue; /* Partial index inappropriate for this query */
145336145734
}
145337145735
if( pProbe->bNoQuery ) continue;
145338145736
rSize = pProbe->aiRowLogEst[0];
@@ -145555,11 +145953,18 @@
145555145953
assert( iTerm<pNew->nLSlot );
145556145954
pNew->aLTerm[iTerm] = pTerm;
145557145955
if( iTerm>mxTerm ) mxTerm = iTerm;
145558145956
testcase( iTerm==15 );
145559145957
testcase( iTerm==16 );
145560
- if( iTerm<16 && pUsage[i].omit ) pNew->u.vtab.omitMask |= 1<<iTerm;
145958
+ if( pUsage[i].omit ){
145959
+ if( i<16 && ((1<<i)&mNoOmit)==0 ){
145960
+ testcase( i!=iTerm );
145961
+ pNew->u.vtab.omitMask |= 1<<iTerm;
145962
+ }else{
145963
+ testcase( i!=iTerm );
145964
+ }
145965
+ }
145561145966
if( (pTerm->eOperator & WO_IN)!=0 ){
145562145967
/* A virtual table that is constrained by an IN clause may not
145563145968
** consume the ORDER BY clause because (1) the order of IN terms
145564145969
** is not necessarily related to the order of output terms and
145565145970
** (2) Multiple outputs from a single IN value will not merge
@@ -145568,11 +145973,10 @@
145568145973
pIdxInfo->idxFlags &= ~SQLITE_INDEX_SCAN_UNIQUE;
145569145974
*pbIn = 1; assert( (mExclude & WO_IN)==0 );
145570145975
}
145571145976
}
145572145977
}
145573
- pNew->u.vtab.omitMask &= ~mNoOmit;
145574145978
145575145979
pNew->nLTerm = mxTerm+1;
145576145980
for(i=0; i<=mxTerm; i++){
145577145981
if( pNew->aLTerm[i]==0 ){
145578145982
/* The non-zero argvIdx values must be contiguous. Raise an
@@ -147163,10 +147567,11 @@
147163147567
sSelect.pEList = pResultSet;
147164147568
sqlite3TreeViewSelect(0, &sSelect, 0);
147165147569
}
147166147570
}
147167147571
if( sqlite3WhereTrace & 0x100 ){ /* Display all terms of the WHERE clause */
147572
+ sqlite3DebugPrintf("---- WHERE clause at start of analysis:\n");
147168147573
sqlite3WhereClausePrint(sWLB.pWC);
147169147574
}
147170147575
#endif
147171147576
147172147577
if( nTabList!=1 || whereShortCut(&sWLB)==0 ){
@@ -147301,11 +147706,17 @@
147301147706
}
147302147707
pWInfo->nLevel--;
147303147708
nTabList--;
147304147709
}
147305147710
}
147711
+#if defined(WHERETRACE_ENABLED)
147712
+ if( sqlite3WhereTrace & 0x100 ){ /* Display all terms of the WHERE clause */
147713
+ sqlite3DebugPrintf("---- WHERE clause at end of analysis:\n");
147714
+ sqlite3WhereClausePrint(sWLB.pWC);
147715
+ }
147306147716
WHERETRACE(0xffff,("*** Optimizer Finished ***\n"));
147717
+#endif
147307147718
pWInfo->pParse->nQueryLoop += pWInfo->nRowOut;
147308147719
147309147720
/* If the caller is an UPDATE or DELETE statement that is requesting
147310147721
** to use a one-pass algorithm, determine if this is appropriate.
147311147722
**
@@ -148571,25 +148982,37 @@
148571148982
}
148572148983
/* Fall through. */
148573148984
148574148985
case TK_AGG_FUNCTION:
148575148986
case TK_COLUMN: {
148576
- Expr *pDup = sqlite3ExprDup(pParse->db, pExpr, 0);
148577
- p->pSub = sqlite3ExprListAppend(pParse, p->pSub, pDup);
148987
+ int iCol = -1;
148988
+ if( p->pSub ){
148989
+ int i;
148990
+ for(i=0; i<p->pSub->nExpr; i++){
148991
+ if( 0==sqlite3ExprCompare(0, p->pSub->a[i].pExpr, pExpr, -1) ){
148992
+ iCol = i;
148993
+ break;
148994
+ }
148995
+ }
148996
+ }
148997
+ if( iCol<0 ){
148998
+ Expr *pDup = sqlite3ExprDup(pParse->db, pExpr, 0);
148999
+ p->pSub = sqlite3ExprListAppend(pParse, p->pSub, pDup);
149000
+ }
148578149001
if( p->pSub ){
148579149002
assert( ExprHasProperty(pExpr, EP_Static)==0 );
148580149003
ExprSetProperty(pExpr, EP_Static);
148581149004
sqlite3ExprDelete(pParse->db, pExpr);
148582149005
ExprClearProperty(pExpr, EP_Static);
148583149006
memset(pExpr, 0, sizeof(Expr));
148584149007
148585149008
pExpr->op = TK_COLUMN;
148586
- pExpr->iColumn = p->pSub->nExpr-1;
149009
+ pExpr->iColumn = (iCol<0 ? p->pSub->nExpr-1: iCol);
148587149010
pExpr->iTable = p->pWin->iEphCsr;
148588149011
pExpr->y.pTab = p->pTab;
148589149012
}
148590
-
149013
+ if( pParse->db->mallocFailed ) return WRC_Abort;
148591149014
break;
148592149015
}
148593149016
148594149017
default: /* no-op */
148595149018
break;
@@ -148667,13 +149090,15 @@
148667149090
if( pAppend ){
148668149091
int i;
148669149092
int nInit = pList ? pList->nExpr : 0;
148670149093
for(i=0; i<pAppend->nExpr; i++){
148671149094
Expr *pDup = sqlite3ExprDup(pParse->db, pAppend->a[i].pExpr, 0);
149095
+ assert( pDup==0 || !ExprHasProperty(pDup, EP_MemToken) );
148672149096
if( bIntToNull && pDup && pDup->op==TK_INTEGER ){
148673149097
pDup->op = TK_NULL;
148674149098
pDup->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
149099
+ pDup->u.zToken = 0;
148675149100
}
148676149101
pList = sqlite3ExprListAppend(pParse, pList, pDup);
148677149102
if( pList ) pList->a[nInit+i].sortFlags = pAppend->a[i].sortFlags;
148678149103
}
148679149104
}
@@ -148704,11 +149129,11 @@
148704149129
Window *pWin; /* Window object iterator */
148705149130
Table *pTab;
148706149131
148707149132
pTab = sqlite3DbMallocZero(db, sizeof(Table));
148708149133
if( pTab==0 ){
148709
- return SQLITE_NOMEM;
149134
+ return sqlite3ErrorToParser(db, SQLITE_NOMEM);
148710149135
}
148711149136
148712149137
p->pSrc = 0;
148713149138
p->pWhere = 0;
148714149139
p->pGroupBy = 0;
@@ -148791,10 +149216,13 @@
148791149216
p->pSrc->a[0].pSelect = pSub;
148792149217
sqlite3SrcListAssignCursors(pParse, p->pSrc);
148793149218
pSub->selFlags |= SF_Expanded;
148794149219
pTab2 = sqlite3ResultSetOfSelect(pParse, pSub, SQLITE_AFF_NONE);
148795149220
if( pTab2==0 ){
149221
+ /* Might actually be some other kind of error, but in that case
149222
+ ** pParse->nErr will be set, so if SQLITE_NOMEM is set, we will get
149223
+ ** the correct error message regardless. */
148796149224
rc = SQLITE_NOMEM;
148797149225
}else{
148798149226
memcpy(pTab, pTab2, sizeof(Table));
148799149227
pTab->tabFlags |= TF_Ephemeral;
148800149228
p->pSrc->a[0].pTab = pTab;
@@ -148809,10 +149237,17 @@
148809149237
}
148810149238
if( db->mallocFailed ) rc = SQLITE_NOMEM;
148811149239
sqlite3DbFree(db, pTab);
148812149240
}
148813149241
149242
+ if( rc ){
149243
+ if( pParse->nErr==0 ){
149244
+ assert( pParse->db->mallocFailed );
149245
+ sqlite3ErrorToParser(pParse->db, SQLITE_NOMEM);
149246
+ }
149247
+ sqlite3SelectReset(pParse, p);
149248
+ }
148814149249
return rc;
148815149250
}
148816149251
148817149252
/*
148818149253
** Unlink the Window object from the Select to which it is attached,
@@ -149045,10 +149480,11 @@
149045149480
/*
149046149481
** Return 0 if the two window objects are identical, or non-zero otherwise.
149047149482
** Identical window objects can be processed in a single scan.
149048149483
*/
149049149484
SQLITE_PRIVATE int sqlite3WindowCompare(Parse *pParse, Window *p1, Window *p2, int bFilter){
149485
+ if( NEVER(p1==0) || NEVER(p2==0) ) return 1;
149050149486
if( p1->eFrmType!=p2->eFrmType ) return 1;
149051149487
if( p1->eStart!=p2->eStart ) return 1;
149052149488
if( p1->eEnd!=p2->eEnd ) return 1;
149053149489
if( p1->eExclude!=p2->eExclude ) return 1;
149054149490
if( sqlite3ExprCompare(pParse, p1->pStart, p2->pStart, -1) ) return 1;
@@ -151033,21 +151469,22 @@
151033151469
#define sqlite3ParserCTX_PDECL ,Parse *pParse
151034151470
#define sqlite3ParserCTX_PARAM ,pParse
151035151471
#define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse;
151036151472
#define sqlite3ParserCTX_STORE yypParser->pParse=pParse;
151037151473
#define YYFALLBACK 1
151038
-#define YYNSTATE 550
151474
+#define YYNSTATE 551
151039151475
#define YYNRULE 385
151476
+#define YYNRULE_WITH_ACTION 325
151040151477
#define YYNTOKEN 181
151041
-#define YY_MAX_SHIFT 549
151042
-#define YY_MIN_SHIFTREDUCE 800
151043
-#define YY_MAX_SHIFTREDUCE 1184
151044
-#define YY_ERROR_ACTION 1185
151045
-#define YY_ACCEPT_ACTION 1186
151046
-#define YY_NO_ACTION 1187
151047
-#define YY_MIN_REDUCE 1188
151048
-#define YY_MAX_REDUCE 1572
151478
+#define YY_MAX_SHIFT 550
151479
+#define YY_MIN_SHIFTREDUCE 801
151480
+#define YY_MAX_SHIFTREDUCE 1185
151481
+#define YY_ERROR_ACTION 1186
151482
+#define YY_ACCEPT_ACTION 1187
151483
+#define YY_NO_ACTION 1188
151484
+#define YY_MIN_REDUCE 1189
151485
+#define YY_MAX_REDUCE 1573
151049151486
/************* End control #defines *******************************************/
151050151487
#define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
151051151488
151052151489
/* Define the yytestcase() macro to be a no-op if is not already defined
151053151490
** otherwise.
@@ -151112,206 +151549,206 @@
151112151549
** yy_default[] Default action for each state.
151113151550
**
151114151551
*********** Begin parsing tables **********************************************/
151115151552
#define YY_ACTTAB_COUNT (1958)
151116151553
static const YYACTIONTYPE yy_action[] = {
151117
- /* 0 */ 544, 1219, 544, 449, 1257, 544, 1236, 544, 114, 111,
151118
- /* 10 */ 211, 544, 1534, 544, 1257, 521, 114, 111, 211, 390,
151119
- /* 20 */ 1229, 342, 42, 42, 42, 42, 1222, 42, 42, 71,
151120
- /* 30 */ 71, 934, 1221, 71, 71, 71, 71, 1459, 1490, 935,
151121
- /* 40 */ 817, 451, 6, 121, 122, 112, 1162, 1162, 1003, 1006,
151122
- /* 50 */ 996, 996, 119, 119, 120, 120, 120, 120, 1540, 390,
151123
- /* 60 */ 1355, 1514, 549, 2, 1190, 194, 526, 434, 143, 291,
151124
- /* 70 */ 526, 136, 526, 369, 261, 502, 272, 383, 1270, 525,
151125
- /* 80 */ 501, 491, 164, 121, 122, 112, 1162, 1162, 1003, 1006,
151126
- /* 90 */ 996, 996, 119, 119, 120, 120, 120, 120, 1355, 440,
151127
- /* 100 */ 1511, 118, 118, 118, 118, 117, 117, 116, 116, 116,
151128
- /* 110 */ 115, 422, 266, 266, 266, 266, 1495, 356, 1497, 433,
151129
- /* 120 */ 355, 1495, 515, 522, 1482, 541, 1111, 541, 1111, 390,
151554
+ /* 0 */ 544, 1220, 544, 449, 1258, 544, 1237, 544, 114, 111,
151555
+ /* 10 */ 211, 544, 1535, 544, 1258, 521, 114, 111, 211, 390,
151556
+ /* 20 */ 1230, 342, 42, 42, 42, 42, 1223, 42, 42, 71,
151557
+ /* 30 */ 71, 935, 1222, 71, 71, 71, 71, 1460, 1491, 936,
151558
+ /* 40 */ 818, 451, 6, 121, 122, 112, 1163, 1163, 1004, 1007,
151559
+ /* 50 */ 997, 997, 119, 119, 120, 120, 120, 120, 1541, 390,
151560
+ /* 60 */ 1356, 1515, 550, 2, 1191, 194, 526, 434, 143, 291,
151561
+ /* 70 */ 526, 136, 526, 369, 261, 502, 272, 383, 1271, 525,
151562
+ /* 80 */ 501, 491, 164, 121, 122, 112, 1163, 1163, 1004, 1007,
151563
+ /* 90 */ 997, 997, 119, 119, 120, 120, 120, 120, 1356, 440,
151564
+ /* 100 */ 1512, 118, 118, 118, 118, 117, 117, 116, 116, 116,
151565
+ /* 110 */ 115, 422, 266, 266, 266, 266, 1496, 356, 1498, 433,
151566
+ /* 120 */ 355, 1496, 515, 522, 1483, 541, 1112, 541, 1112, 390,
151130151567
/* 130 */ 403, 241, 208, 114, 111, 211, 98, 290, 535, 221,
151131
- /* 140 */ 1026, 118, 118, 118, 118, 117, 117, 116, 116, 116,
151132
- /* 150 */ 115, 422, 1139, 121, 122, 112, 1162, 1162, 1003, 1006,
151133
- /* 160 */ 996, 996, 119, 119, 120, 120, 120, 120, 404, 426,
151134
- /* 170 */ 117, 117, 116, 116, 116, 115, 422, 1415, 466, 123,
151568
+ /* 140 */ 1027, 118, 118, 118, 118, 117, 117, 116, 116, 116,
151569
+ /* 150 */ 115, 422, 1140, 121, 122, 112, 1163, 1163, 1004, 1007,
151570
+ /* 160 */ 997, 997, 119, 119, 120, 120, 120, 120, 404, 426,
151571
+ /* 170 */ 117, 117, 116, 116, 116, 115, 422, 1416, 466, 123,
151135151572
/* 180 */ 118, 118, 118, 118, 117, 117, 116, 116, 116, 115,
151136151573
/* 190 */ 422, 116, 116, 116, 115, 422, 538, 538, 538, 390,
151137
- /* 200 */ 503, 120, 120, 120, 120, 113, 1048, 1139, 1140, 1141,
151138
- /* 210 */ 1048, 118, 118, 118, 118, 117, 117, 116, 116, 116,
151139
- /* 220 */ 115, 422, 1458, 121, 122, 112, 1162, 1162, 1003, 1006,
151140
- /* 230 */ 996, 996, 119, 119, 120, 120, 120, 120, 390, 442,
151141
- /* 240 */ 314, 83, 461, 81, 357, 380, 1139, 80, 118, 118,
151574
+ /* 200 */ 503, 120, 120, 120, 120, 113, 1049, 1140, 1141, 1142,
151575
+ /* 210 */ 1049, 118, 118, 118, 118, 117, 117, 116, 116, 116,
151576
+ /* 220 */ 115, 422, 1459, 121, 122, 112, 1163, 1163, 1004, 1007,
151577
+ /* 230 */ 997, 997, 119, 119, 120, 120, 120, 120, 390, 442,
151578
+ /* 240 */ 314, 83, 461, 81, 357, 380, 1140, 80, 118, 118,
151142151579
/* 250 */ 118, 118, 117, 117, 116, 116, 116, 115, 422, 179,
151143
- /* 260 */ 432, 422, 121, 122, 112, 1162, 1162, 1003, 1006, 996,
151144
- /* 270 */ 996, 119, 119, 120, 120, 120, 120, 432, 431, 266,
151580
+ /* 260 */ 432, 422, 121, 122, 112, 1163, 1163, 1004, 1007, 997,
151581
+ /* 270 */ 997, 119, 119, 120, 120, 120, 120, 432, 431, 266,
151145151582
/* 280 */ 266, 118, 118, 118, 118, 117, 117, 116, 116, 116,
151146
- /* 290 */ 115, 422, 541, 1106, 900, 504, 1139, 114, 111, 211,
151147
- /* 300 */ 1428, 1139, 1140, 1141, 206, 489, 1106, 390, 447, 1106,
151148
- /* 310 */ 543, 328, 120, 120, 120, 120, 298, 1428, 1430, 17,
151583
+ /* 290 */ 115, 422, 541, 1107, 901, 504, 1140, 114, 111, 211,
151584
+ /* 300 */ 1429, 1140, 1141, 1142, 206, 489, 1107, 390, 447, 1107,
151585
+ /* 310 */ 543, 328, 120, 120, 120, 120, 298, 1429, 1431, 17,
151149151586
/* 320 */ 118, 118, 118, 118, 117, 117, 116, 116, 116, 115,
151150
- /* 330 */ 422, 121, 122, 112, 1162, 1162, 1003, 1006, 996, 996,
151151
- /* 340 */ 119, 119, 120, 120, 120, 120, 390, 1355, 432, 1139,
151152
- /* 350 */ 480, 1139, 1140, 1141, 993, 993, 1004, 1007, 443, 118,
151587
+ /* 330 */ 422, 121, 122, 112, 1163, 1163, 1004, 1007, 997, 997,
151588
+ /* 340 */ 119, 119, 120, 120, 120, 120, 390, 1356, 432, 1140,
151589
+ /* 350 */ 480, 1140, 1141, 1142, 994, 994, 1005, 1008, 443, 118,
151153151590
/* 360 */ 118, 118, 118, 117, 117, 116, 116, 116, 115, 422,
151154
- /* 370 */ 121, 122, 112, 1162, 1162, 1003, 1006, 996, 996, 119,
151155
- /* 380 */ 119, 120, 120, 120, 120, 1051, 1051, 463, 1428, 118,
151591
+ /* 370 */ 121, 122, 112, 1163, 1163, 1004, 1007, 997, 997, 119,
151592
+ /* 380 */ 119, 120, 120, 120, 120, 1052, 1052, 463, 1429, 118,
151156151593
/* 390 */ 118, 118, 118, 117, 117, 116, 116, 116, 115, 422,
151157
- /* 400 */ 1139, 449, 544, 1423, 1139, 1140, 1141, 233, 963, 1139,
151158
- /* 410 */ 479, 476, 475, 171, 358, 390, 164, 405, 412, 839,
151159
- /* 420 */ 474, 164, 185, 332, 71, 71, 1240, 997, 118, 118,
151594
+ /* 400 */ 1140, 449, 544, 1424, 1140, 1141, 1142, 233, 964, 1140,
151595
+ /* 410 */ 479, 476, 475, 171, 358, 390, 164, 405, 412, 840,
151596
+ /* 420 */ 474, 164, 185, 332, 71, 71, 1241, 998, 118, 118,
151160151597
/* 430 */ 118, 118, 117, 117, 116, 116, 116, 115, 422, 121,
151161
- /* 440 */ 122, 112, 1162, 1162, 1003, 1006, 996, 996, 119, 119,
151162
- /* 450 */ 120, 120, 120, 120, 390, 1139, 1140, 1141, 832, 12,
151163
- /* 460 */ 313, 507, 163, 354, 1139, 1140, 1141, 114, 111, 211,
151598
+ /* 440 */ 122, 112, 1163, 1163, 1004, 1007, 997, 997, 119, 119,
151599
+ /* 450 */ 120, 120, 120, 120, 390, 1140, 1141, 1142, 833, 12,
151600
+ /* 460 */ 313, 507, 163, 354, 1140, 1141, 1142, 114, 111, 211,
151164151601
/* 470 */ 506, 290, 535, 544, 276, 180, 290, 535, 121, 122,
151165
- /* 480 */ 112, 1162, 1162, 1003, 1006, 996, 996, 119, 119, 120,
151602
+ /* 480 */ 112, 1163, 1163, 1004, 1007, 997, 997, 119, 119, 120,
151166151603
/* 490 */ 120, 120, 120, 343, 482, 71, 71, 118, 118, 118,
151167
- /* 500 */ 118, 117, 117, 116, 116, 116, 115, 422, 1139, 209,
151168
- /* 510 */ 409, 521, 1139, 1106, 1568, 376, 252, 269, 340, 485,
151169
- /* 520 */ 335, 484, 238, 390, 511, 362, 1106, 1124, 331, 1106,
151604
+ /* 500 */ 118, 117, 117, 116, 116, 116, 115, 422, 1140, 209,
151605
+ /* 510 */ 409, 521, 1140, 1107, 1569, 376, 252, 269, 340, 485,
151606
+ /* 520 */ 335, 484, 238, 390, 511, 362, 1107, 1125, 331, 1107,
151170151607
/* 530 */ 191, 407, 286, 32, 455, 441, 118, 118, 118, 118,
151171151608
/* 540 */ 117, 117, 116, 116, 116, 115, 422, 121, 122, 112,
151172
- /* 550 */ 1162, 1162, 1003, 1006, 996, 996, 119, 119, 120, 120,
151173
- /* 560 */ 120, 120, 390, 1139, 1140, 1141, 984, 1139, 1140, 1141,
151174
- /* 570 */ 1139, 233, 490, 1489, 479, 476, 475, 6, 163, 544,
151175
- /* 580 */ 510, 544, 115, 422, 474, 5, 121, 122, 112, 1162,
151176
- /* 590 */ 1162, 1003, 1006, 996, 996, 119, 119, 120, 120, 120,
151609
+ /* 550 */ 1163, 1163, 1004, 1007, 997, 997, 119, 119, 120, 120,
151610
+ /* 560 */ 120, 120, 390, 1140, 1141, 1142, 985, 1140, 1141, 1142,
151611
+ /* 570 */ 1140, 233, 490, 1490, 479, 476, 475, 6, 163, 544,
151612
+ /* 580 */ 510, 544, 115, 422, 474, 5, 121, 122, 112, 1163,
151613
+ /* 590 */ 1163, 1004, 1007, 997, 997, 119, 119, 120, 120, 120,
151177151614
/* 600 */ 120, 13, 13, 13, 13, 118, 118, 118, 118, 117,
151178151615
/* 610 */ 117, 116, 116, 116, 115, 422, 401, 500, 406, 544,
151179
- /* 620 */ 1483, 542, 1139, 889, 889, 1139, 1140, 1141, 1470, 1139,
151180
- /* 630 */ 275, 390, 805, 806, 807, 968, 420, 420, 420, 16,
151181
- /* 640 */ 16, 55, 55, 1239, 118, 118, 118, 118, 117, 117,
151182
- /* 650 */ 116, 116, 116, 115, 422, 121, 122, 112, 1162, 1162,
151183
- /* 660 */ 1003, 1006, 996, 996, 119, 119, 120, 120, 120, 120,
151184
- /* 670 */ 390, 1186, 1, 1, 549, 2, 1190, 1139, 1140, 1141,
151185
- /* 680 */ 194, 291, 895, 136, 1139, 1140, 1141, 894, 519, 1489,
151186
- /* 690 */ 1270, 3, 378, 6, 121, 122, 112, 1162, 1162, 1003,
151187
- /* 700 */ 1006, 996, 996, 119, 119, 120, 120, 120, 120, 855,
151188
- /* 710 */ 544, 921, 544, 118, 118, 118, 118, 117, 117, 116,
151189
- /* 720 */ 116, 116, 115, 422, 266, 266, 1089, 1566, 1139, 1518,
151190
- /* 730 */ 1566, 1190, 13, 13, 13, 13, 291, 541, 136, 390,
151191
- /* 740 */ 483, 419, 418, 963, 342, 1270, 466, 408, 856, 279,
151616
+ /* 620 */ 1484, 542, 1140, 890, 890, 1140, 1141, 1142, 1471, 1140,
151617
+ /* 630 */ 275, 390, 806, 807, 808, 969, 420, 420, 420, 16,
151618
+ /* 640 */ 16, 55, 55, 1240, 118, 118, 118, 118, 117, 117,
151619
+ /* 650 */ 116, 116, 116, 115, 422, 121, 122, 112, 1163, 1163,
151620
+ /* 660 */ 1004, 1007, 997, 997, 119, 119, 120, 120, 120, 120,
151621
+ /* 670 */ 390, 1187, 1, 1, 550, 2, 1191, 1140, 1141, 1142,
151622
+ /* 680 */ 194, 291, 896, 136, 1140, 1141, 1142, 895, 519, 1490,
151623
+ /* 690 */ 1271, 3, 378, 6, 121, 122, 112, 1163, 1163, 1004,
151624
+ /* 700 */ 1007, 997, 997, 119, 119, 120, 120, 120, 120, 856,
151625
+ /* 710 */ 544, 922, 544, 118, 118, 118, 118, 117, 117, 116,
151626
+ /* 720 */ 116, 116, 115, 422, 266, 266, 1090, 1567, 1140, 549,
151627
+ /* 730 */ 1567, 1191, 13, 13, 13, 13, 291, 541, 136, 390,
151628
+ /* 740 */ 483, 419, 418, 964, 342, 1271, 466, 408, 857, 279,
151192151629
/* 750 */ 140, 221, 118, 118, 118, 118, 117, 117, 116, 116,
151193
- /* 760 */ 116, 115, 422, 121, 122, 112, 1162, 1162, 1003, 1006,
151194
- /* 770 */ 996, 996, 119, 119, 120, 120, 120, 120, 544, 266,
151195
- /* 780 */ 266, 426, 390, 1139, 1140, 1141, 1169, 827, 1169, 466,
151196
- /* 790 */ 429, 145, 541, 1143, 399, 313, 437, 301, 835, 1487,
151197
- /* 800 */ 71, 71, 410, 6, 1087, 471, 221, 100, 112, 1162,
151198
- /* 810 */ 1162, 1003, 1006, 996, 996, 119, 119, 120, 120, 120,
151630
+ /* 760 */ 116, 115, 422, 121, 122, 112, 1163, 1163, 1004, 1007,
151631
+ /* 770 */ 997, 997, 119, 119, 120, 120, 120, 120, 544, 266,
151632
+ /* 780 */ 266, 426, 390, 1140, 1141, 1142, 1170, 828, 1170, 466,
151633
+ /* 790 */ 429, 145, 541, 1144, 399, 313, 437, 301, 836, 1488,
151634
+ /* 800 */ 71, 71, 410, 6, 1088, 471, 221, 100, 112, 1163,
151635
+ /* 810 */ 1163, 1004, 1007, 997, 997, 119, 119, 120, 120, 120,
151199151636
/* 820 */ 120, 118, 118, 118, 118, 117, 117, 116, 116, 116,
151200
- /* 830 */ 115, 422, 237, 1422, 544, 449, 426, 287, 983, 544,
151201
- /* 840 */ 236, 235, 234, 827, 97, 527, 427, 1262, 1262, 1143,
151202
- /* 850 */ 492, 306, 428, 835, 974, 544, 71, 71, 973, 1238,
151637
+ /* 830 */ 115, 422, 237, 1423, 544, 449, 426, 287, 984, 544,
151638
+ /* 840 */ 236, 235, 234, 828, 97, 527, 427, 1263, 1263, 1144,
151639
+ /* 850 */ 492, 306, 428, 836, 975, 544, 71, 71, 974, 1239,
151203151640
/* 860 */ 544, 51, 51, 300, 118, 118, 118, 118, 117, 117,
151204151641
/* 870 */ 116, 116, 116, 115, 422, 194, 103, 70, 70, 266,
151205
- /* 880 */ 266, 544, 71, 71, 266, 266, 30, 389, 342, 973,
151206
- /* 890 */ 973, 975, 541, 526, 1106, 326, 390, 541, 493, 395,
151207
- /* 900 */ 1467, 195, 528, 13, 13, 1355, 240, 1106, 277, 280,
151208
- /* 910 */ 1106, 280, 303, 455, 305, 331, 390, 31, 188, 417,
151209
- /* 920 */ 121, 122, 112, 1162, 1162, 1003, 1006, 996, 996, 119,
151210
- /* 930 */ 119, 120, 120, 120, 120, 142, 390, 363, 455, 983,
151211
- /* 940 */ 121, 122, 112, 1162, 1162, 1003, 1006, 996, 996, 119,
151212
- /* 950 */ 119, 120, 120, 120, 120, 974, 321, 1139, 324, 973,
151213
- /* 960 */ 121, 110, 112, 1162, 1162, 1003, 1006, 996, 996, 119,
151214
- /* 970 */ 119, 120, 120, 120, 120, 462, 375, 1182, 118, 118,
151215
- /* 980 */ 118, 118, 117, 117, 116, 116, 116, 115, 422, 1139,
151216
- /* 990 */ 973, 973, 975, 304, 9, 364, 244, 360, 118, 118,
151642
+ /* 880 */ 266, 544, 71, 71, 266, 266, 30, 389, 342, 974,
151643
+ /* 890 */ 974, 976, 541, 526, 1107, 326, 390, 541, 493, 395,
151644
+ /* 900 */ 1468, 195, 528, 13, 13, 1356, 240, 1107, 277, 280,
151645
+ /* 910 */ 1107, 280, 303, 455, 305, 331, 390, 31, 188, 417,
151646
+ /* 920 */ 121, 122, 112, 1163, 1163, 1004, 1007, 997, 997, 119,
151647
+ /* 930 */ 119, 120, 120, 120, 120, 142, 390, 363, 455, 984,
151648
+ /* 940 */ 121, 122, 112, 1163, 1163, 1004, 1007, 997, 997, 119,
151649
+ /* 950 */ 119, 120, 120, 120, 120, 975, 321, 1140, 324, 974,
151650
+ /* 960 */ 121, 110, 112, 1163, 1163, 1004, 1007, 997, 997, 119,
151651
+ /* 970 */ 119, 120, 120, 120, 120, 462, 375, 1183, 118, 118,
151652
+ /* 980 */ 118, 118, 117, 117, 116, 116, 116, 115, 422, 1140,
151653
+ /* 990 */ 974, 974, 976, 304, 9, 364, 244, 360, 118, 118,
151217151654
/* 1000 */ 118, 118, 117, 117, 116, 116, 116, 115, 422, 312,
151218
- /* 1010 */ 544, 342, 1139, 1140, 1141, 299, 290, 535, 118, 118,
151219
- /* 1020 */ 118, 118, 117, 117, 116, 116, 116, 115, 422, 1260,
151220
- /* 1030 */ 1260, 1160, 13, 13, 278, 419, 418, 466, 390, 920,
151221
- /* 1040 */ 260, 260, 289, 1166, 1139, 1140, 1141, 189, 1168, 266,
151222
- /* 1050 */ 266, 466, 388, 541, 1183, 544, 1167, 263, 144, 487,
151223
- /* 1060 */ 919, 544, 541, 122, 112, 1162, 1162, 1003, 1006, 996,
151224
- /* 1070 */ 996, 119, 119, 120, 120, 120, 120, 71, 71, 1139,
151225
- /* 1080 */ 1169, 1269, 1169, 13, 13, 895, 1067, 1160, 544, 466,
151226
- /* 1090 */ 894, 107, 536, 1488, 4, 1265, 1106, 6, 523, 1046,
151227
- /* 1100 */ 12, 1068, 1089, 1567, 311, 453, 1567, 518, 539, 1106,
151228
- /* 1110 */ 56, 56, 1106, 1486, 421, 1355, 1069, 6, 343, 285,
151655
+ /* 1010 */ 544, 342, 1140, 1141, 1142, 299, 290, 535, 118, 118,
151656
+ /* 1020 */ 118, 118, 117, 117, 116, 116, 116, 115, 422, 1261,
151657
+ /* 1030 */ 1261, 1161, 13, 13, 278, 419, 418, 466, 390, 921,
151658
+ /* 1040 */ 260, 260, 289, 1167, 1140, 1141, 1142, 189, 1169, 266,
151659
+ /* 1050 */ 266, 466, 388, 541, 1184, 544, 1168, 263, 144, 487,
151660
+ /* 1060 */ 920, 544, 541, 122, 112, 1163, 1163, 1004, 1007, 997,
151661
+ /* 1070 */ 997, 119, 119, 120, 120, 120, 120, 71, 71, 1140,
151662
+ /* 1080 */ 1170, 1270, 1170, 13, 13, 896, 1068, 1161, 544, 466,
151663
+ /* 1090 */ 895, 107, 536, 1489, 4, 1266, 1107, 6, 523, 1047,
151664
+ /* 1100 */ 12, 1069, 1090, 1568, 311, 453, 1568, 518, 539, 1107,
151665
+ /* 1110 */ 56, 56, 1107, 1487, 421, 1356, 1070, 6, 343, 285,
151229151666
/* 1120 */ 118, 118, 118, 118, 117, 117, 116, 116, 116, 115,
151230
- /* 1130 */ 422, 423, 1268, 319, 1139, 1140, 1141, 875, 266, 266,
151231
- /* 1140 */ 1274, 107, 536, 533, 4, 1485, 293, 876, 1208, 6,
151232
- /* 1150 */ 210, 541, 541, 164, 1539, 494, 414, 864, 539, 267,
151233
- /* 1160 */ 267, 1211, 396, 509, 497, 204, 266, 266, 394, 529,
151234
- /* 1170 */ 8, 983, 541, 517, 544, 919, 456, 105, 105, 541,
151235
- /* 1180 */ 1087, 423, 266, 266, 106, 415, 423, 546, 545, 266,
151236
- /* 1190 */ 266, 973, 516, 533, 1370, 541, 15, 15, 266, 266,
151237
- /* 1200 */ 454, 1117, 541, 266, 266, 1067, 1369, 513, 290, 535,
151238
- /* 1210 */ 544, 541, 512, 97, 442, 314, 541, 544, 919, 125,
151239
- /* 1220 */ 1068, 983, 973, 973, 975, 976, 27, 105, 105, 399,
151240
- /* 1230 */ 341, 1508, 44, 44, 106, 1069, 423, 546, 545, 57,
151241
- /* 1240 */ 57, 973, 341, 1508, 107, 536, 544, 4, 460, 399,
151242
- /* 1250 */ 214, 1117, 457, 294, 375, 1088, 532, 297, 544, 537,
151667
+ /* 1130 */ 422, 423, 1269, 319, 1140, 1141, 1142, 876, 266, 266,
151668
+ /* 1140 */ 1275, 107, 536, 533, 4, 1486, 293, 877, 1209, 6,
151669
+ /* 1150 */ 210, 541, 541, 164, 1540, 494, 414, 865, 539, 267,
151670
+ /* 1160 */ 267, 1212, 396, 509, 497, 204, 266, 266, 394, 529,
151671
+ /* 1170 */ 8, 984, 541, 517, 544, 920, 456, 105, 105, 541,
151672
+ /* 1180 */ 1088, 423, 266, 266, 106, 415, 423, 546, 545, 266,
151673
+ /* 1190 */ 266, 974, 516, 533, 1371, 541, 15, 15, 266, 266,
151674
+ /* 1200 */ 454, 1118, 541, 266, 266, 1068, 1370, 513, 290, 535,
151675
+ /* 1210 */ 544, 541, 512, 97, 442, 314, 541, 544, 920, 125,
151676
+ /* 1220 */ 1069, 984, 974, 974, 976, 977, 27, 105, 105, 399,
151677
+ /* 1230 */ 341, 1509, 44, 44, 106, 1070, 423, 546, 545, 57,
151678
+ /* 1240 */ 57, 974, 341, 1509, 107, 536, 544, 4, 460, 399,
151679
+ /* 1250 */ 214, 1118, 457, 294, 375, 1089, 532, 297, 544, 537,
151243151680
/* 1260 */ 396, 539, 290, 535, 104, 244, 102, 524, 58, 58,
151244
- /* 1270 */ 544, 109, 973, 973, 975, 976, 27, 1513, 1128, 425,
151681
+ /* 1270 */ 544, 109, 974, 974, 976, 977, 27, 1514, 1129, 425,
151245151682
/* 1280 */ 59, 59, 270, 237, 423, 138, 95, 373, 373, 372,
151246
- /* 1290 */ 255, 370, 60, 60, 814, 1177, 533, 544, 273, 544,
151247
- /* 1300 */ 1160, 842, 387, 386, 544, 1306, 544, 215, 210, 296,
151248
- /* 1310 */ 513, 846, 544, 265, 208, 514, 1305, 295, 274, 61,
151249
- /* 1320 */ 61, 62, 62, 436, 983, 1159, 45, 45, 46, 46,
151250
- /* 1330 */ 105, 105, 1183, 919, 47, 47, 1473, 106, 544, 423,
151251
- /* 1340 */ 546, 545, 218, 544, 973, 934, 1084, 217, 544, 377,
151252
- /* 1350 */ 395, 107, 536, 935, 4, 156, 1160, 842, 158, 544,
151683
+ /* 1290 */ 255, 370, 60, 60, 815, 1178, 533, 544, 273, 544,
151684
+ /* 1300 */ 1161, 843, 387, 386, 544, 1307, 544, 215, 210, 296,
151685
+ /* 1310 */ 513, 847, 544, 265, 208, 514, 1306, 295, 274, 61,
151686
+ /* 1320 */ 61, 62, 62, 436, 984, 1160, 45, 45, 46, 46,
151687
+ /* 1330 */ 105, 105, 1184, 920, 47, 47, 1474, 106, 544, 423,
151688
+ /* 1340 */ 546, 545, 218, 544, 974, 935, 1085, 217, 544, 377,
151689
+ /* 1350 */ 395, 107, 536, 936, 4, 156, 1161, 843, 158, 544,
151253151690
/* 1360 */ 49, 49, 141, 544, 38, 50, 50, 544, 539, 307,
151254
- /* 1370 */ 63, 63, 544, 1447, 216, 973, 973, 975, 976, 27,
151255
- /* 1380 */ 444, 64, 64, 544, 1446, 65, 65, 544, 524, 14,
151691
+ /* 1370 */ 63, 63, 544, 1448, 216, 974, 974, 976, 977, 27,
151692
+ /* 1380 */ 444, 64, 64, 544, 1447, 65, 65, 544, 524, 14,
151256151693
/* 1390 */ 14, 423, 458, 544, 66, 66, 310, 544, 316, 97,
151257
- /* 1400 */ 1033, 544, 960, 533, 268, 127, 127, 544, 391, 67,
151258
- /* 1410 */ 67, 544, 977, 290, 535, 52, 52, 513, 544, 68,
151259
- /* 1420 */ 68, 1293, 512, 69, 69, 397, 165, 854, 853, 53,
151260
- /* 1430 */ 53, 983, 965, 151, 151, 243, 430, 105, 105, 199,
151261
- /* 1440 */ 152, 152, 448, 1302, 106, 243, 423, 546, 545, 1128,
151262
- /* 1450 */ 425, 973, 320, 270, 861, 862, 1033, 220, 373, 373,
151263
- /* 1460 */ 372, 255, 370, 450, 323, 814, 243, 544, 977, 544,
151264
- /* 1470 */ 107, 536, 544, 4, 544, 937, 938, 325, 215, 1045,
151265
- /* 1480 */ 296, 1045, 973, 973, 975, 976, 27, 539, 295, 76,
151266
- /* 1490 */ 76, 54, 54, 327, 72, 72, 128, 128, 1502, 1253,
151267
- /* 1500 */ 107, 536, 544, 4, 1044, 544, 1044, 531, 1237, 544,
151694
+ /* 1400 */ 1034, 544, 961, 533, 268, 127, 127, 544, 391, 67,
151695
+ /* 1410 */ 67, 544, 978, 290, 535, 52, 52, 513, 544, 68,
151696
+ /* 1420 */ 68, 1294, 512, 69, 69, 397, 165, 855, 854, 53,
151697
+ /* 1430 */ 53, 984, 966, 151, 151, 243, 430, 105, 105, 199,
151698
+ /* 1440 */ 152, 152, 448, 1303, 106, 243, 423, 546, 545, 1129,
151699
+ /* 1450 */ 425, 974, 320, 270, 862, 863, 1034, 220, 373, 373,
151700
+ /* 1460 */ 372, 255, 370, 450, 323, 815, 243, 544, 978, 544,
151701
+ /* 1470 */ 107, 536, 544, 4, 544, 938, 939, 325, 215, 1046,
151702
+ /* 1480 */ 296, 1046, 974, 974, 976, 977, 27, 539, 295, 76,
151703
+ /* 1490 */ 76, 54, 54, 327, 72, 72, 128, 128, 1503, 1254,
151704
+ /* 1500 */ 107, 536, 544, 4, 1045, 544, 1045, 531, 1238, 544,
151268151705
/* 1510 */ 423, 544, 315, 334, 544, 97, 544, 539, 217, 544,
151269
- /* 1520 */ 472, 1527, 533, 239, 73, 73, 156, 129, 129, 158,
151706
+ /* 1520 */ 472, 1528, 533, 239, 73, 73, 156, 129, 129, 158,
151270151707
/* 1530 */ 467, 130, 130, 126, 126, 344, 150, 150, 149, 149,
151271
- /* 1540 */ 423, 134, 134, 329, 1029, 216, 97, 239, 928, 345,
151272
- /* 1550 */ 983, 243, 533, 1314, 339, 544, 105, 105, 899, 1354,
151273
- /* 1560 */ 544, 1289, 258, 106, 338, 423, 546, 545, 544, 1300,
151274
- /* 1570 */ 973, 892, 99, 536, 109, 4, 544, 133, 133, 391,
151275
- /* 1580 */ 983, 197, 131, 131, 290, 535, 105, 105, 530, 539,
151276
- /* 1590 */ 132, 132, 1360, 106, 1218, 423, 546, 545, 75, 75,
151277
- /* 1600 */ 973, 973, 973, 975, 976, 27, 544, 430, 825, 1210,
151278
- /* 1610 */ 893, 139, 423, 109, 544, 1199, 1198, 1200, 1521, 544,
151279
- /* 1620 */ 201, 544, 11, 374, 533, 1286, 347, 349, 77, 77,
151280
- /* 1630 */ 1339, 973, 973, 975, 976, 27, 74, 74, 351, 213,
151281
- /* 1640 */ 435, 43, 43, 48, 48, 302, 477, 309, 1347, 382,
151282
- /* 1650 */ 353, 452, 983, 337, 1236, 1419, 1418, 205, 105, 105,
151283
- /* 1660 */ 192, 367, 193, 534, 1524, 106, 1177, 423, 546, 545,
151284
- /* 1670 */ 247, 167, 973, 270, 1466, 200, 1464, 1174, 373, 373,
151285
- /* 1680 */ 372, 255, 370, 398, 79, 814, 83, 82, 1424, 446,
151286
- /* 1690 */ 161, 177, 169, 95, 1336, 438, 172, 173, 215, 174,
151287
- /* 1700 */ 296, 175, 35, 973, 973, 975, 976, 27, 295, 1344,
151288
- /* 1710 */ 439, 470, 223, 36, 379, 445, 1413, 381, 459, 1350,
151289
- /* 1720 */ 181, 227, 88, 465, 259, 229, 1435, 318, 186, 468,
151290
- /* 1730 */ 322, 230, 384, 1201, 231, 486, 1256, 1255, 217, 411,
151291
- /* 1740 */ 1254, 1247, 90, 846, 206, 413, 156, 505, 1538, 158,
151292
- /* 1750 */ 1225, 1537, 283, 1507, 1226, 336, 385, 284, 1224, 496,
151293
- /* 1760 */ 1536, 1297, 94, 346, 348, 216, 1246, 499, 1298, 245,
151294
- /* 1770 */ 246, 1296, 416, 350, 1493, 124, 1492, 10, 524, 361,
151295
- /* 1780 */ 1399, 101, 96, 288, 508, 253, 1134, 1207, 34, 1295,
151296
- /* 1790 */ 547, 254, 256, 257, 392, 548, 1196, 1191, 359, 391,
151297
- /* 1800 */ 1279, 1278, 196, 365, 290, 535, 366, 352, 1451, 1321,
151298
- /* 1810 */ 1320, 1452, 153, 137, 281, 154, 801, 424, 155, 1450,
151299
- /* 1820 */ 1449, 198, 292, 202, 203, 78, 212, 430, 271, 135,
151300
- /* 1830 */ 1043, 1041, 957, 168, 219, 157, 170, 878, 308, 222,
151301
- /* 1840 */ 1057, 176, 159, 961, 400, 84, 402, 178, 85, 86,
151302
- /* 1850 */ 87, 166, 160, 393, 1060, 224, 225, 1056, 146, 18,
151303
- /* 1860 */ 226, 317, 1049, 1171, 243, 464, 182, 228, 37, 183,
151304
- /* 1870 */ 816, 469, 338, 232, 330, 481, 184, 89, 844, 19,
151305
- /* 1880 */ 20, 92, 473, 478, 333, 91, 162, 857, 147, 488,
151306
- /* 1890 */ 282, 1122, 148, 1009, 927, 1092, 39, 93, 40, 495,
151307
- /* 1900 */ 1093, 187, 498, 207, 262, 264, 922, 242, 1108, 109,
151308
- /* 1910 */ 1112, 1110, 1096, 33, 21, 1116, 520, 1024, 22, 23,
151309
- /* 1920 */ 24, 1115, 25, 190, 97, 1010, 1008, 26, 1012, 1066,
151310
- /* 1930 */ 248, 7, 1065, 249, 1013, 28, 41, 888, 978, 826,
151311
- /* 1940 */ 108, 29, 250, 540, 251, 1529, 371, 368, 1129, 1187,
151312
- /* 1950 */ 1187, 1187, 1187, 1187, 1187, 1187, 1187, 1528,
151708
+ /* 1540 */ 423, 134, 134, 329, 1030, 216, 97, 239, 929, 345,
151709
+ /* 1550 */ 984, 243, 533, 1315, 339, 544, 105, 105, 900, 1355,
151710
+ /* 1560 */ 544, 1290, 258, 106, 338, 423, 546, 545, 544, 1301,
151711
+ /* 1570 */ 974, 893, 99, 536, 109, 4, 544, 133, 133, 391,
151712
+ /* 1580 */ 984, 197, 131, 131, 290, 535, 105, 105, 530, 539,
151713
+ /* 1590 */ 132, 132, 1361, 106, 1219, 423, 546, 545, 75, 75,
151714
+ /* 1600 */ 974, 974, 974, 976, 977, 27, 544, 430, 826, 1211,
151715
+ /* 1610 */ 894, 139, 423, 109, 544, 1200, 1199, 1201, 1522, 544,
151716
+ /* 1620 */ 201, 544, 11, 374, 533, 1287, 347, 349, 77, 77,
151717
+ /* 1630 */ 1340, 974, 974, 976, 977, 27, 74, 74, 351, 213,
151718
+ /* 1640 */ 435, 43, 43, 48, 48, 302, 477, 309, 1348, 382,
151719
+ /* 1650 */ 353, 452, 984, 337, 1237, 1420, 1419, 205, 105, 105,
151720
+ /* 1660 */ 192, 367, 193, 534, 1525, 106, 1178, 423, 546, 545,
151721
+ /* 1670 */ 247, 167, 974, 270, 1467, 200, 1465, 1175, 373, 373,
151722
+ /* 1680 */ 372, 255, 370, 398, 79, 815, 83, 82, 1425, 446,
151723
+ /* 1690 */ 161, 177, 169, 95, 1337, 438, 172, 173, 215, 174,
151724
+ /* 1700 */ 296, 175, 35, 974, 974, 976, 977, 27, 295, 1345,
151725
+ /* 1710 */ 439, 470, 223, 36, 379, 445, 1414, 381, 459, 1351,
151726
+ /* 1720 */ 181, 227, 88, 465, 259, 229, 1436, 318, 186, 468,
151727
+ /* 1730 */ 322, 230, 384, 1202, 231, 486, 1257, 1256, 217, 411,
151728
+ /* 1740 */ 1255, 1248, 90, 847, 206, 413, 156, 505, 1539, 158,
151729
+ /* 1750 */ 1226, 1538, 283, 1508, 1227, 336, 385, 284, 1225, 496,
151730
+ /* 1760 */ 1537, 1298, 94, 346, 348, 216, 1247, 499, 1299, 245,
151731
+ /* 1770 */ 246, 1297, 416, 350, 1494, 124, 1493, 10, 524, 361,
151732
+ /* 1780 */ 1400, 101, 96, 288, 508, 253, 1135, 1208, 34, 1296,
151733
+ /* 1790 */ 547, 254, 256, 257, 392, 548, 1197, 1192, 359, 391,
151734
+ /* 1800 */ 1280, 1279, 196, 365, 290, 535, 366, 352, 1452, 1322,
151735
+ /* 1810 */ 1321, 1453, 153, 137, 281, 154, 802, 424, 155, 1451,
151736
+ /* 1820 */ 1450, 198, 292, 202, 203, 78, 212, 430, 271, 135,
151737
+ /* 1830 */ 1044, 1042, 958, 168, 219, 157, 170, 879, 308, 222,
151738
+ /* 1840 */ 1058, 176, 159, 962, 400, 84, 402, 178, 85, 86,
151739
+ /* 1850 */ 87, 166, 160, 393, 1061, 224, 225, 1057, 146, 18,
151740
+ /* 1860 */ 226, 317, 1050, 1172, 243, 464, 182, 228, 37, 183,
151741
+ /* 1870 */ 817, 469, 338, 232, 330, 481, 184, 89, 845, 19,
151742
+ /* 1880 */ 20, 92, 473, 478, 333, 91, 162, 858, 147, 488,
151743
+ /* 1890 */ 282, 1123, 148, 1010, 928, 1093, 39, 93, 40, 495,
151744
+ /* 1900 */ 1094, 187, 498, 207, 262, 264, 923, 242, 1109, 109,
151745
+ /* 1910 */ 1113, 1111, 1097, 33, 21, 1117, 520, 1025, 22, 23,
151746
+ /* 1920 */ 24, 1116, 25, 190, 97, 1011, 1009, 26, 1013, 1067,
151747
+ /* 1930 */ 248, 7, 1066, 249, 1014, 28, 41, 889, 979, 827,
151748
+ /* 1940 */ 108, 29, 250, 540, 251, 1530, 371, 368, 1131, 1130,
151749
+ /* 1950 */ 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1529,
151313151750
};
151314151751
static const YYCODETYPE yy_lookahead[] = {
151315151752
/* 0 */ 189, 211, 189, 189, 218, 189, 220, 189, 267, 268,
151316151753
/* 10 */ 269, 189, 210, 189, 228, 189, 267, 268, 269, 19,
151317151754
/* 20 */ 218, 189, 211, 212, 211, 212, 211, 211, 212, 211,
@@ -151504,11 +151941,11 @@
151504151941
/* 1890 */ 67, 23, 23, 23, 114, 23, 22, 26, 22, 24,
151505151942
/* 1900 */ 23, 22, 24, 139, 23, 23, 141, 34, 88, 26,
151506151943
/* 1910 */ 75, 86, 23, 22, 34, 75, 24, 23, 34, 34,
151507151944
/* 1920 */ 34, 93, 34, 26, 26, 23, 23, 34, 23, 23,
151508151945
/* 1930 */ 26, 44, 23, 22, 11, 22, 22, 133, 23, 23,
151509
- /* 1940 */ 22, 22, 139, 26, 139, 139, 15, 23, 1, 310,
151946
+ /* 1940 */ 22, 22, 139, 26, 139, 139, 15, 23, 1, 1,
151510151947
/* 1950 */ 310, 310, 310, 310, 310, 310, 310, 139, 310, 310,
151511151948
/* 1960 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
151512151949
/* 1970 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
151513151950
/* 1980 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
151514151951
/* 1990 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
@@ -151525,13 +151962,13 @@
151525151962
/* 2100 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
151526151963
/* 2110 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
151527151964
/* 2120 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
151528151965
/* 2130 */ 310, 310, 310, 310, 310, 310, 310, 310, 310,
151529151966
};
151530
-#define YY_SHIFT_COUNT (549)
151967
+#define YY_SHIFT_COUNT (550)
151531151968
#define YY_SHIFT_MIN (0)
151532
-#define YY_SHIFT_MAX (1947)
151969
+#define YY_SHIFT_MAX (1948)
151533151970
static const unsigned short int yy_shift_ofst[] = {
151534151971
/* 0 */ 1448, 1277, 1668, 1072, 1072, 340, 1122, 1225, 1332, 1481,
151535151972
/* 10 */ 1481, 1481, 335, 0, 0, 180, 897, 1481, 1481, 1481,
151536151973
/* 20 */ 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481,
151537151974
/* 30 */ 930, 930, 1020, 1020, 290, 1, 340, 340, 340, 340,
@@ -151584,10 +152021,11 @@
151584152021
/* 500 */ 1764, 1881, 1882, 1780, 1873, 1879, 1765, 1883, 1880, 1884,
151585152022
/* 510 */ 1885, 1886, 1820, 1835, 1825, 1887, 1840, 1828, 1888, 1889,
151586152023
/* 520 */ 1891, 1892, 1897, 1898, 1893, 1894, 1883, 1902, 1903, 1905,
151587152024
/* 530 */ 1906, 1904, 1909, 1911, 1923, 1913, 1914, 1915, 1916, 1918,
151588152025
/* 540 */ 1919, 1917, 1804, 1803, 1805, 1806, 1818, 1924, 1931, 1947,
152026
+ /* 550 */ 1948,
151589152027
};
151590152028
#define YY_REDUCE_COUNT (389)
151591152029
#define YY_REDUCE_MIN (-262)
151592152030
#define YY_REDUCE_MAX (1617)
151593152031
static const short yy_reduce_ofst[] = {
@@ -151630,65 +152068,66 @@
151630152068
/* 360 */ 1554, 1510, 1583, 1511, 1556, 1559, 1561, 1565, 1588, 1592,
151631152069
/* 370 */ 1601, 1602, 1607, 1608, 1609, 1498, 1557, 1558, 1610, 1600,
151632152070
/* 380 */ 1603, 1611, 1612, 1613, 1596, 1597, 1614, 1615, 1617, 1616,
151633152071
};
151634152072
static const YYACTIONTYPE yy_default[] = {
151635
- /* 0 */ 1572, 1572, 1572, 1408, 1185, 1294, 1185, 1185, 1185, 1408,
151636
- /* 10 */ 1408, 1408, 1185, 1324, 1324, 1461, 1216, 1185, 1185, 1185,
151637
- /* 20 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1407, 1185, 1185,
151638
- /* 30 */ 1185, 1185, 1491, 1491, 1185, 1185, 1185, 1185, 1185, 1185,
151639
- /* 40 */ 1185, 1185, 1185, 1333, 1185, 1185, 1185, 1185, 1185, 1185,
151640
- /* 50 */ 1409, 1410, 1185, 1185, 1185, 1460, 1462, 1425, 1343, 1342,
151641
- /* 60 */ 1341, 1340, 1443, 1311, 1338, 1331, 1335, 1403, 1404, 1402,
151642
- /* 70 */ 1406, 1410, 1409, 1185, 1334, 1374, 1388, 1373, 1185, 1185,
151643
- /* 80 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151644
- /* 90 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151645
- /* 100 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151646
- /* 110 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151647
- /* 120 */ 1185, 1185, 1185, 1185, 1185, 1185, 1382, 1387, 1393, 1386,
151648
- /* 130 */ 1383, 1376, 1375, 1377, 1378, 1185, 1206, 1258, 1185, 1185,
151649
- /* 140 */ 1185, 1185, 1479, 1478, 1185, 1185, 1216, 1368, 1367, 1379,
151650
- /* 150 */ 1380, 1390, 1389, 1468, 1526, 1525, 1426, 1185, 1185, 1185,
151651
- /* 160 */ 1185, 1185, 1185, 1491, 1185, 1185, 1185, 1185, 1185, 1185,
151652
- /* 170 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151653
- /* 180 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1491, 1491,
151654
- /* 190 */ 1185, 1216, 1491, 1491, 1212, 1212, 1318, 1185, 1474, 1294,
151655
- /* 200 */ 1285, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151656
- /* 210 */ 1185, 1185, 1185, 1185, 1185, 1465, 1463, 1185, 1185, 1185,
151657
- /* 220 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151658
- /* 230 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151659
- /* 240 */ 1185, 1185, 1185, 1185, 1185, 1290, 1185, 1185, 1185, 1185,
151660
- /* 250 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1520, 1185, 1438,
151661
- /* 260 */ 1272, 1290, 1290, 1290, 1290, 1292, 1273, 1271, 1284, 1217,
151662
- /* 270 */ 1192, 1564, 1337, 1313, 1313, 1561, 1337, 1337, 1561, 1233,
151663
- /* 280 */ 1542, 1228, 1324, 1324, 1324, 1313, 1318, 1318, 1405, 1291,
151664
- /* 290 */ 1284, 1185, 1564, 1299, 1299, 1563, 1563, 1299, 1426, 1346,
151665
- /* 300 */ 1352, 1261, 1337, 1267, 1267, 1267, 1267, 1299, 1203, 1337,
151666
- /* 310 */ 1337, 1346, 1352, 1261, 1261, 1337, 1299, 1203, 1442, 1558,
151667
- /* 320 */ 1299, 1203, 1416, 1299, 1203, 1299, 1203, 1416, 1259, 1259,
151668
- /* 330 */ 1259, 1248, 1185, 1185, 1416, 1259, 1233, 1259, 1248, 1259,
151669
- /* 340 */ 1259, 1509, 1416, 1420, 1420, 1416, 1317, 1312, 1317, 1312,
151670
- /* 350 */ 1317, 1312, 1317, 1312, 1299, 1501, 1501, 1327, 1327, 1332,
151671
- /* 360 */ 1318, 1411, 1299, 1185, 1332, 1330, 1328, 1337, 1209, 1251,
151672
- /* 370 */ 1523, 1523, 1519, 1519, 1519, 1569, 1569, 1474, 1535, 1216,
151673
- /* 380 */ 1216, 1216, 1216, 1535, 1235, 1235, 1217, 1217, 1216, 1535,
151674
- /* 390 */ 1185, 1185, 1185, 1185, 1185, 1185, 1530, 1185, 1427, 1303,
151675
- /* 400 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151676
- /* 410 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151677
- /* 420 */ 1185, 1185, 1185, 1357, 1185, 1188, 1471, 1185, 1185, 1469,
151678
- /* 430 */ 1185, 1185, 1185, 1185, 1185, 1185, 1304, 1185, 1185, 1185,
151679
- /* 440 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151680
- /* 450 */ 1185, 1185, 1185, 1185, 1185, 1560, 1185, 1185, 1185, 1185,
151681
- /* 460 */ 1185, 1185, 1441, 1440, 1185, 1185, 1301, 1185, 1185, 1185,
151682
- /* 470 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151683
- /* 480 */ 1231, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151684
- /* 490 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151685
- /* 500 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1329, 1185, 1185,
151686
- /* 510 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151687
- /* 520 */ 1185, 1185, 1506, 1319, 1185, 1185, 1551, 1185, 1185, 1185,
151688
- /* 530 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151689
- /* 540 */ 1185, 1546, 1275, 1359, 1185, 1358, 1362, 1185, 1197, 1185,
152073
+ /* 0 */ 1573, 1573, 1573, 1409, 1186, 1295, 1186, 1186, 1186, 1409,
152074
+ /* 10 */ 1409, 1409, 1186, 1325, 1325, 1462, 1217, 1186, 1186, 1186,
152075
+ /* 20 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1408, 1186, 1186,
152076
+ /* 30 */ 1186, 1186, 1492, 1492, 1186, 1186, 1186, 1186, 1186, 1186,
152077
+ /* 40 */ 1186, 1186, 1186, 1334, 1186, 1186, 1186, 1186, 1186, 1186,
152078
+ /* 50 */ 1410, 1411, 1186, 1186, 1186, 1461, 1463, 1426, 1344, 1343,
152079
+ /* 60 */ 1342, 1341, 1444, 1312, 1339, 1332, 1336, 1404, 1405, 1403,
152080
+ /* 70 */ 1407, 1411, 1410, 1186, 1335, 1375, 1389, 1374, 1186, 1186,
152081
+ /* 80 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152082
+ /* 90 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152083
+ /* 100 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152084
+ /* 110 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152085
+ /* 120 */ 1186, 1186, 1186, 1186, 1186, 1186, 1383, 1388, 1394, 1387,
152086
+ /* 130 */ 1384, 1377, 1376, 1378, 1379, 1186, 1207, 1259, 1186, 1186,
152087
+ /* 140 */ 1186, 1186, 1480, 1479, 1186, 1186, 1217, 1369, 1368, 1380,
152088
+ /* 150 */ 1381, 1391, 1390, 1469, 1527, 1526, 1427, 1186, 1186, 1186,
152089
+ /* 160 */ 1186, 1186, 1186, 1492, 1186, 1186, 1186, 1186, 1186, 1186,
152090
+ /* 170 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152091
+ /* 180 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1492, 1492,
152092
+ /* 190 */ 1186, 1217, 1492, 1492, 1213, 1213, 1319, 1186, 1475, 1295,
152093
+ /* 200 */ 1286, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152094
+ /* 210 */ 1186, 1186, 1186, 1186, 1186, 1466, 1464, 1186, 1186, 1186,
152095
+ /* 220 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152096
+ /* 230 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152097
+ /* 240 */ 1186, 1186, 1186, 1186, 1186, 1291, 1186, 1186, 1186, 1186,
152098
+ /* 250 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1521, 1186, 1439,
152099
+ /* 260 */ 1273, 1291, 1291, 1291, 1291, 1293, 1274, 1272, 1285, 1218,
152100
+ /* 270 */ 1193, 1565, 1338, 1314, 1314, 1562, 1338, 1338, 1562, 1234,
152101
+ /* 280 */ 1543, 1229, 1325, 1325, 1325, 1314, 1319, 1319, 1406, 1292,
152102
+ /* 290 */ 1285, 1186, 1565, 1300, 1300, 1564, 1564, 1300, 1427, 1347,
152103
+ /* 300 */ 1353, 1262, 1338, 1268, 1268, 1268, 1268, 1300, 1204, 1338,
152104
+ /* 310 */ 1338, 1347, 1353, 1262, 1262, 1338, 1300, 1204, 1443, 1559,
152105
+ /* 320 */ 1300, 1204, 1417, 1300, 1204, 1300, 1204, 1417, 1260, 1260,
152106
+ /* 330 */ 1260, 1249, 1186, 1186, 1417, 1260, 1234, 1260, 1249, 1260,
152107
+ /* 340 */ 1260, 1510, 1417, 1421, 1421, 1417, 1318, 1313, 1318, 1313,
152108
+ /* 350 */ 1318, 1313, 1318, 1313, 1300, 1502, 1502, 1328, 1328, 1333,
152109
+ /* 360 */ 1319, 1412, 1300, 1186, 1333, 1331, 1329, 1338, 1210, 1252,
152110
+ /* 370 */ 1524, 1524, 1520, 1520, 1520, 1570, 1570, 1475, 1536, 1217,
152111
+ /* 380 */ 1217, 1217, 1217, 1536, 1236, 1236, 1218, 1218, 1217, 1536,
152112
+ /* 390 */ 1186, 1186, 1186, 1186, 1186, 1186, 1531, 1186, 1428, 1304,
152113
+ /* 400 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152114
+ /* 410 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152115
+ /* 420 */ 1186, 1186, 1186, 1358, 1186, 1189, 1472, 1186, 1186, 1470,
152116
+ /* 430 */ 1186, 1186, 1186, 1186, 1186, 1186, 1305, 1186, 1186, 1186,
152117
+ /* 440 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152118
+ /* 450 */ 1186, 1186, 1186, 1186, 1186, 1561, 1186, 1186, 1186, 1186,
152119
+ /* 460 */ 1186, 1186, 1442, 1441, 1186, 1186, 1302, 1186, 1186, 1186,
152120
+ /* 470 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152121
+ /* 480 */ 1232, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152122
+ /* 490 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152123
+ /* 500 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1330, 1186, 1186,
152124
+ /* 510 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152125
+ /* 520 */ 1186, 1186, 1507, 1320, 1186, 1186, 1552, 1186, 1186, 1186,
152126
+ /* 530 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152127
+ /* 540 */ 1186, 1547, 1276, 1360, 1186, 1359, 1363, 1186, 1198, 1186,
152128
+ /* 550 */ 1186,
151690152129
};
151691152130
/********** End of lemon-generated parsing tables *****************************/
151692152131
151693152132
/* The next table maps tokens (terminal symbols) into fallback tokens.
151694152133
** If a construct like the following:
@@ -152619,11 +153058,11 @@
152619153058
/* 325 */ "input ::= cmdlist",
152620153059
/* 326 */ "cmdlist ::= cmdlist ecmd",
152621153060
/* 327 */ "cmdlist ::= ecmd",
152622153061
/* 328 */ "ecmd ::= SEMI",
152623153062
/* 329 */ "ecmd ::= cmdx SEMI",
152624
- /* 330 */ "ecmd ::= explain cmdx",
153063
+ /* 330 */ "ecmd ::= explain cmdx SEMI",
152625153064
/* 331 */ "trans_opt ::=",
152626153065
/* 332 */ "trans_opt ::= TRANSACTION",
152627153066
/* 333 */ "trans_opt ::= TRANSACTION nm",
152628153067
/* 334 */ "savepoint_opt ::= SAVEPOINT",
152629153068
/* 335 */ "savepoint_opt ::=",
@@ -153511,11 +153950,11 @@
153511153950
181, /* (325) input ::= cmdlist */
153512153951
182, /* (326) cmdlist ::= cmdlist ecmd */
153513153952
182, /* (327) cmdlist ::= ecmd */
153514153953
183, /* (328) ecmd ::= SEMI */
153515153954
183, /* (329) ecmd ::= cmdx SEMI */
153516
- 183, /* (330) ecmd ::= explain cmdx */
153955
+ 183, /* (330) ecmd ::= explain cmdx SEMI */
153517153956
188, /* (331) trans_opt ::= */
153518153957
188, /* (332) trans_opt ::= TRANSACTION */
153519153958
188, /* (333) trans_opt ::= TRANSACTION nm */
153520153959
190, /* (334) savepoint_opt ::= SAVEPOINT */
153521153960
190, /* (335) savepoint_opt ::= */
@@ -153901,11 +154340,11 @@
153901154340
-1, /* (325) input ::= cmdlist */
153902154341
-2, /* (326) cmdlist ::= cmdlist ecmd */
153903154342
-1, /* (327) cmdlist ::= ecmd */
153904154343
-1, /* (328) ecmd ::= SEMI */
153905154344
-2, /* (329) ecmd ::= cmdx SEMI */
153906
- -2, /* (330) ecmd ::= explain cmdx */
154345
+ -3, /* (330) ecmd ::= explain cmdx SEMI */
153907154346
0, /* (331) trans_opt ::= */
153908154347
-1, /* (332) trans_opt ::= TRANSACTION */
153909154348
-2, /* (333) trans_opt ::= TRANSACTION nm */
153910154349
-1, /* (334) savepoint_opt ::= SAVEPOINT */
153911154350
0, /* (335) savepoint_opt ::= */
@@ -153989,16 +154428,19 @@
153989154428
yymsp = yypParser->yytos;
153990154429
#ifndef NDEBUG
153991154430
if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
153992154431
yysize = yyRuleInfoNRhs[yyruleno];
153993154432
if( yysize ){
153994
- fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n",
154433
+ fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n",
153995154434
yyTracePrompt,
153996
- yyruleno, yyRuleName[yyruleno], yymsp[yysize].stateno);
154435
+ yyruleno, yyRuleName[yyruleno],
154436
+ yyruleno<YYNRULE_WITH_ACTION ? "" : " without external action",
154437
+ yymsp[yysize].stateno);
153997154438
}else{
153998
- fprintf(yyTraceFILE, "%sReduce %d [%s].\n",
153999
- yyTracePrompt, yyruleno, yyRuleName[yyruleno]);
154439
+ fprintf(yyTraceFILE, "%sReduce %d [%s]%s.\n",
154440
+ yyTracePrompt, yyruleno, yyRuleName[yyruleno],
154441
+ yyruleno<YYNRULE_WITH_ACTION ? "" : " without external action");
154000154442
}
154001154443
}
154002154444
#endif /* NDEBUG */
154003154445
154004154446
/* Check that the stack is large enough to grow by a single entry
@@ -155405,11 +155847,11 @@
155405155847
/* (325) input ::= cmdlist */ yytestcase(yyruleno==325);
155406155848
/* (326) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==326);
155407155849
/* (327) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=327);
155408155850
/* (328) ecmd ::= SEMI */ yytestcase(yyruleno==328);
155409155851
/* (329) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==329);
155410
- /* (330) ecmd ::= explain cmdx */ yytestcase(yyruleno==330);
155852
+ /* (330) ecmd ::= explain cmdx SEMI (NEVER REDUCES) */ assert(yyruleno!=330);
155411155853
/* (331) trans_opt ::= */ yytestcase(yyruleno==331);
155412155854
/* (332) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==332);
155413155855
/* (333) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==333);
155414155856
/* (334) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==334);
155415155857
/* (335) savepoint_opt ::= */ yytestcase(yyruleno==335);
@@ -163082,10 +163524,13 @@
163082163524
# define TESTONLY(X) X
163083163525
#else
163084163526
# define TESTONLY(X)
163085163527
#endif
163086163528
163529
+#define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
163530
+#define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
163531
+
163087163532
#endif /* SQLITE_AMALGAMATION */
163088163533
163089163534
#ifdef SQLITE_DEBUG
163090163535
SQLITE_PRIVATE int sqlite3Fts3Corrupt(void);
163091163536
# define FTS_CORRUPT_VTAB sqlite3Fts3Corrupt()
@@ -163125,10 +163570,11 @@
163125163570
sqlite3_tokenizer *pTokenizer; /* tokenizer for inserts and queries */
163126163571
char *zContentTbl; /* content=xxx option, or NULL */
163127163572
char *zLanguageid; /* languageid=xxx option, or NULL */
163128163573
int nAutoincrmerge; /* Value configured by 'automerge' */
163129163574
u32 nLeafAdd; /* Number of leaf blocks added this trans */
163575
+ int bLock; /* Used to prevent recursive content= tbls */
163130163576
163131163577
/* Precompiled statements used by the implementation. Each of these
163132163578
** statements is run and reset within a single virtual table API call.
163133163579
*/
163134163580
sqlite3_stmt *aStmt[40];
@@ -163463,10 +163909,11 @@
163463163909
163464163910
/* fts3.c */
163465163911
SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char**,const char*,...);
163466163912
SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
163467163913
SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
163914
+SQLITE_PRIVATE int sqlite3Fts3GetVarintU(const char *, sqlite_uint64 *);
163468163915
SQLITE_PRIVATE int sqlite3Fts3GetVarintBounded(const char*,const char*,sqlite3_int64*);
163469163916
SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
163470163917
SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64);
163471163918
SQLITE_PRIVATE void sqlite3Fts3Dequote(char *);
163472163919
SQLITE_PRIVATE void sqlite3Fts3DoclistPrev(int,char*,int,char**,sqlite3_int64*,int*,u8*);
@@ -163550,22 +163997,10 @@
163550163997
#ifndef SQLITE_CORE
163551163998
/* # include "sqlite3ext.h" */
163552163999
SQLITE_EXTENSION_INIT1
163553164000
#endif
163554164001
163555
-/*
163556
-** The following are copied from sqliteInt.h.
163557
-**
163558
-** Constants for the largest and smallest possible 64-bit signed integers.
163559
-** These macros are designed to work correctly on both 32-bit and 64-bit
163560
-** compilers.
163561
-*/
163562
-#ifndef SQLITE_AMALGAMATION
163563
-# define LARGEST_INT64 (0xffffffff|(((sqlite3_int64)0x7fffffff)<<32))
163564
-# define SMALLEST_INT64 (((sqlite3_int64)-1) - LARGEST_INT64)
163565
-#endif
163566
-
163567164002
static int fts3EvalNext(Fts3Cursor *pCsr);
163568164003
static int fts3EvalStart(Fts3Cursor *pCsr);
163569164004
static int fts3TermSegReaderCursor(
163570164005
Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **);
163571164006
@@ -163606,16 +164041,11 @@
163606164041
if( (v & mask2)==0 ){ var = v; return ret; }
163607164042
#define GETVARINT_INIT(v, ptr, shift, mask1, mask2, var, ret) \
163608164043
v = (*ptr++); \
163609164044
if( (v & mask2)==0 ){ var = v; return ret; }
163610164045
163611
-/*
163612
-** Read a 64-bit variable-length integer from memory starting at p[0].
163613
-** Return the number of bytes read, or 0 on error.
163614
-** The value is stored in *v.
163615
-*/
163616
-SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *pBuf, sqlite_int64 *v){
164046
+SQLITE_PRIVATE int sqlite3Fts3GetVarintU(const char *pBuf, sqlite_uint64 *v){
163617164047
const unsigned char *p = (const unsigned char*)pBuf;
163618164048
const unsigned char *pStart = p;
163619164049
u32 a;
163620164050
u64 b;
163621164051
int shift;
@@ -163632,10 +164062,19 @@
163632164062
if( (c & 0x80)==0 ) break;
163633164063
}
163634164064
*v = b;
163635164065
return (int)(p - pStart);
163636164066
}
164067
+
164068
+/*
164069
+** Read a 64-bit variable-length integer from memory starting at p[0].
164070
+** Return the number of bytes read, or 0 on error.
164071
+** The value is stored in *v.
164072
+*/
164073
+SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *pBuf, sqlite_int64 *v){
164074
+ return sqlite3Fts3GetVarintU(pBuf, (sqlite3_uint64*)v);
164075
+}
163637164076
163638164077
/*
163639164078
** Read a 64-bit variable-length integer from memory starting at p[0] and
163640164079
** not extending past pEnd[-1].
163641164080
** Return the number of bytes read, or 0 on error.
@@ -164852,10 +165291,14 @@
164852165291
164853165292
int iLangidCons = -1; /* Index of langid=x constraint, if present */
164854165293
int iDocidGe = -1; /* Index of docid>=x constraint, if present */
164855165294
int iDocidLe = -1; /* Index of docid<=x constraint, if present */
164856165295
int iIdx;
165296
+
165297
+ if( p->bLock ){
165298
+ return SQLITE_ERROR;
165299
+ }
164857165300
164858165301
/* By default use a full table scan. This is an expensive option,
164859165302
** so search through the constraints to see if a more efficient
164860165303
** strategy is possible.
164861165304
*/
@@ -165051,11 +165494,15 @@
165051165494
pCsr->pStmt = p->pSeekStmt;
165052165495
p->pSeekStmt = 0;
165053165496
}else{
165054165497
zSql = sqlite3_mprintf("SELECT %s WHERE rowid = ?", p->zReadExprlist);
165055165498
if( !zSql ) return SQLITE_NOMEM;
165056
- rc = sqlite3_prepare_v3(p->db, zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0);
165499
+ p->bLock++;
165500
+ rc = sqlite3_prepare_v3(
165501
+ p->db, zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0
165502
+ );
165503
+ p->bLock--;
165057165504
sqlite3_free(zSql);
165058165505
}
165059165506
if( rc==SQLITE_OK ) pCsr->bSeekStmt = 1;
165060165507
}
165061165508
return rc;
@@ -165069,15 +165516,19 @@
165069165516
static int fts3CursorSeek(sqlite3_context *pContext, Fts3Cursor *pCsr){
165070165517
int rc = SQLITE_OK;
165071165518
if( pCsr->isRequireSeek ){
165072165519
rc = fts3CursorSeekStmt(pCsr);
165073165520
if( rc==SQLITE_OK ){
165521
+ Fts3Table *pTab = (Fts3Table*)pCsr->base.pVtab;
165522
+ pTab->bLock++;
165074165523
sqlite3_bind_int64(pCsr->pStmt, 1, pCsr->iPrevId);
165075165524
pCsr->isRequireSeek = 0;
165076165525
if( SQLITE_ROW==sqlite3_step(pCsr->pStmt) ){
165526
+ pTab->bLock--;
165077165527
return SQLITE_OK;
165078165528
}else{
165529
+ pTab->bLock--;
165079165530
rc = sqlite3_reset(pCsr->pStmt);
165080165531
if( rc==SQLITE_OK && ((Fts3Table *)pCsr->base.pVtab)->zContentTbl==0 ){
165081165532
/* If no row was found and no error has occurred, then the %_content
165082165533
** table is missing a row that is present in the full-text index.
165083165534
** The data structures are corrupt. */
@@ -165245,11 +165696,11 @@
165245165696
165246165697
assert( piLeaf || piLeaf2 );
165247165698
165248165699
fts3GetVarint32(zNode, &iHeight);
165249165700
rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2);
165250
- assert( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) );
165701
+ assert_fts3_nc( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) );
165251165702
165252165703
if( rc==SQLITE_OK && iHeight>1 ){
165253165704
char *zBlob = 0; /* Blob read from %_segments table */
165254165705
int nBlob = 0; /* Size of zBlob in bytes */
165255165706
@@ -165726,16 +166177,16 @@
165726166177
sqlite3_int64 *pVal /* IN/OUT: Integer value */
165727166178
){
165728166179
if( *pp>=pEnd ){
165729166180
*pp = 0;
165730166181
}else{
165731
- sqlite3_int64 iVal;
165732
- *pp += sqlite3Fts3GetVarint(*pp, &iVal);
166182
+ u64 iVal;
166183
+ *pp += sqlite3Fts3GetVarintU(*pp, &iVal);
165733166184
if( bDescIdx ){
165734
- *pVal -= iVal;
166185
+ *pVal = (i64)((u64)*pVal - iVal);
165735166186
}else{
165736
- *pVal += iVal;
166187
+ *pVal = (i64)((u64)*pVal + iVal);
165737166188
}
165738166189
}
165739166190
}
165740166191
165741166192
/*
@@ -165761,14 +166212,14 @@
165761166212
sqlite3_int64 iVal /* Write this value to the list */
165762166213
){
165763166214
sqlite3_uint64 iWrite;
165764166215
if( bDescIdx==0 || *pbFirst==0 ){
165765166216
assert_fts3_nc( *pbFirst==0 || iVal>=*piPrev );
165766
- iWrite = iVal - *piPrev;
166217
+ iWrite = (u64)iVal - (u64)*piPrev;
165767166218
}else{
165768166219
assert_fts3_nc( *piPrev>=iVal );
165769
- iWrite = *piPrev - iVal;
166220
+ iWrite = (u64)*piPrev - (u64)iVal;
165770166221
}
165771166222
assert( *pbFirst || *piPrev==0 );
165772166223
assert_fts3_nc( *pbFirst==0 || iWrite>0 );
165773166224
*pp += sqlite3Fts3PutVarint(*pp, iWrite);
165774166225
*piPrev = iVal;
@@ -165783,11 +166234,12 @@
165783166234
** Otherwise, (i2-i1).
165784166235
**
165785166236
** Using this makes it easier to write code that can merge doclists that are
165786166237
** sorted in either ascending or descending order.
165787166238
*/
165788
-#define DOCID_CMP(i1, i2) ((bDescDoclist?-1:1) * (i1-i2))
166239
+/* #define DOCID_CMP(i1, i2) ((bDescDoclist?-1:1) * (i64)((u64)i1-i2)) */
166240
+#define DOCID_CMP(i1, i2) ((bDescDoclist?-1:1) * (i1>i2?1:((i1==i2)?0:-1)))
165789166241
165790166242
/*
165791166243
** This function does an "OR" merge of two doclists (output contains all
165792166244
** positions contained in either argument doclist). If the docids in the
165793166245
** input doclists are sorted in ascending order, parameter bDescDoclist
@@ -166197,11 +166649,11 @@
166197166649
** for the pending-terms. If this is a scan, then this call must be being
166198166650
** made by an fts4aux module, not an FTS table. In this case calling
166199166651
** Fts3SegReaderPending might segfault, as the data structures used by
166200166652
** fts4aux are not completely populated. So it's easiest to filter these
166201166653
** calls out here. */
166202
- if( iLevel<0 && p->aIndex ){
166654
+ if( iLevel<0 && p->aIndex && p->iPrevLangid==iLangid ){
166203166655
Fts3SegReader *pSeg = 0;
166204166656
rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix||isScan, &pSeg);
166205166657
if( rc==SQLITE_OK && pSeg ){
166206166658
rc = fts3SegReaderCursorAppend(pCsr, pSeg);
166207166659
}
@@ -166460,17 +166912,20 @@
166460166912
*/
166461166913
static int fts3NextMethod(sqlite3_vtab_cursor *pCursor){
166462166914
int rc;
166463166915
Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
166464166916
if( pCsr->eSearch==FTS3_DOCID_SEARCH || pCsr->eSearch==FTS3_FULLSCAN_SEARCH ){
166917
+ Fts3Table *pTab = (Fts3Table*)pCursor->pVtab;
166918
+ pTab->bLock++;
166465166919
if( SQLITE_ROW!=sqlite3_step(pCsr->pStmt) ){
166466166920
pCsr->isEof = 1;
166467166921
rc = sqlite3_reset(pCsr->pStmt);
166468166922
}else{
166469166923
pCsr->iPrevId = sqlite3_column_int64(pCsr->pStmt, 0);
166470166924
rc = SQLITE_OK;
166471166925
}
166926
+ pTab->bLock--;
166472166927
}else{
166473166928
rc = fts3EvalNext((Fts3Cursor *)pCursor);
166474166929
}
166475166930
assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
166476166931
return rc;
@@ -166526,10 +166981,14 @@
166526166981
sqlite3_value *pDocidLe = 0; /* The "docid <= ?" constraint, if any */
166527166982
int iIdx;
166528166983
166529166984
UNUSED_PARAMETER(idxStr);
166530166985
UNUSED_PARAMETER(nVal);
166986
+
166987
+ if( p->bLock ){
166988
+ return SQLITE_ERROR;
166989
+ }
166531166990
166532166991
eSearch = (idxNum & 0x0000FFFF);
166533166992
assert( eSearch>=0 && eSearch<=(FTS3_FULLTEXT_SEARCH+p->nColumn) );
166534166993
assert( p->pSegments==0 );
166535166994
@@ -166598,11 +167057,15 @@
166598167057
zSql = sqlite3_mprintf("SELECT %s ORDER BY rowid %s",
166599167058
p->zReadExprlist, (pCsr->bDesc ? "DESC" : "ASC")
166600167059
);
166601167060
}
166602167061
if( zSql ){
166603
- rc = sqlite3_prepare_v3(p->db,zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0);
167062
+ p->bLock++;
167063
+ rc = sqlite3_prepare_v3(
167064
+ p->db,zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0
167065
+ );
167066
+ p->bLock--;
166604167067
sqlite3_free(zSql);
166605167068
}else{
166606167069
rc = SQLITE_NOMEM;
166607167070
}
166608167071
}else if( eSearch==FTS3_DOCID_SEARCH ){
@@ -167757,19 +168220,20 @@
167757168220
Fts3Table *pTab,
167758168221
Fts3Doclist *pDL,
167759168222
u8 *pbEof
167760168223
){
167761168224
char *pIter; /* Used to iterate through aAll */
167762
- char *pEnd = &pDL->aAll[pDL->nAll]; /* 1 byte past end of aAll */
168225
+ char *pEnd; /* 1 byte past end of aAll */
167763168226
167764168227
if( pDL->pNextDocid ){
167765168228
pIter = pDL->pNextDocid;
168229
+ assert( pDL->aAll!=0 || pIter==0 );
167766168230
}else{
167767168231
pIter = pDL->aAll;
167768168232
}
167769168233
167770
- if( pIter>=pEnd ){
168234
+ if( pIter==0 || pIter>=(pEnd = pDL->aAll + pDL->nAll) ){
167771168235
/* We have already reached the end of this doclist. EOF. */
167772168236
*pbEof = 1;
167773168237
}else{
167774168238
sqlite3_int64 iDelta;
167775168239
pIter += sqlite3Fts3GetVarint(pIter, &iDelta);
@@ -174105,11 +174569,11 @@
174105174569
int rc = SQLITE_OK;
174106174570
174107174571
assert( !p || p->iLastDocid<=iDocid );
174108174572
174109174573
if( !p || p->iLastDocid!=iDocid ){
174110
- sqlite3_int64 iDelta = iDocid - (p ? p->iLastDocid : 0);
174574
+ u64 iDelta = (u64)iDocid - (u64)(p ? p->iLastDocid : 0);
174111174575
if( p ){
174112174576
assert( p->nData<p->nSpace );
174113174577
assert( p->aData[p->nData]==0 );
174114174578
p->nData++;
174115174579
}
@@ -174646,10 +175110,12 @@
174646175110
aByte = 0;
174647175111
}
174648175112
}
174649175113
*paBlob = aByte;
174650175114
}
175115
+ }else if( rc==SQLITE_ERROR ){
175116
+ rc = FTS_CORRUPT_VTAB;
174651175117
}
174652175118
174653175119
return rc;
174654175120
}
174655175121
@@ -174938,22 +175404,22 @@
174938175404
if( p>=pEnd ){
174939175405
pReader->pOffsetList = 0;
174940175406
}else{
174941175407
rc = fts3SegReaderRequire(pReader, p, FTS3_VARINT_MAX);
174942175408
if( rc==SQLITE_OK ){
174943
- sqlite3_int64 iDelta;
174944
- pReader->pOffsetList = p + sqlite3Fts3GetVarint(p, &iDelta);
175409
+ u64 iDelta;
175410
+ pReader->pOffsetList = p + sqlite3Fts3GetVarintU(p, &iDelta);
174945175411
if( pTab->bDescIdx ){
174946
- pReader->iDocid -= iDelta;
175412
+ pReader->iDocid = (i64)((u64)pReader->iDocid - iDelta);
174947175413
}else{
174948
- pReader->iDocid += iDelta;
175414
+ pReader->iDocid = (i64)((u64)pReader->iDocid + iDelta);
174949175415
}
174950175416
}
174951175417
}
174952175418
}
174953175419
174954
- return SQLITE_OK;
175420
+ return rc;
174955175421
}
174956175422
174957175423
174958175424
SQLITE_PRIVATE int sqlite3Fts3MsrOvfl(
174959175425
Fts3Cursor *pCsr,
@@ -175688,10 +176154,11 @@
175688176154
175689176155
if( nData>0 && nData+nReq>p->nNodeSize ){
175690176156
int rc;
175691176157
175692176158
/* The current leaf node is full. Write it out to the database. */
176159
+ if( pWriter->iFree==LARGEST_INT64 ) return FTS_CORRUPT_VTAB;
175693176160
rc = fts3WriteSegment(p, pWriter->iFree++, pWriter->aData, nData);
175694176161
if( rc!=SQLITE_OK ) return rc;
175695176162
p->nLeafAdd++;
175696176163
175697176164
/* Add the current term to the interior node tree. The term added to
@@ -176385,14 +176852,14 @@
176385176852
/* Calculate the 'docid' delta value to write into the merged
176386176853
** doclist. */
176387176854
sqlite3_int64 iDelta;
176388176855
if( p->bDescIdx && nDoclist>0 ){
176389176856
if( iPrev<=iDocid ) return FTS_CORRUPT_VTAB;
176390
- iDelta = iPrev - iDocid;
176857
+ iDelta = (i64)((u64)iPrev - (u64)iDocid);
176391176858
}else{
176392176859
if( nDoclist>0 && iPrev>=iDocid ) return FTS_CORRUPT_VTAB;
176393
- iDelta = iDocid - iPrev;
176860
+ iDelta = (i64)((u64)iDocid - (u64)iPrev);
176394176861
}
176395176862
176396176863
nByte = sqlite3Fts3VarintLen(iDelta) + (isRequirePos?nList+1:0);
176397176864
if( nDoclist+nByte>pCsr->nBuffer ){
176398176865
char *aNew;
@@ -176671,11 +177138,11 @@
176671177138
if( rc!=SQLITE_ROW ) break;
176672177139
rc = fts3SegWriterAdd(p, &pWriter, 1,
176673177140
csr.zTerm, csr.nTerm, csr.aDoclist, csr.nDoclist);
176674177141
}
176675177142
if( rc!=SQLITE_OK ) goto finished;
176676
- assert( pWriter || bIgnoreEmpty );
177143
+ assert_fts3_nc( pWriter || bIgnoreEmpty );
176677177144
176678177145
if( iLevel!=FTS3_SEGCURSOR_PENDING ){
176679177146
rc = fts3DeleteSegdir(
176680177147
p, iLangid, iIndex, iLevel, csr.apSegment, csr.nSegment
176681177148
);
@@ -178257,17 +178724,21 @@
178257178724
*/
178258178725
static int fts3IncrmergeHintPop(Blob *pHint, i64 *piAbsLevel, int *pnInput){
178259178726
const int nHint = pHint->n;
178260178727
int i;
178261178728
178262
- i = pHint->n-2;
178729
+ i = pHint->n-1;
178730
+ if( (pHint->a[i] & 0x80) ) return FTS_CORRUPT_VTAB;
178263178731
while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
178732
+ if( i==0 ) return FTS_CORRUPT_VTAB;
178733
+ i--;
178264178734
while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
178265178735
178266178736
pHint->n = i;
178267178737
i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel);
178268178738
i += fts3GetVarint32(&pHint->a[i], pnInput);
178739
+ assert( i<=nHint );
178269178740
if( i!=nHint ) return FTS_CORRUPT_VTAB;
178270178741
178271178742
return SQLITE_OK;
178272178743
}
178273178744
@@ -178593,28 +179064,28 @@
178593179064
char *pCsr = csr.aDoclist;
178594179065
char *pEnd = &pCsr[csr.nDoclist];
178595179066
178596179067
i64 iDocid = 0;
178597179068
i64 iCol = 0;
178598
- i64 iPos = 0;
179069
+ u64 iPos = 0;
178599179070
178600179071
pCsr += sqlite3Fts3GetVarint(pCsr, &iDocid);
178601179072
while( pCsr<pEnd ){
178602
- i64 iVal = 0;
178603
- pCsr += sqlite3Fts3GetVarint(pCsr, &iVal);
179073
+ u64 iVal = 0;
179074
+ pCsr += sqlite3Fts3GetVarintU(pCsr, &iVal);
178604179075
if( pCsr<pEnd ){
178605179076
if( iVal==0 || iVal==1 ){
178606179077
iCol = 0;
178607179078
iPos = 0;
178608179079
if( iVal ){
178609179080
pCsr += sqlite3Fts3GetVarint(pCsr, &iCol);
178610179081
}else{
178611
- pCsr += sqlite3Fts3GetVarint(pCsr, &iVal);
179082
+ pCsr += sqlite3Fts3GetVarintU(pCsr, &iVal);
178612179083
if( p->bDescIdx ){
178613
- iDocid -= iVal;
179084
+ iDocid = (i64)((u64)iDocid - iVal);
178614179085
}else{
178615
- iDocid += iVal;
179086
+ iDocid = (i64)((u64)iDocid + iVal);
178616179087
}
178617179088
}
178618179089
}else{
178619179090
iPos += (iVal - 2);
178620179091
cksum = cksum ^ fts3ChecksumEntry(
@@ -182886,22 +183357,53 @@
182886183357
pRoot->jnFlags |= JNODE_APPEND;
182887183358
pParse->aNode[iLabel].jnFlags |= JNODE_RAW;
182888183359
}
182889183360
return pNode;
182890183361
}
182891
- }else if( zPath[0]=='[' && safe_isdigit(zPath[1]) ){
182892
- if( pRoot->eType!=JSON_ARRAY ) return 0;
183362
+ }else if( zPath[0]=='[' ){
182893183363
i = 0;
182894183364
j = 1;
182895183365
while( safe_isdigit(zPath[j]) ){
182896183366
i = i*10 + zPath[j] - '0';
182897183367
j++;
182898183368
}
182899
- if( zPath[j]!=']' ){
182900
- *pzErr = zPath;
182901
- return 0;
183369
+ if( j<2 || zPath[j]!=']' ){
183370
+ if( zPath[1]=='#' ){
183371
+ JsonNode *pBase = pRoot;
183372
+ int iBase = iRoot;
183373
+ if( pRoot->eType!=JSON_ARRAY ) return 0;
183374
+ for(;;){
183375
+ while( j<=pBase->n ){
183376
+ if( (pBase[j].jnFlags & JNODE_REMOVE)==0 ) i++;
183377
+ j += jsonNodeSize(&pBase[j]);
183378
+ }
183379
+ if( (pBase->jnFlags & JNODE_APPEND)==0 ) break;
183380
+ iBase += pBase->u.iAppend;
183381
+ pBase = &pParse->aNode[iBase];
183382
+ j = 1;
183383
+ }
183384
+ j = 2;
183385
+ if( zPath[2]=='-' && safe_isdigit(zPath[3]) ){
183386
+ unsigned int x = 0;
183387
+ j = 3;
183388
+ do{
183389
+ x = x*10 + zPath[j] - '0';
183390
+ j++;
183391
+ }while( safe_isdigit(zPath[j]) );
183392
+ if( x>i ) return 0;
183393
+ i -= x;
183394
+ }
183395
+ if( zPath[j]!=']' ){
183396
+ *pzErr = zPath;
183397
+ return 0;
183398
+ }
183399
+ }else{
183400
+ *pzErr = zPath;
183401
+ return 0;
183402
+ }
182902183403
}
183404
+ if( pRoot->eType!=JSON_ARRAY ) return 0;
182903183405
zPath += j + 1;
182904183406
j = 1;
182905183407
for(;;){
182906183408
while( j<=pRoot->n && (i>0 || (pRoot[j].jnFlags & JNODE_REMOVE)!=0) ){
182907183409
if( (pRoot[j].jnFlags & JNODE_REMOVE)==0 ) i--;
@@ -184365,10 +184867,11 @@
184365184867
/* #include "sqlite3ext.h" */
184366184868
SQLITE_EXTENSION_INIT1
184367184869
#else
184368184870
/* #include "sqlite3.h" */
184369184871
#endif
184872
+SQLITE_PRIVATE int sqlite3GetToken(const unsigned char*,int*); /* In the SQLite core */
184370184873
184371184874
#ifndef SQLITE_AMALGAMATION
184372184875
#include "sqlite3rtree.h"
184373184876
typedef sqlite3_int64 i64;
184374184877
typedef sqlite3_uint64 u64;
@@ -184628,10 +185131,16 @@
184628185131
#define RTREE_GE 0x44 /* D */
184629185132
#define RTREE_GT 0x45 /* E */
184630185133
#define RTREE_MATCH 0x46 /* F: Old-style sqlite3_rtree_geometry_callback() */
184631185134
#define RTREE_QUERY 0x47 /* G: New-style sqlite3_rtree_query_callback() */
184632185135
185136
+/* Special operators available only on cursors. Needs to be consecutive
185137
+** with the normal values above, but must be less than RTREE_MATCH. These
185138
+** are used in the cursor for contraints such as x=NULL (RTREE_FALSE) or
185139
+** x<'xyz' (RTREE_TRUE) */
185140
+#define RTREE_TRUE 0x3f /* ? */
185141
+#define RTREE_FALSE 0x40 /* @ */
184633185142
184634185143
/*
184635185144
** An rtree structure node.
184636185145
*/
184637185146
struct RtreeNode {
@@ -185361,13 +185870,16 @@
185361185870
return rc;
185362185871
}
185363185872
185364185873
185365185874
/*
185366
-** Free the RtreeCursor.aConstraint[] array and its contents.
185875
+** Reset a cursor back to its initial state.
185367185876
*/
185368
-static void freeCursorConstraints(RtreeCursor *pCsr){
185877
+static void resetCursor(RtreeCursor *pCsr){
185878
+ Rtree *pRtree = (Rtree *)(pCsr->base.pVtab);
185879
+ int ii;
185880
+ sqlite3_stmt *pStmt;
185369185881
if( pCsr->aConstraint ){
185370185882
int i; /* Used to iterate through constraint array */
185371185883
for(i=0; i<pCsr->nConstraint; i++){
185372185884
sqlite3_rtree_query_info *pInfo = pCsr->aConstraint[i].pInfo;
185373185885
if( pInfo ){
@@ -185376,24 +185888,28 @@
185376185888
}
185377185889
}
185378185890
sqlite3_free(pCsr->aConstraint);
185379185891
pCsr->aConstraint = 0;
185380185892
}
185893
+ for(ii=0; ii<RTREE_CACHE_SZ; ii++) nodeRelease(pRtree, pCsr->aNode[ii]);
185894
+ sqlite3_free(pCsr->aPoint);
185895
+ pStmt = pCsr->pReadAux;
185896
+ memset(pCsr, 0, sizeof(RtreeCursor));
185897
+ pCsr->base.pVtab = (sqlite3_vtab*)pRtree;
185898
+ pCsr->pReadAux = pStmt;
185899
+
185381185900
}
185382185901
185383185902
/*
185384185903
** Rtree virtual table module xClose method.
185385185904
*/
185386185905
static int rtreeClose(sqlite3_vtab_cursor *cur){
185387185906
Rtree *pRtree = (Rtree *)(cur->pVtab);
185388
- int ii;
185389185907
RtreeCursor *pCsr = (RtreeCursor *)cur;
185390185908
assert( pRtree->nCursor>0 );
185391
- freeCursorConstraints(pCsr);
185909
+ resetCursor(pCsr);
185392185910
sqlite3_finalize(pCsr->pReadAux);
185393
- sqlite3_free(pCsr->aPoint);
185394
- for(ii=0; ii<RTREE_CACHE_SZ; ii++) nodeRelease(pRtree, pCsr->aNode[ii]);
185395185911
sqlite3_free(pCsr);
185396185912
pRtree->nCursor--;
185397185913
nodeBlobReset(pRtree);
185398185914
return SQLITE_OK;
185399185915
}
@@ -185547,13 +186063,16 @@
185547186063
** in a coordinate pair. But make pCellData point to the lower bound.
185548186064
*/
185549186065
pCellData += 8 + 4*(p->iCoord&0xfe);
185550186066
185551186067
assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
185552
- || p->op==RTREE_GT || p->op==RTREE_EQ );
186068
+ || p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_TRUE
186069
+ || p->op==RTREE_FALSE );
185553186070
assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */
185554186071
switch( p->op ){
186072
+ case RTREE_TRUE: return; /* Always satisfied */
186073
+ case RTREE_FALSE: break; /* Never satisfied */
185555186074
case RTREE_LE:
185556186075
case RTREE_LT:
185557186076
case RTREE_EQ:
185558186077
RTREE_DECODE_COORD(eInt, pCellData, val);
185559186078
/* val now holds the lower bound of the coordinate pair */
@@ -185587,20 +186106,23 @@
185587186106
int *peWithin /* Adjust downward, as appropriate */
185588186107
){
185589186108
RtreeDValue xN; /* Coordinate value converted to a double */
185590186109
185591186110
assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
185592
- || p->op==RTREE_GT || p->op==RTREE_EQ );
186111
+ || p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_TRUE
186112
+ || p->op==RTREE_FALSE );
185593186113
pCellData += 8 + p->iCoord*4;
185594186114
assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */
185595186115
RTREE_DECODE_COORD(eInt, pCellData, xN);
185596186116
switch( p->op ){
185597
- case RTREE_LE: if( xN <= p->u.rValue ) return; break;
185598
- case RTREE_LT: if( xN < p->u.rValue ) return; break;
185599
- case RTREE_GE: if( xN >= p->u.rValue ) return; break;
185600
- case RTREE_GT: if( xN > p->u.rValue ) return; break;
185601
- default: if( xN == p->u.rValue ) return; break;
186117
+ case RTREE_TRUE: return; /* Always satisfied */
186118
+ case RTREE_FALSE: break; /* Never satisfied */
186119
+ case RTREE_LE: if( xN <= p->u.rValue ) return; break;
186120
+ case RTREE_LT: if( xN < p->u.rValue ) return; break;
186121
+ case RTREE_GE: if( xN >= p->u.rValue ) return; break;
186122
+ case RTREE_GT: if( xN > p->u.rValue ) return; break;
186123
+ default: if( xN == p->u.rValue ) return; break;
185602186124
}
185603186125
*peWithin = NOT_WITHIN;
185604186126
}
185605186127
185606186128
/*
@@ -186089,30 +186611,32 @@
186089186611
RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor;
186090186612
RtreeNode *pRoot = 0;
186091186613
int ii;
186092186614
int rc = SQLITE_OK;
186093186615
int iCell = 0;
186094
- sqlite3_stmt *pStmt;
186095186616
186096186617
rtreeReference(pRtree);
186097186618
186098186619
/* Reset the cursor to the same state as rtreeOpen() leaves it in. */
186099
- freeCursorConstraints(pCsr);
186100
- sqlite3_free(pCsr->aPoint);
186101
- pStmt = pCsr->pReadAux;
186102
- memset(pCsr, 0, sizeof(RtreeCursor));
186103
- pCsr->base.pVtab = (sqlite3_vtab*)pRtree;
186104
- pCsr->pReadAux = pStmt;
186620
+ resetCursor(pCsr);
186105186621
186106186622
pCsr->iStrategy = idxNum;
186107186623
if( idxNum==1 ){
186108186624
/* Special case - lookup by rowid. */
186109186625
RtreeNode *pLeaf; /* Leaf on which the required cell resides */
186110186626
RtreeSearchPoint *p; /* Search point for the leaf */
186111186627
i64 iRowid = sqlite3_value_int64(argv[0]);
186112186628
i64 iNode = 0;
186113
- rc = findLeafNode(pRtree, iRowid, &pLeaf, &iNode);
186629
+ int eType = sqlite3_value_numeric_type(argv[0]);
186630
+ if( eType==SQLITE_INTEGER
186631
+ || (eType==SQLITE_FLOAT && sqlite3_value_double(argv[0])==iRowid)
186632
+ ){
186633
+ rc = findLeafNode(pRtree, iRowid, &pLeaf, &iNode);
186634
+ }else{
186635
+ rc = SQLITE_OK;
186636
+ pLeaf = 0;
186637
+ }
186114186638
if( rc==SQLITE_OK && pLeaf!=0 ){
186115186639
p = rtreeSearchPointNew(pCsr, RTREE_ZERO, 0);
186116186640
assert( p!=0 ); /* Always returns pCsr->sPoint */
186117186641
pCsr->aNode[0] = pLeaf;
186118186642
p->id = iNode;
@@ -186138,10 +186662,11 @@
186138186662
memset(pCsr->anQueue, 0, sizeof(u32)*(pRtree->iDepth + 1));
186139186663
assert( (idxStr==0 && argc==0)
186140186664
|| (idxStr && (int)strlen(idxStr)==argc*2) );
186141186665
for(ii=0; ii<argc; ii++){
186142186666
RtreeConstraint *p = &pCsr->aConstraint[ii];
186667
+ int eType = sqlite3_value_numeric_type(argv[ii]);
186143186668
p->op = idxStr[ii*2];
186144186669
p->iCoord = idxStr[ii*2+1]-'0';
186145186670
if( p->op>=RTREE_MATCH ){
186146186671
/* A MATCH operator. The right-hand-side must be a blob that
186147186672
** can be cast into an RtreeMatchArg object. One created using
@@ -186152,16 +186677,25 @@
186152186677
break;
186153186678
}
186154186679
p->pInfo->nCoord = pRtree->nDim2;
186155186680
p->pInfo->anQueue = pCsr->anQueue;
186156186681
p->pInfo->mxLevel = pRtree->iDepth + 1;
186157
- }else{
186682
+ }else if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
186158186683
#ifdef SQLITE_RTREE_INT_ONLY
186159186684
p->u.rValue = sqlite3_value_int64(argv[ii]);
186160186685
#else
186161186686
p->u.rValue = sqlite3_value_double(argv[ii]);
186162186687
#endif
186688
+ }else{
186689
+ p->u.rValue = RTREE_ZERO;
186690
+ if( eType==SQLITE_NULL ){
186691
+ p->op = RTREE_FALSE;
186692
+ }else if( p->op==RTREE_LT || p->op==RTREE_LE ){
186693
+ p->op = RTREE_TRUE;
186694
+ }else{
186695
+ p->op = RTREE_FALSE;
186696
+ }
186163186697
}
186164186698
}
186165186699
}
186166186700
}
186167186701
if( rc==SQLITE_OK ){
@@ -187933,10 +188467,18 @@
187933188467
}
187934188468
187935188469
sqlite3_free(zSql);
187936188470
return rc;
187937188471
}
188472
+
188473
+/*
188474
+** Return the length of a token
188475
+*/
188476
+static int rtreeTokenLength(const char *z){
188477
+ int dummy = 0;
188478
+ return sqlite3GetToken((const unsigned char*)z,&dummy);
188479
+}
187938188480
187939188481
/*
187940188482
** This function is the implementation of both the xConnect and xCreate
187941188483
** methods of the r-tree virtual table.
187942188484
**
@@ -187970,12 +188512,12 @@
187970188512
"Too many columns for an rtree table", /* 3 */
187971188513
"Auxiliary rtree columns must be last" /* 4 */
187972188514
};
187973188515
187974188516
assert( RTREE_MAX_AUX_COLUMN<256 ); /* Aux columns counted by a u8 */
187975
- if( argc>RTREE_MAX_AUX_COLUMN+3 ){
187976
- *pzErr = sqlite3_mprintf("%s", aErrMsg[3]);
188517
+ if( argc<6 || argc>RTREE_MAX_AUX_COLUMN+3 ){
188518
+ *pzErr = sqlite3_mprintf("%s", aErrMsg[2 + (argc>=6)]);
187977188519
return SQLITE_ERROR;
187978188520
}
187979188521
187980188522
sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
187981188523
@@ -187999,20 +188541,22 @@
187999188541
/* Create/Connect to the underlying relational database schema. If
188000188542
** that is successful, call sqlite3_declare_vtab() to configure
188001188543
** the r-tree table schema.
188002188544
*/
188003188545
pSql = sqlite3_str_new(db);
188004
- sqlite3_str_appendf(pSql, "CREATE TABLE x(%s", argv[3]);
188546
+ sqlite3_str_appendf(pSql, "CREATE TABLE x(%.*s INT",
188547
+ rtreeTokenLength(argv[3]), argv[3]);
188005188548
for(ii=4; ii<argc; ii++){
188006
- if( argv[ii][0]=='+' ){
188549
+ const char *zArg = argv[ii];
188550
+ if( zArg[0]=='+' ){
188007188551
pRtree->nAux++;
188008
- sqlite3_str_appendf(pSql, ",%s", argv[ii]+1);
188552
+ sqlite3_str_appendf(pSql, ",%.*s", rtreeTokenLength(zArg+1), zArg+1);
188009188553
}else if( pRtree->nAux>0 ){
188010188554
break;
188011188555
}else{
188012188556
pRtree->nDim2++;
188013
- sqlite3_str_appendf(pSql, ",%s", argv[ii]);
188557
+ sqlite3_str_appendf(pSql, ",%.*s NUM", rtreeTokenLength(zArg), zArg);
188014188558
}
188015188559
}
188016188560
sqlite3_str_appendf(pSql, ");");
188017188561
zSql = sqlite3_str_finish(pSql);
188018188562
if( !zSql ){
@@ -189956,21 +190500,15 @@
189956190500
Rtree *pRtree = (Rtree *)pVtabCursor->pVtab;
189957190501
RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor;
189958190502
RtreeNode *pRoot = 0;
189959190503
int rc = SQLITE_OK;
189960190504
int iCell = 0;
189961
- sqlite3_stmt *pStmt;
189962190505
189963190506
rtreeReference(pRtree);
189964190507
189965190508
/* Reset the cursor to the same state as rtreeOpen() leaves it in. */
189966
- freeCursorConstraints(pCsr);
189967
- sqlite3_free(pCsr->aPoint);
189968
- pStmt = pCsr->pReadAux;
189969
- memset(pCsr, 0, sizeof(RtreeCursor));
189970
- pCsr->base.pVtab = (sqlite3_vtab*)pRtree;
189971
- pCsr->pReadAux = pStmt;
190509
+ resetCursor(pCsr);
189972190510
189973190511
pCsr->iStrategy = idxNum;
189974190512
if( idxNum==1 ){
189975190513
/* Special case - lookup by rowid. */
189976190514
RtreeNode *pLeaf; /* Leaf on which the required cell resides */
@@ -196990,11 +197528,11 @@
196990197528
}
196991197529
z += 2;
196992197530
}else{
196993197531
while( *z==0 ) z++;
196994197532
}
196995
- z += (n + 8 + 1);
197533
+ z += (n + 8 + 2);
196996197534
return z;
196997197535
}
196998197536
196999197537
/*
197000197538
** Open an rbu file handle.
@@ -204281,11 +204819,11 @@
204281204819
** the callback, an SQLite error code is returned.
204282204820
**
204283204821
**
204284204822
** xSetAuxdata(pFts5, pAux, xDelete)
204285204823
**
204286
-** Save the pointer passed as the second argument as the extension functions
204824
+** Save the pointer passed as the second argument as the extension function's
204287204825
** "auxiliary data". The pointer may then be retrieved by the current or any
204288204826
** future invocation of the same fts5 extension function made as part of
204289204827
** the same MATCH query using the xGetAuxdata() API.
204290204828
**
204291204829
** Each extension function is allocated a single auxiliary data slot for
@@ -204523,12 +205061,12 @@
204523205061
** all instances of "first place" or "1st place" regardless of which form
204524205062
** the user specified in the MATCH query text.
204525205063
**
204526205064
** There are several ways to approach this in FTS5:
204527205065
**
204528
-** <ol><li> By mapping all synonyms to a single token. In this case, the
204529
-** In the above example, this means that the tokenizer returns the
205066
+** <ol><li> By mapping all synonyms to a single token. In this case, using
205067
+** the above example, this means that the tokenizer returns the
204530205068
** same token for inputs "first" and "1st". Say that token is in
204531205069
** fact "first", so that when the user inserts the document "I won
204532205070
** 1st place" entries are added to the index for tokens "i", "won",
204533205071
** "first" and "place". If the user then queries for '1st + place',
204534205072
** the tokenizer substitutes "first" for "1st" and the query works
@@ -205685,10 +206223,11 @@
205685206223
#define sqlite3Fts5ParserCTX_PARAM
205686206224
#define sqlite3Fts5ParserCTX_FETCH
205687206225
#define sqlite3Fts5ParserCTX_STORE
205688206226
#define fts5YYNSTATE 35
205689206227
#define fts5YYNRULE 28
206228
+#define fts5YYNRULE_WITH_ACTION 28
205690206229
#define fts5YYNFTS5TOKEN 16
205691206230
#define fts5YY_MAX_SHIFT 34
205692206231
#define fts5YY_MIN_SHIFTREDUCE 52
205693206232
#define fts5YY_MAX_SHIFTREDUCE 79
205694206233
#define fts5YY_ERROR_ACTION 80
@@ -206514,16 +207053,19 @@
206514207053
fts5yymsp = fts5yypParser->fts5yytos;
206515207054
#ifndef NDEBUG
206516207055
if( fts5yyTraceFILE && fts5yyruleno<(int)(sizeof(fts5yyRuleName)/sizeof(fts5yyRuleName[0])) ){
206517207056
fts5yysize = fts5yyRuleInfoNRhs[fts5yyruleno];
206518207057
if( fts5yysize ){
206519
- fprintf(fts5yyTraceFILE, "%sReduce %d [%s], go to state %d.\n",
207058
+ fprintf(fts5yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n",
206520207059
fts5yyTracePrompt,
206521
- fts5yyruleno, fts5yyRuleName[fts5yyruleno], fts5yymsp[fts5yysize].stateno);
207060
+ fts5yyruleno, fts5yyRuleName[fts5yyruleno],
207061
+ fts5yyruleno<fts5YYNRULE_WITH_ACTION ? "" : " without external action",
207062
+ fts5yymsp[fts5yysize].stateno);
206522207063
}else{
206523
- fprintf(fts5yyTraceFILE, "%sReduce %d [%s].\n",
206524
- fts5yyTracePrompt, fts5yyruleno, fts5yyRuleName[fts5yyruleno]);
207064
+ fprintf(fts5yyTraceFILE, "%sReduce %d [%s]%s.\n",
207065
+ fts5yyTracePrompt, fts5yyruleno, fts5yyRuleName[fts5yyruleno],
207066
+ fts5yyruleno<fts5YYNRULE_WITH_ACTION ? "" : " without external action");
206525207067
}
206526207068
}
206527207069
#endif /* NDEBUG */
206528207070
206529207071
/* Check that the stack is large enough to grow by a single entry
@@ -208278,11 +208820,11 @@
208278208820
208279208821
/* Set stack variable q to the close-quote character */
208280208822
assert( q=='[' || q=='\'' || q=='"' || q=='`' );
208281208823
if( q=='[' ) q = ']';
208282208824
208283
- while( ALWAYS(z[iIn]) ){
208825
+ while( z[iIn] ){
208284208826
if( z[iIn]==q ){
208285208827
if( z[iIn+1]!=q ){
208286208828
/* Character iIn was the close quote. */
208287208829
iIn++;
208288208830
break;
@@ -211607,14 +212149,16 @@
211607212149
}
211608212150
azConfig[0] = 0;
211609212151
azConfig[1] = "main";
211610212152
azConfig[2] = "tbl";
211611212153
for(i=3; iArg<nArg; iArg++){
211612
- azConfig[i++] = (const char*)sqlite3_value_text(apVal[iArg]);
212154
+ const char *z = (const char*)sqlite3_value_text(apVal[iArg]);
212155
+ azConfig[i++] = (z ? z : "");
211613212156
}
211614212157
211615212158
zExpr = (const char*)sqlite3_value_text(apVal[0]);
212159
+ if( zExpr==0 ) zExpr = "";
211616212160
211617212161
rc = sqlite3Fts5ConfigParse(pGlobal, db, nConfig, azConfig, &pConfig, &zErr);
211618212162
if( rc==SQLITE_OK ){
211619212163
rc = sqlite3Fts5ExprNew(pConfig, pConfig->nCol, zExpr, &pExpr, &zErr);
211620212164
}
@@ -217860,14 +218404,17 @@
217860218404
int n = 0;
217861218405
int i;
217862218406
for(i=0; i<nChar; i++){
217863218407
if( n>=nByte ) return 0; /* Input contains fewer than nChar chars */
217864218408
if( (unsigned char)p[n++]>=0xc0 ){
217865
- if( n>=nByte ) break;
218409
+ if( n>=nByte ) return 0;
217866218410
while( (p[n] & 0xc0)==0x80 ){
217867218411
n++;
217868
- if( n>=nByte ) break;
218412
+ if( n>=nByte ){
218413
+ if( i+1==nChar ) break;
218414
+ return 0;
218415
+ }
217869218416
}
217870218417
}
217871218418
}
217872218419
return n;
217873218420
}
@@ -218265,10 +218812,41 @@
218265218812
218266218813
*pCksum = cksum;
218267218814
return rc;
218268218815
}
218269218816
218817
+/*
218818
+** Check if buffer z[], size n bytes, contains as series of valid utf-8
218819
+** encoded codepoints. If so, return 0. Otherwise, if the buffer does not
218820
+** contain valid utf-8, return non-zero.
218821
+*/
218822
+static int fts5TestUtf8(const char *z, int n){
218823
+ assert_nc( n>0 );
218824
+ int i = 0;
218825
+ while( i<n ){
218826
+ if( (z[i] & 0x80)==0x00 ){
218827
+ i++;
218828
+ }else
218829
+ if( (z[i] & 0xE0)==0xC0 ){
218830
+ if( i+1>=n || (z[i+1] & 0xC0)!=0x80 ) return 1;
218831
+ i += 2;
218832
+ }else
218833
+ if( (z[i] & 0xF0)==0xE0 ){
218834
+ if( i+2>=n || (z[i+1] & 0xC0)!=0x80 || (z[i+2] & 0xC0)!=0x80 ) return 1;
218835
+ i += 3;
218836
+ }else
218837
+ if( (z[i] & 0xF8)==0xF0 ){
218838
+ if( i+3>=n || (z[i+1] & 0xC0)!=0x80 || (z[i+2] & 0xC0)!=0x80 ) return 1;
218839
+ if( (z[i+2] & 0xC0)!=0x80 ) return 1;
218840
+ i += 3;
218841
+ }else{
218842
+ return 1;
218843
+ }
218844
+ }
218845
+
218846
+ return 0;
218847
+}
218270218848
218271218849
/*
218272218850
** This function is also purely an internal test. It does not contribute to
218273218851
** FTS functionality, or even the integrity-check, in any way.
218274218852
*/
@@ -218305,12 +218883,18 @@
218305218883
** the index is disabled are the same. In both ASC and DESC order.
218306218884
**
218307218885
** This check may only be performed if the hash table is empty. This
218308218886
** is because the hash table only supports a single scan query at
218309218887
** a time, and the multi-iter loop from which this function is called
218310
- ** is already performing such a scan. */
218311
- if( p->nPendingData==0 ){
218888
+ ** is already performing such a scan.
218889
+ **
218890
+ ** Also only do this if buffer zTerm contains nTerm bytes of valid
218891
+ ** utf-8. Otherwise, the last part of the buffer contents might contain
218892
+ ** a non-utf-8 sequence that happens to be a prefix of a valid utf-8
218893
+ ** character stored in the main fts index, which will cause the
218894
+ ** test to fail. */
218895
+ if( p->nPendingData==0 && 0==fts5TestUtf8(zTerm, nTerm) ){
218312218896
if( iIdx>0 && rc==SQLITE_OK ){
218313218897
int f = flags|FTS5INDEX_QUERY_TEST_NOIDX;
218314218898
ck2 = 0;
218315218899
rc = fts5QueryCksum(p, iIdx, zTerm, nTerm, f, &ck2);
218316218900
if( rc==SQLITE_OK && ck1!=ck2 ) rc = FTS5_CORRUPT;
@@ -218439,12 +219023,12 @@
218439219023
/* Iterate through the b-tree hierarchy. */
218440219024
while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
218441219025
i64 iRow; /* Rowid for this leaf */
218442219026
Fts5Data *pLeaf; /* Data for this leaf */
218443219027
219028
+ const char *zIdxTerm = (const char*)sqlite3_column_blob(pStmt, 1);
218444219029
int nIdxTerm = sqlite3_column_bytes(pStmt, 1);
218445
- const char *zIdxTerm = (const char*)sqlite3_column_text(pStmt, 1);
218446219030
int iIdxLeaf = sqlite3_column_int(pStmt, 2);
218447219031
int bIdxDlidx = sqlite3_column_int(pStmt, 3);
218448219032
218449219033
/* If the leaf in question has already been trimmed from the segment,
218450219034
** ignore this b-tree entry. Otherwise, load it into memory. */
@@ -220027,19 +220611,28 @@
220027220611
case FTS5_PLAN_SORTED_MATCH: {
220028220612
rc = fts5SorterNext(pCsr);
220029220613
break;
220030220614
}
220031220615
220032
- default:
220616
+ default: {
220617
+ Fts5Config *pConfig = ((Fts5Table*)pCursor->pVtab)->pConfig;
220618
+ pConfig->bLock++;
220033220619
rc = sqlite3_step(pCsr->pStmt);
220620
+ pConfig->bLock--;
220034220621
if( rc!=SQLITE_ROW ){
220035220622
CsrFlagSet(pCsr, FTS5CSR_EOF);
220036220623
rc = sqlite3_reset(pCsr->pStmt);
220624
+ if( rc!=SQLITE_OK ){
220625
+ pCursor->pVtab->zErrMsg = sqlite3_mprintf(
220626
+ "%s", sqlite3_errmsg(pConfig->db)
220627
+ );
220628
+ }
220037220629
}else{
220038220630
rc = SQLITE_OK;
220039220631
}
220040220632
break;
220633
+ }
220041220634
}
220042220635
}
220043220636
220044220637
return rc;
220045220638
}
@@ -220319,10 +220912,17 @@
220319220912
int iCol; /* Column on LHS of MATCH operator */
220320220913
char **pzErrmsg = pConfig->pzErrmsg;
220321220914
int i;
220322220915
int iIdxStr = 0;
220323220916
Fts5Expr *pExpr = 0;
220917
+
220918
+ if( pConfig->bLock ){
220919
+ pTab->p.base.zErrMsg = sqlite3_mprintf(
220920
+ "recursively defined fts5 content table"
220921
+ );
220922
+ return SQLITE_ERROR;
220923
+ }
220324220924
220325220925
if( pCsr->ePlan ){
220326220926
fts5FreeCursorComponents(pCsr);
220327220927
memset(&pCsr->ePlan, 0, sizeof(Fts5Cursor) - ((u8*)&pCsr->ePlan-(u8*)pCsr));
220328220928
}
@@ -220540,21 +221140,28 @@
220540221140
assert( rc!=SQLITE_OK || pTab->p.base.zErrMsg==0 );
220541221141
assert( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_CONTENT) );
220542221142
}
220543221143
220544221144
if( rc==SQLITE_OK && CsrFlagTest(pCsr, FTS5CSR_REQUIRE_CONTENT) ){
221145
+ Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
220545221146
assert( pCsr->pExpr );
220546221147
sqlite3_reset(pCsr->pStmt);
220547221148
sqlite3_bind_int64(pCsr->pStmt, 1, fts5CursorRowid(pCsr));
221149
+ pTab->pConfig->bLock++;
220548221150
rc = sqlite3_step(pCsr->pStmt);
221151
+ pTab->pConfig->bLock--;
220549221152
if( rc==SQLITE_ROW ){
220550221153
rc = SQLITE_OK;
220551221154
CsrFlagClear(pCsr, FTS5CSR_REQUIRE_CONTENT);
220552221155
}else{
220553221156
rc = sqlite3_reset(pCsr->pStmt);
220554221157
if( rc==SQLITE_OK ){
220555221158
rc = FTS5_CORRUPT;
221159
+ }else if( pTab->pConfig->pzErrmsg ){
221160
+ *pTab->pConfig->pzErrmsg = sqlite3_mprintf(
221161
+ "%s", sqlite3_errmsg(pTab->pConfig->db)
221162
+ );
220556221163
}
220557221164
}
220558221165
}
220559221166
return rc;
220560221167
}
@@ -221566,14 +222173,16 @@
221566222173
if( pCsr->pRank || SQLITE_OK==(rc = fts5FindRankFunction(pCsr)) ){
221567222174
fts5ApiInvoke(pCsr->pRank, pCsr, pCtx, pCsr->nRankArg, pCsr->apRankArg);
221568222175
}
221569222176
}
221570222177
}else if( !fts5IsContentless(pTab) ){
222178
+ pConfig->pzErrmsg = &pTab->p.base.zErrMsg;
221571222179
rc = fts5SeekCursor(pCsr, 1);
221572222180
if( rc==SQLITE_OK ){
221573222181
sqlite3_result_value(pCtx, sqlite3_column_value(pCsr->pStmt, iCol+1));
221574222182
}
222183
+ pConfig->pzErrmsg = 0;
221575222184
}
221576222185
return rc;
221577222186
}
221578222187
221579222188
@@ -221846,11 +222455,11 @@
221846222455
int nArg, /* Number of args */
221847222456
sqlite3_value **apUnused /* Function arguments */
221848222457
){
221849222458
assert( nArg==0 );
221850222459
UNUSED_PARAM2(nArg, apUnused);
221851
- sqlite3_result_text(pCtx, "fts5: 2019-11-20 12:07:40 2575a68c3965e72f2ab211d933012442755afe6a9b7de9e9e50cdd2155fd1ec8", -1, SQLITE_TRANSIENT);
222460
+ sqlite3_result_text(pCtx, "fts5: 2019-12-26 01:10:17 f482a4cdfa768941e22c399de8ec29a55e729529eeae86d3832077ad1bef22f3", -1, SQLITE_TRANSIENT);
221852222461
}
221853222462
221854222463
/*
221855222464
** Return true if zName is the extension on one of the shadow tables used
221856222465
** by this module.
@@ -222593,14 +223202,15 @@
222593223202
sqlite3Fts5BufferZero(&buf);
222594223203
rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 0, iRowid);
222595223204
for(ctx.iCol=0; rc==SQLITE_OK && ctx.iCol<pConfig->nCol; ctx.iCol++){
222596223205
ctx.szCol = 0;
222597223206
if( pConfig->abUnindexed[ctx.iCol]==0 ){
223207
+ const char *zText = (const char*)sqlite3_column_text(pScan, ctx.iCol+1);
223208
+ int nText = sqlite3_column_bytes(pScan, ctx.iCol+1);
222598223209
rc = sqlite3Fts5Tokenize(pConfig,
222599223210
FTS5_TOKENIZE_DOCUMENT,
222600
- (const char*)sqlite3_column_text(pScan, ctx.iCol+1),
222601
- sqlite3_column_bytes(pScan, ctx.iCol+1),
223211
+ zText, nText,
222602223212
(void*)&ctx,
222603223213
fts5StorageInsertCallback
222604223214
);
222605223215
}
222606223216
sqlite3Fts5BufferAppendVarint(&rc, &buf, ctx.szCol);
@@ -222718,14 +223328,15 @@
222718223328
rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 0, iRowid);
222719223329
}
222720223330
for(ctx.iCol=0; rc==SQLITE_OK && ctx.iCol<pConfig->nCol; ctx.iCol++){
222721223331
ctx.szCol = 0;
222722223332
if( pConfig->abUnindexed[ctx.iCol]==0 ){
223333
+ const char *zText = (const char*)sqlite3_value_text(apVal[ctx.iCol+2]);
223334
+ int nText = sqlite3_value_bytes(apVal[ctx.iCol+2]);
222723223335
rc = sqlite3Fts5Tokenize(pConfig,
222724223336
FTS5_TOKENIZE_DOCUMENT,
222725
- (const char*)sqlite3_value_text(apVal[ctx.iCol+2]),
222726
- sqlite3_value_bytes(apVal[ctx.iCol+2]),
223337
+ zText, nText,
222727223338
(void*)&ctx,
222728223339
fts5StorageInsertCallback
222729223340
);
222730223341
}
222731223342
sqlite3Fts5BufferAppendVarint(&rc, &buf, ctx.szCol);
@@ -222890,14 +223501,15 @@
222890223501
ctx.szCol = 0;
222891223502
if( pConfig->eDetail==FTS5_DETAIL_COLUMNS ){
222892223503
rc = sqlite3Fts5TermsetNew(&ctx.pTermset);
222893223504
}
222894223505
if( rc==SQLITE_OK ){
223506
+ const char *zText = (const char*)sqlite3_column_text(pScan, i+1);
223507
+ int nText = sqlite3_column_bytes(pScan, i+1);
222895223508
rc = sqlite3Fts5Tokenize(pConfig,
222896223509
FTS5_TOKENIZE_DOCUMENT,
222897
- (const char*)sqlite3_column_text(pScan, i+1),
222898
- sqlite3_column_bytes(pScan, i+1),
223510
+ zText, nText,
222899223511
(void*)&ctx,
222900223512
fts5StorageIntegrityCallback
222901223513
);
222902223514
}
222903223515
if( rc==SQLITE_OK && pConfig->bColumnsize && ctx.szCol!=aColSize[i] ){
@@ -226616,12 +227228,12 @@
226616227228
}
226617227229
#endif /* SQLITE_CORE */
226618227230
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
226619227231
226620227232
/************** End of stmt.c ************************************************/
226621
-#if __LINE__!=226621
227233
+#if __LINE__!=227233
226622227234
#undef SQLITE_SOURCE_ID
226623
-#define SQLITE_SOURCE_ID "2019-11-20 13:31:52 a0f6d526baecd061a5e2bec5eb698fb5dfb10122ac79c853d7b3f4a48bc9alt2"
227235
+#define SQLITE_SOURCE_ID "2019-12-26 01:10:17 f482a4cdfa768941e22c399de8ec29a55e729529eeae86d3832077ad1befalt2"
226624227236
#endif
226625227237
/* Return the source-id for this library */
226626227238
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
226627227239
/************************** End of sqlite3.c ******************************/
226628227240
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1165,11 +1165,11 @@
1165 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1166 ** [sqlite_version()] and [sqlite_source_id()].
1167 */
1168 #define SQLITE_VERSION "3.31.0"
1169 #define SQLITE_VERSION_NUMBER 3031000
1170 #define SQLITE_SOURCE_ID "2019-11-20 13:31:52 a0f6d526baecd061a5e2bec5eb698fb5dfb10122ac79c853d7b3f4a48bc9f49b"
1171
1172 /*
1173 ** CAPI3REF: Run-Time Library Version Numbers
1174 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1175 **
@@ -1581,10 +1581,11 @@
1581 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
1582 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
1583 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
1584 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
1585 #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
 
1586
1587 /*
1588 ** CAPI3REF: Flags For File Open Operations
1589 **
1590 ** These bit values are intended for use in the
@@ -2021,20 +2022,20 @@
2021 **
2022 ** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
2023 ** ^The [SQLITE_FCNTL_BUSYHANDLER]
2024 ** file-control may be invoked by SQLite on the database file handle
2025 ** shortly after it is opened in order to provide a custom VFS with access
2026 ** to the connections busy-handler callback. The argument is of type (void **)
2027 ** - an array of two (void *) values. The first (void *) actually points
2028 ** to a function of type (int (*)(void *)). In order to invoke the connections
2029 ** busy-handler, this function should be invoked with the second (void *) in
2030 ** the array as the only argument. If it returns non-zero, then the operation
2031 ** should be retried. If it returns zero, the custom VFS should abandon the
2032 ** current operation.
2033 **
2034 ** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
2035 ** ^Application can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
2036 ** to have SQLite generate a
2037 ** temporary filename using the same algorithm that is followed to generate
2038 ** temporary filenames for TEMP tables and other internal uses. The
2039 ** argument should be a char** which will be filled with the filename
2040 ** written into memory obtained from [sqlite3_malloc()]. The caller should
@@ -2143,11 +2144,11 @@
2143 ** interface can be used to find if any database on the connection has changed,
2144 ** but that interface responds to changes on TEMP as well as MAIN and does
2145 ** not provide a mechanism to detect changes to MAIN only. Also, the
2146 ** [sqlite3_total_changes()] interface responds to internal changes only and
2147 ** omits changes made by other database connections. The
2148 ** [PRAGMA data_version] command provide a mechanism to detect changes to
2149 ** a single attached database that occur due to other database connections,
2150 ** but omits changes implemented by the database connection on which it is
2151 ** called. This file control is the only mechanism to detect changes that
2152 ** happen either internally or externally and that are associated with
2153 ** a particular attached database.
@@ -2231,14 +2232,14 @@
2231 ** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
2232 ** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
2233 ** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6]. Additional fields
2234 ** may be appended to the sqlite3_vfs object and the iVersion value
2235 ** may increase again in future versions of SQLite.
2236 ** Note that the structure
2237 ** of the sqlite3_vfs object changes in the transition from
2238 ** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
2239 ** and yet the iVersion field was not modified.
2240 **
2241 ** The szOsFile field is the size of the subclassed [sqlite3_file]
2242 ** structure used by this VFS. mxPathname is the maximum length of
2243 ** a pathname in this VFS.
2244 **
@@ -2325,11 +2326,11 @@
2325 ** be created, and that it is an error if it already exists.
2326 ** It is <i>not</i> used to indicate the file should be opened
2327 ** for exclusive access.
2328 **
2329 ** ^At least szOsFile bytes of memory are allocated by SQLite
2330 ** to hold the [sqlite3_file] structure passed as the third
2331 ** argument to xOpen. The xOpen method does not have to
2332 ** allocate the structure; it should just fill it in. Note that
2333 ** the xOpen method must set the sqlite3_file.pMethods to either
2334 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
2335 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
@@ -2448,11 +2449,10 @@
2448 ** SQLite.
2449 */
2450 #define SQLITE_ACCESS_EXISTS 0
2451 #define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */
2452 #define SQLITE_ACCESS_READ 2 /* Unused */
2453 #define SQLITE_ACCESS_SYMLINK 3 /* Test if file is symbolic link */
2454
2455 /*
2456 ** CAPI3REF: Flags for the xShmLock VFS method
2457 **
2458 ** These integer constants define the various locking operations
@@ -2663,11 +2663,11 @@
2663 ** Every memory allocation request coming in through [sqlite3_malloc()]
2664 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
2665 ** that causes the corresponding memory allocation to fail.
2666 **
2667 ** The xInit method initializes the memory allocator. For example,
2668 ** it might allocate any require mutexes or initialize internal data
2669 ** structures. The xShutdown method is invoked (indirectly) by
2670 ** [sqlite3_shutdown()] and should deallocate any resources acquired
2671 ** by xInit. The pAppData pointer is used as the only parameter to
2672 ** xInit and xShutdown.
2673 **
@@ -2804,11 +2804,11 @@
2804 **
2805 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
2806 ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
2807 ** that SQLite can use for the database page cache with the default page
2808 ** cache implementation.
2809 ** This configuration option is a no-op if an application-define page
2810 ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2].
2811 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
2812 ** 8-byte aligned memory (pMem), the size of each page cache line (sz),
2813 ** and the number of cache lines (N).
2814 ** The sz argument should be the size of the largest database page
@@ -3289,11 +3289,11 @@
3289 ** </dd>
3290 **
3291 ** [[SQLITE_DBCONFIG_DQS_DML]]
3292 ** <dt>SQLITE_DBCONFIG_DQS_DML</td>
3293 ** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
3294 ** the legacy [double-quoted string literal] misfeature for DML statement
3295 ** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The
3296 ** default value of this setting is determined by the [-DSQLITE_DQS]
3297 ** compile-time option.
3298 ** </dd>
3299 **
@@ -3550,11 +3550,11 @@
3550 ** will be rolled back automatically.
3551 **
3552 ** ^The sqlite3_interrupt(D) call is in effect until all currently running
3553 ** SQL statements on [database connection] D complete. ^Any new SQL statements
3554 ** that are started after the sqlite3_interrupt() call and before the
3555 ** running statements reaches zero are interrupted as if they had been
3556 ** running prior to the sqlite3_interrupt() call. ^New SQL statements
3557 ** that are started after the running statement count reaches zero are
3558 ** not effected by the sqlite3_interrupt().
3559 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
3560 ** SQL statements is a no-op and has no effect on SQL statements
@@ -3718,13 +3718,13 @@
3718 ** Alice | 43
3719 ** Bob | 28
3720 ** Cindy | 21
3721 ** </pre></blockquote>
3722 **
3723 ** There are two column (M==2) and three rows (N==3). Thus the
3724 ** result table has 8 entries. Suppose the result table is stored
3725 ** in an array names azResult. Then azResult holds this content:
3726 **
3727 ** <blockquote><pre>
3728 ** azResult&#91;0] = "Name";
3729 ** azResult&#91;1] = "Age";
3730 ** azResult&#91;2] = "Alice";
@@ -3874,23 +3874,10 @@
3874 ** sqlite3_malloc64(), and sqlite3_realloc64()
3875 ** is always aligned to at least an 8 byte boundary, or to a
3876 ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
3877 ** option is used.
3878 **
3879 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
3880 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
3881 ** implementation of these routines to be omitted. That capability
3882 ** is no longer provided. Only built-in memory allocators can be used.
3883 **
3884 ** Prior to SQLite version 3.7.10, the Windows OS interface layer called
3885 ** the system malloc() and free() directly when converting
3886 ** filenames between the UTF-8 encoding used by SQLite
3887 ** and whatever filename encoding is used by the particular Windows
3888 ** installation. Memory allocation errors were detected, but
3889 ** they were reported back as [SQLITE_CANTOPEN] or
3890 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
3891 **
3892 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
3893 ** must be either NULL or else pointers obtained from a prior
3894 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
3895 ** not yet been released.
3896 **
@@ -3935,11 +3922,11 @@
3935 ** CAPI3REF: Pseudo-Random Number Generator
3936 **
3937 ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
3938 ** select random [ROWID | ROWIDs] when inserting new records into a table that
3939 ** already uses the largest possible [ROWID]. The PRNG is also used for
3940 ** the build-in random() and randomblob() SQL functions. This interface allows
3941 ** applications to access the same PRNG for other purposes.
3942 **
3943 ** ^A call to this routine stores N bytes of randomness into buffer P.
3944 ** ^The P parameter can be a NULL pointer.
3945 **
@@ -4536,11 +4523,11 @@
4536 ** a VFS implementation when the flags parameter to xOpen() has one or
4537 ** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and
4538 ** P is the name of the query parameter, then
4539 ** sqlite3_uri_parameter(F,P) returns the value of the P
4540 ** parameter if it exists or a NULL pointer if P does not appear as a
4541 ** query parameter on F. If P is a query parameter of F
4542 ** has no explicit value, then sqlite3_uri_parameter(F,P) returns
4543 ** a pointer to an empty string.
4544 **
4545 ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
4546 ** parameter and returns true (1) or false (0) according to the value
@@ -4548,11 +4535,11 @@
4548 ** value of query parameter P is one of "yes", "true", or "on" in any
4549 ** case or if the value begins with a non-zero number. The
4550 ** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
4551 ** query parameter P is one of "no", "false", or "off" in any case or
4552 ** if the value begins with a numeric zero. If P is not a query
4553 ** parameter on F or if the value of P is does not match any of the
4554 ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
4555 **
4556 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
4557 ** 64-bit signed integer and returns that integer, or D if P does not
4558 ** exist. If the value of P is something other than an integer, then
@@ -4885,16 +4872,16 @@
4885 ** in order to find the underlying cause of the problem. With the "v2" prepare
4886 ** interfaces, the underlying reason for the error is returned immediately.
4887 ** </li>
4888 **
4889 ** <li>
4890 ** ^If the specific value bound to [parameter | host parameter] in the
4891 ** WHERE clause might influence the choice of query plan for a statement,
4892 ** then the statement will be automatically recompiled, as if there had been
4893 ** a schema change, on the first [sqlite3_step()] call following any change
4894 ** to the [sqlite3_bind_text | bindings] of that [parameter].
4895 ** ^The specific value of WHERE-clause [parameter] might influence the
4896 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
4897 ** or [GLOB] operator or if the parameter is compared to an indexed column
4898 ** and the [SQLITE_ENABLE_STAT4] compile-time option is enabled.
4899 ** </li>
4900 ** </ol>
@@ -5399,24 +5386,20 @@
5399 ** the statement, where N is the second function argument.
5400 ** ^The left-most column is column 0 for these routines.
5401 **
5402 ** ^If the Nth column returned by the statement is an expression or
5403 ** subquery and is not a column value, then all of these functions return
5404 ** NULL. ^These routine might also return NULL if a memory allocation error
5405 ** occurs. ^Otherwise, they return the name of the attached database, table,
5406 ** or column that query result column was extracted from.
5407 **
5408 ** ^As with all other SQLite APIs, those whose names end with "16" return
5409 ** UTF-16 encoded strings and the other functions return UTF-8.
5410 **
5411 ** ^These APIs are only available if the library was compiled with the
5412 ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
5413 **
5414 ** If two or more threads call one or more of these routines against the same
5415 ** prepared statement and column at the same time then the results are
5416 ** undefined.
5417 **
5418 ** If two or more threads call one or more
5419 ** [sqlite3_column_database_name | column metadata interfaces]
5420 ** for the same [prepared statement] and result column
5421 ** at the same time then the results are undefined.
5422 */
@@ -5549,11 +5532,11 @@
5549 ** METHOD: sqlite3_stmt
5550 **
5551 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
5552 ** current row of the result set of [prepared statement] P.
5553 ** ^If prepared statement P does not have results ready to return
5554 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
5555 ** interfaces) then sqlite3_data_count(P) returns 0.
5556 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
5557 ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
5558 ** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
5559 ** will return non-zero if previous call to [sqlite3_step](P) returned
@@ -6051,13 +6034,16 @@
6051 ** These constants may be ORed together with the
6052 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
6053 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
6054 ** [sqlite3_create_function_v2()].
6055 **
6056 ** The SQLITE_DETERMINISTIC flag means that the new function will always
6057 ** maps the same inputs into the same output. The abs() function is
6058 ** deterministic, for example, but randomblob() is not.
 
 
 
6059 **
6060 ** The SQLITE_DIRECTONLY flag means that the function may only be invoked
6061 ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs. This is
6062 ** a security feature which is recommended for all
6063 ** [application-defined SQL functions] that have side-effects. This flag
@@ -6132,12 +6118,12 @@
6132 **
6133 ** <b>Details:</b>
6134 **
6135 ** These routines extract type, size, and content information from
6136 ** [protected sqlite3_value] objects. Protected sqlite3_value objects
6137 ** are used to pass parameter information into implementation of
6138 ** [application-defined SQL functions] and [virtual tables].
6139 **
6140 ** These routines work only with [protected sqlite3_value] objects.
6141 ** Any attempt to use these routines on an [unprotected sqlite3_value]
6142 ** is not threadsafe.
6143 **
@@ -6190,11 +6176,11 @@
6190 ** the return value is arbitrary and meaningless.
6191 **
6192 ** ^The sqlite3_value_frombind(X) interface returns non-zero if the
6193 ** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()]
6194 ** interfaces. ^If X comes from an SQL literal value, or a table column,
6195 ** and expression, then sqlite3_value_frombind(X) returns zero.
6196 **
6197 ** Please pay particular attention to the fact that the pointer returned
6198 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
6199 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
6200 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
@@ -6276,12 +6262,12 @@
6276 **
6277 ** Implementations of aggregate SQL functions use this
6278 ** routine to allocate memory for storing their state.
6279 **
6280 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
6281 ** for a particular aggregate function, SQLite
6282 ** allocates N of memory, zeroes out that memory, and returns a pointer
6283 ** to the new memory. ^On second and subsequent calls to
6284 ** sqlite3_aggregate_context() for the same aggregate function instance,
6285 ** the same buffer is returned. Sqlite3_aggregate_context() is normally
6286 ** called once for each invocation of the xStep callback and then one
6287 ** last time when the xFinal callback is invoked. ^(When no rows match
@@ -6294,11 +6280,11 @@
6294 ** when first called if N is less than or equal to zero or if a memory
6295 ** allocate error occurs.
6296 **
6297 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
6298 ** determined by the N parameter on first successful call. Changing the
6299 ** value of N in subsequent call to sqlite3_aggregate_context() within
6300 ** the same aggregate function instance will not resize the memory
6301 ** allocation.)^ Within the xFinal callback, it is customary to set
6302 ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
6303 ** pointless memory allocations occur.
6304 **
@@ -6642,11 +6628,11 @@
6642 ** <li> If A&lt;B THEN B&gt;A.
6643 ** <li> If A&lt;B and B&lt;C then A&lt;C.
6644 ** </ol>
6645 **
6646 ** If a collating function fails any of the above constraints and that
6647 ** collating function is registered and used, then the behavior of SQLite
6648 ** is undefined.
6649 **
6650 ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
6651 ** with the addition that the xDestroy callback is invoked on pArg when
6652 ** the collating function is deleted.
@@ -6969,15 +6955,19 @@
6969
6970 /*
6971 ** CAPI3REF: Return The Filename For A Database Connection
6972 ** METHOD: sqlite3
6973 **
6974 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
6975 ** associated with database N of connection D. ^The main database file
6976 ** has the name "main". If there is no attached database N on the database
6977 ** connection D, or if database N is a temporary or in-memory database, then
6978 ** this function will return either a NULL pointer or an empty string.
 
 
 
 
6979 **
6980 ** ^The filename returned by this function is the output of the
6981 ** xFullPathname method of the [VFS]. ^In other words, the filename
6982 ** will be an absolute pathname, even if the filename used
6983 ** to open the database originally was a URI or relative pathname.
@@ -7128,19 +7118,23 @@
7128 ** In prior versions of SQLite,
7129 ** sharing was enabled or disabled for each thread separately.
7130 **
7131 ** ^(The cache sharing mode set by this interface effects all subsequent
7132 ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
7133 ** Existing database connections continue use the sharing mode
7134 ** that was in effect at the time they were opened.)^
7135 **
7136 ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
7137 ** successfully. An [error code] is returned otherwise.)^
7138 **
7139 ** ^Shared cache is disabled by default. But this might change in
7140 ** future releases of SQLite. Applications that care about shared
7141 ** cache setting should set it explicitly.
 
 
 
 
7142 **
7143 ** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0
7144 ** and will always return SQLITE_MISUSE. On those systems,
7145 ** shared cache mode should be enabled per-database connection via
7146 ** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
@@ -7269,11 +7263,11 @@
7269 ** information about column C of table T in database D
7270 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
7271 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
7272 ** the final five arguments with appropriate values if the specified
7273 ** column exists. ^The sqlite3_table_column_metadata() interface returns
7274 ** SQLITE_ERROR and if the specified column does not exist.
7275 ** ^If the column-name parameter to sqlite3_table_column_metadata() is a
7276 ** NULL pointer, then this routine simply checks for the existence of the
7277 ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
7278 ** does not. If the table name parameter T in a call to
7279 ** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is
@@ -7411,11 +7405,11 @@
7411 ** [sqlite3_load_extension()] and the SQL function [load_extension()].
7412 ** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
7413 ** to enable or disable only the C-API.)^
7414 **
7415 ** <b>Security warning:</b> It is recommended that extension loading
7416 ** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
7417 ** rather than this interface, so the [load_extension()] SQL function
7418 ** remains disabled. This will prevent SQL injections from giving attackers
7419 ** access to extension loading capabilities.
7420 */
7421 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
@@ -7498,11 +7492,11 @@
7498 /*
7499 ** CAPI3REF: Virtual Table Object
7500 ** KEYWORDS: sqlite3_module {virtual table module}
7501 **
7502 ** This structure, sometimes called a "virtual table module",
7503 ** defines the implementation of a [virtual tables].
7504 ** This structure consists mostly of methods for the module.
7505 **
7506 ** ^A virtual table module is created by filling in a persistent
7507 ** instance of this structure and passing a pointer to that instance
7508 ** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
@@ -7595,11 +7589,17 @@
7595 ** The [xBestIndex] method must fill aConstraintUsage[] with information
7596 ** about what parameters to pass to xFilter. ^If argvIndex>0 then
7597 ** the right-hand side of the corresponding aConstraint[] is evaluated
7598 ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
7599 ** is true, then the constraint is assumed to be fully handled by the
7600 ** virtual table and is not checked again by SQLite.)^
 
 
 
 
 
 
7601 **
7602 ** ^The idxNum and idxPtr values are recorded and passed into the
7603 ** [xFilter] method.
7604 ** ^[sqlite3_free()] is used to free idxPtr if and only if
7605 ** needToFreeIdxPtr is true.
@@ -7635,11 +7635,11 @@
7635 ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
7636 ** structure for SQLite [version 3.8.2] ([dateof:3.8.2]).
7637 ** If a virtual table extension is
7638 ** used with an SQLite version earlier than 3.8.2, the results of attempting
7639 ** to read or write the estimatedRows field are undefined (but are likely
7640 ** to included crashing the application). The estimatedRows field should
7641 ** therefore only be used if [sqlite3_libversion_number()] returns a
7642 ** value greater than or equal to 3008002. Similarly, the idxFlags field
7643 ** was added for [version 3.9.0] ([dateof:3.9.0]).
7644 ** It may therefore only be used if
7645 ** sqlite3_libversion_number() returns a value greater than or equal to
@@ -7687,11 +7687,11 @@
7687 #define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */
7688
7689 /*
7690 ** CAPI3REF: Virtual Table Constraint Operator Codes
7691 **
7692 ** These macros defined the allowed values for the
7693 ** [sqlite3_index_info].aConstraint[].op field. Each value represents
7694 ** an operator that is part of a constraint term in the wHERE clause of
7695 ** a query that uses a [virtual table].
7696 */
7697 #define SQLITE_INDEX_CONSTRAINT_EQ 2
@@ -8297,11 +8297,11 @@
8297 ** </ul>)^
8298 **
8299 ** The only difference is that the public sqlite3_XXX functions enumerated
8300 ** above silently ignore any invocations that pass a NULL pointer instead
8301 ** of a valid mutex handle. The implementations of the methods defined
8302 ** by this structure are not required to handle this case, the results
8303 ** of passing a NULL pointer instead of a valid mutex handle are undefined
8304 ** (i.e. it is acceptable to provide an implementation that segfaults if
8305 ** it is passed a NULL pointer).
8306 **
8307 ** The xMutexInit() method must be threadsafe. It must be harmless to
@@ -8770,11 +8770,11 @@
8770 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
8771 ** no space was left in the page cache.</dd>)^
8772 **
8773 ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
8774 ** <dd>This parameter records the largest memory allocation request
8775 ** handed to [pagecache memory allocator]. Only the value returned in the
8776 ** *pHighwater parameter to [sqlite3_status()] is of interest.
8777 ** The value written into the *pCurrent parameter is undefined.</dd>)^
8778 **
8779 ** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt>
8780 ** <dd>No longer used.</dd>
@@ -8846,11 +8846,11 @@
8846 ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
8847 ** <dd>This parameter returns the number of lookaside memory slots currently
8848 ** checked out.</dd>)^
8849 **
8850 ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
8851 ** <dd>This parameter returns the number malloc attempts that were
8852 ** satisfied using lookaside memory. Only the high-water value is meaningful;
8853 ** the current value is always zero.)^
8854 **
8855 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
8856 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
@@ -8928,11 +8928,11 @@
8928 ** <dd>This parameter returns the number of dirty cache entries that have
8929 ** been written to disk in the middle of a transaction due to the page
8930 ** cache overflowing. Transactions are more efficient if they are written
8931 ** to disk all at once. When pages spill mid-transaction, that introduces
8932 ** additional overhead. This parameter can be used help identify
8933 ** inefficiencies that can be resolve by increasing the cache size.
8934 ** </dd>
8935 **
8936 ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
8937 ** <dd>This parameter returns zero for the current value if and only if
8938 ** all foreign key constraints (deferred or immediate) have been
@@ -9017,11 +9017,11 @@
9017 ** If the number of virtual machine operations exceeds 2147483647
9018 ** then the value returned by this statement status code is undefined.
9019 **
9020 ** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
9021 ** <dd>^This is the number of times that the prepare statement has been
9022 ** automatically regenerated due to schema changes or change to
9023 ** [bound parameters] that might affect the query plan.
9024 **
9025 ** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
9026 ** <dd>^This is the number of times that the prepared statement has
9027 ** been run. A single "run" for the purposes of this counter is one
@@ -9188,11 +9188,11 @@
9188 ** NULL if allocating a new page is effectively impossible.
9189 ** </table>
9190 **
9191 ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
9192 ** will only use a createFlag of 2 after a prior call with a createFlag of 1
9193 ** failed.)^ In between the to xFetch() calls, SQLite may
9194 ** attempt to unpin one or more cache pages by spilling the content of
9195 ** pinned pages to disk and synching the operating system disk cache.
9196 **
9197 ** [[the xUnpin() page cache method]]
9198 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
@@ -9506,11 +9506,11 @@
9506 ** application receives an SQLITE_LOCKED error, it may call the
9507 ** sqlite3_unlock_notify() method with the blocked connection handle as
9508 ** the first argument to register for a callback that will be invoked
9509 ** when the blocking connections current transaction is concluded. ^The
9510 ** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
9511 ** call that concludes the blocking connections transaction.
9512 **
9513 ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
9514 ** there is a chance that the blocking connection will have already
9515 ** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
9516 ** If this happens, then the specified callback is invoked immediately,
@@ -9544,11 +9544,11 @@
9544 ** However, the signature of the callback function allows SQLite to pass
9545 ** it an array of void* context pointers. The first argument passed to
9546 ** an unlock-notify callback is a pointer to an array of void* pointers,
9547 ** and the second is the number of entries in the array.
9548 **
9549 ** When a blocking connections transaction is concluded, there may be
9550 ** more than one blocked connection that has registered for an unlock-notify
9551 ** callback. ^If two or more such blocked connections have specified the
9552 ** same callback function, then instead of invoking the callback function
9553 ** multiple times, it is invoked once with the set of void* context pointers
9554 ** specified by the blocked connections bundled together into an array.
@@ -10018,37 +10018,37 @@
10018 ** managed by the prepared statement S and will be automatically freed when
10019 ** S is finalized.
10020 **
10021 ** <dl>
10022 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
10023 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
10024 ** set to the total number of times that the X-th loop has run.</dd>
10025 **
10026 ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
10027 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set
10028 ** to the total number of rows examined by all iterations of the X-th loop.</dd>
10029 **
10030 ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
10031 ** <dd>^The "double" variable pointed to by the T parameter will be set to the
10032 ** query planner's estimate for the average number of rows output from each
10033 ** iteration of the X-th loop. If the query planner's estimates was accurate,
10034 ** then this value will approximate the quotient NVISIT/NLOOP and the
10035 ** product of this value for all prior loops with the same SELECTID will
10036 ** be the NLOOP value for the current loop.
10037 **
10038 ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
10039 ** <dd>^The "const char *" variable pointed to by the T parameter will be set
10040 ** to a zero-terminated UTF-8 string containing the name of the index or table
10041 ** used for the X-th loop.
10042 **
10043 ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
10044 ** <dd>^The "const char *" variable pointed to by the T parameter will be set
10045 ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
10046 ** description for the X-th loop.
10047 **
10048 ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
10049 ** <dd>^The "int" variable pointed to by the T parameter will be set to the
10050 ** "select-id" for the X-th loop. The select-id identifies which query or
10051 ** subquery the loop is part of. The main query has a select-id of zero.
10052 ** The select-id is the same value as is output in the first column
10053 ** of an [EXPLAIN QUERY PLAN] query.
10054 ** </dl>
@@ -10899,11 +10899,11 @@
10899 ** METHOD: sqlite3_session
10900 **
10901 ** The second argument (xFilter) is the "filter callback". For changes to rows
10902 ** in tables that are not attached to the Session object, the filter is called
10903 ** to determine whether changes to the table's rows should be tracked or not.
10904 ** If xFilter returns 0, changes is not tracked. Note that once a table is
10905 ** attached, xFilter will not be called again.
10906 */
10907 SQLITE_API void sqlite3session_table_filter(
10908 sqlite3_session *pSession, /* Session object */
10909 int(*xFilter)(
@@ -11073,11 +11073,11 @@
11073 ** identical.
11074 **
11075 ** It an error if database zFrom does not exist or does not contain the
11076 ** required compatible table.
11077 **
11078 ** If the operation successful, SQLITE_OK is returned. Otherwise, an SQLite
11079 ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
11080 ** may be set to point to a buffer containing an English language error
11081 ** message. It is the responsibility of the caller to free this buffer using
11082 ** sqlite3_free().
11083 */
@@ -11210,11 +11210,11 @@
11210
11211 /*
11212 ** CAPI3REF: Advance A Changeset Iterator
11213 ** METHOD: sqlite3_changeset_iter
11214 **
11215 ** This function may only be used with iterators created by function
11216 ** [sqlite3changeset_start()]. If it is called on an iterator passed to
11217 ** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE
11218 ** is returned and the call has no effect.
11219 **
11220 ** Immediately after an iterator is created by sqlite3changeset_start(), it
@@ -11626,12 +11626,12 @@
11626 ** in the changegroup, then the number of columns and the position of the
11627 ** primary key columns for the table must be consistent. If this is not the
11628 ** case, this function fails with SQLITE_SCHEMA. If the input changeset
11629 ** appears to be corrupt and the corruption is detected, SQLITE_CORRUPT is
11630 ** returned. Or, if an out-of-memory condition occurs during processing, this
11631 ** function returns SQLITE_NOMEM. In all cases, if an error occurs the
11632 ** final contents of the changegroup is undefined.
11633 **
11634 ** If no error occurs, SQLITE_OK is returned.
11635 */
11636 SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
11637
@@ -11802,11 +11802,11 @@
11802 ** [SQLITE_CHANGESET_REPLACE].
11803 ** </dl>
11804 **
11805 ** It is safe to execute SQL statements, including those that write to the
11806 ** table that the callback related to, from within the xConflict callback.
11807 ** This can be used to further customize the applications conflict
11808 ** resolution strategy.
11809 **
11810 ** All changes made by these functions are enclosed in a savepoint transaction.
11811 ** If any other error (aside from a constraint failure when attempting to
11812 ** write to the target database) occurs, then the savepoint transaction is
@@ -12112,11 +12112,11 @@
12112 ** CAPI3REF: Rebase a changeset
12113 ** EXPERIMENTAL
12114 **
12115 ** Argument pIn must point to a buffer containing a changeset nIn bytes
12116 ** in size. This function allocates and populates a buffer with a copy
12117 ** of the changeset rebased rebased according to the configuration of the
12118 ** rebaser object passed as the first argument. If successful, (*ppOut)
12119 ** is set to point to the new buffer containing the rebased changeset and
12120 ** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
12121 ** responsibility of the caller to eventually free the new buffer using
12122 ** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
@@ -12520,11 +12520,11 @@
12520 ** the callback, an SQLite error code is returned.
12521 **
12522 **
12523 ** xSetAuxdata(pFts5, pAux, xDelete)
12524 **
12525 ** Save the pointer passed as the second argument as the extension functions
12526 ** "auxiliary data". The pointer may then be retrieved by the current or any
12527 ** future invocation of the same fts5 extension function made as part of
12528 ** the same MATCH query using the xGetAuxdata() API.
12529 **
12530 ** Each extension function is allocated a single auxiliary data slot for
@@ -12762,12 +12762,12 @@
12762 ** all instances of "first place" or "1st place" regardless of which form
12763 ** the user specified in the MATCH query text.
12764 **
12765 ** There are several ways to approach this in FTS5:
12766 **
12767 ** <ol><li> By mapping all synonyms to a single token. In this case, the
12768 ** In the above example, this means that the tokenizer returns the
12769 ** same token for inputs "first" and "1st". Say that token is in
12770 ** fact "first", so that when the user inserts the document "I won
12771 ** 1st place" entries are added to the index for tokens "i", "won",
12772 ** "first" and "place". If the user then queries for '1st + place',
12773 ** the tokenizer substitutes "first" for "1st" and the query works
@@ -13435,10 +13435,30 @@
13435 #else
13436 # define ALWAYS(X) (X)
13437 # define NEVER(X) (X)
13438 #endif
13439
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13440 /*
13441 ** Some conditionals are optimizations only. In other words, if the
13442 ** conditionals are replaced with a constant 1 (true) or 0 (false) then
13443 ** the correct answer is still obtained, though perhaps not as quickly.
13444 **
@@ -15149,13 +15169,14 @@
15149 #define OP_VRename 163
15150 #define OP_Pagecount 164
15151 #define OP_MaxPgcnt 165
15152 #define OP_Trace 166
15153 #define OP_CursorHint 167
15154 #define OP_Noop 168
15155 #define OP_Explain 169
15156 #define OP_Abortable 170
 
15157
15158 /* Properties such as "out2" or "jump" that are specified in
15159 ** comments following the "case" for each opcode in the vdbe.c
15160 ** are encoded into bitvectors as follows:
15161 */
@@ -15185,11 +15206,11 @@
15185 /* 128 */ 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x10, 0x00,\
15186 /* 136 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15187 /* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x10, 0x00,\
15188 /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15189 /* 160 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
15190 /* 168 */ 0x00, 0x00, 0x00,}
15191
15192 /* The sqlite3P2Values() routine is able to run faster if it knows
15193 ** the value of the largest JUMP opcode. The smaller the maximum
15194 ** JUMP opcode the better, so the mkopcodeh.tcl script that
15195 ** generated this include file strives to group all JUMP opcodes
@@ -15262,10 +15283,15 @@
15262 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3);
15263 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
15264 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
15265 SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
15266 SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
 
 
 
 
 
15267 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
15268 SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
15269 SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
15270 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
15271 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
@@ -16841,16 +16867,10 @@
16841 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
16842 pArg, 0, xFunc, 0, 0, 0, #zName, }
16843 #define LIKEFUNC(zName, nArg, arg, flags) \
16844 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
16845 (void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} }
16846 #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue) \
16847 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
16848 SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,0,#zName, {0}}
16849 #define AGGREGATE2(zName, nArg, arg, nc, xStep, xFinal, extraFlags) \
16850 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
16851 SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xFinal,0,#zName, {0}}
16852 #define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f) \
16853 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \
16854 SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,xInverse,#zName, {0}}
16855 #define INTERNAL_FUNCTION(zName, nArg, xFunc) \
16856 {nArg, SQLITE_FUNC_INTERNAL|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
@@ -17978,17 +17998,17 @@
17978 ** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences
17979 ** for the result set. The KeyInfo for addrOpenEphm[2] contains collating
17980 ** sequences for the ORDER BY clause.
17981 */
17982 struct Select {
17983 ExprList *pEList; /* The fields of the result */
17984 u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
17985 LogEst nSelectRow; /* Estimated number of result rows */
17986 u32 selFlags; /* Various SF_* values */
17987 int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */
17988 u32 selId; /* Unique identifier number for this SELECT */
17989 int addrOpenEphm[2]; /* OP_OpenEphem opcodes related to this select */
 
17990 SrcList *pSrc; /* The FROM clause */
17991 Expr *pWhere; /* The WHERE clause */
17992 ExprList *pGroupBy; /* The GROUP BY clause */
17993 Expr *pHaving; /* The HAVING clause */
17994 ExprList *pOrderBy; /* The ORDER BY clause */
@@ -18030,10 +18050,11 @@
18030 #define SF_Converted 0x0010000 /* By convertCompoundSelectToSubquery() */
18031 #define SF_IncludeHidden 0x0020000 /* Include hidden columns in output */
18032 #define SF_ComplexResult 0x0040000 /* Result contains subquery or function */
18033 #define SF_WhereBegin 0x0080000 /* Really a WhereBegin() call. Debug Only */
18034 #define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */
 
18035
18036 /*
18037 ** The results of a SELECT can be distributed in several ways, as defined
18038 ** by one of the following macros. The "SRT" prefix means "SELECT Result
18039 ** Type".
@@ -18309,12 +18330,12 @@
18309 #endif
18310 };
18311
18312 #define PARSE_MODE_NORMAL 0
18313 #define PARSE_MODE_DECLARE_VTAB 1
18314 #define PARSE_MODE_RENAME_COLUMN 2
18315 #define PARSE_MODE_RENAME_TABLE 3
18316
18317 /*
18318 ** Sizes and pointers of various parts of the Parse object.
18319 */
18320 #define PARSE_HDR_SZ offsetof(Parse,aTempReg) /* Recursive part w/o aColCache*/
@@ -18332,11 +18353,11 @@
18332 #endif
18333
18334 #if defined(SQLITE_OMIT_ALTERTABLE)
18335 #define IN_RENAME_OBJECT 0
18336 #else
18337 #define IN_RENAME_OBJECT (pParse->eParseMode>=PARSE_MODE_RENAME_COLUMN)
18338 #endif
18339
18340 #if defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_OMIT_ALTERTABLE)
18341 #define IN_SPECIAL_PARSE 0
18342 #else
@@ -19151,10 +19172,11 @@
19151 SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
19152 SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
19153 SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
19154 Expr*,ExprList*,u32,Expr*);
19155 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3*, Select*);
 
19156 SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*);
19157 SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, int);
19158 SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
19159 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
19160 SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,char*);
@@ -20734,11 +20756,11 @@
20734 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
20735 SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem*, int ifNull);
20736 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
20737 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
20738 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
20739 SQLITE_PRIVATE void sqlite3VdbeMemCast(Mem*,u8,u8);
20740 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);
20741 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
20742 SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
20743 #ifndef SQLITE_OMIT_WINDOWFUNC
20744 SQLITE_PRIVATE int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*);
@@ -22654,11 +22676,11 @@
22654 DO_OS_MALLOC_TEST(0);
22655 /* 0x87f7f is a mask of SQLITE_OPEN_ flags that are valid to be passed
22656 ** down into the VFS layer. Some SQLITE_OPEN_ flags (for example,
22657 ** SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_SHAREDCACHE) are blocked before
22658 ** reaching the VFS. */
22659 rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x87f7f, pFlagsOut);
22660 assert( rc==SQLITE_OK || pFile->pMethods==0 );
22661 return rc;
22662 }
22663 SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
22664 DO_OS_MALLOC_TEST(0);
@@ -29289,12 +29311,13 @@
29289 zOp2[0] = 0;
29290 }
29291 sqlite3TreeViewLine(pView, "COLUMN(%d)%s%s",
29292 pExpr->iColumn, zFlgs, zOp2);
29293 }else{
29294 sqlite3TreeViewLine(pView, "{%d:%d}%s",
29295 pExpr->iTable, pExpr->iColumn, zFlgs);
 
29296 }
29297 if( ExprHasProperty(pExpr, EP_FixedCol) ){
29298 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
29299 }
29300 break;
@@ -30961,11 +30984,11 @@
30961 #pragma warning(disable : 4756)
30962 #endif
30963 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){
30964 #ifndef SQLITE_OMIT_FLOATING_POINT
30965 int incr;
30966 const char *zEnd = z + length;
30967 /* sign * significand * (10 ^ (esign * exponent)) */
30968 int sign = 1; /* sign of significand */
30969 i64 s = 0; /* significand */
30970 int d = 0; /* adjust exponent for shifting decimal point */
30971 int esign = 1; /* sign of exponent */
@@ -30975,13 +30998,15 @@
30975 int nDigit = 0; /* Number of digits processed */
30976 int eType = 1; /* 1: pure integer, 2+: fractional -1 or less: bad UTF16 */
30977
30978 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
30979 *pResult = 0.0; /* Default return value, in case of an error */
 
30980
30981 if( enc==SQLITE_UTF8 ){
30982 incr = 1;
 
30983 }else{
30984 int i;
30985 incr = 2;
30986 assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
30987 testcase( enc==SQLITE_UTF16LE );
@@ -32660,13 +32685,14 @@
32660 /* 163 */ "VRename" OpHelp(""),
32661 /* 164 */ "Pagecount" OpHelp(""),
32662 /* 165 */ "MaxPgcnt" OpHelp(""),
32663 /* 166 */ "Trace" OpHelp(""),
32664 /* 167 */ "CursorHint" OpHelp(""),
32665 /* 168 */ "Noop" OpHelp(""),
32666 /* 169 */ "Explain" OpHelp(""),
32667 /* 170 */ "Abortable" OpHelp(""),
 
32668 };
32669 return azName[i];
32670 }
32671 #endif
32672
@@ -36555,11 +36581,11 @@
36555 zDirname[ii] = '\0';
36556 }else{
36557 if( zDirname[0]!='/' ) zDirname[0] = '.';
36558 zDirname[1] = 0;
36559 }
36560 fd = robust_open(zDirname, O_RDONLY|O_BINARY, 0);
36561 if( fd>=0 ){
36562 OSTRACE(("OPENDIR %-3d %s\n", fd, zDirname));
36563 }
36564 *pFd = fd;
36565 if( fd>=0 ) return SQLITE_OK;
@@ -37446,14 +37472,16 @@
37446 }
37447 }
37448
37449 if( pInode->bProcessLock==0 ){
37450 if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
37451 pShmNode->hShm = robust_open(zShm, O_RDWR|O_CREAT,(sStat.st_mode&0777));
 
37452 }
37453 if( pShmNode->hShm<0 ){
37454 pShmNode->hShm = robust_open(zShm, O_RDONLY, (sStat.st_mode&0777));
 
37455 if( pShmNode->hShm<0 ){
37456 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShm);
37457 goto shm_open_err;
37458 }
37459 pShmNode->isReadonly = 1;
@@ -38799,11 +38827,11 @@
38799 int *pOutFlags /* Output flags returned to SQLite core */
38800 ){
38801 unixFile *p = (unixFile *)pFile;
38802 int fd = -1; /* File descriptor returned by open() */
38803 int openFlags = 0; /* Flags to pass to open() */
38804 int eType = flags&0xFFFFFF00; /* Type of file to open */
38805 int noLock; /* True to omit locking primitives */
38806 int rc = SQLITE_OK; /* Function Return Code */
38807 int ctrlFlags = 0; /* UNIXFILE_* flags */
38808
38809 int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE);
@@ -38909,11 +38937,11 @@
38909 ** 'conch file' locking functions later on. */
38910 if( isReadonly ) openFlags |= O_RDONLY;
38911 if( isReadWrite ) openFlags |= O_RDWR;
38912 if( isCreate ) openFlags |= O_CREAT;
38913 if( isExclusive ) openFlags |= (O_EXCL|O_NOFOLLOW);
38914 openFlags |= (O_LARGEFILE|O_BINARY);
38915
38916 if( fd<0 ){
38917 mode_t openMode; /* Permissions to create file with */
38918 uid_t uid; /* Userid for the file */
38919 gid_t gid; /* Groupid for the file */
@@ -39121,29 +39149,20 @@
39121 ){
39122 UNUSED_PARAMETER(NotUsed);
39123 SimulateIOError( return SQLITE_IOERR_ACCESS; );
39124 assert( pResOut!=0 );
39125
39126 /* The spec says there are four possible values for flags. But the
39127 ** SQLITE_ACCESS_READ flag is never used */
39128 assert( flags==SQLITE_ACCESS_EXISTS
39129 || flags==SQLITE_ACCESS_READWRITE
39130 || flags==SQLITE_ACCESS_SYMLINK );
39131
39132 if( flags==SQLITE_ACCESS_EXISTS ){
39133 struct stat buf;
39134 *pResOut = (0==osStat(zPath, &buf) && buf.st_size>0);
39135 }else if( flags==SQLITE_ACCESS_READWRITE ){
 
39136 *pResOut = osAccess(zPath, W_OK|R_OK)==0;
39137 }else{
39138 #if !defined(HAVE_LSTAT)
39139 *pResOut = 0;
39140 #else
39141 struct stat buf;
39142 *pResOut = (0==osLstat(zPath, &buf) && S_ISLNK(buf.st_mode));
39143 #endif
39144 assert( flags==SQLITE_ACCESS_SYMLINK );
39145 }
39146 return SQLITE_OK;
39147 }
39148
39149 /*
@@ -39191,11 +39210,11 @@
39191 #if !defined(HAVE_READLINK) || !defined(HAVE_LSTAT)
39192 return mkFullPathname(zPath, zOut, nOut);
39193 #else
39194 int rc = SQLITE_OK;
39195 int nByte;
39196 int nLink = 1; /* Number of symbolic links followed so far */
39197 const char *zIn = zPath; /* Input path for each iteration of loop */
39198 char *zDel = 0;
39199
39200 assert( pVfs->mxPathname==MAX_PATHNAME );
39201 UNUSED_PARAMETER(pVfs);
@@ -39220,14 +39239,15 @@
39220 }else{
39221 bLink = S_ISLNK(buf.st_mode);
39222 }
39223
39224 if( bLink ){
 
39225 if( zDel==0 ){
39226 zDel = sqlite3_malloc(nOut);
39227 if( zDel==0 ) rc = SQLITE_NOMEM_BKPT;
39228 }else if( ++nLink>SQLITE_MAX_SYMLINKS ){
39229 rc = SQLITE_CANTOPEN_BKPT;
39230 }
39231
39232 if( rc==SQLITE_OK ){
39233 nByte = osReadlink(zIn, zDel, nOut-1);
@@ -39259,10 +39279,11 @@
39259 if( bLink==0 ) break;
39260 zIn = zOut;
39261 }while( rc==SQLITE_OK );
39262
39263 sqlite3_free(zDel);
 
39264 return rc;
39265 #endif /* HAVE_READLINK && HAVE_LSTAT */
39266 }
39267
39268
@@ -39744,11 +39765,11 @@
39744 int islockfile /* if non zero missing dirs will be created */
39745 ) {
39746 int fd = -1;
39747 unixFile *pNew;
39748 int rc = SQLITE_OK;
39749 int openFlags = O_RDWR | O_CREAT;
39750 sqlite3_vfs dummyVfs;
39751 int terrno = 0;
39752 UnixUnusedFd *pUnused = NULL;
39753
39754 /* 1. first try to open/create the file
@@ -39774,11 +39795,11 @@
39774 fd = robust_open(path, openFlags, 0);
39775 }
39776 }
39777 }
39778 if( fd<0 ){
39779 openFlags = O_RDONLY;
39780 fd = robust_open(path, openFlags, 0);
39781 terrno = errno;
39782 }
39783 if( fd<0 ){
39784 if( islockfile ){
@@ -39900,11 +39921,11 @@
39900 if( readLen<PROXY_PATHINDEX ){
39901 sqlite3_snprintf(sizeof(errmsg),errmsg,"read error (len %d)",(int)readLen);
39902 goto end_breaklock;
39903 }
39904 /* write it out to the temporary break file */
39905 fd = robust_open(tPath, (O_RDWR|O_CREAT|O_EXCL), 0);
39906 if( fd<0 ){
39907 sqlite3_snprintf(sizeof(errmsg), errmsg, "create failed (%d)", errno);
39908 goto end_breaklock;
39909 }
39910 if( osPwrite(fd, buf, readLen, 0) != (ssize_t)readLen ){
@@ -41060,18 +41081,10 @@
41060
41061 #ifndef NTDDI_WINTHRESHOLD
41062 # define NTDDI_WINTHRESHOLD 0x06040000
41063 #endif
41064
41065 /*
41066 ** This constant is needed by the winAccess function; therefore, define
41067 ** it when it is missing from the SDK header files.
41068 */
41069 #ifndef FILE_ATTRIBUTE_REPARSE_POINT
41070 # define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
41071 #endif
41072
41073 /*
41074 ** Check to see if the GetVersionEx[AW] functions are deprecated on the
41075 ** target system. GetVersionEx was first deprecated in Win8.1.
41076 */
41077 #ifndef SQLITE_WIN32_GETVERSIONEX
@@ -46460,14 +46473,10 @@
46460 break;
46461 case SQLITE_ACCESS_READWRITE:
46462 rc = attr!=INVALID_FILE_ATTRIBUTES &&
46463 (attr & FILE_ATTRIBUTE_READONLY)==0;
46464 break;
46465 case SQLITE_ACCESS_SYMLINK:
46466 rc = attr!=INVALID_FILE_ATTRIBUTES &&
46467 (attr & FILE_ATTRIBUTE_REPARSE_POINT)!=0;
46468 break;
46469 default:
46470 assert(!"Invalid flags argument");
46471 }
46472 *pResOut = rc;
46473 OSTRACE(("ACCESS name=%s, pResOut=%p, *pResOut=%d, rc=SQLITE_OK\n",
@@ -49503,17 +49512,19 @@
49503 sqlite3_free(p);
49504 pPg = 0;
49505 }
49506 #else
49507 pPg = pcache1Alloc(pCache->szAlloc);
49508 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
49509 #endif
49510 if( benignMalloc ){ sqlite3EndBenignMalloc(); }
49511 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
49512 pcache1EnterMutex(pCache->pGroup);
49513 #endif
49514 if( pPg==0 ) return 0;
 
 
 
49515 p->page.pBuf = pPg;
49516 p->page.pExtra = &p[1];
49517 p->isBulkLocal = 0;
49518 p->isAnchor = 0;
49519 }
@@ -55782,31 +55793,34 @@
55782 ** to by zPathname, length nPathname. Or, if this is a temporary file,
55783 ** leave both nPathname and zPathname set to 0.
55784 */
55785 if( zFilename && zFilename[0] ){
55786 const char *z;
55787 if( (vfsFlags & SQLITE_OPEN_NOFOLLOW)!=0 ){
55788 int isLink = 0;
55789 int rc = sqlite3OsAccess(pVfs, zFilename, SQLITE_ACCESS_SYMLINK, &isLink);
55790 if( rc==SQLITE_OK && isLink ) rc = SQLITE_CANTOPEN_SYMLINK;
55791 if( rc ) return rc;
55792 }
55793 nPathname = pVfs->mxPathname+1;
55794 zPathname = sqlite3DbMallocRaw(0, nPathname*2);
55795 if( zPathname==0 ){
55796 return SQLITE_NOMEM_BKPT;
55797 }
55798 zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
55799 rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
 
 
 
 
 
 
 
 
 
55800 nPathname = sqlite3Strlen30(zPathname);
55801 z = zUri = &zFilename[sqlite3Strlen30(zFilename)+1];
55802 while( *z ){
55803 z += strlen(z)+1;
55804 z += strlen(z)+1;
55805 nUri++;
55806 }
55807 nUriByte = (int)(&z[2] - zUri);
55808 assert( nUriByte>=1 );
55809 if( rc==SQLITE_OK && nPathname+8>pVfs->mxPathname ){
55810 /* This branch is taken when the journal path required by
55811 ** the database being opened will be more than pVfs->mxPathname
55812 ** bytes in length. This means the database cannot be opened,
@@ -57616,10 +57630,11 @@
57616
57617 /* This routine should not be called if a prior error has occurred.
57618 ** But if (due to a coding error elsewhere in the system) it does get
57619 ** called, just return the same error code without doing anything. */
57620 if( NEVER(pPager->errCode) ) return pPager->errCode;
 
57621
57622 assert( pPager->eState==PAGER_WRITER_LOCKED
57623 || pPager->eState==PAGER_WRITER_FINISHED
57624 || (pagerUseWal(pPager) && pPager->eState==PAGER_WRITER_CACHEMOD)
57625 );
@@ -57644,11 +57659,10 @@
57644 pPager->eState = PAGER_READER;
57645 return SQLITE_OK;
57646 }
57647
57648 PAGERTRACE(("COMMIT %d\n", PAGERID(pPager)));
57649 pPager->iDataVersion++;
57650 rc = pager_end_transaction(pPager, pPager->setMaster, 1);
57651 return pager_error(pPager, rc);
57652 }
57653
57654 /*
@@ -60565,11 +60579,23 @@
60565 ** of the aReadMark[] slot. The assumption here is that if that is
60566 ** happening, the other client may only be increasing the value,
60567 ** not decreasing it. So assuming either that either the "old" or
60568 ** "new" version of the value is read, and not some arbitrary value
60569 ** that would never be written by a real client, things are still
60570 ** safe. */
 
 
 
 
 
 
 
 
 
 
 
 
60571 u32 y = pInfo->aReadMark[i];
60572 if( mxSafeFrame>y ){
60573 assert( y<=pWal->hdr.mxFrame );
60574 rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1);
60575 if( rc==SQLITE_OK ){
@@ -66021,13 +66047,17 @@
66021 memcpy(zFullPathname, zFilename, nFilename);
66022 }else{
66023 rc = sqlite3OsFullPathname(pVfs, zFilename,
66024 nFullPathname, zFullPathname);
66025 if( rc ){
66026 sqlite3_free(zFullPathname);
66027 sqlite3_free(p);
66028 return rc;
 
 
 
 
66029 }
66030 }
66031 #if SQLITE_THREADSAFE
66032 mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN);
66033 sqlite3_mutex_enter(mutexOpen);
@@ -69332,12 +69362,15 @@
69332
69333 /* If the database file is corrupt, it is possible for the value of idx
69334 ** to be invalid here. This can only occur if a second cursor modifies
69335 ** the page while cursor pCur is holding a reference to it. Which can
69336 ** only happen if the database is corrupt in such a way as to link the
69337 ** page into more than one b-tree structure. */
69338 testcase( idx>pPage->nCell );
 
 
 
69339
69340 if( idx>=pPage->nCell ){
69341 if( !pPage->leaf ){
69342 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
69343 if( rc ) return rc;
@@ -71921,10 +71954,34 @@
71921 put4byte(&pRoot->aData[pRoot->hdrOffset+8], pgnoChild);
71922
71923 *ppChild = pChild;
71924 return SQLITE_OK;
71925 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71926
71927 /*
71928 ** The page that pCur currently points to has just been modified in
71929 ** some way. This function figures out if this modification means the
71930 ** tree needs to be balanced, and if so calls the appropriate balancing
@@ -71949,11 +72006,11 @@
71949
71950 if( NEVER(pPage->nFree<0) && btreeComputeFreeSpace(pPage) ) break;
71951 if( pPage->nOverflow==0 && pPage->nFree<=nMin ){
71952 break;
71953 }else if( (iPage = pCur->iPage)==0 ){
71954 if( pPage->nOverflow ){
71955 /* The root page of the b-tree is overfull. In this case call the
71956 ** balance_deeper() function to create a new child for the root-page
71957 ** and copy the current contents of the root-page to it. The
71958 ** next iteration of the do-loop will balance the child page.
71959 */
@@ -72320,11 +72377,13 @@
72320 return btreeOverwriteCell(pCur, &x2);
72321 }
72322 }
72323
72324 }
72325 assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
 
 
72326
72327 pPage = pCur->pPage;
72328 assert( pPage->intKey || pX->nKey>=0 );
72329 assert( pPage->leaf || !pPage->intKey );
72330 if( pPage->nFree<0 ){
@@ -75489,12 +75548,11 @@
75489 if( flags & (MEM_Int|MEM_IntReal) ){
75490 testcase( flags & MEM_IntReal );
75491 return pMem->u.i;
75492 }else if( flags & MEM_Real ){
75493 return doubleToInt64(pMem->u.r);
75494 }else if( flags & (MEM_Str|MEM_Blob) ){
75495 assert( pMem->z || pMem->n==0 );
75496 return memIntValue(pMem);
75497 }else{
75498 return 0;
75499 }
75500 }
@@ -75647,12 +75705,12 @@
75647 ** "aff". Casting is different from applying affinity in that a cast
75648 ** is forced. In other words, the value is converted into the desired
75649 ** affinity even if that results in loss of data. This routine is
75650 ** used (for example) to implement the SQL "cast()" operator.
75651 */
75652 SQLITE_PRIVATE void sqlite3VdbeMemCast(Mem *pMem, u8 aff, u8 encoding){
75653 if( pMem->flags & MEM_Null ) return;
75654 switch( aff ){
75655 case SQLITE_AFF_BLOB: { /* Really a cast to BLOB */
75656 if( (pMem->flags & MEM_Blob)==0 ){
75657 sqlite3ValueApplyAffinity(pMem, SQLITE_AFF_TEXT, encoding);
75658 assert( pMem->flags & MEM_Str || pMem->db->mallocFailed );
@@ -75679,13 +75737,14 @@
75679 assert( MEM_Str==(MEM_Blob>>3) );
75680 pMem->flags |= (pMem->flags&MEM_Blob)>>3;
75681 sqlite3ValueApplyAffinity(pMem, SQLITE_AFF_TEXT, encoding);
75682 assert( pMem->flags & MEM_Str || pMem->db->mallocFailed );
75683 pMem->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal|MEM_Blob|MEM_Zero);
75684 break;
75685 }
75686 }
 
75687 }
75688
75689 /*
75690 ** Initialize bulk memory to be a consistent Mem object.
75691 **
@@ -77454,10 +77513,11 @@
77454 **
77455 ** * OP_Halt with P1=SQLITE_CONSTRAINT and P2=OE_Abort.
77456 ** * OP_HaltIfNull with P1=SQLITE_CONSTRAINT and P2=OE_Abort.
77457 ** * OP_Destroy
77458 ** * OP_VUpdate
 
77459 ** * OP_VRename
77460 ** * OP_FkCounter with P2==0 (immediate foreign key constraint)
77461 ** * OP_CreateBtree/BTREE_INTKEY and OP_InitCoroutine
77462 ** (for CREATE TABLE AS SELECT ...)
77463 **
@@ -77481,10 +77541,11 @@
77481
77482 while( (pOp = opIterNext(&sIter))!=0 ){
77483 int opcode = pOp->opcode;
77484 if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
77485 || opcode==OP_VDestroy
 
77486 || (opcode==OP_ParseSchema && pOp->p4.z==0)
77487 || ((opcode==OP_Halt || opcode==OP_HaltIfNull)
77488 && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
77489 ){
77490 hasAbort = 1;
@@ -77970,10 +78031,33 @@
77970 return sqlite3VdbeChangeToNoop(p, p->nOp-1);
77971 }else{
77972 return 0;
77973 }
77974 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77975
77976 /*
77977 ** Change the value of the P4 operand for a specific instruction.
77978 ** This routine is useful when a large program is loaded from a
77979 ** static array using sqlite3VdbeAddOpList but we want to make a
@@ -78088,11 +78172,12 @@
78088 ** makes the code easier to read during debugging. None of this happens
78089 ** in a production build.
78090 */
78091 static void vdbeVComment(Vdbe *p, const char *zFormat, va_list ap){
78092 assert( p->nOp>0 || p->aOp==0 );
78093 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed );
 
78094 if( p->nOp ){
78095 assert( p->aOp );
78096 sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment);
78097 p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap);
78098 }
@@ -86128,13 +86213,15 @@
86128 testcase( pOp->p2==SQLITE_AFF_INTEGER );
86129 testcase( pOp->p2==SQLITE_AFF_REAL );
86130 pIn1 = &aMem[pOp->p1];
86131 memAboutToChange(p, pIn1);
86132 rc = ExpandBlob(pIn1);
86133 sqlite3VdbeMemCast(pIn1, pOp->p2, encoding);
 
 
86134 UPDATE_MAX_BLOBSIZE(pIn1);
86135 if( rc ) goto abort_due_to_error;
86136 break;
86137 }
86138 #endif /* SQLITE_OMIT_CAST */
86139
86140 /* Opcode: Eq P1 P2 P3 P4 P5
@@ -86289,16 +86376,11 @@
86289 affinity = pOp->p5 & SQLITE_AFF_MASK;
86290 if( affinity>=SQLITE_AFF_NUMERIC ){
86291 if( (flags1 | flags3)&MEM_Str ){
86292 if( (flags1 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
86293 applyNumericAffinity(pIn1,0);
86294 assert( flags3==pIn3->flags );
86295 /* testcase( flags3!=pIn3->flags );
86296 ** this used to be possible with pIn1==pIn3, but not since
86297 ** the column cache was removed. The following assignment
86298 ** is essentially a no-op. But, it provides defense-in-depth
86299 ** in case our analysis is incorrect, so it is left in. */
86300 flags3 = pIn3->flags;
86301 }
86302 if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
86303 applyNumericAffinity(pIn3,0);
86304 }
@@ -86317,11 +86399,11 @@
86317 testcase( pIn1->flags & MEM_Real );
86318 testcase( pIn1->flags & MEM_IntReal );
86319 sqlite3VdbeMemStringify(pIn1, encoding, 1);
86320 testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
86321 flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
86322 assert( pIn1!=pIn3 );
86323 }
86324 if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
86325 testcase( pIn3->flags & MEM_Int );
86326 testcase( pIn3->flags & MEM_Real );
86327 testcase( pIn3->flags & MEM_IntReal );
@@ -86352,14 +86434,14 @@
86352 static const unsigned char aGTb[] = { 1, 0, 1, 0, 0, 1 };
86353 res2 = aGTb[pOp->opcode - OP_Ne];
86354 }
86355
86356 /* Undo any changes made by applyAffinity() to the input registers. */
 
 
86357 assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
86358 pIn1->flags = flags1;
86359 assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
86360 pIn3->flags = flags3;
86361
86362 if( pOp->p5 & SQLITE_STOREP2 ){
86363 pOut = &aMem[pOp->p2];
86364 iCompare = res;
86365 if( (pOp->p5 & SQLITE_KEEPNULL)!=0 ){
@@ -86391,20 +86473,35 @@
86391 break;
86392 }
86393
86394 /* Opcode: ElseNotEq * P2 * * *
86395 **
86396 ** This opcode must immediately follow an OP_Lt or OP_Gt comparison operator.
86397 ** If result of an OP_Eq comparison on the same two operands
86398 ** would have be NULL or false (0), then then jump to P2.
86399 ** If the result of an OP_Eq comparison on the two previous operands
86400 ** would have been true (1), then fall through.
 
 
 
 
 
86401 */
86402 case OP_ElseNotEq: { /* same as TK_ESCAPE, jump */
86403 assert( pOp>aOp );
86404 assert( pOp[-1].opcode==OP_Lt || pOp[-1].opcode==OP_Gt );
86405 assert( pOp[-1].p5 & SQLITE_STOREP2 );
 
 
 
 
 
 
 
 
 
 
86406 VdbeBranchTaken(iCompare!=0, 2);
86407 if( iCompare!=0 ) goto jump_to_p2;
86408 break;
86409 }
86410
@@ -86811,11 +86908,13 @@
86811 const u8 *zEndHdr; /* Pointer to first byte after the header */
86812 u64 offset64; /* 64-bit offset */
86813 u32 t; /* A type code from the record header */
86814 Mem *pReg; /* PseudoTable input register */
86815
 
86816 pC = p->apCsr[pOp->p1];
 
86817 p2 = pOp->p2;
86818
86819 /* If the cursor cache is stale (meaning it is not currently point at
86820 ** the correct row) then bring it up-to-date by doing the necessary
86821 ** B-Tree seek. */
@@ -86823,11 +86922,10 @@
86823 if( rc ) goto abort_due_to_error;
86824
86825 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
86826 pDest = &aMem[pOp->p3];
86827 memAboutToChange(p, pDest);
86828 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
86829 assert( pC!=0 );
86830 assert( p2<pC->nField );
86831 aOffset = pC->aOffset;
86832 assert( pC->eCurType!=CURTYPE_VTAB );
86833 assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow );
@@ -87080,11 +87178,11 @@
87080 assert( pOp->p2>0 );
87081 assert( zAffinity[pOp->p2]==0 );
87082 pIn1 = &aMem[pOp->p1];
87083 while( 1 /*exit-by-break*/ ){
87084 assert( pIn1 <= &p->aMem[(p->nMem+1 - p->nCursor)] );
87085 assert( memIsValid(pIn1) );
87086 applyAffinity(pIn1, zAffinity[0], encoding);
87087 if( zAffinity[0]==SQLITE_AFF_REAL && (pIn1->flags & MEM_Int)!=0 ){
87088 /* When applying REAL affinity, if the result is still an MEM_Int
87089 ** that will fit in 6 bytes, then change the type to MEM_IntReal
87090 ** so that we keep the high-resolution integer value but know that
@@ -87526,12 +87624,16 @@
87526 p->pc = (int)(pOp - aOp);
87527 db->autoCommit = 0;
87528 p->rc = rc = SQLITE_BUSY;
87529 goto vdbe_return;
87530 }
87531 db->isTransactionSavepoint = 0;
87532 rc = p->rc;
 
 
 
 
 
87533 }else{
87534 int isSchemaChange;
87535 iSavepoint = db->nSavepoint - iSavepoint - 1;
87536 if( p1==SAVEPOINT_ROLLBACK ){
87537 isSchemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0;
@@ -87555,10 +87657,11 @@
87555 sqlite3ExpirePreparedStatements(db, 0);
87556 sqlite3ResetAllSchemasOfConnection(db);
87557 db->mDbFlags |= DBFLAG_SchemaChange;
87558 }
87559 }
 
87560
87561 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
87562 ** savepoints nested inside of the savepoint being operated on. */
87563 while( db->pSavepoint!=pSavepoint ){
87564 pTmp = db->pSavepoint;
@@ -88050,10 +88153,11 @@
88050 case OP_OpenDup: {
88051 VdbeCursor *pOrig; /* The original cursor to be duplicated */
88052 VdbeCursor *pCx; /* The new cursor */
88053
88054 pOrig = p->apCsr[pOp->p2];
 
88055 assert( pOrig->pBtx!=0 ); /* Only ephemeral cursors can be duplicated */
88056
88057 pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE);
88058 if( pCx==0 ) goto no_mem;
88059 pCx->nullRow = 1;
@@ -91479,11 +91583,11 @@
91479 pVtab = pCur->uc.pVCur->pVtab;
91480 pModule = pVtab->pModule;
91481 assert( pModule->xColumn );
91482 memset(&sContext, 0, sizeof(sContext));
91483 sContext.pOut = pDest;
91484 testcase( (pOp->p5 & OPFLAG_NOCHNG)==0 && pOp->p5!=0 );
91485 if( pOp->p5 & OPFLAG_NOCHNG ){
91486 sqlite3VdbeMemSetNull(pDest);
91487 pDest->flags = MEM_Null|MEM_Zero;
91488 pDest->u.nZero = 0;
91489 }else{
@@ -91939,10 +92043,57 @@
91939 case OP_Abortable: {
91940 sqlite3VdbeAssertAbortable(p);
91941 break;
91942 }
91943 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91944
91945 /* Opcode: Noop * * * * *
91946 **
91947 ** Do nothing. This instruction is often useful as a jump
91948 ** destination.
@@ -95849,12 +96000,12 @@
95849 testcase( ExprHasProperty(pExpr, EP_Reduced) );
95850 while(1){
95851 rc = pWalker->xExprCallback(pWalker, pExpr);
95852 if( rc ) return rc & WRC_Abort;
95853 if( !ExprHasProperty(pExpr,(EP_TokenOnly|EP_Leaf)) ){
 
95854 if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
95855 assert( pExpr->x.pList==0 || pExpr->pRight==0 );
95856 if( pExpr->pRight ){
95857 assert( !ExprHasProperty(pExpr, EP_WinFunc) );
95858 pExpr = pExpr->pRight;
95859 continue;
95860 }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
@@ -96538,22 +96689,39 @@
96538 pTopNC->nErr++;
96539 }
96540
96541 /* If a column from a table in pSrcList is referenced, then record
96542 ** this fact in the pSrcList.a[].colUsed bitmask. Column 0 causes
96543 ** bit 0 to be set. Column 1 sets bit 1. And so forth. If the
96544 ** column number is greater than the number of bits in the bitmask
96545 ** then set the high-order bit of the bitmask.
 
 
 
 
 
 
 
 
96546 */
96547 if( pExpr->iColumn>=0 && pMatch!=0 ){
96548 int n = pExpr->iColumn;
96549 testcase( n==BMS-1 );
96550 if( n>=BMS ){
96551 n = BMS-1;
96552 }
96553 assert( pMatch->iCursor==pExpr->iTable );
96554 pMatch->colUsed |= ((Bitmask)1)<<n;
 
 
 
 
 
 
 
 
 
 
 
96555 }
96556
96557 /* Clean up and return
96558 */
96559 sqlite3ExprDelete(db, pExpr->pLeft);
@@ -96588,47 +96756,68 @@
96588 */
96589 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
96590 Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
96591 if( p ){
96592 struct SrcList_item *pItem = &pSrc->a[iSrc];
96593 p->y.pTab = pItem->pTab;
96594 p->iTable = pItem->iCursor;
96595 if( p->y.pTab->iPKey==iCol ){
96596 p->iColumn = -1;
96597 }else{
96598 p->iColumn = (ynVar)iCol;
96599 testcase( iCol==BMS );
96600 testcase( iCol==BMS-1 );
96601 pItem->colUsed |= ((Bitmask)1)<<(iCol>=BMS ? BMS-1 : iCol);
 
 
 
 
 
 
 
 
96602 }
96603 }
96604 return p;
96605 }
96606
96607 /*
96608 ** Report an error that an expression is not valid for some set of
96609 ** pNC->ncFlags values determined by validMask.
 
 
 
 
 
 
 
 
 
 
 
 
96610 */
96611 static void notValid(
96612 Parse *pParse, /* Leave error message here */
96613 NameContext *pNC, /* The name context */
96614 const char *zMsg, /* Type of error */
96615 int validMask /* Set of contexts for which prohibited */
96616 ){
96617 assert( (validMask&~(NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol))==0 );
96618 if( (pNC->ncFlags & validMask)!=0 ){
96619 const char *zIn = "partial index WHERE clauses";
96620 if( pNC->ncFlags & NC_IdxExpr ) zIn = "index expressions";
96621 #ifndef SQLITE_OMIT_CHECK
96622 else if( pNC->ncFlags & NC_IsCheck ) zIn = "CHECK constraints";
96623 #endif
96624 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
96625 else if( pNC->ncFlags & NC_GenCol ) zIn = "generated columns";
96626 #endif
96627 sqlite3ErrorMsg(pParse, "%s prohibited in %s", zMsg, zIn);
96628 }
96629 }
 
 
 
96630
96631 /*
96632 ** Expression p should encode a floating point value between 1.0 and 0.0.
96633 ** Return 1024 times this value. Or return -1 if p is not a floating point
96634 ** value between 1.0 and 0.0.
@@ -96713,11 +96902,14 @@
96713 zDb = 0;
96714 zTable = 0;
96715 zColumn = pExpr->u.zToken;
96716 }else{
96717 Expr *pLeft = pExpr->pLeft;
96718 notValid(pParse, pNC, "the \".\" operator", NC_IdxExpr|NC_GenCol);
 
 
 
96719 pRight = pExpr->pRight;
96720 if( pRight->op==TK_ID ){
96721 zDb = 0;
96722 }else{
96723 assert( pRight->op==TK_DOT );
@@ -96810,11 +97002,12 @@
96810 }
96811 if( (pDef->funcFlags & SQLITE_FUNC_CONSTANT)==0 ){
96812 /* Date/time functions that use 'now', and other functions like
96813 ** sqlite_version() that might change over time cannot be used
96814 ** in an index. */
96815 notValid(pParse, pNC, "non-deterministic functions", NC_SelfRef);
 
96816 }else{
96817 assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
96818 pExpr->op2 = pNC->ncFlags & NC_SelfRef;
96819 }
96820 if( (pDef->funcFlags & SQLITE_FUNC_INTERNAL)!=0
@@ -96912,11 +97105,11 @@
96912 #ifndef SQLITE_OMIT_WINDOWFUNC
96913 if( pWin ){
96914 Select *pSel = pNC->pWinSelect;
96915 assert( pWin==pExpr->y.pWin );
96916 if( IN_RENAME_OBJECT==0 ){
96917 sqlite3WindowUpdate(pParse, pSel->pWinDefn, pWin, pDef);
96918 }
96919 sqlite3WalkExprList(pWalker, pWin->pPartition);
96920 sqlite3WalkExprList(pWalker, pWin->pOrderBy);
96921 sqlite3WalkExpr(pWalker, pWin->pFilter);
96922 sqlite3WindowLink(pSel, pWin);
@@ -96957,12 +97150,16 @@
96957 #endif
96958 case TK_IN: {
96959 testcase( pExpr->op==TK_IN );
96960 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
96961 int nRef = pNC->nRef;
96962 notValid(pParse, pNC, "subqueries",
96963 NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol);
 
 
 
 
96964 sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
96965 assert( pNC->nRef>=nRef );
96966 if( nRef!=pNC->nRef ){
96967 ExprSetProperty(pExpr, EP_VarSelect);
96968 pNC->ncFlags |= NC_VarSelect;
@@ -96969,12 +97166,16 @@
96969 }
96970 }
96971 break;
96972 }
96973 case TK_VARIABLE: {
96974 notValid(pParse, pNC, "parameters",
96975 NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol);
 
 
 
 
96976 break;
96977 }
96978 case TK_IS:
96979 case TK_ISNOT: {
96980 Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight);
@@ -98203,10 +98404,11 @@
98203 ){
98204 int p5;
98205 int addr;
98206 CollSeq *p4;
98207
 
98208 if( isCommuted ){
98209 p4 = sqlite3BinaryCompareCollSeq(pParse, pRight, pLeft);
98210 }else{
98211 p4 = sqlite3BinaryCompareCollSeq(pParse, pLeft, pRight);
98212 }
@@ -98420,10 +98622,11 @@
98420 int regRight = 0;
98421 u8 opx = op;
98422 int addrDone = sqlite3VdbeMakeLabel(pParse);
98423 int isCommuted = ExprHasProperty(pExpr,EP_Commuted);
98424
 
98425 if( nLeft!=sqlite3ExprVectorSize(pRight) ){
98426 sqlite3ErrorMsg(pParse, "row value misused");
98427 return;
98428 }
98429 assert( pExpr->op==TK_EQ || pExpr->op==TK_NE
@@ -99768,11 +99971,13 @@
99768 switch( pExpr->op ){
99769 /* Consider functions to be constant if all their arguments are constant
99770 ** and either pWalker->eCode==4 or 5 or the function has the
99771 ** SQLITE_FUNC_CONST flag. */
99772 case TK_FUNCTION:
99773 if( pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_ConstFunc) ){
 
 
99774 return WRC_Continue;
99775 }else{
99776 pWalker->eCode = 0;
99777 return WRC_Abort;
99778 }
@@ -100031,11 +100236,13 @@
100031 case TK_BLOB:
100032 return 0;
100033 case TK_COLUMN:
100034 return ExprHasProperty(p, EP_CanBeNull) ||
100035 p->y.pTab==0 || /* Reference to column of index on expression */
100036 (p->iColumn>=0 && p->y.pTab->aCol[p->iColumn].notNull==0);
 
 
100037 default:
100038 return 1;
100039 }
100040 }
100041
@@ -100508,12 +100715,14 @@
100508 ** message of the form:
100509 **
100510 ** "sub-select returns N columns - expected M"
100511 */
100512 SQLITE_PRIVATE void sqlite3SubselectError(Parse *pParse, int nActual, int nExpect){
100513 const char *zFmt = "sub-select returns %d columns - expected %d";
100514 sqlite3ErrorMsg(pParse, zFmt, nActual, nExpect);
 
 
100515 }
100516 #endif
100517
100518 /*
100519 ** Expression pExpr is a vector that has been used in a context where
@@ -101011,19 +101220,25 @@
101011 }
101012 if( regCkNull && sqlite3ExprCanBeNull(pList->a[ii].pExpr) ){
101013 sqlite3VdbeAddOp3(v, OP_BitAnd, regCkNull, r2, regCkNull);
101014 }
101015 if( ii<pList->nExpr-1 || destIfNull!=destIfFalse ){
101016 sqlite3VdbeAddOp4(v, OP_Eq, rLhs, labelOk, r2,
 
101017 (void*)pColl, P4_COLLSEQ);
101018 VdbeCoverageIf(v, ii<pList->nExpr-1);
101019 VdbeCoverageIf(v, ii==pList->nExpr-1);
 
 
101020 sqlite3VdbeChangeP5(v, zAff[0]);
101021 }else{
 
101022 assert( destIfNull==destIfFalse );
101023 sqlite3VdbeAddOp4(v, OP_Ne, rLhs, destIfFalse, r2,
101024 (void*)pColl, P4_COLLSEQ); VdbeCoverage(v);
 
 
101025 sqlite3VdbeChangeP5(v, zAff[0] | SQLITE_JUMPIFNULL);
101026 }
101027 sqlite3ReleaseTempReg(pParse, regToFree);
101028 }
101029 if( regCkNull ){
@@ -101042,10 +101257,11 @@
101042 if( destIfNull==destIfFalse ){
101043 destStep2 = destIfFalse;
101044 }else{
101045 destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
101046 }
 
101047 for(i=0; i<nVector; i++){
101048 Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
101049 if( sqlite3ExprCanBeNull(p) ){
101050 sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
101051 VdbeCoverage(v);
@@ -101233,15 +101449,24 @@
101233 SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(
101234 Parse *pParse,
101235 Column *pCol,
101236 int regOut
101237 ){
 
 
 
 
 
 
 
 
 
101238 sqlite3ExprCode(pParse, pCol->pDflt, regOut);
101239 if( pCol->affinity>=SQLITE_AFF_TEXT ){
101240 sqlite3VdbeAddOp4(pParse->pVdbe, OP_Affinity, regOut, 1, 0,
101241 &pCol->affinity, 1);
101242 }
 
101243 }
101244 #endif /* SQLITE_OMIT_GENERATED_COLUMNS */
101245
101246 /*
101247 ** Generate code to extract the value of the iCol-th column of a table.
@@ -101312,21 +101537,21 @@
101312 u8 p5 /* P5 value for OP_Column + FLAGS */
101313 ){
101314 assert( pParse->pVdbe!=0 );
101315 sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pTab, iTable, iColumn, iReg);
101316 if( p5 ){
101317 sqlite3VdbeChangeP5(pParse->pVdbe, p5);
 
101318 }
101319 return iReg;
101320 }
101321
101322 /*
101323 ** Generate code to move content from registers iFrom...iFrom+nReg-1
101324 ** over to iTo..iTo+nReg-1.
101325 */
101326 SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse *pParse, int iFrom, int iTo, int nReg){
101327 assert( iFrom>=iTo+nReg || iFrom+nReg<=iTo );
101328 sqlite3VdbeAddOp3(pParse->pVdbe, OP_Move, iFrom, iTo, nReg);
101329 }
101330
101331 /*
101332 ** Convert a scalar expression node to a TK_REGISTER referencing
@@ -101424,19 +101649,25 @@
101424 }
101425 /* Otherwise, fall thru into the TK_COLUMN case */
101426 }
101427 case TK_COLUMN: {
101428 int iTab = pExpr->iTable;
 
101429 if( ExprHasProperty(pExpr, EP_FixedCol) ){
101430 /* This COLUMN expression is really a constant due to WHERE clause
101431 ** constraints, and that constant is coded by the pExpr->pLeft
101432 ** expresssion. However, make sure the constant has the correct
101433 ** datatype by applying the Affinity of the table column to the
101434 ** constant.
101435 */
101436 int iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target);
101437 int aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
 
 
 
 
 
101438 if( aff>SQLITE_AFF_BLOB ){
101439 static const char zAff[] = "B\000C\000D\000E";
101440 assert( SQLITE_AFF_BLOB=='A' );
101441 assert( SQLITE_AFF_TEXT=='B' );
101442 if( iReg!=target ){
@@ -101460,11 +101691,11 @@
101460 Table *pTab = pExpr->y.pTab;
101461 int iSrc;
101462 int iCol = pExpr->iColumn;
101463 assert( pTab!=0 );
101464 assert( iCol>=XN_ROWID );
101465 assert( iCol<pExpr->y.pTab->nCol );
101466 if( iCol<0 ){
101467 return -1-pParse->iSelfTab;
101468 }
101469 pCol = pTab->aCol + iCol;
101470 testcase( iCol!=sqlite3TableColumnToStorage(pTab,iCol) );
@@ -101495,13 +101726,17 @@
101495 /* Coding an expression that is part of an index where column names
101496 ** in the index refer to the table to which the index belongs */
101497 iTab = pParse->iSelfTab - 1;
101498 }
101499 }
101500 return sqlite3ExprCodeGetColumn(pParse, pExpr->y.pTab,
101501 pExpr->iColumn, iTab, target,
101502 pExpr->op2);
 
 
 
 
101503 }
101504 case TK_INTEGER: {
101505 codeInteger(pParse, pExpr, 0, target);
101506 return target;
101507 }
@@ -101519,11 +101754,16 @@
101519 case TK_STRING: {
101520 assert( !ExprHasProperty(pExpr, EP_IntValue) );
101521 sqlite3VdbeLoadString(v, target, pExpr->u.zToken);
101522 return target;
101523 }
101524 case TK_NULL: {
 
 
 
 
 
101525 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
101526 return target;
101527 }
101528 #ifndef SQLITE_OMIT_BLOB_LITERAL
101529 case TK_BLOB: {
@@ -101546,11 +101786,11 @@
101546 assert( pExpr->u.zToken!=0 );
101547 assert( pExpr->u.zToken[0]!=0 );
101548 sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target);
101549 if( pExpr->u.zToken[1]!=0 ){
101550 const char *z = sqlite3VListNumToName(pParse->pVList, pExpr->iColumn);
101551 assert( pExpr->u.zToken[0]=='?' || strcmp(pExpr->u.zToken, z)==0 );
101552 pParse->pVList[0] = 0; /* Indicate VList may no longer be enlarged */
101553 sqlite3VdbeAppendP4(v, (char*)z, P4_STATIC);
101554 }
101555 return target;
101556 }
@@ -101859,12 +102099,16 @@
101859 #endif
101860 {
101861 sqlite3VdbeAddFunctionCall(pParse, constMask, r1, target, nFarg,
101862 pDef, pExpr->op2);
101863 }
101864 if( nFarg && constMask==0 ){
101865 sqlite3ReleaseTempRange(pParse, r1, nFarg);
 
 
 
 
101866 }
101867 return target;
101868 }
101869 #ifndef SQLITE_OMIT_SUBQUERY
101870 case TK_EXISTS:
@@ -101956,11 +102200,11 @@
101956 ** p1==2 -> old.b p1==5 -> new.b
101957 */
101958 Table *pTab = pExpr->y.pTab;
101959 int iCol = pExpr->iColumn;
101960 int p1 = pExpr->iTable * (pTab->nCol+1) + 1
101961 + (iCol>=0 ? sqlite3TableColumnToStorage(pTab, iCol) : -1);
101962
101963 assert( pExpr->iTable==0 || pExpr->iTable==1 );
101964 assert( iCol>=-1 && iCol<pTab->nCol );
101965 assert( pTab->iPKey<0 || iCol!=pTab->iPKey );
101966 assert( p1>=0 && p1<(pTab->nCol*2+2) );
@@ -102030,11 +102274,11 @@
102030 **
102031 ** The result of the expression is the Ri for the first matching Ei,
102032 ** or if there is no matching Ei, the ELSE term Y, or if there is
102033 ** no ELSE term, NULL.
102034 */
102035 default: assert( op==TK_CASE ); {
102036 int endLabel; /* GOTO label for end of CASE stmt */
102037 int nextCase; /* GOTO label for next WHEN clause */
102038 int nExpr; /* 2x number of WHEN terms */
102039 int i; /* Loop counter */
102040 ExprList *pEList; /* List of WHEN terms */
@@ -103087,11 +103331,14 @@
103087 sqlite3WalkExpr(pWalker, pExpr->pRight);
103088 }
103089 return WRC_Prune;
103090
103091 case TK_BETWEEN:
103092 sqlite3WalkExpr(pWalker, pExpr->pLeft);
 
 
 
103093 return WRC_Prune;
103094
103095 /* Virtual tables are allowed to use constraints like x=NULL. So
103096 ** a term of the form x=y does not prove that y is not null if x
103097 ** is the column of a virtual table */
@@ -103501,12 +103748,15 @@
103501 /*
103502 ** Deallocate a register, making available for reuse for some other
103503 ** purpose.
103504 */
103505 SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse *pParse, int iReg){
103506 if( iReg && pParse->nTempReg<ArraySize(pParse->aTempReg) ){
103507 pParse->aTempReg[pParse->nTempReg++] = iReg;
 
 
 
103508 }
103509 }
103510
103511 /*
103512 ** Allocate or deallocate a block of nReg consecutive registers.
@@ -103528,10 +103778,11 @@
103528 SQLITE_PRIVATE void sqlite3ReleaseTempRange(Parse *pParse, int iReg, int nReg){
103529 if( nReg==1 ){
103530 sqlite3ReleaseTempReg(pParse, iReg);
103531 return;
103532 }
 
103533 if( nReg>pParse->nRangeReg ){
103534 pParse->nRangeReg = nReg;
103535 pParse->iRangeReg = iReg;
103536 }
103537 }
@@ -104271,16 +104522,18 @@
104271 */
104272 SQLITE_PRIVATE void *sqlite3RenameTokenMap(Parse *pParse, void *pPtr, Token *pToken){
104273 RenameToken *pNew;
104274 assert( pPtr || pParse->db->mallocFailed );
104275 renameTokenCheckAll(pParse, pPtr);
104276 pNew = sqlite3DbMallocZero(pParse->db, sizeof(RenameToken));
104277 if( pNew ){
104278 pNew->p = pPtr;
104279 pNew->t = *pToken;
104280 pNew->pNext = pParse->pRename;
104281 pParse->pRename = pNew;
 
 
104282 }
104283
104284 return pPtr;
104285 }
104286
@@ -104306,17 +104559,39 @@
104306 static int renameUnmapExprCb(Walker *pWalker, Expr *pExpr){
104307 Parse *pParse = pWalker->pParse;
104308 sqlite3RenameTokenRemap(pParse, 0, (void*)pExpr);
104309 return WRC_Continue;
104310 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104311
104312 /*
104313 ** Walker callback used by sqlite3RenameExprUnmap().
104314 */
104315 static int renameUnmapSelectCb(Walker *pWalker, Select *p){
104316 Parse *pParse = pWalker->pParse;
104317 int i;
 
 
104318 if( ALWAYS(p->pEList) ){
104319 ExprList *pList = p->pEList;
104320 for(i=0; i<pList->nExpr; i++){
104321 if( pList->a[i].zName ){
104322 sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zName);
@@ -104325,25 +104600,31 @@
104325 }
104326 if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
104327 SrcList *pSrc = p->pSrc;
104328 for(i=0; i<pSrc->nSrc; i++){
104329 sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName);
 
104330 }
104331 }
 
 
104332 return WRC_Continue;
104333 }
104334
104335 /*
104336 ** Remove all nodes that are part of expression pExpr from the rename list.
104337 */
104338 SQLITE_PRIVATE void sqlite3RenameExprUnmap(Parse *pParse, Expr *pExpr){
 
104339 Walker sWalker;
104340 memset(&sWalker, 0, sizeof(Walker));
104341 sWalker.pParse = pParse;
104342 sWalker.xExprCallback = renameUnmapExprCb;
104343 sWalker.xSelectCallback = renameUnmapSelectCb;
 
104344 sqlite3WalkExpr(&sWalker, pExpr);
 
104345 }
104346
104347 /*
104348 ** Remove all nodes that are part of expression-list pEList from the
104349 ** rename list.
@@ -104393,34 +104674,17 @@
104393 break;
104394 }
104395 }
104396 }
104397
104398 /*
104399 ** Iterate through the Select objects that are part of WITH clauses attached
104400 ** to select statement pSelect.
104401 */
104402 static void renameWalkWith(Walker *pWalker, Select *pSelect){
104403 if( pSelect->pWith ){
104404 int i;
104405 for(i=0; i<pSelect->pWith->nCte; i++){
104406 Select *p = pSelect->pWith->a[i].pSelect;
104407 NameContext sNC;
104408 memset(&sNC, 0, sizeof(sNC));
104409 sNC.pParse = pWalker->pParse;
104410 sqlite3SelectPrep(sNC.pParse, p, &sNC);
104411 sqlite3WalkSelect(pWalker, p);
104412 }
104413 }
104414 }
104415
104416 /*
104417 ** This is a Walker select callback. It does nothing. It is only required
104418 ** because without a dummy callback, sqlite3WalkExpr() and similar do not
104419 ** descend into sub-select statements.
104420 */
104421 static int renameColumnSelectCb(Walker *pWalker, Select *p){
 
104422 renameWalkWith(pWalker, p);
104423 return WRC_Continue;
104424 }
104425
104426 /*
@@ -104547,11 +104811,10 @@
104547 ** is initialized by this function before it is used.
104548 */
104549 static int renameParseSql(
104550 Parse *p, /* Memory to use for Parse object */
104551 const char *zDb, /* Name of schema SQL belongs to */
104552 int bTable, /* 1 -> RENAME TABLE, 0 -> RENAME COLUMN */
104553 sqlite3 *db, /* Database handle */
104554 const char *zSql, /* SQL to parse */
104555 int bTemp /* True if SQL is from temp schema */
104556 ){
104557 int rc;
@@ -104561,11 +104824,11 @@
104561
104562 /* Parse the SQL statement passed as the first argument. If no error
104563 ** occurs and the parse does not result in a new table, index or
104564 ** trigger object, the database must be corrupt. */
104565 memset(p, 0, sizeof(Parse));
104566 p->eParseMode = (bTable ? PARSE_MODE_RENAME_TABLE : PARSE_MODE_RENAME_COLUMN);
104567 p->db = db;
104568 p->nQueryLoop = 1;
104569 rc = sqlite3RunParser(p, zSql, &zErr);
104570 assert( p->zErrMsg==0 );
104571 assert( rc!=SQLITE_OK || zErr==0 );
@@ -104868,11 +105131,11 @@
104868 sCtx.iCol = ((iCol==pTab->iPKey) ? -1 : iCol);
104869
104870 #ifndef SQLITE_OMIT_AUTHORIZATION
104871 db->xAuth = 0;
104872 #endif
104873 rc = renameParseSql(&sParse, zDb, 0, db, zSql, bTemp);
104874
104875 /* Find tokens that need to be replaced. */
104876 memset(&sWalker, 0, sizeof(Walker));
104877 sWalker.pParse = &sParse;
104878 sWalker.xExprCallback = renameColumnExprCb;
@@ -104882,12 +105145,13 @@
104882 sCtx.pTab = pTab;
104883 if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
104884 if( sParse.pNewTable ){
104885 Select *pSelect = sParse.pNewTable->pSelect;
104886 if( pSelect ){
 
104887 sParse.rc = SQLITE_OK;
104888 sqlite3SelectPrep(&sParse, sParse.pNewTable->pSelect, 0);
104889 rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc);
104890 if( rc==SQLITE_OK ){
104891 sqlite3WalkSelect(&sWalker, pSelect);
104892 }
104893 if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
@@ -105000,10 +105264,11 @@
105000 */
105001 static int renameTableSelectCb(Walker *pWalker, Select *pSelect){
105002 int i;
105003 RenameCtx *p = pWalker->u.pRename;
105004 SrcList *pSrc = pSelect->pSrc;
 
105005 if( pSrc==0 ){
105006 assert( pWalker->pParse->db->mallocFailed );
105007 return WRC_Abort;
105008 }
105009 for(i=0; i<pSrc->nSrc; i++){
@@ -105070,26 +105335,32 @@
105070 sWalker.pParse = &sParse;
105071 sWalker.xExprCallback = renameTableExprCb;
105072 sWalker.xSelectCallback = renameTableSelectCb;
105073 sWalker.u.pRename = &sCtx;
105074
105075 rc = renameParseSql(&sParse, zDb, 1, db, zInput, bTemp);
105076
105077 if( rc==SQLITE_OK ){
105078 int isLegacy = (db->flags & SQLITE_LegacyAlter);
105079 if( sParse.pNewTable ){
105080 Table *pTab = sParse.pNewTable;
105081
105082 if( pTab->pSelect ){
105083 if( isLegacy==0 ){
 
105084 NameContext sNC;
105085 memset(&sNC, 0, sizeof(sNC));
105086 sNC.pParse = &sParse;
105087
 
 
105088 sqlite3SelectPrep(&sParse, pTab->pSelect, &sNC);
105089 if( sParse.nErr ) rc = sParse.rc;
105090 sqlite3WalkSelect(&sWalker, pTab->pSelect);
 
 
 
105091 }
105092 }else{
105093 /* Modify any FK definitions to point to the new table. */
105094 #ifndef SQLITE_OMIT_FOREIGN_KEY
105095 if( isLegacy==0 || (db->flags & SQLITE_ForeignKeys) ){
@@ -105206,11 +105477,11 @@
105206
105207 UNUSED_PARAMETER(NotUsed);
105208 if( zDb && zInput ){
105209 int rc;
105210 Parse sParse;
105211 rc = renameParseSql(&sParse, zDb, 1, db, zInput, bTemp);
105212 if( rc==SQLITE_OK ){
105213 if( isLegacy==0 && sParse.pNewTable && sParse.pNewTable->pSelect ){
105214 NameContext sNC;
105215 memset(&sNC, 0, sizeof(sNC));
105216 sNC.pParse = &sParse;
@@ -108999,17 +109270,19 @@
108999 **
109000 ** So, in other words, this routine shifts all the virtual columns to
109001 ** the end.
109002 **
109003 ** If SQLITE_OMIT_GENERATED_COLUMNS then there are no virtual columns and
109004 ** this routine is a no-op macro.
 
 
109005 */
109006 SQLITE_PRIVATE i16 sqlite3TableColumnToStorage(Table *pTab, i16 iCol){
109007 int i;
109008 i16 n;
109009 assert( iCol<pTab->nCol );
109010 if( (pTab->tabFlags & TF_HasVirtual)==0 ) return iCol;
109011 for(i=0, n=0; i<iCol; i++){
109012 if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ) n++;
109013 }
109014 if( pTab->aCol[i].colFlags & COLFLAG_VIRTUAL ){
109015 /* iCol is a virtual column itself */
@@ -109597,10 +109870,11 @@
109597 pTab->iPKey = iCol;
109598 pTab->keyConf = (u8)onError;
109599 assert( autoInc==0 || autoInc==1 );
109600 pTab->tabFlags |= autoInc*TF_Autoincrement;
109601 if( pList ) pParse->iPkSortOrder = pList->a[0].sortFlags;
 
109602 }else if( autoInc ){
109603 #ifndef SQLITE_OMIT_AUTOINCREMENT
109604 sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
109605 "INTEGER PRIMARY KEY");
109606 #endif
@@ -109681,11 +109955,14 @@
109681 SQLITE_PRIVATE void sqlite3AddGenerated(Parse *pParse, Expr *pExpr, Token *pType){
109682 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
109683 u8 eType = COLFLAG_VIRTUAL;
109684 Table *pTab = pParse->pNewTable;
109685 Column *pCol;
109686 if( NEVER(pTab==0) ) goto generated_done;
 
 
 
109687 pCol = &(pTab->aCol[pTab->nCol-1]);
109688 if( IN_DECLARE_VTAB ){
109689 sqlite3ErrorMsg(pParse, "virtual tables cannot use computed columns");
109690 goto generated_done;
109691 }
@@ -110289,10 +110566,16 @@
110289 #ifndef SQLITE_OMIT_CHECK
110290 /* Resolve names in all CHECK constraint expressions.
110291 */
110292 if( p->pCheck ){
110293 sqlite3ResolveSelfReference(pParse, p, NC_IsCheck, 0, p->pCheck);
 
 
 
 
 
 
110294 }
110295 #endif /* !defined(SQLITE_OMIT_CHECK) */
110296 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
110297 if( p->tabFlags & TF_HasGenerated ){
110298 int ii, nNG = 0;
@@ -110299,14 +110582,23 @@
110299 testcase( p->tabFlags & TF_HasVirtual );
110300 testcase( p->tabFlags & TF_HasStored );
110301 for(ii=0; ii<p->nCol; ii++){
110302 u32 colFlags = p->aCol[ii].colFlags;
110303 if( (colFlags & COLFLAG_GENERATED)!=0 ){
 
110304 testcase( colFlags & COLFLAG_VIRTUAL );
110305 testcase( colFlags & COLFLAG_STORED );
110306 sqlite3ResolveSelfReference(pParse, p, NC_GenCol,
110307 p->aCol[ii].pDflt, 0);
 
 
 
 
 
 
 
 
110308 }else{
110309 nNG++;
110310 }
110311 }
110312 if( nNG==0 ){
@@ -110532,10 +110824,11 @@
110532 /* Make a copy of the entire SELECT statement that defines the view.
110533 ** This will force all the Expr.token.z values to be dynamically
110534 ** allocated rather than point to the input string - which means that
110535 ** they will persist after the current sqlite3_exec() call returns.
110536 */
 
110537 if( IN_RENAME_OBJECT ){
110538 p->pSelect = pSelect;
110539 pSelect = 0;
110540 }else{
110541 p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
@@ -111958,30 +112251,13 @@
111958 }
111959
111960 sqlite3VdbeJumpHere(v, pIndex->tnum);
111961 }
111962 }
111963
111964 /* When adding an index to the list of indices for a table, make
111965 ** sure all indices labeled OE_Replace come after all those labeled
111966 ** OE_Ignore. This is necessary for the correct constraint check
111967 ** processing (in sqlite3GenerateConstraintChecks()) as part of
111968 ** UPDATE and INSERT statements.
111969 */
111970 if( db->init.busy || pTblName==0 ){
111971 if( onError!=OE_Replace || pTab->pIndex==0
111972 || pTab->pIndex->onError==OE_Replace){
111973 pIndex->pNext = pTab->pIndex;
111974 pTab->pIndex = pIndex;
111975 }else{
111976 Index *pOther = pTab->pIndex;
111977 while( pOther->pNext && pOther->pNext->onError!=OE_Replace ){
111978 pOther = pOther->pNext;
111979 }
111980 pIndex->pNext = pOther->pNext;
111981 pOther->pNext = pIndex;
111982 }
111983 pIndex = 0;
111984 }
111985 else if( IN_RENAME_OBJECT ){
111986 assert( pParse->pNewIndex==0 );
111987 pParse->pNewIndex = pIndex;
@@ -111989,10 +112265,25 @@
111989 }
111990
111991 /* Clean up before exiting */
111992 exit_create_index:
111993 if( pIndex ) sqlite3FreeIndex(db, pIndex);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111994 sqlite3ExprDelete(db, pPIWhere);
111995 sqlite3ExprListDelete(db, pList);
111996 sqlite3SrcListDelete(db, pTblName);
111997 sqlite3DbFree(db, zName);
111998 }
@@ -118231,14 +118522,15 @@
118231 }
118232 return 0;
118233 }
118234
118235 /* This walker callback will compute the union of colFlags flags for all
118236 ** references columns in a CHECK constraint or generated column expression.
118237 */
118238 static int exprColumnFlagUnion(Walker *pWalker, Expr *pExpr){
118239 if( pExpr->op==TK_COLUMN ){
 
118240 pWalker->eCode |= pWalker->u.pTab->aCol[pExpr->iColumn].colFlags;
118241 }
118242 return WRC_Continue;
118243 }
118244
@@ -118257,10 +118549,40 @@
118257 ){
118258 int i;
118259 Walker w;
118260 Column *pRedo;
118261 int eProgress;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118262
118263 /* Because there can be multiple generated columns that refer to one another,
118264 ** this is a two-pass algorithm. On the first pass, mark all generated
118265 ** columns as "not available".
118266 */
@@ -118977,10 +119299,14 @@
118977 if( IsVirtual(pTab) ){
118978 sqlite3ErrorMsg(pParse, "UPSERT not implemented for virtual table \"%s\"",
118979 pTab->zName);
118980 goto insert_cleanup;
118981 }
 
 
 
 
118982 if( sqlite3HasExplicitNulls(pParse, pUpsert->pUpsertTarget) ){
118983 goto insert_cleanup;
118984 }
118985 pTabList->a[0].iCursor = iDataCur;
118986 pUpsert->pUpsertSrc = pTabList;
@@ -119211,14 +119537,12 @@
119211
119212 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
119213 /* Compute the new value for generated columns after all other
119214 ** columns have already been computed. This must be done after
119215 ** computing the ROWID in case one of the generated columns
119216 ** refers to the ROWID. */
119217 if( pTab->tabFlags & TF_HasGenerated ){
119218 testcase( pTab->tabFlags & TF_HasVirtual );
119219 testcase( pTab->tabFlags & TF_HasStored );
119220 sqlite3ComputeGeneratedColumns(pParse, regRowid+1, pTab);
119221 }
119222 #endif
119223
119224 /* Generate code to check constraints and generate index keys and
@@ -120246,10 +120570,14 @@
120246
120247 v = sqlite3GetVdbe(pParse);
120248 assert( v!=0 );
120249 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
120250 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
 
 
 
 
120251 if( aRegIdx[i]==0 ) continue;
120252 if( pIdx->pPartIdxWhere ){
120253 sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
120254 VdbeCoverage(v);
120255 }
@@ -124713,11 +125041,13 @@
124713 char *zErr;
124714 int jmp2;
124715 if( j==pTab->iPKey ) continue;
124716 if( pTab->aCol[j].notNull==0 ) continue;
124717 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3);
124718 sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
 
 
124719 jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
124720 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
124721 pTab->aCol[j].zName);
124722 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
124723 integrityCheckResultRow(v);
@@ -126679,11 +127009,14 @@
126679 };
126680 #define SORTFLAG_UseSorter 0x01 /* Use SorterOpen instead of OpenEphemeral */
126681
126682 /*
126683 ** Delete all the content of a Select structure. Deallocate the structure
126684 ** itself only if bFree is true.
 
 
 
126685 */
126686 static void clearSelect(sqlite3 *db, Select *p, int bFree){
126687 while( p ){
126688 Select *pPrior = p->pPrior;
126689 sqlite3ExprListDelete(db, p->pEList);
@@ -126782,10 +127115,24 @@
126782 ** Delete the given Select structure and all of its substructures.
126783 */
126784 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
126785 if( OK_IF_ALWAYS_TRUE(p) ) clearSelect(db, p, 1);
126786 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126787
126788 /*
126789 ** Return a pointer to the right-most SELECT statement in a compound.
126790 */
126791 static Select *findRightmost(Select *p){
@@ -129069,10 +129416,11 @@
129069 assert( p->selFlags & SF_MultiValue );
129070 do{
129071 assert( p->selFlags & SF_Values );
129072 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
129073 assert( p->pNext==0 || p->pEList->nExpr==p->pNext->pEList->nExpr );
 
129074 if( p->pPrior==0 ) break;
129075 assert( p->pPrior->pNext==p );
129076 p = p->pPrior;
129077 nRow += bShowAll;
129078 }while(1);
@@ -129159,11 +129507,12 @@
129159
129160 /* Special handling for a compound-select that originates as a VALUES clause.
129161 */
129162 if( p->selFlags & SF_MultiValue ){
129163 rc = multiSelectValues(pParse, p, &dest);
129164 goto multi_select_end;
 
129165 }
129166
129167 /* Make sure all SELECTs in the statement have the same number of elements
129168 ** in their result sets.
129169 */
@@ -129304,13 +129653,13 @@
129304
129305 /* Convert the data in the temporary table into whatever form
129306 ** it is that we currently need.
129307 */
129308 assert( unionTab==dest.iSDParm || dest.eDest!=priorOp );
129309 if( dest.eDest!=priorOp ){
 
129310 int iCont, iBreak, iStart;
129311 assert( p->pEList );
129312 iBreak = sqlite3VdbeMakeLabel(pParse);
129313 iCont = sqlite3VdbeMakeLabel(pParse);
129314 computeLimitRegisters(pParse, p, iBreak);
129315 sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
129316 iStart = sqlite3VdbeCurrentAddr(v);
@@ -129402,10 +129751,11 @@
129402 if( p->pNext==0 ){
129403 ExplainQueryPlanPop(pParse);
129404 }
129405 #endif
129406 }
 
129407
129408 /* Compute collating sequences used by
129409 ** temporary tables needed to implement the compound select.
129410 ** Attach the KeyInfo structure to all temporary tables.
129411 **
@@ -130193,10 +130543,11 @@
130193 ** (3) If the subquery is the right operand of a LEFT JOIN then
130194 ** (3a) the subquery may not be a join and
130195 ** (3b) the FROM clause of the subquery may not contain a virtual
130196 ** table and
130197 ** (3c) the outer query may not be an aggregate.
 
130198 **
130199 ** (4) The subquery can not be DISTINCT.
130200 **
130201 ** (**) At one point restrictions (4) and (5) defined a subset of DISTINCT
130202 ** sub-queries that were excluded from this optimization. Restriction
@@ -130389,12 +130740,15 @@
130389 **
130390 ** See also tickets #306, #350, and #3300.
130391 */
130392 if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
130393 isLeftJoin = 1;
130394 if( pSubSrc->nSrc>1 || isAgg || IsVirtual(pSubSrc->a[0].pTab) ){
130395 /* (3a) (3c) (3b) */
 
 
 
130396 return 0;
130397 }
130398 }
130399 #ifdef SQLITE_EXTRA_IFNULLROW
130400 else if( iFrom>0 && !isAgg ){
@@ -131164,10 +131518,13 @@
131164 pNew->pHaving = 0;
131165 pNew->pOrderBy = 0;
131166 p->pPrior = 0;
131167 p->pNext = 0;
131168 p->pWith = 0;
 
 
 
131169 p->selFlags &= ~SF_Compound;
131170 assert( (p->selFlags & SF_Converted)==0 );
131171 p->selFlags |= SF_Converted;
131172 assert( pNew->pPrior!=0 );
131173 pNew->pPrior->pNext = pNew;
@@ -132323,11 +132680,13 @@
132323 if( pDest->eDest==SRT_Output ){
132324 generateColumnNames(pParse, p);
132325 }
132326
132327 #ifndef SQLITE_OMIT_WINDOWFUNC
132328 if( sqlite3WindowRewrite(pParse, p) ){
 
 
132329 goto select_end;
132330 }
132331 #if SELECTTRACE_ENABLED
132332 if( p->pWin && (sqlite3SelectTrace & 0x108)!=0 ){
132333 SELECTTRACE(0x104,pParse,p, ("after window rewrite:\n"));
@@ -132659,10 +133018,11 @@
132659 ** written the query must use a temp-table for at least one of the ORDER
132660 ** BY and DISTINCT, and an index or separate temp-table for the other.
132661 */
132662 if( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct
132663 && sqlite3ExprListCompare(sSort.pOrderBy, pEList, -1)==0
 
132664 ){
132665 p->selFlags &= ~SF_Distinct;
132666 pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
132667 /* Notice that even thought SF_Distinct has been cleared from p->selFlags,
132668 ** the sDistinct.isTnct is still set. Hence, isTnct represents the
@@ -134182,12 +134542,16 @@
134182 if( ALWAYS(pTrigger) ){
134183 if( pTrigger->pSchema==pTrigger->pTabSchema ){
134184 Table *pTab = tableOfTrigger(pTrigger);
134185 if( pTab ){
134186 Trigger **pp;
134187 for(pp=&pTab->pTrigger; *pp!=pTrigger; pp=&((*pp)->pNext));
134188 *pp = (*pp)->pNext;
 
 
 
 
134189 }
134190 }
134191 sqlite3DeleteTrigger(db, pTrigger);
134192 db->mDbFlags |= DBFLAG_SchemaChange;
134193 }
@@ -136913,10 +137277,12 @@
136913 char *zStmt;
136914 char *zWhere;
136915 int iDb;
136916 int iReg;
136917 Vdbe *v;
 
 
136918
136919 /* Compute the complete text of the CREATE VIRTUAL TABLE statement */
136920 if( pEnd ){
136921 pParse->sNameToken.n = (int)(pEnd->z - pParse->sNameToken.z) + pEnd->n;
136922 }
@@ -136939,17 +137305,17 @@
136939 pTab->zName,
136940 pTab->zName,
136941 zStmt,
136942 pParse->regRowid
136943 );
136944 sqlite3DbFree(db, zStmt);
136945 v = sqlite3GetVdbe(pParse);
136946 sqlite3ChangeCookie(pParse, iDb);
136947
136948 sqlite3VdbeAddOp0(v, OP_Expire);
136949 zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
136950 sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere);
 
136951
136952 iReg = ++pParse->nMem;
136953 sqlite3VdbeLoadString(v, iReg, pTab->zName);
136954 sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg);
136955 }
@@ -137347,11 +137713,12 @@
137347 return SQLITE_LOCKED;
137348 }
137349 }
137350 p = vtabDisconnectAll(db, pTab);
137351 xDestroy = p->pMod->pModule->xDestroy;
137352 assert( xDestroy!=0 ); /* Checked before the virtual table is created */
 
137353 pTab->nTabRef++;
137354 rc = xDestroy(p->pVtab);
137355 /* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */
137356 if( rc==SQLITE_OK ){
137357 assert( pTab->pVTable==p && p->pNext==0 );
@@ -138776,11 +139143,12 @@
138776 int iEq, /* Look at loop terms starting here */
138777 WhereLoop *pLoop, /* The current loop */
138778 Expr *pX /* The IN expression to be reduced */
138779 ){
138780 sqlite3 *db = pParse->db;
138781 Expr *pNew = sqlite3ExprDup(db, pX, 0);
 
138782 if( db->mallocFailed==0 ){
138783 ExprList *pOrigRhs = pNew->x.pSelect->pEList; /* Original unmodified RHS */
138784 ExprList *pOrigLhs = pNew->pLeft->x.pList; /* Original unmodified LHS */
138785 ExprList *pRhs = 0; /* New RHS after modifications */
138786 ExprList *pLhs = 0; /* New LHS after mods */
@@ -139488,10 +139856,13 @@
139488 pExpr->affExpr = sqlite3ExprAffinity(pExpr);
139489 pExpr->op = TK_COLUMN;
139490 pExpr->iTable = pX->iIdxCur;
139491 pExpr->iColumn = pX->iIdxCol;
139492 pExpr->y.pTab = 0;
 
 
 
139493 return WRC_Prune;
139494 }else{
139495 return WRC_Continue;
139496 }
139497 }
@@ -139502,10 +139873,12 @@
139502 */
139503 static int whereIndexExprTransColumn(Walker *p, Expr *pExpr){
139504 if( pExpr->op==TK_COLUMN ){
139505 IdxExprTrans *pX = p->u.pIdxTrans;
139506 if( pExpr->iTable==pX->iTabCur && pExpr->iColumn==pX->iTabCol ){
 
 
139507 pExpr->iTable = pX->iIdxCur;
139508 pExpr->iColumn = pX->iIdxCol;
139509 pExpr->y.pTab = 0;
139510 }
139511 }
@@ -139547,13 +139920,24 @@
139547 for(iIdxCol=0; iIdxCol<pIdx->nColumn; iIdxCol++){
139548 i16 iRef = pIdx->aiColumn[iIdxCol];
139549 if( iRef==XN_EXPR ){
139550 assert( aColExpr->a[iIdxCol].pExpr!=0 );
139551 x.pIdxExpr = aColExpr->a[iIdxCol].pExpr;
 
139552 w.xExprCallback = whereIndexExprTransNode;
139553 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
139554 }else if( iRef>=0 && (pTab->aCol[iRef].colFlags & COLFLAG_VIRTUAL)!=0 ){
 
 
 
 
 
 
 
 
 
 
139555 x.iTabCol = iRef;
139556 w.xExprCallback = whereIndexExprTransColumn;
139557 #endif /* SQLITE_OMIT_GENERATED_COLUMNS */
139558 }else{
139559 continue;
@@ -140213,14 +140597,14 @@
140213 omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
140214 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0;
140215 if( omitTable ){
140216 /* pIdx is a covering index. No need to access the main table. */
140217 }else if( HasRowid(pIdx->pTable) ){
140218 if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE) || (
140219 (pWInfo->wctrlFlags & WHERE_SEEK_UNIQ_TABLE)
140220 && (pWInfo->eOnePass==ONEPASS_SINGLE)
140221 )){
140222 iRowidReg = ++pParse->nMem;
140223 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
140224 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg);
140225 VdbeCoverage(v);
140226 }else{
@@ -142055,10 +142439,11 @@
142055 Expr *pNewExpr;
142056 pNewExpr = sqlite3PExpr(pParse, TK_MATCH,
142057 0, sqlite3ExprDup(db, pRight, 0));
142058 if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){
142059 ExprSetProperty(pNewExpr, EP_FromJoin);
 
142060 }
142061 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
142062 testcase( idxNew==0 );
142063 pNewTerm = &pWC->a[idxNew];
142064 pNewTerm->prereqRight = prereqExpr;
@@ -142111,15 +142496,19 @@
142111 ** a virtual term for each vector component. The expression object
142112 ** used by each such virtual term is pExpr (the full vector IN(...)
142113 ** expression). The WhereTerm.iField variable identifies the index within
142114 ** the vector on the LHS that the virtual term represents.
142115 **
142116 ** This only works if the RHS is a simple SELECT, not a compound
 
142117 */
142118 if( pWC->op==TK_AND && pExpr->op==TK_IN && pTerm->iField==0
142119 && pExpr->pLeft->op==TK_VECTOR
142120 && pExpr->x.pSelect->pPrior==0
 
 
 
142121 ){
142122 int i;
142123 for(i=0; i<sqlite3ExprVectorSize(pExpr->pLeft); i++){
142124 int idxNew;
142125 idxNew = whereClauseInsert(pWC, pExpr, TERM_VIRTUAL);
@@ -142273,13 +142662,14 @@
142273 mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
142274 }else if( p->x.pList ){
142275 mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
142276 }
142277 #ifndef SQLITE_OMIT_WINDOWFUNC
142278 if( p->op==TK_FUNCTION && p->y.pWin ){
142279 mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition);
142280 mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy);
 
142281 }
142282 #endif
142283 return mask;
142284 }
142285 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
@@ -143163,11 +143553,12 @@
143163 if( (idxCols & cMask)==0 ){
143164 Expr *pX = pTerm->pExpr;
143165 idxCols |= cMask;
143166 pIdx->aiColumn[n] = pTerm->u.leftColumn;
143167 pColl = sqlite3ExprCompareCollSeq(pParse, pX);
143168 pIdx->azColl[n] = ALWAYS(pColl) ? pColl->zName : sqlite3StrBINARY;
 
143169 n++;
143170 }
143171 }
143172 }
143173 assert( (u32)n==pLoop->u.btree.nEq );
@@ -143341,22 +143732,17 @@
143341 testcase( pTerm->eOperator & WO_IS );
143342 testcase( pTerm->eOperator & WO_ISNULL );
143343 testcase( pTerm->eOperator & WO_ALL );
143344 if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
143345 if( pTerm->wtFlags & TERM_VNULL ) continue;
 
 
 
 
143346 if( (pSrc->fg.jointype & JT_LEFT)!=0
143347 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
143348 && (pTerm->eOperator & (WO_IS|WO_ISNULL))
143349 ){
143350 /* An "IS" term in the WHERE clause where the virtual table is the rhs
143351 ** of a LEFT JOIN. Do not pass this term to the virtual table
143352 ** implementation, as this can lead to incorrect results from SQL such
143353 ** as:
143354 **
143355 ** "LEFT JOIN vtab WHERE vtab.col IS NULL" */
143356 testcase( pTerm->eOperator & WO_ISNULL );
143357 testcase( pTerm->eOperator & WO_IS );
143358 continue;
143359 }
143360 assert( pTerm->u.leftColumn>=(-1) );
143361 pIdxCons[j].iColumn = pTerm->u.leftColumn;
143362 pIdxCons[j].iTermOffset = i;
@@ -143383,11 +143769,12 @@
143383 assert( pTerm->eOperator&(WO_IN|WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_AUX) );
143384
143385 if( op & (WO_LT|WO_LE|WO_GT|WO_GE)
143386 && sqlite3ExprIsVector(pTerm->pExpr->pRight)
143387 ){
143388 if( i<16 ) mNoOmit |= (1 << i);
 
143389 if( op==WO_LT ) pIdxCons[j].op = WO_LE;
143390 if( op==WO_GT ) pIdxCons[j].op = WO_GE;
143391 }
143392 }
143393
@@ -144128,14 +144515,16 @@
144128 sqlite3DebugPrintf(
144129 "TERM-%-3d %p %s %-12s prob=%-3d op=0x%03x wtFlags=0x%04x",
144130 iTerm, pTerm, zType, zLeft, pTerm->truthProb,
144131 pTerm->eOperator, pTerm->wtFlags);
144132 if( pTerm->iField ){
144133 sqlite3DebugPrintf(" iField=%d\n", pTerm->iField);
144134 }else{
144135 sqlite3DebugPrintf("\n");
144136 }
 
 
 
 
144137 sqlite3TreeViewExpr(0, pTerm->pExpr, 0);
144138 }
144139 }
144140 #endif
144141
@@ -144178,11 +144567,11 @@
144178 sqlite3DebugPrintf("%20s","");
144179 }
144180 }else{
144181 char *z;
144182 if( p->u.vtab.idxStr ){
144183 z = sqlite3_mprintf("(%d,\"%s\",%x)",
144184 p->u.vtab.idxNum, p->u.vtab.idxStr, p->u.vtab.omitMask);
144185 }else{
144186 z = sqlite3_mprintf("(%d,%x)", p->u.vtab.idxNum, p->u.vtab.omitMask);
144187 }
144188 sqlite3DebugPrintf(" %-19s", z);
@@ -144833,13 +145222,13 @@
144833
144834 /* Do not allow the upper bound of a LIKE optimization range constraint
144835 ** to mix with a lower range bound from some other source */
144836 if( pTerm->wtFlags & TERM_LIKEOPT && pTerm->eOperator==WO_LT ) continue;
144837
144838 /* Do not allow constraints from the WHERE clause to be used by the
144839 ** right table of a LEFT JOIN. Only constraints in the ON clause are
144840 ** allowed */
144841 if( (pSrc->fg.jointype & JT_LEFT)!=0
144842 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
144843 ){
144844 continue;
144845 }
@@ -145152,23 +145541,29 @@
145152 }
145153
145154 /* Check to see if a partial index with pPartIndexWhere can be used
145155 ** in the current query. Return true if it can be and false if not.
145156 */
145157 static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){
 
 
 
 
 
145158 int i;
145159 WhereTerm *pTerm;
145160 Parse *pParse = pWC->pWInfo->pParse;
145161 while( pWhere->op==TK_AND ){
145162 if( !whereUsablePartialIndex(iTab,pWC,pWhere->pLeft) ) return 0;
145163 pWhere = pWhere->pRight;
145164 }
145165 if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0;
145166 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
145167 Expr *pExpr;
145168 pExpr = pTerm->pExpr;
145169 if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab)
 
145170 && sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)
145171 ){
145172 return 1;
145173 }
145174 }
@@ -145327,12 +145722,15 @@
145327 /* Loop over all indices. If there was an INDEXED BY clause, then only
145328 ** consider index pProbe. */
145329 for(; rc==SQLITE_OK && pProbe;
145330 pProbe=(pSrc->pIBIndex ? 0 : pProbe->pNext), iSortIdx++
145331 ){
 
145332 if( pProbe->pPartIdxWhere!=0
145333 && !whereUsablePartialIndex(pSrc->iCursor, pWC, pProbe->pPartIdxWhere) ){
 
 
145334 testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */
145335 continue; /* Partial index inappropriate for this query */
145336 }
145337 if( pProbe->bNoQuery ) continue;
145338 rSize = pProbe->aiRowLogEst[0];
@@ -145555,11 +145953,18 @@
145555 assert( iTerm<pNew->nLSlot );
145556 pNew->aLTerm[iTerm] = pTerm;
145557 if( iTerm>mxTerm ) mxTerm = iTerm;
145558 testcase( iTerm==15 );
145559 testcase( iTerm==16 );
145560 if( iTerm<16 && pUsage[i].omit ) pNew->u.vtab.omitMask |= 1<<iTerm;
 
 
 
 
 
 
 
145561 if( (pTerm->eOperator & WO_IN)!=0 ){
145562 /* A virtual table that is constrained by an IN clause may not
145563 ** consume the ORDER BY clause because (1) the order of IN terms
145564 ** is not necessarily related to the order of output terms and
145565 ** (2) Multiple outputs from a single IN value will not merge
@@ -145568,11 +145973,10 @@
145568 pIdxInfo->idxFlags &= ~SQLITE_INDEX_SCAN_UNIQUE;
145569 *pbIn = 1; assert( (mExclude & WO_IN)==0 );
145570 }
145571 }
145572 }
145573 pNew->u.vtab.omitMask &= ~mNoOmit;
145574
145575 pNew->nLTerm = mxTerm+1;
145576 for(i=0; i<=mxTerm; i++){
145577 if( pNew->aLTerm[i]==0 ){
145578 /* The non-zero argvIdx values must be contiguous. Raise an
@@ -147163,10 +147567,11 @@
147163 sSelect.pEList = pResultSet;
147164 sqlite3TreeViewSelect(0, &sSelect, 0);
147165 }
147166 }
147167 if( sqlite3WhereTrace & 0x100 ){ /* Display all terms of the WHERE clause */
 
147168 sqlite3WhereClausePrint(sWLB.pWC);
147169 }
147170 #endif
147171
147172 if( nTabList!=1 || whereShortCut(&sWLB)==0 ){
@@ -147301,11 +147706,17 @@
147301 }
147302 pWInfo->nLevel--;
147303 nTabList--;
147304 }
147305 }
 
 
 
 
 
147306 WHERETRACE(0xffff,("*** Optimizer Finished ***\n"));
 
147307 pWInfo->pParse->nQueryLoop += pWInfo->nRowOut;
147308
147309 /* If the caller is an UPDATE or DELETE statement that is requesting
147310 ** to use a one-pass algorithm, determine if this is appropriate.
147311 **
@@ -148571,25 +148982,37 @@
148571 }
148572 /* Fall through. */
148573
148574 case TK_AGG_FUNCTION:
148575 case TK_COLUMN: {
148576 Expr *pDup = sqlite3ExprDup(pParse->db, pExpr, 0);
148577 p->pSub = sqlite3ExprListAppend(pParse, p->pSub, pDup);
 
 
 
 
 
 
 
 
 
 
 
 
148578 if( p->pSub ){
148579 assert( ExprHasProperty(pExpr, EP_Static)==0 );
148580 ExprSetProperty(pExpr, EP_Static);
148581 sqlite3ExprDelete(pParse->db, pExpr);
148582 ExprClearProperty(pExpr, EP_Static);
148583 memset(pExpr, 0, sizeof(Expr));
148584
148585 pExpr->op = TK_COLUMN;
148586 pExpr->iColumn = p->pSub->nExpr-1;
148587 pExpr->iTable = p->pWin->iEphCsr;
148588 pExpr->y.pTab = p->pTab;
148589 }
148590
148591 break;
148592 }
148593
148594 default: /* no-op */
148595 break;
@@ -148667,13 +149090,15 @@
148667 if( pAppend ){
148668 int i;
148669 int nInit = pList ? pList->nExpr : 0;
148670 for(i=0; i<pAppend->nExpr; i++){
148671 Expr *pDup = sqlite3ExprDup(pParse->db, pAppend->a[i].pExpr, 0);
 
148672 if( bIntToNull && pDup && pDup->op==TK_INTEGER ){
148673 pDup->op = TK_NULL;
148674 pDup->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
 
148675 }
148676 pList = sqlite3ExprListAppend(pParse, pList, pDup);
148677 if( pList ) pList->a[nInit+i].sortFlags = pAppend->a[i].sortFlags;
148678 }
148679 }
@@ -148704,11 +149129,11 @@
148704 Window *pWin; /* Window object iterator */
148705 Table *pTab;
148706
148707 pTab = sqlite3DbMallocZero(db, sizeof(Table));
148708 if( pTab==0 ){
148709 return SQLITE_NOMEM;
148710 }
148711
148712 p->pSrc = 0;
148713 p->pWhere = 0;
148714 p->pGroupBy = 0;
@@ -148791,10 +149216,13 @@
148791 p->pSrc->a[0].pSelect = pSub;
148792 sqlite3SrcListAssignCursors(pParse, p->pSrc);
148793 pSub->selFlags |= SF_Expanded;
148794 pTab2 = sqlite3ResultSetOfSelect(pParse, pSub, SQLITE_AFF_NONE);
148795 if( pTab2==0 ){
 
 
 
148796 rc = SQLITE_NOMEM;
148797 }else{
148798 memcpy(pTab, pTab2, sizeof(Table));
148799 pTab->tabFlags |= TF_Ephemeral;
148800 p->pSrc->a[0].pTab = pTab;
@@ -148809,10 +149237,17 @@
148809 }
148810 if( db->mallocFailed ) rc = SQLITE_NOMEM;
148811 sqlite3DbFree(db, pTab);
148812 }
148813
 
 
 
 
 
 
 
148814 return rc;
148815 }
148816
148817 /*
148818 ** Unlink the Window object from the Select to which it is attached,
@@ -149045,10 +149480,11 @@
149045 /*
149046 ** Return 0 if the two window objects are identical, or non-zero otherwise.
149047 ** Identical window objects can be processed in a single scan.
149048 */
149049 SQLITE_PRIVATE int sqlite3WindowCompare(Parse *pParse, Window *p1, Window *p2, int bFilter){
 
149050 if( p1->eFrmType!=p2->eFrmType ) return 1;
149051 if( p1->eStart!=p2->eStart ) return 1;
149052 if( p1->eEnd!=p2->eEnd ) return 1;
149053 if( p1->eExclude!=p2->eExclude ) return 1;
149054 if( sqlite3ExprCompare(pParse, p1->pStart, p2->pStart, -1) ) return 1;
@@ -151033,21 +151469,22 @@
151033 #define sqlite3ParserCTX_PDECL ,Parse *pParse
151034 #define sqlite3ParserCTX_PARAM ,pParse
151035 #define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse;
151036 #define sqlite3ParserCTX_STORE yypParser->pParse=pParse;
151037 #define YYFALLBACK 1
151038 #define YYNSTATE 550
151039 #define YYNRULE 385
 
151040 #define YYNTOKEN 181
151041 #define YY_MAX_SHIFT 549
151042 #define YY_MIN_SHIFTREDUCE 800
151043 #define YY_MAX_SHIFTREDUCE 1184
151044 #define YY_ERROR_ACTION 1185
151045 #define YY_ACCEPT_ACTION 1186
151046 #define YY_NO_ACTION 1187
151047 #define YY_MIN_REDUCE 1188
151048 #define YY_MAX_REDUCE 1572
151049 /************* End control #defines *******************************************/
151050 #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
151051
151052 /* Define the yytestcase() macro to be a no-op if is not already defined
151053 ** otherwise.
@@ -151112,206 +151549,206 @@
151112 ** yy_default[] Default action for each state.
151113 **
151114 *********** Begin parsing tables **********************************************/
151115 #define YY_ACTTAB_COUNT (1958)
151116 static const YYACTIONTYPE yy_action[] = {
151117 /* 0 */ 544, 1219, 544, 449, 1257, 544, 1236, 544, 114, 111,
151118 /* 10 */ 211, 544, 1534, 544, 1257, 521, 114, 111, 211, 390,
151119 /* 20 */ 1229, 342, 42, 42, 42, 42, 1222, 42, 42, 71,
151120 /* 30 */ 71, 934, 1221, 71, 71, 71, 71, 1459, 1490, 935,
151121 /* 40 */ 817, 451, 6, 121, 122, 112, 1162, 1162, 1003, 1006,
151122 /* 50 */ 996, 996, 119, 119, 120, 120, 120, 120, 1540, 390,
151123 /* 60 */ 1355, 1514, 549, 2, 1190, 194, 526, 434, 143, 291,
151124 /* 70 */ 526, 136, 526, 369, 261, 502, 272, 383, 1270, 525,
151125 /* 80 */ 501, 491, 164, 121, 122, 112, 1162, 1162, 1003, 1006,
151126 /* 90 */ 996, 996, 119, 119, 120, 120, 120, 120, 1355, 440,
151127 /* 100 */ 1511, 118, 118, 118, 118, 117, 117, 116, 116, 116,
151128 /* 110 */ 115, 422, 266, 266, 266, 266, 1495, 356, 1497, 433,
151129 /* 120 */ 355, 1495, 515, 522, 1482, 541, 1111, 541, 1111, 390,
151130 /* 130 */ 403, 241, 208, 114, 111, 211, 98, 290, 535, 221,
151131 /* 140 */ 1026, 118, 118, 118, 118, 117, 117, 116, 116, 116,
151132 /* 150 */ 115, 422, 1139, 121, 122, 112, 1162, 1162, 1003, 1006,
151133 /* 160 */ 996, 996, 119, 119, 120, 120, 120, 120, 404, 426,
151134 /* 170 */ 117, 117, 116, 116, 116, 115, 422, 1415, 466, 123,
151135 /* 180 */ 118, 118, 118, 118, 117, 117, 116, 116, 116, 115,
151136 /* 190 */ 422, 116, 116, 116, 115, 422, 538, 538, 538, 390,
151137 /* 200 */ 503, 120, 120, 120, 120, 113, 1048, 1139, 1140, 1141,
151138 /* 210 */ 1048, 118, 118, 118, 118, 117, 117, 116, 116, 116,
151139 /* 220 */ 115, 422, 1458, 121, 122, 112, 1162, 1162, 1003, 1006,
151140 /* 230 */ 996, 996, 119, 119, 120, 120, 120, 120, 390, 442,
151141 /* 240 */ 314, 83, 461, 81, 357, 380, 1139, 80, 118, 118,
151142 /* 250 */ 118, 118, 117, 117, 116, 116, 116, 115, 422, 179,
151143 /* 260 */ 432, 422, 121, 122, 112, 1162, 1162, 1003, 1006, 996,
151144 /* 270 */ 996, 119, 119, 120, 120, 120, 120, 432, 431, 266,
151145 /* 280 */ 266, 118, 118, 118, 118, 117, 117, 116, 116, 116,
151146 /* 290 */ 115, 422, 541, 1106, 900, 504, 1139, 114, 111, 211,
151147 /* 300 */ 1428, 1139, 1140, 1141, 206, 489, 1106, 390, 447, 1106,
151148 /* 310 */ 543, 328, 120, 120, 120, 120, 298, 1428, 1430, 17,
151149 /* 320 */ 118, 118, 118, 118, 117, 117, 116, 116, 116, 115,
151150 /* 330 */ 422, 121, 122, 112, 1162, 1162, 1003, 1006, 996, 996,
151151 /* 340 */ 119, 119, 120, 120, 120, 120, 390, 1355, 432, 1139,
151152 /* 350 */ 480, 1139, 1140, 1141, 993, 993, 1004, 1007, 443, 118,
151153 /* 360 */ 118, 118, 118, 117, 117, 116, 116, 116, 115, 422,
151154 /* 370 */ 121, 122, 112, 1162, 1162, 1003, 1006, 996, 996, 119,
151155 /* 380 */ 119, 120, 120, 120, 120, 1051, 1051, 463, 1428, 118,
151156 /* 390 */ 118, 118, 118, 117, 117, 116, 116, 116, 115, 422,
151157 /* 400 */ 1139, 449, 544, 1423, 1139, 1140, 1141, 233, 963, 1139,
151158 /* 410 */ 479, 476, 475, 171, 358, 390, 164, 405, 412, 839,
151159 /* 420 */ 474, 164, 185, 332, 71, 71, 1240, 997, 118, 118,
151160 /* 430 */ 118, 118, 117, 117, 116, 116, 116, 115, 422, 121,
151161 /* 440 */ 122, 112, 1162, 1162, 1003, 1006, 996, 996, 119, 119,
151162 /* 450 */ 120, 120, 120, 120, 390, 1139, 1140, 1141, 832, 12,
151163 /* 460 */ 313, 507, 163, 354, 1139, 1140, 1141, 114, 111, 211,
151164 /* 470 */ 506, 290, 535, 544, 276, 180, 290, 535, 121, 122,
151165 /* 480 */ 112, 1162, 1162, 1003, 1006, 996, 996, 119, 119, 120,
151166 /* 490 */ 120, 120, 120, 343, 482, 71, 71, 118, 118, 118,
151167 /* 500 */ 118, 117, 117, 116, 116, 116, 115, 422, 1139, 209,
151168 /* 510 */ 409, 521, 1139, 1106, 1568, 376, 252, 269, 340, 485,
151169 /* 520 */ 335, 484, 238, 390, 511, 362, 1106, 1124, 331, 1106,
151170 /* 530 */ 191, 407, 286, 32, 455, 441, 118, 118, 118, 118,
151171 /* 540 */ 117, 117, 116, 116, 116, 115, 422, 121, 122, 112,
151172 /* 550 */ 1162, 1162, 1003, 1006, 996, 996, 119, 119, 120, 120,
151173 /* 560 */ 120, 120, 390, 1139, 1140, 1141, 984, 1139, 1140, 1141,
151174 /* 570 */ 1139, 233, 490, 1489, 479, 476, 475, 6, 163, 544,
151175 /* 580 */ 510, 544, 115, 422, 474, 5, 121, 122, 112, 1162,
151176 /* 590 */ 1162, 1003, 1006, 996, 996, 119, 119, 120, 120, 120,
151177 /* 600 */ 120, 13, 13, 13, 13, 118, 118, 118, 118, 117,
151178 /* 610 */ 117, 116, 116, 116, 115, 422, 401, 500, 406, 544,
151179 /* 620 */ 1483, 542, 1139, 889, 889, 1139, 1140, 1141, 1470, 1139,
151180 /* 630 */ 275, 390, 805, 806, 807, 968, 420, 420, 420, 16,
151181 /* 640 */ 16, 55, 55, 1239, 118, 118, 118, 118, 117, 117,
151182 /* 650 */ 116, 116, 116, 115, 422, 121, 122, 112, 1162, 1162,
151183 /* 660 */ 1003, 1006, 996, 996, 119, 119, 120, 120, 120, 120,
151184 /* 670 */ 390, 1186, 1, 1, 549, 2, 1190, 1139, 1140, 1141,
151185 /* 680 */ 194, 291, 895, 136, 1139, 1140, 1141, 894, 519, 1489,
151186 /* 690 */ 1270, 3, 378, 6, 121, 122, 112, 1162, 1162, 1003,
151187 /* 700 */ 1006, 996, 996, 119, 119, 120, 120, 120, 120, 855,
151188 /* 710 */ 544, 921, 544, 118, 118, 118, 118, 117, 117, 116,
151189 /* 720 */ 116, 116, 115, 422, 266, 266, 1089, 1566, 1139, 1518,
151190 /* 730 */ 1566, 1190, 13, 13, 13, 13, 291, 541, 136, 390,
151191 /* 740 */ 483, 419, 418, 963, 342, 1270, 466, 408, 856, 279,
151192 /* 750 */ 140, 221, 118, 118, 118, 118, 117, 117, 116, 116,
151193 /* 760 */ 116, 115, 422, 121, 122, 112, 1162, 1162, 1003, 1006,
151194 /* 770 */ 996, 996, 119, 119, 120, 120, 120, 120, 544, 266,
151195 /* 780 */ 266, 426, 390, 1139, 1140, 1141, 1169, 827, 1169, 466,
151196 /* 790 */ 429, 145, 541, 1143, 399, 313, 437, 301, 835, 1487,
151197 /* 800 */ 71, 71, 410, 6, 1087, 471, 221, 100, 112, 1162,
151198 /* 810 */ 1162, 1003, 1006, 996, 996, 119, 119, 120, 120, 120,
151199 /* 820 */ 120, 118, 118, 118, 118, 117, 117, 116, 116, 116,
151200 /* 830 */ 115, 422, 237, 1422, 544, 449, 426, 287, 983, 544,
151201 /* 840 */ 236, 235, 234, 827, 97, 527, 427, 1262, 1262, 1143,
151202 /* 850 */ 492, 306, 428, 835, 974, 544, 71, 71, 973, 1238,
151203 /* 860 */ 544, 51, 51, 300, 118, 118, 118, 118, 117, 117,
151204 /* 870 */ 116, 116, 116, 115, 422, 194, 103, 70, 70, 266,
151205 /* 880 */ 266, 544, 71, 71, 266, 266, 30, 389, 342, 973,
151206 /* 890 */ 973, 975, 541, 526, 1106, 326, 390, 541, 493, 395,
151207 /* 900 */ 1467, 195, 528, 13, 13, 1355, 240, 1106, 277, 280,
151208 /* 910 */ 1106, 280, 303, 455, 305, 331, 390, 31, 188, 417,
151209 /* 920 */ 121, 122, 112, 1162, 1162, 1003, 1006, 996, 996, 119,
151210 /* 930 */ 119, 120, 120, 120, 120, 142, 390, 363, 455, 983,
151211 /* 940 */ 121, 122, 112, 1162, 1162, 1003, 1006, 996, 996, 119,
151212 /* 950 */ 119, 120, 120, 120, 120, 974, 321, 1139, 324, 973,
151213 /* 960 */ 121, 110, 112, 1162, 1162, 1003, 1006, 996, 996, 119,
151214 /* 970 */ 119, 120, 120, 120, 120, 462, 375, 1182, 118, 118,
151215 /* 980 */ 118, 118, 117, 117, 116, 116, 116, 115, 422, 1139,
151216 /* 990 */ 973, 973, 975, 304, 9, 364, 244, 360, 118, 118,
151217 /* 1000 */ 118, 118, 117, 117, 116, 116, 116, 115, 422, 312,
151218 /* 1010 */ 544, 342, 1139, 1140, 1141, 299, 290, 535, 118, 118,
151219 /* 1020 */ 118, 118, 117, 117, 116, 116, 116, 115, 422, 1260,
151220 /* 1030 */ 1260, 1160, 13, 13, 278, 419, 418, 466, 390, 920,
151221 /* 1040 */ 260, 260, 289, 1166, 1139, 1140, 1141, 189, 1168, 266,
151222 /* 1050 */ 266, 466, 388, 541, 1183, 544, 1167, 263, 144, 487,
151223 /* 1060 */ 919, 544, 541, 122, 112, 1162, 1162, 1003, 1006, 996,
151224 /* 1070 */ 996, 119, 119, 120, 120, 120, 120, 71, 71, 1139,
151225 /* 1080 */ 1169, 1269, 1169, 13, 13, 895, 1067, 1160, 544, 466,
151226 /* 1090 */ 894, 107, 536, 1488, 4, 1265, 1106, 6, 523, 1046,
151227 /* 1100 */ 12, 1068, 1089, 1567, 311, 453, 1567, 518, 539, 1106,
151228 /* 1110 */ 56, 56, 1106, 1486, 421, 1355, 1069, 6, 343, 285,
151229 /* 1120 */ 118, 118, 118, 118, 117, 117, 116, 116, 116, 115,
151230 /* 1130 */ 422, 423, 1268, 319, 1139, 1140, 1141, 875, 266, 266,
151231 /* 1140 */ 1274, 107, 536, 533, 4, 1485, 293, 876, 1208, 6,
151232 /* 1150 */ 210, 541, 541, 164, 1539, 494, 414, 864, 539, 267,
151233 /* 1160 */ 267, 1211, 396, 509, 497, 204, 266, 266, 394, 529,
151234 /* 1170 */ 8, 983, 541, 517, 544, 919, 456, 105, 105, 541,
151235 /* 1180 */ 1087, 423, 266, 266, 106, 415, 423, 546, 545, 266,
151236 /* 1190 */ 266, 973, 516, 533, 1370, 541, 15, 15, 266, 266,
151237 /* 1200 */ 454, 1117, 541, 266, 266, 1067, 1369, 513, 290, 535,
151238 /* 1210 */ 544, 541, 512, 97, 442, 314, 541, 544, 919, 125,
151239 /* 1220 */ 1068, 983, 973, 973, 975, 976, 27, 105, 105, 399,
151240 /* 1230 */ 341, 1508, 44, 44, 106, 1069, 423, 546, 545, 57,
151241 /* 1240 */ 57, 973, 341, 1508, 107, 536, 544, 4, 460, 399,
151242 /* 1250 */ 214, 1117, 457, 294, 375, 1088, 532, 297, 544, 537,
151243 /* 1260 */ 396, 539, 290, 535, 104, 244, 102, 524, 58, 58,
151244 /* 1270 */ 544, 109, 973, 973, 975, 976, 27, 1513, 1128, 425,
151245 /* 1280 */ 59, 59, 270, 237, 423, 138, 95, 373, 373, 372,
151246 /* 1290 */ 255, 370, 60, 60, 814, 1177, 533, 544, 273, 544,
151247 /* 1300 */ 1160, 842, 387, 386, 544, 1306, 544, 215, 210, 296,
151248 /* 1310 */ 513, 846, 544, 265, 208, 514, 1305, 295, 274, 61,
151249 /* 1320 */ 61, 62, 62, 436, 983, 1159, 45, 45, 46, 46,
151250 /* 1330 */ 105, 105, 1183, 919, 47, 47, 1473, 106, 544, 423,
151251 /* 1340 */ 546, 545, 218, 544, 973, 934, 1084, 217, 544, 377,
151252 /* 1350 */ 395, 107, 536, 935, 4, 156, 1160, 842, 158, 544,
151253 /* 1360 */ 49, 49, 141, 544, 38, 50, 50, 544, 539, 307,
151254 /* 1370 */ 63, 63, 544, 1447, 216, 973, 973, 975, 976, 27,
151255 /* 1380 */ 444, 64, 64, 544, 1446, 65, 65, 544, 524, 14,
151256 /* 1390 */ 14, 423, 458, 544, 66, 66, 310, 544, 316, 97,
151257 /* 1400 */ 1033, 544, 960, 533, 268, 127, 127, 544, 391, 67,
151258 /* 1410 */ 67, 544, 977, 290, 535, 52, 52, 513, 544, 68,
151259 /* 1420 */ 68, 1293, 512, 69, 69, 397, 165, 854, 853, 53,
151260 /* 1430 */ 53, 983, 965, 151, 151, 243, 430, 105, 105, 199,
151261 /* 1440 */ 152, 152, 448, 1302, 106, 243, 423, 546, 545, 1128,
151262 /* 1450 */ 425, 973, 320, 270, 861, 862, 1033, 220, 373, 373,
151263 /* 1460 */ 372, 255, 370, 450, 323, 814, 243, 544, 977, 544,
151264 /* 1470 */ 107, 536, 544, 4, 544, 937, 938, 325, 215, 1045,
151265 /* 1480 */ 296, 1045, 973, 973, 975, 976, 27, 539, 295, 76,
151266 /* 1490 */ 76, 54, 54, 327, 72, 72, 128, 128, 1502, 1253,
151267 /* 1500 */ 107, 536, 544, 4, 1044, 544, 1044, 531, 1237, 544,
151268 /* 1510 */ 423, 544, 315, 334, 544, 97, 544, 539, 217, 544,
151269 /* 1520 */ 472, 1527, 533, 239, 73, 73, 156, 129, 129, 158,
151270 /* 1530 */ 467, 130, 130, 126, 126, 344, 150, 150, 149, 149,
151271 /* 1540 */ 423, 134, 134, 329, 1029, 216, 97, 239, 928, 345,
151272 /* 1550 */ 983, 243, 533, 1314, 339, 544, 105, 105, 899, 1354,
151273 /* 1560 */ 544, 1289, 258, 106, 338, 423, 546, 545, 544, 1300,
151274 /* 1570 */ 973, 892, 99, 536, 109, 4, 544, 133, 133, 391,
151275 /* 1580 */ 983, 197, 131, 131, 290, 535, 105, 105, 530, 539,
151276 /* 1590 */ 132, 132, 1360, 106, 1218, 423, 546, 545, 75, 75,
151277 /* 1600 */ 973, 973, 973, 975, 976, 27, 544, 430, 825, 1210,
151278 /* 1610 */ 893, 139, 423, 109, 544, 1199, 1198, 1200, 1521, 544,
151279 /* 1620 */ 201, 544, 11, 374, 533, 1286, 347, 349, 77, 77,
151280 /* 1630 */ 1339, 973, 973, 975, 976, 27, 74, 74, 351, 213,
151281 /* 1640 */ 435, 43, 43, 48, 48, 302, 477, 309, 1347, 382,
151282 /* 1650 */ 353, 452, 983, 337, 1236, 1419, 1418, 205, 105, 105,
151283 /* 1660 */ 192, 367, 193, 534, 1524, 106, 1177, 423, 546, 545,
151284 /* 1670 */ 247, 167, 973, 270, 1466, 200, 1464, 1174, 373, 373,
151285 /* 1680 */ 372, 255, 370, 398, 79, 814, 83, 82, 1424, 446,
151286 /* 1690 */ 161, 177, 169, 95, 1336, 438, 172, 173, 215, 174,
151287 /* 1700 */ 296, 175, 35, 973, 973, 975, 976, 27, 295, 1344,
151288 /* 1710 */ 439, 470, 223, 36, 379, 445, 1413, 381, 459, 1350,
151289 /* 1720 */ 181, 227, 88, 465, 259, 229, 1435, 318, 186, 468,
151290 /* 1730 */ 322, 230, 384, 1201, 231, 486, 1256, 1255, 217, 411,
151291 /* 1740 */ 1254, 1247, 90, 846, 206, 413, 156, 505, 1538, 158,
151292 /* 1750 */ 1225, 1537, 283, 1507, 1226, 336, 385, 284, 1224, 496,
151293 /* 1760 */ 1536, 1297, 94, 346, 348, 216, 1246, 499, 1298, 245,
151294 /* 1770 */ 246, 1296, 416, 350, 1493, 124, 1492, 10, 524, 361,
151295 /* 1780 */ 1399, 101, 96, 288, 508, 253, 1134, 1207, 34, 1295,
151296 /* 1790 */ 547, 254, 256, 257, 392, 548, 1196, 1191, 359, 391,
151297 /* 1800 */ 1279, 1278, 196, 365, 290, 535, 366, 352, 1451, 1321,
151298 /* 1810 */ 1320, 1452, 153, 137, 281, 154, 801, 424, 155, 1450,
151299 /* 1820 */ 1449, 198, 292, 202, 203, 78, 212, 430, 271, 135,
151300 /* 1830 */ 1043, 1041, 957, 168, 219, 157, 170, 878, 308, 222,
151301 /* 1840 */ 1057, 176, 159, 961, 400, 84, 402, 178, 85, 86,
151302 /* 1850 */ 87, 166, 160, 393, 1060, 224, 225, 1056, 146, 18,
151303 /* 1860 */ 226, 317, 1049, 1171, 243, 464, 182, 228, 37, 183,
151304 /* 1870 */ 816, 469, 338, 232, 330, 481, 184, 89, 844, 19,
151305 /* 1880 */ 20, 92, 473, 478, 333, 91, 162, 857, 147, 488,
151306 /* 1890 */ 282, 1122, 148, 1009, 927, 1092, 39, 93, 40, 495,
151307 /* 1900 */ 1093, 187, 498, 207, 262, 264, 922, 242, 1108, 109,
151308 /* 1910 */ 1112, 1110, 1096, 33, 21, 1116, 520, 1024, 22, 23,
151309 /* 1920 */ 24, 1115, 25, 190, 97, 1010, 1008, 26, 1012, 1066,
151310 /* 1930 */ 248, 7, 1065, 249, 1013, 28, 41, 888, 978, 826,
151311 /* 1940 */ 108, 29, 250, 540, 251, 1529, 371, 368, 1129, 1187,
151312 /* 1950 */ 1187, 1187, 1187, 1187, 1187, 1187, 1187, 1528,
151313 };
151314 static const YYCODETYPE yy_lookahead[] = {
151315 /* 0 */ 189, 211, 189, 189, 218, 189, 220, 189, 267, 268,
151316 /* 10 */ 269, 189, 210, 189, 228, 189, 267, 268, 269, 19,
151317 /* 20 */ 218, 189, 211, 212, 211, 212, 211, 211, 212, 211,
@@ -151504,11 +151941,11 @@
151504 /* 1890 */ 67, 23, 23, 23, 114, 23, 22, 26, 22, 24,
151505 /* 1900 */ 23, 22, 24, 139, 23, 23, 141, 34, 88, 26,
151506 /* 1910 */ 75, 86, 23, 22, 34, 75, 24, 23, 34, 34,
151507 /* 1920 */ 34, 93, 34, 26, 26, 23, 23, 34, 23, 23,
151508 /* 1930 */ 26, 44, 23, 22, 11, 22, 22, 133, 23, 23,
151509 /* 1940 */ 22, 22, 139, 26, 139, 139, 15, 23, 1, 310,
151510 /* 1950 */ 310, 310, 310, 310, 310, 310, 310, 139, 310, 310,
151511 /* 1960 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
151512 /* 1970 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
151513 /* 1980 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
151514 /* 1990 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
@@ -151525,13 +151962,13 @@
151525 /* 2100 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
151526 /* 2110 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
151527 /* 2120 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
151528 /* 2130 */ 310, 310, 310, 310, 310, 310, 310, 310, 310,
151529 };
151530 #define YY_SHIFT_COUNT (549)
151531 #define YY_SHIFT_MIN (0)
151532 #define YY_SHIFT_MAX (1947)
151533 static const unsigned short int yy_shift_ofst[] = {
151534 /* 0 */ 1448, 1277, 1668, 1072, 1072, 340, 1122, 1225, 1332, 1481,
151535 /* 10 */ 1481, 1481, 335, 0, 0, 180, 897, 1481, 1481, 1481,
151536 /* 20 */ 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481,
151537 /* 30 */ 930, 930, 1020, 1020, 290, 1, 340, 340, 340, 340,
@@ -151584,10 +152021,11 @@
151584 /* 500 */ 1764, 1881, 1882, 1780, 1873, 1879, 1765, 1883, 1880, 1884,
151585 /* 510 */ 1885, 1886, 1820, 1835, 1825, 1887, 1840, 1828, 1888, 1889,
151586 /* 520 */ 1891, 1892, 1897, 1898, 1893, 1894, 1883, 1902, 1903, 1905,
151587 /* 530 */ 1906, 1904, 1909, 1911, 1923, 1913, 1914, 1915, 1916, 1918,
151588 /* 540 */ 1919, 1917, 1804, 1803, 1805, 1806, 1818, 1924, 1931, 1947,
 
151589 };
151590 #define YY_REDUCE_COUNT (389)
151591 #define YY_REDUCE_MIN (-262)
151592 #define YY_REDUCE_MAX (1617)
151593 static const short yy_reduce_ofst[] = {
@@ -151630,65 +152068,66 @@
151630 /* 360 */ 1554, 1510, 1583, 1511, 1556, 1559, 1561, 1565, 1588, 1592,
151631 /* 370 */ 1601, 1602, 1607, 1608, 1609, 1498, 1557, 1558, 1610, 1600,
151632 /* 380 */ 1603, 1611, 1612, 1613, 1596, 1597, 1614, 1615, 1617, 1616,
151633 };
151634 static const YYACTIONTYPE yy_default[] = {
151635 /* 0 */ 1572, 1572, 1572, 1408, 1185, 1294, 1185, 1185, 1185, 1408,
151636 /* 10 */ 1408, 1408, 1185, 1324, 1324, 1461, 1216, 1185, 1185, 1185,
151637 /* 20 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1407, 1185, 1185,
151638 /* 30 */ 1185, 1185, 1491, 1491, 1185, 1185, 1185, 1185, 1185, 1185,
151639 /* 40 */ 1185, 1185, 1185, 1333, 1185, 1185, 1185, 1185, 1185, 1185,
151640 /* 50 */ 1409, 1410, 1185, 1185, 1185, 1460, 1462, 1425, 1343, 1342,
151641 /* 60 */ 1341, 1340, 1443, 1311, 1338, 1331, 1335, 1403, 1404, 1402,
151642 /* 70 */ 1406, 1410, 1409, 1185, 1334, 1374, 1388, 1373, 1185, 1185,
151643 /* 80 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151644 /* 90 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151645 /* 100 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151646 /* 110 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151647 /* 120 */ 1185, 1185, 1185, 1185, 1185, 1185, 1382, 1387, 1393, 1386,
151648 /* 130 */ 1383, 1376, 1375, 1377, 1378, 1185, 1206, 1258, 1185, 1185,
151649 /* 140 */ 1185, 1185, 1479, 1478, 1185, 1185, 1216, 1368, 1367, 1379,
151650 /* 150 */ 1380, 1390, 1389, 1468, 1526, 1525, 1426, 1185, 1185, 1185,
151651 /* 160 */ 1185, 1185, 1185, 1491, 1185, 1185, 1185, 1185, 1185, 1185,
151652 /* 170 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151653 /* 180 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1491, 1491,
151654 /* 190 */ 1185, 1216, 1491, 1491, 1212, 1212, 1318, 1185, 1474, 1294,
151655 /* 200 */ 1285, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151656 /* 210 */ 1185, 1185, 1185, 1185, 1185, 1465, 1463, 1185, 1185, 1185,
151657 /* 220 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151658 /* 230 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151659 /* 240 */ 1185, 1185, 1185, 1185, 1185, 1290, 1185, 1185, 1185, 1185,
151660 /* 250 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1520, 1185, 1438,
151661 /* 260 */ 1272, 1290, 1290, 1290, 1290, 1292, 1273, 1271, 1284, 1217,
151662 /* 270 */ 1192, 1564, 1337, 1313, 1313, 1561, 1337, 1337, 1561, 1233,
151663 /* 280 */ 1542, 1228, 1324, 1324, 1324, 1313, 1318, 1318, 1405, 1291,
151664 /* 290 */ 1284, 1185, 1564, 1299, 1299, 1563, 1563, 1299, 1426, 1346,
151665 /* 300 */ 1352, 1261, 1337, 1267, 1267, 1267, 1267, 1299, 1203, 1337,
151666 /* 310 */ 1337, 1346, 1352, 1261, 1261, 1337, 1299, 1203, 1442, 1558,
151667 /* 320 */ 1299, 1203, 1416, 1299, 1203, 1299, 1203, 1416, 1259, 1259,
151668 /* 330 */ 1259, 1248, 1185, 1185, 1416, 1259, 1233, 1259, 1248, 1259,
151669 /* 340 */ 1259, 1509, 1416, 1420, 1420, 1416, 1317, 1312, 1317, 1312,
151670 /* 350 */ 1317, 1312, 1317, 1312, 1299, 1501, 1501, 1327, 1327, 1332,
151671 /* 360 */ 1318, 1411, 1299, 1185, 1332, 1330, 1328, 1337, 1209, 1251,
151672 /* 370 */ 1523, 1523, 1519, 1519, 1519, 1569, 1569, 1474, 1535, 1216,
151673 /* 380 */ 1216, 1216, 1216, 1535, 1235, 1235, 1217, 1217, 1216, 1535,
151674 /* 390 */ 1185, 1185, 1185, 1185, 1185, 1185, 1530, 1185, 1427, 1303,
151675 /* 400 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151676 /* 410 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151677 /* 420 */ 1185, 1185, 1185, 1357, 1185, 1188, 1471, 1185, 1185, 1469,
151678 /* 430 */ 1185, 1185, 1185, 1185, 1185, 1185, 1304, 1185, 1185, 1185,
151679 /* 440 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151680 /* 450 */ 1185, 1185, 1185, 1185, 1185, 1560, 1185, 1185, 1185, 1185,
151681 /* 460 */ 1185, 1185, 1441, 1440, 1185, 1185, 1301, 1185, 1185, 1185,
151682 /* 470 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151683 /* 480 */ 1231, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151684 /* 490 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151685 /* 500 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1329, 1185, 1185,
151686 /* 510 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151687 /* 520 */ 1185, 1185, 1506, 1319, 1185, 1185, 1551, 1185, 1185, 1185,
151688 /* 530 */ 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185, 1185,
151689 /* 540 */ 1185, 1546, 1275, 1359, 1185, 1358, 1362, 1185, 1197, 1185,
 
151690 };
151691 /********** End of lemon-generated parsing tables *****************************/
151692
151693 /* The next table maps tokens (terminal symbols) into fallback tokens.
151694 ** If a construct like the following:
@@ -152619,11 +153058,11 @@
152619 /* 325 */ "input ::= cmdlist",
152620 /* 326 */ "cmdlist ::= cmdlist ecmd",
152621 /* 327 */ "cmdlist ::= ecmd",
152622 /* 328 */ "ecmd ::= SEMI",
152623 /* 329 */ "ecmd ::= cmdx SEMI",
152624 /* 330 */ "ecmd ::= explain cmdx",
152625 /* 331 */ "trans_opt ::=",
152626 /* 332 */ "trans_opt ::= TRANSACTION",
152627 /* 333 */ "trans_opt ::= TRANSACTION nm",
152628 /* 334 */ "savepoint_opt ::= SAVEPOINT",
152629 /* 335 */ "savepoint_opt ::=",
@@ -153511,11 +153950,11 @@
153511 181, /* (325) input ::= cmdlist */
153512 182, /* (326) cmdlist ::= cmdlist ecmd */
153513 182, /* (327) cmdlist ::= ecmd */
153514 183, /* (328) ecmd ::= SEMI */
153515 183, /* (329) ecmd ::= cmdx SEMI */
153516 183, /* (330) ecmd ::= explain cmdx */
153517 188, /* (331) trans_opt ::= */
153518 188, /* (332) trans_opt ::= TRANSACTION */
153519 188, /* (333) trans_opt ::= TRANSACTION nm */
153520 190, /* (334) savepoint_opt ::= SAVEPOINT */
153521 190, /* (335) savepoint_opt ::= */
@@ -153901,11 +154340,11 @@
153901 -1, /* (325) input ::= cmdlist */
153902 -2, /* (326) cmdlist ::= cmdlist ecmd */
153903 -1, /* (327) cmdlist ::= ecmd */
153904 -1, /* (328) ecmd ::= SEMI */
153905 -2, /* (329) ecmd ::= cmdx SEMI */
153906 -2, /* (330) ecmd ::= explain cmdx */
153907 0, /* (331) trans_opt ::= */
153908 -1, /* (332) trans_opt ::= TRANSACTION */
153909 -2, /* (333) trans_opt ::= TRANSACTION nm */
153910 -1, /* (334) savepoint_opt ::= SAVEPOINT */
153911 0, /* (335) savepoint_opt ::= */
@@ -153989,16 +154428,19 @@
153989 yymsp = yypParser->yytos;
153990 #ifndef NDEBUG
153991 if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
153992 yysize = yyRuleInfoNRhs[yyruleno];
153993 if( yysize ){
153994 fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n",
153995 yyTracePrompt,
153996 yyruleno, yyRuleName[yyruleno], yymsp[yysize].stateno);
 
 
153997 }else{
153998 fprintf(yyTraceFILE, "%sReduce %d [%s].\n",
153999 yyTracePrompt, yyruleno, yyRuleName[yyruleno]);
 
154000 }
154001 }
154002 #endif /* NDEBUG */
154003
154004 /* Check that the stack is large enough to grow by a single entry
@@ -155405,11 +155847,11 @@
155405 /* (325) input ::= cmdlist */ yytestcase(yyruleno==325);
155406 /* (326) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==326);
155407 /* (327) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=327);
155408 /* (328) ecmd ::= SEMI */ yytestcase(yyruleno==328);
155409 /* (329) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==329);
155410 /* (330) ecmd ::= explain cmdx */ yytestcase(yyruleno==330);
155411 /* (331) trans_opt ::= */ yytestcase(yyruleno==331);
155412 /* (332) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==332);
155413 /* (333) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==333);
155414 /* (334) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==334);
155415 /* (335) savepoint_opt ::= */ yytestcase(yyruleno==335);
@@ -163082,10 +163524,13 @@
163082 # define TESTONLY(X) X
163083 #else
163084 # define TESTONLY(X)
163085 #endif
163086
 
 
 
163087 #endif /* SQLITE_AMALGAMATION */
163088
163089 #ifdef SQLITE_DEBUG
163090 SQLITE_PRIVATE int sqlite3Fts3Corrupt(void);
163091 # define FTS_CORRUPT_VTAB sqlite3Fts3Corrupt()
@@ -163125,10 +163570,11 @@
163125 sqlite3_tokenizer *pTokenizer; /* tokenizer for inserts and queries */
163126 char *zContentTbl; /* content=xxx option, or NULL */
163127 char *zLanguageid; /* languageid=xxx option, or NULL */
163128 int nAutoincrmerge; /* Value configured by 'automerge' */
163129 u32 nLeafAdd; /* Number of leaf blocks added this trans */
 
163130
163131 /* Precompiled statements used by the implementation. Each of these
163132 ** statements is run and reset within a single virtual table API call.
163133 */
163134 sqlite3_stmt *aStmt[40];
@@ -163463,10 +163909,11 @@
163463
163464 /* fts3.c */
163465 SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char**,const char*,...);
163466 SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
163467 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
 
163468 SQLITE_PRIVATE int sqlite3Fts3GetVarintBounded(const char*,const char*,sqlite3_int64*);
163469 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
163470 SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64);
163471 SQLITE_PRIVATE void sqlite3Fts3Dequote(char *);
163472 SQLITE_PRIVATE void sqlite3Fts3DoclistPrev(int,char*,int,char**,sqlite3_int64*,int*,u8*);
@@ -163550,22 +163997,10 @@
163550 #ifndef SQLITE_CORE
163551 /* # include "sqlite3ext.h" */
163552 SQLITE_EXTENSION_INIT1
163553 #endif
163554
163555 /*
163556 ** The following are copied from sqliteInt.h.
163557 **
163558 ** Constants for the largest and smallest possible 64-bit signed integers.
163559 ** These macros are designed to work correctly on both 32-bit and 64-bit
163560 ** compilers.
163561 */
163562 #ifndef SQLITE_AMALGAMATION
163563 # define LARGEST_INT64 (0xffffffff|(((sqlite3_int64)0x7fffffff)<<32))
163564 # define SMALLEST_INT64 (((sqlite3_int64)-1) - LARGEST_INT64)
163565 #endif
163566
163567 static int fts3EvalNext(Fts3Cursor *pCsr);
163568 static int fts3EvalStart(Fts3Cursor *pCsr);
163569 static int fts3TermSegReaderCursor(
163570 Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **);
163571
@@ -163606,16 +164041,11 @@
163606 if( (v & mask2)==0 ){ var = v; return ret; }
163607 #define GETVARINT_INIT(v, ptr, shift, mask1, mask2, var, ret) \
163608 v = (*ptr++); \
163609 if( (v & mask2)==0 ){ var = v; return ret; }
163610
163611 /*
163612 ** Read a 64-bit variable-length integer from memory starting at p[0].
163613 ** Return the number of bytes read, or 0 on error.
163614 ** The value is stored in *v.
163615 */
163616 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *pBuf, sqlite_int64 *v){
163617 const unsigned char *p = (const unsigned char*)pBuf;
163618 const unsigned char *pStart = p;
163619 u32 a;
163620 u64 b;
163621 int shift;
@@ -163632,10 +164062,19 @@
163632 if( (c & 0x80)==0 ) break;
163633 }
163634 *v = b;
163635 return (int)(p - pStart);
163636 }
 
 
 
 
 
 
 
 
 
163637
163638 /*
163639 ** Read a 64-bit variable-length integer from memory starting at p[0] and
163640 ** not extending past pEnd[-1].
163641 ** Return the number of bytes read, or 0 on error.
@@ -164852,10 +165291,14 @@
164852
164853 int iLangidCons = -1; /* Index of langid=x constraint, if present */
164854 int iDocidGe = -1; /* Index of docid>=x constraint, if present */
164855 int iDocidLe = -1; /* Index of docid<=x constraint, if present */
164856 int iIdx;
 
 
 
 
164857
164858 /* By default use a full table scan. This is an expensive option,
164859 ** so search through the constraints to see if a more efficient
164860 ** strategy is possible.
164861 */
@@ -165051,11 +165494,15 @@
165051 pCsr->pStmt = p->pSeekStmt;
165052 p->pSeekStmt = 0;
165053 }else{
165054 zSql = sqlite3_mprintf("SELECT %s WHERE rowid = ?", p->zReadExprlist);
165055 if( !zSql ) return SQLITE_NOMEM;
165056 rc = sqlite3_prepare_v3(p->db, zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0);
 
 
 
 
165057 sqlite3_free(zSql);
165058 }
165059 if( rc==SQLITE_OK ) pCsr->bSeekStmt = 1;
165060 }
165061 return rc;
@@ -165069,15 +165516,19 @@
165069 static int fts3CursorSeek(sqlite3_context *pContext, Fts3Cursor *pCsr){
165070 int rc = SQLITE_OK;
165071 if( pCsr->isRequireSeek ){
165072 rc = fts3CursorSeekStmt(pCsr);
165073 if( rc==SQLITE_OK ){
 
 
165074 sqlite3_bind_int64(pCsr->pStmt, 1, pCsr->iPrevId);
165075 pCsr->isRequireSeek = 0;
165076 if( SQLITE_ROW==sqlite3_step(pCsr->pStmt) ){
 
165077 return SQLITE_OK;
165078 }else{
 
165079 rc = sqlite3_reset(pCsr->pStmt);
165080 if( rc==SQLITE_OK && ((Fts3Table *)pCsr->base.pVtab)->zContentTbl==0 ){
165081 /* If no row was found and no error has occurred, then the %_content
165082 ** table is missing a row that is present in the full-text index.
165083 ** The data structures are corrupt. */
@@ -165245,11 +165696,11 @@
165245
165246 assert( piLeaf || piLeaf2 );
165247
165248 fts3GetVarint32(zNode, &iHeight);
165249 rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2);
165250 assert( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) );
165251
165252 if( rc==SQLITE_OK && iHeight>1 ){
165253 char *zBlob = 0; /* Blob read from %_segments table */
165254 int nBlob = 0; /* Size of zBlob in bytes */
165255
@@ -165726,16 +166177,16 @@
165726 sqlite3_int64 *pVal /* IN/OUT: Integer value */
165727 ){
165728 if( *pp>=pEnd ){
165729 *pp = 0;
165730 }else{
165731 sqlite3_int64 iVal;
165732 *pp += sqlite3Fts3GetVarint(*pp, &iVal);
165733 if( bDescIdx ){
165734 *pVal -= iVal;
165735 }else{
165736 *pVal += iVal;
165737 }
165738 }
165739 }
165740
165741 /*
@@ -165761,14 +166212,14 @@
165761 sqlite3_int64 iVal /* Write this value to the list */
165762 ){
165763 sqlite3_uint64 iWrite;
165764 if( bDescIdx==0 || *pbFirst==0 ){
165765 assert_fts3_nc( *pbFirst==0 || iVal>=*piPrev );
165766 iWrite = iVal - *piPrev;
165767 }else{
165768 assert_fts3_nc( *piPrev>=iVal );
165769 iWrite = *piPrev - iVal;
165770 }
165771 assert( *pbFirst || *piPrev==0 );
165772 assert_fts3_nc( *pbFirst==0 || iWrite>0 );
165773 *pp += sqlite3Fts3PutVarint(*pp, iWrite);
165774 *piPrev = iVal;
@@ -165783,11 +166234,12 @@
165783 ** Otherwise, (i2-i1).
165784 **
165785 ** Using this makes it easier to write code that can merge doclists that are
165786 ** sorted in either ascending or descending order.
165787 */
165788 #define DOCID_CMP(i1, i2) ((bDescDoclist?-1:1) * (i1-i2))
 
165789
165790 /*
165791 ** This function does an "OR" merge of two doclists (output contains all
165792 ** positions contained in either argument doclist). If the docids in the
165793 ** input doclists are sorted in ascending order, parameter bDescDoclist
@@ -166197,11 +166649,11 @@
166197 ** for the pending-terms. If this is a scan, then this call must be being
166198 ** made by an fts4aux module, not an FTS table. In this case calling
166199 ** Fts3SegReaderPending might segfault, as the data structures used by
166200 ** fts4aux are not completely populated. So it's easiest to filter these
166201 ** calls out here. */
166202 if( iLevel<0 && p->aIndex ){
166203 Fts3SegReader *pSeg = 0;
166204 rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix||isScan, &pSeg);
166205 if( rc==SQLITE_OK && pSeg ){
166206 rc = fts3SegReaderCursorAppend(pCsr, pSeg);
166207 }
@@ -166460,17 +166912,20 @@
166460 */
166461 static int fts3NextMethod(sqlite3_vtab_cursor *pCursor){
166462 int rc;
166463 Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
166464 if( pCsr->eSearch==FTS3_DOCID_SEARCH || pCsr->eSearch==FTS3_FULLSCAN_SEARCH ){
 
 
166465 if( SQLITE_ROW!=sqlite3_step(pCsr->pStmt) ){
166466 pCsr->isEof = 1;
166467 rc = sqlite3_reset(pCsr->pStmt);
166468 }else{
166469 pCsr->iPrevId = sqlite3_column_int64(pCsr->pStmt, 0);
166470 rc = SQLITE_OK;
166471 }
 
166472 }else{
166473 rc = fts3EvalNext((Fts3Cursor *)pCursor);
166474 }
166475 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
166476 return rc;
@@ -166526,10 +166981,14 @@
166526 sqlite3_value *pDocidLe = 0; /* The "docid <= ?" constraint, if any */
166527 int iIdx;
166528
166529 UNUSED_PARAMETER(idxStr);
166530 UNUSED_PARAMETER(nVal);
 
 
 
 
166531
166532 eSearch = (idxNum & 0x0000FFFF);
166533 assert( eSearch>=0 && eSearch<=(FTS3_FULLTEXT_SEARCH+p->nColumn) );
166534 assert( p->pSegments==0 );
166535
@@ -166598,11 +167057,15 @@
166598 zSql = sqlite3_mprintf("SELECT %s ORDER BY rowid %s",
166599 p->zReadExprlist, (pCsr->bDesc ? "DESC" : "ASC")
166600 );
166601 }
166602 if( zSql ){
166603 rc = sqlite3_prepare_v3(p->db,zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0);
 
 
 
 
166604 sqlite3_free(zSql);
166605 }else{
166606 rc = SQLITE_NOMEM;
166607 }
166608 }else if( eSearch==FTS3_DOCID_SEARCH ){
@@ -167757,19 +168220,20 @@
167757 Fts3Table *pTab,
167758 Fts3Doclist *pDL,
167759 u8 *pbEof
167760 ){
167761 char *pIter; /* Used to iterate through aAll */
167762 char *pEnd = &pDL->aAll[pDL->nAll]; /* 1 byte past end of aAll */
167763
167764 if( pDL->pNextDocid ){
167765 pIter = pDL->pNextDocid;
 
167766 }else{
167767 pIter = pDL->aAll;
167768 }
167769
167770 if( pIter>=pEnd ){
167771 /* We have already reached the end of this doclist. EOF. */
167772 *pbEof = 1;
167773 }else{
167774 sqlite3_int64 iDelta;
167775 pIter += sqlite3Fts3GetVarint(pIter, &iDelta);
@@ -174105,11 +174569,11 @@
174105 int rc = SQLITE_OK;
174106
174107 assert( !p || p->iLastDocid<=iDocid );
174108
174109 if( !p || p->iLastDocid!=iDocid ){
174110 sqlite3_int64 iDelta = iDocid - (p ? p->iLastDocid : 0);
174111 if( p ){
174112 assert( p->nData<p->nSpace );
174113 assert( p->aData[p->nData]==0 );
174114 p->nData++;
174115 }
@@ -174646,10 +175110,12 @@
174646 aByte = 0;
174647 }
174648 }
174649 *paBlob = aByte;
174650 }
 
 
174651 }
174652
174653 return rc;
174654 }
174655
@@ -174938,22 +175404,22 @@
174938 if( p>=pEnd ){
174939 pReader->pOffsetList = 0;
174940 }else{
174941 rc = fts3SegReaderRequire(pReader, p, FTS3_VARINT_MAX);
174942 if( rc==SQLITE_OK ){
174943 sqlite3_int64 iDelta;
174944 pReader->pOffsetList = p + sqlite3Fts3GetVarint(p, &iDelta);
174945 if( pTab->bDescIdx ){
174946 pReader->iDocid -= iDelta;
174947 }else{
174948 pReader->iDocid += iDelta;
174949 }
174950 }
174951 }
174952 }
174953
174954 return SQLITE_OK;
174955 }
174956
174957
174958 SQLITE_PRIVATE int sqlite3Fts3MsrOvfl(
174959 Fts3Cursor *pCsr,
@@ -175688,10 +176154,11 @@
175688
175689 if( nData>0 && nData+nReq>p->nNodeSize ){
175690 int rc;
175691
175692 /* The current leaf node is full. Write it out to the database. */
 
175693 rc = fts3WriteSegment(p, pWriter->iFree++, pWriter->aData, nData);
175694 if( rc!=SQLITE_OK ) return rc;
175695 p->nLeafAdd++;
175696
175697 /* Add the current term to the interior node tree. The term added to
@@ -176385,14 +176852,14 @@
176385 /* Calculate the 'docid' delta value to write into the merged
176386 ** doclist. */
176387 sqlite3_int64 iDelta;
176388 if( p->bDescIdx && nDoclist>0 ){
176389 if( iPrev<=iDocid ) return FTS_CORRUPT_VTAB;
176390 iDelta = iPrev - iDocid;
176391 }else{
176392 if( nDoclist>0 && iPrev>=iDocid ) return FTS_CORRUPT_VTAB;
176393 iDelta = iDocid - iPrev;
176394 }
176395
176396 nByte = sqlite3Fts3VarintLen(iDelta) + (isRequirePos?nList+1:0);
176397 if( nDoclist+nByte>pCsr->nBuffer ){
176398 char *aNew;
@@ -176671,11 +177138,11 @@
176671 if( rc!=SQLITE_ROW ) break;
176672 rc = fts3SegWriterAdd(p, &pWriter, 1,
176673 csr.zTerm, csr.nTerm, csr.aDoclist, csr.nDoclist);
176674 }
176675 if( rc!=SQLITE_OK ) goto finished;
176676 assert( pWriter || bIgnoreEmpty );
176677
176678 if( iLevel!=FTS3_SEGCURSOR_PENDING ){
176679 rc = fts3DeleteSegdir(
176680 p, iLangid, iIndex, iLevel, csr.apSegment, csr.nSegment
176681 );
@@ -178257,17 +178724,21 @@
178257 */
178258 static int fts3IncrmergeHintPop(Blob *pHint, i64 *piAbsLevel, int *pnInput){
178259 const int nHint = pHint->n;
178260 int i;
178261
178262 i = pHint->n-2;
 
178263 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
 
 
178264 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
178265
178266 pHint->n = i;
178267 i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel);
178268 i += fts3GetVarint32(&pHint->a[i], pnInput);
 
178269 if( i!=nHint ) return FTS_CORRUPT_VTAB;
178270
178271 return SQLITE_OK;
178272 }
178273
@@ -178593,28 +179064,28 @@
178593 char *pCsr = csr.aDoclist;
178594 char *pEnd = &pCsr[csr.nDoclist];
178595
178596 i64 iDocid = 0;
178597 i64 iCol = 0;
178598 i64 iPos = 0;
178599
178600 pCsr += sqlite3Fts3GetVarint(pCsr, &iDocid);
178601 while( pCsr<pEnd ){
178602 i64 iVal = 0;
178603 pCsr += sqlite3Fts3GetVarint(pCsr, &iVal);
178604 if( pCsr<pEnd ){
178605 if( iVal==0 || iVal==1 ){
178606 iCol = 0;
178607 iPos = 0;
178608 if( iVal ){
178609 pCsr += sqlite3Fts3GetVarint(pCsr, &iCol);
178610 }else{
178611 pCsr += sqlite3Fts3GetVarint(pCsr, &iVal);
178612 if( p->bDescIdx ){
178613 iDocid -= iVal;
178614 }else{
178615 iDocid += iVal;
178616 }
178617 }
178618 }else{
178619 iPos += (iVal - 2);
178620 cksum = cksum ^ fts3ChecksumEntry(
@@ -182886,22 +183357,53 @@
182886 pRoot->jnFlags |= JNODE_APPEND;
182887 pParse->aNode[iLabel].jnFlags |= JNODE_RAW;
182888 }
182889 return pNode;
182890 }
182891 }else if( zPath[0]=='[' && safe_isdigit(zPath[1]) ){
182892 if( pRoot->eType!=JSON_ARRAY ) return 0;
182893 i = 0;
182894 j = 1;
182895 while( safe_isdigit(zPath[j]) ){
182896 i = i*10 + zPath[j] - '0';
182897 j++;
182898 }
182899 if( zPath[j]!=']' ){
182900 *pzErr = zPath;
182901 return 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182902 }
 
182903 zPath += j + 1;
182904 j = 1;
182905 for(;;){
182906 while( j<=pRoot->n && (i>0 || (pRoot[j].jnFlags & JNODE_REMOVE)!=0) ){
182907 if( (pRoot[j].jnFlags & JNODE_REMOVE)==0 ) i--;
@@ -184365,10 +184867,11 @@
184365 /* #include "sqlite3ext.h" */
184366 SQLITE_EXTENSION_INIT1
184367 #else
184368 /* #include "sqlite3.h" */
184369 #endif
 
184370
184371 #ifndef SQLITE_AMALGAMATION
184372 #include "sqlite3rtree.h"
184373 typedef sqlite3_int64 i64;
184374 typedef sqlite3_uint64 u64;
@@ -184628,10 +185131,16 @@
184628 #define RTREE_GE 0x44 /* D */
184629 #define RTREE_GT 0x45 /* E */
184630 #define RTREE_MATCH 0x46 /* F: Old-style sqlite3_rtree_geometry_callback() */
184631 #define RTREE_QUERY 0x47 /* G: New-style sqlite3_rtree_query_callback() */
184632
 
 
 
 
 
 
184633
184634 /*
184635 ** An rtree structure node.
184636 */
184637 struct RtreeNode {
@@ -185361,13 +185870,16 @@
185361 return rc;
185362 }
185363
185364
185365 /*
185366 ** Free the RtreeCursor.aConstraint[] array and its contents.
185367 */
185368 static void freeCursorConstraints(RtreeCursor *pCsr){
 
 
 
185369 if( pCsr->aConstraint ){
185370 int i; /* Used to iterate through constraint array */
185371 for(i=0; i<pCsr->nConstraint; i++){
185372 sqlite3_rtree_query_info *pInfo = pCsr->aConstraint[i].pInfo;
185373 if( pInfo ){
@@ -185376,24 +185888,28 @@
185376 }
185377 }
185378 sqlite3_free(pCsr->aConstraint);
185379 pCsr->aConstraint = 0;
185380 }
 
 
 
 
 
 
 
185381 }
185382
185383 /*
185384 ** Rtree virtual table module xClose method.
185385 */
185386 static int rtreeClose(sqlite3_vtab_cursor *cur){
185387 Rtree *pRtree = (Rtree *)(cur->pVtab);
185388 int ii;
185389 RtreeCursor *pCsr = (RtreeCursor *)cur;
185390 assert( pRtree->nCursor>0 );
185391 freeCursorConstraints(pCsr);
185392 sqlite3_finalize(pCsr->pReadAux);
185393 sqlite3_free(pCsr->aPoint);
185394 for(ii=0; ii<RTREE_CACHE_SZ; ii++) nodeRelease(pRtree, pCsr->aNode[ii]);
185395 sqlite3_free(pCsr);
185396 pRtree->nCursor--;
185397 nodeBlobReset(pRtree);
185398 return SQLITE_OK;
185399 }
@@ -185547,13 +186063,16 @@
185547 ** in a coordinate pair. But make pCellData point to the lower bound.
185548 */
185549 pCellData += 8 + 4*(p->iCoord&0xfe);
185550
185551 assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
185552 || p->op==RTREE_GT || p->op==RTREE_EQ );
 
185553 assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */
185554 switch( p->op ){
 
 
185555 case RTREE_LE:
185556 case RTREE_LT:
185557 case RTREE_EQ:
185558 RTREE_DECODE_COORD(eInt, pCellData, val);
185559 /* val now holds the lower bound of the coordinate pair */
@@ -185587,20 +186106,23 @@
185587 int *peWithin /* Adjust downward, as appropriate */
185588 ){
185589 RtreeDValue xN; /* Coordinate value converted to a double */
185590
185591 assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
185592 || p->op==RTREE_GT || p->op==RTREE_EQ );
 
185593 pCellData += 8 + p->iCoord*4;
185594 assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */
185595 RTREE_DECODE_COORD(eInt, pCellData, xN);
185596 switch( p->op ){
185597 case RTREE_LE: if( xN <= p->u.rValue ) return; break;
185598 case RTREE_LT: if( xN < p->u.rValue ) return; break;
185599 case RTREE_GE: if( xN >= p->u.rValue ) return; break;
185600 case RTREE_GT: if( xN > p->u.rValue ) return; break;
185601 default: if( xN == p->u.rValue ) return; break;
 
 
185602 }
185603 *peWithin = NOT_WITHIN;
185604 }
185605
185606 /*
@@ -186089,30 +186611,32 @@
186089 RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor;
186090 RtreeNode *pRoot = 0;
186091 int ii;
186092 int rc = SQLITE_OK;
186093 int iCell = 0;
186094 sqlite3_stmt *pStmt;
186095
186096 rtreeReference(pRtree);
186097
186098 /* Reset the cursor to the same state as rtreeOpen() leaves it in. */
186099 freeCursorConstraints(pCsr);
186100 sqlite3_free(pCsr->aPoint);
186101 pStmt = pCsr->pReadAux;
186102 memset(pCsr, 0, sizeof(RtreeCursor));
186103 pCsr->base.pVtab = (sqlite3_vtab*)pRtree;
186104 pCsr->pReadAux = pStmt;
186105
186106 pCsr->iStrategy = idxNum;
186107 if( idxNum==1 ){
186108 /* Special case - lookup by rowid. */
186109 RtreeNode *pLeaf; /* Leaf on which the required cell resides */
186110 RtreeSearchPoint *p; /* Search point for the leaf */
186111 i64 iRowid = sqlite3_value_int64(argv[0]);
186112 i64 iNode = 0;
186113 rc = findLeafNode(pRtree, iRowid, &pLeaf, &iNode);
 
 
 
 
 
 
 
 
186114 if( rc==SQLITE_OK && pLeaf!=0 ){
186115 p = rtreeSearchPointNew(pCsr, RTREE_ZERO, 0);
186116 assert( p!=0 ); /* Always returns pCsr->sPoint */
186117 pCsr->aNode[0] = pLeaf;
186118 p->id = iNode;
@@ -186138,10 +186662,11 @@
186138 memset(pCsr->anQueue, 0, sizeof(u32)*(pRtree->iDepth + 1));
186139 assert( (idxStr==0 && argc==0)
186140 || (idxStr && (int)strlen(idxStr)==argc*2) );
186141 for(ii=0; ii<argc; ii++){
186142 RtreeConstraint *p = &pCsr->aConstraint[ii];
 
186143 p->op = idxStr[ii*2];
186144 p->iCoord = idxStr[ii*2+1]-'0';
186145 if( p->op>=RTREE_MATCH ){
186146 /* A MATCH operator. The right-hand-side must be a blob that
186147 ** can be cast into an RtreeMatchArg object. One created using
@@ -186152,16 +186677,25 @@
186152 break;
186153 }
186154 p->pInfo->nCoord = pRtree->nDim2;
186155 p->pInfo->anQueue = pCsr->anQueue;
186156 p->pInfo->mxLevel = pRtree->iDepth + 1;
186157 }else{
186158 #ifdef SQLITE_RTREE_INT_ONLY
186159 p->u.rValue = sqlite3_value_int64(argv[ii]);
186160 #else
186161 p->u.rValue = sqlite3_value_double(argv[ii]);
186162 #endif
 
 
 
 
 
 
 
 
 
186163 }
186164 }
186165 }
186166 }
186167 if( rc==SQLITE_OK ){
@@ -187933,10 +188467,18 @@
187933 }
187934
187935 sqlite3_free(zSql);
187936 return rc;
187937 }
 
 
 
 
 
 
 
 
187938
187939 /*
187940 ** This function is the implementation of both the xConnect and xCreate
187941 ** methods of the r-tree virtual table.
187942 **
@@ -187970,12 +188512,12 @@
187970 "Too many columns for an rtree table", /* 3 */
187971 "Auxiliary rtree columns must be last" /* 4 */
187972 };
187973
187974 assert( RTREE_MAX_AUX_COLUMN<256 ); /* Aux columns counted by a u8 */
187975 if( argc>RTREE_MAX_AUX_COLUMN+3 ){
187976 *pzErr = sqlite3_mprintf("%s", aErrMsg[3]);
187977 return SQLITE_ERROR;
187978 }
187979
187980 sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
187981
@@ -187999,20 +188541,22 @@
187999 /* Create/Connect to the underlying relational database schema. If
188000 ** that is successful, call sqlite3_declare_vtab() to configure
188001 ** the r-tree table schema.
188002 */
188003 pSql = sqlite3_str_new(db);
188004 sqlite3_str_appendf(pSql, "CREATE TABLE x(%s", argv[3]);
 
188005 for(ii=4; ii<argc; ii++){
188006 if( argv[ii][0]=='+' ){
 
188007 pRtree->nAux++;
188008 sqlite3_str_appendf(pSql, ",%s", argv[ii]+1);
188009 }else if( pRtree->nAux>0 ){
188010 break;
188011 }else{
188012 pRtree->nDim2++;
188013 sqlite3_str_appendf(pSql, ",%s", argv[ii]);
188014 }
188015 }
188016 sqlite3_str_appendf(pSql, ");");
188017 zSql = sqlite3_str_finish(pSql);
188018 if( !zSql ){
@@ -189956,21 +190500,15 @@
189956 Rtree *pRtree = (Rtree *)pVtabCursor->pVtab;
189957 RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor;
189958 RtreeNode *pRoot = 0;
189959 int rc = SQLITE_OK;
189960 int iCell = 0;
189961 sqlite3_stmt *pStmt;
189962
189963 rtreeReference(pRtree);
189964
189965 /* Reset the cursor to the same state as rtreeOpen() leaves it in. */
189966 freeCursorConstraints(pCsr);
189967 sqlite3_free(pCsr->aPoint);
189968 pStmt = pCsr->pReadAux;
189969 memset(pCsr, 0, sizeof(RtreeCursor));
189970 pCsr->base.pVtab = (sqlite3_vtab*)pRtree;
189971 pCsr->pReadAux = pStmt;
189972
189973 pCsr->iStrategy = idxNum;
189974 if( idxNum==1 ){
189975 /* Special case - lookup by rowid. */
189976 RtreeNode *pLeaf; /* Leaf on which the required cell resides */
@@ -196990,11 +197528,11 @@
196990 }
196991 z += 2;
196992 }else{
196993 while( *z==0 ) z++;
196994 }
196995 z += (n + 8 + 1);
196996 return z;
196997 }
196998
196999 /*
197000 ** Open an rbu file handle.
@@ -204281,11 +204819,11 @@
204281 ** the callback, an SQLite error code is returned.
204282 **
204283 **
204284 ** xSetAuxdata(pFts5, pAux, xDelete)
204285 **
204286 ** Save the pointer passed as the second argument as the extension functions
204287 ** "auxiliary data". The pointer may then be retrieved by the current or any
204288 ** future invocation of the same fts5 extension function made as part of
204289 ** the same MATCH query using the xGetAuxdata() API.
204290 **
204291 ** Each extension function is allocated a single auxiliary data slot for
@@ -204523,12 +205061,12 @@
204523 ** all instances of "first place" or "1st place" regardless of which form
204524 ** the user specified in the MATCH query text.
204525 **
204526 ** There are several ways to approach this in FTS5:
204527 **
204528 ** <ol><li> By mapping all synonyms to a single token. In this case, the
204529 ** In the above example, this means that the tokenizer returns the
204530 ** same token for inputs "first" and "1st". Say that token is in
204531 ** fact "first", so that when the user inserts the document "I won
204532 ** 1st place" entries are added to the index for tokens "i", "won",
204533 ** "first" and "place". If the user then queries for '1st + place',
204534 ** the tokenizer substitutes "first" for "1st" and the query works
@@ -205685,10 +206223,11 @@
205685 #define sqlite3Fts5ParserCTX_PARAM
205686 #define sqlite3Fts5ParserCTX_FETCH
205687 #define sqlite3Fts5ParserCTX_STORE
205688 #define fts5YYNSTATE 35
205689 #define fts5YYNRULE 28
 
205690 #define fts5YYNFTS5TOKEN 16
205691 #define fts5YY_MAX_SHIFT 34
205692 #define fts5YY_MIN_SHIFTREDUCE 52
205693 #define fts5YY_MAX_SHIFTREDUCE 79
205694 #define fts5YY_ERROR_ACTION 80
@@ -206514,16 +207053,19 @@
206514 fts5yymsp = fts5yypParser->fts5yytos;
206515 #ifndef NDEBUG
206516 if( fts5yyTraceFILE && fts5yyruleno<(int)(sizeof(fts5yyRuleName)/sizeof(fts5yyRuleName[0])) ){
206517 fts5yysize = fts5yyRuleInfoNRhs[fts5yyruleno];
206518 if( fts5yysize ){
206519 fprintf(fts5yyTraceFILE, "%sReduce %d [%s], go to state %d.\n",
206520 fts5yyTracePrompt,
206521 fts5yyruleno, fts5yyRuleName[fts5yyruleno], fts5yymsp[fts5yysize].stateno);
 
 
206522 }else{
206523 fprintf(fts5yyTraceFILE, "%sReduce %d [%s].\n",
206524 fts5yyTracePrompt, fts5yyruleno, fts5yyRuleName[fts5yyruleno]);
 
206525 }
206526 }
206527 #endif /* NDEBUG */
206528
206529 /* Check that the stack is large enough to grow by a single entry
@@ -208278,11 +208820,11 @@
208278
208279 /* Set stack variable q to the close-quote character */
208280 assert( q=='[' || q=='\'' || q=='"' || q=='`' );
208281 if( q=='[' ) q = ']';
208282
208283 while( ALWAYS(z[iIn]) ){
208284 if( z[iIn]==q ){
208285 if( z[iIn+1]!=q ){
208286 /* Character iIn was the close quote. */
208287 iIn++;
208288 break;
@@ -211607,14 +212149,16 @@
211607 }
211608 azConfig[0] = 0;
211609 azConfig[1] = "main";
211610 azConfig[2] = "tbl";
211611 for(i=3; iArg<nArg; iArg++){
211612 azConfig[i++] = (const char*)sqlite3_value_text(apVal[iArg]);
 
211613 }
211614
211615 zExpr = (const char*)sqlite3_value_text(apVal[0]);
 
211616
211617 rc = sqlite3Fts5ConfigParse(pGlobal, db, nConfig, azConfig, &pConfig, &zErr);
211618 if( rc==SQLITE_OK ){
211619 rc = sqlite3Fts5ExprNew(pConfig, pConfig->nCol, zExpr, &pExpr, &zErr);
211620 }
@@ -217860,14 +218404,17 @@
217860 int n = 0;
217861 int i;
217862 for(i=0; i<nChar; i++){
217863 if( n>=nByte ) return 0; /* Input contains fewer than nChar chars */
217864 if( (unsigned char)p[n++]>=0xc0 ){
217865 if( n>=nByte ) break;
217866 while( (p[n] & 0xc0)==0x80 ){
217867 n++;
217868 if( n>=nByte ) break;
 
 
 
217869 }
217870 }
217871 }
217872 return n;
217873 }
@@ -218265,10 +218812,41 @@
218265
218266 *pCksum = cksum;
218267 return rc;
218268 }
218269
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218270
218271 /*
218272 ** This function is also purely an internal test. It does not contribute to
218273 ** FTS functionality, or even the integrity-check, in any way.
218274 */
@@ -218305,12 +218883,18 @@
218305 ** the index is disabled are the same. In both ASC and DESC order.
218306 **
218307 ** This check may only be performed if the hash table is empty. This
218308 ** is because the hash table only supports a single scan query at
218309 ** a time, and the multi-iter loop from which this function is called
218310 ** is already performing such a scan. */
218311 if( p->nPendingData==0 ){
 
 
 
 
 
 
218312 if( iIdx>0 && rc==SQLITE_OK ){
218313 int f = flags|FTS5INDEX_QUERY_TEST_NOIDX;
218314 ck2 = 0;
218315 rc = fts5QueryCksum(p, iIdx, zTerm, nTerm, f, &ck2);
218316 if( rc==SQLITE_OK && ck1!=ck2 ) rc = FTS5_CORRUPT;
@@ -218439,12 +219023,12 @@
218439 /* Iterate through the b-tree hierarchy. */
218440 while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
218441 i64 iRow; /* Rowid for this leaf */
218442 Fts5Data *pLeaf; /* Data for this leaf */
218443
 
218444 int nIdxTerm = sqlite3_column_bytes(pStmt, 1);
218445 const char *zIdxTerm = (const char*)sqlite3_column_text(pStmt, 1);
218446 int iIdxLeaf = sqlite3_column_int(pStmt, 2);
218447 int bIdxDlidx = sqlite3_column_int(pStmt, 3);
218448
218449 /* If the leaf in question has already been trimmed from the segment,
218450 ** ignore this b-tree entry. Otherwise, load it into memory. */
@@ -220027,19 +220611,28 @@
220027 case FTS5_PLAN_SORTED_MATCH: {
220028 rc = fts5SorterNext(pCsr);
220029 break;
220030 }
220031
220032 default:
 
 
220033 rc = sqlite3_step(pCsr->pStmt);
 
220034 if( rc!=SQLITE_ROW ){
220035 CsrFlagSet(pCsr, FTS5CSR_EOF);
220036 rc = sqlite3_reset(pCsr->pStmt);
 
 
 
 
 
220037 }else{
220038 rc = SQLITE_OK;
220039 }
220040 break;
 
220041 }
220042 }
220043
220044 return rc;
220045 }
@@ -220319,10 +220912,17 @@
220319 int iCol; /* Column on LHS of MATCH operator */
220320 char **pzErrmsg = pConfig->pzErrmsg;
220321 int i;
220322 int iIdxStr = 0;
220323 Fts5Expr *pExpr = 0;
 
 
 
 
 
 
 
220324
220325 if( pCsr->ePlan ){
220326 fts5FreeCursorComponents(pCsr);
220327 memset(&pCsr->ePlan, 0, sizeof(Fts5Cursor) - ((u8*)&pCsr->ePlan-(u8*)pCsr));
220328 }
@@ -220540,21 +221140,28 @@
220540 assert( rc!=SQLITE_OK || pTab->p.base.zErrMsg==0 );
220541 assert( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_CONTENT) );
220542 }
220543
220544 if( rc==SQLITE_OK && CsrFlagTest(pCsr, FTS5CSR_REQUIRE_CONTENT) ){
 
220545 assert( pCsr->pExpr );
220546 sqlite3_reset(pCsr->pStmt);
220547 sqlite3_bind_int64(pCsr->pStmt, 1, fts5CursorRowid(pCsr));
 
220548 rc = sqlite3_step(pCsr->pStmt);
 
220549 if( rc==SQLITE_ROW ){
220550 rc = SQLITE_OK;
220551 CsrFlagClear(pCsr, FTS5CSR_REQUIRE_CONTENT);
220552 }else{
220553 rc = sqlite3_reset(pCsr->pStmt);
220554 if( rc==SQLITE_OK ){
220555 rc = FTS5_CORRUPT;
 
 
 
 
220556 }
220557 }
220558 }
220559 return rc;
220560 }
@@ -221566,14 +222173,16 @@
221566 if( pCsr->pRank || SQLITE_OK==(rc = fts5FindRankFunction(pCsr)) ){
221567 fts5ApiInvoke(pCsr->pRank, pCsr, pCtx, pCsr->nRankArg, pCsr->apRankArg);
221568 }
221569 }
221570 }else if( !fts5IsContentless(pTab) ){
 
221571 rc = fts5SeekCursor(pCsr, 1);
221572 if( rc==SQLITE_OK ){
221573 sqlite3_result_value(pCtx, sqlite3_column_value(pCsr->pStmt, iCol+1));
221574 }
 
221575 }
221576 return rc;
221577 }
221578
221579
@@ -221846,11 +222455,11 @@
221846 int nArg, /* Number of args */
221847 sqlite3_value **apUnused /* Function arguments */
221848 ){
221849 assert( nArg==0 );
221850 UNUSED_PARAM2(nArg, apUnused);
221851 sqlite3_result_text(pCtx, "fts5: 2019-11-20 12:07:40 2575a68c3965e72f2ab211d933012442755afe6a9b7de9e9e50cdd2155fd1ec8", -1, SQLITE_TRANSIENT);
221852 }
221853
221854 /*
221855 ** Return true if zName is the extension on one of the shadow tables used
221856 ** by this module.
@@ -222593,14 +223202,15 @@
222593 sqlite3Fts5BufferZero(&buf);
222594 rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 0, iRowid);
222595 for(ctx.iCol=0; rc==SQLITE_OK && ctx.iCol<pConfig->nCol; ctx.iCol++){
222596 ctx.szCol = 0;
222597 if( pConfig->abUnindexed[ctx.iCol]==0 ){
 
 
222598 rc = sqlite3Fts5Tokenize(pConfig,
222599 FTS5_TOKENIZE_DOCUMENT,
222600 (const char*)sqlite3_column_text(pScan, ctx.iCol+1),
222601 sqlite3_column_bytes(pScan, ctx.iCol+1),
222602 (void*)&ctx,
222603 fts5StorageInsertCallback
222604 );
222605 }
222606 sqlite3Fts5BufferAppendVarint(&rc, &buf, ctx.szCol);
@@ -222718,14 +223328,15 @@
222718 rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 0, iRowid);
222719 }
222720 for(ctx.iCol=0; rc==SQLITE_OK && ctx.iCol<pConfig->nCol; ctx.iCol++){
222721 ctx.szCol = 0;
222722 if( pConfig->abUnindexed[ctx.iCol]==0 ){
 
 
222723 rc = sqlite3Fts5Tokenize(pConfig,
222724 FTS5_TOKENIZE_DOCUMENT,
222725 (const char*)sqlite3_value_text(apVal[ctx.iCol+2]),
222726 sqlite3_value_bytes(apVal[ctx.iCol+2]),
222727 (void*)&ctx,
222728 fts5StorageInsertCallback
222729 );
222730 }
222731 sqlite3Fts5BufferAppendVarint(&rc, &buf, ctx.szCol);
@@ -222890,14 +223501,15 @@
222890 ctx.szCol = 0;
222891 if( pConfig->eDetail==FTS5_DETAIL_COLUMNS ){
222892 rc = sqlite3Fts5TermsetNew(&ctx.pTermset);
222893 }
222894 if( rc==SQLITE_OK ){
 
 
222895 rc = sqlite3Fts5Tokenize(pConfig,
222896 FTS5_TOKENIZE_DOCUMENT,
222897 (const char*)sqlite3_column_text(pScan, i+1),
222898 sqlite3_column_bytes(pScan, i+1),
222899 (void*)&ctx,
222900 fts5StorageIntegrityCallback
222901 );
222902 }
222903 if( rc==SQLITE_OK && pConfig->bColumnsize && ctx.szCol!=aColSize[i] ){
@@ -226616,12 +227228,12 @@
226616 }
226617 #endif /* SQLITE_CORE */
226618 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
226619
226620 /************** End of stmt.c ************************************************/
226621 #if __LINE__!=226621
226622 #undef SQLITE_SOURCE_ID
226623 #define SQLITE_SOURCE_ID "2019-11-20 13:31:52 a0f6d526baecd061a5e2bec5eb698fb5dfb10122ac79c853d7b3f4a48bc9alt2"
226624 #endif
226625 /* Return the source-id for this library */
226626 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
226627 /************************** End of sqlite3.c ******************************/
226628
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1165,11 +1165,11 @@
1165 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1166 ** [sqlite_version()] and [sqlite_source_id()].
1167 */
1168 #define SQLITE_VERSION "3.31.0"
1169 #define SQLITE_VERSION_NUMBER 3031000
1170 #define SQLITE_SOURCE_ID "2019-12-26 01:10:17 f482a4cdfa768941e22c399de8ec29a55e729529eeae86d3832077ad1bef22f3"
1171
1172 /*
1173 ** CAPI3REF: Run-Time Library Version Numbers
1174 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1175 **
@@ -1581,10 +1581,11 @@
1581 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
1582 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
1583 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
1584 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
1585 #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
1586 #define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8))
1587
1588 /*
1589 ** CAPI3REF: Flags For File Open Operations
1590 **
1591 ** These bit values are intended for use in the
@@ -2021,20 +2022,20 @@
2022 **
2023 ** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
2024 ** ^The [SQLITE_FCNTL_BUSYHANDLER]
2025 ** file-control may be invoked by SQLite on the database file handle
2026 ** shortly after it is opened in order to provide a custom VFS with access
2027 ** to the connection's busy-handler callback. The argument is of type (void**)
2028 ** - an array of two (void *) values. The first (void *) actually points
2029 ** to a function of type (int (*)(void *)). In order to invoke the connection's
2030 ** busy-handler, this function should be invoked with the second (void *) in
2031 ** the array as the only argument. If it returns non-zero, then the operation
2032 ** should be retried. If it returns zero, the custom VFS should abandon the
2033 ** current operation.
2034 **
2035 ** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
2036 ** ^Applications can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
2037 ** to have SQLite generate a
2038 ** temporary filename using the same algorithm that is followed to generate
2039 ** temporary filenames for TEMP tables and other internal uses. The
2040 ** argument should be a char** which will be filled with the filename
2041 ** written into memory obtained from [sqlite3_malloc()]. The caller should
@@ -2143,11 +2144,11 @@
2144 ** interface can be used to find if any database on the connection has changed,
2145 ** but that interface responds to changes on TEMP as well as MAIN and does
2146 ** not provide a mechanism to detect changes to MAIN only. Also, the
2147 ** [sqlite3_total_changes()] interface responds to internal changes only and
2148 ** omits changes made by other database connections. The
2149 ** [PRAGMA data_version] command provides a mechanism to detect changes to
2150 ** a single attached database that occur due to other database connections,
2151 ** but omits changes implemented by the database connection on which it is
2152 ** called. This file control is the only mechanism to detect changes that
2153 ** happen either internally or externally and that are associated with
2154 ** a particular attached database.
@@ -2231,14 +2232,14 @@
2232 ** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
2233 ** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
2234 ** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6]. Additional fields
2235 ** may be appended to the sqlite3_vfs object and the iVersion value
2236 ** may increase again in future versions of SQLite.
2237 ** Note that due to an oversight, the structure
2238 ** of the sqlite3_vfs object changed in the transition from
2239 ** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
2240 ** and yet the iVersion field was not increased.
2241 **
2242 ** The szOsFile field is the size of the subclassed [sqlite3_file]
2243 ** structure used by this VFS. mxPathname is the maximum length of
2244 ** a pathname in this VFS.
2245 **
@@ -2325,11 +2326,11 @@
2326 ** be created, and that it is an error if it already exists.
2327 ** It is <i>not</i> used to indicate the file should be opened
2328 ** for exclusive access.
2329 **
2330 ** ^At least szOsFile bytes of memory are allocated by SQLite
2331 ** to hold the [sqlite3_file] structure passed as the third
2332 ** argument to xOpen. The xOpen method does not have to
2333 ** allocate the structure; it should just fill it in. Note that
2334 ** the xOpen method must set the sqlite3_file.pMethods to either
2335 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
2336 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
@@ -2448,11 +2449,10 @@
2449 ** SQLite.
2450 */
2451 #define SQLITE_ACCESS_EXISTS 0
2452 #define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */
2453 #define SQLITE_ACCESS_READ 2 /* Unused */
 
2454
2455 /*
2456 ** CAPI3REF: Flags for the xShmLock VFS method
2457 **
2458 ** These integer constants define the various locking operations
@@ -2663,11 +2663,11 @@
2663 ** Every memory allocation request coming in through [sqlite3_malloc()]
2664 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
2665 ** that causes the corresponding memory allocation to fail.
2666 **
2667 ** The xInit method initializes the memory allocator. For example,
2668 ** it might allocate any required mutexes or initialize internal data
2669 ** structures. The xShutdown method is invoked (indirectly) by
2670 ** [sqlite3_shutdown()] and should deallocate any resources acquired
2671 ** by xInit. The pAppData pointer is used as the only parameter to
2672 ** xInit and xShutdown.
2673 **
@@ -2804,11 +2804,11 @@
2804 **
2805 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
2806 ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
2807 ** that SQLite can use for the database page cache with the default page
2808 ** cache implementation.
2809 ** This configuration option is a no-op if an application-defined page
2810 ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2].
2811 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
2812 ** 8-byte aligned memory (pMem), the size of each page cache line (sz),
2813 ** and the number of cache lines (N).
2814 ** The sz argument should be the size of the largest database page
@@ -3289,11 +3289,11 @@
3289 ** </dd>
3290 **
3291 ** [[SQLITE_DBCONFIG_DQS_DML]]
3292 ** <dt>SQLITE_DBCONFIG_DQS_DML</td>
3293 ** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
3294 ** the legacy [double-quoted string literal] misfeature for DML statements
3295 ** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The
3296 ** default value of this setting is determined by the [-DSQLITE_DQS]
3297 ** compile-time option.
3298 ** </dd>
3299 **
@@ -3550,11 +3550,11 @@
3550 ** will be rolled back automatically.
3551 **
3552 ** ^The sqlite3_interrupt(D) call is in effect until all currently running
3553 ** SQL statements on [database connection] D complete. ^Any new SQL statements
3554 ** that are started after the sqlite3_interrupt() call and before the
3555 ** running statement count reaches zero are interrupted as if they had been
3556 ** running prior to the sqlite3_interrupt() call. ^New SQL statements
3557 ** that are started after the running statement count reaches zero are
3558 ** not effected by the sqlite3_interrupt().
3559 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
3560 ** SQL statements is a no-op and has no effect on SQL statements
@@ -3718,13 +3718,13 @@
3718 ** Alice | 43
3719 ** Bob | 28
3720 ** Cindy | 21
3721 ** </pre></blockquote>
3722 **
3723 ** There are two columns (M==2) and three rows (N==3). Thus the
3724 ** result table has 8 entries. Suppose the result table is stored
3725 ** in an array named azResult. Then azResult holds this content:
3726 **
3727 ** <blockquote><pre>
3728 ** azResult&#91;0] = "Name";
3729 ** azResult&#91;1] = "Age";
3730 ** azResult&#91;2] = "Alice";
@@ -3874,23 +3874,10 @@
3874 ** sqlite3_malloc64(), and sqlite3_realloc64()
3875 ** is always aligned to at least an 8 byte boundary, or to a
3876 ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
3877 ** option is used.
3878 **
 
 
 
 
 
 
 
 
 
 
 
 
 
3879 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
3880 ** must be either NULL or else pointers obtained from a prior
3881 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
3882 ** not yet been released.
3883 **
@@ -3935,11 +3922,11 @@
3922 ** CAPI3REF: Pseudo-Random Number Generator
3923 **
3924 ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
3925 ** select random [ROWID | ROWIDs] when inserting new records into a table that
3926 ** already uses the largest possible [ROWID]. The PRNG is also used for
3927 ** the built-in random() and randomblob() SQL functions. This interface allows
3928 ** applications to access the same PRNG for other purposes.
3929 **
3930 ** ^A call to this routine stores N bytes of randomness into buffer P.
3931 ** ^The P parameter can be a NULL pointer.
3932 **
@@ -4536,11 +4523,11 @@
4523 ** a VFS implementation when the flags parameter to xOpen() has one or
4524 ** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and
4525 ** P is the name of the query parameter, then
4526 ** sqlite3_uri_parameter(F,P) returns the value of the P
4527 ** parameter if it exists or a NULL pointer if P does not appear as a
4528 ** query parameter on F. If P is a query parameter of F and it
4529 ** has no explicit value, then sqlite3_uri_parameter(F,P) returns
4530 ** a pointer to an empty string.
4531 **
4532 ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
4533 ** parameter and returns true (1) or false (0) according to the value
@@ -4548,11 +4535,11 @@
4535 ** value of query parameter P is one of "yes", "true", or "on" in any
4536 ** case or if the value begins with a non-zero number. The
4537 ** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
4538 ** query parameter P is one of "no", "false", or "off" in any case or
4539 ** if the value begins with a numeric zero. If P is not a query
4540 ** parameter on F or if the value of P does not match any of the
4541 ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
4542 **
4543 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
4544 ** 64-bit signed integer and returns that integer, or D if P does not
4545 ** exist. If the value of P is something other than an integer, then
@@ -4885,16 +4872,16 @@
4872 ** in order to find the underlying cause of the problem. With the "v2" prepare
4873 ** interfaces, the underlying reason for the error is returned immediately.
4874 ** </li>
4875 **
4876 ** <li>
4877 ** ^If the specific value bound to a [parameter | host parameter] in the
4878 ** WHERE clause might influence the choice of query plan for a statement,
4879 ** then the statement will be automatically recompiled, as if there had been
4880 ** a schema change, on the first [sqlite3_step()] call following any change
4881 ** to the [sqlite3_bind_text | bindings] of that [parameter].
4882 ** ^The specific value of a WHERE-clause [parameter] might influence the
4883 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
4884 ** or [GLOB] operator or if the parameter is compared to an indexed column
4885 ** and the [SQLITE_ENABLE_STAT4] compile-time option is enabled.
4886 ** </li>
4887 ** </ol>
@@ -5399,24 +5386,20 @@
5386 ** the statement, where N is the second function argument.
5387 ** ^The left-most column is column 0 for these routines.
5388 **
5389 ** ^If the Nth column returned by the statement is an expression or
5390 ** subquery and is not a column value, then all of these functions return
5391 ** NULL. ^These routines might also return NULL if a memory allocation error
5392 ** occurs. ^Otherwise, they return the name of the attached database, table,
5393 ** or column that query result column was extracted from.
5394 **
5395 ** ^As with all other SQLite APIs, those whose names end with "16" return
5396 ** UTF-16 encoded strings and the other functions return UTF-8.
5397 **
5398 ** ^These APIs are only available if the library was compiled with the
5399 ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
5400 **
 
 
 
 
5401 ** If two or more threads call one or more
5402 ** [sqlite3_column_database_name | column metadata interfaces]
5403 ** for the same [prepared statement] and result column
5404 ** at the same time then the results are undefined.
5405 */
@@ -5549,11 +5532,11 @@
5532 ** METHOD: sqlite3_stmt
5533 **
5534 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
5535 ** current row of the result set of [prepared statement] P.
5536 ** ^If prepared statement P does not have results ready to return
5537 ** (via calls to the [sqlite3_column_int | sqlite3_column()] family of
5538 ** interfaces) then sqlite3_data_count(P) returns 0.
5539 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
5540 ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
5541 ** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
5542 ** will return non-zero if previous call to [sqlite3_step](P) returned
@@ -6051,13 +6034,16 @@
6034 ** These constants may be ORed together with the
6035 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
6036 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
6037 ** [sqlite3_create_function_v2()].
6038 **
6039 ** The SQLITE_DETERMINISTIC flag means that the new function always gives
6040 ** the same output when the input parameters are the same. The abs() function
6041 ** is deterministic, for example, but randomblob() is not. Functions must
6042 ** be deterministic in order to be used in certain contexts such as
6043 ** [CHECK constraints] or [generated columns]. SQLite might also optimize
6044 ** deterministic functions by factoring them out of inner loops.
6045 **
6046 ** The SQLITE_DIRECTONLY flag means that the function may only be invoked
6047 ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs. This is
6048 ** a security feature which is recommended for all
6049 ** [application-defined SQL functions] that have side-effects. This flag
@@ -6132,12 +6118,12 @@
6118 **
6119 ** <b>Details:</b>
6120 **
6121 ** These routines extract type, size, and content information from
6122 ** [protected sqlite3_value] objects. Protected sqlite3_value objects
6123 ** are used to pass parameter information into the functions that
6124 ** implement [application-defined SQL functions] and [virtual tables].
6125 **
6126 ** These routines work only with [protected sqlite3_value] objects.
6127 ** Any attempt to use these routines on an [unprotected sqlite3_value]
6128 ** is not threadsafe.
6129 **
@@ -6190,11 +6176,11 @@
6176 ** the return value is arbitrary and meaningless.
6177 **
6178 ** ^The sqlite3_value_frombind(X) interface returns non-zero if the
6179 ** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()]
6180 ** interfaces. ^If X comes from an SQL literal value, or a table column,
6181 ** or an expression, then sqlite3_value_frombind(X) returns zero.
6182 **
6183 ** Please pay particular attention to the fact that the pointer returned
6184 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
6185 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
6186 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
@@ -6276,12 +6262,12 @@
6262 **
6263 ** Implementations of aggregate SQL functions use this
6264 ** routine to allocate memory for storing their state.
6265 **
6266 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
6267 ** for a particular aggregate function, SQLite allocates
6268 ** N bytes of memory, zeroes out that memory, and returns a pointer
6269 ** to the new memory. ^On second and subsequent calls to
6270 ** sqlite3_aggregate_context() for the same aggregate function instance,
6271 ** the same buffer is returned. Sqlite3_aggregate_context() is normally
6272 ** called once for each invocation of the xStep callback and then one
6273 ** last time when the xFinal callback is invoked. ^(When no rows match
@@ -6294,11 +6280,11 @@
6280 ** when first called if N is less than or equal to zero or if a memory
6281 ** allocate error occurs.
6282 **
6283 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
6284 ** determined by the N parameter on first successful call. Changing the
6285 ** value of N in any subsequents call to sqlite3_aggregate_context() within
6286 ** the same aggregate function instance will not resize the memory
6287 ** allocation.)^ Within the xFinal callback, it is customary to set
6288 ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
6289 ** pointless memory allocations occur.
6290 **
@@ -6642,11 +6628,11 @@
6628 ** <li> If A&lt;B THEN B&gt;A.
6629 ** <li> If A&lt;B and B&lt;C then A&lt;C.
6630 ** </ol>
6631 **
6632 ** If a collating function fails any of the above constraints and that
6633 ** collating function is registered and used, then the behavior of SQLite
6634 ** is undefined.
6635 **
6636 ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
6637 ** with the addition that the xDestroy callback is invoked on pArg when
6638 ** the collating function is deleted.
@@ -6969,15 +6955,19 @@
6955
6956 /*
6957 ** CAPI3REF: Return The Filename For A Database Connection
6958 ** METHOD: sqlite3
6959 **
6960 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to the filename
6961 ** associated with database N of connection D.
6962 ** ^If there is no attached database N on the database
6963 ** connection D, or if database N is a temporary or in-memory database, then
6964 ** this function will return either a NULL pointer or an empty string.
6965 **
6966 ** ^The string value returned by this routine is owned and managed by
6967 ** the database connection. ^The value will be valid until the database N
6968 ** is [DETACH]-ed or until the database connection closes.
6969 **
6970 ** ^The filename returned by this function is the output of the
6971 ** xFullPathname method of the [VFS]. ^In other words, the filename
6972 ** will be an absolute pathname, even if the filename used
6973 ** to open the database originally was a URI or relative pathname.
@@ -7128,19 +7118,23 @@
7118 ** In prior versions of SQLite,
7119 ** sharing was enabled or disabled for each thread separately.
7120 **
7121 ** ^(The cache sharing mode set by this interface effects all subsequent
7122 ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
7123 ** Existing database connections continue to use the sharing mode
7124 ** that was in effect at the time they were opened.)^
7125 **
7126 ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
7127 ** successfully. An [error code] is returned otherwise.)^
7128 **
7129 ** ^Shared cache is disabled by default. It is recommended that it stay
7130 ** that way. In other words, do not use this routine. This interface
7131 ** continues to be provided for historical compatibility, but its use is
7132 ** discouraged. Any use of shared cache is discouraged. If shared cache
7133 ** must be used, it is recommended that shared cache only be enabled for
7134 ** individual database connections using the [sqlite3_open_v2()] interface
7135 ** with the [SQLITE_OPEN_SHAREDCACHE] flag.
7136 **
7137 ** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0
7138 ** and will always return SQLITE_MISUSE. On those systems,
7139 ** shared cache mode should be enabled per-database connection via
7140 ** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
@@ -7269,11 +7263,11 @@
7263 ** information about column C of table T in database D
7264 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
7265 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
7266 ** the final five arguments with appropriate values if the specified
7267 ** column exists. ^The sqlite3_table_column_metadata() interface returns
7268 ** SQLITE_ERROR if the specified column does not exist.
7269 ** ^If the column-name parameter to sqlite3_table_column_metadata() is a
7270 ** NULL pointer, then this routine simply checks for the existence of the
7271 ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
7272 ** does not. If the table name parameter T in a call to
7273 ** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is
@@ -7411,11 +7405,11 @@
7405 ** [sqlite3_load_extension()] and the SQL function [load_extension()].
7406 ** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
7407 ** to enable or disable only the C-API.)^
7408 **
7409 ** <b>Security warning:</b> It is recommended that extension loading
7410 ** be enabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
7411 ** rather than this interface, so the [load_extension()] SQL function
7412 ** remains disabled. This will prevent SQL injections from giving attackers
7413 ** access to extension loading capabilities.
7414 */
7415 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
@@ -7498,11 +7492,11 @@
7492 /*
7493 ** CAPI3REF: Virtual Table Object
7494 ** KEYWORDS: sqlite3_module {virtual table module}
7495 **
7496 ** This structure, sometimes called a "virtual table module",
7497 ** defines the implementation of a [virtual table].
7498 ** This structure consists mostly of methods for the module.
7499 **
7500 ** ^A virtual table module is created by filling in a persistent
7501 ** instance of this structure and passing a pointer to that instance
7502 ** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
@@ -7595,11 +7589,17 @@
7589 ** The [xBestIndex] method must fill aConstraintUsage[] with information
7590 ** about what parameters to pass to xFilter. ^If argvIndex>0 then
7591 ** the right-hand side of the corresponding aConstraint[] is evaluated
7592 ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
7593 ** is true, then the constraint is assumed to be fully handled by the
7594 ** virtual table and might not be checked again by the byte code.)^ ^(The
7595 ** aConstraintUsage[].omit flag is an optimization hint. When the omit flag
7596 ** is left in its default setting of false, the constraint will always be
7597 ** checked separately in byte code. If the omit flag is change to true, then
7598 ** the constraint may or may not be checked in byte code. In other words,
7599 ** when the omit flag is true there is no guarantee that the constraint will
7600 ** not be checked again using byte code.)^
7601 **
7602 ** ^The idxNum and idxPtr values are recorded and passed into the
7603 ** [xFilter] method.
7604 ** ^[sqlite3_free()] is used to free idxPtr if and only if
7605 ** needToFreeIdxPtr is true.
@@ -7635,11 +7635,11 @@
7635 ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
7636 ** structure for SQLite [version 3.8.2] ([dateof:3.8.2]).
7637 ** If a virtual table extension is
7638 ** used with an SQLite version earlier than 3.8.2, the results of attempting
7639 ** to read or write the estimatedRows field are undefined (but are likely
7640 ** to include crashing the application). The estimatedRows field should
7641 ** therefore only be used if [sqlite3_libversion_number()] returns a
7642 ** value greater than or equal to 3008002. Similarly, the idxFlags field
7643 ** was added for [version 3.9.0] ([dateof:3.9.0]).
7644 ** It may therefore only be used if
7645 ** sqlite3_libversion_number() returns a value greater than or equal to
@@ -7687,11 +7687,11 @@
7687 #define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */
7688
7689 /*
7690 ** CAPI3REF: Virtual Table Constraint Operator Codes
7691 **
7692 ** These macros define the allowed values for the
7693 ** [sqlite3_index_info].aConstraint[].op field. Each value represents
7694 ** an operator that is part of a constraint term in the wHERE clause of
7695 ** a query that uses a [virtual table].
7696 */
7697 #define SQLITE_INDEX_CONSTRAINT_EQ 2
@@ -8297,11 +8297,11 @@
8297 ** </ul>)^
8298 **
8299 ** The only difference is that the public sqlite3_XXX functions enumerated
8300 ** above silently ignore any invocations that pass a NULL pointer instead
8301 ** of a valid mutex handle. The implementations of the methods defined
8302 ** by this structure are not required to handle this case. The results
8303 ** of passing a NULL pointer instead of a valid mutex handle are undefined
8304 ** (i.e. it is acceptable to provide an implementation that segfaults if
8305 ** it is passed a NULL pointer).
8306 **
8307 ** The xMutexInit() method must be threadsafe. It must be harmless to
@@ -8770,11 +8770,11 @@
8770 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
8771 ** no space was left in the page cache.</dd>)^
8772 **
8773 ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
8774 ** <dd>This parameter records the largest memory allocation request
8775 ** handed to the [pagecache memory allocator]. Only the value returned in the
8776 ** *pHighwater parameter to [sqlite3_status()] is of interest.
8777 ** The value written into the *pCurrent parameter is undefined.</dd>)^
8778 **
8779 ** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt>
8780 ** <dd>No longer used.</dd>
@@ -8846,11 +8846,11 @@
8846 ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
8847 ** <dd>This parameter returns the number of lookaside memory slots currently
8848 ** checked out.</dd>)^
8849 **
8850 ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
8851 ** <dd>This parameter returns the number of malloc attempts that were
8852 ** satisfied using lookaside memory. Only the high-water value is meaningful;
8853 ** the current value is always zero.)^
8854 **
8855 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
8856 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
@@ -8928,11 +8928,11 @@
8928 ** <dd>This parameter returns the number of dirty cache entries that have
8929 ** been written to disk in the middle of a transaction due to the page
8930 ** cache overflowing. Transactions are more efficient if they are written
8931 ** to disk all at once. When pages spill mid-transaction, that introduces
8932 ** additional overhead. This parameter can be used help identify
8933 ** inefficiencies that can be resolved by increasing the cache size.
8934 ** </dd>
8935 **
8936 ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
8937 ** <dd>This parameter returns zero for the current value if and only if
8938 ** all foreign key constraints (deferred or immediate) have been
@@ -9017,11 +9017,11 @@
9017 ** If the number of virtual machine operations exceeds 2147483647
9018 ** then the value returned by this statement status code is undefined.
9019 **
9020 ** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
9021 ** <dd>^This is the number of times that the prepare statement has been
9022 ** automatically regenerated due to schema changes or changes to
9023 ** [bound parameters] that might affect the query plan.
9024 **
9025 ** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
9026 ** <dd>^This is the number of times that the prepared statement has
9027 ** been run. A single "run" for the purposes of this counter is one
@@ -9188,11 +9188,11 @@
9188 ** NULL if allocating a new page is effectively impossible.
9189 ** </table>
9190 **
9191 ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
9192 ** will only use a createFlag of 2 after a prior call with a createFlag of 1
9193 ** failed.)^ In between the xFetch() calls, SQLite may
9194 ** attempt to unpin one or more cache pages by spilling the content of
9195 ** pinned pages to disk and synching the operating system disk cache.
9196 **
9197 ** [[the xUnpin() page cache method]]
9198 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
@@ -9506,11 +9506,11 @@
9506 ** application receives an SQLITE_LOCKED error, it may call the
9507 ** sqlite3_unlock_notify() method with the blocked connection handle as
9508 ** the first argument to register for a callback that will be invoked
9509 ** when the blocking connections current transaction is concluded. ^The
9510 ** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
9511 ** call that concludes the blocking connection's transaction.
9512 **
9513 ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
9514 ** there is a chance that the blocking connection will have already
9515 ** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
9516 ** If this happens, then the specified callback is invoked immediately,
@@ -9544,11 +9544,11 @@
9544 ** However, the signature of the callback function allows SQLite to pass
9545 ** it an array of void* context pointers. The first argument passed to
9546 ** an unlock-notify callback is a pointer to an array of void* pointers,
9547 ** and the second is the number of entries in the array.
9548 **
9549 ** When a blocking connection's transaction is concluded, there may be
9550 ** more than one blocked connection that has registered for an unlock-notify
9551 ** callback. ^If two or more such blocked connections have specified the
9552 ** same callback function, then instead of invoking the callback function
9553 ** multiple times, it is invoked once with the set of void* context pointers
9554 ** specified by the blocked connections bundled together into an array.
@@ -10018,37 +10018,37 @@
10018 ** managed by the prepared statement S and will be automatically freed when
10019 ** S is finalized.
10020 **
10021 ** <dl>
10022 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
10023 ** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be
10024 ** set to the total number of times that the X-th loop has run.</dd>
10025 **
10026 ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
10027 ** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be set
10028 ** to the total number of rows examined by all iterations of the X-th loop.</dd>
10029 **
10030 ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
10031 ** <dd>^The "double" variable pointed to by the V parameter will be set to the
10032 ** query planner's estimate for the average number of rows output from each
10033 ** iteration of the X-th loop. If the query planner's estimates was accurate,
10034 ** then this value will approximate the quotient NVISIT/NLOOP and the
10035 ** product of this value for all prior loops with the same SELECTID will
10036 ** be the NLOOP value for the current loop.
10037 **
10038 ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
10039 ** <dd>^The "const char *" variable pointed to by the V parameter will be set
10040 ** to a zero-terminated UTF-8 string containing the name of the index or table
10041 ** used for the X-th loop.
10042 **
10043 ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
10044 ** <dd>^The "const char *" variable pointed to by the V parameter will be set
10045 ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
10046 ** description for the X-th loop.
10047 **
10048 ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
10049 ** <dd>^The "int" variable pointed to by the V parameter will be set to the
10050 ** "select-id" for the X-th loop. The select-id identifies which query or
10051 ** subquery the loop is part of. The main query has a select-id of zero.
10052 ** The select-id is the same value as is output in the first column
10053 ** of an [EXPLAIN QUERY PLAN] query.
10054 ** </dl>
@@ -10899,11 +10899,11 @@
10899 ** METHOD: sqlite3_session
10900 **
10901 ** The second argument (xFilter) is the "filter callback". For changes to rows
10902 ** in tables that are not attached to the Session object, the filter is called
10903 ** to determine whether changes to the table's rows should be tracked or not.
10904 ** If xFilter returns 0, changes are not tracked. Note that once a table is
10905 ** attached, xFilter will not be called again.
10906 */
10907 SQLITE_API void sqlite3session_table_filter(
10908 sqlite3_session *pSession, /* Session object */
10909 int(*xFilter)(
@@ -11073,11 +11073,11 @@
11073 ** identical.
11074 **
11075 ** It an error if database zFrom does not exist or does not contain the
11076 ** required compatible table.
11077 **
11078 ** If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite
11079 ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
11080 ** may be set to point to a buffer containing an English language error
11081 ** message. It is the responsibility of the caller to free this buffer using
11082 ** sqlite3_free().
11083 */
@@ -11210,11 +11210,11 @@
11210
11211 /*
11212 ** CAPI3REF: Advance A Changeset Iterator
11213 ** METHOD: sqlite3_changeset_iter
11214 **
11215 ** This function may only be used with iterators created by the function
11216 ** [sqlite3changeset_start()]. If it is called on an iterator passed to
11217 ** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE
11218 ** is returned and the call has no effect.
11219 **
11220 ** Immediately after an iterator is created by sqlite3changeset_start(), it
@@ -11626,12 +11626,12 @@
11626 ** in the changegroup, then the number of columns and the position of the
11627 ** primary key columns for the table must be consistent. If this is not the
11628 ** case, this function fails with SQLITE_SCHEMA. If the input changeset
11629 ** appears to be corrupt and the corruption is detected, SQLITE_CORRUPT is
11630 ** returned. Or, if an out-of-memory condition occurs during processing, this
11631 ** function returns SQLITE_NOMEM. In all cases, if an error occurs the state
11632 ** of the final contents of the changegroup is undefined.
11633 **
11634 ** If no error occurs, SQLITE_OK is returned.
11635 */
11636 SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
11637
@@ -11802,11 +11802,11 @@
11802 ** [SQLITE_CHANGESET_REPLACE].
11803 ** </dl>
11804 **
11805 ** It is safe to execute SQL statements, including those that write to the
11806 ** table that the callback related to, from within the xConflict callback.
11807 ** This can be used to further customize the application's conflict
11808 ** resolution strategy.
11809 **
11810 ** All changes made by these functions are enclosed in a savepoint transaction.
11811 ** If any other error (aside from a constraint failure when attempting to
11812 ** write to the target database) occurs, then the savepoint transaction is
@@ -12112,11 +12112,11 @@
12112 ** CAPI3REF: Rebase a changeset
12113 ** EXPERIMENTAL
12114 **
12115 ** Argument pIn must point to a buffer containing a changeset nIn bytes
12116 ** in size. This function allocates and populates a buffer with a copy
12117 ** of the changeset rebased according to the configuration of the
12118 ** rebaser object passed as the first argument. If successful, (*ppOut)
12119 ** is set to point to the new buffer containing the rebased changeset and
12120 ** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
12121 ** responsibility of the caller to eventually free the new buffer using
12122 ** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
@@ -12520,11 +12520,11 @@
12520 ** the callback, an SQLite error code is returned.
12521 **
12522 **
12523 ** xSetAuxdata(pFts5, pAux, xDelete)
12524 **
12525 ** Save the pointer passed as the second argument as the extension function's
12526 ** "auxiliary data". The pointer may then be retrieved by the current or any
12527 ** future invocation of the same fts5 extension function made as part of
12528 ** the same MATCH query using the xGetAuxdata() API.
12529 **
12530 ** Each extension function is allocated a single auxiliary data slot for
@@ -12762,12 +12762,12 @@
12762 ** all instances of "first place" or "1st place" regardless of which form
12763 ** the user specified in the MATCH query text.
12764 **
12765 ** There are several ways to approach this in FTS5:
12766 **
12767 ** <ol><li> By mapping all synonyms to a single token. In this case, using
12768 ** the above example, this means that the tokenizer returns the
12769 ** same token for inputs "first" and "1st". Say that token is in
12770 ** fact "first", so that when the user inserts the document "I won
12771 ** 1st place" entries are added to the index for tokens "i", "won",
12772 ** "first" and "place". If the user then queries for '1st + place',
12773 ** the tokenizer substitutes "first" for "1st" and the query works
@@ -13435,10 +13435,30 @@
13435 #else
13436 # define ALWAYS(X) (X)
13437 # define NEVER(X) (X)
13438 #endif
13439
13440 /*
13441 ** The harmless(X) macro indicates that expression X is usually false
13442 ** but can be true without causing any problems, but we don't know of
13443 ** any way to cause X to be true.
13444 **
13445 ** In debugging and testing builds, this macro will abort if X is ever
13446 ** true. In this way, developers are alerted to a possible test case
13447 ** that causes X to be true. If a harmless macro ever fails, that is
13448 ** an opportunity to change the macro into a testcase() and add a new
13449 ** test case to the test suite.
13450 **
13451 ** For normal production builds, harmless(X) is a no-op, since it does
13452 ** not matter whether expression X is true or false.
13453 */
13454 #ifdef SQLITE_DEBUG
13455 # define harmless(X) assert(!(X));
13456 #else
13457 # define harmless(X)
13458 #endif
13459
13460 /*
13461 ** Some conditionals are optimizations only. In other words, if the
13462 ** conditionals are replaced with a constant 1 (true) or 0 (false) then
13463 ** the correct answer is still obtained, though perhaps not as quickly.
13464 **
@@ -15149,13 +15169,14 @@
15169 #define OP_VRename 163
15170 #define OP_Pagecount 164
15171 #define OP_MaxPgcnt 165
15172 #define OP_Trace 166
15173 #define OP_CursorHint 167
15174 #define OP_ReleaseReg 168 /* synopsis: release r[P1@P2] mask P3 */
15175 #define OP_Noop 169
15176 #define OP_Explain 170
15177 #define OP_Abortable 171
15178
15179 /* Properties such as "out2" or "jump" that are specified in
15180 ** comments following the "case" for each opcode in the vdbe.c
15181 ** are encoded into bitvectors as follows:
15182 */
@@ -15185,11 +15206,11 @@
15206 /* 128 */ 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x10, 0x00,\
15207 /* 136 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15208 /* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x10, 0x00,\
15209 /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15210 /* 160 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
15211 /* 168 */ 0x00, 0x00, 0x00, 0x00,}
15212
15213 /* The sqlite3P2Values() routine is able to run faster if it knows
15214 ** the value of the largest JUMP opcode. The smaller the maximum
15215 ** JUMP opcode the better, so the mkopcodeh.tcl script that
15216 ** generated this include file strives to group all JUMP opcodes
@@ -15262,10 +15283,15 @@
15283 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3);
15284 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
15285 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
15286 SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
15287 SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
15288 #ifdef SQLITE_DEBUG
15289 SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(Parse*,int addr, int n, u32 mask);
15290 #else
15291 # define sqlite3VdbeReleaseRegisters(P,A,N,M)
15292 #endif
15293 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
15294 SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
15295 SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
15296 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
15297 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
@@ -16841,16 +16867,10 @@
16867 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
16868 pArg, 0, xFunc, 0, 0, 0, #zName, }
16869 #define LIKEFUNC(zName, nArg, arg, flags) \
16870 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
16871 (void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} }
 
 
 
 
 
 
16872 #define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f) \
16873 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \
16874 SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,xInverse,#zName, {0}}
16875 #define INTERNAL_FUNCTION(zName, nArg, xFunc) \
16876 {nArg, SQLITE_FUNC_INTERNAL|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
@@ -17978,17 +17998,17 @@
17998 ** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences
17999 ** for the result set. The KeyInfo for addrOpenEphm[2] contains collating
18000 ** sequences for the ORDER BY clause.
18001 */
18002 struct Select {
 
18003 u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */
18004 LogEst nSelectRow; /* Estimated number of result rows */
18005 u32 selFlags; /* Various SF_* values */
18006 int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */
18007 u32 selId; /* Unique identifier number for this SELECT */
18008 int addrOpenEphm[2]; /* OP_OpenEphem opcodes related to this select */
18009 ExprList *pEList; /* The fields of the result */
18010 SrcList *pSrc; /* The FROM clause */
18011 Expr *pWhere; /* The WHERE clause */
18012 ExprList *pGroupBy; /* The GROUP BY clause */
18013 Expr *pHaving; /* The HAVING clause */
18014 ExprList *pOrderBy; /* The ORDER BY clause */
@@ -18030,10 +18050,11 @@
18050 #define SF_Converted 0x0010000 /* By convertCompoundSelectToSubquery() */
18051 #define SF_IncludeHidden 0x0020000 /* Include hidden columns in output */
18052 #define SF_ComplexResult 0x0040000 /* Result contains subquery or function */
18053 #define SF_WhereBegin 0x0080000 /* Really a WhereBegin() call. Debug Only */
18054 #define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */
18055 #define SF_View 0x0200000 /* SELECT statement is a view */
18056
18057 /*
18058 ** The results of a SELECT can be distributed in several ways, as defined
18059 ** by one of the following macros. The "SRT" prefix means "SELECT Result
18060 ** Type".
@@ -18309,12 +18330,12 @@
18330 #endif
18331 };
18332
18333 #define PARSE_MODE_NORMAL 0
18334 #define PARSE_MODE_DECLARE_VTAB 1
18335 #define PARSE_MODE_RENAME 2
18336 #define PARSE_MODE_UNMAP 3
18337
18338 /*
18339 ** Sizes and pointers of various parts of the Parse object.
18340 */
18341 #define PARSE_HDR_SZ offsetof(Parse,aTempReg) /* Recursive part w/o aColCache*/
@@ -18332,11 +18353,11 @@
18353 #endif
18354
18355 #if defined(SQLITE_OMIT_ALTERTABLE)
18356 #define IN_RENAME_OBJECT 0
18357 #else
18358 #define IN_RENAME_OBJECT (pParse->eParseMode>=PARSE_MODE_RENAME)
18359 #endif
18360
18361 #if defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_OMIT_ALTERTABLE)
18362 #define IN_SPECIAL_PARSE 0
18363 #else
@@ -19151,10 +19172,11 @@
19172 SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
19173 SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
19174 SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
19175 Expr*,ExprList*,u32,Expr*);
19176 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3*, Select*);
19177 SQLITE_PRIVATE void sqlite3SelectReset(Parse*, Select*);
19178 SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*);
19179 SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, int);
19180 SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
19181 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
19182 SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,char*);
@@ -20734,11 +20756,11 @@
20756 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
20757 SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem*, int ifNull);
20758 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
20759 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
20760 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
20761 SQLITE_PRIVATE int sqlite3VdbeMemCast(Mem*,u8,u8);
20762 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);
20763 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
20764 SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
20765 #ifndef SQLITE_OMIT_WINDOWFUNC
20766 SQLITE_PRIVATE int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*);
@@ -22654,11 +22676,11 @@
22676 DO_OS_MALLOC_TEST(0);
22677 /* 0x87f7f is a mask of SQLITE_OPEN_ flags that are valid to be passed
22678 ** down into the VFS layer. Some SQLITE_OPEN_ flags (for example,
22679 ** SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_SHAREDCACHE) are blocked before
22680 ** reaching the VFS. */
22681 rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x1087f7f, pFlagsOut);
22682 assert( rc==SQLITE_OK || pFile->pMethods==0 );
22683 return rc;
22684 }
22685 SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
22686 DO_OS_MALLOC_TEST(0);
@@ -29289,12 +29311,13 @@
29311 zOp2[0] = 0;
29312 }
29313 sqlite3TreeViewLine(pView, "COLUMN(%d)%s%s",
29314 pExpr->iColumn, zFlgs, zOp2);
29315 }else{
29316 sqlite3TreeViewLine(pView, "{%d:%d} pTab=%p%s",
29317 pExpr->iTable, pExpr->iColumn,
29318 pExpr->y.pTab, zFlgs);
29319 }
29320 if( ExprHasProperty(pExpr, EP_FixedCol) ){
29321 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
29322 }
29323 break;
@@ -30961,11 +30984,11 @@
30984 #pragma warning(disable : 4756)
30985 #endif
30986 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){
30987 #ifndef SQLITE_OMIT_FLOATING_POINT
30988 int incr;
30989 const char *zEnd;
30990 /* sign * significand * (10 ^ (esign * exponent)) */
30991 int sign = 1; /* sign of significand */
30992 i64 s = 0; /* significand */
30993 int d = 0; /* adjust exponent for shifting decimal point */
30994 int esign = 1; /* sign of exponent */
@@ -30975,13 +30998,15 @@
30998 int nDigit = 0; /* Number of digits processed */
30999 int eType = 1; /* 1: pure integer, 2+: fractional -1 or less: bad UTF16 */
31000
31001 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
31002 *pResult = 0.0; /* Default return value, in case of an error */
31003 if( length==0 ) return 0;
31004
31005 if( enc==SQLITE_UTF8 ){
31006 incr = 1;
31007 zEnd = z + length;
31008 }else{
31009 int i;
31010 incr = 2;
31011 assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
31012 testcase( enc==SQLITE_UTF16LE );
@@ -32660,13 +32685,14 @@
32685 /* 163 */ "VRename" OpHelp(""),
32686 /* 164 */ "Pagecount" OpHelp(""),
32687 /* 165 */ "MaxPgcnt" OpHelp(""),
32688 /* 166 */ "Trace" OpHelp(""),
32689 /* 167 */ "CursorHint" OpHelp(""),
32690 /* 168 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
32691 /* 169 */ "Noop" OpHelp(""),
32692 /* 170 */ "Explain" OpHelp(""),
32693 /* 171 */ "Abortable" OpHelp(""),
32694 };
32695 return azName[i];
32696 }
32697 #endif
32698
@@ -36555,11 +36581,11 @@
36581 zDirname[ii] = '\0';
36582 }else{
36583 if( zDirname[0]!='/' ) zDirname[0] = '.';
36584 zDirname[1] = 0;
36585 }
36586 fd = robust_open(zDirname, O_RDONLY|O_BINARY|O_NOFOLLOW, 0);
36587 if( fd>=0 ){
36588 OSTRACE(("OPENDIR %-3d %s\n", fd, zDirname));
36589 }
36590 *pFd = fd;
36591 if( fd>=0 ) return SQLITE_OK;
@@ -37446,14 +37472,16 @@
37472 }
37473 }
37474
37475 if( pInode->bProcessLock==0 ){
37476 if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
37477 pShmNode->hShm = robust_open(zShm, O_RDWR|O_CREAT|O_NOFOLLOW,
37478 (sStat.st_mode&0777));
37479 }
37480 if( pShmNode->hShm<0 ){
37481 pShmNode->hShm = robust_open(zShm, O_RDONLY|O_NOFOLLOW,
37482 (sStat.st_mode&0777));
37483 if( pShmNode->hShm<0 ){
37484 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShm);
37485 goto shm_open_err;
37486 }
37487 pShmNode->isReadonly = 1;
@@ -38799,11 +38827,11 @@
38827 int *pOutFlags /* Output flags returned to SQLite core */
38828 ){
38829 unixFile *p = (unixFile *)pFile;
38830 int fd = -1; /* File descriptor returned by open() */
38831 int openFlags = 0; /* Flags to pass to open() */
38832 int eType = flags&0x0FFF00; /* Type of file to open */
38833 int noLock; /* True to omit locking primitives */
38834 int rc = SQLITE_OK; /* Function Return Code */
38835 int ctrlFlags = 0; /* UNIXFILE_* flags */
38836
38837 int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE);
@@ -38909,11 +38937,11 @@
38937 ** 'conch file' locking functions later on. */
38938 if( isReadonly ) openFlags |= O_RDONLY;
38939 if( isReadWrite ) openFlags |= O_RDWR;
38940 if( isCreate ) openFlags |= O_CREAT;
38941 if( isExclusive ) openFlags |= (O_EXCL|O_NOFOLLOW);
38942 openFlags |= (O_LARGEFILE|O_BINARY|O_NOFOLLOW);
38943
38944 if( fd<0 ){
38945 mode_t openMode; /* Permissions to create file with */
38946 uid_t uid; /* Userid for the file */
38947 gid_t gid; /* Groupid for the file */
@@ -39121,29 +39149,20 @@
39149 ){
39150 UNUSED_PARAMETER(NotUsed);
39151 SimulateIOError( return SQLITE_IOERR_ACCESS; );
39152 assert( pResOut!=0 );
39153
39154 /* The spec says there are three possible values for flags. But only
39155 ** two of them are actually used */
39156 assert( flags==SQLITE_ACCESS_EXISTS || flags==SQLITE_ACCESS_READWRITE );
 
 
39157
39158 if( flags==SQLITE_ACCESS_EXISTS ){
39159 struct stat buf;
39160 *pResOut = 0==osStat(zPath, &buf) &&
39161 (S_ISDIR(buf.st_mode) || buf.st_size>0);
39162 }else{
39163 *pResOut = osAccess(zPath, W_OK|R_OK)==0;
 
 
 
 
 
 
 
 
39164 }
39165 return SQLITE_OK;
39166 }
39167
39168 /*
@@ -39191,11 +39210,11 @@
39210 #if !defined(HAVE_READLINK) || !defined(HAVE_LSTAT)
39211 return mkFullPathname(zPath, zOut, nOut);
39212 #else
39213 int rc = SQLITE_OK;
39214 int nByte;
39215 int nLink = 0; /* Number of symbolic links followed so far */
39216 const char *zIn = zPath; /* Input path for each iteration of loop */
39217 char *zDel = 0;
39218
39219 assert( pVfs->mxPathname==MAX_PATHNAME );
39220 UNUSED_PARAMETER(pVfs);
@@ -39220,14 +39239,15 @@
39239 }else{
39240 bLink = S_ISLNK(buf.st_mode);
39241 }
39242
39243 if( bLink ){
39244 nLink++;
39245 if( zDel==0 ){
39246 zDel = sqlite3_malloc(nOut);
39247 if( zDel==0 ) rc = SQLITE_NOMEM_BKPT;
39248 }else if( nLink>=SQLITE_MAX_SYMLINKS ){
39249 rc = SQLITE_CANTOPEN_BKPT;
39250 }
39251
39252 if( rc==SQLITE_OK ){
39253 nByte = osReadlink(zIn, zDel, nOut-1);
@@ -39259,10 +39279,11 @@
39279 if( bLink==0 ) break;
39280 zIn = zOut;
39281 }while( rc==SQLITE_OK );
39282
39283 sqlite3_free(zDel);
39284 if( rc==SQLITE_OK && nLink ) rc = SQLITE_OK_SYMLINK;
39285 return rc;
39286 #endif /* HAVE_READLINK && HAVE_LSTAT */
39287 }
39288
39289
@@ -39744,11 +39765,11 @@
39765 int islockfile /* if non zero missing dirs will be created */
39766 ) {
39767 int fd = -1;
39768 unixFile *pNew;
39769 int rc = SQLITE_OK;
39770 int openFlags = O_RDWR | O_CREAT | O_NOFOLLOW;
39771 sqlite3_vfs dummyVfs;
39772 int terrno = 0;
39773 UnixUnusedFd *pUnused = NULL;
39774
39775 /* 1. first try to open/create the file
@@ -39774,11 +39795,11 @@
39795 fd = robust_open(path, openFlags, 0);
39796 }
39797 }
39798 }
39799 if( fd<0 ){
39800 openFlags = O_RDONLY | O_NOFOLLOW;
39801 fd = robust_open(path, openFlags, 0);
39802 terrno = errno;
39803 }
39804 if( fd<0 ){
39805 if( islockfile ){
@@ -39900,11 +39921,11 @@
39921 if( readLen<PROXY_PATHINDEX ){
39922 sqlite3_snprintf(sizeof(errmsg),errmsg,"read error (len %d)",(int)readLen);
39923 goto end_breaklock;
39924 }
39925 /* write it out to the temporary break file */
39926 fd = robust_open(tPath, (O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW), 0);
39927 if( fd<0 ){
39928 sqlite3_snprintf(sizeof(errmsg), errmsg, "create failed (%d)", errno);
39929 goto end_breaklock;
39930 }
39931 if( osPwrite(fd, buf, readLen, 0) != (ssize_t)readLen ){
@@ -41060,18 +41081,10 @@
41081
41082 #ifndef NTDDI_WINTHRESHOLD
41083 # define NTDDI_WINTHRESHOLD 0x06040000
41084 #endif
41085
 
 
 
 
 
 
 
 
41086 /*
41087 ** Check to see if the GetVersionEx[AW] functions are deprecated on the
41088 ** target system. GetVersionEx was first deprecated in Win8.1.
41089 */
41090 #ifndef SQLITE_WIN32_GETVERSIONEX
@@ -46460,14 +46473,10 @@
46473 break;
46474 case SQLITE_ACCESS_READWRITE:
46475 rc = attr!=INVALID_FILE_ATTRIBUTES &&
46476 (attr & FILE_ATTRIBUTE_READONLY)==0;
46477 break;
 
 
 
 
46478 default:
46479 assert(!"Invalid flags argument");
46480 }
46481 *pResOut = rc;
46482 OSTRACE(("ACCESS name=%s, pResOut=%p, *pResOut=%d, rc=SQLITE_OK\n",
@@ -49503,17 +49512,19 @@
49512 sqlite3_free(p);
49513 pPg = 0;
49514 }
49515 #else
49516 pPg = pcache1Alloc(pCache->szAlloc);
 
49517 #endif
49518 if( benignMalloc ){ sqlite3EndBenignMalloc(); }
49519 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
49520 pcache1EnterMutex(pCache->pGroup);
49521 #endif
49522 if( pPg==0 ) return 0;
49523 #ifndef SQLITE_PCACHE_SEPARATE_HEADER
49524 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
49525 #endif
49526 p->page.pBuf = pPg;
49527 p->page.pExtra = &p[1];
49528 p->isBulkLocal = 0;
49529 p->isAnchor = 0;
49530 }
@@ -55782,31 +55793,34 @@
55793 ** to by zPathname, length nPathname. Or, if this is a temporary file,
55794 ** leave both nPathname and zPathname set to 0.
55795 */
55796 if( zFilename && zFilename[0] ){
55797 const char *z;
 
 
 
 
 
 
55798 nPathname = pVfs->mxPathname+1;
55799 zPathname = sqlite3DbMallocRaw(0, nPathname*2);
55800 if( zPathname==0 ){
55801 return SQLITE_NOMEM_BKPT;
55802 }
55803 zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
55804 rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
55805 if( rc!=SQLITE_OK ){
55806 if( rc==SQLITE_OK_SYMLINK ){
55807 if( vfsFlags & SQLITE_OPEN_NOFOLLOW ){
55808 rc = SQLITE_CANTOPEN_SYMLINK;
55809 }else{
55810 rc = SQLITE_OK;
55811 }
55812 }
55813 }
55814 nPathname = sqlite3Strlen30(zPathname);
55815 z = zUri = &zFilename[sqlite3Strlen30(zFilename)+1];
55816 while( *z ){
55817 z += strlen(z)+1;
55818 z += strlen(z)+1;
55819 nUri++;
55820 }
55821 nUriByte = (int)(&z[1] - zUri);
55822 assert( nUriByte>=1 );
55823 if( rc==SQLITE_OK && nPathname+8>pVfs->mxPathname ){
55824 /* This branch is taken when the journal path required by
55825 ** the database being opened will be more than pVfs->mxPathname
55826 ** bytes in length. This means the database cannot be opened,
@@ -57616,10 +57630,11 @@
57630
57631 /* This routine should not be called if a prior error has occurred.
57632 ** But if (due to a coding error elsewhere in the system) it does get
57633 ** called, just return the same error code without doing anything. */
57634 if( NEVER(pPager->errCode) ) return pPager->errCode;
57635 pPager->iDataVersion++;
57636
57637 assert( pPager->eState==PAGER_WRITER_LOCKED
57638 || pPager->eState==PAGER_WRITER_FINISHED
57639 || (pagerUseWal(pPager) && pPager->eState==PAGER_WRITER_CACHEMOD)
57640 );
@@ -57644,11 +57659,10 @@
57659 pPager->eState = PAGER_READER;
57660 return SQLITE_OK;
57661 }
57662
57663 PAGERTRACE(("COMMIT %d\n", PAGERID(pPager)));
 
57664 rc = pager_end_transaction(pPager, pPager->setMaster, 1);
57665 return pager_error(pPager, rc);
57666 }
57667
57668 /*
@@ -60565,11 +60579,23 @@
60579 ** of the aReadMark[] slot. The assumption here is that if that is
60580 ** happening, the other client may only be increasing the value,
60581 ** not decreasing it. So assuming either that either the "old" or
60582 ** "new" version of the value is read, and not some arbitrary value
60583 ** that would never be written by a real client, things are still
60584 ** safe.
60585 **
60586 ** Astute readers have pointed out that the assumption stated in the
60587 ** last sentence of the previous paragraph is not guaranteed to be
60588 ** true for all conforming systems. However, the assumption is true
60589 ** for all compilers and architectures in common use today (circa
60590 ** 2019-11-27) and the alternatives are both slow and complex, and
60591 ** so we will continue to go with the current design for now. If this
60592 ** bothers you, or if you really are running on a system where aligned
60593 ** 32-bit reads and writes are not atomic, then you can simply avoid
60594 ** the use of WAL mode, or only use WAL mode together with
60595 ** PRAGMA locking_mode=EXCLUSIVE and all will be well.
60596 */
60597 u32 y = pInfo->aReadMark[i];
60598 if( mxSafeFrame>y ){
60599 assert( y<=pWal->hdr.mxFrame );
60600 rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(i), 1);
60601 if( rc==SQLITE_OK ){
@@ -66021,13 +66047,17 @@
66047 memcpy(zFullPathname, zFilename, nFilename);
66048 }else{
66049 rc = sqlite3OsFullPathname(pVfs, zFilename,
66050 nFullPathname, zFullPathname);
66051 if( rc ){
66052 if( rc==SQLITE_OK_SYMLINK ){
66053 rc = SQLITE_OK;
66054 }else{
66055 sqlite3_free(zFullPathname);
66056 sqlite3_free(p);
66057 return rc;
66058 }
66059 }
66060 }
66061 #if SQLITE_THREADSAFE
66062 mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN);
66063 sqlite3_mutex_enter(mutexOpen);
@@ -69332,12 +69362,15 @@
69362
69363 /* If the database file is corrupt, it is possible for the value of idx
69364 ** to be invalid here. This can only occur if a second cursor modifies
69365 ** the page while cursor pCur is holding a reference to it. Which can
69366 ** only happen if the database is corrupt in such a way as to link the
69367 ** page into more than one b-tree structure.
69368 **
69369 ** Update 2019-12-23: appears to long longer be possible after the
69370 ** addition of anotherValidCursor() condition on balance_deeper(). */
69371 harmless( idx>pPage->nCell );
69372
69373 if( idx>=pPage->nCell ){
69374 if( !pPage->leaf ){
69375 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
69376 if( rc ) return rc;
@@ -71921,10 +71954,34 @@
71954 put4byte(&pRoot->aData[pRoot->hdrOffset+8], pgnoChild);
71955
71956 *ppChild = pChild;
71957 return SQLITE_OK;
71958 }
71959
71960 /*
71961 ** Return SQLITE_CORRUPT if any cursor other than pCur is currently valid
71962 ** on the same B-tree as pCur.
71963 **
71964 ** This can if a database is corrupt with two or more SQL tables
71965 ** pointing to the same b-tree. If an insert occurs on one SQL table
71966 ** and causes a BEFORE TRIGGER to do a secondary insert on the other SQL
71967 ** table linked to the same b-tree. If the secondary insert causes a
71968 ** rebalance, that can change content out from under the cursor on the
71969 ** first SQL table, violating invariants on the first insert.
71970 */
71971 static int anotherValidCursor(BtCursor *pCur){
71972 BtCursor *pOther;
71973 for(pOther=pCur->pBt->pCursor; pOther; pOther=pOther->pNext){
71974 if( pOther!=pCur
71975 && pOther->eState==CURSOR_VALID
71976 && pOther->pPage==pCur->pPage
71977 ){
71978 return SQLITE_CORRUPT_BKPT;
71979 }
71980 }
71981 return SQLITE_OK;
71982 }
71983
71984 /*
71985 ** The page that pCur currently points to has just been modified in
71986 ** some way. This function figures out if this modification means the
71987 ** tree needs to be balanced, and if so calls the appropriate balancing
@@ -71949,11 +72006,11 @@
72006
72007 if( NEVER(pPage->nFree<0) && btreeComputeFreeSpace(pPage) ) break;
72008 if( pPage->nOverflow==0 && pPage->nFree<=nMin ){
72009 break;
72010 }else if( (iPage = pCur->iPage)==0 ){
72011 if( pPage->nOverflow && (rc = anotherValidCursor(pCur))==SQLITE_OK ){
72012 /* The root page of the b-tree is overfull. In this case call the
72013 ** balance_deeper() function to create a new child for the root-page
72014 ** and copy the current contents of the root-page to it. The
72015 ** next iteration of the do-loop will balance the child page.
72016 */
@@ -72320,11 +72377,13 @@
72377 return btreeOverwriteCell(pCur, &x2);
72378 }
72379 }
72380
72381 }
72382 assert( pCur->eState==CURSOR_VALID
72383 || (pCur->eState==CURSOR_INVALID && loc)
72384 || CORRUPT_DB );
72385
72386 pPage = pCur->pPage;
72387 assert( pPage->intKey || pX->nKey>=0 );
72388 assert( pPage->leaf || !pPage->intKey );
72389 if( pPage->nFree<0 ){
@@ -75489,12 +75548,11 @@
75548 if( flags & (MEM_Int|MEM_IntReal) ){
75549 testcase( flags & MEM_IntReal );
75550 return pMem->u.i;
75551 }else if( flags & MEM_Real ){
75552 return doubleToInt64(pMem->u.r);
75553 }else if( (flags & (MEM_Str|MEM_Blob))!=0 && pMem->z!=0 ){
 
75554 return memIntValue(pMem);
75555 }else{
75556 return 0;
75557 }
75558 }
@@ -75647,12 +75705,12 @@
75705 ** "aff". Casting is different from applying affinity in that a cast
75706 ** is forced. In other words, the value is converted into the desired
75707 ** affinity even if that results in loss of data. This routine is
75708 ** used (for example) to implement the SQL "cast()" operator.
75709 */
75710 SQLITE_PRIVATE int sqlite3VdbeMemCast(Mem *pMem, u8 aff, u8 encoding){
75711 if( pMem->flags & MEM_Null ) return SQLITE_OK;
75712 switch( aff ){
75713 case SQLITE_AFF_BLOB: { /* Really a cast to BLOB */
75714 if( (pMem->flags & MEM_Blob)==0 ){
75715 sqlite3ValueApplyAffinity(pMem, SQLITE_AFF_TEXT, encoding);
75716 assert( pMem->flags & MEM_Str || pMem->db->mallocFailed );
@@ -75679,13 +75737,14 @@
75737 assert( MEM_Str==(MEM_Blob>>3) );
75738 pMem->flags |= (pMem->flags&MEM_Blob)>>3;
75739 sqlite3ValueApplyAffinity(pMem, SQLITE_AFF_TEXT, encoding);
75740 assert( pMem->flags & MEM_Str || pMem->db->mallocFailed );
75741 pMem->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal|MEM_Blob|MEM_Zero);
75742 return sqlite3VdbeChangeEncoding(pMem, encoding);
75743 }
75744 }
75745 return SQLITE_OK;
75746 }
75747
75748 /*
75749 ** Initialize bulk memory to be a consistent Mem object.
75750 **
@@ -77454,10 +77513,11 @@
77513 **
77514 ** * OP_Halt with P1=SQLITE_CONSTRAINT and P2=OE_Abort.
77515 ** * OP_HaltIfNull with P1=SQLITE_CONSTRAINT and P2=OE_Abort.
77516 ** * OP_Destroy
77517 ** * OP_VUpdate
77518 ** * OP_VCreate
77519 ** * OP_VRename
77520 ** * OP_FkCounter with P2==0 (immediate foreign key constraint)
77521 ** * OP_CreateBtree/BTREE_INTKEY and OP_InitCoroutine
77522 ** (for CREATE TABLE AS SELECT ...)
77523 **
@@ -77481,10 +77541,11 @@
77541
77542 while( (pOp = opIterNext(&sIter))!=0 ){
77543 int opcode = pOp->opcode;
77544 if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
77545 || opcode==OP_VDestroy
77546 || opcode==OP_VCreate
77547 || (opcode==OP_ParseSchema && pOp->p4.z==0)
77548 || ((opcode==OP_Halt || opcode==OP_HaltIfNull)
77549 && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
77550 ){
77551 hasAbort = 1;
@@ -77970,10 +78031,33 @@
78031 return sqlite3VdbeChangeToNoop(p, p->nOp-1);
78032 }else{
78033 return 0;
78034 }
78035 }
78036
78037 #ifdef SQLITE_DEBUG
78038 /*
78039 ** Generate an OP_ReleaseReg opcode to indicate that a range of
78040 ** registers, except any identified by mask, are no longer in use.
78041 */
78042 SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(Parse *pParse, int iFirst, int N, u32 mask){
78043 assert( pParse->pVdbe );
78044 while( N>0 && (mask&1)!=0 ){
78045 mask >>= 1;
78046 iFirst++;
78047 N--;
78048 }
78049 while( N>0 && N<=32 && (mask & MASKBIT32(N-1))!=0 ){
78050 mask &= ~MASKBIT32(N-1);
78051 N--;
78052 }
78053 if( N>0 ){
78054 sqlite3VdbeAddOp3(pParse->pVdbe, OP_ReleaseReg, iFirst, N, *(int*)&mask);
78055 }
78056 }
78057 #endif /* SQLITE_DEBUG */
78058
78059
78060 /*
78061 ** Change the value of the P4 operand for a specific instruction.
78062 ** This routine is useful when a large program is loaded from a
78063 ** static array using sqlite3VdbeAddOpList but we want to make a
@@ -78088,11 +78172,12 @@
78172 ** makes the code easier to read during debugging. None of this happens
78173 ** in a production build.
78174 */
78175 static void vdbeVComment(Vdbe *p, const char *zFormat, va_list ap){
78176 assert( p->nOp>0 || p->aOp==0 );
78177 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed
78178 || p->pParse->nErr>0 );
78179 if( p->nOp ){
78180 assert( p->aOp );
78181 sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment);
78182 p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap);
78183 }
@@ -86128,13 +86213,15 @@
86213 testcase( pOp->p2==SQLITE_AFF_INTEGER );
86214 testcase( pOp->p2==SQLITE_AFF_REAL );
86215 pIn1 = &aMem[pOp->p1];
86216 memAboutToChange(p, pIn1);
86217 rc = ExpandBlob(pIn1);
86218 if( rc ) goto abort_due_to_error;
86219 rc = sqlite3VdbeMemCast(pIn1, pOp->p2, encoding);
86220 if( rc ) goto abort_due_to_error;
86221 UPDATE_MAX_BLOBSIZE(pIn1);
86222 REGISTER_TRACE(pOp->p1, pIn1);
86223 break;
86224 }
86225 #endif /* SQLITE_OMIT_CAST */
86226
86227 /* Opcode: Eq P1 P2 P3 P4 P5
@@ -86289,16 +86376,11 @@
86376 affinity = pOp->p5 & SQLITE_AFF_MASK;
86377 if( affinity>=SQLITE_AFF_NUMERIC ){
86378 if( (flags1 | flags3)&MEM_Str ){
86379 if( (flags1 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
86380 applyNumericAffinity(pIn1,0);
86381 testcase( flags3!=pIn3->flags );
 
 
 
 
 
86382 flags3 = pIn3->flags;
86383 }
86384 if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
86385 applyNumericAffinity(pIn3,0);
86386 }
@@ -86317,11 +86399,11 @@
86399 testcase( pIn1->flags & MEM_Real );
86400 testcase( pIn1->flags & MEM_IntReal );
86401 sqlite3VdbeMemStringify(pIn1, encoding, 1);
86402 testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
86403 flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
86404 if( pIn1==pIn3 ) flags3 = flags1 | MEM_Str;
86405 }
86406 if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
86407 testcase( pIn3->flags & MEM_Int );
86408 testcase( pIn3->flags & MEM_Real );
86409 testcase( pIn3->flags & MEM_IntReal );
@@ -86352,14 +86434,14 @@
86434 static const unsigned char aGTb[] = { 1, 0, 1, 0, 0, 1 };
86435 res2 = aGTb[pOp->opcode - OP_Ne];
86436 }
86437
86438 /* Undo any changes made by applyAffinity() to the input registers. */
86439 assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
86440 pIn3->flags = flags3;
86441 assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
86442 pIn1->flags = flags1;
 
 
86443
86444 if( pOp->p5 & SQLITE_STOREP2 ){
86445 pOut = &aMem[pOp->p2];
86446 iCompare = res;
86447 if( (pOp->p5 & SQLITE_KEEPNULL)!=0 ){
@@ -86391,20 +86473,35 @@
86473 break;
86474 }
86475
86476 /* Opcode: ElseNotEq * P2 * * *
86477 **
86478 ** This opcode must follow an OP_Lt or OP_Gt comparison operator. There
86479 ** can be zero or more OP_ReleaseReg opcodes intervening, but no other
86480 ** opcodes are allowed to occur between this instruction and the previous
86481 ** OP_Lt or OP_Gt. Furthermore, the prior OP_Lt or OP_Gt must have the
86482 ** SQLITE_STOREP2 bit set in the P5 field.
86483 **
86484 ** If result of an OP_Eq comparison on the same two operands as the
86485 ** prior OP_Lt or OP_Gt would have been NULL or false (0), then then
86486 ** jump to P2. If the result of an OP_Eq comparison on the two previous
86487 ** operands would have been true (1), then fall through.
86488 */
86489 case OP_ElseNotEq: { /* same as TK_ESCAPE, jump */
86490
86491 #ifdef SQLITE_DEBUG
86492 /* Verify the preconditions of this opcode - that it follows an OP_Lt or
86493 ** OP_Gt with the SQLITE_STOREP2 flag set, with zero or more intervening
86494 ** OP_ReleaseReg opcodes */
86495 int iAddr;
86496 for(iAddr = (int)(pOp - aOp) - 1; ALWAYS(iAddr>=0); iAddr--){
86497 if( aOp[iAddr].opcode==OP_ReleaseReg ) continue;
86498 assert( aOp[iAddr].opcode==OP_Lt || aOp[iAddr].opcode==OP_Gt );
86499 assert( aOp[iAddr].p5 & SQLITE_STOREP2 );
86500 break;
86501 }
86502 #endif /* SQLITE_DEBUG */
86503 VdbeBranchTaken(iCompare!=0, 2);
86504 if( iCompare!=0 ) goto jump_to_p2;
86505 break;
86506 }
86507
@@ -86811,11 +86908,13 @@
86908 const u8 *zEndHdr; /* Pointer to first byte after the header */
86909 u64 offset64; /* 64-bit offset */
86910 u32 t; /* A type code from the record header */
86911 Mem *pReg; /* PseudoTable input register */
86912
86913 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
86914 pC = p->apCsr[pOp->p1];
86915 assert( pC!=0 );
86916 p2 = pOp->p2;
86917
86918 /* If the cursor cache is stale (meaning it is not currently point at
86919 ** the correct row) then bring it up-to-date by doing the necessary
86920 ** B-Tree seek. */
@@ -86823,11 +86922,10 @@
86922 if( rc ) goto abort_due_to_error;
86923
86924 assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) );
86925 pDest = &aMem[pOp->p3];
86926 memAboutToChange(p, pDest);
 
86927 assert( pC!=0 );
86928 assert( p2<pC->nField );
86929 aOffset = pC->aOffset;
86930 assert( pC->eCurType!=CURTYPE_VTAB );
86931 assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow );
@@ -87080,11 +87178,11 @@
87178 assert( pOp->p2>0 );
87179 assert( zAffinity[pOp->p2]==0 );
87180 pIn1 = &aMem[pOp->p1];
87181 while( 1 /*exit-by-break*/ ){
87182 assert( pIn1 <= &p->aMem[(p->nMem+1 - p->nCursor)] );
87183 assert( zAffinity[0]==SQLITE_AFF_NONE || memIsValid(pIn1) );
87184 applyAffinity(pIn1, zAffinity[0], encoding);
87185 if( zAffinity[0]==SQLITE_AFF_REAL && (pIn1->flags & MEM_Int)!=0 ){
87186 /* When applying REAL affinity, if the result is still an MEM_Int
87187 ** that will fit in 6 bytes, then change the type to MEM_IntReal
87188 ** so that we keep the high-resolution integer value but know that
@@ -87526,12 +87624,16 @@
87624 p->pc = (int)(pOp - aOp);
87625 db->autoCommit = 0;
87626 p->rc = rc = SQLITE_BUSY;
87627 goto vdbe_return;
87628 }
 
87629 rc = p->rc;
87630 if( rc ){
87631 db->autoCommit = 0;
87632 }else{
87633 db->isTransactionSavepoint = 0;
87634 }
87635 }else{
87636 int isSchemaChange;
87637 iSavepoint = db->nSavepoint - iSavepoint - 1;
87638 if( p1==SAVEPOINT_ROLLBACK ){
87639 isSchemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0;
@@ -87555,10 +87657,11 @@
87657 sqlite3ExpirePreparedStatements(db, 0);
87658 sqlite3ResetAllSchemasOfConnection(db);
87659 db->mDbFlags |= DBFLAG_SchemaChange;
87660 }
87661 }
87662 if( rc ) goto abort_due_to_error;
87663
87664 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
87665 ** savepoints nested inside of the savepoint being operated on. */
87666 while( db->pSavepoint!=pSavepoint ){
87667 pTmp = db->pSavepoint;
@@ -88050,10 +88153,11 @@
88153 case OP_OpenDup: {
88154 VdbeCursor *pOrig; /* The original cursor to be duplicated */
88155 VdbeCursor *pCx; /* The new cursor */
88156
88157 pOrig = p->apCsr[pOp->p2];
88158 assert( pOrig );
88159 assert( pOrig->pBtx!=0 ); /* Only ephemeral cursors can be duplicated */
88160
88161 pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE);
88162 if( pCx==0 ) goto no_mem;
88163 pCx->nullRow = 1;
@@ -91479,11 +91583,11 @@
91583 pVtab = pCur->uc.pVCur->pVtab;
91584 pModule = pVtab->pModule;
91585 assert( pModule->xColumn );
91586 memset(&sContext, 0, sizeof(sContext));
91587 sContext.pOut = pDest;
91588 assert( pOp->p5==OPFLAG_NOCHNG || pOp->p5==0 );
91589 if( pOp->p5 & OPFLAG_NOCHNG ){
91590 sqlite3VdbeMemSetNull(pDest);
91591 pDest->flags = MEM_Null|MEM_Zero;
91592 pDest->u.nZero = 0;
91593 }else{
@@ -91939,10 +92043,57 @@
92043 case OP_Abortable: {
92044 sqlite3VdbeAssertAbortable(p);
92045 break;
92046 }
92047 #endif
92048
92049 #ifdef SQLITE_DEBUG
92050 /* Opcode: ReleaseReg P1 P2 P3 * *
92051 ** Synopsis: release r[P1@P2] mask P3
92052 **
92053 ** Release registers from service. Any content that was in the
92054 ** the registers is unreliable after this opcode completes.
92055 **
92056 ** The registers released will be the P2 registers starting at P1,
92057 ** except if bit ii of P3 set, then do not release register P1+ii.
92058 ** In other words, P3 is a mask of registers to preserve.
92059 **
92060 ** Releasing a register clears the Mem.pScopyFrom pointer. That means
92061 ** that if the content of the released register was set using OP_SCopy,
92062 ** a change to the value of the source register for the OP_SCopy will no longer
92063 ** generate an assertion fault in sqlite3VdbeMemAboutToChange().
92064 **
92065 ** TODO: Released registers ought to also have their datatype set to
92066 ** MEM_Undefined so that any subsequent attempt to read the released
92067 ** register (before it is reinitialized) will generate an assertion fault.
92068 ** However, there are places in the code generator which release registers
92069 ** before their are used, under the (valid) assumption that the registers
92070 ** will not be reallocated for some other purpose before they are used and
92071 ** hence are safe to release.
92072 **
92073 ** This opcode is only available in testing and debugging builds. It is
92074 ** not generated for release builds. The purpose of this opcode is to help
92075 ** validate the generated bytecode. This opcode does not actually contribute
92076 ** to computing an answer.
92077 */
92078 case OP_ReleaseReg: {
92079 Mem *pMem;
92080 int i;
92081 u32 constMask;
92082 assert( pOp->p1>0 );
92083 assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 );
92084 pMem = &aMem[pOp->p1];
92085 constMask = pOp->p3;
92086 for(i=0; i<pOp->p2; i++, pMem++){
92087 if( i>=32 || (constMask & MASKBIT32(i))==0 ){
92088 pMem->pScopyFrom = 0;
92089 /* MemSetTypeFlag(pMem, MEM_Undefined); // See the TODO */
92090 }
92091 }
92092 break;
92093 }
92094 #endif
92095
92096 /* Opcode: Noop * * * * *
92097 **
92098 ** Do nothing. This instruction is often useful as a jump
92099 ** destination.
@@ -95849,12 +96000,12 @@
96000 testcase( ExprHasProperty(pExpr, EP_Reduced) );
96001 while(1){
96002 rc = pWalker->xExprCallback(pWalker, pExpr);
96003 if( rc ) return rc & WRC_Abort;
96004 if( !ExprHasProperty(pExpr,(EP_TokenOnly|EP_Leaf)) ){
96005 assert( pExpr->x.pList==0 || pExpr->pRight==0 );
96006 if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
 
96007 if( pExpr->pRight ){
96008 assert( !ExprHasProperty(pExpr, EP_WinFunc) );
96009 pExpr = pExpr->pRight;
96010 continue;
96011 }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
@@ -96538,22 +96689,39 @@
96689 pTopNC->nErr++;
96690 }
96691
96692 /* If a column from a table in pSrcList is referenced, then record
96693 ** this fact in the pSrcList.a[].colUsed bitmask. Column 0 causes
96694 ** bit 0 to be set. Column 1 sets bit 1. And so forth. Bit 63 is
96695 ** set if the 63rd or any subsequent column is used.
96696 **
96697 ** The colUsed mask is an optimization used to help determine if an
96698 ** index is a covering index. The correct answer is still obtained
96699 ** if the mask contains extra set bits. However, it is important to
96700 ** avoid setting bits beyond the maximum column number of the table.
96701 ** (See ticket [b92e5e8ec2cdbaa1]).
96702 **
96703 ** If a generated column is referenced, set bits for every column
96704 ** of the table.
96705 */
96706 if( pExpr->iColumn>=0 && pMatch!=0 ){
96707 int n = pExpr->iColumn;
96708 Table *pExTab = pExpr->y.pTab;
96709 assert( pExTab!=0 );
 
 
96710 assert( pMatch->iCursor==pExpr->iTable );
96711 if( (pExTab->tabFlags & TF_HasGenerated)!=0
96712 && (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0
96713 ){
96714 testcase( pExTab->nCol==BMS-1 );
96715 testcase( pExTab->nCol==BMS );
96716 pMatch->colUsed = pExTab->nCol>=BMS ? ALLBITS : MASKBIT(pExTab->nCol)-1;
96717 }else{
96718 testcase( n==BMS-1 );
96719 testcase( n==BMS );
96720 if( n>=BMS ) n = BMS-1;
96721 pMatch->colUsed |= ((Bitmask)1)<<n;
96722 }
96723 }
96724
96725 /* Clean up and return
96726 */
96727 sqlite3ExprDelete(db, pExpr->pLeft);
@@ -96588,47 +96756,68 @@
96756 */
96757 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
96758 Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
96759 if( p ){
96760 struct SrcList_item *pItem = &pSrc->a[iSrc];
96761 Table *pTab = p->y.pTab = pItem->pTab;
96762 p->iTable = pItem->iCursor;
96763 if( p->y.pTab->iPKey==iCol ){
96764 p->iColumn = -1;
96765 }else{
96766 p->iColumn = (ynVar)iCol;
96767 if( (pTab->tabFlags & TF_HasGenerated)!=0
96768 && (pTab->aCol[iCol].colFlags & COLFLAG_GENERATED)!=0
96769 ){
96770 testcase( pTab->nCol==63 );
96771 testcase( pTab->nCol==64 );
96772 pItem->colUsed = pTab->nCol>=64 ? ALLBITS : MASKBIT(pTab->nCol)-1;
96773 }else{
96774 testcase( iCol==BMS );
96775 testcase( iCol==BMS-1 );
96776 pItem->colUsed |= ((Bitmask)1)<<(iCol>=BMS ? BMS-1 : iCol);
96777 }
96778 }
96779 }
96780 return p;
96781 }
96782
96783 /*
96784 ** Report an error that an expression is not valid for some set of
96785 ** pNC->ncFlags values determined by validMask.
96786 **
96787 ** static void notValid(
96788 ** Parse *pParse, // Leave error message here
96789 ** NameContext *pNC, // The name context
96790 ** const char *zMsg, // Type of error
96791 ** int validMask, // Set of contexts for which prohibited
96792 ** Expr *pExpr // Invalidate this expression on error
96793 ** ){...}
96794 **
96795 ** As an optimization, since the conditional is almost always false
96796 ** (because errors are rare), the conditional is moved outside of the
96797 ** function call using a macro.
96798 */
96799 static void notValidImpl(
96800 Parse *pParse, /* Leave error message here */
96801 NameContext *pNC, /* The name context */
96802 const char *zMsg, /* Type of error */
96803 Expr *pExpr /* Invalidate this expression on error */
96804 ){
96805 const char *zIn = "partial index WHERE clauses";
96806 if( pNC->ncFlags & NC_IdxExpr ) zIn = "index expressions";
 
 
96807 #ifndef SQLITE_OMIT_CHECK
96808 else if( pNC->ncFlags & NC_IsCheck ) zIn = "CHECK constraints";
96809 #endif
96810 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
96811 else if( pNC->ncFlags & NC_GenCol ) zIn = "generated columns";
96812 #endif
96813 sqlite3ErrorMsg(pParse, "%s prohibited in %s", zMsg, zIn);
96814 if( pExpr ) pExpr->op = TK_NULL;
96815 }
96816 #define sqlite3ResolveNotValid(P,N,M,X,E) \
96817 assert( ((X)&~(NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol))==0 ); \
96818 if( ((N)->ncFlags & (X))!=0 ) notValidImpl(P,N,M,E);
96819
96820 /*
96821 ** Expression p should encode a floating point value between 1.0 and 0.0.
96822 ** Return 1024 times this value. Or return -1 if p is not a floating point
96823 ** value between 1.0 and 0.0.
@@ -96713,11 +96902,14 @@
96902 zDb = 0;
96903 zTable = 0;
96904 zColumn = pExpr->u.zToken;
96905 }else{
96906 Expr *pLeft = pExpr->pLeft;
96907 testcase( pNC->ncFlags & NC_IdxExpr );
96908 testcase( pNC->ncFlags & NC_GenCol );
96909 sqlite3ResolveNotValid(pParse, pNC, "the \".\" operator",
96910 NC_IdxExpr|NC_GenCol, 0);
96911 pRight = pExpr->pRight;
96912 if( pRight->op==TK_ID ){
96913 zDb = 0;
96914 }else{
96915 assert( pRight->op==TK_DOT );
@@ -96810,11 +97002,12 @@
97002 }
97003 if( (pDef->funcFlags & SQLITE_FUNC_CONSTANT)==0 ){
97004 /* Date/time functions that use 'now', and other functions like
97005 ** sqlite_version() that might change over time cannot be used
97006 ** in an index. */
97007 sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions",
97008 NC_SelfRef, 0);
97009 }else{
97010 assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
97011 pExpr->op2 = pNC->ncFlags & NC_SelfRef;
97012 }
97013 if( (pDef->funcFlags & SQLITE_FUNC_INTERNAL)!=0
@@ -96912,11 +97105,11 @@
97105 #ifndef SQLITE_OMIT_WINDOWFUNC
97106 if( pWin ){
97107 Select *pSel = pNC->pWinSelect;
97108 assert( pWin==pExpr->y.pWin );
97109 if( IN_RENAME_OBJECT==0 ){
97110 sqlite3WindowUpdate(pParse, pSel ? pSel->pWinDefn : 0, pWin, pDef);
97111 }
97112 sqlite3WalkExprList(pWalker, pWin->pPartition);
97113 sqlite3WalkExprList(pWalker, pWin->pOrderBy);
97114 sqlite3WalkExpr(pWalker, pWin->pFilter);
97115 sqlite3WindowLink(pSel, pWin);
@@ -96957,12 +97150,16 @@
97150 #endif
97151 case TK_IN: {
97152 testcase( pExpr->op==TK_IN );
97153 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
97154 int nRef = pNC->nRef;
97155 testcase( pNC->ncFlags & NC_IsCheck );
97156 testcase( pNC->ncFlags & NC_PartIdx );
97157 testcase( pNC->ncFlags & NC_IdxExpr );
97158 testcase( pNC->ncFlags & NC_GenCol );
97159 sqlite3ResolveNotValid(pParse, pNC, "subqueries",
97160 NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol, pExpr);
97161 sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
97162 assert( pNC->nRef>=nRef );
97163 if( nRef!=pNC->nRef ){
97164 ExprSetProperty(pExpr, EP_VarSelect);
97165 pNC->ncFlags |= NC_VarSelect;
@@ -96969,12 +97166,16 @@
97166 }
97167 }
97168 break;
97169 }
97170 case TK_VARIABLE: {
97171 testcase( pNC->ncFlags & NC_IsCheck );
97172 testcase( pNC->ncFlags & NC_PartIdx );
97173 testcase( pNC->ncFlags & NC_IdxExpr );
97174 testcase( pNC->ncFlags & NC_GenCol );
97175 sqlite3ResolveNotValid(pParse, pNC, "parameters",
97176 NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol, pExpr);
97177 break;
97178 }
97179 case TK_IS:
97180 case TK_ISNOT: {
97181 Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight);
@@ -98203,10 +98404,11 @@
98404 ){
98405 int p5;
98406 int addr;
98407 CollSeq *p4;
98408
98409 if( pParse->nErr ) return 0;
98410 if( isCommuted ){
98411 p4 = sqlite3BinaryCompareCollSeq(pParse, pRight, pLeft);
98412 }else{
98413 p4 = sqlite3BinaryCompareCollSeq(pParse, pLeft, pRight);
98414 }
@@ -98420,10 +98622,11 @@
98622 int regRight = 0;
98623 u8 opx = op;
98624 int addrDone = sqlite3VdbeMakeLabel(pParse);
98625 int isCommuted = ExprHasProperty(pExpr,EP_Commuted);
98626
98627 if( pParse->nErr ) return;
98628 if( nLeft!=sqlite3ExprVectorSize(pRight) ){
98629 sqlite3ErrorMsg(pParse, "row value misused");
98630 return;
98631 }
98632 assert( pExpr->op==TK_EQ || pExpr->op==TK_NE
@@ -99768,11 +99971,13 @@
99971 switch( pExpr->op ){
99972 /* Consider functions to be constant if all their arguments are constant
99973 ** and either pWalker->eCode==4 or 5 or the function has the
99974 ** SQLITE_FUNC_CONST flag. */
99975 case TK_FUNCTION:
99976 if( (pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_ConstFunc))
99977 && !ExprHasProperty(pExpr, EP_WinFunc)
99978 ){
99979 return WRC_Continue;
99980 }else{
99981 pWalker->eCode = 0;
99982 return WRC_Abort;
99983 }
@@ -100031,11 +100236,13 @@
100236 case TK_BLOB:
100237 return 0;
100238 case TK_COLUMN:
100239 return ExprHasProperty(p, EP_CanBeNull) ||
100240 p->y.pTab==0 || /* Reference to column of index on expression */
100241 (p->iColumn>=0
100242 && ALWAYS(p->y.pTab->aCol!=0) /* Defense against OOM problems */
100243 && p->y.pTab->aCol[p->iColumn].notNull==0);
100244 default:
100245 return 1;
100246 }
100247 }
100248
@@ -100508,12 +100715,14 @@
100715 ** message of the form:
100716 **
100717 ** "sub-select returns N columns - expected M"
100718 */
100719 SQLITE_PRIVATE void sqlite3SubselectError(Parse *pParse, int nActual, int nExpect){
100720 if( pParse->nErr==0 ){
100721 const char *zFmt = "sub-select returns %d columns - expected %d";
100722 sqlite3ErrorMsg(pParse, zFmt, nActual, nExpect);
100723 }
100724 }
100725 #endif
100726
100727 /*
100728 ** Expression pExpr is a vector that has been used in a context where
@@ -101011,19 +101220,25 @@
101220 }
101221 if( regCkNull && sqlite3ExprCanBeNull(pList->a[ii].pExpr) ){
101222 sqlite3VdbeAddOp3(v, OP_BitAnd, regCkNull, r2, regCkNull);
101223 }
101224 if( ii<pList->nExpr-1 || destIfNull!=destIfFalse ){
101225 int op = rLhs!=r2 ? OP_Eq : OP_NotNull;
101226 sqlite3VdbeAddOp4(v, op, rLhs, labelOk, r2,
101227 (void*)pColl, P4_COLLSEQ);
101228 VdbeCoverageIf(v, ii<pList->nExpr-1 && op==OP_Eq);
101229 VdbeCoverageIf(v, ii==pList->nExpr-1 && op==OP_Eq);
101230 VdbeCoverageIf(v, ii<pList->nExpr-1 && op==OP_NotNull);
101231 VdbeCoverageIf(v, ii==pList->nExpr-1 && op==OP_NotNull);
101232 sqlite3VdbeChangeP5(v, zAff[0]);
101233 }else{
101234 int op = rLhs!=r2 ? OP_Ne : OP_IsNull;
101235 assert( destIfNull==destIfFalse );
101236 sqlite3VdbeAddOp4(v, op, rLhs, destIfFalse, r2,
101237 (void*)pColl, P4_COLLSEQ);
101238 VdbeCoverageIf(v, op==OP_Ne);
101239 VdbeCoverageIf(v, op==OP_IsNull);
101240 sqlite3VdbeChangeP5(v, zAff[0] | SQLITE_JUMPIFNULL);
101241 }
101242 sqlite3ReleaseTempReg(pParse, regToFree);
101243 }
101244 if( regCkNull ){
@@ -101042,10 +101257,11 @@
101257 if( destIfNull==destIfFalse ){
101258 destStep2 = destIfFalse;
101259 }else{
101260 destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
101261 }
101262 if( pParse->nErr ) goto sqlite3ExprCodeIN_finished;
101263 for(i=0; i<nVector; i++){
101264 Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
101265 if( sqlite3ExprCanBeNull(p) ){
101266 sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
101267 VdbeCoverage(v);
@@ -101233,15 +101449,24 @@
101449 SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(
101450 Parse *pParse,
101451 Column *pCol,
101452 int regOut
101453 ){
101454 int iAddr;
101455 Vdbe *v = pParse->pVdbe;
101456 assert( v!=0 );
101457 assert( pParse->iSelfTab!=0 );
101458 if( pParse->iSelfTab>0 ){
101459 iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut);
101460 }else{
101461 iAddr = 0;
101462 }
101463 sqlite3ExprCode(pParse, pCol->pDflt, regOut);
101464 if( pCol->affinity>=SQLITE_AFF_TEXT ){
101465 sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1);
 
101466 }
101467 if( iAddr ) sqlite3VdbeJumpHere(v, iAddr);
101468 }
101469 #endif /* SQLITE_OMIT_GENERATED_COLUMNS */
101470
101471 /*
101472 ** Generate code to extract the value of the iCol-th column of a table.
@@ -101312,21 +101537,21 @@
101537 u8 p5 /* P5 value for OP_Column + FLAGS */
101538 ){
101539 assert( pParse->pVdbe!=0 );
101540 sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pTab, iTable, iColumn, iReg);
101541 if( p5 ){
101542 VdbeOp *pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1);
101543 if( pOp->opcode==OP_Column ) pOp->p5 = p5;
101544 }
101545 return iReg;
101546 }
101547
101548 /*
101549 ** Generate code to move content from registers iFrom...iFrom+nReg-1
101550 ** over to iTo..iTo+nReg-1.
101551 */
101552 SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse *pParse, int iFrom, int iTo, int nReg){
 
101553 sqlite3VdbeAddOp3(pParse->pVdbe, OP_Move, iFrom, iTo, nReg);
101554 }
101555
101556 /*
101557 ** Convert a scalar expression node to a TK_REGISTER referencing
@@ -101424,19 +101649,25 @@
101649 }
101650 /* Otherwise, fall thru into the TK_COLUMN case */
101651 }
101652 case TK_COLUMN: {
101653 int iTab = pExpr->iTable;
101654 int iReg;
101655 if( ExprHasProperty(pExpr, EP_FixedCol) ){
101656 /* This COLUMN expression is really a constant due to WHERE clause
101657 ** constraints, and that constant is coded by the pExpr->pLeft
101658 ** expresssion. However, make sure the constant has the correct
101659 ** datatype by applying the Affinity of the table column to the
101660 ** constant.
101661 */
101662 int aff;
101663 iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target);
101664 if( pExpr->y.pTab ){
101665 aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
101666 }else{
101667 aff = pExpr->affExpr;
101668 }
101669 if( aff>SQLITE_AFF_BLOB ){
101670 static const char zAff[] = "B\000C\000D\000E";
101671 assert( SQLITE_AFF_BLOB=='A' );
101672 assert( SQLITE_AFF_TEXT=='B' );
101673 if( iReg!=target ){
@@ -101460,11 +101691,11 @@
101691 Table *pTab = pExpr->y.pTab;
101692 int iSrc;
101693 int iCol = pExpr->iColumn;
101694 assert( pTab!=0 );
101695 assert( iCol>=XN_ROWID );
101696 assert( iCol<pTab->nCol );
101697 if( iCol<0 ){
101698 return -1-pParse->iSelfTab;
101699 }
101700 pCol = pTab->aCol + iCol;
101701 testcase( iCol!=sqlite3TableColumnToStorage(pTab,iCol) );
@@ -101495,13 +101726,17 @@
101726 /* Coding an expression that is part of an index where column names
101727 ** in the index refer to the table to which the index belongs */
101728 iTab = pParse->iSelfTab - 1;
101729 }
101730 }
101731 iReg = sqlite3ExprCodeGetColumn(pParse, pExpr->y.pTab,
101732 pExpr->iColumn, iTab, target,
101733 pExpr->op2);
101734 if( pExpr->y.pTab==0 && pExpr->affExpr==SQLITE_AFF_REAL ){
101735 sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
101736 }
101737 return iReg;
101738 }
101739 case TK_INTEGER: {
101740 codeInteger(pParse, pExpr, 0, target);
101741 return target;
101742 }
@@ -101519,11 +101754,16 @@
101754 case TK_STRING: {
101755 assert( !ExprHasProperty(pExpr, EP_IntValue) );
101756 sqlite3VdbeLoadString(v, target, pExpr->u.zToken);
101757 return target;
101758 }
101759 default: {
101760 /* Make NULL the default case so that if a bug causes an illegal
101761 ** Expr node to be passed into this function, it will be handled
101762 ** sanely and not crash. But keep the assert() to bring the problem
101763 ** to the attention of the developers. */
101764 assert( op==TK_NULL );
101765 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
101766 return target;
101767 }
101768 #ifndef SQLITE_OMIT_BLOB_LITERAL
101769 case TK_BLOB: {
@@ -101546,11 +101786,11 @@
101786 assert( pExpr->u.zToken!=0 );
101787 assert( pExpr->u.zToken[0]!=0 );
101788 sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target);
101789 if( pExpr->u.zToken[1]!=0 ){
101790 const char *z = sqlite3VListNumToName(pParse->pVList, pExpr->iColumn);
101791 assert( pExpr->u.zToken[0]=='?' || (z && !strcmp(pExpr->u.zToken, z)) );
101792 pParse->pVList[0] = 0; /* Indicate VList may no longer be enlarged */
101793 sqlite3VdbeAppendP4(v, (char*)z, P4_STATIC);
101794 }
101795 return target;
101796 }
@@ -101859,12 +102099,16 @@
102099 #endif
102100 {
102101 sqlite3VdbeAddFunctionCall(pParse, constMask, r1, target, nFarg,
102102 pDef, pExpr->op2);
102103 }
102104 if( nFarg ){
102105 if( constMask==0 ){
102106 sqlite3ReleaseTempRange(pParse, r1, nFarg);
102107 }else{
102108 sqlite3VdbeReleaseRegisters(pParse, r1, nFarg, constMask);
102109 }
102110 }
102111 return target;
102112 }
102113 #ifndef SQLITE_OMIT_SUBQUERY
102114 case TK_EXISTS:
@@ -101956,11 +102200,11 @@
102200 ** p1==2 -> old.b p1==5 -> new.b
102201 */
102202 Table *pTab = pExpr->y.pTab;
102203 int iCol = pExpr->iColumn;
102204 int p1 = pExpr->iTable * (pTab->nCol+1) + 1
102205 + sqlite3TableColumnToStorage(pTab, iCol);
102206
102207 assert( pExpr->iTable==0 || pExpr->iTable==1 );
102208 assert( iCol>=-1 && iCol<pTab->nCol );
102209 assert( pTab->iPKey<0 || iCol!=pTab->iPKey );
102210 assert( p1>=0 && p1<(pTab->nCol*2+2) );
@@ -102030,11 +102274,11 @@
102274 **
102275 ** The result of the expression is the Ri for the first matching Ei,
102276 ** or if there is no matching Ei, the ELSE term Y, or if there is
102277 ** no ELSE term, NULL.
102278 */
102279 case TK_CASE: {
102280 int endLabel; /* GOTO label for end of CASE stmt */
102281 int nextCase; /* GOTO label for next WHEN clause */
102282 int nExpr; /* 2x number of WHEN terms */
102283 int i; /* Loop counter */
102284 ExprList *pEList; /* List of WHEN terms */
@@ -103087,11 +103331,14 @@
103331 sqlite3WalkExpr(pWalker, pExpr->pRight);
103332 }
103333 return WRC_Prune;
103334
103335 case TK_BETWEEN:
103336 if( sqlite3WalkExpr(pWalker, pExpr->pLeft)==WRC_Abort ){
103337 assert( pWalker->eCode );
103338 return WRC_Abort;
103339 }
103340 return WRC_Prune;
103341
103342 /* Virtual tables are allowed to use constraints like x=NULL. So
103343 ** a term of the form x=y does not prove that y is not null if x
103344 ** is the column of a virtual table */
@@ -103501,12 +103748,15 @@
103748 /*
103749 ** Deallocate a register, making available for reuse for some other
103750 ** purpose.
103751 */
103752 SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse *pParse, int iReg){
103753 if( iReg ){
103754 sqlite3VdbeReleaseRegisters(pParse, iReg, 1, 0);
103755 if( pParse->nTempReg<ArraySize(pParse->aTempReg) ){
103756 pParse->aTempReg[pParse->nTempReg++] = iReg;
103757 }
103758 }
103759 }
103760
103761 /*
103762 ** Allocate or deallocate a block of nReg consecutive registers.
@@ -103528,10 +103778,11 @@
103778 SQLITE_PRIVATE void sqlite3ReleaseTempRange(Parse *pParse, int iReg, int nReg){
103779 if( nReg==1 ){
103780 sqlite3ReleaseTempReg(pParse, iReg);
103781 return;
103782 }
103783 sqlite3VdbeReleaseRegisters(pParse, iReg, nReg, 0);
103784 if( nReg>pParse->nRangeReg ){
103785 pParse->nRangeReg = nReg;
103786 pParse->iRangeReg = iReg;
103787 }
103788 }
@@ -104271,16 +104522,18 @@
104522 */
104523 SQLITE_PRIVATE void *sqlite3RenameTokenMap(Parse *pParse, void *pPtr, Token *pToken){
104524 RenameToken *pNew;
104525 assert( pPtr || pParse->db->mallocFailed );
104526 renameTokenCheckAll(pParse, pPtr);
104527 if( pParse->eParseMode!=PARSE_MODE_UNMAP ){
104528 pNew = sqlite3DbMallocZero(pParse->db, sizeof(RenameToken));
104529 if( pNew ){
104530 pNew->p = pPtr;
104531 pNew->t = *pToken;
104532 pNew->pNext = pParse->pRename;
104533 pParse->pRename = pNew;
104534 }
104535 }
104536
104537 return pPtr;
104538 }
104539
@@ -104306,17 +104559,39 @@
104559 static int renameUnmapExprCb(Walker *pWalker, Expr *pExpr){
104560 Parse *pParse = pWalker->pParse;
104561 sqlite3RenameTokenRemap(pParse, 0, (void*)pExpr);
104562 return WRC_Continue;
104563 }
104564
104565 /*
104566 ** Iterate through the Select objects that are part of WITH clauses attached
104567 ** to select statement pSelect.
104568 */
104569 static void renameWalkWith(Walker *pWalker, Select *pSelect){
104570 With *pWith = pSelect->pWith;
104571 if( pWith ){
104572 int i;
104573 for(i=0; i<pWith->nCte; i++){
104574 Select *p = pWith->a[i].pSelect;
104575 NameContext sNC;
104576 memset(&sNC, 0, sizeof(sNC));
104577 sNC.pParse = pWalker->pParse;
104578 sqlite3SelectPrep(sNC.pParse, p, &sNC);
104579 sqlite3WalkSelect(pWalker, p);
104580 sqlite3RenameExprlistUnmap(pWalker->pParse, pWith->a[i].pCols);
104581 }
104582 }
104583 }
104584
104585 /*
104586 ** Walker callback used by sqlite3RenameExprUnmap().
104587 */
104588 static int renameUnmapSelectCb(Walker *pWalker, Select *p){
104589 Parse *pParse = pWalker->pParse;
104590 int i;
104591 if( pParse->nErr ) return WRC_Abort;
104592 if( NEVER(p->selFlags & SF_View) ) return WRC_Prune;
104593 if( ALWAYS(p->pEList) ){
104594 ExprList *pList = p->pEList;
104595 for(i=0; i<pList->nExpr; i++){
104596 if( pList->a[i].zName ){
104597 sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zName);
@@ -104325,25 +104600,31 @@
104600 }
104601 if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
104602 SrcList *pSrc = p->pSrc;
104603 for(i=0; i<pSrc->nSrc; i++){
104604 sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName);
104605 if( sqlite3WalkExpr(pWalker, pSrc->a[i].pOn) ) return WRC_Abort;
104606 }
104607 }
104608
104609 renameWalkWith(pWalker, p);
104610 return WRC_Continue;
104611 }
104612
104613 /*
104614 ** Remove all nodes that are part of expression pExpr from the rename list.
104615 */
104616 SQLITE_PRIVATE void sqlite3RenameExprUnmap(Parse *pParse, Expr *pExpr){
104617 u8 eMode = pParse->eParseMode;
104618 Walker sWalker;
104619 memset(&sWalker, 0, sizeof(Walker));
104620 sWalker.pParse = pParse;
104621 sWalker.xExprCallback = renameUnmapExprCb;
104622 sWalker.xSelectCallback = renameUnmapSelectCb;
104623 pParse->eParseMode = PARSE_MODE_UNMAP;
104624 sqlite3WalkExpr(&sWalker, pExpr);
104625 pParse->eParseMode = eMode;
104626 }
104627
104628 /*
104629 ** Remove all nodes that are part of expression-list pEList from the
104630 ** rename list.
@@ -104393,34 +104674,17 @@
104674 break;
104675 }
104676 }
104677 }
104678
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104679 /*
104680 ** This is a Walker select callback. It does nothing. It is only required
104681 ** because without a dummy callback, sqlite3WalkExpr() and similar do not
104682 ** descend into sub-select statements.
104683 */
104684 static int renameColumnSelectCb(Walker *pWalker, Select *p){
104685 if( p->selFlags & SF_View ) return WRC_Prune;
104686 renameWalkWith(pWalker, p);
104687 return WRC_Continue;
104688 }
104689
104690 /*
@@ -104547,11 +104811,10 @@
104811 ** is initialized by this function before it is used.
104812 */
104813 static int renameParseSql(
104814 Parse *p, /* Memory to use for Parse object */
104815 const char *zDb, /* Name of schema SQL belongs to */
 
104816 sqlite3 *db, /* Database handle */
104817 const char *zSql, /* SQL to parse */
104818 int bTemp /* True if SQL is from temp schema */
104819 ){
104820 int rc;
@@ -104561,11 +104824,11 @@
104824
104825 /* Parse the SQL statement passed as the first argument. If no error
104826 ** occurs and the parse does not result in a new table, index or
104827 ** trigger object, the database must be corrupt. */
104828 memset(p, 0, sizeof(Parse));
104829 p->eParseMode = PARSE_MODE_RENAME;
104830 p->db = db;
104831 p->nQueryLoop = 1;
104832 rc = sqlite3RunParser(p, zSql, &zErr);
104833 assert( p->zErrMsg==0 );
104834 assert( rc!=SQLITE_OK || zErr==0 );
@@ -104868,11 +105131,11 @@
105131 sCtx.iCol = ((iCol==pTab->iPKey) ? -1 : iCol);
105132
105133 #ifndef SQLITE_OMIT_AUTHORIZATION
105134 db->xAuth = 0;
105135 #endif
105136 rc = renameParseSql(&sParse, zDb, db, zSql, bTemp);
105137
105138 /* Find tokens that need to be replaced. */
105139 memset(&sWalker, 0, sizeof(Walker));
105140 sWalker.pParse = &sParse;
105141 sWalker.xExprCallback = renameColumnExprCb;
@@ -104882,12 +105145,13 @@
105145 sCtx.pTab = pTab;
105146 if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
105147 if( sParse.pNewTable ){
105148 Select *pSelect = sParse.pNewTable->pSelect;
105149 if( pSelect ){
105150 pSelect->selFlags &= ~SF_View;
105151 sParse.rc = SQLITE_OK;
105152 sqlite3SelectPrep(&sParse, pSelect, 0);
105153 rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc);
105154 if( rc==SQLITE_OK ){
105155 sqlite3WalkSelect(&sWalker, pSelect);
105156 }
105157 if( rc!=SQLITE_OK ) goto renameColumnFunc_done;
@@ -105000,10 +105264,11 @@
105264 */
105265 static int renameTableSelectCb(Walker *pWalker, Select *pSelect){
105266 int i;
105267 RenameCtx *p = pWalker->u.pRename;
105268 SrcList *pSrc = pSelect->pSrc;
105269 if( pSelect->selFlags & SF_View ) return WRC_Prune;
105270 if( pSrc==0 ){
105271 assert( pWalker->pParse->db->mallocFailed );
105272 return WRC_Abort;
105273 }
105274 for(i=0; i<pSrc->nSrc; i++){
@@ -105070,26 +105335,32 @@
105335 sWalker.pParse = &sParse;
105336 sWalker.xExprCallback = renameTableExprCb;
105337 sWalker.xSelectCallback = renameTableSelectCb;
105338 sWalker.u.pRename = &sCtx;
105339
105340 rc = renameParseSql(&sParse, zDb, db, zInput, bTemp);
105341
105342 if( rc==SQLITE_OK ){
105343 int isLegacy = (db->flags & SQLITE_LegacyAlter);
105344 if( sParse.pNewTable ){
105345 Table *pTab = sParse.pNewTable;
105346
105347 if( pTab->pSelect ){
105348 if( isLegacy==0 ){
105349 Select *pSelect = pTab->pSelect;
105350 NameContext sNC;
105351 memset(&sNC, 0, sizeof(sNC));
105352 sNC.pParse = &sParse;
105353
105354 assert( pSelect->selFlags & SF_View );
105355 pSelect->selFlags &= ~SF_View;
105356 sqlite3SelectPrep(&sParse, pTab->pSelect, &sNC);
105357 if( sParse.nErr ){
105358 rc = sParse.rc;
105359 }else{
105360 sqlite3WalkSelect(&sWalker, pTab->pSelect);
105361 }
105362 }
105363 }else{
105364 /* Modify any FK definitions to point to the new table. */
105365 #ifndef SQLITE_OMIT_FOREIGN_KEY
105366 if( isLegacy==0 || (db->flags & SQLITE_ForeignKeys) ){
@@ -105206,11 +105477,11 @@
105477
105478 UNUSED_PARAMETER(NotUsed);
105479 if( zDb && zInput ){
105480 int rc;
105481 Parse sParse;
105482 rc = renameParseSql(&sParse, zDb, db, zInput, bTemp);
105483 if( rc==SQLITE_OK ){
105484 if( isLegacy==0 && sParse.pNewTable && sParse.pNewTable->pSelect ){
105485 NameContext sNC;
105486 memset(&sNC, 0, sizeof(sNC));
105487 sNC.pParse = &sParse;
@@ -108999,17 +109270,19 @@
109270 **
109271 ** So, in other words, this routine shifts all the virtual columns to
109272 ** the end.
109273 **
109274 ** If SQLITE_OMIT_GENERATED_COLUMNS then there are no virtual columns and
109275 ** this routine is a no-op macro. If the pTab does not have any virtual
109276 ** columns, then this routine is no-op that always return iCol. If iCol
109277 ** is negative (indicating the ROWID column) then this routine return iCol.
109278 */
109279 SQLITE_PRIVATE i16 sqlite3TableColumnToStorage(Table *pTab, i16 iCol){
109280 int i;
109281 i16 n;
109282 assert( iCol<pTab->nCol );
109283 if( (pTab->tabFlags & TF_HasVirtual)==0 || iCol<0 ) return iCol;
109284 for(i=0, n=0; i<iCol; i++){
109285 if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ) n++;
109286 }
109287 if( pTab->aCol[i].colFlags & COLFLAG_VIRTUAL ){
109288 /* iCol is a virtual column itself */
@@ -109597,10 +109870,11 @@
109870 pTab->iPKey = iCol;
109871 pTab->keyConf = (u8)onError;
109872 assert( autoInc==0 || autoInc==1 );
109873 pTab->tabFlags |= autoInc*TF_Autoincrement;
109874 if( pList ) pParse->iPkSortOrder = pList->a[0].sortFlags;
109875 (void)sqlite3HasExplicitNulls(pParse, pList);
109876 }else if( autoInc ){
109877 #ifndef SQLITE_OMIT_AUTOINCREMENT
109878 sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
109879 "INTEGER PRIMARY KEY");
109880 #endif
@@ -109681,11 +109955,14 @@
109955 SQLITE_PRIVATE void sqlite3AddGenerated(Parse *pParse, Expr *pExpr, Token *pType){
109956 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
109957 u8 eType = COLFLAG_VIRTUAL;
109958 Table *pTab = pParse->pNewTable;
109959 Column *pCol;
109960 if( pTab==0 ){
109961 /* generated column in an CREATE TABLE IF NOT EXISTS that already exists */
109962 goto generated_done;
109963 }
109964 pCol = &(pTab->aCol[pTab->nCol-1]);
109965 if( IN_DECLARE_VTAB ){
109966 sqlite3ErrorMsg(pParse, "virtual tables cannot use computed columns");
109967 goto generated_done;
109968 }
@@ -110289,10 +110566,16 @@
110566 #ifndef SQLITE_OMIT_CHECK
110567 /* Resolve names in all CHECK constraint expressions.
110568 */
110569 if( p->pCheck ){
110570 sqlite3ResolveSelfReference(pParse, p, NC_IsCheck, 0, p->pCheck);
110571 if( pParse->nErr ){
110572 /* If errors are seen, delete the CHECK constraints now, else they might
110573 ** actually be used if PRAGMA writable_schema=ON is set. */
110574 sqlite3ExprListDelete(db, p->pCheck);
110575 p->pCheck = 0;
110576 }
110577 }
110578 #endif /* !defined(SQLITE_OMIT_CHECK) */
110579 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
110580 if( p->tabFlags & TF_HasGenerated ){
110581 int ii, nNG = 0;
@@ -110299,14 +110582,23 @@
110582 testcase( p->tabFlags & TF_HasVirtual );
110583 testcase( p->tabFlags & TF_HasStored );
110584 for(ii=0; ii<p->nCol; ii++){
110585 u32 colFlags = p->aCol[ii].colFlags;
110586 if( (colFlags & COLFLAG_GENERATED)!=0 ){
110587 Expr *pX = p->aCol[ii].pDflt;
110588 testcase( colFlags & COLFLAG_VIRTUAL );
110589 testcase( colFlags & COLFLAG_STORED );
110590 if( sqlite3ResolveSelfReference(pParse, p, NC_GenCol, pX, 0) ){
110591 /* If there are errors in resolving the expression, change the
110592 ** expression to a NULL. This prevents code generators that operate
110593 ** on the expression from inserting extra parts into the expression
110594 ** tree that have been allocated from lookaside memory, which is
110595 ** illegal in a schema and will lead to errors heap corruption when
110596 ** the database connection closes. */
110597 sqlite3ExprDelete(db, pX);
110598 p->aCol[ii].pDflt = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
110599 }
110600 }else{
110601 nNG++;
110602 }
110603 }
110604 if( nNG==0 ){
@@ -110532,10 +110824,11 @@
110824 /* Make a copy of the entire SELECT statement that defines the view.
110825 ** This will force all the Expr.token.z values to be dynamically
110826 ** allocated rather than point to the input string - which means that
110827 ** they will persist after the current sqlite3_exec() call returns.
110828 */
110829 pSelect->selFlags |= SF_View;
110830 if( IN_RENAME_OBJECT ){
110831 p->pSelect = pSelect;
110832 pSelect = 0;
110833 }else{
110834 p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
@@ -111958,30 +112251,13 @@
112251 }
112252
112253 sqlite3VdbeJumpHere(v, pIndex->tnum);
112254 }
112255 }
 
 
 
 
 
 
 
112256 if( db->init.busy || pTblName==0 ){
112257 pIndex->pNext = pTab->pIndex;
112258 pTab->pIndex = pIndex;
 
 
 
 
 
 
 
 
 
 
112259 pIndex = 0;
112260 }
112261 else if( IN_RENAME_OBJECT ){
112262 assert( pParse->pNewIndex==0 );
112263 pParse->pNewIndex = pIndex;
@@ -111989,10 +112265,25 @@
112265 }
112266
112267 /* Clean up before exiting */
112268 exit_create_index:
112269 if( pIndex ) sqlite3FreeIndex(db, pIndex);
112270 if( pTab ){ /* Ensure all REPLACE indexes are at the end of the list */
112271 Index **ppFrom = &pTab->pIndex;
112272 Index *pThis;
112273 for(ppFrom=&pTab->pIndex; (pThis = *ppFrom)!=0; ppFrom=&pThis->pNext){
112274 Index *pNext;
112275 if( pThis->onError!=OE_Replace ) continue;
112276 while( (pNext = pThis->pNext)!=0 && pNext->onError!=OE_Replace ){
112277 *ppFrom = pNext;
112278 pThis->pNext = pNext->pNext;
112279 pNext->pNext = pThis;
112280 ppFrom = &pNext->pNext;
112281 }
112282 break;
112283 }
112284 }
112285 sqlite3ExprDelete(db, pPIWhere);
112286 sqlite3ExprListDelete(db, pList);
112287 sqlite3SrcListDelete(db, pTblName);
112288 sqlite3DbFree(db, zName);
112289 }
@@ -118231,14 +118522,15 @@
118522 }
118523 return 0;
118524 }
118525
118526 /* This walker callback will compute the union of colFlags flags for all
118527 ** referenced columns in a CHECK constraint or generated column expression.
118528 */
118529 static int exprColumnFlagUnion(Walker *pWalker, Expr *pExpr){
118530 if( pExpr->op==TK_COLUMN && pExpr->iColumn>=0 ){
118531 assert( pExpr->iColumn < pWalker->u.pTab->nCol );
118532 pWalker->eCode |= pWalker->u.pTab->aCol[pExpr->iColumn].colFlags;
118533 }
118534 return WRC_Continue;
118535 }
118536
@@ -118257,10 +118549,40 @@
118549 ){
118550 int i;
118551 Walker w;
118552 Column *pRedo;
118553 int eProgress;
118554 VdbeOp *pOp;
118555
118556 assert( pTab->tabFlags & TF_HasGenerated );
118557 testcase( pTab->tabFlags & TF_HasVirtual );
118558 testcase( pTab->tabFlags & TF_HasStored );
118559
118560 /* Before computing generated columns, first go through and make sure
118561 ** that appropriate affinity has been applied to the regular columns
118562 */
118563 sqlite3TableAffinity(pParse->pVdbe, pTab, iRegStore);
118564 if( (pTab->tabFlags & TF_HasStored)!=0
118565 && (pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1))->opcode==OP_Affinity
118566 ){
118567 /* Change the OP_Affinity argument to '@' (NONE) for all stored
118568 ** columns. '@' is the no-op affinity and those columns have not
118569 ** yet been computed. */
118570 int ii, jj;
118571 char *zP4 = pOp->p4.z;
118572 assert( zP4!=0 );
118573 assert( pOp->p4type==P4_DYNAMIC );
118574 for(ii=jj=0; zP4[jj]; ii++){
118575 if( pTab->aCol[ii].colFlags & COLFLAG_VIRTUAL ){
118576 continue;
118577 }
118578 if( pTab->aCol[ii].colFlags & COLFLAG_STORED ){
118579 zP4[jj] = SQLITE_AFF_NONE;
118580 }
118581 jj++;
118582 }
118583 }
118584
118585 /* Because there can be multiple generated columns that refer to one another,
118586 ** this is a two-pass algorithm. On the first pass, mark all generated
118587 ** columns as "not available".
118588 */
@@ -118977,10 +119299,14 @@
119299 if( IsVirtual(pTab) ){
119300 sqlite3ErrorMsg(pParse, "UPSERT not implemented for virtual table \"%s\"",
119301 pTab->zName);
119302 goto insert_cleanup;
119303 }
119304 if( pTab->pSelect ){
119305 sqlite3ErrorMsg(pParse, "cannot UPSERT a view");
119306 goto insert_cleanup;
119307 }
119308 if( sqlite3HasExplicitNulls(pParse, pUpsert->pUpsertTarget) ){
119309 goto insert_cleanup;
119310 }
119311 pTabList->a[0].iCursor = iDataCur;
119312 pUpsert->pUpsertSrc = pTabList;
@@ -119211,14 +119537,12 @@
119537
119538 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
119539 /* Compute the new value for generated columns after all other
119540 ** columns have already been computed. This must be done after
119541 ** computing the ROWID in case one of the generated columns
119542 ** is derived from the INTEGER PRIMARY KEY. */
119543 if( pTab->tabFlags & TF_HasGenerated ){
 
 
119544 sqlite3ComputeGeneratedColumns(pParse, regRowid+1, pTab);
119545 }
119546 #endif
119547
119548 /* Generate code to check constraints and generate index keys and
@@ -120246,10 +120570,14 @@
120570
120571 v = sqlite3GetVdbe(pParse);
120572 assert( v!=0 );
120573 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
120574 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
120575 /* All REPLACE indexes are at the end of the list */
120576 assert( pIdx->onError!=OE_Replace
120577 || pIdx->pNext==0
120578 || pIdx->pNext->onError==OE_Replace );
120579 if( aRegIdx[i]==0 ) continue;
120580 if( pIdx->pPartIdxWhere ){
120581 sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
120582 VdbeCoverage(v);
120583 }
@@ -124713,11 +125041,13 @@
125041 char *zErr;
125042 int jmp2;
125043 if( j==pTab->iPKey ) continue;
125044 if( pTab->aCol[j].notNull==0 ) continue;
125045 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3);
125046 if( sqlite3VdbeGetOp(v,-1)->opcode==OP_Column ){
125047 sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
125048 }
125049 jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
125050 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
125051 pTab->aCol[j].zName);
125052 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
125053 integrityCheckResultRow(v);
@@ -126679,11 +127009,14 @@
127009 };
127010 #define SORTFLAG_UseSorter 0x01 /* Use SorterOpen instead of OpenEphemeral */
127011
127012 /*
127013 ** Delete all the content of a Select structure. Deallocate the structure
127014 ** itself depending on the value of bFree
127015 **
127016 ** If bFree==1, call sqlite3DbFree() on the p object.
127017 ** If bFree==0, Leave the first Select object unfreed
127018 */
127019 static void clearSelect(sqlite3 *db, Select *p, int bFree){
127020 while( p ){
127021 Select *pPrior = p->pPrior;
127022 sqlite3ExprListDelete(db, p->pEList);
@@ -126782,10 +127115,24 @@
127115 ** Delete the given Select structure and all of its substructures.
127116 */
127117 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
127118 if( OK_IF_ALWAYS_TRUE(p) ) clearSelect(db, p, 1);
127119 }
127120
127121 /*
127122 ** Delete all the substructure for p, but keep p allocated. Redefine
127123 ** p to be a single SELECT where every column of the result set has a
127124 ** value of NULL.
127125 */
127126 SQLITE_PRIVATE void sqlite3SelectReset(Parse *pParse, Select *p){
127127 if( ALWAYS(p) ){
127128 clearSelect(pParse->db, p, 0);
127129 memset(&p->iLimit, 0, sizeof(Select) - offsetof(Select,iLimit));
127130 p->pEList = sqlite3ExprListAppend(pParse, 0,
127131 sqlite3ExprAlloc(pParse->db,TK_NULL,0,0));
127132 }
127133 }
127134
127135 /*
127136 ** Return a pointer to the right-most SELECT statement in a compound.
127137 */
127138 static Select *findRightmost(Select *p){
@@ -129069,10 +129416,11 @@
129416 assert( p->selFlags & SF_MultiValue );
129417 do{
129418 assert( p->selFlags & SF_Values );
129419 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
129420 assert( p->pNext==0 || p->pEList->nExpr==p->pNext->pEList->nExpr );
129421 if( p->pWin ) return -1;
129422 if( p->pPrior==0 ) break;
129423 assert( p->pPrior->pNext==p );
129424 p = p->pPrior;
129425 nRow += bShowAll;
129426 }while(1);
@@ -129159,11 +129507,12 @@
129507
129508 /* Special handling for a compound-select that originates as a VALUES clause.
129509 */
129510 if( p->selFlags & SF_MultiValue ){
129511 rc = multiSelectValues(pParse, p, &dest);
129512 if( rc>=0 ) goto multi_select_end;
129513 rc = SQLITE_OK;
129514 }
129515
129516 /* Make sure all SELECTs in the statement have the same number of elements
129517 ** in their result sets.
129518 */
@@ -129304,13 +129653,13 @@
129653
129654 /* Convert the data in the temporary table into whatever form
129655 ** it is that we currently need.
129656 */
129657 assert( unionTab==dest.iSDParm || dest.eDest!=priorOp );
129658 assert( p->pEList || db->mallocFailed );
129659 if( dest.eDest!=priorOp && db->mallocFailed==0 ){
129660 int iCont, iBreak, iStart;
 
129661 iBreak = sqlite3VdbeMakeLabel(pParse);
129662 iCont = sqlite3VdbeMakeLabel(pParse);
129663 computeLimitRegisters(pParse, p, iBreak);
129664 sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
129665 iStart = sqlite3VdbeCurrentAddr(v);
@@ -129402,10 +129751,11 @@
129751 if( p->pNext==0 ){
129752 ExplainQueryPlanPop(pParse);
129753 }
129754 #endif
129755 }
129756 if( pParse->nErr ) goto multi_select_end;
129757
129758 /* Compute collating sequences used by
129759 ** temporary tables needed to implement the compound select.
129760 ** Attach the KeyInfo structure to all temporary tables.
129761 **
@@ -130193,10 +130543,11 @@
130543 ** (3) If the subquery is the right operand of a LEFT JOIN then
130544 ** (3a) the subquery may not be a join and
130545 ** (3b) the FROM clause of the subquery may not contain a virtual
130546 ** table and
130547 ** (3c) the outer query may not be an aggregate.
130548 ** (3d) the outer query may not be DISTINCT.
130549 **
130550 ** (4) The subquery can not be DISTINCT.
130551 **
130552 ** (**) At one point restrictions (4) and (5) defined a subset of DISTINCT
130553 ** sub-queries that were excluded from this optimization. Restriction
@@ -130389,12 +130740,15 @@
130740 **
130741 ** See also tickets #306, #350, and #3300.
130742 */
130743 if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
130744 isLeftJoin = 1;
130745 if( pSubSrc->nSrc>1 /* (3a) */
130746 || isAgg /* (3b) */
130747 || IsVirtual(pSubSrc->a[0].pTab) /* (3c) */
130748 || (p->selFlags & SF_Distinct)!=0 /* (3d) */
130749 ){
130750 return 0;
130751 }
130752 }
130753 #ifdef SQLITE_EXTRA_IFNULLROW
130754 else if( iFrom>0 && !isAgg ){
@@ -131164,10 +131518,13 @@
131518 pNew->pHaving = 0;
131519 pNew->pOrderBy = 0;
131520 p->pPrior = 0;
131521 p->pNext = 0;
131522 p->pWith = 0;
131523 #ifndef SQLITE_OMIT_WINDOWFUNC
131524 p->pWinDefn = 0;
131525 #endif
131526 p->selFlags &= ~SF_Compound;
131527 assert( (p->selFlags & SF_Converted)==0 );
131528 p->selFlags |= SF_Converted;
131529 assert( pNew->pPrior!=0 );
131530 pNew->pPrior->pNext = pNew;
@@ -132323,11 +132680,13 @@
132680 if( pDest->eDest==SRT_Output ){
132681 generateColumnNames(pParse, p);
132682 }
132683
132684 #ifndef SQLITE_OMIT_WINDOWFUNC
132685 rc = sqlite3WindowRewrite(pParse, p);
132686 if( rc ){
132687 assert( db->mallocFailed || pParse->nErr>0 );
132688 goto select_end;
132689 }
132690 #if SELECTTRACE_ENABLED
132691 if( p->pWin && (sqlite3SelectTrace & 0x108)!=0 ){
132692 SELECTTRACE(0x104,pParse,p, ("after window rewrite:\n"));
@@ -132659,10 +133018,11 @@
133018 ** written the query must use a temp-table for at least one of the ORDER
133019 ** BY and DISTINCT, and an index or separate temp-table for the other.
133020 */
133021 if( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct
133022 && sqlite3ExprListCompare(sSort.pOrderBy, pEList, -1)==0
133023 && p->pWin==0
133024 ){
133025 p->selFlags &= ~SF_Distinct;
133026 pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
133027 /* Notice that even thought SF_Distinct has been cleared from p->selFlags,
133028 ** the sDistinct.isTnct is still set. Hence, isTnct represents the
@@ -134182,12 +134542,16 @@
134542 if( ALWAYS(pTrigger) ){
134543 if( pTrigger->pSchema==pTrigger->pTabSchema ){
134544 Table *pTab = tableOfTrigger(pTrigger);
134545 if( pTab ){
134546 Trigger **pp;
134547 for(pp=&pTab->pTrigger; *pp; pp=&((*pp)->pNext)){
134548 if( *pp==pTrigger ){
134549 *pp = (*pp)->pNext;
134550 break;
134551 }
134552 }
134553 }
134554 }
134555 sqlite3DeleteTrigger(db, pTrigger);
134556 db->mDbFlags |= DBFLAG_SchemaChange;
134557 }
@@ -136913,10 +137277,12 @@
137277 char *zStmt;
137278 char *zWhere;
137279 int iDb;
137280 int iReg;
137281 Vdbe *v;
137282
137283 sqlite3MayAbort(pParse);
137284
137285 /* Compute the complete text of the CREATE VIRTUAL TABLE statement */
137286 if( pEnd ){
137287 pParse->sNameToken.n = (int)(pEnd->z - pParse->sNameToken.z) + pEnd->n;
137288 }
@@ -136939,17 +137305,17 @@
137305 pTab->zName,
137306 pTab->zName,
137307 zStmt,
137308 pParse->regRowid
137309 );
 
137310 v = sqlite3GetVdbe(pParse);
137311 sqlite3ChangeCookie(pParse, iDb);
137312
137313 sqlite3VdbeAddOp0(v, OP_Expire);
137314 zWhere = sqlite3MPrintf(db, "name=%Q AND sql=%Q", pTab->zName, zStmt);
137315 sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere);
137316 sqlite3DbFree(db, zStmt);
137317
137318 iReg = ++pParse->nMem;
137319 sqlite3VdbeLoadString(v, iReg, pTab->zName);
137320 sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg);
137321 }
@@ -137347,11 +137713,12 @@
137713 return SQLITE_LOCKED;
137714 }
137715 }
137716 p = vtabDisconnectAll(db, pTab);
137717 xDestroy = p->pMod->pModule->xDestroy;
137718 if( xDestroy==0 ) xDestroy = p->pMod->pModule->xDisconnect;
137719 assert( xDestroy!=0 );
137720 pTab->nTabRef++;
137721 rc = xDestroy(p->pVtab);
137722 /* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */
137723 if( rc==SQLITE_OK ){
137724 assert( pTab->pVTable==p && p->pNext==0 );
@@ -138776,11 +139143,12 @@
139143 int iEq, /* Look at loop terms starting here */
139144 WhereLoop *pLoop, /* The current loop */
139145 Expr *pX /* The IN expression to be reduced */
139146 ){
139147 sqlite3 *db = pParse->db;
139148 Expr *pNew;
139149 pNew = sqlite3ExprDup(db, pX, 0);
139150 if( db->mallocFailed==0 ){
139151 ExprList *pOrigRhs = pNew->x.pSelect->pEList; /* Original unmodified RHS */
139152 ExprList *pOrigLhs = pNew->pLeft->x.pList; /* Original unmodified LHS */
139153 ExprList *pRhs = 0; /* New RHS after modifications */
139154 ExprList *pLhs = 0; /* New LHS after mods */
@@ -139488,10 +139856,13 @@
139856 pExpr->affExpr = sqlite3ExprAffinity(pExpr);
139857 pExpr->op = TK_COLUMN;
139858 pExpr->iTable = pX->iIdxCur;
139859 pExpr->iColumn = pX->iIdxCol;
139860 pExpr->y.pTab = 0;
139861 testcase( ExprHasProperty(pExpr, EP_Skip) );
139862 testcase( ExprHasProperty(pExpr, EP_Unlikely) );
139863 ExprClearProperty(pExpr, EP_Skip|EP_Unlikely);
139864 return WRC_Prune;
139865 }else{
139866 return WRC_Continue;
139867 }
139868 }
@@ -139502,10 +139873,12 @@
139873 */
139874 static int whereIndexExprTransColumn(Walker *p, Expr *pExpr){
139875 if( pExpr->op==TK_COLUMN ){
139876 IdxExprTrans *pX = p->u.pIdxTrans;
139877 if( pExpr->iTable==pX->iTabCur && pExpr->iColumn==pX->iTabCol ){
139878 assert( pExpr->y.pTab!=0 );
139879 pExpr->affExpr = sqlite3TableColumnAffinity(pExpr->y.pTab,pExpr->iColumn);
139880 pExpr->iTable = pX->iIdxCur;
139881 pExpr->iColumn = pX->iIdxCol;
139882 pExpr->y.pTab = 0;
139883 }
139884 }
@@ -139547,13 +139920,24 @@
139920 for(iIdxCol=0; iIdxCol<pIdx->nColumn; iIdxCol++){
139921 i16 iRef = pIdx->aiColumn[iIdxCol];
139922 if( iRef==XN_EXPR ){
139923 assert( aColExpr->a[iIdxCol].pExpr!=0 );
139924 x.pIdxExpr = aColExpr->a[iIdxCol].pExpr;
139925 if( sqlite3ExprIsConstant(x.pIdxExpr) ) continue;
139926 w.xExprCallback = whereIndexExprTransNode;
139927 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
139928 }else if( iRef>=0
139929 && (pTab->aCol[iRef].colFlags & COLFLAG_VIRTUAL)!=0
139930 && (pTab->aCol[iRef].zColl==0
139931 || sqlite3StrICmp(pTab->aCol[iRef].zColl, sqlite3StrBINARY)==0)
139932 ){
139933 /* Check to see if there are direct references to generated columns
139934 ** that are contained in the index. Pulling the generated column
139935 ** out of the index is an optimization only - the main table is always
139936 ** available if the index cannot be used. To avoid unnecessary
139937 ** complication, omit this optimization if the collating sequence for
139938 ** the column is non-standard */
139939 x.iTabCol = iRef;
139940 w.xExprCallback = whereIndexExprTransColumn;
139941 #endif /* SQLITE_OMIT_GENERATED_COLUMNS */
139942 }else{
139943 continue;
@@ -140213,14 +140597,14 @@
140597 omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
140598 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0;
140599 if( omitTable ){
140600 /* pIdx is a covering index. No need to access the main table. */
140601 }else if( HasRowid(pIdx->pTable) ){
140602 if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE)
140603 || ( (pWInfo->wctrlFlags & WHERE_SEEK_UNIQ_TABLE)!=0
140604 && (pWInfo->eOnePass==ONEPASS_SINGLE || pLoop->nLTerm==0) )
140605 ){
140606 iRowidReg = ++pParse->nMem;
140607 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
140608 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg);
140609 VdbeCoverage(v);
140610 }else{
@@ -142055,10 +142439,11 @@
142439 Expr *pNewExpr;
142440 pNewExpr = sqlite3PExpr(pParse, TK_MATCH,
142441 0, sqlite3ExprDup(db, pRight, 0));
142442 if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){
142443 ExprSetProperty(pNewExpr, EP_FromJoin);
142444 pNewExpr->iRightJoinTable = pExpr->iRightJoinTable;
142445 }
142446 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
142447 testcase( idxNew==0 );
142448 pNewTerm = &pWC->a[idxNew];
142449 pNewTerm->prereqRight = prereqExpr;
@@ -142111,15 +142496,19 @@
142496 ** a virtual term for each vector component. The expression object
142497 ** used by each such virtual term is pExpr (the full vector IN(...)
142498 ** expression). The WhereTerm.iField variable identifies the index within
142499 ** the vector on the LHS that the virtual term represents.
142500 **
142501 ** This only works if the RHS is a simple SELECT (not a compound) that does
142502 ** not use window functions.
142503 */
142504 if( pWC->op==TK_AND && pExpr->op==TK_IN && pTerm->iField==0
142505 && pExpr->pLeft->op==TK_VECTOR
142506 && pExpr->x.pSelect->pPrior==0
142507 #ifndef SQLITE_OMIT_WINDOWFUNC
142508 && pExpr->x.pSelect->pWin==0
142509 #endif
142510 ){
142511 int i;
142512 for(i=0; i<sqlite3ExprVectorSize(pExpr->pLeft); i++){
142513 int idxNew;
142514 idxNew = whereClauseInsert(pWC, pExpr, TERM_VIRTUAL);
@@ -142273,13 +142662,14 @@
142662 mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
142663 }else if( p->x.pList ){
142664 mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
142665 }
142666 #ifndef SQLITE_OMIT_WINDOWFUNC
142667 if( (p->op==TK_FUNCTION || p->op==TK_AGG_FUNCTION) && p->y.pWin ){
142668 mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition);
142669 mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy);
142670 mask |= sqlite3WhereExprUsage(pMaskSet, p->y.pWin->pFilter);
142671 }
142672 #endif
142673 return mask;
142674 }
142675 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
@@ -143163,11 +143553,12 @@
143553 if( (idxCols & cMask)==0 ){
143554 Expr *pX = pTerm->pExpr;
143555 idxCols |= cMask;
143556 pIdx->aiColumn[n] = pTerm->u.leftColumn;
143557 pColl = sqlite3ExprCompareCollSeq(pParse, pX);
143558 assert( pColl!=0 || pParse->nErr>0 ); /* TH3 collate01.800 */
143559 pIdx->azColl[n] = pColl ? pColl->zName : sqlite3StrBINARY;
143560 n++;
143561 }
143562 }
143563 }
143564 assert( (u32)n==pLoop->u.btree.nEq );
@@ -143341,22 +143732,17 @@
143732 testcase( pTerm->eOperator & WO_IS );
143733 testcase( pTerm->eOperator & WO_ISNULL );
143734 testcase( pTerm->eOperator & WO_ALL );
143735 if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
143736 if( pTerm->wtFlags & TERM_VNULL ) continue;
143737
143738 /* tag-20191211-002: WHERE-clause constraints are not useful to the
143739 ** right-hand table of a LEFT JOIN. See tag-20191211-001 for the
143740 ** equivalent restriction for ordinary tables. */
143741 if( (pSrc->fg.jointype & JT_LEFT)!=0
143742 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
 
143743 ){
 
 
 
 
 
 
 
 
143744 continue;
143745 }
143746 assert( pTerm->u.leftColumn>=(-1) );
143747 pIdxCons[j].iColumn = pTerm->u.leftColumn;
143748 pIdxCons[j].iTermOffset = i;
@@ -143383,11 +143769,12 @@
143769 assert( pTerm->eOperator&(WO_IN|WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_AUX) );
143770
143771 if( op & (WO_LT|WO_LE|WO_GT|WO_GE)
143772 && sqlite3ExprIsVector(pTerm->pExpr->pRight)
143773 ){
143774 testcase( j!=i );
143775 if( j<16 ) mNoOmit |= (1 << j);
143776 if( op==WO_LT ) pIdxCons[j].op = WO_LE;
143777 if( op==WO_GT ) pIdxCons[j].op = WO_GE;
143778 }
143779 }
143780
@@ -144128,14 +144515,16 @@
144515 sqlite3DebugPrintf(
144516 "TERM-%-3d %p %s %-12s prob=%-3d op=0x%03x wtFlags=0x%04x",
144517 iTerm, pTerm, zType, zLeft, pTerm->truthProb,
144518 pTerm->eOperator, pTerm->wtFlags);
144519 if( pTerm->iField ){
144520 sqlite3DebugPrintf(" iField=%d", pTerm->iField);
 
 
144521 }
144522 if( pTerm->iParent>=0 ){
144523 sqlite3DebugPrintf(" iParent=%d", pTerm->iParent);
144524 }
144525 sqlite3DebugPrintf("\n");
144526 sqlite3TreeViewExpr(0, pTerm->pExpr, 0);
144527 }
144528 }
144529 #endif
144530
@@ -144178,11 +144567,11 @@
144567 sqlite3DebugPrintf("%20s","");
144568 }
144569 }else{
144570 char *z;
144571 if( p->u.vtab.idxStr ){
144572 z = sqlite3_mprintf("(%d,\"%s\",%#x)",
144573 p->u.vtab.idxNum, p->u.vtab.idxStr, p->u.vtab.omitMask);
144574 }else{
144575 z = sqlite3_mprintf("(%d,%x)", p->u.vtab.idxNum, p->u.vtab.omitMask);
144576 }
144577 sqlite3DebugPrintf(" %-19s", z);
@@ -144833,13 +145222,13 @@
145222
145223 /* Do not allow the upper bound of a LIKE optimization range constraint
145224 ** to mix with a lower range bound from some other source */
145225 if( pTerm->wtFlags & TERM_LIKEOPT && pTerm->eOperator==WO_LT ) continue;
145226
145227 /* tag-20191211-001: Do not allow constraints from the WHERE clause to
145228 ** be used by the right table of a LEFT JOIN. Only constraints in the
145229 ** ON clause are allowed. See tag-20191211-002 for the vtab equivalent. */
145230 if( (pSrc->fg.jointype & JT_LEFT)!=0
145231 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
145232 ){
145233 continue;
145234 }
@@ -145152,23 +145541,29 @@
145541 }
145542
145543 /* Check to see if a partial index with pPartIndexWhere can be used
145544 ** in the current query. Return true if it can be and false if not.
145545 */
145546 static int whereUsablePartialIndex(
145547 int iTab, /* The table for which we want an index */
145548 int isLeft, /* True if iTab is the right table of a LEFT JOIN */
145549 WhereClause *pWC, /* The WHERE clause of the query */
145550 Expr *pWhere /* The WHERE clause from the partial index */
145551 ){
145552 int i;
145553 WhereTerm *pTerm;
145554 Parse *pParse = pWC->pWInfo->pParse;
145555 while( pWhere->op==TK_AND ){
145556 if( !whereUsablePartialIndex(iTab,isLeft,pWC,pWhere->pLeft) ) return 0;
145557 pWhere = pWhere->pRight;
145558 }
145559 if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0;
145560 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
145561 Expr *pExpr;
145562 pExpr = pTerm->pExpr;
145563 if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab)
145564 && (isLeft==0 || ExprHasProperty(pExpr, EP_FromJoin))
145565 && sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)
145566 ){
145567 return 1;
145568 }
145569 }
@@ -145327,12 +145722,15 @@
145722 /* Loop over all indices. If there was an INDEXED BY clause, then only
145723 ** consider index pProbe. */
145724 for(; rc==SQLITE_OK && pProbe;
145725 pProbe=(pSrc->pIBIndex ? 0 : pProbe->pNext), iSortIdx++
145726 ){
145727 int isLeft = (pSrc->fg.jointype & JT_OUTER)!=0;
145728 if( pProbe->pPartIdxWhere!=0
145729 && !whereUsablePartialIndex(pSrc->iCursor, isLeft, pWC,
145730 pProbe->pPartIdxWhere)
145731 ){
145732 testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */
145733 continue; /* Partial index inappropriate for this query */
145734 }
145735 if( pProbe->bNoQuery ) continue;
145736 rSize = pProbe->aiRowLogEst[0];
@@ -145555,11 +145953,18 @@
145953 assert( iTerm<pNew->nLSlot );
145954 pNew->aLTerm[iTerm] = pTerm;
145955 if( iTerm>mxTerm ) mxTerm = iTerm;
145956 testcase( iTerm==15 );
145957 testcase( iTerm==16 );
145958 if( pUsage[i].omit ){
145959 if( i<16 && ((1<<i)&mNoOmit)==0 ){
145960 testcase( i!=iTerm );
145961 pNew->u.vtab.omitMask |= 1<<iTerm;
145962 }else{
145963 testcase( i!=iTerm );
145964 }
145965 }
145966 if( (pTerm->eOperator & WO_IN)!=0 ){
145967 /* A virtual table that is constrained by an IN clause may not
145968 ** consume the ORDER BY clause because (1) the order of IN terms
145969 ** is not necessarily related to the order of output terms and
145970 ** (2) Multiple outputs from a single IN value will not merge
@@ -145568,11 +145973,10 @@
145973 pIdxInfo->idxFlags &= ~SQLITE_INDEX_SCAN_UNIQUE;
145974 *pbIn = 1; assert( (mExclude & WO_IN)==0 );
145975 }
145976 }
145977 }
 
145978
145979 pNew->nLTerm = mxTerm+1;
145980 for(i=0; i<=mxTerm; i++){
145981 if( pNew->aLTerm[i]==0 ){
145982 /* The non-zero argvIdx values must be contiguous. Raise an
@@ -147163,10 +147567,11 @@
147567 sSelect.pEList = pResultSet;
147568 sqlite3TreeViewSelect(0, &sSelect, 0);
147569 }
147570 }
147571 if( sqlite3WhereTrace & 0x100 ){ /* Display all terms of the WHERE clause */
147572 sqlite3DebugPrintf("---- WHERE clause at start of analysis:\n");
147573 sqlite3WhereClausePrint(sWLB.pWC);
147574 }
147575 #endif
147576
147577 if( nTabList!=1 || whereShortCut(&sWLB)==0 ){
@@ -147301,11 +147706,17 @@
147706 }
147707 pWInfo->nLevel--;
147708 nTabList--;
147709 }
147710 }
147711 #if defined(WHERETRACE_ENABLED)
147712 if( sqlite3WhereTrace & 0x100 ){ /* Display all terms of the WHERE clause */
147713 sqlite3DebugPrintf("---- WHERE clause at end of analysis:\n");
147714 sqlite3WhereClausePrint(sWLB.pWC);
147715 }
147716 WHERETRACE(0xffff,("*** Optimizer Finished ***\n"));
147717 #endif
147718 pWInfo->pParse->nQueryLoop += pWInfo->nRowOut;
147719
147720 /* If the caller is an UPDATE or DELETE statement that is requesting
147721 ** to use a one-pass algorithm, determine if this is appropriate.
147722 **
@@ -148571,25 +148982,37 @@
148982 }
148983 /* Fall through. */
148984
148985 case TK_AGG_FUNCTION:
148986 case TK_COLUMN: {
148987 int iCol = -1;
148988 if( p->pSub ){
148989 int i;
148990 for(i=0; i<p->pSub->nExpr; i++){
148991 if( 0==sqlite3ExprCompare(0, p->pSub->a[i].pExpr, pExpr, -1) ){
148992 iCol = i;
148993 break;
148994 }
148995 }
148996 }
148997 if( iCol<0 ){
148998 Expr *pDup = sqlite3ExprDup(pParse->db, pExpr, 0);
148999 p->pSub = sqlite3ExprListAppend(pParse, p->pSub, pDup);
149000 }
149001 if( p->pSub ){
149002 assert( ExprHasProperty(pExpr, EP_Static)==0 );
149003 ExprSetProperty(pExpr, EP_Static);
149004 sqlite3ExprDelete(pParse->db, pExpr);
149005 ExprClearProperty(pExpr, EP_Static);
149006 memset(pExpr, 0, sizeof(Expr));
149007
149008 pExpr->op = TK_COLUMN;
149009 pExpr->iColumn = (iCol<0 ? p->pSub->nExpr-1: iCol);
149010 pExpr->iTable = p->pWin->iEphCsr;
149011 pExpr->y.pTab = p->pTab;
149012 }
149013 if( pParse->db->mallocFailed ) return WRC_Abort;
149014 break;
149015 }
149016
149017 default: /* no-op */
149018 break;
@@ -148667,13 +149090,15 @@
149090 if( pAppend ){
149091 int i;
149092 int nInit = pList ? pList->nExpr : 0;
149093 for(i=0; i<pAppend->nExpr; i++){
149094 Expr *pDup = sqlite3ExprDup(pParse->db, pAppend->a[i].pExpr, 0);
149095 assert( pDup==0 || !ExprHasProperty(pDup, EP_MemToken) );
149096 if( bIntToNull && pDup && pDup->op==TK_INTEGER ){
149097 pDup->op = TK_NULL;
149098 pDup->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
149099 pDup->u.zToken = 0;
149100 }
149101 pList = sqlite3ExprListAppend(pParse, pList, pDup);
149102 if( pList ) pList->a[nInit+i].sortFlags = pAppend->a[i].sortFlags;
149103 }
149104 }
@@ -148704,11 +149129,11 @@
149129 Window *pWin; /* Window object iterator */
149130 Table *pTab;
149131
149132 pTab = sqlite3DbMallocZero(db, sizeof(Table));
149133 if( pTab==0 ){
149134 return sqlite3ErrorToParser(db, SQLITE_NOMEM);
149135 }
149136
149137 p->pSrc = 0;
149138 p->pWhere = 0;
149139 p->pGroupBy = 0;
@@ -148791,10 +149216,13 @@
149216 p->pSrc->a[0].pSelect = pSub;
149217 sqlite3SrcListAssignCursors(pParse, p->pSrc);
149218 pSub->selFlags |= SF_Expanded;
149219 pTab2 = sqlite3ResultSetOfSelect(pParse, pSub, SQLITE_AFF_NONE);
149220 if( pTab2==0 ){
149221 /* Might actually be some other kind of error, but in that case
149222 ** pParse->nErr will be set, so if SQLITE_NOMEM is set, we will get
149223 ** the correct error message regardless. */
149224 rc = SQLITE_NOMEM;
149225 }else{
149226 memcpy(pTab, pTab2, sizeof(Table));
149227 pTab->tabFlags |= TF_Ephemeral;
149228 p->pSrc->a[0].pTab = pTab;
@@ -148809,10 +149237,17 @@
149237 }
149238 if( db->mallocFailed ) rc = SQLITE_NOMEM;
149239 sqlite3DbFree(db, pTab);
149240 }
149241
149242 if( rc ){
149243 if( pParse->nErr==0 ){
149244 assert( pParse->db->mallocFailed );
149245 sqlite3ErrorToParser(pParse->db, SQLITE_NOMEM);
149246 }
149247 sqlite3SelectReset(pParse, p);
149248 }
149249 return rc;
149250 }
149251
149252 /*
149253 ** Unlink the Window object from the Select to which it is attached,
@@ -149045,10 +149480,11 @@
149480 /*
149481 ** Return 0 if the two window objects are identical, or non-zero otherwise.
149482 ** Identical window objects can be processed in a single scan.
149483 */
149484 SQLITE_PRIVATE int sqlite3WindowCompare(Parse *pParse, Window *p1, Window *p2, int bFilter){
149485 if( NEVER(p1==0) || NEVER(p2==0) ) return 1;
149486 if( p1->eFrmType!=p2->eFrmType ) return 1;
149487 if( p1->eStart!=p2->eStart ) return 1;
149488 if( p1->eEnd!=p2->eEnd ) return 1;
149489 if( p1->eExclude!=p2->eExclude ) return 1;
149490 if( sqlite3ExprCompare(pParse, p1->pStart, p2->pStart, -1) ) return 1;
@@ -151033,21 +151469,22 @@
151469 #define sqlite3ParserCTX_PDECL ,Parse *pParse
151470 #define sqlite3ParserCTX_PARAM ,pParse
151471 #define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse;
151472 #define sqlite3ParserCTX_STORE yypParser->pParse=pParse;
151473 #define YYFALLBACK 1
151474 #define YYNSTATE 551
151475 #define YYNRULE 385
151476 #define YYNRULE_WITH_ACTION 325
151477 #define YYNTOKEN 181
151478 #define YY_MAX_SHIFT 550
151479 #define YY_MIN_SHIFTREDUCE 801
151480 #define YY_MAX_SHIFTREDUCE 1185
151481 #define YY_ERROR_ACTION 1186
151482 #define YY_ACCEPT_ACTION 1187
151483 #define YY_NO_ACTION 1188
151484 #define YY_MIN_REDUCE 1189
151485 #define YY_MAX_REDUCE 1573
151486 /************* End control #defines *******************************************/
151487 #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
151488
151489 /* Define the yytestcase() macro to be a no-op if is not already defined
151490 ** otherwise.
@@ -151112,206 +151549,206 @@
151549 ** yy_default[] Default action for each state.
151550 **
151551 *********** Begin parsing tables **********************************************/
151552 #define YY_ACTTAB_COUNT (1958)
151553 static const YYACTIONTYPE yy_action[] = {
151554 /* 0 */ 544, 1220, 544, 449, 1258, 544, 1237, 544, 114, 111,
151555 /* 10 */ 211, 544, 1535, 544, 1258, 521, 114, 111, 211, 390,
151556 /* 20 */ 1230, 342, 42, 42, 42, 42, 1223, 42, 42, 71,
151557 /* 30 */ 71, 935, 1222, 71, 71, 71, 71, 1460, 1491, 936,
151558 /* 40 */ 818, 451, 6, 121, 122, 112, 1163, 1163, 1004, 1007,
151559 /* 50 */ 997, 997, 119, 119, 120, 120, 120, 120, 1541, 390,
151560 /* 60 */ 1356, 1515, 550, 2, 1191, 194, 526, 434, 143, 291,
151561 /* 70 */ 526, 136, 526, 369, 261, 502, 272, 383, 1271, 525,
151562 /* 80 */ 501, 491, 164, 121, 122, 112, 1163, 1163, 1004, 1007,
151563 /* 90 */ 997, 997, 119, 119, 120, 120, 120, 120, 1356, 440,
151564 /* 100 */ 1512, 118, 118, 118, 118, 117, 117, 116, 116, 116,
151565 /* 110 */ 115, 422, 266, 266, 266, 266, 1496, 356, 1498, 433,
151566 /* 120 */ 355, 1496, 515, 522, 1483, 541, 1112, 541, 1112, 390,
151567 /* 130 */ 403, 241, 208, 114, 111, 211, 98, 290, 535, 221,
151568 /* 140 */ 1027, 118, 118, 118, 118, 117, 117, 116, 116, 116,
151569 /* 150 */ 115, 422, 1140, 121, 122, 112, 1163, 1163, 1004, 1007,
151570 /* 160 */ 997, 997, 119, 119, 120, 120, 120, 120, 404, 426,
151571 /* 170 */ 117, 117, 116, 116, 116, 115, 422, 1416, 466, 123,
151572 /* 180 */ 118, 118, 118, 118, 117, 117, 116, 116, 116, 115,
151573 /* 190 */ 422, 116, 116, 116, 115, 422, 538, 538, 538, 390,
151574 /* 200 */ 503, 120, 120, 120, 120, 113, 1049, 1140, 1141, 1142,
151575 /* 210 */ 1049, 118, 118, 118, 118, 117, 117, 116, 116, 116,
151576 /* 220 */ 115, 422, 1459, 121, 122, 112, 1163, 1163, 1004, 1007,
151577 /* 230 */ 997, 997, 119, 119, 120, 120, 120, 120, 390, 442,
151578 /* 240 */ 314, 83, 461, 81, 357, 380, 1140, 80, 118, 118,
151579 /* 250 */ 118, 118, 117, 117, 116, 116, 116, 115, 422, 179,
151580 /* 260 */ 432, 422, 121, 122, 112, 1163, 1163, 1004, 1007, 997,
151581 /* 270 */ 997, 119, 119, 120, 120, 120, 120, 432, 431, 266,
151582 /* 280 */ 266, 118, 118, 118, 118, 117, 117, 116, 116, 116,
151583 /* 290 */ 115, 422, 541, 1107, 901, 504, 1140, 114, 111, 211,
151584 /* 300 */ 1429, 1140, 1141, 1142, 206, 489, 1107, 390, 447, 1107,
151585 /* 310 */ 543, 328, 120, 120, 120, 120, 298, 1429, 1431, 17,
151586 /* 320 */ 118, 118, 118, 118, 117, 117, 116, 116, 116, 115,
151587 /* 330 */ 422, 121, 122, 112, 1163, 1163, 1004, 1007, 997, 997,
151588 /* 340 */ 119, 119, 120, 120, 120, 120, 390, 1356, 432, 1140,
151589 /* 350 */ 480, 1140, 1141, 1142, 994, 994, 1005, 1008, 443, 118,
151590 /* 360 */ 118, 118, 118, 117, 117, 116, 116, 116, 115, 422,
151591 /* 370 */ 121, 122, 112, 1163, 1163, 1004, 1007, 997, 997, 119,
151592 /* 380 */ 119, 120, 120, 120, 120, 1052, 1052, 463, 1429, 118,
151593 /* 390 */ 118, 118, 118, 117, 117, 116, 116, 116, 115, 422,
151594 /* 400 */ 1140, 449, 544, 1424, 1140, 1141, 1142, 233, 964, 1140,
151595 /* 410 */ 479, 476, 475, 171, 358, 390, 164, 405, 412, 840,
151596 /* 420 */ 474, 164, 185, 332, 71, 71, 1241, 998, 118, 118,
151597 /* 430 */ 118, 118, 117, 117, 116, 116, 116, 115, 422, 121,
151598 /* 440 */ 122, 112, 1163, 1163, 1004, 1007, 997, 997, 119, 119,
151599 /* 450 */ 120, 120, 120, 120, 390, 1140, 1141, 1142, 833, 12,
151600 /* 460 */ 313, 507, 163, 354, 1140, 1141, 1142, 114, 111, 211,
151601 /* 470 */ 506, 290, 535, 544, 276, 180, 290, 535, 121, 122,
151602 /* 480 */ 112, 1163, 1163, 1004, 1007, 997, 997, 119, 119, 120,
151603 /* 490 */ 120, 120, 120, 343, 482, 71, 71, 118, 118, 118,
151604 /* 500 */ 118, 117, 117, 116, 116, 116, 115, 422, 1140, 209,
151605 /* 510 */ 409, 521, 1140, 1107, 1569, 376, 252, 269, 340, 485,
151606 /* 520 */ 335, 484, 238, 390, 511, 362, 1107, 1125, 331, 1107,
151607 /* 530 */ 191, 407, 286, 32, 455, 441, 118, 118, 118, 118,
151608 /* 540 */ 117, 117, 116, 116, 116, 115, 422, 121, 122, 112,
151609 /* 550 */ 1163, 1163, 1004, 1007, 997, 997, 119, 119, 120, 120,
151610 /* 560 */ 120, 120, 390, 1140, 1141, 1142, 985, 1140, 1141, 1142,
151611 /* 570 */ 1140, 233, 490, 1490, 479, 476, 475, 6, 163, 544,
151612 /* 580 */ 510, 544, 115, 422, 474, 5, 121, 122, 112, 1163,
151613 /* 590 */ 1163, 1004, 1007, 997, 997, 119, 119, 120, 120, 120,
151614 /* 600 */ 120, 13, 13, 13, 13, 118, 118, 118, 118, 117,
151615 /* 610 */ 117, 116, 116, 116, 115, 422, 401, 500, 406, 544,
151616 /* 620 */ 1484, 542, 1140, 890, 890, 1140, 1141, 1142, 1471, 1140,
151617 /* 630 */ 275, 390, 806, 807, 808, 969, 420, 420, 420, 16,
151618 /* 640 */ 16, 55, 55, 1240, 118, 118, 118, 118, 117, 117,
151619 /* 650 */ 116, 116, 116, 115, 422, 121, 122, 112, 1163, 1163,
151620 /* 660 */ 1004, 1007, 997, 997, 119, 119, 120, 120, 120, 120,
151621 /* 670 */ 390, 1187, 1, 1, 550, 2, 1191, 1140, 1141, 1142,
151622 /* 680 */ 194, 291, 896, 136, 1140, 1141, 1142, 895, 519, 1490,
151623 /* 690 */ 1271, 3, 378, 6, 121, 122, 112, 1163, 1163, 1004,
151624 /* 700 */ 1007, 997, 997, 119, 119, 120, 120, 120, 120, 856,
151625 /* 710 */ 544, 922, 544, 118, 118, 118, 118, 117, 117, 116,
151626 /* 720 */ 116, 116, 115, 422, 266, 266, 1090, 1567, 1140, 549,
151627 /* 730 */ 1567, 1191, 13, 13, 13, 13, 291, 541, 136, 390,
151628 /* 740 */ 483, 419, 418, 964, 342, 1271, 466, 408, 857, 279,
151629 /* 750 */ 140, 221, 118, 118, 118, 118, 117, 117, 116, 116,
151630 /* 760 */ 116, 115, 422, 121, 122, 112, 1163, 1163, 1004, 1007,
151631 /* 770 */ 997, 997, 119, 119, 120, 120, 120, 120, 544, 266,
151632 /* 780 */ 266, 426, 390, 1140, 1141, 1142, 1170, 828, 1170, 466,
151633 /* 790 */ 429, 145, 541, 1144, 399, 313, 437, 301, 836, 1488,
151634 /* 800 */ 71, 71, 410, 6, 1088, 471, 221, 100, 112, 1163,
151635 /* 810 */ 1163, 1004, 1007, 997, 997, 119, 119, 120, 120, 120,
151636 /* 820 */ 120, 118, 118, 118, 118, 117, 117, 116, 116, 116,
151637 /* 830 */ 115, 422, 237, 1423, 544, 449, 426, 287, 984, 544,
151638 /* 840 */ 236, 235, 234, 828, 97, 527, 427, 1263, 1263, 1144,
151639 /* 850 */ 492, 306, 428, 836, 975, 544, 71, 71, 974, 1239,
151640 /* 860 */ 544, 51, 51, 300, 118, 118, 118, 118, 117, 117,
151641 /* 870 */ 116, 116, 116, 115, 422, 194, 103, 70, 70, 266,
151642 /* 880 */ 266, 544, 71, 71, 266, 266, 30, 389, 342, 974,
151643 /* 890 */ 974, 976, 541, 526, 1107, 326, 390, 541, 493, 395,
151644 /* 900 */ 1468, 195, 528, 13, 13, 1356, 240, 1107, 277, 280,
151645 /* 910 */ 1107, 280, 303, 455, 305, 331, 390, 31, 188, 417,
151646 /* 920 */ 121, 122, 112, 1163, 1163, 1004, 1007, 997, 997, 119,
151647 /* 930 */ 119, 120, 120, 120, 120, 142, 390, 363, 455, 984,
151648 /* 940 */ 121, 122, 112, 1163, 1163, 1004, 1007, 997, 997, 119,
151649 /* 950 */ 119, 120, 120, 120, 120, 975, 321, 1140, 324, 974,
151650 /* 960 */ 121, 110, 112, 1163, 1163, 1004, 1007, 997, 997, 119,
151651 /* 970 */ 119, 120, 120, 120, 120, 462, 375, 1183, 118, 118,
151652 /* 980 */ 118, 118, 117, 117, 116, 116, 116, 115, 422, 1140,
151653 /* 990 */ 974, 974, 976, 304, 9, 364, 244, 360, 118, 118,
151654 /* 1000 */ 118, 118, 117, 117, 116, 116, 116, 115, 422, 312,
151655 /* 1010 */ 544, 342, 1140, 1141, 1142, 299, 290, 535, 118, 118,
151656 /* 1020 */ 118, 118, 117, 117, 116, 116, 116, 115, 422, 1261,
151657 /* 1030 */ 1261, 1161, 13, 13, 278, 419, 418, 466, 390, 921,
151658 /* 1040 */ 260, 260, 289, 1167, 1140, 1141, 1142, 189, 1169, 266,
151659 /* 1050 */ 266, 466, 388, 541, 1184, 544, 1168, 263, 144, 487,
151660 /* 1060 */ 920, 544, 541, 122, 112, 1163, 1163, 1004, 1007, 997,
151661 /* 1070 */ 997, 119, 119, 120, 120, 120, 120, 71, 71, 1140,
151662 /* 1080 */ 1170, 1270, 1170, 13, 13, 896, 1068, 1161, 544, 466,
151663 /* 1090 */ 895, 107, 536, 1489, 4, 1266, 1107, 6, 523, 1047,
151664 /* 1100 */ 12, 1069, 1090, 1568, 311, 453, 1568, 518, 539, 1107,
151665 /* 1110 */ 56, 56, 1107, 1487, 421, 1356, 1070, 6, 343, 285,
151666 /* 1120 */ 118, 118, 118, 118, 117, 117, 116, 116, 116, 115,
151667 /* 1130 */ 422, 423, 1269, 319, 1140, 1141, 1142, 876, 266, 266,
151668 /* 1140 */ 1275, 107, 536, 533, 4, 1486, 293, 877, 1209, 6,
151669 /* 1150 */ 210, 541, 541, 164, 1540, 494, 414, 865, 539, 267,
151670 /* 1160 */ 267, 1212, 396, 509, 497, 204, 266, 266, 394, 529,
151671 /* 1170 */ 8, 984, 541, 517, 544, 920, 456, 105, 105, 541,
151672 /* 1180 */ 1088, 423, 266, 266, 106, 415, 423, 546, 545, 266,
151673 /* 1190 */ 266, 974, 516, 533, 1371, 541, 15, 15, 266, 266,
151674 /* 1200 */ 454, 1118, 541, 266, 266, 1068, 1370, 513, 290, 535,
151675 /* 1210 */ 544, 541, 512, 97, 442, 314, 541, 544, 920, 125,
151676 /* 1220 */ 1069, 984, 974, 974, 976, 977, 27, 105, 105, 399,
151677 /* 1230 */ 341, 1509, 44, 44, 106, 1070, 423, 546, 545, 57,
151678 /* 1240 */ 57, 974, 341, 1509, 107, 536, 544, 4, 460, 399,
151679 /* 1250 */ 214, 1118, 457, 294, 375, 1089, 532, 297, 544, 537,
151680 /* 1260 */ 396, 539, 290, 535, 104, 244, 102, 524, 58, 58,
151681 /* 1270 */ 544, 109, 974, 974, 976, 977, 27, 1514, 1129, 425,
151682 /* 1280 */ 59, 59, 270, 237, 423, 138, 95, 373, 373, 372,
151683 /* 1290 */ 255, 370, 60, 60, 815, 1178, 533, 544, 273, 544,
151684 /* 1300 */ 1161, 843, 387, 386, 544, 1307, 544, 215, 210, 296,
151685 /* 1310 */ 513, 847, 544, 265, 208, 514, 1306, 295, 274, 61,
151686 /* 1320 */ 61, 62, 62, 436, 984, 1160, 45, 45, 46, 46,
151687 /* 1330 */ 105, 105, 1184, 920, 47, 47, 1474, 106, 544, 423,
151688 /* 1340 */ 546, 545, 218, 544, 974, 935, 1085, 217, 544, 377,
151689 /* 1350 */ 395, 107, 536, 936, 4, 156, 1161, 843, 158, 544,
151690 /* 1360 */ 49, 49, 141, 544, 38, 50, 50, 544, 539, 307,
151691 /* 1370 */ 63, 63, 544, 1448, 216, 974, 974, 976, 977, 27,
151692 /* 1380 */ 444, 64, 64, 544, 1447, 65, 65, 544, 524, 14,
151693 /* 1390 */ 14, 423, 458, 544, 66, 66, 310, 544, 316, 97,
151694 /* 1400 */ 1034, 544, 961, 533, 268, 127, 127, 544, 391, 67,
151695 /* 1410 */ 67, 544, 978, 290, 535, 52, 52, 513, 544, 68,
151696 /* 1420 */ 68, 1294, 512, 69, 69, 397, 165, 855, 854, 53,
151697 /* 1430 */ 53, 984, 966, 151, 151, 243, 430, 105, 105, 199,
151698 /* 1440 */ 152, 152, 448, 1303, 106, 243, 423, 546, 545, 1129,
151699 /* 1450 */ 425, 974, 320, 270, 862, 863, 1034, 220, 373, 373,
151700 /* 1460 */ 372, 255, 370, 450, 323, 815, 243, 544, 978, 544,
151701 /* 1470 */ 107, 536, 544, 4, 544, 938, 939, 325, 215, 1046,
151702 /* 1480 */ 296, 1046, 974, 974, 976, 977, 27, 539, 295, 76,
151703 /* 1490 */ 76, 54, 54, 327, 72, 72, 128, 128, 1503, 1254,
151704 /* 1500 */ 107, 536, 544, 4, 1045, 544, 1045, 531, 1238, 544,
151705 /* 1510 */ 423, 544, 315, 334, 544, 97, 544, 539, 217, 544,
151706 /* 1520 */ 472, 1528, 533, 239, 73, 73, 156, 129, 129, 158,
151707 /* 1530 */ 467, 130, 130, 126, 126, 344, 150, 150, 149, 149,
151708 /* 1540 */ 423, 134, 134, 329, 1030, 216, 97, 239, 929, 345,
151709 /* 1550 */ 984, 243, 533, 1315, 339, 544, 105, 105, 900, 1355,
151710 /* 1560 */ 544, 1290, 258, 106, 338, 423, 546, 545, 544, 1301,
151711 /* 1570 */ 974, 893, 99, 536, 109, 4, 544, 133, 133, 391,
151712 /* 1580 */ 984, 197, 131, 131, 290, 535, 105, 105, 530, 539,
151713 /* 1590 */ 132, 132, 1361, 106, 1219, 423, 546, 545, 75, 75,
151714 /* 1600 */ 974, 974, 974, 976, 977, 27, 544, 430, 826, 1211,
151715 /* 1610 */ 894, 139, 423, 109, 544, 1200, 1199, 1201, 1522, 544,
151716 /* 1620 */ 201, 544, 11, 374, 533, 1287, 347, 349, 77, 77,
151717 /* 1630 */ 1340, 974, 974, 976, 977, 27, 74, 74, 351, 213,
151718 /* 1640 */ 435, 43, 43, 48, 48, 302, 477, 309, 1348, 382,
151719 /* 1650 */ 353, 452, 984, 337, 1237, 1420, 1419, 205, 105, 105,
151720 /* 1660 */ 192, 367, 193, 534, 1525, 106, 1178, 423, 546, 545,
151721 /* 1670 */ 247, 167, 974, 270, 1467, 200, 1465, 1175, 373, 373,
151722 /* 1680 */ 372, 255, 370, 398, 79, 815, 83, 82, 1425, 446,
151723 /* 1690 */ 161, 177, 169, 95, 1337, 438, 172, 173, 215, 174,
151724 /* 1700 */ 296, 175, 35, 974, 974, 976, 977, 27, 295, 1345,
151725 /* 1710 */ 439, 470, 223, 36, 379, 445, 1414, 381, 459, 1351,
151726 /* 1720 */ 181, 227, 88, 465, 259, 229, 1436, 318, 186, 468,
151727 /* 1730 */ 322, 230, 384, 1202, 231, 486, 1257, 1256, 217, 411,
151728 /* 1740 */ 1255, 1248, 90, 847, 206, 413, 156, 505, 1539, 158,
151729 /* 1750 */ 1226, 1538, 283, 1508, 1227, 336, 385, 284, 1225, 496,
151730 /* 1760 */ 1537, 1298, 94, 346, 348, 216, 1247, 499, 1299, 245,
151731 /* 1770 */ 246, 1297, 416, 350, 1494, 124, 1493, 10, 524, 361,
151732 /* 1780 */ 1400, 101, 96, 288, 508, 253, 1135, 1208, 34, 1296,
151733 /* 1790 */ 547, 254, 256, 257, 392, 548, 1197, 1192, 359, 391,
151734 /* 1800 */ 1280, 1279, 196, 365, 290, 535, 366, 352, 1452, 1322,
151735 /* 1810 */ 1321, 1453, 153, 137, 281, 154, 802, 424, 155, 1451,
151736 /* 1820 */ 1450, 198, 292, 202, 203, 78, 212, 430, 271, 135,
151737 /* 1830 */ 1044, 1042, 958, 168, 219, 157, 170, 879, 308, 222,
151738 /* 1840 */ 1058, 176, 159, 962, 400, 84, 402, 178, 85, 86,
151739 /* 1850 */ 87, 166, 160, 393, 1061, 224, 225, 1057, 146, 18,
151740 /* 1860 */ 226, 317, 1050, 1172, 243, 464, 182, 228, 37, 183,
151741 /* 1870 */ 817, 469, 338, 232, 330, 481, 184, 89, 845, 19,
151742 /* 1880 */ 20, 92, 473, 478, 333, 91, 162, 858, 147, 488,
151743 /* 1890 */ 282, 1123, 148, 1010, 928, 1093, 39, 93, 40, 495,
151744 /* 1900 */ 1094, 187, 498, 207, 262, 264, 923, 242, 1109, 109,
151745 /* 1910 */ 1113, 1111, 1097, 33, 21, 1117, 520, 1025, 22, 23,
151746 /* 1920 */ 24, 1116, 25, 190, 97, 1011, 1009, 26, 1013, 1067,
151747 /* 1930 */ 248, 7, 1066, 249, 1014, 28, 41, 889, 979, 827,
151748 /* 1940 */ 108, 29, 250, 540, 251, 1530, 371, 368, 1131, 1130,
151749 /* 1950 */ 1188, 1188, 1188, 1188, 1188, 1188, 1188, 1529,
151750 };
151751 static const YYCODETYPE yy_lookahead[] = {
151752 /* 0 */ 189, 211, 189, 189, 218, 189, 220, 189, 267, 268,
151753 /* 10 */ 269, 189, 210, 189, 228, 189, 267, 268, 269, 19,
151754 /* 20 */ 218, 189, 211, 212, 211, 212, 211, 211, 212, 211,
@@ -151504,11 +151941,11 @@
151941 /* 1890 */ 67, 23, 23, 23, 114, 23, 22, 26, 22, 24,
151942 /* 1900 */ 23, 22, 24, 139, 23, 23, 141, 34, 88, 26,
151943 /* 1910 */ 75, 86, 23, 22, 34, 75, 24, 23, 34, 34,
151944 /* 1920 */ 34, 93, 34, 26, 26, 23, 23, 34, 23, 23,
151945 /* 1930 */ 26, 44, 23, 22, 11, 22, 22, 133, 23, 23,
151946 /* 1940 */ 22, 22, 139, 26, 139, 139, 15, 23, 1, 1,
151947 /* 1950 */ 310, 310, 310, 310, 310, 310, 310, 139, 310, 310,
151948 /* 1960 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
151949 /* 1970 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
151950 /* 1980 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
151951 /* 1990 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
@@ -151525,13 +151962,13 @@
151962 /* 2100 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
151963 /* 2110 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
151964 /* 2120 */ 310, 310, 310, 310, 310, 310, 310, 310, 310, 310,
151965 /* 2130 */ 310, 310, 310, 310, 310, 310, 310, 310, 310,
151966 };
151967 #define YY_SHIFT_COUNT (550)
151968 #define YY_SHIFT_MIN (0)
151969 #define YY_SHIFT_MAX (1948)
151970 static const unsigned short int yy_shift_ofst[] = {
151971 /* 0 */ 1448, 1277, 1668, 1072, 1072, 340, 1122, 1225, 1332, 1481,
151972 /* 10 */ 1481, 1481, 335, 0, 0, 180, 897, 1481, 1481, 1481,
151973 /* 20 */ 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481, 1481,
151974 /* 30 */ 930, 930, 1020, 1020, 290, 1, 340, 340, 340, 340,
@@ -151584,10 +152021,11 @@
152021 /* 500 */ 1764, 1881, 1882, 1780, 1873, 1879, 1765, 1883, 1880, 1884,
152022 /* 510 */ 1885, 1886, 1820, 1835, 1825, 1887, 1840, 1828, 1888, 1889,
152023 /* 520 */ 1891, 1892, 1897, 1898, 1893, 1894, 1883, 1902, 1903, 1905,
152024 /* 530 */ 1906, 1904, 1909, 1911, 1923, 1913, 1914, 1915, 1916, 1918,
152025 /* 540 */ 1919, 1917, 1804, 1803, 1805, 1806, 1818, 1924, 1931, 1947,
152026 /* 550 */ 1948,
152027 };
152028 #define YY_REDUCE_COUNT (389)
152029 #define YY_REDUCE_MIN (-262)
152030 #define YY_REDUCE_MAX (1617)
152031 static const short yy_reduce_ofst[] = {
@@ -151630,65 +152068,66 @@
152068 /* 360 */ 1554, 1510, 1583, 1511, 1556, 1559, 1561, 1565, 1588, 1592,
152069 /* 370 */ 1601, 1602, 1607, 1608, 1609, 1498, 1557, 1558, 1610, 1600,
152070 /* 380 */ 1603, 1611, 1612, 1613, 1596, 1597, 1614, 1615, 1617, 1616,
152071 };
152072 static const YYACTIONTYPE yy_default[] = {
152073 /* 0 */ 1573, 1573, 1573, 1409, 1186, 1295, 1186, 1186, 1186, 1409,
152074 /* 10 */ 1409, 1409, 1186, 1325, 1325, 1462, 1217, 1186, 1186, 1186,
152075 /* 20 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1408, 1186, 1186,
152076 /* 30 */ 1186, 1186, 1492, 1492, 1186, 1186, 1186, 1186, 1186, 1186,
152077 /* 40 */ 1186, 1186, 1186, 1334, 1186, 1186, 1186, 1186, 1186, 1186,
152078 /* 50 */ 1410, 1411, 1186, 1186, 1186, 1461, 1463, 1426, 1344, 1343,
152079 /* 60 */ 1342, 1341, 1444, 1312, 1339, 1332, 1336, 1404, 1405, 1403,
152080 /* 70 */ 1407, 1411, 1410, 1186, 1335, 1375, 1389, 1374, 1186, 1186,
152081 /* 80 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152082 /* 90 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152083 /* 100 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152084 /* 110 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152085 /* 120 */ 1186, 1186, 1186, 1186, 1186, 1186, 1383, 1388, 1394, 1387,
152086 /* 130 */ 1384, 1377, 1376, 1378, 1379, 1186, 1207, 1259, 1186, 1186,
152087 /* 140 */ 1186, 1186, 1480, 1479, 1186, 1186, 1217, 1369, 1368, 1380,
152088 /* 150 */ 1381, 1391, 1390, 1469, 1527, 1526, 1427, 1186, 1186, 1186,
152089 /* 160 */ 1186, 1186, 1186, 1492, 1186, 1186, 1186, 1186, 1186, 1186,
152090 /* 170 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152091 /* 180 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1492, 1492,
152092 /* 190 */ 1186, 1217, 1492, 1492, 1213, 1213, 1319, 1186, 1475, 1295,
152093 /* 200 */ 1286, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152094 /* 210 */ 1186, 1186, 1186, 1186, 1186, 1466, 1464, 1186, 1186, 1186,
152095 /* 220 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152096 /* 230 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152097 /* 240 */ 1186, 1186, 1186, 1186, 1186, 1291, 1186, 1186, 1186, 1186,
152098 /* 250 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1521, 1186, 1439,
152099 /* 260 */ 1273, 1291, 1291, 1291, 1291, 1293, 1274, 1272, 1285, 1218,
152100 /* 270 */ 1193, 1565, 1338, 1314, 1314, 1562, 1338, 1338, 1562, 1234,
152101 /* 280 */ 1543, 1229, 1325, 1325, 1325, 1314, 1319, 1319, 1406, 1292,
152102 /* 290 */ 1285, 1186, 1565, 1300, 1300, 1564, 1564, 1300, 1427, 1347,
152103 /* 300 */ 1353, 1262, 1338, 1268, 1268, 1268, 1268, 1300, 1204, 1338,
152104 /* 310 */ 1338, 1347, 1353, 1262, 1262, 1338, 1300, 1204, 1443, 1559,
152105 /* 320 */ 1300, 1204, 1417, 1300, 1204, 1300, 1204, 1417, 1260, 1260,
152106 /* 330 */ 1260, 1249, 1186, 1186, 1417, 1260, 1234, 1260, 1249, 1260,
152107 /* 340 */ 1260, 1510, 1417, 1421, 1421, 1417, 1318, 1313, 1318, 1313,
152108 /* 350 */ 1318, 1313, 1318, 1313, 1300, 1502, 1502, 1328, 1328, 1333,
152109 /* 360 */ 1319, 1412, 1300, 1186, 1333, 1331, 1329, 1338, 1210, 1252,
152110 /* 370 */ 1524, 1524, 1520, 1520, 1520, 1570, 1570, 1475, 1536, 1217,
152111 /* 380 */ 1217, 1217, 1217, 1536, 1236, 1236, 1218, 1218, 1217, 1536,
152112 /* 390 */ 1186, 1186, 1186, 1186, 1186, 1186, 1531, 1186, 1428, 1304,
152113 /* 400 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152114 /* 410 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152115 /* 420 */ 1186, 1186, 1186, 1358, 1186, 1189, 1472, 1186, 1186, 1470,
152116 /* 430 */ 1186, 1186, 1186, 1186, 1186, 1186, 1305, 1186, 1186, 1186,
152117 /* 440 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152118 /* 450 */ 1186, 1186, 1186, 1186, 1186, 1561, 1186, 1186, 1186, 1186,
152119 /* 460 */ 1186, 1186, 1442, 1441, 1186, 1186, 1302, 1186, 1186, 1186,
152120 /* 470 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152121 /* 480 */ 1232, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152122 /* 490 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152123 /* 500 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1330, 1186, 1186,
152124 /* 510 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152125 /* 520 */ 1186, 1186, 1507, 1320, 1186, 1186, 1552, 1186, 1186, 1186,
152126 /* 530 */ 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186, 1186,
152127 /* 540 */ 1186, 1547, 1276, 1360, 1186, 1359, 1363, 1186, 1198, 1186,
152128 /* 550 */ 1186,
152129 };
152130 /********** End of lemon-generated parsing tables *****************************/
152131
152132 /* The next table maps tokens (terminal symbols) into fallback tokens.
152133 ** If a construct like the following:
@@ -152619,11 +153058,11 @@
153058 /* 325 */ "input ::= cmdlist",
153059 /* 326 */ "cmdlist ::= cmdlist ecmd",
153060 /* 327 */ "cmdlist ::= ecmd",
153061 /* 328 */ "ecmd ::= SEMI",
153062 /* 329 */ "ecmd ::= cmdx SEMI",
153063 /* 330 */ "ecmd ::= explain cmdx SEMI",
153064 /* 331 */ "trans_opt ::=",
153065 /* 332 */ "trans_opt ::= TRANSACTION",
153066 /* 333 */ "trans_opt ::= TRANSACTION nm",
153067 /* 334 */ "savepoint_opt ::= SAVEPOINT",
153068 /* 335 */ "savepoint_opt ::=",
@@ -153511,11 +153950,11 @@
153950 181, /* (325) input ::= cmdlist */
153951 182, /* (326) cmdlist ::= cmdlist ecmd */
153952 182, /* (327) cmdlist ::= ecmd */
153953 183, /* (328) ecmd ::= SEMI */
153954 183, /* (329) ecmd ::= cmdx SEMI */
153955 183, /* (330) ecmd ::= explain cmdx SEMI */
153956 188, /* (331) trans_opt ::= */
153957 188, /* (332) trans_opt ::= TRANSACTION */
153958 188, /* (333) trans_opt ::= TRANSACTION nm */
153959 190, /* (334) savepoint_opt ::= SAVEPOINT */
153960 190, /* (335) savepoint_opt ::= */
@@ -153901,11 +154340,11 @@
154340 -1, /* (325) input ::= cmdlist */
154341 -2, /* (326) cmdlist ::= cmdlist ecmd */
154342 -1, /* (327) cmdlist ::= ecmd */
154343 -1, /* (328) ecmd ::= SEMI */
154344 -2, /* (329) ecmd ::= cmdx SEMI */
154345 -3, /* (330) ecmd ::= explain cmdx SEMI */
154346 0, /* (331) trans_opt ::= */
154347 -1, /* (332) trans_opt ::= TRANSACTION */
154348 -2, /* (333) trans_opt ::= TRANSACTION nm */
154349 -1, /* (334) savepoint_opt ::= SAVEPOINT */
154350 0, /* (335) savepoint_opt ::= */
@@ -153989,16 +154428,19 @@
154428 yymsp = yypParser->yytos;
154429 #ifndef NDEBUG
154430 if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
154431 yysize = yyRuleInfoNRhs[yyruleno];
154432 if( yysize ){
154433 fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n",
154434 yyTracePrompt,
154435 yyruleno, yyRuleName[yyruleno],
154436 yyruleno<YYNRULE_WITH_ACTION ? "" : " without external action",
154437 yymsp[yysize].stateno);
154438 }else{
154439 fprintf(yyTraceFILE, "%sReduce %d [%s]%s.\n",
154440 yyTracePrompt, yyruleno, yyRuleName[yyruleno],
154441 yyruleno<YYNRULE_WITH_ACTION ? "" : " without external action");
154442 }
154443 }
154444 #endif /* NDEBUG */
154445
154446 /* Check that the stack is large enough to grow by a single entry
@@ -155405,11 +155847,11 @@
155847 /* (325) input ::= cmdlist */ yytestcase(yyruleno==325);
155848 /* (326) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==326);
155849 /* (327) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=327);
155850 /* (328) ecmd ::= SEMI */ yytestcase(yyruleno==328);
155851 /* (329) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==329);
155852 /* (330) ecmd ::= explain cmdx SEMI (NEVER REDUCES) */ assert(yyruleno!=330);
155853 /* (331) trans_opt ::= */ yytestcase(yyruleno==331);
155854 /* (332) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==332);
155855 /* (333) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==333);
155856 /* (334) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==334);
155857 /* (335) savepoint_opt ::= */ yytestcase(yyruleno==335);
@@ -163082,10 +163524,13 @@
163524 # define TESTONLY(X) X
163525 #else
163526 # define TESTONLY(X)
163527 #endif
163528
163529 #define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
163530 #define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
163531
163532 #endif /* SQLITE_AMALGAMATION */
163533
163534 #ifdef SQLITE_DEBUG
163535 SQLITE_PRIVATE int sqlite3Fts3Corrupt(void);
163536 # define FTS_CORRUPT_VTAB sqlite3Fts3Corrupt()
@@ -163125,10 +163570,11 @@
163570 sqlite3_tokenizer *pTokenizer; /* tokenizer for inserts and queries */
163571 char *zContentTbl; /* content=xxx option, or NULL */
163572 char *zLanguageid; /* languageid=xxx option, or NULL */
163573 int nAutoincrmerge; /* Value configured by 'automerge' */
163574 u32 nLeafAdd; /* Number of leaf blocks added this trans */
163575 int bLock; /* Used to prevent recursive content= tbls */
163576
163577 /* Precompiled statements used by the implementation. Each of these
163578 ** statements is run and reset within a single virtual table API call.
163579 */
163580 sqlite3_stmt *aStmt[40];
@@ -163463,10 +163909,11 @@
163909
163910 /* fts3.c */
163911 SQLITE_PRIVATE void sqlite3Fts3ErrMsg(char**,const char*,...);
163912 SQLITE_PRIVATE int sqlite3Fts3PutVarint(char *, sqlite3_int64);
163913 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
163914 SQLITE_PRIVATE int sqlite3Fts3GetVarintU(const char *, sqlite_uint64 *);
163915 SQLITE_PRIVATE int sqlite3Fts3GetVarintBounded(const char*,const char*,sqlite3_int64*);
163916 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
163917 SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64);
163918 SQLITE_PRIVATE void sqlite3Fts3Dequote(char *);
163919 SQLITE_PRIVATE void sqlite3Fts3DoclistPrev(int,char*,int,char**,sqlite3_int64*,int*,u8*);
@@ -163550,22 +163997,10 @@
163997 #ifndef SQLITE_CORE
163998 /* # include "sqlite3ext.h" */
163999 SQLITE_EXTENSION_INIT1
164000 #endif
164001
 
 
 
 
 
 
 
 
 
 
 
 
164002 static int fts3EvalNext(Fts3Cursor *pCsr);
164003 static int fts3EvalStart(Fts3Cursor *pCsr);
164004 static int fts3TermSegReaderCursor(
164005 Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **);
164006
@@ -163606,16 +164041,11 @@
164041 if( (v & mask2)==0 ){ var = v; return ret; }
164042 #define GETVARINT_INIT(v, ptr, shift, mask1, mask2, var, ret) \
164043 v = (*ptr++); \
164044 if( (v & mask2)==0 ){ var = v; return ret; }
164045
164046 SQLITE_PRIVATE int sqlite3Fts3GetVarintU(const char *pBuf, sqlite_uint64 *v){
 
 
 
 
 
164047 const unsigned char *p = (const unsigned char*)pBuf;
164048 const unsigned char *pStart = p;
164049 u32 a;
164050 u64 b;
164051 int shift;
@@ -163632,10 +164062,19 @@
164062 if( (c & 0x80)==0 ) break;
164063 }
164064 *v = b;
164065 return (int)(p - pStart);
164066 }
164067
164068 /*
164069 ** Read a 64-bit variable-length integer from memory starting at p[0].
164070 ** Return the number of bytes read, or 0 on error.
164071 ** The value is stored in *v.
164072 */
164073 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *pBuf, sqlite_int64 *v){
164074 return sqlite3Fts3GetVarintU(pBuf, (sqlite3_uint64*)v);
164075 }
164076
164077 /*
164078 ** Read a 64-bit variable-length integer from memory starting at p[0] and
164079 ** not extending past pEnd[-1].
164080 ** Return the number of bytes read, or 0 on error.
@@ -164852,10 +165291,14 @@
165291
165292 int iLangidCons = -1; /* Index of langid=x constraint, if present */
165293 int iDocidGe = -1; /* Index of docid>=x constraint, if present */
165294 int iDocidLe = -1; /* Index of docid<=x constraint, if present */
165295 int iIdx;
165296
165297 if( p->bLock ){
165298 return SQLITE_ERROR;
165299 }
165300
165301 /* By default use a full table scan. This is an expensive option,
165302 ** so search through the constraints to see if a more efficient
165303 ** strategy is possible.
165304 */
@@ -165051,11 +165494,15 @@
165494 pCsr->pStmt = p->pSeekStmt;
165495 p->pSeekStmt = 0;
165496 }else{
165497 zSql = sqlite3_mprintf("SELECT %s WHERE rowid = ?", p->zReadExprlist);
165498 if( !zSql ) return SQLITE_NOMEM;
165499 p->bLock++;
165500 rc = sqlite3_prepare_v3(
165501 p->db, zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0
165502 );
165503 p->bLock--;
165504 sqlite3_free(zSql);
165505 }
165506 if( rc==SQLITE_OK ) pCsr->bSeekStmt = 1;
165507 }
165508 return rc;
@@ -165069,15 +165516,19 @@
165516 static int fts3CursorSeek(sqlite3_context *pContext, Fts3Cursor *pCsr){
165517 int rc = SQLITE_OK;
165518 if( pCsr->isRequireSeek ){
165519 rc = fts3CursorSeekStmt(pCsr);
165520 if( rc==SQLITE_OK ){
165521 Fts3Table *pTab = (Fts3Table*)pCsr->base.pVtab;
165522 pTab->bLock++;
165523 sqlite3_bind_int64(pCsr->pStmt, 1, pCsr->iPrevId);
165524 pCsr->isRequireSeek = 0;
165525 if( SQLITE_ROW==sqlite3_step(pCsr->pStmt) ){
165526 pTab->bLock--;
165527 return SQLITE_OK;
165528 }else{
165529 pTab->bLock--;
165530 rc = sqlite3_reset(pCsr->pStmt);
165531 if( rc==SQLITE_OK && ((Fts3Table *)pCsr->base.pVtab)->zContentTbl==0 ){
165532 /* If no row was found and no error has occurred, then the %_content
165533 ** table is missing a row that is present in the full-text index.
165534 ** The data structures are corrupt. */
@@ -165245,11 +165696,11 @@
165696
165697 assert( piLeaf || piLeaf2 );
165698
165699 fts3GetVarint32(zNode, &iHeight);
165700 rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2);
165701 assert_fts3_nc( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) );
165702
165703 if( rc==SQLITE_OK && iHeight>1 ){
165704 char *zBlob = 0; /* Blob read from %_segments table */
165705 int nBlob = 0; /* Size of zBlob in bytes */
165706
@@ -165726,16 +166177,16 @@
166177 sqlite3_int64 *pVal /* IN/OUT: Integer value */
166178 ){
166179 if( *pp>=pEnd ){
166180 *pp = 0;
166181 }else{
166182 u64 iVal;
166183 *pp += sqlite3Fts3GetVarintU(*pp, &iVal);
166184 if( bDescIdx ){
166185 *pVal = (i64)((u64)*pVal - iVal);
166186 }else{
166187 *pVal = (i64)((u64)*pVal + iVal);
166188 }
166189 }
166190 }
166191
166192 /*
@@ -165761,14 +166212,14 @@
166212 sqlite3_int64 iVal /* Write this value to the list */
166213 ){
166214 sqlite3_uint64 iWrite;
166215 if( bDescIdx==0 || *pbFirst==0 ){
166216 assert_fts3_nc( *pbFirst==0 || iVal>=*piPrev );
166217 iWrite = (u64)iVal - (u64)*piPrev;
166218 }else{
166219 assert_fts3_nc( *piPrev>=iVal );
166220 iWrite = (u64)*piPrev - (u64)iVal;
166221 }
166222 assert( *pbFirst || *piPrev==0 );
166223 assert_fts3_nc( *pbFirst==0 || iWrite>0 );
166224 *pp += sqlite3Fts3PutVarint(*pp, iWrite);
166225 *piPrev = iVal;
@@ -165783,11 +166234,12 @@
166234 ** Otherwise, (i2-i1).
166235 **
166236 ** Using this makes it easier to write code that can merge doclists that are
166237 ** sorted in either ascending or descending order.
166238 */
166239 /* #define DOCID_CMP(i1, i2) ((bDescDoclist?-1:1) * (i64)((u64)i1-i2)) */
166240 #define DOCID_CMP(i1, i2) ((bDescDoclist?-1:1) * (i1>i2?1:((i1==i2)?0:-1)))
166241
166242 /*
166243 ** This function does an "OR" merge of two doclists (output contains all
166244 ** positions contained in either argument doclist). If the docids in the
166245 ** input doclists are sorted in ascending order, parameter bDescDoclist
@@ -166197,11 +166649,11 @@
166649 ** for the pending-terms. If this is a scan, then this call must be being
166650 ** made by an fts4aux module, not an FTS table. In this case calling
166651 ** Fts3SegReaderPending might segfault, as the data structures used by
166652 ** fts4aux are not completely populated. So it's easiest to filter these
166653 ** calls out here. */
166654 if( iLevel<0 && p->aIndex && p->iPrevLangid==iLangid ){
166655 Fts3SegReader *pSeg = 0;
166656 rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix||isScan, &pSeg);
166657 if( rc==SQLITE_OK && pSeg ){
166658 rc = fts3SegReaderCursorAppend(pCsr, pSeg);
166659 }
@@ -166460,17 +166912,20 @@
166912 */
166913 static int fts3NextMethod(sqlite3_vtab_cursor *pCursor){
166914 int rc;
166915 Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
166916 if( pCsr->eSearch==FTS3_DOCID_SEARCH || pCsr->eSearch==FTS3_FULLSCAN_SEARCH ){
166917 Fts3Table *pTab = (Fts3Table*)pCursor->pVtab;
166918 pTab->bLock++;
166919 if( SQLITE_ROW!=sqlite3_step(pCsr->pStmt) ){
166920 pCsr->isEof = 1;
166921 rc = sqlite3_reset(pCsr->pStmt);
166922 }else{
166923 pCsr->iPrevId = sqlite3_column_int64(pCsr->pStmt, 0);
166924 rc = SQLITE_OK;
166925 }
166926 pTab->bLock--;
166927 }else{
166928 rc = fts3EvalNext((Fts3Cursor *)pCursor);
166929 }
166930 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
166931 return rc;
@@ -166526,10 +166981,14 @@
166981 sqlite3_value *pDocidLe = 0; /* The "docid <= ?" constraint, if any */
166982 int iIdx;
166983
166984 UNUSED_PARAMETER(idxStr);
166985 UNUSED_PARAMETER(nVal);
166986
166987 if( p->bLock ){
166988 return SQLITE_ERROR;
166989 }
166990
166991 eSearch = (idxNum & 0x0000FFFF);
166992 assert( eSearch>=0 && eSearch<=(FTS3_FULLTEXT_SEARCH+p->nColumn) );
166993 assert( p->pSegments==0 );
166994
@@ -166598,11 +167057,15 @@
167057 zSql = sqlite3_mprintf("SELECT %s ORDER BY rowid %s",
167058 p->zReadExprlist, (pCsr->bDesc ? "DESC" : "ASC")
167059 );
167060 }
167061 if( zSql ){
167062 p->bLock++;
167063 rc = sqlite3_prepare_v3(
167064 p->db,zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0
167065 );
167066 p->bLock--;
167067 sqlite3_free(zSql);
167068 }else{
167069 rc = SQLITE_NOMEM;
167070 }
167071 }else if( eSearch==FTS3_DOCID_SEARCH ){
@@ -167757,19 +168220,20 @@
168220 Fts3Table *pTab,
168221 Fts3Doclist *pDL,
168222 u8 *pbEof
168223 ){
168224 char *pIter; /* Used to iterate through aAll */
168225 char *pEnd; /* 1 byte past end of aAll */
168226
168227 if( pDL->pNextDocid ){
168228 pIter = pDL->pNextDocid;
168229 assert( pDL->aAll!=0 || pIter==0 );
168230 }else{
168231 pIter = pDL->aAll;
168232 }
168233
168234 if( pIter==0 || pIter>=(pEnd = pDL->aAll + pDL->nAll) ){
168235 /* We have already reached the end of this doclist. EOF. */
168236 *pbEof = 1;
168237 }else{
168238 sqlite3_int64 iDelta;
168239 pIter += sqlite3Fts3GetVarint(pIter, &iDelta);
@@ -174105,11 +174569,11 @@
174569 int rc = SQLITE_OK;
174570
174571 assert( !p || p->iLastDocid<=iDocid );
174572
174573 if( !p || p->iLastDocid!=iDocid ){
174574 u64 iDelta = (u64)iDocid - (u64)(p ? p->iLastDocid : 0);
174575 if( p ){
174576 assert( p->nData<p->nSpace );
174577 assert( p->aData[p->nData]==0 );
174578 p->nData++;
174579 }
@@ -174646,10 +175110,12 @@
175110 aByte = 0;
175111 }
175112 }
175113 *paBlob = aByte;
175114 }
175115 }else if( rc==SQLITE_ERROR ){
175116 rc = FTS_CORRUPT_VTAB;
175117 }
175118
175119 return rc;
175120 }
175121
@@ -174938,22 +175404,22 @@
175404 if( p>=pEnd ){
175405 pReader->pOffsetList = 0;
175406 }else{
175407 rc = fts3SegReaderRequire(pReader, p, FTS3_VARINT_MAX);
175408 if( rc==SQLITE_OK ){
175409 u64 iDelta;
175410 pReader->pOffsetList = p + sqlite3Fts3GetVarintU(p, &iDelta);
175411 if( pTab->bDescIdx ){
175412 pReader->iDocid = (i64)((u64)pReader->iDocid - iDelta);
175413 }else{
175414 pReader->iDocid = (i64)((u64)pReader->iDocid + iDelta);
175415 }
175416 }
175417 }
175418 }
175419
175420 return rc;
175421 }
175422
175423
175424 SQLITE_PRIVATE int sqlite3Fts3MsrOvfl(
175425 Fts3Cursor *pCsr,
@@ -175688,10 +176154,11 @@
176154
176155 if( nData>0 && nData+nReq>p->nNodeSize ){
176156 int rc;
176157
176158 /* The current leaf node is full. Write it out to the database. */
176159 if( pWriter->iFree==LARGEST_INT64 ) return FTS_CORRUPT_VTAB;
176160 rc = fts3WriteSegment(p, pWriter->iFree++, pWriter->aData, nData);
176161 if( rc!=SQLITE_OK ) return rc;
176162 p->nLeafAdd++;
176163
176164 /* Add the current term to the interior node tree. The term added to
@@ -176385,14 +176852,14 @@
176852 /* Calculate the 'docid' delta value to write into the merged
176853 ** doclist. */
176854 sqlite3_int64 iDelta;
176855 if( p->bDescIdx && nDoclist>0 ){
176856 if( iPrev<=iDocid ) return FTS_CORRUPT_VTAB;
176857 iDelta = (i64)((u64)iPrev - (u64)iDocid);
176858 }else{
176859 if( nDoclist>0 && iPrev>=iDocid ) return FTS_CORRUPT_VTAB;
176860 iDelta = (i64)((u64)iDocid - (u64)iPrev);
176861 }
176862
176863 nByte = sqlite3Fts3VarintLen(iDelta) + (isRequirePos?nList+1:0);
176864 if( nDoclist+nByte>pCsr->nBuffer ){
176865 char *aNew;
@@ -176671,11 +177138,11 @@
177138 if( rc!=SQLITE_ROW ) break;
177139 rc = fts3SegWriterAdd(p, &pWriter, 1,
177140 csr.zTerm, csr.nTerm, csr.aDoclist, csr.nDoclist);
177141 }
177142 if( rc!=SQLITE_OK ) goto finished;
177143 assert_fts3_nc( pWriter || bIgnoreEmpty );
177144
177145 if( iLevel!=FTS3_SEGCURSOR_PENDING ){
177146 rc = fts3DeleteSegdir(
177147 p, iLangid, iIndex, iLevel, csr.apSegment, csr.nSegment
177148 );
@@ -178257,17 +178724,21 @@
178724 */
178725 static int fts3IncrmergeHintPop(Blob *pHint, i64 *piAbsLevel, int *pnInput){
178726 const int nHint = pHint->n;
178727 int i;
178728
178729 i = pHint->n-1;
178730 if( (pHint->a[i] & 0x80) ) return FTS_CORRUPT_VTAB;
178731 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
178732 if( i==0 ) return FTS_CORRUPT_VTAB;
178733 i--;
178734 while( i>0 && (pHint->a[i-1] & 0x80) ) i--;
178735
178736 pHint->n = i;
178737 i += sqlite3Fts3GetVarint(&pHint->a[i], piAbsLevel);
178738 i += fts3GetVarint32(&pHint->a[i], pnInput);
178739 assert( i<=nHint );
178740 if( i!=nHint ) return FTS_CORRUPT_VTAB;
178741
178742 return SQLITE_OK;
178743 }
178744
@@ -178593,28 +179064,28 @@
179064 char *pCsr = csr.aDoclist;
179065 char *pEnd = &pCsr[csr.nDoclist];
179066
179067 i64 iDocid = 0;
179068 i64 iCol = 0;
179069 u64 iPos = 0;
179070
179071 pCsr += sqlite3Fts3GetVarint(pCsr, &iDocid);
179072 while( pCsr<pEnd ){
179073 u64 iVal = 0;
179074 pCsr += sqlite3Fts3GetVarintU(pCsr, &iVal);
179075 if( pCsr<pEnd ){
179076 if( iVal==0 || iVal==1 ){
179077 iCol = 0;
179078 iPos = 0;
179079 if( iVal ){
179080 pCsr += sqlite3Fts3GetVarint(pCsr, &iCol);
179081 }else{
179082 pCsr += sqlite3Fts3GetVarintU(pCsr, &iVal);
179083 if( p->bDescIdx ){
179084 iDocid = (i64)((u64)iDocid - iVal);
179085 }else{
179086 iDocid = (i64)((u64)iDocid + iVal);
179087 }
179088 }
179089 }else{
179090 iPos += (iVal - 2);
179091 cksum = cksum ^ fts3ChecksumEntry(
@@ -182886,22 +183357,53 @@
183357 pRoot->jnFlags |= JNODE_APPEND;
183358 pParse->aNode[iLabel].jnFlags |= JNODE_RAW;
183359 }
183360 return pNode;
183361 }
183362 }else if( zPath[0]=='[' ){
 
183363 i = 0;
183364 j = 1;
183365 while( safe_isdigit(zPath[j]) ){
183366 i = i*10 + zPath[j] - '0';
183367 j++;
183368 }
183369 if( j<2 || zPath[j]!=']' ){
183370 if( zPath[1]=='#' ){
183371 JsonNode *pBase = pRoot;
183372 int iBase = iRoot;
183373 if( pRoot->eType!=JSON_ARRAY ) return 0;
183374 for(;;){
183375 while( j<=pBase->n ){
183376 if( (pBase[j].jnFlags & JNODE_REMOVE)==0 ) i++;
183377 j += jsonNodeSize(&pBase[j]);
183378 }
183379 if( (pBase->jnFlags & JNODE_APPEND)==0 ) break;
183380 iBase += pBase->u.iAppend;
183381 pBase = &pParse->aNode[iBase];
183382 j = 1;
183383 }
183384 j = 2;
183385 if( zPath[2]=='-' && safe_isdigit(zPath[3]) ){
183386 unsigned int x = 0;
183387 j = 3;
183388 do{
183389 x = x*10 + zPath[j] - '0';
183390 j++;
183391 }while( safe_isdigit(zPath[j]) );
183392 if( x>i ) return 0;
183393 i -= x;
183394 }
183395 if( zPath[j]!=']' ){
183396 *pzErr = zPath;
183397 return 0;
183398 }
183399 }else{
183400 *pzErr = zPath;
183401 return 0;
183402 }
183403 }
183404 if( pRoot->eType!=JSON_ARRAY ) return 0;
183405 zPath += j + 1;
183406 j = 1;
183407 for(;;){
183408 while( j<=pRoot->n && (i>0 || (pRoot[j].jnFlags & JNODE_REMOVE)!=0) ){
183409 if( (pRoot[j].jnFlags & JNODE_REMOVE)==0 ) i--;
@@ -184365,10 +184867,11 @@
184867 /* #include "sqlite3ext.h" */
184868 SQLITE_EXTENSION_INIT1
184869 #else
184870 /* #include "sqlite3.h" */
184871 #endif
184872 SQLITE_PRIVATE int sqlite3GetToken(const unsigned char*,int*); /* In the SQLite core */
184873
184874 #ifndef SQLITE_AMALGAMATION
184875 #include "sqlite3rtree.h"
184876 typedef sqlite3_int64 i64;
184877 typedef sqlite3_uint64 u64;
@@ -184628,10 +185131,16 @@
185131 #define RTREE_GE 0x44 /* D */
185132 #define RTREE_GT 0x45 /* E */
185133 #define RTREE_MATCH 0x46 /* F: Old-style sqlite3_rtree_geometry_callback() */
185134 #define RTREE_QUERY 0x47 /* G: New-style sqlite3_rtree_query_callback() */
185135
185136 /* Special operators available only on cursors. Needs to be consecutive
185137 ** with the normal values above, but must be less than RTREE_MATCH. These
185138 ** are used in the cursor for contraints such as x=NULL (RTREE_FALSE) or
185139 ** x<'xyz' (RTREE_TRUE) */
185140 #define RTREE_TRUE 0x3f /* ? */
185141 #define RTREE_FALSE 0x40 /* @ */
185142
185143 /*
185144 ** An rtree structure node.
185145 */
185146 struct RtreeNode {
@@ -185361,13 +185870,16 @@
185870 return rc;
185871 }
185872
185873
185874 /*
185875 ** Reset a cursor back to its initial state.
185876 */
185877 static void resetCursor(RtreeCursor *pCsr){
185878 Rtree *pRtree = (Rtree *)(pCsr->base.pVtab);
185879 int ii;
185880 sqlite3_stmt *pStmt;
185881 if( pCsr->aConstraint ){
185882 int i; /* Used to iterate through constraint array */
185883 for(i=0; i<pCsr->nConstraint; i++){
185884 sqlite3_rtree_query_info *pInfo = pCsr->aConstraint[i].pInfo;
185885 if( pInfo ){
@@ -185376,24 +185888,28 @@
185888 }
185889 }
185890 sqlite3_free(pCsr->aConstraint);
185891 pCsr->aConstraint = 0;
185892 }
185893 for(ii=0; ii<RTREE_CACHE_SZ; ii++) nodeRelease(pRtree, pCsr->aNode[ii]);
185894 sqlite3_free(pCsr->aPoint);
185895 pStmt = pCsr->pReadAux;
185896 memset(pCsr, 0, sizeof(RtreeCursor));
185897 pCsr->base.pVtab = (sqlite3_vtab*)pRtree;
185898 pCsr->pReadAux = pStmt;
185899
185900 }
185901
185902 /*
185903 ** Rtree virtual table module xClose method.
185904 */
185905 static int rtreeClose(sqlite3_vtab_cursor *cur){
185906 Rtree *pRtree = (Rtree *)(cur->pVtab);
 
185907 RtreeCursor *pCsr = (RtreeCursor *)cur;
185908 assert( pRtree->nCursor>0 );
185909 resetCursor(pCsr);
185910 sqlite3_finalize(pCsr->pReadAux);
 
 
185911 sqlite3_free(pCsr);
185912 pRtree->nCursor--;
185913 nodeBlobReset(pRtree);
185914 return SQLITE_OK;
185915 }
@@ -185547,13 +186063,16 @@
186063 ** in a coordinate pair. But make pCellData point to the lower bound.
186064 */
186065 pCellData += 8 + 4*(p->iCoord&0xfe);
186066
186067 assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
186068 || p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_TRUE
186069 || p->op==RTREE_FALSE );
186070 assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */
186071 switch( p->op ){
186072 case RTREE_TRUE: return; /* Always satisfied */
186073 case RTREE_FALSE: break; /* Never satisfied */
186074 case RTREE_LE:
186075 case RTREE_LT:
186076 case RTREE_EQ:
186077 RTREE_DECODE_COORD(eInt, pCellData, val);
186078 /* val now holds the lower bound of the coordinate pair */
@@ -185587,20 +186106,23 @@
186106 int *peWithin /* Adjust downward, as appropriate */
186107 ){
186108 RtreeDValue xN; /* Coordinate value converted to a double */
186109
186110 assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
186111 || p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_TRUE
186112 || p->op==RTREE_FALSE );
186113 pCellData += 8 + p->iCoord*4;
186114 assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */
186115 RTREE_DECODE_COORD(eInt, pCellData, xN);
186116 switch( p->op ){
186117 case RTREE_TRUE: return; /* Always satisfied */
186118 case RTREE_FALSE: break; /* Never satisfied */
186119 case RTREE_LE: if( xN <= p->u.rValue ) return; break;
186120 case RTREE_LT: if( xN < p->u.rValue ) return; break;
186121 case RTREE_GE: if( xN >= p->u.rValue ) return; break;
186122 case RTREE_GT: if( xN > p->u.rValue ) return; break;
186123 default: if( xN == p->u.rValue ) return; break;
186124 }
186125 *peWithin = NOT_WITHIN;
186126 }
186127
186128 /*
@@ -186089,30 +186611,32 @@
186611 RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor;
186612 RtreeNode *pRoot = 0;
186613 int ii;
186614 int rc = SQLITE_OK;
186615 int iCell = 0;
 
186616
186617 rtreeReference(pRtree);
186618
186619 /* Reset the cursor to the same state as rtreeOpen() leaves it in. */
186620 resetCursor(pCsr);
 
 
 
 
 
186621
186622 pCsr->iStrategy = idxNum;
186623 if( idxNum==1 ){
186624 /* Special case - lookup by rowid. */
186625 RtreeNode *pLeaf; /* Leaf on which the required cell resides */
186626 RtreeSearchPoint *p; /* Search point for the leaf */
186627 i64 iRowid = sqlite3_value_int64(argv[0]);
186628 i64 iNode = 0;
186629 int eType = sqlite3_value_numeric_type(argv[0]);
186630 if( eType==SQLITE_INTEGER
186631 || (eType==SQLITE_FLOAT && sqlite3_value_double(argv[0])==iRowid)
186632 ){
186633 rc = findLeafNode(pRtree, iRowid, &pLeaf, &iNode);
186634 }else{
186635 rc = SQLITE_OK;
186636 pLeaf = 0;
186637 }
186638 if( rc==SQLITE_OK && pLeaf!=0 ){
186639 p = rtreeSearchPointNew(pCsr, RTREE_ZERO, 0);
186640 assert( p!=0 ); /* Always returns pCsr->sPoint */
186641 pCsr->aNode[0] = pLeaf;
186642 p->id = iNode;
@@ -186138,10 +186662,11 @@
186662 memset(pCsr->anQueue, 0, sizeof(u32)*(pRtree->iDepth + 1));
186663 assert( (idxStr==0 && argc==0)
186664 || (idxStr && (int)strlen(idxStr)==argc*2) );
186665 for(ii=0; ii<argc; ii++){
186666 RtreeConstraint *p = &pCsr->aConstraint[ii];
186667 int eType = sqlite3_value_numeric_type(argv[ii]);
186668 p->op = idxStr[ii*2];
186669 p->iCoord = idxStr[ii*2+1]-'0';
186670 if( p->op>=RTREE_MATCH ){
186671 /* A MATCH operator. The right-hand-side must be a blob that
186672 ** can be cast into an RtreeMatchArg object. One created using
@@ -186152,16 +186677,25 @@
186677 break;
186678 }
186679 p->pInfo->nCoord = pRtree->nDim2;
186680 p->pInfo->anQueue = pCsr->anQueue;
186681 p->pInfo->mxLevel = pRtree->iDepth + 1;
186682 }else if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
186683 #ifdef SQLITE_RTREE_INT_ONLY
186684 p->u.rValue = sqlite3_value_int64(argv[ii]);
186685 #else
186686 p->u.rValue = sqlite3_value_double(argv[ii]);
186687 #endif
186688 }else{
186689 p->u.rValue = RTREE_ZERO;
186690 if( eType==SQLITE_NULL ){
186691 p->op = RTREE_FALSE;
186692 }else if( p->op==RTREE_LT || p->op==RTREE_LE ){
186693 p->op = RTREE_TRUE;
186694 }else{
186695 p->op = RTREE_FALSE;
186696 }
186697 }
186698 }
186699 }
186700 }
186701 if( rc==SQLITE_OK ){
@@ -187933,10 +188467,18 @@
188467 }
188468
188469 sqlite3_free(zSql);
188470 return rc;
188471 }
188472
188473 /*
188474 ** Return the length of a token
188475 */
188476 static int rtreeTokenLength(const char *z){
188477 int dummy = 0;
188478 return sqlite3GetToken((const unsigned char*)z,&dummy);
188479 }
188480
188481 /*
188482 ** This function is the implementation of both the xConnect and xCreate
188483 ** methods of the r-tree virtual table.
188484 **
@@ -187970,12 +188512,12 @@
188512 "Too many columns for an rtree table", /* 3 */
188513 "Auxiliary rtree columns must be last" /* 4 */
188514 };
188515
188516 assert( RTREE_MAX_AUX_COLUMN<256 ); /* Aux columns counted by a u8 */
188517 if( argc<6 || argc>RTREE_MAX_AUX_COLUMN+3 ){
188518 *pzErr = sqlite3_mprintf("%s", aErrMsg[2 + (argc>=6)]);
188519 return SQLITE_ERROR;
188520 }
188521
188522 sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
188523
@@ -187999,20 +188541,22 @@
188541 /* Create/Connect to the underlying relational database schema. If
188542 ** that is successful, call sqlite3_declare_vtab() to configure
188543 ** the r-tree table schema.
188544 */
188545 pSql = sqlite3_str_new(db);
188546 sqlite3_str_appendf(pSql, "CREATE TABLE x(%.*s INT",
188547 rtreeTokenLength(argv[3]), argv[3]);
188548 for(ii=4; ii<argc; ii++){
188549 const char *zArg = argv[ii];
188550 if( zArg[0]=='+' ){
188551 pRtree->nAux++;
188552 sqlite3_str_appendf(pSql, ",%.*s", rtreeTokenLength(zArg+1), zArg+1);
188553 }else if( pRtree->nAux>0 ){
188554 break;
188555 }else{
188556 pRtree->nDim2++;
188557 sqlite3_str_appendf(pSql, ",%.*s NUM", rtreeTokenLength(zArg), zArg);
188558 }
188559 }
188560 sqlite3_str_appendf(pSql, ");");
188561 zSql = sqlite3_str_finish(pSql);
188562 if( !zSql ){
@@ -189956,21 +190500,15 @@
190500 Rtree *pRtree = (Rtree *)pVtabCursor->pVtab;
190501 RtreeCursor *pCsr = (RtreeCursor *)pVtabCursor;
190502 RtreeNode *pRoot = 0;
190503 int rc = SQLITE_OK;
190504 int iCell = 0;
 
190505
190506 rtreeReference(pRtree);
190507
190508 /* Reset the cursor to the same state as rtreeOpen() leaves it in. */
190509 resetCursor(pCsr);
 
 
 
 
 
190510
190511 pCsr->iStrategy = idxNum;
190512 if( idxNum==1 ){
190513 /* Special case - lookup by rowid. */
190514 RtreeNode *pLeaf; /* Leaf on which the required cell resides */
@@ -196990,11 +197528,11 @@
197528 }
197529 z += 2;
197530 }else{
197531 while( *z==0 ) z++;
197532 }
197533 z += (n + 8 + 2);
197534 return z;
197535 }
197536
197537 /*
197538 ** Open an rbu file handle.
@@ -204281,11 +204819,11 @@
204819 ** the callback, an SQLite error code is returned.
204820 **
204821 **
204822 ** xSetAuxdata(pFts5, pAux, xDelete)
204823 **
204824 ** Save the pointer passed as the second argument as the extension function's
204825 ** "auxiliary data". The pointer may then be retrieved by the current or any
204826 ** future invocation of the same fts5 extension function made as part of
204827 ** the same MATCH query using the xGetAuxdata() API.
204828 **
204829 ** Each extension function is allocated a single auxiliary data slot for
@@ -204523,12 +205061,12 @@
205061 ** all instances of "first place" or "1st place" regardless of which form
205062 ** the user specified in the MATCH query text.
205063 **
205064 ** There are several ways to approach this in FTS5:
205065 **
205066 ** <ol><li> By mapping all synonyms to a single token. In this case, using
205067 ** the above example, this means that the tokenizer returns the
205068 ** same token for inputs "first" and "1st". Say that token is in
205069 ** fact "first", so that when the user inserts the document "I won
205070 ** 1st place" entries are added to the index for tokens "i", "won",
205071 ** "first" and "place". If the user then queries for '1st + place',
205072 ** the tokenizer substitutes "first" for "1st" and the query works
@@ -205685,10 +206223,11 @@
206223 #define sqlite3Fts5ParserCTX_PARAM
206224 #define sqlite3Fts5ParserCTX_FETCH
206225 #define sqlite3Fts5ParserCTX_STORE
206226 #define fts5YYNSTATE 35
206227 #define fts5YYNRULE 28
206228 #define fts5YYNRULE_WITH_ACTION 28
206229 #define fts5YYNFTS5TOKEN 16
206230 #define fts5YY_MAX_SHIFT 34
206231 #define fts5YY_MIN_SHIFTREDUCE 52
206232 #define fts5YY_MAX_SHIFTREDUCE 79
206233 #define fts5YY_ERROR_ACTION 80
@@ -206514,16 +207053,19 @@
207053 fts5yymsp = fts5yypParser->fts5yytos;
207054 #ifndef NDEBUG
207055 if( fts5yyTraceFILE && fts5yyruleno<(int)(sizeof(fts5yyRuleName)/sizeof(fts5yyRuleName[0])) ){
207056 fts5yysize = fts5yyRuleInfoNRhs[fts5yyruleno];
207057 if( fts5yysize ){
207058 fprintf(fts5yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n",
207059 fts5yyTracePrompt,
207060 fts5yyruleno, fts5yyRuleName[fts5yyruleno],
207061 fts5yyruleno<fts5YYNRULE_WITH_ACTION ? "" : " without external action",
207062 fts5yymsp[fts5yysize].stateno);
207063 }else{
207064 fprintf(fts5yyTraceFILE, "%sReduce %d [%s]%s.\n",
207065 fts5yyTracePrompt, fts5yyruleno, fts5yyRuleName[fts5yyruleno],
207066 fts5yyruleno<fts5YYNRULE_WITH_ACTION ? "" : " without external action");
207067 }
207068 }
207069 #endif /* NDEBUG */
207070
207071 /* Check that the stack is large enough to grow by a single entry
@@ -208278,11 +208820,11 @@
208820
208821 /* Set stack variable q to the close-quote character */
208822 assert( q=='[' || q=='\'' || q=='"' || q=='`' );
208823 if( q=='[' ) q = ']';
208824
208825 while( z[iIn] ){
208826 if( z[iIn]==q ){
208827 if( z[iIn+1]!=q ){
208828 /* Character iIn was the close quote. */
208829 iIn++;
208830 break;
@@ -211607,14 +212149,16 @@
212149 }
212150 azConfig[0] = 0;
212151 azConfig[1] = "main";
212152 azConfig[2] = "tbl";
212153 for(i=3; iArg<nArg; iArg++){
212154 const char *z = (const char*)sqlite3_value_text(apVal[iArg]);
212155 azConfig[i++] = (z ? z : "");
212156 }
212157
212158 zExpr = (const char*)sqlite3_value_text(apVal[0]);
212159 if( zExpr==0 ) zExpr = "";
212160
212161 rc = sqlite3Fts5ConfigParse(pGlobal, db, nConfig, azConfig, &pConfig, &zErr);
212162 if( rc==SQLITE_OK ){
212163 rc = sqlite3Fts5ExprNew(pConfig, pConfig->nCol, zExpr, &pExpr, &zErr);
212164 }
@@ -217860,14 +218404,17 @@
218404 int n = 0;
218405 int i;
218406 for(i=0; i<nChar; i++){
218407 if( n>=nByte ) return 0; /* Input contains fewer than nChar chars */
218408 if( (unsigned char)p[n++]>=0xc0 ){
218409 if( n>=nByte ) return 0;
218410 while( (p[n] & 0xc0)==0x80 ){
218411 n++;
218412 if( n>=nByte ){
218413 if( i+1==nChar ) break;
218414 return 0;
218415 }
218416 }
218417 }
218418 }
218419 return n;
218420 }
@@ -218265,10 +218812,41 @@
218812
218813 *pCksum = cksum;
218814 return rc;
218815 }
218816
218817 /*
218818 ** Check if buffer z[], size n bytes, contains as series of valid utf-8
218819 ** encoded codepoints. If so, return 0. Otherwise, if the buffer does not
218820 ** contain valid utf-8, return non-zero.
218821 */
218822 static int fts5TestUtf8(const char *z, int n){
218823 assert_nc( n>0 );
218824 int i = 0;
218825 while( i<n ){
218826 if( (z[i] & 0x80)==0x00 ){
218827 i++;
218828 }else
218829 if( (z[i] & 0xE0)==0xC0 ){
218830 if( i+1>=n || (z[i+1] & 0xC0)!=0x80 ) return 1;
218831 i += 2;
218832 }else
218833 if( (z[i] & 0xF0)==0xE0 ){
218834 if( i+2>=n || (z[i+1] & 0xC0)!=0x80 || (z[i+2] & 0xC0)!=0x80 ) return 1;
218835 i += 3;
218836 }else
218837 if( (z[i] & 0xF8)==0xF0 ){
218838 if( i+3>=n || (z[i+1] & 0xC0)!=0x80 || (z[i+2] & 0xC0)!=0x80 ) return 1;
218839 if( (z[i+2] & 0xC0)!=0x80 ) return 1;
218840 i += 3;
218841 }else{
218842 return 1;
218843 }
218844 }
218845
218846 return 0;
218847 }
218848
218849 /*
218850 ** This function is also purely an internal test. It does not contribute to
218851 ** FTS functionality, or even the integrity-check, in any way.
218852 */
@@ -218305,12 +218883,18 @@
218883 ** the index is disabled are the same. In both ASC and DESC order.
218884 **
218885 ** This check may only be performed if the hash table is empty. This
218886 ** is because the hash table only supports a single scan query at
218887 ** a time, and the multi-iter loop from which this function is called
218888 ** is already performing such a scan.
218889 **
218890 ** Also only do this if buffer zTerm contains nTerm bytes of valid
218891 ** utf-8. Otherwise, the last part of the buffer contents might contain
218892 ** a non-utf-8 sequence that happens to be a prefix of a valid utf-8
218893 ** character stored in the main fts index, which will cause the
218894 ** test to fail. */
218895 if( p->nPendingData==0 && 0==fts5TestUtf8(zTerm, nTerm) ){
218896 if( iIdx>0 && rc==SQLITE_OK ){
218897 int f = flags|FTS5INDEX_QUERY_TEST_NOIDX;
218898 ck2 = 0;
218899 rc = fts5QueryCksum(p, iIdx, zTerm, nTerm, f, &ck2);
218900 if( rc==SQLITE_OK && ck1!=ck2 ) rc = FTS5_CORRUPT;
@@ -218439,12 +219023,12 @@
219023 /* Iterate through the b-tree hierarchy. */
219024 while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
219025 i64 iRow; /* Rowid for this leaf */
219026 Fts5Data *pLeaf; /* Data for this leaf */
219027
219028 const char *zIdxTerm = (const char*)sqlite3_column_blob(pStmt, 1);
219029 int nIdxTerm = sqlite3_column_bytes(pStmt, 1);
 
219030 int iIdxLeaf = sqlite3_column_int(pStmt, 2);
219031 int bIdxDlidx = sqlite3_column_int(pStmt, 3);
219032
219033 /* If the leaf in question has already been trimmed from the segment,
219034 ** ignore this b-tree entry. Otherwise, load it into memory. */
@@ -220027,19 +220611,28 @@
220611 case FTS5_PLAN_SORTED_MATCH: {
220612 rc = fts5SorterNext(pCsr);
220613 break;
220614 }
220615
220616 default: {
220617 Fts5Config *pConfig = ((Fts5Table*)pCursor->pVtab)->pConfig;
220618 pConfig->bLock++;
220619 rc = sqlite3_step(pCsr->pStmt);
220620 pConfig->bLock--;
220621 if( rc!=SQLITE_ROW ){
220622 CsrFlagSet(pCsr, FTS5CSR_EOF);
220623 rc = sqlite3_reset(pCsr->pStmt);
220624 if( rc!=SQLITE_OK ){
220625 pCursor->pVtab->zErrMsg = sqlite3_mprintf(
220626 "%s", sqlite3_errmsg(pConfig->db)
220627 );
220628 }
220629 }else{
220630 rc = SQLITE_OK;
220631 }
220632 break;
220633 }
220634 }
220635 }
220636
220637 return rc;
220638 }
@@ -220319,10 +220912,17 @@
220912 int iCol; /* Column on LHS of MATCH operator */
220913 char **pzErrmsg = pConfig->pzErrmsg;
220914 int i;
220915 int iIdxStr = 0;
220916 Fts5Expr *pExpr = 0;
220917
220918 if( pConfig->bLock ){
220919 pTab->p.base.zErrMsg = sqlite3_mprintf(
220920 "recursively defined fts5 content table"
220921 );
220922 return SQLITE_ERROR;
220923 }
220924
220925 if( pCsr->ePlan ){
220926 fts5FreeCursorComponents(pCsr);
220927 memset(&pCsr->ePlan, 0, sizeof(Fts5Cursor) - ((u8*)&pCsr->ePlan-(u8*)pCsr));
220928 }
@@ -220540,21 +221140,28 @@
221140 assert( rc!=SQLITE_OK || pTab->p.base.zErrMsg==0 );
221141 assert( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_CONTENT) );
221142 }
221143
221144 if( rc==SQLITE_OK && CsrFlagTest(pCsr, FTS5CSR_REQUIRE_CONTENT) ){
221145 Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
221146 assert( pCsr->pExpr );
221147 sqlite3_reset(pCsr->pStmt);
221148 sqlite3_bind_int64(pCsr->pStmt, 1, fts5CursorRowid(pCsr));
221149 pTab->pConfig->bLock++;
221150 rc = sqlite3_step(pCsr->pStmt);
221151 pTab->pConfig->bLock--;
221152 if( rc==SQLITE_ROW ){
221153 rc = SQLITE_OK;
221154 CsrFlagClear(pCsr, FTS5CSR_REQUIRE_CONTENT);
221155 }else{
221156 rc = sqlite3_reset(pCsr->pStmt);
221157 if( rc==SQLITE_OK ){
221158 rc = FTS5_CORRUPT;
221159 }else if( pTab->pConfig->pzErrmsg ){
221160 *pTab->pConfig->pzErrmsg = sqlite3_mprintf(
221161 "%s", sqlite3_errmsg(pTab->pConfig->db)
221162 );
221163 }
221164 }
221165 }
221166 return rc;
221167 }
@@ -221566,14 +222173,16 @@
222173 if( pCsr->pRank || SQLITE_OK==(rc = fts5FindRankFunction(pCsr)) ){
222174 fts5ApiInvoke(pCsr->pRank, pCsr, pCtx, pCsr->nRankArg, pCsr->apRankArg);
222175 }
222176 }
222177 }else if( !fts5IsContentless(pTab) ){
222178 pConfig->pzErrmsg = &pTab->p.base.zErrMsg;
222179 rc = fts5SeekCursor(pCsr, 1);
222180 if( rc==SQLITE_OK ){
222181 sqlite3_result_value(pCtx, sqlite3_column_value(pCsr->pStmt, iCol+1));
222182 }
222183 pConfig->pzErrmsg = 0;
222184 }
222185 return rc;
222186 }
222187
222188
@@ -221846,11 +222455,11 @@
222455 int nArg, /* Number of args */
222456 sqlite3_value **apUnused /* Function arguments */
222457 ){
222458 assert( nArg==0 );
222459 UNUSED_PARAM2(nArg, apUnused);
222460 sqlite3_result_text(pCtx, "fts5: 2019-12-26 01:10:17 f482a4cdfa768941e22c399de8ec29a55e729529eeae86d3832077ad1bef22f3", -1, SQLITE_TRANSIENT);
222461 }
222462
222463 /*
222464 ** Return true if zName is the extension on one of the shadow tables used
222465 ** by this module.
@@ -222593,14 +223202,15 @@
223202 sqlite3Fts5BufferZero(&buf);
223203 rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 0, iRowid);
223204 for(ctx.iCol=0; rc==SQLITE_OK && ctx.iCol<pConfig->nCol; ctx.iCol++){
223205 ctx.szCol = 0;
223206 if( pConfig->abUnindexed[ctx.iCol]==0 ){
223207 const char *zText = (const char*)sqlite3_column_text(pScan, ctx.iCol+1);
223208 int nText = sqlite3_column_bytes(pScan, ctx.iCol+1);
223209 rc = sqlite3Fts5Tokenize(pConfig,
223210 FTS5_TOKENIZE_DOCUMENT,
223211 zText, nText,
 
223212 (void*)&ctx,
223213 fts5StorageInsertCallback
223214 );
223215 }
223216 sqlite3Fts5BufferAppendVarint(&rc, &buf, ctx.szCol);
@@ -222718,14 +223328,15 @@
223328 rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 0, iRowid);
223329 }
223330 for(ctx.iCol=0; rc==SQLITE_OK && ctx.iCol<pConfig->nCol; ctx.iCol++){
223331 ctx.szCol = 0;
223332 if( pConfig->abUnindexed[ctx.iCol]==0 ){
223333 const char *zText = (const char*)sqlite3_value_text(apVal[ctx.iCol+2]);
223334 int nText = sqlite3_value_bytes(apVal[ctx.iCol+2]);
223335 rc = sqlite3Fts5Tokenize(pConfig,
223336 FTS5_TOKENIZE_DOCUMENT,
223337 zText, nText,
 
223338 (void*)&ctx,
223339 fts5StorageInsertCallback
223340 );
223341 }
223342 sqlite3Fts5BufferAppendVarint(&rc, &buf, ctx.szCol);
@@ -222890,14 +223501,15 @@
223501 ctx.szCol = 0;
223502 if( pConfig->eDetail==FTS5_DETAIL_COLUMNS ){
223503 rc = sqlite3Fts5TermsetNew(&ctx.pTermset);
223504 }
223505 if( rc==SQLITE_OK ){
223506 const char *zText = (const char*)sqlite3_column_text(pScan, i+1);
223507 int nText = sqlite3_column_bytes(pScan, i+1);
223508 rc = sqlite3Fts5Tokenize(pConfig,
223509 FTS5_TOKENIZE_DOCUMENT,
223510 zText, nText,
 
223511 (void*)&ctx,
223512 fts5StorageIntegrityCallback
223513 );
223514 }
223515 if( rc==SQLITE_OK && pConfig->bColumnsize && ctx.szCol!=aColSize[i] ){
@@ -226616,12 +227228,12 @@
227228 }
227229 #endif /* SQLITE_CORE */
227230 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
227231
227232 /************** End of stmt.c ************************************************/
227233 #if __LINE__!=227233
227234 #undef SQLITE_SOURCE_ID
227235 #define SQLITE_SOURCE_ID "2019-12-26 01:10:17 f482a4cdfa768941e22c399de8ec29a55e729529eeae86d3832077ad1befalt2"
227236 #endif
227237 /* Return the source-id for this library */
227238 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
227239 /************************** End of sqlite3.c ******************************/
227240
+88 -88
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.31.0"
127127
#define SQLITE_VERSION_NUMBER 3031000
128
-#define SQLITE_SOURCE_ID "2019-11-20 13:31:52 a0f6d526baecd061a5e2bec5eb698fb5dfb10122ac79c853d7b3f4a48bc9f49b"
128
+#define SQLITE_SOURCE_ID "2019-12-26 01:10:17 f482a4cdfa768941e22c399de8ec29a55e729529eeae86d3832077ad1bef22f3"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -539,10 +539,11 @@
539539
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
540540
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
541541
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
542542
#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
543543
#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
544
+#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8))
544545
545546
/*
546547
** CAPI3REF: Flags For File Open Operations
547548
**
548549
** These bit values are intended for use in the
@@ -979,20 +980,20 @@
979980
**
980981
** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
981982
** ^The [SQLITE_FCNTL_BUSYHANDLER]
982983
** file-control may be invoked by SQLite on the database file handle
983984
** shortly after it is opened in order to provide a custom VFS with access
984
-** to the connections busy-handler callback. The argument is of type (void **)
985
+** to the connection's busy-handler callback. The argument is of type (void**)
985986
** - an array of two (void *) values. The first (void *) actually points
986
-** to a function of type (int (*)(void *)). In order to invoke the connections
987
+** to a function of type (int (*)(void *)). In order to invoke the connection's
987988
** busy-handler, this function should be invoked with the second (void *) in
988989
** the array as the only argument. If it returns non-zero, then the operation
989990
** should be retried. If it returns zero, the custom VFS should abandon the
990991
** current operation.
991992
**
992993
** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
993
-** ^Application can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
994
+** ^Applications can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
994995
** to have SQLite generate a
995996
** temporary filename using the same algorithm that is followed to generate
996997
** temporary filenames for TEMP tables and other internal uses. The
997998
** argument should be a char** which will be filled with the filename
998999
** written into memory obtained from [sqlite3_malloc()]. The caller should
@@ -1101,11 +1102,11 @@
11011102
** interface can be used to find if any database on the connection has changed,
11021103
** but that interface responds to changes on TEMP as well as MAIN and does
11031104
** not provide a mechanism to detect changes to MAIN only. Also, the
11041105
** [sqlite3_total_changes()] interface responds to internal changes only and
11051106
** omits changes made by other database connections. The
1106
-** [PRAGMA data_version] command provide a mechanism to detect changes to
1107
+** [PRAGMA data_version] command provides a mechanism to detect changes to
11071108
** a single attached database that occur due to other database connections,
11081109
** but omits changes implemented by the database connection on which it is
11091110
** called. This file control is the only mechanism to detect changes that
11101111
** happen either internally or externally and that are associated with
11111112
** a particular attached database.
@@ -1189,14 +1190,14 @@
11891190
** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
11901191
** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
11911192
** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6]. Additional fields
11921193
** may be appended to the sqlite3_vfs object and the iVersion value
11931194
** may increase again in future versions of SQLite.
1194
-** Note that the structure
1195
-** of the sqlite3_vfs object changes in the transition from
1195
+** Note that due to an oversight, the structure
1196
+** of the sqlite3_vfs object changed in the transition from
11961197
** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
1197
-** and yet the iVersion field was not modified.
1198
+** and yet the iVersion field was not increased.
11981199
**
11991200
** The szOsFile field is the size of the subclassed [sqlite3_file]
12001201
** structure used by this VFS. mxPathname is the maximum length of
12011202
** a pathname in this VFS.
12021203
**
@@ -1283,11 +1284,11 @@
12831284
** be created, and that it is an error if it already exists.
12841285
** It is <i>not</i> used to indicate the file should be opened
12851286
** for exclusive access.
12861287
**
12871288
** ^At least szOsFile bytes of memory are allocated by SQLite
1288
-** to hold the [sqlite3_file] structure passed as the third
1289
+** to hold the [sqlite3_file] structure passed as the third
12891290
** argument to xOpen. The xOpen method does not have to
12901291
** allocate the structure; it should just fill it in. Note that
12911292
** the xOpen method must set the sqlite3_file.pMethods to either
12921293
** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
12931294
** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
@@ -1406,11 +1407,10 @@
14061407
** SQLite.
14071408
*/
14081409
#define SQLITE_ACCESS_EXISTS 0
14091410
#define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */
14101411
#define SQLITE_ACCESS_READ 2 /* Unused */
1411
-#define SQLITE_ACCESS_SYMLINK 3 /* Test if file is symbolic link */
14121412
14131413
/*
14141414
** CAPI3REF: Flags for the xShmLock VFS method
14151415
**
14161416
** These integer constants define the various locking operations
@@ -1621,11 +1621,11 @@
16211621
** Every memory allocation request coming in through [sqlite3_malloc()]
16221622
** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
16231623
** that causes the corresponding memory allocation to fail.
16241624
**
16251625
** The xInit method initializes the memory allocator. For example,
1626
-** it might allocate any require mutexes or initialize internal data
1626
+** it might allocate any required mutexes or initialize internal data
16271627
** structures. The xShutdown method is invoked (indirectly) by
16281628
** [sqlite3_shutdown()] and should deallocate any resources acquired
16291629
** by xInit. The pAppData pointer is used as the only parameter to
16301630
** xInit and xShutdown.
16311631
**
@@ -1762,11 +1762,11 @@
17621762
**
17631763
** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
17641764
** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
17651765
** that SQLite can use for the database page cache with the default page
17661766
** cache implementation.
1767
-** This configuration option is a no-op if an application-define page
1767
+** This configuration option is a no-op if an application-defined page
17681768
** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2].
17691769
** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
17701770
** 8-byte aligned memory (pMem), the size of each page cache line (sz),
17711771
** and the number of cache lines (N).
17721772
** The sz argument should be the size of the largest database page
@@ -2247,11 +2247,11 @@
22472247
** </dd>
22482248
**
22492249
** [[SQLITE_DBCONFIG_DQS_DML]]
22502250
** <dt>SQLITE_DBCONFIG_DQS_DML</td>
22512251
** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
2252
-** the legacy [double-quoted string literal] misfeature for DML statement
2252
+** the legacy [double-quoted string literal] misfeature for DML statements
22532253
** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The
22542254
** default value of this setting is determined by the [-DSQLITE_DQS]
22552255
** compile-time option.
22562256
** </dd>
22572257
**
@@ -2508,11 +2508,11 @@
25082508
** will be rolled back automatically.
25092509
**
25102510
** ^The sqlite3_interrupt(D) call is in effect until all currently running
25112511
** SQL statements on [database connection] D complete. ^Any new SQL statements
25122512
** that are started after the sqlite3_interrupt() call and before the
2513
-** running statements reaches zero are interrupted as if they had been
2513
+** running statement count reaches zero are interrupted as if they had been
25142514
** running prior to the sqlite3_interrupt() call. ^New SQL statements
25152515
** that are started after the running statement count reaches zero are
25162516
** not effected by the sqlite3_interrupt().
25172517
** ^A call to sqlite3_interrupt(D) that occurs when there are no running
25182518
** SQL statements is a no-op and has no effect on SQL statements
@@ -2676,13 +2676,13 @@
26762676
** Alice | 43
26772677
** Bob | 28
26782678
** Cindy | 21
26792679
** </pre></blockquote>
26802680
**
2681
-** There are two column (M==2) and three rows (N==3). Thus the
2681
+** There are two columns (M==2) and three rows (N==3). Thus the
26822682
** result table has 8 entries. Suppose the result table is stored
2683
-** in an array names azResult. Then azResult holds this content:
2683
+** in an array named azResult. Then azResult holds this content:
26842684
**
26852685
** <blockquote><pre>
26862686
** azResult&#91;0] = "Name";
26872687
** azResult&#91;1] = "Age";
26882688
** azResult&#91;2] = "Alice";
@@ -2832,23 +2832,10 @@
28322832
** sqlite3_malloc64(), and sqlite3_realloc64()
28332833
** is always aligned to at least an 8 byte boundary, or to a
28342834
** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
28352835
** option is used.
28362836
**
2837
-** In SQLite version 3.5.0 and 3.5.1, it was possible to define
2838
-** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
2839
-** implementation of these routines to be omitted. That capability
2840
-** is no longer provided. Only built-in memory allocators can be used.
2841
-**
2842
-** Prior to SQLite version 3.7.10, the Windows OS interface layer called
2843
-** the system malloc() and free() directly when converting
2844
-** filenames between the UTF-8 encoding used by SQLite
2845
-** and whatever filename encoding is used by the particular Windows
2846
-** installation. Memory allocation errors were detected, but
2847
-** they were reported back as [SQLITE_CANTOPEN] or
2848
-** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
2849
-**
28502837
** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
28512838
** must be either NULL or else pointers obtained from a prior
28522839
** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
28532840
** not yet been released.
28542841
**
@@ -2893,11 +2880,11 @@
28932880
** CAPI3REF: Pseudo-Random Number Generator
28942881
**
28952882
** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
28962883
** select random [ROWID | ROWIDs] when inserting new records into a table that
28972884
** already uses the largest possible [ROWID]. The PRNG is also used for
2898
-** the build-in random() and randomblob() SQL functions. This interface allows
2885
+** the built-in random() and randomblob() SQL functions. This interface allows
28992886
** applications to access the same PRNG for other purposes.
29002887
**
29012888
** ^A call to this routine stores N bytes of randomness into buffer P.
29022889
** ^The P parameter can be a NULL pointer.
29032890
**
@@ -3494,11 +3481,11 @@
34943481
** a VFS implementation when the flags parameter to xOpen() has one or
34953482
** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and
34963483
** P is the name of the query parameter, then
34973484
** sqlite3_uri_parameter(F,P) returns the value of the P
34983485
** parameter if it exists or a NULL pointer if P does not appear as a
3499
-** query parameter on F. If P is a query parameter of F
3486
+** query parameter on F. If P is a query parameter of F and it
35003487
** has no explicit value, then sqlite3_uri_parameter(F,P) returns
35013488
** a pointer to an empty string.
35023489
**
35033490
** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
35043491
** parameter and returns true (1) or false (0) according to the value
@@ -3506,11 +3493,11 @@
35063493
** value of query parameter P is one of "yes", "true", or "on" in any
35073494
** case or if the value begins with a non-zero number. The
35083495
** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
35093496
** query parameter P is one of "no", "false", or "off" in any case or
35103497
** if the value begins with a numeric zero. If P is not a query
3511
-** parameter on F or if the value of P is does not match any of the
3498
+** parameter on F or if the value of P does not match any of the
35123499
** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
35133500
**
35143501
** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
35153502
** 64-bit signed integer and returns that integer, or D if P does not
35163503
** exist. If the value of P is something other than an integer, then
@@ -3843,16 +3830,16 @@
38433830
** in order to find the underlying cause of the problem. With the "v2" prepare
38443831
** interfaces, the underlying reason for the error is returned immediately.
38453832
** </li>
38463833
**
38473834
** <li>
3848
-** ^If the specific value bound to [parameter | host parameter] in the
3835
+** ^If the specific value bound to a [parameter | host parameter] in the
38493836
** WHERE clause might influence the choice of query plan for a statement,
38503837
** then the statement will be automatically recompiled, as if there had been
3851
-** a schema change, on the first [sqlite3_step()] call following any change
3838
+** a schema change, on the first [sqlite3_step()] call following any change
38523839
** to the [sqlite3_bind_text | bindings] of that [parameter].
3853
-** ^The specific value of WHERE-clause [parameter] might influence the
3840
+** ^The specific value of a WHERE-clause [parameter] might influence the
38543841
** choice of query plan if the parameter is the left-hand side of a [LIKE]
38553842
** or [GLOB] operator or if the parameter is compared to an indexed column
38563843
** and the [SQLITE_ENABLE_STAT4] compile-time option is enabled.
38573844
** </li>
38583845
** </ol>
@@ -4357,24 +4344,20 @@
43574344
** the statement, where N is the second function argument.
43584345
** ^The left-most column is column 0 for these routines.
43594346
**
43604347
** ^If the Nth column returned by the statement is an expression or
43614348
** subquery and is not a column value, then all of these functions return
4362
-** NULL. ^These routine might also return NULL if a memory allocation error
4349
+** NULL. ^These routines might also return NULL if a memory allocation error
43634350
** occurs. ^Otherwise, they return the name of the attached database, table,
43644351
** or column that query result column was extracted from.
43654352
**
43664353
** ^As with all other SQLite APIs, those whose names end with "16" return
43674354
** UTF-16 encoded strings and the other functions return UTF-8.
43684355
**
43694356
** ^These APIs are only available if the library was compiled with the
43704357
** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
43714358
**
4372
-** If two or more threads call one or more of these routines against the same
4373
-** prepared statement and column at the same time then the results are
4374
-** undefined.
4375
-**
43764359
** If two or more threads call one or more
43774360
** [sqlite3_column_database_name | column metadata interfaces]
43784361
** for the same [prepared statement] and result column
43794362
** at the same time then the results are undefined.
43804363
*/
@@ -4507,11 +4490,11 @@
45074490
** METHOD: sqlite3_stmt
45084491
**
45094492
** ^The sqlite3_data_count(P) interface returns the number of columns in the
45104493
** current row of the result set of [prepared statement] P.
45114494
** ^If prepared statement P does not have results ready to return
4512
-** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
4495
+** (via calls to the [sqlite3_column_int | sqlite3_column()] family of
45134496
** interfaces) then sqlite3_data_count(P) returns 0.
45144497
** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
45154498
** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
45164499
** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
45174500
** will return non-zero if previous call to [sqlite3_step](P) returned
@@ -5009,13 +4992,16 @@
50094992
** These constants may be ORed together with the
50104993
** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
50114994
** to [sqlite3_create_function()], [sqlite3_create_function16()], or
50124995
** [sqlite3_create_function_v2()].
50134996
**
5014
-** The SQLITE_DETERMINISTIC flag means that the new function will always
5015
-** maps the same inputs into the same output. The abs() function is
5016
-** deterministic, for example, but randomblob() is not.
4997
+** The SQLITE_DETERMINISTIC flag means that the new function always gives
4998
+** the same output when the input parameters are the same. The abs() function
4999
+** is deterministic, for example, but randomblob() is not. Functions must
5000
+** be deterministic in order to be used in certain contexts such as
5001
+** [CHECK constraints] or [generated columns]. SQLite might also optimize
5002
+** deterministic functions by factoring them out of inner loops.
50175003
**
50185004
** The SQLITE_DIRECTONLY flag means that the function may only be invoked
50195005
** from top-level SQL, and cannot be used in VIEWs or TRIGGERs. This is
50205006
** a security feature which is recommended for all
50215007
** [application-defined SQL functions] that have side-effects. This flag
@@ -5090,12 +5076,12 @@
50905076
**
50915077
** <b>Details:</b>
50925078
**
50935079
** These routines extract type, size, and content information from
50945080
** [protected sqlite3_value] objects. Protected sqlite3_value objects
5095
-** are used to pass parameter information into implementation of
5096
-** [application-defined SQL functions] and [virtual tables].
5081
+** are used to pass parameter information into the functions that
5082
+** implement [application-defined SQL functions] and [virtual tables].
50975083
**
50985084
** These routines work only with [protected sqlite3_value] objects.
50995085
** Any attempt to use these routines on an [unprotected sqlite3_value]
51005086
** is not threadsafe.
51015087
**
@@ -5148,11 +5134,11 @@
51485134
** the return value is arbitrary and meaningless.
51495135
**
51505136
** ^The sqlite3_value_frombind(X) interface returns non-zero if the
51515137
** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()]
51525138
** interfaces. ^If X comes from an SQL literal value, or a table column,
5153
-** and expression, then sqlite3_value_frombind(X) returns zero.
5139
+** or an expression, then sqlite3_value_frombind(X) returns zero.
51545140
**
51555141
** Please pay particular attention to the fact that the pointer returned
51565142
** from [sqlite3_value_blob()], [sqlite3_value_text()], or
51575143
** [sqlite3_value_text16()] can be invalidated by a subsequent call to
51585144
** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
@@ -5234,12 +5220,12 @@
52345220
**
52355221
** Implementations of aggregate SQL functions use this
52365222
** routine to allocate memory for storing their state.
52375223
**
52385224
** ^The first time the sqlite3_aggregate_context(C,N) routine is called
5239
-** for a particular aggregate function, SQLite
5240
-** allocates N of memory, zeroes out that memory, and returns a pointer
5225
+** for a particular aggregate function, SQLite allocates
5226
+** N bytes of memory, zeroes out that memory, and returns a pointer
52415227
** to the new memory. ^On second and subsequent calls to
52425228
** sqlite3_aggregate_context() for the same aggregate function instance,
52435229
** the same buffer is returned. Sqlite3_aggregate_context() is normally
52445230
** called once for each invocation of the xStep callback and then one
52455231
** last time when the xFinal callback is invoked. ^(When no rows match
@@ -5252,11 +5238,11 @@
52525238
** when first called if N is less than or equal to zero or if a memory
52535239
** allocate error occurs.
52545240
**
52555241
** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
52565242
** determined by the N parameter on first successful call. Changing the
5257
-** value of N in subsequent call to sqlite3_aggregate_context() within
5243
+** value of N in any subsequents call to sqlite3_aggregate_context() within
52585244
** the same aggregate function instance will not resize the memory
52595245
** allocation.)^ Within the xFinal callback, it is customary to set
52605246
** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
52615247
** pointless memory allocations occur.
52625248
**
@@ -5600,11 +5586,11 @@
56005586
** <li> If A&lt;B THEN B&gt;A.
56015587
** <li> If A&lt;B and B&lt;C then A&lt;C.
56025588
** </ol>
56035589
**
56045590
** If a collating function fails any of the above constraints and that
5605
-** collating function is registered and used, then the behavior of SQLite
5591
+** collating function is registered and used, then the behavior of SQLite
56065592
** is undefined.
56075593
**
56085594
** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
56095595
** with the addition that the xDestroy callback is invoked on pArg when
56105596
** the collating function is deleted.
@@ -5927,15 +5913,19 @@
59275913
59285914
/*
59295915
** CAPI3REF: Return The Filename For A Database Connection
59305916
** METHOD: sqlite3
59315917
**
5932
-** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
5933
-** associated with database N of connection D. ^The main database file
5934
-** has the name "main". If there is no attached database N on the database
5918
+** ^The sqlite3_db_filename(D,N) interface returns a pointer to the filename
5919
+** associated with database N of connection D.
5920
+** ^If there is no attached database N on the database
59355921
** connection D, or if database N is a temporary or in-memory database, then
59365922
** this function will return either a NULL pointer or an empty string.
5923
+**
5924
+** ^The string value returned by this routine is owned and managed by
5925
+** the database connection. ^The value will be valid until the database N
5926
+** is [DETACH]-ed or until the database connection closes.
59375927
**
59385928
** ^The filename returned by this function is the output of the
59395929
** xFullPathname method of the [VFS]. ^In other words, the filename
59405930
** will be an absolute pathname, even if the filename used
59415931
** to open the database originally was a URI or relative pathname.
@@ -6086,19 +6076,23 @@
60866076
** In prior versions of SQLite,
60876077
** sharing was enabled or disabled for each thread separately.
60886078
**
60896079
** ^(The cache sharing mode set by this interface effects all subsequent
60906080
** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
6091
-** Existing database connections continue use the sharing mode
6081
+** Existing database connections continue to use the sharing mode
60926082
** that was in effect at the time they were opened.)^
60936083
**
60946084
** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
60956085
** successfully. An [error code] is returned otherwise.)^
60966086
**
6097
-** ^Shared cache is disabled by default. But this might change in
6098
-** future releases of SQLite. Applications that care about shared
6099
-** cache setting should set it explicitly.
6087
+** ^Shared cache is disabled by default. It is recommended that it stay
6088
+** that way. In other words, do not use this routine. This interface
6089
+** continues to be provided for historical compatibility, but its use is
6090
+** discouraged. Any use of shared cache is discouraged. If shared cache
6091
+** must be used, it is recommended that shared cache only be enabled for
6092
+** individual database connections using the [sqlite3_open_v2()] interface
6093
+** with the [SQLITE_OPEN_SHAREDCACHE] flag.
61006094
**
61016095
** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0
61026096
** and will always return SQLITE_MISUSE. On those systems,
61036097
** shared cache mode should be enabled per-database connection via
61046098
** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
@@ -6227,11 +6221,11 @@
62276221
** information about column C of table T in database D
62286222
** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
62296223
** interface returns SQLITE_OK and fills in the non-NULL pointers in
62306224
** the final five arguments with appropriate values if the specified
62316225
** column exists. ^The sqlite3_table_column_metadata() interface returns
6232
-** SQLITE_ERROR and if the specified column does not exist.
6226
+** SQLITE_ERROR if the specified column does not exist.
62336227
** ^If the column-name parameter to sqlite3_table_column_metadata() is a
62346228
** NULL pointer, then this routine simply checks for the existence of the
62356229
** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
62366230
** does not. If the table name parameter T in a call to
62376231
** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is
@@ -6369,11 +6363,11 @@
63696363
** [sqlite3_load_extension()] and the SQL function [load_extension()].
63706364
** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
63716365
** to enable or disable only the C-API.)^
63726366
**
63736367
** <b>Security warning:</b> It is recommended that extension loading
6374
-** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
6368
+** be enabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
63756369
** rather than this interface, so the [load_extension()] SQL function
63766370
** remains disabled. This will prevent SQL injections from giving attackers
63776371
** access to extension loading capabilities.
63786372
*/
63796373
SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
@@ -6456,11 +6450,11 @@
64566450
/*
64576451
** CAPI3REF: Virtual Table Object
64586452
** KEYWORDS: sqlite3_module {virtual table module}
64596453
**
64606454
** This structure, sometimes called a "virtual table module",
6461
-** defines the implementation of a [virtual tables].
6455
+** defines the implementation of a [virtual table].
64626456
** This structure consists mostly of methods for the module.
64636457
**
64646458
** ^A virtual table module is created by filling in a persistent
64656459
** instance of this structure and passing a pointer to that instance
64666460
** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
@@ -6553,11 +6547,17 @@
65536547
** The [xBestIndex] method must fill aConstraintUsage[] with information
65546548
** about what parameters to pass to xFilter. ^If argvIndex>0 then
65556549
** the right-hand side of the corresponding aConstraint[] is evaluated
65566550
** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
65576551
** is true, then the constraint is assumed to be fully handled by the
6558
-** virtual table and is not checked again by SQLite.)^
6552
+** virtual table and might not be checked again by the byte code.)^ ^(The
6553
+** aConstraintUsage[].omit flag is an optimization hint. When the omit flag
6554
+** is left in its default setting of false, the constraint will always be
6555
+** checked separately in byte code. If the omit flag is change to true, then
6556
+** the constraint may or may not be checked in byte code. In other words,
6557
+** when the omit flag is true there is no guarantee that the constraint will
6558
+** not be checked again using byte code.)^
65596559
**
65606560
** ^The idxNum and idxPtr values are recorded and passed into the
65616561
** [xFilter] method.
65626562
** ^[sqlite3_free()] is used to free idxPtr if and only if
65636563
** needToFreeIdxPtr is true.
@@ -6593,11 +6593,11 @@
65936593
** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
65946594
** structure for SQLite [version 3.8.2] ([dateof:3.8.2]).
65956595
** If a virtual table extension is
65966596
** used with an SQLite version earlier than 3.8.2, the results of attempting
65976597
** to read or write the estimatedRows field are undefined (but are likely
6598
-** to included crashing the application). The estimatedRows field should
6598
+** to include crashing the application). The estimatedRows field should
65996599
** therefore only be used if [sqlite3_libversion_number()] returns a
66006600
** value greater than or equal to 3008002. Similarly, the idxFlags field
66016601
** was added for [version 3.9.0] ([dateof:3.9.0]).
66026602
** It may therefore only be used if
66036603
** sqlite3_libversion_number() returns a value greater than or equal to
@@ -6645,11 +6645,11 @@
66456645
#define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */
66466646
66476647
/*
66486648
** CAPI3REF: Virtual Table Constraint Operator Codes
66496649
**
6650
-** These macros defined the allowed values for the
6650
+** These macros define the allowed values for the
66516651
** [sqlite3_index_info].aConstraint[].op field. Each value represents
66526652
** an operator that is part of a constraint term in the wHERE clause of
66536653
** a query that uses a [virtual table].
66546654
*/
66556655
#define SQLITE_INDEX_CONSTRAINT_EQ 2
@@ -7255,11 +7255,11 @@
72557255
** </ul>)^
72567256
**
72577257
** The only difference is that the public sqlite3_XXX functions enumerated
72587258
** above silently ignore any invocations that pass a NULL pointer instead
72597259
** of a valid mutex handle. The implementations of the methods defined
7260
-** by this structure are not required to handle this case, the results
7260
+** by this structure are not required to handle this case. The results
72617261
** of passing a NULL pointer instead of a valid mutex handle are undefined
72627262
** (i.e. it is acceptable to provide an implementation that segfaults if
72637263
** it is passed a NULL pointer).
72647264
**
72657265
** The xMutexInit() method must be threadsafe. It must be harmless to
@@ -7728,11 +7728,11 @@
77287728
** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
77297729
** no space was left in the page cache.</dd>)^
77307730
**
77317731
** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
77327732
** <dd>This parameter records the largest memory allocation request
7733
-** handed to [pagecache memory allocator]. Only the value returned in the
7733
+** handed to the [pagecache memory allocator]. Only the value returned in the
77347734
** *pHighwater parameter to [sqlite3_status()] is of interest.
77357735
** The value written into the *pCurrent parameter is undefined.</dd>)^
77367736
**
77377737
** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt>
77387738
** <dd>No longer used.</dd>
@@ -7804,11 +7804,11 @@
78047804
** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
78057805
** <dd>This parameter returns the number of lookaside memory slots currently
78067806
** checked out.</dd>)^
78077807
**
78087808
** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
7809
-** <dd>This parameter returns the number malloc attempts that were
7809
+** <dd>This parameter returns the number of malloc attempts that were
78107810
** satisfied using lookaside memory. Only the high-water value is meaningful;
78117811
** the current value is always zero.)^
78127812
**
78137813
** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
78147814
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
@@ -7886,11 +7886,11 @@
78867886
** <dd>This parameter returns the number of dirty cache entries that have
78877887
** been written to disk in the middle of a transaction due to the page
78887888
** cache overflowing. Transactions are more efficient if they are written
78897889
** to disk all at once. When pages spill mid-transaction, that introduces
78907890
** additional overhead. This parameter can be used help identify
7891
-** inefficiencies that can be resolve by increasing the cache size.
7891
+** inefficiencies that can be resolved by increasing the cache size.
78927892
** </dd>
78937893
**
78947894
** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
78957895
** <dd>This parameter returns zero for the current value if and only if
78967896
** all foreign key constraints (deferred or immediate) have been
@@ -7975,11 +7975,11 @@
79757975
** If the number of virtual machine operations exceeds 2147483647
79767976
** then the value returned by this statement status code is undefined.
79777977
**
79787978
** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
79797979
** <dd>^This is the number of times that the prepare statement has been
7980
-** automatically regenerated due to schema changes or change to
7980
+** automatically regenerated due to schema changes or changes to
79817981
** [bound parameters] that might affect the query plan.
79827982
**
79837983
** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
79847984
** <dd>^This is the number of times that the prepared statement has
79857985
** been run. A single "run" for the purposes of this counter is one
@@ -8146,11 +8146,11 @@
81468146
** NULL if allocating a new page is effectively impossible.
81478147
** </table>
81488148
**
81498149
** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
81508150
** will only use a createFlag of 2 after a prior call with a createFlag of 1
8151
-** failed.)^ In between the to xFetch() calls, SQLite may
8151
+** failed.)^ In between the xFetch() calls, SQLite may
81528152
** attempt to unpin one or more cache pages by spilling the content of
81538153
** pinned pages to disk and synching the operating system disk cache.
81548154
**
81558155
** [[the xUnpin() page cache method]]
81568156
** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
@@ -8464,11 +8464,11 @@
84648464
** application receives an SQLITE_LOCKED error, it may call the
84658465
** sqlite3_unlock_notify() method with the blocked connection handle as
84668466
** the first argument to register for a callback that will be invoked
84678467
** when the blocking connections current transaction is concluded. ^The
84688468
** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
8469
-** call that concludes the blocking connections transaction.
8469
+** call that concludes the blocking connection's transaction.
84708470
**
84718471
** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
84728472
** there is a chance that the blocking connection will have already
84738473
** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
84748474
** If this happens, then the specified callback is invoked immediately,
@@ -8502,11 +8502,11 @@
85028502
** However, the signature of the callback function allows SQLite to pass
85038503
** it an array of void* context pointers. The first argument passed to
85048504
** an unlock-notify callback is a pointer to an array of void* pointers,
85058505
** and the second is the number of entries in the array.
85068506
**
8507
-** When a blocking connections transaction is concluded, there may be
8507
+** When a blocking connection's transaction is concluded, there may be
85088508
** more than one blocked connection that has registered for an unlock-notify
85098509
** callback. ^If two or more such blocked connections have specified the
85108510
** same callback function, then instead of invoking the callback function
85118511
** multiple times, it is invoked once with the set of void* context pointers
85128512
** specified by the blocked connections bundled together into an array.
@@ -8976,37 +8976,37 @@
89768976
** managed by the prepared statement S and will be automatically freed when
89778977
** S is finalized.
89788978
**
89798979
** <dl>
89808980
** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
8981
-** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
8981
+** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be
89828982
** set to the total number of times that the X-th loop has run.</dd>
89838983
**
89848984
** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
8985
-** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set
8985
+** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be set
89868986
** to the total number of rows examined by all iterations of the X-th loop.</dd>
89878987
**
89888988
** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
8989
-** <dd>^The "double" variable pointed to by the T parameter will be set to the
8989
+** <dd>^The "double" variable pointed to by the V parameter will be set to the
89908990
** query planner's estimate for the average number of rows output from each
89918991
** iteration of the X-th loop. If the query planner's estimates was accurate,
89928992
** then this value will approximate the quotient NVISIT/NLOOP and the
89938993
** product of this value for all prior loops with the same SELECTID will
89948994
** be the NLOOP value for the current loop.
89958995
**
89968996
** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
8997
-** <dd>^The "const char *" variable pointed to by the T parameter will be set
8997
+** <dd>^The "const char *" variable pointed to by the V parameter will be set
89988998
** to a zero-terminated UTF-8 string containing the name of the index or table
89998999
** used for the X-th loop.
90009000
**
90019001
** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
9002
-** <dd>^The "const char *" variable pointed to by the T parameter will be set
9002
+** <dd>^The "const char *" variable pointed to by the V parameter will be set
90039003
** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
90049004
** description for the X-th loop.
90059005
**
90069006
** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
9007
-** <dd>^The "int" variable pointed to by the T parameter will be set to the
9007
+** <dd>^The "int" variable pointed to by the V parameter will be set to the
90089008
** "select-id" for the X-th loop. The select-id identifies which query or
90099009
** subquery the loop is part of. The main query has a select-id of zero.
90109010
** The select-id is the same value as is output in the first column
90119011
** of an [EXPLAIN QUERY PLAN] query.
90129012
** </dl>
@@ -9857,11 +9857,11 @@
98579857
** METHOD: sqlite3_session
98589858
**
98599859
** The second argument (xFilter) is the "filter callback". For changes to rows
98609860
** in tables that are not attached to the Session object, the filter is called
98619861
** to determine whether changes to the table's rows should be tracked or not.
9862
-** If xFilter returns 0, changes is not tracked. Note that once a table is
9862
+** If xFilter returns 0, changes are not tracked. Note that once a table is
98639863
** attached, xFilter will not be called again.
98649864
*/
98659865
SQLITE_API void sqlite3session_table_filter(
98669866
sqlite3_session *pSession, /* Session object */
98679867
int(*xFilter)(
@@ -10031,11 +10031,11 @@
1003110031
** identical.
1003210032
**
1003310033
** It an error if database zFrom does not exist or does not contain the
1003410034
** required compatible table.
1003510035
**
10036
-** If the operation successful, SQLITE_OK is returned. Otherwise, an SQLite
10036
+** If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite
1003710037
** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
1003810038
** may be set to point to a buffer containing an English language error
1003910039
** message. It is the responsibility of the caller to free this buffer using
1004010040
** sqlite3_free().
1004110041
*/
@@ -10168,11 +10168,11 @@
1016810168
1016910169
/*
1017010170
** CAPI3REF: Advance A Changeset Iterator
1017110171
** METHOD: sqlite3_changeset_iter
1017210172
**
10173
-** This function may only be used with iterators created by function
10173
+** This function may only be used with iterators created by the function
1017410174
** [sqlite3changeset_start()]. If it is called on an iterator passed to
1017510175
** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE
1017610176
** is returned and the call has no effect.
1017710177
**
1017810178
** Immediately after an iterator is created by sqlite3changeset_start(), it
@@ -10584,12 +10584,12 @@
1058410584
** in the changegroup, then the number of columns and the position of the
1058510585
** primary key columns for the table must be consistent. If this is not the
1058610586
** case, this function fails with SQLITE_SCHEMA. If the input changeset
1058710587
** appears to be corrupt and the corruption is detected, SQLITE_CORRUPT is
1058810588
** returned. Or, if an out-of-memory condition occurs during processing, this
10589
-** function returns SQLITE_NOMEM. In all cases, if an error occurs the
10590
-** final contents of the changegroup is undefined.
10589
+** function returns SQLITE_NOMEM. In all cases, if an error occurs the state
10590
+** of the final contents of the changegroup is undefined.
1059110591
**
1059210592
** If no error occurs, SQLITE_OK is returned.
1059310593
*/
1059410594
SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
1059510595
@@ -10760,11 +10760,11 @@
1076010760
** [SQLITE_CHANGESET_REPLACE].
1076110761
** </dl>
1076210762
**
1076310763
** It is safe to execute SQL statements, including those that write to the
1076410764
** table that the callback related to, from within the xConflict callback.
10765
-** This can be used to further customize the applications conflict
10765
+** This can be used to further customize the application's conflict
1076610766
** resolution strategy.
1076710767
**
1076810768
** All changes made by these functions are enclosed in a savepoint transaction.
1076910769
** If any other error (aside from a constraint failure when attempting to
1077010770
** write to the target database) occurs, then the savepoint transaction is
@@ -11070,11 +11070,11 @@
1107011070
** CAPI3REF: Rebase a changeset
1107111071
** EXPERIMENTAL
1107211072
**
1107311073
** Argument pIn must point to a buffer containing a changeset nIn bytes
1107411074
** in size. This function allocates and populates a buffer with a copy
11075
-** of the changeset rebased rebased according to the configuration of the
11075
+** of the changeset rebased according to the configuration of the
1107611076
** rebaser object passed as the first argument. If successful, (*ppOut)
1107711077
** is set to point to the new buffer containing the rebased changeset and
1107811078
** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
1107911079
** responsibility of the caller to eventually free the new buffer using
1108011080
** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
@@ -11478,11 +11478,11 @@
1147811478
** the callback, an SQLite error code is returned.
1147911479
**
1148011480
**
1148111481
** xSetAuxdata(pFts5, pAux, xDelete)
1148211482
**
11483
-** Save the pointer passed as the second argument as the extension functions
11483
+** Save the pointer passed as the second argument as the extension function's
1148411484
** "auxiliary data". The pointer may then be retrieved by the current or any
1148511485
** future invocation of the same fts5 extension function made as part of
1148611486
** the same MATCH query using the xGetAuxdata() API.
1148711487
**
1148811488
** Each extension function is allocated a single auxiliary data slot for
@@ -11720,12 +11720,12 @@
1172011720
** all instances of "first place" or "1st place" regardless of which form
1172111721
** the user specified in the MATCH query text.
1172211722
**
1172311723
** There are several ways to approach this in FTS5:
1172411724
**
11725
-** <ol><li> By mapping all synonyms to a single token. In this case, the
11726
-** In the above example, this means that the tokenizer returns the
11725
+** <ol><li> By mapping all synonyms to a single token. In this case, using
11726
+** the above example, this means that the tokenizer returns the
1172711727
** same token for inputs "first" and "1st". Say that token is in
1172811728
** fact "first", so that when the user inserts the document "I won
1172911729
** 1st place" entries are added to the index for tokens "i", "won",
1173011730
** "first" and "place". If the user then queries for '1st + place',
1173111731
** the tokenizer substitutes "first" for "1st" and the query works
1173211732
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.31.0"
127 #define SQLITE_VERSION_NUMBER 3031000
128 #define SQLITE_SOURCE_ID "2019-11-20 13:31:52 a0f6d526baecd061a5e2bec5eb698fb5dfb10122ac79c853d7b3f4a48bc9f49b"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -539,10 +539,11 @@
539 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
540 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
541 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
542 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
543 #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
 
544
545 /*
546 ** CAPI3REF: Flags For File Open Operations
547 **
548 ** These bit values are intended for use in the
@@ -979,20 +980,20 @@
979 **
980 ** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
981 ** ^The [SQLITE_FCNTL_BUSYHANDLER]
982 ** file-control may be invoked by SQLite on the database file handle
983 ** shortly after it is opened in order to provide a custom VFS with access
984 ** to the connections busy-handler callback. The argument is of type (void **)
985 ** - an array of two (void *) values. The first (void *) actually points
986 ** to a function of type (int (*)(void *)). In order to invoke the connections
987 ** busy-handler, this function should be invoked with the second (void *) in
988 ** the array as the only argument. If it returns non-zero, then the operation
989 ** should be retried. If it returns zero, the custom VFS should abandon the
990 ** current operation.
991 **
992 ** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
993 ** ^Application can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
994 ** to have SQLite generate a
995 ** temporary filename using the same algorithm that is followed to generate
996 ** temporary filenames for TEMP tables and other internal uses. The
997 ** argument should be a char** which will be filled with the filename
998 ** written into memory obtained from [sqlite3_malloc()]. The caller should
@@ -1101,11 +1102,11 @@
1101 ** interface can be used to find if any database on the connection has changed,
1102 ** but that interface responds to changes on TEMP as well as MAIN and does
1103 ** not provide a mechanism to detect changes to MAIN only. Also, the
1104 ** [sqlite3_total_changes()] interface responds to internal changes only and
1105 ** omits changes made by other database connections. The
1106 ** [PRAGMA data_version] command provide a mechanism to detect changes to
1107 ** a single attached database that occur due to other database connections,
1108 ** but omits changes implemented by the database connection on which it is
1109 ** called. This file control is the only mechanism to detect changes that
1110 ** happen either internally or externally and that are associated with
1111 ** a particular attached database.
@@ -1189,14 +1190,14 @@
1189 ** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
1190 ** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
1191 ** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6]. Additional fields
1192 ** may be appended to the sqlite3_vfs object and the iVersion value
1193 ** may increase again in future versions of SQLite.
1194 ** Note that the structure
1195 ** of the sqlite3_vfs object changes in the transition from
1196 ** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
1197 ** and yet the iVersion field was not modified.
1198 **
1199 ** The szOsFile field is the size of the subclassed [sqlite3_file]
1200 ** structure used by this VFS. mxPathname is the maximum length of
1201 ** a pathname in this VFS.
1202 **
@@ -1283,11 +1284,11 @@
1283 ** be created, and that it is an error if it already exists.
1284 ** It is <i>not</i> used to indicate the file should be opened
1285 ** for exclusive access.
1286 **
1287 ** ^At least szOsFile bytes of memory are allocated by SQLite
1288 ** to hold the [sqlite3_file] structure passed as the third
1289 ** argument to xOpen. The xOpen method does not have to
1290 ** allocate the structure; it should just fill it in. Note that
1291 ** the xOpen method must set the sqlite3_file.pMethods to either
1292 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
1293 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
@@ -1406,11 +1407,10 @@
1406 ** SQLite.
1407 */
1408 #define SQLITE_ACCESS_EXISTS 0
1409 #define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */
1410 #define SQLITE_ACCESS_READ 2 /* Unused */
1411 #define SQLITE_ACCESS_SYMLINK 3 /* Test if file is symbolic link */
1412
1413 /*
1414 ** CAPI3REF: Flags for the xShmLock VFS method
1415 **
1416 ** These integer constants define the various locking operations
@@ -1621,11 +1621,11 @@
1621 ** Every memory allocation request coming in through [sqlite3_malloc()]
1622 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
1623 ** that causes the corresponding memory allocation to fail.
1624 **
1625 ** The xInit method initializes the memory allocator. For example,
1626 ** it might allocate any require mutexes or initialize internal data
1627 ** structures. The xShutdown method is invoked (indirectly) by
1628 ** [sqlite3_shutdown()] and should deallocate any resources acquired
1629 ** by xInit. The pAppData pointer is used as the only parameter to
1630 ** xInit and xShutdown.
1631 **
@@ -1762,11 +1762,11 @@
1762 **
1763 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1764 ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
1765 ** that SQLite can use for the database page cache with the default page
1766 ** cache implementation.
1767 ** This configuration option is a no-op if an application-define page
1768 ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2].
1769 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
1770 ** 8-byte aligned memory (pMem), the size of each page cache line (sz),
1771 ** and the number of cache lines (N).
1772 ** The sz argument should be the size of the largest database page
@@ -2247,11 +2247,11 @@
2247 ** </dd>
2248 **
2249 ** [[SQLITE_DBCONFIG_DQS_DML]]
2250 ** <dt>SQLITE_DBCONFIG_DQS_DML</td>
2251 ** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
2252 ** the legacy [double-quoted string literal] misfeature for DML statement
2253 ** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The
2254 ** default value of this setting is determined by the [-DSQLITE_DQS]
2255 ** compile-time option.
2256 ** </dd>
2257 **
@@ -2508,11 +2508,11 @@
2508 ** will be rolled back automatically.
2509 **
2510 ** ^The sqlite3_interrupt(D) call is in effect until all currently running
2511 ** SQL statements on [database connection] D complete. ^Any new SQL statements
2512 ** that are started after the sqlite3_interrupt() call and before the
2513 ** running statements reaches zero are interrupted as if they had been
2514 ** running prior to the sqlite3_interrupt() call. ^New SQL statements
2515 ** that are started after the running statement count reaches zero are
2516 ** not effected by the sqlite3_interrupt().
2517 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
2518 ** SQL statements is a no-op and has no effect on SQL statements
@@ -2676,13 +2676,13 @@
2676 ** Alice | 43
2677 ** Bob | 28
2678 ** Cindy | 21
2679 ** </pre></blockquote>
2680 **
2681 ** There are two column (M==2) and three rows (N==3). Thus the
2682 ** result table has 8 entries. Suppose the result table is stored
2683 ** in an array names azResult. Then azResult holds this content:
2684 **
2685 ** <blockquote><pre>
2686 ** azResult&#91;0] = "Name";
2687 ** azResult&#91;1] = "Age";
2688 ** azResult&#91;2] = "Alice";
@@ -2832,23 +2832,10 @@
2832 ** sqlite3_malloc64(), and sqlite3_realloc64()
2833 ** is always aligned to at least an 8 byte boundary, or to a
2834 ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
2835 ** option is used.
2836 **
2837 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
2838 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
2839 ** implementation of these routines to be omitted. That capability
2840 ** is no longer provided. Only built-in memory allocators can be used.
2841 **
2842 ** Prior to SQLite version 3.7.10, the Windows OS interface layer called
2843 ** the system malloc() and free() directly when converting
2844 ** filenames between the UTF-8 encoding used by SQLite
2845 ** and whatever filename encoding is used by the particular Windows
2846 ** installation. Memory allocation errors were detected, but
2847 ** they were reported back as [SQLITE_CANTOPEN] or
2848 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
2849 **
2850 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
2851 ** must be either NULL or else pointers obtained from a prior
2852 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
2853 ** not yet been released.
2854 **
@@ -2893,11 +2880,11 @@
2893 ** CAPI3REF: Pseudo-Random Number Generator
2894 **
2895 ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
2896 ** select random [ROWID | ROWIDs] when inserting new records into a table that
2897 ** already uses the largest possible [ROWID]. The PRNG is also used for
2898 ** the build-in random() and randomblob() SQL functions. This interface allows
2899 ** applications to access the same PRNG for other purposes.
2900 **
2901 ** ^A call to this routine stores N bytes of randomness into buffer P.
2902 ** ^The P parameter can be a NULL pointer.
2903 **
@@ -3494,11 +3481,11 @@
3494 ** a VFS implementation when the flags parameter to xOpen() has one or
3495 ** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and
3496 ** P is the name of the query parameter, then
3497 ** sqlite3_uri_parameter(F,P) returns the value of the P
3498 ** parameter if it exists or a NULL pointer if P does not appear as a
3499 ** query parameter on F. If P is a query parameter of F
3500 ** has no explicit value, then sqlite3_uri_parameter(F,P) returns
3501 ** a pointer to an empty string.
3502 **
3503 ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
3504 ** parameter and returns true (1) or false (0) according to the value
@@ -3506,11 +3493,11 @@
3506 ** value of query parameter P is one of "yes", "true", or "on" in any
3507 ** case or if the value begins with a non-zero number. The
3508 ** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
3509 ** query parameter P is one of "no", "false", or "off" in any case or
3510 ** if the value begins with a numeric zero. If P is not a query
3511 ** parameter on F or if the value of P is does not match any of the
3512 ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
3513 **
3514 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
3515 ** 64-bit signed integer and returns that integer, or D if P does not
3516 ** exist. If the value of P is something other than an integer, then
@@ -3843,16 +3830,16 @@
3843 ** in order to find the underlying cause of the problem. With the "v2" prepare
3844 ** interfaces, the underlying reason for the error is returned immediately.
3845 ** </li>
3846 **
3847 ** <li>
3848 ** ^If the specific value bound to [parameter | host parameter] in the
3849 ** WHERE clause might influence the choice of query plan for a statement,
3850 ** then the statement will be automatically recompiled, as if there had been
3851 ** a schema change, on the first [sqlite3_step()] call following any change
3852 ** to the [sqlite3_bind_text | bindings] of that [parameter].
3853 ** ^The specific value of WHERE-clause [parameter] might influence the
3854 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
3855 ** or [GLOB] operator or if the parameter is compared to an indexed column
3856 ** and the [SQLITE_ENABLE_STAT4] compile-time option is enabled.
3857 ** </li>
3858 ** </ol>
@@ -4357,24 +4344,20 @@
4357 ** the statement, where N is the second function argument.
4358 ** ^The left-most column is column 0 for these routines.
4359 **
4360 ** ^If the Nth column returned by the statement is an expression or
4361 ** subquery and is not a column value, then all of these functions return
4362 ** NULL. ^These routine might also return NULL if a memory allocation error
4363 ** occurs. ^Otherwise, they return the name of the attached database, table,
4364 ** or column that query result column was extracted from.
4365 **
4366 ** ^As with all other SQLite APIs, those whose names end with "16" return
4367 ** UTF-16 encoded strings and the other functions return UTF-8.
4368 **
4369 ** ^These APIs are only available if the library was compiled with the
4370 ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
4371 **
4372 ** If two or more threads call one or more of these routines against the same
4373 ** prepared statement and column at the same time then the results are
4374 ** undefined.
4375 **
4376 ** If two or more threads call one or more
4377 ** [sqlite3_column_database_name | column metadata interfaces]
4378 ** for the same [prepared statement] and result column
4379 ** at the same time then the results are undefined.
4380 */
@@ -4507,11 +4490,11 @@
4507 ** METHOD: sqlite3_stmt
4508 **
4509 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
4510 ** current row of the result set of [prepared statement] P.
4511 ** ^If prepared statement P does not have results ready to return
4512 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
4513 ** interfaces) then sqlite3_data_count(P) returns 0.
4514 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
4515 ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
4516 ** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
4517 ** will return non-zero if previous call to [sqlite3_step](P) returned
@@ -5009,13 +4992,16 @@
5009 ** These constants may be ORed together with the
5010 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
5011 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
5012 ** [sqlite3_create_function_v2()].
5013 **
5014 ** The SQLITE_DETERMINISTIC flag means that the new function will always
5015 ** maps the same inputs into the same output. The abs() function is
5016 ** deterministic, for example, but randomblob() is not.
 
 
 
5017 **
5018 ** The SQLITE_DIRECTONLY flag means that the function may only be invoked
5019 ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs. This is
5020 ** a security feature which is recommended for all
5021 ** [application-defined SQL functions] that have side-effects. This flag
@@ -5090,12 +5076,12 @@
5090 **
5091 ** <b>Details:</b>
5092 **
5093 ** These routines extract type, size, and content information from
5094 ** [protected sqlite3_value] objects. Protected sqlite3_value objects
5095 ** are used to pass parameter information into implementation of
5096 ** [application-defined SQL functions] and [virtual tables].
5097 **
5098 ** These routines work only with [protected sqlite3_value] objects.
5099 ** Any attempt to use these routines on an [unprotected sqlite3_value]
5100 ** is not threadsafe.
5101 **
@@ -5148,11 +5134,11 @@
5148 ** the return value is arbitrary and meaningless.
5149 **
5150 ** ^The sqlite3_value_frombind(X) interface returns non-zero if the
5151 ** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()]
5152 ** interfaces. ^If X comes from an SQL literal value, or a table column,
5153 ** and expression, then sqlite3_value_frombind(X) returns zero.
5154 **
5155 ** Please pay particular attention to the fact that the pointer returned
5156 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
5157 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
5158 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
@@ -5234,12 +5220,12 @@
5234 **
5235 ** Implementations of aggregate SQL functions use this
5236 ** routine to allocate memory for storing their state.
5237 **
5238 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
5239 ** for a particular aggregate function, SQLite
5240 ** allocates N of memory, zeroes out that memory, and returns a pointer
5241 ** to the new memory. ^On second and subsequent calls to
5242 ** sqlite3_aggregate_context() for the same aggregate function instance,
5243 ** the same buffer is returned. Sqlite3_aggregate_context() is normally
5244 ** called once for each invocation of the xStep callback and then one
5245 ** last time when the xFinal callback is invoked. ^(When no rows match
@@ -5252,11 +5238,11 @@
5252 ** when first called if N is less than or equal to zero or if a memory
5253 ** allocate error occurs.
5254 **
5255 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
5256 ** determined by the N parameter on first successful call. Changing the
5257 ** value of N in subsequent call to sqlite3_aggregate_context() within
5258 ** the same aggregate function instance will not resize the memory
5259 ** allocation.)^ Within the xFinal callback, it is customary to set
5260 ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
5261 ** pointless memory allocations occur.
5262 **
@@ -5600,11 +5586,11 @@
5600 ** <li> If A&lt;B THEN B&gt;A.
5601 ** <li> If A&lt;B and B&lt;C then A&lt;C.
5602 ** </ol>
5603 **
5604 ** If a collating function fails any of the above constraints and that
5605 ** collating function is registered and used, then the behavior of SQLite
5606 ** is undefined.
5607 **
5608 ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
5609 ** with the addition that the xDestroy callback is invoked on pArg when
5610 ** the collating function is deleted.
@@ -5927,15 +5913,19 @@
5927
5928 /*
5929 ** CAPI3REF: Return The Filename For A Database Connection
5930 ** METHOD: sqlite3
5931 **
5932 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
5933 ** associated with database N of connection D. ^The main database file
5934 ** has the name "main". If there is no attached database N on the database
5935 ** connection D, or if database N is a temporary or in-memory database, then
5936 ** this function will return either a NULL pointer or an empty string.
 
 
 
 
5937 **
5938 ** ^The filename returned by this function is the output of the
5939 ** xFullPathname method of the [VFS]. ^In other words, the filename
5940 ** will be an absolute pathname, even if the filename used
5941 ** to open the database originally was a URI or relative pathname.
@@ -6086,19 +6076,23 @@
6086 ** In prior versions of SQLite,
6087 ** sharing was enabled or disabled for each thread separately.
6088 **
6089 ** ^(The cache sharing mode set by this interface effects all subsequent
6090 ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
6091 ** Existing database connections continue use the sharing mode
6092 ** that was in effect at the time they were opened.)^
6093 **
6094 ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
6095 ** successfully. An [error code] is returned otherwise.)^
6096 **
6097 ** ^Shared cache is disabled by default. But this might change in
6098 ** future releases of SQLite. Applications that care about shared
6099 ** cache setting should set it explicitly.
 
 
 
 
6100 **
6101 ** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0
6102 ** and will always return SQLITE_MISUSE. On those systems,
6103 ** shared cache mode should be enabled per-database connection via
6104 ** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
@@ -6227,11 +6221,11 @@
6227 ** information about column C of table T in database D
6228 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
6229 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
6230 ** the final five arguments with appropriate values if the specified
6231 ** column exists. ^The sqlite3_table_column_metadata() interface returns
6232 ** SQLITE_ERROR and if the specified column does not exist.
6233 ** ^If the column-name parameter to sqlite3_table_column_metadata() is a
6234 ** NULL pointer, then this routine simply checks for the existence of the
6235 ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
6236 ** does not. If the table name parameter T in a call to
6237 ** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is
@@ -6369,11 +6363,11 @@
6369 ** [sqlite3_load_extension()] and the SQL function [load_extension()].
6370 ** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
6371 ** to enable or disable only the C-API.)^
6372 **
6373 ** <b>Security warning:</b> It is recommended that extension loading
6374 ** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
6375 ** rather than this interface, so the [load_extension()] SQL function
6376 ** remains disabled. This will prevent SQL injections from giving attackers
6377 ** access to extension loading capabilities.
6378 */
6379 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
@@ -6456,11 +6450,11 @@
6456 /*
6457 ** CAPI3REF: Virtual Table Object
6458 ** KEYWORDS: sqlite3_module {virtual table module}
6459 **
6460 ** This structure, sometimes called a "virtual table module",
6461 ** defines the implementation of a [virtual tables].
6462 ** This structure consists mostly of methods for the module.
6463 **
6464 ** ^A virtual table module is created by filling in a persistent
6465 ** instance of this structure and passing a pointer to that instance
6466 ** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
@@ -6553,11 +6547,17 @@
6553 ** The [xBestIndex] method must fill aConstraintUsage[] with information
6554 ** about what parameters to pass to xFilter. ^If argvIndex>0 then
6555 ** the right-hand side of the corresponding aConstraint[] is evaluated
6556 ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
6557 ** is true, then the constraint is assumed to be fully handled by the
6558 ** virtual table and is not checked again by SQLite.)^
 
 
 
 
 
 
6559 **
6560 ** ^The idxNum and idxPtr values are recorded and passed into the
6561 ** [xFilter] method.
6562 ** ^[sqlite3_free()] is used to free idxPtr if and only if
6563 ** needToFreeIdxPtr is true.
@@ -6593,11 +6593,11 @@
6593 ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
6594 ** structure for SQLite [version 3.8.2] ([dateof:3.8.2]).
6595 ** If a virtual table extension is
6596 ** used with an SQLite version earlier than 3.8.2, the results of attempting
6597 ** to read or write the estimatedRows field are undefined (but are likely
6598 ** to included crashing the application). The estimatedRows field should
6599 ** therefore only be used if [sqlite3_libversion_number()] returns a
6600 ** value greater than or equal to 3008002. Similarly, the idxFlags field
6601 ** was added for [version 3.9.0] ([dateof:3.9.0]).
6602 ** It may therefore only be used if
6603 ** sqlite3_libversion_number() returns a value greater than or equal to
@@ -6645,11 +6645,11 @@
6645 #define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */
6646
6647 /*
6648 ** CAPI3REF: Virtual Table Constraint Operator Codes
6649 **
6650 ** These macros defined the allowed values for the
6651 ** [sqlite3_index_info].aConstraint[].op field. Each value represents
6652 ** an operator that is part of a constraint term in the wHERE clause of
6653 ** a query that uses a [virtual table].
6654 */
6655 #define SQLITE_INDEX_CONSTRAINT_EQ 2
@@ -7255,11 +7255,11 @@
7255 ** </ul>)^
7256 **
7257 ** The only difference is that the public sqlite3_XXX functions enumerated
7258 ** above silently ignore any invocations that pass a NULL pointer instead
7259 ** of a valid mutex handle. The implementations of the methods defined
7260 ** by this structure are not required to handle this case, the results
7261 ** of passing a NULL pointer instead of a valid mutex handle are undefined
7262 ** (i.e. it is acceptable to provide an implementation that segfaults if
7263 ** it is passed a NULL pointer).
7264 **
7265 ** The xMutexInit() method must be threadsafe. It must be harmless to
@@ -7728,11 +7728,11 @@
7728 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
7729 ** no space was left in the page cache.</dd>)^
7730 **
7731 ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
7732 ** <dd>This parameter records the largest memory allocation request
7733 ** handed to [pagecache memory allocator]. Only the value returned in the
7734 ** *pHighwater parameter to [sqlite3_status()] is of interest.
7735 ** The value written into the *pCurrent parameter is undefined.</dd>)^
7736 **
7737 ** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt>
7738 ** <dd>No longer used.</dd>
@@ -7804,11 +7804,11 @@
7804 ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
7805 ** <dd>This parameter returns the number of lookaside memory slots currently
7806 ** checked out.</dd>)^
7807 **
7808 ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
7809 ** <dd>This parameter returns the number malloc attempts that were
7810 ** satisfied using lookaside memory. Only the high-water value is meaningful;
7811 ** the current value is always zero.)^
7812 **
7813 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
7814 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
@@ -7886,11 +7886,11 @@
7886 ** <dd>This parameter returns the number of dirty cache entries that have
7887 ** been written to disk in the middle of a transaction due to the page
7888 ** cache overflowing. Transactions are more efficient if they are written
7889 ** to disk all at once. When pages spill mid-transaction, that introduces
7890 ** additional overhead. This parameter can be used help identify
7891 ** inefficiencies that can be resolve by increasing the cache size.
7892 ** </dd>
7893 **
7894 ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
7895 ** <dd>This parameter returns zero for the current value if and only if
7896 ** all foreign key constraints (deferred or immediate) have been
@@ -7975,11 +7975,11 @@
7975 ** If the number of virtual machine operations exceeds 2147483647
7976 ** then the value returned by this statement status code is undefined.
7977 **
7978 ** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
7979 ** <dd>^This is the number of times that the prepare statement has been
7980 ** automatically regenerated due to schema changes or change to
7981 ** [bound parameters] that might affect the query plan.
7982 **
7983 ** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
7984 ** <dd>^This is the number of times that the prepared statement has
7985 ** been run. A single "run" for the purposes of this counter is one
@@ -8146,11 +8146,11 @@
8146 ** NULL if allocating a new page is effectively impossible.
8147 ** </table>
8148 **
8149 ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
8150 ** will only use a createFlag of 2 after a prior call with a createFlag of 1
8151 ** failed.)^ In between the to xFetch() calls, SQLite may
8152 ** attempt to unpin one or more cache pages by spilling the content of
8153 ** pinned pages to disk and synching the operating system disk cache.
8154 **
8155 ** [[the xUnpin() page cache method]]
8156 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
@@ -8464,11 +8464,11 @@
8464 ** application receives an SQLITE_LOCKED error, it may call the
8465 ** sqlite3_unlock_notify() method with the blocked connection handle as
8466 ** the first argument to register for a callback that will be invoked
8467 ** when the blocking connections current transaction is concluded. ^The
8468 ** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
8469 ** call that concludes the blocking connections transaction.
8470 **
8471 ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
8472 ** there is a chance that the blocking connection will have already
8473 ** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
8474 ** If this happens, then the specified callback is invoked immediately,
@@ -8502,11 +8502,11 @@
8502 ** However, the signature of the callback function allows SQLite to pass
8503 ** it an array of void* context pointers. The first argument passed to
8504 ** an unlock-notify callback is a pointer to an array of void* pointers,
8505 ** and the second is the number of entries in the array.
8506 **
8507 ** When a blocking connections transaction is concluded, there may be
8508 ** more than one blocked connection that has registered for an unlock-notify
8509 ** callback. ^If two or more such blocked connections have specified the
8510 ** same callback function, then instead of invoking the callback function
8511 ** multiple times, it is invoked once with the set of void* context pointers
8512 ** specified by the blocked connections bundled together into an array.
@@ -8976,37 +8976,37 @@
8976 ** managed by the prepared statement S and will be automatically freed when
8977 ** S is finalized.
8978 **
8979 ** <dl>
8980 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
8981 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
8982 ** set to the total number of times that the X-th loop has run.</dd>
8983 **
8984 ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
8985 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set
8986 ** to the total number of rows examined by all iterations of the X-th loop.</dd>
8987 **
8988 ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
8989 ** <dd>^The "double" variable pointed to by the T parameter will be set to the
8990 ** query planner's estimate for the average number of rows output from each
8991 ** iteration of the X-th loop. If the query planner's estimates was accurate,
8992 ** then this value will approximate the quotient NVISIT/NLOOP and the
8993 ** product of this value for all prior loops with the same SELECTID will
8994 ** be the NLOOP value for the current loop.
8995 **
8996 ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
8997 ** <dd>^The "const char *" variable pointed to by the T parameter will be set
8998 ** to a zero-terminated UTF-8 string containing the name of the index or table
8999 ** used for the X-th loop.
9000 **
9001 ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
9002 ** <dd>^The "const char *" variable pointed to by the T parameter will be set
9003 ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
9004 ** description for the X-th loop.
9005 **
9006 ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
9007 ** <dd>^The "int" variable pointed to by the T parameter will be set to the
9008 ** "select-id" for the X-th loop. The select-id identifies which query or
9009 ** subquery the loop is part of. The main query has a select-id of zero.
9010 ** The select-id is the same value as is output in the first column
9011 ** of an [EXPLAIN QUERY PLAN] query.
9012 ** </dl>
@@ -9857,11 +9857,11 @@
9857 ** METHOD: sqlite3_session
9858 **
9859 ** The second argument (xFilter) is the "filter callback". For changes to rows
9860 ** in tables that are not attached to the Session object, the filter is called
9861 ** to determine whether changes to the table's rows should be tracked or not.
9862 ** If xFilter returns 0, changes is not tracked. Note that once a table is
9863 ** attached, xFilter will not be called again.
9864 */
9865 SQLITE_API void sqlite3session_table_filter(
9866 sqlite3_session *pSession, /* Session object */
9867 int(*xFilter)(
@@ -10031,11 +10031,11 @@
10031 ** identical.
10032 **
10033 ** It an error if database zFrom does not exist or does not contain the
10034 ** required compatible table.
10035 **
10036 ** If the operation successful, SQLITE_OK is returned. Otherwise, an SQLite
10037 ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
10038 ** may be set to point to a buffer containing an English language error
10039 ** message. It is the responsibility of the caller to free this buffer using
10040 ** sqlite3_free().
10041 */
@@ -10168,11 +10168,11 @@
10168
10169 /*
10170 ** CAPI3REF: Advance A Changeset Iterator
10171 ** METHOD: sqlite3_changeset_iter
10172 **
10173 ** This function may only be used with iterators created by function
10174 ** [sqlite3changeset_start()]. If it is called on an iterator passed to
10175 ** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE
10176 ** is returned and the call has no effect.
10177 **
10178 ** Immediately after an iterator is created by sqlite3changeset_start(), it
@@ -10584,12 +10584,12 @@
10584 ** in the changegroup, then the number of columns and the position of the
10585 ** primary key columns for the table must be consistent. If this is not the
10586 ** case, this function fails with SQLITE_SCHEMA. If the input changeset
10587 ** appears to be corrupt and the corruption is detected, SQLITE_CORRUPT is
10588 ** returned. Or, if an out-of-memory condition occurs during processing, this
10589 ** function returns SQLITE_NOMEM. In all cases, if an error occurs the
10590 ** final contents of the changegroup is undefined.
10591 **
10592 ** If no error occurs, SQLITE_OK is returned.
10593 */
10594 SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
10595
@@ -10760,11 +10760,11 @@
10760 ** [SQLITE_CHANGESET_REPLACE].
10761 ** </dl>
10762 **
10763 ** It is safe to execute SQL statements, including those that write to the
10764 ** table that the callback related to, from within the xConflict callback.
10765 ** This can be used to further customize the applications conflict
10766 ** resolution strategy.
10767 **
10768 ** All changes made by these functions are enclosed in a savepoint transaction.
10769 ** If any other error (aside from a constraint failure when attempting to
10770 ** write to the target database) occurs, then the savepoint transaction is
@@ -11070,11 +11070,11 @@
11070 ** CAPI3REF: Rebase a changeset
11071 ** EXPERIMENTAL
11072 **
11073 ** Argument pIn must point to a buffer containing a changeset nIn bytes
11074 ** in size. This function allocates and populates a buffer with a copy
11075 ** of the changeset rebased rebased according to the configuration of the
11076 ** rebaser object passed as the first argument. If successful, (*ppOut)
11077 ** is set to point to the new buffer containing the rebased changeset and
11078 ** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
11079 ** responsibility of the caller to eventually free the new buffer using
11080 ** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
@@ -11478,11 +11478,11 @@
11478 ** the callback, an SQLite error code is returned.
11479 **
11480 **
11481 ** xSetAuxdata(pFts5, pAux, xDelete)
11482 **
11483 ** Save the pointer passed as the second argument as the extension functions
11484 ** "auxiliary data". The pointer may then be retrieved by the current or any
11485 ** future invocation of the same fts5 extension function made as part of
11486 ** the same MATCH query using the xGetAuxdata() API.
11487 **
11488 ** Each extension function is allocated a single auxiliary data slot for
@@ -11720,12 +11720,12 @@
11720 ** all instances of "first place" or "1st place" regardless of which form
11721 ** the user specified in the MATCH query text.
11722 **
11723 ** There are several ways to approach this in FTS5:
11724 **
11725 ** <ol><li> By mapping all synonyms to a single token. In this case, the
11726 ** In the above example, this means that the tokenizer returns the
11727 ** same token for inputs "first" and "1st". Say that token is in
11728 ** fact "first", so that when the user inserts the document "I won
11729 ** 1st place" entries are added to the index for tokens "i", "won",
11730 ** "first" and "place". If the user then queries for '1st + place',
11731 ** the tokenizer substitutes "first" for "1st" and the query works
11732
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.31.0"
127 #define SQLITE_VERSION_NUMBER 3031000
128 #define SQLITE_SOURCE_ID "2019-12-26 01:10:17 f482a4cdfa768941e22c399de8ec29a55e729529eeae86d3832077ad1bef22f3"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -539,10 +539,11 @@
539 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
540 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
541 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
542 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
543 #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
544 #define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8))
545
546 /*
547 ** CAPI3REF: Flags For File Open Operations
548 **
549 ** These bit values are intended for use in the
@@ -979,20 +980,20 @@
980 **
981 ** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
982 ** ^The [SQLITE_FCNTL_BUSYHANDLER]
983 ** file-control may be invoked by SQLite on the database file handle
984 ** shortly after it is opened in order to provide a custom VFS with access
985 ** to the connection's busy-handler callback. The argument is of type (void**)
986 ** - an array of two (void *) values. The first (void *) actually points
987 ** to a function of type (int (*)(void *)). In order to invoke the connection's
988 ** busy-handler, this function should be invoked with the second (void *) in
989 ** the array as the only argument. If it returns non-zero, then the operation
990 ** should be retried. If it returns zero, the custom VFS should abandon the
991 ** current operation.
992 **
993 ** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
994 ** ^Applications can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
995 ** to have SQLite generate a
996 ** temporary filename using the same algorithm that is followed to generate
997 ** temporary filenames for TEMP tables and other internal uses. The
998 ** argument should be a char** which will be filled with the filename
999 ** written into memory obtained from [sqlite3_malloc()]. The caller should
@@ -1101,11 +1102,11 @@
1102 ** interface can be used to find if any database on the connection has changed,
1103 ** but that interface responds to changes on TEMP as well as MAIN and does
1104 ** not provide a mechanism to detect changes to MAIN only. Also, the
1105 ** [sqlite3_total_changes()] interface responds to internal changes only and
1106 ** omits changes made by other database connections. The
1107 ** [PRAGMA data_version] command provides a mechanism to detect changes to
1108 ** a single attached database that occur due to other database connections,
1109 ** but omits changes implemented by the database connection on which it is
1110 ** called. This file control is the only mechanism to detect changes that
1111 ** happen either internally or externally and that are associated with
1112 ** a particular attached database.
@@ -1189,14 +1190,14 @@
1190 ** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
1191 ** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
1192 ** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6]. Additional fields
1193 ** may be appended to the sqlite3_vfs object and the iVersion value
1194 ** may increase again in future versions of SQLite.
1195 ** Note that due to an oversight, the structure
1196 ** of the sqlite3_vfs object changed in the transition from
1197 ** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
1198 ** and yet the iVersion field was not increased.
1199 **
1200 ** The szOsFile field is the size of the subclassed [sqlite3_file]
1201 ** structure used by this VFS. mxPathname is the maximum length of
1202 ** a pathname in this VFS.
1203 **
@@ -1283,11 +1284,11 @@
1284 ** be created, and that it is an error if it already exists.
1285 ** It is <i>not</i> used to indicate the file should be opened
1286 ** for exclusive access.
1287 **
1288 ** ^At least szOsFile bytes of memory are allocated by SQLite
1289 ** to hold the [sqlite3_file] structure passed as the third
1290 ** argument to xOpen. The xOpen method does not have to
1291 ** allocate the structure; it should just fill it in. Note that
1292 ** the xOpen method must set the sqlite3_file.pMethods to either
1293 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
1294 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
@@ -1406,11 +1407,10 @@
1407 ** SQLite.
1408 */
1409 #define SQLITE_ACCESS_EXISTS 0
1410 #define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */
1411 #define SQLITE_ACCESS_READ 2 /* Unused */
 
1412
1413 /*
1414 ** CAPI3REF: Flags for the xShmLock VFS method
1415 **
1416 ** These integer constants define the various locking operations
@@ -1621,11 +1621,11 @@
1621 ** Every memory allocation request coming in through [sqlite3_malloc()]
1622 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
1623 ** that causes the corresponding memory allocation to fail.
1624 **
1625 ** The xInit method initializes the memory allocator. For example,
1626 ** it might allocate any required mutexes or initialize internal data
1627 ** structures. The xShutdown method is invoked (indirectly) by
1628 ** [sqlite3_shutdown()] and should deallocate any resources acquired
1629 ** by xInit. The pAppData pointer is used as the only parameter to
1630 ** xInit and xShutdown.
1631 **
@@ -1762,11 +1762,11 @@
1762 **
1763 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1764 ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
1765 ** that SQLite can use for the database page cache with the default page
1766 ** cache implementation.
1767 ** This configuration option is a no-op if an application-defined page
1768 ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2].
1769 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
1770 ** 8-byte aligned memory (pMem), the size of each page cache line (sz),
1771 ** and the number of cache lines (N).
1772 ** The sz argument should be the size of the largest database page
@@ -2247,11 +2247,11 @@
2247 ** </dd>
2248 **
2249 ** [[SQLITE_DBCONFIG_DQS_DML]]
2250 ** <dt>SQLITE_DBCONFIG_DQS_DML</td>
2251 ** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
2252 ** the legacy [double-quoted string literal] misfeature for DML statements
2253 ** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The
2254 ** default value of this setting is determined by the [-DSQLITE_DQS]
2255 ** compile-time option.
2256 ** </dd>
2257 **
@@ -2508,11 +2508,11 @@
2508 ** will be rolled back automatically.
2509 **
2510 ** ^The sqlite3_interrupt(D) call is in effect until all currently running
2511 ** SQL statements on [database connection] D complete. ^Any new SQL statements
2512 ** that are started after the sqlite3_interrupt() call and before the
2513 ** running statement count reaches zero are interrupted as if they had been
2514 ** running prior to the sqlite3_interrupt() call. ^New SQL statements
2515 ** that are started after the running statement count reaches zero are
2516 ** not effected by the sqlite3_interrupt().
2517 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
2518 ** SQL statements is a no-op and has no effect on SQL statements
@@ -2676,13 +2676,13 @@
2676 ** Alice | 43
2677 ** Bob | 28
2678 ** Cindy | 21
2679 ** </pre></blockquote>
2680 **
2681 ** There are two columns (M==2) and three rows (N==3). Thus the
2682 ** result table has 8 entries. Suppose the result table is stored
2683 ** in an array named azResult. Then azResult holds this content:
2684 **
2685 ** <blockquote><pre>
2686 ** azResult&#91;0] = "Name";
2687 ** azResult&#91;1] = "Age";
2688 ** azResult&#91;2] = "Alice";
@@ -2832,23 +2832,10 @@
2832 ** sqlite3_malloc64(), and sqlite3_realloc64()
2833 ** is always aligned to at least an 8 byte boundary, or to a
2834 ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
2835 ** option is used.
2836 **
 
 
 
 
 
 
 
 
 
 
 
 
 
2837 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
2838 ** must be either NULL or else pointers obtained from a prior
2839 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
2840 ** not yet been released.
2841 **
@@ -2893,11 +2880,11 @@
2880 ** CAPI3REF: Pseudo-Random Number Generator
2881 **
2882 ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
2883 ** select random [ROWID | ROWIDs] when inserting new records into a table that
2884 ** already uses the largest possible [ROWID]. The PRNG is also used for
2885 ** the built-in random() and randomblob() SQL functions. This interface allows
2886 ** applications to access the same PRNG for other purposes.
2887 **
2888 ** ^A call to this routine stores N bytes of randomness into buffer P.
2889 ** ^The P parameter can be a NULL pointer.
2890 **
@@ -3494,11 +3481,11 @@
3481 ** a VFS implementation when the flags parameter to xOpen() has one or
3482 ** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and
3483 ** P is the name of the query parameter, then
3484 ** sqlite3_uri_parameter(F,P) returns the value of the P
3485 ** parameter if it exists or a NULL pointer if P does not appear as a
3486 ** query parameter on F. If P is a query parameter of F and it
3487 ** has no explicit value, then sqlite3_uri_parameter(F,P) returns
3488 ** a pointer to an empty string.
3489 **
3490 ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
3491 ** parameter and returns true (1) or false (0) according to the value
@@ -3506,11 +3493,11 @@
3493 ** value of query parameter P is one of "yes", "true", or "on" in any
3494 ** case or if the value begins with a non-zero number. The
3495 ** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
3496 ** query parameter P is one of "no", "false", or "off" in any case or
3497 ** if the value begins with a numeric zero. If P is not a query
3498 ** parameter on F or if the value of P does not match any of the
3499 ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
3500 **
3501 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
3502 ** 64-bit signed integer and returns that integer, or D if P does not
3503 ** exist. If the value of P is something other than an integer, then
@@ -3843,16 +3830,16 @@
3830 ** in order to find the underlying cause of the problem. With the "v2" prepare
3831 ** interfaces, the underlying reason for the error is returned immediately.
3832 ** </li>
3833 **
3834 ** <li>
3835 ** ^If the specific value bound to a [parameter | host parameter] in the
3836 ** WHERE clause might influence the choice of query plan for a statement,
3837 ** then the statement will be automatically recompiled, as if there had been
3838 ** a schema change, on the first [sqlite3_step()] call following any change
3839 ** to the [sqlite3_bind_text | bindings] of that [parameter].
3840 ** ^The specific value of a WHERE-clause [parameter] might influence the
3841 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
3842 ** or [GLOB] operator or if the parameter is compared to an indexed column
3843 ** and the [SQLITE_ENABLE_STAT4] compile-time option is enabled.
3844 ** </li>
3845 ** </ol>
@@ -4357,24 +4344,20 @@
4344 ** the statement, where N is the second function argument.
4345 ** ^The left-most column is column 0 for these routines.
4346 **
4347 ** ^If the Nth column returned by the statement is an expression or
4348 ** subquery and is not a column value, then all of these functions return
4349 ** NULL. ^These routines might also return NULL if a memory allocation error
4350 ** occurs. ^Otherwise, they return the name of the attached database, table,
4351 ** or column that query result column was extracted from.
4352 **
4353 ** ^As with all other SQLite APIs, those whose names end with "16" return
4354 ** UTF-16 encoded strings and the other functions return UTF-8.
4355 **
4356 ** ^These APIs are only available if the library was compiled with the
4357 ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
4358 **
 
 
 
 
4359 ** If two or more threads call one or more
4360 ** [sqlite3_column_database_name | column metadata interfaces]
4361 ** for the same [prepared statement] and result column
4362 ** at the same time then the results are undefined.
4363 */
@@ -4507,11 +4490,11 @@
4490 ** METHOD: sqlite3_stmt
4491 **
4492 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
4493 ** current row of the result set of [prepared statement] P.
4494 ** ^If prepared statement P does not have results ready to return
4495 ** (via calls to the [sqlite3_column_int | sqlite3_column()] family of
4496 ** interfaces) then sqlite3_data_count(P) returns 0.
4497 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
4498 ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
4499 ** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
4500 ** will return non-zero if previous call to [sqlite3_step](P) returned
@@ -5009,13 +4992,16 @@
4992 ** These constants may be ORed together with the
4993 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
4994 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
4995 ** [sqlite3_create_function_v2()].
4996 **
4997 ** The SQLITE_DETERMINISTIC flag means that the new function always gives
4998 ** the same output when the input parameters are the same. The abs() function
4999 ** is deterministic, for example, but randomblob() is not. Functions must
5000 ** be deterministic in order to be used in certain contexts such as
5001 ** [CHECK constraints] or [generated columns]. SQLite might also optimize
5002 ** deterministic functions by factoring them out of inner loops.
5003 **
5004 ** The SQLITE_DIRECTONLY flag means that the function may only be invoked
5005 ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs. This is
5006 ** a security feature which is recommended for all
5007 ** [application-defined SQL functions] that have side-effects. This flag
@@ -5090,12 +5076,12 @@
5076 **
5077 ** <b>Details:</b>
5078 **
5079 ** These routines extract type, size, and content information from
5080 ** [protected sqlite3_value] objects. Protected sqlite3_value objects
5081 ** are used to pass parameter information into the functions that
5082 ** implement [application-defined SQL functions] and [virtual tables].
5083 **
5084 ** These routines work only with [protected sqlite3_value] objects.
5085 ** Any attempt to use these routines on an [unprotected sqlite3_value]
5086 ** is not threadsafe.
5087 **
@@ -5148,11 +5134,11 @@
5134 ** the return value is arbitrary and meaningless.
5135 **
5136 ** ^The sqlite3_value_frombind(X) interface returns non-zero if the
5137 ** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()]
5138 ** interfaces. ^If X comes from an SQL literal value, or a table column,
5139 ** or an expression, then sqlite3_value_frombind(X) returns zero.
5140 **
5141 ** Please pay particular attention to the fact that the pointer returned
5142 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
5143 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
5144 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
@@ -5234,12 +5220,12 @@
5220 **
5221 ** Implementations of aggregate SQL functions use this
5222 ** routine to allocate memory for storing their state.
5223 **
5224 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
5225 ** for a particular aggregate function, SQLite allocates
5226 ** N bytes of memory, zeroes out that memory, and returns a pointer
5227 ** to the new memory. ^On second and subsequent calls to
5228 ** sqlite3_aggregate_context() for the same aggregate function instance,
5229 ** the same buffer is returned. Sqlite3_aggregate_context() is normally
5230 ** called once for each invocation of the xStep callback and then one
5231 ** last time when the xFinal callback is invoked. ^(When no rows match
@@ -5252,11 +5238,11 @@
5238 ** when first called if N is less than or equal to zero or if a memory
5239 ** allocate error occurs.
5240 **
5241 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
5242 ** determined by the N parameter on first successful call. Changing the
5243 ** value of N in any subsequents call to sqlite3_aggregate_context() within
5244 ** the same aggregate function instance will not resize the memory
5245 ** allocation.)^ Within the xFinal callback, it is customary to set
5246 ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
5247 ** pointless memory allocations occur.
5248 **
@@ -5600,11 +5586,11 @@
5586 ** <li> If A&lt;B THEN B&gt;A.
5587 ** <li> If A&lt;B and B&lt;C then A&lt;C.
5588 ** </ol>
5589 **
5590 ** If a collating function fails any of the above constraints and that
5591 ** collating function is registered and used, then the behavior of SQLite
5592 ** is undefined.
5593 **
5594 ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
5595 ** with the addition that the xDestroy callback is invoked on pArg when
5596 ** the collating function is deleted.
@@ -5927,15 +5913,19 @@
5913
5914 /*
5915 ** CAPI3REF: Return The Filename For A Database Connection
5916 ** METHOD: sqlite3
5917 **
5918 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to the filename
5919 ** associated with database N of connection D.
5920 ** ^If there is no attached database N on the database
5921 ** connection D, or if database N is a temporary or in-memory database, then
5922 ** this function will return either a NULL pointer or an empty string.
5923 **
5924 ** ^The string value returned by this routine is owned and managed by
5925 ** the database connection. ^The value will be valid until the database N
5926 ** is [DETACH]-ed or until the database connection closes.
5927 **
5928 ** ^The filename returned by this function is the output of the
5929 ** xFullPathname method of the [VFS]. ^In other words, the filename
5930 ** will be an absolute pathname, even if the filename used
5931 ** to open the database originally was a URI or relative pathname.
@@ -6086,19 +6076,23 @@
6076 ** In prior versions of SQLite,
6077 ** sharing was enabled or disabled for each thread separately.
6078 **
6079 ** ^(The cache sharing mode set by this interface effects all subsequent
6080 ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
6081 ** Existing database connections continue to use the sharing mode
6082 ** that was in effect at the time they were opened.)^
6083 **
6084 ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
6085 ** successfully. An [error code] is returned otherwise.)^
6086 **
6087 ** ^Shared cache is disabled by default. It is recommended that it stay
6088 ** that way. In other words, do not use this routine. This interface
6089 ** continues to be provided for historical compatibility, but its use is
6090 ** discouraged. Any use of shared cache is discouraged. If shared cache
6091 ** must be used, it is recommended that shared cache only be enabled for
6092 ** individual database connections using the [sqlite3_open_v2()] interface
6093 ** with the [SQLITE_OPEN_SHAREDCACHE] flag.
6094 **
6095 ** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0
6096 ** and will always return SQLITE_MISUSE. On those systems,
6097 ** shared cache mode should be enabled per-database connection via
6098 ** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
@@ -6227,11 +6221,11 @@
6221 ** information about column C of table T in database D
6222 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
6223 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
6224 ** the final five arguments with appropriate values if the specified
6225 ** column exists. ^The sqlite3_table_column_metadata() interface returns
6226 ** SQLITE_ERROR if the specified column does not exist.
6227 ** ^If the column-name parameter to sqlite3_table_column_metadata() is a
6228 ** NULL pointer, then this routine simply checks for the existence of the
6229 ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
6230 ** does not. If the table name parameter T in a call to
6231 ** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is
@@ -6369,11 +6363,11 @@
6363 ** [sqlite3_load_extension()] and the SQL function [load_extension()].
6364 ** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
6365 ** to enable or disable only the C-API.)^
6366 **
6367 ** <b>Security warning:</b> It is recommended that extension loading
6368 ** be enabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
6369 ** rather than this interface, so the [load_extension()] SQL function
6370 ** remains disabled. This will prevent SQL injections from giving attackers
6371 ** access to extension loading capabilities.
6372 */
6373 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
@@ -6456,11 +6450,11 @@
6450 /*
6451 ** CAPI3REF: Virtual Table Object
6452 ** KEYWORDS: sqlite3_module {virtual table module}
6453 **
6454 ** This structure, sometimes called a "virtual table module",
6455 ** defines the implementation of a [virtual table].
6456 ** This structure consists mostly of methods for the module.
6457 **
6458 ** ^A virtual table module is created by filling in a persistent
6459 ** instance of this structure and passing a pointer to that instance
6460 ** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
@@ -6553,11 +6547,17 @@
6547 ** The [xBestIndex] method must fill aConstraintUsage[] with information
6548 ** about what parameters to pass to xFilter. ^If argvIndex>0 then
6549 ** the right-hand side of the corresponding aConstraint[] is evaluated
6550 ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit
6551 ** is true, then the constraint is assumed to be fully handled by the
6552 ** virtual table and might not be checked again by the byte code.)^ ^(The
6553 ** aConstraintUsage[].omit flag is an optimization hint. When the omit flag
6554 ** is left in its default setting of false, the constraint will always be
6555 ** checked separately in byte code. If the omit flag is change to true, then
6556 ** the constraint may or may not be checked in byte code. In other words,
6557 ** when the omit flag is true there is no guarantee that the constraint will
6558 ** not be checked again using byte code.)^
6559 **
6560 ** ^The idxNum and idxPtr values are recorded and passed into the
6561 ** [xFilter] method.
6562 ** ^[sqlite3_free()] is used to free idxPtr if and only if
6563 ** needToFreeIdxPtr is true.
@@ -6593,11 +6593,11 @@
6593 ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
6594 ** structure for SQLite [version 3.8.2] ([dateof:3.8.2]).
6595 ** If a virtual table extension is
6596 ** used with an SQLite version earlier than 3.8.2, the results of attempting
6597 ** to read or write the estimatedRows field are undefined (but are likely
6598 ** to include crashing the application). The estimatedRows field should
6599 ** therefore only be used if [sqlite3_libversion_number()] returns a
6600 ** value greater than or equal to 3008002. Similarly, the idxFlags field
6601 ** was added for [version 3.9.0] ([dateof:3.9.0]).
6602 ** It may therefore only be used if
6603 ** sqlite3_libversion_number() returns a value greater than or equal to
@@ -6645,11 +6645,11 @@
6645 #define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */
6646
6647 /*
6648 ** CAPI3REF: Virtual Table Constraint Operator Codes
6649 **
6650 ** These macros define the allowed values for the
6651 ** [sqlite3_index_info].aConstraint[].op field. Each value represents
6652 ** an operator that is part of a constraint term in the wHERE clause of
6653 ** a query that uses a [virtual table].
6654 */
6655 #define SQLITE_INDEX_CONSTRAINT_EQ 2
@@ -7255,11 +7255,11 @@
7255 ** </ul>)^
7256 **
7257 ** The only difference is that the public sqlite3_XXX functions enumerated
7258 ** above silently ignore any invocations that pass a NULL pointer instead
7259 ** of a valid mutex handle. The implementations of the methods defined
7260 ** by this structure are not required to handle this case. The results
7261 ** of passing a NULL pointer instead of a valid mutex handle are undefined
7262 ** (i.e. it is acceptable to provide an implementation that segfaults if
7263 ** it is passed a NULL pointer).
7264 **
7265 ** The xMutexInit() method must be threadsafe. It must be harmless to
@@ -7728,11 +7728,11 @@
7728 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
7729 ** no space was left in the page cache.</dd>)^
7730 **
7731 ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
7732 ** <dd>This parameter records the largest memory allocation request
7733 ** handed to the [pagecache memory allocator]. Only the value returned in the
7734 ** *pHighwater parameter to [sqlite3_status()] is of interest.
7735 ** The value written into the *pCurrent parameter is undefined.</dd>)^
7736 **
7737 ** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt>
7738 ** <dd>No longer used.</dd>
@@ -7804,11 +7804,11 @@
7804 ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
7805 ** <dd>This parameter returns the number of lookaside memory slots currently
7806 ** checked out.</dd>)^
7807 **
7808 ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
7809 ** <dd>This parameter returns the number of malloc attempts that were
7810 ** satisfied using lookaside memory. Only the high-water value is meaningful;
7811 ** the current value is always zero.)^
7812 **
7813 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
7814 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
@@ -7886,11 +7886,11 @@
7886 ** <dd>This parameter returns the number of dirty cache entries that have
7887 ** been written to disk in the middle of a transaction due to the page
7888 ** cache overflowing. Transactions are more efficient if they are written
7889 ** to disk all at once. When pages spill mid-transaction, that introduces
7890 ** additional overhead. This parameter can be used help identify
7891 ** inefficiencies that can be resolved by increasing the cache size.
7892 ** </dd>
7893 **
7894 ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
7895 ** <dd>This parameter returns zero for the current value if and only if
7896 ** all foreign key constraints (deferred or immediate) have been
@@ -7975,11 +7975,11 @@
7975 ** If the number of virtual machine operations exceeds 2147483647
7976 ** then the value returned by this statement status code is undefined.
7977 **
7978 ** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
7979 ** <dd>^This is the number of times that the prepare statement has been
7980 ** automatically regenerated due to schema changes or changes to
7981 ** [bound parameters] that might affect the query plan.
7982 **
7983 ** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
7984 ** <dd>^This is the number of times that the prepared statement has
7985 ** been run. A single "run" for the purposes of this counter is one
@@ -8146,11 +8146,11 @@
8146 ** NULL if allocating a new page is effectively impossible.
8147 ** </table>
8148 **
8149 ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
8150 ** will only use a createFlag of 2 after a prior call with a createFlag of 1
8151 ** failed.)^ In between the xFetch() calls, SQLite may
8152 ** attempt to unpin one or more cache pages by spilling the content of
8153 ** pinned pages to disk and synching the operating system disk cache.
8154 **
8155 ** [[the xUnpin() page cache method]]
8156 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
@@ -8464,11 +8464,11 @@
8464 ** application receives an SQLITE_LOCKED error, it may call the
8465 ** sqlite3_unlock_notify() method with the blocked connection handle as
8466 ** the first argument to register for a callback that will be invoked
8467 ** when the blocking connections current transaction is concluded. ^The
8468 ** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
8469 ** call that concludes the blocking connection's transaction.
8470 **
8471 ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
8472 ** there is a chance that the blocking connection will have already
8473 ** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
8474 ** If this happens, then the specified callback is invoked immediately,
@@ -8502,11 +8502,11 @@
8502 ** However, the signature of the callback function allows SQLite to pass
8503 ** it an array of void* context pointers. The first argument passed to
8504 ** an unlock-notify callback is a pointer to an array of void* pointers,
8505 ** and the second is the number of entries in the array.
8506 **
8507 ** When a blocking connection's transaction is concluded, there may be
8508 ** more than one blocked connection that has registered for an unlock-notify
8509 ** callback. ^If two or more such blocked connections have specified the
8510 ** same callback function, then instead of invoking the callback function
8511 ** multiple times, it is invoked once with the set of void* context pointers
8512 ** specified by the blocked connections bundled together into an array.
@@ -8976,37 +8976,37 @@
8976 ** managed by the prepared statement S and will be automatically freed when
8977 ** S is finalized.
8978 **
8979 ** <dl>
8980 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
8981 ** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be
8982 ** set to the total number of times that the X-th loop has run.</dd>
8983 **
8984 ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
8985 ** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be set
8986 ** to the total number of rows examined by all iterations of the X-th loop.</dd>
8987 **
8988 ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
8989 ** <dd>^The "double" variable pointed to by the V parameter will be set to the
8990 ** query planner's estimate for the average number of rows output from each
8991 ** iteration of the X-th loop. If the query planner's estimates was accurate,
8992 ** then this value will approximate the quotient NVISIT/NLOOP and the
8993 ** product of this value for all prior loops with the same SELECTID will
8994 ** be the NLOOP value for the current loop.
8995 **
8996 ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
8997 ** <dd>^The "const char *" variable pointed to by the V parameter will be set
8998 ** to a zero-terminated UTF-8 string containing the name of the index or table
8999 ** used for the X-th loop.
9000 **
9001 ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
9002 ** <dd>^The "const char *" variable pointed to by the V parameter will be set
9003 ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
9004 ** description for the X-th loop.
9005 **
9006 ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
9007 ** <dd>^The "int" variable pointed to by the V parameter will be set to the
9008 ** "select-id" for the X-th loop. The select-id identifies which query or
9009 ** subquery the loop is part of. The main query has a select-id of zero.
9010 ** The select-id is the same value as is output in the first column
9011 ** of an [EXPLAIN QUERY PLAN] query.
9012 ** </dl>
@@ -9857,11 +9857,11 @@
9857 ** METHOD: sqlite3_session
9858 **
9859 ** The second argument (xFilter) is the "filter callback". For changes to rows
9860 ** in tables that are not attached to the Session object, the filter is called
9861 ** to determine whether changes to the table's rows should be tracked or not.
9862 ** If xFilter returns 0, changes are not tracked. Note that once a table is
9863 ** attached, xFilter will not be called again.
9864 */
9865 SQLITE_API void sqlite3session_table_filter(
9866 sqlite3_session *pSession, /* Session object */
9867 int(*xFilter)(
@@ -10031,11 +10031,11 @@
10031 ** identical.
10032 **
10033 ** It an error if database zFrom does not exist or does not contain the
10034 ** required compatible table.
10035 **
10036 ** If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite
10037 ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
10038 ** may be set to point to a buffer containing an English language error
10039 ** message. It is the responsibility of the caller to free this buffer using
10040 ** sqlite3_free().
10041 */
@@ -10168,11 +10168,11 @@
10168
10169 /*
10170 ** CAPI3REF: Advance A Changeset Iterator
10171 ** METHOD: sqlite3_changeset_iter
10172 **
10173 ** This function may only be used with iterators created by the function
10174 ** [sqlite3changeset_start()]. If it is called on an iterator passed to
10175 ** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE
10176 ** is returned and the call has no effect.
10177 **
10178 ** Immediately after an iterator is created by sqlite3changeset_start(), it
@@ -10584,12 +10584,12 @@
10584 ** in the changegroup, then the number of columns and the position of the
10585 ** primary key columns for the table must be consistent. If this is not the
10586 ** case, this function fails with SQLITE_SCHEMA. If the input changeset
10587 ** appears to be corrupt and the corruption is detected, SQLITE_CORRUPT is
10588 ** returned. Or, if an out-of-memory condition occurs during processing, this
10589 ** function returns SQLITE_NOMEM. In all cases, if an error occurs the state
10590 ** of the final contents of the changegroup is undefined.
10591 **
10592 ** If no error occurs, SQLITE_OK is returned.
10593 */
10594 SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
10595
@@ -10760,11 +10760,11 @@
10760 ** [SQLITE_CHANGESET_REPLACE].
10761 ** </dl>
10762 **
10763 ** It is safe to execute SQL statements, including those that write to the
10764 ** table that the callback related to, from within the xConflict callback.
10765 ** This can be used to further customize the application's conflict
10766 ** resolution strategy.
10767 **
10768 ** All changes made by these functions are enclosed in a savepoint transaction.
10769 ** If any other error (aside from a constraint failure when attempting to
10770 ** write to the target database) occurs, then the savepoint transaction is
@@ -11070,11 +11070,11 @@
11070 ** CAPI3REF: Rebase a changeset
11071 ** EXPERIMENTAL
11072 **
11073 ** Argument pIn must point to a buffer containing a changeset nIn bytes
11074 ** in size. This function allocates and populates a buffer with a copy
11075 ** of the changeset rebased according to the configuration of the
11076 ** rebaser object passed as the first argument. If successful, (*ppOut)
11077 ** is set to point to the new buffer containing the rebased changeset and
11078 ** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
11079 ** responsibility of the caller to eventually free the new buffer using
11080 ** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
@@ -11478,11 +11478,11 @@
11478 ** the callback, an SQLite error code is returned.
11479 **
11480 **
11481 ** xSetAuxdata(pFts5, pAux, xDelete)
11482 **
11483 ** Save the pointer passed as the second argument as the extension function's
11484 ** "auxiliary data". The pointer may then be retrieved by the current or any
11485 ** future invocation of the same fts5 extension function made as part of
11486 ** the same MATCH query using the xGetAuxdata() API.
11487 **
11488 ** Each extension function is allocated a single auxiliary data slot for
@@ -11720,12 +11720,12 @@
11720 ** all instances of "first place" or "1st place" regardless of which form
11721 ** the user specified in the MATCH query text.
11722 **
11723 ** There are several ways to approach this in FTS5:
11724 **
11725 ** <ol><li> By mapping all synonyms to a single token. In this case, using
11726 ** the above example, this means that the tokenizer returns the
11727 ** same token for inputs "first" and "1st". Say that token is in
11728 ** fact "first", so that when the user inserts the document "I won
11729 ** 1st place" entries are added to the index for tokens "i", "won",
11730 ** "first" and "place". If the user then queries for '1st + place',
11731 ** the tokenizer substitutes "first" for "1st" and the query works
11732

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button