1
1
/******************************************************************************
2
2
** This file is an amalgamation of many separate C source files from SQLite
3
- ** version 3.37.1 . By combining all the individual C code files into this
3
+ ** version 3.37.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.37.1 "
456
- #define SQLITE_VERSION_NUMBER 3037001
457
- #define SQLITE_SOURCE_ID "2021-12-30 15:30:28 378629bf2ea546f73eee84063c5358439a12f7300e433f18c9e1bddd948dea62 "
455
+ #define SQLITE_VERSION "3.37.2 "
456
+ #define SQLITE_VERSION_NUMBER 3037002
457
+ #define SQLITE_SOURCE_ID "2022-01-06 13:25:41 872ba256cbf61d9290b571c0e6d82a20c224ca3ad82971edc46b29818d5d17a0 "
458
458
459
459
/*
460
460
** CAPI3REF: Run-Time Library Version Numbers
@@ -18503,6 +18503,8 @@ struct Parse {
18503
18503
AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
18504
18504
Parse *pToplevel; /* Parse structure for main program (or NULL) */
18505
18505
Table *pTriggerTab; /* Table triggers are being coded for */
18506
+ TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
18507
+ ParseCleanup *pCleanup; /* List of cleanup operations to run after parse */
18506
18508
union {
18507
18509
int addrCrTab; /* Address of OP_CreateBtree on CREATE TABLE */
18508
18510
Returning *pReturning; /* The RETURNING clause */
@@ -18557,9 +18559,7 @@ struct Parse {
18557
18559
Token sArg; /* Complete text of a module argument */
18558
18560
Table **apVtabLock; /* Pointer to virtual tables needing locking */
18559
18561
#endif
18560
- TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
18561
18562
With *pWith; /* Current WITH clause, or NULL */
18562
- ParseCleanup *pCleanup; /* List of cleanup operations to run after parse */
18563
18563
#ifndef SQLITE_OMIT_ALTERTABLE
18564
18564
RenameToken *pRename; /* Tokens subject to renaming by ALTER TABLE */
18565
18565
#endif
@@ -20093,13 +20093,15 @@ SQLITE_PRIVATE void sqlite3FkActions(Parse*, Table*, ExprList*, int, int*, int
20093
20093
SQLITE_PRIVATE int sqlite3FkRequired(Parse*, Table*, int*, int);
20094
20094
SQLITE_PRIVATE u32 sqlite3FkOldmask(Parse*, Table*);
20095
20095
SQLITE_PRIVATE FKey *sqlite3FkReferences(Table *);
20096
+ SQLITE_PRIVATE void sqlite3FkClearTriggerCache(sqlite3*,int);
20096
20097
#else
20097
20098
#define sqlite3FkActions(a,b,c,d,e,f)
20098
20099
#define sqlite3FkCheck(a,b,c,d,e,f)
20099
20100
#define sqlite3FkDropTable(a,b,c)
20100
20101
#define sqlite3FkOldmask(a,b) 0
20101
20102
#define sqlite3FkRequired(a,b,c,d) 0
20102
20103
#define sqlite3FkReferences(a) 0
20104
+ #define sqlite3FkClearTriggerCache(a,b)
20103
20105
#endif
20104
20106
#ifndef SQLITE_OMIT_FOREIGN_KEY
20105
20107
SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*);
@@ -56574,7 +56576,7 @@ static int pager_wait_on_lock(Pager *pPager, int locktype){
56574
56576
#if defined(SQLITE_DEBUG)
56575
56577
static void assertTruncateConstraintCb(PgHdr *pPg){
56576
56578
assert( pPg->flags&PGHDR_DIRTY );
56577
- assert( !subjRequiresPage( pPg) || pPg ->pgno<=pPg->pPager->dbSize );
56579
+ assert( pPg->pgno<=pPg->pPager->dbSize || !subjRequiresPage(pPg) );
56578
56580
}
56579
56581
static void assertTruncateConstraint(Pager *pPager){
56580
56582
sqlite3PcacheIterateDirty(pPager->pPCache, assertTruncateConstraintCb);
@@ -57915,7 +57917,7 @@ SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager){
57915
57917
** may mean that the pager was in the error-state when this
57916
57918
** function was called and the journal file does not exist.
57917
57919
*/
57918
- if( !isOpen(pPager->jfd) ){
57920
+ if( !isOpen(pPager->jfd) && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
57919
57921
sqlite3_vfs * const pVfs = pPager->pVfs;
57920
57922
int bExists; /* True if journal file exists */
57921
57923
rc = sqlite3OsAccess(
@@ -66818,7 +66820,7 @@ static void btreeParseCellPtr(
66818
66820
pInfo->nPayload = nPayload;
66819
66821
pInfo->pPayload = pIter;
66820
66822
testcase( nPayload==pPage->maxLocal );
66821
- testcase( nPayload==pPage->maxLocal+1 );
66823
+ testcase( nPayload==(u32) pPage->maxLocal+1 );
66822
66824
if( nPayload<=pPage->maxLocal ){
66823
66825
/* This is the (easy) common case where the entire payload fits
66824
66826
** on the local page. No overflow is required.
@@ -66855,7 +66857,7 @@ static void btreeParseCellPtrIndex(
66855
66857
pInfo->nPayload = nPayload;
66856
66858
pInfo->pPayload = pIter;
66857
66859
testcase( nPayload==pPage->maxLocal );
66858
- testcase( nPayload==pPage->maxLocal+1 );
66860
+ testcase( nPayload==(u32) pPage->maxLocal+1 );
66859
66861
if( nPayload<=pPage->maxLocal ){
66860
66862
/* This is the (easy) common case where the entire payload fits
66861
66863
** on the local page. No overflow is required.
@@ -66918,15 +66920,15 @@ static u16 cellSizePtr(MemPage *pPage, u8 *pCell){
66918
66920
while( (*pIter++)&0x80 && pIter<pEnd );
66919
66921
}
66920
66922
testcase( nSize==pPage->maxLocal );
66921
- testcase( nSize==pPage->maxLocal+1 );
66923
+ testcase( nSize==(u32) pPage->maxLocal+1 );
66922
66924
if( nSize<=pPage->maxLocal ){
66923
66925
nSize += (u32)(pIter - pCell);
66924
66926
if( nSize<4 ) nSize = 4;
66925
66927
}else{
66926
66928
int minLocal = pPage->minLocal;
66927
66929
nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4);
66928
66930
testcase( nSize==pPage->maxLocal );
66929
- testcase( nSize==pPage->maxLocal+1 );
66931
+ testcase( nSize==(u32) pPage->maxLocal+1 );
66930
66932
if( nSize>pPage->maxLocal ){
66931
66933
nSize = minLocal;
66932
66934
}
@@ -69817,7 +69819,7 @@ static void btreeSetNPage(BtShared *pBt, MemPage *pPage1){
69817
69819
int nPage = get4byte(&pPage1->aData[28]);
69818
69820
testcase( nPage==0 );
69819
69821
if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage);
69820
- testcase( pBt->nPage!=nPage );
69822
+ testcase( pBt->nPage!=(u32) nPage );
69821
69823
pBt->nPage = nPage;
69822
69824
}
69823
69825
@@ -72382,16 +72384,18 @@ static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){
72382
72384
int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
72383
72385
72384
72386
if( *pRC ) return;
72385
- assert( idx>=0 && idx<pPage->nCell );
72387
+ assert( idx>=0 );
72388
+ assert( idx<pPage->nCell );
72386
72389
assert( CORRUPT_DB || sz==cellSize(pPage, idx) );
72387
72390
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
72388
72391
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
72389
72392
assert( pPage->nFree>=0 );
72390
72393
data = pPage->aData;
72391
72394
ptr = &pPage->aCellIdx[2*idx];
72395
+ assert( pPage->pBt->usableSize > (int)(ptr-data) );
72392
72396
pc = get2byte(ptr);
72393
72397
hdr = pPage->hdrOffset;
72394
- testcase( pc==get2byte(&data[hdr+5]) );
72398
+ testcase( pc==(u32) get2byte(&data[hdr+5]) );
72395
72399
testcase( pc+sz==pPage->pBt->usableSize );
72396
72400
if( pc+sz > pPage->pBt->usableSize ){
72397
72401
*pRC = SQLITE_CORRUPT_BKPT;
@@ -72683,7 +72687,7 @@ static int rebuildPage(
72683
72687
72684
72688
assert( i<iEnd );
72685
72689
j = get2byte(&aData[hdr+5]);
72686
- if( NEVER( j>(u32)usableSize) ){ j = 0; }
72690
+ if( j>(u32)usableSize ){ j = 0; }
72687
72691
memcpy(&pTmp[j], &aData[j], usableSize - j);
72688
72692
72689
72693
for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
@@ -72914,7 +72918,7 @@ static int editPage(
72914
72918
72915
72919
pData = &aData[get2byteNotZero(&aData[hdr+5])];
72916
72920
if( pData<pBegin ) goto editpage_fail;
72917
- if( NEVER( pData>pPg->aDataEnd) ) goto editpage_fail;
72921
+ if( pData>pPg->aDataEnd ) goto editpage_fail;
72918
72922
72919
72923
/* Add cells to the start of the page */
72920
72924
if( iNew<iOld ){
@@ -74817,7 +74821,12 @@ SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
74817
74821
iCellIdx = pCur->ix;
74818
74822
pPage = pCur->pPage;
74819
74823
pCell = findCell(pPage, iCellIdx);
74820
- if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ) return SQLITE_CORRUPT;
74824
+ if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ){
74825
+ return SQLITE_CORRUPT_BKPT;
74826
+ }
74827
+ if( pPage->nCell<=iCellIdx ){
74828
+ return SQLITE_CORRUPT_BKPT;
74829
+ }
74821
74830
74822
74831
/* If the bPreserve flag is set to true, then the cursor position must
74823
74832
** be preserved following this delete operation. If the current delete
@@ -84101,7 +84110,7 @@ SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3 *db, BtCursor *pCur, i64 *rowid){
84101
84110
/* The index entry must begin with a header size */
84102
84111
getVarint32NR((u8*)m.z, szHdr);
84103
84112
testcase( szHdr==3 );
84104
- testcase( szHdr==m.n );
84113
+ testcase( szHdr==(u32) m.n );
84105
84114
testcase( szHdr>0x7fffffff );
84106
84115
assert( m.n>=0 );
84107
84116
if( unlikely(szHdr<3 || szHdr>(unsigned)m.n) ){
@@ -90511,6 +90520,7 @@ case OP_SetCookie: {
90511
90520
/* When the schema cookie changes, record the new cookie internally */
90512
90521
pDb->pSchema->schema_cookie = pOp->p3 - pOp->p5;
90513
90522
db->mDbFlags |= DBFLAG_SchemaChange;
90523
+ sqlite3FkClearTriggerCache(db, pOp->p1);
90514
90524
}else if( pOp->p2==BTREE_FILE_FORMAT ){
90515
90525
/* Record changes in the file format */
90516
90526
pDb->pSchema->file_format = pOp->p3;
@@ -99143,7 +99153,7 @@ static int memjrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size){
99143
99153
p->pFirst = 0;
99144
99154
}else{
99145
99155
i64 iOff = p->nChunkSize;
99146
- for(pIter=p->pFirst; ALWAYS(pIter) && iOff<= size; pIter=pIter->pNext){
99156
+ for(pIter=p->pFirst; ALWAYS(pIter) && iOff<size; pIter=pIter->pNext){
99147
99157
iOff += p->nChunkSize;
99148
99158
}
99149
99159
if( ALWAYS(pIter) ){
@@ -123234,6 +123244,25 @@ static void fkTriggerDelete(sqlite3 *dbMem, Trigger *p){
123234
123244
}
123235
123245
}
123236
123246
123247
+ /*
123248
+ ** Clear the apTrigger[] cache of CASCADE triggers for all foreign keys
123249
+ ** in a particular database. This needs to happen when the schema
123250
+ ** changes.
123251
+ */
123252
+ SQLITE_PRIVATE void sqlite3FkClearTriggerCache(sqlite3 *db, int iDb){
123253
+ HashElem *k;
123254
+ Hash *pHash = &db->aDb[iDb].pSchema->tblHash;
123255
+ for(k=sqliteHashFirst(pHash); k; k=sqliteHashNext(k)){
123256
+ Table *pTab = sqliteHashData(k);
123257
+ FKey *pFKey;
123258
+ if( !IsOrdinaryTable(pTab) ) continue;
123259
+ for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
123260
+ fkTriggerDelete(db, pFKey->apTrigger[0]); pFKey->apTrigger[0] = 0;
123261
+ fkTriggerDelete(db, pFKey->apTrigger[1]); pFKey->apTrigger[1] = 0;
123262
+ }
123263
+ }
123264
+ }
123265
+
123237
123266
/*
123238
123267
** This function is called to generate code that runs when table pTab is
123239
123268
** being dropped from the database. The SrcList passed as the second argument
@@ -124034,7 +124063,7 @@ SQLITE_PRIVATE void sqlite3OpenTable(
124034
124063
}else{
124035
124064
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
124036
124065
assert( pPk!=0 );
124037
- assert( pPk->tnum==pTab->tnum );
124066
+ assert( pPk->tnum==pTab->tnum || CORRUPT_DB );
124038
124067
sqlite3VdbeAddOp3(v, opcode, iCur, pPk->tnum, iDb);
124039
124068
sqlite3VdbeSetP4KeyInfo(pParse, pPk);
124040
124069
VdbeComment((v, "%s", pTab->zName));
@@ -126540,7 +126569,6 @@ SQLITE_PRIVATE void sqlite3CompleteInsertion(
126540
126569
}
126541
126570
pik_flags = (useSeekResult ? OPFLAG_USESEEKRESULT : 0);
126542
126571
if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
126543
- assert( pParse->nested==0 );
126544
126572
pik_flags |= OPFLAG_NCHANGE;
126545
126573
pik_flags |= (update_flags & OPFLAG_SAVEPOSITION);
126546
126574
if( update_flags==0 ){
@@ -132946,7 +132974,7 @@ static int sqlite3Prepare(
132946
132974
sParse.checkSchema = 0;
132947
132975
}
132948
132976
if( sParse.rc!=SQLITE_OK && sParse.rc!=SQLITE_DONE ){
132949
- if( sParse.checkSchema ){
132977
+ if( sParse.checkSchema && db->init.busy==0 ){
132950
132978
schemaIsValid(&sParse);
132951
132979
}
132952
132980
if( sParse.pVdbe ){
@@ -141889,7 +141917,7 @@ static void codeReturningTrigger(
141889
141917
}
141890
141918
sqlite3ExprListDelete(db, sSelect.pEList);
141891
141919
pNew = sqlite3ExpandReturning(pParse, pReturning->pReturnEL, pTab);
141892
- if( pNew ){
141920
+ if( !db->mallocFailed ){
141893
141921
NameContext sNC;
141894
141922
memset(&sNC, 0, sizeof(sNC));
141895
141923
if( pReturning->nRetCol==0 ){
@@ -141901,24 +141929,27 @@ static void codeReturningTrigger(
141901
141929
sNC.ncFlags = NC_UBaseReg;
141902
141930
pParse->eTriggerOp = pTrigger->op;
141903
141931
pParse->pTriggerTab = pTab;
141904
- if( sqlite3ResolveExprListNames(&sNC, pNew)==SQLITE_OK ){
141932
+ if( sqlite3ResolveExprListNames(&sNC, pNew)==SQLITE_OK
141933
+ && !db->mallocFailed
141934
+ ){
141905
141935
int i;
141906
141936
int nCol = pNew->nExpr;
141907
141937
int reg = pParse->nMem+1;
141908
141938
pParse->nMem += nCol+2;
141909
141939
pReturning->iRetReg = reg;
141910
141940
for(i=0; i<nCol; i++){
141911
141941
Expr *pCol = pNew->a[i].pExpr;
141942
+ assert( pCol!=0 ); /* Due to !db->mallocFailed ~9 lines above */
141912
141943
sqlite3ExprCodeFactorable(pParse, pCol, reg+i);
141913
141944
}
141914
141945
sqlite3VdbeAddOp3(v, OP_MakeRecord, reg, i, reg+i);
141915
141946
sqlite3VdbeAddOp2(v, OP_NewRowid, pReturning->iRetCur, reg+i+1);
141916
141947
sqlite3VdbeAddOp3(v, OP_Insert, pReturning->iRetCur, reg+i, reg+i+1);
141917
141948
}
141918
- sqlite3ExprListDelete(db, pNew);
141919
- pParse->eTriggerOp = 0;
141920
- pParse->pTriggerTab = 0;
141921
141949
}
141950
+ sqlite3ExprListDelete(db, pNew);
141951
+ pParse->eTriggerOp = 0;
141952
+ pParse->pTriggerTab = 0;
141922
141953
}
141923
141954
141924
141955
@@ -232502,7 +232533,7 @@ static void fts5SourceIdFunc(
232502
232533
){
232503
232534
assert( nArg==0 );
232504
232535
UNUSED_PARAM2(nArg, apUnused);
232505
- sqlite3_result_text(pCtx, "fts5: 2021-12-30 15:30:28 378629bf2ea546f73eee84063c5358439a12f7300e433f18c9e1bddd948dea62 ", -1, SQLITE_TRANSIENT);
232536
+ sqlite3_result_text(pCtx, "fts5: 2022-01-06 13:25:41 872ba256cbf61d9290b571c0e6d82a20c224ca3ad82971edc46b29818d5d17a0 ", -1, SQLITE_TRANSIENT);
232506
232537
}
232507
232538
232508
232539
/*
0 commit comments