Fossil SCM

Update the built-in SQLite to the latest 3.28.0 alpha version.

drh 2019-03-18 10:38 trunk
Commit 831e1af2540475cd35b8310108eec470b909efb087c6b2f37de2c4cae85576f3
3 files changed +176 -8 +125 -35 +19 -5
+176 -8
--- src/shell.c
+++ src/shell.c
@@ -2175,17 +2175,17 @@
21752175
if( nIn>mxBlob ){
21762176
sqlite3_result_error_code(ctx, SQLITE_TOOBIG);
21772177
fclose(in);
21782178
return;
21792179
}
2180
- pBuf = sqlite3_malloc64( nIn );
2180
+ pBuf = sqlite3_malloc64( nIn ? nIn : 1 );
21812181
if( pBuf==0 ){
21822182
sqlite3_result_error_nomem(ctx);
21832183
fclose(in);
21842184
return;
21852185
}
2186
- if( 1==fread(pBuf, nIn, 1, in) ){
2186
+ if( nIn==fread(pBuf, 1, nIn, in) ){
21872187
sqlite3_result_blob64(ctx, pBuf, nIn, sqlite3_free);
21882188
}else{
21892189
sqlite3_result_error_code(ctx, SQLITE_IOERR);
21902190
sqlite3_free(pBuf);
21912191
}
@@ -10427,10 +10427,69 @@
1042710427
#endif
1042810428
#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
1042910429
sqlite3WhereTrace = savedWhereTrace;
1043010430
#endif
1043110431
}
10432
+
10433
+/* Name of the TEMP table that holds bind parameter values */
10434
+#define BIND_PARAM_TABLE "$Parameters"
10435
+
10436
+/* Create the TEMP table used to store parameter bindings */
10437
+static void bind_table_init(ShellState *p){
10438
+ sqlite3_exec(p->db,
10439
+ "CREATE TABLE IF NOT EXISTS temp.[" BIND_PARAM_TABLE "](\n"
10440
+ " key TEXT PRIMARY KEY,\n"
10441
+ " value ANY\n"
10442
+ ") WITHOUT ROWID;",
10443
+ 0, 0, 0);
10444
+}
10445
+
10446
+/*
10447
+** Bind parameters on a prepared statement.
10448
+**
10449
+** Parameter bindings are taken from a TEMP table of the form:
10450
+**
10451
+** CREATE TEMP TABLE "$Parameters"(key TEXT PRIMARY KEY, value)
10452
+** WITHOUT ROWID;
10453
+**
10454
+** No bindings occur if this table does not exist. The special character '$'
10455
+** is included in the table name to help prevent collisions with actual tables.
10456
+** The table must be in the TEMP schema.
10457
+*/
10458
+static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){
10459
+ int nVar;
10460
+ int i;
10461
+ int rc;
10462
+ sqlite3_stmt *pQ = 0;
10463
+
10464
+ nVar = sqlite3_bind_parameter_count(pStmt);
10465
+ if( nVar==0 ) return; /* Nothing to do */
10466
+ if( sqlite3_table_column_metadata(pArg->db, "TEMP", BIND_PARAM_TABLE,
10467
+ "key", 0, 0, 0, 0, 0)!=SQLITE_OK ){
10468
+ return; /* Parameter table does not exist */
10469
+ }
10470
+ rc = sqlite3_prepare_v2(pArg->db,
10471
+ "SELECT value FROM temp.\"" BIND_PARAM_TABLE "\""
10472
+ " WHERE key=?1", -1, &pQ, 0);
10473
+ if( rc || pQ==0 ) return;
10474
+ for(i=1; i<=nVar; i++){
10475
+ char zNum[30];
10476
+ const char *zVar = sqlite3_bind_parameter_name(pStmt, i);
10477
+ if( zVar==0 ){
10478
+ sqlite3_snprintf(sizeof(zNum),zNum,"?%d",i);
10479
+ zVar = zNum;
10480
+ }
10481
+ sqlite3_bind_text(pQ, 1, zVar, -1, SQLITE_STATIC);
10482
+ if( sqlite3_step(pQ)==SQLITE_ROW ){
10483
+ sqlite3_bind_value(pStmt, i, sqlite3_column_value(pQ, 0));
10484
+ }else{
10485
+ sqlite3_bind_null(pStmt, i);
10486
+ }
10487
+ sqlite3_reset(pQ);
10488
+ }
10489
+ sqlite3_finalize(pQ);
10490
+}
1043210491
1043310492
/*
1043410493
** Run a prepared statement
1043510494
*/
1043610495
static void exec_prepared_stmt(
@@ -10680,11 +10739,11 @@
1068010739
if( pArg && ShellHasFlag(pArg, SHFLG_Echo) ){
1068110740
utf8_printf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
1068210741
}
1068310742
1068410743
/* Show the EXPLAIN QUERY PLAN if .eqp is on */
10685
- if( pArg && pArg->autoEQP && sqlite3_strlike("EXPLAIN%",zStmtSql,0)!=0 ){
10744
+ if( pArg && pArg->autoEQP && sqlite3_stmt_isexplain(pStmt)==0 ){
1068610745
sqlite3_stmt *pExplain;
1068710746
char *zEQP;
1068810747
int triggerEQP = 0;
1068910748
disable_debug_trace_modes();
1069010749
sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, -1, &triggerEQP);
@@ -10729,17 +10788,14 @@
1072910788
}
1073010789
1073110790
if( pArg ){
1073210791
pArg->cMode = pArg->mode;
1073310792
if( pArg->autoExplain ){
10734
- if( sqlite3_column_count(pStmt)==8
10735
- && sqlite3_strlike("EXPLAIN%", zStmtSql,0)==0
10736
- ){
10793
+ if( sqlite3_stmt_isexplain(pStmt)==1 ){
1073710794
pArg->cMode = MODE_Explain;
1073810795
}
10739
- if( sqlite3_column_count(pStmt)==4
10740
- && sqlite3_strlike("EXPLAIN QUERY PLAN%", zStmtSql,0)==0 ){
10796
+ if( sqlite3_stmt_isexplain(pStmt)==2 ){
1074110797
pArg->cMode = MODE_EQP;
1074210798
}
1074310799
}
1074410800
1074510801
/* If the shell is currently in ".explain" mode, gather the extra
@@ -10747,10 +10803,11 @@
1074710803
if( pArg->cMode==MODE_Explain ){
1074810804
explain_data_prepare(pArg, pStmt);
1074910805
}
1075010806
}
1075110807
10808
+ bind_prepared_stmt(pArg, pStmt);
1075210809
exec_prepared_stmt(pArg, pStmt);
1075310810
explain_data_delete(pArg);
1075410811
eqp_render(pArg);
1075510812
1075610813
/* print usage stats if stats on */
@@ -11178,10 +11235,17 @@
1117811235
" --new Initialize FILE to an empty database",
1117911236
" --readonly Open FILE readonly",
1118011237
" --zip FILE is a ZIP archive",
1118111238
".output ?FILE? Send output to FILE or stdout if FILE is omitted",
1118211239
" If FILE begins with '|' then open it as a pipe.",
11240
+ ".parameter CMD ... Manage SQL parameter bindings",
11241
+ " clear Erase all bindings",
11242
+ " init Initialize the TEMP table that holds bindings",
11243
+ " list List the current parameter bindings",
11244
+ " set PARAMETER VALUE Given SQL parameter PARAMETER a value of VALUE",
11245
+ " PARAMETER should start with '$', ':', '@', or '?'",
11246
+ " unset PARAMETER Remove PARAMETER from the binding table",
1118311247
".print STRING... Print literal STRING",
1118411248
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
1118511249
".progress N Invoke progress handler after every N opcodes",
1118611250
" --limit N Interrupt after N progress callbacks",
1118711251
" --once Do no more than one progress interrupt",
@@ -14708,10 +14772,114 @@
1470814772
} else {
1470914773
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
1471014774
}
1471114775
}
1471214776
}else
14777
+
14778
+ if( c=='p' && n>=3 && strncmp(azArg[0], "parameter", n)==0 ){
14779
+ open_db(p,0);
14780
+ if( nArg<=1 ) goto parameter_syntax_error;
14781
+
14782
+ /* .parameter clear
14783
+ ** Clear all bind parameters by dropping the TEMP table that holds them.
14784
+ */
14785
+ if( nArg==2 && strcmp(azArg[1],"clear")==0 ){
14786
+ sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp.[" BIND_PARAM_TABLE "];",
14787
+ 0, 0, 0);
14788
+ }else
14789
+
14790
+ /* .parameter list
14791
+ ** List all bind parameters.
14792
+ */
14793
+ if( nArg==2 && strcmp(azArg[1],"list")==0 ){
14794
+ sqlite3_stmt *pStmt = 0;
14795
+ int rx;
14796
+ int len = 0;
14797
+ rx = sqlite3_prepare_v2(p->db,
14798
+ "SELECT max(length(key)) "
14799
+ "FROM temp.[" BIND_PARAM_TABLE "];", -1, &pStmt, 0);
14800
+ if( rx==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
14801
+ len = sqlite3_column_int(pStmt, 0);
14802
+ if( len>40 ) len = 40;
14803
+ }
14804
+ sqlite3_finalize(pStmt);
14805
+ pStmt = 0;
14806
+ if( len ){
14807
+ rx = sqlite3_prepare_v2(p->db,
14808
+ "SELECT key, quote(value) "
14809
+ "FROM temp.[" BIND_PARAM_TABLE "];", -1, &pStmt, 0);
14810
+ while( sqlite3_step(pStmt)==SQLITE_ROW ){
14811
+ utf8_printf(p->out, "%-*s %s\n", len, sqlite3_column_text(pStmt,0),
14812
+ sqlite3_column_text(pStmt,1));
14813
+ }
14814
+ sqlite3_finalize(pStmt);
14815
+ }
14816
+ }else
14817
+
14818
+ /* .parameter init
14819
+ ** Make sure the TEMP table used to hold bind parameters exists.
14820
+ ** Create it if necessary.
14821
+ */
14822
+ if( nArg==2 && strcmp(azArg[1],"init")==0 ){
14823
+ bind_table_init(p);
14824
+ }else
14825
+
14826
+ /* .parameter set NAME VALUE
14827
+ ** Set or reset a bind parameter. NAME should be the full parameter
14828
+ ** name exactly as it appears in the query. (ex: $abc, @def). The
14829
+ ** VALUE can be in either SQL literal notation, or if not it will be
14830
+ ** understood to be a text string.
14831
+ */
14832
+ if( nArg==4 && strcmp(azArg[1],"set")==0 ){
14833
+ int rx;
14834
+ char *zSql;
14835
+ sqlite3_stmt *pStmt;
14836
+ const char *zKey = azArg[2];
14837
+ const char *zValue = azArg[3];
14838
+ bind_table_init(p);
14839
+ zSql = sqlite3_mprintf(
14840
+ "REPLACE INTO temp.[" BIND_PARAM_TABLE "](key,value)"
14841
+ "VALUES(%Q,%s);", zKey, zValue);
14842
+ if( zSql==0 ) shell_out_of_memory();
14843
+ pStmt = 0;
14844
+ rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
14845
+ sqlite3_free(zSql);
14846
+ if( rx!=SQLITE_OK ){
14847
+ sqlite3_finalize(pStmt);
14848
+ pStmt = 0;
14849
+ zSql = sqlite3_mprintf(
14850
+ "REPLACE INTO temp.[" BIND_PARAM_TABLE "](key,value)"
14851
+ "VALUES(%Q,%Q);", zKey, zValue);
14852
+ if( zSql==0 ) shell_out_of_memory();
14853
+ rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
14854
+ sqlite3_free(zSql);
14855
+ if( rx!=SQLITE_OK ){
14856
+ utf8_printf(p->out, "Error: %s\n", sqlite3_errmsg(p->db));
14857
+ sqlite3_finalize(pStmt);
14858
+ pStmt = 0;
14859
+ rc = 1;
14860
+ }
14861
+ }
14862
+ sqlite3_step(pStmt);
14863
+ sqlite3_finalize(pStmt);
14864
+ }else
14865
+
14866
+ /* .parameter unset NAME
14867
+ ** Remove the NAME binding from the parameter binding table, if it
14868
+ ** exists.
14869
+ */
14870
+ if( nArg==3 && strcmp(azArg[1],"unset")==0 ){
14871
+ char *zSql = sqlite3_mprintf(
14872
+ "DELETE FROM temp.[" BIND_PARAM_TABLE "] WHERE key=%Q", azArg[2]);
14873
+ if( zSql==0 ) shell_out_of_memory();
14874
+ sqlite3_exec(p->db, zSql, 0, 0, 0);
14875
+ sqlite3_free(zSql);
14876
+ }else
14877
+ /* If no command name matches, show a syntax error */
14878
+ parameter_syntax_error:
14879
+ showHelp(p->out, "parameter");
14880
+ }else
1471314881
1471414882
if( c=='p' && n>=3 && strncmp(azArg[0], "print", n)==0 ){
1471514883
int i;
1471614884
for(i=1; i<nArg; i++){
1471714885
if( i>1 ) raw_printf(p->out, " ");
1471814886
--- src/shell.c
+++ src/shell.c
@@ -2175,17 +2175,17 @@
2175 if( nIn>mxBlob ){
2176 sqlite3_result_error_code(ctx, SQLITE_TOOBIG);
2177 fclose(in);
2178 return;
2179 }
2180 pBuf = sqlite3_malloc64( nIn );
2181 if( pBuf==0 ){
2182 sqlite3_result_error_nomem(ctx);
2183 fclose(in);
2184 return;
2185 }
2186 if( 1==fread(pBuf, nIn, 1, in) ){
2187 sqlite3_result_blob64(ctx, pBuf, nIn, sqlite3_free);
2188 }else{
2189 sqlite3_result_error_code(ctx, SQLITE_IOERR);
2190 sqlite3_free(pBuf);
2191 }
@@ -10427,10 +10427,69 @@
10427 #endif
10428 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
10429 sqlite3WhereTrace = savedWhereTrace;
10430 #endif
10431 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10432
10433 /*
10434 ** Run a prepared statement
10435 */
10436 static void exec_prepared_stmt(
@@ -10680,11 +10739,11 @@
10680 if( pArg && ShellHasFlag(pArg, SHFLG_Echo) ){
10681 utf8_printf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
10682 }
10683
10684 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
10685 if( pArg && pArg->autoEQP && sqlite3_strlike("EXPLAIN%",zStmtSql,0)!=0 ){
10686 sqlite3_stmt *pExplain;
10687 char *zEQP;
10688 int triggerEQP = 0;
10689 disable_debug_trace_modes();
10690 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, -1, &triggerEQP);
@@ -10729,17 +10788,14 @@
10729 }
10730
10731 if( pArg ){
10732 pArg->cMode = pArg->mode;
10733 if( pArg->autoExplain ){
10734 if( sqlite3_column_count(pStmt)==8
10735 && sqlite3_strlike("EXPLAIN%", zStmtSql,0)==0
10736 ){
10737 pArg->cMode = MODE_Explain;
10738 }
10739 if( sqlite3_column_count(pStmt)==4
10740 && sqlite3_strlike("EXPLAIN QUERY PLAN%", zStmtSql,0)==0 ){
10741 pArg->cMode = MODE_EQP;
10742 }
10743 }
10744
10745 /* If the shell is currently in ".explain" mode, gather the extra
@@ -10747,10 +10803,11 @@
10747 if( pArg->cMode==MODE_Explain ){
10748 explain_data_prepare(pArg, pStmt);
10749 }
10750 }
10751
 
10752 exec_prepared_stmt(pArg, pStmt);
10753 explain_data_delete(pArg);
10754 eqp_render(pArg);
10755
10756 /* print usage stats if stats on */
@@ -11178,10 +11235,17 @@
11178 " --new Initialize FILE to an empty database",
11179 " --readonly Open FILE readonly",
11180 " --zip FILE is a ZIP archive",
11181 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
11182 " If FILE begins with '|' then open it as a pipe.",
 
 
 
 
 
 
 
11183 ".print STRING... Print literal STRING",
11184 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
11185 ".progress N Invoke progress handler after every N opcodes",
11186 " --limit N Interrupt after N progress callbacks",
11187 " --once Do no more than one progress interrupt",
@@ -14708,10 +14772,114 @@
14708 } else {
14709 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
14710 }
14711 }
14712 }else
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14713
14714 if( c=='p' && n>=3 && strncmp(azArg[0], "print", n)==0 ){
14715 int i;
14716 for(i=1; i<nArg; i++){
14717 if( i>1 ) raw_printf(p->out, " ");
14718
--- src/shell.c
+++ src/shell.c
@@ -2175,17 +2175,17 @@
2175 if( nIn>mxBlob ){
2176 sqlite3_result_error_code(ctx, SQLITE_TOOBIG);
2177 fclose(in);
2178 return;
2179 }
2180 pBuf = sqlite3_malloc64( nIn ? nIn : 1 );
2181 if( pBuf==0 ){
2182 sqlite3_result_error_nomem(ctx);
2183 fclose(in);
2184 return;
2185 }
2186 if( nIn==fread(pBuf, 1, nIn, in) ){
2187 sqlite3_result_blob64(ctx, pBuf, nIn, sqlite3_free);
2188 }else{
2189 sqlite3_result_error_code(ctx, SQLITE_IOERR);
2190 sqlite3_free(pBuf);
2191 }
@@ -10427,10 +10427,69 @@
10427 #endif
10428 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
10429 sqlite3WhereTrace = savedWhereTrace;
10430 #endif
10431 }
10432
10433 /* Name of the TEMP table that holds bind parameter values */
10434 #define BIND_PARAM_TABLE "$Parameters"
10435
10436 /* Create the TEMP table used to store parameter bindings */
10437 static void bind_table_init(ShellState *p){
10438 sqlite3_exec(p->db,
10439 "CREATE TABLE IF NOT EXISTS temp.[" BIND_PARAM_TABLE "](\n"
10440 " key TEXT PRIMARY KEY,\n"
10441 " value ANY\n"
10442 ") WITHOUT ROWID;",
10443 0, 0, 0);
10444 }
10445
10446 /*
10447 ** Bind parameters on a prepared statement.
10448 **
10449 ** Parameter bindings are taken from a TEMP table of the form:
10450 **
10451 ** CREATE TEMP TABLE "$Parameters"(key TEXT PRIMARY KEY, value)
10452 ** WITHOUT ROWID;
10453 **
10454 ** No bindings occur if this table does not exist. The special character '$'
10455 ** is included in the table name to help prevent collisions with actual tables.
10456 ** The table must be in the TEMP schema.
10457 */
10458 static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){
10459 int nVar;
10460 int i;
10461 int rc;
10462 sqlite3_stmt *pQ = 0;
10463
10464 nVar = sqlite3_bind_parameter_count(pStmt);
10465 if( nVar==0 ) return; /* Nothing to do */
10466 if( sqlite3_table_column_metadata(pArg->db, "TEMP", BIND_PARAM_TABLE,
10467 "key", 0, 0, 0, 0, 0)!=SQLITE_OK ){
10468 return; /* Parameter table does not exist */
10469 }
10470 rc = sqlite3_prepare_v2(pArg->db,
10471 "SELECT value FROM temp.\"" BIND_PARAM_TABLE "\""
10472 " WHERE key=?1", -1, &pQ, 0);
10473 if( rc || pQ==0 ) return;
10474 for(i=1; i<=nVar; i++){
10475 char zNum[30];
10476 const char *zVar = sqlite3_bind_parameter_name(pStmt, i);
10477 if( zVar==0 ){
10478 sqlite3_snprintf(sizeof(zNum),zNum,"?%d",i);
10479 zVar = zNum;
10480 }
10481 sqlite3_bind_text(pQ, 1, zVar, -1, SQLITE_STATIC);
10482 if( sqlite3_step(pQ)==SQLITE_ROW ){
10483 sqlite3_bind_value(pStmt, i, sqlite3_column_value(pQ, 0));
10484 }else{
10485 sqlite3_bind_null(pStmt, i);
10486 }
10487 sqlite3_reset(pQ);
10488 }
10489 sqlite3_finalize(pQ);
10490 }
10491
10492 /*
10493 ** Run a prepared statement
10494 */
10495 static void exec_prepared_stmt(
@@ -10680,11 +10739,11 @@
10739 if( pArg && ShellHasFlag(pArg, SHFLG_Echo) ){
10740 utf8_printf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
10741 }
10742
10743 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
10744 if( pArg && pArg->autoEQP && sqlite3_stmt_isexplain(pStmt)==0 ){
10745 sqlite3_stmt *pExplain;
10746 char *zEQP;
10747 int triggerEQP = 0;
10748 disable_debug_trace_modes();
10749 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, -1, &triggerEQP);
@@ -10729,17 +10788,14 @@
10788 }
10789
10790 if( pArg ){
10791 pArg->cMode = pArg->mode;
10792 if( pArg->autoExplain ){
10793 if( sqlite3_stmt_isexplain(pStmt)==1 ){
 
 
10794 pArg->cMode = MODE_Explain;
10795 }
10796 if( sqlite3_stmt_isexplain(pStmt)==2 ){
 
10797 pArg->cMode = MODE_EQP;
10798 }
10799 }
10800
10801 /* If the shell is currently in ".explain" mode, gather the extra
@@ -10747,10 +10803,11 @@
10803 if( pArg->cMode==MODE_Explain ){
10804 explain_data_prepare(pArg, pStmt);
10805 }
10806 }
10807
10808 bind_prepared_stmt(pArg, pStmt);
10809 exec_prepared_stmt(pArg, pStmt);
10810 explain_data_delete(pArg);
10811 eqp_render(pArg);
10812
10813 /* print usage stats if stats on */
@@ -11178,10 +11235,17 @@
11235 " --new Initialize FILE to an empty database",
11236 " --readonly Open FILE readonly",
11237 " --zip FILE is a ZIP archive",
11238 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
11239 " If FILE begins with '|' then open it as a pipe.",
11240 ".parameter CMD ... Manage SQL parameter bindings",
11241 " clear Erase all bindings",
11242 " init Initialize the TEMP table that holds bindings",
11243 " list List the current parameter bindings",
11244 " set PARAMETER VALUE Given SQL parameter PARAMETER a value of VALUE",
11245 " PARAMETER should start with '$', ':', '@', or '?'",
11246 " unset PARAMETER Remove PARAMETER from the binding table",
11247 ".print STRING... Print literal STRING",
11248 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
11249 ".progress N Invoke progress handler after every N opcodes",
11250 " --limit N Interrupt after N progress callbacks",
11251 " --once Do no more than one progress interrupt",
@@ -14708,10 +14772,114 @@
14772 } else {
14773 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
14774 }
14775 }
14776 }else
14777
14778 if( c=='p' && n>=3 && strncmp(azArg[0], "parameter", n)==0 ){
14779 open_db(p,0);
14780 if( nArg<=1 ) goto parameter_syntax_error;
14781
14782 /* .parameter clear
14783 ** Clear all bind parameters by dropping the TEMP table that holds them.
14784 */
14785 if( nArg==2 && strcmp(azArg[1],"clear")==0 ){
14786 sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp.[" BIND_PARAM_TABLE "];",
14787 0, 0, 0);
14788 }else
14789
14790 /* .parameter list
14791 ** List all bind parameters.
14792 */
14793 if( nArg==2 && strcmp(azArg[1],"list")==0 ){
14794 sqlite3_stmt *pStmt = 0;
14795 int rx;
14796 int len = 0;
14797 rx = sqlite3_prepare_v2(p->db,
14798 "SELECT max(length(key)) "
14799 "FROM temp.[" BIND_PARAM_TABLE "];", -1, &pStmt, 0);
14800 if( rx==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
14801 len = sqlite3_column_int(pStmt, 0);
14802 if( len>40 ) len = 40;
14803 }
14804 sqlite3_finalize(pStmt);
14805 pStmt = 0;
14806 if( len ){
14807 rx = sqlite3_prepare_v2(p->db,
14808 "SELECT key, quote(value) "
14809 "FROM temp.[" BIND_PARAM_TABLE "];", -1, &pStmt, 0);
14810 while( sqlite3_step(pStmt)==SQLITE_ROW ){
14811 utf8_printf(p->out, "%-*s %s\n", len, sqlite3_column_text(pStmt,0),
14812 sqlite3_column_text(pStmt,1));
14813 }
14814 sqlite3_finalize(pStmt);
14815 }
14816 }else
14817
14818 /* .parameter init
14819 ** Make sure the TEMP table used to hold bind parameters exists.
14820 ** Create it if necessary.
14821 */
14822 if( nArg==2 && strcmp(azArg[1],"init")==0 ){
14823 bind_table_init(p);
14824 }else
14825
14826 /* .parameter set NAME VALUE
14827 ** Set or reset a bind parameter. NAME should be the full parameter
14828 ** name exactly as it appears in the query. (ex: $abc, @def). The
14829 ** VALUE can be in either SQL literal notation, or if not it will be
14830 ** understood to be a text string.
14831 */
14832 if( nArg==4 && strcmp(azArg[1],"set")==0 ){
14833 int rx;
14834 char *zSql;
14835 sqlite3_stmt *pStmt;
14836 const char *zKey = azArg[2];
14837 const char *zValue = azArg[3];
14838 bind_table_init(p);
14839 zSql = sqlite3_mprintf(
14840 "REPLACE INTO temp.[" BIND_PARAM_TABLE "](key,value)"
14841 "VALUES(%Q,%s);", zKey, zValue);
14842 if( zSql==0 ) shell_out_of_memory();
14843 pStmt = 0;
14844 rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
14845 sqlite3_free(zSql);
14846 if( rx!=SQLITE_OK ){
14847 sqlite3_finalize(pStmt);
14848 pStmt = 0;
14849 zSql = sqlite3_mprintf(
14850 "REPLACE INTO temp.[" BIND_PARAM_TABLE "](key,value)"
14851 "VALUES(%Q,%Q);", zKey, zValue);
14852 if( zSql==0 ) shell_out_of_memory();
14853 rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
14854 sqlite3_free(zSql);
14855 if( rx!=SQLITE_OK ){
14856 utf8_printf(p->out, "Error: %s\n", sqlite3_errmsg(p->db));
14857 sqlite3_finalize(pStmt);
14858 pStmt = 0;
14859 rc = 1;
14860 }
14861 }
14862 sqlite3_step(pStmt);
14863 sqlite3_finalize(pStmt);
14864 }else
14865
14866 /* .parameter unset NAME
14867 ** Remove the NAME binding from the parameter binding table, if it
14868 ** exists.
14869 */
14870 if( nArg==3 && strcmp(azArg[1],"unset")==0 ){
14871 char *zSql = sqlite3_mprintf(
14872 "DELETE FROM temp.[" BIND_PARAM_TABLE "] WHERE key=%Q", azArg[2]);
14873 if( zSql==0 ) shell_out_of_memory();
14874 sqlite3_exec(p->db, zSql, 0, 0, 0);
14875 sqlite3_free(zSql);
14876 }else
14877 /* If no command name matches, show a syntax error */
14878 parameter_syntax_error:
14879 showHelp(p->out, "parameter");
14880 }else
14881
14882 if( c=='p' && n>=3 && strncmp(azArg[0], "print", n)==0 ){
14883 int i;
14884 for(i=1; i<nArg; i++){
14885 if( i>1 ) raw_printf(p->out, " ");
14886
+125 -35
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
11621162
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11631163
** [sqlite_version()] and [sqlite_source_id()].
11641164
*/
11651165
#define SQLITE_VERSION "3.28.0"
11661166
#define SQLITE_VERSION_NUMBER 3028000
1167
-#define SQLITE_SOURCE_ID "2019-02-25 14:52:43 9da4fb59b28686630d63a79988b458726332cf06cc0e6e84d7c0a7600f5fcab0"
1167
+#define SQLITE_SOURCE_ID "2019-03-17 23:59:02 cc5ab96715ebb1089b4e9aa647badd2510aaa056f26004718f921f4ac07e2f93"
11681168
11691169
/*
11701170
** CAPI3REF: Run-Time Library Version Numbers
11711171
** KEYWORDS: sqlite3_version sqlite3_sourceid
11721172
**
@@ -3123,12 +3123,12 @@
31233123
** following this call. The second parameter may be a NULL pointer, in
31243124
** which case the trigger setting is not reported back. </dd>
31253125
**
31263126
** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
31273127
** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
3128
-** <dd> ^This option is used to enable or disable the two-argument
3129
-** version of the [fts3_tokenizer()] function which is part of the
3128
+** <dd> ^This option is used to enable or disable the
3129
+** [fts3_tokenizer()] function which is part of the
31303130
** [FTS3] full-text search engine extension.
31313131
** There should be two additional arguments.
31323132
** The first argument is an integer which is 0 to disable fts3_tokenizer() or
31333133
** positive to enable fts3_tokenizer() or negative to leave the setting
31343134
** unchanged.
@@ -4931,10 +4931,22 @@
49314931
** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
49324932
** sqlite3_stmt_readonly() returns false for those commands.
49334933
*/
49344934
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
49354935
4936
+/*
4937
+** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
4938
+** METHOD: sqlite3_stmt
4939
+**
4940
+** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the
4941
+** prepared statement S is an EXPLAIN statement, or 2 if the
4942
+** statement S is an EXPLAIN QUERY PLAN.
4943
+** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
4944
+** an ordinary statement or a NULL pointer.
4945
+*/
4946
+SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);
4947
+
49364948
/*
49374949
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
49384950
** METHOD: sqlite3_stmt
49394951
**
49404952
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
@@ -5070,11 +5082,13 @@
50705082
** with embedded NULs is undefined.
50715083
**
50725084
** ^The fifth argument to the BLOB and string binding interfaces
50735085
** is a destructor used to dispose of the BLOB or
50745086
** string after SQLite has finished with it. ^The destructor is called
5075
-** to dispose of the BLOB or string even if the call to bind API fails.
5087
+** to dispose of the BLOB or string even if the call to the bind API fails,
5088
+** except the destructor is not called if the third parameter is a NULL
5089
+** pointer or the fourth parameter is negative.
50765090
** ^If the fifth argument is
50775091
** the special value [SQLITE_STATIC], then SQLite assumes that the
50785092
** information is in static, unmanaged space and does not need to be freed.
50795093
** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
50805094
** SQLite makes its own private copy of the data immediately, before
@@ -6828,11 +6842,11 @@
68286842
**
68296843
** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
68306844
** associated with database N of connection D. ^The main database file
68316845
** has the name "main". If there is no attached database N on the database
68326846
** connection D, or if database N is a temporary or in-memory database, then
6833
-** a NULL pointer is returned.
6847
+** this function will return either a NULL pointer or an empty string.
68346848
**
68356849
** ^The filename returned by this function is the output of the
68366850
** xFullPathname method of the [VFS]. ^In other words, the filename
68376851
** will be an absolute pathname, even if the filename used
68386852
** to open the database originally was a URI or relative pathname.
@@ -40220,13 +40234,10 @@
4022040234
static sqlite3_vfs aVfs[] = {
4022140235
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
4022240236
UNIXVFS("unix", autolockIoFinder ),
4022340237
#elif OS_VXWORKS
4022440238
UNIXVFS("unix", vxworksIoFinder ),
40225
-#elif __Fuchsia__
40226
- /* We are told that Fuchsia only supports dot-file locking */
40227
- UNIXVFS("unix", dotlockIoFinder ),
4022840239
#else
4022940240
UNIXVFS("unix", posixIoFinder ),
4023040241
#endif
4023140242
UNIXVFS("unix-none", nolockIoFinder ),
4023240243
UNIXVFS("unix-dotfile", dotlockIoFinder ),
@@ -51308,10 +51319,13 @@
5130851319
** * the desired page is not currently in the wal file.
5130951320
*/
5131051321
SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno){
5131151322
if( pPager->fd->pMethods==0 ) return 0;
5131251323
if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0;
51324
+#ifdef SQLITE_HAS_CODEC
51325
+ if( pPager->xCodec!=0 ) return 0;
51326
+#endif
5131351327
#ifndef SQLITE_OMIT_WAL
5131451328
if( pPager->pWal ){
5131551329
u32 iRead = 0;
5131651330
int rc;
5131751331
rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iRead);
@@ -54257,12 +54271,18 @@
5425754271
5425854272
if( pPager->eState>PAGER_OPEN && isOpen(pPager->fd) ){
5425954273
rc = sqlite3OsFileSize(pPager->fd, &nByte);
5426054274
}
5426154275
if( rc==SQLITE_OK ){
54262
- pNew = (char *)sqlite3PageMalloc(pageSize);
54263
- if( !pNew ) rc = SQLITE_NOMEM_BKPT;
54276
+ /* 8 bytes of zeroed overrun space is sufficient so that the b-tree
54277
+ * cell header parser will never run off the end of the allocation */
54278
+ pNew = (char *)sqlite3PageMalloc(pageSize+8);
54279
+ if( !pNew ){
54280
+ rc = SQLITE_NOMEM_BKPT;
54281
+ }else{
54282
+ memset(pNew+pageSize, 0, 8);
54283
+ }
5426454284
}
5426554285
5426654286
if( rc==SQLITE_OK ){
5426754287
pager_reset(pPager);
5426854288
rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
@@ -57639,12 +57659,16 @@
5763957659
** page pgno before the 'move' operation, it needs to be retained
5764057660
** for the page moved there.
5764157661
*/
5764257662
pPg->flags &= ~PGHDR_NEED_SYNC;
5764357663
pPgOld = sqlite3PagerLookup(pPager, pgno);
57644
- assert( !pPgOld || pPgOld->nRef==1 );
57664
+ assert( !pPgOld || pPgOld->nRef==1 || CORRUPT_DB );
5764557665
if( pPgOld ){
57666
+ if( pPgOld->nRef>1 ){
57667
+ sqlite3PagerUnrefNotNull(pPgOld);
57668
+ return SQLITE_CORRUPT_BKPT;
57669
+ }
5764657670
pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
5764757671
if( pPager->tempFile ){
5764857672
/* Do not discard pages from an in-memory database since we might
5764957673
** need to rollback later. Just move the page out of the way. */
5765057674
sqlite3PcacheMove(pPgOld, pPager->dbSize+1);
@@ -64486,11 +64510,11 @@
6448664510
temp = 0;
6448764511
src = data = pPage->aData;
6448864512
hdr = pPage->hdrOffset;
6448964513
cellOffset = pPage->cellOffset;
6449064514
nCell = pPage->nCell;
64491
- assert( nCell==get2byte(&data[hdr+3]) );
64515
+ assert( nCell==get2byte(&data[hdr+3]) || CORRUPT_DB );
6449264516
iCellFirst = cellOffset + 2*nCell;
6449364517
usableSize = pPage->pBt->usableSize;
6449464518
6449564519
/* This block handles pages with two or fewer free blocks and nMaxFrag
6449664520
** or fewer fragmented bytes. In this case it is faster to move the
@@ -64638,11 +64662,11 @@
6463864662
}
6463964663
return &aData[pc + x];
6464064664
}
6464164665
iAddr = pc;
6464264666
pc = get2byte(&aData[pc]);
64643
- if( pc<iAddr+size ){
64667
+ if( pc<=iAddr+size ){
6464464668
if( pc ){
6464564669
/* The next slot in the chain is not past the end of the current slot */
6464664670
*pRc = SQLITE_CORRUPT_PAGE(pPg);
6464764671
}
6464864672
return 0;
@@ -68617,11 +68641,11 @@
6861768641
pCur->curFlags &= ~BTCF_ValidOvfl;
6861868642
if( rc ){
6861968643
sqlite3_free(pCellKey);
6862068644
goto moveto_finish;
6862168645
}
68622
- c = xRecordCompare(nCell, pCellKey, pIdxKey);
68646
+ c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
6862368647
sqlite3_free(pCellKey);
6862468648
}
6862568649
assert(
6862668650
(pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
6862768651
&& (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
@@ -70217,12 +70241,13 @@
7021770241
/* Add any overflow cells */
7021870242
for(i=0; i<pPg->nOverflow; i++){
7021970243
int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
7022070244
if( iCell>=0 && iCell<nNew ){
7022170245
pCellptr = &pPg->aCellIdx[iCell * 2];
70222
- assert( nCell>=iCell );
70223
- memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
70246
+ if( nCell>iCell ){
70247
+ memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
70248
+ }
7022470249
nCell++;
7022570250
if( pageInsertArray(
7022670251
pPg, pBegin, &pData, pCellptr,
7022770252
iCell+iNew, 1, pCArray
7022870253
) ) goto editpage_fail;
@@ -72333,10 +72358,13 @@
7233372358
BtShared *pBt = p->pBt;
7233472359
7233572360
assert( sqlite3BtreeHoldsMutex(p) );
7233672361
assert( p->inTrans==TRANS_WRITE );
7233772362
assert( iTable>=2 );
72363
+ if( iTable>btreePagecount(pBt) ){
72364
+ return SQLITE_CORRUPT_BKPT;
72365
+ }
7233872366
7233972367
rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
7234072368
if( rc ) return rc;
7234172369
rc = sqlite3BtreeClearTable(p, iTable, 0);
7234272370
if( rc ){
@@ -72681,14 +72709,14 @@
7268172709
*/
7268272710
static void checkList(
7268372711
IntegrityCk *pCheck, /* Integrity checking context */
7268472712
int isFreeList, /* True for a freelist. False for overflow page list */
7268572713
int iPage, /* Page number for first page in the list */
72686
- int N /* Expected number of pages in the list */
72714
+ u32 N /* Expected number of pages in the list */
7268772715
){
7268872716
int i;
72689
- int expected = N;
72717
+ u32 expected = N;
7269072718
int nErrAtStart = pCheck->nErr;
7269172719
while( iPage!=0 && pCheck->mxErr ){
7269272720
DbPage *pOvflPage;
7269372721
unsigned char *pOvflData;
7269472722
if( checkRef(pCheck, iPage) ) break;
@@ -72943,11 +72971,11 @@
7294372971
keyCanBeEqual = 0; /* Only the first key on the page may ==maxKey */
7294472972
}
7294572973
7294672974
/* Check the content overflow list */
7294772975
if( info.nPayload>info.nLocal ){
72948
- int nPage; /* Number of pages on the overflow chain */
72976
+ u32 nPage; /* Number of pages on the overflow chain */
7294972977
Pgno pgnoOvfl; /* First page of the overflow chain */
7295072978
assert( pc + info.nSize - 4 <= usableSize );
7295172979
nPage = (info.nPayload - info.nLocal + usableSize - 5)/(usableSize - 4);
7295272980
pgnoOvfl = get4byte(&pCell[info.nSize - 4]);
7295372981
#ifndef SQLITE_OMIT_AUTOVACUUM
@@ -76831,10 +76859,11 @@
7683176859
7683276860
while( (pOp = opIterNext(&sIter))!=0 ){
7683376861
int opcode = pOp->opcode;
7683476862
if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
7683576863
|| opcode==OP_VDestroy
76864
+ || (opcode==OP_Function0 && pOp->p4.pFunc->funcFlags&SQLITE_FUNC_INTERNAL)
7683676865
|| ((opcode==OP_Halt || opcode==OP_HaltIfNull)
7683776866
&& ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
7683876867
){
7683976868
hasAbort = 1;
7684076869
break;
@@ -82315,13 +82344,16 @@
8231582344
n = sqlite3_column_count(pStmt);
8231682345
if( N<n && N>=0 ){
8231782346
N += useType*n;
8231882347
sqlite3_mutex_enter(db->mutex);
8231982348
assert( db->mallocFailed==0 );
82349
+#ifndef SQLITE_OMIT_UTF16
8232082350
if( useUtf16 ){
8232182351
ret = sqlite3_value_text16((sqlite3_value*)&p->aColName[N]);
82322
- }else{
82352
+ }else
82353
+#endif
82354
+ {
8232382355
ret = sqlite3_value_text((sqlite3_value*)&p->aColName[N]);
8232482356
}
8232582357
/* A malloc may have failed inside of the _text() call. If this
8232682358
** is the case, clear the mallocFailed flag and return NULL.
8232782359
*/
@@ -82775,10 +82807,18 @@
8277582807
** database.
8277682808
*/
8277782809
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt){
8277882810
return pStmt ? ((Vdbe*)pStmt)->readOnly : 1;
8277982811
}
82812
+
82813
+/*
82814
+** Return 1 if the statement is an EXPLAIN and return 2 if the
82815
+** statement is an EXPLAIN QUERY PLAN
82816
+*/
82817
+SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt){
82818
+ return pStmt ? ((Vdbe*)pStmt)->explain : 0;
82819
+}
8278082820
8278182821
/*
8278282822
** Return true if the prepared statement is in need of being reset.
8278382823
*/
8278482824
SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){
@@ -102329,19 +102369,19 @@
102329102369
pVTab = 0;
102330102370
}
102331102371
}
102332102372
#endif
102333102373
102334
- /* Begin a transaction for database iDb.
102335
- ** Then modify the schema cookie (since the ALTER TABLE modifies the
102336
- ** schema). Open a statement transaction if the table is a virtual
102337
- ** table.
102338
- */
102374
+ /* Begin a transaction for database iDb. Then modify the schema cookie
102375
+ ** (since the ALTER TABLE modifies the schema). Call sqlite3MayAbort(),
102376
+ ** as the scalar functions (e.g. sqlite_rename_table()) invoked by the
102377
+ ** nested SQL may raise an exception. */
102339102378
v = sqlite3GetVdbe(pParse);
102340102379
if( v==0 ){
102341102380
goto exit_rename_table;
102342102381
}
102382
+ sqlite3MayAbort(pParse);
102343102383
102344102384
/* figure out how many UTF-8 characters are in zName */
102345102385
zTabName = pTab->zName;
102346102386
nTabName = sqlite3Utf8CharLen(zTabName, -1);
102347102387
@@ -102406,11 +102446,10 @@
102406102446
#ifndef SQLITE_OMIT_VIRTUALTABLE
102407102447
if( pVTab ){
102408102448
int i = ++pParse->nMem;
102409102449
sqlite3VdbeLoadString(v, i, zName);
102410102450
sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
102411
- sqlite3MayAbort(pParse);
102412102451
}
102413102452
#endif
102414102453
102415102454
renameReloadSchema(pParse, iDb);
102416102455
renameTestSchema(pParse, zDb, iDb==1);
@@ -102727,10 +102766,11 @@
102727102766
102728102767
/* Do the rename operation using a recursive UPDATE statement that
102729102768
** uses the sqlite_rename_column() SQL function to compute the new
102730102769
** CREATE statement text for the sqlite_master table.
102731102770
*/
102771
+ sqlite3MayAbort(pParse);
102732102772
zNew = sqlite3NameFromToken(db, pNew);
102733102773
if( !zNew ) goto exit_rename_column;
102734102774
assert( pNew->n>0 );
102735102775
bQuote = sqlite3Isquote(pNew->z[0]);
102736102776
sqlite3NestedParse(pParse,
@@ -105981,11 +106021,13 @@
105981106021
*/
105982106022
if( rc==SQLITE_OK ){
105983106023
sqlite3BtreeEnterAll(db);
105984106024
db->init.iDb = 0;
105985106025
db->mDbFlags &= ~(DBFLAG_SchemaKnownOk);
105986
- rc = sqlite3Init(db, &zErrDyn);
106026
+ if( !REOPEN_AS_MEMDB(db) ){
106027
+ rc = sqlite3Init(db, &zErrDyn);
106028
+ }
105987106029
sqlite3BtreeLeaveAll(db);
105988106030
assert( zErrDyn==0 || rc!=SQLITE_OK );
105989106031
}
105990106032
#ifdef SQLITE_USER_AUTHENTICATION
105991106033
if( rc==SQLITE_OK ){
@@ -114605,10 +114647,14 @@
114605114647
static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
114606114648
FuncDef *pDef;
114607114649
pDef = sqlite3FindFunction(db, zName, 2, SQLITE_UTF8, 0);
114608114650
if( ALWAYS(pDef) ){
114609114651
pDef->funcFlags |= flagVal;
114652
+ }
114653
+ pDef = sqlite3FindFunction(db, zName, 3, SQLITE_UTF8, 0);
114654
+ if( pDef ){
114655
+ pDef->funcFlags |= flagVal;
114610114656
}
114611114657
}
114612114658
114613114659
/*
114614114660
** Register the built-in LIKE and GLOB functions. The caseSensitive
@@ -129717,11 +129763,11 @@
129717129763
** Update the accumulator memory cells for an aggregate based on
129718129764
** the current cursor position.
129719129765
**
129720129766
** If regAcc is non-zero and there are no min() or max() aggregates
129721129767
** in pAggInfo, then only populate the pAggInfo->nAccumulator accumulator
129722
-** registers i register regAcc contains 0. The caller will take care
129768
+** registers if register regAcc contains 0. The caller will take care
129723129769
** of setting and clearing regAcc.
129724129770
*/
129725129771
static void updateAccumulator(Parse *pParse, int regAcc, AggInfo *pAggInfo){
129726129772
Vdbe *v = pParse->pVdbe;
129727129773
int i;
@@ -137079,10 +137125,38 @@
137079137125
sqlite3WalkExpr(&w, pWInfo->pWhere);
137080137126
sqlite3WalkExprList(&w, pWInfo->pOrderBy);
137081137127
sqlite3WalkExprList(&w, pWInfo->pResultSet);
137082137128
}
137083137129
}
137130
+
137131
+/*
137132
+** The pTruth expression is always true because it is the WHERE clause
137133
+** a partial index that is driving a query loop. Look through all of the
137134
+** WHERE clause terms on the query, and if any of those terms must be
137135
+** true because pTruth is true, then mark those WHERE clause terms as
137136
+** coded.
137137
+*/
137138
+static void whereApplyPartialIndexConstraints(
137139
+ Expr *pTruth,
137140
+ int iTabCur,
137141
+ WhereClause *pWC
137142
+){
137143
+ int i;
137144
+ WhereTerm *pTerm;
137145
+ while( pTruth->op==TK_AND ){
137146
+ whereApplyPartialIndexConstraints(pTruth->pLeft, iTabCur, pWC);
137147
+ pTruth = pTruth->pRight;
137148
+ }
137149
+ for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
137150
+ Expr *pExpr;
137151
+ if( pTerm->wtFlags & TERM_CODED ) continue;
137152
+ pExpr = pTerm->pExpr;
137153
+ if( sqlite3ExprCompare(0, pExpr, pTruth, iTabCur)==0 ){
137154
+ pTerm->wtFlags |= TERM_CODED;
137155
+ }
137156
+ }
137157
+}
137084137158
137085137159
/*
137086137160
** Generate code for the start of the iLevel-th loop in the WHERE clause
137087137161
** implementation described by pWInfo.
137088137162
*/
@@ -137688,10 +137762,18 @@
137688137762
** https://sqlite.org/src/info/4e8e4857d32d401f
137689137763
*/
137690137764
if( pLevel->iLeftJoin==0 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 ){
137691137765
whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
137692137766
}
137767
+
137768
+ /* If a partial index is driving the loop, try to eliminate WHERE clause
137769
+ ** terms from the query that must be true due to the WHERE clause of
137770
+ ** the partial index
137771
+ */
137772
+ if( pIdx->pPartIdxWhere ){
137773
+ whereApplyPartialIndexConstraints(pIdx->pPartIdxWhere, iCur, pWC);
137774
+ }
137693137775
137694137776
/* Record the instruction used to terminate the loop. */
137695137777
if( pLoop->wsFlags & WHERE_ONEROW ){
137696137778
pLevel->op = OP_Noop;
137697137779
}else if( bRev ){
@@ -139685,10 +139767,16 @@
139685139767
if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1;
139686139768
mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
139687139769
}else if( p->x.pList ){
139688139770
mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
139689139771
}
139772
+#ifndef SQLITE_OMIT_WINDOWFUNC
139773
+ if( p->op==TK_FUNCTION && p->y.pWin ){
139774
+ mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition);
139775
+ mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy);
139776
+ }
139777
+#endif
139690139778
return mask;
139691139779
}
139692139780
SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
139693139781
return p ? sqlite3WhereExprUsageNN(pMaskSet,p) : 0;
139694139782
}
@@ -153089,14 +153177,14 @@
153089153177
int n = 0; /* Length of the next token token */
153090153178
int tokenType; /* type of the next token */
153091153179
int lastTokenParsed = -1; /* type of the previous token */
153092153180
sqlite3 *db = pParse->db; /* The database connection */
153093153181
int mxSqlLen; /* Max length of an SQL string */
153094
- VVA_ONLY( u8 startedWithOom = db->mallocFailed );
153095153182
#ifdef sqlite3Parser_ENGINEALWAYSONSTACK
153096153183
yyParser sEngine; /* Space to hold the Lemon-generated Parser object */
153097153184
#endif
153185
+ VVA_ONLY( u8 startedWithOom = db->mallocFailed );
153098153186
153099153187
assert( zSql!=0 );
153100153188
mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
153101153189
if( db->nVdbeActive==0 ){
153102153190
db->u1.isInterrupted = 0;
@@ -161295,11 +161383,11 @@
161295161383
}
161296161384
isFirstTerm = 0;
161297161385
zCsr += fts3GetVarint32(zCsr, &nSuffix);
161298161386
161299161387
assert( nPrefix>=0 && nSuffix>=0 );
161300
- if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr ){
161388
+ if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr || nSuffix==0 ){
161301161389
rc = FTS_CORRUPT_VTAB;
161302161390
goto finish_scan;
161303161391
}
161304161392
if( (i64)nPrefix+nSuffix>nAlloc ){
161305161393
char *zNew;
@@ -168435,11 +168523,13 @@
168435168523
sqlite3_result_error(context, zErr, -1);
168436168524
sqlite3_free(zErr);
168437168525
return;
168438168526
}
168439168527
}
168440
- sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT);
168528
+ if( fts3TokenizerEnabled(context) ){
168529
+ sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT);
168530
+ }
168441168531
}
168442168532
168443168533
SQLITE_PRIVATE int sqlite3Fts3IsIdChar(char c){
168444168534
static const char isFtsIdChar[] = {
168445168535
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
@@ -175688,11 +175778,11 @@
175688175778
SnippetPhrase *pPhrase = &pIter->aPhrase[i];
175689175779
if( pPhrase->pTail ){
175690175780
char *pCsr = pPhrase->pTail;
175691175781
int iCsr = pPhrase->iTail;
175692175782
175693
- while( iCsr<(iStart+pIter->nSnippet) ){
175783
+ while( iCsr<(iStart+pIter->nSnippet) && iCsr>=iStart ){
175694175784
int j;
175695175785
u64 mPhrase = (u64)1 << i;
175696175786
u64 mPos = (u64)1 << (iCsr - iStart);
175697175787
assert( iCsr>=iStart && (iCsr - iStart)<=64 );
175698175788
assert( i>=0 && i<=64 );
@@ -217166,11 +217256,11 @@
217166217256
int nArg, /* Number of args */
217167217257
sqlite3_value **apUnused /* Function arguments */
217168217258
){
217169217259
assert( nArg==0 );
217170217260
UNUSED_PARAM2(nArg, apUnused);
217171
- sqlite3_result_text(pCtx, "fts5: 2019-02-25 14:52:43 9da4fb59b28686630d63a79988b458726332cf06cc0e6e84d7c0a7600f5fcab0", -1, SQLITE_TRANSIENT);
217261
+ sqlite3_result_text(pCtx, "fts5: 2019-03-15 16:17:32 0f2129f59f7df929106e2af876c2976dea6528c1dc1850d64cddb256f20e121a", -1, SQLITE_TRANSIENT);
217172217262
}
217173217263
217174217264
/*
217175217265
** Return true if zName is the extension on one of the shadow tables used
217176217266
** by this module.
@@ -221930,12 +222020,12 @@
221930222020
}
221931222021
#endif /* SQLITE_CORE */
221932222022
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
221933222023
221934222024
/************** End of stmt.c ************************************************/
221935
-#if __LINE__!=221935
222025
+#if __LINE__!=222025
221936222026
#undef SQLITE_SOURCE_ID
221937
-#define SQLITE_SOURCE_ID "2019-02-25 14:52:43 9da4fb59b28686630d63a79988b458726332cf06cc0e6e84d7c0a7600f5falt2"
222027
+#define SQLITE_SOURCE_ID "2019-03-17 23:59:02 cc5ab96715ebb1089b4e9aa647badd2510aaa056f26004718f921f4ac07ealt2"
221938222028
#endif
221939222029
/* Return the source-id for this library */
221940222030
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
221941222031
/************************** End of sqlite3.c ******************************/
221942222032
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
1162 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1163 ** [sqlite_version()] and [sqlite_source_id()].
1164 */
1165 #define SQLITE_VERSION "3.28.0"
1166 #define SQLITE_VERSION_NUMBER 3028000
1167 #define SQLITE_SOURCE_ID "2019-02-25 14:52:43 9da4fb59b28686630d63a79988b458726332cf06cc0e6e84d7c0a7600f5fcab0"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -3123,12 +3123,12 @@
3123 ** following this call. The second parameter may be a NULL pointer, in
3124 ** which case the trigger setting is not reported back. </dd>
3125 **
3126 ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
3127 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
3128 ** <dd> ^This option is used to enable or disable the two-argument
3129 ** version of the [fts3_tokenizer()] function which is part of the
3130 ** [FTS3] full-text search engine extension.
3131 ** There should be two additional arguments.
3132 ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
3133 ** positive to enable fts3_tokenizer() or negative to leave the setting
3134 ** unchanged.
@@ -4931,10 +4931,22 @@
4931 ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
4932 ** sqlite3_stmt_readonly() returns false for those commands.
4933 */
4934 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
4935
 
 
 
 
 
 
 
 
 
 
 
 
4936 /*
4937 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
4938 ** METHOD: sqlite3_stmt
4939 **
4940 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
@@ -5070,11 +5082,13 @@
5070 ** with embedded NULs is undefined.
5071 **
5072 ** ^The fifth argument to the BLOB and string binding interfaces
5073 ** is a destructor used to dispose of the BLOB or
5074 ** string after SQLite has finished with it. ^The destructor is called
5075 ** to dispose of the BLOB or string even if the call to bind API fails.
 
 
5076 ** ^If the fifth argument is
5077 ** the special value [SQLITE_STATIC], then SQLite assumes that the
5078 ** information is in static, unmanaged space and does not need to be freed.
5079 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
5080 ** SQLite makes its own private copy of the data immediately, before
@@ -6828,11 +6842,11 @@
6828 **
6829 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
6830 ** associated with database N of connection D. ^The main database file
6831 ** has the name "main". If there is no attached database N on the database
6832 ** connection D, or if database N is a temporary or in-memory database, then
6833 ** a NULL pointer is returned.
6834 **
6835 ** ^The filename returned by this function is the output of the
6836 ** xFullPathname method of the [VFS]. ^In other words, the filename
6837 ** will be an absolute pathname, even if the filename used
6838 ** to open the database originally was a URI or relative pathname.
@@ -40220,13 +40234,10 @@
40220 static sqlite3_vfs aVfs[] = {
40221 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
40222 UNIXVFS("unix", autolockIoFinder ),
40223 #elif OS_VXWORKS
40224 UNIXVFS("unix", vxworksIoFinder ),
40225 #elif __Fuchsia__
40226 /* We are told that Fuchsia only supports dot-file locking */
40227 UNIXVFS("unix", dotlockIoFinder ),
40228 #else
40229 UNIXVFS("unix", posixIoFinder ),
40230 #endif
40231 UNIXVFS("unix-none", nolockIoFinder ),
40232 UNIXVFS("unix-dotfile", dotlockIoFinder ),
@@ -51308,10 +51319,13 @@
51308 ** * the desired page is not currently in the wal file.
51309 */
51310 SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno){
51311 if( pPager->fd->pMethods==0 ) return 0;
51312 if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0;
 
 
 
51313 #ifndef SQLITE_OMIT_WAL
51314 if( pPager->pWal ){
51315 u32 iRead = 0;
51316 int rc;
51317 rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iRead);
@@ -54257,12 +54271,18 @@
54257
54258 if( pPager->eState>PAGER_OPEN && isOpen(pPager->fd) ){
54259 rc = sqlite3OsFileSize(pPager->fd, &nByte);
54260 }
54261 if( rc==SQLITE_OK ){
54262 pNew = (char *)sqlite3PageMalloc(pageSize);
54263 if( !pNew ) rc = SQLITE_NOMEM_BKPT;
 
 
 
 
 
 
54264 }
54265
54266 if( rc==SQLITE_OK ){
54267 pager_reset(pPager);
54268 rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
@@ -57639,12 +57659,16 @@
57639 ** page pgno before the 'move' operation, it needs to be retained
57640 ** for the page moved there.
57641 */
57642 pPg->flags &= ~PGHDR_NEED_SYNC;
57643 pPgOld = sqlite3PagerLookup(pPager, pgno);
57644 assert( !pPgOld || pPgOld->nRef==1 );
57645 if( pPgOld ){
 
 
 
 
57646 pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
57647 if( pPager->tempFile ){
57648 /* Do not discard pages from an in-memory database since we might
57649 ** need to rollback later. Just move the page out of the way. */
57650 sqlite3PcacheMove(pPgOld, pPager->dbSize+1);
@@ -64486,11 +64510,11 @@
64486 temp = 0;
64487 src = data = pPage->aData;
64488 hdr = pPage->hdrOffset;
64489 cellOffset = pPage->cellOffset;
64490 nCell = pPage->nCell;
64491 assert( nCell==get2byte(&data[hdr+3]) );
64492 iCellFirst = cellOffset + 2*nCell;
64493 usableSize = pPage->pBt->usableSize;
64494
64495 /* This block handles pages with two or fewer free blocks and nMaxFrag
64496 ** or fewer fragmented bytes. In this case it is faster to move the
@@ -64638,11 +64662,11 @@
64638 }
64639 return &aData[pc + x];
64640 }
64641 iAddr = pc;
64642 pc = get2byte(&aData[pc]);
64643 if( pc<iAddr+size ){
64644 if( pc ){
64645 /* The next slot in the chain is not past the end of the current slot */
64646 *pRc = SQLITE_CORRUPT_PAGE(pPg);
64647 }
64648 return 0;
@@ -68617,11 +68641,11 @@
68617 pCur->curFlags &= ~BTCF_ValidOvfl;
68618 if( rc ){
68619 sqlite3_free(pCellKey);
68620 goto moveto_finish;
68621 }
68622 c = xRecordCompare(nCell, pCellKey, pIdxKey);
68623 sqlite3_free(pCellKey);
68624 }
68625 assert(
68626 (pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
68627 && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
@@ -70217,12 +70241,13 @@
70217 /* Add any overflow cells */
70218 for(i=0; i<pPg->nOverflow; i++){
70219 int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
70220 if( iCell>=0 && iCell<nNew ){
70221 pCellptr = &pPg->aCellIdx[iCell * 2];
70222 assert( nCell>=iCell );
70223 memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
 
70224 nCell++;
70225 if( pageInsertArray(
70226 pPg, pBegin, &pData, pCellptr,
70227 iCell+iNew, 1, pCArray
70228 ) ) goto editpage_fail;
@@ -72333,10 +72358,13 @@
72333 BtShared *pBt = p->pBt;
72334
72335 assert( sqlite3BtreeHoldsMutex(p) );
72336 assert( p->inTrans==TRANS_WRITE );
72337 assert( iTable>=2 );
 
 
 
72338
72339 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
72340 if( rc ) return rc;
72341 rc = sqlite3BtreeClearTable(p, iTable, 0);
72342 if( rc ){
@@ -72681,14 +72709,14 @@
72681 */
72682 static void checkList(
72683 IntegrityCk *pCheck, /* Integrity checking context */
72684 int isFreeList, /* True for a freelist. False for overflow page list */
72685 int iPage, /* Page number for first page in the list */
72686 int N /* Expected number of pages in the list */
72687 ){
72688 int i;
72689 int expected = N;
72690 int nErrAtStart = pCheck->nErr;
72691 while( iPage!=0 && pCheck->mxErr ){
72692 DbPage *pOvflPage;
72693 unsigned char *pOvflData;
72694 if( checkRef(pCheck, iPage) ) break;
@@ -72943,11 +72971,11 @@
72943 keyCanBeEqual = 0; /* Only the first key on the page may ==maxKey */
72944 }
72945
72946 /* Check the content overflow list */
72947 if( info.nPayload>info.nLocal ){
72948 int nPage; /* Number of pages on the overflow chain */
72949 Pgno pgnoOvfl; /* First page of the overflow chain */
72950 assert( pc + info.nSize - 4 <= usableSize );
72951 nPage = (info.nPayload - info.nLocal + usableSize - 5)/(usableSize - 4);
72952 pgnoOvfl = get4byte(&pCell[info.nSize - 4]);
72953 #ifndef SQLITE_OMIT_AUTOVACUUM
@@ -76831,10 +76859,11 @@
76831
76832 while( (pOp = opIterNext(&sIter))!=0 ){
76833 int opcode = pOp->opcode;
76834 if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
76835 || opcode==OP_VDestroy
 
76836 || ((opcode==OP_Halt || opcode==OP_HaltIfNull)
76837 && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
76838 ){
76839 hasAbort = 1;
76840 break;
@@ -82315,13 +82344,16 @@
82315 n = sqlite3_column_count(pStmt);
82316 if( N<n && N>=0 ){
82317 N += useType*n;
82318 sqlite3_mutex_enter(db->mutex);
82319 assert( db->mallocFailed==0 );
 
82320 if( useUtf16 ){
82321 ret = sqlite3_value_text16((sqlite3_value*)&p->aColName[N]);
82322 }else{
 
 
82323 ret = sqlite3_value_text((sqlite3_value*)&p->aColName[N]);
82324 }
82325 /* A malloc may have failed inside of the _text() call. If this
82326 ** is the case, clear the mallocFailed flag and return NULL.
82327 */
@@ -82775,10 +82807,18 @@
82775 ** database.
82776 */
82777 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt){
82778 return pStmt ? ((Vdbe*)pStmt)->readOnly : 1;
82779 }
 
 
 
 
 
 
 
 
82780
82781 /*
82782 ** Return true if the prepared statement is in need of being reset.
82783 */
82784 SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){
@@ -102329,19 +102369,19 @@
102329 pVTab = 0;
102330 }
102331 }
102332 #endif
102333
102334 /* Begin a transaction for database iDb.
102335 ** Then modify the schema cookie (since the ALTER TABLE modifies the
102336 ** schema). Open a statement transaction if the table is a virtual
102337 ** table.
102338 */
102339 v = sqlite3GetVdbe(pParse);
102340 if( v==0 ){
102341 goto exit_rename_table;
102342 }
 
102343
102344 /* figure out how many UTF-8 characters are in zName */
102345 zTabName = pTab->zName;
102346 nTabName = sqlite3Utf8CharLen(zTabName, -1);
102347
@@ -102406,11 +102446,10 @@
102406 #ifndef SQLITE_OMIT_VIRTUALTABLE
102407 if( pVTab ){
102408 int i = ++pParse->nMem;
102409 sqlite3VdbeLoadString(v, i, zName);
102410 sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
102411 sqlite3MayAbort(pParse);
102412 }
102413 #endif
102414
102415 renameReloadSchema(pParse, iDb);
102416 renameTestSchema(pParse, zDb, iDb==1);
@@ -102727,10 +102766,11 @@
102727
102728 /* Do the rename operation using a recursive UPDATE statement that
102729 ** uses the sqlite_rename_column() SQL function to compute the new
102730 ** CREATE statement text for the sqlite_master table.
102731 */
 
102732 zNew = sqlite3NameFromToken(db, pNew);
102733 if( !zNew ) goto exit_rename_column;
102734 assert( pNew->n>0 );
102735 bQuote = sqlite3Isquote(pNew->z[0]);
102736 sqlite3NestedParse(pParse,
@@ -105981,11 +106021,13 @@
105981 */
105982 if( rc==SQLITE_OK ){
105983 sqlite3BtreeEnterAll(db);
105984 db->init.iDb = 0;
105985 db->mDbFlags &= ~(DBFLAG_SchemaKnownOk);
105986 rc = sqlite3Init(db, &zErrDyn);
 
 
105987 sqlite3BtreeLeaveAll(db);
105988 assert( zErrDyn==0 || rc!=SQLITE_OK );
105989 }
105990 #ifdef SQLITE_USER_AUTHENTICATION
105991 if( rc==SQLITE_OK ){
@@ -114605,10 +114647,14 @@
114605 static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
114606 FuncDef *pDef;
114607 pDef = sqlite3FindFunction(db, zName, 2, SQLITE_UTF8, 0);
114608 if( ALWAYS(pDef) ){
114609 pDef->funcFlags |= flagVal;
 
 
 
 
114610 }
114611 }
114612
114613 /*
114614 ** Register the built-in LIKE and GLOB functions. The caseSensitive
@@ -129717,11 +129763,11 @@
129717 ** Update the accumulator memory cells for an aggregate based on
129718 ** the current cursor position.
129719 **
129720 ** If regAcc is non-zero and there are no min() or max() aggregates
129721 ** in pAggInfo, then only populate the pAggInfo->nAccumulator accumulator
129722 ** registers i register regAcc contains 0. The caller will take care
129723 ** of setting and clearing regAcc.
129724 */
129725 static void updateAccumulator(Parse *pParse, int regAcc, AggInfo *pAggInfo){
129726 Vdbe *v = pParse->pVdbe;
129727 int i;
@@ -137079,10 +137125,38 @@
137079 sqlite3WalkExpr(&w, pWInfo->pWhere);
137080 sqlite3WalkExprList(&w, pWInfo->pOrderBy);
137081 sqlite3WalkExprList(&w, pWInfo->pResultSet);
137082 }
137083 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137084
137085 /*
137086 ** Generate code for the start of the iLevel-th loop in the WHERE clause
137087 ** implementation described by pWInfo.
137088 */
@@ -137688,10 +137762,18 @@
137688 ** https://sqlite.org/src/info/4e8e4857d32d401f
137689 */
137690 if( pLevel->iLeftJoin==0 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 ){
137691 whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
137692 }
 
 
 
 
 
 
 
 
137693
137694 /* Record the instruction used to terminate the loop. */
137695 if( pLoop->wsFlags & WHERE_ONEROW ){
137696 pLevel->op = OP_Noop;
137697 }else if( bRev ){
@@ -139685,10 +139767,16 @@
139685 if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1;
139686 mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
139687 }else if( p->x.pList ){
139688 mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
139689 }
 
 
 
 
 
 
139690 return mask;
139691 }
139692 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
139693 return p ? sqlite3WhereExprUsageNN(pMaskSet,p) : 0;
139694 }
@@ -153089,14 +153177,14 @@
153089 int n = 0; /* Length of the next token token */
153090 int tokenType; /* type of the next token */
153091 int lastTokenParsed = -1; /* type of the previous token */
153092 sqlite3 *db = pParse->db; /* The database connection */
153093 int mxSqlLen; /* Max length of an SQL string */
153094 VVA_ONLY( u8 startedWithOom = db->mallocFailed );
153095 #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
153096 yyParser sEngine; /* Space to hold the Lemon-generated Parser object */
153097 #endif
 
153098
153099 assert( zSql!=0 );
153100 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
153101 if( db->nVdbeActive==0 ){
153102 db->u1.isInterrupted = 0;
@@ -161295,11 +161383,11 @@
161295 }
161296 isFirstTerm = 0;
161297 zCsr += fts3GetVarint32(zCsr, &nSuffix);
161298
161299 assert( nPrefix>=0 && nSuffix>=0 );
161300 if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr ){
161301 rc = FTS_CORRUPT_VTAB;
161302 goto finish_scan;
161303 }
161304 if( (i64)nPrefix+nSuffix>nAlloc ){
161305 char *zNew;
@@ -168435,11 +168523,13 @@
168435 sqlite3_result_error(context, zErr, -1);
168436 sqlite3_free(zErr);
168437 return;
168438 }
168439 }
168440 sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT);
 
 
168441 }
168442
168443 SQLITE_PRIVATE int sqlite3Fts3IsIdChar(char c){
168444 static const char isFtsIdChar[] = {
168445 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
@@ -175688,11 +175778,11 @@
175688 SnippetPhrase *pPhrase = &pIter->aPhrase[i];
175689 if( pPhrase->pTail ){
175690 char *pCsr = pPhrase->pTail;
175691 int iCsr = pPhrase->iTail;
175692
175693 while( iCsr<(iStart+pIter->nSnippet) ){
175694 int j;
175695 u64 mPhrase = (u64)1 << i;
175696 u64 mPos = (u64)1 << (iCsr - iStart);
175697 assert( iCsr>=iStart && (iCsr - iStart)<=64 );
175698 assert( i>=0 && i<=64 );
@@ -217166,11 +217256,11 @@
217166 int nArg, /* Number of args */
217167 sqlite3_value **apUnused /* Function arguments */
217168 ){
217169 assert( nArg==0 );
217170 UNUSED_PARAM2(nArg, apUnused);
217171 sqlite3_result_text(pCtx, "fts5: 2019-02-25 14:52:43 9da4fb59b28686630d63a79988b458726332cf06cc0e6e84d7c0a7600f5fcab0", -1, SQLITE_TRANSIENT);
217172 }
217173
217174 /*
217175 ** Return true if zName is the extension on one of the shadow tables used
217176 ** by this module.
@@ -221930,12 +222020,12 @@
221930 }
221931 #endif /* SQLITE_CORE */
221932 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
221933
221934 /************** End of stmt.c ************************************************/
221935 #if __LINE__!=221935
221936 #undef SQLITE_SOURCE_ID
221937 #define SQLITE_SOURCE_ID "2019-02-25 14:52:43 9da4fb59b28686630d63a79988b458726332cf06cc0e6e84d7c0a7600f5falt2"
221938 #endif
221939 /* Return the source-id for this library */
221940 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
221941 /************************** End of sqlite3.c ******************************/
221942
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
1162 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1163 ** [sqlite_version()] and [sqlite_source_id()].
1164 */
1165 #define SQLITE_VERSION "3.28.0"
1166 #define SQLITE_VERSION_NUMBER 3028000
1167 #define SQLITE_SOURCE_ID "2019-03-17 23:59:02 cc5ab96715ebb1089b4e9aa647badd2510aaa056f26004718f921f4ac07e2f93"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -3123,12 +3123,12 @@
3123 ** following this call. The second parameter may be a NULL pointer, in
3124 ** which case the trigger setting is not reported back. </dd>
3125 **
3126 ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
3127 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
3128 ** <dd> ^This option is used to enable or disable the
3129 ** [fts3_tokenizer()] function which is part of the
3130 ** [FTS3] full-text search engine extension.
3131 ** There should be two additional arguments.
3132 ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
3133 ** positive to enable fts3_tokenizer() or negative to leave the setting
3134 ** unchanged.
@@ -4931,10 +4931,22 @@
4931 ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
4932 ** sqlite3_stmt_readonly() returns false for those commands.
4933 */
4934 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
4935
4936 /*
4937 ** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
4938 ** METHOD: sqlite3_stmt
4939 **
4940 ** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the
4941 ** prepared statement S is an EXPLAIN statement, or 2 if the
4942 ** statement S is an EXPLAIN QUERY PLAN.
4943 ** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
4944 ** an ordinary statement or a NULL pointer.
4945 */
4946 SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);
4947
4948 /*
4949 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
4950 ** METHOD: sqlite3_stmt
4951 **
4952 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
@@ -5070,11 +5082,13 @@
5082 ** with embedded NULs is undefined.
5083 **
5084 ** ^The fifth argument to the BLOB and string binding interfaces
5085 ** is a destructor used to dispose of the BLOB or
5086 ** string after SQLite has finished with it. ^The destructor is called
5087 ** to dispose of the BLOB or string even if the call to the bind API fails,
5088 ** except the destructor is not called if the third parameter is a NULL
5089 ** pointer or the fourth parameter is negative.
5090 ** ^If the fifth argument is
5091 ** the special value [SQLITE_STATIC], then SQLite assumes that the
5092 ** information is in static, unmanaged space and does not need to be freed.
5093 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
5094 ** SQLite makes its own private copy of the data immediately, before
@@ -6828,11 +6842,11 @@
6842 **
6843 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
6844 ** associated with database N of connection D. ^The main database file
6845 ** has the name "main". If there is no attached database N on the database
6846 ** connection D, or if database N is a temporary or in-memory database, then
6847 ** this function will return either a NULL pointer or an empty string.
6848 **
6849 ** ^The filename returned by this function is the output of the
6850 ** xFullPathname method of the [VFS]. ^In other words, the filename
6851 ** will be an absolute pathname, even if the filename used
6852 ** to open the database originally was a URI or relative pathname.
@@ -40220,13 +40234,10 @@
40234 static sqlite3_vfs aVfs[] = {
40235 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
40236 UNIXVFS("unix", autolockIoFinder ),
40237 #elif OS_VXWORKS
40238 UNIXVFS("unix", vxworksIoFinder ),
 
 
 
40239 #else
40240 UNIXVFS("unix", posixIoFinder ),
40241 #endif
40242 UNIXVFS("unix-none", nolockIoFinder ),
40243 UNIXVFS("unix-dotfile", dotlockIoFinder ),
@@ -51308,10 +51319,13 @@
51319 ** * the desired page is not currently in the wal file.
51320 */
51321 SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno){
51322 if( pPager->fd->pMethods==0 ) return 0;
51323 if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0;
51324 #ifdef SQLITE_HAS_CODEC
51325 if( pPager->xCodec!=0 ) return 0;
51326 #endif
51327 #ifndef SQLITE_OMIT_WAL
51328 if( pPager->pWal ){
51329 u32 iRead = 0;
51330 int rc;
51331 rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iRead);
@@ -54257,12 +54271,18 @@
54271
54272 if( pPager->eState>PAGER_OPEN && isOpen(pPager->fd) ){
54273 rc = sqlite3OsFileSize(pPager->fd, &nByte);
54274 }
54275 if( rc==SQLITE_OK ){
54276 /* 8 bytes of zeroed overrun space is sufficient so that the b-tree
54277 * cell header parser will never run off the end of the allocation */
54278 pNew = (char *)sqlite3PageMalloc(pageSize+8);
54279 if( !pNew ){
54280 rc = SQLITE_NOMEM_BKPT;
54281 }else{
54282 memset(pNew+pageSize, 0, 8);
54283 }
54284 }
54285
54286 if( rc==SQLITE_OK ){
54287 pager_reset(pPager);
54288 rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
@@ -57639,12 +57659,16 @@
57659 ** page pgno before the 'move' operation, it needs to be retained
57660 ** for the page moved there.
57661 */
57662 pPg->flags &= ~PGHDR_NEED_SYNC;
57663 pPgOld = sqlite3PagerLookup(pPager, pgno);
57664 assert( !pPgOld || pPgOld->nRef==1 || CORRUPT_DB );
57665 if( pPgOld ){
57666 if( pPgOld->nRef>1 ){
57667 sqlite3PagerUnrefNotNull(pPgOld);
57668 return SQLITE_CORRUPT_BKPT;
57669 }
57670 pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
57671 if( pPager->tempFile ){
57672 /* Do not discard pages from an in-memory database since we might
57673 ** need to rollback later. Just move the page out of the way. */
57674 sqlite3PcacheMove(pPgOld, pPager->dbSize+1);
@@ -64486,11 +64510,11 @@
64510 temp = 0;
64511 src = data = pPage->aData;
64512 hdr = pPage->hdrOffset;
64513 cellOffset = pPage->cellOffset;
64514 nCell = pPage->nCell;
64515 assert( nCell==get2byte(&data[hdr+3]) || CORRUPT_DB );
64516 iCellFirst = cellOffset + 2*nCell;
64517 usableSize = pPage->pBt->usableSize;
64518
64519 /* This block handles pages with two or fewer free blocks and nMaxFrag
64520 ** or fewer fragmented bytes. In this case it is faster to move the
@@ -64638,11 +64662,11 @@
64662 }
64663 return &aData[pc + x];
64664 }
64665 iAddr = pc;
64666 pc = get2byte(&aData[pc]);
64667 if( pc<=iAddr+size ){
64668 if( pc ){
64669 /* The next slot in the chain is not past the end of the current slot */
64670 *pRc = SQLITE_CORRUPT_PAGE(pPg);
64671 }
64672 return 0;
@@ -68617,11 +68641,11 @@
68641 pCur->curFlags &= ~BTCF_ValidOvfl;
68642 if( rc ){
68643 sqlite3_free(pCellKey);
68644 goto moveto_finish;
68645 }
68646 c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
68647 sqlite3_free(pCellKey);
68648 }
68649 assert(
68650 (pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
68651 && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
@@ -70217,12 +70241,13 @@
70241 /* Add any overflow cells */
70242 for(i=0; i<pPg->nOverflow; i++){
70243 int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
70244 if( iCell>=0 && iCell<nNew ){
70245 pCellptr = &pPg->aCellIdx[iCell * 2];
70246 if( nCell>iCell ){
70247 memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
70248 }
70249 nCell++;
70250 if( pageInsertArray(
70251 pPg, pBegin, &pData, pCellptr,
70252 iCell+iNew, 1, pCArray
70253 ) ) goto editpage_fail;
@@ -72333,10 +72358,13 @@
72358 BtShared *pBt = p->pBt;
72359
72360 assert( sqlite3BtreeHoldsMutex(p) );
72361 assert( p->inTrans==TRANS_WRITE );
72362 assert( iTable>=2 );
72363 if( iTable>btreePagecount(pBt) ){
72364 return SQLITE_CORRUPT_BKPT;
72365 }
72366
72367 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
72368 if( rc ) return rc;
72369 rc = sqlite3BtreeClearTable(p, iTable, 0);
72370 if( rc ){
@@ -72681,14 +72709,14 @@
72709 */
72710 static void checkList(
72711 IntegrityCk *pCheck, /* Integrity checking context */
72712 int isFreeList, /* True for a freelist. False for overflow page list */
72713 int iPage, /* Page number for first page in the list */
72714 u32 N /* Expected number of pages in the list */
72715 ){
72716 int i;
72717 u32 expected = N;
72718 int nErrAtStart = pCheck->nErr;
72719 while( iPage!=0 && pCheck->mxErr ){
72720 DbPage *pOvflPage;
72721 unsigned char *pOvflData;
72722 if( checkRef(pCheck, iPage) ) break;
@@ -72943,11 +72971,11 @@
72971 keyCanBeEqual = 0; /* Only the first key on the page may ==maxKey */
72972 }
72973
72974 /* Check the content overflow list */
72975 if( info.nPayload>info.nLocal ){
72976 u32 nPage; /* Number of pages on the overflow chain */
72977 Pgno pgnoOvfl; /* First page of the overflow chain */
72978 assert( pc + info.nSize - 4 <= usableSize );
72979 nPage = (info.nPayload - info.nLocal + usableSize - 5)/(usableSize - 4);
72980 pgnoOvfl = get4byte(&pCell[info.nSize - 4]);
72981 #ifndef SQLITE_OMIT_AUTOVACUUM
@@ -76831,10 +76859,11 @@
76859
76860 while( (pOp = opIterNext(&sIter))!=0 ){
76861 int opcode = pOp->opcode;
76862 if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
76863 || opcode==OP_VDestroy
76864 || (opcode==OP_Function0 && pOp->p4.pFunc->funcFlags&SQLITE_FUNC_INTERNAL)
76865 || ((opcode==OP_Halt || opcode==OP_HaltIfNull)
76866 && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
76867 ){
76868 hasAbort = 1;
76869 break;
@@ -82315,13 +82344,16 @@
82344 n = sqlite3_column_count(pStmt);
82345 if( N<n && N>=0 ){
82346 N += useType*n;
82347 sqlite3_mutex_enter(db->mutex);
82348 assert( db->mallocFailed==0 );
82349 #ifndef SQLITE_OMIT_UTF16
82350 if( useUtf16 ){
82351 ret = sqlite3_value_text16((sqlite3_value*)&p->aColName[N]);
82352 }else
82353 #endif
82354 {
82355 ret = sqlite3_value_text((sqlite3_value*)&p->aColName[N]);
82356 }
82357 /* A malloc may have failed inside of the _text() call. If this
82358 ** is the case, clear the mallocFailed flag and return NULL.
82359 */
@@ -82775,10 +82807,18 @@
82807 ** database.
82808 */
82809 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt){
82810 return pStmt ? ((Vdbe*)pStmt)->readOnly : 1;
82811 }
82812
82813 /*
82814 ** Return 1 if the statement is an EXPLAIN and return 2 if the
82815 ** statement is an EXPLAIN QUERY PLAN
82816 */
82817 SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt){
82818 return pStmt ? ((Vdbe*)pStmt)->explain : 0;
82819 }
82820
82821 /*
82822 ** Return true if the prepared statement is in need of being reset.
82823 */
82824 SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){
@@ -102329,19 +102369,19 @@
102369 pVTab = 0;
102370 }
102371 }
102372 #endif
102373
102374 /* Begin a transaction for database iDb. Then modify the schema cookie
102375 ** (since the ALTER TABLE modifies the schema). Call sqlite3MayAbort(),
102376 ** as the scalar functions (e.g. sqlite_rename_table()) invoked by the
102377 ** nested SQL may raise an exception. */
 
102378 v = sqlite3GetVdbe(pParse);
102379 if( v==0 ){
102380 goto exit_rename_table;
102381 }
102382 sqlite3MayAbort(pParse);
102383
102384 /* figure out how many UTF-8 characters are in zName */
102385 zTabName = pTab->zName;
102386 nTabName = sqlite3Utf8CharLen(zTabName, -1);
102387
@@ -102406,11 +102446,10 @@
102446 #ifndef SQLITE_OMIT_VIRTUALTABLE
102447 if( pVTab ){
102448 int i = ++pParse->nMem;
102449 sqlite3VdbeLoadString(v, i, zName);
102450 sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
 
102451 }
102452 #endif
102453
102454 renameReloadSchema(pParse, iDb);
102455 renameTestSchema(pParse, zDb, iDb==1);
@@ -102727,10 +102766,11 @@
102766
102767 /* Do the rename operation using a recursive UPDATE statement that
102768 ** uses the sqlite_rename_column() SQL function to compute the new
102769 ** CREATE statement text for the sqlite_master table.
102770 */
102771 sqlite3MayAbort(pParse);
102772 zNew = sqlite3NameFromToken(db, pNew);
102773 if( !zNew ) goto exit_rename_column;
102774 assert( pNew->n>0 );
102775 bQuote = sqlite3Isquote(pNew->z[0]);
102776 sqlite3NestedParse(pParse,
@@ -105981,11 +106021,13 @@
106021 */
106022 if( rc==SQLITE_OK ){
106023 sqlite3BtreeEnterAll(db);
106024 db->init.iDb = 0;
106025 db->mDbFlags &= ~(DBFLAG_SchemaKnownOk);
106026 if( !REOPEN_AS_MEMDB(db) ){
106027 rc = sqlite3Init(db, &zErrDyn);
106028 }
106029 sqlite3BtreeLeaveAll(db);
106030 assert( zErrDyn==0 || rc!=SQLITE_OK );
106031 }
106032 #ifdef SQLITE_USER_AUTHENTICATION
106033 if( rc==SQLITE_OK ){
@@ -114605,10 +114647,14 @@
114647 static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
114648 FuncDef *pDef;
114649 pDef = sqlite3FindFunction(db, zName, 2, SQLITE_UTF8, 0);
114650 if( ALWAYS(pDef) ){
114651 pDef->funcFlags |= flagVal;
114652 }
114653 pDef = sqlite3FindFunction(db, zName, 3, SQLITE_UTF8, 0);
114654 if( pDef ){
114655 pDef->funcFlags |= flagVal;
114656 }
114657 }
114658
114659 /*
114660 ** Register the built-in LIKE and GLOB functions. The caseSensitive
@@ -129717,11 +129763,11 @@
129763 ** Update the accumulator memory cells for an aggregate based on
129764 ** the current cursor position.
129765 **
129766 ** If regAcc is non-zero and there are no min() or max() aggregates
129767 ** in pAggInfo, then only populate the pAggInfo->nAccumulator accumulator
129768 ** registers if register regAcc contains 0. The caller will take care
129769 ** of setting and clearing regAcc.
129770 */
129771 static void updateAccumulator(Parse *pParse, int regAcc, AggInfo *pAggInfo){
129772 Vdbe *v = pParse->pVdbe;
129773 int i;
@@ -137079,10 +137125,38 @@
137125 sqlite3WalkExpr(&w, pWInfo->pWhere);
137126 sqlite3WalkExprList(&w, pWInfo->pOrderBy);
137127 sqlite3WalkExprList(&w, pWInfo->pResultSet);
137128 }
137129 }
137130
137131 /*
137132 ** The pTruth expression is always true because it is the WHERE clause
137133 ** a partial index that is driving a query loop. Look through all of the
137134 ** WHERE clause terms on the query, and if any of those terms must be
137135 ** true because pTruth is true, then mark those WHERE clause terms as
137136 ** coded.
137137 */
137138 static void whereApplyPartialIndexConstraints(
137139 Expr *pTruth,
137140 int iTabCur,
137141 WhereClause *pWC
137142 ){
137143 int i;
137144 WhereTerm *pTerm;
137145 while( pTruth->op==TK_AND ){
137146 whereApplyPartialIndexConstraints(pTruth->pLeft, iTabCur, pWC);
137147 pTruth = pTruth->pRight;
137148 }
137149 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
137150 Expr *pExpr;
137151 if( pTerm->wtFlags & TERM_CODED ) continue;
137152 pExpr = pTerm->pExpr;
137153 if( sqlite3ExprCompare(0, pExpr, pTruth, iTabCur)==0 ){
137154 pTerm->wtFlags |= TERM_CODED;
137155 }
137156 }
137157 }
137158
137159 /*
137160 ** Generate code for the start of the iLevel-th loop in the WHERE clause
137161 ** implementation described by pWInfo.
137162 */
@@ -137688,10 +137762,18 @@
137762 ** https://sqlite.org/src/info/4e8e4857d32d401f
137763 */
137764 if( pLevel->iLeftJoin==0 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 ){
137765 whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
137766 }
137767
137768 /* If a partial index is driving the loop, try to eliminate WHERE clause
137769 ** terms from the query that must be true due to the WHERE clause of
137770 ** the partial index
137771 */
137772 if( pIdx->pPartIdxWhere ){
137773 whereApplyPartialIndexConstraints(pIdx->pPartIdxWhere, iCur, pWC);
137774 }
137775
137776 /* Record the instruction used to terminate the loop. */
137777 if( pLoop->wsFlags & WHERE_ONEROW ){
137778 pLevel->op = OP_Noop;
137779 }else if( bRev ){
@@ -139685,10 +139767,16 @@
139767 if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1;
139768 mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
139769 }else if( p->x.pList ){
139770 mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
139771 }
139772 #ifndef SQLITE_OMIT_WINDOWFUNC
139773 if( p->op==TK_FUNCTION && p->y.pWin ){
139774 mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition);
139775 mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy);
139776 }
139777 #endif
139778 return mask;
139779 }
139780 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
139781 return p ? sqlite3WhereExprUsageNN(pMaskSet,p) : 0;
139782 }
@@ -153089,14 +153177,14 @@
153177 int n = 0; /* Length of the next token token */
153178 int tokenType; /* type of the next token */
153179 int lastTokenParsed = -1; /* type of the previous token */
153180 sqlite3 *db = pParse->db; /* The database connection */
153181 int mxSqlLen; /* Max length of an SQL string */
 
153182 #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
153183 yyParser sEngine; /* Space to hold the Lemon-generated Parser object */
153184 #endif
153185 VVA_ONLY( u8 startedWithOom = db->mallocFailed );
153186
153187 assert( zSql!=0 );
153188 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
153189 if( db->nVdbeActive==0 ){
153190 db->u1.isInterrupted = 0;
@@ -161295,11 +161383,11 @@
161383 }
161384 isFirstTerm = 0;
161385 zCsr += fts3GetVarint32(zCsr, &nSuffix);
161386
161387 assert( nPrefix>=0 && nSuffix>=0 );
161388 if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr || nSuffix==0 ){
161389 rc = FTS_CORRUPT_VTAB;
161390 goto finish_scan;
161391 }
161392 if( (i64)nPrefix+nSuffix>nAlloc ){
161393 char *zNew;
@@ -168435,11 +168523,13 @@
168523 sqlite3_result_error(context, zErr, -1);
168524 sqlite3_free(zErr);
168525 return;
168526 }
168527 }
168528 if( fts3TokenizerEnabled(context) ){
168529 sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT);
168530 }
168531 }
168532
168533 SQLITE_PRIVATE int sqlite3Fts3IsIdChar(char c){
168534 static const char isFtsIdChar[] = {
168535 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
@@ -175688,11 +175778,11 @@
175778 SnippetPhrase *pPhrase = &pIter->aPhrase[i];
175779 if( pPhrase->pTail ){
175780 char *pCsr = pPhrase->pTail;
175781 int iCsr = pPhrase->iTail;
175782
175783 while( iCsr<(iStart+pIter->nSnippet) && iCsr>=iStart ){
175784 int j;
175785 u64 mPhrase = (u64)1 << i;
175786 u64 mPos = (u64)1 << (iCsr - iStart);
175787 assert( iCsr>=iStart && (iCsr - iStart)<=64 );
175788 assert( i>=0 && i<=64 );
@@ -217166,11 +217256,11 @@
217256 int nArg, /* Number of args */
217257 sqlite3_value **apUnused /* Function arguments */
217258 ){
217259 assert( nArg==0 );
217260 UNUSED_PARAM2(nArg, apUnused);
217261 sqlite3_result_text(pCtx, "fts5: 2019-03-15 16:17:32 0f2129f59f7df929106e2af876c2976dea6528c1dc1850d64cddb256f20e121a", -1, SQLITE_TRANSIENT);
217262 }
217263
217264 /*
217265 ** Return true if zName is the extension on one of the shadow tables used
217266 ** by this module.
@@ -221930,12 +222020,12 @@
222020 }
222021 #endif /* SQLITE_CORE */
222022 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
222023
222024 /************** End of stmt.c ************************************************/
222025 #if __LINE__!=222025
222026 #undef SQLITE_SOURCE_ID
222027 #define SQLITE_SOURCE_ID "2019-03-17 23:59:02 cc5ab96715ebb1089b4e9aa647badd2510aaa056f26004718f921f4ac07ealt2"
222028 #endif
222029 /* Return the source-id for this library */
222030 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
222031 /************************** End of sqlite3.c ******************************/
222032
+19 -5
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.28.0"
127127
#define SQLITE_VERSION_NUMBER 3028000
128
-#define SQLITE_SOURCE_ID "2019-02-25 14:52:43 9da4fb59b28686630d63a79988b458726332cf06cc0e6e84d7c0a7600f5fcab0"
128
+#define SQLITE_SOURCE_ID "2019-03-17 23:59:02 cc5ab96715ebb1089b4e9aa647badd2510aaa056f26004718f921f4ac07e2f93"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -2084,12 +2084,12 @@
20842084
** following this call. The second parameter may be a NULL pointer, in
20852085
** which case the trigger setting is not reported back. </dd>
20862086
**
20872087
** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
20882088
** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2089
-** <dd> ^This option is used to enable or disable the two-argument
2090
-** version of the [fts3_tokenizer()] function which is part of the
2089
+** <dd> ^This option is used to enable or disable the
2090
+** [fts3_tokenizer()] function which is part of the
20912091
** [FTS3] full-text search engine extension.
20922092
** There should be two additional arguments.
20932093
** The first argument is an integer which is 0 to disable fts3_tokenizer() or
20942094
** positive to enable fts3_tokenizer() or negative to leave the setting
20952095
** unchanged.
@@ -3892,10 +3892,22 @@
38923892
** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
38933893
** sqlite3_stmt_readonly() returns false for those commands.
38943894
*/
38953895
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
38963896
3897
+/*
3898
+** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
3899
+** METHOD: sqlite3_stmt
3900
+**
3901
+** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the
3902
+** prepared statement S is an EXPLAIN statement, or 2 if the
3903
+** statement S is an EXPLAIN QUERY PLAN.
3904
+** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
3905
+** an ordinary statement or a NULL pointer.
3906
+*/
3907
+SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);
3908
+
38973909
/*
38983910
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
38993911
** METHOD: sqlite3_stmt
39003912
**
39013913
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
@@ -4031,11 +4043,13 @@
40314043
** with embedded NULs is undefined.
40324044
**
40334045
** ^The fifth argument to the BLOB and string binding interfaces
40344046
** is a destructor used to dispose of the BLOB or
40354047
** string after SQLite has finished with it. ^The destructor is called
4036
-** to dispose of the BLOB or string even if the call to bind API fails.
4048
+** to dispose of the BLOB or string even if the call to the bind API fails,
4049
+** except the destructor is not called if the third parameter is a NULL
4050
+** pointer or the fourth parameter is negative.
40374051
** ^If the fifth argument is
40384052
** the special value [SQLITE_STATIC], then SQLite assumes that the
40394053
** information is in static, unmanaged space and does not need to be freed.
40404054
** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
40414055
** SQLite makes its own private copy of the data immediately, before
@@ -5789,11 +5803,11 @@
57895803
**
57905804
** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
57915805
** associated with database N of connection D. ^The main database file
57925806
** has the name "main". If there is no attached database N on the database
57935807
** connection D, or if database N is a temporary or in-memory database, then
5794
-** a NULL pointer is returned.
5808
+** this function will return either a NULL pointer or an empty string.
57955809
**
57965810
** ^The filename returned by this function is the output of the
57975811
** xFullPathname method of the [VFS]. ^In other words, the filename
57985812
** will be an absolute pathname, even if the filename used
57995813
** to open the database originally was a URI or relative pathname.
58005814
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.28.0"
127 #define SQLITE_VERSION_NUMBER 3028000
128 #define SQLITE_SOURCE_ID "2019-02-25 14:52:43 9da4fb59b28686630d63a79988b458726332cf06cc0e6e84d7c0a7600f5fcab0"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -2084,12 +2084,12 @@
2084 ** following this call. The second parameter may be a NULL pointer, in
2085 ** which case the trigger setting is not reported back. </dd>
2086 **
2087 ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
2088 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2089 ** <dd> ^This option is used to enable or disable the two-argument
2090 ** version of the [fts3_tokenizer()] function which is part of the
2091 ** [FTS3] full-text search engine extension.
2092 ** There should be two additional arguments.
2093 ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
2094 ** positive to enable fts3_tokenizer() or negative to leave the setting
2095 ** unchanged.
@@ -3892,10 +3892,22 @@
3892 ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
3893 ** sqlite3_stmt_readonly() returns false for those commands.
3894 */
3895 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3896
 
 
 
 
 
 
 
 
 
 
 
 
3897 /*
3898 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3899 ** METHOD: sqlite3_stmt
3900 **
3901 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
@@ -4031,11 +4043,13 @@
4031 ** with embedded NULs is undefined.
4032 **
4033 ** ^The fifth argument to the BLOB and string binding interfaces
4034 ** is a destructor used to dispose of the BLOB or
4035 ** string after SQLite has finished with it. ^The destructor is called
4036 ** to dispose of the BLOB or string even if the call to bind API fails.
 
 
4037 ** ^If the fifth argument is
4038 ** the special value [SQLITE_STATIC], then SQLite assumes that the
4039 ** information is in static, unmanaged space and does not need to be freed.
4040 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
4041 ** SQLite makes its own private copy of the data immediately, before
@@ -5789,11 +5803,11 @@
5789 **
5790 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
5791 ** associated with database N of connection D. ^The main database file
5792 ** has the name "main". If there is no attached database N on the database
5793 ** connection D, or if database N is a temporary or in-memory database, then
5794 ** a NULL pointer is returned.
5795 **
5796 ** ^The filename returned by this function is the output of the
5797 ** xFullPathname method of the [VFS]. ^In other words, the filename
5798 ** will be an absolute pathname, even if the filename used
5799 ** to open the database originally was a URI or relative pathname.
5800
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.28.0"
127 #define SQLITE_VERSION_NUMBER 3028000
128 #define SQLITE_SOURCE_ID "2019-03-17 23:59:02 cc5ab96715ebb1089b4e9aa647badd2510aaa056f26004718f921f4ac07e2f93"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -2084,12 +2084,12 @@
2084 ** following this call. The second parameter may be a NULL pointer, in
2085 ** which case the trigger setting is not reported back. </dd>
2086 **
2087 ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
2088 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2089 ** <dd> ^This option is used to enable or disable the
2090 ** [fts3_tokenizer()] function which is part of the
2091 ** [FTS3] full-text search engine extension.
2092 ** There should be two additional arguments.
2093 ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
2094 ** positive to enable fts3_tokenizer() or negative to leave the setting
2095 ** unchanged.
@@ -3892,10 +3892,22 @@
3892 ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
3893 ** sqlite3_stmt_readonly() returns false for those commands.
3894 */
3895 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3896
3897 /*
3898 ** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
3899 ** METHOD: sqlite3_stmt
3900 **
3901 ** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the
3902 ** prepared statement S is an EXPLAIN statement, or 2 if the
3903 ** statement S is an EXPLAIN QUERY PLAN.
3904 ** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
3905 ** an ordinary statement or a NULL pointer.
3906 */
3907 SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);
3908
3909 /*
3910 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3911 ** METHOD: sqlite3_stmt
3912 **
3913 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
@@ -4031,11 +4043,13 @@
4043 ** with embedded NULs is undefined.
4044 **
4045 ** ^The fifth argument to the BLOB and string binding interfaces
4046 ** is a destructor used to dispose of the BLOB or
4047 ** string after SQLite has finished with it. ^The destructor is called
4048 ** to dispose of the BLOB or string even if the call to the bind API fails,
4049 ** except the destructor is not called if the third parameter is a NULL
4050 ** pointer or the fourth parameter is negative.
4051 ** ^If the fifth argument is
4052 ** the special value [SQLITE_STATIC], then SQLite assumes that the
4053 ** information is in static, unmanaged space and does not need to be freed.
4054 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
4055 ** SQLite makes its own private copy of the data immediately, before
@@ -5789,11 +5803,11 @@
5803 **
5804 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
5805 ** associated with database N of connection D. ^The main database file
5806 ** has the name "main". If there is no attached database N on the database
5807 ** connection D, or if database N is a temporary or in-memory database, then
5808 ** this function will return either a NULL pointer or an empty string.
5809 **
5810 ** ^The filename returned by this function is the output of the
5811 ** xFullPathname method of the [VFS]. ^In other words, the filename
5812 ** will be an absolute pathname, even if the filename used
5813 ** to open the database originally was a URI or relative pathname.
5814

Keyboard Shortcuts

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