Fossil SCM

Update the built-in SQLite to 3.18.0

jan.nijtmans 2017-03-30 15:27 UTC branch-2.1
Commit 017baa24e112f9d8b1732cae2f6498a16f00f6b8d208aebdef92a5bb250b3680
3 files changed +5 -4 +1828 -1112 +42 -21
+5 -4
--- src/import.c
+++ src/import.c
@@ -1250,12 +1250,12 @@
12501250
return branchId;
12511251
}
12521252
12531253
/*
12541254
** Insert content of corresponding content blob into the database.
1255
-** If content is identified as a symbolic link then:
1256
-** 1)Trailing "link " characters are removed from content.
1255
+** If content is identified as a symbolic link, then trailing
1256
+** "link " characters are removed from content.
12571257
**
12581258
** content is considered to be a symlink if zPerm contains at least
12591259
** one "l" character.
12601260
*/
12611261
static int svn_handle_symlinks(const char *perms, Blob *content){
@@ -1370,15 +1370,16 @@
13701370
int branchType;
13711371
int branchId = svn_parse_path(zTemp, &zFile, &branchType);
13721372
char *zAction = svn_find_header(rec, "Node-action");
13731373
char *zKind = svn_find_header(rec, "Node-kind");
13741374
char *zPerm = svn_find_prop(rec, "svn:executable") ? "x" : 0;
1375
+ int deltaFlag = 0;
1376
+ int srcRev = 0;
1377
+
13751378
if ( zPerm==0 ){
13761379
zPerm = svn_find_prop(rec, "svn:special") ? "l" : 0;
13771380
}
1378
- int deltaFlag = 0;
1379
- int srcRev = 0;
13801381
if( branchId==0 ){
13811382
svn_free_rec(&rec);
13821383
continue;
13831384
}
13841385
if( (zTemp = svn_find_header(rec, "Text-delta")) ){
13851386
--- src/import.c
+++ src/import.c
@@ -1250,12 +1250,12 @@
1250 return branchId;
1251 }
1252
1253 /*
1254 ** Insert content of corresponding content blob into the database.
1255 ** If content is identified as a symbolic link then:
1256 ** 1)Trailing "link " characters are removed from content.
1257 **
1258 ** content is considered to be a symlink if zPerm contains at least
1259 ** one "l" character.
1260 */
1261 static int svn_handle_symlinks(const char *perms, Blob *content){
@@ -1370,15 +1370,16 @@
1370 int branchType;
1371 int branchId = svn_parse_path(zTemp, &zFile, &branchType);
1372 char *zAction = svn_find_header(rec, "Node-action");
1373 char *zKind = svn_find_header(rec, "Node-kind");
1374 char *zPerm = svn_find_prop(rec, "svn:executable") ? "x" : 0;
 
 
 
1375 if ( zPerm==0 ){
1376 zPerm = svn_find_prop(rec, "svn:special") ? "l" : 0;
1377 }
1378 int deltaFlag = 0;
1379 int srcRev = 0;
1380 if( branchId==0 ){
1381 svn_free_rec(&rec);
1382 continue;
1383 }
1384 if( (zTemp = svn_find_header(rec, "Text-delta")) ){
1385
--- src/import.c
+++ src/import.c
@@ -1250,12 +1250,12 @@
1250 return branchId;
1251 }
1252
1253 /*
1254 ** Insert content of corresponding content blob into the database.
1255 ** If content is identified as a symbolic link, then trailing
1256 ** "link " characters are removed from content.
1257 **
1258 ** content is considered to be a symlink if zPerm contains at least
1259 ** one "l" character.
1260 */
1261 static int svn_handle_symlinks(const char *perms, Blob *content){
@@ -1370,15 +1370,16 @@
1370 int branchType;
1371 int branchId = svn_parse_path(zTemp, &zFile, &branchType);
1372 char *zAction = svn_find_header(rec, "Node-action");
1373 char *zKind = svn_find_header(rec, "Node-kind");
1374 char *zPerm = svn_find_prop(rec, "svn:executable") ? "x" : 0;
1375 int deltaFlag = 0;
1376 int srcRev = 0;
1377
1378 if ( zPerm==0 ){
1379 zPerm = svn_find_prop(rec, "svn:special") ? "l" : 0;
1380 }
 
 
1381 if( branchId==0 ){
1382 svn_free_rec(&rec);
1383 continue;
1384 }
1385 if( (zTemp = svn_find_header(rec, "Text-delta")) ){
1386
+1828 -1112
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.17.0. By combining all the individual C code files into this
3
+** version 3.18.0. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -389,20 +389,20 @@
389389
** SQLite source code has been stored in the
390390
** <a href="http://www.fossil-scm.org/">Fossil configuration management
391391
** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
392392
** a string which identifies a particular check-in of SQLite
393393
** within its configuration management system. ^The SQLITE_SOURCE_ID
394
-** string contains the date and time of the check-in (UTC) and an SHA1
395
-** hash of the entire source tree.
394
+** string contains the date and time of the check-in (UTC) and a SHA1
395
+** or SHA3-256 hash of the entire source tree.
396396
**
397397
** See also: [sqlite3_libversion()],
398398
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
399399
** [sqlite_version()] and [sqlite_source_id()].
400400
*/
401
-#define SQLITE_VERSION "3.17.0"
402
-#define SQLITE_VERSION_NUMBER 3017000
403
-#define SQLITE_SOURCE_ID "2017-02-13 16:02:40 ada05cfa86ad7f5645450ac7a2a21c9aa6e57d2c"
401
+#define SQLITE_VERSION "3.18.0"
402
+#define SQLITE_VERSION_NUMBER 3018000
403
+#define SQLITE_SOURCE_ID "2017-03-28 18:48:43 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37"
404404
405405
/*
406406
** CAPI3REF: Run-Time Library Version Numbers
407407
** KEYWORDS: sqlite3_version sqlite3_sourceid
408408
**
@@ -2315,24 +2315,34 @@
23152315
** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
23162316
** names are not also used by explicitly declared columns. ^If
23172317
** the table has a column of type [INTEGER PRIMARY KEY] then that column
23182318
** is another alias for the rowid.
23192319
**
2320
-** ^The sqlite3_last_insert_rowid(D) interface returns the [rowid] of the
2321
-** most recent successful [INSERT] into a rowid table or [virtual table]
2322
-** on database connection D.
2323
-** ^Inserts into [WITHOUT ROWID] tables are not recorded.
2324
-** ^If no successful [INSERT]s into rowid tables
2325
-** have ever occurred on the database connection D,
2326
-** then sqlite3_last_insert_rowid(D) returns zero.
2320
+** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of
2321
+** the most recent successful [INSERT] into a rowid table or [virtual table]
2322
+** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not
2323
+** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred
2324
+** on the database connection D, then sqlite3_last_insert_rowid(D) returns
2325
+** zero.
23272326
**
2328
-** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
2329
-** method, then this routine will return the [rowid] of the inserted
2330
-** row as long as the trigger or virtual table method is running.
2331
-** But once the trigger or virtual table method ends, the value returned
2332
-** by this routine reverts to what it was before the trigger or virtual
2333
-** table method began.)^
2327
+** As well as being set automatically as rows are inserted into database
2328
+** tables, the value returned by this function may be set explicitly by
2329
+** [sqlite3_set_last_insert_rowid()]
2330
+**
2331
+** Some virtual table implementations may INSERT rows into rowid tables as
2332
+** part of committing a transaction (e.g. to flush data accumulated in memory
2333
+** to disk). In this case subsequent calls to this function return the rowid
2334
+** associated with these internal INSERT operations, which leads to
2335
+** unintuitive results. Virtual table implementations that do write to rowid
2336
+** tables in this way can avoid this problem by restoring the original
2337
+** rowid value using [sqlite3_set_last_insert_rowid()] before returning
2338
+** control to the user.
2339
+**
2340
+** ^(If an [INSERT] occurs within a trigger then this routine will
2341
+** return the [rowid] of the inserted row as long as the trigger is
2342
+** running. Once the trigger program ends, the value returned
2343
+** by this routine reverts to what it was before the trigger was fired.)^
23342344
**
23352345
** ^An [INSERT] that fails due to a constraint violation is not a
23362346
** successful [INSERT] and does not change the value returned by this
23372347
** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
23382348
** and INSERT OR ABORT make no changes to the return value of this
@@ -2355,10 +2365,20 @@
23552365
** unpredictable and might not equal either the old or the new
23562366
** last insert [rowid].
23572367
*/
23582368
SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
23592369
2370
+/*
2371
+** CAPI3REF: Set the Last Insert Rowid value.
2372
+** METHOD: sqlite3
2373
+**
2374
+** The sqlite3_set_last_insert_rowid(D, R) method allows the application to
2375
+** set the value returned by calling sqlite3_last_insert_rowid(D) to R
2376
+** without inserting a row into the database.
2377
+*/
2378
+SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);
2379
+
23602380
/*
23612381
** CAPI3REF: Count The Number Of Rows Modified
23622382
** METHOD: sqlite3
23632383
**
23642384
** ^This function returns the number of rows modified, inserted or
@@ -3679,13 +3699,13 @@
36793699
** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
36803700
** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
36813701
**
36823702
** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
36833703
** <dd>The maximum number of instructions in a virtual machine program
3684
-** used to implement an SQL statement. This limit is not currently
3685
-** enforced, though that might be added in some future release of
3686
-** SQLite.</dd>)^
3704
+** used to implement an SQL statement. If [sqlite3_prepare_v2()] or
3705
+** the equivalent tries to allocate space for more than this many opcodes
3706
+** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^
36873707
**
36883708
** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
36893709
** <dd>The maximum number of arguments on a function.</dd>)^
36903710
**
36913711
** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
@@ -3718,10 +3738,11 @@
37183738
#define SQLITE_LIMIT_ATTACHED 7
37193739
#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
37203740
#define SQLITE_LIMIT_VARIABLE_NUMBER 9
37213741
#define SQLITE_LIMIT_TRIGGER_DEPTH 10
37223742
#define SQLITE_LIMIT_WORKER_THREADS 11
3743
+
37233744
37243745
/*
37253746
** CAPI3REF: Compiling An SQL Statement
37263747
** KEYWORDS: {SQL statement compiler}
37273748
** METHOD: sqlite3
@@ -10846,11 +10867,11 @@
1084610867
/*
1084710868
** The maximum number of opcodes in a VDBE program.
1084810869
** Not currently enforced.
1084910870
*/
1085010871
#ifndef SQLITE_MAX_VDBE_OP
10851
-# define SQLITE_MAX_VDBE_OP 25000
10872
+# define SQLITE_MAX_VDBE_OP 250000000
1085210873
#endif
1085310874
1085410875
/*
1085510876
** The maximum number of arguments to an SQL function.
1085610877
*/
@@ -12457,10 +12478,11 @@
1245712478
SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
1245812479
SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
1245912480
1246012481
SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
1246112482
SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
12483
+SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*);
1246212484
1246312485
#ifndef SQLITE_OMIT_INCRBLOB
1246412486
SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*);
1246512487
SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
1246612488
SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *);
@@ -12623,10 +12645,11 @@
1262312645
struct SubProgram {
1262412646
VdbeOp *aOp; /* Array of opcodes for sub-program */
1262512647
int nOp; /* Elements in aOp[] */
1262612648
int nMem; /* Number of memory cells required */
1262712649
int nCsr; /* Number of cursors required */
12650
+ u8 *aOnce; /* Array of OP_Once flags */
1262812651
void *token; /* id that may be used to recursive triggers */
1262912652
SubProgram *pNext; /* Next sub-program already visited */
1263012653
};
1263112654
1263212655
/*
@@ -12757,117 +12780,119 @@
1275712780
#define OP_Divide 50 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
1275812781
#define OP_Remainder 51 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
1275912782
#define OP_Concat 52 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
1276012783
#define OP_Last 53
1276112784
#define OP_BitNot 54 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
12762
-#define OP_SorterSort 55
12763
-#define OP_Sort 56
12764
-#define OP_Rewind 57
12765
-#define OP_IdxLE 58 /* synopsis: key=r[P3@P4] */
12766
-#define OP_IdxGT 59 /* synopsis: key=r[P3@P4] */
12767
-#define OP_IdxLT 60 /* synopsis: key=r[P3@P4] */
12768
-#define OP_IdxGE 61 /* synopsis: key=r[P3@P4] */
12769
-#define OP_RowSetRead 62 /* synopsis: r[P3]=rowset(P1) */
12770
-#define OP_RowSetTest 63 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12771
-#define OP_Program 64
12772
-#define OP_FkIfZero 65 /* synopsis: if fkctr[P1]==0 goto P2 */
12773
-#define OP_IfPos 66 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12774
-#define OP_IfNotZero 67 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
12775
-#define OP_DecrJumpZero 68 /* synopsis: if (--r[P1])==0 goto P2 */
12776
-#define OP_IncrVacuum 69
12777
-#define OP_VNext 70
12778
-#define OP_Init 71 /* synopsis: Start at P2 */
12779
-#define OP_Return 72
12780
-#define OP_EndCoroutine 73
12781
-#define OP_HaltIfNull 74 /* synopsis: if r[P3]=null halt */
12782
-#define OP_Halt 75
12783
-#define OP_Integer 76 /* synopsis: r[P2]=P1 */
12784
-#define OP_Int64 77 /* synopsis: r[P2]=P4 */
12785
-#define OP_String 78 /* synopsis: r[P2]='P4' (len=P1) */
12786
-#define OP_Null 79 /* synopsis: r[P2..P3]=NULL */
12787
-#define OP_SoftNull 80 /* synopsis: r[P1]=NULL */
12788
-#define OP_Blob 81 /* synopsis: r[P2]=P4 (len=P1) */
12789
-#define OP_Variable 82 /* synopsis: r[P2]=parameter(P1,P4) */
12790
-#define OP_Move 83 /* synopsis: r[P2@P3]=r[P1@P3] */
12791
-#define OP_Copy 84 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
12792
-#define OP_SCopy 85 /* synopsis: r[P2]=r[P1] */
12793
-#define OP_IntCopy 86 /* synopsis: r[P2]=r[P1] */
12794
-#define OP_ResultRow 87 /* synopsis: output=r[P1@P2] */
12795
-#define OP_CollSeq 88
12796
-#define OP_Function0 89 /* synopsis: r[P3]=func(r[P2@P5]) */
12797
-#define OP_Function 90 /* synopsis: r[P3]=func(r[P2@P5]) */
12798
-#define OP_AddImm 91 /* synopsis: r[P1]=r[P1]+P2 */
12799
-#define OP_RealAffinity 92
12800
-#define OP_Cast 93 /* synopsis: affinity(r[P1]) */
12801
-#define OP_Permutation 94
12802
-#define OP_Compare 95 /* synopsis: r[P1@P3] <-> r[P2@P3] */
12803
-#define OP_Column 96 /* synopsis: r[P3]=PX */
12785
+#define OP_IfSmaller 55
12786
+#define OP_SorterSort 56
12787
+#define OP_Sort 57
12788
+#define OP_Rewind 58
12789
+#define OP_IdxLE 59 /* synopsis: key=r[P3@P4] */
12790
+#define OP_IdxGT 60 /* synopsis: key=r[P3@P4] */
12791
+#define OP_IdxLT 61 /* synopsis: key=r[P3@P4] */
12792
+#define OP_IdxGE 62 /* synopsis: key=r[P3@P4] */
12793
+#define OP_RowSetRead 63 /* synopsis: r[P3]=rowset(P1) */
12794
+#define OP_RowSetTest 64 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12795
+#define OP_Program 65
12796
+#define OP_FkIfZero 66 /* synopsis: if fkctr[P1]==0 goto P2 */
12797
+#define OP_IfPos 67 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12798
+#define OP_IfNotZero 68 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
12799
+#define OP_DecrJumpZero 69 /* synopsis: if (--r[P1])==0 goto P2 */
12800
+#define OP_IncrVacuum 70
12801
+#define OP_VNext 71
12802
+#define OP_Init 72 /* synopsis: Start at P2 */
12803
+#define OP_Return 73
12804
+#define OP_EndCoroutine 74
12805
+#define OP_HaltIfNull 75 /* synopsis: if r[P3]=null halt */
12806
+#define OP_Halt 76
12807
+#define OP_Integer 77 /* synopsis: r[P2]=P1 */
12808
+#define OP_Int64 78 /* synopsis: r[P2]=P4 */
12809
+#define OP_String 79 /* synopsis: r[P2]='P4' (len=P1) */
12810
+#define OP_Null 80 /* synopsis: r[P2..P3]=NULL */
12811
+#define OP_SoftNull 81 /* synopsis: r[P1]=NULL */
12812
+#define OP_Blob 82 /* synopsis: r[P2]=P4 (len=P1) */
12813
+#define OP_Variable 83 /* synopsis: r[P2]=parameter(P1,P4) */
12814
+#define OP_Move 84 /* synopsis: r[P2@P3]=r[P1@P3] */
12815
+#define OP_Copy 85 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
12816
+#define OP_SCopy 86 /* synopsis: r[P2]=r[P1] */
12817
+#define OP_IntCopy 87 /* synopsis: r[P2]=r[P1] */
12818
+#define OP_ResultRow 88 /* synopsis: output=r[P1@P2] */
12819
+#define OP_CollSeq 89
12820
+#define OP_Function0 90 /* synopsis: r[P3]=func(r[P2@P5]) */
12821
+#define OP_Function 91 /* synopsis: r[P3]=func(r[P2@P5]) */
12822
+#define OP_AddImm 92 /* synopsis: r[P1]=r[P1]+P2 */
12823
+#define OP_RealAffinity 93
12824
+#define OP_Cast 94 /* synopsis: affinity(r[P1]) */
12825
+#define OP_Permutation 95
12826
+#define OP_Compare 96 /* synopsis: r[P1@P3] <-> r[P2@P3] */
1280412827
#define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
12805
-#define OP_Affinity 98 /* synopsis: affinity(r[P1@P2]) */
12806
-#define OP_MakeRecord 99 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
12807
-#define OP_Count 100 /* synopsis: r[P2]=count() */
12808
-#define OP_ReadCookie 101
12809
-#define OP_SetCookie 102
12810
-#define OP_ReopenIdx 103 /* synopsis: root=P2 iDb=P3 */
12811
-#define OP_OpenRead 104 /* synopsis: root=P2 iDb=P3 */
12812
-#define OP_OpenWrite 105 /* synopsis: root=P2 iDb=P3 */
12813
-#define OP_OpenAutoindex 106 /* synopsis: nColumn=P2 */
12814
-#define OP_OpenEphemeral 107 /* synopsis: nColumn=P2 */
12815
-#define OP_SorterOpen 108
12816
-#define OP_SequenceTest 109 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
12817
-#define OP_OpenPseudo 110 /* synopsis: P3 columns in r[P2] */
12818
-#define OP_Close 111
12819
-#define OP_ColumnsUsed 112
12820
-#define OP_Sequence 113 /* synopsis: r[P2]=cursor[P1].ctr++ */
12821
-#define OP_NewRowid 114 /* synopsis: r[P2]=rowid */
12822
-#define OP_Insert 115 /* synopsis: intkey=r[P3] data=r[P2] */
12823
-#define OP_InsertInt 116 /* synopsis: intkey=P3 data=r[P2] */
12824
-#define OP_Delete 117
12825
-#define OP_ResetCount 118
12826
-#define OP_SorterCompare 119 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12827
-#define OP_SorterData 120 /* synopsis: r[P2]=data */
12828
-#define OP_RowData 121 /* synopsis: r[P2]=data */
12829
-#define OP_Rowid 122 /* synopsis: r[P2]=rowid */
12830
-#define OP_NullRow 123
12831
-#define OP_SorterInsert 124 /* synopsis: key=r[P2] */
12832
-#define OP_IdxInsert 125 /* synopsis: key=r[P2] */
12833
-#define OP_IdxDelete 126 /* synopsis: key=r[P2@P3] */
12834
-#define OP_Seek 127 /* synopsis: Move P3 to P1.rowid */
12835
-#define OP_IdxRowid 128 /* synopsis: r[P2]=rowid */
12836
-#define OP_Destroy 129
12837
-#define OP_Clear 130
12838
-#define OP_ResetSorter 131
12828
+#define OP_Column 98 /* synopsis: r[P3]=PX */
12829
+#define OP_Affinity 99 /* synopsis: affinity(r[P1@P2]) */
12830
+#define OP_MakeRecord 100 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
12831
+#define OP_Count 101 /* synopsis: r[P2]=count() */
12832
+#define OP_ReadCookie 102
12833
+#define OP_SetCookie 103
12834
+#define OP_ReopenIdx 104 /* synopsis: root=P2 iDb=P3 */
12835
+#define OP_OpenRead 105 /* synopsis: root=P2 iDb=P3 */
12836
+#define OP_OpenWrite 106 /* synopsis: root=P2 iDb=P3 */
12837
+#define OP_OpenAutoindex 107 /* synopsis: nColumn=P2 */
12838
+#define OP_OpenEphemeral 108 /* synopsis: nColumn=P2 */
12839
+#define OP_SorterOpen 109
12840
+#define OP_SequenceTest 110 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
12841
+#define OP_OpenPseudo 111 /* synopsis: P3 columns in r[P2] */
12842
+#define OP_Close 112
12843
+#define OP_ColumnsUsed 113
12844
+#define OP_Sequence 114 /* synopsis: r[P2]=cursor[P1].ctr++ */
12845
+#define OP_NewRowid 115 /* synopsis: r[P2]=rowid */
12846
+#define OP_Insert 116 /* synopsis: intkey=r[P3] data=r[P2] */
12847
+#define OP_InsertInt 117 /* synopsis: intkey=P3 data=r[P2] */
12848
+#define OP_Delete 118
12849
+#define OP_ResetCount 119
12850
+#define OP_SorterCompare 120 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12851
+#define OP_SorterData 121 /* synopsis: r[P2]=data */
12852
+#define OP_RowData 122 /* synopsis: r[P2]=data */
12853
+#define OP_Rowid 123 /* synopsis: r[P2]=rowid */
12854
+#define OP_NullRow 124
12855
+#define OP_SorterInsert 125 /* synopsis: key=r[P2] */
12856
+#define OP_IdxInsert 126 /* synopsis: key=r[P2] */
12857
+#define OP_IdxDelete 127 /* synopsis: key=r[P2@P3] */
12858
+#define OP_Seek 128 /* synopsis: Move P3 to P1.rowid */
12859
+#define OP_IdxRowid 129 /* synopsis: r[P2]=rowid */
12860
+#define OP_Destroy 130
12861
+#define OP_Clear 131
1283912862
#define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
12840
-#define OP_CreateIndex 133 /* synopsis: r[P2]=root iDb=P1 */
12841
-#define OP_CreateTable 134 /* synopsis: r[P2]=root iDb=P1 */
12842
-#define OP_ParseSchema 135
12843
-#define OP_LoadAnalysis 136
12844
-#define OP_DropTable 137
12845
-#define OP_DropIndex 138
12846
-#define OP_DropTrigger 139
12847
-#define OP_IntegrityCk 140
12848
-#define OP_RowSetAdd 141 /* synopsis: rowset(P1)=r[P2] */
12849
-#define OP_Param 142
12850
-#define OP_FkCounter 143 /* synopsis: fkctr[P1]+=P2 */
12851
-#define OP_MemMax 144 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12852
-#define OP_OffsetLimit 145 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12853
-#define OP_AggStep0 146 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12854
-#define OP_AggStep 147 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12855
-#define OP_AggFinal 148 /* synopsis: accum=r[P1] N=P2 */
12856
-#define OP_Expire 149
12857
-#define OP_TableLock 150 /* synopsis: iDb=P1 root=P2 write=P3 */
12858
-#define OP_VBegin 151
12859
-#define OP_VCreate 152
12860
-#define OP_VDestroy 153
12861
-#define OP_VOpen 154
12862
-#define OP_VColumn 155 /* synopsis: r[P3]=vcolumn(P2) */
12863
-#define OP_VRename 156
12864
-#define OP_Pagecount 157
12865
-#define OP_MaxPgcnt 158
12866
-#define OP_CursorHint 159
12867
-#define OP_Noop 160
12868
-#define OP_Explain 161
12863
+#define OP_ResetSorter 133
12864
+#define OP_CreateIndex 134 /* synopsis: r[P2]=root iDb=P1 */
12865
+#define OP_CreateTable 135 /* synopsis: r[P2]=root iDb=P1 */
12866
+#define OP_SqlExec 136
12867
+#define OP_ParseSchema 137
12868
+#define OP_LoadAnalysis 138
12869
+#define OP_DropTable 139
12870
+#define OP_DropIndex 140
12871
+#define OP_DropTrigger 141
12872
+#define OP_IntegrityCk 142
12873
+#define OP_RowSetAdd 143 /* synopsis: rowset(P1)=r[P2] */
12874
+#define OP_Param 144
12875
+#define OP_FkCounter 145 /* synopsis: fkctr[P1]+=P2 */
12876
+#define OP_MemMax 146 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12877
+#define OP_OffsetLimit 147 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12878
+#define OP_AggStep0 148 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12879
+#define OP_AggStep 149 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12880
+#define OP_AggFinal 150 /* synopsis: accum=r[P1] N=P2 */
12881
+#define OP_Expire 151
12882
+#define OP_TableLock 152 /* synopsis: iDb=P1 root=P2 write=P3 */
12883
+#define OP_VBegin 153
12884
+#define OP_VCreate 154
12885
+#define OP_VDestroy 155
12886
+#define OP_VOpen 156
12887
+#define OP_VColumn 157 /* synopsis: r[P3]=vcolumn(P2) */
12888
+#define OP_VRename 158
12889
+#define OP_Pagecount 159
12890
+#define OP_MaxPgcnt 160
12891
+#define OP_CursorHint 161
12892
+#define OP_Noop 162
12893
+#define OP_Explain 163
1286912894
1287012895
/* Properties such as "out2" or "jump" that are specified in
1287112896
** comments following the "case" for each opcode in the vdbe.c
1287212897
** are encoded into bitvectors as follows:
1287312898
*/
@@ -12883,32 +12908,32 @@
1288312908
/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x09,\
1288412909
/* 24 */ 0x09, 0x09, 0x09, 0x26, 0x26, 0x09, 0x09, 0x09,\
1288512910
/* 32 */ 0x09, 0x09, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
1288612911
/* 40 */ 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26, 0x26,\
1288712912
/* 48 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x01, 0x12, 0x01,\
12888
-/* 56 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x23, 0x0b,\
12889
-/* 64 */ 0x01, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01, 0x01,\
12890
-/* 72 */ 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10, 0x10,\
12891
-/* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00,\
12892
-/* 88 */ 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\
12893
-/* 96 */ 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
12913
+/* 56 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x23,\
12914
+/* 64 */ 0x0b, 0x01, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01,\
12915
+/* 72 */ 0x01, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10,\
12916
+/* 80 */ 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10,\
12917
+/* 88 */ 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00,\
12918
+/* 96 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
1289412919
/* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12895
-/* 112 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
12896
-/* 120 */ 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00, 0x00,\
12897
-/* 128 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00,\
12898
-/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00,\
12899
-/* 144 */ 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12900
-/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
12901
-/* 160 */ 0x00, 0x00,}
12920
+/* 112 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
12921
+/* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00,\
12922
+/* 128 */ 0x00, 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10,\
12923
+/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\
12924
+/* 144 */ 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00,\
12925
+/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
12926
+/* 160 */ 0x10, 0x00, 0x00, 0x00,}
1290212927
1290312928
/* The sqlite3P2Values() routine is able to run faster if it knows
1290412929
** the value of the largest JUMP opcode. The smaller the maximum
1290512930
** JUMP opcode the better, so the mkopcodeh.tcl script that
1290612931
** generated this include file strives to group all JUMP opcodes
1290712932
** together near the beginning of the list.
1290812933
*/
12909
-#define SQLITE_MX_JUMP_OPCODE 71 /* Maximum JUMP opcode */
12934
+#define SQLITE_MX_JUMP_OPCODE 72 /* Maximum JUMP opcode */
1291012935
1291112936
/************** End of opcodes.h *********************************************/
1291212937
/************** Continuing where we left off in vdbe.h ***********************/
1291312938
1291412939
/*
@@ -13868,11 +13893,11 @@
1386813893
** The "PRAGMA synchronous" statement also uses the zero-based numbers.
1386913894
** In other words, the zero-based numbers are used for all external interfaces
1387013895
** and the one-based values are used internally.
1387113896
*/
1387213897
#ifndef SQLITE_DEFAULT_SYNCHRONOUS
13873
-# define SQLITE_DEFAULT_SYNCHRONOUS (PAGER_SYNCHRONOUS_FULL-1)
13898
+# define SQLITE_DEFAULT_SYNCHRONOUS 2
1387413899
#endif
1387513900
#ifndef SQLITE_DEFAULT_WAL_SYNCHRONOUS
1387613901
# define SQLITE_DEFAULT_WAL_SYNCHRONOUS SQLITE_DEFAULT_SYNCHRONOUS
1387713902
#endif
1387813903
@@ -14074,10 +14099,11 @@
1407414099
u8 suppressErr; /* Do not issue error messages if true */
1407514100
u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */
1407614101
u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */
1407714102
u8 mTrace; /* zero or more SQLITE_TRACE flags */
1407814103
u8 skipBtreeMutex; /* True if no shared-cache backends */
14104
+ u8 nSqlExec; /* Number of pending OP_SqlExec opcodes */
1407914105
int nextPagesize; /* Pagesize after VACUUM if >0 */
1408014106
u32 magic; /* Magic number for detect library misuse */
1408114107
int nChange; /* Value returned by sqlite3_changes() */
1408214108
int nTotalChange; /* Value returned by sqlite3_total_changes() */
1408314109
int aLimit[SQLITE_N_LIMIT]; /* Limits */
@@ -14589,18 +14615,18 @@
1458914615
char *zColAff; /* String defining the affinity of each column */
1459014616
ExprList *pCheck; /* All CHECK constraints */
1459114617
/* ... also used as column name list in a VIEW */
1459214618
int tnum; /* Root BTree page for this table */
1459314619
u32 nTabRef; /* Number of pointers to this Table */
14620
+ u32 tabFlags; /* Mask of TF_* values */
1459414621
i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
1459514622
i16 nCol; /* Number of columns in this table */
1459614623
LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
1459714624
LogEst szTabRow; /* Estimated size of each table row in bytes */
1459814625
#ifdef SQLITE_ENABLE_COSTMULT
1459914626
LogEst costMult; /* Cost multiplier for using this table */
1460014627
#endif
14601
- u8 tabFlags; /* Mask of TF_* values */
1460214628
u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
1460314629
#ifndef SQLITE_OMIT_ALTERTABLE
1460414630
int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
1460514631
#endif
1460614632
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -14620,27 +14646,29 @@
1462014646
** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING
1462114647
** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden,
1462214648
** the TF_OOOHidden attribute would apply in this case. Such tables require
1462314649
** special handling during INSERT processing.
1462414650
*/
14625
-#define TF_Readonly 0x01 /* Read-only system table */
14626
-#define TF_Ephemeral 0x02 /* An ephemeral table */
14627
-#define TF_HasPrimaryKey 0x04 /* Table has a primary key */
14628
-#define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
14629
-#define TF_Virtual 0x10 /* Is a virtual table */
14630
-#define TF_WithoutRowid 0x20 /* No rowid. PRIMARY KEY is the key */
14631
-#define TF_NoVisibleRowid 0x40 /* No user-visible "rowid" column */
14632
-#define TF_OOOHidden 0x80 /* Out-of-Order hidden columns */
14633
-
14651
+#define TF_Readonly 0x0001 /* Read-only system table */
14652
+#define TF_Ephemeral 0x0002 /* An ephemeral table */
14653
+#define TF_HasPrimaryKey 0x0004 /* Table has a primary key */
14654
+#define TF_Autoincrement 0x0008 /* Integer primary key is autoincrement */
14655
+#define TF_HasStat1 0x0010 /* nRowLogEst set from sqlite_stat1 */
14656
+#define TF_WithoutRowid 0x0020 /* No rowid. PRIMARY KEY is the key */
14657
+#define TF_NoVisibleRowid 0x0040 /* No user-visible "rowid" column */
14658
+#define TF_OOOHidden 0x0080 /* Out-of-Order hidden columns */
14659
+#define TF_StatsUsed 0x0100 /* Query planner decisions affected by
14660
+ ** Index.aiRowLogEst[] values */
14661
+#define TF_HasNotNull 0x0200 /* Contains NOT NULL constraints */
1463414662
1463514663
/*
1463614664
** Test to see whether or not a table is a virtual table. This is
1463714665
** done as a macro so that it will be optimized out when virtual
1463814666
** table support is omitted from the build.
1463914667
*/
1464014668
#ifndef SQLITE_OMIT_VIRTUALTABLE
14641
-# define IsVirtual(X) (((X)->tabFlags & TF_Virtual)!=0)
14669
+# define IsVirtual(X) ((X)->nModuleArg)
1464214670
#else
1464314671
# define IsVirtual(X) 0
1464414672
#endif
1464514673
1464614674
/*
@@ -14871,10 +14899,11 @@
1487114899
unsigned bUnordered:1; /* Use this index for == or IN queries only */
1487214900
unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */
1487314901
unsigned isResized:1; /* True if resizeIndexObject() has been called */
1487414902
unsigned isCovering:1; /* True if this is a covering index */
1487514903
unsigned noSkipScan:1; /* Do not try to use skip-scan if true */
14904
+ unsigned hasStat1:1; /* aiRowLogEst values come from sqlite_stat1 */
1487614905
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
1487714906
int nSample; /* Number of elements in aSample[] */
1487814907
int nSampleCol; /* Size of IndexSample.anEq[] and so on */
1487914908
tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
1488014909
IndexSample *aSample; /* Samples of the left-most key */
@@ -15181,11 +15210,11 @@
1518115210
** form is used for name resolution with nested FROM clauses.
1518215211
*/
1518315212
struct ExprList {
1518415213
int nExpr; /* Number of expressions on the list */
1518515214
struct ExprList_item { /* For each expression in the list */
15186
- Expr *pExpr; /* The list of expressions */
15215
+ Expr *pExpr; /* The parse tree for this expression */
1518715216
char *zName; /* Token associated with this expression */
1518815217
char *zSpan; /* Original text of the expression */
1518915218
u8 sortOrder; /* 1 for DESC or 0 for ASC */
1519015219
unsigned done :1; /* A flag to indicate when processing is finished */
1519115220
unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
@@ -16504,10 +16533,11 @@
1650416533
SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
1650516534
SQLITE_PRIVATE void sqlite3Vacuum(Parse*,Token*);
1650616535
SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*, int);
1650716536
SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
1650816537
SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*, int);
16538
+SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*, Expr*, int);
1650916539
SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
1651016540
SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Expr*, Expr*, int);
1651116541
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
1651216542
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
1651316543
SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
@@ -17450,19 +17480,25 @@
1745017480
"COMPILER=gcc-" __VERSION__,
1745117481
#endif
1745217482
#if SQLITE_COVERAGE_TEST
1745317483
"COVERAGE_TEST",
1745417484
#endif
17455
-#if SQLITE_DEBUG
17485
+#ifdef SQLITE_DEBUG
1745617486
"DEBUG",
1745717487
#endif
1745817488
#if SQLITE_DEFAULT_LOCKING_MODE
1745917489
"DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE),
1746017490
#endif
1746117491
#if defined(SQLITE_DEFAULT_MMAP_SIZE) && !defined(SQLITE_DEFAULT_MMAP_SIZE_xc)
1746217492
"DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE),
1746317493
#endif
17494
+#if SQLITE_DEFAULT_SYNCHRONOUS
17495
+ "DEFAULT_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_SYNCHRONOUS),
17496
+#endif
17497
+#if SQLITE_DEFAULT_WAL_SYNCHRONOUS
17498
+ "DEFAULT_WAL_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_WAL_SYNCHRONOUS),
17499
+#endif
1746417500
#if SQLITE_DIRECT_OVERFLOW_READ
1746517501
"DIRECT_OVERFLOW_READ",
1746617502
#endif
1746717503
#if SQLITE_DISABLE_DIRSYNC
1746817504
"DISABLE_DIRSYNC",
@@ -18035,10 +18071,11 @@
1803518071
VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */
1803618072
Op *aOp; /* Program instructions for parent frame */
1803718073
i64 *anExec; /* Event counters from parent frame */
1803818074
Mem *aMem; /* Array of memory cells for parent frame */
1803918075
VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */
18076
+ u8 *aOnce; /* Bitmask used by OP_Once */
1804018077
void *token; /* Copy of SubProgram.token */
1804118078
i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
1804218079
AuxData *pAuxData; /* Linked list of auxdata allocations */
1804318080
int nCursor; /* Number of entries in apCsr */
1804418081
int pc; /* Program Counter in parent (calling) frame */
@@ -19505,22 +19542,23 @@
1950519542
**
1950619543
** Move the date backwards to the beginning of the current day,
1950719544
** or month or year.
1950819545
*/
1950919546
if( sqlite3_strnicmp(z, "start of ", 9)!=0 ) break;
19547
+ if( !p->validJD && !p->validYMD && !p->validHMS ) break;
1951019548
z += 9;
1951119549
computeYMD(p);
1951219550
p->validHMS = 1;
1951319551
p->h = p->m = 0;
1951419552
p->s = 0.0;
19553
+ p->rawS = 0;
1951519554
p->validTZ = 0;
1951619555
p->validJD = 0;
1951719556
if( sqlite3_stricmp(z,"month")==0 ){
1951819557
p->D = 1;
1951919558
rc = 0;
1952019559
}else if( sqlite3_stricmp(z,"year")==0 ){
19521
- computeYMD(p);
1952219560
p->M = 1;
1952319561
p->D = 1;
1952419562
rc = 0;
1952519563
}else if( sqlite3_stricmp(z,"day")==0 ){
1952619564
rc = 0;
@@ -20638,11 +20676,13 @@
2063820676
** Use the zone allocator available on apple products unless the
2063920677
** SQLITE_WITHOUT_ZONEMALLOC symbol is defined.
2064020678
*/
2064120679
#include <sys/sysctl.h>
2064220680
#include <malloc/malloc.h>
20681
+#ifdef SQLITE_MIGHT_BE_SINGLE_CORE
2064320682
#include <libkern/OSAtomic.h>
20683
+#endif /* SQLITE_MIGHT_BE_SINGLE_CORE */
2064420684
static malloc_zone_t* _sqliteZone_;
2064520685
#define SQLITE_MALLOC(x) malloc_zone_malloc(_sqliteZone_, (x))
2064620686
#define SQLITE_FREE(x) malloc_zone_free(_sqliteZone_, (x));
2064720687
#define SQLITE_REALLOC(x,y) malloc_zone_realloc(_sqliteZone_, (x), (y))
2064820688
#define SQLITE_MALLOCSIZE(x) \
@@ -20831,23 +20871,14 @@
2083120871
/* defer MT decisions to system malloc */
2083220872
_sqliteZone_ = malloc_default_zone();
2083320873
}else{
2083420874
/* only 1 core, use our own zone to contention over global locks,
2083520875
** e.g. we have our own dedicated locks */
20836
- bool success;
20837
- malloc_zone_t* newzone = malloc_create_zone(4096, 0);
20838
- malloc_set_zone_name(newzone, "Sqlite_Heap");
20839
- do{
20840
- success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone,
20841
- (void * volatile *)&_sqliteZone_);
20842
- }while(!_sqliteZone_);
20843
- if( !success ){
20844
- /* somebody registered a zone first */
20845
- malloc_destroy_zone(newzone);
20846
- }
20847
- }
20848
-#endif
20876
+ _sqliteZone_ = malloc_create_zone(4096, 0);
20877
+ malloc_set_zone_name(_sqliteZone_, "Sqlite_Heap");
20878
+ }
20879
+#endif /* defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC) */
2084920880
UNUSED_PARAMETER(NotUsed);
2085020881
return SQLITE_OK;
2085120882
}
2085220883
2085320884
/*
@@ -24050,12 +24081,12 @@
2405024081
#ifdef SQLITE_DEBUG
2405124082
assert( p->nRef>0 || p->owner==0 );
2405224083
p->owner = tid;
2405324084
p->nRef++;
2405424085
if( p->trace ){
24055
- OSTRACE(("ENTER-MUTEX tid=%lu, mutex=%p (%d), nRef=%d\n",
24056
- tid, p, p->trace, p->nRef));
24086
+ OSTRACE(("ENTER-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n",
24087
+ tid, p->id, p, p->trace, p->nRef));
2405724088
}
2405824089
#endif
2405924090
}
2406024091
2406124092
static int winMutexTry(sqlite3_mutex *p){
@@ -24093,12 +24124,12 @@
2409324124
#else
2409424125
UNUSED_PARAMETER(p);
2409524126
#endif
2409624127
#ifdef SQLITE_DEBUG
2409724128
if( p->trace ){
24098
- OSTRACE(("TRY-MUTEX tid=%lu, mutex=%p (%d), owner=%lu, nRef=%d, rc=%s\n",
24099
- tid, p, p->trace, p->owner, p->nRef, sqlite3ErrName(rc)));
24129
+ OSTRACE(("TRY-MUTEX tid=%lu, mutex(%d)=%p (%d), owner=%lu, nRef=%d, rc=%s\n",
24130
+ tid, p->id, p, p->trace, p->owner, p->nRef, sqlite3ErrName(rc)));
2410024131
}
2410124132
#endif
2410224133
return rc;
2410324134
}
2410424135
@@ -24122,12 +24153,12 @@
2412224153
#endif
2412324154
assert( winMutex_isInit==1 );
2412424155
LeaveCriticalSection(&p->mutex);
2412524156
#ifdef SQLITE_DEBUG
2412624157
if( p->trace ){
24127
- OSTRACE(("LEAVE-MUTEX tid=%lu, mutex=%p (%d), nRef=%d\n",
24128
- tid, p, p->trace, p->nRef));
24158
+ OSTRACE(("LEAVE-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n",
24159
+ tid, p->id, p, p->trace, p->nRef));
2412924160
}
2413024161
#endif
2413124162
}
2413224163
2413324164
SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void){
@@ -24383,10 +24414,17 @@
2438324414
** implementation of malloc_good_size(), which must be called in debug
2438424415
** mode and specifically when the DMD "Dark Matter Detector" is enabled
2438524416
** or else a crash results. Hence, do not attempt to optimize out the
2438624417
** following xRoundup() call. */
2438724418
nFull = sqlite3GlobalConfig.m.xRoundup(n);
24419
+
24420
+#ifdef SQLITE_MAX_MEMORY
24421
+ if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nFull>SQLITE_MAX_MEMORY ){
24422
+ *pp = 0;
24423
+ return;
24424
+ }
24425
+#endif
2438824426
2438924427
sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n);
2439024428
if( mem0.alarmThreshold>0 ){
2439124429
sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
2439224430
if( nUsed >= mem0.alarmThreshold - nFull ){
@@ -24572,11 +24610,11 @@
2457224610
return sqlite3GlobalConfig.m.xSize(p);
2457324611
}
2457424612
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
2457524613
assert( p!=0 );
2457624614
if( db==0 || !isLookaside(db,p) ){
24577
-#if SQLITE_DEBUG
24615
+#ifdef SQLITE_DEBUG
2457824616
if( db==0 ){
2457924617
assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
2458024618
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
2458124619
}else{
2458224620
assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
@@ -24633,11 +24671,11 @@
2463324671
measureAllocationSize(db, p);
2463424672
return;
2463524673
}
2463624674
if( isLookaside(db, p) ){
2463724675
LookasideSlot *pBuf = (LookasideSlot*)p;
24638
-#if SQLITE_DEBUG
24676
+#ifdef SQLITE_DEBUG
2463924677
/* Trash all content in the buffer being freed */
2464024678
memset(p, 0xaa, db->lookaside.sz);
2464124679
#endif
2464224680
pBuf->pNext = db->lookaside.pFree;
2464324681
db->lookaside.pFree = pBuf;
@@ -25002,11 +25040,11 @@
2500225040
2500325041
/*
2500425042
** Conversion types fall into various categories as defined by the
2500525043
** following enumeration.
2500625044
*/
25007
-#define etRADIX 0 /* Integer types. %d, %x, %o, and so forth */
25045
+#define etRADIX 0 /* non-decimal integer types. %x %o */
2500825046
#define etFLOAT 1 /* Floating point. %f */
2500925047
#define etEXP 2 /* Exponentional notation. %e and %E */
2501025048
#define etGENERIC 3 /* Floating or exponential, depending on exponent. %g */
2501125049
#define etSIZE 4 /* Return number of characters processed so far. %n */
2501225050
#define etSTRING 5 /* Strings. %s */
@@ -25020,12 +25058,13 @@
2502025058
#define etTOKEN 11 /* a pointer to a Token structure */
2502125059
#define etSRCLIST 12 /* a pointer to a SrcList */
2502225060
#define etPOINTER 13 /* The %p conversion */
2502325061
#define etSQLESCAPE3 14 /* %w -> Strings with '\"' doubled */
2502425062
#define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */
25063
+#define etDECIMAL 16 /* %d or %u, but not %x, %o */
2502525064
25026
-#define etINVALID 16 /* Any unrecognized conversion type */
25065
+#define etINVALID 17 /* Any unrecognized conversion type */
2502725066
2502825067
2502925068
/*
2503025069
** An "etByte" is an 8-bit unsigned value.
2503125070
*/
@@ -25045,40 +25084,40 @@
2504525084
} et_info;
2504625085
2504725086
/*
2504825087
** Allowed values for et_info.flags
2504925088
*/
25050
-#define FLAG_SIGNED 1 /* True if the value to convert is signed */
25051
-#define FLAG_STRING 4 /* Allow infinity precision */
25089
+#define FLAG_SIGNED 1 /* True if the value to convert is signed */
25090
+#define FLAG_STRING 4 /* Allow infinite precision */
2505225091
2505325092
2505425093
/*
2505525094
** The following table is searched linearly, so it is good to put the
2505625095
** most frequently used conversion types first.
2505725096
*/
2505825097
static const char aDigits[] = "0123456789ABCDEF0123456789abcdef";
2505925098
static const char aPrefix[] = "-x0\000X0";
2506025099
static const et_info fmtinfo[] = {
25061
- { 'd', 10, 1, etRADIX, 0, 0 },
25100
+ { 'd', 10, 1, etDECIMAL, 0, 0 },
2506225101
{ 's', 0, 4, etSTRING, 0, 0 },
2506325102
{ 'g', 0, 1, etGENERIC, 30, 0 },
2506425103
{ 'z', 0, 4, etDYNSTRING, 0, 0 },
2506525104
{ 'q', 0, 4, etSQLESCAPE, 0, 0 },
2506625105
{ 'Q', 0, 4, etSQLESCAPE2, 0, 0 },
2506725106
{ 'w', 0, 4, etSQLESCAPE3, 0, 0 },
2506825107
{ 'c', 0, 0, etCHARX, 0, 0 },
2506925108
{ 'o', 8, 0, etRADIX, 0, 2 },
25070
- { 'u', 10, 0, etRADIX, 0, 0 },
25109
+ { 'u', 10, 0, etDECIMAL, 0, 0 },
2507125110
{ 'x', 16, 0, etRADIX, 16, 1 },
2507225111
{ 'X', 16, 0, etRADIX, 0, 4 },
2507325112
#ifndef SQLITE_OMIT_FLOATING_POINT
2507425113
{ 'f', 0, 1, etFLOAT, 0, 0 },
2507525114
{ 'e', 0, 1, etEXP, 30, 0 },
2507625115
{ 'E', 0, 1, etEXP, 14, 0 },
2507725116
{ 'G', 0, 1, etGENERIC, 14, 0 },
2507825117
#endif
25079
- { 'i', 10, 1, etRADIX, 0, 0 },
25118
+ { 'i', 10, 1, etDECIMAL, 0, 0 },
2508025119
{ 'n', 0, 0, etSIZE, 0, 0 },
2508125120
{ '%', 0, 0, etPERCENT, 0, 0 },
2508225121
{ 'p', 16, 0, etPOINTER, 0, 1 },
2508325122
2508425123
/* All the rest are undocumented and are for internal use only */
@@ -25166,18 +25205,17 @@
2516625205
int precision; /* Precision of the current field */
2516725206
int length; /* Length of the field */
2516825207
int idx; /* A general purpose loop counter */
2516925208
int width; /* Width of the current field */
2517025209
etByte flag_leftjustify; /* True if "-" flag is present */
25171
- etByte flag_plussign; /* True if "+" flag is present */
25172
- etByte flag_blanksign; /* True if " " flag is present */
25210
+ etByte flag_prefix; /* '+' or ' ' or 0 for prefix */
2517325211
etByte flag_alternateform; /* True if "#" flag is present */
2517425212
etByte flag_altform2; /* True if "!" flag is present */
2517525213
etByte flag_zeropad; /* True if field width constant starts with zero */
25176
- etByte flag_long; /* True if "l" flag is present */
25177
- etByte flag_longlong; /* True if the "ll" flag is present */
25214
+ etByte flag_long; /* 1 for the "l" flag, 2 for "ll", 0 by default */
2517825215
etByte done; /* Loop termination flag */
25216
+ etByte cThousand; /* Thousands separator for %d and %u */
2517925217
etByte xtype = etINVALID; /* Conversion paradigm */
2518025218
u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */
2518125219
char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
2518225220
sqlite_uint64 longvalue; /* Value for integer types */
2518325221
LONGDOUBLE_TYPE realvalue; /* Value for real types */
@@ -25216,21 +25254,22 @@
2521625254
if( (c=(*++fmt))==0 ){
2521725255
sqlite3StrAccumAppend(pAccum, "%", 1);
2521825256
break;
2521925257
}
2522025258
/* Find out what flags are present */
25221
- flag_leftjustify = flag_plussign = flag_blanksign =
25259
+ flag_leftjustify = flag_prefix = cThousand =
2522225260
flag_alternateform = flag_altform2 = flag_zeropad = 0;
2522325261
done = 0;
2522425262
do{
2522525263
switch( c ){
2522625264
case '-': flag_leftjustify = 1; break;
25227
- case '+': flag_plussign = 1; break;
25228
- case ' ': flag_blanksign = 1; break;
25265
+ case '+': flag_prefix = '+'; break;
25266
+ case ' ': flag_prefix = ' '; break;
2522925267
case '#': flag_alternateform = 1; break;
2523025268
case '!': flag_altform2 = 1; break;
2523125269
case '0': flag_zeropad = 1; break;
25270
+ case ',': cThousand = ','; break;
2523225271
default: done = 1; break;
2523325272
}
2523425273
}while( !done && (c=(*++fmt))!=0 );
2523525274
/* Get the field width */
2523625275
if( c=='*' ){
@@ -25296,17 +25335,15 @@
2529625335
/* Get the conversion type modifier */
2529725336
if( c=='l' ){
2529825337
flag_long = 1;
2529925338
c = *++fmt;
2530025339
if( c=='l' ){
25301
- flag_longlong = 1;
25340
+ flag_long = 2;
2530225341
c = *++fmt;
25303
- }else{
25304
- flag_longlong = 0;
2530525342
}
2530625343
}else{
25307
- flag_long = flag_longlong = 0;
25344
+ flag_long = 0;
2530825345
}
2530925346
/* Fetch the info entry for the field */
2531025347
infop = &fmtinfo[0];
2531125348
xtype = etINVALID;
2531225349
for(idx=0; idx<ArraySize(fmtinfo); idx++){
@@ -25320,41 +25357,42 @@
2532025357
/*
2532125358
** At this point, variables are initialized as follows:
2532225359
**
2532325360
** flag_alternateform TRUE if a '#' is present.
2532425361
** flag_altform2 TRUE if a '!' is present.
25325
- ** flag_plussign TRUE if a '+' is present.
25362
+ ** flag_prefix '+' or ' ' or zero
2532625363
** flag_leftjustify TRUE if a '-' is present or if the
2532725364
** field width was negative.
2532825365
** flag_zeropad TRUE if the width began with 0.
25329
- ** flag_long TRUE if the letter 'l' (ell) prefixed
25330
- ** the conversion character.
25331
- ** flag_longlong TRUE if the letter 'll' (ell ell) prefixed
25332
- ** the conversion character.
25333
- ** flag_blanksign TRUE if a ' ' is present.
25366
+ ** flag_long 1 for "l", 2 for "ll"
2533425367
** width The specified field width. This is
2533525368
** always non-negative. Zero is the default.
2533625369
** precision The specified precision. The default
2533725370
** is -1.
2533825371
** xtype The class of the conversion.
2533925372
** infop Pointer to the appropriate info struct.
2534025373
*/
2534125374
switch( xtype ){
2534225375
case etPOINTER:
25343
- flag_longlong = sizeof(char*)==sizeof(i64);
25344
- flag_long = sizeof(char*)==sizeof(long int);
25376
+ flag_long = sizeof(char*)==sizeof(i64) ? 2 :
25377
+ sizeof(char*)==sizeof(long int) ? 1 : 0;
2534525378
/* Fall through into the next case */
2534625379
case etORDINAL:
25347
- case etRADIX:
25380
+ case etRADIX:
25381
+ cThousand = 0;
25382
+ /* Fall through into the next case */
25383
+ case etDECIMAL:
2534825384
if( infop->flags & FLAG_SIGNED ){
2534925385
i64 v;
2535025386
if( bArgList ){
2535125387
v = getIntArg(pArgList);
25352
- }else if( flag_longlong ){
25353
- v = va_arg(ap,i64);
2535425388
}else if( flag_long ){
25355
- v = va_arg(ap,long int);
25389
+ if( flag_long==2 ){
25390
+ v = va_arg(ap,i64) ;
25391
+ }else{
25392
+ v = va_arg(ap,long int);
25393
+ }
2535625394
}else{
2535725395
v = va_arg(ap,int);
2535825396
}
2535925397
if( v<0 ){
2536025398
if( v==SMALLEST_INT64 ){
@@ -25363,40 +25401,41 @@
2536325401
longvalue = -v;
2536425402
}
2536525403
prefix = '-';
2536625404
}else{
2536725405
longvalue = v;
25368
- if( flag_plussign ) prefix = '+';
25369
- else if( flag_blanksign ) prefix = ' ';
25370
- else prefix = 0;
25406
+ prefix = flag_prefix;
2537125407
}
2537225408
}else{
2537325409
if( bArgList ){
2537425410
longvalue = (u64)getIntArg(pArgList);
25375
- }else if( flag_longlong ){
25376
- longvalue = va_arg(ap,u64);
2537725411
}else if( flag_long ){
25378
- longvalue = va_arg(ap,unsigned long int);
25412
+ if( flag_long==2 ){
25413
+ longvalue = va_arg(ap,u64);
25414
+ }else{
25415
+ longvalue = va_arg(ap,unsigned long int);
25416
+ }
2537925417
}else{
2538025418
longvalue = va_arg(ap,unsigned int);
2538125419
}
2538225420
prefix = 0;
2538325421
}
2538425422
if( longvalue==0 ) flag_alternateform = 0;
2538525423
if( flag_zeropad && precision<width-(prefix!=0) ){
2538625424
precision = width-(prefix!=0);
2538725425
}
25388
- if( precision<etBUFSIZE-10 ){
25426
+ if( precision<etBUFSIZE-10-etBUFSIZE/3 ){
2538925427
nOut = etBUFSIZE;
2539025428
zOut = buf;
2539125429
}else{
25392
- nOut = precision + 10;
25393
- zOut = zExtra = sqlite3Malloc( nOut );
25430
+ u64 n = (u64)precision + 10 + precision/3;
25431
+ zOut = zExtra = sqlite3Malloc( n );
2539425432
if( zOut==0 ){
2539525433
setStrAccumError(pAccum, STRACCUM_NOMEM);
2539625434
return;
2539725435
}
25436
+ nOut = (int)n;
2539825437
}
2539925438
bufpt = &zOut[nOut-1];
2540025439
if( xtype==etORDINAL ){
2540125440
static const char zOrd[] = "thstndrd";
2540225441
int x = (int)(longvalue % 10);
@@ -25413,12 +25452,27 @@
2541325452
*(--bufpt) = cset[longvalue%base];
2541425453
longvalue = longvalue/base;
2541525454
}while( longvalue>0 );
2541625455
}
2541725456
length = (int)(&zOut[nOut-1]-bufpt);
25418
- for(idx=precision-length; idx>0; idx--){
25457
+ while( precision>length ){
2541925458
*(--bufpt) = '0'; /* Zero pad */
25459
+ length++;
25460
+ }
25461
+ if( cThousand ){
25462
+ int nn = (length - 1)/3; /* Number of "," to insert */
25463
+ int ix = (length - 1)%3 + 1;
25464
+ bufpt -= nn;
25465
+ for(idx=0; nn>0; idx++){
25466
+ bufpt[idx] = bufpt[idx+nn];
25467
+ ix--;
25468
+ if( ix==0 ){
25469
+ bufpt[++idx] = cThousand;
25470
+ nn--;
25471
+ ix = 3;
25472
+ }
25473
+ }
2542025474
}
2542125475
if( prefix ) *(--bufpt) = prefix; /* Add sign */
2542225476
if( flag_alternateform && infop->prefix ){ /* Add "0" or "0x" */
2542325477
const char *pre;
2542425478
char x;
@@ -25441,13 +25495,11 @@
2544125495
if( precision<0 ) precision = 6; /* Set default precision */
2544225496
if( realvalue<0.0 ){
2544325497
realvalue = -realvalue;
2544425498
prefix = '-';
2544525499
}else{
25446
- if( flag_plussign ) prefix = '+';
25447
- else if( flag_blanksign ) prefix = ' ';
25448
- else prefix = 0;
25500
+ prefix = flag_prefix;
2544925501
}
2545025502
if( xtype==etGENERIC && precision>0 ) precision--;
2545125503
testcase( precision>0xfff );
2545225504
for(idx=precision&0xfff, rounder=0.5; idx>0; idx--, rounder*=0.1){}
2545325505
if( xtype==etFLOAT ) realvalue += rounder;
@@ -26215,10 +26267,14 @@
2621526267
** Generate a human-readable description of a Select object.
2621626268
*/
2621726269
SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
2621826270
int n = 0;
2621926271
int cnt = 0;
26272
+ if( p==0 ){
26273
+ sqlite3TreeViewLine(pView, "nil-SELECT");
26274
+ return;
26275
+ }
2622026276
pView = sqlite3TreeViewPush(pView, moreToFollow);
2622126277
if( p->pWith ){
2622226278
sqlite3TreeViewWith(pView, p->pWith, 1);
2622326279
cnt = 1;
2622426280
sqlite3TreeViewPush(pView, 1);
@@ -29464,117 +29520,119 @@
2946429520
/* 50 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
2946529521
/* 51 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
2946629522
/* 52 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
2946729523
/* 53 */ "Last" OpHelp(""),
2946829524
/* 54 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
29469
- /* 55 */ "SorterSort" OpHelp(""),
29470
- /* 56 */ "Sort" OpHelp(""),
29471
- /* 57 */ "Rewind" OpHelp(""),
29472
- /* 58 */ "IdxLE" OpHelp("key=r[P3@P4]"),
29473
- /* 59 */ "IdxGT" OpHelp("key=r[P3@P4]"),
29474
- /* 60 */ "IdxLT" OpHelp("key=r[P3@P4]"),
29475
- /* 61 */ "IdxGE" OpHelp("key=r[P3@P4]"),
29476
- /* 62 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
29477
- /* 63 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
29478
- /* 64 */ "Program" OpHelp(""),
29479
- /* 65 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
29480
- /* 66 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
29481
- /* 67 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
29482
- /* 68 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
29483
- /* 69 */ "IncrVacuum" OpHelp(""),
29484
- /* 70 */ "VNext" OpHelp(""),
29485
- /* 71 */ "Init" OpHelp("Start at P2"),
29486
- /* 72 */ "Return" OpHelp(""),
29487
- /* 73 */ "EndCoroutine" OpHelp(""),
29488
- /* 74 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
29489
- /* 75 */ "Halt" OpHelp(""),
29490
- /* 76 */ "Integer" OpHelp("r[P2]=P1"),
29491
- /* 77 */ "Int64" OpHelp("r[P2]=P4"),
29492
- /* 78 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
29493
- /* 79 */ "Null" OpHelp("r[P2..P3]=NULL"),
29494
- /* 80 */ "SoftNull" OpHelp("r[P1]=NULL"),
29495
- /* 81 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
29496
- /* 82 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
29497
- /* 83 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
29498
- /* 84 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
29499
- /* 85 */ "SCopy" OpHelp("r[P2]=r[P1]"),
29500
- /* 86 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
29501
- /* 87 */ "ResultRow" OpHelp("output=r[P1@P2]"),
29502
- /* 88 */ "CollSeq" OpHelp(""),
29503
- /* 89 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
29504
- /* 90 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
29505
- /* 91 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
29506
- /* 92 */ "RealAffinity" OpHelp(""),
29507
- /* 93 */ "Cast" OpHelp("affinity(r[P1])"),
29508
- /* 94 */ "Permutation" OpHelp(""),
29509
- /* 95 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
29510
- /* 96 */ "Column" OpHelp("r[P3]=PX"),
29525
+ /* 55 */ "IfSmaller" OpHelp(""),
29526
+ /* 56 */ "SorterSort" OpHelp(""),
29527
+ /* 57 */ "Sort" OpHelp(""),
29528
+ /* 58 */ "Rewind" OpHelp(""),
29529
+ /* 59 */ "IdxLE" OpHelp("key=r[P3@P4]"),
29530
+ /* 60 */ "IdxGT" OpHelp("key=r[P3@P4]"),
29531
+ /* 61 */ "IdxLT" OpHelp("key=r[P3@P4]"),
29532
+ /* 62 */ "IdxGE" OpHelp("key=r[P3@P4]"),
29533
+ /* 63 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
29534
+ /* 64 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
29535
+ /* 65 */ "Program" OpHelp(""),
29536
+ /* 66 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
29537
+ /* 67 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
29538
+ /* 68 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
29539
+ /* 69 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
29540
+ /* 70 */ "IncrVacuum" OpHelp(""),
29541
+ /* 71 */ "VNext" OpHelp(""),
29542
+ /* 72 */ "Init" OpHelp("Start at P2"),
29543
+ /* 73 */ "Return" OpHelp(""),
29544
+ /* 74 */ "EndCoroutine" OpHelp(""),
29545
+ /* 75 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
29546
+ /* 76 */ "Halt" OpHelp(""),
29547
+ /* 77 */ "Integer" OpHelp("r[P2]=P1"),
29548
+ /* 78 */ "Int64" OpHelp("r[P2]=P4"),
29549
+ /* 79 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
29550
+ /* 80 */ "Null" OpHelp("r[P2..P3]=NULL"),
29551
+ /* 81 */ "SoftNull" OpHelp("r[P1]=NULL"),
29552
+ /* 82 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
29553
+ /* 83 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
29554
+ /* 84 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
29555
+ /* 85 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
29556
+ /* 86 */ "SCopy" OpHelp("r[P2]=r[P1]"),
29557
+ /* 87 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
29558
+ /* 88 */ "ResultRow" OpHelp("output=r[P1@P2]"),
29559
+ /* 89 */ "CollSeq" OpHelp(""),
29560
+ /* 90 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
29561
+ /* 91 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
29562
+ /* 92 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
29563
+ /* 93 */ "RealAffinity" OpHelp(""),
29564
+ /* 94 */ "Cast" OpHelp("affinity(r[P1])"),
29565
+ /* 95 */ "Permutation" OpHelp(""),
29566
+ /* 96 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
2951129567
/* 97 */ "String8" OpHelp("r[P2]='P4'"),
29512
- /* 98 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
29513
- /* 99 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
29514
- /* 100 */ "Count" OpHelp("r[P2]=count()"),
29515
- /* 101 */ "ReadCookie" OpHelp(""),
29516
- /* 102 */ "SetCookie" OpHelp(""),
29517
- /* 103 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
29518
- /* 104 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
29519
- /* 105 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
29520
- /* 106 */ "OpenAutoindex" OpHelp("nColumn=P2"),
29521
- /* 107 */ "OpenEphemeral" OpHelp("nColumn=P2"),
29522
- /* 108 */ "SorterOpen" OpHelp(""),
29523
- /* 109 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
29524
- /* 110 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
29525
- /* 111 */ "Close" OpHelp(""),
29526
- /* 112 */ "ColumnsUsed" OpHelp(""),
29527
- /* 113 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
29528
- /* 114 */ "NewRowid" OpHelp("r[P2]=rowid"),
29529
- /* 115 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
29530
- /* 116 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
29531
- /* 117 */ "Delete" OpHelp(""),
29532
- /* 118 */ "ResetCount" OpHelp(""),
29533
- /* 119 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
29534
- /* 120 */ "SorterData" OpHelp("r[P2]=data"),
29535
- /* 121 */ "RowData" OpHelp("r[P2]=data"),
29536
- /* 122 */ "Rowid" OpHelp("r[P2]=rowid"),
29537
- /* 123 */ "NullRow" OpHelp(""),
29538
- /* 124 */ "SorterInsert" OpHelp("key=r[P2]"),
29539
- /* 125 */ "IdxInsert" OpHelp("key=r[P2]"),
29540
- /* 126 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
29541
- /* 127 */ "Seek" OpHelp("Move P3 to P1.rowid"),
29542
- /* 128 */ "IdxRowid" OpHelp("r[P2]=rowid"),
29543
- /* 129 */ "Destroy" OpHelp(""),
29544
- /* 130 */ "Clear" OpHelp(""),
29545
- /* 131 */ "ResetSorter" OpHelp(""),
29568
+ /* 98 */ "Column" OpHelp("r[P3]=PX"),
29569
+ /* 99 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
29570
+ /* 100 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
29571
+ /* 101 */ "Count" OpHelp("r[P2]=count()"),
29572
+ /* 102 */ "ReadCookie" OpHelp(""),
29573
+ /* 103 */ "SetCookie" OpHelp(""),
29574
+ /* 104 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
29575
+ /* 105 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
29576
+ /* 106 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
29577
+ /* 107 */ "OpenAutoindex" OpHelp("nColumn=P2"),
29578
+ /* 108 */ "OpenEphemeral" OpHelp("nColumn=P2"),
29579
+ /* 109 */ "SorterOpen" OpHelp(""),
29580
+ /* 110 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
29581
+ /* 111 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
29582
+ /* 112 */ "Close" OpHelp(""),
29583
+ /* 113 */ "ColumnsUsed" OpHelp(""),
29584
+ /* 114 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
29585
+ /* 115 */ "NewRowid" OpHelp("r[P2]=rowid"),
29586
+ /* 116 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
29587
+ /* 117 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
29588
+ /* 118 */ "Delete" OpHelp(""),
29589
+ /* 119 */ "ResetCount" OpHelp(""),
29590
+ /* 120 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
29591
+ /* 121 */ "SorterData" OpHelp("r[P2]=data"),
29592
+ /* 122 */ "RowData" OpHelp("r[P2]=data"),
29593
+ /* 123 */ "Rowid" OpHelp("r[P2]=rowid"),
29594
+ /* 124 */ "NullRow" OpHelp(""),
29595
+ /* 125 */ "SorterInsert" OpHelp("key=r[P2]"),
29596
+ /* 126 */ "IdxInsert" OpHelp("key=r[P2]"),
29597
+ /* 127 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
29598
+ /* 128 */ "Seek" OpHelp("Move P3 to P1.rowid"),
29599
+ /* 129 */ "IdxRowid" OpHelp("r[P2]=rowid"),
29600
+ /* 130 */ "Destroy" OpHelp(""),
29601
+ /* 131 */ "Clear" OpHelp(""),
2954629602
/* 132 */ "Real" OpHelp("r[P2]=P4"),
29547
- /* 133 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
29548
- /* 134 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
29549
- /* 135 */ "ParseSchema" OpHelp(""),
29550
- /* 136 */ "LoadAnalysis" OpHelp(""),
29551
- /* 137 */ "DropTable" OpHelp(""),
29552
- /* 138 */ "DropIndex" OpHelp(""),
29553
- /* 139 */ "DropTrigger" OpHelp(""),
29554
- /* 140 */ "IntegrityCk" OpHelp(""),
29555
- /* 141 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
29556
- /* 142 */ "Param" OpHelp(""),
29557
- /* 143 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
29558
- /* 144 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
29559
- /* 145 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
29560
- /* 146 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
29561
- /* 147 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
29562
- /* 148 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
29563
- /* 149 */ "Expire" OpHelp(""),
29564
- /* 150 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
29565
- /* 151 */ "VBegin" OpHelp(""),
29566
- /* 152 */ "VCreate" OpHelp(""),
29567
- /* 153 */ "VDestroy" OpHelp(""),
29568
- /* 154 */ "VOpen" OpHelp(""),
29569
- /* 155 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
29570
- /* 156 */ "VRename" OpHelp(""),
29571
- /* 157 */ "Pagecount" OpHelp(""),
29572
- /* 158 */ "MaxPgcnt" OpHelp(""),
29573
- /* 159 */ "CursorHint" OpHelp(""),
29574
- /* 160 */ "Noop" OpHelp(""),
29575
- /* 161 */ "Explain" OpHelp(""),
29603
+ /* 133 */ "ResetSorter" OpHelp(""),
29604
+ /* 134 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
29605
+ /* 135 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
29606
+ /* 136 */ "SqlExec" OpHelp(""),
29607
+ /* 137 */ "ParseSchema" OpHelp(""),
29608
+ /* 138 */ "LoadAnalysis" OpHelp(""),
29609
+ /* 139 */ "DropTable" OpHelp(""),
29610
+ /* 140 */ "DropIndex" OpHelp(""),
29611
+ /* 141 */ "DropTrigger" OpHelp(""),
29612
+ /* 142 */ "IntegrityCk" OpHelp(""),
29613
+ /* 143 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
29614
+ /* 144 */ "Param" OpHelp(""),
29615
+ /* 145 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
29616
+ /* 146 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
29617
+ /* 147 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
29618
+ /* 148 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
29619
+ /* 149 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
29620
+ /* 150 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
29621
+ /* 151 */ "Expire" OpHelp(""),
29622
+ /* 152 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
29623
+ /* 153 */ "VBegin" OpHelp(""),
29624
+ /* 154 */ "VCreate" OpHelp(""),
29625
+ /* 155 */ "VDestroy" OpHelp(""),
29626
+ /* 156 */ "VOpen" OpHelp(""),
29627
+ /* 157 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
29628
+ /* 158 */ "VRename" OpHelp(""),
29629
+ /* 159 */ "Pagecount" OpHelp(""),
29630
+ /* 160 */ "MaxPgcnt" OpHelp(""),
29631
+ /* 161 */ "CursorHint" OpHelp(""),
29632
+ /* 162 */ "Noop" OpHelp(""),
29633
+ /* 163 */ "Explain" OpHelp(""),
2957629634
};
2957729635
return azName[i];
2957829636
}
2957929637
#endif
2958029638
@@ -37952,46 +38010,84 @@
3795238010
* be freed immediately and any attempt to access any of that freed
3795338011
* data will almost certainly result in an immediate access violation.
3795438012
******************************************************************************
3795538013
*/
3795638014
#ifndef SQLITE_WIN32_HEAP_CREATE
37957
-# define SQLITE_WIN32_HEAP_CREATE (TRUE)
38015
+# define SQLITE_WIN32_HEAP_CREATE (TRUE)
38016
+#endif
38017
+
38018
+/*
38019
+ * This is the maximum possible initial size of the Win32-specific heap, in
38020
+ * bytes.
38021
+ */
38022
+#ifndef SQLITE_WIN32_HEAP_MAX_INIT_SIZE
38023
+# define SQLITE_WIN32_HEAP_MAX_INIT_SIZE (4294967295U)
38024
+#endif
38025
+
38026
+/*
38027
+ * This is the extra space for the initial size of the Win32-specific heap,
38028
+ * in bytes. This value may be zero.
38029
+ */
38030
+#ifndef SQLITE_WIN32_HEAP_INIT_EXTRA
38031
+# define SQLITE_WIN32_HEAP_INIT_EXTRA (4194304)
38032
+#endif
38033
+
38034
+/*
38035
+ * Calculate the maximum legal cache size, in pages, based on the maximum
38036
+ * possible initial heap size and the default page size, setting aside the
38037
+ * needed extra space.
38038
+ */
38039
+#ifndef SQLITE_WIN32_MAX_CACHE_SIZE
38040
+# define SQLITE_WIN32_MAX_CACHE_SIZE (((SQLITE_WIN32_HEAP_MAX_INIT_SIZE) - \
38041
+ (SQLITE_WIN32_HEAP_INIT_EXTRA)) / \
38042
+ (SQLITE_DEFAULT_PAGE_SIZE))
3795838043
#endif
3795938044
3796038045
/*
3796138046
* This is cache size used in the calculation of the initial size of the
3796238047
* Win32-specific heap. It cannot be negative.
3796338048
*/
3796438049
#ifndef SQLITE_WIN32_CACHE_SIZE
3796538050
# if SQLITE_DEFAULT_CACHE_SIZE>=0
37966
-# define SQLITE_WIN32_CACHE_SIZE (SQLITE_DEFAULT_CACHE_SIZE)
38051
+# define SQLITE_WIN32_CACHE_SIZE (SQLITE_DEFAULT_CACHE_SIZE)
3796738052
# else
37968
-# define SQLITE_WIN32_CACHE_SIZE (-(SQLITE_DEFAULT_CACHE_SIZE))
38053
+# define SQLITE_WIN32_CACHE_SIZE (-(SQLITE_DEFAULT_CACHE_SIZE))
3796938054
# endif
3797038055
#endif
3797138056
38057
+/*
38058
+ * Make sure that the calculated cache size, in pages, cannot cause the
38059
+ * initial size of the Win32-specific heap to exceed the maximum amount
38060
+ * of memory that can be specified in the call to HeapCreate.
38061
+ */
38062
+#if SQLITE_WIN32_CACHE_SIZE>SQLITE_WIN32_MAX_CACHE_SIZE
38063
+# undef SQLITE_WIN32_CACHE_SIZE
38064
+# define SQLITE_WIN32_CACHE_SIZE (2000)
38065
+#endif
38066
+
3797238067
/*
3797338068
* The initial size of the Win32-specific heap. This value may be zero.
3797438069
*/
3797538070
#ifndef SQLITE_WIN32_HEAP_INIT_SIZE
37976
-# define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_WIN32_CACHE_SIZE) * \
37977
- (SQLITE_DEFAULT_PAGE_SIZE) + 4194304)
38071
+# define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_WIN32_CACHE_SIZE) * \
38072
+ (SQLITE_DEFAULT_PAGE_SIZE) + \
38073
+ (SQLITE_WIN32_HEAP_INIT_EXTRA))
3797838074
#endif
3797938075
3798038076
/*
3798138077
* The maximum size of the Win32-specific heap. This value may be zero.
3798238078
*/
3798338079
#ifndef SQLITE_WIN32_HEAP_MAX_SIZE
37984
-# define SQLITE_WIN32_HEAP_MAX_SIZE (0)
38080
+# define SQLITE_WIN32_HEAP_MAX_SIZE (0)
3798538081
#endif
3798638082
3798738083
/*
3798838084
* The extra flags to use in calls to the Win32 heap APIs. This value may be
3798938085
* zero for the default behavior.
3799038086
*/
3799138087
#ifndef SQLITE_WIN32_HEAP_FLAGS
37992
-# define SQLITE_WIN32_HEAP_FLAGS (0)
38088
+# define SQLITE_WIN32_HEAP_FLAGS (0)
3799338089
#endif
3799438090
3799538091
3799638092
/*
3799738093
** The winMemData structure stores information required by the Win32-specific
@@ -44084,11 +44180,11 @@
4408444180
** This routine is for use inside of assert() statements only. For
4408544181
** example:
4408644182
**
4408744183
** assert( sqlite3PcachePageSanity(pPg) );
4408844184
*/
44089
-#if SQLITE_DEBUG
44185
+#ifdef SQLITE_DEBUG
4409044186
SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr *pPg){
4409144187
PCache *pCache;
4409244188
assert( pPg!=0 );
4409344189
assert( pPg->pgno>0 || pPg->pPager==0 ); /* Page number is 1 or more */
4409444190
pCache = pPg->pCache;
@@ -60177,21 +60273,22 @@
6017760273
}
6017860274
#endif
6017960275
6018060276
6018160277
/*
60182
-** Defragment the page given. All Cells are moved to the
60183
-** end of the page and all free space is collected into one
60184
-** big FreeBlk that occurs in between the header and cell
60185
-** pointer array and the cell content area.
60278
+** Defragment the page given. This routine reorganizes cells within the
60279
+** page so that there are no free-blocks on the free-block list.
60280
+**
60281
+** Parameter nMaxFrag is the maximum amount of fragmented space that may be
60282
+** present in the page after this routine returns.
6018660283
**
6018760284
** EVIDENCE-OF: R-44582-60138 SQLite may from time to time reorganize a
6018860285
** b-tree page so that there are no freeblocks or fragment bytes, all
6018960286
** unused bytes are contained in the unallocated space region, and all
6019060287
** cells are packed tightly at the end of the page.
6019160288
*/
60192
-static int defragmentPage(MemPage *pPage){
60289
+static int defragmentPage(MemPage *pPage, int nMaxFrag){
6019360290
int i; /* Loop counter */
6019460291
int pc; /* Address of the i-th cell */
6019560292
int hdr; /* Offset to the page header */
6019660293
int size; /* Size of a cell */
6019760294
int usableSize; /* Number of usable bytes on a page */
@@ -60202,11 +60299,10 @@
6020260299
unsigned char *temp; /* Temp area for cell content */
6020360300
unsigned char *src; /* Source of content */
6020460301
int iCellFirst; /* First allowable cell index */
6020560302
int iCellLast; /* Last possible cell index */
6020660303
60207
-
6020860304
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
6020960305
assert( pPage->pBt!=0 );
6021060306
assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
6021160307
assert( pPage->nOverflow==0 );
6021260308
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
@@ -60214,13 +60310,60 @@
6021460310
src = data = pPage->aData;
6021560311
hdr = pPage->hdrOffset;
6021660312
cellOffset = pPage->cellOffset;
6021760313
nCell = pPage->nCell;
6021860314
assert( nCell==get2byte(&data[hdr+3]) );
60315
+ iCellFirst = cellOffset + 2*nCell;
6021960316
usableSize = pPage->pBt->usableSize;
60317
+
60318
+ /* This block handles pages with two or fewer free blocks and nMaxFrag
60319
+ ** or fewer fragmented bytes. In this case it is faster to move the
60320
+ ** two (or one) blocks of cells using memmove() and add the required
60321
+ ** offsets to each pointer in the cell-pointer array than it is to
60322
+ ** reconstruct the entire page. */
60323
+ if( (int)data[hdr+7]<=nMaxFrag ){
60324
+ int iFree = get2byte(&data[hdr+1]);
60325
+ if( iFree ){
60326
+ int iFree2 = get2byte(&data[iFree]);
60327
+
60328
+ /* pageFindSlot() has already verified that free blocks are sorted
60329
+ ** in order of offset within the page, and that no block extends
60330
+ ** past the end of the page. Provided the two free slots do not
60331
+ ** overlap, this guarantees that the memmove() calls below will not
60332
+ ** overwrite the usableSize byte buffer, even if the database page
60333
+ ** is corrupt. */
60334
+ assert( iFree2==0 || iFree2>iFree );
60335
+ assert( iFree+get2byte(&data[iFree+2]) <= usableSize );
60336
+ assert( iFree2==0 || iFree2+get2byte(&data[iFree2+2]) <= usableSize );
60337
+
60338
+ if( 0==iFree2 || (data[iFree2]==0 && data[iFree2+1]==0) ){
60339
+ u8 *pEnd = &data[cellOffset + nCell*2];
60340
+ u8 *pAddr;
60341
+ int sz2 = 0;
60342
+ int sz = get2byte(&data[iFree+2]);
60343
+ int top = get2byte(&data[hdr+5]);
60344
+ if( iFree2 ){
60345
+ if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_BKPT;
60346
+ sz2 = get2byte(&data[iFree2+2]);
60347
+ assert( iFree+sz+sz2+iFree2-(iFree+sz) <= usableSize );
60348
+ memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
60349
+ sz += sz2;
60350
+ }
60351
+ cbrk = top+sz;
60352
+ assert( cbrk+(iFree-top) <= usableSize );
60353
+ memmove(&data[cbrk], &data[top], iFree-top);
60354
+ for(pAddr=&data[cellOffset]; pAddr<pEnd; pAddr+=2){
60355
+ pc = get2byte(pAddr);
60356
+ if( pc<iFree ){ put2byte(pAddr, pc+sz); }
60357
+ else if( pc<iFree2 ){ put2byte(pAddr, pc+sz2); }
60358
+ }
60359
+ goto defragment_out;
60360
+ }
60361
+ }
60362
+ }
60363
+
6022060364
cbrk = usableSize;
60221
- iCellFirst = cellOffset + 2*nCell;
6022260365
iCellLast = usableSize - 4;
6022360366
for(i=0; i<nCell; i++){
6022460367
u8 *pAddr; /* The i-th cell pointer */
6022560368
pAddr = &data[cellOffset + i*2];
6022660369
pc = get2byte(pAddr);
@@ -60250,20 +60393,22 @@
6025060393
memcpy(&temp[x], &data[x], (cbrk+size) - x);
6025160394
src = temp;
6025260395
}
6025360396
memcpy(&data[cbrk], &src[pc], size);
6025460397
}
60398
+ data[hdr+7] = 0;
60399
+
60400
+ defragment_out:
60401
+ if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
60402
+ return SQLITE_CORRUPT_BKPT;
60403
+ }
6025560404
assert( cbrk>=iCellFirst );
6025660405
put2byte(&data[hdr+5], cbrk);
6025760406
data[hdr+1] = 0;
6025860407
data[hdr+2] = 0;
60259
- data[hdr+7] = 0;
6026060408
memset(&data[iCellFirst], 0, cbrk-iCellFirst);
6026160409
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
60262
- if( cbrk-iCellFirst!=pPage->nFree ){
60263
- return SQLITE_CORRUPT_BKPT;
60264
- }
6026560410
return SQLITE_OK;
6026660411
}
6026760412
6026860413
/*
6026960414
** Search the free-list on page pPg for space to store a cell nByte bytes in
@@ -60397,14 +60542,14 @@
6039760542
** to see if defragmentation is necessary.
6039860543
*/
6039960544
testcase( gap+2+nByte==top );
6040060545
if( gap+2+nByte>top ){
6040160546
assert( pPage->nCell>0 || CORRUPT_DB );
60402
- rc = defragmentPage(pPage);
60547
+ rc = defragmentPage(pPage, MIN(4, pPage->nFree - (2+nByte)));
6040360548
if( rc ) return rc;
6040460549
top = get2byteNotZero(&data[hdr+5]);
60405
- assert( gap+nByte<=top );
60550
+ assert( gap+2+nByte<=top );
6040660551
}
6040760552
6040860553
6040960554
/* Allocate memory from the gap in between the cell pointer array
6041060555
** and the cell content area. The btreeInitPage() call has already
@@ -61672,10 +61817,35 @@
6167261817
sqlite3BtreeLeave(p);
6167361818
return rc;
6167461819
#endif
6167561820
}
6167661821
61822
+/*
61823
+** If the user has not set the safety-level for this database connection
61824
+** using "PRAGMA synchronous", and if the safety-level is not already
61825
+** set to the value passed to this function as the second parameter,
61826
+** set it so.
61827
+*/
61828
+#if SQLITE_DEFAULT_SYNCHRONOUS!=SQLITE_DEFAULT_WAL_SYNCHRONOUS
61829
+static void setDefaultSyncFlag(BtShared *pBt, u8 safety_level){
61830
+ sqlite3 *db;
61831
+ Db *pDb;
61832
+ if( (db=pBt->db)!=0 && (pDb=db->aDb)!=0 ){
61833
+ while( pDb->pBt==0 || pDb->pBt->pBt!=pBt ){ pDb++; }
61834
+ if( pDb->bSyncSet==0
61835
+ && pDb->safety_level!=safety_level
61836
+ && pDb!=&db->aDb[1]
61837
+ ){
61838
+ pDb->safety_level = safety_level;
61839
+ sqlite3PagerSetFlags(pBt->pPager,
61840
+ pDb->safety_level | (db->flags & PAGER_FLAGS_MASK));
61841
+ }
61842
+ }
61843
+}
61844
+#else
61845
+# define setDefaultSyncFlag(pBt,safety_level)
61846
+#endif
6167761847
6167861848
/*
6167961849
** Get a reference to pPage1 of the database file. This will
6168061850
** also acquire a readlock on that file.
6168161851
**
@@ -61745,30 +61915,19 @@
6174561915
int isOpen = 0;
6174661916
rc = sqlite3PagerOpenWal(pBt->pPager, &isOpen);
6174761917
if( rc!=SQLITE_OK ){
6174861918
goto page1_init_failed;
6174961919
}else{
61750
-#if SQLITE_DEFAULT_SYNCHRONOUS!=SQLITE_DEFAULT_WAL_SYNCHRONOUS
61751
- sqlite3 *db;
61752
- Db *pDb;
61753
- if( (db=pBt->db)!=0 && (pDb=db->aDb)!=0 ){
61754
- while( pDb->pBt==0 || pDb->pBt->pBt!=pBt ){ pDb++; }
61755
- if( pDb->bSyncSet==0
61756
- && pDb->safety_level==SQLITE_DEFAULT_SYNCHRONOUS+1
61757
- ){
61758
- pDb->safety_level = SQLITE_DEFAULT_WAL_SYNCHRONOUS+1;
61759
- sqlite3PagerSetFlags(pBt->pPager,
61760
- pDb->safety_level | (db->flags & PAGER_FLAGS_MASK));
61761
- }
61762
- }
61763
-#endif
61920
+ setDefaultSyncFlag(pBt, SQLITE_DEFAULT_WAL_SYNCHRONOUS+1);
6176461921
if( isOpen==0 ){
6176561922
releasePage(pPage1);
6176661923
return SQLITE_OK;
6176761924
}
6176861925
}
6176961926
rc = SQLITE_NOTADB;
61927
+ }else{
61928
+ setDefaultSyncFlag(pBt, SQLITE_DEFAULT_SYNCHRONOUS+1);
6177061929
}
6177161930
#endif
6177261931
6177361932
/* EVIDENCE-OF: R-15465-20813 The maximum and minimum embedded payload
6177461933
** fractions and the leaf payload fraction values must be 64, 32, and 32.
@@ -63636,11 +63795,11 @@
6363663795
pCur->aiIdx[pCur->iPage] = 0;
6363763796
return getAndInitPage(pBt, newPgno, &pCur->apPage[pCur->iPage],
6363863797
pCur, pCur->curPagerFlags);
6363963798
}
6364063799
63641
-#if SQLITE_DEBUG
63800
+#ifdef SQLITE_DEBUG
6364263801
/*
6364363802
** Page pParent is an internal (non-leaf) tree page. This function
6364463803
** asserts that page number iChild is the left-child if the iIdx'th
6364563804
** cell in page pParent. Or, if iIdx is equal to the total number of
6364663805
** cells in pParent, that page number iChild is the right-child of
@@ -64178,10 +64337,34 @@
6417864337
** have been deleted? This API will need to change to return an error code
6417964338
** as well as the boolean result value.
6418064339
*/
6418164340
return (CURSOR_VALID!=pCur->eState);
6418264341
}
64342
+
64343
+/*
64344
+** Return an estimate for the number of rows in the table that pCur is
64345
+** pointing to. Return a negative number if no estimate is currently
64346
+** available.
64347
+*/
64348
+SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor *pCur){
64349
+ i64 n;
64350
+ u8 i;
64351
+
64352
+ assert( cursorOwnsBtShared(pCur) );
64353
+ assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
64354
+
64355
+ /* Currently this interface is only called by the OP_IfSmaller
64356
+ ** opcode, and it that case the cursor will always be valid and
64357
+ ** will always point to a leaf node. */
64358
+ if( NEVER(pCur->eState!=CURSOR_VALID) ) return -1;
64359
+ if( NEVER(pCur->apPage[pCur->iPage]->leaf==0) ) return -1;
64360
+
64361
+ for(n=1, i=0; i<=pCur->iPage; i++){
64362
+ n *= pCur->apPage[i]->nCell;
64363
+ }
64364
+ return n;
64365
+}
6418364366
6418464367
/*
6418564368
** Advance the cursor to the next entry in the database. If
6418664369
** successful then set *pRes=0. If the cursor
6418764370
** was already pointing to the last entry in the database before
@@ -65023,11 +65206,11 @@
6502365206
** pPrior Where to write the pgno of the first overflow page
6502465207
**
6502565208
** Use a call to btreeParseCellPtr() to verify that the values above
6502665209
** were computed correctly.
6502765210
*/
65028
-#if SQLITE_DEBUG
65211
+#ifdef SQLITE_DEBUG
6502965212
{
6503065213
CellInfo info;
6503165214
pPage->xParseCell(pPage, pCell, &info);
6503265215
assert( nHeader==(int)(info.pPayload - pCell) );
6503365216
assert( info.nKey==pX->nKey );
@@ -66549,11 +66732,11 @@
6654966732
** copied into the parent, because if the parent is page 1 then it will
6655066733
** by smaller than the child due to the database header, and so all the
6655166734
** free space needs to be up front.
6655266735
*/
6655366736
assert( nNew==1 || CORRUPT_DB );
66554
- rc = defragmentPage(apNew[0]);
66737
+ rc = defragmentPage(apNew[0], -1);
6655566738
testcase( rc!=SQLITE_OK );
6655666739
assert( apNew[0]->nFree ==
6655766740
(get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2)
6655866741
|| rc!=SQLITE_OK
6655966742
);
@@ -71201,10 +71384,11 @@
7120171384
** Remember the SQL string for a prepared statement.
7120271385
*/
7120371386
SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe *p, const char *z, int n, int isPrepareV2){
7120471387
assert( isPrepareV2==1 || isPrepareV2==0 );
7120571388
if( p==0 ) return;
71389
+ if( !isPrepareV2 ) p->expmask = 0;
7120671390
#if defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_ENABLE_SQLLOG)
7120771391
if( !isPrepareV2 ) return;
7120871392
#endif
7120971393
assert( p->zSql==0 );
7121071394
p->zSql = sqlite3DbStrNDup(p->db, z, n);
@@ -71229,10 +71413,11 @@
7122971413
pB->pPrev = pTmp;
7123071414
zTmp = pA->zSql;
7123171415
pA->zSql = pB->zSql;
7123271416
pB->zSql = zTmp;
7123371417
pB->isPrepareV2 = pA->isPrepareV2;
71418
+ pB->expmask = pA->expmask;
7123471419
}
7123571420
7123671421
/*
7123771422
** Resize the Vdbe.aOp array so that it is at least nOp elements larger
7123871423
** than its current size. nOp is guaranteed to be less than or equal
@@ -71258,10 +71443,16 @@
7125871443
int nNew = (p->nOpAlloc>=512 ? p->nOpAlloc*2 : p->nOpAlloc+nOp);
7125971444
#else
7126071445
int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op)));
7126171446
UNUSED_PARAMETER(nOp);
7126271447
#endif
71448
+
71449
+ /* Ensure that the size of a VDBE does not grow too large */
71450
+ if( nNew > p->db->aLimit[SQLITE_LIMIT_VDBE_OP] ){
71451
+ sqlite3OomFault(p->db);
71452
+ return SQLITE_NOMEM;
71453
+ }
7126371454
7126471455
assert( nOp<=(1024/sizeof(Op)) );
7126571456
assert( nNew>=(p->nOpAlloc+nOp) );
7126671457
pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
7126771458
if( pNew ){
@@ -73753,17 +73944,17 @@
7375373944
** Then the internal cache might have been left in an inconsistent
7375473945
** state. We need to rollback the statement transaction, if there is
7375573946
** one, or the complete transaction if there is no statement transaction.
7375673947
*/
7375773948
73949
+ if( p->magic!=VDBE_MAGIC_RUN ){
73950
+ return SQLITE_OK;
73951
+ }
7375873952
if( db->mallocFailed ){
7375973953
p->rc = SQLITE_NOMEM_BKPT;
7376073954
}
7376173955
closeAllCursors(p);
73762
- if( p->magic!=VDBE_MAGIC_RUN ){
73763
- return SQLITE_OK;
73764
- }
7376573956
checkActiveVdbeCnt(db);
7376673957
7376773958
/* No commit or rollback needed if the program never started or if the
7376873959
** SQL statement does not read or write a database file. */
7376973960
if( p->pc>=0 && p->bIsReader ){
@@ -74706,11 +74897,11 @@
7470674897
}
7470774898
assert( u<=pKeyInfo->nField + 1 );
7470874899
p->nField = u;
7470974900
}
7471074901
74711
-#if SQLITE_DEBUG
74902
+#ifdef SQLITE_DEBUG
7471274903
/*
7471374904
** This function compares two index or table record keys in the same way
7471474905
** as the sqlite3VdbeRecordCompare() routine. Unlike VdbeRecordCompare(),
7471574906
** this function deserializes and compares values using the
7471674907
** sqlite3VdbeSerialGet() and sqlite3MemCompare() functions. It is used
@@ -74811,11 +75002,11 @@
7481175002
if( pKeyInfo->db->mallocFailed ) return 1;
7481275003
return 0;
7481375004
}
7481475005
#endif
7481575006
74816
-#if SQLITE_DEBUG
75007
+#ifdef SQLITE_DEBUG
7481775008
/*
7481875009
** Count the number of fields (a.k.a. columns) in the record given by
7481975010
** pKey,nKey. The verify that this count is less than or equal to the
7482075011
** limit given by pKeyInfo->nField + pKeyInfo->nXField.
7482175012
**
@@ -75694,12 +75885,12 @@
7569475885
** to sqlite3_reoptimize() that re-preparing the statement may result
7569575886
** in a better query plan.
7569675887
*/
7569775888
SQLITE_PRIVATE void sqlite3VdbeSetVarmask(Vdbe *v, int iVar){
7569875889
assert( iVar>0 );
75699
- if( iVar>32 ){
75700
- v->expmask = 0xffffffff;
75890
+ if( iVar>=32 ){
75891
+ v->expmask |= 0x80000000;
7570175892
}else{
7570275893
v->expmask |= ((u32)1 << (iVar-1));
7570375894
}
7570475895
}
7570575896
@@ -75965,11 +76156,12 @@
7596576156
sqlite3_mutex_enter(mutex);
7596676157
for(i=0; i<p->nVar; i++){
7596776158
sqlite3VdbeMemRelease(&p->aVar[i]);
7596876159
p->aVar[i].flags = MEM_Null;
7596976160
}
75970
- if( p->isPrepareV2 && p->expmask ){
76161
+ assert( p->isPrepareV2 || p->expmask==0 );
76162
+ if( p->expmask ){
7597176163
p->expired = 1;
7597276164
}
7597376165
sqlite3_mutex_leave(mutex);
7597476166
return rc;
7597576167
}
@@ -77069,13 +77261,12 @@
7706977261
** parameter in the WHERE clause might influence the choice of query plan
7707077262
** for a statement, then the statement will be automatically recompiled,
7707177263
** as if there had been a schema change, on the first sqlite3_step() call
7707277264
** following any change to the bindings of that parameter.
7707377265
*/
77074
- if( p->isPrepareV2 &&
77075
- ((i<32 && p->expmask & ((u32)1 << i)) || p->expmask==0xffffffff)
77076
- ){
77266
+ assert( p->isPrepareV2 || p->expmask==0 );
77267
+ if( p->expmask!=0 && (p->expmask & (i>=31 ? 0x80000000 : (u32)1<<i))!=0 ){
7707777268
p->expired = 1;
7707877269
}
7707977270
return SQLITE_OK;
7708077271
}
7708177272
@@ -77334,14 +77525,16 @@
7733477525
Vdbe *pFrom = (Vdbe*)pFromStmt;
7733577526
Vdbe *pTo = (Vdbe*)pToStmt;
7733677527
if( pFrom->nVar!=pTo->nVar ){
7733777528
return SQLITE_ERROR;
7733877529
}
77339
- if( pTo->isPrepareV2 && pTo->expmask ){
77530
+ assert( pTo->isPrepareV2 || pTo->expmask==0 );
77531
+ if( pTo->expmask ){
7734077532
pTo->expired = 1;
7734177533
}
77342
- if( pFrom->isPrepareV2 && pFrom->expmask ){
77534
+ assert( pFrom->isPrepareV2 || pFrom->expmask==0 );
77535
+ if( pFrom->expmask ){
7734377536
pFrom->expired = 1;
7734477537
}
7734577538
return sqlite3TransferBindings(pFromStmt, pToStmt);
7734677539
}
7734777540
#endif
@@ -78303,13 +78496,11 @@
7830378496
c = 'e';
7830478497
assert( (f & (MEM_Static|MEM_Dyn))==0 );
7830578498
}else{
7830678499
c = 's';
7830778500
}
78308
-
78309
- sqlite3_snprintf(100, zCsr, "%c", c);
78310
- zCsr += sqlite3Strlen30(zCsr);
78501
+ *(zCsr++) = c;
7831178502
sqlite3_snprintf(100, zCsr, "%d[", pMem->n);
7831278503
zCsr += sqlite3Strlen30(zCsr);
7831378504
for(i=0; i<16 && i<pMem->n; i++){
7831478505
sqlite3_snprintf(100, zCsr, "%02X", ((int)pMem->z[i] & 0xFF));
7831578506
zCsr += sqlite3Strlen30(zCsr);
@@ -78317,13 +78508,11 @@
7831778508
for(i=0; i<16 && i<pMem->n; i++){
7831878509
char z = pMem->z[i];
7831978510
if( z<32 || z>126 ) *zCsr++ = '.';
7832078511
else *zCsr++ = z;
7832178512
}
78322
-
78323
- sqlite3_snprintf(100, zCsr, "]%s", encnames[pMem->enc]);
78324
- zCsr += sqlite3Strlen30(zCsr);
78513
+ *(zCsr++) = ']';
7832578514
if( f & MEM_Zero ){
7832678515
sqlite3_snprintf(100, zCsr,"+%dz",pMem->u.nZero);
7832778516
zCsr += sqlite3Strlen30(zCsr);
7832878517
}
7832978518
*zCsr = '\0';
@@ -79658,39 +79847,39 @@
7965879847
if( pCtx->pOut != pOut ){
7965979848
pCtx->pOut = pOut;
7966079849
for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
7966179850
}
7966279851
79663
- memAboutToChange(p, pCtx->pOut);
79852
+ memAboutToChange(p, pOut);
7966479853
#ifdef SQLITE_DEBUG
7966579854
for(i=0; i<pCtx->argc; i++){
7966679855
assert( memIsValid(pCtx->argv[i]) );
7966779856
REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]);
7966879857
}
7966979858
#endif
79670
- MemSetTypeFlag(pCtx->pOut, MEM_Null);
79859
+ MemSetTypeFlag(pOut, MEM_Null);
7967179860
pCtx->fErrorOrAux = 0;
7967279861
(*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */
7967379862
7967479863
/* If the function returned an error, throw an exception */
7967579864
if( pCtx->fErrorOrAux ){
7967679865
if( pCtx->isError ){
79677
- sqlite3VdbeError(p, "%s", sqlite3_value_text(pCtx->pOut));
79866
+ sqlite3VdbeError(p, "%s", sqlite3_value_text(pOut));
7967879867
rc = pCtx->isError;
7967979868
}
7968079869
sqlite3VdbeDeleteAuxData(db, &p->pAuxData, pCtx->iOp, pOp->p1);
7968179870
if( rc ) goto abort_due_to_error;
7968279871
}
7968379872
7968479873
/* Copy the result of the function into register P3 */
7968579874
if( pOut->flags & (MEM_Str|MEM_Blob) ){
79686
- sqlite3VdbeChangeEncoding(pCtx->pOut, encoding);
79687
- if( sqlite3VdbeMemTooBig(pCtx->pOut) ) goto too_big;
79875
+ sqlite3VdbeChangeEncoding(pOut, encoding);
79876
+ if( sqlite3VdbeMemTooBig(pOut) ) goto too_big;
7968879877
}
7968979878
79690
- REGISTER_TRACE(pOp->p3, pCtx->pOut);
79691
- UPDATE_MAX_BLOBSIZE(pCtx->pOut);
79879
+ REGISTER_TRACE(pOp->p3, pOut);
79880
+ UPDATE_MAX_BLOBSIZE(pOut);
7969279881
break;
7969379882
}
7969479883
7969579884
/* Opcode: BitAnd P1 P2 P3 * *
7969679885
** Synopsis: r[P3]=r[P1]&r[P2]
@@ -80187,11 +80376,11 @@
8018780376
pKeyInfo = pOp->p4.pKeyInfo;
8018880377
assert( n>0 );
8018980378
assert( pKeyInfo!=0 );
8019080379
p1 = pOp->p1;
8019180380
p2 = pOp->p2;
80192
-#if SQLITE_DEBUG
80381
+#ifdef SQLITE_DEBUG
8019380382
if( aPermute ){
8019480383
int k, mx = 0;
8019580384
for(k=0; k<n; k++) if( aPermute[k]>mx ) mx = aPermute[k];
8019680385
assert( p1>0 && p1+mx<=(p->nMem+1 - p->nCursor)+1 );
8019780386
assert( p2>0 && p2+mx<=(p->nMem+1 - p->nCursor)+1 );
@@ -80325,23 +80514,43 @@
8032580514
break;
8032680515
}
8032780516
8032880517
/* Opcode: Once P1 P2 * * *
8032980518
**
80330
-** If the P1 value is equal to the P1 value on the OP_Init opcode at
80331
-** instruction 0, then jump to P2. If the two P1 values differ, then
80332
-** set the P1 value on this opcode to equal the P1 value on the OP_Init
80333
-** and fall through.
80519
+** Fall through to the next instruction the first time this opcode is
80520
+** encountered on each invocation of the byte-code program. Jump to P2
80521
+** on the second and all subsequent encounters during the same invocation.
80522
+**
80523
+** Top-level programs determine first invocation by comparing the P1
80524
+** operand against the P1 operand on the OP_Init opcode at the beginning
80525
+** of the program. If the P1 values differ, then fall through and make
80526
+** the P1 of this opcode equal to the P1 of OP_Init. If P1 values are
80527
+** the same then take the jump.
80528
+**
80529
+** For subprograms, there is a bitmask in the VdbeFrame that determines
80530
+** whether or not the jump should be taken. The bitmask is necessary
80531
+** because the self-altering code trick does not work for recursive
80532
+** triggers.
8033480533
*/
8033580534
case OP_Once: { /* jump */
80535
+ u32 iAddr; /* Address of this instruction */
8033680536
assert( p->aOp[0].opcode==OP_Init );
80337
- VdbeBranchTaken(p->aOp[0].p1==pOp->p1, 2);
80338
- if( p->aOp[0].p1==pOp->p1 ){
80339
- goto jump_to_p2;
80537
+ if( p->pFrame ){
80538
+ iAddr = (int)(pOp - p->aOp);
80539
+ if( (p->pFrame->aOnce[iAddr/8] & (1<<(iAddr & 7)))!=0 ){
80540
+ VdbeBranchTaken(1, 2);
80541
+ goto jump_to_p2;
80542
+ }
80543
+ p->pFrame->aOnce[iAddr/8] |= 1<<(iAddr & 7);
8034080544
}else{
80341
- pOp->p1 = p->aOp[0].p1;
80545
+ if( p->aOp[0].p1==pOp->p1 ){
80546
+ VdbeBranchTaken(1, 2);
80547
+ goto jump_to_p2;
80548
+ }
8034280549
}
80550
+ VdbeBranchTaken(0, 2);
80551
+ pOp->p1 = p->aOp[0].p1;
8034380552
break;
8034480553
}
8034580554
8034680555
/* Opcode: If P1 P2 P3 * *
8034780556
**
@@ -80650,12 +80859,17 @@
8065080859
/* Content is irrelevant for
8065180860
** 1. the typeof() function,
8065280861
** 2. the length(X) function if X is a blob, and
8065380862
** 3. if the content length is zero.
8065480863
** So we might as well use bogus content rather than reading
80655
- ** content from disk. */
80656
- static u8 aZero[8]; /* This is the bogus content */
80864
+ ** content from disk.
80865
+ **
80866
+ ** Although sqlite3VdbeSerialGet() may read at most 8 bytes from the
80867
+ ** buffer passed to it, debugging function VdbeMemPrettyPrint() may
80868
+ ** read up to 16. So 16 bytes of bogus content is supplied.
80869
+ */
80870
+ static u8 aZero[16]; /* This is the bogus content */
8065780871
sqlite3VdbeSerialGet(aZero, t, pDest);
8065880872
}else{
8065980873
rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest);
8066080874
if( rc!=SQLITE_OK ) goto abort_due_to_error;
8066180875
sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest);
@@ -82836,10 +83050,37 @@
8283683050
assert( pOp->p2==0 );
8283783051
}
8283883052
break;
8283983053
}
8284083054
83055
+/* Opcode: IfSmaller P1 P2 P3 * *
83056
+**
83057
+** Estimate the number of rows in the table P1. Jump to P2 if that
83058
+** estimate is less than approximately 2**(0.1*P3).
83059
+*/
83060
+case OP_IfSmaller: { /* jump */
83061
+ VdbeCursor *pC;
83062
+ BtCursor *pCrsr;
83063
+ int res;
83064
+ i64 sz;
83065
+
83066
+ assert( pOp->p1>=0 && pOp->p1<p->nCursor );
83067
+ pC = p->apCsr[pOp->p1];
83068
+ assert( pC!=0 );
83069
+ pCrsr = pC->uc.pCursor;
83070
+ assert( pCrsr );
83071
+ rc = sqlite3BtreeFirst(pCrsr, &res);
83072
+ if( rc ) goto abort_due_to_error;
83073
+ if( res==0 ){
83074
+ sz = sqlite3BtreeRowCountEst(pCrsr);
83075
+ if( ALWAYS(sz>=0) && sqlite3LogEst((u64)sz)<pOp->p3 ) res = 1;
83076
+ }
83077
+ VdbeBranchTaken(res!=0,2);
83078
+ if( res ) goto jump_to_p2;
83079
+ break;
83080
+}
83081
+
8284183082
8284283083
/* Opcode: SorterSort P1 P2 * * *
8284383084
**
8284483085
** After all records have been inserted into the Sorter object
8284583086
** identified by P1, invoke this opcode to actually do the sorting.
@@ -83479,10 +83720,22 @@
8347983720
rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, flags);
8348083721
if( rc ) goto abort_due_to_error;
8348183722
pOut->u.i = pgno;
8348283723
break;
8348383724
}
83725
+
83726
+/* Opcode: SqlExec * * * P4 *
83727
+**
83728
+** Run the SQL statement or statements specified in the P4 string.
83729
+*/
83730
+case OP_SqlExec: {
83731
+ db->nSqlExec++;
83732
+ rc = sqlite3_exec(db, pOp->p4.z, 0, 0, 0);
83733
+ db->nSqlExec--;
83734
+ if( rc ) goto abort_due_to_error;
83735
+ break;
83736
+}
8348483737
8348583738
/* Opcode: ParseSchema P1 * * P4 *
8348683739
**
8348783740
** Read and parse all entries from the SQLITE_MASTER table of database P1
8348883741
** that match the WHERE clause P4.
@@ -83600,11 +83853,11 @@
8360083853
**
8360183854
** Do an analysis of the currently open database. Store in
8360283855
** register P1 the text of an error message describing any problems.
8360383856
** If no problems are found, store a NULL in register P1.
8360483857
**
83605
-** The register P3 contains the maximum number of allowed errors.
83858
+** The register P3 contains one less than the maximum number of allowed errors.
8360683859
** At most reg(P3) errors will be reported.
8360783860
** In other words, the analysis stops as soon as reg(P1) errors are
8360883861
** seen. Reg(P1) is updated with the number of errors remaining.
8360983862
**
8361083863
** The root page numbers of all tables in the database are integers
@@ -83633,18 +83886,18 @@
8363383886
assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 );
8363483887
pIn1 = &aMem[pOp->p1];
8363583888
assert( pOp->p5<db->nDb );
8363683889
assert( DbMaskTest(p->btreeMask, pOp->p5) );
8363783890
z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot,
83638
- (int)pnErr->u.i, &nErr);
83639
- pnErr->u.i -= nErr;
83891
+ (int)pnErr->u.i+1, &nErr);
8364083892
sqlite3VdbeMemSetNull(pIn1);
8364183893
if( nErr==0 ){
8364283894
assert( z==0 );
8364383895
}else if( z==0 ){
8364483896
goto no_mem;
8364583897
}else{
83898
+ pnErr->u.i -= nErr-1;
8364683899
sqlite3VdbeMemSetStr(pIn1, z, -1, SQLITE_UTF8, sqlite3_free);
8364783900
}
8364883901
UPDATE_MAX_BLOBSIZE(pIn1);
8364983902
sqlite3VdbeChangeEncoding(pIn1, encoding);
8365083903
break;
@@ -83819,11 +84072,12 @@
8381984072
nMem = pProgram->nMem + pProgram->nCsr;
8382084073
assert( nMem>0 );
8382184074
if( pProgram->nCsr==0 ) nMem++;
8382284075
nByte = ROUND8(sizeof(VdbeFrame))
8382384076
+ nMem * sizeof(Mem)
83824
- + pProgram->nCsr * sizeof(VdbeCursor *);
84077
+ + pProgram->nCsr * sizeof(VdbeCursor*)
84078
+ + (pProgram->nOp + 7)/8;
8382584079
pFrame = sqlite3DbMallocZero(db, nByte);
8382684080
if( !pFrame ){
8382784081
goto no_mem;
8382884082
}
8382984083
sqlite3VdbeMemRelease(pRt);
@@ -83870,10 +84124,12 @@
8387084124
p->pFrame = pFrame;
8387184125
p->aMem = aMem = VdbeFrameMem(pFrame);
8387284126
p->nMem = pFrame->nChildMem;
8387384127
p->nCursor = (u16)pFrame->nChildCsr;
8387484128
p->apCsr = (VdbeCursor **)&aMem[p->nMem];
84129
+ pFrame->aOnce = (u8*)&p->apCsr[pProgram->nCsr];
84130
+ memset(pFrame->aOnce, 0, (pProgram->nOp + 7)/8);
8387584131
p->aOp = aOp = pProgram->aOp;
8387684132
p->nOp = pProgram->nOp;
8387784133
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
8387884134
p->anExec = 0;
8387984135
#endif
@@ -84899,11 +85155,15 @@
8489985155
char *z = sqlite3VdbeExpandSql(p, zTrace);
8490085156
x(db->pTraceArg, z);
8490185157
sqlite3_free(z);
8490285158
}else
8490385159
#endif
84904
- {
85160
+ if( db->nVdbeExec>1 ){
85161
+ char *z = sqlite3MPrintf(db, "-- %s", zTrace);
85162
+ (void)db->xTrace(SQLITE_TRACE_STMT, db->pTraceArg, p, z);
85163
+ sqlite3DbFree(db, z);
85164
+ }else{
8490585165
(void)db->xTrace(SQLITE_TRACE_STMT, db->pTraceArg, p, zTrace);
8490685166
}
8490785167
}
8490885168
#ifdef SQLITE_USE_FCNTL_TRACE
8490985169
zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
@@ -88787,15 +89047,15 @@
8878789047
** The return value from the callback should be one of the WRC_*
8878889048
** constants to specify how to proceed with the walk.
8878989049
**
8879089050
** WRC_Continue Continue descending down the tree.
8879189051
**
88792
-** WRC_Prune Do not descend into child nodes. But allow
89052
+** WRC_Prune Do not descend into child nodes, but allow
8879389053
** the walk to continue with sibling nodes.
8879489054
**
8879589055
** WRC_Abort Do no more callbacks. Unwind the stack and
88796
-** return the top-level walk call.
89056
+** return from the top-level walk call.
8879789057
**
8879889058
** The return value from this routine is WRC_Abort to abandon the tree walk
8879989059
** and WRC_Continue to continue.
8880089060
*/
8880189061
static SQLITE_NOINLINE int walkExpr(Walker *pWalker, Expr *pExpr){
@@ -89153,11 +89413,12 @@
8915389413
}
8915489414
}
8915589415
}
8915689416
8915789417
/* Start at the inner-most context and move outward until a match is found */
89158
- while( pNC && cnt==0 ){
89418
+ assert( pNC && cnt==0 );
89419
+ do{
8915989420
ExprList *pEList;
8916089421
SrcList *pSrcList = pNC->pSrcList;
8916189422
8916289423
if( pSrcList ){
8916389424
for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
@@ -89338,15 +89599,15 @@
8933889599
}
8933989600
8934089601
/* Advance to the next name context. The loop will exit when either
8934189602
** we have a match (cnt>0) or when we run out of name contexts.
8934289603
*/
89343
- if( cnt==0 ){
89344
- pNC = pNC->pNext;
89345
- nSubquery++;
89346
- }
89347
- }
89604
+ if( cnt ) break;
89605
+ pNC = pNC->pNext;
89606
+ nSubquery++;
89607
+ }while( pNC );
89608
+
8934889609
8934989610
/*
8935089611
** If X and Y are NULL (in other words if only the column name Z is
8935189612
** supplied) and the value of Z is enclosed in double-quotes, then
8935289613
** Z is a string literal if it doesn't match any column names. In that
@@ -89532,37 +89793,42 @@
8953289793
break;
8953389794
}
8953489795
#endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
8953589796
&& !defined(SQLITE_OMIT_SUBQUERY) */
8953689797
89537
- /* A lone identifier is the name of a column.
89538
- */
89539
- case TK_ID: {
89540
- return lookupName(pParse, 0, 0, pExpr->u.zToken, pNC, pExpr);
89541
- }
89542
-
89543
- /* A table name and column name: ID.ID
89798
+ /* A column name: ID
89799
+ ** Or table name and column name: ID.ID
8954489800
** Or a database, table and column: ID.ID.ID
89801
+ **
89802
+ ** The TK_ID and TK_OUT cases are combined so that there will only
89803
+ ** be one call to lookupName(). Then the compiler will in-line
89804
+ ** lookupName() for a size reduction and performance increase.
8954589805
*/
89806
+ case TK_ID:
8954689807
case TK_DOT: {
8954789808
const char *zColumn;
8954889809
const char *zTable;
8954989810
const char *zDb;
8955089811
Expr *pRight;
8955189812
89552
- /* if( pSrcList==0 ) break; */
89553
- notValid(pParse, pNC, "the \".\" operator", NC_IdxExpr);
89554
- pRight = pExpr->pRight;
89555
- if( pRight->op==TK_ID ){
89813
+ if( pExpr->op==TK_ID ){
8955689814
zDb = 0;
89557
- zTable = pExpr->pLeft->u.zToken;
89558
- zColumn = pRight->u.zToken;
89815
+ zTable = 0;
89816
+ zColumn = pExpr->u.zToken;
8955989817
}else{
89560
- assert( pRight->op==TK_DOT );
89561
- zDb = pExpr->pLeft->u.zToken;
89562
- zTable = pRight->pLeft->u.zToken;
89563
- zColumn = pRight->pRight->u.zToken;
89818
+ notValid(pParse, pNC, "the \".\" operator", NC_IdxExpr);
89819
+ pRight = pExpr->pRight;
89820
+ if( pRight->op==TK_ID ){
89821
+ zDb = 0;
89822
+ zTable = pExpr->pLeft->u.zToken;
89823
+ zColumn = pRight->u.zToken;
89824
+ }else{
89825
+ assert( pRight->op==TK_DOT );
89826
+ zDb = pExpr->pLeft->u.zToken;
89827
+ zTable = pRight->pLeft->u.zToken;
89828
+ zColumn = pRight->pRight->u.zToken;
89829
+ }
8956489830
}
8956589831
return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr);
8956689832
}
8956789833
8956889834
/* Resolve function names
@@ -92326,10 +92592,11 @@
9232692592
** in *pValue. If the expression is not an integer or if it is too big
9232792593
** to fit in a signed 32-bit integer, return 0 and leave *pValue unchanged.
9232892594
*/
9232992595
SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr *p, int *pValue){
9233092596
int rc = 0;
92597
+ if( p==0 ) return 0; /* Can only happen following on OOM */
9233192598
9233292599
/* If an expression is an integer literal that fits in a signed 32-bit
9233392600
** integer, then the EP_IntValue flag will have already been set */
9233492601
assert( p->op!=TK_INTEGER || (p->flags & EP_IntValue)!=0
9233592602
|| sqlite3GetInt32(p->u.zToken, &rc)==0 );
@@ -92833,11 +93100,11 @@
9283393100
int nVal = sqlite3ExprVectorSize(pLeft);
9283493101
Select *pSelect = (pExpr->flags & EP_xIsSelect) ? pExpr->x.pSelect : 0;
9283593102
char *zRet;
9283693103
9283793104
assert( pExpr->op==TK_IN );
92838
- zRet = sqlite3DbMallocZero(pParse->db, nVal+1);
93105
+ zRet = sqlite3DbMallocRaw(pParse->db, nVal+1);
9283993106
if( zRet ){
9284093107
int i;
9284193108
for(i=0; i<nVal; i++){
9284293109
Expr *pA = sqlite3VectorFieldSubexpr(pLeft, i);
9284393110
char a = sqlite3ExprAffinity(pA);
@@ -92998,11 +93265,10 @@
9299893265
if( ALWAYS(pEList->nExpr==nVal) ){
9299993266
SelectDest dest;
9300093267
int i;
9300193268
sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
9300293269
dest.zAffSdst = exprINAffinity(pParse, pExpr);
93003
- assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
9300493270
pSelect->iLimit = 0;
9300593271
testcase( pSelect->selFlags & SF_Distinct );
9300693272
testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
9300793273
if( sqlite3Select(pParse, pSelect, &dest) ){
9300893274
sqlite3DbFree(pParse->db, dest.zAffSdst);
@@ -93738,11 +94004,11 @@
9373894004
** Clear all column cache entries.
9373994005
*/
9374094006
SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse *pParse){
9374194007
int i;
9374294008
93743
-#if SQLITE_DEBUG
94009
+#ifdef SQLITE_DEBUG
9374494010
if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
9374594011
printf("CLEAR\n");
9374694012
}
9374794013
#endif
9374894014
for(i=0; i<pParse->nColCache; i++){
@@ -95145,10 +95411,21 @@
9514595411
if( pA->a[i].sortOrder!=pB->a[i].sortOrder ) return 1;
9514695412
if( sqlite3ExprCompare(pExprA, pExprB, iTab) ) return 1;
9514795413
}
9514895414
return 0;
9514995415
}
95416
+
95417
+/*
95418
+** Like sqlite3ExprCompare() except COLLATE operators at the top-level
95419
+** are ignored.
95420
+*/
95421
+SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr *pA, Expr *pB, int iTab){
95422
+ return sqlite3ExprCompare(
95423
+ sqlite3ExprSkipCollate(pA),
95424
+ sqlite3ExprSkipCollate(pB),
95425
+ iTab);
95426
+}
9515095427
9515195428
/*
9515295429
** Return true if we can prove the pE2 will always be true if pE1 is
9515395430
** true. Return false if we cannot complete the proof or if pE2 might
9515495431
** be false. Examples:
@@ -96698,10 +96975,11 @@
9669896975
Stat4Sample current; /* Current row as a Stat4Sample */
9669996976
u32 iPrn; /* Pseudo-random number used for sampling */
9670096977
Stat4Sample *aBest; /* Array of nCol best samples */
9670196978
int iMin; /* Index in a[] of entry with minimum score */
9670296979
int nSample; /* Current number of samples */
96980
+ int nMaxEqZero; /* Max leading 0 in anEq[] for any a[] entry */
9670396981
int iGet; /* Index of current sample accessed by stat_get() */
9670496982
Stat4Sample *a; /* Array of mxSample Stat4Sample objects */
9670596983
sqlite3 *db; /* Database connection, for malloc() */
9670696984
};
9670796985
@@ -96962,10 +97240,17 @@
9696297240
int i;
9696397241
9696497242
assert( IsStat4 || nEqZero==0 );
9696597243
9696697244
#ifdef SQLITE_ENABLE_STAT4
97245
+ /* Stat4Accum.nMaxEqZero is set to the maximum number of leading 0
97246
+ ** values in the anEq[] array of any sample in Stat4Accum.a[]. In
97247
+ ** other words, if nMaxEqZero is n, then it is guaranteed that there
97248
+ ** are no samples with Stat4Sample.anEq[m]==0 for (m>=n). */
97249
+ if( nEqZero>p->nMaxEqZero ){
97250
+ p->nMaxEqZero = nEqZero;
97251
+ }
9696797252
if( pNew->isPSample==0 ){
9696897253
Stat4Sample *pUpgrade = 0;
9696997254
assert( pNew->anEq[pNew->iCol]>0 );
9697097255
9697197256
/* This sample is being added because the prefix that ends in column
@@ -97059,16 +97344,26 @@
9705997344
if( p->nSample<p->mxSample || sampleIsBetter(p, pBest, &p->a[p->iMin]) ){
9706097345
sampleInsert(p, pBest, i);
9706197346
}
9706297347
}
9706397348
97064
- /* Update the anEq[] fields of any samples already collected. */
97349
+ /* Check that no sample contains an anEq[] entry with an index of
97350
+ ** p->nMaxEqZero or greater set to zero. */
9706597351
for(i=p->nSample-1; i>=0; i--){
9706697352
int j;
97067
- for(j=iChng; j<p->nCol; j++){
97068
- if( p->a[i].anEq[j]==0 ) p->a[i].anEq[j] = p->current.anEq[j];
97353
+ for(j=p->nMaxEqZero; j<p->nCol; j++) assert( p->a[i].anEq[j]>0 );
97354
+ }
97355
+
97356
+ /* Update the anEq[] fields of any samples already collected. */
97357
+ if( iChng<p->nMaxEqZero ){
97358
+ for(i=p->nSample-1; i>=0; i--){
97359
+ int j;
97360
+ for(j=iChng; j<p->nCol; j++){
97361
+ if( p->a[i].anEq[j]==0 ) p->a[i].anEq[j] = p->current.anEq[j];
97362
+ }
9706997363
}
97364
+ p->nMaxEqZero = iChng;
9707097365
}
9707197366
#endif
9707297367
9707397368
#if defined(SQLITE_ENABLE_STAT3) && !defined(SQLITE_ENABLE_STAT4)
9707497369
if( iChng==0 ){
@@ -97594,11 +97889,11 @@
9759497889
Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
9759597890
int j, k, regKey;
9759697891
regKey = sqlite3GetTempRange(pParse, pPk->nKeyCol);
9759797892
for(j=0; j<pPk->nKeyCol; j++){
9759897893
k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
97599
- assert( k>=0 && k<pTab->nCol );
97894
+ assert( k>=0 && k<pIdx->nColumn );
9760097895
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, regKey+j);
9760197896
VdbeComment((v, "%s", pTab->aCol[pPk->aiColumn[j]].zName));
9760297897
}
9760397898
sqlite3VdbeAddOp3(v, OP_MakeRecord, regKey, pPk->nKeyCol, regRowid);
9760497899
sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol);
@@ -97778,44 +98073,32 @@
9777898073
/* Form 1: Analyze everything */
9777998074
for(i=0; i<db->nDb; i++){
9778098075
if( i==1 ) continue; /* Do not analyze the TEMP database */
9778198076
analyzeDatabase(pParse, i);
9778298077
}
97783
- }else if( pName2->n==0 ){
97784
- /* Form 2: Analyze the database or table named */
97785
- iDb = sqlite3FindDb(db, pName1);
97786
- if( iDb>=0 ){
97787
- analyzeDatabase(pParse, iDb);
97788
- }else{
97789
- z = sqlite3NameFromToken(db, pName1);
97790
- if( z ){
97791
- if( (pIdx = sqlite3FindIndex(db, z, 0))!=0 ){
97792
- analyzeTable(pParse, pIdx->pTable, pIdx);
97793
- }else if( (pTab = sqlite3LocateTable(pParse, 0, z, 0))!=0 ){
97794
- analyzeTable(pParse, pTab, 0);
97795
- }
97796
- sqlite3DbFree(db, z);
97797
- }
97798
- }
97799
- }else{
97800
- /* Form 3: Analyze the fully qualified table name */
98078
+ }else if( pName2->n==0 && (iDb = sqlite3FindDb(db, pName1))>=0 ){
98079
+ /* Analyze the schema named as the argument */
98080
+ analyzeDatabase(pParse, iDb);
98081
+ }else{
98082
+ /* Form 3: Analyze the table or index named as an argument */
9780198083
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName);
9780298084
if( iDb>=0 ){
97803
- zDb = db->aDb[iDb].zDbSName;
98085
+ zDb = pName2->n ? db->aDb[iDb].zDbSName : 0;
9780498086
z = sqlite3NameFromToken(db, pTableName);
9780598087
if( z ){
9780698088
if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
9780798089
analyzeTable(pParse, pIdx->pTable, pIdx);
9780898090
}else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){
9780998091
analyzeTable(pParse, pTab, 0);
9781098092
}
9781198093
sqlite3DbFree(db, z);
9781298094
}
97813
- }
98095
+ }
9781498096
}
97815
- v = sqlite3GetVdbe(pParse);
97816
- if( v ) sqlite3VdbeAddOp0(v, OP_Expire);
98097
+ if( db->nSqlExec==0 && (v = sqlite3GetVdbe(pParse))!=0 ){
98098
+ sqlite3VdbeAddOp0(v, OP_Expire);
98099
+ }
9781798100
}
9781898101
9781998102
/*
9782098103
** Used to pass information from the analyzer reader through to the
9782198104
** callback routine.
@@ -97940,19 +98223,24 @@
9794098223
}
9794198224
aiRowEst = pIndex->aiRowEst;
9794298225
#endif
9794398226
pIndex->bUnordered = 0;
9794498227
decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex);
97945
- if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
98228
+ pIndex->hasStat1 = 1;
98229
+ if( pIndex->pPartIdxWhere==0 ){
98230
+ pTable->nRowLogEst = pIndex->aiRowLogEst[0];
98231
+ pTable->tabFlags |= TF_HasStat1;
98232
+ }
9794698233
}else{
9794798234
Index fakeIdx;
9794898235
fakeIdx.szIdxRow = pTable->szTabRow;
9794998236
#ifdef SQLITE_ENABLE_COSTMULT
9795098237
fakeIdx.pTable = pTable;
9795198238
#endif
9795298239
decodeIntArray((char*)z, 1, 0, &pTable->nRowLogEst, &fakeIdx);
9795398240
pTable->szTabRow = fakeIdx.szIdxRow;
98241
+ pTable->tabFlags |= TF_HasStat1;
9795498242
}
9795598243
9795698244
return 0;
9795798245
}
9795898246
@@ -98243,19 +98531,24 @@
9824398531
SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
9824498532
analysisInfo sInfo;
9824598533
HashElem *i;
9824698534
char *zSql;
9824798535
int rc = SQLITE_OK;
98536
+ Schema *pSchema = db->aDb[iDb].pSchema;
9824898537
9824998538
assert( iDb>=0 && iDb<db->nDb );
9825098539
assert( db->aDb[iDb].pBt!=0 );
9825198540
9825298541
/* Clear any prior statistics */
9825398542
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
98254
- for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
98543
+ for(i=sqliteHashFirst(&pSchema->tblHash); i; i=sqliteHashNext(i)){
98544
+ Table *pTab = sqliteHashData(i);
98545
+ pTab->tabFlags &= ~TF_HasStat1;
98546
+ }
98547
+ for(i=sqliteHashFirst(&pSchema->idxHash); i; i=sqliteHashNext(i)){
9825598548
Index *pIdx = sqliteHashData(i);
98256
- pIdx->aiRowLogEst[0] = 0;
98549
+ pIdx->hasStat1 = 0;
9825798550
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
9825898551
sqlite3DeleteIndexSamples(db, pIdx);
9825998552
pIdx->aSample = 0;
9826098553
#endif
9826198554
}
@@ -98274,23 +98567,23 @@
9827498567
}
9827598568
}
9827698569
9827798570
/* Set appropriate defaults on all indexes not in the sqlite_stat1 table */
9827898571
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
98279
- for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
98572
+ for(i=sqliteHashFirst(&pSchema->idxHash); i; i=sqliteHashNext(i)){
9828098573
Index *pIdx = sqliteHashData(i);
98281
- if( pIdx->aiRowLogEst[0]==0 ) sqlite3DefaultRowEst(pIdx);
98574
+ if( !pIdx->hasStat1 ) sqlite3DefaultRowEst(pIdx);
9828298575
}
9828398576
9828498577
/* Load the statistics from the sqlite_stat4 table. */
9828598578
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
9828698579
if( rc==SQLITE_OK && OptimizationEnabled(db, SQLITE_Stat34) ){
9828798580
db->lookaside.bDisable++;
9828898581
rc = loadStat4(db, sInfo.zDatabase);
9828998582
db->lookaside.bDisable--;
9829098583
}
98291
- for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
98584
+ for(i=sqliteHashFirst(&pSchema->idxHash); i; i=sqliteHashNext(i)){
9829298585
Index *pIdx = sqliteHashData(i);
9829398586
sqlite3_free(pIdx->aiRowEst);
9829498587
pIdx->aiRowEst = 0;
9829598588
}
9829698589
#endif
@@ -100271,10 +100564,11 @@
100271100564
SQLITE_PRIVATE void sqlite3AddNotNull(Parse *pParse, int onError){
100272100565
Table *p;
100273100566
p = pParse->pNewTable;
100274100567
if( p==0 || NEVER(p->nCol<1) ) return;
100275100568
p->aCol[p->nCol-1].notNull = (u8)onError;
100569
+ p->tabFlags |= TF_HasNotNull;
100276100570
}
100277100571
100278100572
/*
100279100573
** Scan the column type name zType (length nType) and return the
100280100574
** associated affinity type.
@@ -102609,10 +102903,13 @@
102609102903
/* 10, 9, 8, 7, 6 */
102610102904
LogEst aVal[] = { 33, 32, 30, 28, 26 };
102611102905
LogEst *a = pIdx->aiRowLogEst;
102612102906
int nCopy = MIN(ArraySize(aVal), pIdx->nKeyCol);
102613102907
int i;
102908
+
102909
+ /* Indexes with default row estimates should not have stat1 data */
102910
+ assert( !pIdx->hasStat1 );
102614102911
102615102912
/* Set the first entry (number of rows in the index) to the estimated
102616102913
** number of rows in the table, or half the number of rows in the table
102617102914
** for a partial index. But do not let the estimate drop below 10. */
102618102915
a[0] = pIdx->pTable->nRowLogEst;
@@ -105193,19 +105490,17 @@
105193105490
nNeedle = sqlite3_value_bytes(argv[1]);
105194105491
if( nNeedle>0 ){
105195105492
if( typeHaystack==SQLITE_BLOB && typeNeedle==SQLITE_BLOB ){
105196105493
zHaystack = sqlite3_value_blob(argv[0]);
105197105494
zNeedle = sqlite3_value_blob(argv[1]);
105198
- assert( zNeedle!=0 );
105199
- assert( zHaystack!=0 || nHaystack==0 );
105200105495
isText = 0;
105201105496
}else{
105202105497
zHaystack = sqlite3_value_text(argv[0]);
105203105498
zNeedle = sqlite3_value_text(argv[1]);
105204105499
isText = 1;
105205
- if( zHaystack==0 || zNeedle==0 ) return;
105206105500
}
105501
+ if( zNeedle==0 || (nHaystack && zHaystack==0) ) return;
105207105502
while( nNeedle<=nHaystack && memcmp(zHaystack, zNeedle, nNeedle)!=0 ){
105208105503
N++;
105209105504
do{
105210105505
nHaystack--;
105211105506
zHaystack++;
@@ -109798,10 +110093,13 @@
109798110093
VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
109799110094
}
109800110095
}
109801110096
sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
109802110097
VdbeComment((v, "for %s", pIdx->zName));
110098
+#ifdef SQLITE_ENABLE_NULL_TRIM
110099
+ if( pIdx->idxType==2 ) sqlite3SetMakeRecordP5(v, pIdx->pTable);
110100
+#endif
109803110101
109804110102
/* In an UPDATE operation, if this index is the PRIMARY KEY index
109805110103
** of a WITHOUT ROWID table and there has been no change the
109806110104
** primary key, then no collision is possible. The collision detection
109807110105
** logic below can all be skipped. */
@@ -109953,12 +110251,15 @@
109953110251
109954110252
/* Records with omitted columns are only allowed for schema format
109955110253
** version 2 and later (SQLite version 3.1.4, 2005-02-20). */
109956110254
if( pTab->pSchema->file_format<2 ) return;
109957110255
109958
- for(i=pTab->nCol; i>1 && pTab->aCol[i-1].pDflt==0; i--){}
109959
- sqlite3VdbeChangeP5(v, i);
110256
+ for(i=pTab->nCol-1; i>0; i--){
110257
+ if( pTab->aCol[i].pDflt!=0 ) break;
110258
+ if( pTab->aCol[i].colFlags & COLFLAG_PRIMKEY ) break;
110259
+ }
110260
+ sqlite3VdbeChangeP5(v, i+1);
109960110261
}
109961110262
#endif
109962110263
109963110264
/*
109964110265
** This routine generates code to finish the INSERT or UPDATE operation
@@ -110244,11 +110545,11 @@
110244110545
}
110245110546
if( sqlite3TriggerList(pParse, pDest) ){
110246110547
return 0; /* tab1 must not have triggers */
110247110548
}
110248110549
#ifndef SQLITE_OMIT_VIRTUALTABLE
110249
- if( pDest->tabFlags & TF_Virtual ){
110550
+ if( IsVirtual(pDest) ){
110250110551
return 0; /* tab1 must not be a virtual table */
110251110552
}
110252110553
#endif
110253110554
if( onError==OE_Default ){
110254110555
if( pDest->iPKey>=0 ) onError = pDest->keyConf;
@@ -110306,11 +110607,11 @@
110306110607
}
110307110608
if( HasRowid(pDest)!=HasRowid(pSrc) ){
110308110609
return 0; /* source and destination must both be WITHOUT ROWID or not */
110309110610
}
110310110611
#ifndef SQLITE_OMIT_VIRTUALTABLE
110311
- if( pSrc->tabFlags & TF_Virtual ){
110612
+ if( IsVirtual(pSrc) ){
110312110613
return 0; /* tab2 must not be a virtual table */
110313110614
}
110314110615
#endif
110315110616
if( pSrc->pSelect ){
110316110617
return 0; /* tab2 may not be a view */
@@ -110492,12 +110793,10 @@
110492110793
** might change the definition of a collation sequence and then run
110493110794
** a VACUUM command. In that case keys may not be written in strictly
110494110795
** sorted order. */
110495110796
for(i=0; i<pSrcIdx->nColumn; i++){
110496110797
const char *zColl = pSrcIdx->azColl[i];
110497
- assert( sqlite3_stricmp(sqlite3StrBINARY, zColl)!=0
110498
- || sqlite3StrBINARY==zColl );
110499110798
if( sqlite3_stricmp(sqlite3StrBINARY, zColl) ) break;
110500110799
}
110501110800
if( i==pSrcIdx->nColumn ){
110502110801
idxInsFlags = OPFLAG_USESEEKRESULT;
110503110802
sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
@@ -110603,11 +110902,11 @@
110603110902
/* Invoke the callback function if required */
110604110903
if( xCallback && (SQLITE_ROW==rc ||
110605110904
(SQLITE_DONE==rc && !callbackIsInit
110606110905
&& db->flags&SQLITE_NullCallback)) ){
110607110906
if( !callbackIsInit ){
110608
- azCols = sqlite3DbMallocZero(db, 2*nCol*sizeof(const char*) + 1);
110907
+ azCols = sqlite3DbMallocRaw(db, (2*nCol+1)*sizeof(const char*));
110609110908
if( azCols==0 ){
110610110909
goto exec_out;
110611110910
}
110612110911
for(i=0; i<nCol; i++){
110613110912
azCols[i] = (char *)sqlite3_column_name(pStmt, i);
@@ -110624,10 +110923,11 @@
110624110923
if( !azVals[i] && sqlite3_column_type(pStmt, i)!=SQLITE_NULL ){
110625110924
sqlite3OomFault(db);
110626110925
goto exec_out;
110627110926
}
110628110927
}
110928
+ azVals[i] = 0;
110629110929
}
110630110930
if( xCallback(pArg, nCol, azVals, azCols) ){
110631110931
/* EVIDENCE-OF: R-38229-40159 If the callback function to
110632110932
** sqlite3_exec() returns non-zero, then sqlite3_exec() will
110633110933
** return SQLITE_ABORT. */
@@ -110979,10 +111279,12 @@
110979111279
/* Version 3.12.0 and later */
110980111280
int (*system_errno)(sqlite3*);
110981111281
/* Version 3.14.0 and later */
110982111282
int (*trace_v2)(sqlite3*,unsigned,int(*)(unsigned,void*,void*,void*),void*);
110983111283
char *(*expanded_sql)(sqlite3_stmt*);
111284
+ /* Version 3.18.0 and later */
111285
+ void (*set_last_insert_rowid)(sqlite3*,sqlite3_int64);
110984111286
};
110985111287
110986111288
/*
110987111289
** This is the function signature used for all extension entry points. It
110988111290
** is also defined in the file "loadext.c".
@@ -111237,10 +111539,12 @@
111237111539
/* Version 3.12.0 and later */
111238111540
#define sqlite3_system_errno sqlite3_api->system_errno
111239111541
/* Version 3.14.0 and later */
111240111542
#define sqlite3_trace_v2 sqlite3_api->trace_v2
111241111543
#define sqlite3_expanded_sql sqlite3_api->expanded_sql
111544
+/* Version 3.18.0 and later */
111545
+#define sqlite3_set_last_insert_rowid sqlite3_api->set_last_insert_rowid
111242111546
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
111243111547
111244111548
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
111245111549
/* This case when the file really is being compiled as a loadable
111246111550
** extension */
@@ -111662,11 +111966,13 @@
111662111966
sqlite3_db_cacheflush,
111663111967
/* Version 3.12.0 and later */
111664111968
sqlite3_system_errno,
111665111969
/* Version 3.14.0 and later */
111666111970
sqlite3_trace_v2,
111667
- sqlite3_expanded_sql
111971
+ sqlite3_expanded_sql,
111972
+ /* Version 3.18.0 and later */
111973
+ sqlite3_set_last_insert_rowid
111668111974
};
111669111975
111670111976
/*
111671111977
** Attempt to load an SQLite extension library contained in the file
111672111978
** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -112094,15 +112400,15 @@
112094112400
#define PragTyp_JOURNAL_SIZE_LIMIT 20
112095112401
#define PragTyp_LOCK_PROXY_FILE 21
112096112402
#define PragTyp_LOCKING_MODE 22
112097112403
#define PragTyp_PAGE_COUNT 23
112098112404
#define PragTyp_MMAP_SIZE 24
112099
-#define PragTyp_PAGE_SIZE 25
112100
-#define PragTyp_SECURE_DELETE 26
112101
-#define PragTyp_SHRINK_MEMORY 27
112102
-#define PragTyp_SOFT_HEAP_LIMIT 28
112103
-#define PragTyp_STATS 29
112405
+#define PragTyp_OPTIMIZE 25
112406
+#define PragTyp_PAGE_SIZE 26
112407
+#define PragTyp_SECURE_DELETE 27
112408
+#define PragTyp_SHRINK_MEMORY 28
112409
+#define PragTyp_SOFT_HEAP_LIMIT 29
112104112410
#define PragTyp_SYNCHRONOUS 30
112105112411
#define PragTyp_TABLE_INFO 31
112106112412
#define PragTyp_TEMP_STORE 32
112107112413
#define PragTyp_TEMP_STORE_DIRECTORY 33
112108112414
#define PragTyp_THREADS 34
@@ -112112,10 +112418,11 @@
112112112418
#define PragTyp_HEXKEY 38
112113112419
#define PragTyp_KEY 39
112114112420
#define PragTyp_REKEY 40
112115112421
#define PragTyp_LOCK_STATUS 41
112116112422
#define PragTyp_PARSER_TRACE 42
112423
+#define PragTyp_STATS 43
112117112424
112118112425
/* Property flags associated with various pragma. */
112119112426
#define PragFlg_NeedSchema 0x01 /* Force schema load before running */
112120112427
#define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */
112121112428
#define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */
@@ -112135,51 +112442,52 @@
112135112442
/* 2 */ "name",
112136112443
/* 3 */ "type",
112137112444
/* 4 */ "notnull",
112138112445
/* 5 */ "dflt_value",
112139112446
/* 6 */ "pk",
112140
- /* 7 */ "table", /* Used by: stats */
112141
- /* 8 */ "index",
112142
- /* 9 */ "width",
112143
- /* 10 */ "height",
112144
- /* 11 */ "seqno", /* Used by: index_info */
112145
- /* 12 */ "cid",
112146
- /* 13 */ "name",
112147
- /* 14 */ "seqno", /* Used by: index_xinfo */
112148
- /* 15 */ "cid",
112149
- /* 16 */ "name",
112150
- /* 17 */ "desc",
112151
- /* 18 */ "coll",
112152
- /* 19 */ "key",
112153
- /* 20 */ "seq", /* Used by: index_list */
112154
- /* 21 */ "name",
112155
- /* 22 */ "unique",
112156
- /* 23 */ "origin",
112157
- /* 24 */ "partial",
112158
- /* 25 */ "seq", /* Used by: database_list */
112159
- /* 26 */ "name",
112160
- /* 27 */ "file",
112161
- /* 28 */ "seq", /* Used by: collation_list */
112162
- /* 29 */ "name",
112163
- /* 30 */ "id", /* Used by: foreign_key_list */
112164
- /* 31 */ "seq",
112165
- /* 32 */ "table",
112166
- /* 33 */ "from",
112167
- /* 34 */ "to",
112168
- /* 35 */ "on_update",
112169
- /* 36 */ "on_delete",
112170
- /* 37 */ "match",
112171
- /* 38 */ "table", /* Used by: foreign_key_check */
112172
- /* 39 */ "rowid",
112173
- /* 40 */ "parent",
112174
- /* 41 */ "fkid",
112175
- /* 42 */ "busy", /* Used by: wal_checkpoint */
112176
- /* 43 */ "log",
112177
- /* 44 */ "checkpointed",
112178
- /* 45 */ "timeout", /* Used by: busy_timeout */
112179
- /* 46 */ "database", /* Used by: lock_status */
112180
- /* 47 */ "status",
112447
+ /* 7 */ "tbl", /* Used by: stats */
112448
+ /* 8 */ "idx",
112449
+ /* 9 */ "wdth",
112450
+ /* 10 */ "hght",
112451
+ /* 11 */ "flgs",
112452
+ /* 12 */ "seqno", /* Used by: index_info */
112453
+ /* 13 */ "cid",
112454
+ /* 14 */ "name",
112455
+ /* 15 */ "seqno", /* Used by: index_xinfo */
112456
+ /* 16 */ "cid",
112457
+ /* 17 */ "name",
112458
+ /* 18 */ "desc",
112459
+ /* 19 */ "coll",
112460
+ /* 20 */ "key",
112461
+ /* 21 */ "seq", /* Used by: index_list */
112462
+ /* 22 */ "name",
112463
+ /* 23 */ "unique",
112464
+ /* 24 */ "origin",
112465
+ /* 25 */ "partial",
112466
+ /* 26 */ "seq", /* Used by: database_list */
112467
+ /* 27 */ "name",
112468
+ /* 28 */ "file",
112469
+ /* 29 */ "seq", /* Used by: collation_list */
112470
+ /* 30 */ "name",
112471
+ /* 31 */ "id", /* Used by: foreign_key_list */
112472
+ /* 32 */ "seq",
112473
+ /* 33 */ "table",
112474
+ /* 34 */ "from",
112475
+ /* 35 */ "to",
112476
+ /* 36 */ "on_update",
112477
+ /* 37 */ "on_delete",
112478
+ /* 38 */ "match",
112479
+ /* 39 */ "table", /* Used by: foreign_key_check */
112480
+ /* 40 */ "rowid",
112481
+ /* 41 */ "parent",
112482
+ /* 42 */ "fkid",
112483
+ /* 43 */ "busy", /* Used by: wal_checkpoint */
112484
+ /* 44 */ "log",
112485
+ /* 45 */ "checkpointed",
112486
+ /* 46 */ "timeout", /* Used by: busy_timeout */
112487
+ /* 47 */ "database", /* Used by: lock_status */
112488
+ /* 48 */ "status",
112181112489
};
112182112490
112183112491
/* Definitions of all built-in pragmas */
112184112492
typedef struct PragmaName {
112185112493
const char *const zName; /* Name of pragma */
@@ -112221,11 +112529,11 @@
112221112529
#endif
112222112530
#endif
112223112531
{/* zName: */ "busy_timeout",
112224112532
/* ePragTyp: */ PragTyp_BUSY_TIMEOUT,
112225112533
/* ePragFlg: */ PragFlg_Result0,
112226
- /* ColNames: */ 45, 1,
112534
+ /* ColNames: */ 46, 1,
112227112535
/* iArg: */ 0 },
112228112536
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112229112537
{/* zName: */ "cache_size",
112230112538
/* ePragTyp: */ PragTyp_CACHE_SIZE,
112231112539
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
@@ -112258,11 +112566,11 @@
112258112566
#endif
112259112567
#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
112260112568
{/* zName: */ "collation_list",
112261112569
/* ePragTyp: */ PragTyp_COLLATION_LIST,
112262112570
/* ePragFlg: */ PragFlg_Result0,
112263
- /* ColNames: */ 28, 2,
112571
+ /* ColNames: */ 29, 2,
112264112572
/* iArg: */ 0 },
112265112573
#endif
112266112574
#if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
112267112575
{/* zName: */ "compile_options",
112268112576
/* ePragTyp: */ PragTyp_COMPILE_OPTIONS,
@@ -112293,11 +112601,11 @@
112293112601
#endif
112294112602
#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
112295112603
{/* zName: */ "database_list",
112296112604
/* ePragTyp: */ PragTyp_DATABASE_LIST,
112297112605
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
112298
- /* ColNames: */ 25, 3,
112606
+ /* ColNames: */ 26, 3,
112299112607
/* iArg: */ 0 },
112300112608
#endif
112301112609
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
112302112610
{/* zName: */ "default_cache_size",
112303112611
/* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
@@ -112330,18 +112638,18 @@
112330112638
#endif
112331112639
#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
112332112640
{/* zName: */ "foreign_key_check",
112333112641
/* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK,
112334112642
/* ePragFlg: */ PragFlg_NeedSchema,
112335
- /* ColNames: */ 38, 4,
112643
+ /* ColNames: */ 39, 4,
112336112644
/* iArg: */ 0 },
112337112645
#endif
112338112646
#if !defined(SQLITE_OMIT_FOREIGN_KEY)
112339112647
{/* zName: */ "foreign_key_list",
112340112648
/* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST,
112341112649
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112342
- /* ColNames: */ 30, 8,
112650
+ /* ColNames: */ 31, 8,
112343112651
/* iArg: */ 0 },
112344112652
#endif
112345112653
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112346112654
#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
112347112655
{/* zName: */ "foreign_keys",
@@ -112400,21 +112708,21 @@
112400112708
#endif
112401112709
#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
112402112710
{/* zName: */ "index_info",
112403112711
/* ePragTyp: */ PragTyp_INDEX_INFO,
112404112712
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112405
- /* ColNames: */ 11, 3,
112713
+ /* ColNames: */ 12, 3,
112406112714
/* iArg: */ 0 },
112407112715
{/* zName: */ "index_list",
112408112716
/* ePragTyp: */ PragTyp_INDEX_LIST,
112409112717
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112410
- /* ColNames: */ 20, 5,
112718
+ /* ColNames: */ 21, 5,
112411112719
/* iArg: */ 0 },
112412112720
{/* zName: */ "index_xinfo",
112413112721
/* ePragTyp: */ PragTyp_INDEX_INFO,
112414112722
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112415
- /* ColNames: */ 14, 6,
112723
+ /* ColNames: */ 15, 6,
112416112724
/* iArg: */ 1 },
112417112725
#endif
112418112726
#if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
112419112727
{/* zName: */ "integrity_check",
112420112728
/* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
@@ -112457,11 +112765,11 @@
112457112765
#endif
112458112766
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
112459112767
{/* zName: */ "lock_status",
112460112768
/* ePragTyp: */ PragTyp_LOCK_STATUS,
112461112769
/* ePragFlg: */ PragFlg_Result0,
112462
- /* ColNames: */ 46, 2,
112770
+ /* ColNames: */ 47, 2,
112463112771
/* iArg: */ 0 },
112464112772
#endif
112465112773
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112466112774
{/* zName: */ "locking_mode",
112467112775
/* ePragTyp: */ PragTyp_LOCKING_MODE,
@@ -112476,10 +112784,17 @@
112476112784
{/* zName: */ "mmap_size",
112477112785
/* ePragTyp: */ PragTyp_MMAP_SIZE,
112478112786
/* ePragFlg: */ 0,
112479112787
/* ColNames: */ 0, 0,
112480112788
/* iArg: */ 0 },
112789
+#endif
112790
+ {/* zName: */ "optimize",
112791
+ /* ePragTyp: */ PragTyp_OPTIMIZE,
112792
+ /* ePragFlg: */ PragFlg_Result1,
112793
+ /* ColNames: */ 0, 0,
112794
+ /* iArg: */ 0 },
112795
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112481112796
{/* zName: */ "page_count",
112482112797
/* ePragTyp: */ PragTyp_PAGE_COUNT,
112483112798
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
112484112799
/* ColNames: */ 0, 0,
112485112800
/* iArg: */ 0 },
@@ -112574,15 +112889,15 @@
112574112889
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
112575112890
/* ColNames: */ 0, 0,
112576112891
/* iArg: */ SQLITE_SqlTrace },
112577112892
#endif
112578112893
#endif
112579
-#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
112894
+#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && defined(SQLITE_DEBUG)
112580112895
{/* zName: */ "stats",
112581112896
/* ePragTyp: */ PragTyp_STATS,
112582112897
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
112583
- /* ColNames: */ 7, 4,
112898
+ /* ColNames: */ 7, 5,
112584112899
/* iArg: */ 0 },
112585112900
#endif
112586112901
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112587112902
{/* zName: */ "synchronous",
112588112903
/* ePragTyp: */ PragTyp_SYNCHRONOUS,
@@ -112657,11 +112972,11 @@
112657112972
/* ColNames: */ 0, 0,
112658112973
/* iArg: */ 0 },
112659112974
{/* zName: */ "wal_checkpoint",
112660112975
/* ePragTyp: */ PragTyp_WAL_CHECKPOINT,
112661112976
/* ePragFlg: */ PragFlg_NeedSchema,
112662
- /* ColNames: */ 42, 3,
112977
+ /* ColNames: */ 43, 3,
112663112978
/* iArg: */ 0 },
112664112979
#endif
112665112980
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112666112981
{/* zName: */ "writable_schema",
112667112982
/* ePragTyp: */ PragTyp_FLAG,
@@ -112668,11 +112983,11 @@
112668112983
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
112669112984
/* ColNames: */ 0, 0,
112670112985
/* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
112671112986
#endif
112672112987
};
112673
-/* Number of pragmas: 60 on by default, 73 total. */
112988
+/* Number of pragmas: 60 on by default, 74 total. */
112674112989
112675112990
/************** End of pragma.h **********************************************/
112676112991
/************** Continuing where we left off in pragma.c *********************/
112677112992
112678112993
/*
@@ -112937,10 +113252,26 @@
112937113252
lwr = mid + 1;
112938113253
}
112939113254
}
112940113255
return lwr>upr ? 0 : &aPragmaName[mid];
112941113256
}
113257
+
113258
+/*
113259
+** Helper subroutine for PRAGMA integrity_check:
113260
+**
113261
+** Generate code to output a single-column result row with the result
113262
+** held in register regResult. Decrement the result count and halt if
113263
+** the maximum number of result rows have been issued.
113264
+*/
113265
+static int integrityCheckResultRow(Vdbe *v, int regResult){
113266
+ int addr;
113267
+ sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 1);
113268
+ addr = sqlite3VdbeAddOp3(v, OP_IfPos, 1, sqlite3VdbeCurrentAddr(v)+2, 1);
113269
+ VdbeCoverage(v);
113270
+ sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
113271
+ return addr;
113272
+}
112942113273
112943113274
/*
112944113275
** Process a pragma statement.
112945113276
**
112946113277
** Pragmas are of this form:
@@ -113642,11 +113973,11 @@
113642113973
returnSingleInt(v, pDb->safety_level-1);
113643113974
}else{
113644113975
if( !db->autoCommit ){
113645113976
sqlite3ErrorMsg(pParse,
113646113977
"Safety level may not be changed inside a transaction");
113647
- }else{
113978
+ }else if( iDb!=1 ){
113648113979
int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK;
113649113980
if( iLevel==0 ) iLevel = 1;
113650113981
pDb->safety_level = iLevel;
113651113982
pDb->bSyncSet = 1;
113652113983
setAllPagerFlags(db);
@@ -113741,33 +114072,37 @@
113741114072
}
113742114073
}
113743114074
}
113744114075
break;
113745114076
114077
+#ifdef SQLITE_DEBUG
113746114078
case PragTyp_STATS: {
113747114079
Index *pIdx;
113748114080
HashElem *i;
113749
- pParse->nMem = 4;
114081
+ pParse->nMem = 5;
113750114082
sqlite3CodeVerifySchema(pParse, iDb);
113751114083
for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){
113752114084
Table *pTab = sqliteHashData(i);
113753
- sqlite3VdbeMultiLoad(v, 1, "ssii",
114085
+ sqlite3VdbeMultiLoad(v, 1, "ssiii",
113754114086
pTab->zName,
113755114087
0,
113756114088
pTab->szTabRow,
113757
- pTab->nRowLogEst);
113758
- sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4);
114089
+ pTab->nRowLogEst,
114090
+ pTab->tabFlags);
114091
+ sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 5);
113759114092
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
113760
- sqlite3VdbeMultiLoad(v, 2, "sii",
114093
+ sqlite3VdbeMultiLoad(v, 2, "siii",
113761114094
pIdx->zName,
113762114095
pIdx->szIdxRow,
113763
- pIdx->aiRowLogEst[0]);
113764
- sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4);
114096
+ pIdx->aiRowLogEst[0],
114097
+ pIdx->hasStat1);
114098
+ sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 5);
113765114099
}
113766114100
}
113767114101
}
113768114102
break;
114103
+#endif
113769114104
113770114105
case PragTyp_INDEX_INFO: if( zRight ){
113771114106
Index *pIdx;
113772114107
Table *pTab;
113773114108
pIdx = sqlite3FindIndex(db, zRight, zDb);
@@ -114020,13 +114355,21 @@
114020114355
#ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
114021114356
# define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100
114022114357
#endif
114023114358
114024114359
#ifndef SQLITE_OMIT_INTEGRITY_CHECK
114025
- /* Pragma "quick_check" is reduced version of
114360
+ /* PRAGMA integrity_check
114361
+ ** PRAGMA integrity_check(N)
114362
+ ** PRAGMA quick_check
114363
+ ** PRAGMA quick_check(N)
114364
+ **
114365
+ ** Verify the integrity of the database.
114366
+ **
114367
+ ** The "quick_check" is reduced version of
114026114368
** integrity_check designed to detect most database corruption
114027
- ** without most of the overhead of a full integrity-check.
114369
+ ** without the overhead of cross-checking indexes. Quick_check
114370
+ ** is linear time wherease integrity_check is O(NlogN).
114028114371
*/
114029114372
case PragTyp_INTEGRITY_CHECK: {
114030114373
int i, j, addr, mxErr;
114031114374
114032114375
int isQuick = (sqlite3Tolower(zLeft[0])=='q');
@@ -114053,11 +114396,11 @@
114053114396
sqlite3GetInt32(zRight, &mxErr);
114054114397
if( mxErr<=0 ){
114055114398
mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
114056114399
}
114057114400
}
114058
- sqlite3VdbeAddOp2(v, OP_Integer, mxErr, 1); /* reg[1] holds errors left */
114401
+ sqlite3VdbeAddOp2(v, OP_Integer, mxErr-1, 1); /* reg[1] holds errors left */
114059114402
114060114403
/* Do an integrity check on each database file */
114061114404
for(i=0; i<db->nDb; i++){
114062114405
HashElem *x;
114063114406
Hash *pTbls;
@@ -114068,14 +114411,10 @@
114068114411
114069114412
if( OMIT_TEMPDB && i==1 ) continue;
114070114413
if( iDb>=0 && i!=iDb ) continue;
114071114414
114072114415
sqlite3CodeVerifySchema(pParse, i);
114073
- addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Halt if out of errors */
114074
- VdbeCoverage(v);
114075
- sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
114076
- sqlite3VdbeJumpHere(v, addr);
114077114416
114078114417
/* Do an integrity check of the B-Tree
114079114418
**
114080114419
** Begin by finding the root pages numbers
114081114420
** for all tables and indices in the database.
@@ -114111,29 +114450,31 @@
114111114450
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
114112114451
sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zDbSName),
114113114452
P4_DYNAMIC);
114114114453
sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1);
114115114454
sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
114116
- sqlite3VdbeAddOp2(v, OP_ResultRow, 2, 1);
114455
+ integrityCheckResultRow(v, 2);
114117114456
sqlite3VdbeJumpHere(v, addr);
114118114457
114119114458
/* Make sure all the indices are constructed correctly.
114120114459
*/
114121
- for(x=sqliteHashFirst(pTbls); x && !isQuick; x=sqliteHashNext(x)){
114460
+ for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
114122114461
Table *pTab = sqliteHashData(x);
114123114462
Index *pIdx, *pPk;
114124114463
Index *pPrior = 0;
114125114464
int loopTop;
114126114465
int iDataCur, iIdxCur;
114127114466
int r1 = -1;
114128114467
114129
- if( pTab->pIndex==0 ) continue;
114468
+ if( pTab->tnum<1 ) continue; /* Skip VIEWs or VIRTUAL TABLEs */
114469
+ if( pTab->pCheck==0
114470
+ && (pTab->tabFlags & TF_HasNotNull)==0
114471
+ && (pTab->pIndex==0 || isQuick)
114472
+ ){
114473
+ continue; /* No additional checks needed for this table */
114474
+ }
114130114475
pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
114131
- addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
114132
- VdbeCoverage(v);
114133
- sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
114134
- sqlite3VdbeJumpHere(v, addr);
114135114476
sqlite3ExprCacheClear(pParse);
114136114477
sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
114137114478
1, 0, &iDataCur, &iIdxCur);
114138114479
sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
114139114480
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
@@ -114144,28 +114485,46 @@
114144114485
sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v);
114145114486
loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1);
114146114487
/* Verify that all NOT NULL columns really are NOT NULL */
114147114488
for(j=0; j<pTab->nCol; j++){
114148114489
char *zErr;
114149
- int jmp2, jmp3;
114490
+ int jmp2;
114150114491
if( j==pTab->iPKey ) continue;
114151114492
if( pTab->aCol[j].notNull==0 ) continue;
114152114493
sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3);
114153114494
sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
114154114495
jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
114155
- sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
114156114496
zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
114157114497
pTab->aCol[j].zName);
114158114498
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
114159
- sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
114160
- jmp3 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v);
114161
- sqlite3VdbeAddOp0(v, OP_Halt);
114499
+ integrityCheckResultRow(v, 3);
114162114500
sqlite3VdbeJumpHere(v, jmp2);
114163
- sqlite3VdbeJumpHere(v, jmp3);
114501
+ }
114502
+ /* Verify CHECK constraints */
114503
+ if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
114504
+ int addrCkFault = sqlite3VdbeMakeLabel(v);
114505
+ int addrCkOk = sqlite3VdbeMakeLabel(v);
114506
+ ExprList *pCheck = pTab->pCheck;
114507
+ char *zErr;
114508
+ int k;
114509
+ pParse->iSelfTab = iDataCur;
114510
+ sqlite3ExprCachePush(pParse);
114511
+ for(k=pCheck->nExpr-1; k>0; k--){
114512
+ sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
114513
+ }
114514
+ sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk,
114515
+ SQLITE_JUMPIFNULL);
114516
+ sqlite3VdbeResolveLabel(v, addrCkFault);
114517
+ zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
114518
+ pTab->zName);
114519
+ sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
114520
+ integrityCheckResultRow(v, 3);
114521
+ sqlite3VdbeResolveLabel(v, addrCkOk);
114522
+ sqlite3ExprCachePop(pParse);
114164114523
}
114165114524
/* Validate index entries for the current row */
114166
- for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
114525
+ for(j=0, pIdx=pTab->pIndex; pIdx && !isQuick; pIdx=pIdx->pNext, j++){
114167114526
int jmp2, jmp3, jmp4, jmp5;
114168114527
int ckUniq = sqlite3VdbeMakeLabel(v);
114169114528
if( pPk==pIdx ) continue;
114170114529
r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
114171114530
pPrior, r1);
@@ -114172,20 +114531,17 @@
114172114531
pPrior = pIdx;
114173114532
sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */
114174114533
/* Verify that an index entry exists for the current table row */
114175114534
jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
114176114535
pIdx->nColumn); VdbeCoverage(v);
114177
- sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
114178114536
sqlite3VdbeLoadString(v, 3, "row ");
114179114537
sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
114180114538
sqlite3VdbeLoadString(v, 4, " missing from index ");
114181114539
sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
114182114540
jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName);
114183114541
sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
114184
- sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
114185
- jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v);
114186
- sqlite3VdbeAddOp0(v, OP_Halt);
114542
+ jmp4 = integrityCheckResultRow(v, 3);
114187114543
sqlite3VdbeJumpHere(v, jmp2);
114188114544
/* For UNIQUE indexes, verify that only one entry exists with the
114189114545
** current key. The entry is unique if (1) any column is NULL
114190114546
** or (2) the next entry has a different key */
114191114547
if( IsUniqueIndex(pIdx) ){
@@ -114202,11 +114558,10 @@
114202114558
jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v);
114203114559
sqlite3VdbeGoto(v, uniqOk);
114204114560
sqlite3VdbeJumpHere(v, jmp6);
114205114561
sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1,
114206114562
pIdx->nKeyCol); VdbeCoverage(v);
114207
- sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
114208114563
sqlite3VdbeLoadString(v, 3, "non-unique entry in index ");
114209114564
sqlite3VdbeGoto(v, jmp5);
114210114565
sqlite3VdbeResolveLabel(v, uniqOk);
114211114566
}
114212114567
sqlite3VdbeJumpHere(v, jmp4);
@@ -114213,40 +114568,39 @@
114213114568
sqlite3ResolvePartIdxLabel(pParse, jmp3);
114214114569
}
114215114570
sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
114216114571
sqlite3VdbeJumpHere(v, loopTop-1);
114217114572
#ifndef SQLITE_OMIT_BTREECOUNT
114218
- sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
114219
- for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
114220
- if( pPk==pIdx ) continue;
114221
- addr = sqlite3VdbeCurrentAddr(v);
114222
- sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); VdbeCoverage(v);
114223
- sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
114224
- sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
114225
- sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v);
114226
- sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
114227
- sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
114228
- sqlite3VdbeLoadString(v, 3, pIdx->zName);
114229
- sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
114230
- sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1);
114573
+ if( !isQuick ){
114574
+ sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
114575
+ for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
114576
+ if( pPk==pIdx ) continue;
114577
+ sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
114578
+ addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+j, 0, 3); VdbeCoverage(v);
114579
+ sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
114580
+ sqlite3VdbeLoadString(v, 3, pIdx->zName);
114581
+ sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
114582
+ integrityCheckResultRow(v, 7);
114583
+ sqlite3VdbeJumpHere(v, addr);
114584
+ }
114231114585
}
114232114586
#endif /* SQLITE_OMIT_BTREECOUNT */
114233114587
}
114234114588
}
114235114589
{
114236114590
static const int iLn = VDBE_OFFSET_LINENO(2);
114237114591
static const VdbeOpList endCode[] = {
114238114592
{ OP_AddImm, 1, 0, 0}, /* 0 */
114239
- { OP_If, 1, 4, 0}, /* 1 */
114593
+ { OP_IfNotZero, 1, 4, 0}, /* 1 */
114240114594
{ OP_String8, 0, 3, 0}, /* 2 */
114241114595
{ OP_ResultRow, 3, 1, 0}, /* 3 */
114242114596
};
114243114597
VdbeOp *aOp;
114244114598
114245114599
aOp = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
114246114600
if( aOp ){
114247
- aOp[0].p2 = -mxErr;
114601
+ aOp[0].p2 = 1-mxErr;
114248114602
aOp[2].p4type = P4_STATIC;
114249114603
aOp[2].p4.z = "ok";
114250114604
}
114251114605
}
114252114606
}
@@ -114466,10 +114820,122 @@
114466114820
*/
114467114821
case PragTyp_SHRINK_MEMORY: {
114468114822
sqlite3_db_release_memory(db);
114469114823
break;
114470114824
}
114825
+
114826
+ /*
114827
+ ** PRAGMA optimize
114828
+ ** PRAGMA optimize(MASK)
114829
+ ** PRAGMA schema.optimize
114830
+ ** PRAGMA schema.optimize(MASK)
114831
+ **
114832
+ ** Attempt to optimize the database. All schemas are optimized in the first
114833
+ ** two forms, and only the specified schema is optimized in the latter two.
114834
+ **
114835
+ ** The details of optimizations performed by this pragma are expected
114836
+ ** to change and improve over time. Applications should anticipate that
114837
+ ** this pragma will perform new optimizations in future releases.
114838
+ **
114839
+ ** The optional argument is a bitmask of optimizations to perform:
114840
+ **
114841
+ ** 0x0001 Debugging mode. Do not actually perform any optimizations
114842
+ ** but instead return one line of text for each optimization
114843
+ ** that would have been done. Off by default.
114844
+ **
114845
+ ** 0x0002 Run ANALYZE on tables that might benefit. On by default.
114846
+ ** See below for additional information.
114847
+ **
114848
+ ** 0x0004 (Not yet implemented) Record usage and performance
114849
+ ** information from the current session in the
114850
+ ** database file so that it will be available to "optimize"
114851
+ ** pragmas run by future database connections.
114852
+ **
114853
+ ** 0x0008 (Not yet implemented) Create indexes that might have
114854
+ ** been helpful to recent queries
114855
+ **
114856
+ ** The default MASK is and always shall be 0xfffe. 0xfffe means perform all ** of the optimizations listed above except Debug Mode, including new
114857
+ ** optimizations that have not yet been invented. If new optimizations are
114858
+ ** ever added that should be off by default, those off-by-default
114859
+ ** optimizations will have bitmasks of 0x10000 or larger.
114860
+ **
114861
+ ** DETERMINATION OF WHEN TO RUN ANALYZE
114862
+ **
114863
+ ** In the current implementation, a table is analyzed if only if all of
114864
+ ** the following are true:
114865
+ **
114866
+ ** (1) MASK bit 0x02 is set.
114867
+ **
114868
+ ** (2) The query planner used sqlite_stat1-style statistics for one or
114869
+ ** more indexes of the table at some point during the lifetime of
114870
+ ** the current connection.
114871
+ **
114872
+ ** (3) One or more indexes of the table are currently unanalyzed OR
114873
+ ** the number of rows in the table has increased by 25 times or more
114874
+ ** since the last time ANALYZE was run.
114875
+ **
114876
+ ** The rules for when tables are analyzed are likely to change in
114877
+ ** future releases.
114878
+ */
114879
+ case PragTyp_OPTIMIZE: {
114880
+ int iDbLast; /* Loop termination point for the schema loop */
114881
+ int iTabCur; /* Cursor for a table whose size needs checking */
114882
+ HashElem *k; /* Loop over tables of a schema */
114883
+ Schema *pSchema; /* The current schema */
114884
+ Table *pTab; /* A table in the schema */
114885
+ Index *pIdx; /* An index of the table */
114886
+ LogEst szThreshold; /* Size threshold above which reanalysis is needd */
114887
+ char *zSubSql; /* SQL statement for the OP_SqlExec opcode */
114888
+ u32 opMask; /* Mask of operations to perform */
114889
+
114890
+ if( zRight ){
114891
+ opMask = (u32)sqlite3Atoi(zRight);
114892
+ if( (opMask & 0x02)==0 ) break;
114893
+ }else{
114894
+ opMask = 0xfffe;
114895
+ }
114896
+ iTabCur = pParse->nTab++;
114897
+ for(iDbLast = zDb?iDb:db->nDb-1; iDb<=iDbLast; iDb++){
114898
+ if( iDb==1 ) continue;
114899
+ sqlite3CodeVerifySchema(pParse, iDb);
114900
+ pSchema = db->aDb[iDb].pSchema;
114901
+ for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
114902
+ pTab = (Table*)sqliteHashData(k);
114903
+
114904
+ /* If table pTab has not been used in a way that would benefit from
114905
+ ** having analysis statistics during the current session, then skip it.
114906
+ ** This also has the effect of skipping virtual tables and views */
114907
+ if( (pTab->tabFlags & TF_StatsUsed)==0 ) continue;
114908
+
114909
+ /* Reanalyze if the table is 25 times larger than the last analysis */
114910
+ szThreshold = pTab->nRowLogEst + 46; assert( sqlite3LogEst(25)==46 );
114911
+ for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
114912
+ if( !pIdx->hasStat1 ){
114913
+ szThreshold = 0; /* Always analyze if any index lacks statistics */
114914
+ break;
114915
+ }
114916
+ }
114917
+ if( szThreshold ){
114918
+ sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
114919
+ sqlite3VdbeAddOp3(v, OP_IfSmaller, iTabCur,
114920
+ sqlite3VdbeCurrentAddr(v)+2+(opMask&1), szThreshold);
114921
+ VdbeCoverage(v);
114922
+ }
114923
+ zSubSql = sqlite3MPrintf(db, "ANALYZE \"%w\".\"%w\"",
114924
+ db->aDb[iDb].zDbSName, pTab->zName);
114925
+ if( opMask & 0x01 ){
114926
+ int r1 = sqlite3GetTempReg(pParse);
114927
+ sqlite3VdbeAddOp4(v, OP_String8, 0, r1, 0, zSubSql, P4_DYNAMIC);
114928
+ sqlite3VdbeAddOp2(v, OP_ResultRow, r1, 1);
114929
+ }else{
114930
+ sqlite3VdbeAddOp4(v, OP_SqlExec, 0, 0, 0, zSubSql, P4_DYNAMIC);
114931
+ }
114932
+ }
114933
+ }
114934
+ sqlite3VdbeAddOp0(v, OP_Expire);
114935
+ break;
114936
+ }
114471114937
114472114938
/*
114473114939
** PRAGMA busy_timeout
114474114940
** PRAGMA busy_timeout = N
114475114941
**
@@ -119528,11 +119994,13 @@
119528119994
assert( pParent->pGroupBy==0 );
119529119995
pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
119530119996
}else{
119531119997
pParent->pWhere = sqlite3ExprAnd(db, pWhere, pParent->pWhere);
119532119998
}
119533
- substSelect(pParse, pParent, iParent, pSub->pEList, 0);
119999
+ if( db->mallocFailed==0 ){
120000
+ substSelect(pParse, pParent, iParent, pSub->pEList, 0);
120001
+ }
119534120002
119535120003
/* The flattened query is distinct if either the inner or the
119536120004
** outer query is distinct.
119537120005
*/
119538120006
pParent->selFlags |= pSub->selFlags & SF_Distinct;
@@ -123782,12 +124250,29 @@
123782124250
** transient would cause the database file to appear to be deleted
123783124251
** following reboot.
123784124252
*/
123785124253
SQLITE_PRIVATE void sqlite3Vacuum(Parse *pParse, Token *pNm){
123786124254
Vdbe *v = sqlite3GetVdbe(pParse);
123787
- int iDb = pNm ? sqlite3TwoPartName(pParse, pNm, pNm, &pNm) : 0;
123788
- if( v && (iDb>=2 || iDb==0) ){
124255
+ int iDb = 0;
124256
+ if( v==0 ) return;
124257
+ if( pNm ){
124258
+#ifndef SQLITE_BUG_COMPATIBLE_20160819
124259
+ /* Default behavior: Report an error if the argument to VACUUM is
124260
+ ** not recognized */
124261
+ iDb = sqlite3TwoPartName(pParse, pNm, pNm, &pNm);
124262
+ if( iDb<0 ) return;
124263
+#else
124264
+ /* When SQLITE_BUG_COMPATIBLE_20160819 is defined, unrecognized arguments
124265
+ ** to VACUUM are silently ignored. This is a back-out of a bug fix that
124266
+ ** occurred on 2016-08-19 (https://www.sqlite.org/src/info/083f9e6270).
124267
+ ** The buggy behavior is required for binary compatibility with some
124268
+ ** legacy applications. */
124269
+ iDb = sqlite3FindDb(pParse->db, pNm);
124270
+ if( iDb<0 ) iDb = 0;
124271
+#endif
124272
+ }
124273
+ if( iDb!=1 ){
123789124274
sqlite3VdbeAddOp1(v, OP_Vacuum, iDb);
123790124275
sqlite3VdbeUsesBtree(v, iDb);
123791124276
}
123792124277
return;
123793124278
}
@@ -124377,12 +124862,11 @@
124377124862
124378124863
db = pParse->db;
124379124864
iDb = sqlite3SchemaToIndex(db, pTable->pSchema);
124380124865
assert( iDb>=0 );
124381124866
124382
- pTable->tabFlags |= TF_Virtual;
124383
- pTable->nModuleArg = 0;
124867
+ assert( pTable->nModuleArg==0 );
124384124868
addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName));
124385124869
addModuleArgument(db, pTable, 0);
124386124870
addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName));
124387124871
assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0)
124388124872
|| (pParse->sNameToken.z==pName1->z && pName2->z==0)
@@ -124666,11 +125150,11 @@
124666125150
const char *zMod;
124667125151
Module *pMod;
124668125152
int rc;
124669125153
124670125154
assert( pTab );
124671
- if( (pTab->tabFlags & TF_Virtual)==0 || sqlite3GetVTable(db, pTab) ){
125155
+ if( !IsVirtual(pTab) || sqlite3GetVTable(db, pTab) ){
124672125156
return SQLITE_OK;
124673125157
}
124674125158
124675125159
/* Locate the required virtual table module */
124676125160
zMod = pTab->azModuleArg[0];
@@ -124736,11 +125220,11 @@
124736125220
Table *pTab;
124737125221
Module *pMod;
124738125222
const char *zMod;
124739125223
124740125224
pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
124741
- assert( pTab && (pTab->tabFlags & TF_Virtual)!=0 && !pTab->pVTable );
125225
+ assert( pTab && IsVirtual(pTab) && !pTab->pVTable );
124742125226
124743125227
/* Locate the required virtual table module */
124744125228
zMod = pTab->azModuleArg[0];
124745125229
pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
124746125230
@@ -124790,11 +125274,11 @@
124790125274
sqlite3Error(db, SQLITE_MISUSE);
124791125275
sqlite3_mutex_leave(db->mutex);
124792125276
return SQLITE_MISUSE_BKPT;
124793125277
}
124794125278
pTab = pCtx->pTab;
124795
- assert( (pTab->tabFlags & TF_Virtual)!=0 );
125279
+ assert( IsVirtual(pTab) );
124796125280
124797125281
pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
124798125282
if( pParse==0 ){
124799125283
rc = SQLITE_NOMEM_BKPT;
124800125284
}else{
@@ -124804,11 +125288,11 @@
124804125288
124805125289
if( SQLITE_OK==sqlite3RunParser(pParse, zCreateTable, &zErr)
124806125290
&& pParse->pNewTable
124807125291
&& !db->mallocFailed
124808125292
&& !pParse->pNewTable->pSelect
124809
- && (pParse->pNewTable->tabFlags & TF_Virtual)==0
125293
+ && !IsVirtual(pParse->pNewTable)
124810125294
){
124811125295
if( !pTab->aCol ){
124812125296
Table *pNew = pParse->pNewTable;
124813125297
Index *pIdx;
124814125298
pTab->aCol = pNew->aCol;
@@ -125093,11 +125577,11 @@
125093125577
/* Check to see the left operand is a column in a virtual table */
125094125578
if( NEVER(pExpr==0) ) return pDef;
125095125579
if( pExpr->op!=TK_COLUMN ) return pDef;
125096125580
pTab = pExpr->pTab;
125097125581
if( NEVER(pTab==0) ) return pDef;
125098
- if( (pTab->tabFlags & TF_Virtual)==0 ) return pDef;
125582
+ if( !IsVirtual(pTab) ) return pDef;
125099125583
pVtab = sqlite3GetVTable(db, pTab)->pVtab;
125100125584
assert( pVtab!=0 );
125101125585
assert( pVtab->pModule!=0 );
125102125586
pMod = (sqlite3_module *)pVtab->pModule;
125103125587
if( pMod->xFindFunction==0 ) return pDef;
@@ -125188,12 +125672,11 @@
125188125672
return 0;
125189125673
}
125190125674
pMod->pEpoTab = pTab;
125191125675
pTab->nTabRef = 1;
125192125676
pTab->pSchema = db->aDb[0].pSchema;
125193
- pTab->tabFlags |= TF_Virtual;
125194
- pTab->nModuleArg = 0;
125677
+ assert( pTab->nModuleArg==0 );
125195125678
pTab->iPKey = -1;
125196125679
addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
125197125680
addModuleArgument(db, pTab, 0);
125198125681
addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
125199125682
rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
@@ -125260,11 +125743,11 @@
125260125743
case SQLITE_VTAB_CONSTRAINT_SUPPORT: {
125261125744
VtabCtx *p = db->pVtabCtx;
125262125745
if( !p ){
125263125746
rc = SQLITE_MISUSE_BKPT;
125264125747
}else{
125265
- assert( p->pTab==0 || (p->pTab->tabFlags & TF_Virtual)!=0 );
125748
+ assert( p->pTab==0 || IsVirtual(p->pTab) );
125266125749
p->pVTable->bConstraint = (u8)va_arg(ap, int);
125267125750
}
125268125751
break;
125269125752
}
125270125753
default:
@@ -125699,12 +126182,17 @@
125699126182
WhereOrSet *pOrSet; /* Record best loops here, if not NULL */
125700126183
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
125701126184
UnpackedRecord *pRec; /* Probe for stat4 (if required) */
125702126185
int nRecValid; /* Number of valid fields currently in pRec */
125703126186
#endif
126187
+ unsigned int bldFlags; /* SQLITE_BLDF_* flags */
125704126188
};
125705126189
126190
+/* Allowed values for WhereLoopBuider.bldFlags */
126191
+#define SQLITE_BLDF_INDEXED 0x0001 /* An index is used */
126192
+#define SQLITE_BLDF_UNIQUE 0x0002 /* All keys of a UNIQUE index used */
126193
+
125706126194
/*
125707126195
** The WHERE clause processing routine has two halves. The
125708126196
** first part does the start of the WHERE loop and the second
125709126197
** half does the tail of the WHERE loop. An instance of
125710126198
** this structure is returned by the first half and passed
@@ -125715,11 +126203,11 @@
125715126203
*/
125716126204
struct WhereInfo {
125717126205
Parse *pParse; /* Parsing and code generating context */
125718126206
SrcList *pTabList; /* List of tables in the join */
125719126207
ExprList *pOrderBy; /* The ORDER BY clause or NULL */
125720
- ExprList *pDistinctSet; /* DISTINCT over all these values */
126208
+ ExprList *pResultSet; /* Result set of the query */
125721126209
LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
125722126210
int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */
125723126211
int iContinue; /* Jump here to continue with next record */
125724126212
int iBreak; /* Jump here to break out of the loop */
125725126213
int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
@@ -126899,10 +127387,11 @@
126899127387
Parse *pParse; /* Parsing context */
126900127388
sqlite3 *db; /* Database connection */
126901127389
Vdbe *v; /* The prepared stmt under constructions */
126902127390
struct SrcList_item *pTabItem; /* FROM clause term being coded */
126903127391
int addrBrk; /* Jump here to break out of the loop */
127392
+ int addrHalt; /* addrBrk for the outermost loop */
126904127393
int addrCont; /* Jump here to continue with next cycle */
126905127394
int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
126906127395
int iReleaseReg = 0; /* Temp register to free before returning */
126907127396
126908127397
pParse = pWInfo->pParse;
@@ -126939,10 +127428,15 @@
126939127428
if( pLevel->iFrom>0 && (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){
126940127429
pLevel->iLeftJoin = ++pParse->nMem;
126941127430
sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
126942127431
VdbeComment((v, "init LEFT JOIN no-match flag"));
126943127432
}
127433
+
127434
+ /* Compute a safe address to jump to if we discover that the table for
127435
+ ** this loop is empty and can never contribute content. */
127436
+ for(j=iLevel; j>0 && pWInfo->a[j].iLeftJoin==0; j--){}
127437
+ addrHalt = pWInfo->a[j].addrBrk;
126944127438
126945127439
/* Special case of a FROM clause subquery implemented as a co-routine */
126946127440
if( pTabItem->fg.viaCoroutine ){
126947127441
int regYield = pTabItem->regReturn;
126948127442
sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
@@ -127124,11 +127618,11 @@
127124127618
VdbeCoverageIf(v, pX->op==TK_LT);
127125127619
VdbeCoverageIf(v, pX->op==TK_GE);
127126127620
sqlite3ExprCacheAffinityChange(pParse, r1, 1);
127127127621
sqlite3ReleaseTempReg(pParse, rTemp);
127128127622
}else{
127129
- sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrBrk);
127623
+ sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrHalt);
127130127624
VdbeCoverageIf(v, bRev==0);
127131127625
VdbeCoverageIf(v, bRev!=0);
127132127626
}
127133127627
if( pEnd ){
127134127628
Expr *pX;
@@ -127770,11 +128264,11 @@
127770128264
pLevel->op = OP_Noop;
127771128265
}else{
127772128266
codeCursorHint(pTabItem, pWInfo, pLevel, 0);
127773128267
pLevel->op = aStep[bRev];
127774128268
pLevel->p1 = iCur;
127775
- pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
128269
+ pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrHalt);
127776128270
VdbeCoverageIf(v, bRev==0);
127777128271
VdbeCoverageIf(v, bRev!=0);
127778128272
pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
127779128273
}
127780128274
}
@@ -128095,19 +128589,10 @@
128095128589
#ifdef SQLITE_EBCDIC
128096128590
if( *pnoCase ) return 0;
128097128591
#endif
128098128592
pList = pExpr->x.pList;
128099128593
pLeft = pList->a[1].pExpr;
128100
- if( pLeft->op!=TK_COLUMN
128101
- || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT
128102
- || IsVirtual(pLeft->pTab) /* Value might be numeric */
128103
- ){
128104
- /* IMP: R-02065-49465 The left-hand side of the LIKE or GLOB operator must
128105
- ** be the name of an indexed column with TEXT affinity. */
128106
- return 0;
128107
- }
128108
- assert( pLeft->iColumn!=(-1) ); /* Because IPK never has AFF_TEXT */
128109128594
128110128595
pRight = sqlite3ExprSkipCollate(pList->a[0].pExpr);
128111128596
op = pRight->op;
128112128597
if( op==TK_VARIABLE ){
128113128598
Vdbe *pReprepare = pParse->pReprepare;
@@ -128120,10 +128605,27 @@
128120128605
assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER );
128121128606
}else if( op==TK_STRING ){
128122128607
z = pRight->u.zToken;
128123128608
}
128124128609
if( z ){
128610
+
128611
+ /* If the RHS begins with a digit or a minus sign, then the LHS must
128612
+ ** be an ordinary column (not a virtual table column) with TEXT affinity.
128613
+ ** Otherwise the LHS might be numeric and "lhs >= rhs" would be false
128614
+ ** even though "lhs LIKE rhs" is true. But if the RHS does not start
128615
+ ** with a digit or '-', then "lhs LIKE rhs" will always be false if
128616
+ ** the LHS is numeric and so the optimization still works.
128617
+ */
128618
+ if( sqlite3Isdigit(z[0]) || z[0]=='-' ){
128619
+ if( pLeft->op!=TK_COLUMN
128620
+ || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT
128621
+ || IsVirtual(pLeft->pTab) /* Value might be numeric */
128622
+ ){
128623
+ sqlite3ValueFree(pVal);
128624
+ return 0;
128625
+ }
128626
+ }
128125128627
cnt = 0;
128126128628
while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){
128127128629
cnt++;
128128128630
}
128129128631
if( cnt!=0 && 255!=(u8)z[cnt-1] ){
@@ -128748,11 +129250,11 @@
128748129250
iCur = pFrom->a[i].iCursor;
128749129251
for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){
128750129252
if( pIdx->aColExpr==0 ) continue;
128751129253
for(i=0; i<pIdx->nKeyCol; i++){
128752129254
if( pIdx->aiColumn[i]!=XN_EXPR ) continue;
128753
- if( sqlite3ExprCompare(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
129255
+ if( sqlite3ExprCompareSkip(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
128754129256
*piCur = iCur;
128755129257
*piColumn = XN_EXPR;
128756129258
return 1;
128757129259
}
128758129260
}
@@ -129539,11 +130041,12 @@
129539130041
do{
129540130042
for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
129541130043
if( pTerm->leftCursor==iCur
129542130044
&& pTerm->u.leftColumn==iColumn
129543130045
&& (iColumn!=XN_EXPR
129544
- || sqlite3ExprCompare(pTerm->pExpr->pLeft,pScan->pIdxExpr,iCur)==0)
130046
+ || sqlite3ExprCompareSkip(pTerm->pExpr->pLeft,
130047
+ pScan->pIdxExpr,iCur)==0)
129545130048
&& (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
129546130049
){
129547130050
if( (pTerm->eOperator & WO_EQUIV)!=0
129548130051
&& pScan->nEquiv<ArraySize(pScan->aiCur)
129549130052
&& (pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight))->op==TK_COLUMN
@@ -129846,18 +130349,20 @@
129846130349
** cursor iTabCur are transformed into OP_Null. Or, if bIncrRowid is non-zero,
129847130350
** then each OP_Rowid is transformed into an instruction to increment the
129848130351
** value stored in its output register.
129849130352
*/
129850130353
static void translateColumnToCopy(
129851
- Vdbe *v, /* The VDBE containing code to translate */
130354
+ Parse *pParse, /* Parsing context */
129852130355
int iStart, /* Translate from this opcode to the end */
129853130356
int iTabCur, /* OP_Column/OP_Rowid references to this table */
129854130357
int iRegister, /* The first column is in this register */
129855130358
int bIncrRowid /* If non-zero, transform OP_rowid to OP_AddImm(1) */
129856130359
){
130360
+ Vdbe *v = pParse->pVdbe;
129857130361
VdbeOp *pOp = sqlite3VdbeGetOp(v, iStart);
129858130362
int iEnd = sqlite3VdbeCurrentAddr(v);
130363
+ if( pParse->db->mallocFailed ) return;
129859130364
for(; iStart<iEnd; iStart++, pOp++){
129860130365
if( pOp->p1!=iTabCur ) continue;
129861130366
if( pOp->opcode==OP_Column ){
129862130367
pOp->opcode = OP_Copy;
129863130368
pOp->p1 = pOp->p2 + iRegister;
@@ -130131,11 +130636,13 @@
130131130636
sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
130132130637
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
130133130638
if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
130134130639
if( pTabItem->fg.viaCoroutine ){
130135130640
sqlite3VdbeChangeP2(v, addrCounter, regBase+n);
130136
- translateColumnToCopy(v, addrTop, pLevel->iTabCur, pTabItem->regResult, 1);
130641
+ testcase( pParse->db->mallocFailed );
130642
+ translateColumnToCopy(pParse, addrTop, pLevel->iTabCur,
130643
+ pTabItem->regResult, 1);
130137130644
sqlite3VdbeGoto(v, addrTop);
130138130645
pTabItem->fg.viaCoroutine = 0;
130139130646
}else{
130140130647
sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
130141130648
}
@@ -131716,10 +132223,15 @@
131716132223
testcase( eOp & WO_IS );
131717132224
testcase( eOp & WO_ISNULL );
131718132225
continue;
131719132226
}
131720132227
132228
+ if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){
132229
+ pBuilder->bldFlags |= SQLITE_BLDF_UNIQUE;
132230
+ }else{
132231
+ pBuilder->bldFlags |= SQLITE_BLDF_INDEXED;
132232
+ }
131721132233
pNew->wsFlags = saved_wsFlags;
131722132234
pNew->u.btree.nEq = saved_nEq;
131723132235
pNew->u.btree.nBtm = saved_nBtm;
131724132236
pNew->u.btree.nTop = saved_nTop;
131725132237
pNew->nLTerm = saved_nLTerm;
@@ -132263,11 +132775,19 @@
132263132775
pNew->nOut = rSize;
132264132776
if( rc ) break;
132265132777
}
132266132778
}
132267132779
132780
+ pBuilder->bldFlags = 0;
132268132781
rc = whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, 0);
132782
+ if( pBuilder->bldFlags==SQLITE_BLDF_INDEXED ){
132783
+ /* If a non-unique index is used, or if a prefix of the key for
132784
+ ** unique index is used (making the index functionally non-unique)
132785
+ ** then the sqlite_stat1 data becomes important for scoring the
132786
+ ** plan */
132787
+ pTab->tabFlags |= TF_StatsUsed;
132788
+ }
132269132789
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
132270132790
sqlite3Stat4ProbeFree(pBuilder->pRec);
132271132791
pBuilder->nRecValid = 0;
132272132792
pBuilder->pRec = 0;
132273132793
#endif
@@ -133443,13 +133963,13 @@
133443133963
&& (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
133444133964
&& pWInfo->eDistinct==WHERE_DISTINCT_NOOP
133445133965
&& nRowEst
133446133966
){
133447133967
Bitmask notUsed;
133448
- int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pDistinctSet, pFrom,
133968
+ int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pResultSet, pFrom,
133449133969
WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed);
133450
- if( rc==pWInfo->pDistinctSet->nExpr ){
133970
+ if( rc==pWInfo->pResultSet->nExpr ){
133451133971
pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
133452133972
}
133453133973
}
133454133974
if( pWInfo->pOrderBy ){
133455133975
if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
@@ -133682,11 +134202,11 @@
133682134202
SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
133683134203
Parse *pParse, /* The parser context */
133684134204
SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
133685134205
Expr *pWhere, /* The WHERE clause */
133686134206
ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */
133687
- ExprList *pDistinctSet, /* Try not to output two rows that duplicate these */
134207
+ ExprList *pResultSet, /* Query result set. Req'd for DISTINCT */
133688134208
u16 wctrlFlags, /* The WHERE_* flags defined in sqliteInt.h */
133689134209
int iAuxArg /* If WHERE_OR_SUBCLAUSE is set, index cursor number
133690134210
** If WHERE_USE_LIMIT, then the limit amount */
133691134211
){
133692134212
int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
@@ -133758,11 +134278,11 @@
133758134278
goto whereBeginError;
133759134279
}
133760134280
pWInfo->pParse = pParse;
133761134281
pWInfo->pTabList = pTabList;
133762134282
pWInfo->pOrderBy = pOrderBy;
133763
- pWInfo->pDistinctSet = pDistinctSet;
134283
+ pWInfo->pResultSet = pResultSet;
133764134284
pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
133765134285
pWInfo->nLevel = nTabList;
133766134286
pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
133767134287
pWInfo->wctrlFlags = wctrlFlags;
133768134288
pWInfo->iLimit = iAuxArg;
@@ -133836,17 +134356,17 @@
133836134356
/* Analyze all of the subexpressions. */
133837134357
sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
133838134358
if( db->mallocFailed ) goto whereBeginError;
133839134359
133840134360
if( wctrlFlags & WHERE_WANT_DISTINCT ){
133841
- if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pDistinctSet) ){
134361
+ if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){
133842134362
/* The DISTINCT marking is pointless. Ignore it. */
133843134363
pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
133844134364
}else if( pOrderBy==0 ){
133845134365
/* Try to ORDER BY the result set to make distinct processing easier */
133846134366
pWInfo->wctrlFlags |= WHERE_DISTINCTBY;
133847
- pWInfo->pOrderBy = pDistinctSet;
134367
+ pWInfo->pOrderBy = pResultSet;
133848134368
}
133849134369
}
133850134370
133851134371
/* Construct the WhereLoop objects */
133852134372
#if defined(WHERETRACE_ENABLED)
@@ -133918,14 +134438,14 @@
133918134438
}
133919134439
}
133920134440
#endif
133921134441
/* Attempt to omit tables from the join that do not effect the result */
133922134442
if( pWInfo->nLevel>=2
133923
- && pDistinctSet!=0
134443
+ && pResultSet!=0
133924134444
&& OptimizationEnabled(db, SQLITE_OmitNoopJoin)
133925134445
){
133926
- Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pDistinctSet);
134446
+ Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet);
133927134447
if( sWLB.pOrderBy ){
133928134448
tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy);
133929134449
}
133930134450
while( pWInfo->nLevel>=2 ){
133931134451
WhereTerm *pTerm, *pEnd;
@@ -134236,12 +134756,13 @@
134236134756
134237134757
/* For a co-routine, change all OP_Column references to the table of
134238134758
** the co-routine into OP_Copy of result contained in a register.
134239134759
** OP_Rowid becomes OP_Null.
134240134760
*/
134241
- if( pTabItem->fg.viaCoroutine && !db->mallocFailed ){
134242
- translateColumnToCopy(v, pLevel->addrBody, pLevel->iTabCur,
134761
+ if( pTabItem->fg.viaCoroutine ){
134762
+ testcase( pParse->db->mallocFailed );
134763
+ translateColumnToCopy(pParse, pLevel->addrBody, pLevel->iTabCur,
134243134764
pTabItem->regResult, 0);
134244134765
continue;
134245134766
}
134246134767
134247134768
/* If this scan uses an index, make VDBE code substitutions to read data
@@ -134704,166 +135225,166 @@
134704135225
**
134705135226
*********** Begin parsing tables **********************************************/
134706135227
#define YY_ACTTAB_COUNT (1567)
134707135228
static const YYACTIONTYPE yy_action[] = {
134708135229
/* 0 */ 325, 832, 351, 825, 5, 203, 203, 819, 99, 100,
134709
- /* 10 */ 90, 842, 842, 854, 857, 846, 846, 97, 97, 98,
135230
+ /* 10 */ 90, 978, 978, 853, 856, 845, 845, 97, 97, 98,
134710135231
/* 20 */ 98, 98, 98, 301, 96, 96, 96, 96, 95, 95,
134711
- /* 30 */ 94, 94, 94, 93, 351, 325, 977, 977, 824, 824,
134712
- /* 40 */ 826, 947, 354, 99, 100, 90, 842, 842, 854, 857,
134713
- /* 50 */ 846, 846, 97, 97, 98, 98, 98, 98, 338, 96,
135232
+ /* 30 */ 94, 94, 94, 93, 351, 325, 976, 976, 824, 824,
135233
+ /* 40 */ 826, 946, 354, 99, 100, 90, 978, 978, 853, 856,
135234
+ /* 50 */ 845, 845, 97, 97, 98, 98, 98, 98, 338, 96,
134714135235
/* 60 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351,
134715
- /* 70 */ 95, 95, 94, 94, 94, 93, 351, 791, 977, 977,
135236
+ /* 70 */ 95, 95, 94, 94, 94, 93, 351, 791, 976, 976,
134716135237
/* 80 */ 325, 94, 94, 94, 93, 351, 792, 75, 99, 100,
134717
- /* 90 */ 90, 842, 842, 854, 857, 846, 846, 97, 97, 98,
135238
+ /* 90 */ 90, 978, 978, 853, 856, 845, 845, 97, 97, 98,
134718135239
/* 100 */ 98, 98, 98, 450, 96, 96, 96, 96, 95, 95,
134719135240
/* 110 */ 94, 94, 94, 93, 351, 1333, 155, 155, 2, 325,
134720135241
/* 120 */ 275, 146, 132, 52, 52, 93, 351, 99, 100, 90,
134721
- /* 130 */ 842, 842, 854, 857, 846, 846, 97, 97, 98, 98,
135242
+ /* 130 */ 978, 978, 853, 856, 845, 845, 97, 97, 98, 98,
134722135243
/* 140 */ 98, 98, 101, 96, 96, 96, 96, 95, 95, 94,
134723
- /* 150 */ 94, 94, 93, 351, 958, 958, 325, 268, 428, 413,
134724
- /* 160 */ 411, 61, 752, 752, 99, 100, 90, 842, 842, 854,
134725
- /* 170 */ 857, 846, 846, 97, 97, 98, 98, 98, 98, 60,
135244
+ /* 150 */ 94, 94, 93, 351, 957, 957, 325, 268, 428, 413,
135245
+ /* 160 */ 411, 61, 752, 752, 99, 100, 90, 978, 978, 853,
135246
+ /* 170 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 60,
134726135247
/* 180 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
134727
- /* 190 */ 351, 325, 270, 329, 273, 277, 959, 960, 250, 99,
134728
- /* 200 */ 100, 90, 842, 842, 854, 857, 846, 846, 97, 97,
135248
+ /* 190 */ 351, 325, 270, 329, 273, 277, 958, 959, 250, 99,
135249
+ /* 200 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97,
134729135250
/* 210 */ 98, 98, 98, 98, 301, 96, 96, 96, 96, 95,
134730
- /* 220 */ 95, 94, 94, 94, 93, 351, 325, 938, 1326, 698,
134731
- /* 230 */ 706, 1326, 242, 412, 99, 100, 90, 842, 842, 854,
134732
- /* 240 */ 857, 846, 846, 97, 97, 98, 98, 98, 98, 347,
135251
+ /* 220 */ 95, 94, 94, 94, 93, 351, 325, 937, 1326, 698,
135252
+ /* 230 */ 706, 1326, 242, 412, 99, 100, 90, 978, 978, 853,
135253
+ /* 240 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 347,
134733135254
/* 250 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
134734
- /* 260 */ 351, 325, 938, 1327, 384, 699, 1327, 381, 379, 99,
134735
- /* 270 */ 100, 90, 842, 842, 854, 857, 846, 846, 97, 97,
135255
+ /* 260 */ 351, 325, 937, 1327, 384, 699, 1327, 381, 379, 99,
135256
+ /* 270 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97,
134736135257
/* 280 */ 98, 98, 98, 98, 701, 96, 96, 96, 96, 95,
134737135258
/* 290 */ 95, 94, 94, 94, 93, 351, 325, 92, 89, 178,
134738
- /* 300 */ 833, 936, 373, 700, 99, 100, 90, 842, 842, 854,
134739
- /* 310 */ 857, 846, 846, 97, 97, 98, 98, 98, 98, 375,
135259
+ /* 300 */ 833, 935, 373, 700, 99, 100, 90, 978, 978, 853,
135260
+ /* 310 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 375,
134740135261
/* 320 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
134741
- /* 330 */ 351, 325, 1276, 947, 354, 818, 936, 739, 739, 99,
134742
- /* 340 */ 100, 90, 842, 842, 854, 857, 846, 846, 97, 97,
135262
+ /* 330 */ 351, 325, 1275, 946, 354, 818, 935, 739, 739, 99,
135263
+ /* 340 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97,
134743135264
/* 350 */ 98, 98, 98, 98, 230, 96, 96, 96, 96, 95,
134744
- /* 360 */ 95, 94, 94, 94, 93, 351, 325, 969, 227, 92,
134745
- /* 370 */ 89, 178, 373, 300, 99, 100, 90, 842, 842, 854,
134746
- /* 380 */ 857, 846, 846, 97, 97, 98, 98, 98, 98, 921,
135265
+ /* 360 */ 95, 94, 94, 94, 93, 351, 325, 968, 227, 92,
135266
+ /* 370 */ 89, 178, 373, 300, 99, 100, 90, 978, 978, 853,
135267
+ /* 380 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 920,
134747135268
/* 390 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
134748135269
/* 400 */ 351, 325, 449, 447, 447, 447, 147, 737, 737, 99,
134749
- /* 410 */ 100, 90, 842, 842, 854, 857, 846, 846, 97, 97,
135270
+ /* 410 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97,
134750135271
/* 420 */ 98, 98, 98, 98, 296, 96, 96, 96, 96, 95,
134751
- /* 430 */ 95, 94, 94, 94, 93, 351, 325, 419, 231, 958,
134752
- /* 440 */ 958, 158, 25, 422, 99, 100, 90, 842, 842, 854,
134753
- /* 450 */ 857, 846, 846, 97, 97, 98, 98, 98, 98, 450,
135272
+ /* 430 */ 95, 94, 94, 94, 93, 351, 325, 419, 231, 957,
135273
+ /* 440 */ 957, 158, 25, 422, 99, 100, 90, 978, 978, 853,
135274
+ /* 450 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 450,
134754135275
/* 460 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
134755
- /* 470 */ 351, 443, 224, 224, 420, 958, 958, 962, 325, 52,
134756
- /* 480 */ 52, 959, 960, 176, 415, 78, 99, 100, 90, 842,
134757
- /* 490 */ 842, 854, 857, 846, 846, 97, 97, 98, 98, 98,
135276
+ /* 470 */ 351, 443, 224, 224, 420, 957, 957, 961, 325, 52,
135277
+ /* 480 */ 52, 958, 959, 176, 415, 78, 99, 100, 90, 978,
135278
+ /* 490 */ 978, 853, 856, 845, 845, 97, 97, 98, 98, 98,
134758135279
/* 500 */ 98, 379, 96, 96, 96, 96, 95, 95, 94, 94,
134759
- /* 510 */ 94, 93, 351, 325, 428, 418, 298, 959, 960, 962,
134760
- /* 520 */ 81, 99, 88, 90, 842, 842, 854, 857, 846, 846,
135280
+ /* 510 */ 94, 93, 351, 325, 428, 418, 298, 958, 959, 961,
135281
+ /* 520 */ 81, 99, 88, 90, 978, 978, 853, 856, 845, 845,
134761135282
/* 530 */ 97, 97, 98, 98, 98, 98, 717, 96, 96, 96,
134762
- /* 540 */ 96, 95, 95, 94, 94, 94, 93, 351, 325, 843,
134763
- /* 550 */ 843, 855, 858, 996, 318, 343, 379, 100, 90, 842,
134764
- /* 560 */ 842, 854, 857, 846, 846, 97, 97, 98, 98, 98,
135283
+ /* 540 */ 96, 95, 95, 94, 94, 94, 93, 351, 325, 842,
135284
+ /* 550 */ 842, 854, 857, 996, 318, 343, 379, 100, 90, 978,
135285
+ /* 560 */ 978, 853, 856, 845, 845, 97, 97, 98, 98, 98,
134765135286
/* 570 */ 98, 450, 96, 96, 96, 96, 95, 95, 94, 94,
134766135287
/* 580 */ 94, 93, 351, 325, 350, 350, 350, 260, 377, 340,
134767
- /* 590 */ 929, 52, 52, 90, 842, 842, 854, 857, 846, 846,
135288
+ /* 590 */ 928, 52, 52, 90, 978, 978, 853, 856, 845, 845,
134768135289
/* 600 */ 97, 97, 98, 98, 98, 98, 361, 96, 96, 96,
134769135290
/* 610 */ 96, 95, 95, 94, 94, 94, 93, 351, 86, 445,
134770
- /* 620 */ 847, 3, 1203, 361, 360, 378, 344, 813, 958, 958,
134771
- /* 630 */ 1300, 86, 445, 729, 3, 212, 169, 287, 405, 282,
135291
+ /* 620 */ 846, 3, 1202, 361, 360, 378, 344, 813, 957, 957,
135292
+ /* 630 */ 1299, 86, 445, 729, 3, 212, 169, 287, 405, 282,
134772135293
/* 640 */ 404, 199, 232, 450, 300, 760, 83, 84, 280, 245,
134773135294
/* 650 */ 262, 365, 251, 85, 352, 352, 92, 89, 178, 83,
134774135295
/* 660 */ 84, 242, 412, 52, 52, 448, 85, 352, 352, 246,
134775
- /* 670 */ 959, 960, 194, 455, 670, 402, 399, 398, 448, 243,
135296
+ /* 670 */ 958, 959, 194, 455, 670, 402, 399, 398, 448, 243,
134776135297
/* 680 */ 221, 114, 434, 776, 361, 450, 397, 268, 747, 224,
134777135298
/* 690 */ 224, 132, 132, 198, 832, 434, 452, 451, 428, 427,
134778135299
/* 700 */ 819, 415, 734, 713, 132, 52, 52, 832, 268, 452,
134779
- /* 710 */ 451, 734, 194, 819, 363, 402, 399, 398, 450, 1271,
134780
- /* 720 */ 1271, 23, 958, 958, 86, 445, 397, 3, 228, 429,
134781
- /* 730 */ 895, 824, 824, 826, 827, 19, 203, 720, 52, 52,
135300
+ /* 710 */ 451, 734, 194, 819, 363, 402, 399, 398, 450, 1270,
135301
+ /* 720 */ 1270, 23, 957, 957, 86, 445, 397, 3, 228, 429,
135302
+ /* 730 */ 894, 824, 824, 826, 827, 19, 203, 720, 52, 52,
134782135303
/* 740 */ 428, 408, 439, 249, 824, 824, 826, 827, 19, 229,
134783135304
/* 750 */ 403, 153, 83, 84, 761, 177, 241, 450, 721, 85,
134784
- /* 760 */ 352, 352, 120, 157, 959, 960, 58, 977, 409, 355,
135305
+ /* 760 */ 352, 352, 120, 157, 958, 959, 58, 976, 409, 355,
134785135306
/* 770 */ 330, 448, 268, 428, 430, 320, 790, 32, 32, 86,
134786135307
/* 780 */ 445, 776, 3, 341, 98, 98, 98, 98, 434, 96,
134787135308
/* 790 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351,
134788
- /* 800 */ 832, 120, 452, 451, 813, 887, 819, 83, 84, 977,
134789
- /* 810 */ 813, 132, 410, 920, 85, 352, 352, 132, 407, 789,
134790
- /* 820 */ 958, 958, 92, 89, 178, 917, 448, 262, 370, 261,
134791
- /* 830 */ 82, 914, 80, 262, 370, 261, 776, 824, 824, 826,
134792
- /* 840 */ 827, 19, 934, 434, 96, 96, 96, 96, 95, 95,
134793
- /* 850 */ 94, 94, 94, 93, 351, 832, 74, 452, 451, 958,
134794
- /* 860 */ 958, 819, 959, 960, 120, 92, 89, 178, 945, 2,
134795
- /* 870 */ 918, 965, 268, 1, 976, 76, 445, 762, 3, 708,
134796
- /* 880 */ 901, 901, 387, 958, 958, 757, 919, 371, 740, 778,
135309
+ /* 800 */ 832, 120, 452, 451, 813, 886, 819, 83, 84, 976,
135310
+ /* 810 */ 813, 132, 410, 919, 85, 352, 352, 132, 407, 789,
135311
+ /* 820 */ 957, 957, 92, 89, 178, 916, 448, 262, 370, 261,
135312
+ /* 830 */ 82, 913, 80, 262, 370, 261, 776, 824, 824, 826,
135313
+ /* 840 */ 827, 19, 933, 434, 96, 96, 96, 96, 95, 95,
135314
+ /* 850 */ 94, 94, 94, 93, 351, 832, 74, 452, 451, 957,
135315
+ /* 860 */ 957, 819, 958, 959, 120, 92, 89, 178, 944, 2,
135316
+ /* 870 */ 917, 964, 268, 1, 975, 76, 445, 762, 3, 708,
135317
+ /* 880 */ 900, 900, 387, 957, 957, 757, 918, 371, 740, 778,
134797135318
/* 890 */ 756, 257, 824, 824, 826, 827, 19, 417, 741, 450,
134798
- /* 900 */ 24, 959, 960, 83, 84, 369, 958, 958, 177, 226,
134799
- /* 910 */ 85, 352, 352, 885, 315, 314, 313, 215, 311, 10,
134800
- /* 920 */ 10, 683, 448, 349, 348, 959, 960, 909, 777, 157,
134801
- /* 930 */ 120, 958, 958, 337, 776, 416, 711, 310, 450, 434,
134802
- /* 940 */ 450, 321, 450, 791, 103, 200, 175, 450, 959, 960,
134803
- /* 950 */ 908, 832, 792, 452, 451, 9, 9, 819, 10, 10,
135319
+ /* 900 */ 24, 958, 959, 83, 84, 369, 957, 957, 177, 226,
135320
+ /* 910 */ 85, 352, 352, 884, 315, 314, 313, 215, 311, 10,
135321
+ /* 920 */ 10, 683, 448, 349, 348, 958, 959, 908, 777, 157,
135322
+ /* 930 */ 120, 957, 957, 337, 776, 416, 711, 310, 450, 434,
135323
+ /* 940 */ 450, 321, 450, 791, 103, 200, 175, 450, 958, 959,
135324
+ /* 950 */ 907, 832, 792, 452, 451, 9, 9, 819, 10, 10,
134804135325
/* 960 */ 52, 52, 51, 51, 180, 716, 248, 10, 10, 171,
134805
- /* 970 */ 170, 167, 339, 959, 960, 247, 984, 702, 702, 450,
134806
- /* 980 */ 715, 233, 686, 982, 889, 983, 182, 914, 824, 824,
135326
+ /* 970 */ 170, 167, 339, 958, 959, 247, 984, 702, 702, 450,
135327
+ /* 980 */ 715, 233, 686, 982, 888, 983, 182, 913, 824, 824,
134807135328
/* 990 */ 826, 827, 19, 183, 256, 423, 132, 181, 394, 10,
134808
- /* 1000 */ 10, 889, 891, 749, 958, 958, 917, 268, 985, 198,
135329
+ /* 1000 */ 10, 888, 890, 749, 957, 957, 916, 268, 985, 198,
134809135330
/* 1010 */ 985, 349, 348, 425, 415, 299, 817, 832, 326, 825,
134810135331
/* 1020 */ 120, 332, 133, 819, 268, 98, 98, 98, 98, 91,
134811135332
/* 1030 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
134812
- /* 1040 */ 351, 157, 810, 371, 382, 359, 959, 960, 358, 268,
134813
- /* 1050 */ 450, 918, 368, 324, 824, 824, 826, 450, 709, 450,
134814
- /* 1060 */ 264, 380, 889, 450, 877, 746, 253, 919, 255, 433,
135333
+ /* 1040 */ 351, 157, 810, 371, 382, 359, 958, 959, 358, 268,
135334
+ /* 1050 */ 450, 917, 368, 324, 824, 824, 826, 450, 709, 450,
135335
+ /* 1060 */ 264, 380, 888, 450, 876, 746, 253, 918, 255, 433,
134815135336
/* 1070 */ 36, 36, 234, 450, 234, 120, 269, 37, 37, 12,
134816135337
/* 1080 */ 12, 334, 272, 27, 27, 450, 330, 118, 450, 162,
134817135338
/* 1090 */ 742, 280, 450, 38, 38, 450, 985, 356, 985, 450,
134818
- /* 1100 */ 709, 1210, 450, 132, 450, 39, 39, 450, 40, 40,
135339
+ /* 1100 */ 709, 1209, 450, 132, 450, 39, 39, 450, 40, 40,
134819135340
/* 1110 */ 450, 362, 41, 41, 450, 42, 42, 450, 254, 28,
134820135341
/* 1120 */ 28, 450, 29, 29, 31, 31, 450, 43, 43, 450,
134821135342
/* 1130 */ 44, 44, 450, 714, 45, 45, 450, 11, 11, 767,
134822135343
/* 1140 */ 450, 46, 46, 450, 268, 450, 105, 105, 450, 47,
134823135344
/* 1150 */ 47, 450, 48, 48, 450, 237, 33, 33, 450, 172,
134824135345
/* 1160 */ 49, 49, 450, 50, 50, 34, 34, 274, 122, 122,
134825
- /* 1170 */ 450, 123, 123, 450, 124, 124, 450, 898, 56, 56,
134826
- /* 1180 */ 450, 897, 35, 35, 450, 267, 450, 817, 450, 817,
135346
+ /* 1170 */ 450, 123, 123, 450, 124, 124, 450, 897, 56, 56,
135347
+ /* 1180 */ 450, 896, 35, 35, 450, 267, 450, 817, 450, 817,
134827135348
/* 1190 */ 106, 106, 450, 53, 53, 385, 107, 107, 450, 817,
134828135349
/* 1200 */ 108, 108, 817, 450, 104, 104, 121, 121, 119, 119,
134829135350
/* 1210 */ 450, 117, 112, 112, 450, 276, 450, 225, 111, 111,
134830
- /* 1220 */ 450, 730, 450, 109, 109, 450, 673, 674, 675, 912,
135351
+ /* 1220 */ 450, 730, 450, 109, 109, 450, 673, 674, 675, 911,
134831135352
/* 1230 */ 110, 110, 317, 998, 55, 55, 57, 57, 692, 331,
134832
- /* 1240 */ 54, 54, 26, 26, 696, 30, 30, 317, 937, 197,
135353
+ /* 1240 */ 54, 54, 26, 26, 696, 30, 30, 317, 936, 197,
134833135354
/* 1250 */ 196, 195, 335, 281, 336, 446, 331, 745, 689, 436,
134834
- /* 1260 */ 440, 444, 120, 72, 386, 223, 175, 345, 757, 933,
135355
+ /* 1260 */ 440, 444, 120, 72, 386, 223, 175, 345, 757, 932,
134835135356
/* 1270 */ 20, 286, 319, 756, 815, 372, 374, 202, 202, 202,
134836
- /* 1280 */ 263, 395, 285, 74, 208, 21, 696, 719, 718, 884,
135357
+ /* 1280 */ 263, 395, 285, 74, 208, 21, 696, 719, 718, 883,
134837135358
/* 1290 */ 120, 120, 120, 120, 120, 754, 278, 828, 77, 74,
134838
- /* 1300 */ 726, 727, 785, 783, 880, 202, 999, 208, 894, 893,
134839
- /* 1310 */ 894, 893, 694, 816, 763, 116, 774, 1290, 431, 432,
135359
+ /* 1300 */ 726, 727, 785, 783, 879, 202, 999, 208, 893, 892,
135360
+ /* 1310 */ 893, 892, 694, 816, 763, 116, 774, 1289, 431, 432,
134840135361
/* 1320 */ 302, 999, 390, 303, 823, 697, 691, 680, 159, 289,
134841
- /* 1330 */ 679, 884, 681, 952, 291, 218, 293, 7, 316, 828,
134842
- /* 1340 */ 173, 805, 259, 364, 252, 911, 376, 713, 295, 435,
134843
- /* 1350 */ 308, 168, 955, 993, 135, 400, 990, 284, 882, 881,
134844
- /* 1360 */ 205, 928, 926, 59, 333, 62, 144, 156, 130, 72,
135362
+ /* 1330 */ 679, 883, 681, 951, 291, 218, 293, 7, 316, 828,
135363
+ /* 1340 */ 173, 805, 259, 364, 252, 910, 376, 713, 295, 435,
135364
+ /* 1350 */ 308, 168, 954, 993, 135, 400, 990, 284, 881, 880,
135365
+ /* 1360 */ 205, 927, 925, 59, 333, 62, 144, 156, 130, 72,
134845135366
/* 1370 */ 802, 366, 367, 393, 137, 185, 189, 160, 139, 383,
134846
- /* 1380 */ 67, 896, 140, 141, 142, 148, 389, 812, 775, 266,
134847
- /* 1390 */ 219, 190, 154, 391, 913, 876, 271, 406, 191, 322,
135367
+ /* 1380 */ 67, 895, 140, 141, 142, 148, 389, 812, 775, 266,
135368
+ /* 1390 */ 219, 190, 154, 391, 912, 875, 271, 406, 191, 322,
134848135369
/* 1400 */ 682, 733, 192, 342, 732, 724, 731, 711, 723, 421,
134849135370
/* 1410 */ 705, 71, 323, 6, 204, 771, 288, 79, 297, 346,
134850
- /* 1420 */ 772, 704, 290, 283, 703, 770, 292, 294, 967, 239,
134851
- /* 1430 */ 769, 102, 862, 438, 426, 240, 424, 442, 73, 213,
134852
- /* 1440 */ 688, 238, 22, 453, 953, 214, 217, 216, 454, 677,
135371
+ /* 1420 */ 772, 704, 290, 283, 703, 770, 292, 294, 966, 239,
135372
+ /* 1430 */ 769, 102, 861, 438, 426, 240, 424, 442, 73, 213,
135373
+ /* 1440 */ 688, 238, 22, 453, 952, 214, 217, 216, 454, 677,
134853135374
/* 1450 */ 676, 671, 753, 125, 115, 235, 126, 669, 353, 166,
134854
- /* 1460 */ 127, 244, 179, 357, 306, 304, 305, 307, 113, 892,
134855
- /* 1470 */ 327, 890, 811, 328, 134, 128, 136, 138, 743, 258,
134856
- /* 1480 */ 907, 184, 143, 129, 910, 186, 63, 64, 145, 187,
134857
- /* 1490 */ 906, 65, 8, 66, 13, 188, 202, 899, 265, 149,
135375
+ /* 1460 */ 127, 244, 179, 357, 306, 304, 305, 307, 113, 891,
135376
+ /* 1470 */ 327, 889, 811, 328, 134, 128, 136, 138, 743, 258,
135377
+ /* 1480 */ 906, 184, 143, 129, 909, 186, 63, 64, 145, 187,
135378
+ /* 1490 */ 905, 65, 8, 66, 13, 188, 202, 898, 265, 149,
134858135379
/* 1500 */ 987, 388, 150, 685, 161, 392, 285, 193, 279, 396,
134859135380
/* 1510 */ 151, 401, 68, 14, 15, 722, 69, 236, 831, 131,
134860
- /* 1520 */ 830, 860, 70, 751, 16, 414, 755, 4, 174, 220,
134861
- /* 1530 */ 222, 784, 201, 152, 779, 77, 74, 17, 18, 875,
134862
- /* 1540 */ 861, 859, 916, 864, 915, 207, 206, 942, 163, 437,
134863
- /* 1550 */ 948, 943, 164, 209, 1002, 441, 863, 165, 210, 829,
134864
- /* 1560 */ 695, 87, 312, 211, 1292, 1291, 309,
135381
+ /* 1520 */ 830, 859, 70, 751, 16, 414, 755, 4, 174, 220,
135382
+ /* 1530 */ 222, 784, 201, 152, 779, 77, 74, 17, 18, 874,
135383
+ /* 1540 */ 860, 858, 915, 863, 914, 207, 206, 941, 163, 437,
135384
+ /* 1550 */ 947, 942, 164, 209, 1002, 441, 862, 165, 210, 829,
135385
+ /* 1560 */ 695, 87, 312, 211, 1291, 1290, 309,
134865135386
};
134866135387
static const YYCODETYPE yy_lookahead[] = {
134867135388
/* 0 */ 19, 95, 53, 97, 22, 24, 24, 101, 27, 28,
134868135389
/* 10 */ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
134869135390
/* 20 */ 39, 40, 41, 152, 43, 44, 45, 46, 47, 48,
@@ -135112,55 +135633,55 @@
135112135633
/* 300 */ 1256, 1200, 1206, 1260, 1247, 1261, 1263, 1262, 1266, 1278,
135113135634
/* 310 */ 1282, 1292, 1294, 1297, 1298, 1299, 1300, 1221, 1224, 1228,
135114135635
/* 320 */ 1288, 1291, 1276, 1277, 1295,
135115135636
};
135116135637
static const YYACTIONTYPE yy_default[] = {
135117
- /* 0 */ 1281, 1271, 1271, 1271, 1203, 1203, 1203, 1203, 1271, 1096,
135118
- /* 10 */ 1125, 1125, 1255, 1332, 1332, 1332, 1332, 1332, 1332, 1202,
135119
- /* 20 */ 1332, 1332, 1332, 1332, 1271, 1100, 1131, 1332, 1332, 1332,
135120
- /* 30 */ 1332, 1204, 1205, 1332, 1332, 1332, 1254, 1256, 1141, 1140,
135121
- /* 40 */ 1139, 1138, 1237, 1112, 1136, 1129, 1133, 1204, 1198, 1199,
135122
- /* 50 */ 1197, 1201, 1205, 1332, 1132, 1167, 1182, 1166, 1332, 1332,
135638
+ /* 0 */ 1280, 1270, 1270, 1270, 1202, 1202, 1202, 1202, 1270, 1096,
135639
+ /* 10 */ 1125, 1125, 1254, 1332, 1332, 1332, 1332, 1332, 1332, 1201,
135640
+ /* 20 */ 1332, 1332, 1332, 1332, 1270, 1100, 1131, 1332, 1332, 1332,
135641
+ /* 30 */ 1332, 1203, 1204, 1332, 1332, 1332, 1253, 1255, 1141, 1140,
135642
+ /* 40 */ 1139, 1138, 1236, 1112, 1136, 1129, 1133, 1203, 1197, 1198,
135643
+ /* 50 */ 1196, 1200, 1204, 1332, 1132, 1167, 1181, 1166, 1332, 1332,
135123135644
/* 60 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135124135645
/* 70 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135125135646
/* 80 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135126135647
/* 90 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135127
- /* 100 */ 1332, 1332, 1332, 1332, 1176, 1181, 1188, 1180, 1177, 1169,
135648
+ /* 100 */ 1332, 1332, 1332, 1332, 1175, 1180, 1187, 1179, 1176, 1169,
135128135649
/* 110 */ 1168, 1170, 1171, 1332, 1019, 1067, 1332, 1332, 1332, 1172,
135129
- /* 120 */ 1332, 1173, 1185, 1184, 1183, 1262, 1289, 1288, 1332, 1332,
135650
+ /* 120 */ 1332, 1173, 1184, 1183, 1182, 1261, 1288, 1287, 1332, 1332,
135130135651
/* 130 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135131135652
/* 140 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135132
- /* 150 */ 1332, 1332, 1332, 1332, 1332, 1281, 1271, 1025, 1025, 1332,
135133
- /* 160 */ 1271, 1271, 1271, 1271, 1271, 1271, 1267, 1100, 1091, 1332,
135653
+ /* 150 */ 1332, 1332, 1332, 1332, 1332, 1280, 1270, 1025, 1025, 1332,
135654
+ /* 160 */ 1270, 1270, 1270, 1270, 1270, 1270, 1266, 1100, 1091, 1332,
135134135655
/* 170 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135135
- /* 180 */ 1259, 1257, 1332, 1218, 1332, 1332, 1332, 1332, 1332, 1332,
135656
+ /* 180 */ 1258, 1256, 1332, 1217, 1332, 1332, 1332, 1332, 1332, 1332,
135136135657
/* 190 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135137135658
/* 200 */ 1332, 1332, 1332, 1332, 1096, 1332, 1332, 1332, 1332, 1332,
135138
- /* 210 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1283, 1332, 1232,
135659
+ /* 210 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1282, 1332, 1231,
135139135660
/* 220 */ 1096, 1096, 1096, 1098, 1080, 1090, 1004, 1135, 1114, 1114,
135140
- /* 230 */ 1321, 1135, 1321, 1042, 1303, 1039, 1125, 1114, 1200, 1125,
135661
+ /* 230 */ 1321, 1135, 1321, 1042, 1302, 1039, 1125, 1114, 1199, 1125,
135141135662
/* 240 */ 1125, 1097, 1090, 1332, 1324, 1105, 1105, 1323, 1323, 1105,
135142135663
/* 250 */ 1146, 1070, 1135, 1076, 1076, 1076, 1076, 1105, 1016, 1135,
135143
- /* 260 */ 1146, 1070, 1070, 1135, 1105, 1016, 1236, 1318, 1105, 1105,
135144
- /* 270 */ 1016, 1211, 1105, 1016, 1105, 1016, 1211, 1068, 1068, 1068,
135145
- /* 280 */ 1057, 1211, 1068, 1042, 1068, 1057, 1068, 1068, 1118, 1113,
135146
- /* 290 */ 1118, 1113, 1118, 1113, 1118, 1113, 1105, 1206, 1105, 1332,
135147
- /* 300 */ 1211, 1215, 1215, 1211, 1130, 1119, 1128, 1126, 1135, 1022,
135148
- /* 310 */ 1060, 1286, 1286, 1282, 1282, 1282, 1282, 1329, 1329, 1267,
135149
- /* 320 */ 1298, 1298, 1044, 1044, 1298, 1332, 1332, 1332, 1332, 1332,
135150
- /* 330 */ 1332, 1293, 1332, 1220, 1332, 1332, 1332, 1332, 1332, 1332,
135664
+ /* 260 */ 1146, 1070, 1070, 1135, 1105, 1016, 1235, 1318, 1105, 1105,
135665
+ /* 270 */ 1016, 1210, 1105, 1016, 1105, 1016, 1210, 1068, 1068, 1068,
135666
+ /* 280 */ 1057, 1210, 1068, 1042, 1068, 1057, 1068, 1068, 1118, 1113,
135667
+ /* 290 */ 1118, 1113, 1118, 1113, 1118, 1113, 1105, 1205, 1105, 1332,
135668
+ /* 300 */ 1210, 1214, 1214, 1210, 1130, 1119, 1128, 1126, 1135, 1022,
135669
+ /* 310 */ 1060, 1285, 1285, 1281, 1281, 1281, 1281, 1329, 1329, 1266,
135670
+ /* 320 */ 1297, 1297, 1044, 1044, 1297, 1332, 1332, 1332, 1332, 1332,
135671
+ /* 330 */ 1332, 1292, 1332, 1219, 1332, 1332, 1332, 1332, 1332, 1332,
135151135672
/* 340 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135152
- /* 350 */ 1332, 1332, 1152, 1332, 1000, 1264, 1332, 1332, 1263, 1332,
135673
+ /* 350 */ 1332, 1332, 1152, 1332, 1000, 1263, 1332, 1332, 1262, 1332,
135153135674
/* 360 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135154135675
/* 370 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1320,
135155
- /* 380 */ 1332, 1332, 1332, 1332, 1332, 1332, 1235, 1234, 1332, 1332,
135676
+ /* 380 */ 1332, 1332, 1332, 1332, 1332, 1332, 1234, 1233, 1332, 1332,
135156135677
/* 390 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135157135678
/* 400 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135158
- /* 410 */ 1332, 1082, 1332, 1332, 1332, 1307, 1332, 1332, 1332, 1332,
135679
+ /* 410 */ 1332, 1082, 1332, 1332, 1332, 1306, 1332, 1332, 1332, 1332,
135159135680
/* 420 */ 1332, 1332, 1332, 1127, 1332, 1120, 1332, 1332, 1311, 1332,
135160
- /* 430 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1273,
135161
- /* 440 */ 1332, 1332, 1332, 1272, 1332, 1332, 1332, 1332, 1332, 1154,
135681
+ /* 430 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1272,
135682
+ /* 440 */ 1332, 1332, 1332, 1271, 1332, 1332, 1332, 1332, 1332, 1154,
135162135683
/* 450 */ 1332, 1153, 1157, 1332, 1010, 1332,
135163135684
};
135164135685
/********** End of lemon-generated parsing tables *****************************/
135165135686
135166135687
/* The next table maps tokens (terminal symbols) into fallback tokens.
@@ -135602,147 +136123,147 @@
135602136123
/* 169 */ "expr ::= expr EQ|NE expr",
135603136124
/* 170 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
135604136125
/* 171 */ "expr ::= expr PLUS|MINUS expr",
135605136126
/* 172 */ "expr ::= expr STAR|SLASH|REM expr",
135606136127
/* 173 */ "expr ::= expr CONCAT expr",
135607
- /* 174 */ "likeop ::= LIKE_KW|MATCH",
135608
- /* 175 */ "likeop ::= NOT LIKE_KW|MATCH",
135609
- /* 176 */ "expr ::= expr likeop expr",
135610
- /* 177 */ "expr ::= expr likeop expr ESCAPE expr",
135611
- /* 178 */ "expr ::= expr ISNULL|NOTNULL",
135612
- /* 179 */ "expr ::= expr NOT NULL",
135613
- /* 180 */ "expr ::= expr IS expr",
135614
- /* 181 */ "expr ::= expr IS NOT expr",
135615
- /* 182 */ "expr ::= NOT expr",
135616
- /* 183 */ "expr ::= BITNOT expr",
135617
- /* 184 */ "expr ::= MINUS expr",
135618
- /* 185 */ "expr ::= PLUS expr",
135619
- /* 186 */ "between_op ::= BETWEEN",
135620
- /* 187 */ "between_op ::= NOT BETWEEN",
135621
- /* 188 */ "expr ::= expr between_op expr AND expr",
135622
- /* 189 */ "in_op ::= IN",
135623
- /* 190 */ "in_op ::= NOT IN",
135624
- /* 191 */ "expr ::= expr in_op LP exprlist RP",
135625
- /* 192 */ "expr ::= LP select RP",
135626
- /* 193 */ "expr ::= expr in_op LP select RP",
135627
- /* 194 */ "expr ::= expr in_op nm dbnm paren_exprlist",
135628
- /* 195 */ "expr ::= EXISTS LP select RP",
135629
- /* 196 */ "expr ::= CASE case_operand case_exprlist case_else END",
135630
- /* 197 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
135631
- /* 198 */ "case_exprlist ::= WHEN expr THEN expr",
135632
- /* 199 */ "case_else ::= ELSE expr",
135633
- /* 200 */ "case_else ::=",
135634
- /* 201 */ "case_operand ::= expr",
135635
- /* 202 */ "case_operand ::=",
135636
- /* 203 */ "exprlist ::=",
135637
- /* 204 */ "nexprlist ::= nexprlist COMMA expr",
135638
- /* 205 */ "nexprlist ::= expr",
135639
- /* 206 */ "paren_exprlist ::=",
135640
- /* 207 */ "paren_exprlist ::= LP exprlist RP",
135641
- /* 208 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
135642
- /* 209 */ "uniqueflag ::= UNIQUE",
135643
- /* 210 */ "uniqueflag ::=",
135644
- /* 211 */ "eidlist_opt ::=",
135645
- /* 212 */ "eidlist_opt ::= LP eidlist RP",
135646
- /* 213 */ "eidlist ::= eidlist COMMA nm collate sortorder",
135647
- /* 214 */ "eidlist ::= nm collate sortorder",
135648
- /* 215 */ "collate ::=",
135649
- /* 216 */ "collate ::= COLLATE ID|STRING",
135650
- /* 217 */ "cmd ::= DROP INDEX ifexists fullname",
135651
- /* 218 */ "cmd ::= VACUUM",
135652
- /* 219 */ "cmd ::= VACUUM nm",
135653
- /* 220 */ "cmd ::= PRAGMA nm dbnm",
135654
- /* 221 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
135655
- /* 222 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
135656
- /* 223 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
135657
- /* 224 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
135658
- /* 225 */ "plus_num ::= PLUS INTEGER|FLOAT",
135659
- /* 226 */ "minus_num ::= MINUS INTEGER|FLOAT",
135660
- /* 227 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
135661
- /* 228 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
135662
- /* 229 */ "trigger_time ::= BEFORE",
135663
- /* 230 */ "trigger_time ::= AFTER",
135664
- /* 231 */ "trigger_time ::= INSTEAD OF",
135665
- /* 232 */ "trigger_time ::=",
135666
- /* 233 */ "trigger_event ::= DELETE|INSERT",
135667
- /* 234 */ "trigger_event ::= UPDATE",
135668
- /* 235 */ "trigger_event ::= UPDATE OF idlist",
135669
- /* 236 */ "when_clause ::=",
135670
- /* 237 */ "when_clause ::= WHEN expr",
135671
- /* 238 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
135672
- /* 239 */ "trigger_cmd_list ::= trigger_cmd SEMI",
135673
- /* 240 */ "trnm ::= nm DOT nm",
135674
- /* 241 */ "tridxby ::= INDEXED BY nm",
135675
- /* 242 */ "tridxby ::= NOT INDEXED",
135676
- /* 243 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt",
135677
- /* 244 */ "trigger_cmd ::= insert_cmd INTO trnm idlist_opt select",
135678
- /* 245 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt",
135679
- /* 246 */ "trigger_cmd ::= select",
135680
- /* 247 */ "expr ::= RAISE LP IGNORE RP",
135681
- /* 248 */ "expr ::= RAISE LP raisetype COMMA nm RP",
135682
- /* 249 */ "raisetype ::= ROLLBACK",
135683
- /* 250 */ "raisetype ::= ABORT",
135684
- /* 251 */ "raisetype ::= FAIL",
135685
- /* 252 */ "cmd ::= DROP TRIGGER ifexists fullname",
135686
- /* 253 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
135687
- /* 254 */ "cmd ::= DETACH database_kw_opt expr",
135688
- /* 255 */ "key_opt ::=",
135689
- /* 256 */ "key_opt ::= KEY expr",
135690
- /* 257 */ "cmd ::= REINDEX",
135691
- /* 258 */ "cmd ::= REINDEX nm dbnm",
135692
- /* 259 */ "cmd ::= ANALYZE",
135693
- /* 260 */ "cmd ::= ANALYZE nm dbnm",
135694
- /* 261 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
135695
- /* 262 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist",
135696
- /* 263 */ "add_column_fullname ::= fullname",
135697
- /* 264 */ "cmd ::= create_vtab",
135698
- /* 265 */ "cmd ::= create_vtab LP vtabarglist RP",
135699
- /* 266 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
135700
- /* 267 */ "vtabarg ::=",
135701
- /* 268 */ "vtabargtoken ::= ANY",
135702
- /* 269 */ "vtabargtoken ::= lp anylist RP",
135703
- /* 270 */ "lp ::= LP",
135704
- /* 271 */ "with ::=",
135705
- /* 272 */ "with ::= WITH wqlist",
135706
- /* 273 */ "with ::= WITH RECURSIVE wqlist",
135707
- /* 274 */ "wqlist ::= nm eidlist_opt AS LP select RP",
135708
- /* 275 */ "wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP",
135709
- /* 276 */ "input ::= cmdlist",
135710
- /* 277 */ "cmdlist ::= cmdlist ecmd",
135711
- /* 278 */ "cmdlist ::= ecmd",
135712
- /* 279 */ "ecmd ::= SEMI",
135713
- /* 280 */ "ecmd ::= explain cmdx SEMI",
135714
- /* 281 */ "explain ::=",
135715
- /* 282 */ "trans_opt ::=",
135716
- /* 283 */ "trans_opt ::= TRANSACTION",
135717
- /* 284 */ "trans_opt ::= TRANSACTION nm",
135718
- /* 285 */ "savepoint_opt ::= SAVEPOINT",
135719
- /* 286 */ "savepoint_opt ::=",
135720
- /* 287 */ "cmd ::= create_table create_table_args",
135721
- /* 288 */ "columnlist ::= columnlist COMMA columnname carglist",
135722
- /* 289 */ "columnlist ::= columnname carglist",
135723
- /* 290 */ "nm ::= ID|INDEXED",
135724
- /* 291 */ "nm ::= STRING",
135725
- /* 292 */ "nm ::= JOIN_KW",
135726
- /* 293 */ "typetoken ::= typename",
135727
- /* 294 */ "typename ::= ID|STRING",
135728
- /* 295 */ "signed ::= plus_num",
135729
- /* 296 */ "signed ::= minus_num",
135730
- /* 297 */ "carglist ::= carglist ccons",
135731
- /* 298 */ "carglist ::=",
135732
- /* 299 */ "ccons ::= NULL onconf",
135733
- /* 300 */ "conslist_opt ::= COMMA conslist",
135734
- /* 301 */ "conslist ::= conslist tconscomma tcons",
135735
- /* 302 */ "conslist ::= tcons",
135736
- /* 303 */ "tconscomma ::=",
135737
- /* 304 */ "defer_subclause_opt ::= defer_subclause",
135738
- /* 305 */ "resolvetype ::= raisetype",
135739
- /* 306 */ "selectnowith ::= oneselect",
135740
- /* 307 */ "oneselect ::= values",
135741
- /* 308 */ "sclp ::= selcollist COMMA",
135742
- /* 309 */ "as ::= ID|STRING",
135743
- /* 310 */ "expr ::= term",
136128
+ /* 174 */ "likeop ::= NOT LIKE_KW|MATCH",
136129
+ /* 175 */ "expr ::= expr likeop expr",
136130
+ /* 176 */ "expr ::= expr likeop expr ESCAPE expr",
136131
+ /* 177 */ "expr ::= expr ISNULL|NOTNULL",
136132
+ /* 178 */ "expr ::= expr NOT NULL",
136133
+ /* 179 */ "expr ::= expr IS expr",
136134
+ /* 180 */ "expr ::= expr IS NOT expr",
136135
+ /* 181 */ "expr ::= NOT expr",
136136
+ /* 182 */ "expr ::= BITNOT expr",
136137
+ /* 183 */ "expr ::= MINUS expr",
136138
+ /* 184 */ "expr ::= PLUS expr",
136139
+ /* 185 */ "between_op ::= BETWEEN",
136140
+ /* 186 */ "between_op ::= NOT BETWEEN",
136141
+ /* 187 */ "expr ::= expr between_op expr AND expr",
136142
+ /* 188 */ "in_op ::= IN",
136143
+ /* 189 */ "in_op ::= NOT IN",
136144
+ /* 190 */ "expr ::= expr in_op LP exprlist RP",
136145
+ /* 191 */ "expr ::= LP select RP",
136146
+ /* 192 */ "expr ::= expr in_op LP select RP",
136147
+ /* 193 */ "expr ::= expr in_op nm dbnm paren_exprlist",
136148
+ /* 194 */ "expr ::= EXISTS LP select RP",
136149
+ /* 195 */ "expr ::= CASE case_operand case_exprlist case_else END",
136150
+ /* 196 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
136151
+ /* 197 */ "case_exprlist ::= WHEN expr THEN expr",
136152
+ /* 198 */ "case_else ::= ELSE expr",
136153
+ /* 199 */ "case_else ::=",
136154
+ /* 200 */ "case_operand ::= expr",
136155
+ /* 201 */ "case_operand ::=",
136156
+ /* 202 */ "exprlist ::=",
136157
+ /* 203 */ "nexprlist ::= nexprlist COMMA expr",
136158
+ /* 204 */ "nexprlist ::= expr",
136159
+ /* 205 */ "paren_exprlist ::=",
136160
+ /* 206 */ "paren_exprlist ::= LP exprlist RP",
136161
+ /* 207 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
136162
+ /* 208 */ "uniqueflag ::= UNIQUE",
136163
+ /* 209 */ "uniqueflag ::=",
136164
+ /* 210 */ "eidlist_opt ::=",
136165
+ /* 211 */ "eidlist_opt ::= LP eidlist RP",
136166
+ /* 212 */ "eidlist ::= eidlist COMMA nm collate sortorder",
136167
+ /* 213 */ "eidlist ::= nm collate sortorder",
136168
+ /* 214 */ "collate ::=",
136169
+ /* 215 */ "collate ::= COLLATE ID|STRING",
136170
+ /* 216 */ "cmd ::= DROP INDEX ifexists fullname",
136171
+ /* 217 */ "cmd ::= VACUUM",
136172
+ /* 218 */ "cmd ::= VACUUM nm",
136173
+ /* 219 */ "cmd ::= PRAGMA nm dbnm",
136174
+ /* 220 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
136175
+ /* 221 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
136176
+ /* 222 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
136177
+ /* 223 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
136178
+ /* 224 */ "plus_num ::= PLUS INTEGER|FLOAT",
136179
+ /* 225 */ "minus_num ::= MINUS INTEGER|FLOAT",
136180
+ /* 226 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
136181
+ /* 227 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
136182
+ /* 228 */ "trigger_time ::= BEFORE",
136183
+ /* 229 */ "trigger_time ::= AFTER",
136184
+ /* 230 */ "trigger_time ::= INSTEAD OF",
136185
+ /* 231 */ "trigger_time ::=",
136186
+ /* 232 */ "trigger_event ::= DELETE|INSERT",
136187
+ /* 233 */ "trigger_event ::= UPDATE",
136188
+ /* 234 */ "trigger_event ::= UPDATE OF idlist",
136189
+ /* 235 */ "when_clause ::=",
136190
+ /* 236 */ "when_clause ::= WHEN expr",
136191
+ /* 237 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
136192
+ /* 238 */ "trigger_cmd_list ::= trigger_cmd SEMI",
136193
+ /* 239 */ "trnm ::= nm DOT nm",
136194
+ /* 240 */ "tridxby ::= INDEXED BY nm",
136195
+ /* 241 */ "tridxby ::= NOT INDEXED",
136196
+ /* 242 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt",
136197
+ /* 243 */ "trigger_cmd ::= insert_cmd INTO trnm idlist_opt select",
136198
+ /* 244 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt",
136199
+ /* 245 */ "trigger_cmd ::= select",
136200
+ /* 246 */ "expr ::= RAISE LP IGNORE RP",
136201
+ /* 247 */ "expr ::= RAISE LP raisetype COMMA nm RP",
136202
+ /* 248 */ "raisetype ::= ROLLBACK",
136203
+ /* 249 */ "raisetype ::= ABORT",
136204
+ /* 250 */ "raisetype ::= FAIL",
136205
+ /* 251 */ "cmd ::= DROP TRIGGER ifexists fullname",
136206
+ /* 252 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
136207
+ /* 253 */ "cmd ::= DETACH database_kw_opt expr",
136208
+ /* 254 */ "key_opt ::=",
136209
+ /* 255 */ "key_opt ::= KEY expr",
136210
+ /* 256 */ "cmd ::= REINDEX",
136211
+ /* 257 */ "cmd ::= REINDEX nm dbnm",
136212
+ /* 258 */ "cmd ::= ANALYZE",
136213
+ /* 259 */ "cmd ::= ANALYZE nm dbnm",
136214
+ /* 260 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
136215
+ /* 261 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist",
136216
+ /* 262 */ "add_column_fullname ::= fullname",
136217
+ /* 263 */ "cmd ::= create_vtab",
136218
+ /* 264 */ "cmd ::= create_vtab LP vtabarglist RP",
136219
+ /* 265 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
136220
+ /* 266 */ "vtabarg ::=",
136221
+ /* 267 */ "vtabargtoken ::= ANY",
136222
+ /* 268 */ "vtabargtoken ::= lp anylist RP",
136223
+ /* 269 */ "lp ::= LP",
136224
+ /* 270 */ "with ::=",
136225
+ /* 271 */ "with ::= WITH wqlist",
136226
+ /* 272 */ "with ::= WITH RECURSIVE wqlist",
136227
+ /* 273 */ "wqlist ::= nm eidlist_opt AS LP select RP",
136228
+ /* 274 */ "wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP",
136229
+ /* 275 */ "input ::= cmdlist",
136230
+ /* 276 */ "cmdlist ::= cmdlist ecmd",
136231
+ /* 277 */ "cmdlist ::= ecmd",
136232
+ /* 278 */ "ecmd ::= SEMI",
136233
+ /* 279 */ "ecmd ::= explain cmdx SEMI",
136234
+ /* 280 */ "explain ::=",
136235
+ /* 281 */ "trans_opt ::=",
136236
+ /* 282 */ "trans_opt ::= TRANSACTION",
136237
+ /* 283 */ "trans_opt ::= TRANSACTION nm",
136238
+ /* 284 */ "savepoint_opt ::= SAVEPOINT",
136239
+ /* 285 */ "savepoint_opt ::=",
136240
+ /* 286 */ "cmd ::= create_table create_table_args",
136241
+ /* 287 */ "columnlist ::= columnlist COMMA columnname carglist",
136242
+ /* 288 */ "columnlist ::= columnname carglist",
136243
+ /* 289 */ "nm ::= ID|INDEXED",
136244
+ /* 290 */ "nm ::= STRING",
136245
+ /* 291 */ "nm ::= JOIN_KW",
136246
+ /* 292 */ "typetoken ::= typename",
136247
+ /* 293 */ "typename ::= ID|STRING",
136248
+ /* 294 */ "signed ::= plus_num",
136249
+ /* 295 */ "signed ::= minus_num",
136250
+ /* 296 */ "carglist ::= carglist ccons",
136251
+ /* 297 */ "carglist ::=",
136252
+ /* 298 */ "ccons ::= NULL onconf",
136253
+ /* 299 */ "conslist_opt ::= COMMA conslist",
136254
+ /* 300 */ "conslist ::= conslist tconscomma tcons",
136255
+ /* 301 */ "conslist ::= tcons",
136256
+ /* 302 */ "tconscomma ::=",
136257
+ /* 303 */ "defer_subclause_opt ::= defer_subclause",
136258
+ /* 304 */ "resolvetype ::= raisetype",
136259
+ /* 305 */ "selectnowith ::= oneselect",
136260
+ /* 306 */ "oneselect ::= values",
136261
+ /* 307 */ "sclp ::= selcollist COMMA",
136262
+ /* 308 */ "as ::= ID|STRING",
136263
+ /* 309 */ "expr ::= term",
136264
+ /* 310 */ "likeop ::= LIKE_KW|MATCH",
135744136265
/* 311 */ "exprlist ::= nexprlist",
135745136266
/* 312 */ "nmnum ::= plus_num",
135746136267
/* 313 */ "nmnum ::= nm",
135747136268
/* 314 */ "nmnum ::= ON",
135748136269
/* 315 */ "nmnum ::= DELETE",
@@ -136375,11 +136896,10 @@
136375136896
{ 173, 3 },
136376136897
{ 173, 3 },
136377136898
{ 173, 3 },
136378136899
{ 173, 3 },
136379136900
{ 173, 3 },
136380
- { 221, 1 },
136381136901
{ 221, 2 },
136382136902
{ 173, 3 },
136383136903
{ 173, 5 },
136384136904
{ 173, 2 },
136385136905
{ 173, 3 },
@@ -136512,10 +137032,11 @@
136512137032
{ 194, 1 },
136513137033
{ 195, 1 },
136514137034
{ 209, 2 },
136515137035
{ 210, 1 },
136516137036
{ 173, 1 },
137037
+ { 221, 1 },
136517137038
{ 208, 1 },
136518137039
{ 230, 1 },
136519137040
{ 230, 1 },
136520137041
{ 230, 1 },
136521137042
{ 230, 1 },
@@ -136654,11 +137175,11 @@
136654137175
case 42: /* autoinc ::= */ yytestcase(yyruleno==42);
136655137176
case 57: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==57);
136656137177
case 67: /* defer_subclause_opt ::= */ yytestcase(yyruleno==67);
136657137178
case 76: /* ifexists ::= */ yytestcase(yyruleno==76);
136658137179
case 90: /* distinct ::= */ yytestcase(yyruleno==90);
136659
- case 215: /* collate ::= */ yytestcase(yyruleno==215);
137180
+ case 214: /* collate ::= */ yytestcase(yyruleno==214);
136660137181
{yymsp[1].minor.yy194 = 0;}
136661137182
break;
136662137183
case 17: /* ifnotexists ::= IF NOT EXISTS */
136663137184
{yymsp[-2].minor.yy194 = 1;}
136664137185
break;
@@ -136798,13 +137319,13 @@
136798137319
case 144: /* insert_cmd ::= INSERT orconf */ yytestcase(yyruleno==144);
136799137320
{yymsp[-1].minor.yy194 = yymsp[0].minor.yy194;}
136800137321
break;
136801137322
case 58: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
136802137323
case 75: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==75);
136803
- case 187: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==187);
136804
- case 190: /* in_op ::= NOT IN */ yytestcase(yyruleno==190);
136805
- case 216: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==216);
137324
+ case 186: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==186);
137325
+ case 189: /* in_op ::= NOT IN */ yytestcase(yyruleno==189);
137326
+ case 215: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==215);
136806137327
{yymsp[-1].minor.yy194 = 1;}
136807137328
break;
136808137329
case 59: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
136809137330
{yymsp[-1].minor.yy194 = 0;}
136810137331
break;
@@ -136964,13 +137485,13 @@
136964137485
{yymsp[0].minor.yy194 = SF_All;}
136965137486
break;
136966137487
case 91: /* sclp ::= */
136967137488
case 119: /* orderby_opt ::= */ yytestcase(yyruleno==119);
136968137489
case 126: /* groupby_opt ::= */ yytestcase(yyruleno==126);
136969
- case 203: /* exprlist ::= */ yytestcase(yyruleno==203);
136970
- case 206: /* paren_exprlist ::= */ yytestcase(yyruleno==206);
136971
- case 211: /* eidlist_opt ::= */ yytestcase(yyruleno==211);
137490
+ case 202: /* exprlist ::= */ yytestcase(yyruleno==202);
137491
+ case 205: /* paren_exprlist ::= */ yytestcase(yyruleno==205);
137492
+ case 210: /* eidlist_opt ::= */ yytestcase(yyruleno==210);
136972137493
{yymsp[1].minor.yy148 = 0;}
136973137494
break;
136974137495
case 92: /* selcollist ::= sclp expr as */
136975137496
{
136976137497
yymsp[-2].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy148, yymsp[-1].minor.yy190.pExpr);
@@ -136992,12 +137513,12 @@
136992137513
yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148, pDot);
136993137514
}
136994137515
break;
136995137516
case 95: /* as ::= AS nm */
136996137517
case 106: /* dbnm ::= DOT nm */ yytestcase(yyruleno==106);
136997
- case 225: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==225);
136998
- case 226: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==226);
137518
+ case 224: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==224);
137519
+ case 225: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==225);
136999137520
{yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
137000137521
break;
137001137522
case 97: /* from ::= */
137002137523
{yymsp[1].minor.yy185 = sqlite3DbMallocZero(pParse->db, sizeof(*yymsp[1].minor.yy185));}
137003137524
break;
@@ -137076,18 +137597,18 @@
137076137597
{yymsp[-3].minor.yy194 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/}
137077137598
break;
137078137599
case 112: /* on_opt ::= ON expr */
137079137600
case 129: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==129);
137080137601
case 136: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==136);
137081
- case 199: /* case_else ::= ELSE expr */ yytestcase(yyruleno==199);
137602
+ case 198: /* case_else ::= ELSE expr */ yytestcase(yyruleno==198);
137082137603
{yymsp[-1].minor.yy72 = yymsp[0].minor.yy190.pExpr;}
137083137604
break;
137084137605
case 113: /* on_opt ::= */
137085137606
case 128: /* having_opt ::= */ yytestcase(yyruleno==128);
137086137607
case 135: /* where_opt ::= */ yytestcase(yyruleno==135);
137087
- case 200: /* case_else ::= */ yytestcase(yyruleno==200);
137088
- case 202: /* case_operand ::= */ yytestcase(yyruleno==202);
137608
+ case 199: /* case_else ::= */ yytestcase(yyruleno==199);
137609
+ case 201: /* case_operand ::= */ yytestcase(yyruleno==201);
137089137610
{yymsp[1].minor.yy72 = 0;}
137090137611
break;
137091137612
case 115: /* indexed_opt ::= INDEXED BY nm */
137092137613
{yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;}
137093137614
break;
@@ -137230,11 +137751,11 @@
137230137751
case 158: /* term ::= INTEGER */
137231137752
{
137232137753
yylhsminor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
137233137754
yylhsminor.yy190.zStart = yymsp[0].minor.yy0.z;
137234137755
yylhsminor.yy190.zEnd = yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n;
137235
- if( yylhsminor.yy190.pExpr ) yylhsminor.yy190.pExpr->flags |= EP_Leaf;
137756
+ if( yylhsminor.yy190.pExpr ) yylhsminor.yy190.pExpr->flags |= EP_Leaf|EP_Resolved;
137236137757
}
137237137758
yymsp[0].minor.yy190 = yylhsminor.yy190;
137238137759
break;
137239137760
case 159: /* expr ::= VARIABLE */
137240137761
{
@@ -137320,17 +137841,14 @@
137320137841
case 171: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==171);
137321137842
case 172: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==172);
137322137843
case 173: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==173);
137323137844
{spanBinaryExpr(pParse,yymsp[-1].major,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy190);}
137324137845
break;
137325
- case 174: /* likeop ::= LIKE_KW|MATCH */
137326
-{yymsp[0].minor.yy0=yymsp[0].minor.yy0;/*A-overwrites-X*/}
137327
- break;
137328
- case 175: /* likeop ::= NOT LIKE_KW|MATCH */
137846
+ case 174: /* likeop ::= NOT LIKE_KW|MATCH */
137329137847
{yymsp[-1].minor.yy0=yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n|=0x80000000; /*yymsp[-1].minor.yy0-overwrite-yymsp[0].minor.yy0*/}
137330137848
break;
137331
- case 176: /* expr ::= expr likeop expr */
137849
+ case 175: /* expr ::= expr likeop expr */
137332137850
{
137333137851
ExprList *pList;
137334137852
int bNot = yymsp[-1].minor.yy0.n & 0x80000000;
137335137853
yymsp[-1].minor.yy0.n &= 0x7fffffff;
137336137854
pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy190.pExpr);
@@ -137339,11 +137857,11 @@
137339137857
exprNot(pParse, bNot, &yymsp[-2].minor.yy190);
137340137858
yymsp[-2].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd;
137341137859
if( yymsp[-2].minor.yy190.pExpr ) yymsp[-2].minor.yy190.pExpr->flags |= EP_InfixFunc;
137342137860
}
137343137861
break;
137344
- case 177: /* expr ::= expr likeop expr ESCAPE expr */
137862
+ case 176: /* expr ::= expr likeop expr ESCAPE expr */
137345137863
{
137346137864
ExprList *pList;
137347137865
int bNot = yymsp[-3].minor.yy0.n & 0x80000000;
137348137866
yymsp[-3].minor.yy0.n &= 0x7fffffff;
137349137867
pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr);
@@ -137353,43 +137871,43 @@
137353137871
exprNot(pParse, bNot, &yymsp[-4].minor.yy190);
137354137872
yymsp[-4].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd;
137355137873
if( yymsp[-4].minor.yy190.pExpr ) yymsp[-4].minor.yy190.pExpr->flags |= EP_InfixFunc;
137356137874
}
137357137875
break;
137358
- case 178: /* expr ::= expr ISNULL|NOTNULL */
137876
+ case 177: /* expr ::= expr ISNULL|NOTNULL */
137359137877
{spanUnaryPostfix(pParse,yymsp[0].major,&yymsp[-1].minor.yy190,&yymsp[0].minor.yy0);}
137360137878
break;
137361
- case 179: /* expr ::= expr NOT NULL */
137879
+ case 178: /* expr ::= expr NOT NULL */
137362137880
{spanUnaryPostfix(pParse,TK_NOTNULL,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy0);}
137363137881
break;
137364
- case 180: /* expr ::= expr IS expr */
137882
+ case 179: /* expr ::= expr IS expr */
137365137883
{
137366137884
spanBinaryExpr(pParse,TK_IS,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy190);
137367137885
binaryToUnaryIfNull(pParse, yymsp[0].minor.yy190.pExpr, yymsp[-2].minor.yy190.pExpr, TK_ISNULL);
137368137886
}
137369137887
break;
137370
- case 181: /* expr ::= expr IS NOT expr */
137888
+ case 180: /* expr ::= expr IS NOT expr */
137371137889
{
137372137890
spanBinaryExpr(pParse,TK_ISNOT,&yymsp[-3].minor.yy190,&yymsp[0].minor.yy190);
137373137891
binaryToUnaryIfNull(pParse, yymsp[0].minor.yy190.pExpr, yymsp[-3].minor.yy190.pExpr, TK_NOTNULL);
137374137892
}
137375137893
break;
137376
- case 182: /* expr ::= NOT expr */
137377
- case 183: /* expr ::= BITNOT expr */ yytestcase(yyruleno==183);
137894
+ case 181: /* expr ::= NOT expr */
137895
+ case 182: /* expr ::= BITNOT expr */ yytestcase(yyruleno==182);
137378137896
{spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,yymsp[-1].major,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/}
137379137897
break;
137380
- case 184: /* expr ::= MINUS expr */
137898
+ case 183: /* expr ::= MINUS expr */
137381137899
{spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,TK_UMINUS,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/}
137382137900
break;
137383
- case 185: /* expr ::= PLUS expr */
137901
+ case 184: /* expr ::= PLUS expr */
137384137902
{spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,TK_UPLUS,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/}
137385137903
break;
137386
- case 186: /* between_op ::= BETWEEN */
137387
- case 189: /* in_op ::= IN */ yytestcase(yyruleno==189);
137904
+ case 185: /* between_op ::= BETWEEN */
137905
+ case 188: /* in_op ::= IN */ yytestcase(yyruleno==188);
137388137906
{yymsp[0].minor.yy194 = 0;}
137389137907
break;
137390
- case 188: /* expr ::= expr between_op expr AND expr */
137908
+ case 187: /* expr ::= expr between_op expr AND expr */
137391137909
{
137392137910
ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr);
137393137911
pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy190.pExpr);
137394137912
yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy190.pExpr, 0);
137395137913
if( yymsp[-4].minor.yy190.pExpr ){
@@ -137399,11 +137917,11 @@
137399137917
}
137400137918
exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
137401137919
yymsp[-4].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd;
137402137920
}
137403137921
break;
137404
- case 191: /* expr ::= expr in_op LP exprlist RP */
137922
+ case 190: /* expr ::= expr in_op LP exprlist RP */
137405137923
{
137406137924
if( yymsp[-1].minor.yy148==0 ){
137407137925
/* Expressions of the form
137408137926
**
137409137927
** expr1 IN ()
@@ -137452,26 +137970,26 @@
137452137970
exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
137453137971
}
137454137972
yymsp[-4].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
137455137973
}
137456137974
break;
137457
- case 192: /* expr ::= LP select RP */
137975
+ case 191: /* expr ::= LP select RP */
137458137976
{
137459137977
spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
137460137978
yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
137461137979
sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy190.pExpr, yymsp[-1].minor.yy243);
137462137980
}
137463137981
break;
137464
- case 193: /* expr ::= expr in_op LP select RP */
137982
+ case 192: /* expr ::= expr in_op LP select RP */
137465137983
{
137466137984
yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
137467137985
sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, yymsp[-1].minor.yy243);
137468137986
exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
137469137987
yymsp[-4].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
137470137988
}
137471137989
break;
137472
- case 194: /* expr ::= expr in_op nm dbnm paren_exprlist */
137990
+ case 193: /* expr ::= expr in_op nm dbnm paren_exprlist */
137473137991
{
137474137992
SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
137475137993
Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
137476137994
if( yymsp[0].minor.yy148 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy148);
137477137995
yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
@@ -137478,19 +137996,19 @@
137478137996
sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, pSelect);
137479137997
exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
137480137998
yymsp[-4].minor.yy190.zEnd = yymsp[-1].minor.yy0.z ? &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n] : &yymsp[-2].minor.yy0.z[yymsp[-2].minor.yy0.n];
137481137999
}
137482138000
break;
137483
- case 195: /* expr ::= EXISTS LP select RP */
138001
+ case 194: /* expr ::= EXISTS LP select RP */
137484138002
{
137485138003
Expr *p;
137486138004
spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
137487138005
p = yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
137488138006
sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy243);
137489138007
}
137490138008
break;
137491
- case 196: /* expr ::= CASE case_operand case_exprlist case_else END */
138009
+ case 195: /* expr ::= CASE case_operand case_exprlist case_else END */
137492138010
{
137493138011
spanSet(&yymsp[-4].minor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-C*/
137494138012
yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy72, 0);
137495138013
if( yymsp[-4].minor.yy190.pExpr ){
137496138014
yymsp[-4].minor.yy190.pExpr->x.pList = yymsp[-1].minor.yy72 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy148,yymsp[-1].minor.yy72) : yymsp[-2].minor.yy148;
@@ -137499,313 +138017,314 @@
137499138017
sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy148);
137500138018
sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy72);
137501138019
}
137502138020
}
137503138021
break;
137504
- case 197: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
138022
+ case 196: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
137505138023
{
137506138024
yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy148, yymsp[-2].minor.yy190.pExpr);
137507138025
yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy148, yymsp[0].minor.yy190.pExpr);
137508138026
}
137509138027
break;
137510
- case 198: /* case_exprlist ::= WHEN expr THEN expr */
138028
+ case 197: /* case_exprlist ::= WHEN expr THEN expr */
137511138029
{
137512138030
yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr);
137513138031
yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148, yymsp[0].minor.yy190.pExpr);
137514138032
}
137515138033
break;
137516
- case 201: /* case_operand ::= expr */
138034
+ case 200: /* case_operand ::= expr */
137517138035
{yymsp[0].minor.yy72 = yymsp[0].minor.yy190.pExpr; /*A-overwrites-X*/}
137518138036
break;
137519
- case 204: /* nexprlist ::= nexprlist COMMA expr */
138037
+ case 203: /* nexprlist ::= nexprlist COMMA expr */
137520138038
{yymsp[-2].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy148,yymsp[0].minor.yy190.pExpr);}
137521138039
break;
137522
- case 205: /* nexprlist ::= expr */
138040
+ case 204: /* nexprlist ::= expr */
137523138041
{yymsp[0].minor.yy148 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy190.pExpr); /*A-overwrites-Y*/}
137524138042
break;
137525
- case 207: /* paren_exprlist ::= LP exprlist RP */
137526
- case 212: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==212);
138043
+ case 206: /* paren_exprlist ::= LP exprlist RP */
138044
+ case 211: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==211);
137527138045
{yymsp[-2].minor.yy148 = yymsp[-1].minor.yy148;}
137528138046
break;
137529
- case 208: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
138047
+ case 207: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
137530138048
{
137531138049
sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
137532138050
sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy148, yymsp[-10].minor.yy194,
137533138051
&yymsp[-11].minor.yy0, yymsp[0].minor.yy72, SQLITE_SO_ASC, yymsp[-8].minor.yy194, SQLITE_IDXTYPE_APPDEF);
137534138052
}
137535138053
break;
137536
- case 209: /* uniqueflag ::= UNIQUE */
137537
- case 250: /* raisetype ::= ABORT */ yytestcase(yyruleno==250);
138054
+ case 208: /* uniqueflag ::= UNIQUE */
138055
+ case 249: /* raisetype ::= ABORT */ yytestcase(yyruleno==249);
137538138056
{yymsp[0].minor.yy194 = OE_Abort;}
137539138057
break;
137540
- case 210: /* uniqueflag ::= */
138058
+ case 209: /* uniqueflag ::= */
137541138059
{yymsp[1].minor.yy194 = OE_None;}
137542138060
break;
137543
- case 213: /* eidlist ::= eidlist COMMA nm collate sortorder */
138061
+ case 212: /* eidlist ::= eidlist COMMA nm collate sortorder */
137544138062
{
137545138063
yymsp[-4].minor.yy148 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy148, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy194, yymsp[0].minor.yy194);
137546138064
}
137547138065
break;
137548
- case 214: /* eidlist ::= nm collate sortorder */
138066
+ case 213: /* eidlist ::= nm collate sortorder */
137549138067
{
137550138068
yymsp[-2].minor.yy148 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy194, yymsp[0].minor.yy194); /*A-overwrites-Y*/
137551138069
}
137552138070
break;
137553
- case 217: /* cmd ::= DROP INDEX ifexists fullname */
138071
+ case 216: /* cmd ::= DROP INDEX ifexists fullname */
137554138072
{sqlite3DropIndex(pParse, yymsp[0].minor.yy185, yymsp[-1].minor.yy194);}
137555138073
break;
137556
- case 218: /* cmd ::= VACUUM */
138074
+ case 217: /* cmd ::= VACUUM */
137557138075
{sqlite3Vacuum(pParse,0);}
137558138076
break;
137559
- case 219: /* cmd ::= VACUUM nm */
138077
+ case 218: /* cmd ::= VACUUM nm */
137560138078
{sqlite3Vacuum(pParse,&yymsp[0].minor.yy0);}
137561138079
break;
137562
- case 220: /* cmd ::= PRAGMA nm dbnm */
138080
+ case 219: /* cmd ::= PRAGMA nm dbnm */
137563138081
{sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
137564138082
break;
137565
- case 221: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
138083
+ case 220: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
137566138084
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
137567138085
break;
137568
- case 222: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
138086
+ case 221: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
137569138087
{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
137570138088
break;
137571
- case 223: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
138089
+ case 222: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
137572138090
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
137573138091
break;
137574
- case 224: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
138092
+ case 223: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
137575138093
{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
137576138094
break;
137577
- case 227: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
138095
+ case 226: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
137578138096
{
137579138097
Token all;
137580138098
all.z = yymsp[-3].minor.yy0.z;
137581138099
all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
137582138100
sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy145, &all);
137583138101
}
137584138102
break;
137585
- case 228: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
138103
+ case 227: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
137586138104
{
137587138105
sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy194, yymsp[-4].minor.yy332.a, yymsp[-4].minor.yy332.b, yymsp[-2].minor.yy185, yymsp[0].minor.yy72, yymsp[-10].minor.yy194, yymsp[-8].minor.yy194);
137588138106
yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
137589138107
}
137590138108
break;
137591
- case 229: /* trigger_time ::= BEFORE */
138109
+ case 228: /* trigger_time ::= BEFORE */
137592138110
{ yymsp[0].minor.yy194 = TK_BEFORE; }
137593138111
break;
137594
- case 230: /* trigger_time ::= AFTER */
138112
+ case 229: /* trigger_time ::= AFTER */
137595138113
{ yymsp[0].minor.yy194 = TK_AFTER; }
137596138114
break;
137597
- case 231: /* trigger_time ::= INSTEAD OF */
138115
+ case 230: /* trigger_time ::= INSTEAD OF */
137598138116
{ yymsp[-1].minor.yy194 = TK_INSTEAD;}
137599138117
break;
137600
- case 232: /* trigger_time ::= */
138118
+ case 231: /* trigger_time ::= */
137601138119
{ yymsp[1].minor.yy194 = TK_BEFORE; }
137602138120
break;
137603
- case 233: /* trigger_event ::= DELETE|INSERT */
137604
- case 234: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==234);
138121
+ case 232: /* trigger_event ::= DELETE|INSERT */
138122
+ case 233: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==233);
137605138123
{yymsp[0].minor.yy332.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy332.b = 0;}
137606138124
break;
137607
- case 235: /* trigger_event ::= UPDATE OF idlist */
138125
+ case 234: /* trigger_event ::= UPDATE OF idlist */
137608138126
{yymsp[-2].minor.yy332.a = TK_UPDATE; yymsp[-2].minor.yy332.b = yymsp[0].minor.yy254;}
137609138127
break;
137610
- case 236: /* when_clause ::= */
137611
- case 255: /* key_opt ::= */ yytestcase(yyruleno==255);
138128
+ case 235: /* when_clause ::= */
138129
+ case 254: /* key_opt ::= */ yytestcase(yyruleno==254);
137612138130
{ yymsp[1].minor.yy72 = 0; }
137613138131
break;
137614
- case 237: /* when_clause ::= WHEN expr */
137615
- case 256: /* key_opt ::= KEY expr */ yytestcase(yyruleno==256);
138132
+ case 236: /* when_clause ::= WHEN expr */
138133
+ case 255: /* key_opt ::= KEY expr */ yytestcase(yyruleno==255);
137616138134
{ yymsp[-1].minor.yy72 = yymsp[0].minor.yy190.pExpr; }
137617138135
break;
137618
- case 238: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
138136
+ case 237: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
137619138137
{
137620138138
assert( yymsp[-2].minor.yy145!=0 );
137621138139
yymsp[-2].minor.yy145->pLast->pNext = yymsp[-1].minor.yy145;
137622138140
yymsp[-2].minor.yy145->pLast = yymsp[-1].minor.yy145;
137623138141
}
137624138142
break;
137625
- case 239: /* trigger_cmd_list ::= trigger_cmd SEMI */
138143
+ case 238: /* trigger_cmd_list ::= trigger_cmd SEMI */
137626138144
{
137627138145
assert( yymsp[-1].minor.yy145!=0 );
137628138146
yymsp[-1].minor.yy145->pLast = yymsp[-1].minor.yy145;
137629138147
}
137630138148
break;
137631
- case 240: /* trnm ::= nm DOT nm */
138149
+ case 239: /* trnm ::= nm DOT nm */
137632138150
{
137633138151
yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
137634138152
sqlite3ErrorMsg(pParse,
137635138153
"qualified table names are not allowed on INSERT, UPDATE, and DELETE "
137636138154
"statements within triggers");
137637138155
}
137638138156
break;
137639
- case 241: /* tridxby ::= INDEXED BY nm */
138157
+ case 240: /* tridxby ::= INDEXED BY nm */
137640138158
{
137641138159
sqlite3ErrorMsg(pParse,
137642138160
"the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
137643138161
"within triggers");
137644138162
}
137645138163
break;
137646
- case 242: /* tridxby ::= NOT INDEXED */
138164
+ case 241: /* tridxby ::= NOT INDEXED */
137647138165
{
137648138166
sqlite3ErrorMsg(pParse,
137649138167
"the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
137650138168
"within triggers");
137651138169
}
137652138170
break;
137653
- case 243: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
138171
+ case 242: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
137654138172
{yymsp[-6].minor.yy145 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy148, yymsp[0].minor.yy72, yymsp[-5].minor.yy194);}
137655138173
break;
137656
- case 244: /* trigger_cmd ::= insert_cmd INTO trnm idlist_opt select */
138174
+ case 243: /* trigger_cmd ::= insert_cmd INTO trnm idlist_opt select */
137657138175
{yymsp[-4].minor.yy145 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy254, yymsp[0].minor.yy243, yymsp[-4].minor.yy194);/*A-overwrites-R*/}
137658138176
break;
137659
- case 245: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
138177
+ case 244: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
137660138178
{yymsp[-4].minor.yy145 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy72);}
137661138179
break;
137662
- case 246: /* trigger_cmd ::= select */
138180
+ case 245: /* trigger_cmd ::= select */
137663138181
{yymsp[0].minor.yy145 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy243); /*A-overwrites-X*/}
137664138182
break;
137665
- case 247: /* expr ::= RAISE LP IGNORE RP */
138183
+ case 246: /* expr ::= RAISE LP IGNORE RP */
137666138184
{
137667138185
spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
137668138186
yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
137669138187
if( yymsp[-3].minor.yy190.pExpr ){
137670138188
yymsp[-3].minor.yy190.pExpr->affinity = OE_Ignore;
137671138189
}
137672138190
}
137673138191
break;
137674
- case 248: /* expr ::= RAISE LP raisetype COMMA nm RP */
138192
+ case 247: /* expr ::= RAISE LP raisetype COMMA nm RP */
137675138193
{
137676138194
spanSet(&yymsp[-5].minor.yy190,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
137677138195
yymsp[-5].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
137678138196
if( yymsp[-5].minor.yy190.pExpr ) {
137679138197
yymsp[-5].minor.yy190.pExpr->affinity = (char)yymsp[-3].minor.yy194;
137680138198
}
137681138199
}
137682138200
break;
137683
- case 249: /* raisetype ::= ROLLBACK */
138201
+ case 248: /* raisetype ::= ROLLBACK */
137684138202
{yymsp[0].minor.yy194 = OE_Rollback;}
137685138203
break;
137686
- case 251: /* raisetype ::= FAIL */
138204
+ case 250: /* raisetype ::= FAIL */
137687138205
{yymsp[0].minor.yy194 = OE_Fail;}
137688138206
break;
137689
- case 252: /* cmd ::= DROP TRIGGER ifexists fullname */
138207
+ case 251: /* cmd ::= DROP TRIGGER ifexists fullname */
137690138208
{
137691138209
sqlite3DropTrigger(pParse,yymsp[0].minor.yy185,yymsp[-1].minor.yy194);
137692138210
}
137693138211
break;
137694
- case 253: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
138212
+ case 252: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
137695138213
{
137696138214
sqlite3Attach(pParse, yymsp[-3].minor.yy190.pExpr, yymsp[-1].minor.yy190.pExpr, yymsp[0].minor.yy72);
137697138215
}
137698138216
break;
137699
- case 254: /* cmd ::= DETACH database_kw_opt expr */
138217
+ case 253: /* cmd ::= DETACH database_kw_opt expr */
137700138218
{
137701138219
sqlite3Detach(pParse, yymsp[0].minor.yy190.pExpr);
137702138220
}
137703138221
break;
137704
- case 257: /* cmd ::= REINDEX */
138222
+ case 256: /* cmd ::= REINDEX */
137705138223
{sqlite3Reindex(pParse, 0, 0);}
137706138224
break;
137707
- case 258: /* cmd ::= REINDEX nm dbnm */
138225
+ case 257: /* cmd ::= REINDEX nm dbnm */
137708138226
{sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
137709138227
break;
137710
- case 259: /* cmd ::= ANALYZE */
138228
+ case 258: /* cmd ::= ANALYZE */
137711138229
{sqlite3Analyze(pParse, 0, 0);}
137712138230
break;
137713
- case 260: /* cmd ::= ANALYZE nm dbnm */
138231
+ case 259: /* cmd ::= ANALYZE nm dbnm */
137714138232
{sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
137715138233
break;
137716
- case 261: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
138234
+ case 260: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
137717138235
{
137718138236
sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy185,&yymsp[0].minor.yy0);
137719138237
}
137720138238
break;
137721
- case 262: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
138239
+ case 261: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
137722138240
{
137723138241
yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n;
137724138242
sqlite3AlterFinishAddColumn(pParse, &yymsp[-1].minor.yy0);
137725138243
}
137726138244
break;
137727
- case 263: /* add_column_fullname ::= fullname */
138245
+ case 262: /* add_column_fullname ::= fullname */
137728138246
{
137729138247
disableLookaside(pParse);
137730138248
sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy185);
137731138249
}
137732138250
break;
137733
- case 264: /* cmd ::= create_vtab */
138251
+ case 263: /* cmd ::= create_vtab */
137734138252
{sqlite3VtabFinishParse(pParse,0);}
137735138253
break;
137736
- case 265: /* cmd ::= create_vtab LP vtabarglist RP */
138254
+ case 264: /* cmd ::= create_vtab LP vtabarglist RP */
137737138255
{sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
137738138256
break;
137739
- case 266: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
138257
+ case 265: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
137740138258
{
137741138259
sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy194);
137742138260
}
137743138261
break;
137744
- case 267: /* vtabarg ::= */
138262
+ case 266: /* vtabarg ::= */
137745138263
{sqlite3VtabArgInit(pParse);}
137746138264
break;
137747
- case 268: /* vtabargtoken ::= ANY */
137748
- case 269: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==269);
137749
- case 270: /* lp ::= LP */ yytestcase(yyruleno==270);
138265
+ case 267: /* vtabargtoken ::= ANY */
138266
+ case 268: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==268);
138267
+ case 269: /* lp ::= LP */ yytestcase(yyruleno==269);
137750138268
{sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
137751138269
break;
137752
- case 271: /* with ::= */
138270
+ case 270: /* with ::= */
137753138271
{yymsp[1].minor.yy285 = 0;}
137754138272
break;
137755
- case 272: /* with ::= WITH wqlist */
138273
+ case 271: /* with ::= WITH wqlist */
137756138274
{ yymsp[-1].minor.yy285 = yymsp[0].minor.yy285; }
137757138275
break;
137758
- case 273: /* with ::= WITH RECURSIVE wqlist */
138276
+ case 272: /* with ::= WITH RECURSIVE wqlist */
137759138277
{ yymsp[-2].minor.yy285 = yymsp[0].minor.yy285; }
137760138278
break;
137761
- case 274: /* wqlist ::= nm eidlist_opt AS LP select RP */
138279
+ case 273: /* wqlist ::= nm eidlist_opt AS LP select RP */
137762138280
{
137763138281
yymsp[-5].minor.yy285 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy148, yymsp[-1].minor.yy243); /*A-overwrites-X*/
137764138282
}
137765138283
break;
137766
- case 275: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
138284
+ case 274: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
137767138285
{
137768138286
yymsp[-7].minor.yy285 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy285, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy148, yymsp[-1].minor.yy243);
137769138287
}
137770138288
break;
137771138289
default:
137772
- /* (276) input ::= cmdlist */ yytestcase(yyruleno==276);
137773
- /* (277) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==277);
137774
- /* (278) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=278);
137775
- /* (279) ecmd ::= SEMI */ yytestcase(yyruleno==279);
137776
- /* (280) ecmd ::= explain cmdx SEMI */ yytestcase(yyruleno==280);
137777
- /* (281) explain ::= */ yytestcase(yyruleno==281);
137778
- /* (282) trans_opt ::= */ yytestcase(yyruleno==282);
137779
- /* (283) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==283);
137780
- /* (284) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==284);
137781
- /* (285) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==285);
137782
- /* (286) savepoint_opt ::= */ yytestcase(yyruleno==286);
137783
- /* (287) cmd ::= create_table create_table_args */ yytestcase(yyruleno==287);
137784
- /* (288) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==288);
137785
- /* (289) columnlist ::= columnname carglist */ yytestcase(yyruleno==289);
137786
- /* (290) nm ::= ID|INDEXED */ yytestcase(yyruleno==290);
137787
- /* (291) nm ::= STRING */ yytestcase(yyruleno==291);
137788
- /* (292) nm ::= JOIN_KW */ yytestcase(yyruleno==292);
137789
- /* (293) typetoken ::= typename */ yytestcase(yyruleno==293);
137790
- /* (294) typename ::= ID|STRING */ yytestcase(yyruleno==294);
137791
- /* (295) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=295);
137792
- /* (296) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=296);
137793
- /* (297) carglist ::= carglist ccons */ yytestcase(yyruleno==297);
137794
- /* (298) carglist ::= */ yytestcase(yyruleno==298);
137795
- /* (299) ccons ::= NULL onconf */ yytestcase(yyruleno==299);
137796
- /* (300) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==300);
137797
- /* (301) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==301);
137798
- /* (302) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=302);
137799
- /* (303) tconscomma ::= */ yytestcase(yyruleno==303);
137800
- /* (304) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=304);
137801
- /* (305) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=305);
137802
- /* (306) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=306);
137803
- /* (307) oneselect ::= values */ yytestcase(yyruleno==307);
137804
- /* (308) sclp ::= selcollist COMMA */ yytestcase(yyruleno==308);
137805
- /* (309) as ::= ID|STRING */ yytestcase(yyruleno==309);
137806
- /* (310) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=310);
138290
+ /* (275) input ::= cmdlist */ yytestcase(yyruleno==275);
138291
+ /* (276) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==276);
138292
+ /* (277) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=277);
138293
+ /* (278) ecmd ::= SEMI */ yytestcase(yyruleno==278);
138294
+ /* (279) ecmd ::= explain cmdx SEMI */ yytestcase(yyruleno==279);
138295
+ /* (280) explain ::= */ yytestcase(yyruleno==280);
138296
+ /* (281) trans_opt ::= */ yytestcase(yyruleno==281);
138297
+ /* (282) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==282);
138298
+ /* (283) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==283);
138299
+ /* (284) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==284);
138300
+ /* (285) savepoint_opt ::= */ yytestcase(yyruleno==285);
138301
+ /* (286) cmd ::= create_table create_table_args */ yytestcase(yyruleno==286);
138302
+ /* (287) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==287);
138303
+ /* (288) columnlist ::= columnname carglist */ yytestcase(yyruleno==288);
138304
+ /* (289) nm ::= ID|INDEXED */ yytestcase(yyruleno==289);
138305
+ /* (290) nm ::= STRING */ yytestcase(yyruleno==290);
138306
+ /* (291) nm ::= JOIN_KW */ yytestcase(yyruleno==291);
138307
+ /* (292) typetoken ::= typename */ yytestcase(yyruleno==292);
138308
+ /* (293) typename ::= ID|STRING */ yytestcase(yyruleno==293);
138309
+ /* (294) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=294);
138310
+ /* (295) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=295);
138311
+ /* (296) carglist ::= carglist ccons */ yytestcase(yyruleno==296);
138312
+ /* (297) carglist ::= */ yytestcase(yyruleno==297);
138313
+ /* (298) ccons ::= NULL onconf */ yytestcase(yyruleno==298);
138314
+ /* (299) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==299);
138315
+ /* (300) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==300);
138316
+ /* (301) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=301);
138317
+ /* (302) tconscomma ::= */ yytestcase(yyruleno==302);
138318
+ /* (303) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=303);
138319
+ /* (304) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=304);
138320
+ /* (305) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=305);
138321
+ /* (306) oneselect ::= values */ yytestcase(yyruleno==306);
138322
+ /* (307) sclp ::= selcollist COMMA */ yytestcase(yyruleno==307);
138323
+ /* (308) as ::= ID|STRING */ yytestcase(yyruleno==308);
138324
+ /* (309) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=309);
138325
+ /* (310) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==310);
137807138326
/* (311) exprlist ::= nexprlist */ yytestcase(yyruleno==311);
137808138327
/* (312) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=312);
137809138328
/* (313) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=313);
137810138329
/* (314) nmnum ::= ON */ yytestcase(yyruleno==314);
137811138330
/* (315) nmnum ::= DELETE */ yytestcase(yyruleno==315);
@@ -138854,12 +139373,12 @@
138854139373
** memory obtained from sqlite3_malloc() and to make *pzErrMsg point to that
138855139374
** error message.
138856139375
*/
138857139376
SQLITE_PRIVATE int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
138858139377
int nErr = 0; /* Number of errors encountered */
138859
- int i; /* Loop counter */
138860139378
void *pEngine; /* The LEMON-generated LALR(1) parser */
139379
+ int n = 0; /* Length of the next token token */
138861139380
int tokenType; /* type of the next token */
138862139381
int lastTokenParsed = -1; /* type of the previous token */
138863139382
sqlite3 *db = pParse->db; /* The database connection */
138864139383
int mxSqlLen; /* Max length of an SQL string */
138865139384
#ifdef sqlite3Parser_ENGINEALWAYSONSTACK
@@ -138871,11 +139390,10 @@
138871139390
if( db->nVdbeActive==0 ){
138872139391
db->u1.isInterrupted = 0;
138873139392
}
138874139393
pParse->rc = SQLITE_OK;
138875139394
pParse->zTail = zSql;
138876
- i = 0;
138877139395
assert( pzErrMsg!=0 );
138878139396
/* sqlite3ParserTrace(stdout, "parser: "); */
138879139397
#ifdef sqlite3Parser_ENGINEALWAYSONSTACK
138880139398
pEngine = zSpace;
138881139399
sqlite3ParserInit(pEngine);
@@ -138889,16 +139407,14 @@
138889139407
assert( pParse->pNewTable==0 );
138890139408
assert( pParse->pNewTrigger==0 );
138891139409
assert( pParse->nVar==0 );
138892139410
assert( pParse->pVList==0 );
138893139411
while( 1 ){
138894
- assert( i>=0 );
138895
- if( zSql[i]!=0 ){
138896
- pParse->sLastToken.z = &zSql[i];
138897
- pParse->sLastToken.n = sqlite3GetToken((u8*)&zSql[i],&tokenType);
138898
- i += pParse->sLastToken.n;
138899
- if( i>mxSqlLen ){
139412
+ if( zSql[0]!=0 ){
139413
+ n = sqlite3GetToken((u8*)zSql, &tokenType);
139414
+ mxSqlLen -= n;
139415
+ if( mxSqlLen<0 ){
138900139416
pParse->rc = SQLITE_TOOBIG;
138901139417
break;
138902139418
}
138903139419
}else{
138904139420
/* Upon reaching the end of input, call the parser two more times
@@ -138908,30 +139424,34 @@
138908139424
}else if( lastTokenParsed==0 ){
138909139425
break;
138910139426
}else{
138911139427
tokenType = TK_SEMI;
138912139428
}
139429
+ zSql -= n;
138913139430
}
138914139431
if( tokenType>=TK_SPACE ){
138915139432
assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
138916139433
if( db->u1.isInterrupted ){
138917139434
pParse->rc = SQLITE_INTERRUPT;
138918139435
break;
138919139436
}
138920139437
if( tokenType==TK_ILLEGAL ){
138921
- sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"",
138922
- &pParse->sLastToken);
139438
+ sqlite3ErrorMsg(pParse, "unrecognized token: \"%.*s\"", n, zSql);
138923139439
break;
138924139440
}
139441
+ zSql += n;
138925139442
}else{
139443
+ pParse->sLastToken.z = zSql;
139444
+ pParse->sLastToken.n = n;
138926139445
sqlite3Parser(pEngine, tokenType, pParse->sLastToken, pParse);
138927139446
lastTokenParsed = tokenType;
139447
+ zSql += n;
138928139448
if( pParse->rc!=SQLITE_OK || db->mallocFailed ) break;
138929139449
}
138930139450
}
138931139451
assert( nErr==0 );
138932
- pParse->zTail = &zSql[i];
139452
+ pParse->zTail = zSql;
138933139453
#ifdef YYTRACKMAXSTACKDEPTH
138934139454
sqlite3_mutex_enter(sqlite3MallocMutex());
138935139455
sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
138936139456
sqlite3ParserStackPeak(pEngine)
138937139457
);
@@ -140301,10 +140821,25 @@
140301140821
return 0;
140302140822
}
140303140823
#endif
140304140824
return db->lastRowid;
140305140825
}
140826
+
140827
+/*
140828
+** Set the value returned by the sqlite3_last_insert_rowid() API function.
140829
+*/
140830
+SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3 *db, sqlite3_int64 iRowid){
140831
+#ifdef SQLITE_ENABLE_API_ARMOR
140832
+ if( !sqlite3SafetyCheckOk(db) ){
140833
+ (void)SQLITE_MISUSE_BKPT;
140834
+ return;
140835
+ }
140836
+#endif
140837
+ sqlite3_mutex_enter(db->mutex);
140838
+ db->lastRowid = iRowid;
140839
+ sqlite3_mutex_leave(db->mutex);
140840
+}
140306140841
140307140842
/*
140308140843
** Return the number of changes in the most recent call to sqlite3_exec().
140309140844
*/
140310140845
SQLITE_API int sqlite3_changes(sqlite3 *db){
@@ -145052,12 +145587,13 @@
145052145587
/*
145053145588
** Read a 64-bit variable-length integer from memory starting at p[0].
145054145589
** Return the number of bytes read, or 0 on error.
145055145590
** The value is stored in *v.
145056145591
*/
145057
-SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *p, sqlite_int64 *v){
145058
- const char *pStart = p;
145592
+SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *pBuf, sqlite_int64 *v){
145593
+ const unsigned char *p = (const unsigned char*)pBuf;
145594
+ const unsigned char *pStart = p;
145059145595
u32 a;
145060145596
u64 b;
145061145597
int shift;
145062145598
145063145599
GETVARINT_INIT(a, p, 0, 0x00, 0x80, *v, 1);
@@ -146100,11 +146636,13 @@
146100146636
/* Fill in the azColumn array */
146101146637
for(iCol=0; iCol<nCol; iCol++){
146102146638
char *z;
146103146639
int n = 0;
146104146640
z = (char *)sqlite3Fts3NextToken(aCol[iCol], &n);
146105
- memcpy(zCsr, z, n);
146641
+ if( n>0 ){
146642
+ memcpy(zCsr, z, n);
146643
+ }
146106146644
zCsr[n] = '\0';
146107146645
sqlite3Fts3Dequote(zCsr);
146108146646
p->azColumn[iCol] = zCsr;
146109146647
zCsr += n+1;
146110146648
assert( zCsr <= &((char *)p)[nByte] );
@@ -148111,12 +148649,14 @@
148111148649
** segments.
148112148650
*/
148113148651
const u32 nMinMerge = 64; /* Minimum amount of incr-merge work to do */
148114148652
148115148653
Fts3Table *p = (Fts3Table*)pVtab;
148116
- int rc = sqlite3Fts3PendingTermsFlush(p);
148654
+ int rc;
148655
+ i64 iLastRowid = sqlite3_last_insert_rowid(p->db);
148117148656
148657
+ rc = sqlite3Fts3PendingTermsFlush(p);
148118148658
if( rc==SQLITE_OK
148119148659
&& p->nLeafAdd>(nMinMerge/16)
148120148660
&& p->nAutoincrmerge && p->nAutoincrmerge!=0xff
148121148661
){
148122148662
int mxLevel = 0; /* Maximum relative level value in db */
@@ -148127,10 +148667,11 @@
148127148667
A = p->nLeafAdd * mxLevel;
148128148668
A += (A/2);
148129148669
if( A>(int)nMinMerge ) rc = sqlite3Fts3Incrmerge(p, A, p->nAutoincrmerge);
148130148670
}
148131148671
sqlite3Fts3SegmentsClose(p);
148672
+ sqlite3_set_last_insert_rowid(p->db, iLastRowid);
148132148673
return rc;
148133148674
}
148134148675
148135148676
/*
148136148677
** If it is currently unknown whether or not the FTS table has an %_stat
@@ -159737,15 +160278,18 @@
159737160278
159738160279
/*
159739160280
** Convert the text beginning at *pz into an integer and return
159740160281
** its value. Advance *pz to point to the first character past
159741160282
** the integer.
160283
+**
160284
+** This function used for parameters to merge= and incrmerge=
160285
+** commands.
159742160286
*/
159743160287
static int fts3Getint(const char **pz){
159744160288
const char *z = *pz;
159745160289
int i = 0;
159746
- while( (*z)>='0' && (*z)<='9' ) i = 10*i + *(z++) - '0';
160290
+ while( (*z)>='0' && (*z)<='9' && i<214748363 ) i = 10*i + *(z++) - '0';
159747160291
*pz = z;
159748160292
return i;
159749160293
}
159750160294
159751160295
/*
@@ -162307,20 +162851,20 @@
162307162851
const char *zIn, /* Array of characters to make exceptions */
162308162852
int nIn /* Length of z in bytes */
162309162853
){
162310162854
const unsigned char *z = (const unsigned char *)zIn;
162311162855
const unsigned char *zTerm = &z[nIn];
162312
- int iCode;
162856
+ unsigned int iCode;
162313162857
int nEntry = 0;
162314162858
162315162859
assert( bAlnum==0 || bAlnum==1 );
162316162860
162317162861
while( z<zTerm ){
162318162862
READ_UTF8(z, zTerm, iCode);
162319
- assert( (sqlite3FtsUnicodeIsalnum(iCode) & 0xFFFFFFFE)==0 );
162320
- if( sqlite3FtsUnicodeIsalnum(iCode)!=bAlnum
162321
- && sqlite3FtsUnicodeIsdiacritic(iCode)==0
162863
+ assert( (sqlite3FtsUnicodeIsalnum((int)iCode) & 0xFFFFFFFE)==0 );
162864
+ if( sqlite3FtsUnicodeIsalnum((int)iCode)!=bAlnum
162865
+ && sqlite3FtsUnicodeIsdiacritic((int)iCode)==0
162322162866
){
162323162867
nEntry++;
162324162868
}
162325162869
}
162326162870
@@ -162333,17 +162877,17 @@
162333162877
nNew = p->nException;
162334162878
162335162879
z = (const unsigned char *)zIn;
162336162880
while( z<zTerm ){
162337162881
READ_UTF8(z, zTerm, iCode);
162338
- if( sqlite3FtsUnicodeIsalnum(iCode)!=bAlnum
162339
- && sqlite3FtsUnicodeIsdiacritic(iCode)==0
162882
+ if( sqlite3FtsUnicodeIsalnum((int)iCode)!=bAlnum
162883
+ && sqlite3FtsUnicodeIsdiacritic((int)iCode)==0
162340162884
){
162341162885
int i, j;
162342
- for(i=0; i<nNew && aNew[i]<iCode; i++);
162886
+ for(i=0; i<nNew && aNew[i]<(int)iCode; i++);
162343162887
for(j=nNew; j>i; j--) aNew[j] = aNew[j-1];
162344
- aNew[i] = iCode;
162888
+ aNew[i] = (int)iCode;
162345162889
nNew++;
162346162890
}
162347162891
}
162348162892
p->aiException = aNew;
162349162893
p->nException = nNew;
@@ -162489,11 +163033,11 @@
162489163033
int *piEnd, /* OUT: Ending offset of token */
162490163034
int *piPos /* OUT: Position integer of token */
162491163035
){
162492163036
unicode_cursor *pCsr = (unicode_cursor *)pC;
162493163037
unicode_tokenizer *p = ((unicode_tokenizer *)pCsr->base.pTokenizer);
162494
- int iCode = 0;
163038
+ unsigned int iCode = 0;
162495163039
char *zOut;
162496163040
const unsigned char *z = &pCsr->aInput[pCsr->iOff];
162497163041
const unsigned char *zStart = z;
162498163042
const unsigned char *zEnd;
162499163043
const unsigned char *zTerm = &pCsr->aInput[pCsr->nInput];
@@ -162501,11 +163045,11 @@
162501163045
/* Scan past any delimiter characters before the start of the next token.
162502163046
** Return SQLITE_DONE early if this takes us all the way to the end of
162503163047
** the input. */
162504163048
while( z<zTerm ){
162505163049
READ_UTF8(z, zTerm, iCode);
162506
- if( unicodeIsAlnum(p, iCode) ) break;
163050
+ if( unicodeIsAlnum(p, (int)iCode) ) break;
162507163051
zStart = z;
162508163052
}
162509163053
if( zStart>=zTerm ) return SQLITE_DONE;
162510163054
162511163055
zOut = pCsr->zToken;
@@ -162521,20 +163065,20 @@
162521163065
pCsr->nAlloc += 64;
162522163066
}
162523163067
162524163068
/* Write the folded case of the last character read to the output */
162525163069
zEnd = z;
162526
- iOut = sqlite3FtsUnicodeFold(iCode, p->bRemoveDiacritic);
163070
+ iOut = sqlite3FtsUnicodeFold((int)iCode, p->bRemoveDiacritic);
162527163071
if( iOut ){
162528163072
WRITE_UTF8(zOut, iOut);
162529163073
}
162530163074
162531163075
/* If the cursor is not at EOF, read the next character */
162532163076
if( z>=zTerm ) break;
162533163077
READ_UTF8(z, zTerm, iCode);
162534
- }while( unicodeIsAlnum(p, iCode)
162535
- || sqlite3FtsUnicodeIsdiacritic(iCode)
163078
+ }while( unicodeIsAlnum(p, (int)iCode)
163079
+ || sqlite3FtsUnicodeIsdiacritic((int)iCode)
162536163080
);
162537163081
162538163082
/* Set the output variables and return. */
162539163083
pCsr->iOff = (int)(z - pCsr->aInput);
162540163084
*paToken = pCsr->zToken;
@@ -162694,13 +163238,13 @@
162694163238
};
162695163239
static const unsigned int aAscii[4] = {
162696163240
0xFFFFFFFF, 0xFC00FFFF, 0xF8000001, 0xF8000001,
162697163241
};
162698163242
162699
- if( c<128 ){
162700
- return ( (aAscii[c >> 5] & (1 << (c & 0x001F)))==0 );
162701
- }else if( c<(1<<22) ){
163243
+ if( (unsigned int)c<128 ){
163244
+ return ( (aAscii[c >> 5] & ((unsigned int)1 << (c & 0x001F)))==0 );
163245
+ }else if( (unsigned int)c<(1<<22) ){
162702163246
unsigned int key = (((unsigned int)c)<<10) | 0x000003FF;
162703163247
int iRes = 0;
162704163248
int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1;
162705163249
int iLo = 0;
162706163250
while( iHi>=iLo ){
@@ -162889,20 +163433,21 @@
162889163433
65514, 65521, 65527, 65528, 65529,
162890163434
};
162891163435
162892163436
int ret = c;
162893163437
162894
- assert( c>=0 );
162895163438
assert( sizeof(unsigned short)==2 && sizeof(unsigned char)==1 );
162896163439
162897163440
if( c<128 ){
162898163441
if( c>='A' && c<='Z' ) ret = c + ('a' - 'A');
162899163442
}else if( c<65536 ){
163443
+ const struct TableEntry *p;
162900163444
int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1;
162901163445
int iLo = 0;
162902163446
int iRes = -1;
162903163447
163448
+ assert( c>aEntry[0].iCode );
162904163449
while( iHi>=iLo ){
162905163450
int iTest = (iHi + iLo) / 2;
162906163451
int cmp = (c - aEntry[iTest].iCode);
162907163452
if( cmp>=0 ){
162908163453
iRes = iTest;
@@ -162909,18 +163454,16 @@
162909163454
iLo = iTest+1;
162910163455
}else{
162911163456
iHi = iTest-1;
162912163457
}
162913163458
}
162914
- assert( iRes<0 || c>=aEntry[iRes].iCode );
162915
-
162916
- if( iRes>=0 ){
162917
- const struct TableEntry *p = &aEntry[iRes];
162918
- if( c<(p->iCode + p->nRange) && 0==(0x01 & p->flags & (p->iCode ^ c)) ){
162919
- ret = (c + (aiOff[p->flags>>1])) & 0x0000FFFF;
162920
- assert( ret>0 );
162921
- }
163459
+
163460
+ assert( iRes>=0 && c>=aEntry[iRes].iCode );
163461
+ p = &aEntry[iRes];
163462
+ if( c<(p->iCode + p->nRange) && 0==(0x01 & p->flags & (p->iCode ^ c)) ){
163463
+ ret = (c + (aiOff[p->flags>>1])) & 0x0000FFFF;
163464
+ assert( ret>0 );
162922163465
}
162923163466
162924163467
if( bRemoveDiacritic ) ret = remove_diacritic(ret);
162925163468
}
162926163469
@@ -163393,19 +163936,19 @@
163393163936
#elif SQLITE_BYTEORDER==4321
163394163937
i64 x;
163395163938
memcpy(&x, p, 8);
163396163939
return x;
163397163940
#else
163398
- return (
163399
- (((i64)p[0]) << 56) +
163400
- (((i64)p[1]) << 48) +
163401
- (((i64)p[2]) << 40) +
163402
- (((i64)p[3]) << 32) +
163403
- (((i64)p[4]) << 24) +
163404
- (((i64)p[5]) << 16) +
163405
- (((i64)p[6]) << 8) +
163406
- (((i64)p[7]) << 0)
163941
+ return (i64)(
163942
+ (((u64)p[0]) << 56) +
163943
+ (((u64)p[1]) << 48) +
163944
+ (((u64)p[2]) << 40) +
163945
+ (((u64)p[3]) << 32) +
163946
+ (((u64)p[4]) << 24) +
163947
+ (((u64)p[5]) << 16) +
163948
+ (((u64)p[6]) << 8) +
163949
+ (((u64)p[7]) << 0)
163407163950
);
163408163951
#endif
163409163952
}
163410163953
163411163954
/*
@@ -168462,10 +169005,11 @@
168462169005
int nStep; /* Rows processed for current object */
168463169006
int nProgress; /* Rows processed for all objects */
168464169007
RbuObjIter objiter; /* Iterator for skipping through tbl/idx */
168465169008
const char *zVfsName; /* Name of automatically created rbu vfs */
168466169009
rbu_file *pTargetFd; /* File handle open on target db */
169010
+ int nPagePerSector; /* Pages per sector for pTargetFd */
168467169011
i64 iOalSz;
168468169012
i64 nPhaseOneStep;
168469169013
168470169014
/* The following state variables are used as part of the incremental
168471169015
** checkpoint stage (eStage==RBU_STAGE_CKPT). See comments surrounding
@@ -170726,10 +171270,27 @@
170726171270
170727171271
if( p->rc==SQLITE_OK ){
170728171272
if( p->nFrame==0 || (pState && pState->iWalCksum!=p->iWalCksum) ){
170729171273
p->rc = SQLITE_DONE;
170730171274
p->eStage = RBU_STAGE_DONE;
171275
+ }else{
171276
+ int nSectorSize;
171277
+ sqlite3_file *pDb = p->pTargetFd->pReal;
171278
+ sqlite3_file *pWal = p->pTargetFd->pWalFd->pReal;
171279
+ assert( p->nPagePerSector==0 );
171280
+ nSectorSize = pDb->pMethods->xSectorSize(pDb);
171281
+ if( nSectorSize>p->pgsz ){
171282
+ p->nPagePerSector = nSectorSize / p->pgsz;
171283
+ }else{
171284
+ p->nPagePerSector = 1;
171285
+ }
171286
+
171287
+ /* Call xSync() on the wal file. This causes SQLite to sync the
171288
+ ** directory in which the target database and the wal file reside, in
171289
+ ** case it has not been synced since the rename() call in
171290
+ ** rbuMoveOalFile(). */
171291
+ p->rc = pWal->pMethods->xSync(pWal, SQLITE_SYNC_NORMAL);
170731171292
}
170732171293
}
170733171294
}
170734171295
170735171296
/*
@@ -171381,13 +171942,30 @@
171381171942
if( p->rc==SQLITE_OK ){
171382171943
p->eStage = RBU_STAGE_DONE;
171383171944
p->rc = SQLITE_DONE;
171384171945
}
171385171946
}else{
171386
- RbuFrame *pFrame = &p->aFrame[p->nStep];
171387
- rbuCheckpointFrame(p, pFrame);
171388
- p->nStep++;
171947
+ /* At one point the following block copied a single frame from the
171948
+ ** wal file to the database file. So that one call to sqlite3rbu_step()
171949
+ ** checkpointed a single frame.
171950
+ **
171951
+ ** However, if the sector-size is larger than the page-size, and the
171952
+ ** application calls sqlite3rbu_savestate() or close() immediately
171953
+ ** after this step, then rbu_step() again, then a power failure occurs,
171954
+ ** then the database page written here may be damaged. Work around
171955
+ ** this by checkpointing frames until the next page in the aFrame[]
171956
+ ** lies on a different disk sector to the current one. */
171957
+ u32 iSector;
171958
+ do{
171959
+ RbuFrame *pFrame = &p->aFrame[p->nStep];
171960
+ iSector = (pFrame->iDbPage-1) / p->nPagePerSector;
171961
+ rbuCheckpointFrame(p, pFrame);
171962
+ p->nStep++;
171963
+ }while( p->nStep<p->nFrame
171964
+ && iSector==((p->aFrame[p->nStep].iDbPage-1) / p->nPagePerSector)
171965
+ && p->rc==SQLITE_OK
171966
+ );
171389171967
}
171390171968
p->nProgress++;
171391171969
}
171392171970
break;
171393171971
}
@@ -171823,10 +172401,16 @@
171823172401
171824172402
/* Commit the transaction to the *-oal file. */
171825172403
if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_OAL ){
171826172404
p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg);
171827172405
}
172406
+
172407
+ /* Sync the db file if currently doing an incremental checkpoint */
172408
+ if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_CKPT ){
172409
+ sqlite3_file *pDb = p->pTargetFd->pReal;
172410
+ p->rc = pDb->pMethods->xSync(pDb, SQLITE_SYNC_NORMAL);
172411
+ }
171828172412
171829172413
rbuSaveState(p, p->eStage);
171830172414
171831172415
if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_OAL ){
171832172416
p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
@@ -171947,10 +172531,16 @@
171947172531
assert( p->eStage>=RBU_STAGE_OAL && p->eStage<=RBU_STAGE_DONE );
171948172532
if( p->eStage==RBU_STAGE_OAL ){
171949172533
assert( rc!=SQLITE_DONE );
171950172534
if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, 0);
171951172535
}
172536
+
172537
+ /* Sync the db file */
172538
+ if( rc==SQLITE_OK && p->eStage==RBU_STAGE_CKPT ){
172539
+ sqlite3_file *pDb = p->pTargetFd->pReal;
172540
+ rc = pDb->pMethods->xSync(pDb, SQLITE_SYNC_NORMAL);
172541
+ }
171952172542
171953172543
p->rc = rc;
171954172544
rbuSaveState(p, p->eStage);
171955172545
rc = p->rc;
171956172546
@@ -178363,26 +178953,28 @@
178363178953
/* Bit values for the JsonNode.jnFlag field
178364178954
*/
178365178955
#define JNODE_RAW 0x01 /* Content is raw, not JSON encoded */
178366178956
#define JNODE_ESCAPE 0x02 /* Content is text with \ escapes */
178367178957
#define JNODE_REMOVE 0x04 /* Do not output */
178368
-#define JNODE_REPLACE 0x08 /* Replace with JsonNode.iVal */
178369
-#define JNODE_APPEND 0x10 /* More ARRAY/OBJECT entries at u.iAppend */
178370
-#define JNODE_LABEL 0x20 /* Is a label of an object */
178958
+#define JNODE_REPLACE 0x08 /* Replace with JsonNode.u.iReplace */
178959
+#define JNODE_PATCH 0x10 /* Patch with JsonNode.u.pPatch */
178960
+#define JNODE_APPEND 0x20 /* More ARRAY/OBJECT entries at u.iAppend */
178961
+#define JNODE_LABEL 0x40 /* Is a label of an object */
178371178962
178372178963
178373178964
/* A single node of parsed JSON
178374178965
*/
178375178966
struct JsonNode {
178376178967
u8 eType; /* One of the JSON_ type values */
178377178968
u8 jnFlags; /* JNODE flags */
178378
- u8 iVal; /* Replacement value when JNODE_REPLACE */
178379178969
u32 n; /* Bytes of content, or number of sub-nodes */
178380178970
union {
178381178971
const char *zJContent; /* Content for INT, REAL, and STRING */
178382178972
u32 iAppend; /* More terms for ARRAY and OBJECT */
178383178973
u32 iKey; /* Key for ARRAY objects in json_tree() */
178974
+ u32 iReplace; /* Replacement content for JNODE_REPLACE */
178975
+ JsonNode *pPatch; /* Node chain of patch for JNODE_PATCH */
178384178976
} u;
178385178977
};
178386178978
178387178979
/* A completely parsed JSON string
178388178980
*/
@@ -178635,10 +179227,17 @@
178635179227
static void jsonRenderNode(
178636179228
JsonNode *pNode, /* The node to render */
178637179229
JsonString *pOut, /* Write JSON here */
178638179230
sqlite3_value **aReplace /* Replacement values */
178639179231
){
179232
+ if( pNode->jnFlags & (JNODE_REPLACE|JNODE_PATCH) ){
179233
+ if( pNode->jnFlags & JNODE_REPLACE ){
179234
+ jsonAppendValue(pOut, aReplace[pNode->u.iReplace]);
179235
+ return;
179236
+ }
179237
+ pNode = pNode->u.pPatch;
179238
+ }
178640179239
switch( pNode->eType ){
178641179240
default: {
178642179241
assert( pNode->eType==JSON_NULL );
178643179242
jsonAppendRaw(pOut, "null", 4);
178644179243
break;
@@ -178666,16 +179265,11 @@
178666179265
case JSON_ARRAY: {
178667179266
u32 j = 1;
178668179267
jsonAppendChar(pOut, '[');
178669179268
for(;;){
178670179269
while( j<=pNode->n ){
178671
- if( pNode[j].jnFlags & (JNODE_REMOVE|JNODE_REPLACE) ){
178672
- if( pNode[j].jnFlags & JNODE_REPLACE ){
178673
- jsonAppendSeparator(pOut);
178674
- jsonAppendValue(pOut, aReplace[pNode[j].iVal]);
178675
- }
178676
- }else{
179270
+ if( (pNode[j].jnFlags & JNODE_REMOVE)==0 ){
178677179271
jsonAppendSeparator(pOut);
178678179272
jsonRenderNode(&pNode[j], pOut, aReplace);
178679179273
}
178680179274
j += jsonNodeSize(&pNode[j]);
178681179275
}
@@ -178693,15 +179287,11 @@
178693179287
while( j<=pNode->n ){
178694179288
if( (pNode[j+1].jnFlags & JNODE_REMOVE)==0 ){
178695179289
jsonAppendSeparator(pOut);
178696179290
jsonRenderNode(&pNode[j], pOut, aReplace);
178697179291
jsonAppendChar(pOut, ':');
178698
- if( pNode[j+1].jnFlags & JNODE_REPLACE ){
178699
- jsonAppendValue(pOut, aReplace[pNode[j+1].iVal]);
178700
- }else{
178701
- jsonRenderNode(&pNode[j+1], pOut, aReplace);
178702
- }
179292
+ jsonRenderNode(&pNode[j+1], pOut, aReplace);
178703179293
}
178704179294
j += 1 + jsonNodeSize(&pNode[j+1]);
178705179295
}
178706179296
if( (pNode->jnFlags & JNODE_APPEND)==0 ) break;
178707179297
pNode = &pNode[pNode->u.iAppend];
@@ -178924,11 +179514,10 @@
178924179514
return jsonParseAddNodeExpand(pParse, eType, n, zContent);
178925179515
}
178926179516
p = &pParse->aNode[pParse->nNode];
178927179517
p->eType = (u8)eType;
178928179518
p->jnFlags = 0;
178929
- p->iVal = 0;
178930179519
p->n = n;
178931179520
p->u.zJContent = zContent;
178932179521
return pParse->nNode++;
178933179522
}
178934179523
@@ -179390,10 +179979,29 @@
179390179979
zFuncName);
179391179980
sqlite3_result_error(pCtx, zMsg, -1);
179392179981
sqlite3_free(zMsg);
179393179982
}
179394179983
179984
+/*
179985
+** Mark all NULL entries in the Object passed in as JNODE_REMOVE.
179986
+*/
179987
+static void jsonRemoveAllNulls(JsonNode *pNode){
179988
+ int i, n;
179989
+ assert( pNode->eType==JSON_OBJECT );
179990
+ n = pNode->n;
179991
+ for(i=2; i<=n; i += jsonNodeSize(&pNode[i])+1){
179992
+ switch( pNode[i].eType ){
179993
+ case JSON_NULL:
179994
+ pNode[i].jnFlags |= JNODE_REMOVE;
179995
+ break;
179996
+ case JSON_OBJECT:
179997
+ jsonRemoveAllNulls(&pNode[i]);
179998
+ break;
179999
+ }
180000
+ }
180001
+}
180002
+
179395180003
179396180004
/****************************************************************************
179397180005
** SQL functions used for testing and debugging
179398180006
****************************************************************************/
179399180007
@@ -179581,10 +180189,109 @@
179581180189
sqlite3_result_subtype(ctx, JSON_SUBTYPE);
179582180190
}
179583180191
jsonReset(&jx);
179584180192
jsonParseReset(&x);
179585180193
}
180194
+
180195
+/* This is the RFC 7396 MergePatch algorithm.
180196
+*/
180197
+static JsonNode *jsonMergePatch(
180198
+ JsonParse *pParse, /* The JSON parser that contains the TARGET */
180199
+ int iTarget, /* Node of the TARGET in pParse */
180200
+ JsonNode *pPatch /* The PATCH */
180201
+){
180202
+ u32 i, j;
180203
+ u32 iRoot;
180204
+ JsonNode *pTarget;
180205
+ if( pPatch->eType!=JSON_OBJECT ){
180206
+ return pPatch;
180207
+ }
180208
+ assert( iTarget>=0 && iTarget<pParse->nNode );
180209
+ pTarget = &pParse->aNode[iTarget];
180210
+ assert( (pPatch->jnFlags & JNODE_APPEND)==0 );
180211
+ if( pTarget->eType!=JSON_OBJECT ){
180212
+ jsonRemoveAllNulls(pPatch);
180213
+ return pPatch;
180214
+ }
180215
+ iRoot = iTarget;
180216
+ for(i=1; i<pPatch->n; i += jsonNodeSize(&pPatch[i+1])+1){
180217
+ u32 nKey;
180218
+ const char *zKey;
180219
+ assert( pPatch[i].eType==JSON_STRING );
180220
+ assert( pPatch[i].jnFlags & JNODE_LABEL );
180221
+ nKey = pPatch[i].n;
180222
+ zKey = pPatch[i].u.zJContent;
180223
+ assert( (pPatch[i].jnFlags & JNODE_RAW)==0 );
180224
+ for(j=1; j<pTarget->n; j += jsonNodeSize(&pTarget[j+1])+1 ){
180225
+ assert( pTarget[j].eType==JSON_STRING );
180226
+ assert( pTarget[j].jnFlags & JNODE_LABEL );
180227
+ assert( (pPatch[i].jnFlags & JNODE_RAW)==0 );
180228
+ if( pTarget[j].n==nKey && strncmp(pTarget[j].u.zJContent,zKey,nKey)==0 ){
180229
+ if( pTarget[j+1].jnFlags & (JNODE_REMOVE|JNODE_PATCH) ) break;
180230
+ if( pPatch[i+1].eType==JSON_NULL ){
180231
+ pTarget[j+1].jnFlags |= JNODE_REMOVE;
180232
+ }else{
180233
+ JsonNode *pNew = jsonMergePatch(pParse, iTarget+j+1, &pPatch[i+1]);
180234
+ if( pNew==0 ) return 0;
180235
+ pTarget = &pParse->aNode[iTarget];
180236
+ if( pNew!=&pTarget[j+1] ){
180237
+ pTarget[j+1].u.pPatch = pNew;
180238
+ pTarget[j+1].jnFlags |= JNODE_PATCH;
180239
+ }
180240
+ }
180241
+ break;
180242
+ }
180243
+ }
180244
+ if( j>=pTarget->n && pPatch[i+1].eType!=JSON_NULL ){
180245
+ int iStart, iPatch;
180246
+ iStart = jsonParseAddNode(pParse, JSON_OBJECT, 2, 0);
180247
+ jsonParseAddNode(pParse, JSON_STRING, nKey, zKey);
180248
+ iPatch = jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
180249
+ if( pParse->oom ) return 0;
180250
+ jsonRemoveAllNulls(pPatch);
180251
+ pTarget = &pParse->aNode[iTarget];
180252
+ pParse->aNode[iRoot].jnFlags |= JNODE_APPEND;
180253
+ pParse->aNode[iRoot].u.iAppend = iStart - iRoot;
180254
+ iRoot = iStart;
180255
+ pParse->aNode[iPatch].jnFlags |= JNODE_PATCH;
180256
+ pParse->aNode[iPatch].u.pPatch = &pPatch[i+1];
180257
+ }
180258
+ }
180259
+ return pTarget;
180260
+}
180261
+
180262
+/*
180263
+** Implementation of the json_mergepatch(JSON1,JSON2) function. Return a JSON
180264
+** object that is the result of running the RFC 7396 MergePatch() algorithm
180265
+** on the two arguments.
180266
+*/
180267
+static void jsonPatchFunc(
180268
+ sqlite3_context *ctx,
180269
+ int argc,
180270
+ sqlite3_value **argv
180271
+){
180272
+ JsonParse x; /* The JSON that is being patched */
180273
+ JsonParse y; /* The patch */
180274
+ JsonNode *pResult; /* The result of the merge */
180275
+
180276
+ UNUSED_PARAM(argc);
180277
+ if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return;
180278
+ if( jsonParse(&y, ctx, (const char*)sqlite3_value_text(argv[1])) ){
180279
+ jsonParseReset(&x);
180280
+ return;
180281
+ }
180282
+ pResult = jsonMergePatch(&x, 0, y.aNode);
180283
+ assert( pResult!=0 || x.oom );
180284
+ if( pResult ){
180285
+ jsonReturnJson(pResult, ctx, 0);
180286
+ }else{
180287
+ sqlite3_result_error_nomem(ctx);
180288
+ }
180289
+ jsonParseReset(&x);
180290
+ jsonParseReset(&y);
180291
+}
180292
+
179586180293
179587180294
/*
179588180295
** Implementation of the json_object(NAME,VALUE,...) function. Return a JSON
179589180296
** object that contains all name/value given in arguments. Or if any name
179590180297
** is not a string or if any value is a BLOB, throw an error.
@@ -179685,15 +180392,15 @@
179685180392
zPath = (const char*)sqlite3_value_text(argv[i]);
179686180393
pNode = jsonLookup(&x, zPath, 0, ctx);
179687180394
if( x.nErr ) goto replace_err;
179688180395
if( pNode ){
179689180396
pNode->jnFlags |= (u8)JNODE_REPLACE;
179690
- pNode->iVal = (u8)(i+1);
180397
+ pNode->u.iReplace = i + 1;
179691180398
}
179692180399
}
179693180400
if( x.aNode[0].jnFlags & JNODE_REPLACE ){
179694
- sqlite3_result_value(ctx, argv[x.aNode[0].iVal]);
180401
+ sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]);
179695180402
}else{
179696180403
jsonReturnJson(x.aNode, ctx, argv);
179697180404
}
179698180405
replace_err:
179699180406
jsonParseReset(&x);
@@ -179739,15 +180446,15 @@
179739180446
goto jsonSetDone;
179740180447
}else if( x.nErr ){
179741180448
goto jsonSetDone;
179742180449
}else if( pNode && (bApnd || bIsSet) ){
179743180450
pNode->jnFlags |= (u8)JNODE_REPLACE;
179744
- pNode->iVal = (u8)(i+1);
180451
+ pNode->u.iReplace = i + 1;
179745180452
}
179746180453
}
179747180454
if( x.aNode[0].jnFlags & JNODE_REPLACE ){
179748
- sqlite3_result_value(ctx, argv[x.aNode[0].iVal]);
180455
+ sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]);
179749180456
}else{
179750180457
jsonReturnJson(x.aNode, ctx, argv);
179751180458
}
179752180459
jsonSetDone:
179753180460
jsonParseReset(&x);
@@ -180386,10 +181093,11 @@
180386181093
{ "json_array_length", 1, 0, jsonArrayLengthFunc },
180387181094
{ "json_array_length", 2, 0, jsonArrayLengthFunc },
180388181095
{ "json_extract", -1, 0, jsonExtractFunc },
180389181096
{ "json_insert", -1, 0, jsonSetFunc },
180390181097
{ "json_object", -1, 0, jsonObjectFunc },
181098
+ { "json_patch", 2, 0, jsonPatchFunc },
180391181099
{ "json_quote", 1, 0, jsonQuoteFunc },
180392181100
{ "json_remove", -1, 0, jsonRemoveFunc },
180393181101
{ "json_replace", -1, 0, jsonReplaceFunc },
180394181102
{ "json_set", -1, 1, jsonSetFunc },
180395181103
{ "json_type", 1, 0, jsonTypeFunc },
@@ -181079,11 +181787,13 @@
181079181787
typedef unsigned short u16;
181080181788
typedef short i16;
181081181789
typedef sqlite3_int64 i64;
181082181790
typedef sqlite3_uint64 u64;
181083181791
181084
-#define ArraySize(x) ((int)(sizeof(x) / sizeof(x[0])))
181792
+#ifndef ArraySize
181793
+# define ArraySize(x) ((int)(sizeof(x) / sizeof(x[0])))
181794
+#endif
181085181795
181086181796
#define testcase(x)
181087181797
#define ALWAYS(x) 1
181088181798
#define NEVER(x) 0
181089181799
@@ -186302,11 +187012,14 @@
186302187012
if( p1->bEof==0 ){
186303187013
if( (p1->iRowid==iLast)
186304187014
|| (bFromValid && fts5RowidCmp(pExpr, p1->iRowid, iFrom)<0)
186305187015
){
186306187016
int rc = fts5ExprNodeNext(pExpr, p1, bFromValid, iFrom);
186307
- if( rc!=SQLITE_OK ) return rc;
187017
+ if( rc!=SQLITE_OK ){
187018
+ pNode->bNomatch = 0;
187019
+ return rc;
187020
+ }
186308187021
}
186309187022
}
186310187023
}
186311187024
186312187025
fts5ExprNodeTest_OR(pExpr, pNode);
@@ -186333,11 +187046,14 @@
186333187046
Fts5ExprNode *pChild = pAnd->apChild[iChild];
186334187047
int cmp = fts5RowidCmp(pExpr, iLast, pChild->iRowid);
186335187048
if( cmp>0 ){
186336187049
/* Advance pChild until it points to iLast or laster */
186337187050
rc = fts5ExprNodeNext(pExpr, pChild, 1, iLast);
186338
- if( rc!=SQLITE_OK ) return rc;
187051
+ if( rc!=SQLITE_OK ){
187052
+ pAnd->bNomatch = 0;
187053
+ return rc;
187054
+ }
186339187055
}
186340187056
186341187057
/* If the child node is now at EOF, so is the parent AND node. Otherwise,
186342187058
** the child node is guaranteed to have advanced at least as far as
186343187059
** rowid iLast. So if it is not at exactly iLast, pChild->iRowid is the
@@ -186372,10 +187088,12 @@
186372187088
i64 iFrom
186373187089
){
186374187090
int rc = fts5ExprNodeNext(pExpr, pNode->apChild[0], bFromValid, iFrom);
186375187091
if( rc==SQLITE_OK ){
186376187092
rc = fts5ExprNodeTest_AND(pExpr, pNode);
187093
+ }else{
187094
+ pNode->bNomatch = 0;
186377187095
}
186378187096
return rc;
186379187097
}
186380187098
186381187099
static int fts5ExprNodeTest_NOT(
@@ -186414,10 +187132,13 @@
186414187132
){
186415187133
int rc = fts5ExprNodeNext(pExpr, pNode->apChild[0], bFromValid, iFrom);
186416187134
if( rc==SQLITE_OK ){
186417187135
rc = fts5ExprNodeTest_NOT(pExpr, pNode);
186418187136
}
187137
+ if( rc!=SQLITE_OK ){
187138
+ pNode->bNomatch = 0;
187139
+ }
186419187140
return rc;
186420187141
}
186421187142
186422187143
/*
186423187144
** If pNode currently points to a match, this function returns SQLITE_OK
@@ -197534,11 +198255,11 @@
197534198255
int nArg, /* Number of args */
197535198256
sqlite3_value **apUnused /* Function arguments */
197536198257
){
197537198258
assert( nArg==0 );
197538198259
UNUSED_PARAM2(nArg, apUnused);
197539
- sqlite3_result_text(pCtx, "fts5: 2017-02-13 16:02:40 ada05cfa86ad7f5645450ac7a2a21c9aa6e57d2c", -1, SQLITE_TRANSIENT);
198260
+ sqlite3_result_text(pCtx, "fts5: 2017-03-28 18:48:43 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37", -1, SQLITE_TRANSIENT);
197540198261
}
197541198262
197542198263
static int fts5Init(sqlite3 *db){
197543198264
static const sqlite3_module fts5Mod = {
197544198265
/* iVersion */ 2,
@@ -198197,15 +198918,10 @@
198197198918
sqlite3_step(pDel);
198198198919
rc = sqlite3_reset(pDel);
198199198920
}
198200198921
}
198201198922
198202
- /* Write the averages record */
198203
- if( rc==SQLITE_OK ){
198204
- rc = fts5StorageSaveTotals(p);
198205
- }
198206
-
198207198923
return rc;
198208198924
}
198209198925
198210198926
/*
198211198927
** Delete all entries in the FTS5 index.
@@ -198405,15 +199121,10 @@
198405199121
if( rc==SQLITE_OK ){
198406199122
rc = fts5StorageInsertDocsize(p, iRowid, &buf);
198407199123
}
198408199124
sqlite3_free(buf.p);
198409199125
198410
- /* Write the averages record */
198411
- if( rc==SQLITE_OK ){
198412
- rc = fts5StorageSaveTotals(p);
198413
- }
198414
-
198415199126
return rc;
198416199127
}
198417199128
198418199129
static int fts5StorageCount(Fts5Storage *p, const char *zSuffix, i64 *pnRow){
198419199130
Fts5Config *pConfig = p->pConfig;
@@ -198744,16 +199455,21 @@
198744199455
198745199456
/*
198746199457
** Flush any data currently held in-memory to disk.
198747199458
*/
198748199459
static int sqlite3Fts5StorageSync(Fts5Storage *p, int bCommit){
198749
- if( bCommit && p->bTotalsValid ){
198750
- int rc = fts5StorageSaveTotals(p);
198751
- p->bTotalsValid = 0;
198752
- if( rc!=SQLITE_OK ) return rc;
199460
+ int rc = SQLITE_OK;
199461
+ i64 iLastRowid = sqlite3_last_insert_rowid(p->pConfig->db);
199462
+ if( p->bTotalsValid ){
199463
+ rc = fts5StorageSaveTotals(p);
199464
+ if( bCommit ) p->bTotalsValid = 0;
198753199465
}
198754
- return sqlite3Fts5IndexSync(p->pIndex, bCommit);
199466
+ if( rc==SQLITE_OK ){
199467
+ rc = sqlite3Fts5IndexSync(p->pIndex, bCommit);
199468
+ }
199469
+ sqlite3_set_last_insert_rowid(p->pConfig->db, iLastRowid);
199470
+ return rc;
198755199471
}
198756199472
198757199473
static int sqlite3Fts5StorageRollback(Fts5Storage *p){
198758199474
p->bTotalsValid = 0;
198759199475
return sqlite3Fts5IndexRollback(p->pIndex);
198760199476
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.17.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -389,20 +389,20 @@
389 ** SQLite source code has been stored in the
390 ** <a href="http://www.fossil-scm.org/">Fossil configuration management
391 ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
392 ** a string which identifies a particular check-in of SQLite
393 ** within its configuration management system. ^The SQLITE_SOURCE_ID
394 ** string contains the date and time of the check-in (UTC) and an SHA1
395 ** hash of the entire source tree.
396 **
397 ** See also: [sqlite3_libversion()],
398 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
399 ** [sqlite_version()] and [sqlite_source_id()].
400 */
401 #define SQLITE_VERSION "3.17.0"
402 #define SQLITE_VERSION_NUMBER 3017000
403 #define SQLITE_SOURCE_ID "2017-02-13 16:02:40 ada05cfa86ad7f5645450ac7a2a21c9aa6e57d2c"
404
405 /*
406 ** CAPI3REF: Run-Time Library Version Numbers
407 ** KEYWORDS: sqlite3_version sqlite3_sourceid
408 **
@@ -2315,24 +2315,34 @@
2315 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
2316 ** names are not also used by explicitly declared columns. ^If
2317 ** the table has a column of type [INTEGER PRIMARY KEY] then that column
2318 ** is another alias for the rowid.
2319 **
2320 ** ^The sqlite3_last_insert_rowid(D) interface returns the [rowid] of the
2321 ** most recent successful [INSERT] into a rowid table or [virtual table]
2322 ** on database connection D.
2323 ** ^Inserts into [WITHOUT ROWID] tables are not recorded.
2324 ** ^If no successful [INSERT]s into rowid tables
2325 ** have ever occurred on the database connection D,
2326 ** then sqlite3_last_insert_rowid(D) returns zero.
2327 **
2328 ** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
2329 ** method, then this routine will return the [rowid] of the inserted
2330 ** row as long as the trigger or virtual table method is running.
2331 ** But once the trigger or virtual table method ends, the value returned
2332 ** by this routine reverts to what it was before the trigger or virtual
2333 ** table method began.)^
 
 
 
 
 
 
 
 
 
 
 
2334 **
2335 ** ^An [INSERT] that fails due to a constraint violation is not a
2336 ** successful [INSERT] and does not change the value returned by this
2337 ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
2338 ** and INSERT OR ABORT make no changes to the return value of this
@@ -2355,10 +2365,20 @@
2355 ** unpredictable and might not equal either the old or the new
2356 ** last insert [rowid].
2357 */
2358 SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
2359
 
 
 
 
 
 
 
 
 
 
2360 /*
2361 ** CAPI3REF: Count The Number Of Rows Modified
2362 ** METHOD: sqlite3
2363 **
2364 ** ^This function returns the number of rows modified, inserted or
@@ -3679,13 +3699,13 @@
3679 ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
3680 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
3681 **
3682 ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
3683 ** <dd>The maximum number of instructions in a virtual machine program
3684 ** used to implement an SQL statement. This limit is not currently
3685 ** enforced, though that might be added in some future release of
3686 ** SQLite.</dd>)^
3687 **
3688 ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
3689 ** <dd>The maximum number of arguments on a function.</dd>)^
3690 **
3691 ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
@@ -3718,10 +3738,11 @@
3718 #define SQLITE_LIMIT_ATTACHED 7
3719 #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
3720 #define SQLITE_LIMIT_VARIABLE_NUMBER 9
3721 #define SQLITE_LIMIT_TRIGGER_DEPTH 10
3722 #define SQLITE_LIMIT_WORKER_THREADS 11
 
3723
3724 /*
3725 ** CAPI3REF: Compiling An SQL Statement
3726 ** KEYWORDS: {SQL statement compiler}
3727 ** METHOD: sqlite3
@@ -10846,11 +10867,11 @@
10846 /*
10847 ** The maximum number of opcodes in a VDBE program.
10848 ** Not currently enforced.
10849 */
10850 #ifndef SQLITE_MAX_VDBE_OP
10851 # define SQLITE_MAX_VDBE_OP 25000
10852 #endif
10853
10854 /*
10855 ** The maximum number of arguments to an SQL function.
10856 */
@@ -12457,10 +12478,11 @@
12457 SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
12458 SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
12459
12460 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
12461 SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
 
12462
12463 #ifndef SQLITE_OMIT_INCRBLOB
12464 SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*);
12465 SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
12466 SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *);
@@ -12623,10 +12645,11 @@
12623 struct SubProgram {
12624 VdbeOp *aOp; /* Array of opcodes for sub-program */
12625 int nOp; /* Elements in aOp[] */
12626 int nMem; /* Number of memory cells required */
12627 int nCsr; /* Number of cursors required */
 
12628 void *token; /* id that may be used to recursive triggers */
12629 SubProgram *pNext; /* Next sub-program already visited */
12630 };
12631
12632 /*
@@ -12757,117 +12780,119 @@
12757 #define OP_Divide 50 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
12758 #define OP_Remainder 51 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
12759 #define OP_Concat 52 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
12760 #define OP_Last 53
12761 #define OP_BitNot 54 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
12762 #define OP_SorterSort 55
12763 #define OP_Sort 56
12764 #define OP_Rewind 57
12765 #define OP_IdxLE 58 /* synopsis: key=r[P3@P4] */
12766 #define OP_IdxGT 59 /* synopsis: key=r[P3@P4] */
12767 #define OP_IdxLT 60 /* synopsis: key=r[P3@P4] */
12768 #define OP_IdxGE 61 /* synopsis: key=r[P3@P4] */
12769 #define OP_RowSetRead 62 /* synopsis: r[P3]=rowset(P1) */
12770 #define OP_RowSetTest 63 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12771 #define OP_Program 64
12772 #define OP_FkIfZero 65 /* synopsis: if fkctr[P1]==0 goto P2 */
12773 #define OP_IfPos 66 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12774 #define OP_IfNotZero 67 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
12775 #define OP_DecrJumpZero 68 /* synopsis: if (--r[P1])==0 goto P2 */
12776 #define OP_IncrVacuum 69
12777 #define OP_VNext 70
12778 #define OP_Init 71 /* synopsis: Start at P2 */
12779 #define OP_Return 72
12780 #define OP_EndCoroutine 73
12781 #define OP_HaltIfNull 74 /* synopsis: if r[P3]=null halt */
12782 #define OP_Halt 75
12783 #define OP_Integer 76 /* synopsis: r[P2]=P1 */
12784 #define OP_Int64 77 /* synopsis: r[P2]=P4 */
12785 #define OP_String 78 /* synopsis: r[P2]='P4' (len=P1) */
12786 #define OP_Null 79 /* synopsis: r[P2..P3]=NULL */
12787 #define OP_SoftNull 80 /* synopsis: r[P1]=NULL */
12788 #define OP_Blob 81 /* synopsis: r[P2]=P4 (len=P1) */
12789 #define OP_Variable 82 /* synopsis: r[P2]=parameter(P1,P4) */
12790 #define OP_Move 83 /* synopsis: r[P2@P3]=r[P1@P3] */
12791 #define OP_Copy 84 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
12792 #define OP_SCopy 85 /* synopsis: r[P2]=r[P1] */
12793 #define OP_IntCopy 86 /* synopsis: r[P2]=r[P1] */
12794 #define OP_ResultRow 87 /* synopsis: output=r[P1@P2] */
12795 #define OP_CollSeq 88
12796 #define OP_Function0 89 /* synopsis: r[P3]=func(r[P2@P5]) */
12797 #define OP_Function 90 /* synopsis: r[P3]=func(r[P2@P5]) */
12798 #define OP_AddImm 91 /* synopsis: r[P1]=r[P1]+P2 */
12799 #define OP_RealAffinity 92
12800 #define OP_Cast 93 /* synopsis: affinity(r[P1]) */
12801 #define OP_Permutation 94
12802 #define OP_Compare 95 /* synopsis: r[P1@P3] <-> r[P2@P3] */
12803 #define OP_Column 96 /* synopsis: r[P3]=PX */
12804 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
12805 #define OP_Affinity 98 /* synopsis: affinity(r[P1@P2]) */
12806 #define OP_MakeRecord 99 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
12807 #define OP_Count 100 /* synopsis: r[P2]=count() */
12808 #define OP_ReadCookie 101
12809 #define OP_SetCookie 102
12810 #define OP_ReopenIdx 103 /* synopsis: root=P2 iDb=P3 */
12811 #define OP_OpenRead 104 /* synopsis: root=P2 iDb=P3 */
12812 #define OP_OpenWrite 105 /* synopsis: root=P2 iDb=P3 */
12813 #define OP_OpenAutoindex 106 /* synopsis: nColumn=P2 */
12814 #define OP_OpenEphemeral 107 /* synopsis: nColumn=P2 */
12815 #define OP_SorterOpen 108
12816 #define OP_SequenceTest 109 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
12817 #define OP_OpenPseudo 110 /* synopsis: P3 columns in r[P2] */
12818 #define OP_Close 111
12819 #define OP_ColumnsUsed 112
12820 #define OP_Sequence 113 /* synopsis: r[P2]=cursor[P1].ctr++ */
12821 #define OP_NewRowid 114 /* synopsis: r[P2]=rowid */
12822 #define OP_Insert 115 /* synopsis: intkey=r[P3] data=r[P2] */
12823 #define OP_InsertInt 116 /* synopsis: intkey=P3 data=r[P2] */
12824 #define OP_Delete 117
12825 #define OP_ResetCount 118
12826 #define OP_SorterCompare 119 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12827 #define OP_SorterData 120 /* synopsis: r[P2]=data */
12828 #define OP_RowData 121 /* synopsis: r[P2]=data */
12829 #define OP_Rowid 122 /* synopsis: r[P2]=rowid */
12830 #define OP_NullRow 123
12831 #define OP_SorterInsert 124 /* synopsis: key=r[P2] */
12832 #define OP_IdxInsert 125 /* synopsis: key=r[P2] */
12833 #define OP_IdxDelete 126 /* synopsis: key=r[P2@P3] */
12834 #define OP_Seek 127 /* synopsis: Move P3 to P1.rowid */
12835 #define OP_IdxRowid 128 /* synopsis: r[P2]=rowid */
12836 #define OP_Destroy 129
12837 #define OP_Clear 130
12838 #define OP_ResetSorter 131
12839 #define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
12840 #define OP_CreateIndex 133 /* synopsis: r[P2]=root iDb=P1 */
12841 #define OP_CreateTable 134 /* synopsis: r[P2]=root iDb=P1 */
12842 #define OP_ParseSchema 135
12843 #define OP_LoadAnalysis 136
12844 #define OP_DropTable 137
12845 #define OP_DropIndex 138
12846 #define OP_DropTrigger 139
12847 #define OP_IntegrityCk 140
12848 #define OP_RowSetAdd 141 /* synopsis: rowset(P1)=r[P2] */
12849 #define OP_Param 142
12850 #define OP_FkCounter 143 /* synopsis: fkctr[P1]+=P2 */
12851 #define OP_MemMax 144 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12852 #define OP_OffsetLimit 145 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12853 #define OP_AggStep0 146 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12854 #define OP_AggStep 147 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12855 #define OP_AggFinal 148 /* synopsis: accum=r[P1] N=P2 */
12856 #define OP_Expire 149
12857 #define OP_TableLock 150 /* synopsis: iDb=P1 root=P2 write=P3 */
12858 #define OP_VBegin 151
12859 #define OP_VCreate 152
12860 #define OP_VDestroy 153
12861 #define OP_VOpen 154
12862 #define OP_VColumn 155 /* synopsis: r[P3]=vcolumn(P2) */
12863 #define OP_VRename 156
12864 #define OP_Pagecount 157
12865 #define OP_MaxPgcnt 158
12866 #define OP_CursorHint 159
12867 #define OP_Noop 160
12868 #define OP_Explain 161
 
 
12869
12870 /* Properties such as "out2" or "jump" that are specified in
12871 ** comments following the "case" for each opcode in the vdbe.c
12872 ** are encoded into bitvectors as follows:
12873 */
@@ -12883,32 +12908,32 @@
12883 /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x09,\
12884 /* 24 */ 0x09, 0x09, 0x09, 0x26, 0x26, 0x09, 0x09, 0x09,\
12885 /* 32 */ 0x09, 0x09, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
12886 /* 40 */ 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26, 0x26,\
12887 /* 48 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x01, 0x12, 0x01,\
12888 /* 56 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x23, 0x0b,\
12889 /* 64 */ 0x01, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01, 0x01,\
12890 /* 72 */ 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10, 0x10,\
12891 /* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00,\
12892 /* 88 */ 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\
12893 /* 96 */ 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
12894 /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12895 /* 112 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
12896 /* 120 */ 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00, 0x00,\
12897 /* 128 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00,\
12898 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00,\
12899 /* 144 */ 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12900 /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
12901 /* 160 */ 0x00, 0x00,}
12902
12903 /* The sqlite3P2Values() routine is able to run faster if it knows
12904 ** the value of the largest JUMP opcode. The smaller the maximum
12905 ** JUMP opcode the better, so the mkopcodeh.tcl script that
12906 ** generated this include file strives to group all JUMP opcodes
12907 ** together near the beginning of the list.
12908 */
12909 #define SQLITE_MX_JUMP_OPCODE 71 /* Maximum JUMP opcode */
12910
12911 /************** End of opcodes.h *********************************************/
12912 /************** Continuing where we left off in vdbe.h ***********************/
12913
12914 /*
@@ -13868,11 +13893,11 @@
13868 ** The "PRAGMA synchronous" statement also uses the zero-based numbers.
13869 ** In other words, the zero-based numbers are used for all external interfaces
13870 ** and the one-based values are used internally.
13871 */
13872 #ifndef SQLITE_DEFAULT_SYNCHRONOUS
13873 # define SQLITE_DEFAULT_SYNCHRONOUS (PAGER_SYNCHRONOUS_FULL-1)
13874 #endif
13875 #ifndef SQLITE_DEFAULT_WAL_SYNCHRONOUS
13876 # define SQLITE_DEFAULT_WAL_SYNCHRONOUS SQLITE_DEFAULT_SYNCHRONOUS
13877 #endif
13878
@@ -14074,10 +14099,11 @@
14074 u8 suppressErr; /* Do not issue error messages if true */
14075 u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */
14076 u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */
14077 u8 mTrace; /* zero or more SQLITE_TRACE flags */
14078 u8 skipBtreeMutex; /* True if no shared-cache backends */
 
14079 int nextPagesize; /* Pagesize after VACUUM if >0 */
14080 u32 magic; /* Magic number for detect library misuse */
14081 int nChange; /* Value returned by sqlite3_changes() */
14082 int nTotalChange; /* Value returned by sqlite3_total_changes() */
14083 int aLimit[SQLITE_N_LIMIT]; /* Limits */
@@ -14589,18 +14615,18 @@
14589 char *zColAff; /* String defining the affinity of each column */
14590 ExprList *pCheck; /* All CHECK constraints */
14591 /* ... also used as column name list in a VIEW */
14592 int tnum; /* Root BTree page for this table */
14593 u32 nTabRef; /* Number of pointers to this Table */
 
14594 i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
14595 i16 nCol; /* Number of columns in this table */
14596 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
14597 LogEst szTabRow; /* Estimated size of each table row in bytes */
14598 #ifdef SQLITE_ENABLE_COSTMULT
14599 LogEst costMult; /* Cost multiplier for using this table */
14600 #endif
14601 u8 tabFlags; /* Mask of TF_* values */
14602 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
14603 #ifndef SQLITE_OMIT_ALTERTABLE
14604 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
14605 #endif
14606 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -14620,27 +14646,29 @@
14620 ** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING
14621 ** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden,
14622 ** the TF_OOOHidden attribute would apply in this case. Such tables require
14623 ** special handling during INSERT processing.
14624 */
14625 #define TF_Readonly 0x01 /* Read-only system table */
14626 #define TF_Ephemeral 0x02 /* An ephemeral table */
14627 #define TF_HasPrimaryKey 0x04 /* Table has a primary key */
14628 #define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
14629 #define TF_Virtual 0x10 /* Is a virtual table */
14630 #define TF_WithoutRowid 0x20 /* No rowid. PRIMARY KEY is the key */
14631 #define TF_NoVisibleRowid 0x40 /* No user-visible "rowid" column */
14632 #define TF_OOOHidden 0x80 /* Out-of-Order hidden columns */
14633
 
 
14634
14635 /*
14636 ** Test to see whether or not a table is a virtual table. This is
14637 ** done as a macro so that it will be optimized out when virtual
14638 ** table support is omitted from the build.
14639 */
14640 #ifndef SQLITE_OMIT_VIRTUALTABLE
14641 # define IsVirtual(X) (((X)->tabFlags & TF_Virtual)!=0)
14642 #else
14643 # define IsVirtual(X) 0
14644 #endif
14645
14646 /*
@@ -14871,10 +14899,11 @@
14871 unsigned bUnordered:1; /* Use this index for == or IN queries only */
14872 unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */
14873 unsigned isResized:1; /* True if resizeIndexObject() has been called */
14874 unsigned isCovering:1; /* True if this is a covering index */
14875 unsigned noSkipScan:1; /* Do not try to use skip-scan if true */
 
14876 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
14877 int nSample; /* Number of elements in aSample[] */
14878 int nSampleCol; /* Size of IndexSample.anEq[] and so on */
14879 tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
14880 IndexSample *aSample; /* Samples of the left-most key */
@@ -15181,11 +15210,11 @@
15181 ** form is used for name resolution with nested FROM clauses.
15182 */
15183 struct ExprList {
15184 int nExpr; /* Number of expressions on the list */
15185 struct ExprList_item { /* For each expression in the list */
15186 Expr *pExpr; /* The list of expressions */
15187 char *zName; /* Token associated with this expression */
15188 char *zSpan; /* Original text of the expression */
15189 u8 sortOrder; /* 1 for DESC or 0 for ASC */
15190 unsigned done :1; /* A flag to indicate when processing is finished */
15191 unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
@@ -16504,10 +16533,11 @@
16504 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
16505 SQLITE_PRIVATE void sqlite3Vacuum(Parse*,Token*);
16506 SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*, int);
16507 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
16508 SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*, int);
 
16509 SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
16510 SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Expr*, Expr*, int);
16511 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
16512 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
16513 SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
@@ -17450,19 +17480,25 @@
17450 "COMPILER=gcc-" __VERSION__,
17451 #endif
17452 #if SQLITE_COVERAGE_TEST
17453 "COVERAGE_TEST",
17454 #endif
17455 #if SQLITE_DEBUG
17456 "DEBUG",
17457 #endif
17458 #if SQLITE_DEFAULT_LOCKING_MODE
17459 "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE),
17460 #endif
17461 #if defined(SQLITE_DEFAULT_MMAP_SIZE) && !defined(SQLITE_DEFAULT_MMAP_SIZE_xc)
17462 "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE),
17463 #endif
 
 
 
 
 
 
17464 #if SQLITE_DIRECT_OVERFLOW_READ
17465 "DIRECT_OVERFLOW_READ",
17466 #endif
17467 #if SQLITE_DISABLE_DIRSYNC
17468 "DISABLE_DIRSYNC",
@@ -18035,10 +18071,11 @@
18035 VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */
18036 Op *aOp; /* Program instructions for parent frame */
18037 i64 *anExec; /* Event counters from parent frame */
18038 Mem *aMem; /* Array of memory cells for parent frame */
18039 VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */
 
18040 void *token; /* Copy of SubProgram.token */
18041 i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
18042 AuxData *pAuxData; /* Linked list of auxdata allocations */
18043 int nCursor; /* Number of entries in apCsr */
18044 int pc; /* Program Counter in parent (calling) frame */
@@ -19505,22 +19542,23 @@
19505 **
19506 ** Move the date backwards to the beginning of the current day,
19507 ** or month or year.
19508 */
19509 if( sqlite3_strnicmp(z, "start of ", 9)!=0 ) break;
 
19510 z += 9;
19511 computeYMD(p);
19512 p->validHMS = 1;
19513 p->h = p->m = 0;
19514 p->s = 0.0;
 
19515 p->validTZ = 0;
19516 p->validJD = 0;
19517 if( sqlite3_stricmp(z,"month")==0 ){
19518 p->D = 1;
19519 rc = 0;
19520 }else if( sqlite3_stricmp(z,"year")==0 ){
19521 computeYMD(p);
19522 p->M = 1;
19523 p->D = 1;
19524 rc = 0;
19525 }else if( sqlite3_stricmp(z,"day")==0 ){
19526 rc = 0;
@@ -20638,11 +20676,13 @@
20638 ** Use the zone allocator available on apple products unless the
20639 ** SQLITE_WITHOUT_ZONEMALLOC symbol is defined.
20640 */
20641 #include <sys/sysctl.h>
20642 #include <malloc/malloc.h>
 
20643 #include <libkern/OSAtomic.h>
 
20644 static malloc_zone_t* _sqliteZone_;
20645 #define SQLITE_MALLOC(x) malloc_zone_malloc(_sqliteZone_, (x))
20646 #define SQLITE_FREE(x) malloc_zone_free(_sqliteZone_, (x));
20647 #define SQLITE_REALLOC(x,y) malloc_zone_realloc(_sqliteZone_, (x), (y))
20648 #define SQLITE_MALLOCSIZE(x) \
@@ -20831,23 +20871,14 @@
20831 /* defer MT decisions to system malloc */
20832 _sqliteZone_ = malloc_default_zone();
20833 }else{
20834 /* only 1 core, use our own zone to contention over global locks,
20835 ** e.g. we have our own dedicated locks */
20836 bool success;
20837 malloc_zone_t* newzone = malloc_create_zone(4096, 0);
20838 malloc_set_zone_name(newzone, "Sqlite_Heap");
20839 do{
20840 success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone,
20841 (void * volatile *)&_sqliteZone_);
20842 }while(!_sqliteZone_);
20843 if( !success ){
20844 /* somebody registered a zone first */
20845 malloc_destroy_zone(newzone);
20846 }
20847 }
20848 #endif
20849 UNUSED_PARAMETER(NotUsed);
20850 return SQLITE_OK;
20851 }
20852
20853 /*
@@ -24050,12 +24081,12 @@
24050 #ifdef SQLITE_DEBUG
24051 assert( p->nRef>0 || p->owner==0 );
24052 p->owner = tid;
24053 p->nRef++;
24054 if( p->trace ){
24055 OSTRACE(("ENTER-MUTEX tid=%lu, mutex=%p (%d), nRef=%d\n",
24056 tid, p, p->trace, p->nRef));
24057 }
24058 #endif
24059 }
24060
24061 static int winMutexTry(sqlite3_mutex *p){
@@ -24093,12 +24124,12 @@
24093 #else
24094 UNUSED_PARAMETER(p);
24095 #endif
24096 #ifdef SQLITE_DEBUG
24097 if( p->trace ){
24098 OSTRACE(("TRY-MUTEX tid=%lu, mutex=%p (%d), owner=%lu, nRef=%d, rc=%s\n",
24099 tid, p, p->trace, p->owner, p->nRef, sqlite3ErrName(rc)));
24100 }
24101 #endif
24102 return rc;
24103 }
24104
@@ -24122,12 +24153,12 @@
24122 #endif
24123 assert( winMutex_isInit==1 );
24124 LeaveCriticalSection(&p->mutex);
24125 #ifdef SQLITE_DEBUG
24126 if( p->trace ){
24127 OSTRACE(("LEAVE-MUTEX tid=%lu, mutex=%p (%d), nRef=%d\n",
24128 tid, p, p->trace, p->nRef));
24129 }
24130 #endif
24131 }
24132
24133 SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void){
@@ -24383,10 +24414,17 @@
24383 ** implementation of malloc_good_size(), which must be called in debug
24384 ** mode and specifically when the DMD "Dark Matter Detector" is enabled
24385 ** or else a crash results. Hence, do not attempt to optimize out the
24386 ** following xRoundup() call. */
24387 nFull = sqlite3GlobalConfig.m.xRoundup(n);
 
 
 
 
 
 
 
24388
24389 sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n);
24390 if( mem0.alarmThreshold>0 ){
24391 sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
24392 if( nUsed >= mem0.alarmThreshold - nFull ){
@@ -24572,11 +24610,11 @@
24572 return sqlite3GlobalConfig.m.xSize(p);
24573 }
24574 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
24575 assert( p!=0 );
24576 if( db==0 || !isLookaside(db,p) ){
24577 #if SQLITE_DEBUG
24578 if( db==0 ){
24579 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
24580 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
24581 }else{
24582 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
@@ -24633,11 +24671,11 @@
24633 measureAllocationSize(db, p);
24634 return;
24635 }
24636 if( isLookaside(db, p) ){
24637 LookasideSlot *pBuf = (LookasideSlot*)p;
24638 #if SQLITE_DEBUG
24639 /* Trash all content in the buffer being freed */
24640 memset(p, 0xaa, db->lookaside.sz);
24641 #endif
24642 pBuf->pNext = db->lookaside.pFree;
24643 db->lookaside.pFree = pBuf;
@@ -25002,11 +25040,11 @@
25002
25003 /*
25004 ** Conversion types fall into various categories as defined by the
25005 ** following enumeration.
25006 */
25007 #define etRADIX 0 /* Integer types. %d, %x, %o, and so forth */
25008 #define etFLOAT 1 /* Floating point. %f */
25009 #define etEXP 2 /* Exponentional notation. %e and %E */
25010 #define etGENERIC 3 /* Floating or exponential, depending on exponent. %g */
25011 #define etSIZE 4 /* Return number of characters processed so far. %n */
25012 #define etSTRING 5 /* Strings. %s */
@@ -25020,12 +25058,13 @@
25020 #define etTOKEN 11 /* a pointer to a Token structure */
25021 #define etSRCLIST 12 /* a pointer to a SrcList */
25022 #define etPOINTER 13 /* The %p conversion */
25023 #define etSQLESCAPE3 14 /* %w -> Strings with '\"' doubled */
25024 #define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */
 
25025
25026 #define etINVALID 16 /* Any unrecognized conversion type */
25027
25028
25029 /*
25030 ** An "etByte" is an 8-bit unsigned value.
25031 */
@@ -25045,40 +25084,40 @@
25045 } et_info;
25046
25047 /*
25048 ** Allowed values for et_info.flags
25049 */
25050 #define FLAG_SIGNED 1 /* True if the value to convert is signed */
25051 #define FLAG_STRING 4 /* Allow infinity precision */
25052
25053
25054 /*
25055 ** The following table is searched linearly, so it is good to put the
25056 ** most frequently used conversion types first.
25057 */
25058 static const char aDigits[] = "0123456789ABCDEF0123456789abcdef";
25059 static const char aPrefix[] = "-x0\000X0";
25060 static const et_info fmtinfo[] = {
25061 { 'd', 10, 1, etRADIX, 0, 0 },
25062 { 's', 0, 4, etSTRING, 0, 0 },
25063 { 'g', 0, 1, etGENERIC, 30, 0 },
25064 { 'z', 0, 4, etDYNSTRING, 0, 0 },
25065 { 'q', 0, 4, etSQLESCAPE, 0, 0 },
25066 { 'Q', 0, 4, etSQLESCAPE2, 0, 0 },
25067 { 'w', 0, 4, etSQLESCAPE3, 0, 0 },
25068 { 'c', 0, 0, etCHARX, 0, 0 },
25069 { 'o', 8, 0, etRADIX, 0, 2 },
25070 { 'u', 10, 0, etRADIX, 0, 0 },
25071 { 'x', 16, 0, etRADIX, 16, 1 },
25072 { 'X', 16, 0, etRADIX, 0, 4 },
25073 #ifndef SQLITE_OMIT_FLOATING_POINT
25074 { 'f', 0, 1, etFLOAT, 0, 0 },
25075 { 'e', 0, 1, etEXP, 30, 0 },
25076 { 'E', 0, 1, etEXP, 14, 0 },
25077 { 'G', 0, 1, etGENERIC, 14, 0 },
25078 #endif
25079 { 'i', 10, 1, etRADIX, 0, 0 },
25080 { 'n', 0, 0, etSIZE, 0, 0 },
25081 { '%', 0, 0, etPERCENT, 0, 0 },
25082 { 'p', 16, 0, etPOINTER, 0, 1 },
25083
25084 /* All the rest are undocumented and are for internal use only */
@@ -25166,18 +25205,17 @@
25166 int precision; /* Precision of the current field */
25167 int length; /* Length of the field */
25168 int idx; /* A general purpose loop counter */
25169 int width; /* Width of the current field */
25170 etByte flag_leftjustify; /* True if "-" flag is present */
25171 etByte flag_plussign; /* True if "+" flag is present */
25172 etByte flag_blanksign; /* True if " " flag is present */
25173 etByte flag_alternateform; /* True if "#" flag is present */
25174 etByte flag_altform2; /* True if "!" flag is present */
25175 etByte flag_zeropad; /* True if field width constant starts with zero */
25176 etByte flag_long; /* True if "l" flag is present */
25177 etByte flag_longlong; /* True if the "ll" flag is present */
25178 etByte done; /* Loop termination flag */
 
25179 etByte xtype = etINVALID; /* Conversion paradigm */
25180 u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */
25181 char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
25182 sqlite_uint64 longvalue; /* Value for integer types */
25183 LONGDOUBLE_TYPE realvalue; /* Value for real types */
@@ -25216,21 +25254,22 @@
25216 if( (c=(*++fmt))==0 ){
25217 sqlite3StrAccumAppend(pAccum, "%", 1);
25218 break;
25219 }
25220 /* Find out what flags are present */
25221 flag_leftjustify = flag_plussign = flag_blanksign =
25222 flag_alternateform = flag_altform2 = flag_zeropad = 0;
25223 done = 0;
25224 do{
25225 switch( c ){
25226 case '-': flag_leftjustify = 1; break;
25227 case '+': flag_plussign = 1; break;
25228 case ' ': flag_blanksign = 1; break;
25229 case '#': flag_alternateform = 1; break;
25230 case '!': flag_altform2 = 1; break;
25231 case '0': flag_zeropad = 1; break;
 
25232 default: done = 1; break;
25233 }
25234 }while( !done && (c=(*++fmt))!=0 );
25235 /* Get the field width */
25236 if( c=='*' ){
@@ -25296,17 +25335,15 @@
25296 /* Get the conversion type modifier */
25297 if( c=='l' ){
25298 flag_long = 1;
25299 c = *++fmt;
25300 if( c=='l' ){
25301 flag_longlong = 1;
25302 c = *++fmt;
25303 }else{
25304 flag_longlong = 0;
25305 }
25306 }else{
25307 flag_long = flag_longlong = 0;
25308 }
25309 /* Fetch the info entry for the field */
25310 infop = &fmtinfo[0];
25311 xtype = etINVALID;
25312 for(idx=0; idx<ArraySize(fmtinfo); idx++){
@@ -25320,41 +25357,42 @@
25320 /*
25321 ** At this point, variables are initialized as follows:
25322 **
25323 ** flag_alternateform TRUE if a '#' is present.
25324 ** flag_altform2 TRUE if a '!' is present.
25325 ** flag_plussign TRUE if a '+' is present.
25326 ** flag_leftjustify TRUE if a '-' is present or if the
25327 ** field width was negative.
25328 ** flag_zeropad TRUE if the width began with 0.
25329 ** flag_long TRUE if the letter 'l' (ell) prefixed
25330 ** the conversion character.
25331 ** flag_longlong TRUE if the letter 'll' (ell ell) prefixed
25332 ** the conversion character.
25333 ** flag_blanksign TRUE if a ' ' is present.
25334 ** width The specified field width. This is
25335 ** always non-negative. Zero is the default.
25336 ** precision The specified precision. The default
25337 ** is -1.
25338 ** xtype The class of the conversion.
25339 ** infop Pointer to the appropriate info struct.
25340 */
25341 switch( xtype ){
25342 case etPOINTER:
25343 flag_longlong = sizeof(char*)==sizeof(i64);
25344 flag_long = sizeof(char*)==sizeof(long int);
25345 /* Fall through into the next case */
25346 case etORDINAL:
25347 case etRADIX:
 
 
 
25348 if( infop->flags & FLAG_SIGNED ){
25349 i64 v;
25350 if( bArgList ){
25351 v = getIntArg(pArgList);
25352 }else if( flag_longlong ){
25353 v = va_arg(ap,i64);
25354 }else if( flag_long ){
25355 v = va_arg(ap,long int);
 
 
 
 
25356 }else{
25357 v = va_arg(ap,int);
25358 }
25359 if( v<0 ){
25360 if( v==SMALLEST_INT64 ){
@@ -25363,40 +25401,41 @@
25363 longvalue = -v;
25364 }
25365 prefix = '-';
25366 }else{
25367 longvalue = v;
25368 if( flag_plussign ) prefix = '+';
25369 else if( flag_blanksign ) prefix = ' ';
25370 else prefix = 0;
25371 }
25372 }else{
25373 if( bArgList ){
25374 longvalue = (u64)getIntArg(pArgList);
25375 }else if( flag_longlong ){
25376 longvalue = va_arg(ap,u64);
25377 }else if( flag_long ){
25378 longvalue = va_arg(ap,unsigned long int);
 
 
 
 
25379 }else{
25380 longvalue = va_arg(ap,unsigned int);
25381 }
25382 prefix = 0;
25383 }
25384 if( longvalue==0 ) flag_alternateform = 0;
25385 if( flag_zeropad && precision<width-(prefix!=0) ){
25386 precision = width-(prefix!=0);
25387 }
25388 if( precision<etBUFSIZE-10 ){
25389 nOut = etBUFSIZE;
25390 zOut = buf;
25391 }else{
25392 nOut = precision + 10;
25393 zOut = zExtra = sqlite3Malloc( nOut );
25394 if( zOut==0 ){
25395 setStrAccumError(pAccum, STRACCUM_NOMEM);
25396 return;
25397 }
 
25398 }
25399 bufpt = &zOut[nOut-1];
25400 if( xtype==etORDINAL ){
25401 static const char zOrd[] = "thstndrd";
25402 int x = (int)(longvalue % 10);
@@ -25413,12 +25452,27 @@
25413 *(--bufpt) = cset[longvalue%base];
25414 longvalue = longvalue/base;
25415 }while( longvalue>0 );
25416 }
25417 length = (int)(&zOut[nOut-1]-bufpt);
25418 for(idx=precision-length; idx>0; idx--){
25419 *(--bufpt) = '0'; /* Zero pad */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25420 }
25421 if( prefix ) *(--bufpt) = prefix; /* Add sign */
25422 if( flag_alternateform && infop->prefix ){ /* Add "0" or "0x" */
25423 const char *pre;
25424 char x;
@@ -25441,13 +25495,11 @@
25441 if( precision<0 ) precision = 6; /* Set default precision */
25442 if( realvalue<0.0 ){
25443 realvalue = -realvalue;
25444 prefix = '-';
25445 }else{
25446 if( flag_plussign ) prefix = '+';
25447 else if( flag_blanksign ) prefix = ' ';
25448 else prefix = 0;
25449 }
25450 if( xtype==etGENERIC && precision>0 ) precision--;
25451 testcase( precision>0xfff );
25452 for(idx=precision&0xfff, rounder=0.5; idx>0; idx--, rounder*=0.1){}
25453 if( xtype==etFLOAT ) realvalue += rounder;
@@ -26215,10 +26267,14 @@
26215 ** Generate a human-readable description of a Select object.
26216 */
26217 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
26218 int n = 0;
26219 int cnt = 0;
 
 
 
 
26220 pView = sqlite3TreeViewPush(pView, moreToFollow);
26221 if( p->pWith ){
26222 sqlite3TreeViewWith(pView, p->pWith, 1);
26223 cnt = 1;
26224 sqlite3TreeViewPush(pView, 1);
@@ -29464,117 +29520,119 @@
29464 /* 50 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
29465 /* 51 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
29466 /* 52 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
29467 /* 53 */ "Last" OpHelp(""),
29468 /* 54 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
29469 /* 55 */ "SorterSort" OpHelp(""),
29470 /* 56 */ "Sort" OpHelp(""),
29471 /* 57 */ "Rewind" OpHelp(""),
29472 /* 58 */ "IdxLE" OpHelp("key=r[P3@P4]"),
29473 /* 59 */ "IdxGT" OpHelp("key=r[P3@P4]"),
29474 /* 60 */ "IdxLT" OpHelp("key=r[P3@P4]"),
29475 /* 61 */ "IdxGE" OpHelp("key=r[P3@P4]"),
29476 /* 62 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
29477 /* 63 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
29478 /* 64 */ "Program" OpHelp(""),
29479 /* 65 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
29480 /* 66 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
29481 /* 67 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
29482 /* 68 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
29483 /* 69 */ "IncrVacuum" OpHelp(""),
29484 /* 70 */ "VNext" OpHelp(""),
29485 /* 71 */ "Init" OpHelp("Start at P2"),
29486 /* 72 */ "Return" OpHelp(""),
29487 /* 73 */ "EndCoroutine" OpHelp(""),
29488 /* 74 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
29489 /* 75 */ "Halt" OpHelp(""),
29490 /* 76 */ "Integer" OpHelp("r[P2]=P1"),
29491 /* 77 */ "Int64" OpHelp("r[P2]=P4"),
29492 /* 78 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
29493 /* 79 */ "Null" OpHelp("r[P2..P3]=NULL"),
29494 /* 80 */ "SoftNull" OpHelp("r[P1]=NULL"),
29495 /* 81 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
29496 /* 82 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
29497 /* 83 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
29498 /* 84 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
29499 /* 85 */ "SCopy" OpHelp("r[P2]=r[P1]"),
29500 /* 86 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
29501 /* 87 */ "ResultRow" OpHelp("output=r[P1@P2]"),
29502 /* 88 */ "CollSeq" OpHelp(""),
29503 /* 89 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
29504 /* 90 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
29505 /* 91 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
29506 /* 92 */ "RealAffinity" OpHelp(""),
29507 /* 93 */ "Cast" OpHelp("affinity(r[P1])"),
29508 /* 94 */ "Permutation" OpHelp(""),
29509 /* 95 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
29510 /* 96 */ "Column" OpHelp("r[P3]=PX"),
29511 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
29512 /* 98 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
29513 /* 99 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
29514 /* 100 */ "Count" OpHelp("r[P2]=count()"),
29515 /* 101 */ "ReadCookie" OpHelp(""),
29516 /* 102 */ "SetCookie" OpHelp(""),
29517 /* 103 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
29518 /* 104 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
29519 /* 105 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
29520 /* 106 */ "OpenAutoindex" OpHelp("nColumn=P2"),
29521 /* 107 */ "OpenEphemeral" OpHelp("nColumn=P2"),
29522 /* 108 */ "SorterOpen" OpHelp(""),
29523 /* 109 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
29524 /* 110 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
29525 /* 111 */ "Close" OpHelp(""),
29526 /* 112 */ "ColumnsUsed" OpHelp(""),
29527 /* 113 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
29528 /* 114 */ "NewRowid" OpHelp("r[P2]=rowid"),
29529 /* 115 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
29530 /* 116 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
29531 /* 117 */ "Delete" OpHelp(""),
29532 /* 118 */ "ResetCount" OpHelp(""),
29533 /* 119 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
29534 /* 120 */ "SorterData" OpHelp("r[P2]=data"),
29535 /* 121 */ "RowData" OpHelp("r[P2]=data"),
29536 /* 122 */ "Rowid" OpHelp("r[P2]=rowid"),
29537 /* 123 */ "NullRow" OpHelp(""),
29538 /* 124 */ "SorterInsert" OpHelp("key=r[P2]"),
29539 /* 125 */ "IdxInsert" OpHelp("key=r[P2]"),
29540 /* 126 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
29541 /* 127 */ "Seek" OpHelp("Move P3 to P1.rowid"),
29542 /* 128 */ "IdxRowid" OpHelp("r[P2]=rowid"),
29543 /* 129 */ "Destroy" OpHelp(""),
29544 /* 130 */ "Clear" OpHelp(""),
29545 /* 131 */ "ResetSorter" OpHelp(""),
29546 /* 132 */ "Real" OpHelp("r[P2]=P4"),
29547 /* 133 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
29548 /* 134 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
29549 /* 135 */ "ParseSchema" OpHelp(""),
29550 /* 136 */ "LoadAnalysis" OpHelp(""),
29551 /* 137 */ "DropTable" OpHelp(""),
29552 /* 138 */ "DropIndex" OpHelp(""),
29553 /* 139 */ "DropTrigger" OpHelp(""),
29554 /* 140 */ "IntegrityCk" OpHelp(""),
29555 /* 141 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
29556 /* 142 */ "Param" OpHelp(""),
29557 /* 143 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
29558 /* 144 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
29559 /* 145 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
29560 /* 146 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
29561 /* 147 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
29562 /* 148 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
29563 /* 149 */ "Expire" OpHelp(""),
29564 /* 150 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
29565 /* 151 */ "VBegin" OpHelp(""),
29566 /* 152 */ "VCreate" OpHelp(""),
29567 /* 153 */ "VDestroy" OpHelp(""),
29568 /* 154 */ "VOpen" OpHelp(""),
29569 /* 155 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
29570 /* 156 */ "VRename" OpHelp(""),
29571 /* 157 */ "Pagecount" OpHelp(""),
29572 /* 158 */ "MaxPgcnt" OpHelp(""),
29573 /* 159 */ "CursorHint" OpHelp(""),
29574 /* 160 */ "Noop" OpHelp(""),
29575 /* 161 */ "Explain" OpHelp(""),
 
 
29576 };
29577 return azName[i];
29578 }
29579 #endif
29580
@@ -37952,46 +38010,84 @@
37952 * be freed immediately and any attempt to access any of that freed
37953 * data will almost certainly result in an immediate access violation.
37954 ******************************************************************************
37955 */
37956 #ifndef SQLITE_WIN32_HEAP_CREATE
37957 # define SQLITE_WIN32_HEAP_CREATE (TRUE)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37958 #endif
37959
37960 /*
37961 * This is cache size used in the calculation of the initial size of the
37962 * Win32-specific heap. It cannot be negative.
37963 */
37964 #ifndef SQLITE_WIN32_CACHE_SIZE
37965 # if SQLITE_DEFAULT_CACHE_SIZE>=0
37966 # define SQLITE_WIN32_CACHE_SIZE (SQLITE_DEFAULT_CACHE_SIZE)
37967 # else
37968 # define SQLITE_WIN32_CACHE_SIZE (-(SQLITE_DEFAULT_CACHE_SIZE))
37969 # endif
37970 #endif
37971
 
 
 
 
 
 
 
 
 
 
37972 /*
37973 * The initial size of the Win32-specific heap. This value may be zero.
37974 */
37975 #ifndef SQLITE_WIN32_HEAP_INIT_SIZE
37976 # define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_WIN32_CACHE_SIZE) * \
37977 (SQLITE_DEFAULT_PAGE_SIZE) + 4194304)
 
37978 #endif
37979
37980 /*
37981 * The maximum size of the Win32-specific heap. This value may be zero.
37982 */
37983 #ifndef SQLITE_WIN32_HEAP_MAX_SIZE
37984 # define SQLITE_WIN32_HEAP_MAX_SIZE (0)
37985 #endif
37986
37987 /*
37988 * The extra flags to use in calls to the Win32 heap APIs. This value may be
37989 * zero for the default behavior.
37990 */
37991 #ifndef SQLITE_WIN32_HEAP_FLAGS
37992 # define SQLITE_WIN32_HEAP_FLAGS (0)
37993 #endif
37994
37995
37996 /*
37997 ** The winMemData structure stores information required by the Win32-specific
@@ -44084,11 +44180,11 @@
44084 ** This routine is for use inside of assert() statements only. For
44085 ** example:
44086 **
44087 ** assert( sqlite3PcachePageSanity(pPg) );
44088 */
44089 #if SQLITE_DEBUG
44090 SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr *pPg){
44091 PCache *pCache;
44092 assert( pPg!=0 );
44093 assert( pPg->pgno>0 || pPg->pPager==0 ); /* Page number is 1 or more */
44094 pCache = pPg->pCache;
@@ -60177,21 +60273,22 @@
60177 }
60178 #endif
60179
60180
60181 /*
60182 ** Defragment the page given. All Cells are moved to the
60183 ** end of the page and all free space is collected into one
60184 ** big FreeBlk that occurs in between the header and cell
60185 ** pointer array and the cell content area.
 
60186 **
60187 ** EVIDENCE-OF: R-44582-60138 SQLite may from time to time reorganize a
60188 ** b-tree page so that there are no freeblocks or fragment bytes, all
60189 ** unused bytes are contained in the unallocated space region, and all
60190 ** cells are packed tightly at the end of the page.
60191 */
60192 static int defragmentPage(MemPage *pPage){
60193 int i; /* Loop counter */
60194 int pc; /* Address of the i-th cell */
60195 int hdr; /* Offset to the page header */
60196 int size; /* Size of a cell */
60197 int usableSize; /* Number of usable bytes on a page */
@@ -60202,11 +60299,10 @@
60202 unsigned char *temp; /* Temp area for cell content */
60203 unsigned char *src; /* Source of content */
60204 int iCellFirst; /* First allowable cell index */
60205 int iCellLast; /* Last possible cell index */
60206
60207
60208 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
60209 assert( pPage->pBt!=0 );
60210 assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
60211 assert( pPage->nOverflow==0 );
60212 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
@@ -60214,13 +60310,60 @@
60214 src = data = pPage->aData;
60215 hdr = pPage->hdrOffset;
60216 cellOffset = pPage->cellOffset;
60217 nCell = pPage->nCell;
60218 assert( nCell==get2byte(&data[hdr+3]) );
 
60219 usableSize = pPage->pBt->usableSize;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60220 cbrk = usableSize;
60221 iCellFirst = cellOffset + 2*nCell;
60222 iCellLast = usableSize - 4;
60223 for(i=0; i<nCell; i++){
60224 u8 *pAddr; /* The i-th cell pointer */
60225 pAddr = &data[cellOffset + i*2];
60226 pc = get2byte(pAddr);
@@ -60250,20 +60393,22 @@
60250 memcpy(&temp[x], &data[x], (cbrk+size) - x);
60251 src = temp;
60252 }
60253 memcpy(&data[cbrk], &src[pc], size);
60254 }
 
 
 
 
 
 
60255 assert( cbrk>=iCellFirst );
60256 put2byte(&data[hdr+5], cbrk);
60257 data[hdr+1] = 0;
60258 data[hdr+2] = 0;
60259 data[hdr+7] = 0;
60260 memset(&data[iCellFirst], 0, cbrk-iCellFirst);
60261 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
60262 if( cbrk-iCellFirst!=pPage->nFree ){
60263 return SQLITE_CORRUPT_BKPT;
60264 }
60265 return SQLITE_OK;
60266 }
60267
60268 /*
60269 ** Search the free-list on page pPg for space to store a cell nByte bytes in
@@ -60397,14 +60542,14 @@
60397 ** to see if defragmentation is necessary.
60398 */
60399 testcase( gap+2+nByte==top );
60400 if( gap+2+nByte>top ){
60401 assert( pPage->nCell>0 || CORRUPT_DB );
60402 rc = defragmentPage(pPage);
60403 if( rc ) return rc;
60404 top = get2byteNotZero(&data[hdr+5]);
60405 assert( gap+nByte<=top );
60406 }
60407
60408
60409 /* Allocate memory from the gap in between the cell pointer array
60410 ** and the cell content area. The btreeInitPage() call has already
@@ -61672,10 +61817,35 @@
61672 sqlite3BtreeLeave(p);
61673 return rc;
61674 #endif
61675 }
61676
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61677
61678 /*
61679 ** Get a reference to pPage1 of the database file. This will
61680 ** also acquire a readlock on that file.
61681 **
@@ -61745,30 +61915,19 @@
61745 int isOpen = 0;
61746 rc = sqlite3PagerOpenWal(pBt->pPager, &isOpen);
61747 if( rc!=SQLITE_OK ){
61748 goto page1_init_failed;
61749 }else{
61750 #if SQLITE_DEFAULT_SYNCHRONOUS!=SQLITE_DEFAULT_WAL_SYNCHRONOUS
61751 sqlite3 *db;
61752 Db *pDb;
61753 if( (db=pBt->db)!=0 && (pDb=db->aDb)!=0 ){
61754 while( pDb->pBt==0 || pDb->pBt->pBt!=pBt ){ pDb++; }
61755 if( pDb->bSyncSet==0
61756 && pDb->safety_level==SQLITE_DEFAULT_SYNCHRONOUS+1
61757 ){
61758 pDb->safety_level = SQLITE_DEFAULT_WAL_SYNCHRONOUS+1;
61759 sqlite3PagerSetFlags(pBt->pPager,
61760 pDb->safety_level | (db->flags & PAGER_FLAGS_MASK));
61761 }
61762 }
61763 #endif
61764 if( isOpen==0 ){
61765 releasePage(pPage1);
61766 return SQLITE_OK;
61767 }
61768 }
61769 rc = SQLITE_NOTADB;
 
 
61770 }
61771 #endif
61772
61773 /* EVIDENCE-OF: R-15465-20813 The maximum and minimum embedded payload
61774 ** fractions and the leaf payload fraction values must be 64, 32, and 32.
@@ -63636,11 +63795,11 @@
63636 pCur->aiIdx[pCur->iPage] = 0;
63637 return getAndInitPage(pBt, newPgno, &pCur->apPage[pCur->iPage],
63638 pCur, pCur->curPagerFlags);
63639 }
63640
63641 #if SQLITE_DEBUG
63642 /*
63643 ** Page pParent is an internal (non-leaf) tree page. This function
63644 ** asserts that page number iChild is the left-child if the iIdx'th
63645 ** cell in page pParent. Or, if iIdx is equal to the total number of
63646 ** cells in pParent, that page number iChild is the right-child of
@@ -64178,10 +64337,34 @@
64178 ** have been deleted? This API will need to change to return an error code
64179 ** as well as the boolean result value.
64180 */
64181 return (CURSOR_VALID!=pCur->eState);
64182 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64183
64184 /*
64185 ** Advance the cursor to the next entry in the database. If
64186 ** successful then set *pRes=0. If the cursor
64187 ** was already pointing to the last entry in the database before
@@ -65023,11 +65206,11 @@
65023 ** pPrior Where to write the pgno of the first overflow page
65024 **
65025 ** Use a call to btreeParseCellPtr() to verify that the values above
65026 ** were computed correctly.
65027 */
65028 #if SQLITE_DEBUG
65029 {
65030 CellInfo info;
65031 pPage->xParseCell(pPage, pCell, &info);
65032 assert( nHeader==(int)(info.pPayload - pCell) );
65033 assert( info.nKey==pX->nKey );
@@ -66549,11 +66732,11 @@
66549 ** copied into the parent, because if the parent is page 1 then it will
66550 ** by smaller than the child due to the database header, and so all the
66551 ** free space needs to be up front.
66552 */
66553 assert( nNew==1 || CORRUPT_DB );
66554 rc = defragmentPage(apNew[0]);
66555 testcase( rc!=SQLITE_OK );
66556 assert( apNew[0]->nFree ==
66557 (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2)
66558 || rc!=SQLITE_OK
66559 );
@@ -71201,10 +71384,11 @@
71201 ** Remember the SQL string for a prepared statement.
71202 */
71203 SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe *p, const char *z, int n, int isPrepareV2){
71204 assert( isPrepareV2==1 || isPrepareV2==0 );
71205 if( p==0 ) return;
 
71206 #if defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_ENABLE_SQLLOG)
71207 if( !isPrepareV2 ) return;
71208 #endif
71209 assert( p->zSql==0 );
71210 p->zSql = sqlite3DbStrNDup(p->db, z, n);
@@ -71229,10 +71413,11 @@
71229 pB->pPrev = pTmp;
71230 zTmp = pA->zSql;
71231 pA->zSql = pB->zSql;
71232 pB->zSql = zTmp;
71233 pB->isPrepareV2 = pA->isPrepareV2;
 
71234 }
71235
71236 /*
71237 ** Resize the Vdbe.aOp array so that it is at least nOp elements larger
71238 ** than its current size. nOp is guaranteed to be less than or equal
@@ -71258,10 +71443,16 @@
71258 int nNew = (p->nOpAlloc>=512 ? p->nOpAlloc*2 : p->nOpAlloc+nOp);
71259 #else
71260 int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op)));
71261 UNUSED_PARAMETER(nOp);
71262 #endif
 
 
 
 
 
 
71263
71264 assert( nOp<=(1024/sizeof(Op)) );
71265 assert( nNew>=(p->nOpAlloc+nOp) );
71266 pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
71267 if( pNew ){
@@ -73753,17 +73944,17 @@
73753 ** Then the internal cache might have been left in an inconsistent
73754 ** state. We need to rollback the statement transaction, if there is
73755 ** one, or the complete transaction if there is no statement transaction.
73756 */
73757
 
 
 
73758 if( db->mallocFailed ){
73759 p->rc = SQLITE_NOMEM_BKPT;
73760 }
73761 closeAllCursors(p);
73762 if( p->magic!=VDBE_MAGIC_RUN ){
73763 return SQLITE_OK;
73764 }
73765 checkActiveVdbeCnt(db);
73766
73767 /* No commit or rollback needed if the program never started or if the
73768 ** SQL statement does not read or write a database file. */
73769 if( p->pc>=0 && p->bIsReader ){
@@ -74706,11 +74897,11 @@
74706 }
74707 assert( u<=pKeyInfo->nField + 1 );
74708 p->nField = u;
74709 }
74710
74711 #if SQLITE_DEBUG
74712 /*
74713 ** This function compares two index or table record keys in the same way
74714 ** as the sqlite3VdbeRecordCompare() routine. Unlike VdbeRecordCompare(),
74715 ** this function deserializes and compares values using the
74716 ** sqlite3VdbeSerialGet() and sqlite3MemCompare() functions. It is used
@@ -74811,11 +75002,11 @@
74811 if( pKeyInfo->db->mallocFailed ) return 1;
74812 return 0;
74813 }
74814 #endif
74815
74816 #if SQLITE_DEBUG
74817 /*
74818 ** Count the number of fields (a.k.a. columns) in the record given by
74819 ** pKey,nKey. The verify that this count is less than or equal to the
74820 ** limit given by pKeyInfo->nField + pKeyInfo->nXField.
74821 **
@@ -75694,12 +75885,12 @@
75694 ** to sqlite3_reoptimize() that re-preparing the statement may result
75695 ** in a better query plan.
75696 */
75697 SQLITE_PRIVATE void sqlite3VdbeSetVarmask(Vdbe *v, int iVar){
75698 assert( iVar>0 );
75699 if( iVar>32 ){
75700 v->expmask = 0xffffffff;
75701 }else{
75702 v->expmask |= ((u32)1 << (iVar-1));
75703 }
75704 }
75705
@@ -75965,11 +76156,12 @@
75965 sqlite3_mutex_enter(mutex);
75966 for(i=0; i<p->nVar; i++){
75967 sqlite3VdbeMemRelease(&p->aVar[i]);
75968 p->aVar[i].flags = MEM_Null;
75969 }
75970 if( p->isPrepareV2 && p->expmask ){
 
75971 p->expired = 1;
75972 }
75973 sqlite3_mutex_leave(mutex);
75974 return rc;
75975 }
@@ -77069,13 +77261,12 @@
77069 ** parameter in the WHERE clause might influence the choice of query plan
77070 ** for a statement, then the statement will be automatically recompiled,
77071 ** as if there had been a schema change, on the first sqlite3_step() call
77072 ** following any change to the bindings of that parameter.
77073 */
77074 if( p->isPrepareV2 &&
77075 ((i<32 && p->expmask & ((u32)1 << i)) || p->expmask==0xffffffff)
77076 ){
77077 p->expired = 1;
77078 }
77079 return SQLITE_OK;
77080 }
77081
@@ -77334,14 +77525,16 @@
77334 Vdbe *pFrom = (Vdbe*)pFromStmt;
77335 Vdbe *pTo = (Vdbe*)pToStmt;
77336 if( pFrom->nVar!=pTo->nVar ){
77337 return SQLITE_ERROR;
77338 }
77339 if( pTo->isPrepareV2 && pTo->expmask ){
 
77340 pTo->expired = 1;
77341 }
77342 if( pFrom->isPrepareV2 && pFrom->expmask ){
 
77343 pFrom->expired = 1;
77344 }
77345 return sqlite3TransferBindings(pFromStmt, pToStmt);
77346 }
77347 #endif
@@ -78303,13 +78496,11 @@
78303 c = 'e';
78304 assert( (f & (MEM_Static|MEM_Dyn))==0 );
78305 }else{
78306 c = 's';
78307 }
78308
78309 sqlite3_snprintf(100, zCsr, "%c", c);
78310 zCsr += sqlite3Strlen30(zCsr);
78311 sqlite3_snprintf(100, zCsr, "%d[", pMem->n);
78312 zCsr += sqlite3Strlen30(zCsr);
78313 for(i=0; i<16 && i<pMem->n; i++){
78314 sqlite3_snprintf(100, zCsr, "%02X", ((int)pMem->z[i] & 0xFF));
78315 zCsr += sqlite3Strlen30(zCsr);
@@ -78317,13 +78508,11 @@
78317 for(i=0; i<16 && i<pMem->n; i++){
78318 char z = pMem->z[i];
78319 if( z<32 || z>126 ) *zCsr++ = '.';
78320 else *zCsr++ = z;
78321 }
78322
78323 sqlite3_snprintf(100, zCsr, "]%s", encnames[pMem->enc]);
78324 zCsr += sqlite3Strlen30(zCsr);
78325 if( f & MEM_Zero ){
78326 sqlite3_snprintf(100, zCsr,"+%dz",pMem->u.nZero);
78327 zCsr += sqlite3Strlen30(zCsr);
78328 }
78329 *zCsr = '\0';
@@ -79658,39 +79847,39 @@
79658 if( pCtx->pOut != pOut ){
79659 pCtx->pOut = pOut;
79660 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
79661 }
79662
79663 memAboutToChange(p, pCtx->pOut);
79664 #ifdef SQLITE_DEBUG
79665 for(i=0; i<pCtx->argc; i++){
79666 assert( memIsValid(pCtx->argv[i]) );
79667 REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]);
79668 }
79669 #endif
79670 MemSetTypeFlag(pCtx->pOut, MEM_Null);
79671 pCtx->fErrorOrAux = 0;
79672 (*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */
79673
79674 /* If the function returned an error, throw an exception */
79675 if( pCtx->fErrorOrAux ){
79676 if( pCtx->isError ){
79677 sqlite3VdbeError(p, "%s", sqlite3_value_text(pCtx->pOut));
79678 rc = pCtx->isError;
79679 }
79680 sqlite3VdbeDeleteAuxData(db, &p->pAuxData, pCtx->iOp, pOp->p1);
79681 if( rc ) goto abort_due_to_error;
79682 }
79683
79684 /* Copy the result of the function into register P3 */
79685 if( pOut->flags & (MEM_Str|MEM_Blob) ){
79686 sqlite3VdbeChangeEncoding(pCtx->pOut, encoding);
79687 if( sqlite3VdbeMemTooBig(pCtx->pOut) ) goto too_big;
79688 }
79689
79690 REGISTER_TRACE(pOp->p3, pCtx->pOut);
79691 UPDATE_MAX_BLOBSIZE(pCtx->pOut);
79692 break;
79693 }
79694
79695 /* Opcode: BitAnd P1 P2 P3 * *
79696 ** Synopsis: r[P3]=r[P1]&r[P2]
@@ -80187,11 +80376,11 @@
80187 pKeyInfo = pOp->p4.pKeyInfo;
80188 assert( n>0 );
80189 assert( pKeyInfo!=0 );
80190 p1 = pOp->p1;
80191 p2 = pOp->p2;
80192 #if SQLITE_DEBUG
80193 if( aPermute ){
80194 int k, mx = 0;
80195 for(k=0; k<n; k++) if( aPermute[k]>mx ) mx = aPermute[k];
80196 assert( p1>0 && p1+mx<=(p->nMem+1 - p->nCursor)+1 );
80197 assert( p2>0 && p2+mx<=(p->nMem+1 - p->nCursor)+1 );
@@ -80325,23 +80514,43 @@
80325 break;
80326 }
80327
80328 /* Opcode: Once P1 P2 * * *
80329 **
80330 ** If the P1 value is equal to the P1 value on the OP_Init opcode at
80331 ** instruction 0, then jump to P2. If the two P1 values differ, then
80332 ** set the P1 value on this opcode to equal the P1 value on the OP_Init
80333 ** and fall through.
 
 
 
 
 
 
 
 
 
 
80334 */
80335 case OP_Once: { /* jump */
 
80336 assert( p->aOp[0].opcode==OP_Init );
80337 VdbeBranchTaken(p->aOp[0].p1==pOp->p1, 2);
80338 if( p->aOp[0].p1==pOp->p1 ){
80339 goto jump_to_p2;
 
 
 
 
80340 }else{
80341 pOp->p1 = p->aOp[0].p1;
 
 
 
80342 }
 
 
80343 break;
80344 }
80345
80346 /* Opcode: If P1 P2 P3 * *
80347 **
@@ -80650,12 +80859,17 @@
80650 /* Content is irrelevant for
80651 ** 1. the typeof() function,
80652 ** 2. the length(X) function if X is a blob, and
80653 ** 3. if the content length is zero.
80654 ** So we might as well use bogus content rather than reading
80655 ** content from disk. */
80656 static u8 aZero[8]; /* This is the bogus content */
 
 
 
 
 
80657 sqlite3VdbeSerialGet(aZero, t, pDest);
80658 }else{
80659 rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest);
80660 if( rc!=SQLITE_OK ) goto abort_due_to_error;
80661 sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest);
@@ -82836,10 +83050,37 @@
82836 assert( pOp->p2==0 );
82837 }
82838 break;
82839 }
82840
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82841
82842 /* Opcode: SorterSort P1 P2 * * *
82843 **
82844 ** After all records have been inserted into the Sorter object
82845 ** identified by P1, invoke this opcode to actually do the sorting.
@@ -83479,10 +83720,22 @@
83479 rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, flags);
83480 if( rc ) goto abort_due_to_error;
83481 pOut->u.i = pgno;
83482 break;
83483 }
 
 
 
 
 
 
 
 
 
 
 
 
83484
83485 /* Opcode: ParseSchema P1 * * P4 *
83486 **
83487 ** Read and parse all entries from the SQLITE_MASTER table of database P1
83488 ** that match the WHERE clause P4.
@@ -83600,11 +83853,11 @@
83600 **
83601 ** Do an analysis of the currently open database. Store in
83602 ** register P1 the text of an error message describing any problems.
83603 ** If no problems are found, store a NULL in register P1.
83604 **
83605 ** The register P3 contains the maximum number of allowed errors.
83606 ** At most reg(P3) errors will be reported.
83607 ** In other words, the analysis stops as soon as reg(P1) errors are
83608 ** seen. Reg(P1) is updated with the number of errors remaining.
83609 **
83610 ** The root page numbers of all tables in the database are integers
@@ -83633,18 +83886,18 @@
83633 assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 );
83634 pIn1 = &aMem[pOp->p1];
83635 assert( pOp->p5<db->nDb );
83636 assert( DbMaskTest(p->btreeMask, pOp->p5) );
83637 z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot,
83638 (int)pnErr->u.i, &nErr);
83639 pnErr->u.i -= nErr;
83640 sqlite3VdbeMemSetNull(pIn1);
83641 if( nErr==0 ){
83642 assert( z==0 );
83643 }else if( z==0 ){
83644 goto no_mem;
83645 }else{
 
83646 sqlite3VdbeMemSetStr(pIn1, z, -1, SQLITE_UTF8, sqlite3_free);
83647 }
83648 UPDATE_MAX_BLOBSIZE(pIn1);
83649 sqlite3VdbeChangeEncoding(pIn1, encoding);
83650 break;
@@ -83819,11 +84072,12 @@
83819 nMem = pProgram->nMem + pProgram->nCsr;
83820 assert( nMem>0 );
83821 if( pProgram->nCsr==0 ) nMem++;
83822 nByte = ROUND8(sizeof(VdbeFrame))
83823 + nMem * sizeof(Mem)
83824 + pProgram->nCsr * sizeof(VdbeCursor *);
 
83825 pFrame = sqlite3DbMallocZero(db, nByte);
83826 if( !pFrame ){
83827 goto no_mem;
83828 }
83829 sqlite3VdbeMemRelease(pRt);
@@ -83870,10 +84124,12 @@
83870 p->pFrame = pFrame;
83871 p->aMem = aMem = VdbeFrameMem(pFrame);
83872 p->nMem = pFrame->nChildMem;
83873 p->nCursor = (u16)pFrame->nChildCsr;
83874 p->apCsr = (VdbeCursor **)&aMem[p->nMem];
 
 
83875 p->aOp = aOp = pProgram->aOp;
83876 p->nOp = pProgram->nOp;
83877 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
83878 p->anExec = 0;
83879 #endif
@@ -84899,11 +85155,15 @@
84899 char *z = sqlite3VdbeExpandSql(p, zTrace);
84900 x(db->pTraceArg, z);
84901 sqlite3_free(z);
84902 }else
84903 #endif
84904 {
 
 
 
 
84905 (void)db->xTrace(SQLITE_TRACE_STMT, db->pTraceArg, p, zTrace);
84906 }
84907 }
84908 #ifdef SQLITE_USE_FCNTL_TRACE
84909 zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
@@ -88787,15 +89047,15 @@
88787 ** The return value from the callback should be one of the WRC_*
88788 ** constants to specify how to proceed with the walk.
88789 **
88790 ** WRC_Continue Continue descending down the tree.
88791 **
88792 ** WRC_Prune Do not descend into child nodes. But allow
88793 ** the walk to continue with sibling nodes.
88794 **
88795 ** WRC_Abort Do no more callbacks. Unwind the stack and
88796 ** return the top-level walk call.
88797 **
88798 ** The return value from this routine is WRC_Abort to abandon the tree walk
88799 ** and WRC_Continue to continue.
88800 */
88801 static SQLITE_NOINLINE int walkExpr(Walker *pWalker, Expr *pExpr){
@@ -89153,11 +89413,12 @@
89153 }
89154 }
89155 }
89156
89157 /* Start at the inner-most context and move outward until a match is found */
89158 while( pNC && cnt==0 ){
 
89159 ExprList *pEList;
89160 SrcList *pSrcList = pNC->pSrcList;
89161
89162 if( pSrcList ){
89163 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
@@ -89338,15 +89599,15 @@
89338 }
89339
89340 /* Advance to the next name context. The loop will exit when either
89341 ** we have a match (cnt>0) or when we run out of name contexts.
89342 */
89343 if( cnt==0 ){
89344 pNC = pNC->pNext;
89345 nSubquery++;
89346 }
89347 }
89348
89349 /*
89350 ** If X and Y are NULL (in other words if only the column name Z is
89351 ** supplied) and the value of Z is enclosed in double-quotes, then
89352 ** Z is a string literal if it doesn't match any column names. In that
@@ -89532,37 +89793,42 @@
89532 break;
89533 }
89534 #endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
89535 && !defined(SQLITE_OMIT_SUBQUERY) */
89536
89537 /* A lone identifier is the name of a column.
89538 */
89539 case TK_ID: {
89540 return lookupName(pParse, 0, 0, pExpr->u.zToken, pNC, pExpr);
89541 }
89542
89543 /* A table name and column name: ID.ID
89544 ** Or a database, table and column: ID.ID.ID
 
 
 
 
89545 */
 
89546 case TK_DOT: {
89547 const char *zColumn;
89548 const char *zTable;
89549 const char *zDb;
89550 Expr *pRight;
89551
89552 /* if( pSrcList==0 ) break; */
89553 notValid(pParse, pNC, "the \".\" operator", NC_IdxExpr);
89554 pRight = pExpr->pRight;
89555 if( pRight->op==TK_ID ){
89556 zDb = 0;
89557 zTable = pExpr->pLeft->u.zToken;
89558 zColumn = pRight->u.zToken;
89559 }else{
89560 assert( pRight->op==TK_DOT );
89561 zDb = pExpr->pLeft->u.zToken;
89562 zTable = pRight->pLeft->u.zToken;
89563 zColumn = pRight->pRight->u.zToken;
 
 
 
 
 
 
 
 
89564 }
89565 return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr);
89566 }
89567
89568 /* Resolve function names
@@ -92326,10 +92592,11 @@
92326 ** in *pValue. If the expression is not an integer or if it is too big
92327 ** to fit in a signed 32-bit integer, return 0 and leave *pValue unchanged.
92328 */
92329 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr *p, int *pValue){
92330 int rc = 0;
 
92331
92332 /* If an expression is an integer literal that fits in a signed 32-bit
92333 ** integer, then the EP_IntValue flag will have already been set */
92334 assert( p->op!=TK_INTEGER || (p->flags & EP_IntValue)!=0
92335 || sqlite3GetInt32(p->u.zToken, &rc)==0 );
@@ -92833,11 +93100,11 @@
92833 int nVal = sqlite3ExprVectorSize(pLeft);
92834 Select *pSelect = (pExpr->flags & EP_xIsSelect) ? pExpr->x.pSelect : 0;
92835 char *zRet;
92836
92837 assert( pExpr->op==TK_IN );
92838 zRet = sqlite3DbMallocZero(pParse->db, nVal+1);
92839 if( zRet ){
92840 int i;
92841 for(i=0; i<nVal; i++){
92842 Expr *pA = sqlite3VectorFieldSubexpr(pLeft, i);
92843 char a = sqlite3ExprAffinity(pA);
@@ -92998,11 +93265,10 @@
92998 if( ALWAYS(pEList->nExpr==nVal) ){
92999 SelectDest dest;
93000 int i;
93001 sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
93002 dest.zAffSdst = exprINAffinity(pParse, pExpr);
93003 assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
93004 pSelect->iLimit = 0;
93005 testcase( pSelect->selFlags & SF_Distinct );
93006 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
93007 if( sqlite3Select(pParse, pSelect, &dest) ){
93008 sqlite3DbFree(pParse->db, dest.zAffSdst);
@@ -93738,11 +94004,11 @@
93738 ** Clear all column cache entries.
93739 */
93740 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse *pParse){
93741 int i;
93742
93743 #if SQLITE_DEBUG
93744 if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
93745 printf("CLEAR\n");
93746 }
93747 #endif
93748 for(i=0; i<pParse->nColCache; i++){
@@ -95145,10 +95411,21 @@
95145 if( pA->a[i].sortOrder!=pB->a[i].sortOrder ) return 1;
95146 if( sqlite3ExprCompare(pExprA, pExprB, iTab) ) return 1;
95147 }
95148 return 0;
95149 }
 
 
 
 
 
 
 
 
 
 
 
95150
95151 /*
95152 ** Return true if we can prove the pE2 will always be true if pE1 is
95153 ** true. Return false if we cannot complete the proof or if pE2 might
95154 ** be false. Examples:
@@ -96698,10 +96975,11 @@
96698 Stat4Sample current; /* Current row as a Stat4Sample */
96699 u32 iPrn; /* Pseudo-random number used for sampling */
96700 Stat4Sample *aBest; /* Array of nCol best samples */
96701 int iMin; /* Index in a[] of entry with minimum score */
96702 int nSample; /* Current number of samples */
 
96703 int iGet; /* Index of current sample accessed by stat_get() */
96704 Stat4Sample *a; /* Array of mxSample Stat4Sample objects */
96705 sqlite3 *db; /* Database connection, for malloc() */
96706 };
96707
@@ -96962,10 +97240,17 @@
96962 int i;
96963
96964 assert( IsStat4 || nEqZero==0 );
96965
96966 #ifdef SQLITE_ENABLE_STAT4
 
 
 
 
 
 
 
96967 if( pNew->isPSample==0 ){
96968 Stat4Sample *pUpgrade = 0;
96969 assert( pNew->anEq[pNew->iCol]>0 );
96970
96971 /* This sample is being added because the prefix that ends in column
@@ -97059,16 +97344,26 @@
97059 if( p->nSample<p->mxSample || sampleIsBetter(p, pBest, &p->a[p->iMin]) ){
97060 sampleInsert(p, pBest, i);
97061 }
97062 }
97063
97064 /* Update the anEq[] fields of any samples already collected. */
 
97065 for(i=p->nSample-1; i>=0; i--){
97066 int j;
97067 for(j=iChng; j<p->nCol; j++){
97068 if( p->a[i].anEq[j]==0 ) p->a[i].anEq[j] = p->current.anEq[j];
 
 
 
 
 
 
 
 
97069 }
 
97070 }
97071 #endif
97072
97073 #if defined(SQLITE_ENABLE_STAT3) && !defined(SQLITE_ENABLE_STAT4)
97074 if( iChng==0 ){
@@ -97594,11 +97889,11 @@
97594 Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
97595 int j, k, regKey;
97596 regKey = sqlite3GetTempRange(pParse, pPk->nKeyCol);
97597 for(j=0; j<pPk->nKeyCol; j++){
97598 k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
97599 assert( k>=0 && k<pTab->nCol );
97600 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, regKey+j);
97601 VdbeComment((v, "%s", pTab->aCol[pPk->aiColumn[j]].zName));
97602 }
97603 sqlite3VdbeAddOp3(v, OP_MakeRecord, regKey, pPk->nKeyCol, regRowid);
97604 sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol);
@@ -97778,44 +98073,32 @@
97778 /* Form 1: Analyze everything */
97779 for(i=0; i<db->nDb; i++){
97780 if( i==1 ) continue; /* Do not analyze the TEMP database */
97781 analyzeDatabase(pParse, i);
97782 }
97783 }else if( pName2->n==0 ){
97784 /* Form 2: Analyze the database or table named */
97785 iDb = sqlite3FindDb(db, pName1);
97786 if( iDb>=0 ){
97787 analyzeDatabase(pParse, iDb);
97788 }else{
97789 z = sqlite3NameFromToken(db, pName1);
97790 if( z ){
97791 if( (pIdx = sqlite3FindIndex(db, z, 0))!=0 ){
97792 analyzeTable(pParse, pIdx->pTable, pIdx);
97793 }else if( (pTab = sqlite3LocateTable(pParse, 0, z, 0))!=0 ){
97794 analyzeTable(pParse, pTab, 0);
97795 }
97796 sqlite3DbFree(db, z);
97797 }
97798 }
97799 }else{
97800 /* Form 3: Analyze the fully qualified table name */
97801 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName);
97802 if( iDb>=0 ){
97803 zDb = db->aDb[iDb].zDbSName;
97804 z = sqlite3NameFromToken(db, pTableName);
97805 if( z ){
97806 if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
97807 analyzeTable(pParse, pIdx->pTable, pIdx);
97808 }else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){
97809 analyzeTable(pParse, pTab, 0);
97810 }
97811 sqlite3DbFree(db, z);
97812 }
97813 }
97814 }
97815 v = sqlite3GetVdbe(pParse);
97816 if( v ) sqlite3VdbeAddOp0(v, OP_Expire);
 
97817 }
97818
97819 /*
97820 ** Used to pass information from the analyzer reader through to the
97821 ** callback routine.
@@ -97940,19 +98223,24 @@
97940 }
97941 aiRowEst = pIndex->aiRowEst;
97942 #endif
97943 pIndex->bUnordered = 0;
97944 decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex);
97945 if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
 
 
 
 
97946 }else{
97947 Index fakeIdx;
97948 fakeIdx.szIdxRow = pTable->szTabRow;
97949 #ifdef SQLITE_ENABLE_COSTMULT
97950 fakeIdx.pTable = pTable;
97951 #endif
97952 decodeIntArray((char*)z, 1, 0, &pTable->nRowLogEst, &fakeIdx);
97953 pTable->szTabRow = fakeIdx.szIdxRow;
 
97954 }
97955
97956 return 0;
97957 }
97958
@@ -98243,19 +98531,24 @@
98243 SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
98244 analysisInfo sInfo;
98245 HashElem *i;
98246 char *zSql;
98247 int rc = SQLITE_OK;
 
98248
98249 assert( iDb>=0 && iDb<db->nDb );
98250 assert( db->aDb[iDb].pBt!=0 );
98251
98252 /* Clear any prior statistics */
98253 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
98254 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
 
 
 
 
98255 Index *pIdx = sqliteHashData(i);
98256 pIdx->aiRowLogEst[0] = 0;
98257 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
98258 sqlite3DeleteIndexSamples(db, pIdx);
98259 pIdx->aSample = 0;
98260 #endif
98261 }
@@ -98274,23 +98567,23 @@
98274 }
98275 }
98276
98277 /* Set appropriate defaults on all indexes not in the sqlite_stat1 table */
98278 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
98279 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
98280 Index *pIdx = sqliteHashData(i);
98281 if( pIdx->aiRowLogEst[0]==0 ) sqlite3DefaultRowEst(pIdx);
98282 }
98283
98284 /* Load the statistics from the sqlite_stat4 table. */
98285 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
98286 if( rc==SQLITE_OK && OptimizationEnabled(db, SQLITE_Stat34) ){
98287 db->lookaside.bDisable++;
98288 rc = loadStat4(db, sInfo.zDatabase);
98289 db->lookaside.bDisable--;
98290 }
98291 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
98292 Index *pIdx = sqliteHashData(i);
98293 sqlite3_free(pIdx->aiRowEst);
98294 pIdx->aiRowEst = 0;
98295 }
98296 #endif
@@ -100271,10 +100564,11 @@
100271 SQLITE_PRIVATE void sqlite3AddNotNull(Parse *pParse, int onError){
100272 Table *p;
100273 p = pParse->pNewTable;
100274 if( p==0 || NEVER(p->nCol<1) ) return;
100275 p->aCol[p->nCol-1].notNull = (u8)onError;
 
100276 }
100277
100278 /*
100279 ** Scan the column type name zType (length nType) and return the
100280 ** associated affinity type.
@@ -102609,10 +102903,13 @@
102609 /* 10, 9, 8, 7, 6 */
102610 LogEst aVal[] = { 33, 32, 30, 28, 26 };
102611 LogEst *a = pIdx->aiRowLogEst;
102612 int nCopy = MIN(ArraySize(aVal), pIdx->nKeyCol);
102613 int i;
 
 
 
102614
102615 /* Set the first entry (number of rows in the index) to the estimated
102616 ** number of rows in the table, or half the number of rows in the table
102617 ** for a partial index. But do not let the estimate drop below 10. */
102618 a[0] = pIdx->pTable->nRowLogEst;
@@ -105193,19 +105490,17 @@
105193 nNeedle = sqlite3_value_bytes(argv[1]);
105194 if( nNeedle>0 ){
105195 if( typeHaystack==SQLITE_BLOB && typeNeedle==SQLITE_BLOB ){
105196 zHaystack = sqlite3_value_blob(argv[0]);
105197 zNeedle = sqlite3_value_blob(argv[1]);
105198 assert( zNeedle!=0 );
105199 assert( zHaystack!=0 || nHaystack==0 );
105200 isText = 0;
105201 }else{
105202 zHaystack = sqlite3_value_text(argv[0]);
105203 zNeedle = sqlite3_value_text(argv[1]);
105204 isText = 1;
105205 if( zHaystack==0 || zNeedle==0 ) return;
105206 }
 
105207 while( nNeedle<=nHaystack && memcmp(zHaystack, zNeedle, nNeedle)!=0 ){
105208 N++;
105209 do{
105210 nHaystack--;
105211 zHaystack++;
@@ -109798,10 +110093,13 @@
109798 VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
109799 }
109800 }
109801 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
109802 VdbeComment((v, "for %s", pIdx->zName));
 
 
 
109803
109804 /* In an UPDATE operation, if this index is the PRIMARY KEY index
109805 ** of a WITHOUT ROWID table and there has been no change the
109806 ** primary key, then no collision is possible. The collision detection
109807 ** logic below can all be skipped. */
@@ -109953,12 +110251,15 @@
109953
109954 /* Records with omitted columns are only allowed for schema format
109955 ** version 2 and later (SQLite version 3.1.4, 2005-02-20). */
109956 if( pTab->pSchema->file_format<2 ) return;
109957
109958 for(i=pTab->nCol; i>1 && pTab->aCol[i-1].pDflt==0; i--){}
109959 sqlite3VdbeChangeP5(v, i);
 
 
 
109960 }
109961 #endif
109962
109963 /*
109964 ** This routine generates code to finish the INSERT or UPDATE operation
@@ -110244,11 +110545,11 @@
110244 }
110245 if( sqlite3TriggerList(pParse, pDest) ){
110246 return 0; /* tab1 must not have triggers */
110247 }
110248 #ifndef SQLITE_OMIT_VIRTUALTABLE
110249 if( pDest->tabFlags & TF_Virtual ){
110250 return 0; /* tab1 must not be a virtual table */
110251 }
110252 #endif
110253 if( onError==OE_Default ){
110254 if( pDest->iPKey>=0 ) onError = pDest->keyConf;
@@ -110306,11 +110607,11 @@
110306 }
110307 if( HasRowid(pDest)!=HasRowid(pSrc) ){
110308 return 0; /* source and destination must both be WITHOUT ROWID or not */
110309 }
110310 #ifndef SQLITE_OMIT_VIRTUALTABLE
110311 if( pSrc->tabFlags & TF_Virtual ){
110312 return 0; /* tab2 must not be a virtual table */
110313 }
110314 #endif
110315 if( pSrc->pSelect ){
110316 return 0; /* tab2 may not be a view */
@@ -110492,12 +110793,10 @@
110492 ** might change the definition of a collation sequence and then run
110493 ** a VACUUM command. In that case keys may not be written in strictly
110494 ** sorted order. */
110495 for(i=0; i<pSrcIdx->nColumn; i++){
110496 const char *zColl = pSrcIdx->azColl[i];
110497 assert( sqlite3_stricmp(sqlite3StrBINARY, zColl)!=0
110498 || sqlite3StrBINARY==zColl );
110499 if( sqlite3_stricmp(sqlite3StrBINARY, zColl) ) break;
110500 }
110501 if( i==pSrcIdx->nColumn ){
110502 idxInsFlags = OPFLAG_USESEEKRESULT;
110503 sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
@@ -110603,11 +110902,11 @@
110603 /* Invoke the callback function if required */
110604 if( xCallback && (SQLITE_ROW==rc ||
110605 (SQLITE_DONE==rc && !callbackIsInit
110606 && db->flags&SQLITE_NullCallback)) ){
110607 if( !callbackIsInit ){
110608 azCols = sqlite3DbMallocZero(db, 2*nCol*sizeof(const char*) + 1);
110609 if( azCols==0 ){
110610 goto exec_out;
110611 }
110612 for(i=0; i<nCol; i++){
110613 azCols[i] = (char *)sqlite3_column_name(pStmt, i);
@@ -110624,10 +110923,11 @@
110624 if( !azVals[i] && sqlite3_column_type(pStmt, i)!=SQLITE_NULL ){
110625 sqlite3OomFault(db);
110626 goto exec_out;
110627 }
110628 }
 
110629 }
110630 if( xCallback(pArg, nCol, azVals, azCols) ){
110631 /* EVIDENCE-OF: R-38229-40159 If the callback function to
110632 ** sqlite3_exec() returns non-zero, then sqlite3_exec() will
110633 ** return SQLITE_ABORT. */
@@ -110979,10 +111279,12 @@
110979 /* Version 3.12.0 and later */
110980 int (*system_errno)(sqlite3*);
110981 /* Version 3.14.0 and later */
110982 int (*trace_v2)(sqlite3*,unsigned,int(*)(unsigned,void*,void*,void*),void*);
110983 char *(*expanded_sql)(sqlite3_stmt*);
 
 
110984 };
110985
110986 /*
110987 ** This is the function signature used for all extension entry points. It
110988 ** is also defined in the file "loadext.c".
@@ -111237,10 +111539,12 @@
111237 /* Version 3.12.0 and later */
111238 #define sqlite3_system_errno sqlite3_api->system_errno
111239 /* Version 3.14.0 and later */
111240 #define sqlite3_trace_v2 sqlite3_api->trace_v2
111241 #define sqlite3_expanded_sql sqlite3_api->expanded_sql
 
 
111242 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
111243
111244 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
111245 /* This case when the file really is being compiled as a loadable
111246 ** extension */
@@ -111662,11 +111966,13 @@
111662 sqlite3_db_cacheflush,
111663 /* Version 3.12.0 and later */
111664 sqlite3_system_errno,
111665 /* Version 3.14.0 and later */
111666 sqlite3_trace_v2,
111667 sqlite3_expanded_sql
 
 
111668 };
111669
111670 /*
111671 ** Attempt to load an SQLite extension library contained in the file
111672 ** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -112094,15 +112400,15 @@
112094 #define PragTyp_JOURNAL_SIZE_LIMIT 20
112095 #define PragTyp_LOCK_PROXY_FILE 21
112096 #define PragTyp_LOCKING_MODE 22
112097 #define PragTyp_PAGE_COUNT 23
112098 #define PragTyp_MMAP_SIZE 24
112099 #define PragTyp_PAGE_SIZE 25
112100 #define PragTyp_SECURE_DELETE 26
112101 #define PragTyp_SHRINK_MEMORY 27
112102 #define PragTyp_SOFT_HEAP_LIMIT 28
112103 #define PragTyp_STATS 29
112104 #define PragTyp_SYNCHRONOUS 30
112105 #define PragTyp_TABLE_INFO 31
112106 #define PragTyp_TEMP_STORE 32
112107 #define PragTyp_TEMP_STORE_DIRECTORY 33
112108 #define PragTyp_THREADS 34
@@ -112112,10 +112418,11 @@
112112 #define PragTyp_HEXKEY 38
112113 #define PragTyp_KEY 39
112114 #define PragTyp_REKEY 40
112115 #define PragTyp_LOCK_STATUS 41
112116 #define PragTyp_PARSER_TRACE 42
 
112117
112118 /* Property flags associated with various pragma. */
112119 #define PragFlg_NeedSchema 0x01 /* Force schema load before running */
112120 #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */
112121 #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */
@@ -112135,51 +112442,52 @@
112135 /* 2 */ "name",
112136 /* 3 */ "type",
112137 /* 4 */ "notnull",
112138 /* 5 */ "dflt_value",
112139 /* 6 */ "pk",
112140 /* 7 */ "table", /* Used by: stats */
112141 /* 8 */ "index",
112142 /* 9 */ "width",
112143 /* 10 */ "height",
112144 /* 11 */ "seqno", /* Used by: index_info */
112145 /* 12 */ "cid",
112146 /* 13 */ "name",
112147 /* 14 */ "seqno", /* Used by: index_xinfo */
112148 /* 15 */ "cid",
112149 /* 16 */ "name",
112150 /* 17 */ "desc",
112151 /* 18 */ "coll",
112152 /* 19 */ "key",
112153 /* 20 */ "seq", /* Used by: index_list */
112154 /* 21 */ "name",
112155 /* 22 */ "unique",
112156 /* 23 */ "origin",
112157 /* 24 */ "partial",
112158 /* 25 */ "seq", /* Used by: database_list */
112159 /* 26 */ "name",
112160 /* 27 */ "file",
112161 /* 28 */ "seq", /* Used by: collation_list */
112162 /* 29 */ "name",
112163 /* 30 */ "id", /* Used by: foreign_key_list */
112164 /* 31 */ "seq",
112165 /* 32 */ "table",
112166 /* 33 */ "from",
112167 /* 34 */ "to",
112168 /* 35 */ "on_update",
112169 /* 36 */ "on_delete",
112170 /* 37 */ "match",
112171 /* 38 */ "table", /* Used by: foreign_key_check */
112172 /* 39 */ "rowid",
112173 /* 40 */ "parent",
112174 /* 41 */ "fkid",
112175 /* 42 */ "busy", /* Used by: wal_checkpoint */
112176 /* 43 */ "log",
112177 /* 44 */ "checkpointed",
112178 /* 45 */ "timeout", /* Used by: busy_timeout */
112179 /* 46 */ "database", /* Used by: lock_status */
112180 /* 47 */ "status",
 
112181 };
112182
112183 /* Definitions of all built-in pragmas */
112184 typedef struct PragmaName {
112185 const char *const zName; /* Name of pragma */
@@ -112221,11 +112529,11 @@
112221 #endif
112222 #endif
112223 {/* zName: */ "busy_timeout",
112224 /* ePragTyp: */ PragTyp_BUSY_TIMEOUT,
112225 /* ePragFlg: */ PragFlg_Result0,
112226 /* ColNames: */ 45, 1,
112227 /* iArg: */ 0 },
112228 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112229 {/* zName: */ "cache_size",
112230 /* ePragTyp: */ PragTyp_CACHE_SIZE,
112231 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
@@ -112258,11 +112566,11 @@
112258 #endif
112259 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
112260 {/* zName: */ "collation_list",
112261 /* ePragTyp: */ PragTyp_COLLATION_LIST,
112262 /* ePragFlg: */ PragFlg_Result0,
112263 /* ColNames: */ 28, 2,
112264 /* iArg: */ 0 },
112265 #endif
112266 #if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
112267 {/* zName: */ "compile_options",
112268 /* ePragTyp: */ PragTyp_COMPILE_OPTIONS,
@@ -112293,11 +112601,11 @@
112293 #endif
112294 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
112295 {/* zName: */ "database_list",
112296 /* ePragTyp: */ PragTyp_DATABASE_LIST,
112297 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
112298 /* ColNames: */ 25, 3,
112299 /* iArg: */ 0 },
112300 #endif
112301 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
112302 {/* zName: */ "default_cache_size",
112303 /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
@@ -112330,18 +112638,18 @@
112330 #endif
112331 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
112332 {/* zName: */ "foreign_key_check",
112333 /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK,
112334 /* ePragFlg: */ PragFlg_NeedSchema,
112335 /* ColNames: */ 38, 4,
112336 /* iArg: */ 0 },
112337 #endif
112338 #if !defined(SQLITE_OMIT_FOREIGN_KEY)
112339 {/* zName: */ "foreign_key_list",
112340 /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST,
112341 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112342 /* ColNames: */ 30, 8,
112343 /* iArg: */ 0 },
112344 #endif
112345 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112346 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
112347 {/* zName: */ "foreign_keys",
@@ -112400,21 +112708,21 @@
112400 #endif
112401 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
112402 {/* zName: */ "index_info",
112403 /* ePragTyp: */ PragTyp_INDEX_INFO,
112404 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112405 /* ColNames: */ 11, 3,
112406 /* iArg: */ 0 },
112407 {/* zName: */ "index_list",
112408 /* ePragTyp: */ PragTyp_INDEX_LIST,
112409 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112410 /* ColNames: */ 20, 5,
112411 /* iArg: */ 0 },
112412 {/* zName: */ "index_xinfo",
112413 /* ePragTyp: */ PragTyp_INDEX_INFO,
112414 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112415 /* ColNames: */ 14, 6,
112416 /* iArg: */ 1 },
112417 #endif
112418 #if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
112419 {/* zName: */ "integrity_check",
112420 /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
@@ -112457,11 +112765,11 @@
112457 #endif
112458 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
112459 {/* zName: */ "lock_status",
112460 /* ePragTyp: */ PragTyp_LOCK_STATUS,
112461 /* ePragFlg: */ PragFlg_Result0,
112462 /* ColNames: */ 46, 2,
112463 /* iArg: */ 0 },
112464 #endif
112465 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112466 {/* zName: */ "locking_mode",
112467 /* ePragTyp: */ PragTyp_LOCKING_MODE,
@@ -112476,10 +112784,17 @@
112476 {/* zName: */ "mmap_size",
112477 /* ePragTyp: */ PragTyp_MMAP_SIZE,
112478 /* ePragFlg: */ 0,
112479 /* ColNames: */ 0, 0,
112480 /* iArg: */ 0 },
 
 
 
 
 
 
 
112481 {/* zName: */ "page_count",
112482 /* ePragTyp: */ PragTyp_PAGE_COUNT,
112483 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
112484 /* ColNames: */ 0, 0,
112485 /* iArg: */ 0 },
@@ -112574,15 +112889,15 @@
112574 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
112575 /* ColNames: */ 0, 0,
112576 /* iArg: */ SQLITE_SqlTrace },
112577 #endif
112578 #endif
112579 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
112580 {/* zName: */ "stats",
112581 /* ePragTyp: */ PragTyp_STATS,
112582 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
112583 /* ColNames: */ 7, 4,
112584 /* iArg: */ 0 },
112585 #endif
112586 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112587 {/* zName: */ "synchronous",
112588 /* ePragTyp: */ PragTyp_SYNCHRONOUS,
@@ -112657,11 +112972,11 @@
112657 /* ColNames: */ 0, 0,
112658 /* iArg: */ 0 },
112659 {/* zName: */ "wal_checkpoint",
112660 /* ePragTyp: */ PragTyp_WAL_CHECKPOINT,
112661 /* ePragFlg: */ PragFlg_NeedSchema,
112662 /* ColNames: */ 42, 3,
112663 /* iArg: */ 0 },
112664 #endif
112665 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112666 {/* zName: */ "writable_schema",
112667 /* ePragTyp: */ PragTyp_FLAG,
@@ -112668,11 +112983,11 @@
112668 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
112669 /* ColNames: */ 0, 0,
112670 /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
112671 #endif
112672 };
112673 /* Number of pragmas: 60 on by default, 73 total. */
112674
112675 /************** End of pragma.h **********************************************/
112676 /************** Continuing where we left off in pragma.c *********************/
112677
112678 /*
@@ -112937,10 +113252,26 @@
112937 lwr = mid + 1;
112938 }
112939 }
112940 return lwr>upr ? 0 : &aPragmaName[mid];
112941 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112942
112943 /*
112944 ** Process a pragma statement.
112945 **
112946 ** Pragmas are of this form:
@@ -113642,11 +113973,11 @@
113642 returnSingleInt(v, pDb->safety_level-1);
113643 }else{
113644 if( !db->autoCommit ){
113645 sqlite3ErrorMsg(pParse,
113646 "Safety level may not be changed inside a transaction");
113647 }else{
113648 int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK;
113649 if( iLevel==0 ) iLevel = 1;
113650 pDb->safety_level = iLevel;
113651 pDb->bSyncSet = 1;
113652 setAllPagerFlags(db);
@@ -113741,33 +114072,37 @@
113741 }
113742 }
113743 }
113744 break;
113745
 
113746 case PragTyp_STATS: {
113747 Index *pIdx;
113748 HashElem *i;
113749 pParse->nMem = 4;
113750 sqlite3CodeVerifySchema(pParse, iDb);
113751 for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){
113752 Table *pTab = sqliteHashData(i);
113753 sqlite3VdbeMultiLoad(v, 1, "ssii",
113754 pTab->zName,
113755 0,
113756 pTab->szTabRow,
113757 pTab->nRowLogEst);
113758 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4);
 
113759 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
113760 sqlite3VdbeMultiLoad(v, 2, "sii",
113761 pIdx->zName,
113762 pIdx->szIdxRow,
113763 pIdx->aiRowLogEst[0]);
113764 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4);
 
113765 }
113766 }
113767 }
113768 break;
 
113769
113770 case PragTyp_INDEX_INFO: if( zRight ){
113771 Index *pIdx;
113772 Table *pTab;
113773 pIdx = sqlite3FindIndex(db, zRight, zDb);
@@ -114020,13 +114355,21 @@
114020 #ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
114021 # define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100
114022 #endif
114023
114024 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
114025 /* Pragma "quick_check" is reduced version of
 
 
 
 
 
 
 
114026 ** integrity_check designed to detect most database corruption
114027 ** without most of the overhead of a full integrity-check.
 
114028 */
114029 case PragTyp_INTEGRITY_CHECK: {
114030 int i, j, addr, mxErr;
114031
114032 int isQuick = (sqlite3Tolower(zLeft[0])=='q');
@@ -114053,11 +114396,11 @@
114053 sqlite3GetInt32(zRight, &mxErr);
114054 if( mxErr<=0 ){
114055 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
114056 }
114057 }
114058 sqlite3VdbeAddOp2(v, OP_Integer, mxErr, 1); /* reg[1] holds errors left */
114059
114060 /* Do an integrity check on each database file */
114061 for(i=0; i<db->nDb; i++){
114062 HashElem *x;
114063 Hash *pTbls;
@@ -114068,14 +114411,10 @@
114068
114069 if( OMIT_TEMPDB && i==1 ) continue;
114070 if( iDb>=0 && i!=iDb ) continue;
114071
114072 sqlite3CodeVerifySchema(pParse, i);
114073 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Halt if out of errors */
114074 VdbeCoverage(v);
114075 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
114076 sqlite3VdbeJumpHere(v, addr);
114077
114078 /* Do an integrity check of the B-Tree
114079 **
114080 ** Begin by finding the root pages numbers
114081 ** for all tables and indices in the database.
@@ -114111,29 +114450,31 @@
114111 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
114112 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zDbSName),
114113 P4_DYNAMIC);
114114 sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1);
114115 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
114116 sqlite3VdbeAddOp2(v, OP_ResultRow, 2, 1);
114117 sqlite3VdbeJumpHere(v, addr);
114118
114119 /* Make sure all the indices are constructed correctly.
114120 */
114121 for(x=sqliteHashFirst(pTbls); x && !isQuick; x=sqliteHashNext(x)){
114122 Table *pTab = sqliteHashData(x);
114123 Index *pIdx, *pPk;
114124 Index *pPrior = 0;
114125 int loopTop;
114126 int iDataCur, iIdxCur;
114127 int r1 = -1;
114128
114129 if( pTab->pIndex==0 ) continue;
 
 
 
 
 
 
114130 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
114131 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
114132 VdbeCoverage(v);
114133 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
114134 sqlite3VdbeJumpHere(v, addr);
114135 sqlite3ExprCacheClear(pParse);
114136 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
114137 1, 0, &iDataCur, &iIdxCur);
114138 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
114139 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
@@ -114144,28 +114485,46 @@
114144 sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v);
114145 loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1);
114146 /* Verify that all NOT NULL columns really are NOT NULL */
114147 for(j=0; j<pTab->nCol; j++){
114148 char *zErr;
114149 int jmp2, jmp3;
114150 if( j==pTab->iPKey ) continue;
114151 if( pTab->aCol[j].notNull==0 ) continue;
114152 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3);
114153 sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
114154 jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
114155 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
114156 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
114157 pTab->aCol[j].zName);
114158 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
114159 sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
114160 jmp3 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v);
114161 sqlite3VdbeAddOp0(v, OP_Halt);
114162 sqlite3VdbeJumpHere(v, jmp2);
114163 sqlite3VdbeJumpHere(v, jmp3);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114164 }
114165 /* Validate index entries for the current row */
114166 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
114167 int jmp2, jmp3, jmp4, jmp5;
114168 int ckUniq = sqlite3VdbeMakeLabel(v);
114169 if( pPk==pIdx ) continue;
114170 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
114171 pPrior, r1);
@@ -114172,20 +114531,17 @@
114172 pPrior = pIdx;
114173 sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */
114174 /* Verify that an index entry exists for the current table row */
114175 jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
114176 pIdx->nColumn); VdbeCoverage(v);
114177 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
114178 sqlite3VdbeLoadString(v, 3, "row ");
114179 sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
114180 sqlite3VdbeLoadString(v, 4, " missing from index ");
114181 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
114182 jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName);
114183 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
114184 sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
114185 jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v);
114186 sqlite3VdbeAddOp0(v, OP_Halt);
114187 sqlite3VdbeJumpHere(v, jmp2);
114188 /* For UNIQUE indexes, verify that only one entry exists with the
114189 ** current key. The entry is unique if (1) any column is NULL
114190 ** or (2) the next entry has a different key */
114191 if( IsUniqueIndex(pIdx) ){
@@ -114202,11 +114558,10 @@
114202 jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v);
114203 sqlite3VdbeGoto(v, uniqOk);
114204 sqlite3VdbeJumpHere(v, jmp6);
114205 sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1,
114206 pIdx->nKeyCol); VdbeCoverage(v);
114207 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
114208 sqlite3VdbeLoadString(v, 3, "non-unique entry in index ");
114209 sqlite3VdbeGoto(v, jmp5);
114210 sqlite3VdbeResolveLabel(v, uniqOk);
114211 }
114212 sqlite3VdbeJumpHere(v, jmp4);
@@ -114213,40 +114568,39 @@
114213 sqlite3ResolvePartIdxLabel(pParse, jmp3);
114214 }
114215 sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
114216 sqlite3VdbeJumpHere(v, loopTop-1);
114217 #ifndef SQLITE_OMIT_BTREECOUNT
114218 sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
114219 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
114220 if( pPk==pIdx ) continue;
114221 addr = sqlite3VdbeCurrentAddr(v);
114222 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); VdbeCoverage(v);
114223 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
114224 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
114225 sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v);
114226 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
114227 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
114228 sqlite3VdbeLoadString(v, 3, pIdx->zName);
114229 sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
114230 sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1);
114231 }
114232 #endif /* SQLITE_OMIT_BTREECOUNT */
114233 }
114234 }
114235 {
114236 static const int iLn = VDBE_OFFSET_LINENO(2);
114237 static const VdbeOpList endCode[] = {
114238 { OP_AddImm, 1, 0, 0}, /* 0 */
114239 { OP_If, 1, 4, 0}, /* 1 */
114240 { OP_String8, 0, 3, 0}, /* 2 */
114241 { OP_ResultRow, 3, 1, 0}, /* 3 */
114242 };
114243 VdbeOp *aOp;
114244
114245 aOp = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
114246 if( aOp ){
114247 aOp[0].p2 = -mxErr;
114248 aOp[2].p4type = P4_STATIC;
114249 aOp[2].p4.z = "ok";
114250 }
114251 }
114252 }
@@ -114466,10 +114820,122 @@
114466 */
114467 case PragTyp_SHRINK_MEMORY: {
114468 sqlite3_db_release_memory(db);
114469 break;
114470 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114471
114472 /*
114473 ** PRAGMA busy_timeout
114474 ** PRAGMA busy_timeout = N
114475 **
@@ -119528,11 +119994,13 @@
119528 assert( pParent->pGroupBy==0 );
119529 pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
119530 }else{
119531 pParent->pWhere = sqlite3ExprAnd(db, pWhere, pParent->pWhere);
119532 }
119533 substSelect(pParse, pParent, iParent, pSub->pEList, 0);
 
 
119534
119535 /* The flattened query is distinct if either the inner or the
119536 ** outer query is distinct.
119537 */
119538 pParent->selFlags |= pSub->selFlags & SF_Distinct;
@@ -123782,12 +124250,29 @@
123782 ** transient would cause the database file to appear to be deleted
123783 ** following reboot.
123784 */
123785 SQLITE_PRIVATE void sqlite3Vacuum(Parse *pParse, Token *pNm){
123786 Vdbe *v = sqlite3GetVdbe(pParse);
123787 int iDb = pNm ? sqlite3TwoPartName(pParse, pNm, pNm, &pNm) : 0;
123788 if( v && (iDb>=2 || iDb==0) ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123789 sqlite3VdbeAddOp1(v, OP_Vacuum, iDb);
123790 sqlite3VdbeUsesBtree(v, iDb);
123791 }
123792 return;
123793 }
@@ -124377,12 +124862,11 @@
124377
124378 db = pParse->db;
124379 iDb = sqlite3SchemaToIndex(db, pTable->pSchema);
124380 assert( iDb>=0 );
124381
124382 pTable->tabFlags |= TF_Virtual;
124383 pTable->nModuleArg = 0;
124384 addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName));
124385 addModuleArgument(db, pTable, 0);
124386 addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName));
124387 assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0)
124388 || (pParse->sNameToken.z==pName1->z && pName2->z==0)
@@ -124666,11 +125150,11 @@
124666 const char *zMod;
124667 Module *pMod;
124668 int rc;
124669
124670 assert( pTab );
124671 if( (pTab->tabFlags & TF_Virtual)==0 || sqlite3GetVTable(db, pTab) ){
124672 return SQLITE_OK;
124673 }
124674
124675 /* Locate the required virtual table module */
124676 zMod = pTab->azModuleArg[0];
@@ -124736,11 +125220,11 @@
124736 Table *pTab;
124737 Module *pMod;
124738 const char *zMod;
124739
124740 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
124741 assert( pTab && (pTab->tabFlags & TF_Virtual)!=0 && !pTab->pVTable );
124742
124743 /* Locate the required virtual table module */
124744 zMod = pTab->azModuleArg[0];
124745 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
124746
@@ -124790,11 +125274,11 @@
124790 sqlite3Error(db, SQLITE_MISUSE);
124791 sqlite3_mutex_leave(db->mutex);
124792 return SQLITE_MISUSE_BKPT;
124793 }
124794 pTab = pCtx->pTab;
124795 assert( (pTab->tabFlags & TF_Virtual)!=0 );
124796
124797 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
124798 if( pParse==0 ){
124799 rc = SQLITE_NOMEM_BKPT;
124800 }else{
@@ -124804,11 +125288,11 @@
124804
124805 if( SQLITE_OK==sqlite3RunParser(pParse, zCreateTable, &zErr)
124806 && pParse->pNewTable
124807 && !db->mallocFailed
124808 && !pParse->pNewTable->pSelect
124809 && (pParse->pNewTable->tabFlags & TF_Virtual)==0
124810 ){
124811 if( !pTab->aCol ){
124812 Table *pNew = pParse->pNewTable;
124813 Index *pIdx;
124814 pTab->aCol = pNew->aCol;
@@ -125093,11 +125577,11 @@
125093 /* Check to see the left operand is a column in a virtual table */
125094 if( NEVER(pExpr==0) ) return pDef;
125095 if( pExpr->op!=TK_COLUMN ) return pDef;
125096 pTab = pExpr->pTab;
125097 if( NEVER(pTab==0) ) return pDef;
125098 if( (pTab->tabFlags & TF_Virtual)==0 ) return pDef;
125099 pVtab = sqlite3GetVTable(db, pTab)->pVtab;
125100 assert( pVtab!=0 );
125101 assert( pVtab->pModule!=0 );
125102 pMod = (sqlite3_module *)pVtab->pModule;
125103 if( pMod->xFindFunction==0 ) return pDef;
@@ -125188,12 +125672,11 @@
125188 return 0;
125189 }
125190 pMod->pEpoTab = pTab;
125191 pTab->nTabRef = 1;
125192 pTab->pSchema = db->aDb[0].pSchema;
125193 pTab->tabFlags |= TF_Virtual;
125194 pTab->nModuleArg = 0;
125195 pTab->iPKey = -1;
125196 addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
125197 addModuleArgument(db, pTab, 0);
125198 addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
125199 rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
@@ -125260,11 +125743,11 @@
125260 case SQLITE_VTAB_CONSTRAINT_SUPPORT: {
125261 VtabCtx *p = db->pVtabCtx;
125262 if( !p ){
125263 rc = SQLITE_MISUSE_BKPT;
125264 }else{
125265 assert( p->pTab==0 || (p->pTab->tabFlags & TF_Virtual)!=0 );
125266 p->pVTable->bConstraint = (u8)va_arg(ap, int);
125267 }
125268 break;
125269 }
125270 default:
@@ -125699,12 +126182,17 @@
125699 WhereOrSet *pOrSet; /* Record best loops here, if not NULL */
125700 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
125701 UnpackedRecord *pRec; /* Probe for stat4 (if required) */
125702 int nRecValid; /* Number of valid fields currently in pRec */
125703 #endif
 
125704 };
125705
 
 
 
 
125706 /*
125707 ** The WHERE clause processing routine has two halves. The
125708 ** first part does the start of the WHERE loop and the second
125709 ** half does the tail of the WHERE loop. An instance of
125710 ** this structure is returned by the first half and passed
@@ -125715,11 +126203,11 @@
125715 */
125716 struct WhereInfo {
125717 Parse *pParse; /* Parsing and code generating context */
125718 SrcList *pTabList; /* List of tables in the join */
125719 ExprList *pOrderBy; /* The ORDER BY clause or NULL */
125720 ExprList *pDistinctSet; /* DISTINCT over all these values */
125721 LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
125722 int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */
125723 int iContinue; /* Jump here to continue with next record */
125724 int iBreak; /* Jump here to break out of the loop */
125725 int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
@@ -126899,10 +127387,11 @@
126899 Parse *pParse; /* Parsing context */
126900 sqlite3 *db; /* Database connection */
126901 Vdbe *v; /* The prepared stmt under constructions */
126902 struct SrcList_item *pTabItem; /* FROM clause term being coded */
126903 int addrBrk; /* Jump here to break out of the loop */
 
126904 int addrCont; /* Jump here to continue with next cycle */
126905 int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
126906 int iReleaseReg = 0; /* Temp register to free before returning */
126907
126908 pParse = pWInfo->pParse;
@@ -126939,10 +127428,15 @@
126939 if( pLevel->iFrom>0 && (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){
126940 pLevel->iLeftJoin = ++pParse->nMem;
126941 sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
126942 VdbeComment((v, "init LEFT JOIN no-match flag"));
126943 }
 
 
 
 
 
126944
126945 /* Special case of a FROM clause subquery implemented as a co-routine */
126946 if( pTabItem->fg.viaCoroutine ){
126947 int regYield = pTabItem->regReturn;
126948 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
@@ -127124,11 +127618,11 @@
127124 VdbeCoverageIf(v, pX->op==TK_LT);
127125 VdbeCoverageIf(v, pX->op==TK_GE);
127126 sqlite3ExprCacheAffinityChange(pParse, r1, 1);
127127 sqlite3ReleaseTempReg(pParse, rTemp);
127128 }else{
127129 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrBrk);
127130 VdbeCoverageIf(v, bRev==0);
127131 VdbeCoverageIf(v, bRev!=0);
127132 }
127133 if( pEnd ){
127134 Expr *pX;
@@ -127770,11 +128264,11 @@
127770 pLevel->op = OP_Noop;
127771 }else{
127772 codeCursorHint(pTabItem, pWInfo, pLevel, 0);
127773 pLevel->op = aStep[bRev];
127774 pLevel->p1 = iCur;
127775 pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
127776 VdbeCoverageIf(v, bRev==0);
127777 VdbeCoverageIf(v, bRev!=0);
127778 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
127779 }
127780 }
@@ -128095,19 +128589,10 @@
128095 #ifdef SQLITE_EBCDIC
128096 if( *pnoCase ) return 0;
128097 #endif
128098 pList = pExpr->x.pList;
128099 pLeft = pList->a[1].pExpr;
128100 if( pLeft->op!=TK_COLUMN
128101 || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT
128102 || IsVirtual(pLeft->pTab) /* Value might be numeric */
128103 ){
128104 /* IMP: R-02065-49465 The left-hand side of the LIKE or GLOB operator must
128105 ** be the name of an indexed column with TEXT affinity. */
128106 return 0;
128107 }
128108 assert( pLeft->iColumn!=(-1) ); /* Because IPK never has AFF_TEXT */
128109
128110 pRight = sqlite3ExprSkipCollate(pList->a[0].pExpr);
128111 op = pRight->op;
128112 if( op==TK_VARIABLE ){
128113 Vdbe *pReprepare = pParse->pReprepare;
@@ -128120,10 +128605,27 @@
128120 assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER );
128121 }else if( op==TK_STRING ){
128122 z = pRight->u.zToken;
128123 }
128124 if( z ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128125 cnt = 0;
128126 while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){
128127 cnt++;
128128 }
128129 if( cnt!=0 && 255!=(u8)z[cnt-1] ){
@@ -128748,11 +129250,11 @@
128748 iCur = pFrom->a[i].iCursor;
128749 for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){
128750 if( pIdx->aColExpr==0 ) continue;
128751 for(i=0; i<pIdx->nKeyCol; i++){
128752 if( pIdx->aiColumn[i]!=XN_EXPR ) continue;
128753 if( sqlite3ExprCompare(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
128754 *piCur = iCur;
128755 *piColumn = XN_EXPR;
128756 return 1;
128757 }
128758 }
@@ -129539,11 +130041,12 @@
129539 do{
129540 for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
129541 if( pTerm->leftCursor==iCur
129542 && pTerm->u.leftColumn==iColumn
129543 && (iColumn!=XN_EXPR
129544 || sqlite3ExprCompare(pTerm->pExpr->pLeft,pScan->pIdxExpr,iCur)==0)
 
129545 && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
129546 ){
129547 if( (pTerm->eOperator & WO_EQUIV)!=0
129548 && pScan->nEquiv<ArraySize(pScan->aiCur)
129549 && (pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight))->op==TK_COLUMN
@@ -129846,18 +130349,20 @@
129846 ** cursor iTabCur are transformed into OP_Null. Or, if bIncrRowid is non-zero,
129847 ** then each OP_Rowid is transformed into an instruction to increment the
129848 ** value stored in its output register.
129849 */
129850 static void translateColumnToCopy(
129851 Vdbe *v, /* The VDBE containing code to translate */
129852 int iStart, /* Translate from this opcode to the end */
129853 int iTabCur, /* OP_Column/OP_Rowid references to this table */
129854 int iRegister, /* The first column is in this register */
129855 int bIncrRowid /* If non-zero, transform OP_rowid to OP_AddImm(1) */
129856 ){
 
129857 VdbeOp *pOp = sqlite3VdbeGetOp(v, iStart);
129858 int iEnd = sqlite3VdbeCurrentAddr(v);
 
129859 for(; iStart<iEnd; iStart++, pOp++){
129860 if( pOp->p1!=iTabCur ) continue;
129861 if( pOp->opcode==OP_Column ){
129862 pOp->opcode = OP_Copy;
129863 pOp->p1 = pOp->p2 + iRegister;
@@ -130131,11 +130636,13 @@
130131 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
130132 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
130133 if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
130134 if( pTabItem->fg.viaCoroutine ){
130135 sqlite3VdbeChangeP2(v, addrCounter, regBase+n);
130136 translateColumnToCopy(v, addrTop, pLevel->iTabCur, pTabItem->regResult, 1);
 
 
130137 sqlite3VdbeGoto(v, addrTop);
130138 pTabItem->fg.viaCoroutine = 0;
130139 }else{
130140 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
130141 }
@@ -131716,10 +132223,15 @@
131716 testcase( eOp & WO_IS );
131717 testcase( eOp & WO_ISNULL );
131718 continue;
131719 }
131720
 
 
 
 
 
131721 pNew->wsFlags = saved_wsFlags;
131722 pNew->u.btree.nEq = saved_nEq;
131723 pNew->u.btree.nBtm = saved_nBtm;
131724 pNew->u.btree.nTop = saved_nTop;
131725 pNew->nLTerm = saved_nLTerm;
@@ -132263,11 +132775,19 @@
132263 pNew->nOut = rSize;
132264 if( rc ) break;
132265 }
132266 }
132267
 
132268 rc = whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, 0);
 
 
 
 
 
 
 
132269 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
132270 sqlite3Stat4ProbeFree(pBuilder->pRec);
132271 pBuilder->nRecValid = 0;
132272 pBuilder->pRec = 0;
132273 #endif
@@ -133443,13 +133963,13 @@
133443 && (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
133444 && pWInfo->eDistinct==WHERE_DISTINCT_NOOP
133445 && nRowEst
133446 ){
133447 Bitmask notUsed;
133448 int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pDistinctSet, pFrom,
133449 WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed);
133450 if( rc==pWInfo->pDistinctSet->nExpr ){
133451 pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
133452 }
133453 }
133454 if( pWInfo->pOrderBy ){
133455 if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
@@ -133682,11 +134202,11 @@
133682 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
133683 Parse *pParse, /* The parser context */
133684 SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
133685 Expr *pWhere, /* The WHERE clause */
133686 ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */
133687 ExprList *pDistinctSet, /* Try not to output two rows that duplicate these */
133688 u16 wctrlFlags, /* The WHERE_* flags defined in sqliteInt.h */
133689 int iAuxArg /* If WHERE_OR_SUBCLAUSE is set, index cursor number
133690 ** If WHERE_USE_LIMIT, then the limit amount */
133691 ){
133692 int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
@@ -133758,11 +134278,11 @@
133758 goto whereBeginError;
133759 }
133760 pWInfo->pParse = pParse;
133761 pWInfo->pTabList = pTabList;
133762 pWInfo->pOrderBy = pOrderBy;
133763 pWInfo->pDistinctSet = pDistinctSet;
133764 pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
133765 pWInfo->nLevel = nTabList;
133766 pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
133767 pWInfo->wctrlFlags = wctrlFlags;
133768 pWInfo->iLimit = iAuxArg;
@@ -133836,17 +134356,17 @@
133836 /* Analyze all of the subexpressions. */
133837 sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
133838 if( db->mallocFailed ) goto whereBeginError;
133839
133840 if( wctrlFlags & WHERE_WANT_DISTINCT ){
133841 if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pDistinctSet) ){
133842 /* The DISTINCT marking is pointless. Ignore it. */
133843 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
133844 }else if( pOrderBy==0 ){
133845 /* Try to ORDER BY the result set to make distinct processing easier */
133846 pWInfo->wctrlFlags |= WHERE_DISTINCTBY;
133847 pWInfo->pOrderBy = pDistinctSet;
133848 }
133849 }
133850
133851 /* Construct the WhereLoop objects */
133852 #if defined(WHERETRACE_ENABLED)
@@ -133918,14 +134438,14 @@
133918 }
133919 }
133920 #endif
133921 /* Attempt to omit tables from the join that do not effect the result */
133922 if( pWInfo->nLevel>=2
133923 && pDistinctSet!=0
133924 && OptimizationEnabled(db, SQLITE_OmitNoopJoin)
133925 ){
133926 Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pDistinctSet);
133927 if( sWLB.pOrderBy ){
133928 tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy);
133929 }
133930 while( pWInfo->nLevel>=2 ){
133931 WhereTerm *pTerm, *pEnd;
@@ -134236,12 +134756,13 @@
134236
134237 /* For a co-routine, change all OP_Column references to the table of
134238 ** the co-routine into OP_Copy of result contained in a register.
134239 ** OP_Rowid becomes OP_Null.
134240 */
134241 if( pTabItem->fg.viaCoroutine && !db->mallocFailed ){
134242 translateColumnToCopy(v, pLevel->addrBody, pLevel->iTabCur,
 
134243 pTabItem->regResult, 0);
134244 continue;
134245 }
134246
134247 /* If this scan uses an index, make VDBE code substitutions to read data
@@ -134704,166 +135225,166 @@
134704 **
134705 *********** Begin parsing tables **********************************************/
134706 #define YY_ACTTAB_COUNT (1567)
134707 static const YYACTIONTYPE yy_action[] = {
134708 /* 0 */ 325, 832, 351, 825, 5, 203, 203, 819, 99, 100,
134709 /* 10 */ 90, 842, 842, 854, 857, 846, 846, 97, 97, 98,
134710 /* 20 */ 98, 98, 98, 301, 96, 96, 96, 96, 95, 95,
134711 /* 30 */ 94, 94, 94, 93, 351, 325, 977, 977, 824, 824,
134712 /* 40 */ 826, 947, 354, 99, 100, 90, 842, 842, 854, 857,
134713 /* 50 */ 846, 846, 97, 97, 98, 98, 98, 98, 338, 96,
134714 /* 60 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351,
134715 /* 70 */ 95, 95, 94, 94, 94, 93, 351, 791, 977, 977,
134716 /* 80 */ 325, 94, 94, 94, 93, 351, 792, 75, 99, 100,
134717 /* 90 */ 90, 842, 842, 854, 857, 846, 846, 97, 97, 98,
134718 /* 100 */ 98, 98, 98, 450, 96, 96, 96, 96, 95, 95,
134719 /* 110 */ 94, 94, 94, 93, 351, 1333, 155, 155, 2, 325,
134720 /* 120 */ 275, 146, 132, 52, 52, 93, 351, 99, 100, 90,
134721 /* 130 */ 842, 842, 854, 857, 846, 846, 97, 97, 98, 98,
134722 /* 140 */ 98, 98, 101, 96, 96, 96, 96, 95, 95, 94,
134723 /* 150 */ 94, 94, 93, 351, 958, 958, 325, 268, 428, 413,
134724 /* 160 */ 411, 61, 752, 752, 99, 100, 90, 842, 842, 854,
134725 /* 170 */ 857, 846, 846, 97, 97, 98, 98, 98, 98, 60,
134726 /* 180 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
134727 /* 190 */ 351, 325, 270, 329, 273, 277, 959, 960, 250, 99,
134728 /* 200 */ 100, 90, 842, 842, 854, 857, 846, 846, 97, 97,
134729 /* 210 */ 98, 98, 98, 98, 301, 96, 96, 96, 96, 95,
134730 /* 220 */ 95, 94, 94, 94, 93, 351, 325, 938, 1326, 698,
134731 /* 230 */ 706, 1326, 242, 412, 99, 100, 90, 842, 842, 854,
134732 /* 240 */ 857, 846, 846, 97, 97, 98, 98, 98, 98, 347,
134733 /* 250 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
134734 /* 260 */ 351, 325, 938, 1327, 384, 699, 1327, 381, 379, 99,
134735 /* 270 */ 100, 90, 842, 842, 854, 857, 846, 846, 97, 97,
134736 /* 280 */ 98, 98, 98, 98, 701, 96, 96, 96, 96, 95,
134737 /* 290 */ 95, 94, 94, 94, 93, 351, 325, 92, 89, 178,
134738 /* 300 */ 833, 936, 373, 700, 99, 100, 90, 842, 842, 854,
134739 /* 310 */ 857, 846, 846, 97, 97, 98, 98, 98, 98, 375,
134740 /* 320 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
134741 /* 330 */ 351, 325, 1276, 947, 354, 818, 936, 739, 739, 99,
134742 /* 340 */ 100, 90, 842, 842, 854, 857, 846, 846, 97, 97,
134743 /* 350 */ 98, 98, 98, 98, 230, 96, 96, 96, 96, 95,
134744 /* 360 */ 95, 94, 94, 94, 93, 351, 325, 969, 227, 92,
134745 /* 370 */ 89, 178, 373, 300, 99, 100, 90, 842, 842, 854,
134746 /* 380 */ 857, 846, 846, 97, 97, 98, 98, 98, 98, 921,
134747 /* 390 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
134748 /* 400 */ 351, 325, 449, 447, 447, 447, 147, 737, 737, 99,
134749 /* 410 */ 100, 90, 842, 842, 854, 857, 846, 846, 97, 97,
134750 /* 420 */ 98, 98, 98, 98, 296, 96, 96, 96, 96, 95,
134751 /* 430 */ 95, 94, 94, 94, 93, 351, 325, 419, 231, 958,
134752 /* 440 */ 958, 158, 25, 422, 99, 100, 90, 842, 842, 854,
134753 /* 450 */ 857, 846, 846, 97, 97, 98, 98, 98, 98, 450,
134754 /* 460 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
134755 /* 470 */ 351, 443, 224, 224, 420, 958, 958, 962, 325, 52,
134756 /* 480 */ 52, 959, 960, 176, 415, 78, 99, 100, 90, 842,
134757 /* 490 */ 842, 854, 857, 846, 846, 97, 97, 98, 98, 98,
134758 /* 500 */ 98, 379, 96, 96, 96, 96, 95, 95, 94, 94,
134759 /* 510 */ 94, 93, 351, 325, 428, 418, 298, 959, 960, 962,
134760 /* 520 */ 81, 99, 88, 90, 842, 842, 854, 857, 846, 846,
134761 /* 530 */ 97, 97, 98, 98, 98, 98, 717, 96, 96, 96,
134762 /* 540 */ 96, 95, 95, 94, 94, 94, 93, 351, 325, 843,
134763 /* 550 */ 843, 855, 858, 996, 318, 343, 379, 100, 90, 842,
134764 /* 560 */ 842, 854, 857, 846, 846, 97, 97, 98, 98, 98,
134765 /* 570 */ 98, 450, 96, 96, 96, 96, 95, 95, 94, 94,
134766 /* 580 */ 94, 93, 351, 325, 350, 350, 350, 260, 377, 340,
134767 /* 590 */ 929, 52, 52, 90, 842, 842, 854, 857, 846, 846,
134768 /* 600 */ 97, 97, 98, 98, 98, 98, 361, 96, 96, 96,
134769 /* 610 */ 96, 95, 95, 94, 94, 94, 93, 351, 86, 445,
134770 /* 620 */ 847, 3, 1203, 361, 360, 378, 344, 813, 958, 958,
134771 /* 630 */ 1300, 86, 445, 729, 3, 212, 169, 287, 405, 282,
134772 /* 640 */ 404, 199, 232, 450, 300, 760, 83, 84, 280, 245,
134773 /* 650 */ 262, 365, 251, 85, 352, 352, 92, 89, 178, 83,
134774 /* 660 */ 84, 242, 412, 52, 52, 448, 85, 352, 352, 246,
134775 /* 670 */ 959, 960, 194, 455, 670, 402, 399, 398, 448, 243,
134776 /* 680 */ 221, 114, 434, 776, 361, 450, 397, 268, 747, 224,
134777 /* 690 */ 224, 132, 132, 198, 832, 434, 452, 451, 428, 427,
134778 /* 700 */ 819, 415, 734, 713, 132, 52, 52, 832, 268, 452,
134779 /* 710 */ 451, 734, 194, 819, 363, 402, 399, 398, 450, 1271,
134780 /* 720 */ 1271, 23, 958, 958, 86, 445, 397, 3, 228, 429,
134781 /* 730 */ 895, 824, 824, 826, 827, 19, 203, 720, 52, 52,
134782 /* 740 */ 428, 408, 439, 249, 824, 824, 826, 827, 19, 229,
134783 /* 750 */ 403, 153, 83, 84, 761, 177, 241, 450, 721, 85,
134784 /* 760 */ 352, 352, 120, 157, 959, 960, 58, 977, 409, 355,
134785 /* 770 */ 330, 448, 268, 428, 430, 320, 790, 32, 32, 86,
134786 /* 780 */ 445, 776, 3, 341, 98, 98, 98, 98, 434, 96,
134787 /* 790 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351,
134788 /* 800 */ 832, 120, 452, 451, 813, 887, 819, 83, 84, 977,
134789 /* 810 */ 813, 132, 410, 920, 85, 352, 352, 132, 407, 789,
134790 /* 820 */ 958, 958, 92, 89, 178, 917, 448, 262, 370, 261,
134791 /* 830 */ 82, 914, 80, 262, 370, 261, 776, 824, 824, 826,
134792 /* 840 */ 827, 19, 934, 434, 96, 96, 96, 96, 95, 95,
134793 /* 850 */ 94, 94, 94, 93, 351, 832, 74, 452, 451, 958,
134794 /* 860 */ 958, 819, 959, 960, 120, 92, 89, 178, 945, 2,
134795 /* 870 */ 918, 965, 268, 1, 976, 76, 445, 762, 3, 708,
134796 /* 880 */ 901, 901, 387, 958, 958, 757, 919, 371, 740, 778,
134797 /* 890 */ 756, 257, 824, 824, 826, 827, 19, 417, 741, 450,
134798 /* 900 */ 24, 959, 960, 83, 84, 369, 958, 958, 177, 226,
134799 /* 910 */ 85, 352, 352, 885, 315, 314, 313, 215, 311, 10,
134800 /* 920 */ 10, 683, 448, 349, 348, 959, 960, 909, 777, 157,
134801 /* 930 */ 120, 958, 958, 337, 776, 416, 711, 310, 450, 434,
134802 /* 940 */ 450, 321, 450, 791, 103, 200, 175, 450, 959, 960,
134803 /* 950 */ 908, 832, 792, 452, 451, 9, 9, 819, 10, 10,
134804 /* 960 */ 52, 52, 51, 51, 180, 716, 248, 10, 10, 171,
134805 /* 970 */ 170, 167, 339, 959, 960, 247, 984, 702, 702, 450,
134806 /* 980 */ 715, 233, 686, 982, 889, 983, 182, 914, 824, 824,
134807 /* 990 */ 826, 827, 19, 183, 256, 423, 132, 181, 394, 10,
134808 /* 1000 */ 10, 889, 891, 749, 958, 958, 917, 268, 985, 198,
134809 /* 1010 */ 985, 349, 348, 425, 415, 299, 817, 832, 326, 825,
134810 /* 1020 */ 120, 332, 133, 819, 268, 98, 98, 98, 98, 91,
134811 /* 1030 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
134812 /* 1040 */ 351, 157, 810, 371, 382, 359, 959, 960, 358, 268,
134813 /* 1050 */ 450, 918, 368, 324, 824, 824, 826, 450, 709, 450,
134814 /* 1060 */ 264, 380, 889, 450, 877, 746, 253, 919, 255, 433,
134815 /* 1070 */ 36, 36, 234, 450, 234, 120, 269, 37, 37, 12,
134816 /* 1080 */ 12, 334, 272, 27, 27, 450, 330, 118, 450, 162,
134817 /* 1090 */ 742, 280, 450, 38, 38, 450, 985, 356, 985, 450,
134818 /* 1100 */ 709, 1210, 450, 132, 450, 39, 39, 450, 40, 40,
134819 /* 1110 */ 450, 362, 41, 41, 450, 42, 42, 450, 254, 28,
134820 /* 1120 */ 28, 450, 29, 29, 31, 31, 450, 43, 43, 450,
134821 /* 1130 */ 44, 44, 450, 714, 45, 45, 450, 11, 11, 767,
134822 /* 1140 */ 450, 46, 46, 450, 268, 450, 105, 105, 450, 47,
134823 /* 1150 */ 47, 450, 48, 48, 450, 237, 33, 33, 450, 172,
134824 /* 1160 */ 49, 49, 450, 50, 50, 34, 34, 274, 122, 122,
134825 /* 1170 */ 450, 123, 123, 450, 124, 124, 450, 898, 56, 56,
134826 /* 1180 */ 450, 897, 35, 35, 450, 267, 450, 817, 450, 817,
134827 /* 1190 */ 106, 106, 450, 53, 53, 385, 107, 107, 450, 817,
134828 /* 1200 */ 108, 108, 817, 450, 104, 104, 121, 121, 119, 119,
134829 /* 1210 */ 450, 117, 112, 112, 450, 276, 450, 225, 111, 111,
134830 /* 1220 */ 450, 730, 450, 109, 109, 450, 673, 674, 675, 912,
134831 /* 1230 */ 110, 110, 317, 998, 55, 55, 57, 57, 692, 331,
134832 /* 1240 */ 54, 54, 26, 26, 696, 30, 30, 317, 937, 197,
134833 /* 1250 */ 196, 195, 335, 281, 336, 446, 331, 745, 689, 436,
134834 /* 1260 */ 440, 444, 120, 72, 386, 223, 175, 345, 757, 933,
134835 /* 1270 */ 20, 286, 319, 756, 815, 372, 374, 202, 202, 202,
134836 /* 1280 */ 263, 395, 285, 74, 208, 21, 696, 719, 718, 884,
134837 /* 1290 */ 120, 120, 120, 120, 120, 754, 278, 828, 77, 74,
134838 /* 1300 */ 726, 727, 785, 783, 880, 202, 999, 208, 894, 893,
134839 /* 1310 */ 894, 893, 694, 816, 763, 116, 774, 1290, 431, 432,
134840 /* 1320 */ 302, 999, 390, 303, 823, 697, 691, 680, 159, 289,
134841 /* 1330 */ 679, 884, 681, 952, 291, 218, 293, 7, 316, 828,
134842 /* 1340 */ 173, 805, 259, 364, 252, 911, 376, 713, 295, 435,
134843 /* 1350 */ 308, 168, 955, 993, 135, 400, 990, 284, 882, 881,
134844 /* 1360 */ 205, 928, 926, 59, 333, 62, 144, 156, 130, 72,
134845 /* 1370 */ 802, 366, 367, 393, 137, 185, 189, 160, 139, 383,
134846 /* 1380 */ 67, 896, 140, 141, 142, 148, 389, 812, 775, 266,
134847 /* 1390 */ 219, 190, 154, 391, 913, 876, 271, 406, 191, 322,
134848 /* 1400 */ 682, 733, 192, 342, 732, 724, 731, 711, 723, 421,
134849 /* 1410 */ 705, 71, 323, 6, 204, 771, 288, 79, 297, 346,
134850 /* 1420 */ 772, 704, 290, 283, 703, 770, 292, 294, 967, 239,
134851 /* 1430 */ 769, 102, 862, 438, 426, 240, 424, 442, 73, 213,
134852 /* 1440 */ 688, 238, 22, 453, 953, 214, 217, 216, 454, 677,
134853 /* 1450 */ 676, 671, 753, 125, 115, 235, 126, 669, 353, 166,
134854 /* 1460 */ 127, 244, 179, 357, 306, 304, 305, 307, 113, 892,
134855 /* 1470 */ 327, 890, 811, 328, 134, 128, 136, 138, 743, 258,
134856 /* 1480 */ 907, 184, 143, 129, 910, 186, 63, 64, 145, 187,
134857 /* 1490 */ 906, 65, 8, 66, 13, 188, 202, 899, 265, 149,
134858 /* 1500 */ 987, 388, 150, 685, 161, 392, 285, 193, 279, 396,
134859 /* 1510 */ 151, 401, 68, 14, 15, 722, 69, 236, 831, 131,
134860 /* 1520 */ 830, 860, 70, 751, 16, 414, 755, 4, 174, 220,
134861 /* 1530 */ 222, 784, 201, 152, 779, 77, 74, 17, 18, 875,
134862 /* 1540 */ 861, 859, 916, 864, 915, 207, 206, 942, 163, 437,
134863 /* 1550 */ 948, 943, 164, 209, 1002, 441, 863, 165, 210, 829,
134864 /* 1560 */ 695, 87, 312, 211, 1292, 1291, 309,
134865 };
134866 static const YYCODETYPE yy_lookahead[] = {
134867 /* 0 */ 19, 95, 53, 97, 22, 24, 24, 101, 27, 28,
134868 /* 10 */ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
134869 /* 20 */ 39, 40, 41, 152, 43, 44, 45, 46, 47, 48,
@@ -135112,55 +135633,55 @@
135112 /* 300 */ 1256, 1200, 1206, 1260, 1247, 1261, 1263, 1262, 1266, 1278,
135113 /* 310 */ 1282, 1292, 1294, 1297, 1298, 1299, 1300, 1221, 1224, 1228,
135114 /* 320 */ 1288, 1291, 1276, 1277, 1295,
135115 };
135116 static const YYACTIONTYPE yy_default[] = {
135117 /* 0 */ 1281, 1271, 1271, 1271, 1203, 1203, 1203, 1203, 1271, 1096,
135118 /* 10 */ 1125, 1125, 1255, 1332, 1332, 1332, 1332, 1332, 1332, 1202,
135119 /* 20 */ 1332, 1332, 1332, 1332, 1271, 1100, 1131, 1332, 1332, 1332,
135120 /* 30 */ 1332, 1204, 1205, 1332, 1332, 1332, 1254, 1256, 1141, 1140,
135121 /* 40 */ 1139, 1138, 1237, 1112, 1136, 1129, 1133, 1204, 1198, 1199,
135122 /* 50 */ 1197, 1201, 1205, 1332, 1132, 1167, 1182, 1166, 1332, 1332,
135123 /* 60 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135124 /* 70 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135125 /* 80 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135126 /* 90 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135127 /* 100 */ 1332, 1332, 1332, 1332, 1176, 1181, 1188, 1180, 1177, 1169,
135128 /* 110 */ 1168, 1170, 1171, 1332, 1019, 1067, 1332, 1332, 1332, 1172,
135129 /* 120 */ 1332, 1173, 1185, 1184, 1183, 1262, 1289, 1288, 1332, 1332,
135130 /* 130 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135131 /* 140 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135132 /* 150 */ 1332, 1332, 1332, 1332, 1332, 1281, 1271, 1025, 1025, 1332,
135133 /* 160 */ 1271, 1271, 1271, 1271, 1271, 1271, 1267, 1100, 1091, 1332,
135134 /* 170 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135135 /* 180 */ 1259, 1257, 1332, 1218, 1332, 1332, 1332, 1332, 1332, 1332,
135136 /* 190 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135137 /* 200 */ 1332, 1332, 1332, 1332, 1096, 1332, 1332, 1332, 1332, 1332,
135138 /* 210 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1283, 1332, 1232,
135139 /* 220 */ 1096, 1096, 1096, 1098, 1080, 1090, 1004, 1135, 1114, 1114,
135140 /* 230 */ 1321, 1135, 1321, 1042, 1303, 1039, 1125, 1114, 1200, 1125,
135141 /* 240 */ 1125, 1097, 1090, 1332, 1324, 1105, 1105, 1323, 1323, 1105,
135142 /* 250 */ 1146, 1070, 1135, 1076, 1076, 1076, 1076, 1105, 1016, 1135,
135143 /* 260 */ 1146, 1070, 1070, 1135, 1105, 1016, 1236, 1318, 1105, 1105,
135144 /* 270 */ 1016, 1211, 1105, 1016, 1105, 1016, 1211, 1068, 1068, 1068,
135145 /* 280 */ 1057, 1211, 1068, 1042, 1068, 1057, 1068, 1068, 1118, 1113,
135146 /* 290 */ 1118, 1113, 1118, 1113, 1118, 1113, 1105, 1206, 1105, 1332,
135147 /* 300 */ 1211, 1215, 1215, 1211, 1130, 1119, 1128, 1126, 1135, 1022,
135148 /* 310 */ 1060, 1286, 1286, 1282, 1282, 1282, 1282, 1329, 1329, 1267,
135149 /* 320 */ 1298, 1298, 1044, 1044, 1298, 1332, 1332, 1332, 1332, 1332,
135150 /* 330 */ 1332, 1293, 1332, 1220, 1332, 1332, 1332, 1332, 1332, 1332,
135151 /* 340 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135152 /* 350 */ 1332, 1332, 1152, 1332, 1000, 1264, 1332, 1332, 1263, 1332,
135153 /* 360 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135154 /* 370 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1320,
135155 /* 380 */ 1332, 1332, 1332, 1332, 1332, 1332, 1235, 1234, 1332, 1332,
135156 /* 390 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135157 /* 400 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135158 /* 410 */ 1332, 1082, 1332, 1332, 1332, 1307, 1332, 1332, 1332, 1332,
135159 /* 420 */ 1332, 1332, 1332, 1127, 1332, 1120, 1332, 1332, 1311, 1332,
135160 /* 430 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1273,
135161 /* 440 */ 1332, 1332, 1332, 1272, 1332, 1332, 1332, 1332, 1332, 1154,
135162 /* 450 */ 1332, 1153, 1157, 1332, 1010, 1332,
135163 };
135164 /********** End of lemon-generated parsing tables *****************************/
135165
135166 /* The next table maps tokens (terminal symbols) into fallback tokens.
@@ -135602,147 +136123,147 @@
135602 /* 169 */ "expr ::= expr EQ|NE expr",
135603 /* 170 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
135604 /* 171 */ "expr ::= expr PLUS|MINUS expr",
135605 /* 172 */ "expr ::= expr STAR|SLASH|REM expr",
135606 /* 173 */ "expr ::= expr CONCAT expr",
135607 /* 174 */ "likeop ::= LIKE_KW|MATCH",
135608 /* 175 */ "likeop ::= NOT LIKE_KW|MATCH",
135609 /* 176 */ "expr ::= expr likeop expr",
135610 /* 177 */ "expr ::= expr likeop expr ESCAPE expr",
135611 /* 178 */ "expr ::= expr ISNULL|NOTNULL",
135612 /* 179 */ "expr ::= expr NOT NULL",
135613 /* 180 */ "expr ::= expr IS expr",
135614 /* 181 */ "expr ::= expr IS NOT expr",
135615 /* 182 */ "expr ::= NOT expr",
135616 /* 183 */ "expr ::= BITNOT expr",
135617 /* 184 */ "expr ::= MINUS expr",
135618 /* 185 */ "expr ::= PLUS expr",
135619 /* 186 */ "between_op ::= BETWEEN",
135620 /* 187 */ "between_op ::= NOT BETWEEN",
135621 /* 188 */ "expr ::= expr between_op expr AND expr",
135622 /* 189 */ "in_op ::= IN",
135623 /* 190 */ "in_op ::= NOT IN",
135624 /* 191 */ "expr ::= expr in_op LP exprlist RP",
135625 /* 192 */ "expr ::= LP select RP",
135626 /* 193 */ "expr ::= expr in_op LP select RP",
135627 /* 194 */ "expr ::= expr in_op nm dbnm paren_exprlist",
135628 /* 195 */ "expr ::= EXISTS LP select RP",
135629 /* 196 */ "expr ::= CASE case_operand case_exprlist case_else END",
135630 /* 197 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
135631 /* 198 */ "case_exprlist ::= WHEN expr THEN expr",
135632 /* 199 */ "case_else ::= ELSE expr",
135633 /* 200 */ "case_else ::=",
135634 /* 201 */ "case_operand ::= expr",
135635 /* 202 */ "case_operand ::=",
135636 /* 203 */ "exprlist ::=",
135637 /* 204 */ "nexprlist ::= nexprlist COMMA expr",
135638 /* 205 */ "nexprlist ::= expr",
135639 /* 206 */ "paren_exprlist ::=",
135640 /* 207 */ "paren_exprlist ::= LP exprlist RP",
135641 /* 208 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
135642 /* 209 */ "uniqueflag ::= UNIQUE",
135643 /* 210 */ "uniqueflag ::=",
135644 /* 211 */ "eidlist_opt ::=",
135645 /* 212 */ "eidlist_opt ::= LP eidlist RP",
135646 /* 213 */ "eidlist ::= eidlist COMMA nm collate sortorder",
135647 /* 214 */ "eidlist ::= nm collate sortorder",
135648 /* 215 */ "collate ::=",
135649 /* 216 */ "collate ::= COLLATE ID|STRING",
135650 /* 217 */ "cmd ::= DROP INDEX ifexists fullname",
135651 /* 218 */ "cmd ::= VACUUM",
135652 /* 219 */ "cmd ::= VACUUM nm",
135653 /* 220 */ "cmd ::= PRAGMA nm dbnm",
135654 /* 221 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
135655 /* 222 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
135656 /* 223 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
135657 /* 224 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
135658 /* 225 */ "plus_num ::= PLUS INTEGER|FLOAT",
135659 /* 226 */ "minus_num ::= MINUS INTEGER|FLOAT",
135660 /* 227 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
135661 /* 228 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
135662 /* 229 */ "trigger_time ::= BEFORE",
135663 /* 230 */ "trigger_time ::= AFTER",
135664 /* 231 */ "trigger_time ::= INSTEAD OF",
135665 /* 232 */ "trigger_time ::=",
135666 /* 233 */ "trigger_event ::= DELETE|INSERT",
135667 /* 234 */ "trigger_event ::= UPDATE",
135668 /* 235 */ "trigger_event ::= UPDATE OF idlist",
135669 /* 236 */ "when_clause ::=",
135670 /* 237 */ "when_clause ::= WHEN expr",
135671 /* 238 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
135672 /* 239 */ "trigger_cmd_list ::= trigger_cmd SEMI",
135673 /* 240 */ "trnm ::= nm DOT nm",
135674 /* 241 */ "tridxby ::= INDEXED BY nm",
135675 /* 242 */ "tridxby ::= NOT INDEXED",
135676 /* 243 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt",
135677 /* 244 */ "trigger_cmd ::= insert_cmd INTO trnm idlist_opt select",
135678 /* 245 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt",
135679 /* 246 */ "trigger_cmd ::= select",
135680 /* 247 */ "expr ::= RAISE LP IGNORE RP",
135681 /* 248 */ "expr ::= RAISE LP raisetype COMMA nm RP",
135682 /* 249 */ "raisetype ::= ROLLBACK",
135683 /* 250 */ "raisetype ::= ABORT",
135684 /* 251 */ "raisetype ::= FAIL",
135685 /* 252 */ "cmd ::= DROP TRIGGER ifexists fullname",
135686 /* 253 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
135687 /* 254 */ "cmd ::= DETACH database_kw_opt expr",
135688 /* 255 */ "key_opt ::=",
135689 /* 256 */ "key_opt ::= KEY expr",
135690 /* 257 */ "cmd ::= REINDEX",
135691 /* 258 */ "cmd ::= REINDEX nm dbnm",
135692 /* 259 */ "cmd ::= ANALYZE",
135693 /* 260 */ "cmd ::= ANALYZE nm dbnm",
135694 /* 261 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
135695 /* 262 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist",
135696 /* 263 */ "add_column_fullname ::= fullname",
135697 /* 264 */ "cmd ::= create_vtab",
135698 /* 265 */ "cmd ::= create_vtab LP vtabarglist RP",
135699 /* 266 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
135700 /* 267 */ "vtabarg ::=",
135701 /* 268 */ "vtabargtoken ::= ANY",
135702 /* 269 */ "vtabargtoken ::= lp anylist RP",
135703 /* 270 */ "lp ::= LP",
135704 /* 271 */ "with ::=",
135705 /* 272 */ "with ::= WITH wqlist",
135706 /* 273 */ "with ::= WITH RECURSIVE wqlist",
135707 /* 274 */ "wqlist ::= nm eidlist_opt AS LP select RP",
135708 /* 275 */ "wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP",
135709 /* 276 */ "input ::= cmdlist",
135710 /* 277 */ "cmdlist ::= cmdlist ecmd",
135711 /* 278 */ "cmdlist ::= ecmd",
135712 /* 279 */ "ecmd ::= SEMI",
135713 /* 280 */ "ecmd ::= explain cmdx SEMI",
135714 /* 281 */ "explain ::=",
135715 /* 282 */ "trans_opt ::=",
135716 /* 283 */ "trans_opt ::= TRANSACTION",
135717 /* 284 */ "trans_opt ::= TRANSACTION nm",
135718 /* 285 */ "savepoint_opt ::= SAVEPOINT",
135719 /* 286 */ "savepoint_opt ::=",
135720 /* 287 */ "cmd ::= create_table create_table_args",
135721 /* 288 */ "columnlist ::= columnlist COMMA columnname carglist",
135722 /* 289 */ "columnlist ::= columnname carglist",
135723 /* 290 */ "nm ::= ID|INDEXED",
135724 /* 291 */ "nm ::= STRING",
135725 /* 292 */ "nm ::= JOIN_KW",
135726 /* 293 */ "typetoken ::= typename",
135727 /* 294 */ "typename ::= ID|STRING",
135728 /* 295 */ "signed ::= plus_num",
135729 /* 296 */ "signed ::= minus_num",
135730 /* 297 */ "carglist ::= carglist ccons",
135731 /* 298 */ "carglist ::=",
135732 /* 299 */ "ccons ::= NULL onconf",
135733 /* 300 */ "conslist_opt ::= COMMA conslist",
135734 /* 301 */ "conslist ::= conslist tconscomma tcons",
135735 /* 302 */ "conslist ::= tcons",
135736 /* 303 */ "tconscomma ::=",
135737 /* 304 */ "defer_subclause_opt ::= defer_subclause",
135738 /* 305 */ "resolvetype ::= raisetype",
135739 /* 306 */ "selectnowith ::= oneselect",
135740 /* 307 */ "oneselect ::= values",
135741 /* 308 */ "sclp ::= selcollist COMMA",
135742 /* 309 */ "as ::= ID|STRING",
135743 /* 310 */ "expr ::= term",
135744 /* 311 */ "exprlist ::= nexprlist",
135745 /* 312 */ "nmnum ::= plus_num",
135746 /* 313 */ "nmnum ::= nm",
135747 /* 314 */ "nmnum ::= ON",
135748 /* 315 */ "nmnum ::= DELETE",
@@ -136375,11 +136896,10 @@
136375 { 173, 3 },
136376 { 173, 3 },
136377 { 173, 3 },
136378 { 173, 3 },
136379 { 173, 3 },
136380 { 221, 1 },
136381 { 221, 2 },
136382 { 173, 3 },
136383 { 173, 5 },
136384 { 173, 2 },
136385 { 173, 3 },
@@ -136512,10 +137032,11 @@
136512 { 194, 1 },
136513 { 195, 1 },
136514 { 209, 2 },
136515 { 210, 1 },
136516 { 173, 1 },
 
136517 { 208, 1 },
136518 { 230, 1 },
136519 { 230, 1 },
136520 { 230, 1 },
136521 { 230, 1 },
@@ -136654,11 +137175,11 @@
136654 case 42: /* autoinc ::= */ yytestcase(yyruleno==42);
136655 case 57: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==57);
136656 case 67: /* defer_subclause_opt ::= */ yytestcase(yyruleno==67);
136657 case 76: /* ifexists ::= */ yytestcase(yyruleno==76);
136658 case 90: /* distinct ::= */ yytestcase(yyruleno==90);
136659 case 215: /* collate ::= */ yytestcase(yyruleno==215);
136660 {yymsp[1].minor.yy194 = 0;}
136661 break;
136662 case 17: /* ifnotexists ::= IF NOT EXISTS */
136663 {yymsp[-2].minor.yy194 = 1;}
136664 break;
@@ -136798,13 +137319,13 @@
136798 case 144: /* insert_cmd ::= INSERT orconf */ yytestcase(yyruleno==144);
136799 {yymsp[-1].minor.yy194 = yymsp[0].minor.yy194;}
136800 break;
136801 case 58: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
136802 case 75: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==75);
136803 case 187: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==187);
136804 case 190: /* in_op ::= NOT IN */ yytestcase(yyruleno==190);
136805 case 216: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==216);
136806 {yymsp[-1].minor.yy194 = 1;}
136807 break;
136808 case 59: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
136809 {yymsp[-1].minor.yy194 = 0;}
136810 break;
@@ -136964,13 +137485,13 @@
136964 {yymsp[0].minor.yy194 = SF_All;}
136965 break;
136966 case 91: /* sclp ::= */
136967 case 119: /* orderby_opt ::= */ yytestcase(yyruleno==119);
136968 case 126: /* groupby_opt ::= */ yytestcase(yyruleno==126);
136969 case 203: /* exprlist ::= */ yytestcase(yyruleno==203);
136970 case 206: /* paren_exprlist ::= */ yytestcase(yyruleno==206);
136971 case 211: /* eidlist_opt ::= */ yytestcase(yyruleno==211);
136972 {yymsp[1].minor.yy148 = 0;}
136973 break;
136974 case 92: /* selcollist ::= sclp expr as */
136975 {
136976 yymsp[-2].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy148, yymsp[-1].minor.yy190.pExpr);
@@ -136992,12 +137513,12 @@
136992 yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148, pDot);
136993 }
136994 break;
136995 case 95: /* as ::= AS nm */
136996 case 106: /* dbnm ::= DOT nm */ yytestcase(yyruleno==106);
136997 case 225: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==225);
136998 case 226: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==226);
136999 {yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
137000 break;
137001 case 97: /* from ::= */
137002 {yymsp[1].minor.yy185 = sqlite3DbMallocZero(pParse->db, sizeof(*yymsp[1].minor.yy185));}
137003 break;
@@ -137076,18 +137597,18 @@
137076 {yymsp[-3].minor.yy194 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/}
137077 break;
137078 case 112: /* on_opt ::= ON expr */
137079 case 129: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==129);
137080 case 136: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==136);
137081 case 199: /* case_else ::= ELSE expr */ yytestcase(yyruleno==199);
137082 {yymsp[-1].minor.yy72 = yymsp[0].minor.yy190.pExpr;}
137083 break;
137084 case 113: /* on_opt ::= */
137085 case 128: /* having_opt ::= */ yytestcase(yyruleno==128);
137086 case 135: /* where_opt ::= */ yytestcase(yyruleno==135);
137087 case 200: /* case_else ::= */ yytestcase(yyruleno==200);
137088 case 202: /* case_operand ::= */ yytestcase(yyruleno==202);
137089 {yymsp[1].minor.yy72 = 0;}
137090 break;
137091 case 115: /* indexed_opt ::= INDEXED BY nm */
137092 {yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;}
137093 break;
@@ -137230,11 +137751,11 @@
137230 case 158: /* term ::= INTEGER */
137231 {
137232 yylhsminor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
137233 yylhsminor.yy190.zStart = yymsp[0].minor.yy0.z;
137234 yylhsminor.yy190.zEnd = yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n;
137235 if( yylhsminor.yy190.pExpr ) yylhsminor.yy190.pExpr->flags |= EP_Leaf;
137236 }
137237 yymsp[0].minor.yy190 = yylhsminor.yy190;
137238 break;
137239 case 159: /* expr ::= VARIABLE */
137240 {
@@ -137320,17 +137841,14 @@
137320 case 171: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==171);
137321 case 172: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==172);
137322 case 173: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==173);
137323 {spanBinaryExpr(pParse,yymsp[-1].major,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy190);}
137324 break;
137325 case 174: /* likeop ::= LIKE_KW|MATCH */
137326 {yymsp[0].minor.yy0=yymsp[0].minor.yy0;/*A-overwrites-X*/}
137327 break;
137328 case 175: /* likeop ::= NOT LIKE_KW|MATCH */
137329 {yymsp[-1].minor.yy0=yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n|=0x80000000; /*yymsp[-1].minor.yy0-overwrite-yymsp[0].minor.yy0*/}
137330 break;
137331 case 176: /* expr ::= expr likeop expr */
137332 {
137333 ExprList *pList;
137334 int bNot = yymsp[-1].minor.yy0.n & 0x80000000;
137335 yymsp[-1].minor.yy0.n &= 0x7fffffff;
137336 pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy190.pExpr);
@@ -137339,11 +137857,11 @@
137339 exprNot(pParse, bNot, &yymsp[-2].minor.yy190);
137340 yymsp[-2].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd;
137341 if( yymsp[-2].minor.yy190.pExpr ) yymsp[-2].minor.yy190.pExpr->flags |= EP_InfixFunc;
137342 }
137343 break;
137344 case 177: /* expr ::= expr likeop expr ESCAPE expr */
137345 {
137346 ExprList *pList;
137347 int bNot = yymsp[-3].minor.yy0.n & 0x80000000;
137348 yymsp[-3].minor.yy0.n &= 0x7fffffff;
137349 pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr);
@@ -137353,43 +137871,43 @@
137353 exprNot(pParse, bNot, &yymsp[-4].minor.yy190);
137354 yymsp[-4].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd;
137355 if( yymsp[-4].minor.yy190.pExpr ) yymsp[-4].minor.yy190.pExpr->flags |= EP_InfixFunc;
137356 }
137357 break;
137358 case 178: /* expr ::= expr ISNULL|NOTNULL */
137359 {spanUnaryPostfix(pParse,yymsp[0].major,&yymsp[-1].minor.yy190,&yymsp[0].minor.yy0);}
137360 break;
137361 case 179: /* expr ::= expr NOT NULL */
137362 {spanUnaryPostfix(pParse,TK_NOTNULL,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy0);}
137363 break;
137364 case 180: /* expr ::= expr IS expr */
137365 {
137366 spanBinaryExpr(pParse,TK_IS,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy190);
137367 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy190.pExpr, yymsp[-2].minor.yy190.pExpr, TK_ISNULL);
137368 }
137369 break;
137370 case 181: /* expr ::= expr IS NOT expr */
137371 {
137372 spanBinaryExpr(pParse,TK_ISNOT,&yymsp[-3].minor.yy190,&yymsp[0].minor.yy190);
137373 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy190.pExpr, yymsp[-3].minor.yy190.pExpr, TK_NOTNULL);
137374 }
137375 break;
137376 case 182: /* expr ::= NOT expr */
137377 case 183: /* expr ::= BITNOT expr */ yytestcase(yyruleno==183);
137378 {spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,yymsp[-1].major,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/}
137379 break;
137380 case 184: /* expr ::= MINUS expr */
137381 {spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,TK_UMINUS,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/}
137382 break;
137383 case 185: /* expr ::= PLUS expr */
137384 {spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,TK_UPLUS,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/}
137385 break;
137386 case 186: /* between_op ::= BETWEEN */
137387 case 189: /* in_op ::= IN */ yytestcase(yyruleno==189);
137388 {yymsp[0].minor.yy194 = 0;}
137389 break;
137390 case 188: /* expr ::= expr between_op expr AND expr */
137391 {
137392 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr);
137393 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy190.pExpr);
137394 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy190.pExpr, 0);
137395 if( yymsp[-4].minor.yy190.pExpr ){
@@ -137399,11 +137917,11 @@
137399 }
137400 exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
137401 yymsp[-4].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd;
137402 }
137403 break;
137404 case 191: /* expr ::= expr in_op LP exprlist RP */
137405 {
137406 if( yymsp[-1].minor.yy148==0 ){
137407 /* Expressions of the form
137408 **
137409 ** expr1 IN ()
@@ -137452,26 +137970,26 @@
137452 exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
137453 }
137454 yymsp[-4].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
137455 }
137456 break;
137457 case 192: /* expr ::= LP select RP */
137458 {
137459 spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
137460 yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
137461 sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy190.pExpr, yymsp[-1].minor.yy243);
137462 }
137463 break;
137464 case 193: /* expr ::= expr in_op LP select RP */
137465 {
137466 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
137467 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, yymsp[-1].minor.yy243);
137468 exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
137469 yymsp[-4].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
137470 }
137471 break;
137472 case 194: /* expr ::= expr in_op nm dbnm paren_exprlist */
137473 {
137474 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
137475 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
137476 if( yymsp[0].minor.yy148 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy148);
137477 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
@@ -137478,19 +137996,19 @@
137478 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, pSelect);
137479 exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
137480 yymsp[-4].minor.yy190.zEnd = yymsp[-1].minor.yy0.z ? &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n] : &yymsp[-2].minor.yy0.z[yymsp[-2].minor.yy0.n];
137481 }
137482 break;
137483 case 195: /* expr ::= EXISTS LP select RP */
137484 {
137485 Expr *p;
137486 spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
137487 p = yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
137488 sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy243);
137489 }
137490 break;
137491 case 196: /* expr ::= CASE case_operand case_exprlist case_else END */
137492 {
137493 spanSet(&yymsp[-4].minor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-C*/
137494 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy72, 0);
137495 if( yymsp[-4].minor.yy190.pExpr ){
137496 yymsp[-4].minor.yy190.pExpr->x.pList = yymsp[-1].minor.yy72 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy148,yymsp[-1].minor.yy72) : yymsp[-2].minor.yy148;
@@ -137499,313 +138017,314 @@
137499 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy148);
137500 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy72);
137501 }
137502 }
137503 break;
137504 case 197: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
137505 {
137506 yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy148, yymsp[-2].minor.yy190.pExpr);
137507 yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy148, yymsp[0].minor.yy190.pExpr);
137508 }
137509 break;
137510 case 198: /* case_exprlist ::= WHEN expr THEN expr */
137511 {
137512 yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr);
137513 yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148, yymsp[0].minor.yy190.pExpr);
137514 }
137515 break;
137516 case 201: /* case_operand ::= expr */
137517 {yymsp[0].minor.yy72 = yymsp[0].minor.yy190.pExpr; /*A-overwrites-X*/}
137518 break;
137519 case 204: /* nexprlist ::= nexprlist COMMA expr */
137520 {yymsp[-2].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy148,yymsp[0].minor.yy190.pExpr);}
137521 break;
137522 case 205: /* nexprlist ::= expr */
137523 {yymsp[0].minor.yy148 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy190.pExpr); /*A-overwrites-Y*/}
137524 break;
137525 case 207: /* paren_exprlist ::= LP exprlist RP */
137526 case 212: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==212);
137527 {yymsp[-2].minor.yy148 = yymsp[-1].minor.yy148;}
137528 break;
137529 case 208: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
137530 {
137531 sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
137532 sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy148, yymsp[-10].minor.yy194,
137533 &yymsp[-11].minor.yy0, yymsp[0].minor.yy72, SQLITE_SO_ASC, yymsp[-8].minor.yy194, SQLITE_IDXTYPE_APPDEF);
137534 }
137535 break;
137536 case 209: /* uniqueflag ::= UNIQUE */
137537 case 250: /* raisetype ::= ABORT */ yytestcase(yyruleno==250);
137538 {yymsp[0].minor.yy194 = OE_Abort;}
137539 break;
137540 case 210: /* uniqueflag ::= */
137541 {yymsp[1].minor.yy194 = OE_None;}
137542 break;
137543 case 213: /* eidlist ::= eidlist COMMA nm collate sortorder */
137544 {
137545 yymsp[-4].minor.yy148 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy148, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy194, yymsp[0].minor.yy194);
137546 }
137547 break;
137548 case 214: /* eidlist ::= nm collate sortorder */
137549 {
137550 yymsp[-2].minor.yy148 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy194, yymsp[0].minor.yy194); /*A-overwrites-Y*/
137551 }
137552 break;
137553 case 217: /* cmd ::= DROP INDEX ifexists fullname */
137554 {sqlite3DropIndex(pParse, yymsp[0].minor.yy185, yymsp[-1].minor.yy194);}
137555 break;
137556 case 218: /* cmd ::= VACUUM */
137557 {sqlite3Vacuum(pParse,0);}
137558 break;
137559 case 219: /* cmd ::= VACUUM nm */
137560 {sqlite3Vacuum(pParse,&yymsp[0].minor.yy0);}
137561 break;
137562 case 220: /* cmd ::= PRAGMA nm dbnm */
137563 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
137564 break;
137565 case 221: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
137566 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
137567 break;
137568 case 222: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
137569 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
137570 break;
137571 case 223: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
137572 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
137573 break;
137574 case 224: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
137575 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
137576 break;
137577 case 227: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
137578 {
137579 Token all;
137580 all.z = yymsp[-3].minor.yy0.z;
137581 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
137582 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy145, &all);
137583 }
137584 break;
137585 case 228: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
137586 {
137587 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy194, yymsp[-4].minor.yy332.a, yymsp[-4].minor.yy332.b, yymsp[-2].minor.yy185, yymsp[0].minor.yy72, yymsp[-10].minor.yy194, yymsp[-8].minor.yy194);
137588 yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
137589 }
137590 break;
137591 case 229: /* trigger_time ::= BEFORE */
137592 { yymsp[0].minor.yy194 = TK_BEFORE; }
137593 break;
137594 case 230: /* trigger_time ::= AFTER */
137595 { yymsp[0].minor.yy194 = TK_AFTER; }
137596 break;
137597 case 231: /* trigger_time ::= INSTEAD OF */
137598 { yymsp[-1].minor.yy194 = TK_INSTEAD;}
137599 break;
137600 case 232: /* trigger_time ::= */
137601 { yymsp[1].minor.yy194 = TK_BEFORE; }
137602 break;
137603 case 233: /* trigger_event ::= DELETE|INSERT */
137604 case 234: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==234);
137605 {yymsp[0].minor.yy332.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy332.b = 0;}
137606 break;
137607 case 235: /* trigger_event ::= UPDATE OF idlist */
137608 {yymsp[-2].minor.yy332.a = TK_UPDATE; yymsp[-2].minor.yy332.b = yymsp[0].minor.yy254;}
137609 break;
137610 case 236: /* when_clause ::= */
137611 case 255: /* key_opt ::= */ yytestcase(yyruleno==255);
137612 { yymsp[1].minor.yy72 = 0; }
137613 break;
137614 case 237: /* when_clause ::= WHEN expr */
137615 case 256: /* key_opt ::= KEY expr */ yytestcase(yyruleno==256);
137616 { yymsp[-1].minor.yy72 = yymsp[0].minor.yy190.pExpr; }
137617 break;
137618 case 238: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
137619 {
137620 assert( yymsp[-2].minor.yy145!=0 );
137621 yymsp[-2].minor.yy145->pLast->pNext = yymsp[-1].minor.yy145;
137622 yymsp[-2].minor.yy145->pLast = yymsp[-1].minor.yy145;
137623 }
137624 break;
137625 case 239: /* trigger_cmd_list ::= trigger_cmd SEMI */
137626 {
137627 assert( yymsp[-1].minor.yy145!=0 );
137628 yymsp[-1].minor.yy145->pLast = yymsp[-1].minor.yy145;
137629 }
137630 break;
137631 case 240: /* trnm ::= nm DOT nm */
137632 {
137633 yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
137634 sqlite3ErrorMsg(pParse,
137635 "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
137636 "statements within triggers");
137637 }
137638 break;
137639 case 241: /* tridxby ::= INDEXED BY nm */
137640 {
137641 sqlite3ErrorMsg(pParse,
137642 "the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
137643 "within triggers");
137644 }
137645 break;
137646 case 242: /* tridxby ::= NOT INDEXED */
137647 {
137648 sqlite3ErrorMsg(pParse,
137649 "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
137650 "within triggers");
137651 }
137652 break;
137653 case 243: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
137654 {yymsp[-6].minor.yy145 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy148, yymsp[0].minor.yy72, yymsp[-5].minor.yy194);}
137655 break;
137656 case 244: /* trigger_cmd ::= insert_cmd INTO trnm idlist_opt select */
137657 {yymsp[-4].minor.yy145 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy254, yymsp[0].minor.yy243, yymsp[-4].minor.yy194);/*A-overwrites-R*/}
137658 break;
137659 case 245: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
137660 {yymsp[-4].minor.yy145 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy72);}
137661 break;
137662 case 246: /* trigger_cmd ::= select */
137663 {yymsp[0].minor.yy145 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy243); /*A-overwrites-X*/}
137664 break;
137665 case 247: /* expr ::= RAISE LP IGNORE RP */
137666 {
137667 spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
137668 yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
137669 if( yymsp[-3].minor.yy190.pExpr ){
137670 yymsp[-3].minor.yy190.pExpr->affinity = OE_Ignore;
137671 }
137672 }
137673 break;
137674 case 248: /* expr ::= RAISE LP raisetype COMMA nm RP */
137675 {
137676 spanSet(&yymsp[-5].minor.yy190,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
137677 yymsp[-5].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
137678 if( yymsp[-5].minor.yy190.pExpr ) {
137679 yymsp[-5].minor.yy190.pExpr->affinity = (char)yymsp[-3].minor.yy194;
137680 }
137681 }
137682 break;
137683 case 249: /* raisetype ::= ROLLBACK */
137684 {yymsp[0].minor.yy194 = OE_Rollback;}
137685 break;
137686 case 251: /* raisetype ::= FAIL */
137687 {yymsp[0].minor.yy194 = OE_Fail;}
137688 break;
137689 case 252: /* cmd ::= DROP TRIGGER ifexists fullname */
137690 {
137691 sqlite3DropTrigger(pParse,yymsp[0].minor.yy185,yymsp[-1].minor.yy194);
137692 }
137693 break;
137694 case 253: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
137695 {
137696 sqlite3Attach(pParse, yymsp[-3].minor.yy190.pExpr, yymsp[-1].minor.yy190.pExpr, yymsp[0].minor.yy72);
137697 }
137698 break;
137699 case 254: /* cmd ::= DETACH database_kw_opt expr */
137700 {
137701 sqlite3Detach(pParse, yymsp[0].minor.yy190.pExpr);
137702 }
137703 break;
137704 case 257: /* cmd ::= REINDEX */
137705 {sqlite3Reindex(pParse, 0, 0);}
137706 break;
137707 case 258: /* cmd ::= REINDEX nm dbnm */
137708 {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
137709 break;
137710 case 259: /* cmd ::= ANALYZE */
137711 {sqlite3Analyze(pParse, 0, 0);}
137712 break;
137713 case 260: /* cmd ::= ANALYZE nm dbnm */
137714 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
137715 break;
137716 case 261: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
137717 {
137718 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy185,&yymsp[0].minor.yy0);
137719 }
137720 break;
137721 case 262: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
137722 {
137723 yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n;
137724 sqlite3AlterFinishAddColumn(pParse, &yymsp[-1].minor.yy0);
137725 }
137726 break;
137727 case 263: /* add_column_fullname ::= fullname */
137728 {
137729 disableLookaside(pParse);
137730 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy185);
137731 }
137732 break;
137733 case 264: /* cmd ::= create_vtab */
137734 {sqlite3VtabFinishParse(pParse,0);}
137735 break;
137736 case 265: /* cmd ::= create_vtab LP vtabarglist RP */
137737 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
137738 break;
137739 case 266: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
137740 {
137741 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy194);
137742 }
137743 break;
137744 case 267: /* vtabarg ::= */
137745 {sqlite3VtabArgInit(pParse);}
137746 break;
137747 case 268: /* vtabargtoken ::= ANY */
137748 case 269: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==269);
137749 case 270: /* lp ::= LP */ yytestcase(yyruleno==270);
137750 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
137751 break;
137752 case 271: /* with ::= */
137753 {yymsp[1].minor.yy285 = 0;}
137754 break;
137755 case 272: /* with ::= WITH wqlist */
137756 { yymsp[-1].minor.yy285 = yymsp[0].minor.yy285; }
137757 break;
137758 case 273: /* with ::= WITH RECURSIVE wqlist */
137759 { yymsp[-2].minor.yy285 = yymsp[0].minor.yy285; }
137760 break;
137761 case 274: /* wqlist ::= nm eidlist_opt AS LP select RP */
137762 {
137763 yymsp[-5].minor.yy285 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy148, yymsp[-1].minor.yy243); /*A-overwrites-X*/
137764 }
137765 break;
137766 case 275: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
137767 {
137768 yymsp[-7].minor.yy285 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy285, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy148, yymsp[-1].minor.yy243);
137769 }
137770 break;
137771 default:
137772 /* (276) input ::= cmdlist */ yytestcase(yyruleno==276);
137773 /* (277) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==277);
137774 /* (278) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=278);
137775 /* (279) ecmd ::= SEMI */ yytestcase(yyruleno==279);
137776 /* (280) ecmd ::= explain cmdx SEMI */ yytestcase(yyruleno==280);
137777 /* (281) explain ::= */ yytestcase(yyruleno==281);
137778 /* (282) trans_opt ::= */ yytestcase(yyruleno==282);
137779 /* (283) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==283);
137780 /* (284) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==284);
137781 /* (285) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==285);
137782 /* (286) savepoint_opt ::= */ yytestcase(yyruleno==286);
137783 /* (287) cmd ::= create_table create_table_args */ yytestcase(yyruleno==287);
137784 /* (288) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==288);
137785 /* (289) columnlist ::= columnname carglist */ yytestcase(yyruleno==289);
137786 /* (290) nm ::= ID|INDEXED */ yytestcase(yyruleno==290);
137787 /* (291) nm ::= STRING */ yytestcase(yyruleno==291);
137788 /* (292) nm ::= JOIN_KW */ yytestcase(yyruleno==292);
137789 /* (293) typetoken ::= typename */ yytestcase(yyruleno==293);
137790 /* (294) typename ::= ID|STRING */ yytestcase(yyruleno==294);
137791 /* (295) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=295);
137792 /* (296) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=296);
137793 /* (297) carglist ::= carglist ccons */ yytestcase(yyruleno==297);
137794 /* (298) carglist ::= */ yytestcase(yyruleno==298);
137795 /* (299) ccons ::= NULL onconf */ yytestcase(yyruleno==299);
137796 /* (300) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==300);
137797 /* (301) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==301);
137798 /* (302) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=302);
137799 /* (303) tconscomma ::= */ yytestcase(yyruleno==303);
137800 /* (304) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=304);
137801 /* (305) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=305);
137802 /* (306) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=306);
137803 /* (307) oneselect ::= values */ yytestcase(yyruleno==307);
137804 /* (308) sclp ::= selcollist COMMA */ yytestcase(yyruleno==308);
137805 /* (309) as ::= ID|STRING */ yytestcase(yyruleno==309);
137806 /* (310) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=310);
 
137807 /* (311) exprlist ::= nexprlist */ yytestcase(yyruleno==311);
137808 /* (312) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=312);
137809 /* (313) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=313);
137810 /* (314) nmnum ::= ON */ yytestcase(yyruleno==314);
137811 /* (315) nmnum ::= DELETE */ yytestcase(yyruleno==315);
@@ -138854,12 +139373,12 @@
138854 ** memory obtained from sqlite3_malloc() and to make *pzErrMsg point to that
138855 ** error message.
138856 */
138857 SQLITE_PRIVATE int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
138858 int nErr = 0; /* Number of errors encountered */
138859 int i; /* Loop counter */
138860 void *pEngine; /* The LEMON-generated LALR(1) parser */
 
138861 int tokenType; /* type of the next token */
138862 int lastTokenParsed = -1; /* type of the previous token */
138863 sqlite3 *db = pParse->db; /* The database connection */
138864 int mxSqlLen; /* Max length of an SQL string */
138865 #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
@@ -138871,11 +139390,10 @@
138871 if( db->nVdbeActive==0 ){
138872 db->u1.isInterrupted = 0;
138873 }
138874 pParse->rc = SQLITE_OK;
138875 pParse->zTail = zSql;
138876 i = 0;
138877 assert( pzErrMsg!=0 );
138878 /* sqlite3ParserTrace(stdout, "parser: "); */
138879 #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
138880 pEngine = zSpace;
138881 sqlite3ParserInit(pEngine);
@@ -138889,16 +139407,14 @@
138889 assert( pParse->pNewTable==0 );
138890 assert( pParse->pNewTrigger==0 );
138891 assert( pParse->nVar==0 );
138892 assert( pParse->pVList==0 );
138893 while( 1 ){
138894 assert( i>=0 );
138895 if( zSql[i]!=0 ){
138896 pParse->sLastToken.z = &zSql[i];
138897 pParse->sLastToken.n = sqlite3GetToken((u8*)&zSql[i],&tokenType);
138898 i += pParse->sLastToken.n;
138899 if( i>mxSqlLen ){
138900 pParse->rc = SQLITE_TOOBIG;
138901 break;
138902 }
138903 }else{
138904 /* Upon reaching the end of input, call the parser two more times
@@ -138908,30 +139424,34 @@
138908 }else if( lastTokenParsed==0 ){
138909 break;
138910 }else{
138911 tokenType = TK_SEMI;
138912 }
 
138913 }
138914 if( tokenType>=TK_SPACE ){
138915 assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
138916 if( db->u1.isInterrupted ){
138917 pParse->rc = SQLITE_INTERRUPT;
138918 break;
138919 }
138920 if( tokenType==TK_ILLEGAL ){
138921 sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"",
138922 &pParse->sLastToken);
138923 break;
138924 }
 
138925 }else{
 
 
138926 sqlite3Parser(pEngine, tokenType, pParse->sLastToken, pParse);
138927 lastTokenParsed = tokenType;
 
138928 if( pParse->rc!=SQLITE_OK || db->mallocFailed ) break;
138929 }
138930 }
138931 assert( nErr==0 );
138932 pParse->zTail = &zSql[i];
138933 #ifdef YYTRACKMAXSTACKDEPTH
138934 sqlite3_mutex_enter(sqlite3MallocMutex());
138935 sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
138936 sqlite3ParserStackPeak(pEngine)
138937 );
@@ -140301,10 +140821,25 @@
140301 return 0;
140302 }
140303 #endif
140304 return db->lastRowid;
140305 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140306
140307 /*
140308 ** Return the number of changes in the most recent call to sqlite3_exec().
140309 */
140310 SQLITE_API int sqlite3_changes(sqlite3 *db){
@@ -145052,12 +145587,13 @@
145052 /*
145053 ** Read a 64-bit variable-length integer from memory starting at p[0].
145054 ** Return the number of bytes read, or 0 on error.
145055 ** The value is stored in *v.
145056 */
145057 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *p, sqlite_int64 *v){
145058 const char *pStart = p;
 
145059 u32 a;
145060 u64 b;
145061 int shift;
145062
145063 GETVARINT_INIT(a, p, 0, 0x00, 0x80, *v, 1);
@@ -146100,11 +146636,13 @@
146100 /* Fill in the azColumn array */
146101 for(iCol=0; iCol<nCol; iCol++){
146102 char *z;
146103 int n = 0;
146104 z = (char *)sqlite3Fts3NextToken(aCol[iCol], &n);
146105 memcpy(zCsr, z, n);
 
 
146106 zCsr[n] = '\0';
146107 sqlite3Fts3Dequote(zCsr);
146108 p->azColumn[iCol] = zCsr;
146109 zCsr += n+1;
146110 assert( zCsr <= &((char *)p)[nByte] );
@@ -148111,12 +148649,14 @@
148111 ** segments.
148112 */
148113 const u32 nMinMerge = 64; /* Minimum amount of incr-merge work to do */
148114
148115 Fts3Table *p = (Fts3Table*)pVtab;
148116 int rc = sqlite3Fts3PendingTermsFlush(p);
 
148117
 
148118 if( rc==SQLITE_OK
148119 && p->nLeafAdd>(nMinMerge/16)
148120 && p->nAutoincrmerge && p->nAutoincrmerge!=0xff
148121 ){
148122 int mxLevel = 0; /* Maximum relative level value in db */
@@ -148127,10 +148667,11 @@
148127 A = p->nLeafAdd * mxLevel;
148128 A += (A/2);
148129 if( A>(int)nMinMerge ) rc = sqlite3Fts3Incrmerge(p, A, p->nAutoincrmerge);
148130 }
148131 sqlite3Fts3SegmentsClose(p);
 
148132 return rc;
148133 }
148134
148135 /*
148136 ** If it is currently unknown whether or not the FTS table has an %_stat
@@ -159737,15 +160278,18 @@
159737
159738 /*
159739 ** Convert the text beginning at *pz into an integer and return
159740 ** its value. Advance *pz to point to the first character past
159741 ** the integer.
 
 
 
159742 */
159743 static int fts3Getint(const char **pz){
159744 const char *z = *pz;
159745 int i = 0;
159746 while( (*z)>='0' && (*z)<='9' ) i = 10*i + *(z++) - '0';
159747 *pz = z;
159748 return i;
159749 }
159750
159751 /*
@@ -162307,20 +162851,20 @@
162307 const char *zIn, /* Array of characters to make exceptions */
162308 int nIn /* Length of z in bytes */
162309 ){
162310 const unsigned char *z = (const unsigned char *)zIn;
162311 const unsigned char *zTerm = &z[nIn];
162312 int iCode;
162313 int nEntry = 0;
162314
162315 assert( bAlnum==0 || bAlnum==1 );
162316
162317 while( z<zTerm ){
162318 READ_UTF8(z, zTerm, iCode);
162319 assert( (sqlite3FtsUnicodeIsalnum(iCode) & 0xFFFFFFFE)==0 );
162320 if( sqlite3FtsUnicodeIsalnum(iCode)!=bAlnum
162321 && sqlite3FtsUnicodeIsdiacritic(iCode)==0
162322 ){
162323 nEntry++;
162324 }
162325 }
162326
@@ -162333,17 +162877,17 @@
162333 nNew = p->nException;
162334
162335 z = (const unsigned char *)zIn;
162336 while( z<zTerm ){
162337 READ_UTF8(z, zTerm, iCode);
162338 if( sqlite3FtsUnicodeIsalnum(iCode)!=bAlnum
162339 && sqlite3FtsUnicodeIsdiacritic(iCode)==0
162340 ){
162341 int i, j;
162342 for(i=0; i<nNew && aNew[i]<iCode; i++);
162343 for(j=nNew; j>i; j--) aNew[j] = aNew[j-1];
162344 aNew[i] = iCode;
162345 nNew++;
162346 }
162347 }
162348 p->aiException = aNew;
162349 p->nException = nNew;
@@ -162489,11 +163033,11 @@
162489 int *piEnd, /* OUT: Ending offset of token */
162490 int *piPos /* OUT: Position integer of token */
162491 ){
162492 unicode_cursor *pCsr = (unicode_cursor *)pC;
162493 unicode_tokenizer *p = ((unicode_tokenizer *)pCsr->base.pTokenizer);
162494 int iCode = 0;
162495 char *zOut;
162496 const unsigned char *z = &pCsr->aInput[pCsr->iOff];
162497 const unsigned char *zStart = z;
162498 const unsigned char *zEnd;
162499 const unsigned char *zTerm = &pCsr->aInput[pCsr->nInput];
@@ -162501,11 +163045,11 @@
162501 /* Scan past any delimiter characters before the start of the next token.
162502 ** Return SQLITE_DONE early if this takes us all the way to the end of
162503 ** the input. */
162504 while( z<zTerm ){
162505 READ_UTF8(z, zTerm, iCode);
162506 if( unicodeIsAlnum(p, iCode) ) break;
162507 zStart = z;
162508 }
162509 if( zStart>=zTerm ) return SQLITE_DONE;
162510
162511 zOut = pCsr->zToken;
@@ -162521,20 +163065,20 @@
162521 pCsr->nAlloc += 64;
162522 }
162523
162524 /* Write the folded case of the last character read to the output */
162525 zEnd = z;
162526 iOut = sqlite3FtsUnicodeFold(iCode, p->bRemoveDiacritic);
162527 if( iOut ){
162528 WRITE_UTF8(zOut, iOut);
162529 }
162530
162531 /* If the cursor is not at EOF, read the next character */
162532 if( z>=zTerm ) break;
162533 READ_UTF8(z, zTerm, iCode);
162534 }while( unicodeIsAlnum(p, iCode)
162535 || sqlite3FtsUnicodeIsdiacritic(iCode)
162536 );
162537
162538 /* Set the output variables and return. */
162539 pCsr->iOff = (int)(z - pCsr->aInput);
162540 *paToken = pCsr->zToken;
@@ -162694,13 +163238,13 @@
162694 };
162695 static const unsigned int aAscii[4] = {
162696 0xFFFFFFFF, 0xFC00FFFF, 0xF8000001, 0xF8000001,
162697 };
162698
162699 if( c<128 ){
162700 return ( (aAscii[c >> 5] & (1 << (c & 0x001F)))==0 );
162701 }else if( c<(1<<22) ){
162702 unsigned int key = (((unsigned int)c)<<10) | 0x000003FF;
162703 int iRes = 0;
162704 int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1;
162705 int iLo = 0;
162706 while( iHi>=iLo ){
@@ -162889,20 +163433,21 @@
162889 65514, 65521, 65527, 65528, 65529,
162890 };
162891
162892 int ret = c;
162893
162894 assert( c>=0 );
162895 assert( sizeof(unsigned short)==2 && sizeof(unsigned char)==1 );
162896
162897 if( c<128 ){
162898 if( c>='A' && c<='Z' ) ret = c + ('a' - 'A');
162899 }else if( c<65536 ){
 
162900 int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1;
162901 int iLo = 0;
162902 int iRes = -1;
162903
 
162904 while( iHi>=iLo ){
162905 int iTest = (iHi + iLo) / 2;
162906 int cmp = (c - aEntry[iTest].iCode);
162907 if( cmp>=0 ){
162908 iRes = iTest;
@@ -162909,18 +163454,16 @@
162909 iLo = iTest+1;
162910 }else{
162911 iHi = iTest-1;
162912 }
162913 }
162914 assert( iRes<0 || c>=aEntry[iRes].iCode );
162915
162916 if( iRes>=0 ){
162917 const struct TableEntry *p = &aEntry[iRes];
162918 if( c<(p->iCode + p->nRange) && 0==(0x01 & p->flags & (p->iCode ^ c)) ){
162919 ret = (c + (aiOff[p->flags>>1])) & 0x0000FFFF;
162920 assert( ret>0 );
162921 }
162922 }
162923
162924 if( bRemoveDiacritic ) ret = remove_diacritic(ret);
162925 }
162926
@@ -163393,19 +163936,19 @@
163393 #elif SQLITE_BYTEORDER==4321
163394 i64 x;
163395 memcpy(&x, p, 8);
163396 return x;
163397 #else
163398 return (
163399 (((i64)p[0]) << 56) +
163400 (((i64)p[1]) << 48) +
163401 (((i64)p[2]) << 40) +
163402 (((i64)p[3]) << 32) +
163403 (((i64)p[4]) << 24) +
163404 (((i64)p[5]) << 16) +
163405 (((i64)p[6]) << 8) +
163406 (((i64)p[7]) << 0)
163407 );
163408 #endif
163409 }
163410
163411 /*
@@ -168462,10 +169005,11 @@
168462 int nStep; /* Rows processed for current object */
168463 int nProgress; /* Rows processed for all objects */
168464 RbuObjIter objiter; /* Iterator for skipping through tbl/idx */
168465 const char *zVfsName; /* Name of automatically created rbu vfs */
168466 rbu_file *pTargetFd; /* File handle open on target db */
 
168467 i64 iOalSz;
168468 i64 nPhaseOneStep;
168469
168470 /* The following state variables are used as part of the incremental
168471 ** checkpoint stage (eStage==RBU_STAGE_CKPT). See comments surrounding
@@ -170726,10 +171270,27 @@
170726
170727 if( p->rc==SQLITE_OK ){
170728 if( p->nFrame==0 || (pState && pState->iWalCksum!=p->iWalCksum) ){
170729 p->rc = SQLITE_DONE;
170730 p->eStage = RBU_STAGE_DONE;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170731 }
170732 }
170733 }
170734
170735 /*
@@ -171381,13 +171942,30 @@
171381 if( p->rc==SQLITE_OK ){
171382 p->eStage = RBU_STAGE_DONE;
171383 p->rc = SQLITE_DONE;
171384 }
171385 }else{
171386 RbuFrame *pFrame = &p->aFrame[p->nStep];
171387 rbuCheckpointFrame(p, pFrame);
171388 p->nStep++;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171389 }
171390 p->nProgress++;
171391 }
171392 break;
171393 }
@@ -171823,10 +172401,16 @@
171823
171824 /* Commit the transaction to the *-oal file. */
171825 if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_OAL ){
171826 p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg);
171827 }
 
 
 
 
 
 
171828
171829 rbuSaveState(p, p->eStage);
171830
171831 if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_OAL ){
171832 p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
@@ -171947,10 +172531,16 @@
171947 assert( p->eStage>=RBU_STAGE_OAL && p->eStage<=RBU_STAGE_DONE );
171948 if( p->eStage==RBU_STAGE_OAL ){
171949 assert( rc!=SQLITE_DONE );
171950 if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, 0);
171951 }
 
 
 
 
 
 
171952
171953 p->rc = rc;
171954 rbuSaveState(p, p->eStage);
171955 rc = p->rc;
171956
@@ -178363,26 +178953,28 @@
178363 /* Bit values for the JsonNode.jnFlag field
178364 */
178365 #define JNODE_RAW 0x01 /* Content is raw, not JSON encoded */
178366 #define JNODE_ESCAPE 0x02 /* Content is text with \ escapes */
178367 #define JNODE_REMOVE 0x04 /* Do not output */
178368 #define JNODE_REPLACE 0x08 /* Replace with JsonNode.iVal */
178369 #define JNODE_APPEND 0x10 /* More ARRAY/OBJECT entries at u.iAppend */
178370 #define JNODE_LABEL 0x20 /* Is a label of an object */
 
178371
178372
178373 /* A single node of parsed JSON
178374 */
178375 struct JsonNode {
178376 u8 eType; /* One of the JSON_ type values */
178377 u8 jnFlags; /* JNODE flags */
178378 u8 iVal; /* Replacement value when JNODE_REPLACE */
178379 u32 n; /* Bytes of content, or number of sub-nodes */
178380 union {
178381 const char *zJContent; /* Content for INT, REAL, and STRING */
178382 u32 iAppend; /* More terms for ARRAY and OBJECT */
178383 u32 iKey; /* Key for ARRAY objects in json_tree() */
 
 
178384 } u;
178385 };
178386
178387 /* A completely parsed JSON string
178388 */
@@ -178635,10 +179227,17 @@
178635 static void jsonRenderNode(
178636 JsonNode *pNode, /* The node to render */
178637 JsonString *pOut, /* Write JSON here */
178638 sqlite3_value **aReplace /* Replacement values */
178639 ){
 
 
 
 
 
 
 
178640 switch( pNode->eType ){
178641 default: {
178642 assert( pNode->eType==JSON_NULL );
178643 jsonAppendRaw(pOut, "null", 4);
178644 break;
@@ -178666,16 +179265,11 @@
178666 case JSON_ARRAY: {
178667 u32 j = 1;
178668 jsonAppendChar(pOut, '[');
178669 for(;;){
178670 while( j<=pNode->n ){
178671 if( pNode[j].jnFlags & (JNODE_REMOVE|JNODE_REPLACE) ){
178672 if( pNode[j].jnFlags & JNODE_REPLACE ){
178673 jsonAppendSeparator(pOut);
178674 jsonAppendValue(pOut, aReplace[pNode[j].iVal]);
178675 }
178676 }else{
178677 jsonAppendSeparator(pOut);
178678 jsonRenderNode(&pNode[j], pOut, aReplace);
178679 }
178680 j += jsonNodeSize(&pNode[j]);
178681 }
@@ -178693,15 +179287,11 @@
178693 while( j<=pNode->n ){
178694 if( (pNode[j+1].jnFlags & JNODE_REMOVE)==0 ){
178695 jsonAppendSeparator(pOut);
178696 jsonRenderNode(&pNode[j], pOut, aReplace);
178697 jsonAppendChar(pOut, ':');
178698 if( pNode[j+1].jnFlags & JNODE_REPLACE ){
178699 jsonAppendValue(pOut, aReplace[pNode[j+1].iVal]);
178700 }else{
178701 jsonRenderNode(&pNode[j+1], pOut, aReplace);
178702 }
178703 }
178704 j += 1 + jsonNodeSize(&pNode[j+1]);
178705 }
178706 if( (pNode->jnFlags & JNODE_APPEND)==0 ) break;
178707 pNode = &pNode[pNode->u.iAppend];
@@ -178924,11 +179514,10 @@
178924 return jsonParseAddNodeExpand(pParse, eType, n, zContent);
178925 }
178926 p = &pParse->aNode[pParse->nNode];
178927 p->eType = (u8)eType;
178928 p->jnFlags = 0;
178929 p->iVal = 0;
178930 p->n = n;
178931 p->u.zJContent = zContent;
178932 return pParse->nNode++;
178933 }
178934
@@ -179390,10 +179979,29 @@
179390 zFuncName);
179391 sqlite3_result_error(pCtx, zMsg, -1);
179392 sqlite3_free(zMsg);
179393 }
179394
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179395
179396 /****************************************************************************
179397 ** SQL functions used for testing and debugging
179398 ****************************************************************************/
179399
@@ -179581,10 +180189,109 @@
179581 sqlite3_result_subtype(ctx, JSON_SUBTYPE);
179582 }
179583 jsonReset(&jx);
179584 jsonParseReset(&x);
179585 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179586
179587 /*
179588 ** Implementation of the json_object(NAME,VALUE,...) function. Return a JSON
179589 ** object that contains all name/value given in arguments. Or if any name
179590 ** is not a string or if any value is a BLOB, throw an error.
@@ -179685,15 +180392,15 @@
179685 zPath = (const char*)sqlite3_value_text(argv[i]);
179686 pNode = jsonLookup(&x, zPath, 0, ctx);
179687 if( x.nErr ) goto replace_err;
179688 if( pNode ){
179689 pNode->jnFlags |= (u8)JNODE_REPLACE;
179690 pNode->iVal = (u8)(i+1);
179691 }
179692 }
179693 if( x.aNode[0].jnFlags & JNODE_REPLACE ){
179694 sqlite3_result_value(ctx, argv[x.aNode[0].iVal]);
179695 }else{
179696 jsonReturnJson(x.aNode, ctx, argv);
179697 }
179698 replace_err:
179699 jsonParseReset(&x);
@@ -179739,15 +180446,15 @@
179739 goto jsonSetDone;
179740 }else if( x.nErr ){
179741 goto jsonSetDone;
179742 }else if( pNode && (bApnd || bIsSet) ){
179743 pNode->jnFlags |= (u8)JNODE_REPLACE;
179744 pNode->iVal = (u8)(i+1);
179745 }
179746 }
179747 if( x.aNode[0].jnFlags & JNODE_REPLACE ){
179748 sqlite3_result_value(ctx, argv[x.aNode[0].iVal]);
179749 }else{
179750 jsonReturnJson(x.aNode, ctx, argv);
179751 }
179752 jsonSetDone:
179753 jsonParseReset(&x);
@@ -180386,10 +181093,11 @@
180386 { "json_array_length", 1, 0, jsonArrayLengthFunc },
180387 { "json_array_length", 2, 0, jsonArrayLengthFunc },
180388 { "json_extract", -1, 0, jsonExtractFunc },
180389 { "json_insert", -1, 0, jsonSetFunc },
180390 { "json_object", -1, 0, jsonObjectFunc },
 
180391 { "json_quote", 1, 0, jsonQuoteFunc },
180392 { "json_remove", -1, 0, jsonRemoveFunc },
180393 { "json_replace", -1, 0, jsonReplaceFunc },
180394 { "json_set", -1, 1, jsonSetFunc },
180395 { "json_type", 1, 0, jsonTypeFunc },
@@ -181079,11 +181787,13 @@
181079 typedef unsigned short u16;
181080 typedef short i16;
181081 typedef sqlite3_int64 i64;
181082 typedef sqlite3_uint64 u64;
181083
181084 #define ArraySize(x) ((int)(sizeof(x) / sizeof(x[0])))
 
 
181085
181086 #define testcase(x)
181087 #define ALWAYS(x) 1
181088 #define NEVER(x) 0
181089
@@ -186302,11 +187012,14 @@
186302 if( p1->bEof==0 ){
186303 if( (p1->iRowid==iLast)
186304 || (bFromValid && fts5RowidCmp(pExpr, p1->iRowid, iFrom)<0)
186305 ){
186306 int rc = fts5ExprNodeNext(pExpr, p1, bFromValid, iFrom);
186307 if( rc!=SQLITE_OK ) return rc;
 
 
 
186308 }
186309 }
186310 }
186311
186312 fts5ExprNodeTest_OR(pExpr, pNode);
@@ -186333,11 +187046,14 @@
186333 Fts5ExprNode *pChild = pAnd->apChild[iChild];
186334 int cmp = fts5RowidCmp(pExpr, iLast, pChild->iRowid);
186335 if( cmp>0 ){
186336 /* Advance pChild until it points to iLast or laster */
186337 rc = fts5ExprNodeNext(pExpr, pChild, 1, iLast);
186338 if( rc!=SQLITE_OK ) return rc;
 
 
 
186339 }
186340
186341 /* If the child node is now at EOF, so is the parent AND node. Otherwise,
186342 ** the child node is guaranteed to have advanced at least as far as
186343 ** rowid iLast. So if it is not at exactly iLast, pChild->iRowid is the
@@ -186372,10 +187088,12 @@
186372 i64 iFrom
186373 ){
186374 int rc = fts5ExprNodeNext(pExpr, pNode->apChild[0], bFromValid, iFrom);
186375 if( rc==SQLITE_OK ){
186376 rc = fts5ExprNodeTest_AND(pExpr, pNode);
 
 
186377 }
186378 return rc;
186379 }
186380
186381 static int fts5ExprNodeTest_NOT(
@@ -186414,10 +187132,13 @@
186414 ){
186415 int rc = fts5ExprNodeNext(pExpr, pNode->apChild[0], bFromValid, iFrom);
186416 if( rc==SQLITE_OK ){
186417 rc = fts5ExprNodeTest_NOT(pExpr, pNode);
186418 }
 
 
 
186419 return rc;
186420 }
186421
186422 /*
186423 ** If pNode currently points to a match, this function returns SQLITE_OK
@@ -197534,11 +198255,11 @@
197534 int nArg, /* Number of args */
197535 sqlite3_value **apUnused /* Function arguments */
197536 ){
197537 assert( nArg==0 );
197538 UNUSED_PARAM2(nArg, apUnused);
197539 sqlite3_result_text(pCtx, "fts5: 2017-02-13 16:02:40 ada05cfa86ad7f5645450ac7a2a21c9aa6e57d2c", -1, SQLITE_TRANSIENT);
197540 }
197541
197542 static int fts5Init(sqlite3 *db){
197543 static const sqlite3_module fts5Mod = {
197544 /* iVersion */ 2,
@@ -198197,15 +198918,10 @@
198197 sqlite3_step(pDel);
198198 rc = sqlite3_reset(pDel);
198199 }
198200 }
198201
198202 /* Write the averages record */
198203 if( rc==SQLITE_OK ){
198204 rc = fts5StorageSaveTotals(p);
198205 }
198206
198207 return rc;
198208 }
198209
198210 /*
198211 ** Delete all entries in the FTS5 index.
@@ -198405,15 +199121,10 @@
198405 if( rc==SQLITE_OK ){
198406 rc = fts5StorageInsertDocsize(p, iRowid, &buf);
198407 }
198408 sqlite3_free(buf.p);
198409
198410 /* Write the averages record */
198411 if( rc==SQLITE_OK ){
198412 rc = fts5StorageSaveTotals(p);
198413 }
198414
198415 return rc;
198416 }
198417
198418 static int fts5StorageCount(Fts5Storage *p, const char *zSuffix, i64 *pnRow){
198419 Fts5Config *pConfig = p->pConfig;
@@ -198744,16 +199455,21 @@
198744
198745 /*
198746 ** Flush any data currently held in-memory to disk.
198747 */
198748 static int sqlite3Fts5StorageSync(Fts5Storage *p, int bCommit){
198749 if( bCommit && p->bTotalsValid ){
198750 int rc = fts5StorageSaveTotals(p);
198751 p->bTotalsValid = 0;
198752 if( rc!=SQLITE_OK ) return rc;
 
198753 }
198754 return sqlite3Fts5IndexSync(p->pIndex, bCommit);
 
 
 
 
198755 }
198756
198757 static int sqlite3Fts5StorageRollback(Fts5Storage *p){
198758 p->bTotalsValid = 0;
198759 return sqlite3Fts5IndexRollback(p->pIndex);
198760
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.18.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -389,20 +389,20 @@
389 ** SQLite source code has been stored in the
390 ** <a href="http://www.fossil-scm.org/">Fossil configuration management
391 ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
392 ** a string which identifies a particular check-in of SQLite
393 ** within its configuration management system. ^The SQLITE_SOURCE_ID
394 ** string contains the date and time of the check-in (UTC) and a SHA1
395 ** or SHA3-256 hash of the entire source tree.
396 **
397 ** See also: [sqlite3_libversion()],
398 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
399 ** [sqlite_version()] and [sqlite_source_id()].
400 */
401 #define SQLITE_VERSION "3.18.0"
402 #define SQLITE_VERSION_NUMBER 3018000
403 #define SQLITE_SOURCE_ID "2017-03-28 18:48:43 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37"
404
405 /*
406 ** CAPI3REF: Run-Time Library Version Numbers
407 ** KEYWORDS: sqlite3_version sqlite3_sourceid
408 **
@@ -2315,24 +2315,34 @@
2315 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
2316 ** names are not also used by explicitly declared columns. ^If
2317 ** the table has a column of type [INTEGER PRIMARY KEY] then that column
2318 ** is another alias for the rowid.
2319 **
2320 ** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of
2321 ** the most recent successful [INSERT] into a rowid table or [virtual table]
2322 ** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not
2323 ** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred
2324 ** on the database connection D, then sqlite3_last_insert_rowid(D) returns
2325 ** zero.
 
2326 **
2327 ** As well as being set automatically as rows are inserted into database
2328 ** tables, the value returned by this function may be set explicitly by
2329 ** [sqlite3_set_last_insert_rowid()]
2330 **
2331 ** Some virtual table implementations may INSERT rows into rowid tables as
2332 ** part of committing a transaction (e.g. to flush data accumulated in memory
2333 ** to disk). In this case subsequent calls to this function return the rowid
2334 ** associated with these internal INSERT operations, which leads to
2335 ** unintuitive results. Virtual table implementations that do write to rowid
2336 ** tables in this way can avoid this problem by restoring the original
2337 ** rowid value using [sqlite3_set_last_insert_rowid()] before returning
2338 ** control to the user.
2339 **
2340 ** ^(If an [INSERT] occurs within a trigger then this routine will
2341 ** return the [rowid] of the inserted row as long as the trigger is
2342 ** running. Once the trigger program ends, the value returned
2343 ** by this routine reverts to what it was before the trigger was fired.)^
2344 **
2345 ** ^An [INSERT] that fails due to a constraint violation is not a
2346 ** successful [INSERT] and does not change the value returned by this
2347 ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
2348 ** and INSERT OR ABORT make no changes to the return value of this
@@ -2355,10 +2365,20 @@
2365 ** unpredictable and might not equal either the old or the new
2366 ** last insert [rowid].
2367 */
2368 SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
2369
2370 /*
2371 ** CAPI3REF: Set the Last Insert Rowid value.
2372 ** METHOD: sqlite3
2373 **
2374 ** The sqlite3_set_last_insert_rowid(D, R) method allows the application to
2375 ** set the value returned by calling sqlite3_last_insert_rowid(D) to R
2376 ** without inserting a row into the database.
2377 */
2378 SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);
2379
2380 /*
2381 ** CAPI3REF: Count The Number Of Rows Modified
2382 ** METHOD: sqlite3
2383 **
2384 ** ^This function returns the number of rows modified, inserted or
@@ -3679,13 +3699,13 @@
3699 ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
3700 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
3701 **
3702 ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
3703 ** <dd>The maximum number of instructions in a virtual machine program
3704 ** used to implement an SQL statement. If [sqlite3_prepare_v2()] or
3705 ** the equivalent tries to allocate space for more than this many opcodes
3706 ** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^
3707 **
3708 ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
3709 ** <dd>The maximum number of arguments on a function.</dd>)^
3710 **
3711 ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
@@ -3718,10 +3738,11 @@
3738 #define SQLITE_LIMIT_ATTACHED 7
3739 #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
3740 #define SQLITE_LIMIT_VARIABLE_NUMBER 9
3741 #define SQLITE_LIMIT_TRIGGER_DEPTH 10
3742 #define SQLITE_LIMIT_WORKER_THREADS 11
3743
3744
3745 /*
3746 ** CAPI3REF: Compiling An SQL Statement
3747 ** KEYWORDS: {SQL statement compiler}
3748 ** METHOD: sqlite3
@@ -10846,11 +10867,11 @@
10867 /*
10868 ** The maximum number of opcodes in a VDBE program.
10869 ** Not currently enforced.
10870 */
10871 #ifndef SQLITE_MAX_VDBE_OP
10872 # define SQLITE_MAX_VDBE_OP 250000000
10873 #endif
10874
10875 /*
10876 ** The maximum number of arguments to an SQL function.
10877 */
@@ -12457,10 +12478,11 @@
12478 SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
12479 SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
12480
12481 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
12482 SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
12483 SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*);
12484
12485 #ifndef SQLITE_OMIT_INCRBLOB
12486 SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*);
12487 SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
12488 SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *);
@@ -12623,10 +12645,11 @@
12645 struct SubProgram {
12646 VdbeOp *aOp; /* Array of opcodes for sub-program */
12647 int nOp; /* Elements in aOp[] */
12648 int nMem; /* Number of memory cells required */
12649 int nCsr; /* Number of cursors required */
12650 u8 *aOnce; /* Array of OP_Once flags */
12651 void *token; /* id that may be used to recursive triggers */
12652 SubProgram *pNext; /* Next sub-program already visited */
12653 };
12654
12655 /*
@@ -12757,117 +12780,119 @@
12780 #define OP_Divide 50 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
12781 #define OP_Remainder 51 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
12782 #define OP_Concat 52 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
12783 #define OP_Last 53
12784 #define OP_BitNot 54 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
12785 #define OP_IfSmaller 55
12786 #define OP_SorterSort 56
12787 #define OP_Sort 57
12788 #define OP_Rewind 58
12789 #define OP_IdxLE 59 /* synopsis: key=r[P3@P4] */
12790 #define OP_IdxGT 60 /* synopsis: key=r[P3@P4] */
12791 #define OP_IdxLT 61 /* synopsis: key=r[P3@P4] */
12792 #define OP_IdxGE 62 /* synopsis: key=r[P3@P4] */
12793 #define OP_RowSetRead 63 /* synopsis: r[P3]=rowset(P1) */
12794 #define OP_RowSetTest 64 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12795 #define OP_Program 65
12796 #define OP_FkIfZero 66 /* synopsis: if fkctr[P1]==0 goto P2 */
12797 #define OP_IfPos 67 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12798 #define OP_IfNotZero 68 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
12799 #define OP_DecrJumpZero 69 /* synopsis: if (--r[P1])==0 goto P2 */
12800 #define OP_IncrVacuum 70
12801 #define OP_VNext 71
12802 #define OP_Init 72 /* synopsis: Start at P2 */
12803 #define OP_Return 73
12804 #define OP_EndCoroutine 74
12805 #define OP_HaltIfNull 75 /* synopsis: if r[P3]=null halt */
12806 #define OP_Halt 76
12807 #define OP_Integer 77 /* synopsis: r[P2]=P1 */
12808 #define OP_Int64 78 /* synopsis: r[P2]=P4 */
12809 #define OP_String 79 /* synopsis: r[P2]='P4' (len=P1) */
12810 #define OP_Null 80 /* synopsis: r[P2..P3]=NULL */
12811 #define OP_SoftNull 81 /* synopsis: r[P1]=NULL */
12812 #define OP_Blob 82 /* synopsis: r[P2]=P4 (len=P1) */
12813 #define OP_Variable 83 /* synopsis: r[P2]=parameter(P1,P4) */
12814 #define OP_Move 84 /* synopsis: r[P2@P3]=r[P1@P3] */
12815 #define OP_Copy 85 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
12816 #define OP_SCopy 86 /* synopsis: r[P2]=r[P1] */
12817 #define OP_IntCopy 87 /* synopsis: r[P2]=r[P1] */
12818 #define OP_ResultRow 88 /* synopsis: output=r[P1@P2] */
12819 #define OP_CollSeq 89
12820 #define OP_Function0 90 /* synopsis: r[P3]=func(r[P2@P5]) */
12821 #define OP_Function 91 /* synopsis: r[P3]=func(r[P2@P5]) */
12822 #define OP_AddImm 92 /* synopsis: r[P1]=r[P1]+P2 */
12823 #define OP_RealAffinity 93
12824 #define OP_Cast 94 /* synopsis: affinity(r[P1]) */
12825 #define OP_Permutation 95
12826 #define OP_Compare 96 /* synopsis: r[P1@P3] <-> r[P2@P3] */
12827 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
12828 #define OP_Column 98 /* synopsis: r[P3]=PX */
12829 #define OP_Affinity 99 /* synopsis: affinity(r[P1@P2]) */
12830 #define OP_MakeRecord 100 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
12831 #define OP_Count 101 /* synopsis: r[P2]=count() */
12832 #define OP_ReadCookie 102
12833 #define OP_SetCookie 103
12834 #define OP_ReopenIdx 104 /* synopsis: root=P2 iDb=P3 */
12835 #define OP_OpenRead 105 /* synopsis: root=P2 iDb=P3 */
12836 #define OP_OpenWrite 106 /* synopsis: root=P2 iDb=P3 */
12837 #define OP_OpenAutoindex 107 /* synopsis: nColumn=P2 */
12838 #define OP_OpenEphemeral 108 /* synopsis: nColumn=P2 */
12839 #define OP_SorterOpen 109
12840 #define OP_SequenceTest 110 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
12841 #define OP_OpenPseudo 111 /* synopsis: P3 columns in r[P2] */
12842 #define OP_Close 112
12843 #define OP_ColumnsUsed 113
12844 #define OP_Sequence 114 /* synopsis: r[P2]=cursor[P1].ctr++ */
12845 #define OP_NewRowid 115 /* synopsis: r[P2]=rowid */
12846 #define OP_Insert 116 /* synopsis: intkey=r[P3] data=r[P2] */
12847 #define OP_InsertInt 117 /* synopsis: intkey=P3 data=r[P2] */
12848 #define OP_Delete 118
12849 #define OP_ResetCount 119
12850 #define OP_SorterCompare 120 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12851 #define OP_SorterData 121 /* synopsis: r[P2]=data */
12852 #define OP_RowData 122 /* synopsis: r[P2]=data */
12853 #define OP_Rowid 123 /* synopsis: r[P2]=rowid */
12854 #define OP_NullRow 124
12855 #define OP_SorterInsert 125 /* synopsis: key=r[P2] */
12856 #define OP_IdxInsert 126 /* synopsis: key=r[P2] */
12857 #define OP_IdxDelete 127 /* synopsis: key=r[P2@P3] */
12858 #define OP_Seek 128 /* synopsis: Move P3 to P1.rowid */
12859 #define OP_IdxRowid 129 /* synopsis: r[P2]=rowid */
12860 #define OP_Destroy 130
12861 #define OP_Clear 131
12862 #define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
12863 #define OP_ResetSorter 133
12864 #define OP_CreateIndex 134 /* synopsis: r[P2]=root iDb=P1 */
12865 #define OP_CreateTable 135 /* synopsis: r[P2]=root iDb=P1 */
12866 #define OP_SqlExec 136
12867 #define OP_ParseSchema 137
12868 #define OP_LoadAnalysis 138
12869 #define OP_DropTable 139
12870 #define OP_DropIndex 140
12871 #define OP_DropTrigger 141
12872 #define OP_IntegrityCk 142
12873 #define OP_RowSetAdd 143 /* synopsis: rowset(P1)=r[P2] */
12874 #define OP_Param 144
12875 #define OP_FkCounter 145 /* synopsis: fkctr[P1]+=P2 */
12876 #define OP_MemMax 146 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12877 #define OP_OffsetLimit 147 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12878 #define OP_AggStep0 148 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12879 #define OP_AggStep 149 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12880 #define OP_AggFinal 150 /* synopsis: accum=r[P1] N=P2 */
12881 #define OP_Expire 151
12882 #define OP_TableLock 152 /* synopsis: iDb=P1 root=P2 write=P3 */
12883 #define OP_VBegin 153
12884 #define OP_VCreate 154
12885 #define OP_VDestroy 155
12886 #define OP_VOpen 156
12887 #define OP_VColumn 157 /* synopsis: r[P3]=vcolumn(P2) */
12888 #define OP_VRename 158
12889 #define OP_Pagecount 159
12890 #define OP_MaxPgcnt 160
12891 #define OP_CursorHint 161
12892 #define OP_Noop 162
12893 #define OP_Explain 163
12894
12895 /* Properties such as "out2" or "jump" that are specified in
12896 ** comments following the "case" for each opcode in the vdbe.c
12897 ** are encoded into bitvectors as follows:
12898 */
@@ -12883,32 +12908,32 @@
12908 /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x09,\
12909 /* 24 */ 0x09, 0x09, 0x09, 0x26, 0x26, 0x09, 0x09, 0x09,\
12910 /* 32 */ 0x09, 0x09, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
12911 /* 40 */ 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26, 0x26,\
12912 /* 48 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x01, 0x12, 0x01,\
12913 /* 56 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x23,\
12914 /* 64 */ 0x0b, 0x01, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01,\
12915 /* 72 */ 0x01, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10,\
12916 /* 80 */ 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10,\
12917 /* 88 */ 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00,\
12918 /* 96 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
12919 /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12920 /* 112 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
12921 /* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00,\
12922 /* 128 */ 0x00, 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10,\
12923 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\
12924 /* 144 */ 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00,\
12925 /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
12926 /* 160 */ 0x10, 0x00, 0x00, 0x00,}
12927
12928 /* The sqlite3P2Values() routine is able to run faster if it knows
12929 ** the value of the largest JUMP opcode. The smaller the maximum
12930 ** JUMP opcode the better, so the mkopcodeh.tcl script that
12931 ** generated this include file strives to group all JUMP opcodes
12932 ** together near the beginning of the list.
12933 */
12934 #define SQLITE_MX_JUMP_OPCODE 72 /* Maximum JUMP opcode */
12935
12936 /************** End of opcodes.h *********************************************/
12937 /************** Continuing where we left off in vdbe.h ***********************/
12938
12939 /*
@@ -13868,11 +13893,11 @@
13893 ** The "PRAGMA synchronous" statement also uses the zero-based numbers.
13894 ** In other words, the zero-based numbers are used for all external interfaces
13895 ** and the one-based values are used internally.
13896 */
13897 #ifndef SQLITE_DEFAULT_SYNCHRONOUS
13898 # define SQLITE_DEFAULT_SYNCHRONOUS 2
13899 #endif
13900 #ifndef SQLITE_DEFAULT_WAL_SYNCHRONOUS
13901 # define SQLITE_DEFAULT_WAL_SYNCHRONOUS SQLITE_DEFAULT_SYNCHRONOUS
13902 #endif
13903
@@ -14074,10 +14099,11 @@
14099 u8 suppressErr; /* Do not issue error messages if true */
14100 u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */
14101 u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */
14102 u8 mTrace; /* zero or more SQLITE_TRACE flags */
14103 u8 skipBtreeMutex; /* True if no shared-cache backends */
14104 u8 nSqlExec; /* Number of pending OP_SqlExec opcodes */
14105 int nextPagesize; /* Pagesize after VACUUM if >0 */
14106 u32 magic; /* Magic number for detect library misuse */
14107 int nChange; /* Value returned by sqlite3_changes() */
14108 int nTotalChange; /* Value returned by sqlite3_total_changes() */
14109 int aLimit[SQLITE_N_LIMIT]; /* Limits */
@@ -14589,18 +14615,18 @@
14615 char *zColAff; /* String defining the affinity of each column */
14616 ExprList *pCheck; /* All CHECK constraints */
14617 /* ... also used as column name list in a VIEW */
14618 int tnum; /* Root BTree page for this table */
14619 u32 nTabRef; /* Number of pointers to this Table */
14620 u32 tabFlags; /* Mask of TF_* values */
14621 i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
14622 i16 nCol; /* Number of columns in this table */
14623 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
14624 LogEst szTabRow; /* Estimated size of each table row in bytes */
14625 #ifdef SQLITE_ENABLE_COSTMULT
14626 LogEst costMult; /* Cost multiplier for using this table */
14627 #endif
 
14628 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
14629 #ifndef SQLITE_OMIT_ALTERTABLE
14630 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
14631 #endif
14632 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -14620,27 +14646,29 @@
14646 ** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING
14647 ** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden,
14648 ** the TF_OOOHidden attribute would apply in this case. Such tables require
14649 ** special handling during INSERT processing.
14650 */
14651 #define TF_Readonly 0x0001 /* Read-only system table */
14652 #define TF_Ephemeral 0x0002 /* An ephemeral table */
14653 #define TF_HasPrimaryKey 0x0004 /* Table has a primary key */
14654 #define TF_Autoincrement 0x0008 /* Integer primary key is autoincrement */
14655 #define TF_HasStat1 0x0010 /* nRowLogEst set from sqlite_stat1 */
14656 #define TF_WithoutRowid 0x0020 /* No rowid. PRIMARY KEY is the key */
14657 #define TF_NoVisibleRowid 0x0040 /* No user-visible "rowid" column */
14658 #define TF_OOOHidden 0x0080 /* Out-of-Order hidden columns */
14659 #define TF_StatsUsed 0x0100 /* Query planner decisions affected by
14660 ** Index.aiRowLogEst[] values */
14661 #define TF_HasNotNull 0x0200 /* Contains NOT NULL constraints */
14662
14663 /*
14664 ** Test to see whether or not a table is a virtual table. This is
14665 ** done as a macro so that it will be optimized out when virtual
14666 ** table support is omitted from the build.
14667 */
14668 #ifndef SQLITE_OMIT_VIRTUALTABLE
14669 # define IsVirtual(X) ((X)->nModuleArg)
14670 #else
14671 # define IsVirtual(X) 0
14672 #endif
14673
14674 /*
@@ -14871,10 +14899,11 @@
14899 unsigned bUnordered:1; /* Use this index for == or IN queries only */
14900 unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */
14901 unsigned isResized:1; /* True if resizeIndexObject() has been called */
14902 unsigned isCovering:1; /* True if this is a covering index */
14903 unsigned noSkipScan:1; /* Do not try to use skip-scan if true */
14904 unsigned hasStat1:1; /* aiRowLogEst values come from sqlite_stat1 */
14905 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
14906 int nSample; /* Number of elements in aSample[] */
14907 int nSampleCol; /* Size of IndexSample.anEq[] and so on */
14908 tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
14909 IndexSample *aSample; /* Samples of the left-most key */
@@ -15181,11 +15210,11 @@
15210 ** form is used for name resolution with nested FROM clauses.
15211 */
15212 struct ExprList {
15213 int nExpr; /* Number of expressions on the list */
15214 struct ExprList_item { /* For each expression in the list */
15215 Expr *pExpr; /* The parse tree for this expression */
15216 char *zName; /* Token associated with this expression */
15217 char *zSpan; /* Original text of the expression */
15218 u8 sortOrder; /* 1 for DESC or 0 for ASC */
15219 unsigned done :1; /* A flag to indicate when processing is finished */
15220 unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
@@ -16504,10 +16533,11 @@
16533 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
16534 SQLITE_PRIVATE void sqlite3Vacuum(Parse*,Token*);
16535 SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*, int);
16536 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
16537 SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*, int);
16538 SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*, Expr*, int);
16539 SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
16540 SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Expr*, Expr*, int);
16541 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
16542 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
16543 SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
@@ -17450,19 +17480,25 @@
17480 "COMPILER=gcc-" __VERSION__,
17481 #endif
17482 #if SQLITE_COVERAGE_TEST
17483 "COVERAGE_TEST",
17484 #endif
17485 #ifdef SQLITE_DEBUG
17486 "DEBUG",
17487 #endif
17488 #if SQLITE_DEFAULT_LOCKING_MODE
17489 "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE),
17490 #endif
17491 #if defined(SQLITE_DEFAULT_MMAP_SIZE) && !defined(SQLITE_DEFAULT_MMAP_SIZE_xc)
17492 "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE),
17493 #endif
17494 #if SQLITE_DEFAULT_SYNCHRONOUS
17495 "DEFAULT_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_SYNCHRONOUS),
17496 #endif
17497 #if SQLITE_DEFAULT_WAL_SYNCHRONOUS
17498 "DEFAULT_WAL_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_WAL_SYNCHRONOUS),
17499 #endif
17500 #if SQLITE_DIRECT_OVERFLOW_READ
17501 "DIRECT_OVERFLOW_READ",
17502 #endif
17503 #if SQLITE_DISABLE_DIRSYNC
17504 "DISABLE_DIRSYNC",
@@ -18035,10 +18071,11 @@
18071 VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */
18072 Op *aOp; /* Program instructions for parent frame */
18073 i64 *anExec; /* Event counters from parent frame */
18074 Mem *aMem; /* Array of memory cells for parent frame */
18075 VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */
18076 u8 *aOnce; /* Bitmask used by OP_Once */
18077 void *token; /* Copy of SubProgram.token */
18078 i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
18079 AuxData *pAuxData; /* Linked list of auxdata allocations */
18080 int nCursor; /* Number of entries in apCsr */
18081 int pc; /* Program Counter in parent (calling) frame */
@@ -19505,22 +19542,23 @@
19542 **
19543 ** Move the date backwards to the beginning of the current day,
19544 ** or month or year.
19545 */
19546 if( sqlite3_strnicmp(z, "start of ", 9)!=0 ) break;
19547 if( !p->validJD && !p->validYMD && !p->validHMS ) break;
19548 z += 9;
19549 computeYMD(p);
19550 p->validHMS = 1;
19551 p->h = p->m = 0;
19552 p->s = 0.0;
19553 p->rawS = 0;
19554 p->validTZ = 0;
19555 p->validJD = 0;
19556 if( sqlite3_stricmp(z,"month")==0 ){
19557 p->D = 1;
19558 rc = 0;
19559 }else if( sqlite3_stricmp(z,"year")==0 ){
 
19560 p->M = 1;
19561 p->D = 1;
19562 rc = 0;
19563 }else if( sqlite3_stricmp(z,"day")==0 ){
19564 rc = 0;
@@ -20638,11 +20676,13 @@
20676 ** Use the zone allocator available on apple products unless the
20677 ** SQLITE_WITHOUT_ZONEMALLOC symbol is defined.
20678 */
20679 #include <sys/sysctl.h>
20680 #include <malloc/malloc.h>
20681 #ifdef SQLITE_MIGHT_BE_SINGLE_CORE
20682 #include <libkern/OSAtomic.h>
20683 #endif /* SQLITE_MIGHT_BE_SINGLE_CORE */
20684 static malloc_zone_t* _sqliteZone_;
20685 #define SQLITE_MALLOC(x) malloc_zone_malloc(_sqliteZone_, (x))
20686 #define SQLITE_FREE(x) malloc_zone_free(_sqliteZone_, (x));
20687 #define SQLITE_REALLOC(x,y) malloc_zone_realloc(_sqliteZone_, (x), (y))
20688 #define SQLITE_MALLOCSIZE(x) \
@@ -20831,23 +20871,14 @@
20871 /* defer MT decisions to system malloc */
20872 _sqliteZone_ = malloc_default_zone();
20873 }else{
20874 /* only 1 core, use our own zone to contention over global locks,
20875 ** e.g. we have our own dedicated locks */
20876 _sqliteZone_ = malloc_create_zone(4096, 0);
20877 malloc_set_zone_name(_sqliteZone_, "Sqlite_Heap");
20878 }
20879 #endif /* defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC) */
 
 
 
 
 
 
 
 
 
20880 UNUSED_PARAMETER(NotUsed);
20881 return SQLITE_OK;
20882 }
20883
20884 /*
@@ -24050,12 +24081,12 @@
24081 #ifdef SQLITE_DEBUG
24082 assert( p->nRef>0 || p->owner==0 );
24083 p->owner = tid;
24084 p->nRef++;
24085 if( p->trace ){
24086 OSTRACE(("ENTER-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n",
24087 tid, p->id, p, p->trace, p->nRef));
24088 }
24089 #endif
24090 }
24091
24092 static int winMutexTry(sqlite3_mutex *p){
@@ -24093,12 +24124,12 @@
24124 #else
24125 UNUSED_PARAMETER(p);
24126 #endif
24127 #ifdef SQLITE_DEBUG
24128 if( p->trace ){
24129 OSTRACE(("TRY-MUTEX tid=%lu, mutex(%d)=%p (%d), owner=%lu, nRef=%d, rc=%s\n",
24130 tid, p->id, p, p->trace, p->owner, p->nRef, sqlite3ErrName(rc)));
24131 }
24132 #endif
24133 return rc;
24134 }
24135
@@ -24122,12 +24153,12 @@
24153 #endif
24154 assert( winMutex_isInit==1 );
24155 LeaveCriticalSection(&p->mutex);
24156 #ifdef SQLITE_DEBUG
24157 if( p->trace ){
24158 OSTRACE(("LEAVE-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n",
24159 tid, p->id, p, p->trace, p->nRef));
24160 }
24161 #endif
24162 }
24163
24164 SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void){
@@ -24383,10 +24414,17 @@
24414 ** implementation of malloc_good_size(), which must be called in debug
24415 ** mode and specifically when the DMD "Dark Matter Detector" is enabled
24416 ** or else a crash results. Hence, do not attempt to optimize out the
24417 ** following xRoundup() call. */
24418 nFull = sqlite3GlobalConfig.m.xRoundup(n);
24419
24420 #ifdef SQLITE_MAX_MEMORY
24421 if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nFull>SQLITE_MAX_MEMORY ){
24422 *pp = 0;
24423 return;
24424 }
24425 #endif
24426
24427 sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n);
24428 if( mem0.alarmThreshold>0 ){
24429 sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
24430 if( nUsed >= mem0.alarmThreshold - nFull ){
@@ -24572,11 +24610,11 @@
24610 return sqlite3GlobalConfig.m.xSize(p);
24611 }
24612 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
24613 assert( p!=0 );
24614 if( db==0 || !isLookaside(db,p) ){
24615 #ifdef SQLITE_DEBUG
24616 if( db==0 ){
24617 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
24618 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
24619 }else{
24620 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
@@ -24633,11 +24671,11 @@
24671 measureAllocationSize(db, p);
24672 return;
24673 }
24674 if( isLookaside(db, p) ){
24675 LookasideSlot *pBuf = (LookasideSlot*)p;
24676 #ifdef SQLITE_DEBUG
24677 /* Trash all content in the buffer being freed */
24678 memset(p, 0xaa, db->lookaside.sz);
24679 #endif
24680 pBuf->pNext = db->lookaside.pFree;
24681 db->lookaside.pFree = pBuf;
@@ -25002,11 +25040,11 @@
25040
25041 /*
25042 ** Conversion types fall into various categories as defined by the
25043 ** following enumeration.
25044 */
25045 #define etRADIX 0 /* non-decimal integer types. %x %o */
25046 #define etFLOAT 1 /* Floating point. %f */
25047 #define etEXP 2 /* Exponentional notation. %e and %E */
25048 #define etGENERIC 3 /* Floating or exponential, depending on exponent. %g */
25049 #define etSIZE 4 /* Return number of characters processed so far. %n */
25050 #define etSTRING 5 /* Strings. %s */
@@ -25020,12 +25058,13 @@
25058 #define etTOKEN 11 /* a pointer to a Token structure */
25059 #define etSRCLIST 12 /* a pointer to a SrcList */
25060 #define etPOINTER 13 /* The %p conversion */
25061 #define etSQLESCAPE3 14 /* %w -> Strings with '\"' doubled */
25062 #define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */
25063 #define etDECIMAL 16 /* %d or %u, but not %x, %o */
25064
25065 #define etINVALID 17 /* Any unrecognized conversion type */
25066
25067
25068 /*
25069 ** An "etByte" is an 8-bit unsigned value.
25070 */
@@ -25045,40 +25084,40 @@
25084 } et_info;
25085
25086 /*
25087 ** Allowed values for et_info.flags
25088 */
25089 #define FLAG_SIGNED 1 /* True if the value to convert is signed */
25090 #define FLAG_STRING 4 /* Allow infinite precision */
25091
25092
25093 /*
25094 ** The following table is searched linearly, so it is good to put the
25095 ** most frequently used conversion types first.
25096 */
25097 static const char aDigits[] = "0123456789ABCDEF0123456789abcdef";
25098 static const char aPrefix[] = "-x0\000X0";
25099 static const et_info fmtinfo[] = {
25100 { 'd', 10, 1, etDECIMAL, 0, 0 },
25101 { 's', 0, 4, etSTRING, 0, 0 },
25102 { 'g', 0, 1, etGENERIC, 30, 0 },
25103 { 'z', 0, 4, etDYNSTRING, 0, 0 },
25104 { 'q', 0, 4, etSQLESCAPE, 0, 0 },
25105 { 'Q', 0, 4, etSQLESCAPE2, 0, 0 },
25106 { 'w', 0, 4, etSQLESCAPE3, 0, 0 },
25107 { 'c', 0, 0, etCHARX, 0, 0 },
25108 { 'o', 8, 0, etRADIX, 0, 2 },
25109 { 'u', 10, 0, etDECIMAL, 0, 0 },
25110 { 'x', 16, 0, etRADIX, 16, 1 },
25111 { 'X', 16, 0, etRADIX, 0, 4 },
25112 #ifndef SQLITE_OMIT_FLOATING_POINT
25113 { 'f', 0, 1, etFLOAT, 0, 0 },
25114 { 'e', 0, 1, etEXP, 30, 0 },
25115 { 'E', 0, 1, etEXP, 14, 0 },
25116 { 'G', 0, 1, etGENERIC, 14, 0 },
25117 #endif
25118 { 'i', 10, 1, etDECIMAL, 0, 0 },
25119 { 'n', 0, 0, etSIZE, 0, 0 },
25120 { '%', 0, 0, etPERCENT, 0, 0 },
25121 { 'p', 16, 0, etPOINTER, 0, 1 },
25122
25123 /* All the rest are undocumented and are for internal use only */
@@ -25166,18 +25205,17 @@
25205 int precision; /* Precision of the current field */
25206 int length; /* Length of the field */
25207 int idx; /* A general purpose loop counter */
25208 int width; /* Width of the current field */
25209 etByte flag_leftjustify; /* True if "-" flag is present */
25210 etByte flag_prefix; /* '+' or ' ' or 0 for prefix */
 
25211 etByte flag_alternateform; /* True if "#" flag is present */
25212 etByte flag_altform2; /* True if "!" flag is present */
25213 etByte flag_zeropad; /* True if field width constant starts with zero */
25214 etByte flag_long; /* 1 for the "l" flag, 2 for "ll", 0 by default */
 
25215 etByte done; /* Loop termination flag */
25216 etByte cThousand; /* Thousands separator for %d and %u */
25217 etByte xtype = etINVALID; /* Conversion paradigm */
25218 u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */
25219 char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
25220 sqlite_uint64 longvalue; /* Value for integer types */
25221 LONGDOUBLE_TYPE realvalue; /* Value for real types */
@@ -25216,21 +25254,22 @@
25254 if( (c=(*++fmt))==0 ){
25255 sqlite3StrAccumAppend(pAccum, "%", 1);
25256 break;
25257 }
25258 /* Find out what flags are present */
25259 flag_leftjustify = flag_prefix = cThousand =
25260 flag_alternateform = flag_altform2 = flag_zeropad = 0;
25261 done = 0;
25262 do{
25263 switch( c ){
25264 case '-': flag_leftjustify = 1; break;
25265 case '+': flag_prefix = '+'; break;
25266 case ' ': flag_prefix = ' '; break;
25267 case '#': flag_alternateform = 1; break;
25268 case '!': flag_altform2 = 1; break;
25269 case '0': flag_zeropad = 1; break;
25270 case ',': cThousand = ','; break;
25271 default: done = 1; break;
25272 }
25273 }while( !done && (c=(*++fmt))!=0 );
25274 /* Get the field width */
25275 if( c=='*' ){
@@ -25296,17 +25335,15 @@
25335 /* Get the conversion type modifier */
25336 if( c=='l' ){
25337 flag_long = 1;
25338 c = *++fmt;
25339 if( c=='l' ){
25340 flag_long = 2;
25341 c = *++fmt;
 
 
25342 }
25343 }else{
25344 flag_long = 0;
25345 }
25346 /* Fetch the info entry for the field */
25347 infop = &fmtinfo[0];
25348 xtype = etINVALID;
25349 for(idx=0; idx<ArraySize(fmtinfo); idx++){
@@ -25320,41 +25357,42 @@
25357 /*
25358 ** At this point, variables are initialized as follows:
25359 **
25360 ** flag_alternateform TRUE if a '#' is present.
25361 ** flag_altform2 TRUE if a '!' is present.
25362 ** flag_prefix '+' or ' ' or zero
25363 ** flag_leftjustify TRUE if a '-' is present or if the
25364 ** field width was negative.
25365 ** flag_zeropad TRUE if the width began with 0.
25366 ** flag_long 1 for "l", 2 for "ll"
 
 
 
 
25367 ** width The specified field width. This is
25368 ** always non-negative. Zero is the default.
25369 ** precision The specified precision. The default
25370 ** is -1.
25371 ** xtype The class of the conversion.
25372 ** infop Pointer to the appropriate info struct.
25373 */
25374 switch( xtype ){
25375 case etPOINTER:
25376 flag_long = sizeof(char*)==sizeof(i64) ? 2 :
25377 sizeof(char*)==sizeof(long int) ? 1 : 0;
25378 /* Fall through into the next case */
25379 case etORDINAL:
25380 case etRADIX:
25381 cThousand = 0;
25382 /* Fall through into the next case */
25383 case etDECIMAL:
25384 if( infop->flags & FLAG_SIGNED ){
25385 i64 v;
25386 if( bArgList ){
25387 v = getIntArg(pArgList);
 
 
25388 }else if( flag_long ){
25389 if( flag_long==2 ){
25390 v = va_arg(ap,i64) ;
25391 }else{
25392 v = va_arg(ap,long int);
25393 }
25394 }else{
25395 v = va_arg(ap,int);
25396 }
25397 if( v<0 ){
25398 if( v==SMALLEST_INT64 ){
@@ -25363,40 +25401,41 @@
25401 longvalue = -v;
25402 }
25403 prefix = '-';
25404 }else{
25405 longvalue = v;
25406 prefix = flag_prefix;
 
 
25407 }
25408 }else{
25409 if( bArgList ){
25410 longvalue = (u64)getIntArg(pArgList);
 
 
25411 }else if( flag_long ){
25412 if( flag_long==2 ){
25413 longvalue = va_arg(ap,u64);
25414 }else{
25415 longvalue = va_arg(ap,unsigned long int);
25416 }
25417 }else{
25418 longvalue = va_arg(ap,unsigned int);
25419 }
25420 prefix = 0;
25421 }
25422 if( longvalue==0 ) flag_alternateform = 0;
25423 if( flag_zeropad && precision<width-(prefix!=0) ){
25424 precision = width-(prefix!=0);
25425 }
25426 if( precision<etBUFSIZE-10-etBUFSIZE/3 ){
25427 nOut = etBUFSIZE;
25428 zOut = buf;
25429 }else{
25430 u64 n = (u64)precision + 10 + precision/3;
25431 zOut = zExtra = sqlite3Malloc( n );
25432 if( zOut==0 ){
25433 setStrAccumError(pAccum, STRACCUM_NOMEM);
25434 return;
25435 }
25436 nOut = (int)n;
25437 }
25438 bufpt = &zOut[nOut-1];
25439 if( xtype==etORDINAL ){
25440 static const char zOrd[] = "thstndrd";
25441 int x = (int)(longvalue % 10);
@@ -25413,12 +25452,27 @@
25452 *(--bufpt) = cset[longvalue%base];
25453 longvalue = longvalue/base;
25454 }while( longvalue>0 );
25455 }
25456 length = (int)(&zOut[nOut-1]-bufpt);
25457 while( precision>length ){
25458 *(--bufpt) = '0'; /* Zero pad */
25459 length++;
25460 }
25461 if( cThousand ){
25462 int nn = (length - 1)/3; /* Number of "," to insert */
25463 int ix = (length - 1)%3 + 1;
25464 bufpt -= nn;
25465 for(idx=0; nn>0; idx++){
25466 bufpt[idx] = bufpt[idx+nn];
25467 ix--;
25468 if( ix==0 ){
25469 bufpt[++idx] = cThousand;
25470 nn--;
25471 ix = 3;
25472 }
25473 }
25474 }
25475 if( prefix ) *(--bufpt) = prefix; /* Add sign */
25476 if( flag_alternateform && infop->prefix ){ /* Add "0" or "0x" */
25477 const char *pre;
25478 char x;
@@ -25441,13 +25495,11 @@
25495 if( precision<0 ) precision = 6; /* Set default precision */
25496 if( realvalue<0.0 ){
25497 realvalue = -realvalue;
25498 prefix = '-';
25499 }else{
25500 prefix = flag_prefix;
 
 
25501 }
25502 if( xtype==etGENERIC && precision>0 ) precision--;
25503 testcase( precision>0xfff );
25504 for(idx=precision&0xfff, rounder=0.5; idx>0; idx--, rounder*=0.1){}
25505 if( xtype==etFLOAT ) realvalue += rounder;
@@ -26215,10 +26267,14 @@
26267 ** Generate a human-readable description of a Select object.
26268 */
26269 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
26270 int n = 0;
26271 int cnt = 0;
26272 if( p==0 ){
26273 sqlite3TreeViewLine(pView, "nil-SELECT");
26274 return;
26275 }
26276 pView = sqlite3TreeViewPush(pView, moreToFollow);
26277 if( p->pWith ){
26278 sqlite3TreeViewWith(pView, p->pWith, 1);
26279 cnt = 1;
26280 sqlite3TreeViewPush(pView, 1);
@@ -29464,117 +29520,119 @@
29520 /* 50 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
29521 /* 51 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
29522 /* 52 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
29523 /* 53 */ "Last" OpHelp(""),
29524 /* 54 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
29525 /* 55 */ "IfSmaller" OpHelp(""),
29526 /* 56 */ "SorterSort" OpHelp(""),
29527 /* 57 */ "Sort" OpHelp(""),
29528 /* 58 */ "Rewind" OpHelp(""),
29529 /* 59 */ "IdxLE" OpHelp("key=r[P3@P4]"),
29530 /* 60 */ "IdxGT" OpHelp("key=r[P3@P4]"),
29531 /* 61 */ "IdxLT" OpHelp("key=r[P3@P4]"),
29532 /* 62 */ "IdxGE" OpHelp("key=r[P3@P4]"),
29533 /* 63 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
29534 /* 64 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
29535 /* 65 */ "Program" OpHelp(""),
29536 /* 66 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
29537 /* 67 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
29538 /* 68 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
29539 /* 69 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
29540 /* 70 */ "IncrVacuum" OpHelp(""),
29541 /* 71 */ "VNext" OpHelp(""),
29542 /* 72 */ "Init" OpHelp("Start at P2"),
29543 /* 73 */ "Return" OpHelp(""),
29544 /* 74 */ "EndCoroutine" OpHelp(""),
29545 /* 75 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
29546 /* 76 */ "Halt" OpHelp(""),
29547 /* 77 */ "Integer" OpHelp("r[P2]=P1"),
29548 /* 78 */ "Int64" OpHelp("r[P2]=P4"),
29549 /* 79 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
29550 /* 80 */ "Null" OpHelp("r[P2..P3]=NULL"),
29551 /* 81 */ "SoftNull" OpHelp("r[P1]=NULL"),
29552 /* 82 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
29553 /* 83 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
29554 /* 84 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
29555 /* 85 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
29556 /* 86 */ "SCopy" OpHelp("r[P2]=r[P1]"),
29557 /* 87 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
29558 /* 88 */ "ResultRow" OpHelp("output=r[P1@P2]"),
29559 /* 89 */ "CollSeq" OpHelp(""),
29560 /* 90 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
29561 /* 91 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
29562 /* 92 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
29563 /* 93 */ "RealAffinity" OpHelp(""),
29564 /* 94 */ "Cast" OpHelp("affinity(r[P1])"),
29565 /* 95 */ "Permutation" OpHelp(""),
29566 /* 96 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
29567 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
29568 /* 98 */ "Column" OpHelp("r[P3]=PX"),
29569 /* 99 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
29570 /* 100 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
29571 /* 101 */ "Count" OpHelp("r[P2]=count()"),
29572 /* 102 */ "ReadCookie" OpHelp(""),
29573 /* 103 */ "SetCookie" OpHelp(""),
29574 /* 104 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
29575 /* 105 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
29576 /* 106 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
29577 /* 107 */ "OpenAutoindex" OpHelp("nColumn=P2"),
29578 /* 108 */ "OpenEphemeral" OpHelp("nColumn=P2"),
29579 /* 109 */ "SorterOpen" OpHelp(""),
29580 /* 110 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
29581 /* 111 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
29582 /* 112 */ "Close" OpHelp(""),
29583 /* 113 */ "ColumnsUsed" OpHelp(""),
29584 /* 114 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
29585 /* 115 */ "NewRowid" OpHelp("r[P2]=rowid"),
29586 /* 116 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
29587 /* 117 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
29588 /* 118 */ "Delete" OpHelp(""),
29589 /* 119 */ "ResetCount" OpHelp(""),
29590 /* 120 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
29591 /* 121 */ "SorterData" OpHelp("r[P2]=data"),
29592 /* 122 */ "RowData" OpHelp("r[P2]=data"),
29593 /* 123 */ "Rowid" OpHelp("r[P2]=rowid"),
29594 /* 124 */ "NullRow" OpHelp(""),
29595 /* 125 */ "SorterInsert" OpHelp("key=r[P2]"),
29596 /* 126 */ "IdxInsert" OpHelp("key=r[P2]"),
29597 /* 127 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
29598 /* 128 */ "Seek" OpHelp("Move P3 to P1.rowid"),
29599 /* 129 */ "IdxRowid" OpHelp("r[P2]=rowid"),
29600 /* 130 */ "Destroy" OpHelp(""),
29601 /* 131 */ "Clear" OpHelp(""),
29602 /* 132 */ "Real" OpHelp("r[P2]=P4"),
29603 /* 133 */ "ResetSorter" OpHelp(""),
29604 /* 134 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
29605 /* 135 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
29606 /* 136 */ "SqlExec" OpHelp(""),
29607 /* 137 */ "ParseSchema" OpHelp(""),
29608 /* 138 */ "LoadAnalysis" OpHelp(""),
29609 /* 139 */ "DropTable" OpHelp(""),
29610 /* 140 */ "DropIndex" OpHelp(""),
29611 /* 141 */ "DropTrigger" OpHelp(""),
29612 /* 142 */ "IntegrityCk" OpHelp(""),
29613 /* 143 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
29614 /* 144 */ "Param" OpHelp(""),
29615 /* 145 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
29616 /* 146 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
29617 /* 147 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
29618 /* 148 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
29619 /* 149 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
29620 /* 150 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
29621 /* 151 */ "Expire" OpHelp(""),
29622 /* 152 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
29623 /* 153 */ "VBegin" OpHelp(""),
29624 /* 154 */ "VCreate" OpHelp(""),
29625 /* 155 */ "VDestroy" OpHelp(""),
29626 /* 156 */ "VOpen" OpHelp(""),
29627 /* 157 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
29628 /* 158 */ "VRename" OpHelp(""),
29629 /* 159 */ "Pagecount" OpHelp(""),
29630 /* 160 */ "MaxPgcnt" OpHelp(""),
29631 /* 161 */ "CursorHint" OpHelp(""),
29632 /* 162 */ "Noop" OpHelp(""),
29633 /* 163 */ "Explain" OpHelp(""),
29634 };
29635 return azName[i];
29636 }
29637 #endif
29638
@@ -37952,46 +38010,84 @@
38010 * be freed immediately and any attempt to access any of that freed
38011 * data will almost certainly result in an immediate access violation.
38012 ******************************************************************************
38013 */
38014 #ifndef SQLITE_WIN32_HEAP_CREATE
38015 # define SQLITE_WIN32_HEAP_CREATE (TRUE)
38016 #endif
38017
38018 /*
38019 * This is the maximum possible initial size of the Win32-specific heap, in
38020 * bytes.
38021 */
38022 #ifndef SQLITE_WIN32_HEAP_MAX_INIT_SIZE
38023 # define SQLITE_WIN32_HEAP_MAX_INIT_SIZE (4294967295U)
38024 #endif
38025
38026 /*
38027 * This is the extra space for the initial size of the Win32-specific heap,
38028 * in bytes. This value may be zero.
38029 */
38030 #ifndef SQLITE_WIN32_HEAP_INIT_EXTRA
38031 # define SQLITE_WIN32_HEAP_INIT_EXTRA (4194304)
38032 #endif
38033
38034 /*
38035 * Calculate the maximum legal cache size, in pages, based on the maximum
38036 * possible initial heap size and the default page size, setting aside the
38037 * needed extra space.
38038 */
38039 #ifndef SQLITE_WIN32_MAX_CACHE_SIZE
38040 # define SQLITE_WIN32_MAX_CACHE_SIZE (((SQLITE_WIN32_HEAP_MAX_INIT_SIZE) - \
38041 (SQLITE_WIN32_HEAP_INIT_EXTRA)) / \
38042 (SQLITE_DEFAULT_PAGE_SIZE))
38043 #endif
38044
38045 /*
38046 * This is cache size used in the calculation of the initial size of the
38047 * Win32-specific heap. It cannot be negative.
38048 */
38049 #ifndef SQLITE_WIN32_CACHE_SIZE
38050 # if SQLITE_DEFAULT_CACHE_SIZE>=0
38051 # define SQLITE_WIN32_CACHE_SIZE (SQLITE_DEFAULT_CACHE_SIZE)
38052 # else
38053 # define SQLITE_WIN32_CACHE_SIZE (-(SQLITE_DEFAULT_CACHE_SIZE))
38054 # endif
38055 #endif
38056
38057 /*
38058 * Make sure that the calculated cache size, in pages, cannot cause the
38059 * initial size of the Win32-specific heap to exceed the maximum amount
38060 * of memory that can be specified in the call to HeapCreate.
38061 */
38062 #if SQLITE_WIN32_CACHE_SIZE>SQLITE_WIN32_MAX_CACHE_SIZE
38063 # undef SQLITE_WIN32_CACHE_SIZE
38064 # define SQLITE_WIN32_CACHE_SIZE (2000)
38065 #endif
38066
38067 /*
38068 * The initial size of the Win32-specific heap. This value may be zero.
38069 */
38070 #ifndef SQLITE_WIN32_HEAP_INIT_SIZE
38071 # define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_WIN32_CACHE_SIZE) * \
38072 (SQLITE_DEFAULT_PAGE_SIZE) + \
38073 (SQLITE_WIN32_HEAP_INIT_EXTRA))
38074 #endif
38075
38076 /*
38077 * The maximum size of the Win32-specific heap. This value may be zero.
38078 */
38079 #ifndef SQLITE_WIN32_HEAP_MAX_SIZE
38080 # define SQLITE_WIN32_HEAP_MAX_SIZE (0)
38081 #endif
38082
38083 /*
38084 * The extra flags to use in calls to the Win32 heap APIs. This value may be
38085 * zero for the default behavior.
38086 */
38087 #ifndef SQLITE_WIN32_HEAP_FLAGS
38088 # define SQLITE_WIN32_HEAP_FLAGS (0)
38089 #endif
38090
38091
38092 /*
38093 ** The winMemData structure stores information required by the Win32-specific
@@ -44084,11 +44180,11 @@
44180 ** This routine is for use inside of assert() statements only. For
44181 ** example:
44182 **
44183 ** assert( sqlite3PcachePageSanity(pPg) );
44184 */
44185 #ifdef SQLITE_DEBUG
44186 SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr *pPg){
44187 PCache *pCache;
44188 assert( pPg!=0 );
44189 assert( pPg->pgno>0 || pPg->pPager==0 ); /* Page number is 1 or more */
44190 pCache = pPg->pCache;
@@ -60177,21 +60273,22 @@
60273 }
60274 #endif
60275
60276
60277 /*
60278 ** Defragment the page given. This routine reorganizes cells within the
60279 ** page so that there are no free-blocks on the free-block list.
60280 **
60281 ** Parameter nMaxFrag is the maximum amount of fragmented space that may be
60282 ** present in the page after this routine returns.
60283 **
60284 ** EVIDENCE-OF: R-44582-60138 SQLite may from time to time reorganize a
60285 ** b-tree page so that there are no freeblocks or fragment bytes, all
60286 ** unused bytes are contained in the unallocated space region, and all
60287 ** cells are packed tightly at the end of the page.
60288 */
60289 static int defragmentPage(MemPage *pPage, int nMaxFrag){
60290 int i; /* Loop counter */
60291 int pc; /* Address of the i-th cell */
60292 int hdr; /* Offset to the page header */
60293 int size; /* Size of a cell */
60294 int usableSize; /* Number of usable bytes on a page */
@@ -60202,11 +60299,10 @@
60299 unsigned char *temp; /* Temp area for cell content */
60300 unsigned char *src; /* Source of content */
60301 int iCellFirst; /* First allowable cell index */
60302 int iCellLast; /* Last possible cell index */
60303
 
60304 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
60305 assert( pPage->pBt!=0 );
60306 assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
60307 assert( pPage->nOverflow==0 );
60308 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
@@ -60214,13 +60310,60 @@
60310 src = data = pPage->aData;
60311 hdr = pPage->hdrOffset;
60312 cellOffset = pPage->cellOffset;
60313 nCell = pPage->nCell;
60314 assert( nCell==get2byte(&data[hdr+3]) );
60315 iCellFirst = cellOffset + 2*nCell;
60316 usableSize = pPage->pBt->usableSize;
60317
60318 /* This block handles pages with two or fewer free blocks and nMaxFrag
60319 ** or fewer fragmented bytes. In this case it is faster to move the
60320 ** two (or one) blocks of cells using memmove() and add the required
60321 ** offsets to each pointer in the cell-pointer array than it is to
60322 ** reconstruct the entire page. */
60323 if( (int)data[hdr+7]<=nMaxFrag ){
60324 int iFree = get2byte(&data[hdr+1]);
60325 if( iFree ){
60326 int iFree2 = get2byte(&data[iFree]);
60327
60328 /* pageFindSlot() has already verified that free blocks are sorted
60329 ** in order of offset within the page, and that no block extends
60330 ** past the end of the page. Provided the two free slots do not
60331 ** overlap, this guarantees that the memmove() calls below will not
60332 ** overwrite the usableSize byte buffer, even if the database page
60333 ** is corrupt. */
60334 assert( iFree2==0 || iFree2>iFree );
60335 assert( iFree+get2byte(&data[iFree+2]) <= usableSize );
60336 assert( iFree2==0 || iFree2+get2byte(&data[iFree2+2]) <= usableSize );
60337
60338 if( 0==iFree2 || (data[iFree2]==0 && data[iFree2+1]==0) ){
60339 u8 *pEnd = &data[cellOffset + nCell*2];
60340 u8 *pAddr;
60341 int sz2 = 0;
60342 int sz = get2byte(&data[iFree+2]);
60343 int top = get2byte(&data[hdr+5]);
60344 if( iFree2 ){
60345 if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_BKPT;
60346 sz2 = get2byte(&data[iFree2+2]);
60347 assert( iFree+sz+sz2+iFree2-(iFree+sz) <= usableSize );
60348 memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
60349 sz += sz2;
60350 }
60351 cbrk = top+sz;
60352 assert( cbrk+(iFree-top) <= usableSize );
60353 memmove(&data[cbrk], &data[top], iFree-top);
60354 for(pAddr=&data[cellOffset]; pAddr<pEnd; pAddr+=2){
60355 pc = get2byte(pAddr);
60356 if( pc<iFree ){ put2byte(pAddr, pc+sz); }
60357 else if( pc<iFree2 ){ put2byte(pAddr, pc+sz2); }
60358 }
60359 goto defragment_out;
60360 }
60361 }
60362 }
60363
60364 cbrk = usableSize;
 
60365 iCellLast = usableSize - 4;
60366 for(i=0; i<nCell; i++){
60367 u8 *pAddr; /* The i-th cell pointer */
60368 pAddr = &data[cellOffset + i*2];
60369 pc = get2byte(pAddr);
@@ -60250,20 +60393,22 @@
60393 memcpy(&temp[x], &data[x], (cbrk+size) - x);
60394 src = temp;
60395 }
60396 memcpy(&data[cbrk], &src[pc], size);
60397 }
60398 data[hdr+7] = 0;
60399
60400 defragment_out:
60401 if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
60402 return SQLITE_CORRUPT_BKPT;
60403 }
60404 assert( cbrk>=iCellFirst );
60405 put2byte(&data[hdr+5], cbrk);
60406 data[hdr+1] = 0;
60407 data[hdr+2] = 0;
 
60408 memset(&data[iCellFirst], 0, cbrk-iCellFirst);
60409 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
 
 
 
60410 return SQLITE_OK;
60411 }
60412
60413 /*
60414 ** Search the free-list on page pPg for space to store a cell nByte bytes in
@@ -60397,14 +60542,14 @@
60542 ** to see if defragmentation is necessary.
60543 */
60544 testcase( gap+2+nByte==top );
60545 if( gap+2+nByte>top ){
60546 assert( pPage->nCell>0 || CORRUPT_DB );
60547 rc = defragmentPage(pPage, MIN(4, pPage->nFree - (2+nByte)));
60548 if( rc ) return rc;
60549 top = get2byteNotZero(&data[hdr+5]);
60550 assert( gap+2+nByte<=top );
60551 }
60552
60553
60554 /* Allocate memory from the gap in between the cell pointer array
60555 ** and the cell content area. The btreeInitPage() call has already
@@ -61672,10 +61817,35 @@
61817 sqlite3BtreeLeave(p);
61818 return rc;
61819 #endif
61820 }
61821
61822 /*
61823 ** If the user has not set the safety-level for this database connection
61824 ** using "PRAGMA synchronous", and if the safety-level is not already
61825 ** set to the value passed to this function as the second parameter,
61826 ** set it so.
61827 */
61828 #if SQLITE_DEFAULT_SYNCHRONOUS!=SQLITE_DEFAULT_WAL_SYNCHRONOUS
61829 static void setDefaultSyncFlag(BtShared *pBt, u8 safety_level){
61830 sqlite3 *db;
61831 Db *pDb;
61832 if( (db=pBt->db)!=0 && (pDb=db->aDb)!=0 ){
61833 while( pDb->pBt==0 || pDb->pBt->pBt!=pBt ){ pDb++; }
61834 if( pDb->bSyncSet==0
61835 && pDb->safety_level!=safety_level
61836 && pDb!=&db->aDb[1]
61837 ){
61838 pDb->safety_level = safety_level;
61839 sqlite3PagerSetFlags(pBt->pPager,
61840 pDb->safety_level | (db->flags & PAGER_FLAGS_MASK));
61841 }
61842 }
61843 }
61844 #else
61845 # define setDefaultSyncFlag(pBt,safety_level)
61846 #endif
61847
61848 /*
61849 ** Get a reference to pPage1 of the database file. This will
61850 ** also acquire a readlock on that file.
61851 **
@@ -61745,30 +61915,19 @@
61915 int isOpen = 0;
61916 rc = sqlite3PagerOpenWal(pBt->pPager, &isOpen);
61917 if( rc!=SQLITE_OK ){
61918 goto page1_init_failed;
61919 }else{
61920 setDefaultSyncFlag(pBt, SQLITE_DEFAULT_WAL_SYNCHRONOUS+1);
 
 
 
 
 
 
 
 
 
 
 
 
 
61921 if( isOpen==0 ){
61922 releasePage(pPage1);
61923 return SQLITE_OK;
61924 }
61925 }
61926 rc = SQLITE_NOTADB;
61927 }else{
61928 setDefaultSyncFlag(pBt, SQLITE_DEFAULT_SYNCHRONOUS+1);
61929 }
61930 #endif
61931
61932 /* EVIDENCE-OF: R-15465-20813 The maximum and minimum embedded payload
61933 ** fractions and the leaf payload fraction values must be 64, 32, and 32.
@@ -63636,11 +63795,11 @@
63795 pCur->aiIdx[pCur->iPage] = 0;
63796 return getAndInitPage(pBt, newPgno, &pCur->apPage[pCur->iPage],
63797 pCur, pCur->curPagerFlags);
63798 }
63799
63800 #ifdef SQLITE_DEBUG
63801 /*
63802 ** Page pParent is an internal (non-leaf) tree page. This function
63803 ** asserts that page number iChild is the left-child if the iIdx'th
63804 ** cell in page pParent. Or, if iIdx is equal to the total number of
63805 ** cells in pParent, that page number iChild is the right-child of
@@ -64178,10 +64337,34 @@
64337 ** have been deleted? This API will need to change to return an error code
64338 ** as well as the boolean result value.
64339 */
64340 return (CURSOR_VALID!=pCur->eState);
64341 }
64342
64343 /*
64344 ** Return an estimate for the number of rows in the table that pCur is
64345 ** pointing to. Return a negative number if no estimate is currently
64346 ** available.
64347 */
64348 SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor *pCur){
64349 i64 n;
64350 u8 i;
64351
64352 assert( cursorOwnsBtShared(pCur) );
64353 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
64354
64355 /* Currently this interface is only called by the OP_IfSmaller
64356 ** opcode, and it that case the cursor will always be valid and
64357 ** will always point to a leaf node. */
64358 if( NEVER(pCur->eState!=CURSOR_VALID) ) return -1;
64359 if( NEVER(pCur->apPage[pCur->iPage]->leaf==0) ) return -1;
64360
64361 for(n=1, i=0; i<=pCur->iPage; i++){
64362 n *= pCur->apPage[i]->nCell;
64363 }
64364 return n;
64365 }
64366
64367 /*
64368 ** Advance the cursor to the next entry in the database. If
64369 ** successful then set *pRes=0. If the cursor
64370 ** was already pointing to the last entry in the database before
@@ -65023,11 +65206,11 @@
65206 ** pPrior Where to write the pgno of the first overflow page
65207 **
65208 ** Use a call to btreeParseCellPtr() to verify that the values above
65209 ** were computed correctly.
65210 */
65211 #ifdef SQLITE_DEBUG
65212 {
65213 CellInfo info;
65214 pPage->xParseCell(pPage, pCell, &info);
65215 assert( nHeader==(int)(info.pPayload - pCell) );
65216 assert( info.nKey==pX->nKey );
@@ -66549,11 +66732,11 @@
66732 ** copied into the parent, because if the parent is page 1 then it will
66733 ** by smaller than the child due to the database header, and so all the
66734 ** free space needs to be up front.
66735 */
66736 assert( nNew==1 || CORRUPT_DB );
66737 rc = defragmentPage(apNew[0], -1);
66738 testcase( rc!=SQLITE_OK );
66739 assert( apNew[0]->nFree ==
66740 (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2)
66741 || rc!=SQLITE_OK
66742 );
@@ -71201,10 +71384,11 @@
71384 ** Remember the SQL string for a prepared statement.
71385 */
71386 SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe *p, const char *z, int n, int isPrepareV2){
71387 assert( isPrepareV2==1 || isPrepareV2==0 );
71388 if( p==0 ) return;
71389 if( !isPrepareV2 ) p->expmask = 0;
71390 #if defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_ENABLE_SQLLOG)
71391 if( !isPrepareV2 ) return;
71392 #endif
71393 assert( p->zSql==0 );
71394 p->zSql = sqlite3DbStrNDup(p->db, z, n);
@@ -71229,10 +71413,11 @@
71413 pB->pPrev = pTmp;
71414 zTmp = pA->zSql;
71415 pA->zSql = pB->zSql;
71416 pB->zSql = zTmp;
71417 pB->isPrepareV2 = pA->isPrepareV2;
71418 pB->expmask = pA->expmask;
71419 }
71420
71421 /*
71422 ** Resize the Vdbe.aOp array so that it is at least nOp elements larger
71423 ** than its current size. nOp is guaranteed to be less than or equal
@@ -71258,10 +71443,16 @@
71443 int nNew = (p->nOpAlloc>=512 ? p->nOpAlloc*2 : p->nOpAlloc+nOp);
71444 #else
71445 int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op)));
71446 UNUSED_PARAMETER(nOp);
71447 #endif
71448
71449 /* Ensure that the size of a VDBE does not grow too large */
71450 if( nNew > p->db->aLimit[SQLITE_LIMIT_VDBE_OP] ){
71451 sqlite3OomFault(p->db);
71452 return SQLITE_NOMEM;
71453 }
71454
71455 assert( nOp<=(1024/sizeof(Op)) );
71456 assert( nNew>=(p->nOpAlloc+nOp) );
71457 pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
71458 if( pNew ){
@@ -73753,17 +73944,17 @@
73944 ** Then the internal cache might have been left in an inconsistent
73945 ** state. We need to rollback the statement transaction, if there is
73946 ** one, or the complete transaction if there is no statement transaction.
73947 */
73948
73949 if( p->magic!=VDBE_MAGIC_RUN ){
73950 return SQLITE_OK;
73951 }
73952 if( db->mallocFailed ){
73953 p->rc = SQLITE_NOMEM_BKPT;
73954 }
73955 closeAllCursors(p);
 
 
 
73956 checkActiveVdbeCnt(db);
73957
73958 /* No commit or rollback needed if the program never started or if the
73959 ** SQL statement does not read or write a database file. */
73960 if( p->pc>=0 && p->bIsReader ){
@@ -74706,11 +74897,11 @@
74897 }
74898 assert( u<=pKeyInfo->nField + 1 );
74899 p->nField = u;
74900 }
74901
74902 #ifdef SQLITE_DEBUG
74903 /*
74904 ** This function compares two index or table record keys in the same way
74905 ** as the sqlite3VdbeRecordCompare() routine. Unlike VdbeRecordCompare(),
74906 ** this function deserializes and compares values using the
74907 ** sqlite3VdbeSerialGet() and sqlite3MemCompare() functions. It is used
@@ -74811,11 +75002,11 @@
75002 if( pKeyInfo->db->mallocFailed ) return 1;
75003 return 0;
75004 }
75005 #endif
75006
75007 #ifdef SQLITE_DEBUG
75008 /*
75009 ** Count the number of fields (a.k.a. columns) in the record given by
75010 ** pKey,nKey. The verify that this count is less than or equal to the
75011 ** limit given by pKeyInfo->nField + pKeyInfo->nXField.
75012 **
@@ -75694,12 +75885,12 @@
75885 ** to sqlite3_reoptimize() that re-preparing the statement may result
75886 ** in a better query plan.
75887 */
75888 SQLITE_PRIVATE void sqlite3VdbeSetVarmask(Vdbe *v, int iVar){
75889 assert( iVar>0 );
75890 if( iVar>=32 ){
75891 v->expmask |= 0x80000000;
75892 }else{
75893 v->expmask |= ((u32)1 << (iVar-1));
75894 }
75895 }
75896
@@ -75965,11 +76156,12 @@
76156 sqlite3_mutex_enter(mutex);
76157 for(i=0; i<p->nVar; i++){
76158 sqlite3VdbeMemRelease(&p->aVar[i]);
76159 p->aVar[i].flags = MEM_Null;
76160 }
76161 assert( p->isPrepareV2 || p->expmask==0 );
76162 if( p->expmask ){
76163 p->expired = 1;
76164 }
76165 sqlite3_mutex_leave(mutex);
76166 return rc;
76167 }
@@ -77069,13 +77261,12 @@
77261 ** parameter in the WHERE clause might influence the choice of query plan
77262 ** for a statement, then the statement will be automatically recompiled,
77263 ** as if there had been a schema change, on the first sqlite3_step() call
77264 ** following any change to the bindings of that parameter.
77265 */
77266 assert( p->isPrepareV2 || p->expmask==0 );
77267 if( p->expmask!=0 && (p->expmask & (i>=31 ? 0x80000000 : (u32)1<<i))!=0 ){
 
77268 p->expired = 1;
77269 }
77270 return SQLITE_OK;
77271 }
77272
@@ -77334,14 +77525,16 @@
77525 Vdbe *pFrom = (Vdbe*)pFromStmt;
77526 Vdbe *pTo = (Vdbe*)pToStmt;
77527 if( pFrom->nVar!=pTo->nVar ){
77528 return SQLITE_ERROR;
77529 }
77530 assert( pTo->isPrepareV2 || pTo->expmask==0 );
77531 if( pTo->expmask ){
77532 pTo->expired = 1;
77533 }
77534 assert( pFrom->isPrepareV2 || pFrom->expmask==0 );
77535 if( pFrom->expmask ){
77536 pFrom->expired = 1;
77537 }
77538 return sqlite3TransferBindings(pFromStmt, pToStmt);
77539 }
77540 #endif
@@ -78303,13 +78496,11 @@
78496 c = 'e';
78497 assert( (f & (MEM_Static|MEM_Dyn))==0 );
78498 }else{
78499 c = 's';
78500 }
78501 *(zCsr++) = c;
 
 
78502 sqlite3_snprintf(100, zCsr, "%d[", pMem->n);
78503 zCsr += sqlite3Strlen30(zCsr);
78504 for(i=0; i<16 && i<pMem->n; i++){
78505 sqlite3_snprintf(100, zCsr, "%02X", ((int)pMem->z[i] & 0xFF));
78506 zCsr += sqlite3Strlen30(zCsr);
@@ -78317,13 +78508,11 @@
78508 for(i=0; i<16 && i<pMem->n; i++){
78509 char z = pMem->z[i];
78510 if( z<32 || z>126 ) *zCsr++ = '.';
78511 else *zCsr++ = z;
78512 }
78513 *(zCsr++) = ']';
 
 
78514 if( f & MEM_Zero ){
78515 sqlite3_snprintf(100, zCsr,"+%dz",pMem->u.nZero);
78516 zCsr += sqlite3Strlen30(zCsr);
78517 }
78518 *zCsr = '\0';
@@ -79658,39 +79847,39 @@
79847 if( pCtx->pOut != pOut ){
79848 pCtx->pOut = pOut;
79849 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
79850 }
79851
79852 memAboutToChange(p, pOut);
79853 #ifdef SQLITE_DEBUG
79854 for(i=0; i<pCtx->argc; i++){
79855 assert( memIsValid(pCtx->argv[i]) );
79856 REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]);
79857 }
79858 #endif
79859 MemSetTypeFlag(pOut, MEM_Null);
79860 pCtx->fErrorOrAux = 0;
79861 (*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */
79862
79863 /* If the function returned an error, throw an exception */
79864 if( pCtx->fErrorOrAux ){
79865 if( pCtx->isError ){
79866 sqlite3VdbeError(p, "%s", sqlite3_value_text(pOut));
79867 rc = pCtx->isError;
79868 }
79869 sqlite3VdbeDeleteAuxData(db, &p->pAuxData, pCtx->iOp, pOp->p1);
79870 if( rc ) goto abort_due_to_error;
79871 }
79872
79873 /* Copy the result of the function into register P3 */
79874 if( pOut->flags & (MEM_Str|MEM_Blob) ){
79875 sqlite3VdbeChangeEncoding(pOut, encoding);
79876 if( sqlite3VdbeMemTooBig(pOut) ) goto too_big;
79877 }
79878
79879 REGISTER_TRACE(pOp->p3, pOut);
79880 UPDATE_MAX_BLOBSIZE(pOut);
79881 break;
79882 }
79883
79884 /* Opcode: BitAnd P1 P2 P3 * *
79885 ** Synopsis: r[P3]=r[P1]&r[P2]
@@ -80187,11 +80376,11 @@
80376 pKeyInfo = pOp->p4.pKeyInfo;
80377 assert( n>0 );
80378 assert( pKeyInfo!=0 );
80379 p1 = pOp->p1;
80380 p2 = pOp->p2;
80381 #ifdef SQLITE_DEBUG
80382 if( aPermute ){
80383 int k, mx = 0;
80384 for(k=0; k<n; k++) if( aPermute[k]>mx ) mx = aPermute[k];
80385 assert( p1>0 && p1+mx<=(p->nMem+1 - p->nCursor)+1 );
80386 assert( p2>0 && p2+mx<=(p->nMem+1 - p->nCursor)+1 );
@@ -80325,23 +80514,43 @@
80514 break;
80515 }
80516
80517 /* Opcode: Once P1 P2 * * *
80518 **
80519 ** Fall through to the next instruction the first time this opcode is
80520 ** encountered on each invocation of the byte-code program. Jump to P2
80521 ** on the second and all subsequent encounters during the same invocation.
80522 **
80523 ** Top-level programs determine first invocation by comparing the P1
80524 ** operand against the P1 operand on the OP_Init opcode at the beginning
80525 ** of the program. If the P1 values differ, then fall through and make
80526 ** the P1 of this opcode equal to the P1 of OP_Init. If P1 values are
80527 ** the same then take the jump.
80528 **
80529 ** For subprograms, there is a bitmask in the VdbeFrame that determines
80530 ** whether or not the jump should be taken. The bitmask is necessary
80531 ** because the self-altering code trick does not work for recursive
80532 ** triggers.
80533 */
80534 case OP_Once: { /* jump */
80535 u32 iAddr; /* Address of this instruction */
80536 assert( p->aOp[0].opcode==OP_Init );
80537 if( p->pFrame ){
80538 iAddr = (int)(pOp - p->aOp);
80539 if( (p->pFrame->aOnce[iAddr/8] & (1<<(iAddr & 7)))!=0 ){
80540 VdbeBranchTaken(1, 2);
80541 goto jump_to_p2;
80542 }
80543 p->pFrame->aOnce[iAddr/8] |= 1<<(iAddr & 7);
80544 }else{
80545 if( p->aOp[0].p1==pOp->p1 ){
80546 VdbeBranchTaken(1, 2);
80547 goto jump_to_p2;
80548 }
80549 }
80550 VdbeBranchTaken(0, 2);
80551 pOp->p1 = p->aOp[0].p1;
80552 break;
80553 }
80554
80555 /* Opcode: If P1 P2 P3 * *
80556 **
@@ -80650,12 +80859,17 @@
80859 /* Content is irrelevant for
80860 ** 1. the typeof() function,
80861 ** 2. the length(X) function if X is a blob, and
80862 ** 3. if the content length is zero.
80863 ** So we might as well use bogus content rather than reading
80864 ** content from disk.
80865 **
80866 ** Although sqlite3VdbeSerialGet() may read at most 8 bytes from the
80867 ** buffer passed to it, debugging function VdbeMemPrettyPrint() may
80868 ** read up to 16. So 16 bytes of bogus content is supplied.
80869 */
80870 static u8 aZero[16]; /* This is the bogus content */
80871 sqlite3VdbeSerialGet(aZero, t, pDest);
80872 }else{
80873 rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest);
80874 if( rc!=SQLITE_OK ) goto abort_due_to_error;
80875 sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest);
@@ -82836,10 +83050,37 @@
83050 assert( pOp->p2==0 );
83051 }
83052 break;
83053 }
83054
83055 /* Opcode: IfSmaller P1 P2 P3 * *
83056 **
83057 ** Estimate the number of rows in the table P1. Jump to P2 if that
83058 ** estimate is less than approximately 2**(0.1*P3).
83059 */
83060 case OP_IfSmaller: { /* jump */
83061 VdbeCursor *pC;
83062 BtCursor *pCrsr;
83063 int res;
83064 i64 sz;
83065
83066 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
83067 pC = p->apCsr[pOp->p1];
83068 assert( pC!=0 );
83069 pCrsr = pC->uc.pCursor;
83070 assert( pCrsr );
83071 rc = sqlite3BtreeFirst(pCrsr, &res);
83072 if( rc ) goto abort_due_to_error;
83073 if( res==0 ){
83074 sz = sqlite3BtreeRowCountEst(pCrsr);
83075 if( ALWAYS(sz>=0) && sqlite3LogEst((u64)sz)<pOp->p3 ) res = 1;
83076 }
83077 VdbeBranchTaken(res!=0,2);
83078 if( res ) goto jump_to_p2;
83079 break;
83080 }
83081
83082
83083 /* Opcode: SorterSort P1 P2 * * *
83084 **
83085 ** After all records have been inserted into the Sorter object
83086 ** identified by P1, invoke this opcode to actually do the sorting.
@@ -83479,10 +83720,22 @@
83720 rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, flags);
83721 if( rc ) goto abort_due_to_error;
83722 pOut->u.i = pgno;
83723 break;
83724 }
83725
83726 /* Opcode: SqlExec * * * P4 *
83727 **
83728 ** Run the SQL statement or statements specified in the P4 string.
83729 */
83730 case OP_SqlExec: {
83731 db->nSqlExec++;
83732 rc = sqlite3_exec(db, pOp->p4.z, 0, 0, 0);
83733 db->nSqlExec--;
83734 if( rc ) goto abort_due_to_error;
83735 break;
83736 }
83737
83738 /* Opcode: ParseSchema P1 * * P4 *
83739 **
83740 ** Read and parse all entries from the SQLITE_MASTER table of database P1
83741 ** that match the WHERE clause P4.
@@ -83600,11 +83853,11 @@
83853 **
83854 ** Do an analysis of the currently open database. Store in
83855 ** register P1 the text of an error message describing any problems.
83856 ** If no problems are found, store a NULL in register P1.
83857 **
83858 ** The register P3 contains one less than the maximum number of allowed errors.
83859 ** At most reg(P3) errors will be reported.
83860 ** In other words, the analysis stops as soon as reg(P1) errors are
83861 ** seen. Reg(P1) is updated with the number of errors remaining.
83862 **
83863 ** The root page numbers of all tables in the database are integers
@@ -83633,18 +83886,18 @@
83886 assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 );
83887 pIn1 = &aMem[pOp->p1];
83888 assert( pOp->p5<db->nDb );
83889 assert( DbMaskTest(p->btreeMask, pOp->p5) );
83890 z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot,
83891 (int)pnErr->u.i+1, &nErr);
 
83892 sqlite3VdbeMemSetNull(pIn1);
83893 if( nErr==0 ){
83894 assert( z==0 );
83895 }else if( z==0 ){
83896 goto no_mem;
83897 }else{
83898 pnErr->u.i -= nErr-1;
83899 sqlite3VdbeMemSetStr(pIn1, z, -1, SQLITE_UTF8, sqlite3_free);
83900 }
83901 UPDATE_MAX_BLOBSIZE(pIn1);
83902 sqlite3VdbeChangeEncoding(pIn1, encoding);
83903 break;
@@ -83819,11 +84072,12 @@
84072 nMem = pProgram->nMem + pProgram->nCsr;
84073 assert( nMem>0 );
84074 if( pProgram->nCsr==0 ) nMem++;
84075 nByte = ROUND8(sizeof(VdbeFrame))
84076 + nMem * sizeof(Mem)
84077 + pProgram->nCsr * sizeof(VdbeCursor*)
84078 + (pProgram->nOp + 7)/8;
84079 pFrame = sqlite3DbMallocZero(db, nByte);
84080 if( !pFrame ){
84081 goto no_mem;
84082 }
84083 sqlite3VdbeMemRelease(pRt);
@@ -83870,10 +84124,12 @@
84124 p->pFrame = pFrame;
84125 p->aMem = aMem = VdbeFrameMem(pFrame);
84126 p->nMem = pFrame->nChildMem;
84127 p->nCursor = (u16)pFrame->nChildCsr;
84128 p->apCsr = (VdbeCursor **)&aMem[p->nMem];
84129 pFrame->aOnce = (u8*)&p->apCsr[pProgram->nCsr];
84130 memset(pFrame->aOnce, 0, (pProgram->nOp + 7)/8);
84131 p->aOp = aOp = pProgram->aOp;
84132 p->nOp = pProgram->nOp;
84133 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
84134 p->anExec = 0;
84135 #endif
@@ -84899,11 +85155,15 @@
85155 char *z = sqlite3VdbeExpandSql(p, zTrace);
85156 x(db->pTraceArg, z);
85157 sqlite3_free(z);
85158 }else
85159 #endif
85160 if( db->nVdbeExec>1 ){
85161 char *z = sqlite3MPrintf(db, "-- %s", zTrace);
85162 (void)db->xTrace(SQLITE_TRACE_STMT, db->pTraceArg, p, z);
85163 sqlite3DbFree(db, z);
85164 }else{
85165 (void)db->xTrace(SQLITE_TRACE_STMT, db->pTraceArg, p, zTrace);
85166 }
85167 }
85168 #ifdef SQLITE_USE_FCNTL_TRACE
85169 zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
@@ -88787,15 +89047,15 @@
89047 ** The return value from the callback should be one of the WRC_*
89048 ** constants to specify how to proceed with the walk.
89049 **
89050 ** WRC_Continue Continue descending down the tree.
89051 **
89052 ** WRC_Prune Do not descend into child nodes, but allow
89053 ** the walk to continue with sibling nodes.
89054 **
89055 ** WRC_Abort Do no more callbacks. Unwind the stack and
89056 ** return from the top-level walk call.
89057 **
89058 ** The return value from this routine is WRC_Abort to abandon the tree walk
89059 ** and WRC_Continue to continue.
89060 */
89061 static SQLITE_NOINLINE int walkExpr(Walker *pWalker, Expr *pExpr){
@@ -89153,11 +89413,12 @@
89413 }
89414 }
89415 }
89416
89417 /* Start at the inner-most context and move outward until a match is found */
89418 assert( pNC && cnt==0 );
89419 do{
89420 ExprList *pEList;
89421 SrcList *pSrcList = pNC->pSrcList;
89422
89423 if( pSrcList ){
89424 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
@@ -89338,15 +89599,15 @@
89599 }
89600
89601 /* Advance to the next name context. The loop will exit when either
89602 ** we have a match (cnt>0) or when we run out of name contexts.
89603 */
89604 if( cnt ) break;
89605 pNC = pNC->pNext;
89606 nSubquery++;
89607 }while( pNC );
89608
89609
89610 /*
89611 ** If X and Y are NULL (in other words if only the column name Z is
89612 ** supplied) and the value of Z is enclosed in double-quotes, then
89613 ** Z is a string literal if it doesn't match any column names. In that
@@ -89532,37 +89793,42 @@
89793 break;
89794 }
89795 #endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
89796 && !defined(SQLITE_OMIT_SUBQUERY) */
89797
89798 /* A column name: ID
89799 ** Or table name and column name: ID.ID
 
 
 
 
 
89800 ** Or a database, table and column: ID.ID.ID
89801 **
89802 ** The TK_ID and TK_OUT cases are combined so that there will only
89803 ** be one call to lookupName(). Then the compiler will in-line
89804 ** lookupName() for a size reduction and performance increase.
89805 */
89806 case TK_ID:
89807 case TK_DOT: {
89808 const char *zColumn;
89809 const char *zTable;
89810 const char *zDb;
89811 Expr *pRight;
89812
89813 if( pExpr->op==TK_ID ){
 
 
 
89814 zDb = 0;
89815 zTable = 0;
89816 zColumn = pExpr->u.zToken;
89817 }else{
89818 notValid(pParse, pNC, "the \".\" operator", NC_IdxExpr);
89819 pRight = pExpr->pRight;
89820 if( pRight->op==TK_ID ){
89821 zDb = 0;
89822 zTable = pExpr->pLeft->u.zToken;
89823 zColumn = pRight->u.zToken;
89824 }else{
89825 assert( pRight->op==TK_DOT );
89826 zDb = pExpr->pLeft->u.zToken;
89827 zTable = pRight->pLeft->u.zToken;
89828 zColumn = pRight->pRight->u.zToken;
89829 }
89830 }
89831 return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr);
89832 }
89833
89834 /* Resolve function names
@@ -92326,10 +92592,11 @@
92592 ** in *pValue. If the expression is not an integer or if it is too big
92593 ** to fit in a signed 32-bit integer, return 0 and leave *pValue unchanged.
92594 */
92595 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr *p, int *pValue){
92596 int rc = 0;
92597 if( p==0 ) return 0; /* Can only happen following on OOM */
92598
92599 /* If an expression is an integer literal that fits in a signed 32-bit
92600 ** integer, then the EP_IntValue flag will have already been set */
92601 assert( p->op!=TK_INTEGER || (p->flags & EP_IntValue)!=0
92602 || sqlite3GetInt32(p->u.zToken, &rc)==0 );
@@ -92833,11 +93100,11 @@
93100 int nVal = sqlite3ExprVectorSize(pLeft);
93101 Select *pSelect = (pExpr->flags & EP_xIsSelect) ? pExpr->x.pSelect : 0;
93102 char *zRet;
93103
93104 assert( pExpr->op==TK_IN );
93105 zRet = sqlite3DbMallocRaw(pParse->db, nVal+1);
93106 if( zRet ){
93107 int i;
93108 for(i=0; i<nVal; i++){
93109 Expr *pA = sqlite3VectorFieldSubexpr(pLeft, i);
93110 char a = sqlite3ExprAffinity(pA);
@@ -92998,11 +93265,10 @@
93265 if( ALWAYS(pEList->nExpr==nVal) ){
93266 SelectDest dest;
93267 int i;
93268 sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
93269 dest.zAffSdst = exprINAffinity(pParse, pExpr);
 
93270 pSelect->iLimit = 0;
93271 testcase( pSelect->selFlags & SF_Distinct );
93272 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
93273 if( sqlite3Select(pParse, pSelect, &dest) ){
93274 sqlite3DbFree(pParse->db, dest.zAffSdst);
@@ -93738,11 +94004,11 @@
94004 ** Clear all column cache entries.
94005 */
94006 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse *pParse){
94007 int i;
94008
94009 #ifdef SQLITE_DEBUG
94010 if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
94011 printf("CLEAR\n");
94012 }
94013 #endif
94014 for(i=0; i<pParse->nColCache; i++){
@@ -95145,10 +95411,21 @@
95411 if( pA->a[i].sortOrder!=pB->a[i].sortOrder ) return 1;
95412 if( sqlite3ExprCompare(pExprA, pExprB, iTab) ) return 1;
95413 }
95414 return 0;
95415 }
95416
95417 /*
95418 ** Like sqlite3ExprCompare() except COLLATE operators at the top-level
95419 ** are ignored.
95420 */
95421 SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr *pA, Expr *pB, int iTab){
95422 return sqlite3ExprCompare(
95423 sqlite3ExprSkipCollate(pA),
95424 sqlite3ExprSkipCollate(pB),
95425 iTab);
95426 }
95427
95428 /*
95429 ** Return true if we can prove the pE2 will always be true if pE1 is
95430 ** true. Return false if we cannot complete the proof or if pE2 might
95431 ** be false. Examples:
@@ -96698,10 +96975,11 @@
96975 Stat4Sample current; /* Current row as a Stat4Sample */
96976 u32 iPrn; /* Pseudo-random number used for sampling */
96977 Stat4Sample *aBest; /* Array of nCol best samples */
96978 int iMin; /* Index in a[] of entry with minimum score */
96979 int nSample; /* Current number of samples */
96980 int nMaxEqZero; /* Max leading 0 in anEq[] for any a[] entry */
96981 int iGet; /* Index of current sample accessed by stat_get() */
96982 Stat4Sample *a; /* Array of mxSample Stat4Sample objects */
96983 sqlite3 *db; /* Database connection, for malloc() */
96984 };
96985
@@ -96962,10 +97240,17 @@
97240 int i;
97241
97242 assert( IsStat4 || nEqZero==0 );
97243
97244 #ifdef SQLITE_ENABLE_STAT4
97245 /* Stat4Accum.nMaxEqZero is set to the maximum number of leading 0
97246 ** values in the anEq[] array of any sample in Stat4Accum.a[]. In
97247 ** other words, if nMaxEqZero is n, then it is guaranteed that there
97248 ** are no samples with Stat4Sample.anEq[m]==0 for (m>=n). */
97249 if( nEqZero>p->nMaxEqZero ){
97250 p->nMaxEqZero = nEqZero;
97251 }
97252 if( pNew->isPSample==0 ){
97253 Stat4Sample *pUpgrade = 0;
97254 assert( pNew->anEq[pNew->iCol]>0 );
97255
97256 /* This sample is being added because the prefix that ends in column
@@ -97059,16 +97344,26 @@
97344 if( p->nSample<p->mxSample || sampleIsBetter(p, pBest, &p->a[p->iMin]) ){
97345 sampleInsert(p, pBest, i);
97346 }
97347 }
97348
97349 /* Check that no sample contains an anEq[] entry with an index of
97350 ** p->nMaxEqZero or greater set to zero. */
97351 for(i=p->nSample-1; i>=0; i--){
97352 int j;
97353 for(j=p->nMaxEqZero; j<p->nCol; j++) assert( p->a[i].anEq[j]>0 );
97354 }
97355
97356 /* Update the anEq[] fields of any samples already collected. */
97357 if( iChng<p->nMaxEqZero ){
97358 for(i=p->nSample-1; i>=0; i--){
97359 int j;
97360 for(j=iChng; j<p->nCol; j++){
97361 if( p->a[i].anEq[j]==0 ) p->a[i].anEq[j] = p->current.anEq[j];
97362 }
97363 }
97364 p->nMaxEqZero = iChng;
97365 }
97366 #endif
97367
97368 #if defined(SQLITE_ENABLE_STAT3) && !defined(SQLITE_ENABLE_STAT4)
97369 if( iChng==0 ){
@@ -97594,11 +97889,11 @@
97889 Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
97890 int j, k, regKey;
97891 regKey = sqlite3GetTempRange(pParse, pPk->nKeyCol);
97892 for(j=0; j<pPk->nKeyCol; j++){
97893 k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
97894 assert( k>=0 && k<pIdx->nColumn );
97895 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, regKey+j);
97896 VdbeComment((v, "%s", pTab->aCol[pPk->aiColumn[j]].zName));
97897 }
97898 sqlite3VdbeAddOp3(v, OP_MakeRecord, regKey, pPk->nKeyCol, regRowid);
97899 sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol);
@@ -97778,44 +98073,32 @@
98073 /* Form 1: Analyze everything */
98074 for(i=0; i<db->nDb; i++){
98075 if( i==1 ) continue; /* Do not analyze the TEMP database */
98076 analyzeDatabase(pParse, i);
98077 }
98078 }else if( pName2->n==0 && (iDb = sqlite3FindDb(db, pName1))>=0 ){
98079 /* Analyze the schema named as the argument */
98080 analyzeDatabase(pParse, iDb);
98081 }else{
98082 /* Form 3: Analyze the table or index named as an argument */
 
 
 
 
 
 
 
 
 
 
 
 
 
98083 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName);
98084 if( iDb>=0 ){
98085 zDb = pName2->n ? db->aDb[iDb].zDbSName : 0;
98086 z = sqlite3NameFromToken(db, pTableName);
98087 if( z ){
98088 if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
98089 analyzeTable(pParse, pIdx->pTable, pIdx);
98090 }else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){
98091 analyzeTable(pParse, pTab, 0);
98092 }
98093 sqlite3DbFree(db, z);
98094 }
98095 }
98096 }
98097 if( db->nSqlExec==0 && (v = sqlite3GetVdbe(pParse))!=0 ){
98098 sqlite3VdbeAddOp0(v, OP_Expire);
98099 }
98100 }
98101
98102 /*
98103 ** Used to pass information from the analyzer reader through to the
98104 ** callback routine.
@@ -97940,19 +98223,24 @@
98223 }
98224 aiRowEst = pIndex->aiRowEst;
98225 #endif
98226 pIndex->bUnordered = 0;
98227 decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex);
98228 pIndex->hasStat1 = 1;
98229 if( pIndex->pPartIdxWhere==0 ){
98230 pTable->nRowLogEst = pIndex->aiRowLogEst[0];
98231 pTable->tabFlags |= TF_HasStat1;
98232 }
98233 }else{
98234 Index fakeIdx;
98235 fakeIdx.szIdxRow = pTable->szTabRow;
98236 #ifdef SQLITE_ENABLE_COSTMULT
98237 fakeIdx.pTable = pTable;
98238 #endif
98239 decodeIntArray((char*)z, 1, 0, &pTable->nRowLogEst, &fakeIdx);
98240 pTable->szTabRow = fakeIdx.szIdxRow;
98241 pTable->tabFlags |= TF_HasStat1;
98242 }
98243
98244 return 0;
98245 }
98246
@@ -98243,19 +98531,24 @@
98531 SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
98532 analysisInfo sInfo;
98533 HashElem *i;
98534 char *zSql;
98535 int rc = SQLITE_OK;
98536 Schema *pSchema = db->aDb[iDb].pSchema;
98537
98538 assert( iDb>=0 && iDb<db->nDb );
98539 assert( db->aDb[iDb].pBt!=0 );
98540
98541 /* Clear any prior statistics */
98542 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
98543 for(i=sqliteHashFirst(&pSchema->tblHash); i; i=sqliteHashNext(i)){
98544 Table *pTab = sqliteHashData(i);
98545 pTab->tabFlags &= ~TF_HasStat1;
98546 }
98547 for(i=sqliteHashFirst(&pSchema->idxHash); i; i=sqliteHashNext(i)){
98548 Index *pIdx = sqliteHashData(i);
98549 pIdx->hasStat1 = 0;
98550 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
98551 sqlite3DeleteIndexSamples(db, pIdx);
98552 pIdx->aSample = 0;
98553 #endif
98554 }
@@ -98274,23 +98567,23 @@
98567 }
98568 }
98569
98570 /* Set appropriate defaults on all indexes not in the sqlite_stat1 table */
98571 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
98572 for(i=sqliteHashFirst(&pSchema->idxHash); i; i=sqliteHashNext(i)){
98573 Index *pIdx = sqliteHashData(i);
98574 if( !pIdx->hasStat1 ) sqlite3DefaultRowEst(pIdx);
98575 }
98576
98577 /* Load the statistics from the sqlite_stat4 table. */
98578 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
98579 if( rc==SQLITE_OK && OptimizationEnabled(db, SQLITE_Stat34) ){
98580 db->lookaside.bDisable++;
98581 rc = loadStat4(db, sInfo.zDatabase);
98582 db->lookaside.bDisable--;
98583 }
98584 for(i=sqliteHashFirst(&pSchema->idxHash); i; i=sqliteHashNext(i)){
98585 Index *pIdx = sqliteHashData(i);
98586 sqlite3_free(pIdx->aiRowEst);
98587 pIdx->aiRowEst = 0;
98588 }
98589 #endif
@@ -100271,10 +100564,11 @@
100564 SQLITE_PRIVATE void sqlite3AddNotNull(Parse *pParse, int onError){
100565 Table *p;
100566 p = pParse->pNewTable;
100567 if( p==0 || NEVER(p->nCol<1) ) return;
100568 p->aCol[p->nCol-1].notNull = (u8)onError;
100569 p->tabFlags |= TF_HasNotNull;
100570 }
100571
100572 /*
100573 ** Scan the column type name zType (length nType) and return the
100574 ** associated affinity type.
@@ -102609,10 +102903,13 @@
102903 /* 10, 9, 8, 7, 6 */
102904 LogEst aVal[] = { 33, 32, 30, 28, 26 };
102905 LogEst *a = pIdx->aiRowLogEst;
102906 int nCopy = MIN(ArraySize(aVal), pIdx->nKeyCol);
102907 int i;
102908
102909 /* Indexes with default row estimates should not have stat1 data */
102910 assert( !pIdx->hasStat1 );
102911
102912 /* Set the first entry (number of rows in the index) to the estimated
102913 ** number of rows in the table, or half the number of rows in the table
102914 ** for a partial index. But do not let the estimate drop below 10. */
102915 a[0] = pIdx->pTable->nRowLogEst;
@@ -105193,19 +105490,17 @@
105490 nNeedle = sqlite3_value_bytes(argv[1]);
105491 if( nNeedle>0 ){
105492 if( typeHaystack==SQLITE_BLOB && typeNeedle==SQLITE_BLOB ){
105493 zHaystack = sqlite3_value_blob(argv[0]);
105494 zNeedle = sqlite3_value_blob(argv[1]);
 
 
105495 isText = 0;
105496 }else{
105497 zHaystack = sqlite3_value_text(argv[0]);
105498 zNeedle = sqlite3_value_text(argv[1]);
105499 isText = 1;
 
105500 }
105501 if( zNeedle==0 || (nHaystack && zHaystack==0) ) return;
105502 while( nNeedle<=nHaystack && memcmp(zHaystack, zNeedle, nNeedle)!=0 ){
105503 N++;
105504 do{
105505 nHaystack--;
105506 zHaystack++;
@@ -109798,10 +110093,13 @@
110093 VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
110094 }
110095 }
110096 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
110097 VdbeComment((v, "for %s", pIdx->zName));
110098 #ifdef SQLITE_ENABLE_NULL_TRIM
110099 if( pIdx->idxType==2 ) sqlite3SetMakeRecordP5(v, pIdx->pTable);
110100 #endif
110101
110102 /* In an UPDATE operation, if this index is the PRIMARY KEY index
110103 ** of a WITHOUT ROWID table and there has been no change the
110104 ** primary key, then no collision is possible. The collision detection
110105 ** logic below can all be skipped. */
@@ -109953,12 +110251,15 @@
110251
110252 /* Records with omitted columns are only allowed for schema format
110253 ** version 2 and later (SQLite version 3.1.4, 2005-02-20). */
110254 if( pTab->pSchema->file_format<2 ) return;
110255
110256 for(i=pTab->nCol-1; i>0; i--){
110257 if( pTab->aCol[i].pDflt!=0 ) break;
110258 if( pTab->aCol[i].colFlags & COLFLAG_PRIMKEY ) break;
110259 }
110260 sqlite3VdbeChangeP5(v, i+1);
110261 }
110262 #endif
110263
110264 /*
110265 ** This routine generates code to finish the INSERT or UPDATE operation
@@ -110244,11 +110545,11 @@
110545 }
110546 if( sqlite3TriggerList(pParse, pDest) ){
110547 return 0; /* tab1 must not have triggers */
110548 }
110549 #ifndef SQLITE_OMIT_VIRTUALTABLE
110550 if( IsVirtual(pDest) ){
110551 return 0; /* tab1 must not be a virtual table */
110552 }
110553 #endif
110554 if( onError==OE_Default ){
110555 if( pDest->iPKey>=0 ) onError = pDest->keyConf;
@@ -110306,11 +110607,11 @@
110607 }
110608 if( HasRowid(pDest)!=HasRowid(pSrc) ){
110609 return 0; /* source and destination must both be WITHOUT ROWID or not */
110610 }
110611 #ifndef SQLITE_OMIT_VIRTUALTABLE
110612 if( IsVirtual(pSrc) ){
110613 return 0; /* tab2 must not be a virtual table */
110614 }
110615 #endif
110616 if( pSrc->pSelect ){
110617 return 0; /* tab2 may not be a view */
@@ -110492,12 +110793,10 @@
110793 ** might change the definition of a collation sequence and then run
110794 ** a VACUUM command. In that case keys may not be written in strictly
110795 ** sorted order. */
110796 for(i=0; i<pSrcIdx->nColumn; i++){
110797 const char *zColl = pSrcIdx->azColl[i];
 
 
110798 if( sqlite3_stricmp(sqlite3StrBINARY, zColl) ) break;
110799 }
110800 if( i==pSrcIdx->nColumn ){
110801 idxInsFlags = OPFLAG_USESEEKRESULT;
110802 sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
@@ -110603,11 +110902,11 @@
110902 /* Invoke the callback function if required */
110903 if( xCallback && (SQLITE_ROW==rc ||
110904 (SQLITE_DONE==rc && !callbackIsInit
110905 && db->flags&SQLITE_NullCallback)) ){
110906 if( !callbackIsInit ){
110907 azCols = sqlite3DbMallocRaw(db, (2*nCol+1)*sizeof(const char*));
110908 if( azCols==0 ){
110909 goto exec_out;
110910 }
110911 for(i=0; i<nCol; i++){
110912 azCols[i] = (char *)sqlite3_column_name(pStmt, i);
@@ -110624,10 +110923,11 @@
110923 if( !azVals[i] && sqlite3_column_type(pStmt, i)!=SQLITE_NULL ){
110924 sqlite3OomFault(db);
110925 goto exec_out;
110926 }
110927 }
110928 azVals[i] = 0;
110929 }
110930 if( xCallback(pArg, nCol, azVals, azCols) ){
110931 /* EVIDENCE-OF: R-38229-40159 If the callback function to
110932 ** sqlite3_exec() returns non-zero, then sqlite3_exec() will
110933 ** return SQLITE_ABORT. */
@@ -110979,10 +111279,12 @@
111279 /* Version 3.12.0 and later */
111280 int (*system_errno)(sqlite3*);
111281 /* Version 3.14.0 and later */
111282 int (*trace_v2)(sqlite3*,unsigned,int(*)(unsigned,void*,void*,void*),void*);
111283 char *(*expanded_sql)(sqlite3_stmt*);
111284 /* Version 3.18.0 and later */
111285 void (*set_last_insert_rowid)(sqlite3*,sqlite3_int64);
111286 };
111287
111288 /*
111289 ** This is the function signature used for all extension entry points. It
111290 ** is also defined in the file "loadext.c".
@@ -111237,10 +111539,12 @@
111539 /* Version 3.12.0 and later */
111540 #define sqlite3_system_errno sqlite3_api->system_errno
111541 /* Version 3.14.0 and later */
111542 #define sqlite3_trace_v2 sqlite3_api->trace_v2
111543 #define sqlite3_expanded_sql sqlite3_api->expanded_sql
111544 /* Version 3.18.0 and later */
111545 #define sqlite3_set_last_insert_rowid sqlite3_api->set_last_insert_rowid
111546 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
111547
111548 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
111549 /* This case when the file really is being compiled as a loadable
111550 ** extension */
@@ -111662,11 +111966,13 @@
111966 sqlite3_db_cacheflush,
111967 /* Version 3.12.0 and later */
111968 sqlite3_system_errno,
111969 /* Version 3.14.0 and later */
111970 sqlite3_trace_v2,
111971 sqlite3_expanded_sql,
111972 /* Version 3.18.0 and later */
111973 sqlite3_set_last_insert_rowid
111974 };
111975
111976 /*
111977 ** Attempt to load an SQLite extension library contained in the file
111978 ** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -112094,15 +112400,15 @@
112400 #define PragTyp_JOURNAL_SIZE_LIMIT 20
112401 #define PragTyp_LOCK_PROXY_FILE 21
112402 #define PragTyp_LOCKING_MODE 22
112403 #define PragTyp_PAGE_COUNT 23
112404 #define PragTyp_MMAP_SIZE 24
112405 #define PragTyp_OPTIMIZE 25
112406 #define PragTyp_PAGE_SIZE 26
112407 #define PragTyp_SECURE_DELETE 27
112408 #define PragTyp_SHRINK_MEMORY 28
112409 #define PragTyp_SOFT_HEAP_LIMIT 29
112410 #define PragTyp_SYNCHRONOUS 30
112411 #define PragTyp_TABLE_INFO 31
112412 #define PragTyp_TEMP_STORE 32
112413 #define PragTyp_TEMP_STORE_DIRECTORY 33
112414 #define PragTyp_THREADS 34
@@ -112112,10 +112418,11 @@
112418 #define PragTyp_HEXKEY 38
112419 #define PragTyp_KEY 39
112420 #define PragTyp_REKEY 40
112421 #define PragTyp_LOCK_STATUS 41
112422 #define PragTyp_PARSER_TRACE 42
112423 #define PragTyp_STATS 43
112424
112425 /* Property flags associated with various pragma. */
112426 #define PragFlg_NeedSchema 0x01 /* Force schema load before running */
112427 #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */
112428 #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */
@@ -112135,51 +112442,52 @@
112442 /* 2 */ "name",
112443 /* 3 */ "type",
112444 /* 4 */ "notnull",
112445 /* 5 */ "dflt_value",
112446 /* 6 */ "pk",
112447 /* 7 */ "tbl", /* Used by: stats */
112448 /* 8 */ "idx",
112449 /* 9 */ "wdth",
112450 /* 10 */ "hght",
112451 /* 11 */ "flgs",
112452 /* 12 */ "seqno", /* Used by: index_info */
112453 /* 13 */ "cid",
112454 /* 14 */ "name",
112455 /* 15 */ "seqno", /* Used by: index_xinfo */
112456 /* 16 */ "cid",
112457 /* 17 */ "name",
112458 /* 18 */ "desc",
112459 /* 19 */ "coll",
112460 /* 20 */ "key",
112461 /* 21 */ "seq", /* Used by: index_list */
112462 /* 22 */ "name",
112463 /* 23 */ "unique",
112464 /* 24 */ "origin",
112465 /* 25 */ "partial",
112466 /* 26 */ "seq", /* Used by: database_list */
112467 /* 27 */ "name",
112468 /* 28 */ "file",
112469 /* 29 */ "seq", /* Used by: collation_list */
112470 /* 30 */ "name",
112471 /* 31 */ "id", /* Used by: foreign_key_list */
112472 /* 32 */ "seq",
112473 /* 33 */ "table",
112474 /* 34 */ "from",
112475 /* 35 */ "to",
112476 /* 36 */ "on_update",
112477 /* 37 */ "on_delete",
112478 /* 38 */ "match",
112479 /* 39 */ "table", /* Used by: foreign_key_check */
112480 /* 40 */ "rowid",
112481 /* 41 */ "parent",
112482 /* 42 */ "fkid",
112483 /* 43 */ "busy", /* Used by: wal_checkpoint */
112484 /* 44 */ "log",
112485 /* 45 */ "checkpointed",
112486 /* 46 */ "timeout", /* Used by: busy_timeout */
112487 /* 47 */ "database", /* Used by: lock_status */
112488 /* 48 */ "status",
112489 };
112490
112491 /* Definitions of all built-in pragmas */
112492 typedef struct PragmaName {
112493 const char *const zName; /* Name of pragma */
@@ -112221,11 +112529,11 @@
112529 #endif
112530 #endif
112531 {/* zName: */ "busy_timeout",
112532 /* ePragTyp: */ PragTyp_BUSY_TIMEOUT,
112533 /* ePragFlg: */ PragFlg_Result0,
112534 /* ColNames: */ 46, 1,
112535 /* iArg: */ 0 },
112536 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112537 {/* zName: */ "cache_size",
112538 /* ePragTyp: */ PragTyp_CACHE_SIZE,
112539 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
@@ -112258,11 +112566,11 @@
112566 #endif
112567 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
112568 {/* zName: */ "collation_list",
112569 /* ePragTyp: */ PragTyp_COLLATION_LIST,
112570 /* ePragFlg: */ PragFlg_Result0,
112571 /* ColNames: */ 29, 2,
112572 /* iArg: */ 0 },
112573 #endif
112574 #if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
112575 {/* zName: */ "compile_options",
112576 /* ePragTyp: */ PragTyp_COMPILE_OPTIONS,
@@ -112293,11 +112601,11 @@
112601 #endif
112602 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
112603 {/* zName: */ "database_list",
112604 /* ePragTyp: */ PragTyp_DATABASE_LIST,
112605 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
112606 /* ColNames: */ 26, 3,
112607 /* iArg: */ 0 },
112608 #endif
112609 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
112610 {/* zName: */ "default_cache_size",
112611 /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
@@ -112330,18 +112638,18 @@
112638 #endif
112639 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
112640 {/* zName: */ "foreign_key_check",
112641 /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK,
112642 /* ePragFlg: */ PragFlg_NeedSchema,
112643 /* ColNames: */ 39, 4,
112644 /* iArg: */ 0 },
112645 #endif
112646 #if !defined(SQLITE_OMIT_FOREIGN_KEY)
112647 {/* zName: */ "foreign_key_list",
112648 /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST,
112649 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112650 /* ColNames: */ 31, 8,
112651 /* iArg: */ 0 },
112652 #endif
112653 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112654 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
112655 {/* zName: */ "foreign_keys",
@@ -112400,21 +112708,21 @@
112708 #endif
112709 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
112710 {/* zName: */ "index_info",
112711 /* ePragTyp: */ PragTyp_INDEX_INFO,
112712 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112713 /* ColNames: */ 12, 3,
112714 /* iArg: */ 0 },
112715 {/* zName: */ "index_list",
112716 /* ePragTyp: */ PragTyp_INDEX_LIST,
112717 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112718 /* ColNames: */ 21, 5,
112719 /* iArg: */ 0 },
112720 {/* zName: */ "index_xinfo",
112721 /* ePragTyp: */ PragTyp_INDEX_INFO,
112722 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112723 /* ColNames: */ 15, 6,
112724 /* iArg: */ 1 },
112725 #endif
112726 #if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
112727 {/* zName: */ "integrity_check",
112728 /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
@@ -112457,11 +112765,11 @@
112765 #endif
112766 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
112767 {/* zName: */ "lock_status",
112768 /* ePragTyp: */ PragTyp_LOCK_STATUS,
112769 /* ePragFlg: */ PragFlg_Result0,
112770 /* ColNames: */ 47, 2,
112771 /* iArg: */ 0 },
112772 #endif
112773 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112774 {/* zName: */ "locking_mode",
112775 /* ePragTyp: */ PragTyp_LOCKING_MODE,
@@ -112476,10 +112784,17 @@
112784 {/* zName: */ "mmap_size",
112785 /* ePragTyp: */ PragTyp_MMAP_SIZE,
112786 /* ePragFlg: */ 0,
112787 /* ColNames: */ 0, 0,
112788 /* iArg: */ 0 },
112789 #endif
112790 {/* zName: */ "optimize",
112791 /* ePragTyp: */ PragTyp_OPTIMIZE,
112792 /* ePragFlg: */ PragFlg_Result1,
112793 /* ColNames: */ 0, 0,
112794 /* iArg: */ 0 },
112795 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112796 {/* zName: */ "page_count",
112797 /* ePragTyp: */ PragTyp_PAGE_COUNT,
112798 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
112799 /* ColNames: */ 0, 0,
112800 /* iArg: */ 0 },
@@ -112574,15 +112889,15 @@
112889 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
112890 /* ColNames: */ 0, 0,
112891 /* iArg: */ SQLITE_SqlTrace },
112892 #endif
112893 #endif
112894 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && defined(SQLITE_DEBUG)
112895 {/* zName: */ "stats",
112896 /* ePragTyp: */ PragTyp_STATS,
112897 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
112898 /* ColNames: */ 7, 5,
112899 /* iArg: */ 0 },
112900 #endif
112901 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112902 {/* zName: */ "synchronous",
112903 /* ePragTyp: */ PragTyp_SYNCHRONOUS,
@@ -112657,11 +112972,11 @@
112972 /* ColNames: */ 0, 0,
112973 /* iArg: */ 0 },
112974 {/* zName: */ "wal_checkpoint",
112975 /* ePragTyp: */ PragTyp_WAL_CHECKPOINT,
112976 /* ePragFlg: */ PragFlg_NeedSchema,
112977 /* ColNames: */ 43, 3,
112978 /* iArg: */ 0 },
112979 #endif
112980 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112981 {/* zName: */ "writable_schema",
112982 /* ePragTyp: */ PragTyp_FLAG,
@@ -112668,11 +112983,11 @@
112983 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
112984 /* ColNames: */ 0, 0,
112985 /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
112986 #endif
112987 };
112988 /* Number of pragmas: 60 on by default, 74 total. */
112989
112990 /************** End of pragma.h **********************************************/
112991 /************** Continuing where we left off in pragma.c *********************/
112992
112993 /*
@@ -112937,10 +113252,26 @@
113252 lwr = mid + 1;
113253 }
113254 }
113255 return lwr>upr ? 0 : &aPragmaName[mid];
113256 }
113257
113258 /*
113259 ** Helper subroutine for PRAGMA integrity_check:
113260 **
113261 ** Generate code to output a single-column result row with the result
113262 ** held in register regResult. Decrement the result count and halt if
113263 ** the maximum number of result rows have been issued.
113264 */
113265 static int integrityCheckResultRow(Vdbe *v, int regResult){
113266 int addr;
113267 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 1);
113268 addr = sqlite3VdbeAddOp3(v, OP_IfPos, 1, sqlite3VdbeCurrentAddr(v)+2, 1);
113269 VdbeCoverage(v);
113270 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
113271 return addr;
113272 }
113273
113274 /*
113275 ** Process a pragma statement.
113276 **
113277 ** Pragmas are of this form:
@@ -113642,11 +113973,11 @@
113973 returnSingleInt(v, pDb->safety_level-1);
113974 }else{
113975 if( !db->autoCommit ){
113976 sqlite3ErrorMsg(pParse,
113977 "Safety level may not be changed inside a transaction");
113978 }else if( iDb!=1 ){
113979 int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK;
113980 if( iLevel==0 ) iLevel = 1;
113981 pDb->safety_level = iLevel;
113982 pDb->bSyncSet = 1;
113983 setAllPagerFlags(db);
@@ -113741,33 +114072,37 @@
114072 }
114073 }
114074 }
114075 break;
114076
114077 #ifdef SQLITE_DEBUG
114078 case PragTyp_STATS: {
114079 Index *pIdx;
114080 HashElem *i;
114081 pParse->nMem = 5;
114082 sqlite3CodeVerifySchema(pParse, iDb);
114083 for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){
114084 Table *pTab = sqliteHashData(i);
114085 sqlite3VdbeMultiLoad(v, 1, "ssiii",
114086 pTab->zName,
114087 0,
114088 pTab->szTabRow,
114089 pTab->nRowLogEst,
114090 pTab->tabFlags);
114091 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 5);
114092 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
114093 sqlite3VdbeMultiLoad(v, 2, "siii",
114094 pIdx->zName,
114095 pIdx->szIdxRow,
114096 pIdx->aiRowLogEst[0],
114097 pIdx->hasStat1);
114098 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 5);
114099 }
114100 }
114101 }
114102 break;
114103 #endif
114104
114105 case PragTyp_INDEX_INFO: if( zRight ){
114106 Index *pIdx;
114107 Table *pTab;
114108 pIdx = sqlite3FindIndex(db, zRight, zDb);
@@ -114020,13 +114355,21 @@
114355 #ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
114356 # define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100
114357 #endif
114358
114359 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
114360 /* PRAGMA integrity_check
114361 ** PRAGMA integrity_check(N)
114362 ** PRAGMA quick_check
114363 ** PRAGMA quick_check(N)
114364 **
114365 ** Verify the integrity of the database.
114366 **
114367 ** The "quick_check" is reduced version of
114368 ** integrity_check designed to detect most database corruption
114369 ** without the overhead of cross-checking indexes. Quick_check
114370 ** is linear time wherease integrity_check is O(NlogN).
114371 */
114372 case PragTyp_INTEGRITY_CHECK: {
114373 int i, j, addr, mxErr;
114374
114375 int isQuick = (sqlite3Tolower(zLeft[0])=='q');
@@ -114053,11 +114396,11 @@
114396 sqlite3GetInt32(zRight, &mxErr);
114397 if( mxErr<=0 ){
114398 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
114399 }
114400 }
114401 sqlite3VdbeAddOp2(v, OP_Integer, mxErr-1, 1); /* reg[1] holds errors left */
114402
114403 /* Do an integrity check on each database file */
114404 for(i=0; i<db->nDb; i++){
114405 HashElem *x;
114406 Hash *pTbls;
@@ -114068,14 +114411,10 @@
114411
114412 if( OMIT_TEMPDB && i==1 ) continue;
114413 if( iDb>=0 && i!=iDb ) continue;
114414
114415 sqlite3CodeVerifySchema(pParse, i);
 
 
 
 
114416
114417 /* Do an integrity check of the B-Tree
114418 **
114419 ** Begin by finding the root pages numbers
114420 ** for all tables and indices in the database.
@@ -114111,29 +114450,31 @@
114450 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
114451 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zDbSName),
114452 P4_DYNAMIC);
114453 sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1);
114454 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
114455 integrityCheckResultRow(v, 2);
114456 sqlite3VdbeJumpHere(v, addr);
114457
114458 /* Make sure all the indices are constructed correctly.
114459 */
114460 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
114461 Table *pTab = sqliteHashData(x);
114462 Index *pIdx, *pPk;
114463 Index *pPrior = 0;
114464 int loopTop;
114465 int iDataCur, iIdxCur;
114466 int r1 = -1;
114467
114468 if( pTab->tnum<1 ) continue; /* Skip VIEWs or VIRTUAL TABLEs */
114469 if( pTab->pCheck==0
114470 && (pTab->tabFlags & TF_HasNotNull)==0
114471 && (pTab->pIndex==0 || isQuick)
114472 ){
114473 continue; /* No additional checks needed for this table */
114474 }
114475 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
 
 
 
 
114476 sqlite3ExprCacheClear(pParse);
114477 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
114478 1, 0, &iDataCur, &iIdxCur);
114479 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
114480 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
@@ -114144,28 +114485,46 @@
114485 sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v);
114486 loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1);
114487 /* Verify that all NOT NULL columns really are NOT NULL */
114488 for(j=0; j<pTab->nCol; j++){
114489 char *zErr;
114490 int jmp2;
114491 if( j==pTab->iPKey ) continue;
114492 if( pTab->aCol[j].notNull==0 ) continue;
114493 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3);
114494 sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
114495 jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
 
114496 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
114497 pTab->aCol[j].zName);
114498 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
114499 integrityCheckResultRow(v, 3);
 
 
114500 sqlite3VdbeJumpHere(v, jmp2);
114501 }
114502 /* Verify CHECK constraints */
114503 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
114504 int addrCkFault = sqlite3VdbeMakeLabel(v);
114505 int addrCkOk = sqlite3VdbeMakeLabel(v);
114506 ExprList *pCheck = pTab->pCheck;
114507 char *zErr;
114508 int k;
114509 pParse->iSelfTab = iDataCur;
114510 sqlite3ExprCachePush(pParse);
114511 for(k=pCheck->nExpr-1; k>0; k--){
114512 sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
114513 }
114514 sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk,
114515 SQLITE_JUMPIFNULL);
114516 sqlite3VdbeResolveLabel(v, addrCkFault);
114517 zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
114518 pTab->zName);
114519 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
114520 integrityCheckResultRow(v, 3);
114521 sqlite3VdbeResolveLabel(v, addrCkOk);
114522 sqlite3ExprCachePop(pParse);
114523 }
114524 /* Validate index entries for the current row */
114525 for(j=0, pIdx=pTab->pIndex; pIdx && !isQuick; pIdx=pIdx->pNext, j++){
114526 int jmp2, jmp3, jmp4, jmp5;
114527 int ckUniq = sqlite3VdbeMakeLabel(v);
114528 if( pPk==pIdx ) continue;
114529 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
114530 pPrior, r1);
@@ -114172,20 +114531,17 @@
114531 pPrior = pIdx;
114532 sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */
114533 /* Verify that an index entry exists for the current table row */
114534 jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
114535 pIdx->nColumn); VdbeCoverage(v);
 
114536 sqlite3VdbeLoadString(v, 3, "row ");
114537 sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
114538 sqlite3VdbeLoadString(v, 4, " missing from index ");
114539 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
114540 jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName);
114541 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
114542 jmp4 = integrityCheckResultRow(v, 3);
 
 
114543 sqlite3VdbeJumpHere(v, jmp2);
114544 /* For UNIQUE indexes, verify that only one entry exists with the
114545 ** current key. The entry is unique if (1) any column is NULL
114546 ** or (2) the next entry has a different key */
114547 if( IsUniqueIndex(pIdx) ){
@@ -114202,11 +114558,10 @@
114558 jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v);
114559 sqlite3VdbeGoto(v, uniqOk);
114560 sqlite3VdbeJumpHere(v, jmp6);
114561 sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1,
114562 pIdx->nKeyCol); VdbeCoverage(v);
 
114563 sqlite3VdbeLoadString(v, 3, "non-unique entry in index ");
114564 sqlite3VdbeGoto(v, jmp5);
114565 sqlite3VdbeResolveLabel(v, uniqOk);
114566 }
114567 sqlite3VdbeJumpHere(v, jmp4);
@@ -114213,40 +114568,39 @@
114568 sqlite3ResolvePartIdxLabel(pParse, jmp3);
114569 }
114570 sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
114571 sqlite3VdbeJumpHere(v, loopTop-1);
114572 #ifndef SQLITE_OMIT_BTREECOUNT
114573 if( !isQuick ){
114574 sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
114575 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
114576 if( pPk==pIdx ) continue;
114577 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
114578 addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+j, 0, 3); VdbeCoverage(v);
114579 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
114580 sqlite3VdbeLoadString(v, 3, pIdx->zName);
114581 sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
114582 integrityCheckResultRow(v, 7);
114583 sqlite3VdbeJumpHere(v, addr);
114584 }
 
114585 }
114586 #endif /* SQLITE_OMIT_BTREECOUNT */
114587 }
114588 }
114589 {
114590 static const int iLn = VDBE_OFFSET_LINENO(2);
114591 static const VdbeOpList endCode[] = {
114592 { OP_AddImm, 1, 0, 0}, /* 0 */
114593 { OP_IfNotZero, 1, 4, 0}, /* 1 */
114594 { OP_String8, 0, 3, 0}, /* 2 */
114595 { OP_ResultRow, 3, 1, 0}, /* 3 */
114596 };
114597 VdbeOp *aOp;
114598
114599 aOp = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
114600 if( aOp ){
114601 aOp[0].p2 = 1-mxErr;
114602 aOp[2].p4type = P4_STATIC;
114603 aOp[2].p4.z = "ok";
114604 }
114605 }
114606 }
@@ -114466,10 +114820,122 @@
114820 */
114821 case PragTyp_SHRINK_MEMORY: {
114822 sqlite3_db_release_memory(db);
114823 break;
114824 }
114825
114826 /*
114827 ** PRAGMA optimize
114828 ** PRAGMA optimize(MASK)
114829 ** PRAGMA schema.optimize
114830 ** PRAGMA schema.optimize(MASK)
114831 **
114832 ** Attempt to optimize the database. All schemas are optimized in the first
114833 ** two forms, and only the specified schema is optimized in the latter two.
114834 **
114835 ** The details of optimizations performed by this pragma are expected
114836 ** to change and improve over time. Applications should anticipate that
114837 ** this pragma will perform new optimizations in future releases.
114838 **
114839 ** The optional argument is a bitmask of optimizations to perform:
114840 **
114841 ** 0x0001 Debugging mode. Do not actually perform any optimizations
114842 ** but instead return one line of text for each optimization
114843 ** that would have been done. Off by default.
114844 **
114845 ** 0x0002 Run ANALYZE on tables that might benefit. On by default.
114846 ** See below for additional information.
114847 **
114848 ** 0x0004 (Not yet implemented) Record usage and performance
114849 ** information from the current session in the
114850 ** database file so that it will be available to "optimize"
114851 ** pragmas run by future database connections.
114852 **
114853 ** 0x0008 (Not yet implemented) Create indexes that might have
114854 ** been helpful to recent queries
114855 **
114856 ** The default MASK is and always shall be 0xfffe. 0xfffe means perform all ** of the optimizations listed above except Debug Mode, including new
114857 ** optimizations that have not yet been invented. If new optimizations are
114858 ** ever added that should be off by default, those off-by-default
114859 ** optimizations will have bitmasks of 0x10000 or larger.
114860 **
114861 ** DETERMINATION OF WHEN TO RUN ANALYZE
114862 **
114863 ** In the current implementation, a table is analyzed if only if all of
114864 ** the following are true:
114865 **
114866 ** (1) MASK bit 0x02 is set.
114867 **
114868 ** (2) The query planner used sqlite_stat1-style statistics for one or
114869 ** more indexes of the table at some point during the lifetime of
114870 ** the current connection.
114871 **
114872 ** (3) One or more indexes of the table are currently unanalyzed OR
114873 ** the number of rows in the table has increased by 25 times or more
114874 ** since the last time ANALYZE was run.
114875 **
114876 ** The rules for when tables are analyzed are likely to change in
114877 ** future releases.
114878 */
114879 case PragTyp_OPTIMIZE: {
114880 int iDbLast; /* Loop termination point for the schema loop */
114881 int iTabCur; /* Cursor for a table whose size needs checking */
114882 HashElem *k; /* Loop over tables of a schema */
114883 Schema *pSchema; /* The current schema */
114884 Table *pTab; /* A table in the schema */
114885 Index *pIdx; /* An index of the table */
114886 LogEst szThreshold; /* Size threshold above which reanalysis is needd */
114887 char *zSubSql; /* SQL statement for the OP_SqlExec opcode */
114888 u32 opMask; /* Mask of operations to perform */
114889
114890 if( zRight ){
114891 opMask = (u32)sqlite3Atoi(zRight);
114892 if( (opMask & 0x02)==0 ) break;
114893 }else{
114894 opMask = 0xfffe;
114895 }
114896 iTabCur = pParse->nTab++;
114897 for(iDbLast = zDb?iDb:db->nDb-1; iDb<=iDbLast; iDb++){
114898 if( iDb==1 ) continue;
114899 sqlite3CodeVerifySchema(pParse, iDb);
114900 pSchema = db->aDb[iDb].pSchema;
114901 for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
114902 pTab = (Table*)sqliteHashData(k);
114903
114904 /* If table pTab has not been used in a way that would benefit from
114905 ** having analysis statistics during the current session, then skip it.
114906 ** This also has the effect of skipping virtual tables and views */
114907 if( (pTab->tabFlags & TF_StatsUsed)==0 ) continue;
114908
114909 /* Reanalyze if the table is 25 times larger than the last analysis */
114910 szThreshold = pTab->nRowLogEst + 46; assert( sqlite3LogEst(25)==46 );
114911 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
114912 if( !pIdx->hasStat1 ){
114913 szThreshold = 0; /* Always analyze if any index lacks statistics */
114914 break;
114915 }
114916 }
114917 if( szThreshold ){
114918 sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
114919 sqlite3VdbeAddOp3(v, OP_IfSmaller, iTabCur,
114920 sqlite3VdbeCurrentAddr(v)+2+(opMask&1), szThreshold);
114921 VdbeCoverage(v);
114922 }
114923 zSubSql = sqlite3MPrintf(db, "ANALYZE \"%w\".\"%w\"",
114924 db->aDb[iDb].zDbSName, pTab->zName);
114925 if( opMask & 0x01 ){
114926 int r1 = sqlite3GetTempReg(pParse);
114927 sqlite3VdbeAddOp4(v, OP_String8, 0, r1, 0, zSubSql, P4_DYNAMIC);
114928 sqlite3VdbeAddOp2(v, OP_ResultRow, r1, 1);
114929 }else{
114930 sqlite3VdbeAddOp4(v, OP_SqlExec, 0, 0, 0, zSubSql, P4_DYNAMIC);
114931 }
114932 }
114933 }
114934 sqlite3VdbeAddOp0(v, OP_Expire);
114935 break;
114936 }
114937
114938 /*
114939 ** PRAGMA busy_timeout
114940 ** PRAGMA busy_timeout = N
114941 **
@@ -119528,11 +119994,13 @@
119994 assert( pParent->pGroupBy==0 );
119995 pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
119996 }else{
119997 pParent->pWhere = sqlite3ExprAnd(db, pWhere, pParent->pWhere);
119998 }
119999 if( db->mallocFailed==0 ){
120000 substSelect(pParse, pParent, iParent, pSub->pEList, 0);
120001 }
120002
120003 /* The flattened query is distinct if either the inner or the
120004 ** outer query is distinct.
120005 */
120006 pParent->selFlags |= pSub->selFlags & SF_Distinct;
@@ -123782,12 +124250,29 @@
124250 ** transient would cause the database file to appear to be deleted
124251 ** following reboot.
124252 */
124253 SQLITE_PRIVATE void sqlite3Vacuum(Parse *pParse, Token *pNm){
124254 Vdbe *v = sqlite3GetVdbe(pParse);
124255 int iDb = 0;
124256 if( v==0 ) return;
124257 if( pNm ){
124258 #ifndef SQLITE_BUG_COMPATIBLE_20160819
124259 /* Default behavior: Report an error if the argument to VACUUM is
124260 ** not recognized */
124261 iDb = sqlite3TwoPartName(pParse, pNm, pNm, &pNm);
124262 if( iDb<0 ) return;
124263 #else
124264 /* When SQLITE_BUG_COMPATIBLE_20160819 is defined, unrecognized arguments
124265 ** to VACUUM are silently ignored. This is a back-out of a bug fix that
124266 ** occurred on 2016-08-19 (https://www.sqlite.org/src/info/083f9e6270).
124267 ** The buggy behavior is required for binary compatibility with some
124268 ** legacy applications. */
124269 iDb = sqlite3FindDb(pParse->db, pNm);
124270 if( iDb<0 ) iDb = 0;
124271 #endif
124272 }
124273 if( iDb!=1 ){
124274 sqlite3VdbeAddOp1(v, OP_Vacuum, iDb);
124275 sqlite3VdbeUsesBtree(v, iDb);
124276 }
124277 return;
124278 }
@@ -124377,12 +124862,11 @@
124862
124863 db = pParse->db;
124864 iDb = sqlite3SchemaToIndex(db, pTable->pSchema);
124865 assert( iDb>=0 );
124866
124867 assert( pTable->nModuleArg==0 );
 
124868 addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName));
124869 addModuleArgument(db, pTable, 0);
124870 addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName));
124871 assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0)
124872 || (pParse->sNameToken.z==pName1->z && pName2->z==0)
@@ -124666,11 +125150,11 @@
125150 const char *zMod;
125151 Module *pMod;
125152 int rc;
125153
125154 assert( pTab );
125155 if( !IsVirtual(pTab) || sqlite3GetVTable(db, pTab) ){
125156 return SQLITE_OK;
125157 }
125158
125159 /* Locate the required virtual table module */
125160 zMod = pTab->azModuleArg[0];
@@ -124736,11 +125220,11 @@
125220 Table *pTab;
125221 Module *pMod;
125222 const char *zMod;
125223
125224 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
125225 assert( pTab && IsVirtual(pTab) && !pTab->pVTable );
125226
125227 /* Locate the required virtual table module */
125228 zMod = pTab->azModuleArg[0];
125229 pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
125230
@@ -124790,11 +125274,11 @@
125274 sqlite3Error(db, SQLITE_MISUSE);
125275 sqlite3_mutex_leave(db->mutex);
125276 return SQLITE_MISUSE_BKPT;
125277 }
125278 pTab = pCtx->pTab;
125279 assert( IsVirtual(pTab) );
125280
125281 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
125282 if( pParse==0 ){
125283 rc = SQLITE_NOMEM_BKPT;
125284 }else{
@@ -124804,11 +125288,11 @@
125288
125289 if( SQLITE_OK==sqlite3RunParser(pParse, zCreateTable, &zErr)
125290 && pParse->pNewTable
125291 && !db->mallocFailed
125292 && !pParse->pNewTable->pSelect
125293 && !IsVirtual(pParse->pNewTable)
125294 ){
125295 if( !pTab->aCol ){
125296 Table *pNew = pParse->pNewTable;
125297 Index *pIdx;
125298 pTab->aCol = pNew->aCol;
@@ -125093,11 +125577,11 @@
125577 /* Check to see the left operand is a column in a virtual table */
125578 if( NEVER(pExpr==0) ) return pDef;
125579 if( pExpr->op!=TK_COLUMN ) return pDef;
125580 pTab = pExpr->pTab;
125581 if( NEVER(pTab==0) ) return pDef;
125582 if( !IsVirtual(pTab) ) return pDef;
125583 pVtab = sqlite3GetVTable(db, pTab)->pVtab;
125584 assert( pVtab!=0 );
125585 assert( pVtab->pModule!=0 );
125586 pMod = (sqlite3_module *)pVtab->pModule;
125587 if( pMod->xFindFunction==0 ) return pDef;
@@ -125188,12 +125672,11 @@
125672 return 0;
125673 }
125674 pMod->pEpoTab = pTab;
125675 pTab->nTabRef = 1;
125676 pTab->pSchema = db->aDb[0].pSchema;
125677 assert( pTab->nModuleArg==0 );
 
125678 pTab->iPKey = -1;
125679 addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
125680 addModuleArgument(db, pTab, 0);
125681 addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
125682 rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
@@ -125260,11 +125743,11 @@
125743 case SQLITE_VTAB_CONSTRAINT_SUPPORT: {
125744 VtabCtx *p = db->pVtabCtx;
125745 if( !p ){
125746 rc = SQLITE_MISUSE_BKPT;
125747 }else{
125748 assert( p->pTab==0 || IsVirtual(p->pTab) );
125749 p->pVTable->bConstraint = (u8)va_arg(ap, int);
125750 }
125751 break;
125752 }
125753 default:
@@ -125699,12 +126182,17 @@
126182 WhereOrSet *pOrSet; /* Record best loops here, if not NULL */
126183 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
126184 UnpackedRecord *pRec; /* Probe for stat4 (if required) */
126185 int nRecValid; /* Number of valid fields currently in pRec */
126186 #endif
126187 unsigned int bldFlags; /* SQLITE_BLDF_* flags */
126188 };
126189
126190 /* Allowed values for WhereLoopBuider.bldFlags */
126191 #define SQLITE_BLDF_INDEXED 0x0001 /* An index is used */
126192 #define SQLITE_BLDF_UNIQUE 0x0002 /* All keys of a UNIQUE index used */
126193
126194 /*
126195 ** The WHERE clause processing routine has two halves. The
126196 ** first part does the start of the WHERE loop and the second
126197 ** half does the tail of the WHERE loop. An instance of
126198 ** this structure is returned by the first half and passed
@@ -125715,11 +126203,11 @@
126203 */
126204 struct WhereInfo {
126205 Parse *pParse; /* Parsing and code generating context */
126206 SrcList *pTabList; /* List of tables in the join */
126207 ExprList *pOrderBy; /* The ORDER BY clause or NULL */
126208 ExprList *pResultSet; /* Result set of the query */
126209 LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
126210 int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */
126211 int iContinue; /* Jump here to continue with next record */
126212 int iBreak; /* Jump here to break out of the loop */
126213 int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
@@ -126899,10 +127387,11 @@
127387 Parse *pParse; /* Parsing context */
127388 sqlite3 *db; /* Database connection */
127389 Vdbe *v; /* The prepared stmt under constructions */
127390 struct SrcList_item *pTabItem; /* FROM clause term being coded */
127391 int addrBrk; /* Jump here to break out of the loop */
127392 int addrHalt; /* addrBrk for the outermost loop */
127393 int addrCont; /* Jump here to continue with next cycle */
127394 int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
127395 int iReleaseReg = 0; /* Temp register to free before returning */
127396
127397 pParse = pWInfo->pParse;
@@ -126939,10 +127428,15 @@
127428 if( pLevel->iFrom>0 && (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){
127429 pLevel->iLeftJoin = ++pParse->nMem;
127430 sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
127431 VdbeComment((v, "init LEFT JOIN no-match flag"));
127432 }
127433
127434 /* Compute a safe address to jump to if we discover that the table for
127435 ** this loop is empty and can never contribute content. */
127436 for(j=iLevel; j>0 && pWInfo->a[j].iLeftJoin==0; j--){}
127437 addrHalt = pWInfo->a[j].addrBrk;
127438
127439 /* Special case of a FROM clause subquery implemented as a co-routine */
127440 if( pTabItem->fg.viaCoroutine ){
127441 int regYield = pTabItem->regReturn;
127442 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
@@ -127124,11 +127618,11 @@
127618 VdbeCoverageIf(v, pX->op==TK_LT);
127619 VdbeCoverageIf(v, pX->op==TK_GE);
127620 sqlite3ExprCacheAffinityChange(pParse, r1, 1);
127621 sqlite3ReleaseTempReg(pParse, rTemp);
127622 }else{
127623 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrHalt);
127624 VdbeCoverageIf(v, bRev==0);
127625 VdbeCoverageIf(v, bRev!=0);
127626 }
127627 if( pEnd ){
127628 Expr *pX;
@@ -127770,11 +128264,11 @@
128264 pLevel->op = OP_Noop;
128265 }else{
128266 codeCursorHint(pTabItem, pWInfo, pLevel, 0);
128267 pLevel->op = aStep[bRev];
128268 pLevel->p1 = iCur;
128269 pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrHalt);
128270 VdbeCoverageIf(v, bRev==0);
128271 VdbeCoverageIf(v, bRev!=0);
128272 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
128273 }
128274 }
@@ -128095,19 +128589,10 @@
128589 #ifdef SQLITE_EBCDIC
128590 if( *pnoCase ) return 0;
128591 #endif
128592 pList = pExpr->x.pList;
128593 pLeft = pList->a[1].pExpr;
 
 
 
 
 
 
 
 
 
128594
128595 pRight = sqlite3ExprSkipCollate(pList->a[0].pExpr);
128596 op = pRight->op;
128597 if( op==TK_VARIABLE ){
128598 Vdbe *pReprepare = pParse->pReprepare;
@@ -128120,10 +128605,27 @@
128605 assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER );
128606 }else if( op==TK_STRING ){
128607 z = pRight->u.zToken;
128608 }
128609 if( z ){
128610
128611 /* If the RHS begins with a digit or a minus sign, then the LHS must
128612 ** be an ordinary column (not a virtual table column) with TEXT affinity.
128613 ** Otherwise the LHS might be numeric and "lhs >= rhs" would be false
128614 ** even though "lhs LIKE rhs" is true. But if the RHS does not start
128615 ** with a digit or '-', then "lhs LIKE rhs" will always be false if
128616 ** the LHS is numeric and so the optimization still works.
128617 */
128618 if( sqlite3Isdigit(z[0]) || z[0]=='-' ){
128619 if( pLeft->op!=TK_COLUMN
128620 || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT
128621 || IsVirtual(pLeft->pTab) /* Value might be numeric */
128622 ){
128623 sqlite3ValueFree(pVal);
128624 return 0;
128625 }
128626 }
128627 cnt = 0;
128628 while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){
128629 cnt++;
128630 }
128631 if( cnt!=0 && 255!=(u8)z[cnt-1] ){
@@ -128748,11 +129250,11 @@
129250 iCur = pFrom->a[i].iCursor;
129251 for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){
129252 if( pIdx->aColExpr==0 ) continue;
129253 for(i=0; i<pIdx->nKeyCol; i++){
129254 if( pIdx->aiColumn[i]!=XN_EXPR ) continue;
129255 if( sqlite3ExprCompareSkip(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
129256 *piCur = iCur;
129257 *piColumn = XN_EXPR;
129258 return 1;
129259 }
129260 }
@@ -129539,11 +130041,12 @@
130041 do{
130042 for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
130043 if( pTerm->leftCursor==iCur
130044 && pTerm->u.leftColumn==iColumn
130045 && (iColumn!=XN_EXPR
130046 || sqlite3ExprCompareSkip(pTerm->pExpr->pLeft,
130047 pScan->pIdxExpr,iCur)==0)
130048 && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
130049 ){
130050 if( (pTerm->eOperator & WO_EQUIV)!=0
130051 && pScan->nEquiv<ArraySize(pScan->aiCur)
130052 && (pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight))->op==TK_COLUMN
@@ -129846,18 +130349,20 @@
130349 ** cursor iTabCur are transformed into OP_Null. Or, if bIncrRowid is non-zero,
130350 ** then each OP_Rowid is transformed into an instruction to increment the
130351 ** value stored in its output register.
130352 */
130353 static void translateColumnToCopy(
130354 Parse *pParse, /* Parsing context */
130355 int iStart, /* Translate from this opcode to the end */
130356 int iTabCur, /* OP_Column/OP_Rowid references to this table */
130357 int iRegister, /* The first column is in this register */
130358 int bIncrRowid /* If non-zero, transform OP_rowid to OP_AddImm(1) */
130359 ){
130360 Vdbe *v = pParse->pVdbe;
130361 VdbeOp *pOp = sqlite3VdbeGetOp(v, iStart);
130362 int iEnd = sqlite3VdbeCurrentAddr(v);
130363 if( pParse->db->mallocFailed ) return;
130364 for(; iStart<iEnd; iStart++, pOp++){
130365 if( pOp->p1!=iTabCur ) continue;
130366 if( pOp->opcode==OP_Column ){
130367 pOp->opcode = OP_Copy;
130368 pOp->p1 = pOp->p2 + iRegister;
@@ -130131,11 +130636,13 @@
130636 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
130637 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
130638 if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
130639 if( pTabItem->fg.viaCoroutine ){
130640 sqlite3VdbeChangeP2(v, addrCounter, regBase+n);
130641 testcase( pParse->db->mallocFailed );
130642 translateColumnToCopy(pParse, addrTop, pLevel->iTabCur,
130643 pTabItem->regResult, 1);
130644 sqlite3VdbeGoto(v, addrTop);
130645 pTabItem->fg.viaCoroutine = 0;
130646 }else{
130647 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
130648 }
@@ -131716,10 +132223,15 @@
132223 testcase( eOp & WO_IS );
132224 testcase( eOp & WO_ISNULL );
132225 continue;
132226 }
132227
132228 if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){
132229 pBuilder->bldFlags |= SQLITE_BLDF_UNIQUE;
132230 }else{
132231 pBuilder->bldFlags |= SQLITE_BLDF_INDEXED;
132232 }
132233 pNew->wsFlags = saved_wsFlags;
132234 pNew->u.btree.nEq = saved_nEq;
132235 pNew->u.btree.nBtm = saved_nBtm;
132236 pNew->u.btree.nTop = saved_nTop;
132237 pNew->nLTerm = saved_nLTerm;
@@ -132263,11 +132775,19 @@
132775 pNew->nOut = rSize;
132776 if( rc ) break;
132777 }
132778 }
132779
132780 pBuilder->bldFlags = 0;
132781 rc = whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, 0);
132782 if( pBuilder->bldFlags==SQLITE_BLDF_INDEXED ){
132783 /* If a non-unique index is used, or if a prefix of the key for
132784 ** unique index is used (making the index functionally non-unique)
132785 ** then the sqlite_stat1 data becomes important for scoring the
132786 ** plan */
132787 pTab->tabFlags |= TF_StatsUsed;
132788 }
132789 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
132790 sqlite3Stat4ProbeFree(pBuilder->pRec);
132791 pBuilder->nRecValid = 0;
132792 pBuilder->pRec = 0;
132793 #endif
@@ -133443,13 +133963,13 @@
133963 && (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
133964 && pWInfo->eDistinct==WHERE_DISTINCT_NOOP
133965 && nRowEst
133966 ){
133967 Bitmask notUsed;
133968 int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pResultSet, pFrom,
133969 WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed);
133970 if( rc==pWInfo->pResultSet->nExpr ){
133971 pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
133972 }
133973 }
133974 if( pWInfo->pOrderBy ){
133975 if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
@@ -133682,11 +134202,11 @@
134202 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
134203 Parse *pParse, /* The parser context */
134204 SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
134205 Expr *pWhere, /* The WHERE clause */
134206 ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */
134207 ExprList *pResultSet, /* Query result set. Req'd for DISTINCT */
134208 u16 wctrlFlags, /* The WHERE_* flags defined in sqliteInt.h */
134209 int iAuxArg /* If WHERE_OR_SUBCLAUSE is set, index cursor number
134210 ** If WHERE_USE_LIMIT, then the limit amount */
134211 ){
134212 int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
@@ -133758,11 +134278,11 @@
134278 goto whereBeginError;
134279 }
134280 pWInfo->pParse = pParse;
134281 pWInfo->pTabList = pTabList;
134282 pWInfo->pOrderBy = pOrderBy;
134283 pWInfo->pResultSet = pResultSet;
134284 pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
134285 pWInfo->nLevel = nTabList;
134286 pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
134287 pWInfo->wctrlFlags = wctrlFlags;
134288 pWInfo->iLimit = iAuxArg;
@@ -133836,17 +134356,17 @@
134356 /* Analyze all of the subexpressions. */
134357 sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
134358 if( db->mallocFailed ) goto whereBeginError;
134359
134360 if( wctrlFlags & WHERE_WANT_DISTINCT ){
134361 if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){
134362 /* The DISTINCT marking is pointless. Ignore it. */
134363 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
134364 }else if( pOrderBy==0 ){
134365 /* Try to ORDER BY the result set to make distinct processing easier */
134366 pWInfo->wctrlFlags |= WHERE_DISTINCTBY;
134367 pWInfo->pOrderBy = pResultSet;
134368 }
134369 }
134370
134371 /* Construct the WhereLoop objects */
134372 #if defined(WHERETRACE_ENABLED)
@@ -133918,14 +134438,14 @@
134438 }
134439 }
134440 #endif
134441 /* Attempt to omit tables from the join that do not effect the result */
134442 if( pWInfo->nLevel>=2
134443 && pResultSet!=0
134444 && OptimizationEnabled(db, SQLITE_OmitNoopJoin)
134445 ){
134446 Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet);
134447 if( sWLB.pOrderBy ){
134448 tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy);
134449 }
134450 while( pWInfo->nLevel>=2 ){
134451 WhereTerm *pTerm, *pEnd;
@@ -134236,12 +134756,13 @@
134756
134757 /* For a co-routine, change all OP_Column references to the table of
134758 ** the co-routine into OP_Copy of result contained in a register.
134759 ** OP_Rowid becomes OP_Null.
134760 */
134761 if( pTabItem->fg.viaCoroutine ){
134762 testcase( pParse->db->mallocFailed );
134763 translateColumnToCopy(pParse, pLevel->addrBody, pLevel->iTabCur,
134764 pTabItem->regResult, 0);
134765 continue;
134766 }
134767
134768 /* If this scan uses an index, make VDBE code substitutions to read data
@@ -134704,166 +135225,166 @@
135225 **
135226 *********** Begin parsing tables **********************************************/
135227 #define YY_ACTTAB_COUNT (1567)
135228 static const YYACTIONTYPE yy_action[] = {
135229 /* 0 */ 325, 832, 351, 825, 5, 203, 203, 819, 99, 100,
135230 /* 10 */ 90, 978, 978, 853, 856, 845, 845, 97, 97, 98,
135231 /* 20 */ 98, 98, 98, 301, 96, 96, 96, 96, 95, 95,
135232 /* 30 */ 94, 94, 94, 93, 351, 325, 976, 976, 824, 824,
135233 /* 40 */ 826, 946, 354, 99, 100, 90, 978, 978, 853, 856,
135234 /* 50 */ 845, 845, 97, 97, 98, 98, 98, 98, 338, 96,
135235 /* 60 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351,
135236 /* 70 */ 95, 95, 94, 94, 94, 93, 351, 791, 976, 976,
135237 /* 80 */ 325, 94, 94, 94, 93, 351, 792, 75, 99, 100,
135238 /* 90 */ 90, 978, 978, 853, 856, 845, 845, 97, 97, 98,
135239 /* 100 */ 98, 98, 98, 450, 96, 96, 96, 96, 95, 95,
135240 /* 110 */ 94, 94, 94, 93, 351, 1333, 155, 155, 2, 325,
135241 /* 120 */ 275, 146, 132, 52, 52, 93, 351, 99, 100, 90,
135242 /* 130 */ 978, 978, 853, 856, 845, 845, 97, 97, 98, 98,
135243 /* 140 */ 98, 98, 101, 96, 96, 96, 96, 95, 95, 94,
135244 /* 150 */ 94, 94, 93, 351, 957, 957, 325, 268, 428, 413,
135245 /* 160 */ 411, 61, 752, 752, 99, 100, 90, 978, 978, 853,
135246 /* 170 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 60,
135247 /* 180 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
135248 /* 190 */ 351, 325, 270, 329, 273, 277, 958, 959, 250, 99,
135249 /* 200 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97,
135250 /* 210 */ 98, 98, 98, 98, 301, 96, 96, 96, 96, 95,
135251 /* 220 */ 95, 94, 94, 94, 93, 351, 325, 937, 1326, 698,
135252 /* 230 */ 706, 1326, 242, 412, 99, 100, 90, 978, 978, 853,
135253 /* 240 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 347,
135254 /* 250 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
135255 /* 260 */ 351, 325, 937, 1327, 384, 699, 1327, 381, 379, 99,
135256 /* 270 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97,
135257 /* 280 */ 98, 98, 98, 98, 701, 96, 96, 96, 96, 95,
135258 /* 290 */ 95, 94, 94, 94, 93, 351, 325, 92, 89, 178,
135259 /* 300 */ 833, 935, 373, 700, 99, 100, 90, 978, 978, 853,
135260 /* 310 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 375,
135261 /* 320 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
135262 /* 330 */ 351, 325, 1275, 946, 354, 818, 935, 739, 739, 99,
135263 /* 340 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97,
135264 /* 350 */ 98, 98, 98, 98, 230, 96, 96, 96, 96, 95,
135265 /* 360 */ 95, 94, 94, 94, 93, 351, 325, 968, 227, 92,
135266 /* 370 */ 89, 178, 373, 300, 99, 100, 90, 978, 978, 853,
135267 /* 380 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 920,
135268 /* 390 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
135269 /* 400 */ 351, 325, 449, 447, 447, 447, 147, 737, 737, 99,
135270 /* 410 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97,
135271 /* 420 */ 98, 98, 98, 98, 296, 96, 96, 96, 96, 95,
135272 /* 430 */ 95, 94, 94, 94, 93, 351, 325, 419, 231, 957,
135273 /* 440 */ 957, 158, 25, 422, 99, 100, 90, 978, 978, 853,
135274 /* 450 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 450,
135275 /* 460 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
135276 /* 470 */ 351, 443, 224, 224, 420, 957, 957, 961, 325, 52,
135277 /* 480 */ 52, 958, 959, 176, 415, 78, 99, 100, 90, 978,
135278 /* 490 */ 978, 853, 856, 845, 845, 97, 97, 98, 98, 98,
135279 /* 500 */ 98, 379, 96, 96, 96, 96, 95, 95, 94, 94,
135280 /* 510 */ 94, 93, 351, 325, 428, 418, 298, 958, 959, 961,
135281 /* 520 */ 81, 99, 88, 90, 978, 978, 853, 856, 845, 845,
135282 /* 530 */ 97, 97, 98, 98, 98, 98, 717, 96, 96, 96,
135283 /* 540 */ 96, 95, 95, 94, 94, 94, 93, 351, 325, 842,
135284 /* 550 */ 842, 854, 857, 996, 318, 343, 379, 100, 90, 978,
135285 /* 560 */ 978, 853, 856, 845, 845, 97, 97, 98, 98, 98,
135286 /* 570 */ 98, 450, 96, 96, 96, 96, 95, 95, 94, 94,
135287 /* 580 */ 94, 93, 351, 325, 350, 350, 350, 260, 377, 340,
135288 /* 590 */ 928, 52, 52, 90, 978, 978, 853, 856, 845, 845,
135289 /* 600 */ 97, 97, 98, 98, 98, 98, 361, 96, 96, 96,
135290 /* 610 */ 96, 95, 95, 94, 94, 94, 93, 351, 86, 445,
135291 /* 620 */ 846, 3, 1202, 361, 360, 378, 344, 813, 957, 957,
135292 /* 630 */ 1299, 86, 445, 729, 3, 212, 169, 287, 405, 282,
135293 /* 640 */ 404, 199, 232, 450, 300, 760, 83, 84, 280, 245,
135294 /* 650 */ 262, 365, 251, 85, 352, 352, 92, 89, 178, 83,
135295 /* 660 */ 84, 242, 412, 52, 52, 448, 85, 352, 352, 246,
135296 /* 670 */ 958, 959, 194, 455, 670, 402, 399, 398, 448, 243,
135297 /* 680 */ 221, 114, 434, 776, 361, 450, 397, 268, 747, 224,
135298 /* 690 */ 224, 132, 132, 198, 832, 434, 452, 451, 428, 427,
135299 /* 700 */ 819, 415, 734, 713, 132, 52, 52, 832, 268, 452,
135300 /* 710 */ 451, 734, 194, 819, 363, 402, 399, 398, 450, 1270,
135301 /* 720 */ 1270, 23, 957, 957, 86, 445, 397, 3, 228, 429,
135302 /* 730 */ 894, 824, 824, 826, 827, 19, 203, 720, 52, 52,
135303 /* 740 */ 428, 408, 439, 249, 824, 824, 826, 827, 19, 229,
135304 /* 750 */ 403, 153, 83, 84, 761, 177, 241, 450, 721, 85,
135305 /* 760 */ 352, 352, 120, 157, 958, 959, 58, 976, 409, 355,
135306 /* 770 */ 330, 448, 268, 428, 430, 320, 790, 32, 32, 86,
135307 /* 780 */ 445, 776, 3, 341, 98, 98, 98, 98, 434, 96,
135308 /* 790 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351,
135309 /* 800 */ 832, 120, 452, 451, 813, 886, 819, 83, 84, 976,
135310 /* 810 */ 813, 132, 410, 919, 85, 352, 352, 132, 407, 789,
135311 /* 820 */ 957, 957, 92, 89, 178, 916, 448, 262, 370, 261,
135312 /* 830 */ 82, 913, 80, 262, 370, 261, 776, 824, 824, 826,
135313 /* 840 */ 827, 19, 933, 434, 96, 96, 96, 96, 95, 95,
135314 /* 850 */ 94, 94, 94, 93, 351, 832, 74, 452, 451, 957,
135315 /* 860 */ 957, 819, 958, 959, 120, 92, 89, 178, 944, 2,
135316 /* 870 */ 917, 964, 268, 1, 975, 76, 445, 762, 3, 708,
135317 /* 880 */ 900, 900, 387, 957, 957, 757, 918, 371, 740, 778,
135318 /* 890 */ 756, 257, 824, 824, 826, 827, 19, 417, 741, 450,
135319 /* 900 */ 24, 958, 959, 83, 84, 369, 957, 957, 177, 226,
135320 /* 910 */ 85, 352, 352, 884, 315, 314, 313, 215, 311, 10,
135321 /* 920 */ 10, 683, 448, 349, 348, 958, 959, 908, 777, 157,
135322 /* 930 */ 120, 957, 957, 337, 776, 416, 711, 310, 450, 434,
135323 /* 940 */ 450, 321, 450, 791, 103, 200, 175, 450, 958, 959,
135324 /* 950 */ 907, 832, 792, 452, 451, 9, 9, 819, 10, 10,
135325 /* 960 */ 52, 52, 51, 51, 180, 716, 248, 10, 10, 171,
135326 /* 970 */ 170, 167, 339, 958, 959, 247, 984, 702, 702, 450,
135327 /* 980 */ 715, 233, 686, 982, 888, 983, 182, 913, 824, 824,
135328 /* 990 */ 826, 827, 19, 183, 256, 423, 132, 181, 394, 10,
135329 /* 1000 */ 10, 888, 890, 749, 957, 957, 916, 268, 985, 198,
135330 /* 1010 */ 985, 349, 348, 425, 415, 299, 817, 832, 326, 825,
135331 /* 1020 */ 120, 332, 133, 819, 268, 98, 98, 98, 98, 91,
135332 /* 1030 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
135333 /* 1040 */ 351, 157, 810, 371, 382, 359, 958, 959, 358, 268,
135334 /* 1050 */ 450, 917, 368, 324, 824, 824, 826, 450, 709, 450,
135335 /* 1060 */ 264, 380, 888, 450, 876, 746, 253, 918, 255, 433,
135336 /* 1070 */ 36, 36, 234, 450, 234, 120, 269, 37, 37, 12,
135337 /* 1080 */ 12, 334, 272, 27, 27, 450, 330, 118, 450, 162,
135338 /* 1090 */ 742, 280, 450, 38, 38, 450, 985, 356, 985, 450,
135339 /* 1100 */ 709, 1209, 450, 132, 450, 39, 39, 450, 40, 40,
135340 /* 1110 */ 450, 362, 41, 41, 450, 42, 42, 450, 254, 28,
135341 /* 1120 */ 28, 450, 29, 29, 31, 31, 450, 43, 43, 450,
135342 /* 1130 */ 44, 44, 450, 714, 45, 45, 450, 11, 11, 767,
135343 /* 1140 */ 450, 46, 46, 450, 268, 450, 105, 105, 450, 47,
135344 /* 1150 */ 47, 450, 48, 48, 450, 237, 33, 33, 450, 172,
135345 /* 1160 */ 49, 49, 450, 50, 50, 34, 34, 274, 122, 122,
135346 /* 1170 */ 450, 123, 123, 450, 124, 124, 450, 897, 56, 56,
135347 /* 1180 */ 450, 896, 35, 35, 450, 267, 450, 817, 450, 817,
135348 /* 1190 */ 106, 106, 450, 53, 53, 385, 107, 107, 450, 817,
135349 /* 1200 */ 108, 108, 817, 450, 104, 104, 121, 121, 119, 119,
135350 /* 1210 */ 450, 117, 112, 112, 450, 276, 450, 225, 111, 111,
135351 /* 1220 */ 450, 730, 450, 109, 109, 450, 673, 674, 675, 911,
135352 /* 1230 */ 110, 110, 317, 998, 55, 55, 57, 57, 692, 331,
135353 /* 1240 */ 54, 54, 26, 26, 696, 30, 30, 317, 936, 197,
135354 /* 1250 */ 196, 195, 335, 281, 336, 446, 331, 745, 689, 436,
135355 /* 1260 */ 440, 444, 120, 72, 386, 223, 175, 345, 757, 932,
135356 /* 1270 */ 20, 286, 319, 756, 815, 372, 374, 202, 202, 202,
135357 /* 1280 */ 263, 395, 285, 74, 208, 21, 696, 719, 718, 883,
135358 /* 1290 */ 120, 120, 120, 120, 120, 754, 278, 828, 77, 74,
135359 /* 1300 */ 726, 727, 785, 783, 879, 202, 999, 208, 893, 892,
135360 /* 1310 */ 893, 892, 694, 816, 763, 116, 774, 1289, 431, 432,
135361 /* 1320 */ 302, 999, 390, 303, 823, 697, 691, 680, 159, 289,
135362 /* 1330 */ 679, 883, 681, 951, 291, 218, 293, 7, 316, 828,
135363 /* 1340 */ 173, 805, 259, 364, 252, 910, 376, 713, 295, 435,
135364 /* 1350 */ 308, 168, 954, 993, 135, 400, 990, 284, 881, 880,
135365 /* 1360 */ 205, 927, 925, 59, 333, 62, 144, 156, 130, 72,
135366 /* 1370 */ 802, 366, 367, 393, 137, 185, 189, 160, 139, 383,
135367 /* 1380 */ 67, 895, 140, 141, 142, 148, 389, 812, 775, 266,
135368 /* 1390 */ 219, 190, 154, 391, 912, 875, 271, 406, 191, 322,
135369 /* 1400 */ 682, 733, 192, 342, 732, 724, 731, 711, 723, 421,
135370 /* 1410 */ 705, 71, 323, 6, 204, 771, 288, 79, 297, 346,
135371 /* 1420 */ 772, 704, 290, 283, 703, 770, 292, 294, 966, 239,
135372 /* 1430 */ 769, 102, 861, 438, 426, 240, 424, 442, 73, 213,
135373 /* 1440 */ 688, 238, 22, 453, 952, 214, 217, 216, 454, 677,
135374 /* 1450 */ 676, 671, 753, 125, 115, 235, 126, 669, 353, 166,
135375 /* 1460 */ 127, 244, 179, 357, 306, 304, 305, 307, 113, 891,
135376 /* 1470 */ 327, 889, 811, 328, 134, 128, 136, 138, 743, 258,
135377 /* 1480 */ 906, 184, 143, 129, 909, 186, 63, 64, 145, 187,
135378 /* 1490 */ 905, 65, 8, 66, 13, 188, 202, 898, 265, 149,
135379 /* 1500 */ 987, 388, 150, 685, 161, 392, 285, 193, 279, 396,
135380 /* 1510 */ 151, 401, 68, 14, 15, 722, 69, 236, 831, 131,
135381 /* 1520 */ 830, 859, 70, 751, 16, 414, 755, 4, 174, 220,
135382 /* 1530 */ 222, 784, 201, 152, 779, 77, 74, 17, 18, 874,
135383 /* 1540 */ 860, 858, 915, 863, 914, 207, 206, 941, 163, 437,
135384 /* 1550 */ 947, 942, 164, 209, 1002, 441, 862, 165, 210, 829,
135385 /* 1560 */ 695, 87, 312, 211, 1291, 1290, 309,
135386 };
135387 static const YYCODETYPE yy_lookahead[] = {
135388 /* 0 */ 19, 95, 53, 97, 22, 24, 24, 101, 27, 28,
135389 /* 10 */ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
135390 /* 20 */ 39, 40, 41, 152, 43, 44, 45, 46, 47, 48,
@@ -135112,55 +135633,55 @@
135633 /* 300 */ 1256, 1200, 1206, 1260, 1247, 1261, 1263, 1262, 1266, 1278,
135634 /* 310 */ 1282, 1292, 1294, 1297, 1298, 1299, 1300, 1221, 1224, 1228,
135635 /* 320 */ 1288, 1291, 1276, 1277, 1295,
135636 };
135637 static const YYACTIONTYPE yy_default[] = {
135638 /* 0 */ 1280, 1270, 1270, 1270, 1202, 1202, 1202, 1202, 1270, 1096,
135639 /* 10 */ 1125, 1125, 1254, 1332, 1332, 1332, 1332, 1332, 1332, 1201,
135640 /* 20 */ 1332, 1332, 1332, 1332, 1270, 1100, 1131, 1332, 1332, 1332,
135641 /* 30 */ 1332, 1203, 1204, 1332, 1332, 1332, 1253, 1255, 1141, 1140,
135642 /* 40 */ 1139, 1138, 1236, 1112, 1136, 1129, 1133, 1203, 1197, 1198,
135643 /* 50 */ 1196, 1200, 1204, 1332, 1132, 1167, 1181, 1166, 1332, 1332,
135644 /* 60 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135645 /* 70 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135646 /* 80 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135647 /* 90 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135648 /* 100 */ 1332, 1332, 1332, 1332, 1175, 1180, 1187, 1179, 1176, 1169,
135649 /* 110 */ 1168, 1170, 1171, 1332, 1019, 1067, 1332, 1332, 1332, 1172,
135650 /* 120 */ 1332, 1173, 1184, 1183, 1182, 1261, 1288, 1287, 1332, 1332,
135651 /* 130 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135652 /* 140 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135653 /* 150 */ 1332, 1332, 1332, 1332, 1332, 1280, 1270, 1025, 1025, 1332,
135654 /* 160 */ 1270, 1270, 1270, 1270, 1270, 1270, 1266, 1100, 1091, 1332,
135655 /* 170 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135656 /* 180 */ 1258, 1256, 1332, 1217, 1332, 1332, 1332, 1332, 1332, 1332,
135657 /* 190 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135658 /* 200 */ 1332, 1332, 1332, 1332, 1096, 1332, 1332, 1332, 1332, 1332,
135659 /* 210 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1282, 1332, 1231,
135660 /* 220 */ 1096, 1096, 1096, 1098, 1080, 1090, 1004, 1135, 1114, 1114,
135661 /* 230 */ 1321, 1135, 1321, 1042, 1302, 1039, 1125, 1114, 1199, 1125,
135662 /* 240 */ 1125, 1097, 1090, 1332, 1324, 1105, 1105, 1323, 1323, 1105,
135663 /* 250 */ 1146, 1070, 1135, 1076, 1076, 1076, 1076, 1105, 1016, 1135,
135664 /* 260 */ 1146, 1070, 1070, 1135, 1105, 1016, 1235, 1318, 1105, 1105,
135665 /* 270 */ 1016, 1210, 1105, 1016, 1105, 1016, 1210, 1068, 1068, 1068,
135666 /* 280 */ 1057, 1210, 1068, 1042, 1068, 1057, 1068, 1068, 1118, 1113,
135667 /* 290 */ 1118, 1113, 1118, 1113, 1118, 1113, 1105, 1205, 1105, 1332,
135668 /* 300 */ 1210, 1214, 1214, 1210, 1130, 1119, 1128, 1126, 1135, 1022,
135669 /* 310 */ 1060, 1285, 1285, 1281, 1281, 1281, 1281, 1329, 1329, 1266,
135670 /* 320 */ 1297, 1297, 1044, 1044, 1297, 1332, 1332, 1332, 1332, 1332,
135671 /* 330 */ 1332, 1292, 1332, 1219, 1332, 1332, 1332, 1332, 1332, 1332,
135672 /* 340 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135673 /* 350 */ 1332, 1332, 1152, 1332, 1000, 1263, 1332, 1332, 1262, 1332,
135674 /* 360 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135675 /* 370 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1320,
135676 /* 380 */ 1332, 1332, 1332, 1332, 1332, 1332, 1234, 1233, 1332, 1332,
135677 /* 390 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135678 /* 400 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332,
135679 /* 410 */ 1332, 1082, 1332, 1332, 1332, 1306, 1332, 1332, 1332, 1332,
135680 /* 420 */ 1332, 1332, 1332, 1127, 1332, 1120, 1332, 1332, 1311, 1332,
135681 /* 430 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1272,
135682 /* 440 */ 1332, 1332, 1332, 1271, 1332, 1332, 1332, 1332, 1332, 1154,
135683 /* 450 */ 1332, 1153, 1157, 1332, 1010, 1332,
135684 };
135685 /********** End of lemon-generated parsing tables *****************************/
135686
135687 /* The next table maps tokens (terminal symbols) into fallback tokens.
@@ -135602,147 +136123,147 @@
136123 /* 169 */ "expr ::= expr EQ|NE expr",
136124 /* 170 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
136125 /* 171 */ "expr ::= expr PLUS|MINUS expr",
136126 /* 172 */ "expr ::= expr STAR|SLASH|REM expr",
136127 /* 173 */ "expr ::= expr CONCAT expr",
136128 /* 174 */ "likeop ::= NOT LIKE_KW|MATCH",
136129 /* 175 */ "expr ::= expr likeop expr",
136130 /* 176 */ "expr ::= expr likeop expr ESCAPE expr",
136131 /* 177 */ "expr ::= expr ISNULL|NOTNULL",
136132 /* 178 */ "expr ::= expr NOT NULL",
136133 /* 179 */ "expr ::= expr IS expr",
136134 /* 180 */ "expr ::= expr IS NOT expr",
136135 /* 181 */ "expr ::= NOT expr",
136136 /* 182 */ "expr ::= BITNOT expr",
136137 /* 183 */ "expr ::= MINUS expr",
136138 /* 184 */ "expr ::= PLUS expr",
136139 /* 185 */ "between_op ::= BETWEEN",
136140 /* 186 */ "between_op ::= NOT BETWEEN",
136141 /* 187 */ "expr ::= expr between_op expr AND expr",
136142 /* 188 */ "in_op ::= IN",
136143 /* 189 */ "in_op ::= NOT IN",
136144 /* 190 */ "expr ::= expr in_op LP exprlist RP",
136145 /* 191 */ "expr ::= LP select RP",
136146 /* 192 */ "expr ::= expr in_op LP select RP",
136147 /* 193 */ "expr ::= expr in_op nm dbnm paren_exprlist",
136148 /* 194 */ "expr ::= EXISTS LP select RP",
136149 /* 195 */ "expr ::= CASE case_operand case_exprlist case_else END",
136150 /* 196 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
136151 /* 197 */ "case_exprlist ::= WHEN expr THEN expr",
136152 /* 198 */ "case_else ::= ELSE expr",
136153 /* 199 */ "case_else ::=",
136154 /* 200 */ "case_operand ::= expr",
136155 /* 201 */ "case_operand ::=",
136156 /* 202 */ "exprlist ::=",
136157 /* 203 */ "nexprlist ::= nexprlist COMMA expr",
136158 /* 204 */ "nexprlist ::= expr",
136159 /* 205 */ "paren_exprlist ::=",
136160 /* 206 */ "paren_exprlist ::= LP exprlist RP",
136161 /* 207 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
136162 /* 208 */ "uniqueflag ::= UNIQUE",
136163 /* 209 */ "uniqueflag ::=",
136164 /* 210 */ "eidlist_opt ::=",
136165 /* 211 */ "eidlist_opt ::= LP eidlist RP",
136166 /* 212 */ "eidlist ::= eidlist COMMA nm collate sortorder",
136167 /* 213 */ "eidlist ::= nm collate sortorder",
136168 /* 214 */ "collate ::=",
136169 /* 215 */ "collate ::= COLLATE ID|STRING",
136170 /* 216 */ "cmd ::= DROP INDEX ifexists fullname",
136171 /* 217 */ "cmd ::= VACUUM",
136172 /* 218 */ "cmd ::= VACUUM nm",
136173 /* 219 */ "cmd ::= PRAGMA nm dbnm",
136174 /* 220 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
136175 /* 221 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
136176 /* 222 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
136177 /* 223 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
136178 /* 224 */ "plus_num ::= PLUS INTEGER|FLOAT",
136179 /* 225 */ "minus_num ::= MINUS INTEGER|FLOAT",
136180 /* 226 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
136181 /* 227 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
136182 /* 228 */ "trigger_time ::= BEFORE",
136183 /* 229 */ "trigger_time ::= AFTER",
136184 /* 230 */ "trigger_time ::= INSTEAD OF",
136185 /* 231 */ "trigger_time ::=",
136186 /* 232 */ "trigger_event ::= DELETE|INSERT",
136187 /* 233 */ "trigger_event ::= UPDATE",
136188 /* 234 */ "trigger_event ::= UPDATE OF idlist",
136189 /* 235 */ "when_clause ::=",
136190 /* 236 */ "when_clause ::= WHEN expr",
136191 /* 237 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
136192 /* 238 */ "trigger_cmd_list ::= trigger_cmd SEMI",
136193 /* 239 */ "trnm ::= nm DOT nm",
136194 /* 240 */ "tridxby ::= INDEXED BY nm",
136195 /* 241 */ "tridxby ::= NOT INDEXED",
136196 /* 242 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt",
136197 /* 243 */ "trigger_cmd ::= insert_cmd INTO trnm idlist_opt select",
136198 /* 244 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt",
136199 /* 245 */ "trigger_cmd ::= select",
136200 /* 246 */ "expr ::= RAISE LP IGNORE RP",
136201 /* 247 */ "expr ::= RAISE LP raisetype COMMA nm RP",
136202 /* 248 */ "raisetype ::= ROLLBACK",
136203 /* 249 */ "raisetype ::= ABORT",
136204 /* 250 */ "raisetype ::= FAIL",
136205 /* 251 */ "cmd ::= DROP TRIGGER ifexists fullname",
136206 /* 252 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
136207 /* 253 */ "cmd ::= DETACH database_kw_opt expr",
136208 /* 254 */ "key_opt ::=",
136209 /* 255 */ "key_opt ::= KEY expr",
136210 /* 256 */ "cmd ::= REINDEX",
136211 /* 257 */ "cmd ::= REINDEX nm dbnm",
136212 /* 258 */ "cmd ::= ANALYZE",
136213 /* 259 */ "cmd ::= ANALYZE nm dbnm",
136214 /* 260 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
136215 /* 261 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist",
136216 /* 262 */ "add_column_fullname ::= fullname",
136217 /* 263 */ "cmd ::= create_vtab",
136218 /* 264 */ "cmd ::= create_vtab LP vtabarglist RP",
136219 /* 265 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
136220 /* 266 */ "vtabarg ::=",
136221 /* 267 */ "vtabargtoken ::= ANY",
136222 /* 268 */ "vtabargtoken ::= lp anylist RP",
136223 /* 269 */ "lp ::= LP",
136224 /* 270 */ "with ::=",
136225 /* 271 */ "with ::= WITH wqlist",
136226 /* 272 */ "with ::= WITH RECURSIVE wqlist",
136227 /* 273 */ "wqlist ::= nm eidlist_opt AS LP select RP",
136228 /* 274 */ "wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP",
136229 /* 275 */ "input ::= cmdlist",
136230 /* 276 */ "cmdlist ::= cmdlist ecmd",
136231 /* 277 */ "cmdlist ::= ecmd",
136232 /* 278 */ "ecmd ::= SEMI",
136233 /* 279 */ "ecmd ::= explain cmdx SEMI",
136234 /* 280 */ "explain ::=",
136235 /* 281 */ "trans_opt ::=",
136236 /* 282 */ "trans_opt ::= TRANSACTION",
136237 /* 283 */ "trans_opt ::= TRANSACTION nm",
136238 /* 284 */ "savepoint_opt ::= SAVEPOINT",
136239 /* 285 */ "savepoint_opt ::=",
136240 /* 286 */ "cmd ::= create_table create_table_args",
136241 /* 287 */ "columnlist ::= columnlist COMMA columnname carglist",
136242 /* 288 */ "columnlist ::= columnname carglist",
136243 /* 289 */ "nm ::= ID|INDEXED",
136244 /* 290 */ "nm ::= STRING",
136245 /* 291 */ "nm ::= JOIN_KW",
136246 /* 292 */ "typetoken ::= typename",
136247 /* 293 */ "typename ::= ID|STRING",
136248 /* 294 */ "signed ::= plus_num",
136249 /* 295 */ "signed ::= minus_num",
136250 /* 296 */ "carglist ::= carglist ccons",
136251 /* 297 */ "carglist ::=",
136252 /* 298 */ "ccons ::= NULL onconf",
136253 /* 299 */ "conslist_opt ::= COMMA conslist",
136254 /* 300 */ "conslist ::= conslist tconscomma tcons",
136255 /* 301 */ "conslist ::= tcons",
136256 /* 302 */ "tconscomma ::=",
136257 /* 303 */ "defer_subclause_opt ::= defer_subclause",
136258 /* 304 */ "resolvetype ::= raisetype",
136259 /* 305 */ "selectnowith ::= oneselect",
136260 /* 306 */ "oneselect ::= values",
136261 /* 307 */ "sclp ::= selcollist COMMA",
136262 /* 308 */ "as ::= ID|STRING",
136263 /* 309 */ "expr ::= term",
136264 /* 310 */ "likeop ::= LIKE_KW|MATCH",
136265 /* 311 */ "exprlist ::= nexprlist",
136266 /* 312 */ "nmnum ::= plus_num",
136267 /* 313 */ "nmnum ::= nm",
136268 /* 314 */ "nmnum ::= ON",
136269 /* 315 */ "nmnum ::= DELETE",
@@ -136375,11 +136896,10 @@
136896 { 173, 3 },
136897 { 173, 3 },
136898 { 173, 3 },
136899 { 173, 3 },
136900 { 173, 3 },
 
136901 { 221, 2 },
136902 { 173, 3 },
136903 { 173, 5 },
136904 { 173, 2 },
136905 { 173, 3 },
@@ -136512,10 +137032,11 @@
137032 { 194, 1 },
137033 { 195, 1 },
137034 { 209, 2 },
137035 { 210, 1 },
137036 { 173, 1 },
137037 { 221, 1 },
137038 { 208, 1 },
137039 { 230, 1 },
137040 { 230, 1 },
137041 { 230, 1 },
137042 { 230, 1 },
@@ -136654,11 +137175,11 @@
137175 case 42: /* autoinc ::= */ yytestcase(yyruleno==42);
137176 case 57: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==57);
137177 case 67: /* defer_subclause_opt ::= */ yytestcase(yyruleno==67);
137178 case 76: /* ifexists ::= */ yytestcase(yyruleno==76);
137179 case 90: /* distinct ::= */ yytestcase(yyruleno==90);
137180 case 214: /* collate ::= */ yytestcase(yyruleno==214);
137181 {yymsp[1].minor.yy194 = 0;}
137182 break;
137183 case 17: /* ifnotexists ::= IF NOT EXISTS */
137184 {yymsp[-2].minor.yy194 = 1;}
137185 break;
@@ -136798,13 +137319,13 @@
137319 case 144: /* insert_cmd ::= INSERT orconf */ yytestcase(yyruleno==144);
137320 {yymsp[-1].minor.yy194 = yymsp[0].minor.yy194;}
137321 break;
137322 case 58: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
137323 case 75: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==75);
137324 case 186: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==186);
137325 case 189: /* in_op ::= NOT IN */ yytestcase(yyruleno==189);
137326 case 215: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==215);
137327 {yymsp[-1].minor.yy194 = 1;}
137328 break;
137329 case 59: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
137330 {yymsp[-1].minor.yy194 = 0;}
137331 break;
@@ -136964,13 +137485,13 @@
137485 {yymsp[0].minor.yy194 = SF_All;}
137486 break;
137487 case 91: /* sclp ::= */
137488 case 119: /* orderby_opt ::= */ yytestcase(yyruleno==119);
137489 case 126: /* groupby_opt ::= */ yytestcase(yyruleno==126);
137490 case 202: /* exprlist ::= */ yytestcase(yyruleno==202);
137491 case 205: /* paren_exprlist ::= */ yytestcase(yyruleno==205);
137492 case 210: /* eidlist_opt ::= */ yytestcase(yyruleno==210);
137493 {yymsp[1].minor.yy148 = 0;}
137494 break;
137495 case 92: /* selcollist ::= sclp expr as */
137496 {
137497 yymsp[-2].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy148, yymsp[-1].minor.yy190.pExpr);
@@ -136992,12 +137513,12 @@
137513 yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148, pDot);
137514 }
137515 break;
137516 case 95: /* as ::= AS nm */
137517 case 106: /* dbnm ::= DOT nm */ yytestcase(yyruleno==106);
137518 case 224: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==224);
137519 case 225: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==225);
137520 {yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
137521 break;
137522 case 97: /* from ::= */
137523 {yymsp[1].minor.yy185 = sqlite3DbMallocZero(pParse->db, sizeof(*yymsp[1].minor.yy185));}
137524 break;
@@ -137076,18 +137597,18 @@
137597 {yymsp[-3].minor.yy194 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/}
137598 break;
137599 case 112: /* on_opt ::= ON expr */
137600 case 129: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==129);
137601 case 136: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==136);
137602 case 198: /* case_else ::= ELSE expr */ yytestcase(yyruleno==198);
137603 {yymsp[-1].minor.yy72 = yymsp[0].minor.yy190.pExpr;}
137604 break;
137605 case 113: /* on_opt ::= */
137606 case 128: /* having_opt ::= */ yytestcase(yyruleno==128);
137607 case 135: /* where_opt ::= */ yytestcase(yyruleno==135);
137608 case 199: /* case_else ::= */ yytestcase(yyruleno==199);
137609 case 201: /* case_operand ::= */ yytestcase(yyruleno==201);
137610 {yymsp[1].minor.yy72 = 0;}
137611 break;
137612 case 115: /* indexed_opt ::= INDEXED BY nm */
137613 {yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;}
137614 break;
@@ -137230,11 +137751,11 @@
137751 case 158: /* term ::= INTEGER */
137752 {
137753 yylhsminor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
137754 yylhsminor.yy190.zStart = yymsp[0].minor.yy0.z;
137755 yylhsminor.yy190.zEnd = yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n;
137756 if( yylhsminor.yy190.pExpr ) yylhsminor.yy190.pExpr->flags |= EP_Leaf|EP_Resolved;
137757 }
137758 yymsp[0].minor.yy190 = yylhsminor.yy190;
137759 break;
137760 case 159: /* expr ::= VARIABLE */
137761 {
@@ -137320,17 +137841,14 @@
137841 case 171: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==171);
137842 case 172: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==172);
137843 case 173: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==173);
137844 {spanBinaryExpr(pParse,yymsp[-1].major,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy190);}
137845 break;
137846 case 174: /* likeop ::= NOT LIKE_KW|MATCH */
 
 
 
137847 {yymsp[-1].minor.yy0=yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n|=0x80000000; /*yymsp[-1].minor.yy0-overwrite-yymsp[0].minor.yy0*/}
137848 break;
137849 case 175: /* expr ::= expr likeop expr */
137850 {
137851 ExprList *pList;
137852 int bNot = yymsp[-1].minor.yy0.n & 0x80000000;
137853 yymsp[-1].minor.yy0.n &= 0x7fffffff;
137854 pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy190.pExpr);
@@ -137339,11 +137857,11 @@
137857 exprNot(pParse, bNot, &yymsp[-2].minor.yy190);
137858 yymsp[-2].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd;
137859 if( yymsp[-2].minor.yy190.pExpr ) yymsp[-2].minor.yy190.pExpr->flags |= EP_InfixFunc;
137860 }
137861 break;
137862 case 176: /* expr ::= expr likeop expr ESCAPE expr */
137863 {
137864 ExprList *pList;
137865 int bNot = yymsp[-3].minor.yy0.n & 0x80000000;
137866 yymsp[-3].minor.yy0.n &= 0x7fffffff;
137867 pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr);
@@ -137353,43 +137871,43 @@
137871 exprNot(pParse, bNot, &yymsp[-4].minor.yy190);
137872 yymsp[-4].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd;
137873 if( yymsp[-4].minor.yy190.pExpr ) yymsp[-4].minor.yy190.pExpr->flags |= EP_InfixFunc;
137874 }
137875 break;
137876 case 177: /* expr ::= expr ISNULL|NOTNULL */
137877 {spanUnaryPostfix(pParse,yymsp[0].major,&yymsp[-1].minor.yy190,&yymsp[0].minor.yy0);}
137878 break;
137879 case 178: /* expr ::= expr NOT NULL */
137880 {spanUnaryPostfix(pParse,TK_NOTNULL,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy0);}
137881 break;
137882 case 179: /* expr ::= expr IS expr */
137883 {
137884 spanBinaryExpr(pParse,TK_IS,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy190);
137885 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy190.pExpr, yymsp[-2].minor.yy190.pExpr, TK_ISNULL);
137886 }
137887 break;
137888 case 180: /* expr ::= expr IS NOT expr */
137889 {
137890 spanBinaryExpr(pParse,TK_ISNOT,&yymsp[-3].minor.yy190,&yymsp[0].minor.yy190);
137891 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy190.pExpr, yymsp[-3].minor.yy190.pExpr, TK_NOTNULL);
137892 }
137893 break;
137894 case 181: /* expr ::= NOT expr */
137895 case 182: /* expr ::= BITNOT expr */ yytestcase(yyruleno==182);
137896 {spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,yymsp[-1].major,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/}
137897 break;
137898 case 183: /* expr ::= MINUS expr */
137899 {spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,TK_UMINUS,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/}
137900 break;
137901 case 184: /* expr ::= PLUS expr */
137902 {spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,TK_UPLUS,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/}
137903 break;
137904 case 185: /* between_op ::= BETWEEN */
137905 case 188: /* in_op ::= IN */ yytestcase(yyruleno==188);
137906 {yymsp[0].minor.yy194 = 0;}
137907 break;
137908 case 187: /* expr ::= expr between_op expr AND expr */
137909 {
137910 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr);
137911 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy190.pExpr);
137912 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy190.pExpr, 0);
137913 if( yymsp[-4].minor.yy190.pExpr ){
@@ -137399,11 +137917,11 @@
137917 }
137918 exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
137919 yymsp[-4].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd;
137920 }
137921 break;
137922 case 190: /* expr ::= expr in_op LP exprlist RP */
137923 {
137924 if( yymsp[-1].minor.yy148==0 ){
137925 /* Expressions of the form
137926 **
137927 ** expr1 IN ()
@@ -137452,26 +137970,26 @@
137970 exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
137971 }
137972 yymsp[-4].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
137973 }
137974 break;
137975 case 191: /* expr ::= LP select RP */
137976 {
137977 spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
137978 yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
137979 sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy190.pExpr, yymsp[-1].minor.yy243);
137980 }
137981 break;
137982 case 192: /* expr ::= expr in_op LP select RP */
137983 {
137984 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
137985 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, yymsp[-1].minor.yy243);
137986 exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
137987 yymsp[-4].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
137988 }
137989 break;
137990 case 193: /* expr ::= expr in_op nm dbnm paren_exprlist */
137991 {
137992 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
137993 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
137994 if( yymsp[0].minor.yy148 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy148);
137995 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
@@ -137478,19 +137996,19 @@
137996 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, pSelect);
137997 exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
137998 yymsp[-4].minor.yy190.zEnd = yymsp[-1].minor.yy0.z ? &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n] : &yymsp[-2].minor.yy0.z[yymsp[-2].minor.yy0.n];
137999 }
138000 break;
138001 case 194: /* expr ::= EXISTS LP select RP */
138002 {
138003 Expr *p;
138004 spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
138005 p = yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
138006 sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy243);
138007 }
138008 break;
138009 case 195: /* expr ::= CASE case_operand case_exprlist case_else END */
138010 {
138011 spanSet(&yymsp[-4].minor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-C*/
138012 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy72, 0);
138013 if( yymsp[-4].minor.yy190.pExpr ){
138014 yymsp[-4].minor.yy190.pExpr->x.pList = yymsp[-1].minor.yy72 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy148,yymsp[-1].minor.yy72) : yymsp[-2].minor.yy148;
@@ -137499,313 +138017,314 @@
138017 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy148);
138018 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy72);
138019 }
138020 }
138021 break;
138022 case 196: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
138023 {
138024 yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy148, yymsp[-2].minor.yy190.pExpr);
138025 yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy148, yymsp[0].minor.yy190.pExpr);
138026 }
138027 break;
138028 case 197: /* case_exprlist ::= WHEN expr THEN expr */
138029 {
138030 yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr);
138031 yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148, yymsp[0].minor.yy190.pExpr);
138032 }
138033 break;
138034 case 200: /* case_operand ::= expr */
138035 {yymsp[0].minor.yy72 = yymsp[0].minor.yy190.pExpr; /*A-overwrites-X*/}
138036 break;
138037 case 203: /* nexprlist ::= nexprlist COMMA expr */
138038 {yymsp[-2].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy148,yymsp[0].minor.yy190.pExpr);}
138039 break;
138040 case 204: /* nexprlist ::= expr */
138041 {yymsp[0].minor.yy148 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy190.pExpr); /*A-overwrites-Y*/}
138042 break;
138043 case 206: /* paren_exprlist ::= LP exprlist RP */
138044 case 211: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==211);
138045 {yymsp[-2].minor.yy148 = yymsp[-1].minor.yy148;}
138046 break;
138047 case 207: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
138048 {
138049 sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
138050 sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy148, yymsp[-10].minor.yy194,
138051 &yymsp[-11].minor.yy0, yymsp[0].minor.yy72, SQLITE_SO_ASC, yymsp[-8].minor.yy194, SQLITE_IDXTYPE_APPDEF);
138052 }
138053 break;
138054 case 208: /* uniqueflag ::= UNIQUE */
138055 case 249: /* raisetype ::= ABORT */ yytestcase(yyruleno==249);
138056 {yymsp[0].minor.yy194 = OE_Abort;}
138057 break;
138058 case 209: /* uniqueflag ::= */
138059 {yymsp[1].minor.yy194 = OE_None;}
138060 break;
138061 case 212: /* eidlist ::= eidlist COMMA nm collate sortorder */
138062 {
138063 yymsp[-4].minor.yy148 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy148, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy194, yymsp[0].minor.yy194);
138064 }
138065 break;
138066 case 213: /* eidlist ::= nm collate sortorder */
138067 {
138068 yymsp[-2].minor.yy148 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy194, yymsp[0].minor.yy194); /*A-overwrites-Y*/
138069 }
138070 break;
138071 case 216: /* cmd ::= DROP INDEX ifexists fullname */
138072 {sqlite3DropIndex(pParse, yymsp[0].minor.yy185, yymsp[-1].minor.yy194);}
138073 break;
138074 case 217: /* cmd ::= VACUUM */
138075 {sqlite3Vacuum(pParse,0);}
138076 break;
138077 case 218: /* cmd ::= VACUUM nm */
138078 {sqlite3Vacuum(pParse,&yymsp[0].minor.yy0);}
138079 break;
138080 case 219: /* cmd ::= PRAGMA nm dbnm */
138081 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
138082 break;
138083 case 220: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
138084 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
138085 break;
138086 case 221: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
138087 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
138088 break;
138089 case 222: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
138090 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
138091 break;
138092 case 223: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
138093 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
138094 break;
138095 case 226: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
138096 {
138097 Token all;
138098 all.z = yymsp[-3].minor.yy0.z;
138099 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
138100 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy145, &all);
138101 }
138102 break;
138103 case 227: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
138104 {
138105 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy194, yymsp[-4].minor.yy332.a, yymsp[-4].minor.yy332.b, yymsp[-2].minor.yy185, yymsp[0].minor.yy72, yymsp[-10].minor.yy194, yymsp[-8].minor.yy194);
138106 yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
138107 }
138108 break;
138109 case 228: /* trigger_time ::= BEFORE */
138110 { yymsp[0].minor.yy194 = TK_BEFORE; }
138111 break;
138112 case 229: /* trigger_time ::= AFTER */
138113 { yymsp[0].minor.yy194 = TK_AFTER; }
138114 break;
138115 case 230: /* trigger_time ::= INSTEAD OF */
138116 { yymsp[-1].minor.yy194 = TK_INSTEAD;}
138117 break;
138118 case 231: /* trigger_time ::= */
138119 { yymsp[1].minor.yy194 = TK_BEFORE; }
138120 break;
138121 case 232: /* trigger_event ::= DELETE|INSERT */
138122 case 233: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==233);
138123 {yymsp[0].minor.yy332.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy332.b = 0;}
138124 break;
138125 case 234: /* trigger_event ::= UPDATE OF idlist */
138126 {yymsp[-2].minor.yy332.a = TK_UPDATE; yymsp[-2].minor.yy332.b = yymsp[0].minor.yy254;}
138127 break;
138128 case 235: /* when_clause ::= */
138129 case 254: /* key_opt ::= */ yytestcase(yyruleno==254);
138130 { yymsp[1].minor.yy72 = 0; }
138131 break;
138132 case 236: /* when_clause ::= WHEN expr */
138133 case 255: /* key_opt ::= KEY expr */ yytestcase(yyruleno==255);
138134 { yymsp[-1].minor.yy72 = yymsp[0].minor.yy190.pExpr; }
138135 break;
138136 case 237: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
138137 {
138138 assert( yymsp[-2].minor.yy145!=0 );
138139 yymsp[-2].minor.yy145->pLast->pNext = yymsp[-1].minor.yy145;
138140 yymsp[-2].minor.yy145->pLast = yymsp[-1].minor.yy145;
138141 }
138142 break;
138143 case 238: /* trigger_cmd_list ::= trigger_cmd SEMI */
138144 {
138145 assert( yymsp[-1].minor.yy145!=0 );
138146 yymsp[-1].minor.yy145->pLast = yymsp[-1].minor.yy145;
138147 }
138148 break;
138149 case 239: /* trnm ::= nm DOT nm */
138150 {
138151 yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
138152 sqlite3ErrorMsg(pParse,
138153 "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
138154 "statements within triggers");
138155 }
138156 break;
138157 case 240: /* tridxby ::= INDEXED BY nm */
138158 {
138159 sqlite3ErrorMsg(pParse,
138160 "the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
138161 "within triggers");
138162 }
138163 break;
138164 case 241: /* tridxby ::= NOT INDEXED */
138165 {
138166 sqlite3ErrorMsg(pParse,
138167 "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
138168 "within triggers");
138169 }
138170 break;
138171 case 242: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
138172 {yymsp[-6].minor.yy145 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy148, yymsp[0].minor.yy72, yymsp[-5].minor.yy194);}
138173 break;
138174 case 243: /* trigger_cmd ::= insert_cmd INTO trnm idlist_opt select */
138175 {yymsp[-4].minor.yy145 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy254, yymsp[0].minor.yy243, yymsp[-4].minor.yy194);/*A-overwrites-R*/}
138176 break;
138177 case 244: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
138178 {yymsp[-4].minor.yy145 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy72);}
138179 break;
138180 case 245: /* trigger_cmd ::= select */
138181 {yymsp[0].minor.yy145 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy243); /*A-overwrites-X*/}
138182 break;
138183 case 246: /* expr ::= RAISE LP IGNORE RP */
138184 {
138185 spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
138186 yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
138187 if( yymsp[-3].minor.yy190.pExpr ){
138188 yymsp[-3].minor.yy190.pExpr->affinity = OE_Ignore;
138189 }
138190 }
138191 break;
138192 case 247: /* expr ::= RAISE LP raisetype COMMA nm RP */
138193 {
138194 spanSet(&yymsp[-5].minor.yy190,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
138195 yymsp[-5].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
138196 if( yymsp[-5].minor.yy190.pExpr ) {
138197 yymsp[-5].minor.yy190.pExpr->affinity = (char)yymsp[-3].minor.yy194;
138198 }
138199 }
138200 break;
138201 case 248: /* raisetype ::= ROLLBACK */
138202 {yymsp[0].minor.yy194 = OE_Rollback;}
138203 break;
138204 case 250: /* raisetype ::= FAIL */
138205 {yymsp[0].minor.yy194 = OE_Fail;}
138206 break;
138207 case 251: /* cmd ::= DROP TRIGGER ifexists fullname */
138208 {
138209 sqlite3DropTrigger(pParse,yymsp[0].minor.yy185,yymsp[-1].minor.yy194);
138210 }
138211 break;
138212 case 252: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
138213 {
138214 sqlite3Attach(pParse, yymsp[-3].minor.yy190.pExpr, yymsp[-1].minor.yy190.pExpr, yymsp[0].minor.yy72);
138215 }
138216 break;
138217 case 253: /* cmd ::= DETACH database_kw_opt expr */
138218 {
138219 sqlite3Detach(pParse, yymsp[0].minor.yy190.pExpr);
138220 }
138221 break;
138222 case 256: /* cmd ::= REINDEX */
138223 {sqlite3Reindex(pParse, 0, 0);}
138224 break;
138225 case 257: /* cmd ::= REINDEX nm dbnm */
138226 {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
138227 break;
138228 case 258: /* cmd ::= ANALYZE */
138229 {sqlite3Analyze(pParse, 0, 0);}
138230 break;
138231 case 259: /* cmd ::= ANALYZE nm dbnm */
138232 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
138233 break;
138234 case 260: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
138235 {
138236 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy185,&yymsp[0].minor.yy0);
138237 }
138238 break;
138239 case 261: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
138240 {
138241 yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n;
138242 sqlite3AlterFinishAddColumn(pParse, &yymsp[-1].minor.yy0);
138243 }
138244 break;
138245 case 262: /* add_column_fullname ::= fullname */
138246 {
138247 disableLookaside(pParse);
138248 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy185);
138249 }
138250 break;
138251 case 263: /* cmd ::= create_vtab */
138252 {sqlite3VtabFinishParse(pParse,0);}
138253 break;
138254 case 264: /* cmd ::= create_vtab LP vtabarglist RP */
138255 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
138256 break;
138257 case 265: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
138258 {
138259 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy194);
138260 }
138261 break;
138262 case 266: /* vtabarg ::= */
138263 {sqlite3VtabArgInit(pParse);}
138264 break;
138265 case 267: /* vtabargtoken ::= ANY */
138266 case 268: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==268);
138267 case 269: /* lp ::= LP */ yytestcase(yyruleno==269);
138268 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
138269 break;
138270 case 270: /* with ::= */
138271 {yymsp[1].minor.yy285 = 0;}
138272 break;
138273 case 271: /* with ::= WITH wqlist */
138274 { yymsp[-1].minor.yy285 = yymsp[0].minor.yy285; }
138275 break;
138276 case 272: /* with ::= WITH RECURSIVE wqlist */
138277 { yymsp[-2].minor.yy285 = yymsp[0].minor.yy285; }
138278 break;
138279 case 273: /* wqlist ::= nm eidlist_opt AS LP select RP */
138280 {
138281 yymsp[-5].minor.yy285 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy148, yymsp[-1].minor.yy243); /*A-overwrites-X*/
138282 }
138283 break;
138284 case 274: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
138285 {
138286 yymsp[-7].minor.yy285 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy285, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy148, yymsp[-1].minor.yy243);
138287 }
138288 break;
138289 default:
138290 /* (275) input ::= cmdlist */ yytestcase(yyruleno==275);
138291 /* (276) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==276);
138292 /* (277) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=277);
138293 /* (278) ecmd ::= SEMI */ yytestcase(yyruleno==278);
138294 /* (279) ecmd ::= explain cmdx SEMI */ yytestcase(yyruleno==279);
138295 /* (280) explain ::= */ yytestcase(yyruleno==280);
138296 /* (281) trans_opt ::= */ yytestcase(yyruleno==281);
138297 /* (282) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==282);
138298 /* (283) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==283);
138299 /* (284) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==284);
138300 /* (285) savepoint_opt ::= */ yytestcase(yyruleno==285);
138301 /* (286) cmd ::= create_table create_table_args */ yytestcase(yyruleno==286);
138302 /* (287) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==287);
138303 /* (288) columnlist ::= columnname carglist */ yytestcase(yyruleno==288);
138304 /* (289) nm ::= ID|INDEXED */ yytestcase(yyruleno==289);
138305 /* (290) nm ::= STRING */ yytestcase(yyruleno==290);
138306 /* (291) nm ::= JOIN_KW */ yytestcase(yyruleno==291);
138307 /* (292) typetoken ::= typename */ yytestcase(yyruleno==292);
138308 /* (293) typename ::= ID|STRING */ yytestcase(yyruleno==293);
138309 /* (294) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=294);
138310 /* (295) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=295);
138311 /* (296) carglist ::= carglist ccons */ yytestcase(yyruleno==296);
138312 /* (297) carglist ::= */ yytestcase(yyruleno==297);
138313 /* (298) ccons ::= NULL onconf */ yytestcase(yyruleno==298);
138314 /* (299) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==299);
138315 /* (300) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==300);
138316 /* (301) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=301);
138317 /* (302) tconscomma ::= */ yytestcase(yyruleno==302);
138318 /* (303) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=303);
138319 /* (304) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=304);
138320 /* (305) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=305);
138321 /* (306) oneselect ::= values */ yytestcase(yyruleno==306);
138322 /* (307) sclp ::= selcollist COMMA */ yytestcase(yyruleno==307);
138323 /* (308) as ::= ID|STRING */ yytestcase(yyruleno==308);
138324 /* (309) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=309);
138325 /* (310) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==310);
138326 /* (311) exprlist ::= nexprlist */ yytestcase(yyruleno==311);
138327 /* (312) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=312);
138328 /* (313) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=313);
138329 /* (314) nmnum ::= ON */ yytestcase(yyruleno==314);
138330 /* (315) nmnum ::= DELETE */ yytestcase(yyruleno==315);
@@ -138854,12 +139373,12 @@
139373 ** memory obtained from sqlite3_malloc() and to make *pzErrMsg point to that
139374 ** error message.
139375 */
139376 SQLITE_PRIVATE int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
139377 int nErr = 0; /* Number of errors encountered */
 
139378 void *pEngine; /* The LEMON-generated LALR(1) parser */
139379 int n = 0; /* Length of the next token token */
139380 int tokenType; /* type of the next token */
139381 int lastTokenParsed = -1; /* type of the previous token */
139382 sqlite3 *db = pParse->db; /* The database connection */
139383 int mxSqlLen; /* Max length of an SQL string */
139384 #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
@@ -138871,11 +139390,10 @@
139390 if( db->nVdbeActive==0 ){
139391 db->u1.isInterrupted = 0;
139392 }
139393 pParse->rc = SQLITE_OK;
139394 pParse->zTail = zSql;
 
139395 assert( pzErrMsg!=0 );
139396 /* sqlite3ParserTrace(stdout, "parser: "); */
139397 #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
139398 pEngine = zSpace;
139399 sqlite3ParserInit(pEngine);
@@ -138889,16 +139407,14 @@
139407 assert( pParse->pNewTable==0 );
139408 assert( pParse->pNewTrigger==0 );
139409 assert( pParse->nVar==0 );
139410 assert( pParse->pVList==0 );
139411 while( 1 ){
139412 if( zSql[0]!=0 ){
139413 n = sqlite3GetToken((u8*)zSql, &tokenType);
139414 mxSqlLen -= n;
139415 if( mxSqlLen<0 ){
 
 
139416 pParse->rc = SQLITE_TOOBIG;
139417 break;
139418 }
139419 }else{
139420 /* Upon reaching the end of input, call the parser two more times
@@ -138908,30 +139424,34 @@
139424 }else if( lastTokenParsed==0 ){
139425 break;
139426 }else{
139427 tokenType = TK_SEMI;
139428 }
139429 zSql -= n;
139430 }
139431 if( tokenType>=TK_SPACE ){
139432 assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL );
139433 if( db->u1.isInterrupted ){
139434 pParse->rc = SQLITE_INTERRUPT;
139435 break;
139436 }
139437 if( tokenType==TK_ILLEGAL ){
139438 sqlite3ErrorMsg(pParse, "unrecognized token: \"%.*s\"", n, zSql);
 
139439 break;
139440 }
139441 zSql += n;
139442 }else{
139443 pParse->sLastToken.z = zSql;
139444 pParse->sLastToken.n = n;
139445 sqlite3Parser(pEngine, tokenType, pParse->sLastToken, pParse);
139446 lastTokenParsed = tokenType;
139447 zSql += n;
139448 if( pParse->rc!=SQLITE_OK || db->mallocFailed ) break;
139449 }
139450 }
139451 assert( nErr==0 );
139452 pParse->zTail = zSql;
139453 #ifdef YYTRACKMAXSTACKDEPTH
139454 sqlite3_mutex_enter(sqlite3MallocMutex());
139455 sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
139456 sqlite3ParserStackPeak(pEngine)
139457 );
@@ -140301,10 +140821,25 @@
140821 return 0;
140822 }
140823 #endif
140824 return db->lastRowid;
140825 }
140826
140827 /*
140828 ** Set the value returned by the sqlite3_last_insert_rowid() API function.
140829 */
140830 SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3 *db, sqlite3_int64 iRowid){
140831 #ifdef SQLITE_ENABLE_API_ARMOR
140832 if( !sqlite3SafetyCheckOk(db) ){
140833 (void)SQLITE_MISUSE_BKPT;
140834 return;
140835 }
140836 #endif
140837 sqlite3_mutex_enter(db->mutex);
140838 db->lastRowid = iRowid;
140839 sqlite3_mutex_leave(db->mutex);
140840 }
140841
140842 /*
140843 ** Return the number of changes in the most recent call to sqlite3_exec().
140844 */
140845 SQLITE_API int sqlite3_changes(sqlite3 *db){
@@ -145052,12 +145587,13 @@
145587 /*
145588 ** Read a 64-bit variable-length integer from memory starting at p[0].
145589 ** Return the number of bytes read, or 0 on error.
145590 ** The value is stored in *v.
145591 */
145592 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *pBuf, sqlite_int64 *v){
145593 const unsigned char *p = (const unsigned char*)pBuf;
145594 const unsigned char *pStart = p;
145595 u32 a;
145596 u64 b;
145597 int shift;
145598
145599 GETVARINT_INIT(a, p, 0, 0x00, 0x80, *v, 1);
@@ -146100,11 +146636,13 @@
146636 /* Fill in the azColumn array */
146637 for(iCol=0; iCol<nCol; iCol++){
146638 char *z;
146639 int n = 0;
146640 z = (char *)sqlite3Fts3NextToken(aCol[iCol], &n);
146641 if( n>0 ){
146642 memcpy(zCsr, z, n);
146643 }
146644 zCsr[n] = '\0';
146645 sqlite3Fts3Dequote(zCsr);
146646 p->azColumn[iCol] = zCsr;
146647 zCsr += n+1;
146648 assert( zCsr <= &((char *)p)[nByte] );
@@ -148111,12 +148649,14 @@
148649 ** segments.
148650 */
148651 const u32 nMinMerge = 64; /* Minimum amount of incr-merge work to do */
148652
148653 Fts3Table *p = (Fts3Table*)pVtab;
148654 int rc;
148655 i64 iLastRowid = sqlite3_last_insert_rowid(p->db);
148656
148657 rc = sqlite3Fts3PendingTermsFlush(p);
148658 if( rc==SQLITE_OK
148659 && p->nLeafAdd>(nMinMerge/16)
148660 && p->nAutoincrmerge && p->nAutoincrmerge!=0xff
148661 ){
148662 int mxLevel = 0; /* Maximum relative level value in db */
@@ -148127,10 +148667,11 @@
148667 A = p->nLeafAdd * mxLevel;
148668 A += (A/2);
148669 if( A>(int)nMinMerge ) rc = sqlite3Fts3Incrmerge(p, A, p->nAutoincrmerge);
148670 }
148671 sqlite3Fts3SegmentsClose(p);
148672 sqlite3_set_last_insert_rowid(p->db, iLastRowid);
148673 return rc;
148674 }
148675
148676 /*
148677 ** If it is currently unknown whether or not the FTS table has an %_stat
@@ -159737,15 +160278,18 @@
160278
160279 /*
160280 ** Convert the text beginning at *pz into an integer and return
160281 ** its value. Advance *pz to point to the first character past
160282 ** the integer.
160283 **
160284 ** This function used for parameters to merge= and incrmerge=
160285 ** commands.
160286 */
160287 static int fts3Getint(const char **pz){
160288 const char *z = *pz;
160289 int i = 0;
160290 while( (*z)>='0' && (*z)<='9' && i<214748363 ) i = 10*i + *(z++) - '0';
160291 *pz = z;
160292 return i;
160293 }
160294
160295 /*
@@ -162307,20 +162851,20 @@
162851 const char *zIn, /* Array of characters to make exceptions */
162852 int nIn /* Length of z in bytes */
162853 ){
162854 const unsigned char *z = (const unsigned char *)zIn;
162855 const unsigned char *zTerm = &z[nIn];
162856 unsigned int iCode;
162857 int nEntry = 0;
162858
162859 assert( bAlnum==0 || bAlnum==1 );
162860
162861 while( z<zTerm ){
162862 READ_UTF8(z, zTerm, iCode);
162863 assert( (sqlite3FtsUnicodeIsalnum((int)iCode) & 0xFFFFFFFE)==0 );
162864 if( sqlite3FtsUnicodeIsalnum((int)iCode)!=bAlnum
162865 && sqlite3FtsUnicodeIsdiacritic((int)iCode)==0
162866 ){
162867 nEntry++;
162868 }
162869 }
162870
@@ -162333,17 +162877,17 @@
162877 nNew = p->nException;
162878
162879 z = (const unsigned char *)zIn;
162880 while( z<zTerm ){
162881 READ_UTF8(z, zTerm, iCode);
162882 if( sqlite3FtsUnicodeIsalnum((int)iCode)!=bAlnum
162883 && sqlite3FtsUnicodeIsdiacritic((int)iCode)==0
162884 ){
162885 int i, j;
162886 for(i=0; i<nNew && aNew[i]<(int)iCode; i++);
162887 for(j=nNew; j>i; j--) aNew[j] = aNew[j-1];
162888 aNew[i] = (int)iCode;
162889 nNew++;
162890 }
162891 }
162892 p->aiException = aNew;
162893 p->nException = nNew;
@@ -162489,11 +163033,11 @@
163033 int *piEnd, /* OUT: Ending offset of token */
163034 int *piPos /* OUT: Position integer of token */
163035 ){
163036 unicode_cursor *pCsr = (unicode_cursor *)pC;
163037 unicode_tokenizer *p = ((unicode_tokenizer *)pCsr->base.pTokenizer);
163038 unsigned int iCode = 0;
163039 char *zOut;
163040 const unsigned char *z = &pCsr->aInput[pCsr->iOff];
163041 const unsigned char *zStart = z;
163042 const unsigned char *zEnd;
163043 const unsigned char *zTerm = &pCsr->aInput[pCsr->nInput];
@@ -162501,11 +163045,11 @@
163045 /* Scan past any delimiter characters before the start of the next token.
163046 ** Return SQLITE_DONE early if this takes us all the way to the end of
163047 ** the input. */
163048 while( z<zTerm ){
163049 READ_UTF8(z, zTerm, iCode);
163050 if( unicodeIsAlnum(p, (int)iCode) ) break;
163051 zStart = z;
163052 }
163053 if( zStart>=zTerm ) return SQLITE_DONE;
163054
163055 zOut = pCsr->zToken;
@@ -162521,20 +163065,20 @@
163065 pCsr->nAlloc += 64;
163066 }
163067
163068 /* Write the folded case of the last character read to the output */
163069 zEnd = z;
163070 iOut = sqlite3FtsUnicodeFold((int)iCode, p->bRemoveDiacritic);
163071 if( iOut ){
163072 WRITE_UTF8(zOut, iOut);
163073 }
163074
163075 /* If the cursor is not at EOF, read the next character */
163076 if( z>=zTerm ) break;
163077 READ_UTF8(z, zTerm, iCode);
163078 }while( unicodeIsAlnum(p, (int)iCode)
163079 || sqlite3FtsUnicodeIsdiacritic((int)iCode)
163080 );
163081
163082 /* Set the output variables and return. */
163083 pCsr->iOff = (int)(z - pCsr->aInput);
163084 *paToken = pCsr->zToken;
@@ -162694,13 +163238,13 @@
163238 };
163239 static const unsigned int aAscii[4] = {
163240 0xFFFFFFFF, 0xFC00FFFF, 0xF8000001, 0xF8000001,
163241 };
163242
163243 if( (unsigned int)c<128 ){
163244 return ( (aAscii[c >> 5] & ((unsigned int)1 << (c & 0x001F)))==0 );
163245 }else if( (unsigned int)c<(1<<22) ){
163246 unsigned int key = (((unsigned int)c)<<10) | 0x000003FF;
163247 int iRes = 0;
163248 int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1;
163249 int iLo = 0;
163250 while( iHi>=iLo ){
@@ -162889,20 +163433,21 @@
163433 65514, 65521, 65527, 65528, 65529,
163434 };
163435
163436 int ret = c;
163437
 
163438 assert( sizeof(unsigned short)==2 && sizeof(unsigned char)==1 );
163439
163440 if( c<128 ){
163441 if( c>='A' && c<='Z' ) ret = c + ('a' - 'A');
163442 }else if( c<65536 ){
163443 const struct TableEntry *p;
163444 int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1;
163445 int iLo = 0;
163446 int iRes = -1;
163447
163448 assert( c>aEntry[0].iCode );
163449 while( iHi>=iLo ){
163450 int iTest = (iHi + iLo) / 2;
163451 int cmp = (c - aEntry[iTest].iCode);
163452 if( cmp>=0 ){
163453 iRes = iTest;
@@ -162909,18 +163454,16 @@
163454 iLo = iTest+1;
163455 }else{
163456 iHi = iTest-1;
163457 }
163458 }
163459
163460 assert( iRes>=0 && c>=aEntry[iRes].iCode );
163461 p = &aEntry[iRes];
163462 if( c<(p->iCode + p->nRange) && 0==(0x01 & p->flags & (p->iCode ^ c)) ){
163463 ret = (c + (aiOff[p->flags>>1])) & 0x0000FFFF;
163464 assert( ret>0 );
 
 
163465 }
163466
163467 if( bRemoveDiacritic ) ret = remove_diacritic(ret);
163468 }
163469
@@ -163393,19 +163936,19 @@
163936 #elif SQLITE_BYTEORDER==4321
163937 i64 x;
163938 memcpy(&x, p, 8);
163939 return x;
163940 #else
163941 return (i64)(
163942 (((u64)p[0]) << 56) +
163943 (((u64)p[1]) << 48) +
163944 (((u64)p[2]) << 40) +
163945 (((u64)p[3]) << 32) +
163946 (((u64)p[4]) << 24) +
163947 (((u64)p[5]) << 16) +
163948 (((u64)p[6]) << 8) +
163949 (((u64)p[7]) << 0)
163950 );
163951 #endif
163952 }
163953
163954 /*
@@ -168462,10 +169005,11 @@
169005 int nStep; /* Rows processed for current object */
169006 int nProgress; /* Rows processed for all objects */
169007 RbuObjIter objiter; /* Iterator for skipping through tbl/idx */
169008 const char *zVfsName; /* Name of automatically created rbu vfs */
169009 rbu_file *pTargetFd; /* File handle open on target db */
169010 int nPagePerSector; /* Pages per sector for pTargetFd */
169011 i64 iOalSz;
169012 i64 nPhaseOneStep;
169013
169014 /* The following state variables are used as part of the incremental
169015 ** checkpoint stage (eStage==RBU_STAGE_CKPT). See comments surrounding
@@ -170726,10 +171270,27 @@
171270
171271 if( p->rc==SQLITE_OK ){
171272 if( p->nFrame==0 || (pState && pState->iWalCksum!=p->iWalCksum) ){
171273 p->rc = SQLITE_DONE;
171274 p->eStage = RBU_STAGE_DONE;
171275 }else{
171276 int nSectorSize;
171277 sqlite3_file *pDb = p->pTargetFd->pReal;
171278 sqlite3_file *pWal = p->pTargetFd->pWalFd->pReal;
171279 assert( p->nPagePerSector==0 );
171280 nSectorSize = pDb->pMethods->xSectorSize(pDb);
171281 if( nSectorSize>p->pgsz ){
171282 p->nPagePerSector = nSectorSize / p->pgsz;
171283 }else{
171284 p->nPagePerSector = 1;
171285 }
171286
171287 /* Call xSync() on the wal file. This causes SQLite to sync the
171288 ** directory in which the target database and the wal file reside, in
171289 ** case it has not been synced since the rename() call in
171290 ** rbuMoveOalFile(). */
171291 p->rc = pWal->pMethods->xSync(pWal, SQLITE_SYNC_NORMAL);
171292 }
171293 }
171294 }
171295
171296 /*
@@ -171381,13 +171942,30 @@
171942 if( p->rc==SQLITE_OK ){
171943 p->eStage = RBU_STAGE_DONE;
171944 p->rc = SQLITE_DONE;
171945 }
171946 }else{
171947 /* At one point the following block copied a single frame from the
171948 ** wal file to the database file. So that one call to sqlite3rbu_step()
171949 ** checkpointed a single frame.
171950 **
171951 ** However, if the sector-size is larger than the page-size, and the
171952 ** application calls sqlite3rbu_savestate() or close() immediately
171953 ** after this step, then rbu_step() again, then a power failure occurs,
171954 ** then the database page written here may be damaged. Work around
171955 ** this by checkpointing frames until the next page in the aFrame[]
171956 ** lies on a different disk sector to the current one. */
171957 u32 iSector;
171958 do{
171959 RbuFrame *pFrame = &p->aFrame[p->nStep];
171960 iSector = (pFrame->iDbPage-1) / p->nPagePerSector;
171961 rbuCheckpointFrame(p, pFrame);
171962 p->nStep++;
171963 }while( p->nStep<p->nFrame
171964 && iSector==((p->aFrame[p->nStep].iDbPage-1) / p->nPagePerSector)
171965 && p->rc==SQLITE_OK
171966 );
171967 }
171968 p->nProgress++;
171969 }
171970 break;
171971 }
@@ -171823,10 +172401,16 @@
172401
172402 /* Commit the transaction to the *-oal file. */
172403 if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_OAL ){
172404 p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg);
172405 }
172406
172407 /* Sync the db file if currently doing an incremental checkpoint */
172408 if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_CKPT ){
172409 sqlite3_file *pDb = p->pTargetFd->pReal;
172410 p->rc = pDb->pMethods->xSync(pDb, SQLITE_SYNC_NORMAL);
172411 }
172412
172413 rbuSaveState(p, p->eStage);
172414
172415 if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_OAL ){
172416 p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
@@ -171947,10 +172531,16 @@
172531 assert( p->eStage>=RBU_STAGE_OAL && p->eStage<=RBU_STAGE_DONE );
172532 if( p->eStage==RBU_STAGE_OAL ){
172533 assert( rc!=SQLITE_DONE );
172534 if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, 0);
172535 }
172536
172537 /* Sync the db file */
172538 if( rc==SQLITE_OK && p->eStage==RBU_STAGE_CKPT ){
172539 sqlite3_file *pDb = p->pTargetFd->pReal;
172540 rc = pDb->pMethods->xSync(pDb, SQLITE_SYNC_NORMAL);
172541 }
172542
172543 p->rc = rc;
172544 rbuSaveState(p, p->eStage);
172545 rc = p->rc;
172546
@@ -178363,26 +178953,28 @@
178953 /* Bit values for the JsonNode.jnFlag field
178954 */
178955 #define JNODE_RAW 0x01 /* Content is raw, not JSON encoded */
178956 #define JNODE_ESCAPE 0x02 /* Content is text with \ escapes */
178957 #define JNODE_REMOVE 0x04 /* Do not output */
178958 #define JNODE_REPLACE 0x08 /* Replace with JsonNode.u.iReplace */
178959 #define JNODE_PATCH 0x10 /* Patch with JsonNode.u.pPatch */
178960 #define JNODE_APPEND 0x20 /* More ARRAY/OBJECT entries at u.iAppend */
178961 #define JNODE_LABEL 0x40 /* Is a label of an object */
178962
178963
178964 /* A single node of parsed JSON
178965 */
178966 struct JsonNode {
178967 u8 eType; /* One of the JSON_ type values */
178968 u8 jnFlags; /* JNODE flags */
 
178969 u32 n; /* Bytes of content, or number of sub-nodes */
178970 union {
178971 const char *zJContent; /* Content for INT, REAL, and STRING */
178972 u32 iAppend; /* More terms for ARRAY and OBJECT */
178973 u32 iKey; /* Key for ARRAY objects in json_tree() */
178974 u32 iReplace; /* Replacement content for JNODE_REPLACE */
178975 JsonNode *pPatch; /* Node chain of patch for JNODE_PATCH */
178976 } u;
178977 };
178978
178979 /* A completely parsed JSON string
178980 */
@@ -178635,10 +179227,17 @@
179227 static void jsonRenderNode(
179228 JsonNode *pNode, /* The node to render */
179229 JsonString *pOut, /* Write JSON here */
179230 sqlite3_value **aReplace /* Replacement values */
179231 ){
179232 if( pNode->jnFlags & (JNODE_REPLACE|JNODE_PATCH) ){
179233 if( pNode->jnFlags & JNODE_REPLACE ){
179234 jsonAppendValue(pOut, aReplace[pNode->u.iReplace]);
179235 return;
179236 }
179237 pNode = pNode->u.pPatch;
179238 }
179239 switch( pNode->eType ){
179240 default: {
179241 assert( pNode->eType==JSON_NULL );
179242 jsonAppendRaw(pOut, "null", 4);
179243 break;
@@ -178666,16 +179265,11 @@
179265 case JSON_ARRAY: {
179266 u32 j = 1;
179267 jsonAppendChar(pOut, '[');
179268 for(;;){
179269 while( j<=pNode->n ){
179270 if( (pNode[j].jnFlags & JNODE_REMOVE)==0 ){
 
 
 
 
 
179271 jsonAppendSeparator(pOut);
179272 jsonRenderNode(&pNode[j], pOut, aReplace);
179273 }
179274 j += jsonNodeSize(&pNode[j]);
179275 }
@@ -178693,15 +179287,11 @@
179287 while( j<=pNode->n ){
179288 if( (pNode[j+1].jnFlags & JNODE_REMOVE)==0 ){
179289 jsonAppendSeparator(pOut);
179290 jsonRenderNode(&pNode[j], pOut, aReplace);
179291 jsonAppendChar(pOut, ':');
179292 jsonRenderNode(&pNode[j+1], pOut, aReplace);
 
 
 
 
179293 }
179294 j += 1 + jsonNodeSize(&pNode[j+1]);
179295 }
179296 if( (pNode->jnFlags & JNODE_APPEND)==0 ) break;
179297 pNode = &pNode[pNode->u.iAppend];
@@ -178924,11 +179514,10 @@
179514 return jsonParseAddNodeExpand(pParse, eType, n, zContent);
179515 }
179516 p = &pParse->aNode[pParse->nNode];
179517 p->eType = (u8)eType;
179518 p->jnFlags = 0;
 
179519 p->n = n;
179520 p->u.zJContent = zContent;
179521 return pParse->nNode++;
179522 }
179523
@@ -179390,10 +179979,29 @@
179979 zFuncName);
179980 sqlite3_result_error(pCtx, zMsg, -1);
179981 sqlite3_free(zMsg);
179982 }
179983
179984 /*
179985 ** Mark all NULL entries in the Object passed in as JNODE_REMOVE.
179986 */
179987 static void jsonRemoveAllNulls(JsonNode *pNode){
179988 int i, n;
179989 assert( pNode->eType==JSON_OBJECT );
179990 n = pNode->n;
179991 for(i=2; i<=n; i += jsonNodeSize(&pNode[i])+1){
179992 switch( pNode[i].eType ){
179993 case JSON_NULL:
179994 pNode[i].jnFlags |= JNODE_REMOVE;
179995 break;
179996 case JSON_OBJECT:
179997 jsonRemoveAllNulls(&pNode[i]);
179998 break;
179999 }
180000 }
180001 }
180002
180003
180004 /****************************************************************************
180005 ** SQL functions used for testing and debugging
180006 ****************************************************************************/
180007
@@ -179581,10 +180189,109 @@
180189 sqlite3_result_subtype(ctx, JSON_SUBTYPE);
180190 }
180191 jsonReset(&jx);
180192 jsonParseReset(&x);
180193 }
180194
180195 /* This is the RFC 7396 MergePatch algorithm.
180196 */
180197 static JsonNode *jsonMergePatch(
180198 JsonParse *pParse, /* The JSON parser that contains the TARGET */
180199 int iTarget, /* Node of the TARGET in pParse */
180200 JsonNode *pPatch /* The PATCH */
180201 ){
180202 u32 i, j;
180203 u32 iRoot;
180204 JsonNode *pTarget;
180205 if( pPatch->eType!=JSON_OBJECT ){
180206 return pPatch;
180207 }
180208 assert( iTarget>=0 && iTarget<pParse->nNode );
180209 pTarget = &pParse->aNode[iTarget];
180210 assert( (pPatch->jnFlags & JNODE_APPEND)==0 );
180211 if( pTarget->eType!=JSON_OBJECT ){
180212 jsonRemoveAllNulls(pPatch);
180213 return pPatch;
180214 }
180215 iRoot = iTarget;
180216 for(i=1; i<pPatch->n; i += jsonNodeSize(&pPatch[i+1])+1){
180217 u32 nKey;
180218 const char *zKey;
180219 assert( pPatch[i].eType==JSON_STRING );
180220 assert( pPatch[i].jnFlags & JNODE_LABEL );
180221 nKey = pPatch[i].n;
180222 zKey = pPatch[i].u.zJContent;
180223 assert( (pPatch[i].jnFlags & JNODE_RAW)==0 );
180224 for(j=1; j<pTarget->n; j += jsonNodeSize(&pTarget[j+1])+1 ){
180225 assert( pTarget[j].eType==JSON_STRING );
180226 assert( pTarget[j].jnFlags & JNODE_LABEL );
180227 assert( (pPatch[i].jnFlags & JNODE_RAW)==0 );
180228 if( pTarget[j].n==nKey && strncmp(pTarget[j].u.zJContent,zKey,nKey)==0 ){
180229 if( pTarget[j+1].jnFlags & (JNODE_REMOVE|JNODE_PATCH) ) break;
180230 if( pPatch[i+1].eType==JSON_NULL ){
180231 pTarget[j+1].jnFlags |= JNODE_REMOVE;
180232 }else{
180233 JsonNode *pNew = jsonMergePatch(pParse, iTarget+j+1, &pPatch[i+1]);
180234 if( pNew==0 ) return 0;
180235 pTarget = &pParse->aNode[iTarget];
180236 if( pNew!=&pTarget[j+1] ){
180237 pTarget[j+1].u.pPatch = pNew;
180238 pTarget[j+1].jnFlags |= JNODE_PATCH;
180239 }
180240 }
180241 break;
180242 }
180243 }
180244 if( j>=pTarget->n && pPatch[i+1].eType!=JSON_NULL ){
180245 int iStart, iPatch;
180246 iStart = jsonParseAddNode(pParse, JSON_OBJECT, 2, 0);
180247 jsonParseAddNode(pParse, JSON_STRING, nKey, zKey);
180248 iPatch = jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
180249 if( pParse->oom ) return 0;
180250 jsonRemoveAllNulls(pPatch);
180251 pTarget = &pParse->aNode[iTarget];
180252 pParse->aNode[iRoot].jnFlags |= JNODE_APPEND;
180253 pParse->aNode[iRoot].u.iAppend = iStart - iRoot;
180254 iRoot = iStart;
180255 pParse->aNode[iPatch].jnFlags |= JNODE_PATCH;
180256 pParse->aNode[iPatch].u.pPatch = &pPatch[i+1];
180257 }
180258 }
180259 return pTarget;
180260 }
180261
180262 /*
180263 ** Implementation of the json_mergepatch(JSON1,JSON2) function. Return a JSON
180264 ** object that is the result of running the RFC 7396 MergePatch() algorithm
180265 ** on the two arguments.
180266 */
180267 static void jsonPatchFunc(
180268 sqlite3_context *ctx,
180269 int argc,
180270 sqlite3_value **argv
180271 ){
180272 JsonParse x; /* The JSON that is being patched */
180273 JsonParse y; /* The patch */
180274 JsonNode *pResult; /* The result of the merge */
180275
180276 UNUSED_PARAM(argc);
180277 if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return;
180278 if( jsonParse(&y, ctx, (const char*)sqlite3_value_text(argv[1])) ){
180279 jsonParseReset(&x);
180280 return;
180281 }
180282 pResult = jsonMergePatch(&x, 0, y.aNode);
180283 assert( pResult!=0 || x.oom );
180284 if( pResult ){
180285 jsonReturnJson(pResult, ctx, 0);
180286 }else{
180287 sqlite3_result_error_nomem(ctx);
180288 }
180289 jsonParseReset(&x);
180290 jsonParseReset(&y);
180291 }
180292
180293
180294 /*
180295 ** Implementation of the json_object(NAME,VALUE,...) function. Return a JSON
180296 ** object that contains all name/value given in arguments. Or if any name
180297 ** is not a string or if any value is a BLOB, throw an error.
@@ -179685,15 +180392,15 @@
180392 zPath = (const char*)sqlite3_value_text(argv[i]);
180393 pNode = jsonLookup(&x, zPath, 0, ctx);
180394 if( x.nErr ) goto replace_err;
180395 if( pNode ){
180396 pNode->jnFlags |= (u8)JNODE_REPLACE;
180397 pNode->u.iReplace = i + 1;
180398 }
180399 }
180400 if( x.aNode[0].jnFlags & JNODE_REPLACE ){
180401 sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]);
180402 }else{
180403 jsonReturnJson(x.aNode, ctx, argv);
180404 }
180405 replace_err:
180406 jsonParseReset(&x);
@@ -179739,15 +180446,15 @@
180446 goto jsonSetDone;
180447 }else if( x.nErr ){
180448 goto jsonSetDone;
180449 }else if( pNode && (bApnd || bIsSet) ){
180450 pNode->jnFlags |= (u8)JNODE_REPLACE;
180451 pNode->u.iReplace = i + 1;
180452 }
180453 }
180454 if( x.aNode[0].jnFlags & JNODE_REPLACE ){
180455 sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]);
180456 }else{
180457 jsonReturnJson(x.aNode, ctx, argv);
180458 }
180459 jsonSetDone:
180460 jsonParseReset(&x);
@@ -180386,10 +181093,11 @@
181093 { "json_array_length", 1, 0, jsonArrayLengthFunc },
181094 { "json_array_length", 2, 0, jsonArrayLengthFunc },
181095 { "json_extract", -1, 0, jsonExtractFunc },
181096 { "json_insert", -1, 0, jsonSetFunc },
181097 { "json_object", -1, 0, jsonObjectFunc },
181098 { "json_patch", 2, 0, jsonPatchFunc },
181099 { "json_quote", 1, 0, jsonQuoteFunc },
181100 { "json_remove", -1, 0, jsonRemoveFunc },
181101 { "json_replace", -1, 0, jsonReplaceFunc },
181102 { "json_set", -1, 1, jsonSetFunc },
181103 { "json_type", 1, 0, jsonTypeFunc },
@@ -181079,11 +181787,13 @@
181787 typedef unsigned short u16;
181788 typedef short i16;
181789 typedef sqlite3_int64 i64;
181790 typedef sqlite3_uint64 u64;
181791
181792 #ifndef ArraySize
181793 # define ArraySize(x) ((int)(sizeof(x) / sizeof(x[0])))
181794 #endif
181795
181796 #define testcase(x)
181797 #define ALWAYS(x) 1
181798 #define NEVER(x) 0
181799
@@ -186302,11 +187012,14 @@
187012 if( p1->bEof==0 ){
187013 if( (p1->iRowid==iLast)
187014 || (bFromValid && fts5RowidCmp(pExpr, p1->iRowid, iFrom)<0)
187015 ){
187016 int rc = fts5ExprNodeNext(pExpr, p1, bFromValid, iFrom);
187017 if( rc!=SQLITE_OK ){
187018 pNode->bNomatch = 0;
187019 return rc;
187020 }
187021 }
187022 }
187023 }
187024
187025 fts5ExprNodeTest_OR(pExpr, pNode);
@@ -186333,11 +187046,14 @@
187046 Fts5ExprNode *pChild = pAnd->apChild[iChild];
187047 int cmp = fts5RowidCmp(pExpr, iLast, pChild->iRowid);
187048 if( cmp>0 ){
187049 /* Advance pChild until it points to iLast or laster */
187050 rc = fts5ExprNodeNext(pExpr, pChild, 1, iLast);
187051 if( rc!=SQLITE_OK ){
187052 pAnd->bNomatch = 0;
187053 return rc;
187054 }
187055 }
187056
187057 /* If the child node is now at EOF, so is the parent AND node. Otherwise,
187058 ** the child node is guaranteed to have advanced at least as far as
187059 ** rowid iLast. So if it is not at exactly iLast, pChild->iRowid is the
@@ -186372,10 +187088,12 @@
187088 i64 iFrom
187089 ){
187090 int rc = fts5ExprNodeNext(pExpr, pNode->apChild[0], bFromValid, iFrom);
187091 if( rc==SQLITE_OK ){
187092 rc = fts5ExprNodeTest_AND(pExpr, pNode);
187093 }else{
187094 pNode->bNomatch = 0;
187095 }
187096 return rc;
187097 }
187098
187099 static int fts5ExprNodeTest_NOT(
@@ -186414,10 +187132,13 @@
187132 ){
187133 int rc = fts5ExprNodeNext(pExpr, pNode->apChild[0], bFromValid, iFrom);
187134 if( rc==SQLITE_OK ){
187135 rc = fts5ExprNodeTest_NOT(pExpr, pNode);
187136 }
187137 if( rc!=SQLITE_OK ){
187138 pNode->bNomatch = 0;
187139 }
187140 return rc;
187141 }
187142
187143 /*
187144 ** If pNode currently points to a match, this function returns SQLITE_OK
@@ -197534,11 +198255,11 @@
198255 int nArg, /* Number of args */
198256 sqlite3_value **apUnused /* Function arguments */
198257 ){
198258 assert( nArg==0 );
198259 UNUSED_PARAM2(nArg, apUnused);
198260 sqlite3_result_text(pCtx, "fts5: 2017-03-28 18:48:43 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37", -1, SQLITE_TRANSIENT);
198261 }
198262
198263 static int fts5Init(sqlite3 *db){
198264 static const sqlite3_module fts5Mod = {
198265 /* iVersion */ 2,
@@ -198197,15 +198918,10 @@
198918 sqlite3_step(pDel);
198919 rc = sqlite3_reset(pDel);
198920 }
198921 }
198922
 
 
 
 
 
198923 return rc;
198924 }
198925
198926 /*
198927 ** Delete all entries in the FTS5 index.
@@ -198405,15 +199121,10 @@
199121 if( rc==SQLITE_OK ){
199122 rc = fts5StorageInsertDocsize(p, iRowid, &buf);
199123 }
199124 sqlite3_free(buf.p);
199125
 
 
 
 
 
199126 return rc;
199127 }
199128
199129 static int fts5StorageCount(Fts5Storage *p, const char *zSuffix, i64 *pnRow){
199130 Fts5Config *pConfig = p->pConfig;
@@ -198744,16 +199455,21 @@
199455
199456 /*
199457 ** Flush any data currently held in-memory to disk.
199458 */
199459 static int sqlite3Fts5StorageSync(Fts5Storage *p, int bCommit){
199460 int rc = SQLITE_OK;
199461 i64 iLastRowid = sqlite3_last_insert_rowid(p->pConfig->db);
199462 if( p->bTotalsValid ){
199463 rc = fts5StorageSaveTotals(p);
199464 if( bCommit ) p->bTotalsValid = 0;
199465 }
199466 if( rc==SQLITE_OK ){
199467 rc = sqlite3Fts5IndexSync(p->pIndex, bCommit);
199468 }
199469 sqlite3_set_last_insert_rowid(p->pConfig->db, iLastRowid);
199470 return rc;
199471 }
199472
199473 static int sqlite3Fts5StorageRollback(Fts5Storage *p){
199474 p->bTotalsValid = 0;
199475 return sqlite3Fts5IndexRollback(p->pIndex);
199476
+42 -21
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -112,20 +112,20 @@
112112
** SQLite source code has been stored in the
113113
** <a href="http://www.fossil-scm.org/">Fossil configuration management
114114
** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
115115
** a string which identifies a particular check-in of SQLite
116116
** within its configuration management system. ^The SQLITE_SOURCE_ID
117
-** string contains the date and time of the check-in (UTC) and an SHA1
118
-** hash of the entire source tree.
117
+** string contains the date and time of the check-in (UTC) and a SHA1
118
+** or SHA3-256 hash of the entire source tree.
119119
**
120120
** See also: [sqlite3_libversion()],
121121
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122122
** [sqlite_version()] and [sqlite_source_id()].
123123
*/
124
-#define SQLITE_VERSION "3.17.0"
125
-#define SQLITE_VERSION_NUMBER 3017000
126
-#define SQLITE_SOURCE_ID "2017-02-13 16:02:40 ada05cfa86ad7f5645450ac7a2a21c9aa6e57d2c"
124
+#define SQLITE_VERSION "3.18.0"
125
+#define SQLITE_VERSION_NUMBER 3018000
126
+#define SQLITE_SOURCE_ID "2017-03-28 18:48:43 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37"
127127
128128
/*
129129
** CAPI3REF: Run-Time Library Version Numbers
130130
** KEYWORDS: sqlite3_version sqlite3_sourceid
131131
**
@@ -2038,24 +2038,34 @@
20382038
** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
20392039
** names are not also used by explicitly declared columns. ^If
20402040
** the table has a column of type [INTEGER PRIMARY KEY] then that column
20412041
** is another alias for the rowid.
20422042
**
2043
-** ^The sqlite3_last_insert_rowid(D) interface returns the [rowid] of the
2044
-** most recent successful [INSERT] into a rowid table or [virtual table]
2045
-** on database connection D.
2046
-** ^Inserts into [WITHOUT ROWID] tables are not recorded.
2047
-** ^If no successful [INSERT]s into rowid tables
2048
-** have ever occurred on the database connection D,
2049
-** then sqlite3_last_insert_rowid(D) returns zero.
2043
+** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of
2044
+** the most recent successful [INSERT] into a rowid table or [virtual table]
2045
+** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not
2046
+** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred
2047
+** on the database connection D, then sqlite3_last_insert_rowid(D) returns
2048
+** zero.
20502049
**
2051
-** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
2052
-** method, then this routine will return the [rowid] of the inserted
2053
-** row as long as the trigger or virtual table method is running.
2054
-** But once the trigger or virtual table method ends, the value returned
2055
-** by this routine reverts to what it was before the trigger or virtual
2056
-** table method began.)^
2050
+** As well as being set automatically as rows are inserted into database
2051
+** tables, the value returned by this function may be set explicitly by
2052
+** [sqlite3_set_last_insert_rowid()]
2053
+**
2054
+** Some virtual table implementations may INSERT rows into rowid tables as
2055
+** part of committing a transaction (e.g. to flush data accumulated in memory
2056
+** to disk). In this case subsequent calls to this function return the rowid
2057
+** associated with these internal INSERT operations, which leads to
2058
+** unintuitive results. Virtual table implementations that do write to rowid
2059
+** tables in this way can avoid this problem by restoring the original
2060
+** rowid value using [sqlite3_set_last_insert_rowid()] before returning
2061
+** control to the user.
2062
+**
2063
+** ^(If an [INSERT] occurs within a trigger then this routine will
2064
+** return the [rowid] of the inserted row as long as the trigger is
2065
+** running. Once the trigger program ends, the value returned
2066
+** by this routine reverts to what it was before the trigger was fired.)^
20572067
**
20582068
** ^An [INSERT] that fails due to a constraint violation is not a
20592069
** successful [INSERT] and does not change the value returned by this
20602070
** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
20612071
** and INSERT OR ABORT make no changes to the return value of this
@@ -2078,10 +2088,20 @@
20782088
** unpredictable and might not equal either the old or the new
20792089
** last insert [rowid].
20802090
*/
20812091
SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
20822092
2093
+/*
2094
+** CAPI3REF: Set the Last Insert Rowid value.
2095
+** METHOD: sqlite3
2096
+**
2097
+** The sqlite3_set_last_insert_rowid(D, R) method allows the application to
2098
+** set the value returned by calling sqlite3_last_insert_rowid(D) to R
2099
+** without inserting a row into the database.
2100
+*/
2101
+SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);
2102
+
20832103
/*
20842104
** CAPI3REF: Count The Number Of Rows Modified
20852105
** METHOD: sqlite3
20862106
**
20872107
** ^This function returns the number of rows modified, inserted or
@@ -3402,13 +3422,13 @@
34023422
** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
34033423
** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
34043424
**
34053425
** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
34063426
** <dd>The maximum number of instructions in a virtual machine program
3407
-** used to implement an SQL statement. This limit is not currently
3408
-** enforced, though that might be added in some future release of
3409
-** SQLite.</dd>)^
3427
+** used to implement an SQL statement. If [sqlite3_prepare_v2()] or
3428
+** the equivalent tries to allocate space for more than this many opcodes
3429
+** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^
34103430
**
34113431
** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
34123432
** <dd>The maximum number of arguments on a function.</dd>)^
34133433
**
34143434
** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
@@ -3441,10 +3461,11 @@
34413461
#define SQLITE_LIMIT_ATTACHED 7
34423462
#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
34433463
#define SQLITE_LIMIT_VARIABLE_NUMBER 9
34443464
#define SQLITE_LIMIT_TRIGGER_DEPTH 10
34453465
#define SQLITE_LIMIT_WORKER_THREADS 11
3466
+
34463467
34473468
/*
34483469
** CAPI3REF: Compiling An SQL Statement
34493470
** KEYWORDS: {SQL statement compiler}
34503471
** METHOD: sqlite3
34513472
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -112,20 +112,20 @@
112 ** SQLite source code has been stored in the
113 ** <a href="http://www.fossil-scm.org/">Fossil configuration management
114 ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
115 ** a string which identifies a particular check-in of SQLite
116 ** within its configuration management system. ^The SQLITE_SOURCE_ID
117 ** string contains the date and time of the check-in (UTC) and an SHA1
118 ** hash of the entire source tree.
119 **
120 ** See also: [sqlite3_libversion()],
121 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122 ** [sqlite_version()] and [sqlite_source_id()].
123 */
124 #define SQLITE_VERSION "3.17.0"
125 #define SQLITE_VERSION_NUMBER 3017000
126 #define SQLITE_SOURCE_ID "2017-02-13 16:02:40 ada05cfa86ad7f5645450ac7a2a21c9aa6e57d2c"
127
128 /*
129 ** CAPI3REF: Run-Time Library Version Numbers
130 ** KEYWORDS: sqlite3_version sqlite3_sourceid
131 **
@@ -2038,24 +2038,34 @@
2038 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
2039 ** names are not also used by explicitly declared columns. ^If
2040 ** the table has a column of type [INTEGER PRIMARY KEY] then that column
2041 ** is another alias for the rowid.
2042 **
2043 ** ^The sqlite3_last_insert_rowid(D) interface returns the [rowid] of the
2044 ** most recent successful [INSERT] into a rowid table or [virtual table]
2045 ** on database connection D.
2046 ** ^Inserts into [WITHOUT ROWID] tables are not recorded.
2047 ** ^If no successful [INSERT]s into rowid tables
2048 ** have ever occurred on the database connection D,
2049 ** then sqlite3_last_insert_rowid(D) returns zero.
2050 **
2051 ** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
2052 ** method, then this routine will return the [rowid] of the inserted
2053 ** row as long as the trigger or virtual table method is running.
2054 ** But once the trigger or virtual table method ends, the value returned
2055 ** by this routine reverts to what it was before the trigger or virtual
2056 ** table method began.)^
 
 
 
 
 
 
 
 
 
 
 
2057 **
2058 ** ^An [INSERT] that fails due to a constraint violation is not a
2059 ** successful [INSERT] and does not change the value returned by this
2060 ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
2061 ** and INSERT OR ABORT make no changes to the return value of this
@@ -2078,10 +2088,20 @@
2078 ** unpredictable and might not equal either the old or the new
2079 ** last insert [rowid].
2080 */
2081 SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
2082
 
 
 
 
 
 
 
 
 
 
2083 /*
2084 ** CAPI3REF: Count The Number Of Rows Modified
2085 ** METHOD: sqlite3
2086 **
2087 ** ^This function returns the number of rows modified, inserted or
@@ -3402,13 +3422,13 @@
3402 ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
3403 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
3404 **
3405 ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
3406 ** <dd>The maximum number of instructions in a virtual machine program
3407 ** used to implement an SQL statement. This limit is not currently
3408 ** enforced, though that might be added in some future release of
3409 ** SQLite.</dd>)^
3410 **
3411 ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
3412 ** <dd>The maximum number of arguments on a function.</dd>)^
3413 **
3414 ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
@@ -3441,10 +3461,11 @@
3441 #define SQLITE_LIMIT_ATTACHED 7
3442 #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
3443 #define SQLITE_LIMIT_VARIABLE_NUMBER 9
3444 #define SQLITE_LIMIT_TRIGGER_DEPTH 10
3445 #define SQLITE_LIMIT_WORKER_THREADS 11
 
3446
3447 /*
3448 ** CAPI3REF: Compiling An SQL Statement
3449 ** KEYWORDS: {SQL statement compiler}
3450 ** METHOD: sqlite3
3451
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -112,20 +112,20 @@
112 ** SQLite source code has been stored in the
113 ** <a href="http://www.fossil-scm.org/">Fossil configuration management
114 ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
115 ** a string which identifies a particular check-in of SQLite
116 ** within its configuration management system. ^The SQLITE_SOURCE_ID
117 ** string contains the date and time of the check-in (UTC) and a SHA1
118 ** or SHA3-256 hash of the entire source tree.
119 **
120 ** See also: [sqlite3_libversion()],
121 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122 ** [sqlite_version()] and [sqlite_source_id()].
123 */
124 #define SQLITE_VERSION "3.18.0"
125 #define SQLITE_VERSION_NUMBER 3018000
126 #define SQLITE_SOURCE_ID "2017-03-28 18:48:43 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37"
127
128 /*
129 ** CAPI3REF: Run-Time Library Version Numbers
130 ** KEYWORDS: sqlite3_version sqlite3_sourceid
131 **
@@ -2038,24 +2038,34 @@
2038 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
2039 ** names are not also used by explicitly declared columns. ^If
2040 ** the table has a column of type [INTEGER PRIMARY KEY] then that column
2041 ** is another alias for the rowid.
2042 **
2043 ** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of
2044 ** the most recent successful [INSERT] into a rowid table or [virtual table]
2045 ** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not
2046 ** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred
2047 ** on the database connection D, then sqlite3_last_insert_rowid(D) returns
2048 ** zero.
 
2049 **
2050 ** As well as being set automatically as rows are inserted into database
2051 ** tables, the value returned by this function may be set explicitly by
2052 ** [sqlite3_set_last_insert_rowid()]
2053 **
2054 ** Some virtual table implementations may INSERT rows into rowid tables as
2055 ** part of committing a transaction (e.g. to flush data accumulated in memory
2056 ** to disk). In this case subsequent calls to this function return the rowid
2057 ** associated with these internal INSERT operations, which leads to
2058 ** unintuitive results. Virtual table implementations that do write to rowid
2059 ** tables in this way can avoid this problem by restoring the original
2060 ** rowid value using [sqlite3_set_last_insert_rowid()] before returning
2061 ** control to the user.
2062 **
2063 ** ^(If an [INSERT] occurs within a trigger then this routine will
2064 ** return the [rowid] of the inserted row as long as the trigger is
2065 ** running. Once the trigger program ends, the value returned
2066 ** by this routine reverts to what it was before the trigger was fired.)^
2067 **
2068 ** ^An [INSERT] that fails due to a constraint violation is not a
2069 ** successful [INSERT] and does not change the value returned by this
2070 ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
2071 ** and INSERT OR ABORT make no changes to the return value of this
@@ -2078,10 +2088,20 @@
2088 ** unpredictable and might not equal either the old or the new
2089 ** last insert [rowid].
2090 */
2091 SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
2092
2093 /*
2094 ** CAPI3REF: Set the Last Insert Rowid value.
2095 ** METHOD: sqlite3
2096 **
2097 ** The sqlite3_set_last_insert_rowid(D, R) method allows the application to
2098 ** set the value returned by calling sqlite3_last_insert_rowid(D) to R
2099 ** without inserting a row into the database.
2100 */
2101 SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);
2102
2103 /*
2104 ** CAPI3REF: Count The Number Of Rows Modified
2105 ** METHOD: sqlite3
2106 **
2107 ** ^This function returns the number of rows modified, inserted or
@@ -3402,13 +3422,13 @@
3422 ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
3423 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
3424 **
3425 ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
3426 ** <dd>The maximum number of instructions in a virtual machine program
3427 ** used to implement an SQL statement. If [sqlite3_prepare_v2()] or
3428 ** the equivalent tries to allocate space for more than this many opcodes
3429 ** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^
3430 **
3431 ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
3432 ** <dd>The maximum number of arguments on a function.</dd>)^
3433 **
3434 ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
@@ -3441,10 +3461,11 @@
3461 #define SQLITE_LIMIT_ATTACHED 7
3462 #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
3463 #define SQLITE_LIMIT_VARIABLE_NUMBER 9
3464 #define SQLITE_LIMIT_TRIGGER_DEPTH 10
3465 #define SQLITE_LIMIT_WORKER_THREADS 11
3466
3467
3468 /*
3469 ** CAPI3REF: Compiling An SQL Statement
3470 ** KEYWORDS: {SQL statement compiler}
3471 ** METHOD: sqlite3
3472

Keyboard Shortcuts

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