Fossil SCM

Update the built-in SQLite to the latest 3.36.0 alpha for testing.

drh 2021-05-14 19:38 trunk
Commit 8b44988df1ce1ead7f96d65a7bc5315c2e74ef69c4c7e814ed6c6549214d0c1a
3 files changed +21 -20 +471 -431 +44 -26
+21 -20
--- src/shell.c
+++ src/shell.c
@@ -4963,14 +4963,15 @@
49634963
sqlite3_value **argv
49644964
){
49654965
Decimal *pA = decimal_new(context, argv[0], 0, 0);
49664966
Decimal *pB = decimal_new(context, argv[1], 0, 0);
49674967
UNUSED_PARAMETER(argc);
4968
- if( pB==0 ) return;
4969
- pB->sign = !pB->sign;
4970
- decimal_add(pA, pB);
4971
- decimal_result(context, pA);
4968
+ if( pB ){
4969
+ pB->sign = !pB->sign;
4970
+ decimal_add(pA, pB);
4971
+ decimal_result(context, pA);
4972
+ }
49724973
decimal_free(pA);
49734974
decimal_free(pB);
49744975
}
49754976
49764977
/* Aggregate funcion: decimal_sum(X)
@@ -14142,12 +14143,12 @@
1414214143
".oom ?--repeat M? ?N? Simulate an OOM error on the N-th allocation",
1414314144
#endif
1414414145
".open ?OPTIONS? ?FILE? Close existing database and reopen FILE",
1414514146
" Options:",
1414614147
" --append Use appendvfs to append database to the end of FILE",
14147
-#ifdef SQLITE_ENABLE_DESERIALIZE
14148
- " --deserialize Load into memory useing sqlite3_deserialize()",
14148
+#ifndef SQLITE_OMIT_DESERIALIZE
14149
+ " --deserialize Load into memory using sqlite3_deserialize()",
1414914150
" --hexdb Load the output of \"dbtotxt\" as an in-memory db",
1415014151
" --maxsize N Maximum size for --hexdb or --deserialized database",
1415114152
#endif
1415214153
" --new Initialize FILE to an empty database",
1415314154
" --nofollow Do not follow symbolic links",
@@ -14464,11 +14465,11 @@
1446414465
}
1446514466
fclose(f);
1446614467
return rc;
1446714468
}
1446814469
14469
-#ifdef SQLITE_ENABLE_DESERIALIZE
14470
+#ifndef SQLITE_OMIT_DESERIALIZE
1447014471
/*
1447114472
** Reconstruct an in-memory database using the output from the "dbtotxt"
1447214473
** program. Read content from the file in p->zDbFilename. If p->zDbFilename
1447314474
** is 0, then read from standard input.
1447414475
*/
@@ -14553,11 +14554,11 @@
1455314554
}
1455414555
sqlite3_free(a);
1455514556
utf8_printf(stderr,"Error on line %d of --hexdb input\n", nLine);
1455614557
return 0;
1455714558
}
14558
-#endif /* SQLITE_ENABLE_DESERIALIZE */
14559
+#endif /* SQLITE_OMIT_DESERIALIZE */
1455914560
1456014561
/*
1456114562
** Scalar function "shell_int32". The first argument to this function
1456214563
** must be a blob. The second a non-negative integer. This function
1456314564
** reads and returns a 32-bit big-endian integer from byte
@@ -14814,11 +14815,11 @@
1481414815
char *zSql = sqlite3_mprintf(
1481514816
"CREATE VIRTUAL TABLE zip USING zipfile(%Q);", p->zDbFilename);
1481614817
sqlite3_exec(p->db, zSql, 0, 0, 0);
1481714818
sqlite3_free(zSql);
1481814819
}
14819
-#ifdef SQLITE_ENABLE_DESERIALIZE
14820
+#ifndef SQLITE_OMIT_DESERIALIZE
1482014821
else
1482114822
if( p->openMode==SHELL_OPEN_DESERIALIZE || p->openMode==SHELL_OPEN_HEXDB ){
1482214823
int rc;
1482314824
int nData = 0;
1482414825
unsigned char *aData;
@@ -16881,10 +16882,11 @@
1688116882
char *zErr = 0;
1688216883
rc = sqlite3_exec(db, zSql, 0, 0, &zErr);
1688316884
if( rc!=SQLITE_OK ){
1688416885
raw_printf(stderr, "SQL error: %s\n", zErr);
1688516886
}
16887
+ sqlite3_free(zErr);
1688616888
*pRc = rc;
1688716889
}
1688816890
}
1688916891
1689016892
/*
@@ -18185,11 +18187,10 @@
1818518187
}
1818618188
}else
1818718189
1818818190
if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
1818918191
ShellState data;
18190
- char *zErrMsg = 0;
1819118192
int doStats = 0;
1819218193
memcpy(&data, p, sizeof(data));
1819318194
data.showHeader = 0;
1819418195
data.cMode = data.mode = MODE_Semi;
1819518196
if( nArg==2 && optionMatch(azArg[1], "indent") ){
@@ -18207,11 +18208,11 @@
1820718208
" (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
1820818209
" FROM sqlite_schema UNION ALL"
1820918210
" SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_schema) "
1821018211
"WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
1821118212
"ORDER BY rowid",
18212
- callback, &data, &zErrMsg
18213
+ callback, &data, 0
1821318214
);
1821418215
if( rc==SQLITE_OK ){
1821518216
sqlite3_stmt *pStmt;
1821618217
rc = sqlite3_prepare_v2(p->db,
1821718218
"SELECT rowid FROM sqlite_schema"
@@ -18223,16 +18224,16 @@
1822318224
if( doStats==0 ){
1822418225
raw_printf(p->out, "/* No STAT tables available */\n");
1822518226
}else{
1822618227
raw_printf(p->out, "ANALYZE sqlite_schema;\n");
1822718228
sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_schema'",
18228
- callback, &data, &zErrMsg);
18229
+ callback, &data, 0);
1822918230
data.cMode = data.mode = MODE_Insert;
1823018231
data.zDestTable = "sqlite_stat1";
18231
- shell_exec(&data, "SELECT * FROM sqlite_stat1", &zErrMsg);
18232
+ shell_exec(&data, "SELECT * FROM sqlite_stat1", 0);
1823218233
data.zDestTable = "sqlite_stat4";
18233
- shell_exec(&data, "SELECT * FROM sqlite_stat4", &zErrMsg);
18234
+ shell_exec(&data, "SELECT * FROM sqlite_stat4", 0);
1823418235
raw_printf(p->out, "ANALYZE sqlite_schema;\n");
1823518236
}
1823618237
}else
1823718238
1823818239
if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){
@@ -18876,18 +18877,18 @@
1887618877
p->openMode = SHELL_OPEN_APPENDVFS;
1887718878
}else if( optionMatch(z, "readonly") ){
1887818879
p->openMode = SHELL_OPEN_READONLY;
1887918880
}else if( optionMatch(z, "nofollow") ){
1888018881
p->openFlags |= SQLITE_OPEN_NOFOLLOW;
18881
-#ifdef SQLITE_ENABLE_DESERIALIZE
18882
+#ifndef SQLITE_OMIT_DESERIALIZE
1888218883
}else if( optionMatch(z, "deserialize") ){
1888318884
p->openMode = SHELL_OPEN_DESERIALIZE;
1888418885
}else if( optionMatch(z, "hexdb") ){
1888518886
p->openMode = SHELL_OPEN_HEXDB;
1888618887
}else if( optionMatch(z, "maxsize") && iName+1<nArg ){
1888718888
p->szMax = integerValue(azArg[++iName]);
18888
-#endif /* SQLITE_ENABLE_DESERIALIZE */
18889
+#endif /* SQLITE_OMIT_DESERIALIZE */
1888918890
}else if( z[0]=='-' ){
1889018891
utf8_printf(stderr, "unknown option: %s\n", z);
1889118892
rc = 1;
1889218893
goto meta_command_exit;
1889318894
}else if( zNewFilename ){
@@ -20867,11 +20868,11 @@
2086720868
" -batch force batch I/O\n"
2086820869
" -box set output mode to 'box'\n"
2086920870
" -column set output mode to 'column'\n"
2087020871
" -cmd COMMAND run \"COMMAND\" before reading stdin\n"
2087120872
" -csv set output mode to 'csv'\n"
20872
-#if defined(SQLITE_ENABLE_DESERIALIZE)
20873
+#if !defined(SQLITE_OMIT_DESERIALIZE)
2087320874
" -deserialize open the database using sqlite3_deserialize()\n"
2087420875
#endif
2087520876
" -echo print commands before execution\n"
2087620877
" -init FILENAME read/process named file\n"
2087720878
" -[no]header turn headers on or off\n"
@@ -20884,11 +20885,11 @@
2088420885
" -json set output mode to 'json'\n"
2088520886
" -line set output mode to 'line'\n"
2088620887
" -list set output mode to 'list'\n"
2088720888
" -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
2088820889
" -markdown set output mode to 'markdown'\n"
20889
-#if defined(SQLITE_ENABLE_DESERIALIZE)
20890
+#if !defined(SQLITE_OMIT_DESERIALIZE)
2089020891
" -maxsize N maximum size for a --deserialize database\n"
2089120892
#endif
2089220893
" -memtrace trace all memory allocations and deallocations\n"
2089320894
" -mmap N default mmap size set to N\n"
2089420895
#ifdef SQLITE_ENABLE_MULTIPLEX
@@ -21214,11 +21215,11 @@
2121421215
}else if( strcmp(z,"-zip")==0 ){
2121521216
data.openMode = SHELL_OPEN_ZIPFILE;
2121621217
#endif
2121721218
}else if( strcmp(z,"-append")==0 ){
2121821219
data.openMode = SHELL_OPEN_APPENDVFS;
21219
-#ifdef SQLITE_ENABLE_DESERIALIZE
21220
+#ifndef SQLITE_OMIT_DESERIALIZE
2122021221
}else if( strcmp(z,"-deserialize")==0 ){
2122121222
data.openMode = SHELL_OPEN_DESERIALIZE;
2122221223
}else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
2122321224
data.szMax = integerValue(argv[++i]);
2122421225
#endif
@@ -21331,11 +21332,11 @@
2133121332
}else if( strcmp(z,"-zip")==0 ){
2133221333
data.openMode = SHELL_OPEN_ZIPFILE;
2133321334
#endif
2133421335
}else if( strcmp(z,"-append")==0 ){
2133521336
data.openMode = SHELL_OPEN_APPENDVFS;
21336
-#ifdef SQLITE_ENABLE_DESERIALIZE
21337
+#ifndef SQLITE_OMIT_DESERIALIZE
2133721338
}else if( strcmp(z,"-deserialize")==0 ){
2133821339
data.openMode = SHELL_OPEN_DESERIALIZE;
2133921340
}else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
2134021341
data.szMax = integerValue(argv[++i]);
2134121342
#endif
2134221343
--- src/shell.c
+++ src/shell.c
@@ -4963,14 +4963,15 @@
4963 sqlite3_value **argv
4964 ){
4965 Decimal *pA = decimal_new(context, argv[0], 0, 0);
4966 Decimal *pB = decimal_new(context, argv[1], 0, 0);
4967 UNUSED_PARAMETER(argc);
4968 if( pB==0 ) return;
4969 pB->sign = !pB->sign;
4970 decimal_add(pA, pB);
4971 decimal_result(context, pA);
 
4972 decimal_free(pA);
4973 decimal_free(pB);
4974 }
4975
4976 /* Aggregate funcion: decimal_sum(X)
@@ -14142,12 +14143,12 @@
14142 ".oom ?--repeat M? ?N? Simulate an OOM error on the N-th allocation",
14143 #endif
14144 ".open ?OPTIONS? ?FILE? Close existing database and reopen FILE",
14145 " Options:",
14146 " --append Use appendvfs to append database to the end of FILE",
14147 #ifdef SQLITE_ENABLE_DESERIALIZE
14148 " --deserialize Load into memory useing sqlite3_deserialize()",
14149 " --hexdb Load the output of \"dbtotxt\" as an in-memory db",
14150 " --maxsize N Maximum size for --hexdb or --deserialized database",
14151 #endif
14152 " --new Initialize FILE to an empty database",
14153 " --nofollow Do not follow symbolic links",
@@ -14464,11 +14465,11 @@
14464 }
14465 fclose(f);
14466 return rc;
14467 }
14468
14469 #ifdef SQLITE_ENABLE_DESERIALIZE
14470 /*
14471 ** Reconstruct an in-memory database using the output from the "dbtotxt"
14472 ** program. Read content from the file in p->zDbFilename. If p->zDbFilename
14473 ** is 0, then read from standard input.
14474 */
@@ -14553,11 +14554,11 @@
14553 }
14554 sqlite3_free(a);
14555 utf8_printf(stderr,"Error on line %d of --hexdb input\n", nLine);
14556 return 0;
14557 }
14558 #endif /* SQLITE_ENABLE_DESERIALIZE */
14559
14560 /*
14561 ** Scalar function "shell_int32". The first argument to this function
14562 ** must be a blob. The second a non-negative integer. This function
14563 ** reads and returns a 32-bit big-endian integer from byte
@@ -14814,11 +14815,11 @@
14814 char *zSql = sqlite3_mprintf(
14815 "CREATE VIRTUAL TABLE zip USING zipfile(%Q);", p->zDbFilename);
14816 sqlite3_exec(p->db, zSql, 0, 0, 0);
14817 sqlite3_free(zSql);
14818 }
14819 #ifdef SQLITE_ENABLE_DESERIALIZE
14820 else
14821 if( p->openMode==SHELL_OPEN_DESERIALIZE || p->openMode==SHELL_OPEN_HEXDB ){
14822 int rc;
14823 int nData = 0;
14824 unsigned char *aData;
@@ -16881,10 +16882,11 @@
16881 char *zErr = 0;
16882 rc = sqlite3_exec(db, zSql, 0, 0, &zErr);
16883 if( rc!=SQLITE_OK ){
16884 raw_printf(stderr, "SQL error: %s\n", zErr);
16885 }
 
16886 *pRc = rc;
16887 }
16888 }
16889
16890 /*
@@ -18185,11 +18187,10 @@
18185 }
18186 }else
18187
18188 if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
18189 ShellState data;
18190 char *zErrMsg = 0;
18191 int doStats = 0;
18192 memcpy(&data, p, sizeof(data));
18193 data.showHeader = 0;
18194 data.cMode = data.mode = MODE_Semi;
18195 if( nArg==2 && optionMatch(azArg[1], "indent") ){
@@ -18207,11 +18208,11 @@
18207 " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
18208 " FROM sqlite_schema UNION ALL"
18209 " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_schema) "
18210 "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
18211 "ORDER BY rowid",
18212 callback, &data, &zErrMsg
18213 );
18214 if( rc==SQLITE_OK ){
18215 sqlite3_stmt *pStmt;
18216 rc = sqlite3_prepare_v2(p->db,
18217 "SELECT rowid FROM sqlite_schema"
@@ -18223,16 +18224,16 @@
18223 if( doStats==0 ){
18224 raw_printf(p->out, "/* No STAT tables available */\n");
18225 }else{
18226 raw_printf(p->out, "ANALYZE sqlite_schema;\n");
18227 sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_schema'",
18228 callback, &data, &zErrMsg);
18229 data.cMode = data.mode = MODE_Insert;
18230 data.zDestTable = "sqlite_stat1";
18231 shell_exec(&data, "SELECT * FROM sqlite_stat1", &zErrMsg);
18232 data.zDestTable = "sqlite_stat4";
18233 shell_exec(&data, "SELECT * FROM sqlite_stat4", &zErrMsg);
18234 raw_printf(p->out, "ANALYZE sqlite_schema;\n");
18235 }
18236 }else
18237
18238 if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){
@@ -18876,18 +18877,18 @@
18876 p->openMode = SHELL_OPEN_APPENDVFS;
18877 }else if( optionMatch(z, "readonly") ){
18878 p->openMode = SHELL_OPEN_READONLY;
18879 }else if( optionMatch(z, "nofollow") ){
18880 p->openFlags |= SQLITE_OPEN_NOFOLLOW;
18881 #ifdef SQLITE_ENABLE_DESERIALIZE
18882 }else if( optionMatch(z, "deserialize") ){
18883 p->openMode = SHELL_OPEN_DESERIALIZE;
18884 }else if( optionMatch(z, "hexdb") ){
18885 p->openMode = SHELL_OPEN_HEXDB;
18886 }else if( optionMatch(z, "maxsize") && iName+1<nArg ){
18887 p->szMax = integerValue(azArg[++iName]);
18888 #endif /* SQLITE_ENABLE_DESERIALIZE */
18889 }else if( z[0]=='-' ){
18890 utf8_printf(stderr, "unknown option: %s\n", z);
18891 rc = 1;
18892 goto meta_command_exit;
18893 }else if( zNewFilename ){
@@ -20867,11 +20868,11 @@
20867 " -batch force batch I/O\n"
20868 " -box set output mode to 'box'\n"
20869 " -column set output mode to 'column'\n"
20870 " -cmd COMMAND run \"COMMAND\" before reading stdin\n"
20871 " -csv set output mode to 'csv'\n"
20872 #if defined(SQLITE_ENABLE_DESERIALIZE)
20873 " -deserialize open the database using sqlite3_deserialize()\n"
20874 #endif
20875 " -echo print commands before execution\n"
20876 " -init FILENAME read/process named file\n"
20877 " -[no]header turn headers on or off\n"
@@ -20884,11 +20885,11 @@
20884 " -json set output mode to 'json'\n"
20885 " -line set output mode to 'line'\n"
20886 " -list set output mode to 'list'\n"
20887 " -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
20888 " -markdown set output mode to 'markdown'\n"
20889 #if defined(SQLITE_ENABLE_DESERIALIZE)
20890 " -maxsize N maximum size for a --deserialize database\n"
20891 #endif
20892 " -memtrace trace all memory allocations and deallocations\n"
20893 " -mmap N default mmap size set to N\n"
20894 #ifdef SQLITE_ENABLE_MULTIPLEX
@@ -21214,11 +21215,11 @@
21214 }else if( strcmp(z,"-zip")==0 ){
21215 data.openMode = SHELL_OPEN_ZIPFILE;
21216 #endif
21217 }else if( strcmp(z,"-append")==0 ){
21218 data.openMode = SHELL_OPEN_APPENDVFS;
21219 #ifdef SQLITE_ENABLE_DESERIALIZE
21220 }else if( strcmp(z,"-deserialize")==0 ){
21221 data.openMode = SHELL_OPEN_DESERIALIZE;
21222 }else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
21223 data.szMax = integerValue(argv[++i]);
21224 #endif
@@ -21331,11 +21332,11 @@
21331 }else if( strcmp(z,"-zip")==0 ){
21332 data.openMode = SHELL_OPEN_ZIPFILE;
21333 #endif
21334 }else if( strcmp(z,"-append")==0 ){
21335 data.openMode = SHELL_OPEN_APPENDVFS;
21336 #ifdef SQLITE_ENABLE_DESERIALIZE
21337 }else if( strcmp(z,"-deserialize")==0 ){
21338 data.openMode = SHELL_OPEN_DESERIALIZE;
21339 }else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
21340 data.szMax = integerValue(argv[++i]);
21341 #endif
21342
--- src/shell.c
+++ src/shell.c
@@ -4963,14 +4963,15 @@
4963 sqlite3_value **argv
4964 ){
4965 Decimal *pA = decimal_new(context, argv[0], 0, 0);
4966 Decimal *pB = decimal_new(context, argv[1], 0, 0);
4967 UNUSED_PARAMETER(argc);
4968 if( pB ){
4969 pB->sign = !pB->sign;
4970 decimal_add(pA, pB);
4971 decimal_result(context, pA);
4972 }
4973 decimal_free(pA);
4974 decimal_free(pB);
4975 }
4976
4977 /* Aggregate funcion: decimal_sum(X)
@@ -14142,12 +14143,12 @@
14143 ".oom ?--repeat M? ?N? Simulate an OOM error on the N-th allocation",
14144 #endif
14145 ".open ?OPTIONS? ?FILE? Close existing database and reopen FILE",
14146 " Options:",
14147 " --append Use appendvfs to append database to the end of FILE",
14148 #ifndef SQLITE_OMIT_DESERIALIZE
14149 " --deserialize Load into memory using sqlite3_deserialize()",
14150 " --hexdb Load the output of \"dbtotxt\" as an in-memory db",
14151 " --maxsize N Maximum size for --hexdb or --deserialized database",
14152 #endif
14153 " --new Initialize FILE to an empty database",
14154 " --nofollow Do not follow symbolic links",
@@ -14464,11 +14465,11 @@
14465 }
14466 fclose(f);
14467 return rc;
14468 }
14469
14470 #ifndef SQLITE_OMIT_DESERIALIZE
14471 /*
14472 ** Reconstruct an in-memory database using the output from the "dbtotxt"
14473 ** program. Read content from the file in p->zDbFilename. If p->zDbFilename
14474 ** is 0, then read from standard input.
14475 */
@@ -14553,11 +14554,11 @@
14554 }
14555 sqlite3_free(a);
14556 utf8_printf(stderr,"Error on line %d of --hexdb input\n", nLine);
14557 return 0;
14558 }
14559 #endif /* SQLITE_OMIT_DESERIALIZE */
14560
14561 /*
14562 ** Scalar function "shell_int32". The first argument to this function
14563 ** must be a blob. The second a non-negative integer. This function
14564 ** reads and returns a 32-bit big-endian integer from byte
@@ -14814,11 +14815,11 @@
14815 char *zSql = sqlite3_mprintf(
14816 "CREATE VIRTUAL TABLE zip USING zipfile(%Q);", p->zDbFilename);
14817 sqlite3_exec(p->db, zSql, 0, 0, 0);
14818 sqlite3_free(zSql);
14819 }
14820 #ifndef SQLITE_OMIT_DESERIALIZE
14821 else
14822 if( p->openMode==SHELL_OPEN_DESERIALIZE || p->openMode==SHELL_OPEN_HEXDB ){
14823 int rc;
14824 int nData = 0;
14825 unsigned char *aData;
@@ -16881,10 +16882,11 @@
16882 char *zErr = 0;
16883 rc = sqlite3_exec(db, zSql, 0, 0, &zErr);
16884 if( rc!=SQLITE_OK ){
16885 raw_printf(stderr, "SQL error: %s\n", zErr);
16886 }
16887 sqlite3_free(zErr);
16888 *pRc = rc;
16889 }
16890 }
16891
16892 /*
@@ -18185,11 +18187,10 @@
18187 }
18188 }else
18189
18190 if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
18191 ShellState data;
 
18192 int doStats = 0;
18193 memcpy(&data, p, sizeof(data));
18194 data.showHeader = 0;
18195 data.cMode = data.mode = MODE_Semi;
18196 if( nArg==2 && optionMatch(azArg[1], "indent") ){
@@ -18207,11 +18208,11 @@
18208 " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
18209 " FROM sqlite_schema UNION ALL"
18210 " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_schema) "
18211 "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
18212 "ORDER BY rowid",
18213 callback, &data, 0
18214 );
18215 if( rc==SQLITE_OK ){
18216 sqlite3_stmt *pStmt;
18217 rc = sqlite3_prepare_v2(p->db,
18218 "SELECT rowid FROM sqlite_schema"
@@ -18223,16 +18224,16 @@
18224 if( doStats==0 ){
18225 raw_printf(p->out, "/* No STAT tables available */\n");
18226 }else{
18227 raw_printf(p->out, "ANALYZE sqlite_schema;\n");
18228 sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_schema'",
18229 callback, &data, 0);
18230 data.cMode = data.mode = MODE_Insert;
18231 data.zDestTable = "sqlite_stat1";
18232 shell_exec(&data, "SELECT * FROM sqlite_stat1", 0);
18233 data.zDestTable = "sqlite_stat4";
18234 shell_exec(&data, "SELECT * FROM sqlite_stat4", 0);
18235 raw_printf(p->out, "ANALYZE sqlite_schema;\n");
18236 }
18237 }else
18238
18239 if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){
@@ -18876,18 +18877,18 @@
18877 p->openMode = SHELL_OPEN_APPENDVFS;
18878 }else if( optionMatch(z, "readonly") ){
18879 p->openMode = SHELL_OPEN_READONLY;
18880 }else if( optionMatch(z, "nofollow") ){
18881 p->openFlags |= SQLITE_OPEN_NOFOLLOW;
18882 #ifndef SQLITE_OMIT_DESERIALIZE
18883 }else if( optionMatch(z, "deserialize") ){
18884 p->openMode = SHELL_OPEN_DESERIALIZE;
18885 }else if( optionMatch(z, "hexdb") ){
18886 p->openMode = SHELL_OPEN_HEXDB;
18887 }else if( optionMatch(z, "maxsize") && iName+1<nArg ){
18888 p->szMax = integerValue(azArg[++iName]);
18889 #endif /* SQLITE_OMIT_DESERIALIZE */
18890 }else if( z[0]=='-' ){
18891 utf8_printf(stderr, "unknown option: %s\n", z);
18892 rc = 1;
18893 goto meta_command_exit;
18894 }else if( zNewFilename ){
@@ -20867,11 +20868,11 @@
20868 " -batch force batch I/O\n"
20869 " -box set output mode to 'box'\n"
20870 " -column set output mode to 'column'\n"
20871 " -cmd COMMAND run \"COMMAND\" before reading stdin\n"
20872 " -csv set output mode to 'csv'\n"
20873 #if !defined(SQLITE_OMIT_DESERIALIZE)
20874 " -deserialize open the database using sqlite3_deserialize()\n"
20875 #endif
20876 " -echo print commands before execution\n"
20877 " -init FILENAME read/process named file\n"
20878 " -[no]header turn headers on or off\n"
@@ -20884,11 +20885,11 @@
20885 " -json set output mode to 'json'\n"
20886 " -line set output mode to 'line'\n"
20887 " -list set output mode to 'list'\n"
20888 " -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
20889 " -markdown set output mode to 'markdown'\n"
20890 #if !defined(SQLITE_OMIT_DESERIALIZE)
20891 " -maxsize N maximum size for a --deserialize database\n"
20892 #endif
20893 " -memtrace trace all memory allocations and deallocations\n"
20894 " -mmap N default mmap size set to N\n"
20895 #ifdef SQLITE_ENABLE_MULTIPLEX
@@ -21214,11 +21215,11 @@
21215 }else if( strcmp(z,"-zip")==0 ){
21216 data.openMode = SHELL_OPEN_ZIPFILE;
21217 #endif
21218 }else if( strcmp(z,"-append")==0 ){
21219 data.openMode = SHELL_OPEN_APPENDVFS;
21220 #ifndef SQLITE_OMIT_DESERIALIZE
21221 }else if( strcmp(z,"-deserialize")==0 ){
21222 data.openMode = SHELL_OPEN_DESERIALIZE;
21223 }else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
21224 data.szMax = integerValue(argv[++i]);
21225 #endif
@@ -21331,11 +21332,11 @@
21332 }else if( strcmp(z,"-zip")==0 ){
21333 data.openMode = SHELL_OPEN_ZIPFILE;
21334 #endif
21335 }else if( strcmp(z,"-append")==0 ){
21336 data.openMode = SHELL_OPEN_APPENDVFS;
21337 #ifndef SQLITE_OMIT_DESERIALIZE
21338 }else if( strcmp(z,"-deserialize")==0 ){
21339 data.openMode = SHELL_OPEN_DESERIALIZE;
21340 }else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
21341 data.szMax = integerValue(argv[++i]);
21342 #endif
21343
+471 -431
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1186,11 +1186,11 @@
11861186
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11871187
** [sqlite_version()] and [sqlite_source_id()].
11881188
*/
11891189
#define SQLITE_VERSION "3.36.0"
11901190
#define SQLITE_VERSION_NUMBER 3036000
1191
-#define SQLITE_SOURCE_ID "2021-04-28 17:37:26 65ec39f0f092fe29e1d4e9e96cf07a73d2ef7ce2c41b6f1cd3ab23546ada0e67"
1191
+#define SQLITE_SOURCE_ID "2021-05-14 15:37:00 cf63abbe559d04f993f99a37d41ba4a97c0261094f1d4cc05cfa23b1e11731f5"
11921192
11931193
/*
11941194
** CAPI3REF: Run-Time Library Version Numbers
11951195
** KEYWORDS: sqlite3_version sqlite3_sourceid
11961196
**
@@ -2202,10 +2202,14 @@
22022202
** currently has an SQL transaction open on the database. It is set to 0 if
22032203
** the database is not a wal-mode db, or if there is no such connection in any
22042204
** other process. This opcode cannot be used to detect transactions opened
22052205
** by clients within the current process, only within other processes.
22062206
** </ul>
2207
+**
2208
+** <li>[[SQLITE_FCNTL_CKSM_FILE]]
2209
+** Used by the cksmvfs VFS module only.
2210
+** </ul>
22072211
*/
22082212
#define SQLITE_FCNTL_LOCKSTATE 1
22092213
#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
22102214
#define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
22112215
#define SQLITE_FCNTL_LAST_ERRNO 4
@@ -2241,12 +2245,12 @@
22412245
#define SQLITE_FCNTL_DATA_VERSION 35
22422246
#define SQLITE_FCNTL_SIZE_LIMIT 36
22432247
#define SQLITE_FCNTL_CKPT_DONE 37
22442248
#define SQLITE_FCNTL_RESERVE_BYTES 38
22452249
#define SQLITE_FCNTL_CKPT_START 39
2246
-
22472250
#define SQLITE_FCNTL_EXTERNAL_READER 40
2251
+#define SQLITE_FCNTL_CKSM_FILE 41
22482252
22492253
/* deprecated names */
22502254
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
22512255
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
22522256
#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -5255,10 +5259,19 @@
52555259
** changes to the content of the database files on disk.
52565260
** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
52575261
** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
52585262
** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
52595263
** sqlite3_stmt_readonly() returns false for those commands.
5264
+**
5265
+** ^This routine returns false if there is any possibility that the
5266
+** statement might change the database file. ^A false return does
5267
+** not guarantee that the statement will change the database file.
5268
+** ^For example, an UPDATE statement might have a WHERE clause that
5269
+** makes it a no-op, but the sqlite3_stmt_readonly() result would still
5270
+** be false. ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a
5271
+** read-only no-op if the table already exists, but
5272
+** sqlite3_stmt_readonly() still returns false for such a statement.
52605273
*/
52615274
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
52625275
52635276
/*
52645277
** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
@@ -5424,22 +5437,26 @@
54245437
** terminated. If any NUL characters occurs at byte offsets less than
54255438
** the value of the fourth parameter then the resulting string value will
54265439
** contain embedded NULs. The result of expressions involving strings
54275440
** with embedded NULs is undefined.
54285441
**
5429
-** ^The fifth argument to the BLOB and string binding interfaces
5430
-** is a destructor used to dispose of the BLOB or
5431
-** string after SQLite has finished with it. ^The destructor is called
5432
-** to dispose of the BLOB or string even if the call to the bind API fails,
5433
-** except the destructor is not called if the third parameter is a NULL
5434
-** pointer or the fourth parameter is negative.
5435
-** ^If the fifth argument is
5436
-** the special value [SQLITE_STATIC], then SQLite assumes that the
5437
-** information is in static, unmanaged space and does not need to be freed.
5438
-** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
5439
-** SQLite makes its own private copy of the data immediately, before
5440
-** the sqlite3_bind_*() routine returns.
5442
+** ^The fifth argument to the BLOB and string binding interfaces controls
5443
+** or indicates the lifetime of the object referenced by the third parameter.
5444
+** ^These three options exist:
5445
+** ^(1) A destructor to dispose of the BLOB or string after SQLite has finished
5446
+** with it may be passed. ^It is called to dispose of the BLOB or string even
5447
+** if the call to the bind API fails, except the destructor is not called if
5448
+** the third parameter is a NULL pointer or the fourth parameter is negative.
5449
+** ^(2) The special constant, [SQLITE_STATIC], may be passsed to indicate that
5450
+** the application remains responsible for disposing of the object. ^In this
5451
+** case, the object and the provided pointer to it must remain valid until
5452
+** either the prepared statement is finalized or the same SQL parameter is
5453
+** bound to something else, whichever occurs sooner.
5454
+** ^(3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the
5455
+** object is to be copied prior to the return from sqlite3_bind_*(). ^The
5456
+** object and pointer to it must remain valid until then. ^SQLite will then
5457
+** manage the lifetime of its private copy.
54415458
**
54425459
** ^The sixth argument to sqlite3_bind_text64() must be one of
54435460
** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
54445461
** to specify the encoding of the text in the third parameter. If
54455462
** the sixth argument to sqlite3_bind_text64() is not one of the
@@ -10875,12 +10892,12 @@
1087510892
**
1087610893
** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the
1087710894
** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory
1087810895
** allocation error occurs.
1087910896
**
10880
-** This interface is only available if SQLite is compiled with the
10881
-** [SQLITE_ENABLE_DESERIALIZE] option.
10897
+** This interface is omitted if SQLite is compiled with the
10898
+** [SQLITE_OMIT_DESERIALIZE] option.
1088210899
*/
1088310900
SQLITE_API unsigned char *sqlite3_serialize(
1088410901
sqlite3 *db, /* The database connection */
1088510902
const char *zSchema, /* Which DB to serialize. ex: "main", "temp", ... */
1088610903
sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */
@@ -10927,12 +10944,12 @@
1092710944
**
1092810945
** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the
1092910946
** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then
1093010947
** [sqlite3_free()] is invoked on argument P prior to returning.
1093110948
**
10932
-** This interface is only available if SQLite is compiled with the
10933
-** [SQLITE_ENABLE_DESERIALIZE] option.
10949
+** This interface is omitted if SQLite is compiled with the
10950
+** [SQLITE_OMIT_DESERIALIZE] option.
1093410951
*/
1093510952
SQLITE_API int sqlite3_deserialize(
1093610953
sqlite3 *db, /* The database connection */
1093710954
const char *zSchema, /* Which DB to reopen with the deserialization */
1093810955
unsigned char *pData, /* The serialized database content */
@@ -11184,18 +11201,15 @@
1118411201
** METHOD: sqlite3_session
1118511202
**
1118611203
** This method is used to configure a session object after it has been
1118711204
** created. At present the only valid value for the second parameter is
1118811205
** [SQLITE_SESSION_OBJCONFIG_SIZE].
11189
-*/
11190
-SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
11191
-
11192
-/*
11193
-** CAPI3REF: Arguments for sqlite3session_object_config()
11206
+**
11207
+** Arguments for sqlite3session_object_config()
1119411208
**
1119511209
** The following values may passed as the the 4th parameter to
11196
-** [sqlite3session_object_config].
11210
+** sqlite3session_object_config().
1119711211
**
1119811212
** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
1119911213
** This option is used to set, clear or query the flag that enables
1120011214
** the [sqlite3session_changeset_size()] API. Because it imposes some
1120111215
** computational overhead, this API is disabled by default. Argument
@@ -11206,10 +11220,14 @@
1120611220
** variable is set to 1 if the sqlite3session_changeset_size() API is
1120711221
** enabled following the current call, or 0 otherwise.
1120811222
**
1120911223
** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
1121011224
** the first table has been attached to the session object.
11225
+*/
11226
+SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
11227
+
11228
+/*
1121111229
*/
1121211230
#define SQLITE_SESSION_OBJCONFIG_SIZE 1
1121311231
1121411232
/*
1121511233
** CAPI3REF: Enable Or Disable A Session Object
@@ -11454,15 +11472,15 @@
1145411472
void **ppChangeset /* OUT: Buffer containing changeset */
1145511473
);
1145611474
1145711475
/*
1145811476
** CAPI3REF: Return An Upper-limit For The Size Of The Changeset
11459
-** METHOD: sqlite3session_changeset_size()
11477
+** METHOD: sqlite3_session
1146011478
**
1146111479
** By default, this function always returns 0. For it to return
1146211480
** a useful result, the sqlite3_session object must have been configured
11463
-** to enable this API using [sqlite3session_object_config()] with the
11481
+** to enable this API using sqlite3session_object_config() with the
1146411482
** SQLITE_SESSION_OBJCONFIG_SIZE verb.
1146511483
**
1146611484
** When enabled, this function returns an upper limit, in bytes, for the size
1146711485
** of the changeset that might be produced if sqlite3session_changeset() were
1146811486
** called. The final changeset size might be equal to or smaller than the
@@ -17276,11 +17294,10 @@
1727617294
#define SQLITE_PushDown 0x00001000 /* The push-down optimization */
1727717295
#define SQLITE_SimplifyJoin 0x00002000 /* Convert LEFT JOIN to JOIN */
1727817296
#define SQLITE_SkipScan 0x00004000 /* Skip-scans */
1727917297
#define SQLITE_PropagateConst 0x00008000 /* The constant propagation opt */
1728017298
#define SQLITE_MinMaxOpt 0x00010000 /* The min/max optimization */
17281
-#define SQLITE_ExistsToIN 0x00020000 /* The EXISTS-to-IN optimization */
1728217299
#define SQLITE_AllOpts 0xffffffff /* All optimizations */
1728317300
1728417301
/*
1728517302
** Macros for testing whether or not optimizations are enabled or disabled.
1728617303
*/
@@ -19339,11 +19356,11 @@
1933919356
** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE.
1934019357
*/
1934119358
void (*xVdbeBranch)(void*,unsigned iSrcLine,u8 eThis,u8 eMx); /* Callback */
1934219359
void *pVdbeBranchArg; /* 1st argument */
1934319360
#endif
19344
-#ifdef SQLITE_ENABLE_DESERIALIZE
19361
+#ifndef SQLITE_OMIT_DESERIALIZE
1934519362
sqlite3_int64 mxMemdbSize; /* Default max memdb size */
1934619363
#endif
1934719364
#ifndef SQLITE_UNTESTABLE
1934819365
int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
1934919366
#endif
@@ -20235,11 +20252,11 @@
2023520252
2023620253
#if defined(SQLITE_NEED_ERR_NAME)
2023720254
SQLITE_PRIVATE const char *sqlite3ErrName(int);
2023820255
#endif
2023920256
20240
-#ifdef SQLITE_ENABLE_DESERIALIZE
20257
+#ifndef SQLITE_OMIT_DESERIALIZE
2024120258
SQLITE_PRIVATE int sqlite3MemdbInit(void);
2024220259
#endif
2024320260
2024420261
SQLITE_PRIVATE const char *sqlite3ErrStr(int);
2024520262
SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
@@ -20997,11 +21014,11 @@
2099721014
#endif
2099821015
#ifdef SQLITE_VDBE_COVERAGE
2099921016
0, /* xVdbeBranch */
2100021017
0, /* pVbeBranchArg */
2100121018
#endif
21002
-#ifdef SQLITE_ENABLE_DESERIALIZE
21019
+#ifndef SQLITE_OMIT_DESERIALIZE
2100321020
SQLITE_MEMDB_DEFAULT_MAXSIZE, /* mxMemdbSize */
2100421021
#endif
2100521022
#ifndef SQLITE_UNTESTABLE
2100621023
0, /* xTestCallback */
2100721024
#endif
@@ -48428,35 +48445,92 @@
4842848445
**
4842948446
** This file also implements interface sqlite3_serialize() and
4843048447
** sqlite3_deserialize().
4843148448
*/
4843248449
/* #include "sqliteInt.h" */
48433
-#ifdef SQLITE_ENABLE_DESERIALIZE
48450
+#ifndef SQLITE_OMIT_DESERIALIZE
4843448451
4843548452
/*
4843648453
** Forward declaration of objects used by this utility
4843748454
*/
4843848455
typedef struct sqlite3_vfs MemVfs;
4843948456
typedef struct MemFile MemFile;
48457
+typedef struct MemStore MemStore;
4844048458
4844148459
/* Access to a lower-level VFS that (might) implement dynamic loading,
4844248460
** access to randomness, etc.
4844348461
*/
4844448462
#define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
4844548463
48446
-/* An open file */
48447
-struct MemFile {
48448
- sqlite3_file base; /* IO methods */
48464
+/* Storage for a memdb file.
48465
+**
48466
+** An memdb object can be shared or separate. Shared memdb objects can be
48467
+** used by more than one database connection. Mutexes are used by shared
48468
+** memdb objects to coordinate access. Separate memdb objects are only
48469
+** connected to a single database connection and do not require additional
48470
+** mutexes.
48471
+**
48472
+** Shared memdb objects have .zFName!=0 and .pMutex!=0. They are created
48473
+** using "file:/name?vfs=memdb". The first character of the name must be
48474
+** "/" or else the object will be a separate memdb object. All shared
48475
+** memdb objects are stored in memdb_g.apMemStore[] in an arbitrary order.
48476
+**
48477
+** Separate memdb objects are created using a name that does not begin
48478
+** with "/" or using sqlite3_deserialize().
48479
+**
48480
+** Access rules for shared MemStore objects:
48481
+**
48482
+** * .zFName is initialized when the object is created and afterwards
48483
+** is unchanged until the object is destroyed. So it can be accessed
48484
+** at any time as long as we know the object is not being destroyed,
48485
+** which means while either the SQLITE_MUTEX_STATIC_VFS1 or
48486
+** .pMutex is held or the object is not part of memdb_g.apMemStore[].
48487
+**
48488
+** * Can .pMutex can only be changed while holding the
48489
+** SQLITE_MUTEX_STATIC_VFS1 mutex or while the object is not part
48490
+** of memdb_g.apMemStore[].
48491
+**
48492
+** * Other fields can only be changed while holding the .pMutex mutex
48493
+** or when the .nRef is less than zero and the object is not part of
48494
+** memdb_g.apMemStore[].
48495
+**
48496
+** * The .aData pointer has the added requirement that it can can only
48497
+** be changed (for resizing) when nMmap is zero.
48498
+**
48499
+*/
48500
+struct MemStore {
4844948501
sqlite3_int64 sz; /* Size of the file */
4845048502
sqlite3_int64 szAlloc; /* Space allocated to aData */
4845148503
sqlite3_int64 szMax; /* Maximum allowed size of the file */
4845248504
unsigned char *aData; /* content of the file */
48505
+ sqlite3_mutex *pMutex; /* Used by shared stores only */
4845348506
int nMmap; /* Number of memory mapped pages */
4845448507
unsigned mFlags; /* Flags */
48508
+ int nRdLock; /* Number of readers */
48509
+ int nWrLock; /* Number of writers. (Always 0 or 1) */
48510
+ int nRef; /* Number of users of this MemStore */
48511
+ char *zFName; /* The filename for shared stores */
48512
+};
48513
+
48514
+/* An open file */
48515
+struct MemFile {
48516
+ sqlite3_file base; /* IO methods */
48517
+ MemStore *pStore; /* The storage */
4845548518
int eLock; /* Most recent lock against this file */
4845648519
};
4845748520
48521
+/*
48522
+** Global variables for holding the memdb files that are accessible
48523
+** to multiple database connections in separate threads.
48524
+**
48525
+** Must hold SQLITE_MUTEX_STATIC_VFS1 to access any part of this object.
48526
+*/
48527
+struct MemFS {
48528
+ int nMemStore; /* Number of shared MemStore objects */
48529
+ MemStore **apMemStore; /* Array of all shared MemStore objects */
48530
+} memdb_g;
48531
+
4845848532
/*
4845948533
** Methods for MemFile
4846048534
*/
4846148535
static int memdbClose(sqlite3_file*);
4846248536
static int memdbRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
@@ -48531,23 +48605,62 @@
4853148605
0, /* xShmUnmap */
4853248606
memdbFetch, /* xFetch */
4853348607
memdbUnfetch /* xUnfetch */
4853448608
};
4853548609
48610
+/*
48611
+** Enter/leave the mutex on a MemStore
48612
+*/
48613
+static void memdbEnter(MemStore *p){
48614
+ sqlite3_mutex_enter(p->pMutex);
48615
+}
48616
+static void memdbLeave(MemStore *p){
48617
+ sqlite3_mutex_leave(p->pMutex);
48618
+}
48619
+
4853648620
4853748621
4853848622
/*
4853948623
** Close an memdb-file.
48540
-**
48541
-** The pData pointer is owned by the application, so there is nothing
48542
-** to free. Unless the SQLITE_DESERIALIZE_FREEONCLOSE flag is set,
48543
-** in which case we own the pData pointer and need to free it.
48624
+** Free the underlying MemStore object when its refcount drops to zero
48625
+** or less.
4854448626
*/
4854548627
static int memdbClose(sqlite3_file *pFile){
48546
- MemFile *p = (MemFile *)pFile;
48547
- if( p->mFlags & SQLITE_DESERIALIZE_FREEONCLOSE ){
48548
- sqlite3_free(p->aData);
48628
+ MemStore *p = ((MemFile*)pFile)->pStore;
48629
+ if( p->zFName ){
48630
+ int i;
48631
+#ifndef SQLITE_MUTEX_OMIT
48632
+ sqlite3_mutex *pVfsMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
48633
+#endif
48634
+ sqlite3_mutex_enter(pVfsMutex);
48635
+ for(i=0; ALWAYS(i<memdb_g.nMemStore); i++){
48636
+ if( memdb_g.apMemStore[i]==p ){
48637
+ memdbEnter(p);
48638
+ if( p->nRef==1 ){
48639
+ memdb_g.apMemStore[i] = memdb_g.apMemStore[--memdb_g.nMemStore];
48640
+ if( memdb_g.nMemStore==0 ){
48641
+ sqlite3_free(memdb_g.apMemStore);
48642
+ memdb_g.apMemStore = 0;
48643
+ }
48644
+ }
48645
+ break;
48646
+ }
48647
+ }
48648
+ sqlite3_mutex_leave(pVfsMutex);
48649
+ }else{
48650
+ memdbEnter(p);
48651
+ }
48652
+ p->nRef--;
48653
+ if( p->nRef<=0 ){
48654
+ if( p->mFlags & SQLITE_DESERIALIZE_FREEONCLOSE ){
48655
+ sqlite3_free(p->aData);
48656
+ }
48657
+ memdbLeave(p);
48658
+ sqlite3_mutex_free(p->pMutex);
48659
+ sqlite3_free(p);
48660
+ }else{
48661
+ memdbLeave(p);
4854948662
}
4855048663
return SQLITE_OK;
4855148664
}
4855248665
4855348666
/*
@@ -48557,24 +48670,27 @@
4855748670
sqlite3_file *pFile,
4855848671
void *zBuf,
4855948672
int iAmt,
4856048673
sqlite_int64 iOfst
4856148674
){
48562
- MemFile *p = (MemFile *)pFile;
48675
+ MemStore *p = ((MemFile*)pFile)->pStore;
48676
+ memdbEnter(p);
4856348677
if( iOfst+iAmt>p->sz ){
4856448678
memset(zBuf, 0, iAmt);
4856548679
if( iOfst<p->sz ) memcpy(zBuf, p->aData+iOfst, p->sz - iOfst);
48680
+ memdbLeave(p);
4856648681
return SQLITE_IOERR_SHORT_READ;
4856748682
}
4856848683
memcpy(zBuf, p->aData+iOfst, iAmt);
48684
+ memdbLeave(p);
4856948685
return SQLITE_OK;
4857048686
}
4857148687
4857248688
/*
4857348689
** Try to enlarge the memory allocation to hold at least sz bytes
4857448690
*/
48575
-static int memdbEnlarge(MemFile *p, sqlite3_int64 newSz){
48691
+static int memdbEnlarge(MemStore *p, sqlite3_int64 newSz){
4857648692
unsigned char *pNew;
4857748693
if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || p->nMmap>0 ){
4857848694
return SQLITE_FULL;
4857948695
}
4858048696
if( newSz>p->szMax ){
@@ -48596,23 +48712,31 @@
4859648712
sqlite3_file *pFile,
4859748713
const void *z,
4859848714
int iAmt,
4859948715
sqlite_int64 iOfst
4860048716
){
48601
- MemFile *p = (MemFile *)pFile;
48602
- if( NEVER(p->mFlags & SQLITE_DESERIALIZE_READONLY) ) return SQLITE_READONLY;
48717
+ MemStore *p = ((MemFile*)pFile)->pStore;
48718
+ memdbEnter(p);
48719
+ if( NEVER(p->mFlags & SQLITE_DESERIALIZE_READONLY) ){
48720
+ /* Can't happen: memdbLock() will return SQLITE_READONLY before
48721
+ ** reaching this point */
48722
+ memdbLeave(p);
48723
+ return SQLITE_IOERR_WRITE;
48724
+ }
4860348725
if( iOfst+iAmt>p->sz ){
4860448726
int rc;
4860548727
if( iOfst+iAmt>p->szAlloc
4860648728
&& (rc = memdbEnlarge(p, iOfst+iAmt))!=SQLITE_OK
4860748729
){
48730
+ memdbLeave(p);
4860848731
return rc;
4860948732
}
4861048733
if( iOfst>p->sz ) memset(p->aData+p->sz, 0, iOfst-p->sz);
4861148734
p->sz = iOfst+iAmt;
4861248735
}
4861348736
memcpy(p->aData+iOfst, z, iAmt);
48737
+ memdbLeave(p);
4861448738
return SQLITE_OK;
4861548739
}
4861648740
4861748741
/*
4861848742
** Truncate an memdb-file.
@@ -48620,14 +48744,20 @@
4862048744
** In rollback mode (which is always the case for memdb, as it does not
4862148745
** support WAL mode) the truncate() method is only used to reduce
4862248746
** the size of a file, never to increase the size.
4862348747
*/
4862448748
static int memdbTruncate(sqlite3_file *pFile, sqlite_int64 size){
48625
- MemFile *p = (MemFile *)pFile;
48626
- if( NEVER(size>p->sz) ) return SQLITE_FULL;
48627
- p->sz = size;
48628
- return SQLITE_OK;
48749
+ MemStore *p = ((MemFile*)pFile)->pStore;
48750
+ int rc = SQLITE_OK;
48751
+ memdbEnter(p);
48752
+ if( NEVER(size>p->sz) ){
48753
+ rc = SQLITE_FULL;
48754
+ }else{
48755
+ p->sz = size;
48756
+ }
48757
+ memdbLeave(p);
48758
+ return rc;
4862948759
}
4863048760
4863148761
/*
4863248762
** Sync an memdb-file.
4863348763
*/
@@ -48637,45 +48767,78 @@
4863748767
4863848768
/*
4863948769
** Return the current file-size of an memdb-file.
4864048770
*/
4864148771
static int memdbFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
48642
- MemFile *p = (MemFile *)pFile;
48772
+ MemStore *p = ((MemFile*)pFile)->pStore;
48773
+ memdbEnter(p);
4864348774
*pSize = p->sz;
48775
+ memdbLeave(p);
4864448776
return SQLITE_OK;
4864548777
}
4864648778
4864748779
/*
4864848780
** Lock an memdb-file.
4864948781
*/
4865048782
static int memdbLock(sqlite3_file *pFile, int eLock){
48651
- MemFile *p = (MemFile *)pFile;
48652
- if( eLock>SQLITE_LOCK_SHARED
48653
- && (p->mFlags & SQLITE_DESERIALIZE_READONLY)!=0
48654
- ){
48655
- return SQLITE_READONLY;
48656
- }
48657
- p->eLock = eLock;
48658
- return SQLITE_OK;
48783
+ MemFile *pThis = (MemFile*)pFile;
48784
+ MemStore *p = pThis->pStore;
48785
+ int rc = SQLITE_OK;
48786
+ if( eLock==pThis->eLock ) return SQLITE_OK;
48787
+ memdbEnter(p);
48788
+ if( eLock>SQLITE_LOCK_SHARED ){
48789
+ if( p->mFlags & SQLITE_DESERIALIZE_READONLY ){
48790
+ rc = SQLITE_READONLY;
48791
+ }else if( pThis->eLock<=SQLITE_LOCK_SHARED ){
48792
+ if( p->nWrLock ){
48793
+ rc = SQLITE_BUSY;
48794
+ }else{
48795
+ p->nWrLock = 1;
48796
+ }
48797
+ }
48798
+ }else if( eLock==SQLITE_LOCK_SHARED ){
48799
+ if( pThis->eLock > SQLITE_LOCK_SHARED ){
48800
+ assert( p->nWrLock==1 );
48801
+ p->nWrLock = 0;
48802
+ }else if( p->nWrLock ){
48803
+ rc = SQLITE_BUSY;
48804
+ }else{
48805
+ p->nRdLock++;
48806
+ }
48807
+ }else{
48808
+ assert( eLock==SQLITE_LOCK_NONE );
48809
+ if( pThis->eLock>SQLITE_LOCK_SHARED ){
48810
+ assert( p->nWrLock==1 );
48811
+ p->nWrLock = 0;
48812
+ }
48813
+ assert( p->nRdLock>0 );
48814
+ p->nRdLock--;
48815
+ }
48816
+ if( rc==SQLITE_OK ) pThis->eLock = eLock;
48817
+ memdbLeave(p);
48818
+ return rc;
4865948819
}
4866048820
48661
-#if 0 /* Never used because memdbAccess() always returns false */
48821
+#if 0
4866248822
/*
48663
-** Check if another file-handle holds a RESERVED lock on an memdb-file.
48823
+** This interface is only used for crash recovery, which does not
48824
+** occur on an in-memory database.
4866448825
*/
4866548826
static int memdbCheckReservedLock(sqlite3_file *pFile, int *pResOut){
4866648827
*pResOut = 0;
4866748828
return SQLITE_OK;
4866848829
}
4866948830
#endif
48831
+
4867048832
4867148833
/*
4867248834
** File control method. For custom operations on an memdb-file.
4867348835
*/
4867448836
static int memdbFileControl(sqlite3_file *pFile, int op, void *pArg){
48675
- MemFile *p = (MemFile *)pFile;
48837
+ MemStore *p = ((MemFile*)pFile)->pStore;
4867648838
int rc = SQLITE_NOTFOUND;
48839
+ memdbEnter(p);
4867748840
if( op==SQLITE_FCNTL_VFSNAME ){
4867848841
*(char**)pArg = sqlite3_mprintf("memdb(%p,%lld)", p->aData, p->sz);
4867948842
rc = SQLITE_OK;
4868048843
}
4868148844
if( op==SQLITE_FCNTL_SIZE_LIMIT ){
@@ -48689,10 +48852,11 @@
4868948852
}
4869048853
p->szMax = iLimit;
4869148854
*(sqlite3_int64*)pArg = iLimit;
4869248855
rc = SQLITE_OK;
4869348856
}
48857
+ memdbLeave(p);
4869448858
return rc;
4869548859
}
4869648860
4869748861
#if 0 /* Not used because of SQLITE_IOCAP_POWERSAFE_OVERWRITE */
4869848862
/*
@@ -48718,47 +48882,110 @@
4871848882
sqlite3_file *pFile,
4871948883
sqlite3_int64 iOfst,
4872048884
int iAmt,
4872148885
void **pp
4872248886
){
48723
- MemFile *p = (MemFile *)pFile;
48887
+ MemStore *p = ((MemFile*)pFile)->pStore;
48888
+ memdbEnter(p);
4872448889
if( iOfst+iAmt>p->sz ){
4872548890
*pp = 0;
4872648891
}else{
4872748892
p->nMmap++;
4872848893
*pp = (void*)(p->aData + iOfst);
4872948894
}
48895
+ memdbLeave(p);
4873048896
return SQLITE_OK;
4873148897
}
4873248898
4873348899
/* Release a memory-mapped page */
4873448900
static int memdbUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
48735
- MemFile *p = (MemFile *)pFile;
48901
+ MemStore *p = ((MemFile*)pFile)->pStore;
48902
+ memdbEnter(p);
4873648903
p->nMmap--;
48904
+ memdbLeave(p);
4873748905
return SQLITE_OK;
4873848906
}
4873948907
4874048908
/*
4874148909
** Open an mem file handle.
4874248910
*/
4874348911
static int memdbOpen(
4874448912
sqlite3_vfs *pVfs,
4874548913
const char *zName,
48746
- sqlite3_file *pFile,
48914
+ sqlite3_file *pFd,
4874748915
int flags,
4874848916
int *pOutFlags
4874948917
){
48750
- MemFile *p = (MemFile*)pFile;
48918
+ MemFile *pFile = (MemFile*)pFd;
48919
+ MemStore *p = 0;
48920
+ int szName;
4875148921
if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
48752
- return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFile, flags, pOutFlags);
48922
+ return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFd, flags, pOutFlags);
4875348923
}
48754
- memset(p, 0, sizeof(*p));
48755
- p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
48924
+ memset(pFile, 0, sizeof(*p));
48925
+ szName = sqlite3Strlen30(zName);
48926
+ if( szName>1 && zName[0]=='/' ){
48927
+ int i;
48928
+#ifndef SQLITE_MUTEX_OMIT
48929
+ sqlite3_mutex *pVfsMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
48930
+#endif
48931
+ sqlite3_mutex_enter(pVfsMutex);
48932
+ for(i=0; i<memdb_g.nMemStore; i++){
48933
+ if( strcmp(memdb_g.apMemStore[i]->zFName,zName)==0 ){
48934
+ p = memdb_g.apMemStore[i];
48935
+ break;
48936
+ }
48937
+ }
48938
+ if( p==0 ){
48939
+ MemStore **apNew;
48940
+ p = sqlite3Malloc( sizeof(*p) + szName + 3 );
48941
+ if( p==0 ){
48942
+ sqlite3_mutex_leave(pVfsMutex);
48943
+ return SQLITE_NOMEM;
48944
+ }
48945
+ apNew = sqlite3Realloc(memdb_g.apMemStore,
48946
+ sizeof(apNew[0])*(memdb_g.nMemStore+1) );
48947
+ if( apNew==0 ){
48948
+ sqlite3_free(p);
48949
+ sqlite3_mutex_leave(pVfsMutex);
48950
+ return SQLITE_NOMEM;
48951
+ }
48952
+ apNew[memdb_g.nMemStore++] = p;
48953
+ memdb_g.apMemStore = apNew;
48954
+ memset(p, 0, sizeof(*p));
48955
+ p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE|SQLITE_DESERIALIZE_FREEONCLOSE;
48956
+ p->szMax = sqlite3GlobalConfig.mxMemdbSize;
48957
+ p->zFName = (char*)&p[1];
48958
+ memcpy(p->zFName, zName, szName+1);
48959
+ p->pMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
48960
+ if( p->pMutex==0 ){
48961
+ memdb_g.nMemStore--;
48962
+ sqlite3_free(p);
48963
+ sqlite3_mutex_leave(pVfsMutex);
48964
+ return SQLITE_NOMEM;
48965
+ }
48966
+ p->nRef = 1;
48967
+ memdbEnter(p);
48968
+ }else{
48969
+ memdbEnter(p);
48970
+ p->nRef++;
48971
+ }
48972
+ sqlite3_mutex_leave(pVfsMutex);
48973
+ }else{
48974
+ p = sqlite3Malloc( sizeof(*p) );
48975
+ if( p==0 ){
48976
+ return SQLITE_NOMEM;
48977
+ }
48978
+ memset(p, 0, sizeof(*p));
48979
+ p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
48980
+ p->szMax = sqlite3GlobalConfig.mxMemdbSize;
48981
+ }
48982
+ pFile->pStore = p;
4875648983
assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */
4875748984
*pOutFlags = flags | SQLITE_OPEN_MEMORY;
48758
- pFile->pMethods = &memdb_io_methods;
48759
- p->szMax = sqlite3GlobalConfig.mxMemdbSize;
48985
+ pFd->pMethods = &memdb_io_methods;
48986
+ memdbLeave(p);
4876048987
return SQLITE_OK;
4876148988
}
4876248989
4876348990
#if 0 /* Only used to delete rollback journals, super-journals, and WAL
4876448991
** files, none of which exist in memdb. So this routine is never used */
@@ -48869,13 +49096,18 @@
4886949096
** Translate a database connection pointer and schema name into a
4887049097
** MemFile pointer.
4887149098
*/
4887249099
static MemFile *memdbFromDbSchema(sqlite3 *db, const char *zSchema){
4887349100
MemFile *p = 0;
49101
+ MemStore *pStore;
4887449102
int rc = sqlite3_file_control(db, zSchema, SQLITE_FCNTL_FILE_POINTER, &p);
4887549103
if( rc ) return 0;
4887649104
if( p->base.pMethods!=&memdb_io_methods ) return 0;
49105
+ pStore = p->pStore;
49106
+ memdbEnter(pStore);
49107
+ if( pStore->zFName!=0 ) p = 0;
49108
+ memdbLeave(pStore);
4887749109
return p;
4887849110
}
4887949111
4888049112
/*
4888149113
** Return the serialization of a database
@@ -48907,16 +49139,18 @@
4890749139
p = memdbFromDbSchema(db, zSchema);
4890849140
iDb = sqlite3FindDbName(db, zSchema);
4890949141
if( piSize ) *piSize = -1;
4891049142
if( iDb<0 ) return 0;
4891149143
if( p ){
48912
- if( piSize ) *piSize = p->sz;
49144
+ MemStore *pStore = p->pStore;
49145
+ assert( pStore->pMutex==0 );
49146
+ if( piSize ) *piSize = pStore->sz;
4891349147
if( mFlags & SQLITE_SERIALIZE_NOCOPY ){
48914
- pOut = p->aData;
49148
+ pOut = pStore->aData;
4891549149
}else{
48916
- pOut = sqlite3_malloc64( p->sz );
48917
- if( pOut ) memcpy(pOut, p->aData, p->sz);
49150
+ pOut = sqlite3_malloc64( pStore->sz );
49151
+ if( pOut ) memcpy(pOut, pStore->aData, pStore->sz);
4891849152
}
4891949153
return pOut;
4892049154
}
4892149155
pBt = db->aDb[iDb].pBt;
4892249156
if( pBt==0 ) return 0;
@@ -49006,19 +49240,20 @@
4900649240
}
4900749241
p = memdbFromDbSchema(db, zSchema);
4900849242
if( p==0 ){
4900949243
rc = SQLITE_ERROR;
4901049244
}else{
49011
- p->aData = pData;
49245
+ MemStore *pStore = p->pStore;
49246
+ pStore->aData = pData;
4901249247
pData = 0;
49013
- p->sz = szDb;
49014
- p->szAlloc = szBuf;
49015
- p->szMax = szBuf;
49016
- if( p->szMax<sqlite3GlobalConfig.mxMemdbSize ){
49017
- p->szMax = sqlite3GlobalConfig.mxMemdbSize;
49248
+ pStore->sz = szDb;
49249
+ pStore->szAlloc = szBuf;
49250
+ pStore->szMax = szBuf;
49251
+ if( pStore->szMax<sqlite3GlobalConfig.mxMemdbSize ){
49252
+ pStore->szMax = sqlite3GlobalConfig.mxMemdbSize;
4901849253
}
49019
- p->mFlags = mFlags;
49254
+ pStore->mFlags = mFlags;
4902049255
rc = SQLITE_OK;
4902149256
}
4902249257
4902349258
end_deserialize:
4902449259
sqlite3_finalize(pStmt);
@@ -49043,11 +49278,11 @@
4904349278
** is no way to reach it under most builds. */
4904449279
if( sz<sizeof(MemFile) ) sz = sizeof(MemFile); /*NO_TEST*/
4904549280
memdb_vfs.szOsFile = sz;
4904649281
return sqlite3_vfs_register(&memdb_vfs, 0);
4904749282
}
49048
-#endif /* SQLITE_ENABLE_DESERIALIZE */
49283
+#endif /* SQLITE_OMIT_DESERIALIZE */
4904949284
4905049285
/************** End of memdb.c ***********************************************/
4905149286
/************** Begin file bitvec.c ******************************************/
4905249287
/*
4905349288
** 2008 February 16
@@ -56958,11 +57193,11 @@
5695857193
u8 *pPtr;
5695957194
Pager *pPager = 0; /* Pager object to allocate and return */
5696057195
int rc = SQLITE_OK; /* Return code */
5696157196
int tempFile = 0; /* True for temp files (incl. in-memory files) */
5696257197
int memDb = 0; /* True if this is an in-memory file */
56963
-#ifdef SQLITE_ENABLE_DESERIALIZE
57198
+#ifndef SQLITE_OMIT_DESERIALIZE
5696457199
int memJM = 0; /* Memory journal mode */
5696557200
#else
5696657201
# define memJM 0
5696757202
#endif
5696857203
int readOnly = 0; /* True if this is a read-only file */
@@ -57162,11 +57397,11 @@
5716257397
*/
5716357398
if( zFilename && zFilename[0] ){
5716457399
int fout = 0; /* VFS flags returned by xOpen() */
5716557400
rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout);
5716657401
assert( !memDb );
57167
-#ifdef SQLITE_ENABLE_DESERIALIZE
57402
+#ifndef SQLITE_OMIT_DESERIALIZE
5716857403
memJM = (fout&SQLITE_OPEN_MEMORY)!=0;
5716957404
#endif
5717057405
readOnly = (fout&SQLITE_OPEN_READONLY)!=0;
5717157406
5717257407
/* If the file was successfully opened for read/write access,
@@ -61004,11 +61239,10 @@
6100461239
static void walCleanupHash(Wal *pWal){
6100561240
WalHashLoc sLoc; /* Hash table location */
6100661241
int iLimit = 0; /* Zero values greater than this */
6100761242
int nByte; /* Number of bytes to zero in aPgno[] */
6100861243
int i; /* Used to iterate through aHash[] */
61009
- int rc; /* Return code form walHashGet() */
6101061244
6101161245
assert( pWal->writeLock );
6101261246
testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE-1 );
6101361247
testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE );
6101461248
testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE+1 );
@@ -61019,12 +61253,12 @@
6101961253
** the entry that corresponds to frame pWal->hdr.mxFrame. It is guaranteed
6102061254
** that the page said hash-table and array reside on is already mapped.(1)
6102161255
*/
6102261256
assert( pWal->nWiData>walFramePage(pWal->hdr.mxFrame) );
6102361257
assert( pWal->apWiData[walFramePage(pWal->hdr.mxFrame)] );
61024
- rc = walHashGet(pWal, walFramePage(pWal->hdr.mxFrame), &sLoc);
61025
- if( NEVER(rc) ) return; /* Defense-in-depth, in case (1) above is wrong */
61258
+ i = walHashGet(pWal, walFramePage(pWal->hdr.mxFrame), &sLoc);
61259
+ if( NEVER(i) ) return; /* Defense-in-depth, in case (1) above is wrong */
6102661260
6102761261
/* Zero all hash-table entries that correspond to frame numbers greater
6102861262
** than pWal->hdr.mxFrame.
6102961263
*/
6103061264
iLimit = pWal->hdr.mxFrame - sLoc.iZero;
@@ -72271,11 +72505,13 @@
7227172505
assert( pFree>aData && (pFree - aData)<65536 );
7227272506
freeSpace(pPg, (u16)(pFree - aData), szFree);
7227372507
}
7227472508
pFree = pCell;
7227572509
szFree = sz;
72276
- if( pFree+sz>pEnd ) return 0;
72510
+ if( pFree+sz>pEnd ){
72511
+ return 0;
72512
+ }
7227772513
}else{
7227872514
pFree = pCell;
7227972515
szFree += sz;
7228072516
}
7228172517
nRet++;
@@ -73247,10 +73483,11 @@
7324773483
/* Insert new divider cells into pParent. */
7324873484
for(i=0; i<nNew-1; i++){
7324973485
u8 *pCell;
7325073486
u8 *pTemp;
7325173487
int sz;
73488
+ u8 *pSrcEnd;
7325273489
MemPage *pNew = apNew[i];
7325373490
j = cntNew[i];
7325473491
7325573492
assert( j<nMaxCells );
7325673493
assert( b.apCell[j]!=0 );
@@ -73290,10 +73527,16 @@
7329073527
}
7329173528
}
7329273529
iOvflSpace += sz;
7329373530
assert( sz<=pBt->maxLocal+23 );
7329473531
assert( iOvflSpace <= (int)pBt->pageSize );
73532
+ for(k=0; b.ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
73533
+ pSrcEnd = b.apEnd[k];
73534
+ if( SQLITE_WITHIN(pSrcEnd, pCell, pCell+sz) ){
73535
+ rc = SQLITE_CORRUPT_BKPT;
73536
+ goto balance_cleanup;
73537
+ }
7329573538
insertCell(pParent, nxDiv+i, pCell, sz, pTemp, pNew->pgno, &rc);
7329673539
if( rc!=SQLITE_OK ) goto balance_cleanup;
7329773540
assert( sqlite3PagerIswriteable(pParent->pDbPage) );
7329873541
}
7329973542
@@ -86617,10 +86860,15 @@
8661786860
printf(" <== R[%d]", (int)(p->pScopyFrom - &p[-iReg]));
8661886861
}
8661986862
printf("\n");
8662086863
sqlite3VdbeCheckMemInvariants(p);
8662186864
}
86865
+SQLITE_PRIVATE void sqlite3PrintMem(Mem *pMem){
86866
+ memTracePrint(pMem);
86867
+ printf("\n");
86868
+ fflush(stdout);
86869
+}
8662286870
#endif
8662386871
8662486872
#ifdef SQLITE_DEBUG
8662586873
/*
8662686874
** Show the values of all registers in the virtual machine. Used for
@@ -90667,12 +90915,22 @@
9066790915
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
9066890916
pC = p->apCsr[pOp->p1];
9066990917
assert( pC!=0 );
9067090918
assert( pOp->p3>=pOp->p2 );
9067190919
if( pC->seekHit<pOp->p2 ){
90920
+#ifdef SQLITE_DEBUG
90921
+ if( db->flags&SQLITE_VdbeTrace ){
90922
+ printf("seekHit changes from %d to %d\n", pC->seekHit, pOp->p2);
90923
+ }
90924
+#endif
9067290925
pC->seekHit = pOp->p2;
9067390926
}else if( pC->seekHit>pOp->p3 ){
90927
+#ifdef SQLITE_DEBUG
90928
+ if( db->flags&SQLITE_VdbeTrace ){
90929
+ printf("seekHit changes from %d to %d\n", pC->seekHit, pOp->p3);
90930
+ }
90931
+#endif
9067490932
pC->seekHit = pOp->p3;
9067590933
}
9067690934
break;
9067790935
}
9067890936
@@ -90783,10 +91041,15 @@
9078391041
case OP_IfNoHope: { /* jump, in3 */
9078491042
VdbeCursor *pC;
9078591043
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
9078691044
pC = p->apCsr[pOp->p1];
9078791045
assert( pC!=0 );
91046
+#ifdef SQLITE_DEBUG
91047
+ if( db->flags&SQLITE_VdbeTrace ){
91048
+ printf("seekHit is %d\n", pC->seekHit);
91049
+ }
91050
+#endif
9078891051
if( pC->seekHit>=pOp->p4.i ) break;
9078991052
/* Fall through into OP_NotFound */
9079091053
/* no break */ deliberate_fall_through
9079191054
}
9079291055
case OP_NoConflict: /* jump, in3 */
@@ -100897,22 +101160,11 @@
100897101160
Parse *pParse, /* Parsing context */
100898101161
Expr *pExpr, /* Add the "COLLATE" clause to this expression */
100899101162
const Token *pCollName, /* Name of collating sequence */
100900101163
int dequote /* True to dequote pCollName */
100901101164
){
100902
- assert( pExpr!=0 || pParse->db->mallocFailed );
100903
- if( pExpr==0 ) return 0;
100904
- if( pExpr->op==TK_VECTOR ){
100905
- ExprList *pList = pExpr->x.pList;
100906
- if( ALWAYS(pList!=0) ){
100907
- int i;
100908
- for(i=0; i<pList->nExpr; i++){
100909
- pList->a[i].pExpr = sqlite3ExprAddCollateToken(pParse,pList->a[i].pExpr,
100910
- pCollName, dequote);
100911
- }
100912
- }
100913
- }else if( pCollName->n>0 ){
101165
+ if( pCollName->n>0 ){
100914101166
Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, dequote);
100915101167
if( pNew ){
100916101168
pNew->pLeft = pExpr;
100917101169
pNew->flags |= EP_Collate|EP_Skip;
100918101170
pExpr = pNew;
@@ -107808,11 +108060,11 @@
107808108060
*/
107809108061
static int renameUnmapSelectCb(Walker *pWalker, Select *p){
107810108062
Parse *pParse = pWalker->pParse;
107811108063
int i;
107812108064
if( pParse->nErr ) return WRC_Abort;
107813
- if( NEVER(p->selFlags & SF_View) ) return WRC_Prune;
108065
+ if( p->selFlags & SF_View ) return WRC_Prune;
107814108066
if( ALWAYS(p->pEList) ){
107815108067
ExprList *pList = p->pEList;
107816108068
for(i=0; i<pList->nExpr; i++){
107817108069
if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){
107818108070
sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
@@ -111180,11 +111432,11 @@
111180111432
zFile = (const char *)sqlite3_value_text(argv[0]);
111181111433
zName = (const char *)sqlite3_value_text(argv[1]);
111182111434
if( zFile==0 ) zFile = "";
111183111435
if( zName==0 ) zName = "";
111184111436
111185
-#ifdef SQLITE_ENABLE_DESERIALIZE
111437
+#ifndef SQLITE_OMIT_DESERIALIZE
111186111438
# define REOPEN_AS_MEMDB(db) (db->init.reopenMemdb)
111187111439
#else
111188111440
# define REOPEN_AS_MEMDB(db) (0)
111189111441
#endif
111190111442
@@ -113000,10 +113252,26 @@
113000113252
/* iCol is a normal or stored column */
113001113253
return n;
113002113254
}
113003113255
}
113004113256
#endif
113257
+
113258
+/*
113259
+** Insert a single OP_JournalMode query opcode in order to force the
113260
+** prepared statement to return false for sqlite3_stmt_readonly(). This
113261
+** is used by CREATE TABLE IF NOT EXISTS and similar if the table already
113262
+** exists, so that the prepared statement for CREATE TABLE IF NOT EXISTS
113263
+** will return false for sqlite3_stmt_readonly() even if that statement
113264
+** is a read-only no-op.
113265
+*/
113266
+static void sqlite3ForceNotReadOnly(Parse *pParse){
113267
+ int iReg = ++pParse->nMem;
113268
+ Vdbe *v = sqlite3GetVdbe(pParse);
113269
+ if( v ){
113270
+ sqlite3VdbeAddOp3(v, OP_JournalMode, 0, iReg, PAGER_JOURNALMODE_QUERY);
113271
+ }
113272
+}
113005113273
113006113274
/*
113007113275
** Begin constructing a new table representation in memory. This is
113008113276
** the first of several action routines that get called in response
113009113277
** to a CREATE TABLE statement. In particular, this routine is called
@@ -113100,10 +113368,11 @@
113100113368
if( !noErr ){
113101113369
sqlite3ErrorMsg(pParse, "table %T already exists", pName);
113102113370
}else{
113103113371
assert( !db->init.busy || CORRUPT_DB );
113104113372
sqlite3CodeVerifySchema(pParse, iDb);
113373
+ sqlite3ForceNotReadOnly(pParse);
113105113374
}
113106113375
goto begin_table_error;
113107113376
}
113108113377
if( sqlite3FindIndex(db, zName, zDb)!=0 ){
113109113378
sqlite3ErrorMsg(pParse, "there is already an index named %s", zName);
@@ -115150,11 +115419,14 @@
115150115419
assert( isView==0 || isView==LOCATE_VIEW );
115151115420
pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]);
115152115421
if( noErr ) db->suppressErr--;
115153115422
115154115423
if( pTab==0 ){
115155
- if( noErr ) sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
115424
+ if( noErr ){
115425
+ sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
115426
+ sqlite3ForceNotReadOnly(pParse);
115427
+ }
115156115428
goto exit_drop_table;
115157115429
}
115158115430
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
115159115431
assert( iDb>=0 && iDb<db->nDb );
115160115432
@@ -115720,10 +115992,11 @@
115720115992
if( !ifNotExist ){
115721115993
sqlite3ErrorMsg(pParse, "index %s already exists", zName);
115722115994
}else{
115723115995
assert( !db->init.busy );
115724115996
sqlite3CodeVerifySchema(pParse, iDb);
115997
+ sqlite3ForceNotReadOnly(pParse);
115725115998
}
115726115999
goto exit_create_index;
115727116000
}
115728116001
}
115729116002
}else{
@@ -116200,11 +116473,11 @@
116200116473
x = pIdx->pTable->nRowLogEst;
116201116474
assert( 99==sqlite3LogEst(1000) );
116202116475
if( x<99 ){
116203116476
pIdx->pTable->nRowLogEst = x = 99;
116204116477
}
116205
- if( pIdx->pPartIdxWhere!=0 ) x -= 10; assert( 10==sqlite3LogEst(2) );
116478
+ if( pIdx->pPartIdxWhere!=0 ){ x -= 10; assert( 10==sqlite3LogEst(2) ); }
116206116479
a[0] = x;
116207116480
116208116481
/* Estimate that a[1] is 10, a[2] is 9, a[3] is 8, a[4] is 7, a[5] is
116209116482
** 6 and each subsequent value (if any) is 5. */
116210116483
memcpy(&a[1], aVal, nCopy*sizeof(LogEst));
@@ -116238,10 +116511,11 @@
116238116511
if( pIndex==0 ){
116239116512
if( !ifExists ){
116240116513
sqlite3ErrorMsg(pParse, "no such index: %S", pName->a);
116241116514
}else{
116242116515
sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
116516
+ sqlite3ForceNotReadOnly(pParse);
116243116517
}
116244116518
pParse->checkSchema = 1;
116245116519
goto exit_drop_index;
116246116520
}
116247116521
if( pIndex->idxType!=SQLITE_IDXTYPE_APPDEF ){
@@ -136029,11 +136303,11 @@
136029136303
** is part of the AND-connected terms of the expression. For each term
136030136304
** found, add it to the pConst structure.
136031136305
*/
136032136306
static void findConstInWhere(WhereConst *pConst, Expr *pExpr){
136033136307
Expr *pRight, *pLeft;
136034
- if( pExpr==0 ) return;
136308
+ if( NEVER(pExpr==0) ) return;
136035136309
if( ExprHasProperty(pExpr, EP_FromJoin) ) return;
136036136310
if( pExpr->op==TK_AND ){
136037136311
findConstInWhere(pConst, pExpr->pRight);
136038136312
findConstInWhere(pConst, pExpr->pLeft);
136039136313
return;
@@ -137888,11 +138162,12 @@
137888138162
/* Do the WHERE-clause constant propagation optimization if this is
137889138163
** a join. No need to speed time on this operation for non-join queries
137890138164
** as the equivalent optimization will be handled by query planner in
137891138165
** sqlite3WhereBegin().
137892138166
*/
137893
- if( pTabList->nSrc>1
138167
+ if( p->pWhere!=0
138168
+ && p->pWhere->op==TK_AND
137894138169
&& OptimizationEnabled(db, SQLITE_PropagateConst)
137895138170
&& propagateConstants(pParse, p)
137896138171
){
137897138172
#if SELECTTRACE_ENABLED
137898138173
if( sqlite3SelectTrace & 0x100 ){
@@ -144173,12 +144448,12 @@
144173144448
WhereClause *pOrigWC; /* Original, innermost WhereClause */
144174144449
WhereClause *pWC; /* WhereClause currently being scanned */
144175144450
const char *zCollName; /* Required collating sequence, if not NULL */
144176144451
Expr *pIdxExpr; /* Search for this index expression */
144177144452
char idxaff; /* Must match this affinity, if zCollName!=NULL */
144178
- unsigned char nEquiv; /* Number of entries in aEquiv[] */
144179
- unsigned char iEquiv; /* Next unused slot in aEquiv[] */
144453
+ unsigned char nEquiv; /* Number of entries in aiCur[] and aiColumn[] */
144454
+ unsigned char iEquiv; /* Next unused slot in aiCur[] and aiColumn[] */
144180144455
u32 opMask; /* Acceptable operators */
144181144456
int k; /* Resume scanning at this->pWC->a[this->k] */
144182144457
int aiCur[11]; /* Cursors in the equivalence class */
144183144458
i16 aiColumn[11]; /* Corresponding column number in the eq-class */
144184144459
};
@@ -144483,10 +144758,11 @@
144483144758
#define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/
144484144759
#define WHERE_PARTIALIDX 0x00020000 /* The automatic index is partial */
144485144760
#define WHERE_IN_EARLYOUT 0x00040000 /* Perhaps quit IN loops early */
144486144761
#define WHERE_BIGNULL_SORT 0x00080000 /* Column nEq of index is BIGNULL */
144487144762
#define WHERE_IN_SEEKSCAN 0x00100000 /* Seek-scan optimization for IN */
144763
+#define WHERE_TRANSCONS 0x00200000 /* Uses a transitive constraint */
144488144764
144489144765
#endif /* !defined(SQLITE_WHEREINT_H) */
144490144766
144491144767
/************** End of whereInt.h ********************************************/
144492144768
/************** Continuing where we left off in wherecode.c ******************/
@@ -144766,10 +145042,16 @@
144766145042
if( nLoop && (pTerm->wtFlags & TERM_LIKE)!=0 ){
144767145043
pTerm->wtFlags |= TERM_LIKECOND;
144768145044
}else{
144769145045
pTerm->wtFlags |= TERM_CODED;
144770145046
}
145047
+#ifdef WHERETRACE_ENABLED
145048
+ if( sqlite3WhereTrace & 0x20000 ){
145049
+ sqlite3DebugPrintf("DISABLE-");
145050
+ sqlite3WhereTermPrint(pTerm, (int)(pTerm - (pTerm->pWC->a)));
145051
+ }
145052
+#endif
144771145053
if( pTerm->iParent<0 ) break;
144772145054
pTerm = &pTerm->pWC->a[pTerm->iParent];
144773145055
assert( pTerm!=0 );
144774145056
pTerm->nChild--;
144775145057
if( pTerm->nChild!=0 ) break;
@@ -145083,11 +145365,26 @@
145083145365
pLevel->u.in.nIn = 0;
145084145366
}
145085145367
sqlite3DbFree(pParse->db, aiMap);
145086145368
#endif
145087145369
}
145088
- disableTerm(pLevel, pTerm);
145370
+
145371
+ /* As an optimization, try to disable the WHERE clause term that is
145372
+ ** driving the index as it will always be true. The correct answer is
145373
+ ** obtained regardless, but we might get the answer with fewer CPU cycles
145374
+ ** by omitting the term.
145375
+ **
145376
+ ** But do not disable the term unless we are certain that the term is
145377
+ ** not a transitive constraint. For an example of where that does not
145378
+ ** work, see https://sqlite.org/forum/forumpost/eb8613976a (2021-05-04)
145379
+ */
145380
+ if( (pLevel->pWLoop->wsFlags & WHERE_TRANSCONS)==0
145381
+ || (pTerm->eOperator & WO_EQUIV)==0
145382
+ ){
145383
+ disableTerm(pLevel, pTerm);
145384
+ }
145385
+
145089145386
return iReg;
145090145387
}
145091145388
145092145389
/*
145093145390
** Generate code that will evaluate all == and IN constraints for an
@@ -146197,13 +146494,11 @@
146197146494
146198146495
/* If we are doing a reverse order scan on an ascending index, or
146199146496
** a forward order scan on a descending index, interchange the
146200146497
** start and end terms (pRangeStart and pRangeEnd).
146201146498
*/
146202
- if( (nEq<pIdx->nKeyCol && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC))
146203
- || (bRev && pIdx->nKeyCol==nEq)
146204
- ){
146499
+ if( (nEq<pIdx->nColumn && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC)) ){
146205146500
SWAP(WhereTerm *, pRangeEnd, pRangeStart);
146206146501
SWAP(u8, bSeekPastNull, bStopAtNull);
146207146502
SWAP(u8, nBtm, nTop);
146208146503
}
146209146504
@@ -147832,11 +148127,11 @@
147832148127
assert( !ExprHasProperty(pNew, EP_xIsSelect) );
147833148128
pNew->x.pList = pList;
147834148129
idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
147835148130
testcase( idxNew==0 );
147836148131
exprAnalyze(pSrc, pWC, idxNew);
147837
- /* pTerm = &pWC->a[idxTerm]; // would be needed if pTerm where used again */
148132
+ /* pTerm = &pWC->a[idxTerm]; // would be needed if pTerm where reused */
147838148133
markTermAsChild(pWC, idxNew, idxTerm);
147839148134
}else{
147840148135
sqlite3ExprListDelete(db, pList);
147841148136
}
147842148137
}
@@ -147956,10 +148251,11 @@
147956148251
assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE );
147957148252
assert( TK_IS<TK_GE && TK_ISNULL<TK_GE && TK_IN<TK_GE );
147958148253
assert( op<=TK_GE );
147959148254
if( pExpr->op==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){
147960148255
pExpr = pExpr->x.pList->a[0].pExpr;
148256
+
147961148257
}
147962148258
147963148259
if( pExpr->op==TK_COLUMN ){
147964148260
aiCurCol[0] = pExpr->iTable;
147965148261
aiCurCol[1] = pExpr->iColumn;
@@ -147968,280 +148264,10 @@
147968148264
if( mPrereq==0 ) return 0; /* No table references */
147969148265
if( (mPrereq&(mPrereq-1))!=0 ) return 0; /* Refs more than one table */
147970148266
return exprMightBeIndexed2(pFrom,mPrereq,aiCurCol,pExpr);
147971148267
}
147972148268
147973
-/*
147974
-** Expression callback for exprUsesSrclist().
147975
-*/
147976
-static int exprUsesSrclistCb(Walker *p, Expr *pExpr){
147977
- if( pExpr->op==TK_COLUMN ){
147978
- SrcList *pSrc = p->u.pSrcList;
147979
- int iCsr = pExpr->iTable;
147980
- int ii;
147981
- for(ii=0; ii<pSrc->nSrc; ii++){
147982
- if( pSrc->a[ii].iCursor==iCsr ){
147983
- return p->eCode ? WRC_Abort : WRC_Continue;
147984
- }
147985
- }
147986
- return p->eCode ? WRC_Continue : WRC_Abort;
147987
- }
147988
- return WRC_Continue;
147989
-}
147990
-
147991
-/*
147992
-** Select callback for exprUsesSrclist().
147993
-*/
147994
-static int exprUsesSrclistSelectCb(Walker *NotUsed1, Select *NotUsed2){
147995
- UNUSED_PARAMETER(NotUsed1);
147996
- UNUSED_PARAMETER(NotUsed2);
147997
- return WRC_Abort;
147998
-}
147999
-
148000
-/*
148001
-** This function always returns true if expression pExpr contains
148002
-** a sub-select.
148003
-**
148004
-** If there is no sub-select in pExpr, then return true if pExpr
148005
-** contains a TK_COLUMN node for a table that is (bUses==1)
148006
-** or is not (bUses==0) in pSrc.
148007
-**
148008
-** Said another way:
148009
-**
148010
-** bUses Return Meaning
148011
-** -------- ------ ------------------------------------------------
148012
-**
148013
-** bUses==1 true pExpr contains either a sub-select or a
148014
-** TK_COLUMN referencing pSrc.
148015
-**
148016
-** bUses==1 false pExpr contains no sub-selects and all TK_COLUMN
148017
-** nodes reference tables not found in pSrc
148018
-**
148019
-** bUses==0 true pExpr contains either a sub-select or a TK_COLUMN
148020
-** that references a table not in pSrc.
148021
-**
148022
-** bUses==0 false pExpr contains no sub-selects and all TK_COLUMN
148023
-** nodes reference pSrc
148024
-*/
148025
-static int exprUsesSrclist(SrcList *pSrc, Expr *pExpr, int bUses){
148026
- Walker sWalker;
148027
- memset(&sWalker, 0, sizeof(Walker));
148028
- sWalker.eCode = bUses;
148029
- sWalker.u.pSrcList = pSrc;
148030
- sWalker.xExprCallback = exprUsesSrclistCb;
148031
- sWalker.xSelectCallback = exprUsesSrclistSelectCb;
148032
- return (sqlite3WalkExpr(&sWalker, pExpr)==WRC_Abort);
148033
-}
148034
-
148035
-/*
148036
-** Context object used by exprExistsToInIter() as it iterates through an
148037
-** expression tree.
148038
-*/
148039
-struct ExistsToInCtx {
148040
- SrcList *pSrc; /* The tables in an EXISTS(SELECT ... FROM <here> ...) */
148041
- Expr *pInLhs; /* OUT: Use this as the LHS of the IN operator */
148042
- Expr *pEq; /* OUT: The == term that include pInLhs */
148043
- Expr **ppAnd; /* OUT: The AND operator that includes pEq as a child */
148044
- Expr **ppParent; /* The AND operator currently being examined */
148045
-};
148046
-
148047
-/*
148048
-** Iterate through all AND connected nodes in the expression tree
148049
-** headed by (*ppExpr), populating the structure passed as the first
148050
-** argument with the values required by exprAnalyzeExistsFindEq().
148051
-**
148052
-** This function returns non-zero if the expression tree does not meet
148053
-** the two conditions described by the header comment for
148054
-** exprAnalyzeExistsFindEq(), or zero if it does.
148055
-*/
148056
-static int exprExistsToInIter(struct ExistsToInCtx *p, Expr **ppExpr){
148057
- Expr *pExpr = *ppExpr;
148058
- switch( pExpr->op ){
148059
- case TK_AND:
148060
- p->ppParent = ppExpr;
148061
- if( exprExistsToInIter(p, &pExpr->pLeft) ) return 1;
148062
- p->ppParent = ppExpr;
148063
- if( exprExistsToInIter(p, &pExpr->pRight) ) return 1;
148064
- break;
148065
- case TK_EQ: {
148066
- int bLeft = exprUsesSrclist(p->pSrc, pExpr->pLeft, 0);
148067
- int bRight = exprUsesSrclist(p->pSrc, pExpr->pRight, 0);
148068
- if( bLeft || bRight ){
148069
- if( (bLeft && bRight) || p->pInLhs ) return 1;
148070
- p->pInLhs = bLeft ? pExpr->pLeft : pExpr->pRight;
148071
- if( exprUsesSrclist(p->pSrc, p->pInLhs, 1) ) return 1;
148072
- p->pEq = pExpr;
148073
- p->ppAnd = p->ppParent;
148074
- }
148075
- break;
148076
- }
148077
- default:
148078
- if( exprUsesSrclist(p->pSrc, pExpr, 0) ){
148079
- return 1;
148080
- }
148081
- break;
148082
- }
148083
-
148084
- return 0;
148085
-}
148086
-
148087
-/*
148088
-** This function is used by exprAnalyzeExists() when creating virtual IN(...)
148089
-** terms equivalent to user-supplied EXIST(...) clauses. It splits the WHERE
148090
-** clause of the Select object passed as the first argument into one or more
148091
-** expressions joined by AND operators, and then tests if the following are
148092
-** true:
148093
-**
148094
-** 1. Exactly one of the AND separated terms refers to the outer
148095
-** query, and it is an == (TK_EQ) expression.
148096
-**
148097
-** 2. Only one side of the == expression refers to the outer query, and
148098
-** it does not refer to any columns from the inner query.
148099
-**
148100
-** If both these conditions are true, then a pointer to the side of the ==
148101
-** expression that refers to the outer query is returned. The caller will
148102
-** use this expression as the LHS of the IN(...) virtual term. Or, if one
148103
-** or both of the above conditions are not true, NULL is returned.
148104
-**
148105
-** If non-NULL is returned and ppEq is non-NULL, *ppEq is set to point
148106
-** to the == expression node before returning. If pppAnd is non-NULL and
148107
-** the == node is not the root of the WHERE clause, then *pppAnd is set
148108
-** to point to the pointer to the AND node that is the parent of the ==
148109
-** node within the WHERE expression tree.
148110
-*/
148111
-static Expr *exprAnalyzeExistsFindEq(
148112
- Select *pSel, /* The SELECT of the EXISTS */
148113
- Expr **ppEq, /* OUT: == node from WHERE clause */
148114
- Expr ***pppAnd /* OUT: Pointer to parent of ==, if any */
148115
-){
148116
- struct ExistsToInCtx ctx;
148117
- memset(&ctx, 0, sizeof(ctx));
148118
- ctx.pSrc = pSel->pSrc;
148119
- if( exprExistsToInIter(&ctx, &pSel->pWhere) ){
148120
- return 0;
148121
- }
148122
- if( ppEq ) *ppEq = ctx.pEq;
148123
- if( pppAnd ) *pppAnd = ctx.ppAnd;
148124
- return ctx.pInLhs;
148125
-}
148126
-
148127
-/*
148128
-** Term idxTerm of the WHERE clause passed as the second argument is an
148129
-** EXISTS expression with a correlated SELECT statement on the RHS.
148130
-** This function analyzes the SELECT statement, and if possible adds an
148131
-** equivalent "? IN(SELECT...)" virtual term to the WHERE clause.
148132
-**
148133
-** For an EXISTS term such as the following:
148134
-**
148135
-** EXISTS (SELECT ... FROM <srclist> WHERE <e1> = <e2> AND <e3>)
148136
-**
148137
-** The virtual IN() term added is:
148138
-**
148139
-** <e1> IN (SELECT <e2> FROM <srclist> WHERE <e3>)
148140
-**
148141
-** The virtual term is only added if the following conditions are met:
148142
-**
148143
-** 1. The sub-select must not be an aggregate or use window functions,
148144
-**
148145
-** 2. The sub-select must not be a compound SELECT,
148146
-**
148147
-** 3. Expression <e1> must refer to at least one column from the outer
148148
-** query, and must not refer to any column from the inner query
148149
-** (i.e. from <srclist>).
148150
-**
148151
-** 4. <e2> and <e3> must not refer to any values from the outer query.
148152
-** In other words, once <e1> has been removed, the inner query
148153
-** must not be correlated.
148154
-**
148155
-*/
148156
-static void exprAnalyzeExists(
148157
- SrcList *pSrc, /* the FROM clause */
148158
- WhereClause *pWC, /* the WHERE clause */
148159
- int idxTerm /* Index of the term to be analyzed */
148160
-){
148161
- Parse *pParse = pWC->pWInfo->pParse;
148162
- WhereTerm *pTerm = &pWC->a[idxTerm];
148163
- Expr *pExpr = pTerm->pExpr;
148164
- Select *pSel = pExpr->x.pSelect;
148165
- Expr *pDup = 0;
148166
- Expr *pEq = 0;
148167
- Expr *pRet = 0;
148168
- Expr *pInLhs = 0;
148169
- Expr **ppAnd = 0;
148170
- int idxNew;
148171
- sqlite3 *db = pParse->db;
148172
-
148173
- assert( pExpr->op==TK_EXISTS );
148174
- assert( (pExpr->flags & EP_VarSelect) && (pExpr->flags & EP_xIsSelect) );
148175
-
148176
- if( pSel->selFlags & SF_Aggregate ) return;
148177
-#ifndef SQLITE_OMIT_WINDOWFUNC
148178
- if( pSel->pWin ) return;
148179
-#endif
148180
- if( pSel->pPrior ) return;
148181
- if( pSel->pWhere==0 ) return;
148182
- if( pSel->pLimit ) return;
148183
- if( 0==exprAnalyzeExistsFindEq(pSel, 0, 0) ) return;
148184
-
148185
- pDup = sqlite3ExprDup(db, pExpr, 0);
148186
- if( db->mallocFailed ){
148187
- sqlite3ExprDelete(db, pDup);
148188
- return;
148189
- }
148190
- pSel = pDup->x.pSelect;
148191
- sqlite3ExprListDelete(db, pSel->pEList);
148192
- pSel->pEList = 0;
148193
-
148194
- pInLhs = exprAnalyzeExistsFindEq(pSel, &pEq, &ppAnd);
148195
- assert( pInLhs && pEq );
148196
- assert( pEq==pSel->pWhere || ppAnd );
148197
- if( pInLhs==pEq->pLeft ){
148198
- pRet = pEq->pRight;
148199
- }else{
148200
- CollSeq *p = sqlite3ExprCompareCollSeq(pParse, pEq);
148201
- pInLhs = sqlite3ExprAddCollateString(pParse, pInLhs, p?p->zName:"BINARY");
148202
- pRet = pEq->pLeft;
148203
- }
148204
-
148205
- assert( pDup->pLeft==0 );
148206
- pDup->op = TK_IN;
148207
- pDup->pLeft = pInLhs;
148208
- pDup->flags &= ~EP_VarSelect;
148209
- if( pRet->op==TK_VECTOR ){
148210
- pSel->pEList = pRet->x.pList;
148211
- pRet->x.pList = 0;
148212
- sqlite3ExprDelete(db, pRet);
148213
- }else{
148214
- pSel->pEList = sqlite3ExprListAppend(pParse, 0, pRet);
148215
- }
148216
- pEq->pLeft = 0;
148217
- pEq->pRight = 0;
148218
- if( ppAnd ){
148219
- Expr *pAnd = *ppAnd;
148220
- Expr *pOther = (pAnd->pLeft==pEq) ? pAnd->pRight : pAnd->pLeft;
148221
- pAnd->pLeft = pAnd->pRight = 0;
148222
- sqlite3ExprDelete(db, pAnd);
148223
- *ppAnd = pOther;
148224
- }else{
148225
- assert( pSel->pWhere==pEq );
148226
- pSel->pWhere = 0;
148227
- }
148228
- sqlite3ExprDelete(db, pEq);
148229
-
148230
-#ifdef WHERETRACE_ENABLED /* 0x20 */
148231
- if( sqlite3WhereTrace & 0x20 ){
148232
- sqlite3DebugPrintf("Convert EXISTS:\n");
148233
- sqlite3TreeViewExpr(0, pExpr, 0);
148234
- sqlite3DebugPrintf("into IN:\n");
148235
- sqlite3TreeViewExpr(0, pDup, 0);
148236
- }
148237
-#endif
148238
- idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC);
148239
- exprAnalyze(pSrc, pWC, idxNew);
148240
- markTermAsChild(pWC, idxNew, idxTerm);
148241
- pWC->a[idxTerm].wtFlags |= TERM_COPIED;
148242
-}
148243148269
148244148270
/*
148245148271
** The input to this routine is an WhereTerm structure with only the
148246148272
** "pExpr" field filled in. The job of this routine is to analyze the
148247148273
** subexpression and populate all the other fields of the WhereTerm
@@ -148337,10 +148363,11 @@
148337148363
pTerm->eOperator = operatorMask(op) & opMask;
148338148364
}
148339148365
if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
148340148366
if( pRight
148341148367
&& exprMightBeIndexed(pSrc, pTerm->prereqRight, aiCurCol, pRight, op)
148368
+ && !ExprHasProperty(pRight, EP_FixedCol)
148342148369
){
148343148370
WhereTerm *pNew;
148344148371
Expr *pDup;
148345148372
u16 eExtraOp = 0; /* Extra bits for pNew->eOperator */
148346148373
assert( pTerm->u.x.iField==0 );
@@ -148429,20 +148456,10 @@
148429148456
assert( pWC->op==TK_AND );
148430148457
exprAnalyzeOrTerm(pSrc, pWC, idxTerm);
148431148458
pTerm = &pWC->a[idxTerm];
148432148459
}
148433148460
#endif /* SQLITE_OMIT_OR_OPTIMIZATION */
148434
-
148435
- else if( pExpr->op==TK_EXISTS ){
148436
- /* Perhaps treat an EXISTS operator as an IN operator */
148437
- if( (pExpr->flags & EP_VarSelect)!=0
148438
- && OptimizationEnabled(db, SQLITE_ExistsToIN)
148439
- ){
148440
- exprAnalyzeExists(pSrc, pWC, idxTerm);
148441
- }
148442
- }
148443
-
148444148461
/* The form "x IS NOT NULL" can sometimes be evaluated more efficiently
148445148462
** as "x>NULL" if x is not an INTEGER PRIMARY KEY. So construct a
148446148463
** virtual term of that form.
148447148464
**
148448148465
** The virtual term must be tagged with TERM_VNULL.
@@ -149202,10 +149219,22 @@
149202149219
testcase( pTerm->eOperator & WO_IS );
149203149220
continue;
149204149221
}
149205149222
pScan->pWC = pWC;
149206149223
pScan->k = k+1;
149224
+#ifdef WHERETRACE_ENABLED
149225
+ if( sqlite3WhereTrace & 0x20000 ){
149226
+ int ii;
149227
+ sqlite3DebugPrintf("SCAN-TERM %p: nEquiv=%d",
149228
+ pTerm, pScan->nEquiv);
149229
+ for(ii=0; ii<pScan->nEquiv; ii++){
149230
+ sqlite3DebugPrintf(" {%d:%d}",
149231
+ pScan->aiCur[ii], pScan->aiColumn[ii]);
149232
+ }
149233
+ sqlite3DebugPrintf("\n");
149234
+ }
149235
+#endif
149207149236
return pTerm;
149208149237
}
149209149238
}
149210149239
}
149211149240
pWC = pWC->pOuter;
@@ -151365,10 +151394,12 @@
151365151394
opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE|WO_ISNULL|WO_IS;
151366151395
}
151367151396
if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE);
151368151397
151369151398
assert( pNew->u.btree.nEq<pProbe->nColumn );
151399
+ assert( pNew->u.btree.nEq<pProbe->nKeyCol
151400
+ || pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY );
151370151401
151371151402
saved_nEq = pNew->u.btree.nEq;
151372151403
saved_nBtm = pNew->u.btree.nBtm;
151373151404
saved_nTop = pNew->u.btree.nTop;
151374151405
saved_nSkip = pNew->nSkip;
@@ -151498,10 +151529,11 @@
151498151529
pNew->wsFlags |= WHERE_ONEROW;
151499151530
}else{
151500151531
pNew->wsFlags |= WHERE_UNQ_WANTED;
151501151532
}
151502151533
}
151534
+ if( scan.iEquiv>1 ) pNew->wsFlags |= WHERE_TRANSCONS;
151503151535
}else if( eOp & WO_ISNULL ){
151504151536
pNew->wsFlags |= WHERE_COLUMN_NULL;
151505151537
}else if( eOp & (WO_GT|WO_GE) ){
151506151538
testcase( eOp & WO_GT );
151507151539
testcase( eOp & WO_GE );
@@ -151641,10 +151673,12 @@
151641151673
pNew->nOut = nOutUnadjusted;
151642151674
}
151643151675
151644151676
if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
151645151677
&& pNew->u.btree.nEq<pProbe->nColumn
151678
+ && (pNew->u.btree.nEq<pProbe->nKeyCol ||
151679
+ pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY)
151646151680
){
151647151681
whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
151648151682
}
151649151683
pNew->nOut = saved_nOut;
151650151684
#ifdef SQLITE_ENABLE_STAT4
@@ -153009,11 +153043,11 @@
153009153043
if( (pWInfo->wctrlFlags & WHERE_USE_LIMIT)!=0 && pWInfo->iLimit<nRow ){
153010153044
nRow = pWInfo->iLimit;
153011153045
}else if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT) ){
153012153046
/* TUNING: In the sort for a DISTINCT operator, assume that the DISTINCT
153013153047
** reduces the number of output rows by a factor of 2 */
153014
- if( nRow>10 ) nRow -= 10; assert( 10==sqlite3LogEst(2) );
153048
+ if( nRow>10 ){ nRow -= 10; assert( 10==sqlite3LogEst(2) ); }
153015153049
}
153016153050
rSortCost += estLog(nRow);
153017153051
return rSortCost;
153018153052
}
153019153053
@@ -154299,10 +154333,12 @@
154299154333
if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
154300154334
struct InLoop *pIn;
154301154335
int j;
154302154336
sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
154303154337
for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
154338
+ assert( sqlite3VdbeGetOp(v, pIn->addrInTop+1)->opcode==OP_IsNull
154339
+ || pParse->db->mallocFailed );
154304154340
sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
154305154341
if( pIn->eEndLoopOp!=OP_Noop ){
154306154342
if( pIn->nPrefix ){
154307154343
int bEarlyOut =
154308154344
(pLoop->wsFlags & WHERE_VIRTUALTABLE)==0
@@ -154323,10 +154359,15 @@
154323154359
if( bEarlyOut ){
154324154360
sqlite3VdbeAddOp4Int(v, OP_IfNoHope, pLevel->iIdxCur,
154325154361
sqlite3VdbeCurrentAddr(v)+2,
154326154362
pIn->iBase, pIn->nPrefix);
154327154363
VdbeCoverage(v);
154364
+ /* Retarget the OP_IsNull against the left operand of IN so
154365
+ ** it jumps past the OP_IfNoHope. This is because the
154366
+ ** OP_IsNull also bypasses the OP_Affinity opcode that is
154367
+ ** required by OP_IfNoHope. */
154368
+ sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
154328154369
}
154329154370
}
154330154371
sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop);
154331154372
VdbeCoverage(v);
154332154373
VdbeCoverageIf(v, pIn->eEndLoopOp==OP_Prev);
@@ -155454,10 +155495,18 @@
155454155495
){
155455155496
pExpr->op2++;
155456155497
}
155457155498
return WRC_Continue;
155458155499
}
155500
+
155501
+static int disallowAggregatesInOrderByCb(Walker *pWalker, Expr *pExpr){
155502
+ if( pExpr->op==TK_AGG_FUNCTION && pExpr->pAggInfo==0 ){
155503
+ sqlite3ErrorMsg(pWalker->pParse,
155504
+ "misuse of aggregate: %s()", pExpr->u.zToken);
155505
+ }
155506
+ return WRC_Continue;
155507
+}
155459155508
155460155509
/*
155461155510
** If the SELECT statement passed as the second argument does not invoke
155462155511
** any SQL window functions, this function is a no-op. Otherwise, it
155463155512
** rewrites the SELECT statement so that window function xStep functions
@@ -155488,10 +155537,14 @@
155488155537
if( pTab==0 ){
155489155538
return sqlite3ErrorToParser(db, SQLITE_NOMEM);
155490155539
}
155491155540
sqlite3AggInfoPersistWalkerInit(&w, pParse);
155492155541
sqlite3WalkSelect(&w, p);
155542
+ if( (p->selFlags & SF_Aggregate)==0 ){
155543
+ w.xExprCallback = disallowAggregatesInOrderByCb;
155544
+ sqlite3WalkExprList(&w, p->pOrderBy);
155545
+ }
155493155546
155494155547
p->pSrc = 0;
155495155548
p->pWhere = 0;
155496155549
p->pGroupBy = 0;
155497155550
p->pHaving = 0;
@@ -164970,11 +165023,11 @@
164970165023
}
164971165024
if( rc==SQLITE_OK ){
164972165025
sqlite3GlobalConfig.isPCacheInit = 1;
164973165026
rc = sqlite3OsInit();
164974165027
}
164975
-#ifdef SQLITE_ENABLE_DESERIALIZE
165028
+#ifndef SQLITE_OMIT_DESERIALIZE
164976165029
if( rc==SQLITE_OK ){
164977165030
rc = sqlite3MemdbInit();
164978165031
}
164979165032
#endif
164980165033
if( rc==SQLITE_OK ){
@@ -165385,16 +165438,16 @@
165385165438
sqlite3GlobalConfig.szSorterRef = (u32)iVal;
165386165439
break;
165387165440
}
165388165441
#endif /* SQLITE_ENABLE_SORTER_REFERENCES */
165389165442
165390
-#ifdef SQLITE_ENABLE_DESERIALIZE
165443
+#ifndef SQLITE_OMIT_DESERIALIZE
165391165444
case SQLITE_CONFIG_MEMDB_MAXSIZE: {
165392165445
sqlite3GlobalConfig.mxMemdbSize = va_arg(ap, sqlite3_int64);
165393165446
break;
165394165447
}
165395
-#endif /* SQLITE_ENABLE_DESERIALIZE */
165448
+#endif /* SQLITE_OMIT_DESERIALIZE */
165396165449
165397165450
default: {
165398165451
rc = SQLITE_ERROR;
165399165452
break;
165400165453
}
@@ -172515,11 +172568,11 @@
172515172568
const char *zCsr = zNode; /* Cursor to iterate through node */
172516172569
const char *zEnd = &zCsr[nNode];/* End of interior node buffer */
172517172570
char *zBuffer = 0; /* Buffer to load terms into */
172518172571
i64 nAlloc = 0; /* Size of allocated buffer */
172519172572
int isFirstTerm = 1; /* True when processing first term on page */
172520
- sqlite3_int64 iChild; /* Block id of child node to descend to */
172573
+ u64 iChild; /* Block id of child node to descend to */
172521172574
int nBuffer = 0; /* Total term size */
172522172575
172523172576
/* Skip over the 'height' varint that occurs at the start of every
172524172577
** interior node. Then load the blockid of the left-child of the b-tree
172525172578
** node into variable iChild.
@@ -172531,12 +172584,12 @@
172531172584
** either more than 20 bytes of allocated space following the nNode bytes of
172532172585
** contents, or two zero bytes. Or, if the node is read from the %_segments
172533172586
** table, then there are always 20 bytes of zeroed padding following the
172534172587
** nNode bytes of content (see sqlite3Fts3ReadBlock() for details).
172535172588
*/
172536
- zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
172537
- zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
172589
+ zCsr += sqlite3Fts3GetVarintU(zCsr, &iChild);
172590
+ zCsr += sqlite3Fts3GetVarintU(zCsr, &iChild);
172538172591
if( zCsr>zEnd ){
172539172592
return FTS_CORRUPT_VTAB;
172540172593
}
172541172594
172542172595
while( zCsr<zEnd && (piFirst || piLast) ){
@@ -172585,24 +172638,24 @@
172585172638
** If the interior node term is larger than the specified term, then
172586172639
** the tree headed by iChild may contain the specified term.
172587172640
*/
172588172641
cmp = memcmp(zTerm, zBuffer, (nBuffer>nTerm ? nTerm : nBuffer));
172589172642
if( piFirst && (cmp<0 || (cmp==0 && nBuffer>nTerm)) ){
172590
- *piFirst = iChild;
172643
+ *piFirst = (i64)iChild;
172591172644
piFirst = 0;
172592172645
}
172593172646
172594172647
if( piLast && cmp<0 ){
172595
- *piLast = iChild;
172648
+ *piLast = (i64)iChild;
172596172649
piLast = 0;
172597172650
}
172598172651
172599172652
iChild++;
172600172653
};
172601172654
172602
- if( piFirst ) *piFirst = iChild;
172603
- if( piLast ) *piLast = iChild;
172655
+ if( piFirst ) *piFirst = (i64)iChild;
172656
+ if( piLast ) *piLast = (i64)iChild;
172604172657
172605172658
finish_scan:
172606172659
sqlite3_free(zBuffer);
172607172660
return rc;
172608172661
}
@@ -189485,11 +189538,11 @@
189485189538
** any double-quotes or backslash characters contained within the
189486189539
** string.
189487189540
*/
189488189541
static void jsonAppendString(JsonString *p, const char *zIn, u32 N){
189489189542
u32 i;
189490
- if( (N+p->nUsed+2 >= p->nAlloc) && jsonGrow(p,N+2)!=0 ) return;
189543
+ if( zIn==0 || ((N+p->nUsed+2 >= p->nAlloc) && jsonGrow(p,N+2)!=0) ) return;
189491189544
p->zBuf[p->nUsed++] = '"';
189492189545
for(i=0; i<N; i++){
189493189546
unsigned char c = ((unsigned const char*)zIn)[i];
189494189547
if( c=='"' || c=='\\' ){
189495189548
json_simple_escape:
@@ -201243,11 +201296,13 @@
201243201296
);
201244201297
if( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSel) ){
201245201298
zSep = "";
201246201299
for(iCol=0; iCol<pIter->nCol; iCol++){
201247201300
const char *zQuoted = (const char*)sqlite3_column_text(pSel, iCol);
201248
- if( zQuoted[0]=='N' ){
201301
+ if( zQuoted==0 ){
201302
+ p->rc = SQLITE_NOMEM;
201303
+ }else if( zQuoted[0]=='N' ){
201249201304
bFailed = 1;
201250201305
break;
201251201306
}
201252201307
zVector = rbuMPrintf(p, "%z%s%s", zVector, zSep, zQuoted);
201253201308
zSep = ", ";
@@ -204615,32 +204670,18 @@
204615204670
}
204616204671
else if( flags & SQLITE_OPEN_WAL ){
204617204672
rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName, 0);
204618204673
if( pDb ){
204619204674
if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
204620
- /* This call is to open a *-wal file. Intead, open the *-oal. This
204621
- ** code ensures that the string passed to xOpen() is terminated by a
204622
- ** pair of '\0' bytes in case the VFS attempts to extract a URI
204623
- ** parameter from it. */
204624
- const char *zBase = zName;
204625
- size_t nCopy;
204626
- char *zCopy;
204675
+ /* This call is to open a *-wal file. Intead, open the *-oal. */
204676
+ size_t nOpen;
204627204677
if( rbuIsVacuum(pDb->pRbu) ){
204628
- zBase = sqlite3_db_filename(pDb->pRbu->dbRbu, "main");
204629
- zBase = sqlite3_filename_wal(zBase);
204630
- }
204631
- nCopy = strlen(zBase);
204632
- zCopy = sqlite3_malloc64(nCopy+2);
204633
- if( zCopy ){
204634
- memcpy(zCopy, zBase, nCopy);
204635
- zCopy[nCopy-3] = 'o';
204636
- zCopy[nCopy] = '\0';
204637
- zCopy[nCopy+1] = '\0';
204638
- zOpen = (const char*)(pFd->zDel = zCopy);
204639
- }else{
204640
- rc = SQLITE_NOMEM;
204641
- }
204678
+ zOpen = sqlite3_db_filename(pDb->pRbu->dbRbu, "main");
204679
+ zOpen = sqlite3_filename_wal(zOpen);
204680
+ }
204681
+ nOpen = strlen(zOpen);
204682
+ ((char*)zOpen)[nOpen-3] = 'o';
204642204683
pFd->pRbu = pDb->pRbu;
204643204684
}
204644204685
pDb->pWalFd = pFd;
204645204686
}
204646204687
}
@@ -222669,11 +222710,10 @@
222669222710
}else{
222670222711
/* The following could be done by calling fts5SegIterLoadNPos(). But
222671222712
** this block is particularly performance critical, so equivalent
222672222713
** code is inlined. */
222673222714
int nSz;
222674
- assert( p->rc==SQLITE_OK );
222675222715
assert_nc( pIter->iLeafOffset<=pIter->pLeaf->nn );
222676222716
fts5FastGetVarint32(pIter->pLeaf->p, pIter->iLeafOffset, nSz);
222677222717
pIter->bDel = (nSz & 0x0001);
222678222718
pIter->nPos = nSz>>1;
222679222719
assert_nc( pIter->nPos>=0 );
@@ -230123,11 +230163,11 @@
230123230163
int nArg, /* Number of args */
230124230164
sqlite3_value **apUnused /* Function arguments */
230125230165
){
230126230166
assert( nArg==0 );
230127230167
UNUSED_PARAM2(nArg, apUnused);
230128
- sqlite3_result_text(pCtx, "fts5: 2021-04-27 17:18:10 ff3538ae37a02f4f36a15cddd1245171e724aac9c84b2e576980fd3806302775", -1, SQLITE_TRANSIENT);
230168
+ sqlite3_result_text(pCtx, "fts5: 2021-05-14 15:37:00 cf63abbe559d04f993f99a37d41ba4a97c0261094f1d4cc05cfa23b1e11731f5", -1, SQLITE_TRANSIENT);
230129230169
}
230130230170
230131230171
/*
230132230172
** Return true if zName is the extension on one of the shadow tables used
230133230173
** by this module.
@@ -235049,12 +235089,12 @@
235049235089
}
235050235090
#endif /* SQLITE_CORE */
235051235091
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
235052235092
235053235093
/************** End of stmt.c ************************************************/
235054
-#if __LINE__!=235054
235094
+#if __LINE__!=235094
235055235095
#undef SQLITE_SOURCE_ID
235056
-#define SQLITE_SOURCE_ID "2021-04-28 17:37:26 65ec39f0f092fe29e1d4e9e96cf07a73d2ef7ce2c41b6f1cd3ab23546adaalt2"
235096
+#define SQLITE_SOURCE_ID "2021-05-14 15:37:00 cf63abbe559d04f993f99a37d41ba4a97c0261094f1d4cc05cfa23b1e117alt2"
235057235097
#endif
235058235098
/* Return the source-id for this library */
235059235099
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
235060235100
/************************** End of sqlite3.c ******************************/
235061235101
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1186,11 +1186,11 @@
1186 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1187 ** [sqlite_version()] and [sqlite_source_id()].
1188 */
1189 #define SQLITE_VERSION "3.36.0"
1190 #define SQLITE_VERSION_NUMBER 3036000
1191 #define SQLITE_SOURCE_ID "2021-04-28 17:37:26 65ec39f0f092fe29e1d4e9e96cf07a73d2ef7ce2c41b6f1cd3ab23546ada0e67"
1192
1193 /*
1194 ** CAPI3REF: Run-Time Library Version Numbers
1195 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1196 **
@@ -2202,10 +2202,14 @@
2202 ** currently has an SQL transaction open on the database. It is set to 0 if
2203 ** the database is not a wal-mode db, or if there is no such connection in any
2204 ** other process. This opcode cannot be used to detect transactions opened
2205 ** by clients within the current process, only within other processes.
2206 ** </ul>
 
 
 
 
2207 */
2208 #define SQLITE_FCNTL_LOCKSTATE 1
2209 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
2210 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
2211 #define SQLITE_FCNTL_LAST_ERRNO 4
@@ -2241,12 +2245,12 @@
2241 #define SQLITE_FCNTL_DATA_VERSION 35
2242 #define SQLITE_FCNTL_SIZE_LIMIT 36
2243 #define SQLITE_FCNTL_CKPT_DONE 37
2244 #define SQLITE_FCNTL_RESERVE_BYTES 38
2245 #define SQLITE_FCNTL_CKPT_START 39
2246
2247 #define SQLITE_FCNTL_EXTERNAL_READER 40
 
2248
2249 /* deprecated names */
2250 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
2251 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
2252 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -5255,10 +5259,19 @@
5255 ** changes to the content of the database files on disk.
5256 ** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
5257 ** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
5258 ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
5259 ** sqlite3_stmt_readonly() returns false for those commands.
 
 
 
 
 
 
 
 
 
5260 */
5261 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
5262
5263 /*
5264 ** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
@@ -5424,22 +5437,26 @@
5424 ** terminated. If any NUL characters occurs at byte offsets less than
5425 ** the value of the fourth parameter then the resulting string value will
5426 ** contain embedded NULs. The result of expressions involving strings
5427 ** with embedded NULs is undefined.
5428 **
5429 ** ^The fifth argument to the BLOB and string binding interfaces
5430 ** is a destructor used to dispose of the BLOB or
5431 ** string after SQLite has finished with it. ^The destructor is called
5432 ** to dispose of the BLOB or string even if the call to the bind API fails,
5433 ** except the destructor is not called if the third parameter is a NULL
5434 ** pointer or the fourth parameter is negative.
5435 ** ^If the fifth argument is
5436 ** the special value [SQLITE_STATIC], then SQLite assumes that the
5437 ** information is in static, unmanaged space and does not need to be freed.
5438 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
5439 ** SQLite makes its own private copy of the data immediately, before
5440 ** the sqlite3_bind_*() routine returns.
 
 
 
 
5441 **
5442 ** ^The sixth argument to sqlite3_bind_text64() must be one of
5443 ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
5444 ** to specify the encoding of the text in the third parameter. If
5445 ** the sixth argument to sqlite3_bind_text64() is not one of the
@@ -10875,12 +10892,12 @@
10875 **
10876 ** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the
10877 ** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory
10878 ** allocation error occurs.
10879 **
10880 ** This interface is only available if SQLite is compiled with the
10881 ** [SQLITE_ENABLE_DESERIALIZE] option.
10882 */
10883 SQLITE_API unsigned char *sqlite3_serialize(
10884 sqlite3 *db, /* The database connection */
10885 const char *zSchema, /* Which DB to serialize. ex: "main", "temp", ... */
10886 sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */
@@ -10927,12 +10944,12 @@
10927 **
10928 ** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the
10929 ** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then
10930 ** [sqlite3_free()] is invoked on argument P prior to returning.
10931 **
10932 ** This interface is only available if SQLite is compiled with the
10933 ** [SQLITE_ENABLE_DESERIALIZE] option.
10934 */
10935 SQLITE_API int sqlite3_deserialize(
10936 sqlite3 *db, /* The database connection */
10937 const char *zSchema, /* Which DB to reopen with the deserialization */
10938 unsigned char *pData, /* The serialized database content */
@@ -11184,18 +11201,15 @@
11184 ** METHOD: sqlite3_session
11185 **
11186 ** This method is used to configure a session object after it has been
11187 ** created. At present the only valid value for the second parameter is
11188 ** [SQLITE_SESSION_OBJCONFIG_SIZE].
11189 */
11190 SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
11191
11192 /*
11193 ** CAPI3REF: Arguments for sqlite3session_object_config()
11194 **
11195 ** The following values may passed as the the 4th parameter to
11196 ** [sqlite3session_object_config].
11197 **
11198 ** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
11199 ** This option is used to set, clear or query the flag that enables
11200 ** the [sqlite3session_changeset_size()] API. Because it imposes some
11201 ** computational overhead, this API is disabled by default. Argument
@@ -11206,10 +11220,14 @@
11206 ** variable is set to 1 if the sqlite3session_changeset_size() API is
11207 ** enabled following the current call, or 0 otherwise.
11208 **
11209 ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
11210 ** the first table has been attached to the session object.
 
 
 
 
11211 */
11212 #define SQLITE_SESSION_OBJCONFIG_SIZE 1
11213
11214 /*
11215 ** CAPI3REF: Enable Or Disable A Session Object
@@ -11454,15 +11472,15 @@
11454 void **ppChangeset /* OUT: Buffer containing changeset */
11455 );
11456
11457 /*
11458 ** CAPI3REF: Return An Upper-limit For The Size Of The Changeset
11459 ** METHOD: sqlite3session_changeset_size()
11460 **
11461 ** By default, this function always returns 0. For it to return
11462 ** a useful result, the sqlite3_session object must have been configured
11463 ** to enable this API using [sqlite3session_object_config()] with the
11464 ** SQLITE_SESSION_OBJCONFIG_SIZE verb.
11465 **
11466 ** When enabled, this function returns an upper limit, in bytes, for the size
11467 ** of the changeset that might be produced if sqlite3session_changeset() were
11468 ** called. The final changeset size might be equal to or smaller than the
@@ -17276,11 +17294,10 @@
17276 #define SQLITE_PushDown 0x00001000 /* The push-down optimization */
17277 #define SQLITE_SimplifyJoin 0x00002000 /* Convert LEFT JOIN to JOIN */
17278 #define SQLITE_SkipScan 0x00004000 /* Skip-scans */
17279 #define SQLITE_PropagateConst 0x00008000 /* The constant propagation opt */
17280 #define SQLITE_MinMaxOpt 0x00010000 /* The min/max optimization */
17281 #define SQLITE_ExistsToIN 0x00020000 /* The EXISTS-to-IN optimization */
17282 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
17283
17284 /*
17285 ** Macros for testing whether or not optimizations are enabled or disabled.
17286 */
@@ -19339,11 +19356,11 @@
19339 ** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE.
19340 */
19341 void (*xVdbeBranch)(void*,unsigned iSrcLine,u8 eThis,u8 eMx); /* Callback */
19342 void *pVdbeBranchArg; /* 1st argument */
19343 #endif
19344 #ifdef SQLITE_ENABLE_DESERIALIZE
19345 sqlite3_int64 mxMemdbSize; /* Default max memdb size */
19346 #endif
19347 #ifndef SQLITE_UNTESTABLE
19348 int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
19349 #endif
@@ -20235,11 +20252,11 @@
20235
20236 #if defined(SQLITE_NEED_ERR_NAME)
20237 SQLITE_PRIVATE const char *sqlite3ErrName(int);
20238 #endif
20239
20240 #ifdef SQLITE_ENABLE_DESERIALIZE
20241 SQLITE_PRIVATE int sqlite3MemdbInit(void);
20242 #endif
20243
20244 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
20245 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
@@ -20997,11 +21014,11 @@
20997 #endif
20998 #ifdef SQLITE_VDBE_COVERAGE
20999 0, /* xVdbeBranch */
21000 0, /* pVbeBranchArg */
21001 #endif
21002 #ifdef SQLITE_ENABLE_DESERIALIZE
21003 SQLITE_MEMDB_DEFAULT_MAXSIZE, /* mxMemdbSize */
21004 #endif
21005 #ifndef SQLITE_UNTESTABLE
21006 0, /* xTestCallback */
21007 #endif
@@ -48428,35 +48445,92 @@
48428 **
48429 ** This file also implements interface sqlite3_serialize() and
48430 ** sqlite3_deserialize().
48431 */
48432 /* #include "sqliteInt.h" */
48433 #ifdef SQLITE_ENABLE_DESERIALIZE
48434
48435 /*
48436 ** Forward declaration of objects used by this utility
48437 */
48438 typedef struct sqlite3_vfs MemVfs;
48439 typedef struct MemFile MemFile;
 
48440
48441 /* Access to a lower-level VFS that (might) implement dynamic loading,
48442 ** access to randomness, etc.
48443 */
48444 #define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
48445
48446 /* An open file */
48447 struct MemFile {
48448 sqlite3_file base; /* IO methods */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48449 sqlite3_int64 sz; /* Size of the file */
48450 sqlite3_int64 szAlloc; /* Space allocated to aData */
48451 sqlite3_int64 szMax; /* Maximum allowed size of the file */
48452 unsigned char *aData; /* content of the file */
 
48453 int nMmap; /* Number of memory mapped pages */
48454 unsigned mFlags; /* Flags */
 
 
 
 
 
 
 
 
 
 
48455 int eLock; /* Most recent lock against this file */
48456 };
48457
 
 
 
 
 
 
 
 
 
 
 
48458 /*
48459 ** Methods for MemFile
48460 */
48461 static int memdbClose(sqlite3_file*);
48462 static int memdbRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
@@ -48531,23 +48605,62 @@
48531 0, /* xShmUnmap */
48532 memdbFetch, /* xFetch */
48533 memdbUnfetch /* xUnfetch */
48534 };
48535
 
 
 
 
 
 
 
 
 
 
48536
48537
48538 /*
48539 ** Close an memdb-file.
48540 **
48541 ** The pData pointer is owned by the application, so there is nothing
48542 ** to free. Unless the SQLITE_DESERIALIZE_FREEONCLOSE flag is set,
48543 ** in which case we own the pData pointer and need to free it.
48544 */
48545 static int memdbClose(sqlite3_file *pFile){
48546 MemFile *p = (MemFile *)pFile;
48547 if( p->mFlags & SQLITE_DESERIALIZE_FREEONCLOSE ){
48548 sqlite3_free(p->aData);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48549 }
48550 return SQLITE_OK;
48551 }
48552
48553 /*
@@ -48557,24 +48670,27 @@
48557 sqlite3_file *pFile,
48558 void *zBuf,
48559 int iAmt,
48560 sqlite_int64 iOfst
48561 ){
48562 MemFile *p = (MemFile *)pFile;
 
48563 if( iOfst+iAmt>p->sz ){
48564 memset(zBuf, 0, iAmt);
48565 if( iOfst<p->sz ) memcpy(zBuf, p->aData+iOfst, p->sz - iOfst);
 
48566 return SQLITE_IOERR_SHORT_READ;
48567 }
48568 memcpy(zBuf, p->aData+iOfst, iAmt);
 
48569 return SQLITE_OK;
48570 }
48571
48572 /*
48573 ** Try to enlarge the memory allocation to hold at least sz bytes
48574 */
48575 static int memdbEnlarge(MemFile *p, sqlite3_int64 newSz){
48576 unsigned char *pNew;
48577 if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || p->nMmap>0 ){
48578 return SQLITE_FULL;
48579 }
48580 if( newSz>p->szMax ){
@@ -48596,23 +48712,31 @@
48596 sqlite3_file *pFile,
48597 const void *z,
48598 int iAmt,
48599 sqlite_int64 iOfst
48600 ){
48601 MemFile *p = (MemFile *)pFile;
48602 if( NEVER(p->mFlags & SQLITE_DESERIALIZE_READONLY) ) return SQLITE_READONLY;
 
 
 
 
 
 
48603 if( iOfst+iAmt>p->sz ){
48604 int rc;
48605 if( iOfst+iAmt>p->szAlloc
48606 && (rc = memdbEnlarge(p, iOfst+iAmt))!=SQLITE_OK
48607 ){
 
48608 return rc;
48609 }
48610 if( iOfst>p->sz ) memset(p->aData+p->sz, 0, iOfst-p->sz);
48611 p->sz = iOfst+iAmt;
48612 }
48613 memcpy(p->aData+iOfst, z, iAmt);
 
48614 return SQLITE_OK;
48615 }
48616
48617 /*
48618 ** Truncate an memdb-file.
@@ -48620,14 +48744,20 @@
48620 ** In rollback mode (which is always the case for memdb, as it does not
48621 ** support WAL mode) the truncate() method is only used to reduce
48622 ** the size of a file, never to increase the size.
48623 */
48624 static int memdbTruncate(sqlite3_file *pFile, sqlite_int64 size){
48625 MemFile *p = (MemFile *)pFile;
48626 if( NEVER(size>p->sz) ) return SQLITE_FULL;
48627 p->sz = size;
48628 return SQLITE_OK;
 
 
 
 
 
 
48629 }
48630
48631 /*
48632 ** Sync an memdb-file.
48633 */
@@ -48637,45 +48767,78 @@
48637
48638 /*
48639 ** Return the current file-size of an memdb-file.
48640 */
48641 static int memdbFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
48642 MemFile *p = (MemFile *)pFile;
 
48643 *pSize = p->sz;
 
48644 return SQLITE_OK;
48645 }
48646
48647 /*
48648 ** Lock an memdb-file.
48649 */
48650 static int memdbLock(sqlite3_file *pFile, int eLock){
48651 MemFile *p = (MemFile *)pFile;
48652 if( eLock>SQLITE_LOCK_SHARED
48653 && (p->mFlags & SQLITE_DESERIALIZE_READONLY)!=0
48654 ){
48655 return SQLITE_READONLY;
48656 }
48657 p->eLock = eLock;
48658 return SQLITE_OK;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48659 }
48660
48661 #if 0 /* Never used because memdbAccess() always returns false */
48662 /*
48663 ** Check if another file-handle holds a RESERVED lock on an memdb-file.
 
48664 */
48665 static int memdbCheckReservedLock(sqlite3_file *pFile, int *pResOut){
48666 *pResOut = 0;
48667 return SQLITE_OK;
48668 }
48669 #endif
 
48670
48671 /*
48672 ** File control method. For custom operations on an memdb-file.
48673 */
48674 static int memdbFileControl(sqlite3_file *pFile, int op, void *pArg){
48675 MemFile *p = (MemFile *)pFile;
48676 int rc = SQLITE_NOTFOUND;
 
48677 if( op==SQLITE_FCNTL_VFSNAME ){
48678 *(char**)pArg = sqlite3_mprintf("memdb(%p,%lld)", p->aData, p->sz);
48679 rc = SQLITE_OK;
48680 }
48681 if( op==SQLITE_FCNTL_SIZE_LIMIT ){
@@ -48689,10 +48852,11 @@
48689 }
48690 p->szMax = iLimit;
48691 *(sqlite3_int64*)pArg = iLimit;
48692 rc = SQLITE_OK;
48693 }
 
48694 return rc;
48695 }
48696
48697 #if 0 /* Not used because of SQLITE_IOCAP_POWERSAFE_OVERWRITE */
48698 /*
@@ -48718,47 +48882,110 @@
48718 sqlite3_file *pFile,
48719 sqlite3_int64 iOfst,
48720 int iAmt,
48721 void **pp
48722 ){
48723 MemFile *p = (MemFile *)pFile;
 
48724 if( iOfst+iAmt>p->sz ){
48725 *pp = 0;
48726 }else{
48727 p->nMmap++;
48728 *pp = (void*)(p->aData + iOfst);
48729 }
 
48730 return SQLITE_OK;
48731 }
48732
48733 /* Release a memory-mapped page */
48734 static int memdbUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
48735 MemFile *p = (MemFile *)pFile;
 
48736 p->nMmap--;
 
48737 return SQLITE_OK;
48738 }
48739
48740 /*
48741 ** Open an mem file handle.
48742 */
48743 static int memdbOpen(
48744 sqlite3_vfs *pVfs,
48745 const char *zName,
48746 sqlite3_file *pFile,
48747 int flags,
48748 int *pOutFlags
48749 ){
48750 MemFile *p = (MemFile*)pFile;
 
 
48751 if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
48752 return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFile, flags, pOutFlags);
48753 }
48754 memset(p, 0, sizeof(*p));
48755 p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48756 assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */
48757 *pOutFlags = flags | SQLITE_OPEN_MEMORY;
48758 pFile->pMethods = &memdb_io_methods;
48759 p->szMax = sqlite3GlobalConfig.mxMemdbSize;
48760 return SQLITE_OK;
48761 }
48762
48763 #if 0 /* Only used to delete rollback journals, super-journals, and WAL
48764 ** files, none of which exist in memdb. So this routine is never used */
@@ -48869,13 +49096,18 @@
48869 ** Translate a database connection pointer and schema name into a
48870 ** MemFile pointer.
48871 */
48872 static MemFile *memdbFromDbSchema(sqlite3 *db, const char *zSchema){
48873 MemFile *p = 0;
 
48874 int rc = sqlite3_file_control(db, zSchema, SQLITE_FCNTL_FILE_POINTER, &p);
48875 if( rc ) return 0;
48876 if( p->base.pMethods!=&memdb_io_methods ) return 0;
 
 
 
 
48877 return p;
48878 }
48879
48880 /*
48881 ** Return the serialization of a database
@@ -48907,16 +49139,18 @@
48907 p = memdbFromDbSchema(db, zSchema);
48908 iDb = sqlite3FindDbName(db, zSchema);
48909 if( piSize ) *piSize = -1;
48910 if( iDb<0 ) return 0;
48911 if( p ){
48912 if( piSize ) *piSize = p->sz;
 
 
48913 if( mFlags & SQLITE_SERIALIZE_NOCOPY ){
48914 pOut = p->aData;
48915 }else{
48916 pOut = sqlite3_malloc64( p->sz );
48917 if( pOut ) memcpy(pOut, p->aData, p->sz);
48918 }
48919 return pOut;
48920 }
48921 pBt = db->aDb[iDb].pBt;
48922 if( pBt==0 ) return 0;
@@ -49006,19 +49240,20 @@
49006 }
49007 p = memdbFromDbSchema(db, zSchema);
49008 if( p==0 ){
49009 rc = SQLITE_ERROR;
49010 }else{
49011 p->aData = pData;
 
49012 pData = 0;
49013 p->sz = szDb;
49014 p->szAlloc = szBuf;
49015 p->szMax = szBuf;
49016 if( p->szMax<sqlite3GlobalConfig.mxMemdbSize ){
49017 p->szMax = sqlite3GlobalConfig.mxMemdbSize;
49018 }
49019 p->mFlags = mFlags;
49020 rc = SQLITE_OK;
49021 }
49022
49023 end_deserialize:
49024 sqlite3_finalize(pStmt);
@@ -49043,11 +49278,11 @@
49043 ** is no way to reach it under most builds. */
49044 if( sz<sizeof(MemFile) ) sz = sizeof(MemFile); /*NO_TEST*/
49045 memdb_vfs.szOsFile = sz;
49046 return sqlite3_vfs_register(&memdb_vfs, 0);
49047 }
49048 #endif /* SQLITE_ENABLE_DESERIALIZE */
49049
49050 /************** End of memdb.c ***********************************************/
49051 /************** Begin file bitvec.c ******************************************/
49052 /*
49053 ** 2008 February 16
@@ -56958,11 +57193,11 @@
56958 u8 *pPtr;
56959 Pager *pPager = 0; /* Pager object to allocate and return */
56960 int rc = SQLITE_OK; /* Return code */
56961 int tempFile = 0; /* True for temp files (incl. in-memory files) */
56962 int memDb = 0; /* True if this is an in-memory file */
56963 #ifdef SQLITE_ENABLE_DESERIALIZE
56964 int memJM = 0; /* Memory journal mode */
56965 #else
56966 # define memJM 0
56967 #endif
56968 int readOnly = 0; /* True if this is a read-only file */
@@ -57162,11 +57397,11 @@
57162 */
57163 if( zFilename && zFilename[0] ){
57164 int fout = 0; /* VFS flags returned by xOpen() */
57165 rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout);
57166 assert( !memDb );
57167 #ifdef SQLITE_ENABLE_DESERIALIZE
57168 memJM = (fout&SQLITE_OPEN_MEMORY)!=0;
57169 #endif
57170 readOnly = (fout&SQLITE_OPEN_READONLY)!=0;
57171
57172 /* If the file was successfully opened for read/write access,
@@ -61004,11 +61239,10 @@
61004 static void walCleanupHash(Wal *pWal){
61005 WalHashLoc sLoc; /* Hash table location */
61006 int iLimit = 0; /* Zero values greater than this */
61007 int nByte; /* Number of bytes to zero in aPgno[] */
61008 int i; /* Used to iterate through aHash[] */
61009 int rc; /* Return code form walHashGet() */
61010
61011 assert( pWal->writeLock );
61012 testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE-1 );
61013 testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE );
61014 testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE+1 );
@@ -61019,12 +61253,12 @@
61019 ** the entry that corresponds to frame pWal->hdr.mxFrame. It is guaranteed
61020 ** that the page said hash-table and array reside on is already mapped.(1)
61021 */
61022 assert( pWal->nWiData>walFramePage(pWal->hdr.mxFrame) );
61023 assert( pWal->apWiData[walFramePage(pWal->hdr.mxFrame)] );
61024 rc = walHashGet(pWal, walFramePage(pWal->hdr.mxFrame), &sLoc);
61025 if( NEVER(rc) ) return; /* Defense-in-depth, in case (1) above is wrong */
61026
61027 /* Zero all hash-table entries that correspond to frame numbers greater
61028 ** than pWal->hdr.mxFrame.
61029 */
61030 iLimit = pWal->hdr.mxFrame - sLoc.iZero;
@@ -72271,11 +72505,13 @@
72271 assert( pFree>aData && (pFree - aData)<65536 );
72272 freeSpace(pPg, (u16)(pFree - aData), szFree);
72273 }
72274 pFree = pCell;
72275 szFree = sz;
72276 if( pFree+sz>pEnd ) return 0;
 
 
72277 }else{
72278 pFree = pCell;
72279 szFree += sz;
72280 }
72281 nRet++;
@@ -73247,10 +73483,11 @@
73247 /* Insert new divider cells into pParent. */
73248 for(i=0; i<nNew-1; i++){
73249 u8 *pCell;
73250 u8 *pTemp;
73251 int sz;
 
73252 MemPage *pNew = apNew[i];
73253 j = cntNew[i];
73254
73255 assert( j<nMaxCells );
73256 assert( b.apCell[j]!=0 );
@@ -73290,10 +73527,16 @@
73290 }
73291 }
73292 iOvflSpace += sz;
73293 assert( sz<=pBt->maxLocal+23 );
73294 assert( iOvflSpace <= (int)pBt->pageSize );
 
 
 
 
 
 
73295 insertCell(pParent, nxDiv+i, pCell, sz, pTemp, pNew->pgno, &rc);
73296 if( rc!=SQLITE_OK ) goto balance_cleanup;
73297 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
73298 }
73299
@@ -86617,10 +86860,15 @@
86617 printf(" <== R[%d]", (int)(p->pScopyFrom - &p[-iReg]));
86618 }
86619 printf("\n");
86620 sqlite3VdbeCheckMemInvariants(p);
86621 }
 
 
 
 
 
86622 #endif
86623
86624 #ifdef SQLITE_DEBUG
86625 /*
86626 ** Show the values of all registers in the virtual machine. Used for
@@ -90667,12 +90915,22 @@
90667 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90668 pC = p->apCsr[pOp->p1];
90669 assert( pC!=0 );
90670 assert( pOp->p3>=pOp->p2 );
90671 if( pC->seekHit<pOp->p2 ){
 
 
 
 
 
90672 pC->seekHit = pOp->p2;
90673 }else if( pC->seekHit>pOp->p3 ){
 
 
 
 
 
90674 pC->seekHit = pOp->p3;
90675 }
90676 break;
90677 }
90678
@@ -90783,10 +91041,15 @@
90783 case OP_IfNoHope: { /* jump, in3 */
90784 VdbeCursor *pC;
90785 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90786 pC = p->apCsr[pOp->p1];
90787 assert( pC!=0 );
 
 
 
 
 
90788 if( pC->seekHit>=pOp->p4.i ) break;
90789 /* Fall through into OP_NotFound */
90790 /* no break */ deliberate_fall_through
90791 }
90792 case OP_NoConflict: /* jump, in3 */
@@ -100897,22 +101160,11 @@
100897 Parse *pParse, /* Parsing context */
100898 Expr *pExpr, /* Add the "COLLATE" clause to this expression */
100899 const Token *pCollName, /* Name of collating sequence */
100900 int dequote /* True to dequote pCollName */
100901 ){
100902 assert( pExpr!=0 || pParse->db->mallocFailed );
100903 if( pExpr==0 ) return 0;
100904 if( pExpr->op==TK_VECTOR ){
100905 ExprList *pList = pExpr->x.pList;
100906 if( ALWAYS(pList!=0) ){
100907 int i;
100908 for(i=0; i<pList->nExpr; i++){
100909 pList->a[i].pExpr = sqlite3ExprAddCollateToken(pParse,pList->a[i].pExpr,
100910 pCollName, dequote);
100911 }
100912 }
100913 }else if( pCollName->n>0 ){
100914 Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, dequote);
100915 if( pNew ){
100916 pNew->pLeft = pExpr;
100917 pNew->flags |= EP_Collate|EP_Skip;
100918 pExpr = pNew;
@@ -107808,11 +108060,11 @@
107808 */
107809 static int renameUnmapSelectCb(Walker *pWalker, Select *p){
107810 Parse *pParse = pWalker->pParse;
107811 int i;
107812 if( pParse->nErr ) return WRC_Abort;
107813 if( NEVER(p->selFlags & SF_View) ) return WRC_Prune;
107814 if( ALWAYS(p->pEList) ){
107815 ExprList *pList = p->pEList;
107816 for(i=0; i<pList->nExpr; i++){
107817 if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){
107818 sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
@@ -111180,11 +111432,11 @@
111180 zFile = (const char *)sqlite3_value_text(argv[0]);
111181 zName = (const char *)sqlite3_value_text(argv[1]);
111182 if( zFile==0 ) zFile = "";
111183 if( zName==0 ) zName = "";
111184
111185 #ifdef SQLITE_ENABLE_DESERIALIZE
111186 # define REOPEN_AS_MEMDB(db) (db->init.reopenMemdb)
111187 #else
111188 # define REOPEN_AS_MEMDB(db) (0)
111189 #endif
111190
@@ -113000,10 +113252,26 @@
113000 /* iCol is a normal or stored column */
113001 return n;
113002 }
113003 }
113004 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113005
113006 /*
113007 ** Begin constructing a new table representation in memory. This is
113008 ** the first of several action routines that get called in response
113009 ** to a CREATE TABLE statement. In particular, this routine is called
@@ -113100,10 +113368,11 @@
113100 if( !noErr ){
113101 sqlite3ErrorMsg(pParse, "table %T already exists", pName);
113102 }else{
113103 assert( !db->init.busy || CORRUPT_DB );
113104 sqlite3CodeVerifySchema(pParse, iDb);
 
113105 }
113106 goto begin_table_error;
113107 }
113108 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
113109 sqlite3ErrorMsg(pParse, "there is already an index named %s", zName);
@@ -115150,11 +115419,14 @@
115150 assert( isView==0 || isView==LOCATE_VIEW );
115151 pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]);
115152 if( noErr ) db->suppressErr--;
115153
115154 if( pTab==0 ){
115155 if( noErr ) sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
 
 
 
115156 goto exit_drop_table;
115157 }
115158 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
115159 assert( iDb>=0 && iDb<db->nDb );
115160
@@ -115720,10 +115992,11 @@
115720 if( !ifNotExist ){
115721 sqlite3ErrorMsg(pParse, "index %s already exists", zName);
115722 }else{
115723 assert( !db->init.busy );
115724 sqlite3CodeVerifySchema(pParse, iDb);
 
115725 }
115726 goto exit_create_index;
115727 }
115728 }
115729 }else{
@@ -116200,11 +116473,11 @@
116200 x = pIdx->pTable->nRowLogEst;
116201 assert( 99==sqlite3LogEst(1000) );
116202 if( x<99 ){
116203 pIdx->pTable->nRowLogEst = x = 99;
116204 }
116205 if( pIdx->pPartIdxWhere!=0 ) x -= 10; assert( 10==sqlite3LogEst(2) );
116206 a[0] = x;
116207
116208 /* Estimate that a[1] is 10, a[2] is 9, a[3] is 8, a[4] is 7, a[5] is
116209 ** 6 and each subsequent value (if any) is 5. */
116210 memcpy(&a[1], aVal, nCopy*sizeof(LogEst));
@@ -116238,10 +116511,11 @@
116238 if( pIndex==0 ){
116239 if( !ifExists ){
116240 sqlite3ErrorMsg(pParse, "no such index: %S", pName->a);
116241 }else{
116242 sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
 
116243 }
116244 pParse->checkSchema = 1;
116245 goto exit_drop_index;
116246 }
116247 if( pIndex->idxType!=SQLITE_IDXTYPE_APPDEF ){
@@ -136029,11 +136303,11 @@
136029 ** is part of the AND-connected terms of the expression. For each term
136030 ** found, add it to the pConst structure.
136031 */
136032 static void findConstInWhere(WhereConst *pConst, Expr *pExpr){
136033 Expr *pRight, *pLeft;
136034 if( pExpr==0 ) return;
136035 if( ExprHasProperty(pExpr, EP_FromJoin) ) return;
136036 if( pExpr->op==TK_AND ){
136037 findConstInWhere(pConst, pExpr->pRight);
136038 findConstInWhere(pConst, pExpr->pLeft);
136039 return;
@@ -137888,11 +138162,12 @@
137888 /* Do the WHERE-clause constant propagation optimization if this is
137889 ** a join. No need to speed time on this operation for non-join queries
137890 ** as the equivalent optimization will be handled by query planner in
137891 ** sqlite3WhereBegin().
137892 */
137893 if( pTabList->nSrc>1
 
137894 && OptimizationEnabled(db, SQLITE_PropagateConst)
137895 && propagateConstants(pParse, p)
137896 ){
137897 #if SELECTTRACE_ENABLED
137898 if( sqlite3SelectTrace & 0x100 ){
@@ -144173,12 +144448,12 @@
144173 WhereClause *pOrigWC; /* Original, innermost WhereClause */
144174 WhereClause *pWC; /* WhereClause currently being scanned */
144175 const char *zCollName; /* Required collating sequence, if not NULL */
144176 Expr *pIdxExpr; /* Search for this index expression */
144177 char idxaff; /* Must match this affinity, if zCollName!=NULL */
144178 unsigned char nEquiv; /* Number of entries in aEquiv[] */
144179 unsigned char iEquiv; /* Next unused slot in aEquiv[] */
144180 u32 opMask; /* Acceptable operators */
144181 int k; /* Resume scanning at this->pWC->a[this->k] */
144182 int aiCur[11]; /* Cursors in the equivalence class */
144183 i16 aiColumn[11]; /* Corresponding column number in the eq-class */
144184 };
@@ -144483,10 +144758,11 @@
144483 #define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/
144484 #define WHERE_PARTIALIDX 0x00020000 /* The automatic index is partial */
144485 #define WHERE_IN_EARLYOUT 0x00040000 /* Perhaps quit IN loops early */
144486 #define WHERE_BIGNULL_SORT 0x00080000 /* Column nEq of index is BIGNULL */
144487 #define WHERE_IN_SEEKSCAN 0x00100000 /* Seek-scan optimization for IN */
 
144488
144489 #endif /* !defined(SQLITE_WHEREINT_H) */
144490
144491 /************** End of whereInt.h ********************************************/
144492 /************** Continuing where we left off in wherecode.c ******************/
@@ -144766,10 +145042,16 @@
144766 if( nLoop && (pTerm->wtFlags & TERM_LIKE)!=0 ){
144767 pTerm->wtFlags |= TERM_LIKECOND;
144768 }else{
144769 pTerm->wtFlags |= TERM_CODED;
144770 }
 
 
 
 
 
 
144771 if( pTerm->iParent<0 ) break;
144772 pTerm = &pTerm->pWC->a[pTerm->iParent];
144773 assert( pTerm!=0 );
144774 pTerm->nChild--;
144775 if( pTerm->nChild!=0 ) break;
@@ -145083,11 +145365,26 @@
145083 pLevel->u.in.nIn = 0;
145084 }
145085 sqlite3DbFree(pParse->db, aiMap);
145086 #endif
145087 }
145088 disableTerm(pLevel, pTerm);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145089 return iReg;
145090 }
145091
145092 /*
145093 ** Generate code that will evaluate all == and IN constraints for an
@@ -146197,13 +146494,11 @@
146197
146198 /* If we are doing a reverse order scan on an ascending index, or
146199 ** a forward order scan on a descending index, interchange the
146200 ** start and end terms (pRangeStart and pRangeEnd).
146201 */
146202 if( (nEq<pIdx->nKeyCol && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC))
146203 || (bRev && pIdx->nKeyCol==nEq)
146204 ){
146205 SWAP(WhereTerm *, pRangeEnd, pRangeStart);
146206 SWAP(u8, bSeekPastNull, bStopAtNull);
146207 SWAP(u8, nBtm, nTop);
146208 }
146209
@@ -147832,11 +148127,11 @@
147832 assert( !ExprHasProperty(pNew, EP_xIsSelect) );
147833 pNew->x.pList = pList;
147834 idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
147835 testcase( idxNew==0 );
147836 exprAnalyze(pSrc, pWC, idxNew);
147837 /* pTerm = &pWC->a[idxTerm]; // would be needed if pTerm where used again */
147838 markTermAsChild(pWC, idxNew, idxTerm);
147839 }else{
147840 sqlite3ExprListDelete(db, pList);
147841 }
147842 }
@@ -147956,10 +148251,11 @@
147956 assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE );
147957 assert( TK_IS<TK_GE && TK_ISNULL<TK_GE && TK_IN<TK_GE );
147958 assert( op<=TK_GE );
147959 if( pExpr->op==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){
147960 pExpr = pExpr->x.pList->a[0].pExpr;
 
147961 }
147962
147963 if( pExpr->op==TK_COLUMN ){
147964 aiCurCol[0] = pExpr->iTable;
147965 aiCurCol[1] = pExpr->iColumn;
@@ -147968,280 +148264,10 @@
147968 if( mPrereq==0 ) return 0; /* No table references */
147969 if( (mPrereq&(mPrereq-1))!=0 ) return 0; /* Refs more than one table */
147970 return exprMightBeIndexed2(pFrom,mPrereq,aiCurCol,pExpr);
147971 }
147972
147973 /*
147974 ** Expression callback for exprUsesSrclist().
147975 */
147976 static int exprUsesSrclistCb(Walker *p, Expr *pExpr){
147977 if( pExpr->op==TK_COLUMN ){
147978 SrcList *pSrc = p->u.pSrcList;
147979 int iCsr = pExpr->iTable;
147980 int ii;
147981 for(ii=0; ii<pSrc->nSrc; ii++){
147982 if( pSrc->a[ii].iCursor==iCsr ){
147983 return p->eCode ? WRC_Abort : WRC_Continue;
147984 }
147985 }
147986 return p->eCode ? WRC_Continue : WRC_Abort;
147987 }
147988 return WRC_Continue;
147989 }
147990
147991 /*
147992 ** Select callback for exprUsesSrclist().
147993 */
147994 static int exprUsesSrclistSelectCb(Walker *NotUsed1, Select *NotUsed2){
147995 UNUSED_PARAMETER(NotUsed1);
147996 UNUSED_PARAMETER(NotUsed2);
147997 return WRC_Abort;
147998 }
147999
148000 /*
148001 ** This function always returns true if expression pExpr contains
148002 ** a sub-select.
148003 **
148004 ** If there is no sub-select in pExpr, then return true if pExpr
148005 ** contains a TK_COLUMN node for a table that is (bUses==1)
148006 ** or is not (bUses==0) in pSrc.
148007 **
148008 ** Said another way:
148009 **
148010 ** bUses Return Meaning
148011 ** -------- ------ ------------------------------------------------
148012 **
148013 ** bUses==1 true pExpr contains either a sub-select or a
148014 ** TK_COLUMN referencing pSrc.
148015 **
148016 ** bUses==1 false pExpr contains no sub-selects and all TK_COLUMN
148017 ** nodes reference tables not found in pSrc
148018 **
148019 ** bUses==0 true pExpr contains either a sub-select or a TK_COLUMN
148020 ** that references a table not in pSrc.
148021 **
148022 ** bUses==0 false pExpr contains no sub-selects and all TK_COLUMN
148023 ** nodes reference pSrc
148024 */
148025 static int exprUsesSrclist(SrcList *pSrc, Expr *pExpr, int bUses){
148026 Walker sWalker;
148027 memset(&sWalker, 0, sizeof(Walker));
148028 sWalker.eCode = bUses;
148029 sWalker.u.pSrcList = pSrc;
148030 sWalker.xExprCallback = exprUsesSrclistCb;
148031 sWalker.xSelectCallback = exprUsesSrclistSelectCb;
148032 return (sqlite3WalkExpr(&sWalker, pExpr)==WRC_Abort);
148033 }
148034
148035 /*
148036 ** Context object used by exprExistsToInIter() as it iterates through an
148037 ** expression tree.
148038 */
148039 struct ExistsToInCtx {
148040 SrcList *pSrc; /* The tables in an EXISTS(SELECT ... FROM <here> ...) */
148041 Expr *pInLhs; /* OUT: Use this as the LHS of the IN operator */
148042 Expr *pEq; /* OUT: The == term that include pInLhs */
148043 Expr **ppAnd; /* OUT: The AND operator that includes pEq as a child */
148044 Expr **ppParent; /* The AND operator currently being examined */
148045 };
148046
148047 /*
148048 ** Iterate through all AND connected nodes in the expression tree
148049 ** headed by (*ppExpr), populating the structure passed as the first
148050 ** argument with the values required by exprAnalyzeExistsFindEq().
148051 **
148052 ** This function returns non-zero if the expression tree does not meet
148053 ** the two conditions described by the header comment for
148054 ** exprAnalyzeExistsFindEq(), or zero if it does.
148055 */
148056 static int exprExistsToInIter(struct ExistsToInCtx *p, Expr **ppExpr){
148057 Expr *pExpr = *ppExpr;
148058 switch( pExpr->op ){
148059 case TK_AND:
148060 p->ppParent = ppExpr;
148061 if( exprExistsToInIter(p, &pExpr->pLeft) ) return 1;
148062 p->ppParent = ppExpr;
148063 if( exprExistsToInIter(p, &pExpr->pRight) ) return 1;
148064 break;
148065 case TK_EQ: {
148066 int bLeft = exprUsesSrclist(p->pSrc, pExpr->pLeft, 0);
148067 int bRight = exprUsesSrclist(p->pSrc, pExpr->pRight, 0);
148068 if( bLeft || bRight ){
148069 if( (bLeft && bRight) || p->pInLhs ) return 1;
148070 p->pInLhs = bLeft ? pExpr->pLeft : pExpr->pRight;
148071 if( exprUsesSrclist(p->pSrc, p->pInLhs, 1) ) return 1;
148072 p->pEq = pExpr;
148073 p->ppAnd = p->ppParent;
148074 }
148075 break;
148076 }
148077 default:
148078 if( exprUsesSrclist(p->pSrc, pExpr, 0) ){
148079 return 1;
148080 }
148081 break;
148082 }
148083
148084 return 0;
148085 }
148086
148087 /*
148088 ** This function is used by exprAnalyzeExists() when creating virtual IN(...)
148089 ** terms equivalent to user-supplied EXIST(...) clauses. It splits the WHERE
148090 ** clause of the Select object passed as the first argument into one or more
148091 ** expressions joined by AND operators, and then tests if the following are
148092 ** true:
148093 **
148094 ** 1. Exactly one of the AND separated terms refers to the outer
148095 ** query, and it is an == (TK_EQ) expression.
148096 **
148097 ** 2. Only one side of the == expression refers to the outer query, and
148098 ** it does not refer to any columns from the inner query.
148099 **
148100 ** If both these conditions are true, then a pointer to the side of the ==
148101 ** expression that refers to the outer query is returned. The caller will
148102 ** use this expression as the LHS of the IN(...) virtual term. Or, if one
148103 ** or both of the above conditions are not true, NULL is returned.
148104 **
148105 ** If non-NULL is returned and ppEq is non-NULL, *ppEq is set to point
148106 ** to the == expression node before returning. If pppAnd is non-NULL and
148107 ** the == node is not the root of the WHERE clause, then *pppAnd is set
148108 ** to point to the pointer to the AND node that is the parent of the ==
148109 ** node within the WHERE expression tree.
148110 */
148111 static Expr *exprAnalyzeExistsFindEq(
148112 Select *pSel, /* The SELECT of the EXISTS */
148113 Expr **ppEq, /* OUT: == node from WHERE clause */
148114 Expr ***pppAnd /* OUT: Pointer to parent of ==, if any */
148115 ){
148116 struct ExistsToInCtx ctx;
148117 memset(&ctx, 0, sizeof(ctx));
148118 ctx.pSrc = pSel->pSrc;
148119 if( exprExistsToInIter(&ctx, &pSel->pWhere) ){
148120 return 0;
148121 }
148122 if( ppEq ) *ppEq = ctx.pEq;
148123 if( pppAnd ) *pppAnd = ctx.ppAnd;
148124 return ctx.pInLhs;
148125 }
148126
148127 /*
148128 ** Term idxTerm of the WHERE clause passed as the second argument is an
148129 ** EXISTS expression with a correlated SELECT statement on the RHS.
148130 ** This function analyzes the SELECT statement, and if possible adds an
148131 ** equivalent "? IN(SELECT...)" virtual term to the WHERE clause.
148132 **
148133 ** For an EXISTS term such as the following:
148134 **
148135 ** EXISTS (SELECT ... FROM <srclist> WHERE <e1> = <e2> AND <e3>)
148136 **
148137 ** The virtual IN() term added is:
148138 **
148139 ** <e1> IN (SELECT <e2> FROM <srclist> WHERE <e3>)
148140 **
148141 ** The virtual term is only added if the following conditions are met:
148142 **
148143 ** 1. The sub-select must not be an aggregate or use window functions,
148144 **
148145 ** 2. The sub-select must not be a compound SELECT,
148146 **
148147 ** 3. Expression <e1> must refer to at least one column from the outer
148148 ** query, and must not refer to any column from the inner query
148149 ** (i.e. from <srclist>).
148150 **
148151 ** 4. <e2> and <e3> must not refer to any values from the outer query.
148152 ** In other words, once <e1> has been removed, the inner query
148153 ** must not be correlated.
148154 **
148155 */
148156 static void exprAnalyzeExists(
148157 SrcList *pSrc, /* the FROM clause */
148158 WhereClause *pWC, /* the WHERE clause */
148159 int idxTerm /* Index of the term to be analyzed */
148160 ){
148161 Parse *pParse = pWC->pWInfo->pParse;
148162 WhereTerm *pTerm = &pWC->a[idxTerm];
148163 Expr *pExpr = pTerm->pExpr;
148164 Select *pSel = pExpr->x.pSelect;
148165 Expr *pDup = 0;
148166 Expr *pEq = 0;
148167 Expr *pRet = 0;
148168 Expr *pInLhs = 0;
148169 Expr **ppAnd = 0;
148170 int idxNew;
148171 sqlite3 *db = pParse->db;
148172
148173 assert( pExpr->op==TK_EXISTS );
148174 assert( (pExpr->flags & EP_VarSelect) && (pExpr->flags & EP_xIsSelect) );
148175
148176 if( pSel->selFlags & SF_Aggregate ) return;
148177 #ifndef SQLITE_OMIT_WINDOWFUNC
148178 if( pSel->pWin ) return;
148179 #endif
148180 if( pSel->pPrior ) return;
148181 if( pSel->pWhere==0 ) return;
148182 if( pSel->pLimit ) return;
148183 if( 0==exprAnalyzeExistsFindEq(pSel, 0, 0) ) return;
148184
148185 pDup = sqlite3ExprDup(db, pExpr, 0);
148186 if( db->mallocFailed ){
148187 sqlite3ExprDelete(db, pDup);
148188 return;
148189 }
148190 pSel = pDup->x.pSelect;
148191 sqlite3ExprListDelete(db, pSel->pEList);
148192 pSel->pEList = 0;
148193
148194 pInLhs = exprAnalyzeExistsFindEq(pSel, &pEq, &ppAnd);
148195 assert( pInLhs && pEq );
148196 assert( pEq==pSel->pWhere || ppAnd );
148197 if( pInLhs==pEq->pLeft ){
148198 pRet = pEq->pRight;
148199 }else{
148200 CollSeq *p = sqlite3ExprCompareCollSeq(pParse, pEq);
148201 pInLhs = sqlite3ExprAddCollateString(pParse, pInLhs, p?p->zName:"BINARY");
148202 pRet = pEq->pLeft;
148203 }
148204
148205 assert( pDup->pLeft==0 );
148206 pDup->op = TK_IN;
148207 pDup->pLeft = pInLhs;
148208 pDup->flags &= ~EP_VarSelect;
148209 if( pRet->op==TK_VECTOR ){
148210 pSel->pEList = pRet->x.pList;
148211 pRet->x.pList = 0;
148212 sqlite3ExprDelete(db, pRet);
148213 }else{
148214 pSel->pEList = sqlite3ExprListAppend(pParse, 0, pRet);
148215 }
148216 pEq->pLeft = 0;
148217 pEq->pRight = 0;
148218 if( ppAnd ){
148219 Expr *pAnd = *ppAnd;
148220 Expr *pOther = (pAnd->pLeft==pEq) ? pAnd->pRight : pAnd->pLeft;
148221 pAnd->pLeft = pAnd->pRight = 0;
148222 sqlite3ExprDelete(db, pAnd);
148223 *ppAnd = pOther;
148224 }else{
148225 assert( pSel->pWhere==pEq );
148226 pSel->pWhere = 0;
148227 }
148228 sqlite3ExprDelete(db, pEq);
148229
148230 #ifdef WHERETRACE_ENABLED /* 0x20 */
148231 if( sqlite3WhereTrace & 0x20 ){
148232 sqlite3DebugPrintf("Convert EXISTS:\n");
148233 sqlite3TreeViewExpr(0, pExpr, 0);
148234 sqlite3DebugPrintf("into IN:\n");
148235 sqlite3TreeViewExpr(0, pDup, 0);
148236 }
148237 #endif
148238 idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC);
148239 exprAnalyze(pSrc, pWC, idxNew);
148240 markTermAsChild(pWC, idxNew, idxTerm);
148241 pWC->a[idxTerm].wtFlags |= TERM_COPIED;
148242 }
148243
148244 /*
148245 ** The input to this routine is an WhereTerm structure with only the
148246 ** "pExpr" field filled in. The job of this routine is to analyze the
148247 ** subexpression and populate all the other fields of the WhereTerm
@@ -148337,10 +148363,11 @@
148337 pTerm->eOperator = operatorMask(op) & opMask;
148338 }
148339 if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
148340 if( pRight
148341 && exprMightBeIndexed(pSrc, pTerm->prereqRight, aiCurCol, pRight, op)
 
148342 ){
148343 WhereTerm *pNew;
148344 Expr *pDup;
148345 u16 eExtraOp = 0; /* Extra bits for pNew->eOperator */
148346 assert( pTerm->u.x.iField==0 );
@@ -148429,20 +148456,10 @@
148429 assert( pWC->op==TK_AND );
148430 exprAnalyzeOrTerm(pSrc, pWC, idxTerm);
148431 pTerm = &pWC->a[idxTerm];
148432 }
148433 #endif /* SQLITE_OMIT_OR_OPTIMIZATION */
148434
148435 else if( pExpr->op==TK_EXISTS ){
148436 /* Perhaps treat an EXISTS operator as an IN operator */
148437 if( (pExpr->flags & EP_VarSelect)!=0
148438 && OptimizationEnabled(db, SQLITE_ExistsToIN)
148439 ){
148440 exprAnalyzeExists(pSrc, pWC, idxTerm);
148441 }
148442 }
148443
148444 /* The form "x IS NOT NULL" can sometimes be evaluated more efficiently
148445 ** as "x>NULL" if x is not an INTEGER PRIMARY KEY. So construct a
148446 ** virtual term of that form.
148447 **
148448 ** The virtual term must be tagged with TERM_VNULL.
@@ -149202,10 +149219,22 @@
149202 testcase( pTerm->eOperator & WO_IS );
149203 continue;
149204 }
149205 pScan->pWC = pWC;
149206 pScan->k = k+1;
 
 
 
 
 
 
 
 
 
 
 
 
149207 return pTerm;
149208 }
149209 }
149210 }
149211 pWC = pWC->pOuter;
@@ -151365,10 +151394,12 @@
151365 opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE|WO_ISNULL|WO_IS;
151366 }
151367 if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE);
151368
151369 assert( pNew->u.btree.nEq<pProbe->nColumn );
 
 
151370
151371 saved_nEq = pNew->u.btree.nEq;
151372 saved_nBtm = pNew->u.btree.nBtm;
151373 saved_nTop = pNew->u.btree.nTop;
151374 saved_nSkip = pNew->nSkip;
@@ -151498,10 +151529,11 @@
151498 pNew->wsFlags |= WHERE_ONEROW;
151499 }else{
151500 pNew->wsFlags |= WHERE_UNQ_WANTED;
151501 }
151502 }
 
151503 }else if( eOp & WO_ISNULL ){
151504 pNew->wsFlags |= WHERE_COLUMN_NULL;
151505 }else if( eOp & (WO_GT|WO_GE) ){
151506 testcase( eOp & WO_GT );
151507 testcase( eOp & WO_GE );
@@ -151641,10 +151673,12 @@
151641 pNew->nOut = nOutUnadjusted;
151642 }
151643
151644 if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
151645 && pNew->u.btree.nEq<pProbe->nColumn
 
 
151646 ){
151647 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
151648 }
151649 pNew->nOut = saved_nOut;
151650 #ifdef SQLITE_ENABLE_STAT4
@@ -153009,11 +153043,11 @@
153009 if( (pWInfo->wctrlFlags & WHERE_USE_LIMIT)!=0 && pWInfo->iLimit<nRow ){
153010 nRow = pWInfo->iLimit;
153011 }else if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT) ){
153012 /* TUNING: In the sort for a DISTINCT operator, assume that the DISTINCT
153013 ** reduces the number of output rows by a factor of 2 */
153014 if( nRow>10 ) nRow -= 10; assert( 10==sqlite3LogEst(2) );
153015 }
153016 rSortCost += estLog(nRow);
153017 return rSortCost;
153018 }
153019
@@ -154299,10 +154333,12 @@
154299 if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
154300 struct InLoop *pIn;
154301 int j;
154302 sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
154303 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
 
 
154304 sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
154305 if( pIn->eEndLoopOp!=OP_Noop ){
154306 if( pIn->nPrefix ){
154307 int bEarlyOut =
154308 (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0
@@ -154323,10 +154359,15 @@
154323 if( bEarlyOut ){
154324 sqlite3VdbeAddOp4Int(v, OP_IfNoHope, pLevel->iIdxCur,
154325 sqlite3VdbeCurrentAddr(v)+2,
154326 pIn->iBase, pIn->nPrefix);
154327 VdbeCoverage(v);
 
 
 
 
 
154328 }
154329 }
154330 sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop);
154331 VdbeCoverage(v);
154332 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_Prev);
@@ -155454,10 +155495,18 @@
155454 ){
155455 pExpr->op2++;
155456 }
155457 return WRC_Continue;
155458 }
 
 
 
 
 
 
 
 
155459
155460 /*
155461 ** If the SELECT statement passed as the second argument does not invoke
155462 ** any SQL window functions, this function is a no-op. Otherwise, it
155463 ** rewrites the SELECT statement so that window function xStep functions
@@ -155488,10 +155537,14 @@
155488 if( pTab==0 ){
155489 return sqlite3ErrorToParser(db, SQLITE_NOMEM);
155490 }
155491 sqlite3AggInfoPersistWalkerInit(&w, pParse);
155492 sqlite3WalkSelect(&w, p);
 
 
 
 
155493
155494 p->pSrc = 0;
155495 p->pWhere = 0;
155496 p->pGroupBy = 0;
155497 p->pHaving = 0;
@@ -164970,11 +165023,11 @@
164970 }
164971 if( rc==SQLITE_OK ){
164972 sqlite3GlobalConfig.isPCacheInit = 1;
164973 rc = sqlite3OsInit();
164974 }
164975 #ifdef SQLITE_ENABLE_DESERIALIZE
164976 if( rc==SQLITE_OK ){
164977 rc = sqlite3MemdbInit();
164978 }
164979 #endif
164980 if( rc==SQLITE_OK ){
@@ -165385,16 +165438,16 @@
165385 sqlite3GlobalConfig.szSorterRef = (u32)iVal;
165386 break;
165387 }
165388 #endif /* SQLITE_ENABLE_SORTER_REFERENCES */
165389
165390 #ifdef SQLITE_ENABLE_DESERIALIZE
165391 case SQLITE_CONFIG_MEMDB_MAXSIZE: {
165392 sqlite3GlobalConfig.mxMemdbSize = va_arg(ap, sqlite3_int64);
165393 break;
165394 }
165395 #endif /* SQLITE_ENABLE_DESERIALIZE */
165396
165397 default: {
165398 rc = SQLITE_ERROR;
165399 break;
165400 }
@@ -172515,11 +172568,11 @@
172515 const char *zCsr = zNode; /* Cursor to iterate through node */
172516 const char *zEnd = &zCsr[nNode];/* End of interior node buffer */
172517 char *zBuffer = 0; /* Buffer to load terms into */
172518 i64 nAlloc = 0; /* Size of allocated buffer */
172519 int isFirstTerm = 1; /* True when processing first term on page */
172520 sqlite3_int64 iChild; /* Block id of child node to descend to */
172521 int nBuffer = 0; /* Total term size */
172522
172523 /* Skip over the 'height' varint that occurs at the start of every
172524 ** interior node. Then load the blockid of the left-child of the b-tree
172525 ** node into variable iChild.
@@ -172531,12 +172584,12 @@
172531 ** either more than 20 bytes of allocated space following the nNode bytes of
172532 ** contents, or two zero bytes. Or, if the node is read from the %_segments
172533 ** table, then there are always 20 bytes of zeroed padding following the
172534 ** nNode bytes of content (see sqlite3Fts3ReadBlock() for details).
172535 */
172536 zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
172537 zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
172538 if( zCsr>zEnd ){
172539 return FTS_CORRUPT_VTAB;
172540 }
172541
172542 while( zCsr<zEnd && (piFirst || piLast) ){
@@ -172585,24 +172638,24 @@
172585 ** If the interior node term is larger than the specified term, then
172586 ** the tree headed by iChild may contain the specified term.
172587 */
172588 cmp = memcmp(zTerm, zBuffer, (nBuffer>nTerm ? nTerm : nBuffer));
172589 if( piFirst && (cmp<0 || (cmp==0 && nBuffer>nTerm)) ){
172590 *piFirst = iChild;
172591 piFirst = 0;
172592 }
172593
172594 if( piLast && cmp<0 ){
172595 *piLast = iChild;
172596 piLast = 0;
172597 }
172598
172599 iChild++;
172600 };
172601
172602 if( piFirst ) *piFirst = iChild;
172603 if( piLast ) *piLast = iChild;
172604
172605 finish_scan:
172606 sqlite3_free(zBuffer);
172607 return rc;
172608 }
@@ -189485,11 +189538,11 @@
189485 ** any double-quotes or backslash characters contained within the
189486 ** string.
189487 */
189488 static void jsonAppendString(JsonString *p, const char *zIn, u32 N){
189489 u32 i;
189490 if( (N+p->nUsed+2 >= p->nAlloc) && jsonGrow(p,N+2)!=0 ) return;
189491 p->zBuf[p->nUsed++] = '"';
189492 for(i=0; i<N; i++){
189493 unsigned char c = ((unsigned const char*)zIn)[i];
189494 if( c=='"' || c=='\\' ){
189495 json_simple_escape:
@@ -201243,11 +201296,13 @@
201243 );
201244 if( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSel) ){
201245 zSep = "";
201246 for(iCol=0; iCol<pIter->nCol; iCol++){
201247 const char *zQuoted = (const char*)sqlite3_column_text(pSel, iCol);
201248 if( zQuoted[0]=='N' ){
 
 
201249 bFailed = 1;
201250 break;
201251 }
201252 zVector = rbuMPrintf(p, "%z%s%s", zVector, zSep, zQuoted);
201253 zSep = ", ";
@@ -204615,32 +204670,18 @@
204615 }
204616 else if( flags & SQLITE_OPEN_WAL ){
204617 rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName, 0);
204618 if( pDb ){
204619 if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
204620 /* This call is to open a *-wal file. Intead, open the *-oal. This
204621 ** code ensures that the string passed to xOpen() is terminated by a
204622 ** pair of '\0' bytes in case the VFS attempts to extract a URI
204623 ** parameter from it. */
204624 const char *zBase = zName;
204625 size_t nCopy;
204626 char *zCopy;
204627 if( rbuIsVacuum(pDb->pRbu) ){
204628 zBase = sqlite3_db_filename(pDb->pRbu->dbRbu, "main");
204629 zBase = sqlite3_filename_wal(zBase);
204630 }
204631 nCopy = strlen(zBase);
204632 zCopy = sqlite3_malloc64(nCopy+2);
204633 if( zCopy ){
204634 memcpy(zCopy, zBase, nCopy);
204635 zCopy[nCopy-3] = 'o';
204636 zCopy[nCopy] = '\0';
204637 zCopy[nCopy+1] = '\0';
204638 zOpen = (const char*)(pFd->zDel = zCopy);
204639 }else{
204640 rc = SQLITE_NOMEM;
204641 }
204642 pFd->pRbu = pDb->pRbu;
204643 }
204644 pDb->pWalFd = pFd;
204645 }
204646 }
@@ -222669,11 +222710,10 @@
222669 }else{
222670 /* The following could be done by calling fts5SegIterLoadNPos(). But
222671 ** this block is particularly performance critical, so equivalent
222672 ** code is inlined. */
222673 int nSz;
222674 assert( p->rc==SQLITE_OK );
222675 assert_nc( pIter->iLeafOffset<=pIter->pLeaf->nn );
222676 fts5FastGetVarint32(pIter->pLeaf->p, pIter->iLeafOffset, nSz);
222677 pIter->bDel = (nSz & 0x0001);
222678 pIter->nPos = nSz>>1;
222679 assert_nc( pIter->nPos>=0 );
@@ -230123,11 +230163,11 @@
230123 int nArg, /* Number of args */
230124 sqlite3_value **apUnused /* Function arguments */
230125 ){
230126 assert( nArg==0 );
230127 UNUSED_PARAM2(nArg, apUnused);
230128 sqlite3_result_text(pCtx, "fts5: 2021-04-27 17:18:10 ff3538ae37a02f4f36a15cddd1245171e724aac9c84b2e576980fd3806302775", -1, SQLITE_TRANSIENT);
230129 }
230130
230131 /*
230132 ** Return true if zName is the extension on one of the shadow tables used
230133 ** by this module.
@@ -235049,12 +235089,12 @@
235049 }
235050 #endif /* SQLITE_CORE */
235051 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
235052
235053 /************** End of stmt.c ************************************************/
235054 #if __LINE__!=235054
235055 #undef SQLITE_SOURCE_ID
235056 #define SQLITE_SOURCE_ID "2021-04-28 17:37:26 65ec39f0f092fe29e1d4e9e96cf07a73d2ef7ce2c41b6f1cd3ab23546adaalt2"
235057 #endif
235058 /* Return the source-id for this library */
235059 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
235060 /************************** End of sqlite3.c ******************************/
235061
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1186,11 +1186,11 @@
1186 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1187 ** [sqlite_version()] and [sqlite_source_id()].
1188 */
1189 #define SQLITE_VERSION "3.36.0"
1190 #define SQLITE_VERSION_NUMBER 3036000
1191 #define SQLITE_SOURCE_ID "2021-05-14 15:37:00 cf63abbe559d04f993f99a37d41ba4a97c0261094f1d4cc05cfa23b1e11731f5"
1192
1193 /*
1194 ** CAPI3REF: Run-Time Library Version Numbers
1195 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1196 **
@@ -2202,10 +2202,14 @@
2202 ** currently has an SQL transaction open on the database. It is set to 0 if
2203 ** the database is not a wal-mode db, or if there is no such connection in any
2204 ** other process. This opcode cannot be used to detect transactions opened
2205 ** by clients within the current process, only within other processes.
2206 ** </ul>
2207 **
2208 ** <li>[[SQLITE_FCNTL_CKSM_FILE]]
2209 ** Used by the cksmvfs VFS module only.
2210 ** </ul>
2211 */
2212 #define SQLITE_FCNTL_LOCKSTATE 1
2213 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
2214 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
2215 #define SQLITE_FCNTL_LAST_ERRNO 4
@@ -2241,12 +2245,12 @@
2245 #define SQLITE_FCNTL_DATA_VERSION 35
2246 #define SQLITE_FCNTL_SIZE_LIMIT 36
2247 #define SQLITE_FCNTL_CKPT_DONE 37
2248 #define SQLITE_FCNTL_RESERVE_BYTES 38
2249 #define SQLITE_FCNTL_CKPT_START 39
 
2250 #define SQLITE_FCNTL_EXTERNAL_READER 40
2251 #define SQLITE_FCNTL_CKSM_FILE 41
2252
2253 /* deprecated names */
2254 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
2255 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
2256 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -5255,10 +5259,19 @@
5259 ** changes to the content of the database files on disk.
5260 ** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
5261 ** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
5262 ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
5263 ** sqlite3_stmt_readonly() returns false for those commands.
5264 **
5265 ** ^This routine returns false if there is any possibility that the
5266 ** statement might change the database file. ^A false return does
5267 ** not guarantee that the statement will change the database file.
5268 ** ^For example, an UPDATE statement might have a WHERE clause that
5269 ** makes it a no-op, but the sqlite3_stmt_readonly() result would still
5270 ** be false. ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a
5271 ** read-only no-op if the table already exists, but
5272 ** sqlite3_stmt_readonly() still returns false for such a statement.
5273 */
5274 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
5275
5276 /*
5277 ** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
@@ -5424,22 +5437,26 @@
5437 ** terminated. If any NUL characters occurs at byte offsets less than
5438 ** the value of the fourth parameter then the resulting string value will
5439 ** contain embedded NULs. The result of expressions involving strings
5440 ** with embedded NULs is undefined.
5441 **
5442 ** ^The fifth argument to the BLOB and string binding interfaces controls
5443 ** or indicates the lifetime of the object referenced by the third parameter.
5444 ** ^These three options exist:
5445 ** ^(1) A destructor to dispose of the BLOB or string after SQLite has finished
5446 ** with it may be passed. ^It is called to dispose of the BLOB or string even
5447 ** if the call to the bind API fails, except the destructor is not called if
5448 ** the third parameter is a NULL pointer or the fourth parameter is negative.
5449 ** ^(2) The special constant, [SQLITE_STATIC], may be passsed to indicate that
5450 ** the application remains responsible for disposing of the object. ^In this
5451 ** case, the object and the provided pointer to it must remain valid until
5452 ** either the prepared statement is finalized or the same SQL parameter is
5453 ** bound to something else, whichever occurs sooner.
5454 ** ^(3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the
5455 ** object is to be copied prior to the return from sqlite3_bind_*(). ^The
5456 ** object and pointer to it must remain valid until then. ^SQLite will then
5457 ** manage the lifetime of its private copy.
5458 **
5459 ** ^The sixth argument to sqlite3_bind_text64() must be one of
5460 ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
5461 ** to specify the encoding of the text in the third parameter. If
5462 ** the sixth argument to sqlite3_bind_text64() is not one of the
@@ -10875,12 +10892,12 @@
10892 **
10893 ** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the
10894 ** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory
10895 ** allocation error occurs.
10896 **
10897 ** This interface is omitted if SQLite is compiled with the
10898 ** [SQLITE_OMIT_DESERIALIZE] option.
10899 */
10900 SQLITE_API unsigned char *sqlite3_serialize(
10901 sqlite3 *db, /* The database connection */
10902 const char *zSchema, /* Which DB to serialize. ex: "main", "temp", ... */
10903 sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */
@@ -10927,12 +10944,12 @@
10944 **
10945 ** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the
10946 ** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then
10947 ** [sqlite3_free()] is invoked on argument P prior to returning.
10948 **
10949 ** This interface is omitted if SQLite is compiled with the
10950 ** [SQLITE_OMIT_DESERIALIZE] option.
10951 */
10952 SQLITE_API int sqlite3_deserialize(
10953 sqlite3 *db, /* The database connection */
10954 const char *zSchema, /* Which DB to reopen with the deserialization */
10955 unsigned char *pData, /* The serialized database content */
@@ -11184,18 +11201,15 @@
11201 ** METHOD: sqlite3_session
11202 **
11203 ** This method is used to configure a session object after it has been
11204 ** created. At present the only valid value for the second parameter is
11205 ** [SQLITE_SESSION_OBJCONFIG_SIZE].
11206 **
11207 ** Arguments for sqlite3session_object_config()
 
 
 
11208 **
11209 ** The following values may passed as the the 4th parameter to
11210 ** sqlite3session_object_config().
11211 **
11212 ** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
11213 ** This option is used to set, clear or query the flag that enables
11214 ** the [sqlite3session_changeset_size()] API. Because it imposes some
11215 ** computational overhead, this API is disabled by default. Argument
@@ -11206,10 +11220,14 @@
11220 ** variable is set to 1 if the sqlite3session_changeset_size() API is
11221 ** enabled following the current call, or 0 otherwise.
11222 **
11223 ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
11224 ** the first table has been attached to the session object.
11225 */
11226 SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
11227
11228 /*
11229 */
11230 #define SQLITE_SESSION_OBJCONFIG_SIZE 1
11231
11232 /*
11233 ** CAPI3REF: Enable Or Disable A Session Object
@@ -11454,15 +11472,15 @@
11472 void **ppChangeset /* OUT: Buffer containing changeset */
11473 );
11474
11475 /*
11476 ** CAPI3REF: Return An Upper-limit For The Size Of The Changeset
11477 ** METHOD: sqlite3_session
11478 **
11479 ** By default, this function always returns 0. For it to return
11480 ** a useful result, the sqlite3_session object must have been configured
11481 ** to enable this API using sqlite3session_object_config() with the
11482 ** SQLITE_SESSION_OBJCONFIG_SIZE verb.
11483 **
11484 ** When enabled, this function returns an upper limit, in bytes, for the size
11485 ** of the changeset that might be produced if sqlite3session_changeset() were
11486 ** called. The final changeset size might be equal to or smaller than the
@@ -17276,11 +17294,10 @@
17294 #define SQLITE_PushDown 0x00001000 /* The push-down optimization */
17295 #define SQLITE_SimplifyJoin 0x00002000 /* Convert LEFT JOIN to JOIN */
17296 #define SQLITE_SkipScan 0x00004000 /* Skip-scans */
17297 #define SQLITE_PropagateConst 0x00008000 /* The constant propagation opt */
17298 #define SQLITE_MinMaxOpt 0x00010000 /* The min/max optimization */
 
17299 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
17300
17301 /*
17302 ** Macros for testing whether or not optimizations are enabled or disabled.
17303 */
@@ -19339,11 +19356,11 @@
19356 ** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE.
19357 */
19358 void (*xVdbeBranch)(void*,unsigned iSrcLine,u8 eThis,u8 eMx); /* Callback */
19359 void *pVdbeBranchArg; /* 1st argument */
19360 #endif
19361 #ifndef SQLITE_OMIT_DESERIALIZE
19362 sqlite3_int64 mxMemdbSize; /* Default max memdb size */
19363 #endif
19364 #ifndef SQLITE_UNTESTABLE
19365 int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
19366 #endif
@@ -20235,11 +20252,11 @@
20252
20253 #if defined(SQLITE_NEED_ERR_NAME)
20254 SQLITE_PRIVATE const char *sqlite3ErrName(int);
20255 #endif
20256
20257 #ifndef SQLITE_OMIT_DESERIALIZE
20258 SQLITE_PRIVATE int sqlite3MemdbInit(void);
20259 #endif
20260
20261 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
20262 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
@@ -20997,11 +21014,11 @@
21014 #endif
21015 #ifdef SQLITE_VDBE_COVERAGE
21016 0, /* xVdbeBranch */
21017 0, /* pVbeBranchArg */
21018 #endif
21019 #ifndef SQLITE_OMIT_DESERIALIZE
21020 SQLITE_MEMDB_DEFAULT_MAXSIZE, /* mxMemdbSize */
21021 #endif
21022 #ifndef SQLITE_UNTESTABLE
21023 0, /* xTestCallback */
21024 #endif
@@ -48428,35 +48445,92 @@
48445 **
48446 ** This file also implements interface sqlite3_serialize() and
48447 ** sqlite3_deserialize().
48448 */
48449 /* #include "sqliteInt.h" */
48450 #ifndef SQLITE_OMIT_DESERIALIZE
48451
48452 /*
48453 ** Forward declaration of objects used by this utility
48454 */
48455 typedef struct sqlite3_vfs MemVfs;
48456 typedef struct MemFile MemFile;
48457 typedef struct MemStore MemStore;
48458
48459 /* Access to a lower-level VFS that (might) implement dynamic loading,
48460 ** access to randomness, etc.
48461 */
48462 #define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
48463
48464 /* Storage for a memdb file.
48465 **
48466 ** An memdb object can be shared or separate. Shared memdb objects can be
48467 ** used by more than one database connection. Mutexes are used by shared
48468 ** memdb objects to coordinate access. Separate memdb objects are only
48469 ** connected to a single database connection and do not require additional
48470 ** mutexes.
48471 **
48472 ** Shared memdb objects have .zFName!=0 and .pMutex!=0. They are created
48473 ** using "file:/name?vfs=memdb". The first character of the name must be
48474 ** "/" or else the object will be a separate memdb object. All shared
48475 ** memdb objects are stored in memdb_g.apMemStore[] in an arbitrary order.
48476 **
48477 ** Separate memdb objects are created using a name that does not begin
48478 ** with "/" or using sqlite3_deserialize().
48479 **
48480 ** Access rules for shared MemStore objects:
48481 **
48482 ** * .zFName is initialized when the object is created and afterwards
48483 ** is unchanged until the object is destroyed. So it can be accessed
48484 ** at any time as long as we know the object is not being destroyed,
48485 ** which means while either the SQLITE_MUTEX_STATIC_VFS1 or
48486 ** .pMutex is held or the object is not part of memdb_g.apMemStore[].
48487 **
48488 ** * Can .pMutex can only be changed while holding the
48489 ** SQLITE_MUTEX_STATIC_VFS1 mutex or while the object is not part
48490 ** of memdb_g.apMemStore[].
48491 **
48492 ** * Other fields can only be changed while holding the .pMutex mutex
48493 ** or when the .nRef is less than zero and the object is not part of
48494 ** memdb_g.apMemStore[].
48495 **
48496 ** * The .aData pointer has the added requirement that it can can only
48497 ** be changed (for resizing) when nMmap is zero.
48498 **
48499 */
48500 struct MemStore {
48501 sqlite3_int64 sz; /* Size of the file */
48502 sqlite3_int64 szAlloc; /* Space allocated to aData */
48503 sqlite3_int64 szMax; /* Maximum allowed size of the file */
48504 unsigned char *aData; /* content of the file */
48505 sqlite3_mutex *pMutex; /* Used by shared stores only */
48506 int nMmap; /* Number of memory mapped pages */
48507 unsigned mFlags; /* Flags */
48508 int nRdLock; /* Number of readers */
48509 int nWrLock; /* Number of writers. (Always 0 or 1) */
48510 int nRef; /* Number of users of this MemStore */
48511 char *zFName; /* The filename for shared stores */
48512 };
48513
48514 /* An open file */
48515 struct MemFile {
48516 sqlite3_file base; /* IO methods */
48517 MemStore *pStore; /* The storage */
48518 int eLock; /* Most recent lock against this file */
48519 };
48520
48521 /*
48522 ** Global variables for holding the memdb files that are accessible
48523 ** to multiple database connections in separate threads.
48524 **
48525 ** Must hold SQLITE_MUTEX_STATIC_VFS1 to access any part of this object.
48526 */
48527 struct MemFS {
48528 int nMemStore; /* Number of shared MemStore objects */
48529 MemStore **apMemStore; /* Array of all shared MemStore objects */
48530 } memdb_g;
48531
48532 /*
48533 ** Methods for MemFile
48534 */
48535 static int memdbClose(sqlite3_file*);
48536 static int memdbRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
@@ -48531,23 +48605,62 @@
48605 0, /* xShmUnmap */
48606 memdbFetch, /* xFetch */
48607 memdbUnfetch /* xUnfetch */
48608 };
48609
48610 /*
48611 ** Enter/leave the mutex on a MemStore
48612 */
48613 static void memdbEnter(MemStore *p){
48614 sqlite3_mutex_enter(p->pMutex);
48615 }
48616 static void memdbLeave(MemStore *p){
48617 sqlite3_mutex_leave(p->pMutex);
48618 }
48619
48620
48621
48622 /*
48623 ** Close an memdb-file.
48624 ** Free the underlying MemStore object when its refcount drops to zero
48625 ** or less.
 
 
48626 */
48627 static int memdbClose(sqlite3_file *pFile){
48628 MemStore *p = ((MemFile*)pFile)->pStore;
48629 if( p->zFName ){
48630 int i;
48631 #ifndef SQLITE_MUTEX_OMIT
48632 sqlite3_mutex *pVfsMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
48633 #endif
48634 sqlite3_mutex_enter(pVfsMutex);
48635 for(i=0; ALWAYS(i<memdb_g.nMemStore); i++){
48636 if( memdb_g.apMemStore[i]==p ){
48637 memdbEnter(p);
48638 if( p->nRef==1 ){
48639 memdb_g.apMemStore[i] = memdb_g.apMemStore[--memdb_g.nMemStore];
48640 if( memdb_g.nMemStore==0 ){
48641 sqlite3_free(memdb_g.apMemStore);
48642 memdb_g.apMemStore = 0;
48643 }
48644 }
48645 break;
48646 }
48647 }
48648 sqlite3_mutex_leave(pVfsMutex);
48649 }else{
48650 memdbEnter(p);
48651 }
48652 p->nRef--;
48653 if( p->nRef<=0 ){
48654 if( p->mFlags & SQLITE_DESERIALIZE_FREEONCLOSE ){
48655 sqlite3_free(p->aData);
48656 }
48657 memdbLeave(p);
48658 sqlite3_mutex_free(p->pMutex);
48659 sqlite3_free(p);
48660 }else{
48661 memdbLeave(p);
48662 }
48663 return SQLITE_OK;
48664 }
48665
48666 /*
@@ -48557,24 +48670,27 @@
48670 sqlite3_file *pFile,
48671 void *zBuf,
48672 int iAmt,
48673 sqlite_int64 iOfst
48674 ){
48675 MemStore *p = ((MemFile*)pFile)->pStore;
48676 memdbEnter(p);
48677 if( iOfst+iAmt>p->sz ){
48678 memset(zBuf, 0, iAmt);
48679 if( iOfst<p->sz ) memcpy(zBuf, p->aData+iOfst, p->sz - iOfst);
48680 memdbLeave(p);
48681 return SQLITE_IOERR_SHORT_READ;
48682 }
48683 memcpy(zBuf, p->aData+iOfst, iAmt);
48684 memdbLeave(p);
48685 return SQLITE_OK;
48686 }
48687
48688 /*
48689 ** Try to enlarge the memory allocation to hold at least sz bytes
48690 */
48691 static int memdbEnlarge(MemStore *p, sqlite3_int64 newSz){
48692 unsigned char *pNew;
48693 if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || p->nMmap>0 ){
48694 return SQLITE_FULL;
48695 }
48696 if( newSz>p->szMax ){
@@ -48596,23 +48712,31 @@
48712 sqlite3_file *pFile,
48713 const void *z,
48714 int iAmt,
48715 sqlite_int64 iOfst
48716 ){
48717 MemStore *p = ((MemFile*)pFile)->pStore;
48718 memdbEnter(p);
48719 if( NEVER(p->mFlags & SQLITE_DESERIALIZE_READONLY) ){
48720 /* Can't happen: memdbLock() will return SQLITE_READONLY before
48721 ** reaching this point */
48722 memdbLeave(p);
48723 return SQLITE_IOERR_WRITE;
48724 }
48725 if( iOfst+iAmt>p->sz ){
48726 int rc;
48727 if( iOfst+iAmt>p->szAlloc
48728 && (rc = memdbEnlarge(p, iOfst+iAmt))!=SQLITE_OK
48729 ){
48730 memdbLeave(p);
48731 return rc;
48732 }
48733 if( iOfst>p->sz ) memset(p->aData+p->sz, 0, iOfst-p->sz);
48734 p->sz = iOfst+iAmt;
48735 }
48736 memcpy(p->aData+iOfst, z, iAmt);
48737 memdbLeave(p);
48738 return SQLITE_OK;
48739 }
48740
48741 /*
48742 ** Truncate an memdb-file.
@@ -48620,14 +48744,20 @@
48744 ** In rollback mode (which is always the case for memdb, as it does not
48745 ** support WAL mode) the truncate() method is only used to reduce
48746 ** the size of a file, never to increase the size.
48747 */
48748 static int memdbTruncate(sqlite3_file *pFile, sqlite_int64 size){
48749 MemStore *p = ((MemFile*)pFile)->pStore;
48750 int rc = SQLITE_OK;
48751 memdbEnter(p);
48752 if( NEVER(size>p->sz) ){
48753 rc = SQLITE_FULL;
48754 }else{
48755 p->sz = size;
48756 }
48757 memdbLeave(p);
48758 return rc;
48759 }
48760
48761 /*
48762 ** Sync an memdb-file.
48763 */
@@ -48637,45 +48767,78 @@
48767
48768 /*
48769 ** Return the current file-size of an memdb-file.
48770 */
48771 static int memdbFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
48772 MemStore *p = ((MemFile*)pFile)->pStore;
48773 memdbEnter(p);
48774 *pSize = p->sz;
48775 memdbLeave(p);
48776 return SQLITE_OK;
48777 }
48778
48779 /*
48780 ** Lock an memdb-file.
48781 */
48782 static int memdbLock(sqlite3_file *pFile, int eLock){
48783 MemFile *pThis = (MemFile*)pFile;
48784 MemStore *p = pThis->pStore;
48785 int rc = SQLITE_OK;
48786 if( eLock==pThis->eLock ) return SQLITE_OK;
48787 memdbEnter(p);
48788 if( eLock>SQLITE_LOCK_SHARED ){
48789 if( p->mFlags & SQLITE_DESERIALIZE_READONLY ){
48790 rc = SQLITE_READONLY;
48791 }else if( pThis->eLock<=SQLITE_LOCK_SHARED ){
48792 if( p->nWrLock ){
48793 rc = SQLITE_BUSY;
48794 }else{
48795 p->nWrLock = 1;
48796 }
48797 }
48798 }else if( eLock==SQLITE_LOCK_SHARED ){
48799 if( pThis->eLock > SQLITE_LOCK_SHARED ){
48800 assert( p->nWrLock==1 );
48801 p->nWrLock = 0;
48802 }else if( p->nWrLock ){
48803 rc = SQLITE_BUSY;
48804 }else{
48805 p->nRdLock++;
48806 }
48807 }else{
48808 assert( eLock==SQLITE_LOCK_NONE );
48809 if( pThis->eLock>SQLITE_LOCK_SHARED ){
48810 assert( p->nWrLock==1 );
48811 p->nWrLock = 0;
48812 }
48813 assert( p->nRdLock>0 );
48814 p->nRdLock--;
48815 }
48816 if( rc==SQLITE_OK ) pThis->eLock = eLock;
48817 memdbLeave(p);
48818 return rc;
48819 }
48820
48821 #if 0
48822 /*
48823 ** This interface is only used for crash recovery, which does not
48824 ** occur on an in-memory database.
48825 */
48826 static int memdbCheckReservedLock(sqlite3_file *pFile, int *pResOut){
48827 *pResOut = 0;
48828 return SQLITE_OK;
48829 }
48830 #endif
48831
48832
48833 /*
48834 ** File control method. For custom operations on an memdb-file.
48835 */
48836 static int memdbFileControl(sqlite3_file *pFile, int op, void *pArg){
48837 MemStore *p = ((MemFile*)pFile)->pStore;
48838 int rc = SQLITE_NOTFOUND;
48839 memdbEnter(p);
48840 if( op==SQLITE_FCNTL_VFSNAME ){
48841 *(char**)pArg = sqlite3_mprintf("memdb(%p,%lld)", p->aData, p->sz);
48842 rc = SQLITE_OK;
48843 }
48844 if( op==SQLITE_FCNTL_SIZE_LIMIT ){
@@ -48689,10 +48852,11 @@
48852 }
48853 p->szMax = iLimit;
48854 *(sqlite3_int64*)pArg = iLimit;
48855 rc = SQLITE_OK;
48856 }
48857 memdbLeave(p);
48858 return rc;
48859 }
48860
48861 #if 0 /* Not used because of SQLITE_IOCAP_POWERSAFE_OVERWRITE */
48862 /*
@@ -48718,47 +48882,110 @@
48882 sqlite3_file *pFile,
48883 sqlite3_int64 iOfst,
48884 int iAmt,
48885 void **pp
48886 ){
48887 MemStore *p = ((MemFile*)pFile)->pStore;
48888 memdbEnter(p);
48889 if( iOfst+iAmt>p->sz ){
48890 *pp = 0;
48891 }else{
48892 p->nMmap++;
48893 *pp = (void*)(p->aData + iOfst);
48894 }
48895 memdbLeave(p);
48896 return SQLITE_OK;
48897 }
48898
48899 /* Release a memory-mapped page */
48900 static int memdbUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
48901 MemStore *p = ((MemFile*)pFile)->pStore;
48902 memdbEnter(p);
48903 p->nMmap--;
48904 memdbLeave(p);
48905 return SQLITE_OK;
48906 }
48907
48908 /*
48909 ** Open an mem file handle.
48910 */
48911 static int memdbOpen(
48912 sqlite3_vfs *pVfs,
48913 const char *zName,
48914 sqlite3_file *pFd,
48915 int flags,
48916 int *pOutFlags
48917 ){
48918 MemFile *pFile = (MemFile*)pFd;
48919 MemStore *p = 0;
48920 int szName;
48921 if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
48922 return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFd, flags, pOutFlags);
48923 }
48924 memset(pFile, 0, sizeof(*p));
48925 szName = sqlite3Strlen30(zName);
48926 if( szName>1 && zName[0]=='/' ){
48927 int i;
48928 #ifndef SQLITE_MUTEX_OMIT
48929 sqlite3_mutex *pVfsMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
48930 #endif
48931 sqlite3_mutex_enter(pVfsMutex);
48932 for(i=0; i<memdb_g.nMemStore; i++){
48933 if( strcmp(memdb_g.apMemStore[i]->zFName,zName)==0 ){
48934 p = memdb_g.apMemStore[i];
48935 break;
48936 }
48937 }
48938 if( p==0 ){
48939 MemStore **apNew;
48940 p = sqlite3Malloc( sizeof(*p) + szName + 3 );
48941 if( p==0 ){
48942 sqlite3_mutex_leave(pVfsMutex);
48943 return SQLITE_NOMEM;
48944 }
48945 apNew = sqlite3Realloc(memdb_g.apMemStore,
48946 sizeof(apNew[0])*(memdb_g.nMemStore+1) );
48947 if( apNew==0 ){
48948 sqlite3_free(p);
48949 sqlite3_mutex_leave(pVfsMutex);
48950 return SQLITE_NOMEM;
48951 }
48952 apNew[memdb_g.nMemStore++] = p;
48953 memdb_g.apMemStore = apNew;
48954 memset(p, 0, sizeof(*p));
48955 p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE|SQLITE_DESERIALIZE_FREEONCLOSE;
48956 p->szMax = sqlite3GlobalConfig.mxMemdbSize;
48957 p->zFName = (char*)&p[1];
48958 memcpy(p->zFName, zName, szName+1);
48959 p->pMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
48960 if( p->pMutex==0 ){
48961 memdb_g.nMemStore--;
48962 sqlite3_free(p);
48963 sqlite3_mutex_leave(pVfsMutex);
48964 return SQLITE_NOMEM;
48965 }
48966 p->nRef = 1;
48967 memdbEnter(p);
48968 }else{
48969 memdbEnter(p);
48970 p->nRef++;
48971 }
48972 sqlite3_mutex_leave(pVfsMutex);
48973 }else{
48974 p = sqlite3Malloc( sizeof(*p) );
48975 if( p==0 ){
48976 return SQLITE_NOMEM;
48977 }
48978 memset(p, 0, sizeof(*p));
48979 p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
48980 p->szMax = sqlite3GlobalConfig.mxMemdbSize;
48981 }
48982 pFile->pStore = p;
48983 assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */
48984 *pOutFlags = flags | SQLITE_OPEN_MEMORY;
48985 pFd->pMethods = &memdb_io_methods;
48986 memdbLeave(p);
48987 return SQLITE_OK;
48988 }
48989
48990 #if 0 /* Only used to delete rollback journals, super-journals, and WAL
48991 ** files, none of which exist in memdb. So this routine is never used */
@@ -48869,13 +49096,18 @@
49096 ** Translate a database connection pointer and schema name into a
49097 ** MemFile pointer.
49098 */
49099 static MemFile *memdbFromDbSchema(sqlite3 *db, const char *zSchema){
49100 MemFile *p = 0;
49101 MemStore *pStore;
49102 int rc = sqlite3_file_control(db, zSchema, SQLITE_FCNTL_FILE_POINTER, &p);
49103 if( rc ) return 0;
49104 if( p->base.pMethods!=&memdb_io_methods ) return 0;
49105 pStore = p->pStore;
49106 memdbEnter(pStore);
49107 if( pStore->zFName!=0 ) p = 0;
49108 memdbLeave(pStore);
49109 return p;
49110 }
49111
49112 /*
49113 ** Return the serialization of a database
@@ -48907,16 +49139,18 @@
49139 p = memdbFromDbSchema(db, zSchema);
49140 iDb = sqlite3FindDbName(db, zSchema);
49141 if( piSize ) *piSize = -1;
49142 if( iDb<0 ) return 0;
49143 if( p ){
49144 MemStore *pStore = p->pStore;
49145 assert( pStore->pMutex==0 );
49146 if( piSize ) *piSize = pStore->sz;
49147 if( mFlags & SQLITE_SERIALIZE_NOCOPY ){
49148 pOut = pStore->aData;
49149 }else{
49150 pOut = sqlite3_malloc64( pStore->sz );
49151 if( pOut ) memcpy(pOut, pStore->aData, pStore->sz);
49152 }
49153 return pOut;
49154 }
49155 pBt = db->aDb[iDb].pBt;
49156 if( pBt==0 ) return 0;
@@ -49006,19 +49240,20 @@
49240 }
49241 p = memdbFromDbSchema(db, zSchema);
49242 if( p==0 ){
49243 rc = SQLITE_ERROR;
49244 }else{
49245 MemStore *pStore = p->pStore;
49246 pStore->aData = pData;
49247 pData = 0;
49248 pStore->sz = szDb;
49249 pStore->szAlloc = szBuf;
49250 pStore->szMax = szBuf;
49251 if( pStore->szMax<sqlite3GlobalConfig.mxMemdbSize ){
49252 pStore->szMax = sqlite3GlobalConfig.mxMemdbSize;
49253 }
49254 pStore->mFlags = mFlags;
49255 rc = SQLITE_OK;
49256 }
49257
49258 end_deserialize:
49259 sqlite3_finalize(pStmt);
@@ -49043,11 +49278,11 @@
49278 ** is no way to reach it under most builds. */
49279 if( sz<sizeof(MemFile) ) sz = sizeof(MemFile); /*NO_TEST*/
49280 memdb_vfs.szOsFile = sz;
49281 return sqlite3_vfs_register(&memdb_vfs, 0);
49282 }
49283 #endif /* SQLITE_OMIT_DESERIALIZE */
49284
49285 /************** End of memdb.c ***********************************************/
49286 /************** Begin file bitvec.c ******************************************/
49287 /*
49288 ** 2008 February 16
@@ -56958,11 +57193,11 @@
57193 u8 *pPtr;
57194 Pager *pPager = 0; /* Pager object to allocate and return */
57195 int rc = SQLITE_OK; /* Return code */
57196 int tempFile = 0; /* True for temp files (incl. in-memory files) */
57197 int memDb = 0; /* True if this is an in-memory file */
57198 #ifndef SQLITE_OMIT_DESERIALIZE
57199 int memJM = 0; /* Memory journal mode */
57200 #else
57201 # define memJM 0
57202 #endif
57203 int readOnly = 0; /* True if this is a read-only file */
@@ -57162,11 +57397,11 @@
57397 */
57398 if( zFilename && zFilename[0] ){
57399 int fout = 0; /* VFS flags returned by xOpen() */
57400 rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout);
57401 assert( !memDb );
57402 #ifndef SQLITE_OMIT_DESERIALIZE
57403 memJM = (fout&SQLITE_OPEN_MEMORY)!=0;
57404 #endif
57405 readOnly = (fout&SQLITE_OPEN_READONLY)!=0;
57406
57407 /* If the file was successfully opened for read/write access,
@@ -61004,11 +61239,10 @@
61239 static void walCleanupHash(Wal *pWal){
61240 WalHashLoc sLoc; /* Hash table location */
61241 int iLimit = 0; /* Zero values greater than this */
61242 int nByte; /* Number of bytes to zero in aPgno[] */
61243 int i; /* Used to iterate through aHash[] */
 
61244
61245 assert( pWal->writeLock );
61246 testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE-1 );
61247 testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE );
61248 testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE+1 );
@@ -61019,12 +61253,12 @@
61253 ** the entry that corresponds to frame pWal->hdr.mxFrame. It is guaranteed
61254 ** that the page said hash-table and array reside on is already mapped.(1)
61255 */
61256 assert( pWal->nWiData>walFramePage(pWal->hdr.mxFrame) );
61257 assert( pWal->apWiData[walFramePage(pWal->hdr.mxFrame)] );
61258 i = walHashGet(pWal, walFramePage(pWal->hdr.mxFrame), &sLoc);
61259 if( NEVER(i) ) return; /* Defense-in-depth, in case (1) above is wrong */
61260
61261 /* Zero all hash-table entries that correspond to frame numbers greater
61262 ** than pWal->hdr.mxFrame.
61263 */
61264 iLimit = pWal->hdr.mxFrame - sLoc.iZero;
@@ -72271,11 +72505,13 @@
72505 assert( pFree>aData && (pFree - aData)<65536 );
72506 freeSpace(pPg, (u16)(pFree - aData), szFree);
72507 }
72508 pFree = pCell;
72509 szFree = sz;
72510 if( pFree+sz>pEnd ){
72511 return 0;
72512 }
72513 }else{
72514 pFree = pCell;
72515 szFree += sz;
72516 }
72517 nRet++;
@@ -73247,10 +73483,11 @@
73483 /* Insert new divider cells into pParent. */
73484 for(i=0; i<nNew-1; i++){
73485 u8 *pCell;
73486 u8 *pTemp;
73487 int sz;
73488 u8 *pSrcEnd;
73489 MemPage *pNew = apNew[i];
73490 j = cntNew[i];
73491
73492 assert( j<nMaxCells );
73493 assert( b.apCell[j]!=0 );
@@ -73290,10 +73527,16 @@
73527 }
73528 }
73529 iOvflSpace += sz;
73530 assert( sz<=pBt->maxLocal+23 );
73531 assert( iOvflSpace <= (int)pBt->pageSize );
73532 for(k=0; b.ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
73533 pSrcEnd = b.apEnd[k];
73534 if( SQLITE_WITHIN(pSrcEnd, pCell, pCell+sz) ){
73535 rc = SQLITE_CORRUPT_BKPT;
73536 goto balance_cleanup;
73537 }
73538 insertCell(pParent, nxDiv+i, pCell, sz, pTemp, pNew->pgno, &rc);
73539 if( rc!=SQLITE_OK ) goto balance_cleanup;
73540 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
73541 }
73542
@@ -86617,10 +86860,15 @@
86860 printf(" <== R[%d]", (int)(p->pScopyFrom - &p[-iReg]));
86861 }
86862 printf("\n");
86863 sqlite3VdbeCheckMemInvariants(p);
86864 }
86865 SQLITE_PRIVATE void sqlite3PrintMem(Mem *pMem){
86866 memTracePrint(pMem);
86867 printf("\n");
86868 fflush(stdout);
86869 }
86870 #endif
86871
86872 #ifdef SQLITE_DEBUG
86873 /*
86874 ** Show the values of all registers in the virtual machine. Used for
@@ -90667,12 +90915,22 @@
90915 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90916 pC = p->apCsr[pOp->p1];
90917 assert( pC!=0 );
90918 assert( pOp->p3>=pOp->p2 );
90919 if( pC->seekHit<pOp->p2 ){
90920 #ifdef SQLITE_DEBUG
90921 if( db->flags&SQLITE_VdbeTrace ){
90922 printf("seekHit changes from %d to %d\n", pC->seekHit, pOp->p2);
90923 }
90924 #endif
90925 pC->seekHit = pOp->p2;
90926 }else if( pC->seekHit>pOp->p3 ){
90927 #ifdef SQLITE_DEBUG
90928 if( db->flags&SQLITE_VdbeTrace ){
90929 printf("seekHit changes from %d to %d\n", pC->seekHit, pOp->p3);
90930 }
90931 #endif
90932 pC->seekHit = pOp->p3;
90933 }
90934 break;
90935 }
90936
@@ -90783,10 +91041,15 @@
91041 case OP_IfNoHope: { /* jump, in3 */
91042 VdbeCursor *pC;
91043 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
91044 pC = p->apCsr[pOp->p1];
91045 assert( pC!=0 );
91046 #ifdef SQLITE_DEBUG
91047 if( db->flags&SQLITE_VdbeTrace ){
91048 printf("seekHit is %d\n", pC->seekHit);
91049 }
91050 #endif
91051 if( pC->seekHit>=pOp->p4.i ) break;
91052 /* Fall through into OP_NotFound */
91053 /* no break */ deliberate_fall_through
91054 }
91055 case OP_NoConflict: /* jump, in3 */
@@ -100897,22 +101160,11 @@
101160 Parse *pParse, /* Parsing context */
101161 Expr *pExpr, /* Add the "COLLATE" clause to this expression */
101162 const Token *pCollName, /* Name of collating sequence */
101163 int dequote /* True to dequote pCollName */
101164 ){
101165 if( pCollName->n>0 ){
 
 
 
 
 
 
 
 
 
 
 
101166 Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, dequote);
101167 if( pNew ){
101168 pNew->pLeft = pExpr;
101169 pNew->flags |= EP_Collate|EP_Skip;
101170 pExpr = pNew;
@@ -107808,11 +108060,11 @@
108060 */
108061 static int renameUnmapSelectCb(Walker *pWalker, Select *p){
108062 Parse *pParse = pWalker->pParse;
108063 int i;
108064 if( pParse->nErr ) return WRC_Abort;
108065 if( p->selFlags & SF_View ) return WRC_Prune;
108066 if( ALWAYS(p->pEList) ){
108067 ExprList *pList = p->pEList;
108068 for(i=0; i<pList->nExpr; i++){
108069 if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){
108070 sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
@@ -111180,11 +111432,11 @@
111432 zFile = (const char *)sqlite3_value_text(argv[0]);
111433 zName = (const char *)sqlite3_value_text(argv[1]);
111434 if( zFile==0 ) zFile = "";
111435 if( zName==0 ) zName = "";
111436
111437 #ifndef SQLITE_OMIT_DESERIALIZE
111438 # define REOPEN_AS_MEMDB(db) (db->init.reopenMemdb)
111439 #else
111440 # define REOPEN_AS_MEMDB(db) (0)
111441 #endif
111442
@@ -113000,10 +113252,26 @@
113252 /* iCol is a normal or stored column */
113253 return n;
113254 }
113255 }
113256 #endif
113257
113258 /*
113259 ** Insert a single OP_JournalMode query opcode in order to force the
113260 ** prepared statement to return false for sqlite3_stmt_readonly(). This
113261 ** is used by CREATE TABLE IF NOT EXISTS and similar if the table already
113262 ** exists, so that the prepared statement for CREATE TABLE IF NOT EXISTS
113263 ** will return false for sqlite3_stmt_readonly() even if that statement
113264 ** is a read-only no-op.
113265 */
113266 static void sqlite3ForceNotReadOnly(Parse *pParse){
113267 int iReg = ++pParse->nMem;
113268 Vdbe *v = sqlite3GetVdbe(pParse);
113269 if( v ){
113270 sqlite3VdbeAddOp3(v, OP_JournalMode, 0, iReg, PAGER_JOURNALMODE_QUERY);
113271 }
113272 }
113273
113274 /*
113275 ** Begin constructing a new table representation in memory. This is
113276 ** the first of several action routines that get called in response
113277 ** to a CREATE TABLE statement. In particular, this routine is called
@@ -113100,10 +113368,11 @@
113368 if( !noErr ){
113369 sqlite3ErrorMsg(pParse, "table %T already exists", pName);
113370 }else{
113371 assert( !db->init.busy || CORRUPT_DB );
113372 sqlite3CodeVerifySchema(pParse, iDb);
113373 sqlite3ForceNotReadOnly(pParse);
113374 }
113375 goto begin_table_error;
113376 }
113377 if( sqlite3FindIndex(db, zName, zDb)!=0 ){
113378 sqlite3ErrorMsg(pParse, "there is already an index named %s", zName);
@@ -115150,11 +115419,14 @@
115419 assert( isView==0 || isView==LOCATE_VIEW );
115420 pTab = sqlite3LocateTableItem(pParse, isView, &pName->a[0]);
115421 if( noErr ) db->suppressErr--;
115422
115423 if( pTab==0 ){
115424 if( noErr ){
115425 sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
115426 sqlite3ForceNotReadOnly(pParse);
115427 }
115428 goto exit_drop_table;
115429 }
115430 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
115431 assert( iDb>=0 && iDb<db->nDb );
115432
@@ -115720,10 +115992,11 @@
115992 if( !ifNotExist ){
115993 sqlite3ErrorMsg(pParse, "index %s already exists", zName);
115994 }else{
115995 assert( !db->init.busy );
115996 sqlite3CodeVerifySchema(pParse, iDb);
115997 sqlite3ForceNotReadOnly(pParse);
115998 }
115999 goto exit_create_index;
116000 }
116001 }
116002 }else{
@@ -116200,11 +116473,11 @@
116473 x = pIdx->pTable->nRowLogEst;
116474 assert( 99==sqlite3LogEst(1000) );
116475 if( x<99 ){
116476 pIdx->pTable->nRowLogEst = x = 99;
116477 }
116478 if( pIdx->pPartIdxWhere!=0 ){ x -= 10; assert( 10==sqlite3LogEst(2) ); }
116479 a[0] = x;
116480
116481 /* Estimate that a[1] is 10, a[2] is 9, a[3] is 8, a[4] is 7, a[5] is
116482 ** 6 and each subsequent value (if any) is 5. */
116483 memcpy(&a[1], aVal, nCopy*sizeof(LogEst));
@@ -116238,10 +116511,11 @@
116511 if( pIndex==0 ){
116512 if( !ifExists ){
116513 sqlite3ErrorMsg(pParse, "no such index: %S", pName->a);
116514 }else{
116515 sqlite3CodeVerifyNamedSchema(pParse, pName->a[0].zDatabase);
116516 sqlite3ForceNotReadOnly(pParse);
116517 }
116518 pParse->checkSchema = 1;
116519 goto exit_drop_index;
116520 }
116521 if( pIndex->idxType!=SQLITE_IDXTYPE_APPDEF ){
@@ -136029,11 +136303,11 @@
136303 ** is part of the AND-connected terms of the expression. For each term
136304 ** found, add it to the pConst structure.
136305 */
136306 static void findConstInWhere(WhereConst *pConst, Expr *pExpr){
136307 Expr *pRight, *pLeft;
136308 if( NEVER(pExpr==0) ) return;
136309 if( ExprHasProperty(pExpr, EP_FromJoin) ) return;
136310 if( pExpr->op==TK_AND ){
136311 findConstInWhere(pConst, pExpr->pRight);
136312 findConstInWhere(pConst, pExpr->pLeft);
136313 return;
@@ -137888,11 +138162,12 @@
138162 /* Do the WHERE-clause constant propagation optimization if this is
138163 ** a join. No need to speed time on this operation for non-join queries
138164 ** as the equivalent optimization will be handled by query planner in
138165 ** sqlite3WhereBegin().
138166 */
138167 if( p->pWhere!=0
138168 && p->pWhere->op==TK_AND
138169 && OptimizationEnabled(db, SQLITE_PropagateConst)
138170 && propagateConstants(pParse, p)
138171 ){
138172 #if SELECTTRACE_ENABLED
138173 if( sqlite3SelectTrace & 0x100 ){
@@ -144173,12 +144448,12 @@
144448 WhereClause *pOrigWC; /* Original, innermost WhereClause */
144449 WhereClause *pWC; /* WhereClause currently being scanned */
144450 const char *zCollName; /* Required collating sequence, if not NULL */
144451 Expr *pIdxExpr; /* Search for this index expression */
144452 char idxaff; /* Must match this affinity, if zCollName!=NULL */
144453 unsigned char nEquiv; /* Number of entries in aiCur[] and aiColumn[] */
144454 unsigned char iEquiv; /* Next unused slot in aiCur[] and aiColumn[] */
144455 u32 opMask; /* Acceptable operators */
144456 int k; /* Resume scanning at this->pWC->a[this->k] */
144457 int aiCur[11]; /* Cursors in the equivalence class */
144458 i16 aiColumn[11]; /* Corresponding column number in the eq-class */
144459 };
@@ -144483,10 +144758,11 @@
144758 #define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/
144759 #define WHERE_PARTIALIDX 0x00020000 /* The automatic index is partial */
144760 #define WHERE_IN_EARLYOUT 0x00040000 /* Perhaps quit IN loops early */
144761 #define WHERE_BIGNULL_SORT 0x00080000 /* Column nEq of index is BIGNULL */
144762 #define WHERE_IN_SEEKSCAN 0x00100000 /* Seek-scan optimization for IN */
144763 #define WHERE_TRANSCONS 0x00200000 /* Uses a transitive constraint */
144764
144765 #endif /* !defined(SQLITE_WHEREINT_H) */
144766
144767 /************** End of whereInt.h ********************************************/
144768 /************** Continuing where we left off in wherecode.c ******************/
@@ -144766,10 +145042,16 @@
145042 if( nLoop && (pTerm->wtFlags & TERM_LIKE)!=0 ){
145043 pTerm->wtFlags |= TERM_LIKECOND;
145044 }else{
145045 pTerm->wtFlags |= TERM_CODED;
145046 }
145047 #ifdef WHERETRACE_ENABLED
145048 if( sqlite3WhereTrace & 0x20000 ){
145049 sqlite3DebugPrintf("DISABLE-");
145050 sqlite3WhereTermPrint(pTerm, (int)(pTerm - (pTerm->pWC->a)));
145051 }
145052 #endif
145053 if( pTerm->iParent<0 ) break;
145054 pTerm = &pTerm->pWC->a[pTerm->iParent];
145055 assert( pTerm!=0 );
145056 pTerm->nChild--;
145057 if( pTerm->nChild!=0 ) break;
@@ -145083,11 +145365,26 @@
145365 pLevel->u.in.nIn = 0;
145366 }
145367 sqlite3DbFree(pParse->db, aiMap);
145368 #endif
145369 }
145370
145371 /* As an optimization, try to disable the WHERE clause term that is
145372 ** driving the index as it will always be true. The correct answer is
145373 ** obtained regardless, but we might get the answer with fewer CPU cycles
145374 ** by omitting the term.
145375 **
145376 ** But do not disable the term unless we are certain that the term is
145377 ** not a transitive constraint. For an example of where that does not
145378 ** work, see https://sqlite.org/forum/forumpost/eb8613976a (2021-05-04)
145379 */
145380 if( (pLevel->pWLoop->wsFlags & WHERE_TRANSCONS)==0
145381 || (pTerm->eOperator & WO_EQUIV)==0
145382 ){
145383 disableTerm(pLevel, pTerm);
145384 }
145385
145386 return iReg;
145387 }
145388
145389 /*
145390 ** Generate code that will evaluate all == and IN constraints for an
@@ -146197,13 +146494,11 @@
146494
146495 /* If we are doing a reverse order scan on an ascending index, or
146496 ** a forward order scan on a descending index, interchange the
146497 ** start and end terms (pRangeStart and pRangeEnd).
146498 */
146499 if( (nEq<pIdx->nColumn && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC)) ){
 
 
146500 SWAP(WhereTerm *, pRangeEnd, pRangeStart);
146501 SWAP(u8, bSeekPastNull, bStopAtNull);
146502 SWAP(u8, nBtm, nTop);
146503 }
146504
@@ -147832,11 +148127,11 @@
148127 assert( !ExprHasProperty(pNew, EP_xIsSelect) );
148128 pNew->x.pList = pList;
148129 idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
148130 testcase( idxNew==0 );
148131 exprAnalyze(pSrc, pWC, idxNew);
148132 /* pTerm = &pWC->a[idxTerm]; // would be needed if pTerm where reused */
148133 markTermAsChild(pWC, idxNew, idxTerm);
148134 }else{
148135 sqlite3ExprListDelete(db, pList);
148136 }
148137 }
@@ -147956,10 +148251,11 @@
148251 assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE );
148252 assert( TK_IS<TK_GE && TK_ISNULL<TK_GE && TK_IN<TK_GE );
148253 assert( op<=TK_GE );
148254 if( pExpr->op==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){
148255 pExpr = pExpr->x.pList->a[0].pExpr;
148256
148257 }
148258
148259 if( pExpr->op==TK_COLUMN ){
148260 aiCurCol[0] = pExpr->iTable;
148261 aiCurCol[1] = pExpr->iColumn;
@@ -147968,280 +148264,10 @@
148264 if( mPrereq==0 ) return 0; /* No table references */
148265 if( (mPrereq&(mPrereq-1))!=0 ) return 0; /* Refs more than one table */
148266 return exprMightBeIndexed2(pFrom,mPrereq,aiCurCol,pExpr);
148267 }
148268
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148269
148270 /*
148271 ** The input to this routine is an WhereTerm structure with only the
148272 ** "pExpr" field filled in. The job of this routine is to analyze the
148273 ** subexpression and populate all the other fields of the WhereTerm
@@ -148337,10 +148363,11 @@
148363 pTerm->eOperator = operatorMask(op) & opMask;
148364 }
148365 if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
148366 if( pRight
148367 && exprMightBeIndexed(pSrc, pTerm->prereqRight, aiCurCol, pRight, op)
148368 && !ExprHasProperty(pRight, EP_FixedCol)
148369 ){
148370 WhereTerm *pNew;
148371 Expr *pDup;
148372 u16 eExtraOp = 0; /* Extra bits for pNew->eOperator */
148373 assert( pTerm->u.x.iField==0 );
@@ -148429,20 +148456,10 @@
148456 assert( pWC->op==TK_AND );
148457 exprAnalyzeOrTerm(pSrc, pWC, idxTerm);
148458 pTerm = &pWC->a[idxTerm];
148459 }
148460 #endif /* SQLITE_OMIT_OR_OPTIMIZATION */
 
 
 
 
 
 
 
 
 
 
148461 /* The form "x IS NOT NULL" can sometimes be evaluated more efficiently
148462 ** as "x>NULL" if x is not an INTEGER PRIMARY KEY. So construct a
148463 ** virtual term of that form.
148464 **
148465 ** The virtual term must be tagged with TERM_VNULL.
@@ -149202,10 +149219,22 @@
149219 testcase( pTerm->eOperator & WO_IS );
149220 continue;
149221 }
149222 pScan->pWC = pWC;
149223 pScan->k = k+1;
149224 #ifdef WHERETRACE_ENABLED
149225 if( sqlite3WhereTrace & 0x20000 ){
149226 int ii;
149227 sqlite3DebugPrintf("SCAN-TERM %p: nEquiv=%d",
149228 pTerm, pScan->nEquiv);
149229 for(ii=0; ii<pScan->nEquiv; ii++){
149230 sqlite3DebugPrintf(" {%d:%d}",
149231 pScan->aiCur[ii], pScan->aiColumn[ii]);
149232 }
149233 sqlite3DebugPrintf("\n");
149234 }
149235 #endif
149236 return pTerm;
149237 }
149238 }
149239 }
149240 pWC = pWC->pOuter;
@@ -151365,10 +151394,12 @@
151394 opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE|WO_ISNULL|WO_IS;
151395 }
151396 if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE);
151397
151398 assert( pNew->u.btree.nEq<pProbe->nColumn );
151399 assert( pNew->u.btree.nEq<pProbe->nKeyCol
151400 || pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY );
151401
151402 saved_nEq = pNew->u.btree.nEq;
151403 saved_nBtm = pNew->u.btree.nBtm;
151404 saved_nTop = pNew->u.btree.nTop;
151405 saved_nSkip = pNew->nSkip;
@@ -151498,10 +151529,11 @@
151529 pNew->wsFlags |= WHERE_ONEROW;
151530 }else{
151531 pNew->wsFlags |= WHERE_UNQ_WANTED;
151532 }
151533 }
151534 if( scan.iEquiv>1 ) pNew->wsFlags |= WHERE_TRANSCONS;
151535 }else if( eOp & WO_ISNULL ){
151536 pNew->wsFlags |= WHERE_COLUMN_NULL;
151537 }else if( eOp & (WO_GT|WO_GE) ){
151538 testcase( eOp & WO_GT );
151539 testcase( eOp & WO_GE );
@@ -151641,10 +151673,12 @@
151673 pNew->nOut = nOutUnadjusted;
151674 }
151675
151676 if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
151677 && pNew->u.btree.nEq<pProbe->nColumn
151678 && (pNew->u.btree.nEq<pProbe->nKeyCol ||
151679 pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY)
151680 ){
151681 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
151682 }
151683 pNew->nOut = saved_nOut;
151684 #ifdef SQLITE_ENABLE_STAT4
@@ -153009,11 +153043,11 @@
153043 if( (pWInfo->wctrlFlags & WHERE_USE_LIMIT)!=0 && pWInfo->iLimit<nRow ){
153044 nRow = pWInfo->iLimit;
153045 }else if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT) ){
153046 /* TUNING: In the sort for a DISTINCT operator, assume that the DISTINCT
153047 ** reduces the number of output rows by a factor of 2 */
153048 if( nRow>10 ){ nRow -= 10; assert( 10==sqlite3LogEst(2) ); }
153049 }
153050 rSortCost += estLog(nRow);
153051 return rSortCost;
153052 }
153053
@@ -154299,10 +154333,12 @@
154333 if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
154334 struct InLoop *pIn;
154335 int j;
154336 sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
154337 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
154338 assert( sqlite3VdbeGetOp(v, pIn->addrInTop+1)->opcode==OP_IsNull
154339 || pParse->db->mallocFailed );
154340 sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
154341 if( pIn->eEndLoopOp!=OP_Noop ){
154342 if( pIn->nPrefix ){
154343 int bEarlyOut =
154344 (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0
@@ -154323,10 +154359,15 @@
154359 if( bEarlyOut ){
154360 sqlite3VdbeAddOp4Int(v, OP_IfNoHope, pLevel->iIdxCur,
154361 sqlite3VdbeCurrentAddr(v)+2,
154362 pIn->iBase, pIn->nPrefix);
154363 VdbeCoverage(v);
154364 /* Retarget the OP_IsNull against the left operand of IN so
154365 ** it jumps past the OP_IfNoHope. This is because the
154366 ** OP_IsNull also bypasses the OP_Affinity opcode that is
154367 ** required by OP_IfNoHope. */
154368 sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
154369 }
154370 }
154371 sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop);
154372 VdbeCoverage(v);
154373 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_Prev);
@@ -155454,10 +155495,18 @@
155495 ){
155496 pExpr->op2++;
155497 }
155498 return WRC_Continue;
155499 }
155500
155501 static int disallowAggregatesInOrderByCb(Walker *pWalker, Expr *pExpr){
155502 if( pExpr->op==TK_AGG_FUNCTION && pExpr->pAggInfo==0 ){
155503 sqlite3ErrorMsg(pWalker->pParse,
155504 "misuse of aggregate: %s()", pExpr->u.zToken);
155505 }
155506 return WRC_Continue;
155507 }
155508
155509 /*
155510 ** If the SELECT statement passed as the second argument does not invoke
155511 ** any SQL window functions, this function is a no-op. Otherwise, it
155512 ** rewrites the SELECT statement so that window function xStep functions
@@ -155488,10 +155537,14 @@
155537 if( pTab==0 ){
155538 return sqlite3ErrorToParser(db, SQLITE_NOMEM);
155539 }
155540 sqlite3AggInfoPersistWalkerInit(&w, pParse);
155541 sqlite3WalkSelect(&w, p);
155542 if( (p->selFlags & SF_Aggregate)==0 ){
155543 w.xExprCallback = disallowAggregatesInOrderByCb;
155544 sqlite3WalkExprList(&w, p->pOrderBy);
155545 }
155546
155547 p->pSrc = 0;
155548 p->pWhere = 0;
155549 p->pGroupBy = 0;
155550 p->pHaving = 0;
@@ -164970,11 +165023,11 @@
165023 }
165024 if( rc==SQLITE_OK ){
165025 sqlite3GlobalConfig.isPCacheInit = 1;
165026 rc = sqlite3OsInit();
165027 }
165028 #ifndef SQLITE_OMIT_DESERIALIZE
165029 if( rc==SQLITE_OK ){
165030 rc = sqlite3MemdbInit();
165031 }
165032 #endif
165033 if( rc==SQLITE_OK ){
@@ -165385,16 +165438,16 @@
165438 sqlite3GlobalConfig.szSorterRef = (u32)iVal;
165439 break;
165440 }
165441 #endif /* SQLITE_ENABLE_SORTER_REFERENCES */
165442
165443 #ifndef SQLITE_OMIT_DESERIALIZE
165444 case SQLITE_CONFIG_MEMDB_MAXSIZE: {
165445 sqlite3GlobalConfig.mxMemdbSize = va_arg(ap, sqlite3_int64);
165446 break;
165447 }
165448 #endif /* SQLITE_OMIT_DESERIALIZE */
165449
165450 default: {
165451 rc = SQLITE_ERROR;
165452 break;
165453 }
@@ -172515,11 +172568,11 @@
172568 const char *zCsr = zNode; /* Cursor to iterate through node */
172569 const char *zEnd = &zCsr[nNode];/* End of interior node buffer */
172570 char *zBuffer = 0; /* Buffer to load terms into */
172571 i64 nAlloc = 0; /* Size of allocated buffer */
172572 int isFirstTerm = 1; /* True when processing first term on page */
172573 u64 iChild; /* Block id of child node to descend to */
172574 int nBuffer = 0; /* Total term size */
172575
172576 /* Skip over the 'height' varint that occurs at the start of every
172577 ** interior node. Then load the blockid of the left-child of the b-tree
172578 ** node into variable iChild.
@@ -172531,12 +172584,12 @@
172584 ** either more than 20 bytes of allocated space following the nNode bytes of
172585 ** contents, or two zero bytes. Or, if the node is read from the %_segments
172586 ** table, then there are always 20 bytes of zeroed padding following the
172587 ** nNode bytes of content (see sqlite3Fts3ReadBlock() for details).
172588 */
172589 zCsr += sqlite3Fts3GetVarintU(zCsr, &iChild);
172590 zCsr += sqlite3Fts3GetVarintU(zCsr, &iChild);
172591 if( zCsr>zEnd ){
172592 return FTS_CORRUPT_VTAB;
172593 }
172594
172595 while( zCsr<zEnd && (piFirst || piLast) ){
@@ -172585,24 +172638,24 @@
172638 ** If the interior node term is larger than the specified term, then
172639 ** the tree headed by iChild may contain the specified term.
172640 */
172641 cmp = memcmp(zTerm, zBuffer, (nBuffer>nTerm ? nTerm : nBuffer));
172642 if( piFirst && (cmp<0 || (cmp==0 && nBuffer>nTerm)) ){
172643 *piFirst = (i64)iChild;
172644 piFirst = 0;
172645 }
172646
172647 if( piLast && cmp<0 ){
172648 *piLast = (i64)iChild;
172649 piLast = 0;
172650 }
172651
172652 iChild++;
172653 };
172654
172655 if( piFirst ) *piFirst = (i64)iChild;
172656 if( piLast ) *piLast = (i64)iChild;
172657
172658 finish_scan:
172659 sqlite3_free(zBuffer);
172660 return rc;
172661 }
@@ -189485,11 +189538,11 @@
189538 ** any double-quotes or backslash characters contained within the
189539 ** string.
189540 */
189541 static void jsonAppendString(JsonString *p, const char *zIn, u32 N){
189542 u32 i;
189543 if( zIn==0 || ((N+p->nUsed+2 >= p->nAlloc) && jsonGrow(p,N+2)!=0) ) return;
189544 p->zBuf[p->nUsed++] = '"';
189545 for(i=0; i<N; i++){
189546 unsigned char c = ((unsigned const char*)zIn)[i];
189547 if( c=='"' || c=='\\' ){
189548 json_simple_escape:
@@ -201243,11 +201296,13 @@
201296 );
201297 if( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSel) ){
201298 zSep = "";
201299 for(iCol=0; iCol<pIter->nCol; iCol++){
201300 const char *zQuoted = (const char*)sqlite3_column_text(pSel, iCol);
201301 if( zQuoted==0 ){
201302 p->rc = SQLITE_NOMEM;
201303 }else if( zQuoted[0]=='N' ){
201304 bFailed = 1;
201305 break;
201306 }
201307 zVector = rbuMPrintf(p, "%z%s%s", zVector, zSep, zQuoted);
201308 zSep = ", ";
@@ -204615,32 +204670,18 @@
204670 }
204671 else if( flags & SQLITE_OPEN_WAL ){
204672 rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName, 0);
204673 if( pDb ){
204674 if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
204675 /* This call is to open a *-wal file. Intead, open the *-oal. */
204676 size_t nOpen;
 
 
 
 
 
204677 if( rbuIsVacuum(pDb->pRbu) ){
204678 zOpen = sqlite3_db_filename(pDb->pRbu->dbRbu, "main");
204679 zOpen = sqlite3_filename_wal(zOpen);
204680 }
204681 nOpen = strlen(zOpen);
204682 ((char*)zOpen)[nOpen-3] = 'o';
 
 
 
 
 
 
 
 
 
204683 pFd->pRbu = pDb->pRbu;
204684 }
204685 pDb->pWalFd = pFd;
204686 }
204687 }
@@ -222669,11 +222710,10 @@
222710 }else{
222711 /* The following could be done by calling fts5SegIterLoadNPos(). But
222712 ** this block is particularly performance critical, so equivalent
222713 ** code is inlined. */
222714 int nSz;
 
222715 assert_nc( pIter->iLeafOffset<=pIter->pLeaf->nn );
222716 fts5FastGetVarint32(pIter->pLeaf->p, pIter->iLeafOffset, nSz);
222717 pIter->bDel = (nSz & 0x0001);
222718 pIter->nPos = nSz>>1;
222719 assert_nc( pIter->nPos>=0 );
@@ -230123,11 +230163,11 @@
230163 int nArg, /* Number of args */
230164 sqlite3_value **apUnused /* Function arguments */
230165 ){
230166 assert( nArg==0 );
230167 UNUSED_PARAM2(nArg, apUnused);
230168 sqlite3_result_text(pCtx, "fts5: 2021-05-14 15:37:00 cf63abbe559d04f993f99a37d41ba4a97c0261094f1d4cc05cfa23b1e11731f5", -1, SQLITE_TRANSIENT);
230169 }
230170
230171 /*
230172 ** Return true if zName is the extension on one of the shadow tables used
230173 ** by this module.
@@ -235049,12 +235089,12 @@
235089 }
235090 #endif /* SQLITE_CORE */
235091 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
235092
235093 /************** End of stmt.c ************************************************/
235094 #if __LINE__!=235094
235095 #undef SQLITE_SOURCE_ID
235096 #define SQLITE_SOURCE_ID "2021-05-14 15:37:00 cf63abbe559d04f993f99a37d41ba4a97c0261094f1d4cc05cfa23b1e117alt2"
235097 #endif
235098 /* Return the source-id for this library */
235099 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
235100 /************************** End of sqlite3.c ******************************/
235101
+44 -26
--- 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.36.0"
127127
#define SQLITE_VERSION_NUMBER 3036000
128
-#define SQLITE_SOURCE_ID "2021-04-28 17:37:26 65ec39f0f092fe29e1d4e9e96cf07a73d2ef7ce2c41b6f1cd3ab23546ada0e67"
128
+#define SQLITE_SOURCE_ID "2021-05-14 15:37:00 cf63abbe559d04f993f99a37d41ba4a97c0261094f1d4cc05cfa23b1e11731f5"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -1139,10 +1139,14 @@
11391139
** currently has an SQL transaction open on the database. It is set to 0 if
11401140
** the database is not a wal-mode db, or if there is no such connection in any
11411141
** other process. This opcode cannot be used to detect transactions opened
11421142
** by clients within the current process, only within other processes.
11431143
** </ul>
1144
+**
1145
+** <li>[[SQLITE_FCNTL_CKSM_FILE]]
1146
+** Used by the cksmvfs VFS module only.
1147
+** </ul>
11441148
*/
11451149
#define SQLITE_FCNTL_LOCKSTATE 1
11461150
#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
11471151
#define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
11481152
#define SQLITE_FCNTL_LAST_ERRNO 4
@@ -1178,12 +1182,12 @@
11781182
#define SQLITE_FCNTL_DATA_VERSION 35
11791183
#define SQLITE_FCNTL_SIZE_LIMIT 36
11801184
#define SQLITE_FCNTL_CKPT_DONE 37
11811185
#define SQLITE_FCNTL_RESERVE_BYTES 38
11821186
#define SQLITE_FCNTL_CKPT_START 39
1183
-
11841187
#define SQLITE_FCNTL_EXTERNAL_READER 40
1188
+#define SQLITE_FCNTL_CKSM_FILE 41
11851189
11861190
/* deprecated names */
11871191
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
11881192
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
11891193
#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -4192,10 +4196,19 @@
41924196
** changes to the content of the database files on disk.
41934197
** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
41944198
** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
41954199
** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
41964200
** sqlite3_stmt_readonly() returns false for those commands.
4201
+**
4202
+** ^This routine returns false if there is any possibility that the
4203
+** statement might change the database file. ^A false return does
4204
+** not guarantee that the statement will change the database file.
4205
+** ^For example, an UPDATE statement might have a WHERE clause that
4206
+** makes it a no-op, but the sqlite3_stmt_readonly() result would still
4207
+** be false. ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a
4208
+** read-only no-op if the table already exists, but
4209
+** sqlite3_stmt_readonly() still returns false for such a statement.
41974210
*/
41984211
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
41994212
42004213
/*
42014214
** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
@@ -4361,22 +4374,26 @@
43614374
** terminated. If any NUL characters occurs at byte offsets less than
43624375
** the value of the fourth parameter then the resulting string value will
43634376
** contain embedded NULs. The result of expressions involving strings
43644377
** with embedded NULs is undefined.
43654378
**
4366
-** ^The fifth argument to the BLOB and string binding interfaces
4367
-** is a destructor used to dispose of the BLOB or
4368
-** string after SQLite has finished with it. ^The destructor is called
4369
-** to dispose of the BLOB or string even if the call to the bind API fails,
4370
-** except the destructor is not called if the third parameter is a NULL
4371
-** pointer or the fourth parameter is negative.
4372
-** ^If the fifth argument is
4373
-** the special value [SQLITE_STATIC], then SQLite assumes that the
4374
-** information is in static, unmanaged space and does not need to be freed.
4375
-** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
4376
-** SQLite makes its own private copy of the data immediately, before
4377
-** the sqlite3_bind_*() routine returns.
4379
+** ^The fifth argument to the BLOB and string binding interfaces controls
4380
+** or indicates the lifetime of the object referenced by the third parameter.
4381
+** ^These three options exist:
4382
+** ^(1) A destructor to dispose of the BLOB or string after SQLite has finished
4383
+** with it may be passed. ^It is called to dispose of the BLOB or string even
4384
+** if the call to the bind API fails, except the destructor is not called if
4385
+** the third parameter is a NULL pointer or the fourth parameter is negative.
4386
+** ^(2) The special constant, [SQLITE_STATIC], may be passsed to indicate that
4387
+** the application remains responsible for disposing of the object. ^In this
4388
+** case, the object and the provided pointer to it must remain valid until
4389
+** either the prepared statement is finalized or the same SQL parameter is
4390
+** bound to something else, whichever occurs sooner.
4391
+** ^(3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the
4392
+** object is to be copied prior to the return from sqlite3_bind_*(). ^The
4393
+** object and pointer to it must remain valid until then. ^SQLite will then
4394
+** manage the lifetime of its private copy.
43784395
**
43794396
** ^The sixth argument to sqlite3_bind_text64() must be one of
43804397
** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
43814398
** to specify the encoding of the text in the third parameter. If
43824399
** the sixth argument to sqlite3_bind_text64() is not one of the
@@ -9812,12 +9829,12 @@
98129829
**
98139830
** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the
98149831
** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory
98159832
** allocation error occurs.
98169833
**
9817
-** This interface is only available if SQLite is compiled with the
9818
-** [SQLITE_ENABLE_DESERIALIZE] option.
9834
+** This interface is omitted if SQLite is compiled with the
9835
+** [SQLITE_OMIT_DESERIALIZE] option.
98199836
*/
98209837
SQLITE_API unsigned char *sqlite3_serialize(
98219838
sqlite3 *db, /* The database connection */
98229839
const char *zSchema, /* Which DB to serialize. ex: "main", "temp", ... */
98239840
sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */
@@ -9864,12 +9881,12 @@
98649881
**
98659882
** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the
98669883
** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then
98679884
** [sqlite3_free()] is invoked on argument P prior to returning.
98689885
**
9869
-** This interface is only available if SQLite is compiled with the
9870
-** [SQLITE_ENABLE_DESERIALIZE] option.
9886
+** This interface is omitted if SQLite is compiled with the
9887
+** [SQLITE_OMIT_DESERIALIZE] option.
98719888
*/
98729889
SQLITE_API int sqlite3_deserialize(
98739890
sqlite3 *db, /* The database connection */
98749891
const char *zSchema, /* Which DB to reopen with the deserialization */
98759892
unsigned char *pData, /* The serialized database content */
@@ -10121,18 +10138,15 @@
1012110138
** METHOD: sqlite3_session
1012210139
**
1012310140
** This method is used to configure a session object after it has been
1012410141
** created. At present the only valid value for the second parameter is
1012510142
** [SQLITE_SESSION_OBJCONFIG_SIZE].
10126
-*/
10127
-SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
10128
-
10129
-/*
10130
-** CAPI3REF: Arguments for sqlite3session_object_config()
10143
+**
10144
+** Arguments for sqlite3session_object_config()
1013110145
**
1013210146
** The following values may passed as the the 4th parameter to
10133
-** [sqlite3session_object_config].
10147
+** sqlite3session_object_config().
1013410148
**
1013510149
** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
1013610150
** This option is used to set, clear or query the flag that enables
1013710151
** the [sqlite3session_changeset_size()] API. Because it imposes some
1013810152
** computational overhead, this API is disabled by default. Argument
@@ -10143,10 +10157,14 @@
1014310157
** variable is set to 1 if the sqlite3session_changeset_size() API is
1014410158
** enabled following the current call, or 0 otherwise.
1014510159
**
1014610160
** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
1014710161
** the first table has been attached to the session object.
10162
+*/
10163
+SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
10164
+
10165
+/*
1014810166
*/
1014910167
#define SQLITE_SESSION_OBJCONFIG_SIZE 1
1015010168
1015110169
/*
1015210170
** CAPI3REF: Enable Or Disable A Session Object
@@ -10391,15 +10409,15 @@
1039110409
void **ppChangeset /* OUT: Buffer containing changeset */
1039210410
);
1039310411
1039410412
/*
1039510413
** CAPI3REF: Return An Upper-limit For The Size Of The Changeset
10396
-** METHOD: sqlite3session_changeset_size()
10414
+** METHOD: sqlite3_session
1039710415
**
1039810416
** By default, this function always returns 0. For it to return
1039910417
** a useful result, the sqlite3_session object must have been configured
10400
-** to enable this API using [sqlite3session_object_config()] with the
10418
+** to enable this API using sqlite3session_object_config() with the
1040110419
** SQLITE_SESSION_OBJCONFIG_SIZE verb.
1040210420
**
1040310421
** When enabled, this function returns an upper limit, in bytes, for the size
1040410422
** of the changeset that might be produced if sqlite3session_changeset() were
1040510423
** called. The final changeset size might be equal to or smaller than the
1040610424
--- 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.36.0"
127 #define SQLITE_VERSION_NUMBER 3036000
128 #define SQLITE_SOURCE_ID "2021-04-28 17:37:26 65ec39f0f092fe29e1d4e9e96cf07a73d2ef7ce2c41b6f1cd3ab23546ada0e67"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -1139,10 +1139,14 @@
1139 ** currently has an SQL transaction open on the database. It is set to 0 if
1140 ** the database is not a wal-mode db, or if there is no such connection in any
1141 ** other process. This opcode cannot be used to detect transactions opened
1142 ** by clients within the current process, only within other processes.
1143 ** </ul>
 
 
 
 
1144 */
1145 #define SQLITE_FCNTL_LOCKSTATE 1
1146 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
1147 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
1148 #define SQLITE_FCNTL_LAST_ERRNO 4
@@ -1178,12 +1182,12 @@
1178 #define SQLITE_FCNTL_DATA_VERSION 35
1179 #define SQLITE_FCNTL_SIZE_LIMIT 36
1180 #define SQLITE_FCNTL_CKPT_DONE 37
1181 #define SQLITE_FCNTL_RESERVE_BYTES 38
1182 #define SQLITE_FCNTL_CKPT_START 39
1183
1184 #define SQLITE_FCNTL_EXTERNAL_READER 40
 
1185
1186 /* deprecated names */
1187 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1188 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1189 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -4192,10 +4196,19 @@
4192 ** changes to the content of the database files on disk.
4193 ** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
4194 ** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
4195 ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
4196 ** sqlite3_stmt_readonly() returns false for those commands.
 
 
 
 
 
 
 
 
 
4197 */
4198 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
4199
4200 /*
4201 ** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
@@ -4361,22 +4374,26 @@
4361 ** terminated. If any NUL characters occurs at byte offsets less than
4362 ** the value of the fourth parameter then the resulting string value will
4363 ** contain embedded NULs. The result of expressions involving strings
4364 ** with embedded NULs is undefined.
4365 **
4366 ** ^The fifth argument to the BLOB and string binding interfaces
4367 ** is a destructor used to dispose of the BLOB or
4368 ** string after SQLite has finished with it. ^The destructor is called
4369 ** to dispose of the BLOB or string even if the call to the bind API fails,
4370 ** except the destructor is not called if the third parameter is a NULL
4371 ** pointer or the fourth parameter is negative.
4372 ** ^If the fifth argument is
4373 ** the special value [SQLITE_STATIC], then SQLite assumes that the
4374 ** information is in static, unmanaged space and does not need to be freed.
4375 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
4376 ** SQLite makes its own private copy of the data immediately, before
4377 ** the sqlite3_bind_*() routine returns.
 
 
 
 
4378 **
4379 ** ^The sixth argument to sqlite3_bind_text64() must be one of
4380 ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
4381 ** to specify the encoding of the text in the third parameter. If
4382 ** the sixth argument to sqlite3_bind_text64() is not one of the
@@ -9812,12 +9829,12 @@
9812 **
9813 ** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the
9814 ** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory
9815 ** allocation error occurs.
9816 **
9817 ** This interface is only available if SQLite is compiled with the
9818 ** [SQLITE_ENABLE_DESERIALIZE] option.
9819 */
9820 SQLITE_API unsigned char *sqlite3_serialize(
9821 sqlite3 *db, /* The database connection */
9822 const char *zSchema, /* Which DB to serialize. ex: "main", "temp", ... */
9823 sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */
@@ -9864,12 +9881,12 @@
9864 **
9865 ** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the
9866 ** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then
9867 ** [sqlite3_free()] is invoked on argument P prior to returning.
9868 **
9869 ** This interface is only available if SQLite is compiled with the
9870 ** [SQLITE_ENABLE_DESERIALIZE] option.
9871 */
9872 SQLITE_API int sqlite3_deserialize(
9873 sqlite3 *db, /* The database connection */
9874 const char *zSchema, /* Which DB to reopen with the deserialization */
9875 unsigned char *pData, /* The serialized database content */
@@ -10121,18 +10138,15 @@
10121 ** METHOD: sqlite3_session
10122 **
10123 ** This method is used to configure a session object after it has been
10124 ** created. At present the only valid value for the second parameter is
10125 ** [SQLITE_SESSION_OBJCONFIG_SIZE].
10126 */
10127 SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
10128
10129 /*
10130 ** CAPI3REF: Arguments for sqlite3session_object_config()
10131 **
10132 ** The following values may passed as the the 4th parameter to
10133 ** [sqlite3session_object_config].
10134 **
10135 ** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
10136 ** This option is used to set, clear or query the flag that enables
10137 ** the [sqlite3session_changeset_size()] API. Because it imposes some
10138 ** computational overhead, this API is disabled by default. Argument
@@ -10143,10 +10157,14 @@
10143 ** variable is set to 1 if the sqlite3session_changeset_size() API is
10144 ** enabled following the current call, or 0 otherwise.
10145 **
10146 ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
10147 ** the first table has been attached to the session object.
 
 
 
 
10148 */
10149 #define SQLITE_SESSION_OBJCONFIG_SIZE 1
10150
10151 /*
10152 ** CAPI3REF: Enable Or Disable A Session Object
@@ -10391,15 +10409,15 @@
10391 void **ppChangeset /* OUT: Buffer containing changeset */
10392 );
10393
10394 /*
10395 ** CAPI3REF: Return An Upper-limit For The Size Of The Changeset
10396 ** METHOD: sqlite3session_changeset_size()
10397 **
10398 ** By default, this function always returns 0. For it to return
10399 ** a useful result, the sqlite3_session object must have been configured
10400 ** to enable this API using [sqlite3session_object_config()] with the
10401 ** SQLITE_SESSION_OBJCONFIG_SIZE verb.
10402 **
10403 ** When enabled, this function returns an upper limit, in bytes, for the size
10404 ** of the changeset that might be produced if sqlite3session_changeset() were
10405 ** called. The final changeset size might be equal to or smaller than the
10406
--- 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.36.0"
127 #define SQLITE_VERSION_NUMBER 3036000
128 #define SQLITE_SOURCE_ID "2021-05-14 15:37:00 cf63abbe559d04f993f99a37d41ba4a97c0261094f1d4cc05cfa23b1e11731f5"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -1139,10 +1139,14 @@
1139 ** currently has an SQL transaction open on the database. It is set to 0 if
1140 ** the database is not a wal-mode db, or if there is no such connection in any
1141 ** other process. This opcode cannot be used to detect transactions opened
1142 ** by clients within the current process, only within other processes.
1143 ** </ul>
1144 **
1145 ** <li>[[SQLITE_FCNTL_CKSM_FILE]]
1146 ** Used by the cksmvfs VFS module only.
1147 ** </ul>
1148 */
1149 #define SQLITE_FCNTL_LOCKSTATE 1
1150 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
1151 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
1152 #define SQLITE_FCNTL_LAST_ERRNO 4
@@ -1178,12 +1182,12 @@
1182 #define SQLITE_FCNTL_DATA_VERSION 35
1183 #define SQLITE_FCNTL_SIZE_LIMIT 36
1184 #define SQLITE_FCNTL_CKPT_DONE 37
1185 #define SQLITE_FCNTL_RESERVE_BYTES 38
1186 #define SQLITE_FCNTL_CKPT_START 39
 
1187 #define SQLITE_FCNTL_EXTERNAL_READER 40
1188 #define SQLITE_FCNTL_CKSM_FILE 41
1189
1190 /* deprecated names */
1191 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1192 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1193 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -4192,10 +4196,19 @@
4196 ** changes to the content of the database files on disk.
4197 ** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
4198 ** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
4199 ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
4200 ** sqlite3_stmt_readonly() returns false for those commands.
4201 **
4202 ** ^This routine returns false if there is any possibility that the
4203 ** statement might change the database file. ^A false return does
4204 ** not guarantee that the statement will change the database file.
4205 ** ^For example, an UPDATE statement might have a WHERE clause that
4206 ** makes it a no-op, but the sqlite3_stmt_readonly() result would still
4207 ** be false. ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a
4208 ** read-only no-op if the table already exists, but
4209 ** sqlite3_stmt_readonly() still returns false for such a statement.
4210 */
4211 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
4212
4213 /*
4214 ** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
@@ -4361,22 +4374,26 @@
4374 ** terminated. If any NUL characters occurs at byte offsets less than
4375 ** the value of the fourth parameter then the resulting string value will
4376 ** contain embedded NULs. The result of expressions involving strings
4377 ** with embedded NULs is undefined.
4378 **
4379 ** ^The fifth argument to the BLOB and string binding interfaces controls
4380 ** or indicates the lifetime of the object referenced by the third parameter.
4381 ** ^These three options exist:
4382 ** ^(1) A destructor to dispose of the BLOB or string after SQLite has finished
4383 ** with it may be passed. ^It is called to dispose of the BLOB or string even
4384 ** if the call to the bind API fails, except the destructor is not called if
4385 ** the third parameter is a NULL pointer or the fourth parameter is negative.
4386 ** ^(2) The special constant, [SQLITE_STATIC], may be passsed to indicate that
4387 ** the application remains responsible for disposing of the object. ^In this
4388 ** case, the object and the provided pointer to it must remain valid until
4389 ** either the prepared statement is finalized or the same SQL parameter is
4390 ** bound to something else, whichever occurs sooner.
4391 ** ^(3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the
4392 ** object is to be copied prior to the return from sqlite3_bind_*(). ^The
4393 ** object and pointer to it must remain valid until then. ^SQLite will then
4394 ** manage the lifetime of its private copy.
4395 **
4396 ** ^The sixth argument to sqlite3_bind_text64() must be one of
4397 ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
4398 ** to specify the encoding of the text in the third parameter. If
4399 ** the sixth argument to sqlite3_bind_text64() is not one of the
@@ -9812,12 +9829,12 @@
9829 **
9830 ** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the
9831 ** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory
9832 ** allocation error occurs.
9833 **
9834 ** This interface is omitted if SQLite is compiled with the
9835 ** [SQLITE_OMIT_DESERIALIZE] option.
9836 */
9837 SQLITE_API unsigned char *sqlite3_serialize(
9838 sqlite3 *db, /* The database connection */
9839 const char *zSchema, /* Which DB to serialize. ex: "main", "temp", ... */
9840 sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */
@@ -9864,12 +9881,12 @@
9881 **
9882 ** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the
9883 ** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then
9884 ** [sqlite3_free()] is invoked on argument P prior to returning.
9885 **
9886 ** This interface is omitted if SQLite is compiled with the
9887 ** [SQLITE_OMIT_DESERIALIZE] option.
9888 */
9889 SQLITE_API int sqlite3_deserialize(
9890 sqlite3 *db, /* The database connection */
9891 const char *zSchema, /* Which DB to reopen with the deserialization */
9892 unsigned char *pData, /* The serialized database content */
@@ -10121,18 +10138,15 @@
10138 ** METHOD: sqlite3_session
10139 **
10140 ** This method is used to configure a session object after it has been
10141 ** created. At present the only valid value for the second parameter is
10142 ** [SQLITE_SESSION_OBJCONFIG_SIZE].
10143 **
10144 ** Arguments for sqlite3session_object_config()
 
 
 
10145 **
10146 ** The following values may passed as the the 4th parameter to
10147 ** sqlite3session_object_config().
10148 **
10149 ** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
10150 ** This option is used to set, clear or query the flag that enables
10151 ** the [sqlite3session_changeset_size()] API. Because it imposes some
10152 ** computational overhead, this API is disabled by default. Argument
@@ -10143,10 +10157,14 @@
10157 ** variable is set to 1 if the sqlite3session_changeset_size() API is
10158 ** enabled following the current call, or 0 otherwise.
10159 **
10160 ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
10161 ** the first table has been attached to the session object.
10162 */
10163 SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
10164
10165 /*
10166 */
10167 #define SQLITE_SESSION_OBJCONFIG_SIZE 1
10168
10169 /*
10170 ** CAPI3REF: Enable Or Disable A Session Object
@@ -10391,15 +10409,15 @@
10409 void **ppChangeset /* OUT: Buffer containing changeset */
10410 );
10411
10412 /*
10413 ** CAPI3REF: Return An Upper-limit For The Size Of The Changeset
10414 ** METHOD: sqlite3_session
10415 **
10416 ** By default, this function always returns 0. For it to return
10417 ** a useful result, the sqlite3_session object must have been configured
10418 ** to enable this API using sqlite3session_object_config() with the
10419 ** SQLITE_SESSION_OBJCONFIG_SIZE verb.
10420 **
10421 ** When enabled, this function returns an upper limit, in bytes, for the size
10422 ** of the changeset that might be produced if sqlite3session_changeset() were
10423 ** called. The final changeset size might be equal to or smaller than the
10424

Keyboard Shortcuts

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