11/******************************************************************************
22** 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
44** single large file, the entire code can be compiled as a single translation
55** unit. This allows many compilers to do optimizations that would not be
66** possible if the files were compiled separately. Performance improvements
@@ -452,9 +452,9 @@ extern "C" {
452452** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453** [sqlite_version()] and [sqlite_source_id()].
454454*/
455- #define SQLITE_VERSION "3.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 "
458458
459459/*
460460** CAPI3REF: Run-Time Library Version Numbers
@@ -13144,6 +13144,11 @@ struct fts5_api {
1314413144/************** End of sqlite3.h *********************************************/
1314513145/************** Continuing where we left off in sqliteInt.h ******************/
1314613146
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+
1314713152/*
1314813153** Include the configuration header output by 'configure' if we're using the
1314913154** autoconf-based build
@@ -29563,8 +29568,13 @@ SQLITE_PRIVATE void *sqlite3OomFault(sqlite3 *db){
2956329568 }
2956429569 DisableLookaside;
2956529570 if( db->pParse ){
29571+ Parse *pParse;
2956629572 sqlite3ErrorMsg(db->pParse, "out of memory");
2956729573 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+ }
2956829578 }
2956929579 }
2957029580 return 0;
@@ -33459,7 +33469,7 @@ SQLITE_PRIVATE void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){
3345933469 va_list ap;
3346033470 sqlite3 *db = pParse->db;
3346133471 assert( db!=0 );
33462- assert( db->pParse==pParse );
33472+ assert( db->pParse==pParse || db->pParse->pToplevel==pParse );
3346333473 db->errByteOffset = -2;
3346433474 va_start(ap, zFormat);
3346533475 zMsg = sqlite3VMPrintf(db, zFormat, ap);
@@ -41320,6 +41330,7 @@ static const char *unixTempFileDir(void){
4132041330static int unixGetTempname(int nBuf, char *zBuf){
4132141331 const char *zDir;
4132241332 int iLimit = 0;
41333+ int rc = SQLITE_OK;
4132341334
4132441335 /* It's odd to simulate an io-error here, but really this is just
4132541336 ** using the io-error infrastructure to test that SQLite handles this
@@ -41328,18 +41339,26 @@ static int unixGetTempname(int nBuf, char *zBuf){
4132841339 zBuf[0] = 0;
4132941340 SimulateIOError( return SQLITE_IOERR );
4133041341
41342+ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
4133141343 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;
4134341362}
4134441363
4134541364#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
@@ -45482,6 +45501,7 @@ SQLITE_API int sqlite3_win32_set_directory8(
4548245501 int rc = sqlite3_initialize();
4548345502 if( rc ) return rc;
4548445503#endif
45504+ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
4548545505 if( type==SQLITE_WIN32_DATA_DIRECTORY_TYPE ){
4548645506 ppDirectory = &sqlite3_data_directory;
4548745507 }else if( type==SQLITE_WIN32_TEMP_DIRECTORY_TYPE ){
@@ -45496,14 +45516,19 @@ SQLITE_API int sqlite3_win32_set_directory8(
4549645516 if( zValue && zValue[0] ){
4549745517 zCopy = sqlite3_mprintf("%s", zValue);
4549845518 if ( zCopy==0 ){
45499- return SQLITE_NOMEM_BKPT;
45519+ rc = SQLITE_NOMEM_BKPT;
45520+ goto set_directory8_done;
4550045521 }
4550145522 }
4550245523 sqlite3_free(*ppDirectory);
4550345524 *ppDirectory = zCopy;
45504- return SQLITE_OK;
45525+ rc = SQLITE_OK;
45526+ }else{
45527+ rc = SQLITE_ERROR;
4550545528 }
45506- return SQLITE_ERROR;
45529+ set_directory8_done:
45530+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
45531+ return rc;
4550745532}
4550845533
4550945534/*
@@ -48277,6 +48302,18 @@ static int winMakeEndInDirSep(int nBuf, char *zBuf){
4827748302 return 0;
4827848303}
4827948304
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+
4828048317/*
4828148318** Create a temporary file name and store the resulting pointer into pzBuf.
4828248319** The pointer returned in pzBuf must be freed via sqlite3_free().
@@ -48313,20 +48350,23 @@ static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){
4831348350 */
4831448351 nDir = nMax - (nPre + 15);
4831548352 assert( nDir>0 );
48316- if( sqlite3_temp_directory ){
48353+ if( winTempDirDefined() ){
4831748354 int nDirLen = sqlite3Strlen30(sqlite3_temp_directory);
4831848355 if( nDirLen>0 ){
4831948356 if( !winIsDirSep(sqlite3_temp_directory[nDirLen-1]) ){
4832048357 nDirLen++;
4832148358 }
4832248359 if( nDirLen>nDir ){
48360+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
4832348361 sqlite3_free(zBuf);
4832448362 OSTRACE(("TEMP-FILENAME rc=SQLITE_ERROR\n"));
4832548363 return winLogError(SQLITE_ERROR, 0, "winGetTempname1", 0);
4832648364 }
4832748365 sqlite3_snprintf(nMax, zBuf, "%s", sqlite3_temp_directory);
4832848366 }
48367+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
4832948368 }
48369+
4833048370#if defined(__CYGWIN__)
4833148371 else{
4833248372 static const char *azDirs[] = {
@@ -49115,7 +49155,7 @@ static BOOL winIsVerbatimPathname(
4911549155** pathname into zOut[]. zOut[] will be at least pVfs->mxPathname
4911649156** bytes in size.
4911749157*/
49118- static int winFullPathname (
49158+ static int winFullPathnameNoMutex (
4911949159 sqlite3_vfs *pVfs, /* Pointer to vfs object */
4912049160 const char *zRelative, /* Possibly relative input path */
4912149161 int nFull, /* Size of output buffer in bytes */
@@ -49294,6 +49334,19 @@ static int winFullPathname(
4929449334 }
4929549335#endif
4929649336}
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+ }
4929749350
4929849351#ifndef SQLITE_OMIT_LOAD_EXTENSION
4929949352/*
@@ -59676,6 +59729,7 @@ static int pager_open_journal(Pager *pPager){
5967659729 if( rc!=SQLITE_OK ){
5967759730 sqlite3BitvecDestroy(pPager->pInJournal);
5967859731 pPager->pInJournal = 0;
59732+ pPager->journalOff = 0;
5967959733 }else{
5968059734 assert( pPager->eState==PAGER_WRITER_LOCKED );
5968159735 pPager->eState = PAGER_WRITER_CACHEMOD;
@@ -61231,7 +61285,7 @@ SQLITE_PRIVATE int sqlite3PagerGetJournalMode(Pager *pPager){
6123161285SQLITE_PRIVATE int sqlite3PagerOkToChangeJournalMode(Pager *pPager){
6123261286 assert( assert_pager_state(pPager) );
6123361287 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;
6123561289 return 1;
6123661290}
6123761291
@@ -81035,6 +81089,7 @@ SQLITE_PRIVATE int sqlite3VdbeAddFunctionCall(
8103581089 addr = sqlite3VdbeAddOp4(v, eCallCtx ? OP_PureFunc : OP_Function,
8103681090 p1, p2, p3, (char*)pCtx, P4_FUNCCTX);
8103781091 sqlite3VdbeChangeP5(v, eCallCtx & NC_SelfRef);
81092+ sqlite3MayAbort(pParse);
8103881093 return addr;
8103981094}
8104081095
@@ -81370,6 +81425,7 @@ SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){
8137081425 || opcode==OP_VDestroy
8137181426 || opcode==OP_VCreate
8137281427 || opcode==OP_ParseSchema
81428+ || opcode==OP_Function || opcode==OP_PureFunc
8137381429 || ((opcode==OP_Halt || opcode==OP_HaltIfNull)
8137481430 && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
8137581431 ){
@@ -132704,6 +132760,7 @@ SQLITE_PRIVATE void sqlite3Pragma(
132704132760 **
132705132761 */
132706132762 case PragTyp_TEMP_STORE_DIRECTORY: {
132763+ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
132707132764 if( !zRight ){
132708132765 returnSingleText(v, sqlite3_temp_directory);
132709132766 }else{
@@ -132713,6 +132770,7 @@ SQLITE_PRIVATE void sqlite3Pragma(
132713132770 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
132714132771 if( rc!=SQLITE_OK || res==0 ){
132715132772 sqlite3ErrorMsg(pParse, "not a writable directory");
132773+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
132716132774 goto pragma_out;
132717132775 }
132718132776 }
@@ -132730,6 +132788,7 @@ SQLITE_PRIVATE void sqlite3Pragma(
132730132788 }
132731132789#endif /* SQLITE_OMIT_WSD */
132732132790 }
132791+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
132733132792 break;
132734132793 }
132735132794
@@ -132748,6 +132807,7 @@ SQLITE_PRIVATE void sqlite3Pragma(
132748132807 **
132749132808 */
132750132809 case PragTyp_DATA_STORE_DIRECTORY: {
132810+ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
132751132811 if( !zRight ){
132752132812 returnSingleText(v, sqlite3_data_directory);
132753132813 }else{
@@ -132757,6 +132817,7 @@ SQLITE_PRIVATE void sqlite3Pragma(
132757132817 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
132758132818 if( rc!=SQLITE_OK || res==0 ){
132759132819 sqlite3ErrorMsg(pParse, "not a writable directory");
132820+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
132760132821 goto pragma_out;
132761132822 }
132762132823 }
@@ -132768,6 +132829,7 @@ SQLITE_PRIVATE void sqlite3Pragma(
132768132829 }
132769132830#endif /* SQLITE_OMIT_WSD */
132770132831 }
132832+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
132771132833 break;
132772132834 }
132773132835#endif
@@ -137213,14 +137275,17 @@ static void generateSortTail(
137213137275 if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce);
137214137276 addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
137215137277 VdbeCoverage(v);
137216- codeOffset(v, p->iOffset, addrContinue );
137278+ assert( p->iLimit==0 && p-> iOffset==0 );
137217137279 sqlite3VdbeAddOp3(v, OP_SorterData, iTab, regSortOut, iSortTab);
137218137280 bSeq = 0;
137219137281 }else{
137220137282 addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
137221137283 codeOffset(v, p->iOffset, addrContinue);
137222137284 iSortTab = iTab;
137223137285 bSeq = 1;
137286+ if( p->iOffset>0 ){
137287+ sqlite3VdbeAddOp2(v, OP_AddImm, p->iLimit, -1);
137288+ }
137224137289 }
137225137290 for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
137226137291#ifdef SQLITE_ENABLE_SORTER_REFERENCES
@@ -139213,10 +139278,11 @@ static int multiSelectOrderBy(
139213139278 */
139214139279 sqlite3VdbeResolveLabel(v, labelEnd);
139215139280
139216- /* Reassembly the compound query so that it will be freed correctly
139281+ /* Reassemble the compound query so that it will be freed correctly
139217139282 ** by the calling function */
139218139283 if( pSplit->pPrior ){
139219- sqlite3SelectDelete(db, pSplit->pPrior);
139284+ sqlite3ParserAddCleanup(pParse,
139285+ (void(*)(sqlite3*,void*))sqlite3SelectDelete, pSplit->pPrior);
139220139286 }
139221139287 pSplit->pPrior = pPrior;
139222139288 pPrior->pNext = pSplit;
@@ -140735,6 +140801,7 @@ static Table *isSimpleCount(Select *p, AggInfo *pAggInfo){
140735140801 || p->pSrc->nSrc!=1
140736140802 || p->pSrc->a[0].pSelect
140737140803 || pAggInfo->nFunc!=1
140804+ || p->pHaving
140738140805 ){
140739140806 return 0;
140740140807 }
@@ -149783,7 +149850,8 @@ static int codeEqualityTerm(
149783149850 }
149784149851 sqlite3ExprDelete(db, pX);
149785149852 }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));
149787149855 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
149788149856 }
149789149857 pX = pExpr;
@@ -181120,7 +181188,7 @@ static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
181120181188 nDistance = iPrev - nMaxUndeferred;
181121181189 }
181122181190
181123- aOut = (char *)sqlite3_malloc (nPoslist+8 );
181191+ aOut = (char *)sqlite3Fts3MallocZero (nPoslist+FTS3_BUFFER_PADDING );
181124181192 if( !aOut ){
181125181193 sqlite3_free(aPoslist);
181126181194 return SQLITE_NOMEM;
@@ -204146,7 +204214,7 @@ static int geopolyUpdate(
204146204214 sqlite3_free(p);
204147204215 nChange = 1;
204148204216 }
204149- for(jj=1; jj<pRtree->nAux ; jj++){
204217+ for(jj=1; jj<nData-2 ; jj++){
204150204218 nChange++;
204151204219 sqlite3_bind_value(pUp, jj+2, aData[jj+2]);
204152204220 }
@@ -236636,7 +236704,7 @@ static void fts5SourceIdFunc(
236636236704){
236637236705 assert( nArg==0 );
236638236706 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);
236640236708}
236641236709
236642236710/*
0 commit comments