Fossil SCM

Update the built-in SQLite to the second 3.21.0 beta.

drh 2017-10-21 19:37 trunk
Commit 7ac19afae36fce495a70f1e3b8907406e70d5b58e6b0ccf227da0737af11126f
3 files changed +14 -8 +495 -116 +9 -9
+14 -8
--- src/shell.c
+++ src/shell.c
@@ -2771,10 +2771,11 @@
27712771
z = sqlite3_mprintf("%s", azArg[0]);
27722772
j = 0;
27732773
for(i=0; IsSpace(z[i]); i++){}
27742774
for(; (c = z[i])!=0; i++){
27752775
if( IsSpace(c) ){
2776
+ if( z[j-1]=='\r' ) z[j-1] = '\n';
27762777
if( IsSpace(z[j-1]) || z[j-1]=='(' ) continue;
27772778
}else if( (c=='(' || c==')') && j>0 && IsSpace(z[j-1]) ){
27782779
j--;
27792780
}
27802781
z[j++] = c;
@@ -3798,10 +3799,11 @@
37983799
isIPK = 0;
37993800
}
38003801
}
38013802
}
38023803
sqlite3_finalize(pStmt);
3804
+ if( azCol==0 ) return 0;
38033805
azCol[0] = 0;
38043806
azCol[nCol+1] = 0;
38053807
38063808
/* The decision of whether or not a rowid really needs to be preserved
38073809
** is tricky. We never need to preserve a rowid for a WITHOUT ROWID table
@@ -4967,24 +4969,28 @@
49674969
{ "number of views:",
49684970
"SELECT count(*) FROM %s WHERE type='view'" },
49694971
{ "schema size:",
49704972
"SELECT total(length(sql)) FROM %s" },
49714973
};
4972
- sqlite3_file *pFile = 0;
49734974
int i;
49744975
char *zSchemaTab;
49754976
char *zDb = nArg>=2 ? azArg[1] : "main";
4977
+ sqlite3_stmt *pStmt = 0;
49764978
unsigned char aHdr[100];
49774979
open_db(p, 0);
49784980
if( p->db==0 ) return 1;
4979
- sqlite3_file_control(p->db, zDb, SQLITE_FCNTL_FILE_POINTER, &pFile);
4980
- if( pFile==0 || pFile->pMethods==0 || pFile->pMethods->xRead==0 ){
4981
- return 1;
4982
- }
4983
- i = pFile->pMethods->xRead(pFile, aHdr, 100, 0);
4984
- if( i!=SQLITE_OK ){
4981
+ sqlite3_prepare_v2(p->db,"SELECT data FROM sqlite_dbpage(?1) WHERE pgno=1",
4982
+ -1, &pStmt, 0);
4983
+ sqlite3_bind_text(pStmt, 1, zDb, -1, SQLITE_STATIC);
4984
+ if( sqlite3_step(pStmt)==SQLITE_ROW
4985
+ && sqlite3_column_bytes(pStmt,0)>100
4986
+ ){
4987
+ memcpy(aHdr, sqlite3_column_blob(pStmt,0), 100);
4988
+ sqlite3_finalize(pStmt);
4989
+ }else{
49854990
raw_printf(stderr, "unable to read database header\n");
4991
+ sqlite3_finalize(pStmt);
49864992
return 1;
49874993
}
49884994
i = get2byteInt(aHdr+16);
49894995
if( i==1 ) i = 65536;
49904996
utf8_printf(p->out, "%-20s %d\n", "database page size:", i);
@@ -5600,11 +5606,11 @@
56005606
rc = 2;
56015607
}else if( testcase_glob(azArg[1],zRes)==0 ){
56025608
utf8_printf(stderr,
56035609
"testcase-%s FAILED\n Expected: [%s]\n Got: [%s]\n",
56045610
p->zTestcase, azArg[1], zRes);
5605
- rc = 2;
5611
+ rc = 1;
56065612
}else{
56075613
utf8_printf(stdout, "testcase-%s ok\n", p->zTestcase);
56085614
p->nCheck++;
56095615
}
56105616
sqlite3_free(zRes);
56115617
--- src/shell.c
+++ src/shell.c
@@ -2771,10 +2771,11 @@
2771 z = sqlite3_mprintf("%s", azArg[0]);
2772 j = 0;
2773 for(i=0; IsSpace(z[i]); i++){}
2774 for(; (c = z[i])!=0; i++){
2775 if( IsSpace(c) ){
 
2776 if( IsSpace(z[j-1]) || z[j-1]=='(' ) continue;
2777 }else if( (c=='(' || c==')') && j>0 && IsSpace(z[j-1]) ){
2778 j--;
2779 }
2780 z[j++] = c;
@@ -3798,10 +3799,11 @@
3798 isIPK = 0;
3799 }
3800 }
3801 }
3802 sqlite3_finalize(pStmt);
 
3803 azCol[0] = 0;
3804 azCol[nCol+1] = 0;
3805
3806 /* The decision of whether or not a rowid really needs to be preserved
3807 ** is tricky. We never need to preserve a rowid for a WITHOUT ROWID table
@@ -4967,24 +4969,28 @@
4967 { "number of views:",
4968 "SELECT count(*) FROM %s WHERE type='view'" },
4969 { "schema size:",
4970 "SELECT total(length(sql)) FROM %s" },
4971 };
4972 sqlite3_file *pFile = 0;
4973 int i;
4974 char *zSchemaTab;
4975 char *zDb = nArg>=2 ? azArg[1] : "main";
 
4976 unsigned char aHdr[100];
4977 open_db(p, 0);
4978 if( p->db==0 ) return 1;
4979 sqlite3_file_control(p->db, zDb, SQLITE_FCNTL_FILE_POINTER, &pFile);
4980 if( pFile==0 || pFile->pMethods==0 || pFile->pMethods->xRead==0 ){
4981 return 1;
4982 }
4983 i = pFile->pMethods->xRead(pFile, aHdr, 100, 0);
4984 if( i!=SQLITE_OK ){
 
 
 
4985 raw_printf(stderr, "unable to read database header\n");
 
4986 return 1;
4987 }
4988 i = get2byteInt(aHdr+16);
4989 if( i==1 ) i = 65536;
4990 utf8_printf(p->out, "%-20s %d\n", "database page size:", i);
@@ -5600,11 +5606,11 @@
5600 rc = 2;
5601 }else if( testcase_glob(azArg[1],zRes)==0 ){
5602 utf8_printf(stderr,
5603 "testcase-%s FAILED\n Expected: [%s]\n Got: [%s]\n",
5604 p->zTestcase, azArg[1], zRes);
5605 rc = 2;
5606 }else{
5607 utf8_printf(stdout, "testcase-%s ok\n", p->zTestcase);
5608 p->nCheck++;
5609 }
5610 sqlite3_free(zRes);
5611
--- src/shell.c
+++ src/shell.c
@@ -2771,10 +2771,11 @@
2771 z = sqlite3_mprintf("%s", azArg[0]);
2772 j = 0;
2773 for(i=0; IsSpace(z[i]); i++){}
2774 for(; (c = z[i])!=0; i++){
2775 if( IsSpace(c) ){
2776 if( z[j-1]=='\r' ) z[j-1] = '\n';
2777 if( IsSpace(z[j-1]) || z[j-1]=='(' ) continue;
2778 }else if( (c=='(' || c==')') && j>0 && IsSpace(z[j-1]) ){
2779 j--;
2780 }
2781 z[j++] = c;
@@ -3798,10 +3799,11 @@
3799 isIPK = 0;
3800 }
3801 }
3802 }
3803 sqlite3_finalize(pStmt);
3804 if( azCol==0 ) return 0;
3805 azCol[0] = 0;
3806 azCol[nCol+1] = 0;
3807
3808 /* The decision of whether or not a rowid really needs to be preserved
3809 ** is tricky. We never need to preserve a rowid for a WITHOUT ROWID table
@@ -4967,24 +4969,28 @@
4969 { "number of views:",
4970 "SELECT count(*) FROM %s WHERE type='view'" },
4971 { "schema size:",
4972 "SELECT total(length(sql)) FROM %s" },
4973 };
 
4974 int i;
4975 char *zSchemaTab;
4976 char *zDb = nArg>=2 ? azArg[1] : "main";
4977 sqlite3_stmt *pStmt = 0;
4978 unsigned char aHdr[100];
4979 open_db(p, 0);
4980 if( p->db==0 ) return 1;
4981 sqlite3_prepare_v2(p->db,"SELECT data FROM sqlite_dbpage(?1) WHERE pgno=1",
4982 -1, &pStmt, 0);
4983 sqlite3_bind_text(pStmt, 1, zDb, -1, SQLITE_STATIC);
4984 if( sqlite3_step(pStmt)==SQLITE_ROW
4985 && sqlite3_column_bytes(pStmt,0)>100
4986 ){
4987 memcpy(aHdr, sqlite3_column_blob(pStmt,0), 100);
4988 sqlite3_finalize(pStmt);
4989 }else{
4990 raw_printf(stderr, "unable to read database header\n");
4991 sqlite3_finalize(pStmt);
4992 return 1;
4993 }
4994 i = get2byteInt(aHdr+16);
4995 if( i==1 ) i = 65536;
4996 utf8_printf(p->out, "%-20s %d\n", "database page size:", i);
@@ -5600,11 +5606,11 @@
5606 rc = 2;
5607 }else if( testcase_glob(azArg[1],zRes)==0 ){
5608 utf8_printf(stderr,
5609 "testcase-%s FAILED\n Expected: [%s]\n Got: [%s]\n",
5610 p->zTestcase, azArg[1], zRes);
5611 rc = 1;
5612 }else{
5613 utf8_printf(stdout, "testcase-%s ok\n", p->zTestcase);
5614 p->nCheck++;
5615 }
5616 sqlite3_free(zRes);
5617
+495 -116
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1147,11 +1147,11 @@
11471147
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11481148
** [sqlite_version()] and [sqlite_source_id()].
11491149
*/
11501150
#define SQLITE_VERSION "3.21.0"
11511151
#define SQLITE_VERSION_NUMBER 3021000
1152
-#define SQLITE_SOURCE_ID "2017-10-02 02:52:54 c9104b59c7ed360291f7f6fc8caae938e9840c77620d598e4096f78183bf807a"
1152
+#define SQLITE_SOURCE_ID "2017-10-21 17:17:17 fb3ee1b7cac09e4950e4f48b44c277e4f391cb6c8f069644732d2389ca653da4"
11531153
11541154
/*
11551155
** CAPI3REF: Run-Time Library Version Numbers
11561156
** KEYWORDS: sqlite3_version sqlite3_sourceid
11571157
**
@@ -10253,12 +10253,12 @@
1025310253
** a single table are grouped together, tables appear in the order in which
1025410254
** they were attached to the session object).
1025510255
*/
1025610256
SQLITE_API int sqlite3session_patchset(
1025710257
sqlite3_session *pSession, /* Session object */
10258
- int *pnPatchset, /* OUT: Size of buffer at *ppChangeset */
10259
- void **ppPatchset /* OUT: Buffer containing changeset */
10258
+ int *pnPatchset, /* OUT: Size of buffer at *ppPatchset */
10259
+ void **ppPatchset /* OUT: Buffer containing patchset */
1026010260
);
1026110261
1026210262
/*
1026310263
** CAPI3REF: Test if a changeset has recorded any changes.
1026410264
**
@@ -11021,16 +11021,16 @@
1102111021
** The six streaming API xxx_strm() functions serve similar purposes to the
1102211022
** corresponding non-streaming API functions:
1102311023
**
1102411024
** <table border=1 style="margin-left:8ex;margin-right:8ex">
1102511025
** <tr><th>Streaming function<th>Non-streaming equivalent</th>
11026
-** <tr><td>sqlite3changeset_apply_str<td>[sqlite3changeset_apply]
11027
-** <tr><td>sqlite3changeset_concat_str<td>[sqlite3changeset_concat]
11028
-** <tr><td>sqlite3changeset_invert_str<td>[sqlite3changeset_invert]
11029
-** <tr><td>sqlite3changeset_start_str<td>[sqlite3changeset_start]
11030
-** <tr><td>sqlite3session_changeset_str<td>[sqlite3session_changeset]
11031
-** <tr><td>sqlite3session_patchset_str<td>[sqlite3session_patchset]
11026
+** <tr><td>sqlite3changeset_apply_strm<td>[sqlite3changeset_apply]
11027
+** <tr><td>sqlite3changeset_concat_strm<td>[sqlite3changeset_concat]
11028
+** <tr><td>sqlite3changeset_invert_strm<td>[sqlite3changeset_invert]
11029
+** <tr><td>sqlite3changeset_start_strm<td>[sqlite3changeset_start]
11030
+** <tr><td>sqlite3session_changeset_strm<td>[sqlite3session_changeset]
11031
+** <tr><td>sqlite3session_patchset_strm<td>[sqlite3session_patchset]
1103211032
** </table>
1103311033
**
1103411034
** Non-streaming functions that accept changesets (or patchsets) as input
1103511035
** require that the entire changeset be stored in a single buffer in memory.
1103611036
** Similarly, those that return a changeset or patchset do so by returning
@@ -12246,10 +12246,25 @@
1224612246
#else
1224712247
# define ALWAYS(X) (X)
1224812248
# define NEVER(X) (X)
1224912249
#endif
1225012250
12251
+/*
12252
+** Some conditionals are optimizations only. In other words, if the
12253
+** conditionals are replaced with a constant 1 (true) or 0 (false) then
12254
+** the correct answer is still obtained, though perhaps not as quickly.
12255
+**
12256
+** The following macros mark these optimizations conditionals.
12257
+*/
12258
+#if defined(SQLITE_MUTATION_TEST)
12259
+# define OK_IF_ALWAYS_TRUE(X) (1)
12260
+# define OK_IF_ALWAYS_FALSE(X) (0)
12261
+#else
12262
+# define OK_IF_ALWAYS_TRUE(X) (X)
12263
+# define OK_IF_ALWAYS_FALSE(X) (X)
12264
+#endif
12265
+
1225112266
/*
1225212267
** Some malloc failures are only possible if SQLITE_TEST_REALLOC_STRESS is
1225312268
** defined. We need to defend against those failures when testing with
1225412269
** SQLITE_TEST_REALLOC_STRESS, but we don't want the unreachable branches
1225512270
** during a normal build. The following macro can be used to disable tests
@@ -12999,11 +13014,11 @@
1299913014
1300013015
/*
1300113016
** SELECTTRACE_ENABLED will be either 1 or 0 depending on whether or not
1300213017
** the Select query generator tracing logic is turned on.
1300313018
*/
13004
-#if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_SELECTTRACE)
13019
+#if defined(SQLITE_ENABLE_SELECTTRACE)
1300513020
# define SELECTTRACE_ENABLED 1
1300613021
#else
1300713022
# define SELECTTRACE_ENABLED 0
1300813023
#endif
1300913024
@@ -14766,14 +14781,16 @@
1476614781
SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file*,int,void*);
1476714782
SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file*,int,void*);
1476814783
#define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0
1476914784
SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id);
1477014785
SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id);
14786
+#ifndef SQLITE_OMIT_WAL
1477114787
SQLITE_PRIVATE int sqlite3OsShmMap(sqlite3_file *,int,int,int,void volatile **);
1477214788
SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int, int, int);
1477314789
SQLITE_PRIVATE void sqlite3OsShmBarrier(sqlite3_file *id);
1477414790
SQLITE_PRIVATE int sqlite3OsShmUnmap(sqlite3_file *id, int);
14791
+#endif /* SQLITE_OMIT_WAL */
1477514792
SQLITE_PRIVATE int sqlite3OsFetch(sqlite3_file *id, i64, int, void **);
1477614793
SQLITE_PRIVATE int sqlite3OsUnfetch(sqlite3_file *, i64, void *);
1477714794
1477814795
1477914796
/*
@@ -18158,10 +18175,13 @@
1815818175
#if SQLITE_MAX_WORKER_THREADS>0
1815918176
SQLITE_PRIVATE int sqlite3ThreadCreate(SQLiteThread**,void*(*)(void*),void*);
1816018177
SQLITE_PRIVATE int sqlite3ThreadJoin(SQLiteThread*, void**);
1816118178
#endif
1816218179
18180
+#if defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)
18181
+SQLITE_PRIVATE int sqlite3DbpageRegister(sqlite3*);
18182
+#endif
1816318183
#if defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)
1816418184
SQLITE_PRIVATE int sqlite3DbstatRegister(sqlite3*);
1816518185
#endif
1816618186
1816718187
SQLITE_PRIVATE int sqlite3ExprVectorSize(Expr *pExpr);
@@ -20823,10 +20843,11 @@
2082320843
return (xSectorSize ? xSectorSize(id) : SQLITE_DEFAULT_SECTOR_SIZE);
2082420844
}
2082520845
SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id){
2082620846
return id->pMethods->xDeviceCharacteristics(id);
2082720847
}
20848
+#ifndef SQLITE_OMIT_WAL
2082820849
SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int offset, int n, int flags){
2082920850
return id->pMethods->xShmLock(id, offset, n, flags);
2083020851
}
2083120852
SQLITE_PRIVATE void sqlite3OsShmBarrier(sqlite3_file *id){
2083220853
id->pMethods->xShmBarrier(id);
@@ -20842,10 +20863,11 @@
2084220863
void volatile **pp /* OUT: Pointer to mapping */
2084320864
){
2084420865
DO_OS_MALLOC_TEST(id);
2084520866
return id->pMethods->xShmMap(id, iPage, pgsz, bExtend, pp);
2084620867
}
20868
+#endif /* SQLITE_OMIT_WAL */
2084720869
2084820870
#if SQLITE_MAX_MMAP_SIZE>0
2084920871
/* The real implementation of xFetch and xUnfetch */
2085020872
SQLITE_PRIVATE int sqlite3OsFetch(sqlite3_file *id, i64 iOff, int iAmt, void **pp){
2085120873
DO_OS_MALLOC_TEST(id);
@@ -48663,10 +48685,12 @@
4866348685
|| defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
4866448686
int dc; /* Device characteristics */
4866548687
4866648688
assert( isOpen(pPager->fd) );
4866748689
dc = sqlite3OsDeviceCharacteristics(pPager->fd);
48690
+#else
48691
+ UNUSED_PARAMETER(pPager);
4866848692
#endif
4866948693
4867048694
#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
4867148695
if( dc&SQLITE_IOCAP_BATCH_ATOMIC ){
4867248696
return -1;
@@ -50467,10 +50491,12 @@
5046750491
** Otherwise, SQLITE_OK is returned.
5046850492
*/
5046950493
static int readDbPage(PgHdr *pPg){
5047050494
Pager *pPager = pPg->pPager; /* Pager object associated with page pPg */
5047150495
int rc = SQLITE_OK; /* Return code */
50496
+
50497
+#ifndef SQLITE_OMIT_WAL
5047250498
u32 iFrame = 0; /* Frame of WAL containing pgno */
5047350499
5047450500
assert( pPager->eState>=PAGER_READER && !MEMDB );
5047550501
assert( isOpen(pPager->fd) );
5047650502
@@ -50478,11 +50504,13 @@
5047850504
rc = sqlite3WalFindFrame(pPager->pWal, pPg->pgno, &iFrame);
5047950505
if( rc ) return rc;
5048050506
}
5048150507
if( iFrame ){
5048250508
rc = sqlite3WalReadFrame(pPager->pWal, iFrame,pPager->pageSize,pPg->pData);
50483
- }else{
50509
+ }else
50510
+#endif
50511
+ {
5048450512
i64 iOffset = (pPg->pgno-1)*(i64)pPager->pageSize;
5048550513
rc = sqlite3OsRead(pPager->fd, pPg->pData, pPager->pageSize, iOffset);
5048650514
if( rc==SQLITE_IOERR_SHORT_READ ){
5048750515
rc = SQLITE_OK;
5048850516
}
@@ -61683,11 +61711,11 @@
6168361711
static Pgno btreePagecount(BtShared *pBt){
6168461712
return pBt->nPage;
6168561713
}
6168661714
SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree *p){
6168761715
assert( sqlite3BtreeHoldsMutex(p) );
61688
- assert( ((p->pBt->nPage)&0x8000000)==0 );
61716
+ assert( ((p->pBt->nPage)&0x80000000)==0 );
6168961717
return btreePagecount(p->pBt);
6169061718
}
6169161719
6169261720
/*
6169361721
** Get a page from the pager and initialize it.
@@ -62565,11 +62593,12 @@
6256562593
** If the user has not set the safety-level for this database connection
6256662594
** using "PRAGMA synchronous", and if the safety-level is not already
6256762595
** set to the value passed to this function as the second parameter,
6256862596
** set it so.
6256962597
*/
62570
-#if SQLITE_DEFAULT_SYNCHRONOUS!=SQLITE_DEFAULT_WAL_SYNCHRONOUS
62598
+#if SQLITE_DEFAULT_SYNCHRONOUS!=SQLITE_DEFAULT_WAL_SYNCHRONOUS \
62599
+ && !defined(SQLITE_OMIT_WAL)
6257162600
static void setDefaultSyncFlag(BtShared *pBt, u8 safety_level){
6257262601
sqlite3 *db;
6257362602
Db *pDb;
6257462603
if( (db=pBt->db)!=0 && (pDb=db->aDb)!=0 ){
6257562604
while( pDb->pBt==0 || pDb->pBt->pBt!=pBt ){ pDb++; }
@@ -64466,22 +64495,27 @@
6446664495
*/
6446764496
static const void *fetchPayload(
6446864497
BtCursor *pCur, /* Cursor pointing to entry to read from */
6446964498
u32 *pAmt /* Write the number of available bytes here */
6447064499
){
64471
- u32 amt;
64500
+ int amt;
6447264501
assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage);
6447364502
assert( pCur->eState==CURSOR_VALID );
6447464503
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
6447564504
assert( cursorOwnsBtShared(pCur) );
6447664505
assert( pCur->ix<pCur->pPage->nCell );
6447764506
assert( pCur->info.nSize>0 );
6447864507
assert( pCur->info.pPayload>pCur->pPage->aData || CORRUPT_DB );
6447964508
assert( pCur->info.pPayload<pCur->pPage->aDataEnd ||CORRUPT_DB);
64480
- amt = (int)(pCur->pPage->aDataEnd - pCur->info.pPayload);
64481
- if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
64482
- *pAmt = amt;
64509
+ amt = pCur->info.nLocal;
64510
+ if( amt>(int)(pCur->pPage->aDataEnd - pCur->info.pPayload) ){
64511
+ /* There is too little space on the page for the expected amount
64512
+ ** of local content. Database must be corrupt. */
64513
+ assert( CORRUPT_DB );
64514
+ amt = MAX(0, (int)(pCur->pPage->aDataEnd - pCur->info.pPayload));
64515
+ }
64516
+ *pAmt = (u32)amt;
6448364517
return (void*)pCur->info.pPayload;
6448464518
}
6448564519
6448664520
6448764521
/*
@@ -66944,12 +66978,10 @@
6694466978
szScratch =
6694566979
nMaxCells*sizeof(u8*) /* b.apCell */
6694666980
+ nMaxCells*sizeof(u16) /* b.szCell */
6694766981
+ pBt->pageSize; /* aSpace1 */
6694866982
66949
- /* EVIDENCE-OF: R-28375-38319 SQLite will never request a scratch buffer
66950
- ** that is more than 6 times the database page size. */
6695166983
assert( szScratch<=6*(int)pBt->pageSize );
6695266984
b.apCell = sqlite3StackAllocRaw(0, szScratch );
6695366985
if( b.apCell==0 ){
6695466986
rc = SQLITE_NOMEM_BKPT;
6695566987
goto balance_cleanup;
@@ -75017,10 +75049,14 @@
7501775049
** To look at it another way, this routine resets the state of the
7501875050
** virtual machine from VDBE_MAGIC_RUN or VDBE_MAGIC_HALT back to
7501975051
** VDBE_MAGIC_INIT.
7502075052
*/
7502175053
SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){
75054
+#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
75055
+ int i;
75056
+#endif
75057
+
7502275058
sqlite3 *db;
7502375059
db = p->db;
7502475060
7502575061
/* If the VM did not run to completion or if it encountered an
7502675062
** error, then it might not have been halted properly. So halt
@@ -75048,11 +75084,10 @@
7504875084
/* Reset register contents and reclaim error message memory.
7504975085
*/
7505075086
#ifdef SQLITE_DEBUG
7505175087
/* Execute assert() statements to ensure that the Vdbe.apCsr[] and
7505275088
** Vdbe.aMem[] arrays have already been cleaned up. */
75053
- int i;
7505475089
if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
7505575090
if( p->aMem ){
7505675091
for(i=0; i<p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined );
7505775092
}
7505875093
#endif
@@ -75064,11 +75099,10 @@
7506475099
*/
7506575100
#ifdef VDBE_PROFILE
7506675101
{
7506775102
FILE *out = fopen("vdbe_profile.out", "a");
7506875103
if( out ){
75069
- int i;
7507075104
fprintf(out, "---- ");
7507175105
for(i=0; i<p->nOp; i++){
7507275106
fprintf(out, "%02x", p->aOp[i].opcode);
7507375107
}
7507475108
fprintf(out, "\n");
@@ -91194,16 +91228,14 @@
9119491228
int moreToDo = 1;
9119591229
9119691230
pOrderBy = pSelect->pOrderBy;
9119791231
if( pOrderBy==0 ) return 0;
9119891232
db = pParse->db;
91199
-#if SQLITE_MAX_COLUMN
9120091233
if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
9120191234
sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
9120291235
return 1;
9120391236
}
91204
-#endif
9120591237
for(i=0; i<pOrderBy->nExpr; i++){
9120691238
pOrderBy->a[i].done = 0;
9120791239
}
9120891240
pSelect->pNext = 0;
9120991241
while( pSelect->pPrior ){
@@ -91291,16 +91323,14 @@
9129191323
sqlite3 *db = pParse->db;
9129291324
ExprList *pEList;
9129391325
struct ExprList_item *pItem;
9129491326
9129591327
if( pOrderBy==0 || pParse->db->mallocFailed ) return 0;
91296
-#if SQLITE_MAX_COLUMN
9129791328
if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
9129891329
sqlite3ErrorMsg(pParse, "too many terms in %s BY clause", zType);
9129991330
return 1;
9130091331
}
91301
-#endif
9130291332
pEList = pSelect->pEList;
9130391333
assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */
9130491334
for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
9130591335
if( pItem->u.x.iOrderByCol ){
9130691336
if( pItem->u.x.iOrderByCol>pEList->nExpr ){
@@ -101733,16 +101763,14 @@
101733101763
char *z;
101734101764
char *zType;
101735101765
Column *pCol;
101736101766
sqlite3 *db = pParse->db;
101737101767
if( (p = pParse->pNewTable)==0 ) return;
101738
-#if SQLITE_MAX_COLUMN
101739101768
if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){
101740101769
sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName);
101741101770
return;
101742101771
}
101743
-#endif
101744101772
z = sqlite3DbMallocRaw(db, pName->n + pType->n + 2);
101745101773
if( z==0 ) return;
101746101774
memcpy(z, pName->z, pName->n);
101747101775
z[pName->n] = 0;
101748101776
sqlite3Dequote(z);
@@ -103036,18 +103064,10 @@
103036103064
** Code to update the sqlite_master tables and internal schema definitions
103037103065
** in case a root-page belonging to another table is moved by the btree layer
103038103066
** is also added (this can happen with an auto-vacuum database).
103039103067
*/
103040103068
static void destroyTable(Parse *pParse, Table *pTab){
103041
-#ifdef SQLITE_OMIT_AUTOVACUUM
103042
- Index *pIdx;
103043
- int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
103044
- destroyRootPage(pParse, pTab->tnum, iDb);
103045
- for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
103046
- destroyRootPage(pParse, pIdx->tnum, iDb);
103047
- }
103048
-#else
103049103069
/* If the database may be auto-vacuum capable (if SQLITE_OMIT_AUTOVACUUM
103050103070
** is not defined), then it is important to call OP_Destroy on the
103051103071
** table and index root-pages in order, starting with the numerically
103052103072
** largest root-page number. This guarantees that none of the root-pages
103053103073
** to be destroyed is relocated by an earlier OP_Destroy. i.e. if the
@@ -103086,11 +103106,10 @@
103086103106
assert( iDb>=0 && iDb<pParse->db->nDb );
103087103107
destroyRootPage(pParse, iLargest, iDb);
103088103108
iDestroyed = iLargest;
103089103109
}
103090103110
}
103091
-#endif
103092103111
}
103093103112
103094103113
/*
103095103114
** Remove entries from the sqlite_statN tables (for N in (1,2,3))
103096103115
** after a DROP INDEX or DROP TABLE command.
@@ -110324,11 +110343,10 @@
110324110343
IdList *pColumn, /* Column names corresponding to IDLIST. */
110325110344
int onError /* How to handle constraint errors */
110326110345
){
110327110346
sqlite3 *db; /* The main database structure */
110328110347
Table *pTab; /* The table to insert into. aka TABLE */
110329
- char *zTab; /* Name of the table into which we are inserting */
110330110348
int i, j; /* Loop counters */
110331110349
Vdbe *v; /* Generate code into this virtual machine */
110332110350
Index *pIdx; /* For looping over indices of the table */
110333110351
int nColumn; /* Number of columns in the data */
110334110352
int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
@@ -110380,12 +110398,10 @@
110380110398
}
110381110399
110382110400
/* Locate the table into which we will be inserting new information.
110383110401
*/
110384110402
assert( pTabList->nSrc==1 );
110385
- zTab = pTabList->a[0].zName;
110386
- if( NEVER(zTab==0) ) goto insert_cleanup;
110387110403
pTab = sqlite3SrcListLookup(pParse, pTabList);
110388110404
if( pTab==0 ){
110389110405
goto insert_cleanup;
110390110406
}
110391110407
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
@@ -112403,11 +112419,11 @@
112403112419
void (*result_value)(sqlite3_context*,sqlite3_value*);
112404112420
void * (*rollback_hook)(sqlite3*,void(*)(void*),void*);
112405112421
int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*,
112406112422
const char*,const char*),void*);
112407112423
void (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*));
112408
- char * (*snprintf)(int,char*,const char*,...);
112424
+ char * (*xsnprintf)(int,char*,const char*,...);
112409112425
int (*step)(sqlite3_stmt*);
112410112426
int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*,
112411112427
char const**,char const**,int*,int*,int*);
112412112428
void (*thread_cleanup)(void);
112413112429
int (*total_changes)(sqlite3*);
@@ -112687,11 +112703,11 @@
112687112703
#define sqlite3_result_text16le sqlite3_api->result_text16le
112688112704
#define sqlite3_result_value sqlite3_api->result_value
112689112705
#define sqlite3_rollback_hook sqlite3_api->rollback_hook
112690112706
#define sqlite3_set_authorizer sqlite3_api->set_authorizer
112691112707
#define sqlite3_set_auxdata sqlite3_api->set_auxdata
112692
-#define sqlite3_snprintf sqlite3_api->snprintf
112708
+#define sqlite3_snprintf sqlite3_api->xsnprintf
112693112709
#define sqlite3_step sqlite3_api->step
112694112710
#define sqlite3_table_column_metadata sqlite3_api->table_column_metadata
112695112711
#define sqlite3_thread_cleanup sqlite3_api->thread_cleanup
112696112712
#define sqlite3_total_changes sqlite3_api->total_changes
112697112713
#define sqlite3_trace sqlite3_api->trace
@@ -117748,11 +117764,11 @@
117748117764
sqlite3ExprListDelete(db, p->pGroupBy);
117749117765
sqlite3ExprDelete(db, p->pHaving);
117750117766
sqlite3ExprListDelete(db, p->pOrderBy);
117751117767
sqlite3ExprDelete(db, p->pLimit);
117752117768
sqlite3ExprDelete(db, p->pOffset);
117753
- if( p->pWith ) sqlite3WithDelete(db, p->pWith);
117769
+ if( OK_IF_ALWAYS_TRUE(p->pWith) ) sqlite3WithDelete(db, p->pWith);
117754117770
if( bFree ) sqlite3DbFreeNN(db, p);
117755117771
p = pPrior;
117756117772
bFree = 1;
117757117773
}
117758117774
}
@@ -117844,11 +117860,11 @@
117844117860
117845117861
/*
117846117862
** Delete the given Select structure and all of its substructures.
117847117863
*/
117848117864
SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
117849
- if( p ) clearSelect(db, p, 1);
117865
+ if( OK_IF_ALWAYS_TRUE(p) ) clearSelect(db, p, 1);
117850117866
}
117851117867
117852117868
/*
117853117869
** Return a pointer to the right-most SELECT statement in a compound.
117854117870
*/
@@ -118085,15 +118101,14 @@
118085118101
118086118102
pSrc = p->pSrc;
118087118103
pLeft = &pSrc->a[0];
118088118104
pRight = &pLeft[1];
118089118105
for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
118090
- Table *pLeftTab = pLeft->pTab;
118091118106
Table *pRightTab = pRight->pTab;
118092118107
int isOuter;
118093118108
118094
- if( NEVER(pLeftTab==0 || pRightTab==0) ) continue;
118109
+ if( NEVER(pLeft->pTab==0 || pRightTab==0) ) continue;
118095118110
isOuter = (pRight->fg.jointype & JT_OUTER)!=0;
118096118111
118097118112
/* When the NATURAL keyword is present, add WHERE clause terms for
118098118113
** every column that the two tables have in common.
118099118114
*/
@@ -119035,27 +119050,27 @@
119035119050
**
119036119051
** This routine has either 3 or 6 parameters depending on whether or not
119037119052
** the SQLITE_ENABLE_COLUMN_METADATA compile-time option is used.
119038119053
*/
119039119054
#ifdef SQLITE_ENABLE_COLUMN_METADATA
119040
-# define columnType(A,B,C,D,E,F) columnTypeImpl(A,B,C,D,E,F)
119055
+# define columnType(A,B,C,D,E) columnTypeImpl(A,B,C,D,E)
119041119056
#else /* if !defined(SQLITE_ENABLE_COLUMN_METADATA) */
119042
-# define columnType(A,B,C,D,E,F) columnTypeImpl(A,B,F)
119057
+# define columnType(A,B,C,D,E) columnTypeImpl(A,B)
119043119058
#endif
119044119059
static const char *columnTypeImpl(
119045119060
NameContext *pNC,
119061
+#ifndef SQLITE_ENABLE_COLUMN_METADATA
119062
+ Expr *pExpr
119063
+#else
119046119064
Expr *pExpr,
119047
-#ifdef SQLITE_ENABLE_COLUMN_METADATA
119048119065
const char **pzOrigDb,
119049119066
const char **pzOrigTab,
119050
- const char **pzOrigCol,
119067
+ const char **pzOrigCol
119051119068
#endif
119052
- u8 *pEstWidth
119053119069
){
119054119070
char const *zType = 0;
119055119071
int j;
119056
- u8 estWidth = 1;
119057119072
#ifdef SQLITE_ENABLE_COLUMN_METADATA
119058119073
char const *zOrigDb = 0;
119059119074
char const *zOrigTab = 0;
119060119075
char const *zOrigCol = 0;
119061119076
#endif
@@ -119120,37 +119135,36 @@
119120119135
NameContext sNC;
119121119136
Expr *p = pS->pEList->a[iCol].pExpr;
119122119137
sNC.pSrcList = pS->pSrc;
119123119138
sNC.pNext = pNC;
119124119139
sNC.pParse = pNC->pParse;
119125
- zType = columnType(&sNC, p,&zOrigDb,&zOrigTab,&zOrigCol, &estWidth);
119140
+ zType = columnType(&sNC, p,&zOrigDb,&zOrigTab,&zOrigCol);
119126119141
}
119127
- }else if( pTab->pSchema ){
119128
- /* A real table */
119142
+ }else{
119143
+ /* A real table or a CTE table */
119129119144
assert( !pS );
119145
+#ifdef SQLITE_ENABLE_COLUMN_METADATA
119130119146
if( iCol<0 ) iCol = pTab->iPKey;
119131
- assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
119132
-#ifdef SQLITE_ENABLE_COLUMN_METADATA
119147
+ assert( iCol==XN_ROWID || (iCol>=0 && iCol<pTab->nCol) );
119133119148
if( iCol<0 ){
119134119149
zType = "INTEGER";
119135119150
zOrigCol = "rowid";
119136119151
}else{
119137119152
zOrigCol = pTab->aCol[iCol].zName;
119138119153
zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
119139
- estWidth = pTab->aCol[iCol].szEst;
119140119154
}
119141119155
zOrigTab = pTab->zName;
119142
- if( pNC->pParse ){
119156
+ if( pNC->pParse && pTab->pSchema ){
119143119157
int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
119144119158
zOrigDb = pNC->pParse->db->aDb[iDb].zDbSName;
119145119159
}
119146119160
#else
119161
+ assert( iCol==XN_ROWID || (iCol>=0 && iCol<pTab->nCol) );
119147119162
if( iCol<0 ){
119148119163
zType = "INTEGER";
119149119164
}else{
119150119165
zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
119151
- estWidth = pTab->aCol[iCol].szEst;
119152119166
}
119153119167
#endif
119154119168
}
119155119169
break;
119156119170
}
@@ -119165,11 +119179,11 @@
119165119179
Expr *p = pS->pEList->a[0].pExpr;
119166119180
assert( ExprHasProperty(pExpr, EP_xIsSelect) );
119167119181
sNC.pSrcList = pS->pSrc;
119168119182
sNC.pNext = pNC;
119169119183
sNC.pParse = pNC->pParse;
119170
- zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol, &estWidth);
119184
+ zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol);
119171119185
break;
119172119186
}
119173119187
#endif
119174119188
}
119175119189
@@ -119179,11 +119193,10 @@
119179119193
*pzOrigDb = zOrigDb;
119180119194
*pzOrigTab = zOrigTab;
119181119195
*pzOrigCol = zOrigCol;
119182119196
}
119183119197
#endif
119184
- if( pEstWidth ) *pEstWidth = estWidth;
119185119198
return zType;
119186119199
}
119187119200
119188119201
/*
119189119202
** Generate code that will tell the VDBE the declaration types of columns
@@ -119206,21 +119219,21 @@
119206119219
const char *zType;
119207119220
#ifdef SQLITE_ENABLE_COLUMN_METADATA
119208119221
const char *zOrigDb = 0;
119209119222
const char *zOrigTab = 0;
119210119223
const char *zOrigCol = 0;
119211
- zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol, 0);
119224
+ zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol);
119212119225
119213119226
/* The vdbe must make its own copy of the column-type and other
119214119227
** column specific strings, in case the schema is reset before this
119215119228
** virtual machine is deleted.
119216119229
*/
119217119230
sqlite3VdbeSetColName(v, i, COLNAME_DATABASE, zOrigDb, SQLITE_TRANSIENT);
119218119231
sqlite3VdbeSetColName(v, i, COLNAME_TABLE, zOrigTab, SQLITE_TRANSIENT);
119219119232
sqlite3VdbeSetColName(v, i, COLNAME_COLUMN, zOrigCol, SQLITE_TRANSIENT);
119220119233
#else
119221
- zType = columnType(&sNC, p, 0, 0, 0, 0);
119234
+ zType = columnType(&sNC, p, 0, 0, 0);
119222119235
#endif
119223119236
sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
119224119237
}
119225119238
#endif /* !defined(SQLITE_OMIT_DECLTYPE) */
119226119239
}
@@ -119365,10 +119378,11 @@
119365119378
sqlite3HashInit(&ht);
119366119379
if( pEList ){
119367119380
nCol = pEList->nExpr;
119368119381
aCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
119369119382
testcase( aCol==0 );
119383
+ if( nCol>32767 ) nCol = 32767;
119370119384
}else{
119371119385
nCol = 0;
119372119386
aCol = 0;
119373119387
}
119374119388
assert( nCol==(i16)nCol );
@@ -119461,11 +119475,10 @@
119461119475
Column *pCol;
119462119476
CollSeq *pColl;
119463119477
int i;
119464119478
Expr *p;
119465119479
struct ExprList_item *a;
119466
- u64 szAll = 0;
119467119480
119468119481
assert( pSelect!=0 );
119469119482
assert( (pSelect->selFlags & SF_Resolved)!=0 );
119470119483
assert( pTab->nCol==pSelect->pEList->nExpr || db->mallocFailed );
119471119484
if( db->mallocFailed ) return;
@@ -119474,14 +119487,15 @@
119474119487
a = pSelect->pEList->a;
119475119488
for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
119476119489
const char *zType;
119477119490
int n, m;
119478119491
p = a[i].pExpr;
119479
- zType = columnType(&sNC, p, 0, 0, 0, &pCol->szEst);
119480
- szAll += pCol->szEst;
119492
+ zType = columnType(&sNC, p, 0, 0, 0);
119493
+ /* pCol->szEst = ... // Column size est for SELECT tables never used */
119481119494
pCol->affinity = sqlite3ExprAffinity(p);
119482
- if( zType && (m = sqlite3Strlen30(zType))>0 ){
119495
+ if( zType ){
119496
+ m = sqlite3Strlen30(zType);
119483119497
n = sqlite3Strlen30(pCol->zName);
119484119498
pCol->zName = sqlite3DbReallocOrFree(db, pCol->zName, n+m+2);
119485119499
if( pCol->zName ){
119486119500
memcpy(&pCol->zName[n+1], zType, m+1);
119487119501
pCol->colFlags |= COLFLAG_HASTYPE;
@@ -119491,11 +119505,11 @@
119491119505
pColl = sqlite3ExprCollSeq(pParse, p);
119492119506
if( pColl && pCol->zColl==0 ){
119493119507
pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
119494119508
}
119495119509
}
119496
- pTab->szTabRow = sqlite3LogEst(szAll*4);
119510
+ pTab->szTabRow = 1; /* Any non-zero value works */
119497119511
}
119498119512
119499119513
/*
119500119514
** Given a SELECT statement, generate a Table structure that describes
119501119515
** the result set of that SELECT.
@@ -121031,11 +121045,11 @@
121031121045
** until we introduced the group_concat() function.
121032121046
**
121033121047
** (17) If the subquery is a compound select, then
121034121048
** (17a) all compound operators must be a UNION ALL, and
121035121049
** (17b) no terms within the subquery compound may be aggregate
121036
-** or DISTINT, and
121050
+** or DISTINCT, and
121037121051
** (17c) every term within the subquery compound must have a FROM clause
121038121052
** (17d) the outer query may not be
121039121053
** (17d1) aggregate, or
121040121054
** (17d2) DISTINCT, or
121041121055
** (17d3) a join.
@@ -121058,23 +121072,25 @@
121058121072
** columns of the sub-query.
121059121073
**
121060121074
** (19) If the subquery uses LIMIT then the outer query may not
121061121075
** have a WHERE clause.
121062121076
**
121063
-** (20) If the sub-query is a compound select, then it must not use
121064
-** an ORDER BY clause. Ticket #3773. We could relax this constraint
121065
-** somewhat by saying that the terms of the ORDER BY clause must
121066
-** appear as unmodified result columns in the outer query. But we
121067
-** have other optimizations in mind to deal with that case.
121077
+** (**) Subsumed into (17d3). Was: If the sub-query is a compound select,
121078
+** then it must not use an ORDER BY clause - Ticket #3773. Because
121079
+** of (17d3), then only way to have a compound subquery is if it is
121080
+** the only term in the FROM clause of the outer query. But if the
121081
+** only term in the FROM clause has an ORDER BY, then it will be
121082
+** implemented as a co-routine and the flattener will never be called.
121068121083
**
121069121084
** (21) If the subquery uses LIMIT then the outer query may not be
121070121085
** DISTINCT. (See ticket [752e1646fc]).
121071121086
**
121072121087
** (22) The subquery may not be a recursive CTE.
121073121088
**
121074
-** (23) If the outer query is a recursive CTE, then the sub-query may not be
121075
-** a compound query. This restriction is because transforming the
121089
+** (**) Subsumed into restriction (17d3). Was: If the outer query is
121090
+** a recursive CTE, then the sub-query may not be a compound query.
121091
+** This restriction is because transforming the
121076121092
** parent to a compound query confuses the code that handles
121077121093
** recursive queries in multiSelect().
121078121094
**
121079121095
** (**) We no longer attempt to flatten aggregate subqueries. Was:
121080121096
** The subquery may not be an aggregate that uses the built-in min() or
@@ -121151,13 +121167,10 @@
121151121167
return 0; /* Restriction (21) */
121152121168
}
121153121169
if( pSub->selFlags & (SF_Recursive) ){
121154121170
return 0; /* Restrictions (22) */
121155121171
}
121156
- if( (p->selFlags & SF_Recursive) && pSub->pPrior ){
121157
- return 0; /* Restriction (23) */
121158
- }
121159121172
121160121173
/*
121161121174
** If the subquery is the right operand of a LEFT JOIN, then the
121162121175
** subquery may not be a join itself (3a). Example of why this is not
121163121176
** allowed:
@@ -121198,13 +121211,10 @@
121198121211
** use only the UNION ALL operator. And none of the simple select queries
121199121212
** that make up the compound SELECT are allowed to be aggregate or distinct
121200121213
** queries.
121201121214
*/
121202121215
if( pSub->pPrior ){
121203
- if( pSub->pOrderBy ){
121204
- return 0; /* Restriction (20) */
121205
- }
121206121216
if( isAgg || (p->selFlags & SF_Distinct)!=0 || pSrc->nSrc!=1 ){
121207121217
return 0; /* (17d1), (17d2), or (17d3) */
121208121218
}
121209121219
for(pSub1=pSub; pSub1; pSub1=pSub1->pPrior){
121210121220
testcase( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct );
@@ -121227,10 +121237,27 @@
121227121237
if( p->pOrderBy->a[ii].u.x.iOrderByCol==0 ) return 0;
121228121238
}
121229121239
}
121230121240
}
121231121241
121242
+ /* Ex-restriction (23):
121243
+ ** The only way that the recursive part of a CTE can contain a compound
121244
+ ** subquery is for the subquery to be one term of a join. But if the
121245
+ ** subquery is a join, then the flattening has already been stopped by
121246
+ ** restriction (17d3)
121247
+ */
121248
+ assert( (p->selFlags & SF_Recursive)==0 || pSub->pPrior==0 );
121249
+
121250
+ /* Ex-restriction (20):
121251
+ ** A compound subquery must be the only term in the FROM clause of the
121252
+ ** outer query by restriction (17d3). But if that term also has an
121253
+ ** ORDER BY clause, then the subquery will be implemented by co-routine
121254
+ ** and so the flattener will never be invoked. Hence, it is not possible
121255
+ ** for the subquery to be a compound and have an ORDER BY clause.
121256
+ */
121257
+ assert( pSub->pPrior==0 || pSub->pOrderBy==0 );
121258
+
121232121259
/***** If we reach this point, flattening is permitted. *****/
121233121260
SELECTTRACE(1,pParse,p,("flatten %s.%p from term %d\n",
121234121261
pSub->zSelName, pSub, iFrom));
121235121262
121236121263
/* Authorize the subquery */
@@ -121958,11 +121985,11 @@
121958121985
** sqlite3SelectExpand() when walking a SELECT tree to resolve table
121959121986
** names and other FROM clause elements.
121960121987
*/
121961121988
static void selectPopWith(Walker *pWalker, Select *p){
121962121989
Parse *pParse = pWalker->pParse;
121963
- if( pParse->pWith && p->pPrior==0 ){
121990
+ if( OK_IF_ALWAYS_TRUE(pParse->pWith) && p->pPrior==0 ){
121964121991
With *pWith = findRightmost(p)->pWith;
121965121992
if( pWith!=0 ){
121966121993
assert( pParse->pWith==pWith );
121967121994
pParse->pWith = pWith->pOuter;
121968121995
}
@@ -122013,11 +122040,11 @@
122013122040
if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
122014122041
return WRC_Prune;
122015122042
}
122016122043
pTabList = p->pSrc;
122017122044
pEList = p->pEList;
122018
- if( p->pWith ){
122045
+ if( OK_IF_ALWAYS_TRUE(p->pWith) ){
122019122046
sqlite3WithPush(pParse, p->pWith, 0);
122020122047
}
122021122048
122022122049
/* Make sure cursor numbers have been assigned to all entries in
122023122050
** the FROM clause of the SELECT statement.
@@ -122259,16 +122286,14 @@
122259122286
}
122260122287
}
122261122288
sqlite3ExprListDelete(db, pEList);
122262122289
p->pEList = pNew;
122263122290
}
122264
-#if SQLITE_MAX_COLUMN
122265122291
if( p->pEList && p->pEList->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
122266122292
sqlite3ErrorMsg(pParse, "too many columns in result set");
122267122293
return WRC_Abort;
122268122294
}
122269
-#endif
122270122295
return WRC_Continue;
122271122296
}
122272122297
122273122298
/*
122274122299
** No-op routine for the parse-tree walker.
@@ -122318,11 +122343,11 @@
122318122343
*/
122319122344
static void sqlite3SelectExpand(Parse *pParse, Select *pSelect){
122320122345
Walker w;
122321122346
w.xExprCallback = sqlite3ExprWalkNoop;
122322122347
w.pParse = pParse;
122323
- if( pParse->hasCompound ){
122348
+ if( OK_IF_ALWAYS_TRUE(pParse->hasCompound) ){
122324122349
w.xSelectCallback = convertCompoundSelectToSubquery;
122325122350
w.xSelectCallback2 = 0;
122326122351
sqlite3WalkSelect(&w, pSelect);
122327122352
}
122328122353
w.xSelectCallback = selectExpander;
@@ -122406,19 +122431,17 @@
122406122431
SQLITE_PRIVATE void sqlite3SelectPrep(
122407122432
Parse *pParse, /* The parser context */
122408122433
Select *p, /* The SELECT statement being coded. */
122409122434
NameContext *pOuterNC /* Name context for container */
122410122435
){
122411
- sqlite3 *db;
122412
- if( NEVER(p==0) ) return;
122413
- db = pParse->db;
122414
- if( db->mallocFailed ) return;
122436
+ assert( p!=0 || pParse->db->mallocFailed );
122437
+ if( pParse->db->mallocFailed ) return;
122415122438
if( p->selFlags & SF_HasTypeInfo ) return;
122416122439
sqlite3SelectExpand(pParse, p);
122417
- if( pParse->nErr || db->mallocFailed ) return;
122440
+ if( pParse->nErr || pParse->db->mallocFailed ) return;
122418122441
sqlite3ResolveSelectNames(pParse, p, pOuterNC);
122419
- if( pParse->nErr || db->mallocFailed ) return;
122442
+ if( pParse->nErr || pParse->db->mallocFailed ) return;
122420122443
sqlite3SelectAddTypeInfo(pParse, p);
122421122444
}
122422122445
122423122446
/*
122424122447
** Reset the aggregate accumulator.
@@ -126333,12 +126356,14 @@
126333126356
void *pAux, /* Context pointer for xCreate/xConnect */
126334126357
void (*xDestroy)(void *) /* Module destructor function */
126335126358
){
126336126359
Module *pMod;
126337126360
int nName = sqlite3Strlen30(zName);
126338
- pMod = (Module *)sqlite3DbMallocRawNN(db, sizeof(Module) + nName + 1);
126339
- if( pMod ){
126361
+ pMod = (Module *)sqlite3Malloc(sizeof(Module) + nName + 1);
126362
+ if( pMod==0 ){
126363
+ sqlite3OomFault(db);
126364
+ }else{
126340126365
Module *pDel;
126341126366
char *zCopy = (char *)(&pMod[1]);
126342126367
memcpy(zCopy, zName, nName+1);
126343126368
pMod->zName = zCopy;
126344126369
pMod->pModule = pModule;
@@ -126809,17 +126834,18 @@
126809126834
);
126810126835
return SQLITE_LOCKED;
126811126836
}
126812126837
}
126813126838
126814
- zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
126839
+ zModuleName = sqlite3DbStrDup(db, pTab->zName);
126815126840
if( !zModuleName ){
126816126841
return SQLITE_NOMEM_BKPT;
126817126842
}
126818126843
126819
- pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
126844
+ pVTable = sqlite3MallocZero(sizeof(VTable));
126820126845
if( !pVTable ){
126846
+ sqlite3OomFault(db);
126821126847
sqlite3DbFree(db, zModuleName);
126822126848
return SQLITE_NOMEM_BKPT;
126823126849
}
126824126850
pVTable->db = db;
126825126851
pVTable->pMod = pMod;
@@ -133669,22 +133695,23 @@
133669133695
133670133696
/*
133671133697
** Return TRUE if all of the following are true:
133672133698
**
133673133699
** (1) X has the same or lower cost that Y
133674
-** (2) X is a proper subset of Y
133675
-** (3) X skips at least as many columns as Y
133700
+** (2) X uses fewer WHERE clause terms than Y
133701
+** (3) Every WHERE clause term used by X is also used by Y
133702
+** (4) X skips at least as many columns as Y
133703
+** (5) If X is a covering index, than Y is too
133676133704
**
133677
-** By "proper subset" we mean that X uses fewer WHERE clause terms
133678
-** than Y and that every WHERE clause term used by X is also used
133679
-** by Y.
133680
-**
133705
+** Conditions (2) and (3) mean that X is a "proper subset" of Y.
133681133706
** If X is a proper subset of Y then Y is a better choice and ought
133682133707
** to have a lower cost. This routine returns TRUE when that cost
133683
-** relationship is inverted and needs to be adjusted. The third rule
133708
+** relationship is inverted and needs to be adjusted. Constraint (4)
133684133709
** was added because if X uses skip-scan less than Y it still might
133685
-** deserve a lower cost even if it is a proper subset of Y.
133710
+** deserve a lower cost even if it is a proper subset of Y. Constraint (5)
133711
+** was added because a covering index probably deserves to have a lower cost
133712
+** than a non-covering index even if it is a proper subset.
133686133713
*/
133687133714
static int whereLoopCheaperProperSubset(
133688133715
const WhereLoop *pX, /* First WhereLoop to compare */
133689133716
const WhereLoop *pY /* Compare against this WhereLoop */
133690133717
){
@@ -133701,10 +133728,14 @@
133701133728
if( pX->aLTerm[i]==0 ) continue;
133702133729
for(j=pY->nLTerm-1; j>=0; j--){
133703133730
if( pY->aLTerm[j]==pX->aLTerm[i] ) break;
133704133731
}
133705133732
if( j<0 ) return 0; /* X not a subset of Y since term X[i] not used by Y */
133733
+ }
133734
+ if( (pX->wsFlags&WHERE_IDX_ONLY)!=0
133735
+ && (pY->wsFlags&WHERE_IDX_ONLY)==0 ){
133736
+ return 0; /* Constraint (5) */
133706133737
}
133707133738
return 1; /* All conditions meet */
133708133739
}
133709133740
133710133741
/*
@@ -141996,13 +142027,15 @@
141996142027
/* IMPLEMENTATION-OF: R-53536-42575 The sqlite3_libversion() function returns
141997142028
** a pointer to the to the sqlite3_version[] string constant.
141998142029
*/
141999142030
SQLITE_API const char *sqlite3_libversion(void){ return sqlite3_version; }
142000142031
142001
-/* IMPLEMENTATION-OF: R-63124-39300 The sqlite3_sourceid() function returns a
142032
+/* IMPLEMENTATION-OF: R-25063-23286 The sqlite3_sourceid() function returns a
142002142033
** pointer to a string constant whose value is the same as the
142003
-** SQLITE_SOURCE_ID C preprocessor macro.
142034
+** SQLITE_SOURCE_ID C preprocessor macro. Except if SQLite is built using
142035
+** an edited copy of the amalgamation, then the last four characters of
142036
+** the hash might be different from SQLITE_SOURCE_ID.
142004142037
*/
142005142038
/* SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } */
142006142039
142007142040
/* IMPLEMENTATION-OF: R-35210-63508 The sqlite3_libversion_number() function
142008142041
** returns an integer equal to SQLITE_VERSION_NUMBER.
@@ -145000,10 +145033,16 @@
145000145033
#ifdef SQLITE_ENABLE_RTREE
145001145034
if( !db->mallocFailed && rc==SQLITE_OK){
145002145035
rc = sqlite3RtreeInit(db);
145003145036
}
145004145037
#endif
145038
+
145039
+#ifdef SQLITE_ENABLE_DBPAGE_VTAB
145040
+ if( !db->mallocFailed && rc==SQLITE_OK){
145041
+ rc = sqlite3DbpageRegister(db);
145042
+ }
145043
+#endif
145005145044
145006145045
#ifdef SQLITE_ENABLE_DBSTAT_VTAB
145007145046
if( !db->mallocFailed && rc==SQLITE_OK){
145008145047
rc = sqlite3DbstatRegister(db);
145009145048
}
@@ -145660,11 +145699,11 @@
145660145699
** sqlite3_test_control(SQLITE_TESTCTRL_ALWAYS, int X)
145661145700
**
145662145701
** This action provides a run-time test to see how the ALWAYS and
145663145702
** NEVER macros were defined at compile-time.
145664145703
**
145665
- ** The return value is ALWAYS(X).
145704
+ ** The return value is ALWAYS(X) if X is true, or 0 if X is false.
145666145705
**
145667145706
** The recommended test is X==2. If the return value is 2, that means
145668145707
** ALWAYS() and NEVER() are both no-op pass-through macros, which is the
145669145708
** default setting. If the return value is 1, then ALWAYS() is either
145670145709
** hard-coded to true or else it asserts if its argument is false.
@@ -145683,11 +145722,11 @@
145683145722
** // ALWAYS(x) is a constant 1. NEVER(x) is a constant 0.
145684145723
** }
145685145724
*/
145686145725
case SQLITE_TESTCTRL_ALWAYS: {
145687145726
int x = va_arg(ap,int);
145688
- rc = ALWAYS(x);
145727
+ rc = x ? ALWAYS(x) : 0;
145689145728
break;
145690145729
}
145691145730
145692145731
/*
145693145732
** sqlite3_test_control(SQLITE_TESTCTRL_BYTEORDER);
@@ -170889,10 +170928,17 @@
170889170928
#endif
170890170929
170891170930
/* Maximum number of prepared UPDATE statements held by this module */
170892170931
#define SQLITE_RBU_UPDATE_CACHESIZE 16
170893170932
170933
+/* Delta checksums disabled by default. Compile with -DRBU_ENABLE_DELTA_CKSUM
170934
+** to enable checksum verification.
170935
+*/
170936
+#ifndef RBU_ENABLE_DELTA_CKSUM
170937
+# define RBU_ENABLE_DELTA_CKSUM 0
170938
+#endif
170939
+
170894170940
/*
170895170941
** Swap two objects of type TYPE.
170896170942
*/
170897170943
#if !defined(SQLITE_AMALGAMATION)
170898170944
# define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;}
@@ -171263,10 +171309,11 @@
171263171309
*pLen -= z - zStart;
171264171310
*pz = (char*)z;
171265171311
return v;
171266171312
}
171267171313
171314
+#if RBU_ENABLE_DELTA_CKSUM
171268171315
/*
171269171316
** Compute a 32-bit checksum on the N-byte buffer. Return the result.
171270171317
*/
171271171318
static unsigned int rbuDeltaChecksum(const char *zIn, size_t N){
171272171319
const unsigned char *z = (const unsigned char *)zIn;
@@ -171297,10 +171344,11 @@
171297171344
case 1: sum3 += (z[0] << 24);
171298171345
default: ;
171299171346
}
171300171347
return sum3;
171301171348
}
171349
+#endif
171302171350
171303171351
/*
171304171352
** Apply a delta.
171305171353
**
171306171354
** The output buffer should be big enough to hold the whole output
@@ -171327,11 +171375,11 @@
171327171375
int lenDelta, /* Length of the delta */
171328171376
char *zOut /* Write the output into this preallocated buffer */
171329171377
){
171330171378
unsigned int limit;
171331171379
unsigned int total = 0;
171332
-#ifndef FOSSIL_OMIT_DELTA_CKSUM_TEST
171380
+#if RBU_ENABLE_DELTA_CKSUM
171333171381
char *zOrigOut = zOut;
171334171382
#endif
171335171383
171336171384
limit = rbuDeltaGetInt(&zDelta, &lenDelta);
171337171385
if( *zDelta!='\n' ){
@@ -171382,11 +171430,11 @@
171382171430
break;
171383171431
}
171384171432
case ';': {
171385171433
zDelta++; lenDelta--;
171386171434
zOut[0] = 0;
171387
-#ifndef FOSSIL_OMIT_DELTA_CKSUM_TEST
171435
+#if RBU_ENABLE_DELTA_CKSUM
171388171436
if( cnt!=rbuDeltaChecksum(zOrigOut, total) ){
171389171437
/* ERROR: bad checksum */
171390171438
return -1;
171391171439
}
171392171440
#endif
@@ -176366,10 +176414,342 @@
176366176414
#elif defined(SQLITE_ENABLE_DBSTAT_VTAB)
176367176415
SQLITE_PRIVATE int sqlite3DbstatRegister(sqlite3 *db){ return SQLITE_OK; }
176368176416
#endif /* SQLITE_ENABLE_DBSTAT_VTAB */
176369176417
176370176418
/************** End of dbstat.c **********************************************/
176419
+/************** Begin file dbpage.c ******************************************/
176420
+/*
176421
+** 2017-10-11
176422
+**
176423
+** The author disclaims copyright to this source code. In place of
176424
+** a legal notice, here is a blessing:
176425
+**
176426
+** May you do good and not evil.
176427
+** May you find forgiveness for yourself and forgive others.
176428
+** May you share freely, never taking more than you give.
176429
+**
176430
+******************************************************************************
176431
+**
176432
+** This file contains an implementation of the "sqlite_dbpage" virtual table.
176433
+**
176434
+** The sqlite_dbpage virtual table is used to read or write whole raw
176435
+** pages of the database file. The pager interface is used so that
176436
+** uncommitted changes and changes recorded in the WAL file are correctly
176437
+** retrieved.
176438
+**
176439
+** Usage example:
176440
+**
176441
+** SELECT data FROM sqlite_dbpage('aux1') WHERE pgno=123;
176442
+**
176443
+** This is an eponymous virtual table so it does not need to be created before
176444
+** use. The optional argument to the sqlite_dbpage() table name is the
176445
+** schema for the database file that is to be read. The default schema is
176446
+** "main".
176447
+**
176448
+** The data field of sqlite_dbpage table can be updated. The new
176449
+** value must be a BLOB which is the correct page size, otherwise the
176450
+** update fails. Rows may not be deleted or inserted.
176451
+*/
176452
+
176453
+/* #include "sqliteInt.h" ** Requires access to internal data structures ** */
176454
+#if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \
176455
+ && !defined(SQLITE_OMIT_VIRTUALTABLE)
176456
+
176457
+typedef struct DbpageTable DbpageTable;
176458
+typedef struct DbpageCursor DbpageCursor;
176459
+
176460
+struct DbpageCursor {
176461
+ sqlite3_vtab_cursor base; /* Base class. Must be first */
176462
+ int pgno; /* Current page number */
176463
+ int mxPgno; /* Last page to visit on this scan */
176464
+};
176465
+
176466
+struct DbpageTable {
176467
+ sqlite3_vtab base; /* Base class. Must be first */
176468
+ sqlite3 *db; /* The database */
176469
+ Pager *pPager; /* Pager being read/written */
176470
+ int iDb; /* Index of database to analyze */
176471
+ int szPage; /* Size of each page in bytes */
176472
+ int nPage; /* Number of pages in the file */
176473
+};
176474
+
176475
+/*
176476
+** Connect to or create a dbpagevfs virtual table.
176477
+*/
176478
+static int dbpageConnect(
176479
+ sqlite3 *db,
176480
+ void *pAux,
176481
+ int argc, const char *const*argv,
176482
+ sqlite3_vtab **ppVtab,
176483
+ char **pzErr
176484
+){
176485
+ DbpageTable *pTab = 0;
176486
+ int rc = SQLITE_OK;
176487
+ int iDb;
176488
+
176489
+ if( argc>=4 ){
176490
+ Token nm;
176491
+ sqlite3TokenInit(&nm, (char*)argv[3]);
176492
+ iDb = sqlite3FindDb(db, &nm);
176493
+ if( iDb<0 ){
176494
+ *pzErr = sqlite3_mprintf("no such schema: %s", argv[3]);
176495
+ return SQLITE_ERROR;
176496
+ }
176497
+ }else{
176498
+ iDb = 0;
176499
+ }
176500
+ rc = sqlite3_declare_vtab(db,
176501
+ "CREATE TABLE x(pgno INTEGER PRIMARY KEY, data BLOB, schema HIDDEN)");
176502
+ if( rc==SQLITE_OK ){
176503
+ pTab = (DbpageTable *)sqlite3_malloc64(sizeof(DbpageTable));
176504
+ if( pTab==0 ) rc = SQLITE_NOMEM_BKPT;
176505
+ }
176506
+
176507
+ assert( rc==SQLITE_OK || pTab==0 );
176508
+ if( rc==SQLITE_OK ){
176509
+ Btree *pBt = db->aDb[iDb].pBt;
176510
+ memset(pTab, 0, sizeof(DbpageTable));
176511
+ pTab->db = db;
176512
+ pTab->iDb = iDb;
176513
+ pTab->pPager = pBt ? sqlite3BtreePager(pBt) : 0;
176514
+ }
176515
+
176516
+ *ppVtab = (sqlite3_vtab*)pTab;
176517
+ return rc;
176518
+}
176519
+
176520
+/*
176521
+** Disconnect from or destroy a dbpagevfs virtual table.
176522
+*/
176523
+static int dbpageDisconnect(sqlite3_vtab *pVtab){
176524
+ sqlite3_free(pVtab);
176525
+ return SQLITE_OK;
176526
+}
176527
+
176528
+/*
176529
+** idxNum:
176530
+**
176531
+** 0 full table scan
176532
+** 1 pgno=?1
176533
+*/
176534
+static int dbpageBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
176535
+ int i;
176536
+ pIdxInfo->estimatedCost = 1.0e6; /* Initial cost estimate */
176537
+ for(i=0; i<pIdxInfo->nConstraint; i++){
176538
+ struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[i];
176539
+ if( p->usable && p->iColumn<=0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
176540
+ pIdxInfo->estimatedRows = 1;
176541
+ pIdxInfo->idxFlags = SQLITE_INDEX_SCAN_UNIQUE;
176542
+ pIdxInfo->estimatedCost = 1.0;
176543
+ pIdxInfo->idxNum = 1;
176544
+ pIdxInfo->aConstraintUsage[i].argvIndex = 1;
176545
+ pIdxInfo->aConstraintUsage[i].omit = 1;
176546
+ break;
176547
+ }
176548
+ }
176549
+ if( pIdxInfo->nOrderBy>=1
176550
+ && pIdxInfo->aOrderBy[0].iColumn<=0
176551
+ && pIdxInfo->aOrderBy[0].desc==0
176552
+ ){
176553
+ pIdxInfo->orderByConsumed = 1;
176554
+ }
176555
+ return SQLITE_OK;
176556
+}
176557
+
176558
+/*
176559
+** Open a new dbpagevfs cursor.
176560
+*/
176561
+static int dbpageOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
176562
+ DbpageCursor *pCsr;
176563
+
176564
+ pCsr = (DbpageCursor *)sqlite3_malloc64(sizeof(DbpageCursor));
176565
+ if( pCsr==0 ){
176566
+ return SQLITE_NOMEM_BKPT;
176567
+ }else{
176568
+ memset(pCsr, 0, sizeof(DbpageCursor));
176569
+ pCsr->base.pVtab = pVTab;
176570
+ pCsr->pgno = -1;
176571
+ }
176572
+
176573
+ *ppCursor = (sqlite3_vtab_cursor *)pCsr;
176574
+ return SQLITE_OK;
176575
+}
176576
+
176577
+/*
176578
+** Close a dbpagevfs cursor.
176579
+*/
176580
+static int dbpageClose(sqlite3_vtab_cursor *pCursor){
176581
+ DbpageCursor *pCsr = (DbpageCursor *)pCursor;
176582
+ sqlite3_free(pCsr);
176583
+ return SQLITE_OK;
176584
+}
176585
+
176586
+/*
176587
+** Move a dbpagevfs cursor to the next entry in the file.
176588
+*/
176589
+static int dbpageNext(sqlite3_vtab_cursor *pCursor){
176590
+ int rc = SQLITE_OK;
176591
+ DbpageCursor *pCsr = (DbpageCursor *)pCursor;
176592
+ pCsr->pgno++;
176593
+ return rc;
176594
+}
176595
+
176596
+static int dbpageEof(sqlite3_vtab_cursor *pCursor){
176597
+ DbpageCursor *pCsr = (DbpageCursor *)pCursor;
176598
+ return pCsr->pgno > pCsr->mxPgno;
176599
+}
176600
+
176601
+static int dbpageFilter(
176602
+ sqlite3_vtab_cursor *pCursor,
176603
+ int idxNum, const char *idxStr,
176604
+ int argc, sqlite3_value **argv
176605
+){
176606
+ DbpageCursor *pCsr = (DbpageCursor *)pCursor;
176607
+ DbpageTable *pTab = (DbpageTable *)pCursor->pVtab;
176608
+ int rc = SQLITE_OK;
176609
+ Btree *pBt = pTab->db->aDb[pTab->iDb].pBt;
176610
+
176611
+ pTab->szPage = sqlite3BtreeGetPageSize(pBt);
176612
+ pTab->nPage = sqlite3BtreeLastPage(pBt);
176613
+ if( idxNum==1 ){
176614
+ pCsr->pgno = sqlite3_value_int(argv[0]);
176615
+ if( pCsr->pgno<1 || pCsr->pgno>pTab->nPage ){
176616
+ pCsr->pgno = 1;
176617
+ pCsr->mxPgno = 0;
176618
+ }else{
176619
+ pCsr->mxPgno = pCsr->pgno;
176620
+ }
176621
+ }else{
176622
+ pCsr->pgno = 1;
176623
+ pCsr->mxPgno = pTab->nPage;
176624
+ }
176625
+ return rc;
176626
+}
176627
+
176628
+static int dbpageColumn(
176629
+ sqlite3_vtab_cursor *pCursor,
176630
+ sqlite3_context *ctx,
176631
+ int i
176632
+){
176633
+ DbpageCursor *pCsr = (DbpageCursor *)pCursor;
176634
+ DbpageTable *pTab = (DbpageTable *)pCursor->pVtab;
176635
+ int rc = SQLITE_OK;
176636
+ switch( i ){
176637
+ case 0: { /* pgno */
176638
+ sqlite3_result_int(ctx, pCsr->pgno);
176639
+ break;
176640
+ }
176641
+ case 1: { /* data */
176642
+ DbPage *pDbPage = 0;
176643
+ rc = sqlite3PagerGet(pTab->pPager, pCsr->pgno, (DbPage**)&pDbPage, 0);
176644
+ if( rc==SQLITE_OK ){
176645
+ sqlite3_result_blob(ctx, sqlite3PagerGetData(pDbPage), pTab->szPage,
176646
+ SQLITE_TRANSIENT);
176647
+ }
176648
+ sqlite3PagerUnref(pDbPage);
176649
+ break;
176650
+ }
176651
+ default: { /* schema */
176652
+ sqlite3 *db = sqlite3_context_db_handle(ctx);
176653
+ sqlite3_result_text(ctx, db->aDb[pTab->iDb].zDbSName, -1, SQLITE_STATIC);
176654
+ break;
176655
+ }
176656
+ }
176657
+ return SQLITE_OK;
176658
+}
176659
+
176660
+static int dbpageRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
176661
+ DbpageCursor *pCsr = (DbpageCursor *)pCursor;
176662
+ *pRowid = pCsr->pgno;
176663
+ return SQLITE_OK;
176664
+}
176665
+
176666
+static int dbpageUpdate(
176667
+ sqlite3_vtab *pVtab,
176668
+ int argc,
176669
+ sqlite3_value **argv,
176670
+ sqlite_int64 *pRowid
176671
+){
176672
+ DbpageTable *pTab = (DbpageTable *)pVtab;
176673
+ int pgno;
176674
+ DbPage *pDbPage = 0;
176675
+ int rc = SQLITE_OK;
176676
+ char *zErr = 0;
176677
+
176678
+ if( argc==1 ){
176679
+ zErr = "cannot delete";
176680
+ goto update_fail;
176681
+ }
176682
+ pgno = sqlite3_value_int(argv[0]);
176683
+ if( pgno<1 || pgno>pTab->nPage ){
176684
+ zErr = "bad page number";
176685
+ goto update_fail;
176686
+ }
176687
+ if( sqlite3_value_int(argv[1])!=pgno ){
176688
+ zErr = "cannot insert";
176689
+ goto update_fail;
176690
+ }
176691
+ if( sqlite3_value_type(argv[3])!=SQLITE_BLOB
176692
+ || sqlite3_value_bytes(argv[3])!=pTab->szPage
176693
+ ){
176694
+ zErr = "bad page value";
176695
+ goto update_fail;
176696
+ }
176697
+ rc = sqlite3PagerGet(pTab->pPager, pgno, (DbPage**)&pDbPage, 0);
176698
+ if( rc==SQLITE_OK ){
176699
+ rc = sqlite3PagerWrite(pDbPage);
176700
+ if( rc==SQLITE_OK ){
176701
+ memcpy(sqlite3PagerGetData(pDbPage),
176702
+ sqlite3_value_blob(argv[3]),
176703
+ pTab->szPage);
176704
+ }
176705
+ }
176706
+ sqlite3PagerUnref(pDbPage);
176707
+ return rc;
176708
+
176709
+update_fail:
176710
+ sqlite3_free(pVtab->zErrMsg);
176711
+ pVtab->zErrMsg = sqlite3_mprintf("%s", zErr);
176712
+ return SQLITE_ERROR;
176713
+}
176714
+
176715
+/*
176716
+** Invoke this routine to register the "dbpage" virtual table module
176717
+*/
176718
+SQLITE_PRIVATE int sqlite3DbpageRegister(sqlite3 *db){
176719
+ static sqlite3_module dbpage_module = {
176720
+ 0, /* iVersion */
176721
+ dbpageConnect, /* xCreate */
176722
+ dbpageConnect, /* xConnect */
176723
+ dbpageBestIndex, /* xBestIndex */
176724
+ dbpageDisconnect, /* xDisconnect */
176725
+ dbpageDisconnect, /* xDestroy */
176726
+ dbpageOpen, /* xOpen - open a cursor */
176727
+ dbpageClose, /* xClose - close a cursor */
176728
+ dbpageFilter, /* xFilter - configure scan constraints */
176729
+ dbpageNext, /* xNext - advance a cursor */
176730
+ dbpageEof, /* xEof - check for end of scan */
176731
+ dbpageColumn, /* xColumn - read data */
176732
+ dbpageRowid, /* xRowid - read data */
176733
+ dbpageUpdate, /* xUpdate */
176734
+ 0, /* xBegin */
176735
+ 0, /* xSync */
176736
+ 0, /* xCommit */
176737
+ 0, /* xRollback */
176738
+ 0, /* xFindMethod */
176739
+ 0, /* xRename */
176740
+ 0, /* xSavepoint */
176741
+ 0, /* xRelease */
176742
+ 0, /* xRollbackTo */
176743
+ };
176744
+ return sqlite3_create_module(db, "sqlite_dbpage", &dbpage_module, 0);
176745
+}
176746
+#elif defined(SQLITE_ENABLE_DBPAGE_VTAB)
176747
+SQLITE_PRIVATE int sqlite3DbpageRegister(sqlite3 *db){ return SQLITE_OK; }
176748
+#endif /* SQLITE_ENABLE_DBSTAT_VTAB */
176749
+
176750
+/************** End of dbpage.c **********************************************/
176371176751
/************** Begin file sqlite3session.c **********************************/
176372176752
176373176753
#if defined(SQLITE_ENABLE_SESSION) && defined(SQLITE_ENABLE_PREUPDATE_HOOK)
176374176754
/* #include "sqlite3session.h" */
176375176755
/* #include <assert.h> */
@@ -200697,11 +201077,11 @@
200697201077
int nArg, /* Number of args */
200698201078
sqlite3_value **apUnused /* Function arguments */
200699201079
){
200700201080
assert( nArg==0 );
200701201081
UNUSED_PARAM2(nArg, apUnused);
200702
- sqlite3_result_text(pCtx, "fts5: 2017-09-29 16:07:56 0840f9f824c16212ce3fd6c859e501176eb0a58924ea1728a54d5bdfd0c25c86", -1, SQLITE_TRANSIENT);
201082
+ sqlite3_result_text(pCtx, "fts5: 2017-10-19 15:17:38 04925dee41a21ffca9a9f9df27d8165431668c42c2b33d08b077fdb28011170b", -1, SQLITE_TRANSIENT);
200703201083
}
200704201084
200705201085
static int fts5Init(sqlite3 *db){
200706201086
static const sqlite3_module fts5Mod = {
200707201087
/* iVersion */ 2,
@@ -204579,11 +204959,10 @@
204579204959
iVal = pCsr->aDoc[0];
204580204960
}else{
204581204961
iVal = pCsr->aCnt[0];
204582204962
}
204583204963
}else{
204584
- int eDetail = pCsr->pConfig->eDetail;
204585204964
assert( eType==FTS5_VOCAB_INSTANCE );
204586204965
switch( iCol ){
204587204966
case 1:
204588204967
sqlite3_result_int64(pCtx, pCsr->pIter->iRowid);
204589204968
break;
@@ -204590,11 +204969,11 @@
204590204969
case 2: {
204591204970
int ii = -1;
204592204971
if( eDetail==FTS5_DETAIL_FULL ){
204593204972
ii = FTS5_POS2COLUMN(pCsr->iInstPos);
204594204973
}else if( eDetail==FTS5_DETAIL_COLUMNS ){
204595
- ii = pCsr->iInstPos;
204974
+ ii = (int)pCsr->iInstPos;
204596204975
}
204597204976
if( ii>=0 && ii<pCsr->pConfig->nCol ){
204598204977
const char *z = pCsr->pConfig->azCol[ii];
204599204978
sqlite3_result_text(pCtx, z, -1, SQLITE_STATIC);
204600204979
}
@@ -204966,12 +205345,12 @@
204966205345
}
204967205346
#endif /* SQLITE_CORE */
204968205347
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
204969205348
204970205349
/************** End of stmt.c ************************************************/
204971
-#if __LINE__!=204971
205350
+#if __LINE__!=205350
204972205351
#undef SQLITE_SOURCE_ID
204973
-#define SQLITE_SOURCE_ID "2017-10-02 02:52:54 c9104b59c7ed360291f7f6fc8caae938e9840c77620d598e4096f78183bfalt2"
205352
+#define SQLITE_SOURCE_ID "2017-10-21 17:17:17 fb3ee1b7cac09e4950e4f48b44c277e4f391cb6c8f069644732d2389ca65alt2"
204974205353
#endif
204975205354
/* Return the source-id for this library */
204976205355
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
204977205356
/************************** End of sqlite3.c ******************************/
204978205357
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1147,11 +1147,11 @@
1147 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1148 ** [sqlite_version()] and [sqlite_source_id()].
1149 */
1150 #define SQLITE_VERSION "3.21.0"
1151 #define SQLITE_VERSION_NUMBER 3021000
1152 #define SQLITE_SOURCE_ID "2017-10-02 02:52:54 c9104b59c7ed360291f7f6fc8caae938e9840c77620d598e4096f78183bf807a"
1153
1154 /*
1155 ** CAPI3REF: Run-Time Library Version Numbers
1156 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1157 **
@@ -10253,12 +10253,12 @@
10253 ** a single table are grouped together, tables appear in the order in which
10254 ** they were attached to the session object).
10255 */
10256 SQLITE_API int sqlite3session_patchset(
10257 sqlite3_session *pSession, /* Session object */
10258 int *pnPatchset, /* OUT: Size of buffer at *ppChangeset */
10259 void **ppPatchset /* OUT: Buffer containing changeset */
10260 );
10261
10262 /*
10263 ** CAPI3REF: Test if a changeset has recorded any changes.
10264 **
@@ -11021,16 +11021,16 @@
11021 ** The six streaming API xxx_strm() functions serve similar purposes to the
11022 ** corresponding non-streaming API functions:
11023 **
11024 ** <table border=1 style="margin-left:8ex;margin-right:8ex">
11025 ** <tr><th>Streaming function<th>Non-streaming equivalent</th>
11026 ** <tr><td>sqlite3changeset_apply_str<td>[sqlite3changeset_apply]
11027 ** <tr><td>sqlite3changeset_concat_str<td>[sqlite3changeset_concat]
11028 ** <tr><td>sqlite3changeset_invert_str<td>[sqlite3changeset_invert]
11029 ** <tr><td>sqlite3changeset_start_str<td>[sqlite3changeset_start]
11030 ** <tr><td>sqlite3session_changeset_str<td>[sqlite3session_changeset]
11031 ** <tr><td>sqlite3session_patchset_str<td>[sqlite3session_patchset]
11032 ** </table>
11033 **
11034 ** Non-streaming functions that accept changesets (or patchsets) as input
11035 ** require that the entire changeset be stored in a single buffer in memory.
11036 ** Similarly, those that return a changeset or patchset do so by returning
@@ -12246,10 +12246,25 @@
12246 #else
12247 # define ALWAYS(X) (X)
12248 # define NEVER(X) (X)
12249 #endif
12250
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12251 /*
12252 ** Some malloc failures are only possible if SQLITE_TEST_REALLOC_STRESS is
12253 ** defined. We need to defend against those failures when testing with
12254 ** SQLITE_TEST_REALLOC_STRESS, but we don't want the unreachable branches
12255 ** during a normal build. The following macro can be used to disable tests
@@ -12999,11 +13014,11 @@
12999
13000 /*
13001 ** SELECTTRACE_ENABLED will be either 1 or 0 depending on whether or not
13002 ** the Select query generator tracing logic is turned on.
13003 */
13004 #if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_SELECTTRACE)
13005 # define SELECTTRACE_ENABLED 1
13006 #else
13007 # define SELECTTRACE_ENABLED 0
13008 #endif
13009
@@ -14766,14 +14781,16 @@
14766 SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file*,int,void*);
14767 SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file*,int,void*);
14768 #define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0
14769 SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id);
14770 SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id);
 
14771 SQLITE_PRIVATE int sqlite3OsShmMap(sqlite3_file *,int,int,int,void volatile **);
14772 SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int, int, int);
14773 SQLITE_PRIVATE void sqlite3OsShmBarrier(sqlite3_file *id);
14774 SQLITE_PRIVATE int sqlite3OsShmUnmap(sqlite3_file *id, int);
 
14775 SQLITE_PRIVATE int sqlite3OsFetch(sqlite3_file *id, i64, int, void **);
14776 SQLITE_PRIVATE int sqlite3OsUnfetch(sqlite3_file *, i64, void *);
14777
14778
14779 /*
@@ -18158,10 +18175,13 @@
18158 #if SQLITE_MAX_WORKER_THREADS>0
18159 SQLITE_PRIVATE int sqlite3ThreadCreate(SQLiteThread**,void*(*)(void*),void*);
18160 SQLITE_PRIVATE int sqlite3ThreadJoin(SQLiteThread*, void**);
18161 #endif
18162
 
 
 
18163 #if defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)
18164 SQLITE_PRIVATE int sqlite3DbstatRegister(sqlite3*);
18165 #endif
18166
18167 SQLITE_PRIVATE int sqlite3ExprVectorSize(Expr *pExpr);
@@ -20823,10 +20843,11 @@
20823 return (xSectorSize ? xSectorSize(id) : SQLITE_DEFAULT_SECTOR_SIZE);
20824 }
20825 SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id){
20826 return id->pMethods->xDeviceCharacteristics(id);
20827 }
 
20828 SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int offset, int n, int flags){
20829 return id->pMethods->xShmLock(id, offset, n, flags);
20830 }
20831 SQLITE_PRIVATE void sqlite3OsShmBarrier(sqlite3_file *id){
20832 id->pMethods->xShmBarrier(id);
@@ -20842,10 +20863,11 @@
20842 void volatile **pp /* OUT: Pointer to mapping */
20843 ){
20844 DO_OS_MALLOC_TEST(id);
20845 return id->pMethods->xShmMap(id, iPage, pgsz, bExtend, pp);
20846 }
 
20847
20848 #if SQLITE_MAX_MMAP_SIZE>0
20849 /* The real implementation of xFetch and xUnfetch */
20850 SQLITE_PRIVATE int sqlite3OsFetch(sqlite3_file *id, i64 iOff, int iAmt, void **pp){
20851 DO_OS_MALLOC_TEST(id);
@@ -48663,10 +48685,12 @@
48663 || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
48664 int dc; /* Device characteristics */
48665
48666 assert( isOpen(pPager->fd) );
48667 dc = sqlite3OsDeviceCharacteristics(pPager->fd);
 
 
48668 #endif
48669
48670 #ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
48671 if( dc&SQLITE_IOCAP_BATCH_ATOMIC ){
48672 return -1;
@@ -50467,10 +50491,12 @@
50467 ** Otherwise, SQLITE_OK is returned.
50468 */
50469 static int readDbPage(PgHdr *pPg){
50470 Pager *pPager = pPg->pPager; /* Pager object associated with page pPg */
50471 int rc = SQLITE_OK; /* Return code */
 
 
50472 u32 iFrame = 0; /* Frame of WAL containing pgno */
50473
50474 assert( pPager->eState>=PAGER_READER && !MEMDB );
50475 assert( isOpen(pPager->fd) );
50476
@@ -50478,11 +50504,13 @@
50478 rc = sqlite3WalFindFrame(pPager->pWal, pPg->pgno, &iFrame);
50479 if( rc ) return rc;
50480 }
50481 if( iFrame ){
50482 rc = sqlite3WalReadFrame(pPager->pWal, iFrame,pPager->pageSize,pPg->pData);
50483 }else{
 
 
50484 i64 iOffset = (pPg->pgno-1)*(i64)pPager->pageSize;
50485 rc = sqlite3OsRead(pPager->fd, pPg->pData, pPager->pageSize, iOffset);
50486 if( rc==SQLITE_IOERR_SHORT_READ ){
50487 rc = SQLITE_OK;
50488 }
@@ -61683,11 +61711,11 @@
61683 static Pgno btreePagecount(BtShared *pBt){
61684 return pBt->nPage;
61685 }
61686 SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree *p){
61687 assert( sqlite3BtreeHoldsMutex(p) );
61688 assert( ((p->pBt->nPage)&0x8000000)==0 );
61689 return btreePagecount(p->pBt);
61690 }
61691
61692 /*
61693 ** Get a page from the pager and initialize it.
@@ -62565,11 +62593,12 @@
62565 ** If the user has not set the safety-level for this database connection
62566 ** using "PRAGMA synchronous", and if the safety-level is not already
62567 ** set to the value passed to this function as the second parameter,
62568 ** set it so.
62569 */
62570 #if SQLITE_DEFAULT_SYNCHRONOUS!=SQLITE_DEFAULT_WAL_SYNCHRONOUS
 
62571 static void setDefaultSyncFlag(BtShared *pBt, u8 safety_level){
62572 sqlite3 *db;
62573 Db *pDb;
62574 if( (db=pBt->db)!=0 && (pDb=db->aDb)!=0 ){
62575 while( pDb->pBt==0 || pDb->pBt->pBt!=pBt ){ pDb++; }
@@ -64466,22 +64495,27 @@
64466 */
64467 static const void *fetchPayload(
64468 BtCursor *pCur, /* Cursor pointing to entry to read from */
64469 u32 *pAmt /* Write the number of available bytes here */
64470 ){
64471 u32 amt;
64472 assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage);
64473 assert( pCur->eState==CURSOR_VALID );
64474 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
64475 assert( cursorOwnsBtShared(pCur) );
64476 assert( pCur->ix<pCur->pPage->nCell );
64477 assert( pCur->info.nSize>0 );
64478 assert( pCur->info.pPayload>pCur->pPage->aData || CORRUPT_DB );
64479 assert( pCur->info.pPayload<pCur->pPage->aDataEnd ||CORRUPT_DB);
64480 amt = (int)(pCur->pPage->aDataEnd - pCur->info.pPayload);
64481 if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
64482 *pAmt = amt;
 
 
 
 
 
64483 return (void*)pCur->info.pPayload;
64484 }
64485
64486
64487 /*
@@ -66944,12 +66978,10 @@
66944 szScratch =
66945 nMaxCells*sizeof(u8*) /* b.apCell */
66946 + nMaxCells*sizeof(u16) /* b.szCell */
66947 + pBt->pageSize; /* aSpace1 */
66948
66949 /* EVIDENCE-OF: R-28375-38319 SQLite will never request a scratch buffer
66950 ** that is more than 6 times the database page size. */
66951 assert( szScratch<=6*(int)pBt->pageSize );
66952 b.apCell = sqlite3StackAllocRaw(0, szScratch );
66953 if( b.apCell==0 ){
66954 rc = SQLITE_NOMEM_BKPT;
66955 goto balance_cleanup;
@@ -75017,10 +75049,14 @@
75017 ** To look at it another way, this routine resets the state of the
75018 ** virtual machine from VDBE_MAGIC_RUN or VDBE_MAGIC_HALT back to
75019 ** VDBE_MAGIC_INIT.
75020 */
75021 SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){
 
 
 
 
75022 sqlite3 *db;
75023 db = p->db;
75024
75025 /* If the VM did not run to completion or if it encountered an
75026 ** error, then it might not have been halted properly. So halt
@@ -75048,11 +75084,10 @@
75048 /* Reset register contents and reclaim error message memory.
75049 */
75050 #ifdef SQLITE_DEBUG
75051 /* Execute assert() statements to ensure that the Vdbe.apCsr[] and
75052 ** Vdbe.aMem[] arrays have already been cleaned up. */
75053 int i;
75054 if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
75055 if( p->aMem ){
75056 for(i=0; i<p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined );
75057 }
75058 #endif
@@ -75064,11 +75099,10 @@
75064 */
75065 #ifdef VDBE_PROFILE
75066 {
75067 FILE *out = fopen("vdbe_profile.out", "a");
75068 if( out ){
75069 int i;
75070 fprintf(out, "---- ");
75071 for(i=0; i<p->nOp; i++){
75072 fprintf(out, "%02x", p->aOp[i].opcode);
75073 }
75074 fprintf(out, "\n");
@@ -91194,16 +91228,14 @@
91194 int moreToDo = 1;
91195
91196 pOrderBy = pSelect->pOrderBy;
91197 if( pOrderBy==0 ) return 0;
91198 db = pParse->db;
91199 #if SQLITE_MAX_COLUMN
91200 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
91201 sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
91202 return 1;
91203 }
91204 #endif
91205 for(i=0; i<pOrderBy->nExpr; i++){
91206 pOrderBy->a[i].done = 0;
91207 }
91208 pSelect->pNext = 0;
91209 while( pSelect->pPrior ){
@@ -91291,16 +91323,14 @@
91291 sqlite3 *db = pParse->db;
91292 ExprList *pEList;
91293 struct ExprList_item *pItem;
91294
91295 if( pOrderBy==0 || pParse->db->mallocFailed ) return 0;
91296 #if SQLITE_MAX_COLUMN
91297 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
91298 sqlite3ErrorMsg(pParse, "too many terms in %s BY clause", zType);
91299 return 1;
91300 }
91301 #endif
91302 pEList = pSelect->pEList;
91303 assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */
91304 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
91305 if( pItem->u.x.iOrderByCol ){
91306 if( pItem->u.x.iOrderByCol>pEList->nExpr ){
@@ -101733,16 +101763,14 @@
101733 char *z;
101734 char *zType;
101735 Column *pCol;
101736 sqlite3 *db = pParse->db;
101737 if( (p = pParse->pNewTable)==0 ) return;
101738 #if SQLITE_MAX_COLUMN
101739 if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){
101740 sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName);
101741 return;
101742 }
101743 #endif
101744 z = sqlite3DbMallocRaw(db, pName->n + pType->n + 2);
101745 if( z==0 ) return;
101746 memcpy(z, pName->z, pName->n);
101747 z[pName->n] = 0;
101748 sqlite3Dequote(z);
@@ -103036,18 +103064,10 @@
103036 ** Code to update the sqlite_master tables and internal schema definitions
103037 ** in case a root-page belonging to another table is moved by the btree layer
103038 ** is also added (this can happen with an auto-vacuum database).
103039 */
103040 static void destroyTable(Parse *pParse, Table *pTab){
103041 #ifdef SQLITE_OMIT_AUTOVACUUM
103042 Index *pIdx;
103043 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
103044 destroyRootPage(pParse, pTab->tnum, iDb);
103045 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
103046 destroyRootPage(pParse, pIdx->tnum, iDb);
103047 }
103048 #else
103049 /* If the database may be auto-vacuum capable (if SQLITE_OMIT_AUTOVACUUM
103050 ** is not defined), then it is important to call OP_Destroy on the
103051 ** table and index root-pages in order, starting with the numerically
103052 ** largest root-page number. This guarantees that none of the root-pages
103053 ** to be destroyed is relocated by an earlier OP_Destroy. i.e. if the
@@ -103086,11 +103106,10 @@
103086 assert( iDb>=0 && iDb<pParse->db->nDb );
103087 destroyRootPage(pParse, iLargest, iDb);
103088 iDestroyed = iLargest;
103089 }
103090 }
103091 #endif
103092 }
103093
103094 /*
103095 ** Remove entries from the sqlite_statN tables (for N in (1,2,3))
103096 ** after a DROP INDEX or DROP TABLE command.
@@ -110324,11 +110343,10 @@
110324 IdList *pColumn, /* Column names corresponding to IDLIST. */
110325 int onError /* How to handle constraint errors */
110326 ){
110327 sqlite3 *db; /* The main database structure */
110328 Table *pTab; /* The table to insert into. aka TABLE */
110329 char *zTab; /* Name of the table into which we are inserting */
110330 int i, j; /* Loop counters */
110331 Vdbe *v; /* Generate code into this virtual machine */
110332 Index *pIdx; /* For looping over indices of the table */
110333 int nColumn; /* Number of columns in the data */
110334 int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
@@ -110380,12 +110398,10 @@
110380 }
110381
110382 /* Locate the table into which we will be inserting new information.
110383 */
110384 assert( pTabList->nSrc==1 );
110385 zTab = pTabList->a[0].zName;
110386 if( NEVER(zTab==0) ) goto insert_cleanup;
110387 pTab = sqlite3SrcListLookup(pParse, pTabList);
110388 if( pTab==0 ){
110389 goto insert_cleanup;
110390 }
110391 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
@@ -112403,11 +112419,11 @@
112403 void (*result_value)(sqlite3_context*,sqlite3_value*);
112404 void * (*rollback_hook)(sqlite3*,void(*)(void*),void*);
112405 int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*,
112406 const char*,const char*),void*);
112407 void (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*));
112408 char * (*snprintf)(int,char*,const char*,...);
112409 int (*step)(sqlite3_stmt*);
112410 int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*,
112411 char const**,char const**,int*,int*,int*);
112412 void (*thread_cleanup)(void);
112413 int (*total_changes)(sqlite3*);
@@ -112687,11 +112703,11 @@
112687 #define sqlite3_result_text16le sqlite3_api->result_text16le
112688 #define sqlite3_result_value sqlite3_api->result_value
112689 #define sqlite3_rollback_hook sqlite3_api->rollback_hook
112690 #define sqlite3_set_authorizer sqlite3_api->set_authorizer
112691 #define sqlite3_set_auxdata sqlite3_api->set_auxdata
112692 #define sqlite3_snprintf sqlite3_api->snprintf
112693 #define sqlite3_step sqlite3_api->step
112694 #define sqlite3_table_column_metadata sqlite3_api->table_column_metadata
112695 #define sqlite3_thread_cleanup sqlite3_api->thread_cleanup
112696 #define sqlite3_total_changes sqlite3_api->total_changes
112697 #define sqlite3_trace sqlite3_api->trace
@@ -117748,11 +117764,11 @@
117748 sqlite3ExprListDelete(db, p->pGroupBy);
117749 sqlite3ExprDelete(db, p->pHaving);
117750 sqlite3ExprListDelete(db, p->pOrderBy);
117751 sqlite3ExprDelete(db, p->pLimit);
117752 sqlite3ExprDelete(db, p->pOffset);
117753 if( p->pWith ) sqlite3WithDelete(db, p->pWith);
117754 if( bFree ) sqlite3DbFreeNN(db, p);
117755 p = pPrior;
117756 bFree = 1;
117757 }
117758 }
@@ -117844,11 +117860,11 @@
117844
117845 /*
117846 ** Delete the given Select structure and all of its substructures.
117847 */
117848 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
117849 if( p ) clearSelect(db, p, 1);
117850 }
117851
117852 /*
117853 ** Return a pointer to the right-most SELECT statement in a compound.
117854 */
@@ -118085,15 +118101,14 @@
118085
118086 pSrc = p->pSrc;
118087 pLeft = &pSrc->a[0];
118088 pRight = &pLeft[1];
118089 for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
118090 Table *pLeftTab = pLeft->pTab;
118091 Table *pRightTab = pRight->pTab;
118092 int isOuter;
118093
118094 if( NEVER(pLeftTab==0 || pRightTab==0) ) continue;
118095 isOuter = (pRight->fg.jointype & JT_OUTER)!=0;
118096
118097 /* When the NATURAL keyword is present, add WHERE clause terms for
118098 ** every column that the two tables have in common.
118099 */
@@ -119035,27 +119050,27 @@
119035 **
119036 ** This routine has either 3 or 6 parameters depending on whether or not
119037 ** the SQLITE_ENABLE_COLUMN_METADATA compile-time option is used.
119038 */
119039 #ifdef SQLITE_ENABLE_COLUMN_METADATA
119040 # define columnType(A,B,C,D,E,F) columnTypeImpl(A,B,C,D,E,F)
119041 #else /* if !defined(SQLITE_ENABLE_COLUMN_METADATA) */
119042 # define columnType(A,B,C,D,E,F) columnTypeImpl(A,B,F)
119043 #endif
119044 static const char *columnTypeImpl(
119045 NameContext *pNC,
 
 
 
119046 Expr *pExpr,
119047 #ifdef SQLITE_ENABLE_COLUMN_METADATA
119048 const char **pzOrigDb,
119049 const char **pzOrigTab,
119050 const char **pzOrigCol,
119051 #endif
119052 u8 *pEstWidth
119053 ){
119054 char const *zType = 0;
119055 int j;
119056 u8 estWidth = 1;
119057 #ifdef SQLITE_ENABLE_COLUMN_METADATA
119058 char const *zOrigDb = 0;
119059 char const *zOrigTab = 0;
119060 char const *zOrigCol = 0;
119061 #endif
@@ -119120,37 +119135,36 @@
119120 NameContext sNC;
119121 Expr *p = pS->pEList->a[iCol].pExpr;
119122 sNC.pSrcList = pS->pSrc;
119123 sNC.pNext = pNC;
119124 sNC.pParse = pNC->pParse;
119125 zType = columnType(&sNC, p,&zOrigDb,&zOrigTab,&zOrigCol, &estWidth);
119126 }
119127 }else if( pTab->pSchema ){
119128 /* A real table */
119129 assert( !pS );
 
119130 if( iCol<0 ) iCol = pTab->iPKey;
119131 assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
119132 #ifdef SQLITE_ENABLE_COLUMN_METADATA
119133 if( iCol<0 ){
119134 zType = "INTEGER";
119135 zOrigCol = "rowid";
119136 }else{
119137 zOrigCol = pTab->aCol[iCol].zName;
119138 zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
119139 estWidth = pTab->aCol[iCol].szEst;
119140 }
119141 zOrigTab = pTab->zName;
119142 if( pNC->pParse ){
119143 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
119144 zOrigDb = pNC->pParse->db->aDb[iDb].zDbSName;
119145 }
119146 #else
 
119147 if( iCol<0 ){
119148 zType = "INTEGER";
119149 }else{
119150 zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
119151 estWidth = pTab->aCol[iCol].szEst;
119152 }
119153 #endif
119154 }
119155 break;
119156 }
@@ -119165,11 +119179,11 @@
119165 Expr *p = pS->pEList->a[0].pExpr;
119166 assert( ExprHasProperty(pExpr, EP_xIsSelect) );
119167 sNC.pSrcList = pS->pSrc;
119168 sNC.pNext = pNC;
119169 sNC.pParse = pNC->pParse;
119170 zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol, &estWidth);
119171 break;
119172 }
119173 #endif
119174 }
119175
@@ -119179,11 +119193,10 @@
119179 *pzOrigDb = zOrigDb;
119180 *pzOrigTab = zOrigTab;
119181 *pzOrigCol = zOrigCol;
119182 }
119183 #endif
119184 if( pEstWidth ) *pEstWidth = estWidth;
119185 return zType;
119186 }
119187
119188 /*
119189 ** Generate code that will tell the VDBE the declaration types of columns
@@ -119206,21 +119219,21 @@
119206 const char *zType;
119207 #ifdef SQLITE_ENABLE_COLUMN_METADATA
119208 const char *zOrigDb = 0;
119209 const char *zOrigTab = 0;
119210 const char *zOrigCol = 0;
119211 zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol, 0);
119212
119213 /* The vdbe must make its own copy of the column-type and other
119214 ** column specific strings, in case the schema is reset before this
119215 ** virtual machine is deleted.
119216 */
119217 sqlite3VdbeSetColName(v, i, COLNAME_DATABASE, zOrigDb, SQLITE_TRANSIENT);
119218 sqlite3VdbeSetColName(v, i, COLNAME_TABLE, zOrigTab, SQLITE_TRANSIENT);
119219 sqlite3VdbeSetColName(v, i, COLNAME_COLUMN, zOrigCol, SQLITE_TRANSIENT);
119220 #else
119221 zType = columnType(&sNC, p, 0, 0, 0, 0);
119222 #endif
119223 sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
119224 }
119225 #endif /* !defined(SQLITE_OMIT_DECLTYPE) */
119226 }
@@ -119365,10 +119378,11 @@
119365 sqlite3HashInit(&ht);
119366 if( pEList ){
119367 nCol = pEList->nExpr;
119368 aCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
119369 testcase( aCol==0 );
 
119370 }else{
119371 nCol = 0;
119372 aCol = 0;
119373 }
119374 assert( nCol==(i16)nCol );
@@ -119461,11 +119475,10 @@
119461 Column *pCol;
119462 CollSeq *pColl;
119463 int i;
119464 Expr *p;
119465 struct ExprList_item *a;
119466 u64 szAll = 0;
119467
119468 assert( pSelect!=0 );
119469 assert( (pSelect->selFlags & SF_Resolved)!=0 );
119470 assert( pTab->nCol==pSelect->pEList->nExpr || db->mallocFailed );
119471 if( db->mallocFailed ) return;
@@ -119474,14 +119487,15 @@
119474 a = pSelect->pEList->a;
119475 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
119476 const char *zType;
119477 int n, m;
119478 p = a[i].pExpr;
119479 zType = columnType(&sNC, p, 0, 0, 0, &pCol->szEst);
119480 szAll += pCol->szEst;
119481 pCol->affinity = sqlite3ExprAffinity(p);
119482 if( zType && (m = sqlite3Strlen30(zType))>0 ){
 
119483 n = sqlite3Strlen30(pCol->zName);
119484 pCol->zName = sqlite3DbReallocOrFree(db, pCol->zName, n+m+2);
119485 if( pCol->zName ){
119486 memcpy(&pCol->zName[n+1], zType, m+1);
119487 pCol->colFlags |= COLFLAG_HASTYPE;
@@ -119491,11 +119505,11 @@
119491 pColl = sqlite3ExprCollSeq(pParse, p);
119492 if( pColl && pCol->zColl==0 ){
119493 pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
119494 }
119495 }
119496 pTab->szTabRow = sqlite3LogEst(szAll*4);
119497 }
119498
119499 /*
119500 ** Given a SELECT statement, generate a Table structure that describes
119501 ** the result set of that SELECT.
@@ -121031,11 +121045,11 @@
121031 ** until we introduced the group_concat() function.
121032 **
121033 ** (17) If the subquery is a compound select, then
121034 ** (17a) all compound operators must be a UNION ALL, and
121035 ** (17b) no terms within the subquery compound may be aggregate
121036 ** or DISTINT, and
121037 ** (17c) every term within the subquery compound must have a FROM clause
121038 ** (17d) the outer query may not be
121039 ** (17d1) aggregate, or
121040 ** (17d2) DISTINCT, or
121041 ** (17d3) a join.
@@ -121058,23 +121072,25 @@
121058 ** columns of the sub-query.
121059 **
121060 ** (19) If the subquery uses LIMIT then the outer query may not
121061 ** have a WHERE clause.
121062 **
121063 ** (20) If the sub-query is a compound select, then it must not use
121064 ** an ORDER BY clause. Ticket #3773. We could relax this constraint
121065 ** somewhat by saying that the terms of the ORDER BY clause must
121066 ** appear as unmodified result columns in the outer query. But we
121067 ** have other optimizations in mind to deal with that case.
 
121068 **
121069 ** (21) If the subquery uses LIMIT then the outer query may not be
121070 ** DISTINCT. (See ticket [752e1646fc]).
121071 **
121072 ** (22) The subquery may not be a recursive CTE.
121073 **
121074 ** (23) If the outer query is a recursive CTE, then the sub-query may not be
121075 ** a compound query. This restriction is because transforming the
 
121076 ** parent to a compound query confuses the code that handles
121077 ** recursive queries in multiSelect().
121078 **
121079 ** (**) We no longer attempt to flatten aggregate subqueries. Was:
121080 ** The subquery may not be an aggregate that uses the built-in min() or
@@ -121151,13 +121167,10 @@
121151 return 0; /* Restriction (21) */
121152 }
121153 if( pSub->selFlags & (SF_Recursive) ){
121154 return 0; /* Restrictions (22) */
121155 }
121156 if( (p->selFlags & SF_Recursive) && pSub->pPrior ){
121157 return 0; /* Restriction (23) */
121158 }
121159
121160 /*
121161 ** If the subquery is the right operand of a LEFT JOIN, then the
121162 ** subquery may not be a join itself (3a). Example of why this is not
121163 ** allowed:
@@ -121198,13 +121211,10 @@
121198 ** use only the UNION ALL operator. And none of the simple select queries
121199 ** that make up the compound SELECT are allowed to be aggregate or distinct
121200 ** queries.
121201 */
121202 if( pSub->pPrior ){
121203 if( pSub->pOrderBy ){
121204 return 0; /* Restriction (20) */
121205 }
121206 if( isAgg || (p->selFlags & SF_Distinct)!=0 || pSrc->nSrc!=1 ){
121207 return 0; /* (17d1), (17d2), or (17d3) */
121208 }
121209 for(pSub1=pSub; pSub1; pSub1=pSub1->pPrior){
121210 testcase( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct );
@@ -121227,10 +121237,27 @@
121227 if( p->pOrderBy->a[ii].u.x.iOrderByCol==0 ) return 0;
121228 }
121229 }
121230 }
121231
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121232 /***** If we reach this point, flattening is permitted. *****/
121233 SELECTTRACE(1,pParse,p,("flatten %s.%p from term %d\n",
121234 pSub->zSelName, pSub, iFrom));
121235
121236 /* Authorize the subquery */
@@ -121958,11 +121985,11 @@
121958 ** sqlite3SelectExpand() when walking a SELECT tree to resolve table
121959 ** names and other FROM clause elements.
121960 */
121961 static void selectPopWith(Walker *pWalker, Select *p){
121962 Parse *pParse = pWalker->pParse;
121963 if( pParse->pWith && p->pPrior==0 ){
121964 With *pWith = findRightmost(p)->pWith;
121965 if( pWith!=0 ){
121966 assert( pParse->pWith==pWith );
121967 pParse->pWith = pWith->pOuter;
121968 }
@@ -122013,11 +122040,11 @@
122013 if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
122014 return WRC_Prune;
122015 }
122016 pTabList = p->pSrc;
122017 pEList = p->pEList;
122018 if( p->pWith ){
122019 sqlite3WithPush(pParse, p->pWith, 0);
122020 }
122021
122022 /* Make sure cursor numbers have been assigned to all entries in
122023 ** the FROM clause of the SELECT statement.
@@ -122259,16 +122286,14 @@
122259 }
122260 }
122261 sqlite3ExprListDelete(db, pEList);
122262 p->pEList = pNew;
122263 }
122264 #if SQLITE_MAX_COLUMN
122265 if( p->pEList && p->pEList->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
122266 sqlite3ErrorMsg(pParse, "too many columns in result set");
122267 return WRC_Abort;
122268 }
122269 #endif
122270 return WRC_Continue;
122271 }
122272
122273 /*
122274 ** No-op routine for the parse-tree walker.
@@ -122318,11 +122343,11 @@
122318 */
122319 static void sqlite3SelectExpand(Parse *pParse, Select *pSelect){
122320 Walker w;
122321 w.xExprCallback = sqlite3ExprWalkNoop;
122322 w.pParse = pParse;
122323 if( pParse->hasCompound ){
122324 w.xSelectCallback = convertCompoundSelectToSubquery;
122325 w.xSelectCallback2 = 0;
122326 sqlite3WalkSelect(&w, pSelect);
122327 }
122328 w.xSelectCallback = selectExpander;
@@ -122406,19 +122431,17 @@
122406 SQLITE_PRIVATE void sqlite3SelectPrep(
122407 Parse *pParse, /* The parser context */
122408 Select *p, /* The SELECT statement being coded. */
122409 NameContext *pOuterNC /* Name context for container */
122410 ){
122411 sqlite3 *db;
122412 if( NEVER(p==0) ) return;
122413 db = pParse->db;
122414 if( db->mallocFailed ) return;
122415 if( p->selFlags & SF_HasTypeInfo ) return;
122416 sqlite3SelectExpand(pParse, p);
122417 if( pParse->nErr || db->mallocFailed ) return;
122418 sqlite3ResolveSelectNames(pParse, p, pOuterNC);
122419 if( pParse->nErr || db->mallocFailed ) return;
122420 sqlite3SelectAddTypeInfo(pParse, p);
122421 }
122422
122423 /*
122424 ** Reset the aggregate accumulator.
@@ -126333,12 +126356,14 @@
126333 void *pAux, /* Context pointer for xCreate/xConnect */
126334 void (*xDestroy)(void *) /* Module destructor function */
126335 ){
126336 Module *pMod;
126337 int nName = sqlite3Strlen30(zName);
126338 pMod = (Module *)sqlite3DbMallocRawNN(db, sizeof(Module) + nName + 1);
126339 if( pMod ){
 
 
126340 Module *pDel;
126341 char *zCopy = (char *)(&pMod[1]);
126342 memcpy(zCopy, zName, nName+1);
126343 pMod->zName = zCopy;
126344 pMod->pModule = pModule;
@@ -126809,17 +126834,18 @@
126809 );
126810 return SQLITE_LOCKED;
126811 }
126812 }
126813
126814 zModuleName = sqlite3MPrintf(db, "%s", pTab->zName);
126815 if( !zModuleName ){
126816 return SQLITE_NOMEM_BKPT;
126817 }
126818
126819 pVTable = sqlite3DbMallocZero(db, sizeof(VTable));
126820 if( !pVTable ){
 
126821 sqlite3DbFree(db, zModuleName);
126822 return SQLITE_NOMEM_BKPT;
126823 }
126824 pVTable->db = db;
126825 pVTable->pMod = pMod;
@@ -133669,22 +133695,23 @@
133669
133670 /*
133671 ** Return TRUE if all of the following are true:
133672 **
133673 ** (1) X has the same or lower cost that Y
133674 ** (2) X is a proper subset of Y
133675 ** (3) X skips at least as many columns as Y
 
 
133676 **
133677 ** By "proper subset" we mean that X uses fewer WHERE clause terms
133678 ** than Y and that every WHERE clause term used by X is also used
133679 ** by Y.
133680 **
133681 ** If X is a proper subset of Y then Y is a better choice and ought
133682 ** to have a lower cost. This routine returns TRUE when that cost
133683 ** relationship is inverted and needs to be adjusted. The third rule
133684 ** was added because if X uses skip-scan less than Y it still might
133685 ** deserve a lower cost even if it is a proper subset of Y.
 
 
133686 */
133687 static int whereLoopCheaperProperSubset(
133688 const WhereLoop *pX, /* First WhereLoop to compare */
133689 const WhereLoop *pY /* Compare against this WhereLoop */
133690 ){
@@ -133701,10 +133728,14 @@
133701 if( pX->aLTerm[i]==0 ) continue;
133702 for(j=pY->nLTerm-1; j>=0; j--){
133703 if( pY->aLTerm[j]==pX->aLTerm[i] ) break;
133704 }
133705 if( j<0 ) return 0; /* X not a subset of Y since term X[i] not used by Y */
 
 
 
 
133706 }
133707 return 1; /* All conditions meet */
133708 }
133709
133710 /*
@@ -141996,13 +142027,15 @@
141996 /* IMPLEMENTATION-OF: R-53536-42575 The sqlite3_libversion() function returns
141997 ** a pointer to the to the sqlite3_version[] string constant.
141998 */
141999 SQLITE_API const char *sqlite3_libversion(void){ return sqlite3_version; }
142000
142001 /* IMPLEMENTATION-OF: R-63124-39300 The sqlite3_sourceid() function returns a
142002 ** pointer to a string constant whose value is the same as the
142003 ** SQLITE_SOURCE_ID C preprocessor macro.
 
 
142004 */
142005 /* SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } */
142006
142007 /* IMPLEMENTATION-OF: R-35210-63508 The sqlite3_libversion_number() function
142008 ** returns an integer equal to SQLITE_VERSION_NUMBER.
@@ -145000,10 +145033,16 @@
145000 #ifdef SQLITE_ENABLE_RTREE
145001 if( !db->mallocFailed && rc==SQLITE_OK){
145002 rc = sqlite3RtreeInit(db);
145003 }
145004 #endif
 
 
 
 
 
 
145005
145006 #ifdef SQLITE_ENABLE_DBSTAT_VTAB
145007 if( !db->mallocFailed && rc==SQLITE_OK){
145008 rc = sqlite3DbstatRegister(db);
145009 }
@@ -145660,11 +145699,11 @@
145660 ** sqlite3_test_control(SQLITE_TESTCTRL_ALWAYS, int X)
145661 **
145662 ** This action provides a run-time test to see how the ALWAYS and
145663 ** NEVER macros were defined at compile-time.
145664 **
145665 ** The return value is ALWAYS(X).
145666 **
145667 ** The recommended test is X==2. If the return value is 2, that means
145668 ** ALWAYS() and NEVER() are both no-op pass-through macros, which is the
145669 ** default setting. If the return value is 1, then ALWAYS() is either
145670 ** hard-coded to true or else it asserts if its argument is false.
@@ -145683,11 +145722,11 @@
145683 ** // ALWAYS(x) is a constant 1. NEVER(x) is a constant 0.
145684 ** }
145685 */
145686 case SQLITE_TESTCTRL_ALWAYS: {
145687 int x = va_arg(ap,int);
145688 rc = ALWAYS(x);
145689 break;
145690 }
145691
145692 /*
145693 ** sqlite3_test_control(SQLITE_TESTCTRL_BYTEORDER);
@@ -170889,10 +170928,17 @@
170889 #endif
170890
170891 /* Maximum number of prepared UPDATE statements held by this module */
170892 #define SQLITE_RBU_UPDATE_CACHESIZE 16
170893
 
 
 
 
 
 
 
170894 /*
170895 ** Swap two objects of type TYPE.
170896 */
170897 #if !defined(SQLITE_AMALGAMATION)
170898 # define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;}
@@ -171263,10 +171309,11 @@
171263 *pLen -= z - zStart;
171264 *pz = (char*)z;
171265 return v;
171266 }
171267
 
171268 /*
171269 ** Compute a 32-bit checksum on the N-byte buffer. Return the result.
171270 */
171271 static unsigned int rbuDeltaChecksum(const char *zIn, size_t N){
171272 const unsigned char *z = (const unsigned char *)zIn;
@@ -171297,10 +171344,11 @@
171297 case 1: sum3 += (z[0] << 24);
171298 default: ;
171299 }
171300 return sum3;
171301 }
 
171302
171303 /*
171304 ** Apply a delta.
171305 **
171306 ** The output buffer should be big enough to hold the whole output
@@ -171327,11 +171375,11 @@
171327 int lenDelta, /* Length of the delta */
171328 char *zOut /* Write the output into this preallocated buffer */
171329 ){
171330 unsigned int limit;
171331 unsigned int total = 0;
171332 #ifndef FOSSIL_OMIT_DELTA_CKSUM_TEST
171333 char *zOrigOut = zOut;
171334 #endif
171335
171336 limit = rbuDeltaGetInt(&zDelta, &lenDelta);
171337 if( *zDelta!='\n' ){
@@ -171382,11 +171430,11 @@
171382 break;
171383 }
171384 case ';': {
171385 zDelta++; lenDelta--;
171386 zOut[0] = 0;
171387 #ifndef FOSSIL_OMIT_DELTA_CKSUM_TEST
171388 if( cnt!=rbuDeltaChecksum(zOrigOut, total) ){
171389 /* ERROR: bad checksum */
171390 return -1;
171391 }
171392 #endif
@@ -176366,10 +176414,342 @@
176366 #elif defined(SQLITE_ENABLE_DBSTAT_VTAB)
176367 SQLITE_PRIVATE int sqlite3DbstatRegister(sqlite3 *db){ return SQLITE_OK; }
176368 #endif /* SQLITE_ENABLE_DBSTAT_VTAB */
176369
176370 /************** End of dbstat.c **********************************************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176371 /************** Begin file sqlite3session.c **********************************/
176372
176373 #if defined(SQLITE_ENABLE_SESSION) && defined(SQLITE_ENABLE_PREUPDATE_HOOK)
176374 /* #include "sqlite3session.h" */
176375 /* #include <assert.h> */
@@ -200697,11 +201077,11 @@
200697 int nArg, /* Number of args */
200698 sqlite3_value **apUnused /* Function arguments */
200699 ){
200700 assert( nArg==0 );
200701 UNUSED_PARAM2(nArg, apUnused);
200702 sqlite3_result_text(pCtx, "fts5: 2017-09-29 16:07:56 0840f9f824c16212ce3fd6c859e501176eb0a58924ea1728a54d5bdfd0c25c86", -1, SQLITE_TRANSIENT);
200703 }
200704
200705 static int fts5Init(sqlite3 *db){
200706 static const sqlite3_module fts5Mod = {
200707 /* iVersion */ 2,
@@ -204579,11 +204959,10 @@
204579 iVal = pCsr->aDoc[0];
204580 }else{
204581 iVal = pCsr->aCnt[0];
204582 }
204583 }else{
204584 int eDetail = pCsr->pConfig->eDetail;
204585 assert( eType==FTS5_VOCAB_INSTANCE );
204586 switch( iCol ){
204587 case 1:
204588 sqlite3_result_int64(pCtx, pCsr->pIter->iRowid);
204589 break;
@@ -204590,11 +204969,11 @@
204590 case 2: {
204591 int ii = -1;
204592 if( eDetail==FTS5_DETAIL_FULL ){
204593 ii = FTS5_POS2COLUMN(pCsr->iInstPos);
204594 }else if( eDetail==FTS5_DETAIL_COLUMNS ){
204595 ii = pCsr->iInstPos;
204596 }
204597 if( ii>=0 && ii<pCsr->pConfig->nCol ){
204598 const char *z = pCsr->pConfig->azCol[ii];
204599 sqlite3_result_text(pCtx, z, -1, SQLITE_STATIC);
204600 }
@@ -204966,12 +205345,12 @@
204966 }
204967 #endif /* SQLITE_CORE */
204968 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
204969
204970 /************** End of stmt.c ************************************************/
204971 #if __LINE__!=204971
204972 #undef SQLITE_SOURCE_ID
204973 #define SQLITE_SOURCE_ID "2017-10-02 02:52:54 c9104b59c7ed360291f7f6fc8caae938e9840c77620d598e4096f78183bfalt2"
204974 #endif
204975 /* Return the source-id for this library */
204976 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
204977 /************************** End of sqlite3.c ******************************/
204978
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1147,11 +1147,11 @@
1147 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1148 ** [sqlite_version()] and [sqlite_source_id()].
1149 */
1150 #define SQLITE_VERSION "3.21.0"
1151 #define SQLITE_VERSION_NUMBER 3021000
1152 #define SQLITE_SOURCE_ID "2017-10-21 17:17:17 fb3ee1b7cac09e4950e4f48b44c277e4f391cb6c8f069644732d2389ca653da4"
1153
1154 /*
1155 ** CAPI3REF: Run-Time Library Version Numbers
1156 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1157 **
@@ -10253,12 +10253,12 @@
10253 ** a single table are grouped together, tables appear in the order in which
10254 ** they were attached to the session object).
10255 */
10256 SQLITE_API int sqlite3session_patchset(
10257 sqlite3_session *pSession, /* Session object */
10258 int *pnPatchset, /* OUT: Size of buffer at *ppPatchset */
10259 void **ppPatchset /* OUT: Buffer containing patchset */
10260 );
10261
10262 /*
10263 ** CAPI3REF: Test if a changeset has recorded any changes.
10264 **
@@ -11021,16 +11021,16 @@
11021 ** The six streaming API xxx_strm() functions serve similar purposes to the
11022 ** corresponding non-streaming API functions:
11023 **
11024 ** <table border=1 style="margin-left:8ex;margin-right:8ex">
11025 ** <tr><th>Streaming function<th>Non-streaming equivalent</th>
11026 ** <tr><td>sqlite3changeset_apply_strm<td>[sqlite3changeset_apply]
11027 ** <tr><td>sqlite3changeset_concat_strm<td>[sqlite3changeset_concat]
11028 ** <tr><td>sqlite3changeset_invert_strm<td>[sqlite3changeset_invert]
11029 ** <tr><td>sqlite3changeset_start_strm<td>[sqlite3changeset_start]
11030 ** <tr><td>sqlite3session_changeset_strm<td>[sqlite3session_changeset]
11031 ** <tr><td>sqlite3session_patchset_strm<td>[sqlite3session_patchset]
11032 ** </table>
11033 **
11034 ** Non-streaming functions that accept changesets (or patchsets) as input
11035 ** require that the entire changeset be stored in a single buffer in memory.
11036 ** Similarly, those that return a changeset or patchset do so by returning
@@ -12246,10 +12246,25 @@
12246 #else
12247 # define ALWAYS(X) (X)
12248 # define NEVER(X) (X)
12249 #endif
12250
12251 /*
12252 ** Some conditionals are optimizations only. In other words, if the
12253 ** conditionals are replaced with a constant 1 (true) or 0 (false) then
12254 ** the correct answer is still obtained, though perhaps not as quickly.
12255 **
12256 ** The following macros mark these optimizations conditionals.
12257 */
12258 #if defined(SQLITE_MUTATION_TEST)
12259 # define OK_IF_ALWAYS_TRUE(X) (1)
12260 # define OK_IF_ALWAYS_FALSE(X) (0)
12261 #else
12262 # define OK_IF_ALWAYS_TRUE(X) (X)
12263 # define OK_IF_ALWAYS_FALSE(X) (X)
12264 #endif
12265
12266 /*
12267 ** Some malloc failures are only possible if SQLITE_TEST_REALLOC_STRESS is
12268 ** defined. We need to defend against those failures when testing with
12269 ** SQLITE_TEST_REALLOC_STRESS, but we don't want the unreachable branches
12270 ** during a normal build. The following macro can be used to disable tests
@@ -12999,11 +13014,11 @@
13014
13015 /*
13016 ** SELECTTRACE_ENABLED will be either 1 or 0 depending on whether or not
13017 ** the Select query generator tracing logic is turned on.
13018 */
13019 #if defined(SQLITE_ENABLE_SELECTTRACE)
13020 # define SELECTTRACE_ENABLED 1
13021 #else
13022 # define SELECTTRACE_ENABLED 0
13023 #endif
13024
@@ -14766,14 +14781,16 @@
14781 SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file*,int,void*);
14782 SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file*,int,void*);
14783 #define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0
14784 SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id);
14785 SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id);
14786 #ifndef SQLITE_OMIT_WAL
14787 SQLITE_PRIVATE int sqlite3OsShmMap(sqlite3_file *,int,int,int,void volatile **);
14788 SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int, int, int);
14789 SQLITE_PRIVATE void sqlite3OsShmBarrier(sqlite3_file *id);
14790 SQLITE_PRIVATE int sqlite3OsShmUnmap(sqlite3_file *id, int);
14791 #endif /* SQLITE_OMIT_WAL */
14792 SQLITE_PRIVATE int sqlite3OsFetch(sqlite3_file *id, i64, int, void **);
14793 SQLITE_PRIVATE int sqlite3OsUnfetch(sqlite3_file *, i64, void *);
14794
14795
14796 /*
@@ -18158,10 +18175,13 @@
18175 #if SQLITE_MAX_WORKER_THREADS>0
18176 SQLITE_PRIVATE int sqlite3ThreadCreate(SQLiteThread**,void*(*)(void*),void*);
18177 SQLITE_PRIVATE int sqlite3ThreadJoin(SQLiteThread*, void**);
18178 #endif
18179
18180 #if defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)
18181 SQLITE_PRIVATE int sqlite3DbpageRegister(sqlite3*);
18182 #endif
18183 #if defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)
18184 SQLITE_PRIVATE int sqlite3DbstatRegister(sqlite3*);
18185 #endif
18186
18187 SQLITE_PRIVATE int sqlite3ExprVectorSize(Expr *pExpr);
@@ -20823,10 +20843,11 @@
20843 return (xSectorSize ? xSectorSize(id) : SQLITE_DEFAULT_SECTOR_SIZE);
20844 }
20845 SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id){
20846 return id->pMethods->xDeviceCharacteristics(id);
20847 }
20848 #ifndef SQLITE_OMIT_WAL
20849 SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int offset, int n, int flags){
20850 return id->pMethods->xShmLock(id, offset, n, flags);
20851 }
20852 SQLITE_PRIVATE void sqlite3OsShmBarrier(sqlite3_file *id){
20853 id->pMethods->xShmBarrier(id);
@@ -20842,10 +20863,11 @@
20863 void volatile **pp /* OUT: Pointer to mapping */
20864 ){
20865 DO_OS_MALLOC_TEST(id);
20866 return id->pMethods->xShmMap(id, iPage, pgsz, bExtend, pp);
20867 }
20868 #endif /* SQLITE_OMIT_WAL */
20869
20870 #if SQLITE_MAX_MMAP_SIZE>0
20871 /* The real implementation of xFetch and xUnfetch */
20872 SQLITE_PRIVATE int sqlite3OsFetch(sqlite3_file *id, i64 iOff, int iAmt, void **pp){
20873 DO_OS_MALLOC_TEST(id);
@@ -48663,10 +48685,12 @@
48685 || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
48686 int dc; /* Device characteristics */
48687
48688 assert( isOpen(pPager->fd) );
48689 dc = sqlite3OsDeviceCharacteristics(pPager->fd);
48690 #else
48691 UNUSED_PARAMETER(pPager);
48692 #endif
48693
48694 #ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
48695 if( dc&SQLITE_IOCAP_BATCH_ATOMIC ){
48696 return -1;
@@ -50467,10 +50491,12 @@
50491 ** Otherwise, SQLITE_OK is returned.
50492 */
50493 static int readDbPage(PgHdr *pPg){
50494 Pager *pPager = pPg->pPager; /* Pager object associated with page pPg */
50495 int rc = SQLITE_OK; /* Return code */
50496
50497 #ifndef SQLITE_OMIT_WAL
50498 u32 iFrame = 0; /* Frame of WAL containing pgno */
50499
50500 assert( pPager->eState>=PAGER_READER && !MEMDB );
50501 assert( isOpen(pPager->fd) );
50502
@@ -50478,11 +50504,13 @@
50504 rc = sqlite3WalFindFrame(pPager->pWal, pPg->pgno, &iFrame);
50505 if( rc ) return rc;
50506 }
50507 if( iFrame ){
50508 rc = sqlite3WalReadFrame(pPager->pWal, iFrame,pPager->pageSize,pPg->pData);
50509 }else
50510 #endif
50511 {
50512 i64 iOffset = (pPg->pgno-1)*(i64)pPager->pageSize;
50513 rc = sqlite3OsRead(pPager->fd, pPg->pData, pPager->pageSize, iOffset);
50514 if( rc==SQLITE_IOERR_SHORT_READ ){
50515 rc = SQLITE_OK;
50516 }
@@ -61683,11 +61711,11 @@
61711 static Pgno btreePagecount(BtShared *pBt){
61712 return pBt->nPage;
61713 }
61714 SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree *p){
61715 assert( sqlite3BtreeHoldsMutex(p) );
61716 assert( ((p->pBt->nPage)&0x80000000)==0 );
61717 return btreePagecount(p->pBt);
61718 }
61719
61720 /*
61721 ** Get a page from the pager and initialize it.
@@ -62565,11 +62593,12 @@
62593 ** If the user has not set the safety-level for this database connection
62594 ** using "PRAGMA synchronous", and if the safety-level is not already
62595 ** set to the value passed to this function as the second parameter,
62596 ** set it so.
62597 */
62598 #if SQLITE_DEFAULT_SYNCHRONOUS!=SQLITE_DEFAULT_WAL_SYNCHRONOUS \
62599 && !defined(SQLITE_OMIT_WAL)
62600 static void setDefaultSyncFlag(BtShared *pBt, u8 safety_level){
62601 sqlite3 *db;
62602 Db *pDb;
62603 if( (db=pBt->db)!=0 && (pDb=db->aDb)!=0 ){
62604 while( pDb->pBt==0 || pDb->pBt->pBt!=pBt ){ pDb++; }
@@ -64466,22 +64495,27 @@
64495 */
64496 static const void *fetchPayload(
64497 BtCursor *pCur, /* Cursor pointing to entry to read from */
64498 u32 *pAmt /* Write the number of available bytes here */
64499 ){
64500 int amt;
64501 assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage);
64502 assert( pCur->eState==CURSOR_VALID );
64503 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
64504 assert( cursorOwnsBtShared(pCur) );
64505 assert( pCur->ix<pCur->pPage->nCell );
64506 assert( pCur->info.nSize>0 );
64507 assert( pCur->info.pPayload>pCur->pPage->aData || CORRUPT_DB );
64508 assert( pCur->info.pPayload<pCur->pPage->aDataEnd ||CORRUPT_DB);
64509 amt = pCur->info.nLocal;
64510 if( amt>(int)(pCur->pPage->aDataEnd - pCur->info.pPayload) ){
64511 /* There is too little space on the page for the expected amount
64512 ** of local content. Database must be corrupt. */
64513 assert( CORRUPT_DB );
64514 amt = MAX(0, (int)(pCur->pPage->aDataEnd - pCur->info.pPayload));
64515 }
64516 *pAmt = (u32)amt;
64517 return (void*)pCur->info.pPayload;
64518 }
64519
64520
64521 /*
@@ -66944,12 +66978,10 @@
66978 szScratch =
66979 nMaxCells*sizeof(u8*) /* b.apCell */
66980 + nMaxCells*sizeof(u16) /* b.szCell */
66981 + pBt->pageSize; /* aSpace1 */
66982
 
 
66983 assert( szScratch<=6*(int)pBt->pageSize );
66984 b.apCell = sqlite3StackAllocRaw(0, szScratch );
66985 if( b.apCell==0 ){
66986 rc = SQLITE_NOMEM_BKPT;
66987 goto balance_cleanup;
@@ -75017,10 +75049,14 @@
75049 ** To look at it another way, this routine resets the state of the
75050 ** virtual machine from VDBE_MAGIC_RUN or VDBE_MAGIC_HALT back to
75051 ** VDBE_MAGIC_INIT.
75052 */
75053 SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){
75054 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
75055 int i;
75056 #endif
75057
75058 sqlite3 *db;
75059 db = p->db;
75060
75061 /* If the VM did not run to completion or if it encountered an
75062 ** error, then it might not have been halted properly. So halt
@@ -75048,11 +75084,10 @@
75084 /* Reset register contents and reclaim error message memory.
75085 */
75086 #ifdef SQLITE_DEBUG
75087 /* Execute assert() statements to ensure that the Vdbe.apCsr[] and
75088 ** Vdbe.aMem[] arrays have already been cleaned up. */
 
75089 if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
75090 if( p->aMem ){
75091 for(i=0; i<p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined );
75092 }
75093 #endif
@@ -75064,11 +75099,10 @@
75099 */
75100 #ifdef VDBE_PROFILE
75101 {
75102 FILE *out = fopen("vdbe_profile.out", "a");
75103 if( out ){
 
75104 fprintf(out, "---- ");
75105 for(i=0; i<p->nOp; i++){
75106 fprintf(out, "%02x", p->aOp[i].opcode);
75107 }
75108 fprintf(out, "\n");
@@ -91194,16 +91228,14 @@
91228 int moreToDo = 1;
91229
91230 pOrderBy = pSelect->pOrderBy;
91231 if( pOrderBy==0 ) return 0;
91232 db = pParse->db;
 
91233 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
91234 sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
91235 return 1;
91236 }
 
91237 for(i=0; i<pOrderBy->nExpr; i++){
91238 pOrderBy->a[i].done = 0;
91239 }
91240 pSelect->pNext = 0;
91241 while( pSelect->pPrior ){
@@ -91291,16 +91323,14 @@
91323 sqlite3 *db = pParse->db;
91324 ExprList *pEList;
91325 struct ExprList_item *pItem;
91326
91327 if( pOrderBy==0 || pParse->db->mallocFailed ) return 0;
 
91328 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
91329 sqlite3ErrorMsg(pParse, "too many terms in %s BY clause", zType);
91330 return 1;
91331 }
 
91332 pEList = pSelect->pEList;
91333 assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */
91334 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
91335 if( pItem->u.x.iOrderByCol ){
91336 if( pItem->u.x.iOrderByCol>pEList->nExpr ){
@@ -101733,16 +101763,14 @@
101763 char *z;
101764 char *zType;
101765 Column *pCol;
101766 sqlite3 *db = pParse->db;
101767 if( (p = pParse->pNewTable)==0 ) return;
 
101768 if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){
101769 sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName);
101770 return;
101771 }
 
101772 z = sqlite3DbMallocRaw(db, pName->n + pType->n + 2);
101773 if( z==0 ) return;
101774 memcpy(z, pName->z, pName->n);
101775 z[pName->n] = 0;
101776 sqlite3Dequote(z);
@@ -103036,18 +103064,10 @@
103064 ** Code to update the sqlite_master tables and internal schema definitions
103065 ** in case a root-page belonging to another table is moved by the btree layer
103066 ** is also added (this can happen with an auto-vacuum database).
103067 */
103068 static void destroyTable(Parse *pParse, Table *pTab){
 
 
 
 
 
 
 
 
103069 /* If the database may be auto-vacuum capable (if SQLITE_OMIT_AUTOVACUUM
103070 ** is not defined), then it is important to call OP_Destroy on the
103071 ** table and index root-pages in order, starting with the numerically
103072 ** largest root-page number. This guarantees that none of the root-pages
103073 ** to be destroyed is relocated by an earlier OP_Destroy. i.e. if the
@@ -103086,11 +103106,10 @@
103106 assert( iDb>=0 && iDb<pParse->db->nDb );
103107 destroyRootPage(pParse, iLargest, iDb);
103108 iDestroyed = iLargest;
103109 }
103110 }
 
103111 }
103112
103113 /*
103114 ** Remove entries from the sqlite_statN tables (for N in (1,2,3))
103115 ** after a DROP INDEX or DROP TABLE command.
@@ -110324,11 +110343,10 @@
110343 IdList *pColumn, /* Column names corresponding to IDLIST. */
110344 int onError /* How to handle constraint errors */
110345 ){
110346 sqlite3 *db; /* The main database structure */
110347 Table *pTab; /* The table to insert into. aka TABLE */
 
110348 int i, j; /* Loop counters */
110349 Vdbe *v; /* Generate code into this virtual machine */
110350 Index *pIdx; /* For looping over indices of the table */
110351 int nColumn; /* Number of columns in the data */
110352 int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
@@ -110380,12 +110398,10 @@
110398 }
110399
110400 /* Locate the table into which we will be inserting new information.
110401 */
110402 assert( pTabList->nSrc==1 );
 
 
110403 pTab = sqlite3SrcListLookup(pParse, pTabList);
110404 if( pTab==0 ){
110405 goto insert_cleanup;
110406 }
110407 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
@@ -112403,11 +112419,11 @@
112419 void (*result_value)(sqlite3_context*,sqlite3_value*);
112420 void * (*rollback_hook)(sqlite3*,void(*)(void*),void*);
112421 int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*,
112422 const char*,const char*),void*);
112423 void (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*));
112424 char * (*xsnprintf)(int,char*,const char*,...);
112425 int (*step)(sqlite3_stmt*);
112426 int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*,
112427 char const**,char const**,int*,int*,int*);
112428 void (*thread_cleanup)(void);
112429 int (*total_changes)(sqlite3*);
@@ -112687,11 +112703,11 @@
112703 #define sqlite3_result_text16le sqlite3_api->result_text16le
112704 #define sqlite3_result_value sqlite3_api->result_value
112705 #define sqlite3_rollback_hook sqlite3_api->rollback_hook
112706 #define sqlite3_set_authorizer sqlite3_api->set_authorizer
112707 #define sqlite3_set_auxdata sqlite3_api->set_auxdata
112708 #define sqlite3_snprintf sqlite3_api->xsnprintf
112709 #define sqlite3_step sqlite3_api->step
112710 #define sqlite3_table_column_metadata sqlite3_api->table_column_metadata
112711 #define sqlite3_thread_cleanup sqlite3_api->thread_cleanup
112712 #define sqlite3_total_changes sqlite3_api->total_changes
112713 #define sqlite3_trace sqlite3_api->trace
@@ -117748,11 +117764,11 @@
117764 sqlite3ExprListDelete(db, p->pGroupBy);
117765 sqlite3ExprDelete(db, p->pHaving);
117766 sqlite3ExprListDelete(db, p->pOrderBy);
117767 sqlite3ExprDelete(db, p->pLimit);
117768 sqlite3ExprDelete(db, p->pOffset);
117769 if( OK_IF_ALWAYS_TRUE(p->pWith) ) sqlite3WithDelete(db, p->pWith);
117770 if( bFree ) sqlite3DbFreeNN(db, p);
117771 p = pPrior;
117772 bFree = 1;
117773 }
117774 }
@@ -117844,11 +117860,11 @@
117860
117861 /*
117862 ** Delete the given Select structure and all of its substructures.
117863 */
117864 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
117865 if( OK_IF_ALWAYS_TRUE(p) ) clearSelect(db, p, 1);
117866 }
117867
117868 /*
117869 ** Return a pointer to the right-most SELECT statement in a compound.
117870 */
@@ -118085,15 +118101,14 @@
118101
118102 pSrc = p->pSrc;
118103 pLeft = &pSrc->a[0];
118104 pRight = &pLeft[1];
118105 for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
 
118106 Table *pRightTab = pRight->pTab;
118107 int isOuter;
118108
118109 if( NEVER(pLeft->pTab==0 || pRightTab==0) ) continue;
118110 isOuter = (pRight->fg.jointype & JT_OUTER)!=0;
118111
118112 /* When the NATURAL keyword is present, add WHERE clause terms for
118113 ** every column that the two tables have in common.
118114 */
@@ -119035,27 +119050,27 @@
119050 **
119051 ** This routine has either 3 or 6 parameters depending on whether or not
119052 ** the SQLITE_ENABLE_COLUMN_METADATA compile-time option is used.
119053 */
119054 #ifdef SQLITE_ENABLE_COLUMN_METADATA
119055 # define columnType(A,B,C,D,E) columnTypeImpl(A,B,C,D,E)
119056 #else /* if !defined(SQLITE_ENABLE_COLUMN_METADATA) */
119057 # define columnType(A,B,C,D,E) columnTypeImpl(A,B)
119058 #endif
119059 static const char *columnTypeImpl(
119060 NameContext *pNC,
119061 #ifndef SQLITE_ENABLE_COLUMN_METADATA
119062 Expr *pExpr
119063 #else
119064 Expr *pExpr,
 
119065 const char **pzOrigDb,
119066 const char **pzOrigTab,
119067 const char **pzOrigCol
119068 #endif
 
119069 ){
119070 char const *zType = 0;
119071 int j;
 
119072 #ifdef SQLITE_ENABLE_COLUMN_METADATA
119073 char const *zOrigDb = 0;
119074 char const *zOrigTab = 0;
119075 char const *zOrigCol = 0;
119076 #endif
@@ -119120,37 +119135,36 @@
119135 NameContext sNC;
119136 Expr *p = pS->pEList->a[iCol].pExpr;
119137 sNC.pSrcList = pS->pSrc;
119138 sNC.pNext = pNC;
119139 sNC.pParse = pNC->pParse;
119140 zType = columnType(&sNC, p,&zOrigDb,&zOrigTab,&zOrigCol);
119141 }
119142 }else{
119143 /* A real table or a CTE table */
119144 assert( !pS );
119145 #ifdef SQLITE_ENABLE_COLUMN_METADATA
119146 if( iCol<0 ) iCol = pTab->iPKey;
119147 assert( iCol==XN_ROWID || (iCol>=0 && iCol<pTab->nCol) );
 
119148 if( iCol<0 ){
119149 zType = "INTEGER";
119150 zOrigCol = "rowid";
119151 }else{
119152 zOrigCol = pTab->aCol[iCol].zName;
119153 zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
 
119154 }
119155 zOrigTab = pTab->zName;
119156 if( pNC->pParse && pTab->pSchema ){
119157 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
119158 zOrigDb = pNC->pParse->db->aDb[iDb].zDbSName;
119159 }
119160 #else
119161 assert( iCol==XN_ROWID || (iCol>=0 && iCol<pTab->nCol) );
119162 if( iCol<0 ){
119163 zType = "INTEGER";
119164 }else{
119165 zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
 
119166 }
119167 #endif
119168 }
119169 break;
119170 }
@@ -119165,11 +119179,11 @@
119179 Expr *p = pS->pEList->a[0].pExpr;
119180 assert( ExprHasProperty(pExpr, EP_xIsSelect) );
119181 sNC.pSrcList = pS->pSrc;
119182 sNC.pNext = pNC;
119183 sNC.pParse = pNC->pParse;
119184 zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol);
119185 break;
119186 }
119187 #endif
119188 }
119189
@@ -119179,11 +119193,10 @@
119193 *pzOrigDb = zOrigDb;
119194 *pzOrigTab = zOrigTab;
119195 *pzOrigCol = zOrigCol;
119196 }
119197 #endif
 
119198 return zType;
119199 }
119200
119201 /*
119202 ** Generate code that will tell the VDBE the declaration types of columns
@@ -119206,21 +119219,21 @@
119219 const char *zType;
119220 #ifdef SQLITE_ENABLE_COLUMN_METADATA
119221 const char *zOrigDb = 0;
119222 const char *zOrigTab = 0;
119223 const char *zOrigCol = 0;
119224 zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol);
119225
119226 /* The vdbe must make its own copy of the column-type and other
119227 ** column specific strings, in case the schema is reset before this
119228 ** virtual machine is deleted.
119229 */
119230 sqlite3VdbeSetColName(v, i, COLNAME_DATABASE, zOrigDb, SQLITE_TRANSIENT);
119231 sqlite3VdbeSetColName(v, i, COLNAME_TABLE, zOrigTab, SQLITE_TRANSIENT);
119232 sqlite3VdbeSetColName(v, i, COLNAME_COLUMN, zOrigCol, SQLITE_TRANSIENT);
119233 #else
119234 zType = columnType(&sNC, p, 0, 0, 0);
119235 #endif
119236 sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
119237 }
119238 #endif /* !defined(SQLITE_OMIT_DECLTYPE) */
119239 }
@@ -119365,10 +119378,11 @@
119378 sqlite3HashInit(&ht);
119379 if( pEList ){
119380 nCol = pEList->nExpr;
119381 aCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
119382 testcase( aCol==0 );
119383 if( nCol>32767 ) nCol = 32767;
119384 }else{
119385 nCol = 0;
119386 aCol = 0;
119387 }
119388 assert( nCol==(i16)nCol );
@@ -119461,11 +119475,10 @@
119475 Column *pCol;
119476 CollSeq *pColl;
119477 int i;
119478 Expr *p;
119479 struct ExprList_item *a;
 
119480
119481 assert( pSelect!=0 );
119482 assert( (pSelect->selFlags & SF_Resolved)!=0 );
119483 assert( pTab->nCol==pSelect->pEList->nExpr || db->mallocFailed );
119484 if( db->mallocFailed ) return;
@@ -119474,14 +119487,15 @@
119487 a = pSelect->pEList->a;
119488 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
119489 const char *zType;
119490 int n, m;
119491 p = a[i].pExpr;
119492 zType = columnType(&sNC, p, 0, 0, 0);
119493 /* pCol->szEst = ... // Column size est for SELECT tables never used */
119494 pCol->affinity = sqlite3ExprAffinity(p);
119495 if( zType ){
119496 m = sqlite3Strlen30(zType);
119497 n = sqlite3Strlen30(pCol->zName);
119498 pCol->zName = sqlite3DbReallocOrFree(db, pCol->zName, n+m+2);
119499 if( pCol->zName ){
119500 memcpy(&pCol->zName[n+1], zType, m+1);
119501 pCol->colFlags |= COLFLAG_HASTYPE;
@@ -119491,11 +119505,11 @@
119505 pColl = sqlite3ExprCollSeq(pParse, p);
119506 if( pColl && pCol->zColl==0 ){
119507 pCol->zColl = sqlite3DbStrDup(db, pColl->zName);
119508 }
119509 }
119510 pTab->szTabRow = 1; /* Any non-zero value works */
119511 }
119512
119513 /*
119514 ** Given a SELECT statement, generate a Table structure that describes
119515 ** the result set of that SELECT.
@@ -121031,11 +121045,11 @@
121045 ** until we introduced the group_concat() function.
121046 **
121047 ** (17) If the subquery is a compound select, then
121048 ** (17a) all compound operators must be a UNION ALL, and
121049 ** (17b) no terms within the subquery compound may be aggregate
121050 ** or DISTINCT, and
121051 ** (17c) every term within the subquery compound must have a FROM clause
121052 ** (17d) the outer query may not be
121053 ** (17d1) aggregate, or
121054 ** (17d2) DISTINCT, or
121055 ** (17d3) a join.
@@ -121058,23 +121072,25 @@
121072 ** columns of the sub-query.
121073 **
121074 ** (19) If the subquery uses LIMIT then the outer query may not
121075 ** have a WHERE clause.
121076 **
121077 ** (**) Subsumed into (17d3). Was: If the sub-query is a compound select,
121078 ** then it must not use an ORDER BY clause - Ticket #3773. Because
121079 ** of (17d3), then only way to have a compound subquery is if it is
121080 ** the only term in the FROM clause of the outer query. But if the
121081 ** only term in the FROM clause has an ORDER BY, then it will be
121082 ** implemented as a co-routine and the flattener will never be called.
121083 **
121084 ** (21) If the subquery uses LIMIT then the outer query may not be
121085 ** DISTINCT. (See ticket [752e1646fc]).
121086 **
121087 ** (22) The subquery may not be a recursive CTE.
121088 **
121089 ** (**) Subsumed into restriction (17d3). Was: If the outer query is
121090 ** a recursive CTE, then the sub-query may not be a compound query.
121091 ** This restriction is because transforming the
121092 ** parent to a compound query confuses the code that handles
121093 ** recursive queries in multiSelect().
121094 **
121095 ** (**) We no longer attempt to flatten aggregate subqueries. Was:
121096 ** The subquery may not be an aggregate that uses the built-in min() or
@@ -121151,13 +121167,10 @@
121167 return 0; /* Restriction (21) */
121168 }
121169 if( pSub->selFlags & (SF_Recursive) ){
121170 return 0; /* Restrictions (22) */
121171 }
 
 
 
121172
121173 /*
121174 ** If the subquery is the right operand of a LEFT JOIN, then the
121175 ** subquery may not be a join itself (3a). Example of why this is not
121176 ** allowed:
@@ -121198,13 +121211,10 @@
121211 ** use only the UNION ALL operator. And none of the simple select queries
121212 ** that make up the compound SELECT are allowed to be aggregate or distinct
121213 ** queries.
121214 */
121215 if( pSub->pPrior ){
 
 
 
121216 if( isAgg || (p->selFlags & SF_Distinct)!=0 || pSrc->nSrc!=1 ){
121217 return 0; /* (17d1), (17d2), or (17d3) */
121218 }
121219 for(pSub1=pSub; pSub1; pSub1=pSub1->pPrior){
121220 testcase( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct );
@@ -121227,10 +121237,27 @@
121237 if( p->pOrderBy->a[ii].u.x.iOrderByCol==0 ) return 0;
121238 }
121239 }
121240 }
121241
121242 /* Ex-restriction (23):
121243 ** The only way that the recursive part of a CTE can contain a compound
121244 ** subquery is for the subquery to be one term of a join. But if the
121245 ** subquery is a join, then the flattening has already been stopped by
121246 ** restriction (17d3)
121247 */
121248 assert( (p->selFlags & SF_Recursive)==0 || pSub->pPrior==0 );
121249
121250 /* Ex-restriction (20):
121251 ** A compound subquery must be the only term in the FROM clause of the
121252 ** outer query by restriction (17d3). But if that term also has an
121253 ** ORDER BY clause, then the subquery will be implemented by co-routine
121254 ** and so the flattener will never be invoked. Hence, it is not possible
121255 ** for the subquery to be a compound and have an ORDER BY clause.
121256 */
121257 assert( pSub->pPrior==0 || pSub->pOrderBy==0 );
121258
121259 /***** If we reach this point, flattening is permitted. *****/
121260 SELECTTRACE(1,pParse,p,("flatten %s.%p from term %d\n",
121261 pSub->zSelName, pSub, iFrom));
121262
121263 /* Authorize the subquery */
@@ -121958,11 +121985,11 @@
121985 ** sqlite3SelectExpand() when walking a SELECT tree to resolve table
121986 ** names and other FROM clause elements.
121987 */
121988 static void selectPopWith(Walker *pWalker, Select *p){
121989 Parse *pParse = pWalker->pParse;
121990 if( OK_IF_ALWAYS_TRUE(pParse->pWith) && p->pPrior==0 ){
121991 With *pWith = findRightmost(p)->pWith;
121992 if( pWith!=0 ){
121993 assert( pParse->pWith==pWith );
121994 pParse->pWith = pWith->pOuter;
121995 }
@@ -122013,11 +122040,11 @@
122040 if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
122041 return WRC_Prune;
122042 }
122043 pTabList = p->pSrc;
122044 pEList = p->pEList;
122045 if( OK_IF_ALWAYS_TRUE(p->pWith) ){
122046 sqlite3WithPush(pParse, p->pWith, 0);
122047 }
122048
122049 /* Make sure cursor numbers have been assigned to all entries in
122050 ** the FROM clause of the SELECT statement.
@@ -122259,16 +122286,14 @@
122286 }
122287 }
122288 sqlite3ExprListDelete(db, pEList);
122289 p->pEList = pNew;
122290 }
 
122291 if( p->pEList && p->pEList->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
122292 sqlite3ErrorMsg(pParse, "too many columns in result set");
122293 return WRC_Abort;
122294 }
 
122295 return WRC_Continue;
122296 }
122297
122298 /*
122299 ** No-op routine for the parse-tree walker.
@@ -122318,11 +122343,11 @@
122343 */
122344 static void sqlite3SelectExpand(Parse *pParse, Select *pSelect){
122345 Walker w;
122346 w.xExprCallback = sqlite3ExprWalkNoop;
122347 w.pParse = pParse;
122348 if( OK_IF_ALWAYS_TRUE(pParse->hasCompound) ){
122349 w.xSelectCallback = convertCompoundSelectToSubquery;
122350 w.xSelectCallback2 = 0;
122351 sqlite3WalkSelect(&w, pSelect);
122352 }
122353 w.xSelectCallback = selectExpander;
@@ -122406,19 +122431,17 @@
122431 SQLITE_PRIVATE void sqlite3SelectPrep(
122432 Parse *pParse, /* The parser context */
122433 Select *p, /* The SELECT statement being coded. */
122434 NameContext *pOuterNC /* Name context for container */
122435 ){
122436 assert( p!=0 || pParse->db->mallocFailed );
122437 if( pParse->db->mallocFailed ) return;
 
 
122438 if( p->selFlags & SF_HasTypeInfo ) return;
122439 sqlite3SelectExpand(pParse, p);
122440 if( pParse->nErr || pParse->db->mallocFailed ) return;
122441 sqlite3ResolveSelectNames(pParse, p, pOuterNC);
122442 if( pParse->nErr || pParse->db->mallocFailed ) return;
122443 sqlite3SelectAddTypeInfo(pParse, p);
122444 }
122445
122446 /*
122447 ** Reset the aggregate accumulator.
@@ -126333,12 +126356,14 @@
126356 void *pAux, /* Context pointer for xCreate/xConnect */
126357 void (*xDestroy)(void *) /* Module destructor function */
126358 ){
126359 Module *pMod;
126360 int nName = sqlite3Strlen30(zName);
126361 pMod = (Module *)sqlite3Malloc(sizeof(Module) + nName + 1);
126362 if( pMod==0 ){
126363 sqlite3OomFault(db);
126364 }else{
126365 Module *pDel;
126366 char *zCopy = (char *)(&pMod[1]);
126367 memcpy(zCopy, zName, nName+1);
126368 pMod->zName = zCopy;
126369 pMod->pModule = pModule;
@@ -126809,17 +126834,18 @@
126834 );
126835 return SQLITE_LOCKED;
126836 }
126837 }
126838
126839 zModuleName = sqlite3DbStrDup(db, pTab->zName);
126840 if( !zModuleName ){
126841 return SQLITE_NOMEM_BKPT;
126842 }
126843
126844 pVTable = sqlite3MallocZero(sizeof(VTable));
126845 if( !pVTable ){
126846 sqlite3OomFault(db);
126847 sqlite3DbFree(db, zModuleName);
126848 return SQLITE_NOMEM_BKPT;
126849 }
126850 pVTable->db = db;
126851 pVTable->pMod = pMod;
@@ -133669,22 +133695,23 @@
133695
133696 /*
133697 ** Return TRUE if all of the following are true:
133698 **
133699 ** (1) X has the same or lower cost that Y
133700 ** (2) X uses fewer WHERE clause terms than Y
133701 ** (3) Every WHERE clause term used by X is also used by Y
133702 ** (4) X skips at least as many columns as Y
133703 ** (5) If X is a covering index, than Y is too
133704 **
133705 ** Conditions (2) and (3) mean that X is a "proper subset" of Y.
 
 
 
133706 ** If X is a proper subset of Y then Y is a better choice and ought
133707 ** to have a lower cost. This routine returns TRUE when that cost
133708 ** relationship is inverted and needs to be adjusted. Constraint (4)
133709 ** was added because if X uses skip-scan less than Y it still might
133710 ** deserve a lower cost even if it is a proper subset of Y. Constraint (5)
133711 ** was added because a covering index probably deserves to have a lower cost
133712 ** than a non-covering index even if it is a proper subset.
133713 */
133714 static int whereLoopCheaperProperSubset(
133715 const WhereLoop *pX, /* First WhereLoop to compare */
133716 const WhereLoop *pY /* Compare against this WhereLoop */
133717 ){
@@ -133701,10 +133728,14 @@
133728 if( pX->aLTerm[i]==0 ) continue;
133729 for(j=pY->nLTerm-1; j>=0; j--){
133730 if( pY->aLTerm[j]==pX->aLTerm[i] ) break;
133731 }
133732 if( j<0 ) return 0; /* X not a subset of Y since term X[i] not used by Y */
133733 }
133734 if( (pX->wsFlags&WHERE_IDX_ONLY)!=0
133735 && (pY->wsFlags&WHERE_IDX_ONLY)==0 ){
133736 return 0; /* Constraint (5) */
133737 }
133738 return 1; /* All conditions meet */
133739 }
133740
133741 /*
@@ -141996,13 +142027,15 @@
142027 /* IMPLEMENTATION-OF: R-53536-42575 The sqlite3_libversion() function returns
142028 ** a pointer to the to the sqlite3_version[] string constant.
142029 */
142030 SQLITE_API const char *sqlite3_libversion(void){ return sqlite3_version; }
142031
142032 /* IMPLEMENTATION-OF: R-25063-23286 The sqlite3_sourceid() function returns a
142033 ** pointer to a string constant whose value is the same as the
142034 ** SQLITE_SOURCE_ID C preprocessor macro. Except if SQLite is built using
142035 ** an edited copy of the amalgamation, then the last four characters of
142036 ** the hash might be different from SQLITE_SOURCE_ID.
142037 */
142038 /* SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } */
142039
142040 /* IMPLEMENTATION-OF: R-35210-63508 The sqlite3_libversion_number() function
142041 ** returns an integer equal to SQLITE_VERSION_NUMBER.
@@ -145000,10 +145033,16 @@
145033 #ifdef SQLITE_ENABLE_RTREE
145034 if( !db->mallocFailed && rc==SQLITE_OK){
145035 rc = sqlite3RtreeInit(db);
145036 }
145037 #endif
145038
145039 #ifdef SQLITE_ENABLE_DBPAGE_VTAB
145040 if( !db->mallocFailed && rc==SQLITE_OK){
145041 rc = sqlite3DbpageRegister(db);
145042 }
145043 #endif
145044
145045 #ifdef SQLITE_ENABLE_DBSTAT_VTAB
145046 if( !db->mallocFailed && rc==SQLITE_OK){
145047 rc = sqlite3DbstatRegister(db);
145048 }
@@ -145660,11 +145699,11 @@
145699 ** sqlite3_test_control(SQLITE_TESTCTRL_ALWAYS, int X)
145700 **
145701 ** This action provides a run-time test to see how the ALWAYS and
145702 ** NEVER macros were defined at compile-time.
145703 **
145704 ** The return value is ALWAYS(X) if X is true, or 0 if X is false.
145705 **
145706 ** The recommended test is X==2. If the return value is 2, that means
145707 ** ALWAYS() and NEVER() are both no-op pass-through macros, which is the
145708 ** default setting. If the return value is 1, then ALWAYS() is either
145709 ** hard-coded to true or else it asserts if its argument is false.
@@ -145683,11 +145722,11 @@
145722 ** // ALWAYS(x) is a constant 1. NEVER(x) is a constant 0.
145723 ** }
145724 */
145725 case SQLITE_TESTCTRL_ALWAYS: {
145726 int x = va_arg(ap,int);
145727 rc = x ? ALWAYS(x) : 0;
145728 break;
145729 }
145730
145731 /*
145732 ** sqlite3_test_control(SQLITE_TESTCTRL_BYTEORDER);
@@ -170889,10 +170928,17 @@
170928 #endif
170929
170930 /* Maximum number of prepared UPDATE statements held by this module */
170931 #define SQLITE_RBU_UPDATE_CACHESIZE 16
170932
170933 /* Delta checksums disabled by default. Compile with -DRBU_ENABLE_DELTA_CKSUM
170934 ** to enable checksum verification.
170935 */
170936 #ifndef RBU_ENABLE_DELTA_CKSUM
170937 # define RBU_ENABLE_DELTA_CKSUM 0
170938 #endif
170939
170940 /*
170941 ** Swap two objects of type TYPE.
170942 */
170943 #if !defined(SQLITE_AMALGAMATION)
170944 # define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;}
@@ -171263,10 +171309,11 @@
171309 *pLen -= z - zStart;
171310 *pz = (char*)z;
171311 return v;
171312 }
171313
171314 #if RBU_ENABLE_DELTA_CKSUM
171315 /*
171316 ** Compute a 32-bit checksum on the N-byte buffer. Return the result.
171317 */
171318 static unsigned int rbuDeltaChecksum(const char *zIn, size_t N){
171319 const unsigned char *z = (const unsigned char *)zIn;
@@ -171297,10 +171344,11 @@
171344 case 1: sum3 += (z[0] << 24);
171345 default: ;
171346 }
171347 return sum3;
171348 }
171349 #endif
171350
171351 /*
171352 ** Apply a delta.
171353 **
171354 ** The output buffer should be big enough to hold the whole output
@@ -171327,11 +171375,11 @@
171375 int lenDelta, /* Length of the delta */
171376 char *zOut /* Write the output into this preallocated buffer */
171377 ){
171378 unsigned int limit;
171379 unsigned int total = 0;
171380 #if RBU_ENABLE_DELTA_CKSUM
171381 char *zOrigOut = zOut;
171382 #endif
171383
171384 limit = rbuDeltaGetInt(&zDelta, &lenDelta);
171385 if( *zDelta!='\n' ){
@@ -171382,11 +171430,11 @@
171430 break;
171431 }
171432 case ';': {
171433 zDelta++; lenDelta--;
171434 zOut[0] = 0;
171435 #if RBU_ENABLE_DELTA_CKSUM
171436 if( cnt!=rbuDeltaChecksum(zOrigOut, total) ){
171437 /* ERROR: bad checksum */
171438 return -1;
171439 }
171440 #endif
@@ -176366,10 +176414,342 @@
176414 #elif defined(SQLITE_ENABLE_DBSTAT_VTAB)
176415 SQLITE_PRIVATE int sqlite3DbstatRegister(sqlite3 *db){ return SQLITE_OK; }
176416 #endif /* SQLITE_ENABLE_DBSTAT_VTAB */
176417
176418 /************** End of dbstat.c **********************************************/
176419 /************** Begin file dbpage.c ******************************************/
176420 /*
176421 ** 2017-10-11
176422 **
176423 ** The author disclaims copyright to this source code. In place of
176424 ** a legal notice, here is a blessing:
176425 **
176426 ** May you do good and not evil.
176427 ** May you find forgiveness for yourself and forgive others.
176428 ** May you share freely, never taking more than you give.
176429 **
176430 ******************************************************************************
176431 **
176432 ** This file contains an implementation of the "sqlite_dbpage" virtual table.
176433 **
176434 ** The sqlite_dbpage virtual table is used to read or write whole raw
176435 ** pages of the database file. The pager interface is used so that
176436 ** uncommitted changes and changes recorded in the WAL file are correctly
176437 ** retrieved.
176438 **
176439 ** Usage example:
176440 **
176441 ** SELECT data FROM sqlite_dbpage('aux1') WHERE pgno=123;
176442 **
176443 ** This is an eponymous virtual table so it does not need to be created before
176444 ** use. The optional argument to the sqlite_dbpage() table name is the
176445 ** schema for the database file that is to be read. The default schema is
176446 ** "main".
176447 **
176448 ** The data field of sqlite_dbpage table can be updated. The new
176449 ** value must be a BLOB which is the correct page size, otherwise the
176450 ** update fails. Rows may not be deleted or inserted.
176451 */
176452
176453 /* #include "sqliteInt.h" ** Requires access to internal data structures ** */
176454 #if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \
176455 && !defined(SQLITE_OMIT_VIRTUALTABLE)
176456
176457 typedef struct DbpageTable DbpageTable;
176458 typedef struct DbpageCursor DbpageCursor;
176459
176460 struct DbpageCursor {
176461 sqlite3_vtab_cursor base; /* Base class. Must be first */
176462 int pgno; /* Current page number */
176463 int mxPgno; /* Last page to visit on this scan */
176464 };
176465
176466 struct DbpageTable {
176467 sqlite3_vtab base; /* Base class. Must be first */
176468 sqlite3 *db; /* The database */
176469 Pager *pPager; /* Pager being read/written */
176470 int iDb; /* Index of database to analyze */
176471 int szPage; /* Size of each page in bytes */
176472 int nPage; /* Number of pages in the file */
176473 };
176474
176475 /*
176476 ** Connect to or create a dbpagevfs virtual table.
176477 */
176478 static int dbpageConnect(
176479 sqlite3 *db,
176480 void *pAux,
176481 int argc, const char *const*argv,
176482 sqlite3_vtab **ppVtab,
176483 char **pzErr
176484 ){
176485 DbpageTable *pTab = 0;
176486 int rc = SQLITE_OK;
176487 int iDb;
176488
176489 if( argc>=4 ){
176490 Token nm;
176491 sqlite3TokenInit(&nm, (char*)argv[3]);
176492 iDb = sqlite3FindDb(db, &nm);
176493 if( iDb<0 ){
176494 *pzErr = sqlite3_mprintf("no such schema: %s", argv[3]);
176495 return SQLITE_ERROR;
176496 }
176497 }else{
176498 iDb = 0;
176499 }
176500 rc = sqlite3_declare_vtab(db,
176501 "CREATE TABLE x(pgno INTEGER PRIMARY KEY, data BLOB, schema HIDDEN)");
176502 if( rc==SQLITE_OK ){
176503 pTab = (DbpageTable *)sqlite3_malloc64(sizeof(DbpageTable));
176504 if( pTab==0 ) rc = SQLITE_NOMEM_BKPT;
176505 }
176506
176507 assert( rc==SQLITE_OK || pTab==0 );
176508 if( rc==SQLITE_OK ){
176509 Btree *pBt = db->aDb[iDb].pBt;
176510 memset(pTab, 0, sizeof(DbpageTable));
176511 pTab->db = db;
176512 pTab->iDb = iDb;
176513 pTab->pPager = pBt ? sqlite3BtreePager(pBt) : 0;
176514 }
176515
176516 *ppVtab = (sqlite3_vtab*)pTab;
176517 return rc;
176518 }
176519
176520 /*
176521 ** Disconnect from or destroy a dbpagevfs virtual table.
176522 */
176523 static int dbpageDisconnect(sqlite3_vtab *pVtab){
176524 sqlite3_free(pVtab);
176525 return SQLITE_OK;
176526 }
176527
176528 /*
176529 ** idxNum:
176530 **
176531 ** 0 full table scan
176532 ** 1 pgno=?1
176533 */
176534 static int dbpageBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
176535 int i;
176536 pIdxInfo->estimatedCost = 1.0e6; /* Initial cost estimate */
176537 for(i=0; i<pIdxInfo->nConstraint; i++){
176538 struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[i];
176539 if( p->usable && p->iColumn<=0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
176540 pIdxInfo->estimatedRows = 1;
176541 pIdxInfo->idxFlags = SQLITE_INDEX_SCAN_UNIQUE;
176542 pIdxInfo->estimatedCost = 1.0;
176543 pIdxInfo->idxNum = 1;
176544 pIdxInfo->aConstraintUsage[i].argvIndex = 1;
176545 pIdxInfo->aConstraintUsage[i].omit = 1;
176546 break;
176547 }
176548 }
176549 if( pIdxInfo->nOrderBy>=1
176550 && pIdxInfo->aOrderBy[0].iColumn<=0
176551 && pIdxInfo->aOrderBy[0].desc==0
176552 ){
176553 pIdxInfo->orderByConsumed = 1;
176554 }
176555 return SQLITE_OK;
176556 }
176557
176558 /*
176559 ** Open a new dbpagevfs cursor.
176560 */
176561 static int dbpageOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
176562 DbpageCursor *pCsr;
176563
176564 pCsr = (DbpageCursor *)sqlite3_malloc64(sizeof(DbpageCursor));
176565 if( pCsr==0 ){
176566 return SQLITE_NOMEM_BKPT;
176567 }else{
176568 memset(pCsr, 0, sizeof(DbpageCursor));
176569 pCsr->base.pVtab = pVTab;
176570 pCsr->pgno = -1;
176571 }
176572
176573 *ppCursor = (sqlite3_vtab_cursor *)pCsr;
176574 return SQLITE_OK;
176575 }
176576
176577 /*
176578 ** Close a dbpagevfs cursor.
176579 */
176580 static int dbpageClose(sqlite3_vtab_cursor *pCursor){
176581 DbpageCursor *pCsr = (DbpageCursor *)pCursor;
176582 sqlite3_free(pCsr);
176583 return SQLITE_OK;
176584 }
176585
176586 /*
176587 ** Move a dbpagevfs cursor to the next entry in the file.
176588 */
176589 static int dbpageNext(sqlite3_vtab_cursor *pCursor){
176590 int rc = SQLITE_OK;
176591 DbpageCursor *pCsr = (DbpageCursor *)pCursor;
176592 pCsr->pgno++;
176593 return rc;
176594 }
176595
176596 static int dbpageEof(sqlite3_vtab_cursor *pCursor){
176597 DbpageCursor *pCsr = (DbpageCursor *)pCursor;
176598 return pCsr->pgno > pCsr->mxPgno;
176599 }
176600
176601 static int dbpageFilter(
176602 sqlite3_vtab_cursor *pCursor,
176603 int idxNum, const char *idxStr,
176604 int argc, sqlite3_value **argv
176605 ){
176606 DbpageCursor *pCsr = (DbpageCursor *)pCursor;
176607 DbpageTable *pTab = (DbpageTable *)pCursor->pVtab;
176608 int rc = SQLITE_OK;
176609 Btree *pBt = pTab->db->aDb[pTab->iDb].pBt;
176610
176611 pTab->szPage = sqlite3BtreeGetPageSize(pBt);
176612 pTab->nPage = sqlite3BtreeLastPage(pBt);
176613 if( idxNum==1 ){
176614 pCsr->pgno = sqlite3_value_int(argv[0]);
176615 if( pCsr->pgno<1 || pCsr->pgno>pTab->nPage ){
176616 pCsr->pgno = 1;
176617 pCsr->mxPgno = 0;
176618 }else{
176619 pCsr->mxPgno = pCsr->pgno;
176620 }
176621 }else{
176622 pCsr->pgno = 1;
176623 pCsr->mxPgno = pTab->nPage;
176624 }
176625 return rc;
176626 }
176627
176628 static int dbpageColumn(
176629 sqlite3_vtab_cursor *pCursor,
176630 sqlite3_context *ctx,
176631 int i
176632 ){
176633 DbpageCursor *pCsr = (DbpageCursor *)pCursor;
176634 DbpageTable *pTab = (DbpageTable *)pCursor->pVtab;
176635 int rc = SQLITE_OK;
176636 switch( i ){
176637 case 0: { /* pgno */
176638 sqlite3_result_int(ctx, pCsr->pgno);
176639 break;
176640 }
176641 case 1: { /* data */
176642 DbPage *pDbPage = 0;
176643 rc = sqlite3PagerGet(pTab->pPager, pCsr->pgno, (DbPage**)&pDbPage, 0);
176644 if( rc==SQLITE_OK ){
176645 sqlite3_result_blob(ctx, sqlite3PagerGetData(pDbPage), pTab->szPage,
176646 SQLITE_TRANSIENT);
176647 }
176648 sqlite3PagerUnref(pDbPage);
176649 break;
176650 }
176651 default: { /* schema */
176652 sqlite3 *db = sqlite3_context_db_handle(ctx);
176653 sqlite3_result_text(ctx, db->aDb[pTab->iDb].zDbSName, -1, SQLITE_STATIC);
176654 break;
176655 }
176656 }
176657 return SQLITE_OK;
176658 }
176659
176660 static int dbpageRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
176661 DbpageCursor *pCsr = (DbpageCursor *)pCursor;
176662 *pRowid = pCsr->pgno;
176663 return SQLITE_OK;
176664 }
176665
176666 static int dbpageUpdate(
176667 sqlite3_vtab *pVtab,
176668 int argc,
176669 sqlite3_value **argv,
176670 sqlite_int64 *pRowid
176671 ){
176672 DbpageTable *pTab = (DbpageTable *)pVtab;
176673 int pgno;
176674 DbPage *pDbPage = 0;
176675 int rc = SQLITE_OK;
176676 char *zErr = 0;
176677
176678 if( argc==1 ){
176679 zErr = "cannot delete";
176680 goto update_fail;
176681 }
176682 pgno = sqlite3_value_int(argv[0]);
176683 if( pgno<1 || pgno>pTab->nPage ){
176684 zErr = "bad page number";
176685 goto update_fail;
176686 }
176687 if( sqlite3_value_int(argv[1])!=pgno ){
176688 zErr = "cannot insert";
176689 goto update_fail;
176690 }
176691 if( sqlite3_value_type(argv[3])!=SQLITE_BLOB
176692 || sqlite3_value_bytes(argv[3])!=pTab->szPage
176693 ){
176694 zErr = "bad page value";
176695 goto update_fail;
176696 }
176697 rc = sqlite3PagerGet(pTab->pPager, pgno, (DbPage**)&pDbPage, 0);
176698 if( rc==SQLITE_OK ){
176699 rc = sqlite3PagerWrite(pDbPage);
176700 if( rc==SQLITE_OK ){
176701 memcpy(sqlite3PagerGetData(pDbPage),
176702 sqlite3_value_blob(argv[3]),
176703 pTab->szPage);
176704 }
176705 }
176706 sqlite3PagerUnref(pDbPage);
176707 return rc;
176708
176709 update_fail:
176710 sqlite3_free(pVtab->zErrMsg);
176711 pVtab->zErrMsg = sqlite3_mprintf("%s", zErr);
176712 return SQLITE_ERROR;
176713 }
176714
176715 /*
176716 ** Invoke this routine to register the "dbpage" virtual table module
176717 */
176718 SQLITE_PRIVATE int sqlite3DbpageRegister(sqlite3 *db){
176719 static sqlite3_module dbpage_module = {
176720 0, /* iVersion */
176721 dbpageConnect, /* xCreate */
176722 dbpageConnect, /* xConnect */
176723 dbpageBestIndex, /* xBestIndex */
176724 dbpageDisconnect, /* xDisconnect */
176725 dbpageDisconnect, /* xDestroy */
176726 dbpageOpen, /* xOpen - open a cursor */
176727 dbpageClose, /* xClose - close a cursor */
176728 dbpageFilter, /* xFilter - configure scan constraints */
176729 dbpageNext, /* xNext - advance a cursor */
176730 dbpageEof, /* xEof - check for end of scan */
176731 dbpageColumn, /* xColumn - read data */
176732 dbpageRowid, /* xRowid - read data */
176733 dbpageUpdate, /* xUpdate */
176734 0, /* xBegin */
176735 0, /* xSync */
176736 0, /* xCommit */
176737 0, /* xRollback */
176738 0, /* xFindMethod */
176739 0, /* xRename */
176740 0, /* xSavepoint */
176741 0, /* xRelease */
176742 0, /* xRollbackTo */
176743 };
176744 return sqlite3_create_module(db, "sqlite_dbpage", &dbpage_module, 0);
176745 }
176746 #elif defined(SQLITE_ENABLE_DBPAGE_VTAB)
176747 SQLITE_PRIVATE int sqlite3DbpageRegister(sqlite3 *db){ return SQLITE_OK; }
176748 #endif /* SQLITE_ENABLE_DBSTAT_VTAB */
176749
176750 /************** End of dbpage.c **********************************************/
176751 /************** Begin file sqlite3session.c **********************************/
176752
176753 #if defined(SQLITE_ENABLE_SESSION) && defined(SQLITE_ENABLE_PREUPDATE_HOOK)
176754 /* #include "sqlite3session.h" */
176755 /* #include <assert.h> */
@@ -200697,11 +201077,11 @@
201077 int nArg, /* Number of args */
201078 sqlite3_value **apUnused /* Function arguments */
201079 ){
201080 assert( nArg==0 );
201081 UNUSED_PARAM2(nArg, apUnused);
201082 sqlite3_result_text(pCtx, "fts5: 2017-10-19 15:17:38 04925dee41a21ffca9a9f9df27d8165431668c42c2b33d08b077fdb28011170b", -1, SQLITE_TRANSIENT);
201083 }
201084
201085 static int fts5Init(sqlite3 *db){
201086 static const sqlite3_module fts5Mod = {
201087 /* iVersion */ 2,
@@ -204579,11 +204959,10 @@
204959 iVal = pCsr->aDoc[0];
204960 }else{
204961 iVal = pCsr->aCnt[0];
204962 }
204963 }else{
 
204964 assert( eType==FTS5_VOCAB_INSTANCE );
204965 switch( iCol ){
204966 case 1:
204967 sqlite3_result_int64(pCtx, pCsr->pIter->iRowid);
204968 break;
@@ -204590,11 +204969,11 @@
204969 case 2: {
204970 int ii = -1;
204971 if( eDetail==FTS5_DETAIL_FULL ){
204972 ii = FTS5_POS2COLUMN(pCsr->iInstPos);
204973 }else if( eDetail==FTS5_DETAIL_COLUMNS ){
204974 ii = (int)pCsr->iInstPos;
204975 }
204976 if( ii>=0 && ii<pCsr->pConfig->nCol ){
204977 const char *z = pCsr->pConfig->azCol[ii];
204978 sqlite3_result_text(pCtx, z, -1, SQLITE_STATIC);
204979 }
@@ -204966,12 +205345,12 @@
205345 }
205346 #endif /* SQLITE_CORE */
205347 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
205348
205349 /************** End of stmt.c ************************************************/
205350 #if __LINE__!=205350
205351 #undef SQLITE_SOURCE_ID
205352 #define SQLITE_SOURCE_ID "2017-10-21 17:17:17 fb3ee1b7cac09e4950e4f48b44c277e4f391cb6c8f069644732d2389ca65alt2"
205353 #endif
205354 /* Return the source-id for this library */
205355 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
205356 /************************** End of sqlite3.c ******************************/
205357
+9 -9
--- 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.21.0"
127127
#define SQLITE_VERSION_NUMBER 3021000
128
-#define SQLITE_SOURCE_ID "2017-10-02 02:52:54 c9104b59c7ed360291f7f6fc8caae938e9840c77620d598e4096f78183bf807a"
128
+#define SQLITE_SOURCE_ID "2017-10-21 17:17:17 fb3ee1b7cac09e4950e4f48b44c277e4f391cb6c8f069644732d2389ca653da4"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -9229,12 +9229,12 @@
92299229
** a single table are grouped together, tables appear in the order in which
92309230
** they were attached to the session object).
92319231
*/
92329232
SQLITE_API int sqlite3session_patchset(
92339233
sqlite3_session *pSession, /* Session object */
9234
- int *pnPatchset, /* OUT: Size of buffer at *ppChangeset */
9235
- void **ppPatchset /* OUT: Buffer containing changeset */
9234
+ int *pnPatchset, /* OUT: Size of buffer at *ppPatchset */
9235
+ void **ppPatchset /* OUT: Buffer containing patchset */
92369236
);
92379237
92389238
/*
92399239
** CAPI3REF: Test if a changeset has recorded any changes.
92409240
**
@@ -9997,16 +9997,16 @@
99979997
** The six streaming API xxx_strm() functions serve similar purposes to the
99989998
** corresponding non-streaming API functions:
99999999
**
1000010000
** <table border=1 style="margin-left:8ex;margin-right:8ex">
1000110001
** <tr><th>Streaming function<th>Non-streaming equivalent</th>
10002
-** <tr><td>sqlite3changeset_apply_str<td>[sqlite3changeset_apply]
10003
-** <tr><td>sqlite3changeset_concat_str<td>[sqlite3changeset_concat]
10004
-** <tr><td>sqlite3changeset_invert_str<td>[sqlite3changeset_invert]
10005
-** <tr><td>sqlite3changeset_start_str<td>[sqlite3changeset_start]
10006
-** <tr><td>sqlite3session_changeset_str<td>[sqlite3session_changeset]
10007
-** <tr><td>sqlite3session_patchset_str<td>[sqlite3session_patchset]
10002
+** <tr><td>sqlite3changeset_apply_strm<td>[sqlite3changeset_apply]
10003
+** <tr><td>sqlite3changeset_concat_strm<td>[sqlite3changeset_concat]
10004
+** <tr><td>sqlite3changeset_invert_strm<td>[sqlite3changeset_invert]
10005
+** <tr><td>sqlite3changeset_start_strm<td>[sqlite3changeset_start]
10006
+** <tr><td>sqlite3session_changeset_strm<td>[sqlite3session_changeset]
10007
+** <tr><td>sqlite3session_patchset_strm<td>[sqlite3session_patchset]
1000810008
** </table>
1000910009
**
1001010010
** Non-streaming functions that accept changesets (or patchsets) as input
1001110011
** require that the entire changeset be stored in a single buffer in memory.
1001210012
** Similarly, those that return a changeset or patchset do so by returning
1001310013
--- 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.21.0"
127 #define SQLITE_VERSION_NUMBER 3021000
128 #define SQLITE_SOURCE_ID "2017-10-02 02:52:54 c9104b59c7ed360291f7f6fc8caae938e9840c77620d598e4096f78183bf807a"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -9229,12 +9229,12 @@
9229 ** a single table are grouped together, tables appear in the order in which
9230 ** they were attached to the session object).
9231 */
9232 SQLITE_API int sqlite3session_patchset(
9233 sqlite3_session *pSession, /* Session object */
9234 int *pnPatchset, /* OUT: Size of buffer at *ppChangeset */
9235 void **ppPatchset /* OUT: Buffer containing changeset */
9236 );
9237
9238 /*
9239 ** CAPI3REF: Test if a changeset has recorded any changes.
9240 **
@@ -9997,16 +9997,16 @@
9997 ** The six streaming API xxx_strm() functions serve similar purposes to the
9998 ** corresponding non-streaming API functions:
9999 **
10000 ** <table border=1 style="margin-left:8ex;margin-right:8ex">
10001 ** <tr><th>Streaming function<th>Non-streaming equivalent</th>
10002 ** <tr><td>sqlite3changeset_apply_str<td>[sqlite3changeset_apply]
10003 ** <tr><td>sqlite3changeset_concat_str<td>[sqlite3changeset_concat]
10004 ** <tr><td>sqlite3changeset_invert_str<td>[sqlite3changeset_invert]
10005 ** <tr><td>sqlite3changeset_start_str<td>[sqlite3changeset_start]
10006 ** <tr><td>sqlite3session_changeset_str<td>[sqlite3session_changeset]
10007 ** <tr><td>sqlite3session_patchset_str<td>[sqlite3session_patchset]
10008 ** </table>
10009 **
10010 ** Non-streaming functions that accept changesets (or patchsets) as input
10011 ** require that the entire changeset be stored in a single buffer in memory.
10012 ** Similarly, those that return a changeset or patchset do so by returning
10013
--- 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.21.0"
127 #define SQLITE_VERSION_NUMBER 3021000
128 #define SQLITE_SOURCE_ID "2017-10-21 17:17:17 fb3ee1b7cac09e4950e4f48b44c277e4f391cb6c8f069644732d2389ca653da4"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -9229,12 +9229,12 @@
9229 ** a single table are grouped together, tables appear in the order in which
9230 ** they were attached to the session object).
9231 */
9232 SQLITE_API int sqlite3session_patchset(
9233 sqlite3_session *pSession, /* Session object */
9234 int *pnPatchset, /* OUT: Size of buffer at *ppPatchset */
9235 void **ppPatchset /* OUT: Buffer containing patchset */
9236 );
9237
9238 /*
9239 ** CAPI3REF: Test if a changeset has recorded any changes.
9240 **
@@ -9997,16 +9997,16 @@
9997 ** The six streaming API xxx_strm() functions serve similar purposes to the
9998 ** corresponding non-streaming API functions:
9999 **
10000 ** <table border=1 style="margin-left:8ex;margin-right:8ex">
10001 ** <tr><th>Streaming function<th>Non-streaming equivalent</th>
10002 ** <tr><td>sqlite3changeset_apply_strm<td>[sqlite3changeset_apply]
10003 ** <tr><td>sqlite3changeset_concat_strm<td>[sqlite3changeset_concat]
10004 ** <tr><td>sqlite3changeset_invert_strm<td>[sqlite3changeset_invert]
10005 ** <tr><td>sqlite3changeset_start_strm<td>[sqlite3changeset_start]
10006 ** <tr><td>sqlite3session_changeset_strm<td>[sqlite3session_changeset]
10007 ** <tr><td>sqlite3session_patchset_strm<td>[sqlite3session_patchset]
10008 ** </table>
10009 **
10010 ** Non-streaming functions that accept changesets (or patchsets) as input
10011 ** require that the entire changeset be stored in a single buffer in memory.
10012 ** Similarly, those that return a changeset or patchset do so by returning
10013

Keyboard Shortcuts

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