1
1
/******************************************************************************
2
2
** This file is an amalgamation of many separate C source files from SQLite
3
- ** version 3.38.1 . By combining all the individual C code files into this
3
+ ** version 3.38.2 . By combining all the individual C code files into this
4
4
** single large file, the entire code can be compiled as a single translation
5
5
** unit. This allows many compilers to do optimizations that would not be
6
6
** possible if the files were compiled separately. Performance improvements
@@ -452,9 +452,9 @@ extern "C" {
452
452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453
453
** [sqlite_version()] and [sqlite_source_id()].
454
454
*/
455
- #define SQLITE_VERSION "3.38.1 "
456
- #define SQLITE_VERSION_NUMBER 3038001
457
- #define SQLITE_SOURCE_ID "2022-03-12 13:37:29 38c210fdd258658321c85ec9c01a072fda3ada94540e3239d29b34dc547a8cbc "
455
+ #define SQLITE_VERSION "3.38.2 "
456
+ #define SQLITE_VERSION_NUMBER 3038002
457
+ #define SQLITE_SOURCE_ID "2022-03-26 13:51:10 d33c709cc0af66bc5b6dc6216eba9f1f0b40960b9ae83694c986fbf4c1d6f08f "
458
458
459
459
/*
460
460
** CAPI3REF: Run-Time Library Version Numbers
@@ -39691,11 +39691,17 @@ static int unixShmLock(
39691
39691
int flags /* What to do with the lock */
39692
39692
){
39693
39693
unixFile *pDbFd = (unixFile*)fd; /* Connection holding shared memory */
39694
- unixShm *p = pDbFd->pShm; /* The shared memory being locked */
39695
- unixShmNode *pShmNode = p->pShmNode; /* The underlying file iNode */
39694
+ unixShm *p; /* The shared memory being locked */
39695
+ unixShmNode *pShmNode; /* The underlying file iNode */
39696
39696
int rc = SQLITE_OK; /* Result code */
39697
39697
u16 mask; /* Mask of locks to take or release */
39698
- int *aLock = pShmNode->aLock;
39698
+ int *aLock;
39699
+
39700
+ p = pDbFd->pShm;
39701
+ if( p==0 ) return SQLITE_IOERR_SHMLOCK;
39702
+ pShmNode = p->pShmNode;
39703
+ if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK;
39704
+ aLock = pShmNode->aLock;
39699
39705
39700
39706
assert( pShmNode==pDbFd->pInode->pShmNode );
39701
39707
assert( pShmNode->pInode==pDbFd->pInode );
@@ -46983,10 +46989,14 @@ static int winShmLock(
46983
46989
winFile *pDbFd = (winFile*)fd; /* Connection holding shared memory */
46984
46990
winShm *p = pDbFd->pShm; /* The shared memory being locked */
46985
46991
winShm *pX; /* For looping over all siblings */
46986
- winShmNode *pShmNode = p->pShmNode ;
46992
+ winShmNode *pShmNode;
46987
46993
int rc = SQLITE_OK; /* Result code */
46988
46994
u16 mask; /* Mask of locks to take or release */
46989
46995
46996
+ if( p==0 ) return SQLITE_IOERR_SHMLOCK;
46997
+ pShmNode = p->pShmNode;
46998
+ if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK;
46999
+
46990
47000
assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK );
46991
47001
assert( n>=1 );
46992
47002
assert( flags==(SQLITE_SHM_LOCK | SQLITE_SHM_SHARED)
@@ -74993,24 +75003,6 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
74993
75003
assert( (flags & (BTREE_SAVEPOSITION|BTREE_APPEND|BTREE_PREFORMAT))==flags );
74994
75004
assert( (flags & BTREE_PREFORMAT)==0 || seekResult || pCur->pKeyInfo==0 );
74995
75005
74996
- if( pCur->eState==CURSOR_FAULT ){
74997
- assert( pCur->skipNext!=SQLITE_OK );
74998
- return pCur->skipNext;
74999
- }
75000
-
75001
- assert( cursorOwnsBtShared(pCur) );
75002
- assert( (pCur->curFlags & BTCF_WriteFlag)!=0
75003
- && pBt->inTransaction==TRANS_WRITE
75004
- && (pBt->btsFlags & BTS_READ_ONLY)==0 );
75005
- assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
75006
-
75007
- /* Assert that the caller has been consistent. If this cursor was opened
75008
- ** expecting an index b-tree, then the caller should be inserting blob
75009
- ** keys with no associated data. If the cursor was opened expecting an
75010
- ** intkey table, the caller should be inserting integer keys with a
75011
- ** blob of associated data. */
75012
- assert( (flags & BTREE_PREFORMAT) || (pX->pKey==0)==(pCur->pKeyInfo==0) );
75013
-
75014
75006
/* Save the positions of any other cursors open on this table.
75015
75007
**
75016
75008
** In some cases, the call to btreeMoveto() below is a no-op. For
@@ -75035,6 +75027,24 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
75035
75027
}
75036
75028
}
75037
75029
75030
+ if( pCur->eState>=CURSOR_REQUIRESEEK ){
75031
+ rc = moveToRoot(pCur);
75032
+ if( rc && rc!=SQLITE_EMPTY ) return rc;
75033
+ }
75034
+
75035
+ assert( cursorOwnsBtShared(pCur) );
75036
+ assert( (pCur->curFlags & BTCF_WriteFlag)!=0
75037
+ && pBt->inTransaction==TRANS_WRITE
75038
+ && (pBt->btsFlags & BTS_READ_ONLY)==0 );
75039
+ assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
75040
+
75041
+ /* Assert that the caller has been consistent. If this cursor was opened
75042
+ ** expecting an index b-tree, then the caller should be inserting blob
75043
+ ** keys with no associated data. If the cursor was opened expecting an
75044
+ ** intkey table, the caller should be inserting integer keys with a
75045
+ ** blob of associated data. */
75046
+ assert( (flags & BTREE_PREFORMAT) || (pX->pKey==0)==(pCur->pKeyInfo==0) );
75047
+
75038
75048
if( pCur->pKeyInfo==0 ){
75039
75049
assert( pX->pKey==0 );
75040
75050
/* If this is an insert into a table b-tree, invalidate any incrblob
@@ -75123,8 +75133,7 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
75123
75133
}
75124
75134
}
75125
75135
assert( pCur->eState==CURSOR_VALID
75126
- || (pCur->eState==CURSOR_INVALID && loc)
75127
- || CORRUPT_DB );
75136
+ || (pCur->eState==CURSOR_INVALID && loc) );
75128
75137
75129
75138
pPage = pCur->pPage;
75130
75139
assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
@@ -75411,12 +75420,16 @@ SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
75411
75420
assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
75412
75421
assert( !hasReadConflicts(p, pCur->pgnoRoot) );
75413
75422
assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
75414
- if( pCur->eState==CURSOR_REQUIRESEEK ){
75415
- rc = btreeRestoreCursorPosition(pCur);
75416
- assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID );
75417
- if( rc || pCur->eState!=CURSOR_VALID ) return rc;
75423
+ if( pCur->eState!=CURSOR_VALID ){
75424
+ if( pCur->eState>=CURSOR_REQUIRESEEK ){
75425
+ rc = btreeRestoreCursorPosition(pCur);
75426
+ assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID );
75427
+ if( rc || pCur->eState!=CURSOR_VALID ) return rc;
75428
+ }else{
75429
+ return SQLITE_CORRUPT_BKPT;
75430
+ }
75418
75431
}
75419
- assert( CORRUPT_DB || pCur->eState==CURSOR_VALID );
75432
+ assert( pCur->eState==CURSOR_VALID );
75420
75433
75421
75434
iCellDepth = pCur->iPage;
75422
75435
iCellIdx = pCur->ix;
@@ -125098,7 +125111,7 @@ SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){
125098
125111
}
125099
125112
125100
125113
for(i=j=0; i<pTab->nCol; i++){
125101
- assert( pTab->aCol[i].affinity!=0 );
125114
+ assert( pTab->aCol[i].affinity!=0 || sqlite3VdbeParser(v)->nErr>0 );
125102
125115
if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){
125103
125116
zColAff[j++] = pTab->aCol[i].affinity;
125104
125117
}
@@ -133539,7 +133552,7 @@ SQLITE_PRIVATE int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg, u32 mFl
133539
133552
sqlite3ResetAllSchemasOfConnection(db);
133540
133553
pDb = &db->aDb[iDb];
133541
133554
}else
133542
- if( rc==SQLITE_OK || (db->flags&SQLITE_NoSchemaError)){
133555
+ if( rc==SQLITE_OK || (( db->flags&SQLITE_NoSchemaError) && rc!=SQLITE_NOMEM )){
133543
133556
/* Hack: If the SQLITE_NoSchemaError flag is set, then consider
133544
133557
** the schema loaded, even if errors (other than OOM) occurred. In
133545
133558
** this situation the current sqlite3_prepare() operation will fail,
@@ -146285,6 +146298,7 @@ SQLITE_API int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
146285
146298
146286
146299
sqlite3ParseObjectInit(&sParse, db);
146287
146300
sParse.eParseMode = PARSE_MODE_DECLARE_VTAB;
146301
+ sParse.disableTriggers = 1;
146288
146302
/* We should never be able to reach this point while loading the
146289
146303
** schema. Nevertheless, defend against that (turn off db->init.busy)
146290
146304
** in case a bug arises. */
@@ -154582,8 +154596,17 @@ static void whereLoopOutputAdjust(
154582
154596
/* If there are extra terms in the WHERE clause not used by an index
154583
154597
** that depend only on the table being scanned, and that will tend to
154584
154598
** cause many rows to be omitted, then mark that table as
154585
- ** "self-culling". */
154586
- pLoop->wsFlags |= WHERE_SELFCULL;
154599
+ ** "self-culling".
154600
+ **
154601
+ ** 2022-03-24: Self-culling only applies if either the extra terms
154602
+ ** are straight comparison operators that are non-true with NULL
154603
+ ** operand, or if the loop is not a LEFT JOIN.
154604
+ */
154605
+ if( (pTerm->eOperator & 0x3f)!=0
154606
+ || (pWC->pWInfo->pTabList->a[pLoop->iTab].fg.jointype & JT_LEFT)==0
154607
+ ){
154608
+ pLoop->wsFlags |= WHERE_SELFCULL;
154609
+ }
154587
154610
}
154588
154611
if( pTerm->truthProb<=0 ){
154589
154612
/* If a truth probability is specified using the likelihood() hints,
@@ -157882,6 +157905,26 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
157882
157905
}
157883
157906
#endif
157884
157907
157908
+ #ifdef SQLITE_DEBUG
157909
+ /*
157910
+ ** Return true if cursor iCur is opened by instruction k of the
157911
+ ** bytecode. Used inside of assert() only.
157912
+ */
157913
+ static int cursorIsOpen(Vdbe *v, int iCur, int k){
157914
+ while( k>=0 ){
157915
+ VdbeOp *pOp = sqlite3VdbeGetOp(v,k--);
157916
+ if( pOp->p1!=iCur ) continue;
157917
+ if( pOp->opcode==OP_Close ) return 0;
157918
+ if( pOp->opcode==OP_OpenRead ) return 1;
157919
+ if( pOp->opcode==OP_OpenWrite ) return 1;
157920
+ if( pOp->opcode==OP_OpenDup ) return 1;
157921
+ if( pOp->opcode==OP_OpenAutoindex ) return 1;
157922
+ if( pOp->opcode==OP_OpenEphemeral ) return 1;
157923
+ }
157924
+ return 0;
157925
+ }
157926
+ #endif /* SQLITE_DEBUG */
157927
+
157885
157928
/*
157886
157929
** Generate the end of the WHERE loop. See comments on
157887
157930
** sqlite3WhereBegin() for additional information.
@@ -158134,14 +158177,15 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){
158134
158177
){
158135
158178
int x = pOp->p2;
158136
158179
assert( pIdx->pTable==pTab );
158180
+ #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
158181
+ if( pOp->opcode==OP_Offset ){
158182
+ /* Do not need to translate the column number */
158183
+ }else
158184
+ #endif
158137
158185
if( !HasRowid(pTab) ){
158138
158186
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
158139
158187
x = pPk->aiColumn[x];
158140
158188
assert( x>=0 );
158141
- #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
158142
- }else if( pOp->opcode==OP_Offset ){
158143
- /* Do not need to translate the column number */
158144
- #endif
158145
158189
}else{
158146
158190
testcase( x!=sqlite3StorageColumnToTable(pTab,x) );
158147
158191
x = sqlite3StorageColumnToTable(pTab,x);
@@ -158151,9 +158195,22 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){
158151
158195
pOp->p2 = x;
158152
158196
pOp->p1 = pLevel->iIdxCur;
158153
158197
OpcodeRewriteTrace(db, k, pOp);
158198
+ }else{
158199
+ /* Unable to translate the table reference into an index
158200
+ ** reference. Verify that this is harmless - that the
158201
+ ** table being referenced really is open.
158202
+ */
158203
+ #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
158204
+ assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
158205
+ || cursorIsOpen(v,pOp->p1,k)
158206
+ || pOp->opcode==OP_Offset
158207
+ );
158208
+ #else
158209
+ assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
158210
+ || cursorIsOpen(v,pOp->p1,k)
158211
+ );
158212
+ #endif
158154
158213
}
158155
- assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0
158156
- || pWInfo->eOnePass );
158157
158214
}else if( pOp->opcode==OP_Rowid ){
158158
158215
pOp->p1 = pLevel->iIdxCur;
158159
158216
pOp->opcode = OP_IdxRowid;
@@ -234376,7 +234433,7 @@ static void fts5SourceIdFunc(
234376
234433
){
234377
234434
assert( nArg==0 );
234378
234435
UNUSED_PARAM2(nArg, apUnused);
234379
- sqlite3_result_text(pCtx, "fts5: 2022-03-12 13:37:29 38c210fdd258658321c85ec9c01a072fda3ada94540e3239d29b34dc547a8cbc ", -1, SQLITE_TRANSIENT);
234436
+ sqlite3_result_text(pCtx, "fts5: 2022-03-26 13:51:10 d33c709cc0af66bc5b6dc6216eba9f1f0b40960b9ae83694c986fbf4c1d6f08f ", -1, SQLITE_TRANSIENT);
234380
234437
}
234381
234438
234382
234439
/*
0 commit comments