Fossil SCM

Update the built-in SQLite to the latest 3.27.0 alpha.

drh 2019-02-01 15:55 trunk
Commit 6ba52d791f57ae7f448e7a6bcef7d2f99612f82c1a32a93f6c9b4304bff97413
2 files changed +165 -89 +13 -1
+165 -89
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
11621162
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11631163
** [sqlite_version()] and [sqlite_source_id()].
11641164
*/
11651165
#define SQLITE_VERSION "3.27.0"
11661166
#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"
11681168
11691169
/*
11701170
** CAPI3REF: Run-Time Library Version Numbers
11711171
** KEYWORDS: sqlite3_version sqlite3_sourceid
11721172
**
@@ -3019,10 +3019,21 @@
30193019
** from the database as records are returned in sorted order. The default
30203020
** value for this option is to never use this optimization. Specifying a
30213021
** negative value for this option restores the default behaviour.
30223022
** This option is only available if SQLite is compiled with the
30233023
** [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.
30243035
** </dl>
30253036
*/
30263037
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
30273038
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
30283039
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -3049,10 +3060,11 @@
30493060
#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
30503061
#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
30513062
#define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
30523063
#define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
30533064
#define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */
3065
+#define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */
30543066
30553067
/*
30563068
** CAPI3REF: Database Connection Configuration Options
30573069
**
30583070
** These constants are the available integer configuration options that
@@ -16433,10 +16445,11 @@
1643316445
#define SQLITE_SqlTrace HI(0x0001) /* Debug print SQL as it executes */
1643416446
#define SQLITE_VdbeListing HI(0x0002) /* Debug listings of VDBE progs */
1643516447
#define SQLITE_VdbeTrace HI(0x0004) /* True to trace VDBE execution */
1643616448
#define SQLITE_VdbeAddopTrace HI(0x0008) /* Trace sqlite3VdbeAddOp() calls */
1643716449
#define SQLITE_VdbeEQP HI(0x0010) /* Debug EXPLAIN QUERY PLAN */
16450
+#define SQLITE_ParserTrace HI(0x0020) /* PRAGMA parser_trace=ON */
1643816451
#endif
1643916452
1644016453
/*
1644116454
** Allowed values for sqlite3.mDbFlags
1644216455
*/
@@ -18305,10 +18318,13 @@
1830518318
** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE.
1830618319
*/
1830718320
void (*xVdbeBranch)(void*,unsigned iSrcLine,u8 eThis,u8 eMx); /* Callback */
1830818321
void *pVdbeBranchArg; /* 1st argument */
1830918322
#endif
18323
+#ifdef SQLITE_ENABLE_DESERIALIZE
18324
+ sqlite3_int64 mxMemdbSize; /* Default max memdb size */
18325
+#endif
1831018326
#ifndef SQLITE_UNTESTABLE
1831118327
int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
1831218328
#endif
1831318329
int bLocaltimeFault; /* True to fail localtime() calls */
1831418330
int bInternalFunctions; /* Internal SQL functions are visible */
@@ -18722,10 +18738,11 @@
1872218738
SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int);
1872318739
SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
1872418740
SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*);
1872518741
SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
1872618742
SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
18743
+SQLITE_PRIVATE int sqlite3IndexHasDuplicateRootPage(Index*);
1872718744
SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
1872818745
SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
1872918746
SQLITE_PRIVATE int sqlite3InitOne(sqlite3*, int, char**, u32);
1873018747
SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
1873118748
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -19716,10 +19733,17 @@
1971619733
#ifndef SQLITE_DEFAULT_LOOKASIDE
1971719734
# define SQLITE_DEFAULT_LOOKASIDE 1200,100
1971819735
#endif
1971919736
1972019737
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
+
1972119745
/*
1972219746
** The following singleton contains the global configuration for
1972319747
** the SQLite library.
1972419748
*/
1972519749
SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
@@ -19763,17 +19787,20 @@
1976319787
#endif
1976419788
#ifdef SQLITE_VDBE_COVERAGE
1976519789
0, /* xVdbeBranch */
1976619790
0, /* pVbeBranchArg */
1976719791
#endif
19792
+#ifdef SQLITE_ENABLE_DESERIALIZE
19793
+ SQLITE_MEMDB_DEFAULT_MAXSIZE, /* mxMemdbSize */
19794
+#endif
1976819795
#ifndef SQLITE_UNTESTABLE
1976919796
0, /* xTestCallback */
1977019797
#endif
1977119798
0, /* bLocaltimeFault */
1977219799
0, /* bInternalFunctions */
1977319800
0x7ffffffe, /* iOnceResetThreshold */
19774
- SQLITE_DEFAULT_SORTERREF_SIZE /* szSorterRef */
19801
+ SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */
1977519802
};
1977619803
1977719804
/*
1977819805
** Hash table for global functions - functions common to all
1977919806
** database connections. After initialization, this table is
@@ -46578,15 +46605,10 @@
4657846605
int nMmap; /* Number of memory mapped pages */
4657946606
unsigned mFlags; /* Flags */
4658046607
int eLock; /* Most recent lock against this file */
4658146608
};
4658246609
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
-
4658846610
/*
4658946611
** Methods for MemFile
4659046612
*/
4659146613
static int memdbClose(sqlite3_file*);
4659246614
static int memdbRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
@@ -46847,11 +46869,10 @@
4684746869
int iAmt,
4684846870
void **pp
4684946871
){
4685046872
MemFile *p = (MemFile *)pFile;
4685146873
if( iOfst+iAmt>p->sz ){
46852
- assert( CORRUPT_DB );
4685346874
*pp = 0;
4685446875
}else{
4685546876
p->nMmap++;
4685646877
*pp = (void*)(p->aData + iOfst);
4685746878
}
@@ -46882,11 +46903,11 @@
4688246903
memset(p, 0, sizeof(*p));
4688346904
p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
4688446905
assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */
4688546906
*pOutFlags = flags | SQLITE_OPEN_MEMORY;
4688646907
p->base.pMethods = &memdb_io_methods;
46887
- p->szMax = SQLITE_MEMDB_DEFAULT_MAXSIZE;
46908
+ p->szMax = sqlite3GlobalConfig.mxMemdbSize;
4688846909
return SQLITE_OK;
4688946910
}
4689046911
4689146912
#if 0 /* Only used to delete rollback journals, master journals, and WAL
4689246913
** files, none of which exist in memdb. So this routine is never used */
@@ -47134,12 +47155,12 @@
4713447155
}else{
4713547156
p->aData = pData;
4713647157
p->sz = szDb;
4713747158
p->szAlloc = szBuf;
4713847159
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;
4714147162
}
4714247163
p->mFlags = mFlags;
4714347164
rc = SQLITE_OK;
4714447165
}
4714547166
@@ -62473,13 +62494,20 @@
6247362494
**
6247462495
** Fields in this structure are accessed under the BtShared.mutex
6247562496
** found at self->pBt->mutex.
6247662497
**
6247762498
** 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.
6248162509
*/
6248262510
struct BtCursor {
6248362511
u8 eState; /* One of the CURSOR_XXX constants (see below) */
6248462512
u8 curFlags; /* zero or more BTCF_* flags defined below */
6248562513
u8 curPagerFlags; /* Flags to send to sqlite3PagerGet() */
@@ -63824,11 +63852,11 @@
6382463852
rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext);
6382563853
if( rc==SQLITE_OK ){
6382663854
sqlite3_free(pCur->pKey);
6382763855
pCur->pKey = 0;
6382863856
assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID );
63829
- pCur->skipNext |= skipNext;
63857
+ if( skipNext ) pCur->skipNext = skipNext;
6383063858
if( pCur->skipNext && pCur->eState==CURSOR_VALID ){
6383163859
pCur->eState = CURSOR_SKIPNEXT;
6383263860
}
6383363861
}
6383463862
return rc;
@@ -63894,11 +63922,10 @@
6389463922
return rc;
6389563923
}
6389663924
if( pCur->eState!=CURSOR_VALID ){
6389763925
*pDifferentRow = 1;
6389863926
}else{
63899
- assert( pCur->skipNext==0 );
6390063927
*pDifferentRow = 0;
6390163928
}
6390263929
return SQLITE_OK;
6390363930
}
6390463931
@@ -68313,11 +68340,11 @@
6831368340
}
6831468341
/* If the requested key is one more than the previous key, then
6831568342
** try to get there using sqlite3BtreeNext() rather than a full
6831668343
** binary search. This is an optimization only. The correct answer
6831768344
** 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 ){
6831968346
*pRes = 0;
6832068347
rc = sqlite3BtreeNext(pCur, 0);
6832168348
if( rc==SQLITE_OK ){
6832268349
getCellInfo(pCur);
6832368350
if( pCur->info.nKey==intKey ){
@@ -68587,28 +68614,22 @@
6858768614
int rc;
6858868615
int idx;
6858968616
MemPage *pPage;
6859068617
6859168618
assert( cursorOwnsBtShared(pCur) );
68592
- assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
6859368619
if( pCur->eState!=CURSOR_VALID ){
6859468620
assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
6859568621
rc = restoreCursorPosition(pCur);
6859668622
if( rc!=SQLITE_OK ){
6859768623
return rc;
6859868624
}
6859968625
if( CURSOR_INVALID==pCur->eState ){
6860068626
return SQLITE_DONE;
6860168627
}
68602
- if( pCur->skipNext ){
68603
- assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT );
68628
+ if( pCur->eState==CURSOR_SKIPNEXT ){
6860468629
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;
6861068631
}
6861168632
}
6861268633
6861368634
pPage = pCur->pPage;
6861468635
idx = ++pCur->ix;
@@ -68659,11 +68680,10 @@
6865968680
SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int flags){
6866068681
MemPage *pPage;
6866168682
UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */
6866268683
assert( cursorOwnsBtShared(pCur) );
6866368684
assert( flags==0 || flags==1 );
68664
- assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
6866568685
pCur->info.nSize = 0;
6866668686
pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
6866768687
if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur);
6866868688
pPage = pCur->pPage;
6866968689
if( (++pCur->ix)>=pPage->nCell ){
@@ -68700,11 +68720,10 @@
6870068720
static SQLITE_NOINLINE int btreePrevious(BtCursor *pCur){
6870168721
int rc;
6870268722
MemPage *pPage;
6870368723
6870468724
assert( cursorOwnsBtShared(pCur) );
68705
- assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
6870668725
assert( (pCur->curFlags & (BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey))==0 );
6870768726
assert( pCur->info.nSize==0 );
6870868727
if( pCur->eState!=CURSOR_VALID ){
6870968728
rc = restoreCursorPosition(pCur);
6871068729
if( rc!=SQLITE_OK ){
@@ -68711,18 +68730,13 @@
6871168730
return rc;
6871268731
}
6871368732
if( CURSOR_INVALID==pCur->eState ){
6871468733
return SQLITE_DONE;
6871568734
}
68716
- if( pCur->skipNext ){
68717
- assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT );
68735
+ if( CURSOR_SKIPNEXT==pCur->eState ){
6871868736
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;
6872468738
}
6872568739
}
6872668740
6872768741
pPage = pCur->pPage;
6872868742
assert( pPage->isInit );
@@ -68753,11 +68767,10 @@
6875368767
return rc;
6875468768
}
6875568769
SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int flags){
6875668770
assert( cursorOwnsBtShared(pCur) );
6875768771
assert( flags==0 || flags==1 );
68758
- assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
6875968772
UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */
6876068773
pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey);
6876168774
pCur->info.nSize = 0;
6876268775
if( pCur->eState!=CURSOR_VALID
6876368776
|| pCur->ix==0
@@ -69722,27 +69735,38 @@
6972269735
** / | \
6972369736
** --------- --------- ---------
6972469737
** |Child-1| |Child-2| |Child-3|
6972569738
** --------- --------- ---------
6972669739
**
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:
6972869741
**
6972969742
** 1. All cells from Child-1 in order
6973069743
** 2. The first divider cell from Parent
6973169744
** 3. All cells from Child-2 in order
6973269745
** 4. The second divider cell from Parent
6973369746
** 5. All cells from Child-3 in order
6973469747
**
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
+**
6973969756
** ixNx[0] = Number of cells in Child-1.
6974069757
** ixNx[1] = Number of cells in Child-1 plus 1 for first divider.
6974169758
** ixNx[2] = Number of cells in Child-1 and Child-2 + 1 for 1st divider.
6974269759
** ixNx[3] = Number of cells in Child-1 and Child-2 + both divider cells
6974369760
** 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
6974469768
*/
6974569769
typedef struct CellArray CellArray;
6974669770
struct CellArray {
6974769771
int nCell; /* Number of cells in apCell[] */
6974869772
MemPage *pRef; /* Reference page */
@@ -69808,20 +69832,21 @@
6980869832
const int hdr = pPg->hdrOffset; /* Offset of header on pPg */
6980969833
u8 * const aData = pPg->aData; /* Pointer to data for pPg */
6981069834
const int usableSize = pPg->pBt->usableSize;
6981169835
u8 * const pEnd = &aData[usableSize];
6981269836
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 */
6981469838
int iEnd = i+nCell; /* Loop terminator */
6981569839
u8 *pCellptr = pPg->aCellIdx;
6981669840
u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
6981769841
u8 *pData;
6981869842
int k; /* Current slot in pCArray->apEnd[] */
6981969843
u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */
6982069844
6982169845
assert( i<iEnd );
6982269846
j = get2byte(&aData[hdr+5]);
69847
+ if( NEVER(j>(u32)usableSize) ){ j = 0; }
6982369848
memcpy(&pTmp[j], &aData[j], usableSize - j);
6982469849
6982569850
for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
6982669851
pSrcEnd = pCArray->apEnd[k];
6982769852
@@ -69997,11 +70022,11 @@
6999770022
}
6999870023
return nRet;
6999970024
}
7000070025
7000170026
/*
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
7000370028
** balanced. The current page, pPg, has pPg->nCell cells starting with
7000470029
** pCArray->apCell[iOld]. After balancing, this page should hold nNew cells
7000570030
** starting at apCell[iNew].
7000670031
**
7000770032
** This routine makes the necessary adjustments to pPg so that it contains
@@ -70031,26 +70056,31 @@
7003170056
u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
7003270057
memcpy(pTmp, aData, pPg->pBt->usableSize);
7003370058
#endif
7003470059
7003570060
/* Remove cells from the start and end of the page */
70061
+ assert( nCell>=0 );
7003670062
if( iOld<iNew ){
7003770063
int nShift = pageFreeArray(pPg, iOld, iNew-iOld, pCArray);
70064
+ if( nShift>nCell ) return SQLITE_CORRUPT_BKPT;
7003870065
memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2);
7003970066
nCell -= nShift;
7004070067
}
7004170068
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;
7004370072
}
7004470073
7004570074
pData = &aData[get2byteNotZero(&aData[hdr+5])];
7004670075
if( pData<pBegin ) goto editpage_fail;
7004770076
7004870077
/* Add cells to the start of the page */
7004970078
if( iNew<iOld ){
7005070079
int nAdd = MIN(nNew,iOld-iNew);
7005170080
assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
70081
+ assert( nAdd>=0 );
7005270082
pCellptr = pPg->aCellIdx;
7005370083
memmove(&pCellptr[nAdd*2], pCellptr, nCell*2);
7005470084
if( pageInsertArray(
7005570085
pPg, pBegin, &pData, pCellptr,
7005670086
iNew, nAdd, pCArray
@@ -70061,10 +70091,11 @@
7006170091
/* Add any overflow cells */
7006270092
for(i=0; i<pPg->nOverflow; i++){
7006370093
int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
7006470094
if( iCell>=0 && iCell<nNew ){
7006570095
pCellptr = &pPg->aCellIdx[iCell * 2];
70096
+ assert( nCell>=iCell );
7006670097
memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
7006770098
nCell++;
7006870099
if( pageInsertArray(
7006970100
pPg, pBegin, &pData, pCellptr,
7007070101
iCell+iNew, 1, pCArray
@@ -70071,10 +70102,11 @@
7007170102
) ) goto editpage_fail;
7007270103
}
7007370104
}
7007470105
7007570106
/* Append cells to the end of the page */
70107
+ assert( nCell>=0 );
7007670108
pCellptr = &pPg->aCellIdx[nCell*2];
7007770109
if( pageInsertArray(
7007870110
pPg, pBegin, &pData, pCellptr,
7007970111
iNew+nCell, nNew-nCell, pCArray
7008070112
) ) goto editpage_fail;
@@ -70644,16 +70676,19 @@
7064470676
** the right of the i-th sibling page.
7064570677
** usableSpace: Number of bytes of space available on each sibling.
7064670678
**
7064770679
*/
7064870680
usableSpace = pBt->usableSize - 12 + leafCorrection;
70649
- for(i=0; i<nOld; i++){
70681
+ for(i=k=0; i<nOld; i++, k++){
7065070682
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
+ }
7065570690
szNew[i] = usableSpace - p->nFree;
7065670691
for(j=0; j<p->nOverflow; j++){
7065770692
szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);
7065870693
}
7065970694
cntNew[i] = cntOld[i];
@@ -71749,11 +71784,10 @@
7174971784
** from the internal node. The 'previous' entry is used for this instead
7175071785
** of the 'next' entry, as the previous entry is always a part of the
7175171786
** sub-tree headed by the child page of the cell being deleted. This makes
7175271787
** balancing the tree following the delete operation easier. */
7175371788
if( !pPage->leaf ){
71754
- pCur->skipNext = 0;
7175571789
rc = sqlite3BtreePrevious(pCur, 0);
7175671790
assert( rc!=SQLITE_DONE );
7175771791
if( rc ) return rc;
7175871792
}
7175971793
@@ -97882,10 +97916,11 @@
9788297916
static void gatherSelectWindows(Select *p){
9788397917
Walker w;
9788497918
w.xExprCallback = gatherSelectWindowsCallback;
9788597919
w.xSelectCallback = gatherSelectWindowsSelectCallback;
9788697920
w.xSelectCallback2 = 0;
97921
+ w.pParse = 0;
9788797922
w.u.pSelect = p;
9788897923
sqlite3WalkSelect(&w, p);
9788997924
}
9789097925
#endif
9789197926
@@ -109965,21 +110000,26 @@
109965110000
assert( pParse->nErr==0 );
109966110001
if( db->init.busy ){
109967110002
Index *p;
109968110003
assert( !IN_SPECIAL_PARSE );
109969110004
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
+ }
109970110013
p = sqlite3HashInsert(&pIndex->pSchema->idxHash,
109971110014
pIndex->zName, pIndex);
109972110015
if( p ){
109973110016
assert( p==pIndex ); /* Malloc must have failed */
109974110017
sqlite3OomFault(db);
109975110018
goto exit_create_index;
109976110019
}
109977110020
db->mDbFlags |= DBFLAG_SchemaChange;
109978
- if( pTblName!=0 ){
109979
- pIndex->tnum = db->init.newTnum;
109980
- }
109981110021
}
109982110022
109983110023
/* If this is the initial CREATE INDEX statement (or CREATE TABLE if the
109984110024
** index is an implied index for a UNIQUE or PRIMARY KEY constraint) then
109985110025
** emit code to allocate the index rootpage on disk and make an entry for
@@ -120194,12 +120234,11 @@
120194120234
#define PragTyp_WAL_CHECKPOINT 39
120195120235
#define PragTyp_ACTIVATE_EXTENSIONS 40
120196120236
#define PragTyp_HEXKEY 41
120197120237
#define PragTyp_KEY 42
120198120238
#define PragTyp_LOCK_STATUS 43
120199
-#define PragTyp_PARSER_TRACE 44
120200
-#define PragTyp_STATS 45
120239
+#define PragTyp_STATS 44
120201120240
120202120241
/* Property flags associated with various pragma. */
120203120242
#define PragFlg_NeedSchema 0x01 /* Force schema load before running */
120204120243
#define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */
120205120244
#define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */
@@ -120618,16 +120657,18 @@
120618120657
/* ePragTyp: */ PragTyp_PAGE_SIZE,
120619120658
/* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
120620120659
/* ColNames: */ 0, 0,
120621120660
/* iArg: */ 0 },
120622120661
#endif
120623
-#if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_PARSER_TRACE)
120662
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120663
+#if defined(SQLITE_DEBUG)
120624120664
{/* zName: */ "parser_trace",
120625
- /* ePragTyp: */ PragTyp_PARSER_TRACE,
120626
- /* ePragFlg: */ 0,
120665
+ /* ePragTyp: */ PragTyp_FLAG,
120666
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120627120667
/* ColNames: */ 0, 0,
120628
- /* iArg: */ 0 },
120668
+ /* iArg: */ SQLITE_ParserTrace },
120669
+#endif
120629120670
#endif
120630120671
#if defined(SQLITE_INTROSPECTION_PRAGMAS)
120631120672
{/* zName: */ "pragma_list",
120632120673
/* ePragTyp: */ PragTyp_PRAGMA_LIST,
120633120674
/* ePragFlg: */ PragFlg_Result0,
@@ -122225,23 +122266,10 @@
122225122266
}
122226122267
break;
122227122268
#endif /* !defined(SQLITE_OMIT_TRIGGER) */
122228122269
#endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
122229122270
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
-
122243122271
/* Reinstall the LIKE and GLOB functions. The variant of LIKE
122244122272
** used will be case sensitive or not depending on the RHS.
122245122273
*/
122246122274
case PragTyp_CASE_SENSITIVE_LIKE: {
122247122275
if( zRight ){
@@ -123358,10 +123386,23 @@
123358123386
if( zExtra && zExtra[0] ) z = sqlite3MPrintf(db, "%z - %s", z, zExtra);
123359123387
*pData->pzErrMsg = z;
123360123388
pData->rc = SQLITE_CORRUPT_BKPT;
123361123389
}
123362123390
}
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
+}
123363123404
123364123405
/*
123365123406
** This is the callback routine for the code that initializes the
123366123407
** database. See sqlite3Init() below for additional information.
123367123408
** This routine is also called from the OP_ParseSchema opcode of the VDBE.
@@ -123437,10 +123478,11 @@
123437123478
Index *pIndex;
123438123479
pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zDbSName);
123439123480
if( pIndex==0
123440123481
|| sqlite3GetInt32(argv[1],&pIndex->tnum)==0
123441123482
|| pIndex->tnum<2
123483
+ || sqlite3IndexHasDuplicateRootPage(pIndex)
123442123484
){
123443123485
corruptSchema(pData, argv[0], pIndex?"invalid rootpage":"orphan index");
123444123486
}
123445123487
}
123446123488
return 0;
@@ -139887,10 +139929,21 @@
139887139929
k = 0;
139888139930
pScan->iEquiv++;
139889139931
}
139890139932
return 0;
139891139933
}
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
+}
139892139945
139893139946
/*
139894139947
** Initialize a WHERE clause scanner object. Return a pointer to the
139895139948
** first match. Return NULL if there are no matches.
139896139949
**
@@ -139920,31 +139973,33 @@
139920139973
pScan->pOrigWC = pWC;
139921139974
pScan->pWC = pWC;
139922139975
pScan->pIdxExpr = 0;
139923139976
pScan->idxaff = 0;
139924139977
pScan->zCollName = 0;
139978
+ pScan->opMask = opMask;
139979
+ pScan->k = 0;
139980
+ pScan->aiCur[0] = iCur;
139981
+ pScan->nEquiv = 1;
139982
+ pScan->iEquiv = 1;
139925139983
if( pIdx ){
139926139984
int j = iColumn;
139927139985
iColumn = pIdx->aiColumn[j];
139928139986
if( iColumn==XN_EXPR ){
139929139987
pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr;
139930139988
pScan->zCollName = pIdx->azColl[j];
139989
+ pScan->aiColumn[0] = XN_EXPR;
139990
+ return whereScanInitIndexExpr(pScan);
139931139991
}else if( iColumn==pIdx->pTable->iPKey ){
139932139992
iColumn = XN_ROWID;
139933139993
}else if( iColumn>=0 ){
139934139994
pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
139935139995
pScan->zCollName = pIdx->azColl[j];
139936139996
}
139937139997
}else if( iColumn==XN_EXPR ){
139938139998
return 0;
139939139999
}
139940
- pScan->opMask = opMask;
139941
- pScan->k = 0;
139942
- pScan->aiCur[0] = iCur;
139943140000
pScan->aiColumn[0] = iColumn;
139944
- pScan->nEquiv = 1;
139945
- pScan->iEquiv = 1;
139946140001
return whereScanNext(pScan);
139947140002
}
139948140003
139949140004
/*
139950140005
** Search for a term in the WHERE clause that is of the form "X <op> <expr>"
@@ -152900,11 +152955,18 @@
152900152955
db->u1.isInterrupted = 0;
152901152956
}
152902152957
pParse->rc = SQLITE_OK;
152903152958
pParse->zTail = zSql;
152904152959
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
152906152968
#ifdef sqlite3Parser_ENGINEALWAYSONSTACK
152907152969
pEngine = &sEngine;
152908152970
sqlite3ParserInit(pEngine, pParse);
152909152971
#else
152910152972
pEngine = sqlite3ParserAlloc(sqlite3Malloc, pParse);
@@ -154223,10 +154285,17 @@
154223154285
sqlite3GlobalConfig.szSorterRef = (u32)iVal;
154224154286
break;
154225154287
}
154226154288
#endif /* SQLITE_ENABLE_SORTER_REFERENCES */
154227154289
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
+
154228154297
default: {
154229154298
rc = SQLITE_ERROR;
154230154299
break;
154231154300
}
154232154301
}
@@ -161990,10 +162059,11 @@
161990162059
*/
161991162060
pTS->aaOutput[0] = sqlite3_malloc(nDoclist + FTS3_VARINT_MAX + 1);
161992162061
pTS->anOutput[0] = nDoclist;
161993162062
if( pTS->aaOutput[0] ){
161994162063
memcpy(pTS->aaOutput[0], aDoclist, nDoclist);
162064
+ memset(&pTS->aaOutput[0][nDoclist], 0, FTS3_VARINT_MAX);
161995162065
}else{
161996162066
return SQLITE_NOMEM;
161997162067
}
161998162068
}else{
161999162069
char *aMerge = aDoclist;
@@ -165603,19 +165673,19 @@
165603165673
if( iEq>=0 || iGe>=0 ){
165604165674
const unsigned char *zStr = sqlite3_value_text(apVal[0]);
165605165675
assert( (iEq==0 && iGe==-1) || (iEq==-1 && iGe==0) );
165606165676
if( zStr ){
165607165677
pCsr->filter.zTerm = sqlite3_mprintf("%s", zStr);
165608
- pCsr->filter.nTerm = sqlite3_value_bytes(apVal[0]);
165609165678
if( pCsr->filter.zTerm==0 ) return SQLITE_NOMEM;
165679
+ pCsr->filter.nTerm = (int)strlen(pCsr->filter.zTerm);
165610165680
}
165611165681
}
165612165682
165613165683
if( iLe>=0 ){
165614165684
pCsr->zStop = sqlite3_mprintf("%s", sqlite3_value_text(apVal[iLe]));
165615
- pCsr->nStop = sqlite3_value_bytes(apVal[iLe]);
165616165685
if( pCsr->zStop==0 ) return SQLITE_NOMEM;
165686
+ pCsr->nStop = (int)strlen(pCsr->zStop);
165617165687
}
165618165688
165619165689
if( iLangid>=0 ){
165620165690
iLangVal = sqlite3_value_int(apVal[iLangid]);
165621165691
@@ -202679,11 +202749,13 @@
202679202749
int iAdj;
202680202750
int nScore;
202681202751
int jj;
202682202752
202683202753
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;
202685202757
memset(aSeen, 0, nPhrase);
202686202758
rc = fts5SnippetScore(pApi, pFts, nDocsize, aSeen, i,
202687202759
io, nToken, &nScore, &iAdj
202688202760
);
202689202761
if( rc==SQLITE_OK && nScore>nBestScore ){
@@ -209352,11 +209424,11 @@
209352209424
u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
209353209425
int iOff = pIter->iLeafOffset; /* Offset to read at */
209354209426
int nNew; /* Bytes of new data */
209355209427
209356209428
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 ){
209358209430
p->rc = FTS5_CORRUPT;
209359209431
return;
209360209432
}
209361209433
pIter->term.n = nKeep;
209362209434
fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
@@ -210026,11 +210098,11 @@
210026210098
}while( 1 );
210027210099
}
210028210100
210029210101
search_success:
210030210102
pIter->iLeafOffset = iOff + nNew;
210031
- if( pIter->iLeafOffset>n ){
210103
+ if( pIter->iLeafOffset>n || nNew<1 ){
210032210104
p->rc = FTS5_CORRUPT;
210033210105
return;
210034210106
}
210035210107
pIter->iTermLeafOffset = pIter->iLeafOffset;
210036210108
pIter->iTermLeafPgno = pIter->iLeafPgno;
@@ -210804,11 +210876,12 @@
210804210876
Fts5Index *p,
210805210877
Fts5SegIter *pSeg,
210806210878
Fts5Colset *pColset,
210807210879
Fts5Buffer *pBuf
210808210880
){
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);
210810210883
if( pColset==0 ){
210811210884
fts5ChunkIterate(p, pSeg, (void*)pBuf, fts5PoslistCallback);
210812210885
}else{
210813210886
if( p->pConfig->eDetail==FTS5_DETAIL_FULL ){
210814210887
PoslistCallbackCtx sCtx;
@@ -211845,11 +211918,11 @@
211845211918
Fts5Data *pData;
211846211919
int iId = pSeg->pSeg->iSegid;
211847211920
u8 aHdr[4] = {0x00, 0x00, 0x00, 0x00};
211848211921
211849211922
iLeafRowid = FTS5_SEGMENT_ROWID(iId, pSeg->iTermLeafPgno);
211850
- pData = fts5DataRead(p, iLeafRowid);
211923
+ pData = fts5LeafRead(p, iLeafRowid);
211851211924
if( pData ){
211852211925
if( iOff>pData->szLeaf ){
211853211926
/* This can occur if the pages that the segments occupy overlap - if
211854211927
** a single page has been assigned to more than one segment. In
211855211928
** this case a prior iteration of this loop may have corrupted the
@@ -212700,11 +212773,11 @@
212700212773
sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos1);
212701212774
}
212702212775
sqlite3Fts5PoslistNext64(a1, i1.nPoslist, &iOff1, &iPos1);
212703212776
if( iPos1<0 ) break;
212704212777
}else{
212705
- assert( iPos2!=iPrev );
212778
+ assert_nc( iPos2!=iPrev );
212706212779
sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos2);
212707212780
sqlite3Fts5PoslistNext64(a2, i2.nPoslist, &iOff2, &iPos2);
212708212781
if( iPos2<0 ) break;
212709212782
}
212710212783
}
@@ -215964,11 +216037,13 @@
215964216037
const char **pz,
215965216038
int *pn
215966216039
){
215967216040
int rc = SQLITE_OK;
215968216041
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
+ ){
215970216045
*pz = 0;
215971216046
*pn = 0;
215972216047
}else{
215973216048
rc = fts5SeekCursor(pCsr, 0);
215974216049
if( rc==SQLITE_OK ){
@@ -216902,11 +216977,11 @@
216902216977
int nArg, /* Number of args */
216903216978
sqlite3_value **apUnused /* Function arguments */
216904216979
){
216905216980
assert( nArg==0 );
216906216981
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);
216908216983
}
216909216984
216910216985
/*
216911216986
** Return true if zName is the extension on one of the shadow tables used
216912216987
** by this module.
@@ -221072,10 +221147,11 @@
221072221147
}else{
221073221148
const char *zTerm;
221074221149
int nTerm;
221075221150
221076221151
zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
221152
+ assert( nTerm>=0 );
221077221153
if( pCsr->nLeTerm>=0 ){
221078221154
int nCmp = MIN(nTerm, pCsr->nLeTerm);
221079221155
int bCmp = memcmp(pCsr->zLeTerm, zTerm, nCmp);
221080221156
if( bCmp<0 || (bCmp==0 && pCsr->nLeTerm<nTerm) ){
221081221157
pCsr->bEof = 1;
@@ -221665,12 +221741,12 @@
221665221741
}
221666221742
#endif /* SQLITE_CORE */
221667221743
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
221668221744
221669221745
/************** End of stmt.c ************************************************/
221670
-#if __LINE__!=221670
221746
+#if __LINE__!=221746
221671221747
#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"
221673221749
#endif
221674221750
/* Return the source-id for this library */
221675221751
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
221676221752
/************************** End of sqlite3.c ******************************/
221677221753
--- 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 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.27.0"
127127
#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"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -1980,10 +1980,21 @@
19801980
** from the database as records are returned in sorted order. The default
19811981
** value for this option is to never use this optimization. Specifying a
19821982
** negative value for this option restores the default behaviour.
19831983
** This option is only available if SQLite is compiled with the
19841984
** [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.
19851996
** </dl>
19861997
*/
19871998
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
19881999
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
19892000
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -2010,10 +2021,11 @@
20102021
#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
20112022
#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
20122023
#define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
20132024
#define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
20142025
#define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */
2026
+#define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */
20152027
20162028
/*
20172029
** CAPI3REF: Database Connection Configuration Options
20182030
**
20192031
** These constants are the available integer configuration options that
20202032
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button