better-sqlite3-multiple-ciphers 7.5.1-beta.2 → 7.5.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/deps/copy.js +26 -0
- package/deps/download.sh +111 -111
- package/deps/setup.ps1 +1 -1
- package/deps/sqlite3/sqlite3.c +415 -178
- package/deps/sqlite3/sqlite3.h +14 -10
- package/deps/sqlite3.gyp +4 -4
- package/package.json +1 -1
- package/deps/symlink.js +0 -19
package/deps/sqlite3/sqlite3.c
CHANGED
|
@@ -92,7 +92,7 @@ extern SQLITE_API LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
|
|
|
92
92
|
/*** Begin of #include "sqlite3patched.c" ***/
|
|
93
93
|
/******************************************************************************
|
|
94
94
|
** This file is an amalgamation of many separate C source files from SQLite
|
|
95
|
-
** version 3.38.
|
|
95
|
+
** version 3.38.2. By combining all the individual C code files into this
|
|
96
96
|
** single large file, the entire code can be compiled as a single translation
|
|
97
97
|
** unit. This allows many compilers to do optimizations that would not be
|
|
98
98
|
** possible if the files were compiled separately. Performance improvements
|
|
@@ -544,9 +544,9 @@ extern "C" {
|
|
|
544
544
|
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
|
|
545
545
|
** [sqlite_version()] and [sqlite_source_id()].
|
|
546
546
|
*/
|
|
547
|
-
#define SQLITE_VERSION "3.38.
|
|
548
|
-
#define SQLITE_VERSION_NUMBER
|
|
549
|
-
#define SQLITE_SOURCE_ID "2022-
|
|
547
|
+
#define SQLITE_VERSION "3.38.2"
|
|
548
|
+
#define SQLITE_VERSION_NUMBER 3038002
|
|
549
|
+
#define SQLITE_SOURCE_ID "2022-03-26 13:51:10 d33c709cc0af66bc5b6dc6216eba9f1f0b40960b9ae83694c986fbf4c1d6f08f"
|
|
550
550
|
|
|
551
551
|
/*
|
|
552
552
|
** CAPI3REF: Run-Time Library Version Numbers
|
|
@@ -5377,6 +5377,10 @@ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
|
|
|
5377
5377
|
** even empty strings, are always zero-terminated. ^The return
|
|
5378
5378
|
** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
|
|
5379
5379
|
**
|
|
5380
|
+
** ^Strings returned by sqlite3_column_text16() always have the endianness
|
|
5381
|
+
** which is native to the platform, regardless of the text encoding set
|
|
5382
|
+
** for the database.
|
|
5383
|
+
**
|
|
5380
5384
|
** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an
|
|
5381
5385
|
** [unprotected sqlite3_value] object. In a multithreaded environment,
|
|
5382
5386
|
** an unprotected sqlite3_value object may only be used safely with
|
|
@@ -5390,7 +5394,7 @@ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
|
|
|
5390
5394
|
** [application-defined SQL functions] or [virtual tables], not within
|
|
5391
5395
|
** top-level application code.
|
|
5392
5396
|
**
|
|
5393
|
-
**
|
|
5397
|
+
** These routines may attempt to convert the datatype of the result.
|
|
5394
5398
|
** ^For example, if the internal representation is FLOAT and a text result
|
|
5395
5399
|
** is requested, [sqlite3_snprintf()] is used internally to perform the
|
|
5396
5400
|
** conversion automatically. ^(The following table details the conversions
|
|
@@ -5415,7 +5419,7 @@ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
|
|
|
5415
5419
|
** <tr><td> TEXT <td> BLOB <td> No change
|
|
5416
5420
|
** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER
|
|
5417
5421
|
** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL
|
|
5418
|
-
** <tr><td> BLOB <td> TEXT <td>
|
|
5422
|
+
** <tr><td> BLOB <td> TEXT <td> [CAST] to TEXT, ensure zero terminator
|
|
5419
5423
|
** </table>
|
|
5420
5424
|
** </blockquote>)^
|
|
5421
5425
|
**
|
|
@@ -10165,7 +10169,7 @@ SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut);
|
|
|
10165
10169
|
** ^When xBestIndex returns, the sqlite3_value object returned by
|
|
10166
10170
|
** sqlite3_vtab_rhs_value() is automatically deallocated.
|
|
10167
10171
|
**
|
|
10168
|
-
** The "_rhs_" in the name of this routine is an
|
|
10172
|
+
** The "_rhs_" in the name of this routine is an abbreviation for
|
|
10169
10173
|
** "Right-Hand Side".
|
|
10170
10174
|
*/
|
|
10171
10175
|
SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal);
|
|
@@ -20463,7 +20467,12 @@ SQLITE_PRIVATE int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **);
|
|
|
20463
20467
|
SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse*, Table*);
|
|
20464
20468
|
SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3*, int, const char *);
|
|
20465
20469
|
SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, VTable *);
|
|
20470
|
+
|
|
20466
20471
|
SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
|
|
20472
|
+
#if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \
|
|
20473
|
+
&& !defined(SQLITE_OMIT_VIRTUALTABLE)
|
|
20474
|
+
SQLITE_PRIVATE void sqlite3VtabWriteAll(sqlite3_index_info*);
|
|
20475
|
+
#endif
|
|
20467
20476
|
SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
|
|
20468
20477
|
SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
|
|
20469
20478
|
SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
|
|
@@ -23753,7 +23762,7 @@ static int toLocaltime(
|
|
|
23753
23762
|
p->D = sLocal.tm_mday;
|
|
23754
23763
|
p->h = sLocal.tm_hour;
|
|
23755
23764
|
p->m = sLocal.tm_min;
|
|
23756
|
-
p->s = sLocal.tm_sec;
|
|
23765
|
+
p->s = sLocal.tm_sec + (p->iJD%1000)*0.001;
|
|
23757
23766
|
p->validYMD = 1;
|
|
23758
23767
|
p->validHMS = 1;
|
|
23759
23768
|
p->validJD = 0;
|
|
@@ -39781,11 +39790,17 @@ static int unixShmLock(
|
|
|
39781
39790
|
int flags /* What to do with the lock */
|
|
39782
39791
|
){
|
|
39783
39792
|
unixFile *pDbFd = (unixFile*)fd; /* Connection holding shared memory */
|
|
39784
|
-
unixShm *p
|
|
39785
|
-
unixShmNode *pShmNode
|
|
39793
|
+
unixShm *p; /* The shared memory being locked */
|
|
39794
|
+
unixShmNode *pShmNode; /* The underlying file iNode */
|
|
39786
39795
|
int rc = SQLITE_OK; /* Result code */
|
|
39787
39796
|
u16 mask; /* Mask of locks to take or release */
|
|
39788
|
-
int *aLock
|
|
39797
|
+
int *aLock;
|
|
39798
|
+
|
|
39799
|
+
p = pDbFd->pShm;
|
|
39800
|
+
if( p==0 ) return SQLITE_IOERR_SHMLOCK;
|
|
39801
|
+
pShmNode = p->pShmNode;
|
|
39802
|
+
if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK;
|
|
39803
|
+
aLock = pShmNode->aLock;
|
|
39789
39804
|
|
|
39790
39805
|
assert( pShmNode==pDbFd->pInode->pShmNode );
|
|
39791
39806
|
assert( pShmNode->pInode==pDbFd->pInode );
|
|
@@ -47073,10 +47088,14 @@ static int winShmLock(
|
|
|
47073
47088
|
winFile *pDbFd = (winFile*)fd; /* Connection holding shared memory */
|
|
47074
47089
|
winShm *p = pDbFd->pShm; /* The shared memory being locked */
|
|
47075
47090
|
winShm *pX; /* For looping over all siblings */
|
|
47076
|
-
winShmNode *pShmNode
|
|
47091
|
+
winShmNode *pShmNode;
|
|
47077
47092
|
int rc = SQLITE_OK; /* Result code */
|
|
47078
47093
|
u16 mask; /* Mask of locks to take or release */
|
|
47079
47094
|
|
|
47095
|
+
if( p==0 ) return SQLITE_IOERR_SHMLOCK;
|
|
47096
|
+
pShmNode = p->pShmNode;
|
|
47097
|
+
if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK;
|
|
47098
|
+
|
|
47080
47099
|
assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK );
|
|
47081
47100
|
assert( n>=1 );
|
|
47082
47101
|
assert( flags==(SQLITE_SHM_LOCK | SQLITE_SHM_SHARED)
|
|
@@ -51006,7 +51025,8 @@ SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr *p){
|
|
|
51006
51025
|
** make it so.
|
|
51007
51026
|
*/
|
|
51008
51027
|
SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr *p){
|
|
51009
|
-
assert( p->nRef>0 );
|
|
51028
|
+
assert( p->nRef>0 || p->pCache->bPurgeable==0 );
|
|
51029
|
+
testcase( p->nRef==0 );
|
|
51010
51030
|
assert( sqlite3PcachePageSanity(p) );
|
|
51011
51031
|
if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ /*OPTIMIZATION-IF-FALSE*/
|
|
51012
51032
|
p->flags &= ~PGHDR_DONT_WRITE;
|
|
@@ -56138,6 +56158,9 @@ static int pager_playback(Pager *pPager, int isHot){
|
|
|
56138
56158
|
goto end_playback;
|
|
56139
56159
|
}
|
|
56140
56160
|
pPager->dbSize = mxPg;
|
|
56161
|
+
if( pPager->mxPgno<mxPg ){
|
|
56162
|
+
pPager->mxPgno = mxPg;
|
|
56163
|
+
}
|
|
56141
56164
|
}
|
|
56142
56165
|
|
|
56143
56166
|
/* Copy original pages out of the journal and back into the
|
|
@@ -65497,7 +65520,9 @@ struct MemPage {
|
|
|
65497
65520
|
u8 *apOvfl[4]; /* Pointers to the body of overflow cells */
|
|
65498
65521
|
BtShared *pBt; /* Pointer to BtShared that this page is part of */
|
|
65499
65522
|
u8 *aData; /* Pointer to disk image of the page data */
|
|
65500
|
-
u8 *aDataEnd; /* One byte past the end of
|
|
65523
|
+
u8 *aDataEnd; /* One byte past the end of the entire page - not just
|
|
65524
|
+
** the usable space, the entire page. Used to prevent
|
|
65525
|
+
** corruption-induced of buffer overflow. */
|
|
65501
65526
|
u8 *aCellIdx; /* The cell index area */
|
|
65502
65527
|
u8 *aDataOfst; /* Same as aData for leaves. aData+4 for interior */
|
|
65503
65528
|
DbPage *pDbPage; /* Pager page handle */
|
|
@@ -68282,7 +68307,7 @@ static int btreeInitPage(MemPage *pPage){
|
|
|
68282
68307
|
pPage->nOverflow = 0;
|
|
68283
68308
|
pPage->cellOffset = pPage->hdrOffset + 8 + pPage->childPtrSize;
|
|
68284
68309
|
pPage->aCellIdx = data + pPage->childPtrSize + 8;
|
|
68285
|
-
pPage->aDataEnd = pPage->aData + pBt->
|
|
68310
|
+
pPage->aDataEnd = pPage->aData + pBt->pageSize;
|
|
68286
68311
|
pPage->aDataOfst = pPage->aData + pPage->childPtrSize;
|
|
68287
68312
|
/* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
|
|
68288
68313
|
** number of cells on the page. */
|
|
@@ -68317,7 +68342,7 @@ static void zeroPage(MemPage *pPage, int flags){
|
|
|
68317
68342
|
u8 hdr = pPage->hdrOffset;
|
|
68318
68343
|
u16 first;
|
|
68319
68344
|
|
|
68320
|
-
assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno );
|
|
68345
|
+
assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno || CORRUPT_DB );
|
|
68321
68346
|
assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
|
|
68322
68347
|
assert( sqlite3PagerGetData(pPage->pDbPage) == data );
|
|
68323
68348
|
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
|
|
@@ -68333,7 +68358,7 @@ static void zeroPage(MemPage *pPage, int flags){
|
|
|
68333
68358
|
pPage->nFree = (u16)(pBt->usableSize - first);
|
|
68334
68359
|
decodeFlags(pPage, flags);
|
|
68335
68360
|
pPage->cellOffset = first;
|
|
68336
|
-
pPage->aDataEnd = &data[pBt->
|
|
68361
|
+
pPage->aDataEnd = &data[pBt->pageSize];
|
|
68337
68362
|
pPage->aCellIdx = &data[first];
|
|
68338
68363
|
pPage->aDataOfst = &data[pPage->childPtrSize];
|
|
68339
68364
|
pPage->nOverflow = 0;
|
|
@@ -68459,7 +68484,7 @@ static int getAndInitPage(
|
|
|
68459
68484
|
goto getAndInitPage_error2;
|
|
68460
68485
|
}
|
|
68461
68486
|
}
|
|
68462
|
-
assert( (*ppPage)->pgno==pgno );
|
|
68487
|
+
assert( (*ppPage)->pgno==pgno || CORRUPT_DB );
|
|
68463
68488
|
assert( (*ppPage)->aData==sqlite3PagerGetData(pDbPage) );
|
|
68464
68489
|
|
|
68465
68490
|
/* If obtaining a child page for a cursor, we must verify that the page is
|
|
@@ -71546,7 +71571,7 @@ static int moveToRoot(BtCursor *pCur){
|
|
|
71546
71571
|
pCur->curIntKey = pCur->pPage->intKey;
|
|
71547
71572
|
}
|
|
71548
71573
|
pRoot = pCur->pPage;
|
|
71549
|
-
assert( pRoot->pgno==pCur->pgnoRoot );
|
|
71574
|
+
assert( pRoot->pgno==pCur->pgnoRoot || CORRUPT_DB );
|
|
71550
71575
|
|
|
71551
71576
|
/* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor
|
|
71552
71577
|
** expected to open it on an index b-tree. Otherwise, if pKeyInfo is
|
|
@@ -75077,24 +75102,6 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
|
|
|
75077
75102
|
assert( (flags & (BTREE_SAVEPOSITION|BTREE_APPEND|BTREE_PREFORMAT))==flags );
|
|
75078
75103
|
assert( (flags & BTREE_PREFORMAT)==0 || seekResult || pCur->pKeyInfo==0 );
|
|
75079
75104
|
|
|
75080
|
-
if( pCur->eState==CURSOR_FAULT ){
|
|
75081
|
-
assert( pCur->skipNext!=SQLITE_OK );
|
|
75082
|
-
return pCur->skipNext;
|
|
75083
|
-
}
|
|
75084
|
-
|
|
75085
|
-
assert( cursorOwnsBtShared(pCur) );
|
|
75086
|
-
assert( (pCur->curFlags & BTCF_WriteFlag)!=0
|
|
75087
|
-
&& pBt->inTransaction==TRANS_WRITE
|
|
75088
|
-
&& (pBt->btsFlags & BTS_READ_ONLY)==0 );
|
|
75089
|
-
assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
|
|
75090
|
-
|
|
75091
|
-
/* Assert that the caller has been consistent. If this cursor was opened
|
|
75092
|
-
** expecting an index b-tree, then the caller should be inserting blob
|
|
75093
|
-
** keys with no associated data. If the cursor was opened expecting an
|
|
75094
|
-
** intkey table, the caller should be inserting integer keys with a
|
|
75095
|
-
** blob of associated data. */
|
|
75096
|
-
assert( (flags & BTREE_PREFORMAT) || (pX->pKey==0)==(pCur->pKeyInfo==0) );
|
|
75097
|
-
|
|
75098
75105
|
/* Save the positions of any other cursors open on this table.
|
|
75099
75106
|
**
|
|
75100
75107
|
** In some cases, the call to btreeMoveto() below is a no-op. For
|
|
@@ -75119,6 +75126,24 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
|
|
|
75119
75126
|
}
|
|
75120
75127
|
}
|
|
75121
75128
|
|
|
75129
|
+
if( pCur->eState>=CURSOR_REQUIRESEEK ){
|
|
75130
|
+
rc = moveToRoot(pCur);
|
|
75131
|
+
if( rc && rc!=SQLITE_EMPTY ) return rc;
|
|
75132
|
+
}
|
|
75133
|
+
|
|
75134
|
+
assert( cursorOwnsBtShared(pCur) );
|
|
75135
|
+
assert( (pCur->curFlags & BTCF_WriteFlag)!=0
|
|
75136
|
+
&& pBt->inTransaction==TRANS_WRITE
|
|
75137
|
+
&& (pBt->btsFlags & BTS_READ_ONLY)==0 );
|
|
75138
|
+
assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
|
|
75139
|
+
|
|
75140
|
+
/* Assert that the caller has been consistent. If this cursor was opened
|
|
75141
|
+
** expecting an index b-tree, then the caller should be inserting blob
|
|
75142
|
+
** keys with no associated data. If the cursor was opened expecting an
|
|
75143
|
+
** intkey table, the caller should be inserting integer keys with a
|
|
75144
|
+
** blob of associated data. */
|
|
75145
|
+
assert( (flags & BTREE_PREFORMAT) || (pX->pKey==0)==(pCur->pKeyInfo==0) );
|
|
75146
|
+
|
|
75122
75147
|
if( pCur->pKeyInfo==0 ){
|
|
75123
75148
|
assert( pX->pKey==0 );
|
|
75124
75149
|
/* If this is an insert into a table b-tree, invalidate any incrblob
|
|
@@ -75207,14 +75232,13 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
|
|
|
75207
75232
|
}
|
|
75208
75233
|
}
|
|
75209
75234
|
assert( pCur->eState==CURSOR_VALID
|
|
75210
|
-
|| (pCur->eState==CURSOR_INVALID && loc)
|
|
75211
|
-
|| CORRUPT_DB );
|
|
75235
|
+
|| (pCur->eState==CURSOR_INVALID && loc) );
|
|
75212
75236
|
|
|
75213
75237
|
pPage = pCur->pPage;
|
|
75214
75238
|
assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
|
|
75215
75239
|
assert( pPage->leaf || !pPage->intKey );
|
|
75216
75240
|
if( pPage->nFree<0 ){
|
|
75217
|
-
if(
|
|
75241
|
+
if( pCur->eState>CURSOR_INVALID ){
|
|
75218
75242
|
rc = SQLITE_CORRUPT_BKPT;
|
|
75219
75243
|
}else{
|
|
75220
75244
|
rc = btreeComputeFreeSpace(pPage);
|
|
@@ -75495,12 +75519,16 @@ SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
|
|
|
75495
75519
|
assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
|
|
75496
75520
|
assert( !hasReadConflicts(p, pCur->pgnoRoot) );
|
|
75497
75521
|
assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
|
|
75498
|
-
if( pCur->eState
|
|
75499
|
-
|
|
75500
|
-
|
|
75501
|
-
|
|
75522
|
+
if( pCur->eState!=CURSOR_VALID ){
|
|
75523
|
+
if( pCur->eState>=CURSOR_REQUIRESEEK ){
|
|
75524
|
+
rc = btreeRestoreCursorPosition(pCur);
|
|
75525
|
+
assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID );
|
|
75526
|
+
if( rc || pCur->eState!=CURSOR_VALID ) return rc;
|
|
75527
|
+
}else{
|
|
75528
|
+
return SQLITE_CORRUPT_BKPT;
|
|
75529
|
+
}
|
|
75502
75530
|
}
|
|
75503
|
-
assert(
|
|
75531
|
+
assert( pCur->eState==CURSOR_VALID );
|
|
75504
75532
|
|
|
75505
75533
|
iCellDepth = pCur->iPage;
|
|
75506
75534
|
iCellIdx = pCur->ix;
|
|
@@ -78835,6 +78863,7 @@ SQLITE_PRIVATE void sqlite3VdbeMemSetPointer(
|
|
|
78835
78863
|
void (*xDestructor)(void*)
|
|
78836
78864
|
){
|
|
78837
78865
|
assert( pMem->flags==MEM_Null );
|
|
78866
|
+
vdbeMemClear(pMem);
|
|
78838
78867
|
pMem->u.zPType = zPType ? zPType : "";
|
|
78839
78868
|
pMem->z = pPtr;
|
|
78840
78869
|
pMem->flags = MEM_Null|MEM_Dyn|MEM_Subtype|MEM_Term;
|
|
@@ -90089,10 +90118,18 @@ case OP_Offset: { /* out3 */
|
|
|
90089
90118
|
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
|
|
90090
90119
|
pC = p->apCsr[pOp->p1];
|
|
90091
90120
|
pOut = &p->aMem[pOp->p3];
|
|
90092
|
-
if(
|
|
90121
|
+
if( pC==0 || pC->eCurType!=CURTYPE_BTREE ){
|
|
90093
90122
|
sqlite3VdbeMemSetNull(pOut);
|
|
90094
90123
|
}else{
|
|
90095
|
-
|
|
90124
|
+
if( pC->deferredMoveto ){
|
|
90125
|
+
rc = sqlite3VdbeFinishMoveto(pC);
|
|
90126
|
+
if( rc ) goto abort_due_to_error;
|
|
90127
|
+
}
|
|
90128
|
+
if( sqlite3BtreeEof(pC->uc.pCursor) ){
|
|
90129
|
+
sqlite3VdbeMemSetNull(pOut);
|
|
90130
|
+
}else{
|
|
90131
|
+
sqlite3VdbeMemSetInt64(pOut, sqlite3BtreeOffset(pC->uc.pCursor));
|
|
90132
|
+
}
|
|
90096
90133
|
}
|
|
90097
90134
|
break;
|
|
90098
90135
|
}
|
|
@@ -93171,6 +93208,10 @@ case OP_Rowid: { /* out2 */
|
|
|
93171
93208
|
** Move the cursor P1 to a null row. Any OP_Column operations
|
|
93172
93209
|
** that occur while the cursor is on the null row will always
|
|
93173
93210
|
** write a NULL.
|
|
93211
|
+
**
|
|
93212
|
+
** Or, if P1 is a Pseudo-Cursor (a cursor opened using OP_OpenPseudo)
|
|
93213
|
+
** just reset the cache for that cursor. This causes the row of
|
|
93214
|
+
** content held by the pseudo-cursor to be reparsed.
|
|
93174
93215
|
*/
|
|
93175
93216
|
case OP_NullRow: {
|
|
93176
93217
|
VdbeCursor *pC;
|
|
@@ -110017,19 +110058,21 @@ static int renameParseSql(
|
|
|
110017
110058
|
){
|
|
110018
110059
|
int rc;
|
|
110019
110060
|
|
|
110020
|
-
db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb);
|
|
110021
|
-
|
|
110022
|
-
/* Parse the SQL statement passed as the first argument. If no error
|
|
110023
|
-
** occurs and the parse does not result in a new table, index or
|
|
110024
|
-
** trigger object, the database must be corrupt. */
|
|
110025
110061
|
sqlite3ParseObjectInit(p, db);
|
|
110062
|
+
if( zSql==0 ){
|
|
110063
|
+
return SQLITE_NOMEM;
|
|
110064
|
+
}
|
|
110065
|
+
if( sqlite3StrNICmp(zSql,"CREATE ",7)!=0 ){
|
|
110066
|
+
return SQLITE_CORRUPT_BKPT;
|
|
110067
|
+
}
|
|
110068
|
+
db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb);
|
|
110026
110069
|
p->eParseMode = PARSE_MODE_RENAME;
|
|
110027
110070
|
p->db = db;
|
|
110028
110071
|
p->nQueryLoop = 1;
|
|
110029
|
-
rc =
|
|
110072
|
+
rc = sqlite3RunParser(p, zSql);
|
|
110030
110073
|
if( db->mallocFailed ) rc = SQLITE_NOMEM;
|
|
110031
110074
|
if( rc==SQLITE_OK
|
|
110032
|
-
&& p->pNewTable==0 && p->pNewIndex==0 && p->pNewTrigger==0
|
|
110075
|
+
&& NEVER(p->pNewTable==0 && p->pNewIndex==0 && p->pNewTrigger==0)
|
|
110033
110076
|
){
|
|
110034
110077
|
rc = SQLITE_CORRUPT_BKPT;
|
|
110035
110078
|
}
|
|
@@ -116783,6 +116826,11 @@ SQLITE_PRIVATE void sqlite3EndTable(
|
|
|
116783
116826
|
int addrInsLoop; /* Top of the loop for inserting rows */
|
|
116784
116827
|
Table *pSelTab; /* A table that describes the SELECT results */
|
|
116785
116828
|
|
|
116829
|
+
if( IN_SPECIAL_PARSE ){
|
|
116830
|
+
pParse->rc = SQLITE_ERROR;
|
|
116831
|
+
pParse->nErr++;
|
|
116832
|
+
return;
|
|
116833
|
+
}
|
|
116786
116834
|
regYield = ++pParse->nMem;
|
|
116787
116835
|
regRec = ++pParse->nMem;
|
|
116788
116836
|
regRowid = ++pParse->nMem;
|
|
@@ -123362,8 +123410,8 @@ SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(void){
|
|
|
123362
123410
|
INLINE_FUNC(likelihood, 2, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
|
|
123363
123411
|
INLINE_FUNC(likely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
|
|
123364
123412
|
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
|
|
123365
|
-
|
|
123366
|
-
|
|
123413
|
+
{1, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_OFFSET|SQLITE_FUNC_TYPEOF,
|
|
123414
|
+
0, 0, noopFunc, 0, 0, 0, "sqlite_offset", {0} },
|
|
123367
123415
|
#endif
|
|
123368
123416
|
FUNCTION(ltrim, 1, 1, 0, trimFunc ),
|
|
123369
123417
|
FUNCTION(ltrim, 2, 1, 0, trimFunc ),
|
|
@@ -125167,7 +125215,7 @@ SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){
|
|
|
125167
125215
|
}
|
|
125168
125216
|
|
|
125169
125217
|
for(i=j=0; i<pTab->nCol; i++){
|
|
125170
|
-
assert( pTab->aCol[i].affinity!=0 );
|
|
125218
|
+
assert( pTab->aCol[i].affinity!=0 || sqlite3VdbeParser(v)->nErr>0 );
|
|
125171
125219
|
if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){
|
|
125172
125220
|
zColAff[j++] = pTab->aCol[i].affinity;
|
|
125173
125221
|
}
|
|
@@ -125781,7 +125829,11 @@ SQLITE_PRIVATE void sqlite3Insert(
|
|
|
125781
125829
|
**
|
|
125782
125830
|
** This is the 2nd template.
|
|
125783
125831
|
*/
|
|
125784
|
-
if( pColumn==0
|
|
125832
|
+
if( pColumn==0
|
|
125833
|
+
&& pSelect!=0
|
|
125834
|
+
&& pTrigger==0
|
|
125835
|
+
&& xferOptimization(pParse, pTab, pSelect, onError, iDb)
|
|
125836
|
+
){
|
|
125785
125837
|
assert( !pTrigger );
|
|
125786
125838
|
assert( pList==0 );
|
|
125787
125839
|
goto insert_end;
|
|
@@ -127752,18 +127804,13 @@ static int xferOptimization(
|
|
|
127752
127804
|
int destHasUniqueIdx = 0; /* True if pDest has a UNIQUE index */
|
|
127753
127805
|
int regData, regRowid; /* Registers holding data and rowid */
|
|
127754
127806
|
|
|
127755
|
-
|
|
127756
|
-
return 0; /* Must be of the form INSERT INTO ... SELECT ... */
|
|
127757
|
-
}
|
|
127807
|
+
assert( pSelect!=0 );
|
|
127758
127808
|
if( pParse->pWith || pSelect->pWith ){
|
|
127759
127809
|
/* Do not attempt to process this query if there are an WITH clauses
|
|
127760
127810
|
** attached to it. Proceeding may generate a false "no such table: xxx"
|
|
127761
127811
|
** error if pSelect reads from a CTE named "xxx". */
|
|
127762
127812
|
return 0;
|
|
127763
127813
|
}
|
|
127764
|
-
if( sqlite3TriggerList(pParse, pDest) ){
|
|
127765
|
-
return 0; /* tab1 must not have triggers */
|
|
127766
|
-
}
|
|
127767
127814
|
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
|
127768
127815
|
if( IsVirtual(pDest) ){
|
|
127769
127816
|
return 0; /* tab1 must not be a virtual table */
|
|
@@ -133609,7 +133656,7 @@ SQLITE_PRIVATE int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg, u32 mFl
|
|
|
133609
133656
|
sqlite3ResetAllSchemasOfConnection(db);
|
|
133610
133657
|
pDb = &db->aDb[iDb];
|
|
133611
133658
|
}else
|
|
133612
|
-
if( rc==SQLITE_OK || (db->flags&SQLITE_NoSchemaError)){
|
|
133659
|
+
if( rc==SQLITE_OK || ((db->flags&SQLITE_NoSchemaError) && rc!=SQLITE_NOMEM)){
|
|
133613
133660
|
/* Hack: If the SQLITE_NoSchemaError flag is set, then consider
|
|
133614
133661
|
** the schema loaded, even if errors (other than OOM) occurred. In
|
|
133615
133662
|
** this situation the current sqlite3_prepare() operation will fail,
|
|
@@ -142476,6 +142523,7 @@ static TriggerStep *triggerStepAllocate(
|
|
|
142476
142523
|
sqlite3 *db = pParse->db;
|
|
142477
142524
|
TriggerStep *pTriggerStep;
|
|
142478
142525
|
|
|
142526
|
+
if( pParse->nErr ) return 0;
|
|
142479
142527
|
pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1);
|
|
142480
142528
|
if( pTriggerStep ){
|
|
142481
142529
|
char *z = (char*)&pTriggerStep[1];
|
|
@@ -146354,6 +146402,7 @@ SQLITE_API int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
|
|
|
146354
146402
|
|
|
146355
146403
|
sqlite3ParseObjectInit(&sParse, db);
|
|
146356
146404
|
sParse.eParseMode = PARSE_MODE_DECLARE_VTAB;
|
|
146405
|
+
sParse.disableTriggers = 1;
|
|
146357
146406
|
/* We should never be able to reach this point while loading the
|
|
146358
146407
|
** schema. Nevertheless, defend against that (turn off db->init.busy)
|
|
146359
146408
|
** in case a bug arises. */
|
|
@@ -148289,6 +148338,7 @@ static int codeAllEqualityTerms(
|
|
|
148289
148338
|
VdbeCoverageIf(v, bRev!=0);
|
|
148290
148339
|
VdbeComment((v, "begin skip-scan on %s", pIdx->zName));
|
|
148291
148340
|
j = sqlite3VdbeAddOp0(v, OP_Goto);
|
|
148341
|
+
assert( pLevel->addrSkip==0 );
|
|
148292
148342
|
pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLT:OP_SeekGT),
|
|
148293
148343
|
iIdxCur, 0, regBase, nSkip);
|
|
148294
148344
|
VdbeCoverageIf(v, bRev==0);
|
|
@@ -148886,6 +148936,7 @@ static SQLITE_NOINLINE void filterPullDown(
|
|
|
148886
148936
|
WhereLevel *pLevel = &pWInfo->a[iLevel];
|
|
148887
148937
|
WhereLoop *pLoop = pLevel->pWLoop;
|
|
148888
148938
|
if( pLevel->regFilter==0 ) continue;
|
|
148939
|
+
if( pLevel->pWLoop->nSkip ) continue;
|
|
148889
148940
|
/* ,--- Because sqlite3ConstructBloomFilter() has will not have set
|
|
148890
148941
|
** vvvvv--' pLevel->regFilter if this were true. */
|
|
148891
148942
|
if( NEVER(pLoop->prereq & notReady) ) continue;
|
|
@@ -149020,7 +149071,6 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
|
|
|
149020
149071
|
int iReg; /* P3 Value for OP_VFilter */
|
|
149021
149072
|
int addrNotFound;
|
|
149022
149073
|
int nConstraint = pLoop->nLTerm;
|
|
149023
|
-
int iIn; /* Counter for IN constraints */
|
|
149024
149074
|
|
|
149025
149075
|
iReg = sqlite3GetTempRange(pParse, nConstraint+2);
|
|
149026
149076
|
addrNotFound = pLevel->addrBrk;
|
|
@@ -149066,50 +149116,54 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
|
|
|
149066
149116
|
pLevel->op = pWInfo->eOnePass ? OP_Noop : OP_VNext;
|
|
149067
149117
|
pLevel->p2 = sqlite3VdbeCurrentAddr(v);
|
|
149068
149118
|
assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
|
|
149069
|
-
|
|
149070
|
-
|
|
149071
|
-
}else{
|
|
149072
|
-
iIn = 0;
|
|
149073
|
-
}
|
|
149074
|
-
for(j=nConstraint-1; j>=0; j--){
|
|
149075
|
-
int bIn; /* True to generate byte code to loop over RHS IN values */
|
|
149119
|
+
|
|
149120
|
+
for(j=0; j<nConstraint; j++){
|
|
149076
149121
|
pTerm = pLoop->aLTerm[j];
|
|
149122
|
+
if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){
|
|
149123
|
+
disableTerm(pLevel, pTerm);
|
|
149124
|
+
continue;
|
|
149125
|
+
}
|
|
149077
149126
|
if( (pTerm->eOperator & WO_IN)!=0
|
|
149078
149127
|
&& (SMASKBIT32(j) & pLoop->u.vtab.mHandleIn)==0
|
|
149128
|
+
&& !db->mallocFailed
|
|
149079
149129
|
){
|
|
149080
|
-
bIn = 1;
|
|
149081
|
-
}else{
|
|
149082
|
-
bIn = 0;
|
|
149083
|
-
}
|
|
149084
|
-
if( bIn ) iIn--;
|
|
149085
|
-
if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){
|
|
149086
|
-
disableTerm(pLevel, pTerm);
|
|
149087
|
-
}else if( bIn && sqlite3ExprVectorSize(pTerm->pExpr->pLeft)==1 ){
|
|
149088
149130
|
Expr *pCompare; /* The comparison operator */
|
|
149089
149131
|
Expr *pRight; /* RHS of the comparison */
|
|
149090
149132
|
VdbeOp *pOp; /* Opcode to access the value of the IN constraint */
|
|
149133
|
+
int iIn; /* IN loop corresponding to the j-th constraint */
|
|
149091
149134
|
|
|
149092
149135
|
/* Reload the constraint value into reg[iReg+j+2]. The same value
|
|
149093
149136
|
** was loaded into the same register prior to the OP_VFilter, but
|
|
149094
149137
|
** the xFilter implementation might have changed the datatype or
|
|
149095
|
-
** encoding of the value in the register, so it *must* be reloaded.
|
|
149096
|
-
|
|
149097
|
-
|
|
149098
|
-
assert( iIn>=0 && iIn<pLevel->u.in.nIn );
|
|
149138
|
+
** encoding of the value in the register, so it *must* be reloaded.
|
|
149139
|
+
*/
|
|
149140
|
+
for(iIn=0; ALWAYS(iIn<pLevel->u.in.nIn); iIn++){
|
|
149099
149141
|
pOp = sqlite3VdbeGetOp(v, pLevel->u.in.aInLoop[iIn].addrInTop);
|
|
149100
|
-
|
|
149101
|
-
|
|
149102
|
-
|
|
149103
|
-
|
|
149104
|
-
|
|
149142
|
+
if( (pOp->opcode==OP_Column && pOp->p3==iReg+j+2)
|
|
149143
|
+
|| (pOp->opcode==OP_Rowid && pOp->p2==iReg+j+2)
|
|
149144
|
+
){
|
|
149145
|
+
testcase( pOp->opcode==OP_Rowid );
|
|
149146
|
+
sqlite3VdbeAddOp3(v, pOp->opcode, pOp->p1, pOp->p2, pOp->p3);
|
|
149147
|
+
break;
|
|
149148
|
+
}
|
|
149105
149149
|
}
|
|
149106
149150
|
|
|
149107
149151
|
/* Generate code that will continue to the next row if
|
|
149108
|
-
** the IN constraint is not satisfied
|
|
149152
|
+
** the IN constraint is not satisfied
|
|
149153
|
+
*/
|
|
149109
149154
|
pCompare = sqlite3PExpr(pParse, TK_EQ, 0, 0);
|
|
149110
|
-
|
|
149111
|
-
|
|
149112
|
-
|
|
149155
|
+
if( !db->mallocFailed ){
|
|
149156
|
+
int iFld = pTerm->u.x.iField;
|
|
149157
|
+
Expr *pLeft = pTerm->pExpr->pLeft;
|
|
149158
|
+
assert( pLeft!=0 );
|
|
149159
|
+
if( iFld>0 ){
|
|
149160
|
+
assert( pLeft->op==TK_VECTOR );
|
|
149161
|
+
assert( ExprUseXList(pLeft) );
|
|
149162
|
+
assert( iFld<=pLeft->x.pList->nExpr );
|
|
149163
|
+
pCompare->pLeft = pLeft->x.pList->a[iFld-1].pExpr;
|
|
149164
|
+
}else{
|
|
149165
|
+
pCompare->pLeft = pLeft;
|
|
149166
|
+
}
|
|
149113
149167
|
pCompare->pRight = pRight = sqlite3Expr(db, TK_REGISTER, 0);
|
|
149114
149168
|
if( pRight ){
|
|
149115
149169
|
pRight->iTable = iReg+j+2;
|
|
@@ -149118,11 +149172,11 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
|
|
|
149118
149172
|
);
|
|
149119
149173
|
}
|
|
149120
149174
|
pCompare->pLeft = 0;
|
|
149121
|
-
sqlite3ExprDelete(db, pCompare);
|
|
149122
149175
|
}
|
|
149176
|
+
sqlite3ExprDelete(db, pCompare);
|
|
149123
149177
|
}
|
|
149124
149178
|
}
|
|
149125
|
-
|
|
149179
|
+
|
|
149126
149180
|
/* These registers need to be preserved in case there is an IN operator
|
|
149127
149181
|
** loop. So we could deallocate the registers here (and potentially
|
|
149128
149182
|
** reuse them later) if (pLoop->wsFlags & WHERE_IN_ABLE)==0. But it seems
|
|
@@ -149832,6 +149886,14 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
|
|
|
149832
149886
|
** the initialization of the right-hand operand of the vector comparison
|
|
149833
149887
|
** might not occur, or might occur only in an OR branch that is not
|
|
149834
149888
|
** taken. dbsqlfuzz 80a9fade844b4fb43564efc972bcb2c68270f5d1.
|
|
149889
|
+
**
|
|
149890
|
+
** 2022-03-03: Do not push down expressions that involve subqueries.
|
|
149891
|
+
** The subquery might get coded as a subroutine. Any table-references
|
|
149892
|
+
** in the subquery might be resolved to index-references for the index on
|
|
149893
|
+
** the OR branch in which the subroutine is coded. But if the subroutine
|
|
149894
|
+
** is invoked from a different OR branch that uses a different index, such
|
|
149895
|
+
** index-references will not work. tag-20220303a
|
|
149896
|
+
** https://sqlite.org/forum/forumpost/36937b197273d403
|
|
149835
149897
|
*/
|
|
149836
149898
|
if( pWC->nTerm>1 ){
|
|
149837
149899
|
int iTerm;
|
|
@@ -149845,7 +149907,7 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
|
|
|
149845
149907
|
continue;
|
|
149846
149908
|
}
|
|
149847
149909
|
if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
|
|
149848
|
-
|
|
149910
|
+
if( ExprHasProperty(pExpr, EP_Subquery) ) continue; /* tag-20220303a */
|
|
149849
149911
|
pExpr = sqlite3ExprDup(db, pExpr, 0);
|
|
149850
149912
|
pAndExpr = sqlite3ExprAnd(pParse, pAndExpr, pExpr);
|
|
149851
149913
|
}
|
|
@@ -153122,7 +153184,10 @@ static SQLITE_NOINLINE void sqlite3ConstructBloomFilter(
|
|
|
153122
153184
|
pLoop->wsFlags &= ~WHERE_BLOOMFILTER;
|
|
153123
153185
|
if( OptimizationDisabled(pParse->db, SQLITE_BloomPulldown) ) break;
|
|
153124
153186
|
while( ++iLevel < pWInfo->nLevel ){
|
|
153187
|
+
const SrcItem *pTabItem;
|
|
153125
153188
|
pLevel = &pWInfo->a[iLevel];
|
|
153189
|
+
pTabItem = &pWInfo->pTabList->a[pLevel->iFrom];
|
|
153190
|
+
if( pTabItem->fg.jointype & JT_LEFT ) continue;
|
|
153126
153191
|
pLoop = pLevel->pWLoop;
|
|
153127
153192
|
if( NEVER(pLoop==0) ) continue;
|
|
153128
153193
|
if( pLoop->prereq & notReady ) continue;
|
|
@@ -154635,8 +154700,17 @@ static void whereLoopOutputAdjust(
|
|
|
154635
154700
|
/* If there are extra terms in the WHERE clause not used by an index
|
|
154636
154701
|
** that depend only on the table being scanned, and that will tend to
|
|
154637
154702
|
** cause many rows to be omitted, then mark that table as
|
|
154638
|
-
** "self-culling".
|
|
154639
|
-
|
|
154703
|
+
** "self-culling".
|
|
154704
|
+
**
|
|
154705
|
+
** 2022-03-24: Self-culling only applies if either the extra terms
|
|
154706
|
+
** are straight comparison operators that are non-true with NULL
|
|
154707
|
+
** operand, or if the loop is not a LEFT JOIN.
|
|
154708
|
+
*/
|
|
154709
|
+
if( (pTerm->eOperator & 0x3f)!=0
|
|
154710
|
+
|| (pWC->pWInfo->pTabList->a[pLoop->iTab].fg.jointype & JT_LEFT)==0
|
|
154711
|
+
){
|
|
154712
|
+
pLoop->wsFlags |= WHERE_SELFCULL;
|
|
154713
|
+
}
|
|
154640
154714
|
}
|
|
154641
154715
|
if( pTerm->truthProb<=0 ){
|
|
154642
154716
|
/* If a truth probability is specified using the likelihood() hints,
|
|
@@ -155805,7 +155879,6 @@ SQLITE_API int sqlite3_vtab_rhs_value(
|
|
|
155805
155879
|
return rc;
|
|
155806
155880
|
}
|
|
155807
155881
|
|
|
155808
|
-
|
|
155809
155882
|
/*
|
|
155810
155883
|
** Return true if ORDER BY clause may be handled as DISTINCT.
|
|
155811
155884
|
*/
|
|
@@ -155817,6 +155890,22 @@ SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info *pIdxInfo){
|
|
|
155817
155890
|
return pHidden->eDistinct;
|
|
155818
155891
|
}
|
|
155819
155892
|
|
|
155893
|
+
#if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \
|
|
155894
|
+
&& !defined(SQLITE_OMIT_VIRTUALTABLE)
|
|
155895
|
+
/*
|
|
155896
|
+
** Cause the prepared statement that is associated with a call to
|
|
155897
|
+
** xBestIndex to open write transactions on all attached schemas.
|
|
155898
|
+
** This is used by the (built-in) sqlite_dbpage virtual table.
|
|
155899
|
+
*/
|
|
155900
|
+
SQLITE_PRIVATE void sqlite3VtabWriteAll(sqlite3_index_info *pIdxInfo){
|
|
155901
|
+
HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
|
|
155902
|
+
Parse *pParse = pHidden->pParse;
|
|
155903
|
+
int nDb = pParse->db->nDb;
|
|
155904
|
+
int i;
|
|
155905
|
+
for(i=0; i<nDb; i++) sqlite3BeginWriteOperation(pParse, 0, i);
|
|
155906
|
+
}
|
|
155907
|
+
#endif
|
|
155908
|
+
|
|
155820
155909
|
/*
|
|
155821
155910
|
** Add all WhereLoop objects for a table of the join identified by
|
|
155822
155911
|
** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
|
|
@@ -157920,6 +158009,26 @@ whereBeginError:
|
|
|
157920
158009
|
}
|
|
157921
158010
|
#endif
|
|
157922
158011
|
|
|
158012
|
+
#ifdef SQLITE_DEBUG
|
|
158013
|
+
/*
|
|
158014
|
+
** Return true if cursor iCur is opened by instruction k of the
|
|
158015
|
+
** bytecode. Used inside of assert() only.
|
|
158016
|
+
*/
|
|
158017
|
+
static int cursorIsOpen(Vdbe *v, int iCur, int k){
|
|
158018
|
+
while( k>=0 ){
|
|
158019
|
+
VdbeOp *pOp = sqlite3VdbeGetOp(v,k--);
|
|
158020
|
+
if( pOp->p1!=iCur ) continue;
|
|
158021
|
+
if( pOp->opcode==OP_Close ) return 0;
|
|
158022
|
+
if( pOp->opcode==OP_OpenRead ) return 1;
|
|
158023
|
+
if( pOp->opcode==OP_OpenWrite ) return 1;
|
|
158024
|
+
if( pOp->opcode==OP_OpenDup ) return 1;
|
|
158025
|
+
if( pOp->opcode==OP_OpenAutoindex ) return 1;
|
|
158026
|
+
if( pOp->opcode==OP_OpenEphemeral ) return 1;
|
|
158027
|
+
}
|
|
158028
|
+
return 0;
|
|
158029
|
+
}
|
|
158030
|
+
#endif /* SQLITE_DEBUG */
|
|
158031
|
+
|
|
157923
158032
|
/*
|
|
157924
158033
|
** Generate the end of the WHERE loop. See comments on
|
|
157925
158034
|
** sqlite3WhereBegin() for additional information.
|
|
@@ -158172,6 +158281,11 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){
|
|
|
158172
158281
|
){
|
|
158173
158282
|
int x = pOp->p2;
|
|
158174
158283
|
assert( pIdx->pTable==pTab );
|
|
158284
|
+
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
|
|
158285
|
+
if( pOp->opcode==OP_Offset ){
|
|
158286
|
+
/* Do not need to translate the column number */
|
|
158287
|
+
}else
|
|
158288
|
+
#endif
|
|
158175
158289
|
if( !HasRowid(pTab) ){
|
|
158176
158290
|
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
|
|
158177
158291
|
x = pPk->aiColumn[x];
|
|
@@ -158185,9 +158299,22 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){
|
|
|
158185
158299
|
pOp->p2 = x;
|
|
158186
158300
|
pOp->p1 = pLevel->iIdxCur;
|
|
158187
158301
|
OpcodeRewriteTrace(db, k, pOp);
|
|
158302
|
+
}else{
|
|
158303
|
+
/* Unable to translate the table reference into an index
|
|
158304
|
+
** reference. Verify that this is harmless - that the
|
|
158305
|
+
** table being referenced really is open.
|
|
158306
|
+
*/
|
|
158307
|
+
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
|
|
158308
|
+
assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
|
|
158309
|
+
|| cursorIsOpen(v,pOp->p1,k)
|
|
158310
|
+
|| pOp->opcode==OP_Offset
|
|
158311
|
+
);
|
|
158312
|
+
#else
|
|
158313
|
+
assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
|
|
158314
|
+
|| cursorIsOpen(v,pOp->p1,k)
|
|
158315
|
+
);
|
|
158316
|
+
#endif
|
|
158188
158317
|
}
|
|
158189
|
-
assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0
|
|
158190
|
-
|| pWInfo->eOnePass );
|
|
158191
158318
|
}else if( pOp->opcode==OP_Rowid ){
|
|
158192
158319
|
pOp->p1 = pLevel->iIdxCur;
|
|
158193
158320
|
pOp->opcode = OP_IdxRowid;
|
|
@@ -159175,7 +159302,11 @@ static int disallowAggregatesInOrderByCb(Walker *pWalker, Expr *pExpr){
|
|
|
159175
159302
|
*/
|
|
159176
159303
|
SQLITE_PRIVATE int sqlite3WindowRewrite(Parse *pParse, Select *p){
|
|
159177
159304
|
int rc = SQLITE_OK;
|
|
159178
|
-
if( p->pWin
|
|
159305
|
+
if( p->pWin
|
|
159306
|
+
&& p->pPrior==0
|
|
159307
|
+
&& ALWAYS((p->selFlags & SF_WinRewrite)==0)
|
|
159308
|
+
&& ALWAYS(!IN_RENAME_OBJECT)
|
|
159309
|
+
){
|
|
159179
159310
|
Vdbe *v = sqlite3GetVdbe(pParse);
|
|
159180
159311
|
sqlite3 *db = pParse->db;
|
|
159181
159312
|
Select *pSub = 0; /* The subquery */
|
|
@@ -159250,6 +159381,7 @@ SQLITE_PRIVATE int sqlite3WindowRewrite(Parse *pParse, Select *p){
|
|
|
159250
159381
|
for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
|
|
159251
159382
|
ExprList *pArgs;
|
|
159252
159383
|
assert( ExprUseXList(pWin->pOwner) );
|
|
159384
|
+
assert( pWin->pFunc!=0 );
|
|
159253
159385
|
pArgs = pWin->pOwner->x.pList;
|
|
159254
159386
|
if( pWin->pFunc->funcFlags & SQLITE_FUNC_SUBTYPE ){
|
|
159255
159387
|
selectWindowRewriteEList(pParse, pMWin, pSrc, pArgs, pTab, &pSublist);
|
|
@@ -210066,6 +210198,7 @@ static int dbpageBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
|
|
210066
210198
|
){
|
|
210067
210199
|
pIdxInfo->orderByConsumed = 1;
|
|
210068
210200
|
}
|
|
210201
|
+
sqlite3VtabWriteAll(pIdxInfo);
|
|
210069
210202
|
return SQLITE_OK;
|
|
210070
210203
|
}
|
|
210071
210204
|
|
|
@@ -232420,7 +232553,7 @@ static int fts5SorterNext(Fts5Cursor *pCsr){
|
|
|
232420
232553
|
rc = sqlite3_step(pSorter->pStmt);
|
|
232421
232554
|
if( rc==SQLITE_DONE ){
|
|
232422
232555
|
rc = SQLITE_OK;
|
|
232423
|
-
CsrFlagSet(pCsr, FTS5CSR_EOF);
|
|
232556
|
+
CsrFlagSet(pCsr, FTS5CSR_EOF|FTS5CSR_REQUIRE_CONTENT);
|
|
232424
232557
|
}else if( rc==SQLITE_ROW ){
|
|
232425
232558
|
const u8 *a;
|
|
232426
232559
|
const u8 *aBlob;
|
|
@@ -234409,7 +234542,7 @@ static void fts5SourceIdFunc(
|
|
|
234409
234542
|
){
|
|
234410
234543
|
assert( nArg==0 );
|
|
234411
234544
|
UNUSED_PARAM2(nArg, apUnused);
|
|
234412
|
-
sqlite3_result_text(pCtx, "fts5: 2022-
|
|
234545
|
+
sqlite3_result_text(pCtx, "fts5: 2022-03-26 13:51:10 d33c709cc0af66bc5b6dc6216eba9f1f0b40960b9ae83694c986fbf4c1d6f08f", -1, SQLITE_TRANSIENT);
|
|
234413
234546
|
}
|
|
234414
234547
|
|
|
234415
234548
|
/*
|
|
@@ -239527,7 +239660,7 @@ SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
|
|
|
239527
239660
|
** Purpose: SQLite3 Multiple Ciphers version numbers
|
|
239528
239661
|
** Author: Ulrich Telle
|
|
239529
239662
|
** Created: 2020-08-05
|
|
239530
|
-
** Copyright: (c) 2020-
|
|
239663
|
+
** Copyright: (c) 2020-2022 Ulrich Telle
|
|
239531
239664
|
** License: MIT
|
|
239532
239665
|
*/
|
|
239533
239666
|
|
|
@@ -239537,10 +239670,10 @@ SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
|
|
|
239537
239670
|
#define SQLITE3MC_VERSION_H_
|
|
239538
239671
|
|
|
239539
239672
|
#define SQLITE3MC_VERSION_MAJOR 1
|
|
239540
|
-
#define SQLITE3MC_VERSION_MINOR
|
|
239541
|
-
#define SQLITE3MC_VERSION_RELEASE
|
|
239673
|
+
#define SQLITE3MC_VERSION_MINOR 4
|
|
239674
|
+
#define SQLITE3MC_VERSION_RELEASE 0
|
|
239542
239675
|
#define SQLITE3MC_VERSION_SUBRELEASE 0
|
|
239543
|
-
#define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.
|
|
239676
|
+
#define SQLITE3MC_VERSION_STRING "SQLite3 Multiple Ciphers 1.4.0"
|
|
239544
239677
|
|
|
239545
239678
|
#endif /* SQLITE3MC_VERSION_H_ */
|
|
239546
239679
|
/*** End of #include "sqlite3mc_version.h" ***/
|
|
@@ -239699,9 +239832,9 @@ extern "C" {
|
|
|
239699
239832
|
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
|
|
239700
239833
|
** [sqlite_version()] and [sqlite_source_id()].
|
|
239701
239834
|
*/
|
|
239702
|
-
#define SQLITE_VERSION "3.38.
|
|
239703
|
-
#define SQLITE_VERSION_NUMBER
|
|
239704
|
-
#define SQLITE_SOURCE_ID "2022-
|
|
239835
|
+
#define SQLITE_VERSION "3.38.2"
|
|
239836
|
+
#define SQLITE_VERSION_NUMBER 3038002
|
|
239837
|
+
#define SQLITE_SOURCE_ID "2022-03-26 13:51:10 d33c709cc0af66bc5b6dc6216eba9f1f0b40960b9ae83694c986fbf4c1d6f08f"
|
|
239705
239838
|
|
|
239706
239839
|
/*
|
|
239707
239840
|
** CAPI3REF: Run-Time Library Version Numbers
|
|
@@ -244532,6 +244665,10 @@ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
|
|
|
244532
244665
|
** even empty strings, are always zero-terminated. ^The return
|
|
244533
244666
|
** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
|
|
244534
244667
|
**
|
|
244668
|
+
** ^Strings returned by sqlite3_column_text16() always have the endianness
|
|
244669
|
+
** which is native to the platform, regardless of the text encoding set
|
|
244670
|
+
** for the database.
|
|
244671
|
+
**
|
|
244535
244672
|
** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an
|
|
244536
244673
|
** [unprotected sqlite3_value] object. In a multithreaded environment,
|
|
244537
244674
|
** an unprotected sqlite3_value object may only be used safely with
|
|
@@ -244545,7 +244682,7 @@ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
|
|
|
244545
244682
|
** [application-defined SQL functions] or [virtual tables], not within
|
|
244546
244683
|
** top-level application code.
|
|
244547
244684
|
**
|
|
244548
|
-
**
|
|
244685
|
+
** These routines may attempt to convert the datatype of the result.
|
|
244549
244686
|
** ^For example, if the internal representation is FLOAT and a text result
|
|
244550
244687
|
** is requested, [sqlite3_snprintf()] is used internally to perform the
|
|
244551
244688
|
** conversion automatically. ^(The following table details the conversions
|
|
@@ -244570,7 +244707,7 @@ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
|
|
|
244570
244707
|
** <tr><td> TEXT <td> BLOB <td> No change
|
|
244571
244708
|
** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER
|
|
244572
244709
|
** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL
|
|
244573
|
-
** <tr><td> BLOB <td> TEXT <td>
|
|
244710
|
+
** <tr><td> BLOB <td> TEXT <td> [CAST] to TEXT, ensure zero terminator
|
|
244574
244711
|
** </table>
|
|
244575
244712
|
** </blockquote>)^
|
|
244576
244713
|
**
|
|
@@ -249320,7 +249457,7 @@ SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut);
|
|
|
249320
249457
|
** ^When xBestIndex returns, the sqlite3_value object returned by
|
|
249321
249458
|
** sqlite3_vtab_rhs_value() is automatically deallocated.
|
|
249322
249459
|
**
|
|
249323
|
-
** The "_rhs_" in the name of this routine is an
|
|
249460
|
+
** The "_rhs_" in the name of this routine is an abbreviation for
|
|
249324
249461
|
** "Right-Hand Side".
|
|
249325
249462
|
*/
|
|
249326
249463
|
SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal);
|
|
@@ -262224,6 +262361,26 @@ sqlite3mcFileControlPragma(sqlite3* db, const char* zDbName, int op, void* pArg)
|
|
|
262224
262361
|
((char**)pArg)[0] = sqlite3_mprintf("ok");
|
|
262225
262362
|
}
|
|
262226
262363
|
}
|
|
262364
|
+
else if (sqlite3StrICmp(pragmaName, "hexkey") == 0)
|
|
262365
|
+
{
|
|
262366
|
+
int nValue = sqlite3Strlen30(pragmaValue);
|
|
262367
|
+
if (((nValue & 1) == 0) && (sqlite3mcIsHexKey(pragmaValue, nValue) != 0))
|
|
262368
|
+
{
|
|
262369
|
+
char* zHexKey = sqlite3_malloc(nValue/2);
|
|
262370
|
+
sqlite3mcConvertHex2Bin(pragmaValue, nValue, zHexKey);
|
|
262371
|
+
rc = sqlite3_key_v2(db, zDbName, zHexKey, nValue/2);
|
|
262372
|
+
sqlite3_free(zHexKey);
|
|
262373
|
+
if (rc == SQLITE_OK)
|
|
262374
|
+
{
|
|
262375
|
+
((char**)pArg)[0] = sqlite3_mprintf("ok");
|
|
262376
|
+
}
|
|
262377
|
+
}
|
|
262378
|
+
else
|
|
262379
|
+
{
|
|
262380
|
+
rc = SQLITE_ERROR;
|
|
262381
|
+
((char**)pArg)[0] = sqlite3_mprintf("Malformed hex string");
|
|
262382
|
+
}
|
|
262383
|
+
}
|
|
262227
262384
|
else if (sqlite3StrICmp(pragmaName, "rekey") == 0)
|
|
262228
262385
|
{
|
|
262229
262386
|
rc = sqlite3_rekey_v2(db, zDbName, pragmaValue, -1);
|
|
@@ -262243,6 +262400,37 @@ sqlite3mcFileControlPragma(sqlite3* db, const char* zDbName, int op, void* pArg)
|
|
|
262243
262400
|
}
|
|
262244
262401
|
}
|
|
262245
262402
|
}
|
|
262403
|
+
else if (sqlite3StrICmp(pragmaName, "hexrekey") == 0)
|
|
262404
|
+
{
|
|
262405
|
+
int nValue = sqlite3Strlen30(pragmaValue);
|
|
262406
|
+
if (((nValue & 1) == 0) && (sqlite3mcIsHexKey(pragmaValue, nValue) != 0))
|
|
262407
|
+
{
|
|
262408
|
+
char* zHexKey = sqlite3_malloc(nValue/2);
|
|
262409
|
+
sqlite3mcConvertHex2Bin(pragmaValue, nValue, zHexKey);
|
|
262410
|
+
rc = sqlite3_rekey_v2(db, zDbName, zHexKey, nValue/2);
|
|
262411
|
+
sqlite3_free(zHexKey);
|
|
262412
|
+
if (rc == SQLITE_OK)
|
|
262413
|
+
{
|
|
262414
|
+
((char**)pArg)[0] = sqlite3_mprintf("ok");
|
|
262415
|
+
}
|
|
262416
|
+
else
|
|
262417
|
+
{
|
|
262418
|
+
if (db->pErr)
|
|
262419
|
+
{
|
|
262420
|
+
const char* z = (const char*)sqlite3_value_text(db->pErr);
|
|
262421
|
+
if (z && sqlite3Strlen30(z) > 0)
|
|
262422
|
+
{
|
|
262423
|
+
((char**)pArg)[0] = sqlite3_mprintf(z);
|
|
262424
|
+
}
|
|
262425
|
+
}
|
|
262426
|
+
}
|
|
262427
|
+
}
|
|
262428
|
+
else
|
|
262429
|
+
{
|
|
262430
|
+
rc = SQLITE_ERROR;
|
|
262431
|
+
((char**)pArg)[0] = sqlite3_mprintf("Malformed hex string");
|
|
262432
|
+
}
|
|
262433
|
+
}
|
|
262246
262434
|
else
|
|
262247
262435
|
{
|
|
262248
262436
|
int j;
|
|
@@ -262307,13 +262495,15 @@ sqlite3mcCodecQueryParameters(sqlite3* db, const char* zDb, const char* zUri)
|
|
|
262307
262495
|
{
|
|
262308
262496
|
u8 iByte;
|
|
262309
262497
|
int i;
|
|
262310
|
-
|
|
262311
|
-
|
|
262498
|
+
int nKey = sqlite3Strlen30(zKey);
|
|
262499
|
+
char* zDecoded = sqlite3_malloc(nKey);
|
|
262500
|
+
for (i = 0, iByte = 0; i < nKey && sqlite3Isxdigit(zKey[i]); i++)
|
|
262312
262501
|
{
|
|
262313
262502
|
iByte = (iByte << 4) + sqlite3HexToInt(zKey[i]);
|
|
262314
|
-
if ((i & 1) != 0) zDecoded[i
|
|
262503
|
+
if ((i & 1) != 0) zDecoded[i/2] = iByte;
|
|
262315
262504
|
}
|
|
262316
|
-
sqlite3_key_v2(db, zDb, zDecoded, i
|
|
262505
|
+
sqlite3_key_v2(db, zDb, zDecoded, i/2);
|
|
262506
|
+
sqlite3_free(zDecoded);
|
|
262317
262507
|
}
|
|
262318
262508
|
else if ((zKey = sqlite3_uri_parameter(zUri, "key")) != 0)
|
|
262319
262509
|
{
|
|
@@ -262391,7 +262581,7 @@ sqlite3mcHandleMainKey(sqlite3* db, const char* zPath)
|
|
|
262391
262581
|
** Purpose: Implementation of SQLite codec API
|
|
262392
262582
|
** Author: Ulrich Telle
|
|
262393
262583
|
** Created: 2006-12-06
|
|
262394
|
-
** Copyright: (c) 2006-
|
|
262584
|
+
** Copyright: (c) 2006-2022 Ulrich Telle
|
|
262395
262585
|
** License: MIT
|
|
262396
262586
|
*/
|
|
262397
262587
|
|
|
@@ -262467,7 +262657,7 @@ sqlite3mcBtreeSetPageSize(Btree* p, int pageSize, int nReserve, int iFix)
|
|
|
262467
262657
|
** Change 4: Call sqlite3mcBtreeSetPageSize instead of sqlite3BtreeSetPageSize for main database
|
|
262468
262658
|
** (sqlite3mcBtreeSetPageSize allows to reduce the number of reserved bytes)
|
|
262469
262659
|
**
|
|
262470
|
-
** This code is generated by the script rekeyvacuum.sh from SQLite version 3.38.
|
|
262660
|
+
** This code is generated by the script rekeyvacuum.sh from SQLite version 3.38.2 amalgamation.
|
|
262471
262661
|
*/
|
|
262472
262662
|
SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3mcRunVacuumForRekey(
|
|
262473
262663
|
char **pzErrMsg, /* Write error message here */
|
|
@@ -262859,7 +263049,7 @@ SQLITE_PRIVATE Codec*
|
|
|
262859
263049
|
sqlite3mcGetMainCodec(sqlite3* db);
|
|
262860
263050
|
|
|
262861
263051
|
SQLITE_PRIVATE void
|
|
262862
|
-
sqlite3mcSetCodec(sqlite3* db, const char* zFileName, Codec* codec);
|
|
263052
|
+
sqlite3mcSetCodec(sqlite3* db, const char* zDbName, const char* zFileName, Codec* codec);
|
|
262863
263053
|
|
|
262864
263054
|
static int
|
|
262865
263055
|
mcAdjustBtree(Btree* pBt, int nPageSize, int nReserved, int isLegacy)
|
|
@@ -262921,7 +263111,7 @@ sqlite3mcCodecAttach(sqlite3* db, int nDb, const char* zPath, const void* zKey,
|
|
|
262921
263111
|
sqlite3mcSetBtree(codec, db->aDb[nDb].pBt);
|
|
262922
263112
|
mcAdjustBtree(db->aDb[nDb].pBt, pageSize, reserved, sqlite3mcGetLegacyWriteCipher(codec));
|
|
262923
263113
|
sqlite3mcCodecSizeChange(codec, pageSize, reserved);
|
|
262924
|
-
sqlite3mcSetCodec(db, dbFileName, codec);
|
|
263114
|
+
sqlite3mcSetCodec(db, zDbName, dbFileName, codec);
|
|
262925
263115
|
}
|
|
262926
263116
|
else
|
|
262927
263117
|
{
|
|
@@ -262942,7 +263132,7 @@ sqlite3mcCodecAttach(sqlite3* db, int nDb, const char* zPath, const void* zKey,
|
|
|
262942
263132
|
/* Remove codec for main database */
|
|
262943
263133
|
if (nDb == 0 && nKey == 0)
|
|
262944
263134
|
{
|
|
262945
|
-
sqlite3mcSetCodec(db, dbFileName, NULL);
|
|
263135
|
+
sqlite3mcSetCodec(db, zDbName, dbFileName, NULL);
|
|
262946
263136
|
}
|
|
262947
263137
|
}
|
|
262948
263138
|
}
|
|
@@ -262977,7 +263167,7 @@ sqlite3mcCodecAttach(sqlite3* db, int nDb, const char* zPath, const void* zKey,
|
|
|
262977
263167
|
int reserved = sqlite3mcGetReservedWriteCipher(codec);
|
|
262978
263168
|
mcAdjustBtree(db->aDb[nDb].pBt, pageSize, reserved, sqlite3mcGetLegacyWriteCipher(codec));
|
|
262979
263169
|
sqlite3mcCodecSizeChange(codec, pageSize, reserved);
|
|
262980
|
-
sqlite3mcSetCodec(db, dbFileName, codec);
|
|
263170
|
+
sqlite3mcSetCodec(db, zDbName, dbFileName, codec);
|
|
262981
263171
|
}
|
|
262982
263172
|
else
|
|
262983
263173
|
{
|
|
@@ -263124,7 +263314,7 @@ sqlite3_rekey_v2(sqlite3* db, const char* zDbName, const void* zKey, int nKey)
|
|
|
263124
263314
|
int nReservedWriteCipher;
|
|
263125
263315
|
sqlite3mcSetHasReadCipher(codec, 0); /* Original database is not encrypted */
|
|
263126
263316
|
mcAdjustBtree(pBt, sqlite3mcGetPageSizeWriteCipher(codec), sqlite3mcGetReservedWriteCipher(codec), sqlite3mcGetLegacyWriteCipher(codec));
|
|
263127
|
-
sqlite3mcSetCodec(db, dbFileName, codec);
|
|
263317
|
+
sqlite3mcSetCodec(db, zDbName, dbFileName, codec);
|
|
263128
263318
|
nReservedWriteCipher = sqlite3mcGetReservedWriteCipher(codec);
|
|
263129
263319
|
sqlite3mcCodecSizeChange(codec, nPagesize, nReservedWriteCipher);
|
|
263130
263320
|
if (nReserved != nReservedWriteCipher)
|
|
@@ -263275,7 +263465,7 @@ leave_rekey:
|
|
|
263275
263465
|
if (!sqlite3mcIsEncrypted(codec))
|
|
263276
263466
|
{
|
|
263277
263467
|
/* Remove codec for unencrypted database */
|
|
263278
|
-
sqlite3mcSetCodec(db, dbFileName, NULL);
|
|
263468
|
+
sqlite3mcSetCodec(db, zDbName, dbFileName, NULL);
|
|
263279
263469
|
}
|
|
263280
263470
|
return rc;
|
|
263281
263471
|
}
|
|
@@ -267223,6 +267413,15 @@ SQLITE_EXTENSION_INIT1
|
|
|
267223
267413
|
#include <stdio.h>
|
|
267224
267414
|
#include <math.h>
|
|
267225
267415
|
|
|
267416
|
+
#ifdef SQLITE_HAVE_ZLIB
|
|
267417
|
+
#include <zlib.h>
|
|
267418
|
+
#define fopen gzopen
|
|
267419
|
+
#define fclose gzclose
|
|
267420
|
+
#define fread gzfread
|
|
267421
|
+
#define fseek gzseek
|
|
267422
|
+
#define ftell gztell
|
|
267423
|
+
#endif
|
|
267424
|
+
|
|
267226
267425
|
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
|
267227
267426
|
|
|
267228
267427
|
/*
|
|
@@ -267254,7 +267453,11 @@ SQLITE_EXTENSION_INIT1
|
|
|
267254
267453
|
typedef struct VsvReader VsvReader;
|
|
267255
267454
|
struct VsvReader
|
|
267256
267455
|
{
|
|
267456
|
+
#ifdef SQLITE_HAVE_ZLIB
|
|
267457
|
+
gzFile in; /* Read the VSV text from this compressed input stream */
|
|
267458
|
+
#else
|
|
267257
267459
|
FILE *in; /* Read the VSV text from this input stream */
|
|
267460
|
+
#endif
|
|
267258
267461
|
char *z; /* Accumulated text for a field */
|
|
267259
267462
|
int n; /* Number of bytes in z */
|
|
267260
267463
|
int nAlloc; /* Space allocated for z[] */
|
|
@@ -268154,6 +268357,7 @@ static int vsvtabConnect(
|
|
|
268154
268357
|
}
|
|
268155
268358
|
else if (nCol<0)
|
|
268156
268359
|
{
|
|
268360
|
+
nCol = 0;
|
|
268157
268361
|
do
|
|
268158
268362
|
{
|
|
268159
268363
|
vsv_read_one_field(&sRdr);
|
|
@@ -273163,7 +273367,7 @@ int sqlite3_regexp_init(
|
|
|
273163
273367
|
** Purpose: Implementation of SQLite VFS for Multiple Ciphers
|
|
273164
273368
|
** Author: Ulrich Telle
|
|
273165
273369
|
** Created: 2020-02-28
|
|
273166
|
-
** Copyright: (c) 2020-
|
|
273370
|
+
** Copyright: (c) 2020-2022 Ulrich Telle
|
|
273167
273371
|
** License: MIT
|
|
273168
273372
|
*/
|
|
273169
273373
|
|
|
@@ -273192,6 +273396,7 @@ struct sqlite3mc_file
|
|
|
273192
273396
|
{
|
|
273193
273397
|
sqlite3_file base; /* sqlite3_file I/O methods */
|
|
273194
273398
|
sqlite3_file* pFile; /* Real underlying OS file */
|
|
273399
|
+
sqlite3mc_vfs* pVfsMC; /* Pointer to the sqlite3mc_vfs object */
|
|
273195
273400
|
const char* zFileName; /* File name */
|
|
273196
273401
|
int openFlags; /* Open flags */
|
|
273197
273402
|
sqlite3mc_file* pMainNext; /* Next main db file */
|
|
@@ -273214,9 +273419,6 @@ struct sqlite3mc_vfs
|
|
|
273214
273419
|
#define REALVFS(p) ((sqlite3_vfs*)(((sqlite3mc_vfs*)(p))->base.pAppData))
|
|
273215
273420
|
#define REALFILE(p) (((sqlite3mc_file*)(p))->pFile)
|
|
273216
273421
|
|
|
273217
|
-
#define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
|
|
273218
|
-
#define ORIGFILE(p) ((sqlite3_file*)(((CksmFile*)(p))+1))
|
|
273219
|
-
|
|
273220
273422
|
/*
|
|
273221
273423
|
** Prototypes for VFS methods
|
|
273222
273424
|
*/
|
|
@@ -273270,37 +273472,8 @@ static const int walFrameHeaderSize = 24;
|
|
|
273270
273472
|
static const int walFileHeaderSize = 32;
|
|
273271
273473
|
|
|
273272
273474
|
/*
|
|
273273
|
-
** Global
|
|
273475
|
+
** Global I/O method structure of SQLite3 Multiple Ciphers VFS
|
|
273274
273476
|
*/
|
|
273275
|
-
static sqlite3mc_vfs mcVfsGlobal =
|
|
273276
|
-
{
|
|
273277
|
-
{
|
|
273278
|
-
3, /* iVersion */
|
|
273279
|
-
0, /* szOsFile */
|
|
273280
|
-
1024, /* mxPathname */
|
|
273281
|
-
0, /* pNext */
|
|
273282
|
-
SQLITE3MC_VFS_NAME, /* zName */
|
|
273283
|
-
0, /* pAppData */
|
|
273284
|
-
mcVfsOpen, /* xOpen */
|
|
273285
|
-
mcVfsDelete, /* xDelete */
|
|
273286
|
-
mcVfsAccess, /* xAccess */
|
|
273287
|
-
mcVfsFullPathname, /* xFullPathname */
|
|
273288
|
-
mcVfsDlOpen, /* xDlOpen */
|
|
273289
|
-
mcVfsDlError, /* xDlError */
|
|
273290
|
-
mcVfsDlSym, /* xDlSym */
|
|
273291
|
-
mcVfsDlClose, /* xDlClose */
|
|
273292
|
-
mcVfsRandomness, /* xRandomness */
|
|
273293
|
-
mcVfsSleep, /* xSleep */
|
|
273294
|
-
mcVfsCurrentTime, /* xCurrentTime */
|
|
273295
|
-
mcVfsGetLastError, /* xGetLastError */
|
|
273296
|
-
mcVfsCurrentTimeInt64, /* xCurrentTimeInt64 */
|
|
273297
|
-
mcVfsSetSystemCall, /* xSetSystemCall */
|
|
273298
|
-
mcVfsGetSystemCall, /* xGetSystemCall */
|
|
273299
|
-
mcVfsNextSystemCall /* xNextSystemCall */
|
|
273300
|
-
},
|
|
273301
|
-
NULL
|
|
273302
|
-
};
|
|
273303
|
-
|
|
273304
273477
|
static sqlite3_io_methods mcIoMethodsGlobal =
|
|
273305
273478
|
{
|
|
273306
273479
|
3, /* iVersion */
|
|
@@ -273334,10 +273507,10 @@ static sqlite3_io_methods mcIoMethodsGlobal =
|
|
|
273334
273507
|
static void mcMainListAdd(sqlite3mc_file* pFile)
|
|
273335
273508
|
{
|
|
273336
273509
|
assert( (pFile->openFlags & SQLITE_OPEN_MAIN_DB) );
|
|
273337
|
-
sqlite3_mutex_enter(
|
|
273338
|
-
pFile->pMainNext =
|
|
273339
|
-
|
|
273340
|
-
sqlite3_mutex_leave(
|
|
273510
|
+
sqlite3_mutex_enter(pFile->pVfsMC->mutex);
|
|
273511
|
+
pFile->pMainNext = pFile->pVfsMC->pMain;
|
|
273512
|
+
pFile->pVfsMC->pMain = pFile;
|
|
273513
|
+
sqlite3_mutex_leave(pFile->pVfsMC->mutex);
|
|
273341
273514
|
}
|
|
273342
273515
|
|
|
273343
273516
|
/*
|
|
@@ -273346,11 +273519,11 @@ static void mcMainListAdd(sqlite3mc_file* pFile)
|
|
|
273346
273519
|
static void mcMainListRemove(sqlite3mc_file* pFile)
|
|
273347
273520
|
{
|
|
273348
273521
|
sqlite3mc_file** pMainPrev;
|
|
273349
|
-
sqlite3_mutex_enter(
|
|
273350
|
-
for (pMainPrev = &
|
|
273522
|
+
sqlite3_mutex_enter(pFile->pVfsMC->mutex);
|
|
273523
|
+
for (pMainPrev = &pFile->pVfsMC->pMain; *pMainPrev && *pMainPrev != pFile; pMainPrev = &((*pMainPrev)->pMainNext)){}
|
|
273351
273524
|
if (*pMainPrev) *pMainPrev = pFile->pMainNext;
|
|
273352
273525
|
pFile->pMainNext = 0;
|
|
273353
|
-
sqlite3_mutex_leave(
|
|
273526
|
+
sqlite3_mutex_leave(pFile->pVfsMC->mutex);
|
|
273354
273527
|
}
|
|
273355
273528
|
|
|
273356
273529
|
/*
|
|
@@ -273368,6 +273541,51 @@ static sqlite3mc_file* mcFindDbMainFileName(sqlite3mc_vfs* mcVfs, const char* zF
|
|
|
273368
273541
|
return pDb;
|
|
273369
273542
|
}
|
|
273370
273543
|
|
|
273544
|
+
/*
|
|
273545
|
+
** Find a pointer to the Multiple Ciphers VFS in use for a database connection.
|
|
273546
|
+
*/
|
|
273547
|
+
static sqlite3mc_vfs* mcFindVfs(sqlite3* db, const char* zDbName)
|
|
273548
|
+
{
|
|
273549
|
+
sqlite3mc_vfs* pVfsMC = NULL;
|
|
273550
|
+
if (db->pVfs && db->pVfs->xOpen == mcVfsOpen)
|
|
273551
|
+
{
|
|
273552
|
+
/* The top level VFS is a Multiple Ciphers VFS */
|
|
273553
|
+
pVfsMC = (sqlite3mc_vfs*)(db->pVfs);
|
|
273554
|
+
}
|
|
273555
|
+
else
|
|
273556
|
+
{
|
|
273557
|
+
/*
|
|
273558
|
+
** The top level VFS is not a Multiple Ciphers VFS.
|
|
273559
|
+
** Retrieve the VFS names stack.
|
|
273560
|
+
*/
|
|
273561
|
+
char* zVfsNameStack = 0;
|
|
273562
|
+
if ((sqlite3_file_control(db, zDbName, SQLITE_FCNTL_VFSNAME, &zVfsNameStack) == SQLITE_OK) && (zVfsNameStack != NULL))
|
|
273563
|
+
{
|
|
273564
|
+
/* Search for the name prefix of a Multiple Ciphers VFS. */
|
|
273565
|
+
char* zVfsName = strstr(zVfsNameStack, SQLITE3MC_VFS_NAME);
|
|
273566
|
+
if (zVfsName != NULL)
|
|
273567
|
+
{
|
|
273568
|
+
/* The prefix was found, now determine the full VFS name. */
|
|
273569
|
+
char* zVfsNameEnd = zVfsName + strlen(SQLITE3MC_VFS_NAME);
|
|
273570
|
+
if (*zVfsNameEnd == '-')
|
|
273571
|
+
{
|
|
273572
|
+
for (++zVfsNameEnd; *zVfsNameEnd != '/' && *zVfsNameEnd != 0; ++zVfsNameEnd);
|
|
273573
|
+
if (*zVfsNameEnd == '/') *zVfsNameEnd = 0;
|
|
273574
|
+
|
|
273575
|
+
/* Find a pointer to the VFS with the determined name. */
|
|
273576
|
+
sqlite3_vfs* pVfs = sqlite3_vfs_find(zVfsName);
|
|
273577
|
+
if (pVfs && pVfs->xOpen == mcVfsOpen)
|
|
273578
|
+
{
|
|
273579
|
+
pVfsMC = (sqlite3mc_vfs*) pVfs;
|
|
273580
|
+
}
|
|
273581
|
+
}
|
|
273582
|
+
}
|
|
273583
|
+
sqlite3_free(zVfsNameStack);
|
|
273584
|
+
}
|
|
273585
|
+
}
|
|
273586
|
+
return pVfsMC;
|
|
273587
|
+
}
|
|
273588
|
+
|
|
273371
273589
|
/*
|
|
273372
273590
|
** Find the codec of the database file
|
|
273373
273591
|
** corresponding to the database schema name.
|
|
@@ -273375,11 +273593,16 @@ static sqlite3mc_file* mcFindDbMainFileName(sqlite3mc_vfs* mcVfs, const char* zF
|
|
|
273375
273593
|
SQLITE_PRIVATE Codec* sqlite3mcGetCodec(sqlite3* db, const char* zDbName)
|
|
273376
273594
|
{
|
|
273377
273595
|
Codec* codec = NULL;
|
|
273378
|
-
|
|
273379
|
-
|
|
273380
|
-
if (
|
|
273596
|
+
sqlite3mc_vfs* pVfsMC = mcFindVfs(db, zDbName);
|
|
273597
|
+
|
|
273598
|
+
if (pVfsMC)
|
|
273381
273599
|
{
|
|
273382
|
-
|
|
273600
|
+
const char* dbFileName = sqlite3_db_filename(db, zDbName);
|
|
273601
|
+
sqlite3mc_file* pDbMain = mcFindDbMainFileName(pVfsMC, dbFileName);
|
|
273602
|
+
if (pDbMain)
|
|
273603
|
+
{
|
|
273604
|
+
codec = pDbMain->codec;
|
|
273605
|
+
}
|
|
273383
273606
|
}
|
|
273384
273607
|
return codec;
|
|
273385
273608
|
}
|
|
@@ -273402,9 +273625,14 @@ SQLITE_PRIVATE Codec* sqlite3mcGetMainCodec(sqlite3* db)
|
|
|
273402
273625
|
** connection handle is actually valid, because the association between
|
|
273403
273626
|
** connection handles and database file handles is not maintained properly.
|
|
273404
273627
|
*/
|
|
273405
|
-
SQLITE_PRIVATE void sqlite3mcSetCodec(sqlite3* db, const char* zFileName, Codec* codec)
|
|
273628
|
+
SQLITE_PRIVATE void sqlite3mcSetCodec(sqlite3* db, const char* zDbName, const char* zFileName, Codec* codec)
|
|
273406
273629
|
{
|
|
273407
|
-
sqlite3mc_file* pDbMain =
|
|
273630
|
+
sqlite3mc_file* pDbMain = NULL;
|
|
273631
|
+
sqlite3mc_vfs* pVfsMC = mcFindVfs(db, zDbName);
|
|
273632
|
+
if (pVfsMC)
|
|
273633
|
+
{
|
|
273634
|
+
pDbMain = mcFindDbMainFileName((sqlite3mc_vfs*)(db->pVfs), zFileName);
|
|
273635
|
+
}
|
|
273408
273636
|
if (pDbMain)
|
|
273409
273637
|
{
|
|
273410
273638
|
Codec* prevCodec = pDbMain->codec;
|
|
@@ -273473,6 +273701,7 @@ static int mcVfsOpen(sqlite3_vfs* pVfs, const char* zName, sqlite3_file* pFile,
|
|
|
273473
273701
|
sqlite3mc_vfs* mcVfs = (sqlite3mc_vfs*) pVfs;
|
|
273474
273702
|
sqlite3mc_file* mcFile = (sqlite3mc_file*) pFile;
|
|
273475
273703
|
mcFile->pFile = (sqlite3_file*) &mcFile[1];
|
|
273704
|
+
mcFile->pVfsMC = mcVfs;
|
|
273476
273705
|
mcFile->openFlags = flags;
|
|
273477
273706
|
mcFile->zFileName = zName;
|
|
273478
273707
|
mcFile->codec = 0;
|
|
@@ -273503,7 +273732,7 @@ static int mcVfsOpen(sqlite3_vfs* pVfs, const char* zName, sqlite3_file* pFile,
|
|
|
273503
273732
|
else if (flags & SQLITE_OPEN_MAIN_JOURNAL)
|
|
273504
273733
|
{
|
|
273505
273734
|
const char* dbFileName = sqlite3_filename_database(zName);
|
|
273506
|
-
mcFile->pMainDb = mcFindDbMainFileName(
|
|
273735
|
+
mcFile->pMainDb = mcFindDbMainFileName(mcFile->pVfsMC, dbFileName);
|
|
273507
273736
|
mcFile->zFileName = zName;
|
|
273508
273737
|
SQLITE3MC_DEBUG_LOG("mcVfsOpen MAIN Journal: mcFile=%p fileName=%s dbFileName=%s\n", mcFile, mcFile->zFileName, dbFileName);
|
|
273509
273738
|
}
|
|
@@ -273518,7 +273747,7 @@ static int mcVfsOpen(sqlite3_vfs* pVfs, const char* zName, sqlite3_file* pFile,
|
|
|
273518
273747
|
else if (flags & SQLITE_OPEN_SUBJOURNAL)
|
|
273519
273748
|
{
|
|
273520
273749
|
const char* dbFileName = sqlite3_filename_database(zName);
|
|
273521
|
-
mcFile->pMainDb = mcFindDbMainFileName(
|
|
273750
|
+
mcFile->pMainDb = mcFindDbMainFileName(mcFile->pVfsMC, dbFileName);
|
|
273522
273751
|
mcFile->zFileName = zName;
|
|
273523
273752
|
SQLITE3MC_DEBUG_LOG("mcVfsOpen SUB Journal: mcFile=%p fileName=%s dbFileName=%s\n", mcFile, mcFile->zFileName, dbFileName);
|
|
273524
273753
|
}
|
|
@@ -273534,7 +273763,7 @@ static int mcVfsOpen(sqlite3_vfs* pVfs, const char* zName, sqlite3_file* pFile,
|
|
|
273534
273763
|
else if (flags & SQLITE_OPEN_WAL)
|
|
273535
273764
|
{
|
|
273536
273765
|
const char* dbFileName = sqlite3_filename_database(zName);
|
|
273537
|
-
mcFile->pMainDb = mcFindDbMainFileName(
|
|
273766
|
+
mcFile->pMainDb = mcFindDbMainFileName(mcFile->pVfsMC, dbFileName);
|
|
273538
273767
|
mcFile->zFileName = zName;
|
|
273539
273768
|
SQLITE3MC_DEBUG_LOG("mcVfsOpen WAL Journal: mcFile=%p fileName=%s dbFileName=%s\n", mcFile, mcFile->zFileName, dbFileName);
|
|
273540
273769
|
}
|
|
@@ -273656,7 +273885,7 @@ static int mcIoClose(sqlite3_file* pFile)
|
|
|
273656
273885
|
p->codec = 0;
|
|
273657
273886
|
}
|
|
273658
273887
|
|
|
273659
|
-
assert(p->pMainNext == 0 &&
|
|
273888
|
+
assert(p->pMainNext == 0 && p->pVfsMC->pMain != p);
|
|
273660
273889
|
rc = REALFILE(pFile)->pMethods->xClose(REALFILE(pFile));
|
|
273661
273890
|
return rc;
|
|
273662
273891
|
}
|
|
@@ -274318,6 +274547,14 @@ static int mcIoFileControl(sqlite3_file* pFile, int op, void* pArg)
|
|
|
274318
274547
|
if (doReal)
|
|
274319
274548
|
{
|
|
274320
274549
|
rc = REALFILE(pFile)->pMethods->xFileControl(REALFILE(pFile), op, pArg);
|
|
274550
|
+
if (rc == SQLITE_OK && op == SQLITE_FCNTL_VFSNAME)
|
|
274551
|
+
{
|
|
274552
|
+
sqlite3mc_vfs* pVfsMC = p->pVfsMC;
|
|
274553
|
+
char* zIn = *(char**)pArg;
|
|
274554
|
+
char* zOut = sqlite3_mprintf("%s/%z", pVfsMC->base.zName, zIn);
|
|
274555
|
+
*(char**)pArg = zOut;
|
|
274556
|
+
if (zOut == 0) rc = SQLITE_NOMEM;
|
|
274557
|
+
}
|
|
274321
274558
|
}
|
|
274322
274559
|
return rc;
|
|
274323
274560
|
}
|