11/******************************************************************************
22** 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
44** single large file, the entire code can be compiled as a single translation
55** unit. This allows many compilers to do optimizations that would not be
66** possible if the files were compiled separately. Performance improvements
@@ -452,9 +452,9 @@ extern "C" {
452452** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453** [sqlite_version()] and [sqlite_source_id()].
454454*/
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 "
458458
459459/*
460460** CAPI3REF: Run-Time Library Version Numbers
@@ -39691,11 +39691,17 @@ static int unixShmLock(
3969139691 int flags /* What to do with the lock */
3969239692){
3969339693 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 */
3969639696 int rc = SQLITE_OK; /* Result code */
3969739697 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;
3969939705
3970039706 assert( pShmNode==pDbFd->pInode->pShmNode );
3970139707 assert( pShmNode->pInode==pDbFd->pInode );
@@ -46983,10 +46989,14 @@ static int winShmLock(
4698346989 winFile *pDbFd = (winFile*)fd; /* Connection holding shared memory */
4698446990 winShm *p = pDbFd->pShm; /* The shared memory being locked */
4698546991 winShm *pX; /* For looping over all siblings */
46986- winShmNode *pShmNode = p->pShmNode ;
46992+ winShmNode *pShmNode;
4698746993 int rc = SQLITE_OK; /* Result code */
4698846994 u16 mask; /* Mask of locks to take or release */
4698946995
46996+ if( p==0 ) return SQLITE_IOERR_SHMLOCK;
46997+ pShmNode = p->pShmNode;
46998+ if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK;
46999+
4699047000 assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK );
4699147001 assert( n>=1 );
4699247002 assert( flags==(SQLITE_SHM_LOCK | SQLITE_SHM_SHARED)
@@ -74993,24 +75003,6 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
7499375003 assert( (flags & (BTREE_SAVEPOSITION|BTREE_APPEND|BTREE_PREFORMAT))==flags );
7499475004 assert( (flags & BTREE_PREFORMAT)==0 || seekResult || pCur->pKeyInfo==0 );
7499575005
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-
7501475006 /* Save the positions of any other cursors open on this table.
7501575007 **
7501675008 ** In some cases, the call to btreeMoveto() below is a no-op. For
@@ -75035,6 +75027,24 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
7503575027 }
7503675028 }
7503775029
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+
7503875048 if( pCur->pKeyInfo==0 ){
7503975049 assert( pX->pKey==0 );
7504075050 /* If this is an insert into a table b-tree, invalidate any incrblob
@@ -75123,8 +75133,7 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
7512375133 }
7512475134 }
7512575135 assert( pCur->eState==CURSOR_VALID
75126- || (pCur->eState==CURSOR_INVALID && loc)
75127- || CORRUPT_DB );
75136+ || (pCur->eState==CURSOR_INVALID && loc) );
7512875137
7512975138 pPage = pCur->pPage;
7513075139 assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
@@ -75411,12 +75420,16 @@ SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
7541175420 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
7541275421 assert( !hasReadConflicts(p, pCur->pgnoRoot) );
7541375422 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+ }
7541875431 }
75419- assert( CORRUPT_DB || pCur->eState==CURSOR_VALID );
75432+ assert( pCur->eState==CURSOR_VALID );
7542075433
7542175434 iCellDepth = pCur->iPage;
7542275435 iCellIdx = pCur->ix;
@@ -125098,7 +125111,7 @@ SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){
125098125111 }
125099125112
125100125113 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 );
125102125115 if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){
125103125116 zColAff[j++] = pTab->aCol[i].affinity;
125104125117 }
@@ -133539,7 +133552,7 @@ SQLITE_PRIVATE int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg, u32 mFl
133539133552 sqlite3ResetAllSchemasOfConnection(db);
133540133553 pDb = &db->aDb[iDb];
133541133554 }else
133542- if( rc==SQLITE_OK || (db->flags&SQLITE_NoSchemaError)){
133555+ if( rc==SQLITE_OK || (( db->flags&SQLITE_NoSchemaError) && rc!=SQLITE_NOMEM )){
133543133556 /* Hack: If the SQLITE_NoSchemaError flag is set, then consider
133544133557 ** the schema loaded, even if errors (other than OOM) occurred. In
133545133558 ** this situation the current sqlite3_prepare() operation will fail,
@@ -146285,6 +146298,7 @@ SQLITE_API int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
146285146298
146286146299 sqlite3ParseObjectInit(&sParse, db);
146287146300 sParse.eParseMode = PARSE_MODE_DECLARE_VTAB;
146301+ sParse.disableTriggers = 1;
146288146302 /* We should never be able to reach this point while loading the
146289146303 ** schema. Nevertheless, defend against that (turn off db->init.busy)
146290146304 ** in case a bug arises. */
@@ -154582,8 +154596,17 @@ static void whereLoopOutputAdjust(
154582154596 /* If there are extra terms in the WHERE clause not used by an index
154583154597 ** that depend only on the table being scanned, and that will tend to
154584154598 ** 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+ }
154587154610 }
154588154611 if( pTerm->truthProb<=0 ){
154589154612 /* If a truth probability is specified using the likelihood() hints,
@@ -157882,6 +157905,26 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
157882157905 }
157883157906#endif
157884157907
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+
157885157928/*
157886157929** Generate the end of the WHERE loop. See comments on
157887157930** sqlite3WhereBegin() for additional information.
@@ -158134,14 +158177,15 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){
158134158177 ){
158135158178 int x = pOp->p2;
158136158179 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
158137158185 if( !HasRowid(pTab) ){
158138158186 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
158139158187 x = pPk->aiColumn[x];
158140158188 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
158145158189 }else{
158146158190 testcase( x!=sqlite3StorageColumnToTable(pTab,x) );
158147158191 x = sqlite3StorageColumnToTable(pTab,x);
@@ -158151,9 +158195,22 @@ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){
158151158195 pOp->p2 = x;
158152158196 pOp->p1 = pLevel->iIdxCur;
158153158197 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
158154158213 }
158155- assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0
158156- || pWInfo->eOnePass );
158157158214 }else if( pOp->opcode==OP_Rowid ){
158158158215 pOp->p1 = pLevel->iIdxCur;
158159158216 pOp->opcode = OP_IdxRowid;
@@ -234376,7 +234433,7 @@ static void fts5SourceIdFunc(
234376234433){
234377234434 assert( nArg==0 );
234378234435 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);
234380234437}
234381234438
234382234439/*
0 commit comments