| | @@ -16,11 +16,11 @@ |
| 16 | 16 | ** if you want a wrapper to interface SQLite with your choice of programming |
| 17 | 17 | ** language. The code for the "sqlite3" command-line shell is also in a |
| 18 | 18 | ** separate file. This file contains only code for the core SQLite library. |
| 19 | 19 | ** |
| 20 | 20 | ** The content in this amalgamation comes from Fossil check-in |
| 21 | | -** 4bfc6e53a95d710b7f40fa9c80d8cdd1df50 with changes in files: |
| 21 | +** a435d786fe0e245e352d08d2e2ddf8c1e151 with changes in files: |
| 22 | 22 | ** |
| 23 | 23 | ** |
| 24 | 24 | */ |
| 25 | 25 | #ifndef SQLITE_AMALGAMATION |
| 26 | 26 | #define SQLITE_CORE 1 |
| | @@ -467,14 +467,14 @@ |
| 467 | 467 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 468 | 468 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 469 | 469 | */ |
| 470 | 470 | #define SQLITE_VERSION "3.54.0" |
| 471 | 471 | #define SQLITE_VERSION_NUMBER 3054000 |
| 472 | | -#define SQLITE_SOURCE_ID "2026-10-05 14:22:13 4bfc6e53a95d710b7f40fa9c80d8cdd1df50d69ed8614e9800f7e6a1ca5a3c29" |
| 472 | +#define SQLITE_SOURCE_ID "2026-10-06 18:52:47 a435d786fe0e245e352d08d2e2ddf8c1e15154809e3b471810cc327e9d90ef85" |
| 473 | 473 | #define SQLITE_SCM_BRANCH "trunk" |
| 474 | 474 | #define SQLITE_SCM_TAGS "" |
| 475 | | -#define SQLITE_SCM_DATETIME "2026-10-05T14:22:13.597Z" |
| 475 | +#define SQLITE_SCM_DATETIME "2026-10-06T18:52:47.576Z" |
| 476 | 476 | |
| 477 | 477 | /* |
| 478 | 478 | ** CAPI3REF: Run-Time Library Version Numbers |
| 479 | 479 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 480 | 480 | ** |
| | @@ -47272,13 +47272,13 @@ |
| 47272 | 47272 | /* On systems that support O_TMPFILE, use that flag to create a more |
| 47273 | 47273 | ** secure temporary file that cannot be accessed by other processes |
| 47274 | 47274 | */ |
| 47275 | 47275 | zName = unixTempFileDir(); |
| 47276 | 47276 | if( zName |
| 47277 | | - && (fd = robust_open(zName, O_RDWR|O_CREAT|O_EXCL|O_TMPFILE, 0600))>=0 |
| 47277 | + && (fd = robust_open(zName, O_RDWR|O_EXCL|O_TMPFILE, 0600))>=0 |
| 47278 | 47278 | ){ |
| 47279 | | - rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags); |
| 47279 | + rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags|UNIXFILE_NOLOCK); |
| 47280 | 47280 | goto open_finished; |
| 47281 | 47281 | } |
| 47282 | 47282 | #endif |
| 47283 | 47283 | rc = unixGetTempname(pVfs->mxPathname, zTmpname); |
| 47284 | 47284 | if( rc!=SQLITE_OK ){ |
| | @@ -52305,10 +52305,32 @@ |
| 52305 | 52305 | }else{ |
| 52306 | 52306 | pp = &p->pNext; |
| 52307 | 52307 | } |
| 52308 | 52308 | } |
| 52309 | 52309 | } |
| 52310 | + |
| 52311 | +/* |
| 52312 | +** Handle h is open on the *-shm file. This function zeroes the first |
| 52313 | +** 8 bytes of the file. If SQLITE_ENABLE_SETLK_TIMEOUT is defined, h may |
| 52314 | +** have been opened with FILE_FLAG_OVERLAPPED. |
| 52315 | +*/ |
| 52316 | +static int winZeroSharedMemory(HANDLE h){ |
| 52317 | + u8 aZero[8] = {0,0,0,0,0,0,0,0}; |
| 52318 | + DWORD nWrite = 0; |
| 52319 | + OVERLAPPED ovlp; |
| 52320 | + memset(&ovlp, 0, sizeof(OVERLAPPED)); |
| 52321 | + if( !osWriteFile(h, aZero, sizeof(aZero), &nWrite, &ovlp) ){ |
| 52322 | + /* If the file was opened with FILE_FLAG_OVERLAPPED, the write may still |
| 52323 | + ** be pending. Wait for it with GetOverlappedResult(). */ |
| 52324 | + if( osGetLastError()!=ERROR_IO_PENDING |
| 52325 | + || !GetOverlappedResult(h, &ovlp, &nWrite, TRUE) |
| 52326 | + ){ |
| 52327 | + nWrite = 0; |
| 52328 | + } |
| 52329 | + } |
| 52330 | + return (nWrite==sizeof(aZero) ? SQLITE_OK : SQLITE_IOERR_WRITE); |
| 52331 | +} |
| 52310 | 52332 | |
| 52311 | 52333 | /* |
| 52312 | 52334 | ** The DMS lock has not yet been taken on the shm file associated with |
| 52313 | 52335 | ** pShmNode. Take the lock. Truncate the *-shm file if required. |
| 52314 | 52336 | ** Return SQLITE_OK if successful, or an SQLite error code otherwise. |
| | @@ -52324,11 +52346,16 @@ |
| 52324 | 52346 | ** is the first process to open the file. Truncate it to zero bytes |
| 52325 | 52347 | ** in this case. */ |
| 52326 | 52348 | if( pShmNode->isReadonly ){ |
| 52327 | 52349 | rc = SQLITE_READONLY_CANTINIT; |
| 52328 | 52350 | }else{ |
| 52329 | | - rc = winHandleTruncate(h, 0); |
| 52351 | + if( SQLITE_OK!=winHandleTruncate(h, 0) ){ |
| 52352 | + /* Sometimes the truncate operation may fail because some other |
| 52353 | + ** process is still holding an open mapping. So try to write |
| 52354 | + ** zeroes into the start of the file instead. */ |
| 52355 | + rc = winZeroSharedMemory(h); |
| 52356 | + } |
| 52330 | 52357 | } |
| 52331 | 52358 | |
| 52332 | 52359 | /* Release the EXCLUSIVE lock acquired above. */ |
| 52333 | 52360 | winUnlockFile(&h, WIN_SHM_DMS, 0, 1, 0); |
| 52334 | 52361 | }else if( (rc & 0xFF)==SQLITE_BUSY ){ |
| | @@ -82682,11 +82709,11 @@ |
| 82682 | 82709 | assert( MX_CELL_SIZE(pBt) >= nCell ); |
| 82683 | 82710 | pTmp = pBt->pTmpSpace; |
| 82684 | 82711 | assert( pTmp!=0 ); |
| 82685 | 82712 | rc = sqlite3PagerWrite(pLeaf->pDbPage); |
| 82686 | 82713 | if( rc==SQLITE_OK ){ |
| 82687 | | - rc = insertCell(pPage, iCellIdx, pCell-4, nCell+4, pTmp, n); |
| 82714 | + rc = insertCell(pPage, iCellIdx, pCell-4, nCell+4-(pCell[0]==2), pTmp, n); |
| 82688 | 82715 | } |
| 82689 | 82716 | dropCell(pLeaf, pLeaf->nCell-1, nCell, &rc); |
| 82690 | 82717 | if( rc ) return rc; |
| 82691 | 82718 | } |
| 82692 | 82719 | |
| | @@ -125833,10 +125860,27 @@ |
| 125833 | 125860 | return ( |
| 125834 | 125861 | sqlite3StrICmp(db->aDb[iDb].zDbSName, zName)==0 |
| 125835 | 125862 | || (iDb==0 && sqlite3StrICmp("main", zName)==0) |
| 125836 | 125863 | ); |
| 125837 | 125864 | } |
| 125865 | + |
| 125866 | +/* |
| 125867 | +** If any TEMP triggers reference schema pSchema, move those triggers to |
| 125868 | +** reference the TEMP schema itself. |
| 125869 | +*/ |
| 125870 | +static void detachTempTriggers(sqlite3 *db, Schema *pSchema){ |
| 125871 | + HashElem *pEntry; |
| 125872 | + assert( db->aDb[1].pSchema ); |
| 125873 | + pEntry = sqliteHashFirst(&db->aDb[1].pSchema->trigHash); |
| 125874 | + while( pEntry ){ |
| 125875 | + Trigger *pTrig = (Trigger*)sqliteHashData(pEntry); |
| 125876 | + if( pTrig->pTabSchema==pSchema ){ |
| 125877 | + pTrig->pTabSchema = pTrig->pSchema; |
| 125878 | + } |
| 125879 | + pEntry = sqliteHashNext(pEntry); |
| 125880 | + } |
| 125881 | +} |
| 125838 | 125882 | |
| 125839 | 125883 | /* |
| 125840 | 125884 | ** An SQL user-function registered to do the work of an ATTACH statement. The |
| 125841 | 125885 | ** three arguments to the function come directly from an attach statement: |
| 125842 | 125886 | ** |
| | @@ -125903,18 +125947,20 @@ |
| 125903 | 125947 | Schema *pNewSchema = sqlite3SchemaGet(db, pNewBt); |
| 125904 | 125948 | if( pNewSchema ){ |
| 125905 | 125949 | /* Both the Btree and the new Schema were allocated successfully. |
| 125906 | 125950 | ** Close the old db and update the aDb[] slot with the new memdb |
| 125907 | 125951 | ** values. */ |
| 125952 | + detachTempTriggers(db, pNew->pSchema); |
| 125908 | 125953 | sqlite3BtreeClose(pNew->pBt); |
| 125909 | 125954 | pNew->pBt = pNewBt; |
| 125910 | 125955 | pNew->pSchema = pNewSchema; |
| 125911 | 125956 | if( db->init.iDb==0 ){ |
| 125912 | 125957 | /* Clear all eponymous virtual table instances, as they are holding |
| 125913 | 125958 | ** pointers to the schema object just freed by sqlite3BtreeClose() */ |
| 125914 | 125959 | sqlite3VtabEponymousTableClearAll(db); |
| 125915 | 125960 | } |
| 125961 | + sqlite3ExpirePreparedStatements(db, 1); |
| 125916 | 125962 | }else{ |
| 125917 | 125963 | sqlite3BtreeClose(pNewBt); |
| 125918 | 125964 | rc = SQLITE_NOMEM; |
| 125919 | 125965 | } |
| 125920 | 125966 | } |
| | @@ -126082,11 +126128,10 @@ |
| 126082 | 126128 | ){ |
| 126083 | 126129 | const char *zName = (const char *)sqlite3_value_text(argv[0]); |
| 126084 | 126130 | sqlite3 *db = sqlite3_context_db_handle(context); |
| 126085 | 126131 | int i; |
| 126086 | 126132 | Db *pDb = 0; |
| 126087 | | - HashElem *pEntry; |
| 126088 | 126133 | char zErr[128]; |
| 126089 | 126134 | |
| 126090 | 126135 | UNUSED_PARAMETER(NotUsed); |
| 126091 | 126136 | |
| 126092 | 126137 | if( zName==0 ) zName = ""; |
| | @@ -126109,22 +126154,11 @@ |
| 126109 | 126154 | ){ |
| 126110 | 126155 | sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName); |
| 126111 | 126156 | goto detach_error; |
| 126112 | 126157 | } |
| 126113 | 126158 | |
| 126114 | | - /* If any TEMP triggers reference the schema being detached, move those |
| 126115 | | - ** triggers to reference the TEMP schema itself. */ |
| 126116 | | - assert( db->aDb[1].pSchema ); |
| 126117 | | - pEntry = sqliteHashFirst(&db->aDb[1].pSchema->trigHash); |
| 126118 | | - while( pEntry ){ |
| 126119 | | - Trigger *pTrig = (Trigger*)sqliteHashData(pEntry); |
| 126120 | | - if( pTrig->pTabSchema==pDb->pSchema ){ |
| 126121 | | - pTrig->pTabSchema = pTrig->pSchema; |
| 126122 | | - } |
| 126123 | | - pEntry = sqliteHashNext(pEntry); |
| 126124 | | - } |
| 126125 | | - |
| 126159 | + detachTempTriggers(db, pDb->pSchema); |
| 126126 | 126160 | sqlite3BtreeClose(pDb->pBt); |
| 126127 | 126161 | pDb->pBt = 0; |
| 126128 | 126162 | pDb->pSchema = 0; |
| 126129 | 126163 | sqlite3CollapseDatabaseArray(db); |
| 126130 | 126164 | return; |
| | @@ -187997,11 +188031,10 @@ |
| 187997 | 188031 | break; |
| 187998 | 188032 | } |
| 187999 | 188033 | zSql += 2; |
| 188000 | 188034 | while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; } |
| 188001 | 188035 | if( zSql[0]==0 ){ |
| 188002 | | - if( state==0 ) state = 2; |
| 188003 | 188036 | pending = '/'; |
| 188004 | 188037 | goto incomplete_finish; |
| 188005 | 188038 | } |
| 188006 | 188039 | zSql++; |
| 188007 | 188040 | token = tkWS; |
| | @@ -188012,11 +188045,11 @@ |
| 188012 | 188045 | token = tkOTHER; |
| 188013 | 188046 | break; |
| 188014 | 188047 | } |
| 188015 | 188048 | while( *zSql && *zSql!='\n' ){ zSql++; } |
| 188016 | 188049 | if( *zSql==0 ){ |
| 188017 | | - if( state!=1 ) pending = '-'; |
| 188050 | + pending = '-'; |
| 188018 | 188051 | goto incomplete_finish; |
| 188019 | 188052 | } |
| 188020 | 188053 | token = tkWS; |
| 188021 | 188054 | break; |
| 188022 | 188055 | } |
| | @@ -188115,16 +188148,16 @@ |
| 188115 | 188148 | } |
| 188116 | 188149 | state = trans[state][token]; |
| 188117 | 188150 | zSql++; |
| 188118 | 188151 | } |
| 188119 | 188152 | incomplete_finish: |
| 188120 | | - if( state==0 ) return SQLITE_EMPTY; |
| 188153 | + if( state==0 && pending==0 ) return SQLITE_EMPTY; |
| 188121 | 188154 | if( state==1 ) nParen = 0; |
| 188122 | 188155 | return (i64)((((u64)nParen)<<32) | |
| 188123 | 188156 | ((u64)pending<<16) | |
| 188124 | 188157 | ((u64)statemap[state]<<8) | |
| 188125 | | - (state!=1)); |
| 188158 | + (state>1 || pending!=0)); |
| 188126 | 188159 | } |
| 188127 | 188160 | SQLITE_API int sqlite3_complete(const char *zSql){ |
| 188128 | 188161 | return sqlite3_incomplete(zSql)==0; |
| 188129 | 188162 | } |
| 188130 | 188163 | |
| | @@ -188615,11 +188648,11 @@ |
| 188615 | 188648 | SQLITE_API int sqlite3_initialize(void){ |
| 188616 | 188649 | /* If this build does not support writable static data (WSD) natively |
| 188617 | 188650 | ** then we have to invoke the (application-supplied) WSD initialization |
| 188618 | 188651 | ** routine before doing anything else. */ |
| 188619 | 188652 | #ifdef SQLITE_OMIT_WSD |
| 188620 | | - rc = sqlite3_wsd_init(4096, 24); |
| 188653 | + int rc = sqlite3_wsd_init(4096, 24); |
| 188621 | 188654 | if( rc!=SQLITE_OK ){ |
| 188622 | 188655 | return rc; |
| 188623 | 188656 | } |
| 188624 | 188657 | #endif |
| 188625 | 188658 | |
| | @@ -265376,11 +265409,11 @@ |
| 265376 | 265409 | int nArg, /* Number of args */ |
| 265377 | 265410 | sqlite3_value **apUnused /* Function arguments */ |
| 265378 | 265411 | ){ |
| 265379 | 265412 | assert( nArg==0 ); |
| 265380 | 265413 | UNUSED_PARAM2(nArg, apUnused); |
| 265381 | | - sqlite3_result_text(pCtx, "fts5: 2026-10-05 14:22:13 4bfc6e53a95d710b7f40fa9c80d8cdd1df50d69ed8614e9800f7e6a1ca5a3c29", -1, SQLITE_TRANSIENT); |
| 265414 | + sqlite3_result_text(pCtx, "fts5: 2026-10-06 14:34:02 adacd1423f159fa4698f7e40dd1488256a13dff0b31cc90e28c3441109596ef4", -1, SQLITE_TRANSIENT); |
| 265382 | 265415 | } |
| 265383 | 265416 | |
| 265384 | 265417 | /* |
| 265385 | 265418 | ** Implementation of fts5_locale(LOCALE, TEXT) function. |
| 265386 | 265419 | ** |
| 265387 | 265420 | |