|
1 | 1 | /****************************************************************************** |
2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
3 | | -** version 3.47.0. By combining all the individual C code files into this |
| 3 | +** version 3.47.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 |
|
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 | | -** 03a9703e27c44437c39363d0baf82db4ebc9. |
| 21 | +** b95d11e958643b969c47a8e5857f3793b9e6. |
22 | 22 | */ |
23 | 23 | #define SQLITE_CORE 1 |
24 | 24 | #define SQLITE_AMALGAMATION 1 |
@@ -462,9 +462,9 @@ extern "C" { |
462 | 462 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
463 | 463 | ** [sqlite_version()] and [sqlite_source_id()]. |
464 | 464 | */ |
465 | | -#define SQLITE_VERSION "3.47.0" |
466 | | -#define SQLITE_VERSION_NUMBER 3047000 |
467 | | -#define SQLITE_SOURCE_ID "2024-10-21 16:30:22 03a9703e27c44437c39363d0baf82db4ebc94538a0f28411c85dda156f82636e" |
| 465 | +#define SQLITE_VERSION "3.47.1" |
| 466 | +#define SQLITE_VERSION_NUMBER 3047001 |
| 467 | +#define SQLITE_SOURCE_ID "2024-11-25 12:07:48 b95d11e958643b969c47a8e5857f3793b9e69700b8f1469371386369a26e577e" |
468 | 468 |
|
469 | 469 | /* |
470 | 470 | ** CAPI3REF: Run-Time Library Version Numbers |
@@ -968,6 +968,13 @@ SQLITE_API int sqlite3_exec( |
968 | 968 | ** filesystem supports doing multiple write operations atomically when those |
969 | 969 | ** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and |
970 | 970 | ** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. |
| 971 | +** |
| 972 | +** The SQLITE_IOCAP_SUBPAGE_READ property means that it is ok to read |
| 973 | +** from the database file in amounts that are not a multiple of the |
| 974 | +** page size and that do not begin at a page boundary. Without this |
| 975 | +** property, SQLite is careful to only do full-page reads and write |
| 976 | +** on aligned pages, with the one exception that it will do a sub-page |
| 977 | +** read of the first page to access the database header. |
971 | 978 | */ |
972 | 979 | #define SQLITE_IOCAP_ATOMIC 0x00000001 |
973 | 980 | #define SQLITE_IOCAP_ATOMIC512 0x00000002 |
@@ -984,6 +991,7 @@ SQLITE_API int sqlite3_exec( |
984 | 991 | #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000 |
985 | 992 | #define SQLITE_IOCAP_IMMUTABLE 0x00002000 |
986 | 993 | #define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000 |
| 994 | +#define SQLITE_IOCAP_SUBPAGE_READ 0x00008000 |
987 | 995 |
|
988 | 996 | /* |
989 | 997 | ** CAPI3REF: File Locking Levels |
@@ -1130,6 +1138,7 @@ struct sqlite3_file { |
1130 | 1138 | ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE] |
1131 | 1139 | ** <li> [SQLITE_IOCAP_IMMUTABLE] |
1132 | 1140 | ** <li> [SQLITE_IOCAP_BATCH_ATOMIC] |
| 1141 | +** <li> [SQLITE_IOCAP_SUBPAGE_READ] |
1133 | 1142 | ** </ul> |
1134 | 1143 | ** |
1135 | 1144 | ** The SQLITE_IOCAP_ATOMIC property means that all writes of |
@@ -32298,6 +32307,7 @@ SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3 *db, const Expr *pExp |
32298 | 32307 | pExpr = pExpr->pLeft; |
32299 | 32308 | } |
32300 | 32309 | if( pExpr==0 ) return; |
| 32310 | + if( ExprHasProperty(pExpr, EP_FromDDL) ) return; |
32301 | 32311 | db->errByteOffset = pExpr->w.iOfst; |
32302 | 32312 | } |
32303 | 32313 |
|
@@ -42591,6 +42601,7 @@ static void setDeviceCharacteristics(unixFile *pFd){ |
42591 | 42601 | if( pFd->ctrlFlags & UNIXFILE_PSOW ){ |
42592 | 42602 | pFd->deviceCharacteristics |= SQLITE_IOCAP_POWERSAFE_OVERWRITE; |
42593 | 42603 | } |
| 42604 | + pFd->deviceCharacteristics |= SQLITE_IOCAP_SUBPAGE_READ; |
42594 | 42605 |
|
42595 | 42606 | pFd->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE; |
42596 | 42607 | } |
@@ -50391,7 +50402,7 @@ static int winSectorSize(sqlite3_file *id){ |
50391 | 50402 | */ |
50392 | 50403 | static int winDeviceCharacteristics(sqlite3_file *id){ |
50393 | 50404 | winFile *p = (winFile*)id; |
50394 | | - return SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN | |
| 50405 | + return SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN | SQLITE_IOCAP_SUBPAGE_READ | |
50395 | 50406 | ((p->ctrlFlags & WINFILE_PSOW)?SQLITE_IOCAP_POWERSAFE_OVERWRITE:0); |
50396 | 50407 | } |
50397 | 50408 |
|
@@ -51779,7 +51790,7 @@ static int winOpen( |
51779 | 51790 |
|
51780 | 51791 | int rc = SQLITE_OK; /* Function Return Code */ |
51781 | 51792 | #if !defined(NDEBUG) || SQLITE_OS_WINCE |
51782 | | - int eType = flags&0xFFFFFF00; /* Type of file to open */ |
| 51793 | + int eType = flags&0x0FFF00; /* Type of file to open */ |
51783 | 51794 | #endif |
51784 | 51795 |
|
51785 | 51796 | int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE); |
@@ -57999,18 +58010,26 @@ static const unsigned char aJournalMagic[] = { |
57999 | 58010 | ** Return true if page pgno can be read directly from the database file |
58000 | 58011 | ** by the b-tree layer. This is the case if: |
58001 | 58012 | ** |
58002 | | -** * the database file is open, |
58003 | | -** * there are no dirty pages in the cache, and |
58004 | | -** * the desired page is not currently in the wal file. |
| 58013 | +** (1) the database file is open |
| 58014 | +** (2) the VFS for the database is able to do unaligned sub-page reads |
| 58015 | +** (3) there are no dirty pages in the cache, and |
| 58016 | +** (4) the desired page is not currently in the wal file. |
58005 | 58017 | */ |
58006 | 58018 | SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno){ |
58007 | | - if( pPager->fd->pMethods==0 ) return 0; |
58008 | | - if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0; |
| 58019 | + assert( pPager!=0 ); |
| 58020 | + assert( pPager->fd!=0 ); |
| 58021 | + if( pPager->fd->pMethods==0 ) return 0; /* Case (1) */ |
| 58022 | + assert( pPager->fd->pMethods->xDeviceCharacteristics!=0 ); |
| 58023 | + if( (pPager->fd->pMethods->xDeviceCharacteristics(pPager->fd) |
| 58024 | + & SQLITE_IOCAP_SUBPAGE_READ)==0 ){ |
| 58025 | + return 0; /* Case (2) */ |
| 58026 | + } |
| 58027 | + if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0; /* Failed (3) */ |
58009 | 58028 | #ifndef SQLITE_OMIT_WAL |
58010 | 58029 | if( pPager->pWal ){ |
58011 | 58030 | u32 iRead = 0; |
58012 | 58031 | (void)sqlite3WalFindFrame(pPager->pWal, pgno, &iRead); |
58013 | | - return iRead==0; |
| 58032 | + return iRead==0; /* Condition (4) */ |
58014 | 58033 | } |
58015 | 58034 | #endif |
58016 | 58035 | return 1; |
@@ -158939,6 +158958,7 @@ static Expr *removeUnindexableInClauseTerms( |
158939 | 158958 | pNew->pLeft->x.pList = pLhs; |
158940 | 158959 | } |
158941 | 158960 | pSelect->pEList = pRhs; |
| 158961 | + pSelect->selId = ++pParse->nSelect; /* Req'd for SubrtnSig validity */ |
158942 | 158962 | if( pLhs && pLhs->nExpr==1 ){ |
158943 | 158963 | /* Take care here not to generate a TK_VECTOR containing only a |
158944 | 158964 | ** single value. Since the parser never creates such a vector, some |
@@ -189798,10 +189818,15 @@ static int fts3PoslistPhraseMerge( |
189798 | 189818 | if( *p1==POS_COLUMN ){ |
189799 | 189819 | p1++; |
189800 | 189820 | p1 += fts3GetVarint32(p1, &iCol1); |
| 189821 | + /* iCol1==0 indicates corruption. Column 0 does not have a POS_COLUMN |
| 189822 | + ** entry, so this is actually end-of-doclist. */ |
| 189823 | + if( iCol1==0 ) return 0; |
189801 | 189824 | } |
189802 | 189825 | if( *p2==POS_COLUMN ){ |
189803 | 189826 | p2++; |
189804 | 189827 | p2 += fts3GetVarint32(p2, &iCol2); |
| 189828 | + /* As above, iCol2==0 indicates corruption. */ |
| 189829 | + if( iCol2==0 ) return 0; |
189805 | 189830 | } |
189806 | 189831 |
|
189807 | 189832 | while( 1 ){ |
@@ -192972,7 +192997,7 @@ static int fts3EvalNearTest(Fts3Expr *pExpr, int *pRc){ |
192972 | 192997 | nTmp += p->pRight->pPhrase->doclist.nList; |
192973 | 192998 | } |
192974 | 192999 | nTmp += p->pPhrase->doclist.nList; |
192975 | | - aTmp = sqlite3_malloc64(nTmp*2); |
| 193000 | + aTmp = sqlite3_malloc64(nTmp*2 + FTS3_VARINT_MAX); |
192976 | 193001 | if( !aTmp ){ |
192977 | 193002 | *pRc = SQLITE_NOMEM; |
192978 | 193003 | res = 0; |
@@ -194525,10 +194550,11 @@ static int getNextString( |
194525 | 194550 | Fts3PhraseToken *pToken; |
194526 | 194551 |
|
194527 | 194552 | p = fts3ReallocOrFree(p, nSpace + ii*sizeof(Fts3PhraseToken)); |
194528 | | - if( !p ) goto no_mem; |
194529 | | - |
194530 | 194553 | zTemp = fts3ReallocOrFree(zTemp, nTemp + nByte); |
194531 | | - if( !zTemp ) goto no_mem; |
| 194554 | + if( !zTemp || !p ){ |
| 194555 | + rc = SQLITE_NOMEM; |
| 194556 | + goto getnextstring_out; |
| 194557 | + } |
194532 | 194558 |
|
194533 | 194559 | assert( nToken==ii ); |
194534 | 194560 | pToken = &((Fts3Phrase *)(&p[1]))->aToken[ii]; |
@@ -194543,29 +194569,27 @@ static int getNextString( |
194543 | 194569 | nToken = ii+1; |
194544 | 194570 | } |
194545 | 194571 | } |
194546 | | - |
194547 | | - pModule->xClose(pCursor); |
194548 | | - pCursor = 0; |
194549 | 194572 | } |
194550 | 194573 |
|
194551 | 194574 | if( rc==SQLITE_DONE ){ |
194552 | 194575 | int jj; |
194553 | 194576 | char *zBuf = 0; |
194554 | 194577 |
|
194555 | 194578 | p = fts3ReallocOrFree(p, nSpace + nToken*sizeof(Fts3PhraseToken) + nTemp); |
194556 | | - if( !p ) goto no_mem; |
| 194579 | + if( !p ){ |
| 194580 | + rc = SQLITE_NOMEM; |
| 194581 | + goto getnextstring_out; |
| 194582 | + } |
194557 | 194583 | memset(p, 0, (char *)&(((Fts3Phrase *)&p[1])->aToken[0])-(char *)p); |
194558 | 194584 | p->eType = FTSQUERY_PHRASE; |
194559 | 194585 | p->pPhrase = (Fts3Phrase *)&p[1]; |
194560 | 194586 | p->pPhrase->iColumn = pParse->iDefaultCol; |
194561 | 194587 | p->pPhrase->nToken = nToken; |
194562 | 194588 |
|
194563 | 194589 | zBuf = (char *)&p->pPhrase->aToken[nToken]; |
| 194590 | + assert( nTemp==0 || zTemp ); |
194564 | 194591 | if( zTemp ){ |
194565 | 194592 | memcpy(zBuf, zTemp, nTemp); |
194566 | | - sqlite3_free(zTemp); |
194567 | | - }else{ |
194568 | | - assert( nTemp==0 ); |
194569 | 194593 | } |
194570 | 194594 |
|
194571 | 194595 | for(jj=0; jj<p->pPhrase->nToken; jj++){ |
@@ -194575,17 +194599,17 @@ static int getNextString( |
194575 | 194599 | rc = SQLITE_OK; |
194576 | 194600 | } |
194577 | 194601 |
|
194578 | | - *ppExpr = p; |
194579 | | - return rc; |
194580 | | -no_mem: |
194581 | | - |
| 194602 | + getnextstring_out: |
194582 | 194603 | if( pCursor ){ |
194583 | 194604 | pModule->xClose(pCursor); |
194584 | 194605 | } |
194585 | 194606 | sqlite3_free(zTemp); |
194586 | | - sqlite3_free(p); |
194587 | | - *ppExpr = 0; |
194588 | | - return SQLITE_NOMEM; |
| 194607 | + if( rc!=SQLITE_OK ){ |
| 194608 | + sqlite3_free(p); |
| 194609 | + p = 0; |
| 194610 | + } |
| 194611 | + *ppExpr = p; |
| 194612 | + return rc; |
194589 | 194613 | } |
194590 | 194614 |
|
194591 | 194615 | /* |
@@ -232806,7 +232830,27 @@ SQLITE_API int sqlite3session_config(int op, void *pArg){ |
232806 | 232830 | /************** End of sqlite3session.c **************************************/ |
232807 | 232831 | /************** Begin file fts5.c ********************************************/ |
232808 | 232832 |
|
232809 | | - |
| 232833 | +/* |
| 232834 | +** This, the "fts5.c" source file, is a composite file that is itself |
| 232835 | +** assembled from the following files: |
| 232836 | +** |
| 232837 | +** fts5.h |
| 232838 | +** fts5Int.h |
| 232839 | +** fts5parse.h <--- Generated from fts5parse.y by Lemon |
| 232840 | +** fts5parse.c <--- Generated from fts5parse.y by Lemon |
| 232841 | +** fts5_aux.c |
| 232842 | +** fts5_buffer.c |
| 232843 | +** fts5_config.c |
| 232844 | +** fts5_expr.c |
| 232845 | +** fts5_hash.c |
| 232846 | +** fts5_index.c |
| 232847 | +** fts5_main.c |
| 232848 | +** fts5_storage.c |
| 232849 | +** fts5_tokenize.c |
| 232850 | +** fts5_unicode2.c |
| 232851 | +** fts5_varint.c |
| 232852 | +** fts5_vocab.c |
| 232853 | +*/ |
232810 | 232854 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS5) |
232811 | 232855 |
|
232812 | 232856 | #if !defined(NDEBUG) && !defined(SQLITE_DEBUG) |
@@ -232816,6 +232860,12 @@ SQLITE_API int sqlite3session_config(int op, void *pArg){ |
232816 | 232860 | # undef NDEBUG |
232817 | 232861 | #endif |
232818 | 232862 |
|
| 232863 | +#ifdef HAVE_STDINT_H |
| 232864 | +/* #include <stdint.h> */ |
| 232865 | +#endif |
| 232866 | +#ifdef HAVE_INTTYPES_H |
| 232867 | +/* #include <inttypes.h> */ |
| 232868 | +#endif |
232819 | 232869 | /* |
232820 | 232870 | ** 2014 May 31 |
232821 | 232871 | ** |
@@ -254888,7 +254938,7 @@ static void fts5SourceIdFunc( |
254888 | 254938 | ){ |
254889 | 254939 | assert( nArg==0 ); |
254890 | 254940 | UNUSED_PARAM2(nArg, apUnused); |
254891 | | - sqlite3_result_text(pCtx, "fts5: 2024-10-21 16:30:22 03a9703e27c44437c39363d0baf82db4ebc94538a0f28411c85dda156f82636e", -1, SQLITE_TRANSIENT); |
| 254941 | + sqlite3_result_text(pCtx, "fts5: 2024-11-25 12:07:48 b95d11e958643b969c47a8e5857f3793b9e69700b8f1469371386369a26e577e", -1, SQLITE_TRANSIENT); |
254892 | 254942 | } |
254893 | 254943 |
|
254894 | 254944 | /* |
@@ -260079,7 +260129,7 @@ static int sqlite3Fts5VocabInit(Fts5Global *pGlobal, sqlite3 *db){ |
260079 | 260129 | } |
260080 | 260130 |
|
260081 | 260131 |
|
260082 | | - |
| 260132 | +/* Here ends the fts5.c composite file. */ |
260083 | 260133 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS5) */ |
260084 | 260134 |
|
260085 | 260135 | /************** End of fts5.c ************************************************/ |
|