Fossil SCM
Update the built-in SQLite to the latest 3.27.0 alpha.
Commit
6ba52d791f57ae7f448e7a6bcef7d2f99612f82c1a32a93f6c9b4304bff97413
Parent
af91e0575e4293a…
2 files changed
+165
-89
+13
-1
+165
-89
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -1162,11 +1162,11 @@ | ||
| 1162 | 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1163 | 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1164 | 1164 | */ |
| 1165 | 1165 | #define SQLITE_VERSION "3.27.0" |
| 1166 | 1166 | #define SQLITE_VERSION_NUMBER 3027000 |
| 1167 | -#define SQLITE_SOURCE_ID "2019-01-27 02:45:32 9cf8ebd141aa2eb661d457624c76433bd9e4abfdef04aa52e28bc169172calt1" | |
| 1167 | +#define SQLITE_SOURCE_ID "2019-02-01 15:06:27 4ca9d5d53d41d08fbce29f9da8cc0948df9c4c3136210af88b499cf889b5ccb8" | |
| 1168 | 1168 | |
| 1169 | 1169 | /* |
| 1170 | 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1171 | 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1172 | 1172 | ** |
| @@ -3019,10 +3019,21 @@ | ||
| 3019 | 3019 | ** from the database as records are returned in sorted order. The default |
| 3020 | 3020 | ** value for this option is to never use this optimization. Specifying a |
| 3021 | 3021 | ** negative value for this option restores the default behaviour. |
| 3022 | 3022 | ** This option is only available if SQLite is compiled with the |
| 3023 | 3023 | ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option. |
| 3024 | +** | |
| 3025 | +** [[SQLITE_CONFIG_MEMDB_MAXSIZE]] | |
| 3026 | +** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE | |
| 3027 | +** <dd>The SQLITE_CONFIG_MEMDB_MAXSIZE option accepts a single parameter | |
| 3028 | +** [sqlite3_int64] parameter which is the default maximum size for an in-memory | |
| 3029 | +** database created using [sqlite3_deserialize()]. This default maximum | |
| 3030 | +** size can be adjusted up or down for individual databases using the | |
| 3031 | +** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this | |
| 3032 | +** configuration setting is never used, then the default maximum is determined | |
| 3033 | +** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that | |
| 3034 | +** compile-time option is not set, then the default maximum is 1073741824. | |
| 3024 | 3035 | ** </dl> |
| 3025 | 3036 | */ |
| 3026 | 3037 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 3027 | 3038 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 3028 | 3039 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| @@ -3049,10 +3060,11 @@ | ||
| 3049 | 3060 | #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ |
| 3050 | 3061 | #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */ |
| 3051 | 3062 | #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */ |
| 3052 | 3063 | #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */ |
| 3053 | 3064 | #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */ |
| 3065 | +#define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */ | |
| 3054 | 3066 | |
| 3055 | 3067 | /* |
| 3056 | 3068 | ** CAPI3REF: Database Connection Configuration Options |
| 3057 | 3069 | ** |
| 3058 | 3070 | ** These constants are the available integer configuration options that |
| @@ -16433,10 +16445,11 @@ | ||
| 16433 | 16445 | #define SQLITE_SqlTrace HI(0x0001) /* Debug print SQL as it executes */ |
| 16434 | 16446 | #define SQLITE_VdbeListing HI(0x0002) /* Debug listings of VDBE progs */ |
| 16435 | 16447 | #define SQLITE_VdbeTrace HI(0x0004) /* True to trace VDBE execution */ |
| 16436 | 16448 | #define SQLITE_VdbeAddopTrace HI(0x0008) /* Trace sqlite3VdbeAddOp() calls */ |
| 16437 | 16449 | #define SQLITE_VdbeEQP HI(0x0010) /* Debug EXPLAIN QUERY PLAN */ |
| 16450 | +#define SQLITE_ParserTrace HI(0x0020) /* PRAGMA parser_trace=ON */ | |
| 16438 | 16451 | #endif |
| 16439 | 16452 | |
| 16440 | 16453 | /* |
| 16441 | 16454 | ** Allowed values for sqlite3.mDbFlags |
| 16442 | 16455 | */ |
| @@ -18305,10 +18318,13 @@ | ||
| 18305 | 18318 | ** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE. |
| 18306 | 18319 | */ |
| 18307 | 18320 | void (*xVdbeBranch)(void*,unsigned iSrcLine,u8 eThis,u8 eMx); /* Callback */ |
| 18308 | 18321 | void *pVdbeBranchArg; /* 1st argument */ |
| 18309 | 18322 | #endif |
| 18323 | +#ifdef SQLITE_ENABLE_DESERIALIZE | |
| 18324 | + sqlite3_int64 mxMemdbSize; /* Default max memdb size */ | |
| 18325 | +#endif | |
| 18310 | 18326 | #ifndef SQLITE_UNTESTABLE |
| 18311 | 18327 | int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */ |
| 18312 | 18328 | #endif |
| 18313 | 18329 | int bLocaltimeFault; /* True to fail localtime() calls */ |
| 18314 | 18330 | int bInternalFunctions; /* Internal SQL functions are visible */ |
| @@ -18722,10 +18738,11 @@ | ||
| 18722 | 18738 | SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int); |
| 18723 | 18739 | SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int); |
| 18724 | 18740 | SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*); |
| 18725 | 18741 | SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*); |
| 18726 | 18742 | SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*); |
| 18743 | +SQLITE_PRIVATE int sqlite3IndexHasDuplicateRootPage(Index*); | |
| 18727 | 18744 | SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**); |
| 18728 | 18745 | SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**); |
| 18729 | 18746 | SQLITE_PRIVATE int sqlite3InitOne(sqlite3*, int, char**, u32); |
| 18730 | 18747 | SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int); |
| 18731 | 18748 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| @@ -19716,10 +19733,17 @@ | ||
| 19716 | 19733 | #ifndef SQLITE_DEFAULT_LOOKASIDE |
| 19717 | 19734 | # define SQLITE_DEFAULT_LOOKASIDE 1200,100 |
| 19718 | 19735 | #endif |
| 19719 | 19736 | |
| 19720 | 19737 | |
| 19738 | +/* The default maximum size of an in-memory database created using | |
| 19739 | +** sqlite3_deserialize() | |
| 19740 | +*/ | |
| 19741 | +#ifndef SQLITE_MEMDB_DEFAULT_MAXSIZE | |
| 19742 | +# define SQLITE_MEMDB_DEFAULT_MAXSIZE 1073741824 | |
| 19743 | +#endif | |
| 19744 | + | |
| 19721 | 19745 | /* |
| 19722 | 19746 | ** The following singleton contains the global configuration for |
| 19723 | 19747 | ** the SQLite library. |
| 19724 | 19748 | */ |
| 19725 | 19749 | SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = { |
| @@ -19763,17 +19787,20 @@ | ||
| 19763 | 19787 | #endif |
| 19764 | 19788 | #ifdef SQLITE_VDBE_COVERAGE |
| 19765 | 19789 | 0, /* xVdbeBranch */ |
| 19766 | 19790 | 0, /* pVbeBranchArg */ |
| 19767 | 19791 | #endif |
| 19792 | +#ifdef SQLITE_ENABLE_DESERIALIZE | |
| 19793 | + SQLITE_MEMDB_DEFAULT_MAXSIZE, /* mxMemdbSize */ | |
| 19794 | +#endif | |
| 19768 | 19795 | #ifndef SQLITE_UNTESTABLE |
| 19769 | 19796 | 0, /* xTestCallback */ |
| 19770 | 19797 | #endif |
| 19771 | 19798 | 0, /* bLocaltimeFault */ |
| 19772 | 19799 | 0, /* bInternalFunctions */ |
| 19773 | 19800 | 0x7ffffffe, /* iOnceResetThreshold */ |
| 19774 | - SQLITE_DEFAULT_SORTERREF_SIZE /* szSorterRef */ | |
| 19801 | + SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */ | |
| 19775 | 19802 | }; |
| 19776 | 19803 | |
| 19777 | 19804 | /* |
| 19778 | 19805 | ** Hash table for global functions - functions common to all |
| 19779 | 19806 | ** database connections. After initialization, this table is |
| @@ -46578,15 +46605,10 @@ | ||
| 46578 | 46605 | int nMmap; /* Number of memory mapped pages */ |
| 46579 | 46606 | unsigned mFlags; /* Flags */ |
| 46580 | 46607 | int eLock; /* Most recent lock against this file */ |
| 46581 | 46608 | }; |
| 46582 | 46609 | |
| 46583 | -/* The default maximum size of an in-memory database */ | |
| 46584 | -#ifndef SQLITE_MEMDB_DEFAULT_MAXSIZE | |
| 46585 | -# define SQLITE_MEMDB_DEFAULT_MAXSIZE 1073741824 | |
| 46586 | -#endif | |
| 46587 | - | |
| 46588 | 46610 | /* |
| 46589 | 46611 | ** Methods for MemFile |
| 46590 | 46612 | */ |
| 46591 | 46613 | static int memdbClose(sqlite3_file*); |
| 46592 | 46614 | static int memdbRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); |
| @@ -46847,11 +46869,10 @@ | ||
| 46847 | 46869 | int iAmt, |
| 46848 | 46870 | void **pp |
| 46849 | 46871 | ){ |
| 46850 | 46872 | MemFile *p = (MemFile *)pFile; |
| 46851 | 46873 | if( iOfst+iAmt>p->sz ){ |
| 46852 | - assert( CORRUPT_DB ); | |
| 46853 | 46874 | *pp = 0; |
| 46854 | 46875 | }else{ |
| 46855 | 46876 | p->nMmap++; |
| 46856 | 46877 | *pp = (void*)(p->aData + iOfst); |
| 46857 | 46878 | } |
| @@ -46882,11 +46903,11 @@ | ||
| 46882 | 46903 | memset(p, 0, sizeof(*p)); |
| 46883 | 46904 | p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE; |
| 46884 | 46905 | assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */ |
| 46885 | 46906 | *pOutFlags = flags | SQLITE_OPEN_MEMORY; |
| 46886 | 46907 | p->base.pMethods = &memdb_io_methods; |
| 46887 | - p->szMax = SQLITE_MEMDB_DEFAULT_MAXSIZE; | |
| 46908 | + p->szMax = sqlite3GlobalConfig.mxMemdbSize; | |
| 46888 | 46909 | return SQLITE_OK; |
| 46889 | 46910 | } |
| 46890 | 46911 | |
| 46891 | 46912 | #if 0 /* Only used to delete rollback journals, master journals, and WAL |
| 46892 | 46913 | ** files, none of which exist in memdb. So this routine is never used */ |
| @@ -47134,12 +47155,12 @@ | ||
| 47134 | 47155 | }else{ |
| 47135 | 47156 | p->aData = pData; |
| 47136 | 47157 | p->sz = szDb; |
| 47137 | 47158 | p->szAlloc = szBuf; |
| 47138 | 47159 | p->szMax = szBuf; |
| 47139 | - if( p->szMax<SQLITE_MEMDB_DEFAULT_MAXSIZE ){ | |
| 47140 | - p->szMax = SQLITE_MEMDB_DEFAULT_MAXSIZE; | |
| 47160 | + if( p->szMax<sqlite3GlobalConfig.mxMemdbSize ){ | |
| 47161 | + p->szMax = sqlite3GlobalConfig.mxMemdbSize; | |
| 47141 | 47162 | } |
| 47142 | 47163 | p->mFlags = mFlags; |
| 47143 | 47164 | rc = SQLITE_OK; |
| 47144 | 47165 | } |
| 47145 | 47166 | |
| @@ -62473,13 +62494,20 @@ | ||
| 62473 | 62494 | ** |
| 62474 | 62495 | ** Fields in this structure are accessed under the BtShared.mutex |
| 62475 | 62496 | ** found at self->pBt->mutex. |
| 62476 | 62497 | ** |
| 62477 | 62498 | ** skipNext meaning: |
| 62478 | -** eState==SKIPNEXT && skipNext>0: Next sqlite3BtreeNext() is no-op. | |
| 62479 | -** eState==SKIPNEXT && skipNext<0: Next sqlite3BtreePrevious() is no-op. | |
| 62480 | -** eState==FAULT: Cursor fault with skipNext as error code. | |
| 62499 | +** The meaning of skipNext depends on the value of eState: | |
| 62500 | +** | |
| 62501 | +** eState Meaning of skipNext | |
| 62502 | +** VALID skipNext is meaningless and is ignored | |
| 62503 | +** INVALID skipNext is meaningless and is ignored | |
| 62504 | +** SKIPNEXT sqlite3BtreeNext() is a no-op if skipNext>0 and | |
| 62505 | +** sqlite3BtreePrevious() is no-op if skipNext<0. | |
| 62506 | +** REQUIRESEEK restoreCursorPosition() restores the cursor to | |
| 62507 | +** eState=SKIPNEXT if skipNext!=0 | |
| 62508 | +** FAULT skipNext holds the cursor fault error code. | |
| 62481 | 62509 | */ |
| 62482 | 62510 | struct BtCursor { |
| 62483 | 62511 | u8 eState; /* One of the CURSOR_XXX constants (see below) */ |
| 62484 | 62512 | u8 curFlags; /* zero or more BTCF_* flags defined below */ |
| 62485 | 62513 | u8 curPagerFlags; /* Flags to send to sqlite3PagerGet() */ |
| @@ -63824,11 +63852,11 @@ | ||
| 63824 | 63852 | rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext); |
| 63825 | 63853 | if( rc==SQLITE_OK ){ |
| 63826 | 63854 | sqlite3_free(pCur->pKey); |
| 63827 | 63855 | pCur->pKey = 0; |
| 63828 | 63856 | assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID ); |
| 63829 | - pCur->skipNext |= skipNext; | |
| 63857 | + if( skipNext ) pCur->skipNext = skipNext; | |
| 63830 | 63858 | if( pCur->skipNext && pCur->eState==CURSOR_VALID ){ |
| 63831 | 63859 | pCur->eState = CURSOR_SKIPNEXT; |
| 63832 | 63860 | } |
| 63833 | 63861 | } |
| 63834 | 63862 | return rc; |
| @@ -63894,11 +63922,10 @@ | ||
| 63894 | 63922 | return rc; |
| 63895 | 63923 | } |
| 63896 | 63924 | if( pCur->eState!=CURSOR_VALID ){ |
| 63897 | 63925 | *pDifferentRow = 1; |
| 63898 | 63926 | }else{ |
| 63899 | - assert( pCur->skipNext==0 ); | |
| 63900 | 63927 | *pDifferentRow = 0; |
| 63901 | 63928 | } |
| 63902 | 63929 | return SQLITE_OK; |
| 63903 | 63930 | } |
| 63904 | 63931 | |
| @@ -68313,11 +68340,11 @@ | ||
| 68313 | 68340 | } |
| 68314 | 68341 | /* If the requested key is one more than the previous key, then |
| 68315 | 68342 | ** try to get there using sqlite3BtreeNext() rather than a full |
| 68316 | 68343 | ** binary search. This is an optimization only. The correct answer |
| 68317 | 68344 | ** is still obtained without this case, only a little more slowely */ |
| 68318 | - if( pCur->info.nKey+1==intKey && !pCur->skipNext ){ | |
| 68345 | + if( pCur->info.nKey+1==intKey ){ | |
| 68319 | 68346 | *pRes = 0; |
| 68320 | 68347 | rc = sqlite3BtreeNext(pCur, 0); |
| 68321 | 68348 | if( rc==SQLITE_OK ){ |
| 68322 | 68349 | getCellInfo(pCur); |
| 68323 | 68350 | if( pCur->info.nKey==intKey ){ |
| @@ -68587,28 +68614,22 @@ | ||
| 68587 | 68614 | int rc; |
| 68588 | 68615 | int idx; |
| 68589 | 68616 | MemPage *pPage; |
| 68590 | 68617 | |
| 68591 | 68618 | assert( cursorOwnsBtShared(pCur) ); |
| 68592 | - assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID ); | |
| 68593 | 68619 | if( pCur->eState!=CURSOR_VALID ){ |
| 68594 | 68620 | assert( (pCur->curFlags & BTCF_ValidOvfl)==0 ); |
| 68595 | 68621 | rc = restoreCursorPosition(pCur); |
| 68596 | 68622 | if( rc!=SQLITE_OK ){ |
| 68597 | 68623 | return rc; |
| 68598 | 68624 | } |
| 68599 | 68625 | if( CURSOR_INVALID==pCur->eState ){ |
| 68600 | 68626 | return SQLITE_DONE; |
| 68601 | 68627 | } |
| 68602 | - if( pCur->skipNext ){ | |
| 68603 | - assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT ); | |
| 68628 | + if( pCur->eState==CURSOR_SKIPNEXT ){ | |
| 68604 | 68629 | pCur->eState = CURSOR_VALID; |
| 68605 | - if( pCur->skipNext>0 ){ | |
| 68606 | - pCur->skipNext = 0; | |
| 68607 | - return SQLITE_OK; | |
| 68608 | - } | |
| 68609 | - pCur->skipNext = 0; | |
| 68630 | + if( pCur->skipNext>0 ) return SQLITE_OK; | |
| 68610 | 68631 | } |
| 68611 | 68632 | } |
| 68612 | 68633 | |
| 68613 | 68634 | pPage = pCur->pPage; |
| 68614 | 68635 | idx = ++pCur->ix; |
| @@ -68659,11 +68680,10 @@ | ||
| 68659 | 68680 | SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int flags){ |
| 68660 | 68681 | MemPage *pPage; |
| 68661 | 68682 | UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */ |
| 68662 | 68683 | assert( cursorOwnsBtShared(pCur) ); |
| 68663 | 68684 | assert( flags==0 || flags==1 ); |
| 68664 | - assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID ); | |
| 68665 | 68685 | pCur->info.nSize = 0; |
| 68666 | 68686 | pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl); |
| 68667 | 68687 | if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur); |
| 68668 | 68688 | pPage = pCur->pPage; |
| 68669 | 68689 | if( (++pCur->ix)>=pPage->nCell ){ |
| @@ -68700,11 +68720,10 @@ | ||
| 68700 | 68720 | static SQLITE_NOINLINE int btreePrevious(BtCursor *pCur){ |
| 68701 | 68721 | int rc; |
| 68702 | 68722 | MemPage *pPage; |
| 68703 | 68723 | |
| 68704 | 68724 | assert( cursorOwnsBtShared(pCur) ); |
| 68705 | - assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID ); | |
| 68706 | 68725 | assert( (pCur->curFlags & (BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey))==0 ); |
| 68707 | 68726 | assert( pCur->info.nSize==0 ); |
| 68708 | 68727 | if( pCur->eState!=CURSOR_VALID ){ |
| 68709 | 68728 | rc = restoreCursorPosition(pCur); |
| 68710 | 68729 | if( rc!=SQLITE_OK ){ |
| @@ -68711,18 +68730,13 @@ | ||
| 68711 | 68730 | return rc; |
| 68712 | 68731 | } |
| 68713 | 68732 | if( CURSOR_INVALID==pCur->eState ){ |
| 68714 | 68733 | return SQLITE_DONE; |
| 68715 | 68734 | } |
| 68716 | - if( pCur->skipNext ){ | |
| 68717 | - assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT ); | |
| 68735 | + if( CURSOR_SKIPNEXT==pCur->eState ){ | |
| 68718 | 68736 | pCur->eState = CURSOR_VALID; |
| 68719 | - if( pCur->skipNext<0 ){ | |
| 68720 | - pCur->skipNext = 0; | |
| 68721 | - return SQLITE_OK; | |
| 68722 | - } | |
| 68723 | - pCur->skipNext = 0; | |
| 68737 | + if( pCur->skipNext<0 ) return SQLITE_OK; | |
| 68724 | 68738 | } |
| 68725 | 68739 | } |
| 68726 | 68740 | |
| 68727 | 68741 | pPage = pCur->pPage; |
| 68728 | 68742 | assert( pPage->isInit ); |
| @@ -68753,11 +68767,10 @@ | ||
| 68753 | 68767 | return rc; |
| 68754 | 68768 | } |
| 68755 | 68769 | SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int flags){ |
| 68756 | 68770 | assert( cursorOwnsBtShared(pCur) ); |
| 68757 | 68771 | assert( flags==0 || flags==1 ); |
| 68758 | - assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID ); | |
| 68759 | 68772 | UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */ |
| 68760 | 68773 | pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey); |
| 68761 | 68774 | pCur->info.nSize = 0; |
| 68762 | 68775 | if( pCur->eState!=CURSOR_VALID |
| 68763 | 68776 | || pCur->ix==0 |
| @@ -69722,27 +69735,38 @@ | ||
| 69722 | 69735 | ** / | \ |
| 69723 | 69736 | ** --------- --------- --------- |
| 69724 | 69737 | ** |Child-1| |Child-2| |Child-3| |
| 69725 | 69738 | ** --------- --------- --------- |
| 69726 | 69739 | ** |
| 69727 | -** The order of cells is in the array is: | |
| 69740 | +** The order of cells is in the array is for an index btree is: | |
| 69728 | 69741 | ** |
| 69729 | 69742 | ** 1. All cells from Child-1 in order |
| 69730 | 69743 | ** 2. The first divider cell from Parent |
| 69731 | 69744 | ** 3. All cells from Child-2 in order |
| 69732 | 69745 | ** 4. The second divider cell from Parent |
| 69733 | 69746 | ** 5. All cells from Child-3 in order |
| 69734 | 69747 | ** |
| 69735 | -** The apEnd[] array holds pointer to the end of page for Child-1, the | |
| 69736 | -** Parent, Child-2, the Parent (again), and Child-3. The ixNx[] array | |
| 69737 | -** holds the number of cells contained in each of these 5 stages, and | |
| 69738 | -** all stages to the left. Hence: | |
| 69748 | +** For a table-btree (with rowids) the items 2 and 4 are empty because | |
| 69749 | +** content exists only in leaves and there are no divider cells. | |
| 69750 | +** | |
| 69751 | +** For an index btree, the apEnd[] array holds pointer to the end of page | |
| 69752 | +** for Child-1, the Parent, Child-2, the Parent (again), and Child-3, | |
| 69753 | +** respectively. The ixNx[] array holds the number of cells contained in | |
| 69754 | +** each of these 5 stages, and all stages to the left. Hence: | |
| 69755 | +** | |
| 69739 | 69756 | ** ixNx[0] = Number of cells in Child-1. |
| 69740 | 69757 | ** ixNx[1] = Number of cells in Child-1 plus 1 for first divider. |
| 69741 | 69758 | ** ixNx[2] = Number of cells in Child-1 and Child-2 + 1 for 1st divider. |
| 69742 | 69759 | ** ixNx[3] = Number of cells in Child-1 and Child-2 + both divider cells |
| 69743 | 69760 | ** ixNx[4] = Total number of cells. |
| 69761 | +** | |
| 69762 | +** For a table-btree, the concept is similar, except only apEnd[0]..apEnd[2] | |
| 69763 | +** are used and they point to the leaf pages only, and the ixNx value are: | |
| 69764 | +** | |
| 69765 | +** ixNx[0] = Number of cells in Child-1. | |
| 69766 | +** ixNx[1] = Number of cells in Child-1 and Child-2 + 1 for 1st divider. | |
| 69767 | +** ixNx[2] = Number of cells in Child-1 and Child-2 + both divider cells | |
| 69744 | 69768 | */ |
| 69745 | 69769 | typedef struct CellArray CellArray; |
| 69746 | 69770 | struct CellArray { |
| 69747 | 69771 | int nCell; /* Number of cells in apCell[] */ |
| 69748 | 69772 | MemPage *pRef; /* Reference page */ |
| @@ -69808,20 +69832,21 @@ | ||
| 69808 | 69832 | const int hdr = pPg->hdrOffset; /* Offset of header on pPg */ |
| 69809 | 69833 | u8 * const aData = pPg->aData; /* Pointer to data for pPg */ |
| 69810 | 69834 | const int usableSize = pPg->pBt->usableSize; |
| 69811 | 69835 | u8 * const pEnd = &aData[usableSize]; |
| 69812 | 69836 | int i = iFirst; /* Which cell to copy from pCArray*/ |
| 69813 | - int j; /* Start of cell content area */ | |
| 69837 | + u32 j; /* Start of cell content area */ | |
| 69814 | 69838 | int iEnd = i+nCell; /* Loop terminator */ |
| 69815 | 69839 | u8 *pCellptr = pPg->aCellIdx; |
| 69816 | 69840 | u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager); |
| 69817 | 69841 | u8 *pData; |
| 69818 | 69842 | int k; /* Current slot in pCArray->apEnd[] */ |
| 69819 | 69843 | u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */ |
| 69820 | 69844 | |
| 69821 | 69845 | assert( i<iEnd ); |
| 69822 | 69846 | j = get2byte(&aData[hdr+5]); |
| 69847 | + if( NEVER(j>(u32)usableSize) ){ j = 0; } | |
| 69823 | 69848 | memcpy(&pTmp[j], &aData[j], usableSize - j); |
| 69824 | 69849 | |
| 69825 | 69850 | for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){} |
| 69826 | 69851 | pSrcEnd = pCArray->apEnd[k]; |
| 69827 | 69852 | |
| @@ -69997,11 +70022,11 @@ | ||
| 69997 | 70022 | } |
| 69998 | 70023 | return nRet; |
| 69999 | 70024 | } |
| 70000 | 70025 | |
| 70001 | 70026 | /* |
| 70002 | -** pCArray contains pointers to and sizes of all cells in the pages being | |
| 70027 | +** pCArray contains pointers to and sizes of all cells in the page being | |
| 70003 | 70028 | ** balanced. The current page, pPg, has pPg->nCell cells starting with |
| 70004 | 70029 | ** pCArray->apCell[iOld]. After balancing, this page should hold nNew cells |
| 70005 | 70030 | ** starting at apCell[iNew]. |
| 70006 | 70031 | ** |
| 70007 | 70032 | ** This routine makes the necessary adjustments to pPg so that it contains |
| @@ -70031,26 +70056,31 @@ | ||
| 70031 | 70056 | u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager); |
| 70032 | 70057 | memcpy(pTmp, aData, pPg->pBt->usableSize); |
| 70033 | 70058 | #endif |
| 70034 | 70059 | |
| 70035 | 70060 | /* Remove cells from the start and end of the page */ |
| 70061 | + assert( nCell>=0 ); | |
| 70036 | 70062 | if( iOld<iNew ){ |
| 70037 | 70063 | int nShift = pageFreeArray(pPg, iOld, iNew-iOld, pCArray); |
| 70064 | + if( nShift>nCell ) return SQLITE_CORRUPT_BKPT; | |
| 70038 | 70065 | memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2); |
| 70039 | 70066 | nCell -= nShift; |
| 70040 | 70067 | } |
| 70041 | 70068 | if( iNewEnd < iOldEnd ){ |
| 70042 | - nCell -= pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray); | |
| 70069 | + int nTail = pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray); | |
| 70070 | + assert( nCell>=nTail ); | |
| 70071 | + nCell -= nTail; | |
| 70043 | 70072 | } |
| 70044 | 70073 | |
| 70045 | 70074 | pData = &aData[get2byteNotZero(&aData[hdr+5])]; |
| 70046 | 70075 | if( pData<pBegin ) goto editpage_fail; |
| 70047 | 70076 | |
| 70048 | 70077 | /* Add cells to the start of the page */ |
| 70049 | 70078 | if( iNew<iOld ){ |
| 70050 | 70079 | int nAdd = MIN(nNew,iOld-iNew); |
| 70051 | 70080 | assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB ); |
| 70081 | + assert( nAdd>=0 ); | |
| 70052 | 70082 | pCellptr = pPg->aCellIdx; |
| 70053 | 70083 | memmove(&pCellptr[nAdd*2], pCellptr, nCell*2); |
| 70054 | 70084 | if( pageInsertArray( |
| 70055 | 70085 | pPg, pBegin, &pData, pCellptr, |
| 70056 | 70086 | iNew, nAdd, pCArray |
| @@ -70061,10 +70091,11 @@ | ||
| 70061 | 70091 | /* Add any overflow cells */ |
| 70062 | 70092 | for(i=0; i<pPg->nOverflow; i++){ |
| 70063 | 70093 | int iCell = (iOld + pPg->aiOvfl[i]) - iNew; |
| 70064 | 70094 | if( iCell>=0 && iCell<nNew ){ |
| 70065 | 70095 | pCellptr = &pPg->aCellIdx[iCell * 2]; |
| 70096 | + assert( nCell>=iCell ); | |
| 70066 | 70097 | memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2); |
| 70067 | 70098 | nCell++; |
| 70068 | 70099 | if( pageInsertArray( |
| 70069 | 70100 | pPg, pBegin, &pData, pCellptr, |
| 70070 | 70101 | iCell+iNew, 1, pCArray |
| @@ -70071,10 +70102,11 @@ | ||
| 70071 | 70102 | ) ) goto editpage_fail; |
| 70072 | 70103 | } |
| 70073 | 70104 | } |
| 70074 | 70105 | |
| 70075 | 70106 | /* Append cells to the end of the page */ |
| 70107 | + assert( nCell>=0 ); | |
| 70076 | 70108 | pCellptr = &pPg->aCellIdx[nCell*2]; |
| 70077 | 70109 | if( pageInsertArray( |
| 70078 | 70110 | pPg, pBegin, &pData, pCellptr, |
| 70079 | 70111 | iNew+nCell, nNew-nCell, pCArray |
| 70080 | 70112 | ) ) goto editpage_fail; |
| @@ -70644,16 +70676,19 @@ | ||
| 70644 | 70676 | ** the right of the i-th sibling page. |
| 70645 | 70677 | ** usableSpace: Number of bytes of space available on each sibling. |
| 70646 | 70678 | ** |
| 70647 | 70679 | */ |
| 70648 | 70680 | usableSpace = pBt->usableSize - 12 + leafCorrection; |
| 70649 | - for(i=0; i<nOld; i++){ | |
| 70681 | + for(i=k=0; i<nOld; i++, k++){ | |
| 70650 | 70682 | MemPage *p = apOld[i]; |
| 70651 | - b.apEnd[i*2] = p->aDataEnd; | |
| 70652 | - b.apEnd[i*2+1] = pParent->aDataEnd; | |
| 70653 | - b.ixNx[i*2] = cntOld[i]; | |
| 70654 | - b.ixNx[i*2+1] = cntOld[i]+1; | |
| 70683 | + b.apEnd[k] = p->aDataEnd; | |
| 70684 | + b.ixNx[k] = cntOld[i]; | |
| 70685 | + if( !leafData ){ | |
| 70686 | + k++; | |
| 70687 | + b.apEnd[k] = pParent->aDataEnd; | |
| 70688 | + b.ixNx[k] = cntOld[i]+1; | |
| 70689 | + } | |
| 70655 | 70690 | szNew[i] = usableSpace - p->nFree; |
| 70656 | 70691 | for(j=0; j<p->nOverflow; j++){ |
| 70657 | 70692 | szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]); |
| 70658 | 70693 | } |
| 70659 | 70694 | cntNew[i] = cntOld[i]; |
| @@ -71749,11 +71784,10 @@ | ||
| 71749 | 71784 | ** from the internal node. The 'previous' entry is used for this instead |
| 71750 | 71785 | ** of the 'next' entry, as the previous entry is always a part of the |
| 71751 | 71786 | ** sub-tree headed by the child page of the cell being deleted. This makes |
| 71752 | 71787 | ** balancing the tree following the delete operation easier. */ |
| 71753 | 71788 | if( !pPage->leaf ){ |
| 71754 | - pCur->skipNext = 0; | |
| 71755 | 71789 | rc = sqlite3BtreePrevious(pCur, 0); |
| 71756 | 71790 | assert( rc!=SQLITE_DONE ); |
| 71757 | 71791 | if( rc ) return rc; |
| 71758 | 71792 | } |
| 71759 | 71793 | |
| @@ -97882,10 +97916,11 @@ | ||
| 97882 | 97916 | static void gatherSelectWindows(Select *p){ |
| 97883 | 97917 | Walker w; |
| 97884 | 97918 | w.xExprCallback = gatherSelectWindowsCallback; |
| 97885 | 97919 | w.xSelectCallback = gatherSelectWindowsSelectCallback; |
| 97886 | 97920 | w.xSelectCallback2 = 0; |
| 97921 | + w.pParse = 0; | |
| 97887 | 97922 | w.u.pSelect = p; |
| 97888 | 97923 | sqlite3WalkSelect(&w, p); |
| 97889 | 97924 | } |
| 97890 | 97925 | #endif |
| 97891 | 97926 | |
| @@ -109965,21 +110000,26 @@ | ||
| 109965 | 110000 | assert( pParse->nErr==0 ); |
| 109966 | 110001 | if( db->init.busy ){ |
| 109967 | 110002 | Index *p; |
| 109968 | 110003 | assert( !IN_SPECIAL_PARSE ); |
| 109969 | 110004 | assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) ); |
| 110005 | + if( pTblName!=0 ){ | |
| 110006 | + pIndex->tnum = db->init.newTnum; | |
| 110007 | + if( sqlite3IndexHasDuplicateRootPage(pIndex) ){ | |
| 110008 | + sqlite3ErrorMsg(pParse, "invalid rootpage"); | |
| 110009 | + pParse->rc = SQLITE_CORRUPT_BKPT; | |
| 110010 | + goto exit_create_index; | |
| 110011 | + } | |
| 110012 | + } | |
| 109970 | 110013 | p = sqlite3HashInsert(&pIndex->pSchema->idxHash, |
| 109971 | 110014 | pIndex->zName, pIndex); |
| 109972 | 110015 | if( p ){ |
| 109973 | 110016 | assert( p==pIndex ); /* Malloc must have failed */ |
| 109974 | 110017 | sqlite3OomFault(db); |
| 109975 | 110018 | goto exit_create_index; |
| 109976 | 110019 | } |
| 109977 | 110020 | db->mDbFlags |= DBFLAG_SchemaChange; |
| 109978 | - if( pTblName!=0 ){ | |
| 109979 | - pIndex->tnum = db->init.newTnum; | |
| 109980 | - } | |
| 109981 | 110021 | } |
| 109982 | 110022 | |
| 109983 | 110023 | /* If this is the initial CREATE INDEX statement (or CREATE TABLE if the |
| 109984 | 110024 | ** index is an implied index for a UNIQUE or PRIMARY KEY constraint) then |
| 109985 | 110025 | ** emit code to allocate the index rootpage on disk and make an entry for |
| @@ -120194,12 +120234,11 @@ | ||
| 120194 | 120234 | #define PragTyp_WAL_CHECKPOINT 39 |
| 120195 | 120235 | #define PragTyp_ACTIVATE_EXTENSIONS 40 |
| 120196 | 120236 | #define PragTyp_HEXKEY 41 |
| 120197 | 120237 | #define PragTyp_KEY 42 |
| 120198 | 120238 | #define PragTyp_LOCK_STATUS 43 |
| 120199 | -#define PragTyp_PARSER_TRACE 44 | |
| 120200 | -#define PragTyp_STATS 45 | |
| 120239 | +#define PragTyp_STATS 44 | |
| 120201 | 120240 | |
| 120202 | 120241 | /* Property flags associated with various pragma. */ |
| 120203 | 120242 | #define PragFlg_NeedSchema 0x01 /* Force schema load before running */ |
| 120204 | 120243 | #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */ |
| 120205 | 120244 | #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */ |
| @@ -120618,16 +120657,18 @@ | ||
| 120618 | 120657 | /* ePragTyp: */ PragTyp_PAGE_SIZE, |
| 120619 | 120658 | /* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1, |
| 120620 | 120659 | /* ColNames: */ 0, 0, |
| 120621 | 120660 | /* iArg: */ 0 }, |
| 120622 | 120661 | #endif |
| 120623 | -#if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_PARSER_TRACE) | |
| 120662 | +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) | |
| 120663 | +#if defined(SQLITE_DEBUG) | |
| 120624 | 120664 | {/* zName: */ "parser_trace", |
| 120625 | - /* ePragTyp: */ PragTyp_PARSER_TRACE, | |
| 120626 | - /* ePragFlg: */ 0, | |
| 120665 | + /* ePragTyp: */ PragTyp_FLAG, | |
| 120666 | + /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, | |
| 120627 | 120667 | /* ColNames: */ 0, 0, |
| 120628 | - /* iArg: */ 0 }, | |
| 120668 | + /* iArg: */ SQLITE_ParserTrace }, | |
| 120669 | +#endif | |
| 120629 | 120670 | #endif |
| 120630 | 120671 | #if defined(SQLITE_INTROSPECTION_PRAGMAS) |
| 120631 | 120672 | {/* zName: */ "pragma_list", |
| 120632 | 120673 | /* ePragTyp: */ PragTyp_PRAGMA_LIST, |
| 120633 | 120674 | /* ePragFlg: */ PragFlg_Result0, |
| @@ -122225,23 +122266,10 @@ | ||
| 122225 | 122266 | } |
| 122226 | 122267 | break; |
| 122227 | 122268 | #endif /* !defined(SQLITE_OMIT_TRIGGER) */ |
| 122228 | 122269 | #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ |
| 122229 | 122270 | |
| 122230 | -#ifndef NDEBUG | |
| 122231 | - case PragTyp_PARSER_TRACE: { | |
| 122232 | - if( zRight ){ | |
| 122233 | - if( sqlite3GetBoolean(zRight, 0) ){ | |
| 122234 | - sqlite3ParserTrace(stdout, "parser: "); | |
| 122235 | - }else{ | |
| 122236 | - sqlite3ParserTrace(0, 0); | |
| 122237 | - } | |
| 122238 | - } | |
| 122239 | - } | |
| 122240 | - break; | |
| 122241 | -#endif | |
| 122242 | - | |
| 122243 | 122271 | /* Reinstall the LIKE and GLOB functions. The variant of LIKE |
| 122244 | 122272 | ** used will be case sensitive or not depending on the RHS. |
| 122245 | 122273 | */ |
| 122246 | 122274 | case PragTyp_CASE_SENSITIVE_LIKE: { |
| 122247 | 122275 | if( zRight ){ |
| @@ -123358,10 +123386,23 @@ | ||
| 123358 | 123386 | if( zExtra && zExtra[0] ) z = sqlite3MPrintf(db, "%z - %s", z, zExtra); |
| 123359 | 123387 | *pData->pzErrMsg = z; |
| 123360 | 123388 | pData->rc = SQLITE_CORRUPT_BKPT; |
| 123361 | 123389 | } |
| 123362 | 123390 | } |
| 123391 | + | |
| 123392 | +/* | |
| 123393 | +** Check to see if any sibling index (another index on the same table) | |
| 123394 | +** of pIndex has the same root page number, and if it does, return true. | |
| 123395 | +** This would indicate a corrupt schema. | |
| 123396 | +*/ | |
| 123397 | +SQLITE_PRIVATE int sqlite3IndexHasDuplicateRootPage(Index *pIndex){ | |
| 123398 | + Index *p; | |
| 123399 | + for(p=pIndex->pTable->pIndex; p; p=p->pNext){ | |
| 123400 | + if( p->tnum==pIndex->tnum && p!=pIndex ) return 1; | |
| 123401 | + } | |
| 123402 | + return 0; | |
| 123403 | +} | |
| 123363 | 123404 | |
| 123364 | 123405 | /* |
| 123365 | 123406 | ** This is the callback routine for the code that initializes the |
| 123366 | 123407 | ** database. See sqlite3Init() below for additional information. |
| 123367 | 123408 | ** This routine is also called from the OP_ParseSchema opcode of the VDBE. |
| @@ -123437,10 +123478,11 @@ | ||
| 123437 | 123478 | Index *pIndex; |
| 123438 | 123479 | pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zDbSName); |
| 123439 | 123480 | if( pIndex==0 |
| 123440 | 123481 | || sqlite3GetInt32(argv[1],&pIndex->tnum)==0 |
| 123441 | 123482 | || pIndex->tnum<2 |
| 123483 | + || sqlite3IndexHasDuplicateRootPage(pIndex) | |
| 123442 | 123484 | ){ |
| 123443 | 123485 | corruptSchema(pData, argv[0], pIndex?"invalid rootpage":"orphan index"); |
| 123444 | 123486 | } |
| 123445 | 123487 | } |
| 123446 | 123488 | return 0; |
| @@ -139887,10 +139929,21 @@ | ||
| 139887 | 139929 | k = 0; |
| 139888 | 139930 | pScan->iEquiv++; |
| 139889 | 139931 | } |
| 139890 | 139932 | return 0; |
| 139891 | 139933 | } |
| 139934 | + | |
| 139935 | +/* | |
| 139936 | +** This is whereScanInit() for the case of an index on an expression. | |
| 139937 | +** It is factored out into a separate tail-recursion subroutine so that | |
| 139938 | +** the normal whereScanInit() routine, which is a high-runner, does not | |
| 139939 | +** need to push registers onto the stack as part of its prologue. | |
| 139940 | +*/ | |
| 139941 | +static SQLITE_NOINLINE WhereTerm *whereScanInitIndexExpr(WhereScan *pScan){ | |
| 139942 | + pScan->idxaff = sqlite3ExprAffinity(pScan->pIdxExpr); | |
| 139943 | + return whereScanNext(pScan); | |
| 139944 | +} | |
| 139892 | 139945 | |
| 139893 | 139946 | /* |
| 139894 | 139947 | ** Initialize a WHERE clause scanner object. Return a pointer to the |
| 139895 | 139948 | ** first match. Return NULL if there are no matches. |
| 139896 | 139949 | ** |
| @@ -139920,31 +139973,33 @@ | ||
| 139920 | 139973 | pScan->pOrigWC = pWC; |
| 139921 | 139974 | pScan->pWC = pWC; |
| 139922 | 139975 | pScan->pIdxExpr = 0; |
| 139923 | 139976 | pScan->idxaff = 0; |
| 139924 | 139977 | pScan->zCollName = 0; |
| 139978 | + pScan->opMask = opMask; | |
| 139979 | + pScan->k = 0; | |
| 139980 | + pScan->aiCur[0] = iCur; | |
| 139981 | + pScan->nEquiv = 1; | |
| 139982 | + pScan->iEquiv = 1; | |
| 139925 | 139983 | if( pIdx ){ |
| 139926 | 139984 | int j = iColumn; |
| 139927 | 139985 | iColumn = pIdx->aiColumn[j]; |
| 139928 | 139986 | if( iColumn==XN_EXPR ){ |
| 139929 | 139987 | pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr; |
| 139930 | 139988 | pScan->zCollName = pIdx->azColl[j]; |
| 139989 | + pScan->aiColumn[0] = XN_EXPR; | |
| 139990 | + return whereScanInitIndexExpr(pScan); | |
| 139931 | 139991 | }else if( iColumn==pIdx->pTable->iPKey ){ |
| 139932 | 139992 | iColumn = XN_ROWID; |
| 139933 | 139993 | }else if( iColumn>=0 ){ |
| 139934 | 139994 | pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity; |
| 139935 | 139995 | pScan->zCollName = pIdx->azColl[j]; |
| 139936 | 139996 | } |
| 139937 | 139997 | }else if( iColumn==XN_EXPR ){ |
| 139938 | 139998 | return 0; |
| 139939 | 139999 | } |
| 139940 | - pScan->opMask = opMask; | |
| 139941 | - pScan->k = 0; | |
| 139942 | - pScan->aiCur[0] = iCur; | |
| 139943 | 140000 | pScan->aiColumn[0] = iColumn; |
| 139944 | - pScan->nEquiv = 1; | |
| 139945 | - pScan->iEquiv = 1; | |
| 139946 | 140001 | return whereScanNext(pScan); |
| 139947 | 140002 | } |
| 139948 | 140003 | |
| 139949 | 140004 | /* |
| 139950 | 140005 | ** Search for a term in the WHERE clause that is of the form "X <op> <expr>" |
| @@ -152900,11 +152955,18 @@ | ||
| 152900 | 152955 | db->u1.isInterrupted = 0; |
| 152901 | 152956 | } |
| 152902 | 152957 | pParse->rc = SQLITE_OK; |
| 152903 | 152958 | pParse->zTail = zSql; |
| 152904 | 152959 | assert( pzErrMsg!=0 ); |
| 152905 | - /* sqlite3ParserTrace(stdout, "parser: "); */ | |
| 152960 | +#ifdef SQLITE_DEBUG | |
| 152961 | + if( db->flags & SQLITE_ParserTrace ){ | |
| 152962 | + printf("parser: [[[%s]]]\n", zSql); | |
| 152963 | + sqlite3ParserTrace(stdout, "parser: "); | |
| 152964 | + }else{ | |
| 152965 | + sqlite3ParserTrace(0, 0); | |
| 152966 | + } | |
| 152967 | +#endif | |
| 152906 | 152968 | #ifdef sqlite3Parser_ENGINEALWAYSONSTACK |
| 152907 | 152969 | pEngine = &sEngine; |
| 152908 | 152970 | sqlite3ParserInit(pEngine, pParse); |
| 152909 | 152971 | #else |
| 152910 | 152972 | pEngine = sqlite3ParserAlloc(sqlite3Malloc, pParse); |
| @@ -154223,10 +154285,17 @@ | ||
| 154223 | 154285 | sqlite3GlobalConfig.szSorterRef = (u32)iVal; |
| 154224 | 154286 | break; |
| 154225 | 154287 | } |
| 154226 | 154288 | #endif /* SQLITE_ENABLE_SORTER_REFERENCES */ |
| 154227 | 154289 | |
| 154290 | +#ifdef SQLITE_ENABLE_DESERIALIZE | |
| 154291 | + case SQLITE_CONFIG_MEMDB_MAXSIZE: { | |
| 154292 | + sqlite3GlobalConfig.mxMemdbSize = va_arg(ap, sqlite3_int64); | |
| 154293 | + break; | |
| 154294 | + } | |
| 154295 | +#endif /* SQLITE_ENABLE_DESERIALIZE */ | |
| 154296 | + | |
| 154228 | 154297 | default: { |
| 154229 | 154298 | rc = SQLITE_ERROR; |
| 154230 | 154299 | break; |
| 154231 | 154300 | } |
| 154232 | 154301 | } |
| @@ -161990,10 +162059,11 @@ | ||
| 161990 | 162059 | */ |
| 161991 | 162060 | pTS->aaOutput[0] = sqlite3_malloc(nDoclist + FTS3_VARINT_MAX + 1); |
| 161992 | 162061 | pTS->anOutput[0] = nDoclist; |
| 161993 | 162062 | if( pTS->aaOutput[0] ){ |
| 161994 | 162063 | memcpy(pTS->aaOutput[0], aDoclist, nDoclist); |
| 162064 | + memset(&pTS->aaOutput[0][nDoclist], 0, FTS3_VARINT_MAX); | |
| 161995 | 162065 | }else{ |
| 161996 | 162066 | return SQLITE_NOMEM; |
| 161997 | 162067 | } |
| 161998 | 162068 | }else{ |
| 161999 | 162069 | char *aMerge = aDoclist; |
| @@ -165603,19 +165673,19 @@ | ||
| 165603 | 165673 | if( iEq>=0 || iGe>=0 ){ |
| 165604 | 165674 | const unsigned char *zStr = sqlite3_value_text(apVal[0]); |
| 165605 | 165675 | assert( (iEq==0 && iGe==-1) || (iEq==-1 && iGe==0) ); |
| 165606 | 165676 | if( zStr ){ |
| 165607 | 165677 | pCsr->filter.zTerm = sqlite3_mprintf("%s", zStr); |
| 165608 | - pCsr->filter.nTerm = sqlite3_value_bytes(apVal[0]); | |
| 165609 | 165678 | if( pCsr->filter.zTerm==0 ) return SQLITE_NOMEM; |
| 165679 | + pCsr->filter.nTerm = (int)strlen(pCsr->filter.zTerm); | |
| 165610 | 165680 | } |
| 165611 | 165681 | } |
| 165612 | 165682 | |
| 165613 | 165683 | if( iLe>=0 ){ |
| 165614 | 165684 | pCsr->zStop = sqlite3_mprintf("%s", sqlite3_value_text(apVal[iLe])); |
| 165615 | - pCsr->nStop = sqlite3_value_bytes(apVal[iLe]); | |
| 165616 | 165685 | if( pCsr->zStop==0 ) return SQLITE_NOMEM; |
| 165686 | + pCsr->nStop = (int)strlen(pCsr->zStop); | |
| 165617 | 165687 | } |
| 165618 | 165688 | |
| 165619 | 165689 | if( iLangid>=0 ){ |
| 165620 | 165690 | iLangVal = sqlite3_value_int(apVal[iLangid]); |
| 165621 | 165691 | |
| @@ -202679,11 +202749,13 @@ | ||
| 202679 | 202749 | int iAdj; |
| 202680 | 202750 | int nScore; |
| 202681 | 202751 | int jj; |
| 202682 | 202752 | |
| 202683 | 202753 | rc = pApi->xInst(pFts, ii, &ip, &ic, &io); |
| 202684 | - if( ic!=i || rc!=SQLITE_OK ) continue; | |
| 202754 | + if( ic!=i ) continue; | |
| 202755 | + if( io>nDocsize ) rc = FTS5_CORRUPT; | |
| 202756 | + if( rc!=SQLITE_OK ) continue; | |
| 202685 | 202757 | memset(aSeen, 0, nPhrase); |
| 202686 | 202758 | rc = fts5SnippetScore(pApi, pFts, nDocsize, aSeen, i, |
| 202687 | 202759 | io, nToken, &nScore, &iAdj |
| 202688 | 202760 | ); |
| 202689 | 202761 | if( rc==SQLITE_OK && nScore>nBestScore ){ |
| @@ -209352,11 +209424,11 @@ | ||
| 209352 | 209424 | u8 *a = pIter->pLeaf->p; /* Buffer to read data from */ |
| 209353 | 209425 | int iOff = pIter->iLeafOffset; /* Offset to read at */ |
| 209354 | 209426 | int nNew; /* Bytes of new data */ |
| 209355 | 209427 | |
| 209356 | 209428 | iOff += fts5GetVarint32(&a[iOff], nNew); |
| 209357 | - if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n ){ | |
| 209429 | + if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){ | |
| 209358 | 209430 | p->rc = FTS5_CORRUPT; |
| 209359 | 209431 | return; |
| 209360 | 209432 | } |
| 209361 | 209433 | pIter->term.n = nKeep; |
| 209362 | 209434 | fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]); |
| @@ -210026,11 +210098,11 @@ | ||
| 210026 | 210098 | }while( 1 ); |
| 210027 | 210099 | } |
| 210028 | 210100 | |
| 210029 | 210101 | search_success: |
| 210030 | 210102 | pIter->iLeafOffset = iOff + nNew; |
| 210031 | - if( pIter->iLeafOffset>n ){ | |
| 210103 | + if( pIter->iLeafOffset>n || nNew<1 ){ | |
| 210032 | 210104 | p->rc = FTS5_CORRUPT; |
| 210033 | 210105 | return; |
| 210034 | 210106 | } |
| 210035 | 210107 | pIter->iTermLeafOffset = pIter->iLeafOffset; |
| 210036 | 210108 | pIter->iTermLeafPgno = pIter->iLeafPgno; |
| @@ -210804,11 +210876,12 @@ | ||
| 210804 | 210876 | Fts5Index *p, |
| 210805 | 210877 | Fts5SegIter *pSeg, |
| 210806 | 210878 | Fts5Colset *pColset, |
| 210807 | 210879 | Fts5Buffer *pBuf |
| 210808 | 210880 | ){ |
| 210809 | - if( 0==fts5BufferGrow(&p->rc, pBuf, pSeg->nPos) ){ | |
| 210881 | + if( 0==fts5BufferGrow(&p->rc, pBuf, pSeg->nPos+FTS5_DATA_ZERO_PADDING) ){ | |
| 210882 | + memset(&pBuf->p[pBuf->n+pSeg->nPos], 0, FTS5_DATA_ZERO_PADDING); | |
| 210810 | 210883 | if( pColset==0 ){ |
| 210811 | 210884 | fts5ChunkIterate(p, pSeg, (void*)pBuf, fts5PoslistCallback); |
| 210812 | 210885 | }else{ |
| 210813 | 210886 | if( p->pConfig->eDetail==FTS5_DETAIL_FULL ){ |
| 210814 | 210887 | PoslistCallbackCtx sCtx; |
| @@ -211845,11 +211918,11 @@ | ||
| 211845 | 211918 | Fts5Data *pData; |
| 211846 | 211919 | int iId = pSeg->pSeg->iSegid; |
| 211847 | 211920 | u8 aHdr[4] = {0x00, 0x00, 0x00, 0x00}; |
| 211848 | 211921 | |
| 211849 | 211922 | iLeafRowid = FTS5_SEGMENT_ROWID(iId, pSeg->iTermLeafPgno); |
| 211850 | - pData = fts5DataRead(p, iLeafRowid); | |
| 211923 | + pData = fts5LeafRead(p, iLeafRowid); | |
| 211851 | 211924 | if( pData ){ |
| 211852 | 211925 | if( iOff>pData->szLeaf ){ |
| 211853 | 211926 | /* This can occur if the pages that the segments occupy overlap - if |
| 211854 | 211927 | ** a single page has been assigned to more than one segment. In |
| 211855 | 211928 | ** this case a prior iteration of this loop may have corrupted the |
| @@ -212700,11 +212773,11 @@ | ||
| 212700 | 212773 | sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos1); |
| 212701 | 212774 | } |
| 212702 | 212775 | sqlite3Fts5PoslistNext64(a1, i1.nPoslist, &iOff1, &iPos1); |
| 212703 | 212776 | if( iPos1<0 ) break; |
| 212704 | 212777 | }else{ |
| 212705 | - assert( iPos2!=iPrev ); | |
| 212778 | + assert_nc( iPos2!=iPrev ); | |
| 212706 | 212779 | sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos2); |
| 212707 | 212780 | sqlite3Fts5PoslistNext64(a2, i2.nPoslist, &iOff2, &iPos2); |
| 212708 | 212781 | if( iPos2<0 ) break; |
| 212709 | 212782 | } |
| 212710 | 212783 | } |
| @@ -215964,11 +216037,13 @@ | ||
| 215964 | 216037 | const char **pz, |
| 215965 | 216038 | int *pn |
| 215966 | 216039 | ){ |
| 215967 | 216040 | int rc = SQLITE_OK; |
| 215968 | 216041 | Fts5Cursor *pCsr = (Fts5Cursor*)pCtx; |
| 215969 | - if( fts5IsContentless((Fts5FullTable*)(pCsr->base.pVtab)) ){ | |
| 216042 | + if( fts5IsContentless((Fts5FullTable*)(pCsr->base.pVtab)) | |
| 216043 | + || pCsr->ePlan==FTS5_PLAN_SPECIAL | |
| 216044 | + ){ | |
| 215970 | 216045 | *pz = 0; |
| 215971 | 216046 | *pn = 0; |
| 215972 | 216047 | }else{ |
| 215973 | 216048 | rc = fts5SeekCursor(pCsr, 0); |
| 215974 | 216049 | if( rc==SQLITE_OK ){ |
| @@ -216902,11 +216977,11 @@ | ||
| 216902 | 216977 | int nArg, /* Number of args */ |
| 216903 | 216978 | sqlite3_value **apUnused /* Function arguments */ |
| 216904 | 216979 | ){ |
| 216905 | 216980 | assert( nArg==0 ); |
| 216906 | 216981 | UNUSED_PARAM2(nArg, apUnused); |
| 216907 | - sqlite3_result_text(pCtx, "fts5: 2019-01-26 23:34:50 a3ea1a822d3a110f4f186f2fc8550f435c8c98635d058096b7be9d4df7066b8b", -1, SQLITE_TRANSIENT); | |
| 216982 | + sqlite3_result_text(pCtx, "fts5: 2019-02-01 15:06:27 4ca9d5d53d41d08fbce29f9da8cc0948df9c4c3136210af88b499cf889b5ccb8", -1, SQLITE_TRANSIENT); | |
| 216908 | 216983 | } |
| 216909 | 216984 | |
| 216910 | 216985 | /* |
| 216911 | 216986 | ** Return true if zName is the extension on one of the shadow tables used |
| 216912 | 216987 | ** by this module. |
| @@ -221072,10 +221147,11 @@ | ||
| 221072 | 221147 | }else{ |
| 221073 | 221148 | const char *zTerm; |
| 221074 | 221149 | int nTerm; |
| 221075 | 221150 | |
| 221076 | 221151 | zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm); |
| 221152 | + assert( nTerm>=0 ); | |
| 221077 | 221153 | if( pCsr->nLeTerm>=0 ){ |
| 221078 | 221154 | int nCmp = MIN(nTerm, pCsr->nLeTerm); |
| 221079 | 221155 | int bCmp = memcmp(pCsr->zLeTerm, zTerm, nCmp); |
| 221080 | 221156 | if( bCmp<0 || (bCmp==0 && pCsr->nLeTerm<nTerm) ){ |
| 221081 | 221157 | pCsr->bEof = 1; |
| @@ -221665,12 +221741,12 @@ | ||
| 221665 | 221741 | } |
| 221666 | 221742 | #endif /* SQLITE_CORE */ |
| 221667 | 221743 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 221668 | 221744 | |
| 221669 | 221745 | /************** End of stmt.c ************************************************/ |
| 221670 | -#if __LINE__!=221670 | |
| 221746 | +#if __LINE__!=221746 | |
| 221671 | 221747 | #undef SQLITE_SOURCE_ID |
| 221672 | -#define SQLITE_SOURCE_ID "2019-01-27 02:45:32 9cf8ebd141aa2eb661d457624c76433bd9e4abfdef04aa52e28bc169172calt2" | |
| 221748 | +#define SQLITE_SOURCE_ID "2019-02-01 15:06:27 4ca9d5d53d41d08fbce29f9da8cc0948df9c4c3136210af88b499cf889b5alt2" | |
| 221673 | 221749 | #endif |
| 221674 | 221750 | /* Return the source-id for this library */ |
| 221675 | 221751 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 221676 | 221752 | /************************** End of sqlite3.c ******************************/ |
| 221677 | 221753 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1162,11 +1162,11 @@ | |
| 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1164 | */ |
| 1165 | #define SQLITE_VERSION "3.27.0" |
| 1166 | #define SQLITE_VERSION_NUMBER 3027000 |
| 1167 | #define SQLITE_SOURCE_ID "2019-01-27 02:45:32 9cf8ebd141aa2eb661d457624c76433bd9e4abfdef04aa52e28bc169172calt1" |
| 1168 | |
| 1169 | /* |
| 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1172 | ** |
| @@ -3019,10 +3019,21 @@ | |
| 3019 | ** from the database as records are returned in sorted order. The default |
| 3020 | ** value for this option is to never use this optimization. Specifying a |
| 3021 | ** negative value for this option restores the default behaviour. |
| 3022 | ** This option is only available if SQLite is compiled with the |
| 3023 | ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option. |
| 3024 | ** </dl> |
| 3025 | */ |
| 3026 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 3027 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 3028 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| @@ -3049,10 +3060,11 @@ | |
| 3049 | #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ |
| 3050 | #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */ |
| 3051 | #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */ |
| 3052 | #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */ |
| 3053 | #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */ |
| 3054 | |
| 3055 | /* |
| 3056 | ** CAPI3REF: Database Connection Configuration Options |
| 3057 | ** |
| 3058 | ** These constants are the available integer configuration options that |
| @@ -16433,10 +16445,11 @@ | |
| 16433 | #define SQLITE_SqlTrace HI(0x0001) /* Debug print SQL as it executes */ |
| 16434 | #define SQLITE_VdbeListing HI(0x0002) /* Debug listings of VDBE progs */ |
| 16435 | #define SQLITE_VdbeTrace HI(0x0004) /* True to trace VDBE execution */ |
| 16436 | #define SQLITE_VdbeAddopTrace HI(0x0008) /* Trace sqlite3VdbeAddOp() calls */ |
| 16437 | #define SQLITE_VdbeEQP HI(0x0010) /* Debug EXPLAIN QUERY PLAN */ |
| 16438 | #endif |
| 16439 | |
| 16440 | /* |
| 16441 | ** Allowed values for sqlite3.mDbFlags |
| 16442 | */ |
| @@ -18305,10 +18318,13 @@ | |
| 18305 | ** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE. |
| 18306 | */ |
| 18307 | void (*xVdbeBranch)(void*,unsigned iSrcLine,u8 eThis,u8 eMx); /* Callback */ |
| 18308 | void *pVdbeBranchArg; /* 1st argument */ |
| 18309 | #endif |
| 18310 | #ifndef SQLITE_UNTESTABLE |
| 18311 | int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */ |
| 18312 | #endif |
| 18313 | int bLocaltimeFault; /* True to fail localtime() calls */ |
| 18314 | int bInternalFunctions; /* Internal SQL functions are visible */ |
| @@ -18722,10 +18738,11 @@ | |
| 18722 | SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int); |
| 18723 | SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int); |
| 18724 | SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*); |
| 18725 | SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*); |
| 18726 | SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*); |
| 18727 | SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**); |
| 18728 | SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**); |
| 18729 | SQLITE_PRIVATE int sqlite3InitOne(sqlite3*, int, char**, u32); |
| 18730 | SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int); |
| 18731 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| @@ -19716,10 +19733,17 @@ | |
| 19716 | #ifndef SQLITE_DEFAULT_LOOKASIDE |
| 19717 | # define SQLITE_DEFAULT_LOOKASIDE 1200,100 |
| 19718 | #endif |
| 19719 | |
| 19720 | |
| 19721 | /* |
| 19722 | ** The following singleton contains the global configuration for |
| 19723 | ** the SQLite library. |
| 19724 | */ |
| 19725 | SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = { |
| @@ -19763,17 +19787,20 @@ | |
| 19763 | #endif |
| 19764 | #ifdef SQLITE_VDBE_COVERAGE |
| 19765 | 0, /* xVdbeBranch */ |
| 19766 | 0, /* pVbeBranchArg */ |
| 19767 | #endif |
| 19768 | #ifndef SQLITE_UNTESTABLE |
| 19769 | 0, /* xTestCallback */ |
| 19770 | #endif |
| 19771 | 0, /* bLocaltimeFault */ |
| 19772 | 0, /* bInternalFunctions */ |
| 19773 | 0x7ffffffe, /* iOnceResetThreshold */ |
| 19774 | SQLITE_DEFAULT_SORTERREF_SIZE /* szSorterRef */ |
| 19775 | }; |
| 19776 | |
| 19777 | /* |
| 19778 | ** Hash table for global functions - functions common to all |
| 19779 | ** database connections. After initialization, this table is |
| @@ -46578,15 +46605,10 @@ | |
| 46578 | int nMmap; /* Number of memory mapped pages */ |
| 46579 | unsigned mFlags; /* Flags */ |
| 46580 | int eLock; /* Most recent lock against this file */ |
| 46581 | }; |
| 46582 | |
| 46583 | /* The default maximum size of an in-memory database */ |
| 46584 | #ifndef SQLITE_MEMDB_DEFAULT_MAXSIZE |
| 46585 | # define SQLITE_MEMDB_DEFAULT_MAXSIZE 1073741824 |
| 46586 | #endif |
| 46587 | |
| 46588 | /* |
| 46589 | ** Methods for MemFile |
| 46590 | */ |
| 46591 | static int memdbClose(sqlite3_file*); |
| 46592 | static int memdbRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); |
| @@ -46847,11 +46869,10 @@ | |
| 46847 | int iAmt, |
| 46848 | void **pp |
| 46849 | ){ |
| 46850 | MemFile *p = (MemFile *)pFile; |
| 46851 | if( iOfst+iAmt>p->sz ){ |
| 46852 | assert( CORRUPT_DB ); |
| 46853 | *pp = 0; |
| 46854 | }else{ |
| 46855 | p->nMmap++; |
| 46856 | *pp = (void*)(p->aData + iOfst); |
| 46857 | } |
| @@ -46882,11 +46903,11 @@ | |
| 46882 | memset(p, 0, sizeof(*p)); |
| 46883 | p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE; |
| 46884 | assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */ |
| 46885 | *pOutFlags = flags | SQLITE_OPEN_MEMORY; |
| 46886 | p->base.pMethods = &memdb_io_methods; |
| 46887 | p->szMax = SQLITE_MEMDB_DEFAULT_MAXSIZE; |
| 46888 | return SQLITE_OK; |
| 46889 | } |
| 46890 | |
| 46891 | #if 0 /* Only used to delete rollback journals, master journals, and WAL |
| 46892 | ** files, none of which exist in memdb. So this routine is never used */ |
| @@ -47134,12 +47155,12 @@ | |
| 47134 | }else{ |
| 47135 | p->aData = pData; |
| 47136 | p->sz = szDb; |
| 47137 | p->szAlloc = szBuf; |
| 47138 | p->szMax = szBuf; |
| 47139 | if( p->szMax<SQLITE_MEMDB_DEFAULT_MAXSIZE ){ |
| 47140 | p->szMax = SQLITE_MEMDB_DEFAULT_MAXSIZE; |
| 47141 | } |
| 47142 | p->mFlags = mFlags; |
| 47143 | rc = SQLITE_OK; |
| 47144 | } |
| 47145 | |
| @@ -62473,13 +62494,20 @@ | |
| 62473 | ** |
| 62474 | ** Fields in this structure are accessed under the BtShared.mutex |
| 62475 | ** found at self->pBt->mutex. |
| 62476 | ** |
| 62477 | ** skipNext meaning: |
| 62478 | ** eState==SKIPNEXT && skipNext>0: Next sqlite3BtreeNext() is no-op. |
| 62479 | ** eState==SKIPNEXT && skipNext<0: Next sqlite3BtreePrevious() is no-op. |
| 62480 | ** eState==FAULT: Cursor fault with skipNext as error code. |
| 62481 | */ |
| 62482 | struct BtCursor { |
| 62483 | u8 eState; /* One of the CURSOR_XXX constants (see below) */ |
| 62484 | u8 curFlags; /* zero or more BTCF_* flags defined below */ |
| 62485 | u8 curPagerFlags; /* Flags to send to sqlite3PagerGet() */ |
| @@ -63824,11 +63852,11 @@ | |
| 63824 | rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext); |
| 63825 | if( rc==SQLITE_OK ){ |
| 63826 | sqlite3_free(pCur->pKey); |
| 63827 | pCur->pKey = 0; |
| 63828 | assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID ); |
| 63829 | pCur->skipNext |= skipNext; |
| 63830 | if( pCur->skipNext && pCur->eState==CURSOR_VALID ){ |
| 63831 | pCur->eState = CURSOR_SKIPNEXT; |
| 63832 | } |
| 63833 | } |
| 63834 | return rc; |
| @@ -63894,11 +63922,10 @@ | |
| 63894 | return rc; |
| 63895 | } |
| 63896 | if( pCur->eState!=CURSOR_VALID ){ |
| 63897 | *pDifferentRow = 1; |
| 63898 | }else{ |
| 63899 | assert( pCur->skipNext==0 ); |
| 63900 | *pDifferentRow = 0; |
| 63901 | } |
| 63902 | return SQLITE_OK; |
| 63903 | } |
| 63904 | |
| @@ -68313,11 +68340,11 @@ | |
| 68313 | } |
| 68314 | /* If the requested key is one more than the previous key, then |
| 68315 | ** try to get there using sqlite3BtreeNext() rather than a full |
| 68316 | ** binary search. This is an optimization only. The correct answer |
| 68317 | ** is still obtained without this case, only a little more slowely */ |
| 68318 | if( pCur->info.nKey+1==intKey && !pCur->skipNext ){ |
| 68319 | *pRes = 0; |
| 68320 | rc = sqlite3BtreeNext(pCur, 0); |
| 68321 | if( rc==SQLITE_OK ){ |
| 68322 | getCellInfo(pCur); |
| 68323 | if( pCur->info.nKey==intKey ){ |
| @@ -68587,28 +68614,22 @@ | |
| 68587 | int rc; |
| 68588 | int idx; |
| 68589 | MemPage *pPage; |
| 68590 | |
| 68591 | assert( cursorOwnsBtShared(pCur) ); |
| 68592 | assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID ); |
| 68593 | if( pCur->eState!=CURSOR_VALID ){ |
| 68594 | assert( (pCur->curFlags & BTCF_ValidOvfl)==0 ); |
| 68595 | rc = restoreCursorPosition(pCur); |
| 68596 | if( rc!=SQLITE_OK ){ |
| 68597 | return rc; |
| 68598 | } |
| 68599 | if( CURSOR_INVALID==pCur->eState ){ |
| 68600 | return SQLITE_DONE; |
| 68601 | } |
| 68602 | if( pCur->skipNext ){ |
| 68603 | assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT ); |
| 68604 | pCur->eState = CURSOR_VALID; |
| 68605 | if( pCur->skipNext>0 ){ |
| 68606 | pCur->skipNext = 0; |
| 68607 | return SQLITE_OK; |
| 68608 | } |
| 68609 | pCur->skipNext = 0; |
| 68610 | } |
| 68611 | } |
| 68612 | |
| 68613 | pPage = pCur->pPage; |
| 68614 | idx = ++pCur->ix; |
| @@ -68659,11 +68680,10 @@ | |
| 68659 | SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int flags){ |
| 68660 | MemPage *pPage; |
| 68661 | UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */ |
| 68662 | assert( cursorOwnsBtShared(pCur) ); |
| 68663 | assert( flags==0 || flags==1 ); |
| 68664 | assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID ); |
| 68665 | pCur->info.nSize = 0; |
| 68666 | pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl); |
| 68667 | if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur); |
| 68668 | pPage = pCur->pPage; |
| 68669 | if( (++pCur->ix)>=pPage->nCell ){ |
| @@ -68700,11 +68720,10 @@ | |
| 68700 | static SQLITE_NOINLINE int btreePrevious(BtCursor *pCur){ |
| 68701 | int rc; |
| 68702 | MemPage *pPage; |
| 68703 | |
| 68704 | assert( cursorOwnsBtShared(pCur) ); |
| 68705 | assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID ); |
| 68706 | assert( (pCur->curFlags & (BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey))==0 ); |
| 68707 | assert( pCur->info.nSize==0 ); |
| 68708 | if( pCur->eState!=CURSOR_VALID ){ |
| 68709 | rc = restoreCursorPosition(pCur); |
| 68710 | if( rc!=SQLITE_OK ){ |
| @@ -68711,18 +68730,13 @@ | |
| 68711 | return rc; |
| 68712 | } |
| 68713 | if( CURSOR_INVALID==pCur->eState ){ |
| 68714 | return SQLITE_DONE; |
| 68715 | } |
| 68716 | if( pCur->skipNext ){ |
| 68717 | assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT ); |
| 68718 | pCur->eState = CURSOR_VALID; |
| 68719 | if( pCur->skipNext<0 ){ |
| 68720 | pCur->skipNext = 0; |
| 68721 | return SQLITE_OK; |
| 68722 | } |
| 68723 | pCur->skipNext = 0; |
| 68724 | } |
| 68725 | } |
| 68726 | |
| 68727 | pPage = pCur->pPage; |
| 68728 | assert( pPage->isInit ); |
| @@ -68753,11 +68767,10 @@ | |
| 68753 | return rc; |
| 68754 | } |
| 68755 | SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int flags){ |
| 68756 | assert( cursorOwnsBtShared(pCur) ); |
| 68757 | assert( flags==0 || flags==1 ); |
| 68758 | assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID ); |
| 68759 | UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */ |
| 68760 | pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey); |
| 68761 | pCur->info.nSize = 0; |
| 68762 | if( pCur->eState!=CURSOR_VALID |
| 68763 | || pCur->ix==0 |
| @@ -69722,27 +69735,38 @@ | |
| 69722 | ** / | \ |
| 69723 | ** --------- --------- --------- |
| 69724 | ** |Child-1| |Child-2| |Child-3| |
| 69725 | ** --------- --------- --------- |
| 69726 | ** |
| 69727 | ** The order of cells is in the array is: |
| 69728 | ** |
| 69729 | ** 1. All cells from Child-1 in order |
| 69730 | ** 2. The first divider cell from Parent |
| 69731 | ** 3. All cells from Child-2 in order |
| 69732 | ** 4. The second divider cell from Parent |
| 69733 | ** 5. All cells from Child-3 in order |
| 69734 | ** |
| 69735 | ** The apEnd[] array holds pointer to the end of page for Child-1, the |
| 69736 | ** Parent, Child-2, the Parent (again), and Child-3. The ixNx[] array |
| 69737 | ** holds the number of cells contained in each of these 5 stages, and |
| 69738 | ** all stages to the left. Hence: |
| 69739 | ** ixNx[0] = Number of cells in Child-1. |
| 69740 | ** ixNx[1] = Number of cells in Child-1 plus 1 for first divider. |
| 69741 | ** ixNx[2] = Number of cells in Child-1 and Child-2 + 1 for 1st divider. |
| 69742 | ** ixNx[3] = Number of cells in Child-1 and Child-2 + both divider cells |
| 69743 | ** ixNx[4] = Total number of cells. |
| 69744 | */ |
| 69745 | typedef struct CellArray CellArray; |
| 69746 | struct CellArray { |
| 69747 | int nCell; /* Number of cells in apCell[] */ |
| 69748 | MemPage *pRef; /* Reference page */ |
| @@ -69808,20 +69832,21 @@ | |
| 69808 | const int hdr = pPg->hdrOffset; /* Offset of header on pPg */ |
| 69809 | u8 * const aData = pPg->aData; /* Pointer to data for pPg */ |
| 69810 | const int usableSize = pPg->pBt->usableSize; |
| 69811 | u8 * const pEnd = &aData[usableSize]; |
| 69812 | int i = iFirst; /* Which cell to copy from pCArray*/ |
| 69813 | int j; /* Start of cell content area */ |
| 69814 | int iEnd = i+nCell; /* Loop terminator */ |
| 69815 | u8 *pCellptr = pPg->aCellIdx; |
| 69816 | u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager); |
| 69817 | u8 *pData; |
| 69818 | int k; /* Current slot in pCArray->apEnd[] */ |
| 69819 | u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */ |
| 69820 | |
| 69821 | assert( i<iEnd ); |
| 69822 | j = get2byte(&aData[hdr+5]); |
| 69823 | memcpy(&pTmp[j], &aData[j], usableSize - j); |
| 69824 | |
| 69825 | for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){} |
| 69826 | pSrcEnd = pCArray->apEnd[k]; |
| 69827 | |
| @@ -69997,11 +70022,11 @@ | |
| 69997 | } |
| 69998 | return nRet; |
| 69999 | } |
| 70000 | |
| 70001 | /* |
| 70002 | ** pCArray contains pointers to and sizes of all cells in the pages being |
| 70003 | ** balanced. The current page, pPg, has pPg->nCell cells starting with |
| 70004 | ** pCArray->apCell[iOld]. After balancing, this page should hold nNew cells |
| 70005 | ** starting at apCell[iNew]. |
| 70006 | ** |
| 70007 | ** This routine makes the necessary adjustments to pPg so that it contains |
| @@ -70031,26 +70056,31 @@ | |
| 70031 | u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager); |
| 70032 | memcpy(pTmp, aData, pPg->pBt->usableSize); |
| 70033 | #endif |
| 70034 | |
| 70035 | /* Remove cells from the start and end of the page */ |
| 70036 | if( iOld<iNew ){ |
| 70037 | int nShift = pageFreeArray(pPg, iOld, iNew-iOld, pCArray); |
| 70038 | memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2); |
| 70039 | nCell -= nShift; |
| 70040 | } |
| 70041 | if( iNewEnd < iOldEnd ){ |
| 70042 | nCell -= pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray); |
| 70043 | } |
| 70044 | |
| 70045 | pData = &aData[get2byteNotZero(&aData[hdr+5])]; |
| 70046 | if( pData<pBegin ) goto editpage_fail; |
| 70047 | |
| 70048 | /* Add cells to the start of the page */ |
| 70049 | if( iNew<iOld ){ |
| 70050 | int nAdd = MIN(nNew,iOld-iNew); |
| 70051 | assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB ); |
| 70052 | pCellptr = pPg->aCellIdx; |
| 70053 | memmove(&pCellptr[nAdd*2], pCellptr, nCell*2); |
| 70054 | if( pageInsertArray( |
| 70055 | pPg, pBegin, &pData, pCellptr, |
| 70056 | iNew, nAdd, pCArray |
| @@ -70061,10 +70091,11 @@ | |
| 70061 | /* Add any overflow cells */ |
| 70062 | for(i=0; i<pPg->nOverflow; i++){ |
| 70063 | int iCell = (iOld + pPg->aiOvfl[i]) - iNew; |
| 70064 | if( iCell>=0 && iCell<nNew ){ |
| 70065 | pCellptr = &pPg->aCellIdx[iCell * 2]; |
| 70066 | memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2); |
| 70067 | nCell++; |
| 70068 | if( pageInsertArray( |
| 70069 | pPg, pBegin, &pData, pCellptr, |
| 70070 | iCell+iNew, 1, pCArray |
| @@ -70071,10 +70102,11 @@ | |
| 70071 | ) ) goto editpage_fail; |
| 70072 | } |
| 70073 | } |
| 70074 | |
| 70075 | /* Append cells to the end of the page */ |
| 70076 | pCellptr = &pPg->aCellIdx[nCell*2]; |
| 70077 | if( pageInsertArray( |
| 70078 | pPg, pBegin, &pData, pCellptr, |
| 70079 | iNew+nCell, nNew-nCell, pCArray |
| 70080 | ) ) goto editpage_fail; |
| @@ -70644,16 +70676,19 @@ | |
| 70644 | ** the right of the i-th sibling page. |
| 70645 | ** usableSpace: Number of bytes of space available on each sibling. |
| 70646 | ** |
| 70647 | */ |
| 70648 | usableSpace = pBt->usableSize - 12 + leafCorrection; |
| 70649 | for(i=0; i<nOld; i++){ |
| 70650 | MemPage *p = apOld[i]; |
| 70651 | b.apEnd[i*2] = p->aDataEnd; |
| 70652 | b.apEnd[i*2+1] = pParent->aDataEnd; |
| 70653 | b.ixNx[i*2] = cntOld[i]; |
| 70654 | b.ixNx[i*2+1] = cntOld[i]+1; |
| 70655 | szNew[i] = usableSpace - p->nFree; |
| 70656 | for(j=0; j<p->nOverflow; j++){ |
| 70657 | szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]); |
| 70658 | } |
| 70659 | cntNew[i] = cntOld[i]; |
| @@ -71749,11 +71784,10 @@ | |
| 71749 | ** from the internal node. The 'previous' entry is used for this instead |
| 71750 | ** of the 'next' entry, as the previous entry is always a part of the |
| 71751 | ** sub-tree headed by the child page of the cell being deleted. This makes |
| 71752 | ** balancing the tree following the delete operation easier. */ |
| 71753 | if( !pPage->leaf ){ |
| 71754 | pCur->skipNext = 0; |
| 71755 | rc = sqlite3BtreePrevious(pCur, 0); |
| 71756 | assert( rc!=SQLITE_DONE ); |
| 71757 | if( rc ) return rc; |
| 71758 | } |
| 71759 | |
| @@ -97882,10 +97916,11 @@ | |
| 97882 | static void gatherSelectWindows(Select *p){ |
| 97883 | Walker w; |
| 97884 | w.xExprCallback = gatherSelectWindowsCallback; |
| 97885 | w.xSelectCallback = gatherSelectWindowsSelectCallback; |
| 97886 | w.xSelectCallback2 = 0; |
| 97887 | w.u.pSelect = p; |
| 97888 | sqlite3WalkSelect(&w, p); |
| 97889 | } |
| 97890 | #endif |
| 97891 | |
| @@ -109965,21 +110000,26 @@ | |
| 109965 | assert( pParse->nErr==0 ); |
| 109966 | if( db->init.busy ){ |
| 109967 | Index *p; |
| 109968 | assert( !IN_SPECIAL_PARSE ); |
| 109969 | assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) ); |
| 109970 | p = sqlite3HashInsert(&pIndex->pSchema->idxHash, |
| 109971 | pIndex->zName, pIndex); |
| 109972 | if( p ){ |
| 109973 | assert( p==pIndex ); /* Malloc must have failed */ |
| 109974 | sqlite3OomFault(db); |
| 109975 | goto exit_create_index; |
| 109976 | } |
| 109977 | db->mDbFlags |= DBFLAG_SchemaChange; |
| 109978 | if( pTblName!=0 ){ |
| 109979 | pIndex->tnum = db->init.newTnum; |
| 109980 | } |
| 109981 | } |
| 109982 | |
| 109983 | /* If this is the initial CREATE INDEX statement (or CREATE TABLE if the |
| 109984 | ** index is an implied index for a UNIQUE or PRIMARY KEY constraint) then |
| 109985 | ** emit code to allocate the index rootpage on disk and make an entry for |
| @@ -120194,12 +120234,11 @@ | |
| 120194 | #define PragTyp_WAL_CHECKPOINT 39 |
| 120195 | #define PragTyp_ACTIVATE_EXTENSIONS 40 |
| 120196 | #define PragTyp_HEXKEY 41 |
| 120197 | #define PragTyp_KEY 42 |
| 120198 | #define PragTyp_LOCK_STATUS 43 |
| 120199 | #define PragTyp_PARSER_TRACE 44 |
| 120200 | #define PragTyp_STATS 45 |
| 120201 | |
| 120202 | /* Property flags associated with various pragma. */ |
| 120203 | #define PragFlg_NeedSchema 0x01 /* Force schema load before running */ |
| 120204 | #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */ |
| 120205 | #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */ |
| @@ -120618,16 +120657,18 @@ | |
| 120618 | /* ePragTyp: */ PragTyp_PAGE_SIZE, |
| 120619 | /* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1, |
| 120620 | /* ColNames: */ 0, 0, |
| 120621 | /* iArg: */ 0 }, |
| 120622 | #endif |
| 120623 | #if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_PARSER_TRACE) |
| 120624 | {/* zName: */ "parser_trace", |
| 120625 | /* ePragTyp: */ PragTyp_PARSER_TRACE, |
| 120626 | /* ePragFlg: */ 0, |
| 120627 | /* ColNames: */ 0, 0, |
| 120628 | /* iArg: */ 0 }, |
| 120629 | #endif |
| 120630 | #if defined(SQLITE_INTROSPECTION_PRAGMAS) |
| 120631 | {/* zName: */ "pragma_list", |
| 120632 | /* ePragTyp: */ PragTyp_PRAGMA_LIST, |
| 120633 | /* ePragFlg: */ PragFlg_Result0, |
| @@ -122225,23 +122266,10 @@ | |
| 122225 | } |
| 122226 | break; |
| 122227 | #endif /* !defined(SQLITE_OMIT_TRIGGER) */ |
| 122228 | #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ |
| 122229 | |
| 122230 | #ifndef NDEBUG |
| 122231 | case PragTyp_PARSER_TRACE: { |
| 122232 | if( zRight ){ |
| 122233 | if( sqlite3GetBoolean(zRight, 0) ){ |
| 122234 | sqlite3ParserTrace(stdout, "parser: "); |
| 122235 | }else{ |
| 122236 | sqlite3ParserTrace(0, 0); |
| 122237 | } |
| 122238 | } |
| 122239 | } |
| 122240 | break; |
| 122241 | #endif |
| 122242 | |
| 122243 | /* Reinstall the LIKE and GLOB functions. The variant of LIKE |
| 122244 | ** used will be case sensitive or not depending on the RHS. |
| 122245 | */ |
| 122246 | case PragTyp_CASE_SENSITIVE_LIKE: { |
| 122247 | if( zRight ){ |
| @@ -123358,10 +123386,23 @@ | |
| 123358 | if( zExtra && zExtra[0] ) z = sqlite3MPrintf(db, "%z - %s", z, zExtra); |
| 123359 | *pData->pzErrMsg = z; |
| 123360 | pData->rc = SQLITE_CORRUPT_BKPT; |
| 123361 | } |
| 123362 | } |
| 123363 | |
| 123364 | /* |
| 123365 | ** This is the callback routine for the code that initializes the |
| 123366 | ** database. See sqlite3Init() below for additional information. |
| 123367 | ** This routine is also called from the OP_ParseSchema opcode of the VDBE. |
| @@ -123437,10 +123478,11 @@ | |
| 123437 | Index *pIndex; |
| 123438 | pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zDbSName); |
| 123439 | if( pIndex==0 |
| 123440 | || sqlite3GetInt32(argv[1],&pIndex->tnum)==0 |
| 123441 | || pIndex->tnum<2 |
| 123442 | ){ |
| 123443 | corruptSchema(pData, argv[0], pIndex?"invalid rootpage":"orphan index"); |
| 123444 | } |
| 123445 | } |
| 123446 | return 0; |
| @@ -139887,10 +139929,21 @@ | |
| 139887 | k = 0; |
| 139888 | pScan->iEquiv++; |
| 139889 | } |
| 139890 | return 0; |
| 139891 | } |
| 139892 | |
| 139893 | /* |
| 139894 | ** Initialize a WHERE clause scanner object. Return a pointer to the |
| 139895 | ** first match. Return NULL if there are no matches. |
| 139896 | ** |
| @@ -139920,31 +139973,33 @@ | |
| 139920 | pScan->pOrigWC = pWC; |
| 139921 | pScan->pWC = pWC; |
| 139922 | pScan->pIdxExpr = 0; |
| 139923 | pScan->idxaff = 0; |
| 139924 | pScan->zCollName = 0; |
| 139925 | if( pIdx ){ |
| 139926 | int j = iColumn; |
| 139927 | iColumn = pIdx->aiColumn[j]; |
| 139928 | if( iColumn==XN_EXPR ){ |
| 139929 | pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr; |
| 139930 | pScan->zCollName = pIdx->azColl[j]; |
| 139931 | }else if( iColumn==pIdx->pTable->iPKey ){ |
| 139932 | iColumn = XN_ROWID; |
| 139933 | }else if( iColumn>=0 ){ |
| 139934 | pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity; |
| 139935 | pScan->zCollName = pIdx->azColl[j]; |
| 139936 | } |
| 139937 | }else if( iColumn==XN_EXPR ){ |
| 139938 | return 0; |
| 139939 | } |
| 139940 | pScan->opMask = opMask; |
| 139941 | pScan->k = 0; |
| 139942 | pScan->aiCur[0] = iCur; |
| 139943 | pScan->aiColumn[0] = iColumn; |
| 139944 | pScan->nEquiv = 1; |
| 139945 | pScan->iEquiv = 1; |
| 139946 | return whereScanNext(pScan); |
| 139947 | } |
| 139948 | |
| 139949 | /* |
| 139950 | ** Search for a term in the WHERE clause that is of the form "X <op> <expr>" |
| @@ -152900,11 +152955,18 @@ | |
| 152900 | db->u1.isInterrupted = 0; |
| 152901 | } |
| 152902 | pParse->rc = SQLITE_OK; |
| 152903 | pParse->zTail = zSql; |
| 152904 | assert( pzErrMsg!=0 ); |
| 152905 | /* sqlite3ParserTrace(stdout, "parser: "); */ |
| 152906 | #ifdef sqlite3Parser_ENGINEALWAYSONSTACK |
| 152907 | pEngine = &sEngine; |
| 152908 | sqlite3ParserInit(pEngine, pParse); |
| 152909 | #else |
| 152910 | pEngine = sqlite3ParserAlloc(sqlite3Malloc, pParse); |
| @@ -154223,10 +154285,17 @@ | |
| 154223 | sqlite3GlobalConfig.szSorterRef = (u32)iVal; |
| 154224 | break; |
| 154225 | } |
| 154226 | #endif /* SQLITE_ENABLE_SORTER_REFERENCES */ |
| 154227 | |
| 154228 | default: { |
| 154229 | rc = SQLITE_ERROR; |
| 154230 | break; |
| 154231 | } |
| 154232 | } |
| @@ -161990,10 +162059,11 @@ | |
| 161990 | */ |
| 161991 | pTS->aaOutput[0] = sqlite3_malloc(nDoclist + FTS3_VARINT_MAX + 1); |
| 161992 | pTS->anOutput[0] = nDoclist; |
| 161993 | if( pTS->aaOutput[0] ){ |
| 161994 | memcpy(pTS->aaOutput[0], aDoclist, nDoclist); |
| 161995 | }else{ |
| 161996 | return SQLITE_NOMEM; |
| 161997 | } |
| 161998 | }else{ |
| 161999 | char *aMerge = aDoclist; |
| @@ -165603,19 +165673,19 @@ | |
| 165603 | if( iEq>=0 || iGe>=0 ){ |
| 165604 | const unsigned char *zStr = sqlite3_value_text(apVal[0]); |
| 165605 | assert( (iEq==0 && iGe==-1) || (iEq==-1 && iGe==0) ); |
| 165606 | if( zStr ){ |
| 165607 | pCsr->filter.zTerm = sqlite3_mprintf("%s", zStr); |
| 165608 | pCsr->filter.nTerm = sqlite3_value_bytes(apVal[0]); |
| 165609 | if( pCsr->filter.zTerm==0 ) return SQLITE_NOMEM; |
| 165610 | } |
| 165611 | } |
| 165612 | |
| 165613 | if( iLe>=0 ){ |
| 165614 | pCsr->zStop = sqlite3_mprintf("%s", sqlite3_value_text(apVal[iLe])); |
| 165615 | pCsr->nStop = sqlite3_value_bytes(apVal[iLe]); |
| 165616 | if( pCsr->zStop==0 ) return SQLITE_NOMEM; |
| 165617 | } |
| 165618 | |
| 165619 | if( iLangid>=0 ){ |
| 165620 | iLangVal = sqlite3_value_int(apVal[iLangid]); |
| 165621 | |
| @@ -202679,11 +202749,13 @@ | |
| 202679 | int iAdj; |
| 202680 | int nScore; |
| 202681 | int jj; |
| 202682 | |
| 202683 | rc = pApi->xInst(pFts, ii, &ip, &ic, &io); |
| 202684 | if( ic!=i || rc!=SQLITE_OK ) continue; |
| 202685 | memset(aSeen, 0, nPhrase); |
| 202686 | rc = fts5SnippetScore(pApi, pFts, nDocsize, aSeen, i, |
| 202687 | io, nToken, &nScore, &iAdj |
| 202688 | ); |
| 202689 | if( rc==SQLITE_OK && nScore>nBestScore ){ |
| @@ -209352,11 +209424,11 @@ | |
| 209352 | u8 *a = pIter->pLeaf->p; /* Buffer to read data from */ |
| 209353 | int iOff = pIter->iLeafOffset; /* Offset to read at */ |
| 209354 | int nNew; /* Bytes of new data */ |
| 209355 | |
| 209356 | iOff += fts5GetVarint32(&a[iOff], nNew); |
| 209357 | if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n ){ |
| 209358 | p->rc = FTS5_CORRUPT; |
| 209359 | return; |
| 209360 | } |
| 209361 | pIter->term.n = nKeep; |
| 209362 | fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]); |
| @@ -210026,11 +210098,11 @@ | |
| 210026 | }while( 1 ); |
| 210027 | } |
| 210028 | |
| 210029 | search_success: |
| 210030 | pIter->iLeafOffset = iOff + nNew; |
| 210031 | if( pIter->iLeafOffset>n ){ |
| 210032 | p->rc = FTS5_CORRUPT; |
| 210033 | return; |
| 210034 | } |
| 210035 | pIter->iTermLeafOffset = pIter->iLeafOffset; |
| 210036 | pIter->iTermLeafPgno = pIter->iLeafPgno; |
| @@ -210804,11 +210876,12 @@ | |
| 210804 | Fts5Index *p, |
| 210805 | Fts5SegIter *pSeg, |
| 210806 | Fts5Colset *pColset, |
| 210807 | Fts5Buffer *pBuf |
| 210808 | ){ |
| 210809 | if( 0==fts5BufferGrow(&p->rc, pBuf, pSeg->nPos) ){ |
| 210810 | if( pColset==0 ){ |
| 210811 | fts5ChunkIterate(p, pSeg, (void*)pBuf, fts5PoslistCallback); |
| 210812 | }else{ |
| 210813 | if( p->pConfig->eDetail==FTS5_DETAIL_FULL ){ |
| 210814 | PoslistCallbackCtx sCtx; |
| @@ -211845,11 +211918,11 @@ | |
| 211845 | Fts5Data *pData; |
| 211846 | int iId = pSeg->pSeg->iSegid; |
| 211847 | u8 aHdr[4] = {0x00, 0x00, 0x00, 0x00}; |
| 211848 | |
| 211849 | iLeafRowid = FTS5_SEGMENT_ROWID(iId, pSeg->iTermLeafPgno); |
| 211850 | pData = fts5DataRead(p, iLeafRowid); |
| 211851 | if( pData ){ |
| 211852 | if( iOff>pData->szLeaf ){ |
| 211853 | /* This can occur if the pages that the segments occupy overlap - if |
| 211854 | ** a single page has been assigned to more than one segment. In |
| 211855 | ** this case a prior iteration of this loop may have corrupted the |
| @@ -212700,11 +212773,11 @@ | |
| 212700 | sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos1); |
| 212701 | } |
| 212702 | sqlite3Fts5PoslistNext64(a1, i1.nPoslist, &iOff1, &iPos1); |
| 212703 | if( iPos1<0 ) break; |
| 212704 | }else{ |
| 212705 | assert( iPos2!=iPrev ); |
| 212706 | sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos2); |
| 212707 | sqlite3Fts5PoslistNext64(a2, i2.nPoslist, &iOff2, &iPos2); |
| 212708 | if( iPos2<0 ) break; |
| 212709 | } |
| 212710 | } |
| @@ -215964,11 +216037,13 @@ | |
| 215964 | const char **pz, |
| 215965 | int *pn |
| 215966 | ){ |
| 215967 | int rc = SQLITE_OK; |
| 215968 | Fts5Cursor *pCsr = (Fts5Cursor*)pCtx; |
| 215969 | if( fts5IsContentless((Fts5FullTable*)(pCsr->base.pVtab)) ){ |
| 215970 | *pz = 0; |
| 215971 | *pn = 0; |
| 215972 | }else{ |
| 215973 | rc = fts5SeekCursor(pCsr, 0); |
| 215974 | if( rc==SQLITE_OK ){ |
| @@ -216902,11 +216977,11 @@ | |
| 216902 | int nArg, /* Number of args */ |
| 216903 | sqlite3_value **apUnused /* Function arguments */ |
| 216904 | ){ |
| 216905 | assert( nArg==0 ); |
| 216906 | UNUSED_PARAM2(nArg, apUnused); |
| 216907 | sqlite3_result_text(pCtx, "fts5: 2019-01-26 23:34:50 a3ea1a822d3a110f4f186f2fc8550f435c8c98635d058096b7be9d4df7066b8b", -1, SQLITE_TRANSIENT); |
| 216908 | } |
| 216909 | |
| 216910 | /* |
| 216911 | ** Return true if zName is the extension on one of the shadow tables used |
| 216912 | ** by this module. |
| @@ -221072,10 +221147,11 @@ | |
| 221072 | }else{ |
| 221073 | const char *zTerm; |
| 221074 | int nTerm; |
| 221075 | |
| 221076 | zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm); |
| 221077 | if( pCsr->nLeTerm>=0 ){ |
| 221078 | int nCmp = MIN(nTerm, pCsr->nLeTerm); |
| 221079 | int bCmp = memcmp(pCsr->zLeTerm, zTerm, nCmp); |
| 221080 | if( bCmp<0 || (bCmp==0 && pCsr->nLeTerm<nTerm) ){ |
| 221081 | pCsr->bEof = 1; |
| @@ -221665,12 +221741,12 @@ | |
| 221665 | } |
| 221666 | #endif /* SQLITE_CORE */ |
| 221667 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 221668 | |
| 221669 | /************** End of stmt.c ************************************************/ |
| 221670 | #if __LINE__!=221670 |
| 221671 | #undef SQLITE_SOURCE_ID |
| 221672 | #define SQLITE_SOURCE_ID "2019-01-27 02:45:32 9cf8ebd141aa2eb661d457624c76433bd9e4abfdef04aa52e28bc169172calt2" |
| 221673 | #endif |
| 221674 | /* Return the source-id for this library */ |
| 221675 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 221676 | /************************** End of sqlite3.c ******************************/ |
| 221677 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1162,11 +1162,11 @@ | |
| 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1164 | */ |
| 1165 | #define SQLITE_VERSION "3.27.0" |
| 1166 | #define SQLITE_VERSION_NUMBER 3027000 |
| 1167 | #define SQLITE_SOURCE_ID "2019-02-01 15:06:27 4ca9d5d53d41d08fbce29f9da8cc0948df9c4c3136210af88b499cf889b5ccb8" |
| 1168 | |
| 1169 | /* |
| 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1172 | ** |
| @@ -3019,10 +3019,21 @@ | |
| 3019 | ** from the database as records are returned in sorted order. The default |
| 3020 | ** value for this option is to never use this optimization. Specifying a |
| 3021 | ** negative value for this option restores the default behaviour. |
| 3022 | ** This option is only available if SQLite is compiled with the |
| 3023 | ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option. |
| 3024 | ** |
| 3025 | ** [[SQLITE_CONFIG_MEMDB_MAXSIZE]] |
| 3026 | ** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE |
| 3027 | ** <dd>The SQLITE_CONFIG_MEMDB_MAXSIZE option accepts a single parameter |
| 3028 | ** [sqlite3_int64] parameter which is the default maximum size for an in-memory |
| 3029 | ** database created using [sqlite3_deserialize()]. This default maximum |
| 3030 | ** size can be adjusted up or down for individual databases using the |
| 3031 | ** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this |
| 3032 | ** configuration setting is never used, then the default maximum is determined |
| 3033 | ** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that |
| 3034 | ** compile-time option is not set, then the default maximum is 1073741824. |
| 3035 | ** </dl> |
| 3036 | */ |
| 3037 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 3038 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 3039 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| @@ -3049,10 +3060,11 @@ | |
| 3060 | #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ |
| 3061 | #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */ |
| 3062 | #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */ |
| 3063 | #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */ |
| 3064 | #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */ |
| 3065 | #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */ |
| 3066 | |
| 3067 | /* |
| 3068 | ** CAPI3REF: Database Connection Configuration Options |
| 3069 | ** |
| 3070 | ** These constants are the available integer configuration options that |
| @@ -16433,10 +16445,11 @@ | |
| 16445 | #define SQLITE_SqlTrace HI(0x0001) /* Debug print SQL as it executes */ |
| 16446 | #define SQLITE_VdbeListing HI(0x0002) /* Debug listings of VDBE progs */ |
| 16447 | #define SQLITE_VdbeTrace HI(0x0004) /* True to trace VDBE execution */ |
| 16448 | #define SQLITE_VdbeAddopTrace HI(0x0008) /* Trace sqlite3VdbeAddOp() calls */ |
| 16449 | #define SQLITE_VdbeEQP HI(0x0010) /* Debug EXPLAIN QUERY PLAN */ |
| 16450 | #define SQLITE_ParserTrace HI(0x0020) /* PRAGMA parser_trace=ON */ |
| 16451 | #endif |
| 16452 | |
| 16453 | /* |
| 16454 | ** Allowed values for sqlite3.mDbFlags |
| 16455 | */ |
| @@ -18305,10 +18318,13 @@ | |
| 18318 | ** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE. |
| 18319 | */ |
| 18320 | void (*xVdbeBranch)(void*,unsigned iSrcLine,u8 eThis,u8 eMx); /* Callback */ |
| 18321 | void *pVdbeBranchArg; /* 1st argument */ |
| 18322 | #endif |
| 18323 | #ifdef SQLITE_ENABLE_DESERIALIZE |
| 18324 | sqlite3_int64 mxMemdbSize; /* Default max memdb size */ |
| 18325 | #endif |
| 18326 | #ifndef SQLITE_UNTESTABLE |
| 18327 | int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */ |
| 18328 | #endif |
| 18329 | int bLocaltimeFault; /* True to fail localtime() calls */ |
| 18330 | int bInternalFunctions; /* Internal SQL functions are visible */ |
| @@ -18722,10 +18738,11 @@ | |
| 18738 | SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int); |
| 18739 | SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int); |
| 18740 | SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*); |
| 18741 | SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*); |
| 18742 | SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*); |
| 18743 | SQLITE_PRIVATE int sqlite3IndexHasDuplicateRootPage(Index*); |
| 18744 | SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**); |
| 18745 | SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**); |
| 18746 | SQLITE_PRIVATE int sqlite3InitOne(sqlite3*, int, char**, u32); |
| 18747 | SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int); |
| 18748 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| @@ -19716,10 +19733,17 @@ | |
| 19733 | #ifndef SQLITE_DEFAULT_LOOKASIDE |
| 19734 | # define SQLITE_DEFAULT_LOOKASIDE 1200,100 |
| 19735 | #endif |
| 19736 | |
| 19737 | |
| 19738 | /* The default maximum size of an in-memory database created using |
| 19739 | ** sqlite3_deserialize() |
| 19740 | */ |
| 19741 | #ifndef SQLITE_MEMDB_DEFAULT_MAXSIZE |
| 19742 | # define SQLITE_MEMDB_DEFAULT_MAXSIZE 1073741824 |
| 19743 | #endif |
| 19744 | |
| 19745 | /* |
| 19746 | ** The following singleton contains the global configuration for |
| 19747 | ** the SQLite library. |
| 19748 | */ |
| 19749 | SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = { |
| @@ -19763,17 +19787,20 @@ | |
| 19787 | #endif |
| 19788 | #ifdef SQLITE_VDBE_COVERAGE |
| 19789 | 0, /* xVdbeBranch */ |
| 19790 | 0, /* pVbeBranchArg */ |
| 19791 | #endif |
| 19792 | #ifdef SQLITE_ENABLE_DESERIALIZE |
| 19793 | SQLITE_MEMDB_DEFAULT_MAXSIZE, /* mxMemdbSize */ |
| 19794 | #endif |
| 19795 | #ifndef SQLITE_UNTESTABLE |
| 19796 | 0, /* xTestCallback */ |
| 19797 | #endif |
| 19798 | 0, /* bLocaltimeFault */ |
| 19799 | 0, /* bInternalFunctions */ |
| 19800 | 0x7ffffffe, /* iOnceResetThreshold */ |
| 19801 | SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */ |
| 19802 | }; |
| 19803 | |
| 19804 | /* |
| 19805 | ** Hash table for global functions - functions common to all |
| 19806 | ** database connections. After initialization, this table is |
| @@ -46578,15 +46605,10 @@ | |
| 46605 | int nMmap; /* Number of memory mapped pages */ |
| 46606 | unsigned mFlags; /* Flags */ |
| 46607 | int eLock; /* Most recent lock against this file */ |
| 46608 | }; |
| 46609 | |
| 46610 | /* |
| 46611 | ** Methods for MemFile |
| 46612 | */ |
| 46613 | static int memdbClose(sqlite3_file*); |
| 46614 | static int memdbRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); |
| @@ -46847,11 +46869,10 @@ | |
| 46869 | int iAmt, |
| 46870 | void **pp |
| 46871 | ){ |
| 46872 | MemFile *p = (MemFile *)pFile; |
| 46873 | if( iOfst+iAmt>p->sz ){ |
| 46874 | *pp = 0; |
| 46875 | }else{ |
| 46876 | p->nMmap++; |
| 46877 | *pp = (void*)(p->aData + iOfst); |
| 46878 | } |
| @@ -46882,11 +46903,11 @@ | |
| 46903 | memset(p, 0, sizeof(*p)); |
| 46904 | p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE; |
| 46905 | assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */ |
| 46906 | *pOutFlags = flags | SQLITE_OPEN_MEMORY; |
| 46907 | p->base.pMethods = &memdb_io_methods; |
| 46908 | p->szMax = sqlite3GlobalConfig.mxMemdbSize; |
| 46909 | return SQLITE_OK; |
| 46910 | } |
| 46911 | |
| 46912 | #if 0 /* Only used to delete rollback journals, master journals, and WAL |
| 46913 | ** files, none of which exist in memdb. So this routine is never used */ |
| @@ -47134,12 +47155,12 @@ | |
| 47155 | }else{ |
| 47156 | p->aData = pData; |
| 47157 | p->sz = szDb; |
| 47158 | p->szAlloc = szBuf; |
| 47159 | p->szMax = szBuf; |
| 47160 | if( p->szMax<sqlite3GlobalConfig.mxMemdbSize ){ |
| 47161 | p->szMax = sqlite3GlobalConfig.mxMemdbSize; |
| 47162 | } |
| 47163 | p->mFlags = mFlags; |
| 47164 | rc = SQLITE_OK; |
| 47165 | } |
| 47166 | |
| @@ -62473,13 +62494,20 @@ | |
| 62494 | ** |
| 62495 | ** Fields in this structure are accessed under the BtShared.mutex |
| 62496 | ** found at self->pBt->mutex. |
| 62497 | ** |
| 62498 | ** skipNext meaning: |
| 62499 | ** The meaning of skipNext depends on the value of eState: |
| 62500 | ** |
| 62501 | ** eState Meaning of skipNext |
| 62502 | ** VALID skipNext is meaningless and is ignored |
| 62503 | ** INVALID skipNext is meaningless and is ignored |
| 62504 | ** SKIPNEXT sqlite3BtreeNext() is a no-op if skipNext>0 and |
| 62505 | ** sqlite3BtreePrevious() is no-op if skipNext<0. |
| 62506 | ** REQUIRESEEK restoreCursorPosition() restores the cursor to |
| 62507 | ** eState=SKIPNEXT if skipNext!=0 |
| 62508 | ** FAULT skipNext holds the cursor fault error code. |
| 62509 | */ |
| 62510 | struct BtCursor { |
| 62511 | u8 eState; /* One of the CURSOR_XXX constants (see below) */ |
| 62512 | u8 curFlags; /* zero or more BTCF_* flags defined below */ |
| 62513 | u8 curPagerFlags; /* Flags to send to sqlite3PagerGet() */ |
| @@ -63824,11 +63852,11 @@ | |
| 63852 | rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext); |
| 63853 | if( rc==SQLITE_OK ){ |
| 63854 | sqlite3_free(pCur->pKey); |
| 63855 | pCur->pKey = 0; |
| 63856 | assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID ); |
| 63857 | if( skipNext ) pCur->skipNext = skipNext; |
| 63858 | if( pCur->skipNext && pCur->eState==CURSOR_VALID ){ |
| 63859 | pCur->eState = CURSOR_SKIPNEXT; |
| 63860 | } |
| 63861 | } |
| 63862 | return rc; |
| @@ -63894,11 +63922,10 @@ | |
| 63922 | return rc; |
| 63923 | } |
| 63924 | if( pCur->eState!=CURSOR_VALID ){ |
| 63925 | *pDifferentRow = 1; |
| 63926 | }else{ |
| 63927 | *pDifferentRow = 0; |
| 63928 | } |
| 63929 | return SQLITE_OK; |
| 63930 | } |
| 63931 | |
| @@ -68313,11 +68340,11 @@ | |
| 68340 | } |
| 68341 | /* If the requested key is one more than the previous key, then |
| 68342 | ** try to get there using sqlite3BtreeNext() rather than a full |
| 68343 | ** binary search. This is an optimization only. The correct answer |
| 68344 | ** is still obtained without this case, only a little more slowely */ |
| 68345 | if( pCur->info.nKey+1==intKey ){ |
| 68346 | *pRes = 0; |
| 68347 | rc = sqlite3BtreeNext(pCur, 0); |
| 68348 | if( rc==SQLITE_OK ){ |
| 68349 | getCellInfo(pCur); |
| 68350 | if( pCur->info.nKey==intKey ){ |
| @@ -68587,28 +68614,22 @@ | |
| 68614 | int rc; |
| 68615 | int idx; |
| 68616 | MemPage *pPage; |
| 68617 | |
| 68618 | assert( cursorOwnsBtShared(pCur) ); |
| 68619 | if( pCur->eState!=CURSOR_VALID ){ |
| 68620 | assert( (pCur->curFlags & BTCF_ValidOvfl)==0 ); |
| 68621 | rc = restoreCursorPosition(pCur); |
| 68622 | if( rc!=SQLITE_OK ){ |
| 68623 | return rc; |
| 68624 | } |
| 68625 | if( CURSOR_INVALID==pCur->eState ){ |
| 68626 | return SQLITE_DONE; |
| 68627 | } |
| 68628 | if( pCur->eState==CURSOR_SKIPNEXT ){ |
| 68629 | pCur->eState = CURSOR_VALID; |
| 68630 | if( pCur->skipNext>0 ) return SQLITE_OK; |
| 68631 | } |
| 68632 | } |
| 68633 | |
| 68634 | pPage = pCur->pPage; |
| 68635 | idx = ++pCur->ix; |
| @@ -68659,11 +68680,10 @@ | |
| 68680 | SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int flags){ |
| 68681 | MemPage *pPage; |
| 68682 | UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */ |
| 68683 | assert( cursorOwnsBtShared(pCur) ); |
| 68684 | assert( flags==0 || flags==1 ); |
| 68685 | pCur->info.nSize = 0; |
| 68686 | pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl); |
| 68687 | if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur); |
| 68688 | pPage = pCur->pPage; |
| 68689 | if( (++pCur->ix)>=pPage->nCell ){ |
| @@ -68700,11 +68720,10 @@ | |
| 68720 | static SQLITE_NOINLINE int btreePrevious(BtCursor *pCur){ |
| 68721 | int rc; |
| 68722 | MemPage *pPage; |
| 68723 | |
| 68724 | assert( cursorOwnsBtShared(pCur) ); |
| 68725 | assert( (pCur->curFlags & (BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey))==0 ); |
| 68726 | assert( pCur->info.nSize==0 ); |
| 68727 | if( pCur->eState!=CURSOR_VALID ){ |
| 68728 | rc = restoreCursorPosition(pCur); |
| 68729 | if( rc!=SQLITE_OK ){ |
| @@ -68711,18 +68730,13 @@ | |
| 68730 | return rc; |
| 68731 | } |
| 68732 | if( CURSOR_INVALID==pCur->eState ){ |
| 68733 | return SQLITE_DONE; |
| 68734 | } |
| 68735 | if( CURSOR_SKIPNEXT==pCur->eState ){ |
| 68736 | pCur->eState = CURSOR_VALID; |
| 68737 | if( pCur->skipNext<0 ) return SQLITE_OK; |
| 68738 | } |
| 68739 | } |
| 68740 | |
| 68741 | pPage = pCur->pPage; |
| 68742 | assert( pPage->isInit ); |
| @@ -68753,11 +68767,10 @@ | |
| 68767 | return rc; |
| 68768 | } |
| 68769 | SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int flags){ |
| 68770 | assert( cursorOwnsBtShared(pCur) ); |
| 68771 | assert( flags==0 || flags==1 ); |
| 68772 | UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */ |
| 68773 | pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey); |
| 68774 | pCur->info.nSize = 0; |
| 68775 | if( pCur->eState!=CURSOR_VALID |
| 68776 | || pCur->ix==0 |
| @@ -69722,27 +69735,38 @@ | |
| 69735 | ** / | \ |
| 69736 | ** --------- --------- --------- |
| 69737 | ** |Child-1| |Child-2| |Child-3| |
| 69738 | ** --------- --------- --------- |
| 69739 | ** |
| 69740 | ** The order of cells is in the array is for an index btree is: |
| 69741 | ** |
| 69742 | ** 1. All cells from Child-1 in order |
| 69743 | ** 2. The first divider cell from Parent |
| 69744 | ** 3. All cells from Child-2 in order |
| 69745 | ** 4. The second divider cell from Parent |
| 69746 | ** 5. All cells from Child-3 in order |
| 69747 | ** |
| 69748 | ** For a table-btree (with rowids) the items 2 and 4 are empty because |
| 69749 | ** content exists only in leaves and there are no divider cells. |
| 69750 | ** |
| 69751 | ** For an index btree, the apEnd[] array holds pointer to the end of page |
| 69752 | ** for Child-1, the Parent, Child-2, the Parent (again), and Child-3, |
| 69753 | ** respectively. The ixNx[] array holds the number of cells contained in |
| 69754 | ** each of these 5 stages, and all stages to the left. Hence: |
| 69755 | ** |
| 69756 | ** ixNx[0] = Number of cells in Child-1. |
| 69757 | ** ixNx[1] = Number of cells in Child-1 plus 1 for first divider. |
| 69758 | ** ixNx[2] = Number of cells in Child-1 and Child-2 + 1 for 1st divider. |
| 69759 | ** ixNx[3] = Number of cells in Child-1 and Child-2 + both divider cells |
| 69760 | ** ixNx[4] = Total number of cells. |
| 69761 | ** |
| 69762 | ** For a table-btree, the concept is similar, except only apEnd[0]..apEnd[2] |
| 69763 | ** are used and they point to the leaf pages only, and the ixNx value are: |
| 69764 | ** |
| 69765 | ** ixNx[0] = Number of cells in Child-1. |
| 69766 | ** ixNx[1] = Number of cells in Child-1 and Child-2 + 1 for 1st divider. |
| 69767 | ** ixNx[2] = Number of cells in Child-1 and Child-2 + both divider cells |
| 69768 | */ |
| 69769 | typedef struct CellArray CellArray; |
| 69770 | struct CellArray { |
| 69771 | int nCell; /* Number of cells in apCell[] */ |
| 69772 | MemPage *pRef; /* Reference page */ |
| @@ -69808,20 +69832,21 @@ | |
| 69832 | const int hdr = pPg->hdrOffset; /* Offset of header on pPg */ |
| 69833 | u8 * const aData = pPg->aData; /* Pointer to data for pPg */ |
| 69834 | const int usableSize = pPg->pBt->usableSize; |
| 69835 | u8 * const pEnd = &aData[usableSize]; |
| 69836 | int i = iFirst; /* Which cell to copy from pCArray*/ |
| 69837 | u32 j; /* Start of cell content area */ |
| 69838 | int iEnd = i+nCell; /* Loop terminator */ |
| 69839 | u8 *pCellptr = pPg->aCellIdx; |
| 69840 | u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager); |
| 69841 | u8 *pData; |
| 69842 | int k; /* Current slot in pCArray->apEnd[] */ |
| 69843 | u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */ |
| 69844 | |
| 69845 | assert( i<iEnd ); |
| 69846 | j = get2byte(&aData[hdr+5]); |
| 69847 | if( NEVER(j>(u32)usableSize) ){ j = 0; } |
| 69848 | memcpy(&pTmp[j], &aData[j], usableSize - j); |
| 69849 | |
| 69850 | for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){} |
| 69851 | pSrcEnd = pCArray->apEnd[k]; |
| 69852 | |
| @@ -69997,11 +70022,11 @@ | |
| 70022 | } |
| 70023 | return nRet; |
| 70024 | } |
| 70025 | |
| 70026 | /* |
| 70027 | ** pCArray contains pointers to and sizes of all cells in the page being |
| 70028 | ** balanced. The current page, pPg, has pPg->nCell cells starting with |
| 70029 | ** pCArray->apCell[iOld]. After balancing, this page should hold nNew cells |
| 70030 | ** starting at apCell[iNew]. |
| 70031 | ** |
| 70032 | ** This routine makes the necessary adjustments to pPg so that it contains |
| @@ -70031,26 +70056,31 @@ | |
| 70056 | u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager); |
| 70057 | memcpy(pTmp, aData, pPg->pBt->usableSize); |
| 70058 | #endif |
| 70059 | |
| 70060 | /* Remove cells from the start and end of the page */ |
| 70061 | assert( nCell>=0 ); |
| 70062 | if( iOld<iNew ){ |
| 70063 | int nShift = pageFreeArray(pPg, iOld, iNew-iOld, pCArray); |
| 70064 | if( nShift>nCell ) return SQLITE_CORRUPT_BKPT; |
| 70065 | memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2); |
| 70066 | nCell -= nShift; |
| 70067 | } |
| 70068 | if( iNewEnd < iOldEnd ){ |
| 70069 | int nTail = pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray); |
| 70070 | assert( nCell>=nTail ); |
| 70071 | nCell -= nTail; |
| 70072 | } |
| 70073 | |
| 70074 | pData = &aData[get2byteNotZero(&aData[hdr+5])]; |
| 70075 | if( pData<pBegin ) goto editpage_fail; |
| 70076 | |
| 70077 | /* Add cells to the start of the page */ |
| 70078 | if( iNew<iOld ){ |
| 70079 | int nAdd = MIN(nNew,iOld-iNew); |
| 70080 | assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB ); |
| 70081 | assert( nAdd>=0 ); |
| 70082 | pCellptr = pPg->aCellIdx; |
| 70083 | memmove(&pCellptr[nAdd*2], pCellptr, nCell*2); |
| 70084 | if( pageInsertArray( |
| 70085 | pPg, pBegin, &pData, pCellptr, |
| 70086 | iNew, nAdd, pCArray |
| @@ -70061,10 +70091,11 @@ | |
| 70091 | /* Add any overflow cells */ |
| 70092 | for(i=0; i<pPg->nOverflow; i++){ |
| 70093 | int iCell = (iOld + pPg->aiOvfl[i]) - iNew; |
| 70094 | if( iCell>=0 && iCell<nNew ){ |
| 70095 | pCellptr = &pPg->aCellIdx[iCell * 2]; |
| 70096 | assert( nCell>=iCell ); |
| 70097 | memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2); |
| 70098 | nCell++; |
| 70099 | if( pageInsertArray( |
| 70100 | pPg, pBegin, &pData, pCellptr, |
| 70101 | iCell+iNew, 1, pCArray |
| @@ -70071,10 +70102,11 @@ | |
| 70102 | ) ) goto editpage_fail; |
| 70103 | } |
| 70104 | } |
| 70105 | |
| 70106 | /* Append cells to the end of the page */ |
| 70107 | assert( nCell>=0 ); |
| 70108 | pCellptr = &pPg->aCellIdx[nCell*2]; |
| 70109 | if( pageInsertArray( |
| 70110 | pPg, pBegin, &pData, pCellptr, |
| 70111 | iNew+nCell, nNew-nCell, pCArray |
| 70112 | ) ) goto editpage_fail; |
| @@ -70644,16 +70676,19 @@ | |
| 70676 | ** the right of the i-th sibling page. |
| 70677 | ** usableSpace: Number of bytes of space available on each sibling. |
| 70678 | ** |
| 70679 | */ |
| 70680 | usableSpace = pBt->usableSize - 12 + leafCorrection; |
| 70681 | for(i=k=0; i<nOld; i++, k++){ |
| 70682 | MemPage *p = apOld[i]; |
| 70683 | b.apEnd[k] = p->aDataEnd; |
| 70684 | b.ixNx[k] = cntOld[i]; |
| 70685 | if( !leafData ){ |
| 70686 | k++; |
| 70687 | b.apEnd[k] = pParent->aDataEnd; |
| 70688 | b.ixNx[k] = cntOld[i]+1; |
| 70689 | } |
| 70690 | szNew[i] = usableSpace - p->nFree; |
| 70691 | for(j=0; j<p->nOverflow; j++){ |
| 70692 | szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]); |
| 70693 | } |
| 70694 | cntNew[i] = cntOld[i]; |
| @@ -71749,11 +71784,10 @@ | |
| 71784 | ** from the internal node. The 'previous' entry is used for this instead |
| 71785 | ** of the 'next' entry, as the previous entry is always a part of the |
| 71786 | ** sub-tree headed by the child page of the cell being deleted. This makes |
| 71787 | ** balancing the tree following the delete operation easier. */ |
| 71788 | if( !pPage->leaf ){ |
| 71789 | rc = sqlite3BtreePrevious(pCur, 0); |
| 71790 | assert( rc!=SQLITE_DONE ); |
| 71791 | if( rc ) return rc; |
| 71792 | } |
| 71793 | |
| @@ -97882,10 +97916,11 @@ | |
| 97916 | static void gatherSelectWindows(Select *p){ |
| 97917 | Walker w; |
| 97918 | w.xExprCallback = gatherSelectWindowsCallback; |
| 97919 | w.xSelectCallback = gatherSelectWindowsSelectCallback; |
| 97920 | w.xSelectCallback2 = 0; |
| 97921 | w.pParse = 0; |
| 97922 | w.u.pSelect = p; |
| 97923 | sqlite3WalkSelect(&w, p); |
| 97924 | } |
| 97925 | #endif |
| 97926 | |
| @@ -109965,21 +110000,26 @@ | |
| 110000 | assert( pParse->nErr==0 ); |
| 110001 | if( db->init.busy ){ |
| 110002 | Index *p; |
| 110003 | assert( !IN_SPECIAL_PARSE ); |
| 110004 | assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) ); |
| 110005 | if( pTblName!=0 ){ |
| 110006 | pIndex->tnum = db->init.newTnum; |
| 110007 | if( sqlite3IndexHasDuplicateRootPage(pIndex) ){ |
| 110008 | sqlite3ErrorMsg(pParse, "invalid rootpage"); |
| 110009 | pParse->rc = SQLITE_CORRUPT_BKPT; |
| 110010 | goto exit_create_index; |
| 110011 | } |
| 110012 | } |
| 110013 | p = sqlite3HashInsert(&pIndex->pSchema->idxHash, |
| 110014 | pIndex->zName, pIndex); |
| 110015 | if( p ){ |
| 110016 | assert( p==pIndex ); /* Malloc must have failed */ |
| 110017 | sqlite3OomFault(db); |
| 110018 | goto exit_create_index; |
| 110019 | } |
| 110020 | db->mDbFlags |= DBFLAG_SchemaChange; |
| 110021 | } |
| 110022 | |
| 110023 | /* If this is the initial CREATE INDEX statement (or CREATE TABLE if the |
| 110024 | ** index is an implied index for a UNIQUE or PRIMARY KEY constraint) then |
| 110025 | ** emit code to allocate the index rootpage on disk and make an entry for |
| @@ -120194,12 +120234,11 @@ | |
| 120234 | #define PragTyp_WAL_CHECKPOINT 39 |
| 120235 | #define PragTyp_ACTIVATE_EXTENSIONS 40 |
| 120236 | #define PragTyp_HEXKEY 41 |
| 120237 | #define PragTyp_KEY 42 |
| 120238 | #define PragTyp_LOCK_STATUS 43 |
| 120239 | #define PragTyp_STATS 44 |
| 120240 | |
| 120241 | /* Property flags associated with various pragma. */ |
| 120242 | #define PragFlg_NeedSchema 0x01 /* Force schema load before running */ |
| 120243 | #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */ |
| 120244 | #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */ |
| @@ -120618,16 +120657,18 @@ | |
| 120657 | /* ePragTyp: */ PragTyp_PAGE_SIZE, |
| 120658 | /* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1, |
| 120659 | /* ColNames: */ 0, 0, |
| 120660 | /* iArg: */ 0 }, |
| 120661 | #endif |
| 120662 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 120663 | #if defined(SQLITE_DEBUG) |
| 120664 | {/* zName: */ "parser_trace", |
| 120665 | /* ePragTyp: */ PragTyp_FLAG, |
| 120666 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| 120667 | /* ColNames: */ 0, 0, |
| 120668 | /* iArg: */ SQLITE_ParserTrace }, |
| 120669 | #endif |
| 120670 | #endif |
| 120671 | #if defined(SQLITE_INTROSPECTION_PRAGMAS) |
| 120672 | {/* zName: */ "pragma_list", |
| 120673 | /* ePragTyp: */ PragTyp_PRAGMA_LIST, |
| 120674 | /* ePragFlg: */ PragFlg_Result0, |
| @@ -122225,23 +122266,10 @@ | |
| 122266 | } |
| 122267 | break; |
| 122268 | #endif /* !defined(SQLITE_OMIT_TRIGGER) */ |
| 122269 | #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */ |
| 122270 | |
| 122271 | /* Reinstall the LIKE and GLOB functions. The variant of LIKE |
| 122272 | ** used will be case sensitive or not depending on the RHS. |
| 122273 | */ |
| 122274 | case PragTyp_CASE_SENSITIVE_LIKE: { |
| 122275 | if( zRight ){ |
| @@ -123358,10 +123386,23 @@ | |
| 123386 | if( zExtra && zExtra[0] ) z = sqlite3MPrintf(db, "%z - %s", z, zExtra); |
| 123387 | *pData->pzErrMsg = z; |
| 123388 | pData->rc = SQLITE_CORRUPT_BKPT; |
| 123389 | } |
| 123390 | } |
| 123391 | |
| 123392 | /* |
| 123393 | ** Check to see if any sibling index (another index on the same table) |
| 123394 | ** of pIndex has the same root page number, and if it does, return true. |
| 123395 | ** This would indicate a corrupt schema. |
| 123396 | */ |
| 123397 | SQLITE_PRIVATE int sqlite3IndexHasDuplicateRootPage(Index *pIndex){ |
| 123398 | Index *p; |
| 123399 | for(p=pIndex->pTable->pIndex; p; p=p->pNext){ |
| 123400 | if( p->tnum==pIndex->tnum && p!=pIndex ) return 1; |
| 123401 | } |
| 123402 | return 0; |
| 123403 | } |
| 123404 | |
| 123405 | /* |
| 123406 | ** This is the callback routine for the code that initializes the |
| 123407 | ** database. See sqlite3Init() below for additional information. |
| 123408 | ** This routine is also called from the OP_ParseSchema opcode of the VDBE. |
| @@ -123437,10 +123478,11 @@ | |
| 123478 | Index *pIndex; |
| 123479 | pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zDbSName); |
| 123480 | if( pIndex==0 |
| 123481 | || sqlite3GetInt32(argv[1],&pIndex->tnum)==0 |
| 123482 | || pIndex->tnum<2 |
| 123483 | || sqlite3IndexHasDuplicateRootPage(pIndex) |
| 123484 | ){ |
| 123485 | corruptSchema(pData, argv[0], pIndex?"invalid rootpage":"orphan index"); |
| 123486 | } |
| 123487 | } |
| 123488 | return 0; |
| @@ -139887,10 +139929,21 @@ | |
| 139929 | k = 0; |
| 139930 | pScan->iEquiv++; |
| 139931 | } |
| 139932 | return 0; |
| 139933 | } |
| 139934 | |
| 139935 | /* |
| 139936 | ** This is whereScanInit() for the case of an index on an expression. |
| 139937 | ** It is factored out into a separate tail-recursion subroutine so that |
| 139938 | ** the normal whereScanInit() routine, which is a high-runner, does not |
| 139939 | ** need to push registers onto the stack as part of its prologue. |
| 139940 | */ |
| 139941 | static SQLITE_NOINLINE WhereTerm *whereScanInitIndexExpr(WhereScan *pScan){ |
| 139942 | pScan->idxaff = sqlite3ExprAffinity(pScan->pIdxExpr); |
| 139943 | return whereScanNext(pScan); |
| 139944 | } |
| 139945 | |
| 139946 | /* |
| 139947 | ** Initialize a WHERE clause scanner object. Return a pointer to the |
| 139948 | ** first match. Return NULL if there are no matches. |
| 139949 | ** |
| @@ -139920,31 +139973,33 @@ | |
| 139973 | pScan->pOrigWC = pWC; |
| 139974 | pScan->pWC = pWC; |
| 139975 | pScan->pIdxExpr = 0; |
| 139976 | pScan->idxaff = 0; |
| 139977 | pScan->zCollName = 0; |
| 139978 | pScan->opMask = opMask; |
| 139979 | pScan->k = 0; |
| 139980 | pScan->aiCur[0] = iCur; |
| 139981 | pScan->nEquiv = 1; |
| 139982 | pScan->iEquiv = 1; |
| 139983 | if( pIdx ){ |
| 139984 | int j = iColumn; |
| 139985 | iColumn = pIdx->aiColumn[j]; |
| 139986 | if( iColumn==XN_EXPR ){ |
| 139987 | pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr; |
| 139988 | pScan->zCollName = pIdx->azColl[j]; |
| 139989 | pScan->aiColumn[0] = XN_EXPR; |
| 139990 | return whereScanInitIndexExpr(pScan); |
| 139991 | }else if( iColumn==pIdx->pTable->iPKey ){ |
| 139992 | iColumn = XN_ROWID; |
| 139993 | }else if( iColumn>=0 ){ |
| 139994 | pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity; |
| 139995 | pScan->zCollName = pIdx->azColl[j]; |
| 139996 | } |
| 139997 | }else if( iColumn==XN_EXPR ){ |
| 139998 | return 0; |
| 139999 | } |
| 140000 | pScan->aiColumn[0] = iColumn; |
| 140001 | return whereScanNext(pScan); |
| 140002 | } |
| 140003 | |
| 140004 | /* |
| 140005 | ** Search for a term in the WHERE clause that is of the form "X <op> <expr>" |
| @@ -152900,11 +152955,18 @@ | |
| 152955 | db->u1.isInterrupted = 0; |
| 152956 | } |
| 152957 | pParse->rc = SQLITE_OK; |
| 152958 | pParse->zTail = zSql; |
| 152959 | assert( pzErrMsg!=0 ); |
| 152960 | #ifdef SQLITE_DEBUG |
| 152961 | if( db->flags & SQLITE_ParserTrace ){ |
| 152962 | printf("parser: [[[%s]]]\n", zSql); |
| 152963 | sqlite3ParserTrace(stdout, "parser: "); |
| 152964 | }else{ |
| 152965 | sqlite3ParserTrace(0, 0); |
| 152966 | } |
| 152967 | #endif |
| 152968 | #ifdef sqlite3Parser_ENGINEALWAYSONSTACK |
| 152969 | pEngine = &sEngine; |
| 152970 | sqlite3ParserInit(pEngine, pParse); |
| 152971 | #else |
| 152972 | pEngine = sqlite3ParserAlloc(sqlite3Malloc, pParse); |
| @@ -154223,10 +154285,17 @@ | |
| 154285 | sqlite3GlobalConfig.szSorterRef = (u32)iVal; |
| 154286 | break; |
| 154287 | } |
| 154288 | #endif /* SQLITE_ENABLE_SORTER_REFERENCES */ |
| 154289 | |
| 154290 | #ifdef SQLITE_ENABLE_DESERIALIZE |
| 154291 | case SQLITE_CONFIG_MEMDB_MAXSIZE: { |
| 154292 | sqlite3GlobalConfig.mxMemdbSize = va_arg(ap, sqlite3_int64); |
| 154293 | break; |
| 154294 | } |
| 154295 | #endif /* SQLITE_ENABLE_DESERIALIZE */ |
| 154296 | |
| 154297 | default: { |
| 154298 | rc = SQLITE_ERROR; |
| 154299 | break; |
| 154300 | } |
| 154301 | } |
| @@ -161990,10 +162059,11 @@ | |
| 162059 | */ |
| 162060 | pTS->aaOutput[0] = sqlite3_malloc(nDoclist + FTS3_VARINT_MAX + 1); |
| 162061 | pTS->anOutput[0] = nDoclist; |
| 162062 | if( pTS->aaOutput[0] ){ |
| 162063 | memcpy(pTS->aaOutput[0], aDoclist, nDoclist); |
| 162064 | memset(&pTS->aaOutput[0][nDoclist], 0, FTS3_VARINT_MAX); |
| 162065 | }else{ |
| 162066 | return SQLITE_NOMEM; |
| 162067 | } |
| 162068 | }else{ |
| 162069 | char *aMerge = aDoclist; |
| @@ -165603,19 +165673,19 @@ | |
| 165673 | if( iEq>=0 || iGe>=0 ){ |
| 165674 | const unsigned char *zStr = sqlite3_value_text(apVal[0]); |
| 165675 | assert( (iEq==0 && iGe==-1) || (iEq==-1 && iGe==0) ); |
| 165676 | if( zStr ){ |
| 165677 | pCsr->filter.zTerm = sqlite3_mprintf("%s", zStr); |
| 165678 | if( pCsr->filter.zTerm==0 ) return SQLITE_NOMEM; |
| 165679 | pCsr->filter.nTerm = (int)strlen(pCsr->filter.zTerm); |
| 165680 | } |
| 165681 | } |
| 165682 | |
| 165683 | if( iLe>=0 ){ |
| 165684 | pCsr->zStop = sqlite3_mprintf("%s", sqlite3_value_text(apVal[iLe])); |
| 165685 | if( pCsr->zStop==0 ) return SQLITE_NOMEM; |
| 165686 | pCsr->nStop = (int)strlen(pCsr->zStop); |
| 165687 | } |
| 165688 | |
| 165689 | if( iLangid>=0 ){ |
| 165690 | iLangVal = sqlite3_value_int(apVal[iLangid]); |
| 165691 | |
| @@ -202679,11 +202749,13 @@ | |
| 202749 | int iAdj; |
| 202750 | int nScore; |
| 202751 | int jj; |
| 202752 | |
| 202753 | rc = pApi->xInst(pFts, ii, &ip, &ic, &io); |
| 202754 | if( ic!=i ) continue; |
| 202755 | if( io>nDocsize ) rc = FTS5_CORRUPT; |
| 202756 | if( rc!=SQLITE_OK ) continue; |
| 202757 | memset(aSeen, 0, nPhrase); |
| 202758 | rc = fts5SnippetScore(pApi, pFts, nDocsize, aSeen, i, |
| 202759 | io, nToken, &nScore, &iAdj |
| 202760 | ); |
| 202761 | if( rc==SQLITE_OK && nScore>nBestScore ){ |
| @@ -209352,11 +209424,11 @@ | |
| 209424 | u8 *a = pIter->pLeaf->p; /* Buffer to read data from */ |
| 209425 | int iOff = pIter->iLeafOffset; /* Offset to read at */ |
| 209426 | int nNew; /* Bytes of new data */ |
| 209427 | |
| 209428 | iOff += fts5GetVarint32(&a[iOff], nNew); |
| 209429 | if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){ |
| 209430 | p->rc = FTS5_CORRUPT; |
| 209431 | return; |
| 209432 | } |
| 209433 | pIter->term.n = nKeep; |
| 209434 | fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]); |
| @@ -210026,11 +210098,11 @@ | |
| 210098 | }while( 1 ); |
| 210099 | } |
| 210100 | |
| 210101 | search_success: |
| 210102 | pIter->iLeafOffset = iOff + nNew; |
| 210103 | if( pIter->iLeafOffset>n || nNew<1 ){ |
| 210104 | p->rc = FTS5_CORRUPT; |
| 210105 | return; |
| 210106 | } |
| 210107 | pIter->iTermLeafOffset = pIter->iLeafOffset; |
| 210108 | pIter->iTermLeafPgno = pIter->iLeafPgno; |
| @@ -210804,11 +210876,12 @@ | |
| 210876 | Fts5Index *p, |
| 210877 | Fts5SegIter *pSeg, |
| 210878 | Fts5Colset *pColset, |
| 210879 | Fts5Buffer *pBuf |
| 210880 | ){ |
| 210881 | if( 0==fts5BufferGrow(&p->rc, pBuf, pSeg->nPos+FTS5_DATA_ZERO_PADDING) ){ |
| 210882 | memset(&pBuf->p[pBuf->n+pSeg->nPos], 0, FTS5_DATA_ZERO_PADDING); |
| 210883 | if( pColset==0 ){ |
| 210884 | fts5ChunkIterate(p, pSeg, (void*)pBuf, fts5PoslistCallback); |
| 210885 | }else{ |
| 210886 | if( p->pConfig->eDetail==FTS5_DETAIL_FULL ){ |
| 210887 | PoslistCallbackCtx sCtx; |
| @@ -211845,11 +211918,11 @@ | |
| 211918 | Fts5Data *pData; |
| 211919 | int iId = pSeg->pSeg->iSegid; |
| 211920 | u8 aHdr[4] = {0x00, 0x00, 0x00, 0x00}; |
| 211921 | |
| 211922 | iLeafRowid = FTS5_SEGMENT_ROWID(iId, pSeg->iTermLeafPgno); |
| 211923 | pData = fts5LeafRead(p, iLeafRowid); |
| 211924 | if( pData ){ |
| 211925 | if( iOff>pData->szLeaf ){ |
| 211926 | /* This can occur if the pages that the segments occupy overlap - if |
| 211927 | ** a single page has been assigned to more than one segment. In |
| 211928 | ** this case a prior iteration of this loop may have corrupted the |
| @@ -212700,11 +212773,11 @@ | |
| 212773 | sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos1); |
| 212774 | } |
| 212775 | sqlite3Fts5PoslistNext64(a1, i1.nPoslist, &iOff1, &iPos1); |
| 212776 | if( iPos1<0 ) break; |
| 212777 | }else{ |
| 212778 | assert_nc( iPos2!=iPrev ); |
| 212779 | sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos2); |
| 212780 | sqlite3Fts5PoslistNext64(a2, i2.nPoslist, &iOff2, &iPos2); |
| 212781 | if( iPos2<0 ) break; |
| 212782 | } |
| 212783 | } |
| @@ -215964,11 +216037,13 @@ | |
| 216037 | const char **pz, |
| 216038 | int *pn |
| 216039 | ){ |
| 216040 | int rc = SQLITE_OK; |
| 216041 | Fts5Cursor *pCsr = (Fts5Cursor*)pCtx; |
| 216042 | if( fts5IsContentless((Fts5FullTable*)(pCsr->base.pVtab)) |
| 216043 | || pCsr->ePlan==FTS5_PLAN_SPECIAL |
| 216044 | ){ |
| 216045 | *pz = 0; |
| 216046 | *pn = 0; |
| 216047 | }else{ |
| 216048 | rc = fts5SeekCursor(pCsr, 0); |
| 216049 | if( rc==SQLITE_OK ){ |
| @@ -216902,11 +216977,11 @@ | |
| 216977 | int nArg, /* Number of args */ |
| 216978 | sqlite3_value **apUnused /* Function arguments */ |
| 216979 | ){ |
| 216980 | assert( nArg==0 ); |
| 216981 | UNUSED_PARAM2(nArg, apUnused); |
| 216982 | sqlite3_result_text(pCtx, "fts5: 2019-02-01 15:06:27 4ca9d5d53d41d08fbce29f9da8cc0948df9c4c3136210af88b499cf889b5ccb8", -1, SQLITE_TRANSIENT); |
| 216983 | } |
| 216984 | |
| 216985 | /* |
| 216986 | ** Return true if zName is the extension on one of the shadow tables used |
| 216987 | ** by this module. |
| @@ -221072,10 +221147,11 @@ | |
| 221147 | }else{ |
| 221148 | const char *zTerm; |
| 221149 | int nTerm; |
| 221150 | |
| 221151 | zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm); |
| 221152 | assert( nTerm>=0 ); |
| 221153 | if( pCsr->nLeTerm>=0 ){ |
| 221154 | int nCmp = MIN(nTerm, pCsr->nLeTerm); |
| 221155 | int bCmp = memcmp(pCsr->zLeTerm, zTerm, nCmp); |
| 221156 | if( bCmp<0 || (bCmp==0 && pCsr->nLeTerm<nTerm) ){ |
| 221157 | pCsr->bEof = 1; |
| @@ -221665,12 +221741,12 @@ | |
| 221741 | } |
| 221742 | #endif /* SQLITE_CORE */ |
| 221743 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 221744 | |
| 221745 | /************** End of stmt.c ************************************************/ |
| 221746 | #if __LINE__!=221746 |
| 221747 | #undef SQLITE_SOURCE_ID |
| 221748 | #define SQLITE_SOURCE_ID "2019-02-01 15:06:27 4ca9d5d53d41d08fbce29f9da8cc0948df9c4c3136210af88b499cf889b5alt2" |
| 221749 | #endif |
| 221750 | /* Return the source-id for this library */ |
| 221751 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 221752 | /************************** End of sqlite3.c ******************************/ |
| 221753 |
+13
-1
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -123,11 +123,11 @@ | ||
| 123 | 123 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 124 | 124 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 125 | 125 | */ |
| 126 | 126 | #define SQLITE_VERSION "3.27.0" |
| 127 | 127 | #define SQLITE_VERSION_NUMBER 3027000 |
| 128 | -#define SQLITE_SOURCE_ID "2019-01-27 02:45:32 9cf8ebd141aa2eb661d457624c76433bd9e4abfdef04aa52e28bc169172calt1" | |
| 128 | +#define SQLITE_SOURCE_ID "2019-02-01 15:06:27 4ca9d5d53d41d08fbce29f9da8cc0948df9c4c3136210af88b499cf889b5ccb8" | |
| 129 | 129 | |
| 130 | 130 | /* |
| 131 | 131 | ** CAPI3REF: Run-Time Library Version Numbers |
| 132 | 132 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 133 | 133 | ** |
| @@ -1980,10 +1980,21 @@ | ||
| 1980 | 1980 | ** from the database as records are returned in sorted order. The default |
| 1981 | 1981 | ** value for this option is to never use this optimization. Specifying a |
| 1982 | 1982 | ** negative value for this option restores the default behaviour. |
| 1983 | 1983 | ** This option is only available if SQLite is compiled with the |
| 1984 | 1984 | ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option. |
| 1985 | +** | |
| 1986 | +** [[SQLITE_CONFIG_MEMDB_MAXSIZE]] | |
| 1987 | +** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE | |
| 1988 | +** <dd>The SQLITE_CONFIG_MEMDB_MAXSIZE option accepts a single parameter | |
| 1989 | +** [sqlite3_int64] parameter which is the default maximum size for an in-memory | |
| 1990 | +** database created using [sqlite3_deserialize()]. This default maximum | |
| 1991 | +** size can be adjusted up or down for individual databases using the | |
| 1992 | +** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this | |
| 1993 | +** configuration setting is never used, then the default maximum is determined | |
| 1994 | +** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that | |
| 1995 | +** compile-time option is not set, then the default maximum is 1073741824. | |
| 1985 | 1996 | ** </dl> |
| 1986 | 1997 | */ |
| 1987 | 1998 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1988 | 1999 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 1989 | 2000 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| @@ -2010,10 +2021,11 @@ | ||
| 2010 | 2021 | #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ |
| 2011 | 2022 | #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */ |
| 2012 | 2023 | #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */ |
| 2013 | 2024 | #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */ |
| 2014 | 2025 | #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */ |
| 2026 | +#define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */ | |
| 2015 | 2027 | |
| 2016 | 2028 | /* |
| 2017 | 2029 | ** CAPI3REF: Database Connection Configuration Options |
| 2018 | 2030 | ** |
| 2019 | 2031 | ** These constants are the available integer configuration options that |
| 2020 | 2032 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -123,11 +123,11 @@ | |
| 123 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 124 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 125 | */ |
| 126 | #define SQLITE_VERSION "3.27.0" |
| 127 | #define SQLITE_VERSION_NUMBER 3027000 |
| 128 | #define SQLITE_SOURCE_ID "2019-01-27 02:45:32 9cf8ebd141aa2eb661d457624c76433bd9e4abfdef04aa52e28bc169172calt1" |
| 129 | |
| 130 | /* |
| 131 | ** CAPI3REF: Run-Time Library Version Numbers |
| 132 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 133 | ** |
| @@ -1980,10 +1980,21 @@ | |
| 1980 | ** from the database as records are returned in sorted order. The default |
| 1981 | ** value for this option is to never use this optimization. Specifying a |
| 1982 | ** negative value for this option restores the default behaviour. |
| 1983 | ** This option is only available if SQLite is compiled with the |
| 1984 | ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option. |
| 1985 | ** </dl> |
| 1986 | */ |
| 1987 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1988 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 1989 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| @@ -2010,10 +2021,11 @@ | |
| 2010 | #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ |
| 2011 | #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */ |
| 2012 | #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */ |
| 2013 | #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */ |
| 2014 | #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */ |
| 2015 | |
| 2016 | /* |
| 2017 | ** CAPI3REF: Database Connection Configuration Options |
| 2018 | ** |
| 2019 | ** These constants are the available integer configuration options that |
| 2020 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -123,11 +123,11 @@ | |
| 123 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 124 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 125 | */ |
| 126 | #define SQLITE_VERSION "3.27.0" |
| 127 | #define SQLITE_VERSION_NUMBER 3027000 |
| 128 | #define SQLITE_SOURCE_ID "2019-02-01 15:06:27 4ca9d5d53d41d08fbce29f9da8cc0948df9c4c3136210af88b499cf889b5ccb8" |
| 129 | |
| 130 | /* |
| 131 | ** CAPI3REF: Run-Time Library Version Numbers |
| 132 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 133 | ** |
| @@ -1980,10 +1980,21 @@ | |
| 1980 | ** from the database as records are returned in sorted order. The default |
| 1981 | ** value for this option is to never use this optimization. Specifying a |
| 1982 | ** negative value for this option restores the default behaviour. |
| 1983 | ** This option is only available if SQLite is compiled with the |
| 1984 | ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option. |
| 1985 | ** |
| 1986 | ** [[SQLITE_CONFIG_MEMDB_MAXSIZE]] |
| 1987 | ** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE |
| 1988 | ** <dd>The SQLITE_CONFIG_MEMDB_MAXSIZE option accepts a single parameter |
| 1989 | ** [sqlite3_int64] parameter which is the default maximum size for an in-memory |
| 1990 | ** database created using [sqlite3_deserialize()]. This default maximum |
| 1991 | ** size can be adjusted up or down for individual databases using the |
| 1992 | ** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this |
| 1993 | ** configuration setting is never used, then the default maximum is determined |
| 1994 | ** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that |
| 1995 | ** compile-time option is not set, then the default maximum is 1073741824. |
| 1996 | ** </dl> |
| 1997 | */ |
| 1998 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 1999 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 2000 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| @@ -2010,10 +2021,11 @@ | |
| 2021 | #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ |
| 2022 | #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */ |
| 2023 | #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */ |
| 2024 | #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */ |
| 2025 | #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */ |
| 2026 | #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */ |
| 2027 | |
| 2028 | /* |
| 2029 | ** CAPI3REF: Database Connection Configuration Options |
| 2030 | ** |
| 2031 | ** These constants are the available integer configuration options that |
| 2032 |