Fossil SCM

Update the built-in SQLite to the latest 3.38.0 alpha that includes all of the bug fixes that appear in 3.37.2.

drh 2022-01-06 22:19 trunk
Commit 186f5c262381a9273cf08835fcc8400068a79c6c11728331e6ed50ad15e63460
+4 -1
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -14443,11 +14443,14 @@
1444314443
do{
1444414444
nRow++;
1444514445
/* extract the data and data types */
1444614446
for(i=0; i<nCol; i++){
1444714447
aiTypes[i] = x = sqlite3_column_type(pStmt, i);
14448
- if( x==SQLITE_BLOB && pArg && pArg->cMode==MODE_Insert ){
14448
+ if( x==SQLITE_BLOB
14449
+ && pArg
14450
+ && (pArg->cMode==MODE_Insert || pArg->cMode==MODE_Quote)
14451
+ ){
1444914452
azVals[i] = "";
1445014453
}else{
1445114454
azVals[i] = (char*)sqlite3_column_text(pStmt, i);
1445214455
}
1445314456
if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
1445414457
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -14443,11 +14443,14 @@
14443 do{
14444 nRow++;
14445 /* extract the data and data types */
14446 for(i=0; i<nCol; i++){
14447 aiTypes[i] = x = sqlite3_column_type(pStmt, i);
14448 if( x==SQLITE_BLOB && pArg && pArg->cMode==MODE_Insert ){
 
 
 
14449 azVals[i] = "";
14450 }else{
14451 azVals[i] = (char*)sqlite3_column_text(pStmt, i);
14452 }
14453 if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
14454
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -14443,11 +14443,14 @@
14443 do{
14444 nRow++;
14445 /* extract the data and data types */
14446 for(i=0; i<nCol; i++){
14447 aiTypes[i] = x = sqlite3_column_type(pStmt, i);
14448 if( x==SQLITE_BLOB
14449 && pArg
14450 && (pArg->cMode==MODE_Insert || pArg->cMode==MODE_Quote)
14451 ){
14452 azVals[i] = "";
14453 }else{
14454 azVals[i] = (char*)sqlite3_column_text(pStmt, i);
14455 }
14456 if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
14457
+135 -80
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455455
#define SQLITE_VERSION "3.38.0"
456456
#define SQLITE_VERSION_NUMBER 3038000
457
-#define SQLITE_SOURCE_ID "2021-12-31 22:53:15 e654b57a9fc32021453eed48d1c1bba65c833fb1aac3946567968c877e4cbd10"
457
+#define SQLITE_SOURCE_ID "2022-01-06 17:13:56 2d6a16caa7d28ad5c766036b2eb6c2020683fcc9389b3c7df2013739929dd36f"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -20137,17 +20137,19 @@
2013720137
SQLITE_PRIVATE void sqlite3FkDropTable(Parse*, SrcList *, Table*);
2013820138
SQLITE_PRIVATE void sqlite3FkActions(Parse*, Table*, ExprList*, int, int*, int);
2013920139
SQLITE_PRIVATE int sqlite3FkRequired(Parse*, Table*, int*, int);
2014020140
SQLITE_PRIVATE u32 sqlite3FkOldmask(Parse*, Table*);
2014120141
SQLITE_PRIVATE FKey *sqlite3FkReferences(Table *);
20142
+SQLITE_PRIVATE void sqlite3FkClearTriggerCache(sqlite3*,int);
2014220143
#else
2014320144
#define sqlite3FkActions(a,b,c,d,e,f)
2014420145
#define sqlite3FkCheck(a,b,c,d,e,f)
2014520146
#define sqlite3FkDropTable(a,b,c)
2014620147
#define sqlite3FkOldmask(a,b) 0
2014720148
#define sqlite3FkRequired(a,b,c,d) 0
2014820149
#define sqlite3FkReferences(a) 0
20150
+ #define sqlite3FkClearTriggerCache(a,b)
2014920151
#endif
2015020152
#ifndef SQLITE_OMIT_FOREIGN_KEY
2015120153
SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*);
2015220154
SQLITE_PRIVATE int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**);
2015320155
#else
@@ -21797,11 +21799,11 @@
2179721799
** * A one-row "pseudotable" stored in a single register
2179821800
*/
2179921801
typedef struct VdbeCursor VdbeCursor;
2180021802
struct VdbeCursor {
2180121803
u8 eCurType; /* One of the CURTYPE_* values above */
21802
- i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
21804
+ i8 iDb; /* Index of cursor database in db->aDb[] */
2180321805
u8 nullRow; /* True if pointing to a row with no data */
2180421806
u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
2180521807
u8 isTable; /* True for rowid tables. False for indexes */
2180621808
#ifdef SQLITE_DEBUG
2180721809
u8 seekOp; /* Most recent seek operation on this cursor */
@@ -21810,13 +21812,15 @@
2181021812
Bool isEphemeral:1; /* True for an ephemeral table */
2181121813
Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */
2181221814
Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */
2181321815
Bool hasBeenDuped:1; /* This cursor was source or target of OP_OpenDup */
2181421816
u16 seekHit; /* See the OP_SeekHit and OP_IfNoHope opcodes */
21815
- Btree *pBtx; /* Separate file holding temporary table */
21817
+ union { /* pBtx for isEphermeral. pAltMap otherwise */
21818
+ Btree *pBtx; /* Separate file holding temporary table */
21819
+ u32 *aAltMap; /* Mapping from table to index column numbers */
21820
+ } ub;
2181621821
i64 seqCount; /* Sequence counter */
21817
- u32 *aAltMap; /* Mapping from table to index column numbers */
2181821822
2181921823
/* Cached OP_Column parse information is only valid if cacheStatus matches
2182021824
** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
2182121825
** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
2182221826
** the cache is out of date. */
@@ -56664,12 +56668,11 @@
5666456668
**
5666556669
** a) The page number is less than or equal to the size of the
5666656670
** current database image, in pages, OR
5666756671
**
5666856672
** b) if the page content were written at this time, it would not
56669
-** be necessary to write the current content out to the sub-journal
56670
-** (as determined by function subjRequiresPage()).
56673
+** be necessary to write the current content out to the sub-journal.
5667156674
**
5667256675
** If the condition asserted by this function were not true, and the
5667356676
** dirty page were to be discarded from the cache via the pagerStress()
5667456677
** routine, pagerStress() would not write the current page content to
5667556678
** the database file. If a savepoint transaction were rolled back after
@@ -56680,12 +56683,20 @@
5668056683
** database image would become corrupt. It is therefore fortunate that
5668156684
** this circumstance cannot arise.
5668256685
*/
5668356686
#if defined(SQLITE_DEBUG)
5668456687
static void assertTruncateConstraintCb(PgHdr *pPg){
56688
+ Pager *pPager = pPg->pPager;
5668556689
assert( pPg->flags&PGHDR_DIRTY );
56686
- assert( !subjRequiresPage(pPg) || pPg->pgno<=pPg->pPager->dbSize );
56690
+ if( pPg->pgno>pPager->dbSize ){ /* if (a) is false */
56691
+ Pgno pgno = pPg->pgno;
56692
+ int i;
56693
+ for(i=0; i<pPg->pPager->nSavepoint; i++){
56694
+ PagerSavepoint *p = &pPager->aSavepoint[i];
56695
+ assert( p->nOrig<pgno || sqlite3BitvecTestNotNull(p->pInSavepoint,pgno) );
56696
+ }
56697
+ }
5668756698
}
5668856699
static void assertTruncateConstraint(Pager *pPager){
5668956700
sqlite3PcacheIterateDirty(pPager->pPCache, assertTruncateConstraintCb);
5669056701
}
5669156702
#else
@@ -58022,11 +58033,11 @@
5802258033
** other connection managed to get in and roll it back before
5802358034
** this connection obtained the exclusive lock above. Or, it
5802458035
** may mean that the pager was in the error-state when this
5802558036
** function was called and the journal file does not exist.
5802658037
*/
58027
- if( !isOpen(pPager->jfd) ){
58038
+ if( !isOpen(pPager->jfd) && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
5802858039
sqlite3_vfs * const pVfs = pPager->pVfs;
5802958040
int bExists; /* True if journal file exists */
5803058041
rc = sqlite3OsAccess(
5803158042
pVfs, pPager->zJournal, SQLITE_ACCESS_EXISTS, &bExists);
5803258043
if( rc==SQLITE_OK && bExists ){
@@ -60029,16 +60040,16 @@
6002960040
*/
6003060041
SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *pPager, int eMode){
6003160042
u8 eOld = pPager->journalMode; /* Prior journalmode */
6003260043
6003360044
/* The eMode parameter is always valid */
60034
- assert( eMode==PAGER_JOURNALMODE_DELETE
60035
- || eMode==PAGER_JOURNALMODE_TRUNCATE
60036
- || eMode==PAGER_JOURNALMODE_PERSIST
60037
- || eMode==PAGER_JOURNALMODE_OFF
60038
- || eMode==PAGER_JOURNALMODE_WAL
60039
- || eMode==PAGER_JOURNALMODE_MEMORY );
60045
+ assert( eMode==PAGER_JOURNALMODE_DELETE /* 0 */
60046
+ || eMode==PAGER_JOURNALMODE_PERSIST /* 1 */
60047
+ || eMode==PAGER_JOURNALMODE_OFF /* 2 */
60048
+ || eMode==PAGER_JOURNALMODE_TRUNCATE /* 3 */
60049
+ || eMode==PAGER_JOURNALMODE_MEMORY /* 4 */
60050
+ || eMode==PAGER_JOURNALMODE_WAL /* 5 */ );
6004060051
6004160052
/* This routine is only called from the OP_JournalMode opcode, and
6004260053
** the logic there will never allow a temporary file to be changed
6004360054
** to WAL mode.
6004460055
*/
@@ -60071,11 +60082,10 @@
6007160082
assert( (PAGER_JOURNALMODE_OFF & 5)==0 );
6007260083
assert( (PAGER_JOURNALMODE_WAL & 5)==5 );
6007360084
6007460085
assert( isOpen(pPager->fd) || pPager->exclusiveMode );
6007560086
if( !pPager->exclusiveMode && (eOld & 5)==1 && (eMode & 1)==0 ){
60076
-
6007760087
/* In this case we would like to delete the journal file. If it is
6007860088
** not possible, then that is not a problem. Deleting the journal file
6007960089
** here is an optimization only.
6008060090
**
6008160091
** Before deleting the journal file, obtain a RESERVED lock on the
@@ -66904,22 +66914,36 @@
6690466914
6690566915
/* The next block of code is equivalent to:
6690666916
**
6690766917
** pIter += getVarint(pIter, (u64*)&pInfo->nKey);
6690866918
**
66909
- ** The code is inlined to avoid a function call.
66919
+ ** The code is inlined and the loop is unrolled for performance.
66920
+ ** This routine is a high-runner.
6691066921
*/
6691166922
iKey = *pIter;
6691266923
if( iKey>=0x80 ){
66913
- u8 *pEnd = &pIter[7];
66914
- iKey &= 0x7f;
66915
- while(1){
66916
- iKey = (iKey<<7) | (*++pIter & 0x7f);
66917
- if( (*pIter)<0x80 ) break;
66918
- if( pIter>=pEnd ){
66919
- iKey = (iKey<<8) | *++pIter;
66920
- break;
66924
+ u8 x;
66925
+ iKey = ((iKey&0x7f)<<7) | ((x = *++pIter) & 0x7f);
66926
+ if( x>=0x80 ){
66927
+ iKey = (iKey<<7) | ((x =*++pIter) & 0x7f);
66928
+ if( x>=0x80 ){
66929
+ iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
66930
+ if( x>=0x80 ){
66931
+ iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
66932
+ if( x>=0x80 ){
66933
+ iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
66934
+ if( x>=0x80 ){
66935
+ iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
66936
+ if( x>=0x80 ){
66937
+ iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
66938
+ if( x>=0x80 ){
66939
+ iKey = (iKey<<8) | (*++pIter);
66940
+ }
66941
+ }
66942
+ }
66943
+ }
66944
+ }
6692166945
}
6692266946
}
6692366947
}
6692466948
pIter++;
6692566949
@@ -71240,11 +71264,10 @@
7124071264
assert( pPage->intKey );
7124171265
lwr = 0;
7124271266
upr = pPage->nCell-1;
7124371267
assert( biasRight==0 || biasRight==1 );
7124471268
idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */
71245
- pCur->ix = (u16)idx;
7124671269
for(;;){
7124771270
i64 nCellKey;
7124871271
pCell = findCellPastPtr(pPage, idx);
7124971272
if( pPage->intKeyLeaf ){
7125071273
while( 0x80 <= *(pCell++) ){
@@ -71382,11 +71405,10 @@
7138271405
assert( pPage->nCell>0 );
7138371406
assert( pPage->intKey==(pIdxKey==0) );
7138471407
lwr = 0;
7138571408
upr = pPage->nCell-1;
7138671409
idx = upr>>1; /* idx = (lwr+upr)/2; */
71387
- pCur->ix = (u16)idx;
7138871410
for(;;){
7138971411
int nCell; /* Size of the pCell cell in bytes */
7139071412
pCell = findCellPastPtr(pPage, idx);
7139171413
7139271414
/* The maximum supported page-size is 65536 bytes. This means that
@@ -72498,17 +72520,19 @@
7249872520
u8 *ptr; /* Used to move bytes around within data[] */
7249972521
int rc; /* The return code */
7250072522
int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
7250172523
7250272524
if( *pRC ) return;
72503
- assert( idx>=0 && idx<pPage->nCell );
72525
+ assert( idx>=0 );
72526
+ assert( idx<pPage->nCell );
7250472527
assert( CORRUPT_DB || sz==cellSize(pPage, idx) );
7250572528
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
7250672529
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
7250772530
assert( pPage->nFree>=0 );
7250872531
data = pPage->aData;
7250972532
ptr = &pPage->aCellIdx[2*idx];
72533
+ assert( pPage->pBt->usableSize > (int)(ptr-data) );
7251072534
pc = get2byte(ptr);
7251172535
hdr = pPage->hdrOffset;
7251272536
testcase( pc==(u32)get2byte(&data[hdr+5]) );
7251372537
testcase( pc+sz==pPage->pBt->usableSize );
7251472538
if( pc+sz > pPage->pBt->usableSize ){
@@ -72799,11 +72823,11 @@
7279972823
int k; /* Current slot in pCArray->apEnd[] */
7280072824
u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */
7280172825
7280272826
assert( i<iEnd );
7280372827
j = get2byte(&aData[hdr+5]);
72804
- if( NEVER(j>(u32)usableSize) ){ j = 0; }
72828
+ if( j>(u32)usableSize ){ j = 0; }
7280572829
memcpy(&pTmp[j], &aData[j], usableSize - j);
7280672830
7280772831
for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
7280872832
pSrcEnd = pCArray->apEnd[k];
7280972833
@@ -73030,11 +73054,11 @@
7303073054
nCell -= nTail;
7303173055
}
7303273056
7303373057
pData = &aData[get2byteNotZero(&aData[hdr+5])];
7303473058
if( pData<pBegin ) goto editpage_fail;
73035
- if( NEVER(pData>pPg->aDataEnd) ) goto editpage_fail;
73059
+ if( pData>pPg->aDataEnd ) goto editpage_fail;
7303673060
7303773061
/* Add cells to the start of the page */
7303873062
if( iNew<iOld ){
7303973063
int nAdd = MIN(nNew,iOld-iNew);
7304073064
assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
@@ -74906,18 +74930,17 @@
7490674930
** but which might be used by alternative storage engines.
7490774931
*/
7490874932
SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
7490974933
Btree *p = pCur->pBtree;
7491074934
BtShared *pBt = p->pBt;
74911
- int rc; /* Return code */
74912
- MemPage *pPage; /* Page to delete cell from */
74913
- unsigned char *pCell; /* Pointer to cell to delete */
74914
- int iCellIdx; /* Index of cell to delete */
74915
- int iCellDepth; /* Depth of node containing pCell */
74916
- CellInfo info; /* Size of the cell being deleted */
74917
- int bSkipnext = 0; /* Leaf cursor in SKIPNEXT state */
74918
- u8 bPreserve = flags & BTREE_SAVEPOSITION; /* Keep cursor valid */
74935
+ int rc; /* Return code */
74936
+ MemPage *pPage; /* Page to delete cell from */
74937
+ unsigned char *pCell; /* Pointer to cell to delete */
74938
+ int iCellIdx; /* Index of cell to delete */
74939
+ int iCellDepth; /* Depth of node containing pCell */
74940
+ CellInfo info; /* Size of the cell being deleted */
74941
+ u8 bPreserve; /* Keep cursor valid. 2 for CURSOR_SKIPNEXT */
7491974942
7492074943
assert( cursorOwnsBtShared(pCur) );
7492174944
assert( pBt->inTransaction==TRANS_WRITE );
7492274945
assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
7492374946
assert( pCur->curFlags & BTCF_WriteFlag );
@@ -74932,22 +74955,35 @@
7493274955
assert( CORRUPT_DB || pCur->eState==CURSOR_VALID );
7493374956
7493474957
iCellDepth = pCur->iPage;
7493574958
iCellIdx = pCur->ix;
7493674959
pPage = pCur->pPage;
74960
+ if( pPage->nCell<=iCellIdx ){
74961
+ return SQLITE_CORRUPT_BKPT;
74962
+ }
7493774963
pCell = findCell(pPage, iCellIdx);
74938
- if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ) return SQLITE_CORRUPT;
74964
+ if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ){
74965
+ return SQLITE_CORRUPT_BKPT;
74966
+ }
7493974967
74940
- /* If the bPreserve flag is set to true, then the cursor position must
74968
+ /* If the BTREE_SAVEPOSITION bit is on, then the cursor position must
7494174969
** be preserved following this delete operation. If the current delete
7494274970
** will cause a b-tree rebalance, then this is done by saving the cursor
7494374971
** key and leaving the cursor in CURSOR_REQUIRESEEK state before
7494474972
** returning.
7494574973
**
74946
- ** Or, if the current delete will not cause a rebalance, then the cursor
74974
+ ** If the current delete will not cause a rebalance, then the cursor
7494774975
** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately
74948
- ** before or after the deleted entry. In this case set bSkipnext to true. */
74976
+ ** before or after the deleted entry.
74977
+ **
74978
+ ** The bPreserve value records which path is required:
74979
+ **
74980
+ ** bPreserve==0 Not necessary to save the cursor position
74981
+ ** bPreserve==1 Use CURSOR_REQUIRESEEK to save the cursor position
74982
+ ** bPreserve==2 Cursor won't move. Set CURSOR_SKIPNEXT.
74983
+ */
74984
+ bPreserve = (flags & BTREE_SAVEPOSITION)!=0;
7494974985
if( bPreserve ){
7495074986
if( !pPage->leaf
7495174987
|| (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
7495274988
|| pPage->nCell==1 /* See dbfuzz001.test for a test case */
7495374989
){
@@ -74954,11 +74990,11 @@
7495474990
/* A b-tree rebalance will be required after deleting this entry.
7495574991
** Save the cursor key. */
7495674992
rc = saveCursorKey(pCur);
7495774993
if( rc ) return rc;
7495874994
}else{
74959
- bSkipnext = 1;
74995
+ bPreserve = 2;
7496074996
}
7496174997
}
7496274998
7496374999
/* If the page containing the entry to delete is not a leaf page, move
7496475000
** the cursor to the largest entry in the tree that is smaller than
@@ -75054,12 +75090,12 @@
7505475090
pCur->pPage = pCur->apPage[pCur->iPage];
7505575091
rc = balance(pCur);
7505675092
}
7505775093
7505875094
if( rc==SQLITE_OK ){
75059
- if( bSkipnext ){
75060
- assert( bPreserve && (pCur->iPage==iCellDepth || CORRUPT_DB) );
75095
+ if( bPreserve>1 ){
75096
+ assert( (pCur->iPage==iCellDepth || CORRUPT_DB) );
7506175097
assert( pPage==pCur->pPage || CORRUPT_DB );
7506275098
assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
7506375099
pCur->eState = CURSOR_SKIPNEXT;
7506475100
if( iCellIdx>=pPage->nCell ){
7506575101
pCur->skipNext = -1;
@@ -81753,12 +81789,10 @@
8175381789
*/
8175481790
SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){
8175581791
if( pCx==0 ){
8175681792
return;
8175781793
}
81758
- assert( pCx->pBtx==0 || pCx->eCurType==CURTYPE_BTREE );
81759
- assert( pCx->pBtx==0 || pCx->isEphemeral );
8176081794
switch( pCx->eCurType ){
8176181795
case CURTYPE_SORTER: {
8176281796
sqlite3VdbeSorterClose(p->db, pCx);
8176381797
break;
8176481798
}
@@ -82856,11 +82890,11 @@
8285682890
VdbeCursor *p = *pp;
8285782891
assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO );
8285882892
if( p->deferredMoveto ){
8285982893
u32 iMap;
8286082894
assert( !p->isEphemeral );
82861
- if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 && !p->nullRow ){
82895
+ if( p->ub.aAltMap && (iMap = p->ub.aAltMap[1+*piCol])>0 && !p->nullRow ){
8286282896
*pp = p->pAltCursor;
8286382897
*piCol = iMap - 1;
8286482898
return SQLITE_OK;
8286582899
}
8286682900
return sqlite3VdbeFinishMoveto(p);
@@ -87057,11 +87091,10 @@
8705787091
*/
8705887092
static VdbeCursor *allocateCursor(
8705987093
Vdbe *p, /* The virtual machine */
8706087094
int iCur, /* Index of the new VdbeCursor */
8706187095
int nField, /* Number of fields in the table or index */
87062
- int iDb, /* Database the cursor belongs to, or -1 */
8706387096
u8 eCurType /* Type of the new cursor */
8706487097
){
8706587098
/* Find the memory cell that will be used to store the blob of memory
8706687099
** required for this VdbeCursor structure. It is convenient to use a
8706787100
** vdbe memory cell to manage the memory allocation required for a
@@ -87114,11 +87147,10 @@
8711487147
}
8711587148
8711687149
p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->zMalloc;
8711787150
memset(pCx, 0, offsetof(VdbeCursor,pAltCursor));
8711887151
pCx->eCurType = eCurType;
87119
- pCx->iDb = iDb;
8712087152
pCx->nField = nField;
8712187153
pCx->aOffset = &pCx->aType[nField];
8712287154
if( eCurType==CURTYPE_BTREE ){
8712387155
pCx->uc.pCursor = (BtCursor*)
8712487156
&pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField];
@@ -89508,10 +89540,11 @@
8950889540
pDest = &aMem[pOp->p3];
8950989541
memAboutToChange(p, pDest);
8951089542
assert( pC!=0 );
8951189543
assert( p2<(u32)pC->nField );
8951289544
aOffset = pC->aOffset;
89545
+ assert( aOffset==pC->aType+pC->nField );
8951389546
assert( pC->eCurType!=CURTYPE_VTAB );
8951489547
assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow );
8951589548
assert( pC->eCurType!=CURTYPE_SORTER );
8951689549
8951789550
if( pC->cacheStatus!=p->cacheCtr ){ /*OPTIMIZATION-IF-FALSE*/
@@ -90657,10 +90690,11 @@
9065790690
rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, pOp->p3);
9065890691
if( pOp->p2==BTREE_SCHEMA_VERSION ){
9065990692
/* When the schema cookie changes, record the new cookie internally */
9066090693
pDb->pSchema->schema_cookie = pOp->p3 - pOp->p5;
9066190694
db->mDbFlags |= DBFLAG_SchemaChange;
90695
+ sqlite3FkClearTriggerCache(db, pOp->p1);
9066290696
}else if( pOp->p2==BTREE_FILE_FORMAT ){
9066390697
/* Record changes in the file format */
9066490698
pDb->pSchema->file_format = pOp->p3;
9066590699
}
9066690700
if( pOp->p1==1 ){
@@ -90834,12 +90868,13 @@
9083490868
nField = pOp->p4.i;
9083590869
}
9083690870
assert( pOp->p1>=0 );
9083790871
assert( nField>=0 );
9083890872
testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
90839
- pCur = allocateCursor(p, pOp->p1, nField, iDb, CURTYPE_BTREE);
90873
+ pCur = allocateCursor(p, pOp->p1, nField, CURTYPE_BTREE);
9084090874
if( pCur==0 ) goto no_mem;
90875
+ pCur->iDb = iDb;
9084190876
pCur->nullRow = 1;
9084290877
pCur->isOrdered = 1;
9084390878
pCur->pgnoRoot = p2;
9084490879
#ifdef SQLITE_DEBUG
9084590880
pCur->wrFlag = wrFlag;
@@ -90877,22 +90912,22 @@
9087790912
9087890913
pOrig = p->apCsr[pOp->p2];
9087990914
assert( pOrig );
9088090915
assert( pOrig->isEphemeral ); /* Only ephemeral cursors can be duplicated */
9088190916
90882
- pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE);
90917
+ pCx = allocateCursor(p, pOp->p1, pOrig->nField, CURTYPE_BTREE);
9088390918
if( pCx==0 ) goto no_mem;
9088490919
pCx->nullRow = 1;
9088590920
pCx->isEphemeral = 1;
9088690921
pCx->pKeyInfo = pOrig->pKeyInfo;
9088790922
pCx->isTable = pOrig->isTable;
9088890923
pCx->pgnoRoot = pOrig->pgnoRoot;
9088990924
pCx->isOrdered = pOrig->isOrdered;
90890
- pCx->pBtx = pOrig->pBtx;
90925
+ pCx->ub.pBtx = pOrig->ub.pBtx;
9089190926
pCx->hasBeenDuped = 1;
9089290927
pOrig->hasBeenDuped = 1;
90893
- rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
90928
+ rc = sqlite3BtreeCursor(pCx->ub.pBtx, pCx->pgnoRoot, BTREE_WRCSR,
9089490929
pCx->pKeyInfo, pCx->uc.pCursor);
9089590930
/* The sqlite3BtreeCursor() routine can only fail for the first cursor
9089690931
** opened for a database. Since there is already an open cursor when this
9089790932
** opcode is run, the sqlite3BtreeCursor() cannot fail */
9089890933
assert( rc==SQLITE_OK );
@@ -90961,48 +90996,48 @@
9096190996
** OP_OpenDup, then erase all existing content so that the table is
9096290997
** empty again, rather than creating a new table. */
9096390998
assert( pCx->isEphemeral );
9096490999
pCx->seqCount = 0;
9096591000
pCx->cacheStatus = CACHE_STALE;
90966
- rc = sqlite3BtreeClearTable(pCx->pBtx, pCx->pgnoRoot, 0);
91001
+ rc = sqlite3BtreeClearTable(pCx->ub.pBtx, pCx->pgnoRoot, 0);
9096791002
}else{
90968
- pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE);
91003
+ pCx = allocateCursor(p, pOp->p1, pOp->p2, CURTYPE_BTREE);
9096991004
if( pCx==0 ) goto no_mem;
9097091005
pCx->isEphemeral = 1;
90971
- rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBtx,
91006
+ rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->ub.pBtx,
9097291007
BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5,
9097391008
vfsFlags);
9097491009
if( rc==SQLITE_OK ){
90975
- rc = sqlite3BtreeBeginTrans(pCx->pBtx, 1, 0);
91010
+ rc = sqlite3BtreeBeginTrans(pCx->ub.pBtx, 1, 0);
9097691011
if( rc==SQLITE_OK ){
9097791012
/* If a transient index is required, create it by calling
9097891013
** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
9097991014
** opening it. If a transient table is required, just use the
9098091015
** automatically created table with root-page 1 (an BLOB_INTKEY table).
9098191016
*/
9098291017
if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
9098391018
assert( pOp->p4type==P4_KEYINFO );
90984
- rc = sqlite3BtreeCreateTable(pCx->pBtx, &pCx->pgnoRoot,
91019
+ rc = sqlite3BtreeCreateTable(pCx->ub.pBtx, &pCx->pgnoRoot,
9098591020
BTREE_BLOBKEY | pOp->p5);
9098691021
if( rc==SQLITE_OK ){
9098791022
assert( pCx->pgnoRoot==SCHEMA_ROOT+1 );
9098891023
assert( pKeyInfo->db==db );
9098991024
assert( pKeyInfo->enc==ENC(db) );
90990
- rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
91025
+ rc = sqlite3BtreeCursor(pCx->ub.pBtx, pCx->pgnoRoot, BTREE_WRCSR,
9099191026
pKeyInfo, pCx->uc.pCursor);
9099291027
}
9099391028
pCx->isTable = 0;
9099491029
}else{
9099591030
pCx->pgnoRoot = SCHEMA_ROOT;
90996
- rc = sqlite3BtreeCursor(pCx->pBtx, SCHEMA_ROOT, BTREE_WRCSR,
91031
+ rc = sqlite3BtreeCursor(pCx->ub.pBtx, SCHEMA_ROOT, BTREE_WRCSR,
9099791032
0, pCx->uc.pCursor);
9099891033
pCx->isTable = 1;
9099991034
}
9100091035
}
9100191036
pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
9100291037
if( rc ){
91003
- sqlite3BtreeClose(pCx->pBtx);
91038
+ sqlite3BtreeClose(pCx->ub.pBtx);
9100491039
}
9100591040
}
9100691041
}
9100791042
if( rc ) goto abort_due_to_error;
9100891043
pCx->nullRow = 1;
@@ -91022,11 +91057,11 @@
9102291057
case OP_SorterOpen: {
9102391058
VdbeCursor *pCx;
9102491059
9102591060
assert( pOp->p1>=0 );
9102691061
assert( pOp->p2>=0 );
91027
- pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_SORTER);
91062
+ pCx = allocateCursor(p, pOp->p1, pOp->p2, CURTYPE_SORTER);
9102891063
if( pCx==0 ) goto no_mem;
9102991064
pCx->pKeyInfo = pOp->p4.pKeyInfo;
9103091065
assert( pCx->pKeyInfo->db==db );
9103191066
assert( pCx->pKeyInfo->enc==ENC(db) );
9103291067
rc = sqlite3VdbeSorterInit(db, pOp->p3, pCx);
@@ -91071,11 +91106,11 @@
9107191106
case OP_OpenPseudo: {
9107291107
VdbeCursor *pCx;
9107391108
9107491109
assert( pOp->p1>=0 );
9107591110
assert( pOp->p3>=0 );
91076
- pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, CURTYPE_PSEUDO);
91111
+ pCx = allocateCursor(p, pOp->p1, pOp->p3, CURTYPE_PSEUDO);
9107791112
if( pCx==0 ) goto no_mem;
9107891113
pCx->nullRow = 1;
9107991114
pCx->seekResult = pOp->p2;
9108091115
pCx->isTable = 1;
9108191116
/* Give this pseudo-cursor a fake BtCursor pointer so that pCx
@@ -93011,13 +93046,13 @@
9301193046
assert( pTabCur->isTable );
9301293047
pTabCur->nullRow = 0;
9301393048
pTabCur->movetoTarget = rowid;
9301493049
pTabCur->deferredMoveto = 1;
9301593050
assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 );
93016
- pTabCur->aAltMap = pOp->p4.ai;
93017
- assert( !pC->isEphemeral );
9301893051
assert( !pTabCur->isEphemeral );
93052
+ pTabCur->ub.aAltMap = pOp->p4.ai;
93053
+ assert( !pC->isEphemeral );
9301993054
pTabCur->pAltCursor = pC;
9302093055
}else{
9302193056
pOut = out2Prerelease(p, pOp);
9302293057
pOut->u.i = rowid;
9302393058
}
@@ -94535,11 +94570,11 @@
9453594570
9453694571
/* Initialize sqlite3_vtab_cursor base class */
9453794572
pVCur->pVtab = pVtab;
9453894573
9453994574
/* Initialize vdbe cursor object */
94540
- pCur = allocateCursor(p, pOp->p1, 0, -1, CURTYPE_VTAB);
94575
+ pCur = allocateCursor(p, pOp->p1, 0, CURTYPE_VTAB);
9454194576
if( pCur ){
9454294577
pCur->uc.pVCur = pVCur;
9454394578
pVtab->nRef++;
9454494579
}else{
9454594580
assert( db->mallocFailed );
@@ -96860,11 +96895,12 @@
9686096895
if( nWorker>=SORTER_MAX_MERGE_COUNT ){
9686196896
nWorker = SORTER_MAX_MERGE_COUNT-1;
9686296897
}
9686396898
#endif
9686496899
96865
- assert( pCsr->pKeyInfo && pCsr->pBtx==0 );
96900
+ assert( pCsr->pKeyInfo );
96901
+ assert( !pCsr->isEphemeral );
9686696902
assert( pCsr->eCurType==CURTYPE_SORTER );
9686796903
szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nKeyField-1)*sizeof(CollSeq*);
9686896904
sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask);
9686996905
9687096906
pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
@@ -99360,11 +99396,11 @@
9936099396
if( size==0 ){
9936199397
memjrnlFreeChunks(p->pFirst);
9936299398
p->pFirst = 0;
9936399399
}else{
9936499400
i64 iOff = p->nChunkSize;
99365
- for(pIter=p->pFirst; ALWAYS(pIter) && iOff<=size; pIter=pIter->pNext){
99401
+ for(pIter=p->pFirst; ALWAYS(pIter) && iOff<size; pIter=pIter->pNext){
9936699402
iOff += p->nChunkSize;
9936799403
}
9936899404
if( ALWAYS(pIter) ){
9936999405
memjrnlFreeChunks(pIter->pNext);
9937099406
pIter->pNext = 0;
@@ -123463,10 +123499,29 @@
123463123499
sqlite3SelectDelete(dbMem, pStep->pSelect);
123464123500
sqlite3ExprDelete(dbMem, p->pWhen);
123465123501
sqlite3DbFree(dbMem, p);
123466123502
}
123467123503
}
123504
+
123505
+/*
123506
+** Clear the apTrigger[] cache of CASCADE triggers for all foreign keys
123507
+** in a particular database. This needs to happen when the schema
123508
+** changes.
123509
+*/
123510
+SQLITE_PRIVATE void sqlite3FkClearTriggerCache(sqlite3 *db, int iDb){
123511
+ HashElem *k;
123512
+ Hash *pHash = &db->aDb[iDb].pSchema->tblHash;
123513
+ for(k=sqliteHashFirst(pHash); k; k=sqliteHashNext(k)){
123514
+ Table *pTab = sqliteHashData(k);
123515
+ FKey *pFKey;
123516
+ if( !IsOrdinaryTable(pTab) ) continue;
123517
+ for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
123518
+ fkTriggerDelete(db, pFKey->apTrigger[0]); pFKey->apTrigger[0] = 0;
123519
+ fkTriggerDelete(db, pFKey->apTrigger[1]); pFKey->apTrigger[1] = 0;
123520
+ }
123521
+ }
123522
+}
123468123523
123469123524
/*
123470123525
** This function is called to generate code that runs when table pTab is
123471123526
** being dropped from the database. The SrcList passed as the second argument
123472123527
** to this function contains a single entry guaranteed to resolve to
@@ -124264,11 +124319,11 @@
124264124319
sqlite3VdbeAddOp4Int(v, opcode, iCur, pTab->tnum, iDb, pTab->nNVCol);
124265124320
VdbeComment((v, "%s", pTab->zName));
124266124321
}else{
124267124322
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
124268124323
assert( pPk!=0 );
124269
- assert( pPk->tnum==pTab->tnum );
124324
+ assert( pPk->tnum==pTab->tnum || CORRUPT_DB );
124270124325
sqlite3VdbeAddOp3(v, opcode, iCur, pPk->tnum, iDb);
124271124326
sqlite3VdbeSetP4KeyInfo(pParse, pPk);
124272124327
VdbeComment((v, "%s", pTab->zName));
124273124328
}
124274124329
}
@@ -126768,11 +126823,10 @@
126768126823
sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
126769126824
VdbeCoverage(v);
126770126825
}
126771126826
pik_flags = (useSeekResult ? OPFLAG_USESEEKRESULT : 0);
126772126827
if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
126773
- assert( pParse->nested==0 );
126774126828
pik_flags |= OPFLAG_NCHANGE;
126775126829
pik_flags |= (update_flags & OPFLAG_SAVEPOSITION);
126776126830
if( update_flags==0 ){
126777126831
codeWithoutRowidPreupdate(pParse, pTab, iIdxCur+i, aRegIdx[i]);
126778126832
}
@@ -133183,11 +133237,11 @@
133183133237
if( db->mallocFailed ){
133184133238
sParse.rc = SQLITE_NOMEM_BKPT;
133185133239
sParse.checkSchema = 0;
133186133240
}
133187133241
if( sParse.rc!=SQLITE_OK && sParse.rc!=SQLITE_DONE ){
133188
- if( sParse.checkSchema ){
133242
+ if( sParse.checkSchema && db->init.busy==0 ){
133189133243
schemaIsValid(&sParse);
133190133244
}
133191133245
if( sParse.pVdbe ){
133192133246
sqlite3VdbeFinalize(sParse.pVdbe);
133193133247
}
@@ -142138,11 +142192,11 @@
142138142192
if( db->mallocFailed==0 && pParse->nErr==0 ){
142139142193
sqlite3GenerateColumnNames(pParse, &sSelect);
142140142194
}
142141142195
sqlite3ExprListDelete(db, sSelect.pEList);
142142142196
pNew = sqlite3ExpandReturning(pParse, pReturning->pReturnEL, pTab);
142143
- if( pNew ){
142197
+ if( !db->mallocFailed ){
142144142198
NameContext sNC;
142145142199
memset(&sNC, 0, sizeof(sNC));
142146142200
if( pReturning->nRetCol==0 ){
142147142201
pReturning->nRetCol = pNew->nExpr;
142148142202
pReturning->iRetCur = pParse->nTab++;
@@ -142150,33 +142204,34 @@
142150142204
sNC.pParse = pParse;
142151142205
sNC.uNC.iBaseReg = regIn;
142152142206
sNC.ncFlags = NC_UBaseReg;
142153142207
pParse->eTriggerOp = pTrigger->op;
142154142208
pParse->pTriggerTab = pTab;
142155
- if( sqlite3ResolveExprListNames(&sNC, pNew)==SQLITE_OK ){
142209
+ if( sqlite3ResolveExprListNames(&sNC, pNew)==SQLITE_OK
142210
+ && !db->mallocFailed
142211
+ ){
142156142212
int i;
142157142213
int nCol = pNew->nExpr;
142158142214
int reg = pParse->nMem+1;
142159142215
pParse->nMem += nCol+2;
142160142216
pReturning->iRetReg = reg;
142161142217
for(i=0; i<nCol; i++){
142162142218
Expr *pCol = pNew->a[i].pExpr;
142163
- assert( pCol!=0 || pParse->db->mallocFailed );
142164
- if( pCol==0 ) continue;
142219
+ assert( pCol!=0 ); /* Due to !db->mallocFailed ~9 lines above */
142165142220
sqlite3ExprCodeFactorable(pParse, pCol, reg+i);
142166142221
if( sqlite3ExprAffinity(pCol)==SQLITE_AFF_REAL ){
142167142222
sqlite3VdbeAddOp1(v, OP_RealAffinity, reg+i);
142168142223
}
142169142224
}
142170142225
sqlite3VdbeAddOp3(v, OP_MakeRecord, reg, i, reg+i);
142171142226
sqlite3VdbeAddOp2(v, OP_NewRowid, pReturning->iRetCur, reg+i+1);
142172142227
sqlite3VdbeAddOp3(v, OP_Insert, pReturning->iRetCur, reg+i, reg+i+1);
142173142228
}
142174
- sqlite3ExprListDelete(db, pNew);
142175
- pParse->eTriggerOp = 0;
142176
- pParse->pTriggerTab = 0;
142177142229
}
142230
+ sqlite3ExprListDelete(db, pNew);
142231
+ pParse->eTriggerOp = 0;
142232
+ pParse->pTriggerTab = 0;
142178142233
}
142179142234
142180142235
142181142236
142182142237
/*
@@ -229243,11 +229298,11 @@
229243229298
assert( (flags & FTS5INDEX_QUERY_SCAN)==0 || flags==FTS5INDEX_QUERY_SCAN );
229244229299
229245229300
if( sqlite3Fts5BufferSize(&p->rc, &buf, nToken+1)==0 ){
229246229301
int iIdx = 0; /* Index to search */
229247229302
int iPrefixIdx = 0; /* +1 prefix index */
229248
- if( nToken ) memcpy(&buf.p[1], pToken, nToken);
229303
+ if( nToken>0 ) memcpy(&buf.p[1], pToken, nToken);
229249229304
229250229305
/* Figure out which index to search and set iIdx accordingly. If this
229251229306
** is a prefix query for which there is no prefix index, set iIdx to
229252229307
** greater than pConfig->nPrefix to indicate that the query will be
229253229308
** satisfied by scanning multiple terms in the main index.
@@ -233291,11 +233346,11 @@
233291233346
int nArg, /* Number of args */
233292233347
sqlite3_value **apUnused /* Function arguments */
233293233348
){
233294233349
assert( nArg==0 );
233295233350
UNUSED_PARAM2(nArg, apUnused);
233296
- sqlite3_result_text(pCtx, "fts5: 2021-12-31 22:53:15 e654b57a9fc32021453eed48d1c1bba65c833fb1aac3946567968c877e4cbd10", -1, SQLITE_TRANSIENT);
233351
+ sqlite3_result_text(pCtx, "fts5: 2022-01-06 17:13:56 2d6a16caa7d28ad5c766036b2eb6c2020683fcc9389b3c7df2013739929dd36f", -1, SQLITE_TRANSIENT);
233297233352
}
233298233353
233299233354
/*
233300233355
** Return true if zName is the extension on one of the shadow tables used
233301233356
** by this module.
233302233357
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.38.0"
456 #define SQLITE_VERSION_NUMBER 3038000
457 #define SQLITE_SOURCE_ID "2021-12-31 22:53:15 e654b57a9fc32021453eed48d1c1bba65c833fb1aac3946567968c877e4cbd10"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -20137,17 +20137,19 @@
20137 SQLITE_PRIVATE void sqlite3FkDropTable(Parse*, SrcList *, Table*);
20138 SQLITE_PRIVATE void sqlite3FkActions(Parse*, Table*, ExprList*, int, int*, int);
20139 SQLITE_PRIVATE int sqlite3FkRequired(Parse*, Table*, int*, int);
20140 SQLITE_PRIVATE u32 sqlite3FkOldmask(Parse*, Table*);
20141 SQLITE_PRIVATE FKey *sqlite3FkReferences(Table *);
 
20142 #else
20143 #define sqlite3FkActions(a,b,c,d,e,f)
20144 #define sqlite3FkCheck(a,b,c,d,e,f)
20145 #define sqlite3FkDropTable(a,b,c)
20146 #define sqlite3FkOldmask(a,b) 0
20147 #define sqlite3FkRequired(a,b,c,d) 0
20148 #define sqlite3FkReferences(a) 0
 
20149 #endif
20150 #ifndef SQLITE_OMIT_FOREIGN_KEY
20151 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*);
20152 SQLITE_PRIVATE int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**);
20153 #else
@@ -21797,11 +21799,11 @@
21797 ** * A one-row "pseudotable" stored in a single register
21798 */
21799 typedef struct VdbeCursor VdbeCursor;
21800 struct VdbeCursor {
21801 u8 eCurType; /* One of the CURTYPE_* values above */
21802 i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
21803 u8 nullRow; /* True if pointing to a row with no data */
21804 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
21805 u8 isTable; /* True for rowid tables. False for indexes */
21806 #ifdef SQLITE_DEBUG
21807 u8 seekOp; /* Most recent seek operation on this cursor */
@@ -21810,13 +21812,15 @@
21810 Bool isEphemeral:1; /* True for an ephemeral table */
21811 Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */
21812 Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */
21813 Bool hasBeenDuped:1; /* This cursor was source or target of OP_OpenDup */
21814 u16 seekHit; /* See the OP_SeekHit and OP_IfNoHope opcodes */
21815 Btree *pBtx; /* Separate file holding temporary table */
 
 
 
21816 i64 seqCount; /* Sequence counter */
21817 u32 *aAltMap; /* Mapping from table to index column numbers */
21818
21819 /* Cached OP_Column parse information is only valid if cacheStatus matches
21820 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
21821 ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
21822 ** the cache is out of date. */
@@ -56664,12 +56668,11 @@
56664 **
56665 ** a) The page number is less than or equal to the size of the
56666 ** current database image, in pages, OR
56667 **
56668 ** b) if the page content were written at this time, it would not
56669 ** be necessary to write the current content out to the sub-journal
56670 ** (as determined by function subjRequiresPage()).
56671 **
56672 ** If the condition asserted by this function were not true, and the
56673 ** dirty page were to be discarded from the cache via the pagerStress()
56674 ** routine, pagerStress() would not write the current page content to
56675 ** the database file. If a savepoint transaction were rolled back after
@@ -56680,12 +56683,20 @@
56680 ** database image would become corrupt. It is therefore fortunate that
56681 ** this circumstance cannot arise.
56682 */
56683 #if defined(SQLITE_DEBUG)
56684 static void assertTruncateConstraintCb(PgHdr *pPg){
 
56685 assert( pPg->flags&PGHDR_DIRTY );
56686 assert( !subjRequiresPage(pPg) || pPg->pgno<=pPg->pPager->dbSize );
 
 
 
 
 
 
 
56687 }
56688 static void assertTruncateConstraint(Pager *pPager){
56689 sqlite3PcacheIterateDirty(pPager->pPCache, assertTruncateConstraintCb);
56690 }
56691 #else
@@ -58022,11 +58033,11 @@
58022 ** other connection managed to get in and roll it back before
58023 ** this connection obtained the exclusive lock above. Or, it
58024 ** may mean that the pager was in the error-state when this
58025 ** function was called and the journal file does not exist.
58026 */
58027 if( !isOpen(pPager->jfd) ){
58028 sqlite3_vfs * const pVfs = pPager->pVfs;
58029 int bExists; /* True if journal file exists */
58030 rc = sqlite3OsAccess(
58031 pVfs, pPager->zJournal, SQLITE_ACCESS_EXISTS, &bExists);
58032 if( rc==SQLITE_OK && bExists ){
@@ -60029,16 +60040,16 @@
60029 */
60030 SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *pPager, int eMode){
60031 u8 eOld = pPager->journalMode; /* Prior journalmode */
60032
60033 /* The eMode parameter is always valid */
60034 assert( eMode==PAGER_JOURNALMODE_DELETE
60035 || eMode==PAGER_JOURNALMODE_TRUNCATE
60036 || eMode==PAGER_JOURNALMODE_PERSIST
60037 || eMode==PAGER_JOURNALMODE_OFF
60038 || eMode==PAGER_JOURNALMODE_WAL
60039 || eMode==PAGER_JOURNALMODE_MEMORY );
60040
60041 /* This routine is only called from the OP_JournalMode opcode, and
60042 ** the logic there will never allow a temporary file to be changed
60043 ** to WAL mode.
60044 */
@@ -60071,11 +60082,10 @@
60071 assert( (PAGER_JOURNALMODE_OFF & 5)==0 );
60072 assert( (PAGER_JOURNALMODE_WAL & 5)==5 );
60073
60074 assert( isOpen(pPager->fd) || pPager->exclusiveMode );
60075 if( !pPager->exclusiveMode && (eOld & 5)==1 && (eMode & 1)==0 ){
60076
60077 /* In this case we would like to delete the journal file. If it is
60078 ** not possible, then that is not a problem. Deleting the journal file
60079 ** here is an optimization only.
60080 **
60081 ** Before deleting the journal file, obtain a RESERVED lock on the
@@ -66904,22 +66914,36 @@
66904
66905 /* The next block of code is equivalent to:
66906 **
66907 ** pIter += getVarint(pIter, (u64*)&pInfo->nKey);
66908 **
66909 ** The code is inlined to avoid a function call.
 
66910 */
66911 iKey = *pIter;
66912 if( iKey>=0x80 ){
66913 u8 *pEnd = &pIter[7];
66914 iKey &= 0x7f;
66915 while(1){
66916 iKey = (iKey<<7) | (*++pIter & 0x7f);
66917 if( (*pIter)<0x80 ) break;
66918 if( pIter>=pEnd ){
66919 iKey = (iKey<<8) | *++pIter;
66920 break;
 
 
 
 
 
 
 
 
 
 
 
 
 
66921 }
66922 }
66923 }
66924 pIter++;
66925
@@ -71240,11 +71264,10 @@
71240 assert( pPage->intKey );
71241 lwr = 0;
71242 upr = pPage->nCell-1;
71243 assert( biasRight==0 || biasRight==1 );
71244 idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */
71245 pCur->ix = (u16)idx;
71246 for(;;){
71247 i64 nCellKey;
71248 pCell = findCellPastPtr(pPage, idx);
71249 if( pPage->intKeyLeaf ){
71250 while( 0x80 <= *(pCell++) ){
@@ -71382,11 +71405,10 @@
71382 assert( pPage->nCell>0 );
71383 assert( pPage->intKey==(pIdxKey==0) );
71384 lwr = 0;
71385 upr = pPage->nCell-1;
71386 idx = upr>>1; /* idx = (lwr+upr)/2; */
71387 pCur->ix = (u16)idx;
71388 for(;;){
71389 int nCell; /* Size of the pCell cell in bytes */
71390 pCell = findCellPastPtr(pPage, idx);
71391
71392 /* The maximum supported page-size is 65536 bytes. This means that
@@ -72498,17 +72520,19 @@
72498 u8 *ptr; /* Used to move bytes around within data[] */
72499 int rc; /* The return code */
72500 int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
72501
72502 if( *pRC ) return;
72503 assert( idx>=0 && idx<pPage->nCell );
 
72504 assert( CORRUPT_DB || sz==cellSize(pPage, idx) );
72505 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
72506 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
72507 assert( pPage->nFree>=0 );
72508 data = pPage->aData;
72509 ptr = &pPage->aCellIdx[2*idx];
 
72510 pc = get2byte(ptr);
72511 hdr = pPage->hdrOffset;
72512 testcase( pc==(u32)get2byte(&data[hdr+5]) );
72513 testcase( pc+sz==pPage->pBt->usableSize );
72514 if( pc+sz > pPage->pBt->usableSize ){
@@ -72799,11 +72823,11 @@
72799 int k; /* Current slot in pCArray->apEnd[] */
72800 u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */
72801
72802 assert( i<iEnd );
72803 j = get2byte(&aData[hdr+5]);
72804 if( NEVER(j>(u32)usableSize) ){ j = 0; }
72805 memcpy(&pTmp[j], &aData[j], usableSize - j);
72806
72807 for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
72808 pSrcEnd = pCArray->apEnd[k];
72809
@@ -73030,11 +73054,11 @@
73030 nCell -= nTail;
73031 }
73032
73033 pData = &aData[get2byteNotZero(&aData[hdr+5])];
73034 if( pData<pBegin ) goto editpage_fail;
73035 if( NEVER(pData>pPg->aDataEnd) ) goto editpage_fail;
73036
73037 /* Add cells to the start of the page */
73038 if( iNew<iOld ){
73039 int nAdd = MIN(nNew,iOld-iNew);
73040 assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
@@ -74906,18 +74930,17 @@
74906 ** but which might be used by alternative storage engines.
74907 */
74908 SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
74909 Btree *p = pCur->pBtree;
74910 BtShared *pBt = p->pBt;
74911 int rc; /* Return code */
74912 MemPage *pPage; /* Page to delete cell from */
74913 unsigned char *pCell; /* Pointer to cell to delete */
74914 int iCellIdx; /* Index of cell to delete */
74915 int iCellDepth; /* Depth of node containing pCell */
74916 CellInfo info; /* Size of the cell being deleted */
74917 int bSkipnext = 0; /* Leaf cursor in SKIPNEXT state */
74918 u8 bPreserve = flags & BTREE_SAVEPOSITION; /* Keep cursor valid */
74919
74920 assert( cursorOwnsBtShared(pCur) );
74921 assert( pBt->inTransaction==TRANS_WRITE );
74922 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
74923 assert( pCur->curFlags & BTCF_WriteFlag );
@@ -74932,22 +74955,35 @@
74932 assert( CORRUPT_DB || pCur->eState==CURSOR_VALID );
74933
74934 iCellDepth = pCur->iPage;
74935 iCellIdx = pCur->ix;
74936 pPage = pCur->pPage;
 
 
 
74937 pCell = findCell(pPage, iCellIdx);
74938 if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ) return SQLITE_CORRUPT;
 
 
74939
74940 /* If the bPreserve flag is set to true, then the cursor position must
74941 ** be preserved following this delete operation. If the current delete
74942 ** will cause a b-tree rebalance, then this is done by saving the cursor
74943 ** key and leaving the cursor in CURSOR_REQUIRESEEK state before
74944 ** returning.
74945 **
74946 ** Or, if the current delete will not cause a rebalance, then the cursor
74947 ** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately
74948 ** before or after the deleted entry. In this case set bSkipnext to true. */
 
 
 
 
 
 
 
 
74949 if( bPreserve ){
74950 if( !pPage->leaf
74951 || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
74952 || pPage->nCell==1 /* See dbfuzz001.test for a test case */
74953 ){
@@ -74954,11 +74990,11 @@
74954 /* A b-tree rebalance will be required after deleting this entry.
74955 ** Save the cursor key. */
74956 rc = saveCursorKey(pCur);
74957 if( rc ) return rc;
74958 }else{
74959 bSkipnext = 1;
74960 }
74961 }
74962
74963 /* If the page containing the entry to delete is not a leaf page, move
74964 ** the cursor to the largest entry in the tree that is smaller than
@@ -75054,12 +75090,12 @@
75054 pCur->pPage = pCur->apPage[pCur->iPage];
75055 rc = balance(pCur);
75056 }
75057
75058 if( rc==SQLITE_OK ){
75059 if( bSkipnext ){
75060 assert( bPreserve && (pCur->iPage==iCellDepth || CORRUPT_DB) );
75061 assert( pPage==pCur->pPage || CORRUPT_DB );
75062 assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
75063 pCur->eState = CURSOR_SKIPNEXT;
75064 if( iCellIdx>=pPage->nCell ){
75065 pCur->skipNext = -1;
@@ -81753,12 +81789,10 @@
81753 */
81754 SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){
81755 if( pCx==0 ){
81756 return;
81757 }
81758 assert( pCx->pBtx==0 || pCx->eCurType==CURTYPE_BTREE );
81759 assert( pCx->pBtx==0 || pCx->isEphemeral );
81760 switch( pCx->eCurType ){
81761 case CURTYPE_SORTER: {
81762 sqlite3VdbeSorterClose(p->db, pCx);
81763 break;
81764 }
@@ -82856,11 +82890,11 @@
82856 VdbeCursor *p = *pp;
82857 assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO );
82858 if( p->deferredMoveto ){
82859 u32 iMap;
82860 assert( !p->isEphemeral );
82861 if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 && !p->nullRow ){
82862 *pp = p->pAltCursor;
82863 *piCol = iMap - 1;
82864 return SQLITE_OK;
82865 }
82866 return sqlite3VdbeFinishMoveto(p);
@@ -87057,11 +87091,10 @@
87057 */
87058 static VdbeCursor *allocateCursor(
87059 Vdbe *p, /* The virtual machine */
87060 int iCur, /* Index of the new VdbeCursor */
87061 int nField, /* Number of fields in the table or index */
87062 int iDb, /* Database the cursor belongs to, or -1 */
87063 u8 eCurType /* Type of the new cursor */
87064 ){
87065 /* Find the memory cell that will be used to store the blob of memory
87066 ** required for this VdbeCursor structure. It is convenient to use a
87067 ** vdbe memory cell to manage the memory allocation required for a
@@ -87114,11 +87147,10 @@
87114 }
87115
87116 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->zMalloc;
87117 memset(pCx, 0, offsetof(VdbeCursor,pAltCursor));
87118 pCx->eCurType = eCurType;
87119 pCx->iDb = iDb;
87120 pCx->nField = nField;
87121 pCx->aOffset = &pCx->aType[nField];
87122 if( eCurType==CURTYPE_BTREE ){
87123 pCx->uc.pCursor = (BtCursor*)
87124 &pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField];
@@ -89508,10 +89540,11 @@
89508 pDest = &aMem[pOp->p3];
89509 memAboutToChange(p, pDest);
89510 assert( pC!=0 );
89511 assert( p2<(u32)pC->nField );
89512 aOffset = pC->aOffset;
 
89513 assert( pC->eCurType!=CURTYPE_VTAB );
89514 assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow );
89515 assert( pC->eCurType!=CURTYPE_SORTER );
89516
89517 if( pC->cacheStatus!=p->cacheCtr ){ /*OPTIMIZATION-IF-FALSE*/
@@ -90657,10 +90690,11 @@
90657 rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, pOp->p3);
90658 if( pOp->p2==BTREE_SCHEMA_VERSION ){
90659 /* When the schema cookie changes, record the new cookie internally */
90660 pDb->pSchema->schema_cookie = pOp->p3 - pOp->p5;
90661 db->mDbFlags |= DBFLAG_SchemaChange;
 
90662 }else if( pOp->p2==BTREE_FILE_FORMAT ){
90663 /* Record changes in the file format */
90664 pDb->pSchema->file_format = pOp->p3;
90665 }
90666 if( pOp->p1==1 ){
@@ -90834,12 +90868,13 @@
90834 nField = pOp->p4.i;
90835 }
90836 assert( pOp->p1>=0 );
90837 assert( nField>=0 );
90838 testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
90839 pCur = allocateCursor(p, pOp->p1, nField, iDb, CURTYPE_BTREE);
90840 if( pCur==0 ) goto no_mem;
 
90841 pCur->nullRow = 1;
90842 pCur->isOrdered = 1;
90843 pCur->pgnoRoot = p2;
90844 #ifdef SQLITE_DEBUG
90845 pCur->wrFlag = wrFlag;
@@ -90877,22 +90912,22 @@
90877
90878 pOrig = p->apCsr[pOp->p2];
90879 assert( pOrig );
90880 assert( pOrig->isEphemeral ); /* Only ephemeral cursors can be duplicated */
90881
90882 pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE);
90883 if( pCx==0 ) goto no_mem;
90884 pCx->nullRow = 1;
90885 pCx->isEphemeral = 1;
90886 pCx->pKeyInfo = pOrig->pKeyInfo;
90887 pCx->isTable = pOrig->isTable;
90888 pCx->pgnoRoot = pOrig->pgnoRoot;
90889 pCx->isOrdered = pOrig->isOrdered;
90890 pCx->pBtx = pOrig->pBtx;
90891 pCx->hasBeenDuped = 1;
90892 pOrig->hasBeenDuped = 1;
90893 rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
90894 pCx->pKeyInfo, pCx->uc.pCursor);
90895 /* The sqlite3BtreeCursor() routine can only fail for the first cursor
90896 ** opened for a database. Since there is already an open cursor when this
90897 ** opcode is run, the sqlite3BtreeCursor() cannot fail */
90898 assert( rc==SQLITE_OK );
@@ -90961,48 +90996,48 @@
90961 ** OP_OpenDup, then erase all existing content so that the table is
90962 ** empty again, rather than creating a new table. */
90963 assert( pCx->isEphemeral );
90964 pCx->seqCount = 0;
90965 pCx->cacheStatus = CACHE_STALE;
90966 rc = sqlite3BtreeClearTable(pCx->pBtx, pCx->pgnoRoot, 0);
90967 }else{
90968 pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE);
90969 if( pCx==0 ) goto no_mem;
90970 pCx->isEphemeral = 1;
90971 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBtx,
90972 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5,
90973 vfsFlags);
90974 if( rc==SQLITE_OK ){
90975 rc = sqlite3BtreeBeginTrans(pCx->pBtx, 1, 0);
90976 if( rc==SQLITE_OK ){
90977 /* If a transient index is required, create it by calling
90978 ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
90979 ** opening it. If a transient table is required, just use the
90980 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
90981 */
90982 if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
90983 assert( pOp->p4type==P4_KEYINFO );
90984 rc = sqlite3BtreeCreateTable(pCx->pBtx, &pCx->pgnoRoot,
90985 BTREE_BLOBKEY | pOp->p5);
90986 if( rc==SQLITE_OK ){
90987 assert( pCx->pgnoRoot==SCHEMA_ROOT+1 );
90988 assert( pKeyInfo->db==db );
90989 assert( pKeyInfo->enc==ENC(db) );
90990 rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
90991 pKeyInfo, pCx->uc.pCursor);
90992 }
90993 pCx->isTable = 0;
90994 }else{
90995 pCx->pgnoRoot = SCHEMA_ROOT;
90996 rc = sqlite3BtreeCursor(pCx->pBtx, SCHEMA_ROOT, BTREE_WRCSR,
90997 0, pCx->uc.pCursor);
90998 pCx->isTable = 1;
90999 }
91000 }
91001 pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
91002 if( rc ){
91003 sqlite3BtreeClose(pCx->pBtx);
91004 }
91005 }
91006 }
91007 if( rc ) goto abort_due_to_error;
91008 pCx->nullRow = 1;
@@ -91022,11 +91057,11 @@
91022 case OP_SorterOpen: {
91023 VdbeCursor *pCx;
91024
91025 assert( pOp->p1>=0 );
91026 assert( pOp->p2>=0 );
91027 pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_SORTER);
91028 if( pCx==0 ) goto no_mem;
91029 pCx->pKeyInfo = pOp->p4.pKeyInfo;
91030 assert( pCx->pKeyInfo->db==db );
91031 assert( pCx->pKeyInfo->enc==ENC(db) );
91032 rc = sqlite3VdbeSorterInit(db, pOp->p3, pCx);
@@ -91071,11 +91106,11 @@
91071 case OP_OpenPseudo: {
91072 VdbeCursor *pCx;
91073
91074 assert( pOp->p1>=0 );
91075 assert( pOp->p3>=0 );
91076 pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, CURTYPE_PSEUDO);
91077 if( pCx==0 ) goto no_mem;
91078 pCx->nullRow = 1;
91079 pCx->seekResult = pOp->p2;
91080 pCx->isTable = 1;
91081 /* Give this pseudo-cursor a fake BtCursor pointer so that pCx
@@ -93011,13 +93046,13 @@
93011 assert( pTabCur->isTable );
93012 pTabCur->nullRow = 0;
93013 pTabCur->movetoTarget = rowid;
93014 pTabCur->deferredMoveto = 1;
93015 assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 );
93016 pTabCur->aAltMap = pOp->p4.ai;
93017 assert( !pC->isEphemeral );
93018 assert( !pTabCur->isEphemeral );
 
 
93019 pTabCur->pAltCursor = pC;
93020 }else{
93021 pOut = out2Prerelease(p, pOp);
93022 pOut->u.i = rowid;
93023 }
@@ -94535,11 +94570,11 @@
94535
94536 /* Initialize sqlite3_vtab_cursor base class */
94537 pVCur->pVtab = pVtab;
94538
94539 /* Initialize vdbe cursor object */
94540 pCur = allocateCursor(p, pOp->p1, 0, -1, CURTYPE_VTAB);
94541 if( pCur ){
94542 pCur->uc.pVCur = pVCur;
94543 pVtab->nRef++;
94544 }else{
94545 assert( db->mallocFailed );
@@ -96860,11 +96895,12 @@
96860 if( nWorker>=SORTER_MAX_MERGE_COUNT ){
96861 nWorker = SORTER_MAX_MERGE_COUNT-1;
96862 }
96863 #endif
96864
96865 assert( pCsr->pKeyInfo && pCsr->pBtx==0 );
 
96866 assert( pCsr->eCurType==CURTYPE_SORTER );
96867 szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nKeyField-1)*sizeof(CollSeq*);
96868 sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask);
96869
96870 pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
@@ -99360,11 +99396,11 @@
99360 if( size==0 ){
99361 memjrnlFreeChunks(p->pFirst);
99362 p->pFirst = 0;
99363 }else{
99364 i64 iOff = p->nChunkSize;
99365 for(pIter=p->pFirst; ALWAYS(pIter) && iOff<=size; pIter=pIter->pNext){
99366 iOff += p->nChunkSize;
99367 }
99368 if( ALWAYS(pIter) ){
99369 memjrnlFreeChunks(pIter->pNext);
99370 pIter->pNext = 0;
@@ -123463,10 +123499,29 @@
123463 sqlite3SelectDelete(dbMem, pStep->pSelect);
123464 sqlite3ExprDelete(dbMem, p->pWhen);
123465 sqlite3DbFree(dbMem, p);
123466 }
123467 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123468
123469 /*
123470 ** This function is called to generate code that runs when table pTab is
123471 ** being dropped from the database. The SrcList passed as the second argument
123472 ** to this function contains a single entry guaranteed to resolve to
@@ -124264,11 +124319,11 @@
124264 sqlite3VdbeAddOp4Int(v, opcode, iCur, pTab->tnum, iDb, pTab->nNVCol);
124265 VdbeComment((v, "%s", pTab->zName));
124266 }else{
124267 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
124268 assert( pPk!=0 );
124269 assert( pPk->tnum==pTab->tnum );
124270 sqlite3VdbeAddOp3(v, opcode, iCur, pPk->tnum, iDb);
124271 sqlite3VdbeSetP4KeyInfo(pParse, pPk);
124272 VdbeComment((v, "%s", pTab->zName));
124273 }
124274 }
@@ -126768,11 +126823,10 @@
126768 sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
126769 VdbeCoverage(v);
126770 }
126771 pik_flags = (useSeekResult ? OPFLAG_USESEEKRESULT : 0);
126772 if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
126773 assert( pParse->nested==0 );
126774 pik_flags |= OPFLAG_NCHANGE;
126775 pik_flags |= (update_flags & OPFLAG_SAVEPOSITION);
126776 if( update_flags==0 ){
126777 codeWithoutRowidPreupdate(pParse, pTab, iIdxCur+i, aRegIdx[i]);
126778 }
@@ -133183,11 +133237,11 @@
133183 if( db->mallocFailed ){
133184 sParse.rc = SQLITE_NOMEM_BKPT;
133185 sParse.checkSchema = 0;
133186 }
133187 if( sParse.rc!=SQLITE_OK && sParse.rc!=SQLITE_DONE ){
133188 if( sParse.checkSchema ){
133189 schemaIsValid(&sParse);
133190 }
133191 if( sParse.pVdbe ){
133192 sqlite3VdbeFinalize(sParse.pVdbe);
133193 }
@@ -142138,11 +142192,11 @@
142138 if( db->mallocFailed==0 && pParse->nErr==0 ){
142139 sqlite3GenerateColumnNames(pParse, &sSelect);
142140 }
142141 sqlite3ExprListDelete(db, sSelect.pEList);
142142 pNew = sqlite3ExpandReturning(pParse, pReturning->pReturnEL, pTab);
142143 if( pNew ){
142144 NameContext sNC;
142145 memset(&sNC, 0, sizeof(sNC));
142146 if( pReturning->nRetCol==0 ){
142147 pReturning->nRetCol = pNew->nExpr;
142148 pReturning->iRetCur = pParse->nTab++;
@@ -142150,33 +142204,34 @@
142150 sNC.pParse = pParse;
142151 sNC.uNC.iBaseReg = regIn;
142152 sNC.ncFlags = NC_UBaseReg;
142153 pParse->eTriggerOp = pTrigger->op;
142154 pParse->pTriggerTab = pTab;
142155 if( sqlite3ResolveExprListNames(&sNC, pNew)==SQLITE_OK ){
 
 
142156 int i;
142157 int nCol = pNew->nExpr;
142158 int reg = pParse->nMem+1;
142159 pParse->nMem += nCol+2;
142160 pReturning->iRetReg = reg;
142161 for(i=0; i<nCol; i++){
142162 Expr *pCol = pNew->a[i].pExpr;
142163 assert( pCol!=0 || pParse->db->mallocFailed );
142164 if( pCol==0 ) continue;
142165 sqlite3ExprCodeFactorable(pParse, pCol, reg+i);
142166 if( sqlite3ExprAffinity(pCol)==SQLITE_AFF_REAL ){
142167 sqlite3VdbeAddOp1(v, OP_RealAffinity, reg+i);
142168 }
142169 }
142170 sqlite3VdbeAddOp3(v, OP_MakeRecord, reg, i, reg+i);
142171 sqlite3VdbeAddOp2(v, OP_NewRowid, pReturning->iRetCur, reg+i+1);
142172 sqlite3VdbeAddOp3(v, OP_Insert, pReturning->iRetCur, reg+i, reg+i+1);
142173 }
142174 sqlite3ExprListDelete(db, pNew);
142175 pParse->eTriggerOp = 0;
142176 pParse->pTriggerTab = 0;
142177 }
 
 
 
142178 }
142179
142180
142181
142182 /*
@@ -229243,11 +229298,11 @@
229243 assert( (flags & FTS5INDEX_QUERY_SCAN)==0 || flags==FTS5INDEX_QUERY_SCAN );
229244
229245 if( sqlite3Fts5BufferSize(&p->rc, &buf, nToken+1)==0 ){
229246 int iIdx = 0; /* Index to search */
229247 int iPrefixIdx = 0; /* +1 prefix index */
229248 if( nToken ) memcpy(&buf.p[1], pToken, nToken);
229249
229250 /* Figure out which index to search and set iIdx accordingly. If this
229251 ** is a prefix query for which there is no prefix index, set iIdx to
229252 ** greater than pConfig->nPrefix to indicate that the query will be
229253 ** satisfied by scanning multiple terms in the main index.
@@ -233291,11 +233346,11 @@
233291 int nArg, /* Number of args */
233292 sqlite3_value **apUnused /* Function arguments */
233293 ){
233294 assert( nArg==0 );
233295 UNUSED_PARAM2(nArg, apUnused);
233296 sqlite3_result_text(pCtx, "fts5: 2021-12-31 22:53:15 e654b57a9fc32021453eed48d1c1bba65c833fb1aac3946567968c877e4cbd10", -1, SQLITE_TRANSIENT);
233297 }
233298
233299 /*
233300 ** Return true if zName is the extension on one of the shadow tables used
233301 ** by this module.
233302
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.38.0"
456 #define SQLITE_VERSION_NUMBER 3038000
457 #define SQLITE_SOURCE_ID "2022-01-06 17:13:56 2d6a16caa7d28ad5c766036b2eb6c2020683fcc9389b3c7df2013739929dd36f"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -20137,17 +20137,19 @@
20137 SQLITE_PRIVATE void sqlite3FkDropTable(Parse*, SrcList *, Table*);
20138 SQLITE_PRIVATE void sqlite3FkActions(Parse*, Table*, ExprList*, int, int*, int);
20139 SQLITE_PRIVATE int sqlite3FkRequired(Parse*, Table*, int*, int);
20140 SQLITE_PRIVATE u32 sqlite3FkOldmask(Parse*, Table*);
20141 SQLITE_PRIVATE FKey *sqlite3FkReferences(Table *);
20142 SQLITE_PRIVATE void sqlite3FkClearTriggerCache(sqlite3*,int);
20143 #else
20144 #define sqlite3FkActions(a,b,c,d,e,f)
20145 #define sqlite3FkCheck(a,b,c,d,e,f)
20146 #define sqlite3FkDropTable(a,b,c)
20147 #define sqlite3FkOldmask(a,b) 0
20148 #define sqlite3FkRequired(a,b,c,d) 0
20149 #define sqlite3FkReferences(a) 0
20150 #define sqlite3FkClearTriggerCache(a,b)
20151 #endif
20152 #ifndef SQLITE_OMIT_FOREIGN_KEY
20153 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*);
20154 SQLITE_PRIVATE int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**);
20155 #else
@@ -21797,11 +21799,11 @@
21799 ** * A one-row "pseudotable" stored in a single register
21800 */
21801 typedef struct VdbeCursor VdbeCursor;
21802 struct VdbeCursor {
21803 u8 eCurType; /* One of the CURTYPE_* values above */
21804 i8 iDb; /* Index of cursor database in db->aDb[] */
21805 u8 nullRow; /* True if pointing to a row with no data */
21806 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
21807 u8 isTable; /* True for rowid tables. False for indexes */
21808 #ifdef SQLITE_DEBUG
21809 u8 seekOp; /* Most recent seek operation on this cursor */
@@ -21810,13 +21812,15 @@
21812 Bool isEphemeral:1; /* True for an ephemeral table */
21813 Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */
21814 Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */
21815 Bool hasBeenDuped:1; /* This cursor was source or target of OP_OpenDup */
21816 u16 seekHit; /* See the OP_SeekHit and OP_IfNoHope opcodes */
21817 union { /* pBtx for isEphermeral. pAltMap otherwise */
21818 Btree *pBtx; /* Separate file holding temporary table */
21819 u32 *aAltMap; /* Mapping from table to index column numbers */
21820 } ub;
21821 i64 seqCount; /* Sequence counter */
 
21822
21823 /* Cached OP_Column parse information is only valid if cacheStatus matches
21824 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
21825 ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
21826 ** the cache is out of date. */
@@ -56664,12 +56668,11 @@
56668 **
56669 ** a) The page number is less than or equal to the size of the
56670 ** current database image, in pages, OR
56671 **
56672 ** b) if the page content were written at this time, it would not
56673 ** be necessary to write the current content out to the sub-journal.
 
56674 **
56675 ** If the condition asserted by this function were not true, and the
56676 ** dirty page were to be discarded from the cache via the pagerStress()
56677 ** routine, pagerStress() would not write the current page content to
56678 ** the database file. If a savepoint transaction were rolled back after
@@ -56680,12 +56683,20 @@
56683 ** database image would become corrupt. It is therefore fortunate that
56684 ** this circumstance cannot arise.
56685 */
56686 #if defined(SQLITE_DEBUG)
56687 static void assertTruncateConstraintCb(PgHdr *pPg){
56688 Pager *pPager = pPg->pPager;
56689 assert( pPg->flags&PGHDR_DIRTY );
56690 if( pPg->pgno>pPager->dbSize ){ /* if (a) is false */
56691 Pgno pgno = pPg->pgno;
56692 int i;
56693 for(i=0; i<pPg->pPager->nSavepoint; i++){
56694 PagerSavepoint *p = &pPager->aSavepoint[i];
56695 assert( p->nOrig<pgno || sqlite3BitvecTestNotNull(p->pInSavepoint,pgno) );
56696 }
56697 }
56698 }
56699 static void assertTruncateConstraint(Pager *pPager){
56700 sqlite3PcacheIterateDirty(pPager->pPCache, assertTruncateConstraintCb);
56701 }
56702 #else
@@ -58022,11 +58033,11 @@
58033 ** other connection managed to get in and roll it back before
58034 ** this connection obtained the exclusive lock above. Or, it
58035 ** may mean that the pager was in the error-state when this
58036 ** function was called and the journal file does not exist.
58037 */
58038 if( !isOpen(pPager->jfd) && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
58039 sqlite3_vfs * const pVfs = pPager->pVfs;
58040 int bExists; /* True if journal file exists */
58041 rc = sqlite3OsAccess(
58042 pVfs, pPager->zJournal, SQLITE_ACCESS_EXISTS, &bExists);
58043 if( rc==SQLITE_OK && bExists ){
@@ -60029,16 +60040,16 @@
60040 */
60041 SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *pPager, int eMode){
60042 u8 eOld = pPager->journalMode; /* Prior journalmode */
60043
60044 /* The eMode parameter is always valid */
60045 assert( eMode==PAGER_JOURNALMODE_DELETE /* 0 */
60046 || eMode==PAGER_JOURNALMODE_PERSIST /* 1 */
60047 || eMode==PAGER_JOURNALMODE_OFF /* 2 */
60048 || eMode==PAGER_JOURNALMODE_TRUNCATE /* 3 */
60049 || eMode==PAGER_JOURNALMODE_MEMORY /* 4 */
60050 || eMode==PAGER_JOURNALMODE_WAL /* 5 */ );
60051
60052 /* This routine is only called from the OP_JournalMode opcode, and
60053 ** the logic there will never allow a temporary file to be changed
60054 ** to WAL mode.
60055 */
@@ -60071,11 +60082,10 @@
60082 assert( (PAGER_JOURNALMODE_OFF & 5)==0 );
60083 assert( (PAGER_JOURNALMODE_WAL & 5)==5 );
60084
60085 assert( isOpen(pPager->fd) || pPager->exclusiveMode );
60086 if( !pPager->exclusiveMode && (eOld & 5)==1 && (eMode & 1)==0 ){
 
60087 /* In this case we would like to delete the journal file. If it is
60088 ** not possible, then that is not a problem. Deleting the journal file
60089 ** here is an optimization only.
60090 **
60091 ** Before deleting the journal file, obtain a RESERVED lock on the
@@ -66904,22 +66914,36 @@
66914
66915 /* The next block of code is equivalent to:
66916 **
66917 ** pIter += getVarint(pIter, (u64*)&pInfo->nKey);
66918 **
66919 ** The code is inlined and the loop is unrolled for performance.
66920 ** This routine is a high-runner.
66921 */
66922 iKey = *pIter;
66923 if( iKey>=0x80 ){
66924 u8 x;
66925 iKey = ((iKey&0x7f)<<7) | ((x = *++pIter) & 0x7f);
66926 if( x>=0x80 ){
66927 iKey = (iKey<<7) | ((x =*++pIter) & 0x7f);
66928 if( x>=0x80 ){
66929 iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
66930 if( x>=0x80 ){
66931 iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
66932 if( x>=0x80 ){
66933 iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
66934 if( x>=0x80 ){
66935 iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
66936 if( x>=0x80 ){
66937 iKey = (iKey<<7) | ((x = *++pIter) & 0x7f);
66938 if( x>=0x80 ){
66939 iKey = (iKey<<8) | (*++pIter);
66940 }
66941 }
66942 }
66943 }
66944 }
66945 }
66946 }
66947 }
66948 pIter++;
66949
@@ -71240,11 +71264,10 @@
71264 assert( pPage->intKey );
71265 lwr = 0;
71266 upr = pPage->nCell-1;
71267 assert( biasRight==0 || biasRight==1 );
71268 idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */
 
71269 for(;;){
71270 i64 nCellKey;
71271 pCell = findCellPastPtr(pPage, idx);
71272 if( pPage->intKeyLeaf ){
71273 while( 0x80 <= *(pCell++) ){
@@ -71382,11 +71405,10 @@
71405 assert( pPage->nCell>0 );
71406 assert( pPage->intKey==(pIdxKey==0) );
71407 lwr = 0;
71408 upr = pPage->nCell-1;
71409 idx = upr>>1; /* idx = (lwr+upr)/2; */
 
71410 for(;;){
71411 int nCell; /* Size of the pCell cell in bytes */
71412 pCell = findCellPastPtr(pPage, idx);
71413
71414 /* The maximum supported page-size is 65536 bytes. This means that
@@ -72498,17 +72520,19 @@
72520 u8 *ptr; /* Used to move bytes around within data[] */
72521 int rc; /* The return code */
72522 int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
72523
72524 if( *pRC ) return;
72525 assert( idx>=0 );
72526 assert( idx<pPage->nCell );
72527 assert( CORRUPT_DB || sz==cellSize(pPage, idx) );
72528 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
72529 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
72530 assert( pPage->nFree>=0 );
72531 data = pPage->aData;
72532 ptr = &pPage->aCellIdx[2*idx];
72533 assert( pPage->pBt->usableSize > (int)(ptr-data) );
72534 pc = get2byte(ptr);
72535 hdr = pPage->hdrOffset;
72536 testcase( pc==(u32)get2byte(&data[hdr+5]) );
72537 testcase( pc+sz==pPage->pBt->usableSize );
72538 if( pc+sz > pPage->pBt->usableSize ){
@@ -72799,11 +72823,11 @@
72823 int k; /* Current slot in pCArray->apEnd[] */
72824 u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */
72825
72826 assert( i<iEnd );
72827 j = get2byte(&aData[hdr+5]);
72828 if( j>(u32)usableSize ){ j = 0; }
72829 memcpy(&pTmp[j], &aData[j], usableSize - j);
72830
72831 for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
72832 pSrcEnd = pCArray->apEnd[k];
72833
@@ -73030,11 +73054,11 @@
73054 nCell -= nTail;
73055 }
73056
73057 pData = &aData[get2byteNotZero(&aData[hdr+5])];
73058 if( pData<pBegin ) goto editpage_fail;
73059 if( pData>pPg->aDataEnd ) goto editpage_fail;
73060
73061 /* Add cells to the start of the page */
73062 if( iNew<iOld ){
73063 int nAdd = MIN(nNew,iOld-iNew);
73064 assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
@@ -74906,18 +74930,17 @@
74930 ** but which might be used by alternative storage engines.
74931 */
74932 SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
74933 Btree *p = pCur->pBtree;
74934 BtShared *pBt = p->pBt;
74935 int rc; /* Return code */
74936 MemPage *pPage; /* Page to delete cell from */
74937 unsigned char *pCell; /* Pointer to cell to delete */
74938 int iCellIdx; /* Index of cell to delete */
74939 int iCellDepth; /* Depth of node containing pCell */
74940 CellInfo info; /* Size of the cell being deleted */
74941 u8 bPreserve; /* Keep cursor valid. 2 for CURSOR_SKIPNEXT */
 
74942
74943 assert( cursorOwnsBtShared(pCur) );
74944 assert( pBt->inTransaction==TRANS_WRITE );
74945 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
74946 assert( pCur->curFlags & BTCF_WriteFlag );
@@ -74932,22 +74955,35 @@
74955 assert( CORRUPT_DB || pCur->eState==CURSOR_VALID );
74956
74957 iCellDepth = pCur->iPage;
74958 iCellIdx = pCur->ix;
74959 pPage = pCur->pPage;
74960 if( pPage->nCell<=iCellIdx ){
74961 return SQLITE_CORRUPT_BKPT;
74962 }
74963 pCell = findCell(pPage, iCellIdx);
74964 if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ){
74965 return SQLITE_CORRUPT_BKPT;
74966 }
74967
74968 /* If the BTREE_SAVEPOSITION bit is on, then the cursor position must
74969 ** be preserved following this delete operation. If the current delete
74970 ** will cause a b-tree rebalance, then this is done by saving the cursor
74971 ** key and leaving the cursor in CURSOR_REQUIRESEEK state before
74972 ** returning.
74973 **
74974 ** If the current delete will not cause a rebalance, then the cursor
74975 ** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately
74976 ** before or after the deleted entry.
74977 **
74978 ** The bPreserve value records which path is required:
74979 **
74980 ** bPreserve==0 Not necessary to save the cursor position
74981 ** bPreserve==1 Use CURSOR_REQUIRESEEK to save the cursor position
74982 ** bPreserve==2 Cursor won't move. Set CURSOR_SKIPNEXT.
74983 */
74984 bPreserve = (flags & BTREE_SAVEPOSITION)!=0;
74985 if( bPreserve ){
74986 if( !pPage->leaf
74987 || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
74988 || pPage->nCell==1 /* See dbfuzz001.test for a test case */
74989 ){
@@ -74954,11 +74990,11 @@
74990 /* A b-tree rebalance will be required after deleting this entry.
74991 ** Save the cursor key. */
74992 rc = saveCursorKey(pCur);
74993 if( rc ) return rc;
74994 }else{
74995 bPreserve = 2;
74996 }
74997 }
74998
74999 /* If the page containing the entry to delete is not a leaf page, move
75000 ** the cursor to the largest entry in the tree that is smaller than
@@ -75054,12 +75090,12 @@
75090 pCur->pPage = pCur->apPage[pCur->iPage];
75091 rc = balance(pCur);
75092 }
75093
75094 if( rc==SQLITE_OK ){
75095 if( bPreserve>1 ){
75096 assert( (pCur->iPage==iCellDepth || CORRUPT_DB) );
75097 assert( pPage==pCur->pPage || CORRUPT_DB );
75098 assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
75099 pCur->eState = CURSOR_SKIPNEXT;
75100 if( iCellIdx>=pPage->nCell ){
75101 pCur->skipNext = -1;
@@ -81753,12 +81789,10 @@
81789 */
81790 SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){
81791 if( pCx==0 ){
81792 return;
81793 }
 
 
81794 switch( pCx->eCurType ){
81795 case CURTYPE_SORTER: {
81796 sqlite3VdbeSorterClose(p->db, pCx);
81797 break;
81798 }
@@ -82856,11 +82890,11 @@
82890 VdbeCursor *p = *pp;
82891 assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO );
82892 if( p->deferredMoveto ){
82893 u32 iMap;
82894 assert( !p->isEphemeral );
82895 if( p->ub.aAltMap && (iMap = p->ub.aAltMap[1+*piCol])>0 && !p->nullRow ){
82896 *pp = p->pAltCursor;
82897 *piCol = iMap - 1;
82898 return SQLITE_OK;
82899 }
82900 return sqlite3VdbeFinishMoveto(p);
@@ -87057,11 +87091,10 @@
87091 */
87092 static VdbeCursor *allocateCursor(
87093 Vdbe *p, /* The virtual machine */
87094 int iCur, /* Index of the new VdbeCursor */
87095 int nField, /* Number of fields in the table or index */
 
87096 u8 eCurType /* Type of the new cursor */
87097 ){
87098 /* Find the memory cell that will be used to store the blob of memory
87099 ** required for this VdbeCursor structure. It is convenient to use a
87100 ** vdbe memory cell to manage the memory allocation required for a
@@ -87114,11 +87147,10 @@
87147 }
87148
87149 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->zMalloc;
87150 memset(pCx, 0, offsetof(VdbeCursor,pAltCursor));
87151 pCx->eCurType = eCurType;
 
87152 pCx->nField = nField;
87153 pCx->aOffset = &pCx->aType[nField];
87154 if( eCurType==CURTYPE_BTREE ){
87155 pCx->uc.pCursor = (BtCursor*)
87156 &pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField];
@@ -89508,10 +89540,11 @@
89540 pDest = &aMem[pOp->p3];
89541 memAboutToChange(p, pDest);
89542 assert( pC!=0 );
89543 assert( p2<(u32)pC->nField );
89544 aOffset = pC->aOffset;
89545 assert( aOffset==pC->aType+pC->nField );
89546 assert( pC->eCurType!=CURTYPE_VTAB );
89547 assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow );
89548 assert( pC->eCurType!=CURTYPE_SORTER );
89549
89550 if( pC->cacheStatus!=p->cacheCtr ){ /*OPTIMIZATION-IF-FALSE*/
@@ -90657,10 +90690,11 @@
90690 rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, pOp->p3);
90691 if( pOp->p2==BTREE_SCHEMA_VERSION ){
90692 /* When the schema cookie changes, record the new cookie internally */
90693 pDb->pSchema->schema_cookie = pOp->p3 - pOp->p5;
90694 db->mDbFlags |= DBFLAG_SchemaChange;
90695 sqlite3FkClearTriggerCache(db, pOp->p1);
90696 }else if( pOp->p2==BTREE_FILE_FORMAT ){
90697 /* Record changes in the file format */
90698 pDb->pSchema->file_format = pOp->p3;
90699 }
90700 if( pOp->p1==1 ){
@@ -90834,12 +90868,13 @@
90868 nField = pOp->p4.i;
90869 }
90870 assert( pOp->p1>=0 );
90871 assert( nField>=0 );
90872 testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
90873 pCur = allocateCursor(p, pOp->p1, nField, CURTYPE_BTREE);
90874 if( pCur==0 ) goto no_mem;
90875 pCur->iDb = iDb;
90876 pCur->nullRow = 1;
90877 pCur->isOrdered = 1;
90878 pCur->pgnoRoot = p2;
90879 #ifdef SQLITE_DEBUG
90880 pCur->wrFlag = wrFlag;
@@ -90877,22 +90912,22 @@
90912
90913 pOrig = p->apCsr[pOp->p2];
90914 assert( pOrig );
90915 assert( pOrig->isEphemeral ); /* Only ephemeral cursors can be duplicated */
90916
90917 pCx = allocateCursor(p, pOp->p1, pOrig->nField, CURTYPE_BTREE);
90918 if( pCx==0 ) goto no_mem;
90919 pCx->nullRow = 1;
90920 pCx->isEphemeral = 1;
90921 pCx->pKeyInfo = pOrig->pKeyInfo;
90922 pCx->isTable = pOrig->isTable;
90923 pCx->pgnoRoot = pOrig->pgnoRoot;
90924 pCx->isOrdered = pOrig->isOrdered;
90925 pCx->ub.pBtx = pOrig->ub.pBtx;
90926 pCx->hasBeenDuped = 1;
90927 pOrig->hasBeenDuped = 1;
90928 rc = sqlite3BtreeCursor(pCx->ub.pBtx, pCx->pgnoRoot, BTREE_WRCSR,
90929 pCx->pKeyInfo, pCx->uc.pCursor);
90930 /* The sqlite3BtreeCursor() routine can only fail for the first cursor
90931 ** opened for a database. Since there is already an open cursor when this
90932 ** opcode is run, the sqlite3BtreeCursor() cannot fail */
90933 assert( rc==SQLITE_OK );
@@ -90961,48 +90996,48 @@
90996 ** OP_OpenDup, then erase all existing content so that the table is
90997 ** empty again, rather than creating a new table. */
90998 assert( pCx->isEphemeral );
90999 pCx->seqCount = 0;
91000 pCx->cacheStatus = CACHE_STALE;
91001 rc = sqlite3BtreeClearTable(pCx->ub.pBtx, pCx->pgnoRoot, 0);
91002 }else{
91003 pCx = allocateCursor(p, pOp->p1, pOp->p2, CURTYPE_BTREE);
91004 if( pCx==0 ) goto no_mem;
91005 pCx->isEphemeral = 1;
91006 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->ub.pBtx,
91007 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5,
91008 vfsFlags);
91009 if( rc==SQLITE_OK ){
91010 rc = sqlite3BtreeBeginTrans(pCx->ub.pBtx, 1, 0);
91011 if( rc==SQLITE_OK ){
91012 /* If a transient index is required, create it by calling
91013 ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
91014 ** opening it. If a transient table is required, just use the
91015 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
91016 */
91017 if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
91018 assert( pOp->p4type==P4_KEYINFO );
91019 rc = sqlite3BtreeCreateTable(pCx->ub.pBtx, &pCx->pgnoRoot,
91020 BTREE_BLOBKEY | pOp->p5);
91021 if( rc==SQLITE_OK ){
91022 assert( pCx->pgnoRoot==SCHEMA_ROOT+1 );
91023 assert( pKeyInfo->db==db );
91024 assert( pKeyInfo->enc==ENC(db) );
91025 rc = sqlite3BtreeCursor(pCx->ub.pBtx, pCx->pgnoRoot, BTREE_WRCSR,
91026 pKeyInfo, pCx->uc.pCursor);
91027 }
91028 pCx->isTable = 0;
91029 }else{
91030 pCx->pgnoRoot = SCHEMA_ROOT;
91031 rc = sqlite3BtreeCursor(pCx->ub.pBtx, SCHEMA_ROOT, BTREE_WRCSR,
91032 0, pCx->uc.pCursor);
91033 pCx->isTable = 1;
91034 }
91035 }
91036 pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
91037 if( rc ){
91038 sqlite3BtreeClose(pCx->ub.pBtx);
91039 }
91040 }
91041 }
91042 if( rc ) goto abort_due_to_error;
91043 pCx->nullRow = 1;
@@ -91022,11 +91057,11 @@
91057 case OP_SorterOpen: {
91058 VdbeCursor *pCx;
91059
91060 assert( pOp->p1>=0 );
91061 assert( pOp->p2>=0 );
91062 pCx = allocateCursor(p, pOp->p1, pOp->p2, CURTYPE_SORTER);
91063 if( pCx==0 ) goto no_mem;
91064 pCx->pKeyInfo = pOp->p4.pKeyInfo;
91065 assert( pCx->pKeyInfo->db==db );
91066 assert( pCx->pKeyInfo->enc==ENC(db) );
91067 rc = sqlite3VdbeSorterInit(db, pOp->p3, pCx);
@@ -91071,11 +91106,11 @@
91106 case OP_OpenPseudo: {
91107 VdbeCursor *pCx;
91108
91109 assert( pOp->p1>=0 );
91110 assert( pOp->p3>=0 );
91111 pCx = allocateCursor(p, pOp->p1, pOp->p3, CURTYPE_PSEUDO);
91112 if( pCx==0 ) goto no_mem;
91113 pCx->nullRow = 1;
91114 pCx->seekResult = pOp->p2;
91115 pCx->isTable = 1;
91116 /* Give this pseudo-cursor a fake BtCursor pointer so that pCx
@@ -93011,13 +93046,13 @@
93046 assert( pTabCur->isTable );
93047 pTabCur->nullRow = 0;
93048 pTabCur->movetoTarget = rowid;
93049 pTabCur->deferredMoveto = 1;
93050 assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 );
 
 
93051 assert( !pTabCur->isEphemeral );
93052 pTabCur->ub.aAltMap = pOp->p4.ai;
93053 assert( !pC->isEphemeral );
93054 pTabCur->pAltCursor = pC;
93055 }else{
93056 pOut = out2Prerelease(p, pOp);
93057 pOut->u.i = rowid;
93058 }
@@ -94535,11 +94570,11 @@
94570
94571 /* Initialize sqlite3_vtab_cursor base class */
94572 pVCur->pVtab = pVtab;
94573
94574 /* Initialize vdbe cursor object */
94575 pCur = allocateCursor(p, pOp->p1, 0, CURTYPE_VTAB);
94576 if( pCur ){
94577 pCur->uc.pVCur = pVCur;
94578 pVtab->nRef++;
94579 }else{
94580 assert( db->mallocFailed );
@@ -96860,11 +96895,12 @@
96895 if( nWorker>=SORTER_MAX_MERGE_COUNT ){
96896 nWorker = SORTER_MAX_MERGE_COUNT-1;
96897 }
96898 #endif
96899
96900 assert( pCsr->pKeyInfo );
96901 assert( !pCsr->isEphemeral );
96902 assert( pCsr->eCurType==CURTYPE_SORTER );
96903 szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nKeyField-1)*sizeof(CollSeq*);
96904 sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask);
96905
96906 pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
@@ -99360,11 +99396,11 @@
99396 if( size==0 ){
99397 memjrnlFreeChunks(p->pFirst);
99398 p->pFirst = 0;
99399 }else{
99400 i64 iOff = p->nChunkSize;
99401 for(pIter=p->pFirst; ALWAYS(pIter) && iOff<size; pIter=pIter->pNext){
99402 iOff += p->nChunkSize;
99403 }
99404 if( ALWAYS(pIter) ){
99405 memjrnlFreeChunks(pIter->pNext);
99406 pIter->pNext = 0;
@@ -123463,10 +123499,29 @@
123499 sqlite3SelectDelete(dbMem, pStep->pSelect);
123500 sqlite3ExprDelete(dbMem, p->pWhen);
123501 sqlite3DbFree(dbMem, p);
123502 }
123503 }
123504
123505 /*
123506 ** Clear the apTrigger[] cache of CASCADE triggers for all foreign keys
123507 ** in a particular database. This needs to happen when the schema
123508 ** changes.
123509 */
123510 SQLITE_PRIVATE void sqlite3FkClearTriggerCache(sqlite3 *db, int iDb){
123511 HashElem *k;
123512 Hash *pHash = &db->aDb[iDb].pSchema->tblHash;
123513 for(k=sqliteHashFirst(pHash); k; k=sqliteHashNext(k)){
123514 Table *pTab = sqliteHashData(k);
123515 FKey *pFKey;
123516 if( !IsOrdinaryTable(pTab) ) continue;
123517 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
123518 fkTriggerDelete(db, pFKey->apTrigger[0]); pFKey->apTrigger[0] = 0;
123519 fkTriggerDelete(db, pFKey->apTrigger[1]); pFKey->apTrigger[1] = 0;
123520 }
123521 }
123522 }
123523
123524 /*
123525 ** This function is called to generate code that runs when table pTab is
123526 ** being dropped from the database. The SrcList passed as the second argument
123527 ** to this function contains a single entry guaranteed to resolve to
@@ -124264,11 +124319,11 @@
124319 sqlite3VdbeAddOp4Int(v, opcode, iCur, pTab->tnum, iDb, pTab->nNVCol);
124320 VdbeComment((v, "%s", pTab->zName));
124321 }else{
124322 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
124323 assert( pPk!=0 );
124324 assert( pPk->tnum==pTab->tnum || CORRUPT_DB );
124325 sqlite3VdbeAddOp3(v, opcode, iCur, pPk->tnum, iDb);
124326 sqlite3VdbeSetP4KeyInfo(pParse, pPk);
124327 VdbeComment((v, "%s", pTab->zName));
124328 }
124329 }
@@ -126768,11 +126823,10 @@
126823 sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
126824 VdbeCoverage(v);
126825 }
126826 pik_flags = (useSeekResult ? OPFLAG_USESEEKRESULT : 0);
126827 if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
 
126828 pik_flags |= OPFLAG_NCHANGE;
126829 pik_flags |= (update_flags & OPFLAG_SAVEPOSITION);
126830 if( update_flags==0 ){
126831 codeWithoutRowidPreupdate(pParse, pTab, iIdxCur+i, aRegIdx[i]);
126832 }
@@ -133183,11 +133237,11 @@
133237 if( db->mallocFailed ){
133238 sParse.rc = SQLITE_NOMEM_BKPT;
133239 sParse.checkSchema = 0;
133240 }
133241 if( sParse.rc!=SQLITE_OK && sParse.rc!=SQLITE_DONE ){
133242 if( sParse.checkSchema && db->init.busy==0 ){
133243 schemaIsValid(&sParse);
133244 }
133245 if( sParse.pVdbe ){
133246 sqlite3VdbeFinalize(sParse.pVdbe);
133247 }
@@ -142138,11 +142192,11 @@
142192 if( db->mallocFailed==0 && pParse->nErr==0 ){
142193 sqlite3GenerateColumnNames(pParse, &sSelect);
142194 }
142195 sqlite3ExprListDelete(db, sSelect.pEList);
142196 pNew = sqlite3ExpandReturning(pParse, pReturning->pReturnEL, pTab);
142197 if( !db->mallocFailed ){
142198 NameContext sNC;
142199 memset(&sNC, 0, sizeof(sNC));
142200 if( pReturning->nRetCol==0 ){
142201 pReturning->nRetCol = pNew->nExpr;
142202 pReturning->iRetCur = pParse->nTab++;
@@ -142150,33 +142204,34 @@
142204 sNC.pParse = pParse;
142205 sNC.uNC.iBaseReg = regIn;
142206 sNC.ncFlags = NC_UBaseReg;
142207 pParse->eTriggerOp = pTrigger->op;
142208 pParse->pTriggerTab = pTab;
142209 if( sqlite3ResolveExprListNames(&sNC, pNew)==SQLITE_OK
142210 && !db->mallocFailed
142211 ){
142212 int i;
142213 int nCol = pNew->nExpr;
142214 int reg = pParse->nMem+1;
142215 pParse->nMem += nCol+2;
142216 pReturning->iRetReg = reg;
142217 for(i=0; i<nCol; i++){
142218 Expr *pCol = pNew->a[i].pExpr;
142219 assert( pCol!=0 ); /* Due to !db->mallocFailed ~9 lines above */
 
142220 sqlite3ExprCodeFactorable(pParse, pCol, reg+i);
142221 if( sqlite3ExprAffinity(pCol)==SQLITE_AFF_REAL ){
142222 sqlite3VdbeAddOp1(v, OP_RealAffinity, reg+i);
142223 }
142224 }
142225 sqlite3VdbeAddOp3(v, OP_MakeRecord, reg, i, reg+i);
142226 sqlite3VdbeAddOp2(v, OP_NewRowid, pReturning->iRetCur, reg+i+1);
142227 sqlite3VdbeAddOp3(v, OP_Insert, pReturning->iRetCur, reg+i, reg+i+1);
142228 }
 
 
 
142229 }
142230 sqlite3ExprListDelete(db, pNew);
142231 pParse->eTriggerOp = 0;
142232 pParse->pTriggerTab = 0;
142233 }
142234
142235
142236
142237 /*
@@ -229243,11 +229298,11 @@
229298 assert( (flags & FTS5INDEX_QUERY_SCAN)==0 || flags==FTS5INDEX_QUERY_SCAN );
229299
229300 if( sqlite3Fts5BufferSize(&p->rc, &buf, nToken+1)==0 ){
229301 int iIdx = 0; /* Index to search */
229302 int iPrefixIdx = 0; /* +1 prefix index */
229303 if( nToken>0 ) memcpy(&buf.p[1], pToken, nToken);
229304
229305 /* Figure out which index to search and set iIdx accordingly. If this
229306 ** is a prefix query for which there is no prefix index, set iIdx to
229307 ** greater than pConfig->nPrefix to indicate that the query will be
229308 ** satisfied by scanning multiple terms in the main index.
@@ -233291,11 +233346,11 @@
233346 int nArg, /* Number of args */
233347 sqlite3_value **apUnused /* Function arguments */
233348 ){
233349 assert( nArg==0 );
233350 UNUSED_PARAM2(nArg, apUnused);
233351 sqlite3_result_text(pCtx, "fts5: 2022-01-06 17:13:56 2d6a16caa7d28ad5c766036b2eb6c2020683fcc9389b3c7df2013739929dd36f", -1, SQLITE_TRANSIENT);
233352 }
233353
233354 /*
233355 ** Return true if zName is the extension on one of the shadow tables used
233356 ** by this module.
233357
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.38.0"
150150
#define SQLITE_VERSION_NUMBER 3038000
151
-#define SQLITE_SOURCE_ID "2021-12-31 22:53:15 e654b57a9fc32021453eed48d1c1bba65c833fb1aac3946567968c877e4cbd10"
151
+#define SQLITE_SOURCE_ID "2022-01-06 17:13:56 2d6a16caa7d28ad5c766036b2eb6c2020683fcc9389b3c7df2013739929dd36f"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
157157
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.38.0"
150 #define SQLITE_VERSION_NUMBER 3038000
151 #define SQLITE_SOURCE_ID "2021-12-31 22:53:15 e654b57a9fc32021453eed48d1c1bba65c833fb1aac3946567968c877e4cbd10"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.38.0"
150 #define SQLITE_VERSION_NUMBER 3038000
151 #define SQLITE_SOURCE_ID "2022-01-06 17:13:56 2d6a16caa7d28ad5c766036b2eb6c2020683fcc9389b3c7df2013739929dd36f"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157

Keyboard Shortcuts

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