1
1
/******************************************************************************
2
2
** This file is an amalgamation of many separate C source files from SQLite
3
- ** version 3.40.0 . By combining all the individual C code files into this
3
+ ** version 3.40.1 . 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.40.0 "
456
- #define SQLITE_VERSION_NUMBER 3040000
457
- #define SQLITE_SOURCE_ID "2022-11-16 12:10:08 89c459e766ea7e9165d0beeb124708b955a4950d0f4792f457465d71b158d318 "
455
+ #define SQLITE_VERSION "3.40.1 "
456
+ #define SQLITE_VERSION_NUMBER 3040001
457
+ #define SQLITE_SOURCE_ID "2022-12-28 14:03:47 df5c253c0b3dd24916e4ec7cf77d3db5294cc9fd45ae7b9c5e82ad8197f38a24 "
458
458
459
459
/*
460
460
** CAPI3REF: Run-Time Library Version Numbers
@@ -1498,6 +1498,12 @@ struct sqlite3_io_methods {
1498
1498
**
1499
1499
** <li>[[SQLITE_FCNTL_CKSM_FILE]]
1500
1500
** Used by the cksmvfs VFS module only.
1501
+ **
1502
+ ** <li>[[SQLITE_FCNTL_RESET_CACHE]]
1503
+ ** If there is currently no transaction open on the database, and the
1504
+ ** database is not a temp db, then this file-control purges the contents
1505
+ ** of the in-memory page cache. If there is an open transaction, or if
1506
+ ** the db is a temp-db, it is a no-op, not an error.
1501
1507
** </ul>
1502
1508
*/
1503
1509
#define SQLITE_FCNTL_LOCKSTATE 1
@@ -1540,6 +1546,7 @@ struct sqlite3_io_methods {
1540
1546
#define SQLITE_FCNTL_CKPT_START 39
1541
1547
#define SQLITE_FCNTL_EXTERNAL_READER 40
1542
1548
#define SQLITE_FCNTL_CKSM_FILE 41
1549
+ #define SQLITE_FCNTL_RESET_CACHE 42
1543
1550
1544
1551
/* deprecated names */
1545
1552
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
@@ -15714,6 +15721,8 @@ SQLITE_PRIVATE int sqlite3BtreeCheckpoint(Btree*, int, int *, int *);
15714
15721
15715
15722
SQLITE_PRIVATE int sqlite3BtreeTransferRow(BtCursor*, BtCursor*, i64);
15716
15723
15724
+ SQLITE_PRIVATE void sqlite3BtreeClearCache(Btree*);
15725
+
15717
15726
/*
15718
15727
** If we are not using shared cache, then there is no need to
15719
15728
** use mutexes to access the BtShared structures. So make the
@@ -27290,9 +27299,13 @@ static int memsys5Roundup(int n){
27290
27299
if( n<=mem5.szAtom ) return mem5.szAtom;
27291
27300
return mem5.szAtom*2;
27292
27301
}
27293
- if( n>0x40000000 ) return 0;
27302
+ if( n>0x10000000 ){
27303
+ if( n>0x40000000 ) return 0;
27304
+ if( n>0x20000000 ) return 0x40000000;
27305
+ return 0x20000000;
27306
+ }
27294
27307
for(iFullSz=mem5.szAtom*8; iFullSz<n; iFullSz *= 4);
27295
- if( (iFullSz/2)>=n ) return iFullSz/2;
27308
+ if( (iFullSz/2)>=(i64) n ) return iFullSz/2;
27296
27309
return iFullSz;
27297
27310
}
27298
27311
@@ -37338,6 +37351,9 @@ static int robust_open(const char *z, int f, mode_t m){
37338
37351
break;
37339
37352
}
37340
37353
if( fd>=SQLITE_MINIMUM_FILE_DESCRIPTOR ) break;
37354
+ if( (f & (O_EXCL|O_CREAT))==(O_EXCL|O_CREAT) ){
37355
+ (void)osUnlink(z);
37356
+ }
37341
37357
osClose(fd);
37342
37358
sqlite3_log(SQLITE_WARNING,
37343
37359
"attempt to open \"%s\" as file descriptor %d", z, fd);
@@ -51071,6 +51087,7 @@ static int memdbTruncate(sqlite3_file*, sqlite3_int64 size);
51071
51087
static int memdbSync(sqlite3_file*, int flags);
51072
51088
static int memdbFileSize(sqlite3_file*, sqlite3_int64 *pSize);
51073
51089
static int memdbLock(sqlite3_file*, int);
51090
+ static int memdbUnlock(sqlite3_file*, int);
51074
51091
/* static int memdbCheckReservedLock(sqlite3_file*, int *pResOut);// not used */
51075
51092
static int memdbFileControl(sqlite3_file*, int op, void *pArg);
51076
51093
/* static int memdbSectorSize(sqlite3_file*); // not used */
@@ -51129,7 +51146,7 @@ static const sqlite3_io_methods memdb_io_methods = {
51129
51146
memdbSync, /* xSync */
51130
51147
memdbFileSize, /* xFileSize */
51131
51148
memdbLock, /* xLock */
51132
- memdbLock , /* xUnlock - same as xLock in this case */
51149
+ memdbUnlock , /* xUnlock */
51133
51150
0, /* memdbCheckReservedLock, */ /* xCheckReservedLock */
51134
51151
memdbFileControl, /* xFileControl */
51135
51152
0, /* memdbSectorSize,*/ /* xSectorSize */
@@ -51330,39 +51347,81 @@ static int memdbLock(sqlite3_file *pFile, int eLock){
51330
51347
MemFile *pThis = (MemFile*)pFile;
51331
51348
MemStore *p = pThis->pStore;
51332
51349
int rc = SQLITE_OK;
51333
- if( eLock= =pThis->eLock ) return SQLITE_OK;
51350
+ if( eLock< =pThis->eLock ) return SQLITE_OK;
51334
51351
memdbEnter(p);
51335
- if( eLock>SQLITE_LOCK_SHARED ){
51336
- if( p->mFlags & SQLITE_DESERIALIZE_READONLY ){
51337
- rc = SQLITE_READONLY;
51338
- }else if( pThis->eLock<=SQLITE_LOCK_SHARED ){
51339
- if( p->nWrLock ){
51340
- rc = SQLITE_BUSY;
51341
- }else{
51342
- p->nWrLock = 1;
51352
+
51353
+ assert( p->nWrLock==0 || p->nWrLock==1 );
51354
+ assert( pThis->eLock<=SQLITE_LOCK_SHARED || p->nWrLock==1 );
51355
+ assert( pThis->eLock==SQLITE_LOCK_NONE || p->nRdLock>=1 );
51356
+
51357
+ if( eLock>SQLITE_LOCK_SHARED && (p->mFlags & SQLITE_DESERIALIZE_READONLY) ){
51358
+ rc = SQLITE_READONLY;
51359
+ }else{
51360
+ switch( eLock ){
51361
+ case SQLITE_LOCK_SHARED: {
51362
+ assert( pThis->eLock==SQLITE_LOCK_NONE );
51363
+ if( p->nWrLock>0 ){
51364
+ rc = SQLITE_BUSY;
51365
+ }else{
51366
+ p->nRdLock++;
51367
+ }
51368
+ break;
51369
+ };
51370
+
51371
+ case SQLITE_LOCK_RESERVED:
51372
+ case SQLITE_LOCK_PENDING: {
51373
+ assert( pThis->eLock>=SQLITE_LOCK_SHARED );
51374
+ if( ALWAYS(pThis->eLock==SQLITE_LOCK_SHARED) ){
51375
+ if( p->nWrLock>0 ){
51376
+ rc = SQLITE_BUSY;
51377
+ }else{
51378
+ p->nWrLock = 1;
51379
+ }
51380
+ }
51381
+ break;
51382
+ }
51383
+
51384
+ default: {
51385
+ assert( eLock==SQLITE_LOCK_EXCLUSIVE );
51386
+ assert( pThis->eLock>=SQLITE_LOCK_SHARED );
51387
+ if( p->nRdLock>1 ){
51388
+ rc = SQLITE_BUSY;
51389
+ }else if( pThis->eLock==SQLITE_LOCK_SHARED ){
51390
+ p->nWrLock = 1;
51391
+ }
51392
+ break;
51343
51393
}
51344
51394
}
51345
- }else if( eLock==SQLITE_LOCK_SHARED ){
51346
- if( pThis->eLock > SQLITE_LOCK_SHARED ){
51347
- assert( p->nWrLock==1 );
51348
- p->nWrLock = 0;
51349
- }else if( p->nWrLock ){
51350
- rc = SQLITE_BUSY;
51351
- }else{
51352
- p->nRdLock++;
51395
+ }
51396
+ if( rc==SQLITE_OK ) pThis->eLock = eLock;
51397
+ memdbLeave(p);
51398
+ return rc;
51399
+ }
51400
+
51401
+ /*
51402
+ ** Unlock an memdb-file.
51403
+ */
51404
+ static int memdbUnlock(sqlite3_file *pFile, int eLock){
51405
+ MemFile *pThis = (MemFile*)pFile;
51406
+ MemStore *p = pThis->pStore;
51407
+ if( eLock>=pThis->eLock ) return SQLITE_OK;
51408
+ memdbEnter(p);
51409
+
51410
+ assert( eLock==SQLITE_LOCK_SHARED || eLock==SQLITE_LOCK_NONE );
51411
+ if( eLock==SQLITE_LOCK_SHARED ){
51412
+ if( ALWAYS(pThis->eLock>SQLITE_LOCK_SHARED) ){
51413
+ p->nWrLock--;
51353
51414
}
51354
51415
}else{
51355
- assert( eLock==SQLITE_LOCK_NONE );
51356
51416
if( pThis->eLock>SQLITE_LOCK_SHARED ){
51357
- assert( p->nWrLock==1 );
51358
- p->nWrLock = 0;
51417
+ p->nWrLock--;
51359
51418
}
51360
- assert( p->nRdLock>0 );
51361
51419
p->nRdLock--;
51362
51420
}
51363
- if( rc==SQLITE_OK ) pThis->eLock = eLock;
51421
+
51422
+ pThis->eLock = eLock;
51364
51423
memdbLeave(p);
51365
- return rc ;
51424
+ return SQLITE_OK ;
51366
51425
}
51367
51426
51368
51427
#if 0
@@ -51472,7 +51531,7 @@ static int memdbOpen(
51472
51531
51473
51532
memset(pFile, 0, sizeof(*pFile));
51474
51533
szName = sqlite3Strlen30(zName);
51475
- if( szName>1 && zName[0]=='/' ){
51534
+ if( szName>1 && ( zName[0]=='/' || zName[0]=='\\') ){
51476
51535
int i;
51477
51536
#ifndef SQLITE_MUTEX_OMIT
51478
51537
sqlite3_mutex *pVfsMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
@@ -51819,6 +51878,13 @@ SQLITE_API int sqlite3_deserialize(
51819
51878
return rc;
51820
51879
}
51821
51880
51881
+ /*
51882
+ ** Return true if the VFS is the memvfs.
51883
+ */
51884
+ SQLITE_PRIVATE int sqlite3IsMemdb(const sqlite3_vfs *pVfs){
51885
+ return pVfs==&memdb_vfs;
51886
+ }
51887
+
51822
51888
/*
51823
51889
** This routine is called when the extension is loaded.
51824
51890
** Register the new VFS.
@@ -79147,6 +79213,17 @@ SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *p){
79147
79213
*/
79148
79214
SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return ROUND8(sizeof(MemPage)); }
79149
79215
79216
+ /*
79217
+ ** If no transaction is active and the database is not a temp-db, clear
79218
+ ** the in-memory pager cache.
79219
+ */
79220
+ SQLITE_PRIVATE void sqlite3BtreeClearCache(Btree *p){
79221
+ BtShared *pBt = p->pBt;
79222
+ if( pBt->inTransaction==TRANS_NONE ){
79223
+ sqlite3PagerClearCache(pBt->pPager);
79224
+ }
79225
+ }
79226
+
79150
79227
#if !defined(SQLITE_OMIT_SHARED_CACHE)
79151
79228
/*
79152
79229
** Return true if the Btree passed as the only argument is sharable.
@@ -83386,7 +83463,7 @@ SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe *p, void *pP4, int n){
83386
83463
if( p->db->mallocFailed ){
83387
83464
freeP4(p->db, n, pP4);
83388
83465
}else{
83389
- assert( pP4!=0 );
83466
+ assert( pP4!=0 || n==P4_DYNAMIC );
83390
83467
assert( p->nOp>0 );
83391
83468
pOp = &p->aOp[p->nOp-1];
83392
83469
assert( pOp->p4type==P4_NOTUSED );
@@ -132298,7 +132375,7 @@ static const sqlite3_api_routines sqlite3Apis = {
132298
132375
#endif
132299
132376
sqlite3_db_name,
132300
132377
/* Version 3.40.0 and later */
132301
- sqlite3_value_type
132378
+ sqlite3_value_encoding
132302
132379
};
132303
132380
132304
132381
/* True if x is the directory separator character
@@ -145439,7 +145516,7 @@ SQLITE_PRIVATE Trigger *sqlite3TriggerList(Parse *pParse, Table *pTab){
145439
145516
if( pTrig->pTabSchema==pTab->pSchema
145440
145517
&& pTrig->table
145441
145518
&& 0==sqlite3StrICmp(pTrig->table, pTab->zName)
145442
- && pTrig->pTabSchema!=pTmpSchema
145519
+ && ( pTrig->pTabSchema!=pTmpSchema || pTrig->bReturning)
145443
145520
){
145444
145521
pTrig->pNext = pList;
145445
145522
pList = pTrig;
@@ -155623,7 +155700,7 @@ SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo *pWInfo){
155623
155700
** block sorting is required.
155624
155701
*/
155625
155702
SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo *pWInfo){
155626
- return pWInfo->nOBSat;
155703
+ return pWInfo->nOBSat<0 ? 0 : pWInfo->nOBSat ;
155627
155704
}
155628
155705
155629
155706
/*
@@ -174531,7 +174608,7 @@ SQLITE_API int sqlite3_overload_function(
174531
174608
rc = sqlite3FindFunction(db, zName, nArg, SQLITE_UTF8, 0)!=0;
174532
174609
sqlite3_mutex_leave(db->mutex);
174533
174610
if( rc ) return SQLITE_OK;
174534
- zCopy = sqlite3_mprintf(zName);
174611
+ zCopy = sqlite3_mprintf("%s", zName);
174535
174612
if( zCopy==0 ) return SQLITE_NOMEM;
174536
174613
return sqlite3_create_function_v2(db, zName, nArg, SQLITE_UTF8,
174537
174614
zCopy, sqlite3InvalidFunction, 0, 0, sqlite3_free);
@@ -176363,6 +176440,9 @@ SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, vo
176363
176440
sqlite3BtreeSetPageSize(pBtree, 0, iNew, 0);
176364
176441
}
176365
176442
rc = SQLITE_OK;
176443
+ }else if( op==SQLITE_FCNTL_RESET_CACHE ){
176444
+ sqlite3BtreeClearCache(pBtree);
176445
+ rc = SQLITE_OK;
176366
176446
}else{
176367
176447
int nSave = db->busyHandler.nBusy;
176368
176448
rc = sqlite3OsFileControl(fd, op, pArg);
@@ -217778,6 +217858,22 @@ static int sessionChangesetNextOne(
217778
217858
if( p->op==SQLITE_INSERT ) p->op = SQLITE_DELETE;
217779
217859
else if( p->op==SQLITE_DELETE ) p->op = SQLITE_INSERT;
217780
217860
}
217861
+
217862
+ /* If this is an UPDATE that is part of a changeset, then check that
217863
+ ** there are no fields in the old.* record that are not (a) PK fields,
217864
+ ** or (b) also present in the new.* record.
217865
+ **
217866
+ ** Such records are technically corrupt, but the rebaser was at one
217867
+ ** point generating them. Under most circumstances this is benign, but
217868
+ ** can cause spurious SQLITE_RANGE errors when applying the changeset. */
217869
+ if( p->bPatchset==0 && p->op==SQLITE_UPDATE){
217870
+ for(i=0; i<p->nCol; i++){
217871
+ if( p->abPK[i]==0 && p->apValue[i+p->nCol]==0 ){
217872
+ sqlite3ValueFree(p->apValue[i]);
217873
+ p->apValue[i] = 0;
217874
+ }
217875
+ }
217876
+ }
217781
217877
}
217782
217878
217783
217879
return SQLITE_ROW;
@@ -219974,7 +220070,7 @@ static void sessionAppendPartialUpdate(
219974
220070
if( !pIter->abPK[i] && a1[0] ) bData = 1;
219975
220071
memcpy(pOut, a1, n1);
219976
220072
pOut += n1;
219977
- }else if( a2[0]!=0xFF ){
220073
+ }else if( a2[0]!=0xFF && a1[0] ){
219978
220074
bData = 1;
219979
220075
memcpy(pOut, a2, n2);
219980
220076
pOut += n2;
@@ -236004,7 +236100,7 @@ static void fts5CheckTransactionState(Fts5FullTable *p, int op, int iSavepoint){
236004
236100
break;
236005
236101
236006
236102
case FTS5_SYNC:
236007
- assert( p->ts.eState==1 );
236103
+ assert( p->ts.eState==1 || p->ts.eState==2 );
236008
236104
p->ts.eState = 2;
236009
236105
break;
236010
236106
@@ -236019,21 +236115,21 @@ static void fts5CheckTransactionState(Fts5FullTable *p, int op, int iSavepoint){
236019
236115
break;
236020
236116
236021
236117
case FTS5_SAVEPOINT:
236022
- assert( p->ts.eState= =1 );
236118
+ assert( p->ts.eState> =1 );
236023
236119
assert( iSavepoint>=0 );
236024
236120
assert( iSavepoint>=p->ts.iSavepoint );
236025
236121
p->ts.iSavepoint = iSavepoint;
236026
236122
break;
236027
236123
236028
236124
case FTS5_RELEASE:
236029
- assert( p->ts.eState= =1 );
236125
+ assert( p->ts.eState> =1 );
236030
236126
assert( iSavepoint>=0 );
236031
236127
assert( iSavepoint<=p->ts.iSavepoint );
236032
236128
p->ts.iSavepoint = iSavepoint-1;
236033
236129
break;
236034
236130
236035
236131
case FTS5_ROLLBACKTO:
236036
- assert( p->ts.eState= =1 );
236132
+ assert( p->ts.eState> =1 );
236037
236133
assert( iSavepoint>=-1 );
236038
236134
/* The following assert() can fail if another vtab strikes an error
236039
236135
** within an xSavepoint() call then SQLite calls xRollbackTo() - without
@@ -237369,7 +237465,7 @@ static int fts5UpdateMethod(
237369
237465
int rc = SQLITE_OK; /* Return code */
237370
237466
237371
237467
/* A transaction must be open when this is called. */
237372
- assert( pTab->ts.eState==1 );
237468
+ assert( pTab->ts.eState==1 || pTab->ts.eState==2 );
237373
237469
237374
237470
assert( pVtab->zErrMsg==0 );
237375
237471
assert( nArg==1 || nArg==(2+pConfig->nCol+2) );
@@ -238537,7 +238633,7 @@ static void fts5SourceIdFunc(
238537
238633
){
238538
238634
assert( nArg==0 );
238539
238635
UNUSED_PARAM2(nArg, apUnused);
238540
- sqlite3_result_text(pCtx, "fts5: 2022-11-16 12:10:08 89c459e766ea7e9165d0beeb124708b955a4950d0f4792f457465d71b158d318 ", -1, SQLITE_TRANSIENT);
238636
+ sqlite3_result_text(pCtx, "fts5: 2022-12-28 14:03:47 df5c253c0b3dd24916e4ec7cf77d3db5294cc9fd45ae7b9c5e82ad8197f38a24 ", -1, SQLITE_TRANSIENT);
238541
238637
}
238542
238638
238543
238639
/*
0 commit comments