1
1
/******************************************************************************
2
2
** This file is an amalgamation of many separate C source files from SQLite
3
- ** version 3.39.2 . By combining all the individual C code files into this
3
+ ** version 3.39.3 . 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.39.2 "
456
- #define SQLITE_VERSION_NUMBER 3039002
457
- #define SQLITE_SOURCE_ID "2022-07-21 15:24:47 698edb77537b67c41adc68f9b892db56bcf9a55e00371a61420f3ddd668e6603 "
455
+ #define SQLITE_VERSION "3.39.3 "
456
+ #define SQLITE_VERSION_NUMBER 3039003
457
+ #define SQLITE_SOURCE_ID "2022-09-05 11:02:23 4635f4a69c8c2a8df242b384a992aea71224e39a2ccab42d8c0b0602f1e826e8 "
458
458
459
459
/*
460
460
** CAPI3REF: Run-Time Library Version Numbers
@@ -13144,6 +13144,11 @@ struct fts5_api {
13144
13144
/************** End of sqlite3.h *********************************************/
13145
13145
/************** Continuing where we left off in sqliteInt.h ******************/
13146
13146
13147
+ /*
13148
+ ** Reuse the STATIC_LRU for mutex access to sqlite3_temp_directory.
13149
+ */
13150
+ #define SQLITE_MUTEX_STATIC_TEMPDIR SQLITE_MUTEX_STATIC_VFS1
13151
+
13147
13152
/*
13148
13153
** Include the configuration header output by 'configure' if we're using the
13149
13154
** autoconf-based build
@@ -29563,8 +29568,13 @@ SQLITE_PRIVATE void *sqlite3OomFault(sqlite3 *db){
29563
29568
}
29564
29569
DisableLookaside;
29565
29570
if( db->pParse ){
29571
+ Parse *pParse;
29566
29572
sqlite3ErrorMsg(db->pParse, "out of memory");
29567
29573
db->pParse->rc = SQLITE_NOMEM_BKPT;
29574
+ for(pParse=db->pParse->pOuterParse; pParse; pParse = pParse->pOuterParse){
29575
+ pParse->nErr++;
29576
+ pParse->rc = SQLITE_NOMEM;
29577
+ }
29568
29578
}
29569
29579
}
29570
29580
return 0;
@@ -33459,7 +33469,7 @@ SQLITE_PRIVATE void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){
33459
33469
va_list ap;
33460
33470
sqlite3 *db = pParse->db;
33461
33471
assert( db!=0 );
33462
- assert( db->pParse==pParse );
33472
+ assert( db->pParse==pParse || db->pParse->pToplevel==pParse );
33463
33473
db->errByteOffset = -2;
33464
33474
va_start(ap, zFormat);
33465
33475
zMsg = sqlite3VMPrintf(db, zFormat, ap);
@@ -41320,6 +41330,7 @@ static const char *unixTempFileDir(void){
41320
41330
static int unixGetTempname(int nBuf, char *zBuf){
41321
41331
const char *zDir;
41322
41332
int iLimit = 0;
41333
+ int rc = SQLITE_OK;
41323
41334
41324
41335
/* It's odd to simulate an io-error here, but really this is just
41325
41336
** using the io-error infrastructure to test that SQLite handles this
@@ -41328,18 +41339,26 @@ static int unixGetTempname(int nBuf, char *zBuf){
41328
41339
zBuf[0] = 0;
41329
41340
SimulateIOError( return SQLITE_IOERR );
41330
41341
41342
+ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
41331
41343
zDir = unixTempFileDir();
41332
- if( zDir==0 ) return SQLITE_IOERR_GETTEMPPATH;
41333
- do{
41334
- u64 r;
41335
- sqlite3_randomness(sizeof(r), &r);
41336
- assert( nBuf>2 );
41337
- zBuf[nBuf-2] = 0;
41338
- sqlite3_snprintf(nBuf, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX"%llx%c",
41339
- zDir, r, 0);
41340
- if( zBuf[nBuf-2]!=0 || (iLimit++)>10 ) return SQLITE_ERROR;
41341
- }while( osAccess(zBuf,0)==0 );
41342
- return SQLITE_OK;
41344
+ if( zDir==0 ){
41345
+ rc = SQLITE_IOERR_GETTEMPPATH;
41346
+ }else{
41347
+ do{
41348
+ u64 r;
41349
+ sqlite3_randomness(sizeof(r), &r);
41350
+ assert( nBuf>2 );
41351
+ zBuf[nBuf-2] = 0;
41352
+ sqlite3_snprintf(nBuf, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX"%llx%c",
41353
+ zDir, r, 0);
41354
+ if( zBuf[nBuf-2]!=0 || (iLimit++)>10 ){
41355
+ rc = SQLITE_ERROR;
41356
+ break;
41357
+ }
41358
+ }while( osAccess(zBuf,0)==0 );
41359
+ }
41360
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
41361
+ return rc;
41343
41362
}
41344
41363
41345
41364
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
@@ -45482,6 +45501,7 @@ SQLITE_API int sqlite3_win32_set_directory8(
45482
45501
int rc = sqlite3_initialize();
45483
45502
if( rc ) return rc;
45484
45503
#endif
45504
+ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
45485
45505
if( type==SQLITE_WIN32_DATA_DIRECTORY_TYPE ){
45486
45506
ppDirectory = &sqlite3_data_directory;
45487
45507
}else if( type==SQLITE_WIN32_TEMP_DIRECTORY_TYPE ){
@@ -45496,14 +45516,19 @@ SQLITE_API int sqlite3_win32_set_directory8(
45496
45516
if( zValue && zValue[0] ){
45497
45517
zCopy = sqlite3_mprintf("%s", zValue);
45498
45518
if ( zCopy==0 ){
45499
- return SQLITE_NOMEM_BKPT;
45519
+ rc = SQLITE_NOMEM_BKPT;
45520
+ goto set_directory8_done;
45500
45521
}
45501
45522
}
45502
45523
sqlite3_free(*ppDirectory);
45503
45524
*ppDirectory = zCopy;
45504
- return SQLITE_OK;
45525
+ rc = SQLITE_OK;
45526
+ }else{
45527
+ rc = SQLITE_ERROR;
45505
45528
}
45506
- return SQLITE_ERROR;
45529
+ set_directory8_done:
45530
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
45531
+ return rc;
45507
45532
}
45508
45533
45509
45534
/*
@@ -48277,6 +48302,18 @@ static int winMakeEndInDirSep(int nBuf, char *zBuf){
48277
48302
return 0;
48278
48303
}
48279
48304
48305
+ /*
48306
+ ** If sqlite3_temp_directory is not, take the mutex and return true.
48307
+ **
48308
+ ** If sqlite3_temp_directory is NULL, omit the mutex and return false.
48309
+ */
48310
+ static int winTempDirDefined(void){
48311
+ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
48312
+ if( sqlite3_temp_directory!=0 ) return 1;
48313
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
48314
+ return 0;
48315
+ }
48316
+
48280
48317
/*
48281
48318
** Create a temporary file name and store the resulting pointer into pzBuf.
48282
48319
** The pointer returned in pzBuf must be freed via sqlite3_free().
@@ -48313,20 +48350,23 @@ static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){
48313
48350
*/
48314
48351
nDir = nMax - (nPre + 15);
48315
48352
assert( nDir>0 );
48316
- if( sqlite3_temp_directory ){
48353
+ if( winTempDirDefined() ){
48317
48354
int nDirLen = sqlite3Strlen30(sqlite3_temp_directory);
48318
48355
if( nDirLen>0 ){
48319
48356
if( !winIsDirSep(sqlite3_temp_directory[nDirLen-1]) ){
48320
48357
nDirLen++;
48321
48358
}
48322
48359
if( nDirLen>nDir ){
48360
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
48323
48361
sqlite3_free(zBuf);
48324
48362
OSTRACE(("TEMP-FILENAME rc=SQLITE_ERROR\n"));
48325
48363
return winLogError(SQLITE_ERROR, 0, "winGetTempname1", 0);
48326
48364
}
48327
48365
sqlite3_snprintf(nMax, zBuf, "%s", sqlite3_temp_directory);
48328
48366
}
48367
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
48329
48368
}
48369
+
48330
48370
#if defined(__CYGWIN__)
48331
48371
else{
48332
48372
static const char *azDirs[] = {
@@ -49115,7 +49155,7 @@ static BOOL winIsVerbatimPathname(
49115
49155
** pathname into zOut[]. zOut[] will be at least pVfs->mxPathname
49116
49156
** bytes in size.
49117
49157
*/
49118
- static int winFullPathname (
49158
+ static int winFullPathnameNoMutex (
49119
49159
sqlite3_vfs *pVfs, /* Pointer to vfs object */
49120
49160
const char *zRelative, /* Possibly relative input path */
49121
49161
int nFull, /* Size of output buffer in bytes */
@@ -49294,6 +49334,19 @@ static int winFullPathname(
49294
49334
}
49295
49335
#endif
49296
49336
}
49337
+ static int winFullPathname(
49338
+ sqlite3_vfs *pVfs, /* Pointer to vfs object */
49339
+ const char *zRelative, /* Possibly relative input path */
49340
+ int nFull, /* Size of output buffer in bytes */
49341
+ char *zFull /* Output buffer */
49342
+ ){
49343
+ int rc;
49344
+ sqlite3_mutex *pMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR);
49345
+ sqlite3_mutex_enter(pMutex);
49346
+ rc = winFullPathnameNoMutex(pVfs, zRelative, nFull, zFull);
49347
+ sqlite3_mutex_leave(pMutex);
49348
+ return rc;
49349
+ }
49297
49350
49298
49351
#ifndef SQLITE_OMIT_LOAD_EXTENSION
49299
49352
/*
@@ -59676,6 +59729,7 @@ static int pager_open_journal(Pager *pPager){
59676
59729
if( rc!=SQLITE_OK ){
59677
59730
sqlite3BitvecDestroy(pPager->pInJournal);
59678
59731
pPager->pInJournal = 0;
59732
+ pPager->journalOff = 0;
59679
59733
}else{
59680
59734
assert( pPager->eState==PAGER_WRITER_LOCKED );
59681
59735
pPager->eState = PAGER_WRITER_CACHEMOD;
@@ -61231,7 +61285,7 @@ SQLITE_PRIVATE int sqlite3PagerGetJournalMode(Pager *pPager){
61231
61285
SQLITE_PRIVATE int sqlite3PagerOkToChangeJournalMode(Pager *pPager){
61232
61286
assert( assert_pager_state(pPager) );
61233
61287
if( pPager->eState>=PAGER_WRITER_CACHEMOD ) return 0;
61234
- if( NEVER( isOpen(pPager->jfd) && pPager->journalOff>0) ) return 0;
61288
+ if( isOpen(pPager->jfd) && pPager->journalOff>0 ) return 0;
61235
61289
return 1;
61236
61290
}
61237
61291
@@ -81035,6 +81089,7 @@ SQLITE_PRIVATE int sqlite3VdbeAddFunctionCall(
81035
81089
addr = sqlite3VdbeAddOp4(v, eCallCtx ? OP_PureFunc : OP_Function,
81036
81090
p1, p2, p3, (char*)pCtx, P4_FUNCCTX);
81037
81091
sqlite3VdbeChangeP5(v, eCallCtx & NC_SelfRef);
81092
+ sqlite3MayAbort(pParse);
81038
81093
return addr;
81039
81094
}
81040
81095
@@ -81370,6 +81425,7 @@ SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){
81370
81425
|| opcode==OP_VDestroy
81371
81426
|| opcode==OP_VCreate
81372
81427
|| opcode==OP_ParseSchema
81428
+ || opcode==OP_Function || opcode==OP_PureFunc
81373
81429
|| ((opcode==OP_Halt || opcode==OP_HaltIfNull)
81374
81430
&& ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
81375
81431
){
@@ -132704,6 +132760,7 @@ SQLITE_PRIVATE void sqlite3Pragma(
132704
132760
**
132705
132761
*/
132706
132762
case PragTyp_TEMP_STORE_DIRECTORY: {
132763
+ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
132707
132764
if( !zRight ){
132708
132765
returnSingleText(v, sqlite3_temp_directory);
132709
132766
}else{
@@ -132713,6 +132770,7 @@ SQLITE_PRIVATE void sqlite3Pragma(
132713
132770
rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
132714
132771
if( rc!=SQLITE_OK || res==0 ){
132715
132772
sqlite3ErrorMsg(pParse, "not a writable directory");
132773
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
132716
132774
goto pragma_out;
132717
132775
}
132718
132776
}
@@ -132730,6 +132788,7 @@ SQLITE_PRIVATE void sqlite3Pragma(
132730
132788
}
132731
132789
#endif /* SQLITE_OMIT_WSD */
132732
132790
}
132791
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
132733
132792
break;
132734
132793
}
132735
132794
@@ -132748,6 +132807,7 @@ SQLITE_PRIVATE void sqlite3Pragma(
132748
132807
**
132749
132808
*/
132750
132809
case PragTyp_DATA_STORE_DIRECTORY: {
132810
+ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
132751
132811
if( !zRight ){
132752
132812
returnSingleText(v, sqlite3_data_directory);
132753
132813
}else{
@@ -132757,6 +132817,7 @@ SQLITE_PRIVATE void sqlite3Pragma(
132757
132817
rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
132758
132818
if( rc!=SQLITE_OK || res==0 ){
132759
132819
sqlite3ErrorMsg(pParse, "not a writable directory");
132820
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
132760
132821
goto pragma_out;
132761
132822
}
132762
132823
}
@@ -132768,6 +132829,7 @@ SQLITE_PRIVATE void sqlite3Pragma(
132768
132829
}
132769
132830
#endif /* SQLITE_OMIT_WSD */
132770
132831
}
132832
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
132771
132833
break;
132772
132834
}
132773
132835
#endif
@@ -137213,14 +137275,17 @@ static void generateSortTail(
137213
137275
if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce);
137214
137276
addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
137215
137277
VdbeCoverage(v);
137216
- codeOffset(v, p->iOffset, addrContinue );
137278
+ assert( p->iLimit==0 && p-> iOffset==0 );
137217
137279
sqlite3VdbeAddOp3(v, OP_SorterData, iTab, regSortOut, iSortTab);
137218
137280
bSeq = 0;
137219
137281
}else{
137220
137282
addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
137221
137283
codeOffset(v, p->iOffset, addrContinue);
137222
137284
iSortTab = iTab;
137223
137285
bSeq = 1;
137286
+ if( p->iOffset>0 ){
137287
+ sqlite3VdbeAddOp2(v, OP_AddImm, p->iLimit, -1);
137288
+ }
137224
137289
}
137225
137290
for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
137226
137291
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
@@ -139213,10 +139278,11 @@ static int multiSelectOrderBy(
139213
139278
*/
139214
139279
sqlite3VdbeResolveLabel(v, labelEnd);
139215
139280
139216
- /* Reassembly the compound query so that it will be freed correctly
139281
+ /* Reassemble the compound query so that it will be freed correctly
139217
139282
** by the calling function */
139218
139283
if( pSplit->pPrior ){
139219
- sqlite3SelectDelete(db, pSplit->pPrior);
139284
+ sqlite3ParserAddCleanup(pParse,
139285
+ (void(*)(sqlite3*,void*))sqlite3SelectDelete, pSplit->pPrior);
139220
139286
}
139221
139287
pSplit->pPrior = pPrior;
139222
139288
pPrior->pNext = pSplit;
@@ -140735,6 +140801,7 @@ static Table *isSimpleCount(Select *p, AggInfo *pAggInfo){
140735
140801
|| p->pSrc->nSrc!=1
140736
140802
|| p->pSrc->a[0].pSelect
140737
140803
|| pAggInfo->nFunc!=1
140804
+ || p->pHaving
140738
140805
){
140739
140806
return 0;
140740
140807
}
@@ -149783,7 +149850,8 @@ static int codeEqualityTerm(
149783
149850
}
149784
149851
sqlite3ExprDelete(db, pX);
149785
149852
}else{
149786
- aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
149853
+ int n = sqlite3ExprVectorSize(pX->pLeft);
149854
+ aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*MAX(nEq,n));
149787
149855
eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
149788
149856
}
149789
149857
pX = pExpr;
@@ -181120,7 +181188,7 @@ static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
181120
181188
nDistance = iPrev - nMaxUndeferred;
181121
181189
}
181122
181190
181123
- aOut = (char *)sqlite3_malloc (nPoslist+8 );
181191
+ aOut = (char *)sqlite3Fts3MallocZero (nPoslist+FTS3_BUFFER_PADDING );
181124
181192
if( !aOut ){
181125
181193
sqlite3_free(aPoslist);
181126
181194
return SQLITE_NOMEM;
@@ -204146,7 +204214,7 @@ static int geopolyUpdate(
204146
204214
sqlite3_free(p);
204147
204215
nChange = 1;
204148
204216
}
204149
- for(jj=1; jj<pRtree->nAux ; jj++){
204217
+ for(jj=1; jj<nData-2 ; jj++){
204150
204218
nChange++;
204151
204219
sqlite3_bind_value(pUp, jj+2, aData[jj+2]);
204152
204220
}
@@ -236636,7 +236704,7 @@ static void fts5SourceIdFunc(
236636
236704
){
236637
236705
assert( nArg==0 );
236638
236706
UNUSED_PARAM2(nArg, apUnused);
236639
- sqlite3_result_text(pCtx, "fts5: 2022-07-21 15:24:47 698edb77537b67c41adc68f9b892db56bcf9a55e00371a61420f3ddd668e6603 ", -1, SQLITE_TRANSIENT);
236707
+ sqlite3_result_text(pCtx, "fts5: 2022-09-05 11:02:23 4635f4a69c8c2a8df242b384a992aea71224e39a2ccab42d8c0b0602f1e826e8 ", -1, SQLITE_TRANSIENT);
236640
236708
}
236641
236709
236642
236710
/*
0 commit comments