Fossil SCM

Update the built-in SQLite to the latest 3.16.0 alpha for testing.

drh 2016-12-08 20:03 UTC trunk
Commit 814dfd5a9cb4caa6b8c7b62dbecf4039c7f0bb52
3 files changed +5 -5 +810 -479 +57 -6
+5 -5
--- src/shell.c
+++ src/shell.c
@@ -2581,11 +2581,11 @@
25812581
}
25822582
}
25832583
return f;
25842584
}
25852585
2586
-#if !defined(SQLITE_OMIT_BUILTIN_TEST)
2586
+#if !defined(SQLITE_UNTESTABLE)
25872587
#if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
25882588
/*
25892589
** A routine for handling output from sqlite3_trace().
25902590
*/
25912591
static int sql_trace_callback(
@@ -3857,11 +3857,11 @@
38573857
"Error: querying sqlite_master and sqlite_temp_master\n");
38583858
rc = 1;
38593859
}
38603860
}else
38613861
3862
-#ifndef SQLITE_OMIT_BUILTIN_TEST
3862
+#ifndef SQLITE_UNTESTABLE
38633863
if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
38643864
char *zSql;
38653865
char *zCollist = 0;
38663866
sqlite3_stmt *pStmt;
38673867
int tnum = 0;
@@ -4077,11 +4077,11 @@
40774077
p->mode = MODE_Ascii;
40784078
sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Unit);
40794079
sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Record);
40804080
}else {
40814081
raw_printf(stderr, "Error: mode should be one of: "
4082
- "ascii column csv html insert line list tabs tcl\n");
4082
+ "ascii column csv html insert line list quote tabs tcl\n");
40834083
rc = 1;
40844084
}
40854085
p->cMode = p->mode;
40864086
}else
40874087
@@ -4793,11 +4793,11 @@
47934793
}else{
47944794
sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
47954795
}
47964796
}else
47974797
4798
-#ifndef SQLITE_OMIT_BUILTIN_TEST
4798
+#ifndef SQLITE_UNTESTABLE
47994799
if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 && nArg>=2 ){
48004800
static const struct {
48014801
const char *zCtrlName; /* Name of a test-control option */
48024802
int ctrlCode; /* Integer code for that option */
48034803
} aCtrl[] = {
@@ -4969,11 +4969,11 @@
49694969
}else{
49704970
sqlite3_trace_v2(p->db, SQLITE_TRACE_STMT, sql_trace_callback,p->traceOut);
49714971
}
49724972
#endif
49734973
}else
4974
-#endif /* !defined(SQLITE_OMIT_BUILTIN_TEST) */
4974
+#endif /* !defined(SQLITE_UNTESTABLE) */
49754975
49764976
#if SQLITE_USER_AUTHENTICATION
49774977
if( c=='u' && strncmp(azArg[0], "user", n)==0 ){
49784978
if( nArg<2 ){
49794979
raw_printf(stderr, "Usage: .user SUBCOMMAND ...\n");
49804980
--- src/shell.c
+++ src/shell.c
@@ -2581,11 +2581,11 @@
2581 }
2582 }
2583 return f;
2584 }
2585
2586 #if !defined(SQLITE_OMIT_BUILTIN_TEST)
2587 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
2588 /*
2589 ** A routine for handling output from sqlite3_trace().
2590 */
2591 static int sql_trace_callback(
@@ -3857,11 +3857,11 @@
3857 "Error: querying sqlite_master and sqlite_temp_master\n");
3858 rc = 1;
3859 }
3860 }else
3861
3862 #ifndef SQLITE_OMIT_BUILTIN_TEST
3863 if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
3864 char *zSql;
3865 char *zCollist = 0;
3866 sqlite3_stmt *pStmt;
3867 int tnum = 0;
@@ -4077,11 +4077,11 @@
4077 p->mode = MODE_Ascii;
4078 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Unit);
4079 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Record);
4080 }else {
4081 raw_printf(stderr, "Error: mode should be one of: "
4082 "ascii column csv html insert line list tabs tcl\n");
4083 rc = 1;
4084 }
4085 p->cMode = p->mode;
4086 }else
4087
@@ -4793,11 +4793,11 @@
4793 }else{
4794 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
4795 }
4796 }else
4797
4798 #ifndef SQLITE_OMIT_BUILTIN_TEST
4799 if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 && nArg>=2 ){
4800 static const struct {
4801 const char *zCtrlName; /* Name of a test-control option */
4802 int ctrlCode; /* Integer code for that option */
4803 } aCtrl[] = {
@@ -4969,11 +4969,11 @@
4969 }else{
4970 sqlite3_trace_v2(p->db, SQLITE_TRACE_STMT, sql_trace_callback,p->traceOut);
4971 }
4972 #endif
4973 }else
4974 #endif /* !defined(SQLITE_OMIT_BUILTIN_TEST) */
4975
4976 #if SQLITE_USER_AUTHENTICATION
4977 if( c=='u' && strncmp(azArg[0], "user", n)==0 ){
4978 if( nArg<2 ){
4979 raw_printf(stderr, "Usage: .user SUBCOMMAND ...\n");
4980
--- src/shell.c
+++ src/shell.c
@@ -2581,11 +2581,11 @@
2581 }
2582 }
2583 return f;
2584 }
2585
2586 #if !defined(SQLITE_UNTESTABLE)
2587 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
2588 /*
2589 ** A routine for handling output from sqlite3_trace().
2590 */
2591 static int sql_trace_callback(
@@ -3857,11 +3857,11 @@
3857 "Error: querying sqlite_master and sqlite_temp_master\n");
3858 rc = 1;
3859 }
3860 }else
3861
3862 #ifndef SQLITE_UNTESTABLE
3863 if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
3864 char *zSql;
3865 char *zCollist = 0;
3866 sqlite3_stmt *pStmt;
3867 int tnum = 0;
@@ -4077,11 +4077,11 @@
4077 p->mode = MODE_Ascii;
4078 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Unit);
4079 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Record);
4080 }else {
4081 raw_printf(stderr, "Error: mode should be one of: "
4082 "ascii column csv html insert line list quote tabs tcl\n");
4083 rc = 1;
4084 }
4085 p->cMode = p->mode;
4086 }else
4087
@@ -4793,11 +4793,11 @@
4793 }else{
4794 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
4795 }
4796 }else
4797
4798 #ifndef SQLITE_UNTESTABLE
4799 if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 && nArg>=2 ){
4800 static const struct {
4801 const char *zCtrlName; /* Name of a test-control option */
4802 int ctrlCode; /* Integer code for that option */
4803 } aCtrl[] = {
@@ -4969,11 +4969,11 @@
4969 }else{
4970 sqlite3_trace_v2(p->db, SQLITE_TRACE_STMT, sql_trace_callback,p->traceOut);
4971 }
4972 #endif
4973 }else
4974 #endif /* !defined(SQLITE_UNTESTABLE) */
4975
4976 #if SQLITE_USER_AUTHENTICATION
4977 if( c=='u' && strncmp(azArg[0], "user", n)==0 ){
4978 if( nArg<2 ){
4979 raw_printf(stderr, "Usage: .user SUBCOMMAND ...\n");
4980
+810 -479
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -381,11 +381,11 @@
381381
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
382382
** [sqlite_version()] and [sqlite_source_id()].
383383
*/
384384
#define SQLITE_VERSION "3.16.0"
385385
#define SQLITE_VERSION_NUMBER 3016000
386
-#define SQLITE_SOURCE_ID "2016-11-22 20:29:05 bee2859b953c935c413de2917588159d03c672d9"
386
+#define SQLITE_SOURCE_ID "2016-12-08 19:04:36 b26df26e184ec6da4b5537526c10f42a293d09b5"
387387
388388
/*
389389
** CAPI3REF: Run-Time Library Version Numbers
390390
** KEYWORDS: sqlite3_version sqlite3_sourceid
391391
**
@@ -3868,10 +3868,14 @@
38683868
** rather they control the timing of when other statements modify the
38693869
** database. ^The [ATTACH] and [DETACH] statements also cause
38703870
** sqlite3_stmt_readonly() to return true since, while those statements
38713871
** change the configuration of a database connection, they do not make
38723872
** changes to the content of the database files on disk.
3873
+** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
3874
+** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
3875
+** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
3876
+** sqlite3_stmt_readonly() returns false for those commands.
38733877
*/
38743878
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
38753879
38763880
/*
38773881
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
@@ -8517,11 +8521,11 @@
85178521
*/
85188522
SQLITE_API int sqlite3_system_errno(sqlite3*);
85198523
85208524
/*
85218525
** CAPI3REF: Database Snapshot
8522
-** KEYWORDS: {snapshot}
8526
+** KEYWORDS: {snapshot} {sqlite3_snapshot}
85238527
** EXPERIMENTAL
85248528
**
85258529
** An instance of the snapshot object records the state of a [WAL mode]
85268530
** database for some specific point in history.
85278531
**
@@ -8541,11 +8545,13 @@
85418545
** The constructor for this object is [sqlite3_snapshot_get()]. The
85428546
** [sqlite3_snapshot_open()] method causes a fresh read transaction to refer
85438547
** to an historical snapshot (if possible). The destructor for
85448548
** sqlite3_snapshot objects is [sqlite3_snapshot_free()].
85458549
*/
8546
-typedef struct sqlite3_snapshot sqlite3_snapshot;
8550
+typedef struct sqlite3_snapshot {
8551
+ unsigned char hidden[48];
8552
+} sqlite3_snapshot;
85478553
85488554
/*
85498555
** CAPI3REF: Record A Database Snapshot
85508556
** EXPERIMENTAL
85518557
**
@@ -8552,13 +8558,36 @@
85528558
** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a
85538559
** new [sqlite3_snapshot] object that records the current state of
85548560
** schema S in database connection D. ^On success, the
85558561
** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly
85568562
** created [sqlite3_snapshot] object into *P and returns SQLITE_OK.
8557
-** ^If schema S of [database connection] D is not a [WAL mode] database
8558
-** that is in a read transaction, then [sqlite3_snapshot_get(D,S,P)]
8559
-** leaves the *P value unchanged and returns an appropriate [error code].
8563
+** If there is not already a read-transaction open on schema S when
8564
+** this function is called, one is opened automatically.
8565
+**
8566
+** The following must be true for this function to succeed. If any of
8567
+** the following statements are false when sqlite3_snapshot_get() is
8568
+** called, SQLITE_ERROR is returned. The final value of *P is undefined
8569
+** in this case.
8570
+**
8571
+** <ul>
8572
+** <li> The database handle must be in [autocommit mode].
8573
+**
8574
+** <li> Schema S of [database connection] D must be a [WAL mode] database.
8575
+**
8576
+** <li> There must not be a write transaction open on schema S of database
8577
+** connection D.
8578
+**
8579
+** <li> One or more transactions must have been written to the current wal
8580
+** file since it was created on disk (by any connection). This means
8581
+** that a snapshot cannot be taken on a wal mode database with no wal
8582
+** file immediately after it is first opened. At least one transaction
8583
+** must be written to it first.
8584
+** </ul>
8585
+**
8586
+** This function may also return SQLITE_NOMEM. If it is called with the
8587
+** database handle in autocommit mode but fails for some other reason,
8588
+** whether or not a read transaction is opened on schema S is undefined.
85608589
**
85618590
** The [sqlite3_snapshot] object returned from a successful call to
85628591
** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()]
85638592
** to avoid a memory leak.
85648593
**
@@ -8647,10 +8676,32 @@
86478676
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(
86488677
sqlite3_snapshot *p1,
86498678
sqlite3_snapshot *p2
86508679
);
86518680
8681
+/*
8682
+** CAPI3REF: Recover snapshots from a wal file
8683
+** EXPERIMENTAL
8684
+**
8685
+** If all connections disconnect from a database file but do not perform
8686
+** a checkpoint, the existing wal file is opened along with the database
8687
+** file the next time the database is opened. At this point it is only
8688
+** possible to successfully call sqlite3_snapshot_open() to open the most
8689
+** recent snapshot of the database (the one at the head of the wal file),
8690
+** even though the wal file may contain other valid snapshots for which
8691
+** clients have sqlite3_snapshot handles.
8692
+**
8693
+** This function attempts to scan the wal file associated with database zDb
8694
+** of database handle db and make all valid snapshots available to
8695
+** sqlite3_snapshot_open(). It is an error if there is already a read
8696
+** transaction open on the database, or if the database is not a wal mode
8697
+** database.
8698
+**
8699
+** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
8700
+*/
8701
+SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
8702
+
86528703
/*
86538704
** Undo the hack that converts floating point types to integer for
86548705
** builds on processors without floating point support.
86558706
*/
86568707
#ifdef SQLITE_OMIT_FLOATING_POINT
@@ -12323,19 +12374,19 @@
1232312374
SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
1232412375
SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
1232512376
SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
1232612377
SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
1232712378
SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
12328
-SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
12379
+SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
1232912380
SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
1233012381
SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
12331
-SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
1233212382
1233312383
SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
1233412384
SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
1233512385
1233612386
#ifndef SQLITE_OMIT_INCRBLOB
12387
+SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*);
1233712388
SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
1233812389
SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *);
1233912390
#endif
1234012391
SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *);
1234112392
SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
@@ -12518,26 +12569,25 @@
1251812569
** Allowed values of VdbeOp.p4type
1251912570
*/
1252012571
#define P4_NOTUSED 0 /* The P4 parameter is not used */
1252112572
#define P4_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */
1252212573
#define P4_STATIC (-2) /* Pointer to a static string */
12523
-#define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */
12524
-#define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */
12525
-#define P4_KEYINFO (-6) /* P4 is a pointer to a KeyInfo structure */
12526
-#define P4_EXPR (-7) /* P4 is a pointer to an Expr tree */
12527
-#define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */
12574
+#define P4_COLLSEQ (-3) /* P4 is a pointer to a CollSeq structure */
12575
+#define P4_FUNCDEF (-4) /* P4 is a pointer to a FuncDef structure */
12576
+#define P4_KEYINFO (-5) /* P4 is a pointer to a KeyInfo structure */
12577
+#define P4_EXPR (-6) /* P4 is a pointer to an Expr tree */
12578
+#define P4_MEM (-7) /* P4 is a pointer to a Mem* structure */
1252812579
#define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */
12529
-#define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */
12530
-#define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */
12531
-#define P4_REAL (-12) /* P4 is a 64-bit floating point value */
12532
-#define P4_INT64 (-13) /* P4 is a 64-bit signed integer */
12533
-#define P4_INT32 (-14) /* P4 is a 32-bit signed integer */
12534
-#define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
12535
-#define P4_SUBPROGRAM (-18) /* P4 is a pointer to a SubProgram structure */
12536
-#define P4_ADVANCE (-19) /* P4 is a pointer to BtreeNext() or BtreePrev() */
12537
-#define P4_TABLE (-20) /* P4 is a pointer to a Table structure */
12538
-#define P4_FUNCCTX (-21) /* P4 is a pointer to an sqlite3_context object */
12580
+#define P4_VTAB (-8) /* P4 is a pointer to an sqlite3_vtab structure */
12581
+#define P4_REAL (-9) /* P4 is a 64-bit floating point value */
12582
+#define P4_INT64 (-10) /* P4 is a 64-bit signed integer */
12583
+#define P4_INT32 (-11) /* P4 is a 32-bit signed integer */
12584
+#define P4_INTARRAY (-12) /* P4 is a vector of 32-bit integers */
12585
+#define P4_SUBPROGRAM (-13) /* P4 is a pointer to a SubProgram structure */
12586
+#define P4_ADVANCE (-14) /* P4 is a pointer to BtreeNext() or BtreePrev() */
12587
+#define P4_TABLE (-15) /* P4 is a pointer to a Table structure */
12588
+#define P4_FUNCCTX (-16) /* P4 is a pointer to an sqlite3_context object */
1253912589
1254012590
/* Error message codes for OP_Halt */
1254112591
#define P5_ConstraintNotNull 1
1254212592
#define P5_ConstraintUnique 2
1254312593
#define P5_ConstraintCheck 3
@@ -12697,52 +12747,51 @@
1269712747
#define OP_InsertInt 116 /* synopsis: intkey=P3 data=r[P2] */
1269812748
#define OP_Delete 117
1269912749
#define OP_ResetCount 118
1270012750
#define OP_SorterCompare 119 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
1270112751
#define OP_SorterData 120 /* synopsis: r[P2]=data */
12702
-#define OP_RowKey 121 /* synopsis: r[P2]=key */
12703
-#define OP_RowData 122 /* synopsis: r[P2]=data */
12704
-#define OP_Rowid 123 /* synopsis: r[P2]=rowid */
12705
-#define OP_NullRow 124
12706
-#define OP_SorterInsert 125 /* synopsis: key=r[P2] */
12707
-#define OP_IdxInsert 126 /* synopsis: key=r[P2] */
12708
-#define OP_IdxDelete 127 /* synopsis: key=r[P2@P3] */
12709
-#define OP_Seek 128 /* synopsis: Move P3 to P1.rowid */
12710
-#define OP_IdxRowid 129 /* synopsis: r[P2]=rowid */
12711
-#define OP_Destroy 130
12712
-#define OP_Clear 131
12752
+#define OP_RowData 121 /* synopsis: r[P2]=data */
12753
+#define OP_Rowid 122 /* synopsis: r[P2]=rowid */
12754
+#define OP_NullRow 123
12755
+#define OP_SorterInsert 124 /* synopsis: key=r[P2] */
12756
+#define OP_IdxInsert 125 /* synopsis: key=r[P2] */
12757
+#define OP_IdxDelete 126 /* synopsis: key=r[P2@P3] */
12758
+#define OP_Seek 127 /* synopsis: Move P3 to P1.rowid */
12759
+#define OP_IdxRowid 128 /* synopsis: r[P2]=rowid */
12760
+#define OP_Destroy 129
12761
+#define OP_Clear 130
12762
+#define OP_ResetSorter 131
1271312763
#define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
12714
-#define OP_ResetSorter 133
12715
-#define OP_CreateIndex 134 /* synopsis: r[P2]=root iDb=P1 */
12716
-#define OP_CreateTable 135 /* synopsis: r[P2]=root iDb=P1 */
12717
-#define OP_ParseSchema 136
12718
-#define OP_LoadAnalysis 137
12719
-#define OP_DropTable 138
12720
-#define OP_DropIndex 139
12721
-#define OP_DropTrigger 140
12722
-#define OP_IntegrityCk 141
12723
-#define OP_RowSetAdd 142 /* synopsis: rowset(P1)=r[P2] */
12724
-#define OP_Param 143
12725
-#define OP_FkCounter 144 /* synopsis: fkctr[P1]+=P2 */
12726
-#define OP_MemMax 145 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12727
-#define OP_OffsetLimit 146 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12728
-#define OP_AggStep0 147 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12729
-#define OP_AggStep 148 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12730
-#define OP_AggFinal 149 /* synopsis: accum=r[P1] N=P2 */
12731
-#define OP_Expire 150
12732
-#define OP_TableLock 151 /* synopsis: iDb=P1 root=P2 write=P3 */
12733
-#define OP_VBegin 152
12734
-#define OP_VCreate 153
12735
-#define OP_VDestroy 154
12736
-#define OP_VOpen 155
12737
-#define OP_VColumn 156 /* synopsis: r[P3]=vcolumn(P2) */
12738
-#define OP_VRename 157
12739
-#define OP_Pagecount 158
12740
-#define OP_MaxPgcnt 159
12741
-#define OP_CursorHint 160
12742
-#define OP_Noop 161
12743
-#define OP_Explain 162
12764
+#define OP_CreateIndex 133 /* synopsis: r[P2]=root iDb=P1 */
12765
+#define OP_CreateTable 134 /* synopsis: r[P2]=root iDb=P1 */
12766
+#define OP_ParseSchema 135
12767
+#define OP_LoadAnalysis 136
12768
+#define OP_DropTable 137
12769
+#define OP_DropIndex 138
12770
+#define OP_DropTrigger 139
12771
+#define OP_IntegrityCk 140
12772
+#define OP_RowSetAdd 141 /* synopsis: rowset(P1)=r[P2] */
12773
+#define OP_Param 142
12774
+#define OP_FkCounter 143 /* synopsis: fkctr[P1]+=P2 */
12775
+#define OP_MemMax 144 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12776
+#define OP_OffsetLimit 145 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12777
+#define OP_AggStep0 146 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12778
+#define OP_AggStep 147 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12779
+#define OP_AggFinal 148 /* synopsis: accum=r[P1] N=P2 */
12780
+#define OP_Expire 149
12781
+#define OP_TableLock 150 /* synopsis: iDb=P1 root=P2 write=P3 */
12782
+#define OP_VBegin 151
12783
+#define OP_VCreate 152
12784
+#define OP_VDestroy 153
12785
+#define OP_VOpen 154
12786
+#define OP_VColumn 155 /* synopsis: r[P3]=vcolumn(P2) */
12787
+#define OP_VRename 156
12788
+#define OP_Pagecount 157
12789
+#define OP_MaxPgcnt 158
12790
+#define OP_CursorHint 159
12791
+#define OP_Noop 160
12792
+#define OP_Explain 161
1274412793
1274512794
/* Properties such as "out2" or "jump" that are specified in
1274612795
** comments following the "case" for each opcode in the vdbe.c
1274712796
** are encoded into bitvectors as follows:
1274812797
*/
@@ -12766,16 +12815,16 @@
1276612815
/* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00,\
1276712816
/* 88 */ 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\
1276812817
/* 96 */ 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
1276912818
/* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
1277012819
/* 112 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
12771
-/* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00,\
12772
-/* 128 */ 0x00, 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10,\
12773
-/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10,\
12774
-/* 144 */ 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00,\
12775
-/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
12776
-/* 160 */ 0x00, 0x00, 0x00,}
12820
+/* 120 */ 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00, 0x00,\
12821
+/* 128 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00,\
12822
+/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00,\
12823
+/* 144 */ 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12824
+/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
12825
+/* 160 */ 0x00, 0x00,}
1277712826
1277812827
/* The sqlite3P2Values() routine is able to run faster if it knows
1277912828
** the value of the largest JUMP opcode. The smaller the maximum
1278012829
** JUMP opcode the better, so the mkopcodeh.tcl script that
1278112830
** generated this include file strives to group all JUMP opcodes
@@ -12816,10 +12865,11 @@
1281612865
SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
1281712866
SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
1281812867
SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
1281912868
SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
1282012869
SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
12870
+SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
1282112871
SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
1282212872
SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
1282312873
SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
1282412874
SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
1282512875
SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*);
@@ -13116,10 +13166,11 @@
1311613166
SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3*);
1311713167
SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager);
1311813168
# ifdef SQLITE_ENABLE_SNAPSHOT
1311913169
SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot);
1312013170
SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot);
13171
+SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager);
1312113172
# endif
1312213173
#else
1312313174
# define sqlite3PagerUseWal(x) 0
1312413175
#endif
1312513176
@@ -14115,17 +14166,12 @@
1411514166
#define SQLITE_AllOpts 0xffff /* All optimizations */
1411614167
1411714168
/*
1411814169
** Macros for testing whether or not optimizations are enabled or disabled.
1411914170
*/
14120
-#ifndef SQLITE_OMIT_BUILTIN_TEST
1412114171
#define OptimizationDisabled(db, mask) (((db)->dbOptFlags&(mask))!=0)
1412214172
#define OptimizationEnabled(db, mask) (((db)->dbOptFlags&(mask))==0)
14123
-#else
14124
-#define OptimizationDisabled(db, mask) 0
14125
-#define OptimizationEnabled(db, mask) 1
14126
-#endif
1412714173
1412814174
/*
1412914175
** Return true if it OK to factor constant expressions into the initialization
1413014176
** code. The argument is a Parse object for the code generator.
1413114177
*/
@@ -15891,11 +15937,11 @@
1589115937
** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE.
1589215938
*/
1589315939
void (*xVdbeBranch)(void*,int iSrcLine,u8 eThis,u8 eMx); /* Callback */
1589415940
void *pVdbeBranchArg; /* 1st argument */
1589515941
#endif
15896
-#ifndef SQLITE_OMIT_BUILTIN_TEST
15942
+#ifndef SQLITE_UNTESTABLE
1589715943
int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
1589815944
#endif
1589915945
int bLocaltimeFault; /* True to fail localtime() calls */
1590015946
int iOnceResetThreshold; /* When to reset OP_Once counters */
1590115947
};
@@ -16095,11 +16141,11 @@
1609516141
SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
1609616142
SQLITE_PRIVATE void sqlite3ScratchFree(void*);
1609716143
SQLITE_PRIVATE void *sqlite3PageMalloc(int);
1609816144
SQLITE_PRIVATE void sqlite3PageFree(void*);
1609916145
SQLITE_PRIVATE void sqlite3MemSetDefault(void);
16100
-#ifndef SQLITE_OMIT_BUILTIN_TEST
16146
+#ifndef SQLITE_UNTESTABLE
1610116147
SQLITE_PRIVATE void sqlite3BenignMallocHooks(void (*)(void), void (*)(void));
1610216148
#endif
1610316149
SQLITE_PRIVATE int sqlite3HeapNearlyFull(void);
1610416150
1610516151
/*
@@ -16206,11 +16252,11 @@
1620616252
SQLITE_PRIVATE int sqlite3NoTempsInRange(Parse*,int,int);
1620716253
#endif
1620816254
SQLITE_PRIVATE Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int);
1620916255
SQLITE_PRIVATE Expr *sqlite3Expr(sqlite3*,int,const char*);
1621016256
SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
16211
-SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
16257
+SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*);
1621216258
SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*);
1621316259
SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
1621416260
SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
1621516261
SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
1621616262
SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
@@ -16250,11 +16296,11 @@
1625016296
SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);
1625116297
SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
1625216298
sqlite3_vfs**,char**,char **);
1625316299
SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*);
1625416300
16255
-#ifdef SQLITE_OMIT_BUILTIN_TEST
16301
+#ifdef SQLITE_UNTESTABLE
1625616302
# define sqlite3FaultSim(X) SQLITE_OK
1625716303
#else
1625816304
SQLITE_PRIVATE int sqlite3FaultSim(int);
1625916305
#endif
1626016306
@@ -16263,11 +16309,11 @@
1626316309
SQLITE_PRIVATE int sqlite3BitvecTestNotNull(Bitvec*, u32);
1626416310
SQLITE_PRIVATE int sqlite3BitvecSet(Bitvec*, u32);
1626516311
SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec*, u32, void*);
1626616312
SQLITE_PRIVATE void sqlite3BitvecDestroy(Bitvec*);
1626716313
SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec*);
16268
-#ifndef SQLITE_OMIT_BUILTIN_TEST
16314
+#ifndef SQLITE_UNTESTABLE
1626916315
SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int,int*);
1627016316
#endif
1627116317
1627216318
SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3*, void*, unsigned int);
1627316319
SQLITE_PRIVATE void sqlite3RowSetClear(RowSet*);
@@ -16383,11 +16429,11 @@
1638316429
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
1638416430
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
1638516431
SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
1638616432
SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
1638716433
SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
16388
-#ifndef SQLITE_OMIT_BUILTIN_TEST
16434
+#ifndef SQLITE_UNTESTABLE
1638916435
SQLITE_PRIVATE void sqlite3PrngSaveState(void);
1639016436
SQLITE_PRIVATE void sqlite3PrngRestoreState(void);
1639116437
#endif
1639216438
SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int);
1639316439
SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int);
@@ -16811,14 +16857,14 @@
1681116857
#define SQLITE_FAULTINJECTOR_MALLOC 0
1681216858
#define SQLITE_FAULTINJECTOR_COUNT 1
1681316859
1681416860
/*
1681516861
** The interface to the code in fault.c used for identifying "benign"
16816
-** malloc failures. This is only present if SQLITE_OMIT_BUILTIN_TEST
16862
+** malloc failures. This is only present if SQLITE_UNTESTABLE
1681716863
** is not defined.
1681816864
*/
16819
-#ifndef SQLITE_OMIT_BUILTIN_TEST
16865
+#ifndef SQLITE_UNTESTABLE
1682016866
SQLITE_PRIVATE void sqlite3BeginBenignMalloc(void);
1682116867
SQLITE_PRIVATE void sqlite3EndBenignMalloc(void);
1682216868
#else
1682316869
#define sqlite3BeginBenignMalloc()
1682416870
#define sqlite3EndBenignMalloc()
@@ -16945,10 +16991,11 @@
1694516991
1694616992
SQLITE_PRIVATE int sqlite3ExprVectorSize(Expr *pExpr);
1694716993
SQLITE_PRIVATE int sqlite3ExprIsVector(Expr *pExpr);
1694816994
SQLITE_PRIVATE Expr *sqlite3VectorFieldSubexpr(Expr*, int);
1694916995
SQLITE_PRIVATE Expr *sqlite3ExprForVectorField(Parse*,Expr*,int);
16996
+SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse*, Expr*);
1695016997
1695116998
#endif /* SQLITEINT_H */
1695216999
1695317000
/************** End of sqliteInt.h *******************************************/
1695417001
/************** Begin file global.c ******************************************/
@@ -17171,11 +17218,11 @@
1717117218
#endif
1717217219
#ifdef SQLITE_VDBE_COVERAGE
1717317220
0, /* xVdbeBranch */
1717417221
0, /* pVbeBranchArg */
1717517222
#endif
17176
-#ifndef SQLITE_OMIT_BUILTIN_TEST
17223
+#ifndef SQLITE_UNTESTABLE
1717717224
0, /* xTestCallback */
1717817225
#endif
1717917226
0, /* bLocaltimeFault */
1718017227
0x7ffffffe /* iOnceResetThreshold */
1718117228
};
@@ -17467,13 +17514,10 @@
1746717514
"OMIT_BLOB_LITERAL",
1746817515
#endif
1746917516
#if SQLITE_OMIT_BTREECOUNT
1747017517
"OMIT_BTREECOUNT",
1747117518
#endif
17472
-#if SQLITE_OMIT_BUILTIN_TEST
17473
- "OMIT_BUILTIN_TEST",
17474
-#endif
1747517519
#if SQLITE_OMIT_CAST
1747617520
"OMIT_CAST",
1747717521
#endif
1747817522
#if SQLITE_OMIT_CHECK
1747917523
"OMIT_CHECK",
@@ -17631,10 +17675,13 @@
1763117675
#if SQLITE_TEST
1763217676
"TEST",
1763317677
#endif
1763417678
#if defined(SQLITE_THREADSAFE)
1763517679
"THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
17680
+#endif
17681
+#if SQLITE_UNTESTABLE
17682
+ "UNTESTABLE"
1763617683
#endif
1763717684
#if SQLITE_USE_ALLOCA
1763817685
"USE_ALLOCA",
1763917686
#endif
1764017687
#if SQLITE_USER_AUTHENTICATION
@@ -18199,11 +18246,11 @@
1819918246
SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
1820018247
SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
1820118248
SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
1820218249
SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
1820318250
SQLITE_PRIVATE void sqlite3VdbeMemCast(Mem*,u8,u8);
18204
-SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*);
18251
+SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);
1820518252
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
1820618253
SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
1820718254
SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
1820818255
SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
1820918256
SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int n);
@@ -18668,20 +18715,22 @@
1866818715
/*
1866918716
** A structure for holding a single date and time.
1867018717
*/
1867118718
typedef struct DateTime DateTime;
1867218719
struct DateTime {
18673
- sqlite3_int64 iJD; /* The julian day number times 86400000 */
18674
- int Y, M, D; /* Year, month, and day */
18675
- int h, m; /* Hour and minutes */
18676
- int tz; /* Timezone offset in minutes */
18677
- double s; /* Seconds */
18678
- char validYMD; /* True (1) if Y,M,D are valid */
18679
- char validHMS; /* True (1) if h,m,s are valid */
18680
- char validJD; /* True (1) if iJD is valid */
18681
- char validTZ; /* True (1) if tz is valid */
18682
- char tzSet; /* Timezone was set explicitly */
18720
+ sqlite3_int64 iJD; /* The julian day number times 86400000 */
18721
+ int Y, M, D; /* Year, month, and day */
18722
+ int h, m; /* Hour and minutes */
18723
+ int tz; /* Timezone offset in minutes */
18724
+ double s; /* Seconds */
18725
+ char validJD; /* True (1) if iJD is valid */
18726
+ char rawS; /* Raw numeric value stored in s */
18727
+ char validYMD; /* True (1) if Y,M,D are valid */
18728
+ char validHMS; /* True (1) if h,m,s are valid */
18729
+ char validTZ; /* True (1) if tz is valid */
18730
+ char tzSet; /* Timezone was set explicitly */
18731
+ char isError; /* An overflow has occurred */
1868318732
};
1868418733
1868518734
1868618735
/*
1868718736
** Convert zDate into one or more integers according to the conversion
@@ -18825,18 +18874,27 @@
1882518874
}
1882618875
}else{
1882718876
s = 0;
1882818877
}
1882918878
p->validJD = 0;
18879
+ p->rawS = 0;
1883018880
p->validHMS = 1;
1883118881
p->h = h;
1883218882
p->m = m;
1883318883
p->s = s + ms;
1883418884
if( parseTimezone(zDate, p) ) return 1;
1883518885
p->validTZ = (p->tz!=0)?1:0;
1883618886
return 0;
1883718887
}
18888
+
18889
+/*
18890
+** Put the DateTime object into its error state.
18891
+*/
18892
+static void datetimeError(DateTime *p){
18893
+ memset(p, 0, sizeof(*p));
18894
+ p->isError = 1;
18895
+}
1883818896
1883918897
/*
1884018898
** Convert from YYYY-MM-DD HH:MM:SS to julian day. We always assume
1884118899
** that the YYYY-MM-DD is according to the Gregorian calendar.
1884218900
**
@@ -18852,10 +18910,14 @@
1885218910
D = p->D;
1885318911
}else{
1885418912
Y = 2000; /* If no YMD specified, assume 2000-Jan-01 */
1885518913
M = 1;
1885618914
D = 1;
18915
+ }
18916
+ if( Y<-4713 || Y>9999 || p->rawS ){
18917
+ datetimeError(p);
18918
+ return;
1885718919
}
1885818920
if( M<=2 ){
1885918921
Y--;
1886018922
M += 12;
1886118923
}
@@ -18932,10 +18994,25 @@
1893218994
return 0;
1893318995
}else{
1893418996
return 1;
1893518997
}
1893618998
}
18999
+
19000
+/*
19001
+** Input "r" is a numeric quantity which might be a julian day number,
19002
+** or the number of seconds since 1970. If the value if r is within
19003
+** range of a julian day number, install it as such and set validJD.
19004
+** If the value is a valid unix timestamp, put it in p->s and set p->rawS.
19005
+*/
19006
+static void setRawDateNumber(DateTime *p, double r){
19007
+ p->s = r;
19008
+ p->rawS = 1;
19009
+ if( r>=0.0 && r<5373484.5 ){
19010
+ p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
19011
+ p->validJD = 1;
19012
+ }
19013
+}
1893719014
1893819015
/*
1893919016
** Attempt to parse the given string into a julian day number. Return
1894019017
** the number of errors.
1894119018
**
@@ -18962,16 +19039,24 @@
1896219039
}else if( parseHhMmSs(zDate, p)==0 ){
1896319040
return 0;
1896419041
}else if( sqlite3StrICmp(zDate,"now")==0){
1896519042
return setDateTimeToCurrent(context, p);
1896619043
}else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){
18967
- p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
18968
- p->validJD = 1;
19044
+ setRawDateNumber(p, r);
1896919045
return 0;
1897019046
}
1897119047
return 1;
1897219048
}
19049
+
19050
+/*
19051
+** Return TRUE if the given julian day number is within range.
19052
+**
19053
+** The input is the JulianDay times 86400000.
19054
+*/
19055
+static int validJulianDay(sqlite3_int64 iJD){
19056
+ return iJD>=0 && iJD<=464269060799999;
19057
+}
1897319058
1897419059
/*
1897519060
** Compute the Year, Month, and Day from the julian day number.
1897619061
*/
1897719062
static void computeYMD(DateTime *p){
@@ -18980,10 +19065,11 @@
1898019065
if( !p->validJD ){
1898119066
p->Y = 2000;
1898219067
p->M = 1;
1898319068
p->D = 1;
1898419069
}else{
19070
+ assert( validJulianDay(p->iJD) );
1898519071
Z = (int)((p->iJD + 43200000)/86400000);
1898619072
A = (int)((Z - 1867216.25)/36524.25);
1898719073
A = Z + 1 + A - (A/4);
1898819074
B = A + 1524;
1898919075
C = (int)((B - 122.1)/365.25);
@@ -19010,10 +19096,11 @@
1901019096
p->s -= s;
1901119097
p->h = s/3600;
1901219098
s -= p->h*3600;
1901319099
p->m = s/60;
1901419100
p->s += s - p->m*60;
19101
+ p->rawS = 0;
1901519102
p->validHMS = 1;
1901619103
}
1901719104
1901819105
/*
1901919106
** Compute both YMD and HMS
@@ -19071,18 +19158,18 @@
1907119158
#if SQLITE_THREADSAFE>0
1907219159
sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
1907319160
#endif
1907419161
sqlite3_mutex_enter(mutex);
1907519162
pX = localtime(t);
19076
-#ifndef SQLITE_OMIT_BUILTIN_TEST
19163
+#ifndef SQLITE_UNTESTABLE
1907719164
if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0;
1907819165
#endif
1907919166
if( pX ) *pTm = *pX;
1908019167
sqlite3_mutex_leave(mutex);
1908119168
rc = pX==0;
1908219169
#else
19083
-#ifndef SQLITE_OMIT_BUILTIN_TEST
19170
+#ifndef SQLITE_UNTESTABLE
1908419171
if( sqlite3GlobalConfig.bLocaltimeFault ) return 1;
1908519172
#endif
1908619173
#if HAVE_LOCALTIME_R
1908719174
rc = localtime_r(t, pTm)==0;
1908819175
#else
@@ -19149,16 +19236,41 @@
1914919236
y.m = sLocal.tm_min;
1915019237
y.s = sLocal.tm_sec;
1915119238
y.validYMD = 1;
1915219239
y.validHMS = 1;
1915319240
y.validJD = 0;
19241
+ y.rawS = 0;
1915419242
y.validTZ = 0;
19243
+ y.isError = 0;
1915519244
computeJD(&y);
1915619245
*pRc = SQLITE_OK;
1915719246
return y.iJD - x.iJD;
1915819247
}
1915919248
#endif /* SQLITE_OMIT_LOCALTIME */
19249
+
19250
+/*
19251
+** The following table defines various date transformations of the form
19252
+**
19253
+** 'NNN days'
19254
+**
19255
+** Where NNN is an arbitrary floating-point number and "days" can be one
19256
+** of several units of time.
19257
+*/
19258
+static const struct {
19259
+ u8 eType; /* Transformation type code */
19260
+ u8 nName; /* Length of th name */
19261
+ char *zName; /* Name of the transformation */
19262
+ double rLimit; /* Maximum NNN value for this transform */
19263
+ double rXform; /* Constant used for this transform */
19264
+} aXformType[] = {
19265
+ { 0, 6, "second", 464269060800.0, 86400000.0/(24.0*60.0*60.0) },
19266
+ { 0, 6, "minute", 7737817680.0, 86400000.0/(24.0*60.0) },
19267
+ { 0, 4, "hour", 128963628.0, 86400000.0/24.0 },
19268
+ { 0, 3, "day", 5373485.0, 86400000.0 },
19269
+ { 1, 5, "month", 176546.0, 30.0*86400000.0 },
19270
+ { 2, 4, "year", 14713.0, 365.0*86400000.0 },
19271
+};
1916019272
1916119273
/*
1916219274
** Process a modifier to a date-time stamp. The modifiers are
1916319275
** as follows:
1916419276
**
@@ -19180,29 +19292,27 @@
1918019292
** Return 0 on success and 1 if there is any kind of error. If the error
1918119293
** is in a system call (i.e. localtime()), then an error message is written
1918219294
** to context pCtx. If the error is an unrecognized modifier, no error is
1918319295
** written to pCtx.
1918419296
*/
19185
-static int parseModifier(sqlite3_context *pCtx, const char *zMod, DateTime *p){
19297
+static int parseModifier(
19298
+ sqlite3_context *pCtx, /* Function context */
19299
+ const char *z, /* The text of the modifier */
19300
+ int n, /* Length of zMod in bytes */
19301
+ DateTime *p /* The date/time value to be modified */
19302
+){
1918619303
int rc = 1;
19187
- int n;
1918819304
double r;
19189
- char *z, zBuf[30];
19190
- z = zBuf;
19191
- for(n=0; n<ArraySize(zBuf)-1 && zMod[n]; n++){
19192
- z[n] = (char)sqlite3UpperToLower[(u8)zMod[n]];
19193
- }
19194
- z[n] = 0;
19195
- switch( z[0] ){
19305
+ switch(sqlite3UpperToLower[(u8)z[0]] ){
1919619306
#ifndef SQLITE_OMIT_LOCALTIME
1919719307
case 'l': {
1919819308
/* localtime
1919919309
**
1920019310
** Assuming the current time value is UTC (a.k.a. GMT), shift it to
1920119311
** show local time.
1920219312
*/
19203
- if( strcmp(z, "localtime")==0 ){
19313
+ if( sqlite3_stricmp(z, "localtime")==0 ){
1920419314
computeJD(p);
1920519315
p->iJD += localtimeOffset(p, pCtx, &rc);
1920619316
clearYMD_HMS_TZ(p);
1920719317
}
1920819318
break;
@@ -19210,20 +19320,25 @@
1921019320
#endif
1921119321
case 'u': {
1921219322
/*
1921319323
** unixepoch
1921419324
**
19215
- ** Treat the current value of p->iJD as the number of
19325
+ ** Treat the current value of p->s as the number of
1921619326
** seconds since 1970. Convert to a real julian day number.
1921719327
*/
19218
- if( strcmp(z, "unixepoch")==0 && p->validJD ){
19219
- p->iJD = (p->iJD + 43200)/86400 + 21086676*(i64)10000000;
19220
- clearYMD_HMS_TZ(p);
19221
- rc = 0;
19328
+ if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){
19329
+ r = p->s*1000.0 + 210866760000000.0;
19330
+ if( r>=0.0 && r<464269060800000.0 ){
19331
+ clearYMD_HMS_TZ(p);
19332
+ p->iJD = (sqlite3_int64)r;
19333
+ p->validJD = 1;
19334
+ p->rawS = 0;
19335
+ rc = 0;
19336
+ }
1922219337
}
1922319338
#ifndef SQLITE_OMIT_LOCALTIME
19224
- else if( strcmp(z, "utc")==0 ){
19339
+ else if( sqlite3_stricmp(z, "utc")==0 ){
1922519340
if( p->tzSet==0 ){
1922619341
sqlite3_int64 c1;
1922719342
computeJD(p);
1922819343
c1 = localtimeOffset(p, pCtx, &rc);
1922919344
if( rc==SQLITE_OK ){
@@ -19245,11 +19360,11 @@
1924519360
**
1924619361
** Move the date to the same time on the next occurrence of
1924719362
** weekday N where 0==Sunday, 1==Monday, and so forth. If the
1924819363
** date is already on the appropriate weekday, this is a no-op.
1924919364
*/
19250
- if( strncmp(z, "weekday ", 8)==0
19365
+ if( sqlite3_strnicmp(z, "weekday ", 8)==0
1925119366
&& sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8)
1925219367
&& (n=(int)r)==r && n>=0 && r<7 ){
1925319368
sqlite3_int64 Z;
1925419369
computeYMD_HMS(p);
1925519370
p->validTZ = 0;
@@ -19268,27 +19383,27 @@
1926819383
** start of TTTTT
1926919384
**
1927019385
** Move the date backwards to the beginning of the current day,
1927119386
** or month or year.
1927219387
*/
19273
- if( strncmp(z, "start of ", 9)!=0 ) break;
19388
+ if( sqlite3_strnicmp(z, "start of ", 9)!=0 ) break;
1927419389
z += 9;
1927519390
computeYMD(p);
1927619391
p->validHMS = 1;
1927719392
p->h = p->m = 0;
1927819393
p->s = 0.0;
1927919394
p->validTZ = 0;
1928019395
p->validJD = 0;
19281
- if( strcmp(z,"month")==0 ){
19396
+ if( sqlite3_stricmp(z,"month")==0 ){
1928219397
p->D = 1;
1928319398
rc = 0;
19284
- }else if( strcmp(z,"year")==0 ){
19399
+ }else if( sqlite3_stricmp(z,"year")==0 ){
1928519400
computeYMD(p);
1928619401
p->M = 1;
1928719402
p->D = 1;
1928819403
rc = 0;
19289
- }else if( strcmp(z,"day")==0 ){
19404
+ }else if( sqlite3_stricmp(z,"day")==0 ){
1929019405
rc = 0;
1929119406
}
1929219407
break;
1929319408
}
1929419409
case '+':
@@ -19302,10 +19417,11 @@
1930219417
case '6':
1930319418
case '7':
1930419419
case '8':
1930519420
case '9': {
1930619421
double rRounder;
19422
+ int i;
1930719423
for(n=1; z[n] && z[n]!=':' && !sqlite3Isspace(z[n]); n++){}
1930819424
if( !sqlite3AtoF(z, &r, n, SQLITE_UTF8) ){
1930919425
rc = 1;
1931019426
break;
1931119427
}
@@ -19330,50 +19446,52 @@
1933019446
clearYMD_HMS_TZ(p);
1933119447
p->iJD += tx.iJD;
1933219448
rc = 0;
1933319449
break;
1933419450
}
19451
+
19452
+ /* If control reaches this point, it means the transformation is
19453
+ ** one of the forms like "+NNN days". */
1933519454
z += n;
1933619455
while( sqlite3Isspace(*z) ) z++;
1933719456
n = sqlite3Strlen30(z);
1933819457
if( n>10 || n<3 ) break;
19339
- if( z[n-1]=='s' ){ z[n-1] = 0; n--; }
19458
+ if( sqlite3UpperToLower[(u8)z[n-1]]=='s' ) n--;
1934019459
computeJD(p);
19341
- rc = 0;
19460
+ rc = 1;
1934219461
rRounder = r<0 ? -0.5 : +0.5;
19343
- if( n==3 && strcmp(z,"day")==0 ){
19344
- p->iJD += (sqlite3_int64)(r*86400000.0 + rRounder);
19345
- }else if( n==4 && strcmp(z,"hour")==0 ){
19346
- p->iJD += (sqlite3_int64)(r*(86400000.0/24.0) + rRounder);
19347
- }else if( n==6 && strcmp(z,"minute")==0 ){
19348
- p->iJD += (sqlite3_int64)(r*(86400000.0/(24.0*60.0)) + rRounder);
19349
- }else if( n==6 && strcmp(z,"second")==0 ){
19350
- p->iJD += (sqlite3_int64)(r*(86400000.0/(24.0*60.0*60.0)) + rRounder);
19351
- }else if( n==5 && strcmp(z,"month")==0 ){
19352
- int x, y;
19353
- computeYMD_HMS(p);
19354
- p->M += (int)r;
19355
- x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
19356
- p->Y += x;
19357
- p->M -= x*12;
19358
- p->validJD = 0;
19359
- computeJD(p);
19360
- y = (int)r;
19361
- if( y!=r ){
19362
- p->iJD += (sqlite3_int64)((r - y)*30.0*86400000.0 + rRounder);
19363
- }
19364
- }else if( n==4 && strcmp(z,"year")==0 ){
19365
- int y = (int)r;
19366
- computeYMD_HMS(p);
19367
- p->Y += y;
19368
- p->validJD = 0;
19369
- computeJD(p);
19370
- if( y!=r ){
19371
- p->iJD += (sqlite3_int64)((r - y)*365.0*86400000.0 + rRounder);
19372
- }
19373
- }else{
19374
- rc = 1;
19462
+ for(i=0; i<ArraySize(aXformType); i++){
19463
+ if( aXformType[i].nName==n
19464
+ && sqlite3_strnicmp(aXformType[i].zName, z, n)==0
19465
+ && r>-aXformType[i].rLimit && r<aXformType[i].rLimit
19466
+ ){
19467
+ switch( aXformType[i].eType ){
19468
+ case 1: { /* Special processing to add months */
19469
+ int x;
19470
+ computeYMD_HMS(p);
19471
+ p->M += (int)r;
19472
+ x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
19473
+ p->Y += x;
19474
+ p->M -= x*12;
19475
+ p->validJD = 0;
19476
+ r -= (int)r;
19477
+ break;
19478
+ }
19479
+ case 2: { /* Special processing to add years */
19480
+ int y = (int)r;
19481
+ computeYMD_HMS(p);
19482
+ p->Y += y;
19483
+ p->validJD = 0;
19484
+ r -= (int)r;
19485
+ break;
19486
+ }
19487
+ }
19488
+ computeJD(p);
19489
+ p->iJD += (sqlite3_int64)(r*aXformType[i].rXform + rRounder);
19490
+ rc = 0;
19491
+ break;
19492
+ }
1937519493
}
1937619494
clearYMD_HMS_TZ(p);
1937719495
break;
1937819496
}
1937919497
default: {
@@ -19396,31 +19514,33 @@
1939619514
sqlite3_context *context,
1939719515
int argc,
1939819516
sqlite3_value **argv,
1939919517
DateTime *p
1940019518
){
19401
- int i;
19519
+ int i, n;
1940219520
const unsigned char *z;
1940319521
int eType;
1940419522
memset(p, 0, sizeof(*p));
1940519523
if( argc==0 ){
1940619524
return setDateTimeToCurrent(context, p);
1940719525
}
1940819526
if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
1940919527
|| eType==SQLITE_INTEGER ){
19410
- p->iJD = (sqlite3_int64)(sqlite3_value_double(argv[0])*86400000.0 + 0.5);
19411
- p->validJD = 1;
19528
+ setRawDateNumber(p, sqlite3_value_double(argv[0]));
1941219529
}else{
1941319530
z = sqlite3_value_text(argv[0]);
1941419531
if( !z || parseDateOrTime(context, (char*)z, p) ){
1941519532
return 1;
1941619533
}
1941719534
}
1941819535
for(i=1; i<argc; i++){
1941919536
z = sqlite3_value_text(argv[i]);
19420
- if( z==0 || parseModifier(context, (char*)z, p) ) return 1;
19537
+ n = sqlite3_value_bytes(argv[i]);
19538
+ if( z==0 || parseModifier(context, (char*)z, n, p) ) return 1;
1942119539
}
19540
+ computeJD(p);
19541
+ if( p->isError || !validJulianDay(p->iJD) ) return 1;
1942219542
return 0;
1942319543
}
1942419544
1942519545
1942619546
/*
@@ -20214,11 +20334,11 @@
2021420334
** during a hash table resize is a benign fault.
2021520335
*/
2021620336
2021720337
/* #include "sqliteInt.h" */
2021820338
20219
-#ifndef SQLITE_OMIT_BUILTIN_TEST
20339
+#ifndef SQLITE_UNTESTABLE
2022020340
2022120341
/*
2022220342
** Global variables.
2022320343
*/
2022420344
typedef struct BenignMallocHooks BenignMallocHooks;
@@ -20272,11 +20392,11 @@
2027220392
if( wsdHooks.xBenignEnd ){
2027320393
wsdHooks.xBenignEnd();
2027420394
}
2027520395
}
2027620396
20277
-#endif /* #ifndef SQLITE_OMIT_BUILTIN_TEST */
20397
+#endif /* #ifndef SQLITE_UNTESTABLE */
2027820398
2027920399
/************** End of fault.c ***********************************************/
2028020400
/************** Begin file mem0.c ********************************************/
2028120401
/*
2028220402
** 2008 October 28
@@ -25599,22 +25719,27 @@
2559925719
/*
2560025720
** Finish off a string by making sure it is zero-terminated.
2560125721
** Return a pointer to the resulting string. Return a NULL
2560225722
** pointer if any kind of error was encountered.
2560325723
*/
25724
+static SQLITE_NOINLINE char *strAccumFinishRealloc(StrAccum *p){
25725
+ assert( p->mxAlloc>0 && !isMalloced(p) );
25726
+ p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
25727
+ if( p->zText ){
25728
+ memcpy(p->zText, p->zBase, p->nChar+1);
25729
+ p->printfFlags |= SQLITE_PRINTF_MALLOCED;
25730
+ }else{
25731
+ setStrAccumError(p, STRACCUM_NOMEM);
25732
+ }
25733
+ return p->zText;
25734
+}
2560425735
SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
2560525736
if( p->zText ){
2560625737
assert( (p->zText==p->zBase)==!isMalloced(p) );
2560725738
p->zText[p->nChar] = 0;
2560825739
if( p->mxAlloc>0 && !isMalloced(p) ){
25609
- p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
25610
- if( p->zText ){
25611
- memcpy(p->zText, p->zBase, p->nChar+1);
25612
- p->printfFlags |= SQLITE_PRINTF_MALLOCED;
25613
- }else{
25614
- setStrAccumError(p, STRACCUM_NOMEM);
25615
- }
25740
+ return strAccumFinishRealloc(p);
2561625741
}
2561725742
}
2561825743
return p->zText;
2561925744
}
2562025745
@@ -25750,11 +25875,12 @@
2575025875
return zBuf;
2575125876
}
2575225877
#endif
2575325878
sqlite3StrAccumInit(&acc, 0, zBuf, n, 0);
2575425879
sqlite3VXPrintf(&acc, zFormat, ap);
25755
- return sqlite3StrAccumFinish(&acc);
25880
+ zBuf[acc.nChar] = 0;
25881
+ return zBuf;
2575625882
}
2575725883
SQLITE_API char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
2575825884
char *z;
2575925885
va_list ap;
2576025886
va_start(ap,zFormat);
@@ -26459,11 +26585,11 @@
2645926585
*(zBuf++) = wsdPrng.s[t];
2646026586
}while( --N );
2646126587
sqlite3_mutex_leave(mutex);
2646226588
}
2646326589
26464
-#ifndef SQLITE_OMIT_BUILTIN_TEST
26590
+#ifndef SQLITE_UNTESTABLE
2646526591
/*
2646626592
** For testing purposes, we sometimes want to preserve the state of
2646726593
** PRNG and restore the PRNG to its saved state at a later time, or
2646826594
** to reset the PRNG to its initial state. These routines accomplish
2646926595
** those tasks.
@@ -26484,11 +26610,11 @@
2648426610
&GLOBAL(struct sqlite3PrngType, sqlite3Prng),
2648526611
&GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng),
2648626612
sizeof(sqlite3Prng)
2648726613
);
2648826614
}
26489
-#endif /* SQLITE_OMIT_BUILTIN_TEST */
26615
+#endif /* SQLITE_UNTESTABLE */
2649026616
2649126617
/************** End of random.c **********************************************/
2649226618
/************** Begin file threads.c *****************************************/
2649326619
/*
2649426620
** 2012 July 21
@@ -27342,11 +27468,11 @@
2734227468
** which of multiple sqlite3FaultSim() calls has been hit.
2734327469
**
2734427470
** Return whatever integer value the test callback returns, or return
2734527471
** SQLITE_OK if no test callback is installed.
2734627472
*/
27347
-#ifndef SQLITE_OMIT_BUILTIN_TEST
27473
+#ifndef SQLITE_UNTESTABLE
2734827474
SQLITE_PRIVATE int sqlite3FaultSim(int iTest){
2734927475
int (*xCallback)(int) = sqlite3GlobalConfig.xTestCallback;
2735027476
return xCallback ? xCallback(iTest) : SQLITE_OK;
2735127477
}
2735227478
#endif
@@ -29163,52 +29289,51 @@
2916329289
/* 116 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
2916429290
/* 117 */ "Delete" OpHelp(""),
2916529291
/* 118 */ "ResetCount" OpHelp(""),
2916629292
/* 119 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
2916729293
/* 120 */ "SorterData" OpHelp("r[P2]=data"),
29168
- /* 121 */ "RowKey" OpHelp("r[P2]=key"),
29169
- /* 122 */ "RowData" OpHelp("r[P2]=data"),
29170
- /* 123 */ "Rowid" OpHelp("r[P2]=rowid"),
29171
- /* 124 */ "NullRow" OpHelp(""),
29172
- /* 125 */ "SorterInsert" OpHelp("key=r[P2]"),
29173
- /* 126 */ "IdxInsert" OpHelp("key=r[P2]"),
29174
- /* 127 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
29175
- /* 128 */ "Seek" OpHelp("Move P3 to P1.rowid"),
29176
- /* 129 */ "IdxRowid" OpHelp("r[P2]=rowid"),
29177
- /* 130 */ "Destroy" OpHelp(""),
29178
- /* 131 */ "Clear" OpHelp(""),
29294
+ /* 121 */ "RowData" OpHelp("r[P2]=data"),
29295
+ /* 122 */ "Rowid" OpHelp("r[P2]=rowid"),
29296
+ /* 123 */ "NullRow" OpHelp(""),
29297
+ /* 124 */ "SorterInsert" OpHelp("key=r[P2]"),
29298
+ /* 125 */ "IdxInsert" OpHelp("key=r[P2]"),
29299
+ /* 126 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
29300
+ /* 127 */ "Seek" OpHelp("Move P3 to P1.rowid"),
29301
+ /* 128 */ "IdxRowid" OpHelp("r[P2]=rowid"),
29302
+ /* 129 */ "Destroy" OpHelp(""),
29303
+ /* 130 */ "Clear" OpHelp(""),
29304
+ /* 131 */ "ResetSorter" OpHelp(""),
2917929305
/* 132 */ "Real" OpHelp("r[P2]=P4"),
29180
- /* 133 */ "ResetSorter" OpHelp(""),
29181
- /* 134 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
29182
- /* 135 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
29183
- /* 136 */ "ParseSchema" OpHelp(""),
29184
- /* 137 */ "LoadAnalysis" OpHelp(""),
29185
- /* 138 */ "DropTable" OpHelp(""),
29186
- /* 139 */ "DropIndex" OpHelp(""),
29187
- /* 140 */ "DropTrigger" OpHelp(""),
29188
- /* 141 */ "IntegrityCk" OpHelp(""),
29189
- /* 142 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
29190
- /* 143 */ "Param" OpHelp(""),
29191
- /* 144 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
29192
- /* 145 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
29193
- /* 146 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
29194
- /* 147 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
29195
- /* 148 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
29196
- /* 149 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
29197
- /* 150 */ "Expire" OpHelp(""),
29198
- /* 151 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
29199
- /* 152 */ "VBegin" OpHelp(""),
29200
- /* 153 */ "VCreate" OpHelp(""),
29201
- /* 154 */ "VDestroy" OpHelp(""),
29202
- /* 155 */ "VOpen" OpHelp(""),
29203
- /* 156 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
29204
- /* 157 */ "VRename" OpHelp(""),
29205
- /* 158 */ "Pagecount" OpHelp(""),
29206
- /* 159 */ "MaxPgcnt" OpHelp(""),
29207
- /* 160 */ "CursorHint" OpHelp(""),
29208
- /* 161 */ "Noop" OpHelp(""),
29209
- /* 162 */ "Explain" OpHelp(""),
29306
+ /* 133 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
29307
+ /* 134 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
29308
+ /* 135 */ "ParseSchema" OpHelp(""),
29309
+ /* 136 */ "LoadAnalysis" OpHelp(""),
29310
+ /* 137 */ "DropTable" OpHelp(""),
29311
+ /* 138 */ "DropIndex" OpHelp(""),
29312
+ /* 139 */ "DropTrigger" OpHelp(""),
29313
+ /* 140 */ "IntegrityCk" OpHelp(""),
29314
+ /* 141 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
29315
+ /* 142 */ "Param" OpHelp(""),
29316
+ /* 143 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
29317
+ /* 144 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
29318
+ /* 145 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
29319
+ /* 146 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
29320
+ /* 147 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
29321
+ /* 148 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
29322
+ /* 149 */ "Expire" OpHelp(""),
29323
+ /* 150 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
29324
+ /* 151 */ "VBegin" OpHelp(""),
29325
+ /* 152 */ "VCreate" OpHelp(""),
29326
+ /* 153 */ "VDestroy" OpHelp(""),
29327
+ /* 154 */ "VOpen" OpHelp(""),
29328
+ /* 155 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
29329
+ /* 156 */ "VRename" OpHelp(""),
29330
+ /* 157 */ "Pagecount" OpHelp(""),
29331
+ /* 158 */ "MaxPgcnt" OpHelp(""),
29332
+ /* 159 */ "CursorHint" OpHelp(""),
29333
+ /* 160 */ "Noop" OpHelp(""),
29334
+ /* 161 */ "Explain" OpHelp(""),
2921029335
};
2921129336
return azName[i];
2921229337
}
2921329338
#endif
2921429339
@@ -30473,11 +30598,18 @@
3047330598
struct unixFileId {
3047430599
dev_t dev; /* Device number */
3047530600
#if OS_VXWORKS
3047630601
struct vxworksFileId *pId; /* Unique file ID for vxworks. */
3047730602
#else
30478
- ino_t ino; /* Inode number */
30603
+ /* We are told that some versions of Android contain a bug that
30604
+ ** sizes ino_t at only 32-bits instead of 64-bits. (See
30605
+ ** https://android-review.googlesource.com/#/c/115351/3/dist/sqlite3.c)
30606
+ ** To work around this, always allocate 64-bits for the inode number.
30607
+ ** On small machines that only have 32-bit inodes, this wastes 4 bytes,
30608
+ ** but that should not be a big deal. */
30609
+ /* WAS: ino_t ino; */
30610
+ u64 ino; /* Inode number */
3047930611
#endif
3048030612
};
3048130613
3048230614
/*
3048330615
** An instance of the following structure is allocated for each open
@@ -30718,11 +30850,11 @@
3071830850
memset(&fileId, 0, sizeof(fileId));
3071930851
fileId.dev = statbuf.st_dev;
3072030852
#if OS_VXWORKS
3072130853
fileId.pId = pFile->pId;
3072230854
#else
30723
- fileId.ino = statbuf.st_ino;
30855
+ fileId.ino = (u64)statbuf.st_ino;
3072430856
#endif
3072530857
pInode = inodeList;
3072630858
while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
3072730859
pInode = pInode->pNext;
3072830860
}
@@ -30752,11 +30884,12 @@
3075230884
#if OS_VXWORKS
3075330885
return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId;
3075430886
#else
3075530887
struct stat buf;
3075630888
return pFile->pInode!=0 &&
30757
- (osStat(pFile->zPath, &buf)!=0 || buf.st_ino!=pFile->pInode->fileId.ino);
30889
+ (osStat(pFile->zPath, &buf)!=0
30890
+ || (u64)buf.st_ino!=pFile->pInode->fileId.ino);
3075830891
#endif
3075930892
}
3076030893
3076130894
3076230895
/*
@@ -34924,11 +35057,11 @@
3492435057
unixInodeInfo *pInode;
3492535058
3492635059
unixEnterMutex();
3492735060
pInode = inodeList;
3492835061
while( pInode && (pInode->fileId.dev!=sStat.st_dev
34929
- || pInode->fileId.ino!=sStat.st_ino) ){
35062
+ || pInode->fileId.ino!=(u64)sStat.st_ino) ){
3493035063
pInode = pInode->pNext;
3493135064
}
3493235065
if( pInode ){
3493335066
UnixUnusedFd **pp;
3493435067
for(pp=&pInode->pUnused; *pp && (*pp)->flags!=flags; pp=&((*pp)->pNext));
@@ -43485,11 +43618,11 @@
4348543618
*/
4348643619
SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec *p){
4348743620
return p->iSize;
4348843621
}
4348943622
43490
-#ifndef SQLITE_OMIT_BUILTIN_TEST
43623
+#ifndef SQLITE_UNTESTABLE
4349143624
/*
4349243625
** Let V[] be an array of unsigned characters sufficient to hold
4349343626
** up to N bits. Let I be an integer between 0 and N. 0<=I<N.
4349443627
** Then the following macros can be used to set, clear, or test
4349543628
** individual bits within V.
@@ -43600,11 +43733,11 @@
4360043733
sqlite3_free(pTmpSpace);
4360143734
sqlite3_free(pV);
4360243735
sqlite3BitvecDestroy(pBitvec);
4360343736
return rc;
4360443737
}
43605
-#endif /* SQLITE_OMIT_BUILTIN_TEST */
43738
+#endif /* SQLITE_UNTESTABLE */
4360643739
4360743740
/************** End of bitvec.c **********************************************/
4360843741
/************** Begin file pcache.c ******************************************/
4360943742
/*
4361043743
** 2008 August 05
@@ -46398,10 +46531,11 @@
4639846531
SQLITE_PRIVATE int sqlite3WalHeapMemory(Wal *pWal);
4639946532
4640046533
#ifdef SQLITE_ENABLE_SNAPSHOT
4640146534
SQLITE_PRIVATE int sqlite3WalSnapshotGet(Wal *pWal, sqlite3_snapshot **ppSnapshot);
4640246535
SQLITE_PRIVATE void sqlite3WalSnapshotOpen(Wal *pWal, sqlite3_snapshot *pSnapshot);
46536
+SQLITE_PRIVATE int sqlite3WalSnapshotRecover(Wal *pWal);
4640346537
#endif
4640446538
4640546539
#ifdef SQLITE_ENABLE_ZIPVFS
4640646540
/* If the WAL file is not empty, return the number of bytes of content
4640746541
** stored in each frame (i.e. the db page-size when the WAL was created).
@@ -53799,10 +53933,24 @@
5379953933
}else{
5380053934
rc = SQLITE_ERROR;
5380153935
}
5380253936
return rc;
5380353937
}
53938
+
53939
+/*
53940
+** If this is a WAL database, call sqlite3WalSnapshotRecover(). If this
53941
+** is not a WAL database, return an error.
53942
+*/
53943
+SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager){
53944
+ int rc;
53945
+ if( pPager->pWal ){
53946
+ rc = sqlite3WalSnapshotRecover(pPager->pWal);
53947
+ }else{
53948
+ rc = SQLITE_ERROR;
53949
+ }
53950
+ return rc;
53951
+}
5380453952
#endif /* SQLITE_ENABLE_SNAPSHOT */
5380553953
#endif /* !SQLITE_OMIT_WAL */
5380653954
5380753955
#ifdef SQLITE_ENABLE_ZIPVFS
5380853956
/*
@@ -56201,10 +56349,88 @@
5620156349
pWal->readLock = (i16)mxI;
5620256350
}
5620356351
return rc;
5620456352
}
5620556353
56354
+#ifdef SQLITE_ENABLE_SNAPSHOT
56355
+/*
56356
+** Attempt to reduce the value of the WalCkptInfo.nBackfillAttempted
56357
+** variable so that older snapshots can be accessed. To do this, loop
56358
+** through all wal frames from nBackfillAttempted to (nBackfill+1),
56359
+** comparing their content to the corresponding page with the database
56360
+** file, if any. Set nBackfillAttempted to the frame number of the
56361
+** first frame for which the wal file content matches the db file.
56362
+**
56363
+** This is only really safe if the file-system is such that any page
56364
+** writes made by earlier checkpointers were atomic operations, which
56365
+** is not always true. It is also possible that nBackfillAttempted
56366
+** may be left set to a value larger than expected, if a wal frame
56367
+** contains content that duplicate of an earlier version of the same
56368
+** page.
56369
+**
56370
+** SQLITE_OK is returned if successful, or an SQLite error code if an
56371
+** error occurs. It is not an error if nBackfillAttempted cannot be
56372
+** decreased at all.
56373
+*/
56374
+SQLITE_PRIVATE int sqlite3WalSnapshotRecover(Wal *pWal){
56375
+ int rc;
56376
+
56377
+ assert( pWal->readLock>=0 );
56378
+ rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1);
56379
+ if( rc==SQLITE_OK ){
56380
+ volatile WalCkptInfo *pInfo = walCkptInfo(pWal);
56381
+ int szPage = (int)pWal->szPage;
56382
+ i64 szDb; /* Size of db file in bytes */
56383
+
56384
+ rc = sqlite3OsFileSize(pWal->pDbFd, &szDb);
56385
+ if( rc==SQLITE_OK ){
56386
+ void *pBuf1 = sqlite3_malloc(szPage);
56387
+ void *pBuf2 = sqlite3_malloc(szPage);
56388
+ if( pBuf1==0 || pBuf2==0 ){
56389
+ rc = SQLITE_NOMEM;
56390
+ }else{
56391
+ u32 i = pInfo->nBackfillAttempted;
56392
+ for(i=pInfo->nBackfillAttempted; i>pInfo->nBackfill; i--){
56393
+ volatile ht_slot *dummy;
56394
+ volatile u32 *aPgno; /* Array of page numbers */
56395
+ u32 iZero; /* Frame corresponding to aPgno[0] */
56396
+ u32 pgno; /* Page number in db file */
56397
+ i64 iDbOff; /* Offset of db file entry */
56398
+ i64 iWalOff; /* Offset of wal file entry */
56399
+
56400
+ rc = walHashGet(pWal, walFramePage(i), &dummy, &aPgno, &iZero);
56401
+ if( rc!=SQLITE_OK ) break;
56402
+ pgno = aPgno[i-iZero];
56403
+ iDbOff = (i64)(pgno-1) * szPage;
56404
+
56405
+ if( iDbOff+szPage<=szDb ){
56406
+ iWalOff = walFrameOffset(i, szPage) + WAL_FRAME_HDRSIZE;
56407
+ rc = sqlite3OsRead(pWal->pWalFd, pBuf1, szPage, iWalOff);
56408
+
56409
+ if( rc==SQLITE_OK ){
56410
+ rc = sqlite3OsRead(pWal->pDbFd, pBuf2, szPage, iDbOff);
56411
+ }
56412
+
56413
+ if( rc!=SQLITE_OK || 0==memcmp(pBuf1, pBuf2, szPage) ){
56414
+ break;
56415
+ }
56416
+ }
56417
+
56418
+ pInfo->nBackfillAttempted = i-1;
56419
+ }
56420
+ }
56421
+
56422
+ sqlite3_free(pBuf1);
56423
+ sqlite3_free(pBuf2);
56424
+ }
56425
+ walUnlockExclusive(pWal, WAL_CKPT_LOCK, 1);
56426
+ }
56427
+
56428
+ return rc;
56429
+}
56430
+#endif /* SQLITE_ENABLE_SNAPSHOT */
56431
+
5620656432
/*
5620756433
** Begin a read transaction on the database.
5620856434
**
5620956435
** This routine used to be called sqlite3OpenSnapshot() and with good reason:
5621056436
** it takes a snapshot of the state of the WAL and wal-index for the current
@@ -56263,11 +56489,15 @@
5626356489
** checkpointer has already determined that it will checkpoint
5626456490
** snapshot X, where X is later in the wal file than pSnapshot, but
5626556491
** has not yet set the pInfo->nBackfillAttempted variable to indicate
5626656492
** its intent. To avoid the race condition this leads to, ensure that
5626756493
** there is no checkpointer process by taking a shared CKPT lock
56268
- ** before checking pInfo->nBackfillAttempted. */
56494
+ ** before checking pInfo->nBackfillAttempted.
56495
+ **
56496
+ ** TODO: Does the aReadMark[] lock prevent a checkpointer from doing
56497
+ ** this already?
56498
+ */
5626956499
rc = walLockShared(pWal, WAL_CKPT_LOCK);
5627056500
5627156501
if( rc==SQLITE_OK ){
5627256502
/* Check that the wal file has not been wrapped. Assuming that it has
5627356503
** not, also check that no checkpointer has attempted to checkpoint any
@@ -57215,13 +57445,18 @@
5721557445
** in the object.
5721657446
*/
5721757447
SQLITE_PRIVATE int sqlite3WalSnapshotGet(Wal *pWal, sqlite3_snapshot **ppSnapshot){
5721857448
int rc = SQLITE_OK;
5721957449
WalIndexHdr *pRet;
57450
+ static const u32 aZero[4] = { 0, 0, 0, 0 };
5722057451
5722157452
assert( pWal->readLock>=0 && pWal->writeLock==0 );
5722257453
57454
+ if( memcmp(&pWal->hdr.aFrameCksum[0],aZero,16)==0 ){
57455
+ *ppSnapshot = 0;
57456
+ return SQLITE_ERROR;
57457
+ }
5722357458
pRet = (WalIndexHdr*)sqlite3_malloc(sizeof(WalIndexHdr));
5722457459
if( pRet==0 ){
5722557460
rc = SQLITE_NOMEM_BKPT;
5722657461
}else{
5722757462
memcpy(pRet, &pWal->hdr, sizeof(WalIndexHdr));
@@ -58922,11 +59157,11 @@
5892259157
/* For an index btree, save the complete key content */
5892359158
void *pKey;
5892459159
pCur->nKey = sqlite3BtreePayloadSize(pCur);
5892559160
pKey = sqlite3Malloc( pCur->nKey );
5892659161
if( pKey ){
58927
- rc = sqlite3BtreeKey(pCur, 0, (int)pCur->nKey, pKey);
59162
+ rc = sqlite3BtreePayload(pCur, 0, (int)pCur->nKey, pKey);
5892859163
if( rc==SQLITE_OK ){
5892959164
pCur->pKey = pKey;
5893059165
}else{
5893159166
sqlite3_free(pKey);
5893259167
}
@@ -62941,47 +63176,39 @@
6294163176
}
6294263177
return rc;
6294363178
}
6294463179
6294563180
/*
62946
-** Read part of the key associated with cursor pCur. Exactly
62947
-** "amt" bytes will be transferred into pBuf[]. The transfer
63181
+** Read part of the payload for the row at which that cursor pCur is currently
63182
+** pointing. "amt" bytes will be transferred into pBuf[]. The transfer
6294863183
** begins at "offset".
6294963184
**
62950
-** The caller must ensure that pCur is pointing to a valid row
62951
-** in the table.
63185
+** pCur can be pointing to either a table or an index b-tree.
63186
+** If pointing to a table btree, then the content section is read. If
63187
+** pCur is pointing to an index b-tree then the key section is read.
63188
+**
63189
+** For sqlite3BtreePayload(), the caller must ensure that pCur is pointing
63190
+** to a valid row in the table. For sqlite3BtreePayloadChecked(), the
63191
+** cursor might be invalid or might need to be restored before being read.
6295263192
**
6295363193
** Return SQLITE_OK on success or an error code if anything goes
6295463194
** wrong. An error is returned if "offset+amt" is larger than
6295563195
** the available payload.
6295663196
*/
62957
-SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
63197
+SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
6295863198
assert( cursorHoldsMutex(pCur) );
6295963199
assert( pCur->eState==CURSOR_VALID );
6296063200
assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
6296163201
assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
6296263202
return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
6296363203
}
62964
-
62965
-/*
62966
-** Read part of the data associated with cursor pCur. Exactly
62967
-** "amt" bytes will be transfered into pBuf[]. The transfer
62968
-** begins at "offset".
62969
-**
62970
-** Return SQLITE_OK on success or an error code if anything goes
62971
-** wrong. An error is returned if "offset+amt" is larger than
62972
-** the available payload.
62973
-*/
62974
-SQLITE_PRIVATE int sqlite3BtreeData(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
62975
- int rc;
62976
-
6297763204
#ifndef SQLITE_OMIT_INCRBLOB
63205
+SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
63206
+ int rc;
6297863207
if ( pCur->eState==CURSOR_INVALID ){
6297963208
return SQLITE_ABORT;
6298063209
}
62981
-#endif
62982
-
6298363210
assert( cursorOwnsBtShared(pCur) );
6298463211
rc = restoreCursorPosition(pCur);
6298563212
if( rc==SQLITE_OK ){
6298663213
assert( pCur->eState==CURSOR_VALID );
6298763214
assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
@@ -62988,10 +63215,11 @@
6298863215
assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
6298963216
rc = accessPayload(pCur, offset, amt, pBuf, 0);
6299063217
}
6299163218
return rc;
6299263219
}
63220
+#endif /* SQLITE_OMIT_INCRBLOB */
6299363221
6299463222
/*
6299563223
** Return a pointer to payload information from the entry that the
6299663224
** pCur cursor is pointing to. The pointer is to the beginning of
6299763225
** the key if index btrees (pPage->intKey==0) and is the data for
@@ -69752,14 +69980,13 @@
6975269980
return SQLITE_OK;
6975369981
}
6975469982
6975569983
/*
6975669984
** Move data out of a btree key or data field and into a Mem structure.
69757
-** The data or key is taken from the entry that pCur is currently pointing
69985
+** The data is payload from the entry that pCur is currently pointing
6975869986
** to. offset and amt determine what portion of the data or key to retrieve.
69759
-** key is true to get the key or false to get data. The result is written
69760
-** into the pMem element.
69987
+** The result is written into the pMem element.
6976169988
**
6976269989
** The pMem object must have been initialized. This routine will use
6976369990
** pMem->zMalloc to hold the content from the btree, if possible. New
6976469991
** pMem->zMalloc space will be allocated if necessary. The calling routine
6976569992
** is responsible for making sure that the pMem object is eventually
@@ -69770,21 +69997,16 @@
6977069997
*/
6977169998
static SQLITE_NOINLINE int vdbeMemFromBtreeResize(
6977269999
BtCursor *pCur, /* Cursor pointing at record to retrieve. */
6977370000
u32 offset, /* Offset from the start of data to return bytes from. */
6977470001
u32 amt, /* Number of bytes to return. */
69775
- int key, /* If true, retrieve from the btree key, not data. */
6977670002
Mem *pMem /* OUT: Return data in this Mem structure. */
6977770003
){
6977870004
int rc;
6977970005
pMem->flags = MEM_Null;
6978070006
if( SQLITE_OK==(rc = sqlite3VdbeMemClearAndResize(pMem, amt+2)) ){
69781
- if( key ){
69782
- rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
69783
- }else{
69784
- rc = sqlite3BtreeData(pCur, offset, amt, pMem->z);
69785
- }
70007
+ rc = sqlite3BtreePayload(pCur, offset, amt, pMem->z);
6978670008
if( rc==SQLITE_OK ){
6978770009
pMem->z[amt] = 0;
6978870010
pMem->z[amt+1] = 0;
6978970011
pMem->flags = MEM_Blob|MEM_Term;
6979070012
pMem->n = (int)amt;
@@ -69796,11 +70018,10 @@
6979670018
}
6979770019
SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(
6979870020
BtCursor *pCur, /* Cursor pointing at record to retrieve. */
6979970021
u32 offset, /* Offset from the start of data to return bytes from. */
6980070022
u32 amt, /* Number of bytes to return. */
69801
- int key, /* If true, retrieve from the btree key, not data. */
6980270023
Mem *pMem /* OUT: Return data in this Mem structure. */
6980370024
){
6980470025
char *zData; /* Data from the btree layer */
6980570026
u32 available = 0; /* Number of bytes available on the local btree page */
6980670027
int rc = SQLITE_OK; /* Return code */
@@ -69817,11 +70038,11 @@
6981770038
if( offset+amt<=available ){
6981870039
pMem->z = &zData[offset];
6981970040
pMem->flags = MEM_Blob|MEM_Ephem;
6982070041
pMem->n = (int)amt;
6982170042
}else{
69822
- rc = vdbeMemFromBtreeResize(pCur, offset, amt, key, pMem);
70043
+ rc = vdbeMemFromBtreeResize(pCur, offset, amt, pMem);
6982370044
}
6982470045
6982570046
return rc;
6982670047
}
6982770048
@@ -70847,11 +71068,15 @@
7084771068
int p2, /* The P2 operand */
7084871069
int p3, /* The P3 operand */
7084971070
int p4 /* The P4 operand as an integer */
7085071071
){
7085171072
int addr = sqlite3VdbeAddOp3(p, op, p1, p2, p3);
70852
- sqlite3VdbeChangeP4(p, addr, SQLITE_INT_TO_PTR(p4), P4_INT32);
71073
+ if( p->db->mallocFailed==0 ){
71074
+ VdbeOp *pOp = &p->aOp[addr];
71075
+ pOp->p4type = P4_INT32;
71076
+ pOp->p4.i = p4;
71077
+ }
7085371078
return addr;
7085471079
}
7085571080
7085671081
/* Insert the end of a co-routine
7085771082
*/
@@ -71358,14 +71583,10 @@
7135871583
case P4_EXPR: {
7135971584
sqlite3ExprDelete(db, (Expr*)p4);
7136071585
break;
7136171586
}
7136271587
#endif
71363
- case P4_MPRINTF: {
71364
- if( db->pnBytesFreed==0 ) sqlite3_free(p4);
71365
- break;
71366
- }
7136771588
case P4_FUNCDEF: {
7136871589
freeEphemeralFunction(db, (FuncDef*)p4);
7136971590
break;
7137071591
}
7137171592
case P4_MEM: {
@@ -71505,21 +71726,47 @@
7150571726
pOp->p4.p = (void*)zP4;
7150671727
pOp->p4type = (signed char)n;
7150771728
if( n==P4_VTAB ) sqlite3VtabLock((VTable*)zP4);
7150871729
}
7150971730
}
71731
+
71732
+/*
71733
+** Change the P4 operand of the most recently coded instruction
71734
+** to the value defined by the arguments. This is a high-speed
71735
+** version of sqlite3VdbeChangeP4().
71736
+**
71737
+** The P4 operand must not have been previously defined. And the new
71738
+** P4 must not be P4_INT32. Use sqlite3VdbeChangeP4() in either of
71739
+** those cases.
71740
+*/
71741
+SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe *p, void *pP4, int n){
71742
+ VdbeOp *pOp;
71743
+ assert( n!=P4_INT32 && n!=P4_VTAB );
71744
+ assert( n<=0 );
71745
+ if( p->db->mallocFailed ){
71746
+ freeP4(p->db, n, pP4);
71747
+ }else{
71748
+ assert( pP4!=0 );
71749
+ assert( p->nOp>0 );
71750
+ pOp = &p->aOp[p->nOp-1];
71751
+ assert( pOp->p4type==P4_NOTUSED );
71752
+ pOp->p4type = n;
71753
+ pOp->p4.p = pP4;
71754
+ }
71755
+}
7151071756
7151171757
/*
7151271758
** Set the P4 on the most recently added opcode to the KeyInfo for the
7151371759
** index given.
7151471760
*/
7151571761
SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse *pParse, Index *pIdx){
7151671762
Vdbe *v = pParse->pVdbe;
71763
+ KeyInfo *pKeyInfo;
7151771764
assert( v!=0 );
7151871765
assert( pIdx!=0 );
71519
- sqlite3VdbeChangeP4(v, -1, (char*)sqlite3KeyInfoOfIndex(pParse, pIdx),
71520
- P4_KEYINFO);
71766
+ pKeyInfo = sqlite3KeyInfoOfIndex(pParse, pIdx);
71767
+ if( pKeyInfo ) sqlite3VdbeAppendP4(v, pKeyInfo, P4_KEYINFO);
7152171768
}
7152271769
7152371770
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
7152471771
/*
7152571772
** Change the comment on the most recently coded instruction. Or
@@ -71805,11 +72052,11 @@
7180572052
case P4_FUNCDEF: {
7180672053
FuncDef *pDef = pOp->p4.pFunc;
7180772054
sqlite3XPrintf(&x, "%s(%d)", pDef->zName, pDef->nArg);
7180872055
break;
7180972056
}
71810
-#ifdef SQLITE_DEBUG
72057
+#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
7181172058
case P4_FUNCCTX: {
7181272059
FuncDef *pDef = pOp->p4.pCtx->pFunc;
7181372060
sqlite3XPrintf(&x, "%s(%d)", pDef->zName, pDef->nArg);
7181472061
break;
7181572062
}
@@ -74899,11 +75146,11 @@
7489975146
nCellKey = sqlite3BtreePayloadSize(pCur);
7490075147
assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
7490175148
7490275149
/* Read in the complete content of the index entry */
7490375150
sqlite3VdbeMemInit(&m, db, 0);
74904
- rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m);
75151
+ rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, &m);
7490575152
if( rc ){
7490675153
return rc;
7490775154
}
7490875155
7490975156
/* The index entry must begin with a header size */
@@ -74979,11 +75226,11 @@
7497975226
if( nCellKey<=0 || nCellKey>0x7fffffff ){
7498075227
*res = 0;
7498175228
return SQLITE_CORRUPT_BKPT;
7498275229
}
7498375230
sqlite3VdbeMemInit(&m, db, 0);
74984
- rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m);
75231
+ rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, &m);
7498575232
if( rc ){
7498675233
return rc;
7498775234
}
7498875235
*res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked);
7498975236
sqlite3VdbeMemRelease(&m);
@@ -76868,11 +77115,11 @@
7686877115
u8 *aRec;
7686977116
7687077117
nRec = sqlite3BtreePayloadSize(p->pCsr->uc.pCursor);
7687177118
aRec = sqlite3DbMallocRaw(db, nRec);
7687277119
if( !aRec ) goto preupdate_old_out;
76873
- rc = sqlite3BtreeData(p->pCsr->uc.pCursor, 0, nRec, aRec);
77120
+ rc = sqlite3BtreePayload(p->pCsr->uc.pCursor, 0, nRec, aRec);
7687477121
if( rc==SQLITE_OK ){
7687577122
p->pUnpacked = vdbeUnpackRecord(&p->keyinfo, nRec, aRec);
7687677123
if( !p->pUnpacked ) rc = SQLITE_NOMEM;
7687777124
}
7687877125
if( rc!=SQLITE_OK ){
@@ -77385,11 +77632,11 @@
7738577632
7738677633
/*
7738777634
** Test a register to see if it exceeds the current maximum blob size.
7738877635
** If it does, record the new maximum blob size.
7738977636
*/
77390
-#if defined(SQLITE_TEST) && !defined(SQLITE_OMIT_BUILTIN_TEST)
77637
+#if defined(SQLITE_TEST) && !defined(SQLITE_UNTESTABLE)
7739177638
# define UPDATE_MAX_BLOBSIZE(P) updateMaxBlobsize(P)
7739277639
#else
7739377640
# define UPDATE_MAX_BLOBSIZE(P)
7739477641
#endif
7739577642
@@ -79833,11 +80080,10 @@
7983380080
assert( p2<pC->nField );
7983480081
aOffset = pC->aOffset;
7983580082
assert( pC->eCurType!=CURTYPE_VTAB );
7983680083
assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow );
7983780084
assert( pC->eCurType!=CURTYPE_SORTER );
79838
- pCrsr = pC->uc.pCursor;
7983980085
7984080086
if( pC->cacheStatus!=p->cacheCtr ){ /*OPTIMIZATION-IF-FALSE*/
7984180087
if( pC->nullRow ){
7984280088
if( pC->eCurType==CURTYPE_PSEUDO ){
7984380089
assert( pC->uc.pseudoTableReg>0 );
@@ -79849,10 +80095,11 @@
7984980095
}else{
7985080096
sqlite3VdbeMemSetNull(pDest);
7985180097
goto op_column_out;
7985280098
}
7985380099
}else{
80100
+ pCrsr = pC->uc.pCursor;
7985480101
assert( pC->eCurType==CURTYPE_BTREE );
7985580102
assert( pCrsr );
7985680103
assert( sqlite3BtreeCursorIsValid(pCrsr) );
7985780104
pC->payloadSize = sqlite3BtreePayloadSize(pCrsr);
7985880105
pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &avail);
@@ -79912,11 +80159,11 @@
7991280159
*/
7991380160
if( pC->iHdrOffset<aOffset[0] ){
7991480161
/* Make sure zData points to enough of the record to cover the header. */
7991580162
if( pC->aRow==0 ){
7991680163
memset(&sMem, 0, sizeof(sMem));
79917
- rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0], !pC->isTable, &sMem);
80164
+ rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, 0, aOffset[0], &sMem);
7991880165
if( rc!=SQLITE_OK ) goto abort_due_to_error;
7991980166
zData = (u8*)sMem.z;
7992080167
}else{
7992180168
zData = pC->aRow;
7992280169
}
@@ -80025,12 +80272,11 @@
8002580272
** So we might as well use bogus content rather than reading
8002680273
** content from disk. */
8002780274
static u8 aZero[8]; /* This is the bogus content */
8002880275
sqlite3VdbeSerialGet(aZero, t, pDest);
8002980276
}else{
80030
- rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, !pC->isTable,
80031
- pDest);
80277
+ rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest);
8003280278
if( rc!=SQLITE_OK ) goto abort_due_to_error;
8003380279
sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest);
8003480280
pDest->flags &= ~MEM_Ephem;
8003580281
}
8003680282
}
@@ -82002,51 +82248,40 @@
8200282248
}
8200382249
8200482250
/* Opcode: RowData P1 P2 * * *
8200582251
** Synopsis: r[P2]=data
8200682252
**
82007
-** Write into register P2 the complete row data for cursor P1.
82253
+** Write into register P2 the complete row content for the row at
82254
+** which cursor P1 is currently pointing.
8200882255
** There is no interpretation of the data.
8200982256
** It is just copied onto the P2 register exactly as
8201082257
** it is found in the database file.
8201182258
**
82012
-** If the P1 cursor must be pointing to a valid row (not a NULL row)
82013
-** of a real table, not a pseudo-table.
82014
-*/
82015
-/* Opcode: RowKey P1 P2 * * *
82016
-** Synopsis: r[P2]=key
82017
-**
82018
-** Write into register P2 the complete row key for cursor P1.
82019
-** There is no interpretation of the data.
82020
-** The key is copied onto the P2 register exactly as
82021
-** it is found in the database file.
82259
+** If cursor P1 is an index, then the content is the key of the row.
82260
+** If cursor P2 is a table, then the content extracted is the data.
8202282261
**
8202382262
** If the P1 cursor must be pointing to a valid row (not a NULL row)
8202482263
** of a real table, not a pseudo-table.
8202582264
*/
82026
-case OP_RowKey:
8202782265
case OP_RowData: {
8202882266
VdbeCursor *pC;
8202982267
BtCursor *pCrsr;
8203082268
u32 n;
8203182269
8203282270
pOut = &aMem[pOp->p2];
8203382271
memAboutToChange(p, pOut);
8203482272
82035
- /* Note that RowKey and RowData are really exactly the same instruction */
8203682273
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
8203782274
pC = p->apCsr[pOp->p1];
8203882275
assert( pC!=0 );
8203982276
assert( pC->eCurType==CURTYPE_BTREE );
8204082277
assert( isSorter(pC)==0 );
82041
- assert( pC->isTable || pOp->opcode!=OP_RowData );
82042
- assert( pC->isTable==0 || pOp->opcode==OP_RowData );
8204382278
assert( pC->nullRow==0 );
8204482279
assert( pC->uc.pCursor!=0 );
8204582280
pCrsr = pC->uc.pCursor;
8204682281
82047
- /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or
82282
+ /* The OP_RowData opcodes always follow OP_NotExists or
8204882283
** OP_SeekRowid or OP_Rewind/Op_Next with no intervening instructions
8204982284
** that might invalidate the cursor.
8205082285
** If this where not the case, on of the following assert()s
8205182286
** would fail. Should this ever change (because of changes in the code
8205282287
** generator) then the fix would be to insert a call to
@@ -82067,15 +82302,11 @@
8206782302
if( sqlite3VdbeMemClearAndResize(pOut, MAX(n,32)) ){
8206882303
goto no_mem;
8206982304
}
8207082305
pOut->n = n;
8207182306
MemSetTypeFlag(pOut, MEM_Blob);
82072
- if( pC->isTable==0 ){
82073
- rc = sqlite3BtreeKey(pCrsr, 0, n, pOut->z);
82074
- }else{
82075
- rc = sqlite3BtreeData(pCrsr, 0, n, pOut->z);
82076
- }
82307
+ rc = sqlite3BtreePayload(pCrsr, 0, n, pOut->z);
8207782308
if( rc ) goto abort_due_to_error;
8207882309
pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
8207982310
UPDATE_MAX_BLOBSIZE(pOut);
8208082311
REGISTER_TRACE(pOp->p2, pOut);
8208182312
break;
@@ -83401,17 +83632,17 @@
8340183632
}
8340283633
8340383634
/* Opcode: DecrJumpZero P1 P2 * * *
8340483635
** Synopsis: if (--r[P1])==0 goto P2
8340583636
**
83406
-** Register P1 must hold an integer. Decrement the value in register P1
83407
-** then jump to P2 if the new value is exactly zero.
83637
+** Register P1 must hold an integer. Decrement the value in P1
83638
+** and jump to P2 if the new value is exactly zero.
8340883639
*/
8340983640
case OP_DecrJumpZero: { /* jump, in1 */
8341083641
pIn1 = &aMem[pOp->p1];
8341183642
assert( pIn1->flags&MEM_Int );
83412
- pIn1->u.i--;
83643
+ if( pIn1->u.i>SMALLEST_INT64 ) pIn1->u.i--;
8341383644
VdbeBranchTaken(pIn1->u.i==0, 2);
8341483645
if( pIn1->u.i==0 ) goto jump_to_p2;
8341583646
break;
8341683647
}
8341783648
@@ -84854,11 +85085,11 @@
8485485085
8485585086
/*
8485685087
** Read data from a blob handle.
8485785088
*/
8485885089
SQLITE_API int sqlite3_blob_read(sqlite3_blob *pBlob, void *z, int n, int iOffset){
84859
- return blobReadWrite(pBlob, z, n, iOffset, sqlite3BtreeData);
85090
+ return blobReadWrite(pBlob, z, n, iOffset, sqlite3BtreePayloadChecked);
8486085091
}
8486185092
8486285093
/*
8486385094
** Write data to a blob handle.
8486485095
*/
@@ -90235,11 +90466,11 @@
9023590466
** can be attached to pRight to cause this node to take ownership of
9023690467
** pVector. Typically there will be multiple TK_SELECT_COLUMN nodes
9023790468
** with the same pLeft pointer to the pVector, but only one of them
9023890469
** will own the pVector.
9023990470
*/
90240
- pRet = sqlite3PExpr(pParse, TK_SELECT_COLUMN, 0, 0, 0);
90471
+ pRet = sqlite3PExpr(pParse, TK_SELECT_COLUMN, 0, 0);
9024190472
if( pRet ){
9024290473
pRet->iColumn = iField;
9024390474
pRet->pLeft = pVector;
9024490475
}
9024590476
assert( pRet==0 || pRet->iTable==0 );
@@ -90627,19 +90858,23 @@
9062790858
*/
9062890859
SQLITE_PRIVATE Expr *sqlite3PExpr(
9062990860
Parse *pParse, /* Parsing context */
9063090861
int op, /* Expression opcode */
9063190862
Expr *pLeft, /* Left operand */
90632
- Expr *pRight, /* Right operand */
90633
- const Token *pToken /* Argument token */
90863
+ Expr *pRight /* Right operand */
9063490864
){
9063590865
Expr *p;
9063690866
if( op==TK_AND && pParse->nErr==0 ){
9063790867
/* Take advantage of short-circuit false optimization for AND */
9063890868
p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
9063990869
}else{
90640
- p = sqlite3ExprAlloc(pParse->db, op & TKFLG_MASK, pToken, 1);
90870
+ p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr));
90871
+ if( p ){
90872
+ memset(p, 0, sizeof(Expr));
90873
+ p->op = op & TKFLG_MASK;
90874
+ p->iAgg = -1;
90875
+ }
9064190876
sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
9064290877
}
9064390878
if( p ) {
9064490879
sqlite3ExprCheckHeight(pParse, p->nHeight);
9064590880
}
@@ -92158,10 +92393,32 @@
9215892393
SQLITE_PRIVATE void sqlite3SubselectError(Parse *pParse, int nActual, int nExpect){
9215992394
const char *zFmt = "sub-select returns %d columns - expected %d";
9216092395
sqlite3ErrorMsg(pParse, zFmt, nActual, nExpect);
9216192396
}
9216292397
#endif
92398
+
92399
+/*
92400
+** Expression pExpr is a vector that has been used in a context where
92401
+** it is not permitted. If pExpr is a sub-select vector, this routine
92402
+** loads the Parse object with a message of the form:
92403
+**
92404
+** "sub-select returns N columns - expected 1"
92405
+**
92406
+** Or, if it is a regular scalar vector:
92407
+**
92408
+** "row value misused"
92409
+*/
92410
+SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse *pParse, Expr *pExpr){
92411
+#ifndef SQLITE_OMIT_SUBQUERY
92412
+ if( pExpr->flags & EP_xIsSelect ){
92413
+ sqlite3SubselectError(pParse, pExpr->x.pSelect->pEList->nExpr, 1);
92414
+ }else
92415
+#endif
92416
+ {
92417
+ sqlite3ErrorMsg(pParse, "row value misused");
92418
+ }
92419
+}
9216392420
9216492421
/*
9216592422
** Generate code for scalar subqueries used as a subquery expression, EXISTS,
9216692423
** or IN operators. Examples:
9216792424
**
@@ -92441,15 +92698,11 @@
9244192698
if( nVector!=pIn->x.pSelect->pEList->nExpr ){
9244292699
sqlite3SubselectError(pParse, pIn->x.pSelect->pEList->nExpr, nVector);
9244392700
return 1;
9244492701
}
9244592702
}else if( nVector!=1 ){
92446
- if( (pIn->pLeft->flags & EP_xIsSelect) ){
92447
- sqlite3SubselectError(pParse, nVector, 1);
92448
- }else{
92449
- sqlite3ErrorMsg(pParse, "row value misused");
92450
- }
92703
+ sqlite3VectorErrorMsg(pParse, pIn->pLeft);
9245192704
return 1;
9245292705
}
9245392706
return 0;
9245492707
}
9245592708
#endif
@@ -92750,26 +93003,26 @@
9275093003
int c;
9275193004
i64 value;
9275293005
const char *z = pExpr->u.zToken;
9275393006
assert( z!=0 );
9275493007
c = sqlite3DecOrHexToI64(z, &value);
92755
- if( c==0 || (c==2 && negFlag) ){
92756
- if( negFlag ){ value = c==2 ? SMALLEST_INT64 : -value; }
92757
- sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, iMem, 0, (u8*)&value, P4_INT64);
92758
- }else{
93008
+ if( c==1 || (c==2 && !negFlag) || (negFlag && value==SMALLEST_INT64)){
9275993009
#ifdef SQLITE_OMIT_FLOATING_POINT
9276093010
sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z);
9276193011
#else
9276293012
#ifndef SQLITE_OMIT_HEX_INTEGER
9276393013
if( sqlite3_strnicmp(z,"0x",2)==0 ){
92764
- sqlite3ErrorMsg(pParse, "hex literal too big: %s", z);
93014
+ sqlite3ErrorMsg(pParse, "hex literal too big: %s%s", negFlag?"-":"",z);
9276593015
}else
9276693016
#endif
9276793017
{
9276893018
codeReal(v, z, negFlag, iMem);
9276993019
}
9277093020
#endif
93021
+ }else{
93022
+ if( negFlag ){ value = c==2 ? SMALLEST_INT64 : -value; }
93023
+ sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, iMem, 0, (u8*)&value, P4_INT64);
9277193024
}
9277293025
}
9277393026
}
9277493027
9277593028
/*
@@ -93104,11 +93357,11 @@
9310493357
}else{
9310593358
int i;
9310693359
iResult = pParse->nMem+1;
9310793360
pParse->nMem += nResult;
9310893361
for(i=0; i<nResult; i++){
93109
- sqlite3ExprCode(pParse, p->x.pList->a[i].pExpr, i+iResult);
93362
+ sqlite3ExprCodeFactorable(pParse, p->x.pList->a[i].pExpr, i+iResult);
9311093363
}
9311193364
}
9311293365
}
9311393366
return iResult;
9311493367
}
@@ -93218,11 +93471,11 @@
9321893471
assert( pExpr->u.zToken[0]!=0 );
9321993472
sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target);
9322093473
if( pExpr->u.zToken[1]!=0 ){
9322193474
assert( pExpr->u.zToken[0]=='?'
9322293475
|| strcmp(pExpr->u.zToken, pParse->azVar[pExpr->iColumn-1])==0 );
93223
- sqlite3VdbeChangeP4(v, -1, pParse->azVar[pExpr->iColumn-1], P4_STATIC);
93476
+ sqlite3VdbeAppendP4(v, pParse->azVar[pExpr->iColumn-1], P4_STATIC);
9322493477
}
9322593478
return target;
9322693479
}
9322793480
case TK_REGISTER: {
9322893481
return pExpr->iTable;
@@ -93975,10 +94228,15 @@
9397594228
compRight.pRight = pExpr->x.pList->a[1].pExpr;
9397694229
exprToRegister(&exprX, exprCodeVector(pParse, &exprX, &regFree1));
9397794230
if( xJump ){
9397894231
xJump(pParse, &exprAnd, dest, jumpIfNull);
9397994232
}else{
94233
+ /* Mark the expression is being from the ON or USING clause of a join
94234
+ ** so that the sqlite3ExprCodeTarget() routine will not attempt to move
94235
+ ** it into the Parse.pConstExpr list. We should use a new bit for this,
94236
+ ** for clarity, but we are out of bits in the Expr.flags field so we
94237
+ ** have to reuse the EP_FromJoin bit. Bummer. */
9398094238
exprX.flags |= EP_FromJoin;
9398194239
sqlite3ExprCodeTarget(pParse, &exprAnd, dest);
9398294240
}
9398394241
sqlite3ReleaseTempReg(pParse, regFree1);
9398494242
@@ -103465,11 +103723,11 @@
103465103723
** DELETE FROM table_a WHERE rowid IN (
103466103724
** SELECT rowid FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
103467103725
** );
103468103726
*/
103469103727
103470
- pSelectRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0);
103728
+ pSelectRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0);
103471103729
if( pSelectRowid == 0 ) goto limit_where_cleanup;
103472103730
pEList = sqlite3ExprListAppend(pParse, 0, pSelectRowid);
103473103731
if( pEList == 0 ) goto limit_where_cleanup;
103474103732
103475103733
/* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree
@@ -103484,12 +103742,12 @@
103484103742
pSelect = sqlite3SelectNew(pParse,pEList,pSelectSrc,pWhere,0,0,
103485103743
pOrderBy,0,pLimit,pOffset);
103486103744
if( pSelect == 0 ) return 0;
103487103745
103488103746
/* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
103489
- pWhereRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0);
103490
- pInClause = pWhereRowid ? sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0) : 0;
103747
+ pWhereRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0);
103748
+ pInClause = pWhereRowid ? sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0) : 0;
103491103749
sqlite3PExprAddSelect(pParse, pInClause, pSelect);
103492103750
return pInClause;
103493103751
103494103752
limit_where_cleanup:
103495103753
sqlite3ExprDelete(pParse->db, pWhere);
@@ -103796,11 +104054,11 @@
103796104054
sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
103797104055
VdbeCoverage(v);
103798104056
}
103799104057
}else if( pPk ){
103800104058
addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v);
103801
- sqlite3VdbeAddOp2(v, OP_RowKey, iEphCur, iKey);
104059
+ sqlite3VdbeAddOp2(v, OP_RowData, iEphCur, iKey);
103802104060
assert( nKey==0 ); /* OP_Found will use a composite key */
103803104061
}else{
103804104062
addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
103805104063
VdbeCoverage(v);
103806104064
assert( nKey==1 );
@@ -104013,11 +104271,11 @@
104013104271
*/
104014104272
if( pTab->pSelect==0 ){
104015104273
u8 p5 = 0;
104016104274
sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
104017104275
sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
104018
- sqlite3VdbeChangeP4(v, -1, (char*)pTab, P4_TABLE);
104276
+ sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE);
104019104277
if( eMode!=ONEPASS_OFF ){
104020104278
sqlite3VdbeChangeP5(v, OPFLAG_AUXDELETE);
104021104279
}
104022104280
if( iIdxNoSeek>=0 ){
104023104281
sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek);
@@ -104790,13 +105048,23 @@
104790105048
/* If SQLITE_CASE_SENSITIVE_LIKE is defined, then the LIKE operator
104791105049
** is case sensitive causing 'a' LIKE 'A' to be false */
104792105050
static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 };
104793105051
104794105052
/*
104795
-** Compare two UTF-8 strings for equality where the first string can
104796
-** potentially be a "glob" or "like" expression. Return true (1) if they
104797
-** are the same and false (0) if they are different.
105053
+** Possible error returns from patternMatch()
105054
+*/
105055
+#define SQLITE_MATCH 0
105056
+#define SQLITE_NOMATCH 1
105057
+#define SQLITE_NOWILDCARDMATCH 2
105058
+
105059
+/*
105060
+** Compare two UTF-8 strings for equality where the first string is
105061
+** a GLOB or LIKE expression. Return values:
105062
+**
105063
+** SQLITE_MATCH: Match
105064
+** SQLITE_NOMATCH: No match
105065
+** SQLITE_NOWILDCARDMATCH: No match in spite of having * or % wildcards.
104798105066
**
104799105067
** Globbing rules:
104800105068
**
104801105069
** '*' Matches any sequence of zero or more characters.
104802105070
**
@@ -104843,71 +105111,76 @@
104843105111
/* Skip over multiple "*" characters in the pattern. If there
104844105112
** are also "?" characters, skip those as well, but consume a
104845105113
** single character of the input string for each "?" skipped */
104846105114
while( (c=Utf8Read(zPattern)) == matchAll || c == matchOne ){
104847105115
if( c==matchOne && sqlite3Utf8Read(&zString)==0 ){
104848
- return 0;
105116
+ return SQLITE_NOWILDCARDMATCH;
104849105117
}
104850105118
}
104851105119
if( c==0 ){
104852
- return 1; /* "*" at the end of the pattern matches */
105120
+ return SQLITE_MATCH; /* "*" at the end of the pattern matches */
104853105121
}else if( c==matchOther ){
104854105122
if( pInfo->matchSet==0 ){
104855105123
c = sqlite3Utf8Read(&zPattern);
104856
- if( c==0 ) return 0;
105124
+ if( c==0 ) return SQLITE_NOWILDCARDMATCH;
104857105125
}else{
104858105126
/* "[...]" immediately follows the "*". We have to do a slow
104859105127
** recursive search in this case, but it is an unusual case. */
104860105128
assert( matchOther<0x80 ); /* '[' is a single-byte character */
104861
- while( *zString
104862
- && patternCompare(&zPattern[-1],zString,pInfo,matchOther)==0 ){
105129
+ while( *zString ){
105130
+ int bMatch = patternCompare(&zPattern[-1],zString,pInfo,matchOther);
105131
+ if( bMatch!=SQLITE_NOMATCH ) return bMatch;
104863105132
SQLITE_SKIP_UTF8(zString);
104864105133
}
104865
- return *zString!=0;
105134
+ return SQLITE_NOWILDCARDMATCH;
104866105135
}
104867105136
}
104868105137
104869105138
/* At this point variable c contains the first character of the
104870105139
** pattern string past the "*". Search in the input string for the
104871
- ** first matching character and recursively contine the match from
105140
+ ** first matching character and recursively continue the match from
104872105141
** that point.
104873105142
**
104874105143
** For a case-insensitive search, set variable cx to be the same as
104875105144
** c but in the other case and search the input string for either
104876105145
** c or cx.
104877105146
*/
104878105147
if( c<=0x80 ){
104879105148
u32 cx;
105149
+ int bMatch;
104880105150
if( noCase ){
104881105151
cx = sqlite3Toupper(c);
104882105152
c = sqlite3Tolower(c);
104883105153
}else{
104884105154
cx = c;
104885105155
}
104886105156
while( (c2 = *(zString++))!=0 ){
104887105157
if( c2!=c && c2!=cx ) continue;
104888
- if( patternCompare(zPattern,zString,pInfo,matchOther) ) return 1;
105158
+ bMatch = patternCompare(zPattern,zString,pInfo,matchOther);
105159
+ if( bMatch!=SQLITE_NOMATCH ) return bMatch;
104889105160
}
104890105161
}else{
105162
+ int bMatch;
104891105163
while( (c2 = Utf8Read(zString))!=0 ){
104892105164
if( c2!=c ) continue;
104893
- if( patternCompare(zPattern,zString,pInfo,matchOther) ) return 1;
105165
+ bMatch = patternCompare(zPattern,zString,pInfo,matchOther);
105166
+ if( bMatch!=SQLITE_NOMATCH ) return bMatch;
104894105167
}
104895105168
}
104896
- return 0;
105169
+ return SQLITE_NOWILDCARDMATCH;
104897105170
}
104898105171
if( c==matchOther ){
104899105172
if( pInfo->matchSet==0 ){
104900105173
c = sqlite3Utf8Read(&zPattern);
104901
- if( c==0 ) return 0;
105174
+ if( c==0 ) return SQLITE_NOMATCH;
104902105175
zEscaped = zPattern;
104903105176
}else{
104904105177
u32 prior_c = 0;
104905105178
int seen = 0;
104906105179
int invert = 0;
104907105180
c = sqlite3Utf8Read(&zString);
104908
- if( c==0 ) return 0;
105181
+ if( c==0 ) return SQLITE_NOMATCH;
104909105182
c2 = sqlite3Utf8Read(&zPattern);
104910105183
if( c2=='^' ){
104911105184
invert = 1;
104912105185
c2 = sqlite3Utf8Read(&zPattern);
104913105186
}
@@ -104927,11 +105200,11 @@
104927105200
prior_c = c2;
104928105201
}
104929105202
c2 = sqlite3Utf8Read(&zPattern);
104930105203
}
104931105204
if( c2==0 || (seen ^ invert)==0 ){
104932
- return 0;
105205
+ return SQLITE_NOMATCH;
104933105206
}
104934105207
continue;
104935105208
}
104936105209
}
104937105210
c2 = Utf8Read(zString);
@@ -104938,27 +105211,29 @@
104938105211
if( c==c2 ) continue;
104939105212
if( noCase && sqlite3Tolower(c)==sqlite3Tolower(c2) && c<0x80 && c2<0x80 ){
104940105213
continue;
104941105214
}
104942105215
if( c==matchOne && zPattern!=zEscaped && c2!=0 ) continue;
104943
- return 0;
105216
+ return SQLITE_NOMATCH;
104944105217
}
104945
- return *zString==0;
105218
+ return *zString==0 ? SQLITE_MATCH : SQLITE_NOMATCH;
104946105219
}
104947105220
104948105221
/*
104949
-** The sqlite3_strglob() interface.
105222
+** The sqlite3_strglob() interface. Return 0 on a match (like strcmp()) and
105223
+** non-zero if there is no match.
104950105224
*/
104951105225
SQLITE_API int sqlite3_strglob(const char *zGlobPattern, const char *zString){
104952
- return patternCompare((u8*)zGlobPattern, (u8*)zString, &globInfo, '[')==0;
105226
+ return patternCompare((u8*)zGlobPattern, (u8*)zString, &globInfo, '[');
104953105227
}
104954105228
104955105229
/*
104956
-** The sqlite3_strlike() interface.
105230
+** The sqlite3_strlike() interface. Return 0 on a match and non-zero for
105231
+** a miss - like strcmp().
104957105232
*/
104958105233
SQLITE_API int sqlite3_strlike(const char *zPattern, const char *zStr, unsigned int esc){
104959
- return patternCompare((u8*)zPattern, (u8*)zStr, &likeInfoNorm, esc)==0;
105234
+ return patternCompare((u8*)zPattern, (u8*)zStr, &likeInfoNorm, esc);
104960105235
}
104961105236
104962105237
/*
104963105238
** Count the number of times that the LIKE operator (or GLOB which is
104964105239
** just a variation of LIKE) gets called. This is used for testing
@@ -105035,11 +105310,11 @@
105035105310
}
105036105311
if( zA && zB ){
105037105312
#ifdef SQLITE_TEST
105038105313
sqlite3_like_count++;
105039105314
#endif
105040
- sqlite3_result_int(context, patternCompare(zB, zA, pInfo, escape));
105315
+ sqlite3_result_int(context, patternCompare(zB, zA, pInfo, escape)==SQLITE_MATCH);
105041105316
}
105042105317
}
105043105318
105044105319
/*
105045105320
** Implementation of the NULLIF(x,y) function. The result is the first
@@ -106628,11 +106903,11 @@
106628106903
pLeft = exprTableRegister(pParse, pTab, regData, iCol);
106629106904
iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
106630106905
assert( iCol>=0 );
106631106906
zCol = pFKey->pFrom->aCol[iCol].zName;
106632106907
pRight = sqlite3Expr(db, TK_ID, zCol);
106633
- pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0);
106908
+ pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight);
106634106909
pWhere = sqlite3ExprAnd(db, pWhere, pEq);
106635106910
}
106636106911
106637106912
/* If the child table is the same as the parent table, then add terms
106638106913
** to the WHERE clause that prevent this entry from being scanned.
@@ -106650,24 +106925,24 @@
106650106925
Expr *pLeft; /* Value from parent table row */
106651106926
Expr *pRight; /* Column ref to child table */
106652106927
if( HasRowid(pTab) ){
106653106928
pLeft = exprTableRegister(pParse, pTab, regData, -1);
106654106929
pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
106655
- pNe = sqlite3PExpr(pParse, TK_NE, pLeft, pRight, 0);
106930
+ pNe = sqlite3PExpr(pParse, TK_NE, pLeft, pRight);
106656106931
}else{
106657106932
Expr *pEq, *pAll = 0;
106658106933
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
106659106934
assert( pIdx!=0 );
106660106935
for(i=0; i<pPk->nKeyCol; i++){
106661106936
i16 iCol = pIdx->aiColumn[i];
106662106937
assert( iCol>=0 );
106663106938
pLeft = exprTableRegister(pParse, pTab, regData, iCol);
106664106939
pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol);
106665
- pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0);
106940
+ pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight);
106666106941
pAll = sqlite3ExprAnd(db, pAll, pEq);
106667106942
}
106668
- pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0, 0);
106943
+ pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0);
106669106944
}
106670106945
pWhere = sqlite3ExprAnd(db, pWhere, pNe);
106671106946
}
106672106947
106673106948
/* Resolve the references in the WHERE clause. */
@@ -107249,14 +107524,13 @@
107249107524
** that the affinity and collation sequence associated with the
107250107525
** parent table are used for the comparison. */
107251107526
pEq = sqlite3PExpr(pParse, TK_EQ,
107252107527
sqlite3PExpr(pParse, TK_DOT,
107253107528
sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
107254
- sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
107255
- , 0),
107529
+ sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)),
107256107530
sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0)
107257
- , 0);
107531
+ );
107258107532
pWhere = sqlite3ExprAnd(db, pWhere, pEq);
107259107533
107260107534
/* For ON UPDATE, construct the next term of the WHEN clause.
107261107535
** The final WHEN clause will be like this:
107262107536
**
@@ -107264,27 +107538,24 @@
107264107538
*/
107265107539
if( pChanges ){
107266107540
pEq = sqlite3PExpr(pParse, TK_IS,
107267107541
sqlite3PExpr(pParse, TK_DOT,
107268107542
sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
107269
- sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
107270
- 0),
107543
+ sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)),
107271107544
sqlite3PExpr(pParse, TK_DOT,
107272107545
sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
107273
- sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
107274
- 0),
107275
- 0);
107546
+ sqlite3ExprAlloc(db, TK_ID, &tToCol, 0))
107547
+ );
107276107548
pWhen = sqlite3ExprAnd(db, pWhen, pEq);
107277107549
}
107278107550
107279107551
if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){
107280107552
Expr *pNew;
107281107553
if( action==OE_Cascade ){
107282107554
pNew = sqlite3PExpr(pParse, TK_DOT,
107283107555
sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
107284
- sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
107285
- , 0);
107556
+ sqlite3ExprAlloc(db, TK_ID, &tToCol, 0));
107286107557
}else if( action==OE_SetDflt ){
107287107558
Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt;
107288107559
if( pDflt ){
107289107560
pNew = sqlite3ExprDup(db, pDflt, 0);
107290107561
}else{
@@ -107336,11 +107607,11 @@
107336107607
107337107608
pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
107338107609
pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
107339107610
pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
107340107611
if( pWhen ){
107341
- pWhen = sqlite3PExpr(pParse, TK_NOT, pWhen, 0, 0);
107612
+ pWhen = sqlite3PExpr(pParse, TK_NOT, pWhen, 0);
107342107613
pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
107343107614
}
107344107615
}
107345107616
107346107617
/* Re-enable the lookaside buffer, if it was disabled earlier. */
@@ -108760,12 +109031,13 @@
108760109031
/* Fall through */
108761109032
case OE_Rollback:
108762109033
case OE_Fail: {
108763109034
char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
108764109035
pTab->aCol[i].zName);
108765
- sqlite3VdbeAddOp4(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, onError,
108766
- regNewData+1+i, zMsg, P4_DYNAMIC);
109036
+ sqlite3VdbeAddOp3(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, onError,
109037
+ regNewData+1+i);
109038
+ sqlite3VdbeAppendP4(v, zMsg, P4_DYNAMIC);
108767109039
sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
108768109040
VdbeCoverage(v);
108769109041
break;
108770109042
}
108771109043
case OE_Ignore: {
@@ -108903,11 +109175,11 @@
108903109175
/* This OP_Delete opcode fires the pre-update-hook only. It does
108904109176
** not modify the b-tree. It is more efficient to let the coming
108905109177
** OP_Insert replace the existing entry than it is to delete the
108906109178
** existing entry and then insert a new one. */
108907109179
sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, OPFLAG_ISNOOP);
108908
- sqlite3VdbeChangeP4(v, -1, (char *)pTab, P4_TABLE);
109180
+ sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
108909109181
}
108910109182
#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
108911109183
if( pTab->pIndex ){
108912109184
sqlite3MultiWrite(pParse);
108913109185
sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,-1);
@@ -109180,11 +109452,11 @@
109180109452
if( useSeekResult ){
109181109453
pik_flags |= OPFLAG_USESEEKRESULT;
109182109454
}
109183109455
sqlite3VdbeAddOp3(v, OP_Insert, iDataCur, regRec, regNewData);
109184109456
if( !pParse->nested ){
109185
- sqlite3VdbeChangeP4(v, -1, (char *)pTab, P4_TABLE);
109457
+ sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
109186109458
}
109187109459
sqlite3VdbeChangeP5(v, pik_flags);
109188109460
}
109189109461
109190109462
/*
@@ -109611,11 +109883,11 @@
109611109883
sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest);
109612109884
sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
109613109885
sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
109614109886
VdbeComment((v, "%s", pDestIdx->zName));
109615109887
addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
109616
- sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
109888
+ sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
109617109889
if( db->flags & SQLITE_Vacuum ){
109618109890
/* This INSERT command is part of a VACUUM operation, which guarantees
109619109891
** that the destination table is empty. If all indexed columns use
109620109892
** collation sequence BINARY, then it can also be assumed that the
109621109893
** index will be populated by inserting keys in strictly sorted
@@ -114820,11 +115092,11 @@
114820115092
assert( pSrc->a[iRight].pTab );
114821115093
114822115094
pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iColLeft);
114823115095
pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
114824115096
114825
- pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2, 0);
115097
+ pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2);
114826115098
if( pEq && isOuterJoin ){
114827115099
ExprSetProperty(pEq, EP_FromJoin);
114828115100
assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) );
114829115101
ExprSetVVAProperty(pEq, EP_NoReduce);
114830115102
pEq->iRightJoinTable = (i16)pE2->iTable;
@@ -116992,11 +117264,11 @@
116992117264
iBreak = sqlite3VdbeMakeLabel(v);
116993117265
iCont = sqlite3VdbeMakeLabel(v);
116994117266
computeLimitRegisters(pParse, p, iBreak);
116995117267
sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
116996117268
r1 = sqlite3GetTempReg(pParse);
116997
- iStart = sqlite3VdbeAddOp2(v, OP_RowKey, tab1, r1);
117269
+ iStart = sqlite3VdbeAddOp2(v, OP_RowData, tab1, r1);
116998117270
sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0); VdbeCoverage(v);
116999117271
sqlite3ReleaseTempReg(pParse, r1);
117000117272
selectInnerLoop(pParse, p, p->pEList, tab1,
117001117273
0, 0, &dest, iCont, iBreak);
117002117274
sqlite3VdbeResolveLabel(v, iCont);
@@ -117619,12 +117891,12 @@
117619117891
}
117620117892
#endif
117621117893
117622117894
#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
117623117895
/* Forward Declarations */
117624
-static void substExprList(sqlite3*, ExprList*, int, ExprList*);
117625
-static void substSelect(sqlite3*, Select *, int, ExprList*, int);
117896
+static void substExprList(Parse*, ExprList*, int, ExprList*);
117897
+static void substSelect(Parse*, Select *, int, ExprList*, int);
117626117898
117627117899
/*
117628117900
** Scan through the expression pExpr. Replace every reference to
117629117901
** a column in table number iTable with a copy of the iColumn-th
117630117902
** entry in pEList. (But leave references to the ROWID column
@@ -117636,52 +117908,62 @@
117636117908
** FORM clause entry is iTable. This routine make the necessary
117637117909
** changes to pExpr so that it refers directly to the source table
117638117910
** of the subquery rather the result set of the subquery.
117639117911
*/
117640117912
static Expr *substExpr(
117641
- sqlite3 *db, /* Report malloc errors to this connection */
117913
+ Parse *pParse, /* Report errors here */
117642117914
Expr *pExpr, /* Expr in which substitution occurs */
117643117915
int iTable, /* Table to be substituted */
117644117916
ExprList *pEList /* Substitute expressions */
117645117917
){
117918
+ sqlite3 *db = pParse->db;
117646117919
if( pExpr==0 ) return 0;
117647117920
if( pExpr->op==TK_COLUMN && pExpr->iTable==iTable ){
117648117921
if( pExpr->iColumn<0 ){
117649117922
pExpr->op = TK_NULL;
117650117923
}else{
117651117924
Expr *pNew;
117925
+ Expr *pCopy = pEList->a[pExpr->iColumn].pExpr;
117652117926
assert( pEList!=0 && pExpr->iColumn<pEList->nExpr );
117653117927
assert( pExpr->pLeft==0 && pExpr->pRight==0 );
117654
- pNew = sqlite3ExprDup(db, pEList->a[pExpr->iColumn].pExpr, 0);
117655
- sqlite3ExprDelete(db, pExpr);
117656
- pExpr = pNew;
117928
+ if( sqlite3ExprIsVector(pCopy) ){
117929
+ sqlite3VectorErrorMsg(pParse, pCopy);
117930
+ }else{
117931
+ pNew = sqlite3ExprDup(db, pCopy, 0);
117932
+ if( pNew && (pExpr->flags & EP_FromJoin) ){
117933
+ pNew->iRightJoinTable = pExpr->iRightJoinTable;
117934
+ pNew->flags |= EP_FromJoin;
117935
+ }
117936
+ sqlite3ExprDelete(db, pExpr);
117937
+ pExpr = pNew;
117938
+ }
117657117939
}
117658117940
}else{
117659
- pExpr->pLeft = substExpr(db, pExpr->pLeft, iTable, pEList);
117660
- pExpr->pRight = substExpr(db, pExpr->pRight, iTable, pEList);
117941
+ pExpr->pLeft = substExpr(pParse, pExpr->pLeft, iTable, pEList);
117942
+ pExpr->pRight = substExpr(pParse, pExpr->pRight, iTable, pEList);
117661117943
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
117662
- substSelect(db, pExpr->x.pSelect, iTable, pEList, 1);
117944
+ substSelect(pParse, pExpr->x.pSelect, iTable, pEList, 1);
117663117945
}else{
117664
- substExprList(db, pExpr->x.pList, iTable, pEList);
117946
+ substExprList(pParse, pExpr->x.pList, iTable, pEList);
117665117947
}
117666117948
}
117667117949
return pExpr;
117668117950
}
117669117951
static void substExprList(
117670
- sqlite3 *db, /* Report malloc errors here */
117952
+ Parse *pParse, /* Report errors here */
117671117953
ExprList *pList, /* List to scan and in which to make substitutes */
117672117954
int iTable, /* Table to be substituted */
117673117955
ExprList *pEList /* Substitute values */
117674117956
){
117675117957
int i;
117676117958
if( pList==0 ) return;
117677117959
for(i=0; i<pList->nExpr; i++){
117678
- pList->a[i].pExpr = substExpr(db, pList->a[i].pExpr, iTable, pEList);
117960
+ pList->a[i].pExpr = substExpr(pParse, pList->a[i].pExpr, iTable, pEList);
117679117961
}
117680117962
}
117681117963
static void substSelect(
117682
- sqlite3 *db, /* Report malloc errors here */
117964
+ Parse *pParse, /* Report errors here */
117683117965
Select *p, /* SELECT statement in which to make substitutions */
117684117966
int iTable, /* Table to be replaced */
117685117967
ExprList *pEList, /* Substitute values */
117686117968
int doPrior /* Do substitutes on p->pPrior too */
117687117969
){
@@ -117688,21 +117970,21 @@
117688117970
SrcList *pSrc;
117689117971
struct SrcList_item *pItem;
117690117972
int i;
117691117973
if( !p ) return;
117692117974
do{
117693
- substExprList(db, p->pEList, iTable, pEList);
117694
- substExprList(db, p->pGroupBy, iTable, pEList);
117695
- substExprList(db, p->pOrderBy, iTable, pEList);
117696
- p->pHaving = substExpr(db, p->pHaving, iTable, pEList);
117697
- p->pWhere = substExpr(db, p->pWhere, iTable, pEList);
117975
+ substExprList(pParse, p->pEList, iTable, pEList);
117976
+ substExprList(pParse, p->pGroupBy, iTable, pEList);
117977
+ substExprList(pParse, p->pOrderBy, iTable, pEList);
117978
+ p->pHaving = substExpr(pParse, p->pHaving, iTable, pEList);
117979
+ p->pWhere = substExpr(pParse, p->pWhere, iTable, pEList);
117698117980
pSrc = p->pSrc;
117699117981
assert( pSrc!=0 );
117700117982
for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
117701
- substSelect(db, pItem->pSelect, iTable, pEList, 1);
117983
+ substSelect(pParse, pItem->pSelect, iTable, pEList, 1);
117702117984
if( pItem->fg.isTabFunc ){
117703
- substExprList(db, pItem->u1.pFuncArg, iTable, pEList);
117985
+ substExprList(pParse, pItem->u1.pFuncArg, iTable, pEList);
117704117986
}
117705117987
}
117706117988
}while( doPrior && (p = p->pPrior)!=0 );
117707117989
}
117708117990
#endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
@@ -118223,11 +118505,11 @@
118223118505
assert( pParent->pGroupBy==0 );
118224118506
pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
118225118507
}else{
118226118508
pParent->pWhere = sqlite3ExprAnd(db, pWhere, pParent->pWhere);
118227118509
}
118228
- substSelect(db, pParent, iParent, pSub->pEList, 0);
118510
+ substSelect(pParse, pParent, iParent, pSub->pEList, 0);
118229118511
118230118512
/* The flattened query is distinct if either the inner or the
118231118513
** outer query is distinct.
118232118514
*/
118233118515
pParent->selFlags |= pSub->selFlags & SF_Distinct;
@@ -118297,11 +118579,11 @@
118297118579
**
118298118580
** Return 0 if no changes are made and non-zero if one or more WHERE clause
118299118581
** terms are duplicated into the subquery.
118300118582
*/
118301118583
static int pushDownWhereTerms(
118302
- sqlite3 *db, /* The database connection (for malloc()) */
118584
+ Parse *pParse, /* Parse context (for malloc() and error reporting) */
118303118585
Select *pSubq, /* The subquery whose WHERE clause is to be augmented */
118304118586
Expr *pWhere, /* The WHERE clause of the outer query */
118305118587
int iCursor /* Cursor number of the subquery */
118306118588
){
118307118589
Expr *pNew;
@@ -118318,20 +118600,20 @@
118318118600
}
118319118601
if( pSubq->pLimit!=0 ){
118320118602
return 0; /* restriction (3) */
118321118603
}
118322118604
while( pWhere->op==TK_AND ){
118323
- nChng += pushDownWhereTerms(db, pSubq, pWhere->pRight, iCursor);
118605
+ nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, iCursor);
118324118606
pWhere = pWhere->pLeft;
118325118607
}
118326118608
if( ExprHasProperty(pWhere,EP_FromJoin) ) return 0; /* restriction 5 */
118327118609
if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
118328118610
nChng++;
118329118611
while( pSubq ){
118330
- pNew = sqlite3ExprDup(db, pWhere, 0);
118331
- pNew = substExpr(db, pNew, iCursor, pSubq->pEList);
118332
- pSubq->pWhere = sqlite3ExprAnd(db, pSubq->pWhere, pNew);
118612
+ pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
118613
+ pNew = substExpr(pParse, pNew, iCursor, pSubq->pEList);
118614
+ pSubq->pWhere = sqlite3ExprAnd(pParse->db, pSubq->pWhere, pNew);
118333118615
pSubq = pSubq->pPrior;
118334118616
}
118335118617
}
118336118618
return nChng;
118337118619
}
@@ -118957,14 +119239,14 @@
118957119239
zColname = zName;
118958119240
zToFree = 0;
118959119241
if( longNames || pTabList->nSrc>1 ){
118960119242
Expr *pLeft;
118961119243
pLeft = sqlite3Expr(db, TK_ID, zTabName);
118962
- pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
119244
+ pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
118963119245
if( zSchemaName ){
118964119246
pLeft = sqlite3Expr(db, TK_ID, zSchemaName);
118965
- pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pExpr, 0);
119247
+ pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pExpr);
118966119248
}
118967119249
if( longNames ){
118968119250
zColname = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
118969119251
zToFree = zColname;
118970119252
}
@@ -119197,12 +119479,12 @@
119197119479
int i;
119198119480
struct AggInfo_func *pF;
119199119481
for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
119200119482
ExprList *pList = pF->pExpr->x.pList;
119201119483
assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
119202
- sqlite3VdbeAddOp4(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0, 0,
119203
- (void*)pF->pFunc, P4_FUNCDEF);
119484
+ sqlite3VdbeAddOp2(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0);
119485
+ sqlite3VdbeAppendP4(v, pF->pFunc, P4_FUNCDEF);
119204119486
}
119205119487
}
119206119488
119207119489
/*
119208119490
** Update the accumulator memory cells for an aggregate based on
@@ -119249,12 +119531,12 @@
119249119531
pColl = pParse->db->pDfltColl;
119250119532
}
119251119533
if( regHit==0 && pAggInfo->nAccumulator ) regHit = ++pParse->nMem;
119252119534
sqlite3VdbeAddOp4(v, OP_CollSeq, regHit, 0, 0, (char *)pColl, P4_COLLSEQ);
119253119535
}
119254
- sqlite3VdbeAddOp4(v, OP_AggStep0, 0, regAgg, pF->iMem,
119255
- (void*)pF->pFunc, P4_FUNCDEF);
119536
+ sqlite3VdbeAddOp3(v, OP_AggStep0, 0, regAgg, pF->iMem);
119537
+ sqlite3VdbeAppendP4(v, pF->pFunc, P4_FUNCDEF);
119256119538
sqlite3VdbeChangeP5(v, (u8)nArg);
119257119539
sqlite3ExprCacheAffinityChange(pParse, regAgg, nArg);
119258119540
sqlite3ReleaseTempRange(pParse, regAgg, nArg);
119259119541
if( addrNext ){
119260119542
sqlite3VdbeResolveLabel(v, addrNext);
@@ -119484,11 +119766,11 @@
119484119766
119485119767
/* Make copies of constant WHERE-clause terms in the outer query down
119486119768
** inside the subquery. This can help the subquery to run more efficiently.
119487119769
*/
119488119770
if( (pItem->fg.jointype & JT_OUTER)==0
119489
- && pushDownWhereTerms(db, pSub, p->pWhere, pItem->iCursor)
119771
+ && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor)
119490119772
){
119491119773
#if SELECTTRACE_ENABLED
119492119774
if( sqlite3SelectTrace & 0x100 ){
119493119775
SELECTTRACE(0x100,pParse,p,("After WHERE-clause push-down:\n"));
119494119776
sqlite3TreeViewSelect(0, p, 0);
@@ -121570,11 +121852,11 @@
121570121852
VdbeComment((v, "%s.%s", pTab->zName, pCol->zName));
121571121853
assert( i<pTab->nCol );
121572121854
sqlite3ValueFromExpr(sqlite3VdbeDb(v), pCol->pDflt, enc,
121573121855
pCol->affinity, &pValue);
121574121856
if( pValue ){
121575
- sqlite3VdbeChangeP4(v, -1, (const char *)pValue, P4_MEM);
121857
+ sqlite3VdbeAppendP4(v, pValue, P4_MEM);
121576121858
}
121577121859
#ifndef SQLITE_OMIT_FLOATING_POINT
121578121860
if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){
121579121861
sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
121580121862
}
@@ -121953,11 +122235,11 @@
121953122235
VdbeCoverageIf(v, pPk==0);
121954122236
VdbeCoverageIf(v, pPk!=0);
121955122237
}else if( pPk ){
121956122238
labelContinue = sqlite3VdbeMakeLabel(v);
121957122239
sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak); VdbeCoverage(v);
121958
- addrTop = sqlite3VdbeAddOp2(v, OP_RowKey, iEph, regKey);
122240
+ addrTop = sqlite3VdbeAddOp2(v, OP_RowData, iEph, regKey);
121959122241
sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey, 0);
121960122242
VdbeCoverage(v);
121961122243
}else{
121962122244
labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet, labelBreak,
121963122245
regOldRowid);
@@ -122111,11 +122393,11 @@
122111122393
sqlite3VdbeAddOp3(v, OP_Delete, iDataCur,
122112122394
OPFLAG_ISUPDATE | ((hasFK || chngKey || pPk!=0) ? 0 : OPFLAG_ISNOOP),
122113122395
regNewRowid
122114122396
);
122115122397
if( !pParse->nested ){
122116
- sqlite3VdbeChangeP4(v, -1, (char*)pTab, P4_TABLE);
122398
+ sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
122117122399
}
122118122400
#else
122119122401
if( hasFK || chngKey || pPk!=0 ){
122120122402
sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
122121122403
}
@@ -125607,11 +125889,11 @@
125607125889
}
125608125890
sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg);
125609125891
sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1);
125610125892
sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg,
125611125893
pLoop->u.vtab.idxStr,
125612
- pLoop->u.vtab.needFree ? P4_MPRINTF : P4_STATIC);
125894
+ pLoop->u.vtab.needFree ? P4_DYNAMIC : P4_STATIC);
125613125895
VdbeCoverage(v);
125614125896
pLoop->u.vtab.needFree = 0;
125615125897
pLevel->p1 = iCur;
125616125898
pLevel->op = pWInfo->eOnePass ? OP_Noop : OP_VNext;
125617125899
pLevel->p2 = sqlite3VdbeCurrentAddr(v);
@@ -125640,11 +125922,11 @@
125640125922
sqlite3VdbeAddOp3(v, pOp->opcode, pOp->p1, pOp->p2, pOp->p3);
125641125923
}
125642125924
125643125925
/* Generate code that will continue to the next row if
125644125926
** the IN constraint is not satisfied */
125645
- pCompare = sqlite3PExpr(pParse, TK_EQ, 0, 0, 0);
125927
+ pCompare = sqlite3PExpr(pParse, TK_EQ, 0, 0);
125646125928
assert( pCompare!=0 || db->mallocFailed );
125647125929
if( pCompare ){
125648125930
pCompare->pLeft = pTerm->pExpr->pLeft;
125649125931
pCompare->pRight = pRight = sqlite3Expr(db, TK_REGISTER, 0);
125650125932
if( pRight ){
@@ -126239,11 +126521,11 @@
126239126521
testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
126240126522
pExpr = sqlite3ExprDup(db, pExpr, 0);
126241126523
pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr);
126242126524
}
126243126525
if( pAndExpr ){
126244
- pAndExpr = sqlite3PExpr(pParse, TK_AND|TKFLG_DONTFOLD, 0, pAndExpr, 0);
126526
+ pAndExpr = sqlite3PExpr(pParse, TK_AND|TKFLG_DONTFOLD, 0, pAndExpr);
126245126527
}
126246126528
}
126247126529
126248126530
/* Run a separate WHERE clause for each term of the OR clause. After
126249126531
** eliminating duplicates from other WHERE clauses, the action for each
@@ -127241,11 +127523,11 @@
127241127523
pList = sqlite3ExprListAppend(pWInfo->pParse, pList, pDup);
127242127524
pLeft = pOrTerm->pExpr->pLeft;
127243127525
}
127244127526
assert( pLeft!=0 );
127245127527
pDup = sqlite3ExprDup(db, pLeft, 0);
127246
- pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0, 0);
127528
+ pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0);
127247127529
if( pNew ){
127248127530
int idxNew;
127249127531
transferJoinMarkings(pNew, pExpr);
127250127532
assert( !ExprHasProperty(pNew, EP_xIsSelect) );
127251127533
pNew->x.pList = pList;
@@ -127539,11 +127821,11 @@
127539127821
for(i=0; i<2; i++){
127540127822
Expr *pNewExpr;
127541127823
int idxNew;
127542127824
pNewExpr = sqlite3PExpr(pParse, ops[i],
127543127825
sqlite3ExprDup(db, pExpr->pLeft, 0),
127544
- sqlite3ExprDup(db, pList->a[i].pExpr, 0), 0);
127826
+ sqlite3ExprDup(db, pList->a[i].pExpr, 0));
127545127827
transferJoinMarkings(pNewExpr, pExpr);
127546127828
idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
127547127829
testcase( idxNew==0 );
127548127830
exprAnalyze(pSrc, pWC, idxNew);
127549127831
pTerm = &pWC->a[idxTerm];
@@ -127624,19 +127906,19 @@
127624127906
}
127625127907
zCollSeqName = noCase ? "NOCASE" : "BINARY";
127626127908
pNewExpr1 = sqlite3ExprDup(db, pLeft, 0);
127627127909
pNewExpr1 = sqlite3PExpr(pParse, TK_GE,
127628127910
sqlite3ExprAddCollateString(pParse,pNewExpr1,zCollSeqName),
127629
- pStr1, 0);
127911
+ pStr1);
127630127912
transferJoinMarkings(pNewExpr1, pExpr);
127631127913
idxNew1 = whereClauseInsert(pWC, pNewExpr1, wtFlags);
127632127914
testcase( idxNew1==0 );
127633127915
exprAnalyze(pSrc, pWC, idxNew1);
127634127916
pNewExpr2 = sqlite3ExprDup(db, pLeft, 0);
127635127917
pNewExpr2 = sqlite3PExpr(pParse, TK_LT,
127636127918
sqlite3ExprAddCollateString(pParse,pNewExpr2,zCollSeqName),
127637
- pStr2, 0);
127919
+ pStr2);
127638127920
transferJoinMarkings(pNewExpr2, pExpr);
127639127921
idxNew2 = whereClauseInsert(pWC, pNewExpr2, wtFlags);
127640127922
testcase( idxNew2==0 );
127641127923
exprAnalyze(pSrc, pWC, idxNew2);
127642127924
pTerm = &pWC->a[idxTerm];
@@ -127665,11 +127947,11 @@
127665127947
prereqExpr = sqlite3WhereExprUsage(pMaskSet, pRight);
127666127948
prereqColumn = sqlite3WhereExprUsage(pMaskSet, pLeft);
127667127949
if( (prereqExpr & prereqColumn)==0 ){
127668127950
Expr *pNewExpr;
127669127951
pNewExpr = sqlite3PExpr(pParse, TK_MATCH,
127670
- 0, sqlite3ExprDup(db, pRight, 0), 0);
127952
+ 0, sqlite3ExprDup(db, pRight, 0));
127671127953
idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
127672127954
testcase( idxNew==0 );
127673127955
pNewTerm = &pWC->a[idxNew];
127674127956
pNewTerm->prereqRight = prereqExpr;
127675127957
pNewTerm->leftCursor = pLeft->iTable;
@@ -127704,11 +127986,11 @@
127704127986
int idxNew;
127705127987
Expr *pNew;
127706127988
Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i);
127707127989
Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i);
127708127990
127709
- pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight, 0);
127991
+ pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight);
127710127992
transferJoinMarkings(pNew, pExpr);
127711127993
idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC);
127712127994
exprAnalyze(pSrc, pWC, idxNew);
127713127995
}
127714127996
pTerm = &pWC->a[idxTerm];
@@ -127756,11 +128038,11 @@
127756128038
int idxNew;
127757128039
WhereTerm *pNewTerm;
127758128040
127759128041
pNewExpr = sqlite3PExpr(pParse, TK_GT,
127760128042
sqlite3ExprDup(db, pLeft, 0),
127761
- sqlite3ExprAlloc(db, TK_NULL, 0, 0), 0);
128043
+ sqlite3ExprAlloc(db, TK_NULL, 0, 0));
127762128044
127763128045
idxNew = whereClauseInsert(pWC, pNewExpr,
127764128046
TERM_VIRTUAL|TERM_DYNAMIC|TERM_VNULL);
127765128047
if( idxNew ){
127766128048
pNewTerm = &pWC->a[idxNew];
@@ -127942,11 +128224,11 @@
127942128224
if( pColRef==0 ) return;
127943128225
pColRef->iTable = pItem->iCursor;
127944128226
pColRef->iColumn = k++;
127945128227
pColRef->pTab = pTab;
127946128228
pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef,
127947
- sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
128229
+ sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0));
127948128230
whereClauseInsert(pWC, pTerm, TERM_DYNAMIC);
127949128231
}
127950128232
}
127951128233
127952128234
/************** End of whereexpr.c *******************************************/
@@ -133067,20 +133349,20 @@
133067133349
Parse *pParse, /* The parsing context. Errors accumulate here */
133068133350
int op, /* The binary operation */
133069133351
ExprSpan *pLeft, /* The left operand, and output */
133070133352
ExprSpan *pRight /* The right operand */
133071133353
){
133072
- pLeft->pExpr = sqlite3PExpr(pParse, op, pLeft->pExpr, pRight->pExpr, 0);
133354
+ pLeft->pExpr = sqlite3PExpr(pParse, op, pLeft->pExpr, pRight->pExpr);
133073133355
pLeft->zEnd = pRight->zEnd;
133074133356
}
133075133357
133076133358
/* If doNot is true, then add a TK_NOT Expr-node wrapper around the
133077133359
** outside of *ppExpr.
133078133360
*/
133079133361
static void exprNot(Parse *pParse, int doNot, ExprSpan *pSpan){
133080133362
if( doNot ){
133081
- pSpan->pExpr = sqlite3PExpr(pParse, TK_NOT, pSpan->pExpr, 0, 0);
133363
+ pSpan->pExpr = sqlite3PExpr(pParse, TK_NOT, pSpan->pExpr, 0);
133082133364
}
133083133365
}
133084133366
133085133367
/* Construct an expression node for a unary postfix operator
133086133368
*/
@@ -133088,11 +133370,11 @@
133088133370
Parse *pParse, /* Parsing context to record errors */
133089133371
int op, /* The operator */
133090133372
ExprSpan *pOperand, /* The operand, and output */
133091133373
Token *pPostOp /* The operand token for setting the span */
133092133374
){
133093
- pOperand->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0);
133375
+ pOperand->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0);
133094133376
pOperand->zEnd = &pPostOp->z[pPostOp->n];
133095133377
}
133096133378
133097133379
/* A routine to convert a binary TK_IS or TK_ISNOT expression into a
133098133380
** unary TK_ISNULL or TK_NOTNULL expression. */
@@ -133113,11 +133395,11 @@
133113133395
int op, /* The operator */
133114133396
ExprSpan *pOperand, /* The operand */
133115133397
Token *pPreOp /* The operand token for setting the span */
133116133398
){
133117133399
pOut->zStart = pPreOp->z;
133118
- pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0);
133400
+ pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0);
133119133401
pOut->zEnd = pOperand->zEnd;
133120133402
}
133121133403
133122133404
/* Add a single new term to an ExprList that is used to store a
133123133405
** list of identifiers. Report an error if the ID list contains
@@ -134706,11 +134988,10 @@
134706134988
/*
134707134989
** The following routine is called if the stack overflows.
134708134990
*/
134709134991
static void yyStackOverflow(yyParser *yypParser){
134710134992
sqlite3ParserARG_FETCH;
134711
- yypParser->yytos--;
134712134993
#ifndef NDEBUG
134713134994
if( yyTraceFILE ){
134714134995
fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
134715134996
}
134716134997
#endif
@@ -134761,16 +135042,18 @@
134761135042
assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
134762135043
}
134763135044
#endif
134764135045
#if YYSTACKDEPTH>0
134765135046
if( yypParser->yytos>=&yypParser->yystack[YYSTACKDEPTH] ){
135047
+ yypParser->yytos--;
134766135048
yyStackOverflow(yypParser);
134767135049
return;
134768135050
}
134769135051
#else
134770135052
if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
134771135053
if( yyGrowStack(yypParser) ){
135054
+ yypParser->yytos--;
134772135055
yyStackOverflow(yypParser);
134773135056
return;
134774135057
}
134775135058
}
134776135059
#endif
@@ -135308,11 +135591,11 @@
135308135591
{sqlite3AddDefaultValue(pParse,&yymsp[-1].minor.yy190);}
135309135592
break;
135310135593
case 33: /* ccons ::= DEFAULT MINUS term */
135311135594
{
135312135595
ExprSpan v;
135313
- v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy190.pExpr, 0, 0);
135596
+ v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy190.pExpr, 0);
135314135597
v.zStart = yymsp[-1].minor.yy0.z;
135315135598
v.zEnd = yymsp[0].minor.yy190.zEnd;
135316135599
sqlite3AddDefaultValue(pParse,&v);
135317135600
}
135318135601
break;
@@ -135572,13 +135855,13 @@
135572135855
yymsp[-1].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy148, p);
135573135856
}
135574135857
break;
135575135858
case 94: /* selcollist ::= sclp nm DOT STAR */
135576135859
{
135577
- Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0, 0);
135578
- Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
135579
- Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
135860
+ Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
135861
+ Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
135862
+ Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
135580135863
yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148, pDot);
135581135864
}
135582135865
break;
135583135866
case 95: /* as ::= AS nm */
135584135867
case 106: /* dbnm ::= DOT nm */ yytestcase(yyruleno==106);
@@ -135800,21 +136083,21 @@
135800136083
case 154: /* expr ::= nm DOT nm */
135801136084
{
135802136085
Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
135803136086
Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
135804136087
spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
135805
- yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
136088
+ yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
135806136089
}
135807136090
break;
135808136091
case 155: /* expr ::= nm DOT nm DOT nm */
135809136092
{
135810136093
Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-4].minor.yy0, 1);
135811136094
Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
135812136095
Expr *temp3 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
135813
- Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0);
136096
+ Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
135814136097
spanSet(&yymsp[-4].minor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
135815
- yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
136098
+ yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
135816136099
}
135817136100
break;
135818136101
case 158: /* term ::= INTEGER */
135819136102
{
135820136103
yylhsminor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
@@ -135839,11 +136122,11 @@
135839136122
spanSet(&yymsp[0].minor.yy190, &t, &t);
135840136123
if( pParse->nested==0 ){
135841136124
sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t);
135842136125
yymsp[0].minor.yy190.pExpr = 0;
135843136126
}else{
135844
- yymsp[0].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, 0);
136127
+ yymsp[0].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0);
135845136128
if( yymsp[0].minor.yy190.pExpr ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy190.pExpr->iTable);
135846136129
}
135847136130
}
135848136131
}
135849136132
break;
@@ -135854,11 +136137,12 @@
135854136137
}
135855136138
break;
135856136139
case 161: /* expr ::= CAST LP expr AS typetoken RP */
135857136140
{
135858136141
spanSet(&yymsp[-5].minor.yy190,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
135859
- yymsp[-5].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy190.pExpr, 0, &yymsp[-1].minor.yy0);
136142
+ yymsp[-5].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_CAST, &yymsp[-1].minor.yy0, 1);
136143
+ sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy190.pExpr, yymsp[-3].minor.yy190.pExpr, 0);
135860136144
}
135861136145
break;
135862136146
case 162: /* expr ::= ID|INDEXED LP distinct exprlist RP */
135863136147
{
135864136148
if( yymsp[-1].minor.yy148 && yymsp[-1].minor.yy148->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
@@ -135887,11 +136171,11 @@
135887136171
yymsp[0].minor.yy190 = yylhsminor.yy190;
135888136172
break;
135889136173
case 165: /* expr ::= LP nexprlist COMMA expr RP */
135890136174
{
135891136175
ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy148, yymsp[-1].minor.yy190.pExpr);
135892
- yylhsminor.yy190.pExpr = sqlite3PExpr(pParse, TK_VECTOR, 0, 0, 0);
136176
+ yylhsminor.yy190.pExpr = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
135893136177
if( yylhsminor.yy190.pExpr ){
135894136178
yylhsminor.yy190.pExpr->x.pList = pList;
135895136179
spanSet(&yylhsminor.yy190, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0);
135896136180
}else{
135897136181
sqlite3ExprListDelete(pParse->db, pList);
@@ -135976,11 +136260,11 @@
135976136260
break;
135977136261
case 188: /* expr ::= expr between_op expr AND expr */
135978136262
{
135979136263
ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr);
135980136264
pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy190.pExpr);
135981
- yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy190.pExpr, 0, 0);
136265
+ yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy190.pExpr, 0);
135982136266
if( yymsp[-4].minor.yy190.pExpr ){
135983136267
yymsp[-4].minor.yy190.pExpr->x.pList = pList;
135984136268
}else{
135985136269
sqlite3ExprListDelete(pParse->db, pList);
135986136270
}
@@ -135998,11 +136282,11 @@
135998136282
**
135999136283
** simplify to constants 0 (false) and 1 (true), respectively,
136000136284
** regardless of the value of expr1.
136001136285
*/
136002136286
sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy190.pExpr);
136003
- yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, &sqlite3IntTokens[yymsp[-3].minor.yy194]);
136287
+ yymsp[-4].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy194],1);
136004136288
}else if( yymsp[-1].minor.yy148->nExpr==1 ){
136005136289
/* Expressions of the form:
136006136290
**
136007136291
** expr1 IN (?1)
136008136292
** expr1 NOT IN (?2)
@@ -136025,13 +136309,13 @@
136025136309
** before now and control would have never reached this point */
136026136310
if( ALWAYS(pRHS) ){
136027136311
pRHS->flags &= ~EP_Collate;
136028136312
pRHS->flags |= EP_Generic;
136029136313
}
136030
- yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, yymsp[-3].minor.yy194 ? TK_NE : TK_EQ, yymsp[-4].minor.yy190.pExpr, pRHS, 0);
136314
+ yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, yymsp[-3].minor.yy194 ? TK_NE : TK_EQ, yymsp[-4].minor.yy190.pExpr, pRHS);
136031136315
}else{
136032
- yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0, 0);
136316
+ yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
136033136317
if( yymsp[-4].minor.yy190.pExpr ){
136034136318
yymsp[-4].minor.yy190.pExpr->x.pList = yymsp[-1].minor.yy148;
136035136319
sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy190.pExpr);
136036136320
}else{
136037136321
sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy148);
@@ -136042,17 +136326,17 @@
136042136326
}
136043136327
break;
136044136328
case 192: /* expr ::= LP select RP */
136045136329
{
136046136330
spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
136047
- yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
136331
+ yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
136048136332
sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy190.pExpr, yymsp[-1].minor.yy243);
136049136333
}
136050136334
break;
136051136335
case 193: /* expr ::= expr in_op LP select RP */
136052136336
{
136053
- yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0, 0);
136337
+ yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
136054136338
sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, yymsp[-1].minor.yy243);
136055136339
exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
136056136340
yymsp[-4].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
136057136341
}
136058136342
break;
@@ -136059,28 +136343,28 @@
136059136343
case 194: /* expr ::= expr in_op nm dbnm paren_exprlist */
136060136344
{
136061136345
SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
136062136346
Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
136063136347
if( yymsp[0].minor.yy148 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy148);
136064
- yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0, 0);
136348
+ yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
136065136349
sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, pSelect);
136066136350
exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
136067136351
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];
136068136352
}
136069136353
break;
136070136354
case 195: /* expr ::= EXISTS LP select RP */
136071136355
{
136072136356
Expr *p;
136073136357
spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
136074
- p = yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
136358
+ p = yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
136075136359
sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy243);
136076136360
}
136077136361
break;
136078136362
case 196: /* expr ::= CASE case_operand case_exprlist case_else END */
136079136363
{
136080136364
spanSet(&yymsp[-4].minor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-C*/
136081
- yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy72, 0, 0);
136365
+ yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy72, 0);
136082136366
if( yymsp[-4].minor.yy190.pExpr ){
136083136367
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;
136084136368
sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy190.pExpr);
136085136369
}else{
136086136370
sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy148);
@@ -136250,20 +136534,20 @@
136250136534
{yymsp[0].minor.yy145 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy243); /*A-overwrites-X*/}
136251136535
break;
136252136536
case 247: /* expr ::= RAISE LP IGNORE RP */
136253136537
{
136254136538
spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
136255
- yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0);
136539
+ yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
136256136540
if( yymsp[-3].minor.yy190.pExpr ){
136257136541
yymsp[-3].minor.yy190.pExpr->affinity = OE_Ignore;
136258136542
}
136259136543
}
136260136544
break;
136261136545
case 248: /* expr ::= RAISE LP raisetype COMMA nm RP */
136262136546
{
136263136547
spanSet(&yymsp[-5].minor.yy190,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
136264
- yymsp[-5].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0);
136548
+ yymsp[-5].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
136265136549
if( yymsp[-5].minor.yy190.pExpr ) {
136266136550
yymsp[-5].minor.yy190.pExpr->affinity = (char)yymsp[-3].minor.yy194;
136267136551
}
136268136552
}
136269136553
break;
@@ -141491,11 +141775,11 @@
141491141775
/*
141492141776
** Interface to the testing logic.
141493141777
*/
141494141778
SQLITE_API int sqlite3_test_control(int op, ...){
141495141779
int rc = 0;
141496
-#ifdef SQLITE_OMIT_BUILTIN_TEST
141780
+#ifdef SQLITE_UNTESTABLE
141497141781
UNUSED_PARAMETER(op);
141498141782
#else
141499141783
va_list ap;
141500141784
va_start(ap, op);
141501141785
switch( op ){
@@ -141828,11 +142112,11 @@
141828142112
sqlite3_mutex_leave(db->mutex);
141829142113
break;
141830142114
}
141831142115
}
141832142116
va_end(ap);
141833
-#endif /* SQLITE_OMIT_BUILTIN_TEST */
142117
+#endif /* SQLITE_UNTESTABLE */
141834142118
return rc;
141835142119
}
141836142120
141837142121
/*
141838142122
** This is a utility routine, useful to VFS implementations, that checks
@@ -141939,26 +142223,27 @@
141939142223
const char *zDb,
141940142224
sqlite3_snapshot **ppSnapshot
141941142225
){
141942142226
int rc = SQLITE_ERROR;
141943142227
#ifndef SQLITE_OMIT_WAL
141944
- int iDb;
141945142228
141946142229
#ifdef SQLITE_ENABLE_API_ARMOR
141947142230
if( !sqlite3SafetyCheckOk(db) ){
141948142231
return SQLITE_MISUSE_BKPT;
141949142232
}
141950142233
#endif
141951142234
sqlite3_mutex_enter(db->mutex);
141952142235
141953
- iDb = sqlite3FindDbName(db, zDb);
141954
- if( iDb==0 || iDb>1 ){
141955
- Btree *pBt = db->aDb[iDb].pBt;
141956
- if( 0==sqlite3BtreeIsInTrans(pBt) ){
141957
- rc = sqlite3BtreeBeginTrans(pBt, 0);
141958
- if( rc==SQLITE_OK ){
141959
- rc = sqlite3PagerSnapshotGet(sqlite3BtreePager(pBt), ppSnapshot);
142236
+ if( db->autoCommit==0 ){
142237
+ int iDb = sqlite3FindDbName(db, zDb);
142238
+ if( iDb==0 || iDb>1 ){
142239
+ Btree *pBt = db->aDb[iDb].pBt;
142240
+ if( 0==sqlite3BtreeIsInTrans(pBt) ){
142241
+ rc = sqlite3BtreeBeginTrans(pBt, 0);
142242
+ if( rc==SQLITE_OK ){
142243
+ rc = sqlite3PagerSnapshotGet(sqlite3BtreePager(pBt), ppSnapshot);
142244
+ }
141960142245
}
141961142246
}
141962142247
}
141963142248
141964142249
sqlite3_mutex_leave(db->mutex);
@@ -141996,10 +142281,42 @@
141996142281
}
141997142282
}
141998142283
}
141999142284
}
142000142285
142286
+ sqlite3_mutex_leave(db->mutex);
142287
+#endif /* SQLITE_OMIT_WAL */
142288
+ return rc;
142289
+}
142290
+
142291
+/*
142292
+** Recover as many snapshots as possible from the wal file associated with
142293
+** schema zDb of database db.
142294
+*/
142295
+SQLITE_API int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb){
142296
+ int rc = SQLITE_ERROR;
142297
+ int iDb;
142298
+#ifndef SQLITE_OMIT_WAL
142299
+
142300
+#ifdef SQLITE_ENABLE_API_ARMOR
142301
+ if( !sqlite3SafetyCheckOk(db) ){
142302
+ return SQLITE_MISUSE_BKPT;
142303
+ }
142304
+#endif
142305
+
142306
+ sqlite3_mutex_enter(db->mutex);
142307
+ iDb = sqlite3FindDbName(db, zDb);
142308
+ if( iDb==0 || iDb>1 ){
142309
+ Btree *pBt = db->aDb[iDb].pBt;
142310
+ if( 0==sqlite3BtreeIsInReadTrans(pBt) ){
142311
+ rc = sqlite3BtreeBeginTrans(pBt, 0);
142312
+ if( rc==SQLITE_OK ){
142313
+ rc = sqlite3PagerSnapshotRecover(sqlite3BtreePager(pBt));
142314
+ sqlite3BtreeCommit(pBt);
142315
+ }
142316
+ }
142317
+ }
142001142318
sqlite3_mutex_leave(db->mutex);
142002142319
#endif /* SQLITE_OMIT_WAL */
142003142320
return rc;
142004142321
}
142005142322
@@ -180834,11 +181151,10 @@
180834181151
/*
180835181152
** The following routine is called if the stack overflows.
180836181153
*/
180837181154
static void fts5yyStackOverflow(fts5yyParser *fts5yypParser){
180838181155
sqlite3Fts5ParserARG_FETCH;
180839
- fts5yypParser->fts5yytos--;
180840181156
#ifndef NDEBUG
180841181157
if( fts5yyTraceFILE ){
180842181158
fprintf(fts5yyTraceFILE,"%sStack Overflow!\n",fts5yyTracePrompt);
180843181159
}
180844181160
#endif
@@ -180889,16 +181205,18 @@
180889181205
assert( fts5yypParser->fts5yyhwm == (int)(fts5yypParser->fts5yytos - fts5yypParser->fts5yystack) );
180890181206
}
180891181207
#endif
180892181208
#if fts5YYSTACKDEPTH>0
180893181209
if( fts5yypParser->fts5yytos>=&fts5yypParser->fts5yystack[fts5YYSTACKDEPTH] ){
181210
+ fts5yypParser->fts5yytos--;
180894181211
fts5yyStackOverflow(fts5yypParser);
180895181212
return;
180896181213
}
180897181214
#else
180898181215
if( fts5yypParser->fts5yytos>=&fts5yypParser->fts5yystack[fts5yypParser->fts5yystksz] ){
180899181216
if( fts5yyGrowStack(fts5yypParser) ){
181217
+ fts5yypParser->fts5yytos--;
180900181218
fts5yyStackOverflow(fts5yypParser);
180901181219
return;
180902181220
}
180903181221
}
180904181222
#endif
@@ -184206,52 +184524,65 @@
184206184524
184207184525
/*
184208184526
** Initialize all term iterators in the pNear object. If any term is found
184209184527
** to match no documents at all, return immediately without initializing any
184210184528
** further iterators.
184529
+**
184530
+** If an error occurs, return an SQLite error code. Otherwise, return
184531
+** SQLITE_OK. It is not considered an error if some term matches zero
184532
+** documents.
184211184533
*/
184212184534
static int fts5ExprNearInitAll(
184213184535
Fts5Expr *pExpr,
184214184536
Fts5ExprNode *pNode
184215184537
){
184216184538
Fts5ExprNearset *pNear = pNode->pNear;
184217
- int i, j;
184218
- int rc = SQLITE_OK;
184219
- int bEof = 1;
184539
+ int i;
184220184540
184221184541
assert( pNode->bNomatch==0 );
184222
- for(i=0; rc==SQLITE_OK && i<pNear->nPhrase; i++){
184542
+ for(i=0; i<pNear->nPhrase; i++){
184223184543
Fts5ExprPhrase *pPhrase = pNear->apPhrase[i];
184224
- for(j=0; j<pPhrase->nTerm; j++){
184225
- Fts5ExprTerm *pTerm = &pPhrase->aTerm[j];
184226
- Fts5ExprTerm *p;
184227
-
184228
- for(p=pTerm; p && rc==SQLITE_OK; p=p->pSynonym){
184229
- if( p->pIter ){
184230
- sqlite3Fts5IterClose(p->pIter);
184231
- p->pIter = 0;
184232
- }
184233
- rc = sqlite3Fts5IndexQuery(
184234
- pExpr->pIndex, p->zTerm, (int)strlen(p->zTerm),
184235
- (pTerm->bPrefix ? FTS5INDEX_QUERY_PREFIX : 0) |
184236
- (pExpr->bDesc ? FTS5INDEX_QUERY_DESC : 0),
184237
- pNear->pColset,
184238
- &p->pIter
184239
- );
184240
- assert( rc==SQLITE_OK || p->pIter==0 );
184241
- if( p->pIter && 0==sqlite3Fts5IterEof(p->pIter) ){
184242
- bEof = 0;
184243
- }
184244
- }
184245
-
184246
- if( bEof ) break;
184247
- }
184248
- if( bEof ) break;
184249
- }
184250
-
184251
- pNode->bEof = bEof;
184252
- return rc;
184544
+ if( pPhrase->nTerm==0 ){
184545
+ pNode->bEof = 1;
184546
+ return SQLITE_OK;
184547
+ }else{
184548
+ int j;
184549
+ for(j=0; j<pPhrase->nTerm; j++){
184550
+ Fts5ExprTerm *pTerm = &pPhrase->aTerm[j];
184551
+ Fts5ExprTerm *p;
184552
+ int bHit = 0;
184553
+
184554
+ for(p=pTerm; p; p=p->pSynonym){
184555
+ int rc;
184556
+ if( p->pIter ){
184557
+ sqlite3Fts5IterClose(p->pIter);
184558
+ p->pIter = 0;
184559
+ }
184560
+ rc = sqlite3Fts5IndexQuery(
184561
+ pExpr->pIndex, p->zTerm, (int)strlen(p->zTerm),
184562
+ (pTerm->bPrefix ? FTS5INDEX_QUERY_PREFIX : 0) |
184563
+ (pExpr->bDesc ? FTS5INDEX_QUERY_DESC : 0),
184564
+ pNear->pColset,
184565
+ &p->pIter
184566
+ );
184567
+ assert( (rc==SQLITE_OK)==(p->pIter!=0) );
184568
+ if( rc!=SQLITE_OK ) return rc;
184569
+ if( 0==sqlite3Fts5IterEof(p->pIter) ){
184570
+ bHit = 1;
184571
+ }
184572
+ }
184573
+
184574
+ if( bHit==0 ){
184575
+ pNode->bEof = 1;
184576
+ return SQLITE_OK;
184577
+ }
184578
+ }
184579
+ }
184580
+ }
184581
+
184582
+ pNode->bEof = 0;
184583
+ return SQLITE_OK;
184253184584
}
184254184585
184255184586
/*
184256184587
** If pExpr is an ASC iterator, this function returns a value with the
184257184588
** same sign as:
@@ -195785,11 +196116,11 @@
195785196116
int nArg, /* Number of args */
195786196117
sqlite3_value **apUnused /* Function arguments */
195787196118
){
195788196119
assert( nArg==0 );
195789196120
UNUSED_PARAM2(nArg, apUnused);
195790
- sqlite3_result_text(pCtx, "fts5: 2016-11-19 18:31:37 28393c413cc4505b94411730e728583c5d4baaae", -1, SQLITE_TRANSIENT);
196121
+ sqlite3_result_text(pCtx, "fts5: 2016-12-08 19:04:36 b26df26e184ec6da4b5537526c10f42a293d09b5", -1, SQLITE_TRANSIENT);
195791196122
}
195792196123
195793196124
static int fts5Init(sqlite3 *db){
195794196125
static const sqlite3_module fts5Mod = {
195795196126
/* iVersion */ 2,
195796196127
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -381,11 +381,11 @@
381 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
382 ** [sqlite_version()] and [sqlite_source_id()].
383 */
384 #define SQLITE_VERSION "3.16.0"
385 #define SQLITE_VERSION_NUMBER 3016000
386 #define SQLITE_SOURCE_ID "2016-11-22 20:29:05 bee2859b953c935c413de2917588159d03c672d9"
387
388 /*
389 ** CAPI3REF: Run-Time Library Version Numbers
390 ** KEYWORDS: sqlite3_version sqlite3_sourceid
391 **
@@ -3868,10 +3868,14 @@
3868 ** rather they control the timing of when other statements modify the
3869 ** database. ^The [ATTACH] and [DETACH] statements also cause
3870 ** sqlite3_stmt_readonly() to return true since, while those statements
3871 ** change the configuration of a database connection, they do not make
3872 ** changes to the content of the database files on disk.
 
 
 
 
3873 */
3874 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3875
3876 /*
3877 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
@@ -8517,11 +8521,11 @@
8517 */
8518 SQLITE_API int sqlite3_system_errno(sqlite3*);
8519
8520 /*
8521 ** CAPI3REF: Database Snapshot
8522 ** KEYWORDS: {snapshot}
8523 ** EXPERIMENTAL
8524 **
8525 ** An instance of the snapshot object records the state of a [WAL mode]
8526 ** database for some specific point in history.
8527 **
@@ -8541,11 +8545,13 @@
8541 ** The constructor for this object is [sqlite3_snapshot_get()]. The
8542 ** [sqlite3_snapshot_open()] method causes a fresh read transaction to refer
8543 ** to an historical snapshot (if possible). The destructor for
8544 ** sqlite3_snapshot objects is [sqlite3_snapshot_free()].
8545 */
8546 typedef struct sqlite3_snapshot sqlite3_snapshot;
 
 
8547
8548 /*
8549 ** CAPI3REF: Record A Database Snapshot
8550 ** EXPERIMENTAL
8551 **
@@ -8552,13 +8558,36 @@
8552 ** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a
8553 ** new [sqlite3_snapshot] object that records the current state of
8554 ** schema S in database connection D. ^On success, the
8555 ** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly
8556 ** created [sqlite3_snapshot] object into *P and returns SQLITE_OK.
8557 ** ^If schema S of [database connection] D is not a [WAL mode] database
8558 ** that is in a read transaction, then [sqlite3_snapshot_get(D,S,P)]
8559 ** leaves the *P value unchanged and returns an appropriate [error code].
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8560 **
8561 ** The [sqlite3_snapshot] object returned from a successful call to
8562 ** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()]
8563 ** to avoid a memory leak.
8564 **
@@ -8647,10 +8676,32 @@
8647 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(
8648 sqlite3_snapshot *p1,
8649 sqlite3_snapshot *p2
8650 );
8651
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8652 /*
8653 ** Undo the hack that converts floating point types to integer for
8654 ** builds on processors without floating point support.
8655 */
8656 #ifdef SQLITE_OMIT_FLOATING_POINT
@@ -12323,19 +12374,19 @@
12323 SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
12324 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
12325 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
12326 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
12327 SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
12328 SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
12329 SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
12330 SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
12331 SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
12332
12333 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
12334 SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
12335
12336 #ifndef SQLITE_OMIT_INCRBLOB
 
12337 SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
12338 SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *);
12339 #endif
12340 SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *);
12341 SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
@@ -12518,26 +12569,25 @@
12518 ** Allowed values of VdbeOp.p4type
12519 */
12520 #define P4_NOTUSED 0 /* The P4 parameter is not used */
12521 #define P4_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */
12522 #define P4_STATIC (-2) /* Pointer to a static string */
12523 #define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */
12524 #define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */
12525 #define P4_KEYINFO (-6) /* P4 is a pointer to a KeyInfo structure */
12526 #define P4_EXPR (-7) /* P4 is a pointer to an Expr tree */
12527 #define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */
12528 #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */
12529 #define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */
12530 #define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */
12531 #define P4_REAL (-12) /* P4 is a 64-bit floating point value */
12532 #define P4_INT64 (-13) /* P4 is a 64-bit signed integer */
12533 #define P4_INT32 (-14) /* P4 is a 32-bit signed integer */
12534 #define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
12535 #define P4_SUBPROGRAM (-18) /* P4 is a pointer to a SubProgram structure */
12536 #define P4_ADVANCE (-19) /* P4 is a pointer to BtreeNext() or BtreePrev() */
12537 #define P4_TABLE (-20) /* P4 is a pointer to a Table structure */
12538 #define P4_FUNCCTX (-21) /* P4 is a pointer to an sqlite3_context object */
12539
12540 /* Error message codes for OP_Halt */
12541 #define P5_ConstraintNotNull 1
12542 #define P5_ConstraintUnique 2
12543 #define P5_ConstraintCheck 3
@@ -12697,52 +12747,51 @@
12697 #define OP_InsertInt 116 /* synopsis: intkey=P3 data=r[P2] */
12698 #define OP_Delete 117
12699 #define OP_ResetCount 118
12700 #define OP_SorterCompare 119 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12701 #define OP_SorterData 120 /* synopsis: r[P2]=data */
12702 #define OP_RowKey 121 /* synopsis: r[P2]=key */
12703 #define OP_RowData 122 /* synopsis: r[P2]=data */
12704 #define OP_Rowid 123 /* synopsis: r[P2]=rowid */
12705 #define OP_NullRow 124
12706 #define OP_SorterInsert 125 /* synopsis: key=r[P2] */
12707 #define OP_IdxInsert 126 /* synopsis: key=r[P2] */
12708 #define OP_IdxDelete 127 /* synopsis: key=r[P2@P3] */
12709 #define OP_Seek 128 /* synopsis: Move P3 to P1.rowid */
12710 #define OP_IdxRowid 129 /* synopsis: r[P2]=rowid */
12711 #define OP_Destroy 130
12712 #define OP_Clear 131
12713 #define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
12714 #define OP_ResetSorter 133
12715 #define OP_CreateIndex 134 /* synopsis: r[P2]=root iDb=P1 */
12716 #define OP_CreateTable 135 /* synopsis: r[P2]=root iDb=P1 */
12717 #define OP_ParseSchema 136
12718 #define OP_LoadAnalysis 137
12719 #define OP_DropTable 138
12720 #define OP_DropIndex 139
12721 #define OP_DropTrigger 140
12722 #define OP_IntegrityCk 141
12723 #define OP_RowSetAdd 142 /* synopsis: rowset(P1)=r[P2] */
12724 #define OP_Param 143
12725 #define OP_FkCounter 144 /* synopsis: fkctr[P1]+=P2 */
12726 #define OP_MemMax 145 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12727 #define OP_OffsetLimit 146 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12728 #define OP_AggStep0 147 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12729 #define OP_AggStep 148 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12730 #define OP_AggFinal 149 /* synopsis: accum=r[P1] N=P2 */
12731 #define OP_Expire 150
12732 #define OP_TableLock 151 /* synopsis: iDb=P1 root=P2 write=P3 */
12733 #define OP_VBegin 152
12734 #define OP_VCreate 153
12735 #define OP_VDestroy 154
12736 #define OP_VOpen 155
12737 #define OP_VColumn 156 /* synopsis: r[P3]=vcolumn(P2) */
12738 #define OP_VRename 157
12739 #define OP_Pagecount 158
12740 #define OP_MaxPgcnt 159
12741 #define OP_CursorHint 160
12742 #define OP_Noop 161
12743 #define OP_Explain 162
12744
12745 /* Properties such as "out2" or "jump" that are specified in
12746 ** comments following the "case" for each opcode in the vdbe.c
12747 ** are encoded into bitvectors as follows:
12748 */
@@ -12766,16 +12815,16 @@
12766 /* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00,\
12767 /* 88 */ 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\
12768 /* 96 */ 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
12769 /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12770 /* 112 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
12771 /* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00,\
12772 /* 128 */ 0x00, 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10,\
12773 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10,\
12774 /* 144 */ 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00,\
12775 /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
12776 /* 160 */ 0x00, 0x00, 0x00,}
12777
12778 /* The sqlite3P2Values() routine is able to run faster if it knows
12779 ** the value of the largest JUMP opcode. The smaller the maximum
12780 ** JUMP opcode the better, so the mkopcodeh.tcl script that
12781 ** generated this include file strives to group all JUMP opcodes
@@ -12816,10 +12865,11 @@
12816 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
12817 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
12818 SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
12819 SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
12820 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
 
12821 SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
12822 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
12823 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
12824 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
12825 SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*);
@@ -13116,10 +13166,11 @@
13116 SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3*);
13117 SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager);
13118 # ifdef SQLITE_ENABLE_SNAPSHOT
13119 SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot);
13120 SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot);
 
13121 # endif
13122 #else
13123 # define sqlite3PagerUseWal(x) 0
13124 #endif
13125
@@ -14115,17 +14166,12 @@
14115 #define SQLITE_AllOpts 0xffff /* All optimizations */
14116
14117 /*
14118 ** Macros for testing whether or not optimizations are enabled or disabled.
14119 */
14120 #ifndef SQLITE_OMIT_BUILTIN_TEST
14121 #define OptimizationDisabled(db, mask) (((db)->dbOptFlags&(mask))!=0)
14122 #define OptimizationEnabled(db, mask) (((db)->dbOptFlags&(mask))==0)
14123 #else
14124 #define OptimizationDisabled(db, mask) 0
14125 #define OptimizationEnabled(db, mask) 1
14126 #endif
14127
14128 /*
14129 ** Return true if it OK to factor constant expressions into the initialization
14130 ** code. The argument is a Parse object for the code generator.
14131 */
@@ -15891,11 +15937,11 @@
15891 ** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE.
15892 */
15893 void (*xVdbeBranch)(void*,int iSrcLine,u8 eThis,u8 eMx); /* Callback */
15894 void *pVdbeBranchArg; /* 1st argument */
15895 #endif
15896 #ifndef SQLITE_OMIT_BUILTIN_TEST
15897 int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
15898 #endif
15899 int bLocaltimeFault; /* True to fail localtime() calls */
15900 int iOnceResetThreshold; /* When to reset OP_Once counters */
15901 };
@@ -16095,11 +16141,11 @@
16095 SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
16096 SQLITE_PRIVATE void sqlite3ScratchFree(void*);
16097 SQLITE_PRIVATE void *sqlite3PageMalloc(int);
16098 SQLITE_PRIVATE void sqlite3PageFree(void*);
16099 SQLITE_PRIVATE void sqlite3MemSetDefault(void);
16100 #ifndef SQLITE_OMIT_BUILTIN_TEST
16101 SQLITE_PRIVATE void sqlite3BenignMallocHooks(void (*)(void), void (*)(void));
16102 #endif
16103 SQLITE_PRIVATE int sqlite3HeapNearlyFull(void);
16104
16105 /*
@@ -16206,11 +16252,11 @@
16206 SQLITE_PRIVATE int sqlite3NoTempsInRange(Parse*,int,int);
16207 #endif
16208 SQLITE_PRIVATE Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int);
16209 SQLITE_PRIVATE Expr *sqlite3Expr(sqlite3*,int,const char*);
16210 SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
16211 SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
16212 SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*);
16213 SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
16214 SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
16215 SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
16216 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
@@ -16250,11 +16296,11 @@
16250 SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);
16251 SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
16252 sqlite3_vfs**,char**,char **);
16253 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*);
16254
16255 #ifdef SQLITE_OMIT_BUILTIN_TEST
16256 # define sqlite3FaultSim(X) SQLITE_OK
16257 #else
16258 SQLITE_PRIVATE int sqlite3FaultSim(int);
16259 #endif
16260
@@ -16263,11 +16309,11 @@
16263 SQLITE_PRIVATE int sqlite3BitvecTestNotNull(Bitvec*, u32);
16264 SQLITE_PRIVATE int sqlite3BitvecSet(Bitvec*, u32);
16265 SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec*, u32, void*);
16266 SQLITE_PRIVATE void sqlite3BitvecDestroy(Bitvec*);
16267 SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec*);
16268 #ifndef SQLITE_OMIT_BUILTIN_TEST
16269 SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int,int*);
16270 #endif
16271
16272 SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3*, void*, unsigned int);
16273 SQLITE_PRIVATE void sqlite3RowSetClear(RowSet*);
@@ -16383,11 +16429,11 @@
16383 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
16384 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
16385 SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
16386 SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
16387 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
16388 #ifndef SQLITE_OMIT_BUILTIN_TEST
16389 SQLITE_PRIVATE void sqlite3PrngSaveState(void);
16390 SQLITE_PRIVATE void sqlite3PrngRestoreState(void);
16391 #endif
16392 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int);
16393 SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int);
@@ -16811,14 +16857,14 @@
16811 #define SQLITE_FAULTINJECTOR_MALLOC 0
16812 #define SQLITE_FAULTINJECTOR_COUNT 1
16813
16814 /*
16815 ** The interface to the code in fault.c used for identifying "benign"
16816 ** malloc failures. This is only present if SQLITE_OMIT_BUILTIN_TEST
16817 ** is not defined.
16818 */
16819 #ifndef SQLITE_OMIT_BUILTIN_TEST
16820 SQLITE_PRIVATE void sqlite3BeginBenignMalloc(void);
16821 SQLITE_PRIVATE void sqlite3EndBenignMalloc(void);
16822 #else
16823 #define sqlite3BeginBenignMalloc()
16824 #define sqlite3EndBenignMalloc()
@@ -16945,10 +16991,11 @@
16945
16946 SQLITE_PRIVATE int sqlite3ExprVectorSize(Expr *pExpr);
16947 SQLITE_PRIVATE int sqlite3ExprIsVector(Expr *pExpr);
16948 SQLITE_PRIVATE Expr *sqlite3VectorFieldSubexpr(Expr*, int);
16949 SQLITE_PRIVATE Expr *sqlite3ExprForVectorField(Parse*,Expr*,int);
 
16950
16951 #endif /* SQLITEINT_H */
16952
16953 /************** End of sqliteInt.h *******************************************/
16954 /************** Begin file global.c ******************************************/
@@ -17171,11 +17218,11 @@
17171 #endif
17172 #ifdef SQLITE_VDBE_COVERAGE
17173 0, /* xVdbeBranch */
17174 0, /* pVbeBranchArg */
17175 #endif
17176 #ifndef SQLITE_OMIT_BUILTIN_TEST
17177 0, /* xTestCallback */
17178 #endif
17179 0, /* bLocaltimeFault */
17180 0x7ffffffe /* iOnceResetThreshold */
17181 };
@@ -17467,13 +17514,10 @@
17467 "OMIT_BLOB_LITERAL",
17468 #endif
17469 #if SQLITE_OMIT_BTREECOUNT
17470 "OMIT_BTREECOUNT",
17471 #endif
17472 #if SQLITE_OMIT_BUILTIN_TEST
17473 "OMIT_BUILTIN_TEST",
17474 #endif
17475 #if SQLITE_OMIT_CAST
17476 "OMIT_CAST",
17477 #endif
17478 #if SQLITE_OMIT_CHECK
17479 "OMIT_CHECK",
@@ -17631,10 +17675,13 @@
17631 #if SQLITE_TEST
17632 "TEST",
17633 #endif
17634 #if defined(SQLITE_THREADSAFE)
17635 "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
 
 
 
17636 #endif
17637 #if SQLITE_USE_ALLOCA
17638 "USE_ALLOCA",
17639 #endif
17640 #if SQLITE_USER_AUTHENTICATION
@@ -18199,11 +18246,11 @@
18199 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
18200 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
18201 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
18202 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
18203 SQLITE_PRIVATE void sqlite3VdbeMemCast(Mem*,u8,u8);
18204 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*);
18205 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
18206 SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
18207 SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
18208 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
18209 SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int n);
@@ -18668,20 +18715,22 @@
18668 /*
18669 ** A structure for holding a single date and time.
18670 */
18671 typedef struct DateTime DateTime;
18672 struct DateTime {
18673 sqlite3_int64 iJD; /* The julian day number times 86400000 */
18674 int Y, M, D; /* Year, month, and day */
18675 int h, m; /* Hour and minutes */
18676 int tz; /* Timezone offset in minutes */
18677 double s; /* Seconds */
18678 char validYMD; /* True (1) if Y,M,D are valid */
18679 char validHMS; /* True (1) if h,m,s are valid */
18680 char validJD; /* True (1) if iJD is valid */
18681 char validTZ; /* True (1) if tz is valid */
18682 char tzSet; /* Timezone was set explicitly */
 
 
18683 };
18684
18685
18686 /*
18687 ** Convert zDate into one or more integers according to the conversion
@@ -18825,18 +18874,27 @@
18825 }
18826 }else{
18827 s = 0;
18828 }
18829 p->validJD = 0;
 
18830 p->validHMS = 1;
18831 p->h = h;
18832 p->m = m;
18833 p->s = s + ms;
18834 if( parseTimezone(zDate, p) ) return 1;
18835 p->validTZ = (p->tz!=0)?1:0;
18836 return 0;
18837 }
 
 
 
 
 
 
 
 
18838
18839 /*
18840 ** Convert from YYYY-MM-DD HH:MM:SS to julian day. We always assume
18841 ** that the YYYY-MM-DD is according to the Gregorian calendar.
18842 **
@@ -18852,10 +18910,14 @@
18852 D = p->D;
18853 }else{
18854 Y = 2000; /* If no YMD specified, assume 2000-Jan-01 */
18855 M = 1;
18856 D = 1;
 
 
 
 
18857 }
18858 if( M<=2 ){
18859 Y--;
18860 M += 12;
18861 }
@@ -18932,10 +18994,25 @@
18932 return 0;
18933 }else{
18934 return 1;
18935 }
18936 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18937
18938 /*
18939 ** Attempt to parse the given string into a julian day number. Return
18940 ** the number of errors.
18941 **
@@ -18962,16 +19039,24 @@
18962 }else if( parseHhMmSs(zDate, p)==0 ){
18963 return 0;
18964 }else if( sqlite3StrICmp(zDate,"now")==0){
18965 return setDateTimeToCurrent(context, p);
18966 }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){
18967 p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
18968 p->validJD = 1;
18969 return 0;
18970 }
18971 return 1;
18972 }
 
 
 
 
 
 
 
 
 
18973
18974 /*
18975 ** Compute the Year, Month, and Day from the julian day number.
18976 */
18977 static void computeYMD(DateTime *p){
@@ -18980,10 +19065,11 @@
18980 if( !p->validJD ){
18981 p->Y = 2000;
18982 p->M = 1;
18983 p->D = 1;
18984 }else{
 
18985 Z = (int)((p->iJD + 43200000)/86400000);
18986 A = (int)((Z - 1867216.25)/36524.25);
18987 A = Z + 1 + A - (A/4);
18988 B = A + 1524;
18989 C = (int)((B - 122.1)/365.25);
@@ -19010,10 +19096,11 @@
19010 p->s -= s;
19011 p->h = s/3600;
19012 s -= p->h*3600;
19013 p->m = s/60;
19014 p->s += s - p->m*60;
 
19015 p->validHMS = 1;
19016 }
19017
19018 /*
19019 ** Compute both YMD and HMS
@@ -19071,18 +19158,18 @@
19071 #if SQLITE_THREADSAFE>0
19072 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
19073 #endif
19074 sqlite3_mutex_enter(mutex);
19075 pX = localtime(t);
19076 #ifndef SQLITE_OMIT_BUILTIN_TEST
19077 if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0;
19078 #endif
19079 if( pX ) *pTm = *pX;
19080 sqlite3_mutex_leave(mutex);
19081 rc = pX==0;
19082 #else
19083 #ifndef SQLITE_OMIT_BUILTIN_TEST
19084 if( sqlite3GlobalConfig.bLocaltimeFault ) return 1;
19085 #endif
19086 #if HAVE_LOCALTIME_R
19087 rc = localtime_r(t, pTm)==0;
19088 #else
@@ -19149,16 +19236,41 @@
19149 y.m = sLocal.tm_min;
19150 y.s = sLocal.tm_sec;
19151 y.validYMD = 1;
19152 y.validHMS = 1;
19153 y.validJD = 0;
 
19154 y.validTZ = 0;
 
19155 computeJD(&y);
19156 *pRc = SQLITE_OK;
19157 return y.iJD - x.iJD;
19158 }
19159 #endif /* SQLITE_OMIT_LOCALTIME */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19160
19161 /*
19162 ** Process a modifier to a date-time stamp. The modifiers are
19163 ** as follows:
19164 **
@@ -19180,29 +19292,27 @@
19180 ** Return 0 on success and 1 if there is any kind of error. If the error
19181 ** is in a system call (i.e. localtime()), then an error message is written
19182 ** to context pCtx. If the error is an unrecognized modifier, no error is
19183 ** written to pCtx.
19184 */
19185 static int parseModifier(sqlite3_context *pCtx, const char *zMod, DateTime *p){
 
 
 
 
 
19186 int rc = 1;
19187 int n;
19188 double r;
19189 char *z, zBuf[30];
19190 z = zBuf;
19191 for(n=0; n<ArraySize(zBuf)-1 && zMod[n]; n++){
19192 z[n] = (char)sqlite3UpperToLower[(u8)zMod[n]];
19193 }
19194 z[n] = 0;
19195 switch( z[0] ){
19196 #ifndef SQLITE_OMIT_LOCALTIME
19197 case 'l': {
19198 /* localtime
19199 **
19200 ** Assuming the current time value is UTC (a.k.a. GMT), shift it to
19201 ** show local time.
19202 */
19203 if( strcmp(z, "localtime")==0 ){
19204 computeJD(p);
19205 p->iJD += localtimeOffset(p, pCtx, &rc);
19206 clearYMD_HMS_TZ(p);
19207 }
19208 break;
@@ -19210,20 +19320,25 @@
19210 #endif
19211 case 'u': {
19212 /*
19213 ** unixepoch
19214 **
19215 ** Treat the current value of p->iJD as the number of
19216 ** seconds since 1970. Convert to a real julian day number.
19217 */
19218 if( strcmp(z, "unixepoch")==0 && p->validJD ){
19219 p->iJD = (p->iJD + 43200)/86400 + 21086676*(i64)10000000;
19220 clearYMD_HMS_TZ(p);
19221 rc = 0;
 
 
 
 
 
19222 }
19223 #ifndef SQLITE_OMIT_LOCALTIME
19224 else if( strcmp(z, "utc")==0 ){
19225 if( p->tzSet==0 ){
19226 sqlite3_int64 c1;
19227 computeJD(p);
19228 c1 = localtimeOffset(p, pCtx, &rc);
19229 if( rc==SQLITE_OK ){
@@ -19245,11 +19360,11 @@
19245 **
19246 ** Move the date to the same time on the next occurrence of
19247 ** weekday N where 0==Sunday, 1==Monday, and so forth. If the
19248 ** date is already on the appropriate weekday, this is a no-op.
19249 */
19250 if( strncmp(z, "weekday ", 8)==0
19251 && sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8)
19252 && (n=(int)r)==r && n>=0 && r<7 ){
19253 sqlite3_int64 Z;
19254 computeYMD_HMS(p);
19255 p->validTZ = 0;
@@ -19268,27 +19383,27 @@
19268 ** start of TTTTT
19269 **
19270 ** Move the date backwards to the beginning of the current day,
19271 ** or month or year.
19272 */
19273 if( strncmp(z, "start of ", 9)!=0 ) break;
19274 z += 9;
19275 computeYMD(p);
19276 p->validHMS = 1;
19277 p->h = p->m = 0;
19278 p->s = 0.0;
19279 p->validTZ = 0;
19280 p->validJD = 0;
19281 if( strcmp(z,"month")==0 ){
19282 p->D = 1;
19283 rc = 0;
19284 }else if( strcmp(z,"year")==0 ){
19285 computeYMD(p);
19286 p->M = 1;
19287 p->D = 1;
19288 rc = 0;
19289 }else if( strcmp(z,"day")==0 ){
19290 rc = 0;
19291 }
19292 break;
19293 }
19294 case '+':
@@ -19302,10 +19417,11 @@
19302 case '6':
19303 case '7':
19304 case '8':
19305 case '9': {
19306 double rRounder;
 
19307 for(n=1; z[n] && z[n]!=':' && !sqlite3Isspace(z[n]); n++){}
19308 if( !sqlite3AtoF(z, &r, n, SQLITE_UTF8) ){
19309 rc = 1;
19310 break;
19311 }
@@ -19330,50 +19446,52 @@
19330 clearYMD_HMS_TZ(p);
19331 p->iJD += tx.iJD;
19332 rc = 0;
19333 break;
19334 }
 
 
 
19335 z += n;
19336 while( sqlite3Isspace(*z) ) z++;
19337 n = sqlite3Strlen30(z);
19338 if( n>10 || n<3 ) break;
19339 if( z[n-1]=='s' ){ z[n-1] = 0; n--; }
19340 computeJD(p);
19341 rc = 0;
19342 rRounder = r<0 ? -0.5 : +0.5;
19343 if( n==3 && strcmp(z,"day")==0 ){
19344 p->iJD += (sqlite3_int64)(r*86400000.0 + rRounder);
19345 }else if( n==4 && strcmp(z,"hour")==0 ){
19346 p->iJD += (sqlite3_int64)(r*(86400000.0/24.0) + rRounder);
19347 }else if( n==6 && strcmp(z,"minute")==0 ){
19348 p->iJD += (sqlite3_int64)(r*(86400000.0/(24.0*60.0)) + rRounder);
19349 }else if( n==6 && strcmp(z,"second")==0 ){
19350 p->iJD += (sqlite3_int64)(r*(86400000.0/(24.0*60.0*60.0)) + rRounder);
19351 }else if( n==5 && strcmp(z,"month")==0 ){
19352 int x, y;
19353 computeYMD_HMS(p);
19354 p->M += (int)r;
19355 x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
19356 p->Y += x;
19357 p->M -= x*12;
19358 p->validJD = 0;
19359 computeJD(p);
19360 y = (int)r;
19361 if( y!=r ){
19362 p->iJD += (sqlite3_int64)((r - y)*30.0*86400000.0 + rRounder);
19363 }
19364 }else if( n==4 && strcmp(z,"year")==0 ){
19365 int y = (int)r;
19366 computeYMD_HMS(p);
19367 p->Y += y;
19368 p->validJD = 0;
19369 computeJD(p);
19370 if( y!=r ){
19371 p->iJD += (sqlite3_int64)((r - y)*365.0*86400000.0 + rRounder);
19372 }
19373 }else{
19374 rc = 1;
19375 }
19376 clearYMD_HMS_TZ(p);
19377 break;
19378 }
19379 default: {
@@ -19396,31 +19514,33 @@
19396 sqlite3_context *context,
19397 int argc,
19398 sqlite3_value **argv,
19399 DateTime *p
19400 ){
19401 int i;
19402 const unsigned char *z;
19403 int eType;
19404 memset(p, 0, sizeof(*p));
19405 if( argc==0 ){
19406 return setDateTimeToCurrent(context, p);
19407 }
19408 if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
19409 || eType==SQLITE_INTEGER ){
19410 p->iJD = (sqlite3_int64)(sqlite3_value_double(argv[0])*86400000.0 + 0.5);
19411 p->validJD = 1;
19412 }else{
19413 z = sqlite3_value_text(argv[0]);
19414 if( !z || parseDateOrTime(context, (char*)z, p) ){
19415 return 1;
19416 }
19417 }
19418 for(i=1; i<argc; i++){
19419 z = sqlite3_value_text(argv[i]);
19420 if( z==0 || parseModifier(context, (char*)z, p) ) return 1;
 
19421 }
 
 
19422 return 0;
19423 }
19424
19425
19426 /*
@@ -20214,11 +20334,11 @@
20214 ** during a hash table resize is a benign fault.
20215 */
20216
20217 /* #include "sqliteInt.h" */
20218
20219 #ifndef SQLITE_OMIT_BUILTIN_TEST
20220
20221 /*
20222 ** Global variables.
20223 */
20224 typedef struct BenignMallocHooks BenignMallocHooks;
@@ -20272,11 +20392,11 @@
20272 if( wsdHooks.xBenignEnd ){
20273 wsdHooks.xBenignEnd();
20274 }
20275 }
20276
20277 #endif /* #ifndef SQLITE_OMIT_BUILTIN_TEST */
20278
20279 /************** End of fault.c ***********************************************/
20280 /************** Begin file mem0.c ********************************************/
20281 /*
20282 ** 2008 October 28
@@ -25599,22 +25719,27 @@
25599 /*
25600 ** Finish off a string by making sure it is zero-terminated.
25601 ** Return a pointer to the resulting string. Return a NULL
25602 ** pointer if any kind of error was encountered.
25603 */
 
 
 
 
 
 
 
 
 
 
 
25604 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
25605 if( p->zText ){
25606 assert( (p->zText==p->zBase)==!isMalloced(p) );
25607 p->zText[p->nChar] = 0;
25608 if( p->mxAlloc>0 && !isMalloced(p) ){
25609 p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
25610 if( p->zText ){
25611 memcpy(p->zText, p->zBase, p->nChar+1);
25612 p->printfFlags |= SQLITE_PRINTF_MALLOCED;
25613 }else{
25614 setStrAccumError(p, STRACCUM_NOMEM);
25615 }
25616 }
25617 }
25618 return p->zText;
25619 }
25620
@@ -25750,11 +25875,12 @@
25750 return zBuf;
25751 }
25752 #endif
25753 sqlite3StrAccumInit(&acc, 0, zBuf, n, 0);
25754 sqlite3VXPrintf(&acc, zFormat, ap);
25755 return sqlite3StrAccumFinish(&acc);
 
25756 }
25757 SQLITE_API char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
25758 char *z;
25759 va_list ap;
25760 va_start(ap,zFormat);
@@ -26459,11 +26585,11 @@
26459 *(zBuf++) = wsdPrng.s[t];
26460 }while( --N );
26461 sqlite3_mutex_leave(mutex);
26462 }
26463
26464 #ifndef SQLITE_OMIT_BUILTIN_TEST
26465 /*
26466 ** For testing purposes, we sometimes want to preserve the state of
26467 ** PRNG and restore the PRNG to its saved state at a later time, or
26468 ** to reset the PRNG to its initial state. These routines accomplish
26469 ** those tasks.
@@ -26484,11 +26610,11 @@
26484 &GLOBAL(struct sqlite3PrngType, sqlite3Prng),
26485 &GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng),
26486 sizeof(sqlite3Prng)
26487 );
26488 }
26489 #endif /* SQLITE_OMIT_BUILTIN_TEST */
26490
26491 /************** End of random.c **********************************************/
26492 /************** Begin file threads.c *****************************************/
26493 /*
26494 ** 2012 July 21
@@ -27342,11 +27468,11 @@
27342 ** which of multiple sqlite3FaultSim() calls has been hit.
27343 **
27344 ** Return whatever integer value the test callback returns, or return
27345 ** SQLITE_OK if no test callback is installed.
27346 */
27347 #ifndef SQLITE_OMIT_BUILTIN_TEST
27348 SQLITE_PRIVATE int sqlite3FaultSim(int iTest){
27349 int (*xCallback)(int) = sqlite3GlobalConfig.xTestCallback;
27350 return xCallback ? xCallback(iTest) : SQLITE_OK;
27351 }
27352 #endif
@@ -29163,52 +29289,51 @@
29163 /* 116 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
29164 /* 117 */ "Delete" OpHelp(""),
29165 /* 118 */ "ResetCount" OpHelp(""),
29166 /* 119 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
29167 /* 120 */ "SorterData" OpHelp("r[P2]=data"),
29168 /* 121 */ "RowKey" OpHelp("r[P2]=key"),
29169 /* 122 */ "RowData" OpHelp("r[P2]=data"),
29170 /* 123 */ "Rowid" OpHelp("r[P2]=rowid"),
29171 /* 124 */ "NullRow" OpHelp(""),
29172 /* 125 */ "SorterInsert" OpHelp("key=r[P2]"),
29173 /* 126 */ "IdxInsert" OpHelp("key=r[P2]"),
29174 /* 127 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
29175 /* 128 */ "Seek" OpHelp("Move P3 to P1.rowid"),
29176 /* 129 */ "IdxRowid" OpHelp("r[P2]=rowid"),
29177 /* 130 */ "Destroy" OpHelp(""),
29178 /* 131 */ "Clear" OpHelp(""),
29179 /* 132 */ "Real" OpHelp("r[P2]=P4"),
29180 /* 133 */ "ResetSorter" OpHelp(""),
29181 /* 134 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
29182 /* 135 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
29183 /* 136 */ "ParseSchema" OpHelp(""),
29184 /* 137 */ "LoadAnalysis" OpHelp(""),
29185 /* 138 */ "DropTable" OpHelp(""),
29186 /* 139 */ "DropIndex" OpHelp(""),
29187 /* 140 */ "DropTrigger" OpHelp(""),
29188 /* 141 */ "IntegrityCk" OpHelp(""),
29189 /* 142 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
29190 /* 143 */ "Param" OpHelp(""),
29191 /* 144 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
29192 /* 145 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
29193 /* 146 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
29194 /* 147 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
29195 /* 148 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
29196 /* 149 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
29197 /* 150 */ "Expire" OpHelp(""),
29198 /* 151 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
29199 /* 152 */ "VBegin" OpHelp(""),
29200 /* 153 */ "VCreate" OpHelp(""),
29201 /* 154 */ "VDestroy" OpHelp(""),
29202 /* 155 */ "VOpen" OpHelp(""),
29203 /* 156 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
29204 /* 157 */ "VRename" OpHelp(""),
29205 /* 158 */ "Pagecount" OpHelp(""),
29206 /* 159 */ "MaxPgcnt" OpHelp(""),
29207 /* 160 */ "CursorHint" OpHelp(""),
29208 /* 161 */ "Noop" OpHelp(""),
29209 /* 162 */ "Explain" OpHelp(""),
29210 };
29211 return azName[i];
29212 }
29213 #endif
29214
@@ -30473,11 +30598,18 @@
30473 struct unixFileId {
30474 dev_t dev; /* Device number */
30475 #if OS_VXWORKS
30476 struct vxworksFileId *pId; /* Unique file ID for vxworks. */
30477 #else
30478 ino_t ino; /* Inode number */
 
 
 
 
 
 
 
30479 #endif
30480 };
30481
30482 /*
30483 ** An instance of the following structure is allocated for each open
@@ -30718,11 +30850,11 @@
30718 memset(&fileId, 0, sizeof(fileId));
30719 fileId.dev = statbuf.st_dev;
30720 #if OS_VXWORKS
30721 fileId.pId = pFile->pId;
30722 #else
30723 fileId.ino = statbuf.st_ino;
30724 #endif
30725 pInode = inodeList;
30726 while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
30727 pInode = pInode->pNext;
30728 }
@@ -30752,11 +30884,12 @@
30752 #if OS_VXWORKS
30753 return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId;
30754 #else
30755 struct stat buf;
30756 return pFile->pInode!=0 &&
30757 (osStat(pFile->zPath, &buf)!=0 || buf.st_ino!=pFile->pInode->fileId.ino);
 
30758 #endif
30759 }
30760
30761
30762 /*
@@ -34924,11 +35057,11 @@
34924 unixInodeInfo *pInode;
34925
34926 unixEnterMutex();
34927 pInode = inodeList;
34928 while( pInode && (pInode->fileId.dev!=sStat.st_dev
34929 || pInode->fileId.ino!=sStat.st_ino) ){
34930 pInode = pInode->pNext;
34931 }
34932 if( pInode ){
34933 UnixUnusedFd **pp;
34934 for(pp=&pInode->pUnused; *pp && (*pp)->flags!=flags; pp=&((*pp)->pNext));
@@ -43485,11 +43618,11 @@
43485 */
43486 SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec *p){
43487 return p->iSize;
43488 }
43489
43490 #ifndef SQLITE_OMIT_BUILTIN_TEST
43491 /*
43492 ** Let V[] be an array of unsigned characters sufficient to hold
43493 ** up to N bits. Let I be an integer between 0 and N. 0<=I<N.
43494 ** Then the following macros can be used to set, clear, or test
43495 ** individual bits within V.
@@ -43600,11 +43733,11 @@
43600 sqlite3_free(pTmpSpace);
43601 sqlite3_free(pV);
43602 sqlite3BitvecDestroy(pBitvec);
43603 return rc;
43604 }
43605 #endif /* SQLITE_OMIT_BUILTIN_TEST */
43606
43607 /************** End of bitvec.c **********************************************/
43608 /************** Begin file pcache.c ******************************************/
43609 /*
43610 ** 2008 August 05
@@ -46398,10 +46531,11 @@
46398 SQLITE_PRIVATE int sqlite3WalHeapMemory(Wal *pWal);
46399
46400 #ifdef SQLITE_ENABLE_SNAPSHOT
46401 SQLITE_PRIVATE int sqlite3WalSnapshotGet(Wal *pWal, sqlite3_snapshot **ppSnapshot);
46402 SQLITE_PRIVATE void sqlite3WalSnapshotOpen(Wal *pWal, sqlite3_snapshot *pSnapshot);
 
46403 #endif
46404
46405 #ifdef SQLITE_ENABLE_ZIPVFS
46406 /* If the WAL file is not empty, return the number of bytes of content
46407 ** stored in each frame (i.e. the db page-size when the WAL was created).
@@ -53799,10 +53933,24 @@
53799 }else{
53800 rc = SQLITE_ERROR;
53801 }
53802 return rc;
53803 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53804 #endif /* SQLITE_ENABLE_SNAPSHOT */
53805 #endif /* !SQLITE_OMIT_WAL */
53806
53807 #ifdef SQLITE_ENABLE_ZIPVFS
53808 /*
@@ -56201,10 +56349,88 @@
56201 pWal->readLock = (i16)mxI;
56202 }
56203 return rc;
56204 }
56205
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56206 /*
56207 ** Begin a read transaction on the database.
56208 **
56209 ** This routine used to be called sqlite3OpenSnapshot() and with good reason:
56210 ** it takes a snapshot of the state of the WAL and wal-index for the current
@@ -56263,11 +56489,15 @@
56263 ** checkpointer has already determined that it will checkpoint
56264 ** snapshot X, where X is later in the wal file than pSnapshot, but
56265 ** has not yet set the pInfo->nBackfillAttempted variable to indicate
56266 ** its intent. To avoid the race condition this leads to, ensure that
56267 ** there is no checkpointer process by taking a shared CKPT lock
56268 ** before checking pInfo->nBackfillAttempted. */
 
 
 
 
56269 rc = walLockShared(pWal, WAL_CKPT_LOCK);
56270
56271 if( rc==SQLITE_OK ){
56272 /* Check that the wal file has not been wrapped. Assuming that it has
56273 ** not, also check that no checkpointer has attempted to checkpoint any
@@ -57215,13 +57445,18 @@
57215 ** in the object.
57216 */
57217 SQLITE_PRIVATE int sqlite3WalSnapshotGet(Wal *pWal, sqlite3_snapshot **ppSnapshot){
57218 int rc = SQLITE_OK;
57219 WalIndexHdr *pRet;
 
57220
57221 assert( pWal->readLock>=0 && pWal->writeLock==0 );
57222
 
 
 
 
57223 pRet = (WalIndexHdr*)sqlite3_malloc(sizeof(WalIndexHdr));
57224 if( pRet==0 ){
57225 rc = SQLITE_NOMEM_BKPT;
57226 }else{
57227 memcpy(pRet, &pWal->hdr, sizeof(WalIndexHdr));
@@ -58922,11 +59157,11 @@
58922 /* For an index btree, save the complete key content */
58923 void *pKey;
58924 pCur->nKey = sqlite3BtreePayloadSize(pCur);
58925 pKey = sqlite3Malloc( pCur->nKey );
58926 if( pKey ){
58927 rc = sqlite3BtreeKey(pCur, 0, (int)pCur->nKey, pKey);
58928 if( rc==SQLITE_OK ){
58929 pCur->pKey = pKey;
58930 }else{
58931 sqlite3_free(pKey);
58932 }
@@ -62941,47 +63176,39 @@
62941 }
62942 return rc;
62943 }
62944
62945 /*
62946 ** Read part of the key associated with cursor pCur. Exactly
62947 ** "amt" bytes will be transferred into pBuf[]. The transfer
62948 ** begins at "offset".
62949 **
62950 ** The caller must ensure that pCur is pointing to a valid row
62951 ** in the table.
 
 
 
 
 
62952 **
62953 ** Return SQLITE_OK on success or an error code if anything goes
62954 ** wrong. An error is returned if "offset+amt" is larger than
62955 ** the available payload.
62956 */
62957 SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
62958 assert( cursorHoldsMutex(pCur) );
62959 assert( pCur->eState==CURSOR_VALID );
62960 assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
62961 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
62962 return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
62963 }
62964
62965 /*
62966 ** Read part of the data associated with cursor pCur. Exactly
62967 ** "amt" bytes will be transfered into pBuf[]. The transfer
62968 ** begins at "offset".
62969 **
62970 ** Return SQLITE_OK on success or an error code if anything goes
62971 ** wrong. An error is returned if "offset+amt" is larger than
62972 ** the available payload.
62973 */
62974 SQLITE_PRIVATE int sqlite3BtreeData(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
62975 int rc;
62976
62977 #ifndef SQLITE_OMIT_INCRBLOB
 
 
62978 if ( pCur->eState==CURSOR_INVALID ){
62979 return SQLITE_ABORT;
62980 }
62981 #endif
62982
62983 assert( cursorOwnsBtShared(pCur) );
62984 rc = restoreCursorPosition(pCur);
62985 if( rc==SQLITE_OK ){
62986 assert( pCur->eState==CURSOR_VALID );
62987 assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
@@ -62988,10 +63215,11 @@
62988 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
62989 rc = accessPayload(pCur, offset, amt, pBuf, 0);
62990 }
62991 return rc;
62992 }
 
62993
62994 /*
62995 ** Return a pointer to payload information from the entry that the
62996 ** pCur cursor is pointing to. The pointer is to the beginning of
62997 ** the key if index btrees (pPage->intKey==0) and is the data for
@@ -69752,14 +69980,13 @@
69752 return SQLITE_OK;
69753 }
69754
69755 /*
69756 ** Move data out of a btree key or data field and into a Mem structure.
69757 ** The data or key is taken from the entry that pCur is currently pointing
69758 ** to. offset and amt determine what portion of the data or key to retrieve.
69759 ** key is true to get the key or false to get data. The result is written
69760 ** into the pMem element.
69761 **
69762 ** The pMem object must have been initialized. This routine will use
69763 ** pMem->zMalloc to hold the content from the btree, if possible. New
69764 ** pMem->zMalloc space will be allocated if necessary. The calling routine
69765 ** is responsible for making sure that the pMem object is eventually
@@ -69770,21 +69997,16 @@
69770 */
69771 static SQLITE_NOINLINE int vdbeMemFromBtreeResize(
69772 BtCursor *pCur, /* Cursor pointing at record to retrieve. */
69773 u32 offset, /* Offset from the start of data to return bytes from. */
69774 u32 amt, /* Number of bytes to return. */
69775 int key, /* If true, retrieve from the btree key, not data. */
69776 Mem *pMem /* OUT: Return data in this Mem structure. */
69777 ){
69778 int rc;
69779 pMem->flags = MEM_Null;
69780 if( SQLITE_OK==(rc = sqlite3VdbeMemClearAndResize(pMem, amt+2)) ){
69781 if( key ){
69782 rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
69783 }else{
69784 rc = sqlite3BtreeData(pCur, offset, amt, pMem->z);
69785 }
69786 if( rc==SQLITE_OK ){
69787 pMem->z[amt] = 0;
69788 pMem->z[amt+1] = 0;
69789 pMem->flags = MEM_Blob|MEM_Term;
69790 pMem->n = (int)amt;
@@ -69796,11 +70018,10 @@
69796 }
69797 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(
69798 BtCursor *pCur, /* Cursor pointing at record to retrieve. */
69799 u32 offset, /* Offset from the start of data to return bytes from. */
69800 u32 amt, /* Number of bytes to return. */
69801 int key, /* If true, retrieve from the btree key, not data. */
69802 Mem *pMem /* OUT: Return data in this Mem structure. */
69803 ){
69804 char *zData; /* Data from the btree layer */
69805 u32 available = 0; /* Number of bytes available on the local btree page */
69806 int rc = SQLITE_OK; /* Return code */
@@ -69817,11 +70038,11 @@
69817 if( offset+amt<=available ){
69818 pMem->z = &zData[offset];
69819 pMem->flags = MEM_Blob|MEM_Ephem;
69820 pMem->n = (int)amt;
69821 }else{
69822 rc = vdbeMemFromBtreeResize(pCur, offset, amt, key, pMem);
69823 }
69824
69825 return rc;
69826 }
69827
@@ -70847,11 +71068,15 @@
70847 int p2, /* The P2 operand */
70848 int p3, /* The P3 operand */
70849 int p4 /* The P4 operand as an integer */
70850 ){
70851 int addr = sqlite3VdbeAddOp3(p, op, p1, p2, p3);
70852 sqlite3VdbeChangeP4(p, addr, SQLITE_INT_TO_PTR(p4), P4_INT32);
 
 
 
 
70853 return addr;
70854 }
70855
70856 /* Insert the end of a co-routine
70857 */
@@ -71358,14 +71583,10 @@
71358 case P4_EXPR: {
71359 sqlite3ExprDelete(db, (Expr*)p4);
71360 break;
71361 }
71362 #endif
71363 case P4_MPRINTF: {
71364 if( db->pnBytesFreed==0 ) sqlite3_free(p4);
71365 break;
71366 }
71367 case P4_FUNCDEF: {
71368 freeEphemeralFunction(db, (FuncDef*)p4);
71369 break;
71370 }
71371 case P4_MEM: {
@@ -71505,21 +71726,47 @@
71505 pOp->p4.p = (void*)zP4;
71506 pOp->p4type = (signed char)n;
71507 if( n==P4_VTAB ) sqlite3VtabLock((VTable*)zP4);
71508 }
71509 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71510
71511 /*
71512 ** Set the P4 on the most recently added opcode to the KeyInfo for the
71513 ** index given.
71514 */
71515 SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse *pParse, Index *pIdx){
71516 Vdbe *v = pParse->pVdbe;
 
71517 assert( v!=0 );
71518 assert( pIdx!=0 );
71519 sqlite3VdbeChangeP4(v, -1, (char*)sqlite3KeyInfoOfIndex(pParse, pIdx),
71520 P4_KEYINFO);
71521 }
71522
71523 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
71524 /*
71525 ** Change the comment on the most recently coded instruction. Or
@@ -71805,11 +72052,11 @@
71805 case P4_FUNCDEF: {
71806 FuncDef *pDef = pOp->p4.pFunc;
71807 sqlite3XPrintf(&x, "%s(%d)", pDef->zName, pDef->nArg);
71808 break;
71809 }
71810 #ifdef SQLITE_DEBUG
71811 case P4_FUNCCTX: {
71812 FuncDef *pDef = pOp->p4.pCtx->pFunc;
71813 sqlite3XPrintf(&x, "%s(%d)", pDef->zName, pDef->nArg);
71814 break;
71815 }
@@ -74899,11 +75146,11 @@
74899 nCellKey = sqlite3BtreePayloadSize(pCur);
74900 assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
74901
74902 /* Read in the complete content of the index entry */
74903 sqlite3VdbeMemInit(&m, db, 0);
74904 rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m);
74905 if( rc ){
74906 return rc;
74907 }
74908
74909 /* The index entry must begin with a header size */
@@ -74979,11 +75226,11 @@
74979 if( nCellKey<=0 || nCellKey>0x7fffffff ){
74980 *res = 0;
74981 return SQLITE_CORRUPT_BKPT;
74982 }
74983 sqlite3VdbeMemInit(&m, db, 0);
74984 rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m);
74985 if( rc ){
74986 return rc;
74987 }
74988 *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked);
74989 sqlite3VdbeMemRelease(&m);
@@ -76868,11 +77115,11 @@
76868 u8 *aRec;
76869
76870 nRec = sqlite3BtreePayloadSize(p->pCsr->uc.pCursor);
76871 aRec = sqlite3DbMallocRaw(db, nRec);
76872 if( !aRec ) goto preupdate_old_out;
76873 rc = sqlite3BtreeData(p->pCsr->uc.pCursor, 0, nRec, aRec);
76874 if( rc==SQLITE_OK ){
76875 p->pUnpacked = vdbeUnpackRecord(&p->keyinfo, nRec, aRec);
76876 if( !p->pUnpacked ) rc = SQLITE_NOMEM;
76877 }
76878 if( rc!=SQLITE_OK ){
@@ -77385,11 +77632,11 @@
77385
77386 /*
77387 ** Test a register to see if it exceeds the current maximum blob size.
77388 ** If it does, record the new maximum blob size.
77389 */
77390 #if defined(SQLITE_TEST) && !defined(SQLITE_OMIT_BUILTIN_TEST)
77391 # define UPDATE_MAX_BLOBSIZE(P) updateMaxBlobsize(P)
77392 #else
77393 # define UPDATE_MAX_BLOBSIZE(P)
77394 #endif
77395
@@ -79833,11 +80080,10 @@
79833 assert( p2<pC->nField );
79834 aOffset = pC->aOffset;
79835 assert( pC->eCurType!=CURTYPE_VTAB );
79836 assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow );
79837 assert( pC->eCurType!=CURTYPE_SORTER );
79838 pCrsr = pC->uc.pCursor;
79839
79840 if( pC->cacheStatus!=p->cacheCtr ){ /*OPTIMIZATION-IF-FALSE*/
79841 if( pC->nullRow ){
79842 if( pC->eCurType==CURTYPE_PSEUDO ){
79843 assert( pC->uc.pseudoTableReg>0 );
@@ -79849,10 +80095,11 @@
79849 }else{
79850 sqlite3VdbeMemSetNull(pDest);
79851 goto op_column_out;
79852 }
79853 }else{
 
79854 assert( pC->eCurType==CURTYPE_BTREE );
79855 assert( pCrsr );
79856 assert( sqlite3BtreeCursorIsValid(pCrsr) );
79857 pC->payloadSize = sqlite3BtreePayloadSize(pCrsr);
79858 pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &avail);
@@ -79912,11 +80159,11 @@
79912 */
79913 if( pC->iHdrOffset<aOffset[0] ){
79914 /* Make sure zData points to enough of the record to cover the header. */
79915 if( pC->aRow==0 ){
79916 memset(&sMem, 0, sizeof(sMem));
79917 rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0], !pC->isTable, &sMem);
79918 if( rc!=SQLITE_OK ) goto abort_due_to_error;
79919 zData = (u8*)sMem.z;
79920 }else{
79921 zData = pC->aRow;
79922 }
@@ -80025,12 +80272,11 @@
80025 ** So we might as well use bogus content rather than reading
80026 ** content from disk. */
80027 static u8 aZero[8]; /* This is the bogus content */
80028 sqlite3VdbeSerialGet(aZero, t, pDest);
80029 }else{
80030 rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, !pC->isTable,
80031 pDest);
80032 if( rc!=SQLITE_OK ) goto abort_due_to_error;
80033 sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest);
80034 pDest->flags &= ~MEM_Ephem;
80035 }
80036 }
@@ -82002,51 +82248,40 @@
82002 }
82003
82004 /* Opcode: RowData P1 P2 * * *
82005 ** Synopsis: r[P2]=data
82006 **
82007 ** Write into register P2 the complete row data for cursor P1.
 
82008 ** There is no interpretation of the data.
82009 ** It is just copied onto the P2 register exactly as
82010 ** it is found in the database file.
82011 **
82012 ** If the P1 cursor must be pointing to a valid row (not a NULL row)
82013 ** of a real table, not a pseudo-table.
82014 */
82015 /* Opcode: RowKey P1 P2 * * *
82016 ** Synopsis: r[P2]=key
82017 **
82018 ** Write into register P2 the complete row key for cursor P1.
82019 ** There is no interpretation of the data.
82020 ** The key is copied onto the P2 register exactly as
82021 ** it is found in the database file.
82022 **
82023 ** If the P1 cursor must be pointing to a valid row (not a NULL row)
82024 ** of a real table, not a pseudo-table.
82025 */
82026 case OP_RowKey:
82027 case OP_RowData: {
82028 VdbeCursor *pC;
82029 BtCursor *pCrsr;
82030 u32 n;
82031
82032 pOut = &aMem[pOp->p2];
82033 memAboutToChange(p, pOut);
82034
82035 /* Note that RowKey and RowData are really exactly the same instruction */
82036 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
82037 pC = p->apCsr[pOp->p1];
82038 assert( pC!=0 );
82039 assert( pC->eCurType==CURTYPE_BTREE );
82040 assert( isSorter(pC)==0 );
82041 assert( pC->isTable || pOp->opcode!=OP_RowData );
82042 assert( pC->isTable==0 || pOp->opcode==OP_RowData );
82043 assert( pC->nullRow==0 );
82044 assert( pC->uc.pCursor!=0 );
82045 pCrsr = pC->uc.pCursor;
82046
82047 /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or
82048 ** OP_SeekRowid or OP_Rewind/Op_Next with no intervening instructions
82049 ** that might invalidate the cursor.
82050 ** If this where not the case, on of the following assert()s
82051 ** would fail. Should this ever change (because of changes in the code
82052 ** generator) then the fix would be to insert a call to
@@ -82067,15 +82302,11 @@
82067 if( sqlite3VdbeMemClearAndResize(pOut, MAX(n,32)) ){
82068 goto no_mem;
82069 }
82070 pOut->n = n;
82071 MemSetTypeFlag(pOut, MEM_Blob);
82072 if( pC->isTable==0 ){
82073 rc = sqlite3BtreeKey(pCrsr, 0, n, pOut->z);
82074 }else{
82075 rc = sqlite3BtreeData(pCrsr, 0, n, pOut->z);
82076 }
82077 if( rc ) goto abort_due_to_error;
82078 pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
82079 UPDATE_MAX_BLOBSIZE(pOut);
82080 REGISTER_TRACE(pOp->p2, pOut);
82081 break;
@@ -83401,17 +83632,17 @@
83401 }
83402
83403 /* Opcode: DecrJumpZero P1 P2 * * *
83404 ** Synopsis: if (--r[P1])==0 goto P2
83405 **
83406 ** Register P1 must hold an integer. Decrement the value in register P1
83407 ** then jump to P2 if the new value is exactly zero.
83408 */
83409 case OP_DecrJumpZero: { /* jump, in1 */
83410 pIn1 = &aMem[pOp->p1];
83411 assert( pIn1->flags&MEM_Int );
83412 pIn1->u.i--;
83413 VdbeBranchTaken(pIn1->u.i==0, 2);
83414 if( pIn1->u.i==0 ) goto jump_to_p2;
83415 break;
83416 }
83417
@@ -84854,11 +85085,11 @@
84854
84855 /*
84856 ** Read data from a blob handle.
84857 */
84858 SQLITE_API int sqlite3_blob_read(sqlite3_blob *pBlob, void *z, int n, int iOffset){
84859 return blobReadWrite(pBlob, z, n, iOffset, sqlite3BtreeData);
84860 }
84861
84862 /*
84863 ** Write data to a blob handle.
84864 */
@@ -90235,11 +90466,11 @@
90235 ** can be attached to pRight to cause this node to take ownership of
90236 ** pVector. Typically there will be multiple TK_SELECT_COLUMN nodes
90237 ** with the same pLeft pointer to the pVector, but only one of them
90238 ** will own the pVector.
90239 */
90240 pRet = sqlite3PExpr(pParse, TK_SELECT_COLUMN, 0, 0, 0);
90241 if( pRet ){
90242 pRet->iColumn = iField;
90243 pRet->pLeft = pVector;
90244 }
90245 assert( pRet==0 || pRet->iTable==0 );
@@ -90627,19 +90858,23 @@
90627 */
90628 SQLITE_PRIVATE Expr *sqlite3PExpr(
90629 Parse *pParse, /* Parsing context */
90630 int op, /* Expression opcode */
90631 Expr *pLeft, /* Left operand */
90632 Expr *pRight, /* Right operand */
90633 const Token *pToken /* Argument token */
90634 ){
90635 Expr *p;
90636 if( op==TK_AND && pParse->nErr==0 ){
90637 /* Take advantage of short-circuit false optimization for AND */
90638 p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
90639 }else{
90640 p = sqlite3ExprAlloc(pParse->db, op & TKFLG_MASK, pToken, 1);
 
 
 
 
 
90641 sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
90642 }
90643 if( p ) {
90644 sqlite3ExprCheckHeight(pParse, p->nHeight);
90645 }
@@ -92158,10 +92393,32 @@
92158 SQLITE_PRIVATE void sqlite3SubselectError(Parse *pParse, int nActual, int nExpect){
92159 const char *zFmt = "sub-select returns %d columns - expected %d";
92160 sqlite3ErrorMsg(pParse, zFmt, nActual, nExpect);
92161 }
92162 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92163
92164 /*
92165 ** Generate code for scalar subqueries used as a subquery expression, EXISTS,
92166 ** or IN operators. Examples:
92167 **
@@ -92441,15 +92698,11 @@
92441 if( nVector!=pIn->x.pSelect->pEList->nExpr ){
92442 sqlite3SubselectError(pParse, pIn->x.pSelect->pEList->nExpr, nVector);
92443 return 1;
92444 }
92445 }else if( nVector!=1 ){
92446 if( (pIn->pLeft->flags & EP_xIsSelect) ){
92447 sqlite3SubselectError(pParse, nVector, 1);
92448 }else{
92449 sqlite3ErrorMsg(pParse, "row value misused");
92450 }
92451 return 1;
92452 }
92453 return 0;
92454 }
92455 #endif
@@ -92750,26 +93003,26 @@
92750 int c;
92751 i64 value;
92752 const char *z = pExpr->u.zToken;
92753 assert( z!=0 );
92754 c = sqlite3DecOrHexToI64(z, &value);
92755 if( c==0 || (c==2 && negFlag) ){
92756 if( negFlag ){ value = c==2 ? SMALLEST_INT64 : -value; }
92757 sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, iMem, 0, (u8*)&value, P4_INT64);
92758 }else{
92759 #ifdef SQLITE_OMIT_FLOATING_POINT
92760 sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z);
92761 #else
92762 #ifndef SQLITE_OMIT_HEX_INTEGER
92763 if( sqlite3_strnicmp(z,"0x",2)==0 ){
92764 sqlite3ErrorMsg(pParse, "hex literal too big: %s", z);
92765 }else
92766 #endif
92767 {
92768 codeReal(v, z, negFlag, iMem);
92769 }
92770 #endif
 
 
 
92771 }
92772 }
92773 }
92774
92775 /*
@@ -93104,11 +93357,11 @@
93104 }else{
93105 int i;
93106 iResult = pParse->nMem+1;
93107 pParse->nMem += nResult;
93108 for(i=0; i<nResult; i++){
93109 sqlite3ExprCode(pParse, p->x.pList->a[i].pExpr, i+iResult);
93110 }
93111 }
93112 }
93113 return iResult;
93114 }
@@ -93218,11 +93471,11 @@
93218 assert( pExpr->u.zToken[0]!=0 );
93219 sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target);
93220 if( pExpr->u.zToken[1]!=0 ){
93221 assert( pExpr->u.zToken[0]=='?'
93222 || strcmp(pExpr->u.zToken, pParse->azVar[pExpr->iColumn-1])==0 );
93223 sqlite3VdbeChangeP4(v, -1, pParse->azVar[pExpr->iColumn-1], P4_STATIC);
93224 }
93225 return target;
93226 }
93227 case TK_REGISTER: {
93228 return pExpr->iTable;
@@ -93975,10 +94228,15 @@
93975 compRight.pRight = pExpr->x.pList->a[1].pExpr;
93976 exprToRegister(&exprX, exprCodeVector(pParse, &exprX, &regFree1));
93977 if( xJump ){
93978 xJump(pParse, &exprAnd, dest, jumpIfNull);
93979 }else{
 
 
 
 
 
93980 exprX.flags |= EP_FromJoin;
93981 sqlite3ExprCodeTarget(pParse, &exprAnd, dest);
93982 }
93983 sqlite3ReleaseTempReg(pParse, regFree1);
93984
@@ -103465,11 +103723,11 @@
103465 ** DELETE FROM table_a WHERE rowid IN (
103466 ** SELECT rowid FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
103467 ** );
103468 */
103469
103470 pSelectRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0);
103471 if( pSelectRowid == 0 ) goto limit_where_cleanup;
103472 pEList = sqlite3ExprListAppend(pParse, 0, pSelectRowid);
103473 if( pEList == 0 ) goto limit_where_cleanup;
103474
103475 /* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree
@@ -103484,12 +103742,12 @@
103484 pSelect = sqlite3SelectNew(pParse,pEList,pSelectSrc,pWhere,0,0,
103485 pOrderBy,0,pLimit,pOffset);
103486 if( pSelect == 0 ) return 0;
103487
103488 /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
103489 pWhereRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0);
103490 pInClause = pWhereRowid ? sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0) : 0;
103491 sqlite3PExprAddSelect(pParse, pInClause, pSelect);
103492 return pInClause;
103493
103494 limit_where_cleanup:
103495 sqlite3ExprDelete(pParse->db, pWhere);
@@ -103796,11 +104054,11 @@
103796 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
103797 VdbeCoverage(v);
103798 }
103799 }else if( pPk ){
103800 addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v);
103801 sqlite3VdbeAddOp2(v, OP_RowKey, iEphCur, iKey);
103802 assert( nKey==0 ); /* OP_Found will use a composite key */
103803 }else{
103804 addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
103805 VdbeCoverage(v);
103806 assert( nKey==1 );
@@ -104013,11 +104271,11 @@
104013 */
104014 if( pTab->pSelect==0 ){
104015 u8 p5 = 0;
104016 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
104017 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
104018 sqlite3VdbeChangeP4(v, -1, (char*)pTab, P4_TABLE);
104019 if( eMode!=ONEPASS_OFF ){
104020 sqlite3VdbeChangeP5(v, OPFLAG_AUXDELETE);
104021 }
104022 if( iIdxNoSeek>=0 ){
104023 sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek);
@@ -104790,13 +105048,23 @@
104790 /* If SQLITE_CASE_SENSITIVE_LIKE is defined, then the LIKE operator
104791 ** is case sensitive causing 'a' LIKE 'A' to be false */
104792 static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 };
104793
104794 /*
104795 ** Compare two UTF-8 strings for equality where the first string can
104796 ** potentially be a "glob" or "like" expression. Return true (1) if they
104797 ** are the same and false (0) if they are different.
 
 
 
 
 
 
 
 
 
 
104798 **
104799 ** Globbing rules:
104800 **
104801 ** '*' Matches any sequence of zero or more characters.
104802 **
@@ -104843,71 +105111,76 @@
104843 /* Skip over multiple "*" characters in the pattern. If there
104844 ** are also "?" characters, skip those as well, but consume a
104845 ** single character of the input string for each "?" skipped */
104846 while( (c=Utf8Read(zPattern)) == matchAll || c == matchOne ){
104847 if( c==matchOne && sqlite3Utf8Read(&zString)==0 ){
104848 return 0;
104849 }
104850 }
104851 if( c==0 ){
104852 return 1; /* "*" at the end of the pattern matches */
104853 }else if( c==matchOther ){
104854 if( pInfo->matchSet==0 ){
104855 c = sqlite3Utf8Read(&zPattern);
104856 if( c==0 ) return 0;
104857 }else{
104858 /* "[...]" immediately follows the "*". We have to do a slow
104859 ** recursive search in this case, but it is an unusual case. */
104860 assert( matchOther<0x80 ); /* '[' is a single-byte character */
104861 while( *zString
104862 && patternCompare(&zPattern[-1],zString,pInfo,matchOther)==0 ){
 
104863 SQLITE_SKIP_UTF8(zString);
104864 }
104865 return *zString!=0;
104866 }
104867 }
104868
104869 /* At this point variable c contains the first character of the
104870 ** pattern string past the "*". Search in the input string for the
104871 ** first matching character and recursively contine the match from
104872 ** that point.
104873 **
104874 ** For a case-insensitive search, set variable cx to be the same as
104875 ** c but in the other case and search the input string for either
104876 ** c or cx.
104877 */
104878 if( c<=0x80 ){
104879 u32 cx;
 
104880 if( noCase ){
104881 cx = sqlite3Toupper(c);
104882 c = sqlite3Tolower(c);
104883 }else{
104884 cx = c;
104885 }
104886 while( (c2 = *(zString++))!=0 ){
104887 if( c2!=c && c2!=cx ) continue;
104888 if( patternCompare(zPattern,zString,pInfo,matchOther) ) return 1;
 
104889 }
104890 }else{
 
104891 while( (c2 = Utf8Read(zString))!=0 ){
104892 if( c2!=c ) continue;
104893 if( patternCompare(zPattern,zString,pInfo,matchOther) ) return 1;
 
104894 }
104895 }
104896 return 0;
104897 }
104898 if( c==matchOther ){
104899 if( pInfo->matchSet==0 ){
104900 c = sqlite3Utf8Read(&zPattern);
104901 if( c==0 ) return 0;
104902 zEscaped = zPattern;
104903 }else{
104904 u32 prior_c = 0;
104905 int seen = 0;
104906 int invert = 0;
104907 c = sqlite3Utf8Read(&zString);
104908 if( c==0 ) return 0;
104909 c2 = sqlite3Utf8Read(&zPattern);
104910 if( c2=='^' ){
104911 invert = 1;
104912 c2 = sqlite3Utf8Read(&zPattern);
104913 }
@@ -104927,11 +105200,11 @@
104927 prior_c = c2;
104928 }
104929 c2 = sqlite3Utf8Read(&zPattern);
104930 }
104931 if( c2==0 || (seen ^ invert)==0 ){
104932 return 0;
104933 }
104934 continue;
104935 }
104936 }
104937 c2 = Utf8Read(zString);
@@ -104938,27 +105211,29 @@
104938 if( c==c2 ) continue;
104939 if( noCase && sqlite3Tolower(c)==sqlite3Tolower(c2) && c<0x80 && c2<0x80 ){
104940 continue;
104941 }
104942 if( c==matchOne && zPattern!=zEscaped && c2!=0 ) continue;
104943 return 0;
104944 }
104945 return *zString==0;
104946 }
104947
104948 /*
104949 ** The sqlite3_strglob() interface.
 
104950 */
104951 SQLITE_API int sqlite3_strglob(const char *zGlobPattern, const char *zString){
104952 return patternCompare((u8*)zGlobPattern, (u8*)zString, &globInfo, '[')==0;
104953 }
104954
104955 /*
104956 ** The sqlite3_strlike() interface.
 
104957 */
104958 SQLITE_API int sqlite3_strlike(const char *zPattern, const char *zStr, unsigned int esc){
104959 return patternCompare((u8*)zPattern, (u8*)zStr, &likeInfoNorm, esc)==0;
104960 }
104961
104962 /*
104963 ** Count the number of times that the LIKE operator (or GLOB which is
104964 ** just a variation of LIKE) gets called. This is used for testing
@@ -105035,11 +105310,11 @@
105035 }
105036 if( zA && zB ){
105037 #ifdef SQLITE_TEST
105038 sqlite3_like_count++;
105039 #endif
105040 sqlite3_result_int(context, patternCompare(zB, zA, pInfo, escape));
105041 }
105042 }
105043
105044 /*
105045 ** Implementation of the NULLIF(x,y) function. The result is the first
@@ -106628,11 +106903,11 @@
106628 pLeft = exprTableRegister(pParse, pTab, regData, iCol);
106629 iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
106630 assert( iCol>=0 );
106631 zCol = pFKey->pFrom->aCol[iCol].zName;
106632 pRight = sqlite3Expr(db, TK_ID, zCol);
106633 pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0);
106634 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
106635 }
106636
106637 /* If the child table is the same as the parent table, then add terms
106638 ** to the WHERE clause that prevent this entry from being scanned.
@@ -106650,24 +106925,24 @@
106650 Expr *pLeft; /* Value from parent table row */
106651 Expr *pRight; /* Column ref to child table */
106652 if( HasRowid(pTab) ){
106653 pLeft = exprTableRegister(pParse, pTab, regData, -1);
106654 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
106655 pNe = sqlite3PExpr(pParse, TK_NE, pLeft, pRight, 0);
106656 }else{
106657 Expr *pEq, *pAll = 0;
106658 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
106659 assert( pIdx!=0 );
106660 for(i=0; i<pPk->nKeyCol; i++){
106661 i16 iCol = pIdx->aiColumn[i];
106662 assert( iCol>=0 );
106663 pLeft = exprTableRegister(pParse, pTab, regData, iCol);
106664 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol);
106665 pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0);
106666 pAll = sqlite3ExprAnd(db, pAll, pEq);
106667 }
106668 pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0, 0);
106669 }
106670 pWhere = sqlite3ExprAnd(db, pWhere, pNe);
106671 }
106672
106673 /* Resolve the references in the WHERE clause. */
@@ -107249,14 +107524,13 @@
107249 ** that the affinity and collation sequence associated with the
107250 ** parent table are used for the comparison. */
107251 pEq = sqlite3PExpr(pParse, TK_EQ,
107252 sqlite3PExpr(pParse, TK_DOT,
107253 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
107254 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
107255 , 0),
107256 sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0)
107257 , 0);
107258 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
107259
107260 /* For ON UPDATE, construct the next term of the WHEN clause.
107261 ** The final WHEN clause will be like this:
107262 **
@@ -107264,27 +107538,24 @@
107264 */
107265 if( pChanges ){
107266 pEq = sqlite3PExpr(pParse, TK_IS,
107267 sqlite3PExpr(pParse, TK_DOT,
107268 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
107269 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
107270 0),
107271 sqlite3PExpr(pParse, TK_DOT,
107272 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
107273 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
107274 0),
107275 0);
107276 pWhen = sqlite3ExprAnd(db, pWhen, pEq);
107277 }
107278
107279 if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){
107280 Expr *pNew;
107281 if( action==OE_Cascade ){
107282 pNew = sqlite3PExpr(pParse, TK_DOT,
107283 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
107284 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
107285 , 0);
107286 }else if( action==OE_SetDflt ){
107287 Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt;
107288 if( pDflt ){
107289 pNew = sqlite3ExprDup(db, pDflt, 0);
107290 }else{
@@ -107336,11 +107607,11 @@
107336
107337 pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
107338 pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
107339 pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
107340 if( pWhen ){
107341 pWhen = sqlite3PExpr(pParse, TK_NOT, pWhen, 0, 0);
107342 pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
107343 }
107344 }
107345
107346 /* Re-enable the lookaside buffer, if it was disabled earlier. */
@@ -108760,12 +109031,13 @@
108760 /* Fall through */
108761 case OE_Rollback:
108762 case OE_Fail: {
108763 char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
108764 pTab->aCol[i].zName);
108765 sqlite3VdbeAddOp4(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, onError,
108766 regNewData+1+i, zMsg, P4_DYNAMIC);
 
108767 sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
108768 VdbeCoverage(v);
108769 break;
108770 }
108771 case OE_Ignore: {
@@ -108903,11 +109175,11 @@
108903 /* This OP_Delete opcode fires the pre-update-hook only. It does
108904 ** not modify the b-tree. It is more efficient to let the coming
108905 ** OP_Insert replace the existing entry than it is to delete the
108906 ** existing entry and then insert a new one. */
108907 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, OPFLAG_ISNOOP);
108908 sqlite3VdbeChangeP4(v, -1, (char *)pTab, P4_TABLE);
108909 }
108910 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
108911 if( pTab->pIndex ){
108912 sqlite3MultiWrite(pParse);
108913 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,-1);
@@ -109180,11 +109452,11 @@
109180 if( useSeekResult ){
109181 pik_flags |= OPFLAG_USESEEKRESULT;
109182 }
109183 sqlite3VdbeAddOp3(v, OP_Insert, iDataCur, regRec, regNewData);
109184 if( !pParse->nested ){
109185 sqlite3VdbeChangeP4(v, -1, (char *)pTab, P4_TABLE);
109186 }
109187 sqlite3VdbeChangeP5(v, pik_flags);
109188 }
109189
109190 /*
@@ -109611,11 +109883,11 @@
109611 sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest);
109612 sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
109613 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
109614 VdbeComment((v, "%s", pDestIdx->zName));
109615 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
109616 sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
109617 if( db->flags & SQLITE_Vacuum ){
109618 /* This INSERT command is part of a VACUUM operation, which guarantees
109619 ** that the destination table is empty. If all indexed columns use
109620 ** collation sequence BINARY, then it can also be assumed that the
109621 ** index will be populated by inserting keys in strictly sorted
@@ -114820,11 +115092,11 @@
114820 assert( pSrc->a[iRight].pTab );
114821
114822 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iColLeft);
114823 pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
114824
114825 pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2, 0);
114826 if( pEq && isOuterJoin ){
114827 ExprSetProperty(pEq, EP_FromJoin);
114828 assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) );
114829 ExprSetVVAProperty(pEq, EP_NoReduce);
114830 pEq->iRightJoinTable = (i16)pE2->iTable;
@@ -116992,11 +117264,11 @@
116992 iBreak = sqlite3VdbeMakeLabel(v);
116993 iCont = sqlite3VdbeMakeLabel(v);
116994 computeLimitRegisters(pParse, p, iBreak);
116995 sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
116996 r1 = sqlite3GetTempReg(pParse);
116997 iStart = sqlite3VdbeAddOp2(v, OP_RowKey, tab1, r1);
116998 sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0); VdbeCoverage(v);
116999 sqlite3ReleaseTempReg(pParse, r1);
117000 selectInnerLoop(pParse, p, p->pEList, tab1,
117001 0, 0, &dest, iCont, iBreak);
117002 sqlite3VdbeResolveLabel(v, iCont);
@@ -117619,12 +117891,12 @@
117619 }
117620 #endif
117621
117622 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
117623 /* Forward Declarations */
117624 static void substExprList(sqlite3*, ExprList*, int, ExprList*);
117625 static void substSelect(sqlite3*, Select *, int, ExprList*, int);
117626
117627 /*
117628 ** Scan through the expression pExpr. Replace every reference to
117629 ** a column in table number iTable with a copy of the iColumn-th
117630 ** entry in pEList. (But leave references to the ROWID column
@@ -117636,52 +117908,62 @@
117636 ** FORM clause entry is iTable. This routine make the necessary
117637 ** changes to pExpr so that it refers directly to the source table
117638 ** of the subquery rather the result set of the subquery.
117639 */
117640 static Expr *substExpr(
117641 sqlite3 *db, /* Report malloc errors to this connection */
117642 Expr *pExpr, /* Expr in which substitution occurs */
117643 int iTable, /* Table to be substituted */
117644 ExprList *pEList /* Substitute expressions */
117645 ){
 
117646 if( pExpr==0 ) return 0;
117647 if( pExpr->op==TK_COLUMN && pExpr->iTable==iTable ){
117648 if( pExpr->iColumn<0 ){
117649 pExpr->op = TK_NULL;
117650 }else{
117651 Expr *pNew;
 
117652 assert( pEList!=0 && pExpr->iColumn<pEList->nExpr );
117653 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
117654 pNew = sqlite3ExprDup(db, pEList->a[pExpr->iColumn].pExpr, 0);
117655 sqlite3ExprDelete(db, pExpr);
117656 pExpr = pNew;
 
 
 
 
 
 
 
 
117657 }
117658 }else{
117659 pExpr->pLeft = substExpr(db, pExpr->pLeft, iTable, pEList);
117660 pExpr->pRight = substExpr(db, pExpr->pRight, iTable, pEList);
117661 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
117662 substSelect(db, pExpr->x.pSelect, iTable, pEList, 1);
117663 }else{
117664 substExprList(db, pExpr->x.pList, iTable, pEList);
117665 }
117666 }
117667 return pExpr;
117668 }
117669 static void substExprList(
117670 sqlite3 *db, /* Report malloc errors here */
117671 ExprList *pList, /* List to scan and in which to make substitutes */
117672 int iTable, /* Table to be substituted */
117673 ExprList *pEList /* Substitute values */
117674 ){
117675 int i;
117676 if( pList==0 ) return;
117677 for(i=0; i<pList->nExpr; i++){
117678 pList->a[i].pExpr = substExpr(db, pList->a[i].pExpr, iTable, pEList);
117679 }
117680 }
117681 static void substSelect(
117682 sqlite3 *db, /* Report malloc errors here */
117683 Select *p, /* SELECT statement in which to make substitutions */
117684 int iTable, /* Table to be replaced */
117685 ExprList *pEList, /* Substitute values */
117686 int doPrior /* Do substitutes on p->pPrior too */
117687 ){
@@ -117688,21 +117970,21 @@
117688 SrcList *pSrc;
117689 struct SrcList_item *pItem;
117690 int i;
117691 if( !p ) return;
117692 do{
117693 substExprList(db, p->pEList, iTable, pEList);
117694 substExprList(db, p->pGroupBy, iTable, pEList);
117695 substExprList(db, p->pOrderBy, iTable, pEList);
117696 p->pHaving = substExpr(db, p->pHaving, iTable, pEList);
117697 p->pWhere = substExpr(db, p->pWhere, iTable, pEList);
117698 pSrc = p->pSrc;
117699 assert( pSrc!=0 );
117700 for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
117701 substSelect(db, pItem->pSelect, iTable, pEList, 1);
117702 if( pItem->fg.isTabFunc ){
117703 substExprList(db, pItem->u1.pFuncArg, iTable, pEList);
117704 }
117705 }
117706 }while( doPrior && (p = p->pPrior)!=0 );
117707 }
117708 #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
@@ -118223,11 +118505,11 @@
118223 assert( pParent->pGroupBy==0 );
118224 pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
118225 }else{
118226 pParent->pWhere = sqlite3ExprAnd(db, pWhere, pParent->pWhere);
118227 }
118228 substSelect(db, pParent, iParent, pSub->pEList, 0);
118229
118230 /* The flattened query is distinct if either the inner or the
118231 ** outer query is distinct.
118232 */
118233 pParent->selFlags |= pSub->selFlags & SF_Distinct;
@@ -118297,11 +118579,11 @@
118297 **
118298 ** Return 0 if no changes are made and non-zero if one or more WHERE clause
118299 ** terms are duplicated into the subquery.
118300 */
118301 static int pushDownWhereTerms(
118302 sqlite3 *db, /* The database connection (for malloc()) */
118303 Select *pSubq, /* The subquery whose WHERE clause is to be augmented */
118304 Expr *pWhere, /* The WHERE clause of the outer query */
118305 int iCursor /* Cursor number of the subquery */
118306 ){
118307 Expr *pNew;
@@ -118318,20 +118600,20 @@
118318 }
118319 if( pSubq->pLimit!=0 ){
118320 return 0; /* restriction (3) */
118321 }
118322 while( pWhere->op==TK_AND ){
118323 nChng += pushDownWhereTerms(db, pSubq, pWhere->pRight, iCursor);
118324 pWhere = pWhere->pLeft;
118325 }
118326 if( ExprHasProperty(pWhere,EP_FromJoin) ) return 0; /* restriction 5 */
118327 if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
118328 nChng++;
118329 while( pSubq ){
118330 pNew = sqlite3ExprDup(db, pWhere, 0);
118331 pNew = substExpr(db, pNew, iCursor, pSubq->pEList);
118332 pSubq->pWhere = sqlite3ExprAnd(db, pSubq->pWhere, pNew);
118333 pSubq = pSubq->pPrior;
118334 }
118335 }
118336 return nChng;
118337 }
@@ -118957,14 +119239,14 @@
118957 zColname = zName;
118958 zToFree = 0;
118959 if( longNames || pTabList->nSrc>1 ){
118960 Expr *pLeft;
118961 pLeft = sqlite3Expr(db, TK_ID, zTabName);
118962 pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
118963 if( zSchemaName ){
118964 pLeft = sqlite3Expr(db, TK_ID, zSchemaName);
118965 pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pExpr, 0);
118966 }
118967 if( longNames ){
118968 zColname = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
118969 zToFree = zColname;
118970 }
@@ -119197,12 +119479,12 @@
119197 int i;
119198 struct AggInfo_func *pF;
119199 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
119200 ExprList *pList = pF->pExpr->x.pList;
119201 assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
119202 sqlite3VdbeAddOp4(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0, 0,
119203 (void*)pF->pFunc, P4_FUNCDEF);
119204 }
119205 }
119206
119207 /*
119208 ** Update the accumulator memory cells for an aggregate based on
@@ -119249,12 +119531,12 @@
119249 pColl = pParse->db->pDfltColl;
119250 }
119251 if( regHit==0 && pAggInfo->nAccumulator ) regHit = ++pParse->nMem;
119252 sqlite3VdbeAddOp4(v, OP_CollSeq, regHit, 0, 0, (char *)pColl, P4_COLLSEQ);
119253 }
119254 sqlite3VdbeAddOp4(v, OP_AggStep0, 0, regAgg, pF->iMem,
119255 (void*)pF->pFunc, P4_FUNCDEF);
119256 sqlite3VdbeChangeP5(v, (u8)nArg);
119257 sqlite3ExprCacheAffinityChange(pParse, regAgg, nArg);
119258 sqlite3ReleaseTempRange(pParse, regAgg, nArg);
119259 if( addrNext ){
119260 sqlite3VdbeResolveLabel(v, addrNext);
@@ -119484,11 +119766,11 @@
119484
119485 /* Make copies of constant WHERE-clause terms in the outer query down
119486 ** inside the subquery. This can help the subquery to run more efficiently.
119487 */
119488 if( (pItem->fg.jointype & JT_OUTER)==0
119489 && pushDownWhereTerms(db, pSub, p->pWhere, pItem->iCursor)
119490 ){
119491 #if SELECTTRACE_ENABLED
119492 if( sqlite3SelectTrace & 0x100 ){
119493 SELECTTRACE(0x100,pParse,p,("After WHERE-clause push-down:\n"));
119494 sqlite3TreeViewSelect(0, p, 0);
@@ -121570,11 +121852,11 @@
121570 VdbeComment((v, "%s.%s", pTab->zName, pCol->zName));
121571 assert( i<pTab->nCol );
121572 sqlite3ValueFromExpr(sqlite3VdbeDb(v), pCol->pDflt, enc,
121573 pCol->affinity, &pValue);
121574 if( pValue ){
121575 sqlite3VdbeChangeP4(v, -1, (const char *)pValue, P4_MEM);
121576 }
121577 #ifndef SQLITE_OMIT_FLOATING_POINT
121578 if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){
121579 sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
121580 }
@@ -121953,11 +122235,11 @@
121953 VdbeCoverageIf(v, pPk==0);
121954 VdbeCoverageIf(v, pPk!=0);
121955 }else if( pPk ){
121956 labelContinue = sqlite3VdbeMakeLabel(v);
121957 sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak); VdbeCoverage(v);
121958 addrTop = sqlite3VdbeAddOp2(v, OP_RowKey, iEph, regKey);
121959 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey, 0);
121960 VdbeCoverage(v);
121961 }else{
121962 labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet, labelBreak,
121963 regOldRowid);
@@ -122111,11 +122393,11 @@
122111 sqlite3VdbeAddOp3(v, OP_Delete, iDataCur,
122112 OPFLAG_ISUPDATE | ((hasFK || chngKey || pPk!=0) ? 0 : OPFLAG_ISNOOP),
122113 regNewRowid
122114 );
122115 if( !pParse->nested ){
122116 sqlite3VdbeChangeP4(v, -1, (char*)pTab, P4_TABLE);
122117 }
122118 #else
122119 if( hasFK || chngKey || pPk!=0 ){
122120 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
122121 }
@@ -125607,11 +125889,11 @@
125607 }
125608 sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg);
125609 sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1);
125610 sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg,
125611 pLoop->u.vtab.idxStr,
125612 pLoop->u.vtab.needFree ? P4_MPRINTF : P4_STATIC);
125613 VdbeCoverage(v);
125614 pLoop->u.vtab.needFree = 0;
125615 pLevel->p1 = iCur;
125616 pLevel->op = pWInfo->eOnePass ? OP_Noop : OP_VNext;
125617 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
@@ -125640,11 +125922,11 @@
125640 sqlite3VdbeAddOp3(v, pOp->opcode, pOp->p1, pOp->p2, pOp->p3);
125641 }
125642
125643 /* Generate code that will continue to the next row if
125644 ** the IN constraint is not satisfied */
125645 pCompare = sqlite3PExpr(pParse, TK_EQ, 0, 0, 0);
125646 assert( pCompare!=0 || db->mallocFailed );
125647 if( pCompare ){
125648 pCompare->pLeft = pTerm->pExpr->pLeft;
125649 pCompare->pRight = pRight = sqlite3Expr(db, TK_REGISTER, 0);
125650 if( pRight ){
@@ -126239,11 +126521,11 @@
126239 testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
126240 pExpr = sqlite3ExprDup(db, pExpr, 0);
126241 pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr);
126242 }
126243 if( pAndExpr ){
126244 pAndExpr = sqlite3PExpr(pParse, TK_AND|TKFLG_DONTFOLD, 0, pAndExpr, 0);
126245 }
126246 }
126247
126248 /* Run a separate WHERE clause for each term of the OR clause. After
126249 ** eliminating duplicates from other WHERE clauses, the action for each
@@ -127241,11 +127523,11 @@
127241 pList = sqlite3ExprListAppend(pWInfo->pParse, pList, pDup);
127242 pLeft = pOrTerm->pExpr->pLeft;
127243 }
127244 assert( pLeft!=0 );
127245 pDup = sqlite3ExprDup(db, pLeft, 0);
127246 pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0, 0);
127247 if( pNew ){
127248 int idxNew;
127249 transferJoinMarkings(pNew, pExpr);
127250 assert( !ExprHasProperty(pNew, EP_xIsSelect) );
127251 pNew->x.pList = pList;
@@ -127539,11 +127821,11 @@
127539 for(i=0; i<2; i++){
127540 Expr *pNewExpr;
127541 int idxNew;
127542 pNewExpr = sqlite3PExpr(pParse, ops[i],
127543 sqlite3ExprDup(db, pExpr->pLeft, 0),
127544 sqlite3ExprDup(db, pList->a[i].pExpr, 0), 0);
127545 transferJoinMarkings(pNewExpr, pExpr);
127546 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
127547 testcase( idxNew==0 );
127548 exprAnalyze(pSrc, pWC, idxNew);
127549 pTerm = &pWC->a[idxTerm];
@@ -127624,19 +127906,19 @@
127624 }
127625 zCollSeqName = noCase ? "NOCASE" : "BINARY";
127626 pNewExpr1 = sqlite3ExprDup(db, pLeft, 0);
127627 pNewExpr1 = sqlite3PExpr(pParse, TK_GE,
127628 sqlite3ExprAddCollateString(pParse,pNewExpr1,zCollSeqName),
127629 pStr1, 0);
127630 transferJoinMarkings(pNewExpr1, pExpr);
127631 idxNew1 = whereClauseInsert(pWC, pNewExpr1, wtFlags);
127632 testcase( idxNew1==0 );
127633 exprAnalyze(pSrc, pWC, idxNew1);
127634 pNewExpr2 = sqlite3ExprDup(db, pLeft, 0);
127635 pNewExpr2 = sqlite3PExpr(pParse, TK_LT,
127636 sqlite3ExprAddCollateString(pParse,pNewExpr2,zCollSeqName),
127637 pStr2, 0);
127638 transferJoinMarkings(pNewExpr2, pExpr);
127639 idxNew2 = whereClauseInsert(pWC, pNewExpr2, wtFlags);
127640 testcase( idxNew2==0 );
127641 exprAnalyze(pSrc, pWC, idxNew2);
127642 pTerm = &pWC->a[idxTerm];
@@ -127665,11 +127947,11 @@
127665 prereqExpr = sqlite3WhereExprUsage(pMaskSet, pRight);
127666 prereqColumn = sqlite3WhereExprUsage(pMaskSet, pLeft);
127667 if( (prereqExpr & prereqColumn)==0 ){
127668 Expr *pNewExpr;
127669 pNewExpr = sqlite3PExpr(pParse, TK_MATCH,
127670 0, sqlite3ExprDup(db, pRight, 0), 0);
127671 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
127672 testcase( idxNew==0 );
127673 pNewTerm = &pWC->a[idxNew];
127674 pNewTerm->prereqRight = prereqExpr;
127675 pNewTerm->leftCursor = pLeft->iTable;
@@ -127704,11 +127986,11 @@
127704 int idxNew;
127705 Expr *pNew;
127706 Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i);
127707 Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i);
127708
127709 pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight, 0);
127710 transferJoinMarkings(pNew, pExpr);
127711 idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC);
127712 exprAnalyze(pSrc, pWC, idxNew);
127713 }
127714 pTerm = &pWC->a[idxTerm];
@@ -127756,11 +128038,11 @@
127756 int idxNew;
127757 WhereTerm *pNewTerm;
127758
127759 pNewExpr = sqlite3PExpr(pParse, TK_GT,
127760 sqlite3ExprDup(db, pLeft, 0),
127761 sqlite3ExprAlloc(db, TK_NULL, 0, 0), 0);
127762
127763 idxNew = whereClauseInsert(pWC, pNewExpr,
127764 TERM_VIRTUAL|TERM_DYNAMIC|TERM_VNULL);
127765 if( idxNew ){
127766 pNewTerm = &pWC->a[idxNew];
@@ -127942,11 +128224,11 @@
127942 if( pColRef==0 ) return;
127943 pColRef->iTable = pItem->iCursor;
127944 pColRef->iColumn = k++;
127945 pColRef->pTab = pTab;
127946 pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef,
127947 sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
127948 whereClauseInsert(pWC, pTerm, TERM_DYNAMIC);
127949 }
127950 }
127951
127952 /************** End of whereexpr.c *******************************************/
@@ -133067,20 +133349,20 @@
133067 Parse *pParse, /* The parsing context. Errors accumulate here */
133068 int op, /* The binary operation */
133069 ExprSpan *pLeft, /* The left operand, and output */
133070 ExprSpan *pRight /* The right operand */
133071 ){
133072 pLeft->pExpr = sqlite3PExpr(pParse, op, pLeft->pExpr, pRight->pExpr, 0);
133073 pLeft->zEnd = pRight->zEnd;
133074 }
133075
133076 /* If doNot is true, then add a TK_NOT Expr-node wrapper around the
133077 ** outside of *ppExpr.
133078 */
133079 static void exprNot(Parse *pParse, int doNot, ExprSpan *pSpan){
133080 if( doNot ){
133081 pSpan->pExpr = sqlite3PExpr(pParse, TK_NOT, pSpan->pExpr, 0, 0);
133082 }
133083 }
133084
133085 /* Construct an expression node for a unary postfix operator
133086 */
@@ -133088,11 +133370,11 @@
133088 Parse *pParse, /* Parsing context to record errors */
133089 int op, /* The operator */
133090 ExprSpan *pOperand, /* The operand, and output */
133091 Token *pPostOp /* The operand token for setting the span */
133092 ){
133093 pOperand->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0);
133094 pOperand->zEnd = &pPostOp->z[pPostOp->n];
133095 }
133096
133097 /* A routine to convert a binary TK_IS or TK_ISNOT expression into a
133098 ** unary TK_ISNULL or TK_NOTNULL expression. */
@@ -133113,11 +133395,11 @@
133113 int op, /* The operator */
133114 ExprSpan *pOperand, /* The operand */
133115 Token *pPreOp /* The operand token for setting the span */
133116 ){
133117 pOut->zStart = pPreOp->z;
133118 pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0);
133119 pOut->zEnd = pOperand->zEnd;
133120 }
133121
133122 /* Add a single new term to an ExprList that is used to store a
133123 ** list of identifiers. Report an error if the ID list contains
@@ -134706,11 +134988,10 @@
134706 /*
134707 ** The following routine is called if the stack overflows.
134708 */
134709 static void yyStackOverflow(yyParser *yypParser){
134710 sqlite3ParserARG_FETCH;
134711 yypParser->yytos--;
134712 #ifndef NDEBUG
134713 if( yyTraceFILE ){
134714 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
134715 }
134716 #endif
@@ -134761,16 +135042,18 @@
134761 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
134762 }
134763 #endif
134764 #if YYSTACKDEPTH>0
134765 if( yypParser->yytos>=&yypParser->yystack[YYSTACKDEPTH] ){
 
134766 yyStackOverflow(yypParser);
134767 return;
134768 }
134769 #else
134770 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
134771 if( yyGrowStack(yypParser) ){
 
134772 yyStackOverflow(yypParser);
134773 return;
134774 }
134775 }
134776 #endif
@@ -135308,11 +135591,11 @@
135308 {sqlite3AddDefaultValue(pParse,&yymsp[-1].minor.yy190);}
135309 break;
135310 case 33: /* ccons ::= DEFAULT MINUS term */
135311 {
135312 ExprSpan v;
135313 v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy190.pExpr, 0, 0);
135314 v.zStart = yymsp[-1].minor.yy0.z;
135315 v.zEnd = yymsp[0].minor.yy190.zEnd;
135316 sqlite3AddDefaultValue(pParse,&v);
135317 }
135318 break;
@@ -135572,13 +135855,13 @@
135572 yymsp[-1].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy148, p);
135573 }
135574 break;
135575 case 94: /* selcollist ::= sclp nm DOT STAR */
135576 {
135577 Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0, 0);
135578 Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
135579 Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
135580 yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148, pDot);
135581 }
135582 break;
135583 case 95: /* as ::= AS nm */
135584 case 106: /* dbnm ::= DOT nm */ yytestcase(yyruleno==106);
@@ -135800,21 +136083,21 @@
135800 case 154: /* expr ::= nm DOT nm */
135801 {
135802 Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
135803 Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
135804 spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
135805 yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
135806 }
135807 break;
135808 case 155: /* expr ::= nm DOT nm DOT nm */
135809 {
135810 Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-4].minor.yy0, 1);
135811 Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
135812 Expr *temp3 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
135813 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0);
135814 spanSet(&yymsp[-4].minor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
135815 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
135816 }
135817 break;
135818 case 158: /* term ::= INTEGER */
135819 {
135820 yylhsminor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
@@ -135839,11 +136122,11 @@
135839 spanSet(&yymsp[0].minor.yy190, &t, &t);
135840 if( pParse->nested==0 ){
135841 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t);
135842 yymsp[0].minor.yy190.pExpr = 0;
135843 }else{
135844 yymsp[0].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, 0);
135845 if( yymsp[0].minor.yy190.pExpr ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy190.pExpr->iTable);
135846 }
135847 }
135848 }
135849 break;
@@ -135854,11 +136137,12 @@
135854 }
135855 break;
135856 case 161: /* expr ::= CAST LP expr AS typetoken RP */
135857 {
135858 spanSet(&yymsp[-5].minor.yy190,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
135859 yymsp[-5].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy190.pExpr, 0, &yymsp[-1].minor.yy0);
 
135860 }
135861 break;
135862 case 162: /* expr ::= ID|INDEXED LP distinct exprlist RP */
135863 {
135864 if( yymsp[-1].minor.yy148 && yymsp[-1].minor.yy148->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
@@ -135887,11 +136171,11 @@
135887 yymsp[0].minor.yy190 = yylhsminor.yy190;
135888 break;
135889 case 165: /* expr ::= LP nexprlist COMMA expr RP */
135890 {
135891 ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy148, yymsp[-1].minor.yy190.pExpr);
135892 yylhsminor.yy190.pExpr = sqlite3PExpr(pParse, TK_VECTOR, 0, 0, 0);
135893 if( yylhsminor.yy190.pExpr ){
135894 yylhsminor.yy190.pExpr->x.pList = pList;
135895 spanSet(&yylhsminor.yy190, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0);
135896 }else{
135897 sqlite3ExprListDelete(pParse->db, pList);
@@ -135976,11 +136260,11 @@
135976 break;
135977 case 188: /* expr ::= expr between_op expr AND expr */
135978 {
135979 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr);
135980 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy190.pExpr);
135981 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy190.pExpr, 0, 0);
135982 if( yymsp[-4].minor.yy190.pExpr ){
135983 yymsp[-4].minor.yy190.pExpr->x.pList = pList;
135984 }else{
135985 sqlite3ExprListDelete(pParse->db, pList);
135986 }
@@ -135998,11 +136282,11 @@
135998 **
135999 ** simplify to constants 0 (false) and 1 (true), respectively,
136000 ** regardless of the value of expr1.
136001 */
136002 sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy190.pExpr);
136003 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, &sqlite3IntTokens[yymsp[-3].minor.yy194]);
136004 }else if( yymsp[-1].minor.yy148->nExpr==1 ){
136005 /* Expressions of the form:
136006 **
136007 ** expr1 IN (?1)
136008 ** expr1 NOT IN (?2)
@@ -136025,13 +136309,13 @@
136025 ** before now and control would have never reached this point */
136026 if( ALWAYS(pRHS) ){
136027 pRHS->flags &= ~EP_Collate;
136028 pRHS->flags |= EP_Generic;
136029 }
136030 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, yymsp[-3].minor.yy194 ? TK_NE : TK_EQ, yymsp[-4].minor.yy190.pExpr, pRHS, 0);
136031 }else{
136032 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0, 0);
136033 if( yymsp[-4].minor.yy190.pExpr ){
136034 yymsp[-4].minor.yy190.pExpr->x.pList = yymsp[-1].minor.yy148;
136035 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy190.pExpr);
136036 }else{
136037 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy148);
@@ -136042,17 +136326,17 @@
136042 }
136043 break;
136044 case 192: /* expr ::= LP select RP */
136045 {
136046 spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
136047 yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
136048 sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy190.pExpr, yymsp[-1].minor.yy243);
136049 }
136050 break;
136051 case 193: /* expr ::= expr in_op LP select RP */
136052 {
136053 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0, 0);
136054 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, yymsp[-1].minor.yy243);
136055 exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
136056 yymsp[-4].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
136057 }
136058 break;
@@ -136059,28 +136343,28 @@
136059 case 194: /* expr ::= expr in_op nm dbnm paren_exprlist */
136060 {
136061 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
136062 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
136063 if( yymsp[0].minor.yy148 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy148);
136064 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0, 0);
136065 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, pSelect);
136066 exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
136067 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];
136068 }
136069 break;
136070 case 195: /* expr ::= EXISTS LP select RP */
136071 {
136072 Expr *p;
136073 spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
136074 p = yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
136075 sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy243);
136076 }
136077 break;
136078 case 196: /* expr ::= CASE case_operand case_exprlist case_else END */
136079 {
136080 spanSet(&yymsp[-4].minor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-C*/
136081 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy72, 0, 0);
136082 if( yymsp[-4].minor.yy190.pExpr ){
136083 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;
136084 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy190.pExpr);
136085 }else{
136086 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy148);
@@ -136250,20 +136534,20 @@
136250 {yymsp[0].minor.yy145 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy243); /*A-overwrites-X*/}
136251 break;
136252 case 247: /* expr ::= RAISE LP IGNORE RP */
136253 {
136254 spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
136255 yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0);
136256 if( yymsp[-3].minor.yy190.pExpr ){
136257 yymsp[-3].minor.yy190.pExpr->affinity = OE_Ignore;
136258 }
136259 }
136260 break;
136261 case 248: /* expr ::= RAISE LP raisetype COMMA nm RP */
136262 {
136263 spanSet(&yymsp[-5].minor.yy190,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
136264 yymsp[-5].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0);
136265 if( yymsp[-5].minor.yy190.pExpr ) {
136266 yymsp[-5].minor.yy190.pExpr->affinity = (char)yymsp[-3].minor.yy194;
136267 }
136268 }
136269 break;
@@ -141491,11 +141775,11 @@
141491 /*
141492 ** Interface to the testing logic.
141493 */
141494 SQLITE_API int sqlite3_test_control(int op, ...){
141495 int rc = 0;
141496 #ifdef SQLITE_OMIT_BUILTIN_TEST
141497 UNUSED_PARAMETER(op);
141498 #else
141499 va_list ap;
141500 va_start(ap, op);
141501 switch( op ){
@@ -141828,11 +142112,11 @@
141828 sqlite3_mutex_leave(db->mutex);
141829 break;
141830 }
141831 }
141832 va_end(ap);
141833 #endif /* SQLITE_OMIT_BUILTIN_TEST */
141834 return rc;
141835 }
141836
141837 /*
141838 ** This is a utility routine, useful to VFS implementations, that checks
@@ -141939,26 +142223,27 @@
141939 const char *zDb,
141940 sqlite3_snapshot **ppSnapshot
141941 ){
141942 int rc = SQLITE_ERROR;
141943 #ifndef SQLITE_OMIT_WAL
141944 int iDb;
141945
141946 #ifdef SQLITE_ENABLE_API_ARMOR
141947 if( !sqlite3SafetyCheckOk(db) ){
141948 return SQLITE_MISUSE_BKPT;
141949 }
141950 #endif
141951 sqlite3_mutex_enter(db->mutex);
141952
141953 iDb = sqlite3FindDbName(db, zDb);
141954 if( iDb==0 || iDb>1 ){
141955 Btree *pBt = db->aDb[iDb].pBt;
141956 if( 0==sqlite3BtreeIsInTrans(pBt) ){
141957 rc = sqlite3BtreeBeginTrans(pBt, 0);
141958 if( rc==SQLITE_OK ){
141959 rc = sqlite3PagerSnapshotGet(sqlite3BtreePager(pBt), ppSnapshot);
 
 
141960 }
141961 }
141962 }
141963
141964 sqlite3_mutex_leave(db->mutex);
@@ -141996,10 +142281,42 @@
141996 }
141997 }
141998 }
141999 }
142000
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142001 sqlite3_mutex_leave(db->mutex);
142002 #endif /* SQLITE_OMIT_WAL */
142003 return rc;
142004 }
142005
@@ -180834,11 +181151,10 @@
180834 /*
180835 ** The following routine is called if the stack overflows.
180836 */
180837 static void fts5yyStackOverflow(fts5yyParser *fts5yypParser){
180838 sqlite3Fts5ParserARG_FETCH;
180839 fts5yypParser->fts5yytos--;
180840 #ifndef NDEBUG
180841 if( fts5yyTraceFILE ){
180842 fprintf(fts5yyTraceFILE,"%sStack Overflow!\n",fts5yyTracePrompt);
180843 }
180844 #endif
@@ -180889,16 +181205,18 @@
180889 assert( fts5yypParser->fts5yyhwm == (int)(fts5yypParser->fts5yytos - fts5yypParser->fts5yystack) );
180890 }
180891 #endif
180892 #if fts5YYSTACKDEPTH>0
180893 if( fts5yypParser->fts5yytos>=&fts5yypParser->fts5yystack[fts5YYSTACKDEPTH] ){
 
180894 fts5yyStackOverflow(fts5yypParser);
180895 return;
180896 }
180897 #else
180898 if( fts5yypParser->fts5yytos>=&fts5yypParser->fts5yystack[fts5yypParser->fts5yystksz] ){
180899 if( fts5yyGrowStack(fts5yypParser) ){
 
180900 fts5yyStackOverflow(fts5yypParser);
180901 return;
180902 }
180903 }
180904 #endif
@@ -184206,52 +184524,65 @@
184206
184207 /*
184208 ** Initialize all term iterators in the pNear object. If any term is found
184209 ** to match no documents at all, return immediately without initializing any
184210 ** further iterators.
 
 
 
 
184211 */
184212 static int fts5ExprNearInitAll(
184213 Fts5Expr *pExpr,
184214 Fts5ExprNode *pNode
184215 ){
184216 Fts5ExprNearset *pNear = pNode->pNear;
184217 int i, j;
184218 int rc = SQLITE_OK;
184219 int bEof = 1;
184220
184221 assert( pNode->bNomatch==0 );
184222 for(i=0; rc==SQLITE_OK && i<pNear->nPhrase; i++){
184223 Fts5ExprPhrase *pPhrase = pNear->apPhrase[i];
184224 for(j=0; j<pPhrase->nTerm; j++){
184225 Fts5ExprTerm *pTerm = &pPhrase->aTerm[j];
184226 Fts5ExprTerm *p;
184227
184228 for(p=pTerm; p && rc==SQLITE_OK; p=p->pSynonym){
184229 if( p->pIter ){
184230 sqlite3Fts5IterClose(p->pIter);
184231 p->pIter = 0;
184232 }
184233 rc = sqlite3Fts5IndexQuery(
184234 pExpr->pIndex, p->zTerm, (int)strlen(p->zTerm),
184235 (pTerm->bPrefix ? FTS5INDEX_QUERY_PREFIX : 0) |
184236 (pExpr->bDesc ? FTS5INDEX_QUERY_DESC : 0),
184237 pNear->pColset,
184238 &p->pIter
184239 );
184240 assert( rc==SQLITE_OK || p->pIter==0 );
184241 if( p->pIter && 0==sqlite3Fts5IterEof(p->pIter) ){
184242 bEof = 0;
184243 }
184244 }
184245
184246 if( bEof ) break;
184247 }
184248 if( bEof ) break;
184249 }
184250
184251 pNode->bEof = bEof;
184252 return rc;
 
 
 
 
 
 
 
 
 
 
 
184253 }
184254
184255 /*
184256 ** If pExpr is an ASC iterator, this function returns a value with the
184257 ** same sign as:
@@ -195785,11 +196116,11 @@
195785 int nArg, /* Number of args */
195786 sqlite3_value **apUnused /* Function arguments */
195787 ){
195788 assert( nArg==0 );
195789 UNUSED_PARAM2(nArg, apUnused);
195790 sqlite3_result_text(pCtx, "fts5: 2016-11-19 18:31:37 28393c413cc4505b94411730e728583c5d4baaae", -1, SQLITE_TRANSIENT);
195791 }
195792
195793 static int fts5Init(sqlite3 *db){
195794 static const sqlite3_module fts5Mod = {
195795 /* iVersion */ 2,
195796
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -381,11 +381,11 @@
381 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
382 ** [sqlite_version()] and [sqlite_source_id()].
383 */
384 #define SQLITE_VERSION "3.16.0"
385 #define SQLITE_VERSION_NUMBER 3016000
386 #define SQLITE_SOURCE_ID "2016-12-08 19:04:36 b26df26e184ec6da4b5537526c10f42a293d09b5"
387
388 /*
389 ** CAPI3REF: Run-Time Library Version Numbers
390 ** KEYWORDS: sqlite3_version sqlite3_sourceid
391 **
@@ -3868,10 +3868,14 @@
3868 ** rather they control the timing of when other statements modify the
3869 ** database. ^The [ATTACH] and [DETACH] statements also cause
3870 ** sqlite3_stmt_readonly() to return true since, while those statements
3871 ** change the configuration of a database connection, they do not make
3872 ** changes to the content of the database files on disk.
3873 ** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
3874 ** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
3875 ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
3876 ** sqlite3_stmt_readonly() returns false for those commands.
3877 */
3878 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3879
3880 /*
3881 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
@@ -8517,11 +8521,11 @@
8521 */
8522 SQLITE_API int sqlite3_system_errno(sqlite3*);
8523
8524 /*
8525 ** CAPI3REF: Database Snapshot
8526 ** KEYWORDS: {snapshot} {sqlite3_snapshot}
8527 ** EXPERIMENTAL
8528 **
8529 ** An instance of the snapshot object records the state of a [WAL mode]
8530 ** database for some specific point in history.
8531 **
@@ -8541,11 +8545,13 @@
8545 ** The constructor for this object is [sqlite3_snapshot_get()]. The
8546 ** [sqlite3_snapshot_open()] method causes a fresh read transaction to refer
8547 ** to an historical snapshot (if possible). The destructor for
8548 ** sqlite3_snapshot objects is [sqlite3_snapshot_free()].
8549 */
8550 typedef struct sqlite3_snapshot {
8551 unsigned char hidden[48];
8552 } sqlite3_snapshot;
8553
8554 /*
8555 ** CAPI3REF: Record A Database Snapshot
8556 ** EXPERIMENTAL
8557 **
@@ -8552,13 +8558,36 @@
8558 ** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a
8559 ** new [sqlite3_snapshot] object that records the current state of
8560 ** schema S in database connection D. ^On success, the
8561 ** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly
8562 ** created [sqlite3_snapshot] object into *P and returns SQLITE_OK.
8563 ** If there is not already a read-transaction open on schema S when
8564 ** this function is called, one is opened automatically.
8565 **
8566 ** The following must be true for this function to succeed. If any of
8567 ** the following statements are false when sqlite3_snapshot_get() is
8568 ** called, SQLITE_ERROR is returned. The final value of *P is undefined
8569 ** in this case.
8570 **
8571 ** <ul>
8572 ** <li> The database handle must be in [autocommit mode].
8573 **
8574 ** <li> Schema S of [database connection] D must be a [WAL mode] database.
8575 **
8576 ** <li> There must not be a write transaction open on schema S of database
8577 ** connection D.
8578 **
8579 ** <li> One or more transactions must have been written to the current wal
8580 ** file since it was created on disk (by any connection). This means
8581 ** that a snapshot cannot be taken on a wal mode database with no wal
8582 ** file immediately after it is first opened. At least one transaction
8583 ** must be written to it first.
8584 ** </ul>
8585 **
8586 ** This function may also return SQLITE_NOMEM. If it is called with the
8587 ** database handle in autocommit mode but fails for some other reason,
8588 ** whether or not a read transaction is opened on schema S is undefined.
8589 **
8590 ** The [sqlite3_snapshot] object returned from a successful call to
8591 ** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()]
8592 ** to avoid a memory leak.
8593 **
@@ -8647,10 +8676,32 @@
8676 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(
8677 sqlite3_snapshot *p1,
8678 sqlite3_snapshot *p2
8679 );
8680
8681 /*
8682 ** CAPI3REF: Recover snapshots from a wal file
8683 ** EXPERIMENTAL
8684 **
8685 ** If all connections disconnect from a database file but do not perform
8686 ** a checkpoint, the existing wal file is opened along with the database
8687 ** file the next time the database is opened. At this point it is only
8688 ** possible to successfully call sqlite3_snapshot_open() to open the most
8689 ** recent snapshot of the database (the one at the head of the wal file),
8690 ** even though the wal file may contain other valid snapshots for which
8691 ** clients have sqlite3_snapshot handles.
8692 **
8693 ** This function attempts to scan the wal file associated with database zDb
8694 ** of database handle db and make all valid snapshots available to
8695 ** sqlite3_snapshot_open(). It is an error if there is already a read
8696 ** transaction open on the database, or if the database is not a wal mode
8697 ** database.
8698 **
8699 ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
8700 */
8701 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
8702
8703 /*
8704 ** Undo the hack that converts floating point types to integer for
8705 ** builds on processors without floating point support.
8706 */
8707 #ifdef SQLITE_OMIT_FLOATING_POINT
@@ -12323,19 +12374,19 @@
12374 SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
12375 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
12376 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
12377 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
12378 SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
12379 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
12380 SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
12381 SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
 
12382
12383 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
12384 SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
12385
12386 #ifndef SQLITE_OMIT_INCRBLOB
12387 SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*);
12388 SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
12389 SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *);
12390 #endif
12391 SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *);
12392 SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
@@ -12518,26 +12569,25 @@
12569 ** Allowed values of VdbeOp.p4type
12570 */
12571 #define P4_NOTUSED 0 /* The P4 parameter is not used */
12572 #define P4_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */
12573 #define P4_STATIC (-2) /* Pointer to a static string */
12574 #define P4_COLLSEQ (-3) /* P4 is a pointer to a CollSeq structure */
12575 #define P4_FUNCDEF (-4) /* P4 is a pointer to a FuncDef structure */
12576 #define P4_KEYINFO (-5) /* P4 is a pointer to a KeyInfo structure */
12577 #define P4_EXPR (-6) /* P4 is a pointer to an Expr tree */
12578 #define P4_MEM (-7) /* P4 is a pointer to a Mem* structure */
12579 #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */
12580 #define P4_VTAB (-8) /* P4 is a pointer to an sqlite3_vtab structure */
12581 #define P4_REAL (-9) /* P4 is a 64-bit floating point value */
12582 #define P4_INT64 (-10) /* P4 is a 64-bit signed integer */
12583 #define P4_INT32 (-11) /* P4 is a 32-bit signed integer */
12584 #define P4_INTARRAY (-12) /* P4 is a vector of 32-bit integers */
12585 #define P4_SUBPROGRAM (-13) /* P4 is a pointer to a SubProgram structure */
12586 #define P4_ADVANCE (-14) /* P4 is a pointer to BtreeNext() or BtreePrev() */
12587 #define P4_TABLE (-15) /* P4 is a pointer to a Table structure */
12588 #define P4_FUNCCTX (-16) /* P4 is a pointer to an sqlite3_context object */
 
12589
12590 /* Error message codes for OP_Halt */
12591 #define P5_ConstraintNotNull 1
12592 #define P5_ConstraintUnique 2
12593 #define P5_ConstraintCheck 3
@@ -12697,52 +12747,51 @@
12747 #define OP_InsertInt 116 /* synopsis: intkey=P3 data=r[P2] */
12748 #define OP_Delete 117
12749 #define OP_ResetCount 118
12750 #define OP_SorterCompare 119 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12751 #define OP_SorterData 120 /* synopsis: r[P2]=data */
12752 #define OP_RowData 121 /* synopsis: r[P2]=data */
12753 #define OP_Rowid 122 /* synopsis: r[P2]=rowid */
12754 #define OP_NullRow 123
12755 #define OP_SorterInsert 124 /* synopsis: key=r[P2] */
12756 #define OP_IdxInsert 125 /* synopsis: key=r[P2] */
12757 #define OP_IdxDelete 126 /* synopsis: key=r[P2@P3] */
12758 #define OP_Seek 127 /* synopsis: Move P3 to P1.rowid */
12759 #define OP_IdxRowid 128 /* synopsis: r[P2]=rowid */
12760 #define OP_Destroy 129
12761 #define OP_Clear 130
12762 #define OP_ResetSorter 131
12763 #define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
12764 #define OP_CreateIndex 133 /* synopsis: r[P2]=root iDb=P1 */
12765 #define OP_CreateTable 134 /* synopsis: r[P2]=root iDb=P1 */
12766 #define OP_ParseSchema 135
12767 #define OP_LoadAnalysis 136
12768 #define OP_DropTable 137
12769 #define OP_DropIndex 138
12770 #define OP_DropTrigger 139
12771 #define OP_IntegrityCk 140
12772 #define OP_RowSetAdd 141 /* synopsis: rowset(P1)=r[P2] */
12773 #define OP_Param 142
12774 #define OP_FkCounter 143 /* synopsis: fkctr[P1]+=P2 */
12775 #define OP_MemMax 144 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12776 #define OP_OffsetLimit 145 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12777 #define OP_AggStep0 146 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12778 #define OP_AggStep 147 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12779 #define OP_AggFinal 148 /* synopsis: accum=r[P1] N=P2 */
12780 #define OP_Expire 149
12781 #define OP_TableLock 150 /* synopsis: iDb=P1 root=P2 write=P3 */
12782 #define OP_VBegin 151
12783 #define OP_VCreate 152
12784 #define OP_VDestroy 153
12785 #define OP_VOpen 154
12786 #define OP_VColumn 155 /* synopsis: r[P3]=vcolumn(P2) */
12787 #define OP_VRename 156
12788 #define OP_Pagecount 157
12789 #define OP_MaxPgcnt 158
12790 #define OP_CursorHint 159
12791 #define OP_Noop 160
12792 #define OP_Explain 161
 
12793
12794 /* Properties such as "out2" or "jump" that are specified in
12795 ** comments following the "case" for each opcode in the vdbe.c
12796 ** are encoded into bitvectors as follows:
12797 */
@@ -12766,16 +12815,16 @@
12815 /* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00,\
12816 /* 88 */ 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\
12817 /* 96 */ 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
12818 /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12819 /* 112 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
12820 /* 120 */ 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00, 0x00,\
12821 /* 128 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00,\
12822 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00,\
12823 /* 144 */ 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12824 /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
12825 /* 160 */ 0x00, 0x00,}
12826
12827 /* The sqlite3P2Values() routine is able to run faster if it knows
12828 ** the value of the largest JUMP opcode. The smaller the maximum
12829 ** JUMP opcode the better, so the mkopcodeh.tcl script that
12830 ** generated this include file strives to group all JUMP opcodes
@@ -12816,10 +12865,11 @@
12865 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
12866 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
12867 SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
12868 SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
12869 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
12870 SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
12871 SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
12872 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
12873 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
12874 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
12875 SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*);
@@ -13116,10 +13166,11 @@
13166 SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3*);
13167 SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager);
13168 # ifdef SQLITE_ENABLE_SNAPSHOT
13169 SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot);
13170 SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot);
13171 SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager);
13172 # endif
13173 #else
13174 # define sqlite3PagerUseWal(x) 0
13175 #endif
13176
@@ -14115,17 +14166,12 @@
14166 #define SQLITE_AllOpts 0xffff /* All optimizations */
14167
14168 /*
14169 ** Macros for testing whether or not optimizations are enabled or disabled.
14170 */
 
14171 #define OptimizationDisabled(db, mask) (((db)->dbOptFlags&(mask))!=0)
14172 #define OptimizationEnabled(db, mask) (((db)->dbOptFlags&(mask))==0)
 
 
 
 
14173
14174 /*
14175 ** Return true if it OK to factor constant expressions into the initialization
14176 ** code. The argument is a Parse object for the code generator.
14177 */
@@ -15891,11 +15937,11 @@
15937 ** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE.
15938 */
15939 void (*xVdbeBranch)(void*,int iSrcLine,u8 eThis,u8 eMx); /* Callback */
15940 void *pVdbeBranchArg; /* 1st argument */
15941 #endif
15942 #ifndef SQLITE_UNTESTABLE
15943 int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
15944 #endif
15945 int bLocaltimeFault; /* True to fail localtime() calls */
15946 int iOnceResetThreshold; /* When to reset OP_Once counters */
15947 };
@@ -16095,11 +16141,11 @@
16141 SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
16142 SQLITE_PRIVATE void sqlite3ScratchFree(void*);
16143 SQLITE_PRIVATE void *sqlite3PageMalloc(int);
16144 SQLITE_PRIVATE void sqlite3PageFree(void*);
16145 SQLITE_PRIVATE void sqlite3MemSetDefault(void);
16146 #ifndef SQLITE_UNTESTABLE
16147 SQLITE_PRIVATE void sqlite3BenignMallocHooks(void (*)(void), void (*)(void));
16148 #endif
16149 SQLITE_PRIVATE int sqlite3HeapNearlyFull(void);
16150
16151 /*
@@ -16206,11 +16252,11 @@
16252 SQLITE_PRIVATE int sqlite3NoTempsInRange(Parse*,int,int);
16253 #endif
16254 SQLITE_PRIVATE Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int);
16255 SQLITE_PRIVATE Expr *sqlite3Expr(sqlite3*,int,const char*);
16256 SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
16257 SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*);
16258 SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*);
16259 SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
16260 SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
16261 SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
16262 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
@@ -16250,11 +16296,11 @@
16296 SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);
16297 SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
16298 sqlite3_vfs**,char**,char **);
16299 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*);
16300
16301 #ifdef SQLITE_UNTESTABLE
16302 # define sqlite3FaultSim(X) SQLITE_OK
16303 #else
16304 SQLITE_PRIVATE int sqlite3FaultSim(int);
16305 #endif
16306
@@ -16263,11 +16309,11 @@
16309 SQLITE_PRIVATE int sqlite3BitvecTestNotNull(Bitvec*, u32);
16310 SQLITE_PRIVATE int sqlite3BitvecSet(Bitvec*, u32);
16311 SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec*, u32, void*);
16312 SQLITE_PRIVATE void sqlite3BitvecDestroy(Bitvec*);
16313 SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec*);
16314 #ifndef SQLITE_UNTESTABLE
16315 SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int,int*);
16316 #endif
16317
16318 SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3*, void*, unsigned int);
16319 SQLITE_PRIVATE void sqlite3RowSetClear(RowSet*);
@@ -16383,11 +16429,11 @@
16429 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
16430 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
16431 SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
16432 SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
16433 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
16434 #ifndef SQLITE_UNTESTABLE
16435 SQLITE_PRIVATE void sqlite3PrngSaveState(void);
16436 SQLITE_PRIVATE void sqlite3PrngRestoreState(void);
16437 #endif
16438 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int);
16439 SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int);
@@ -16811,14 +16857,14 @@
16857 #define SQLITE_FAULTINJECTOR_MALLOC 0
16858 #define SQLITE_FAULTINJECTOR_COUNT 1
16859
16860 /*
16861 ** The interface to the code in fault.c used for identifying "benign"
16862 ** malloc failures. This is only present if SQLITE_UNTESTABLE
16863 ** is not defined.
16864 */
16865 #ifndef SQLITE_UNTESTABLE
16866 SQLITE_PRIVATE void sqlite3BeginBenignMalloc(void);
16867 SQLITE_PRIVATE void sqlite3EndBenignMalloc(void);
16868 #else
16869 #define sqlite3BeginBenignMalloc()
16870 #define sqlite3EndBenignMalloc()
@@ -16945,10 +16991,11 @@
16991
16992 SQLITE_PRIVATE int sqlite3ExprVectorSize(Expr *pExpr);
16993 SQLITE_PRIVATE int sqlite3ExprIsVector(Expr *pExpr);
16994 SQLITE_PRIVATE Expr *sqlite3VectorFieldSubexpr(Expr*, int);
16995 SQLITE_PRIVATE Expr *sqlite3ExprForVectorField(Parse*,Expr*,int);
16996 SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse*, Expr*);
16997
16998 #endif /* SQLITEINT_H */
16999
17000 /************** End of sqliteInt.h *******************************************/
17001 /************** Begin file global.c ******************************************/
@@ -17171,11 +17218,11 @@
17218 #endif
17219 #ifdef SQLITE_VDBE_COVERAGE
17220 0, /* xVdbeBranch */
17221 0, /* pVbeBranchArg */
17222 #endif
17223 #ifndef SQLITE_UNTESTABLE
17224 0, /* xTestCallback */
17225 #endif
17226 0, /* bLocaltimeFault */
17227 0x7ffffffe /* iOnceResetThreshold */
17228 };
@@ -17467,13 +17514,10 @@
17514 "OMIT_BLOB_LITERAL",
17515 #endif
17516 #if SQLITE_OMIT_BTREECOUNT
17517 "OMIT_BTREECOUNT",
17518 #endif
 
 
 
17519 #if SQLITE_OMIT_CAST
17520 "OMIT_CAST",
17521 #endif
17522 #if SQLITE_OMIT_CHECK
17523 "OMIT_CHECK",
@@ -17631,10 +17675,13 @@
17675 #if SQLITE_TEST
17676 "TEST",
17677 #endif
17678 #if defined(SQLITE_THREADSAFE)
17679 "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
17680 #endif
17681 #if SQLITE_UNTESTABLE
17682 "UNTESTABLE"
17683 #endif
17684 #if SQLITE_USE_ALLOCA
17685 "USE_ALLOCA",
17686 #endif
17687 #if SQLITE_USER_AUTHENTICATION
@@ -18199,11 +18246,11 @@
18246 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
18247 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
18248 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
18249 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
18250 SQLITE_PRIVATE void sqlite3VdbeMemCast(Mem*,u8,u8);
18251 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);
18252 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
18253 SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
18254 SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
18255 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
18256 SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int n);
@@ -18668,20 +18715,22 @@
18715 /*
18716 ** A structure for holding a single date and time.
18717 */
18718 typedef struct DateTime DateTime;
18719 struct DateTime {
18720 sqlite3_int64 iJD; /* The julian day number times 86400000 */
18721 int Y, M, D; /* Year, month, and day */
18722 int h, m; /* Hour and minutes */
18723 int tz; /* Timezone offset in minutes */
18724 double s; /* Seconds */
18725 char validJD; /* True (1) if iJD is valid */
18726 char rawS; /* Raw numeric value stored in s */
18727 char validYMD; /* True (1) if Y,M,D are valid */
18728 char validHMS; /* True (1) if h,m,s are valid */
18729 char validTZ; /* True (1) if tz is valid */
18730 char tzSet; /* Timezone was set explicitly */
18731 char isError; /* An overflow has occurred */
18732 };
18733
18734
18735 /*
18736 ** Convert zDate into one or more integers according to the conversion
@@ -18825,18 +18874,27 @@
18874 }
18875 }else{
18876 s = 0;
18877 }
18878 p->validJD = 0;
18879 p->rawS = 0;
18880 p->validHMS = 1;
18881 p->h = h;
18882 p->m = m;
18883 p->s = s + ms;
18884 if( parseTimezone(zDate, p) ) return 1;
18885 p->validTZ = (p->tz!=0)?1:0;
18886 return 0;
18887 }
18888
18889 /*
18890 ** Put the DateTime object into its error state.
18891 */
18892 static void datetimeError(DateTime *p){
18893 memset(p, 0, sizeof(*p));
18894 p->isError = 1;
18895 }
18896
18897 /*
18898 ** Convert from YYYY-MM-DD HH:MM:SS to julian day. We always assume
18899 ** that the YYYY-MM-DD is according to the Gregorian calendar.
18900 **
@@ -18852,10 +18910,14 @@
18910 D = p->D;
18911 }else{
18912 Y = 2000; /* If no YMD specified, assume 2000-Jan-01 */
18913 M = 1;
18914 D = 1;
18915 }
18916 if( Y<-4713 || Y>9999 || p->rawS ){
18917 datetimeError(p);
18918 return;
18919 }
18920 if( M<=2 ){
18921 Y--;
18922 M += 12;
18923 }
@@ -18932,10 +18994,25 @@
18994 return 0;
18995 }else{
18996 return 1;
18997 }
18998 }
18999
19000 /*
19001 ** Input "r" is a numeric quantity which might be a julian day number,
19002 ** or the number of seconds since 1970. If the value if r is within
19003 ** range of a julian day number, install it as such and set validJD.
19004 ** If the value is a valid unix timestamp, put it in p->s and set p->rawS.
19005 */
19006 static void setRawDateNumber(DateTime *p, double r){
19007 p->s = r;
19008 p->rawS = 1;
19009 if( r>=0.0 && r<5373484.5 ){
19010 p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
19011 p->validJD = 1;
19012 }
19013 }
19014
19015 /*
19016 ** Attempt to parse the given string into a julian day number. Return
19017 ** the number of errors.
19018 **
@@ -18962,16 +19039,24 @@
19039 }else if( parseHhMmSs(zDate, p)==0 ){
19040 return 0;
19041 }else if( sqlite3StrICmp(zDate,"now")==0){
19042 return setDateTimeToCurrent(context, p);
19043 }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){
19044 setRawDateNumber(p, r);
 
19045 return 0;
19046 }
19047 return 1;
19048 }
19049
19050 /*
19051 ** Return TRUE if the given julian day number is within range.
19052 **
19053 ** The input is the JulianDay times 86400000.
19054 */
19055 static int validJulianDay(sqlite3_int64 iJD){
19056 return iJD>=0 && iJD<=464269060799999;
19057 }
19058
19059 /*
19060 ** Compute the Year, Month, and Day from the julian day number.
19061 */
19062 static void computeYMD(DateTime *p){
@@ -18980,10 +19065,11 @@
19065 if( !p->validJD ){
19066 p->Y = 2000;
19067 p->M = 1;
19068 p->D = 1;
19069 }else{
19070 assert( validJulianDay(p->iJD) );
19071 Z = (int)((p->iJD + 43200000)/86400000);
19072 A = (int)((Z - 1867216.25)/36524.25);
19073 A = Z + 1 + A - (A/4);
19074 B = A + 1524;
19075 C = (int)((B - 122.1)/365.25);
@@ -19010,10 +19096,11 @@
19096 p->s -= s;
19097 p->h = s/3600;
19098 s -= p->h*3600;
19099 p->m = s/60;
19100 p->s += s - p->m*60;
19101 p->rawS = 0;
19102 p->validHMS = 1;
19103 }
19104
19105 /*
19106 ** Compute both YMD and HMS
@@ -19071,18 +19158,18 @@
19158 #if SQLITE_THREADSAFE>0
19159 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
19160 #endif
19161 sqlite3_mutex_enter(mutex);
19162 pX = localtime(t);
19163 #ifndef SQLITE_UNTESTABLE
19164 if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0;
19165 #endif
19166 if( pX ) *pTm = *pX;
19167 sqlite3_mutex_leave(mutex);
19168 rc = pX==0;
19169 #else
19170 #ifndef SQLITE_UNTESTABLE
19171 if( sqlite3GlobalConfig.bLocaltimeFault ) return 1;
19172 #endif
19173 #if HAVE_LOCALTIME_R
19174 rc = localtime_r(t, pTm)==0;
19175 #else
@@ -19149,16 +19236,41 @@
19236 y.m = sLocal.tm_min;
19237 y.s = sLocal.tm_sec;
19238 y.validYMD = 1;
19239 y.validHMS = 1;
19240 y.validJD = 0;
19241 y.rawS = 0;
19242 y.validTZ = 0;
19243 y.isError = 0;
19244 computeJD(&y);
19245 *pRc = SQLITE_OK;
19246 return y.iJD - x.iJD;
19247 }
19248 #endif /* SQLITE_OMIT_LOCALTIME */
19249
19250 /*
19251 ** The following table defines various date transformations of the form
19252 **
19253 ** 'NNN days'
19254 **
19255 ** Where NNN is an arbitrary floating-point number and "days" can be one
19256 ** of several units of time.
19257 */
19258 static const struct {
19259 u8 eType; /* Transformation type code */
19260 u8 nName; /* Length of th name */
19261 char *zName; /* Name of the transformation */
19262 double rLimit; /* Maximum NNN value for this transform */
19263 double rXform; /* Constant used for this transform */
19264 } aXformType[] = {
19265 { 0, 6, "second", 464269060800.0, 86400000.0/(24.0*60.0*60.0) },
19266 { 0, 6, "minute", 7737817680.0, 86400000.0/(24.0*60.0) },
19267 { 0, 4, "hour", 128963628.0, 86400000.0/24.0 },
19268 { 0, 3, "day", 5373485.0, 86400000.0 },
19269 { 1, 5, "month", 176546.0, 30.0*86400000.0 },
19270 { 2, 4, "year", 14713.0, 365.0*86400000.0 },
19271 };
19272
19273 /*
19274 ** Process a modifier to a date-time stamp. The modifiers are
19275 ** as follows:
19276 **
@@ -19180,29 +19292,27 @@
19292 ** Return 0 on success and 1 if there is any kind of error. If the error
19293 ** is in a system call (i.e. localtime()), then an error message is written
19294 ** to context pCtx. If the error is an unrecognized modifier, no error is
19295 ** written to pCtx.
19296 */
19297 static int parseModifier(
19298 sqlite3_context *pCtx, /* Function context */
19299 const char *z, /* The text of the modifier */
19300 int n, /* Length of zMod in bytes */
19301 DateTime *p /* The date/time value to be modified */
19302 ){
19303 int rc = 1;
 
19304 double r;
19305 switch(sqlite3UpperToLower[(u8)z[0]] ){
 
 
 
 
 
 
19306 #ifndef SQLITE_OMIT_LOCALTIME
19307 case 'l': {
19308 /* localtime
19309 **
19310 ** Assuming the current time value is UTC (a.k.a. GMT), shift it to
19311 ** show local time.
19312 */
19313 if( sqlite3_stricmp(z, "localtime")==0 ){
19314 computeJD(p);
19315 p->iJD += localtimeOffset(p, pCtx, &rc);
19316 clearYMD_HMS_TZ(p);
19317 }
19318 break;
@@ -19210,20 +19320,25 @@
19320 #endif
19321 case 'u': {
19322 /*
19323 ** unixepoch
19324 **
19325 ** Treat the current value of p->s as the number of
19326 ** seconds since 1970. Convert to a real julian day number.
19327 */
19328 if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){
19329 r = p->s*1000.0 + 210866760000000.0;
19330 if( r>=0.0 && r<464269060800000.0 ){
19331 clearYMD_HMS_TZ(p);
19332 p->iJD = (sqlite3_int64)r;
19333 p->validJD = 1;
19334 p->rawS = 0;
19335 rc = 0;
19336 }
19337 }
19338 #ifndef SQLITE_OMIT_LOCALTIME
19339 else if( sqlite3_stricmp(z, "utc")==0 ){
19340 if( p->tzSet==0 ){
19341 sqlite3_int64 c1;
19342 computeJD(p);
19343 c1 = localtimeOffset(p, pCtx, &rc);
19344 if( rc==SQLITE_OK ){
@@ -19245,11 +19360,11 @@
19360 **
19361 ** Move the date to the same time on the next occurrence of
19362 ** weekday N where 0==Sunday, 1==Monday, and so forth. If the
19363 ** date is already on the appropriate weekday, this is a no-op.
19364 */
19365 if( sqlite3_strnicmp(z, "weekday ", 8)==0
19366 && sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8)
19367 && (n=(int)r)==r && n>=0 && r<7 ){
19368 sqlite3_int64 Z;
19369 computeYMD_HMS(p);
19370 p->validTZ = 0;
@@ -19268,27 +19383,27 @@
19383 ** start of TTTTT
19384 **
19385 ** Move the date backwards to the beginning of the current day,
19386 ** or month or year.
19387 */
19388 if( sqlite3_strnicmp(z, "start of ", 9)!=0 ) break;
19389 z += 9;
19390 computeYMD(p);
19391 p->validHMS = 1;
19392 p->h = p->m = 0;
19393 p->s = 0.0;
19394 p->validTZ = 0;
19395 p->validJD = 0;
19396 if( sqlite3_stricmp(z,"month")==0 ){
19397 p->D = 1;
19398 rc = 0;
19399 }else if( sqlite3_stricmp(z,"year")==0 ){
19400 computeYMD(p);
19401 p->M = 1;
19402 p->D = 1;
19403 rc = 0;
19404 }else if( sqlite3_stricmp(z,"day")==0 ){
19405 rc = 0;
19406 }
19407 break;
19408 }
19409 case '+':
@@ -19302,10 +19417,11 @@
19417 case '6':
19418 case '7':
19419 case '8':
19420 case '9': {
19421 double rRounder;
19422 int i;
19423 for(n=1; z[n] && z[n]!=':' && !sqlite3Isspace(z[n]); n++){}
19424 if( !sqlite3AtoF(z, &r, n, SQLITE_UTF8) ){
19425 rc = 1;
19426 break;
19427 }
@@ -19330,50 +19446,52 @@
19446 clearYMD_HMS_TZ(p);
19447 p->iJD += tx.iJD;
19448 rc = 0;
19449 break;
19450 }
19451
19452 /* If control reaches this point, it means the transformation is
19453 ** one of the forms like "+NNN days". */
19454 z += n;
19455 while( sqlite3Isspace(*z) ) z++;
19456 n = sqlite3Strlen30(z);
19457 if( n>10 || n<3 ) break;
19458 if( sqlite3UpperToLower[(u8)z[n-1]]=='s' ) n--;
19459 computeJD(p);
19460 rc = 1;
19461 rRounder = r<0 ? -0.5 : +0.5;
19462 for(i=0; i<ArraySize(aXformType); i++){
19463 if( aXformType[i].nName==n
19464 && sqlite3_strnicmp(aXformType[i].zName, z, n)==0
19465 && r>-aXformType[i].rLimit && r<aXformType[i].rLimit
19466 ){
19467 switch( aXformType[i].eType ){
19468 case 1: { /* Special processing to add months */
19469 int x;
19470 computeYMD_HMS(p);
19471 p->M += (int)r;
19472 x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
19473 p->Y += x;
19474 p->M -= x*12;
19475 p->validJD = 0;
19476 r -= (int)r;
19477 break;
19478 }
19479 case 2: { /* Special processing to add years */
19480 int y = (int)r;
19481 computeYMD_HMS(p);
19482 p->Y += y;
19483 p->validJD = 0;
19484 r -= (int)r;
19485 break;
19486 }
19487 }
19488 computeJD(p);
19489 p->iJD += (sqlite3_int64)(r*aXformType[i].rXform + rRounder);
19490 rc = 0;
19491 break;
19492 }
 
19493 }
19494 clearYMD_HMS_TZ(p);
19495 break;
19496 }
19497 default: {
@@ -19396,31 +19514,33 @@
19514 sqlite3_context *context,
19515 int argc,
19516 sqlite3_value **argv,
19517 DateTime *p
19518 ){
19519 int i, n;
19520 const unsigned char *z;
19521 int eType;
19522 memset(p, 0, sizeof(*p));
19523 if( argc==0 ){
19524 return setDateTimeToCurrent(context, p);
19525 }
19526 if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
19527 || eType==SQLITE_INTEGER ){
19528 setRawDateNumber(p, sqlite3_value_double(argv[0]));
 
19529 }else{
19530 z = sqlite3_value_text(argv[0]);
19531 if( !z || parseDateOrTime(context, (char*)z, p) ){
19532 return 1;
19533 }
19534 }
19535 for(i=1; i<argc; i++){
19536 z = sqlite3_value_text(argv[i]);
19537 n = sqlite3_value_bytes(argv[i]);
19538 if( z==0 || parseModifier(context, (char*)z, n, p) ) return 1;
19539 }
19540 computeJD(p);
19541 if( p->isError || !validJulianDay(p->iJD) ) return 1;
19542 return 0;
19543 }
19544
19545
19546 /*
@@ -20214,11 +20334,11 @@
20334 ** during a hash table resize is a benign fault.
20335 */
20336
20337 /* #include "sqliteInt.h" */
20338
20339 #ifndef SQLITE_UNTESTABLE
20340
20341 /*
20342 ** Global variables.
20343 */
20344 typedef struct BenignMallocHooks BenignMallocHooks;
@@ -20272,11 +20392,11 @@
20392 if( wsdHooks.xBenignEnd ){
20393 wsdHooks.xBenignEnd();
20394 }
20395 }
20396
20397 #endif /* #ifndef SQLITE_UNTESTABLE */
20398
20399 /************** End of fault.c ***********************************************/
20400 /************** Begin file mem0.c ********************************************/
20401 /*
20402 ** 2008 October 28
@@ -25599,22 +25719,27 @@
25719 /*
25720 ** Finish off a string by making sure it is zero-terminated.
25721 ** Return a pointer to the resulting string. Return a NULL
25722 ** pointer if any kind of error was encountered.
25723 */
25724 static SQLITE_NOINLINE char *strAccumFinishRealloc(StrAccum *p){
25725 assert( p->mxAlloc>0 && !isMalloced(p) );
25726 p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
25727 if( p->zText ){
25728 memcpy(p->zText, p->zBase, p->nChar+1);
25729 p->printfFlags |= SQLITE_PRINTF_MALLOCED;
25730 }else{
25731 setStrAccumError(p, STRACCUM_NOMEM);
25732 }
25733 return p->zText;
25734 }
25735 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
25736 if( p->zText ){
25737 assert( (p->zText==p->zBase)==!isMalloced(p) );
25738 p->zText[p->nChar] = 0;
25739 if( p->mxAlloc>0 && !isMalloced(p) ){
25740 return strAccumFinishRealloc(p);
 
 
 
 
 
 
25741 }
25742 }
25743 return p->zText;
25744 }
25745
@@ -25750,11 +25875,12 @@
25875 return zBuf;
25876 }
25877 #endif
25878 sqlite3StrAccumInit(&acc, 0, zBuf, n, 0);
25879 sqlite3VXPrintf(&acc, zFormat, ap);
25880 zBuf[acc.nChar] = 0;
25881 return zBuf;
25882 }
25883 SQLITE_API char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
25884 char *z;
25885 va_list ap;
25886 va_start(ap,zFormat);
@@ -26459,11 +26585,11 @@
26585 *(zBuf++) = wsdPrng.s[t];
26586 }while( --N );
26587 sqlite3_mutex_leave(mutex);
26588 }
26589
26590 #ifndef SQLITE_UNTESTABLE
26591 /*
26592 ** For testing purposes, we sometimes want to preserve the state of
26593 ** PRNG and restore the PRNG to its saved state at a later time, or
26594 ** to reset the PRNG to its initial state. These routines accomplish
26595 ** those tasks.
@@ -26484,11 +26610,11 @@
26610 &GLOBAL(struct sqlite3PrngType, sqlite3Prng),
26611 &GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng),
26612 sizeof(sqlite3Prng)
26613 );
26614 }
26615 #endif /* SQLITE_UNTESTABLE */
26616
26617 /************** End of random.c **********************************************/
26618 /************** Begin file threads.c *****************************************/
26619 /*
26620 ** 2012 July 21
@@ -27342,11 +27468,11 @@
27468 ** which of multiple sqlite3FaultSim() calls has been hit.
27469 **
27470 ** Return whatever integer value the test callback returns, or return
27471 ** SQLITE_OK if no test callback is installed.
27472 */
27473 #ifndef SQLITE_UNTESTABLE
27474 SQLITE_PRIVATE int sqlite3FaultSim(int iTest){
27475 int (*xCallback)(int) = sqlite3GlobalConfig.xTestCallback;
27476 return xCallback ? xCallback(iTest) : SQLITE_OK;
27477 }
27478 #endif
@@ -29163,52 +29289,51 @@
29289 /* 116 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
29290 /* 117 */ "Delete" OpHelp(""),
29291 /* 118 */ "ResetCount" OpHelp(""),
29292 /* 119 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
29293 /* 120 */ "SorterData" OpHelp("r[P2]=data"),
29294 /* 121 */ "RowData" OpHelp("r[P2]=data"),
29295 /* 122 */ "Rowid" OpHelp("r[P2]=rowid"),
29296 /* 123 */ "NullRow" OpHelp(""),
29297 /* 124 */ "SorterInsert" OpHelp("key=r[P2]"),
29298 /* 125 */ "IdxInsert" OpHelp("key=r[P2]"),
29299 /* 126 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
29300 /* 127 */ "Seek" OpHelp("Move P3 to P1.rowid"),
29301 /* 128 */ "IdxRowid" OpHelp("r[P2]=rowid"),
29302 /* 129 */ "Destroy" OpHelp(""),
29303 /* 130 */ "Clear" OpHelp(""),
29304 /* 131 */ "ResetSorter" OpHelp(""),
29305 /* 132 */ "Real" OpHelp("r[P2]=P4"),
29306 /* 133 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
29307 /* 134 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
29308 /* 135 */ "ParseSchema" OpHelp(""),
29309 /* 136 */ "LoadAnalysis" OpHelp(""),
29310 /* 137 */ "DropTable" OpHelp(""),
29311 /* 138 */ "DropIndex" OpHelp(""),
29312 /* 139 */ "DropTrigger" OpHelp(""),
29313 /* 140 */ "IntegrityCk" OpHelp(""),
29314 /* 141 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
29315 /* 142 */ "Param" OpHelp(""),
29316 /* 143 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
29317 /* 144 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
29318 /* 145 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
29319 /* 146 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
29320 /* 147 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
29321 /* 148 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
29322 /* 149 */ "Expire" OpHelp(""),
29323 /* 150 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
29324 /* 151 */ "VBegin" OpHelp(""),
29325 /* 152 */ "VCreate" OpHelp(""),
29326 /* 153 */ "VDestroy" OpHelp(""),
29327 /* 154 */ "VOpen" OpHelp(""),
29328 /* 155 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
29329 /* 156 */ "VRename" OpHelp(""),
29330 /* 157 */ "Pagecount" OpHelp(""),
29331 /* 158 */ "MaxPgcnt" OpHelp(""),
29332 /* 159 */ "CursorHint" OpHelp(""),
29333 /* 160 */ "Noop" OpHelp(""),
29334 /* 161 */ "Explain" OpHelp(""),
 
29335 };
29336 return azName[i];
29337 }
29338 #endif
29339
@@ -30473,11 +30598,18 @@
30598 struct unixFileId {
30599 dev_t dev; /* Device number */
30600 #if OS_VXWORKS
30601 struct vxworksFileId *pId; /* Unique file ID for vxworks. */
30602 #else
30603 /* We are told that some versions of Android contain a bug that
30604 ** sizes ino_t at only 32-bits instead of 64-bits. (See
30605 ** https://android-review.googlesource.com/#/c/115351/3/dist/sqlite3.c)
30606 ** To work around this, always allocate 64-bits for the inode number.
30607 ** On small machines that only have 32-bit inodes, this wastes 4 bytes,
30608 ** but that should not be a big deal. */
30609 /* WAS: ino_t ino; */
30610 u64 ino; /* Inode number */
30611 #endif
30612 };
30613
30614 /*
30615 ** An instance of the following structure is allocated for each open
@@ -30718,11 +30850,11 @@
30850 memset(&fileId, 0, sizeof(fileId));
30851 fileId.dev = statbuf.st_dev;
30852 #if OS_VXWORKS
30853 fileId.pId = pFile->pId;
30854 #else
30855 fileId.ino = (u64)statbuf.st_ino;
30856 #endif
30857 pInode = inodeList;
30858 while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
30859 pInode = pInode->pNext;
30860 }
@@ -30752,11 +30884,12 @@
30884 #if OS_VXWORKS
30885 return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId;
30886 #else
30887 struct stat buf;
30888 return pFile->pInode!=0 &&
30889 (osStat(pFile->zPath, &buf)!=0
30890 || (u64)buf.st_ino!=pFile->pInode->fileId.ino);
30891 #endif
30892 }
30893
30894
30895 /*
@@ -34924,11 +35057,11 @@
35057 unixInodeInfo *pInode;
35058
35059 unixEnterMutex();
35060 pInode = inodeList;
35061 while( pInode && (pInode->fileId.dev!=sStat.st_dev
35062 || pInode->fileId.ino!=(u64)sStat.st_ino) ){
35063 pInode = pInode->pNext;
35064 }
35065 if( pInode ){
35066 UnixUnusedFd **pp;
35067 for(pp=&pInode->pUnused; *pp && (*pp)->flags!=flags; pp=&((*pp)->pNext));
@@ -43485,11 +43618,11 @@
43618 */
43619 SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec *p){
43620 return p->iSize;
43621 }
43622
43623 #ifndef SQLITE_UNTESTABLE
43624 /*
43625 ** Let V[] be an array of unsigned characters sufficient to hold
43626 ** up to N bits. Let I be an integer between 0 and N. 0<=I<N.
43627 ** Then the following macros can be used to set, clear, or test
43628 ** individual bits within V.
@@ -43600,11 +43733,11 @@
43733 sqlite3_free(pTmpSpace);
43734 sqlite3_free(pV);
43735 sqlite3BitvecDestroy(pBitvec);
43736 return rc;
43737 }
43738 #endif /* SQLITE_UNTESTABLE */
43739
43740 /************** End of bitvec.c **********************************************/
43741 /************** Begin file pcache.c ******************************************/
43742 /*
43743 ** 2008 August 05
@@ -46398,10 +46531,11 @@
46531 SQLITE_PRIVATE int sqlite3WalHeapMemory(Wal *pWal);
46532
46533 #ifdef SQLITE_ENABLE_SNAPSHOT
46534 SQLITE_PRIVATE int sqlite3WalSnapshotGet(Wal *pWal, sqlite3_snapshot **ppSnapshot);
46535 SQLITE_PRIVATE void sqlite3WalSnapshotOpen(Wal *pWal, sqlite3_snapshot *pSnapshot);
46536 SQLITE_PRIVATE int sqlite3WalSnapshotRecover(Wal *pWal);
46537 #endif
46538
46539 #ifdef SQLITE_ENABLE_ZIPVFS
46540 /* If the WAL file is not empty, return the number of bytes of content
46541 ** stored in each frame (i.e. the db page-size when the WAL was created).
@@ -53799,10 +53933,24 @@
53933 }else{
53934 rc = SQLITE_ERROR;
53935 }
53936 return rc;
53937 }
53938
53939 /*
53940 ** If this is a WAL database, call sqlite3WalSnapshotRecover(). If this
53941 ** is not a WAL database, return an error.
53942 */
53943 SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager){
53944 int rc;
53945 if( pPager->pWal ){
53946 rc = sqlite3WalSnapshotRecover(pPager->pWal);
53947 }else{
53948 rc = SQLITE_ERROR;
53949 }
53950 return rc;
53951 }
53952 #endif /* SQLITE_ENABLE_SNAPSHOT */
53953 #endif /* !SQLITE_OMIT_WAL */
53954
53955 #ifdef SQLITE_ENABLE_ZIPVFS
53956 /*
@@ -56201,10 +56349,88 @@
56349 pWal->readLock = (i16)mxI;
56350 }
56351 return rc;
56352 }
56353
56354 #ifdef SQLITE_ENABLE_SNAPSHOT
56355 /*
56356 ** Attempt to reduce the value of the WalCkptInfo.nBackfillAttempted
56357 ** variable so that older snapshots can be accessed. To do this, loop
56358 ** through all wal frames from nBackfillAttempted to (nBackfill+1),
56359 ** comparing their content to the corresponding page with the database
56360 ** file, if any. Set nBackfillAttempted to the frame number of the
56361 ** first frame for which the wal file content matches the db file.
56362 **
56363 ** This is only really safe if the file-system is such that any page
56364 ** writes made by earlier checkpointers were atomic operations, which
56365 ** is not always true. It is also possible that nBackfillAttempted
56366 ** may be left set to a value larger than expected, if a wal frame
56367 ** contains content that duplicate of an earlier version of the same
56368 ** page.
56369 **
56370 ** SQLITE_OK is returned if successful, or an SQLite error code if an
56371 ** error occurs. It is not an error if nBackfillAttempted cannot be
56372 ** decreased at all.
56373 */
56374 SQLITE_PRIVATE int sqlite3WalSnapshotRecover(Wal *pWal){
56375 int rc;
56376
56377 assert( pWal->readLock>=0 );
56378 rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1);
56379 if( rc==SQLITE_OK ){
56380 volatile WalCkptInfo *pInfo = walCkptInfo(pWal);
56381 int szPage = (int)pWal->szPage;
56382 i64 szDb; /* Size of db file in bytes */
56383
56384 rc = sqlite3OsFileSize(pWal->pDbFd, &szDb);
56385 if( rc==SQLITE_OK ){
56386 void *pBuf1 = sqlite3_malloc(szPage);
56387 void *pBuf2 = sqlite3_malloc(szPage);
56388 if( pBuf1==0 || pBuf2==0 ){
56389 rc = SQLITE_NOMEM;
56390 }else{
56391 u32 i = pInfo->nBackfillAttempted;
56392 for(i=pInfo->nBackfillAttempted; i>pInfo->nBackfill; i--){
56393 volatile ht_slot *dummy;
56394 volatile u32 *aPgno; /* Array of page numbers */
56395 u32 iZero; /* Frame corresponding to aPgno[0] */
56396 u32 pgno; /* Page number in db file */
56397 i64 iDbOff; /* Offset of db file entry */
56398 i64 iWalOff; /* Offset of wal file entry */
56399
56400 rc = walHashGet(pWal, walFramePage(i), &dummy, &aPgno, &iZero);
56401 if( rc!=SQLITE_OK ) break;
56402 pgno = aPgno[i-iZero];
56403 iDbOff = (i64)(pgno-1) * szPage;
56404
56405 if( iDbOff+szPage<=szDb ){
56406 iWalOff = walFrameOffset(i, szPage) + WAL_FRAME_HDRSIZE;
56407 rc = sqlite3OsRead(pWal->pWalFd, pBuf1, szPage, iWalOff);
56408
56409 if( rc==SQLITE_OK ){
56410 rc = sqlite3OsRead(pWal->pDbFd, pBuf2, szPage, iDbOff);
56411 }
56412
56413 if( rc!=SQLITE_OK || 0==memcmp(pBuf1, pBuf2, szPage) ){
56414 break;
56415 }
56416 }
56417
56418 pInfo->nBackfillAttempted = i-1;
56419 }
56420 }
56421
56422 sqlite3_free(pBuf1);
56423 sqlite3_free(pBuf2);
56424 }
56425 walUnlockExclusive(pWal, WAL_CKPT_LOCK, 1);
56426 }
56427
56428 return rc;
56429 }
56430 #endif /* SQLITE_ENABLE_SNAPSHOT */
56431
56432 /*
56433 ** Begin a read transaction on the database.
56434 **
56435 ** This routine used to be called sqlite3OpenSnapshot() and with good reason:
56436 ** it takes a snapshot of the state of the WAL and wal-index for the current
@@ -56263,11 +56489,15 @@
56489 ** checkpointer has already determined that it will checkpoint
56490 ** snapshot X, where X is later in the wal file than pSnapshot, but
56491 ** has not yet set the pInfo->nBackfillAttempted variable to indicate
56492 ** its intent. To avoid the race condition this leads to, ensure that
56493 ** there is no checkpointer process by taking a shared CKPT lock
56494 ** before checking pInfo->nBackfillAttempted.
56495 **
56496 ** TODO: Does the aReadMark[] lock prevent a checkpointer from doing
56497 ** this already?
56498 */
56499 rc = walLockShared(pWal, WAL_CKPT_LOCK);
56500
56501 if( rc==SQLITE_OK ){
56502 /* Check that the wal file has not been wrapped. Assuming that it has
56503 ** not, also check that no checkpointer has attempted to checkpoint any
@@ -57215,13 +57445,18 @@
57445 ** in the object.
57446 */
57447 SQLITE_PRIVATE int sqlite3WalSnapshotGet(Wal *pWal, sqlite3_snapshot **ppSnapshot){
57448 int rc = SQLITE_OK;
57449 WalIndexHdr *pRet;
57450 static const u32 aZero[4] = { 0, 0, 0, 0 };
57451
57452 assert( pWal->readLock>=0 && pWal->writeLock==0 );
57453
57454 if( memcmp(&pWal->hdr.aFrameCksum[0],aZero,16)==0 ){
57455 *ppSnapshot = 0;
57456 return SQLITE_ERROR;
57457 }
57458 pRet = (WalIndexHdr*)sqlite3_malloc(sizeof(WalIndexHdr));
57459 if( pRet==0 ){
57460 rc = SQLITE_NOMEM_BKPT;
57461 }else{
57462 memcpy(pRet, &pWal->hdr, sizeof(WalIndexHdr));
@@ -58922,11 +59157,11 @@
59157 /* For an index btree, save the complete key content */
59158 void *pKey;
59159 pCur->nKey = sqlite3BtreePayloadSize(pCur);
59160 pKey = sqlite3Malloc( pCur->nKey );
59161 if( pKey ){
59162 rc = sqlite3BtreePayload(pCur, 0, (int)pCur->nKey, pKey);
59163 if( rc==SQLITE_OK ){
59164 pCur->pKey = pKey;
59165 }else{
59166 sqlite3_free(pKey);
59167 }
@@ -62941,47 +63176,39 @@
63176 }
63177 return rc;
63178 }
63179
63180 /*
63181 ** Read part of the payload for the row at which that cursor pCur is currently
63182 ** pointing. "amt" bytes will be transferred into pBuf[]. The transfer
63183 ** begins at "offset".
63184 **
63185 ** pCur can be pointing to either a table or an index b-tree.
63186 ** If pointing to a table btree, then the content section is read. If
63187 ** pCur is pointing to an index b-tree then the key section is read.
63188 **
63189 ** For sqlite3BtreePayload(), the caller must ensure that pCur is pointing
63190 ** to a valid row in the table. For sqlite3BtreePayloadChecked(), the
63191 ** cursor might be invalid or might need to be restored before being read.
63192 **
63193 ** Return SQLITE_OK on success or an error code if anything goes
63194 ** wrong. An error is returned if "offset+amt" is larger than
63195 ** the available payload.
63196 */
63197 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
63198 assert( cursorHoldsMutex(pCur) );
63199 assert( pCur->eState==CURSOR_VALID );
63200 assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
63201 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
63202 return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
63203 }
 
 
 
 
 
 
 
 
 
 
 
 
 
63204 #ifndef SQLITE_OMIT_INCRBLOB
63205 SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
63206 int rc;
63207 if ( pCur->eState==CURSOR_INVALID ){
63208 return SQLITE_ABORT;
63209 }
 
 
63210 assert( cursorOwnsBtShared(pCur) );
63211 rc = restoreCursorPosition(pCur);
63212 if( rc==SQLITE_OK ){
63213 assert( pCur->eState==CURSOR_VALID );
63214 assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
@@ -62988,10 +63215,11 @@
63215 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
63216 rc = accessPayload(pCur, offset, amt, pBuf, 0);
63217 }
63218 return rc;
63219 }
63220 #endif /* SQLITE_OMIT_INCRBLOB */
63221
63222 /*
63223 ** Return a pointer to payload information from the entry that the
63224 ** pCur cursor is pointing to. The pointer is to the beginning of
63225 ** the key if index btrees (pPage->intKey==0) and is the data for
@@ -69752,14 +69980,13 @@
69980 return SQLITE_OK;
69981 }
69982
69983 /*
69984 ** Move data out of a btree key or data field and into a Mem structure.
69985 ** The data is payload from the entry that pCur is currently pointing
69986 ** to. offset and amt determine what portion of the data or key to retrieve.
69987 ** The result is written into the pMem element.
 
69988 **
69989 ** The pMem object must have been initialized. This routine will use
69990 ** pMem->zMalloc to hold the content from the btree, if possible. New
69991 ** pMem->zMalloc space will be allocated if necessary. The calling routine
69992 ** is responsible for making sure that the pMem object is eventually
@@ -69770,21 +69997,16 @@
69997 */
69998 static SQLITE_NOINLINE int vdbeMemFromBtreeResize(
69999 BtCursor *pCur, /* Cursor pointing at record to retrieve. */
70000 u32 offset, /* Offset from the start of data to return bytes from. */
70001 u32 amt, /* Number of bytes to return. */
 
70002 Mem *pMem /* OUT: Return data in this Mem structure. */
70003 ){
70004 int rc;
70005 pMem->flags = MEM_Null;
70006 if( SQLITE_OK==(rc = sqlite3VdbeMemClearAndResize(pMem, amt+2)) ){
70007 rc = sqlite3BtreePayload(pCur, offset, amt, pMem->z);
 
 
 
 
70008 if( rc==SQLITE_OK ){
70009 pMem->z[amt] = 0;
70010 pMem->z[amt+1] = 0;
70011 pMem->flags = MEM_Blob|MEM_Term;
70012 pMem->n = (int)amt;
@@ -69796,11 +70018,10 @@
70018 }
70019 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(
70020 BtCursor *pCur, /* Cursor pointing at record to retrieve. */
70021 u32 offset, /* Offset from the start of data to return bytes from. */
70022 u32 amt, /* Number of bytes to return. */
 
70023 Mem *pMem /* OUT: Return data in this Mem structure. */
70024 ){
70025 char *zData; /* Data from the btree layer */
70026 u32 available = 0; /* Number of bytes available on the local btree page */
70027 int rc = SQLITE_OK; /* Return code */
@@ -69817,11 +70038,11 @@
70038 if( offset+amt<=available ){
70039 pMem->z = &zData[offset];
70040 pMem->flags = MEM_Blob|MEM_Ephem;
70041 pMem->n = (int)amt;
70042 }else{
70043 rc = vdbeMemFromBtreeResize(pCur, offset, amt, pMem);
70044 }
70045
70046 return rc;
70047 }
70048
@@ -70847,11 +71068,15 @@
71068 int p2, /* The P2 operand */
71069 int p3, /* The P3 operand */
71070 int p4 /* The P4 operand as an integer */
71071 ){
71072 int addr = sqlite3VdbeAddOp3(p, op, p1, p2, p3);
71073 if( p->db->mallocFailed==0 ){
71074 VdbeOp *pOp = &p->aOp[addr];
71075 pOp->p4type = P4_INT32;
71076 pOp->p4.i = p4;
71077 }
71078 return addr;
71079 }
71080
71081 /* Insert the end of a co-routine
71082 */
@@ -71358,14 +71583,10 @@
71583 case P4_EXPR: {
71584 sqlite3ExprDelete(db, (Expr*)p4);
71585 break;
71586 }
71587 #endif
 
 
 
 
71588 case P4_FUNCDEF: {
71589 freeEphemeralFunction(db, (FuncDef*)p4);
71590 break;
71591 }
71592 case P4_MEM: {
@@ -71505,21 +71726,47 @@
71726 pOp->p4.p = (void*)zP4;
71727 pOp->p4type = (signed char)n;
71728 if( n==P4_VTAB ) sqlite3VtabLock((VTable*)zP4);
71729 }
71730 }
71731
71732 /*
71733 ** Change the P4 operand of the most recently coded instruction
71734 ** to the value defined by the arguments. This is a high-speed
71735 ** version of sqlite3VdbeChangeP4().
71736 **
71737 ** The P4 operand must not have been previously defined. And the new
71738 ** P4 must not be P4_INT32. Use sqlite3VdbeChangeP4() in either of
71739 ** those cases.
71740 */
71741 SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe *p, void *pP4, int n){
71742 VdbeOp *pOp;
71743 assert( n!=P4_INT32 && n!=P4_VTAB );
71744 assert( n<=0 );
71745 if( p->db->mallocFailed ){
71746 freeP4(p->db, n, pP4);
71747 }else{
71748 assert( pP4!=0 );
71749 assert( p->nOp>0 );
71750 pOp = &p->aOp[p->nOp-1];
71751 assert( pOp->p4type==P4_NOTUSED );
71752 pOp->p4type = n;
71753 pOp->p4.p = pP4;
71754 }
71755 }
71756
71757 /*
71758 ** Set the P4 on the most recently added opcode to the KeyInfo for the
71759 ** index given.
71760 */
71761 SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse *pParse, Index *pIdx){
71762 Vdbe *v = pParse->pVdbe;
71763 KeyInfo *pKeyInfo;
71764 assert( v!=0 );
71765 assert( pIdx!=0 );
71766 pKeyInfo = sqlite3KeyInfoOfIndex(pParse, pIdx);
71767 if( pKeyInfo ) sqlite3VdbeAppendP4(v, pKeyInfo, P4_KEYINFO);
71768 }
71769
71770 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
71771 /*
71772 ** Change the comment on the most recently coded instruction. Or
@@ -71805,11 +72052,11 @@
72052 case P4_FUNCDEF: {
72053 FuncDef *pDef = pOp->p4.pFunc;
72054 sqlite3XPrintf(&x, "%s(%d)", pDef->zName, pDef->nArg);
72055 break;
72056 }
72057 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
72058 case P4_FUNCCTX: {
72059 FuncDef *pDef = pOp->p4.pCtx->pFunc;
72060 sqlite3XPrintf(&x, "%s(%d)", pDef->zName, pDef->nArg);
72061 break;
72062 }
@@ -74899,11 +75146,11 @@
75146 nCellKey = sqlite3BtreePayloadSize(pCur);
75147 assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
75148
75149 /* Read in the complete content of the index entry */
75150 sqlite3VdbeMemInit(&m, db, 0);
75151 rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, &m);
75152 if( rc ){
75153 return rc;
75154 }
75155
75156 /* The index entry must begin with a header size */
@@ -74979,11 +75226,11 @@
75226 if( nCellKey<=0 || nCellKey>0x7fffffff ){
75227 *res = 0;
75228 return SQLITE_CORRUPT_BKPT;
75229 }
75230 sqlite3VdbeMemInit(&m, db, 0);
75231 rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, &m);
75232 if( rc ){
75233 return rc;
75234 }
75235 *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked);
75236 sqlite3VdbeMemRelease(&m);
@@ -76868,11 +77115,11 @@
77115 u8 *aRec;
77116
77117 nRec = sqlite3BtreePayloadSize(p->pCsr->uc.pCursor);
77118 aRec = sqlite3DbMallocRaw(db, nRec);
77119 if( !aRec ) goto preupdate_old_out;
77120 rc = sqlite3BtreePayload(p->pCsr->uc.pCursor, 0, nRec, aRec);
77121 if( rc==SQLITE_OK ){
77122 p->pUnpacked = vdbeUnpackRecord(&p->keyinfo, nRec, aRec);
77123 if( !p->pUnpacked ) rc = SQLITE_NOMEM;
77124 }
77125 if( rc!=SQLITE_OK ){
@@ -77385,11 +77632,11 @@
77632
77633 /*
77634 ** Test a register to see if it exceeds the current maximum blob size.
77635 ** If it does, record the new maximum blob size.
77636 */
77637 #if defined(SQLITE_TEST) && !defined(SQLITE_UNTESTABLE)
77638 # define UPDATE_MAX_BLOBSIZE(P) updateMaxBlobsize(P)
77639 #else
77640 # define UPDATE_MAX_BLOBSIZE(P)
77641 #endif
77642
@@ -79833,11 +80080,10 @@
80080 assert( p2<pC->nField );
80081 aOffset = pC->aOffset;
80082 assert( pC->eCurType!=CURTYPE_VTAB );
80083 assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow );
80084 assert( pC->eCurType!=CURTYPE_SORTER );
 
80085
80086 if( pC->cacheStatus!=p->cacheCtr ){ /*OPTIMIZATION-IF-FALSE*/
80087 if( pC->nullRow ){
80088 if( pC->eCurType==CURTYPE_PSEUDO ){
80089 assert( pC->uc.pseudoTableReg>0 );
@@ -79849,10 +80095,11 @@
80095 }else{
80096 sqlite3VdbeMemSetNull(pDest);
80097 goto op_column_out;
80098 }
80099 }else{
80100 pCrsr = pC->uc.pCursor;
80101 assert( pC->eCurType==CURTYPE_BTREE );
80102 assert( pCrsr );
80103 assert( sqlite3BtreeCursorIsValid(pCrsr) );
80104 pC->payloadSize = sqlite3BtreePayloadSize(pCrsr);
80105 pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &avail);
@@ -79912,11 +80159,11 @@
80159 */
80160 if( pC->iHdrOffset<aOffset[0] ){
80161 /* Make sure zData points to enough of the record to cover the header. */
80162 if( pC->aRow==0 ){
80163 memset(&sMem, 0, sizeof(sMem));
80164 rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, 0, aOffset[0], &sMem);
80165 if( rc!=SQLITE_OK ) goto abort_due_to_error;
80166 zData = (u8*)sMem.z;
80167 }else{
80168 zData = pC->aRow;
80169 }
@@ -80025,12 +80272,11 @@
80272 ** So we might as well use bogus content rather than reading
80273 ** content from disk. */
80274 static u8 aZero[8]; /* This is the bogus content */
80275 sqlite3VdbeSerialGet(aZero, t, pDest);
80276 }else{
80277 rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest);
 
80278 if( rc!=SQLITE_OK ) goto abort_due_to_error;
80279 sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest);
80280 pDest->flags &= ~MEM_Ephem;
80281 }
80282 }
@@ -82002,51 +82248,40 @@
82248 }
82249
82250 /* Opcode: RowData P1 P2 * * *
82251 ** Synopsis: r[P2]=data
82252 **
82253 ** Write into register P2 the complete row content for the row at
82254 ** which cursor P1 is currently pointing.
82255 ** There is no interpretation of the data.
82256 ** It is just copied onto the P2 register exactly as
82257 ** it is found in the database file.
82258 **
82259 ** If cursor P1 is an index, then the content is the key of the row.
82260 ** If cursor P2 is a table, then the content extracted is the data.
 
 
 
 
 
 
 
 
82261 **
82262 ** If the P1 cursor must be pointing to a valid row (not a NULL row)
82263 ** of a real table, not a pseudo-table.
82264 */
 
82265 case OP_RowData: {
82266 VdbeCursor *pC;
82267 BtCursor *pCrsr;
82268 u32 n;
82269
82270 pOut = &aMem[pOp->p2];
82271 memAboutToChange(p, pOut);
82272
 
82273 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
82274 pC = p->apCsr[pOp->p1];
82275 assert( pC!=0 );
82276 assert( pC->eCurType==CURTYPE_BTREE );
82277 assert( isSorter(pC)==0 );
 
 
82278 assert( pC->nullRow==0 );
82279 assert( pC->uc.pCursor!=0 );
82280 pCrsr = pC->uc.pCursor;
82281
82282 /* The OP_RowData opcodes always follow OP_NotExists or
82283 ** OP_SeekRowid or OP_Rewind/Op_Next with no intervening instructions
82284 ** that might invalidate the cursor.
82285 ** If this where not the case, on of the following assert()s
82286 ** would fail. Should this ever change (because of changes in the code
82287 ** generator) then the fix would be to insert a call to
@@ -82067,15 +82302,11 @@
82302 if( sqlite3VdbeMemClearAndResize(pOut, MAX(n,32)) ){
82303 goto no_mem;
82304 }
82305 pOut->n = n;
82306 MemSetTypeFlag(pOut, MEM_Blob);
82307 rc = sqlite3BtreePayload(pCrsr, 0, n, pOut->z);
 
 
 
 
82308 if( rc ) goto abort_due_to_error;
82309 pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
82310 UPDATE_MAX_BLOBSIZE(pOut);
82311 REGISTER_TRACE(pOp->p2, pOut);
82312 break;
@@ -83401,17 +83632,17 @@
83632 }
83633
83634 /* Opcode: DecrJumpZero P1 P2 * * *
83635 ** Synopsis: if (--r[P1])==0 goto P2
83636 **
83637 ** Register P1 must hold an integer. Decrement the value in P1
83638 ** and jump to P2 if the new value is exactly zero.
83639 */
83640 case OP_DecrJumpZero: { /* jump, in1 */
83641 pIn1 = &aMem[pOp->p1];
83642 assert( pIn1->flags&MEM_Int );
83643 if( pIn1->u.i>SMALLEST_INT64 ) pIn1->u.i--;
83644 VdbeBranchTaken(pIn1->u.i==0, 2);
83645 if( pIn1->u.i==0 ) goto jump_to_p2;
83646 break;
83647 }
83648
@@ -84854,11 +85085,11 @@
85085
85086 /*
85087 ** Read data from a blob handle.
85088 */
85089 SQLITE_API int sqlite3_blob_read(sqlite3_blob *pBlob, void *z, int n, int iOffset){
85090 return blobReadWrite(pBlob, z, n, iOffset, sqlite3BtreePayloadChecked);
85091 }
85092
85093 /*
85094 ** Write data to a blob handle.
85095 */
@@ -90235,11 +90466,11 @@
90466 ** can be attached to pRight to cause this node to take ownership of
90467 ** pVector. Typically there will be multiple TK_SELECT_COLUMN nodes
90468 ** with the same pLeft pointer to the pVector, but only one of them
90469 ** will own the pVector.
90470 */
90471 pRet = sqlite3PExpr(pParse, TK_SELECT_COLUMN, 0, 0);
90472 if( pRet ){
90473 pRet->iColumn = iField;
90474 pRet->pLeft = pVector;
90475 }
90476 assert( pRet==0 || pRet->iTable==0 );
@@ -90627,19 +90858,23 @@
90858 */
90859 SQLITE_PRIVATE Expr *sqlite3PExpr(
90860 Parse *pParse, /* Parsing context */
90861 int op, /* Expression opcode */
90862 Expr *pLeft, /* Left operand */
90863 Expr *pRight /* Right operand */
 
90864 ){
90865 Expr *p;
90866 if( op==TK_AND && pParse->nErr==0 ){
90867 /* Take advantage of short-circuit false optimization for AND */
90868 p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
90869 }else{
90870 p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr));
90871 if( p ){
90872 memset(p, 0, sizeof(Expr));
90873 p->op = op & TKFLG_MASK;
90874 p->iAgg = -1;
90875 }
90876 sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
90877 }
90878 if( p ) {
90879 sqlite3ExprCheckHeight(pParse, p->nHeight);
90880 }
@@ -92158,10 +92393,32 @@
92393 SQLITE_PRIVATE void sqlite3SubselectError(Parse *pParse, int nActual, int nExpect){
92394 const char *zFmt = "sub-select returns %d columns - expected %d";
92395 sqlite3ErrorMsg(pParse, zFmt, nActual, nExpect);
92396 }
92397 #endif
92398
92399 /*
92400 ** Expression pExpr is a vector that has been used in a context where
92401 ** it is not permitted. If pExpr is a sub-select vector, this routine
92402 ** loads the Parse object with a message of the form:
92403 **
92404 ** "sub-select returns N columns - expected 1"
92405 **
92406 ** Or, if it is a regular scalar vector:
92407 **
92408 ** "row value misused"
92409 */
92410 SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse *pParse, Expr *pExpr){
92411 #ifndef SQLITE_OMIT_SUBQUERY
92412 if( pExpr->flags & EP_xIsSelect ){
92413 sqlite3SubselectError(pParse, pExpr->x.pSelect->pEList->nExpr, 1);
92414 }else
92415 #endif
92416 {
92417 sqlite3ErrorMsg(pParse, "row value misused");
92418 }
92419 }
92420
92421 /*
92422 ** Generate code for scalar subqueries used as a subquery expression, EXISTS,
92423 ** or IN operators. Examples:
92424 **
@@ -92441,15 +92698,11 @@
92698 if( nVector!=pIn->x.pSelect->pEList->nExpr ){
92699 sqlite3SubselectError(pParse, pIn->x.pSelect->pEList->nExpr, nVector);
92700 return 1;
92701 }
92702 }else if( nVector!=1 ){
92703 sqlite3VectorErrorMsg(pParse, pIn->pLeft);
 
 
 
 
92704 return 1;
92705 }
92706 return 0;
92707 }
92708 #endif
@@ -92750,26 +93003,26 @@
93003 int c;
93004 i64 value;
93005 const char *z = pExpr->u.zToken;
93006 assert( z!=0 );
93007 c = sqlite3DecOrHexToI64(z, &value);
93008 if( c==1 || (c==2 && !negFlag) || (negFlag && value==SMALLEST_INT64)){
 
 
 
93009 #ifdef SQLITE_OMIT_FLOATING_POINT
93010 sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z);
93011 #else
93012 #ifndef SQLITE_OMIT_HEX_INTEGER
93013 if( sqlite3_strnicmp(z,"0x",2)==0 ){
93014 sqlite3ErrorMsg(pParse, "hex literal too big: %s%s", negFlag?"-":"",z);
93015 }else
93016 #endif
93017 {
93018 codeReal(v, z, negFlag, iMem);
93019 }
93020 #endif
93021 }else{
93022 if( negFlag ){ value = c==2 ? SMALLEST_INT64 : -value; }
93023 sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, iMem, 0, (u8*)&value, P4_INT64);
93024 }
93025 }
93026 }
93027
93028 /*
@@ -93104,11 +93357,11 @@
93357 }else{
93358 int i;
93359 iResult = pParse->nMem+1;
93360 pParse->nMem += nResult;
93361 for(i=0; i<nResult; i++){
93362 sqlite3ExprCodeFactorable(pParse, p->x.pList->a[i].pExpr, i+iResult);
93363 }
93364 }
93365 }
93366 return iResult;
93367 }
@@ -93218,11 +93471,11 @@
93471 assert( pExpr->u.zToken[0]!=0 );
93472 sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target);
93473 if( pExpr->u.zToken[1]!=0 ){
93474 assert( pExpr->u.zToken[0]=='?'
93475 || strcmp(pExpr->u.zToken, pParse->azVar[pExpr->iColumn-1])==0 );
93476 sqlite3VdbeAppendP4(v, pParse->azVar[pExpr->iColumn-1], P4_STATIC);
93477 }
93478 return target;
93479 }
93480 case TK_REGISTER: {
93481 return pExpr->iTable;
@@ -93975,10 +94228,15 @@
94228 compRight.pRight = pExpr->x.pList->a[1].pExpr;
94229 exprToRegister(&exprX, exprCodeVector(pParse, &exprX, &regFree1));
94230 if( xJump ){
94231 xJump(pParse, &exprAnd, dest, jumpIfNull);
94232 }else{
94233 /* Mark the expression is being from the ON or USING clause of a join
94234 ** so that the sqlite3ExprCodeTarget() routine will not attempt to move
94235 ** it into the Parse.pConstExpr list. We should use a new bit for this,
94236 ** for clarity, but we are out of bits in the Expr.flags field so we
94237 ** have to reuse the EP_FromJoin bit. Bummer. */
94238 exprX.flags |= EP_FromJoin;
94239 sqlite3ExprCodeTarget(pParse, &exprAnd, dest);
94240 }
94241 sqlite3ReleaseTempReg(pParse, regFree1);
94242
@@ -103465,11 +103723,11 @@
103723 ** DELETE FROM table_a WHERE rowid IN (
103724 ** SELECT rowid FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
103725 ** );
103726 */
103727
103728 pSelectRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0);
103729 if( pSelectRowid == 0 ) goto limit_where_cleanup;
103730 pEList = sqlite3ExprListAppend(pParse, 0, pSelectRowid);
103731 if( pEList == 0 ) goto limit_where_cleanup;
103732
103733 /* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree
@@ -103484,12 +103742,12 @@
103742 pSelect = sqlite3SelectNew(pParse,pEList,pSelectSrc,pWhere,0,0,
103743 pOrderBy,0,pLimit,pOffset);
103744 if( pSelect == 0 ) return 0;
103745
103746 /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
103747 pWhereRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0);
103748 pInClause = pWhereRowid ? sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0) : 0;
103749 sqlite3PExprAddSelect(pParse, pInClause, pSelect);
103750 return pInClause;
103751
103752 limit_where_cleanup:
103753 sqlite3ExprDelete(pParse->db, pWhere);
@@ -103796,11 +104054,11 @@
104054 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
104055 VdbeCoverage(v);
104056 }
104057 }else if( pPk ){
104058 addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v);
104059 sqlite3VdbeAddOp2(v, OP_RowData, iEphCur, iKey);
104060 assert( nKey==0 ); /* OP_Found will use a composite key */
104061 }else{
104062 addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
104063 VdbeCoverage(v);
104064 assert( nKey==1 );
@@ -104013,11 +104271,11 @@
104271 */
104272 if( pTab->pSelect==0 ){
104273 u8 p5 = 0;
104274 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
104275 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
104276 sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE);
104277 if( eMode!=ONEPASS_OFF ){
104278 sqlite3VdbeChangeP5(v, OPFLAG_AUXDELETE);
104279 }
104280 if( iIdxNoSeek>=0 ){
104281 sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek);
@@ -104790,13 +105048,23 @@
105048 /* If SQLITE_CASE_SENSITIVE_LIKE is defined, then the LIKE operator
105049 ** is case sensitive causing 'a' LIKE 'A' to be false */
105050 static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 };
105051
105052 /*
105053 ** Possible error returns from patternMatch()
105054 */
105055 #define SQLITE_MATCH 0
105056 #define SQLITE_NOMATCH 1
105057 #define SQLITE_NOWILDCARDMATCH 2
105058
105059 /*
105060 ** Compare two UTF-8 strings for equality where the first string is
105061 ** a GLOB or LIKE expression. Return values:
105062 **
105063 ** SQLITE_MATCH: Match
105064 ** SQLITE_NOMATCH: No match
105065 ** SQLITE_NOWILDCARDMATCH: No match in spite of having * or % wildcards.
105066 **
105067 ** Globbing rules:
105068 **
105069 ** '*' Matches any sequence of zero or more characters.
105070 **
@@ -104843,71 +105111,76 @@
105111 /* Skip over multiple "*" characters in the pattern. If there
105112 ** are also "?" characters, skip those as well, but consume a
105113 ** single character of the input string for each "?" skipped */
105114 while( (c=Utf8Read(zPattern)) == matchAll || c == matchOne ){
105115 if( c==matchOne && sqlite3Utf8Read(&zString)==0 ){
105116 return SQLITE_NOWILDCARDMATCH;
105117 }
105118 }
105119 if( c==0 ){
105120 return SQLITE_MATCH; /* "*" at the end of the pattern matches */
105121 }else if( c==matchOther ){
105122 if( pInfo->matchSet==0 ){
105123 c = sqlite3Utf8Read(&zPattern);
105124 if( c==0 ) return SQLITE_NOWILDCARDMATCH;
105125 }else{
105126 /* "[...]" immediately follows the "*". We have to do a slow
105127 ** recursive search in this case, but it is an unusual case. */
105128 assert( matchOther<0x80 ); /* '[' is a single-byte character */
105129 while( *zString ){
105130 int bMatch = patternCompare(&zPattern[-1],zString,pInfo,matchOther);
105131 if( bMatch!=SQLITE_NOMATCH ) return bMatch;
105132 SQLITE_SKIP_UTF8(zString);
105133 }
105134 return SQLITE_NOWILDCARDMATCH;
105135 }
105136 }
105137
105138 /* At this point variable c contains the first character of the
105139 ** pattern string past the "*". Search in the input string for the
105140 ** first matching character and recursively continue the match from
105141 ** that point.
105142 **
105143 ** For a case-insensitive search, set variable cx to be the same as
105144 ** c but in the other case and search the input string for either
105145 ** c or cx.
105146 */
105147 if( c<=0x80 ){
105148 u32 cx;
105149 int bMatch;
105150 if( noCase ){
105151 cx = sqlite3Toupper(c);
105152 c = sqlite3Tolower(c);
105153 }else{
105154 cx = c;
105155 }
105156 while( (c2 = *(zString++))!=0 ){
105157 if( c2!=c && c2!=cx ) continue;
105158 bMatch = patternCompare(zPattern,zString,pInfo,matchOther);
105159 if( bMatch!=SQLITE_NOMATCH ) return bMatch;
105160 }
105161 }else{
105162 int bMatch;
105163 while( (c2 = Utf8Read(zString))!=0 ){
105164 if( c2!=c ) continue;
105165 bMatch = patternCompare(zPattern,zString,pInfo,matchOther);
105166 if( bMatch!=SQLITE_NOMATCH ) return bMatch;
105167 }
105168 }
105169 return SQLITE_NOWILDCARDMATCH;
105170 }
105171 if( c==matchOther ){
105172 if( pInfo->matchSet==0 ){
105173 c = sqlite3Utf8Read(&zPattern);
105174 if( c==0 ) return SQLITE_NOMATCH;
105175 zEscaped = zPattern;
105176 }else{
105177 u32 prior_c = 0;
105178 int seen = 0;
105179 int invert = 0;
105180 c = sqlite3Utf8Read(&zString);
105181 if( c==0 ) return SQLITE_NOMATCH;
105182 c2 = sqlite3Utf8Read(&zPattern);
105183 if( c2=='^' ){
105184 invert = 1;
105185 c2 = sqlite3Utf8Read(&zPattern);
105186 }
@@ -104927,11 +105200,11 @@
105200 prior_c = c2;
105201 }
105202 c2 = sqlite3Utf8Read(&zPattern);
105203 }
105204 if( c2==0 || (seen ^ invert)==0 ){
105205 return SQLITE_NOMATCH;
105206 }
105207 continue;
105208 }
105209 }
105210 c2 = Utf8Read(zString);
@@ -104938,27 +105211,29 @@
105211 if( c==c2 ) continue;
105212 if( noCase && sqlite3Tolower(c)==sqlite3Tolower(c2) && c<0x80 && c2<0x80 ){
105213 continue;
105214 }
105215 if( c==matchOne && zPattern!=zEscaped && c2!=0 ) continue;
105216 return SQLITE_NOMATCH;
105217 }
105218 return *zString==0 ? SQLITE_MATCH : SQLITE_NOMATCH;
105219 }
105220
105221 /*
105222 ** The sqlite3_strglob() interface. Return 0 on a match (like strcmp()) and
105223 ** non-zero if there is no match.
105224 */
105225 SQLITE_API int sqlite3_strglob(const char *zGlobPattern, const char *zString){
105226 return patternCompare((u8*)zGlobPattern, (u8*)zString, &globInfo, '[');
105227 }
105228
105229 /*
105230 ** The sqlite3_strlike() interface. Return 0 on a match and non-zero for
105231 ** a miss - like strcmp().
105232 */
105233 SQLITE_API int sqlite3_strlike(const char *zPattern, const char *zStr, unsigned int esc){
105234 return patternCompare((u8*)zPattern, (u8*)zStr, &likeInfoNorm, esc);
105235 }
105236
105237 /*
105238 ** Count the number of times that the LIKE operator (or GLOB which is
105239 ** just a variation of LIKE) gets called. This is used for testing
@@ -105035,11 +105310,11 @@
105310 }
105311 if( zA && zB ){
105312 #ifdef SQLITE_TEST
105313 sqlite3_like_count++;
105314 #endif
105315 sqlite3_result_int(context, patternCompare(zB, zA, pInfo, escape)==SQLITE_MATCH);
105316 }
105317 }
105318
105319 /*
105320 ** Implementation of the NULLIF(x,y) function. The result is the first
@@ -106628,11 +106903,11 @@
106903 pLeft = exprTableRegister(pParse, pTab, regData, iCol);
106904 iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
106905 assert( iCol>=0 );
106906 zCol = pFKey->pFrom->aCol[iCol].zName;
106907 pRight = sqlite3Expr(db, TK_ID, zCol);
106908 pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight);
106909 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
106910 }
106911
106912 /* If the child table is the same as the parent table, then add terms
106913 ** to the WHERE clause that prevent this entry from being scanned.
@@ -106650,24 +106925,24 @@
106925 Expr *pLeft; /* Value from parent table row */
106926 Expr *pRight; /* Column ref to child table */
106927 if( HasRowid(pTab) ){
106928 pLeft = exprTableRegister(pParse, pTab, regData, -1);
106929 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
106930 pNe = sqlite3PExpr(pParse, TK_NE, pLeft, pRight);
106931 }else{
106932 Expr *pEq, *pAll = 0;
106933 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
106934 assert( pIdx!=0 );
106935 for(i=0; i<pPk->nKeyCol; i++){
106936 i16 iCol = pIdx->aiColumn[i];
106937 assert( iCol>=0 );
106938 pLeft = exprTableRegister(pParse, pTab, regData, iCol);
106939 pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol);
106940 pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight);
106941 pAll = sqlite3ExprAnd(db, pAll, pEq);
106942 }
106943 pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0);
106944 }
106945 pWhere = sqlite3ExprAnd(db, pWhere, pNe);
106946 }
106947
106948 /* Resolve the references in the WHERE clause. */
@@ -107249,14 +107524,13 @@
107524 ** that the affinity and collation sequence associated with the
107525 ** parent table are used for the comparison. */
107526 pEq = sqlite3PExpr(pParse, TK_EQ,
107527 sqlite3PExpr(pParse, TK_DOT,
107528 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
107529 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)),
 
107530 sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0)
107531 );
107532 pWhere = sqlite3ExprAnd(db, pWhere, pEq);
107533
107534 /* For ON UPDATE, construct the next term of the WHEN clause.
107535 ** The final WHEN clause will be like this:
107536 **
@@ -107264,27 +107538,24 @@
107538 */
107539 if( pChanges ){
107540 pEq = sqlite3PExpr(pParse, TK_IS,
107541 sqlite3PExpr(pParse, TK_DOT,
107542 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
107543 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)),
 
107544 sqlite3PExpr(pParse, TK_DOT,
107545 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
107546 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0))
107547 );
 
107548 pWhen = sqlite3ExprAnd(db, pWhen, pEq);
107549 }
107550
107551 if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){
107552 Expr *pNew;
107553 if( action==OE_Cascade ){
107554 pNew = sqlite3PExpr(pParse, TK_DOT,
107555 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
107556 sqlite3ExprAlloc(db, TK_ID, &tToCol, 0));
 
107557 }else if( action==OE_SetDflt ){
107558 Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt;
107559 if( pDflt ){
107560 pNew = sqlite3ExprDup(db, pDflt, 0);
107561 }else{
@@ -107336,11 +107607,11 @@
107607
107608 pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
107609 pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
107610 pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
107611 if( pWhen ){
107612 pWhen = sqlite3PExpr(pParse, TK_NOT, pWhen, 0);
107613 pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
107614 }
107615 }
107616
107617 /* Re-enable the lookaside buffer, if it was disabled earlier. */
@@ -108760,12 +109031,13 @@
109031 /* Fall through */
109032 case OE_Rollback:
109033 case OE_Fail: {
109034 char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
109035 pTab->aCol[i].zName);
109036 sqlite3VdbeAddOp3(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, onError,
109037 regNewData+1+i);
109038 sqlite3VdbeAppendP4(v, zMsg, P4_DYNAMIC);
109039 sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
109040 VdbeCoverage(v);
109041 break;
109042 }
109043 case OE_Ignore: {
@@ -108903,11 +109175,11 @@
109175 /* This OP_Delete opcode fires the pre-update-hook only. It does
109176 ** not modify the b-tree. It is more efficient to let the coming
109177 ** OP_Insert replace the existing entry than it is to delete the
109178 ** existing entry and then insert a new one. */
109179 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, OPFLAG_ISNOOP);
109180 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
109181 }
109182 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
109183 if( pTab->pIndex ){
109184 sqlite3MultiWrite(pParse);
109185 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,-1);
@@ -109180,11 +109452,11 @@
109452 if( useSeekResult ){
109453 pik_flags |= OPFLAG_USESEEKRESULT;
109454 }
109455 sqlite3VdbeAddOp3(v, OP_Insert, iDataCur, regRec, regNewData);
109456 if( !pParse->nested ){
109457 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
109458 }
109459 sqlite3VdbeChangeP5(v, pik_flags);
109460 }
109461
109462 /*
@@ -109611,11 +109883,11 @@
109883 sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest);
109884 sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
109885 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
109886 VdbeComment((v, "%s", pDestIdx->zName));
109887 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
109888 sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
109889 if( db->flags & SQLITE_Vacuum ){
109890 /* This INSERT command is part of a VACUUM operation, which guarantees
109891 ** that the destination table is empty. If all indexed columns use
109892 ** collation sequence BINARY, then it can also be assumed that the
109893 ** index will be populated by inserting keys in strictly sorted
@@ -114820,11 +115092,11 @@
115092 assert( pSrc->a[iRight].pTab );
115093
115094 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iColLeft);
115095 pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
115096
115097 pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2);
115098 if( pEq && isOuterJoin ){
115099 ExprSetProperty(pEq, EP_FromJoin);
115100 assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) );
115101 ExprSetVVAProperty(pEq, EP_NoReduce);
115102 pEq->iRightJoinTable = (i16)pE2->iTable;
@@ -116992,11 +117264,11 @@
117264 iBreak = sqlite3VdbeMakeLabel(v);
117265 iCont = sqlite3VdbeMakeLabel(v);
117266 computeLimitRegisters(pParse, p, iBreak);
117267 sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
117268 r1 = sqlite3GetTempReg(pParse);
117269 iStart = sqlite3VdbeAddOp2(v, OP_RowData, tab1, r1);
117270 sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0); VdbeCoverage(v);
117271 sqlite3ReleaseTempReg(pParse, r1);
117272 selectInnerLoop(pParse, p, p->pEList, tab1,
117273 0, 0, &dest, iCont, iBreak);
117274 sqlite3VdbeResolveLabel(v, iCont);
@@ -117619,12 +117891,12 @@
117891 }
117892 #endif
117893
117894 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
117895 /* Forward Declarations */
117896 static void substExprList(Parse*, ExprList*, int, ExprList*);
117897 static void substSelect(Parse*, Select *, int, ExprList*, int);
117898
117899 /*
117900 ** Scan through the expression pExpr. Replace every reference to
117901 ** a column in table number iTable with a copy of the iColumn-th
117902 ** entry in pEList. (But leave references to the ROWID column
@@ -117636,52 +117908,62 @@
117908 ** FORM clause entry is iTable. This routine make the necessary
117909 ** changes to pExpr so that it refers directly to the source table
117910 ** of the subquery rather the result set of the subquery.
117911 */
117912 static Expr *substExpr(
117913 Parse *pParse, /* Report errors here */
117914 Expr *pExpr, /* Expr in which substitution occurs */
117915 int iTable, /* Table to be substituted */
117916 ExprList *pEList /* Substitute expressions */
117917 ){
117918 sqlite3 *db = pParse->db;
117919 if( pExpr==0 ) return 0;
117920 if( pExpr->op==TK_COLUMN && pExpr->iTable==iTable ){
117921 if( pExpr->iColumn<0 ){
117922 pExpr->op = TK_NULL;
117923 }else{
117924 Expr *pNew;
117925 Expr *pCopy = pEList->a[pExpr->iColumn].pExpr;
117926 assert( pEList!=0 && pExpr->iColumn<pEList->nExpr );
117927 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
117928 if( sqlite3ExprIsVector(pCopy) ){
117929 sqlite3VectorErrorMsg(pParse, pCopy);
117930 }else{
117931 pNew = sqlite3ExprDup(db, pCopy, 0);
117932 if( pNew && (pExpr->flags & EP_FromJoin) ){
117933 pNew->iRightJoinTable = pExpr->iRightJoinTable;
117934 pNew->flags |= EP_FromJoin;
117935 }
117936 sqlite3ExprDelete(db, pExpr);
117937 pExpr = pNew;
117938 }
117939 }
117940 }else{
117941 pExpr->pLeft = substExpr(pParse, pExpr->pLeft, iTable, pEList);
117942 pExpr->pRight = substExpr(pParse, pExpr->pRight, iTable, pEList);
117943 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
117944 substSelect(pParse, pExpr->x.pSelect, iTable, pEList, 1);
117945 }else{
117946 substExprList(pParse, pExpr->x.pList, iTable, pEList);
117947 }
117948 }
117949 return pExpr;
117950 }
117951 static void substExprList(
117952 Parse *pParse, /* Report errors here */
117953 ExprList *pList, /* List to scan and in which to make substitutes */
117954 int iTable, /* Table to be substituted */
117955 ExprList *pEList /* Substitute values */
117956 ){
117957 int i;
117958 if( pList==0 ) return;
117959 for(i=0; i<pList->nExpr; i++){
117960 pList->a[i].pExpr = substExpr(pParse, pList->a[i].pExpr, iTable, pEList);
117961 }
117962 }
117963 static void substSelect(
117964 Parse *pParse, /* Report errors here */
117965 Select *p, /* SELECT statement in which to make substitutions */
117966 int iTable, /* Table to be replaced */
117967 ExprList *pEList, /* Substitute values */
117968 int doPrior /* Do substitutes on p->pPrior too */
117969 ){
@@ -117688,21 +117970,21 @@
117970 SrcList *pSrc;
117971 struct SrcList_item *pItem;
117972 int i;
117973 if( !p ) return;
117974 do{
117975 substExprList(pParse, p->pEList, iTable, pEList);
117976 substExprList(pParse, p->pGroupBy, iTable, pEList);
117977 substExprList(pParse, p->pOrderBy, iTable, pEList);
117978 p->pHaving = substExpr(pParse, p->pHaving, iTable, pEList);
117979 p->pWhere = substExpr(pParse, p->pWhere, iTable, pEList);
117980 pSrc = p->pSrc;
117981 assert( pSrc!=0 );
117982 for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
117983 substSelect(pParse, pItem->pSelect, iTable, pEList, 1);
117984 if( pItem->fg.isTabFunc ){
117985 substExprList(pParse, pItem->u1.pFuncArg, iTable, pEList);
117986 }
117987 }
117988 }while( doPrior && (p = p->pPrior)!=0 );
117989 }
117990 #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
@@ -118223,11 +118505,11 @@
118505 assert( pParent->pGroupBy==0 );
118506 pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
118507 }else{
118508 pParent->pWhere = sqlite3ExprAnd(db, pWhere, pParent->pWhere);
118509 }
118510 substSelect(pParse, pParent, iParent, pSub->pEList, 0);
118511
118512 /* The flattened query is distinct if either the inner or the
118513 ** outer query is distinct.
118514 */
118515 pParent->selFlags |= pSub->selFlags & SF_Distinct;
@@ -118297,11 +118579,11 @@
118579 **
118580 ** Return 0 if no changes are made and non-zero if one or more WHERE clause
118581 ** terms are duplicated into the subquery.
118582 */
118583 static int pushDownWhereTerms(
118584 Parse *pParse, /* Parse context (for malloc() and error reporting) */
118585 Select *pSubq, /* The subquery whose WHERE clause is to be augmented */
118586 Expr *pWhere, /* The WHERE clause of the outer query */
118587 int iCursor /* Cursor number of the subquery */
118588 ){
118589 Expr *pNew;
@@ -118318,20 +118600,20 @@
118600 }
118601 if( pSubq->pLimit!=0 ){
118602 return 0; /* restriction (3) */
118603 }
118604 while( pWhere->op==TK_AND ){
118605 nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, iCursor);
118606 pWhere = pWhere->pLeft;
118607 }
118608 if( ExprHasProperty(pWhere,EP_FromJoin) ) return 0; /* restriction 5 */
118609 if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
118610 nChng++;
118611 while( pSubq ){
118612 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
118613 pNew = substExpr(pParse, pNew, iCursor, pSubq->pEList);
118614 pSubq->pWhere = sqlite3ExprAnd(pParse->db, pSubq->pWhere, pNew);
118615 pSubq = pSubq->pPrior;
118616 }
118617 }
118618 return nChng;
118619 }
@@ -118957,14 +119239,14 @@
119239 zColname = zName;
119240 zToFree = 0;
119241 if( longNames || pTabList->nSrc>1 ){
119242 Expr *pLeft;
119243 pLeft = sqlite3Expr(db, TK_ID, zTabName);
119244 pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
119245 if( zSchemaName ){
119246 pLeft = sqlite3Expr(db, TK_ID, zSchemaName);
119247 pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pExpr);
119248 }
119249 if( longNames ){
119250 zColname = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
119251 zToFree = zColname;
119252 }
@@ -119197,12 +119479,12 @@
119479 int i;
119480 struct AggInfo_func *pF;
119481 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
119482 ExprList *pList = pF->pExpr->x.pList;
119483 assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
119484 sqlite3VdbeAddOp2(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0);
119485 sqlite3VdbeAppendP4(v, pF->pFunc, P4_FUNCDEF);
119486 }
119487 }
119488
119489 /*
119490 ** Update the accumulator memory cells for an aggregate based on
@@ -119249,12 +119531,12 @@
119531 pColl = pParse->db->pDfltColl;
119532 }
119533 if( regHit==0 && pAggInfo->nAccumulator ) regHit = ++pParse->nMem;
119534 sqlite3VdbeAddOp4(v, OP_CollSeq, regHit, 0, 0, (char *)pColl, P4_COLLSEQ);
119535 }
119536 sqlite3VdbeAddOp3(v, OP_AggStep0, 0, regAgg, pF->iMem);
119537 sqlite3VdbeAppendP4(v, pF->pFunc, P4_FUNCDEF);
119538 sqlite3VdbeChangeP5(v, (u8)nArg);
119539 sqlite3ExprCacheAffinityChange(pParse, regAgg, nArg);
119540 sqlite3ReleaseTempRange(pParse, regAgg, nArg);
119541 if( addrNext ){
119542 sqlite3VdbeResolveLabel(v, addrNext);
@@ -119484,11 +119766,11 @@
119766
119767 /* Make copies of constant WHERE-clause terms in the outer query down
119768 ** inside the subquery. This can help the subquery to run more efficiently.
119769 */
119770 if( (pItem->fg.jointype & JT_OUTER)==0
119771 && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor)
119772 ){
119773 #if SELECTTRACE_ENABLED
119774 if( sqlite3SelectTrace & 0x100 ){
119775 SELECTTRACE(0x100,pParse,p,("After WHERE-clause push-down:\n"));
119776 sqlite3TreeViewSelect(0, p, 0);
@@ -121570,11 +121852,11 @@
121852 VdbeComment((v, "%s.%s", pTab->zName, pCol->zName));
121853 assert( i<pTab->nCol );
121854 sqlite3ValueFromExpr(sqlite3VdbeDb(v), pCol->pDflt, enc,
121855 pCol->affinity, &pValue);
121856 if( pValue ){
121857 sqlite3VdbeAppendP4(v, pValue, P4_MEM);
121858 }
121859 #ifndef SQLITE_OMIT_FLOATING_POINT
121860 if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){
121861 sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
121862 }
@@ -121953,11 +122235,11 @@
122235 VdbeCoverageIf(v, pPk==0);
122236 VdbeCoverageIf(v, pPk!=0);
122237 }else if( pPk ){
122238 labelContinue = sqlite3VdbeMakeLabel(v);
122239 sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak); VdbeCoverage(v);
122240 addrTop = sqlite3VdbeAddOp2(v, OP_RowData, iEph, regKey);
122241 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey, 0);
122242 VdbeCoverage(v);
122243 }else{
122244 labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet, labelBreak,
122245 regOldRowid);
@@ -122111,11 +122393,11 @@
122393 sqlite3VdbeAddOp3(v, OP_Delete, iDataCur,
122394 OPFLAG_ISUPDATE | ((hasFK || chngKey || pPk!=0) ? 0 : OPFLAG_ISNOOP),
122395 regNewRowid
122396 );
122397 if( !pParse->nested ){
122398 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
122399 }
122400 #else
122401 if( hasFK || chngKey || pPk!=0 ){
122402 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
122403 }
@@ -125607,11 +125889,11 @@
125889 }
125890 sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg);
125891 sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1);
125892 sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg,
125893 pLoop->u.vtab.idxStr,
125894 pLoop->u.vtab.needFree ? P4_DYNAMIC : P4_STATIC);
125895 VdbeCoverage(v);
125896 pLoop->u.vtab.needFree = 0;
125897 pLevel->p1 = iCur;
125898 pLevel->op = pWInfo->eOnePass ? OP_Noop : OP_VNext;
125899 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
@@ -125640,11 +125922,11 @@
125922 sqlite3VdbeAddOp3(v, pOp->opcode, pOp->p1, pOp->p2, pOp->p3);
125923 }
125924
125925 /* Generate code that will continue to the next row if
125926 ** the IN constraint is not satisfied */
125927 pCompare = sqlite3PExpr(pParse, TK_EQ, 0, 0);
125928 assert( pCompare!=0 || db->mallocFailed );
125929 if( pCompare ){
125930 pCompare->pLeft = pTerm->pExpr->pLeft;
125931 pCompare->pRight = pRight = sqlite3Expr(db, TK_REGISTER, 0);
125932 if( pRight ){
@@ -126239,11 +126521,11 @@
126521 testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
126522 pExpr = sqlite3ExprDup(db, pExpr, 0);
126523 pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr);
126524 }
126525 if( pAndExpr ){
126526 pAndExpr = sqlite3PExpr(pParse, TK_AND|TKFLG_DONTFOLD, 0, pAndExpr);
126527 }
126528 }
126529
126530 /* Run a separate WHERE clause for each term of the OR clause. After
126531 ** eliminating duplicates from other WHERE clauses, the action for each
@@ -127241,11 +127523,11 @@
127523 pList = sqlite3ExprListAppend(pWInfo->pParse, pList, pDup);
127524 pLeft = pOrTerm->pExpr->pLeft;
127525 }
127526 assert( pLeft!=0 );
127527 pDup = sqlite3ExprDup(db, pLeft, 0);
127528 pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0);
127529 if( pNew ){
127530 int idxNew;
127531 transferJoinMarkings(pNew, pExpr);
127532 assert( !ExprHasProperty(pNew, EP_xIsSelect) );
127533 pNew->x.pList = pList;
@@ -127539,11 +127821,11 @@
127821 for(i=0; i<2; i++){
127822 Expr *pNewExpr;
127823 int idxNew;
127824 pNewExpr = sqlite3PExpr(pParse, ops[i],
127825 sqlite3ExprDup(db, pExpr->pLeft, 0),
127826 sqlite3ExprDup(db, pList->a[i].pExpr, 0));
127827 transferJoinMarkings(pNewExpr, pExpr);
127828 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
127829 testcase( idxNew==0 );
127830 exprAnalyze(pSrc, pWC, idxNew);
127831 pTerm = &pWC->a[idxTerm];
@@ -127624,19 +127906,19 @@
127906 }
127907 zCollSeqName = noCase ? "NOCASE" : "BINARY";
127908 pNewExpr1 = sqlite3ExprDup(db, pLeft, 0);
127909 pNewExpr1 = sqlite3PExpr(pParse, TK_GE,
127910 sqlite3ExprAddCollateString(pParse,pNewExpr1,zCollSeqName),
127911 pStr1);
127912 transferJoinMarkings(pNewExpr1, pExpr);
127913 idxNew1 = whereClauseInsert(pWC, pNewExpr1, wtFlags);
127914 testcase( idxNew1==0 );
127915 exprAnalyze(pSrc, pWC, idxNew1);
127916 pNewExpr2 = sqlite3ExprDup(db, pLeft, 0);
127917 pNewExpr2 = sqlite3PExpr(pParse, TK_LT,
127918 sqlite3ExprAddCollateString(pParse,pNewExpr2,zCollSeqName),
127919 pStr2);
127920 transferJoinMarkings(pNewExpr2, pExpr);
127921 idxNew2 = whereClauseInsert(pWC, pNewExpr2, wtFlags);
127922 testcase( idxNew2==0 );
127923 exprAnalyze(pSrc, pWC, idxNew2);
127924 pTerm = &pWC->a[idxTerm];
@@ -127665,11 +127947,11 @@
127947 prereqExpr = sqlite3WhereExprUsage(pMaskSet, pRight);
127948 prereqColumn = sqlite3WhereExprUsage(pMaskSet, pLeft);
127949 if( (prereqExpr & prereqColumn)==0 ){
127950 Expr *pNewExpr;
127951 pNewExpr = sqlite3PExpr(pParse, TK_MATCH,
127952 0, sqlite3ExprDup(db, pRight, 0));
127953 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
127954 testcase( idxNew==0 );
127955 pNewTerm = &pWC->a[idxNew];
127956 pNewTerm->prereqRight = prereqExpr;
127957 pNewTerm->leftCursor = pLeft->iTable;
@@ -127704,11 +127986,11 @@
127986 int idxNew;
127987 Expr *pNew;
127988 Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i);
127989 Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i);
127990
127991 pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight);
127992 transferJoinMarkings(pNew, pExpr);
127993 idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC);
127994 exprAnalyze(pSrc, pWC, idxNew);
127995 }
127996 pTerm = &pWC->a[idxTerm];
@@ -127756,11 +128038,11 @@
128038 int idxNew;
128039 WhereTerm *pNewTerm;
128040
128041 pNewExpr = sqlite3PExpr(pParse, TK_GT,
128042 sqlite3ExprDup(db, pLeft, 0),
128043 sqlite3ExprAlloc(db, TK_NULL, 0, 0));
128044
128045 idxNew = whereClauseInsert(pWC, pNewExpr,
128046 TERM_VIRTUAL|TERM_DYNAMIC|TERM_VNULL);
128047 if( idxNew ){
128048 pNewTerm = &pWC->a[idxNew];
@@ -127942,11 +128224,11 @@
128224 if( pColRef==0 ) return;
128225 pColRef->iTable = pItem->iCursor;
128226 pColRef->iColumn = k++;
128227 pColRef->pTab = pTab;
128228 pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef,
128229 sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0));
128230 whereClauseInsert(pWC, pTerm, TERM_DYNAMIC);
128231 }
128232 }
128233
128234 /************** End of whereexpr.c *******************************************/
@@ -133067,20 +133349,20 @@
133349 Parse *pParse, /* The parsing context. Errors accumulate here */
133350 int op, /* The binary operation */
133351 ExprSpan *pLeft, /* The left operand, and output */
133352 ExprSpan *pRight /* The right operand */
133353 ){
133354 pLeft->pExpr = sqlite3PExpr(pParse, op, pLeft->pExpr, pRight->pExpr);
133355 pLeft->zEnd = pRight->zEnd;
133356 }
133357
133358 /* If doNot is true, then add a TK_NOT Expr-node wrapper around the
133359 ** outside of *ppExpr.
133360 */
133361 static void exprNot(Parse *pParse, int doNot, ExprSpan *pSpan){
133362 if( doNot ){
133363 pSpan->pExpr = sqlite3PExpr(pParse, TK_NOT, pSpan->pExpr, 0);
133364 }
133365 }
133366
133367 /* Construct an expression node for a unary postfix operator
133368 */
@@ -133088,11 +133370,11 @@
133370 Parse *pParse, /* Parsing context to record errors */
133371 int op, /* The operator */
133372 ExprSpan *pOperand, /* The operand, and output */
133373 Token *pPostOp /* The operand token for setting the span */
133374 ){
133375 pOperand->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0);
133376 pOperand->zEnd = &pPostOp->z[pPostOp->n];
133377 }
133378
133379 /* A routine to convert a binary TK_IS or TK_ISNOT expression into a
133380 ** unary TK_ISNULL or TK_NOTNULL expression. */
@@ -133113,11 +133395,11 @@
133395 int op, /* The operator */
133396 ExprSpan *pOperand, /* The operand */
133397 Token *pPreOp /* The operand token for setting the span */
133398 ){
133399 pOut->zStart = pPreOp->z;
133400 pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0);
133401 pOut->zEnd = pOperand->zEnd;
133402 }
133403
133404 /* Add a single new term to an ExprList that is used to store a
133405 ** list of identifiers. Report an error if the ID list contains
@@ -134706,11 +134988,10 @@
134988 /*
134989 ** The following routine is called if the stack overflows.
134990 */
134991 static void yyStackOverflow(yyParser *yypParser){
134992 sqlite3ParserARG_FETCH;
 
134993 #ifndef NDEBUG
134994 if( yyTraceFILE ){
134995 fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
134996 }
134997 #endif
@@ -134761,16 +135042,18 @@
135042 assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
135043 }
135044 #endif
135045 #if YYSTACKDEPTH>0
135046 if( yypParser->yytos>=&yypParser->yystack[YYSTACKDEPTH] ){
135047 yypParser->yytos--;
135048 yyStackOverflow(yypParser);
135049 return;
135050 }
135051 #else
135052 if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
135053 if( yyGrowStack(yypParser) ){
135054 yypParser->yytos--;
135055 yyStackOverflow(yypParser);
135056 return;
135057 }
135058 }
135059 #endif
@@ -135308,11 +135591,11 @@
135591 {sqlite3AddDefaultValue(pParse,&yymsp[-1].minor.yy190);}
135592 break;
135593 case 33: /* ccons ::= DEFAULT MINUS term */
135594 {
135595 ExprSpan v;
135596 v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy190.pExpr, 0);
135597 v.zStart = yymsp[-1].minor.yy0.z;
135598 v.zEnd = yymsp[0].minor.yy190.zEnd;
135599 sqlite3AddDefaultValue(pParse,&v);
135600 }
135601 break;
@@ -135572,13 +135855,13 @@
135855 yymsp[-1].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy148, p);
135856 }
135857 break;
135858 case 94: /* selcollist ::= sclp nm DOT STAR */
135859 {
135860 Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
135861 Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
135862 Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
135863 yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148, pDot);
135864 }
135865 break;
135866 case 95: /* as ::= AS nm */
135867 case 106: /* dbnm ::= DOT nm */ yytestcase(yyruleno==106);
@@ -135800,21 +136083,21 @@
136083 case 154: /* expr ::= nm DOT nm */
136084 {
136085 Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
136086 Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
136087 spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
136088 yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
136089 }
136090 break;
136091 case 155: /* expr ::= nm DOT nm DOT nm */
136092 {
136093 Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-4].minor.yy0, 1);
136094 Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
136095 Expr *temp3 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
136096 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
136097 spanSet(&yymsp[-4].minor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
136098 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
136099 }
136100 break;
136101 case 158: /* term ::= INTEGER */
136102 {
136103 yylhsminor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
@@ -135839,11 +136122,11 @@
136122 spanSet(&yymsp[0].minor.yy190, &t, &t);
136123 if( pParse->nested==0 ){
136124 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t);
136125 yymsp[0].minor.yy190.pExpr = 0;
136126 }else{
136127 yymsp[0].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0);
136128 if( yymsp[0].minor.yy190.pExpr ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy190.pExpr->iTable);
136129 }
136130 }
136131 }
136132 break;
@@ -135854,11 +136137,12 @@
136137 }
136138 break;
136139 case 161: /* expr ::= CAST LP expr AS typetoken RP */
136140 {
136141 spanSet(&yymsp[-5].minor.yy190,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
136142 yymsp[-5].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_CAST, &yymsp[-1].minor.yy0, 1);
136143 sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy190.pExpr, yymsp[-3].minor.yy190.pExpr, 0);
136144 }
136145 break;
136146 case 162: /* expr ::= ID|INDEXED LP distinct exprlist RP */
136147 {
136148 if( yymsp[-1].minor.yy148 && yymsp[-1].minor.yy148->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
@@ -135887,11 +136171,11 @@
136171 yymsp[0].minor.yy190 = yylhsminor.yy190;
136172 break;
136173 case 165: /* expr ::= LP nexprlist COMMA expr RP */
136174 {
136175 ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy148, yymsp[-1].minor.yy190.pExpr);
136176 yylhsminor.yy190.pExpr = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
136177 if( yylhsminor.yy190.pExpr ){
136178 yylhsminor.yy190.pExpr->x.pList = pList;
136179 spanSet(&yylhsminor.yy190, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0);
136180 }else{
136181 sqlite3ExprListDelete(pParse->db, pList);
@@ -135976,11 +136260,11 @@
136260 break;
136261 case 188: /* expr ::= expr between_op expr AND expr */
136262 {
136263 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr);
136264 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy190.pExpr);
136265 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy190.pExpr, 0);
136266 if( yymsp[-4].minor.yy190.pExpr ){
136267 yymsp[-4].minor.yy190.pExpr->x.pList = pList;
136268 }else{
136269 sqlite3ExprListDelete(pParse->db, pList);
136270 }
@@ -135998,11 +136282,11 @@
136282 **
136283 ** simplify to constants 0 (false) and 1 (true), respectively,
136284 ** regardless of the value of expr1.
136285 */
136286 sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy190.pExpr);
136287 yymsp[-4].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy194],1);
136288 }else if( yymsp[-1].minor.yy148->nExpr==1 ){
136289 /* Expressions of the form:
136290 **
136291 ** expr1 IN (?1)
136292 ** expr1 NOT IN (?2)
@@ -136025,13 +136309,13 @@
136309 ** before now and control would have never reached this point */
136310 if( ALWAYS(pRHS) ){
136311 pRHS->flags &= ~EP_Collate;
136312 pRHS->flags |= EP_Generic;
136313 }
136314 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, yymsp[-3].minor.yy194 ? TK_NE : TK_EQ, yymsp[-4].minor.yy190.pExpr, pRHS);
136315 }else{
136316 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
136317 if( yymsp[-4].minor.yy190.pExpr ){
136318 yymsp[-4].minor.yy190.pExpr->x.pList = yymsp[-1].minor.yy148;
136319 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy190.pExpr);
136320 }else{
136321 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy148);
@@ -136042,17 +136326,17 @@
136326 }
136327 break;
136328 case 192: /* expr ::= LP select RP */
136329 {
136330 spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
136331 yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
136332 sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy190.pExpr, yymsp[-1].minor.yy243);
136333 }
136334 break;
136335 case 193: /* expr ::= expr in_op LP select RP */
136336 {
136337 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
136338 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, yymsp[-1].minor.yy243);
136339 exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
136340 yymsp[-4].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
136341 }
136342 break;
@@ -136059,28 +136343,28 @@
136343 case 194: /* expr ::= expr in_op nm dbnm paren_exprlist */
136344 {
136345 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
136346 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
136347 if( yymsp[0].minor.yy148 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy148);
136348 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0);
136349 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, pSelect);
136350 exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190);
136351 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];
136352 }
136353 break;
136354 case 195: /* expr ::= EXISTS LP select RP */
136355 {
136356 Expr *p;
136357 spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
136358 p = yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
136359 sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy243);
136360 }
136361 break;
136362 case 196: /* expr ::= CASE case_operand case_exprlist case_else END */
136363 {
136364 spanSet(&yymsp[-4].minor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-C*/
136365 yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy72, 0);
136366 if( yymsp[-4].minor.yy190.pExpr ){
136367 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;
136368 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy190.pExpr);
136369 }else{
136370 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy148);
@@ -136250,20 +136534,20 @@
136534 {yymsp[0].minor.yy145 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy243); /*A-overwrites-X*/}
136535 break;
136536 case 247: /* expr ::= RAISE LP IGNORE RP */
136537 {
136538 spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
136539 yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
136540 if( yymsp[-3].minor.yy190.pExpr ){
136541 yymsp[-3].minor.yy190.pExpr->affinity = OE_Ignore;
136542 }
136543 }
136544 break;
136545 case 248: /* expr ::= RAISE LP raisetype COMMA nm RP */
136546 {
136547 spanSet(&yymsp[-5].minor.yy190,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/
136548 yymsp[-5].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
136549 if( yymsp[-5].minor.yy190.pExpr ) {
136550 yymsp[-5].minor.yy190.pExpr->affinity = (char)yymsp[-3].minor.yy194;
136551 }
136552 }
136553 break;
@@ -141491,11 +141775,11 @@
141775 /*
141776 ** Interface to the testing logic.
141777 */
141778 SQLITE_API int sqlite3_test_control(int op, ...){
141779 int rc = 0;
141780 #ifdef SQLITE_UNTESTABLE
141781 UNUSED_PARAMETER(op);
141782 #else
141783 va_list ap;
141784 va_start(ap, op);
141785 switch( op ){
@@ -141828,11 +142112,11 @@
142112 sqlite3_mutex_leave(db->mutex);
142113 break;
142114 }
142115 }
142116 va_end(ap);
142117 #endif /* SQLITE_UNTESTABLE */
142118 return rc;
142119 }
142120
142121 /*
142122 ** This is a utility routine, useful to VFS implementations, that checks
@@ -141939,26 +142223,27 @@
142223 const char *zDb,
142224 sqlite3_snapshot **ppSnapshot
142225 ){
142226 int rc = SQLITE_ERROR;
142227 #ifndef SQLITE_OMIT_WAL
 
142228
142229 #ifdef SQLITE_ENABLE_API_ARMOR
142230 if( !sqlite3SafetyCheckOk(db) ){
142231 return SQLITE_MISUSE_BKPT;
142232 }
142233 #endif
142234 sqlite3_mutex_enter(db->mutex);
142235
142236 if( db->autoCommit==0 ){
142237 int iDb = sqlite3FindDbName(db, zDb);
142238 if( iDb==0 || iDb>1 ){
142239 Btree *pBt = db->aDb[iDb].pBt;
142240 if( 0==sqlite3BtreeIsInTrans(pBt) ){
142241 rc = sqlite3BtreeBeginTrans(pBt, 0);
142242 if( rc==SQLITE_OK ){
142243 rc = sqlite3PagerSnapshotGet(sqlite3BtreePager(pBt), ppSnapshot);
142244 }
142245 }
142246 }
142247 }
142248
142249 sqlite3_mutex_leave(db->mutex);
@@ -141996,10 +142281,42 @@
142281 }
142282 }
142283 }
142284 }
142285
142286 sqlite3_mutex_leave(db->mutex);
142287 #endif /* SQLITE_OMIT_WAL */
142288 return rc;
142289 }
142290
142291 /*
142292 ** Recover as many snapshots as possible from the wal file associated with
142293 ** schema zDb of database db.
142294 */
142295 SQLITE_API int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb){
142296 int rc = SQLITE_ERROR;
142297 int iDb;
142298 #ifndef SQLITE_OMIT_WAL
142299
142300 #ifdef SQLITE_ENABLE_API_ARMOR
142301 if( !sqlite3SafetyCheckOk(db) ){
142302 return SQLITE_MISUSE_BKPT;
142303 }
142304 #endif
142305
142306 sqlite3_mutex_enter(db->mutex);
142307 iDb = sqlite3FindDbName(db, zDb);
142308 if( iDb==0 || iDb>1 ){
142309 Btree *pBt = db->aDb[iDb].pBt;
142310 if( 0==sqlite3BtreeIsInReadTrans(pBt) ){
142311 rc = sqlite3BtreeBeginTrans(pBt, 0);
142312 if( rc==SQLITE_OK ){
142313 rc = sqlite3PagerSnapshotRecover(sqlite3BtreePager(pBt));
142314 sqlite3BtreeCommit(pBt);
142315 }
142316 }
142317 }
142318 sqlite3_mutex_leave(db->mutex);
142319 #endif /* SQLITE_OMIT_WAL */
142320 return rc;
142321 }
142322
@@ -180834,11 +181151,10 @@
181151 /*
181152 ** The following routine is called if the stack overflows.
181153 */
181154 static void fts5yyStackOverflow(fts5yyParser *fts5yypParser){
181155 sqlite3Fts5ParserARG_FETCH;
 
181156 #ifndef NDEBUG
181157 if( fts5yyTraceFILE ){
181158 fprintf(fts5yyTraceFILE,"%sStack Overflow!\n",fts5yyTracePrompt);
181159 }
181160 #endif
@@ -180889,16 +181205,18 @@
181205 assert( fts5yypParser->fts5yyhwm == (int)(fts5yypParser->fts5yytos - fts5yypParser->fts5yystack) );
181206 }
181207 #endif
181208 #if fts5YYSTACKDEPTH>0
181209 if( fts5yypParser->fts5yytos>=&fts5yypParser->fts5yystack[fts5YYSTACKDEPTH] ){
181210 fts5yypParser->fts5yytos--;
181211 fts5yyStackOverflow(fts5yypParser);
181212 return;
181213 }
181214 #else
181215 if( fts5yypParser->fts5yytos>=&fts5yypParser->fts5yystack[fts5yypParser->fts5yystksz] ){
181216 if( fts5yyGrowStack(fts5yypParser) ){
181217 fts5yypParser->fts5yytos--;
181218 fts5yyStackOverflow(fts5yypParser);
181219 return;
181220 }
181221 }
181222 #endif
@@ -184206,52 +184524,65 @@
184524
184525 /*
184526 ** Initialize all term iterators in the pNear object. If any term is found
184527 ** to match no documents at all, return immediately without initializing any
184528 ** further iterators.
184529 **
184530 ** If an error occurs, return an SQLite error code. Otherwise, return
184531 ** SQLITE_OK. It is not considered an error if some term matches zero
184532 ** documents.
184533 */
184534 static int fts5ExprNearInitAll(
184535 Fts5Expr *pExpr,
184536 Fts5ExprNode *pNode
184537 ){
184538 Fts5ExprNearset *pNear = pNode->pNear;
184539 int i;
 
 
184540
184541 assert( pNode->bNomatch==0 );
184542 for(i=0; i<pNear->nPhrase; i++){
184543 Fts5ExprPhrase *pPhrase = pNear->apPhrase[i];
184544 if( pPhrase->nTerm==0 ){
184545 pNode->bEof = 1;
184546 return SQLITE_OK;
184547 }else{
184548 int j;
184549 for(j=0; j<pPhrase->nTerm; j++){
184550 Fts5ExprTerm *pTerm = &pPhrase->aTerm[j];
184551 Fts5ExprTerm *p;
184552 int bHit = 0;
184553
184554 for(p=pTerm; p; p=p->pSynonym){
184555 int rc;
184556 if( p->pIter ){
184557 sqlite3Fts5IterClose(p->pIter);
184558 p->pIter = 0;
184559 }
184560 rc = sqlite3Fts5IndexQuery(
184561 pExpr->pIndex, p->zTerm, (int)strlen(p->zTerm),
184562 (pTerm->bPrefix ? FTS5INDEX_QUERY_PREFIX : 0) |
184563 (pExpr->bDesc ? FTS5INDEX_QUERY_DESC : 0),
184564 pNear->pColset,
184565 &p->pIter
184566 );
184567 assert( (rc==SQLITE_OK)==(p->pIter!=0) );
184568 if( rc!=SQLITE_OK ) return rc;
184569 if( 0==sqlite3Fts5IterEof(p->pIter) ){
184570 bHit = 1;
184571 }
184572 }
184573
184574 if( bHit==0 ){
184575 pNode->bEof = 1;
184576 return SQLITE_OK;
184577 }
184578 }
184579 }
184580 }
184581
184582 pNode->bEof = 0;
184583 return SQLITE_OK;
184584 }
184585
184586 /*
184587 ** If pExpr is an ASC iterator, this function returns a value with the
184588 ** same sign as:
@@ -195785,11 +196116,11 @@
196116 int nArg, /* Number of args */
196117 sqlite3_value **apUnused /* Function arguments */
196118 ){
196119 assert( nArg==0 );
196120 UNUSED_PARAM2(nArg, apUnused);
196121 sqlite3_result_text(pCtx, "fts5: 2016-12-08 19:04:36 b26df26e184ec6da4b5537526c10f42a293d09b5", -1, SQLITE_TRANSIENT);
196122 }
196123
196124 static int fts5Init(sqlite3 *db){
196125 static const sqlite3_module fts5Mod = {
196126 /* iVersion */ 2,
196127
+57 -6
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,11 +121,11 @@
121121
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122122
** [sqlite_version()] and [sqlite_source_id()].
123123
*/
124124
#define SQLITE_VERSION "3.16.0"
125125
#define SQLITE_VERSION_NUMBER 3016000
126
-#define SQLITE_SOURCE_ID "2016-11-22 20:29:05 bee2859b953c935c413de2917588159d03c672d9"
126
+#define SQLITE_SOURCE_ID "2016-12-08 19:04:36 b26df26e184ec6da4b5537526c10f42a293d09b5"
127127
128128
/*
129129
** CAPI3REF: Run-Time Library Version Numbers
130130
** KEYWORDS: sqlite3_version sqlite3_sourceid
131131
**
@@ -3608,10 +3608,14 @@
36083608
** rather they control the timing of when other statements modify the
36093609
** database. ^The [ATTACH] and [DETACH] statements also cause
36103610
** sqlite3_stmt_readonly() to return true since, while those statements
36113611
** change the configuration of a database connection, they do not make
36123612
** changes to the content of the database files on disk.
3613
+** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
3614
+** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
3615
+** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
3616
+** sqlite3_stmt_readonly() returns false for those commands.
36133617
*/
36143618
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
36153619
36163620
/*
36173621
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
@@ -8257,11 +8261,11 @@
82578261
*/
82588262
SQLITE_API int sqlite3_system_errno(sqlite3*);
82598263
82608264
/*
82618265
** CAPI3REF: Database Snapshot
8262
-** KEYWORDS: {snapshot}
8266
+** KEYWORDS: {snapshot} {sqlite3_snapshot}
82638267
** EXPERIMENTAL
82648268
**
82658269
** An instance of the snapshot object records the state of a [WAL mode]
82668270
** database for some specific point in history.
82678271
**
@@ -8281,11 +8285,13 @@
82818285
** The constructor for this object is [sqlite3_snapshot_get()]. The
82828286
** [sqlite3_snapshot_open()] method causes a fresh read transaction to refer
82838287
** to an historical snapshot (if possible). The destructor for
82848288
** sqlite3_snapshot objects is [sqlite3_snapshot_free()].
82858289
*/
8286
-typedef struct sqlite3_snapshot sqlite3_snapshot;
8290
+typedef struct sqlite3_snapshot {
8291
+ unsigned char hidden[48];
8292
+} sqlite3_snapshot;
82878293
82888294
/*
82898295
** CAPI3REF: Record A Database Snapshot
82908296
** EXPERIMENTAL
82918297
**
@@ -8292,13 +8298,36 @@
82928298
** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a
82938299
** new [sqlite3_snapshot] object that records the current state of
82948300
** schema S in database connection D. ^On success, the
82958301
** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly
82968302
** created [sqlite3_snapshot] object into *P and returns SQLITE_OK.
8297
-** ^If schema S of [database connection] D is not a [WAL mode] database
8298
-** that is in a read transaction, then [sqlite3_snapshot_get(D,S,P)]
8299
-** leaves the *P value unchanged and returns an appropriate [error code].
8303
+** If there is not already a read-transaction open on schema S when
8304
+** this function is called, one is opened automatically.
8305
+**
8306
+** The following must be true for this function to succeed. If any of
8307
+** the following statements are false when sqlite3_snapshot_get() is
8308
+** called, SQLITE_ERROR is returned. The final value of *P is undefined
8309
+** in this case.
8310
+**
8311
+** <ul>
8312
+** <li> The database handle must be in [autocommit mode].
8313
+**
8314
+** <li> Schema S of [database connection] D must be a [WAL mode] database.
8315
+**
8316
+** <li> There must not be a write transaction open on schema S of database
8317
+** connection D.
8318
+**
8319
+** <li> One or more transactions must have been written to the current wal
8320
+** file since it was created on disk (by any connection). This means
8321
+** that a snapshot cannot be taken on a wal mode database with no wal
8322
+** file immediately after it is first opened. At least one transaction
8323
+** must be written to it first.
8324
+** </ul>
8325
+**
8326
+** This function may also return SQLITE_NOMEM. If it is called with the
8327
+** database handle in autocommit mode but fails for some other reason,
8328
+** whether or not a read transaction is opened on schema S is undefined.
83008329
**
83018330
** The [sqlite3_snapshot] object returned from a successful call to
83028331
** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()]
83038332
** to avoid a memory leak.
83048333
**
@@ -8387,10 +8416,32 @@
83878416
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(
83888417
sqlite3_snapshot *p1,
83898418
sqlite3_snapshot *p2
83908419
);
83918420
8421
+/*
8422
+** CAPI3REF: Recover snapshots from a wal file
8423
+** EXPERIMENTAL
8424
+**
8425
+** If all connections disconnect from a database file but do not perform
8426
+** a checkpoint, the existing wal file is opened along with the database
8427
+** file the next time the database is opened. At this point it is only
8428
+** possible to successfully call sqlite3_snapshot_open() to open the most
8429
+** recent snapshot of the database (the one at the head of the wal file),
8430
+** even though the wal file may contain other valid snapshots for which
8431
+** clients have sqlite3_snapshot handles.
8432
+**
8433
+** This function attempts to scan the wal file associated with database zDb
8434
+** of database handle db and make all valid snapshots available to
8435
+** sqlite3_snapshot_open(). It is an error if there is already a read
8436
+** transaction open on the database, or if the database is not a wal mode
8437
+** database.
8438
+**
8439
+** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
8440
+*/
8441
+SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
8442
+
83928443
/*
83938444
** Undo the hack that converts floating point types to integer for
83948445
** builds on processors without floating point support.
83958446
*/
83968447
#ifdef SQLITE_OMIT_FLOATING_POINT
83978448
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,11 +121,11 @@
121 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122 ** [sqlite_version()] and [sqlite_source_id()].
123 */
124 #define SQLITE_VERSION "3.16.0"
125 #define SQLITE_VERSION_NUMBER 3016000
126 #define SQLITE_SOURCE_ID "2016-11-22 20:29:05 bee2859b953c935c413de2917588159d03c672d9"
127
128 /*
129 ** CAPI3REF: Run-Time Library Version Numbers
130 ** KEYWORDS: sqlite3_version sqlite3_sourceid
131 **
@@ -3608,10 +3608,14 @@
3608 ** rather they control the timing of when other statements modify the
3609 ** database. ^The [ATTACH] and [DETACH] statements also cause
3610 ** sqlite3_stmt_readonly() to return true since, while those statements
3611 ** change the configuration of a database connection, they do not make
3612 ** changes to the content of the database files on disk.
 
 
 
 
3613 */
3614 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3615
3616 /*
3617 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
@@ -8257,11 +8261,11 @@
8257 */
8258 SQLITE_API int sqlite3_system_errno(sqlite3*);
8259
8260 /*
8261 ** CAPI3REF: Database Snapshot
8262 ** KEYWORDS: {snapshot}
8263 ** EXPERIMENTAL
8264 **
8265 ** An instance of the snapshot object records the state of a [WAL mode]
8266 ** database for some specific point in history.
8267 **
@@ -8281,11 +8285,13 @@
8281 ** The constructor for this object is [sqlite3_snapshot_get()]. The
8282 ** [sqlite3_snapshot_open()] method causes a fresh read transaction to refer
8283 ** to an historical snapshot (if possible). The destructor for
8284 ** sqlite3_snapshot objects is [sqlite3_snapshot_free()].
8285 */
8286 typedef struct sqlite3_snapshot sqlite3_snapshot;
 
 
8287
8288 /*
8289 ** CAPI3REF: Record A Database Snapshot
8290 ** EXPERIMENTAL
8291 **
@@ -8292,13 +8298,36 @@
8292 ** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a
8293 ** new [sqlite3_snapshot] object that records the current state of
8294 ** schema S in database connection D. ^On success, the
8295 ** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly
8296 ** created [sqlite3_snapshot] object into *P and returns SQLITE_OK.
8297 ** ^If schema S of [database connection] D is not a [WAL mode] database
8298 ** that is in a read transaction, then [sqlite3_snapshot_get(D,S,P)]
8299 ** leaves the *P value unchanged and returns an appropriate [error code].
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8300 **
8301 ** The [sqlite3_snapshot] object returned from a successful call to
8302 ** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()]
8303 ** to avoid a memory leak.
8304 **
@@ -8387,10 +8416,32 @@
8387 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(
8388 sqlite3_snapshot *p1,
8389 sqlite3_snapshot *p2
8390 );
8391
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8392 /*
8393 ** Undo the hack that converts floating point types to integer for
8394 ** builds on processors without floating point support.
8395 */
8396 #ifdef SQLITE_OMIT_FLOATING_POINT
8397
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,11 +121,11 @@
121 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122 ** [sqlite_version()] and [sqlite_source_id()].
123 */
124 #define SQLITE_VERSION "3.16.0"
125 #define SQLITE_VERSION_NUMBER 3016000
126 #define SQLITE_SOURCE_ID "2016-12-08 19:04:36 b26df26e184ec6da4b5537526c10f42a293d09b5"
127
128 /*
129 ** CAPI3REF: Run-Time Library Version Numbers
130 ** KEYWORDS: sqlite3_version sqlite3_sourceid
131 **
@@ -3608,10 +3608,14 @@
3608 ** rather they control the timing of when other statements modify the
3609 ** database. ^The [ATTACH] and [DETACH] statements also cause
3610 ** sqlite3_stmt_readonly() to return true since, while those statements
3611 ** change the configuration of a database connection, they do not make
3612 ** changes to the content of the database files on disk.
3613 ** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
3614 ** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
3615 ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
3616 ** sqlite3_stmt_readonly() returns false for those commands.
3617 */
3618 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3619
3620 /*
3621 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
@@ -8257,11 +8261,11 @@
8261 */
8262 SQLITE_API int sqlite3_system_errno(sqlite3*);
8263
8264 /*
8265 ** CAPI3REF: Database Snapshot
8266 ** KEYWORDS: {snapshot} {sqlite3_snapshot}
8267 ** EXPERIMENTAL
8268 **
8269 ** An instance of the snapshot object records the state of a [WAL mode]
8270 ** database for some specific point in history.
8271 **
@@ -8281,11 +8285,13 @@
8285 ** The constructor for this object is [sqlite3_snapshot_get()]. The
8286 ** [sqlite3_snapshot_open()] method causes a fresh read transaction to refer
8287 ** to an historical snapshot (if possible). The destructor for
8288 ** sqlite3_snapshot objects is [sqlite3_snapshot_free()].
8289 */
8290 typedef struct sqlite3_snapshot {
8291 unsigned char hidden[48];
8292 } sqlite3_snapshot;
8293
8294 /*
8295 ** CAPI3REF: Record A Database Snapshot
8296 ** EXPERIMENTAL
8297 **
@@ -8292,13 +8298,36 @@
8298 ** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a
8299 ** new [sqlite3_snapshot] object that records the current state of
8300 ** schema S in database connection D. ^On success, the
8301 ** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly
8302 ** created [sqlite3_snapshot] object into *P and returns SQLITE_OK.
8303 ** If there is not already a read-transaction open on schema S when
8304 ** this function is called, one is opened automatically.
8305 **
8306 ** The following must be true for this function to succeed. If any of
8307 ** the following statements are false when sqlite3_snapshot_get() is
8308 ** called, SQLITE_ERROR is returned. The final value of *P is undefined
8309 ** in this case.
8310 **
8311 ** <ul>
8312 ** <li> The database handle must be in [autocommit mode].
8313 **
8314 ** <li> Schema S of [database connection] D must be a [WAL mode] database.
8315 **
8316 ** <li> There must not be a write transaction open on schema S of database
8317 ** connection D.
8318 **
8319 ** <li> One or more transactions must have been written to the current wal
8320 ** file since it was created on disk (by any connection). This means
8321 ** that a snapshot cannot be taken on a wal mode database with no wal
8322 ** file immediately after it is first opened. At least one transaction
8323 ** must be written to it first.
8324 ** </ul>
8325 **
8326 ** This function may also return SQLITE_NOMEM. If it is called with the
8327 ** database handle in autocommit mode but fails for some other reason,
8328 ** whether or not a read transaction is opened on schema S is undefined.
8329 **
8330 ** The [sqlite3_snapshot] object returned from a successful call to
8331 ** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()]
8332 ** to avoid a memory leak.
8333 **
@@ -8387,10 +8416,32 @@
8416 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(
8417 sqlite3_snapshot *p1,
8418 sqlite3_snapshot *p2
8419 );
8420
8421 /*
8422 ** CAPI3REF: Recover snapshots from a wal file
8423 ** EXPERIMENTAL
8424 **
8425 ** If all connections disconnect from a database file but do not perform
8426 ** a checkpoint, the existing wal file is opened along with the database
8427 ** file the next time the database is opened. At this point it is only
8428 ** possible to successfully call sqlite3_snapshot_open() to open the most
8429 ** recent snapshot of the database (the one at the head of the wal file),
8430 ** even though the wal file may contain other valid snapshots for which
8431 ** clients have sqlite3_snapshot handles.
8432 **
8433 ** This function attempts to scan the wal file associated with database zDb
8434 ** of database handle db and make all valid snapshots available to
8435 ** sqlite3_snapshot_open(). It is an error if there is already a read
8436 ** transaction open on the database, or if the database is not a wal mode
8437 ** database.
8438 **
8439 ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
8440 */
8441 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
8442
8443 /*
8444 ** Undo the hack that converts floating point types to integer for
8445 ** builds on processors without floating point support.
8446 */
8447 #ifdef SQLITE_OMIT_FLOATING_POINT
8448

Keyboard Shortcuts

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