Fossil SCM

Update the built-in SQLite to the third 3.22.0 beta for testing. Also fix a typo in a comment in the "fossil ui" command.

drh 2018-01-21 23:48 trunk
Commit 861f4b0bde739b6b76280a55c4b09b8a948327887be73c019ab4e772e890a7e2
4 files changed +1 -1 +57 -14 +285 -73 +32 -4
+1 -1
--- src/main.c
+++ src/main.c
@@ -2034,11 +2034,11 @@
20342034
** If g.argv[arg] exists then it is either the name of a repository
20352035
** that will be used by a server, or else it is a directory that
20362036
** contains multiple repositories that can be served. If g.argv[arg]
20372037
** is a directory, the repositories it contains must be named
20382038
** "*.fossil". If g.argv[arg] does not exist, then we must be within
2039
-** an open check-out and the repository serve is the repository of
2039
+** an open check-out and the repository to serve is the repository of
20402040
** that check-out.
20412041
**
20422042
** Open the repository to be served if it is known. If g.argv[arg] is
20432043
** a directory full of repositories, then set g.zRepositoryName to
20442044
** the name of that directory and the specific repository will be
20452045
--- src/main.c
+++ src/main.c
@@ -2034,11 +2034,11 @@
2034 ** If g.argv[arg] exists then it is either the name of a repository
2035 ** that will be used by a server, or else it is a directory that
2036 ** contains multiple repositories that can be served. If g.argv[arg]
2037 ** is a directory, the repositories it contains must be named
2038 ** "*.fossil". If g.argv[arg] does not exist, then we must be within
2039 ** an open check-out and the repository serve is the repository of
2040 ** that check-out.
2041 **
2042 ** Open the repository to be served if it is known. If g.argv[arg] is
2043 ** a directory full of repositories, then set g.zRepositoryName to
2044 ** the name of that directory and the specific repository will be
2045
--- src/main.c
+++ src/main.c
@@ -2034,11 +2034,11 @@
2034 ** If g.argv[arg] exists then it is either the name of a repository
2035 ** that will be used by a server, or else it is a directory that
2036 ** contains multiple repositories that can be served. If g.argv[arg]
2037 ** is a directory, the repositories it contains must be named
2038 ** "*.fossil". If g.argv[arg] does not exist, then we must be within
2039 ** an open check-out and the repository to serve is the repository of
2040 ** that check-out.
2041 **
2042 ** Open the repository to be served if it is known. If g.argv[arg] is
2043 ** a directory full of repositories, then set g.zRepositoryName to
2044 ** the name of that directory and the specific repository will be
2045
+57 -14
--- src/shell.c
+++ src/shell.c
@@ -881,10 +881,11 @@
881881
int nVal,
882882
sqlite3_value **apVal
883883
){
884884
const char *zName = (const char*)sqlite3_value_text(apVal[0]);
885885
char *zFake = shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName);
886
+ UNUSED_PARAMETER(nVal);
886887
if( zFake ){
887888
sqlite3_result_text(pCtx, sqlite3_mprintf("/* %s */", zFake),
888889
-1, sqlite3_free);
889890
free(zFake);
890891
}
@@ -925,10 +926,11 @@
925926
int i = 0;
926927
const char *zIn = (const char*)sqlite3_value_text(apVal[0]);
927928
const char *zSchema = (const char*)sqlite3_value_text(apVal[1]);
928929
const char *zName = (const char*)sqlite3_value_text(apVal[2]);
929930
sqlite3 *db = sqlite3_context_db_handle(pCtx);
931
+ UNUSED_PARAMETER(nVal);
930932
if( zIn!=0 && strncmp(zIn, "CREATE ", 7)==0 ){
931933
for(i=0; i<(int)(sizeof(aPrefix)/sizeof(aPrefix[0])); i++){
932934
int n = strlen30(aPrefix[i]);
933935
if( strncmp(zIn+7, aPrefix[i], n)==0 && zIn[n+7]==' ' ){
934936
char *z = 0;
@@ -2414,10 +2416,11 @@
24142416
sqlite3_value **argv
24152417
){
24162418
int i;
24172419
int iMode = sqlite3_value_int(argv[0]);
24182420
char z[16];
2421
+ (void)argc;
24192422
if( S_ISLNK(iMode) ){
24202423
z[0] = 'l';
24212424
}else if( S_ISREG(iMode) ){
24222425
z[0] = '-';
24232426
}else if( S_ISDIR(iMode) ){
@@ -2479,11 +2482,14 @@
24792482
sqlite3_vtab **ppVtab,
24802483
char **pzErr
24812484
){
24822485
fsdir_tab *pNew = 0;
24832486
int rc;
2484
-
2487
+ (void)pAux;
2488
+ (void)argc;
2489
+ (void)argv;
2490
+ (void)pzErr;
24852491
rc = sqlite3_declare_vtab(db, "CREATE TABLE x" FSDIR_SCHEMA);
24862492
if( rc==SQLITE_OK ){
24872493
pNew = (fsdir_tab*)sqlite3_malloc( sizeof(*pNew) );
24882494
if( pNew==0 ) return SQLITE_NOMEM;
24892495
memset(pNew, 0, sizeof(*pNew));
@@ -2503,10 +2509,11 @@
25032509
/*
25042510
** Constructor for a new fsdir_cursor object.
25052511
*/
25062512
static int fsdirOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
25072513
fsdir_cursor *pCur;
2514
+ (void)p;
25082515
pCur = sqlite3_malloc( sizeof(*pCur) );
25092516
if( pCur==0 ) return SQLITE_NOMEM;
25102517
memset(pCur, 0, sizeof(*pCur));
25112518
pCur->iLvl = -1;
25122519
*ppCursor = &pCur->base;
@@ -2706,11 +2713,11 @@
27062713
int idxNum, const char *idxStr,
27072714
int argc, sqlite3_value **argv
27082715
){
27092716
const char *zDir = 0;
27102717
fsdir_cursor *pCur = (fsdir_cursor*)cur;
2711
-
2718
+ (void)idxStr;
27122719
fsdirResetCursor(pCur);
27132720
27142721
if( idxNum==0 ){
27152722
fsdirSetErrmsg(pCur, "table function fsdir requires an argument");
27162723
return SQLITE_ERROR;
@@ -2764,12 +2771,13 @@
27642771
sqlite3_index_info *pIdxInfo
27652772
){
27662773
int i; /* Loop over constraints */
27672774
int idx4 = -1;
27682775
int idx5 = -1;
2769
-
27702776
const struct sqlite3_index_constraint *pConstraint;
2777
+
2778
+ (void)tab;
27712779
pConstraint = pIdxInfo->aConstraint;
27722780
for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
27732781
if( pConstraint->usable==0 ) continue;
27742782
if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
27752783
if( pConstraint->iColumn==4 ) idx4 = i;
@@ -2819,10 +2827,13 @@
28192827
0, /* xSync */
28202828
0, /* xCommit */
28212829
0, /* xRollback */
28222830
0, /* xFindMethod */
28232831
0, /* xRename */
2832
+ 0, /* xSavepoint */
2833
+ 0, /* xRelease */
2834
+ 0 /* xRollbackTo */
28242835
};
28252836
28262837
int rc = sqlite3_create_module(db, "fsdir", &fsdirModule, 0);
28272838
return rc;
28282839
}
@@ -3931,10 +3942,12 @@
39313942
const sqlite3_api_routines *pApi
39323943
){
39333944
int rc = SQLITE_OK;
39343945
sqlite3_vfs *pOrig;
39353946
SQLITE_EXTENSION_INIT2(pApi);
3947
+ (void)pzErrMsg;
3948
+ (void)db;
39363949
pOrig = sqlite3_vfs_find(0);
39373950
apnd_vfs.iVersion = pOrig->iVersion;
39383951
apnd_vfs.pAppData = pOrig;
39393952
apnd_vfs.szOsFile = pOrig->szOsFile + sizeof(ApndFile);
39403953
rc = sqlite3_vfs_register(&apnd_vfs, 0);
@@ -4720,11 +4733,11 @@
47204733
rc = SQLITE_NOMEM;
47214734
}else{
47224735
int res;
47234736
z_stream str;
47244737
memset(&str, 0, sizeof(str));
4725
- str.next_in = (z_const Bytef*)aIn;
4738
+ str.next_in = (Bytef*)aIn;
47264739
str.avail_in = nIn;
47274740
str.next_out = aOut;
47284741
str.avail_out = nAlloc;
47294742
47304743
deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
@@ -5286,18 +5299,20 @@
52865299
sz = nIn;
52875300
pData = aIn;
52885301
nData = nIn;
52895302
if( iMethod!=0 && iMethod!=8 ){
52905303
rc = SQLITE_CONSTRAINT;
5291
- }else if( bAuto || iMethod ){
5292
- int nCmp;
5293
- rc = zipfileDeflate(pTab, aIn, nIn, &pFree, &nCmp);
5294
- if( rc==SQLITE_OK ){
5295
- if( iMethod || nCmp<nIn ){
5296
- iMethod = 8;
5297
- pData = pFree;
5298
- nData = nCmp;
5304
+ }else{
5305
+ if( bAuto || iMethod ){
5306
+ int nCmp;
5307
+ rc = zipfileDeflate(pTab, aIn, nIn, &pFree, &nCmp);
5308
+ if( rc==SQLITE_OK ){
5309
+ if( iMethod || nCmp<nIn ){
5310
+ iMethod = 8;
5311
+ pData = pFree;
5312
+ nData = nCmp;
5313
+ }
52995314
}
53005315
}
53015316
iCrc32 = crc32(0, aIn, nIn);
53025317
}
53035318
}
@@ -6417,19 +6432,24 @@
64176432
sqlite3_vtab *pVtab,
64186433
int nData,
64196434
sqlite3_value **azData,
64206435
sqlite_int64 *pRowid
64216436
){
6437
+ (void)pVtab;
6438
+ (void)nData;
6439
+ (void)azData;
6440
+ (void)pRowid;
64226441
return SQLITE_OK;
64236442
}
64246443
64256444
/*
64266445
** Virtual table module xOpen method.
64276446
*/
64286447
static int expertOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
64296448
int rc = SQLITE_OK;
64306449
ExpertCsr *pCsr;
6450
+ (void)pVTab;
64316451
pCsr = idxMalloc(&rc, sizeof(ExpertCsr));
64326452
*ppCursor = (sqlite3_vtab_cursor*)pCsr;
64336453
return rc;
64346454
}
64356455
@@ -6475,10 +6495,11 @@
64756495
64766496
/*
64776497
** Virtual table module xRowid method.
64786498
*/
64796499
static int expertRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
6500
+ (void)cur;
64806501
*pRowid = 0;
64816502
return SQLITE_OK;
64826503
}
64836504
64846505
/*
@@ -6505,10 +6526,14 @@
65056526
ExpertCsr *pCsr = (ExpertCsr*)cur;
65066527
ExpertVtab *pVtab = (ExpertVtab*)(cur->pVtab);
65076528
sqlite3expert *pExpert = pVtab->pExpert;
65086529
int rc;
65096530
6531
+ (void)idxNum;
6532
+ (void)idxStr;
6533
+ (void)argc;
6534
+ (void)argv;
65106535
rc = sqlite3_finalize(pCsr->pData);
65116536
pCsr->pData = 0;
65126537
if( rc==SQLITE_OK ){
65136538
rc = idxPrintfPrepareStmt(pExpert->db, &pCsr->pData, &pVtab->base.zErrMsg,
65146539
"SELECT * FROM main.%Q WHERE sample()", pVtab->pTab->zName
@@ -6915,11 +6940,11 @@
69156940
69166941
/*
69176942
** Create candidate indexes in database [dbm] based on the data in
69186943
** linked-list pScan.
69196944
*/
6920
-static int idxCreateCandidates(sqlite3expert *p, char **pzErr){
6945
+static int idxCreateCandidates(sqlite3expert *p){
69216946
int rc = SQLITE_OK;
69226947
IdxScan *pIter;
69236948
69246949
for(pIter=p->pScan; pIter && rc==SQLITE_OK; pIter=pIter->pNextScan){
69256950
rc = idxCreateFromWhere(p, pIter, 0);
@@ -7078,10 +7103,12 @@
70787103
const char *z4,
70797104
const char *zDb,
70807105
const char *zTrigger
70817106
){
70827107
int rc = SQLITE_OK;
7108
+ (void)z4;
7109
+ (void)zTrigger;
70837110
if( eOp==SQLITE_INSERT || eOp==SQLITE_UPDATE || eOp==SQLITE_DELETE ){
70847111
if( sqlite3_stricmp(zDb, "main")==0 ){
70857112
sqlite3expert *p = (sqlite3expert*)pCtx;
70867113
IdxTable *pTab;
70877114
for(pTab=p->pTable; pTab; pTab=pTab->pNext){
@@ -7280,10 +7307,11 @@
72807307
sqlite3_value **argv
72817308
){
72827309
struct IdxSampleCtx *p = (struct IdxSampleCtx*)sqlite3_user_data(pCtx);
72837310
int bRet;
72847311
7312
+ (void)argv;
72857313
assert( argc==0 );
72867314
if( p->nRow==0.0 ){
72877315
bRet = 1;
72887316
}else{
72897317
bRet = (p->nRet / p->nRow) <= p->target;
@@ -7765,11 +7793,11 @@
77657793
/* Do trigger processing to collect any extra IdxScan structures */
77667794
rc = idxProcessTriggers(p, pzErr);
77677795
77687796
/* Create candidate indexes within the in-memory database file */
77697797
if( rc==SQLITE_OK ){
7770
- rc = idxCreateCandidates(p, pzErr);
7798
+ rc = idxCreateCandidates(p);
77717799
}
77727800
77737801
/* Generate the stat1 data */
77747802
if( rc==SQLITE_OK ){
77757803
rc = idxPopulateStat1(p, pzErr);
@@ -8033,10 +8061,11 @@
80338061
sqlite3_context *pCtx,
80348062
int nVal,
80358063
sqlite3_value **apVal
80368064
){
80378065
ShellState *p = (ShellState*)sqlite3_user_data(pCtx);
8066
+ (void)nVal;
80388067
utf8_printf(p->out, "%s\n", sqlite3_value_text(apVal[0]));
80398068
sqlite3_result_value(pCtx, apVal[0]);
80408069
}
80418070
80428071
/*
@@ -14418,10 +14447,24 @@
1441814447
#endif /* SQLITE_USER_AUTHENTICATION */
1441914448
1442014449
if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
1442114450
utf8_printf(p->out, "SQLite %s %s\n" /*extra-version-info*/,
1442214451
sqlite3_libversion(), sqlite3_sourceid());
14452
+#if SQLITE_HAVE_ZLIB
14453
+ utf8_printf(p->out, "zlib version %s\n", zlibVersion());
14454
+#endif
14455
+#define CTIMEOPT_VAL_(opt) #opt
14456
+#define CTIMEOPT_VAL(opt) CTIMEOPT_VAL_(opt)
14457
+#if defined(__clang__) && defined(__clang_major__)
14458
+ utf8_printf(p->out, "clang-" CTIMEOPT_VAL(__clang_major__) "."
14459
+ CTIMEOPT_VAL(__clang_minor__) "."
14460
+ CTIMEOPT_VAL(__clang_patchlevel__) "\n");
14461
+#elif defined(_MSC_VER)
14462
+ utf8_printf(p->out, "msvc-" CTIMEOPT_VAL(_MSC_VER) "\n");
14463
+#elif defined(__GNUC__) && defined(__VERSION__)
14464
+ utf8_printf(p->out, "gcc-" __VERSION__ "\n");
14465
+#endif
1442314466
}else
1442414467
1442514468
if( c=='v' && strncmp(azArg[0], "vfsinfo", n)==0 ){
1442614469
const char *zDbName = nArg==2 ? azArg[1] : "main";
1442714470
sqlite3_vfs *pVfs = 0;
1442814471
--- src/shell.c
+++ src/shell.c
@@ -881,10 +881,11 @@
881 int nVal,
882 sqlite3_value **apVal
883 ){
884 const char *zName = (const char*)sqlite3_value_text(apVal[0]);
885 char *zFake = shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName);
 
886 if( zFake ){
887 sqlite3_result_text(pCtx, sqlite3_mprintf("/* %s */", zFake),
888 -1, sqlite3_free);
889 free(zFake);
890 }
@@ -925,10 +926,11 @@
925 int i = 0;
926 const char *zIn = (const char*)sqlite3_value_text(apVal[0]);
927 const char *zSchema = (const char*)sqlite3_value_text(apVal[1]);
928 const char *zName = (const char*)sqlite3_value_text(apVal[2]);
929 sqlite3 *db = sqlite3_context_db_handle(pCtx);
 
930 if( zIn!=0 && strncmp(zIn, "CREATE ", 7)==0 ){
931 for(i=0; i<(int)(sizeof(aPrefix)/sizeof(aPrefix[0])); i++){
932 int n = strlen30(aPrefix[i]);
933 if( strncmp(zIn+7, aPrefix[i], n)==0 && zIn[n+7]==' ' ){
934 char *z = 0;
@@ -2414,10 +2416,11 @@
2414 sqlite3_value **argv
2415 ){
2416 int i;
2417 int iMode = sqlite3_value_int(argv[0]);
2418 char z[16];
 
2419 if( S_ISLNK(iMode) ){
2420 z[0] = 'l';
2421 }else if( S_ISREG(iMode) ){
2422 z[0] = '-';
2423 }else if( S_ISDIR(iMode) ){
@@ -2479,11 +2482,14 @@
2479 sqlite3_vtab **ppVtab,
2480 char **pzErr
2481 ){
2482 fsdir_tab *pNew = 0;
2483 int rc;
2484
 
 
 
2485 rc = sqlite3_declare_vtab(db, "CREATE TABLE x" FSDIR_SCHEMA);
2486 if( rc==SQLITE_OK ){
2487 pNew = (fsdir_tab*)sqlite3_malloc( sizeof(*pNew) );
2488 if( pNew==0 ) return SQLITE_NOMEM;
2489 memset(pNew, 0, sizeof(*pNew));
@@ -2503,10 +2509,11 @@
2503 /*
2504 ** Constructor for a new fsdir_cursor object.
2505 */
2506 static int fsdirOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
2507 fsdir_cursor *pCur;
 
2508 pCur = sqlite3_malloc( sizeof(*pCur) );
2509 if( pCur==0 ) return SQLITE_NOMEM;
2510 memset(pCur, 0, sizeof(*pCur));
2511 pCur->iLvl = -1;
2512 *ppCursor = &pCur->base;
@@ -2706,11 +2713,11 @@
2706 int idxNum, const char *idxStr,
2707 int argc, sqlite3_value **argv
2708 ){
2709 const char *zDir = 0;
2710 fsdir_cursor *pCur = (fsdir_cursor*)cur;
2711
2712 fsdirResetCursor(pCur);
2713
2714 if( idxNum==0 ){
2715 fsdirSetErrmsg(pCur, "table function fsdir requires an argument");
2716 return SQLITE_ERROR;
@@ -2764,12 +2771,13 @@
2764 sqlite3_index_info *pIdxInfo
2765 ){
2766 int i; /* Loop over constraints */
2767 int idx4 = -1;
2768 int idx5 = -1;
2769
2770 const struct sqlite3_index_constraint *pConstraint;
 
 
2771 pConstraint = pIdxInfo->aConstraint;
2772 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
2773 if( pConstraint->usable==0 ) continue;
2774 if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
2775 if( pConstraint->iColumn==4 ) idx4 = i;
@@ -2819,10 +2827,13 @@
2819 0, /* xSync */
2820 0, /* xCommit */
2821 0, /* xRollback */
2822 0, /* xFindMethod */
2823 0, /* xRename */
 
 
 
2824 };
2825
2826 int rc = sqlite3_create_module(db, "fsdir", &fsdirModule, 0);
2827 return rc;
2828 }
@@ -3931,10 +3942,12 @@
3931 const sqlite3_api_routines *pApi
3932 ){
3933 int rc = SQLITE_OK;
3934 sqlite3_vfs *pOrig;
3935 SQLITE_EXTENSION_INIT2(pApi);
 
 
3936 pOrig = sqlite3_vfs_find(0);
3937 apnd_vfs.iVersion = pOrig->iVersion;
3938 apnd_vfs.pAppData = pOrig;
3939 apnd_vfs.szOsFile = pOrig->szOsFile + sizeof(ApndFile);
3940 rc = sqlite3_vfs_register(&apnd_vfs, 0);
@@ -4720,11 +4733,11 @@
4720 rc = SQLITE_NOMEM;
4721 }else{
4722 int res;
4723 z_stream str;
4724 memset(&str, 0, sizeof(str));
4725 str.next_in = (z_const Bytef*)aIn;
4726 str.avail_in = nIn;
4727 str.next_out = aOut;
4728 str.avail_out = nAlloc;
4729
4730 deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
@@ -5286,18 +5299,20 @@
5286 sz = nIn;
5287 pData = aIn;
5288 nData = nIn;
5289 if( iMethod!=0 && iMethod!=8 ){
5290 rc = SQLITE_CONSTRAINT;
5291 }else if( bAuto || iMethod ){
5292 int nCmp;
5293 rc = zipfileDeflate(pTab, aIn, nIn, &pFree, &nCmp);
5294 if( rc==SQLITE_OK ){
5295 if( iMethod || nCmp<nIn ){
5296 iMethod = 8;
5297 pData = pFree;
5298 nData = nCmp;
 
 
5299 }
5300 }
5301 iCrc32 = crc32(0, aIn, nIn);
5302 }
5303 }
@@ -6417,19 +6432,24 @@
6417 sqlite3_vtab *pVtab,
6418 int nData,
6419 sqlite3_value **azData,
6420 sqlite_int64 *pRowid
6421 ){
 
 
 
 
6422 return SQLITE_OK;
6423 }
6424
6425 /*
6426 ** Virtual table module xOpen method.
6427 */
6428 static int expertOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
6429 int rc = SQLITE_OK;
6430 ExpertCsr *pCsr;
 
6431 pCsr = idxMalloc(&rc, sizeof(ExpertCsr));
6432 *ppCursor = (sqlite3_vtab_cursor*)pCsr;
6433 return rc;
6434 }
6435
@@ -6475,10 +6495,11 @@
6475
6476 /*
6477 ** Virtual table module xRowid method.
6478 */
6479 static int expertRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
 
6480 *pRowid = 0;
6481 return SQLITE_OK;
6482 }
6483
6484 /*
@@ -6505,10 +6526,14 @@
6505 ExpertCsr *pCsr = (ExpertCsr*)cur;
6506 ExpertVtab *pVtab = (ExpertVtab*)(cur->pVtab);
6507 sqlite3expert *pExpert = pVtab->pExpert;
6508 int rc;
6509
 
 
 
 
6510 rc = sqlite3_finalize(pCsr->pData);
6511 pCsr->pData = 0;
6512 if( rc==SQLITE_OK ){
6513 rc = idxPrintfPrepareStmt(pExpert->db, &pCsr->pData, &pVtab->base.zErrMsg,
6514 "SELECT * FROM main.%Q WHERE sample()", pVtab->pTab->zName
@@ -6915,11 +6940,11 @@
6915
6916 /*
6917 ** Create candidate indexes in database [dbm] based on the data in
6918 ** linked-list pScan.
6919 */
6920 static int idxCreateCandidates(sqlite3expert *p, char **pzErr){
6921 int rc = SQLITE_OK;
6922 IdxScan *pIter;
6923
6924 for(pIter=p->pScan; pIter && rc==SQLITE_OK; pIter=pIter->pNextScan){
6925 rc = idxCreateFromWhere(p, pIter, 0);
@@ -7078,10 +7103,12 @@
7078 const char *z4,
7079 const char *zDb,
7080 const char *zTrigger
7081 ){
7082 int rc = SQLITE_OK;
 
 
7083 if( eOp==SQLITE_INSERT || eOp==SQLITE_UPDATE || eOp==SQLITE_DELETE ){
7084 if( sqlite3_stricmp(zDb, "main")==0 ){
7085 sqlite3expert *p = (sqlite3expert*)pCtx;
7086 IdxTable *pTab;
7087 for(pTab=p->pTable; pTab; pTab=pTab->pNext){
@@ -7280,10 +7307,11 @@
7280 sqlite3_value **argv
7281 ){
7282 struct IdxSampleCtx *p = (struct IdxSampleCtx*)sqlite3_user_data(pCtx);
7283 int bRet;
7284
 
7285 assert( argc==0 );
7286 if( p->nRow==0.0 ){
7287 bRet = 1;
7288 }else{
7289 bRet = (p->nRet / p->nRow) <= p->target;
@@ -7765,11 +7793,11 @@
7765 /* Do trigger processing to collect any extra IdxScan structures */
7766 rc = idxProcessTriggers(p, pzErr);
7767
7768 /* Create candidate indexes within the in-memory database file */
7769 if( rc==SQLITE_OK ){
7770 rc = idxCreateCandidates(p, pzErr);
7771 }
7772
7773 /* Generate the stat1 data */
7774 if( rc==SQLITE_OK ){
7775 rc = idxPopulateStat1(p, pzErr);
@@ -8033,10 +8061,11 @@
8033 sqlite3_context *pCtx,
8034 int nVal,
8035 sqlite3_value **apVal
8036 ){
8037 ShellState *p = (ShellState*)sqlite3_user_data(pCtx);
 
8038 utf8_printf(p->out, "%s\n", sqlite3_value_text(apVal[0]));
8039 sqlite3_result_value(pCtx, apVal[0]);
8040 }
8041
8042 /*
@@ -14418,10 +14447,24 @@
14418 #endif /* SQLITE_USER_AUTHENTICATION */
14419
14420 if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
14421 utf8_printf(p->out, "SQLite %s %s\n" /*extra-version-info*/,
14422 sqlite3_libversion(), sqlite3_sourceid());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14423 }else
14424
14425 if( c=='v' && strncmp(azArg[0], "vfsinfo", n)==0 ){
14426 const char *zDbName = nArg==2 ? azArg[1] : "main";
14427 sqlite3_vfs *pVfs = 0;
14428
--- src/shell.c
+++ src/shell.c
@@ -881,10 +881,11 @@
881 int nVal,
882 sqlite3_value **apVal
883 ){
884 const char *zName = (const char*)sqlite3_value_text(apVal[0]);
885 char *zFake = shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName);
886 UNUSED_PARAMETER(nVal);
887 if( zFake ){
888 sqlite3_result_text(pCtx, sqlite3_mprintf("/* %s */", zFake),
889 -1, sqlite3_free);
890 free(zFake);
891 }
@@ -925,10 +926,11 @@
926 int i = 0;
927 const char *zIn = (const char*)sqlite3_value_text(apVal[0]);
928 const char *zSchema = (const char*)sqlite3_value_text(apVal[1]);
929 const char *zName = (const char*)sqlite3_value_text(apVal[2]);
930 sqlite3 *db = sqlite3_context_db_handle(pCtx);
931 UNUSED_PARAMETER(nVal);
932 if( zIn!=0 && strncmp(zIn, "CREATE ", 7)==0 ){
933 for(i=0; i<(int)(sizeof(aPrefix)/sizeof(aPrefix[0])); i++){
934 int n = strlen30(aPrefix[i]);
935 if( strncmp(zIn+7, aPrefix[i], n)==0 && zIn[n+7]==' ' ){
936 char *z = 0;
@@ -2414,10 +2416,11 @@
2416 sqlite3_value **argv
2417 ){
2418 int i;
2419 int iMode = sqlite3_value_int(argv[0]);
2420 char z[16];
2421 (void)argc;
2422 if( S_ISLNK(iMode) ){
2423 z[0] = 'l';
2424 }else if( S_ISREG(iMode) ){
2425 z[0] = '-';
2426 }else if( S_ISDIR(iMode) ){
@@ -2479,11 +2482,14 @@
2482 sqlite3_vtab **ppVtab,
2483 char **pzErr
2484 ){
2485 fsdir_tab *pNew = 0;
2486 int rc;
2487 (void)pAux;
2488 (void)argc;
2489 (void)argv;
2490 (void)pzErr;
2491 rc = sqlite3_declare_vtab(db, "CREATE TABLE x" FSDIR_SCHEMA);
2492 if( rc==SQLITE_OK ){
2493 pNew = (fsdir_tab*)sqlite3_malloc( sizeof(*pNew) );
2494 if( pNew==0 ) return SQLITE_NOMEM;
2495 memset(pNew, 0, sizeof(*pNew));
@@ -2503,10 +2509,11 @@
2509 /*
2510 ** Constructor for a new fsdir_cursor object.
2511 */
2512 static int fsdirOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
2513 fsdir_cursor *pCur;
2514 (void)p;
2515 pCur = sqlite3_malloc( sizeof(*pCur) );
2516 if( pCur==0 ) return SQLITE_NOMEM;
2517 memset(pCur, 0, sizeof(*pCur));
2518 pCur->iLvl = -1;
2519 *ppCursor = &pCur->base;
@@ -2706,11 +2713,11 @@
2713 int idxNum, const char *idxStr,
2714 int argc, sqlite3_value **argv
2715 ){
2716 const char *zDir = 0;
2717 fsdir_cursor *pCur = (fsdir_cursor*)cur;
2718 (void)idxStr;
2719 fsdirResetCursor(pCur);
2720
2721 if( idxNum==0 ){
2722 fsdirSetErrmsg(pCur, "table function fsdir requires an argument");
2723 return SQLITE_ERROR;
@@ -2764,12 +2771,13 @@
2771 sqlite3_index_info *pIdxInfo
2772 ){
2773 int i; /* Loop over constraints */
2774 int idx4 = -1;
2775 int idx5 = -1;
 
2776 const struct sqlite3_index_constraint *pConstraint;
2777
2778 (void)tab;
2779 pConstraint = pIdxInfo->aConstraint;
2780 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
2781 if( pConstraint->usable==0 ) continue;
2782 if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
2783 if( pConstraint->iColumn==4 ) idx4 = i;
@@ -2819,10 +2827,13 @@
2827 0, /* xSync */
2828 0, /* xCommit */
2829 0, /* xRollback */
2830 0, /* xFindMethod */
2831 0, /* xRename */
2832 0, /* xSavepoint */
2833 0, /* xRelease */
2834 0 /* xRollbackTo */
2835 };
2836
2837 int rc = sqlite3_create_module(db, "fsdir", &fsdirModule, 0);
2838 return rc;
2839 }
@@ -3931,10 +3942,12 @@
3942 const sqlite3_api_routines *pApi
3943 ){
3944 int rc = SQLITE_OK;
3945 sqlite3_vfs *pOrig;
3946 SQLITE_EXTENSION_INIT2(pApi);
3947 (void)pzErrMsg;
3948 (void)db;
3949 pOrig = sqlite3_vfs_find(0);
3950 apnd_vfs.iVersion = pOrig->iVersion;
3951 apnd_vfs.pAppData = pOrig;
3952 apnd_vfs.szOsFile = pOrig->szOsFile + sizeof(ApndFile);
3953 rc = sqlite3_vfs_register(&apnd_vfs, 0);
@@ -4720,11 +4733,11 @@
4733 rc = SQLITE_NOMEM;
4734 }else{
4735 int res;
4736 z_stream str;
4737 memset(&str, 0, sizeof(str));
4738 str.next_in = (Bytef*)aIn;
4739 str.avail_in = nIn;
4740 str.next_out = aOut;
4741 str.avail_out = nAlloc;
4742
4743 deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
@@ -5286,18 +5299,20 @@
5299 sz = nIn;
5300 pData = aIn;
5301 nData = nIn;
5302 if( iMethod!=0 && iMethod!=8 ){
5303 rc = SQLITE_CONSTRAINT;
5304 }else{
5305 if( bAuto || iMethod ){
5306 int nCmp;
5307 rc = zipfileDeflate(pTab, aIn, nIn, &pFree, &nCmp);
5308 if( rc==SQLITE_OK ){
5309 if( iMethod || nCmp<nIn ){
5310 iMethod = 8;
5311 pData = pFree;
5312 nData = nCmp;
5313 }
5314 }
5315 }
5316 iCrc32 = crc32(0, aIn, nIn);
5317 }
5318 }
@@ -6417,19 +6432,24 @@
6432 sqlite3_vtab *pVtab,
6433 int nData,
6434 sqlite3_value **azData,
6435 sqlite_int64 *pRowid
6436 ){
6437 (void)pVtab;
6438 (void)nData;
6439 (void)azData;
6440 (void)pRowid;
6441 return SQLITE_OK;
6442 }
6443
6444 /*
6445 ** Virtual table module xOpen method.
6446 */
6447 static int expertOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
6448 int rc = SQLITE_OK;
6449 ExpertCsr *pCsr;
6450 (void)pVTab;
6451 pCsr = idxMalloc(&rc, sizeof(ExpertCsr));
6452 *ppCursor = (sqlite3_vtab_cursor*)pCsr;
6453 return rc;
6454 }
6455
@@ -6475,10 +6495,11 @@
6495
6496 /*
6497 ** Virtual table module xRowid method.
6498 */
6499 static int expertRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
6500 (void)cur;
6501 *pRowid = 0;
6502 return SQLITE_OK;
6503 }
6504
6505 /*
@@ -6505,10 +6526,14 @@
6526 ExpertCsr *pCsr = (ExpertCsr*)cur;
6527 ExpertVtab *pVtab = (ExpertVtab*)(cur->pVtab);
6528 sqlite3expert *pExpert = pVtab->pExpert;
6529 int rc;
6530
6531 (void)idxNum;
6532 (void)idxStr;
6533 (void)argc;
6534 (void)argv;
6535 rc = sqlite3_finalize(pCsr->pData);
6536 pCsr->pData = 0;
6537 if( rc==SQLITE_OK ){
6538 rc = idxPrintfPrepareStmt(pExpert->db, &pCsr->pData, &pVtab->base.zErrMsg,
6539 "SELECT * FROM main.%Q WHERE sample()", pVtab->pTab->zName
@@ -6915,11 +6940,11 @@
6940
6941 /*
6942 ** Create candidate indexes in database [dbm] based on the data in
6943 ** linked-list pScan.
6944 */
6945 static int idxCreateCandidates(sqlite3expert *p){
6946 int rc = SQLITE_OK;
6947 IdxScan *pIter;
6948
6949 for(pIter=p->pScan; pIter && rc==SQLITE_OK; pIter=pIter->pNextScan){
6950 rc = idxCreateFromWhere(p, pIter, 0);
@@ -7078,10 +7103,12 @@
7103 const char *z4,
7104 const char *zDb,
7105 const char *zTrigger
7106 ){
7107 int rc = SQLITE_OK;
7108 (void)z4;
7109 (void)zTrigger;
7110 if( eOp==SQLITE_INSERT || eOp==SQLITE_UPDATE || eOp==SQLITE_DELETE ){
7111 if( sqlite3_stricmp(zDb, "main")==0 ){
7112 sqlite3expert *p = (sqlite3expert*)pCtx;
7113 IdxTable *pTab;
7114 for(pTab=p->pTable; pTab; pTab=pTab->pNext){
@@ -7280,10 +7307,11 @@
7307 sqlite3_value **argv
7308 ){
7309 struct IdxSampleCtx *p = (struct IdxSampleCtx*)sqlite3_user_data(pCtx);
7310 int bRet;
7311
7312 (void)argv;
7313 assert( argc==0 );
7314 if( p->nRow==0.0 ){
7315 bRet = 1;
7316 }else{
7317 bRet = (p->nRet / p->nRow) <= p->target;
@@ -7765,11 +7793,11 @@
7793 /* Do trigger processing to collect any extra IdxScan structures */
7794 rc = idxProcessTriggers(p, pzErr);
7795
7796 /* Create candidate indexes within the in-memory database file */
7797 if( rc==SQLITE_OK ){
7798 rc = idxCreateCandidates(p);
7799 }
7800
7801 /* Generate the stat1 data */
7802 if( rc==SQLITE_OK ){
7803 rc = idxPopulateStat1(p, pzErr);
@@ -8033,10 +8061,11 @@
8061 sqlite3_context *pCtx,
8062 int nVal,
8063 sqlite3_value **apVal
8064 ){
8065 ShellState *p = (ShellState*)sqlite3_user_data(pCtx);
8066 (void)nVal;
8067 utf8_printf(p->out, "%s\n", sqlite3_value_text(apVal[0]));
8068 sqlite3_result_value(pCtx, apVal[0]);
8069 }
8070
8071 /*
@@ -14418,10 +14447,24 @@
14447 #endif /* SQLITE_USER_AUTHENTICATION */
14448
14449 if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
14450 utf8_printf(p->out, "SQLite %s %s\n" /*extra-version-info*/,
14451 sqlite3_libversion(), sqlite3_sourceid());
14452 #if SQLITE_HAVE_ZLIB
14453 utf8_printf(p->out, "zlib version %s\n", zlibVersion());
14454 #endif
14455 #define CTIMEOPT_VAL_(opt) #opt
14456 #define CTIMEOPT_VAL(opt) CTIMEOPT_VAL_(opt)
14457 #if defined(__clang__) && defined(__clang_major__)
14458 utf8_printf(p->out, "clang-" CTIMEOPT_VAL(__clang_major__) "."
14459 CTIMEOPT_VAL(__clang_minor__) "."
14460 CTIMEOPT_VAL(__clang_patchlevel__) "\n");
14461 #elif defined(_MSC_VER)
14462 utf8_printf(p->out, "msvc-" CTIMEOPT_VAL(_MSC_VER) "\n");
14463 #elif defined(__GNUC__) && defined(__VERSION__)
14464 utf8_printf(p->out, "gcc-" __VERSION__ "\n");
14465 #endif
14466 }else
14467
14468 if( c=='v' && strncmp(azArg[0], "vfsinfo", n)==0 ){
14469 const char *zDbName = nArg==2 ? azArg[1] : "main";
14470 sqlite3_vfs *pVfs = 0;
14471
+285 -73
--- 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.22.0"
11511151
#define SQLITE_VERSION_NUMBER 3022000
1152
-#define SQLITE_SOURCE_ID "2018-01-16 13:37:43 feb2c2b6f66b0f45490beb1642d99cdb89fa220e299a8c118929df557c814189"
1152
+#define SQLITE_SOURCE_ID "2018-01-20 15:48:45 136bf323e42dc90e1780199a381bcbb084b069eca5c7343ee6fc6e2550831536"
11531153
11541154
/*
11551155
** CAPI3REF: Run-Time Library Version Numbers
11561156
** KEYWORDS: sqlite3_version sqlite3_sourceid
11571157
**
@@ -1532,11 +1532,10 @@
15321532
#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
15331533
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
15341534
#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
15351535
#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
15361536
#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
1537
-#define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8))
15381537
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
15391538
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
15401539
#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
15411540
#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
15421541
#define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
@@ -3974,12 +3973,12 @@
39743973
/*
39753974
** CAPI3REF: SQL Trace Event Codes
39763975
** KEYWORDS: SQLITE_TRACE
39773976
**
39783977
** These constants identify classes of events that can be monitored
3979
-** using the [sqlite3_trace_v2()] tracing logic. The third argument
3980
-** to [sqlite3_trace_v2()] is an OR-ed combination of one or more of
3978
+** using the [sqlite3_trace_v2()] tracing logic. The M argument
3979
+** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of
39813980
** the following constants. ^The first argument to the trace callback
39823981
** is one of the following constants.
39833982
**
39843983
** New tracing constants may be added in future releases.
39853984
**
@@ -10097,10 +10096,39 @@
1009710096
** Changes are not recorded for individual rows that have NULL values stored
1009810097
** in one or more of their PRIMARY KEY columns.
1009910098
**
1010010099
** SQLITE_OK is returned if the call completes without error. Or, if an error
1010110100
** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
10101
+**
10102
+** <h3>Special sqlite_stat1 Handling</h3>
10103
+**
10104
+** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to
10105
+** some of the rules above. In SQLite, the schema of sqlite_stat1 is:
10106
+** <pre>
10107
+** &nbsp; CREATE TABLE sqlite_stat1(tbl,idx,stat)
10108
+** </pre>
10109
+**
10110
+** Even though sqlite_stat1 does not have a PRIMARY KEY, changes are
10111
+** recorded for it as if the PRIMARY KEY is (tbl,idx). Additionally, changes
10112
+** are recorded for rows for which (idx IS NULL) is true. However, for such
10113
+** rows a zero-length blob (SQL value X'') is stored in the changeset or
10114
+** patchset instead of a NULL value. This allows such changesets to be
10115
+** manipulated by legacy implementations of sqlite3changeset_invert(),
10116
+** concat() and similar.
10117
+**
10118
+** The sqlite3changeset_apply() function automatically converts the
10119
+** zero-length blob back to a NULL value when updating the sqlite_stat1
10120
+** table. However, if the application calls sqlite3changeset_new(),
10121
+** sqlite3changeset_old() or sqlite3changeset_conflict on a changeset
10122
+** iterator directly (including on a changeset iterator passed to a
10123
+** conflict-handler callback) then the X'' value is returned. The application
10124
+** must translate X'' to NULL itself if required.
10125
+**
10126
+** Legacy (older than 3.22.0) versions of the sessions module cannot capture
10127
+** changes made to the sqlite_stat1 table. Legacy versions of the
10128
+** sqlite3changeset_apply() function silently ignore any modifications to the
10129
+** sqlite_stat1 table that are part of a changeset or patchset.
1010210130
*/
1010310131
SQLITE_API int sqlite3session_attach(
1010410132
sqlite3_session *pSession, /* Session object */
1010510133
const char *zTab /* Table name */
1010610134
);
@@ -18923,11 +18951,10 @@
1892318951
Vdbe *pVdbe; /* The VM that owns this context */
1892418952
int iOp; /* Instruction number of OP_Function */
1892518953
int isError; /* Error code returned by the function. */
1892618954
u8 skipFlag; /* Skip accumulator loading if true */
1892718955
u8 fErrorOrAux; /* isError!=0 or pVdbe->pAuxData modified */
18928
- u8 bVtabNoChng; /* Fetching an unchanging column in a vtab UPDATE */
1892918956
u8 argc; /* Number of arguments */
1893018957
sqlite3_value *argv[1]; /* Argument set */
1893118958
};
1893218959
1893318960
/* A bitfield type for use inside of structures. Always follow with :N where
@@ -28766,19 +28793,40 @@
2876628793
** E==2 results in 100. E==50 results in 1.0e50.
2876728794
**
2876828795
** This routine only works for values of E between 1 and 341.
2876928796
*/
2877028797
static LONGDOUBLE_TYPE sqlite3Pow10(int E){
28798
+#if defined(_MSC_VER)
28799
+ static const LONGDOUBLE_TYPE x[] = {
28800
+ 1.0e+001,
28801
+ 1.0e+002,
28802
+ 1.0e+004,
28803
+ 1.0e+008,
28804
+ 1.0e+016,
28805
+ 1.0e+032,
28806
+ 1.0e+064,
28807
+ 1.0e+128,
28808
+ 1.0e+256
28809
+ };
28810
+ LONGDOUBLE_TYPE r = 1.0;
28811
+ int i;
28812
+ assert( E>=0 && E<=307 );
28813
+ for(i=0; E!=0; i++, E >>=1){
28814
+ if( E & 1 ) r *= x[i];
28815
+ }
28816
+ return r;
28817
+#else
2877128818
LONGDOUBLE_TYPE x = 10.0;
2877228819
LONGDOUBLE_TYPE r = 1.0;
2877328820
while(1){
2877428821
if( E & 1 ) r *= x;
2877528822
E >>= 1;
2877628823
if( E==0 ) break;
2877728824
x *= x;
2877828825
}
2877928826
return r;
28827
+#endif
2878028828
}
2878128829
2878228830
/*
2878328831
** The string z[] is an text representation of a real number.
2878428832
** Convert this string to a double and write it into *pResult.
@@ -42498,11 +42546,10 @@
4249842546
*/
4249942547
static int winOpenSharedMemory(winFile *pDbFd){
4250042548
struct winShm *p; /* The connection to be opened */
4250142549
winShmNode *pShmNode = 0; /* The underlying mmapped file */
4250242550
int rc = SQLITE_OK; /* Result code */
42503
- int rc2 = SQLITE_ERROR; /* winOpen result code */
4250442551
winShmNode *pNew; /* Newly allocated winShmNode */
4250542552
int nName; /* Size of zName in bytes */
4250642553
4250742554
assert( pDbFd->pShm==0 ); /* Not previously opened */
4250842555
@@ -42532,10 +42579,13 @@
4253242579
if( sqlite3StrICmp(pShmNode->zFilename, pNew->zFilename)==0 ) break;
4253342580
}
4253442581
if( pShmNode ){
4253542582
sqlite3_free(pNew);
4253642583
}else{
42584
+ int inFlags = SQLITE_OPEN_WAL;
42585
+ int outFlags = 0;
42586
+
4253742587
pShmNode = pNew;
4253842588
pNew = 0;
4253942589
((winFile*)(&pShmNode->hFile))->h = INVALID_HANDLE_VALUE;
4254042590
pShmNode->pNext = winShmNodeList;
4254142591
winShmNodeList = pShmNode;
@@ -42547,29 +42597,23 @@
4254742597
goto shm_open_err;
4254842598
}
4254942599
}
4255042600
4255142601
if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
42552
- rc2 = winOpen(pDbFd->pVfs,
42553
- pShmNode->zFilename,
42554
- (sqlite3_file*)&pShmNode->hFile,
42555
- SQLITE_OPEN_WAL|SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE,
42556
- 0);
42557
- }
42558
- if( rc2!=SQLITE_OK ){
42559
- rc2 = winOpen(pDbFd->pVfs,
42560
- pShmNode->zFilename,
42561
- (sqlite3_file*)&pShmNode->hFile,
42562
- SQLITE_OPEN_WAL|SQLITE_OPEN_READONLY,
42563
- 0);
42564
- if( rc2!=SQLITE_OK ){
42565
- rc = winLogError(rc2, osGetLastError(), "winOpenShm",
42566
- pShmNode->zFilename);
42567
- goto shm_open_err;
42568
- }
42569
- pShmNode->isReadonly = 1;
42570
- }
42602
+ inFlags |= SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
42603
+ }else{
42604
+ inFlags |= SQLITE_OPEN_READONLY;
42605
+ }
42606
+ rc = winOpen(pDbFd->pVfs, pShmNode->zFilename,
42607
+ (sqlite3_file*)&pShmNode->hFile,
42608
+ inFlags, &outFlags);
42609
+ if( rc!=SQLITE_OK ){
42610
+ rc = winLogError(rc, osGetLastError(), "winOpenShm",
42611
+ pShmNode->zFilename);
42612
+ goto shm_open_err;
42613
+ }
42614
+ if( outFlags==SQLITE_OPEN_READONLY ) pShmNode->isReadonly = 1;
4257142615
4257242616
rc = winLockSharedMemory(pShmNode);
4257342617
if( rc!=SQLITE_OK && rc!=SQLITE_READONLY_CANTINIT ) goto shm_open_err;
4257442618
}
4257542619
@@ -43751,12 +43795,14 @@
4375143795
dwShareMode,
4375243796
dwCreationDisposition,
4375343797
&extendedParameters);
4375443798
if( h!=INVALID_HANDLE_VALUE ) break;
4375543799
if( isReadWrite ){
43756
- int isRO = 0;
43757
- int rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO);
43800
+ int rc2, isRO = 0;
43801
+ sqlite3BeginBenignMalloc();
43802
+ rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO);
43803
+ sqlite3EndBenignMalloc();
4375843804
if( rc2==SQLITE_OK && isRO ) break;
4375943805
}
4376043806
}while( winRetryIoerr(&cnt, &lastErrno) );
4376143807
#else
4376243808
do{
@@ -43766,12 +43812,14 @@
4376643812
dwCreationDisposition,
4376743813
dwFlagsAndAttributes,
4376843814
NULL);
4376943815
if( h!=INVALID_HANDLE_VALUE ) break;
4377043816
if( isReadWrite ){
43771
- int isRO = 0;
43772
- int rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO);
43817
+ int rc2, isRO = 0;
43818
+ sqlite3BeginBenignMalloc();
43819
+ rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO);
43820
+ sqlite3EndBenignMalloc();
4377343821
if( rc2==SQLITE_OK && isRO ) break;
4377443822
}
4377543823
}while( winRetryIoerr(&cnt, &lastErrno) );
4377643824
#endif
4377743825
}
@@ -43784,12 +43832,14 @@
4378443832
dwCreationDisposition,
4378543833
dwFlagsAndAttributes,
4378643834
NULL);
4378743835
if( h!=INVALID_HANDLE_VALUE ) break;
4378843836
if( isReadWrite ){
43789
- int isRO = 0;
43790
- int rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO);
43837
+ int rc2, isRO = 0;
43838
+ sqlite3BeginBenignMalloc();
43839
+ rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO);
43840
+ sqlite3EndBenignMalloc();
4379143841
if( rc2==SQLITE_OK && isRO ) break;
4379243842
}
4379343843
}while( winRetryIoerr(&cnt, &lastErrno) );
4379443844
}
4379543845
#endif
@@ -93290,19 +93340,19 @@
9329093340
for(i=0; i<p->nExpr; i++){
9329193341
heightOfExpr(p->a[i].pExpr, pnHeight);
9329293342
}
9329393343
}
9329493344
}
93295
-static void heightOfSelect(Select *p, int *pnHeight){
93296
- if( p ){
93345
+static void heightOfSelect(Select *pSelect, int *pnHeight){
93346
+ Select *p;
93347
+ for(p=pSelect; p; p=p->pPrior){
9329793348
heightOfExpr(p->pWhere, pnHeight);
9329893349
heightOfExpr(p->pHaving, pnHeight);
9329993350
heightOfExpr(p->pLimit, pnHeight);
9330093351
heightOfExprList(p->pEList, pnHeight);
9330193352
heightOfExprList(p->pGroupBy, pnHeight);
9330293353
heightOfExprList(p->pOrderBy, pnHeight);
93303
- heightOfSelect(p->pPrior, pnHeight);
9330493354
}
9330593355
}
9330693356
9330793357
/*
9330893358
** Set the Expr.nHeight variable in the structure passed as an
@@ -100084,10 +100134,13 @@
100084100134
assert( "BBB"[0]==SQLITE_AFF_TEXT );
100085100135
sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
100086100136
sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
100087100137
sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
100088100138
sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
100139
+#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
100140
+ sqlite3VdbeChangeP4(v, -1, (char*)pStat1, P4_TABLE);
100141
+#endif
100089100142
sqlite3VdbeJumpHere(v, jZeroRows);
100090100143
}
100091100144
}
100092100145
100093100146
@@ -113501,10 +113554,11 @@
113501113554
int (*bind_pointer)(sqlite3_stmt*,int,void*,const char*,void(*)(void*));
113502113555
void (*result_pointer)(sqlite3_context*,void*,const char*,void(*)(void*));
113503113556
void *(*value_pointer)(sqlite3_value*,const char*);
113504113557
int (*vtab_nochange)(sqlite3_context*);
113505113558
int (*value_nochange)(sqlite3_value*);
113559
+ const char *(*vtab_collation)(sqlite3_index_info*,int);
113506113560
};
113507113561
113508113562
/*
113509113563
** This is the function signature used for all extension entry points. It
113510113564
** is also defined in the file "loadext.c".
@@ -113770,10 +113824,11 @@
113770113824
#define sqlite3_result_pointer sqlite3_api->result_pointer
113771113825
#define sqlite3_value_pointer sqlite3_api->value_pointer
113772113826
/* Version 3.22.0 and later */
113773113827
#define sqlite3_vtab_nochange sqlite3_api->vtab_nochange
113774113828
#define sqlite3_value_nochange sqltie3_api->value_nochange
113829
+#define sqlite3_vtab_collation sqltie3_api->vtab_collation
113775113830
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
113776113831
113777113832
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
113778113833
/* This case when the file really is being compiled as a loadable
113779113834
** extension */
@@ -114207,11 +114262,12 @@
114207114262
sqlite3_bind_pointer,
114208114263
sqlite3_result_pointer,
114209114264
sqlite3_value_pointer,
114210114265
/* Version 3.22.0 and later */
114211114266
sqlite3_vtab_nochange,
114212
- sqlite3_value_nochange
114267
+ sqlite3_value_nochange,
114268
+ sqlite3_vtab_collation
114213114269
};
114214114270
114215114271
/*
114216114272
** Attempt to load an SQLite extension library contained in the file
114217114273
** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -140461,10 +140517,12 @@
140461140517
int yygoto; /* The next state */
140462140518
int yyact; /* The next action */
140463140519
yyStackEntry *yymsp; /* The top of the parser's stack */
140464140520
int yysize; /* Amount to pop the stack */
140465140521
sqlite3ParserARG_FETCH;
140522
+ (void)yyLookahead;
140523
+ (void)yyLookaheadToken;
140466140524
yymsp = yypParser->yytos;
140467140525
#ifndef NDEBUG
140468140526
if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
140469140527
yysize = yyRuleInfo[yyruleno].nrhs;
140470140528
if( yysize ){
@@ -143275,10 +143333,14 @@
143275143333
**
143276143334
** This header file is used by programs that want to link against the
143277143335
** RTREE library. All it does is declare the sqlite3RtreeInit() interface.
143278143336
*/
143279143337
/* #include "sqlite3.h" */
143338
+
143339
+#ifdef SQLITE_OMIT_VIRTUALTABLE
143340
+# undef SQLITE_ENABLE_RTREE
143341
+#endif
143280143342
143281143343
#if 0
143282143344
extern "C" {
143283143345
#endif /* __cplusplus */
143284143346
@@ -167030,11 +167092,12 @@
167030167092
** of 4-byte coordinates. For leaf nodes the integer is the rowid
167031167093
** of a record. For internal nodes it is the node number of a
167032167094
** child page.
167033167095
*/
167034167096
167035
-#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RTREE)
167097
+#if !defined(SQLITE_CORE) \
167098
+ || (defined(SQLITE_ENABLE_RTREE) && !defined(SQLITE_OMIT_VIRTUALTABLE))
167036167099
167037167100
#ifndef SQLITE_CORE
167038167101
/* #include "sqlite3ext.h" */
167039167102
SQLITE_EXTENSION_INIT1
167040167103
#else
@@ -178688,10 +178751,11 @@
178688178751
int bIndirect; /* True if all changes are indirect */
178689178752
int bAutoAttach; /* True to auto-attach tables */
178690178753
int rc; /* Non-zero if an error has occurred */
178691178754
void *pFilterCtx; /* First argument to pass to xTableFilter */
178692178755
int (*xTableFilter)(void *pCtx, const char *zTab);
178756
+ sqlite3_value *pZeroBlob; /* Value containing X'' */
178693178757
sqlite3_session *pNext; /* Next session object on same db. */
178694178758
SessionTable *pTable; /* List of attached tables */
178695178759
SessionHook hook; /* APIs to grab new and old data with */
178696178760
};
178697178761
@@ -178755,10 +178819,11 @@
178755178819
*/
178756178820
struct SessionTable {
178757178821
SessionTable *pNext;
178758178822
char *zName; /* Local name of table */
178759178823
int nCol; /* Number of columns in table zName */
178824
+ int bStat1; /* True if this is sqlite_stat1 */
178760178825
const char **azCol; /* Column names */
178761178826
u8 *abPK; /* Array of primary key flags */
178762178827
int nEntry; /* Total number of entries in hash table */
178763178828
int nChange; /* Size of apChange[] array */
178764178829
SessionChange **apChange; /* Hash table buckets */
@@ -179138,10 +179203,11 @@
179138179203
n = sqlite3_value_bytes(pVal);
179139179204
if( !z && (eType!=SQLITE_BLOB || n>0) ) return SQLITE_NOMEM;
179140179205
h = sessionHashAppendBlob(h, n, z);
179141179206
}else{
179142179207
assert( eType==SQLITE_NULL );
179208
+ assert( pTab->bStat1==0 || i!=1 );
179143179209
*pbNullPK = 1;
179144179210
}
179145179211
}
179146179212
}
179147179213
@@ -179480,11 +179546,10 @@
179480179546
}else{
179481179547
z = sqlite3_value_blob(pVal);
179482179548
}
179483179549
if( memcmp(a, z, n) ) return 0;
179484179550
a += n;
179485
- break;
179486179551
}
179487179552
}
179488179553
}
179489179554
179490179555
return 1;
@@ -179690,14 +179755,58 @@
179690179755
if( abPK[i] ){
179691179756
pTab->abPK = abPK;
179692179757
break;
179693179758
}
179694179759
}
179760
+ if( 0==sqlite3_stricmp("sqlite_stat1", pTab->zName) ){
179761
+ pTab->bStat1 = 1;
179762
+ }
179695179763
}
179696179764
}
179697179765
return (pSession->rc || pTab->abPK==0);
179698179766
}
179767
+
179768
+/*
179769
+** Versions of the four methods in object SessionHook for use with the
179770
+** sqlite_stat1 table. The purpose of this is to substitute a zero-length
179771
+** blob each time a NULL value is read from the "idx" column of the
179772
+** sqlite_stat1 table.
179773
+*/
179774
+typedef struct SessionStat1Ctx SessionStat1Ctx;
179775
+struct SessionStat1Ctx {
179776
+ SessionHook hook;
179777
+ sqlite3_session *pSession;
179778
+};
179779
+static int sessionStat1Old(void *pCtx, int iCol, sqlite3_value **ppVal){
179780
+ SessionStat1Ctx *p = (SessionStat1Ctx*)pCtx;
179781
+ sqlite3_value *pVal = 0;
179782
+ int rc = p->hook.xOld(p->hook.pCtx, iCol, &pVal);
179783
+ if( rc==SQLITE_OK && iCol==1 && sqlite3_value_type(pVal)==SQLITE_NULL ){
179784
+ pVal = p->pSession->pZeroBlob;
179785
+ }
179786
+ *ppVal = pVal;
179787
+ return rc;
179788
+}
179789
+static int sessionStat1New(void *pCtx, int iCol, sqlite3_value **ppVal){
179790
+ SessionStat1Ctx *p = (SessionStat1Ctx*)pCtx;
179791
+ sqlite3_value *pVal = 0;
179792
+ int rc = p->hook.xNew(p->hook.pCtx, iCol, &pVal);
179793
+ if( rc==SQLITE_OK && iCol==1 && sqlite3_value_type(pVal)==SQLITE_NULL ){
179794
+ pVal = p->pSession->pZeroBlob;
179795
+ }
179796
+ *ppVal = pVal;
179797
+ return rc;
179798
+}
179799
+static int sessionStat1Count(void *pCtx){
179800
+ SessionStat1Ctx *p = (SessionStat1Ctx*)pCtx;
179801
+ return p->hook.xCount(p->hook.pCtx);
179802
+}
179803
+static int sessionStat1Depth(void *pCtx){
179804
+ SessionStat1Ctx *p = (SessionStat1Ctx*)pCtx;
179805
+ return p->hook.xDepth(p->hook.pCtx);
179806
+}
179807
+
179699179808
179700179809
/*
179701179810
** This function is only called from with a pre-update-hook reporting a
179702179811
** change on table pTab (attached to session pSession). The type of change
179703179812
** (UPDATE, INSERT, DELETE) is specified by the first argument.
@@ -179711,10 +179820,11 @@
179711179820
SessionTable *pTab /* Table that change applies to */
179712179821
){
179713179822
int iHash;
179714179823
int bNull = 0;
179715179824
int rc = SQLITE_OK;
179825
+ SessionStat1Ctx stat1;
179716179826
179717179827
if( pSession->rc ) return;
179718179828
179719179829
/* Load table details if required */
179720179830
if( sessionInitTable(pSession, pTab) ) return;
@@ -179729,10 +179839,29 @@
179729179839
/* Grow the hash table if required */
179730179840
if( sessionGrowHash(0, pTab) ){
179731179841
pSession->rc = SQLITE_NOMEM;
179732179842
return;
179733179843
}
179844
+
179845
+ if( pTab->bStat1 ){
179846
+ stat1.hook = pSession->hook;
179847
+ stat1.pSession = pSession;
179848
+ pSession->hook.pCtx = (void*)&stat1;
179849
+ pSession->hook.xNew = sessionStat1New;
179850
+ pSession->hook.xOld = sessionStat1Old;
179851
+ pSession->hook.xCount = sessionStat1Count;
179852
+ pSession->hook.xDepth = sessionStat1Depth;
179853
+ if( pSession->pZeroBlob==0 ){
179854
+ sqlite3_value *p = sqlite3ValueNew(0);
179855
+ if( p==0 ){
179856
+ rc = SQLITE_NOMEM;
179857
+ goto error_out;
179858
+ }
179859
+ sqlite3ValueSetStr(p, 0, "", 0, SQLITE_STATIC);
179860
+ pSession->pZeroBlob = p;
179861
+ }
179862
+ }
179734179863
179735179864
/* Calculate the hash-key for this change. If the primary key of the row
179736179865
** includes a NULL value, exit early. Such changes are ignored by the
179737179866
** session module. */
179738179867
rc = sessionPreupdateHash(pSession, pTab, op==SQLITE_INSERT, &iHash, &bNull);
@@ -179819,10 +179948,13 @@
179819179948
}
179820179949
}
179821179950
179822179951
/* If an error has occurred, mark the session object as failed. */
179823179952
error_out:
179953
+ if( pTab->bStat1 ){
179954
+ pSession->hook = stat1.hook;
179955
+ }
179824179956
if( rc!=SQLITE_OK ){
179825179957
pSession->rc = rc;
179826179958
}
179827179959
}
179828179960
@@ -180280,10 +180412,11 @@
180280180412
if( pHead ) sqlite3_preupdate_hook(db, xPreUpdate, (void*)pHead);
180281180413
break;
180282180414
}
180283180415
}
180284180416
sqlite3_mutex_leave(sqlite3_db_mutex(db));
180417
+ sqlite3ValueFree(pSession->pZeroBlob);
180285180418
180286180419
/* Delete all attached table objects. And the contents of their
180287180420
** associated hash-tables. */
180288180421
sessionDeleteTable(pSession->pTable);
180289180422
@@ -180747,32 +180880,45 @@
180747180880
const char **azCol, /* Names of table columns */
180748180881
u8 *abPK, /* PRIMARY KEY array */
180749180882
sqlite3_stmt **ppStmt /* OUT: Prepared SELECT statement */
180750180883
){
180751180884
int rc = SQLITE_OK;
180752
- int i;
180753
- const char *zSep = "";
180754
- SessionBuffer buf = {0, 0, 0};
180755
-
180756
- sessionAppendStr(&buf, "SELECT * FROM ", &rc);
180757
- sessionAppendIdent(&buf, zDb, &rc);
180758
- sessionAppendStr(&buf, ".", &rc);
180759
- sessionAppendIdent(&buf, zTab, &rc);
180760
- sessionAppendStr(&buf, " WHERE ", &rc);
180761
- for(i=0; i<nCol; i++){
180762
- if( abPK[i] ){
180763
- sessionAppendStr(&buf, zSep, &rc);
180764
- sessionAppendIdent(&buf, azCol[i], &rc);
180765
- sessionAppendStr(&buf, " = ?", &rc);
180766
- sessionAppendInteger(&buf, i+1, &rc);
180767
- zSep = " AND ";
180768
- }
180769
- }
180770
- if( rc==SQLITE_OK ){
180771
- rc = sqlite3_prepare_v2(db, (char *)buf.aBuf, buf.nBuf, ppStmt, 0);
180772
- }
180773
- sqlite3_free(buf.aBuf);
180885
+ char *zSql = 0;
180886
+ int nSql = -1;
180887
+
180888
+ if( 0==sqlite3_stricmp("sqlite_stat1", zTab) ){
180889
+ zSql = sqlite3_mprintf(
180890
+ "SELECT tbl, ?2, stat FROM %Q.sqlite_stat1 WHERE tbl IS ?1 AND "
180891
+ "idx IS (CASE WHEN ?2=X'' THEN NULL ELSE ?2 END)", zDb
180892
+ );
180893
+ }else{
180894
+ int i;
180895
+ const char *zSep = "";
180896
+ SessionBuffer buf = {0, 0, 0};
180897
+
180898
+ sessionAppendStr(&buf, "SELECT * FROM ", &rc);
180899
+ sessionAppendIdent(&buf, zDb, &rc);
180900
+ sessionAppendStr(&buf, ".", &rc);
180901
+ sessionAppendIdent(&buf, zTab, &rc);
180902
+ sessionAppendStr(&buf, " WHERE ", &rc);
180903
+ for(i=0; i<nCol; i++){
180904
+ if( abPK[i] ){
180905
+ sessionAppendStr(&buf, zSep, &rc);
180906
+ sessionAppendIdent(&buf, azCol[i], &rc);
180907
+ sessionAppendStr(&buf, " IS ?", &rc);
180908
+ sessionAppendInteger(&buf, i+1, &rc);
180909
+ zSep = " AND ";
180910
+ }
180911
+ }
180912
+ zSql = (char*)buf.aBuf;
180913
+ nSql = buf.nBuf;
180914
+ }
180915
+
180916
+ if( rc==SQLITE_OK ){
180917
+ rc = sqlite3_prepare_v2(db, zSql, nSql, ppStmt, 0);
180918
+ }
180919
+ sqlite3_free(zSql);
180774180920
return rc;
180775180921
}
180776180922
180777180923
/*
180778180924
** Bind the PRIMARY KEY values from the change passed in argument pChange
@@ -181937,11 +182083,11 @@
181937182083
sqlite3_stmt *pInsert; /* INSERT statement */
181938182084
sqlite3_stmt *pSelect; /* SELECT statement */
181939182085
int nCol; /* Size of azCol[] and abPK[] arrays */
181940182086
const char **azCol; /* Array of column names */
181941182087
u8 *abPK; /* Boolean array - true if column is in PK */
181942
-
182088
+ int bStat1; /* True if table is sqlite_stat1 */
181943182089
int bDeferConstraints; /* True to defer constraints */
181944182090
SessionBuffer constraints; /* Deferred constraints are stored here */
181945182091
};
181946182092
181947182093
/*
@@ -182106,10 +182252,11 @@
182106182252
}
182107182253
sqlite3_free(buf.aBuf);
182108182254
182109182255
return rc;
182110182256
}
182257
+
182111182258
182112182259
/*
182113182260
** Formulate and prepare an SQL statement to query table zTab by primary
182114182261
** key. Assuming the following table structure:
182115182262
**
@@ -182167,10 +182314,51 @@
182167182314
rc = sqlite3_prepare_v2(db, (char *)buf.aBuf, buf.nBuf, &p->pInsert, 0);
182168182315
}
182169182316
sqlite3_free(buf.aBuf);
182170182317
return rc;
182171182318
}
182319
+
182320
+static int sessionPrepare(sqlite3 *db, sqlite3_stmt **pp, const char *zSql){
182321
+ return sqlite3_prepare_v2(db, zSql, -1, pp, 0);
182322
+}
182323
+
182324
+/*
182325
+** Prepare statements for applying changes to the sqlite_stat1 table.
182326
+** These are similar to those created by sessionSelectRow(),
182327
+** sessionInsertRow(), sessionUpdateRow() and sessionDeleteRow() for
182328
+** other tables.
182329
+*/
182330
+static int sessionStat1Sql(sqlite3 *db, SessionApplyCtx *p){
182331
+ int rc = sessionSelectRow(db, "sqlite_stat1", p);
182332
+ if( rc==SQLITE_OK ){
182333
+ rc = sessionPrepare(db, &p->pInsert,
182334
+ "INSERT INTO main.sqlite_stat1 VALUES(?1, "
182335
+ "CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END, "
182336
+ "?3)"
182337
+ );
182338
+ }
182339
+ if( rc==SQLITE_OK ){
182340
+ rc = sessionPrepare(db, &p->pUpdate,
182341
+ "UPDATE main.sqlite_stat1 SET "
182342
+ "tbl = CASE WHEN ?2 THEN ?3 ELSE tbl END, "
182343
+ "idx = CASE WHEN ?5 THEN ?6 ELSE idx END, "
182344
+ "stat = CASE WHEN ?8 THEN ?9 ELSE stat END "
182345
+ "WHERE tbl=?1 AND idx IS "
182346
+ "CASE WHEN length(?4)=0 AND typeof(?4)='blob' THEN NULL ELSE ?4 END "
182347
+ "AND (?10 OR ?8=0 OR stat IS ?7)"
182348
+ );
182349
+ }
182350
+ if( rc==SQLITE_OK ){
182351
+ rc = sessionPrepare(db, &p->pDelete,
182352
+ "DELETE FROM main.sqlite_stat1 WHERE tbl=?1 AND idx IS "
182353
+ "CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END "
182354
+ "AND (?4 OR stat IS ?3)"
182355
+ );
182356
+ }
182357
+ assert( rc==SQLITE_OK );
182358
+ return rc;
182359
+}
182172182360
182173182361
/*
182174182362
** A wrapper around sqlite3_bind_value() that detects an extra problem.
182175182363
** See comments in the body of this function for details.
182176182364
*/
@@ -182498,15 +182686,29 @@
182498182686
);
182499182687
}
182500182688
182501182689
}else{
182502182690
assert( op==SQLITE_INSERT );
182503
- rc = sessionBindRow(pIter, sqlite3changeset_new, nCol, 0, p->pInsert);
182504
- if( rc!=SQLITE_OK ) return rc;
182691
+ if( p->bStat1 ){
182692
+ /* Check if there is a conflicting row. For sqlite_stat1, this needs
182693
+ ** to be done using a SELECT, as there is no PRIMARY KEY in the
182694
+ ** database schema to throw an exception if a duplicate is inserted. */
182695
+ rc = sessionSeekToRow(p->db, pIter, p->abPK, p->pSelect);
182696
+ if( rc==SQLITE_ROW ){
182697
+ rc = SQLITE_CONSTRAINT;
182698
+ sqlite3_reset(p->pSelect);
182699
+ }
182700
+ }
182505182701
182506
- sqlite3_step(p->pInsert);
182507
- rc = sqlite3_reset(p->pInsert);
182702
+ if( rc==SQLITE_OK ){
182703
+ rc = sessionBindRow(pIter, sqlite3changeset_new, nCol, 0, p->pInsert);
182704
+ if( rc!=SQLITE_OK ) return rc;
182705
+
182706
+ sqlite3_step(p->pInsert);
182707
+ rc = sqlite3_reset(p->pInsert);
182708
+ }
182709
+
182508182710
if( (rc&0xff)==SQLITE_CONSTRAINT ){
182509182711
rc = sessionConflictHandler(
182510182712
SQLITE_CHANGESET_CONFLICT, p, pIter, xConflict, pCtx, pbReplace
182511182713
);
182512182714
}
@@ -182735,16 +182937,24 @@
182735182937
"primary key mismatch for table %s", zTab
182736182938
);
182737182939
}
182738182940
else{
182739182941
sApply.nCol = nCol;
182740
- if((rc = sessionSelectRow(db, zTab, &sApply))
182741
- || (rc = sessionUpdateRow(db, zTab, &sApply))
182742
- || (rc = sessionDeleteRow(db, zTab, &sApply))
182743
- || (rc = sessionInsertRow(db, zTab, &sApply))
182744
- ){
182745
- break;
182942
+ if( 0==sqlite3_stricmp(zTab, "sqlite_stat1") ){
182943
+ if( (rc = sessionStat1Sql(db, &sApply) ) ){
182944
+ break;
182945
+ }
182946
+ sApply.bStat1 = 1;
182947
+ }else{
182948
+ if((rc = sessionSelectRow(db, zTab, &sApply))
182949
+ || (rc = sessionUpdateRow(db, zTab, &sApply))
182950
+ || (rc = sessionDeleteRow(db, zTab, &sApply))
182951
+ || (rc = sessionInsertRow(db, zTab, &sApply))
182952
+ ){
182953
+ break;
182954
+ }
182955
+ sApply.bStat1 = 0;
182746182956
}
182747182957
}
182748182958
nTab = sqlite3Strlen30(zTab);
182749182959
}
182750182960
}
@@ -188063,10 +188273,12 @@
188063188273
int fts5yygoto; /* The next state */
188064188274
int fts5yyact; /* The next action */
188065188275
fts5yyStackEntry *fts5yymsp; /* The top of the parser's stack */
188066188276
int fts5yysize; /* Amount to pop the stack */
188067188277
sqlite3Fts5ParserARG_FETCH;
188278
+ (void)fts5yyLookahead;
188279
+ (void)fts5yyLookaheadToken;
188068188280
fts5yymsp = fts5yypParser->fts5yytos;
188069188281
#ifndef NDEBUG
188070188282
if( fts5yyTraceFILE && fts5yyruleno<(int)(sizeof(fts5yyRuleName)/sizeof(fts5yyRuleName[0])) ){
188071188283
fts5yysize = fts5yyRuleInfo[fts5yyruleno].nrhs;
188072188284
if( fts5yysize ){
@@ -203116,11 +203328,11 @@
203116203328
int nArg, /* Number of args */
203117203329
sqlite3_value **apUnused /* Function arguments */
203118203330
){
203119203331
assert( nArg==0 );
203120203332
UNUSED_PARAM2(nArg, apUnused);
203121
- sqlite3_result_text(pCtx, "fts5: 2018-01-16 13:37:43 feb2c2b6f66b0f45490beb1642d99cdb89fa220e299a8c118929df557c814189", -1, SQLITE_TRANSIENT);
203333
+ sqlite3_result_text(pCtx, "fts5: 2018-01-20 15:48:45 136bf323e42dc90e1780199a381bcbb084b069eca5c7343ee6fc6e2550831536", -1, SQLITE_TRANSIENT);
203122203334
}
203123203335
203124203336
static int fts5Init(sqlite3 *db){
203125203337
static const sqlite3_module fts5Mod = {
203126203338
/* iVersion */ 2,
@@ -207384,12 +207596,12 @@
207384207596
}
207385207597
#endif /* SQLITE_CORE */
207386207598
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
207387207599
207388207600
/************** End of stmt.c ************************************************/
207389
-#if __LINE__!=207389
207601
+#if __LINE__!=207601
207390207602
#undef SQLITE_SOURCE_ID
207391
-#define SQLITE_SOURCE_ID "2018-01-16 13:37:43 feb2c2b6f66b0f45490beb1642d99cdb89fa220e299a8c118929df557c81alt2"
207603
+#define SQLITE_SOURCE_ID "2018-01-20 15:48:45 136bf323e42dc90e1780199a381bcbb084b069eca5c7343ee6fc6e255083alt2"
207392207604
#endif
207393207605
/* Return the source-id for this library */
207394207606
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
207395207607
/************************** End of sqlite3.c ******************************/
207396207608
--- 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.22.0"
1151 #define SQLITE_VERSION_NUMBER 3022000
1152 #define SQLITE_SOURCE_ID "2018-01-16 13:37:43 feb2c2b6f66b0f45490beb1642d99cdb89fa220e299a8c118929df557c814189"
1153
1154 /*
1155 ** CAPI3REF: Run-Time Library Version Numbers
1156 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1157 **
@@ -1532,11 +1532,10 @@
1532 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
1533 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
1534 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
1535 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
1536 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
1537 #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8))
1538 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
1539 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
1540 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
1541 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
1542 #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
@@ -3974,12 +3973,12 @@
3974 /*
3975 ** CAPI3REF: SQL Trace Event Codes
3976 ** KEYWORDS: SQLITE_TRACE
3977 **
3978 ** These constants identify classes of events that can be monitored
3979 ** using the [sqlite3_trace_v2()] tracing logic. The third argument
3980 ** to [sqlite3_trace_v2()] is an OR-ed combination of one or more of
3981 ** the following constants. ^The first argument to the trace callback
3982 ** is one of the following constants.
3983 **
3984 ** New tracing constants may be added in future releases.
3985 **
@@ -10097,10 +10096,39 @@
10097 ** Changes are not recorded for individual rows that have NULL values stored
10098 ** in one or more of their PRIMARY KEY columns.
10099 **
10100 ** SQLITE_OK is returned if the call completes without error. Or, if an error
10101 ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10102 */
10103 SQLITE_API int sqlite3session_attach(
10104 sqlite3_session *pSession, /* Session object */
10105 const char *zTab /* Table name */
10106 );
@@ -18923,11 +18951,10 @@
18923 Vdbe *pVdbe; /* The VM that owns this context */
18924 int iOp; /* Instruction number of OP_Function */
18925 int isError; /* Error code returned by the function. */
18926 u8 skipFlag; /* Skip accumulator loading if true */
18927 u8 fErrorOrAux; /* isError!=0 or pVdbe->pAuxData modified */
18928 u8 bVtabNoChng; /* Fetching an unchanging column in a vtab UPDATE */
18929 u8 argc; /* Number of arguments */
18930 sqlite3_value *argv[1]; /* Argument set */
18931 };
18932
18933 /* A bitfield type for use inside of structures. Always follow with :N where
@@ -28766,19 +28793,40 @@
28766 ** E==2 results in 100. E==50 results in 1.0e50.
28767 **
28768 ** This routine only works for values of E between 1 and 341.
28769 */
28770 static LONGDOUBLE_TYPE sqlite3Pow10(int E){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28771 LONGDOUBLE_TYPE x = 10.0;
28772 LONGDOUBLE_TYPE r = 1.0;
28773 while(1){
28774 if( E & 1 ) r *= x;
28775 E >>= 1;
28776 if( E==0 ) break;
28777 x *= x;
28778 }
28779 return r;
 
28780 }
28781
28782 /*
28783 ** The string z[] is an text representation of a real number.
28784 ** Convert this string to a double and write it into *pResult.
@@ -42498,11 +42546,10 @@
42498 */
42499 static int winOpenSharedMemory(winFile *pDbFd){
42500 struct winShm *p; /* The connection to be opened */
42501 winShmNode *pShmNode = 0; /* The underlying mmapped file */
42502 int rc = SQLITE_OK; /* Result code */
42503 int rc2 = SQLITE_ERROR; /* winOpen result code */
42504 winShmNode *pNew; /* Newly allocated winShmNode */
42505 int nName; /* Size of zName in bytes */
42506
42507 assert( pDbFd->pShm==0 ); /* Not previously opened */
42508
@@ -42532,10 +42579,13 @@
42532 if( sqlite3StrICmp(pShmNode->zFilename, pNew->zFilename)==0 ) break;
42533 }
42534 if( pShmNode ){
42535 sqlite3_free(pNew);
42536 }else{
 
 
 
42537 pShmNode = pNew;
42538 pNew = 0;
42539 ((winFile*)(&pShmNode->hFile))->h = INVALID_HANDLE_VALUE;
42540 pShmNode->pNext = winShmNodeList;
42541 winShmNodeList = pShmNode;
@@ -42547,29 +42597,23 @@
42547 goto shm_open_err;
42548 }
42549 }
42550
42551 if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
42552 rc2 = winOpen(pDbFd->pVfs,
42553 pShmNode->zFilename,
42554 (sqlite3_file*)&pShmNode->hFile,
42555 SQLITE_OPEN_WAL|SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE,
42556 0);
42557 }
42558 if( rc2!=SQLITE_OK ){
42559 rc2 = winOpen(pDbFd->pVfs,
42560 pShmNode->zFilename,
42561 (sqlite3_file*)&pShmNode->hFile,
42562 SQLITE_OPEN_WAL|SQLITE_OPEN_READONLY,
42563 0);
42564 if( rc2!=SQLITE_OK ){
42565 rc = winLogError(rc2, osGetLastError(), "winOpenShm",
42566 pShmNode->zFilename);
42567 goto shm_open_err;
42568 }
42569 pShmNode->isReadonly = 1;
42570 }
42571
42572 rc = winLockSharedMemory(pShmNode);
42573 if( rc!=SQLITE_OK && rc!=SQLITE_READONLY_CANTINIT ) goto shm_open_err;
42574 }
42575
@@ -43751,12 +43795,14 @@
43751 dwShareMode,
43752 dwCreationDisposition,
43753 &extendedParameters);
43754 if( h!=INVALID_HANDLE_VALUE ) break;
43755 if( isReadWrite ){
43756 int isRO = 0;
43757 int rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO);
 
 
43758 if( rc2==SQLITE_OK && isRO ) break;
43759 }
43760 }while( winRetryIoerr(&cnt, &lastErrno) );
43761 #else
43762 do{
@@ -43766,12 +43812,14 @@
43766 dwCreationDisposition,
43767 dwFlagsAndAttributes,
43768 NULL);
43769 if( h!=INVALID_HANDLE_VALUE ) break;
43770 if( isReadWrite ){
43771 int isRO = 0;
43772 int rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO);
 
 
43773 if( rc2==SQLITE_OK && isRO ) break;
43774 }
43775 }while( winRetryIoerr(&cnt, &lastErrno) );
43776 #endif
43777 }
@@ -43784,12 +43832,14 @@
43784 dwCreationDisposition,
43785 dwFlagsAndAttributes,
43786 NULL);
43787 if( h!=INVALID_HANDLE_VALUE ) break;
43788 if( isReadWrite ){
43789 int isRO = 0;
43790 int rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO);
 
 
43791 if( rc2==SQLITE_OK && isRO ) break;
43792 }
43793 }while( winRetryIoerr(&cnt, &lastErrno) );
43794 }
43795 #endif
@@ -93290,19 +93340,19 @@
93290 for(i=0; i<p->nExpr; i++){
93291 heightOfExpr(p->a[i].pExpr, pnHeight);
93292 }
93293 }
93294 }
93295 static void heightOfSelect(Select *p, int *pnHeight){
93296 if( p ){
 
93297 heightOfExpr(p->pWhere, pnHeight);
93298 heightOfExpr(p->pHaving, pnHeight);
93299 heightOfExpr(p->pLimit, pnHeight);
93300 heightOfExprList(p->pEList, pnHeight);
93301 heightOfExprList(p->pGroupBy, pnHeight);
93302 heightOfExprList(p->pOrderBy, pnHeight);
93303 heightOfSelect(p->pPrior, pnHeight);
93304 }
93305 }
93306
93307 /*
93308 ** Set the Expr.nHeight variable in the structure passed as an
@@ -100084,10 +100134,13 @@
100084 assert( "BBB"[0]==SQLITE_AFF_TEXT );
100085 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
100086 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
100087 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
100088 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
 
 
 
100089 sqlite3VdbeJumpHere(v, jZeroRows);
100090 }
100091 }
100092
100093
@@ -113501,10 +113554,11 @@
113501 int (*bind_pointer)(sqlite3_stmt*,int,void*,const char*,void(*)(void*));
113502 void (*result_pointer)(sqlite3_context*,void*,const char*,void(*)(void*));
113503 void *(*value_pointer)(sqlite3_value*,const char*);
113504 int (*vtab_nochange)(sqlite3_context*);
113505 int (*value_nochange)(sqlite3_value*);
 
113506 };
113507
113508 /*
113509 ** This is the function signature used for all extension entry points. It
113510 ** is also defined in the file "loadext.c".
@@ -113770,10 +113824,11 @@
113770 #define sqlite3_result_pointer sqlite3_api->result_pointer
113771 #define sqlite3_value_pointer sqlite3_api->value_pointer
113772 /* Version 3.22.0 and later */
113773 #define sqlite3_vtab_nochange sqlite3_api->vtab_nochange
113774 #define sqlite3_value_nochange sqltie3_api->value_nochange
 
113775 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
113776
113777 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
113778 /* This case when the file really is being compiled as a loadable
113779 ** extension */
@@ -114207,11 +114262,12 @@
114207 sqlite3_bind_pointer,
114208 sqlite3_result_pointer,
114209 sqlite3_value_pointer,
114210 /* Version 3.22.0 and later */
114211 sqlite3_vtab_nochange,
114212 sqlite3_value_nochange
 
114213 };
114214
114215 /*
114216 ** Attempt to load an SQLite extension library contained in the file
114217 ** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -140461,10 +140517,12 @@
140461 int yygoto; /* The next state */
140462 int yyact; /* The next action */
140463 yyStackEntry *yymsp; /* The top of the parser's stack */
140464 int yysize; /* Amount to pop the stack */
140465 sqlite3ParserARG_FETCH;
 
 
140466 yymsp = yypParser->yytos;
140467 #ifndef NDEBUG
140468 if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
140469 yysize = yyRuleInfo[yyruleno].nrhs;
140470 if( yysize ){
@@ -143275,10 +143333,14 @@
143275 **
143276 ** This header file is used by programs that want to link against the
143277 ** RTREE library. All it does is declare the sqlite3RtreeInit() interface.
143278 */
143279 /* #include "sqlite3.h" */
 
 
 
 
143280
143281 #if 0
143282 extern "C" {
143283 #endif /* __cplusplus */
143284
@@ -167030,11 +167092,12 @@
167030 ** of 4-byte coordinates. For leaf nodes the integer is the rowid
167031 ** of a record. For internal nodes it is the node number of a
167032 ** child page.
167033 */
167034
167035 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RTREE)
 
167036
167037 #ifndef SQLITE_CORE
167038 /* #include "sqlite3ext.h" */
167039 SQLITE_EXTENSION_INIT1
167040 #else
@@ -178688,10 +178751,11 @@
178688 int bIndirect; /* True if all changes are indirect */
178689 int bAutoAttach; /* True to auto-attach tables */
178690 int rc; /* Non-zero if an error has occurred */
178691 void *pFilterCtx; /* First argument to pass to xTableFilter */
178692 int (*xTableFilter)(void *pCtx, const char *zTab);
 
178693 sqlite3_session *pNext; /* Next session object on same db. */
178694 SessionTable *pTable; /* List of attached tables */
178695 SessionHook hook; /* APIs to grab new and old data with */
178696 };
178697
@@ -178755,10 +178819,11 @@
178755 */
178756 struct SessionTable {
178757 SessionTable *pNext;
178758 char *zName; /* Local name of table */
178759 int nCol; /* Number of columns in table zName */
 
178760 const char **azCol; /* Column names */
178761 u8 *abPK; /* Array of primary key flags */
178762 int nEntry; /* Total number of entries in hash table */
178763 int nChange; /* Size of apChange[] array */
178764 SessionChange **apChange; /* Hash table buckets */
@@ -179138,10 +179203,11 @@
179138 n = sqlite3_value_bytes(pVal);
179139 if( !z && (eType!=SQLITE_BLOB || n>0) ) return SQLITE_NOMEM;
179140 h = sessionHashAppendBlob(h, n, z);
179141 }else{
179142 assert( eType==SQLITE_NULL );
 
179143 *pbNullPK = 1;
179144 }
179145 }
179146 }
179147
@@ -179480,11 +179546,10 @@
179480 }else{
179481 z = sqlite3_value_blob(pVal);
179482 }
179483 if( memcmp(a, z, n) ) return 0;
179484 a += n;
179485 break;
179486 }
179487 }
179488 }
179489
179490 return 1;
@@ -179690,14 +179755,58 @@
179690 if( abPK[i] ){
179691 pTab->abPK = abPK;
179692 break;
179693 }
179694 }
 
 
 
179695 }
179696 }
179697 return (pSession->rc || pTab->abPK==0);
179698 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179699
179700 /*
179701 ** This function is only called from with a pre-update-hook reporting a
179702 ** change on table pTab (attached to session pSession). The type of change
179703 ** (UPDATE, INSERT, DELETE) is specified by the first argument.
@@ -179711,10 +179820,11 @@
179711 SessionTable *pTab /* Table that change applies to */
179712 ){
179713 int iHash;
179714 int bNull = 0;
179715 int rc = SQLITE_OK;
 
179716
179717 if( pSession->rc ) return;
179718
179719 /* Load table details if required */
179720 if( sessionInitTable(pSession, pTab) ) return;
@@ -179729,10 +179839,29 @@
179729 /* Grow the hash table if required */
179730 if( sessionGrowHash(0, pTab) ){
179731 pSession->rc = SQLITE_NOMEM;
179732 return;
179733 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179734
179735 /* Calculate the hash-key for this change. If the primary key of the row
179736 ** includes a NULL value, exit early. Such changes are ignored by the
179737 ** session module. */
179738 rc = sessionPreupdateHash(pSession, pTab, op==SQLITE_INSERT, &iHash, &bNull);
@@ -179819,10 +179948,13 @@
179819 }
179820 }
179821
179822 /* If an error has occurred, mark the session object as failed. */
179823 error_out:
 
 
 
179824 if( rc!=SQLITE_OK ){
179825 pSession->rc = rc;
179826 }
179827 }
179828
@@ -180280,10 +180412,11 @@
180280 if( pHead ) sqlite3_preupdate_hook(db, xPreUpdate, (void*)pHead);
180281 break;
180282 }
180283 }
180284 sqlite3_mutex_leave(sqlite3_db_mutex(db));
 
180285
180286 /* Delete all attached table objects. And the contents of their
180287 ** associated hash-tables. */
180288 sessionDeleteTable(pSession->pTable);
180289
@@ -180747,32 +180880,45 @@
180747 const char **azCol, /* Names of table columns */
180748 u8 *abPK, /* PRIMARY KEY array */
180749 sqlite3_stmt **ppStmt /* OUT: Prepared SELECT statement */
180750 ){
180751 int rc = SQLITE_OK;
180752 int i;
180753 const char *zSep = "";
180754 SessionBuffer buf = {0, 0, 0};
180755
180756 sessionAppendStr(&buf, "SELECT * FROM ", &rc);
180757 sessionAppendIdent(&buf, zDb, &rc);
180758 sessionAppendStr(&buf, ".", &rc);
180759 sessionAppendIdent(&buf, zTab, &rc);
180760 sessionAppendStr(&buf, " WHERE ", &rc);
180761 for(i=0; i<nCol; i++){
180762 if( abPK[i] ){
180763 sessionAppendStr(&buf, zSep, &rc);
180764 sessionAppendIdent(&buf, azCol[i], &rc);
180765 sessionAppendStr(&buf, " = ?", &rc);
180766 sessionAppendInteger(&buf, i+1, &rc);
180767 zSep = " AND ";
180768 }
180769 }
180770 if( rc==SQLITE_OK ){
180771 rc = sqlite3_prepare_v2(db, (char *)buf.aBuf, buf.nBuf, ppStmt, 0);
180772 }
180773 sqlite3_free(buf.aBuf);
 
 
 
 
 
 
 
 
 
 
 
 
 
180774 return rc;
180775 }
180776
180777 /*
180778 ** Bind the PRIMARY KEY values from the change passed in argument pChange
@@ -181937,11 +182083,11 @@
181937 sqlite3_stmt *pInsert; /* INSERT statement */
181938 sqlite3_stmt *pSelect; /* SELECT statement */
181939 int nCol; /* Size of azCol[] and abPK[] arrays */
181940 const char **azCol; /* Array of column names */
181941 u8 *abPK; /* Boolean array - true if column is in PK */
181942
181943 int bDeferConstraints; /* True to defer constraints */
181944 SessionBuffer constraints; /* Deferred constraints are stored here */
181945 };
181946
181947 /*
@@ -182106,10 +182252,11 @@
182106 }
182107 sqlite3_free(buf.aBuf);
182108
182109 return rc;
182110 }
 
182111
182112 /*
182113 ** Formulate and prepare an SQL statement to query table zTab by primary
182114 ** key. Assuming the following table structure:
182115 **
@@ -182167,10 +182314,51 @@
182167 rc = sqlite3_prepare_v2(db, (char *)buf.aBuf, buf.nBuf, &p->pInsert, 0);
182168 }
182169 sqlite3_free(buf.aBuf);
182170 return rc;
182171 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182172
182173 /*
182174 ** A wrapper around sqlite3_bind_value() that detects an extra problem.
182175 ** See comments in the body of this function for details.
182176 */
@@ -182498,15 +182686,29 @@
182498 );
182499 }
182500
182501 }else{
182502 assert( op==SQLITE_INSERT );
182503 rc = sessionBindRow(pIter, sqlite3changeset_new, nCol, 0, p->pInsert);
182504 if( rc!=SQLITE_OK ) return rc;
 
 
 
 
 
 
 
 
182505
182506 sqlite3_step(p->pInsert);
182507 rc = sqlite3_reset(p->pInsert);
 
 
 
 
 
 
182508 if( (rc&0xff)==SQLITE_CONSTRAINT ){
182509 rc = sessionConflictHandler(
182510 SQLITE_CHANGESET_CONFLICT, p, pIter, xConflict, pCtx, pbReplace
182511 );
182512 }
@@ -182735,16 +182937,24 @@
182735 "primary key mismatch for table %s", zTab
182736 );
182737 }
182738 else{
182739 sApply.nCol = nCol;
182740 if((rc = sessionSelectRow(db, zTab, &sApply))
182741 || (rc = sessionUpdateRow(db, zTab, &sApply))
182742 || (rc = sessionDeleteRow(db, zTab, &sApply))
182743 || (rc = sessionInsertRow(db, zTab, &sApply))
182744 ){
182745 break;
 
 
 
 
 
 
 
 
182746 }
182747 }
182748 nTab = sqlite3Strlen30(zTab);
182749 }
182750 }
@@ -188063,10 +188273,12 @@
188063 int fts5yygoto; /* The next state */
188064 int fts5yyact; /* The next action */
188065 fts5yyStackEntry *fts5yymsp; /* The top of the parser's stack */
188066 int fts5yysize; /* Amount to pop the stack */
188067 sqlite3Fts5ParserARG_FETCH;
 
 
188068 fts5yymsp = fts5yypParser->fts5yytos;
188069 #ifndef NDEBUG
188070 if( fts5yyTraceFILE && fts5yyruleno<(int)(sizeof(fts5yyRuleName)/sizeof(fts5yyRuleName[0])) ){
188071 fts5yysize = fts5yyRuleInfo[fts5yyruleno].nrhs;
188072 if( fts5yysize ){
@@ -203116,11 +203328,11 @@
203116 int nArg, /* Number of args */
203117 sqlite3_value **apUnused /* Function arguments */
203118 ){
203119 assert( nArg==0 );
203120 UNUSED_PARAM2(nArg, apUnused);
203121 sqlite3_result_text(pCtx, "fts5: 2018-01-16 13:37:43 feb2c2b6f66b0f45490beb1642d99cdb89fa220e299a8c118929df557c814189", -1, SQLITE_TRANSIENT);
203122 }
203123
203124 static int fts5Init(sqlite3 *db){
203125 static const sqlite3_module fts5Mod = {
203126 /* iVersion */ 2,
@@ -207384,12 +207596,12 @@
207384 }
207385 #endif /* SQLITE_CORE */
207386 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
207387
207388 /************** End of stmt.c ************************************************/
207389 #if __LINE__!=207389
207390 #undef SQLITE_SOURCE_ID
207391 #define SQLITE_SOURCE_ID "2018-01-16 13:37:43 feb2c2b6f66b0f45490beb1642d99cdb89fa220e299a8c118929df557c81alt2"
207392 #endif
207393 /* Return the source-id for this library */
207394 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
207395 /************************** End of sqlite3.c ******************************/
207396
--- 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.22.0"
1151 #define SQLITE_VERSION_NUMBER 3022000
1152 #define SQLITE_SOURCE_ID "2018-01-20 15:48:45 136bf323e42dc90e1780199a381bcbb084b069eca5c7343ee6fc6e2550831536"
1153
1154 /*
1155 ** CAPI3REF: Run-Time Library Version Numbers
1156 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1157 **
@@ -1532,11 +1532,10 @@
1532 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
1533 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
1534 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
1535 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
1536 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
 
1537 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
1538 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
1539 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
1540 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
1541 #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
@@ -3974,12 +3973,12 @@
3973 /*
3974 ** CAPI3REF: SQL Trace Event Codes
3975 ** KEYWORDS: SQLITE_TRACE
3976 **
3977 ** These constants identify classes of events that can be monitored
3978 ** using the [sqlite3_trace_v2()] tracing logic. The M argument
3979 ** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of
3980 ** the following constants. ^The first argument to the trace callback
3981 ** is one of the following constants.
3982 **
3983 ** New tracing constants may be added in future releases.
3984 **
@@ -10097,10 +10096,39 @@
10096 ** Changes are not recorded for individual rows that have NULL values stored
10097 ** in one or more of their PRIMARY KEY columns.
10098 **
10099 ** SQLITE_OK is returned if the call completes without error. Or, if an error
10100 ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
10101 **
10102 ** <h3>Special sqlite_stat1 Handling</h3>
10103 **
10104 ** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to
10105 ** some of the rules above. In SQLite, the schema of sqlite_stat1 is:
10106 ** <pre>
10107 ** &nbsp; CREATE TABLE sqlite_stat1(tbl,idx,stat)
10108 ** </pre>
10109 **
10110 ** Even though sqlite_stat1 does not have a PRIMARY KEY, changes are
10111 ** recorded for it as if the PRIMARY KEY is (tbl,idx). Additionally, changes
10112 ** are recorded for rows for which (idx IS NULL) is true. However, for such
10113 ** rows a zero-length blob (SQL value X'') is stored in the changeset or
10114 ** patchset instead of a NULL value. This allows such changesets to be
10115 ** manipulated by legacy implementations of sqlite3changeset_invert(),
10116 ** concat() and similar.
10117 **
10118 ** The sqlite3changeset_apply() function automatically converts the
10119 ** zero-length blob back to a NULL value when updating the sqlite_stat1
10120 ** table. However, if the application calls sqlite3changeset_new(),
10121 ** sqlite3changeset_old() or sqlite3changeset_conflict on a changeset
10122 ** iterator directly (including on a changeset iterator passed to a
10123 ** conflict-handler callback) then the X'' value is returned. The application
10124 ** must translate X'' to NULL itself if required.
10125 **
10126 ** Legacy (older than 3.22.0) versions of the sessions module cannot capture
10127 ** changes made to the sqlite_stat1 table. Legacy versions of the
10128 ** sqlite3changeset_apply() function silently ignore any modifications to the
10129 ** sqlite_stat1 table that are part of a changeset or patchset.
10130 */
10131 SQLITE_API int sqlite3session_attach(
10132 sqlite3_session *pSession, /* Session object */
10133 const char *zTab /* Table name */
10134 );
@@ -18923,11 +18951,10 @@
18951 Vdbe *pVdbe; /* The VM that owns this context */
18952 int iOp; /* Instruction number of OP_Function */
18953 int isError; /* Error code returned by the function. */
18954 u8 skipFlag; /* Skip accumulator loading if true */
18955 u8 fErrorOrAux; /* isError!=0 or pVdbe->pAuxData modified */
 
18956 u8 argc; /* Number of arguments */
18957 sqlite3_value *argv[1]; /* Argument set */
18958 };
18959
18960 /* A bitfield type for use inside of structures. Always follow with :N where
@@ -28766,19 +28793,40 @@
28793 ** E==2 results in 100. E==50 results in 1.0e50.
28794 **
28795 ** This routine only works for values of E between 1 and 341.
28796 */
28797 static LONGDOUBLE_TYPE sqlite3Pow10(int E){
28798 #if defined(_MSC_VER)
28799 static const LONGDOUBLE_TYPE x[] = {
28800 1.0e+001,
28801 1.0e+002,
28802 1.0e+004,
28803 1.0e+008,
28804 1.0e+016,
28805 1.0e+032,
28806 1.0e+064,
28807 1.0e+128,
28808 1.0e+256
28809 };
28810 LONGDOUBLE_TYPE r = 1.0;
28811 int i;
28812 assert( E>=0 && E<=307 );
28813 for(i=0; E!=0; i++, E >>=1){
28814 if( E & 1 ) r *= x[i];
28815 }
28816 return r;
28817 #else
28818 LONGDOUBLE_TYPE x = 10.0;
28819 LONGDOUBLE_TYPE r = 1.0;
28820 while(1){
28821 if( E & 1 ) r *= x;
28822 E >>= 1;
28823 if( E==0 ) break;
28824 x *= x;
28825 }
28826 return r;
28827 #endif
28828 }
28829
28830 /*
28831 ** The string z[] is an text representation of a real number.
28832 ** Convert this string to a double and write it into *pResult.
@@ -42498,11 +42546,10 @@
42546 */
42547 static int winOpenSharedMemory(winFile *pDbFd){
42548 struct winShm *p; /* The connection to be opened */
42549 winShmNode *pShmNode = 0; /* The underlying mmapped file */
42550 int rc = SQLITE_OK; /* Result code */
 
42551 winShmNode *pNew; /* Newly allocated winShmNode */
42552 int nName; /* Size of zName in bytes */
42553
42554 assert( pDbFd->pShm==0 ); /* Not previously opened */
42555
@@ -42532,10 +42579,13 @@
42579 if( sqlite3StrICmp(pShmNode->zFilename, pNew->zFilename)==0 ) break;
42580 }
42581 if( pShmNode ){
42582 sqlite3_free(pNew);
42583 }else{
42584 int inFlags = SQLITE_OPEN_WAL;
42585 int outFlags = 0;
42586
42587 pShmNode = pNew;
42588 pNew = 0;
42589 ((winFile*)(&pShmNode->hFile))->h = INVALID_HANDLE_VALUE;
42590 pShmNode->pNext = winShmNodeList;
42591 winShmNodeList = pShmNode;
@@ -42547,29 +42597,23 @@
42597 goto shm_open_err;
42598 }
42599 }
42600
42601 if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
42602 inFlags |= SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
42603 }else{
42604 inFlags |= SQLITE_OPEN_READONLY;
42605 }
42606 rc = winOpen(pDbFd->pVfs, pShmNode->zFilename,
42607 (sqlite3_file*)&pShmNode->hFile,
42608 inFlags, &outFlags);
42609 if( rc!=SQLITE_OK ){
42610 rc = winLogError(rc, osGetLastError(), "winOpenShm",
42611 pShmNode->zFilename);
42612 goto shm_open_err;
42613 }
42614 if( outFlags==SQLITE_OPEN_READONLY ) pShmNode->isReadonly = 1;
 
 
 
 
 
 
42615
42616 rc = winLockSharedMemory(pShmNode);
42617 if( rc!=SQLITE_OK && rc!=SQLITE_READONLY_CANTINIT ) goto shm_open_err;
42618 }
42619
@@ -43751,12 +43795,14 @@
43795 dwShareMode,
43796 dwCreationDisposition,
43797 &extendedParameters);
43798 if( h!=INVALID_HANDLE_VALUE ) break;
43799 if( isReadWrite ){
43800 int rc2, isRO = 0;
43801 sqlite3BeginBenignMalloc();
43802 rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO);
43803 sqlite3EndBenignMalloc();
43804 if( rc2==SQLITE_OK && isRO ) break;
43805 }
43806 }while( winRetryIoerr(&cnt, &lastErrno) );
43807 #else
43808 do{
@@ -43766,12 +43812,14 @@
43812 dwCreationDisposition,
43813 dwFlagsAndAttributes,
43814 NULL);
43815 if( h!=INVALID_HANDLE_VALUE ) break;
43816 if( isReadWrite ){
43817 int rc2, isRO = 0;
43818 sqlite3BeginBenignMalloc();
43819 rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO);
43820 sqlite3EndBenignMalloc();
43821 if( rc2==SQLITE_OK && isRO ) break;
43822 }
43823 }while( winRetryIoerr(&cnt, &lastErrno) );
43824 #endif
43825 }
@@ -43784,12 +43832,14 @@
43832 dwCreationDisposition,
43833 dwFlagsAndAttributes,
43834 NULL);
43835 if( h!=INVALID_HANDLE_VALUE ) break;
43836 if( isReadWrite ){
43837 int rc2, isRO = 0;
43838 sqlite3BeginBenignMalloc();
43839 rc2 = winAccess(pVfs, zName, SQLITE_ACCESS_READ, &isRO);
43840 sqlite3EndBenignMalloc();
43841 if( rc2==SQLITE_OK && isRO ) break;
43842 }
43843 }while( winRetryIoerr(&cnt, &lastErrno) );
43844 }
43845 #endif
@@ -93290,19 +93340,19 @@
93340 for(i=0; i<p->nExpr; i++){
93341 heightOfExpr(p->a[i].pExpr, pnHeight);
93342 }
93343 }
93344 }
93345 static void heightOfSelect(Select *pSelect, int *pnHeight){
93346 Select *p;
93347 for(p=pSelect; p; p=p->pPrior){
93348 heightOfExpr(p->pWhere, pnHeight);
93349 heightOfExpr(p->pHaving, pnHeight);
93350 heightOfExpr(p->pLimit, pnHeight);
93351 heightOfExprList(p->pEList, pnHeight);
93352 heightOfExprList(p->pGroupBy, pnHeight);
93353 heightOfExprList(p->pOrderBy, pnHeight);
 
93354 }
93355 }
93356
93357 /*
93358 ** Set the Expr.nHeight variable in the structure passed as an
@@ -100084,10 +100134,13 @@
100134 assert( "BBB"[0]==SQLITE_AFF_TEXT );
100135 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
100136 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
100137 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
100138 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
100139 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
100140 sqlite3VdbeChangeP4(v, -1, (char*)pStat1, P4_TABLE);
100141 #endif
100142 sqlite3VdbeJumpHere(v, jZeroRows);
100143 }
100144 }
100145
100146
@@ -113501,10 +113554,11 @@
113554 int (*bind_pointer)(sqlite3_stmt*,int,void*,const char*,void(*)(void*));
113555 void (*result_pointer)(sqlite3_context*,void*,const char*,void(*)(void*));
113556 void *(*value_pointer)(sqlite3_value*,const char*);
113557 int (*vtab_nochange)(sqlite3_context*);
113558 int (*value_nochange)(sqlite3_value*);
113559 const char *(*vtab_collation)(sqlite3_index_info*,int);
113560 };
113561
113562 /*
113563 ** This is the function signature used for all extension entry points. It
113564 ** is also defined in the file "loadext.c".
@@ -113770,10 +113824,11 @@
113824 #define sqlite3_result_pointer sqlite3_api->result_pointer
113825 #define sqlite3_value_pointer sqlite3_api->value_pointer
113826 /* Version 3.22.0 and later */
113827 #define sqlite3_vtab_nochange sqlite3_api->vtab_nochange
113828 #define sqlite3_value_nochange sqltie3_api->value_nochange
113829 #define sqlite3_vtab_collation sqltie3_api->vtab_collation
113830 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
113831
113832 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
113833 /* This case when the file really is being compiled as a loadable
113834 ** extension */
@@ -114207,11 +114262,12 @@
114262 sqlite3_bind_pointer,
114263 sqlite3_result_pointer,
114264 sqlite3_value_pointer,
114265 /* Version 3.22.0 and later */
114266 sqlite3_vtab_nochange,
114267 sqlite3_value_nochange,
114268 sqlite3_vtab_collation
114269 };
114270
114271 /*
114272 ** Attempt to load an SQLite extension library contained in the file
114273 ** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -140461,10 +140517,12 @@
140517 int yygoto; /* The next state */
140518 int yyact; /* The next action */
140519 yyStackEntry *yymsp; /* The top of the parser's stack */
140520 int yysize; /* Amount to pop the stack */
140521 sqlite3ParserARG_FETCH;
140522 (void)yyLookahead;
140523 (void)yyLookaheadToken;
140524 yymsp = yypParser->yytos;
140525 #ifndef NDEBUG
140526 if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
140527 yysize = yyRuleInfo[yyruleno].nrhs;
140528 if( yysize ){
@@ -143275,10 +143333,14 @@
143333 **
143334 ** This header file is used by programs that want to link against the
143335 ** RTREE library. All it does is declare the sqlite3RtreeInit() interface.
143336 */
143337 /* #include "sqlite3.h" */
143338
143339 #ifdef SQLITE_OMIT_VIRTUALTABLE
143340 # undef SQLITE_ENABLE_RTREE
143341 #endif
143342
143343 #if 0
143344 extern "C" {
143345 #endif /* __cplusplus */
143346
@@ -167030,11 +167092,12 @@
167092 ** of 4-byte coordinates. For leaf nodes the integer is the rowid
167093 ** of a record. For internal nodes it is the node number of a
167094 ** child page.
167095 */
167096
167097 #if !defined(SQLITE_CORE) \
167098 || (defined(SQLITE_ENABLE_RTREE) && !defined(SQLITE_OMIT_VIRTUALTABLE))
167099
167100 #ifndef SQLITE_CORE
167101 /* #include "sqlite3ext.h" */
167102 SQLITE_EXTENSION_INIT1
167103 #else
@@ -178688,10 +178751,11 @@
178751 int bIndirect; /* True if all changes are indirect */
178752 int bAutoAttach; /* True to auto-attach tables */
178753 int rc; /* Non-zero if an error has occurred */
178754 void *pFilterCtx; /* First argument to pass to xTableFilter */
178755 int (*xTableFilter)(void *pCtx, const char *zTab);
178756 sqlite3_value *pZeroBlob; /* Value containing X'' */
178757 sqlite3_session *pNext; /* Next session object on same db. */
178758 SessionTable *pTable; /* List of attached tables */
178759 SessionHook hook; /* APIs to grab new and old data with */
178760 };
178761
@@ -178755,10 +178819,11 @@
178819 */
178820 struct SessionTable {
178821 SessionTable *pNext;
178822 char *zName; /* Local name of table */
178823 int nCol; /* Number of columns in table zName */
178824 int bStat1; /* True if this is sqlite_stat1 */
178825 const char **azCol; /* Column names */
178826 u8 *abPK; /* Array of primary key flags */
178827 int nEntry; /* Total number of entries in hash table */
178828 int nChange; /* Size of apChange[] array */
178829 SessionChange **apChange; /* Hash table buckets */
@@ -179138,10 +179203,11 @@
179203 n = sqlite3_value_bytes(pVal);
179204 if( !z && (eType!=SQLITE_BLOB || n>0) ) return SQLITE_NOMEM;
179205 h = sessionHashAppendBlob(h, n, z);
179206 }else{
179207 assert( eType==SQLITE_NULL );
179208 assert( pTab->bStat1==0 || i!=1 );
179209 *pbNullPK = 1;
179210 }
179211 }
179212 }
179213
@@ -179480,11 +179546,10 @@
179546 }else{
179547 z = sqlite3_value_blob(pVal);
179548 }
179549 if( memcmp(a, z, n) ) return 0;
179550 a += n;
 
179551 }
179552 }
179553 }
179554
179555 return 1;
@@ -179690,14 +179755,58 @@
179755 if( abPK[i] ){
179756 pTab->abPK = abPK;
179757 break;
179758 }
179759 }
179760 if( 0==sqlite3_stricmp("sqlite_stat1", pTab->zName) ){
179761 pTab->bStat1 = 1;
179762 }
179763 }
179764 }
179765 return (pSession->rc || pTab->abPK==0);
179766 }
179767
179768 /*
179769 ** Versions of the four methods in object SessionHook for use with the
179770 ** sqlite_stat1 table. The purpose of this is to substitute a zero-length
179771 ** blob each time a NULL value is read from the "idx" column of the
179772 ** sqlite_stat1 table.
179773 */
179774 typedef struct SessionStat1Ctx SessionStat1Ctx;
179775 struct SessionStat1Ctx {
179776 SessionHook hook;
179777 sqlite3_session *pSession;
179778 };
179779 static int sessionStat1Old(void *pCtx, int iCol, sqlite3_value **ppVal){
179780 SessionStat1Ctx *p = (SessionStat1Ctx*)pCtx;
179781 sqlite3_value *pVal = 0;
179782 int rc = p->hook.xOld(p->hook.pCtx, iCol, &pVal);
179783 if( rc==SQLITE_OK && iCol==1 && sqlite3_value_type(pVal)==SQLITE_NULL ){
179784 pVal = p->pSession->pZeroBlob;
179785 }
179786 *ppVal = pVal;
179787 return rc;
179788 }
179789 static int sessionStat1New(void *pCtx, int iCol, sqlite3_value **ppVal){
179790 SessionStat1Ctx *p = (SessionStat1Ctx*)pCtx;
179791 sqlite3_value *pVal = 0;
179792 int rc = p->hook.xNew(p->hook.pCtx, iCol, &pVal);
179793 if( rc==SQLITE_OK && iCol==1 && sqlite3_value_type(pVal)==SQLITE_NULL ){
179794 pVal = p->pSession->pZeroBlob;
179795 }
179796 *ppVal = pVal;
179797 return rc;
179798 }
179799 static int sessionStat1Count(void *pCtx){
179800 SessionStat1Ctx *p = (SessionStat1Ctx*)pCtx;
179801 return p->hook.xCount(p->hook.pCtx);
179802 }
179803 static int sessionStat1Depth(void *pCtx){
179804 SessionStat1Ctx *p = (SessionStat1Ctx*)pCtx;
179805 return p->hook.xDepth(p->hook.pCtx);
179806 }
179807
179808
179809 /*
179810 ** This function is only called from with a pre-update-hook reporting a
179811 ** change on table pTab (attached to session pSession). The type of change
179812 ** (UPDATE, INSERT, DELETE) is specified by the first argument.
@@ -179711,10 +179820,11 @@
179820 SessionTable *pTab /* Table that change applies to */
179821 ){
179822 int iHash;
179823 int bNull = 0;
179824 int rc = SQLITE_OK;
179825 SessionStat1Ctx stat1;
179826
179827 if( pSession->rc ) return;
179828
179829 /* Load table details if required */
179830 if( sessionInitTable(pSession, pTab) ) return;
@@ -179729,10 +179839,29 @@
179839 /* Grow the hash table if required */
179840 if( sessionGrowHash(0, pTab) ){
179841 pSession->rc = SQLITE_NOMEM;
179842 return;
179843 }
179844
179845 if( pTab->bStat1 ){
179846 stat1.hook = pSession->hook;
179847 stat1.pSession = pSession;
179848 pSession->hook.pCtx = (void*)&stat1;
179849 pSession->hook.xNew = sessionStat1New;
179850 pSession->hook.xOld = sessionStat1Old;
179851 pSession->hook.xCount = sessionStat1Count;
179852 pSession->hook.xDepth = sessionStat1Depth;
179853 if( pSession->pZeroBlob==0 ){
179854 sqlite3_value *p = sqlite3ValueNew(0);
179855 if( p==0 ){
179856 rc = SQLITE_NOMEM;
179857 goto error_out;
179858 }
179859 sqlite3ValueSetStr(p, 0, "", 0, SQLITE_STATIC);
179860 pSession->pZeroBlob = p;
179861 }
179862 }
179863
179864 /* Calculate the hash-key for this change. If the primary key of the row
179865 ** includes a NULL value, exit early. Such changes are ignored by the
179866 ** session module. */
179867 rc = sessionPreupdateHash(pSession, pTab, op==SQLITE_INSERT, &iHash, &bNull);
@@ -179819,10 +179948,13 @@
179948 }
179949 }
179950
179951 /* If an error has occurred, mark the session object as failed. */
179952 error_out:
179953 if( pTab->bStat1 ){
179954 pSession->hook = stat1.hook;
179955 }
179956 if( rc!=SQLITE_OK ){
179957 pSession->rc = rc;
179958 }
179959 }
179960
@@ -180280,10 +180412,11 @@
180412 if( pHead ) sqlite3_preupdate_hook(db, xPreUpdate, (void*)pHead);
180413 break;
180414 }
180415 }
180416 sqlite3_mutex_leave(sqlite3_db_mutex(db));
180417 sqlite3ValueFree(pSession->pZeroBlob);
180418
180419 /* Delete all attached table objects. And the contents of their
180420 ** associated hash-tables. */
180421 sessionDeleteTable(pSession->pTable);
180422
@@ -180747,32 +180880,45 @@
180880 const char **azCol, /* Names of table columns */
180881 u8 *abPK, /* PRIMARY KEY array */
180882 sqlite3_stmt **ppStmt /* OUT: Prepared SELECT statement */
180883 ){
180884 int rc = SQLITE_OK;
180885 char *zSql = 0;
180886 int nSql = -1;
180887
180888 if( 0==sqlite3_stricmp("sqlite_stat1", zTab) ){
180889 zSql = sqlite3_mprintf(
180890 "SELECT tbl, ?2, stat FROM %Q.sqlite_stat1 WHERE tbl IS ?1 AND "
180891 "idx IS (CASE WHEN ?2=X'' THEN NULL ELSE ?2 END)", zDb
180892 );
180893 }else{
180894 int i;
180895 const char *zSep = "";
180896 SessionBuffer buf = {0, 0, 0};
180897
180898 sessionAppendStr(&buf, "SELECT * FROM ", &rc);
180899 sessionAppendIdent(&buf, zDb, &rc);
180900 sessionAppendStr(&buf, ".", &rc);
180901 sessionAppendIdent(&buf, zTab, &rc);
180902 sessionAppendStr(&buf, " WHERE ", &rc);
180903 for(i=0; i<nCol; i++){
180904 if( abPK[i] ){
180905 sessionAppendStr(&buf, zSep, &rc);
180906 sessionAppendIdent(&buf, azCol[i], &rc);
180907 sessionAppendStr(&buf, " IS ?", &rc);
180908 sessionAppendInteger(&buf, i+1, &rc);
180909 zSep = " AND ";
180910 }
180911 }
180912 zSql = (char*)buf.aBuf;
180913 nSql = buf.nBuf;
180914 }
180915
180916 if( rc==SQLITE_OK ){
180917 rc = sqlite3_prepare_v2(db, zSql, nSql, ppStmt, 0);
180918 }
180919 sqlite3_free(zSql);
180920 return rc;
180921 }
180922
180923 /*
180924 ** Bind the PRIMARY KEY values from the change passed in argument pChange
@@ -181937,11 +182083,11 @@
182083 sqlite3_stmt *pInsert; /* INSERT statement */
182084 sqlite3_stmt *pSelect; /* SELECT statement */
182085 int nCol; /* Size of azCol[] and abPK[] arrays */
182086 const char **azCol; /* Array of column names */
182087 u8 *abPK; /* Boolean array - true if column is in PK */
182088 int bStat1; /* True if table is sqlite_stat1 */
182089 int bDeferConstraints; /* True to defer constraints */
182090 SessionBuffer constraints; /* Deferred constraints are stored here */
182091 };
182092
182093 /*
@@ -182106,10 +182252,11 @@
182252 }
182253 sqlite3_free(buf.aBuf);
182254
182255 return rc;
182256 }
182257
182258
182259 /*
182260 ** Formulate and prepare an SQL statement to query table zTab by primary
182261 ** key. Assuming the following table structure:
182262 **
@@ -182167,10 +182314,51 @@
182314 rc = sqlite3_prepare_v2(db, (char *)buf.aBuf, buf.nBuf, &p->pInsert, 0);
182315 }
182316 sqlite3_free(buf.aBuf);
182317 return rc;
182318 }
182319
182320 static int sessionPrepare(sqlite3 *db, sqlite3_stmt **pp, const char *zSql){
182321 return sqlite3_prepare_v2(db, zSql, -1, pp, 0);
182322 }
182323
182324 /*
182325 ** Prepare statements for applying changes to the sqlite_stat1 table.
182326 ** These are similar to those created by sessionSelectRow(),
182327 ** sessionInsertRow(), sessionUpdateRow() and sessionDeleteRow() for
182328 ** other tables.
182329 */
182330 static int sessionStat1Sql(sqlite3 *db, SessionApplyCtx *p){
182331 int rc = sessionSelectRow(db, "sqlite_stat1", p);
182332 if( rc==SQLITE_OK ){
182333 rc = sessionPrepare(db, &p->pInsert,
182334 "INSERT INTO main.sqlite_stat1 VALUES(?1, "
182335 "CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END, "
182336 "?3)"
182337 );
182338 }
182339 if( rc==SQLITE_OK ){
182340 rc = sessionPrepare(db, &p->pUpdate,
182341 "UPDATE main.sqlite_stat1 SET "
182342 "tbl = CASE WHEN ?2 THEN ?3 ELSE tbl END, "
182343 "idx = CASE WHEN ?5 THEN ?6 ELSE idx END, "
182344 "stat = CASE WHEN ?8 THEN ?9 ELSE stat END "
182345 "WHERE tbl=?1 AND idx IS "
182346 "CASE WHEN length(?4)=0 AND typeof(?4)='blob' THEN NULL ELSE ?4 END "
182347 "AND (?10 OR ?8=0 OR stat IS ?7)"
182348 );
182349 }
182350 if( rc==SQLITE_OK ){
182351 rc = sessionPrepare(db, &p->pDelete,
182352 "DELETE FROM main.sqlite_stat1 WHERE tbl=?1 AND idx IS "
182353 "CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END "
182354 "AND (?4 OR stat IS ?3)"
182355 );
182356 }
182357 assert( rc==SQLITE_OK );
182358 return rc;
182359 }
182360
182361 /*
182362 ** A wrapper around sqlite3_bind_value() that detects an extra problem.
182363 ** See comments in the body of this function for details.
182364 */
@@ -182498,15 +182686,29 @@
182686 );
182687 }
182688
182689 }else{
182690 assert( op==SQLITE_INSERT );
182691 if( p->bStat1 ){
182692 /* Check if there is a conflicting row. For sqlite_stat1, this needs
182693 ** to be done using a SELECT, as there is no PRIMARY KEY in the
182694 ** database schema to throw an exception if a duplicate is inserted. */
182695 rc = sessionSeekToRow(p->db, pIter, p->abPK, p->pSelect);
182696 if( rc==SQLITE_ROW ){
182697 rc = SQLITE_CONSTRAINT;
182698 sqlite3_reset(p->pSelect);
182699 }
182700 }
182701
182702 if( rc==SQLITE_OK ){
182703 rc = sessionBindRow(pIter, sqlite3changeset_new, nCol, 0, p->pInsert);
182704 if( rc!=SQLITE_OK ) return rc;
182705
182706 sqlite3_step(p->pInsert);
182707 rc = sqlite3_reset(p->pInsert);
182708 }
182709
182710 if( (rc&0xff)==SQLITE_CONSTRAINT ){
182711 rc = sessionConflictHandler(
182712 SQLITE_CHANGESET_CONFLICT, p, pIter, xConflict, pCtx, pbReplace
182713 );
182714 }
@@ -182735,16 +182937,24 @@
182937 "primary key mismatch for table %s", zTab
182938 );
182939 }
182940 else{
182941 sApply.nCol = nCol;
182942 if( 0==sqlite3_stricmp(zTab, "sqlite_stat1") ){
182943 if( (rc = sessionStat1Sql(db, &sApply) ) ){
182944 break;
182945 }
182946 sApply.bStat1 = 1;
182947 }else{
182948 if((rc = sessionSelectRow(db, zTab, &sApply))
182949 || (rc = sessionUpdateRow(db, zTab, &sApply))
182950 || (rc = sessionDeleteRow(db, zTab, &sApply))
182951 || (rc = sessionInsertRow(db, zTab, &sApply))
182952 ){
182953 break;
182954 }
182955 sApply.bStat1 = 0;
182956 }
182957 }
182958 nTab = sqlite3Strlen30(zTab);
182959 }
182960 }
@@ -188063,10 +188273,12 @@
188273 int fts5yygoto; /* The next state */
188274 int fts5yyact; /* The next action */
188275 fts5yyStackEntry *fts5yymsp; /* The top of the parser's stack */
188276 int fts5yysize; /* Amount to pop the stack */
188277 sqlite3Fts5ParserARG_FETCH;
188278 (void)fts5yyLookahead;
188279 (void)fts5yyLookaheadToken;
188280 fts5yymsp = fts5yypParser->fts5yytos;
188281 #ifndef NDEBUG
188282 if( fts5yyTraceFILE && fts5yyruleno<(int)(sizeof(fts5yyRuleName)/sizeof(fts5yyRuleName[0])) ){
188283 fts5yysize = fts5yyRuleInfo[fts5yyruleno].nrhs;
188284 if( fts5yysize ){
@@ -203116,11 +203328,11 @@
203328 int nArg, /* Number of args */
203329 sqlite3_value **apUnused /* Function arguments */
203330 ){
203331 assert( nArg==0 );
203332 UNUSED_PARAM2(nArg, apUnused);
203333 sqlite3_result_text(pCtx, "fts5: 2018-01-20 15:48:45 136bf323e42dc90e1780199a381bcbb084b069eca5c7343ee6fc6e2550831536", -1, SQLITE_TRANSIENT);
203334 }
203335
203336 static int fts5Init(sqlite3 *db){
203337 static const sqlite3_module fts5Mod = {
203338 /* iVersion */ 2,
@@ -207384,12 +207596,12 @@
207596 }
207597 #endif /* SQLITE_CORE */
207598 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
207599
207600 /************** End of stmt.c ************************************************/
207601 #if __LINE__!=207601
207602 #undef SQLITE_SOURCE_ID
207603 #define SQLITE_SOURCE_ID "2018-01-20 15:48:45 136bf323e42dc90e1780199a381bcbb084b069eca5c7343ee6fc6e255083alt2"
207604 #endif
207605 /* Return the source-id for this library */
207606 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
207607 /************************** End of sqlite3.c ******************************/
207608
+32 -4
--- 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.22.0"
127127
#define SQLITE_VERSION_NUMBER 3022000
128
-#define SQLITE_SOURCE_ID "2018-01-16 13:37:43 feb2c2b6f66b0f45490beb1642d99cdb89fa220e299a8c118929df557c814189"
128
+#define SQLITE_SOURCE_ID "2018-01-20 15:48:45 136bf323e42dc90e1780199a381bcbb084b069eca5c7343ee6fc6e2550831536"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -508,11 +508,10 @@
508508
#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
509509
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
510510
#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
511511
#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
512512
#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
513
-#define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8))
514513
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
515514
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
516515
#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
517516
#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
518517
#define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
@@ -2950,12 +2949,12 @@
29502949
/*
29512950
** CAPI3REF: SQL Trace Event Codes
29522951
** KEYWORDS: SQLITE_TRACE
29532952
**
29542953
** These constants identify classes of events that can be monitored
2955
-** using the [sqlite3_trace_v2()] tracing logic. The third argument
2956
-** to [sqlite3_trace_v2()] is an OR-ed combination of one or more of
2954
+** using the [sqlite3_trace_v2()] tracing logic. The M argument
2955
+** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of
29572956
** the following constants. ^The first argument to the trace callback
29582957
** is one of the following constants.
29592958
**
29602959
** New tracing constants may be added in future releases.
29612960
**
@@ -9073,10 +9072,39 @@
90739072
** Changes are not recorded for individual rows that have NULL values stored
90749073
** in one or more of their PRIMARY KEY columns.
90759074
**
90769075
** SQLITE_OK is returned if the call completes without error. Or, if an error
90779076
** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
9077
+**
9078
+** <h3>Special sqlite_stat1 Handling</h3>
9079
+**
9080
+** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to
9081
+** some of the rules above. In SQLite, the schema of sqlite_stat1 is:
9082
+** <pre>
9083
+** &nbsp; CREATE TABLE sqlite_stat1(tbl,idx,stat)
9084
+** </pre>
9085
+**
9086
+** Even though sqlite_stat1 does not have a PRIMARY KEY, changes are
9087
+** recorded for it as if the PRIMARY KEY is (tbl,idx). Additionally, changes
9088
+** are recorded for rows for which (idx IS NULL) is true. However, for such
9089
+** rows a zero-length blob (SQL value X'') is stored in the changeset or
9090
+** patchset instead of a NULL value. This allows such changesets to be
9091
+** manipulated by legacy implementations of sqlite3changeset_invert(),
9092
+** concat() and similar.
9093
+**
9094
+** The sqlite3changeset_apply() function automatically converts the
9095
+** zero-length blob back to a NULL value when updating the sqlite_stat1
9096
+** table. However, if the application calls sqlite3changeset_new(),
9097
+** sqlite3changeset_old() or sqlite3changeset_conflict on a changeset
9098
+** iterator directly (including on a changeset iterator passed to a
9099
+** conflict-handler callback) then the X'' value is returned. The application
9100
+** must translate X'' to NULL itself if required.
9101
+**
9102
+** Legacy (older than 3.22.0) versions of the sessions module cannot capture
9103
+** changes made to the sqlite_stat1 table. Legacy versions of the
9104
+** sqlite3changeset_apply() function silently ignore any modifications to the
9105
+** sqlite_stat1 table that are part of a changeset or patchset.
90789106
*/
90799107
SQLITE_API int sqlite3session_attach(
90809108
sqlite3_session *pSession, /* Session object */
90819109
const char *zTab /* Table name */
90829110
);
90839111
--- 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.22.0"
127 #define SQLITE_VERSION_NUMBER 3022000
128 #define SQLITE_SOURCE_ID "2018-01-16 13:37:43 feb2c2b6f66b0f45490beb1642d99cdb89fa220e299a8c118929df557c814189"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -508,11 +508,10 @@
508 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
509 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
510 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
511 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
512 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
513 #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8))
514 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
515 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
516 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
517 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
518 #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
@@ -2950,12 +2949,12 @@
2950 /*
2951 ** CAPI3REF: SQL Trace Event Codes
2952 ** KEYWORDS: SQLITE_TRACE
2953 **
2954 ** These constants identify classes of events that can be monitored
2955 ** using the [sqlite3_trace_v2()] tracing logic. The third argument
2956 ** to [sqlite3_trace_v2()] is an OR-ed combination of one or more of
2957 ** the following constants. ^The first argument to the trace callback
2958 ** is one of the following constants.
2959 **
2960 ** New tracing constants may be added in future releases.
2961 **
@@ -9073,10 +9072,39 @@
9073 ** Changes are not recorded for individual rows that have NULL values stored
9074 ** in one or more of their PRIMARY KEY columns.
9075 **
9076 ** SQLITE_OK is returned if the call completes without error. Or, if an error
9077 ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9078 */
9079 SQLITE_API int sqlite3session_attach(
9080 sqlite3_session *pSession, /* Session object */
9081 const char *zTab /* Table name */
9082 );
9083
--- 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.22.0"
127 #define SQLITE_VERSION_NUMBER 3022000
128 #define SQLITE_SOURCE_ID "2018-01-20 15:48:45 136bf323e42dc90e1780199a381bcbb084b069eca5c7343ee6fc6e2550831536"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -508,11 +508,10 @@
508 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
509 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
510 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
511 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
512 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
 
513 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
514 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
515 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
516 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
517 #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
@@ -2950,12 +2949,12 @@
2949 /*
2950 ** CAPI3REF: SQL Trace Event Codes
2951 ** KEYWORDS: SQLITE_TRACE
2952 **
2953 ** These constants identify classes of events that can be monitored
2954 ** using the [sqlite3_trace_v2()] tracing logic. The M argument
2955 ** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of
2956 ** the following constants. ^The first argument to the trace callback
2957 ** is one of the following constants.
2958 **
2959 ** New tracing constants may be added in future releases.
2960 **
@@ -9073,10 +9072,39 @@
9072 ** Changes are not recorded for individual rows that have NULL values stored
9073 ** in one or more of their PRIMARY KEY columns.
9074 **
9075 ** SQLITE_OK is returned if the call completes without error. Or, if an error
9076 ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
9077 **
9078 ** <h3>Special sqlite_stat1 Handling</h3>
9079 **
9080 ** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to
9081 ** some of the rules above. In SQLite, the schema of sqlite_stat1 is:
9082 ** <pre>
9083 ** &nbsp; CREATE TABLE sqlite_stat1(tbl,idx,stat)
9084 ** </pre>
9085 **
9086 ** Even though sqlite_stat1 does not have a PRIMARY KEY, changes are
9087 ** recorded for it as if the PRIMARY KEY is (tbl,idx). Additionally, changes
9088 ** are recorded for rows for which (idx IS NULL) is true. However, for such
9089 ** rows a zero-length blob (SQL value X'') is stored in the changeset or
9090 ** patchset instead of a NULL value. This allows such changesets to be
9091 ** manipulated by legacy implementations of sqlite3changeset_invert(),
9092 ** concat() and similar.
9093 **
9094 ** The sqlite3changeset_apply() function automatically converts the
9095 ** zero-length blob back to a NULL value when updating the sqlite_stat1
9096 ** table. However, if the application calls sqlite3changeset_new(),
9097 ** sqlite3changeset_old() or sqlite3changeset_conflict on a changeset
9098 ** iterator directly (including on a changeset iterator passed to a
9099 ** conflict-handler callback) then the X'' value is returned. The application
9100 ** must translate X'' to NULL itself if required.
9101 **
9102 ** Legacy (older than 3.22.0) versions of the sessions module cannot capture
9103 ** changes made to the sqlite_stat1 table. Legacy versions of the
9104 ** sqlite3changeset_apply() function silently ignore any modifications to the
9105 ** sqlite_stat1 table that are part of a changeset or patchset.
9106 */
9107 SQLITE_API int sqlite3session_attach(
9108 sqlite3_session *pSession, /* Session object */
9109 const char *zTab /* Table name */
9110 );
9111

Keyboard Shortcuts

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