Fossil SCM

Update the built-in SQLite to the latest 3.36.0 prototype.

drh 2021-04-28 19:01 trunk
Commit d3d7a78fe384522e5a67f07e1a1dbcc043f5b7961a9720748f918cf0d94311af
3 files changed +38 -30 +597 -236 +58 -1
+38 -30
--- src/shell.c
+++ src/shell.c
@@ -5918,14 +5918,28 @@
59185918
59195919
#ifndef SQLITE_OMIT_VIRTUALTABLE
59205920
59215921
#ifndef SQLITE_AMALGAMATION
59225922
5923
+#ifndef UINT32_TYPE
5924
+# ifdef HAVE_UINT32_T
5925
+# define UINT32_TYPE uint32_t
5926
+# else
5927
+# define UINT32_TYPE unsigned int
5928
+# endif
5929
+#endif
5930
+#ifndef UINT16_TYPE
5931
+# ifdef HAVE_UINT16_T
5932
+# define UINT16_TYPE uint16_t
5933
+# else
5934
+# define UINT16_TYPE unsigned short int
5935
+# endif
5936
+#endif
59235937
/* typedef sqlite3_int64 i64; */
59245938
/* typedef unsigned char u8; */
5925
-typedef unsigned short u16;
5926
-typedef unsigned long u32;
5939
+typedef UINT32_TYPE u32; /* 4-byte unsigned integer */
5940
+typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
59275941
#define MIN(a,b) ((a)<(b) ? (a) : (b))
59285942
59295943
#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST)
59305944
# define ALWAYS(X) (1)
59315945
# define NEVER(X) (0)
@@ -6588,38 +6602,28 @@
65886602
** Bits 09-15: years from 1980
65896603
**
65906604
** https://msdn.microsoft.com/en-us/library/9kkf9tah.aspx
65916605
*/
65926606
static u32 zipfileMtime(ZipfileCDS *pCDS){
6593
- int Y = (1980 + ((pCDS->mDate >> 9) & 0x7F));
6594
- int M = ((pCDS->mDate >> 5) & 0x0F);
6595
- int D = (pCDS->mDate & 0x1F);
6596
- int B = -13;
6597
-
6598
- int sec = (pCDS->mTime & 0x1F)*2;
6599
- int min = (pCDS->mTime >> 5) & 0x3F;
6600
- int hr = (pCDS->mTime >> 11) & 0x1F;
6601
- i64 JD;
6602
-
6603
- /* JD = INT(365.25 * (Y+4716)) + INT(30.6001 * (M+1)) + D + B - 1524.5 */
6604
-
6605
- /* Calculate the JD in seconds for noon on the day in question */
6606
- if( M<3 ){
6607
- Y = Y-1;
6608
- M = M+12;
6609
- }
6610
- JD = (i64)(24*60*60) * (
6611
- (int)(365.25 * (Y + 4716))
6612
- + (int)(30.6001 * (M + 1))
6613
- + D + B - 1524
6614
- );
6615
-
6616
- /* Correct the JD for the time within the day */
6617
- JD += (hr-12) * 3600 + min * 60 + sec;
6618
-
6619
- /* Convert JD to unix timestamp (the JD epoch is 2440587.5) */
6620
- return (u32)(JD - (i64)(24405875) * 24*60*6);
6607
+ int Y,M,D,X1,X2,A,B,sec,min,hr;
6608
+ i64 JDsec;
6609
+ Y = (1980 + ((pCDS->mDate >> 9) & 0x7F));
6610
+ M = ((pCDS->mDate >> 5) & 0x0F);
6611
+ D = (pCDS->mDate & 0x1F);
6612
+ sec = (pCDS->mTime & 0x1F)*2;
6613
+ min = (pCDS->mTime >> 5) & 0x3F;
6614
+ hr = (pCDS->mTime >> 11) & 0x1F;
6615
+ if( M<=2 ){
6616
+ Y--;
6617
+ M += 12;
6618
+ }
6619
+ X1 = 36525*(Y+4716)/100;
6620
+ X2 = 306001*(M+1)/10000;
6621
+ A = Y/100;
6622
+ B = 2 - A + (A/4);
6623
+ JDsec = (i64)((X1 + X2 + D + B - 1524.5)*86400) + hr*3600 + min*60 + sec;
6624
+ return (u32)(JDsec - (i64)24405875*(i64)8640);
66216625
}
66226626
66236627
/*
66246628
** The opposite of zipfileMtime(). This function populates the mTime and
66256629
** mDate fields of the CDS structure passed as the first argument according
@@ -8052,10 +8056,14 @@
80528056
if( rc==SQLITE_OK ){
80538057
rc = sqlite3_create_function(db, "zipfile", -1, SQLITE_UTF8, 0, 0,
80548058
zipfileStep, zipfileFinal
80558059
);
80568060
}
8061
+ assert( sizeof(i64)==8 );
8062
+ assert( sizeof(u32)==4 );
8063
+ assert( sizeof(u16)==2 );
8064
+ assert( sizeof(u8)==1 );
80578065
return rc;
80588066
}
80598067
#else /* SQLITE_OMIT_VIRTUALTABLE */
80608068
# define zipfileRegister(x) SQLITE_OK
80618069
#endif
80628070
--- src/shell.c
+++ src/shell.c
@@ -5918,14 +5918,28 @@
5918
5919 #ifndef SQLITE_OMIT_VIRTUALTABLE
5920
5921 #ifndef SQLITE_AMALGAMATION
5922
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5923 /* typedef sqlite3_int64 i64; */
5924 /* typedef unsigned char u8; */
5925 typedef unsigned short u16;
5926 typedef unsigned long u32;
5927 #define MIN(a,b) ((a)<(b) ? (a) : (b))
5928
5929 #if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST)
5930 # define ALWAYS(X) (1)
5931 # define NEVER(X) (0)
@@ -6588,38 +6602,28 @@
6588 ** Bits 09-15: years from 1980
6589 **
6590 ** https://msdn.microsoft.com/en-us/library/9kkf9tah.aspx
6591 */
6592 static u32 zipfileMtime(ZipfileCDS *pCDS){
6593 int Y = (1980 + ((pCDS->mDate >> 9) & 0x7F));
6594 int M = ((pCDS->mDate >> 5) & 0x0F);
6595 int D = (pCDS->mDate & 0x1F);
6596 int B = -13;
6597
6598 int sec = (pCDS->mTime & 0x1F)*2;
6599 int min = (pCDS->mTime >> 5) & 0x3F;
6600 int hr = (pCDS->mTime >> 11) & 0x1F;
6601 i64 JD;
6602
6603 /* JD = INT(365.25 * (Y+4716)) + INT(30.6001 * (M+1)) + D + B - 1524.5 */
6604
6605 /* Calculate the JD in seconds for noon on the day in question */
6606 if( M<3 ){
6607 Y = Y-1;
6608 M = M+12;
6609 }
6610 JD = (i64)(24*60*60) * (
6611 (int)(365.25 * (Y + 4716))
6612 + (int)(30.6001 * (M + 1))
6613 + D + B - 1524
6614 );
6615
6616 /* Correct the JD for the time within the day */
6617 JD += (hr-12) * 3600 + min * 60 + sec;
6618
6619 /* Convert JD to unix timestamp (the JD epoch is 2440587.5) */
6620 return (u32)(JD - (i64)(24405875) * 24*60*6);
6621 }
6622
6623 /*
6624 ** The opposite of zipfileMtime(). This function populates the mTime and
6625 ** mDate fields of the CDS structure passed as the first argument according
@@ -8052,10 +8056,14 @@
8052 if( rc==SQLITE_OK ){
8053 rc = sqlite3_create_function(db, "zipfile", -1, SQLITE_UTF8, 0, 0,
8054 zipfileStep, zipfileFinal
8055 );
8056 }
 
 
 
 
8057 return rc;
8058 }
8059 #else /* SQLITE_OMIT_VIRTUALTABLE */
8060 # define zipfileRegister(x) SQLITE_OK
8061 #endif
8062
--- src/shell.c
+++ src/shell.c
@@ -5918,14 +5918,28 @@
5918
5919 #ifndef SQLITE_OMIT_VIRTUALTABLE
5920
5921 #ifndef SQLITE_AMALGAMATION
5922
5923 #ifndef UINT32_TYPE
5924 # ifdef HAVE_UINT32_T
5925 # define UINT32_TYPE uint32_t
5926 # else
5927 # define UINT32_TYPE unsigned int
5928 # endif
5929 #endif
5930 #ifndef UINT16_TYPE
5931 # ifdef HAVE_UINT16_T
5932 # define UINT16_TYPE uint16_t
5933 # else
5934 # define UINT16_TYPE unsigned short int
5935 # endif
5936 #endif
5937 /* typedef sqlite3_int64 i64; */
5938 /* typedef unsigned char u8; */
5939 typedef UINT32_TYPE u32; /* 4-byte unsigned integer */
5940 typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
5941 #define MIN(a,b) ((a)<(b) ? (a) : (b))
5942
5943 #if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST)
5944 # define ALWAYS(X) (1)
5945 # define NEVER(X) (0)
@@ -6588,38 +6602,28 @@
6602 ** Bits 09-15: years from 1980
6603 **
6604 ** https://msdn.microsoft.com/en-us/library/9kkf9tah.aspx
6605 */
6606 static u32 zipfileMtime(ZipfileCDS *pCDS){
6607 int Y,M,D,X1,X2,A,B,sec,min,hr;
6608 i64 JDsec;
6609 Y = (1980 + ((pCDS->mDate >> 9) & 0x7F));
6610 M = ((pCDS->mDate >> 5) & 0x0F);
6611 D = (pCDS->mDate & 0x1F);
6612 sec = (pCDS->mTime & 0x1F)*2;
6613 min = (pCDS->mTime >> 5) & 0x3F;
6614 hr = (pCDS->mTime >> 11) & 0x1F;
6615 if( M<=2 ){
6616 Y--;
6617 M += 12;
6618 }
6619 X1 = 36525*(Y+4716)/100;
6620 X2 = 306001*(M+1)/10000;
6621 A = Y/100;
6622 B = 2 - A + (A/4);
6623 JDsec = (i64)((X1 + X2 + D + B - 1524.5)*86400) + hr*3600 + min*60 + sec;
6624 return (u32)(JDsec - (i64)24405875*(i64)8640);
 
 
 
 
 
 
 
 
 
 
6625 }
6626
6627 /*
6628 ** The opposite of zipfileMtime(). This function populates the mTime and
6629 ** mDate fields of the CDS structure passed as the first argument according
@@ -8052,10 +8056,14 @@
8056 if( rc==SQLITE_OK ){
8057 rc = sqlite3_create_function(db, "zipfile", -1, SQLITE_UTF8, 0, 0,
8058 zipfileStep, zipfileFinal
8059 );
8060 }
8061 assert( sizeof(i64)==8 );
8062 assert( sizeof(u32)==4 );
8063 assert( sizeof(u16)==2 );
8064 assert( sizeof(u8)==1 );
8065 return rc;
8066 }
8067 #else /* SQLITE_OMIT_VIRTUALTABLE */
8068 # define zipfileRegister(x) SQLITE_OK
8069 #endif
8070
+597 -236
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1186,11 +1186,11 @@
11861186
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11871187
** [sqlite_version()] and [sqlite_source_id()].
11881188
*/
11891189
#define SQLITE_VERSION "3.36.0"
11901190
#define SQLITE_VERSION_NUMBER 3036000
1191
-#define SQLITE_SOURCE_ID "2021-04-07 18:17:53 a2ddb89b206c13876d34c5f9e3db41cda72d6eb3fea31ffa8cc6daa1e1580e16"
1191
+#define SQLITE_SOURCE_ID "2021-04-28 17:37:26 65ec39f0f092fe29e1d4e9e96cf07a73d2ef7ce2c41b6f1cd3ab23546ada0e67"
11921192
11931193
/*
11941194
** CAPI3REF: Run-Time Library Version Numbers
11951195
** KEYWORDS: sqlite3_version sqlite3_sourceid
11961196
**
@@ -10607,10 +10607,19 @@
1060710607
** callback was invoked as a result of a direct insert, update, or delete
1060810608
** operation; or 1 for inserts, updates, or deletes invoked by top-level
1060910609
** triggers; or 2 for changes resulting from triggers called by top-level
1061010610
** triggers; and so forth.
1061110611
**
10612
+** When the [sqlite3_blob_write()] API is used to update a blob column,
10613
+** the pre-update hook is invoked with SQLITE_DELETE. This is because the
10614
+** in this case the new values are not available. In this case, when a
10615
+** callback made with op==SQLITE_DELETE is actuall a write using the
10616
+** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
10617
+** the index of the column being written. In other cases, where the
10618
+** pre-update hook is being invoked for some other reason, including a
10619
+** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
10620
+**
1061210621
** See also: [sqlite3_update_hook()]
1061310622
*/
1061410623
#if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
1061510624
SQLITE_API void *sqlite3_preupdate_hook(
1061610625
sqlite3 *db,
@@ -10627,10 +10636,11 @@
1062710636
);
1062810637
SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
1062910638
SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
1063010639
SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
1063110640
SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
10641
+SQLITE_API int sqlite3_preupdate_blobwrite(sqlite3 *);
1063210642
#endif
1063310643
1063410644
/*
1063510645
** CAPI3REF: Low-level system error code
1063610646
** METHOD: sqlite3
@@ -11167,10 +11177,41 @@
1116711177
** are attached is closed. Refer to the documentation for
1116811178
** [sqlite3session_create()] for details.
1116911179
*/
1117011180
SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
1117111181
11182
+/*
11183
+** CAPIREF: Conigure a Session Object
11184
+** METHOD: sqlite3_session
11185
+**
11186
+** This method is used to configure a session object after it has been
11187
+** created. At present the only valid value for the second parameter is
11188
+** [SQLITE_SESSION_OBJCONFIG_SIZE].
11189
+*/
11190
+SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
11191
+
11192
+/*
11193
+** CAPI3REF: Arguments for sqlite3session_object_config()
11194
+**
11195
+** The following values may passed as the the 4th parameter to
11196
+** [sqlite3session_object_config].
11197
+**
11198
+** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
11199
+** This option is used to set, clear or query the flag that enables
11200
+** the [sqlite3session_changeset_size()] API. Because it imposes some
11201
+** computational overhead, this API is disabled by default. Argument
11202
+** pArg must point to a value of type (int). If the value is initially
11203
+** 0, then the sqlite3session_changeset_size() API is disabled. If it
11204
+** is greater than 0, then the same API is enabled. Or, if the initial
11205
+** value is less than zero, no change is made. In all cases the (int)
11206
+** variable is set to 1 if the sqlite3session_changeset_size() API is
11207
+** enabled following the current call, or 0 otherwise.
11208
+**
11209
+** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
11210
+** the first table has been attached to the session object.
11211
+*/
11212
+#define SQLITE_SESSION_OBJCONFIG_SIZE 1
1117211213
1117311214
/*
1117411215
** CAPI3REF: Enable Or Disable A Session Object
1117511216
** METHOD: sqlite3_session
1117611217
**
@@ -11411,10 +11452,26 @@
1141111452
sqlite3_session *pSession, /* Session object */
1141211453
int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
1141311454
void **ppChangeset /* OUT: Buffer containing changeset */
1141411455
);
1141511456
11457
+/*
11458
+** CAPI3REF: Return An Upper-limit For The Size Of The Changeset
11459
+** METHOD: sqlite3session_changeset_size()
11460
+**
11461
+** By default, this function always returns 0. For it to return
11462
+** a useful result, the sqlite3_session object must have been configured
11463
+** to enable this API using [sqlite3session_object_config()] with the
11464
+** SQLITE_SESSION_OBJCONFIG_SIZE verb.
11465
+**
11466
+** When enabled, this function returns an upper limit, in bytes, for the size
11467
+** of the changeset that might be produced if sqlite3session_changeset() were
11468
+** called. The final changeset size might be equal to or smaller than the
11469
+** size in bytes returned by this function.
11470
+*/
11471
+SQLITE_API sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession);
11472
+
1141611473
/*
1141711474
** CAPI3REF: Load The Difference Between Tables Into A Session
1141811475
** METHOD: sqlite3_session
1141911476
**
1142011477
** If it is not already attached to the session object passed as the first
@@ -17724,10 +17781,11 @@
1772417781
#define TF_OOOHidden 0x0400 /* Out-of-Order hidden columns */
1772517782
#define TF_HasNotNull 0x0800 /* Contains NOT NULL constraints */
1772617783
#define TF_Shadow 0x1000 /* True for a shadow table */
1772717784
#define TF_HasStat4 0x2000 /* STAT4 info available for this table */
1772817785
#define TF_Ephemeral 0x4000 /* An ephemeral table */
17786
+#define TF_Eponymous 0x8000 /* An eponymous virtual table */
1772917787
1773017788
/*
1773117789
** Test to see whether or not a table is a virtual table. This is
1773217790
** done as a macro so that it will be optimized out when virtual
1773317791
** table support is omitted from the build.
@@ -18553,11 +18611,11 @@
1855318611
Upsert *pUpsert; /* ON CONFLICT clause information from an upsert */
1855418612
int iBaseReg; /* For TK_REGISTER when parsing RETURNING */
1855518613
} uNC;
1855618614
NameContext *pNext; /* Next outer name context. NULL for outermost */
1855718615
int nRef; /* Number of names resolved by this context */
18558
- int nErr; /* Number of errors encountered while resolving names */
18616
+ int nNcErr; /* Number of errors encountered while resolving names */
1855918617
int ncFlags; /* Zero or more NC_* flags defined below */
1856018618
Select *pWinSelect; /* SELECT statement for any window functions */
1856118619
};
1856218620
1856318621
/*
@@ -18586,10 +18644,11 @@
1858618644
#define NC_AllowWin 0x04000 /* Window functions are allowed here */
1858718645
#define NC_HasWin 0x08000 /* One or more window functions seen */
1858818646
#define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */
1858918647
#define NC_InAggFunc 0x20000 /* True if analyzing arguments to an agg func */
1859018648
#define NC_FromDDL 0x40000 /* SQL text comes from sqlite_schema */
18649
+#define NC_NoSelect 0x80000 /* Do not descend into sub-selects */
1859118650
1859218651
/*
1859318652
** An instance of the following object describes a single ON CONFLICT
1859418653
** clause in an upsert.
1859518654
**
@@ -19367,10 +19426,11 @@
1936719426
SQLITE_PRIVATE int sqlite3ExprWalkNoop(Walker*, Expr*);
1936819427
SQLITE_PRIVATE int sqlite3SelectWalkNoop(Walker*, Select*);
1936919428
SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker*, Select*);
1937019429
SQLITE_PRIVATE int sqlite3WalkerDepthIncrease(Walker*,Select*);
1937119430
SQLITE_PRIVATE void sqlite3WalkerDepthDecrease(Walker*,Select*);
19431
+SQLITE_PRIVATE void sqlite3WalkWinDefnDummyCallback(Walker*,Select*);
1937219432
1937319433
#ifdef SQLITE_DEBUG
1937419434
SQLITE_PRIVATE void sqlite3SelectWalkAssert2(Walker*, Select*);
1937519435
#endif
1937619436
@@ -21500,10 +21560,11 @@
2150021560
u8 *aRecord; /* old.* database record */
2150121561
KeyInfo keyinfo;
2150221562
UnpackedRecord *pUnpacked; /* Unpacked version of aRecord[] */
2150321563
UnpackedRecord *pNewUnpacked; /* Unpacked version of new.* record */
2150421564
int iNewReg; /* Register for new.* values */
21565
+ int iBlobWrite; /* Value returned by preupdate_blobwrite() */
2150521566
i64 iKey1; /* First key value passed to hook */
2150621567
i64 iKey2; /* Second key value passed to hook */
2150721568
Mem *aNew; /* Array of new.* values */
2150821569
Table *pTab; /* Schema object being upated */
2150921570
Index *pPk; /* PK index if pTab is WITHOUT ROWID */
@@ -21588,11 +21649,12 @@
2158821649
#endif
2158921650
SQLITE_PRIVATE void sqlite3VdbeFrameMemDel(void*); /* Destructor on Mem */
2159021651
SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*); /* Actually deletes the Frame */
2159121652
SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
2159221653
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
21593
-SQLITE_PRIVATE void sqlite3VdbePreUpdateHook(Vdbe*,VdbeCursor*,int,const char*,Table*,i64,int);
21654
+SQLITE_PRIVATE void sqlite3VdbePreUpdateHook(
21655
+ Vdbe*,VdbeCursor*,int,const char*,Table*,i64,int,int);
2159421656
#endif
2159521657
SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p);
2159621658
2159721659
SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *, int, VdbeCursor *);
2159821660
SQLITE_PRIVATE void sqlite3VdbeSorterReset(sqlite3 *, VdbeSorter *);
@@ -29932,10 +29994,11 @@
2993229994
for(i=0; i<pSrc->nSrc; i++){
2993329995
const SrcItem *pItem = &pSrc->a[i];
2993429996
StrAccum x;
2993529997
char zLine[100];
2993629998
sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
29999
+ x.printfFlags |= SQLITE_PRINTF_INTERNAL;
2993730000
sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
2993830001
if( pItem->pTab ){
2993930002
sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx",
2994030003
pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed);
2994130004
}
@@ -48518,11 +48581,11 @@
4851848581
return SQLITE_FULL;
4851948582
}
4852048583
newSz *= 2;
4852148584
if( newSz>p->szMax ) newSz = p->szMax;
4852248585
pNew = sqlite3Realloc(p->aData, newSz);
48523
- if( pNew==0 ) return SQLITE_NOMEM;
48586
+ if( pNew==0 ) return SQLITE_IOERR_NOMEM;
4852448587
p->aData = pNew;
4852548588
p->szAlloc = newSz;
4852648589
return SQLITE_OK;
4852748590
}
4852848591
@@ -58067,11 +58130,11 @@
5806758130
5806858131
if( pPager->errCode ) return pPager->errCode;
5806958132
assert( pPager->eState>=PAGER_READER && pPager->eState<PAGER_ERROR );
5807058133
pPager->subjInMemory = (u8)subjInMemory;
5807158134
58072
- if( ALWAYS(pPager->eState==PAGER_READER) ){
58135
+ if( pPager->eState==PAGER_READER ){
5807358136
assert( pPager->pInJournal==0 );
5807458137
5807558138
if( pagerUseWal(pPager) ){
5807658139
/* If the pager is configured to use locking_mode=exclusive, and an
5807758140
** exclusive lock on the database is not already held, obtain it now.
@@ -66488,10 +66551,11 @@
6648866551
unsigned char *data; /* The page data */
6648966552
unsigned char *temp; /* Temp area for cell content */
6649066553
unsigned char *src; /* Source of content */
6649166554
int iCellFirst; /* First allowable cell index */
6649266555
int iCellLast; /* Last possible cell index */
66556
+ int iCellStart; /* First cell offset in input */
6649366557
6649466558
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
6649566559
assert( pPage->pBt!=0 );
6649666560
assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
6649766561
assert( pPage->nOverflow==0 );
@@ -66529,11 +66593,11 @@
6652966593
if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage);
6653066594
sz2 = get2byte(&data[iFree2+2]);
6653166595
if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage);
6653266596
memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
6653366597
sz += sz2;
66534
- }else if( NEVER(iFree+sz>usableSize) ){
66598
+ }else if( iFree+sz>usableSize ){
6653566599
return SQLITE_CORRUPT_PAGE(pPage);
6653666600
}
6653766601
6653866602
cbrk = top+sz;
6653966603
assert( cbrk+(iFree-top) <= usableSize );
@@ -66548,38 +66612,37 @@
6654866612
}
6654966613
}
6655066614
6655166615
cbrk = usableSize;
6655266616
iCellLast = usableSize - 4;
66617
+ iCellStart = get2byte(&data[hdr+5]);
6655366618
for(i=0; i<nCell; i++){
6655466619
u8 *pAddr; /* The i-th cell pointer */
6655566620
pAddr = &data[cellOffset + i*2];
6655666621
pc = get2byte(pAddr);
6655766622
testcase( pc==iCellFirst );
6655866623
testcase( pc==iCellLast );
6655966624
/* These conditions have already been verified in btreeInitPage()
6656066625
** if PRAGMA cell_size_check=ON.
6656166626
*/
66562
- if( pc<iCellFirst || pc>iCellLast ){
66627
+ if( pc<iCellStart || pc>iCellLast ){
6656366628
return SQLITE_CORRUPT_PAGE(pPage);
6656466629
}
66565
- assert( pc>=iCellFirst && pc<=iCellLast );
66630
+ assert( pc>=iCellStart && pc<=iCellLast );
6656666631
size = pPage->xCellSize(pPage, &src[pc]);
6656766632
cbrk -= size;
66568
- if( cbrk<iCellFirst || pc+size>usableSize ){
66633
+ if( cbrk<iCellStart || pc+size>usableSize ){
6656966634
return SQLITE_CORRUPT_PAGE(pPage);
6657066635
}
66571
- assert( cbrk+size<=usableSize && cbrk>=iCellFirst );
66636
+ assert( cbrk+size<=usableSize && cbrk>=iCellStart );
6657266637
testcase( cbrk+size==usableSize );
6657366638
testcase( pc+size==usableSize );
6657466639
put2byte(pAddr, cbrk);
6657566640
if( temp==0 ){
66576
- int x;
6657766641
if( cbrk==pc ) continue;
6657866642
temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
66579
- x = get2byte(&data[hdr+5]);
66580
- memcpy(&temp[x], &data[x], (cbrk+size) - x);
66643
+ memcpy(&temp[iCellStart], &data[iCellStart], (cbrk+size) - iCellStart);
6658166644
src = temp;
6658266645
}
6658366646
memcpy(&data[cbrk], &src[pc], size);
6658466647
}
6658566648
data[hdr+7] = 0;
@@ -72055,11 +72118,11 @@
7205572118
pData = pEnd;
7205672119
while( 1/*exit by break*/ ){
7205772120
u8 *pCell = pCArray->apCell[i];
7205872121
u16 sz = pCArray->szCell[i];
7205972122
assert( sz>0 );
72060
- if( SQLITE_WITHIN(pCell,aData,pEnd) ){
72123
+ if( SQLITE_WITHIN(pCell,aData+j,pEnd) ){
7206172124
if( ((uptr)(pCell+sz))>(uptr)pEnd ) return SQLITE_CORRUPT_BKPT;
7206272125
pCell = &pTmp[pCell - aData];
7206372126
}else if( (uptr)(pCell+sz)>(uptr)pSrcEnd
7206472127
&& (uptr)(pCell)<(uptr)pSrcEnd
7206572128
){
@@ -72068,13 +72131,12 @@
7206872131
7206972132
pData -= sz;
7207072133
put2byte(pCellptr, (pData - aData));
7207172134
pCellptr += 2;
7207272135
if( pData < pCellptr ) return SQLITE_CORRUPT_BKPT;
72073
- memcpy(pData, pCell, sz);
72136
+ memmove(pData, pCell, sz);
7207472137
assert( sz==pPg->xCellSize(pPg, pCell) || CORRUPT_DB );
72075
- testcase( sz!=pPg->xCellSize(pPg,pCell) )
7207672138
i++;
7207772139
if( i>=iEnd ) break;
7207872140
if( pCArray->ixNx[k]<=i ){
7207972141
k++;
7208072142
pSrcEnd = pCArray->apEnd[k];
@@ -72862,11 +72924,11 @@
7286272924
b.apCell[b.nCell] = pTemp+leafCorrection;
7286372925
assert( leafCorrection==0 || leafCorrection==4 );
7286472926
b.szCell[b.nCell] = b.szCell[b.nCell] - leafCorrection;
7286572927
if( !pOld->leaf ){
7286672928
assert( leafCorrection==0 );
72867
- assert( pOld->hdrOffset==0 );
72929
+ assert( pOld->hdrOffset==0 || CORRUPT_DB );
7286872930
/* The right pointer of the child page pOld becomes the left
7286972931
** pointer of the divider cell */
7287072932
memcpy(b.apCell[b.nCell], &pOld->aData[8], 4);
7287172933
}else{
7287272934
assert( leafCorrection==4 );
@@ -73770,10 +73832,18 @@
7377073832
** not to clear the cursor here.
7377173833
*/
7377273834
if( pCur->curFlags & BTCF_Multiple ){
7377373835
rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
7377473836
if( rc ) return rc;
73837
+ if( loc && pCur->iPage<0 ){
73838
+ /* This can only happen if the schema is corrupt such that there is more
73839
+ ** than one table or index with the same root page as used by the cursor.
73840
+ ** Which can only happen if the SQLITE_NoSchemaError flag was set when
73841
+ ** the schema was loaded. This cannot be asserted though, as a user might
73842
+ ** set the flag, load the schema, and then unset the flag. */
73843
+ return SQLITE_CORRUPT_BKPT;
73844
+ }
7377573845
}
7377673846
7377773847
if( pCur->pKeyInfo==0 ){
7377873848
assert( pX->pKey==0 );
7377973849
/* If this is an insert into a table b-tree, invalidate any incrblob
@@ -73857,21 +73927,20 @@
7385773927
x2.nData = pX->nKey;
7385873928
x2.nZero = 0;
7385973929
return btreeOverwriteCell(pCur, &x2);
7386073930
}
7386173931
}
73862
-
7386373932
}
7386473933
assert( pCur->eState==CURSOR_VALID
7386573934
|| (pCur->eState==CURSOR_INVALID && loc)
7386673935
|| CORRUPT_DB );
7386773936
7386873937
pPage = pCur->pPage;
7386973938
assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
7387073939
assert( pPage->leaf || !pPage->intKey );
7387173940
if( pPage->nFree<0 ){
73872
- if( pCur->eState>CURSOR_INVALID ){
73941
+ if( NEVER(pCur->eState>CURSOR_INVALID) ){
7387373942
rc = SQLITE_CORRUPT_BKPT;
7387473943
}else{
7387573944
rc = btreeComputeFreeSpace(pPage);
7387673945
}
7387773946
if( rc ) return rc;
@@ -74148,11 +74217,12 @@
7414874217
assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
7414974218
assert( !hasReadConflicts(p, pCur->pgnoRoot) );
7415074219
assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
7415174220
if( pCur->eState==CURSOR_REQUIRESEEK ){
7415274221
rc = btreeRestoreCursorPosition(pCur);
74153
- if( rc ) return rc;
74222
+ assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID );
74223
+ if( rc || pCur->eState!=CURSOR_VALID ) return rc;
7415474224
}
7415574225
assert( CORRUPT_DB || pCur->eState==CURSOR_VALID );
7415674226
7415774227
iCellDepth = pCur->iPage;
7415874228
iCellIdx = pCur->ix;
@@ -83652,11 +83722,12 @@
8365283722
VdbeCursor *pCsr, /* Cursor to grab old.* values from */
8365383723
int op, /* SQLITE_INSERT, UPDATE or DELETE */
8365483724
const char *zDb, /* Database name */
8365583725
Table *pTab, /* Modified table */
8365683726
i64 iKey1, /* Initial key value */
83657
- int iReg /* Register for new.* record */
83727
+ int iReg, /* Register for new.* record */
83728
+ int iBlobWrite
8365883729
){
8365983730
sqlite3 *db = v->db;
8366083731
i64 iKey2;
8366183732
PreUpdate preupdate;
8366283733
const char *zTbl = pTab->zName;
@@ -83688,10 +83759,11 @@
8368883759
preupdate.keyinfo.nKeyField = pTab->nCol;
8368983760
preupdate.keyinfo.aSortFlags = (u8*)&fakeSortOrder;
8369083761
preupdate.iKey1 = iKey1;
8369183762
preupdate.iKey2 = iKey2;
8369283763
preupdate.pTab = pTab;
83764
+ preupdate.iBlobWrite = iBlobWrite;
8369383765
8369483766
db->pPreUpdate = &preupdate;
8369583767
db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2);
8369683768
db->pPreUpdate = 0;
8369783769
sqlite3DbFree(db, preupdate.aRecord);
@@ -85613,10 +85685,21 @@
8561385685
SQLITE_API int sqlite3_preupdate_depth(sqlite3 *db){
8561485686
PreUpdate *p = db->pPreUpdate;
8561585687
return (p ? p->v->nFrame : 0);
8561685688
}
8561785689
#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
85690
+
85691
+#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
85692
+/*
85693
+** This function is designed to be called from within a pre-update callback
85694
+** only.
85695
+*/
85696
+SQLITE_API int sqlite3_preupdate_blobwrite(sqlite3 *db){
85697
+ PreUpdate *p = db->pPreUpdate;
85698
+ return (p ? p->iBlobWrite : -1);
85699
+}
85700
+#endif
8561885701
8561985702
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
8562085703
/*
8562185704
** This function is called from within a pre-update callback to retrieve
8562285705
** a field of the row currently being updated or inserted.
@@ -86393,11 +86476,14 @@
8639386476
static u16 SQLITE_NOINLINE computeNumericType(Mem *pMem){
8639486477
int rc;
8639586478
sqlite3_int64 ix;
8639686479
assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 );
8639786480
assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
86398
- ExpandBlob(pMem);
86481
+ if( ExpandBlob(pMem) ){
86482
+ pMem->u.i = 0;
86483
+ return MEM_Int;
86484
+ }
8639986485
rc = sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc);
8640086486
if( rc<=0 ){
8640186487
if( rc==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1 ){
8640286488
pMem->u.i = ix;
8640386489
return MEM_Int;
@@ -91126,11 +91212,11 @@
9112691212
9112791213
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
9112891214
/* Invoke the pre-update hook, if any */
9112991215
if( pTab ){
9113091216
if( db->xPreUpdateCallback && !(pOp->p5 & OPFLAG_ISUPDATE) ){
91131
- sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, x.nKey,pOp->p2);
91217
+ sqlite3VdbePreUpdateHook(p,pC,SQLITE_INSERT,zDb,pTab,x.nKey,pOp->p2,-1);
9113291218
}
9113391219
if( db->xUpdateCallback==0 || pTab->aCol==0 ){
9113491220
/* Prevent post-update hook from running in cases when it should not */
9113591221
pTab = 0;
9113691222
}
@@ -91286,11 +91372,11 @@
9128691372
|| (aMem[pOp->p3].flags & MEM_Int)
9128791373
);
9128891374
sqlite3VdbePreUpdateHook(p, pC,
9128991375
(opflags & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_DELETE,
9129091376
zDb, pTab, pC->movetoTarget,
91291
- pOp->p3
91377
+ pOp->p3, -1
9129291378
);
9129391379
}
9129491380
if( opflags & OPFLAG_ISNOOP ) break;
9129591381
#endif
9129691382
@@ -92355,11 +92441,11 @@
9235592441
}
9235692442
#endif
9235792443
9235892444
iDb = pOp->p1;
9235992445
assert( iDb>=0 && iDb<db->nDb );
92360
- assert( DbHasProperty(db, iDb, DB_SchemaLoaded) );
92446
+ assert( DbHasProperty(db, iDb, DB_SchemaLoaded) || db->mallocFailed );
9236192447
9236292448
#ifndef SQLITE_OMIT_ALTERTABLE
9236392449
if( pOp->p4.z==0 ){
9236492450
sqlite3SchemaClear(db->aDb[iDb].pSchema);
9236592451
db->mDbFlags &= ~DBFLAG_SchemaKnownOk;
@@ -94715,11 +94801,11 @@
9471594801
** anyhow.
9471694802
*/
9471794803
sqlite3_int64 iKey;
9471894804
iKey = sqlite3BtreeIntegerKey(p->pCsr);
9471994805
sqlite3VdbePreUpdateHook(
94720
- v, v->apCsr[0], SQLITE_DELETE, p->zDb, p->pTab, iKey, -1
94806
+ v, v->apCsr[0], SQLITE_DELETE, p->zDb, p->pTab, iKey, -1, p->iCol
9472194807
);
9472294808
}
9472394809
#endif
9472494810
9472594811
rc = xCall(p->pCsr, iOffset+p->iOffset, n, z);
@@ -94786,10 +94872,11 @@
9478694872
** already been invalidated. Return SQLITE_ABORT in this case.
9478794873
*/
9478894874
rc = SQLITE_ABORT;
9478994875
}else{
9479094876
char *zErr;
94877
+ ((Vdbe*)p->pStmt)->rc = SQLITE_OK;
9479194878
rc = blobSeekToRow(p, iRow, &zErr);
9479294879
if( rc!=SQLITE_OK ){
9479394880
sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
9479494881
sqlite3DbFree(db, zErr);
9479594882
}
@@ -98468,19 +98555,14 @@
9846898555
if( rc ) return WRC_Abort;
9846998556
rc = sqlite3WalkExprList(pWalker, pWin->pPartition);
9847098557
if( rc ) return WRC_Abort;
9847198558
rc = sqlite3WalkExpr(pWalker, pWin->pFilter);
9847298559
if( rc ) return WRC_Abort;
98473
-
98474
- /* The next two are purely for calls to sqlite3RenameExprUnmap()
98475
- ** within sqlite3WindowOffsetExpr(). Because of constraints imposed
98476
- ** by sqlite3WindowOffsetExpr(), they can never fail. The results do
98477
- ** not matter anyhow. */
9847898560
rc = sqlite3WalkExpr(pWalker, pWin->pStart);
98479
- if( NEVER(rc) ) return WRC_Abort;
98561
+ if( rc ) return WRC_Abort;
9848098562
rc = sqlite3WalkExpr(pWalker, pWin->pEnd);
98481
- if( NEVER(rc) ) return WRC_Abort;
98563
+ if( rc ) return WRC_Abort;
9848298564
if( bOneOnly ) break;
9848398565
}
9848498566
return WRC_Continue;
9848598567
}
9848698568
#endif
@@ -98552,10 +98634,20 @@
9855298634
if( sqlite3WalkExpr(pWalker, pItem->pExpr) ) return WRC_Abort;
9855398635
}
9855498636
}
9855598637
return WRC_Continue;
9855698638
}
98639
+
98640
+/*
98641
+** This is a no-op callback for Walker->xSelectCallback2. If this
98642
+** callback is set, then the Select->pWinDefn list is traversed.
98643
+*/
98644
+SQLITE_PRIVATE void sqlite3WalkWinDefnDummyCallback(Walker *pWalker, Select *p){
98645
+ UNUSED_PARAMETER(pWalker);
98646
+ UNUSED_PARAMETER(p);
98647
+ /* No-op */
98648
+}
9855798649
9855898650
/*
9855998651
** Walk all expressions associated with SELECT statement p. Do
9856098652
** not invoke the SELECT callback on p, but do (of course) invoke
9856198653
** any expr callbacks and SELECT callbacks that come from subqueries.
@@ -98566,14 +98658,16 @@
9856698658
if( sqlite3WalkExpr(pWalker, p->pWhere) ) return WRC_Abort;
9856798659
if( sqlite3WalkExprList(pWalker, p->pGroupBy) ) return WRC_Abort;
9856898660
if( sqlite3WalkExpr(pWalker, p->pHaving) ) return WRC_Abort;
9856998661
if( sqlite3WalkExprList(pWalker, p->pOrderBy) ) return WRC_Abort;
9857098662
if( sqlite3WalkExpr(pWalker, p->pLimit) ) return WRC_Abort;
98571
-#if !defined(SQLITE_OMIT_WINDOWFUNC) && !defined(SQLITE_OMIT_ALTERTABLE)
98572
- {
98573
- Parse *pParse = pWalker->pParse;
98574
- if( pParse && IN_RENAME_OBJECT ){
98663
+#if !defined(SQLITE_OMIT_WINDOWFUNC)
98664
+ if( p->pWinDefn ){
98665
+ Parse *pParse;
98666
+ if( pWalker->xSelectCallback2==sqlite3WalkWinDefnDummyCallback
98667
+ || ((pParse = pWalker->pParse)!=0 && IN_RENAME_OBJECT)
98668
+ ){
9857598669
/* The following may return WRC_Abort if there are unresolvable
9857698670
** symbols (e.g. a table that does not exist) in a window definition. */
9857798671
int rc = walkWindowList(pWalker, p->pWinDefn, 0);
9857898672
return rc;
9857998673
}
@@ -98593,11 +98687,11 @@
9859398687
SrcList *pSrc;
9859498688
int i;
9859598689
SrcItem *pItem;
9859698690
9859798691
pSrc = p->pSrc;
98598
- if( pSrc ){
98692
+ if( ALWAYS(pSrc) ){
9859998693
for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
9860098694
if( pItem->pSelect && sqlite3WalkSelect(pWalker, pItem->pSelect) ){
9860198695
return WRC_Abort;
9860298696
}
9860398697
if( pItem->fg.isTabFunc
@@ -98767,11 +98861,14 @@
9876798861
assert( iCol>=0 && iCol<pEList->nExpr );
9876898862
pOrig = pEList->a[iCol].pExpr;
9876998863
assert( pOrig!=0 );
9877098864
db = pParse->db;
9877198865
pDup = sqlite3ExprDup(db, pOrig, 0);
98772
- if( pDup!=0 ){
98866
+ if( db->mallocFailed ){
98867
+ sqlite3ExprDelete(db, pDup);
98868
+ pDup = 0;
98869
+ }else{
9877398870
incrAggFunctionDepth(pDup, nSubquery);
9877498871
if( pExpr->op==TK_COLLATE ){
9877598872
pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
9877698873
}
9877798874
@@ -98789,14 +98886,12 @@
9878998886
assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 );
9879098887
pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
9879198888
pExpr->flags |= EP_MemToken;
9879298889
}
9879398890
if( ExprHasProperty(pExpr, EP_WinFunc) ){
98794
- if( pExpr->y.pWin!=0 ){
98891
+ if( ALWAYS(pExpr->y.pWin!=0) ){
9879598892
pExpr->y.pWin->pOwner = pExpr;
98796
- }else{
98797
- assert( db->mallocFailed );
9879898893
}
9879998894
}
9880098895
sqlite3DbFree(db, pDup);
9880198896
}
9880298897
}
@@ -99184,12 +99279,12 @@
9918499279
** or HAVING clauses, or as part of a larger expression in the ORDER BY
9918599280
** clause is not standard SQL. This is a (goofy) SQLite extension, that
9918699281
** is supported for backwards compatibility only. Hence, we issue a warning
9918799282
** on sqlite3_log() whenever the capability is used.
9918899283
*/
99189
- if( (pNC->ncFlags & NC_UEList)!=0
99190
- && cnt==0
99284
+ if( cnt==0
99285
+ && (pNC->ncFlags & NC_UEList)!=0
9919199286
&& zTab==0
9919299287
){
9919399288
pEList = pNC->uNC.pEList;
9919499289
assert( pEList!=0 );
9919599290
for(j=0; j<pEList->nExpr; j++){
@@ -99293,11 +99388,11 @@
9929399388
sqlite3ErrorMsg(pParse, "%s: %s.%s", zErr, zTab, zCol);
9929499389
}else{
9929599390
sqlite3ErrorMsg(pParse, "%s: %s", zErr, zCol);
9929699391
}
9929799392
pParse->checkSchema = 1;
99298
- pTopNC->nErr++;
99393
+ pTopNC->nNcErr++;
9929999394
}
9930099395
9930199396
/* If a column from a table in pSrcList is referenced, then record
9930299397
** this fact in the pSrcList.a[].colUsed bitmask. Column 0 causes
9930399398
** bit 0 to be set. Column 1 sets bit 1. And so forth. Bit 63 is
@@ -99600,11 +99695,11 @@
9960099695
pExpr->iTable = exprProbability(pList->a[1].pExpr);
9960199696
if( pExpr->iTable<0 ){
9960299697
sqlite3ErrorMsg(pParse,
9960399698
"second argument to likelihood() must be a "
9960499699
"constant between 0.0 and 1.0");
99605
- pNC->nErr++;
99700
+ pNC->nNcErr++;
9960699701
}
9960799702
}else{
9960899703
/* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is
9960999704
** equivalent to likelihood(X, 0.0625).
9961099705
** EVIDENCE-OF: R-01283-11636 The unlikely(X) function is
@@ -99622,11 +99717,11 @@
9962299717
int auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0,pDef->zName,0);
9962399718
if( auth!=SQLITE_OK ){
9962499719
if( auth==SQLITE_DENY ){
9962599720
sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
9962699721
pDef->zName);
99627
- pNC->nErr++;
99722
+ pNC->nNcErr++;
9962899723
}
9962999724
pExpr->op = TK_NULL;
9963099725
return WRC_Prune;
9963199726
}
9963299727
}
@@ -99678,11 +99773,11 @@
9967899773
);
9967999774
if( pDef && pDef->xValue==0 && pWin ){
9968099775
sqlite3ErrorMsg(pParse,
9968199776
"%.*s() may not be used as a window function", nId, zId
9968299777
);
99683
- pNC->nErr++;
99778
+ pNC->nNcErr++;
9968499779
}else if(
9968599780
(is_agg && (pNC->ncFlags & NC_AllowAgg)==0)
9968699781
|| (is_agg && (pDef->funcFlags&SQLITE_FUNC_WINDOW) && !pWin)
9968799782
|| (is_agg && pWin && (pNC->ncFlags & NC_AllowWin)==0)
9968899783
){
@@ -99691,39 +99786,39 @@
9969199786
zType = "window";
9969299787
}else{
9969399788
zType = "aggregate";
9969499789
}
9969599790
sqlite3ErrorMsg(pParse, "misuse of %s function %.*s()",zType,nId,zId);
99696
- pNC->nErr++;
99791
+ pNC->nNcErr++;
9969799792
is_agg = 0;
9969899793
}
9969999794
#else
9970099795
if( (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) ){
9970199796
sqlite3ErrorMsg(pParse,"misuse of aggregate function %.*s()",nId,zId);
99702
- pNC->nErr++;
99797
+ pNC->nNcErr++;
9970399798
is_agg = 0;
9970499799
}
9970599800
#endif
9970699801
else if( no_such_func && pParse->db->init.busy==0
9970799802
#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
9970899803
&& pParse->explain==0
9970999804
#endif
9971099805
){
9971199806
sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId);
99712
- pNC->nErr++;
99807
+ pNC->nNcErr++;
9971399808
}else if( wrong_num_args ){
9971499809
sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()",
9971599810
nId, zId);
99716
- pNC->nErr++;
99811
+ pNC->nNcErr++;
9971799812
}
9971899813
#ifndef SQLITE_OMIT_WINDOWFUNC
9971999814
else if( is_agg==0 && ExprHasProperty(pExpr, EP_WinFunc) ){
9972099815
sqlite3ErrorMsg(pParse,
9972199816
"FILTER may not be used with non-aggregate %.*s()",
9972299817
nId, zId
9972399818
);
99724
- pNC->nErr++;
99819
+ pNC->nNcErr++;
9972599820
}
9972699821
#endif
9972799822
if( is_agg ){
9972899823
/* Window functions may not be arguments of aggregate functions.
9972999824
** Or arguments of other window functions. But aggregate functions
@@ -99943,12 +100038,12 @@
99943100038
*/
99944100039
memset(&nc, 0, sizeof(nc));
99945100040
nc.pParse = pParse;
99946100041
nc.pSrcList = pSelect->pSrc;
99947100042
nc.uNC.pEList = pEList;
99948
- nc.ncFlags = NC_AllowAgg|NC_UEList;
99949
- nc.nErr = 0;
100043
+ nc.ncFlags = NC_AllowAgg|NC_UEList|NC_NoSelect;
100044
+ nc.nNcErr = 0;
99950100045
db = pParse->db;
99951100046
savedSuppErr = db->suppressErr;
99952100047
if( IN_RENAME_OBJECT==0 ) db->suppressErr = 1;
99953100048
rc = sqlite3ResolveExprNames(&nc, pE);
99954100049
db->suppressErr = savedSuppErr;
@@ -100203,11 +100298,11 @@
100203100298
int iCol; /* Column number */
100204100299
struct ExprList_item *pItem; /* A term of the ORDER BY clause */
100205100300
Parse *pParse; /* Parsing context */
100206100301
int nResult; /* Number of terms in the result set */
100207100302
100208
- if( pOrderBy==0 ) return 0;
100303
+ assert( pOrderBy!=0 );
100209100304
nResult = pSelect->pEList->nExpr;
100210100305
pParse = pNC->pParse;
100211100306
for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
100212100307
Expr *pE = pItem->pExpr;
100213100308
Expr *pE2 = sqlite3ExprSkipCollateAndLikely(pE);
@@ -100293,11 +100388,13 @@
100293100388
nCompound = 0;
100294100389
pLeftmost = p;
100295100390
while( p ){
100296100391
assert( (p->selFlags & SF_Expanded)!=0 );
100297100392
assert( (p->selFlags & SF_Resolved)==0 );
100393
+ assert( db->suppressErr==0 ); /* SF_Resolved not set if errors suppressed */
100298100394
p->selFlags |= SF_Resolved;
100395
+
100299100396
100300100397
/* Resolve the expressions in the LIMIT and OFFSET clauses. These
100301100398
** are not allowed to refer to any names, so pass an empty NameContext.
100302100399
*/
100303100400
memset(&sNC, 0, sizeof(sNC));
@@ -100368,17 +100465,10 @@
100368100465
p->selFlags |= SF_Aggregate | (sNC.ncFlags&NC_MinMaxAgg);
100369100466
}else{
100370100467
sNC.ncFlags &= ~NC_AllowAgg;
100371100468
}
100372100469
100373
- /* If a HAVING clause is present, then there must be a GROUP BY clause.
100374
- */
100375
- if( p->pHaving && !pGroupBy ){
100376
- sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING");
100377
- return WRC_Abort;
100378
- }
100379
-
100380100470
/* Add the output column list to the name-context before parsing the
100381100471
** other expressions in the SELECT statement. This is so that
100382100472
** expressions in the WHERE clause (etc.) can refer to expressions by
100383100473
** aliases in the result set.
100384100474
**
@@ -100386,11 +100476,17 @@
100386100476
** re-evaluated for each reference to it.
100387100477
*/
100388100478
assert( (sNC.ncFlags & (NC_UAggInfo|NC_UUpsert|NC_UBaseReg))==0 );
100389100479
sNC.uNC.pEList = p->pEList;
100390100480
sNC.ncFlags |= NC_UEList;
100391
- if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;
100481
+ if( p->pHaving ){
100482
+ if( !pGroupBy ){
100483
+ sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING");
100484
+ return WRC_Abort;
100485
+ }
100486
+ if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;
100487
+ }
100392100488
if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort;
100393100489
100394100490
/* Resolve names in table-valued-function arguments */
100395100491
for(i=0; i<p->pSrc->nSrc; i++){
100396100492
SrcItem *pItem = &p->pSrc->a[i];
@@ -100426,11 +100522,12 @@
100426100522
** If there is an ORDER BY clause on a term of a compound-select other
100427100523
** than the right-most term, then that is a syntax error. But the error
100428100524
** is not detected until much later, and so we need to go ahead and
100429100525
** resolve those symbols on the incorrect ORDER BY for consistency.
100430100526
*/
100431
- if( isCompound<=nCompound /* Defer right-most ORDER BY of a compound */
100527
+ if( p->pOrderBy!=0
100528
+ && isCompound<=nCompound /* Defer right-most ORDER BY of a compound */
100432100529
&& resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER")
100433100530
){
100434100531
return WRC_Abort;
100435100532
}
100436100533
if( db->mallocFailed ){
@@ -100550,11 +100647,11 @@
100550100647
if( pExpr==0 ) return SQLITE_OK;
100551100648
savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
100552100649
pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
100553100650
w.pParse = pNC->pParse;
100554100651
w.xExprCallback = resolveExprStep;
100555
- w.xSelectCallback = resolveSelectStep;
100652
+ w.xSelectCallback = (pNC->ncFlags & NC_NoSelect) ? 0 : resolveSelectStep;
100556100653
w.xSelectCallback2 = 0;
100557100654
w.u.pNC = pNC;
100558100655
#if SQLITE_MAX_EXPR_DEPTH>0
100559100656
w.pParse->nHeight += pExpr->nHeight;
100560100657
if( sqlite3ExprCheckHeight(w.pParse, w.pParse->nHeight) ){
@@ -100569,11 +100666,11 @@
100569100666
assert( EP_Win==NC_HasWin );
100570100667
testcase( pNC->ncFlags & NC_HasAgg );
100571100668
testcase( pNC->ncFlags & NC_HasWin );
100572100669
ExprSetProperty(pExpr, pNC->ncFlags & (NC_HasAgg|NC_HasWin) );
100573100670
pNC->ncFlags |= savedHasAgg;
100574
- return pNC->nErr>0 || w.pParse->nErr>0;
100671
+ return pNC->nNcErr>0 || w.pParse->nErr>0;
100575100672
}
100576100673
100577100674
/*
100578100675
** Resolve all names for all expression in an expression list. This is
100579100676
** just like sqlite3ResolveExprNames() except that it works for an expression
@@ -100614,11 +100711,11 @@
100614100711
if( pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin) ){
100615100712
ExprSetProperty(pExpr, pNC->ncFlags & (NC_HasAgg|NC_HasWin) );
100616100713
savedHasAgg |= pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
100617100714
pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
100618100715
}
100619
- if( pNC->nErr>0 || w.pParse->nErr>0 ) return WRC_Abort;
100716
+ if( w.pParse->nErr>0 ) return WRC_Abort;
100620100717
}
100621100718
pNC->ncFlags |= savedHasAgg;
100622100719
return WRC_Continue;
100623100720
}
100624100721
@@ -100757,27 +100854,27 @@
100757100854
|| (pExpr->op==TK_REGISTER && pExpr->op2==TK_IF_NULL_ROW) );
100758100855
pExpr = pExpr->pLeft;
100759100856
assert( pExpr!=0 );
100760100857
}
100761100858
op = pExpr->op;
100859
+ if( op==TK_REGISTER ) op = pExpr->op2;
100860
+ if( (op==TK_COLUMN || op==TK_AGG_COLUMN) && pExpr->y.pTab ){
100861
+ return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
100862
+ }
100762100863
if( op==TK_SELECT ){
100763100864
assert( pExpr->flags&EP_xIsSelect );
100764100865
assert( pExpr->x.pSelect!=0 );
100765100866
assert( pExpr->x.pSelect->pEList!=0 );
100766100867
assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 );
100767100868
return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
100768100869
}
100769
- if( op==TK_REGISTER ) op = pExpr->op2;
100770100870
#ifndef SQLITE_OMIT_CAST
100771100871
if( op==TK_CAST ){
100772100872
assert( !ExprHasProperty(pExpr, EP_IntValue) );
100773100873
return sqlite3AffinityType(pExpr->u.zToken, 0);
100774100874
}
100775100875
#endif
100776
- if( (op==TK_AGG_COLUMN || op==TK_COLUMN) && pExpr->y.pTab ){
100777
- return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
100778
- }
100779100876
if( op==TK_SELECT_COLUMN ){
100780100877
assert( pExpr->pLeft->flags&EP_xIsSelect );
100781100878
return sqlite3ExprAffinity(
100782100879
pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
100783100880
);
@@ -102029,10 +102126,11 @@
102029102126
102030102127
/* Figure out where to write the new Expr structure. */
102031102128
if( pzBuffer ){
102032102129
zAlloc = *pzBuffer;
102033102130
staticFlag = EP_Static;
102131
+ assert( zAlloc!=0 );
102034102132
}else{
102035102133
zAlloc = sqlite3DbMallocRawNN(db, dupedExprSize(p, dupFlags));
102036102134
staticFlag = 0;
102037102135
}
102038102136
pNew = (Expr *)zAlloc;
@@ -102107,11 +102205,12 @@
102107102205
}else{
102108102206
if( !ExprHasProperty(p, EP_TokenOnly|EP_Leaf) ){
102109102207
if( pNew->op==TK_SELECT_COLUMN ){
102110102208
pNew->pLeft = p->pLeft;
102111102209
assert( p->iColumn==0 || p->pRight==0 );
102112
- assert( p->pRight==0 || p->pRight==p->pLeft );
102210
+ assert( p->pRight==0 || p->pRight==p->pLeft
102211
+ || ExprHasProperty(p->pLeft, EP_Subquery) );
102113102212
}else{
102114102213
pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
102115102214
}
102116102215
pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
102117102216
}
@@ -102352,10 +102451,18 @@
102352102451
pNew->pWin = 0;
102353102452
pNew->pWinDefn = sqlite3WindowListDup(db, p->pWinDefn);
102354102453
if( p->pWin && db->mallocFailed==0 ) gatherSelectWindows(pNew);
102355102454
#endif
102356102455
pNew->selId = p->selId;
102456
+ if( db->mallocFailed ){
102457
+ /* Any prior OOM might have left the Select object incomplete.
102458
+ ** Delete the whole thing rather than allow an incomplete Select
102459
+ ** to be used by the code generator. */
102460
+ pNew->pNext = 0;
102461
+ sqlite3SelectDelete(db, pNew);
102462
+ break;
102463
+ }
102357102464
*pp = pNew;
102358102465
pp = &pNew->pPrior;
102359102466
pNext = pNew;
102360102467
}
102361102468
@@ -103052,12 +103159,14 @@
103052103159
** will likely result in an incorrect answer. So when in doubt, return
103053103160
** TRUE.
103054103161
*/
103055103162
SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr *p){
103056103163
u8 op;
103164
+ assert( p!=0 );
103057103165
while( p->op==TK_UPLUS || p->op==TK_UMINUS ){
103058103166
p = p->pLeft;
103167
+ assert( p!=0 );
103059103168
}
103060103169
op = p->op;
103061103170
if( op==TK_REGISTER ) op = p->op2;
103062103171
switch( op ){
103063103172
case TK_INTEGER:
@@ -103903,11 +104012,11 @@
103903104012
** columns as the vector on the LHS. Or, if the RHS of the IN() is not
103904104013
** a sub-query, that the LHS is a vector of size 1.
103905104014
*/
103906104015
SQLITE_PRIVATE int sqlite3ExprCheckIN(Parse *pParse, Expr *pIn){
103907104016
int nVector = sqlite3ExprVectorSize(pIn->pLeft);
103908
- if( (pIn->flags & EP_xIsSelect) ){
104017
+ if( (pIn->flags & EP_xIsSelect)!=0 && !pParse->db->mallocFailed ){
103909104018
if( nVector!=pIn->x.pSelect->pEList->nExpr ){
103910104019
sqlite3SubselectError(pParse, pIn->x.pSelect->pEList->nExpr, nVector);
103911104020
return 1;
103912104021
}
103913104022
}else if( nVector!=1 ){
@@ -104720,11 +104829,11 @@
104720104829
default: {
104721104830
/* Make NULL the default case so that if a bug causes an illegal
104722104831
** Expr node to be passed into this function, it will be handled
104723104832
** sanely and not crash. But keep the assert() to bring the problem
104724104833
** to the attention of the developers. */
104725
- assert( op==TK_NULL );
104834
+ assert( op==TK_NULL || pParse->db->mallocFailed );
104726104835
sqlite3VdbeAddOp2(v, OP_Null, 0, target);
104727104836
return target;
104728104837
}
104729104838
#ifndef SQLITE_OMIT_BLOB_LITERAL
104730104839
case TK_BLOB: {
@@ -106895,10 +107004,11 @@
106895107004
** Or, if zName is not a system table, zero is returned.
106896107005
*/
106897107006
static int isAlterableTable(Parse *pParse, Table *pTab){
106898107007
if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7)
106899107008
#ifndef SQLITE_OMIT_VIRTUALTABLE
107009
+ || (pTab->tabFlags & TF_Eponymous)!=0
106900107010
|| ( (pTab->tabFlags & TF_Shadow)!=0
106901107011
&& sqlite3ReadOnlyShadowTables(pParse->db)
106902107012
)
106903107013
#endif
106904107014
){
@@ -107782,11 +107892,13 @@
107782107892
Parse *pParse,
107783107893
struct RenameCtx *pCtx,
107784107894
void *pPtr
107785107895
){
107786107896
RenameToken **pp;
107787
- assert( pPtr!=0 );
107897
+ if( NEVER(pPtr==0) ){
107898
+ return 0;
107899
+ }
107788107900
for(pp=&pParse->pRename; (*pp); pp=&(*pp)->pNext){
107789107901
if( (*pp)->p==pPtr ){
107790107902
RenameToken *pToken = *pp;
107791107903
if( pCtx ){
107792107904
*pp = pToken->pNext;
@@ -108439,11 +108551,11 @@
108439108551
static int renameTableSelectCb(Walker *pWalker, Select *pSelect){
108440108552
int i;
108441108553
RenameCtx *p = pWalker->u.pRename;
108442108554
SrcList *pSrc = pSelect->pSrc;
108443108555
if( pSelect->selFlags & SF_View ) return WRC_Prune;
108444
- if( pSrc==0 ){
108556
+ if( NEVER(pSrc==0) ){
108445108557
assert( pWalker->pParse->db->mallocFailed );
108446108558
return WRC_Abort;
108447108559
}
108448108560
for(i=0; i<pSrc->nSrc; i++){
108449108561
SrcItem *pItem = &pSrc->a[i];
@@ -108983,20 +109095,25 @@
108983109095
if( iPos<pPk->nKeyCol ) continue;
108984109096
regOut = reg+1+iPos-(iPos>iColPos);
108985109097
}else{
108986109098
regOut = reg+1+nField;
108987109099
}
108988
- sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut);
109100
+ if( i==pTab->iPKey ){
109101
+ sqlite3VdbeAddOp2(v, OP_Null, 0, regOut);
109102
+ }else{
109103
+ sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut);
109104
+ }
108989109105
nField++;
108990109106
}
108991109107
}
108992109108
sqlite3VdbeAddOp3(v, OP_MakeRecord, reg+1, nField, regRec);
108993109109
if( pPk ){
108994109110
sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iCur, regRec, reg+1, pPk->nKeyCol);
108995109111
}else{
108996109112
sqlite3VdbeAddOp3(v, OP_Insert, iCur, regRec, reg);
108997109113
}
109114
+ sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION);
108998109115
108999109116
sqlite3VdbeAddOp2(v, OP_Next, iCur, addr+1); VdbeCoverage(v);
109000109117
sqlite3VdbeJumpHere(v, addr);
109001109118
}
109002109119
@@ -111479,11 +111596,11 @@
111479111596
pFix->pName = pName;
111480111597
pFix->bTemp = (iDb==1);
111481111598
pFix->w.pParse = pParse;
111482111599
pFix->w.xExprCallback = fixExprCb;
111483111600
pFix->w.xSelectCallback = fixSelectCb;
111484
- pFix->w.xSelectCallback2 = 0;
111601
+ pFix->w.xSelectCallback2 = sqlite3WalkWinDefnDummyCallback;
111485111602
pFix->w.walkerDepth = 0;
111486111603
pFix->w.eCode = 0;
111487111604
pFix->w.u.pFix = pFix;
111488111605
}
111489111606
@@ -111541,18 +111658,20 @@
111541111658
|| sqlite3FixSrcList(pFix, pStep->pFrom)
111542111659
){
111543111660
return 1;
111544111661
}
111545111662
#ifndef SQLITE_OMIT_UPSERT
111546
- if( pStep->pUpsert ){
111547
- Upsert *pUp = pStep->pUpsert;
111548
- if( sqlite3WalkExprList(&pFix->w, pUp->pUpsertTarget)
111549
- || sqlite3WalkExpr(&pFix->w, pUp->pUpsertTargetWhere)
111550
- || sqlite3WalkExprList(&pFix->w, pUp->pUpsertSet)
111551
- || sqlite3WalkExpr(&pFix->w, pUp->pUpsertWhere)
111552
- ){
111553
- return 1;
111663
+ {
111664
+ Upsert *pUp;
111665
+ for(pUp=pStep->pUpsert; pUp; pUp=pUp->pNextUpsert){
111666
+ if( sqlite3WalkExprList(&pFix->w, pUp->pUpsertTarget)
111667
+ || sqlite3WalkExpr(&pFix->w, pUp->pUpsertTargetWhere)
111668
+ || sqlite3WalkExprList(&pFix->w, pUp->pUpsertSet)
111669
+ || sqlite3WalkExpr(&pFix->w, pUp->pUpsertWhere)
111670
+ ){
111671
+ return 1;
111672
+ }
111554111673
}
111555111674
}
111556111675
#endif
111557111676
pStep = pStep->pNext;
111558111677
}
@@ -112272,11 +112391,11 @@
112272112391
if( p==0 ){
112273112392
#ifndef SQLITE_OMIT_VIRTUALTABLE
112274112393
/* If zName is the not the name of a table in the schema created using
112275112394
** CREATE, then check to see if it is the name of an virtual table that
112276112395
** can be an eponymous virtual table. */
112277
- if( pParse->disableVtab==0 ){
112396
+ if( pParse->disableVtab==0 && db->init.busy==0 ){
112278112397
Module *pMod = (Module*)sqlite3HashFind(&db->aModule, zName);
112279112398
if( pMod==0 && sqlite3_strnicmp(zName, "pragma_", 7)==0 ){
112280112399
pMod = sqlite3PragmaVtabRegister(db, zName);
112281112400
}
112282112401
if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){
@@ -112295,10 +112414,12 @@
112295112414
if( zDbase ){
112296112415
sqlite3ErrorMsg(pParse, "%s: %s.%s", zMsg, zDbase, zName);
112297112416
}else{
112298112417
sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName);
112299112418
}
112419
+ }else{
112420
+ assert( HasRowid(p) || p->iPKey<0 );
112300112421
}
112301112422
112302112423
return p;
112303112424
}
112304112425
@@ -113155,10 +113276,11 @@
113155113276
pRet->retTrig.zName = RETURNING_TRIGGER_NAME;
113156113277
pRet->retTrig.op = TK_RETURNING;
113157113278
pRet->retTrig.tr_tm = TRIGGER_AFTER;
113158113279
pRet->retTrig.bReturning = 1;
113159113280
pRet->retTrig.pSchema = db->aDb[1].pSchema;
113281
+ pRet->retTrig.pTabSchema = db->aDb[1].pSchema;
113160113282
pRet->retTrig.step_list = &pRet->retTStep;
113161113283
pRet->retTStep.op = TK_RETURNING;
113162113284
pRet->retTStep.pTrig = &pRet->retTrig;
113163113285
pRet->retTStep.pExprList = pList;
113164113286
pHash = &(db->aDb[1].pSchema->trigHash);
@@ -114013,20 +114135,26 @@
114013114135
ExprList *pList;
114014114136
Token ipkToken;
114015114137
sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zName);
114016114138
pList = sqlite3ExprListAppend(pParse, 0,
114017114139
sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
114018
- if( pList==0 ) return;
114140
+ if( pList==0 ){
114141
+ pTab->tabFlags &= ~TF_WithoutRowid;
114142
+ return;
114143
+ }
114019114144
if( IN_RENAME_OBJECT ){
114020114145
sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
114021114146
}
114022114147
pList->a[0].sortFlags = pParse->iPkSortOrder;
114023114148
assert( pParse->pNewTable==pTab );
114024114149
pTab->iPKey = -1;
114025114150
sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
114026114151
SQLITE_IDXTYPE_PRIMARYKEY);
114027
- if( db->mallocFailed || pParse->nErr ) return;
114152
+ if( db->mallocFailed || pParse->nErr ){
114153
+ pTab->tabFlags &= ~TF_WithoutRowid;
114154
+ return;
114155
+ }
114028114156
pPk = sqlite3PrimaryKeyIndex(pTab);
114029114157
assert( pPk->nKeyCol==1 );
114030114158
}else{
114031114159
pPk = sqlite3PrimaryKeyIndex(pTab);
114032114160
assert( pPk!=0 );
@@ -114226,11 +114354,10 @@
114226114354
Index *pIdx; /* An implied index of the table */
114227114355
114228114356
if( pEnd==0 && pSelect==0 ){
114229114357
return;
114230114358
}
114231
- assert( !db->mallocFailed );
114232114359
p = pParse->pNewTable;
114233114360
if( p==0 ) return;
114234114361
114235114362
if( pSelect==0 && sqlite3ShadowTableName(db, p->zName) ){
114236114363
p->tabFlags |= TF_Shadow;
@@ -114474,10 +114601,11 @@
114474114601
*/
114475114602
if( db->init.busy ){
114476114603
Table *pOld;
114477114604
Schema *pSchema = p->pSchema;
114478114605
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
114606
+ assert( HasRowid(p) || p->iPKey<0 );
114479114607
pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName, p);
114480114608
if( pOld ){
114481114609
assert( p==pOld ); /* Malloc must have failed inside HashInsert() */
114482114610
sqlite3OomFault(db);
114483114611
return;
@@ -116421,12 +116549,12 @@
116421116549
** Assign VdbeCursor index numbers to all tables in a SrcList
116422116550
*/
116423116551
SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse *pParse, SrcList *pList){
116424116552
int i;
116425116553
SrcItem *pItem;
116426
- assert(pList || pParse->db->mallocFailed );
116427
- if( pList ){
116554
+ assert( pList || pParse->db->mallocFailed );
116555
+ if( ALWAYS(pList) ){
116428116556
for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
116429116557
if( pItem->iCursor>=0 ) continue;
116430116558
pItem->iCursor = pParse->nTab++;
116431116559
if( pItem->pSelect ){
116432116560
sqlite3SrcListAssignCursors(pParse, pItem->pSelect->pSrc);
@@ -120759,13 +120887,11 @@
120759120887
ans = x(v0, v1);
120760120888
sqlite3_result_double(context, ans);
120761120889
}
120762120890
120763120891
/*
120764
-** Implementation of 2-argument SQL math functions:
120765
-**
120766
-** power(X,Y) - Compute X to the Y-th power
120892
+** Implementation of 0-argument pi() function.
120767120893
*/
120768120894
static void piFunc(
120769120895
sqlite3_context *context,
120770120896
int argc,
120771120897
sqlite3_value **argv
@@ -122791,11 +122917,11 @@
122791122917
/* Verify that the sqlite_sequence table exists and is an ordinary
122792122918
** rowid table with exactly two columns.
122793122919
** Ticket d8dc2b3a58cd5dc2918a1d4acb 2018-05-23 */
122794122920
if( pSeqTab==0
122795122921
|| !HasRowid(pSeqTab)
122796
- || IsVirtual(pSeqTab)
122922
+ || NEVER(IsVirtual(pSeqTab))
122797122923
|| pSeqTab->nCol!=2
122798122924
){
122799122925
pParse->nErr++;
122800122926
pParse->rc = SQLITE_CORRUPT_SEQUENCE;
122801122927
return 0;
@@ -130510,18 +130636,18 @@
130510130636
130511130637
assert( argc==5 );
130512130638
UNUSED_PARAMETER2(NotUsed, argc);
130513130639
assert( sqlite3_mutex_held(db->mutex) );
130514130640
db->mDbFlags |= DBFLAG_EncodingFixed;
130641
+ if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
130515130642
pData->nInitRow++;
130516130643
if( db->mallocFailed ){
130517130644
corruptSchema(pData, argv, 0);
130518130645
return 1;
130519130646
}
130520130647
130521130648
assert( iDb>=0 && iDb<db->nDb );
130522
- if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
130523130649
if( argv[3]==0 ){
130524130650
corruptSchema(pData, argv, 0);
130525130651
}else if( argv[4]
130526130652
&& 'c'==sqlite3UpperToLower[(unsigned char)argv[4][0]]
130527130653
&& 'r'==sqlite3UpperToLower[(unsigned char)argv[4][1]] ){
@@ -130794,19 +130920,21 @@
130794130920
#endif
130795130921
}
130796130922
if( db->mallocFailed ){
130797130923
rc = SQLITE_NOMEM_BKPT;
130798130924
sqlite3ResetAllSchemasOfConnection(db);
130799
- }
130925
+ }else
130800130926
if( rc==SQLITE_OK || (db->flags&SQLITE_NoSchemaError)){
130801
- /* Black magic: If the SQLITE_NoSchemaError flag is set, then consider
130802
- ** the schema loaded, even if errors occurred. In this situation the
130803
- ** current sqlite3_prepare() operation will fail, but the following one
130804
- ** will attempt to compile the supplied statement against whatever subset
130805
- ** of the schema was loaded before the error occurred. The primary
130806
- ** purpose of this is to allow access to the sqlite_schema table
130807
- ** even when its contents have been corrupted.
130927
+ /* Hack: If the SQLITE_NoSchemaError flag is set, then consider
130928
+ ** the schema loaded, even if errors (other than OOM) occurred. In
130929
+ ** this situation the current sqlite3_prepare() operation will fail,
130930
+ ** but the following one will attempt to compile the supplied statement
130931
+ ** against whatever subset of the schema was loaded before the error
130932
+ ** occurred.
130933
+ **
130934
+ ** The primary purpose of this is to allow access to the sqlite_schema
130935
+ ** table even when its contents have been corrupted.
130808130936
*/
130809130937
DbSetProperty(db, iDb, DB_SchemaLoaded);
130810130938
rc = SQLITE_OK;
130811130939
}
130812130940
@@ -134976,10 +135104,13 @@
134976135104
if( p->pPrior ){
134977135105
sqlite3SelectDelete(db, p->pPrior);
134978135106
}
134979135107
p->pPrior = pPrior;
134980135108
pPrior->pNext = p;
135109
+
135110
+ sqlite3ExprListDelete(db, pPrior->pOrderBy);
135111
+ pPrior->pOrderBy = 0;
134981135112
134982135113
/*** TBD: Insert subroutine calls to close cursors on incomplete
134983135114
**** subqueries ****/
134984135115
ExplainQueryPlanPop(pParse);
134985135116
return pParse->nErr!=0;
@@ -135056,30 +135187,32 @@
135056135187
ifNullRow.flags = EP_IfNullRow;
135057135188
pCopy = &ifNullRow;
135058135189
}
135059135190
testcase( ExprHasProperty(pCopy, EP_Subquery) );
135060135191
pNew = sqlite3ExprDup(db, pCopy, 0);
135061
- if( pNew && pSubst->isLeftJoin ){
135192
+ if( db->mallocFailed ){
135193
+ sqlite3ExprDelete(db, pNew);
135194
+ return pExpr;
135195
+ }
135196
+ if( pSubst->isLeftJoin ){
135062135197
ExprSetProperty(pNew, EP_CanBeNull);
135063135198
}
135064
- if( pNew && ExprHasProperty(pExpr,EP_FromJoin) ){
135199
+ if( ExprHasProperty(pExpr,EP_FromJoin) ){
135065135200
sqlite3SetJoinExpr(pNew, pExpr->iRightJoinTable);
135066135201
}
135067135202
sqlite3ExprDelete(db, pExpr);
135068135203
pExpr = pNew;
135069135204
135070135205
/* Ensure that the expression now has an implicit collation sequence,
135071135206
** just as it did when it was a column of a view or sub-query. */
135072
- if( pExpr ){
135073
- if( pExpr->op!=TK_COLUMN && pExpr->op!=TK_COLLATE ){
135074
- CollSeq *pColl = sqlite3ExprCollSeq(pSubst->pParse, pExpr);
135075
- pExpr = sqlite3ExprAddCollateString(pSubst->pParse, pExpr,
135076
- (pColl ? pColl->zName : "BINARY")
135077
- );
135078
- }
135079
- ExprClearProperty(pExpr, EP_Collate);
135080
- }
135207
+ if( pExpr->op!=TK_COLUMN && pExpr->op!=TK_COLLATE ){
135208
+ CollSeq *pColl = sqlite3ExprCollSeq(pSubst->pParse, pExpr);
135209
+ pExpr = sqlite3ExprAddCollateString(pSubst->pParse, pExpr,
135210
+ (pColl ? pColl->zName : "BINARY")
135211
+ );
135212
+ }
135213
+ ExprClearProperty(pExpr, EP_Collate);
135081135214
}
135082135215
}
135083135216
}else{
135084135217
if( pExpr->op==TK_IF_NULL_ROW && pExpr->iTable==pSubst->iTable ){
135085135218
pExpr->iTable = pSubst->iNewTable;
@@ -135194,11 +135327,14 @@
135194135327
int i;
135195135328
SrcItem *pItem;
135196135329
for(i=0, pItem=pSrc->a; i<pSrc->nSrc; i++, pItem++){
135197135330
if( i!=iExcept ){
135198135331
Select *p;
135199
- pItem->iCursor = aCsrMap[pItem->iCursor] = pParse->nTab++;
135332
+ if( !pItem->fg.isRecursive || aCsrMap[pItem->iCursor]==0 ){
135333
+ aCsrMap[pItem->iCursor] = pParse->nTab++;
135334
+ }
135335
+ pItem->iCursor = aCsrMap[pItem->iCursor];
135200135336
for(p=pItem->pSelect; p; p=p->pPrior){
135201135337
srclistRenumberCursors(pParse, aCsrMap, p->pSrc, -1);
135202135338
}
135203135339
}
135204135340
}
@@ -135634,11 +135770,11 @@
135634135770
pSubitem->pTab = pItemTab;
135635135771
if( pNew==0 ){
135636135772
p->pPrior = pPrior;
135637135773
}else{
135638135774
pNew->selId = ++pParse->nSelect;
135639
- if( aCsrMap && db->mallocFailed==0 ){
135775
+ if( aCsrMap && ALWAYS(db->mallocFailed==0) ){
135640135776
renumberCursors(pParse, pNew, iFrom, aCsrMap);
135641135777
}
135642135778
pNew->pPrior = pPrior;
135643135779
if( pPrior ) pPrior->pNext = pNew;
135644135780
pNew->pNext = p;
@@ -137626,12 +137762,11 @@
137626137762
if( pDest->eDest==SRT_Output ){
137627137763
generateColumnNames(pParse, p);
137628137764
}
137629137765
137630137766
#ifndef SQLITE_OMIT_WINDOWFUNC
137631
- rc = sqlite3WindowRewrite(pParse, p);
137632
- if( rc ){
137767
+ if( sqlite3WindowRewrite(pParse, p) ){
137633137768
assert( db->mallocFailed || pParse->nErr>0 );
137634137769
goto select_end;
137635137770
}
137636137771
#if SELECTTRACE_ENABLED
137637137772
if( p->pWin && (sqlite3SelectTrace & 0x108)!=0 ){
@@ -138344,12 +138479,14 @@
138344138479
sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
138345138480
SELECTTRACE(1,pParse,p,("WhereBegin\n"));
138346138481
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct,
138347138482
WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0
138348138483
);
138349
- sqlite3ExprListDelete(db, pDistinct);
138350
- if( pWInfo==0 ) goto select_end;
138484
+ if( pWInfo==0 ){
138485
+ sqlite3ExprListDelete(db, pDistinct);
138486
+ goto select_end;
138487
+ }
138351138488
eDist = sqlite3WhereIsDistinct(pWInfo);
138352138489
SELECTTRACE(1,pParse,p,("WhereBegin returns\n"));
138353138490
if( sqlite3WhereIsOrdered(pWInfo)==pGroupBy->nExpr ){
138354138491
/* The optimizer is able to deliver rows in group by order so
138355138492
** we do not have to sort. The OP_OpenEphemeral table will be
@@ -138478,10 +138615,11 @@
138478138615
}else{
138479138616
SELECTTRACE(1,pParse,p,("WhereEnd\n"));
138480138617
sqlite3WhereEnd(pWInfo);
138481138618
sqlite3VdbeChangeToNoop(v, addrSortingIdx);
138482138619
}
138620
+ sqlite3ExprListDelete(db, pDistinct);
138483138621
138484138622
/* Output the final row of result
138485138623
*/
138486138624
sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
138487138625
VdbeComment((v, "output final row"));
@@ -138692,10 +138830,12 @@
138692138830
138693138831
/* Control jumps to here if an error is encountered above, or upon
138694138832
** successful coding of the SELECT.
138695138833
*/
138696138834
select_end:
138835
+ assert( db->mallocFailed==0 || db->mallocFailed==1 );
138836
+ pParse->nErr += db->mallocFailed;
138697138837
sqlite3ExprListDelete(db, pMinMaxOrderBy);
138698138838
#ifdef SQLITE_DEBUG
138699138839
if( pAggInfo && !db->mallocFailed ){
138700138840
for(i=0; i<pAggInfo->nColumn; i++){
138701138841
Expr *pExpr = pAggInfo->aCol[i].pCExpr;
@@ -138982,37 +139122,45 @@
138982139122
if( pParse->disableTriggers ){
138983139123
return 0;
138984139124
}
138985139125
pTmpSchema = pParse->db->aDb[1].pSchema;
138986139126
p = sqliteHashFirst(&pTmpSchema->trigHash);
138987
- if( p==0 ){
138988
- return pTab->pTrigger;
138989
- }
138990139127
pList = pTab->pTrigger;
138991
- if( pTmpSchema!=pTab->pSchema ){
138992
- while( p ){
138993
- Trigger *pTrig = (Trigger *)sqliteHashData(p);
138994
- if( pTrig->pTabSchema==pTab->pSchema
138995
- && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
138996
- ){
138997
- pTrig->pNext = pList;
138998
- pList = pTrig;
138999
- }else if( pTrig->op==TK_RETURNING
139128
+ while( p ){
139129
+ Trigger *pTrig = (Trigger *)sqliteHashData(p);
139130
+ if( pTrig->pTabSchema==pTab->pSchema
139131
+ && pTrig->table
139132
+ && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
139133
+ && pTrig->pTabSchema!=pTmpSchema
139134
+ ){
139135
+ pTrig->pNext = pList;
139136
+ pList = pTrig;
139137
+ }else if( pTrig->op==TK_RETURNING
139000139138
#ifndef SQLITE_OMIT_VIRTUALTABLE
139001
- && pParse->db->pVtabCtx==0
139139
+ && pParse->db->pVtabCtx==0
139002139140
#endif
139003
- ){
139004
- assert( pParse->bReturning );
139005
- assert( &(pParse->u1.pReturning->retTrig) == pTrig );
139006
- pTrig->table = pTab->zName;
139007
- pTrig->pTabSchema = pTab->pSchema;
139008
- pTrig->pNext = pList;
139009
- pList = pTrig;
139010
- }
139011
- p = sqliteHashNext(p);
139012
- }
139013
- }
139141
+ ){
139142
+ assert( pParse->bReturning );
139143
+ assert( &(pParse->u1.pReturning->retTrig) == pTrig );
139144
+ pTrig->table = pTab->zName;
139145
+ pTrig->pTabSchema = pTab->pSchema;
139146
+ pTrig->pNext = pList;
139147
+ pList = pTrig;
139148
+ }
139149
+ p = sqliteHashNext(p);
139150
+ }
139151
+#if 0
139152
+ if( pList ){
139153
+ Trigger *pX;
139154
+ printf("Triggers for %s:", pTab->zName);
139155
+ for(pX=pList; pX; pX=pX->pNext){
139156
+ printf(" %s", pX->zName);
139157
+ }
139158
+ printf("\n");
139159
+ fflush(stdout);
139160
+ }
139161
+#endif
139014139162
return pList;
139015139163
}
139016139164
139017139165
/*
139018139166
** This is called by the parser when it sees a CREATE TRIGGER statement
@@ -140581,11 +140729,12 @@
140581140729
if( pLimit ){
140582140730
pGrp = sqlite3ExprListAppend(pParse, 0, sqlite3PExpr(pParse,TK_ROW,0,0));
140583140731
}
140584140732
#endif
140585140733
}
140586
- if( ALWAYS(pChanges) ){
140734
+ assert( pChanges!=0 || pParse->db->mallocFailed );
140735
+ if( pChanges ){
140587140736
for(i=0; i<pChanges->nExpr; i++){
140588140737
pList = sqlite3ExprListAppend(pParse, pList,
140589140738
sqlite3ExprDup(db, pChanges->a[i].pExpr, 0)
140590140739
);
140591140740
}
@@ -143607,10 +143756,11 @@
143607143756
pMod->pEpoTab = pTab;
143608143757
pTab->nTabRef = 1;
143609143758
pTab->pSchema = db->aDb[0].pSchema;
143610143759
assert( pTab->nModuleArg==0 );
143611143760
pTab->iPKey = -1;
143761
+ pTab->tabFlags |= TF_Eponymous;
143612143762
addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
143613143763
addModuleArgument(pParse, pTab, 0);
143614143764
addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
143615143765
rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
143616143766
if( rc ){
@@ -145019,10 +145169,11 @@
145019145169
zAff = sqlite3DbStrDup(pParse->db,sqlite3IndexAffinityStr(pParse->db,pIdx));
145020145170
assert( zAff!=0 || pParse->db->mallocFailed );
145021145171
145022145172
if( nSkip ){
145023145173
int iIdxCur = pLevel->iIdxCur;
145174
+ sqlite3VdbeAddOp3(v, OP_Null, 0, regBase, regBase+nSkip-1);
145024145175
sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur);
145025145176
VdbeCoverageIf(v, bRev==0);
145026145177
VdbeCoverageIf(v, bRev!=0);
145027145178
VdbeComment((v, "begin skip-scan on %s", pIdx->zName));
145028145179
j = sqlite3VdbeAddOp0(v, OP_Goto);
@@ -145070,11 +145221,11 @@
145070145221
Expr *pRight = pTerm->pExpr->pRight;
145071145222
if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){
145072145223
sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
145073145224
VdbeCoverage(v);
145074145225
}
145075
- if( zAff ){
145226
+ if( pParse->db->mallocFailed==0 ){
145076145227
if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_BLOB ){
145077145228
zAff[j] = SQLITE_AFF_BLOB;
145078145229
}
145079145230
if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){
145080145231
zAff[j] = SQLITE_AFF_BLOB;
@@ -147320,10 +147471,11 @@
147320147471
sqlite3 *db; /* Database connection (for malloc) */
147321147472
Expr *pNew; /* New virtual expression */
147322147473
int op; /* Operator for the combined expression */
147323147474
int idxNew; /* Index in pWC of the next virtual term */
147324147475
147476
+ if( (pOne->wtFlags | pTwo->wtFlags) & TERM_VNULL ) return;
147325147477
if( (pOne->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return;
147326147478
if( (pTwo->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return;
147327147479
if( (eOp & (WO_EQ|WO_LT|WO_LE))!=eOp
147328147480
&& (eOp & (WO_EQ|WO_GT|WO_GE))!=eOp ) return;
147329147481
assert( pOne->pExpr->pLeft!=0 && pOne->pExpr->pRight!=0 );
@@ -148973,11 +149125,13 @@
148973149125
** If the right-hand branch of the expression is a TK_COLUMN, then return
148974149126
** a pointer to the right-hand branch. Otherwise, return NULL.
148975149127
*/
148976149128
static Expr *whereRightSubexprIsColumn(Expr *p){
148977149129
p = sqlite3ExprSkipCollateAndLikely(p->pRight);
148978
- if( ALWAYS(p!=0) && p->op==TK_COLUMN ) return p;
149130
+ if( ALWAYS(p!=0) && p->op==TK_COLUMN && !ExprHasProperty(p, EP_FixedCol) ){
149131
+ return p;
149132
+ }
148979149133
return 0;
148980149134
}
148981149135
148982149136
/*
148983149137
** Advance to the next WhereTerm that matches according to the criteria
@@ -150652,11 +150806,11 @@
150652150806
** Transfer content from the second pLoop into the first.
150653150807
*/
150654150808
static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
150655150809
whereLoopClearUnion(db, pTo);
150656150810
if( whereLoopResize(db, pTo, pFrom->nLTerm) ){
150657
- memset(&pTo->u, 0, sizeof(pTo->u));
150811
+ memset(pTo, 0, WHERE_LOOP_XFER_SZ);
150658150812
return SQLITE_NOMEM_BKPT;
150659150813
}
150660150814
memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
150661150815
memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
150662150816
if( pFrom->wsFlags & WHERE_VIRTUALTABLE ){
@@ -150694,10 +150848,21 @@
150694150848
whereLoopDelete(db, p);
150695150849
}
150696150850
assert( pWInfo->pExprMods==0 );
150697150851
sqlite3DbFreeNN(db, pWInfo);
150698150852
}
150853
+
150854
+/* Undo all Expr node modifications
150855
+*/
150856
+static void whereUndoExprMods(WhereInfo *pWInfo){
150857
+ while( pWInfo->pExprMods ){
150858
+ WhereExprMod *p = pWInfo->pExprMods;
150859
+ pWInfo->pExprMods = p->pNext;
150860
+ memcpy(p->pExpr, &p->orig, sizeof(p->orig));
150861
+ sqlite3DbFree(pWInfo->pParse->db, p);
150862
+ }
150863
+}
150699150864
150700150865
/*
150701150866
** Return TRUE if all of the following are true:
150702150867
**
150703150868
** (1) X has the same or lower cost that Y
@@ -152307,11 +152472,13 @@
152307152472
rc = whereLoopAddBtree(&sSubBuild, mPrereq);
152308152473
}
152309152474
if( rc==SQLITE_OK ){
152310152475
rc = whereLoopAddOr(&sSubBuild, mPrereq, mUnusable);
152311152476
}
152312
- assert( rc==SQLITE_OK || rc==SQLITE_DONE || sCur.n==0 );
152477
+ assert( rc==SQLITE_OK || rc==SQLITE_DONE || sCur.n==0
152478
+ || rc==SQLITE_NOMEM );
152479
+ testcase( rc==SQLITE_NOMEM && sCur.n>0 );
152313152480
testcase( rc==SQLITE_DONE );
152314152481
if( sCur.n==0 ){
152315152482
sSum.n = 0;
152316152483
break;
152317152484
}else if( once ){
@@ -152576,10 +152743,14 @@
152576152743
nKeyCol = pIndex->nKeyCol;
152577152744
nColumn = pIndex->nColumn;
152578152745
assert( nColumn==nKeyCol+1 || !HasRowid(pIndex->pTable) );
152579152746
assert( pIndex->aiColumn[nColumn-1]==XN_ROWID
152580152747
|| !HasRowid(pIndex->pTable));
152748
+ /* All relevant terms of the index must also be non-NULL in order
152749
+ ** for isOrderDistinct to be true. So the isOrderDistint value
152750
+ ** computed here might be a false positive. Corrections will be
152751
+ ** made at tag-20210426-1 below */
152581152752
isOrderDistinct = IsUniqueIndex(pIndex)
152582152753
&& (pLoop->wsFlags & WHERE_SKIPSCAN)==0;
152583152754
}
152584152755
152585152756
/* Loop through all columns of the index and deal with the ones
@@ -152643,18 +152814,22 @@
152643152814
iColumn = XN_ROWID;
152644152815
revIdx = 0;
152645152816
}
152646152817
152647152818
/* An unconstrained column that might be NULL means that this
152648
- ** WhereLoop is not well-ordered
152819
+ ** WhereLoop is not well-ordered. tag-20210426-1
152649152820
*/
152650
- if( isOrderDistinct
152651
- && iColumn>=0
152652
- && j>=pLoop->u.btree.nEq
152653
- && pIndex->pTable->aCol[iColumn].notNull==0
152654
- ){
152655
- isOrderDistinct = 0;
152821
+ if( isOrderDistinct ){
152822
+ if( iColumn>=0
152823
+ && j>=pLoop->u.btree.nEq
152824
+ && pIndex->pTable->aCol[iColumn].notNull==0
152825
+ ){
152826
+ isOrderDistinct = 0;
152827
+ }
152828
+ if( iColumn==XN_EXPR ){
152829
+ isOrderDistinct = 0;
152830
+ }
152656152831
}
152657152832
152658152833
/* Find the ORDER BY term that corresponds to the j-th column
152659152834
** of the index and mark that ORDER BY term off
152660152835
*/
@@ -154026,10 +154201,12 @@
154026154201
return pWInfo;
154027154202
154028154203
/* Jump here if malloc fails */
154029154204
whereBeginError:
154030154205
if( pWInfo ){
154206
+ testcase( pWInfo->pExprMods!=0 );
154207
+ whereUndoExprMods(pWInfo);
154031154208
pParse->nQueryLoop = pWInfo->savedNQueryLoop;
154032154209
whereInfoFree(db, pWInfo);
154033154210
}
154034154211
return 0;
154035154212
}
@@ -154325,20 +154502,13 @@
154325154502
if( db->flags & SQLITE_VdbeAddopTrace ) printf("TRANSLATE complete\n");
154326154503
#endif
154327154504
}
154328154505
}
154329154506
154330
- /* Undo all Expr node modifications */
154331
- while( pWInfo->pExprMods ){
154332
- WhereExprMod *p = pWInfo->pExprMods;
154333
- pWInfo->pExprMods = p->pNext;
154334
- memcpy(p->pExpr, &p->orig, sizeof(p->orig));
154335
- sqlite3DbFree(db, p);
154336
- }
154337
-
154338154507
/* Final cleanup
154339154508
*/
154509
+ if( pWInfo->pExprMods ) whereUndoExprMods(pWInfo);
154340154510
pParse->nQueryLoop = pWInfo->savedNQueryLoop;
154341154511
whereInfoFree(db, pWInfo);
154342154512
return;
154343154513
}
154344154514
@@ -155914,10 +156084,11 @@
155914156084
Vdbe *pVdbe; /* VDBE object */
155915156085
int addrGosub; /* OP_Gosub to this address to return one row */
155916156086
int regGosub; /* Register used with OP_Gosub(addrGosub) */
155917156087
int regArg; /* First in array of accumulator registers */
155918156088
int eDelete; /* See above */
156089
+ int regRowid;
155919156090
155920156091
WindowCsrAndReg start;
155921156092
WindowCsrAndReg current;
155922156093
WindowCsrAndReg end;
155923156094
};
@@ -156590,20 +156761,28 @@
156590156761
addrContinue = sqlite3VdbeCurrentAddr(v);
156591156762
156592156763
/* If this is a (RANGE BETWEEN a FOLLOWING AND b FOLLOWING) or
156593156764
** (RANGE BETWEEN b PRECEDING AND a PRECEDING) frame, ensure the
156594156765
** start cursor does not advance past the end cursor within the
156595
- ** temporary table. It otherwise might, if (a>b). */
156766
+ ** temporary table. It otherwise might, if (a>b). Also ensure that,
156767
+ ** if the input cursor is still finding new rows, that the end
156768
+ ** cursor does not go past it to EOF. */
156596156769
if( pMWin->eStart==pMWin->eEnd && regCountdown
156597
- && pMWin->eFrmType==TK_RANGE && op==WINDOW_AGGINVERSE
156770
+ && pMWin->eFrmType==TK_RANGE
156598156771
){
156599156772
int regRowid1 = sqlite3GetTempReg(pParse);
156600156773
int regRowid2 = sqlite3GetTempReg(pParse);
156601
- sqlite3VdbeAddOp2(v, OP_Rowid, p->start.csr, regRowid1);
156602
- sqlite3VdbeAddOp2(v, OP_Rowid, p->end.csr, regRowid2);
156603
- sqlite3VdbeAddOp3(v, OP_Ge, regRowid2, lblDone, regRowid1);
156604
- VdbeCoverage(v);
156774
+ if( op==WINDOW_AGGINVERSE ){
156775
+ sqlite3VdbeAddOp2(v, OP_Rowid, p->start.csr, regRowid1);
156776
+ sqlite3VdbeAddOp2(v, OP_Rowid, p->end.csr, regRowid2);
156777
+ sqlite3VdbeAddOp3(v, OP_Ge, regRowid2, lblDone, regRowid1);
156778
+ VdbeCoverage(v);
156779
+ }else if( p->regRowid ){
156780
+ sqlite3VdbeAddOp2(v, OP_Rowid, p->end.csr, regRowid1);
156781
+ sqlite3VdbeAddOp3(v, OP_Ge, p->regRowid, lblDone, regRowid1);
156782
+ VdbeCoverageNeverNull(v);
156783
+ }
156605156784
sqlite3ReleaseTempReg(pParse, regRowid1);
156606156785
sqlite3ReleaseTempReg(pParse, regRowid2);
156607156786
assert( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_FOLLOWING );
156608156787
}
156609156788
@@ -157096,11 +157275,10 @@
157096157275
int addrGosubFlush = 0; /* Address of OP_Gosub to flush: */
157097157276
int addrInteger = 0; /* Address of OP_Integer */
157098157277
int addrEmpty; /* Address of OP_Rewind in flush: */
157099157278
int regNew; /* Array of registers holding new input row */
157100157279
int regRecord; /* regNew array in record form */
157101
- int regRowid; /* Rowid for regRecord in eph table */
157102157280
int regNewPeer = 0; /* Peer values for new row (part of regNew) */
157103157281
int regPeer = 0; /* Peer values for current row */
157104157282
int regFlushPart = 0; /* Register for "Gosub flush_partition" */
157105157283
WindowCodeArg s; /* Context object for sub-routines */
157106157284
int lblWhereEnd; /* Label just before sqlite3WhereEnd() code */
@@ -157168,11 +157346,11 @@
157168157346
** samve values in record form, and the rowid used to insert said record
157169157347
** into the ephemeral table. */
157170157348
regNew = pParse->nMem+1;
157171157349
pParse->nMem += nInput;
157172157350
regRecord = ++pParse->nMem;
157173
- regRowid = ++pParse->nMem;
157351
+ s.regRowid = ++pParse->nMem;
157174157352
157175157353
/* If the window frame contains an "<expr> PRECEDING" or "<expr> FOLLOWING"
157176157354
** clause, allocate registers to store the results of evaluating each
157177157355
** <expr>. */
157178157356
if( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_FOLLOWING ){
@@ -157224,13 +157402,13 @@
157224157402
VdbeComment((v, "call flush_partition"));
157225157403
sqlite3VdbeAddOp3(v, OP_Copy, regNewPart, pMWin->regPart, nPart-1);
157226157404
}
157227157405
157228157406
/* Insert the new row into the ephemeral table */
157229
- sqlite3VdbeAddOp2(v, OP_NewRowid, csrWrite, regRowid);
157230
- sqlite3VdbeAddOp3(v, OP_Insert, csrWrite, regRecord, regRowid);
157231
- addrNe = sqlite3VdbeAddOp3(v, OP_Ne, pMWin->regOne, 0, regRowid);
157407
+ sqlite3VdbeAddOp2(v, OP_NewRowid, csrWrite, s.regRowid);
157408
+ sqlite3VdbeAddOp3(v, OP_Insert, csrWrite, regRecord, s.regRowid);
157409
+ addrNe = sqlite3VdbeAddOp3(v, OP_Ne, pMWin->regOne, 0, s.regRowid);
157232157410
VdbeCoverageNeverNull(v);
157233157411
157234157412
/* This block is run for the first row of each partition */
157235157413
s.regArg = windowInitAccum(pParse, pMWin);
157236157414
@@ -157344,10 +157522,11 @@
157344157522
if( pMWin->pPartition ){
157345157523
addrInteger = sqlite3VdbeAddOp2(v, OP_Integer, 0, regFlushPart);
157346157524
sqlite3VdbeJumpHere(v, addrGosubFlush);
157347157525
}
157348157526
157527
+ s.regRowid = 0;
157349157528
addrEmpty = sqlite3VdbeAddOp1(v, OP_Rewind, csrWrite);
157350157529
VdbeCoverage(v);
157351157530
if( pMWin->eEnd==TK_PRECEDING ){
157352157531
int bRPS = (pMWin->eStart==TK_PRECEDING && pMWin->eFrmType==TK_RANGE);
157353157532
windowCodeOp(&s, WINDOW_AGGSTEP, regEnd, 0);
@@ -161012,12 +161191,11 @@
161012161191
break;
161013161192
case 16: /* ifnotexists ::= IF NOT EXISTS */
161014161193
{yymsp[-2].minor.yy60 = 1;}
161015161194
break;
161016161195
case 17: /* temp ::= TEMP */
161017
- case 46: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==46);
161018
-{yymsp[0].minor.yy60 = 1;}
161196
+{yymsp[0].minor.yy60 = pParse->db->init.busy==0;}
161019161197
break;
161020161198
case 19: /* create_table_args ::= LP columnlist conslist_opt RP table_options */
161021161199
{
161022161200
sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy60,0);
161023161201
}
@@ -161125,10 +161303,13 @@
161125161303
case 43: /* generated ::= LP expr RP */
161126161304
{sqlite3AddGenerated(pParse,yymsp[-1].minor.yy602,0);}
161127161305
break;
161128161306
case 44: /* generated ::= LP expr RP ID */
161129161307
{sqlite3AddGenerated(pParse,yymsp[-2].minor.yy602,&yymsp[0].minor.yy0);}
161308
+ break;
161309
+ case 46: /* autoinc ::= AUTOINCR */
161310
+{yymsp[0].minor.yy60 = 1;}
161130161311
break;
161131161312
case 47: /* refargs ::= */
161132161313
{ yymsp[1].minor.yy60 = OE_None*0x0101; /* EV: R-19803-45884 */}
161133161314
break;
161134161315
case 48: /* refargs ::= refargs refarg */
@@ -162296,11 +162477,15 @@
162296162477
case 330: /* window_clause ::= WINDOW windowdefn_list */
162297162478
{ yymsp[-1].minor.yy19 = yymsp[0].minor.yy19; }
162298162479
break;
162299162480
case 331: /* filter_over ::= filter_clause over_clause */
162300162481
{
162301
- yymsp[0].minor.yy19->pFilter = yymsp[-1].minor.yy602;
162482
+ if( yymsp[0].minor.yy19 ){
162483
+ yymsp[0].minor.yy19->pFilter = yymsp[-1].minor.yy602;
162484
+ }else{
162485
+ sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy602);
162486
+ }
162302162487
yylhsminor.yy19 = yymsp[0].minor.yy19;
162303162488
}
162304162489
yymsp[-1].minor.yy19 = yylhsminor.yy19;
162305162490
break;
162306162491
case 333: /* filter_over ::= filter_clause */
@@ -162795,10 +162980,11 @@
162795162980
#define CC_TILDA 25 /* '~' */
162796162981
#define CC_DOT 26 /* '.' */
162797162982
#define CC_ID 27 /* unicode characters usable in IDs */
162798162983
#define CC_ILLEGAL 28 /* Illegal character */
162799162984
#define CC_NUL 29 /* 0x00 */
162985
+#define CC_BOM 30 /* First byte of UTF8 BOM: 0xEF 0xBB 0xBF */
162800162986
162801162987
static const unsigned char aiClass[] = {
162802162988
#ifdef SQLITE_ASCII
162803162989
/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf */
162804162990
/* 0x */ 29, 28, 28, 28, 28, 28, 28, 28, 28, 7, 7, 28, 7, 7, 28, 28,
@@ -162807,18 +162993,18 @@
162807162993
/* 3x */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 19, 12, 14, 13, 6,
162808162994
/* 4x */ 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
162809162995
/* 5x */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 9, 28, 28, 28, 2,
162810162996
/* 6x */ 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
162811162997
/* 7x */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 28, 10, 28, 25, 28,
162812
-/* 8x */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
162813
-/* 9x */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
162814
-/* Ax */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
162815
-/* Bx */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
162816
-/* Cx */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
162817
-/* Dx */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
162818
-/* Ex */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
162819
-/* Fx */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
162998
+/* 8x */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
162999
+/* 9x */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
163000
+/* Ax */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
163001
+/* Bx */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
163002
+/* Cx */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
163003
+/* Dx */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
163004
+/* Ex */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 30,
163005
+/* Fx */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27
162820163006
#endif
162821163007
#ifdef SQLITE_EBCDIC
162822163008
/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf */
162823163009
/* 0x */ 29, 28, 28, 28, 28, 7, 28, 28, 28, 28, 28, 28, 7, 7, 28, 28,
162824163010
/* 1x */ 28, 28, 28, 28, 28, 7, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
@@ -163757,10 +163943,18 @@
163757163943
** SQL keywords start with the letter 'x'. Fall through */
163758163944
/* no break */ deliberate_fall_through
163759163945
}
163760163946
case CC_KYWD:
163761163947
case CC_ID: {
163948
+ i = 1;
163949
+ break;
163950
+ }
163951
+ case CC_BOM: {
163952
+ if( z[1]==0xbb && z[2]==0xbf ){
163953
+ *tokenType = TK_SPACE;
163954
+ return 3;
163955
+ }
163762163956
i = 1;
163763163957
break;
163764163958
}
163765163959
case CC_NUL: {
163766163960
*tokenType = TK_ILLEGAL;
@@ -165745,11 +165939,11 @@
165745165939
}
165746165940
165747165941
/*
165748165942
** Two variations on the public interface for closing a database
165749165943
** connection. The sqlite3_close() version returns SQLITE_BUSY and
165750
-** leaves the connection option if there are unfinalized prepared
165944
+** leaves the connection open if there are unfinalized prepared
165751165945
** statements or unfinished sqlite3_backups. The sqlite3_close_v2()
165752165946
** version forces the connection to become a zombie if there are
165753165947
** unclosed resources, and arranges for deallocation when the last
165754165948
** prepare statement or sqlite3_backup closes.
165755165949
*/
@@ -175552,20 +175746,19 @@
175552175746
175553175747
/* Determine which, if any, tokens in the expression should be deferred. */
175554175748
#ifndef SQLITE_DISABLE_FTS4_DEFERRED
175555175749
if( rc==SQLITE_OK && nToken>1 && pTab->bFts4 ){
175556175750
Fts3TokenAndCost *aTC;
175557
- Fts3Expr **apOr;
175558175751
aTC = (Fts3TokenAndCost *)sqlite3_malloc64(
175559175752
sizeof(Fts3TokenAndCost) * nToken
175560175753
+ sizeof(Fts3Expr *) * nOr * 2
175561175754
);
175562
- apOr = (Fts3Expr **)&aTC[nToken];
175563175755
175564175756
if( !aTC ){
175565175757
rc = SQLITE_NOMEM;
175566175758
}else{
175759
+ Fts3Expr **apOr = (Fts3Expr **)&aTC[nToken];
175567175760
int ii;
175568175761
Fts3TokenAndCost *pTC = aTC;
175569175762
Fts3Expr **ppOr = apOr;
175570175763
175571175764
fts3EvalTokenCosts(pCsr, 0, pCsr->pExpr, &pTC, &ppOr, &rc);
@@ -176937,10 +177130,11 @@
176937177130
/* In case this cursor is being reused, close and zero it. */
176938177131
testcase(pCsr->filter.zTerm);
176939177132
sqlite3Fts3SegReaderFinish(&pCsr->csr);
176940177133
sqlite3_free((void *)pCsr->filter.zTerm);
176941177134
sqlite3_free(pCsr->aStat);
177135
+ sqlite3_free(pCsr->zStop);
176942177136
memset(&pCsr->csr, 0, ((u8*)&pCsr[1]) - (u8*)&pCsr->csr);
176943177137
176944177138
pCsr->filter.flags = FTS3_SEGMENT_REQUIRE_POS|FTS3_SEGMENT_IGNORE_EMPTY;
176945177139
if( isScan ) pCsr->filter.flags |= FTS3_SEGMENT_SCAN;
176946177140
@@ -182458,11 +182652,11 @@
182458182652
rc = (pLhs->aNode==0) - (pRhs->aNode==0);
182459182653
}
182460182654
if( rc==0 ){
182461182655
rc = pRhs->iIdx - pLhs->iIdx;
182462182656
}
182463
- assert( rc!=0 );
182657
+ assert_fts3_nc( rc!=0 );
182464182658
return rc;
182465182659
}
182466182660
182467182661
/*
182468182662
** A different comparison function for SegReader structures. In this
@@ -186468,10 +186662,14 @@
186468186662
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
186469186663
186470186664
/* #include <string.h> */
186471186665
/* #include <assert.h> */
186472186666
186667
+#ifndef SQLITE_AMALGAMATION
186668
+typedef sqlite3_int64 i64;
186669
+#endif
186670
+
186473186671
/*
186474186672
** Characters that may appear in the second argument to matchinfo().
186475186673
*/
186476186674
#define FTS3_MATCHINFO_NPHRASE 'p' /* 1 value */
186477186675
#define FTS3_MATCHINFO_NCOL 'c' /* 1 value */
@@ -186518,13 +186716,13 @@
186518186716
};
186519186717
186520186718
struct SnippetPhrase {
186521186719
int nToken; /* Number of tokens in phrase */
186522186720
char *pList; /* Pointer to start of phrase position list */
186523
- int iHead; /* Next value in position list */
186721
+ i64 iHead; /* Next value in position list */
186524186722
char *pHead; /* Position list data following iHead */
186525
- int iTail; /* Next value in trailing position list */
186723
+ i64 iTail; /* Next value in trailing position list */
186526186724
char *pTail; /* Position list data following iTail */
186527186725
};
186528186726
186529186727
struct SnippetFragment {
186530186728
int iCol; /* Column snippet is extracted from */
@@ -186685,11 +186883,11 @@
186685186883
** When this function is called, *pp points to the start of an element of
186686186884
** the list. *piPos contains the value of the previous entry in the list.
186687186885
** After it returns, *piPos contains the value of the next element of the
186688186886
** list and *pp is advanced to the following varint.
186689186887
*/
186690
-static void fts3GetDeltaPosition(char **pp, int *piPos){
186888
+static void fts3GetDeltaPosition(char **pp, i64 *piPos){
186691186889
int iVal;
186692186890
*pp += fts3GetVarint32(*pp, &iVal);
186693186891
*piPos += (iVal-2);
186694186892
}
186695186893
@@ -186794,14 +186992,14 @@
186794186992
/*
186795186993
** Advance the position list iterator specified by the first two
186796186994
** arguments so that it points to the first element with a value greater
186797186995
** than or equal to parameter iNext.
186798186996
*/
186799
-static void fts3SnippetAdvance(char **ppIter, int *piIter, int iNext){
186997
+static void fts3SnippetAdvance(char **ppIter, i64 *piIter, int iNext){
186800186998
char *pIter = *ppIter;
186801186999
if( pIter ){
186802
- int iIter = *piIter;
187000
+ i64 iIter = *piIter;
186803187001
186804187002
while( iIter<iNext ){
186805187003
if( 0==(*pIter & 0xFE) ){
186806187004
iIter = -1;
186807187005
pIter = 0;
@@ -186880,11 +187078,11 @@
186880187078
186881187079
for(i=0; i<pIter->nPhrase; i++){
186882187080
SnippetPhrase *pPhrase = &pIter->aPhrase[i];
186883187081
if( pPhrase->pTail ){
186884187082
char *pCsr = pPhrase->pTail;
186885
- int iCsr = pPhrase->iTail;
187083
+ i64 iCsr = pPhrase->iTail;
186886187084
186887187085
while( iCsr<(iStart+pIter->nSnippet) && iCsr>=iStart ){
186888187086
int j;
186889187087
u64 mPhrase = (u64)1 << (i%64);
186890187088
u64 mPos = (u64)1 << (iCsr - iStart);
@@ -186926,11 +187124,11 @@
186926187124
186927187125
pPhrase->nToken = pExpr->pPhrase->nToken;
186928187126
rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pCsr);
186929187127
assert( rc==SQLITE_OK || pCsr==0 );
186930187128
if( pCsr ){
186931
- int iFirst = 0;
187129
+ i64 iFirst = 0;
186932187130
pPhrase->pList = pCsr;
186933187131
fts3GetDeltaPosition(&pCsr, &iFirst);
186934187132
if( iFirst<0 ){
186935187133
rc = FTS_CORRUPT_VTAB;
186936187134
}else{
@@ -187990,12 +188188,12 @@
187990188188
typedef struct TermOffset TermOffset;
187991188189
typedef struct TermOffsetCtx TermOffsetCtx;
187992188190
187993188191
struct TermOffset {
187994188192
char *pList; /* Position-list */
187995
- int iPos; /* Position just read from pList */
187996
- int iOff; /* Offset of this term from read positions */
188193
+ i64 iPos; /* Position just read from pList */
188194
+ i64 iOff; /* Offset of this term from read positions */
187997188195
};
187998188196
187999188197
struct TermOffsetCtx {
188000188198
Fts3Cursor *pCsr;
188001188199
int iCol; /* Column of table to populate aTerm for */
@@ -188010,11 +188208,11 @@
188010188208
static int fts3ExprTermOffsetInit(Fts3Expr *pExpr, int iPhrase, void *ctx){
188011188209
TermOffsetCtx *p = (TermOffsetCtx *)ctx;
188012188210
int nTerm; /* Number of tokens in phrase */
188013188211
int iTerm; /* For looping through nTerm phrase terms */
188014188212
char *pList; /* Pointer to position list for phrase */
188015
- int iPos = 0; /* First position in position-list */
188213
+ i64 iPos = 0; /* First position in position-list */
188016188214
int rc;
188017188215
188018188216
UNUSED_PARAMETER(iPhrase);
188019188217
rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pList);
188020188218
nTerm = pExpr->pPhrase->nToken;
@@ -190886,12 +191084,12 @@
190886191084
if( pStr->zBuf==0 ){
190887191085
jsonInit(pStr, ctx);
190888191086
jsonAppendChar(pStr, '[');
190889191087
}else if( pStr->nUsed>1 ){
190890191088
jsonAppendChar(pStr, ',');
190891
- pStr->pCtx = ctx;
190892191089
}
191090
+ pStr->pCtx = ctx;
190893191091
jsonAppendValue(pStr, argv[0]);
190894191092
}
190895191093
}
190896191094
static void jsonArrayCompute(sqlite3_context *ctx, int isFinal){
190897191095
JsonString *pStr;
@@ -190947,26 +191145,27 @@
190947191145
/* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will
190948191146
** always have been called to initalize it */
190949191147
if( NEVER(!pStr) ) return;
190950191148
#endif
190951191149
z = pStr->zBuf;
190952
- for(i=1; (c = z[i])!=',' || inStr || nNest; i++){
190953
- if( i>=pStr->nUsed ){
190954
- pStr->nUsed = 1;
190955
- return;
190956
- }
191150
+ for(i=1; i<pStr->nUsed && ((c = z[i])!=',' || inStr || nNest); i++){
190957191151
if( c=='"' ){
190958191152
inStr = !inStr;
190959191153
}else if( c=='\\' ){
190960191154
i++;
190961191155
}else if( !inStr ){
190962191156
if( c=='{' || c=='[' ) nNest++;
190963191157
if( c=='}' || c==']' ) nNest--;
190964191158
}
190965191159
}
190966
- pStr->nUsed -= i;
190967
- memmove(&z[1], &z[i+1], (size_t)pStr->nUsed-1);
191160
+ if( i<pStr->nUsed ){
191161
+ pStr->nUsed -= i;
191162
+ memmove(&z[1], &z[i+1], (size_t)pStr->nUsed-1);
191163
+ z[pStr->nUsed] = 0;
191164
+ }else{
191165
+ pStr->nUsed = 1;
191166
+ }
190968191167
}
190969191168
#else
190970191169
# define jsonGroupInverse 0
190971191170
#endif
190972191171
@@ -195512,15 +195711,20 @@
195512195711
*/
195513195712
static void rtreedepth(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){
195514195713
UNUSED_PARAMETER(nArg);
195515195714
if( sqlite3_value_type(apArg[0])!=SQLITE_BLOB
195516195715
|| sqlite3_value_bytes(apArg[0])<2
195716
+
195517195717
){
195518195718
sqlite3_result_error(ctx, "Invalid argument to rtreedepth()", -1);
195519195719
}else{
195520195720
u8 *zBlob = (u8 *)sqlite3_value_blob(apArg[0]);
195521
- sqlite3_result_int(ctx, readInt16(zBlob));
195721
+ if( zBlob ){
195722
+ sqlite3_result_int(ctx, readInt16(zBlob));
195723
+ }else{
195724
+ sqlite3_result_error_nomem(ctx);
195725
+ }
195522195726
}
195523195727
}
195524195728
195525195729
/*
195526195730
** Context object passed between the various routines that make up the
@@ -206045,17 +206249,19 @@
206045206249
** Session handle structure.
206046206250
*/
206047206251
struct sqlite3_session {
206048206252
sqlite3 *db; /* Database handle session is attached to */
206049206253
char *zDb; /* Name of database session is attached to */
206254
+ int bEnableSize; /* True if changeset_size() enabled */
206050206255
int bEnable; /* True if currently recording */
206051206256
int bIndirect; /* True if all changes are indirect */
206052206257
int bAutoAttach; /* True to auto-attach tables */
206053206258
int rc; /* Non-zero if an error has occurred */
206054206259
void *pFilterCtx; /* First argument to pass to xTableFilter */
206055206260
int (*xTableFilter)(void *pCtx, const char *zTab);
206056206261
i64 nMalloc; /* Number of bytes of data allocated */
206262
+ i64 nMaxChangesetSize;
206057206263
sqlite3_value *pZeroBlob; /* Value containing X'' */
206058206264
sqlite3_session *pNext; /* Next session object on same db. */
206059206265
SessionTable *pTable; /* List of attached tables */
206060206266
SessionHook hook; /* APIs to grab new and old data with */
206061206267
};
@@ -206294,12 +206500,13 @@
206294206500
/*
206295206501
** For each row modified during a session, there exists a single instance of
206296206502
** this structure stored in a SessionTable.aChange[] hash table.
206297206503
*/
206298206504
struct SessionChange {
206299
- int op; /* One of UPDATE, DELETE, INSERT */
206300
- int bIndirect; /* True if this change is "indirect" */
206505
+ u8 op; /* One of UPDATE, DELETE, INSERT */
206506
+ u8 bIndirect; /* True if this change is "indirect" */
206507
+ int nMaxSize; /* Max size of eventual changeset record */
206301206508
int nRecord; /* Number of bytes in buffer aRecord[] */
206302206509
u8 *aRecord; /* Buffer containing old.* record */
206303206510
SessionChange *pNext; /* For hash-table collisions */
206304206511
};
206305206512
@@ -207124,10 +207331,16 @@
207124207331
}
207125207332
}
207126207333
if( 0==sqlite3_stricmp("sqlite_stat1", pTab->zName) ){
207127207334
pTab->bStat1 = 1;
207128207335
}
207336
+
207337
+ if( pSession->bEnableSize ){
207338
+ pSession->nMaxChangesetSize += (
207339
+ 1 + sessionVarintLen(pTab->nCol) + pTab->nCol + strlen(pTab->zName)+1
207340
+ );
207341
+ }
207129207342
}
207130207343
}
207131207344
return (pSession->rc || pTab->abPK==0);
207132207345
}
207133207346
@@ -207169,10 +207382,107 @@
207169207382
static int sessionStat1Depth(void *pCtx){
207170207383
SessionStat1Ctx *p = (SessionStat1Ctx*)pCtx;
207171207384
return p->hook.xDepth(p->hook.pCtx);
207172207385
}
207173207386
207387
+static int sessionUpdateMaxSize(
207388
+ int op,
207389
+ sqlite3_session *pSession, /* Session object pTab is attached to */
207390
+ SessionTable *pTab, /* Table that change applies to */
207391
+ SessionChange *pC /* Update pC->nMaxSize */
207392
+){
207393
+ i64 nNew = 2;
207394
+ if( pC->op==SQLITE_INSERT ){
207395
+ if( op!=SQLITE_DELETE ){
207396
+ int ii;
207397
+ for(ii=0; ii<pTab->nCol; ii++){
207398
+ sqlite3_value *p = 0;
207399
+ pSession->hook.xNew(pSession->hook.pCtx, ii, &p);
207400
+ sessionSerializeValue(0, p, &nNew);
207401
+ }
207402
+ }
207403
+ }else if( op==SQLITE_DELETE ){
207404
+ nNew += pC->nRecord;
207405
+ if( sqlite3_preupdate_blobwrite(pSession->db)>=0 ){
207406
+ nNew += pC->nRecord;
207407
+ }
207408
+ }else{
207409
+ int ii;
207410
+ u8 *pCsr = pC->aRecord;
207411
+ for(ii=0; ii<pTab->nCol; ii++){
207412
+ int bChanged = 1;
207413
+ int nOld = 0;
207414
+ int eType;
207415
+ sqlite3_value *p = 0;
207416
+ pSession->hook.xNew(pSession->hook.pCtx, ii, &p);
207417
+ if( p==0 ){
207418
+ return SQLITE_NOMEM;
207419
+ }
207420
+
207421
+ eType = *pCsr++;
207422
+ switch( eType ){
207423
+ case SQLITE_NULL:
207424
+ bChanged = sqlite3_value_type(p)!=SQLITE_NULL;
207425
+ break;
207426
+
207427
+ case SQLITE_FLOAT:
207428
+ case SQLITE_INTEGER: {
207429
+ if( eType==sqlite3_value_type(p) ){
207430
+ sqlite3_int64 iVal = sessionGetI64(pCsr);
207431
+ if( eType==SQLITE_INTEGER ){
207432
+ bChanged = (iVal!=sqlite3_value_int64(p));
207433
+ }else{
207434
+ double dVal;
207435
+ memcpy(&dVal, &iVal, 8);
207436
+ bChanged = (dVal!=sqlite3_value_double(p));
207437
+ }
207438
+ }
207439
+ nOld = 8;
207440
+ pCsr += 8;
207441
+ break;
207442
+ }
207443
+
207444
+ default: {
207445
+ int nByte;
207446
+ nOld = sessionVarintGet(pCsr, &nByte);
207447
+ pCsr += nOld;
207448
+ nOld += nByte;
207449
+ assert( eType==SQLITE_TEXT || eType==SQLITE_BLOB );
207450
+ if( eType==sqlite3_value_type(p)
207451
+ && nByte==sqlite3_value_bytes(p)
207452
+ && (nByte==0 || 0==memcmp(pCsr, sqlite3_value_blob(p), nByte))
207453
+ ){
207454
+ bChanged = 0;
207455
+ }
207456
+ pCsr += nByte;
207457
+ break;
207458
+ }
207459
+ }
207460
+
207461
+ if( bChanged && pTab->abPK[ii] ){
207462
+ nNew = pC->nRecord + 2;
207463
+ break;
207464
+ }
207465
+
207466
+ if( bChanged ){
207467
+ nNew += 1 + nOld;
207468
+ sessionSerializeValue(0, p, &nNew);
207469
+ }else if( pTab->abPK[ii] ){
207470
+ nNew += 2 + nOld;
207471
+ }else{
207472
+ nNew += 2;
207473
+ }
207474
+ }
207475
+ }
207476
+
207477
+ if( nNew>pC->nMaxSize ){
207478
+ int nIncr = nNew - pC->nMaxSize;
207479
+ pC->nMaxSize = nNew;
207480
+ pSession->nMaxChangesetSize += nIncr;
207481
+ }
207482
+ return SQLITE_OK;
207483
+}
207174207484
207175207485
/*
207176207486
** This function is only called from with a pre-update-hook reporting a
207177207487
** change on table pTab (attached to session pSession). The type of change
207178207488
** (UPDATE, INSERT, DELETE) is specified by the first argument.
@@ -207242,11 +207552,10 @@
207242207552
207243207553
if( pC==0 ){
207244207554
/* Create a new change object containing all the old values (if
207245207555
** this is an SQLITE_UPDATE or SQLITE_DELETE), or just the PK
207246207556
** values (if this is an INSERT). */
207247
- SessionChange *pChange; /* New change object */
207248207557
sqlite3_int64 nByte; /* Number of bytes to allocate */
207249207558
int i; /* Used to iterate through columns */
207250207559
207251207560
assert( rc==SQLITE_OK );
207252207561
pTab->nEntry++;
@@ -207268,17 +207577,17 @@
207268207577
rc = sessionSerializeValue(0, p, &nByte);
207269207578
if( rc!=SQLITE_OK ) goto error_out;
207270207579
}
207271207580
207272207581
/* Allocate the change object */
207273
- pChange = (SessionChange *)sessionMalloc64(pSession, nByte);
207274
- if( !pChange ){
207582
+ pC = (SessionChange *)sessionMalloc64(pSession, nByte);
207583
+ if( !pC ){
207275207584
rc = SQLITE_NOMEM;
207276207585
goto error_out;
207277207586
}else{
207278
- memset(pChange, 0, sizeof(SessionChange));
207279
- pChange->aRecord = (u8 *)&pChange[1];
207587
+ memset(pC, 0, sizeof(SessionChange));
207588
+ pC->aRecord = (u8 *)&pC[1];
207280207589
}
207281207590
207282207591
/* Populate the change object. None of the preupdate_old(),
207283207592
** preupdate_new() or SerializeValue() calls below may fail as all
207284207593
** required values and encodings have already been cached in memory.
@@ -207289,21 +207598,21 @@
207289207598
if( op!=SQLITE_INSERT ){
207290207599
pSession->hook.xOld(pSession->hook.pCtx, i, &p);
207291207600
}else if( pTab->abPK[i] ){
207292207601
pSession->hook.xNew(pSession->hook.pCtx, i, &p);
207293207602
}
207294
- sessionSerializeValue(&pChange->aRecord[nByte], p, &nByte);
207603
+ sessionSerializeValue(&pC->aRecord[nByte], p, &nByte);
207295207604
}
207296207605
207297207606
/* Add the change to the hash-table */
207298207607
if( pSession->bIndirect || pSession->hook.xDepth(pSession->hook.pCtx) ){
207299
- pChange->bIndirect = 1;
207608
+ pC->bIndirect = 1;
207300207609
}
207301
- pChange->nRecord = nByte;
207302
- pChange->op = op;
207303
- pChange->pNext = pTab->apChange[iHash];
207304
- pTab->apChange[iHash] = pChange;
207610
+ pC->nRecord = nByte;
207611
+ pC->op = op;
207612
+ pC->pNext = pTab->apChange[iHash];
207613
+ pTab->apChange[iHash] = pC;
207305207614
207306207615
}else if( pC->bIndirect ){
207307207616
/* If the existing change is considered "indirect", but this current
207308207617
** change is "direct", mark the change object as direct. */
207309207618
if( pSession->hook.xDepth(pSession->hook.pCtx)==0
@@ -207310,11 +207619,17 @@
207310207619
&& pSession->bIndirect==0
207311207620
){
207312207621
pC->bIndirect = 0;
207313207622
}
207314207623
}
207624
+
207625
+ assert( rc==SQLITE_OK );
207626
+ if( pSession->bEnableSize ){
207627
+ rc = sessionUpdateMaxSize(op, pSession, pTab, pC);
207628
+ }
207315207629
}
207630
+
207316207631
207317207632
/* If an error has occurred, mark the session object as failed. */
207318207633
error_out:
207319207634
if( pTab->bStat1 ){
207320207635
pSession->hook = stat1.hook;
@@ -208523,11 +208838,15 @@
208523208838
SQLITE_API int sqlite3session_changeset(
208524208839
sqlite3_session *pSession, /* Session object */
208525208840
int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
208526208841
void **ppChangeset /* OUT: Buffer containing changeset */
208527208842
){
208528
- return sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset, ppChangeset);
208843
+ int rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset,ppChangeset);
208844
+ assert( rc || pnChangeset==0
208845
+ || pSession->bEnableSize==0 || *pnChangeset<=pSession->nMaxChangesetSize
208846
+ );
208847
+ return rc;
208529208848
}
208530208849
208531208850
/*
208532208851
** Streaming version of sqlite3session_changeset().
208533208852
*/
@@ -208614,10 +208933,43 @@
208614208933
** Return the amount of heap memory in use.
208615208934
*/
208616208935
SQLITE_API sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession){
208617208936
return pSession->nMalloc;
208618208937
}
208938
+
208939
+/*
208940
+** Configure the session object passed as the first argument.
208941
+*/
208942
+SQLITE_API int sqlite3session_object_config(sqlite3_session *pSession, int op, void *pArg){
208943
+ int rc = SQLITE_OK;
208944
+ switch( op ){
208945
+ case SQLITE_SESSION_OBJCONFIG_SIZE: {
208946
+ int iArg = *(int*)pArg;
208947
+ if( iArg>=0 ){
208948
+ if( pSession->pTable ){
208949
+ rc = SQLITE_MISUSE;
208950
+ }else{
208951
+ pSession->bEnableSize = (iArg!=0);
208952
+ }
208953
+ }
208954
+ *(int*)pArg = pSession->bEnableSize;
208955
+ break;
208956
+ }
208957
+
208958
+ default:
208959
+ rc = SQLITE_MISUSE;
208960
+ }
208961
+
208962
+ return rc;
208963
+}
208964
+
208965
+/*
208966
+** Return the maximum size of sqlite3session_changeset() output.
208967
+*/
208968
+SQLITE_API sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession){
208969
+ return pSession->nMaxChangesetSize;
208970
+}
208619208971
208620208972
/*
208621208973
** Do the work for either sqlite3changeset_start() or start_strm().
208622208974
*/
208623208975
static int sessionChangesetStart(
@@ -216198,11 +216550,11 @@
216198216550
pRet->db = db;
216199216551
pRet->iCookie = -1;
216200216552
216201216553
nByte = nArg * (sizeof(char*) + sizeof(u8));
216202216554
pRet->azCol = (char**)sqlite3Fts5MallocZero(&rc, nByte);
216203
- pRet->abUnindexed = (u8*)&pRet->azCol[nArg];
216555
+ pRet->abUnindexed = pRet->azCol ? (u8*)&pRet->azCol[nArg] : 0;
216204216556
pRet->zDb = sqlite3Fts5Strndup(&rc, azArg[1], -1);
216205216557
pRet->zName = sqlite3Fts5Strndup(&rc, azArg[2], -1);
216206216558
pRet->bColumnsize = 1;
216207216559
pRet->eDetail = FTS5_DETAIL_FULL;
216208216560
#ifdef SQLITE_DEBUG
@@ -219034,10 +219386,11 @@
219034219386
}
219035219387
219036219388
return pRet;
219037219389
}
219038219390
219391
+#ifdef SQLITE_TEST
219039219392
static char *fts5ExprTermPrint(Fts5ExprTerm *pTerm){
219040219393
sqlite3_int64 nByte = 0;
219041219394
Fts5ExprTerm *p;
219042219395
char *zQuoted;
219043219396
@@ -219400,16 +219753,18 @@
219400219753
iCode = sqlite3_value_int(apVal[0]);
219401219754
if( nArg==2 ) bRemoveDiacritics = sqlite3_value_int(apVal[1]);
219402219755
sqlite3_result_int(pCtx, sqlite3Fts5UnicodeFold(iCode, bRemoveDiacritics));
219403219756
}
219404219757
}
219758
+#endif /* ifdef SQLITE_TEST */
219405219759
219406219760
/*
219407219761
** This is called during initialization to register the fts5_expr() scalar
219408219762
** UDF with the SQLite handle passed as the only argument.
219409219763
*/
219410219764
static int sqlite3Fts5ExprInit(Fts5Global *pGlobal, sqlite3 *db){
219765
+#ifdef SQLITE_TEST
219411219766
struct Fts5ExprFunc {
219412219767
const char *z;
219413219768
void (*x)(sqlite3_context*,int,sqlite3_value**);
219414219769
} aFunc[] = {
219415219770
{ "fts5_expr", fts5ExprFunctionHr },
@@ -219423,10 +219778,14 @@
219423219778
219424219779
for(i=0; rc==SQLITE_OK && i<ArraySize(aFunc); i++){
219425219780
struct Fts5ExprFunc *p = &aFunc[i];
219426219781
rc = sqlite3_create_function(db, p->z, -1, SQLITE_UTF8, pCtx, p->x, 0, 0);
219427219782
}
219783
+#else
219784
+ int rc = SQLITE_OK;
219785
+ UNUSED_PARAM2(pGlobal,db);
219786
+#endif
219428219787
219429219788
/* Avoid warnings indicating that sqlite3Fts5ParserTrace() and
219430219789
** sqlite3Fts5ParserFallback() are unused */
219431219790
#ifndef NDEBUG
219432219791
(void)sqlite3Fts5ParserTrace;
@@ -220669,11 +221028,11 @@
220669221028
Fts5StructureSegment *pSeg; /* Segment to iterate through */
220670221029
int flags; /* Mask of configuration flags */
220671221030
int iLeafPgno; /* Current leaf page number */
220672221031
Fts5Data *pLeaf; /* Current leaf data */
220673221032
Fts5Data *pNextLeaf; /* Leaf page (iLeafPgno+1) */
220674
- int iLeafOffset; /* Byte offset within current leaf */
221033
+ i64 iLeafOffset; /* Byte offset within current leaf */
220675221034
220676221035
/* Next method */
220677221036
void (*xNext)(Fts5Index*, Fts5SegIter*, int*);
220678221037
220679221038
/* The page and offset from which the current term was read. The offset
@@ -221849,11 +222208,11 @@
221849222208
}
221850222209
}
221851222210
221852222211
static void fts5SegIterLoadRowid(Fts5Index *p, Fts5SegIter *pIter){
221853222212
u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
221854
- int iOff = pIter->iLeafOffset;
222213
+ i64 iOff = pIter->iLeafOffset;
221855222214
221856222215
ASSERT_SZLEAF_OK(pIter->pLeaf);
221857222216
if( iOff>=pIter->pLeaf->szLeaf ){
221858222217
fts5SegIterNextPage(p, pIter);
221859222218
if( pIter->pLeaf==0 ){
@@ -221882,11 +222241,11 @@
221882222241
** the first position list. The position list belonging to document
221883222242
** (Fts5SegIter.iRowid).
221884222243
*/
221885222244
static void fts5SegIterLoadTerm(Fts5Index *p, Fts5SegIter *pIter, int nKeep){
221886222245
u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
221887
- int iOff = pIter->iLeafOffset; /* Offset to read at */
222246
+ i64 iOff = pIter->iLeafOffset; /* Offset to read at */
221888222247
int nNew; /* Bytes of new data */
221889222248
221890222249
iOff += fts5GetVarint32(&a[iOff], nNew);
221891222250
if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){
221892222251
p->rc = FTS5_CORRUPT;
@@ -224779,18 +225138,18 @@
224779225138
if( pgsz>=(pBuf->n + pPgidx->n + nDoclist + 1) ){
224780225139
/* The entire doclist will fit on the current leaf. */
224781225140
fts5BufferSafeAppendBlob(pBuf, pDoclist, nDoclist);
224782225141
}else{
224783225142
i64 iRowid = 0;
224784
- i64 iDelta = 0;
225143
+ u64 iDelta = 0;
224785225144
int iOff = 0;
224786225145
224787225146
/* The entire doclist will not fit on this leaf. The following
224788225147
** loop iterates through the poslists that make up the current
224789225148
** doclist. */
224790225149
while( p->rc==SQLITE_OK && iOff<nDoclist ){
224791
- iOff += fts5GetVarint(&pDoclist[iOff], (u64*)&iDelta);
225150
+ iOff += fts5GetVarint(&pDoclist[iOff], &iDelta);
224792225151
iRowid += iDelta;
224793225152
224794225153
if( writer.bFirstRowidInPage ){
224795225154
fts5PutU16(&pBuf->p[0], (u16)pBuf->n); /* first rowid on page */
224796225155
pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid);
@@ -225317,11 +225676,12 @@
225317225676
sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, pHead->iPos);
225318225677
}
225319225678
nTail = pHead->iter.nPoslist - pHead->iOff;
225320225679
225321225680
/* WRITEPOSLISTSIZE */
225322
- assert( tmp.n+nTail<=nTmp );
225681
+ assert_nc( tmp.n+nTail<=nTmp );
225682
+ assert( tmp.n+nTail<=nTmp+nMerge*10 );
225323225683
if( tmp.n+nTail>nTmp-FTS5_DATA_ZERO_PADDING ){
225324225684
if( p->rc==SQLITE_OK ) p->rc = FTS5_CORRUPT;
225325225685
break;
225326225686
}
225327225687
fts5BufferSafeAppendVarint(&out, (tmp.n+nTail) * 2);
@@ -226958,10 +227318,11 @@
226958227318
);
226959227319
}
226960227320
return rc;
226961227321
#else
226962227322
return SQLITE_OK;
227323
+ UNUSED_PARAM(db);
226963227324
#endif
226964227325
}
226965227326
226966227327
226967227328
static int sqlite3Fts5IndexReset(Fts5Index *p){
@@ -229762,11 +230123,11 @@
229762230123
int nArg, /* Number of args */
229763230124
sqlite3_value **apUnused /* Function arguments */
229764230125
){
229765230126
assert( nArg==0 );
229766230127
UNUSED_PARAM2(nArg, apUnused);
229767
- sqlite3_result_text(pCtx, "fts5: 2021-04-07 13:20:34 c22e47c77a35ebcd1fdfc0caea9119dd5e24e76d5fdd0f2ffbb58205a7242297", -1, SQLITE_TRANSIENT);
230128
+ sqlite3_result_text(pCtx, "fts5: 2021-04-27 17:18:10 ff3538ae37a02f4f36a15cddd1245171e724aac9c84b2e576980fd3806302775", -1, SQLITE_TRANSIENT);
229768230129
}
229769230130
229770230131
/*
229771230132
** Return true if zName is the extension on one of the shadow tables used
229772230133
** by this module.
@@ -234688,12 +235049,12 @@
234688235049
}
234689235050
#endif /* SQLITE_CORE */
234690235051
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
234691235052
234692235053
/************** End of stmt.c ************************************************/
234693
-#if __LINE__!=234693
235054
+#if __LINE__!=235054
234694235055
#undef SQLITE_SOURCE_ID
234695
-#define SQLITE_SOURCE_ID "2021-04-07 18:17:53 a2ddb89b206c13876d34c5f9e3db41cda72d6eb3fea31ffa8cc6daa1e158alt2"
235056
+#define SQLITE_SOURCE_ID "2021-04-28 17:37:26 65ec39f0f092fe29e1d4e9e96cf07a73d2ef7ce2c41b6f1cd3ab23546adaalt2"
234696235057
#endif
234697235058
/* Return the source-id for this library */
234698235059
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
234699235060
/************************** End of sqlite3.c ******************************/
234700235061
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1186,11 +1186,11 @@
1186 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1187 ** [sqlite_version()] and [sqlite_source_id()].
1188 */
1189 #define SQLITE_VERSION "3.36.0"
1190 #define SQLITE_VERSION_NUMBER 3036000
1191 #define SQLITE_SOURCE_ID "2021-04-07 18:17:53 a2ddb89b206c13876d34c5f9e3db41cda72d6eb3fea31ffa8cc6daa1e1580e16"
1192
1193 /*
1194 ** CAPI3REF: Run-Time Library Version Numbers
1195 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1196 **
@@ -10607,10 +10607,19 @@
10607 ** callback was invoked as a result of a direct insert, update, or delete
10608 ** operation; or 1 for inserts, updates, or deletes invoked by top-level
10609 ** triggers; or 2 for changes resulting from triggers called by top-level
10610 ** triggers; and so forth.
10611 **
 
 
 
 
 
 
 
 
 
10612 ** See also: [sqlite3_update_hook()]
10613 */
10614 #if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
10615 SQLITE_API void *sqlite3_preupdate_hook(
10616 sqlite3 *db,
@@ -10627,10 +10636,11 @@
10627 );
10628 SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
10629 SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
10630 SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
10631 SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
 
10632 #endif
10633
10634 /*
10635 ** CAPI3REF: Low-level system error code
10636 ** METHOD: sqlite3
@@ -11167,10 +11177,41 @@
11167 ** are attached is closed. Refer to the documentation for
11168 ** [sqlite3session_create()] for details.
11169 */
11170 SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
11171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11172
11173 /*
11174 ** CAPI3REF: Enable Or Disable A Session Object
11175 ** METHOD: sqlite3_session
11176 **
@@ -11411,10 +11452,26 @@
11411 sqlite3_session *pSession, /* Session object */
11412 int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
11413 void **ppChangeset /* OUT: Buffer containing changeset */
11414 );
11415
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11416 /*
11417 ** CAPI3REF: Load The Difference Between Tables Into A Session
11418 ** METHOD: sqlite3_session
11419 **
11420 ** If it is not already attached to the session object passed as the first
@@ -17724,10 +17781,11 @@
17724 #define TF_OOOHidden 0x0400 /* Out-of-Order hidden columns */
17725 #define TF_HasNotNull 0x0800 /* Contains NOT NULL constraints */
17726 #define TF_Shadow 0x1000 /* True for a shadow table */
17727 #define TF_HasStat4 0x2000 /* STAT4 info available for this table */
17728 #define TF_Ephemeral 0x4000 /* An ephemeral table */
 
17729
17730 /*
17731 ** Test to see whether or not a table is a virtual table. This is
17732 ** done as a macro so that it will be optimized out when virtual
17733 ** table support is omitted from the build.
@@ -18553,11 +18611,11 @@
18553 Upsert *pUpsert; /* ON CONFLICT clause information from an upsert */
18554 int iBaseReg; /* For TK_REGISTER when parsing RETURNING */
18555 } uNC;
18556 NameContext *pNext; /* Next outer name context. NULL for outermost */
18557 int nRef; /* Number of names resolved by this context */
18558 int nErr; /* Number of errors encountered while resolving names */
18559 int ncFlags; /* Zero or more NC_* flags defined below */
18560 Select *pWinSelect; /* SELECT statement for any window functions */
18561 };
18562
18563 /*
@@ -18586,10 +18644,11 @@
18586 #define NC_AllowWin 0x04000 /* Window functions are allowed here */
18587 #define NC_HasWin 0x08000 /* One or more window functions seen */
18588 #define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */
18589 #define NC_InAggFunc 0x20000 /* True if analyzing arguments to an agg func */
18590 #define NC_FromDDL 0x40000 /* SQL text comes from sqlite_schema */
 
18591
18592 /*
18593 ** An instance of the following object describes a single ON CONFLICT
18594 ** clause in an upsert.
18595 **
@@ -19367,10 +19426,11 @@
19367 SQLITE_PRIVATE int sqlite3ExprWalkNoop(Walker*, Expr*);
19368 SQLITE_PRIVATE int sqlite3SelectWalkNoop(Walker*, Select*);
19369 SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker*, Select*);
19370 SQLITE_PRIVATE int sqlite3WalkerDepthIncrease(Walker*,Select*);
19371 SQLITE_PRIVATE void sqlite3WalkerDepthDecrease(Walker*,Select*);
 
19372
19373 #ifdef SQLITE_DEBUG
19374 SQLITE_PRIVATE void sqlite3SelectWalkAssert2(Walker*, Select*);
19375 #endif
19376
@@ -21500,10 +21560,11 @@
21500 u8 *aRecord; /* old.* database record */
21501 KeyInfo keyinfo;
21502 UnpackedRecord *pUnpacked; /* Unpacked version of aRecord[] */
21503 UnpackedRecord *pNewUnpacked; /* Unpacked version of new.* record */
21504 int iNewReg; /* Register for new.* values */
 
21505 i64 iKey1; /* First key value passed to hook */
21506 i64 iKey2; /* Second key value passed to hook */
21507 Mem *aNew; /* Array of new.* values */
21508 Table *pTab; /* Schema object being upated */
21509 Index *pPk; /* PK index if pTab is WITHOUT ROWID */
@@ -21588,11 +21649,12 @@
21588 #endif
21589 SQLITE_PRIVATE void sqlite3VdbeFrameMemDel(void*); /* Destructor on Mem */
21590 SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*); /* Actually deletes the Frame */
21591 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
21592 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
21593 SQLITE_PRIVATE void sqlite3VdbePreUpdateHook(Vdbe*,VdbeCursor*,int,const char*,Table*,i64,int);
 
21594 #endif
21595 SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p);
21596
21597 SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *, int, VdbeCursor *);
21598 SQLITE_PRIVATE void sqlite3VdbeSorterReset(sqlite3 *, VdbeSorter *);
@@ -29932,10 +29994,11 @@
29932 for(i=0; i<pSrc->nSrc; i++){
29933 const SrcItem *pItem = &pSrc->a[i];
29934 StrAccum x;
29935 char zLine[100];
29936 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
 
29937 sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
29938 if( pItem->pTab ){
29939 sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx",
29940 pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed);
29941 }
@@ -48518,11 +48581,11 @@
48518 return SQLITE_FULL;
48519 }
48520 newSz *= 2;
48521 if( newSz>p->szMax ) newSz = p->szMax;
48522 pNew = sqlite3Realloc(p->aData, newSz);
48523 if( pNew==0 ) return SQLITE_NOMEM;
48524 p->aData = pNew;
48525 p->szAlloc = newSz;
48526 return SQLITE_OK;
48527 }
48528
@@ -58067,11 +58130,11 @@
58067
58068 if( pPager->errCode ) return pPager->errCode;
58069 assert( pPager->eState>=PAGER_READER && pPager->eState<PAGER_ERROR );
58070 pPager->subjInMemory = (u8)subjInMemory;
58071
58072 if( ALWAYS(pPager->eState==PAGER_READER) ){
58073 assert( pPager->pInJournal==0 );
58074
58075 if( pagerUseWal(pPager) ){
58076 /* If the pager is configured to use locking_mode=exclusive, and an
58077 ** exclusive lock on the database is not already held, obtain it now.
@@ -66488,10 +66551,11 @@
66488 unsigned char *data; /* The page data */
66489 unsigned char *temp; /* Temp area for cell content */
66490 unsigned char *src; /* Source of content */
66491 int iCellFirst; /* First allowable cell index */
66492 int iCellLast; /* Last possible cell index */
 
66493
66494 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
66495 assert( pPage->pBt!=0 );
66496 assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
66497 assert( pPage->nOverflow==0 );
@@ -66529,11 +66593,11 @@
66529 if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage);
66530 sz2 = get2byte(&data[iFree2+2]);
66531 if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage);
66532 memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
66533 sz += sz2;
66534 }else if( NEVER(iFree+sz>usableSize) ){
66535 return SQLITE_CORRUPT_PAGE(pPage);
66536 }
66537
66538 cbrk = top+sz;
66539 assert( cbrk+(iFree-top) <= usableSize );
@@ -66548,38 +66612,37 @@
66548 }
66549 }
66550
66551 cbrk = usableSize;
66552 iCellLast = usableSize - 4;
 
66553 for(i=0; i<nCell; i++){
66554 u8 *pAddr; /* The i-th cell pointer */
66555 pAddr = &data[cellOffset + i*2];
66556 pc = get2byte(pAddr);
66557 testcase( pc==iCellFirst );
66558 testcase( pc==iCellLast );
66559 /* These conditions have already been verified in btreeInitPage()
66560 ** if PRAGMA cell_size_check=ON.
66561 */
66562 if( pc<iCellFirst || pc>iCellLast ){
66563 return SQLITE_CORRUPT_PAGE(pPage);
66564 }
66565 assert( pc>=iCellFirst && pc<=iCellLast );
66566 size = pPage->xCellSize(pPage, &src[pc]);
66567 cbrk -= size;
66568 if( cbrk<iCellFirst || pc+size>usableSize ){
66569 return SQLITE_CORRUPT_PAGE(pPage);
66570 }
66571 assert( cbrk+size<=usableSize && cbrk>=iCellFirst );
66572 testcase( cbrk+size==usableSize );
66573 testcase( pc+size==usableSize );
66574 put2byte(pAddr, cbrk);
66575 if( temp==0 ){
66576 int x;
66577 if( cbrk==pc ) continue;
66578 temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
66579 x = get2byte(&data[hdr+5]);
66580 memcpy(&temp[x], &data[x], (cbrk+size) - x);
66581 src = temp;
66582 }
66583 memcpy(&data[cbrk], &src[pc], size);
66584 }
66585 data[hdr+7] = 0;
@@ -72055,11 +72118,11 @@
72055 pData = pEnd;
72056 while( 1/*exit by break*/ ){
72057 u8 *pCell = pCArray->apCell[i];
72058 u16 sz = pCArray->szCell[i];
72059 assert( sz>0 );
72060 if( SQLITE_WITHIN(pCell,aData,pEnd) ){
72061 if( ((uptr)(pCell+sz))>(uptr)pEnd ) return SQLITE_CORRUPT_BKPT;
72062 pCell = &pTmp[pCell - aData];
72063 }else if( (uptr)(pCell+sz)>(uptr)pSrcEnd
72064 && (uptr)(pCell)<(uptr)pSrcEnd
72065 ){
@@ -72068,13 +72131,12 @@
72068
72069 pData -= sz;
72070 put2byte(pCellptr, (pData - aData));
72071 pCellptr += 2;
72072 if( pData < pCellptr ) return SQLITE_CORRUPT_BKPT;
72073 memcpy(pData, pCell, sz);
72074 assert( sz==pPg->xCellSize(pPg, pCell) || CORRUPT_DB );
72075 testcase( sz!=pPg->xCellSize(pPg,pCell) )
72076 i++;
72077 if( i>=iEnd ) break;
72078 if( pCArray->ixNx[k]<=i ){
72079 k++;
72080 pSrcEnd = pCArray->apEnd[k];
@@ -72862,11 +72924,11 @@
72862 b.apCell[b.nCell] = pTemp+leafCorrection;
72863 assert( leafCorrection==0 || leafCorrection==4 );
72864 b.szCell[b.nCell] = b.szCell[b.nCell] - leafCorrection;
72865 if( !pOld->leaf ){
72866 assert( leafCorrection==0 );
72867 assert( pOld->hdrOffset==0 );
72868 /* The right pointer of the child page pOld becomes the left
72869 ** pointer of the divider cell */
72870 memcpy(b.apCell[b.nCell], &pOld->aData[8], 4);
72871 }else{
72872 assert( leafCorrection==4 );
@@ -73770,10 +73832,18 @@
73770 ** not to clear the cursor here.
73771 */
73772 if( pCur->curFlags & BTCF_Multiple ){
73773 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
73774 if( rc ) return rc;
 
 
 
 
 
 
 
 
73775 }
73776
73777 if( pCur->pKeyInfo==0 ){
73778 assert( pX->pKey==0 );
73779 /* If this is an insert into a table b-tree, invalidate any incrblob
@@ -73857,21 +73927,20 @@
73857 x2.nData = pX->nKey;
73858 x2.nZero = 0;
73859 return btreeOverwriteCell(pCur, &x2);
73860 }
73861 }
73862
73863 }
73864 assert( pCur->eState==CURSOR_VALID
73865 || (pCur->eState==CURSOR_INVALID && loc)
73866 || CORRUPT_DB );
73867
73868 pPage = pCur->pPage;
73869 assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
73870 assert( pPage->leaf || !pPage->intKey );
73871 if( pPage->nFree<0 ){
73872 if( pCur->eState>CURSOR_INVALID ){
73873 rc = SQLITE_CORRUPT_BKPT;
73874 }else{
73875 rc = btreeComputeFreeSpace(pPage);
73876 }
73877 if( rc ) return rc;
@@ -74148,11 +74217,12 @@
74148 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
74149 assert( !hasReadConflicts(p, pCur->pgnoRoot) );
74150 assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
74151 if( pCur->eState==CURSOR_REQUIRESEEK ){
74152 rc = btreeRestoreCursorPosition(pCur);
74153 if( rc ) return rc;
 
74154 }
74155 assert( CORRUPT_DB || pCur->eState==CURSOR_VALID );
74156
74157 iCellDepth = pCur->iPage;
74158 iCellIdx = pCur->ix;
@@ -83652,11 +83722,12 @@
83652 VdbeCursor *pCsr, /* Cursor to grab old.* values from */
83653 int op, /* SQLITE_INSERT, UPDATE or DELETE */
83654 const char *zDb, /* Database name */
83655 Table *pTab, /* Modified table */
83656 i64 iKey1, /* Initial key value */
83657 int iReg /* Register for new.* record */
 
83658 ){
83659 sqlite3 *db = v->db;
83660 i64 iKey2;
83661 PreUpdate preupdate;
83662 const char *zTbl = pTab->zName;
@@ -83688,10 +83759,11 @@
83688 preupdate.keyinfo.nKeyField = pTab->nCol;
83689 preupdate.keyinfo.aSortFlags = (u8*)&fakeSortOrder;
83690 preupdate.iKey1 = iKey1;
83691 preupdate.iKey2 = iKey2;
83692 preupdate.pTab = pTab;
 
83693
83694 db->pPreUpdate = &preupdate;
83695 db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2);
83696 db->pPreUpdate = 0;
83697 sqlite3DbFree(db, preupdate.aRecord);
@@ -85613,10 +85685,21 @@
85613 SQLITE_API int sqlite3_preupdate_depth(sqlite3 *db){
85614 PreUpdate *p = db->pPreUpdate;
85615 return (p ? p->v->nFrame : 0);
85616 }
85617 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
 
 
 
 
 
 
 
 
 
 
 
85618
85619 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
85620 /*
85621 ** This function is called from within a pre-update callback to retrieve
85622 ** a field of the row currently being updated or inserted.
@@ -86393,11 +86476,14 @@
86393 static u16 SQLITE_NOINLINE computeNumericType(Mem *pMem){
86394 int rc;
86395 sqlite3_int64 ix;
86396 assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 );
86397 assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
86398 ExpandBlob(pMem);
 
 
 
86399 rc = sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc);
86400 if( rc<=0 ){
86401 if( rc==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1 ){
86402 pMem->u.i = ix;
86403 return MEM_Int;
@@ -91126,11 +91212,11 @@
91126
91127 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
91128 /* Invoke the pre-update hook, if any */
91129 if( pTab ){
91130 if( db->xPreUpdateCallback && !(pOp->p5 & OPFLAG_ISUPDATE) ){
91131 sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, x.nKey,pOp->p2);
91132 }
91133 if( db->xUpdateCallback==0 || pTab->aCol==0 ){
91134 /* Prevent post-update hook from running in cases when it should not */
91135 pTab = 0;
91136 }
@@ -91286,11 +91372,11 @@
91286 || (aMem[pOp->p3].flags & MEM_Int)
91287 );
91288 sqlite3VdbePreUpdateHook(p, pC,
91289 (opflags & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_DELETE,
91290 zDb, pTab, pC->movetoTarget,
91291 pOp->p3
91292 );
91293 }
91294 if( opflags & OPFLAG_ISNOOP ) break;
91295 #endif
91296
@@ -92355,11 +92441,11 @@
92355 }
92356 #endif
92357
92358 iDb = pOp->p1;
92359 assert( iDb>=0 && iDb<db->nDb );
92360 assert( DbHasProperty(db, iDb, DB_SchemaLoaded) );
92361
92362 #ifndef SQLITE_OMIT_ALTERTABLE
92363 if( pOp->p4.z==0 ){
92364 sqlite3SchemaClear(db->aDb[iDb].pSchema);
92365 db->mDbFlags &= ~DBFLAG_SchemaKnownOk;
@@ -94715,11 +94801,11 @@
94715 ** anyhow.
94716 */
94717 sqlite3_int64 iKey;
94718 iKey = sqlite3BtreeIntegerKey(p->pCsr);
94719 sqlite3VdbePreUpdateHook(
94720 v, v->apCsr[0], SQLITE_DELETE, p->zDb, p->pTab, iKey, -1
94721 );
94722 }
94723 #endif
94724
94725 rc = xCall(p->pCsr, iOffset+p->iOffset, n, z);
@@ -94786,10 +94872,11 @@
94786 ** already been invalidated. Return SQLITE_ABORT in this case.
94787 */
94788 rc = SQLITE_ABORT;
94789 }else{
94790 char *zErr;
 
94791 rc = blobSeekToRow(p, iRow, &zErr);
94792 if( rc!=SQLITE_OK ){
94793 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
94794 sqlite3DbFree(db, zErr);
94795 }
@@ -98468,19 +98555,14 @@
98468 if( rc ) return WRC_Abort;
98469 rc = sqlite3WalkExprList(pWalker, pWin->pPartition);
98470 if( rc ) return WRC_Abort;
98471 rc = sqlite3WalkExpr(pWalker, pWin->pFilter);
98472 if( rc ) return WRC_Abort;
98473
98474 /* The next two are purely for calls to sqlite3RenameExprUnmap()
98475 ** within sqlite3WindowOffsetExpr(). Because of constraints imposed
98476 ** by sqlite3WindowOffsetExpr(), they can never fail. The results do
98477 ** not matter anyhow. */
98478 rc = sqlite3WalkExpr(pWalker, pWin->pStart);
98479 if( NEVER(rc) ) return WRC_Abort;
98480 rc = sqlite3WalkExpr(pWalker, pWin->pEnd);
98481 if( NEVER(rc) ) return WRC_Abort;
98482 if( bOneOnly ) break;
98483 }
98484 return WRC_Continue;
98485 }
98486 #endif
@@ -98552,10 +98634,20 @@
98552 if( sqlite3WalkExpr(pWalker, pItem->pExpr) ) return WRC_Abort;
98553 }
98554 }
98555 return WRC_Continue;
98556 }
 
 
 
 
 
 
 
 
 
 
98557
98558 /*
98559 ** Walk all expressions associated with SELECT statement p. Do
98560 ** not invoke the SELECT callback on p, but do (of course) invoke
98561 ** any expr callbacks and SELECT callbacks that come from subqueries.
@@ -98566,14 +98658,16 @@
98566 if( sqlite3WalkExpr(pWalker, p->pWhere) ) return WRC_Abort;
98567 if( sqlite3WalkExprList(pWalker, p->pGroupBy) ) return WRC_Abort;
98568 if( sqlite3WalkExpr(pWalker, p->pHaving) ) return WRC_Abort;
98569 if( sqlite3WalkExprList(pWalker, p->pOrderBy) ) return WRC_Abort;
98570 if( sqlite3WalkExpr(pWalker, p->pLimit) ) return WRC_Abort;
98571 #if !defined(SQLITE_OMIT_WINDOWFUNC) && !defined(SQLITE_OMIT_ALTERTABLE)
98572 {
98573 Parse *pParse = pWalker->pParse;
98574 if( pParse && IN_RENAME_OBJECT ){
 
 
98575 /* The following may return WRC_Abort if there are unresolvable
98576 ** symbols (e.g. a table that does not exist) in a window definition. */
98577 int rc = walkWindowList(pWalker, p->pWinDefn, 0);
98578 return rc;
98579 }
@@ -98593,11 +98687,11 @@
98593 SrcList *pSrc;
98594 int i;
98595 SrcItem *pItem;
98596
98597 pSrc = p->pSrc;
98598 if( pSrc ){
98599 for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
98600 if( pItem->pSelect && sqlite3WalkSelect(pWalker, pItem->pSelect) ){
98601 return WRC_Abort;
98602 }
98603 if( pItem->fg.isTabFunc
@@ -98767,11 +98861,14 @@
98767 assert( iCol>=0 && iCol<pEList->nExpr );
98768 pOrig = pEList->a[iCol].pExpr;
98769 assert( pOrig!=0 );
98770 db = pParse->db;
98771 pDup = sqlite3ExprDup(db, pOrig, 0);
98772 if( pDup!=0 ){
 
 
 
98773 incrAggFunctionDepth(pDup, nSubquery);
98774 if( pExpr->op==TK_COLLATE ){
98775 pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
98776 }
98777
@@ -98789,14 +98886,12 @@
98789 assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 );
98790 pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
98791 pExpr->flags |= EP_MemToken;
98792 }
98793 if( ExprHasProperty(pExpr, EP_WinFunc) ){
98794 if( pExpr->y.pWin!=0 ){
98795 pExpr->y.pWin->pOwner = pExpr;
98796 }else{
98797 assert( db->mallocFailed );
98798 }
98799 }
98800 sqlite3DbFree(db, pDup);
98801 }
98802 }
@@ -99184,12 +99279,12 @@
99184 ** or HAVING clauses, or as part of a larger expression in the ORDER BY
99185 ** clause is not standard SQL. This is a (goofy) SQLite extension, that
99186 ** is supported for backwards compatibility only. Hence, we issue a warning
99187 ** on sqlite3_log() whenever the capability is used.
99188 */
99189 if( (pNC->ncFlags & NC_UEList)!=0
99190 && cnt==0
99191 && zTab==0
99192 ){
99193 pEList = pNC->uNC.pEList;
99194 assert( pEList!=0 );
99195 for(j=0; j<pEList->nExpr; j++){
@@ -99293,11 +99388,11 @@
99293 sqlite3ErrorMsg(pParse, "%s: %s.%s", zErr, zTab, zCol);
99294 }else{
99295 sqlite3ErrorMsg(pParse, "%s: %s", zErr, zCol);
99296 }
99297 pParse->checkSchema = 1;
99298 pTopNC->nErr++;
99299 }
99300
99301 /* If a column from a table in pSrcList is referenced, then record
99302 ** this fact in the pSrcList.a[].colUsed bitmask. Column 0 causes
99303 ** bit 0 to be set. Column 1 sets bit 1. And so forth. Bit 63 is
@@ -99600,11 +99695,11 @@
99600 pExpr->iTable = exprProbability(pList->a[1].pExpr);
99601 if( pExpr->iTable<0 ){
99602 sqlite3ErrorMsg(pParse,
99603 "second argument to likelihood() must be a "
99604 "constant between 0.0 and 1.0");
99605 pNC->nErr++;
99606 }
99607 }else{
99608 /* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is
99609 ** equivalent to likelihood(X, 0.0625).
99610 ** EVIDENCE-OF: R-01283-11636 The unlikely(X) function is
@@ -99622,11 +99717,11 @@
99622 int auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0,pDef->zName,0);
99623 if( auth!=SQLITE_OK ){
99624 if( auth==SQLITE_DENY ){
99625 sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
99626 pDef->zName);
99627 pNC->nErr++;
99628 }
99629 pExpr->op = TK_NULL;
99630 return WRC_Prune;
99631 }
99632 }
@@ -99678,11 +99773,11 @@
99678 );
99679 if( pDef && pDef->xValue==0 && pWin ){
99680 sqlite3ErrorMsg(pParse,
99681 "%.*s() may not be used as a window function", nId, zId
99682 );
99683 pNC->nErr++;
99684 }else if(
99685 (is_agg && (pNC->ncFlags & NC_AllowAgg)==0)
99686 || (is_agg && (pDef->funcFlags&SQLITE_FUNC_WINDOW) && !pWin)
99687 || (is_agg && pWin && (pNC->ncFlags & NC_AllowWin)==0)
99688 ){
@@ -99691,39 +99786,39 @@
99691 zType = "window";
99692 }else{
99693 zType = "aggregate";
99694 }
99695 sqlite3ErrorMsg(pParse, "misuse of %s function %.*s()",zType,nId,zId);
99696 pNC->nErr++;
99697 is_agg = 0;
99698 }
99699 #else
99700 if( (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) ){
99701 sqlite3ErrorMsg(pParse,"misuse of aggregate function %.*s()",nId,zId);
99702 pNC->nErr++;
99703 is_agg = 0;
99704 }
99705 #endif
99706 else if( no_such_func && pParse->db->init.busy==0
99707 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
99708 && pParse->explain==0
99709 #endif
99710 ){
99711 sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId);
99712 pNC->nErr++;
99713 }else if( wrong_num_args ){
99714 sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()",
99715 nId, zId);
99716 pNC->nErr++;
99717 }
99718 #ifndef SQLITE_OMIT_WINDOWFUNC
99719 else if( is_agg==0 && ExprHasProperty(pExpr, EP_WinFunc) ){
99720 sqlite3ErrorMsg(pParse,
99721 "FILTER may not be used with non-aggregate %.*s()",
99722 nId, zId
99723 );
99724 pNC->nErr++;
99725 }
99726 #endif
99727 if( is_agg ){
99728 /* Window functions may not be arguments of aggregate functions.
99729 ** Or arguments of other window functions. But aggregate functions
@@ -99943,12 +100038,12 @@
99943 */
99944 memset(&nc, 0, sizeof(nc));
99945 nc.pParse = pParse;
99946 nc.pSrcList = pSelect->pSrc;
99947 nc.uNC.pEList = pEList;
99948 nc.ncFlags = NC_AllowAgg|NC_UEList;
99949 nc.nErr = 0;
99950 db = pParse->db;
99951 savedSuppErr = db->suppressErr;
99952 if( IN_RENAME_OBJECT==0 ) db->suppressErr = 1;
99953 rc = sqlite3ResolveExprNames(&nc, pE);
99954 db->suppressErr = savedSuppErr;
@@ -100203,11 +100298,11 @@
100203 int iCol; /* Column number */
100204 struct ExprList_item *pItem; /* A term of the ORDER BY clause */
100205 Parse *pParse; /* Parsing context */
100206 int nResult; /* Number of terms in the result set */
100207
100208 if( pOrderBy==0 ) return 0;
100209 nResult = pSelect->pEList->nExpr;
100210 pParse = pNC->pParse;
100211 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
100212 Expr *pE = pItem->pExpr;
100213 Expr *pE2 = sqlite3ExprSkipCollateAndLikely(pE);
@@ -100293,11 +100388,13 @@
100293 nCompound = 0;
100294 pLeftmost = p;
100295 while( p ){
100296 assert( (p->selFlags & SF_Expanded)!=0 );
100297 assert( (p->selFlags & SF_Resolved)==0 );
 
100298 p->selFlags |= SF_Resolved;
 
100299
100300 /* Resolve the expressions in the LIMIT and OFFSET clauses. These
100301 ** are not allowed to refer to any names, so pass an empty NameContext.
100302 */
100303 memset(&sNC, 0, sizeof(sNC));
@@ -100368,17 +100465,10 @@
100368 p->selFlags |= SF_Aggregate | (sNC.ncFlags&NC_MinMaxAgg);
100369 }else{
100370 sNC.ncFlags &= ~NC_AllowAgg;
100371 }
100372
100373 /* If a HAVING clause is present, then there must be a GROUP BY clause.
100374 */
100375 if( p->pHaving && !pGroupBy ){
100376 sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING");
100377 return WRC_Abort;
100378 }
100379
100380 /* Add the output column list to the name-context before parsing the
100381 ** other expressions in the SELECT statement. This is so that
100382 ** expressions in the WHERE clause (etc.) can refer to expressions by
100383 ** aliases in the result set.
100384 **
@@ -100386,11 +100476,17 @@
100386 ** re-evaluated for each reference to it.
100387 */
100388 assert( (sNC.ncFlags & (NC_UAggInfo|NC_UUpsert|NC_UBaseReg))==0 );
100389 sNC.uNC.pEList = p->pEList;
100390 sNC.ncFlags |= NC_UEList;
100391 if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;
 
 
 
 
 
 
100392 if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort;
100393
100394 /* Resolve names in table-valued-function arguments */
100395 for(i=0; i<p->pSrc->nSrc; i++){
100396 SrcItem *pItem = &p->pSrc->a[i];
@@ -100426,11 +100522,12 @@
100426 ** If there is an ORDER BY clause on a term of a compound-select other
100427 ** than the right-most term, then that is a syntax error. But the error
100428 ** is not detected until much later, and so we need to go ahead and
100429 ** resolve those symbols on the incorrect ORDER BY for consistency.
100430 */
100431 if( isCompound<=nCompound /* Defer right-most ORDER BY of a compound */
 
100432 && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER")
100433 ){
100434 return WRC_Abort;
100435 }
100436 if( db->mallocFailed ){
@@ -100550,11 +100647,11 @@
100550 if( pExpr==0 ) return SQLITE_OK;
100551 savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
100552 pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
100553 w.pParse = pNC->pParse;
100554 w.xExprCallback = resolveExprStep;
100555 w.xSelectCallback = resolveSelectStep;
100556 w.xSelectCallback2 = 0;
100557 w.u.pNC = pNC;
100558 #if SQLITE_MAX_EXPR_DEPTH>0
100559 w.pParse->nHeight += pExpr->nHeight;
100560 if( sqlite3ExprCheckHeight(w.pParse, w.pParse->nHeight) ){
@@ -100569,11 +100666,11 @@
100569 assert( EP_Win==NC_HasWin );
100570 testcase( pNC->ncFlags & NC_HasAgg );
100571 testcase( pNC->ncFlags & NC_HasWin );
100572 ExprSetProperty(pExpr, pNC->ncFlags & (NC_HasAgg|NC_HasWin) );
100573 pNC->ncFlags |= savedHasAgg;
100574 return pNC->nErr>0 || w.pParse->nErr>0;
100575 }
100576
100577 /*
100578 ** Resolve all names for all expression in an expression list. This is
100579 ** just like sqlite3ResolveExprNames() except that it works for an expression
@@ -100614,11 +100711,11 @@
100614 if( pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin) ){
100615 ExprSetProperty(pExpr, pNC->ncFlags & (NC_HasAgg|NC_HasWin) );
100616 savedHasAgg |= pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
100617 pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
100618 }
100619 if( pNC->nErr>0 || w.pParse->nErr>0 ) return WRC_Abort;
100620 }
100621 pNC->ncFlags |= savedHasAgg;
100622 return WRC_Continue;
100623 }
100624
@@ -100757,27 +100854,27 @@
100757 || (pExpr->op==TK_REGISTER && pExpr->op2==TK_IF_NULL_ROW) );
100758 pExpr = pExpr->pLeft;
100759 assert( pExpr!=0 );
100760 }
100761 op = pExpr->op;
 
 
 
 
100762 if( op==TK_SELECT ){
100763 assert( pExpr->flags&EP_xIsSelect );
100764 assert( pExpr->x.pSelect!=0 );
100765 assert( pExpr->x.pSelect->pEList!=0 );
100766 assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 );
100767 return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
100768 }
100769 if( op==TK_REGISTER ) op = pExpr->op2;
100770 #ifndef SQLITE_OMIT_CAST
100771 if( op==TK_CAST ){
100772 assert( !ExprHasProperty(pExpr, EP_IntValue) );
100773 return sqlite3AffinityType(pExpr->u.zToken, 0);
100774 }
100775 #endif
100776 if( (op==TK_AGG_COLUMN || op==TK_COLUMN) && pExpr->y.pTab ){
100777 return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
100778 }
100779 if( op==TK_SELECT_COLUMN ){
100780 assert( pExpr->pLeft->flags&EP_xIsSelect );
100781 return sqlite3ExprAffinity(
100782 pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
100783 );
@@ -102029,10 +102126,11 @@
102029
102030 /* Figure out where to write the new Expr structure. */
102031 if( pzBuffer ){
102032 zAlloc = *pzBuffer;
102033 staticFlag = EP_Static;
 
102034 }else{
102035 zAlloc = sqlite3DbMallocRawNN(db, dupedExprSize(p, dupFlags));
102036 staticFlag = 0;
102037 }
102038 pNew = (Expr *)zAlloc;
@@ -102107,11 +102205,12 @@
102107 }else{
102108 if( !ExprHasProperty(p, EP_TokenOnly|EP_Leaf) ){
102109 if( pNew->op==TK_SELECT_COLUMN ){
102110 pNew->pLeft = p->pLeft;
102111 assert( p->iColumn==0 || p->pRight==0 );
102112 assert( p->pRight==0 || p->pRight==p->pLeft );
 
102113 }else{
102114 pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
102115 }
102116 pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
102117 }
@@ -102352,10 +102451,18 @@
102352 pNew->pWin = 0;
102353 pNew->pWinDefn = sqlite3WindowListDup(db, p->pWinDefn);
102354 if( p->pWin && db->mallocFailed==0 ) gatherSelectWindows(pNew);
102355 #endif
102356 pNew->selId = p->selId;
 
 
 
 
 
 
 
 
102357 *pp = pNew;
102358 pp = &pNew->pPrior;
102359 pNext = pNew;
102360 }
102361
@@ -103052,12 +103159,14 @@
103052 ** will likely result in an incorrect answer. So when in doubt, return
103053 ** TRUE.
103054 */
103055 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr *p){
103056 u8 op;
 
103057 while( p->op==TK_UPLUS || p->op==TK_UMINUS ){
103058 p = p->pLeft;
 
103059 }
103060 op = p->op;
103061 if( op==TK_REGISTER ) op = p->op2;
103062 switch( op ){
103063 case TK_INTEGER:
@@ -103903,11 +104012,11 @@
103903 ** columns as the vector on the LHS. Or, if the RHS of the IN() is not
103904 ** a sub-query, that the LHS is a vector of size 1.
103905 */
103906 SQLITE_PRIVATE int sqlite3ExprCheckIN(Parse *pParse, Expr *pIn){
103907 int nVector = sqlite3ExprVectorSize(pIn->pLeft);
103908 if( (pIn->flags & EP_xIsSelect) ){
103909 if( nVector!=pIn->x.pSelect->pEList->nExpr ){
103910 sqlite3SubselectError(pParse, pIn->x.pSelect->pEList->nExpr, nVector);
103911 return 1;
103912 }
103913 }else if( nVector!=1 ){
@@ -104720,11 +104829,11 @@
104720 default: {
104721 /* Make NULL the default case so that if a bug causes an illegal
104722 ** Expr node to be passed into this function, it will be handled
104723 ** sanely and not crash. But keep the assert() to bring the problem
104724 ** to the attention of the developers. */
104725 assert( op==TK_NULL );
104726 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
104727 return target;
104728 }
104729 #ifndef SQLITE_OMIT_BLOB_LITERAL
104730 case TK_BLOB: {
@@ -106895,10 +107004,11 @@
106895 ** Or, if zName is not a system table, zero is returned.
106896 */
106897 static int isAlterableTable(Parse *pParse, Table *pTab){
106898 if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7)
106899 #ifndef SQLITE_OMIT_VIRTUALTABLE
 
106900 || ( (pTab->tabFlags & TF_Shadow)!=0
106901 && sqlite3ReadOnlyShadowTables(pParse->db)
106902 )
106903 #endif
106904 ){
@@ -107782,11 +107892,13 @@
107782 Parse *pParse,
107783 struct RenameCtx *pCtx,
107784 void *pPtr
107785 ){
107786 RenameToken **pp;
107787 assert( pPtr!=0 );
 
 
107788 for(pp=&pParse->pRename; (*pp); pp=&(*pp)->pNext){
107789 if( (*pp)->p==pPtr ){
107790 RenameToken *pToken = *pp;
107791 if( pCtx ){
107792 *pp = pToken->pNext;
@@ -108439,11 +108551,11 @@
108439 static int renameTableSelectCb(Walker *pWalker, Select *pSelect){
108440 int i;
108441 RenameCtx *p = pWalker->u.pRename;
108442 SrcList *pSrc = pSelect->pSrc;
108443 if( pSelect->selFlags & SF_View ) return WRC_Prune;
108444 if( pSrc==0 ){
108445 assert( pWalker->pParse->db->mallocFailed );
108446 return WRC_Abort;
108447 }
108448 for(i=0; i<pSrc->nSrc; i++){
108449 SrcItem *pItem = &pSrc->a[i];
@@ -108983,20 +109095,25 @@
108983 if( iPos<pPk->nKeyCol ) continue;
108984 regOut = reg+1+iPos-(iPos>iColPos);
108985 }else{
108986 regOut = reg+1+nField;
108987 }
108988 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut);
 
 
 
 
108989 nField++;
108990 }
108991 }
108992 sqlite3VdbeAddOp3(v, OP_MakeRecord, reg+1, nField, regRec);
108993 if( pPk ){
108994 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iCur, regRec, reg+1, pPk->nKeyCol);
108995 }else{
108996 sqlite3VdbeAddOp3(v, OP_Insert, iCur, regRec, reg);
108997 }
 
108998
108999 sqlite3VdbeAddOp2(v, OP_Next, iCur, addr+1); VdbeCoverage(v);
109000 sqlite3VdbeJumpHere(v, addr);
109001 }
109002
@@ -111479,11 +111596,11 @@
111479 pFix->pName = pName;
111480 pFix->bTemp = (iDb==1);
111481 pFix->w.pParse = pParse;
111482 pFix->w.xExprCallback = fixExprCb;
111483 pFix->w.xSelectCallback = fixSelectCb;
111484 pFix->w.xSelectCallback2 = 0;
111485 pFix->w.walkerDepth = 0;
111486 pFix->w.eCode = 0;
111487 pFix->w.u.pFix = pFix;
111488 }
111489
@@ -111541,18 +111658,20 @@
111541 || sqlite3FixSrcList(pFix, pStep->pFrom)
111542 ){
111543 return 1;
111544 }
111545 #ifndef SQLITE_OMIT_UPSERT
111546 if( pStep->pUpsert ){
111547 Upsert *pUp = pStep->pUpsert;
111548 if( sqlite3WalkExprList(&pFix->w, pUp->pUpsertTarget)
111549 || sqlite3WalkExpr(&pFix->w, pUp->pUpsertTargetWhere)
111550 || sqlite3WalkExprList(&pFix->w, pUp->pUpsertSet)
111551 || sqlite3WalkExpr(&pFix->w, pUp->pUpsertWhere)
111552 ){
111553 return 1;
 
 
111554 }
111555 }
111556 #endif
111557 pStep = pStep->pNext;
111558 }
@@ -112272,11 +112391,11 @@
112272 if( p==0 ){
112273 #ifndef SQLITE_OMIT_VIRTUALTABLE
112274 /* If zName is the not the name of a table in the schema created using
112275 ** CREATE, then check to see if it is the name of an virtual table that
112276 ** can be an eponymous virtual table. */
112277 if( pParse->disableVtab==0 ){
112278 Module *pMod = (Module*)sqlite3HashFind(&db->aModule, zName);
112279 if( pMod==0 && sqlite3_strnicmp(zName, "pragma_", 7)==0 ){
112280 pMod = sqlite3PragmaVtabRegister(db, zName);
112281 }
112282 if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){
@@ -112295,10 +112414,12 @@
112295 if( zDbase ){
112296 sqlite3ErrorMsg(pParse, "%s: %s.%s", zMsg, zDbase, zName);
112297 }else{
112298 sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName);
112299 }
 
 
112300 }
112301
112302 return p;
112303 }
112304
@@ -113155,10 +113276,11 @@
113155 pRet->retTrig.zName = RETURNING_TRIGGER_NAME;
113156 pRet->retTrig.op = TK_RETURNING;
113157 pRet->retTrig.tr_tm = TRIGGER_AFTER;
113158 pRet->retTrig.bReturning = 1;
113159 pRet->retTrig.pSchema = db->aDb[1].pSchema;
 
113160 pRet->retTrig.step_list = &pRet->retTStep;
113161 pRet->retTStep.op = TK_RETURNING;
113162 pRet->retTStep.pTrig = &pRet->retTrig;
113163 pRet->retTStep.pExprList = pList;
113164 pHash = &(db->aDb[1].pSchema->trigHash);
@@ -114013,20 +114135,26 @@
114013 ExprList *pList;
114014 Token ipkToken;
114015 sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zName);
114016 pList = sqlite3ExprListAppend(pParse, 0,
114017 sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
114018 if( pList==0 ) return;
 
 
 
114019 if( IN_RENAME_OBJECT ){
114020 sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
114021 }
114022 pList->a[0].sortFlags = pParse->iPkSortOrder;
114023 assert( pParse->pNewTable==pTab );
114024 pTab->iPKey = -1;
114025 sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
114026 SQLITE_IDXTYPE_PRIMARYKEY);
114027 if( db->mallocFailed || pParse->nErr ) return;
 
 
 
114028 pPk = sqlite3PrimaryKeyIndex(pTab);
114029 assert( pPk->nKeyCol==1 );
114030 }else{
114031 pPk = sqlite3PrimaryKeyIndex(pTab);
114032 assert( pPk!=0 );
@@ -114226,11 +114354,10 @@
114226 Index *pIdx; /* An implied index of the table */
114227
114228 if( pEnd==0 && pSelect==0 ){
114229 return;
114230 }
114231 assert( !db->mallocFailed );
114232 p = pParse->pNewTable;
114233 if( p==0 ) return;
114234
114235 if( pSelect==0 && sqlite3ShadowTableName(db, p->zName) ){
114236 p->tabFlags |= TF_Shadow;
@@ -114474,10 +114601,11 @@
114474 */
114475 if( db->init.busy ){
114476 Table *pOld;
114477 Schema *pSchema = p->pSchema;
114478 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
 
114479 pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName, p);
114480 if( pOld ){
114481 assert( p==pOld ); /* Malloc must have failed inside HashInsert() */
114482 sqlite3OomFault(db);
114483 return;
@@ -116421,12 +116549,12 @@
116421 ** Assign VdbeCursor index numbers to all tables in a SrcList
116422 */
116423 SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse *pParse, SrcList *pList){
116424 int i;
116425 SrcItem *pItem;
116426 assert(pList || pParse->db->mallocFailed );
116427 if( pList ){
116428 for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
116429 if( pItem->iCursor>=0 ) continue;
116430 pItem->iCursor = pParse->nTab++;
116431 if( pItem->pSelect ){
116432 sqlite3SrcListAssignCursors(pParse, pItem->pSelect->pSrc);
@@ -120759,13 +120887,11 @@
120759 ans = x(v0, v1);
120760 sqlite3_result_double(context, ans);
120761 }
120762
120763 /*
120764 ** Implementation of 2-argument SQL math functions:
120765 **
120766 ** power(X,Y) - Compute X to the Y-th power
120767 */
120768 static void piFunc(
120769 sqlite3_context *context,
120770 int argc,
120771 sqlite3_value **argv
@@ -122791,11 +122917,11 @@
122791 /* Verify that the sqlite_sequence table exists and is an ordinary
122792 ** rowid table with exactly two columns.
122793 ** Ticket d8dc2b3a58cd5dc2918a1d4acb 2018-05-23 */
122794 if( pSeqTab==0
122795 || !HasRowid(pSeqTab)
122796 || IsVirtual(pSeqTab)
122797 || pSeqTab->nCol!=2
122798 ){
122799 pParse->nErr++;
122800 pParse->rc = SQLITE_CORRUPT_SEQUENCE;
122801 return 0;
@@ -130510,18 +130636,18 @@
130510
130511 assert( argc==5 );
130512 UNUSED_PARAMETER2(NotUsed, argc);
130513 assert( sqlite3_mutex_held(db->mutex) );
130514 db->mDbFlags |= DBFLAG_EncodingFixed;
 
130515 pData->nInitRow++;
130516 if( db->mallocFailed ){
130517 corruptSchema(pData, argv, 0);
130518 return 1;
130519 }
130520
130521 assert( iDb>=0 && iDb<db->nDb );
130522 if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
130523 if( argv[3]==0 ){
130524 corruptSchema(pData, argv, 0);
130525 }else if( argv[4]
130526 && 'c'==sqlite3UpperToLower[(unsigned char)argv[4][0]]
130527 && 'r'==sqlite3UpperToLower[(unsigned char)argv[4][1]] ){
@@ -130794,19 +130920,21 @@
130794 #endif
130795 }
130796 if( db->mallocFailed ){
130797 rc = SQLITE_NOMEM_BKPT;
130798 sqlite3ResetAllSchemasOfConnection(db);
130799 }
130800 if( rc==SQLITE_OK || (db->flags&SQLITE_NoSchemaError)){
130801 /* Black magic: If the SQLITE_NoSchemaError flag is set, then consider
130802 ** the schema loaded, even if errors occurred. In this situation the
130803 ** current sqlite3_prepare() operation will fail, but the following one
130804 ** will attempt to compile the supplied statement against whatever subset
130805 ** of the schema was loaded before the error occurred. The primary
130806 ** purpose of this is to allow access to the sqlite_schema table
130807 ** even when its contents have been corrupted.
 
 
130808 */
130809 DbSetProperty(db, iDb, DB_SchemaLoaded);
130810 rc = SQLITE_OK;
130811 }
130812
@@ -134976,10 +135104,13 @@
134976 if( p->pPrior ){
134977 sqlite3SelectDelete(db, p->pPrior);
134978 }
134979 p->pPrior = pPrior;
134980 pPrior->pNext = p;
 
 
 
134981
134982 /*** TBD: Insert subroutine calls to close cursors on incomplete
134983 **** subqueries ****/
134984 ExplainQueryPlanPop(pParse);
134985 return pParse->nErr!=0;
@@ -135056,30 +135187,32 @@
135056 ifNullRow.flags = EP_IfNullRow;
135057 pCopy = &ifNullRow;
135058 }
135059 testcase( ExprHasProperty(pCopy, EP_Subquery) );
135060 pNew = sqlite3ExprDup(db, pCopy, 0);
135061 if( pNew && pSubst->isLeftJoin ){
 
 
 
 
135062 ExprSetProperty(pNew, EP_CanBeNull);
135063 }
135064 if( pNew && ExprHasProperty(pExpr,EP_FromJoin) ){
135065 sqlite3SetJoinExpr(pNew, pExpr->iRightJoinTable);
135066 }
135067 sqlite3ExprDelete(db, pExpr);
135068 pExpr = pNew;
135069
135070 /* Ensure that the expression now has an implicit collation sequence,
135071 ** just as it did when it was a column of a view or sub-query. */
135072 if( pExpr ){
135073 if( pExpr->op!=TK_COLUMN && pExpr->op!=TK_COLLATE ){
135074 CollSeq *pColl = sqlite3ExprCollSeq(pSubst->pParse, pExpr);
135075 pExpr = sqlite3ExprAddCollateString(pSubst->pParse, pExpr,
135076 (pColl ? pColl->zName : "BINARY")
135077 );
135078 }
135079 ExprClearProperty(pExpr, EP_Collate);
135080 }
135081 }
135082 }
135083 }else{
135084 if( pExpr->op==TK_IF_NULL_ROW && pExpr->iTable==pSubst->iTable ){
135085 pExpr->iTable = pSubst->iNewTable;
@@ -135194,11 +135327,14 @@
135194 int i;
135195 SrcItem *pItem;
135196 for(i=0, pItem=pSrc->a; i<pSrc->nSrc; i++, pItem++){
135197 if( i!=iExcept ){
135198 Select *p;
135199 pItem->iCursor = aCsrMap[pItem->iCursor] = pParse->nTab++;
 
 
 
135200 for(p=pItem->pSelect; p; p=p->pPrior){
135201 srclistRenumberCursors(pParse, aCsrMap, p->pSrc, -1);
135202 }
135203 }
135204 }
@@ -135634,11 +135770,11 @@
135634 pSubitem->pTab = pItemTab;
135635 if( pNew==0 ){
135636 p->pPrior = pPrior;
135637 }else{
135638 pNew->selId = ++pParse->nSelect;
135639 if( aCsrMap && db->mallocFailed==0 ){
135640 renumberCursors(pParse, pNew, iFrom, aCsrMap);
135641 }
135642 pNew->pPrior = pPrior;
135643 if( pPrior ) pPrior->pNext = pNew;
135644 pNew->pNext = p;
@@ -137626,12 +137762,11 @@
137626 if( pDest->eDest==SRT_Output ){
137627 generateColumnNames(pParse, p);
137628 }
137629
137630 #ifndef SQLITE_OMIT_WINDOWFUNC
137631 rc = sqlite3WindowRewrite(pParse, p);
137632 if( rc ){
137633 assert( db->mallocFailed || pParse->nErr>0 );
137634 goto select_end;
137635 }
137636 #if SELECTTRACE_ENABLED
137637 if( p->pWin && (sqlite3SelectTrace & 0x108)!=0 ){
@@ -138344,12 +138479,14 @@
138344 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
138345 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
138346 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct,
138347 WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0
138348 );
138349 sqlite3ExprListDelete(db, pDistinct);
138350 if( pWInfo==0 ) goto select_end;
 
 
138351 eDist = sqlite3WhereIsDistinct(pWInfo);
138352 SELECTTRACE(1,pParse,p,("WhereBegin returns\n"));
138353 if( sqlite3WhereIsOrdered(pWInfo)==pGroupBy->nExpr ){
138354 /* The optimizer is able to deliver rows in group by order so
138355 ** we do not have to sort. The OP_OpenEphemeral table will be
@@ -138478,10 +138615,11 @@
138478 }else{
138479 SELECTTRACE(1,pParse,p,("WhereEnd\n"));
138480 sqlite3WhereEnd(pWInfo);
138481 sqlite3VdbeChangeToNoop(v, addrSortingIdx);
138482 }
 
138483
138484 /* Output the final row of result
138485 */
138486 sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
138487 VdbeComment((v, "output final row"));
@@ -138692,10 +138830,12 @@
138692
138693 /* Control jumps to here if an error is encountered above, or upon
138694 ** successful coding of the SELECT.
138695 */
138696 select_end:
 
 
138697 sqlite3ExprListDelete(db, pMinMaxOrderBy);
138698 #ifdef SQLITE_DEBUG
138699 if( pAggInfo && !db->mallocFailed ){
138700 for(i=0; i<pAggInfo->nColumn; i++){
138701 Expr *pExpr = pAggInfo->aCol[i].pCExpr;
@@ -138982,37 +139122,45 @@
138982 if( pParse->disableTriggers ){
138983 return 0;
138984 }
138985 pTmpSchema = pParse->db->aDb[1].pSchema;
138986 p = sqliteHashFirst(&pTmpSchema->trigHash);
138987 if( p==0 ){
138988 return pTab->pTrigger;
138989 }
138990 pList = pTab->pTrigger;
138991 if( pTmpSchema!=pTab->pSchema ){
138992 while( p ){
138993 Trigger *pTrig = (Trigger *)sqliteHashData(p);
138994 if( pTrig->pTabSchema==pTab->pSchema
138995 && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
138996 ){
138997 pTrig->pNext = pList;
138998 pList = pTrig;
138999 }else if( pTrig->op==TK_RETURNING
 
139000 #ifndef SQLITE_OMIT_VIRTUALTABLE
139001 && pParse->db->pVtabCtx==0
139002 #endif
139003 ){
139004 assert( pParse->bReturning );
139005 assert( &(pParse->u1.pReturning->retTrig) == pTrig );
139006 pTrig->table = pTab->zName;
139007 pTrig->pTabSchema = pTab->pSchema;
139008 pTrig->pNext = pList;
139009 pList = pTrig;
139010 }
139011 p = sqliteHashNext(p);
139012 }
139013 }
 
 
 
 
 
 
 
 
 
 
139014 return pList;
139015 }
139016
139017 /*
139018 ** This is called by the parser when it sees a CREATE TRIGGER statement
@@ -140581,11 +140729,12 @@
140581 if( pLimit ){
140582 pGrp = sqlite3ExprListAppend(pParse, 0, sqlite3PExpr(pParse,TK_ROW,0,0));
140583 }
140584 #endif
140585 }
140586 if( ALWAYS(pChanges) ){
 
140587 for(i=0; i<pChanges->nExpr; i++){
140588 pList = sqlite3ExprListAppend(pParse, pList,
140589 sqlite3ExprDup(db, pChanges->a[i].pExpr, 0)
140590 );
140591 }
@@ -143607,10 +143756,11 @@
143607 pMod->pEpoTab = pTab;
143608 pTab->nTabRef = 1;
143609 pTab->pSchema = db->aDb[0].pSchema;
143610 assert( pTab->nModuleArg==0 );
143611 pTab->iPKey = -1;
 
143612 addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
143613 addModuleArgument(pParse, pTab, 0);
143614 addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
143615 rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
143616 if( rc ){
@@ -145019,10 +145169,11 @@
145019 zAff = sqlite3DbStrDup(pParse->db,sqlite3IndexAffinityStr(pParse->db,pIdx));
145020 assert( zAff!=0 || pParse->db->mallocFailed );
145021
145022 if( nSkip ){
145023 int iIdxCur = pLevel->iIdxCur;
 
145024 sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur);
145025 VdbeCoverageIf(v, bRev==0);
145026 VdbeCoverageIf(v, bRev!=0);
145027 VdbeComment((v, "begin skip-scan on %s", pIdx->zName));
145028 j = sqlite3VdbeAddOp0(v, OP_Goto);
@@ -145070,11 +145221,11 @@
145070 Expr *pRight = pTerm->pExpr->pRight;
145071 if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){
145072 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
145073 VdbeCoverage(v);
145074 }
145075 if( zAff ){
145076 if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_BLOB ){
145077 zAff[j] = SQLITE_AFF_BLOB;
145078 }
145079 if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){
145080 zAff[j] = SQLITE_AFF_BLOB;
@@ -147320,10 +147471,11 @@
147320 sqlite3 *db; /* Database connection (for malloc) */
147321 Expr *pNew; /* New virtual expression */
147322 int op; /* Operator for the combined expression */
147323 int idxNew; /* Index in pWC of the next virtual term */
147324
 
147325 if( (pOne->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return;
147326 if( (pTwo->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return;
147327 if( (eOp & (WO_EQ|WO_LT|WO_LE))!=eOp
147328 && (eOp & (WO_EQ|WO_GT|WO_GE))!=eOp ) return;
147329 assert( pOne->pExpr->pLeft!=0 && pOne->pExpr->pRight!=0 );
@@ -148973,11 +149125,13 @@
148973 ** If the right-hand branch of the expression is a TK_COLUMN, then return
148974 ** a pointer to the right-hand branch. Otherwise, return NULL.
148975 */
148976 static Expr *whereRightSubexprIsColumn(Expr *p){
148977 p = sqlite3ExprSkipCollateAndLikely(p->pRight);
148978 if( ALWAYS(p!=0) && p->op==TK_COLUMN ) return p;
 
 
148979 return 0;
148980 }
148981
148982 /*
148983 ** Advance to the next WhereTerm that matches according to the criteria
@@ -150652,11 +150806,11 @@
150652 ** Transfer content from the second pLoop into the first.
150653 */
150654 static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
150655 whereLoopClearUnion(db, pTo);
150656 if( whereLoopResize(db, pTo, pFrom->nLTerm) ){
150657 memset(&pTo->u, 0, sizeof(pTo->u));
150658 return SQLITE_NOMEM_BKPT;
150659 }
150660 memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
150661 memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
150662 if( pFrom->wsFlags & WHERE_VIRTUALTABLE ){
@@ -150694,10 +150848,21 @@
150694 whereLoopDelete(db, p);
150695 }
150696 assert( pWInfo->pExprMods==0 );
150697 sqlite3DbFreeNN(db, pWInfo);
150698 }
 
 
 
 
 
 
 
 
 
 
 
150699
150700 /*
150701 ** Return TRUE if all of the following are true:
150702 **
150703 ** (1) X has the same or lower cost that Y
@@ -152307,11 +152472,13 @@
152307 rc = whereLoopAddBtree(&sSubBuild, mPrereq);
152308 }
152309 if( rc==SQLITE_OK ){
152310 rc = whereLoopAddOr(&sSubBuild, mPrereq, mUnusable);
152311 }
152312 assert( rc==SQLITE_OK || rc==SQLITE_DONE || sCur.n==0 );
 
 
152313 testcase( rc==SQLITE_DONE );
152314 if( sCur.n==0 ){
152315 sSum.n = 0;
152316 break;
152317 }else if( once ){
@@ -152576,10 +152743,14 @@
152576 nKeyCol = pIndex->nKeyCol;
152577 nColumn = pIndex->nColumn;
152578 assert( nColumn==nKeyCol+1 || !HasRowid(pIndex->pTable) );
152579 assert( pIndex->aiColumn[nColumn-1]==XN_ROWID
152580 || !HasRowid(pIndex->pTable));
 
 
 
 
152581 isOrderDistinct = IsUniqueIndex(pIndex)
152582 && (pLoop->wsFlags & WHERE_SKIPSCAN)==0;
152583 }
152584
152585 /* Loop through all columns of the index and deal with the ones
@@ -152643,18 +152814,22 @@
152643 iColumn = XN_ROWID;
152644 revIdx = 0;
152645 }
152646
152647 /* An unconstrained column that might be NULL means that this
152648 ** WhereLoop is not well-ordered
152649 */
152650 if( isOrderDistinct
152651 && iColumn>=0
152652 && j>=pLoop->u.btree.nEq
152653 && pIndex->pTable->aCol[iColumn].notNull==0
152654 ){
152655 isOrderDistinct = 0;
 
 
 
 
152656 }
152657
152658 /* Find the ORDER BY term that corresponds to the j-th column
152659 ** of the index and mark that ORDER BY term off
152660 */
@@ -154026,10 +154201,12 @@
154026 return pWInfo;
154027
154028 /* Jump here if malloc fails */
154029 whereBeginError:
154030 if( pWInfo ){
 
 
154031 pParse->nQueryLoop = pWInfo->savedNQueryLoop;
154032 whereInfoFree(db, pWInfo);
154033 }
154034 return 0;
154035 }
@@ -154325,20 +154502,13 @@
154325 if( db->flags & SQLITE_VdbeAddopTrace ) printf("TRANSLATE complete\n");
154326 #endif
154327 }
154328 }
154329
154330 /* Undo all Expr node modifications */
154331 while( pWInfo->pExprMods ){
154332 WhereExprMod *p = pWInfo->pExprMods;
154333 pWInfo->pExprMods = p->pNext;
154334 memcpy(p->pExpr, &p->orig, sizeof(p->orig));
154335 sqlite3DbFree(db, p);
154336 }
154337
154338 /* Final cleanup
154339 */
 
154340 pParse->nQueryLoop = pWInfo->savedNQueryLoop;
154341 whereInfoFree(db, pWInfo);
154342 return;
154343 }
154344
@@ -155914,10 +156084,11 @@
155914 Vdbe *pVdbe; /* VDBE object */
155915 int addrGosub; /* OP_Gosub to this address to return one row */
155916 int regGosub; /* Register used with OP_Gosub(addrGosub) */
155917 int regArg; /* First in array of accumulator registers */
155918 int eDelete; /* See above */
 
155919
155920 WindowCsrAndReg start;
155921 WindowCsrAndReg current;
155922 WindowCsrAndReg end;
155923 };
@@ -156590,20 +156761,28 @@
156590 addrContinue = sqlite3VdbeCurrentAddr(v);
156591
156592 /* If this is a (RANGE BETWEEN a FOLLOWING AND b FOLLOWING) or
156593 ** (RANGE BETWEEN b PRECEDING AND a PRECEDING) frame, ensure the
156594 ** start cursor does not advance past the end cursor within the
156595 ** temporary table. It otherwise might, if (a>b). */
 
 
156596 if( pMWin->eStart==pMWin->eEnd && regCountdown
156597 && pMWin->eFrmType==TK_RANGE && op==WINDOW_AGGINVERSE
156598 ){
156599 int regRowid1 = sqlite3GetTempReg(pParse);
156600 int regRowid2 = sqlite3GetTempReg(pParse);
156601 sqlite3VdbeAddOp2(v, OP_Rowid, p->start.csr, regRowid1);
156602 sqlite3VdbeAddOp2(v, OP_Rowid, p->end.csr, regRowid2);
156603 sqlite3VdbeAddOp3(v, OP_Ge, regRowid2, lblDone, regRowid1);
156604 VdbeCoverage(v);
 
 
 
 
 
 
156605 sqlite3ReleaseTempReg(pParse, regRowid1);
156606 sqlite3ReleaseTempReg(pParse, regRowid2);
156607 assert( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_FOLLOWING );
156608 }
156609
@@ -157096,11 +157275,10 @@
157096 int addrGosubFlush = 0; /* Address of OP_Gosub to flush: */
157097 int addrInteger = 0; /* Address of OP_Integer */
157098 int addrEmpty; /* Address of OP_Rewind in flush: */
157099 int regNew; /* Array of registers holding new input row */
157100 int regRecord; /* regNew array in record form */
157101 int regRowid; /* Rowid for regRecord in eph table */
157102 int regNewPeer = 0; /* Peer values for new row (part of regNew) */
157103 int regPeer = 0; /* Peer values for current row */
157104 int regFlushPart = 0; /* Register for "Gosub flush_partition" */
157105 WindowCodeArg s; /* Context object for sub-routines */
157106 int lblWhereEnd; /* Label just before sqlite3WhereEnd() code */
@@ -157168,11 +157346,11 @@
157168 ** samve values in record form, and the rowid used to insert said record
157169 ** into the ephemeral table. */
157170 regNew = pParse->nMem+1;
157171 pParse->nMem += nInput;
157172 regRecord = ++pParse->nMem;
157173 regRowid = ++pParse->nMem;
157174
157175 /* If the window frame contains an "<expr> PRECEDING" or "<expr> FOLLOWING"
157176 ** clause, allocate registers to store the results of evaluating each
157177 ** <expr>. */
157178 if( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_FOLLOWING ){
@@ -157224,13 +157402,13 @@
157224 VdbeComment((v, "call flush_partition"));
157225 sqlite3VdbeAddOp3(v, OP_Copy, regNewPart, pMWin->regPart, nPart-1);
157226 }
157227
157228 /* Insert the new row into the ephemeral table */
157229 sqlite3VdbeAddOp2(v, OP_NewRowid, csrWrite, regRowid);
157230 sqlite3VdbeAddOp3(v, OP_Insert, csrWrite, regRecord, regRowid);
157231 addrNe = sqlite3VdbeAddOp3(v, OP_Ne, pMWin->regOne, 0, regRowid);
157232 VdbeCoverageNeverNull(v);
157233
157234 /* This block is run for the first row of each partition */
157235 s.regArg = windowInitAccum(pParse, pMWin);
157236
@@ -157344,10 +157522,11 @@
157344 if( pMWin->pPartition ){
157345 addrInteger = sqlite3VdbeAddOp2(v, OP_Integer, 0, regFlushPart);
157346 sqlite3VdbeJumpHere(v, addrGosubFlush);
157347 }
157348
 
157349 addrEmpty = sqlite3VdbeAddOp1(v, OP_Rewind, csrWrite);
157350 VdbeCoverage(v);
157351 if( pMWin->eEnd==TK_PRECEDING ){
157352 int bRPS = (pMWin->eStart==TK_PRECEDING && pMWin->eFrmType==TK_RANGE);
157353 windowCodeOp(&s, WINDOW_AGGSTEP, regEnd, 0);
@@ -161012,12 +161191,11 @@
161012 break;
161013 case 16: /* ifnotexists ::= IF NOT EXISTS */
161014 {yymsp[-2].minor.yy60 = 1;}
161015 break;
161016 case 17: /* temp ::= TEMP */
161017 case 46: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==46);
161018 {yymsp[0].minor.yy60 = 1;}
161019 break;
161020 case 19: /* create_table_args ::= LP columnlist conslist_opt RP table_options */
161021 {
161022 sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy60,0);
161023 }
@@ -161125,10 +161303,13 @@
161125 case 43: /* generated ::= LP expr RP */
161126 {sqlite3AddGenerated(pParse,yymsp[-1].minor.yy602,0);}
161127 break;
161128 case 44: /* generated ::= LP expr RP ID */
161129 {sqlite3AddGenerated(pParse,yymsp[-2].minor.yy602,&yymsp[0].minor.yy0);}
 
 
 
161130 break;
161131 case 47: /* refargs ::= */
161132 { yymsp[1].minor.yy60 = OE_None*0x0101; /* EV: R-19803-45884 */}
161133 break;
161134 case 48: /* refargs ::= refargs refarg */
@@ -162296,11 +162477,15 @@
162296 case 330: /* window_clause ::= WINDOW windowdefn_list */
162297 { yymsp[-1].minor.yy19 = yymsp[0].minor.yy19; }
162298 break;
162299 case 331: /* filter_over ::= filter_clause over_clause */
162300 {
162301 yymsp[0].minor.yy19->pFilter = yymsp[-1].minor.yy602;
 
 
 
 
162302 yylhsminor.yy19 = yymsp[0].minor.yy19;
162303 }
162304 yymsp[-1].minor.yy19 = yylhsminor.yy19;
162305 break;
162306 case 333: /* filter_over ::= filter_clause */
@@ -162795,10 +162980,11 @@
162795 #define CC_TILDA 25 /* '~' */
162796 #define CC_DOT 26 /* '.' */
162797 #define CC_ID 27 /* unicode characters usable in IDs */
162798 #define CC_ILLEGAL 28 /* Illegal character */
162799 #define CC_NUL 29 /* 0x00 */
 
162800
162801 static const unsigned char aiClass[] = {
162802 #ifdef SQLITE_ASCII
162803 /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf */
162804 /* 0x */ 29, 28, 28, 28, 28, 28, 28, 28, 28, 7, 7, 28, 7, 7, 28, 28,
@@ -162807,18 +162993,18 @@
162807 /* 3x */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 19, 12, 14, 13, 6,
162808 /* 4x */ 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
162809 /* 5x */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 9, 28, 28, 28, 2,
162810 /* 6x */ 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
162811 /* 7x */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 28, 10, 28, 25, 28,
162812 /* 8x */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
162813 /* 9x */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
162814 /* Ax */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
162815 /* Bx */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
162816 /* Cx */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
162817 /* Dx */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
162818 /* Ex */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
162819 /* Fx */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
162820 #endif
162821 #ifdef SQLITE_EBCDIC
162822 /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf */
162823 /* 0x */ 29, 28, 28, 28, 28, 7, 28, 28, 28, 28, 28, 28, 7, 7, 28, 28,
162824 /* 1x */ 28, 28, 28, 28, 28, 7, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
@@ -163757,10 +163943,18 @@
163757 ** SQL keywords start with the letter 'x'. Fall through */
163758 /* no break */ deliberate_fall_through
163759 }
163760 case CC_KYWD:
163761 case CC_ID: {
 
 
 
 
 
 
 
 
163762 i = 1;
163763 break;
163764 }
163765 case CC_NUL: {
163766 *tokenType = TK_ILLEGAL;
@@ -165745,11 +165939,11 @@
165745 }
165746
165747 /*
165748 ** Two variations on the public interface for closing a database
165749 ** connection. The sqlite3_close() version returns SQLITE_BUSY and
165750 ** leaves the connection option if there are unfinalized prepared
165751 ** statements or unfinished sqlite3_backups. The sqlite3_close_v2()
165752 ** version forces the connection to become a zombie if there are
165753 ** unclosed resources, and arranges for deallocation when the last
165754 ** prepare statement or sqlite3_backup closes.
165755 */
@@ -175552,20 +175746,19 @@
175552
175553 /* Determine which, if any, tokens in the expression should be deferred. */
175554 #ifndef SQLITE_DISABLE_FTS4_DEFERRED
175555 if( rc==SQLITE_OK && nToken>1 && pTab->bFts4 ){
175556 Fts3TokenAndCost *aTC;
175557 Fts3Expr **apOr;
175558 aTC = (Fts3TokenAndCost *)sqlite3_malloc64(
175559 sizeof(Fts3TokenAndCost) * nToken
175560 + sizeof(Fts3Expr *) * nOr * 2
175561 );
175562 apOr = (Fts3Expr **)&aTC[nToken];
175563
175564 if( !aTC ){
175565 rc = SQLITE_NOMEM;
175566 }else{
 
175567 int ii;
175568 Fts3TokenAndCost *pTC = aTC;
175569 Fts3Expr **ppOr = apOr;
175570
175571 fts3EvalTokenCosts(pCsr, 0, pCsr->pExpr, &pTC, &ppOr, &rc);
@@ -176937,10 +177130,11 @@
176937 /* In case this cursor is being reused, close and zero it. */
176938 testcase(pCsr->filter.zTerm);
176939 sqlite3Fts3SegReaderFinish(&pCsr->csr);
176940 sqlite3_free((void *)pCsr->filter.zTerm);
176941 sqlite3_free(pCsr->aStat);
 
176942 memset(&pCsr->csr, 0, ((u8*)&pCsr[1]) - (u8*)&pCsr->csr);
176943
176944 pCsr->filter.flags = FTS3_SEGMENT_REQUIRE_POS|FTS3_SEGMENT_IGNORE_EMPTY;
176945 if( isScan ) pCsr->filter.flags |= FTS3_SEGMENT_SCAN;
176946
@@ -182458,11 +182652,11 @@
182458 rc = (pLhs->aNode==0) - (pRhs->aNode==0);
182459 }
182460 if( rc==0 ){
182461 rc = pRhs->iIdx - pLhs->iIdx;
182462 }
182463 assert( rc!=0 );
182464 return rc;
182465 }
182466
182467 /*
182468 ** A different comparison function for SegReader structures. In this
@@ -186468,10 +186662,14 @@
186468 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
186469
186470 /* #include <string.h> */
186471 /* #include <assert.h> */
186472
 
 
 
 
186473 /*
186474 ** Characters that may appear in the second argument to matchinfo().
186475 */
186476 #define FTS3_MATCHINFO_NPHRASE 'p' /* 1 value */
186477 #define FTS3_MATCHINFO_NCOL 'c' /* 1 value */
@@ -186518,13 +186716,13 @@
186518 };
186519
186520 struct SnippetPhrase {
186521 int nToken; /* Number of tokens in phrase */
186522 char *pList; /* Pointer to start of phrase position list */
186523 int iHead; /* Next value in position list */
186524 char *pHead; /* Position list data following iHead */
186525 int iTail; /* Next value in trailing position list */
186526 char *pTail; /* Position list data following iTail */
186527 };
186528
186529 struct SnippetFragment {
186530 int iCol; /* Column snippet is extracted from */
@@ -186685,11 +186883,11 @@
186685 ** When this function is called, *pp points to the start of an element of
186686 ** the list. *piPos contains the value of the previous entry in the list.
186687 ** After it returns, *piPos contains the value of the next element of the
186688 ** list and *pp is advanced to the following varint.
186689 */
186690 static void fts3GetDeltaPosition(char **pp, int *piPos){
186691 int iVal;
186692 *pp += fts3GetVarint32(*pp, &iVal);
186693 *piPos += (iVal-2);
186694 }
186695
@@ -186794,14 +186992,14 @@
186794 /*
186795 ** Advance the position list iterator specified by the first two
186796 ** arguments so that it points to the first element with a value greater
186797 ** than or equal to parameter iNext.
186798 */
186799 static void fts3SnippetAdvance(char **ppIter, int *piIter, int iNext){
186800 char *pIter = *ppIter;
186801 if( pIter ){
186802 int iIter = *piIter;
186803
186804 while( iIter<iNext ){
186805 if( 0==(*pIter & 0xFE) ){
186806 iIter = -1;
186807 pIter = 0;
@@ -186880,11 +187078,11 @@
186880
186881 for(i=0; i<pIter->nPhrase; i++){
186882 SnippetPhrase *pPhrase = &pIter->aPhrase[i];
186883 if( pPhrase->pTail ){
186884 char *pCsr = pPhrase->pTail;
186885 int iCsr = pPhrase->iTail;
186886
186887 while( iCsr<(iStart+pIter->nSnippet) && iCsr>=iStart ){
186888 int j;
186889 u64 mPhrase = (u64)1 << (i%64);
186890 u64 mPos = (u64)1 << (iCsr - iStart);
@@ -186926,11 +187124,11 @@
186926
186927 pPhrase->nToken = pExpr->pPhrase->nToken;
186928 rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pCsr);
186929 assert( rc==SQLITE_OK || pCsr==0 );
186930 if( pCsr ){
186931 int iFirst = 0;
186932 pPhrase->pList = pCsr;
186933 fts3GetDeltaPosition(&pCsr, &iFirst);
186934 if( iFirst<0 ){
186935 rc = FTS_CORRUPT_VTAB;
186936 }else{
@@ -187990,12 +188188,12 @@
187990 typedef struct TermOffset TermOffset;
187991 typedef struct TermOffsetCtx TermOffsetCtx;
187992
187993 struct TermOffset {
187994 char *pList; /* Position-list */
187995 int iPos; /* Position just read from pList */
187996 int iOff; /* Offset of this term from read positions */
187997 };
187998
187999 struct TermOffsetCtx {
188000 Fts3Cursor *pCsr;
188001 int iCol; /* Column of table to populate aTerm for */
@@ -188010,11 +188208,11 @@
188010 static int fts3ExprTermOffsetInit(Fts3Expr *pExpr, int iPhrase, void *ctx){
188011 TermOffsetCtx *p = (TermOffsetCtx *)ctx;
188012 int nTerm; /* Number of tokens in phrase */
188013 int iTerm; /* For looping through nTerm phrase terms */
188014 char *pList; /* Pointer to position list for phrase */
188015 int iPos = 0; /* First position in position-list */
188016 int rc;
188017
188018 UNUSED_PARAMETER(iPhrase);
188019 rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pList);
188020 nTerm = pExpr->pPhrase->nToken;
@@ -190886,12 +191084,12 @@
190886 if( pStr->zBuf==0 ){
190887 jsonInit(pStr, ctx);
190888 jsonAppendChar(pStr, '[');
190889 }else if( pStr->nUsed>1 ){
190890 jsonAppendChar(pStr, ',');
190891 pStr->pCtx = ctx;
190892 }
 
190893 jsonAppendValue(pStr, argv[0]);
190894 }
190895 }
190896 static void jsonArrayCompute(sqlite3_context *ctx, int isFinal){
190897 JsonString *pStr;
@@ -190947,26 +191145,27 @@
190947 /* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will
190948 ** always have been called to initalize it */
190949 if( NEVER(!pStr) ) return;
190950 #endif
190951 z = pStr->zBuf;
190952 for(i=1; (c = z[i])!=',' || inStr || nNest; i++){
190953 if( i>=pStr->nUsed ){
190954 pStr->nUsed = 1;
190955 return;
190956 }
190957 if( c=='"' ){
190958 inStr = !inStr;
190959 }else if( c=='\\' ){
190960 i++;
190961 }else if( !inStr ){
190962 if( c=='{' || c=='[' ) nNest++;
190963 if( c=='}' || c==']' ) nNest--;
190964 }
190965 }
190966 pStr->nUsed -= i;
190967 memmove(&z[1], &z[i+1], (size_t)pStr->nUsed-1);
 
 
 
 
 
190968 }
190969 #else
190970 # define jsonGroupInverse 0
190971 #endif
190972
@@ -195512,15 +195711,20 @@
195512 */
195513 static void rtreedepth(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){
195514 UNUSED_PARAMETER(nArg);
195515 if( sqlite3_value_type(apArg[0])!=SQLITE_BLOB
195516 || sqlite3_value_bytes(apArg[0])<2
 
195517 ){
195518 sqlite3_result_error(ctx, "Invalid argument to rtreedepth()", -1);
195519 }else{
195520 u8 *zBlob = (u8 *)sqlite3_value_blob(apArg[0]);
195521 sqlite3_result_int(ctx, readInt16(zBlob));
 
 
 
 
195522 }
195523 }
195524
195525 /*
195526 ** Context object passed between the various routines that make up the
@@ -206045,17 +206249,19 @@
206045 ** Session handle structure.
206046 */
206047 struct sqlite3_session {
206048 sqlite3 *db; /* Database handle session is attached to */
206049 char *zDb; /* Name of database session is attached to */
 
206050 int bEnable; /* True if currently recording */
206051 int bIndirect; /* True if all changes are indirect */
206052 int bAutoAttach; /* True to auto-attach tables */
206053 int rc; /* Non-zero if an error has occurred */
206054 void *pFilterCtx; /* First argument to pass to xTableFilter */
206055 int (*xTableFilter)(void *pCtx, const char *zTab);
206056 i64 nMalloc; /* Number of bytes of data allocated */
 
206057 sqlite3_value *pZeroBlob; /* Value containing X'' */
206058 sqlite3_session *pNext; /* Next session object on same db. */
206059 SessionTable *pTable; /* List of attached tables */
206060 SessionHook hook; /* APIs to grab new and old data with */
206061 };
@@ -206294,12 +206500,13 @@
206294 /*
206295 ** For each row modified during a session, there exists a single instance of
206296 ** this structure stored in a SessionTable.aChange[] hash table.
206297 */
206298 struct SessionChange {
206299 int op; /* One of UPDATE, DELETE, INSERT */
206300 int bIndirect; /* True if this change is "indirect" */
 
206301 int nRecord; /* Number of bytes in buffer aRecord[] */
206302 u8 *aRecord; /* Buffer containing old.* record */
206303 SessionChange *pNext; /* For hash-table collisions */
206304 };
206305
@@ -207124,10 +207331,16 @@
207124 }
207125 }
207126 if( 0==sqlite3_stricmp("sqlite_stat1", pTab->zName) ){
207127 pTab->bStat1 = 1;
207128 }
 
 
 
 
 
 
207129 }
207130 }
207131 return (pSession->rc || pTab->abPK==0);
207132 }
207133
@@ -207169,10 +207382,107 @@
207169 static int sessionStat1Depth(void *pCtx){
207170 SessionStat1Ctx *p = (SessionStat1Ctx*)pCtx;
207171 return p->hook.xDepth(p->hook.pCtx);
207172 }
207173
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207174
207175 /*
207176 ** This function is only called from with a pre-update-hook reporting a
207177 ** change on table pTab (attached to session pSession). The type of change
207178 ** (UPDATE, INSERT, DELETE) is specified by the first argument.
@@ -207242,11 +207552,10 @@
207242
207243 if( pC==0 ){
207244 /* Create a new change object containing all the old values (if
207245 ** this is an SQLITE_UPDATE or SQLITE_DELETE), or just the PK
207246 ** values (if this is an INSERT). */
207247 SessionChange *pChange; /* New change object */
207248 sqlite3_int64 nByte; /* Number of bytes to allocate */
207249 int i; /* Used to iterate through columns */
207250
207251 assert( rc==SQLITE_OK );
207252 pTab->nEntry++;
@@ -207268,17 +207577,17 @@
207268 rc = sessionSerializeValue(0, p, &nByte);
207269 if( rc!=SQLITE_OK ) goto error_out;
207270 }
207271
207272 /* Allocate the change object */
207273 pChange = (SessionChange *)sessionMalloc64(pSession, nByte);
207274 if( !pChange ){
207275 rc = SQLITE_NOMEM;
207276 goto error_out;
207277 }else{
207278 memset(pChange, 0, sizeof(SessionChange));
207279 pChange->aRecord = (u8 *)&pChange[1];
207280 }
207281
207282 /* Populate the change object. None of the preupdate_old(),
207283 ** preupdate_new() or SerializeValue() calls below may fail as all
207284 ** required values and encodings have already been cached in memory.
@@ -207289,21 +207598,21 @@
207289 if( op!=SQLITE_INSERT ){
207290 pSession->hook.xOld(pSession->hook.pCtx, i, &p);
207291 }else if( pTab->abPK[i] ){
207292 pSession->hook.xNew(pSession->hook.pCtx, i, &p);
207293 }
207294 sessionSerializeValue(&pChange->aRecord[nByte], p, &nByte);
207295 }
207296
207297 /* Add the change to the hash-table */
207298 if( pSession->bIndirect || pSession->hook.xDepth(pSession->hook.pCtx) ){
207299 pChange->bIndirect = 1;
207300 }
207301 pChange->nRecord = nByte;
207302 pChange->op = op;
207303 pChange->pNext = pTab->apChange[iHash];
207304 pTab->apChange[iHash] = pChange;
207305
207306 }else if( pC->bIndirect ){
207307 /* If the existing change is considered "indirect", but this current
207308 ** change is "direct", mark the change object as direct. */
207309 if( pSession->hook.xDepth(pSession->hook.pCtx)==0
@@ -207310,11 +207619,17 @@
207310 && pSession->bIndirect==0
207311 ){
207312 pC->bIndirect = 0;
207313 }
207314 }
 
 
 
 
 
207315 }
 
207316
207317 /* If an error has occurred, mark the session object as failed. */
207318 error_out:
207319 if( pTab->bStat1 ){
207320 pSession->hook = stat1.hook;
@@ -208523,11 +208838,15 @@
208523 SQLITE_API int sqlite3session_changeset(
208524 sqlite3_session *pSession, /* Session object */
208525 int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
208526 void **ppChangeset /* OUT: Buffer containing changeset */
208527 ){
208528 return sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset, ppChangeset);
 
 
 
 
208529 }
208530
208531 /*
208532 ** Streaming version of sqlite3session_changeset().
208533 */
@@ -208614,10 +208933,43 @@
208614 ** Return the amount of heap memory in use.
208615 */
208616 SQLITE_API sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession){
208617 return pSession->nMalloc;
208618 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208619
208620 /*
208621 ** Do the work for either sqlite3changeset_start() or start_strm().
208622 */
208623 static int sessionChangesetStart(
@@ -216198,11 +216550,11 @@
216198 pRet->db = db;
216199 pRet->iCookie = -1;
216200
216201 nByte = nArg * (sizeof(char*) + sizeof(u8));
216202 pRet->azCol = (char**)sqlite3Fts5MallocZero(&rc, nByte);
216203 pRet->abUnindexed = (u8*)&pRet->azCol[nArg];
216204 pRet->zDb = sqlite3Fts5Strndup(&rc, azArg[1], -1);
216205 pRet->zName = sqlite3Fts5Strndup(&rc, azArg[2], -1);
216206 pRet->bColumnsize = 1;
216207 pRet->eDetail = FTS5_DETAIL_FULL;
216208 #ifdef SQLITE_DEBUG
@@ -219034,10 +219386,11 @@
219034 }
219035
219036 return pRet;
219037 }
219038
 
219039 static char *fts5ExprTermPrint(Fts5ExprTerm *pTerm){
219040 sqlite3_int64 nByte = 0;
219041 Fts5ExprTerm *p;
219042 char *zQuoted;
219043
@@ -219400,16 +219753,18 @@
219400 iCode = sqlite3_value_int(apVal[0]);
219401 if( nArg==2 ) bRemoveDiacritics = sqlite3_value_int(apVal[1]);
219402 sqlite3_result_int(pCtx, sqlite3Fts5UnicodeFold(iCode, bRemoveDiacritics));
219403 }
219404 }
 
219405
219406 /*
219407 ** This is called during initialization to register the fts5_expr() scalar
219408 ** UDF with the SQLite handle passed as the only argument.
219409 */
219410 static int sqlite3Fts5ExprInit(Fts5Global *pGlobal, sqlite3 *db){
 
219411 struct Fts5ExprFunc {
219412 const char *z;
219413 void (*x)(sqlite3_context*,int,sqlite3_value**);
219414 } aFunc[] = {
219415 { "fts5_expr", fts5ExprFunctionHr },
@@ -219423,10 +219778,14 @@
219423
219424 for(i=0; rc==SQLITE_OK && i<ArraySize(aFunc); i++){
219425 struct Fts5ExprFunc *p = &aFunc[i];
219426 rc = sqlite3_create_function(db, p->z, -1, SQLITE_UTF8, pCtx, p->x, 0, 0);
219427 }
 
 
 
 
219428
219429 /* Avoid warnings indicating that sqlite3Fts5ParserTrace() and
219430 ** sqlite3Fts5ParserFallback() are unused */
219431 #ifndef NDEBUG
219432 (void)sqlite3Fts5ParserTrace;
@@ -220669,11 +221028,11 @@
220669 Fts5StructureSegment *pSeg; /* Segment to iterate through */
220670 int flags; /* Mask of configuration flags */
220671 int iLeafPgno; /* Current leaf page number */
220672 Fts5Data *pLeaf; /* Current leaf data */
220673 Fts5Data *pNextLeaf; /* Leaf page (iLeafPgno+1) */
220674 int iLeafOffset; /* Byte offset within current leaf */
220675
220676 /* Next method */
220677 void (*xNext)(Fts5Index*, Fts5SegIter*, int*);
220678
220679 /* The page and offset from which the current term was read. The offset
@@ -221849,11 +222208,11 @@
221849 }
221850 }
221851
221852 static void fts5SegIterLoadRowid(Fts5Index *p, Fts5SegIter *pIter){
221853 u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
221854 int iOff = pIter->iLeafOffset;
221855
221856 ASSERT_SZLEAF_OK(pIter->pLeaf);
221857 if( iOff>=pIter->pLeaf->szLeaf ){
221858 fts5SegIterNextPage(p, pIter);
221859 if( pIter->pLeaf==0 ){
@@ -221882,11 +222241,11 @@
221882 ** the first position list. The position list belonging to document
221883 ** (Fts5SegIter.iRowid).
221884 */
221885 static void fts5SegIterLoadTerm(Fts5Index *p, Fts5SegIter *pIter, int nKeep){
221886 u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
221887 int iOff = pIter->iLeafOffset; /* Offset to read at */
221888 int nNew; /* Bytes of new data */
221889
221890 iOff += fts5GetVarint32(&a[iOff], nNew);
221891 if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){
221892 p->rc = FTS5_CORRUPT;
@@ -224779,18 +225138,18 @@
224779 if( pgsz>=(pBuf->n + pPgidx->n + nDoclist + 1) ){
224780 /* The entire doclist will fit on the current leaf. */
224781 fts5BufferSafeAppendBlob(pBuf, pDoclist, nDoclist);
224782 }else{
224783 i64 iRowid = 0;
224784 i64 iDelta = 0;
224785 int iOff = 0;
224786
224787 /* The entire doclist will not fit on this leaf. The following
224788 ** loop iterates through the poslists that make up the current
224789 ** doclist. */
224790 while( p->rc==SQLITE_OK && iOff<nDoclist ){
224791 iOff += fts5GetVarint(&pDoclist[iOff], (u64*)&iDelta);
224792 iRowid += iDelta;
224793
224794 if( writer.bFirstRowidInPage ){
224795 fts5PutU16(&pBuf->p[0], (u16)pBuf->n); /* first rowid on page */
224796 pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid);
@@ -225317,11 +225676,12 @@
225317 sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, pHead->iPos);
225318 }
225319 nTail = pHead->iter.nPoslist - pHead->iOff;
225320
225321 /* WRITEPOSLISTSIZE */
225322 assert( tmp.n+nTail<=nTmp );
 
225323 if( tmp.n+nTail>nTmp-FTS5_DATA_ZERO_PADDING ){
225324 if( p->rc==SQLITE_OK ) p->rc = FTS5_CORRUPT;
225325 break;
225326 }
225327 fts5BufferSafeAppendVarint(&out, (tmp.n+nTail) * 2);
@@ -226958,10 +227318,11 @@
226958 );
226959 }
226960 return rc;
226961 #else
226962 return SQLITE_OK;
 
226963 #endif
226964 }
226965
226966
226967 static int sqlite3Fts5IndexReset(Fts5Index *p){
@@ -229762,11 +230123,11 @@
229762 int nArg, /* Number of args */
229763 sqlite3_value **apUnused /* Function arguments */
229764 ){
229765 assert( nArg==0 );
229766 UNUSED_PARAM2(nArg, apUnused);
229767 sqlite3_result_text(pCtx, "fts5: 2021-04-07 13:20:34 c22e47c77a35ebcd1fdfc0caea9119dd5e24e76d5fdd0f2ffbb58205a7242297", -1, SQLITE_TRANSIENT);
229768 }
229769
229770 /*
229771 ** Return true if zName is the extension on one of the shadow tables used
229772 ** by this module.
@@ -234688,12 +235049,12 @@
234688 }
234689 #endif /* SQLITE_CORE */
234690 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
234691
234692 /************** End of stmt.c ************************************************/
234693 #if __LINE__!=234693
234694 #undef SQLITE_SOURCE_ID
234695 #define SQLITE_SOURCE_ID "2021-04-07 18:17:53 a2ddb89b206c13876d34c5f9e3db41cda72d6eb3fea31ffa8cc6daa1e158alt2"
234696 #endif
234697 /* Return the source-id for this library */
234698 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
234699 /************************** End of sqlite3.c ******************************/
234700
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1186,11 +1186,11 @@
1186 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1187 ** [sqlite_version()] and [sqlite_source_id()].
1188 */
1189 #define SQLITE_VERSION "3.36.0"
1190 #define SQLITE_VERSION_NUMBER 3036000
1191 #define SQLITE_SOURCE_ID "2021-04-28 17:37:26 65ec39f0f092fe29e1d4e9e96cf07a73d2ef7ce2c41b6f1cd3ab23546ada0e67"
1192
1193 /*
1194 ** CAPI3REF: Run-Time Library Version Numbers
1195 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1196 **
@@ -10607,10 +10607,19 @@
10607 ** callback was invoked as a result of a direct insert, update, or delete
10608 ** operation; or 1 for inserts, updates, or deletes invoked by top-level
10609 ** triggers; or 2 for changes resulting from triggers called by top-level
10610 ** triggers; and so forth.
10611 **
10612 ** When the [sqlite3_blob_write()] API is used to update a blob column,
10613 ** the pre-update hook is invoked with SQLITE_DELETE. This is because the
10614 ** in this case the new values are not available. In this case, when a
10615 ** callback made with op==SQLITE_DELETE is actuall a write using the
10616 ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
10617 ** the index of the column being written. In other cases, where the
10618 ** pre-update hook is being invoked for some other reason, including a
10619 ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
10620 **
10621 ** See also: [sqlite3_update_hook()]
10622 */
10623 #if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
10624 SQLITE_API void *sqlite3_preupdate_hook(
10625 sqlite3 *db,
@@ -10627,10 +10636,11 @@
10636 );
10637 SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
10638 SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
10639 SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
10640 SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
10641 SQLITE_API int sqlite3_preupdate_blobwrite(sqlite3 *);
10642 #endif
10643
10644 /*
10645 ** CAPI3REF: Low-level system error code
10646 ** METHOD: sqlite3
@@ -11167,10 +11177,41 @@
11177 ** are attached is closed. Refer to the documentation for
11178 ** [sqlite3session_create()] for details.
11179 */
11180 SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
11181
11182 /*
11183 ** CAPIREF: Conigure a Session Object
11184 ** METHOD: sqlite3_session
11185 **
11186 ** This method is used to configure a session object after it has been
11187 ** created. At present the only valid value for the second parameter is
11188 ** [SQLITE_SESSION_OBJCONFIG_SIZE].
11189 */
11190 SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
11191
11192 /*
11193 ** CAPI3REF: Arguments for sqlite3session_object_config()
11194 **
11195 ** The following values may passed as the the 4th parameter to
11196 ** [sqlite3session_object_config].
11197 **
11198 ** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
11199 ** This option is used to set, clear or query the flag that enables
11200 ** the [sqlite3session_changeset_size()] API. Because it imposes some
11201 ** computational overhead, this API is disabled by default. Argument
11202 ** pArg must point to a value of type (int). If the value is initially
11203 ** 0, then the sqlite3session_changeset_size() API is disabled. If it
11204 ** is greater than 0, then the same API is enabled. Or, if the initial
11205 ** value is less than zero, no change is made. In all cases the (int)
11206 ** variable is set to 1 if the sqlite3session_changeset_size() API is
11207 ** enabled following the current call, or 0 otherwise.
11208 **
11209 ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
11210 ** the first table has been attached to the session object.
11211 */
11212 #define SQLITE_SESSION_OBJCONFIG_SIZE 1
11213
11214 /*
11215 ** CAPI3REF: Enable Or Disable A Session Object
11216 ** METHOD: sqlite3_session
11217 **
@@ -11411,10 +11452,26 @@
11452 sqlite3_session *pSession, /* Session object */
11453 int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
11454 void **ppChangeset /* OUT: Buffer containing changeset */
11455 );
11456
11457 /*
11458 ** CAPI3REF: Return An Upper-limit For The Size Of The Changeset
11459 ** METHOD: sqlite3session_changeset_size()
11460 **
11461 ** By default, this function always returns 0. For it to return
11462 ** a useful result, the sqlite3_session object must have been configured
11463 ** to enable this API using [sqlite3session_object_config()] with the
11464 ** SQLITE_SESSION_OBJCONFIG_SIZE verb.
11465 **
11466 ** When enabled, this function returns an upper limit, in bytes, for the size
11467 ** of the changeset that might be produced if sqlite3session_changeset() were
11468 ** called. The final changeset size might be equal to or smaller than the
11469 ** size in bytes returned by this function.
11470 */
11471 SQLITE_API sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession);
11472
11473 /*
11474 ** CAPI3REF: Load The Difference Between Tables Into A Session
11475 ** METHOD: sqlite3_session
11476 **
11477 ** If it is not already attached to the session object passed as the first
@@ -17724,10 +17781,11 @@
17781 #define TF_OOOHidden 0x0400 /* Out-of-Order hidden columns */
17782 #define TF_HasNotNull 0x0800 /* Contains NOT NULL constraints */
17783 #define TF_Shadow 0x1000 /* True for a shadow table */
17784 #define TF_HasStat4 0x2000 /* STAT4 info available for this table */
17785 #define TF_Ephemeral 0x4000 /* An ephemeral table */
17786 #define TF_Eponymous 0x8000 /* An eponymous virtual table */
17787
17788 /*
17789 ** Test to see whether or not a table is a virtual table. This is
17790 ** done as a macro so that it will be optimized out when virtual
17791 ** table support is omitted from the build.
@@ -18553,11 +18611,11 @@
18611 Upsert *pUpsert; /* ON CONFLICT clause information from an upsert */
18612 int iBaseReg; /* For TK_REGISTER when parsing RETURNING */
18613 } uNC;
18614 NameContext *pNext; /* Next outer name context. NULL for outermost */
18615 int nRef; /* Number of names resolved by this context */
18616 int nNcErr; /* Number of errors encountered while resolving names */
18617 int ncFlags; /* Zero or more NC_* flags defined below */
18618 Select *pWinSelect; /* SELECT statement for any window functions */
18619 };
18620
18621 /*
@@ -18586,10 +18644,11 @@
18644 #define NC_AllowWin 0x04000 /* Window functions are allowed here */
18645 #define NC_HasWin 0x08000 /* One or more window functions seen */
18646 #define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */
18647 #define NC_InAggFunc 0x20000 /* True if analyzing arguments to an agg func */
18648 #define NC_FromDDL 0x40000 /* SQL text comes from sqlite_schema */
18649 #define NC_NoSelect 0x80000 /* Do not descend into sub-selects */
18650
18651 /*
18652 ** An instance of the following object describes a single ON CONFLICT
18653 ** clause in an upsert.
18654 **
@@ -19367,10 +19426,11 @@
19426 SQLITE_PRIVATE int sqlite3ExprWalkNoop(Walker*, Expr*);
19427 SQLITE_PRIVATE int sqlite3SelectWalkNoop(Walker*, Select*);
19428 SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker*, Select*);
19429 SQLITE_PRIVATE int sqlite3WalkerDepthIncrease(Walker*,Select*);
19430 SQLITE_PRIVATE void sqlite3WalkerDepthDecrease(Walker*,Select*);
19431 SQLITE_PRIVATE void sqlite3WalkWinDefnDummyCallback(Walker*,Select*);
19432
19433 #ifdef SQLITE_DEBUG
19434 SQLITE_PRIVATE void sqlite3SelectWalkAssert2(Walker*, Select*);
19435 #endif
19436
@@ -21500,10 +21560,11 @@
21560 u8 *aRecord; /* old.* database record */
21561 KeyInfo keyinfo;
21562 UnpackedRecord *pUnpacked; /* Unpacked version of aRecord[] */
21563 UnpackedRecord *pNewUnpacked; /* Unpacked version of new.* record */
21564 int iNewReg; /* Register for new.* values */
21565 int iBlobWrite; /* Value returned by preupdate_blobwrite() */
21566 i64 iKey1; /* First key value passed to hook */
21567 i64 iKey2; /* Second key value passed to hook */
21568 Mem *aNew; /* Array of new.* values */
21569 Table *pTab; /* Schema object being upated */
21570 Index *pPk; /* PK index if pTab is WITHOUT ROWID */
@@ -21588,11 +21649,12 @@
21649 #endif
21650 SQLITE_PRIVATE void sqlite3VdbeFrameMemDel(void*); /* Destructor on Mem */
21651 SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*); /* Actually deletes the Frame */
21652 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
21653 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
21654 SQLITE_PRIVATE void sqlite3VdbePreUpdateHook(
21655 Vdbe*,VdbeCursor*,int,const char*,Table*,i64,int,int);
21656 #endif
21657 SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p);
21658
21659 SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *, int, VdbeCursor *);
21660 SQLITE_PRIVATE void sqlite3VdbeSorterReset(sqlite3 *, VdbeSorter *);
@@ -29932,10 +29994,11 @@
29994 for(i=0; i<pSrc->nSrc; i++){
29995 const SrcItem *pItem = &pSrc->a[i];
29996 StrAccum x;
29997 char zLine[100];
29998 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
29999 x.printfFlags |= SQLITE_PRINTF_INTERNAL;
30000 sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
30001 if( pItem->pTab ){
30002 sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx",
30003 pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed);
30004 }
@@ -48518,11 +48581,11 @@
48581 return SQLITE_FULL;
48582 }
48583 newSz *= 2;
48584 if( newSz>p->szMax ) newSz = p->szMax;
48585 pNew = sqlite3Realloc(p->aData, newSz);
48586 if( pNew==0 ) return SQLITE_IOERR_NOMEM;
48587 p->aData = pNew;
48588 p->szAlloc = newSz;
48589 return SQLITE_OK;
48590 }
48591
@@ -58067,11 +58130,11 @@
58130
58131 if( pPager->errCode ) return pPager->errCode;
58132 assert( pPager->eState>=PAGER_READER && pPager->eState<PAGER_ERROR );
58133 pPager->subjInMemory = (u8)subjInMemory;
58134
58135 if( pPager->eState==PAGER_READER ){
58136 assert( pPager->pInJournal==0 );
58137
58138 if( pagerUseWal(pPager) ){
58139 /* If the pager is configured to use locking_mode=exclusive, and an
58140 ** exclusive lock on the database is not already held, obtain it now.
@@ -66488,10 +66551,11 @@
66551 unsigned char *data; /* The page data */
66552 unsigned char *temp; /* Temp area for cell content */
66553 unsigned char *src; /* Source of content */
66554 int iCellFirst; /* First allowable cell index */
66555 int iCellLast; /* Last possible cell index */
66556 int iCellStart; /* First cell offset in input */
66557
66558 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
66559 assert( pPage->pBt!=0 );
66560 assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
66561 assert( pPage->nOverflow==0 );
@@ -66529,11 +66593,11 @@
66593 if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage);
66594 sz2 = get2byte(&data[iFree2+2]);
66595 if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage);
66596 memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
66597 sz += sz2;
66598 }else if( iFree+sz>usableSize ){
66599 return SQLITE_CORRUPT_PAGE(pPage);
66600 }
66601
66602 cbrk = top+sz;
66603 assert( cbrk+(iFree-top) <= usableSize );
@@ -66548,38 +66612,37 @@
66612 }
66613 }
66614
66615 cbrk = usableSize;
66616 iCellLast = usableSize - 4;
66617 iCellStart = get2byte(&data[hdr+5]);
66618 for(i=0; i<nCell; i++){
66619 u8 *pAddr; /* The i-th cell pointer */
66620 pAddr = &data[cellOffset + i*2];
66621 pc = get2byte(pAddr);
66622 testcase( pc==iCellFirst );
66623 testcase( pc==iCellLast );
66624 /* These conditions have already been verified in btreeInitPage()
66625 ** if PRAGMA cell_size_check=ON.
66626 */
66627 if( pc<iCellStart || pc>iCellLast ){
66628 return SQLITE_CORRUPT_PAGE(pPage);
66629 }
66630 assert( pc>=iCellStart && pc<=iCellLast );
66631 size = pPage->xCellSize(pPage, &src[pc]);
66632 cbrk -= size;
66633 if( cbrk<iCellStart || pc+size>usableSize ){
66634 return SQLITE_CORRUPT_PAGE(pPage);
66635 }
66636 assert( cbrk+size<=usableSize && cbrk>=iCellStart );
66637 testcase( cbrk+size==usableSize );
66638 testcase( pc+size==usableSize );
66639 put2byte(pAddr, cbrk);
66640 if( temp==0 ){
 
66641 if( cbrk==pc ) continue;
66642 temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
66643 memcpy(&temp[iCellStart], &data[iCellStart], (cbrk+size) - iCellStart);
 
66644 src = temp;
66645 }
66646 memcpy(&data[cbrk], &src[pc], size);
66647 }
66648 data[hdr+7] = 0;
@@ -72055,11 +72118,11 @@
72118 pData = pEnd;
72119 while( 1/*exit by break*/ ){
72120 u8 *pCell = pCArray->apCell[i];
72121 u16 sz = pCArray->szCell[i];
72122 assert( sz>0 );
72123 if( SQLITE_WITHIN(pCell,aData+j,pEnd) ){
72124 if( ((uptr)(pCell+sz))>(uptr)pEnd ) return SQLITE_CORRUPT_BKPT;
72125 pCell = &pTmp[pCell - aData];
72126 }else if( (uptr)(pCell+sz)>(uptr)pSrcEnd
72127 && (uptr)(pCell)<(uptr)pSrcEnd
72128 ){
@@ -72068,13 +72131,12 @@
72131
72132 pData -= sz;
72133 put2byte(pCellptr, (pData - aData));
72134 pCellptr += 2;
72135 if( pData < pCellptr ) return SQLITE_CORRUPT_BKPT;
72136 memmove(pData, pCell, sz);
72137 assert( sz==pPg->xCellSize(pPg, pCell) || CORRUPT_DB );
 
72138 i++;
72139 if( i>=iEnd ) break;
72140 if( pCArray->ixNx[k]<=i ){
72141 k++;
72142 pSrcEnd = pCArray->apEnd[k];
@@ -72862,11 +72924,11 @@
72924 b.apCell[b.nCell] = pTemp+leafCorrection;
72925 assert( leafCorrection==0 || leafCorrection==4 );
72926 b.szCell[b.nCell] = b.szCell[b.nCell] - leafCorrection;
72927 if( !pOld->leaf ){
72928 assert( leafCorrection==0 );
72929 assert( pOld->hdrOffset==0 || CORRUPT_DB );
72930 /* The right pointer of the child page pOld becomes the left
72931 ** pointer of the divider cell */
72932 memcpy(b.apCell[b.nCell], &pOld->aData[8], 4);
72933 }else{
72934 assert( leafCorrection==4 );
@@ -73770,10 +73832,18 @@
73832 ** not to clear the cursor here.
73833 */
73834 if( pCur->curFlags & BTCF_Multiple ){
73835 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
73836 if( rc ) return rc;
73837 if( loc && pCur->iPage<0 ){
73838 /* This can only happen if the schema is corrupt such that there is more
73839 ** than one table or index with the same root page as used by the cursor.
73840 ** Which can only happen if the SQLITE_NoSchemaError flag was set when
73841 ** the schema was loaded. This cannot be asserted though, as a user might
73842 ** set the flag, load the schema, and then unset the flag. */
73843 return SQLITE_CORRUPT_BKPT;
73844 }
73845 }
73846
73847 if( pCur->pKeyInfo==0 ){
73848 assert( pX->pKey==0 );
73849 /* If this is an insert into a table b-tree, invalidate any incrblob
@@ -73857,21 +73927,20 @@
73927 x2.nData = pX->nKey;
73928 x2.nZero = 0;
73929 return btreeOverwriteCell(pCur, &x2);
73930 }
73931 }
 
73932 }
73933 assert( pCur->eState==CURSOR_VALID
73934 || (pCur->eState==CURSOR_INVALID && loc)
73935 || CORRUPT_DB );
73936
73937 pPage = pCur->pPage;
73938 assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
73939 assert( pPage->leaf || !pPage->intKey );
73940 if( pPage->nFree<0 ){
73941 if( NEVER(pCur->eState>CURSOR_INVALID) ){
73942 rc = SQLITE_CORRUPT_BKPT;
73943 }else{
73944 rc = btreeComputeFreeSpace(pPage);
73945 }
73946 if( rc ) return rc;
@@ -74148,11 +74217,12 @@
74217 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
74218 assert( !hasReadConflicts(p, pCur->pgnoRoot) );
74219 assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
74220 if( pCur->eState==CURSOR_REQUIRESEEK ){
74221 rc = btreeRestoreCursorPosition(pCur);
74222 assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID );
74223 if( rc || pCur->eState!=CURSOR_VALID ) return rc;
74224 }
74225 assert( CORRUPT_DB || pCur->eState==CURSOR_VALID );
74226
74227 iCellDepth = pCur->iPage;
74228 iCellIdx = pCur->ix;
@@ -83652,11 +83722,12 @@
83722 VdbeCursor *pCsr, /* Cursor to grab old.* values from */
83723 int op, /* SQLITE_INSERT, UPDATE or DELETE */
83724 const char *zDb, /* Database name */
83725 Table *pTab, /* Modified table */
83726 i64 iKey1, /* Initial key value */
83727 int iReg, /* Register for new.* record */
83728 int iBlobWrite
83729 ){
83730 sqlite3 *db = v->db;
83731 i64 iKey2;
83732 PreUpdate preupdate;
83733 const char *zTbl = pTab->zName;
@@ -83688,10 +83759,11 @@
83759 preupdate.keyinfo.nKeyField = pTab->nCol;
83760 preupdate.keyinfo.aSortFlags = (u8*)&fakeSortOrder;
83761 preupdate.iKey1 = iKey1;
83762 preupdate.iKey2 = iKey2;
83763 preupdate.pTab = pTab;
83764 preupdate.iBlobWrite = iBlobWrite;
83765
83766 db->pPreUpdate = &preupdate;
83767 db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2);
83768 db->pPreUpdate = 0;
83769 sqlite3DbFree(db, preupdate.aRecord);
@@ -85613,10 +85685,21 @@
85685 SQLITE_API int sqlite3_preupdate_depth(sqlite3 *db){
85686 PreUpdate *p = db->pPreUpdate;
85687 return (p ? p->v->nFrame : 0);
85688 }
85689 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
85690
85691 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
85692 /*
85693 ** This function is designed to be called from within a pre-update callback
85694 ** only.
85695 */
85696 SQLITE_API int sqlite3_preupdate_blobwrite(sqlite3 *db){
85697 PreUpdate *p = db->pPreUpdate;
85698 return (p ? p->iBlobWrite : -1);
85699 }
85700 #endif
85701
85702 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
85703 /*
85704 ** This function is called from within a pre-update callback to retrieve
85705 ** a field of the row currently being updated or inserted.
@@ -86393,11 +86476,14 @@
86476 static u16 SQLITE_NOINLINE computeNumericType(Mem *pMem){
86477 int rc;
86478 sqlite3_int64 ix;
86479 assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 );
86480 assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
86481 if( ExpandBlob(pMem) ){
86482 pMem->u.i = 0;
86483 return MEM_Int;
86484 }
86485 rc = sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc);
86486 if( rc<=0 ){
86487 if( rc==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1 ){
86488 pMem->u.i = ix;
86489 return MEM_Int;
@@ -91126,11 +91212,11 @@
91212
91213 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
91214 /* Invoke the pre-update hook, if any */
91215 if( pTab ){
91216 if( db->xPreUpdateCallback && !(pOp->p5 & OPFLAG_ISUPDATE) ){
91217 sqlite3VdbePreUpdateHook(p,pC,SQLITE_INSERT,zDb,pTab,x.nKey,pOp->p2,-1);
91218 }
91219 if( db->xUpdateCallback==0 || pTab->aCol==0 ){
91220 /* Prevent post-update hook from running in cases when it should not */
91221 pTab = 0;
91222 }
@@ -91286,11 +91372,11 @@
91372 || (aMem[pOp->p3].flags & MEM_Int)
91373 );
91374 sqlite3VdbePreUpdateHook(p, pC,
91375 (opflags & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_DELETE,
91376 zDb, pTab, pC->movetoTarget,
91377 pOp->p3, -1
91378 );
91379 }
91380 if( opflags & OPFLAG_ISNOOP ) break;
91381 #endif
91382
@@ -92355,11 +92441,11 @@
92441 }
92442 #endif
92443
92444 iDb = pOp->p1;
92445 assert( iDb>=0 && iDb<db->nDb );
92446 assert( DbHasProperty(db, iDb, DB_SchemaLoaded) || db->mallocFailed );
92447
92448 #ifndef SQLITE_OMIT_ALTERTABLE
92449 if( pOp->p4.z==0 ){
92450 sqlite3SchemaClear(db->aDb[iDb].pSchema);
92451 db->mDbFlags &= ~DBFLAG_SchemaKnownOk;
@@ -94715,11 +94801,11 @@
94801 ** anyhow.
94802 */
94803 sqlite3_int64 iKey;
94804 iKey = sqlite3BtreeIntegerKey(p->pCsr);
94805 sqlite3VdbePreUpdateHook(
94806 v, v->apCsr[0], SQLITE_DELETE, p->zDb, p->pTab, iKey, -1, p->iCol
94807 );
94808 }
94809 #endif
94810
94811 rc = xCall(p->pCsr, iOffset+p->iOffset, n, z);
@@ -94786,10 +94872,11 @@
94872 ** already been invalidated. Return SQLITE_ABORT in this case.
94873 */
94874 rc = SQLITE_ABORT;
94875 }else{
94876 char *zErr;
94877 ((Vdbe*)p->pStmt)->rc = SQLITE_OK;
94878 rc = blobSeekToRow(p, iRow, &zErr);
94879 if( rc!=SQLITE_OK ){
94880 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
94881 sqlite3DbFree(db, zErr);
94882 }
@@ -98468,19 +98555,14 @@
98555 if( rc ) return WRC_Abort;
98556 rc = sqlite3WalkExprList(pWalker, pWin->pPartition);
98557 if( rc ) return WRC_Abort;
98558 rc = sqlite3WalkExpr(pWalker, pWin->pFilter);
98559 if( rc ) return WRC_Abort;
 
 
 
 
 
98560 rc = sqlite3WalkExpr(pWalker, pWin->pStart);
98561 if( rc ) return WRC_Abort;
98562 rc = sqlite3WalkExpr(pWalker, pWin->pEnd);
98563 if( rc ) return WRC_Abort;
98564 if( bOneOnly ) break;
98565 }
98566 return WRC_Continue;
98567 }
98568 #endif
@@ -98552,10 +98634,20 @@
98634 if( sqlite3WalkExpr(pWalker, pItem->pExpr) ) return WRC_Abort;
98635 }
98636 }
98637 return WRC_Continue;
98638 }
98639
98640 /*
98641 ** This is a no-op callback for Walker->xSelectCallback2. If this
98642 ** callback is set, then the Select->pWinDefn list is traversed.
98643 */
98644 SQLITE_PRIVATE void sqlite3WalkWinDefnDummyCallback(Walker *pWalker, Select *p){
98645 UNUSED_PARAMETER(pWalker);
98646 UNUSED_PARAMETER(p);
98647 /* No-op */
98648 }
98649
98650 /*
98651 ** Walk all expressions associated with SELECT statement p. Do
98652 ** not invoke the SELECT callback on p, but do (of course) invoke
98653 ** any expr callbacks and SELECT callbacks that come from subqueries.
@@ -98566,14 +98658,16 @@
98658 if( sqlite3WalkExpr(pWalker, p->pWhere) ) return WRC_Abort;
98659 if( sqlite3WalkExprList(pWalker, p->pGroupBy) ) return WRC_Abort;
98660 if( sqlite3WalkExpr(pWalker, p->pHaving) ) return WRC_Abort;
98661 if( sqlite3WalkExprList(pWalker, p->pOrderBy) ) return WRC_Abort;
98662 if( sqlite3WalkExpr(pWalker, p->pLimit) ) return WRC_Abort;
98663 #if !defined(SQLITE_OMIT_WINDOWFUNC)
98664 if( p->pWinDefn ){
98665 Parse *pParse;
98666 if( pWalker->xSelectCallback2==sqlite3WalkWinDefnDummyCallback
98667 || ((pParse = pWalker->pParse)!=0 && IN_RENAME_OBJECT)
98668 ){
98669 /* The following may return WRC_Abort if there are unresolvable
98670 ** symbols (e.g. a table that does not exist) in a window definition. */
98671 int rc = walkWindowList(pWalker, p->pWinDefn, 0);
98672 return rc;
98673 }
@@ -98593,11 +98687,11 @@
98687 SrcList *pSrc;
98688 int i;
98689 SrcItem *pItem;
98690
98691 pSrc = p->pSrc;
98692 if( ALWAYS(pSrc) ){
98693 for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
98694 if( pItem->pSelect && sqlite3WalkSelect(pWalker, pItem->pSelect) ){
98695 return WRC_Abort;
98696 }
98697 if( pItem->fg.isTabFunc
@@ -98767,11 +98861,14 @@
98861 assert( iCol>=0 && iCol<pEList->nExpr );
98862 pOrig = pEList->a[iCol].pExpr;
98863 assert( pOrig!=0 );
98864 db = pParse->db;
98865 pDup = sqlite3ExprDup(db, pOrig, 0);
98866 if( db->mallocFailed ){
98867 sqlite3ExprDelete(db, pDup);
98868 pDup = 0;
98869 }else{
98870 incrAggFunctionDepth(pDup, nSubquery);
98871 if( pExpr->op==TK_COLLATE ){
98872 pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
98873 }
98874
@@ -98789,14 +98886,12 @@
98886 assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 );
98887 pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
98888 pExpr->flags |= EP_MemToken;
98889 }
98890 if( ExprHasProperty(pExpr, EP_WinFunc) ){
98891 if( ALWAYS(pExpr->y.pWin!=0) ){
98892 pExpr->y.pWin->pOwner = pExpr;
 
 
98893 }
98894 }
98895 sqlite3DbFree(db, pDup);
98896 }
98897 }
@@ -99184,12 +99279,12 @@
99279 ** or HAVING clauses, or as part of a larger expression in the ORDER BY
99280 ** clause is not standard SQL. This is a (goofy) SQLite extension, that
99281 ** is supported for backwards compatibility only. Hence, we issue a warning
99282 ** on sqlite3_log() whenever the capability is used.
99283 */
99284 if( cnt==0
99285 && (pNC->ncFlags & NC_UEList)!=0
99286 && zTab==0
99287 ){
99288 pEList = pNC->uNC.pEList;
99289 assert( pEList!=0 );
99290 for(j=0; j<pEList->nExpr; j++){
@@ -99293,11 +99388,11 @@
99388 sqlite3ErrorMsg(pParse, "%s: %s.%s", zErr, zTab, zCol);
99389 }else{
99390 sqlite3ErrorMsg(pParse, "%s: %s", zErr, zCol);
99391 }
99392 pParse->checkSchema = 1;
99393 pTopNC->nNcErr++;
99394 }
99395
99396 /* If a column from a table in pSrcList is referenced, then record
99397 ** this fact in the pSrcList.a[].colUsed bitmask. Column 0 causes
99398 ** bit 0 to be set. Column 1 sets bit 1. And so forth. Bit 63 is
@@ -99600,11 +99695,11 @@
99695 pExpr->iTable = exprProbability(pList->a[1].pExpr);
99696 if( pExpr->iTable<0 ){
99697 sqlite3ErrorMsg(pParse,
99698 "second argument to likelihood() must be a "
99699 "constant between 0.0 and 1.0");
99700 pNC->nNcErr++;
99701 }
99702 }else{
99703 /* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is
99704 ** equivalent to likelihood(X, 0.0625).
99705 ** EVIDENCE-OF: R-01283-11636 The unlikely(X) function is
@@ -99622,11 +99717,11 @@
99717 int auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0,pDef->zName,0);
99718 if( auth!=SQLITE_OK ){
99719 if( auth==SQLITE_DENY ){
99720 sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
99721 pDef->zName);
99722 pNC->nNcErr++;
99723 }
99724 pExpr->op = TK_NULL;
99725 return WRC_Prune;
99726 }
99727 }
@@ -99678,11 +99773,11 @@
99773 );
99774 if( pDef && pDef->xValue==0 && pWin ){
99775 sqlite3ErrorMsg(pParse,
99776 "%.*s() may not be used as a window function", nId, zId
99777 );
99778 pNC->nNcErr++;
99779 }else if(
99780 (is_agg && (pNC->ncFlags & NC_AllowAgg)==0)
99781 || (is_agg && (pDef->funcFlags&SQLITE_FUNC_WINDOW) && !pWin)
99782 || (is_agg && pWin && (pNC->ncFlags & NC_AllowWin)==0)
99783 ){
@@ -99691,39 +99786,39 @@
99786 zType = "window";
99787 }else{
99788 zType = "aggregate";
99789 }
99790 sqlite3ErrorMsg(pParse, "misuse of %s function %.*s()",zType,nId,zId);
99791 pNC->nNcErr++;
99792 is_agg = 0;
99793 }
99794 #else
99795 if( (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) ){
99796 sqlite3ErrorMsg(pParse,"misuse of aggregate function %.*s()",nId,zId);
99797 pNC->nNcErr++;
99798 is_agg = 0;
99799 }
99800 #endif
99801 else if( no_such_func && pParse->db->init.busy==0
99802 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
99803 && pParse->explain==0
99804 #endif
99805 ){
99806 sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId);
99807 pNC->nNcErr++;
99808 }else if( wrong_num_args ){
99809 sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()",
99810 nId, zId);
99811 pNC->nNcErr++;
99812 }
99813 #ifndef SQLITE_OMIT_WINDOWFUNC
99814 else if( is_agg==0 && ExprHasProperty(pExpr, EP_WinFunc) ){
99815 sqlite3ErrorMsg(pParse,
99816 "FILTER may not be used with non-aggregate %.*s()",
99817 nId, zId
99818 );
99819 pNC->nNcErr++;
99820 }
99821 #endif
99822 if( is_agg ){
99823 /* Window functions may not be arguments of aggregate functions.
99824 ** Or arguments of other window functions. But aggregate functions
@@ -99943,12 +100038,12 @@
100038 */
100039 memset(&nc, 0, sizeof(nc));
100040 nc.pParse = pParse;
100041 nc.pSrcList = pSelect->pSrc;
100042 nc.uNC.pEList = pEList;
100043 nc.ncFlags = NC_AllowAgg|NC_UEList|NC_NoSelect;
100044 nc.nNcErr = 0;
100045 db = pParse->db;
100046 savedSuppErr = db->suppressErr;
100047 if( IN_RENAME_OBJECT==0 ) db->suppressErr = 1;
100048 rc = sqlite3ResolveExprNames(&nc, pE);
100049 db->suppressErr = savedSuppErr;
@@ -100203,11 +100298,11 @@
100298 int iCol; /* Column number */
100299 struct ExprList_item *pItem; /* A term of the ORDER BY clause */
100300 Parse *pParse; /* Parsing context */
100301 int nResult; /* Number of terms in the result set */
100302
100303 assert( pOrderBy!=0 );
100304 nResult = pSelect->pEList->nExpr;
100305 pParse = pNC->pParse;
100306 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
100307 Expr *pE = pItem->pExpr;
100308 Expr *pE2 = sqlite3ExprSkipCollateAndLikely(pE);
@@ -100293,11 +100388,13 @@
100388 nCompound = 0;
100389 pLeftmost = p;
100390 while( p ){
100391 assert( (p->selFlags & SF_Expanded)!=0 );
100392 assert( (p->selFlags & SF_Resolved)==0 );
100393 assert( db->suppressErr==0 ); /* SF_Resolved not set if errors suppressed */
100394 p->selFlags |= SF_Resolved;
100395
100396
100397 /* Resolve the expressions in the LIMIT and OFFSET clauses. These
100398 ** are not allowed to refer to any names, so pass an empty NameContext.
100399 */
100400 memset(&sNC, 0, sizeof(sNC));
@@ -100368,17 +100465,10 @@
100465 p->selFlags |= SF_Aggregate | (sNC.ncFlags&NC_MinMaxAgg);
100466 }else{
100467 sNC.ncFlags &= ~NC_AllowAgg;
100468 }
100469
 
 
 
 
 
 
 
100470 /* Add the output column list to the name-context before parsing the
100471 ** other expressions in the SELECT statement. This is so that
100472 ** expressions in the WHERE clause (etc.) can refer to expressions by
100473 ** aliases in the result set.
100474 **
@@ -100386,11 +100476,17 @@
100476 ** re-evaluated for each reference to it.
100477 */
100478 assert( (sNC.ncFlags & (NC_UAggInfo|NC_UUpsert|NC_UBaseReg))==0 );
100479 sNC.uNC.pEList = p->pEList;
100480 sNC.ncFlags |= NC_UEList;
100481 if( p->pHaving ){
100482 if( !pGroupBy ){
100483 sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING");
100484 return WRC_Abort;
100485 }
100486 if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;
100487 }
100488 if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort;
100489
100490 /* Resolve names in table-valued-function arguments */
100491 for(i=0; i<p->pSrc->nSrc; i++){
100492 SrcItem *pItem = &p->pSrc->a[i];
@@ -100426,11 +100522,12 @@
100522 ** If there is an ORDER BY clause on a term of a compound-select other
100523 ** than the right-most term, then that is a syntax error. But the error
100524 ** is not detected until much later, and so we need to go ahead and
100525 ** resolve those symbols on the incorrect ORDER BY for consistency.
100526 */
100527 if( p->pOrderBy!=0
100528 && isCompound<=nCompound /* Defer right-most ORDER BY of a compound */
100529 && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER")
100530 ){
100531 return WRC_Abort;
100532 }
100533 if( db->mallocFailed ){
@@ -100550,11 +100647,11 @@
100647 if( pExpr==0 ) return SQLITE_OK;
100648 savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
100649 pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
100650 w.pParse = pNC->pParse;
100651 w.xExprCallback = resolveExprStep;
100652 w.xSelectCallback = (pNC->ncFlags & NC_NoSelect) ? 0 : resolveSelectStep;
100653 w.xSelectCallback2 = 0;
100654 w.u.pNC = pNC;
100655 #if SQLITE_MAX_EXPR_DEPTH>0
100656 w.pParse->nHeight += pExpr->nHeight;
100657 if( sqlite3ExprCheckHeight(w.pParse, w.pParse->nHeight) ){
@@ -100569,11 +100666,11 @@
100666 assert( EP_Win==NC_HasWin );
100667 testcase( pNC->ncFlags & NC_HasAgg );
100668 testcase( pNC->ncFlags & NC_HasWin );
100669 ExprSetProperty(pExpr, pNC->ncFlags & (NC_HasAgg|NC_HasWin) );
100670 pNC->ncFlags |= savedHasAgg;
100671 return pNC->nNcErr>0 || w.pParse->nErr>0;
100672 }
100673
100674 /*
100675 ** Resolve all names for all expression in an expression list. This is
100676 ** just like sqlite3ResolveExprNames() except that it works for an expression
@@ -100614,11 +100711,11 @@
100711 if( pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin) ){
100712 ExprSetProperty(pExpr, pNC->ncFlags & (NC_HasAgg|NC_HasWin) );
100713 savedHasAgg |= pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
100714 pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
100715 }
100716 if( w.pParse->nErr>0 ) return WRC_Abort;
100717 }
100718 pNC->ncFlags |= savedHasAgg;
100719 return WRC_Continue;
100720 }
100721
@@ -100757,27 +100854,27 @@
100854 || (pExpr->op==TK_REGISTER && pExpr->op2==TK_IF_NULL_ROW) );
100855 pExpr = pExpr->pLeft;
100856 assert( pExpr!=0 );
100857 }
100858 op = pExpr->op;
100859 if( op==TK_REGISTER ) op = pExpr->op2;
100860 if( (op==TK_COLUMN || op==TK_AGG_COLUMN) && pExpr->y.pTab ){
100861 return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
100862 }
100863 if( op==TK_SELECT ){
100864 assert( pExpr->flags&EP_xIsSelect );
100865 assert( pExpr->x.pSelect!=0 );
100866 assert( pExpr->x.pSelect->pEList!=0 );
100867 assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 );
100868 return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
100869 }
 
100870 #ifndef SQLITE_OMIT_CAST
100871 if( op==TK_CAST ){
100872 assert( !ExprHasProperty(pExpr, EP_IntValue) );
100873 return sqlite3AffinityType(pExpr->u.zToken, 0);
100874 }
100875 #endif
 
 
 
100876 if( op==TK_SELECT_COLUMN ){
100877 assert( pExpr->pLeft->flags&EP_xIsSelect );
100878 return sqlite3ExprAffinity(
100879 pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
100880 );
@@ -102029,10 +102126,11 @@
102126
102127 /* Figure out where to write the new Expr structure. */
102128 if( pzBuffer ){
102129 zAlloc = *pzBuffer;
102130 staticFlag = EP_Static;
102131 assert( zAlloc!=0 );
102132 }else{
102133 zAlloc = sqlite3DbMallocRawNN(db, dupedExprSize(p, dupFlags));
102134 staticFlag = 0;
102135 }
102136 pNew = (Expr *)zAlloc;
@@ -102107,11 +102205,12 @@
102205 }else{
102206 if( !ExprHasProperty(p, EP_TokenOnly|EP_Leaf) ){
102207 if( pNew->op==TK_SELECT_COLUMN ){
102208 pNew->pLeft = p->pLeft;
102209 assert( p->iColumn==0 || p->pRight==0 );
102210 assert( p->pRight==0 || p->pRight==p->pLeft
102211 || ExprHasProperty(p->pLeft, EP_Subquery) );
102212 }else{
102213 pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
102214 }
102215 pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
102216 }
@@ -102352,10 +102451,18 @@
102451 pNew->pWin = 0;
102452 pNew->pWinDefn = sqlite3WindowListDup(db, p->pWinDefn);
102453 if( p->pWin && db->mallocFailed==0 ) gatherSelectWindows(pNew);
102454 #endif
102455 pNew->selId = p->selId;
102456 if( db->mallocFailed ){
102457 /* Any prior OOM might have left the Select object incomplete.
102458 ** Delete the whole thing rather than allow an incomplete Select
102459 ** to be used by the code generator. */
102460 pNew->pNext = 0;
102461 sqlite3SelectDelete(db, pNew);
102462 break;
102463 }
102464 *pp = pNew;
102465 pp = &pNew->pPrior;
102466 pNext = pNew;
102467 }
102468
@@ -103052,12 +103159,14 @@
103159 ** will likely result in an incorrect answer. So when in doubt, return
103160 ** TRUE.
103161 */
103162 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr *p){
103163 u8 op;
103164 assert( p!=0 );
103165 while( p->op==TK_UPLUS || p->op==TK_UMINUS ){
103166 p = p->pLeft;
103167 assert( p!=0 );
103168 }
103169 op = p->op;
103170 if( op==TK_REGISTER ) op = p->op2;
103171 switch( op ){
103172 case TK_INTEGER:
@@ -103903,11 +104012,11 @@
104012 ** columns as the vector on the LHS. Or, if the RHS of the IN() is not
104013 ** a sub-query, that the LHS is a vector of size 1.
104014 */
104015 SQLITE_PRIVATE int sqlite3ExprCheckIN(Parse *pParse, Expr *pIn){
104016 int nVector = sqlite3ExprVectorSize(pIn->pLeft);
104017 if( (pIn->flags & EP_xIsSelect)!=0 && !pParse->db->mallocFailed ){
104018 if( nVector!=pIn->x.pSelect->pEList->nExpr ){
104019 sqlite3SubselectError(pParse, pIn->x.pSelect->pEList->nExpr, nVector);
104020 return 1;
104021 }
104022 }else if( nVector!=1 ){
@@ -104720,11 +104829,11 @@
104829 default: {
104830 /* Make NULL the default case so that if a bug causes an illegal
104831 ** Expr node to be passed into this function, it will be handled
104832 ** sanely and not crash. But keep the assert() to bring the problem
104833 ** to the attention of the developers. */
104834 assert( op==TK_NULL || pParse->db->mallocFailed );
104835 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
104836 return target;
104837 }
104838 #ifndef SQLITE_OMIT_BLOB_LITERAL
104839 case TK_BLOB: {
@@ -106895,10 +107004,11 @@
107004 ** Or, if zName is not a system table, zero is returned.
107005 */
107006 static int isAlterableTable(Parse *pParse, Table *pTab){
107007 if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7)
107008 #ifndef SQLITE_OMIT_VIRTUALTABLE
107009 || (pTab->tabFlags & TF_Eponymous)!=0
107010 || ( (pTab->tabFlags & TF_Shadow)!=0
107011 && sqlite3ReadOnlyShadowTables(pParse->db)
107012 )
107013 #endif
107014 ){
@@ -107782,11 +107892,13 @@
107892 Parse *pParse,
107893 struct RenameCtx *pCtx,
107894 void *pPtr
107895 ){
107896 RenameToken **pp;
107897 if( NEVER(pPtr==0) ){
107898 return 0;
107899 }
107900 for(pp=&pParse->pRename; (*pp); pp=&(*pp)->pNext){
107901 if( (*pp)->p==pPtr ){
107902 RenameToken *pToken = *pp;
107903 if( pCtx ){
107904 *pp = pToken->pNext;
@@ -108439,11 +108551,11 @@
108551 static int renameTableSelectCb(Walker *pWalker, Select *pSelect){
108552 int i;
108553 RenameCtx *p = pWalker->u.pRename;
108554 SrcList *pSrc = pSelect->pSrc;
108555 if( pSelect->selFlags & SF_View ) return WRC_Prune;
108556 if( NEVER(pSrc==0) ){
108557 assert( pWalker->pParse->db->mallocFailed );
108558 return WRC_Abort;
108559 }
108560 for(i=0; i<pSrc->nSrc; i++){
108561 SrcItem *pItem = &pSrc->a[i];
@@ -108983,20 +109095,25 @@
109095 if( iPos<pPk->nKeyCol ) continue;
109096 regOut = reg+1+iPos-(iPos>iColPos);
109097 }else{
109098 regOut = reg+1+nField;
109099 }
109100 if( i==pTab->iPKey ){
109101 sqlite3VdbeAddOp2(v, OP_Null, 0, regOut);
109102 }else{
109103 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut);
109104 }
109105 nField++;
109106 }
109107 }
109108 sqlite3VdbeAddOp3(v, OP_MakeRecord, reg+1, nField, regRec);
109109 if( pPk ){
109110 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iCur, regRec, reg+1, pPk->nKeyCol);
109111 }else{
109112 sqlite3VdbeAddOp3(v, OP_Insert, iCur, regRec, reg);
109113 }
109114 sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION);
109115
109116 sqlite3VdbeAddOp2(v, OP_Next, iCur, addr+1); VdbeCoverage(v);
109117 sqlite3VdbeJumpHere(v, addr);
109118 }
109119
@@ -111479,11 +111596,11 @@
111596 pFix->pName = pName;
111597 pFix->bTemp = (iDb==1);
111598 pFix->w.pParse = pParse;
111599 pFix->w.xExprCallback = fixExprCb;
111600 pFix->w.xSelectCallback = fixSelectCb;
111601 pFix->w.xSelectCallback2 = sqlite3WalkWinDefnDummyCallback;
111602 pFix->w.walkerDepth = 0;
111603 pFix->w.eCode = 0;
111604 pFix->w.u.pFix = pFix;
111605 }
111606
@@ -111541,18 +111658,20 @@
111658 || sqlite3FixSrcList(pFix, pStep->pFrom)
111659 ){
111660 return 1;
111661 }
111662 #ifndef SQLITE_OMIT_UPSERT
111663 {
111664 Upsert *pUp;
111665 for(pUp=pStep->pUpsert; pUp; pUp=pUp->pNextUpsert){
111666 if( sqlite3WalkExprList(&pFix->w, pUp->pUpsertTarget)
111667 || sqlite3WalkExpr(&pFix->w, pUp->pUpsertTargetWhere)
111668 || sqlite3WalkExprList(&pFix->w, pUp->pUpsertSet)
111669 || sqlite3WalkExpr(&pFix->w, pUp->pUpsertWhere)
111670 ){
111671 return 1;
111672 }
111673 }
111674 }
111675 #endif
111676 pStep = pStep->pNext;
111677 }
@@ -112272,11 +112391,11 @@
112391 if( p==0 ){
112392 #ifndef SQLITE_OMIT_VIRTUALTABLE
112393 /* If zName is the not the name of a table in the schema created using
112394 ** CREATE, then check to see if it is the name of an virtual table that
112395 ** can be an eponymous virtual table. */
112396 if( pParse->disableVtab==0 && db->init.busy==0 ){
112397 Module *pMod = (Module*)sqlite3HashFind(&db->aModule, zName);
112398 if( pMod==0 && sqlite3_strnicmp(zName, "pragma_", 7)==0 ){
112399 pMod = sqlite3PragmaVtabRegister(db, zName);
112400 }
112401 if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){
@@ -112295,10 +112414,12 @@
112414 if( zDbase ){
112415 sqlite3ErrorMsg(pParse, "%s: %s.%s", zMsg, zDbase, zName);
112416 }else{
112417 sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName);
112418 }
112419 }else{
112420 assert( HasRowid(p) || p->iPKey<0 );
112421 }
112422
112423 return p;
112424 }
112425
@@ -113155,10 +113276,11 @@
113276 pRet->retTrig.zName = RETURNING_TRIGGER_NAME;
113277 pRet->retTrig.op = TK_RETURNING;
113278 pRet->retTrig.tr_tm = TRIGGER_AFTER;
113279 pRet->retTrig.bReturning = 1;
113280 pRet->retTrig.pSchema = db->aDb[1].pSchema;
113281 pRet->retTrig.pTabSchema = db->aDb[1].pSchema;
113282 pRet->retTrig.step_list = &pRet->retTStep;
113283 pRet->retTStep.op = TK_RETURNING;
113284 pRet->retTStep.pTrig = &pRet->retTrig;
113285 pRet->retTStep.pExprList = pList;
113286 pHash = &(db->aDb[1].pSchema->trigHash);
@@ -114013,20 +114135,26 @@
114135 ExprList *pList;
114136 Token ipkToken;
114137 sqlite3TokenInit(&ipkToken, pTab->aCol[pTab->iPKey].zName);
114138 pList = sqlite3ExprListAppend(pParse, 0,
114139 sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
114140 if( pList==0 ){
114141 pTab->tabFlags &= ~TF_WithoutRowid;
114142 return;
114143 }
114144 if( IN_RENAME_OBJECT ){
114145 sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
114146 }
114147 pList->a[0].sortFlags = pParse->iPkSortOrder;
114148 assert( pParse->pNewTable==pTab );
114149 pTab->iPKey = -1;
114150 sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
114151 SQLITE_IDXTYPE_PRIMARYKEY);
114152 if( db->mallocFailed || pParse->nErr ){
114153 pTab->tabFlags &= ~TF_WithoutRowid;
114154 return;
114155 }
114156 pPk = sqlite3PrimaryKeyIndex(pTab);
114157 assert( pPk->nKeyCol==1 );
114158 }else{
114159 pPk = sqlite3PrimaryKeyIndex(pTab);
114160 assert( pPk!=0 );
@@ -114226,11 +114354,10 @@
114354 Index *pIdx; /* An implied index of the table */
114355
114356 if( pEnd==0 && pSelect==0 ){
114357 return;
114358 }
 
114359 p = pParse->pNewTable;
114360 if( p==0 ) return;
114361
114362 if( pSelect==0 && sqlite3ShadowTableName(db, p->zName) ){
114363 p->tabFlags |= TF_Shadow;
@@ -114474,10 +114601,11 @@
114601 */
114602 if( db->init.busy ){
114603 Table *pOld;
114604 Schema *pSchema = p->pSchema;
114605 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
114606 assert( HasRowid(p) || p->iPKey<0 );
114607 pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName, p);
114608 if( pOld ){
114609 assert( p==pOld ); /* Malloc must have failed inside HashInsert() */
114610 sqlite3OomFault(db);
114611 return;
@@ -116421,12 +116549,12 @@
116549 ** Assign VdbeCursor index numbers to all tables in a SrcList
116550 */
116551 SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse *pParse, SrcList *pList){
116552 int i;
116553 SrcItem *pItem;
116554 assert( pList || pParse->db->mallocFailed );
116555 if( ALWAYS(pList) ){
116556 for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
116557 if( pItem->iCursor>=0 ) continue;
116558 pItem->iCursor = pParse->nTab++;
116559 if( pItem->pSelect ){
116560 sqlite3SrcListAssignCursors(pParse, pItem->pSelect->pSrc);
@@ -120759,13 +120887,11 @@
120887 ans = x(v0, v1);
120888 sqlite3_result_double(context, ans);
120889 }
120890
120891 /*
120892 ** Implementation of 0-argument pi() function.
 
 
120893 */
120894 static void piFunc(
120895 sqlite3_context *context,
120896 int argc,
120897 sqlite3_value **argv
@@ -122791,11 +122917,11 @@
122917 /* Verify that the sqlite_sequence table exists and is an ordinary
122918 ** rowid table with exactly two columns.
122919 ** Ticket d8dc2b3a58cd5dc2918a1d4acb 2018-05-23 */
122920 if( pSeqTab==0
122921 || !HasRowid(pSeqTab)
122922 || NEVER(IsVirtual(pSeqTab))
122923 || pSeqTab->nCol!=2
122924 ){
122925 pParse->nErr++;
122926 pParse->rc = SQLITE_CORRUPT_SEQUENCE;
122927 return 0;
@@ -130510,18 +130636,18 @@
130636
130637 assert( argc==5 );
130638 UNUSED_PARAMETER2(NotUsed, argc);
130639 assert( sqlite3_mutex_held(db->mutex) );
130640 db->mDbFlags |= DBFLAG_EncodingFixed;
130641 if( argv==0 ) return 0; /* Might happen if EMPTY_RESULT_CALLBACKS are on */
130642 pData->nInitRow++;
130643 if( db->mallocFailed ){
130644 corruptSchema(pData, argv, 0);
130645 return 1;
130646 }
130647
130648 assert( iDb>=0 && iDb<db->nDb );
 
130649 if( argv[3]==0 ){
130650 corruptSchema(pData, argv, 0);
130651 }else if( argv[4]
130652 && 'c'==sqlite3UpperToLower[(unsigned char)argv[4][0]]
130653 && 'r'==sqlite3UpperToLower[(unsigned char)argv[4][1]] ){
@@ -130794,19 +130920,21 @@
130920 #endif
130921 }
130922 if( db->mallocFailed ){
130923 rc = SQLITE_NOMEM_BKPT;
130924 sqlite3ResetAllSchemasOfConnection(db);
130925 }else
130926 if( rc==SQLITE_OK || (db->flags&SQLITE_NoSchemaError)){
130927 /* Hack: If the SQLITE_NoSchemaError flag is set, then consider
130928 ** the schema loaded, even if errors (other than OOM) occurred. In
130929 ** this situation the current sqlite3_prepare() operation will fail,
130930 ** but the following one will attempt to compile the supplied statement
130931 ** against whatever subset of the schema was loaded before the error
130932 ** occurred.
130933 **
130934 ** The primary purpose of this is to allow access to the sqlite_schema
130935 ** table even when its contents have been corrupted.
130936 */
130937 DbSetProperty(db, iDb, DB_SchemaLoaded);
130938 rc = SQLITE_OK;
130939 }
130940
@@ -134976,10 +135104,13 @@
135104 if( p->pPrior ){
135105 sqlite3SelectDelete(db, p->pPrior);
135106 }
135107 p->pPrior = pPrior;
135108 pPrior->pNext = p;
135109
135110 sqlite3ExprListDelete(db, pPrior->pOrderBy);
135111 pPrior->pOrderBy = 0;
135112
135113 /*** TBD: Insert subroutine calls to close cursors on incomplete
135114 **** subqueries ****/
135115 ExplainQueryPlanPop(pParse);
135116 return pParse->nErr!=0;
@@ -135056,30 +135187,32 @@
135187 ifNullRow.flags = EP_IfNullRow;
135188 pCopy = &ifNullRow;
135189 }
135190 testcase( ExprHasProperty(pCopy, EP_Subquery) );
135191 pNew = sqlite3ExprDup(db, pCopy, 0);
135192 if( db->mallocFailed ){
135193 sqlite3ExprDelete(db, pNew);
135194 return pExpr;
135195 }
135196 if( pSubst->isLeftJoin ){
135197 ExprSetProperty(pNew, EP_CanBeNull);
135198 }
135199 if( ExprHasProperty(pExpr,EP_FromJoin) ){
135200 sqlite3SetJoinExpr(pNew, pExpr->iRightJoinTable);
135201 }
135202 sqlite3ExprDelete(db, pExpr);
135203 pExpr = pNew;
135204
135205 /* Ensure that the expression now has an implicit collation sequence,
135206 ** just as it did when it was a column of a view or sub-query. */
135207 if( pExpr->op!=TK_COLUMN && pExpr->op!=TK_COLLATE ){
135208 CollSeq *pColl = sqlite3ExprCollSeq(pSubst->pParse, pExpr);
135209 pExpr = sqlite3ExprAddCollateString(pSubst->pParse, pExpr,
135210 (pColl ? pColl->zName : "BINARY")
135211 );
135212 }
135213 ExprClearProperty(pExpr, EP_Collate);
 
 
135214 }
135215 }
135216 }else{
135217 if( pExpr->op==TK_IF_NULL_ROW && pExpr->iTable==pSubst->iTable ){
135218 pExpr->iTable = pSubst->iNewTable;
@@ -135194,11 +135327,14 @@
135327 int i;
135328 SrcItem *pItem;
135329 for(i=0, pItem=pSrc->a; i<pSrc->nSrc; i++, pItem++){
135330 if( i!=iExcept ){
135331 Select *p;
135332 if( !pItem->fg.isRecursive || aCsrMap[pItem->iCursor]==0 ){
135333 aCsrMap[pItem->iCursor] = pParse->nTab++;
135334 }
135335 pItem->iCursor = aCsrMap[pItem->iCursor];
135336 for(p=pItem->pSelect; p; p=p->pPrior){
135337 srclistRenumberCursors(pParse, aCsrMap, p->pSrc, -1);
135338 }
135339 }
135340 }
@@ -135634,11 +135770,11 @@
135770 pSubitem->pTab = pItemTab;
135771 if( pNew==0 ){
135772 p->pPrior = pPrior;
135773 }else{
135774 pNew->selId = ++pParse->nSelect;
135775 if( aCsrMap && ALWAYS(db->mallocFailed==0) ){
135776 renumberCursors(pParse, pNew, iFrom, aCsrMap);
135777 }
135778 pNew->pPrior = pPrior;
135779 if( pPrior ) pPrior->pNext = pNew;
135780 pNew->pNext = p;
@@ -137626,12 +137762,11 @@
137762 if( pDest->eDest==SRT_Output ){
137763 generateColumnNames(pParse, p);
137764 }
137765
137766 #ifndef SQLITE_OMIT_WINDOWFUNC
137767 if( sqlite3WindowRewrite(pParse, p) ){
 
137768 assert( db->mallocFailed || pParse->nErr>0 );
137769 goto select_end;
137770 }
137771 #if SELECTTRACE_ENABLED
137772 if( p->pWin && (sqlite3SelectTrace & 0x108)!=0 ){
@@ -138344,12 +138479,14 @@
138479 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
138480 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
138481 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct,
138482 WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0
138483 );
138484 if( pWInfo==0 ){
138485 sqlite3ExprListDelete(db, pDistinct);
138486 goto select_end;
138487 }
138488 eDist = sqlite3WhereIsDistinct(pWInfo);
138489 SELECTTRACE(1,pParse,p,("WhereBegin returns\n"));
138490 if( sqlite3WhereIsOrdered(pWInfo)==pGroupBy->nExpr ){
138491 /* The optimizer is able to deliver rows in group by order so
138492 ** we do not have to sort. The OP_OpenEphemeral table will be
@@ -138478,10 +138615,11 @@
138615 }else{
138616 SELECTTRACE(1,pParse,p,("WhereEnd\n"));
138617 sqlite3WhereEnd(pWInfo);
138618 sqlite3VdbeChangeToNoop(v, addrSortingIdx);
138619 }
138620 sqlite3ExprListDelete(db, pDistinct);
138621
138622 /* Output the final row of result
138623 */
138624 sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
138625 VdbeComment((v, "output final row"));
@@ -138692,10 +138830,12 @@
138830
138831 /* Control jumps to here if an error is encountered above, or upon
138832 ** successful coding of the SELECT.
138833 */
138834 select_end:
138835 assert( db->mallocFailed==0 || db->mallocFailed==1 );
138836 pParse->nErr += db->mallocFailed;
138837 sqlite3ExprListDelete(db, pMinMaxOrderBy);
138838 #ifdef SQLITE_DEBUG
138839 if( pAggInfo && !db->mallocFailed ){
138840 for(i=0; i<pAggInfo->nColumn; i++){
138841 Expr *pExpr = pAggInfo->aCol[i].pCExpr;
@@ -138982,37 +139122,45 @@
139122 if( pParse->disableTriggers ){
139123 return 0;
139124 }
139125 pTmpSchema = pParse->db->aDb[1].pSchema;
139126 p = sqliteHashFirst(&pTmpSchema->trigHash);
 
 
 
139127 pList = pTab->pTrigger;
139128 while( p ){
139129 Trigger *pTrig = (Trigger *)sqliteHashData(p);
139130 if( pTrig->pTabSchema==pTab->pSchema
139131 && pTrig->table
139132 && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
139133 && pTrig->pTabSchema!=pTmpSchema
139134 ){
139135 pTrig->pNext = pList;
139136 pList = pTrig;
139137 }else if( pTrig->op==TK_RETURNING
139138 #ifndef SQLITE_OMIT_VIRTUALTABLE
139139 && pParse->db->pVtabCtx==0
139140 #endif
139141 ){
139142 assert( pParse->bReturning );
139143 assert( &(pParse->u1.pReturning->retTrig) == pTrig );
139144 pTrig->table = pTab->zName;
139145 pTrig->pTabSchema = pTab->pSchema;
139146 pTrig->pNext = pList;
139147 pList = pTrig;
139148 }
139149 p = sqliteHashNext(p);
139150 }
139151 #if 0
139152 if( pList ){
139153 Trigger *pX;
139154 printf("Triggers for %s:", pTab->zName);
139155 for(pX=pList; pX; pX=pX->pNext){
139156 printf(" %s", pX->zName);
139157 }
139158 printf("\n");
139159 fflush(stdout);
139160 }
139161 #endif
139162 return pList;
139163 }
139164
139165 /*
139166 ** This is called by the parser when it sees a CREATE TRIGGER statement
@@ -140581,11 +140729,12 @@
140729 if( pLimit ){
140730 pGrp = sqlite3ExprListAppend(pParse, 0, sqlite3PExpr(pParse,TK_ROW,0,0));
140731 }
140732 #endif
140733 }
140734 assert( pChanges!=0 || pParse->db->mallocFailed );
140735 if( pChanges ){
140736 for(i=0; i<pChanges->nExpr; i++){
140737 pList = sqlite3ExprListAppend(pParse, pList,
140738 sqlite3ExprDup(db, pChanges->a[i].pExpr, 0)
140739 );
140740 }
@@ -143607,10 +143756,11 @@
143756 pMod->pEpoTab = pTab;
143757 pTab->nTabRef = 1;
143758 pTab->pSchema = db->aDb[0].pSchema;
143759 assert( pTab->nModuleArg==0 );
143760 pTab->iPKey = -1;
143761 pTab->tabFlags |= TF_Eponymous;
143762 addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
143763 addModuleArgument(pParse, pTab, 0);
143764 addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
143765 rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
143766 if( rc ){
@@ -145019,10 +145169,11 @@
145169 zAff = sqlite3DbStrDup(pParse->db,sqlite3IndexAffinityStr(pParse->db,pIdx));
145170 assert( zAff!=0 || pParse->db->mallocFailed );
145171
145172 if( nSkip ){
145173 int iIdxCur = pLevel->iIdxCur;
145174 sqlite3VdbeAddOp3(v, OP_Null, 0, regBase, regBase+nSkip-1);
145175 sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur);
145176 VdbeCoverageIf(v, bRev==0);
145177 VdbeCoverageIf(v, bRev!=0);
145178 VdbeComment((v, "begin skip-scan on %s", pIdx->zName));
145179 j = sqlite3VdbeAddOp0(v, OP_Goto);
@@ -145070,11 +145221,11 @@
145221 Expr *pRight = pTerm->pExpr->pRight;
145222 if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){
145223 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
145224 VdbeCoverage(v);
145225 }
145226 if( pParse->db->mallocFailed==0 ){
145227 if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_BLOB ){
145228 zAff[j] = SQLITE_AFF_BLOB;
145229 }
145230 if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){
145231 zAff[j] = SQLITE_AFF_BLOB;
@@ -147320,10 +147471,11 @@
147471 sqlite3 *db; /* Database connection (for malloc) */
147472 Expr *pNew; /* New virtual expression */
147473 int op; /* Operator for the combined expression */
147474 int idxNew; /* Index in pWC of the next virtual term */
147475
147476 if( (pOne->wtFlags | pTwo->wtFlags) & TERM_VNULL ) return;
147477 if( (pOne->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return;
147478 if( (pTwo->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return;
147479 if( (eOp & (WO_EQ|WO_LT|WO_LE))!=eOp
147480 && (eOp & (WO_EQ|WO_GT|WO_GE))!=eOp ) return;
147481 assert( pOne->pExpr->pLeft!=0 && pOne->pExpr->pRight!=0 );
@@ -148973,11 +149125,13 @@
149125 ** If the right-hand branch of the expression is a TK_COLUMN, then return
149126 ** a pointer to the right-hand branch. Otherwise, return NULL.
149127 */
149128 static Expr *whereRightSubexprIsColumn(Expr *p){
149129 p = sqlite3ExprSkipCollateAndLikely(p->pRight);
149130 if( ALWAYS(p!=0) && p->op==TK_COLUMN && !ExprHasProperty(p, EP_FixedCol) ){
149131 return p;
149132 }
149133 return 0;
149134 }
149135
149136 /*
149137 ** Advance to the next WhereTerm that matches according to the criteria
@@ -150652,11 +150806,11 @@
150806 ** Transfer content from the second pLoop into the first.
150807 */
150808 static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
150809 whereLoopClearUnion(db, pTo);
150810 if( whereLoopResize(db, pTo, pFrom->nLTerm) ){
150811 memset(pTo, 0, WHERE_LOOP_XFER_SZ);
150812 return SQLITE_NOMEM_BKPT;
150813 }
150814 memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
150815 memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
150816 if( pFrom->wsFlags & WHERE_VIRTUALTABLE ){
@@ -150694,10 +150848,21 @@
150848 whereLoopDelete(db, p);
150849 }
150850 assert( pWInfo->pExprMods==0 );
150851 sqlite3DbFreeNN(db, pWInfo);
150852 }
150853
150854 /* Undo all Expr node modifications
150855 */
150856 static void whereUndoExprMods(WhereInfo *pWInfo){
150857 while( pWInfo->pExprMods ){
150858 WhereExprMod *p = pWInfo->pExprMods;
150859 pWInfo->pExprMods = p->pNext;
150860 memcpy(p->pExpr, &p->orig, sizeof(p->orig));
150861 sqlite3DbFree(pWInfo->pParse->db, p);
150862 }
150863 }
150864
150865 /*
150866 ** Return TRUE if all of the following are true:
150867 **
150868 ** (1) X has the same or lower cost that Y
@@ -152307,11 +152472,13 @@
152472 rc = whereLoopAddBtree(&sSubBuild, mPrereq);
152473 }
152474 if( rc==SQLITE_OK ){
152475 rc = whereLoopAddOr(&sSubBuild, mPrereq, mUnusable);
152476 }
152477 assert( rc==SQLITE_OK || rc==SQLITE_DONE || sCur.n==0
152478 || rc==SQLITE_NOMEM );
152479 testcase( rc==SQLITE_NOMEM && sCur.n>0 );
152480 testcase( rc==SQLITE_DONE );
152481 if( sCur.n==0 ){
152482 sSum.n = 0;
152483 break;
152484 }else if( once ){
@@ -152576,10 +152743,14 @@
152743 nKeyCol = pIndex->nKeyCol;
152744 nColumn = pIndex->nColumn;
152745 assert( nColumn==nKeyCol+1 || !HasRowid(pIndex->pTable) );
152746 assert( pIndex->aiColumn[nColumn-1]==XN_ROWID
152747 || !HasRowid(pIndex->pTable));
152748 /* All relevant terms of the index must also be non-NULL in order
152749 ** for isOrderDistinct to be true. So the isOrderDistint value
152750 ** computed here might be a false positive. Corrections will be
152751 ** made at tag-20210426-1 below */
152752 isOrderDistinct = IsUniqueIndex(pIndex)
152753 && (pLoop->wsFlags & WHERE_SKIPSCAN)==0;
152754 }
152755
152756 /* Loop through all columns of the index and deal with the ones
@@ -152643,18 +152814,22 @@
152814 iColumn = XN_ROWID;
152815 revIdx = 0;
152816 }
152817
152818 /* An unconstrained column that might be NULL means that this
152819 ** WhereLoop is not well-ordered. tag-20210426-1
152820 */
152821 if( isOrderDistinct ){
152822 if( iColumn>=0
152823 && j>=pLoop->u.btree.nEq
152824 && pIndex->pTable->aCol[iColumn].notNull==0
152825 ){
152826 isOrderDistinct = 0;
152827 }
152828 if( iColumn==XN_EXPR ){
152829 isOrderDistinct = 0;
152830 }
152831 }
152832
152833 /* Find the ORDER BY term that corresponds to the j-th column
152834 ** of the index and mark that ORDER BY term off
152835 */
@@ -154026,10 +154201,12 @@
154201 return pWInfo;
154202
154203 /* Jump here if malloc fails */
154204 whereBeginError:
154205 if( pWInfo ){
154206 testcase( pWInfo->pExprMods!=0 );
154207 whereUndoExprMods(pWInfo);
154208 pParse->nQueryLoop = pWInfo->savedNQueryLoop;
154209 whereInfoFree(db, pWInfo);
154210 }
154211 return 0;
154212 }
@@ -154325,20 +154502,13 @@
154502 if( db->flags & SQLITE_VdbeAddopTrace ) printf("TRANSLATE complete\n");
154503 #endif
154504 }
154505 }
154506
 
 
 
 
 
 
 
 
154507 /* Final cleanup
154508 */
154509 if( pWInfo->pExprMods ) whereUndoExprMods(pWInfo);
154510 pParse->nQueryLoop = pWInfo->savedNQueryLoop;
154511 whereInfoFree(db, pWInfo);
154512 return;
154513 }
154514
@@ -155914,10 +156084,11 @@
156084 Vdbe *pVdbe; /* VDBE object */
156085 int addrGosub; /* OP_Gosub to this address to return one row */
156086 int regGosub; /* Register used with OP_Gosub(addrGosub) */
156087 int regArg; /* First in array of accumulator registers */
156088 int eDelete; /* See above */
156089 int regRowid;
156090
156091 WindowCsrAndReg start;
156092 WindowCsrAndReg current;
156093 WindowCsrAndReg end;
156094 };
@@ -156590,20 +156761,28 @@
156761 addrContinue = sqlite3VdbeCurrentAddr(v);
156762
156763 /* If this is a (RANGE BETWEEN a FOLLOWING AND b FOLLOWING) or
156764 ** (RANGE BETWEEN b PRECEDING AND a PRECEDING) frame, ensure the
156765 ** start cursor does not advance past the end cursor within the
156766 ** temporary table. It otherwise might, if (a>b). Also ensure that,
156767 ** if the input cursor is still finding new rows, that the end
156768 ** cursor does not go past it to EOF. */
156769 if( pMWin->eStart==pMWin->eEnd && regCountdown
156770 && pMWin->eFrmType==TK_RANGE
156771 ){
156772 int regRowid1 = sqlite3GetTempReg(pParse);
156773 int regRowid2 = sqlite3GetTempReg(pParse);
156774 if( op==WINDOW_AGGINVERSE ){
156775 sqlite3VdbeAddOp2(v, OP_Rowid, p->start.csr, regRowid1);
156776 sqlite3VdbeAddOp2(v, OP_Rowid, p->end.csr, regRowid2);
156777 sqlite3VdbeAddOp3(v, OP_Ge, regRowid2, lblDone, regRowid1);
156778 VdbeCoverage(v);
156779 }else if( p->regRowid ){
156780 sqlite3VdbeAddOp2(v, OP_Rowid, p->end.csr, regRowid1);
156781 sqlite3VdbeAddOp3(v, OP_Ge, p->regRowid, lblDone, regRowid1);
156782 VdbeCoverageNeverNull(v);
156783 }
156784 sqlite3ReleaseTempReg(pParse, regRowid1);
156785 sqlite3ReleaseTempReg(pParse, regRowid2);
156786 assert( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_FOLLOWING );
156787 }
156788
@@ -157096,11 +157275,10 @@
157275 int addrGosubFlush = 0; /* Address of OP_Gosub to flush: */
157276 int addrInteger = 0; /* Address of OP_Integer */
157277 int addrEmpty; /* Address of OP_Rewind in flush: */
157278 int regNew; /* Array of registers holding new input row */
157279 int regRecord; /* regNew array in record form */
 
157280 int regNewPeer = 0; /* Peer values for new row (part of regNew) */
157281 int regPeer = 0; /* Peer values for current row */
157282 int regFlushPart = 0; /* Register for "Gosub flush_partition" */
157283 WindowCodeArg s; /* Context object for sub-routines */
157284 int lblWhereEnd; /* Label just before sqlite3WhereEnd() code */
@@ -157168,11 +157346,11 @@
157346 ** samve values in record form, and the rowid used to insert said record
157347 ** into the ephemeral table. */
157348 regNew = pParse->nMem+1;
157349 pParse->nMem += nInput;
157350 regRecord = ++pParse->nMem;
157351 s.regRowid = ++pParse->nMem;
157352
157353 /* If the window frame contains an "<expr> PRECEDING" or "<expr> FOLLOWING"
157354 ** clause, allocate registers to store the results of evaluating each
157355 ** <expr>. */
157356 if( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_FOLLOWING ){
@@ -157224,13 +157402,13 @@
157402 VdbeComment((v, "call flush_partition"));
157403 sqlite3VdbeAddOp3(v, OP_Copy, regNewPart, pMWin->regPart, nPart-1);
157404 }
157405
157406 /* Insert the new row into the ephemeral table */
157407 sqlite3VdbeAddOp2(v, OP_NewRowid, csrWrite, s.regRowid);
157408 sqlite3VdbeAddOp3(v, OP_Insert, csrWrite, regRecord, s.regRowid);
157409 addrNe = sqlite3VdbeAddOp3(v, OP_Ne, pMWin->regOne, 0, s.regRowid);
157410 VdbeCoverageNeverNull(v);
157411
157412 /* This block is run for the first row of each partition */
157413 s.regArg = windowInitAccum(pParse, pMWin);
157414
@@ -157344,10 +157522,11 @@
157522 if( pMWin->pPartition ){
157523 addrInteger = sqlite3VdbeAddOp2(v, OP_Integer, 0, regFlushPart);
157524 sqlite3VdbeJumpHere(v, addrGosubFlush);
157525 }
157526
157527 s.regRowid = 0;
157528 addrEmpty = sqlite3VdbeAddOp1(v, OP_Rewind, csrWrite);
157529 VdbeCoverage(v);
157530 if( pMWin->eEnd==TK_PRECEDING ){
157531 int bRPS = (pMWin->eStart==TK_PRECEDING && pMWin->eFrmType==TK_RANGE);
157532 windowCodeOp(&s, WINDOW_AGGSTEP, regEnd, 0);
@@ -161012,12 +161191,11 @@
161191 break;
161192 case 16: /* ifnotexists ::= IF NOT EXISTS */
161193 {yymsp[-2].minor.yy60 = 1;}
161194 break;
161195 case 17: /* temp ::= TEMP */
161196 {yymsp[0].minor.yy60 = pParse->db->init.busy==0;}
 
161197 break;
161198 case 19: /* create_table_args ::= LP columnlist conslist_opt RP table_options */
161199 {
161200 sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy60,0);
161201 }
@@ -161125,10 +161303,13 @@
161303 case 43: /* generated ::= LP expr RP */
161304 {sqlite3AddGenerated(pParse,yymsp[-1].minor.yy602,0);}
161305 break;
161306 case 44: /* generated ::= LP expr RP ID */
161307 {sqlite3AddGenerated(pParse,yymsp[-2].minor.yy602,&yymsp[0].minor.yy0);}
161308 break;
161309 case 46: /* autoinc ::= AUTOINCR */
161310 {yymsp[0].minor.yy60 = 1;}
161311 break;
161312 case 47: /* refargs ::= */
161313 { yymsp[1].minor.yy60 = OE_None*0x0101; /* EV: R-19803-45884 */}
161314 break;
161315 case 48: /* refargs ::= refargs refarg */
@@ -162296,11 +162477,15 @@
162477 case 330: /* window_clause ::= WINDOW windowdefn_list */
162478 { yymsp[-1].minor.yy19 = yymsp[0].minor.yy19; }
162479 break;
162480 case 331: /* filter_over ::= filter_clause over_clause */
162481 {
162482 if( yymsp[0].minor.yy19 ){
162483 yymsp[0].minor.yy19->pFilter = yymsp[-1].minor.yy602;
162484 }else{
162485 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy602);
162486 }
162487 yylhsminor.yy19 = yymsp[0].minor.yy19;
162488 }
162489 yymsp[-1].minor.yy19 = yylhsminor.yy19;
162490 break;
162491 case 333: /* filter_over ::= filter_clause */
@@ -162795,10 +162980,11 @@
162980 #define CC_TILDA 25 /* '~' */
162981 #define CC_DOT 26 /* '.' */
162982 #define CC_ID 27 /* unicode characters usable in IDs */
162983 #define CC_ILLEGAL 28 /* Illegal character */
162984 #define CC_NUL 29 /* 0x00 */
162985 #define CC_BOM 30 /* First byte of UTF8 BOM: 0xEF 0xBB 0xBF */
162986
162987 static const unsigned char aiClass[] = {
162988 #ifdef SQLITE_ASCII
162989 /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf */
162990 /* 0x */ 29, 28, 28, 28, 28, 28, 28, 28, 28, 7, 7, 28, 7, 7, 28, 28,
@@ -162807,18 +162993,18 @@
162993 /* 3x */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 19, 12, 14, 13, 6,
162994 /* 4x */ 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
162995 /* 5x */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 9, 28, 28, 28, 2,
162996 /* 6x */ 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
162997 /* 7x */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 28, 10, 28, 25, 28,
162998 /* 8x */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
162999 /* 9x */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
163000 /* Ax */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
163001 /* Bx */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
163002 /* Cx */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
163003 /* Dx */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
163004 /* Ex */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 30,
163005 /* Fx */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27
163006 #endif
163007 #ifdef SQLITE_EBCDIC
163008 /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf */
163009 /* 0x */ 29, 28, 28, 28, 28, 7, 28, 28, 28, 28, 28, 28, 7, 7, 28, 28,
163010 /* 1x */ 28, 28, 28, 28, 28, 7, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
@@ -163757,10 +163943,18 @@
163943 ** SQL keywords start with the letter 'x'. Fall through */
163944 /* no break */ deliberate_fall_through
163945 }
163946 case CC_KYWD:
163947 case CC_ID: {
163948 i = 1;
163949 break;
163950 }
163951 case CC_BOM: {
163952 if( z[1]==0xbb && z[2]==0xbf ){
163953 *tokenType = TK_SPACE;
163954 return 3;
163955 }
163956 i = 1;
163957 break;
163958 }
163959 case CC_NUL: {
163960 *tokenType = TK_ILLEGAL;
@@ -165745,11 +165939,11 @@
165939 }
165940
165941 /*
165942 ** Two variations on the public interface for closing a database
165943 ** connection. The sqlite3_close() version returns SQLITE_BUSY and
165944 ** leaves the connection open if there are unfinalized prepared
165945 ** statements or unfinished sqlite3_backups. The sqlite3_close_v2()
165946 ** version forces the connection to become a zombie if there are
165947 ** unclosed resources, and arranges for deallocation when the last
165948 ** prepare statement or sqlite3_backup closes.
165949 */
@@ -175552,20 +175746,19 @@
175746
175747 /* Determine which, if any, tokens in the expression should be deferred. */
175748 #ifndef SQLITE_DISABLE_FTS4_DEFERRED
175749 if( rc==SQLITE_OK && nToken>1 && pTab->bFts4 ){
175750 Fts3TokenAndCost *aTC;
 
175751 aTC = (Fts3TokenAndCost *)sqlite3_malloc64(
175752 sizeof(Fts3TokenAndCost) * nToken
175753 + sizeof(Fts3Expr *) * nOr * 2
175754 );
 
175755
175756 if( !aTC ){
175757 rc = SQLITE_NOMEM;
175758 }else{
175759 Fts3Expr **apOr = (Fts3Expr **)&aTC[nToken];
175760 int ii;
175761 Fts3TokenAndCost *pTC = aTC;
175762 Fts3Expr **ppOr = apOr;
175763
175764 fts3EvalTokenCosts(pCsr, 0, pCsr->pExpr, &pTC, &ppOr, &rc);
@@ -176937,10 +177130,11 @@
177130 /* In case this cursor is being reused, close and zero it. */
177131 testcase(pCsr->filter.zTerm);
177132 sqlite3Fts3SegReaderFinish(&pCsr->csr);
177133 sqlite3_free((void *)pCsr->filter.zTerm);
177134 sqlite3_free(pCsr->aStat);
177135 sqlite3_free(pCsr->zStop);
177136 memset(&pCsr->csr, 0, ((u8*)&pCsr[1]) - (u8*)&pCsr->csr);
177137
177138 pCsr->filter.flags = FTS3_SEGMENT_REQUIRE_POS|FTS3_SEGMENT_IGNORE_EMPTY;
177139 if( isScan ) pCsr->filter.flags |= FTS3_SEGMENT_SCAN;
177140
@@ -182458,11 +182652,11 @@
182652 rc = (pLhs->aNode==0) - (pRhs->aNode==0);
182653 }
182654 if( rc==0 ){
182655 rc = pRhs->iIdx - pLhs->iIdx;
182656 }
182657 assert_fts3_nc( rc!=0 );
182658 return rc;
182659 }
182660
182661 /*
182662 ** A different comparison function for SegReader structures. In this
@@ -186468,10 +186662,14 @@
186662 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
186663
186664 /* #include <string.h> */
186665 /* #include <assert.h> */
186666
186667 #ifndef SQLITE_AMALGAMATION
186668 typedef sqlite3_int64 i64;
186669 #endif
186670
186671 /*
186672 ** Characters that may appear in the second argument to matchinfo().
186673 */
186674 #define FTS3_MATCHINFO_NPHRASE 'p' /* 1 value */
186675 #define FTS3_MATCHINFO_NCOL 'c' /* 1 value */
@@ -186518,13 +186716,13 @@
186716 };
186717
186718 struct SnippetPhrase {
186719 int nToken; /* Number of tokens in phrase */
186720 char *pList; /* Pointer to start of phrase position list */
186721 i64 iHead; /* Next value in position list */
186722 char *pHead; /* Position list data following iHead */
186723 i64 iTail; /* Next value in trailing position list */
186724 char *pTail; /* Position list data following iTail */
186725 };
186726
186727 struct SnippetFragment {
186728 int iCol; /* Column snippet is extracted from */
@@ -186685,11 +186883,11 @@
186883 ** When this function is called, *pp points to the start of an element of
186884 ** the list. *piPos contains the value of the previous entry in the list.
186885 ** After it returns, *piPos contains the value of the next element of the
186886 ** list and *pp is advanced to the following varint.
186887 */
186888 static void fts3GetDeltaPosition(char **pp, i64 *piPos){
186889 int iVal;
186890 *pp += fts3GetVarint32(*pp, &iVal);
186891 *piPos += (iVal-2);
186892 }
186893
@@ -186794,14 +186992,14 @@
186992 /*
186993 ** Advance the position list iterator specified by the first two
186994 ** arguments so that it points to the first element with a value greater
186995 ** than or equal to parameter iNext.
186996 */
186997 static void fts3SnippetAdvance(char **ppIter, i64 *piIter, int iNext){
186998 char *pIter = *ppIter;
186999 if( pIter ){
187000 i64 iIter = *piIter;
187001
187002 while( iIter<iNext ){
187003 if( 0==(*pIter & 0xFE) ){
187004 iIter = -1;
187005 pIter = 0;
@@ -186880,11 +187078,11 @@
187078
187079 for(i=0; i<pIter->nPhrase; i++){
187080 SnippetPhrase *pPhrase = &pIter->aPhrase[i];
187081 if( pPhrase->pTail ){
187082 char *pCsr = pPhrase->pTail;
187083 i64 iCsr = pPhrase->iTail;
187084
187085 while( iCsr<(iStart+pIter->nSnippet) && iCsr>=iStart ){
187086 int j;
187087 u64 mPhrase = (u64)1 << (i%64);
187088 u64 mPos = (u64)1 << (iCsr - iStart);
@@ -186926,11 +187124,11 @@
187124
187125 pPhrase->nToken = pExpr->pPhrase->nToken;
187126 rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pCsr);
187127 assert( rc==SQLITE_OK || pCsr==0 );
187128 if( pCsr ){
187129 i64 iFirst = 0;
187130 pPhrase->pList = pCsr;
187131 fts3GetDeltaPosition(&pCsr, &iFirst);
187132 if( iFirst<0 ){
187133 rc = FTS_CORRUPT_VTAB;
187134 }else{
@@ -187990,12 +188188,12 @@
188188 typedef struct TermOffset TermOffset;
188189 typedef struct TermOffsetCtx TermOffsetCtx;
188190
188191 struct TermOffset {
188192 char *pList; /* Position-list */
188193 i64 iPos; /* Position just read from pList */
188194 i64 iOff; /* Offset of this term from read positions */
188195 };
188196
188197 struct TermOffsetCtx {
188198 Fts3Cursor *pCsr;
188199 int iCol; /* Column of table to populate aTerm for */
@@ -188010,11 +188208,11 @@
188208 static int fts3ExprTermOffsetInit(Fts3Expr *pExpr, int iPhrase, void *ctx){
188209 TermOffsetCtx *p = (TermOffsetCtx *)ctx;
188210 int nTerm; /* Number of tokens in phrase */
188211 int iTerm; /* For looping through nTerm phrase terms */
188212 char *pList; /* Pointer to position list for phrase */
188213 i64 iPos = 0; /* First position in position-list */
188214 int rc;
188215
188216 UNUSED_PARAMETER(iPhrase);
188217 rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pList);
188218 nTerm = pExpr->pPhrase->nToken;
@@ -190886,12 +191084,12 @@
191084 if( pStr->zBuf==0 ){
191085 jsonInit(pStr, ctx);
191086 jsonAppendChar(pStr, '[');
191087 }else if( pStr->nUsed>1 ){
191088 jsonAppendChar(pStr, ',');
 
191089 }
191090 pStr->pCtx = ctx;
191091 jsonAppendValue(pStr, argv[0]);
191092 }
191093 }
191094 static void jsonArrayCompute(sqlite3_context *ctx, int isFinal){
191095 JsonString *pStr;
@@ -190947,26 +191145,27 @@
191145 /* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will
191146 ** always have been called to initalize it */
191147 if( NEVER(!pStr) ) return;
191148 #endif
191149 z = pStr->zBuf;
191150 for(i=1; i<pStr->nUsed && ((c = z[i])!=',' || inStr || nNest); i++){
 
 
 
 
191151 if( c=='"' ){
191152 inStr = !inStr;
191153 }else if( c=='\\' ){
191154 i++;
191155 }else if( !inStr ){
191156 if( c=='{' || c=='[' ) nNest++;
191157 if( c=='}' || c==']' ) nNest--;
191158 }
191159 }
191160 if( i<pStr->nUsed ){
191161 pStr->nUsed -= i;
191162 memmove(&z[1], &z[i+1], (size_t)pStr->nUsed-1);
191163 z[pStr->nUsed] = 0;
191164 }else{
191165 pStr->nUsed = 1;
191166 }
191167 }
191168 #else
191169 # define jsonGroupInverse 0
191170 #endif
191171
@@ -195512,15 +195711,20 @@
195711 */
195712 static void rtreedepth(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){
195713 UNUSED_PARAMETER(nArg);
195714 if( sqlite3_value_type(apArg[0])!=SQLITE_BLOB
195715 || sqlite3_value_bytes(apArg[0])<2
195716
195717 ){
195718 sqlite3_result_error(ctx, "Invalid argument to rtreedepth()", -1);
195719 }else{
195720 u8 *zBlob = (u8 *)sqlite3_value_blob(apArg[0]);
195721 if( zBlob ){
195722 sqlite3_result_int(ctx, readInt16(zBlob));
195723 }else{
195724 sqlite3_result_error_nomem(ctx);
195725 }
195726 }
195727 }
195728
195729 /*
195730 ** Context object passed between the various routines that make up the
@@ -206045,17 +206249,19 @@
206249 ** Session handle structure.
206250 */
206251 struct sqlite3_session {
206252 sqlite3 *db; /* Database handle session is attached to */
206253 char *zDb; /* Name of database session is attached to */
206254 int bEnableSize; /* True if changeset_size() enabled */
206255 int bEnable; /* True if currently recording */
206256 int bIndirect; /* True if all changes are indirect */
206257 int bAutoAttach; /* True to auto-attach tables */
206258 int rc; /* Non-zero if an error has occurred */
206259 void *pFilterCtx; /* First argument to pass to xTableFilter */
206260 int (*xTableFilter)(void *pCtx, const char *zTab);
206261 i64 nMalloc; /* Number of bytes of data allocated */
206262 i64 nMaxChangesetSize;
206263 sqlite3_value *pZeroBlob; /* Value containing X'' */
206264 sqlite3_session *pNext; /* Next session object on same db. */
206265 SessionTable *pTable; /* List of attached tables */
206266 SessionHook hook; /* APIs to grab new and old data with */
206267 };
@@ -206294,12 +206500,13 @@
206500 /*
206501 ** For each row modified during a session, there exists a single instance of
206502 ** this structure stored in a SessionTable.aChange[] hash table.
206503 */
206504 struct SessionChange {
206505 u8 op; /* One of UPDATE, DELETE, INSERT */
206506 u8 bIndirect; /* True if this change is "indirect" */
206507 int nMaxSize; /* Max size of eventual changeset record */
206508 int nRecord; /* Number of bytes in buffer aRecord[] */
206509 u8 *aRecord; /* Buffer containing old.* record */
206510 SessionChange *pNext; /* For hash-table collisions */
206511 };
206512
@@ -207124,10 +207331,16 @@
207331 }
207332 }
207333 if( 0==sqlite3_stricmp("sqlite_stat1", pTab->zName) ){
207334 pTab->bStat1 = 1;
207335 }
207336
207337 if( pSession->bEnableSize ){
207338 pSession->nMaxChangesetSize += (
207339 1 + sessionVarintLen(pTab->nCol) + pTab->nCol + strlen(pTab->zName)+1
207340 );
207341 }
207342 }
207343 }
207344 return (pSession->rc || pTab->abPK==0);
207345 }
207346
@@ -207169,10 +207382,107 @@
207382 static int sessionStat1Depth(void *pCtx){
207383 SessionStat1Ctx *p = (SessionStat1Ctx*)pCtx;
207384 return p->hook.xDepth(p->hook.pCtx);
207385 }
207386
207387 static int sessionUpdateMaxSize(
207388 int op,
207389 sqlite3_session *pSession, /* Session object pTab is attached to */
207390 SessionTable *pTab, /* Table that change applies to */
207391 SessionChange *pC /* Update pC->nMaxSize */
207392 ){
207393 i64 nNew = 2;
207394 if( pC->op==SQLITE_INSERT ){
207395 if( op!=SQLITE_DELETE ){
207396 int ii;
207397 for(ii=0; ii<pTab->nCol; ii++){
207398 sqlite3_value *p = 0;
207399 pSession->hook.xNew(pSession->hook.pCtx, ii, &p);
207400 sessionSerializeValue(0, p, &nNew);
207401 }
207402 }
207403 }else if( op==SQLITE_DELETE ){
207404 nNew += pC->nRecord;
207405 if( sqlite3_preupdate_blobwrite(pSession->db)>=0 ){
207406 nNew += pC->nRecord;
207407 }
207408 }else{
207409 int ii;
207410 u8 *pCsr = pC->aRecord;
207411 for(ii=0; ii<pTab->nCol; ii++){
207412 int bChanged = 1;
207413 int nOld = 0;
207414 int eType;
207415 sqlite3_value *p = 0;
207416 pSession->hook.xNew(pSession->hook.pCtx, ii, &p);
207417 if( p==0 ){
207418 return SQLITE_NOMEM;
207419 }
207420
207421 eType = *pCsr++;
207422 switch( eType ){
207423 case SQLITE_NULL:
207424 bChanged = sqlite3_value_type(p)!=SQLITE_NULL;
207425 break;
207426
207427 case SQLITE_FLOAT:
207428 case SQLITE_INTEGER: {
207429 if( eType==sqlite3_value_type(p) ){
207430 sqlite3_int64 iVal = sessionGetI64(pCsr);
207431 if( eType==SQLITE_INTEGER ){
207432 bChanged = (iVal!=sqlite3_value_int64(p));
207433 }else{
207434 double dVal;
207435 memcpy(&dVal, &iVal, 8);
207436 bChanged = (dVal!=sqlite3_value_double(p));
207437 }
207438 }
207439 nOld = 8;
207440 pCsr += 8;
207441 break;
207442 }
207443
207444 default: {
207445 int nByte;
207446 nOld = sessionVarintGet(pCsr, &nByte);
207447 pCsr += nOld;
207448 nOld += nByte;
207449 assert( eType==SQLITE_TEXT || eType==SQLITE_BLOB );
207450 if( eType==sqlite3_value_type(p)
207451 && nByte==sqlite3_value_bytes(p)
207452 && (nByte==0 || 0==memcmp(pCsr, sqlite3_value_blob(p), nByte))
207453 ){
207454 bChanged = 0;
207455 }
207456 pCsr += nByte;
207457 break;
207458 }
207459 }
207460
207461 if( bChanged && pTab->abPK[ii] ){
207462 nNew = pC->nRecord + 2;
207463 break;
207464 }
207465
207466 if( bChanged ){
207467 nNew += 1 + nOld;
207468 sessionSerializeValue(0, p, &nNew);
207469 }else if( pTab->abPK[ii] ){
207470 nNew += 2 + nOld;
207471 }else{
207472 nNew += 2;
207473 }
207474 }
207475 }
207476
207477 if( nNew>pC->nMaxSize ){
207478 int nIncr = nNew - pC->nMaxSize;
207479 pC->nMaxSize = nNew;
207480 pSession->nMaxChangesetSize += nIncr;
207481 }
207482 return SQLITE_OK;
207483 }
207484
207485 /*
207486 ** This function is only called from with a pre-update-hook reporting a
207487 ** change on table pTab (attached to session pSession). The type of change
207488 ** (UPDATE, INSERT, DELETE) is specified by the first argument.
@@ -207242,11 +207552,10 @@
207552
207553 if( pC==0 ){
207554 /* Create a new change object containing all the old values (if
207555 ** this is an SQLITE_UPDATE or SQLITE_DELETE), or just the PK
207556 ** values (if this is an INSERT). */
 
207557 sqlite3_int64 nByte; /* Number of bytes to allocate */
207558 int i; /* Used to iterate through columns */
207559
207560 assert( rc==SQLITE_OK );
207561 pTab->nEntry++;
@@ -207268,17 +207577,17 @@
207577 rc = sessionSerializeValue(0, p, &nByte);
207578 if( rc!=SQLITE_OK ) goto error_out;
207579 }
207580
207581 /* Allocate the change object */
207582 pC = (SessionChange *)sessionMalloc64(pSession, nByte);
207583 if( !pC ){
207584 rc = SQLITE_NOMEM;
207585 goto error_out;
207586 }else{
207587 memset(pC, 0, sizeof(SessionChange));
207588 pC->aRecord = (u8 *)&pC[1];
207589 }
207590
207591 /* Populate the change object. None of the preupdate_old(),
207592 ** preupdate_new() or SerializeValue() calls below may fail as all
207593 ** required values and encodings have already been cached in memory.
@@ -207289,21 +207598,21 @@
207598 if( op!=SQLITE_INSERT ){
207599 pSession->hook.xOld(pSession->hook.pCtx, i, &p);
207600 }else if( pTab->abPK[i] ){
207601 pSession->hook.xNew(pSession->hook.pCtx, i, &p);
207602 }
207603 sessionSerializeValue(&pC->aRecord[nByte], p, &nByte);
207604 }
207605
207606 /* Add the change to the hash-table */
207607 if( pSession->bIndirect || pSession->hook.xDepth(pSession->hook.pCtx) ){
207608 pC->bIndirect = 1;
207609 }
207610 pC->nRecord = nByte;
207611 pC->op = op;
207612 pC->pNext = pTab->apChange[iHash];
207613 pTab->apChange[iHash] = pC;
207614
207615 }else if( pC->bIndirect ){
207616 /* If the existing change is considered "indirect", but this current
207617 ** change is "direct", mark the change object as direct. */
207618 if( pSession->hook.xDepth(pSession->hook.pCtx)==0
@@ -207310,11 +207619,17 @@
207619 && pSession->bIndirect==0
207620 ){
207621 pC->bIndirect = 0;
207622 }
207623 }
207624
207625 assert( rc==SQLITE_OK );
207626 if( pSession->bEnableSize ){
207627 rc = sessionUpdateMaxSize(op, pSession, pTab, pC);
207628 }
207629 }
207630
207631
207632 /* If an error has occurred, mark the session object as failed. */
207633 error_out:
207634 if( pTab->bStat1 ){
207635 pSession->hook = stat1.hook;
@@ -208523,11 +208838,15 @@
208838 SQLITE_API int sqlite3session_changeset(
208839 sqlite3_session *pSession, /* Session object */
208840 int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
208841 void **ppChangeset /* OUT: Buffer containing changeset */
208842 ){
208843 int rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset,ppChangeset);
208844 assert( rc || pnChangeset==0
208845 || pSession->bEnableSize==0 || *pnChangeset<=pSession->nMaxChangesetSize
208846 );
208847 return rc;
208848 }
208849
208850 /*
208851 ** Streaming version of sqlite3session_changeset().
208852 */
@@ -208614,10 +208933,43 @@
208933 ** Return the amount of heap memory in use.
208934 */
208935 SQLITE_API sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession){
208936 return pSession->nMalloc;
208937 }
208938
208939 /*
208940 ** Configure the session object passed as the first argument.
208941 */
208942 SQLITE_API int sqlite3session_object_config(sqlite3_session *pSession, int op, void *pArg){
208943 int rc = SQLITE_OK;
208944 switch( op ){
208945 case SQLITE_SESSION_OBJCONFIG_SIZE: {
208946 int iArg = *(int*)pArg;
208947 if( iArg>=0 ){
208948 if( pSession->pTable ){
208949 rc = SQLITE_MISUSE;
208950 }else{
208951 pSession->bEnableSize = (iArg!=0);
208952 }
208953 }
208954 *(int*)pArg = pSession->bEnableSize;
208955 break;
208956 }
208957
208958 default:
208959 rc = SQLITE_MISUSE;
208960 }
208961
208962 return rc;
208963 }
208964
208965 /*
208966 ** Return the maximum size of sqlite3session_changeset() output.
208967 */
208968 SQLITE_API sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession){
208969 return pSession->nMaxChangesetSize;
208970 }
208971
208972 /*
208973 ** Do the work for either sqlite3changeset_start() or start_strm().
208974 */
208975 static int sessionChangesetStart(
@@ -216198,11 +216550,11 @@
216550 pRet->db = db;
216551 pRet->iCookie = -1;
216552
216553 nByte = nArg * (sizeof(char*) + sizeof(u8));
216554 pRet->azCol = (char**)sqlite3Fts5MallocZero(&rc, nByte);
216555 pRet->abUnindexed = pRet->azCol ? (u8*)&pRet->azCol[nArg] : 0;
216556 pRet->zDb = sqlite3Fts5Strndup(&rc, azArg[1], -1);
216557 pRet->zName = sqlite3Fts5Strndup(&rc, azArg[2], -1);
216558 pRet->bColumnsize = 1;
216559 pRet->eDetail = FTS5_DETAIL_FULL;
216560 #ifdef SQLITE_DEBUG
@@ -219034,10 +219386,11 @@
219386 }
219387
219388 return pRet;
219389 }
219390
219391 #ifdef SQLITE_TEST
219392 static char *fts5ExprTermPrint(Fts5ExprTerm *pTerm){
219393 sqlite3_int64 nByte = 0;
219394 Fts5ExprTerm *p;
219395 char *zQuoted;
219396
@@ -219400,16 +219753,18 @@
219753 iCode = sqlite3_value_int(apVal[0]);
219754 if( nArg==2 ) bRemoveDiacritics = sqlite3_value_int(apVal[1]);
219755 sqlite3_result_int(pCtx, sqlite3Fts5UnicodeFold(iCode, bRemoveDiacritics));
219756 }
219757 }
219758 #endif /* ifdef SQLITE_TEST */
219759
219760 /*
219761 ** This is called during initialization to register the fts5_expr() scalar
219762 ** UDF with the SQLite handle passed as the only argument.
219763 */
219764 static int sqlite3Fts5ExprInit(Fts5Global *pGlobal, sqlite3 *db){
219765 #ifdef SQLITE_TEST
219766 struct Fts5ExprFunc {
219767 const char *z;
219768 void (*x)(sqlite3_context*,int,sqlite3_value**);
219769 } aFunc[] = {
219770 { "fts5_expr", fts5ExprFunctionHr },
@@ -219423,10 +219778,14 @@
219778
219779 for(i=0; rc==SQLITE_OK && i<ArraySize(aFunc); i++){
219780 struct Fts5ExprFunc *p = &aFunc[i];
219781 rc = sqlite3_create_function(db, p->z, -1, SQLITE_UTF8, pCtx, p->x, 0, 0);
219782 }
219783 #else
219784 int rc = SQLITE_OK;
219785 UNUSED_PARAM2(pGlobal,db);
219786 #endif
219787
219788 /* Avoid warnings indicating that sqlite3Fts5ParserTrace() and
219789 ** sqlite3Fts5ParserFallback() are unused */
219790 #ifndef NDEBUG
219791 (void)sqlite3Fts5ParserTrace;
@@ -220669,11 +221028,11 @@
221028 Fts5StructureSegment *pSeg; /* Segment to iterate through */
221029 int flags; /* Mask of configuration flags */
221030 int iLeafPgno; /* Current leaf page number */
221031 Fts5Data *pLeaf; /* Current leaf data */
221032 Fts5Data *pNextLeaf; /* Leaf page (iLeafPgno+1) */
221033 i64 iLeafOffset; /* Byte offset within current leaf */
221034
221035 /* Next method */
221036 void (*xNext)(Fts5Index*, Fts5SegIter*, int*);
221037
221038 /* The page and offset from which the current term was read. The offset
@@ -221849,11 +222208,11 @@
222208 }
222209 }
222210
222211 static void fts5SegIterLoadRowid(Fts5Index *p, Fts5SegIter *pIter){
222212 u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
222213 i64 iOff = pIter->iLeafOffset;
222214
222215 ASSERT_SZLEAF_OK(pIter->pLeaf);
222216 if( iOff>=pIter->pLeaf->szLeaf ){
222217 fts5SegIterNextPage(p, pIter);
222218 if( pIter->pLeaf==0 ){
@@ -221882,11 +222241,11 @@
222241 ** the first position list. The position list belonging to document
222242 ** (Fts5SegIter.iRowid).
222243 */
222244 static void fts5SegIterLoadTerm(Fts5Index *p, Fts5SegIter *pIter, int nKeep){
222245 u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
222246 i64 iOff = pIter->iLeafOffset; /* Offset to read at */
222247 int nNew; /* Bytes of new data */
222248
222249 iOff += fts5GetVarint32(&a[iOff], nNew);
222250 if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){
222251 p->rc = FTS5_CORRUPT;
@@ -224779,18 +225138,18 @@
225138 if( pgsz>=(pBuf->n + pPgidx->n + nDoclist + 1) ){
225139 /* The entire doclist will fit on the current leaf. */
225140 fts5BufferSafeAppendBlob(pBuf, pDoclist, nDoclist);
225141 }else{
225142 i64 iRowid = 0;
225143 u64 iDelta = 0;
225144 int iOff = 0;
225145
225146 /* The entire doclist will not fit on this leaf. The following
225147 ** loop iterates through the poslists that make up the current
225148 ** doclist. */
225149 while( p->rc==SQLITE_OK && iOff<nDoclist ){
225150 iOff += fts5GetVarint(&pDoclist[iOff], &iDelta);
225151 iRowid += iDelta;
225152
225153 if( writer.bFirstRowidInPage ){
225154 fts5PutU16(&pBuf->p[0], (u16)pBuf->n); /* first rowid on page */
225155 pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid);
@@ -225317,11 +225676,12 @@
225676 sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, pHead->iPos);
225677 }
225678 nTail = pHead->iter.nPoslist - pHead->iOff;
225679
225680 /* WRITEPOSLISTSIZE */
225681 assert_nc( tmp.n+nTail<=nTmp );
225682 assert( tmp.n+nTail<=nTmp+nMerge*10 );
225683 if( tmp.n+nTail>nTmp-FTS5_DATA_ZERO_PADDING ){
225684 if( p->rc==SQLITE_OK ) p->rc = FTS5_CORRUPT;
225685 break;
225686 }
225687 fts5BufferSafeAppendVarint(&out, (tmp.n+nTail) * 2);
@@ -226958,10 +227318,11 @@
227318 );
227319 }
227320 return rc;
227321 #else
227322 return SQLITE_OK;
227323 UNUSED_PARAM(db);
227324 #endif
227325 }
227326
227327
227328 static int sqlite3Fts5IndexReset(Fts5Index *p){
@@ -229762,11 +230123,11 @@
230123 int nArg, /* Number of args */
230124 sqlite3_value **apUnused /* Function arguments */
230125 ){
230126 assert( nArg==0 );
230127 UNUSED_PARAM2(nArg, apUnused);
230128 sqlite3_result_text(pCtx, "fts5: 2021-04-27 17:18:10 ff3538ae37a02f4f36a15cddd1245171e724aac9c84b2e576980fd3806302775", -1, SQLITE_TRANSIENT);
230129 }
230130
230131 /*
230132 ** Return true if zName is the extension on one of the shadow tables used
230133 ** by this module.
@@ -234688,12 +235049,12 @@
235049 }
235050 #endif /* SQLITE_CORE */
235051 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
235052
235053 /************** End of stmt.c ************************************************/
235054 #if __LINE__!=235054
235055 #undef SQLITE_SOURCE_ID
235056 #define SQLITE_SOURCE_ID "2021-04-28 17:37:26 65ec39f0f092fe29e1d4e9e96cf07a73d2ef7ce2c41b6f1cd3ab23546adaalt2"
235057 #endif
235058 /* Return the source-id for this library */
235059 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
235060 /************************** End of sqlite3.c ******************************/
235061
+58 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.36.0"
127127
#define SQLITE_VERSION_NUMBER 3036000
128
-#define SQLITE_SOURCE_ID "2021-04-07 18:17:53 a2ddb89b206c13876d34c5f9e3db41cda72d6eb3fea31ffa8cc6daa1e1580e16"
128
+#define SQLITE_SOURCE_ID "2021-04-28 17:37:26 65ec39f0f092fe29e1d4e9e96cf07a73d2ef7ce2c41b6f1cd3ab23546ada0e67"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -9544,10 +9544,19 @@
95449544
** callback was invoked as a result of a direct insert, update, or delete
95459545
** operation; or 1 for inserts, updates, or deletes invoked by top-level
95469546
** triggers; or 2 for changes resulting from triggers called by top-level
95479547
** triggers; and so forth.
95489548
**
9549
+** When the [sqlite3_blob_write()] API is used to update a blob column,
9550
+** the pre-update hook is invoked with SQLITE_DELETE. This is because the
9551
+** in this case the new values are not available. In this case, when a
9552
+** callback made with op==SQLITE_DELETE is actuall a write using the
9553
+** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
9554
+** the index of the column being written. In other cases, where the
9555
+** pre-update hook is being invoked for some other reason, including a
9556
+** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
9557
+**
95499558
** See also: [sqlite3_update_hook()]
95509559
*/
95519560
#if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
95529561
SQLITE_API void *sqlite3_preupdate_hook(
95539562
sqlite3 *db,
@@ -9564,10 +9573,11 @@
95649573
);
95659574
SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
95669575
SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
95679576
SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
95689577
SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
9578
+SQLITE_API int sqlite3_preupdate_blobwrite(sqlite3 *);
95699579
#endif
95709580
95719581
/*
95729582
** CAPI3REF: Low-level system error code
95739583
** METHOD: sqlite3
@@ -10104,10 +10114,41 @@
1010410114
** are attached is closed. Refer to the documentation for
1010510115
** [sqlite3session_create()] for details.
1010610116
*/
1010710117
SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
1010810118
10119
+/*
10120
+** CAPIREF: Conigure a Session Object
10121
+** METHOD: sqlite3_session
10122
+**
10123
+** This method is used to configure a session object after it has been
10124
+** created. At present the only valid value for the second parameter is
10125
+** [SQLITE_SESSION_OBJCONFIG_SIZE].
10126
+*/
10127
+SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
10128
+
10129
+/*
10130
+** CAPI3REF: Arguments for sqlite3session_object_config()
10131
+**
10132
+** The following values may passed as the the 4th parameter to
10133
+** [sqlite3session_object_config].
10134
+**
10135
+** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
10136
+** This option is used to set, clear or query the flag that enables
10137
+** the [sqlite3session_changeset_size()] API. Because it imposes some
10138
+** computational overhead, this API is disabled by default. Argument
10139
+** pArg must point to a value of type (int). If the value is initially
10140
+** 0, then the sqlite3session_changeset_size() API is disabled. If it
10141
+** is greater than 0, then the same API is enabled. Or, if the initial
10142
+** value is less than zero, no change is made. In all cases the (int)
10143
+** variable is set to 1 if the sqlite3session_changeset_size() API is
10144
+** enabled following the current call, or 0 otherwise.
10145
+**
10146
+** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
10147
+** the first table has been attached to the session object.
10148
+*/
10149
+#define SQLITE_SESSION_OBJCONFIG_SIZE 1
1010910150
1011010151
/*
1011110152
** CAPI3REF: Enable Or Disable A Session Object
1011210153
** METHOD: sqlite3_session
1011310154
**
@@ -10348,10 +10389,26 @@
1034810389
sqlite3_session *pSession, /* Session object */
1034910390
int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
1035010391
void **ppChangeset /* OUT: Buffer containing changeset */
1035110392
);
1035210393
10394
+/*
10395
+** CAPI3REF: Return An Upper-limit For The Size Of The Changeset
10396
+** METHOD: sqlite3session_changeset_size()
10397
+**
10398
+** By default, this function always returns 0. For it to return
10399
+** a useful result, the sqlite3_session object must have been configured
10400
+** to enable this API using [sqlite3session_object_config()] with the
10401
+** SQLITE_SESSION_OBJCONFIG_SIZE verb.
10402
+**
10403
+** When enabled, this function returns an upper limit, in bytes, for the size
10404
+** of the changeset that might be produced if sqlite3session_changeset() were
10405
+** called. The final changeset size might be equal to or smaller than the
10406
+** size in bytes returned by this function.
10407
+*/
10408
+SQLITE_API sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession);
10409
+
1035310410
/*
1035410411
** CAPI3REF: Load The Difference Between Tables Into A Session
1035510412
** METHOD: sqlite3_session
1035610413
**
1035710414
** If it is not already attached to the session object passed as the first
1035810415
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.36.0"
127 #define SQLITE_VERSION_NUMBER 3036000
128 #define SQLITE_SOURCE_ID "2021-04-07 18:17:53 a2ddb89b206c13876d34c5f9e3db41cda72d6eb3fea31ffa8cc6daa1e1580e16"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -9544,10 +9544,19 @@
9544 ** callback was invoked as a result of a direct insert, update, or delete
9545 ** operation; or 1 for inserts, updates, or deletes invoked by top-level
9546 ** triggers; or 2 for changes resulting from triggers called by top-level
9547 ** triggers; and so forth.
9548 **
 
 
 
 
 
 
 
 
 
9549 ** See also: [sqlite3_update_hook()]
9550 */
9551 #if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
9552 SQLITE_API void *sqlite3_preupdate_hook(
9553 sqlite3 *db,
@@ -9564,10 +9573,11 @@
9564 );
9565 SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
9566 SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
9567 SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
9568 SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
 
9569 #endif
9570
9571 /*
9572 ** CAPI3REF: Low-level system error code
9573 ** METHOD: sqlite3
@@ -10104,10 +10114,41 @@
10104 ** are attached is closed. Refer to the documentation for
10105 ** [sqlite3session_create()] for details.
10106 */
10107 SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
10108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10109
10110 /*
10111 ** CAPI3REF: Enable Or Disable A Session Object
10112 ** METHOD: sqlite3_session
10113 **
@@ -10348,10 +10389,26 @@
10348 sqlite3_session *pSession, /* Session object */
10349 int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
10350 void **ppChangeset /* OUT: Buffer containing changeset */
10351 );
10352
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10353 /*
10354 ** CAPI3REF: Load The Difference Between Tables Into A Session
10355 ** METHOD: sqlite3_session
10356 **
10357 ** If it is not already attached to the session object passed as the first
10358
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.36.0"
127 #define SQLITE_VERSION_NUMBER 3036000
128 #define SQLITE_SOURCE_ID "2021-04-28 17:37:26 65ec39f0f092fe29e1d4e9e96cf07a73d2ef7ce2c41b6f1cd3ab23546ada0e67"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -9544,10 +9544,19 @@
9544 ** callback was invoked as a result of a direct insert, update, or delete
9545 ** operation; or 1 for inserts, updates, or deletes invoked by top-level
9546 ** triggers; or 2 for changes resulting from triggers called by top-level
9547 ** triggers; and so forth.
9548 **
9549 ** When the [sqlite3_blob_write()] API is used to update a blob column,
9550 ** the pre-update hook is invoked with SQLITE_DELETE. This is because the
9551 ** in this case the new values are not available. In this case, when a
9552 ** callback made with op==SQLITE_DELETE is actuall a write using the
9553 ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
9554 ** the index of the column being written. In other cases, where the
9555 ** pre-update hook is being invoked for some other reason, including a
9556 ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
9557 **
9558 ** See also: [sqlite3_update_hook()]
9559 */
9560 #if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
9561 SQLITE_API void *sqlite3_preupdate_hook(
9562 sqlite3 *db,
@@ -9564,10 +9573,11 @@
9573 );
9574 SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
9575 SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
9576 SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
9577 SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
9578 SQLITE_API int sqlite3_preupdate_blobwrite(sqlite3 *);
9579 #endif
9580
9581 /*
9582 ** CAPI3REF: Low-level system error code
9583 ** METHOD: sqlite3
@@ -10104,10 +10114,41 @@
10114 ** are attached is closed. Refer to the documentation for
10115 ** [sqlite3session_create()] for details.
10116 */
10117 SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
10118
10119 /*
10120 ** CAPIREF: Conigure a Session Object
10121 ** METHOD: sqlite3_session
10122 **
10123 ** This method is used to configure a session object after it has been
10124 ** created. At present the only valid value for the second parameter is
10125 ** [SQLITE_SESSION_OBJCONFIG_SIZE].
10126 */
10127 SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
10128
10129 /*
10130 ** CAPI3REF: Arguments for sqlite3session_object_config()
10131 **
10132 ** The following values may passed as the the 4th parameter to
10133 ** [sqlite3session_object_config].
10134 **
10135 ** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
10136 ** This option is used to set, clear or query the flag that enables
10137 ** the [sqlite3session_changeset_size()] API. Because it imposes some
10138 ** computational overhead, this API is disabled by default. Argument
10139 ** pArg must point to a value of type (int). If the value is initially
10140 ** 0, then the sqlite3session_changeset_size() API is disabled. If it
10141 ** is greater than 0, then the same API is enabled. Or, if the initial
10142 ** value is less than zero, no change is made. In all cases the (int)
10143 ** variable is set to 1 if the sqlite3session_changeset_size() API is
10144 ** enabled following the current call, or 0 otherwise.
10145 **
10146 ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
10147 ** the first table has been attached to the session object.
10148 */
10149 #define SQLITE_SESSION_OBJCONFIG_SIZE 1
10150
10151 /*
10152 ** CAPI3REF: Enable Or Disable A Session Object
10153 ** METHOD: sqlite3_session
10154 **
@@ -10348,10 +10389,26 @@
10389 sqlite3_session *pSession, /* Session object */
10390 int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
10391 void **ppChangeset /* OUT: Buffer containing changeset */
10392 );
10393
10394 /*
10395 ** CAPI3REF: Return An Upper-limit For The Size Of The Changeset
10396 ** METHOD: sqlite3session_changeset_size()
10397 **
10398 ** By default, this function always returns 0. For it to return
10399 ** a useful result, the sqlite3_session object must have been configured
10400 ** to enable this API using [sqlite3session_object_config()] with the
10401 ** SQLITE_SESSION_OBJCONFIG_SIZE verb.
10402 **
10403 ** When enabled, this function returns an upper limit, in bytes, for the size
10404 ** of the changeset that might be produced if sqlite3session_changeset() were
10405 ** called. The final changeset size might be equal to or smaller than the
10406 ** size in bytes returned by this function.
10407 */
10408 SQLITE_API sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession);
10409
10410 /*
10411 ** CAPI3REF: Load The Difference Between Tables Into A Session
10412 ** METHOD: sqlite3_session
10413 **
10414 ** If it is not already attached to the session object passed as the first
10415

Keyboard Shortcuts

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