Fossil SCM

Update the built-in SQLite to version 3.28.0.

drh 2019-04-17 19:22 trunk
Commit 14db745dfe74a7e812e45aec020dffff186ec58a2b7893f60196ced4563b60f9
2 files changed +193 -111 +1 -1
+193 -111
--- 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.28.0"
11661166
#define SQLITE_VERSION_NUMBER 3028000
1167
-#define SQLITE_SOURCE_ID "2019-04-10 18:29:40 f294cfc173c5653ef161dbff63b7838dbccdcad797f5163c49b3173f9f35ab0f"
1167
+#define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50"
11681168
11691169
/*
11701170
** CAPI3REF: Run-Time Library Version Numbers
11711171
** KEYWORDS: sqlite3_version sqlite3_sourceid
11721172
**
@@ -13416,11 +13416,11 @@
1341613416
struct Hash {
1341713417
unsigned int htsize; /* Number of buckets in the hash table */
1341813418
unsigned int count; /* Number of entries in this table */
1341913419
HashElem *first; /* The first element of the array */
1342013420
struct _ht { /* the hash table */
13421
- int count; /* Number of entries with this hash */
13421
+ unsigned int count; /* Number of entries with this hash */
1342213422
HashElem *chain; /* Pointer to first entry with this hash */
1342313423
} *ht;
1342413424
};
1342513425
1342613426
/* Each element in the hash table is an instance of the following
@@ -29858,15 +29858,15 @@
2985829858
** This routine transforms the internal text encoding used by pMem to
2985929859
** desiredEnc. It is an error if the string is already of the desired
2986029860
** encoding, or if *pMem does not contain a string value.
2986129861
*/
2986229862
SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
29863
- int len; /* Maximum length of output string in bytes */
29864
- unsigned char *zOut; /* Output buffer */
29865
- unsigned char *zIn; /* Input iterator */
29866
- unsigned char *zTerm; /* End of input */
29867
- unsigned char *z; /* Output iterator */
29863
+ sqlite3_int64 len; /* Maximum length of output string in bytes */
29864
+ unsigned char *zOut; /* Output buffer */
29865
+ unsigned char *zIn; /* Input iterator */
29866
+ unsigned char *zTerm; /* End of input */
29867
+ unsigned char *z; /* Output iterator */
2986829868
unsigned int c;
2986929869
2987029870
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
2987129871
assert( pMem->flags&MEM_Str );
2987229872
assert( pMem->enc!=desiredEnc );
@@ -29911,18 +29911,18 @@
2991129911
** translating a 2-byte character to a 4-byte UTF-8 character.
2991229912
** A single byte is required for the output string
2991329913
** nul-terminator.
2991429914
*/
2991529915
pMem->n &= ~1;
29916
- len = pMem->n * 2 + 1;
29916
+ len = 2 * (sqlite3_int64)pMem->n + 1;
2991729917
}else{
2991829918
/* When converting from UTF-8 to UTF-16 the maximum growth is caused
2991929919
** when a 1-byte UTF-8 character is translated into a 2-byte UTF-16
2992029920
** character. Two bytes are required in the output buffer for the
2992129921
** nul-terminator.
2992229922
*/
29923
- len = pMem->n * 2 + 2;
29923
+ len = 2 * (sqlite3_int64)pMem->n + 2;
2992429924
}
2992529925
2992629926
/* Set zIn to point at the start of the input buffer and zTerm to point 1
2992729927
** byte past the end.
2992829928
**
@@ -31790,11 +31790,11 @@
3179031790
3179131791
nInt = nName/4 + 3;
3179231792
assert( pIn==0 || pIn[0]>=3 ); /* Verify ok to add new elements */
3179331793
if( pIn==0 || pIn[1]+nInt > pIn[0] ){
3179431794
/* Enlarge the allocation */
31795
- int nAlloc = (pIn ? pIn[0]*2 : 10) + nInt;
31795
+ sqlite3_int64 nAlloc = (pIn ? 2*(sqlite3_int64)pIn[0] : 10) + nInt;
3179631796
VList *pOut = sqlite3DbRealloc(db, pIn, nAlloc*sizeof(int));
3179731797
if( pOut==0 ) return pIn;
3179831798
if( pIn==0 ) pOut[1] = 2;
3179931799
pIn = pOut;
3180031800
pIn[0] = nAlloc;
@@ -31996,11 +31996,11 @@
3199631996
const Hash *pH, /* The pH to be searched */
3199731997
const char *pKey, /* The key we are searching for */
3199831998
unsigned int *pHash /* Write the hash value here */
3199931999
){
3200032000
HashElem *elem; /* Used to loop thru the element list */
32001
- int count; /* Number of elements left to test */
32001
+ unsigned int count; /* Number of elements left to test */
3200232002
unsigned int h; /* The computed hash */
3200332003
static HashElem nullElement = { 0, 0, 0, 0 };
3200432004
3200532005
if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/
3200632006
struct _ht *pEntry;
@@ -32044,12 +32044,12 @@
3204432044
if( pH->ht ){
3204532045
pEntry = &pH->ht[h];
3204632046
if( pEntry->chain==elem ){
3204732047
pEntry->chain = elem->next;
3204832048
}
32049
+ assert( pEntry->count>0 );
3204932050
pEntry->count--;
32050
- assert( pEntry->count>=0 );
3205132051
}
3205232052
sqlite3_free( elem );
3205332053
pH->count--;
3205432054
if( pH->count==0 ){
3205532055
assert( pH->first==0 );
@@ -49129,13 +49129,11 @@
4912949129
** Malloc function used by SQLite to obtain space from the buffer configured
4913049130
** using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no such buffer
4913149131
** exists, this function falls back to sqlite3Malloc().
4913249132
*/
4913349133
SQLITE_PRIVATE void *sqlite3PageMalloc(int sz){
49134
- /* During rebalance operations on a corrupt database file, it is sometimes
49135
- ** (rarely) possible to overread the temporary page buffer by a few bytes.
49136
- ** Enlarge the allocation slightly so that this does not cause problems. */
49134
+ assert( sz<=65536+8 ); /* These allocations are never very large */
4913749135
return pcache1Alloc(sz);
4913849136
}
4913949137
4914049138
/*
4914149139
** Free an allocated buffer obtained from sqlite3PageMalloc().
@@ -58889,11 +58887,11 @@
5888958887
){
5889058888
int rc = SQLITE_OK;
5889158889
5889258890
/* Enlarge the pWal->apWiData[] array if required */
5889358891
if( pWal->nWiData<=iPage ){
58894
- int nByte = sizeof(u32*)*(iPage+1);
58892
+ sqlite3_int64 nByte = sizeof(u32*)*(iPage+1);
5889558893
volatile u32 **apNew;
5889658894
apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte);
5889758895
if( !apNew ){
5889858896
*ppPage = 0;
5889958897
return SQLITE_NOMEM_BKPT;
@@ -58993,10 +58991,11 @@
5899358991
s1 = s2 = 0;
5899458992
}
5899558993
5899658994
assert( nByte>=8 );
5899758995
assert( (nByte&0x00000007)==0 );
58996
+ assert( nByte<=65536 );
5899858997
5899958998
if( nativeCksum ){
5900058999
do {
5900159000
s1 += *aData++ + s2;
5900259001
s2 += *aData++ + s1;
@@ -59930,11 +59929,11 @@
5993059929
*/
5993159930
static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp){
5993259931
WalIterator *p; /* Return value */
5993359932
int nSegment; /* Number of segments to merge */
5993459933
u32 iLast; /* Last frame in log */
59935
- int nByte; /* Number of bytes to allocate */
59934
+ sqlite3_int64 nByte; /* Number of bytes to allocate */
5993659935
int i; /* Iterator variable */
5993759936
ht_slot *aTmp; /* Temp space used by merge-sort */
5993859937
int rc = SQLITE_OK; /* Return Code */
5993959938
5994059939
/* This routine only runs while holding the checkpoint lock. And
@@ -76469,13 +76468,15 @@
7646976468
** during testing only. With SQLITE_TEST_REALLOC_STRESS grow the op array
7647076469
** by the minimum* amount required until the size reaches 512. Normal
7647176470
** operation (without SQLITE_TEST_REALLOC_STRESS) is to double the current
7647276471
** size of the op array or add 1KB of space, whichever is smaller. */
7647376472
#ifdef SQLITE_TEST_REALLOC_STRESS
76474
- int nNew = (v->nOpAlloc>=512 ? v->nOpAlloc*2 : v->nOpAlloc+nOp);
76473
+ sqlite3_int64 nNew = (v->nOpAlloc>=512 ? 2*(sqlite3_int64)v->nOpAlloc
76474
+ : (sqlite3_int64)v->nOpAlloc+nOp);
7647576475
#else
76476
- int nNew = (v->nOpAlloc ? v->nOpAlloc*2 : (int)(1024/sizeof(Op)));
76476
+ sqlite3_int64 nNew = (v->nOpAlloc ? 2*(sqlite3_int64)v->nOpAlloc
76477
+ : (sqlite3_int64)(1024/sizeof(Op)));
7647776478
UNUSED_PARAMETER(nOp);
7647876479
#endif
7647976480
7648076481
/* Ensure that the size of a VDBE does not grow too large */
7648176482
if( nNew > p->db->aLimit[SQLITE_LIMIT_VDBE_OP] ){
@@ -77259,11 +77260,11 @@
7725977260
int addrLoop, /* Address of loop counter */
7726077261
int addrVisit, /* Address of rows visited counter */
7726177262
LogEst nEst, /* Estimated number of output rows */
7726277263
const char *zName /* Name of table or index being scanned */
7726377264
){
77264
- int nByte = (p->nScan+1) * sizeof(ScanStatus);
77265
+ sqlite3_int64 nByte = (p->nScan+1) * sizeof(ScanStatus);
7726577266
ScanStatus *aNew;
7726677267
aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
7726777268
if( aNew ){
7726877269
ScanStatus *pNew = &aNew[p->nScan++];
7726977270
pNew->addrExplain = addrExplain;
@@ -78380,13 +78381,13 @@
7838078381
/* An instance of this object describes bulk memory available for use
7838178382
** by subcomponents of a prepared statement. Space is allocated out
7838278383
** of a ReusableSpace object by the allocSpace() routine below.
7838378384
*/
7838478385
struct ReusableSpace {
78385
- u8 *pSpace; /* Available memory */
78386
- int nFree; /* Bytes of available memory */
78387
- int nNeeded; /* Total bytes that could not be allocated */
78386
+ u8 *pSpace; /* Available memory */
78387
+ sqlite3_int64 nFree; /* Bytes of available memory */
78388
+ sqlite3_int64 nNeeded; /* Total bytes that could not be allocated */
7838878389
};
7838978390
7839078391
/* Try to allocate nByte bytes of 8-byte aligned bulk memory for pBuf
7839178392
** from the ReusableSpace object. Return a pointer to the allocated
7839278393
** memory on success. If insufficient memory is available in the
@@ -78402,11 +78403,11 @@
7840278403
** statement.
7840378404
*/
7840478405
static void *allocSpace(
7840578406
struct ReusableSpace *p, /* Bulk memory available for allocation */
7840678407
void *pBuf, /* Pointer to a prior allocation */
78407
- int nByte /* Bytes of memory needed */
78408
+ sqlite3_int64 nByte /* Bytes of memory needed */
7840878409
){
7840978410
assert( EIGHT_BYTE_ALIGNMENT(p->pSpace) );
7841078411
if( pBuf==0 ){
7841178412
nByte = ROUND8(nByte);
7841278413
if( nByte <= p->nFree ){
@@ -81359,11 +81360,11 @@
8135981360
assert( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0 );
8136081361
assert( db->init.busy==0 );
8136181362
assert( p->zSql!=0 );
8136281363
sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
8136381364
iElapse = (iNow - p->startTime)*1000000;
81364
-#ifndef SQLITE_OMIT_DEPRECATED
81365
+#ifndef SQLITE_OMIT_DEPRECATED
8136581366
if( db->xProfile ){
8136681367
db->xProfile(db->pProfileArg, p->zSql, iElapse);
8136781368
}
8136881369
#endif
8136981370
if( db->mTrace & SQLITE_TRACE_PROFILE ){
@@ -92255,11 +92256,11 @@
9225592256
int nRem; /* Bytes remaining to copy */
9225692257
9225792258
/* Extend the p->aAlloc[] allocation if required. */
9225892259
if( p->nAlloc<nByte ){
9225992260
u8 *aNew;
92260
- int nNew = MAX(128, p->nAlloc*2);
92261
+ sqlite3_int64 nNew = MAX(128, 2*(sqlite3_int64)p->nAlloc);
9226192262
while( nByte>nNew ) nNew = nNew*2;
9226292263
aNew = sqlite3Realloc(p->aAlloc, nNew);
9226392264
if( !aNew ) return SQLITE_NOMEM_BKPT;
9226492265
p->nAlloc = nNew;
9226592266
p->aAlloc = aNew;
@@ -93546,19 +93547,23 @@
9354693547
if( pSorter->list.aMemory ){
9354793548
int nMin = pSorter->iMemory + nReq;
9354893549
9354993550
if( nMin>pSorter->nMemory ){
9355093551
u8 *aNew;
93551
- int iListOff = (u8*)pSorter->list.pList - pSorter->list.aMemory;
93552
- int nNew = pSorter->nMemory * 2;
93552
+ sqlite3_int64 nNew = 2 * (sqlite3_int64)pSorter->nMemory;
93553
+ int iListOff = -1;
93554
+ if( pSorter->list.pList ){
93555
+ iListOff = (u8*)pSorter->list.pList - pSorter->list.aMemory;
93556
+ }
9355393557
while( nNew < nMin ) nNew = nNew*2;
9355493558
if( nNew > pSorter->mxPmaSize ) nNew = pSorter->mxPmaSize;
9355593559
if( nNew < nMin ) nNew = nMin;
93556
-
9355793560
aNew = sqlite3Realloc(pSorter->list.aMemory, nNew);
9355893561
if( !aNew ) return SQLITE_NOMEM_BKPT;
93559
- pSorter->list.pList = (SorterRecord*)&aNew[iListOff];
93562
+ if( iListOff>=0 ){
93563
+ pSorter->list.pList = (SorterRecord*)&aNew[iListOff];
93564
+ }
9356093565
pSorter->list.aMemory = aNew;
9356193566
pSorter->nMemory = nNew;
9356293567
}
9356393568
9356493569
pNew = (SorterRecord*)&pSorter->list.aMemory[pSorter->iMemory];
@@ -98204,11 +98209,11 @@
9820498209
*/
9820598210
#ifndef SQLITE_OMIT_CTE
9820698211
static With *withDup(sqlite3 *db, With *p){
9820798212
With *pRet = 0;
9820898213
if( p ){
98209
- int nByte = sizeof(*p) + sizeof(p->a[0]) * (p->nCte-1);
98214
+ sqlite3_int64 nByte = sizeof(*p) + sizeof(p->a[0]) * (p->nCte-1);
9821098215
pRet = sqlite3DbMallocZero(db, nByte);
9821198216
if( pRet ){
9821298217
int i;
9821398218
pRet->nCte = p->nCte;
9821498219
for(i=0; i<p->nCte; i++){
@@ -98469,11 +98474,11 @@
9846998474
}
9847098475
pList->nExpr = 0;
9847198476
}else if( (pList->nExpr & (pList->nExpr-1))==0 ){
9847298477
ExprList *pNew;
9847398478
pNew = sqlite3DbRealloc(db, pList,
98474
- sizeof(*pList)+(2*pList->nExpr - 1)*sizeof(pList->a[0]));
98479
+ sizeof(*pList)+(2*(sqlite3_int64)pList->nExpr-1)*sizeof(pList->a[0]));
9847598480
if( pNew==0 ){
9847698481
goto no_mem;
9847798482
}
9847898483
pList = pNew;
9847998484
}
@@ -106165,11 +106170,11 @@
106165106170
}
106166106171
sqlite3BtreeLeaveAll(db);
106167106172
assert( zErrDyn==0 || rc!=SQLITE_OK );
106168106173
}
106169106174
#ifdef SQLITE_USER_AUTHENTICATION
106170
- if( rc==SQLITE_OK ){
106175
+ if( rc==SQLITE_OK && !REOPEN_AS_MEMDB(db) ){
106171106176
u8 newAuth = 0;
106172106177
rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth);
106173106178
if( newAuth<db->auth.authLevel ){
106174106179
rc = SQLITE_AUTH_USER;
106175106180
}
@@ -110602,23 +110607,22 @@
110602110607
int szEntry, /* Size of each object in the array */
110603110608
int *pnEntry, /* Number of objects currently in use */
110604110609
int *pIdx /* Write the index of a new slot here */
110605110610
){
110606110611
char *z;
110607
- int n = *pnEntry;
110612
+ sqlite3_int64 n = *pIdx = *pnEntry;
110608110613
if( (n & (n-1))==0 ){
110609
- int sz = (n==0) ? 1 : 2*n;
110614
+ sqlite3_int64 sz = (n==0) ? 1 : 2*n;
110610110615
void *pNew = sqlite3DbRealloc(db, pArray, sz*szEntry);
110611110616
if( pNew==0 ){
110612110617
*pIdx = -1;
110613110618
return pArray;
110614110619
}
110615110620
pArray = pNew;
110616110621
}
110617110622
z = (char*)pArray;
110618110623
memset(&z[n * szEntry], 0, szEntry);
110619
- *pIdx = n;
110620110624
++*pnEntry;
110621110625
return pArray;
110622110626
}
110623110627
110624110628
/*
@@ -110725,11 +110729,11 @@
110725110729
assert( iStart<=pSrc->nSrc );
110726110730
110727110731
/* Allocate additional space if needed */
110728110732
if( (u32)pSrc->nSrc+nExtra>pSrc->nAlloc ){
110729110733
SrcList *pNew;
110730
- int nAlloc = pSrc->nSrc*2+nExtra;
110734
+ sqlite3_int64 nAlloc = 2*(sqlite3_int64)pSrc->nSrc+nExtra;
110731110735
sqlite3 *db = pParse->db;
110732110736
110733110737
if( pSrc->nSrc+nExtra>=SQLITE_MAX_SRCLIST ){
110734110738
sqlite3ErrorMsg(pParse, "too many FROM clause terms, max: %d",
110735110739
SQLITE_MAX_SRCLIST);
@@ -111482,11 +111486,11 @@
111482111486
}
111483111487
}
111484111488
}
111485111489
111486111490
if( pWith ){
111487
- int nByte = sizeof(*pWith) + (sizeof(pWith->a[1]) * pWith->nCte);
111491
+ sqlite3_int64 nByte = sizeof(*pWith) + (sizeof(pWith->a[1]) * pWith->nCte);
111488111492
pNew = sqlite3DbRealloc(db, pWith, nByte);
111489111493
}else{
111490111494
pNew = sqlite3DbMallocZero(db, sizeof(*pWith));
111491111495
}
111492111496
assert( (pNew!=0 && zName!=0) || db->mallocFailed );
@@ -134593,13 +134597,17 @@
134593134597
** Add a new module argument to pTable->azModuleArg[].
134594134598
** The string is not copied - the pointer is stored. The
134595134599
** string will be freed automatically when the table is
134596134600
** deleted.
134597134601
*/
134598
-static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
134599
- int nBytes = sizeof(char *)*(2+pTable->nModuleArg);
134602
+static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){
134603
+ sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->nModuleArg);
134600134604
char **azModuleArg;
134605
+ sqlite3 *db = pParse->db;
134606
+ if( pTable->nModuleArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){
134607
+ sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName);
134608
+ }
134601134609
azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
134602134610
if( azModuleArg==0 ){
134603134611
sqlite3DbFree(db, zArg);
134604134612
}else{
134605134613
int i = pTable->nModuleArg++;
@@ -134630,13 +134638,13 @@
134630134638
assert( 0==pTable->pIndex );
134631134639
134632134640
db = pParse->db;
134633134641
134634134642
assert( pTable->nModuleArg==0 );
134635
- addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName));
134636
- addModuleArgument(db, pTable, 0);
134637
- addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName));
134643
+ addModuleArgument(pParse, pTable, sqlite3NameFromToken(db, pModuleName));
134644
+ addModuleArgument(pParse, pTable, 0);
134645
+ addModuleArgument(pParse, pTable, sqlite3DbStrDup(db, pTable->zName));
134638134646
assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0)
134639134647
|| (pParse->sNameToken.z==pName1->z && pName2->z==0)
134640134648
);
134641134649
pParse->sNameToken.n = (int)(
134642134650
&pModuleName->z[pModuleName->n] - pParse->sNameToken.z
@@ -134665,11 +134673,11 @@
134665134673
static void addArgumentToVtab(Parse *pParse){
134666134674
if( pParse->sArg.z && pParse->pNewTable ){
134667134675
const char *z = (const char*)pParse->sArg.z;
134668134676
int n = pParse->sArg.n;
134669134677
sqlite3 *db = pParse->db;
134670
- addModuleArgument(db, pParse->pNewTable, sqlite3DbStrNDup(db, z, n));
134678
+ addModuleArgument(pParse, pParse->pNewTable, sqlite3DbStrNDup(db, z, n));
134671134679
}
134672134680
}
134673134681
134674134682
/*
134675134683
** The parser calls this routine after the CREATE VIRTUAL TABLE statement
@@ -134954,11 +134962,12 @@
134954134962
const int ARRAY_INCR = 5;
134955134963
134956134964
/* Grow the sqlite3.aVTrans array if required */
134957134965
if( (db->nVTrans%ARRAY_INCR)==0 ){
134958134966
VTable **aVTrans;
134959
- int nBytes = sizeof(sqlite3_vtab *) * (db->nVTrans + ARRAY_INCR);
134967
+ sqlite3_int64 nBytes = sizeof(sqlite3_vtab*)*
134968
+ ((sqlite3_int64)db->nVTrans + ARRAY_INCR);
134960134969
aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes);
134961134970
if( !aVTrans ){
134962134971
return SQLITE_NOMEM_BKPT;
134963134972
}
134964134973
memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
@@ -135450,13 +135459,13 @@
135450135459
pMod->pEpoTab = pTab;
135451135460
pTab->nTabRef = 1;
135452135461
pTab->pSchema = db->aDb[0].pSchema;
135453135462
assert( pTab->nModuleArg==0 );
135454135463
pTab->iPKey = -1;
135455
- addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
135456
- addModuleArgument(db, pTab, 0);
135457
- addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
135464
+ addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
135465
+ addModuleArgument(pParse, pTab, 0);
135466
+ addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
135458135467
rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
135459135468
if( rc ){
135460135469
sqlite3ErrorMsg(pParse, "%s", zErr);
135461135470
sqlite3DbFree(db, zErr);
135462135471
sqlite3VtabEponymousTableClear(db, pMod);
@@ -155309,11 +155318,11 @@
155309155318
if( sz==0 || cnt==0 ){
155310155319
sz = 0;
155311155320
pStart = 0;
155312155321
}else if( pBuf==0 ){
155313155322
sqlite3BeginBenignMalloc();
155314
- pStart = sqlite3Malloc( sz*cnt ); /* IMP: R-61949-35727 */
155323
+ pStart = sqlite3Malloc( sz*(sqlite3_int64)cnt ); /* IMP: R-61949-35727 */
155315155324
sqlite3EndBenignMalloc();
155316155325
if( pStart ) cnt = sqlite3MallocSize(pStart)/sz;
155317155326
}else{
155318155327
pStart = pBuf;
155319155328
}
@@ -169347,12 +169356,12 @@
169347169356
}else{
169348169357
char const **aArg = 0;
169349169358
int iArg = 0;
169350169359
z = &z[n+1];
169351169360
while( z<zEnd && (NULL!=(z = (char *)sqlite3Fts3NextToken(z, &n))) ){
169352
- int nNew = sizeof(char *)*(iArg+1);
169353
- char const **aNew = (const char **)sqlite3_realloc((void *)aArg, nNew);
169361
+ sqlite3_int64 nNew = sizeof(char *)*(iArg+1);
169362
+ char const **aNew = (const char **)sqlite3_realloc64((void *)aArg, nNew);
169354169363
if( !aNew ){
169355169364
sqlite3_free(zCopy);
169356169365
sqlite3_free((void *)aArg);
169357169366
return SQLITE_NOMEM;
169358169367
}
@@ -170255,11 +170264,11 @@
170255170264
170256170265
fts3tokResetCursor(pCsr);
170257170266
if( idxNum==1 ){
170258170267
const char *zByte = (const char *)sqlite3_value_text(apVal[0]);
170259170268
int nByte = sqlite3_value_bytes(apVal[0]);
170260
- pCsr->zInput = sqlite3_malloc(nByte+1);
170269
+ pCsr->zInput = sqlite3_malloc64(nByte+1);
170261170270
if( pCsr->zInput==0 ){
170262170271
rc = SQLITE_NOMEM;
170263170272
}else{
170264170273
memcpy(pCsr->zInput, zByte, nByte);
170265170274
pCsr->zInput[nByte] = 0;
@@ -172119,12 +172128,13 @@
172119172128
nElem = 1;
172120172129
}
172121172130
}
172122172131
172123172132
if( nElem>0 ){
172124
- int nByte = sizeof(Fts3SegReader) + (nElem+1)*sizeof(Fts3HashElem *);
172125
- pReader = (Fts3SegReader *)sqlite3_malloc(nByte);
172133
+ sqlite3_int64 nByte;
172134
+ nByte = sizeof(Fts3SegReader) + (nElem+1)*sizeof(Fts3HashElem *);
172135
+ pReader = (Fts3SegReader *)sqlite3_malloc64(nByte);
172126172136
if( !pReader ){
172127172137
rc = SQLITE_NOMEM;
172128172138
}else{
172129172139
memset(pReader, 0, nByte);
172130172140
pReader->iIdx = 0x7FFFFFFF;
@@ -173734,11 +173744,11 @@
173734173744
int nBlob; /* Number of bytes in the BLOB */
173735173745
sqlite3_stmt *pStmt; /* Statement used to insert the encoding */
173736173746
int rc; /* Result code from subfunctions */
173737173747
173738173748
if( *pRC ) return;
173739
- pBlob = sqlite3_malloc( 10*p->nColumn );
173749
+ pBlob = sqlite3_malloc64( 10*(sqlite3_int64)p->nColumn );
173740173750
if( pBlob==0 ){
173741173751
*pRC = SQLITE_NOMEM;
173742173752
return;
173743173753
}
173744173754
fts3EncodeIntArray(p->nColumn, aSz, pBlob, &nBlob);
@@ -173784,11 +173794,11 @@
173784173794
int rc; /* Result code from subfunctions */
173785173795
173786173796
const int nStat = p->nColumn+2;
173787173797
173788173798
if( *pRC ) return;
173789
- a = sqlite3_malloc( (sizeof(u32)+10)*nStat );
173799
+ a = sqlite3_malloc64( (sizeof(u32)+10)*(sqlite3_int64)nStat );
173790173800
if( a==0 ){
173791173801
*pRC = SQLITE_NOMEM;
173792173802
return;
173793173803
}
173794173804
pBlob = (char*)&a[nStat];
@@ -173905,12 +173915,12 @@
173905173915
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
173906173916
sqlite3_free(zSql);
173907173917
}
173908173918
173909173919
if( rc==SQLITE_OK ){
173910
- int nByte = sizeof(u32) * (p->nColumn+1)*3;
173911
- aSz = (u32 *)sqlite3_malloc(nByte);
173920
+ sqlite3_int64 nByte = sizeof(u32) * ((sqlite3_int64)p->nColumn+1)*3;
173921
+ aSz = (u32 *)sqlite3_malloc64(nByte);
173912173922
if( aSz==0 ){
173913173923
rc = SQLITE_NOMEM;
173914173924
}else{
173915173925
memset(aSz, 0, nByte);
173916173926
aSzIns = &aSz[p->nColumn+1];
@@ -173972,16 +173982,16 @@
173972173982
int nSeg, /* Number of segments to merge */
173973173983
Fts3MultiSegReader *pCsr /* Cursor object to populate */
173974173984
){
173975173985
int rc; /* Return Code */
173976173986
sqlite3_stmt *pStmt = 0; /* Statement used to read %_segdir entry */
173977
- int nByte; /* Bytes allocated at pCsr->apSegment[] */
173987
+ sqlite3_int64 nByte; /* Bytes allocated at pCsr->apSegment[] */
173978173988
173979173989
/* Allocate space for the Fts3MultiSegReader.aCsr[] array */
173980173990
memset(pCsr, 0, sizeof(*pCsr));
173981173991
nByte = sizeof(Fts3SegReader *) * nSeg;
173982
- pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc(nByte);
173992
+ pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc64(nByte);
173983173993
173984173994
if( pCsr->apSegment==0 ){
173985173995
rc = SQLITE_NOMEM;
173986173996
}else{
173987173997
memset(pCsr->apSegment, 0, nByte);
@@ -175957,11 +175967,11 @@
175957175967
rc = SQLITE_CONSTRAINT;
175958175968
goto update_out;
175959175969
}
175960175970
175961175971
/* Allocate space to hold the change in document sizes */
175962
- aSzDel = sqlite3_malloc( sizeof(aSzDel[0])*(p->nColumn+1)*2 );
175972
+ aSzDel = sqlite3_malloc64(sizeof(aSzDel[0])*((sqlite3_int64)p->nColumn+1)*2);
175963175973
if( aSzDel==0 ){
175964175974
rc = SQLITE_NOMEM;
175965175975
goto update_out;
175966175976
}
175967175977
aSzIns = &aSzDel[p->nColumn+1];
@@ -176211,21 +176221,23 @@
176211176221
*/
176212176222
176213176223
/*
176214176224
** Allocate a two-slot MatchinfoBuffer object.
176215176225
*/
176216
-static MatchinfoBuffer *fts3MIBufferNew(int nElem, const char *zMatchinfo){
176226
+static MatchinfoBuffer *fts3MIBufferNew(size_t nElem, const char *zMatchinfo){
176217176227
MatchinfoBuffer *pRet;
176218
- int nByte = sizeof(u32) * (2*nElem + 1) + sizeof(MatchinfoBuffer);
176219
- int nStr = (int)strlen(zMatchinfo);
176228
+ sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1)
176229
+ + sizeof(MatchinfoBuffer);
176230
+ sqlite3_int64 nStr = strlen(zMatchinfo);
176220176231
176221
- pRet = sqlite3_malloc(nByte + nStr+1);
176232
+ pRet = sqlite3_malloc64(nByte + nStr+1);
176222176233
if( pRet ){
176223176234
memset(pRet, 0, nByte);
176224176235
pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet;
176225
- pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0] + sizeof(u32)*(nElem+1);
176226
- pRet->nElem = nElem;
176236
+ pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0]
176237
+ + sizeof(u32)*((int)nElem+1);
176238
+ pRet->nElem = (int)nElem;
176227176239
pRet->zMatchinfo = ((char*)pRet) + nByte;
176228176240
memcpy(pRet->zMatchinfo, zMatchinfo, nStr+1);
176229176241
pRet->aRef[0] = 1;
176230176242
}
176231176243
@@ -177082,12 +177094,12 @@
177082177094
}
177083177095
sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg);
177084177096
return SQLITE_ERROR;
177085177097
}
177086177098
177087
-static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
177088
- int nVal; /* Number of integers output by cArg */
177099
+static size_t fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
177100
+ size_t nVal; /* Number of integers output by cArg */
177089177101
177090177102
switch( cArg ){
177091177103
case FTS3_MATCHINFO_NDOC:
177092177104
case FTS3_MATCHINFO_NPHRASE:
177093177105
case FTS3_MATCHINFO_NCOL:
@@ -177367,11 +177379,11 @@
177367177379
}
177368177380
break;
177369177381
177370177382
case FTS3_MATCHINFO_LHITS_BM:
177371177383
case FTS3_MATCHINFO_LHITS: {
177372
- int nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
177384
+ size_t nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
177373177385
memset(pInfo->aMatchinfo, 0, nZero);
177374177386
rc = fts3ExprLHitGather(pCsr->pExpr, pInfo);
177375177387
break;
177376177388
}
177377177389
@@ -177436,11 +177448,11 @@
177436177448
** matchinfo function has been called for this query. In this case
177437177449
** allocate the array used to accumulate the matchinfo data and
177438177450
** initialize those elements that are constant for every row.
177439177451
*/
177440177452
if( pCsr->pMIBuffer==0 ){
177441
- int nMatchinfo = 0; /* Number of u32 elements in match-info */
177453
+ size_t nMatchinfo = 0; /* Number of u32 elements in match-info */
177442177454
int i; /* Used to iterate through zArg */
177443177455
177444177456
/* Determine the number of phrases in the query */
177445177457
pCsr->nPhrase = fts3ExprPhraseCount(pCsr->pExpr);
177446177458
sInfo.nPhrase = pCsr->nPhrase;
@@ -185697,11 +185709,11 @@
185697185709
&& (s.z++, geopolySkipSpace(&s)==0)
185698185710
){
185699185711
GeoPoly *pOut;
185700185712
int x = 1;
185701185713
s.nVertex--; /* Remove the redundant vertex at the end */
185702
- pOut = sqlite3_malloc64( GEOPOLY_SZ(s.nVertex) );
185714
+ pOut = sqlite3_malloc64( GEOPOLY_SZ((sqlite3_int64)s.nVertex) );
185703185715
x = 1;
185704185716
if( pOut==0 ) goto parse_json_err;
185705185717
pOut->nVertex = s.nVertex;
185706185718
memcpy(pOut->a, s.a, s.nVertex*2*sizeof(GeoCoord));
185707185719
pOut->hdr[0] = *(unsigned char*)&x;
@@ -186083,11 +186095,11 @@
186083186095
else if( r>mxY ) mxY = (float)r;
186084186096
}
186085186097
if( pRc ) *pRc = SQLITE_OK;
186086186098
if( aCoord==0 ){
186087186099
geopolyBboxFill:
186088
- pOut = sqlite3_realloc(p, GEOPOLY_SZ(4));
186100
+ pOut = sqlite3_realloc64(p, GEOPOLY_SZ(4));
186089186101
if( pOut==0 ){
186090186102
sqlite3_free(p);
186091186103
if( context ) sqlite3_result_error_nomem(context);
186092186104
if( pRc ) *pRc = SQLITE_NOMEM;
186093186105
return 0;
@@ -186479,13 +186491,13 @@
186479186491
186480186492
/*
186481186493
** Determine the overlap between two polygons
186482186494
*/
186483186495
static int geopolyOverlap(GeoPoly *p1, GeoPoly *p2){
186484
- int nVertex = p1->nVertex + p2->nVertex + 2;
186496
+ sqlite3_int64 nVertex = p1->nVertex + p2->nVertex + 2;
186485186497
GeoOverlap *p;
186486
- int nByte;
186498
+ sqlite3_int64 nByte;
186487186499
GeoEvent *pThisEvent;
186488186500
double rX;
186489186501
int rc = 0;
186490186502
int needSort = 0;
186491186503
GeoSegment *pActive = 0;
@@ -186493,11 +186505,11 @@
186493186505
unsigned char aOverlap[4];
186494186506
186495186507
nByte = sizeof(GeoEvent)*nVertex*2
186496186508
+ sizeof(GeoSegment)*nVertex
186497186509
+ sizeof(GeoOverlap);
186498
- p = sqlite3_malloc( nByte );
186510
+ p = sqlite3_malloc64( nByte );
186499186511
if( p==0 ) return -1;
186500186512
p->aEvent = (GeoEvent*)&p[1];
186501186513
p->aSegment = (GeoSegment*)&p->aEvent[nVertex*2];
186502186514
p->nEvent = p->nSegment = 0;
186503186515
geopolyAddSegments(p, p1, 1);
@@ -186652,22 +186664,22 @@
186652186664
char **pzErr, /* OUT: Error message, if any */
186653186665
int isCreate /* True for xCreate, false for xConnect */
186654186666
){
186655186667
int rc = SQLITE_OK;
186656186668
Rtree *pRtree;
186657
- int nDb; /* Length of string argv[1] */
186658
- int nName; /* Length of string argv[2] */
186669
+ sqlite3_int64 nDb; /* Length of string argv[1] */
186670
+ sqlite3_int64 nName; /* Length of string argv[2] */
186659186671
sqlite3_str *pSql;
186660186672
char *zSql;
186661186673
int ii;
186662186674
186663186675
sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
186664186676
186665186677
/* Allocate the sqlite3_vtab structure */
186666
- nDb = (int)strlen(argv[1]);
186667
- nName = (int)strlen(argv[2]);
186668
- pRtree = (Rtree *)sqlite3_malloc(sizeof(Rtree)+nDb+nName+2);
186678
+ nDb = strlen(argv[1]);
186679
+ nName = strlen(argv[2]);
186680
+ pRtree = (Rtree *)sqlite3_malloc64(sizeof(Rtree)+nDb+nName+2);
186669186681
if( !pRtree ){
186670186682
return SQLITE_NOMEM;
186671186683
}
186672186684
memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2);
186673186685
pRtree->nBusy = 1;
@@ -189088,10 +189100,15 @@
189088189100
** abIndexed:
189089189101
** If the table has no indexes on it, abIndexed is set to NULL. Otherwise,
189090189102
** it points to an array of flags nTblCol elements in size. The flag is
189091189103
** set for each column that is either a part of the PK or a part of an
189092189104
** index. Or clear otherwise.
189105
+**
189106
+** If there are one or more partial indexes on the table, all fields of
189107
+** this array set set to 1. This is because in that case, the module has
189108
+** no way to tell which fields will be required to add and remove entries
189109
+** from the partial indexes.
189093189110
**
189094189111
*/
189095189112
struct RbuObjIter {
189096189113
sqlite3_stmt *pTblIter; /* Iterate through tables */
189097189114
sqlite3_stmt *pIdxIter; /* Index iterator */
@@ -189883,11 +189900,11 @@
189883189900
** error code in the rbu handle passed as the first argument. Or, if an
189884189901
** error has already occurred when this function is called, return NULL
189885189902
** immediately without attempting the allocation or modifying the stored
189886189903
** error code.
189887189904
*/
189888
-static void *rbuMalloc(sqlite3rbu *p, int nByte){
189905
+static void *rbuMalloc(sqlite3rbu *p, sqlite3_int64 nByte){
189889189906
void *pRet = 0;
189890189907
if( p->rc==SQLITE_OK ){
189891189908
assert( nByte>0 );
189892189909
pRet = sqlite3_malloc64(nByte);
189893189910
if( pRet==0 ){
@@ -189904,11 +189921,11 @@
189904189921
** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that
189905189922
** there is room for at least nCol elements. If an OOM occurs, store an
189906189923
** error code in the RBU handle passed as the first argument.
189907189924
*/
189908189925
static void rbuAllocateIterArrays(sqlite3rbu *p, RbuObjIter *pIter, int nCol){
189909
- int nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol;
189926
+ sqlite3_int64 nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol;
189910189927
char **azNew;
189911189928
189912189929
azNew = (char**)rbuMalloc(p, nByte);
189913189930
if( azNew ){
189914189931
pIter->azTblCol = azNew;
@@ -190098,12 +190115,16 @@
190098190115
}
190099190116
190100190117
pIter->nIndex = 0;
190101190118
while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pList) ){
190102190119
const char *zIdx = (const char*)sqlite3_column_text(pList, 1);
190120
+ int bPartial = sqlite3_column_int(pList, 4);
190103190121
sqlite3_stmt *pXInfo = 0;
190104190122
if( zIdx==0 ) break;
190123
+ if( bPartial ){
190124
+ memset(pIter->abIndexed, 0x01, sizeof(u8)*pIter->nTblCol);
190125
+ }
190105190126
p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg,
190106190127
sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", zIdx)
190107190128
);
190108190129
while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
190109190130
int iCid = sqlite3_column_int(pXInfo, 1);
@@ -190544,11 +190565,11 @@
190544190565
** when this function is called, NULL is returned immediately, without
190545190566
** attempting the allocation or modifying the stored error code.
190546190567
*/
190547190568
static char *rbuObjIterGetBindlist(sqlite3rbu *p, int nBind){
190548190569
char *zRet = 0;
190549
- int nByte = nBind*2 + 1;
190570
+ sqlite3_int64 nByte = 2*(sqlite3_int64)nBind + 1;
190550190571
190551190572
zRet = (char*)rbuMalloc(p, nByte);
190552190573
if( zRet ){
190553190574
int i;
190554190575
for(i=0; i<nBind; i++){
@@ -190805,10 +190826,66 @@
190805190826
190806190827
if( rc!=SQLITE_OK ){
190807190828
sqlite3_result_error_code(pCtx, rc);
190808190829
}
190809190830
}
190831
+
190832
+static char *rbuObjIterGetIndexWhere(sqlite3rbu *p, RbuObjIter *pIter){
190833
+ sqlite3_stmt *pStmt = 0;
190834
+ int rc = p->rc;
190835
+ char *zRet = 0;
190836
+
190837
+ if( rc==SQLITE_OK ){
190838
+ rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
190839
+ "SELECT trim(sql) FROM sqlite_master WHERE type='index' AND name=?"
190840
+ );
190841
+ }
190842
+ if( rc==SQLITE_OK ){
190843
+ int rc2;
190844
+ rc = sqlite3_bind_text(pStmt, 1, pIter->zIdx, -1, SQLITE_STATIC);
190845
+ if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
190846
+ const char *zSql = (const char*)sqlite3_column_text(pStmt, 0);
190847
+ if( zSql ){
190848
+ int nParen = 0; /* Number of open parenthesis */
190849
+ int i;
190850
+ for(i=0; zSql[i]; i++){
190851
+ char c = zSql[i];
190852
+ if( c=='(' ){
190853
+ nParen++;
190854
+ }
190855
+ else if( c==')' ){
190856
+ nParen--;
190857
+ if( nParen==0 ){
190858
+ i++;
190859
+ break;
190860
+ }
190861
+ }else if( c=='"' || c=='\'' || c=='`' ){
190862
+ for(i++; 1; i++){
190863
+ if( zSql[i]==c ){
190864
+ if( zSql[i+1]!=c ) break;
190865
+ i++;
190866
+ }
190867
+ }
190868
+ }else if( c=='[' ){
190869
+ for(i++; 1; i++){
190870
+ if( zSql[i]==']' ) break;
190871
+ }
190872
+ }
190873
+ }
190874
+ if( zSql[i] ){
190875
+ zRet = rbuStrndup(&zSql[i], &rc);
190876
+ }
190877
+ }
190878
+ }
190879
+
190880
+ rc2 = sqlite3_finalize(pStmt);
190881
+ if( rc==SQLITE_OK ) rc = rc2;
190882
+ }
190883
+
190884
+ p->rc = rc;
190885
+ return zRet;
190886
+}
190810190887
190811190888
/*
190812190889
** Ensure that the SQLite statement handles required to update the
190813190890
** target database object currently indicated by the iterator passed
190814190891
** as the second argument are available.
@@ -190835,17 +190912,19 @@
190835190912
const char *zTbl = pIter->zTbl;
190836190913
char *zImposterCols = 0; /* Columns for imposter table */
190837190914
char *zImposterPK = 0; /* Primary key declaration for imposter */
190838190915
char *zWhere = 0; /* WHERE clause on PK columns */
190839190916
char *zBind = 0;
190917
+ char *zPart = 0;
190840190918
int nBind = 0;
190841190919
190842190920
assert( pIter->eType!=RBU_PK_VTAB );
190843190921
zCollist = rbuObjIterGetIndexCols(
190844190922
p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind
190845190923
);
190846190924
zBind = rbuObjIterGetBindlist(p, nBind);
190925
+ zPart = rbuObjIterGetIndexWhere(p, pIter);
190847190926
190848190927
/* Create the imposter table used to write to this index. */
190849190928
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
190850190929
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1,tnum);
190851190930
rbuMPrintfExec(p, p->dbMain,
@@ -190874,32 +190953,34 @@
190874190953
/* Create the SELECT statement to read keys in sorted order */
190875190954
if( p->rc==SQLITE_OK ){
190876190955
char *zSql;
190877190956
if( rbuIsVacuum(p) ){
190878190957
zSql = sqlite3_mprintf(
190879
- "SELECT %s, 0 AS rbu_control FROM '%q' ORDER BY %s%s",
190958
+ "SELECT %s, 0 AS rbu_control FROM '%q' %s ORDER BY %s%s",
190880190959
zCollist,
190881190960
pIter->zDataTbl,
190882
- zCollist, zLimit
190961
+ zPart, zCollist, zLimit
190883190962
);
190884190963
}else
190885190964
190886190965
if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
190887190966
zSql = sqlite3_mprintf(
190888
- "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s",
190967
+ "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s ORDER BY %s%s",
190889190968
zCollist, p->zStateDb, pIter->zDataTbl,
190890
- zCollist, zLimit
190969
+ zPart, zCollist, zLimit
190891190970
);
190892190971
}else{
190893190972
zSql = sqlite3_mprintf(
190894
- "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' "
190973
+ "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s "
190895190974
"UNION ALL "
190896190975
"SELECT %s, rbu_control FROM '%q' "
190897
- "WHERE typeof(rbu_control)='integer' AND rbu_control!=1 "
190976
+ "%s %s typeof(rbu_control)='integer' AND rbu_control!=1 "
190898190977
"ORDER BY %s%s",
190899
- zCollist, p->zStateDb, pIter->zDataTbl,
190978
+ zCollist, p->zStateDb, pIter->zDataTbl, zPart,
190900190979
zCollist, pIter->zDataTbl,
190980
+ zPart,
190981
+ (zPart ? "AND" : "WHERE"),
190901190982
zCollist, zLimit
190902190983
);
190903190984
}
190904190985
p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql);
190905190986
}
@@ -190906,10 +190987,11 @@
190906190987
190907190988
sqlite3_free(zImposterCols);
190908190989
sqlite3_free(zImposterPK);
190909190990
sqlite3_free(zWhere);
190910190991
sqlite3_free(zBind);
190992
+ sqlite3_free(zPart);
190911190993
}else{
190912190994
int bRbuRowid = (pIter->eType==RBU_PK_VTAB)
190913190995
||(pIter->eType==RBU_PK_NONE)
190914190996
||(pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p));
190915190997
const char *zTbl = pIter->zTbl; /* Table this step applies to */
@@ -193339,11 +193421,11 @@
193339193421
** rbu is in the RBU_STAGE_OAL state, use heap memory for *-shm space
193340193422
** instead of a file on disk. */
193341193423
assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
193342193424
if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){
193343193425
if( iRegion<=p->nShm ){
193344
- int nByte = (iRegion+1) * sizeof(char*);
193426
+ sqlite3_int64 nByte = (iRegion+1) * sizeof(char*);
193345193427
char **apNew = (char**)sqlite3_realloc64(p->apShm, nByte);
193346193428
if( apNew==0 ){
193347193429
rc = SQLITE_NOMEM;
193348193430
}else{
193349193431
memset(&apNew[p->nShm], 0, sizeof(char*) * (1 + iRegion - p->nShm));
@@ -195850,11 +195932,11 @@
195850195932
*/
195851195933
static int sessionGrowHash(int bPatchset, SessionTable *pTab){
195852195934
if( pTab->nChange==0 || pTab->nEntry>=(pTab->nChange/2) ){
195853195935
int i;
195854195936
SessionChange **apNew;
195855
- int nNew = (pTab->nChange ? pTab->nChange : 128) * 2;
195937
+ sqlite3_int64 nNew = 2*(sqlite3_int64)(pTab->nChange ? pTab->nChange : 128);
195856195938
195857195939
apNew = (SessionChange **)sqlite3_malloc64(sizeof(SessionChange *) * nNew);
195858195940
if( apNew==0 ){
195859195941
if( pTab->nChange==0 ){
195860195942
return SQLITE_ERROR;
@@ -196777,11 +196859,11 @@
196777196859
** If not, use sqlite3_realloc() to grow the buffer so that there is.
196778196860
**
196779196861
** If successful, return zero. Otherwise, if an OOM condition is encountered,
196780196862
** set *pRc to SQLITE_NOMEM and return non-zero.
196781196863
*/
196782
-static int sessionBufferGrow(SessionBuffer *p, int nByte, int *pRc){
196864
+static int sessionBufferGrow(SessionBuffer *p, size_t nByte, int *pRc){
196783196865
if( *pRc==SQLITE_OK && p->nAlloc-p->nBuf<nByte ){
196784196866
u8 *aNew;
196785196867
i64 nNew = p->nAlloc ? p->nAlloc : 128;
196786196868
do {
196787196869
nNew = nNew*2;
@@ -197895,11 +197977,11 @@
197895197977
rc = SQLITE_CORRUPT_BKPT;
197896197978
}
197897197979
}
197898197980
197899197981
if( rc==SQLITE_OK ){
197900
- int iPK = sizeof(sqlite3_value*)*p->nCol*2;
197982
+ size_t iPK = sizeof(sqlite3_value*)*p->nCol*2;
197901197983
memset(p->tblhdr.aBuf, 0, iPK);
197902197984
memcpy(&p->tblhdr.aBuf[iPK], &p->in.aData[p->in.iNext], nCopy);
197903197985
p->in.iNext += nCopy;
197904197986
}
197905197987
@@ -199199,11 +199281,11 @@
199199199281
SessionBuffer cons = pApply->constraints;
199200199282
memset(&pApply->constraints, 0, sizeof(SessionBuffer));
199201199283
199202199284
rc = sessionChangesetStart(&pIter2, 0, 0, cons.nBuf, cons.aBuf, 0);
199203199285
if( rc==SQLITE_OK ){
199204
- int nByte = 2*pApply->nCol*sizeof(sqlite3_value*);
199286
+ size_t nByte = 2*pApply->nCol*sizeof(sqlite3_value*);
199205199287
int rc2;
199206199288
pIter2->bPatchset = bPatchset;
199207199289
pIter2->zTab = (char*)zTab;
199208199290
pIter2->nCol = pApply->nCol;
199209199291
pIter2->abPK = pApply->abPK;
@@ -212488,11 +212570,11 @@
212488212570
pWriter->aDlidx, sizeof(Fts5DlidxWriter) * nLvl
212489212571
);
212490212572
if( aDlidx==0 ){
212491212573
p->rc = SQLITE_NOMEM;
212492212574
}else{
212493
- int nByte = sizeof(Fts5DlidxWriter) * (nLvl - pWriter->nDlidx);
212575
+ size_t nByte = sizeof(Fts5DlidxWriter) * (nLvl - pWriter->nDlidx);
212494212576
memset(&aDlidx[pWriter->nDlidx], 0, nByte);
212495212577
pWriter->aDlidx = aDlidx;
212496212578
pWriter->nDlidx = nLvl;
212497212579
}
212498212580
}
@@ -217839,18 +217921,18 @@
217839217921
){
217840217922
Fts5Global *pGlobal = (Fts5Global*)pApi;
217841217923
int rc = sqlite3_overload_function(pGlobal->db, zName, -1);
217842217924
if( rc==SQLITE_OK ){
217843217925
Fts5Auxiliary *pAux;
217844
- int nName; /* Size of zName in bytes, including \0 */
217845
- int nByte; /* Bytes of space to allocate */
217926
+ sqlite3_int64 nName; /* Size of zName in bytes, including \0 */
217927
+ sqlite3_int64 nByte; /* Bytes of space to allocate */
217846217928
217847
- nName = (int)strlen(zName) + 1;
217929
+ nName = strlen(zName) + 1;
217848217930
nByte = sizeof(Fts5Auxiliary) + nName;
217849
- pAux = (Fts5Auxiliary*)sqlite3_malloc(nByte);
217931
+ pAux = (Fts5Auxiliary*)sqlite3_malloc64(nByte);
217850217932
if( pAux ){
217851
- memset(pAux, 0, nByte);
217933
+ memset(pAux, 0, (size_t)nByte);
217852217934
pAux->zFunc = (char*)&pAux[1];
217853217935
memcpy(pAux->zFunc, zName, nName);
217854217936
pAux->pGlobal = pGlobal;
217855217937
pAux->pUserData = pUserData;
217856217938
pAux->xFunc = xFunc;
@@ -217876,19 +217958,19 @@
217876217958
fts5_tokenizer *pTokenizer, /* Tokenizer implementation */
217877217959
void(*xDestroy)(void*) /* Destructor for pUserData */
217878217960
){
217879217961
Fts5Global *pGlobal = (Fts5Global*)pApi;
217880217962
Fts5TokenizerModule *pNew;
217881
- int nName; /* Size of zName and its \0 terminator */
217882
- int nByte; /* Bytes of space to allocate */
217963
+ sqlite3_int64 nName; /* Size of zName and its \0 terminator */
217964
+ sqlite3_int64 nByte; /* Bytes of space to allocate */
217883217965
int rc = SQLITE_OK;
217884217966
217885
- nName = (int)strlen(zName) + 1;
217967
+ nName = strlen(zName) + 1;
217886217968
nByte = sizeof(Fts5TokenizerModule) + nName;
217887
- pNew = (Fts5TokenizerModule*)sqlite3_malloc(nByte);
217969
+ pNew = (Fts5TokenizerModule*)sqlite3_malloc64(nByte);
217888217970
if( pNew ){
217889
- memset(pNew, 0, nByte);
217971
+ memset(pNew, 0, (size_t)nByte);
217890217972
pNew->zName = (char*)&pNew[1];
217891217973
memcpy(pNew->zName, zName, nName);
217892217974
pNew->pUserData = pUserData;
217893217975
pNew->x = *pTokenizer;
217894217976
pNew->xDestroy = xDestroy;
@@ -218019,11 +218101,11 @@
218019218101
int nArg, /* Number of args */
218020218102
sqlite3_value **apUnused /* Function arguments */
218021218103
){
218022218104
assert( nArg==0 );
218023218105
UNUSED_PARAM2(nArg, apUnused);
218024
- sqlite3_result_text(pCtx, "fts5: 2019-04-10 18:29:40 f294cfc173c5653ef161dbff63b7838dbccdcad797f5163c49b3173f9f35ab0f", -1, SQLITE_TRANSIENT);
218106
+ sqlite3_result_text(pCtx, "fts5: 2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50", -1, SQLITE_TRANSIENT);
218025218107
}
218026218108
218027218109
/*
218028218110
** Return true if zName is the extension on one of the shadow tables used
218029218111
** by this module.
@@ -219664,11 +219746,11 @@
219664219746
int i;
219665219747
memset(p, 0, sizeof(Unicode61Tokenizer));
219666219748
219667219749
p->eRemoveDiacritic = FTS5_REMOVE_DIACRITICS_SIMPLE;
219668219750
p->nFold = 64;
219669
- p->aFold = sqlite3_malloc(p->nFold * sizeof(char));
219751
+ p->aFold = sqlite3_malloc64(p->nFold * sizeof(char));
219670219752
if( p->aFold==0 ){
219671219753
rc = SQLITE_NOMEM;
219672219754
}
219673219755
219674219756
/* Search for a "categories" argument */
@@ -222783,12 +222865,12 @@
222783222865
}
222784222866
#endif /* SQLITE_CORE */
222785222867
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
222786222868
222787222869
/************** End of stmt.c ************************************************/
222788
-#if __LINE__!=222788
222870
+#if __LINE__!=222870
222789222871
#undef SQLITE_SOURCE_ID
222790
-#define SQLITE_SOURCE_ID "2019-04-10 18:29:40 f294cfc173c5653ef161dbff63b7838dbccdcad797f5163c49b3173f9f35alt2"
222872
+#define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f8315alt2"
222791222873
#endif
222792222874
/* Return the source-id for this library */
222793222875
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
222794222876
/************************** End of sqlite3.c ******************************/
222795222877
--- 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.28.0"
1166 #define SQLITE_VERSION_NUMBER 3028000
1167 #define SQLITE_SOURCE_ID "2019-04-10 18:29:40 f294cfc173c5653ef161dbff63b7838dbccdcad797f5163c49b3173f9f35ab0f"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -13416,11 +13416,11 @@
13416 struct Hash {
13417 unsigned int htsize; /* Number of buckets in the hash table */
13418 unsigned int count; /* Number of entries in this table */
13419 HashElem *first; /* The first element of the array */
13420 struct _ht { /* the hash table */
13421 int count; /* Number of entries with this hash */
13422 HashElem *chain; /* Pointer to first entry with this hash */
13423 } *ht;
13424 };
13425
13426 /* Each element in the hash table is an instance of the following
@@ -29858,15 +29858,15 @@
29858 ** This routine transforms the internal text encoding used by pMem to
29859 ** desiredEnc. It is an error if the string is already of the desired
29860 ** encoding, or if *pMem does not contain a string value.
29861 */
29862 SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
29863 int len; /* Maximum length of output string in bytes */
29864 unsigned char *zOut; /* Output buffer */
29865 unsigned char *zIn; /* Input iterator */
29866 unsigned char *zTerm; /* End of input */
29867 unsigned char *z; /* Output iterator */
29868 unsigned int c;
29869
29870 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
29871 assert( pMem->flags&MEM_Str );
29872 assert( pMem->enc!=desiredEnc );
@@ -29911,18 +29911,18 @@
29911 ** translating a 2-byte character to a 4-byte UTF-8 character.
29912 ** A single byte is required for the output string
29913 ** nul-terminator.
29914 */
29915 pMem->n &= ~1;
29916 len = pMem->n * 2 + 1;
29917 }else{
29918 /* When converting from UTF-8 to UTF-16 the maximum growth is caused
29919 ** when a 1-byte UTF-8 character is translated into a 2-byte UTF-16
29920 ** character. Two bytes are required in the output buffer for the
29921 ** nul-terminator.
29922 */
29923 len = pMem->n * 2 + 2;
29924 }
29925
29926 /* Set zIn to point at the start of the input buffer and zTerm to point 1
29927 ** byte past the end.
29928 **
@@ -31790,11 +31790,11 @@
31790
31791 nInt = nName/4 + 3;
31792 assert( pIn==0 || pIn[0]>=3 ); /* Verify ok to add new elements */
31793 if( pIn==0 || pIn[1]+nInt > pIn[0] ){
31794 /* Enlarge the allocation */
31795 int nAlloc = (pIn ? pIn[0]*2 : 10) + nInt;
31796 VList *pOut = sqlite3DbRealloc(db, pIn, nAlloc*sizeof(int));
31797 if( pOut==0 ) return pIn;
31798 if( pIn==0 ) pOut[1] = 2;
31799 pIn = pOut;
31800 pIn[0] = nAlloc;
@@ -31996,11 +31996,11 @@
31996 const Hash *pH, /* The pH to be searched */
31997 const char *pKey, /* The key we are searching for */
31998 unsigned int *pHash /* Write the hash value here */
31999 ){
32000 HashElem *elem; /* Used to loop thru the element list */
32001 int count; /* Number of elements left to test */
32002 unsigned int h; /* The computed hash */
32003 static HashElem nullElement = { 0, 0, 0, 0 };
32004
32005 if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/
32006 struct _ht *pEntry;
@@ -32044,12 +32044,12 @@
32044 if( pH->ht ){
32045 pEntry = &pH->ht[h];
32046 if( pEntry->chain==elem ){
32047 pEntry->chain = elem->next;
32048 }
 
32049 pEntry->count--;
32050 assert( pEntry->count>=0 );
32051 }
32052 sqlite3_free( elem );
32053 pH->count--;
32054 if( pH->count==0 ){
32055 assert( pH->first==0 );
@@ -49129,13 +49129,11 @@
49129 ** Malloc function used by SQLite to obtain space from the buffer configured
49130 ** using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no such buffer
49131 ** exists, this function falls back to sqlite3Malloc().
49132 */
49133 SQLITE_PRIVATE void *sqlite3PageMalloc(int sz){
49134 /* During rebalance operations on a corrupt database file, it is sometimes
49135 ** (rarely) possible to overread the temporary page buffer by a few bytes.
49136 ** Enlarge the allocation slightly so that this does not cause problems. */
49137 return pcache1Alloc(sz);
49138 }
49139
49140 /*
49141 ** Free an allocated buffer obtained from sqlite3PageMalloc().
@@ -58889,11 +58887,11 @@
58889 ){
58890 int rc = SQLITE_OK;
58891
58892 /* Enlarge the pWal->apWiData[] array if required */
58893 if( pWal->nWiData<=iPage ){
58894 int nByte = sizeof(u32*)*(iPage+1);
58895 volatile u32 **apNew;
58896 apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte);
58897 if( !apNew ){
58898 *ppPage = 0;
58899 return SQLITE_NOMEM_BKPT;
@@ -58993,10 +58991,11 @@
58993 s1 = s2 = 0;
58994 }
58995
58996 assert( nByte>=8 );
58997 assert( (nByte&0x00000007)==0 );
 
58998
58999 if( nativeCksum ){
59000 do {
59001 s1 += *aData++ + s2;
59002 s2 += *aData++ + s1;
@@ -59930,11 +59929,11 @@
59930 */
59931 static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp){
59932 WalIterator *p; /* Return value */
59933 int nSegment; /* Number of segments to merge */
59934 u32 iLast; /* Last frame in log */
59935 int nByte; /* Number of bytes to allocate */
59936 int i; /* Iterator variable */
59937 ht_slot *aTmp; /* Temp space used by merge-sort */
59938 int rc = SQLITE_OK; /* Return Code */
59939
59940 /* This routine only runs while holding the checkpoint lock. And
@@ -76469,13 +76468,15 @@
76469 ** during testing only. With SQLITE_TEST_REALLOC_STRESS grow the op array
76470 ** by the minimum* amount required until the size reaches 512. Normal
76471 ** operation (without SQLITE_TEST_REALLOC_STRESS) is to double the current
76472 ** size of the op array or add 1KB of space, whichever is smaller. */
76473 #ifdef SQLITE_TEST_REALLOC_STRESS
76474 int nNew = (v->nOpAlloc>=512 ? v->nOpAlloc*2 : v->nOpAlloc+nOp);
 
76475 #else
76476 int nNew = (v->nOpAlloc ? v->nOpAlloc*2 : (int)(1024/sizeof(Op)));
 
76477 UNUSED_PARAMETER(nOp);
76478 #endif
76479
76480 /* Ensure that the size of a VDBE does not grow too large */
76481 if( nNew > p->db->aLimit[SQLITE_LIMIT_VDBE_OP] ){
@@ -77259,11 +77260,11 @@
77259 int addrLoop, /* Address of loop counter */
77260 int addrVisit, /* Address of rows visited counter */
77261 LogEst nEst, /* Estimated number of output rows */
77262 const char *zName /* Name of table or index being scanned */
77263 ){
77264 int nByte = (p->nScan+1) * sizeof(ScanStatus);
77265 ScanStatus *aNew;
77266 aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
77267 if( aNew ){
77268 ScanStatus *pNew = &aNew[p->nScan++];
77269 pNew->addrExplain = addrExplain;
@@ -78380,13 +78381,13 @@
78380 /* An instance of this object describes bulk memory available for use
78381 ** by subcomponents of a prepared statement. Space is allocated out
78382 ** of a ReusableSpace object by the allocSpace() routine below.
78383 */
78384 struct ReusableSpace {
78385 u8 *pSpace; /* Available memory */
78386 int nFree; /* Bytes of available memory */
78387 int nNeeded; /* Total bytes that could not be allocated */
78388 };
78389
78390 /* Try to allocate nByte bytes of 8-byte aligned bulk memory for pBuf
78391 ** from the ReusableSpace object. Return a pointer to the allocated
78392 ** memory on success. If insufficient memory is available in the
@@ -78402,11 +78403,11 @@
78402 ** statement.
78403 */
78404 static void *allocSpace(
78405 struct ReusableSpace *p, /* Bulk memory available for allocation */
78406 void *pBuf, /* Pointer to a prior allocation */
78407 int nByte /* Bytes of memory needed */
78408 ){
78409 assert( EIGHT_BYTE_ALIGNMENT(p->pSpace) );
78410 if( pBuf==0 ){
78411 nByte = ROUND8(nByte);
78412 if( nByte <= p->nFree ){
@@ -81359,11 +81360,11 @@
81359 assert( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0 );
81360 assert( db->init.busy==0 );
81361 assert( p->zSql!=0 );
81362 sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
81363 iElapse = (iNow - p->startTime)*1000000;
81364 #ifndef SQLITE_OMIT_DEPRECATED
81365 if( db->xProfile ){
81366 db->xProfile(db->pProfileArg, p->zSql, iElapse);
81367 }
81368 #endif
81369 if( db->mTrace & SQLITE_TRACE_PROFILE ){
@@ -92255,11 +92256,11 @@
92255 int nRem; /* Bytes remaining to copy */
92256
92257 /* Extend the p->aAlloc[] allocation if required. */
92258 if( p->nAlloc<nByte ){
92259 u8 *aNew;
92260 int nNew = MAX(128, p->nAlloc*2);
92261 while( nByte>nNew ) nNew = nNew*2;
92262 aNew = sqlite3Realloc(p->aAlloc, nNew);
92263 if( !aNew ) return SQLITE_NOMEM_BKPT;
92264 p->nAlloc = nNew;
92265 p->aAlloc = aNew;
@@ -93546,19 +93547,23 @@
93546 if( pSorter->list.aMemory ){
93547 int nMin = pSorter->iMemory + nReq;
93548
93549 if( nMin>pSorter->nMemory ){
93550 u8 *aNew;
93551 int iListOff = (u8*)pSorter->list.pList - pSorter->list.aMemory;
93552 int nNew = pSorter->nMemory * 2;
 
 
 
93553 while( nNew < nMin ) nNew = nNew*2;
93554 if( nNew > pSorter->mxPmaSize ) nNew = pSorter->mxPmaSize;
93555 if( nNew < nMin ) nNew = nMin;
93556
93557 aNew = sqlite3Realloc(pSorter->list.aMemory, nNew);
93558 if( !aNew ) return SQLITE_NOMEM_BKPT;
93559 pSorter->list.pList = (SorterRecord*)&aNew[iListOff];
 
 
93560 pSorter->list.aMemory = aNew;
93561 pSorter->nMemory = nNew;
93562 }
93563
93564 pNew = (SorterRecord*)&pSorter->list.aMemory[pSorter->iMemory];
@@ -98204,11 +98209,11 @@
98204 */
98205 #ifndef SQLITE_OMIT_CTE
98206 static With *withDup(sqlite3 *db, With *p){
98207 With *pRet = 0;
98208 if( p ){
98209 int nByte = sizeof(*p) + sizeof(p->a[0]) * (p->nCte-1);
98210 pRet = sqlite3DbMallocZero(db, nByte);
98211 if( pRet ){
98212 int i;
98213 pRet->nCte = p->nCte;
98214 for(i=0; i<p->nCte; i++){
@@ -98469,11 +98474,11 @@
98469 }
98470 pList->nExpr = 0;
98471 }else if( (pList->nExpr & (pList->nExpr-1))==0 ){
98472 ExprList *pNew;
98473 pNew = sqlite3DbRealloc(db, pList,
98474 sizeof(*pList)+(2*pList->nExpr - 1)*sizeof(pList->a[0]));
98475 if( pNew==0 ){
98476 goto no_mem;
98477 }
98478 pList = pNew;
98479 }
@@ -106165,11 +106170,11 @@
106165 }
106166 sqlite3BtreeLeaveAll(db);
106167 assert( zErrDyn==0 || rc!=SQLITE_OK );
106168 }
106169 #ifdef SQLITE_USER_AUTHENTICATION
106170 if( rc==SQLITE_OK ){
106171 u8 newAuth = 0;
106172 rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth);
106173 if( newAuth<db->auth.authLevel ){
106174 rc = SQLITE_AUTH_USER;
106175 }
@@ -110602,23 +110607,22 @@
110602 int szEntry, /* Size of each object in the array */
110603 int *pnEntry, /* Number of objects currently in use */
110604 int *pIdx /* Write the index of a new slot here */
110605 ){
110606 char *z;
110607 int n = *pnEntry;
110608 if( (n & (n-1))==0 ){
110609 int sz = (n==0) ? 1 : 2*n;
110610 void *pNew = sqlite3DbRealloc(db, pArray, sz*szEntry);
110611 if( pNew==0 ){
110612 *pIdx = -1;
110613 return pArray;
110614 }
110615 pArray = pNew;
110616 }
110617 z = (char*)pArray;
110618 memset(&z[n * szEntry], 0, szEntry);
110619 *pIdx = n;
110620 ++*pnEntry;
110621 return pArray;
110622 }
110623
110624 /*
@@ -110725,11 +110729,11 @@
110725 assert( iStart<=pSrc->nSrc );
110726
110727 /* Allocate additional space if needed */
110728 if( (u32)pSrc->nSrc+nExtra>pSrc->nAlloc ){
110729 SrcList *pNew;
110730 int nAlloc = pSrc->nSrc*2+nExtra;
110731 sqlite3 *db = pParse->db;
110732
110733 if( pSrc->nSrc+nExtra>=SQLITE_MAX_SRCLIST ){
110734 sqlite3ErrorMsg(pParse, "too many FROM clause terms, max: %d",
110735 SQLITE_MAX_SRCLIST);
@@ -111482,11 +111486,11 @@
111482 }
111483 }
111484 }
111485
111486 if( pWith ){
111487 int nByte = sizeof(*pWith) + (sizeof(pWith->a[1]) * pWith->nCte);
111488 pNew = sqlite3DbRealloc(db, pWith, nByte);
111489 }else{
111490 pNew = sqlite3DbMallocZero(db, sizeof(*pWith));
111491 }
111492 assert( (pNew!=0 && zName!=0) || db->mallocFailed );
@@ -134593,13 +134597,17 @@
134593 ** Add a new module argument to pTable->azModuleArg[].
134594 ** The string is not copied - the pointer is stored. The
134595 ** string will be freed automatically when the table is
134596 ** deleted.
134597 */
134598 static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
134599 int nBytes = sizeof(char *)*(2+pTable->nModuleArg);
134600 char **azModuleArg;
 
 
 
 
134601 azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
134602 if( azModuleArg==0 ){
134603 sqlite3DbFree(db, zArg);
134604 }else{
134605 int i = pTable->nModuleArg++;
@@ -134630,13 +134638,13 @@
134630 assert( 0==pTable->pIndex );
134631
134632 db = pParse->db;
134633
134634 assert( pTable->nModuleArg==0 );
134635 addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName));
134636 addModuleArgument(db, pTable, 0);
134637 addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName));
134638 assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0)
134639 || (pParse->sNameToken.z==pName1->z && pName2->z==0)
134640 );
134641 pParse->sNameToken.n = (int)(
134642 &pModuleName->z[pModuleName->n] - pParse->sNameToken.z
@@ -134665,11 +134673,11 @@
134665 static void addArgumentToVtab(Parse *pParse){
134666 if( pParse->sArg.z && pParse->pNewTable ){
134667 const char *z = (const char*)pParse->sArg.z;
134668 int n = pParse->sArg.n;
134669 sqlite3 *db = pParse->db;
134670 addModuleArgument(db, pParse->pNewTable, sqlite3DbStrNDup(db, z, n));
134671 }
134672 }
134673
134674 /*
134675 ** The parser calls this routine after the CREATE VIRTUAL TABLE statement
@@ -134954,11 +134962,12 @@
134954 const int ARRAY_INCR = 5;
134955
134956 /* Grow the sqlite3.aVTrans array if required */
134957 if( (db->nVTrans%ARRAY_INCR)==0 ){
134958 VTable **aVTrans;
134959 int nBytes = sizeof(sqlite3_vtab *) * (db->nVTrans + ARRAY_INCR);
 
134960 aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes);
134961 if( !aVTrans ){
134962 return SQLITE_NOMEM_BKPT;
134963 }
134964 memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
@@ -135450,13 +135459,13 @@
135450 pMod->pEpoTab = pTab;
135451 pTab->nTabRef = 1;
135452 pTab->pSchema = db->aDb[0].pSchema;
135453 assert( pTab->nModuleArg==0 );
135454 pTab->iPKey = -1;
135455 addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
135456 addModuleArgument(db, pTab, 0);
135457 addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
135458 rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
135459 if( rc ){
135460 sqlite3ErrorMsg(pParse, "%s", zErr);
135461 sqlite3DbFree(db, zErr);
135462 sqlite3VtabEponymousTableClear(db, pMod);
@@ -155309,11 +155318,11 @@
155309 if( sz==0 || cnt==0 ){
155310 sz = 0;
155311 pStart = 0;
155312 }else if( pBuf==0 ){
155313 sqlite3BeginBenignMalloc();
155314 pStart = sqlite3Malloc( sz*cnt ); /* IMP: R-61949-35727 */
155315 sqlite3EndBenignMalloc();
155316 if( pStart ) cnt = sqlite3MallocSize(pStart)/sz;
155317 }else{
155318 pStart = pBuf;
155319 }
@@ -169347,12 +169356,12 @@
169347 }else{
169348 char const **aArg = 0;
169349 int iArg = 0;
169350 z = &z[n+1];
169351 while( z<zEnd && (NULL!=(z = (char *)sqlite3Fts3NextToken(z, &n))) ){
169352 int nNew = sizeof(char *)*(iArg+1);
169353 char const **aNew = (const char **)sqlite3_realloc((void *)aArg, nNew);
169354 if( !aNew ){
169355 sqlite3_free(zCopy);
169356 sqlite3_free((void *)aArg);
169357 return SQLITE_NOMEM;
169358 }
@@ -170255,11 +170264,11 @@
170255
170256 fts3tokResetCursor(pCsr);
170257 if( idxNum==1 ){
170258 const char *zByte = (const char *)sqlite3_value_text(apVal[0]);
170259 int nByte = sqlite3_value_bytes(apVal[0]);
170260 pCsr->zInput = sqlite3_malloc(nByte+1);
170261 if( pCsr->zInput==0 ){
170262 rc = SQLITE_NOMEM;
170263 }else{
170264 memcpy(pCsr->zInput, zByte, nByte);
170265 pCsr->zInput[nByte] = 0;
@@ -172119,12 +172128,13 @@
172119 nElem = 1;
172120 }
172121 }
172122
172123 if( nElem>0 ){
172124 int nByte = sizeof(Fts3SegReader) + (nElem+1)*sizeof(Fts3HashElem *);
172125 pReader = (Fts3SegReader *)sqlite3_malloc(nByte);
 
172126 if( !pReader ){
172127 rc = SQLITE_NOMEM;
172128 }else{
172129 memset(pReader, 0, nByte);
172130 pReader->iIdx = 0x7FFFFFFF;
@@ -173734,11 +173744,11 @@
173734 int nBlob; /* Number of bytes in the BLOB */
173735 sqlite3_stmt *pStmt; /* Statement used to insert the encoding */
173736 int rc; /* Result code from subfunctions */
173737
173738 if( *pRC ) return;
173739 pBlob = sqlite3_malloc( 10*p->nColumn );
173740 if( pBlob==0 ){
173741 *pRC = SQLITE_NOMEM;
173742 return;
173743 }
173744 fts3EncodeIntArray(p->nColumn, aSz, pBlob, &nBlob);
@@ -173784,11 +173794,11 @@
173784 int rc; /* Result code from subfunctions */
173785
173786 const int nStat = p->nColumn+2;
173787
173788 if( *pRC ) return;
173789 a = sqlite3_malloc( (sizeof(u32)+10)*nStat );
173790 if( a==0 ){
173791 *pRC = SQLITE_NOMEM;
173792 return;
173793 }
173794 pBlob = (char*)&a[nStat];
@@ -173905,12 +173915,12 @@
173905 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
173906 sqlite3_free(zSql);
173907 }
173908
173909 if( rc==SQLITE_OK ){
173910 int nByte = sizeof(u32) * (p->nColumn+1)*3;
173911 aSz = (u32 *)sqlite3_malloc(nByte);
173912 if( aSz==0 ){
173913 rc = SQLITE_NOMEM;
173914 }else{
173915 memset(aSz, 0, nByte);
173916 aSzIns = &aSz[p->nColumn+1];
@@ -173972,16 +173982,16 @@
173972 int nSeg, /* Number of segments to merge */
173973 Fts3MultiSegReader *pCsr /* Cursor object to populate */
173974 ){
173975 int rc; /* Return Code */
173976 sqlite3_stmt *pStmt = 0; /* Statement used to read %_segdir entry */
173977 int nByte; /* Bytes allocated at pCsr->apSegment[] */
173978
173979 /* Allocate space for the Fts3MultiSegReader.aCsr[] array */
173980 memset(pCsr, 0, sizeof(*pCsr));
173981 nByte = sizeof(Fts3SegReader *) * nSeg;
173982 pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc(nByte);
173983
173984 if( pCsr->apSegment==0 ){
173985 rc = SQLITE_NOMEM;
173986 }else{
173987 memset(pCsr->apSegment, 0, nByte);
@@ -175957,11 +175967,11 @@
175957 rc = SQLITE_CONSTRAINT;
175958 goto update_out;
175959 }
175960
175961 /* Allocate space to hold the change in document sizes */
175962 aSzDel = sqlite3_malloc( sizeof(aSzDel[0])*(p->nColumn+1)*2 );
175963 if( aSzDel==0 ){
175964 rc = SQLITE_NOMEM;
175965 goto update_out;
175966 }
175967 aSzIns = &aSzDel[p->nColumn+1];
@@ -176211,21 +176221,23 @@
176211 */
176212
176213 /*
176214 ** Allocate a two-slot MatchinfoBuffer object.
176215 */
176216 static MatchinfoBuffer *fts3MIBufferNew(int nElem, const char *zMatchinfo){
176217 MatchinfoBuffer *pRet;
176218 int nByte = sizeof(u32) * (2*nElem + 1) + sizeof(MatchinfoBuffer);
176219 int nStr = (int)strlen(zMatchinfo);
 
176220
176221 pRet = sqlite3_malloc(nByte + nStr+1);
176222 if( pRet ){
176223 memset(pRet, 0, nByte);
176224 pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet;
176225 pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0] + sizeof(u32)*(nElem+1);
176226 pRet->nElem = nElem;
 
176227 pRet->zMatchinfo = ((char*)pRet) + nByte;
176228 memcpy(pRet->zMatchinfo, zMatchinfo, nStr+1);
176229 pRet->aRef[0] = 1;
176230 }
176231
@@ -177082,12 +177094,12 @@
177082 }
177083 sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg);
177084 return SQLITE_ERROR;
177085 }
177086
177087 static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
177088 int nVal; /* Number of integers output by cArg */
177089
177090 switch( cArg ){
177091 case FTS3_MATCHINFO_NDOC:
177092 case FTS3_MATCHINFO_NPHRASE:
177093 case FTS3_MATCHINFO_NCOL:
@@ -177367,11 +177379,11 @@
177367 }
177368 break;
177369
177370 case FTS3_MATCHINFO_LHITS_BM:
177371 case FTS3_MATCHINFO_LHITS: {
177372 int nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
177373 memset(pInfo->aMatchinfo, 0, nZero);
177374 rc = fts3ExprLHitGather(pCsr->pExpr, pInfo);
177375 break;
177376 }
177377
@@ -177436,11 +177448,11 @@
177436 ** matchinfo function has been called for this query. In this case
177437 ** allocate the array used to accumulate the matchinfo data and
177438 ** initialize those elements that are constant for every row.
177439 */
177440 if( pCsr->pMIBuffer==0 ){
177441 int nMatchinfo = 0; /* Number of u32 elements in match-info */
177442 int i; /* Used to iterate through zArg */
177443
177444 /* Determine the number of phrases in the query */
177445 pCsr->nPhrase = fts3ExprPhraseCount(pCsr->pExpr);
177446 sInfo.nPhrase = pCsr->nPhrase;
@@ -185697,11 +185709,11 @@
185697 && (s.z++, geopolySkipSpace(&s)==0)
185698 ){
185699 GeoPoly *pOut;
185700 int x = 1;
185701 s.nVertex--; /* Remove the redundant vertex at the end */
185702 pOut = sqlite3_malloc64( GEOPOLY_SZ(s.nVertex) );
185703 x = 1;
185704 if( pOut==0 ) goto parse_json_err;
185705 pOut->nVertex = s.nVertex;
185706 memcpy(pOut->a, s.a, s.nVertex*2*sizeof(GeoCoord));
185707 pOut->hdr[0] = *(unsigned char*)&x;
@@ -186083,11 +186095,11 @@
186083 else if( r>mxY ) mxY = (float)r;
186084 }
186085 if( pRc ) *pRc = SQLITE_OK;
186086 if( aCoord==0 ){
186087 geopolyBboxFill:
186088 pOut = sqlite3_realloc(p, GEOPOLY_SZ(4));
186089 if( pOut==0 ){
186090 sqlite3_free(p);
186091 if( context ) sqlite3_result_error_nomem(context);
186092 if( pRc ) *pRc = SQLITE_NOMEM;
186093 return 0;
@@ -186479,13 +186491,13 @@
186479
186480 /*
186481 ** Determine the overlap between two polygons
186482 */
186483 static int geopolyOverlap(GeoPoly *p1, GeoPoly *p2){
186484 int nVertex = p1->nVertex + p2->nVertex + 2;
186485 GeoOverlap *p;
186486 int nByte;
186487 GeoEvent *pThisEvent;
186488 double rX;
186489 int rc = 0;
186490 int needSort = 0;
186491 GeoSegment *pActive = 0;
@@ -186493,11 +186505,11 @@
186493 unsigned char aOverlap[4];
186494
186495 nByte = sizeof(GeoEvent)*nVertex*2
186496 + sizeof(GeoSegment)*nVertex
186497 + sizeof(GeoOverlap);
186498 p = sqlite3_malloc( nByte );
186499 if( p==0 ) return -1;
186500 p->aEvent = (GeoEvent*)&p[1];
186501 p->aSegment = (GeoSegment*)&p->aEvent[nVertex*2];
186502 p->nEvent = p->nSegment = 0;
186503 geopolyAddSegments(p, p1, 1);
@@ -186652,22 +186664,22 @@
186652 char **pzErr, /* OUT: Error message, if any */
186653 int isCreate /* True for xCreate, false for xConnect */
186654 ){
186655 int rc = SQLITE_OK;
186656 Rtree *pRtree;
186657 int nDb; /* Length of string argv[1] */
186658 int nName; /* Length of string argv[2] */
186659 sqlite3_str *pSql;
186660 char *zSql;
186661 int ii;
186662
186663 sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
186664
186665 /* Allocate the sqlite3_vtab structure */
186666 nDb = (int)strlen(argv[1]);
186667 nName = (int)strlen(argv[2]);
186668 pRtree = (Rtree *)sqlite3_malloc(sizeof(Rtree)+nDb+nName+2);
186669 if( !pRtree ){
186670 return SQLITE_NOMEM;
186671 }
186672 memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2);
186673 pRtree->nBusy = 1;
@@ -189088,10 +189100,15 @@
189088 ** abIndexed:
189089 ** If the table has no indexes on it, abIndexed is set to NULL. Otherwise,
189090 ** it points to an array of flags nTblCol elements in size. The flag is
189091 ** set for each column that is either a part of the PK or a part of an
189092 ** index. Or clear otherwise.
 
 
 
 
 
189093 **
189094 */
189095 struct RbuObjIter {
189096 sqlite3_stmt *pTblIter; /* Iterate through tables */
189097 sqlite3_stmt *pIdxIter; /* Index iterator */
@@ -189883,11 +189900,11 @@
189883 ** error code in the rbu handle passed as the first argument. Or, if an
189884 ** error has already occurred when this function is called, return NULL
189885 ** immediately without attempting the allocation or modifying the stored
189886 ** error code.
189887 */
189888 static void *rbuMalloc(sqlite3rbu *p, int nByte){
189889 void *pRet = 0;
189890 if( p->rc==SQLITE_OK ){
189891 assert( nByte>0 );
189892 pRet = sqlite3_malloc64(nByte);
189893 if( pRet==0 ){
@@ -189904,11 +189921,11 @@
189904 ** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that
189905 ** there is room for at least nCol elements. If an OOM occurs, store an
189906 ** error code in the RBU handle passed as the first argument.
189907 */
189908 static void rbuAllocateIterArrays(sqlite3rbu *p, RbuObjIter *pIter, int nCol){
189909 int nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol;
189910 char **azNew;
189911
189912 azNew = (char**)rbuMalloc(p, nByte);
189913 if( azNew ){
189914 pIter->azTblCol = azNew;
@@ -190098,12 +190115,16 @@
190098 }
190099
190100 pIter->nIndex = 0;
190101 while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pList) ){
190102 const char *zIdx = (const char*)sqlite3_column_text(pList, 1);
 
190103 sqlite3_stmt *pXInfo = 0;
190104 if( zIdx==0 ) break;
 
 
 
190105 p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg,
190106 sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", zIdx)
190107 );
190108 while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
190109 int iCid = sqlite3_column_int(pXInfo, 1);
@@ -190544,11 +190565,11 @@
190544 ** when this function is called, NULL is returned immediately, without
190545 ** attempting the allocation or modifying the stored error code.
190546 */
190547 static char *rbuObjIterGetBindlist(sqlite3rbu *p, int nBind){
190548 char *zRet = 0;
190549 int nByte = nBind*2 + 1;
190550
190551 zRet = (char*)rbuMalloc(p, nByte);
190552 if( zRet ){
190553 int i;
190554 for(i=0; i<nBind; i++){
@@ -190805,10 +190826,66 @@
190805
190806 if( rc!=SQLITE_OK ){
190807 sqlite3_result_error_code(pCtx, rc);
190808 }
190809 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190810
190811 /*
190812 ** Ensure that the SQLite statement handles required to update the
190813 ** target database object currently indicated by the iterator passed
190814 ** as the second argument are available.
@@ -190835,17 +190912,19 @@
190835 const char *zTbl = pIter->zTbl;
190836 char *zImposterCols = 0; /* Columns for imposter table */
190837 char *zImposterPK = 0; /* Primary key declaration for imposter */
190838 char *zWhere = 0; /* WHERE clause on PK columns */
190839 char *zBind = 0;
 
190840 int nBind = 0;
190841
190842 assert( pIter->eType!=RBU_PK_VTAB );
190843 zCollist = rbuObjIterGetIndexCols(
190844 p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind
190845 );
190846 zBind = rbuObjIterGetBindlist(p, nBind);
 
190847
190848 /* Create the imposter table used to write to this index. */
190849 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
190850 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1,tnum);
190851 rbuMPrintfExec(p, p->dbMain,
@@ -190874,32 +190953,34 @@
190874 /* Create the SELECT statement to read keys in sorted order */
190875 if( p->rc==SQLITE_OK ){
190876 char *zSql;
190877 if( rbuIsVacuum(p) ){
190878 zSql = sqlite3_mprintf(
190879 "SELECT %s, 0 AS rbu_control FROM '%q' ORDER BY %s%s",
190880 zCollist,
190881 pIter->zDataTbl,
190882 zCollist, zLimit
190883 );
190884 }else
190885
190886 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
190887 zSql = sqlite3_mprintf(
190888 "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s",
190889 zCollist, p->zStateDb, pIter->zDataTbl,
190890 zCollist, zLimit
190891 );
190892 }else{
190893 zSql = sqlite3_mprintf(
190894 "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' "
190895 "UNION ALL "
190896 "SELECT %s, rbu_control FROM '%q' "
190897 "WHERE typeof(rbu_control)='integer' AND rbu_control!=1 "
190898 "ORDER BY %s%s",
190899 zCollist, p->zStateDb, pIter->zDataTbl,
190900 zCollist, pIter->zDataTbl,
 
 
190901 zCollist, zLimit
190902 );
190903 }
190904 p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql);
190905 }
@@ -190906,10 +190987,11 @@
190906
190907 sqlite3_free(zImposterCols);
190908 sqlite3_free(zImposterPK);
190909 sqlite3_free(zWhere);
190910 sqlite3_free(zBind);
 
190911 }else{
190912 int bRbuRowid = (pIter->eType==RBU_PK_VTAB)
190913 ||(pIter->eType==RBU_PK_NONE)
190914 ||(pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p));
190915 const char *zTbl = pIter->zTbl; /* Table this step applies to */
@@ -193339,11 +193421,11 @@
193339 ** rbu is in the RBU_STAGE_OAL state, use heap memory for *-shm space
193340 ** instead of a file on disk. */
193341 assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
193342 if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){
193343 if( iRegion<=p->nShm ){
193344 int nByte = (iRegion+1) * sizeof(char*);
193345 char **apNew = (char**)sqlite3_realloc64(p->apShm, nByte);
193346 if( apNew==0 ){
193347 rc = SQLITE_NOMEM;
193348 }else{
193349 memset(&apNew[p->nShm], 0, sizeof(char*) * (1 + iRegion - p->nShm));
@@ -195850,11 +195932,11 @@
195850 */
195851 static int sessionGrowHash(int bPatchset, SessionTable *pTab){
195852 if( pTab->nChange==0 || pTab->nEntry>=(pTab->nChange/2) ){
195853 int i;
195854 SessionChange **apNew;
195855 int nNew = (pTab->nChange ? pTab->nChange : 128) * 2;
195856
195857 apNew = (SessionChange **)sqlite3_malloc64(sizeof(SessionChange *) * nNew);
195858 if( apNew==0 ){
195859 if( pTab->nChange==0 ){
195860 return SQLITE_ERROR;
@@ -196777,11 +196859,11 @@
196777 ** If not, use sqlite3_realloc() to grow the buffer so that there is.
196778 **
196779 ** If successful, return zero. Otherwise, if an OOM condition is encountered,
196780 ** set *pRc to SQLITE_NOMEM and return non-zero.
196781 */
196782 static int sessionBufferGrow(SessionBuffer *p, int nByte, int *pRc){
196783 if( *pRc==SQLITE_OK && p->nAlloc-p->nBuf<nByte ){
196784 u8 *aNew;
196785 i64 nNew = p->nAlloc ? p->nAlloc : 128;
196786 do {
196787 nNew = nNew*2;
@@ -197895,11 +197977,11 @@
197895 rc = SQLITE_CORRUPT_BKPT;
197896 }
197897 }
197898
197899 if( rc==SQLITE_OK ){
197900 int iPK = sizeof(sqlite3_value*)*p->nCol*2;
197901 memset(p->tblhdr.aBuf, 0, iPK);
197902 memcpy(&p->tblhdr.aBuf[iPK], &p->in.aData[p->in.iNext], nCopy);
197903 p->in.iNext += nCopy;
197904 }
197905
@@ -199199,11 +199281,11 @@
199199 SessionBuffer cons = pApply->constraints;
199200 memset(&pApply->constraints, 0, sizeof(SessionBuffer));
199201
199202 rc = sessionChangesetStart(&pIter2, 0, 0, cons.nBuf, cons.aBuf, 0);
199203 if( rc==SQLITE_OK ){
199204 int nByte = 2*pApply->nCol*sizeof(sqlite3_value*);
199205 int rc2;
199206 pIter2->bPatchset = bPatchset;
199207 pIter2->zTab = (char*)zTab;
199208 pIter2->nCol = pApply->nCol;
199209 pIter2->abPK = pApply->abPK;
@@ -212488,11 +212570,11 @@
212488 pWriter->aDlidx, sizeof(Fts5DlidxWriter) * nLvl
212489 );
212490 if( aDlidx==0 ){
212491 p->rc = SQLITE_NOMEM;
212492 }else{
212493 int nByte = sizeof(Fts5DlidxWriter) * (nLvl - pWriter->nDlidx);
212494 memset(&aDlidx[pWriter->nDlidx], 0, nByte);
212495 pWriter->aDlidx = aDlidx;
212496 pWriter->nDlidx = nLvl;
212497 }
212498 }
@@ -217839,18 +217921,18 @@
217839 ){
217840 Fts5Global *pGlobal = (Fts5Global*)pApi;
217841 int rc = sqlite3_overload_function(pGlobal->db, zName, -1);
217842 if( rc==SQLITE_OK ){
217843 Fts5Auxiliary *pAux;
217844 int nName; /* Size of zName in bytes, including \0 */
217845 int nByte; /* Bytes of space to allocate */
217846
217847 nName = (int)strlen(zName) + 1;
217848 nByte = sizeof(Fts5Auxiliary) + nName;
217849 pAux = (Fts5Auxiliary*)sqlite3_malloc(nByte);
217850 if( pAux ){
217851 memset(pAux, 0, nByte);
217852 pAux->zFunc = (char*)&pAux[1];
217853 memcpy(pAux->zFunc, zName, nName);
217854 pAux->pGlobal = pGlobal;
217855 pAux->pUserData = pUserData;
217856 pAux->xFunc = xFunc;
@@ -217876,19 +217958,19 @@
217876 fts5_tokenizer *pTokenizer, /* Tokenizer implementation */
217877 void(*xDestroy)(void*) /* Destructor for pUserData */
217878 ){
217879 Fts5Global *pGlobal = (Fts5Global*)pApi;
217880 Fts5TokenizerModule *pNew;
217881 int nName; /* Size of zName and its \0 terminator */
217882 int nByte; /* Bytes of space to allocate */
217883 int rc = SQLITE_OK;
217884
217885 nName = (int)strlen(zName) + 1;
217886 nByte = sizeof(Fts5TokenizerModule) + nName;
217887 pNew = (Fts5TokenizerModule*)sqlite3_malloc(nByte);
217888 if( pNew ){
217889 memset(pNew, 0, nByte);
217890 pNew->zName = (char*)&pNew[1];
217891 memcpy(pNew->zName, zName, nName);
217892 pNew->pUserData = pUserData;
217893 pNew->x = *pTokenizer;
217894 pNew->xDestroy = xDestroy;
@@ -218019,11 +218101,11 @@
218019 int nArg, /* Number of args */
218020 sqlite3_value **apUnused /* Function arguments */
218021 ){
218022 assert( nArg==0 );
218023 UNUSED_PARAM2(nArg, apUnused);
218024 sqlite3_result_text(pCtx, "fts5: 2019-04-10 18:29:40 f294cfc173c5653ef161dbff63b7838dbccdcad797f5163c49b3173f9f35ab0f", -1, SQLITE_TRANSIENT);
218025 }
218026
218027 /*
218028 ** Return true if zName is the extension on one of the shadow tables used
218029 ** by this module.
@@ -219664,11 +219746,11 @@
219664 int i;
219665 memset(p, 0, sizeof(Unicode61Tokenizer));
219666
219667 p->eRemoveDiacritic = FTS5_REMOVE_DIACRITICS_SIMPLE;
219668 p->nFold = 64;
219669 p->aFold = sqlite3_malloc(p->nFold * sizeof(char));
219670 if( p->aFold==0 ){
219671 rc = SQLITE_NOMEM;
219672 }
219673
219674 /* Search for a "categories" argument */
@@ -222783,12 +222865,12 @@
222783 }
222784 #endif /* SQLITE_CORE */
222785 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
222786
222787 /************** End of stmt.c ************************************************/
222788 #if __LINE__!=222788
222789 #undef SQLITE_SOURCE_ID
222790 #define SQLITE_SOURCE_ID "2019-04-10 18:29:40 f294cfc173c5653ef161dbff63b7838dbccdcad797f5163c49b3173f9f35alt2"
222791 #endif
222792 /* Return the source-id for this library */
222793 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
222794 /************************** End of sqlite3.c ******************************/
222795
--- 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.28.0"
1166 #define SQLITE_VERSION_NUMBER 3028000
1167 #define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -13416,11 +13416,11 @@
13416 struct Hash {
13417 unsigned int htsize; /* Number of buckets in the hash table */
13418 unsigned int count; /* Number of entries in this table */
13419 HashElem *first; /* The first element of the array */
13420 struct _ht { /* the hash table */
13421 unsigned int count; /* Number of entries with this hash */
13422 HashElem *chain; /* Pointer to first entry with this hash */
13423 } *ht;
13424 };
13425
13426 /* Each element in the hash table is an instance of the following
@@ -29858,15 +29858,15 @@
29858 ** This routine transforms the internal text encoding used by pMem to
29859 ** desiredEnc. It is an error if the string is already of the desired
29860 ** encoding, or if *pMem does not contain a string value.
29861 */
29862 SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
29863 sqlite3_int64 len; /* Maximum length of output string in bytes */
29864 unsigned char *zOut; /* Output buffer */
29865 unsigned char *zIn; /* Input iterator */
29866 unsigned char *zTerm; /* End of input */
29867 unsigned char *z; /* Output iterator */
29868 unsigned int c;
29869
29870 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
29871 assert( pMem->flags&MEM_Str );
29872 assert( pMem->enc!=desiredEnc );
@@ -29911,18 +29911,18 @@
29911 ** translating a 2-byte character to a 4-byte UTF-8 character.
29912 ** A single byte is required for the output string
29913 ** nul-terminator.
29914 */
29915 pMem->n &= ~1;
29916 len = 2 * (sqlite3_int64)pMem->n + 1;
29917 }else{
29918 /* When converting from UTF-8 to UTF-16 the maximum growth is caused
29919 ** when a 1-byte UTF-8 character is translated into a 2-byte UTF-16
29920 ** character. Two bytes are required in the output buffer for the
29921 ** nul-terminator.
29922 */
29923 len = 2 * (sqlite3_int64)pMem->n + 2;
29924 }
29925
29926 /* Set zIn to point at the start of the input buffer and zTerm to point 1
29927 ** byte past the end.
29928 **
@@ -31790,11 +31790,11 @@
31790
31791 nInt = nName/4 + 3;
31792 assert( pIn==0 || pIn[0]>=3 ); /* Verify ok to add new elements */
31793 if( pIn==0 || pIn[1]+nInt > pIn[0] ){
31794 /* Enlarge the allocation */
31795 sqlite3_int64 nAlloc = (pIn ? 2*(sqlite3_int64)pIn[0] : 10) + nInt;
31796 VList *pOut = sqlite3DbRealloc(db, pIn, nAlloc*sizeof(int));
31797 if( pOut==0 ) return pIn;
31798 if( pIn==0 ) pOut[1] = 2;
31799 pIn = pOut;
31800 pIn[0] = nAlloc;
@@ -31996,11 +31996,11 @@
31996 const Hash *pH, /* The pH to be searched */
31997 const char *pKey, /* The key we are searching for */
31998 unsigned int *pHash /* Write the hash value here */
31999 ){
32000 HashElem *elem; /* Used to loop thru the element list */
32001 unsigned int count; /* Number of elements left to test */
32002 unsigned int h; /* The computed hash */
32003 static HashElem nullElement = { 0, 0, 0, 0 };
32004
32005 if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/
32006 struct _ht *pEntry;
@@ -32044,12 +32044,12 @@
32044 if( pH->ht ){
32045 pEntry = &pH->ht[h];
32046 if( pEntry->chain==elem ){
32047 pEntry->chain = elem->next;
32048 }
32049 assert( pEntry->count>0 );
32050 pEntry->count--;
 
32051 }
32052 sqlite3_free( elem );
32053 pH->count--;
32054 if( pH->count==0 ){
32055 assert( pH->first==0 );
@@ -49129,13 +49129,11 @@
49129 ** Malloc function used by SQLite to obtain space from the buffer configured
49130 ** using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no such buffer
49131 ** exists, this function falls back to sqlite3Malloc().
49132 */
49133 SQLITE_PRIVATE void *sqlite3PageMalloc(int sz){
49134 assert( sz<=65536+8 ); /* These allocations are never very large */
 
 
49135 return pcache1Alloc(sz);
49136 }
49137
49138 /*
49139 ** Free an allocated buffer obtained from sqlite3PageMalloc().
@@ -58889,11 +58887,11 @@
58887 ){
58888 int rc = SQLITE_OK;
58889
58890 /* Enlarge the pWal->apWiData[] array if required */
58891 if( pWal->nWiData<=iPage ){
58892 sqlite3_int64 nByte = sizeof(u32*)*(iPage+1);
58893 volatile u32 **apNew;
58894 apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte);
58895 if( !apNew ){
58896 *ppPage = 0;
58897 return SQLITE_NOMEM_BKPT;
@@ -58993,10 +58991,11 @@
58991 s1 = s2 = 0;
58992 }
58993
58994 assert( nByte>=8 );
58995 assert( (nByte&0x00000007)==0 );
58996 assert( nByte<=65536 );
58997
58998 if( nativeCksum ){
58999 do {
59000 s1 += *aData++ + s2;
59001 s2 += *aData++ + s1;
@@ -59930,11 +59929,11 @@
59929 */
59930 static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp){
59931 WalIterator *p; /* Return value */
59932 int nSegment; /* Number of segments to merge */
59933 u32 iLast; /* Last frame in log */
59934 sqlite3_int64 nByte; /* Number of bytes to allocate */
59935 int i; /* Iterator variable */
59936 ht_slot *aTmp; /* Temp space used by merge-sort */
59937 int rc = SQLITE_OK; /* Return Code */
59938
59939 /* This routine only runs while holding the checkpoint lock. And
@@ -76469,13 +76468,15 @@
76468 ** during testing only. With SQLITE_TEST_REALLOC_STRESS grow the op array
76469 ** by the minimum* amount required until the size reaches 512. Normal
76470 ** operation (without SQLITE_TEST_REALLOC_STRESS) is to double the current
76471 ** size of the op array or add 1KB of space, whichever is smaller. */
76472 #ifdef SQLITE_TEST_REALLOC_STRESS
76473 sqlite3_int64 nNew = (v->nOpAlloc>=512 ? 2*(sqlite3_int64)v->nOpAlloc
76474 : (sqlite3_int64)v->nOpAlloc+nOp);
76475 #else
76476 sqlite3_int64 nNew = (v->nOpAlloc ? 2*(sqlite3_int64)v->nOpAlloc
76477 : (sqlite3_int64)(1024/sizeof(Op)));
76478 UNUSED_PARAMETER(nOp);
76479 #endif
76480
76481 /* Ensure that the size of a VDBE does not grow too large */
76482 if( nNew > p->db->aLimit[SQLITE_LIMIT_VDBE_OP] ){
@@ -77259,11 +77260,11 @@
77260 int addrLoop, /* Address of loop counter */
77261 int addrVisit, /* Address of rows visited counter */
77262 LogEst nEst, /* Estimated number of output rows */
77263 const char *zName /* Name of table or index being scanned */
77264 ){
77265 sqlite3_int64 nByte = (p->nScan+1) * sizeof(ScanStatus);
77266 ScanStatus *aNew;
77267 aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
77268 if( aNew ){
77269 ScanStatus *pNew = &aNew[p->nScan++];
77270 pNew->addrExplain = addrExplain;
@@ -78380,13 +78381,13 @@
78381 /* An instance of this object describes bulk memory available for use
78382 ** by subcomponents of a prepared statement. Space is allocated out
78383 ** of a ReusableSpace object by the allocSpace() routine below.
78384 */
78385 struct ReusableSpace {
78386 u8 *pSpace; /* Available memory */
78387 sqlite3_int64 nFree; /* Bytes of available memory */
78388 sqlite3_int64 nNeeded; /* Total bytes that could not be allocated */
78389 };
78390
78391 /* Try to allocate nByte bytes of 8-byte aligned bulk memory for pBuf
78392 ** from the ReusableSpace object. Return a pointer to the allocated
78393 ** memory on success. If insufficient memory is available in the
@@ -78402,11 +78403,11 @@
78403 ** statement.
78404 */
78405 static void *allocSpace(
78406 struct ReusableSpace *p, /* Bulk memory available for allocation */
78407 void *pBuf, /* Pointer to a prior allocation */
78408 sqlite3_int64 nByte /* Bytes of memory needed */
78409 ){
78410 assert( EIGHT_BYTE_ALIGNMENT(p->pSpace) );
78411 if( pBuf==0 ){
78412 nByte = ROUND8(nByte);
78413 if( nByte <= p->nFree ){
@@ -81359,11 +81360,11 @@
81360 assert( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0 );
81361 assert( db->init.busy==0 );
81362 assert( p->zSql!=0 );
81363 sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
81364 iElapse = (iNow - p->startTime)*1000000;
81365 #ifndef SQLITE_OMIT_DEPRECATED
81366 if( db->xProfile ){
81367 db->xProfile(db->pProfileArg, p->zSql, iElapse);
81368 }
81369 #endif
81370 if( db->mTrace & SQLITE_TRACE_PROFILE ){
@@ -92255,11 +92256,11 @@
92256 int nRem; /* Bytes remaining to copy */
92257
92258 /* Extend the p->aAlloc[] allocation if required. */
92259 if( p->nAlloc<nByte ){
92260 u8 *aNew;
92261 sqlite3_int64 nNew = MAX(128, 2*(sqlite3_int64)p->nAlloc);
92262 while( nByte>nNew ) nNew = nNew*2;
92263 aNew = sqlite3Realloc(p->aAlloc, nNew);
92264 if( !aNew ) return SQLITE_NOMEM_BKPT;
92265 p->nAlloc = nNew;
92266 p->aAlloc = aNew;
@@ -93546,19 +93547,23 @@
93547 if( pSorter->list.aMemory ){
93548 int nMin = pSorter->iMemory + nReq;
93549
93550 if( nMin>pSorter->nMemory ){
93551 u8 *aNew;
93552 sqlite3_int64 nNew = 2 * (sqlite3_int64)pSorter->nMemory;
93553 int iListOff = -1;
93554 if( pSorter->list.pList ){
93555 iListOff = (u8*)pSorter->list.pList - pSorter->list.aMemory;
93556 }
93557 while( nNew < nMin ) nNew = nNew*2;
93558 if( nNew > pSorter->mxPmaSize ) nNew = pSorter->mxPmaSize;
93559 if( nNew < nMin ) nNew = nMin;
 
93560 aNew = sqlite3Realloc(pSorter->list.aMemory, nNew);
93561 if( !aNew ) return SQLITE_NOMEM_BKPT;
93562 if( iListOff>=0 ){
93563 pSorter->list.pList = (SorterRecord*)&aNew[iListOff];
93564 }
93565 pSorter->list.aMemory = aNew;
93566 pSorter->nMemory = nNew;
93567 }
93568
93569 pNew = (SorterRecord*)&pSorter->list.aMemory[pSorter->iMemory];
@@ -98204,11 +98209,11 @@
98209 */
98210 #ifndef SQLITE_OMIT_CTE
98211 static With *withDup(sqlite3 *db, With *p){
98212 With *pRet = 0;
98213 if( p ){
98214 sqlite3_int64 nByte = sizeof(*p) + sizeof(p->a[0]) * (p->nCte-1);
98215 pRet = sqlite3DbMallocZero(db, nByte);
98216 if( pRet ){
98217 int i;
98218 pRet->nCte = p->nCte;
98219 for(i=0; i<p->nCte; i++){
@@ -98469,11 +98474,11 @@
98474 }
98475 pList->nExpr = 0;
98476 }else if( (pList->nExpr & (pList->nExpr-1))==0 ){
98477 ExprList *pNew;
98478 pNew = sqlite3DbRealloc(db, pList,
98479 sizeof(*pList)+(2*(sqlite3_int64)pList->nExpr-1)*sizeof(pList->a[0]));
98480 if( pNew==0 ){
98481 goto no_mem;
98482 }
98483 pList = pNew;
98484 }
@@ -106165,11 +106170,11 @@
106170 }
106171 sqlite3BtreeLeaveAll(db);
106172 assert( zErrDyn==0 || rc!=SQLITE_OK );
106173 }
106174 #ifdef SQLITE_USER_AUTHENTICATION
106175 if( rc==SQLITE_OK && !REOPEN_AS_MEMDB(db) ){
106176 u8 newAuth = 0;
106177 rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth);
106178 if( newAuth<db->auth.authLevel ){
106179 rc = SQLITE_AUTH_USER;
106180 }
@@ -110602,23 +110607,22 @@
110607 int szEntry, /* Size of each object in the array */
110608 int *pnEntry, /* Number of objects currently in use */
110609 int *pIdx /* Write the index of a new slot here */
110610 ){
110611 char *z;
110612 sqlite3_int64 n = *pIdx = *pnEntry;
110613 if( (n & (n-1))==0 ){
110614 sqlite3_int64 sz = (n==0) ? 1 : 2*n;
110615 void *pNew = sqlite3DbRealloc(db, pArray, sz*szEntry);
110616 if( pNew==0 ){
110617 *pIdx = -1;
110618 return pArray;
110619 }
110620 pArray = pNew;
110621 }
110622 z = (char*)pArray;
110623 memset(&z[n * szEntry], 0, szEntry);
 
110624 ++*pnEntry;
110625 return pArray;
110626 }
110627
110628 /*
@@ -110725,11 +110729,11 @@
110729 assert( iStart<=pSrc->nSrc );
110730
110731 /* Allocate additional space if needed */
110732 if( (u32)pSrc->nSrc+nExtra>pSrc->nAlloc ){
110733 SrcList *pNew;
110734 sqlite3_int64 nAlloc = 2*(sqlite3_int64)pSrc->nSrc+nExtra;
110735 sqlite3 *db = pParse->db;
110736
110737 if( pSrc->nSrc+nExtra>=SQLITE_MAX_SRCLIST ){
110738 sqlite3ErrorMsg(pParse, "too many FROM clause terms, max: %d",
110739 SQLITE_MAX_SRCLIST);
@@ -111482,11 +111486,11 @@
111486 }
111487 }
111488 }
111489
111490 if( pWith ){
111491 sqlite3_int64 nByte = sizeof(*pWith) + (sizeof(pWith->a[1]) * pWith->nCte);
111492 pNew = sqlite3DbRealloc(db, pWith, nByte);
111493 }else{
111494 pNew = sqlite3DbMallocZero(db, sizeof(*pWith));
111495 }
111496 assert( (pNew!=0 && zName!=0) || db->mallocFailed );
@@ -134593,13 +134597,17 @@
134597 ** Add a new module argument to pTable->azModuleArg[].
134598 ** The string is not copied - the pointer is stored. The
134599 ** string will be freed automatically when the table is
134600 ** deleted.
134601 */
134602 static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){
134603 sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->nModuleArg);
134604 char **azModuleArg;
134605 sqlite3 *db = pParse->db;
134606 if( pTable->nModuleArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){
134607 sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName);
134608 }
134609 azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
134610 if( azModuleArg==0 ){
134611 sqlite3DbFree(db, zArg);
134612 }else{
134613 int i = pTable->nModuleArg++;
@@ -134630,13 +134638,13 @@
134638 assert( 0==pTable->pIndex );
134639
134640 db = pParse->db;
134641
134642 assert( pTable->nModuleArg==0 );
134643 addModuleArgument(pParse, pTable, sqlite3NameFromToken(db, pModuleName));
134644 addModuleArgument(pParse, pTable, 0);
134645 addModuleArgument(pParse, pTable, sqlite3DbStrDup(db, pTable->zName));
134646 assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0)
134647 || (pParse->sNameToken.z==pName1->z && pName2->z==0)
134648 );
134649 pParse->sNameToken.n = (int)(
134650 &pModuleName->z[pModuleName->n] - pParse->sNameToken.z
@@ -134665,11 +134673,11 @@
134673 static void addArgumentToVtab(Parse *pParse){
134674 if( pParse->sArg.z && pParse->pNewTable ){
134675 const char *z = (const char*)pParse->sArg.z;
134676 int n = pParse->sArg.n;
134677 sqlite3 *db = pParse->db;
134678 addModuleArgument(pParse, pParse->pNewTable, sqlite3DbStrNDup(db, z, n));
134679 }
134680 }
134681
134682 /*
134683 ** The parser calls this routine after the CREATE VIRTUAL TABLE statement
@@ -134954,11 +134962,12 @@
134962 const int ARRAY_INCR = 5;
134963
134964 /* Grow the sqlite3.aVTrans array if required */
134965 if( (db->nVTrans%ARRAY_INCR)==0 ){
134966 VTable **aVTrans;
134967 sqlite3_int64 nBytes = sizeof(sqlite3_vtab*)*
134968 ((sqlite3_int64)db->nVTrans + ARRAY_INCR);
134969 aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes);
134970 if( !aVTrans ){
134971 return SQLITE_NOMEM_BKPT;
134972 }
134973 memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
@@ -135450,13 +135459,13 @@
135459 pMod->pEpoTab = pTab;
135460 pTab->nTabRef = 1;
135461 pTab->pSchema = db->aDb[0].pSchema;
135462 assert( pTab->nModuleArg==0 );
135463 pTab->iPKey = -1;
135464 addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
135465 addModuleArgument(pParse, pTab, 0);
135466 addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
135467 rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
135468 if( rc ){
135469 sqlite3ErrorMsg(pParse, "%s", zErr);
135470 sqlite3DbFree(db, zErr);
135471 sqlite3VtabEponymousTableClear(db, pMod);
@@ -155309,11 +155318,11 @@
155318 if( sz==0 || cnt==0 ){
155319 sz = 0;
155320 pStart = 0;
155321 }else if( pBuf==0 ){
155322 sqlite3BeginBenignMalloc();
155323 pStart = sqlite3Malloc( sz*(sqlite3_int64)cnt ); /* IMP: R-61949-35727 */
155324 sqlite3EndBenignMalloc();
155325 if( pStart ) cnt = sqlite3MallocSize(pStart)/sz;
155326 }else{
155327 pStart = pBuf;
155328 }
@@ -169347,12 +169356,12 @@
169356 }else{
169357 char const **aArg = 0;
169358 int iArg = 0;
169359 z = &z[n+1];
169360 while( z<zEnd && (NULL!=(z = (char *)sqlite3Fts3NextToken(z, &n))) ){
169361 sqlite3_int64 nNew = sizeof(char *)*(iArg+1);
169362 char const **aNew = (const char **)sqlite3_realloc64((void *)aArg, nNew);
169363 if( !aNew ){
169364 sqlite3_free(zCopy);
169365 sqlite3_free((void *)aArg);
169366 return SQLITE_NOMEM;
169367 }
@@ -170255,11 +170264,11 @@
170264
170265 fts3tokResetCursor(pCsr);
170266 if( idxNum==1 ){
170267 const char *zByte = (const char *)sqlite3_value_text(apVal[0]);
170268 int nByte = sqlite3_value_bytes(apVal[0]);
170269 pCsr->zInput = sqlite3_malloc64(nByte+1);
170270 if( pCsr->zInput==0 ){
170271 rc = SQLITE_NOMEM;
170272 }else{
170273 memcpy(pCsr->zInput, zByte, nByte);
170274 pCsr->zInput[nByte] = 0;
@@ -172119,12 +172128,13 @@
172128 nElem = 1;
172129 }
172130 }
172131
172132 if( nElem>0 ){
172133 sqlite3_int64 nByte;
172134 nByte = sizeof(Fts3SegReader) + (nElem+1)*sizeof(Fts3HashElem *);
172135 pReader = (Fts3SegReader *)sqlite3_malloc64(nByte);
172136 if( !pReader ){
172137 rc = SQLITE_NOMEM;
172138 }else{
172139 memset(pReader, 0, nByte);
172140 pReader->iIdx = 0x7FFFFFFF;
@@ -173734,11 +173744,11 @@
173744 int nBlob; /* Number of bytes in the BLOB */
173745 sqlite3_stmt *pStmt; /* Statement used to insert the encoding */
173746 int rc; /* Result code from subfunctions */
173747
173748 if( *pRC ) return;
173749 pBlob = sqlite3_malloc64( 10*(sqlite3_int64)p->nColumn );
173750 if( pBlob==0 ){
173751 *pRC = SQLITE_NOMEM;
173752 return;
173753 }
173754 fts3EncodeIntArray(p->nColumn, aSz, pBlob, &nBlob);
@@ -173784,11 +173794,11 @@
173794 int rc; /* Result code from subfunctions */
173795
173796 const int nStat = p->nColumn+2;
173797
173798 if( *pRC ) return;
173799 a = sqlite3_malloc64( (sizeof(u32)+10)*(sqlite3_int64)nStat );
173800 if( a==0 ){
173801 *pRC = SQLITE_NOMEM;
173802 return;
173803 }
173804 pBlob = (char*)&a[nStat];
@@ -173905,12 +173915,12 @@
173915 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
173916 sqlite3_free(zSql);
173917 }
173918
173919 if( rc==SQLITE_OK ){
173920 sqlite3_int64 nByte = sizeof(u32) * ((sqlite3_int64)p->nColumn+1)*3;
173921 aSz = (u32 *)sqlite3_malloc64(nByte);
173922 if( aSz==0 ){
173923 rc = SQLITE_NOMEM;
173924 }else{
173925 memset(aSz, 0, nByte);
173926 aSzIns = &aSz[p->nColumn+1];
@@ -173972,16 +173982,16 @@
173982 int nSeg, /* Number of segments to merge */
173983 Fts3MultiSegReader *pCsr /* Cursor object to populate */
173984 ){
173985 int rc; /* Return Code */
173986 sqlite3_stmt *pStmt = 0; /* Statement used to read %_segdir entry */
173987 sqlite3_int64 nByte; /* Bytes allocated at pCsr->apSegment[] */
173988
173989 /* Allocate space for the Fts3MultiSegReader.aCsr[] array */
173990 memset(pCsr, 0, sizeof(*pCsr));
173991 nByte = sizeof(Fts3SegReader *) * nSeg;
173992 pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc64(nByte);
173993
173994 if( pCsr->apSegment==0 ){
173995 rc = SQLITE_NOMEM;
173996 }else{
173997 memset(pCsr->apSegment, 0, nByte);
@@ -175957,11 +175967,11 @@
175967 rc = SQLITE_CONSTRAINT;
175968 goto update_out;
175969 }
175970
175971 /* Allocate space to hold the change in document sizes */
175972 aSzDel = sqlite3_malloc64(sizeof(aSzDel[0])*((sqlite3_int64)p->nColumn+1)*2);
175973 if( aSzDel==0 ){
175974 rc = SQLITE_NOMEM;
175975 goto update_out;
175976 }
175977 aSzIns = &aSzDel[p->nColumn+1];
@@ -176211,21 +176221,23 @@
176221 */
176222
176223 /*
176224 ** Allocate a two-slot MatchinfoBuffer object.
176225 */
176226 static MatchinfoBuffer *fts3MIBufferNew(size_t nElem, const char *zMatchinfo){
176227 MatchinfoBuffer *pRet;
176228 sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1)
176229 + sizeof(MatchinfoBuffer);
176230 sqlite3_int64 nStr = strlen(zMatchinfo);
176231
176232 pRet = sqlite3_malloc64(nByte + nStr+1);
176233 if( pRet ){
176234 memset(pRet, 0, nByte);
176235 pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet;
176236 pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0]
176237 + sizeof(u32)*((int)nElem+1);
176238 pRet->nElem = (int)nElem;
176239 pRet->zMatchinfo = ((char*)pRet) + nByte;
176240 memcpy(pRet->zMatchinfo, zMatchinfo, nStr+1);
176241 pRet->aRef[0] = 1;
176242 }
176243
@@ -177082,12 +177094,12 @@
177094 }
177095 sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg);
177096 return SQLITE_ERROR;
177097 }
177098
177099 static size_t fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
177100 size_t nVal; /* Number of integers output by cArg */
177101
177102 switch( cArg ){
177103 case FTS3_MATCHINFO_NDOC:
177104 case FTS3_MATCHINFO_NPHRASE:
177105 case FTS3_MATCHINFO_NCOL:
@@ -177367,11 +177379,11 @@
177379 }
177380 break;
177381
177382 case FTS3_MATCHINFO_LHITS_BM:
177383 case FTS3_MATCHINFO_LHITS: {
177384 size_t nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
177385 memset(pInfo->aMatchinfo, 0, nZero);
177386 rc = fts3ExprLHitGather(pCsr->pExpr, pInfo);
177387 break;
177388 }
177389
@@ -177436,11 +177448,11 @@
177448 ** matchinfo function has been called for this query. In this case
177449 ** allocate the array used to accumulate the matchinfo data and
177450 ** initialize those elements that are constant for every row.
177451 */
177452 if( pCsr->pMIBuffer==0 ){
177453 size_t nMatchinfo = 0; /* Number of u32 elements in match-info */
177454 int i; /* Used to iterate through zArg */
177455
177456 /* Determine the number of phrases in the query */
177457 pCsr->nPhrase = fts3ExprPhraseCount(pCsr->pExpr);
177458 sInfo.nPhrase = pCsr->nPhrase;
@@ -185697,11 +185709,11 @@
185709 && (s.z++, geopolySkipSpace(&s)==0)
185710 ){
185711 GeoPoly *pOut;
185712 int x = 1;
185713 s.nVertex--; /* Remove the redundant vertex at the end */
185714 pOut = sqlite3_malloc64( GEOPOLY_SZ((sqlite3_int64)s.nVertex) );
185715 x = 1;
185716 if( pOut==0 ) goto parse_json_err;
185717 pOut->nVertex = s.nVertex;
185718 memcpy(pOut->a, s.a, s.nVertex*2*sizeof(GeoCoord));
185719 pOut->hdr[0] = *(unsigned char*)&x;
@@ -186083,11 +186095,11 @@
186095 else if( r>mxY ) mxY = (float)r;
186096 }
186097 if( pRc ) *pRc = SQLITE_OK;
186098 if( aCoord==0 ){
186099 geopolyBboxFill:
186100 pOut = sqlite3_realloc64(p, GEOPOLY_SZ(4));
186101 if( pOut==0 ){
186102 sqlite3_free(p);
186103 if( context ) sqlite3_result_error_nomem(context);
186104 if( pRc ) *pRc = SQLITE_NOMEM;
186105 return 0;
@@ -186479,13 +186491,13 @@
186491
186492 /*
186493 ** Determine the overlap between two polygons
186494 */
186495 static int geopolyOverlap(GeoPoly *p1, GeoPoly *p2){
186496 sqlite3_int64 nVertex = p1->nVertex + p2->nVertex + 2;
186497 GeoOverlap *p;
186498 sqlite3_int64 nByte;
186499 GeoEvent *pThisEvent;
186500 double rX;
186501 int rc = 0;
186502 int needSort = 0;
186503 GeoSegment *pActive = 0;
@@ -186493,11 +186505,11 @@
186505 unsigned char aOverlap[4];
186506
186507 nByte = sizeof(GeoEvent)*nVertex*2
186508 + sizeof(GeoSegment)*nVertex
186509 + sizeof(GeoOverlap);
186510 p = sqlite3_malloc64( nByte );
186511 if( p==0 ) return -1;
186512 p->aEvent = (GeoEvent*)&p[1];
186513 p->aSegment = (GeoSegment*)&p->aEvent[nVertex*2];
186514 p->nEvent = p->nSegment = 0;
186515 geopolyAddSegments(p, p1, 1);
@@ -186652,22 +186664,22 @@
186664 char **pzErr, /* OUT: Error message, if any */
186665 int isCreate /* True for xCreate, false for xConnect */
186666 ){
186667 int rc = SQLITE_OK;
186668 Rtree *pRtree;
186669 sqlite3_int64 nDb; /* Length of string argv[1] */
186670 sqlite3_int64 nName; /* Length of string argv[2] */
186671 sqlite3_str *pSql;
186672 char *zSql;
186673 int ii;
186674
186675 sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
186676
186677 /* Allocate the sqlite3_vtab structure */
186678 nDb = strlen(argv[1]);
186679 nName = strlen(argv[2]);
186680 pRtree = (Rtree *)sqlite3_malloc64(sizeof(Rtree)+nDb+nName+2);
186681 if( !pRtree ){
186682 return SQLITE_NOMEM;
186683 }
186684 memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2);
186685 pRtree->nBusy = 1;
@@ -189088,10 +189100,15 @@
189100 ** abIndexed:
189101 ** If the table has no indexes on it, abIndexed is set to NULL. Otherwise,
189102 ** it points to an array of flags nTblCol elements in size. The flag is
189103 ** set for each column that is either a part of the PK or a part of an
189104 ** index. Or clear otherwise.
189105 **
189106 ** If there are one or more partial indexes on the table, all fields of
189107 ** this array set set to 1. This is because in that case, the module has
189108 ** no way to tell which fields will be required to add and remove entries
189109 ** from the partial indexes.
189110 **
189111 */
189112 struct RbuObjIter {
189113 sqlite3_stmt *pTblIter; /* Iterate through tables */
189114 sqlite3_stmt *pIdxIter; /* Index iterator */
@@ -189883,11 +189900,11 @@
189900 ** error code in the rbu handle passed as the first argument. Or, if an
189901 ** error has already occurred when this function is called, return NULL
189902 ** immediately without attempting the allocation or modifying the stored
189903 ** error code.
189904 */
189905 static void *rbuMalloc(sqlite3rbu *p, sqlite3_int64 nByte){
189906 void *pRet = 0;
189907 if( p->rc==SQLITE_OK ){
189908 assert( nByte>0 );
189909 pRet = sqlite3_malloc64(nByte);
189910 if( pRet==0 ){
@@ -189904,11 +189921,11 @@
189921 ** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that
189922 ** there is room for at least nCol elements. If an OOM occurs, store an
189923 ** error code in the RBU handle passed as the first argument.
189924 */
189925 static void rbuAllocateIterArrays(sqlite3rbu *p, RbuObjIter *pIter, int nCol){
189926 sqlite3_int64 nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol;
189927 char **azNew;
189928
189929 azNew = (char**)rbuMalloc(p, nByte);
189930 if( azNew ){
189931 pIter->azTblCol = azNew;
@@ -190098,12 +190115,16 @@
190115 }
190116
190117 pIter->nIndex = 0;
190118 while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pList) ){
190119 const char *zIdx = (const char*)sqlite3_column_text(pList, 1);
190120 int bPartial = sqlite3_column_int(pList, 4);
190121 sqlite3_stmt *pXInfo = 0;
190122 if( zIdx==0 ) break;
190123 if( bPartial ){
190124 memset(pIter->abIndexed, 0x01, sizeof(u8)*pIter->nTblCol);
190125 }
190126 p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg,
190127 sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", zIdx)
190128 );
190129 while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
190130 int iCid = sqlite3_column_int(pXInfo, 1);
@@ -190544,11 +190565,11 @@
190565 ** when this function is called, NULL is returned immediately, without
190566 ** attempting the allocation or modifying the stored error code.
190567 */
190568 static char *rbuObjIterGetBindlist(sqlite3rbu *p, int nBind){
190569 char *zRet = 0;
190570 sqlite3_int64 nByte = 2*(sqlite3_int64)nBind + 1;
190571
190572 zRet = (char*)rbuMalloc(p, nByte);
190573 if( zRet ){
190574 int i;
190575 for(i=0; i<nBind; i++){
@@ -190805,10 +190826,66 @@
190826
190827 if( rc!=SQLITE_OK ){
190828 sqlite3_result_error_code(pCtx, rc);
190829 }
190830 }
190831
190832 static char *rbuObjIterGetIndexWhere(sqlite3rbu *p, RbuObjIter *pIter){
190833 sqlite3_stmt *pStmt = 0;
190834 int rc = p->rc;
190835 char *zRet = 0;
190836
190837 if( rc==SQLITE_OK ){
190838 rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
190839 "SELECT trim(sql) FROM sqlite_master WHERE type='index' AND name=?"
190840 );
190841 }
190842 if( rc==SQLITE_OK ){
190843 int rc2;
190844 rc = sqlite3_bind_text(pStmt, 1, pIter->zIdx, -1, SQLITE_STATIC);
190845 if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
190846 const char *zSql = (const char*)sqlite3_column_text(pStmt, 0);
190847 if( zSql ){
190848 int nParen = 0; /* Number of open parenthesis */
190849 int i;
190850 for(i=0; zSql[i]; i++){
190851 char c = zSql[i];
190852 if( c=='(' ){
190853 nParen++;
190854 }
190855 else if( c==')' ){
190856 nParen--;
190857 if( nParen==0 ){
190858 i++;
190859 break;
190860 }
190861 }else if( c=='"' || c=='\'' || c=='`' ){
190862 for(i++; 1; i++){
190863 if( zSql[i]==c ){
190864 if( zSql[i+1]!=c ) break;
190865 i++;
190866 }
190867 }
190868 }else if( c=='[' ){
190869 for(i++; 1; i++){
190870 if( zSql[i]==']' ) break;
190871 }
190872 }
190873 }
190874 if( zSql[i] ){
190875 zRet = rbuStrndup(&zSql[i], &rc);
190876 }
190877 }
190878 }
190879
190880 rc2 = sqlite3_finalize(pStmt);
190881 if( rc==SQLITE_OK ) rc = rc2;
190882 }
190883
190884 p->rc = rc;
190885 return zRet;
190886 }
190887
190888 /*
190889 ** Ensure that the SQLite statement handles required to update the
190890 ** target database object currently indicated by the iterator passed
190891 ** as the second argument are available.
@@ -190835,17 +190912,19 @@
190912 const char *zTbl = pIter->zTbl;
190913 char *zImposterCols = 0; /* Columns for imposter table */
190914 char *zImposterPK = 0; /* Primary key declaration for imposter */
190915 char *zWhere = 0; /* WHERE clause on PK columns */
190916 char *zBind = 0;
190917 char *zPart = 0;
190918 int nBind = 0;
190919
190920 assert( pIter->eType!=RBU_PK_VTAB );
190921 zCollist = rbuObjIterGetIndexCols(
190922 p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind
190923 );
190924 zBind = rbuObjIterGetBindlist(p, nBind);
190925 zPart = rbuObjIterGetIndexWhere(p, pIter);
190926
190927 /* Create the imposter table used to write to this index. */
190928 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
190929 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1,tnum);
190930 rbuMPrintfExec(p, p->dbMain,
@@ -190874,32 +190953,34 @@
190953 /* Create the SELECT statement to read keys in sorted order */
190954 if( p->rc==SQLITE_OK ){
190955 char *zSql;
190956 if( rbuIsVacuum(p) ){
190957 zSql = sqlite3_mprintf(
190958 "SELECT %s, 0 AS rbu_control FROM '%q' %s ORDER BY %s%s",
190959 zCollist,
190960 pIter->zDataTbl,
190961 zPart, zCollist, zLimit
190962 );
190963 }else
190964
190965 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
190966 zSql = sqlite3_mprintf(
190967 "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s ORDER BY %s%s",
190968 zCollist, p->zStateDb, pIter->zDataTbl,
190969 zPart, zCollist, zLimit
190970 );
190971 }else{
190972 zSql = sqlite3_mprintf(
190973 "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s "
190974 "UNION ALL "
190975 "SELECT %s, rbu_control FROM '%q' "
190976 "%s %s typeof(rbu_control)='integer' AND rbu_control!=1 "
190977 "ORDER BY %s%s",
190978 zCollist, p->zStateDb, pIter->zDataTbl, zPart,
190979 zCollist, pIter->zDataTbl,
190980 zPart,
190981 (zPart ? "AND" : "WHERE"),
190982 zCollist, zLimit
190983 );
190984 }
190985 p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql);
190986 }
@@ -190906,10 +190987,11 @@
190987
190988 sqlite3_free(zImposterCols);
190989 sqlite3_free(zImposterPK);
190990 sqlite3_free(zWhere);
190991 sqlite3_free(zBind);
190992 sqlite3_free(zPart);
190993 }else{
190994 int bRbuRowid = (pIter->eType==RBU_PK_VTAB)
190995 ||(pIter->eType==RBU_PK_NONE)
190996 ||(pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p));
190997 const char *zTbl = pIter->zTbl; /* Table this step applies to */
@@ -193339,11 +193421,11 @@
193421 ** rbu is in the RBU_STAGE_OAL state, use heap memory for *-shm space
193422 ** instead of a file on disk. */
193423 assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
193424 if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){
193425 if( iRegion<=p->nShm ){
193426 sqlite3_int64 nByte = (iRegion+1) * sizeof(char*);
193427 char **apNew = (char**)sqlite3_realloc64(p->apShm, nByte);
193428 if( apNew==0 ){
193429 rc = SQLITE_NOMEM;
193430 }else{
193431 memset(&apNew[p->nShm], 0, sizeof(char*) * (1 + iRegion - p->nShm));
@@ -195850,11 +195932,11 @@
195932 */
195933 static int sessionGrowHash(int bPatchset, SessionTable *pTab){
195934 if( pTab->nChange==0 || pTab->nEntry>=(pTab->nChange/2) ){
195935 int i;
195936 SessionChange **apNew;
195937 sqlite3_int64 nNew = 2*(sqlite3_int64)(pTab->nChange ? pTab->nChange : 128);
195938
195939 apNew = (SessionChange **)sqlite3_malloc64(sizeof(SessionChange *) * nNew);
195940 if( apNew==0 ){
195941 if( pTab->nChange==0 ){
195942 return SQLITE_ERROR;
@@ -196777,11 +196859,11 @@
196859 ** If not, use sqlite3_realloc() to grow the buffer so that there is.
196860 **
196861 ** If successful, return zero. Otherwise, if an OOM condition is encountered,
196862 ** set *pRc to SQLITE_NOMEM and return non-zero.
196863 */
196864 static int sessionBufferGrow(SessionBuffer *p, size_t nByte, int *pRc){
196865 if( *pRc==SQLITE_OK && p->nAlloc-p->nBuf<nByte ){
196866 u8 *aNew;
196867 i64 nNew = p->nAlloc ? p->nAlloc : 128;
196868 do {
196869 nNew = nNew*2;
@@ -197895,11 +197977,11 @@
197977 rc = SQLITE_CORRUPT_BKPT;
197978 }
197979 }
197980
197981 if( rc==SQLITE_OK ){
197982 size_t iPK = sizeof(sqlite3_value*)*p->nCol*2;
197983 memset(p->tblhdr.aBuf, 0, iPK);
197984 memcpy(&p->tblhdr.aBuf[iPK], &p->in.aData[p->in.iNext], nCopy);
197985 p->in.iNext += nCopy;
197986 }
197987
@@ -199199,11 +199281,11 @@
199281 SessionBuffer cons = pApply->constraints;
199282 memset(&pApply->constraints, 0, sizeof(SessionBuffer));
199283
199284 rc = sessionChangesetStart(&pIter2, 0, 0, cons.nBuf, cons.aBuf, 0);
199285 if( rc==SQLITE_OK ){
199286 size_t nByte = 2*pApply->nCol*sizeof(sqlite3_value*);
199287 int rc2;
199288 pIter2->bPatchset = bPatchset;
199289 pIter2->zTab = (char*)zTab;
199290 pIter2->nCol = pApply->nCol;
199291 pIter2->abPK = pApply->abPK;
@@ -212488,11 +212570,11 @@
212570 pWriter->aDlidx, sizeof(Fts5DlidxWriter) * nLvl
212571 );
212572 if( aDlidx==0 ){
212573 p->rc = SQLITE_NOMEM;
212574 }else{
212575 size_t nByte = sizeof(Fts5DlidxWriter) * (nLvl - pWriter->nDlidx);
212576 memset(&aDlidx[pWriter->nDlidx], 0, nByte);
212577 pWriter->aDlidx = aDlidx;
212578 pWriter->nDlidx = nLvl;
212579 }
212580 }
@@ -217839,18 +217921,18 @@
217921 ){
217922 Fts5Global *pGlobal = (Fts5Global*)pApi;
217923 int rc = sqlite3_overload_function(pGlobal->db, zName, -1);
217924 if( rc==SQLITE_OK ){
217925 Fts5Auxiliary *pAux;
217926 sqlite3_int64 nName; /* Size of zName in bytes, including \0 */
217927 sqlite3_int64 nByte; /* Bytes of space to allocate */
217928
217929 nName = strlen(zName) + 1;
217930 nByte = sizeof(Fts5Auxiliary) + nName;
217931 pAux = (Fts5Auxiliary*)sqlite3_malloc64(nByte);
217932 if( pAux ){
217933 memset(pAux, 0, (size_t)nByte);
217934 pAux->zFunc = (char*)&pAux[1];
217935 memcpy(pAux->zFunc, zName, nName);
217936 pAux->pGlobal = pGlobal;
217937 pAux->pUserData = pUserData;
217938 pAux->xFunc = xFunc;
@@ -217876,19 +217958,19 @@
217958 fts5_tokenizer *pTokenizer, /* Tokenizer implementation */
217959 void(*xDestroy)(void*) /* Destructor for pUserData */
217960 ){
217961 Fts5Global *pGlobal = (Fts5Global*)pApi;
217962 Fts5TokenizerModule *pNew;
217963 sqlite3_int64 nName; /* Size of zName and its \0 terminator */
217964 sqlite3_int64 nByte; /* Bytes of space to allocate */
217965 int rc = SQLITE_OK;
217966
217967 nName = strlen(zName) + 1;
217968 nByte = sizeof(Fts5TokenizerModule) + nName;
217969 pNew = (Fts5TokenizerModule*)sqlite3_malloc64(nByte);
217970 if( pNew ){
217971 memset(pNew, 0, (size_t)nByte);
217972 pNew->zName = (char*)&pNew[1];
217973 memcpy(pNew->zName, zName, nName);
217974 pNew->pUserData = pUserData;
217975 pNew->x = *pTokenizer;
217976 pNew->xDestroy = xDestroy;
@@ -218019,11 +218101,11 @@
218101 int nArg, /* Number of args */
218102 sqlite3_value **apUnused /* Function arguments */
218103 ){
218104 assert( nArg==0 );
218105 UNUSED_PARAM2(nArg, apUnused);
218106 sqlite3_result_text(pCtx, "fts5: 2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50", -1, SQLITE_TRANSIENT);
218107 }
218108
218109 /*
218110 ** Return true if zName is the extension on one of the shadow tables used
218111 ** by this module.
@@ -219664,11 +219746,11 @@
219746 int i;
219747 memset(p, 0, sizeof(Unicode61Tokenizer));
219748
219749 p->eRemoveDiacritic = FTS5_REMOVE_DIACRITICS_SIMPLE;
219750 p->nFold = 64;
219751 p->aFold = sqlite3_malloc64(p->nFold * sizeof(char));
219752 if( p->aFold==0 ){
219753 rc = SQLITE_NOMEM;
219754 }
219755
219756 /* Search for a "categories" argument */
@@ -222783,12 +222865,12 @@
222865 }
222866 #endif /* SQLITE_CORE */
222867 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
222868
222869 /************** End of stmt.c ************************************************/
222870 #if __LINE__!=222870
222871 #undef SQLITE_SOURCE_ID
222872 #define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f8315alt2"
222873 #endif
222874 /* Return the source-id for this library */
222875 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
222876 /************************** End of sqlite3.c ******************************/
222877
+1 -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.28.0"
127127
#define SQLITE_VERSION_NUMBER 3028000
128
-#define SQLITE_SOURCE_ID "2019-04-10 18:29:40 f294cfc173c5653ef161dbff63b7838dbccdcad797f5163c49b3173f9f35ab0f"
128
+#define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
134134
--- 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.28.0"
127 #define SQLITE_VERSION_NUMBER 3028000
128 #define SQLITE_SOURCE_ID "2019-04-10 18:29:40 f294cfc173c5653ef161dbff63b7838dbccdcad797f5163c49b3173f9f35ab0f"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
134
--- 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.28.0"
127 #define SQLITE_VERSION_NUMBER 3028000
128 #define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
134

Keyboard Shortcuts

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