From 5e3132ebe83b0e849cae1cc279b89c5fbb5a644e Mon Sep 17 00:00:00 2001 From: Stephen Lombardo Date: Sun, 24 May 2020 07:23:38 -0400 Subject: [PATCH] Snapshot of upstream SQLite 3.32.0 --- Makefile.in | 14 +- Makefile.msc | 22 +- autoconf/Makefile.msc | 2 + doc/lemon.html | 12 +- ext/expert/expert1.test | 15 +- ext/expert/sqlite3expert.c | 13 +- ext/fts3/fts3.c | 45 +- ext/fts3/fts3Int.h | 1 + ext/fts3/fts3_expr.c | 5 +- ext/fts3/fts3_snippet.c | 2 +- ext/fts3/fts3_write.c | 13 +- ext/fts5/fts5_vocab.c | 9 + ext/fts5/test/fts5vocab.test | 13 +- ext/icu/README.txt | 3 +- ext/icu/icu.c | 6 +- ext/misc/cksumvfs.c | 797 +++++++++++++++++++++++++++++++++++ ext/misc/fileio.c | 2 + ext/misc/json1.c | 1 + ext/misc/sha1.c | 5 +- ext/misc/stmt.c | 3 +- ext/misc/uint.c | 92 ++++ ext/rtree/rtree.c | 4 +- ext/rtree/rtree1.test | 14 +- ext/session/sessionH.test | 46 ++ ext/session/sqlite3session.c | 4 +- main.mk | 10 +- manifest | 303 ++++++------- manifest.uuid | 2 +- src/alter.c | 58 ++- src/analyze.c | 328 +++++++------- src/attach.c | 29 +- src/backup.c | 2 +- src/btree.c | 64 +-- src/btree.h | 4 +- src/btreeInt.h | 1 + src/build.c | 110 ++++- src/callback.c | 19 +- src/ctime.c | 6 +- src/date.c | 12 +- src/dbstat.c | 5 +- src/delete.c | 5 +- src/expr.c | 214 ++++++---- src/fkey.c | 2 +- src/func.c | 38 +- src/insert.c | 9 +- src/loadext.c | 14 +- src/main.c | 296 +++++++------ src/malloc.c | 16 +- src/memdb.c | 11 +- src/os_unix.c | 41 +- src/os_win.c | 23 +- src/pager.c | 69 ++- src/pager.h | 17 +- src/parse.y | 4 +- src/pragma.c | 40 +- src/pragma.h | 94 +++-- src/prepare.c | 19 +- src/printf.c | 4 +- src/resolve.c | 97 +++-- src/rowset.c | 4 +- src/select.c | 87 +++- src/shell.c.in | 561 +++++++++++++++++------- src/sqlite.h.in | 191 +++++++-- src/sqlite3ext.h | 9 + src/sqliteInt.h | 77 +++- src/sqliteLimit.h | 5 +- src/table.c | 4 +- src/tclsqlite.c | 13 +- src/test_multiplex.c | 7 +- src/tokenize.c | 4 +- src/treeview.c | 12 +- src/trigger.c | 2 +- src/update.c | 14 +- src/utf.c | 113 +++-- src/util.c | 13 + src/vacuum.c | 4 +- src/vdbe.c | 85 ++-- src/vdbe.h | 4 + src/vdbeInt.h | 16 +- src/vdbeapi.c | 4 +- src/vdbeaux.c | 408 ++++++++++-------- src/vdbemem.c | 7 +- src/vdbevtab.c | 424 +++++++++++++++++++ src/vtab.c | 2 +- src/wal.c | 409 ++++++++++++------ src/wal.h | 5 + src/walker.c | 19 +- src/where.c | 114 +++-- src/whereInt.h | 15 +- src/wherecode.c | 3 + src/whereexpr.c | 12 +- src/window.c | 23 +- test/alter.test | 1 + test/alter3.test | 1 + test/alter4.test | 2 + test/altertab.test | 48 ++- test/analyzeG.test | 88 ++++ test/attach.test | 13 +- test/count.test | 38 ++ test/cse.test | 40 ++ test/cursorhint.test | 8 +- test/default.test | 9 + test/distinct.test | 4 +- test/e_createtable.test | 80 ++-- test/e_dropview.test | 36 +- test/e_expr.test | 50 +-- test/e_fkey.test | 4 +- test/enc.test | 80 ++++ test/fkey2.test | 3 + test/fordelete.test | 2 +- test/fts3corrupt.test | 12 + test/fts3corrupt4.test | 232 ++++++++++ test/fts3matchinfo2.test | 35 ++ test/fts3misc.test | 20 + test/fts3snippet.test | 13 - test/fts3snippet2.test | 60 +++ test/fts4aa.test | 4 +- test/fts4min.test | 53 +++ test/func.test | 20 + test/func5.test | 3 +- test/fuzzcheck.c | 152 ++++++- test/fuzzdata7.db | Bin 16819200 -> 16819200 bytes test/fuzzdata8.db | Bin 1741824 -> 1492992 bytes test/icu.test | 18 + test/in6.test | 20 + test/join2.test | 31 ++ test/like.test | 18 + test/like3.test | 6 +- test/misc8.test | 6 +- test/nulls1.test | 42 ++ test/orderby5.test | 57 +++ test/permutations.test | 10 + test/select3.test | 8 + test/select4.test | 19 + test/shell1.test | 36 +- test/shell5.test | 9 +- test/tester.tcl | 3 + test/wal.test | 1 + test/walsetlk.test | 198 +++++++++ test/whereD.test | 16 + test/whereL.test | 46 ++ test/win32longpath.test | 31 +- test/window1.test | 134 ++++++ test/window4.tcl | 14 + test/window4.test | 16 + test/window9.test | 33 ++ test/windowfault.test | 11 + test/without_rowid3.test | 3 + tool/mkpragmatab.tcl | 3 + tool/mksqlite3c.tcl | 1 + tool/spaceanal.tcl | 3 + 151 files changed, 6028 insertions(+), 1655 deletions(-) create mode 100644 ext/misc/cksumvfs.c create mode 100644 ext/misc/uint.c create mode 100644 src/vdbevtab.c create mode 100644 test/analyzeG.test create mode 100644 test/fts3matchinfo2.test create mode 100644 test/fts3snippet2.test create mode 100644 test/fts4min.test create mode 100644 test/walsetlk.test diff --git a/Makefile.in b/Makefile.in index e4b8243..1341dee 100644 --- a/Makefile.in +++ b/Makefile.in @@ -190,7 +190,8 @@ LIBOBJS0 = alter.lo analyze.lo attach.lo auth.lo \ table.lo threads.lo tokenize.lo treeview.lo trigger.lo \ update.lo userauth.lo upsert.lo util.lo vacuum.lo \ vdbe.lo vdbeapi.lo vdbeaux.lo vdbeblob.lo vdbemem.lo vdbesort.lo \ - vdbetrace.lo wal.lo walker.lo where.lo wherecode.lo whereexpr.lo \ + vdbetrace.lo vdbevtab.lo \ + wal.lo walker.lo where.lo wherecode.lo whereexpr.lo \ window.lo utf.lo vtab.lo # Object files for the amalgamation. @@ -296,6 +297,7 @@ SRC = \ $(TOP)/src/vdbemem.c \ $(TOP)/src/vdbesort.c \ $(TOP)/src/vdbetrace.c \ + $(TOP)/src/vdbevtab.c \ $(TOP)/src/vdbeInt.h \ $(TOP)/src/vtab.c \ $(TOP)/src/vxworks.h \ @@ -502,6 +504,7 @@ TESTSRC2 = \ $(TOP)/src/vdbe.c \ $(TOP)/src/vdbemem.c \ $(TOP)/src/vdbetrace.c \ + $(TOP)/src/vdbevtab.c \ $(TOP)/src/where.c \ $(TOP)/src/wherecode.c \ $(TOP)/src/whereexpr.c \ @@ -607,6 +610,7 @@ SHELL_OPT += -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION SHELL_OPT += -DSQLITE_ENABLE_STMTVTAB SHELL_OPT += -DSQLITE_ENABLE_DBPAGE_VTAB SHELL_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB +SHELL_OPT += -DSQLITE_ENABLE_BYTECODE_VTAB SHELL_OPT += -DSQLITE_ENABLE_OFFSET_SQL_FUNC SHELL_OPT += -DSQLITE_ENABLE_DESERIALIZE FUZZERSHELL_OPT = -DSQLITE_ENABLE_JSON1 @@ -615,10 +619,12 @@ FUZZCHECK_OPT += -DSQLITE_MAX_MEMORY=50000000 FUZZCHECK_OPT += -DSQLITE_PRINTF_PRECISION_LIMIT=1000 FUZZCHECK_OPT += -DSQLITE_ENABLE_DESERIALIZE FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS4 +FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS3_PARENTHESIS #FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS5 FUZZCHECK_OPT += -DSQLITE_ENABLE_RTREE FUZZCHECK_OPT += -DSQLITE_ENABLE_GEOPOLY FUZZCHECK_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB +FUZZCHECK_OPT += -DSQLITE_ENABLE_BYTECODE_VTAB FUZZCHECK_SRC = $(TOP)/test/fuzzcheck.c $(TOP)/test/ossfuzz.c DBFUZZ_OPT = @@ -688,6 +694,7 @@ DBFUZZ2_OPTS = \ -DSQLITE_ENABLE_DESERIALIZE \ -DSQLITE_DEBUG \ -DSQLITE_ENABLE_DBSTAT_VTAB \ + -DSQLITE_ENABLE_BYTECODE_VTAB \ -DSQLITE_ENABLE_RTREE \ -DSQLITE_ENABLE_FTS4 \ -DSQLITE_ENABLE_FTS5 @@ -1004,6 +1011,9 @@ vdbesort.lo: $(TOP)/src/vdbesort.c $(HDR) vdbetrace.lo: $(TOP)/src/vdbetrace.c $(HDR) $(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/vdbetrace.c +vdbevtab.lo: $(TOP)/src/vdbevtab.c $(HDR) + $(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/vdbevtab.c + vtab.lo: $(TOP)/src/vtab.c $(HDR) $(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/vtab.c @@ -1069,6 +1079,7 @@ SHELL_SRC = \ $(TOP)/ext/misc/fileio.c \ $(TOP)/ext/misc/completion.c \ $(TOP)/ext/misc/sqlar.c \ + $(TOP)/ext/misc/uint.c \ $(TOP)/ext/expert/sqlite3expert.c \ $(TOP)/ext/expert/sqlite3expert.h \ $(TOP)/ext/misc/zipfile.c \ @@ -1210,6 +1221,7 @@ TESTFIXTURE_FLAGS += -DSQLITE_SERIES_CONSTRAINT_VERIFY=1 TESTFIXTURE_FLAGS += -DSQLITE_DEFAULT_PAGE_SIZE=1024 TESTFIXTURE_FLAGS += -DSQLITE_ENABLE_STMTVTAB TESTFIXTURE_FLAGS += -DSQLITE_ENABLE_DBPAGE_VTAB +TESTFIXTURE_FLAGS += -DSQLITE_ENABLE_BYTECODE_VTAB TESTFIXTURE_FLAGS += -DSQLITE_ENABLE_DESERIALIZE TESTFIXTURE_SRC0 = $(TESTSRC2) libsqlite3.la diff --git a/Makefile.msc b/Makefile.msc index d0b7860..a5c9828 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -234,6 +234,15 @@ OSTRACE = 0 DEBUG = 0 !ENDIF +# <> +# Disable use of the --linemacros argument to the mksqlite3c.tcl tool, which +# is used to build the amalgamation. +# +!IFNDEF NO_LINEMACROS +NO_LINEMACROS = 0 +!ENDIF +# <> + # Enable use of available compiler optimizations? Normally, this should be # non-zero. Setting this to zero, thus disabling all compiler optimizations, # can be useful for testing. @@ -357,6 +366,7 @@ OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_JSON1=1 OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1 OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1 OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBSTAT_VTAB=1 +OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_BYTECODE_VTAB=1 OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DESERIALIZE=1 !ENDIF OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_COLUMN_METADATA=1 @@ -775,7 +785,7 @@ MKSQLITE3C_TOOL = $(TOP)\tool\mksqlite3c.tcl !ENDIF !IFNDEF MKSQLITE3C_ARGS -!IF $(DEBUG)>1 +!IF $(DEBUG)>1 && $(NO_LINEMACROS)==0 MKSQLITE3C_ARGS = --linemacros !ELSE MKSQLITE3C_ARGS = @@ -1246,7 +1256,8 @@ LIBOBJS0 = vdbe.lo parse.lo alter.lo analyze.lo attach.lo auth.lo \ table.lo threads.lo tokenize.lo treeview.lo trigger.lo \ update.lo upsert.lo util.lo vacuum.lo \ vdbeapi.lo vdbeaux.lo vdbeblob.lo vdbemem.lo vdbesort.lo \ - vdbetrace.lo wal.lo walker.lo where.lo wherecode.lo whereexpr.lo \ + vdbetrace.lo vdbevtab.lo wal.lo walker.lo where.lo wherecode.lo \ + whereexpr.lo \ window.lo utf.lo vtab.lo # <> @@ -1353,6 +1364,7 @@ SRC01 = \ $(TOP)\src\vdbemem.c \ $(TOP)\src\vdbesort.c \ $(TOP)\src\vdbetrace.c \ + $(TOP)\src\vdbevtab.c \ $(TOP)\src\vtab.c \ $(TOP)\src\wal.c \ $(TOP)\src\walker.c \ @@ -1684,6 +1696,7 @@ FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_FTS4 FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_RTREE FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_GEOPOLY FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_DBSTAT_VTAB +FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_BYTECODE_VTAB FUZZCHECK_SRC = $(TOP)\test\fuzzcheck.c $(TOP)\test\ossfuzz.c OSSSHELL_SRC = $(TOP)\test\ossshell.c $(TOP)\test\ossfuzz.c @@ -2109,6 +2122,9 @@ vdbesort.lo: $(TOP)\src\vdbesort.c $(HDR) vdbetrace.lo: $(TOP)\src\vdbetrace.c $(HDR) $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\vdbetrace.c +vdbevtab.lo: $(TOP)\src\vdbevtab.c $(HDR) + $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\vdbevtab.c + vtab.lo: $(TOP)\src\vtab.c $(HDR) $(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\vtab.c @@ -2182,6 +2198,7 @@ SHELL_SRC = \ $(TOP)\ext\misc\shathree.c \ $(TOP)\ext\misc\fileio.c \ $(TOP)\ext\misc\completion.c \ + $(TOP)\ext\misc\uint.c \ $(TOP)\ext\expert\sqlite3expert.c \ $(TOP)\ext\expert\sqlite3expert.h \ $(TOP)\ext\misc\memtrace.c \ @@ -2352,6 +2369,7 @@ TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_SERIES_CONSTRAINT_VERIFY=1 TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_DEFAULT_PAGE_SIZE=1024 TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1 TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1 +TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_BYTECODE_VTAB=1 TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_JSON1=1 TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_DESERIALIZE=1 TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) $(TEST_CCONV_OPTS) diff --git a/autoconf/Makefile.msc b/autoconf/Makefile.msc index 37a3c1b..746162a 100644 --- a/autoconf/Makefile.msc +++ b/autoconf/Makefile.msc @@ -196,6 +196,7 @@ OSTRACE = 0 DEBUG = 0 !ENDIF + # Enable use of available compiler optimizations? Normally, this should be # non-zero. Setting this to zero, thus disabling all compiler optimizations, # can be useful for testing. @@ -288,6 +289,7 @@ OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_JSON1=1 OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1 OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1 OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBSTAT_VTAB=1 +OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_BYTECODE_VTAB=1 OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DESERIALIZE=1 !ENDIF OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_COLUMN_METADATA=1 diff --git a/doc/lemon.html b/doc/lemon.html index 056ae5f..17988de 100644 --- a/doc/lemon.html +++ b/doc/lemon.html @@ -123,7 +123,7 @@ Suppress generation of the report file.
  • -r Do not sort or renumber the parser states as part of optimization.
  • -s -Show parser statistics before existing. +Show parser statistics before exiting.
  • -Tfile Use file as the template for the generated C-code parser implementation.
  • -x @@ -488,7 +488,7 @@ is an error.

    The precedence of a grammar rule is equal to the precedence of the left-most terminal symbol in the rule for which a precedence is defined. This is normally what you want, but in those cases where -you want to precedence of a grammar rule to be something different, +you want the precedence of a grammar rule to be something different, you can specify an alternative precedence symbol by putting the symbol in square braces after the period at the end of the rule and before any C-code. For example:

    @@ -689,7 +689,7 @@ on Parse().

    The %extra_context directive

    -The %extra_context directive instructs Lemon to add a 2th parameter +The %extra_context directive instructs Lemon to add a 2nd parameter to the parameter list of the ParseAlloc() and ParseInif() functions. Lemon doesn't do anything itself with these extra argument, but it does store the value make it available to C-code action routines, destructors, @@ -699,9 +699,9 @@ and so forth. For example, if the grammar file contains:

    %extra_context { MyStruct *pAbc }

    -

    Then the ParseAlloc() and ParseInit() functions will have an 2th parameter +

    Then the ParseAlloc() and ParseInit() functions will have an 2nd parameter of type "MyStruct*" and all action routines will have access to -a variable named "pAbc" that is the value of that 2th parameter.

    +a variable named "pAbc" that is the value of that 2nd parameter.

    The %extra_argument directive works the same except that it is passed in on the Parse() routine instead of on ParseAlloc()/ParseInit(). @@ -996,7 +996,7 @@ on the parser's stack associated with terminal and non-terminal symbols. The values of all terminal symbols must be of the same type. This turns out to be the same data type as the 3rd parameter to the Parse() function generated by Lemon. Typically, you will -make the value of a terminal symbol by a pointer to some kind of +make the value of a terminal symbol be a pointer to some kind of token structure. Like this:

    diff --git a/ext/expert/expert1.test b/ext/expert/expert1.test
    index a0a18f6..3e5d604 100644
    --- a/ext/expert/expert1.test
    +++ b/ext/expert/expert1.test
    @@ -37,6 +37,9 @@ proc squish {txt} {
     
     proc do_setup_rec_test {tn setup sql res} {
       reset_db
    +  if {[info exists ::set_main_db_name]} {
    +    dbconfig_maindbname_icecube db
    +  }
       db eval $setup
       uplevel [list do_rec_test $tn $sql $res]
     }
    @@ -76,6 +79,10 @@ foreach {tn setup} {
         }
       }
       3 {
    +    if {[info commands sqlite3_expert_new]==""} { continue }
    +    set ::set_main_db_name 1
    +  }
    +  4 {
         if {![file executable $CLI]} { continue }
     
         proc do_rec_test {tn sql res} {
    @@ -336,7 +343,7 @@ proc do_candidates_test {tn sql res} {
     
     
     reset_db
    -do_execsql_test 4.0 {
    +do_execsql_test 5.0 {
       CREATE TABLE t1(a, b);
       CREATE TABLE t2(c, d);
     
    @@ -346,7 +353,7 @@ do_execsql_test 4.0 {
       WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<100)
       INSERT INTO t2 SELECT (i-1)/20, (i-1)/5 FROM s;
     }
    -do_candidates_test 4.1 {
    +do_candidates_test 5.1 {
       SELECT * FROM t1,t2 WHERE (b=? OR a=?) AND (c=? OR d=?)
     } {
       CREATE INDEX t1_idx_00000062 ON t1(b); -- stat1: 100 20 
    @@ -355,14 +362,14 @@ do_candidates_test 4.1 {
       CREATE INDEX t2_idx_00000064 ON t2(d); -- stat1: 100 5
     }
     
    -do_candidates_test 4.2 {
    +do_candidates_test 5.2 {
       SELECT * FROM t1,t2 WHERE a=? AND b=? AND c=? AND d=?
     } {
       CREATE INDEX t1_idx_000123a7 ON t1(a, b); -- stat1: 100 50 17
       CREATE INDEX t2_idx_0001295b ON t2(c, d); -- stat1: 100 20 5
     }
     
    -do_execsql_test 4.3 {
    +do_execsql_test 5.3 {
       CREATE INDEX t1_idx_00000061 ON t1(a); -- stat1: 100 50 
       CREATE INDEX t1_idx_00000062 ON t1(b); -- stat1: 100 20 
       CREATE INDEX t1_idx_000123a7 ON t1(a, b); -- stat1: 100 50 16
    diff --git a/ext/expert/sqlite3expert.c b/ext/expert/sqlite3expert.c
    index e88fb7e..b5a6fd2 100644
    --- a/ext/expert/sqlite3expert.c
    +++ b/ext/expert/sqlite3expert.c
    @@ -1128,14 +1128,19 @@ int idxFindIndexes(
           /* int iParent = sqlite3_column_int(pExplain, 1); */
           /* int iNotUsed = sqlite3_column_int(pExplain, 2); */
           const char *zDetail = (const char*)sqlite3_column_text(pExplain, 3);
    -      int nDetail = STRLEN(zDetail);
    +      int nDetail;
           int i;
     
    +      if( !zDetail ) continue;
    +      nDetail = STRLEN(zDetail);
    +
           for(i=0; i='0' && z[i]<='9'; i++){
    +    iVal = iVal*10 + (z[i] - '0');
    +    if( iVal>0x7FFFFFFF ) return -1;
    +  }
    +  *pnOut = (int)iVal;
    +  return i;
    +}
    +
     /*
     ** This function interprets the string at (*pp) as a non-negative integer
     ** value. It reads the integer and sets *pnOut to the value read, then 
    @@ -977,19 +993,17 @@ static char *fts3WriteExprList(Fts3Table *p, const char *zFunc, int *pRc){
     */
     static int fts3GobbleInt(const char **pp, int *pnOut){
       const int MAX_NPREFIX = 10000000;
    -  const char *p;                  /* Iterator pointer */
       int nInt = 0;                   /* Output value */
    -
    -  for(p=*pp; p[0]>='0' && p[0]<='9'; p++){
    -    nInt = nInt * 10 + (p[0] - '0');
    -    if( nInt>MAX_NPREFIX ){
    -      nInt = 0;
    -      break;
    -    }
    +  int nByte;
    +  nByte = sqlite3Fts3ReadInt(*pp, &nInt);
    +  if( nInt>MAX_NPREFIX ){
    +    nInt = 0;
    +  }
    +  if( nByte==0 ){
    +    return SQLITE_ERROR;
       }
    -  if( p==*pp ) return SQLITE_ERROR;
       *pnOut = nInt;
    -  *pp = p;
    +  *pp += nByte;
       return SQLITE_OK;
     }
     
    @@ -1884,6 +1898,7 @@ static int fts3ScanInteriorNode(
       i64 nAlloc = 0;                 /* Size of allocated buffer */
       int isFirstTerm = 1;            /* True when processing first term on page */
       sqlite3_int64 iChild;           /* Block id of child node to descend to */
    +  int nBuffer = 0;                /* Total term size */
     
       /* Skip over the 'height' varint that occurs at the start of every 
       ** interior node. Then load the blockid of the left-child of the b-tree
    @@ -1908,12 +1923,15 @@ static int fts3ScanInteriorNode(
         int cmp;                      /* memcmp() result */
         int nSuffix;                  /* Size of term suffix */
         int nPrefix = 0;              /* Size of term prefix */
    -    int nBuffer;                  /* Total term size */
       
         /* Load the next term on the node into zBuffer. Use realloc() to expand
         ** the size of zBuffer if required.  */
         if( !isFirstTerm ){
           zCsr += fts3GetVarint32(zCsr, &nPrefix);
    +      if( nPrefix>nBuffer ){
    +        rc = FTS_CORRUPT_VTAB;
    +        goto finish_scan;
    +      }
         }
         isFirstTerm = 0;
         zCsr += fts3GetVarint32(zCsr, &nSuffix);
    @@ -2167,7 +2185,9 @@ static void fts3ReadNextPos(
       sqlite3_int64 *pi             /* IN/OUT: Value read from position-list */
     ){
       if( (**pp)&0xFE ){
    -    fts3GetDeltaVarint(pp, pi);
    +    int iVal;
    +    *pp += fts3GetVarint32((*pp), &iVal);
    +    *pi += iVal;
         *pi -= 2;
       }else{
         *pi = POSITION_LIST_END;
    @@ -5297,6 +5317,7 @@ static void fts3EvalNextRow(
                     fts3EvalNextRow(pCsr, pLeft, pRc);
                   }
                 }
    +            pRight->bEof = pLeft->bEof = 1;
               }
             }
             break;
    diff --git a/ext/fts3/fts3Int.h b/ext/fts3/fts3Int.h
    index 50370a9..453afce 100644
    --- a/ext/fts3/fts3Int.h
    +++ b/ext/fts3/fts3Int.h
    @@ -591,6 +591,7 @@ int sqlite3Fts3EvalPhraseStats(Fts3Cursor *, Fts3Expr *, u32 *);
     int sqlite3Fts3FirstFilter(sqlite3_int64, char *, int, char *);
     void sqlite3Fts3CreateStatTable(int*, Fts3Table*);
     int sqlite3Fts3EvalTestDeferred(Fts3Cursor *pCsr, int *pRc);
    +int sqlite3Fts3ReadInt(const char *z, int *pnOut);
     
     /* fts3_tokenizer.c */
     const char *sqlite3Fts3NextToken(const char *, int *);
    diff --git a/ext/fts3/fts3_expr.c b/ext/fts3/fts3_expr.c
    index 5775fbc..e19137a 100644
    --- a/ext/fts3/fts3_expr.c
    +++ b/ext/fts3/fts3_expr.c
    @@ -446,10 +446,7 @@ static int getNextNode(
           if( pKey->eType==FTSQUERY_NEAR ){
             assert( nKey==4 );
             if( zInput[4]=='/' && zInput[5]>='0' && zInput[5]<='9' ){
    -          nNear = 0;
    -          for(nKey=5; zInput[nKey]>='0' && zInput[nKey]<='9'; nKey++){
    -            nNear = nNear * 10 + (zInput[nKey] - '0');
    -          }
    +          nKey += 1+sqlite3Fts3ReadInt(&zInput[nKey+1], &nNear);
             }
           }
     
    diff --git a/ext/fts3/fts3_snippet.c b/ext/fts3/fts3_snippet.c
    index 2b20ba1..ebc771f 100644
    --- a/ext/fts3/fts3_snippet.c
    +++ b/ext/fts3/fts3_snippet.c
    @@ -876,7 +876,7 @@ static int fts3ExprLHits(
         iStart = pExpr->iPhrase * ((p->nCol + 31) / 32);
       }
     
    -  while( 1 ){
    +  if( pIter ) while( 1 ){
         int nHit = fts3ColumnlistCount(&pIter);
         if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){
           if( p->flag==FTS3_MATCHINFO_LHITS ){
    diff --git a/ext/fts3/fts3_write.c b/ext/fts3/fts3_write.c
    index 253be11..b9acc47 100644
    --- a/ext/fts3/fts3_write.c
    +++ b/ext/fts3/fts3_write.c
    @@ -1415,6 +1415,7 @@ static int fts3SegReaderNext(
       */
       if( pReader->nDoclist > pReader->nNode-(pReader->aDoclist-pReader->aNode)
        || (pReader->nPopulate==0 && pReader->aDoclist[pReader->nDoclist-1])
    +   || pReader->nDoclist==0
       ){
         return FTS_CORRUPT_VTAB;
       }
    @@ -3068,11 +3069,11 @@ static void fts3ReadEndBlockField(
       if( zText ){
         int i;
         int iMul = 1;
    -    i64 iVal = 0;
    +    u64 iVal = 0;
         for(i=0; zText[i]>='0' && zText[i]<='9'; i++){
           iVal = iVal*10 + (zText[i] - '0');
         }
    -    *piEndBlock = iVal;
    +    *piEndBlock = (i64)iVal;
         while( zText[i]==' ' ) i++;
         iVal = 0;
         if( zText[i]=='-' ){
    @@ -3082,7 +3083,7 @@ static void fts3ReadEndBlockField(
         for(/* no-op */; zText[i]>='0' && zText[i]<='9'; i++){
           iVal = iVal*10 + (zText[i] - '0');
         }
    -    *pnByte = (iVal * (i64)iMul);
    +    *pnByte = ((i64)iVal * (i64)iMul);
       }
     }
     
    @@ -4953,6 +4954,12 @@ int sqlite3Fts3Incrmerge(Fts3Table *p, int nMerge, int nMin){
         ** Exit early in this case.  */
         if( nSeg<=0 ) break;
     
    +    assert( nMod<=0x7FFFFFFF );
    +    if( iAbsLevel<0 || iAbsLevel>(nMod<<32) ){
    +      rc = FTS_CORRUPT_VTAB;
    +      break;
    +    }
    +
         /* Open a cursor to iterate through the contents of the oldest nSeg 
         ** indexes of absolute level iAbsLevel. If this cursor is opened using 
         ** the 'hint' parameters, it is possible that there are less than nSeg
    diff --git a/ext/fts5/fts5_vocab.c b/ext/fts5/fts5_vocab.c
    index 36a3673..48aa693 100644
    --- a/ext/fts5/fts5_vocab.c
    +++ b/ext/fts5/fts5_vocab.c
    @@ -50,6 +50,7 @@ struct Fts5VocabTable {
       sqlite3 *db;                    /* Database handle */
       Fts5Global *pGlobal;            /* FTS5 global object for this database */
       int eType;                      /* FTS5_VOCAB_COL, ROW or INSTANCE */
    +  unsigned bBusy;                 /* True if busy */
     };
     
     struct Fts5VocabCursor {
    @@ -332,6 +333,12 @@ static int fts5VocabOpenMethod(
       sqlite3_stmt *pStmt = 0;
       char *zSql = 0;
     
    +  if( pTab->bBusy ){
    +    pVTab->zErrMsg = sqlite3_mprintf(
    +       "recursive definition for %s.%s", pTab->zFts5Db, pTab->zFts5Tbl
    +    );
    +    return SQLITE_ERROR;
    +  }
       zSql = sqlite3Fts5Mprintf(&rc,
           "SELECT t.%Q FROM %Q.%Q AS t WHERE t.%Q MATCH '*id'",
           pTab->zFts5Tbl, pTab->zFts5Db, pTab->zFts5Tbl, pTab->zFts5Tbl
    @@ -343,10 +350,12 @@ static int fts5VocabOpenMethod(
       assert( rc==SQLITE_OK || pStmt==0 );
       if( rc==SQLITE_ERROR ) rc = SQLITE_OK;
     
    +  pTab->bBusy = 1;
       if( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){
         i64 iId = sqlite3_column_int64(pStmt, 0);
         pFts5 = sqlite3Fts5TableFromCsrid(pTab->pGlobal, iId);
       }
    +  pTab->bBusy = 0;
     
       if( rc==SQLITE_OK ){
         if( pFts5==0 ){
    diff --git a/ext/fts5/test/fts5vocab.test b/ext/fts5/test/fts5vocab.test
    index a1bf2a4..c457c5c 100644
    --- a/ext/fts5/test/fts5vocab.test
    +++ b/ext/fts5/test/fts5vocab.test
    @@ -542,5 +542,16 @@ do_execsql_test 10.7.3 {
       SELECT * FROM t2 WHERE term=?;
     }
     
    -finish_test
    +# 2020-02-16  Detect recursively define fts5vocab() tables.
    +# Error found by dbsqlfuzz.
    +#
    +reset_db
    +do_execsql_test 11.100 {
    +  CREATE VIRTUAL TABLE t3 USING fts5vocab(rowid , 'col');
    +  CREATE VIRTUAL TABLE rowid USING fts5vocab(rowid , 'instance');
    +} {}
    +do_catchsql_test 11.110 {
    +  SELECT rowid+1,rowid, * FROM t3 WHERE null>rowid ;
    +} {1 {SQL logic error}}
     
    +finish_test
    diff --git a/ext/icu/README.txt b/ext/icu/README.txt
    index af75d22..be443f5 100644
    --- a/ext/icu/README.txt
    +++ b/ext/icu/README.txt
    @@ -116,7 +116,8 @@ SQLite. Documentation follows.
       and use it as a dynamically loadable SQLite extension. To do this
       using gcc on *nix:
     
    -    gcc -shared icu.c `icu-config --ldflags` -o libSqliteIcu.so
    +    gcc -fPIC -shared icu.c `pkg-config --libs --cflags icu-uc icu-io` \
    +        -o libSqliteIcu.so
     
       You may need to add "-I" flags so that gcc can find sqlite3ext.h
       and sqlite3.h. The resulting shared lib, libSqliteIcu.so, may be
    diff --git a/ext/icu/icu.c b/ext/icu/icu.c
    index 7fbe32a..92d7c54 100644
    --- a/ext/icu/icu.c
    +++ b/ext/icu/icu.c
    @@ -143,7 +143,7 @@ static int icuLikeCompare(
         **     3. uPattern is an unescaped escape character, or
         **     4. uPattern is to be handled as an ordinary character
         */
    -    if( !prevEscape && uPattern==MATCH_ALL ){
    +    if( uPattern==MATCH_ALL && !prevEscape && uPattern!=(uint32_t)uEsc ){
           /* Case 1. */
           uint8_t c;
     
    @@ -169,12 +169,12 @@ static int icuLikeCompare(
           }
           return 0;
     
    -    }else if( !prevEscape && uPattern==MATCH_ONE ){
    +    }else if( uPattern==MATCH_ONE && !prevEscape && uPattern!=(uint32_t)uEsc ){
           /* Case 2. */
           if( *zString==0 ) return 0;
           SQLITE_ICU_SKIP_UTF8(zString);
     
    -    }else if( !prevEscape && uPattern==(uint32_t)uEsc){
    +    }else if( uPattern==(uint32_t)uEsc && !prevEscape ){
           /* Case 3. */
           prevEscape = 1;
     
    diff --git a/ext/misc/cksumvfs.c b/ext/misc/cksumvfs.c
    new file mode 100644
    index 0000000..2cc8148
    --- /dev/null
    +++ b/ext/misc/cksumvfs.c
    @@ -0,0 +1,797 @@
    +/*
    +** 2020-04-20
    +**
    +** The author disclaims copyright to this source code.  In place of
    +** a legal notice, here is a blessing:
    +**
    +**    May you do good and not evil.
    +**    May you find forgiveness for yourself and forgive others.
    +**    May you share freely, never taking more than you give.
    +**
    +******************************************************************************
    +**
    +** This file implements a VFS shim that writes a checksum on each page
    +** of an SQLite database file.  When reading pages, the checksum is verified
    +** and an error is raised if the checksum is incorrect.
    +**
    +** COMPILING
    +**
    +** This extension requires SQLite 3.32.0 or later.  It uses the
    +** sqlite3_database_file_object() interface which was added in
    +** version 3.32.0, so it will not link with an earlier version of
    +** SQLite.
    +**
    +** To build this extension as a separately loaded shared library or
    +** DLL, use compiler command-lines similar to the following:
    +**
    +**   (linux)    gcc -fPIC -shared cksumvfs.c -o cksumvfs.so
    +**   (mac)      clang -fPIC -dynamiclib cksumvfs.c -o cksumvfs.dylib
    +**   (windows)  cl cksumvfs.c -link -dll -out:cksumvfs.dll
    +**
    +** You may want to add additional compiler options, of course,
    +** according to the needs of your project.
    +**
    +** If you want to statically link this extension with your product,
    +** then compile it like any other C-language module but add the
    +** "-DSQLITE_CKSUMVFS_STATIC" option so that this module knows that
    +** it is being statically linked rather than dynamically linked
    +**
    +** LOADING
    +**
    +** To load this extension as a shared library, you first have to
    +** bring up a dummy SQLite database connection to use as the argument
    +** to the sqlite3_load_extension() API call.  Then you invoke the
    +** sqlite3_load_extension() API and shutdown the dummy database
    +** connection.  All subsequent database connections that are opened
    +** will include this extension.  For example:
    +**
    +**     sqlite3 *db;
    +**     sqlite3_open(":memory:", &db);
    +**     sqlite3_load_extention(db, "./cksumvfs");
    +**     sqlite3_close(db);
    +**
    +** If this extension is compiled with -DSQLITE_CKSUMVFS_STATIC and
    +** statically linked against the application, initialize it using
    +** a single API call as follows:
    +**
    +**     sqlite3_cksumvfs_init();
    +**
    +** Cksumvfs is a VFS Shim. When loaded, "cksmvfs" becomes the new
    +** default VFS and it uses the prior default VFS as the next VFS
    +** down in the stack.  This is normally what you want.  However, it
    +** complex situations where multiple VFS shims are being loaded,
    +** it might be important to ensure that cksumvfs is loaded in the
    +** correct order so that it sequences itself into the default VFS
    +** Shim stack in the right order.
    +**
    +** USING
    +**
    +** Open database connections using the sqlite3_open() or 
    +** sqlite3_open_v2() interfaces, as normal.  Ordinary database files
    +** (without a checksum) will operate normally.  Databases with 
    +** checksums will return an SQLITE_IOERR_DATA error if a page is
    +** encountered that contains an invalid checksum.
    +**
    +** Checksumming only works on databases that have a reserve-bytes
    +** value of exactly 8.  The default value for reserve-bytes is 0.
    +** Hence, newly created database files will omit the checksum by
    +** default.  To create a database that includes a checksum, change
    +** the reserve-bytes value to 8 by runing:
    +**
    +**    int n = 8;
    +**    sqlite3_file_control(db, 0, SQLITE_FCNTL_RESERVED_BYTES, &n);
    +**
    +** If you do this immediately after creating a new database file,
    +** before anything else has been written into the file, then that
    +** might be all that you need to do.  Otherwise, the API call
    +** above should be followed by:
    +**
    +**    sqlite3_exec(db, "VACUUM", 0, 0, 0);
    +**
    +** It never hurts to run the VACUUM, even if you don't need it.
    +** If the database is in WAL mode, you should shutdown and
    +** reopen all database connections before continuing.
    +**
    +** From the CLI, use the ".filectrl reserve_bytes 8" command, 
    +** followed by "VACUUM;".
    +**
    +** Note that SQLite allows the number of reserve-bytes to be
    +** increased but not decreased.  So if a database file already
    +** has a reserve-bytes value greater than 8, there is no way to
    +** activate checksumming on that database, other than to dump
    +** and restore the database file.  Note also that other extensions
    +** might also make use of the reserve-bytes.  Checksumming will
    +** be incompatible with those other extensions.
    +**
    +** VERIFICATION OF CHECKSUMS
    +**
    +** If any checksum is incorrect, the "PRAGMA quick_check" command
    +** will find it.  To verify that checksums are actually enabled
    +** and running, use the following query:
    +**
    +**   SELECT count(*), verify_checksum(data)
    +**     FROM sqlite_dbpage
    +**    GROUP BY 2;
    +**
    +** There are three possible outputs form the verify_checksum()
    +** function: 1, 0, and NULL.  1 is returned if the checksum is
    +** correct.  0 is returned if the checksum is incorrect.  NULL
    +** is returned if the page is unreadable.  If checksumming is
    +** enabled, the read will fail if the checksum is wrong, so the
    +** usual result from verify_checksum() on a bad checksum is NULL.
    +**
    +** If everything is OK, the query above should return a single
    +** row where the second column is 1.  Any other result indicates
    +** either that there is a checksum error, or checksum validation
    +** is disabled.
    +**
    +** CONTROLLING CHECKSUM VERIFICATION
    +**
    +** The cksumvfs extension implements a new PRAGMA statement that can
    +** be used to disable, re-enable, or query the status of checksum
    +** verification:
    +**
    +**    PRAGMA checksum_verification;          -- query status
    +**    PRAGMA checksum_verification=OFF;      -- disable verification
    +**    PRAGMA checksum_verification=ON;       -- re-enable verification
    +**
    +** The "checksum_verification" pragma will return "1" (true) or "0"
    +** (false) if checksum verification is enabled or disabled, respectively.
    +** "Verification" in this context means the feature that causes
    +** SQLITE_IOERR_DATA errors if a checksum mismatch is detected while
    +** reading.  Checksums are always kept up-to-date as long as the
    +** reserve-bytes value of the database is 8, regardless of the setting
    +** of this pragma.  Checksum verification can be disabled (for example)
    +** to do forensic analysis of a database that has previously reported
    +** a checksum error.
    +**
    +** The "checksum_verification" pragma will always respond with "0" if
    +** the database file does not have a reserve-bytes value of 8.  The
    +** pragma will return no rows at all if the cksumvfs extension is
    +** not loaded.
    +**
    +** IMPLEMENTATION NOTES
    +**
    +** The checksum is stored in the last 8 bytes of each page.  This
    +** module only operates if the "bytes of reserved space on each page"
    +** value at offset 20 the SQLite database header is exactly 8.  If
    +** the reserved-space value is not 8, this module is a no-op.
    +*/
    +#ifdef SQLITE_CKSUMVFS_STATIC
    +# include "sqlite3.h"
    +#else
    +# include "sqlite3ext.h"
    +  SQLITE_EXTENSION_INIT1
    +#endif
    +#include 
    +#include 
    +
    +
    +/*
    +** Forward declaration of objects used by this utility
    +*/
    +typedef struct sqlite3_vfs CksmVfs;
    +typedef struct CksmFile CksmFile;
    +
    +/*
    +** Useful datatype abbreviations
    +*/
    +#if !defined(SQLITE_CORE)
    +  typedef unsigned char u8;
    +  typedef unsigned int u32;
    +#endif
    +
    +/* Access to a lower-level VFS that (might) implement dynamic loading,
    +** access to randomness, etc.
    +*/
    +#define ORIGVFS(p)  ((sqlite3_vfs*)((p)->pAppData))
    +#define ORIGFILE(p) ((sqlite3_file*)(((CksmFile*)(p))+1))
    +
    +/* An open file */
    +struct CksmFile {
    +  sqlite3_file base;    /* IO methods */
    +  const char *zFName;   /* Original name of the file */
    +  char computeCksm;     /* True to compute checksums.
    +                        ** Always true if reserve size is 8. */
    +  char verifyCksm;      /* True to verify checksums */
    +  char isWal;           /* True if processing a WAL file */
    +  char inCkpt;          /* Currently doing a checkpoint */
    +  CksmFile *pPartner;   /* Ptr from WAL to main-db, or from main-db to WAL */
    +};
    +
    +/*
    +** Methods for CksmFile
    +*/
    +static int cksmClose(sqlite3_file*);
    +static int cksmRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
    +static int cksmWrite(sqlite3_file*,const void*,int iAmt, sqlite3_int64 iOfst);
    +static int cksmTruncate(sqlite3_file*, sqlite3_int64 size);
    +static int cksmSync(sqlite3_file*, int flags);
    +static int cksmFileSize(sqlite3_file*, sqlite3_int64 *pSize);
    +static int cksmLock(sqlite3_file*, int);
    +static int cksmUnlock(sqlite3_file*, int);
    +static int cksmCheckReservedLock(sqlite3_file*, int *pResOut);
    +static int cksmFileControl(sqlite3_file*, int op, void *pArg);
    +static int cksmSectorSize(sqlite3_file*);
    +static int cksmDeviceCharacteristics(sqlite3_file*);
    +static int cksmShmMap(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
    +static int cksmShmLock(sqlite3_file*, int offset, int n, int flags);
    +static void cksmShmBarrier(sqlite3_file*);
    +static int cksmShmUnmap(sqlite3_file*, int deleteFlag);
    +static int cksmFetch(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
    +static int cksmUnfetch(sqlite3_file*, sqlite3_int64 iOfst, void *p);
    +
    +/*
    +** Methods for CksmVfs
    +*/
    +static int cksmOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *);
    +static int cksmDelete(sqlite3_vfs*, const char *zName, int syncDir);
    +static int cksmAccess(sqlite3_vfs*, const char *zName, int flags, int *);
    +static int cksmFullPathname(sqlite3_vfs*, const char *zName, int, char *zOut);
    +static void *cksmDlOpen(sqlite3_vfs*, const char *zFilename);
    +static void cksmDlError(sqlite3_vfs*, int nByte, char *zErrMsg);
    +static void (*cksmDlSym(sqlite3_vfs *pVfs, void *p, const char*zSym))(void);
    +static void cksmDlClose(sqlite3_vfs*, void*);
    +static int cksmRandomness(sqlite3_vfs*, int nByte, char *zOut);
    +static int cksmSleep(sqlite3_vfs*, int microseconds);
    +static int cksmCurrentTime(sqlite3_vfs*, double*);
    +static int cksmGetLastError(sqlite3_vfs*, int, char *);
    +static int cksmCurrentTimeInt64(sqlite3_vfs*, sqlite3_int64*);
    +static int cksmSetSystemCall(sqlite3_vfs*, const char*,sqlite3_syscall_ptr);
    +static sqlite3_syscall_ptr cksmGetSystemCall(sqlite3_vfs*, const char *z);
    +static const char *cksmNextSystemCall(sqlite3_vfs*, const char *zName);
    +
    +static sqlite3_vfs cksm_vfs = {
    +  3,                            /* iVersion (set when registered) */
    +  0,                            /* szOsFile (set when registered) */
    +  1024,                         /* mxPathname */
    +  0,                            /* pNext */
    +  "cksmvfs",                    /* zName */
    +  0,                            /* pAppData (set when registered) */ 
    +  cksmOpen,                     /* xOpen */
    +  cksmDelete,                   /* xDelete */
    +  cksmAccess,                   /* xAccess */
    +  cksmFullPathname,             /* xFullPathname */
    +  cksmDlOpen,                   /* xDlOpen */
    +  cksmDlError,                  /* xDlError */
    +  cksmDlSym,                    /* xDlSym */
    +  cksmDlClose,                  /* xDlClose */
    +  cksmRandomness,               /* xRandomness */
    +  cksmSleep,                    /* xSleep */
    +  cksmCurrentTime,              /* xCurrentTime */
    +  cksmGetLastError,             /* xGetLastError */
    +  cksmCurrentTimeInt64,         /* xCurrentTimeInt64 */
    +  cksmSetSystemCall,            /* xSetSystemCall */
    +  cksmGetSystemCall,            /* xGetSystemCall */
    +  cksmNextSystemCall            /* xNextSystemCall */
    +};
    +
    +static const sqlite3_io_methods cksm_io_methods = {
    +  3,                              /* iVersion */
    +  cksmClose,                      /* xClose */
    +  cksmRead,                       /* xRead */
    +  cksmWrite,                      /* xWrite */
    +  cksmTruncate,                   /* xTruncate */
    +  cksmSync,                       /* xSync */
    +  cksmFileSize,                   /* xFileSize */
    +  cksmLock,                       /* xLock */
    +  cksmUnlock,                     /* xUnlock */
    +  cksmCheckReservedLock,          /* xCheckReservedLock */
    +  cksmFileControl,                /* xFileControl */
    +  cksmSectorSize,                 /* xSectorSize */
    +  cksmDeviceCharacteristics,      /* xDeviceCharacteristics */
    +  cksmShmMap,                     /* xShmMap */
    +  cksmShmLock,                    /* xShmLock */
    +  cksmShmBarrier,                 /* xShmBarrier */
    +  cksmShmUnmap,                   /* xShmUnmap */
    +  cksmFetch,                      /* xFetch */
    +  cksmUnfetch                     /* xUnfetch */
    +};
    +
    +/* Do byte swapping on a unsigned 32-bit integer */
    +#define BYTESWAP32(x) ( \
    +    (((x)&0x000000FF)<<24) + (((x)&0x0000FF00)<<8)  \
    +  + (((x)&0x00FF0000)>>8)  + (((x)&0xFF000000)>>24) \
    +)
    +
    +/* Compute a checksum on a buffer */
    +static void cksmCompute(
    +  u8 *a,           /* Content to be checksummed */
    +  int nByte,       /* Bytes of content in a[].  Must be a multiple of 8. */
    +  u8 *aOut         /* OUT: Final 8-byte checksum value output */
    +){
    +  u32 s1 = 0, s2 = 0;
    +  u32 *aData = (u32*)a;
    +  u32 *aEnd = (u32*)&a[nByte];
    +  u32 x = 1;
    +
    +  assert( nByte>=8 );
    +  assert( (nByte&0x00000007)==0 );
    +  assert( nByte<=65536 );
    +
    +  if( 1 == *(u8*)&x ){
    +    /* Little-endian */
    +    do {
    +      s1 += *aData++ + s2;
    +      s2 += *aData++ + s1;
    +    }while( aData65536 || (nByte & (nByte-1))!=0 ) return;
    +  cksmCompute(data, nByte-8, cksum);
    +  sqlite3_result_int(context, memcmp(data+nByte-8,cksum,8)==0);
    +}
    +
    +/*
    +** Close a cksm-file.
    +*/
    +static int cksmClose(sqlite3_file *pFile){
    +  CksmFile *p = (CksmFile *)pFile;
    +  if( p->pPartner ){
    +    assert( p->pPartner->pPartner==p );
    +    p->pPartner->pPartner = 0;
    +    p->pPartner = 0;
    +  }
    +  pFile = ORIGFILE(pFile);
    +  return pFile->pMethods->xClose(pFile);
    +}
    +
    +/*
    +** Set the computeCkSm and verifyCksm flags, if they need to be
    +** changed.
    +*/
    +static void cksmSetFlags(CksmFile *p, int hasCorrectReserveSize){
    +  if( hasCorrectReserveSize!=p->computeCksm ){
    +    p->computeCksm = p->verifyCksm = hasCorrectReserveSize;
    +    if( p->pPartner ){
    +      p->pPartner->verifyCksm = hasCorrectReserveSize;
    +      p->pPartner->computeCksm = hasCorrectReserveSize;
    +    }
    +  }
    +}
    +
    +/*
    +** Read data from a cksm-file.
    +*/
    +static int cksmRead(
    +  sqlite3_file *pFile, 
    +  void *zBuf, 
    +  int iAmt, 
    +  sqlite_int64 iOfst
    +){
    +  int rc;
    +  CksmFile *p = (CksmFile *)pFile;
    +  pFile = ORIGFILE(pFile);
    +  rc = pFile->pMethods->xRead(pFile, zBuf, iAmt, iOfst);
    +  if( rc==SQLITE_OK ){
    +    if( iOfst==0 && iAmt>=100 && memcmp(zBuf,"SQLite format 3",16)==0 ){
    +      u8 *d = (u8*)zBuf;
    +      char hasCorrectReserveSize = (d[20]==8);
    +      cksmSetFlags(p, hasCorrectReserveSize);
    +    }
    +    /* Verify the checksum if
    +    **    (1) the size indicates that we are dealing with a complete
    +    **        database page
    +    **    (2) checksum verification is enabled
    +    **    (3) we are not in the middle of checkpoint
    +    */
    +    if( iAmt>=512           /* (1) */
    +     && p->verifyCksm       /* (2) */
    +     && !p->inCkpt          /* (3) */
    +    ){
    +      u8 cksum[8];
    +      cksmCompute((u8*)zBuf, iAmt-8, cksum);
    +      if( memcmp((u8*)zBuf+iAmt-8, cksum, 8)!=0 ){
    +        sqlite3_log(SQLITE_IOERR_DATA,
    +           "checksum fault offset %lld of \"%s\"",
    +           iOfst, p->zFName);
    +        rc = SQLITE_IOERR_DATA;
    +      }
    +    }
    +  }
    +  return rc;
    +}
    +
    +/*
    +** Write data to a cksm-file.
    +*/
    +static int cksmWrite(
    +  sqlite3_file *pFile,
    +  const void *zBuf,
    +  int iAmt,
    +  sqlite_int64 iOfst
    +){
    +  CksmFile *p = (CksmFile *)pFile;
    +  pFile = ORIGFILE(pFile);
    +  if( iOfst==0 && iAmt>=100 && memcmp(zBuf,"SQLite format 3",16)==0 ){
    +    u8 *d = (u8*)zBuf;
    +    char hasCorrectReserveSize = (d[20]==8);
    +    cksmSetFlags(p, hasCorrectReserveSize);
    +  }
    +  /* If the write size is appropriate for a database page and if
    +  ** checksums where ever enabled, then it will be safe to compute
    +  ** the checksums.  The reserve byte size might have increased, but
    +  ** it will never decrease.  And because it cannot decrease, the
    +  ** checksum will not overwrite anything.
    +  */
    +  if( iAmt>=512
    +   && p->computeCksm
    +   && !p->inCkpt
    +  ){
    +    cksmCompute((u8*)zBuf, iAmt-8, ((u8*)zBuf)+iAmt-8);
    +  }
    +  return pFile->pMethods->xWrite(pFile, zBuf, iAmt, iOfst);
    +}
    +
    +/*
    +** Truncate a cksm-file.
    +*/
    +static int cksmTruncate(sqlite3_file *pFile, sqlite_int64 size){
    +  pFile = ORIGFILE(pFile);
    +  return pFile->pMethods->xTruncate(pFile, size);
    +}
    +
    +/*
    +** Sync a cksm-file.
    +*/
    +static int cksmSync(sqlite3_file *pFile, int flags){
    +  pFile = ORIGFILE(pFile);
    +  return pFile->pMethods->xSync(pFile, flags);
    +}
    +
    +/*
    +** Return the current file-size of a cksm-file.
    +*/
    +static int cksmFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
    +  CksmFile *p = (CksmFile *)pFile;
    +  pFile = ORIGFILE(p);
    +  return pFile->pMethods->xFileSize(pFile, pSize);
    +}
    +
    +/*
    +** Lock a cksm-file.
    +*/
    +static int cksmLock(sqlite3_file *pFile, int eLock){
    +  pFile = ORIGFILE(pFile);
    +  return pFile->pMethods->xLock(pFile, eLock);
    +}
    +
    +/*
    +** Unlock a cksm-file.
    +*/
    +static int cksmUnlock(sqlite3_file *pFile, int eLock){
    +  pFile = ORIGFILE(pFile);
    +  return pFile->pMethods->xUnlock(pFile, eLock);
    +}
    +
    +/*
    +** Check if another file-handle holds a RESERVED lock on a cksm-file.
    +*/
    +static int cksmCheckReservedLock(sqlite3_file *pFile, int *pResOut){
    +  pFile = ORIGFILE(pFile);
    +  return pFile->pMethods->xCheckReservedLock(pFile, pResOut);
    +}
    +
    +/*
    +** File control method. For custom operations on a cksm-file.
    +*/
    +static int cksmFileControl(sqlite3_file *pFile, int op, void *pArg){
    +  int rc;
    +  CksmFile *p = (CksmFile*)pFile;
    +  pFile = ORIGFILE(pFile);
    +  if( op==SQLITE_FCNTL_PRAGMA ){
    +    char **azArg = (char**)pArg;
    +    assert( azArg[1]!=0 );
    +    if( sqlite3_stricmp(azArg[1],"checksum_verification")==0 ){
    +      char *zArg = azArg[2];
    +      if( zArg!=0 ){
    +        if( (zArg[0]>='1' && zArg[0]<='9')
    +         || sqlite3_strlike("enable%",zArg,0)==0
    +         || sqlite3_stricmp("yes",zArg)==0
    +         || sqlite3_stricmp("on",zArg)==0
    +        ){
    +          p->verifyCksm = p->computeCksm;
    +        }else{
    +          p->verifyCksm = 0;
    +        }
    +        if( p->pPartner ) p->pPartner->verifyCksm = p->verifyCksm;
    +      }
    +      azArg[0] = sqlite3_mprintf("%d",p->verifyCksm);
    +      return SQLITE_OK;
    +    }else if( p->computeCksm && azArg[2]!=0
    +           && sqlite3_stricmp(azArg[1], "page_size")==0 ){
    +      /* Do not allow page size changes on a checksum database */
    +      return SQLITE_OK;
    +    }
    +  }else if( op==SQLITE_FCNTL_CKPT_START || op==SQLITE_FCNTL_CKPT_DONE ){
    +    p->inCkpt = op==SQLITE_FCNTL_CKPT_START;
    +    if( p->pPartner ) p->pPartner->inCkpt = p->inCkpt;
    +  }
    +  rc = pFile->pMethods->xFileControl(pFile, op, pArg);
    +  if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
    +    *(char**)pArg = sqlite3_mprintf("cksm/%z", *(char**)pArg);
    +  }
    +  return rc;
    +}
    +
    +/*
    +** Return the sector-size in bytes for a cksm-file.
    +*/
    +static int cksmSectorSize(sqlite3_file *pFile){
    +  pFile = ORIGFILE(pFile);
    +  return pFile->pMethods->xSectorSize(pFile);
    +}
    +
    +/*
    +** Return the device characteristic flags supported by a cksm-file.
    +*/
    +static int cksmDeviceCharacteristics(sqlite3_file *pFile){
    +  pFile = ORIGFILE(pFile);
    +  return pFile->pMethods->xDeviceCharacteristics(pFile);
    +}
    +
    +/* Create a shared memory file mapping */
    +static int cksmShmMap(
    +  sqlite3_file *pFile,
    +  int iPg,
    +  int pgsz,
    +  int bExtend,
    +  void volatile **pp
    +){
    +  pFile = ORIGFILE(pFile);
    +  return pFile->pMethods->xShmMap(pFile,iPg,pgsz,bExtend,pp);
    +}
    +
    +/* Perform locking on a shared-memory segment */
    +static int cksmShmLock(sqlite3_file *pFile, int offset, int n, int flags){
    +  pFile = ORIGFILE(pFile);
    +  return pFile->pMethods->xShmLock(pFile,offset,n,flags);
    +}
    +
    +/* Memory barrier operation on shared memory */
    +static void cksmShmBarrier(sqlite3_file *pFile){
    +  pFile = ORIGFILE(pFile);
    +  pFile->pMethods->xShmBarrier(pFile);
    +}
    +
    +/* Unmap a shared memory segment */
    +static int cksmShmUnmap(sqlite3_file *pFile, int deleteFlag){
    +  pFile = ORIGFILE(pFile);
    +  return pFile->pMethods->xShmUnmap(pFile,deleteFlag);
    +}
    +
    +/* Fetch a page of a memory-mapped file */
    +static int cksmFetch(
    +  sqlite3_file *pFile,
    +  sqlite3_int64 iOfst,
    +  int iAmt,
    +  void **pp
    +){
    +  CksmFile *p = (CksmFile *)pFile;
    +  if( p->computeCksm ){
    +    *pp = 0;
    +    return SQLITE_OK;
    +  }
    +  pFile = ORIGFILE(pFile);
    +  return pFile->pMethods->xFetch(pFile, iOfst, iAmt, pp);
    +}
    +
    +/* Release a memory-mapped page */
    +static int cksmUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
    +  pFile = ORIGFILE(pFile);
    +  return pFile->pMethods->xUnfetch(pFile, iOfst, pPage);
    +}
    +
    +/*
    +** Open a cksm file handle.
    +*/
    +static int cksmOpen(
    +  sqlite3_vfs *pVfs,
    +  const char *zName,
    +  sqlite3_file *pFile,
    +  int flags,
    +  int *pOutFlags
    +){
    +  CksmFile *p;
    +  sqlite3_file *pSubFile;
    +  sqlite3_vfs *pSubVfs;
    +  int rc;
    +  pSubVfs = ORIGVFS(pVfs);
    +  if( (flags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_WAL))==0 ){
    +    return pSubVfs->xOpen(pSubVfs, zName, pFile, flags, pOutFlags);
    +  }
    +  p = (CksmFile*)pFile;
    +  memset(p, 0, sizeof(*p));
    +  pSubFile = ORIGFILE(pFile);
    +  p->base.pMethods = &cksm_io_methods;
    +  rc = pSubVfs->xOpen(pSubVfs, zName, pSubFile, flags, pOutFlags);
    +  if( rc ) goto cksm_open_done;
    +  if( flags & SQLITE_OPEN_WAL ){
    +    sqlite3_file *pDb = sqlite3_database_file_object(zName);
    +    p->pPartner = (CksmFile*)pDb;
    +    assert( p->pPartner->pPartner==0 );
    +    p->pPartner->pPartner = p;
    +    p->isWal = 1;
    +    p->computeCksm = p->pPartner->computeCksm;
    +  }else{
    +    p->isWal = 0;
    +    p->computeCksm = 0;
    +  }
    +  p->zFName = zName;
    +cksm_open_done:
    +  if( rc ) pFile->pMethods = 0;
    +  return rc;
    +}
    +
    +/*
    +** All other VFS methods are pass-thrus.
    +*/
    +static int cksmDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
    +  return ORIGVFS(pVfs)->xDelete(ORIGVFS(pVfs), zPath, dirSync);
    +}
    +static int cksmAccess(
    +  sqlite3_vfs *pVfs, 
    +  const char *zPath, 
    +  int flags, 
    +  int *pResOut
    +){
    +  return ORIGVFS(pVfs)->xAccess(ORIGVFS(pVfs), zPath, flags, pResOut);
    +}
    +static int cksmFullPathname(
    +  sqlite3_vfs *pVfs, 
    +  const char *zPath, 
    +  int nOut, 
    +  char *zOut
    +){
    +  return ORIGVFS(pVfs)->xFullPathname(ORIGVFS(pVfs),zPath,nOut,zOut);
    +}
    +static void *cksmDlOpen(sqlite3_vfs *pVfs, const char *zPath){
    +  return ORIGVFS(pVfs)->xDlOpen(ORIGVFS(pVfs), zPath);
    +}
    +static void cksmDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
    +  ORIGVFS(pVfs)->xDlError(ORIGVFS(pVfs), nByte, zErrMsg);
    +}
    +static void (*cksmDlSym(sqlite3_vfs *pVfs, void *p, const char *zSym))(void){
    +  return ORIGVFS(pVfs)->xDlSym(ORIGVFS(pVfs), p, zSym);
    +}
    +static void cksmDlClose(sqlite3_vfs *pVfs, void *pHandle){
    +  ORIGVFS(pVfs)->xDlClose(ORIGVFS(pVfs), pHandle);
    +}
    +static int cksmRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
    +  return ORIGVFS(pVfs)->xRandomness(ORIGVFS(pVfs), nByte, zBufOut);
    +}
    +static int cksmSleep(sqlite3_vfs *pVfs, int nMicro){
    +  return ORIGVFS(pVfs)->xSleep(ORIGVFS(pVfs), nMicro);
    +}
    +static int cksmCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
    +  return ORIGVFS(pVfs)->xCurrentTime(ORIGVFS(pVfs), pTimeOut);
    +}
    +static int cksmGetLastError(sqlite3_vfs *pVfs, int a, char *b){
    +  return ORIGVFS(pVfs)->xGetLastError(ORIGVFS(pVfs), a, b);
    +}
    +static int cksmCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *p){
    +  return ORIGVFS(pVfs)->xCurrentTimeInt64(ORIGVFS(pVfs), p);
    +}
    +static int cksmSetSystemCall(
    +  sqlite3_vfs *pVfs,
    +  const char *zName,
    +  sqlite3_syscall_ptr pCall
    +){
    +  return ORIGVFS(pVfs)->xSetSystemCall(ORIGVFS(pVfs),zName,pCall);
    +}
    +static sqlite3_syscall_ptr cksmGetSystemCall(
    +  sqlite3_vfs *pVfs,
    +  const char *zName
    +){
    +  return ORIGVFS(pVfs)->xGetSystemCall(ORIGVFS(pVfs),zName);
    +}
    +static const char *cksmNextSystemCall(sqlite3_vfs *pVfs, const char *zName){
    +  return ORIGVFS(pVfs)->xNextSystemCall(ORIGVFS(pVfs), zName);
    +}
    +
    +/* Register the verify_checksum() SQL function.
    +*/
    +static int cksmRegisterFunc(
    +  sqlite3 *db, 
    +  char **pzErrMsg, 
    +  const sqlite3_api_routines *pApi
    +){
    +  int rc;
    +  if( db==0 ) return SQLITE_OK;
    +  rc = sqlite3_create_function(db, "verify_checksum", 1,
    +                   SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
    +                   0, cksmVerifyFunc, 0, 0);
    +  return rc;
    +}
    +
    +/*
    +** Register the cksum VFS as the default VFS for the system.
    +** Also make arrangements to automatically register the "verify_checksum()"
    +** SQL function on each new database connection.
    +*/
    +static int cksmRegisterVfs(void){
    +  int rc = SQLITE_OK;
    +  sqlite3_vfs *pOrig;
    +  if( sqlite3_vfs_find("cksum")!=0 ) return SQLITE_OK;
    +  pOrig = sqlite3_vfs_find(0);
    +  cksm_vfs.iVersion = pOrig->iVersion;
    +  cksm_vfs.pAppData = pOrig;
    +  cksm_vfs.szOsFile = pOrig->szOsFile + sizeof(CksmFile);
    +  rc = sqlite3_vfs_register(&cksm_vfs, 1);
    +  if( rc==SQLITE_OK ){
    +    rc = sqlite3_auto_extension((void(*)(void))cksmRegisterFunc);
    +  }
    +  return rc;
    +}
    +
    +#if defined(SQLITE_CKSUMVFS_STATIC)
    +/* This variant of the initializer runs when the extension is
    +** statically linked.
    +*/
    +int sqlite3_register_cksumvfs(const char *NotUsed){
    +  (void)NotUsed;
    +  return cksmRegisterVfs();
    +}
    +#endif /* defined(SQLITE_CKSUMVFS_STATIC */
    +
    +#if !defined(SQLITE_CKSUMVFS_STATIC)
    +/* This variant of the initializer function is used when the
    +** extension is shared library to be loaded at run-time.
    +*/
    +#ifdef _WIN32
    +__declspec(dllexport)
    +#endif
    +/* 
    +** This routine is called by sqlite3_load_extension() when the
    +** extension is first loaded.
    +***/
    +int sqlite3_cksumvfs_init(
    +  sqlite3 *db, 
    +  char **pzErrMsg, 
    +  const sqlite3_api_routines *pApi
    +){
    +  int rc;
    +  SQLITE_EXTENSION_INIT2(pApi);
    +  (void)pzErrMsg; /* not used */
    +  rc = cksmRegisterFunc(db, 0, 0);
    +  if( rc==SQLITE_OK ){
    +    
    +  }
    +  if( rc==SQLITE_OK ){
    +    rc = cksmRegisterVfs();
    +  }
    +  if( rc==SQLITE_OK ) rc = SQLITE_OK_LOAD_PERMANENTLY;
    +  return rc;
    +}
    +#endif /* !defined(SQLITE_CKSUMVFS_STATIC) */
    diff --git a/ext/misc/fileio.c b/ext/misc/fileio.c
    index 1335229..d977d41 100644
    --- a/ext/misc/fileio.c
    +++ b/ext/misc/fileio.c
    @@ -394,6 +394,7 @@ static int writeFile(
     
       if( mtime>=0 ){
     #if defined(_WIN32)
    +#if !SQLITE_OS_WINRT
         /* Windows */
         FILETIME lastAccess;
         FILETIME lastWrite;
    @@ -424,6 +425,7 @@ static int writeFile(
         }else{
           return 1;
         }
    +#endif
     #elif defined(AT_FDCWD) && 0 /* utimensat() is not universally available */
         /* Recent unix */
         struct timespec times[2];
    diff --git a/ext/misc/json1.c b/ext/misc/json1.c
    index d42cad1..caf7a99 100644
    --- a/ext/misc/json1.c
    +++ b/ext/misc/json1.c
    @@ -254,6 +254,7 @@ static int jsonGrow(JsonString *p, u32 N){
     /* Append N bytes from zIn onto the end of the JsonString string.
     */
     static void jsonAppendRaw(JsonString *p, const char *zIn, u32 N){
    +  if( N==0 ) return;
       if( (N+p->nUsed >= p->nAlloc) && jsonGrow(p,N)!=0 ) return;
       memcpy(p->zBuf+p->nUsed, zIn, N);
       p->nUsed += N;
    diff --git a/ext/misc/sha1.c b/ext/misc/sha1.c
    index 0050fdf..9fe6cae 100644
    --- a/ext/misc/sha1.c
    +++ b/ext/misc/sha1.c
    @@ -381,8 +381,9 @@ int sqlite3_sha_init(
       int rc = SQLITE_OK;
       SQLITE_EXTENSION_INIT2(pApi);
       (void)pzErrMsg;  /* Unused parameter */
    -  rc = sqlite3_create_function(db, "sha1", 1, SQLITE_UTF8|SQLITE_INNOCUOUS, 0,
    -                               sha1Func, 0, 0);
    +  rc = sqlite3_create_function(db, "sha1", 1, 
    +                       SQLITE_UTF8 | SQLITE_INNOCUOUS | SQLITE_DETERMINISTIC,
    +                               0, sha1Func, 0, 0);
       if( rc==SQLITE_OK ){
         rc = sqlite3_create_function(db, "sha1_query", 1, 
                                      SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
    diff --git a/ext/misc/stmt.c b/ext/misc/stmt.c
    index d2b33e7..876b0e5 100644
    --- a/ext/misc/stmt.c
    +++ b/ext/misc/stmt.c
    @@ -168,7 +168,8 @@ static int stmtColumn(
           sqlite3_result_int(ctx, sqlite3_stmt_busy(pCur->pStmt));
           break;
         }
    -    case STMT_COLUMN_MEM: {
    +    default: {
    +      assert( i==STMT_COLUMN_MEM );
           i = SQLITE_STMTSTATUS_MEMUSED + 
                 STMT_COLUMN_NSCAN - SQLITE_STMTSTATUS_FULLSCAN_STEP;
           /* Fall thru */
    diff --git a/ext/misc/uint.c b/ext/misc/uint.c
    new file mode 100644
    index 0000000..286314f
    --- /dev/null
    +++ b/ext/misc/uint.c
    @@ -0,0 +1,92 @@
    +/*
    +** 2020-04-14
    +**
    +** The author disclaims copyright to this source code.  In place of
    +** a legal notice, here is a blessing:
    +**
    +**    May you do good and not evil.
    +**    May you find forgiveness for yourself and forgive others.
    +**    May you share freely, never taking more than you give.
    +**
    +******************************************************************************
    +**
    +** This SQLite extension implements the UINT collating sequence.
    +**
    +** UINT works like BINARY for text, except that embedded strings
    +** of digits compare in numeric order.
    +**
    +**     *   Leading zeros are handled properly, in the sense that
    +**         they do not mess of the maginitude comparison of embedded
    +**         strings of digits.  "x00123y" is equal to "x123y".
    +**
    +**     *   Only unsigned integers are recognized.  Plus and minus
    +**         signs are ignored.  Decimal points and exponential notation
    +**         are ignored.
    +**
    +**     *   Embedded integers can be of arbitrary length.  Comparison
    +**         is *not* limited integers that can be expressed as a
    +**         64-bit machine integer.
    +*/
    +#include "sqlite3ext.h"
    +SQLITE_EXTENSION_INIT1
    +#include 
    +#include 
    +#include 
    +
    +/*
    +** Compare text in lexicographic order, except strings of digits
    +** compare in numeric order.
    +*/
    +static int uintCollFunc(
    +  void *notUsed,
    +  int nKey1, const void *pKey1,
    +  int nKey2, const void *pKey2
    +){
    +  const unsigned char *zA = (const unsigned char*)pKey1;
    +  const unsigned char *zB = (const unsigned char*)pKey2;
    +  int i=0, j=0, x;
    +  (void)notUsed;
    +  while( inAux>0 ){
           break;
         }else{
    +      static const char *azFormat[] = {",%.*s REAL", ",%.*s INT"};
           pRtree->nDim2++;
    -      sqlite3_str_appendf(pSql, ",%.*s NUM", rtreeTokenLength(zArg), zArg);
    +      sqlite3_str_appendf(pSql, azFormat[eCoordType],
    +                          rtreeTokenLength(zArg), zArg);
         }
       }
       sqlite3_str_appendf(pSql, ");");
    diff --git a/ext/rtree/rtree1.test b/ext/rtree/rtree1.test
    index 447ef5d..c37a2a7 100644
    --- a/ext/rtree/rtree1.test
    +++ b/ext/rtree/rtree1.test
    @@ -716,6 +716,18 @@ do_execsql_test 18.0 {
       SELECT rt0.c1 > '-1' FROM rt0;
     } {9 1}
     
    -
     expand_all_sql db
    +
    +# 2020-02-28 ticket e63b4d1a65546532
    +reset_db
    +do_execsql_test 19.0 {
    +  CREATE VIRTUAL TABLE rt0 USING rtree(a,b,c);
    +  INSERT INTO rt0(a,b,c) VALUES(0,0.0,0.0);
    +  CREATE VIEW v0(x) AS SELECT DISTINCT rt0.b FROM rt0;
    +  SELECT v0.x FROM v0, rt0;
    +} {0.0}
    +do_execsql_test 19.1 {
    +  SELECT v0.x FROM v0, rt0 WHERE v0.x = rt0.b;
    +} {0.0}
    +
     finish_test
    diff --git a/ext/session/sessionH.test b/ext/session/sessionH.test
    index 3f5a28d..8ba2311 100644
    --- a/ext/session/sessionH.test
    +++ b/ext/session/sessionH.test
    @@ -34,5 +34,51 @@ do_test 1.0 {
       compare_db db db2
     } {}
     
    +#------------------------------------------------------------------------
    +db2 close
    +reset_db
    +
    +do_execsql_test 2.0 {
    +  CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
    +  INSERT INTO main.t1 VALUES(1, 2, 3), (4, 5, 6), (7, 8, 9);
    +}
    +
    +do_test 2.1 {
    +  sqlite3session S db main
    +  S attach *
    +  db eval {
    +    BEGIN;
    +      INSERT INTO t1 VALUES(10, 11, 12);
    +      DELETE FROM t1 WHERE a=1;
    +      UPDATE t1 SET b='five', c='six' WHERE a=4;
    +  }
    +
    +  set C [S changeset]
    +  db eval ROLLBACK
    +  S delete
    +  set {} {}
    +} {}
    +
    +do_execsql_test 2.2 {
    +  CREATE TEMP TABLE t1(a INTEGER PRIMARY KEY, b, c);
    +  INSERT INTO temp.t1 VALUES(1, 2, 3), (4, 5, 6), (7, 8, 9);
    +}
    +
    +set ::conflict [list]
    +proc xConflict {args} { lappend ::conflict $args ; return "" }
    +do_test 2.3 {
    +  sqlite3changeset_apply db $C xConflict
    +  set ::conflict
    +} {}
    +do_execsql_test 2.4 {
    +  SELECT * FROM main.t1;
    +  SELECT '****';
    +  SELECT * FROM temp.t1;
    +} {
    +  4 five six 7 8 9 10 11 12
    +  ****
    +  1 2 3 4 5 6 7 8 9
    +}
    +
     
     finish_test
    diff --git a/ext/session/sqlite3session.c b/ext/session/sqlite3session.c
    index a14172d..78cc587 100644
    --- a/ext/session/sqlite3session.c
    +++ b/ext/session/sqlite3session.c
    @@ -3513,7 +3513,7 @@ static int sessionDeleteRow(
       SessionBuffer buf = {0, 0, 0};
       int nPk = 0;
     
    -  sessionAppendStr(&buf, "DELETE FROM ", &rc);
    +  sessionAppendStr(&buf, "DELETE FROM main.", &rc);
       sessionAppendIdent(&buf, zTab, &rc);
       sessionAppendStr(&buf, " WHERE ", &rc);
     
    @@ -3596,7 +3596,7 @@ static int sessionUpdateRow(
       SessionBuffer buf = {0, 0, 0};
     
       /* Append "UPDATE tbl SET " */
    -  sessionAppendStr(&buf, "UPDATE ", &rc);
    +  sessionAppendStr(&buf, "UPDATE main.", &rc);
       sessionAppendIdent(&buf, zTab, &rc);
       sessionAppendStr(&buf, " SET ", &rc);
     
    diff --git a/main.mk b/main.mk
    index cbf14f0..654bd04 100644
    --- a/main.mk
    +++ b/main.mk
    @@ -74,7 +74,8 @@ LIBOBJ+= vdbe.o parse.o \
              table.o threads.o tokenize.o treeview.o trigger.o \
              update.o upsert.o userauth.o util.o vacuum.o \
              vdbeapi.o vdbeaux.o vdbeblob.o vdbemem.o vdbesort.o \
    -	 vdbetrace.o wal.o walker.o where.o wherecode.o whereexpr.o \
    +	 vdbetrace.o vdbevtab.o \
    +         wal.o walker.o where.o wherecode.o whereexpr.o \
              utf.o vtab.o window.o
     
     LIBOBJ += sqlite3session.o
    @@ -173,6 +174,7 @@ SRC = \
       $(TOP)/src/vdbemem.c \
       $(TOP)/src/vdbesort.c \
       $(TOP)/src/vdbetrace.c \
    +  $(TOP)/src/vdbevtab.c \
       $(TOP)/src/vdbeInt.h \
       $(TOP)/src/vtab.c \
       $(TOP)/src/vxworks.h \
    @@ -421,6 +423,7 @@ TESTSRC2 = \
       $(TOP)/src/vdbeaux.c \
       $(TOP)/src/vdbe.c \
       $(TOP)/src/vdbemem.c \
    +  $(TOP)/src/vdbevtab.c \
       $(TOP)/src/where.c \
       $(TOP)/src/wherecode.c \
       $(TOP)/src/whereexpr.c \
    @@ -526,6 +529,7 @@ SHELL_OPT += -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
     SHELL_OPT += -DSQLITE_ENABLE_STMTVTAB
     SHELL_OPT += -DSQLITE_ENABLE_DBPAGE_VTAB
     SHELL_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
    +SHELL_OPT += -DSQLITE_ENABLE_BYTECODE_VTAB
     SHELL_OPT += -DSQLITE_ENABLE_OFFSET_SQL_FUNC
     FUZZERSHELL_OPT = -DSQLITE_ENABLE_JSON1
     FUZZCHECK_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5
    @@ -536,6 +540,7 @@ FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS4
     FUZZCHECK_OPT += -DSQLITE_ENABLE_RTREE
     FUZZCHECK_OPT += -DSQLITE_ENABLE_GEOPOLY
     FUZZCHECK_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
    +FUZZCHECK_OPT += -DSQLITE_ENABLE_BYTECODE_VTAB
     DBFUZZ_OPT =
     KV_OPT = -DSQLITE_THREADSAFE=0 -DSQLITE_DIRECT_OVERFLOW_READ
     ST_OPT = -DSQLITE_THREADSAFE=0
    @@ -586,6 +591,7 @@ DBFUZZ2_OPTS = \
       -DSQLITE_ENABLE_DESERIALIZE \
       -DSQLITE_DEBUG \
       -DSQLITE_ENABLE_DBSTAT_VTAB \
    +  -DSQLITE_ENABLE_BYTECODE_VTAB \
       -DSQLITE_ENABLE_RTREE \
       -DSQLITE_ENABLE_FTS4 \
       -DSQLITE_ENABLE_FTS5
    @@ -733,6 +739,7 @@ SHELL_SRC = \
     	$(TOP)/ext/misc/fileio.c \
     	$(TOP)/ext/misc/completion.c \
     	$(TOP)/ext/misc/sqlar.c \
    +        $(TOP)/ext/misc/uint.c \
     	$(TOP)/ext/expert/sqlite3expert.c \
     	$(TOP)/ext/expert/sqlite3expert.h \
     	$(TOP)/ext/misc/zipfile.c \
    @@ -894,6 +901,7 @@ TESTFIXTURE_FLAGS += -DSQLITE_SERIES_CONSTRAINT_VERIFY=1
     TESTFIXTURE_FLAGS += -DSQLITE_DEFAULT_PAGE_SIZE=1024
     TESTFIXTURE_FLAGS += -DSQLITE_ENABLE_STMTVTAB
     TESTFIXTURE_FLAGS += -DSQLITE_ENABLE_DBPAGE_VTAB
    +TESTFIXTURE_FLAGS += -DSQLITE_ENABLE_BYTECODE_VTAB
     TESTFIXTURE_FLAGS += -DTCLSH_INIT_PROC=sqlite3TestInit
     
     testfixture$(EXE): $(TESTSRC2) libsqlite3.a $(TESTSRC) $(TOP)/src/tclsqlite.c
    diff --git a/manifest b/manifest
    index 0f0664a..dfe33d2 100644
    --- a/manifest
    +++ b/manifest
    @@ -1,11 +1,11 @@
    -C Simplify\sthe\scode\sby\sremoving\sthe\sunsupported\sand\sundocumented\s\nSQLITE_HAS_CODEC\scompile-time\soption
    -D 2020-02-07T01:12:53.927
    +C Version\s3.32.0
    +D 2020-05-22T17:46:16.912
     F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
     F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
     F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
    -F Makefile.in 9dfc7936f675785309b74d09202bb656732325e65df889e5aaa18cc8932e5b0c
    +F Makefile.in 376f53999defeb32b7ad2626fd58aae8f3694c38ab7ee30c2289e0d0525a9238
     F Makefile.linux-gcc f609543700659711fbd230eced1f01353117621dccae7b9fb70daa64236c5241
    -F Makefile.msc fab23c6b10cb6f06a7e9c407fc2e35cb184a6d653f1b793bda87fcee2eafa4f6
    +F Makefile.msc 8d00aeba2609bb498dded5eead2890126321f02e292573bf29bf2d18487d37bd
     F README.md 1514a365ffca3c138e00c5cc839906108a01011a6b082bad19b09781e3aa498a
     F VERSION 980d78a2ce04a1fd0ebefbaabd665f7f9186563820629ee29c6e350e96f19b52
     F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50
    @@ -15,7 +15,7 @@ F art/sqlite370.jpg d512473dae7e378a67e28ff96a34da7cb331def2
     F autoconf/INSTALL 83e4a25da9fd053c7b3665eaaaf7919707915903
     F autoconf/Makefile.am e14b629addaa1ce372b72043f28f40de2e32b7e211b6e0fc18dbb87989197e40
     F autoconf/Makefile.fallback 22fe523eb36dfce31e0f6349f782eb084e86a5620b2b0b4f84a2d6133f53f5ac
    -F autoconf/Makefile.msc 1d1e4af61289c62b94aa65a93afcd3dfa4b53e4195908980e0b138203e71e1c9
    +F autoconf/Makefile.msc e0f1dafc48d000fd6ddfdb01815271528db55cbc7299ca888df5b93367f0d5a4
     F autoconf/README.first 6c4f34fe115ff55d4e8dbfa3cecf04a0188292f7
     F autoconf/README.txt 4f04b0819303aabaa35fff5f7b257fb0c1ef95f1
     F autoconf/configure.ac 3cd933b959fe514eebd1ca1717dfddbf2c9b825b6bc2c5f744deaf5d63af9288
    @@ -38,7 +38,7 @@ F configure 4bbb5f13998f2faf929b9ae708aea9fbcb08a46cb6dd3150e36c3f09c0a05a75 x
     F configure.ac 798a24cee2879325ca5b688a618199eb32cc77ed8136edbaa43d9137b470d54e
     F contrib/sqlitecon.tcl 210a913ad63f9f991070821e599d600bd913e0ad
     F doc/F2FS.txt c1d4a0ae9711cfe0e1d8b019d154f1c29e0d3abfe820787ba1e9ed7691160fcd
    -F doc/lemon.html 24956ab2995e55fe171e55bdd04f22b553957dc8bb43501dbb9311e30187e0d3
    +F doc/lemon.html 857495c0ce060a4e2f2ad7111135ad7e28041a32c10612279ab398eddf678f58
     F doc/pager-invariants.txt 27fed9a70ddad2088750c4a2b493b63853da2710
     F doc/trusted-schema.md 33625008620e879c7bcfbbfa079587612c434fa094d338b08242288d358c3e8a
     F doc/vfs-shm.txt e101f27ea02a8387ce46a05be2b1a902a021d37a
    @@ -48,8 +48,8 @@ F ext/async/sqlite3async.c 0f3070cc3f5ede78f2b9361fb3b629ce200d7d74
     F ext/async/sqlite3async.h f489b080af7e72aec0e1ee6f1d98ab6cf2e4dcef
     F ext/expert/README.md b321c2762bb93c18ea102d5a5f7753a4b8bac646cb392b3b437f633caf2020c3
     F ext/expert/expert.c d548d603a4cc9e61f446cc179c120c6713511c413f82a4a32b1e1e69d3f086a4
    -F ext/expert/expert1.test e2afc53a27610e8251e44c7f961806607a5490ff204b3db342740d558e052662
    -F ext/expert/sqlite3expert.c 3da865f2286433588260f41e796422c611bceaca3a0bbf9139a619cf7d062c19
    +F ext/expert/expert1.test 2e10ff875c31c9e6fc5e324767624181273859771fe34c5daeeadf3f2974a4f7
    +F ext/expert/sqlite3expert.c ac008c72c00e6ded0f5116914d22ebd57f415fc0a7ea04738f4e9766dbdd3117
     F ext/expert/sqlite3expert.h ca81efc2679a92373a13a3e76a6138d0310e32be53d6c3bfaedabd158ea8969b
     F ext/expert/test_expert.c d56c194b769bdc90cf829a14c9ecbc1edca9c850b837a4d0b13be14095c32a72
     F ext/fts1/README.txt 20ac73b006a70bcfd80069bdaf59214b6cf1db5e
    @@ -82,16 +82,16 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51
     F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a
     F ext/fts3/README.tokenizers b92bdeb8b46503f0dd301d364efc5ef59ef9fa8e2758b8e742f39fa93a2e422d
     F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d
    -F ext/fts3/fts3.c 52c09f459364732b5df73eff0373f991fd6af8f0f60fcdbb4b649205e88a7568
    +F ext/fts3/fts3.c 45f5774987a68d36355799503b6d02dbff5286ffb42bec14d928b295d2b93c1b
     F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe
    -F ext/fts3/fts3Int.h f091030b976045e7df91af2337935952b477cdbd9f48058c44c965684484cb50
    +F ext/fts3/fts3Int.h 2c59cc46aefde134c1782e89a6a5384710ddcd4e783071337aa5d43d07269be3
     F ext/fts3/fts3_aux.c 96708c8b3a7d9b8ca1b68ea2b7e503e283f20e95f145becadedfad096dbd0f34
    -F ext/fts3/fts3_expr.c b132af223e90e35b9f9efa9fe63d6ae737d34153a3b6066736086df8abc78a1f
    +F ext/fts3/fts3_expr.c f081e38da641724cd72c20e23b71db2bf4d0c9517c14637442f6910259f11a34
     F ext/fts3/fts3_hash.c 8b6e31bfb0844c27dc6092c2620bdb1fca17ed613072db057d96952c6bdb48b7
     F ext/fts3/fts3_hash.h 39cf6874dc239d6b4e30479b1975fe5b22a3caaf
     F ext/fts3/fts3_icu.c 305ce7fb6036484085b5556a9c8e62acdc7763f0f4cdf5fd538212a9f3720116
     F ext/fts3/fts3_porter.c 3565faf04b626cddf85f03825e86056a4562c009
    -F ext/fts3/fts3_snippet.c 052b35ad746349ffb53820379bacdb23ff3ac60d3cc13d986e56d42822ef5a9a
    +F ext/fts3/fts3_snippet.c 86e7e947a176f0f005720b3ca17631aca2fd2f9daa6729d4adbf2d16ab1b9613
     F ext/fts3/fts3_term.c f45a1e7c6ef464abb1231245d123dae12266b69e05cc56e14045b76591ae92d1
     F ext/fts3/fts3_test.c 73b16e229e517c1b1f0fb8e1046182a4e5dbc8dbe6eea8a5d4353fcce7dbbf39
     F ext/fts3/fts3_tokenize_vtab.c cb792f59212f7799bf2891c7d4579bbf568f124ce8fbb0a9902aa5bd577e8b75
    @@ -100,7 +100,7 @@ F ext/fts3/fts3_tokenizer.h 64c6ef6c5272c51ebe60fc607a896e84288fcbc3
     F ext/fts3/fts3_tokenizer1.c 5c98225a53705e5ee34824087478cf477bdb7004
     F ext/fts3/fts3_unicode.c 4b9af6151c29b35ed09574937083cece7c31e911f69615e168a39677569b684d
     F ext/fts3/fts3_unicode2.c 416eb7e1e81142703520d284b768ca2751d40e31fa912cae24ba74860532bf0f
    -F ext/fts3/fts3_write.c ddf34315b6c3dce79a28d966981cc76919b18f645d82c6132133a7c65b8ed283
    +F ext/fts3/fts3_write.c ed869b24d074f2498bdbef915d6db1f88c604ca5811502112061932a0bed5133
     F ext/fts3/fts3speed.tcl b54caf6a18d38174f1a6e84219950d85e98bb1e9
     F ext/fts3/mkfts3amal.tcl 252ecb7fe6467854f2aa237bf2c390b74e71f100
     F ext/fts3/tool/fts3cov.sh c331d006359456cf6f8f953e37f2b9c7d568f3863f00bb5f7eb87fea4ac01b73
    @@ -126,7 +126,7 @@ F ext/fts5/fts5_test_tok.c f96c6e193c466711d6d7828d5f190407fe7ab897062d371426dd3
     F ext/fts5/fts5_tokenize.c 2e508c6a3bd8ee56c48e98a38052e1a650e49b32a484cce9b189984114bc3b88
     F ext/fts5/fts5_unicode2.c 8bd0cd07396b74c1a05590e4070d635bccfc849812c305619f109e6c0485e250
     F ext/fts5/fts5_varint.c e64d2113f6e1bfee0032972cffc1207b77af63319746951bf1d09885d1dadf80
    -F ext/fts5/fts5_vocab.c c3f12188570abb423303cd193b16dd19ba54e21c2e930e9b748d743de3b385f5
    +F ext/fts5/fts5_vocab.c 7a071833064dc8bca236c3c323e56aac36f583aa2c46ce916d52e31ce87462c9
     F ext/fts5/fts5parse.y eb526940f892ade5693f22ffd6c4f2702543a9059942772526eac1fde256bb05
     F ext/fts5/mkportersteps.tcl 5acf962d2e0074f701620bb5308155fa1e4a63ba
     F ext/fts5/test/fts5_common.tcl b01c584144b5064f30e6c648145a2dd6bc440841
    @@ -223,15 +223,15 @@ F ext/fts5/test/fts5unicode4.test 6463301d669f963c83988017aa354108be0b947d325aef
     F ext/fts5/test/fts5unindexed.test 9021af86a0fb9fc616f7a69a996db0116e7936d0db63892db6bafabbec21af4d
     F ext/fts5/test/fts5update.test b8affd796e45c94a4d19ad5c26606ea06065a0f162a9562d9f005b5a80ccf0bc
     F ext/fts5/test/fts5version.test c8f2cc105f0abf0224965f93e584633dee3e06c91478bc67e468f7cfdf97fd6a
    -F ext/fts5/test/fts5vocab.test 648fb2fe86b55e08295e34504704718d92fba3e2cf3e1f5d72fa3682df4cd0f0
    +F ext/fts5/test/fts5vocab.test 7ed80d9af1ddaaa1637da05e406327b5aac250848bc604c1c1cc667908b87760
     F ext/fts5/test/fts5vocab2.test e0fdc3a3095f6eda68ac9bf9a443ff929a124d46f00af19933604085712e9d47
     F ext/fts5/tool/fts5speed.tcl b0056f91a55b2d1a3684ec05729de92b042e2f85
     F ext/fts5/tool/fts5txt2db.tcl 526a9979c963f1c54fd50976a05a502e533a4c59
     F ext/fts5/tool/loadfts5.tcl 95b03429ee6b138645703c6ca192c3ac96eaf093
     F ext/fts5/tool/mkfts5c.tcl d1c2a9ab8e0ec690a52316f33dd9b1d379942f45
     F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c
    -F ext/icu/README.txt a295e91db742b153e8dce8f7efd31d28ad1eea4df31ef4daa3eedc85be2f5138
    -F ext/icu/icu.c 7adfe8a72dd4f54b47684dc9b88523399c6ef119d733b73e17371445f7428dd1
    +F ext/icu/README.txt 1c48ffaf7f255bd73d00a35f68f6de357c2a6594f16cb00506a151be23694706
    +F ext/icu/icu.c 91c021c7e3e8bbba286960810fa303295c622e323567b2e6def4ce58e4466e60
     F ext/icu/sqliteicu.h 728867a802baa5a96de7495e9689a8e01715ef37
     F ext/lsm1/Makefile a553b728bba6c11201b795188c5708915cc4290f02b7df6ba7e8c4c943fd5cd9
     F ext/lsm1/Makefile.msc f8c878b467232226de288da320e1ac71c131f5ec91e08b21f502303347260013
    @@ -285,6 +285,7 @@ F ext/misc/appendvfs.c 3777f22ec1057dc4e5fd89f2fbddcc7a29fbeef1ad038c736c54411bb
     F ext/misc/blobio.c a867c4c4617f6ec223a307ebfe0eabb45e0992f74dd47722b96f3e631c0edb2a
     F ext/misc/btreeinfo.c 26004b7a6be320ec08fc20ca8d0f01fccb00a98cbe0f3197446794ff2a506aa3
     F ext/misc/carray.c 91e9a7f512fda934894bed30464552fffa7d3073b5be04189ae0bd0c59f26bfd
    +F ext/misc/cksumvfs.c b0d07f2e1bb08f8b6f311f4e454360b6a7f0021912c326428d74900020f29c31
     F ext/misc/closure.c dbfd8543b2a017ae6b1a5843986b22ddf99ff126ec9634a2f4047cd14c85c243
     F ext/misc/completion.c a0efe03edfdc4f717c61e6c9b0bfe2708ff7878010dae3174980a68fdf76aabc
     F ext/misc/compress.c 3354c77a7c8e86e07d849916000cdac451ed96500bfb5bd83b20eb61eee012c9
    @@ -293,11 +294,11 @@ F ext/misc/dbdata.c e316fba936571584e55abd5b974a32a191727a6b746053a0c9d439bd2cf9
     F ext/misc/dbdump.c baf6e37447c9d6968417b1cd34cbedb0b0ab3f91b5329501d8a8d5be3287c336
     F ext/misc/eval.c 04bc9aada78c888394204b4ed996ab834b99726fb59603b0ee3ed6e049755dc1
     F ext/misc/explain.c d5c12962d79913ef774b297006872af1fccda388f61a11d37758f9179a09551f
    -F ext/misc/fileio.c bfa11a207da4eed8e5f84a1e3954608492f25f8850f9f00d0d2076f4648d7608
    +F ext/misc/fileio.c 9b69e25da3b51d4a1d905a464ccb96709792ad627a742ba09215bc0d1447e7bd
     F ext/misc/fossildelta.c 1240b2d3e52eab1d50c160c7fe1902a9bd210e052dc209200a750bbf885402d5
     F ext/misc/fuzzer.c eae560134f66333e9e1ca4c8ffea75df42056e2ce8456734565dbe1c2a92bf3d
     F ext/misc/ieee754.c eaffd9b364d7c8371727e9c43fc8bec38cdacc4d11fc26beffaa3ca05a0ea9d6
    -F ext/misc/json1.c 2d44e3fa37f958b42cbcd41651f9f0a0eaaf3bac3f1f4b8eb456431623cb3bd8
    +F ext/misc/json1.c 3a42e3231d716516a8ae33b0a052d3ed5f52943e3d627b68744a427a6e552ae3
     F ext/misc/memstat.c 3017a0832c645c0f8c773435620d663855f04690172316bd127270d1a7523d4d
     F ext/misc/memtrace.c 7c0d115d2ef716ad0ba632c91e05bd119cb16c1aedf3bec9f06196ead2d5537b
     F ext/misc/memvfs.c ab36f49e02ebcdf85a1e08dc4d8599ea8f343e073ac9e0bca18a98b7e1ec9567
    @@ -312,14 +313,15 @@ F ext/misc/remember.c add730f0f7e7436cd15ea3fd6a90fd83c3f706ab44169f7f048438b7d6
     F ext/misc/rot13.c 51ac5f51e9d5fd811db58a9c23c628ad5f333c173f1fc53c8491a3603d38556c
     F ext/misc/scrub.c db9fff56fed322ca587d73727c6021b11ae79ce3f31b389e1d82891d144f22ad
     F ext/misc/series.c 4057dda3579b38ff88b2d3b13b4dd92dbd9d6f90dac2b55c19b0a8ed87ee4959
    -F ext/misc/sha1.c 1190aec0d9d886d9f5ffdf891142a626812327d11472c0cade3489db3b7b140a
    +F ext/misc/sha1.c c8f2253c8792ffab9517695ea7d88c079f0395a5505eefef5c8198fe184ed5ac
     F ext/misc/shathree.c 135b7c145db4a09b1650c3e7aff9cb538763a9a361e834c015dd1aaf8d5c9a00
     F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52
     F ext/misc/spellfix.c 94df9bbfa514a563c1484f684a2df3d128a2f7209a84ca3ca100c68a0163e29f
     F ext/misc/sqlar.c c9e5d58544e1506135806a1e0f525f92d4bb6bb125348dce469d778fb334fbce
    -F ext/misc/stmt.c 8a8dc4675042e4551e4afe99b8d0cc7a4a2fc1a8dacc0a9ce1b1bbff145da93d
    +F ext/misc/stmt.c 35063044a388ead95557e4b84b89c1b93accc2f1c6ddea3f9710e8486a7af94a
     F ext/misc/templatevtab.c 8a16a91a5ceaccfcbd6aaaa56d46828806e460dd194965b3f77bf38f14b942c4
     F ext/misc/totype.c fa4aedeb07f66169005dffa8de3b0a2b621779fd44f85c103228a42afa71853b
    +F ext/misc/uint.c 053fed3bce2e89583afcd4bf804d75d659879bbcedac74d0fa9ed548839a030b
     F ext/misc/unionvtab.c 36237f0607ca954ac13a4a0e2d2ac40c33bc6e032a5f55f431713061ef1625f9
     F ext/misc/urifuncs.c f71360d14fa9e7626b563f1f781c6148109462741c5235ac63ae0f8917b9c751
     F ext/misc/uuid.c 5bb2264c1b64d163efa46509544fd7500cb8769cb7c16dd52052da8d961505cf
    @@ -384,9 +386,9 @@ F ext/repair/test/checkindex01.test b530f141413b587c9eb78ff734de6bb79bc3515c3350
     F ext/repair/test/test.tcl 686d76d888dffd021f64260abf29a55c57b2cedfa7fc69150b42b1d6119aac3c
     F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
     F ext/rtree/geopoly.c cac70b5502742bd0ba8877a1329a74e86a379c78567546a2a18cf5f9c3787f73
    -F ext/rtree/rtree.c 84b939a9a558edd0461bb976b98f60012e3e574b3b17a0f44533d6f2a9aa2f2e
    +F ext/rtree/rtree.c 0ee39cc787b95aa03a012e09e6090b0fa452154fa812af9a379898560fd6c00f
     F ext/rtree/rtree.h 4a690463901cb5e6127cf05eb8e642f127012fd5003830dbc974eca5802d9412
    -F ext/rtree/rtree1.test 4092a8bd2b5eafc4fafe4fe9024249c12b13e4bab23c2c3eaff57412fdf805fa
    +F ext/rtree/rtree1.test 00792b030a4e188ff1b22e8530e8aa0452bb5dd81c2b18cb004afc7dc63e040e
     F ext/rtree/rtree2.test 9d9deddbb16fd0c30c36e6b4fdc3ee3132d765567f0f9432ee71e1303d32603d
     F ext/rtree/rtree3.test 4ee5d7df86040efe3d8d84f141f2962a7745452200a7cba1db06f86d97050499
     F ext/rtree/rtree4.test 304de65d484540111b896827e4261815e5dca4ce28eeecd58be648cd73452c4b
    @@ -433,7 +435,7 @@ F ext/session/sessionD.test 4f91d0ca8afc4c3969c72c9f0b5ea9527e21de29039937d0d973
     F ext/session/sessionE.test b2010949c9d7415306f64e3c2072ddabc4b8250c98478d3c0c4d064bce83111d
     F ext/session/sessionF.test d37ed800881e742c208df443537bf29aa49fd56eac520d0f0c6df3e6320f3401
     F ext/session/sessionG.test 3828b944cd1285f4379340fd36f8b64c464fc84df6ff3ccbc95578fd87140b9c
    -F ext/session/sessionH.test a417559f29a7e775950fc5fc82b3d01256a7cbe793ddf1180df234df823d56e2
    +F ext/session/sessionH.test b17afdbd3b8f17e9bab91e235acf167cf35485db2ab2df0ea8893fbb914741a4
     F ext/session/session_common.tcl 29ec9910aca1e996ca1c8531b8cecabf96eb576aa53de65a8ff03d848b9a2a8b
     F ext/session/session_speed_test.c dcf0ef58d76b70c8fbd9eab3be77cf9deb8bc1638fed8be518b62d6cbdef88b3
     F ext/session/sessionat.test efe88965e74ff1bc2af9c310b28358c02d420c1fb2705cc7a28f0c1cc142c3ec
    @@ -444,7 +446,7 @@ F ext/session/sessioninvert.test ae1a003a9ab1f8d64227dbb5c3a4c97e65b561b01e7b295
     F ext/session/sessionrebase.test ccfa716b23bd1d3b03217ee58cfd90c78d4b99f53e6a9a2f05e82363b9142810
     F ext/session/sessionstat1.test 218d351cf9fcd6648f125a26b607b140310160184723c2666091b54450a68fb5
     F ext/session/sessionwor.test 67b5ab91d4f93ce65ff1f58240ac5ddf73f8670facc1ffa49cef56293d52818d
    -F ext/session/sqlite3session.c a4dfb372f270df93422b0dc7666fd46849e6979b62a152f11287c21eed4ac21b
    +F ext/session/sqlite3session.c e25b345896fa3646ff8b6c4058b3d9e365dc7eab4afe80b110808681098551c8
     F ext/session/sqlite3session.h a2db5b72b938d12c727b4b4ec632254ca493670a9c0de597af3271a7f774fc57
     F ext/session/test_session.c 98797aba475a799376c9a42214f2d1debf2d0c3cb657d9c8bbf4f70bf3fb4aec
     F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3
    @@ -453,7 +455,7 @@ F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865
     F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
     F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
     F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60
    -F main.mk 7ce055f3df31a4f7d21e38f493f907c21db1f673863a573e231f55e2ab005023
    +F main.mk addd0a300e90ad090dc4a934df8a6f1b6c52c057a1aebb93682aed29fb68a345
     F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83
     F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271
     F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504
    @@ -465,44 +467,44 @@ F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca
     F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
     F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786
     F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
    -F src/alter.c f48a4423c8f198d7f1ae4940f74b606707d05384ac79fb219be8e3323af2a2de
    -F src/analyze.c b3ceec3fc052df8a96ca8a8c858d455dc5029ba681b4be98bb5c5a9162cfa58c
    -F src/attach.c fee2f4279474edad2df73f38ff17d8b6b250429c6e9b59a708fb48a090f3ad32
    +F src/alter.c 826bc4561456094cf758f095776026f25892a2bb3a7cd86742323267dc9bdb5f
    +F src/analyze.c 953a6c43870ccaf080597244e1eeb4dc2ff6cb84f9501b24e46323de36970b61
    +F src/attach.c ff2daea0fe62080192e3f262670e4f61f5a86c1e7bea9cec34e960fe79852aa1
     F src/auth.c a3d5bfdba83d25abed1013a8c7a5f204e2e29b0c25242a56bc02bb0c07bf1e06
    -F src/backup.c 5e617c087f1c2d6005c2ec694ce80d6e16bc68d906e1b1c556d7c7c2228b636b
    +F src/backup.c b1c90cd4110248c8e1273ff4578d3a84c0c34725e1b96dacd4a6294a908702de
     F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33
     F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6
    -F src/btree.c 7cc1fb4086847a9089d78ebc3e52f5437d4aed20fc7d2da13219cba9fd5a8c8d
    -F src/btree.h 6111552f19ed7a40f029cf4b33badc6fef9880314fffd80a945f0b7f43ab7471
    -F src/btreeInt.h dee1a1d0c621524e006bb260bd6b66d5d1867da6fe38cba9ad7b6a9bb9c0c175
    -F src/build.c 2394d2c853088106dfc1cf485d609f20e6421d7c84892b795824e454f78e50ad
    -F src/callback.c c547d00963ae28100117b4fb1f0f32242109b5804374ee3bfe01138a54da7f76
    +F src/btree.c f14e415fcfd0b52b4e4ebd193ba5fadac5e8252c30f023389af682813af44025
    +F src/btree.h 989ef3c33413549e3e148f3dcb46c030f317dac130dc86809ba6b9aa4b16c72a
    +F src/btreeInt.h 5c8b8749805787313ecf49eb5be3ced1e94bbf8ef54bb01470ce6bd0d5185c67
    +F src/build.c ca9e7a33b74f1bf2eb3a5f37f9d07dfed335469f2d70c0bd350e0dd42a50183a
    +F src/callback.c d0b853dd413255d2e337b34545e54d888ea02f20da5ad0e63585b389624c4a6c
     F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
    -F src/ctime.c 6a77ec9e0eb87aea929e002c816298907e337094a7b556898ae2d1e6be209f90
    -F src/date.c 6c408fdd2e9ddf6e8431aba76315a2d061bea2cec8fbb75e25d7c1ba08274712
    +F src/ctime.c e98518d2d3d4029a13c805e07313fb60c877be56db76e90dd5f3af73085d0ce6
    +F src/date.c b29b349d277e3d579dcc295b24c0a2caed83fd8f090a9f7cbe6070c0fd662384
     F src/dbpage.c 8a01e865bf8bc6d7b1844b4314443a6436c07c3efe1d488ed89e81719047833a
    -F src/dbstat.c 0f55297469d4244ab7df395849e1af98eb5e95816af7c661e7d2d8402dea23da
    -F src/delete.c a5c59b9c0251cf7682bc52af0d64f09b1aefc6781a63592c8f1136f7b73c66e4
    -F src/expr.c 6617ca8d4cc808b82348ae0c2844000b665de86aacc60fa0524f1b29b1918921
    +F src/dbstat.c 793deaf88a0904f88285d93d6713c636d55ede0ffd9f08d10f4ea825531d367f
    +F src/delete.c 88047c8e59878c920fce14582bc1dde4d81157d1ca5ffdf36c2907e6d41996c4
    +F src/expr.c 8eed44d9de8a3b0fe1c9809bb75a02b65488774c8ba8685512d8f63adade18e5
     F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
    -F src/fkey.c 92a248ec0fa4ed8ab60c98d9b188ce173aaf218f32e7737ba77deb2a684f9847
    -F src/func.c 108577cebe8a50c86d849a93b99493a54e348dd0b846f00d13b52ca973d5baf4
    +F src/fkey.c 4b575423b0a5d4898b1a7868ce985cf1a8ad91c741c9abbb108ff02536d20f41
    +F src/func.c 2333eb4277f55a5efdc12ef754e7d7ec9105d257b2fd00301d23ce1e8fa67dc0
     F src/global.c 79a988b56b06ce2d08ebefe1d35da9aa25b3851faa47ea5233361c4827185a64
     F src/hash.c 8d7dda241d0ebdafb6ffdeda3149a412d7df75102cecfc1021c98d6219823b19
     F src/hash.h 9d56a9079d523b648774c1784b74b89bd93fac7b365210157482e4319a468f38
     F src/hwtime.h cb1d7e3e1ed94b7aa6fde95ae2c2daccc3df826be26fc9ed7fd90d1750ae6144
     F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
    -F src/insert.c 9b487eb4b756a2bab16fa5ba19d207375551f7d0b8da3f4dff769f3035dc6bab
    +F src/insert.c 8e4211d04eb460c0694d486c6ba1c068d468c6f653c3f237869a802ad82854de
     F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
    -F src/loadext.c 8cd803f1747c03a50b32fe87ebfb5851998d0cdafefe02737daa95e0616b42bb
    -F src/main.c 12d42b43c331778f6e3a1ebc57b63470f1951350efbea377e03cac6660e03b57
    -F src/malloc.c eaa4dc9602ce28b077f7de2eb275db2be270c5cc56d7fec5466301bd9b80e2f5
    +F src/loadext.c 421310045bd78afefb772294a99e50f37d87ae578786a6169074e6291e30d969
    +F src/main.c 97d962ab1f830540043042e41085c5b85636a60e6ed95002c1a56b64f7eb6a0b
    +F src/malloc.c d0400b0366e1a3a2414ca4534b4a7406df34732835f37a15cb4642eb7df1a363
     F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
     F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de
     F src/mem2.c f1940d9e91948dd6a908fbb9ce3835c36b5d83c3
     F src/mem3.c 8768ac94694f31ffaf8b4d0ea5dc08af7010a35a
     F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944
    -F src/memdb.c 02a5fcec19b9d40dd449ca802dc1b2e8f93f255fbf2a886277a3c3800d8d35db
    +F src/memdb.c 252137ca122acb8f54a99b48cf9f96a31d5130f19d174381a53294446d8b64a3
     F src/memjournal.c 7561c01c90958f3ba9bc6cb2d857123d932bdfa5539ea34427a0957b2e35154d
     F src/msvc.h 3a15918220367a8876be3fa4f2abe423a861491e84b864fb2b7426bf022a28f8
     F src/mutex.c 5e3409715552348732e97b9194abe92fdfcd934cfb681df4ba0ab87ac6c18d25
    @@ -515,32 +517,32 @@ F src/os.c 669cc3839cc35d20f81faf0be1ab6d4581cea35e9d8f3a9d48a98d6571f7c285
     F src/os.h 48388821692e87da174ea198bf96b1b2d9d83be5dfc908f673ee21fafbe0d432
     F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85
     F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586
    -F src/os_unix.c ad7640c04eed946052a3b12856362a773d0a717696707313037186df0e2b59f2
    -F src/os_win.c 035a813cbd17f355bdcad7ab894af214a9c13a1db8aeac902365350b98cd45a7
    +F src/os_unix.c 13f983da988b6460ef3c4c22099c67ab0938291e543644ac4d99eccc8ba604f1
    +F src/os_win.c e832e21e830c1f9409c9c54053939b6dcb14c1e92128b756204ce1e3e331d678
     F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a
    -F src/pager.c b1e79698f3903e64d7a8ab5f4b3163aa39ed25686289a68de20b6b5734de70e6
    -F src/pager.h 3b33619a90180e0874c7eca31d6f6ceb464d9322c6fb4e9a7bbb318c8a17bdb3
    -F src/parse.y 61ae75b1764c86f56fdfe384d736e4ba9b0d54015a5ca61925d8cb6b94943d4c
    +F src/pager.c 96436cb1920074d4ade120a1a8a9d0ae3f52df06651e21b7eccc5eae2f02b111
    +F src/pager.h 8d1dc9a2c3fc5eb6eeed75f48a076f425e77706f8935f05817fa05a308f587b5
    +F src/parse.y c8eff38606f443d5ba245263fa7abc05e4116d95656e050c4b78e9bfbf931add
     F src/pcache.c 385ff064bca69789d199a98e2169445dc16e4291fa807babd61d4890c3b34177
     F src/pcache.h 4f87acd914cef5016fae3030343540d75f5b85a1877eed1a2a19b9f284248586
     F src/pcache1.c 6596e10baf3d8f84cc1585d226cf1ab26564a5f5caf85a15757a281ff977d51a
    -F src/pragma.c 4c8f3665cb3e1b114d22319f944a0c73c9563869c1f01a322732a880a7a2f82a
    -F src/pragma.h 9473160d220416456b40f27323bb4b316d4e4e08ffbf8bf88c5f7045d49c38e5
    -F src/prepare.c 6049beb71385f017af6fc320d2c75a4e50b75e280c54232442b785fbb83df057
    -F src/printf.c 9be6945837c839ba57837b4bc3af349eba630920fa5532aa518816defe42a7d4
    +F src/pragma.c 1b0db48177e52b256c003b8dc6ac708b1079a82cded944a23820574586a4731f
    +F src/pragma.h 8168e588536bffd95319451f34e9a754dc37d205ebe433031a7813c5b286beae
    +F src/prepare.c 8d4d6c8aa6afefc48027c54b41cdf134b4d6bc2fc4badbe483ad7fd9e1728a28
    +F src/printf.c ebf563cff3122f6a61149964b738b470196d3619df31d6a720d0ff72fcfd7c7b
     F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
    -F src/resolve.c f0781c9e180028b279bc4ff079ad54f4727223d470c8d2343643fcaf79b67740
    -F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93
    -F src/select.c 3f7aecf64b08b018b89e4fe16ea621cc9a0e3f3801e9e5638cfe1a6035fa1581
    -F src/shell.c.in c2e20c43a44fb5588a6c27ce60589538fbf4794fd7686f5b2598eca22eaae1fa
    -F src/sqlite.h.in 572ea78b08ee90529d7588cea966c350afbf9624fdf133378edb346a233c6625
    +F src/resolve.c d36a2b1639e1c33d7b508abfd3452a63e7fd81737f6f3940bfef085fca6f21f4
    +F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
    +F src/select.c ee4b02ad8047c35891b7a612091beec21ae7a0155290dcbefb0824aed20c46f3
    +F src/shell.c.in cf2d24f54412c06e5fb34af7fabc748651125e1dceac29b740e91f06d23447b6
    +F src/sqlite.h.in 74342b41e9d68ff9e56b192009046f8dd0aa2bd76ce1a588f330de614ba61de7
     F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
    -F src/sqlite3ext.h 27951f294f29cd875c6027f2707d644ef99f469bd97514568b5a8581a114db8c
    -F src/sqliteInt.h ce2038197482723e6da107447d95e4d3a1afcfd630c955b6abef5dc9ff597567
    -F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b
    +F src/sqlite3ext.h 2d1af80082edffd71c6f96f70ad1ce6a4fb46615ad10291fc77fe0dea9ff0197
    +F src/sqliteInt.h 8878a88c18a013d1843638001d7fc56a8f99740f151fc7597b1641b61accf58c
    +F src/sqliteLimit.h 95cb8479ca459496d9c1c6a9f76b38aee12203a56ce1092fe13e50ae2454c032
     F src/status.c 9ff2210207c6c3b4d9631a8241a7d45ab1b26a0e9c84cb07a9b5ce2de9a3b278
    -F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34
    -F src/tclsqlite.c d0aa320416efe88c4dbb0156ed6c494f2f9958871a940e46984ee57b3e7fcc50
    +F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1
    +F src/tclsqlite.c 986b6391f02cd9b53c1d688be55899f6ffddeb8e8014cd83c1b73ff912579a71
     F src/test1.c 5e8b8cc54e8c88906ea8a084387aa79bad245e539f4cee73149e5c0527e1db16
     F src/test2.c 3efb99ab7f1fc8d154933e02ae1378bac9637da5
     F src/test3.c 61798bb0d38b915067a8c8e03f5a534b431181f802659a6616f9b4ff7d872644
    @@ -570,7 +572,7 @@ F src/test_journal.c a0b9709b2f12b1ec819eea8a1176f283bca6d688a6d4a502bd6fd79786f
     F src/test_loadext.c 337056bae59f80b9eb00ba82088b39d0f4fe6dfd
     F src/test_malloc.c dec0aa821b230773aeb3dd11d652c1193f7cedb18a20b25659bc672288115242
     F src/test_md5.c 7268e1e8c399d4a5e181b64ac20e1e6f3bc4dd9fc87abac02db145a3d951fa8c
    -F src/test_multiplex.c e5fac104a0eebf935e6732cda6abce79ea0b4b10949518d5dac7b0293173a40f
    +F src/test_multiplex.c 46e278397bef99b10530c1a695b4f6f23823fde6d6589b182f14e9bd43440b57
     F src/test_multiplex.h 5436d03f2d0501d04f3ed50a75819e190495b635
     F src/test_mutex.c 7f4337ba23ee6b1d2ec81c189653608cb069926a
     F src/test_onefile.c f31e52e891c5fef6709b9fcef54ce660648a34172423a9cbdf4cbce3ba0049f4
    @@ -595,33 +597,34 @@ F src/test_windirent.h 90dfbe95442c9762357fe128dc7ae3dc199d006de93eb33ba3972e0a9
     F src/test_window.c cdae419fdcea5bad6dcd9368c685abdad6deb59e9fc8b84b153de513d394ba3f
     F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
     F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c
    -F src/tokenize.c 7b17f6e2f20f6cbcb0b215025a86b7457c38451fc7622f705e553d7a488c572d
    -F src/treeview.c 438c1000587b33faba35e87596bebcf7f40638d98f33781cdd9e04711b18b09c
    -F src/trigger.c a40d50e88bd3355f1d2a73f0a3b2d6b42eae26ca4219001b82ef0d064439badc
    -F src/update.c 9ad19af96aff95dc02a923a99f97c1bc0b909009a29a2914b796f786b9ac0c60
    +F src/tokenize.c eee7bae3ec0bc4abee951554bf46a8ba567c0f7752ac90c820ed8afff4c612dc
    +F src/treeview.c 82c6391a3ba76215d4185fd4719a56ec4caf186a40c8a7b6e6ba4ae4467c2742
    +F src/trigger.c 4ada1037cc99777f647a882cdacbd1a4deb6567b69daf02946286401b88cdc04
    +F src/update.c 3199098455830fc2d8c8fc4ae3ec2ea513eef64339ae9a7048db62b21169bc7a
     F src/upsert.c 2920de71b20f04fe25eb00b655d086f0ba60ea133c59d7fa3325c49838818e78
    -F src/utf.c 736ff76753236ffbc8b5b939f5e0607f28aeaa7c780b3a56b419228f0a81c87b
    -F src/util.c a285c1e026907b69fa2592bd05047a565a1d8a1aef2b73c924b6a8ffe772871a
    -F src/vacuum.c 813b510ba887fee6492bcb11f2bf77d7eb58b232b83649136372e0a2fc17f4b9
    -F src/vdbe.c 15cae95de3c1301747f7ee17a70046772741e7e630b6d5554c685b613798b8e8
    -F src/vdbe.h defd693289c7bb8d325f109be9490c77138061211a116827da7244b6015a4934
    -F src/vdbeInt.h a17146053a1aa438474012998fe07e314f3df274a61491ad838ad85d848ac051
    -F src/vdbeapi.c 1252d80c548711e47a6d84dae88ed4e95d3fbb4e7bd0eaa1347299af7efddf02
    -F src/vdbeaux.c eaf1df6465f410e69330864bfc152458208f9bb2edd99930432ae342662d2ecd
    +F src/utf.c d7a61c1dfdac3eb091d43341a674032dca5a34e122f78ef0b5bd2d5a31967dde
    +F src/util.c 3b6cedf7a0c69bd6e1acce832873952d416212d6293b18d03064e07d7a9b5118
    +F src/vacuum.c de9780b89fa4ee74c3534f60b94820e3179aca759ffc1338ee53cb4ea7693dd3
    +F src/vdbe.c e3dba0dee25bc92e871c13cac655260912b3be4abcc85b439259c9934b208da3
    +F src/vdbe.h 07b8c636a87df8b6e58f29d6badd7f10d5844353deff1d7c88ed1c2bfe3bbd35
    +F src/vdbeInt.h 571413068b5ac07e2ed8ca7a02fa529622fd5455ae6981498376e5e492d2e5ef
    +F src/vdbeapi.c e467b75a710ea099f8d2d022abf601d2ccd05e28f63b44b12d93000b6a75f4a8
    +F src/vdbeaux.c 80626786d21296d9e7936186850343afe5fc6368ad9724a172e151788425a063
     F src/vdbeblob.c 253ed82894924c362a7fa3079551d3554cd1cdace39aa833da77d3bc67e7c1b1
    -F src/vdbemem.c ff2a1fd86ea943efb7174bd74bc661815c449be6165e136e8849e1dc59e24353
    +F src/vdbemem.c 39b942ecca179f4f30a32b54579a85d74ccaefa5af2a0ad2700abe5ef0768b22
     F src/vdbesort.c 2be76d26998ce2b3324cdcc9f6443728e54b6c7677c553ad909c7d7cfab587df
     F src/vdbetrace.c fa3bf238002f0bbbdfb66cc8afb0cea284ff9f148d6439bc1f6f2b4c3b7143f0
    -F src/vtab.c 7b704a90515a239c6cdba6a66b1bb3a385e62326cceb5ecb05ec7a091d6b8515
    +F src/vdbevtab.c ee5b4c902fdda2230f9503ac7b84c6d614c91e8f6f4dc1633e2e8dfef8ffb144
    +F src/vtab.c 7b452592ed2ee95dedb1f323d557cebede5a6f3b4558b21a5dca527e6ae9b12c
     F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
    -F src/wal.c 697424314e40d99f93f548c7bfa526c10e87f4bdf64d5a76a96b999dd7133ebc
    -F src/wal.h 606292549f5a7be50b6227bd685fa76e3a4affad71bb8ac5ce4cb5c79f6a176a
    -F src/walker.c a137468bf36c92e64d2275caa80c83902e3a0fc59273591b96c6416d3253d05d
    -F src/where.c 2005d0511e05e5f7b6fb3be514b44f264f23d45f3b0cc5e150c63e3006a003e5
    -F src/whereInt.h 9157228db086f436a574589f8cc5749bd971e94017c552305ad9ec472ed2e098
    -F src/wherecode.c f5df56e395ade2240cabb2d39500c681bd29f8cc0636c3301c4996ad160df94d
    -F src/whereexpr.c 4b34be1434183e7bb8a05d4bf42bd53ea53021b0b060936fbd12062b4ff6b396
    -F src/window.c f8ba2ee12a19b51d3ba42c16277c74185ee9215306bc0d5a03974ade8b5bc98f
    +F src/wal.c 17ea0a319d3ead17ef3b16aa30f10f2626056893effea7e609a20a6661ffec1b
    +F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a
    +F src/walker.c 7c429c694abd12413a5c17aec9f47cfe9eba6807e6b0a32df883e8e3a14835ed
    +F src/where.c 9546c82056e8cdb27291f98cf1adca5d271240b399bb97b32f77fc2bea6146c9
    +F src/whereInt.h 6b874aa15f94e43a2cec1080be64d955b04deeafeac90ffb5d6975c0d511be3c
    +F src/wherecode.c 7b939de85d65cc4b4bfa197513136b9e0ae03167e3b82842ca5a0ba1055ba65d
    +F src/whereexpr.c 264d58971eaf8256eb5b0917bcd7fc7a1f1109fdda183a8382308a1b18a2dce7
    +F src/window.c 194fc168626f186a2b90dfe5edb534ab164cbeb6c4906177bfcdd5c188a0b53d
     F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
     F test/affinity2.test ce1aafc86e110685b324e9a763eab4f2a73f737842ec3b687bd965867de90627
     F test/affinity3.test 6a101af2fc945ce2912f6fe54dd646018551710d
    @@ -629,17 +632,17 @@ F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
     F test/aggnested.test 12106f0748e8e9bfc1a8e6840e203e051eae06a26ed13fc9fd5db108a8d6db54
     F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87
     F test/all.test 2ecb8bbd52416642e41c9081182a8df05d42c75637afd4488aace78cc4b69e13
    -F test/alter.test 77f0092d137dd9470fc683b64ed92868e188462e713e52f48deae8902ea60b96
    +F test/alter.test 25e109787dc5e631e117eb6e1c57f96a572bb51228db3b4f8b5f41d665e2ccaa
     F test/alter2.test a966ccfcddf9ce0a4e0e6ff1aca9e6e7948e0e242cd7e43fc091948521807687
    -F test/alter3.test 9351a9f0c59ff9dddecccaaa2f777ffee5369870c63d30d3a74add815254ec0f
    -F test/alter4.test 74b22251c5e9c48093cfc4921ed9c11b59df84634aeeb00e501773320beb8424
    +F test/alter3.test e487958dec7932453e0b83baf21d6b1e71d5e7d9a55bc20eadfa62a51ddffc29
    +F test/alter4.test dfd6086faf461b27ca2d2999848dcd207edf23352fc1592d0005c0844f3f08cf
     F test/alterauth.test 63442ba61ceb0c1eeb63aac1f4f5cebfa509d352276059d27106ae256bafc959
     F test/alterauth2.test c0a1ddf5b93d93cb0d15ba7acaf0c5c6fb515bbe861ede75b2d3fabad33b6499
     F test/altercol.test 1d6a6fe698b81e626baea4881f5717f9bc53d7d07f1cd23ee7ad1b931f117ddf
     F test/alterlegacy.test 82022721ce0de29cedc9a7af63bc9fcc078b0ee000f8283b4b6ea9c3eab2f44b
     F test/altermalloc.test 167a47de41b5c638f5f5c6efb59784002b196fff70f98d9b4ed3cd74a3fb80c9
     F test/altermalloc2.test fa7b1c1139ea39b8dec407cf1feb032ca8e0076bd429574969b619175ad0174b
    -F test/altertab.test bd61e5b73d495ec4707133db91b07f09d57e339d988de5ec5a76d34a2198e8f2
    +F test/altertab.test 523ba6368e0da19f462f7c05563c569675736d946724cac1c4ae848f76783434
     F test/altertab2.test b0d62f323ca5dab42b0bc028c52e310ebdd13e655e8fac070fe622bad7852c2b
     F test/altertab3.test 155b8dc225ce484454a7fb4c8ba745680b6fa0fc3e08919cbbc19f9309d128ff
     F test/amatch1.test b5ae7065f042b7f4c1c922933f4700add50cdb9f
    @@ -655,6 +658,7 @@ F test/analyzeC.test 489fe2ea3be3f17548e8dd895f1b41c9669b52de1b0861f5bffe6eec46e
     F test/analyzeD.test e50cd0b3e6063216cc0c88a1776e8645dc0bd65a6bb275769cbee33b7fd8d90c
     F test/analyzeE.test 8684e8ac5722fb97c251887ad97e5d496a98af1d
     F test/analyzeF.test 9e1a0537949eb5483642b1140a5c39e5b4025939024b935398471fa552f4dabb
    +F test/analyzeG.test a48c0f324dd14de9a40d52abe5ca2637f682b9a791d2523dd619f6efa14e345b
     F test/analyzer1.test 459fa02c445ddbf0101a3bad47b34290a35f2e49
     F test/async.test 1d0e056ba1bb9729283a0f22718d3a25e82c277b
     F test/async2.test c0a9bd20816d7d6a2ceca7b8c03d3d69c28ffb8b
    @@ -665,7 +669,7 @@ F test/atof1.test 1ccfc96a6888566597b83d882c81b3c04258dc39317e8c1cec89ba481eaa2f
     F test/atomic.test 065a453dde33c77ff586d91ccaa6ed419829d492dbb1a5694b8a09f3f9d7d061
     F test/atomic2.test b6863b4aa552543874f80b42fb3063f1c8c2e3d8e56b6562f00a3cc347b5c1da
     F test/atrc.c ec92d56d8fbed9eb3e11aaf1ab98cf7dd59e69dae31f128013f1d97e54e7dfed
    -F test/attach.test 21bce8681f780a8d631a5ec7ecd0d849bfe84611257b038ae4ffeccc609d8a4e
    +F test/attach.test d42862c72fef3d54367d962d41dcfb5363442a4a1bd898c22ae950cea1aa0dd3
     F test/attach2.test 256bd240da1835fb8408dd59fb7ef71f8358c7a756c46662434d11d07ba3a0ce
     F test/attach3.test c59d92791070c59272e00183b7353eeb94915976
     F test/attach4.test aa05b1d8218b24eba5a7cccf4f224f514ba57ba705c9267f09d2bb63fed0eea1
    @@ -779,7 +783,7 @@ F test/corruptK.test 5b4212fe346699831c5ad559a62c54e11c0611bdde1ea8423a091f9c01a
     F test/corruptL.test 13ef74a93223af25015d223add0df4c2d375f0b958b546a2a72033f2fdab7a70
     F test/corruptM.test 7d574320e08c1b36caa3e47262061f186367d593a7e305d35f15289cc2c3e067
     F test/cost.test 51f4fcaae6e78ad5a57096831259ed6c760e2ac6876836e91c00030fad385b34
    -F test/count.test cb2e0f934c6eb33670044520748d2ecccd46259c
    +F test/count.test e0699a15712bc2a4679d60e408921c2cce7f6365a30340e790c98e0f334a9c77
     F test/countofview.test e17d6e6688cf74f22783c9ec6e788c0790ee4fbbaee713affd00b1ac0bb39b86
     F test/coveridxscan.test 5ec98719a2e2914e8908dc75f7247d9b54a26df04625f846ac7900d5483f7296
     F test/crash.test fb9dc4a02dcba30d4aa5c2c226f98b220b2b959f
    @@ -793,10 +797,10 @@ F test/crash8.test 64366e459c28dd62edfb7ad87253a409c7533b92d16fcc479a6a8131bdcc3
     F test/crashM.test d95f59046fa749b0d0822edf18a717788c8f318d
     F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
     F test/createtab.test 85cdfdae5c3de331cd888d6c66e1aba575b47c2e3c3cc4a1d6f54140699f5165
    -F test/cse.test 277350a26264495e86b1785f34d2d0c8600e021c
    +F test/cse.test 00b3aea44b16828833c94fbe92475fd6977583fcb064ae0bc590986812b38d0c
     F test/csv01.test c9c3af0d58c34e9ac970c5875a77939edb958762c8aafb95409e19a3f088b6cd
     F test/ctime.test 78749e6c9a5f0010d67985be80788f841e3cd2da18114e2ed6010399a7d807f3
    -F test/cursorhint.test 7bc346788390475e77a345da2b92270d04d35856
    +F test/cursorhint.test 0175e4404181ace3ceca8b114eb0a98eae600d565aa4e2705abbe6614c7fe201
     F test/cursorhint2.test 6f3aa9cb19e7418967a10ec6905209bcbb5968054da855fc36c8beee9ae9c42f
     F test/dataversion1.test 6e5e86ac681f0782e766ebcb56c019ae001522d114e0e111e5ebf68ccf2a7bb8
     F test/date.test 9b73bbeb1b82d9c1f44dec5cf563bf7da58d2373
    @@ -809,7 +813,7 @@ F test/dbfuzz2.c c2c9cb40082a77b7e95ffb8b2da1e93322efadfb1c8c1e0001c95a0af1e156c
     F test/dbpage.test 650234ba683b9d82b899c6c51439819787e7609f17a0cc40e0080a7b6443bc38
     F test/dbstatus.test 4a4221a883025ffd39696b3d1b3910b928fb097d77e671351acb35f3aed42759
     F test/dbstatus2.test f5fe0afed3fa45e57cfa70d1147606c20d2ba23feac78e9a172f2fe8ab5b78ef
    -F test/default.test 3e46c421eebefd2787c2f96673efabf792d360f3a1d5073918cbe450ce672a62
    +F test/default.test 9687cfb16717e4b8238c191697c98be88c0b16e568dd5368cd9284154097ef50
     F test/delete.test 31832b0c45ecb51a54348c68db173be462985901e6ed7f403d6d7a8f70ab4ef0
     F test/delete2.test 3a03f2cca1f9a67ec469915cb8babd6485db43fa
     F test/delete3.test 555e84a00a99230b7d049d477a324a631126a6ab
    @@ -819,7 +823,7 @@ F test/descidx1.test edc8adee58d491b06c7157c50364eaf1c3605c9c19f8093cb1ea2b6184f
     F test/descidx2.test a0ba347037ff3b811f4c6ceca5fd0f9d5d72e74e59f2d9de346a9d2f6ad78298
     F test/descidx3.test 953c831df7ea219c73826dfbf2f6ee02d95040725aa88ccb4fa43d1a1999b926
     F test/diskfull.test 106391384780753ea6896b7b4f005d10e9866b6e
    -F test/distinct.test 8b6c652f0b2d477f0830884736f2a1cd2e8f7fc10a04aa6d571a401fa13ed88b
    +F test/distinct.test e7d0cf371944dd0cbedff86420744e2f1ea2b528156451c97eb6ff41a99b9236
     F test/distinct2.test 11b0594c932098e969d084ba45ab81d5040f4d4e766db65d49146705a305ed98
     F test/distinctagg.test 1a6ef9c87a58669438fc771450d7a72577417376
     F test/e_blobbytes.test 439a945953b35cb6948a552edaec4dc31fd70a05
    @@ -827,12 +831,12 @@ F test/e_blobclose.test 4b3c8c60c2171164d472059c73e9f3c1844bb66d
     F test/e_blobopen.test e95e1d40f995056f6f322cd5e1a1b83a27e1a145
     F test/e_blobwrite.test f87ff598b67af5b3ec002a8d83e804dc8d23808e88cf0080c176612fc9ffce14
     F test/e_changes.test fd66105385153dbf21fdb35eb8ef6c3e1eade579
    -F test/e_createtable.test 1c602347e73ab80b11b9fa083f47155861aaafcff8054aac9e0b76d0df33b0a7
    +F test/e_createtable.test ea27082d6f84df61e1d9e383f3fd79220418856a4a8afc41af75d458b8e7ac33
     F test/e_delete.test ab39084f26ae1f033c940b70ebdbbd523dc4962e
     F test/e_droptrigger.test 3cd080807622c13e5bbb61fc9a57bd7754da2412
    -F test/e_dropview.test 21ce09c361227ddbc9819a5608ee2700c276bdd5
    -F test/e_expr.test 328d2d7c84f8e53e942a13eac771b337bcdfcf4c3569324001868b5639f3c857
    -F test/e_fkey.test 2febb2084aef9b0186782421c07bc9d377abf067c9cb4efd49d9647ae31f5afe
    +F test/e_dropview.test 74e405df7fa0f762e0c9445b166fe03955856532e2bb234c372f7c51228d75e7
    +F test/e_expr.test 62000e6675d5bcf4b09276fe011a27779629ff8f6678ba5937fb6f1b78d645ff
    +F test/e_fkey.test b497feb7c436693e16a36cdaba8d81ffe12f23659d139ee71dfa57c0c52d1e5b
     F test/e_fts3.test 17ba7c373aba4d4f5696ba147ee23fd1a1ef70782af050e03e262ca187c5ee07
     F test/e_insert.test f02f7f17852b2163732c6611d193f84fc67bc641fb4882c77a464076e5eba80e
     F test/e_reindex.test 2b0e29344497d9a8a999453a003cb476b6b1d2eef2d6c120f83c2d3a429f3164
    @@ -848,7 +852,7 @@ F test/e_walauto.test 248af31e73c98df23476a22bdb815524c9dc3ba8
     F test/e_walckpt.test 28c371a6bb5e5fe7f31679c1df1763a19d19e8a0
     F test/e_walhook.test 01b494287ba9e60b70f6ebf3c6c62e0ffe01788e344a4846b08e5de0b344cb66
     F test/emptytable.test a38110becbdfa6325cd65cb588dca658cd885f62
    -F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea
    +F test/enc.test 9a7be5479da985381d740b15f432800f65e2c87029ee57a318f42cb2eb43763a
     F test/enc2.test 848bf05f15b011719f478dddb7b5e9aea35e39e457493cba4c4eef75d849a5ec
     F test/enc3.test 6807f7a7740a00361ca8d0ccd66bc60c8dc5f2b6
     F test/enc4.test c8f1ce3618508fd0909945beb8b8831feef2c020
    @@ -871,7 +875,7 @@ F test/filter2.tcl 44e525497ce07382915f01bd29ffd0fa49dab3adb87253b5e5103ba8f9339
     F test/filter2.test 485cf95d1f6d6ceee5632201ca52a71868599836f430cdee42e5f7f14666e30a
     F test/filterfault.test c08fb491d698e8df6c122c98f7db1c65ffcfcad2c1ab0e07fa8a5be1b34eaa8b
     F test/fkey1.test d11dbb8a93ead9b5c46ae5d02da016d61245d47662fb2d844c99214f6163f768
    -F test/fkey2.test 65c86b11127c11f80c0f450b3480321e0f087edea3031b9daa1978e3c020c91b
    +F test/fkey2.test b1b6a8c5556dc0ccf31291b1fed8aa57e404b38f3236110e19ab4dc6aa93edf2
     F test/fkey3.test 76d475c80b84ee7a5d062e56ccb6ea68882e2b49
     F test/fkey4.test 86446017011273aad8f9a99c1a65019e7bd9ca9d
     F test/fkey5.test 24dd28eb3d9f1b5a174f47e9899ace5facb08373a4223593c8c631e6cf9f7d5a
    @@ -879,7 +883,7 @@ F test/fkey6.test d078a1e323a740062bed38df32b8a736fd320dc0
     F test/fkey7.test 64fb28da03da5dfe3cdef5967aa7e832c2507bf7fb8f0780cacbca1f2338d031
     F test/fkey8.test 48ef829d63f5f7b37aabd4df9363ac05f65539d1da8c4a44251631769d920579
     F test/fkey_malloc.test 594a7ea1fbab553c036c70813cd8bd9407d63749
    -F test/fordelete.test eb93a2f34137bb87bdab88fcab06c0bd92719aff
    +F test/fordelete.test ba98f14446b310f9c9d935b97ec748753d0144a28b356ba30d1f4f6958fdde5c
     F test/format4.test eeae341953db8b6bda7f549044797c3278a6cc345d11ada81471671b654f8ef4
     F test/fts-9fd058691.test 78b887e30ae6816df0e1fed6259de4b5a64ad33c
     F test/fts1a.test 46090311f85da51bb33bd5ce84f7948359c6d8d7
    @@ -941,10 +945,10 @@ F test/fts3b.test c15c4a9d04e210d0be67e54ce6a87b927168fbf9c1e3faec8c1a732c366fd4
     F test/fts3c.test fc723a9cf10b397fdfc2b32e73c53c8b1ec02958
     F test/fts3comp1.test a0f5b16a2df44dd0b15751787130af2183167c0c
     F test/fts3conf.test c84bbaec81281c1788aa545ac6e78a6bd6cde2bdbbce2da261690e3659f5a76b
    -F test/fts3corrupt.test ce7f7b5eaeee5f1804584d061b978d85e64abf2af9adaa7577589fac6f7eae01
    +F test/fts3corrupt.test 79a32ffdcd5254e2f7fa121d9656e61949ad049c3c6554229911b7ceac37c9c6
     F test/fts3corrupt2.test bf55c3fa0b0dc8ea1c0fe5543623bd27714585da6a129038fd6999fe3b0d25f3
     F test/fts3corrupt3.test 0d5b69a0998b4adf868cc301fc78f3d0707745f1d984ce044c205cdb764b491f
    -F test/fts3corrupt4.test e8ad49403179cbf714b6b669d2e0f9234ae95f4ca258a253b0f29ce28c1b027c
    +F test/fts3corrupt4.test fde292a4712753c7ef235a199273c5d196e18a56bd2c4d2db7ccaf59b7027a0a
     F test/fts3corrupt5.test 0549f85ec4bd22e992f645f13c59b99d652f2f5e643dac75568bfd23a6db7ed5
     F test/fts3cov.test 7eacdbefd756cfa4dc2241974e3db2834e9b372ca215880e00032222f32194cf
     F test/fts3d.test 2bd8c97bcb9975f2334147173b4872505b6a41359a4f9068960a36afe07a679f
    @@ -965,7 +969,8 @@ F test/fts3fuzz001.test e3c7b0ce9b04cc02281dcc96812a277f02df03cd7dc082055d87e11e
     F test/fts3join.test 949b4f5ae3ae9cc2423cb865d711e32476bdb205ab2be923fdf48246e4a44166
     F test/fts3malloc.test b0e4c133b8d61d4f6d112d8110f8320e9e453ef6
     F test/fts3matchinfo.test aa66cc50615578b30f6df9984819ae5b702511cf8a94251ec7c594096a703a4a
    -F test/fts3misc.test c47d2c1ea1351c51c32c688545b02c8180a3f22156d1aedc206a8c09b9d95905
    +F test/fts3matchinfo2.test 00144e841704b8debfcdf6097969cd9f2a1cf759e2203cda42583648f2e6bf58
    +F test/fts3misc.test 9ec15e7c0b5831a6353bd4c46bf3acdf1360eda5d9f396f667db4d05bcf92ecf
     F test/fts3near.test 7e3354d46f155a822b59c0e957fd2a70c1d7e905
     F test/fts3offsets.test b85fd382abdc78ebce721d8117bd552dfb75094c
     F test/fts3prefix.test fa794eaab0bdae466494947b0b153d7844478ab2
    @@ -974,12 +979,13 @@ F test/fts3query.test ca033ff2ebcc22c69d89032fb0bc1850997d31e7e60ecd26440796ba16
     F test/fts3rank.test cd99bc83a3c923c8d52afd90d86979cf05fc41849f892faeac3988055ef37b99
     F test/fts3rnd.test 1320d8826a845e38a96e769562bf83d7a92a15d0
     F test/fts3shared.test 57e26a801f21027b7530da77db54286a6fe4997e
    -F test/fts3snippet.test d9b9f4b717584040fb56df1dacab53acd474958e9c1d00b073d10726695cea0c
    +F test/fts3snippet.test 0887196d67cffbe365edde535b95ecc642a532ce8551ccd9a73aab5999c3ffae
    +F test/fts3snippet2.test 2dabb5889eda4c9980aad325e688b470781f97ce7c0fca0db125616fae0a2cdd
     F test/fts3sort.test ed34c716a11cc2009a35210e84ad5f9c102362ca
     F test/fts3tok1.test a663f4cac22a9505400bc22aacb818d7055240409c28729669ea7d4cc2120d15
     F test/fts3tok_err.test 52273cd193b9036282f7bacb43da78c6be87418d
     F test/fts3varint.test 0b84a3fd4eba8a39f3687523804d18f3b322e6d4539a55bf342079c3614f2ada
    -F test/fts4aa.test 9857f939f5aeb6cc4c143e74cf1cfe07ac87972240ac26d3a0100e36d02f4359
    +F test/fts4aa.test 0e6bfd6a81695a39b23e448dda25d864e63dda75bde6949c45ddc95426c6c3f5
     F test/fts4check.test 6259f856604445d7b684c9b306b2efb6346834c3f50e8fc4a59a2ca6d5319ad0
     F test/fts4content.test 73bbb123420d2c46ef2fb3b24761e9acdb78b0877179d3a5d7d57aada08066f6
     F test/fts4docid.test e33c383cfbdff0284685604d256f347a18fdbf01
    @@ -993,6 +999,7 @@ F test/fts4merge2.test 5faa558d1b672f82b847d2a337465fa745e46891
     F test/fts4merge3.test 8d9ccb4a3d41c4c617a149d6c4b13ad02de797d0
     F test/fts4merge4.test d895b1057a7798b67e03455d0fa50e9ea836c47b
     F test/fts4merge5.test 69932d85cda8a1c4dcfb742865900ed8fbda51724b8cf9a45bbe226dfd06c596
    +F test/fts4min.test 1c11e4bde16674a0c795953509cbc3731a7d9cbd1ddc7f35467bf39d632d749f
     F test/fts4noti.test 5553d7bb2e20bf4a06b23e849352efc022ce6309
     F test/fts4onepass.test d69ddc4ee3415e40b0c5d1d0408488a87614d4f63ba9c44f3e52db541d6b7cc7
     F test/fts4opt.test 0fd0cc84000743ff2a883b9b84b4a5be07249f0ba790c8848a757164cdd46b2a
    @@ -1001,11 +1008,11 @@ F test/fts4rename.test 15fd9985c2bce6dea20da2245b22029ec89bd4710ed317c4c53abbe3c
     F test/fts4umlaut.test fcaca4471de7e78c9d1f7e8976e3e8704d7d8ad979d57a739d00f3f757380429
     F test/fts4unicode.test ceca76422abc251818cb25dabe33d3c3970da5f7c90e1540f190824e6b3a7c95
     F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d
    -F test/func.test b7f1a706d1bb8de103a24bd0c30c9e3dc3eedf0df24aabc54b0a4f6e08742622
    +F test/func.test f673822636fb8ed618dd2b80230d16e495d19c8f2e2e7d6c22e93e2b3de097ad
     F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f
     F test/func3.test 2bb0f31ab7baaed690b962a88544d7be6b34fa389364bc36a44e441ed3e3f1e6
     F test/func4.test a94858a8c1f10a408b0b3db439c990b59dbb2349411d503de011ac4e2b5f27a6
    -F test/func5.test cdd224400bc3e48d891827cc913a57051a426fa4
    +F test/func5.test 863e6d1bd0013d09c17236f8a13ea34008dd857d87d85a13a673960e4c25d82a
     F test/func6.test 90e42b64c4f9fb6f04f44cb8a1da586c8542502e926b19c76504fe74ff2a9b7c
     F test/fuzz-oss1.test e58330d01cbbd8215ee636b17a03fe220b37dbfa
     F test/fuzz.test 96083052bf5765e4518c1ba686ce2bab785670d1
    @@ -1014,15 +1021,15 @@ F test/fuzz3.test 9c813e6613b837cb7a277b0383cd66bfa07042b4cf0317157c35852f30043c
     F test/fuzz4.test c229bcdb45518a89e1d208a21343e061503460ac69fae1539320a89f572eb634
     F test/fuzz_common.tcl b7197de6ed1ee8250a4f82d67876f4561b42ee8cbbfc6160dcb66331bad3f830
     F test/fuzz_malloc.test f348276e732e814802e39f042b1f6da6362a610af73a528d8f76898fde6b22f2
    -F test/fuzzcheck.c a9746aa49843827f960bc875cc70e04b0cfcd3e10e6676e3abc402ad190e165f
    +F test/fuzzcheck.c 656ee850f331872a784e7d6a10649efe2af123bdaacb728b5a03e4faee8b959c
     F test/fuzzdata1.db d36e88741b4f23bcbaaf55b006290669d03c6c891cf13c7b3a53bc1b097b693f
     F test/fuzzdata2.db 128b3feeb78918d075c9b14b48610145a0dd4c8d6f1ca7c2870c7e425f5bf31f
     F test/fuzzdata3.db c6586d3e3cef0fbc18108f9bb649aa77bfc38aba
     F test/fuzzdata4.db b502c7d5498261715812dd8b3c2005bad08b3a26e6489414bd13926cd3e42ed2
     F test/fuzzdata5.db e35f64af17ec48926481cfaf3b3855e436bd40d1cfe2d59a9474cb4b748a52a5
     F test/fuzzdata6.db 92a80e4afc172c24f662a10a612d188fb272de4a9bd19e017927c95f737de6d7
    -F test/fuzzdata7.db e7a86fd83dda151d160445d542e32e5c6019c541b3a74c2a525b6ac640639711
    -F test/fuzzdata8.db 8bd41f8e1b9c61af011bf5cf16a85fb7f718fdd3348e476b78ba36adab872653
    +F test/fuzzdata7.db 0166b56fd7a6b9636a1d60ef0a060f86ddaecf99400a666bb6e5bbd7199ad1f2
    +F test/fuzzdata8.db 209623791b0ad72ab39110c867af2080a79004e493c4da14ad661e790b5d1ed8
     F test/fuzzer1.test 3d4c4b7e547aba5e5511a2991e3e3d07166cfbb8
     F test/fuzzer2.test a85ef814ce071293bce1ad8dffa217cbbaad4c14
     F test/fuzzerfault.test 8792cd77fd5bce765b05d0c8e01b9edcf8af8536
    @@ -1034,7 +1041,7 @@ F test/hexlit.test 4a6a5f46e3c65c4bf1fa06f5dd5a9507a5627751
     F test/hidden.test 23c1393a79e846d68fd902d72c85d5e5dcf98711
     F test/hook.test 1604b3b2f5931430087540404555c1b6be3618600b81558657c66b533ed70b13
     F test/hook2.test b9ff3b8c6519fb67f33192f1afe86e7782ee4ac8
    -F test/icu.test 41aa8847745a879b897a7febea0f8f9efc8e67fe8bf680589b6e07c7b0a1569a
    +F test/icu.test 716a6b89fbabe5cc63e0cd4c260befb08fd7b9d761f04d43669233292f0753b1
     F test/ieee754.test 806fc0ce7f305f57e3331eaceeddcfec9339e607
     F test/imposter1.test c3f1db2d3db2c24611a6596a3fc0ffc14f1466c8
     F test/in.test ae4ba0fe3232fdd84ef1090a68c5cd6ccd93f1f8774d5c967dd0c1b301492eed
    @@ -1042,7 +1049,7 @@ F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75
     F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0
     F test/in4.test 65460600d48933adba4283c6ebd089aae173d16136ab9d01f74c89089090c5a5
     F test/in5.test b32ce7f4a93f44c5dee94af16886d922cc16ebe33c8e1765c73d4049d0f4b40f
    -F test/in6.test 62d943a02f722948f4410ee0b53c3cb39acd7c41afb083df8d7004238fe90a20
    +F test/in6.test 8562d0945195cab3cc4ab3794e9118e72cb44c43f785c2b04d48a9d06ca6b4ec
     F test/incrblob.test c9b96afc292aeff43d6687bcb09b0280aa599822
     F test/incrblob2.test a494c9e848560039a23974b9119cfc2cf3ad3bd15cc2694ee6367ae537ef8f1f
     F test/incrblob3.test d8d036fde015d4a159cd3cbae9d29003b37227a4
    @@ -1090,7 +1097,7 @@ F test/ioerr5.test 2edfa4fb0f896f733071303b42224df8bedd9da4
     F test/ioerr6.test a395a6ab144b26a9e3e21059a1ab6a7149cca65b
     F test/istrue.test 75327829744e65cc8700e69340b8e6c192e10e39dfae7ccb0e970d3c4f49090a
     F test/join.test bca044589e94bb466e4c1e91fb6fecdc3f3326ca6b3f590f555f1958156eb321
    -F test/join2.test 659bc6193f5c3fe20fa444dd2c91713db8c33e376b098b860644e175e87b8dbc
    +F test/join2.test 7d24d095ab88d3910228d53a3b548b7baf2e0e7d8aac6731a273e300e1b34b61
     F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
     F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
     F test/join5.test 3a96dc62f0b45402d7207e22d1993fe0c2fce1c57644a11439891dd62b990eb7
    @@ -1111,9 +1118,9 @@ F test/kvtest.c 94da54bb66aae7a54e47cf7e4ea4acecc0f217560f79ad3abfcc0361d6d557ba
     F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63
     F test/laststmtchanges.test ae613f53819206b3222771828d024154d51db200
     F test/lemon-test01.y 58b764610fd934e189ffbb0bbfa33d171b9cb06019b55bdc04d090d6767e11d7
    -F test/like.test 3d702d79bf871fa32985b1ce334294c587e3948d3ab972001e811a58577e8b3c
    +F test/like.test 47b81d5de2ff19d996d49a65d50ec9754246aacbe0e950b48d186d9d8171eaf0
     F test/like2.test 3b2ee13149ba4a8a60b59756f4e5d345573852da
    -F test/like3.test 4f940ad275c006319950054a7a65661f476772171b82b6fdf795e4dda36f246f
    +F test/like3.test 03d1bdf848483b78d2cfd1db283d75c4ec2e37c8b8eccc006813f3978d78fbbd
     F test/limit.test 0c99a27a87b14c646a9d583c7c89fd06c352663e
     F test/limit2.test 9409b033284642a859fafc95f29a5a6a557bd57c1f0d7c3f554bd64ed69df77e
     F test/loadext.test faa4f6eed07a5aac35d57fdd7bc07f8fc82464cfd327567c10cf0ba3c86cde04
    @@ -1171,7 +1178,7 @@ F test/misc4.test 10cd6addb2fa9093df4751a1b92b50440175dd5468a6ec84d0386e78f087db
     F test/misc5.test c4aeaa0fa28faa08f2485309c38db4719e6cd1364215d5687a5b96d340a3fa58
     F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91
     F test/misc7.test 4f21954012e4eb0a923c54a311f38c81bf6798ccdd7b51584db46d4007f63daa
    -F test/misc8.test 8fb0f31d7a8aed484d759773ab8ad12ec746a477f4a67394a4af0e677494c3ca
    +F test/misc8.test 8782708f4c8a459591c3e8fe1215bd2048bffb4024b3df249e9b9ed407dc61ed
     F test/misuse.test 9e7f78402005e833af71dcab32d048003869eca5abcaccc985d4f8dc1d86bcc7
     F test/mjournal.test 28a08d5cb5fb5b5702a46e19176e45e964e0800d1f894677169e79f34030e152
     F test/mmap1.test fb04e0c10492455007624ade884ca0c8852ff3e4e11d95408f9709ca2ef7f626
    @@ -1195,7 +1202,7 @@ F test/notify2.test 2ecabaa1305083856b7c39cf32816b612740c161
     F test/notify3.test 10ff25cde502e72a92053a2f215d64bece4ef934
     F test/notnull.test a37b663d5bb728d66fc182016613fb8e4a0a4bbf3d75b8876a7527f7d4ed3f18
     F test/null.test 0dcce4f04284ec66108c503327ad6d224c0752b3
    -F test/nulls1.test fe4153fd59a3786b4b9f3663a3e65a3aa43a318c7b4d7dcb3f6c3ed5652c9095
    +F test/nulls1.test 82c5bc33148405f21205865abf13c786084438d573a4ac4e87e11b6091cde526
     F test/numcast.test 5d126f7f581432e86a90d1e35cac625164aec4a1
     F test/numindex1.test 20a5450d4b056e48cd5db30e659f13347a099823
     F test/offset1.test f06b83657bcf26f9ce805e67450e189e282143b2
    @@ -1207,7 +1214,7 @@ F test/orderby1.test 6bf0ce45cbfb1cf4779dd418ac5e8cf66abfa04de2c1d2edf1e0e85f152
     F test/orderby2.test bc11009f7cd99d96b1b11e57b199b00633eb5b04
     F test/orderby3.test 8619d06a3debdcd80a27c0fdea5c40b468854b99
     F test/orderby4.test 4d39bfbaaa3ae64d026ca2ff166353d2edca4ba4
    -F test/orderby5.test 5f4d6cb93cc2f6d3f4228354310a2ce1fbd95d5bbffcba8c6482eeb62a466407
    +F test/orderby5.test bd7d9e3380e87e5dcf6ea817ebaab6d15da213c7804b38767e1b3e695e85650b
     F test/orderby6.test 8b38138ab0972588240b3fca0985d2e400432859
     F test/orderby7.test 3d1383d52ade5b9eb3a173b3147fdd296f0202da
     F test/orderby8.test 23ef1a5d72bd3adcc2f65561c654295d1b8047bd
    @@ -1230,7 +1237,7 @@ F test/parser1.test 6ccdf5e459a5dc4673d3273dc311a7e9742ca952dd0551a6a6320d27035c
     F test/pcache.test c8acbedd3b6fd0f9a7ca887a83b11d24a007972b
     F test/pcache2.test af7f3deb1a819f77a6d0d81534e97d1cf62cd442
     F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff
    -F test/permutations.test 8587800fe1a0eb01456a3f4500b821e54e3347e78acf11dbf05f4990530f6cee
    +F test/permutations.test c83339862d72b6272f957905205f874e6eefdbad2823380452c4f0128fd3d906
     F test/pg_common.tcl 222a1bad1c41c308fa366313cd7b51b3be7e9b21c8736a421b974ac941693b54
     F test/pragma.test 59becdfd720b80d463ab750f69f7118fde10dfd556aa5d554f3bf6b7e5ea7533
     F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f
    @@ -1301,8 +1308,8 @@ F test/securedel.test 2f70b2449186a1921bd01ec9da407fbfa98c3a7a5521854c300c194b2f
     F test/securedel2.test 2d54c28e46eb1fd6902089958b20b1b056c6f1c5
     F test/select1.test 009a6d8eacd9684d046302b8d13b50846a87e39d6f08e92178aa13e95ea29a2d
     F test/select2.test 352480e0e9c66eda9c3044e412abdf5be0215b56
    -F test/select3.test 3905450067c28766bc83ee397f6d87342de868baa60f2bcfd00f286dfbd62cb9
    -F test/select4.test 5389d9895968d1196c457d59b3ee6515d771d328
    +F test/select3.test ddd1bc6d0c8dece136321c11bd26d0d8ad17f2b27c72935fdd6574d8cb99d1d4
    +F test/select4.test e8a2502e3623f3058871030599a48abb35789d2244d5b380ecf3696873fdd4a4
     F test/select5.test df9ec0d218cedceb4fe7b63262025b547b50a55e59148c6f40b60ca25f1d4546
     F test/select6.test 319d45e414cdd321bf17cfacedaf19e3935ad64dac357c53f1492338c6e9b801
     F test/select7.test f659f231489349e8c5734e610803d7654207318f
    @@ -1331,11 +1338,11 @@ F test/sharedA.test 49d87ec54ab640fbbc3786ee3c01de94aaa482a3a9f834ad3fe92770eb69
     F test/sharedB.test 16cc7178e20965d75278f410943109b77b2e645e
     F test/shared_err.test 32634e404a3317eeb94abc7a099c556a346fdb8fb3858dbe222a4cbb8926a939
     F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304
    -F test/shell1.test 3c9707dce15e8fdca529503378660f099777d3ddcedccf801a37589a405c5942
    +F test/shell1.test 5bd10014ec494744f5e966a1521334e9d612119a0afcfa5251684a4e1f2ffc66
     F test/shell2.test e242a9912f44f4c23c3d1d802a83e934e84c853b
     F test/shell3.test ac8c2b744014c3e9a0e26bfd829ab65f00923dc1a91ffd044863e9423cc91494
     F test/shell4.test 1c6aef11daaa2d6830acaba3ac9cbec93fbc1c3d5530743a637f39b3987d08ce
    -F test/shell5.test 23939a4c51f0421330ea61dbd3c74f9c215f5f8d3d1a94846da6ffc777a35458
    +F test/shell5.test 84a30b55722a95a5b72989e691c469a999ca7591e7aa00b7fabc783ea5c9a6fe
     F test/shell6.test 1ceb51b2678c472ba6cf1e5da96679ce8347889fe2c3bf93a0e0fa73f00b00d3
     F test/shell7.test 115132f66d0463417f408562cc2cf534f6bbc6d83a6d50f0072a9eb171bae97f
     F test/shell8.test 96be02ea0c21f05b24c1883d7b711a1fa8525a68ab7b636aacf6057876941013
    @@ -1413,7 +1420,7 @@ F test/temptable.test d2c9b87a54147161bcd1822e30c1d1cd891e5b30
     F test/temptable2.test d2940417496e2b9548e01d09990763fbe88c316504033256d51493e1f1a5ce6a
     F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637
     F test/temptrigger.test 38f0ca479b1822d3117069e014daabcaacefffcc
    -F test/tester.tcl abba168acd7f01dbfa3ffdbf402d151eb97e8a824d9208e845ab34c194441483
    +F test/tester.tcl fd9d134a7cc4e31b307ad028a195f51cdcf556fc620d74b680515562f0137f25
     F test/thread001.test b61a29dd87cf669f5f6ac96124a7c97d71b0c80d9012746072055877055cf9ef
     F test/thread002.test e630504f8a06c00bf8bbe68528774dd96aeb2e58
     F test/thread003.test ee4c9efc3b86a6a2767516a37bd64251272560a7
    @@ -1653,7 +1660,7 @@ F test/vtab_alter.test 736e66fb5ec7b4fee58229aa3ada2f27ec58bc58c00edae4836890c37
     F test/vtab_err.test dcc8b7b9cb67522b3fe7a272c73856829dae4ab7fdb30399aea1b6981bda2b65
     F test/vtab_shared.test 5253bff2355a9a3f014c15337da7e177ab0ef8ad
     F test/vtabdrop.test 65d4cf6722972e5499bdaf0c0d70ee3b8133944a4e4bc31862563f32a7edca12
    -F test/wal.test cdf0ca6cc0447520d19ef1c83287824ebeb3e82d75af856511ba96841a79fc9b
    +F test/wal.test 16180bc4becda176428ad02eaea437b4b8f5ae099314de443a4e12b2dcc007a2
     F test/wal2.test 537f59e5c5932e3b45bf3591ae3e48a2601360c2e52821b633e222fe6ebd5b09
     F test/wal3.test 2a93004bc0fb2b5c29888964024695bade278ab2
     F test/wal4.test 4744e155cd6299c6bd99d3eab1c82f77db9cdb3c
    @@ -1684,6 +1691,7 @@ F test/walprotocol2.test 7d3b6b4bf0b12f8007121b1e6ef714bc99101fb3b48e46371df1db8
     F test/walro.test cb438d05ba0d191f10b688e39c4f0cd5b71569a1d1f4440e5bdf3c6880e08c20
     F test/walro2.test 0e79dd15cbdb4f482c01ea248373669c732414a726b357d04846a816afafb768
     F test/walrofault.test c70cb6e308c443867701856cce92ad8288cd99488fa52afab77cca6cfd51af68
    +F test/walsetlk.test 11f7fe792fdce54cf09874dab824e0627f2eedecfb9f7983e325606ec5184e0c
     F test/walshared.test 0befc811dcf0b287efae21612304d15576e35417
     F test/walslow.test c05c68d4dc2700a982f89133ce103a1a84cc285f
     F test/walthread.test 14b20fcfa6ae152f5d8e12f5dc8a8a724b7ef189f5d8ef1e2ceab79f2af51747
    @@ -1702,7 +1710,7 @@ F test/where9.test 2c554b97bbdb2fdf26c57099f60db8a52bfcf7c147f2c256f9798fa0e267c
     F test/whereA.test 6c6a420ca7d313242f9b1bd471dc80e4d0f8323700ba9c78df0bb843d4daa3b4
     F test/whereB.test 0def95db3bdec220a731c7e4bec5930327c1d8c5
     F test/whereC.test cae295158703cb3fc23bf1a108a9ab730efff0f6
    -F test/whereD.test 711d4df58d6d4fb9b3f5ce040b818564198be002
    +F test/whereD.test c1c335e914e28b122e000e9310f02d2be83e1c9dbca2e29f46bd732703944d1b
     F test/whereE.test b3a055eef928c992b0a33198a7b8dc10eea5ad2f
     F test/whereF.test 3d9412b1199d3e2bed34fcb76b4c48d0bf4df95d27e3f8dd27b6f8b4716d0d89
     F test/whereG.test c9378b285828754377ef47fbece7264018c0a3743e7eb686e89917bb9df10885
    @@ -1710,34 +1718,34 @@ F test/whereH.test e4b07f7a3c2f5d31195cd33710054c78667573b2
     F test/whereI.test a2874062140ed4aba9ffae76e6190a3df6fc73d1373fdfa8fd632945082a5364
     F test/whereJ.test 88287550f6ee604422403b053455b1ad894eeaa5c35d348532dfa1439286cb9a
     F test/whereK.test f8e3cf26a8513ecc7f514f54df9f0572c046c42b
    -F test/whereL.test 976f100f412ce2f39bf923eb57794cdc39fc0a3fec8fab025d51706a7cc4845b
    +F test/whereL.test e05cedc9389c6f09ad55bd5999a3fddccebec90672fb989433c145dcdaf26996
     F test/wherefault.test 1374c3aa198388925246475f84ad4cd5f9528864
     F test/wherelfault.test 9012e4ef5259058b771606616bd007af5d154e64cc25fa9fd4170f6411db44e3
     F test/wherelimit.test 592081800806d297dd7449b1030c863d2883d6d42901837ccd2e5a9bd962edb0
     F test/wherelimit2.test 9bf0aa56cca40ea0e4c5e2915341355a2bbc0859ec4ce1589197fe2a9d94635f
     F test/win32heap.test 10fd891266bd00af68671e702317726375e5407561d859be1aa04696f2aeee74
     F test/win32lock.test fbf107c91d8f5512be5a5b87c4c42ab9fdd54972
    -F test/win32longpath.test 169c75a3b2e43481f4a62122510210c67b08f26d
    +F test/win32longpath.test 4baffc3acb2e5188a5e3a895b2b543ed09e62f7c72d713c1feebf76222fe9976
     F test/win32nolock.test ac4f08811a562e45a5755e661f45ca85892bdbbc
    -F test/window1.test cec56b9a0a2e7ca4bd63b30590c7b049dce9acfd87478e2597e13b67152bd821
    +F test/window1.test a3504d44a3a125e35c53358cde1457d55bfc487bbe00f4c86bfed3a0bcc02140
     F test/window2.tcl 492c125fa550cda1dd3555768a2303b3effbeceee215293adf8871efc25f1476
     F test/window2.test e466a88bd626d66edc3d352d7d7e1d5531e0079b549ba44efb029d1fbff9fd3c
     F test/window3.tcl acea6e86a4324a210fd608d06741010ca83ded9fde438341cb978c49928faf03
     F test/window3.test e9959a993c8a71e96433be8daaa1827d78b8921e4f12debd7bdbeb3c856ef3cb
    -F test/window4.tcl d732df0e81beedc0ba8a563ade68611d322d27303ad0c0c8e4444107c39e84ec
    -F test/window4.test 807f3e6b15f9338e5b9742b87c5c7ca825b42b9657fde6096e890119370848e0
    +F test/window4.tcl 6f85307eb67242b654d051f7da32a996a66aee039a09c5ae358541aa61720742
    +F test/window4.test fbead87f681400ac07ef3555e0488b544a47d35491f8bf09a7474b6f76ce9b4e
     F test/window5.test d328dd18221217c49c144181975eea17339eaeaf0e9aa558cee3afb84652821e
     F test/window6.test f8d674254b23289cc17c84d79dec7eda7caa1dfb7836c43122cfdf3640d1df32
     F test/window7.tcl 6a1210f05d40ec89c22960213a22cd3f98d4e2f2eb20646c83c8c30d4d76108f
     F test/window7.test 1d31276961ae7801edc72173edaf7593e3cbc79c06d1f1f09e20d8418af403cd
     F test/window8.tcl f2711aa3571e4e6b0dad98db8d95fd6cb8d9db0c92bbdf535f153b07606a1ce2
     F test/window8.test c4331b27a6f66d69fa8f8bab10cc731db1a81d293ae108a68f7c3487fa94e65b
    -F test/window9.test b63f6f74d730547e63e78946f951f5d1a7d4e99f91f6d5906305469043d92a15
    +F test/window9.test c22c25377c820613e1842fe7ad4af7c03df625f6a7caee99e6fdb4fcd52e0a8b
     F test/windowA.test 6d63dc1260daa17141a55007600581778523a8b420629f1282d2acfc36af23be
     F test/windowB.test 7a983ea1cc1cf72be7f378e4b32f6cb2d73014c5cd8b25aaee825164cd4269e5
     F test/windowerr.tcl f5acd6fbc210d7b5546c0e879d157888455cd4a17a1d3f28f07c1c8a387019e0
     F test/windowerr.test a8b752402109c15aa1c5efe1b93ccb0ce1ef84fa964ae1cd6684dd0b3cc1819b
    -F test/windowfault.test 8e3b69abe0eea9595ba3940afd9c63644e11966ed8815734b67f1479a8e9891a
    +F test/windowfault.test 72375ae71031eabf96bc88d0af128c8628a091ddc99b5a394e848b3df5fc17ad
     F test/with1.test 584580a5ae79868a91873863f8cb2d00040006dc1e4c332ef1d8642f2815dc6e
     F test/with2.test e0030e2f0267a910d6c0e4f46f2dfe941c1cc0d4f659ba69b3597728e7e8f1ab
     F test/with3.test 13b3336739da648a9e4dfa11bb04e73a920c97620041007c5f75d5d14084c346
    @@ -1745,7 +1753,7 @@ F test/with4.test 257be66c0c67fee1defbbac0f685c3465e2cad037f21ce65f23f86084f1982
     F test/withM.test 693b61765f2b387b5e3e24a4536e2e82de15ff64
     F test/without_rowid1.test 9cfb83705c506e3849fa7efc88a3c9a15f9a50bf9b1516b41757a7cef9bba8c3
     F test/without_rowid2.test af260339f79d13cb220288b67cd287fbcf81ad99
    -F test/without_rowid3.test 392e6e12f275d11d931a8bc4580e573342f391639c87ffb631010a7b3cedfdc0
    +F test/without_rowid3.test f8e6b9f7cb32a3570bab743dd4f28d2000e2107808d57585e776f5c3eb076241
     F test/without_rowid4.test 4e08bcbaee0399f35d58b5581881e7a6243d458a
     F test/without_rowid5.test 89b1c587bd92a0590e440da33e7666bf4891572a
     F test/without_rowid6.test 8463b20098e9f75a501a9f17dfb42fffc79068eac0b2775fe56ef2281d2df45e
    @@ -1791,12 +1799,12 @@ F tool/mkmsvcmin.tcl 6ecab9fe22c2c8de4d82d4c46797bda3d2deac8e763885f5a38d0c44a89
     F tool/mkopcodec.tcl d1b6362bd3aa80d5520d4d6f3765badf01f6c43c
     F tool/mkopcodeh.tcl 352a4319c0ad869eb26442bf7c3b015aa15594c21f1cce5a6420dbe999367c21
     F tool/mkopts.tcl 680f785fdb09729fd9ac50632413da4eadbdf9071535e3f26d03795828ab07fa
    -F tool/mkpragmatab.tcl 62663c65d9191aada624a787e1ee3420f268a3c27999ad0ffb77a6918ddc1e52
    +F tool/mkpragmatab.tcl d348a4bf71ac068bddf89326562071cbbd962273d88f9b5e5d622f3e73b78bdf
     F tool/mkshellc.tcl 70a9978e363b0f3280ca9ce1c46d72563ff479c1930a12a7375e3881b7325712
     F tool/mksourceid.c 36aa8020014aed0836fd13c51d6dc9219b0df1761d6b5f58ff5b616211b079b9
     F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97
     F tool/mksqlite3c-noext.tcl 4f7cfef5152b0c91920355cbfc1d608a4ad242cb819f1aea07f6d0274f584a7f
    -F tool/mksqlite3c.tcl 5fed3d75069d8f66f202d3b5200b0cea4aa7108481acd06732a06fdd42eb83a2
    +F tool/mksqlite3c.tcl 3ab95bcf7b765f9d6d99cbeb8c4f150b38b0bb1f001ffac688f2ad02ebce2123
     F tool/mksqlite3h.tcl 080873e3856eceb9d289a08a00c4b30f875ea3feadcbece796bd509b1532792c
     F tool/mksqlite3internalh.tcl eb994013e833359137eb53a55acdad0b5ae1049b
     F tool/mkvsix.tcl b9e0777a213c23156b6542842c238479e496ebf5
    @@ -1815,7 +1823,7 @@ F tool/showshm.c a0ab6ec32dd1f11218ca2a4018f8fb875b59414801ab8ceed8b2e69b7b45a80
     F tool/showstat4.c 0682ebea7abf4d3657f53c4a243f2e7eab48eab344ed36a94bb75dcd19a5c2a1
     F tool/showwal.c ad9d768f96ca6199ad3a8c9562d679680bd032dd01204ea3e5ea6fb931d81847
     F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe
    -F tool/spaceanal.tcl 4bfd19aad7eb3ce0372ef0255f58035e0bba4ff5e9acfd763a10c6fb365c8dec
    +F tool/spaceanal.tcl c161d838825d0242317c7cc13b1eb2126f8cec031950ef31114d42732cb2674e
     F tool/speed-check.sh 2b042d703a9472f08c3b13be27afac658426f8e4fc87cd2d575953fda86f08d1
     F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355
     F tool/speedtest16.c ecb6542862151c3e6509bbc00509b234562ae81e
    @@ -1858,8 +1866,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
     F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
     F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
     F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
    -P a8a7c05b16f6c73ac55c359fbf62cae4a76eb0d105a3c53e9f47cede9fd85916
    -R 014522d0d8b6f7e2f23a6a5506d80ae9
    +P ce36b6d1331edba5a921fef32553e2470a79bdb1f62d2cfd81190691c83d5b06
    +R b5a877f3e2a7ab538bc565ffd2aae787
    +T +bgcolor * #d0c0ff
    +T +sym-release *
    +T +sym-version-3.32.0 *
     U drh
    -Z bb09705c5da204b17eae60b0010baaaf
    +Z 4af13806b6e302c99aeddae94a54c013
     # Remove this line to create a well-formed manifest.
    diff --git a/manifest.uuid b/manifest.uuid
    index 4df2614..d2aca4a 100644
    --- a/manifest.uuid
    +++ b/manifest.uuid
    @@ -1 +1 @@
    -5a877221ce90e7523059353a68650c5fdd28ed032807afc2f10afbfbf864bdfe
    +5998789c9c744bce92e4cff7636bba800a75574243d6977e1fc8281e360f8d5a
    diff --git a/src/alter.c b/src/alter.c
    index ee193d1..3332665 100644
    --- a/src/alter.c
    +++ b/src/alter.c
    @@ -123,7 +123,10 @@ void sqlite3AlterRenameTable(
       /* Check that a table or index named 'zName' does not already exist
       ** in database iDb. If so, this is an error.
       */
    -  if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) ){
    +  if( sqlite3FindTable(db, zName, zDb)
    +   || sqlite3FindIndex(db, zName, zDb)
    +   || sqlite3IsShadowTableOf(db, pTab, zName)
    +  ){
         sqlite3ErrorMsg(pParse, 
             "there is already another table or index with this name: %s", zName);
         goto exit_rename_table;
    @@ -255,6 +258,22 @@ exit_rename_table:
       db->mDbFlags = savedDbFlags;
     }
     
    +/*
    +** Write code that will raise an error if the table described by
    +** zDb and zTab is not empty.
    +*/
    +static void sqlite3ErrorIfNotEmpty(
    +  Parse *pParse,        /* Parsing context */
    +  const char *zDb,      /* Schema holding the table */
    +  const char *zTab,     /* Table to check for empty */
    +  const char *zErr      /* Error message text */
    +){
    +  sqlite3NestedParse(pParse,
    +     "SELECT raise(ABORT,%Q) FROM \"%w\".\"%w\"",
    +     zErr, zDb, zTab
    +  );
    +}
    +
     /*
     ** This function is called after an "ALTER TABLE ... ADD" statement
     ** has been parsed. Argument pColDef contains the text of the new
    @@ -307,7 +326,8 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
         return;
       }
       if( pNew->pIndex ){
    -    sqlite3ErrorMsg(pParse, "Cannot add a UNIQUE column");
    +    sqlite3ErrorMsg(pParse,
    +         "Cannot add a UNIQUE column");
         return;
       }
       if( (pCol->colFlags & COLFLAG_GENERATED)==0 ){
    @@ -320,16 +340,15 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
           pDflt = 0;
         }
         if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){
    -      sqlite3ErrorMsg(pParse, 
    +      sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
               "Cannot add a REFERENCES column with non-NULL default value");
    -      return;
         }
         if( pCol->notNull && !pDflt ){
    -      sqlite3ErrorMsg(pParse, 
    +      sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
               "Cannot add a NOT NULL column with default value NULL");
    -      return;
         }
     
    +
         /* Ensure the default expression is something that sqlite3ValueFromExpr()
         ** can handle (i.e. not CURRENT_TIME etc.)
         */
    @@ -343,14 +362,13 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
             return;
           }
           if( !pVal ){
    -        sqlite3ErrorMsg(pParse,"Cannot add a column with non-constant default");
    -        return;
    +        sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
    +           "Cannot add a column with non-constant default");
           }
           sqlite3ValueFree(pVal);
         }
       }else if( pCol->colFlags & COLFLAG_STORED ){
    -    sqlite3ErrorMsg(pParse, "cannot add a STORED column");
    -    return;
    +    sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, "cannot add a STORED column");
       }
     
     
    @@ -469,6 +487,7 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){
       for(i=0; inCol; i++){
         Column *pCol = &pNew->aCol[i];
         pCol->zName = sqlite3DbStrDup(db, pCol->zName);
    +    pCol->hName = sqlite3StrIHash(pCol->zName);
         pCol->zColl = 0;
         pCol->pDflt = 0;
       }
    @@ -697,7 +716,7 @@ void *sqlite3RenameTokenMap(Parse *pParse, void *pPtr, Token *pToken){
       RenameToken *pNew;
       assert( pPtr || pParse->db->mallocFailed );
       renameTokenCheckAll(pParse, pPtr);
    -  if( pParse->eParseMode!=PARSE_MODE_UNMAP ){
    +  if( ALWAYS(pParse->eParseMode!=PARSE_MODE_UNMAP) ){
         pNew = sqlite3DbMallocZero(pParse->db, sizeof(RenameToken));
         if( pNew ){
           pNew->p = pPtr;
    @@ -755,6 +774,21 @@ static void renameWalkWith(Walker *pWalker, Select *pSelect){
       }
     }
     
    +/*
    +** Unmap all tokens in the IdList object passed as the second argument.
    +*/
    +static void unmapColumnIdlistNames(
    +  Parse *pParse,
    +  IdList *pIdList
    +){
    +  if( pIdList ){
    +    int ii;
    +    for(ii=0; iinId; ii++){
    +      sqlite3RenameTokenRemap(pParse, 0, (void*)pIdList->a[ii].zName);
    +    }
    +  }
    +}
    +
     /*
     ** Walker callback used by sqlite3RenameExprUnmap().
     */
    @@ -776,6 +810,7 @@ static int renameUnmapSelectCb(Walker *pWalker, Select *p){
         for(i=0; inSrc; i++){
           sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName);
           if( sqlite3WalkExpr(pWalker, pSrc->a[i].pOn) ) return WRC_Abort;
    +      unmapColumnIdlistNames(pParse, pSrc->a[i].pUsing);
         }
       }
     
    @@ -984,6 +1019,7 @@ static void renameColumnIdlistNames(
       }
     }
     
    +
     /*
     ** Parse the SQL statement zSql using Parse object (*p). The Parse object
     ** is initialized by this function before it is used.
    diff --git a/src/analyze.c b/src/analyze.c
    index 2a071ef..b2f030d 100644
    --- a/src/analyze.c
    +++ b/src/analyze.c
    @@ -188,6 +188,11 @@ static void openStatTable(
       Vdbe *v = sqlite3GetVdbe(pParse);
       int aRoot[ArraySize(aTable)];
       u8 aCreateTbl[ArraySize(aTable)];
    +#ifdef SQLITE_ENABLE_STAT4
    +  const int nToOpen = OptimizationEnabled(db,SQLITE_Stat4) ? 2 : 1;
    +#else
    +  const int nToOpen = 1;
    +#endif
     
       if( v==0 ) return;
       assert( sqlite3BtreeHoldsAllMutexes(db) );
    @@ -200,8 +205,9 @@ static void openStatTable(
       for(i=0; izDbSName))==0 ){
    -      if( aTable[i].zCols ){
    +      if( iregRoot. This is important 
    @@ -217,7 +223,6 @@ static void openStatTable(
           ** associated with the table zWhere. If zWhere is NULL, delete the
           ** entire contents of the table. */
           aRoot[i] = pStat->tnum;
    -      aCreateTbl[i] = 0;
           sqlite3TableLock(pParse, iDb, aRoot[i], 1, zTab);
           if( zWhere ){
             sqlite3NestedParse(pParse,
    @@ -236,7 +241,7 @@ static void openStatTable(
       }
     
       /* Open the sqlite_stat[134] tables for writing. */
    -  for(i=0; aTable[i].zCols; i++){
    +  for(i=0; inRowid ){
         sqlite3DbFree(db, p->u.aRowid);
    @@ -305,7 +315,7 @@ static void sampleClear(sqlite3 *db, Stat4Sample *p){
     /* Initialize the BLOB value of a ROWID
     */
     #ifdef SQLITE_ENABLE_STAT4
    -static void sampleSetRowid(sqlite3 *db, Stat4Sample *p, int n, const u8 *pData){
    +static void sampleSetRowid(sqlite3 *db, StatSample *p, int n, const u8 *pData){
       assert( db!=0 );
       if( p->nRowid ) sqlite3DbFree(db, p->u.aRowid);
       p->u.aRowid = sqlite3DbMallocRawNN(db, n);
    @@ -321,7 +331,7 @@ static void sampleSetRowid(sqlite3 *db, Stat4Sample *p, int n, const u8 *pData){
     /* Initialize the INTEGER value of a ROWID.
     */
     #ifdef SQLITE_ENABLE_STAT4
    -static void sampleSetRowidInt64(sqlite3 *db, Stat4Sample *p, i64 iRowid){
    +static void sampleSetRowidInt64(sqlite3 *db, StatSample *p, i64 iRowid){
       assert( db!=0 );
       if( p->nRowid ) sqlite3DbFree(db, p->u.aRowid);
       p->nRowid = 0;
    @@ -334,7 +344,7 @@ static void sampleSetRowidInt64(sqlite3 *db, Stat4Sample *p, i64 iRowid){
     ** Copy the contents of object (*pFrom) into (*pTo).
     */
     #ifdef SQLITE_ENABLE_STAT4
    -static void sampleCopy(Stat4Accum *p, Stat4Sample *pTo, Stat4Sample *pFrom){
    +static void sampleCopy(StatAccum *p, StatSample *pTo, StatSample *pFrom){
       pTo->isPSample = pFrom->isPSample;
       pTo->iCol = pFrom->iCol;
       pTo->iHash = pFrom->iHash;
    @@ -350,40 +360,41 @@ static void sampleCopy(Stat4Accum *p, Stat4Sample *pTo, Stat4Sample *pFrom){
     #endif
     
     /*
    -** Reclaim all memory of a Stat4Accum structure.
    +** Reclaim all memory of a StatAccum structure.
     */
    -static void stat4Destructor(void *pOld){
    -  Stat4Accum *p = (Stat4Accum*)pOld;
    +static void statAccumDestructor(void *pOld){
    +  StatAccum *p = (StatAccum*)pOld;
     #ifdef SQLITE_ENABLE_STAT4
    -  int i;
    -  for(i=0; inCol; i++) sampleClear(p->db, p->aBest+i);
    -  for(i=0; imxSample; i++) sampleClear(p->db, p->a+i);
    -  sampleClear(p->db, &p->current);
    +  if( p->mxSample ){
    +    int i;
    +    for(i=0; inCol; i++) sampleClear(p->db, p->aBest+i);
    +    for(i=0; imxSample; i++) sampleClear(p->db, p->a+i);
    +    sampleClear(p->db, &p->current);
    +  }
     #endif
       sqlite3DbFree(p->db, p);
     }
     
     /*
    -** Implementation of the stat_init(N,K,C) SQL function. The three parameters
    +** Implementation of the stat_init(N,K,C,L) SQL function. The four parameters
     ** are:
     **     N:    The number of columns in the index including the rowid/pk (note 1)
     **     K:    The number of columns in the index excluding the rowid/pk.
    -**     C:    The number of rows in the index (note 2)
    +**     C:    Estimated number of rows in the index
    +**     L:    A limit on the number of rows to scan, or 0 for no-limit 
     **
     ** Note 1:  In the special case of the covering index that implements a
     ** WITHOUT ROWID table, N is the number of PRIMARY KEY columns, not the
     ** total number of columns in the table.
     **
    -** Note 2:  C is only used for STAT4.
    -**
     ** For indexes on ordinary rowid tables, N==K+1.  But for indexes on
     ** WITHOUT ROWID tables, N=K+P where P is the number of columns in the
     ** PRIMARY KEY of the table.  The covering index that implements the
     ** original WITHOUT ROWID table as N==K as a special case.
     **
    -** This routine allocates the Stat4Accum object in heap memory. The return 
    -** value is a pointer to the Stat4Accum object.  The datatype of the
    -** return value is BLOB, but it is really just a pointer to the Stat4Accum
    +** This routine allocates the StatAccum object in heap memory. The return 
    +** value is a pointer to the StatAccum object.  The datatype of the
    +** return value is BLOB, but it is really just a pointer to the StatAccum
     ** object.
     */
     static void statInit(
    @@ -391,14 +402,15 @@ static void statInit(
       int argc,
       sqlite3_value **argv
     ){
    -  Stat4Accum *p;
    +  StatAccum *p;
       int nCol;                       /* Number of columns in index being sampled */
       int nKeyCol;                    /* Number of key columns */
       int nColUp;                     /* nCol rounded up for alignment */
       int n;                          /* Bytes of space to allocate */
    -  sqlite3 *db;                    /* Database connection */
    +  sqlite3 *db = sqlite3_context_db_handle(context);   /* Database connection */
     #ifdef SQLITE_ENABLE_STAT4
    -  int mxSample = SQLITE_STAT4_SAMPLES;
    +  /* Maximum number of samples.  0 if STAT4 data is not collected */
    +  int mxSample = OptimizationEnabled(db,SQLITE_Stat4) ?SQLITE_STAT4_SAMPLES :0;
     #endif
     
       /* Decode the three function arguments */
    @@ -410,16 +422,17 @@ static void statInit(
       assert( nKeyCol<=nCol );
       assert( nKeyCol>0 );
     
    -  /* Allocate the space required for the Stat4Accum object */
    +  /* Allocate the space required for the StatAccum object */
       n = sizeof(*p) 
    -    + sizeof(tRowcnt)*nColUp                  /* Stat4Accum.anEq */
    -    + sizeof(tRowcnt)*nColUp                  /* Stat4Accum.anDLt */
    +    + sizeof(tRowcnt)*nColUp                  /* StatAccum.anEq */
    +    + sizeof(tRowcnt)*nColUp;                 /* StatAccum.anDLt */
     #ifdef SQLITE_ENABLE_STAT4
    -    + sizeof(tRowcnt)*nColUp                  /* Stat4Accum.anLt */
    -    + sizeof(Stat4Sample)*(nCol+mxSample)     /* Stat4Accum.aBest[], a[] */
    -    + sizeof(tRowcnt)*3*nColUp*(nCol+mxSample)
    +  if( mxSample ){
    +    n += sizeof(tRowcnt)*nColUp                  /* StatAccum.anLt */
    +      + sizeof(StatSample)*(nCol+mxSample)       /* StatAccum.aBest[], a[] */
    +      + sizeof(tRowcnt)*3*nColUp*(nCol+mxSample);
    +  }
     #endif
    -  ;
       db = sqlite3_context_db_handle(context);
       p = sqlite3DbMallocZero(db, n);
       if( p==0 ){
    @@ -428,25 +441,28 @@ static void statInit(
       }
     
       p->db = db;
    +  p->nEst = sqlite3_value_int64(argv[2]);
       p->nRow = 0;
    +  p->nLimit = sqlite3_value_int64(argv[3]);
       p->nCol = nCol;
       p->nKeyCol = nKeyCol;
    +  p->nSkipAhead = 0;
       p->current.anDLt = (tRowcnt*)&p[1];
       p->current.anEq = &p->current.anDLt[nColUp];
     
     #ifdef SQLITE_ENABLE_STAT4
    -  {
    +  p->mxSample = p->nLimit==0 ? mxSample : 0;
    +  if( mxSample ){
         u8 *pSpace;                     /* Allocated space not yet assigned */
         int i;                          /* Used to iterate through p->aSample[] */
     
         p->iGet = -1;
    -    p->mxSample = mxSample;
    -    p->nPSample = (tRowcnt)(sqlite3_value_int64(argv[2])/(mxSample/3+1) + 1);
    +    p->nPSample = (tRowcnt)(p->nEst/(mxSample/3+1) + 1);
         p->current.anLt = &p->current.anEq[nColUp];
         p->iPrn = 0x689e962d*(u32)nCol ^ 0xd0944565*(u32)sqlite3_value_int(argv[2]);
       
    -    /* Set up the Stat4Accum.a[] and aBest[] arrays */
    -    p->a = (struct Stat4Sample*)&p->current.anLt[nColUp];
    +    /* Set up the StatAccum.a[] and aBest[] arrays */
    +    p->a = (struct StatSample*)&p->current.anLt[nColUp];
         p->aBest = &p->a[mxSample];
         pSpace = (u8*)(&p->a[mxSample+nCol]);
         for(i=0; i<(mxSample+nCol); i++){
    @@ -466,10 +482,10 @@ static void statInit(
       ** only the pointer (the 2nd parameter) matters.  The size of the object
       ** (given by the 3rd parameter) is never used and can be any positive
       ** value. */
    -  sqlite3_result_blob(context, p, sizeof(*p), stat4Destructor);
    +  sqlite3_result_blob(context, p, sizeof(*p), statAccumDestructor);
     }
     static const FuncDef statInitFuncdef = {
    -  2+IsStat4,       /* nArg */
    +  4,               /* nArg */
       SQLITE_UTF8,     /* funcFlags */
       0,               /* pUserData */
       0,               /* pNext */
    @@ -493,9 +509,9 @@ static const FuncDef statInitFuncdef = {
     ** the anEq[] array from pSample->anEq[pSample->iCol+1] onwards are valid. 
     */
     static int sampleIsBetterPost(
    -  Stat4Accum *pAccum, 
    -  Stat4Sample *pNew, 
    -  Stat4Sample *pOld
    +  StatAccum *pAccum, 
    +  StatSample *pNew, 
    +  StatSample *pOld
     ){
       int nCol = pAccum->nCol;
       int i;
    @@ -517,9 +533,9 @@ static int sampleIsBetterPost(
     ** the anEq[] array from pSample->anEq[pSample->iCol] onwards are valid. 
     */
     static int sampleIsBetter(
    -  Stat4Accum *pAccum, 
    -  Stat4Sample *pNew, 
    -  Stat4Sample *pOld
    +  StatAccum *pAccum, 
    +  StatSample *pNew, 
    +  StatSample *pOld
     ){
       tRowcnt nEqNew = pNew->anEq[pNew->iCol];
       tRowcnt nEqOld = pOld->anEq[pOld->iCol];
    @@ -539,21 +555,21 @@ static int sampleIsBetter(
     ** Copy the contents of sample *pNew into the p->a[] array. If necessary,
     ** remove the least desirable sample from p->a[] to make room.
     */
    -static void sampleInsert(Stat4Accum *p, Stat4Sample *pNew, int nEqZero){
    -  Stat4Sample *pSample = 0;
    +static void sampleInsert(StatAccum *p, StatSample *pNew, int nEqZero){
    +  StatSample *pSample = 0;
       int i;
     
       assert( IsStat4 || nEqZero==0 );
     
    -  /* Stat4Accum.nMaxEqZero is set to the maximum number of leading 0
    -  ** values in the anEq[] array of any sample in Stat4Accum.a[]. In
    +  /* StatAccum.nMaxEqZero is set to the maximum number of leading 0
    +  ** values in the anEq[] array of any sample in StatAccum.a[]. In
       ** other words, if nMaxEqZero is n, then it is guaranteed that there
    -  ** are no samples with Stat4Sample.anEq[m]==0 for (m>=n). */
    +  ** are no samples with StatSample.anEq[m]==0 for (m>=n). */
       if( nEqZero>p->nMaxEqZero ){
         p->nMaxEqZero = nEqZero;
       }
       if( pNew->isPSample==0 ){
    -    Stat4Sample *pUpgrade = 0;
    +    StatSample *pUpgrade = 0;
         assert( pNew->anEq[pNew->iCol]>0 );
     
         /* This sample is being added because the prefix that ends in column 
    @@ -562,7 +578,7 @@ static void sampleInsert(Stat4Accum *p, Stat4Sample *pNew, int nEqZero){
         ** this one. Instead, upgrade the priority of the highest priority
         ** existing sample that shares this prefix.  */
         for(i=p->nSample-1; i>=0; i--){
    -      Stat4Sample *pOld = &p->a[i];
    +      StatSample *pOld = &p->a[i];
           if( pOld->anEq[pNew->iCol]==0 ){
             if( pOld->isPSample ) return;
             assert( pOld->iCol>pNew->iCol );
    @@ -581,7 +597,7 @@ static void sampleInsert(Stat4Accum *p, Stat4Sample *pNew, int nEqZero){
     
       /* If necessary, remove sample iMin to make room for the new sample. */
       if( p->nSample>=p->mxSample ){
    -    Stat4Sample *pMin = &p->a[p->iMin];
    +    StatSample *pMin = &p->a[p->iMin];
         tRowcnt *anEq = pMin->anEq;
         tRowcnt *anLt = pMin->anLt;
         tRowcnt *anDLt = pMin->anDLt;
    @@ -624,20 +640,20 @@ find_new_min:
     }
     #endif /* SQLITE_ENABLE_STAT4 */
     
    +#ifdef SQLITE_ENABLE_STAT4
     /*
     ** Field iChng of the index being scanned has changed. So at this point
     ** p->current contains a sample that reflects the previous row of the
     ** index. The value of anEq[iChng] and subsequent anEq[] elements are
     ** correct at this point.
     */
    -static void samplePushPrevious(Stat4Accum *p, int iChng){
    -#ifdef SQLITE_ENABLE_STAT4
    +static void samplePushPrevious(StatAccum *p, int iChng){
       int i;
     
       /* Check if any samples from the aBest[] array should be pushed
       ** into IndexSample.a[] at this point.  */
       for(i=(p->nCol-2); i>=iChng; i--){
    -    Stat4Sample *pBest = &p->aBest[i];
    +    StatSample *pBest = &p->aBest[i];
         pBest->anEq[i] = p->current.anEq[i];
         if( p->nSamplemxSample || sampleIsBetter(p, pBest, &p->a[p->iMin]) ){
           sampleInsert(p, pBest, i);
    @@ -661,27 +677,25 @@ static void samplePushPrevious(Stat4Accum *p, int iChng){
         }
         p->nMaxEqZero = iChng;
       }
    -#endif
    -
    -#ifndef SQLITE_ENABLE_STAT4
    -  UNUSED_PARAMETER( p );
    -  UNUSED_PARAMETER( iChng );
    -#endif
     }
    +#endif /* SQLITE_ENABLE_STAT4 */
     
     /*
     ** Implementation of the stat_push SQL function:  stat_push(P,C,R)
     ** Arguments:
     **
    -**    P     Pointer to the Stat4Accum object created by stat_init()
    +**    P     Pointer to the StatAccum object created by stat_init()
     **    C     Index of left-most column to differ from previous row
     **    R     Rowid for the current row.  Might be a key record for
     **          WITHOUT ROWID tables.
     **
    -** This SQL function always returns NULL.  It's purpose it to accumulate
    -** statistical data and/or samples in the Stat4Accum object about the
    -** index being analyzed.  The stat_get() SQL function will later be used to
    -** extract relevant information for constructing the sqlite_statN tables.
    +** The purpose of this routine is to collect statistical data and/or
    +** samples from the index being analyzed into the StatAccum object.
    +** The stat_get() SQL function will be used afterwards to
    +** retrieve the information gathered.
    +**
    +** This SQL function usually returns NULL, but might return an integer
    +** if it wants the byte-code to do special processing.
     **
     ** The R parameter is only used for STAT4
     */
    @@ -693,7 +707,7 @@ static void statPush(
       int i;
     
       /* The three function arguments */
    -  Stat4Accum *p = (Stat4Accum*)sqlite3_value_blob(argv[0]);
    +  StatAccum *p = (StatAccum*)sqlite3_value_blob(argv[0]);
       int iChng = sqlite3_value_int(argv[1]);
     
       UNUSED_PARAMETER( argc );
    @@ -706,7 +720,9 @@ static void statPush(
         for(i=0; inCol; i++) p->current.anEq[i] = 1;
       }else{
         /* Second and subsequent calls get processed here */
    -    samplePushPrevious(p, iChng);
    +#ifdef SQLITE_ENABLE_STAT4
    +    if( p->mxSample ) samplePushPrevious(p, iChng);
    +#endif
     
         /* Update anDLt[], anLt[] and anEq[] to reflect the values that apply
         ** to the current row of the index. */
    @@ -716,26 +732,25 @@ static void statPush(
         for(i=iChng; inCol; i++){
           p->current.anDLt[i]++;
     #ifdef SQLITE_ENABLE_STAT4
    -      p->current.anLt[i] += p->current.anEq[i];
    +      if( p->mxSample ) p->current.anLt[i] += p->current.anEq[i];
     #endif
           p->current.anEq[i] = 1;
         }
       }
    +
       p->nRow++;
     #ifdef SQLITE_ENABLE_STAT4
    -  if( sqlite3_value_type(argv[2])==SQLITE_INTEGER ){
    -    sampleSetRowidInt64(p->db, &p->current, sqlite3_value_int64(argv[2]));
    -  }else{
    -    sampleSetRowid(p->db, &p->current, sqlite3_value_bytes(argv[2]),
    -                                       sqlite3_value_blob(argv[2]));
    -  }
    -  p->current.iHash = p->iPrn = p->iPrn*1103515245 + 12345;
    -#endif
    -
    -#ifdef SQLITE_ENABLE_STAT4
    -  {
    -    tRowcnt nLt = p->current.anLt[p->nCol-1];
    +  if( p->mxSample ){
    +    tRowcnt nLt;
    +    if( sqlite3_value_type(argv[2])==SQLITE_INTEGER ){
    +      sampleSetRowidInt64(p->db, &p->current, sqlite3_value_int64(argv[2]));
    +    }else{
    +      sampleSetRowid(p->db, &p->current, sqlite3_value_bytes(argv[2]),
    +                                         sqlite3_value_blob(argv[2]));
    +    }
    +    p->current.iHash = p->iPrn = p->iPrn*1103515245 + 12345;
     
    +    nLt = p->current.anLt[p->nCol-1];
         /* Check if this is to be a periodic sample. If so, add it. */
         if( (nLt/p->nPSample)!=(nLt+1)/p->nPSample ){
           p->current.isPSample = 1;
    @@ -751,9 +766,14 @@ static void statPush(
             sampleCopy(p, &p->aBest[i], &p->current);
           }
         }
    -  }
    +  }else
     #endif
    +  if( p->nLimit && p->nRow>(tRowcnt)p->nLimit*(p->nSkipAhead+1) ){
    +    p->nSkipAhead++;
    +    sqlite3_result_int(context, p->current.anDLt[0]>0);
    +  }
     }
    +
     static const FuncDef statPushFuncdef = {
       2+IsStat4,       /* nArg */
       SQLITE_UTF8,     /* funcFlags */
    @@ -775,15 +795,15 @@ static const FuncDef statPushFuncdef = {
     /*
     ** Implementation of the stat_get(P,J) SQL function.  This routine is
     ** used to query statistical information that has been gathered into
    -** the Stat4Accum object by prior calls to stat_push().  The P parameter
    -** has type BLOB but it is really just a pointer to the Stat4Accum object.
    +** the StatAccum object by prior calls to stat_push().  The P parameter
    +** has type BLOB but it is really just a pointer to the StatAccum object.
     ** The content to returned is determined by the parameter J
     ** which is one of the STAT_GET_xxxx values defined above.
     **
     ** The stat_get(P,J) function is not available to generic SQL.  It is
     ** inserted as part of a manually constructed bytecode program.  (See
     ** the callStatGet() routine below.)  It is guaranteed that the P
    -** parameter will always be a poiner to a Stat4Accum object, never a
    +** parameter will always be a pointer to a StatAccum object, never a
     ** NULL.
     **
     ** If STAT4 is not enabled, then J is always
    @@ -796,7 +816,7 @@ static void statGet(
       int argc,
       sqlite3_value **argv
     ){
    -  Stat4Accum *p = (Stat4Accum*)sqlite3_value_blob(argv[0]);
    +  StatAccum *p = (StatAccum*)sqlite3_value_blob(argv[0]);
     #ifdef SQLITE_ENABLE_STAT4
       /* STAT4 has a parameter on this routine. */
       int eCall = sqlite3_value_int(argv[1]);
    @@ -805,6 +825,7 @@ static void statGet(
            || eCall==STAT_GET_ROWID || eCall==STAT_GET_NLT
            || eCall==STAT_GET_NDLT 
       );
    +  assert( eCall==STAT_GET_STAT1 || p->mxSample );
       if( eCall==STAT_GET_STAT1 )
     #else
       assert( argc==1 );
    @@ -817,7 +838,7 @@ static void statGet(
         ** the index. The first integer in the list is the total number of 
         ** entries in the index. There is one additional integer in the list 
         ** for each indexed column. This additional integer is an estimate of
    -    ** the number of rows matched by a stabbing query on the index using
    +    ** the number of rows matched by a equality query on the index using
         ** a key with the corresponding number of fields. In other words,
         ** if the index is on columns (a,b) and the sqlite_stat1 value is 
         ** "100 10 2", then SQLite estimates that:
    @@ -840,7 +861,8 @@ static void statGet(
           return;
         }
     
    -    sqlite3_snprintf(24, zRet, "%llu", (u64)p->nRow);
    +    sqlite3_snprintf(24, zRet, "%llu", 
    +        p->nSkipAhead ? (u64)p->nEst : (u64)p->nRow);
         z = zRet + sqlite3Strlen30(zRet);
         for(i=0; inKeyCol; i++){
           u64 nDistinct = p->current.anDLt[i] + 1;
    @@ -860,7 +882,7 @@ static void statGet(
           p->iGet = 0;
         }
         if( p->iGetnSample ){
    -      Stat4Sample *pS = p->a + p->iGet;
    +      StatSample *pS = p->a + p->iGet;
           if( pS->nRowid==0 ){
             sqlite3_result_int64(context, pS->u.iRowid);
           }else{
    @@ -916,16 +938,16 @@ static const FuncDef statGetFuncdef = {
       {0}
     };
     
    -static void callStatGet(Parse *pParse, int regStat4, int iParam, int regOut){
    +static void callStatGet(Parse *pParse, int regStat, int iParam, int regOut){
     #ifdef SQLITE_ENABLE_STAT4
    -  sqlite3VdbeAddOp2(pParse->pVdbe, OP_Integer, iParam, regStat4+1);
    +  sqlite3VdbeAddOp2(pParse->pVdbe, OP_Integer, iParam, regStat+1);
     #elif SQLITE_DEBUG
       assert( iParam==STAT_GET_STAT1 );
     #else
       UNUSED_PARAMETER( iParam );
     #endif
    -  assert( regOut!=regStat4 && regOut!=regStat4+1 );
    -  sqlite3VdbeAddFunctionCall(pParse, 0, regStat4, regOut, 1+IsStat4,
    +  assert( regOut!=regStat && regOut!=regStat+1 );
    +  sqlite3VdbeAddFunctionCall(pParse, 0, regStat, regOut, 1+IsStat4,
                                  &statGetFuncdef, 0);
     }
     
    @@ -951,12 +973,11 @@ static void analyzeOneTable(
       int iDb;                     /* Index of database containing pTab */
       u8 needTableCnt = 1;         /* True to count the table */
       int regNewRowid = iMem++;    /* Rowid for the inserted record */
    -  int regStat4 = iMem++;       /* Register to hold Stat4Accum object */
    +  int regStat = iMem++;        /* Register to hold StatAccum object */
       int regChng = iMem++;        /* Index of changed index field */
    -#ifdef SQLITE_ENABLE_STAT4
       int regRowid = iMem++;       /* Rowid argument passed to stat_push() */
    -#endif
       int regTemp = iMem++;        /* Temporary use register */
    +  int regTemp2 = iMem++;       /* Second temporary use register */
       int regTabname = iMem++;     /* Register containing table name */
       int regIdxname = iMem++;     /* Register containing index name */
       int regStat1 = iMem++;       /* Value for the stat column of sqlite_stat1 */
    @@ -1084,17 +1105,26 @@ static void analyzeOneTable(
         **    (1) the number of columns in the index including the rowid
         **        (or for a WITHOUT ROWID table, the number of PK columns),
         **    (2) the number of columns in the key without the rowid/pk
    -    **    (3) the number of rows in the index,
    -    **
    -    **
    -    ** The third argument is only used for STAT4
    +    **    (3) estimated number of rows in the index,
         */
    +    sqlite3VdbeAddOp2(v, OP_Integer, nCol, regStat+1);
    +    assert( regRowid==regStat+2 );
    +    sqlite3VdbeAddOp2(v, OP_Integer, pIdx->nKeyCol, regRowid);
     #ifdef SQLITE_ENABLE_STAT4
    -    sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regStat4+3);
    +    if( OptimizationEnabled(db, SQLITE_Stat4) ){
    +      sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regTemp);
    +      addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
    +      VdbeCoverage(v);
    +    }else
     #endif
    -    sqlite3VdbeAddOp2(v, OP_Integer, nCol, regStat4+1);
    -    sqlite3VdbeAddOp2(v, OP_Integer, pIdx->nKeyCol, regStat4+2);
    -    sqlite3VdbeAddFunctionCall(pParse, 0, regStat4+1, regStat4, 2+IsStat4,
    +    {
    +      addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
    +      VdbeCoverage(v);
    +      sqlite3VdbeAddOp3(v, OP_Count, iIdxCur, regTemp, 1);
    +    }
    +    assert( regTemp2==regStat+4 );
    +    sqlite3VdbeAddOp2(v, OP_Integer, db->nAnalysisLimit, regTemp2);
    +    sqlite3VdbeAddFunctionCall(pParse, 0, regStat+1, regStat, 4,
                                    &statInitFuncdef, 0);
     
         /* Implementation of the following:
    @@ -1105,8 +1135,6 @@ static void analyzeOneTable(
         **   goto next_push_0;
         **
         */
    -    addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
    -    VdbeCoverage(v);
         sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
         addrNextRow = sqlite3VdbeCurrentAddr(v);
     
    @@ -1139,6 +1167,7 @@ static void analyzeOneTable(
             char *pColl = (char*)sqlite3LocateCollSeq(pParse, pIdx->azColl[i]);
             sqlite3VdbeAddOp2(v, OP_Integer, i, regChng);
             sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp);
    +        VdbeComment((v, "%s.column(%d)", pIdx->zName, i));
             aGotoChng[i] = 
             sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
             sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
    @@ -1159,6 +1188,7 @@ static void analyzeOneTable(
           for(i=0; izName, i));
           }
           sqlite3VdbeResolveLabel(v, endDistinctTest);
           sqlite3DbFree(db, aGotoChng);
    @@ -1172,30 +1202,46 @@ static void analyzeOneTable(
         **   if !eof(csr) goto next_row;
         */
     #ifdef SQLITE_ENABLE_STAT4
    -    assert( regRowid==(regStat4+2) );
    -    if( HasRowid(pTab) ){
    -      sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, regRowid);
    -    }else{
    -      Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
    -      int j, k, regKey;
    -      regKey = sqlite3GetTempRange(pParse, pPk->nKeyCol);
    -      for(j=0; jnKeyCol; j++){
    -        k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[j]);
    -        assert( k>=0 && knColumn );
    -        sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, regKey+j);
    -        VdbeComment((v, "%s", pTab->aCol[pPk->aiColumn[j]].zName));
    +    if( OptimizationEnabled(db, SQLITE_Stat4) ){
    +      assert( regRowid==(regStat+2) );
    +      if( HasRowid(pTab) ){
    +        sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, regRowid);
    +      }else{
    +        Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
    +        int j, k, regKey;
    +        regKey = sqlite3GetTempRange(pParse, pPk->nKeyCol);
    +        for(j=0; jnKeyCol; j++){
    +          k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[j]);
    +          assert( k>=0 && knColumn );
    +          sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, regKey+j);
    +          VdbeComment((v, "%s.column(%d)", pIdx->zName, i));
    +        }
    +        sqlite3VdbeAddOp3(v, OP_MakeRecord, regKey, pPk->nKeyCol, regRowid);
    +        sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol);
           }
    -      sqlite3VdbeAddOp3(v, OP_MakeRecord, regKey, pPk->nKeyCol, regRowid);
    -      sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol);
         }
     #endif
    -    assert( regChng==(regStat4+1) );
    -    sqlite3VdbeAddFunctionCall(pParse, 1, regStat4, regTemp, 2+IsStat4,
    -                               &statPushFuncdef, 0);
    -    sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v);
    +    assert( regChng==(regStat+1) );
    +    {
    +      sqlite3VdbeAddFunctionCall(pParse, 1, regStat, regTemp, 2+IsStat4,
    +                                 &statPushFuncdef, 0);
    +      if( db->nAnalysisLimit ){
    +        int j1, j2, j3;
    +        j1 = sqlite3VdbeAddOp1(v, OP_IsNull, regTemp); VdbeCoverage(v);
    +        j2 = sqlite3VdbeAddOp1(v, OP_If, regTemp); VdbeCoverage(v);
    +        j3 = sqlite3VdbeAddOp4Int(v, OP_SeekGT, iIdxCur, 0, regPrev, 1);
    +        VdbeCoverage(v);
    +        sqlite3VdbeJumpHere(v, j1);
    +        sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v);
    +        sqlite3VdbeJumpHere(v, j2);
    +        sqlite3VdbeJumpHere(v, j3);
    +      }else{
    +        sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v);
    +      }
    +    }
     
         /* Add the entry to the stat1 table. */
    -    callStatGet(pParse, regStat4, STAT_GET_STAT1, regStat1);
    +    callStatGet(pParse, regStat, STAT_GET_STAT1, regStat1);
         assert( "BBB"[0]==SQLITE_AFF_TEXT );
         sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0);
         sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
    @@ -1207,7 +1253,7 @@ static void analyzeOneTable(
     
         /* Add the entries to the stat4 table. */
     #ifdef SQLITE_ENABLE_STAT4
    -    {
    +    if( OptimizationEnabled(db, SQLITE_Stat4) && db->nAnalysisLimit==0 ){
           int regEq = regStat1;
           int regLt = regStat1+1;
           int regDLt = regStat1+2;
    @@ -1221,12 +1267,12 @@ static void analyzeOneTable(
           pParse->nMem = MAX(pParse->nMem, regCol+nCol);
     
           addrNext = sqlite3VdbeCurrentAddr(v);
    -      callStatGet(pParse, regStat4, STAT_GET_ROWID, regSampleRowid);
    +      callStatGet(pParse, regStat, STAT_GET_ROWID, regSampleRowid);
           addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regSampleRowid);
           VdbeCoverage(v);
    -      callStatGet(pParse, regStat4, STAT_GET_NEQ, regEq);
    -      callStatGet(pParse, regStat4, STAT_GET_NLT, regLt);
    -      callStatGet(pParse, regStat4, STAT_GET_NDLT, regDLt);
    +      callStatGet(pParse, regStat, STAT_GET_NEQ, regEq);
    +      callStatGet(pParse, regStat, STAT_GET_NLT, regLt);
    +      callStatGet(pParse, regStat, STAT_GET_NDLT, regDLt);
           sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0);
           VdbeCoverage(v);
           for(i=0; iaDb[iDb].zDbSName, zName)==0
    +   || (iDb==0 && sqlite3StrICmp("main", zName)==0)
    +  );
    +}
    +
     /*
     ** An SQL user-function registered to do the work of an ATTACH statement. The
     ** three arguments to the function come directly from an attach statement:
    @@ -117,9 +128,8 @@ static void attachFunc(
           goto attach_error;
         }
         for(i=0; inDb; i++){
    -      char *z = db->aDb[i].zDbSName;
    -      assert( z && zName );
    -      if( sqlite3StrICmp(z, zName)==0 ){
    +      assert( zName );
    +      if( sqlite3DbIsNamed(db, i, zName) ){
             zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
             goto attach_error;
           }
    @@ -187,7 +197,7 @@ static void attachFunc(
       if( rc==SQLITE_OK && pNew->zDbSName==0 ){
         rc = SQLITE_NOMEM_BKPT;
       }
    -  sqlite3_free( zPath );
    +  sqlite3_free_filename( zPath );
     
       /* If the file was opened successfully, read the schema for the new database.
       ** If this fails, or if opening the file failed, then close the file and 
    @@ -272,7 +282,7 @@ static void detachFunc(
       for(i=0; inDb; i++){
         pDb = &db->aDb[i];
         if( pDb->pBt==0 ) continue;
    -    if( sqlite3StrICmp(pDb->zDbSName, zName)==0 ) break;
    +    if( sqlite3DbIsNamed(db, i, zName) ) break;
       }
     
       if( i>=db->nDb ){
    @@ -463,20 +473,21 @@ int sqlite3FixSrcList(
       SrcList *pList       /* The Source list to check and modify */
     ){
       int i;
    -  const char *zDb;
       struct SrcList_item *pItem;
    +  sqlite3 *db = pFix->pParse->db;
    +  int iDb = sqlite3FindDbName(db, pFix->zDb);
     
       if( NEVER(pList==0) ) return 0;
    -  zDb = pFix->zDb;
    +
       for(i=0, pItem=pList->a; inSrc; i++, pItem++){
         if( pFix->bTemp==0 ){
    -      if( pItem->zDatabase && sqlite3StrICmp(pItem->zDatabase, zDb) ){
    +      if( pItem->zDatabase && iDb!=sqlite3FindDbName(db, pItem->zDatabase) ){
             sqlite3ErrorMsg(pFix->pParse,
                 "%s %T cannot reference objects in database %s",
                 pFix->zType, pFix->pName, pItem->zDatabase);
             return 1;
           }
    -      sqlite3DbFree(pFix->pParse->db, pItem->zDatabase);
    +      sqlite3DbFree(db, pItem->zDatabase);
           pItem->zDatabase = 0;
           pItem->pSchema = pFix->pSchema;
           pItem->fg.fromDDL = 1;
    diff --git a/src/backup.c b/src/backup.c
    index 233d0ce..77e7ed9 100644
    --- a/src/backup.c
    +++ b/src/backup.c
    @@ -112,7 +112,7 @@ static Btree *findBtree(sqlite3 *pErrorDb, sqlite3 *pDb, const char *zDb){
     */
     static int setDestPgsz(sqlite3_backup *p){
       int rc;
    -  rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),-1,0);
    +  rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),0,0);
       return rc;
     }
     
    diff --git a/src/btree.c b/src/btree.c
    index de05fd9..f269b3d 100644
    --- a/src/btree.c
    +++ b/src/btree.c
    @@ -611,7 +611,7 @@ static int btreeSetHasContent(BtShared *pBt, Pgno pgno){
     */
     static int btreeGetHasContent(BtShared *pBt, Pgno pgno){
       Bitvec *p = pBt->pHasContent;
    -  return (p && (pgno>sqlite3BitvecSize(p) || sqlite3BitvecTest(p, pgno)));
    +  return p && (pgno>sqlite3BitvecSize(p) || sqlite3BitvecTestNotNull(p, pgno));
     }
     
     /*
    @@ -1449,7 +1449,7 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){
             int sz2 = 0;
             int sz = get2byte(&data[iFree+2]);
             int top = get2byte(&data[hdr+5]);
    -        if( NEVER(top>=iFree) ){
    +        if( top>=iFree ){
               return SQLITE_CORRUPT_PAGE(pPage);
             }
             if( iFree2 ){
    @@ -2304,8 +2304,7 @@ static int btreeInvokeBusyHandler(void *pArg){
       BtShared *pBt = (BtShared*)pArg;
       assert( pBt->db );
       assert( sqlite3_mutex_held(pBt->db->mutex) );
    -  return sqlite3InvokeBusyHandler(&pBt->db->busyHandler,
    -                                  sqlite3PagerFile(pBt->pPager));
    +  return sqlite3InvokeBusyHandler(&pBt->db->busyHandler);
     }
     
     /*
    @@ -2856,16 +2855,17 @@ int sqlite3BtreeSetPagerFlags(
     */
     int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve, int iFix){
       int rc = SQLITE_OK;
    +  int x;
       BtShared *pBt = p->pBt;
    -  assert( nReserve>=-1 && nReserve<=255 );
    +  assert( nReserve>=0 && nReserve<=255 );
       sqlite3BtreeEnter(p);
    +  pBt->nReserveWanted = nReserve;
    +  x = pBt->pageSize - pBt->usableSize;
    +  if( nReservebtsFlags & BTS_PAGESIZE_FIXED ){
         sqlite3BtreeLeave(p);
         return SQLITE_READONLY;
       }
    -  if( nReserve<0 ){
    -    nReserve = pBt->pageSize - pBt->usableSize;
    -  }
       assert( nReserve>=0 && nReserve<=255 );
       if( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE &&
             ((pageSize-1)&pageSize)==0 ){
    @@ -2911,16 +2911,17 @@ int sqlite3BtreeGetReserveNoMutex(Btree *p){
     ** are intentually left unused.  This is the "reserved" space that is
     ** sometimes used by extensions.
     **
    -** If SQLITE_HAS_MUTEX is defined then the number returned is the
    -** greater of the current reserved space and the maximum requested
    -** reserve space.
    +** The value returned is the larger of the current reserve size and
    +** the latest reserve size requested by SQLITE_FILECTRL_RESERVE_BYTES.
    +** The amount of reserve can only grow - never shrink.
     */
    -int sqlite3BtreeGetOptimalReserve(Btree *p){
    -  int n;
    +int sqlite3BtreeGetRequestedReserve(Btree *p){
    +  int n1, n2;
       sqlite3BtreeEnter(p);
    -  n = sqlite3BtreeGetReserveNoMutex(p);
    +  n1 = (int)p->pBt->nReserveWanted;
    +  n2 = sqlite3BtreeGetReserveNoMutex(p);
       sqlite3BtreeLeave(p);
    -  return n;
    +  return n1>n2 ? n1 : n2;
     }
     
     
    @@ -3370,6 +3371,7 @@ int sqlite3BtreeNewDb(Btree *p){
     */
     int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){
       BtShared *pBt = p->pBt;
    +  Pager *pPager = pBt->pPager;
       int rc = SQLITE_OK;
     
       sqlite3BtreeEnter(p);
    @@ -3385,7 +3387,7 @@ int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){
       assert( pBt->inTransaction==TRANS_WRITE || IfNotOmitAV(pBt->bDoTruncate)==0 );
     
       if( (p->db->flags & SQLITE_ResetDatabase) 
    -   && sqlite3PagerIsreadonly(pBt->pPager)==0 
    +   && sqlite3PagerIsreadonly(pPager)==0 
       ){
         pBt->btsFlags &= ~BTS_READ_ONLY;
       }
    @@ -3433,6 +3435,18 @@ int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){
       pBt->btsFlags &= ~BTS_INITIALLY_EMPTY;
       if( pBt->nPage==0 ) pBt->btsFlags |= BTS_INITIALLY_EMPTY;
       do {
    +    sqlite3PagerWalDb(pPager, p->db);
    +
    +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
    +    /* If transitioning from no transaction directly to a write transaction,
    +    ** block for the WRITER lock first if possible. */
    +    if( pBt->pPage1==0 && wrflag ){
    +      assert( pBt->inTransaction==TRANS_NONE );
    +      rc = sqlite3PagerWalWriteLock(pPager, 1);
    +      if( rc!=SQLITE_BUSY && rc!=SQLITE_OK ) break;
    +    }
    +#endif
    +
         /* Call lockBtree() until either pBt->pPage1 is populated or
         ** lockBtree() returns something other than SQLITE_OK. lockBtree()
         ** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after
    @@ -3446,7 +3460,7 @@ int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){
           if( (pBt->btsFlags & BTS_READ_ONLY)!=0 ){
             rc = SQLITE_READONLY;
           }else{
    -        rc = sqlite3PagerBegin(pBt->pPager,wrflag>1,sqlite3TempInMemory(p->db));
    +        rc = sqlite3PagerBegin(pPager, wrflag>1, sqlite3TempInMemory(p->db));
             if( rc==SQLITE_OK ){
               rc = newDatabase(pBt);
             }else if( rc==SQLITE_BUSY_SNAPSHOT && pBt->inTransaction==TRANS_NONE ){
    @@ -3459,11 +3473,15 @@ int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){
         }
       
         if( rc!=SQLITE_OK ){
    +      (void)sqlite3PagerWalWriteLock(pPager, 0);
           unlockBtreeIfUnused(pBt);
         }
       }while( (rc&0xFF)==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE &&
               btreeInvokeBusyHandler(pBt) );
    -  sqlite3PagerResetLockTimeout(pBt->pPager);
    +  sqlite3PagerWalDb(pPager, 0);
    +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
    +  if( rc==SQLITE_BUSY_TIMEOUT ) rc = SQLITE_BUSY;
    +#endif
     
       if( rc==SQLITE_OK ){
         if( p->inTrans==TRANS_NONE ){
    @@ -3515,7 +3533,7 @@ trans_begun:
           ** open savepoints. If the second parameter is greater than 0 and
           ** the sub-journal is not already open, then it will be opened here.
           */
    -      rc = sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint);
    +      rc = sqlite3PagerOpenSavepoint(pPager, p->db->nSavepoint);
         }
       }
     
    @@ -7151,7 +7169,7 @@ static int editPage(
       assert( nCell>=0 );
       if( iOldnCell ) return SQLITE_CORRUPT_BKPT;
    +    if( NEVER(nShift>nCell) ) return SQLITE_CORRUPT_BKPT;
         memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2);
         nCell -= nShift;
       }
    @@ -9508,7 +9526,6 @@ int sqlite3BtreeUpdateMeta(Btree *p, int idx, u32 iMeta){
       return rc;
     }
     
    -#ifndef SQLITE_OMIT_BTREECOUNT
     /*
     ** The first argument, pCur, is a cursor opened on some b-tree. Count the
     ** number of entries in the b-tree and write the result to *pnEntry.
    @@ -9530,7 +9547,7 @@ int sqlite3BtreeCount(sqlite3 *db, BtCursor *pCur, i64 *pnEntry){
       /* Unless an error occurs, the following loop runs one iteration for each
       ** page in the B-Tree structure (not including overflow pages). 
       */
    -  while( rc==SQLITE_OK && !db->u1.isInterrupted ){
    +  while( rc==SQLITE_OK && !AtomicLoad(&db->u1.isInterrupted) ){
         int iIdx;                          /* Index of child node in parent */
         MemPage *pPage;                    /* Current page of the b-tree */
     
    @@ -9581,7 +9598,6 @@ int sqlite3BtreeCount(sqlite3 *db, BtCursor *pCur, i64 *pnEntry){
       /* An error has occurred. Return an error code. */
       return rc;
     }
    -#endif
     
     /*
     ** Return the pager associated with a BTree.  This routine is used for
    @@ -9656,7 +9672,7 @@ static int checkRef(IntegrityCk *pCheck, Pgno iPage){
         checkAppendMsg(pCheck, "2nd reference to page %d", iPage);
         return 1;
       }
    -  if( pCheck->db->u1.isInterrupted ) return 1;
    +  if( AtomicLoad(&pCheck->db->u1.isInterrupted) ) return 1;
       setPageReferenced(pCheck, iPage);
       return 0;
     }
    diff --git a/src/btree.h b/src/btree.h
    index 4bd41f7..c152b63 100644
    --- a/src/btree.h
    +++ b/src/btree.h
    @@ -74,7 +74,7 @@ int sqlite3BtreeGetPageSize(Btree*);
     int sqlite3BtreeMaxPageCount(Btree*,int);
     u32 sqlite3BtreeLastPage(Btree*);
     int sqlite3BtreeSecureDelete(Btree*,int);
    -int sqlite3BtreeGetOptimalReserve(Btree*);
    +int sqlite3BtreeGetRequestedReserve(Btree*);
     int sqlite3BtreeGetReserveNoMutex(Btree *p);
     int sqlite3BtreeSetAutoVacuum(Btree *, int);
     int sqlite3BtreeGetAutoVacuum(Btree *);
    @@ -336,9 +336,7 @@ int sqlite3BtreeCursorIsValid(BtCursor*);
     #endif
     int sqlite3BtreeCursorIsValidNN(BtCursor*);
     
    -#ifndef SQLITE_OMIT_BTREECOUNT
     int sqlite3BtreeCount(sqlite3*, BtCursor*, i64*);
    -#endif
     
     #ifdef SQLITE_TEST
     int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
    diff --git a/src/btreeInt.h b/src/btreeInt.h
    index e5149d9..ec25b54 100644
    --- a/src/btreeInt.h
    +++ b/src/btreeInt.h
    @@ -417,6 +417,7 @@ struct BtShared {
     #endif
       u8 inTransaction;     /* Transaction state */
       u8 max1bytePayload;   /* Maximum first byte of cell for a 1-byte payload */
    +  u8 nReserveWanted;    /* Desired number of extra bytes per page */
       u16 btsFlags;         /* Boolean parameters.  See BTS_* macros below */
       u16 maxLocal;         /* Maximum local payload in non-LEAFDATA tables */
       u16 minLocal;         /* Minimum local payload in non-LEAFDATA tables */
    diff --git a/src/build.c b/src/build.c
    index a7dc36f..6ff595c 100644
    --- a/src/build.c
    +++ b/src/build.c
    @@ -312,22 +312,39 @@ Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
         return 0;
       }
     #endif
    -  while(1){
    -    for(i=OMIT_TEMPDB; inDb; i++){
    -      int j = (i<2) ? i^1 : i;   /* Search TEMP before MAIN */
    -      if( zDatabase==0 || sqlite3StrICmp(zDatabase, db->aDb[j].zDbSName)==0 ){
    -        assert( sqlite3SchemaMutexHeld(db, j, 0) );
    -        p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
    -        if( p ) return p;
    +  if( zDatabase ){
    +    for(i=0; inDb; i++){
    +      if( sqlite3StrICmp(zDatabase, db->aDb[i].zDbSName)==0 ) break;
    +    }
    +    if( i>=db->nDb ){
    +      /* No match against the official names.  But always match "main"
    +      ** to schema 0 as a legacy fallback. */
    +      if( sqlite3StrICmp(zDatabase,"main")==0 ){
    +        i = 0;
    +      }else{
    +        return 0;
           }
         }
    -    /* Not found.  If the name we were looking for was temp.sqlite_master
    -    ** then change the name to sqlite_temp_master and try again. */
    -    if( sqlite3StrICmp(zName, MASTER_NAME)!=0 ) break;
    -    if( sqlite3_stricmp(zDatabase, db->aDb[1].zDbSName)!=0 ) break;
    -    zName = TEMP_MASTER_NAME;
    +    p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName);
    +    if( p==0 && i==1 && sqlite3StrICmp(zName, MASTER_NAME)==0 ){
    +      /* All temp.sqlite_master to be an alias for sqlite_temp_master */
    +      p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, TEMP_MASTER_NAME);
    +    }
    +  }else{
    +    /* Match against TEMP first */
    +    p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, zName);
    +    if( p ) return p;
    +    /* The main database is second */
    +    p = sqlite3HashFind(&db->aDb[0].pSchema->tblHash, zName);
    +    if( p ) return p;
    +    /* Attached databases are in order of attachment */
    +    for(i=2; inDb; i++){
    +      assert( sqlite3SchemaMutexHeld(db, i, 0) );
    +      p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName);
    +      if( p ) break;
    +    }
       }
    -  return 0;
    +  return p;
     }
     
     /*
    @@ -437,7 +454,7 @@ Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
         int j = (i<2) ? i^1 : i;  /* Search TEMP before MAIN */
         Schema *pSchema = db->aDb[j].pSchema;
         assert( pSchema );
    -    if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zDbSName) ) continue;
    +    if( zDb && sqlite3DbIsNamed(db, j, zDb)==0 ) continue;
         assert( sqlite3SchemaMutexHeld(db, j, 0) );
         p = sqlite3HashFind(&pSchema->idxHash, zName);
         if( p ) break;
    @@ -590,6 +607,7 @@ void sqlite3DeleteColumnNames(sqlite3 *db, Table *pTable){
       assert( pTable!=0 );
       if( (pCol = pTable->aCol)!=0 ){
         for(i=0; inCol; i++, pCol++){
    +      assert( pCol->zName==0 || pCol->hName==sqlite3StrIHash(pCol->zName) );
           sqlite3DbFree(db, pCol->zName);
           sqlite3ExprDelete(db, pCol->pDflt);
           sqlite3DbFree(db, pCol->zColl);
    @@ -1238,6 +1256,7 @@ void sqlite3AddColumn(Parse *pParse, Token *pName, Token *pType){
       pCol = &p->aCol[p->nCol];
       memset(pCol, 0, sizeof(p->aCol[0]));
       pCol->zName = z;
    +  pCol->hName = sqlite3StrIHash(z);
       sqlite3ColumnPropertiesFromName(p, pCol);
      
       if( pType->n==0 ){
    @@ -2129,6 +2148,28 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
       recomputeColumnsNotIndexed(pPk);
     }
     
    +
    +#ifndef SQLITE_OMIT_VIRTUALTABLE
    +/*
    +** Return true if pTab is a virtual table and zName is a shadow table name
    +** for that virtual table.
    +*/
    +int sqlite3IsShadowTableOf(sqlite3 *db, Table *pTab, const char *zName){
    +  int nName;                    /* Length of zName */
    +  Module *pMod;                 /* Module for the virtual table */
    +
    +  if( !IsVirtual(pTab) ) return 0;
    +  nName = sqlite3Strlen30(pTab->zName);
    +  if( sqlite3_strnicmp(zName, pTab->zName, nName)!=0 ) return 0;
    +  if( zName[nName]!='_' ) return 0;
    +  pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->azModuleArg[0]);
    +  if( pMod==0 ) return 0;
    +  if( pMod->pModule->iVersion<3 ) return 0;
    +  if( pMod->pModule->xShadowName==0 ) return 0;
    +  return pMod->pModule->xShadowName(zName+nName+1);
    +}
    +#endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
    +
     #ifndef SQLITE_OMIT_VIRTUALTABLE
     /*
     ** Return true if zName is a shadow table name in the current database
    @@ -2140,8 +2181,6 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
     int sqlite3ShadowTableName(sqlite3 *db, const char *zName){
       char *zTail;                  /* Pointer to the last "_" in zName */
       Table *pTab;                  /* Table that zName is a shadow of */
    -  Module *pMod;                 /* Module for the virtual table */
    -
       zTail = strrchr(zName, '_');
       if( zTail==0 ) return 0;
       *zTail = 0;
    @@ -2149,14 +2188,37 @@ int sqlite3ShadowTableName(sqlite3 *db, const char *zName){
       *zTail = '_';
       if( pTab==0 ) return 0;
       if( !IsVirtual(pTab) ) return 0;
    -  pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->azModuleArg[0]);
    -  if( pMod==0 ) return 0;
    -  if( pMod->pModule->iVersion<3 ) return 0;
    -  if( pMod->pModule->xShadowName==0 ) return 0;
    -  return pMod->pModule->xShadowName(zTail+1);
    +  return sqlite3IsShadowTableOf(db, pTab, zName);
     }
     #endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
     
    +
    +#ifdef SQLITE_DEBUG
    +/*
    +** Mark all nodes of an expression as EP_Immutable, indicating that
    +** they should not be changed.  Expressions attached to a table or
    +** index definition are tagged this way to help ensure that we do
    +** not pass them into code generator routines by mistake.
    +*/
    +static int markImmutableExprStep(Walker *pWalker, Expr *pExpr){
    +  ExprSetVVAProperty(pExpr, EP_Immutable);
    +  return WRC_Continue;
    +}
    +static void markExprListImmutable(ExprList *pList){
    +  if( pList ){
    +    Walker w;
    +    memset(&w, 0, sizeof(w));
    +    w.xExprCallback = markImmutableExprStep;
    +    w.xSelectCallback = sqlite3SelectWalkNoop;
    +    w.xSelectCallback2 = 0;
    +    sqlite3WalkExprList(&w, pList);
    +  }
    +}
    +#else
    +#define markExprListImmutable(X)  /* no-op */
    +#endif /* SQLITE_DEBUG */
    +
    +
     /*
     ** This routine is called to report the final ")" that terminates
     ** a CREATE TABLE statement.
    @@ -2249,6 +2311,8 @@ void sqlite3EndTable(
           ** actually be used if PRAGMA writable_schema=ON is set. */
           sqlite3ExprListDelete(db, p->pCheck);
           p->pCheck = 0;
    +    }else{
    +      markExprListImmutable(p->pCheck);
         }
       }
     #endif /* !defined(SQLITE_OMIT_CHECK) */
    @@ -4600,7 +4664,7 @@ int sqlite3OpenTempDatabase(Parse *pParse){
         }
         db->aDb[1].pBt = pBt;
         assert( db->aDb[1].pSchema );
    -    if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
    +    if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, 0, 0) ){
           sqlite3OomFault(db);
           return 1;
         }
    @@ -4711,7 +4775,7 @@ void sqlite3HaltConstraint(
       u8 p5Errmsg       /* P5_ErrMsg type */
     ){
       Vdbe *v = sqlite3GetVdbe(pParse);
    -  assert( (errCode&0xff)==SQLITE_CONSTRAINT );
    +  assert( (errCode&0xff)==SQLITE_CONSTRAINT || pParse->nested );
       if( onError==OE_Abort ){
         sqlite3MayAbort(pParse);
       }
    diff --git a/src/callback.c b/src/callback.c
    index 3d99190..421cef2 100644
    --- a/src/callback.c
    +++ b/src/callback.c
    @@ -163,17 +163,30 @@ CollSeq *sqlite3FindCollSeq(
       int create            /* True to create CollSeq if doesn't already exist */
     ){
       CollSeq *pColl;
    +  assert( SQLITE_UTF8==1 && SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
    +  assert( enc>=SQLITE_UTF8 && enc<=SQLITE_UTF16BE );
       if( zName ){
         pColl = findCollSeqEntry(db, zName, create);
    +    if( pColl ) pColl += enc-1;
       }else{
         pColl = db->pDfltColl;
       }
    -  assert( SQLITE_UTF8==1 && SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
    -  assert( enc>=SQLITE_UTF8 && enc<=SQLITE_UTF16BE );
    -  if( pColl ) pColl += enc-1;
       return pColl;
     }
     
    +/*
    +** Change the text encoding for a database connection. This means that
    +** the pDfltColl must change as well.
    +*/
    +void sqlite3SetTextEncoding(sqlite3 *db, u8 enc){
    +  assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
    +  db->enc = enc;
    +  /* EVIDENCE-OF: R-08308-17224 The default collating function for all
    +  ** strings is BINARY. 
    +  */
    +  db->pDfltColl = sqlite3FindCollSeq(db, enc, sqlite3StrBINARY, 0);
    +}
    +
     /*
     ** This function is responsible for invoking the collation factory callback
     ** or substituting a collation sequence of a different encoding when the
    diff --git a/src/ctime.c b/src/ctime.c
    index 7a2ace9..e3e1e79 100644
    --- a/src/ctime.c
    +++ b/src/ctime.c
    @@ -193,6 +193,9 @@ static const char * const sqlite3azCompileOpt[] = {
     #if SQLITE_ENABLE_BATCH_ATOMIC_WRITE
       "ENABLE_BATCH_ATOMIC_WRITE",
     #endif
    +#if SQLITE_ENABLE_BYTECODE_VTAB
    +  "ENABLE_BYTECODE_VTAB",
    +#endif
     #if SQLITE_ENABLE_CEROD
       "ENABLE_CEROD=" CTIMEOPT_VAL(SQLITE_ENABLE_CEROD),
     #endif
    @@ -511,9 +514,6 @@ static const char * const sqlite3azCompileOpt[] = {
     #if SQLITE_OMIT_BLOB_LITERAL
       "OMIT_BLOB_LITERAL",
     #endif
    -#if SQLITE_OMIT_BTREECOUNT
    -  "OMIT_BTREECOUNT",
    -#endif
     #if SQLITE_OMIT_CAST
       "OMIT_CAST",
     #endif
    diff --git a/src/date.c b/src/date.c
    index 6a8defc..fff062f 100644
    --- a/src/date.c
    +++ b/src/date.c
    @@ -621,12 +621,12 @@ static const struct {
       double rLimit;      /* Maximum NNN value for this transform */
       double rXform;      /* Constant used for this transform */
     } aXformType[] = {
    -  { 0, 6, "second", 464269060800.0, 86400000.0/(24.0*60.0*60.0) },
    -  { 0, 6, "minute", 7737817680.0,   86400000.0/(24.0*60.0)      },
    -  { 0, 4, "hour",   128963628.0,    86400000.0/24.0             },
    -  { 0, 3, "day",    5373485.0,      86400000.0                  },
    -  { 1, 5, "month",  176546.0,       30.0*86400000.0             },
    -  { 2, 4, "year",   14713.0,        365.0*86400000.0            },
    +  { 0, 6, "second", 464269060800.0, 1000.0         },
    +  { 0, 6, "minute", 7737817680.0,   60000.0        },
    +  { 0, 4, "hour",   128963628.0,    3600000.0      },
    +  { 0, 3, "day",    5373485.0,      86400000.0     },
    +  { 1, 5, "month",  176546.0,       2592000000.0   },
    +  { 2, 4, "year",   14713.0,        31536000000.0  },
     };
     
     /*
    diff --git a/src/dbstat.c b/src/dbstat.c
    index 2fea48c..bddde79 100644
    --- a/src/dbstat.c
    +++ b/src/dbstat.c
    @@ -238,6 +238,7 @@ static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
       i = 0;
       if( iSchema>=0 ){
         pIdxInfo->aConstraintUsage[iSchema].argvIndex = ++i;
    +    pIdxInfo->aConstraintUsage[iSchema].omit = 1;
         pIdxInfo->idxNum |= 0x01;
       }
       if( iName>=0 ){
    @@ -452,7 +453,9 @@ static int statDecodePage(Btree *pBt, StatPage *p){
             if( nPayload>(u32)nLocal ){
               int j;
               int nOvfl = ((nPayload - nLocal) + nUsable-4 - 1) / (nUsable - 4);
    -          if( iOff+nLocal>nUsable ) goto statPageIsCorrupt;
    +          if( iOff+nLocal>nUsable || nPayload>0x7fffffff ){
    +            goto statPageIsCorrupt;
    +          }
               pCell->nLastOvfl = (nPayload-nLocal) - (nOvfl-1) * (nUsable-4);
               pCell->nOvfl = nOvfl;
               pCell->aOvfl = sqlite3_malloc64(sizeof(u32)*nOvfl);
    diff --git a/src/delete.c b/src/delete.c
    index 0a83f1b..141efa5 100644
    --- a/src/delete.c
    +++ b/src/delete.c
    @@ -533,7 +533,9 @@ void sqlite3DeleteFrom(
                                      iTabCur, aToOpen, &iDataCur, &iIdxCur);
           assert( pPk || IsVirtual(pTab) || iDataCur==iTabCur );
           assert( pPk || IsVirtual(pTab) || iIdxCur==iDataCur+1 );
    -      if( eOnePass==ONEPASS_MULTI ) sqlite3VdbeJumpHere(v, iAddrOnce);
    +      if( eOnePass==ONEPASS_MULTI ){
    +        sqlite3VdbeJumpHereOrPopInst(v, iAddrOnce);
    +      }
         }
       
         /* Set up a loop over the rowids/primary-keys that were found in the
    @@ -856,6 +858,7 @@ void sqlite3GenerateRowIndexDelete(
             &iPartIdxLabel, pPrior, r1);
         sqlite3VdbeAddOp3(v, OP_IdxDelete, iIdxCur+i, r1,
             pIdx->uniqNotNull ? pIdx->nKeyCol : pIdx->nColumn);
    +    sqlite3VdbeChangeP5(v, 1);  /* Cause IdxDelete to error if no entry found */
         sqlite3ResolvePartIdxLabel(pParse, iPartIdxLabel);
         pPrior = pIdx;
       }
    diff --git a/src/expr.c b/src/expr.c
    index 46a3f9f..7205f86 100644
    --- a/src/expr.c
    +++ b/src/expr.c
    @@ -42,10 +42,10 @@ char sqlite3TableColumnAffinity(Table *pTab, int iCol){
     ** SELECT a AS b FROM t1 WHERE b;
     ** SELECT * FROM t1 WHERE (select a from t1);
     */
    -char sqlite3ExprAffinity(Expr *pExpr){
    +char sqlite3ExprAffinity(const Expr *pExpr){
       int op;
       while( ExprHasProperty(pExpr, EP_Skip) ){
    -    assert( pExpr->op==TK_COLLATE );
    +    assert( pExpr->op==TK_COLLATE || pExpr->op==TK_IF_NULL_ROW );
         pExpr = pExpr->pLeft;
         assert( pExpr!=0 );
       }
    @@ -112,7 +112,7 @@ Expr *sqlite3ExprAddCollateString(Parse *pParse, Expr *pExpr, const char *zC){
     */
     Expr *sqlite3ExprSkipCollate(Expr *pExpr){
       while( pExpr && ExprHasProperty(pExpr, EP_Skip) ){
    -    assert( pExpr->op==TK_COLLATE );
    +    assert( pExpr->op==TK_COLLATE || pExpr->op==TK_IF_NULL_ROW );
         pExpr = pExpr->pLeft;
       }   
       return pExpr;
    @@ -131,7 +131,7 @@ Expr *sqlite3ExprSkipCollateAndLikely(Expr *pExpr){
           assert( pExpr->op==TK_FUNCTION );
           pExpr = pExpr->x.pList->a[0].pExpr;
         }else{
    -      assert( pExpr->op==TK_COLLATE );
    +      assert( pExpr->op==TK_COLLATE || pExpr->op==TK_IF_NULL_ROW );
           pExpr = pExpr->pLeft;
         }
       }   
    @@ -152,10 +152,10 @@ Expr *sqlite3ExprSkipCollateAndLikely(Expr *pExpr){
     ** COLLATE operators take first precedence.  Left operands take
     ** precedence over right operands.
     */
    -CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr){
    +CollSeq *sqlite3ExprCollSeq(Parse *pParse, const Expr *pExpr){
       sqlite3 *db = pParse->db;
       CollSeq *pColl = 0;
    -  Expr *p = pExpr;
    +  const Expr *p = pExpr;
       while( p ){
         int op = p->op;
         if( op==TK_REGISTER ) op = p->op2;
    @@ -224,7 +224,7 @@ CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr){
     ** The sqlite3ExprCollSeq() routine works the same except that it
     ** returns NULL if there is no defined collation.
     */
    -CollSeq *sqlite3ExprNNCollSeq(Parse *pParse, Expr *pExpr){
    +CollSeq *sqlite3ExprNNCollSeq(Parse *pParse, const Expr *pExpr){
       CollSeq *p = sqlite3ExprCollSeq(pParse, pExpr);
       if( p==0 ) p = pParse->db->pDfltColl;
       assert( p!=0 );
    @@ -234,7 +234,7 @@ CollSeq *sqlite3ExprNNCollSeq(Parse *pParse, Expr *pExpr){
     /*
     ** Return TRUE if the two expressions have equivalent collating sequences.
     */
    -int sqlite3ExprCollSeqMatch(Parse *pParse, Expr *pE1, Expr *pE2){
    +int sqlite3ExprCollSeqMatch(Parse *pParse, const Expr *pE1, const Expr *pE2){
       CollSeq *pColl1 = sqlite3ExprNNCollSeq(pParse, pE1);
       CollSeq *pColl2 = sqlite3ExprNNCollSeq(pParse, pE2);
       return sqlite3StrICmp(pColl1->zName, pColl2->zName)==0;
    @@ -245,7 +245,7 @@ int sqlite3ExprCollSeqMatch(Parse *pParse, Expr *pE1, Expr *pE2){
     ** type affinity of the other operand.  This routine returns the
     ** type affinity that should be used for the comparison operator.
     */
    -char sqlite3CompareAffinity(Expr *pExpr, char aff2){
    +char sqlite3CompareAffinity(const Expr *pExpr, char aff2){
       char aff1 = sqlite3ExprAffinity(pExpr);
       if( aff1>SQLITE_AFF_NONE && aff2>SQLITE_AFF_NONE ){
         /* Both sides of the comparison are columns. If one has numeric
    @@ -267,7 +267,7 @@ char sqlite3CompareAffinity(Expr *pExpr, char aff2){
     ** pExpr is a comparison operator.  Return the type affinity that should
     ** be applied to both operands prior to doing the comparison.
     */
    -static char comparisonAffinity(Expr *pExpr){
    +static char comparisonAffinity(const Expr *pExpr){
       char aff;
       assert( pExpr->op==TK_EQ || pExpr->op==TK_IN || pExpr->op==TK_LT ||
               pExpr->op==TK_GT || pExpr->op==TK_GE || pExpr->op==TK_LE ||
    @@ -290,7 +290,7 @@ static char comparisonAffinity(Expr *pExpr){
     ** if the index with affinity idx_affinity may be used to implement
     ** the comparison in pExpr.
     */
    -int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity){
    +int sqlite3IndexAffinityOk(const Expr *pExpr, char idx_affinity){
       char aff = comparisonAffinity(pExpr);
       if( affpRight, p->pLeft);
       }else{
    @@ -594,6 +598,7 @@ static void codeVectorCompare(
       int addrDone = sqlite3VdbeMakeLabel(pParse);
       int isCommuted = ExprHasProperty(pExpr,EP_Commuted);
     
    +  assert( !ExprHasVVAProperty(pExpr,EP_Immutable) );
       if( pParse->nErr ) return;
       if( nLeft!=sqlite3ExprVectorSize(pRight) ){
         sqlite3ErrorMsg(pParse, "row value misused");
    @@ -1206,7 +1211,7 @@ static int dupedExprStructSize(Expr *p, int flags){
         assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
         assert( !ExprHasProperty(p, EP_FromJoin) ); 
         assert( !ExprHasProperty(p, EP_MemToken) );
    -    assert( !ExprHasProperty(p, EP_NoReduce) );
    +    assert( !ExprHasVVAProperty(p, EP_NoReduce) );
         if( p->pLeft || p->x.pList ){
           nSize = EXPR_REDUCEDSIZE | EP_Reduced;
         }else{
    @@ -1311,6 +1316,10 @@ static Expr *exprDup(sqlite3 *db, Expr *p, int dupFlags, u8 **pzBuffer){
         pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static|EP_MemToken);
         pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly);
         pNew->flags |= staticFlag;
    +    ExprClearVVAProperties(pNew);
    +    if( dupFlags ){
    +      ExprSetVVAProperty(pNew, EP_Immutable);
    +    }
     
         /* Copy the p->u.zToken string, if any. */
         if( nToken ){
    @@ -1778,6 +1787,7 @@ void sqlite3ExprListSetName(
       int dequote             /* True to cause the name to be dequoted */
     ){
       assert( pList!=0 || pParse->db->mallocFailed!=0 );
    +  assert( pParse->eParseMode!=PARSE_MODE_UNMAP || dequote==0 );
       if( pList ){
         struct ExprList_item *pItem;
         assert( pList->nExpr>0 );
    @@ -1785,9 +1795,14 @@ void sqlite3ExprListSetName(
         assert( pItem->zEName==0 );
         assert( pItem->eEName==ENAME_NAME );
         pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
    -    if( dequote ) sqlite3Dequote(pItem->zEName);
    -    if( IN_RENAME_OBJECT ){
    -      sqlite3RenameTokenMap(pParse, (void*)pItem->zEName, pName);
    +    if( dequote ){
    +      /* If dequote==0, then pName->z does not point to part of a DDL
    +      ** statement handled by the parser. And so no token need be added
    +      ** to the token-map.  */
    +      sqlite3Dequote(pItem->zEName);
    +      if( IN_RENAME_OBJECT ){
    +        sqlite3RenameTokenMap(pParse, (void*)pItem->zEName, pName);
    +      }
         }
       }
     }
    @@ -2087,7 +2102,7 @@ int sqlite3ExprIsConstant(Expr *p){
     **
     ** When this routine returns true, it indicates that the expression
     ** can be added to the pParse->pConstExpr list and evaluated once when
    -** the prepared statement starts up.  See sqlite3ExprCodeAtInit().
    +** the prepared statement starts up.  See sqlite3ExprCodeRunJustOnce().
     */
     int sqlite3ExprIsConstantNotJoin(Expr *p){
       return exprIsConst(p, 2, 0);
    @@ -2850,6 +2865,7 @@ void sqlite3CodeRhsOfIN(
     
         /* Begin coding the subroutine */
         ExprSetProperty(pExpr, EP_Subrtn);
    +    assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
         pExpr->y.sub.regReturn = ++pParse->nMem;
         pExpr->y.sub.iAddr =
           sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
    @@ -2931,6 +2947,8 @@ void sqlite3CodeRhsOfIN(
         affinity = sqlite3ExprAffinity(pLeft);
         if( affinity<=SQLITE_AFF_NONE ){
           affinity = SQLITE_AFF_BLOB;
    +    }else if( affinity==SQLITE_AFF_REAL ){
    +      affinity = SQLITE_AFF_NUMERIC;
         }
         if( pKeyInfo ){
           assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
    @@ -3169,7 +3187,9 @@ static void sqlite3ExprCodeIN(
       int destNotNull;      /* Jump here if a comparison is not true in step 6 */
       int addrTop;          /* Top of the step-6 loop */ 
       int iTab = 0;         /* Index to use */
    +  u8 okConstFactor = pParse->okConstFactor;
     
    +  assert( !ExprHasVVAProperty(pExpr,EP_Immutable) );
       pLeft = pExpr->pLeft;
       if( sqlite3ExprCheckIN(pParse, pExpr) ) return;
       zAff = exprINAffinity(pParse, pExpr);
    @@ -3212,8 +3232,14 @@ static void sqlite3ExprCodeIN(
       ** so that the fields are in the same order as an existing index.   The
       ** aiMap[] array contains a mapping from the original LHS field order to
       ** the field order that matches the RHS index.
    -  */
    +  **
    +  ** Avoid factoring the LHS of the IN(...) expression out of the loop,
    +  ** even if it is constant, as OP_Affinity may be used on the register
    +  ** by code generated below.  */
    +  assert( pParse->okConstFactor==okConstFactor );
    +  pParse->okConstFactor = 0;
       rLhsOrig = exprCodeVector(pParse, pLeft, &iDummy);
    +  pParse->okConstFactor = okConstFactor;
       for(i=0; ipLeft)==SQLITE_AFF_REAL;
         for(ii=0; iinExpr; ii++){
    -      if( bLhsReal ){
    -        r2 = regToFree = sqlite3GetTempReg(pParse);
    -        sqlite3ExprCode(pParse, pList->a[ii].pExpr, r2);
    -        sqlite3VdbeAddOp4(v, OP_Affinity, r2, 1, 0, "E", P4_STATIC);
    -      }else{
    -        r2 = sqlite3ExprCodeTemp(pParse, pList->a[ii].pExpr, ®ToFree);
    -      }
    +      r2 = sqlite3ExprCodeTemp(pParse, pList->a[ii].pExpr, ®ToFree);
           if( regCkNull && sqlite3ExprCanBeNull(pList->a[ii].pExpr) ){
             sqlite3VdbeAddOp3(v, OP_BitAnd, regCkNull, r2, regCkNull);
           }
    @@ -3496,7 +3514,7 @@ void sqlite3ExprCodeGeneratedColumn(
       }else{
         iAddr = 0;
       }
    -  sqlite3ExprCode(pParse, pCol->pDflt, regOut);
    +  sqlite3ExprCodeCopy(pParse, pCol->pDflt, regOut);
       if( pCol->affinity>=SQLITE_AFF_TEXT ){
         sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1);
       }
    @@ -3682,6 +3700,13 @@ static int exprCodeInlineFunction(
           sqlite3VdbeResolveLabel(v, endCoalesce);
           break;
         }
    +    case INLINEFUNC_iif: {
    +      Expr caseExpr;
    +      memset(&caseExpr, 0, sizeof(caseExpr));
    +      caseExpr.op = TK_CASE;
    +      caseExpr.x.pList = pFarg;
    +      return sqlite3ExprCodeTarget(pParse, &caseExpr, target);
    +    }
     
         default: {   
           /* The UNLIKELY() function is a no-op.  The result is the value
    @@ -3780,6 +3805,7 @@ expr_code_doover:
       if( pExpr==0 ){
         op = TK_NULL;
       }else{
    +    assert( !ExprHasVVAProperty(pExpr,EP_Immutable) );
         op = pExpr->op;
       }
       switch( op ){
    @@ -3790,8 +3816,17 @@ expr_code_doover:
             assert( pCol->iMem>0 );
             return pCol->iMem;
           }else if( pAggInfo->useSortingIdx ){
    +        Table *pTab = pCol->pTab;
             sqlite3VdbeAddOp3(v, OP_Column, pAggInfo->sortingIdxPTab,
                                   pCol->iSorterColumn, target);
    +        if( pCol->iColumn<0 ){
    +          VdbeComment((v,"%s.rowid",pTab->zName));
    +        }else{
    +          VdbeComment((v,"%s.%s",pTab->zName,pTab->aCol[pCol->iColumn].zName));
    +          if( pTab->aCol[pCol->iColumn].affinity==SQLITE_AFF_REAL ){
    +            sqlite3VdbeAddOp1(v, OP_RealAffinity, target);
    +          }
    +        }
             return target;
           }
           /* Otherwise, fall thru into the TK_COLUMN case */
    @@ -3817,10 +3852,6 @@ expr_code_doover:
               static const char zAff[] = "B\000C\000D\000E";
               assert( SQLITE_AFF_BLOB=='A' );
               assert( SQLITE_AFF_TEXT=='B' );
    -          if( iReg!=target ){
    -            sqlite3VdbeAddOp2(v, OP_SCopy, iReg, target);
    -            iReg = target;
    -          }
               sqlite3VdbeAddOp4(v, OP_Affinity, iReg, 1, 0,
                                 &zAff[(aff-'B')*2], P4_STATIC);
             }
    @@ -4034,6 +4065,7 @@ expr_code_doover:
             tempX.op = TK_INTEGER;
             tempX.flags = EP_IntValue|EP_TokenOnly;
             tempX.u.iValue = 0;
    +        ExprClearVVAProperties(&tempX);
             r1 = sqlite3ExprCodeTemp(pParse, &tempX, ®Free1);
             r2 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, ®Free2);
             sqlite3VdbeAddOp3(v, OP_Subtract, r2, r1, target);
    @@ -4105,16 +4137,13 @@ expr_code_doover:
     #endif
     
           if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){
    -        /* SQL functions can be expensive. So try to move constant functions
    -        ** out of the inner loop, even if that means an extra OP_Copy. */
    -        return sqlite3ExprCodeAtInit(pParse, pExpr, -1);
    +        /* SQL functions can be expensive. So try to avoid running them
    +        ** multiple times if we know they always give the same result */
    +        return sqlite3ExprCodeRunJustOnce(pParse, pExpr, -1);
           }
           assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
    -      if( ExprHasProperty(pExpr, EP_TokenOnly) ){
    -        pFarg = 0;
    -      }else{
    -        pFarg = pExpr->x.pList;
    -      }
    +      assert( !ExprHasProperty(pExpr, EP_TokenOnly) );
    +      pFarg = pExpr->x.pList;
           nFarg = pFarg ? pFarg->nExpr : 0;
           assert( !ExprHasProperty(pExpr, EP_IntValue) );
           zId = pExpr->u.zToken;
    @@ -4460,7 +4489,7 @@ expr_code_doover:
                || pExpr->affExpr==OE_Fail
                || pExpr->affExpr==OE_Ignore
           );
    -      if( !pParse->pTriggerTab ){
    +      if( !pParse->pTriggerTab && !pParse->nested ){
             sqlite3ErrorMsg(pParse,
                            "RAISE() may only be used within a trigger-program");
             return 0;
    @@ -4474,8 +4503,9 @@ expr_code_doover:
                 v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0);
             VdbeCoverage(v);
           }else{
    -        sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_TRIGGER,
    -                              pExpr->affExpr, pExpr->u.zToken, 0, 0);
    +        sqlite3HaltConstraint(pParse,
    +             pParse->pTriggerTab ? SQLITE_CONSTRAINT_TRIGGER : SQLITE_ERROR,
    +             pExpr->affExpr, pExpr->u.zToken, 0, 0);
           }
     
           break;
    @@ -4488,15 +4518,23 @@ expr_code_doover:
     }
     
     /*
    -** Factor out the code of the given expression to initialization time.
    +** Generate code that will evaluate expression pExpr just one time
    +** per prepared statement execution.
    +**
    +** If the expression uses functions (that might throw an exception) then
    +** guard them with an OP_Once opcode to ensure that the code is only executed
    +** once. If no functions are involved, then factor the code out and put it at
    +** the end of the prepared statement in the initialization section.
     **
     ** If regDest>=0 then the result is always stored in that register and the
     ** result is not reusable.  If regDest<0 then this routine is free to 
     ** store the value whereever it wants.  The register where the expression 
    -** is stored is returned.  When regDest<0, two identical expressions will
    -** code to the same register.
    +** is stored is returned.  When regDest<0, two identical expressions might
    +** code to the same register, if they do not contain function calls and hence
    +** are factored out into the initialization section at the end of the
    +** prepared statement.
     */
    -int sqlite3ExprCodeAtInit(
    +int sqlite3ExprCodeRunJustOnce(
       Parse *pParse,    /* Parsing context */
       Expr *pExpr,      /* The expression to code when the VDBE initializes */
       int regDest       /* Store the value in this register */
    @@ -4514,14 +4552,29 @@ int sqlite3ExprCodeAtInit(
         }
       }
       pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
    -  p = sqlite3ExprListAppend(pParse, p, pExpr);
    -  if( p ){
    -     struct ExprList_item *pItem = &p->a[p->nExpr-1];
    -     pItem->reusable = regDest<0;
    -     if( regDest<0 ) regDest = ++pParse->nMem;
    -     pItem->u.iConstExprReg = regDest;
    +  if( pExpr!=0 && ExprHasProperty(pExpr, EP_HasFunc) ){
    +    Vdbe *v = pParse->pVdbe;
    +    int addr;
    +    assert( v );
    +    addr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
    +    pParse->okConstFactor = 0;
    +    if( !pParse->db->mallocFailed ){
    +      if( regDest<0 ) regDest = ++pParse->nMem;
    +      sqlite3ExprCode(pParse, pExpr, regDest);
    +    }
    +    pParse->okConstFactor = 1;
    +    sqlite3ExprDelete(pParse->db, pExpr);
    +    sqlite3VdbeJumpHere(v, addr);
    +  }else{
    +    p = sqlite3ExprListAppend(pParse, p, pExpr);
    +    if( p ){
    +       struct ExprList_item *pItem = &p->a[p->nExpr-1];
    +       pItem->reusable = regDest<0;
    +       if( regDest<0 ) regDest = ++pParse->nMem;
    +       pItem->u.iConstExprReg = regDest;
    +    }
    +    pParse->pConstExpr = p;
       }
    -  pParse->pConstExpr = p;
       return regDest;
     }
     
    @@ -4546,7 +4599,7 @@ int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
        && sqlite3ExprIsConstantNotJoin(pExpr)
       ){
         *pReg  = 0;
    -    r2 = sqlite3ExprCodeAtInit(pParse, pExpr, -1);
    +    r2 = sqlite3ExprCodeRunJustOnce(pParse, pExpr, -1);
       }else{
         int r1 = sqlite3GetTempReg(pParse);
         r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
    @@ -4568,6 +4621,7 @@ int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
     void sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
       int inReg;
     
    +  assert( pExpr==0 || !ExprHasVVAProperty(pExpr,EP_Immutable) );
       assert( target>0 && target<=pParse->nMem );
       inReg = sqlite3ExprCodeTarget(pParse, pExpr, target);
       assert( pParse->pVdbe!=0 || pParse->db->mallocFailed );
    @@ -4602,9 +4656,9 @@ void sqlite3ExprCodeCopy(Parse *pParse, Expr *pExpr, int target){
     */
     void sqlite3ExprCodeFactorable(Parse *pParse, Expr *pExpr, int target){
       if( pParse->okConstFactor && sqlite3ExprIsConstantNotJoin(pExpr) ){
    -    sqlite3ExprCodeAtInit(pParse, pExpr, target);
    +    sqlite3ExprCodeRunJustOnce(pParse, pExpr, target);
       }else{
    -    sqlite3ExprCode(pParse, pExpr, target);
    +    sqlite3ExprCodeCopy(pParse, pExpr, target);
       }
     }
     
    @@ -4662,7 +4716,7 @@ int sqlite3ExprCodeExprList(
         }else if( (flags & SQLITE_ECEL_FACTOR)!=0
                && sqlite3ExprIsConstantNotJoin(pExpr)
         ){
    -      sqlite3ExprCodeAtInit(pParse, pExpr, target+i);
    +      sqlite3ExprCodeRunJustOnce(pParse, pExpr, target+i);
         }else{
           int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
           if( inReg!=target+i ){
    @@ -4785,6 +4839,7 @@ void sqlite3ExprIfTrue(Parse *pParse, Expr *pExpr, int dest, int jumpIfNull){
       assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
       if( NEVER(v==0) )     return;  /* Existence of VDBE checked by caller */
       if( NEVER(pExpr==0) ) return;  /* No way this can happen */
    +  assert( !ExprHasVVAProperty(pExpr, EP_Immutable) );
       op = pExpr->op;
       switch( op ){
         case TK_AND:
    @@ -4926,6 +4981,7 @@ void sqlite3ExprIfFalse(Parse *pParse, Expr *pExpr, int dest, int jumpIfNull){
       assert( jumpIfNull==SQLITE_JUMPIFNULL || jumpIfNull==0 );
       if( NEVER(v==0) ) return; /* Existence of VDBE checked by caller */
       if( pExpr==0 )    return;
    +  assert( !ExprHasVVAProperty(pExpr,EP_Immutable) );
     
       /* The value of pExpr->op and op are related as follows:
       **
    @@ -5209,7 +5265,7 @@ int sqlite3ExprCompare(Parse *pParse, Expr *pA, Expr *pB, int iTab){
       }
       if( (pA->flags & (EP_Distinct|EP_Commuted))
          != (pB->flags & (EP_Distinct|EP_Commuted)) ) return 2;
    -  if( (combinedFlags & EP_TokenOnly)==0 ){
    +  if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
         if( combinedFlags & EP_xIsSelect ) return 2;
         if( (combinedFlags & EP_FixedCol)==0
          && sqlite3ExprCompare(pParse, pA->pLeft, pB->pLeft, iTab) ) return 2;
    @@ -5217,24 +5273,10 @@ int sqlite3ExprCompare(Parse *pParse, Expr *pA, Expr *pB, int iTab){
         if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
         if( pA->op!=TK_STRING
          && pA->op!=TK_TRUEFALSE
    -     && (combinedFlags & EP_Reduced)==0
    +     && ALWAYS((combinedFlags & EP_Reduced)==0)
         ){
           if( pA->iColumn!=pB->iColumn ) return 2;
    -      if( pA->op2!=pB->op2 ){
    -        if( pA->op==TK_TRUTH ) return 2;
    -        if( pA->op==TK_FUNCTION && iTab<0 ){
    -          /* Ex: CREATE TABLE t1(a CHECK( aop2!=pB->op2 && pA->op==TK_TRUTH ) return 2;
           if( pA->op!=TK_IN && pA->iTable!=pB->iTable && pA->iTable!=iTab ){
             return 2;
           }
    @@ -5472,19 +5514,25 @@ static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
         case TK_LT:
         case TK_LE:
         case TK_GT:
    -    case TK_GE:
    +    case TK_GE: {
    +      Expr *pLeft = pExpr->pLeft;
    +      Expr *pRight = pExpr->pRight;
           testcase( pExpr->op==TK_EQ );
           testcase( pExpr->op==TK_NE );
           testcase( pExpr->op==TK_LT );
           testcase( pExpr->op==TK_LE );
           testcase( pExpr->op==TK_GT );
           testcase( pExpr->op==TK_GE );
    -      if( (pExpr->pLeft->op==TK_COLUMN && IsVirtual(pExpr->pLeft->y.pTab))
    -       || (pExpr->pRight->op==TK_COLUMN && IsVirtual(pExpr->pRight->y.pTab))
    +      /* The y.pTab=0 assignment in wherecode.c always happens after the
    +      ** impliesNotNullRow() test */
    +      if( (pLeft->op==TK_COLUMN && ALWAYS(pLeft->y.pTab!=0)
    +                               && IsVirtual(pLeft->y.pTab))
    +       || (pRight->op==TK_COLUMN && ALWAYS(pRight->y.pTab!=0)
    +                               && IsVirtual(pRight->y.pTab))
           ){
    -       return WRC_Prune;
    +        return WRC_Prune;
           }
    -
    +    }
         default:
           return WRC_Continue;
       }
    diff --git a/src/fkey.c b/src/fkey.c
    index 9698d34..7bc20fe 100644
    --- a/src/fkey.c
    +++ b/src/fkey.c
    @@ -658,7 +658,7 @@ static void fkScanChildren(
       /* Clean up the WHERE clause constructed above. */
       sqlite3ExprDelete(db, pWhere);
       if( iFkIfZero ){
    -    sqlite3VdbeJumpHere(v, iFkIfZero);
    +    sqlite3VdbeJumpHereOrPopInst(v, iFkIfZero);
       }
     }
     
    diff --git a/src/func.c b/src/func.c
    index 966a007..48b5f5f 100644
    --- a/src/func.c
    +++ b/src/func.c
    @@ -853,6 +853,7 @@ static void likeFunc(
       int nPat;
       sqlite3 *db = sqlite3_context_db_handle(context);
       struct compareInfo *pInfo = sqlite3_user_data(context);
    +  struct compareInfo backupInfo;
     
     #ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS
       if( sqlite3_value_type(argv[0])==SQLITE_BLOB
    @@ -888,6 +889,12 @@ static void likeFunc(
           return;
         }
         escape = sqlite3Utf8Read(&zEsc);
    +    if( escape==pInfo->matchAll || escape==pInfo->matchOne ){
    +      memcpy(&backupInfo, pInfo, sizeof(backupInfo));
    +      pInfo = &backupInfo;
    +      if( escape==pInfo->matchAll ) pInfo->matchAll = 0;
    +      if( escape==pInfo->matchOne ) pInfo->matchOne = 0;
    +    }
       }else{
         escape = pInfo->matchSet;
       }
    @@ -1276,7 +1283,7 @@ static void replaceFunc(
               ** whose index is a power of two: 1, 2, 4, 8, 16, 32, ... */
               u8 *zOld;
               zOld = zOut;
    -          zOut = sqlite3_realloc64(zOut, (int)nOut + (nOut - nStr - 1));
    +          zOut = sqlite3Realloc(zOut, (int)nOut + (nOut - nStr - 1));
               if( zOut==0 ){
                 sqlite3_result_error_nomem(context);
                 sqlite3_free(zOld);
    @@ -1870,16 +1877,6 @@ int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
       if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){
         return 0;
       }
    -  if( nExpr<3 ){
    -    aWc[3] = 0;
    -  }else{
    -    Expr *pEscape = pExpr->x.pList->a[2].pExpr;
    -    char *zEscape;
    -    if( pEscape->op!=TK_STRING ) return 0;
    -    zEscape = pEscape->u.zToken;
    -    if( zEscape[0]==0 || zEscape[1]!=0 ) return 0;
    -    aWc[3] = zEscape[0];
    -  }
     
       /* The memcpy() statement assumes that the wildcard characters are
       ** the first three statements in the compareInfo structure.  The
    @@ -1889,6 +1886,20 @@ int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
       assert( (char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll );
       assert( &((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne );
       assert( &((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet );
    +
    +  if( nExpr<3 ){
    +    aWc[3] = 0;
    +  }else{
    +    Expr *pEscape = pExpr->x.pList->a[2].pExpr;
    +    char *zEscape;
    +    if( pEscape->op!=TK_STRING ) return 0;
    +    zEscape = pEscape->u.zToken;
    +    if( zEscape[0]==0 || zEscape[1]!=0 ) return 0;
    +    if( zEscape[0]==aWc[0] ) return 0;
    +    if( zEscape[0]==aWc[1] ) return 0;
    +    aWc[3] = zEscape[0];
    +  }
    +
       *pIsNocase = (pDef->funcFlags & SQLITE_FUNC_CASE)==0;
       return 1;
     }
    @@ -1969,7 +1980,7 @@ void sqlite3RegisterBuiltinFunctions(void){
         FUNCTION(upper,              1, 0, 0, upperFunc        ),
         FUNCTION(lower,              1, 0, 0, lowerFunc        ),
         FUNCTION(hex,                1, 0, 0, hexFunc          ),
    -    INLINE_FUNC(ifnull,          2, INLINEFUNC_coalesce, SQLITE_FUNC_COALESCE),
    +    INLINE_FUNC(ifnull,          2, INLINEFUNC_coalesce, 0 ),
         VFUNCTION(random,            0, 0, 0, randomFunc       ),
         VFUNCTION(randomblob,        1, 0, 0, randomBlob       ),
         FUNCTION(nullif,             2, 0, 1, nullifFunc       ),
    @@ -2009,7 +2020,8 @@ void sqlite3RegisterBuiltinFunctions(void){
     #endif
         FUNCTION(coalesce,           1, 0, 0, 0                ),
         FUNCTION(coalesce,           0, 0, 0, 0                ),
    -    INLINE_FUNC(coalesce,       -1, INLINEFUNC_coalesce, SQLITE_FUNC_COALESCE),
    +    INLINE_FUNC(coalesce,       -1, INLINEFUNC_coalesce, 0 ),
    +    INLINE_FUNC(iif,             3, INLINEFUNC_iif,      0 ),
       };
     #ifndef SQLITE_OMIT_ALTERTABLE
       sqlite3AlterFunctions();
    diff --git a/src/insert.c b/src/insert.c
    index 43d2f11..f4049fb 100644
    --- a/src/insert.c
    +++ b/src/insert.c
    @@ -1606,7 +1606,7 @@ void sqlite3GenerateConstraintChecks(
                 VdbeCoverage(v);
                 assert( (pCol->colFlags & COLFLAG_GENERATED)==0 );
                 nSeenReplace++;
    -            sqlite3ExprCode(pParse, pCol->pDflt, iReg);
    +            sqlite3ExprCodeCopy(pParse, pCol->pDflt, iReg);
                 sqlite3VdbeJumpHere(v, addr1);
                 break;
               }
    @@ -1661,6 +1661,7 @@ void sqlite3GenerateConstraintChecks(
         onError = overrideError!=OE_Default ? overrideError : OE_Abort;
         for(i=0; inExpr; i++){
           int allOk;
    +      Expr *pCopy;
           Expr *pExpr = pCheck->a[i].pExpr;
           if( aiChng
            && !sqlite3ExprReferencesUpdatedColumn(pExpr, aiChng, pkChng)
    @@ -1675,7 +1676,11 @@ void sqlite3GenerateConstraintChecks(
           }
           allOk = sqlite3VdbeMakeLabel(pParse);
           sqlite3VdbeVerifyAbortable(v, onError);
    -      sqlite3ExprIfTrue(pParse, pExpr, allOk, SQLITE_JUMPIFNULL);
    +      pCopy = sqlite3ExprDup(db, pExpr, 0);
    +      if( !db->mallocFailed ){
    +        sqlite3ExprIfTrue(pParse, pCopy, allOk, SQLITE_JUMPIFNULL);
    +      }
    +      sqlite3ExprDelete(db, pCopy);
           if( onError==OE_Ignore ){
             sqlite3VdbeGoto(v, ignoreDest);
           }else{
    diff --git a/src/loadext.c b/src/loadext.c
    index 245e9b0..067c47c 100644
    --- a/src/loadext.c
    +++ b/src/loadext.c
    @@ -474,8 +474,20 @@ static const sqlite3_api_routines sqlite3Apis = {
       sqlite3_filename_database,
       sqlite3_filename_journal,
       sqlite3_filename_wal,
    +  /* Version 3.32.0 and later */
    +  sqlite3_create_filename,
    +  sqlite3_free_filename,
    +  sqlite3_database_file_object,
     };
     
    +/* True if x is the directory separator character
    +*/
    +#if SQLITE_OS_WIN
    +# define DirSep(X)  ((X)=='/'||(X)=='\\')
    +#else
    +# define DirSep(X)  ((X)=='/')
    +#endif
    +
     /*
     ** Attempt to load an SQLite extension library contained in the file
     ** zFile.  The entry point is zProc.  zProc may be 0 in which case a
    @@ -577,7 +589,7 @@ static int sqlite3LoadExtension(
           return SQLITE_NOMEM_BKPT;
         }
         memcpy(zAltEntry, "sqlite3_", 8);
    -    for(iFile=ncFile-1; iFile>=0 && zFile[iFile]!='/'; iFile--){}
    +    for(iFile=ncFile-1; iFile>=0 && !DirSep(zFile[iFile]); iFile--){}
         iFile++;
         if( sqlite3_strnicmp(zFile+iFile, "lib", 3)==0 ) iFile += 3;
         for(iEntry=8; (c = zFile[iFile])!=0 && c!='.'; iFile++){
    diff --git a/src/main.c b/src/main.c
    index 3eccd08..9f99cbd 100644
    --- a/src/main.c
    +++ b/src/main.c
    @@ -25,15 +25,78 @@
     #if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS)
     # include "sqliteicu.h"
     #endif
    +
    +/*
    +** This is an extension initializer that is a no-op and always
    +** succeeds, except that it fails if the fault-simulation is set
    +** to 500.
    +*/
    +static int sqlite3TestExtInit(sqlite3 *db){
    +  (void)db;
    +  return sqlite3FaultSim(500);
    +}
    +
    +
    +/*
    +** Forward declarations of external module initializer functions
    +** for modules that need them.
    +*/
    +#ifdef SQLITE_ENABLE_FTS1
    +int sqlite3Fts1Init(sqlite3*);
    +#endif
    +#ifdef SQLITE_ENABLE_FTS2
    +int sqlite3Fts2Init(sqlite3*);
    +#endif
    +#ifdef SQLITE_ENABLE_FTS5
    +int sqlite3Fts5Init(sqlite3*);
    +#endif
     #ifdef SQLITE_ENABLE_JSON1
     int sqlite3Json1Init(sqlite3*);
     #endif
     #ifdef SQLITE_ENABLE_STMTVTAB
     int sqlite3StmtVtabInit(sqlite3*);
     #endif
    -#ifdef SQLITE_ENABLE_FTS5
    -int sqlite3Fts5Init(sqlite3*);
    +
    +/*
    +** An array of pointers to extension initializer functions for
    +** built-in extensions.
    +*/
    +static int (*const sqlite3BuiltinExtensions[])(sqlite3*) = {
    +#ifdef SQLITE_ENABLE_FTS1
    +  sqlite3Fts1Init,
     #endif
    +#ifdef SQLITE_ENABLE_FTS2
    +  sqlite3Fts2Init,
    +#endif
    +#ifdef SQLITE_ENABLE_FTS3
    +  sqlite3Fts3Init,
    +#endif
    +#ifdef SQLITE_ENABLE_FTS5
    +  sqlite3Fts5Init,
    +#endif
    +#if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS)
    +  sqlite3IcuInit,
    +#endif
    +#ifdef SQLITE_ENABLE_RTREE
    +  sqlite3RtreeInit,
    +#endif
    +#ifdef SQLITE_ENABLE_DBPAGE_VTAB
    +  sqlite3DbpageRegister,
    +#endif
    +#ifdef SQLITE_ENABLE_DBSTAT_VTAB
    +  sqlite3DbstatRegister,
    +#endif
    +  sqlite3TestExtInit,
    +#ifdef SQLITE_ENABLE_JSON1
    +  sqlite3Json1Init,
    +#endif
    +#ifdef SQLITE_ENABLE_STMTVTAB
    +  sqlite3StmtVtabInit,
    +#endif
    +#ifdef SQLITE_ENABLE_BYTECODE_VTAB
    +  sqlite3VdbeBytecodeVtabInit,
    +#endif
    +};
     
     #ifndef SQLITE_AMALGAMATION
     /* IMPLEMENTATION-OF: R-46656-45156 The sqlite3_version[] string constant
    @@ -250,6 +313,7 @@ int sqlite3_initialize(void){
         if( rc==SQLITE_OK ){
           sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage, 
               sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage);
    +      sqlite3MemoryBarrier();
           sqlite3GlobalConfig.isInit = 1;
     #ifdef SQLITE_EXTRA_INIT
           bRunExtraInit = 1;
    @@ -1551,8 +1615,7 @@ const char *sqlite3ErrStr(int rc){
     */
     static int sqliteDefaultBusyCallback(
       void *ptr,               /* Database connection */
    -  int count,               /* Number of times table has been busy */
    -  sqlite3_file *pFile      /* The file on which the lock occurred */
    +  int count                /* Number of times table has been busy */
     ){
     #if SQLITE_OS_WIN || HAVE_USLEEP
       /* This case is for systems that have support for sleeping for fractions of
    @@ -1566,19 +1629,6 @@ static int sqliteDefaultBusyCallback(
       int tmout = db->busyTimeout;
       int delay, prior;
     
    -#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
    -  if( sqlite3OsFileControl(pFile,SQLITE_FCNTL_LOCK_TIMEOUT,&tmout)==SQLITE_OK ){
    -    if( count ){
    -      tmout = 0;
    -      sqlite3OsFileControl(pFile, SQLITE_FCNTL_LOCK_TIMEOUT, &tmout);
    -      return 0;
    -    }else{
    -      return 1;
    -    }
    -  }
    -#else
    -  UNUSED_PARAMETER(pFile);
    -#endif
       assert( count>=0 );
       if( count < NDELAY ){
         delay = delays[count];
    @@ -1598,7 +1648,6 @@ static int sqliteDefaultBusyCallback(
       ** must be done in increments of whole seconds */
       sqlite3 *db = (sqlite3 *)ptr;
       int tmout = ((sqlite3 *)ptr)->busyTimeout;
    -  UNUSED_PARAMETER(pFile);
       if( (count+1)*1000 > tmout ){
         return 0;
       }
    @@ -1616,19 +1665,10 @@ static int sqliteDefaultBusyCallback(
     ** If this routine returns non-zero, the lock is retried.  If it
     ** returns 0, the operation aborts with an SQLITE_BUSY error.
     */
    -int sqlite3InvokeBusyHandler(BusyHandler *p, sqlite3_file *pFile){
    +int sqlite3InvokeBusyHandler(BusyHandler *p){
       int rc;
       if( p->xBusyHandler==0 || p->nBusy<0 ) return 0;
    -  if( p->bExtraFileArg ){
    -    /* Add an extra parameter with the pFile pointer to the end of the
    -    ** callback argument list */
    -    int (*xTra)(void*,int,sqlite3_file*);
    -    xTra = (int(*)(void*,int,sqlite3_file*))p->xBusyHandler;
    -    rc = xTra(p->pBusyArg, p->nBusy, pFile);
    -  }else{
    -    /* Legacy style busy handler callback */
    -    rc = p->xBusyHandler(p->pBusyArg, p->nBusy);
    -  }
    +  rc = p->xBusyHandler(p->pBusyArg, p->nBusy);
       if( rc==0 ){
         p->nBusy = -1;
       }else{
    @@ -1653,7 +1693,6 @@ int sqlite3_busy_handler(
       db->busyHandler.xBusyHandler = xBusy;
       db->busyHandler.pBusyArg = pArg;
       db->busyHandler.nBusy = 0;
    -  db->busyHandler.bExtraFileArg = 0;
       db->busyTimeout = 0;
       sqlite3_mutex_leave(db->mutex);
       return SQLITE_OK;
    @@ -1704,7 +1743,6 @@ int sqlite3_busy_timeout(sqlite3 *db, int ms){
         sqlite3_busy_handler(db, (int(*)(void*,int))sqliteDefaultBusyCallback,
                                  (void*)db);
         db->busyTimeout = ms;
    -    db->busyHandler.bExtraFileArg = 1;
       }else{
         sqlite3_busy_handler(db, 0, 0);
       }
    @@ -1721,7 +1759,7 @@ void sqlite3_interrupt(sqlite3 *db){
         return;
       }
     #endif
    -  db->u1.isInterrupted = 1;
    +  AtomicStore(&db->u1.isInterrupted, 1);
     }
     
     
    @@ -2343,7 +2381,7 @@ int sqlite3_wal_checkpoint_v2(
       /* If there are no active statements, clear the interrupt flag at this
       ** point.  */
       if( db->nVdbeActive==0 ){
    -    db->u1.isInterrupted = 0;
    +    AtomicStore(&db->u1.isInterrupted, 0);
       }
     
       sqlite3_mutex_leave(db->mutex);
    @@ -2753,9 +2791,11 @@ int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
     **
     ** If successful, SQLITE_OK is returned. In this case *ppVfs is set to point to
     ** the VFS that should be used to open the database file. *pzFile is set to
    -** point to a buffer containing the name of the file to open. It is the 
    -** responsibility of the caller to eventually call sqlite3_free() to release
    -** this buffer.
    +** point to a buffer containing the name of the file to open.  The value
    +** stored in *pzFile is a database name acceptable to sqlite3_uri_parameter()
    +** and is in the same format as names created using sqlite3_create_filename().
    +** The caller must invoke sqlite3_free_filename() (not sqlite3_free()!) on
    +** the value returned in *pzFile to avoid a memory leak.
     **
     ** If an error occurs, then an SQLite error code is returned and *pzErrMsg
     ** may be set to point to a buffer containing an English language error 
    @@ -2787,7 +2827,7 @@ int sqlite3ParseUri(
         int eState;                   /* Parser state when parsing URI */
         int iIn;                      /* Input character index */
         int iOut = 0;                 /* Output character index */
    -    u64 nByte = nUri+2;           /* Bytes of space to allocate */
    +    u64 nByte = nUri+8;           /* Bytes of space to allocate */
     
         /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen 
         ** method that there may be extra parameters following the file-name.  */
    @@ -2797,6 +2837,9 @@ int sqlite3ParseUri(
         zFile = sqlite3_malloc64(nByte);
         if( !zFile ) return SQLITE_NOMEM_BKPT;
     
    +    memset(zFile, 0, 4);  /* 4-byte of 0x00 is the start of DB name marker */
    +    zFile += 4;
    +
         iIn = 5;
     #ifdef SQLITE_ALLOW_URI_AUTHORITY
         if( strncmp(zUri+5, "///", 3)==0 ){
    @@ -2886,8 +2929,7 @@ int sqlite3ParseUri(
           zFile[iOut++] = c;
         }
         if( eState==1 ) zFile[iOut++] = '\0';
    -    zFile[iOut++] = '\0';
    -    zFile[iOut++] = '\0';
    +    memset(zFile+iOut, 0, 4); /* end-of-options + empty journal filenames */
     
         /* Check if there were any options specified that should be interpreted 
         ** here. Options that are interpreted here include "vfs" and those that
    @@ -2967,13 +3009,14 @@ int sqlite3ParseUri(
         }
     
       }else{
    -    zFile = sqlite3_malloc64(nUri+2);
    +    zFile = sqlite3_malloc64(nUri+8);
         if( !zFile ) return SQLITE_NOMEM_BKPT;
    +    memset(zFile, 0, 4);
    +    zFile += 4;
         if( nUri ){
           memcpy(zFile, zUri, nUri);
         }
    -    zFile[nUri] = '\0';
    -    zFile[nUri+1] = '\0';
    +    memset(zFile+nUri, 0, 4);
         flags &= ~SQLITE_OPEN_URI;
       }
     
    @@ -2984,7 +3027,7 @@ int sqlite3ParseUri(
       }
      parse_uri_out:
       if( rc!=SQLITE_OK ){
    -    sqlite3_free(zFile);
    +    sqlite3_free_filename(zFile);
         zFile = 0;
       }
       *pFlags = flags;
    @@ -3025,6 +3068,7 @@ static int openDatabase(
       int isThreadsafe;               /* True for threadsafe connections */
       char *zOpen = 0;                /* Filename argument to pass to BtreeOpen() */
       char *zErrMsg = 0;              /* Error message from sqlite3ParseUri() */
    +  int i;                          /* Loop counter */
     
     #ifdef SQLITE_ENABLE_API_ARMOR
       if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
    @@ -3172,6 +3216,9 @@ static int openDatabase(
     #endif
     #if defined(SQLITE_DEFAULT_DEFENSIVE)
                      | SQLITE_Defensive
    +#endif
    +#if defined(SQLITE_DEFAULT_LEGACY_ALTER_TABLE)
    +                 | SQLITE_LegacyAlter
     #endif
           ;
       sqlite3HashInit(&db->aCollSeq);
    @@ -3194,11 +3241,6 @@ static int openDatabase(
       if( db->mallocFailed ){
         goto opendb_out;
       }
    -  /* EVIDENCE-OF: R-08308-17224 The default collating function for all
    -  ** strings is BINARY. 
    -  */
    -  db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, sqlite3StrBINARY, 0);
    -  assert( db->pDfltColl!=0 );
     
       /* Parse the filename/URI argument
       **
    @@ -3220,7 +3262,7 @@ static int openDatabase(
       testcase( (1<<(flags&7))==0x04 ); /* READWRITE */
       testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */
       if( ((1<<(flags&7)) & 0x46)==0 ){
    -    rc = SQLITE_MISUSE_BKPT;  /* IMP: R-65497-44594 */
    +    rc = SQLITE_MISUSE_BKPT;  /* IMP: R-18321-05872 */
       }else{
         rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg);
       }
    @@ -3243,7 +3285,9 @@ static int openDatabase(
       }
       sqlite3BtreeEnter(db->aDb[0].pBt);
       db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
    -  if( !db->mallocFailed ) ENC(db) = SCHEMA_ENC(db);
    +  if( !db->mallocFailed ){
    +    sqlite3SetTextEncoding(db, SCHEMA_ENC(db));
    +  }
       sqlite3BtreeLeave(db->aDb[0].pBt);
       db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
     
    @@ -3268,14 +3312,11 @@ static int openDatabase(
       sqlite3RegisterPerConnectionBuiltinFunctions(db);
       rc = sqlite3_errcode(db);
     
    -#ifdef SQLITE_ENABLE_FTS5
    -  /* Register any built-in FTS5 module before loading the automatic
    -  ** extensions. This allows automatic extensions to register FTS5 
    -  ** tokenizers and auxiliary functions.  */
    -  if( !db->mallocFailed && rc==SQLITE_OK ){
    -    rc = sqlite3Fts5Init(db);
    +
    +  /* Load compiled-in extensions */
    +  for(i=0; rc==SQLITE_OK && imallocFailed ){
    -    extern int sqlite3Fts1Init(sqlite3*);
    -    rc = sqlite3Fts1Init(db);
    -  }
    -#endif
    -
    -#ifdef SQLITE_ENABLE_FTS2
    -  if( !db->mallocFailed && rc==SQLITE_OK ){
    -    extern int sqlite3Fts2Init(sqlite3*);
    -    rc = sqlite3Fts2Init(db);
    -  }
    -#endif
    -
    -#ifdef SQLITE_ENABLE_FTS3 /* automatically defined by SQLITE_ENABLE_FTS4 */
    -  if( !db->mallocFailed && rc==SQLITE_OK ){
    -    rc = sqlite3Fts3Init(db);
    -  }
    -#endif
    -
    -#if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS)
    -  if( !db->mallocFailed && rc==SQLITE_OK ){
    -    rc = sqlite3IcuInit(db);
    -  }
    -#endif
    -
    -#ifdef SQLITE_ENABLE_RTREE
    -  if( !db->mallocFailed && rc==SQLITE_OK){
    -    rc = sqlite3RtreeInit(db);
    -  }
    -#endif
    -
    -#ifdef SQLITE_ENABLE_DBPAGE_VTAB
    -  if( !db->mallocFailed && rc==SQLITE_OK){
    -    rc = sqlite3DbpageRegister(db);
    -  }
    -#endif
    -
    -#ifdef SQLITE_ENABLE_DBSTAT_VTAB
    -  if( !db->mallocFailed && rc==SQLITE_OK){
    -    rc = sqlite3DbstatRegister(db);
    -  }
    -#endif
    -
    -#ifdef SQLITE_ENABLE_JSON1
    -  if( !db->mallocFailed && rc==SQLITE_OK){
    -    rc = sqlite3Json1Init(db);
    -  }
    -#endif
    -
    -#ifdef SQLITE_ENABLE_STMTVTAB
    -  if( !db->mallocFailed && rc==SQLITE_OK){
    -    rc = sqlite3StmtVtabInit(db);
    -  }
    -#endif
    -
     #ifdef SQLITE_ENABLE_INTERNAL_FUNCTIONS
       /* Testing use only!!! The -DSQLITE_ENABLE_INTERNAL_FUNCTIONS=1 compile-time
       ** option gives access to internal functions by default.  
    @@ -3391,7 +3376,7 @@ opendb_out:
         sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0);
       }
     #endif
    -  sqlite3_free(zOpen);
    +  sqlite3_free_filename(zOpen);
       return rc & 0xff;
     }
     
    @@ -3829,6 +3814,13 @@ int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
         }else if( op==SQLITE_FCNTL_DATA_VERSION ){
           *(unsigned int*)pArg = sqlite3PagerDataVersion(pPager);
           rc = SQLITE_OK;
    +    }else if( op==SQLITE_FCNTL_RESERVE_BYTES ){
    +      int iNew = *(int*)pArg;
    +      *(int*)pArg = sqlite3BtreeGetRequestedReserve(pBtree);
    +      if( iNew>=0 && iNew<=255 ){
    +        sqlite3BtreeSetPageSize(pBtree, 0, iNew, 0);
    +      }
    +      rc = SQLITE_OK;
         }else{
           rc = sqlite3OsFileControl(fd, op, pArg);
         }
    @@ -4045,20 +4037,6 @@ int sqlite3_test_control(int op, ...){
           break;
         }
     
    -    /*   sqlite3_test_control(SQLITE_TESTCTRL_RESERVE, sqlite3 *db, int N)
    -    **
    -    ** Set the nReserve size to N for the main database on the database
    -    ** connection db.
    -    */
    -    case SQLITE_TESTCTRL_RESERVE: {
    -      sqlite3 *db = va_arg(ap, sqlite3*);
    -      int x = va_arg(ap,int);
    -      sqlite3_mutex_enter(db->mutex);
    -      sqlite3BtreeSetPageSize(db->aDb[0].pBt, 0, x, 0);
    -      sqlite3_mutex_leave(db->mutex);
    -      break;
    -    }
    -
         /*  sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, sqlite3 *db, int N)
         **
         ** Enable or disable various optimizations for testing purposes.  The 
    @@ -4242,6 +4220,68 @@ static const char *databaseName(const char *zName){
       return zName;
     }
     
    +/*
    +** Append text z[] to the end of p[].  Return a pointer to the first
    +** character after then zero terminator on the new text in p[].
    +*/
    +static char *appendText(char *p, const char *z){
    +  size_t n = strlen(z);
    +  memcpy(p, z, n+1);
    +  return p+n+1;
    +}
    +
    +/*
    +** Allocate memory to hold names for a database, journal file, WAL file,
    +** and query parameters.  The pointer returned is valid for use by
    +** sqlite3_filename_database() and sqlite3_uri_parameter() and related
    +** functions.
    +**
    +** Memory layout must be compatible with that generated by the pager
    +** and expected by sqlite3_uri_parameter() and databaseName().
    +*/
    +char *sqlite3_create_filename(
    +  const char *zDatabase,
    +  const char *zJournal,
    +  const char *zWal,
    +  int nParam,
    +  const char **azParam
    +){
    +  sqlite3_int64 nByte;
    +  int i;
    +  char *pResult, *p;
    +  nByte = strlen(zDatabase) + strlen(zJournal) + strlen(zWal) + 10;
    +  for(i=0; i0 && n<=nUsed);
    +  AtomicStore(&mem0.nearlyFull, n>0 && n<=nUsed);
       sqlite3_mutex_leave(mem0.mutex);
       excess = sqlite3_memory_used() - n;
       if( excess>0 ) sqlite3_release_memory((int)(excess & 0x7fffffff));
    @@ -179,7 +179,7 @@ int sqlite3MallocInit(void){
     ** sqlite3_soft_heap_limit().
     */
     int sqlite3HeapNearlyFull(void){
    -  return mem0.nearlyFull;
    +  return AtomicLoad(&mem0.nearlyFull);
     }
     
     /*
    @@ -243,7 +243,7 @@ static void mallocWithAlarm(int n, void **pp){
       if( mem0.alarmThreshold>0 ){
         sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
         if( nUsed >= mem0.alarmThreshold - nFull ){
    -      mem0.nearlyFull = 1;
    +      AtomicStore(&mem0.nearlyFull, 1);
           sqlite3MallocAlarm(nFull);
           if( mem0.hardLimit ){
             nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
    @@ -253,7 +253,7 @@ static void mallocWithAlarm(int n, void **pp){
             }
           }
         }else{
    -      mem0.nearlyFull = 0;
    +      AtomicStore(&mem0.nearlyFull, 0);
         }
       }
       p = sqlite3GlobalConfig.m.xMalloc(nFull);
    @@ -482,10 +482,12 @@ void *sqlite3Realloc(void *pOld, u64 nBytes){
           sqlite3MallocAlarm(nDiff);
         }
         pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
    +#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
         if( pNew==0 && mem0.alarmThreshold>0 ){
           sqlite3MallocAlarm((int)nBytes);
           pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
         }
    +#endif
         if( pNew ){
           nNew = sqlite3MallocSize(pNew);
           sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nNew-nOld);
    @@ -670,7 +672,7 @@ static SQLITE_NOINLINE void *dbReallocFinish(sqlite3 *db, void *p, u64 n){
           assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
           assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
           sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
    -      pNew = sqlite3_realloc64(p, n);
    +      pNew = sqlite3Realloc(p, n);
           if( !pNew ){
             sqlite3OomFault(db);
           }
    @@ -760,7 +762,7 @@ void sqlite3OomFault(sqlite3 *db){
       if( db->mallocFailed==0 && db->bBenignMalloc==0 ){
         db->mallocFailed = 1;
         if( db->nVdbeExec>0 ){
    -      db->u1.isInterrupted = 1;
    +      AtomicStore(&db->u1.isInterrupted, 1);
         }
         DisableLookaside;
         if( db->pParse ){
    @@ -779,7 +781,7 @@ void sqlite3OomFault(sqlite3 *db){
     void sqlite3OomClear(sqlite3 *db){
       if( db->mallocFailed && db->nVdbeExec==0 ){
         db->mallocFailed = 0;
    -    db->u1.isInterrupted = 0;
    +    AtomicStore(&db->u1.isInterrupted, 0);
         assert( db->lookaside.bDisable>0 );
         EnableLookaside;
       }
    diff --git a/src/memdb.c b/src/memdb.c
    index 2ddecae..10da6d8 100644
    --- a/src/memdb.c
    +++ b/src/memdb.c
    @@ -166,7 +166,7 @@ static int memdbEnlarge(MemFile *p, sqlite3_int64 newSz){
       }
       newSz *= 2;
       if( newSz>p->szMax ) newSz = p->szMax;
    -  pNew = sqlite3_realloc64(p->aData, newSz);
    +  pNew = sqlite3Realloc(p->aData, newSz);
       if( pNew==0 ) return SQLITE_NOMEM;
       p->aData = pNew;
       p->szAlloc = newSz;
    @@ -613,10 +613,11 @@ int sqlite3MemdbInit(void){
       sqlite3_vfs *pLower = sqlite3_vfs_find(0);
       int sz = pLower->szOsFile;
       memdb_vfs.pAppData = pLower;
    -  /* In all known configurations of SQLite, the size of a default
    -  ** sqlite3_file is greater than the size of a memdb sqlite3_file.
    -  ** Should that ever change, remove the following NEVER() */
    -  if( NEVER(sz=0 ){
         if( m!=0 ){
    @@ -1565,8 +1565,9 @@ static int osSetPosixAdvisoryLock(
       struct flock *pLock,  /* The description of the lock */
       unixFile *pFile       /* Structure holding timeout value */
     ){
    +  int tm = pFile->iBusyTimeout;
       int rc = osFcntl(h,F_SETLK,pLock);
    -  while( rc<0 && pFile->iBusyTimeout>0 ){
    +  while( rc<0 && tm>0 ){
         /* On systems that support some kind of blocking file lock with a timeout,
         ** make appropriate changes here to invoke that blocking file lock.  On
         ** generic posix, however, there is no such API.  So we simply try the
    @@ -1574,7 +1575,7 @@ static int osSetPosixAdvisoryLock(
         ** the lock is obtained. */
         usleep(1000);
         rc = osFcntl(h,F_SETLK,pLock);
    -    pFile->iBusyTimeout--;
    +    tm--;
       }
       return rc;
     }
    @@ -3685,7 +3686,7 @@ static int openDirectory(const char *zFilename, int *pFd){
         if( zDirname[0]!='/' ) zDirname[0] = '.';
         zDirname[1] = 0;
       }
    -  fd = robust_open(zDirname, O_RDONLY|O_BINARY|O_NOFOLLOW, 0);
    +  fd = robust_open(zDirname, O_RDONLY|O_BINARY, 0);
       if( fd>=0 ){
         OSTRACE(("OPENDIR %-3d %s\n", fd, zDirname));
       }
    @@ -3995,7 +3996,9 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){
         }
     #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
         case SQLITE_FCNTL_LOCK_TIMEOUT: {
    +      int iOld = pFile->iBusyTimeout;
           pFile->iBusyTimeout = *(int*)pArg;
    +      *(int*)pArg = iOld;
           return SQLITE_OK;
         }
     #endif
    @@ -4314,13 +4317,20 @@ static int unixShmSystemLock(
       assert( n>=1 && n<=SQLITE_SHM_NLOCK );
     
       if( pShmNode->hShm>=0 ){
    +    int res;
         /* Initialize the locking parameters */
         f.l_type = lockType;
         f.l_whence = SEEK_SET;
         f.l_start = ofst;
         f.l_len = n;
    -    rc = osSetPosixAdvisoryLock(pShmNode->hShm, &f, pFile);
    -    rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY;
    +    res = osSetPosixAdvisoryLock(pShmNode->hShm, &f, pFile);
    +    if( res==-1 ){
    +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
    +      rc = (pFile->iBusyTimeout ? SQLITE_BUSY_TIMEOUT : SQLITE_BUSY);
    +#else
    +      rc = SQLITE_BUSY;
    +#endif
    +    }
       }
     
       /* Update the global lock state and do debug tracing */
    @@ -4817,6 +4827,25 @@ static int unixShmLock(
       assert( pShmNode->hShm>=0 || pDbFd->pInode->bProcessLock==1 );
       assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 );
     
    +  /* Check that, if this to be a blocking lock, no locks that occur later
    +  ** in the following list than the lock being obtained are already held:
    +  **
    +  **   1. Checkpointer lock (ofst==1).
    +  **   2. Write lock (ofst==0).
    +  **   3. Read locks (ofst>=3 && ofstiBusyTimeout==0 || (
    +         (ofst!=2)                                   /* not RECOVER */
    +      && (ofst!=1 || (p->exclMask|p->sharedMask)==0)
    +      && (ofst!=0 || (p->exclMask|p->sharedMask)<3)
    +      && (ofst<3  || (p->exclMask|p->sharedMask)<(1<1 || mask==(1<pShmMutex);
    diff --git a/src/os_win.c b/src/os_win.c
    index 32758ab..0adfd7f 100644
    --- a/src/os_win.c
    +++ b/src/os_win.c
    @@ -3502,6 +3502,7 @@ static void winModeBit(winFile *pFile, unsigned char mask, int *pArg){
     /* Forward references to VFS helper methods used for temporary files */
     static int winGetTempname(sqlite3_vfs *, char **);
     static int winIsDir(const void *);
    +static BOOL winIsLongPathPrefix(const char *);
     static BOOL winIsDriveLetterAndColon(const char *);
     
     /*
    @@ -5271,7 +5272,9 @@ static int winOpen(
       if( isReadonly ){
         pFile->ctrlFlags |= WINFILE_RDONLY;
       }
    -  if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){
    +  if( (flags & SQLITE_OPEN_MAIN_DB)
    +   && sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) 
    +  ){
         pFile->ctrlFlags |= WINFILE_PSOW;
       }
       pFile->lastErrno = NO_ERROR;
    @@ -5481,6 +5484,17 @@ static int winAccess(
       return SQLITE_OK;
     }
     
    +/*
    +** Returns non-zero if the specified path name starts with the "long path"
    +** prefix.
    +*/
    +static BOOL winIsLongPathPrefix(
    +  const char *zPathname
    +){
    +  return ( zPathname[0]=='\\' && zPathname[1]=='\\'
    +        && zPathname[2]=='?'  && zPathname[3]=='\\' );
    +}
    +
     /*
     ** Returns non-zero if the specified path name starts with a drive letter
     ** followed by a colon character.
    @@ -5545,10 +5559,11 @@ static int winFullPathname(
       char *zOut;
     #endif
     
    -  /* If this path name begins with "/X:", where "X" is any alphabetic
    -  ** character, discard the initial "/" from the pathname.
    +  /* If this path name begins with "/X:" or "\\?\", where "X" is any
    +  ** alphabetic character, discard the initial "/" from the pathname.
       */
    -  if( zRelative[0]=='/' && winIsDriveLetterAndColon(zRelative+1) ){
    +  if( zRelative[0]=='/' && (winIsDriveLetterAndColon(zRelative+1)
    +       || winIsLongPathPrefix(zRelative+1)) ){
         zRelative++;
       }
     
    diff --git a/src/pager.c b/src/pager.c
    index ff62926..a826f25 100644
    --- a/src/pager.c
    +++ b/src/pager.c
    @@ -2536,9 +2536,12 @@ static int pager_delmaster(Pager *pPager, const char *zMaster){
           /* One of the journals pointed to by the master journal exists.
           ** Open it and check if it points at the master journal. If
           ** so, return without deleting the master journal file.
    +      ** NB:  zJournal is really a MAIN_JOURNAL.  But call it a 
    +      ** MASTER_JOURNAL here so that the VFS will not send the zJournal
    +      ** name into sqlite3_database_file_object().
           */
           int c;
    -      int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MAIN_JOURNAL);
    +      int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MASTER_JOURNAL);
           rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0);
           if( rc!=SQLITE_OK ){
             goto delmaster_out;
    @@ -4742,6 +4745,7 @@ int sqlite3PagerOpen(
       **     Database file handle            (pVfs->szOsFile bytes)
       **     Sub-journal file handle         (journalFileSize bytes)
       **     Main journal file handle        (journalFileSize bytes)
    +  **     Ptr back to the Pager           (sizeof(Pager*) bytes)
       **     \0\0\0\0 database prefix        (4 bytes)
       **     Database file name              (nPathname+1 bytes)
       **     URI query parameters            (nUriByte bytes)
    @@ -4770,12 +4774,18 @@ int sqlite3PagerOpen(
       **   - \0
       **   - WAL Path (zWALName)
       **   - \0
    +  **
    +  ** The sqlite3_create_filename() interface and the databaseFilename() utility
    +  ** that is used by sqlite3_filename_database() and kin also depend on the
    +  ** specific formatting and order of the various filenames, so if the format
    +  ** changes here, be sure to change it there as well.
       */
       pPtr = (u8 *)sqlite3MallocZero(
         ROUND8(sizeof(*pPager)) +            /* Pager structure */
         ROUND8(pcacheSize) +                 /* PCache object */
         ROUND8(pVfs->szOsFile) +             /* The main db file */
         journalFileSize * 2 +                /* The two journal files */
    +    sizeof(pPager) +                     /* Space to hold a pointer */
         4 +                                  /* Database prefix */
         nPathname + 1 +                      /* database filename */
         nUriByte +                           /* query parameters */
    @@ -4796,6 +4806,7 @@ int sqlite3PagerOpen(
       pPager->sjfd = (sqlite3_file*)pPtr;     pPtr += journalFileSize;
       pPager->jfd =  (sqlite3_file*)pPtr;     pPtr += journalFileSize;
       assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) );
    +  memcpy(pPtr, &pPager, sizeof(pPager));  pPtr += sizeof(pPager);
     
       /* Fill in the Pager.zFilename and pPager.zQueryParam fields */
                                               pPtr += 4;  /* Skip zero prefix */
    @@ -4996,6 +5007,19 @@ act_like_temp_file:
       return SQLITE_OK;
     }
     
    +/*
    +** Return the sqlite3_file for the main database given the name
    +** of the corresonding WAL or Journal name as passed into
    +** xOpen.
    +*/
    +sqlite3_file *sqlite3_database_file_object(const char *zName){
    +  Pager *pPager;
    +  while( zName[-1]!=0 || zName[-2]!=0 || zName[-3]!=0 || zName[-4]!=0 ){
    +    zName--;
    +  }
    +  pPager = *(Pager**)(zName - 4 - sizeof(Pager*));
    +  return pPager->fd;
    +}
     
     
     /*
    @@ -5681,7 +5705,6 @@ void sqlite3PagerUnrefPageOne(DbPage *pPg){
       assert( pPg->pgno==1 );
       assert( (pPg->flags & PGHDR_MMAP)==0 ); /* Page1 is never memory mapped */
       pPager = pPg->pPager;
    -  sqlite3PagerResetLockTimeout(pPager);
       sqlite3PcacheRelease(pPg);
       pagerUnlockIfUnused(pPager);
     }
    @@ -6954,7 +6977,7 @@ int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint){
     ** sqlite3_uri_parameter() and sqlite3_filename_database() and friends.
     */
     const char *sqlite3PagerFilename(const Pager *pPager, int nullIfMemDb){
    -  static const char zFake[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
    +  static const char zFake[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
       return (nullIfMemDb && pPager->memDb) ? &zFake[4] : pPager->zFilename;
     }
     
    @@ -6974,16 +6997,6 @@ sqlite3_file *sqlite3PagerFile(Pager *pPager){
       return pPager->fd;
     }
     
    -#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
    -/*
    -** Reset the lock timeout for pager.
    -*/
    -void sqlite3PagerResetLockTimeout(Pager *pPager){
    -  int x = 0;
    -  sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_LOCK_TIMEOUT, &x);
    -}
    -#endif
    -
     /*
     ** Return the file handle for the journal file (if it exists).
     ** This will be either the rollback journal or the WAL file.
    @@ -7397,7 +7410,6 @@ int sqlite3PagerCheckpoint(
             pPager->walSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace,
             pnLog, pnCkpt
         );
    -    sqlite3PagerResetLockTimeout(pPager);
       }
       return rc;
     }
    @@ -7562,7 +7574,31 @@ int sqlite3PagerCloseWal(Pager *pPager, sqlite3 *db){
       return rc;
     }
     
    +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
    +/*
    +** If pager pPager is a wal-mode database not in exclusive locking mode,
    +** invoke the sqlite3WalWriteLock() function on the associated Wal object 
    +** with the same db and bLock parameters as were passed to this function.
    +** Return an SQLite error code if an error occurs, or SQLITE_OK otherwise.
    +*/
    +int sqlite3PagerWalWriteLock(Pager *pPager, int bLock){
    +  int rc = SQLITE_OK;
    +  if( pagerUseWal(pPager) && pPager->exclusiveMode==0 ){
    +    rc = sqlite3WalWriteLock(pPager->pWal, bLock);
    +  }
    +  return rc;
    +}
     
    +/*
    +** Set the database handle used by the wal layer to determine if 
    +** blocking locks are required.
    +*/
    +void sqlite3PagerWalDb(Pager *pPager, sqlite3 *db){
    +  if( pagerUseWal(pPager) ){
    +    sqlite3WalDb(pPager->pWal, db);
    +  }
    +}
    +#endif
     
     #ifdef SQLITE_ENABLE_SNAPSHOT
     /*
    @@ -7582,7 +7618,10 @@ int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot){
     ** read transaction is opened, attempt to read from the snapshot it 
     ** identifies. If this is not a WAL database, return an error.
     */
    -int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot){
    +int sqlite3PagerSnapshotOpen(
    +  Pager *pPager, 
    +  sqlite3_snapshot *pSnapshot
    +){
       int rc = SQLITE_OK;
       if( pPager->pWal ){
         sqlite3WalSnapshotOpen(pPager->pWal, pSnapshot);
    diff --git a/src/pager.h b/src/pager.h
    index 2c99d67..62a371e 100644
    --- a/src/pager.h
    +++ b/src/pager.h
    @@ -177,14 +177,22 @@ int sqlite3PagerSharedLock(Pager *pPager);
       int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen);
       int sqlite3PagerCloseWal(Pager *pPager, sqlite3*);
     # ifdef SQLITE_ENABLE_SNAPSHOT
    -  int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot);
    -  int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot);
    +  int sqlite3PagerSnapshotGet(Pager*, sqlite3_snapshot **ppSnapshot);
    +  int sqlite3PagerSnapshotOpen(Pager*, sqlite3_snapshot *pSnapshot);
       int sqlite3PagerSnapshotRecover(Pager *pPager);
       int sqlite3PagerSnapshotCheck(Pager *pPager, sqlite3_snapshot *pSnapshot);
       void sqlite3PagerSnapshotUnlock(Pager *pPager);
     # endif
     #endif
     
    +#if !defined(SQLITE_OMIT_WAL) && defined(SQLITE_ENABLE_SETLK_TIMEOUT)
    +  int sqlite3PagerWalWriteLock(Pager*, int);
    +  void sqlite3PagerWalDb(Pager*, sqlite3*);
    +#else
    +# define sqlite3PagerWalWriteLock(y,z) SQLITE_OK
    +# define sqlite3PagerWalDb(x,y)
    +#endif
    +
     #ifdef SQLITE_DIRECT_OVERFLOW_READ
       int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno);
     #endif
    @@ -210,11 +218,6 @@ int sqlite3PagerIsMemdb(Pager*);
     void sqlite3PagerCacheStat(Pager *, int, int, int *);
     void sqlite3PagerClearCache(Pager*);
     int sqlite3SectorSize(sqlite3_file *);
    -#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
    -void sqlite3PagerResetLockTimeout(Pager *pPager);
    -#else
    -# define sqlite3PagerResetLockTimeout(X)
    -#endif
     
     /* Functions used to truncate the database file. */
     void sqlite3PagerTruncateImage(Pager*,Pgno);
    diff --git a/src/parse.y b/src/parse.y
    index c783c69..09731eb 100644
    --- a/src/parse.y
    +++ b/src/parse.y
    @@ -965,6 +965,7 @@ idlist(A) ::= nm(Y).
           p->op = (u8)op;
           p->affExpr = 0;
           p->flags = EP_Leaf;
    +      ExprClearVVAProperties(p);
           p->iAgg = -1;
           p->pLeft = p->pRight = 0;
           p->x.pList = 0;
    @@ -1193,10 +1194,11 @@ expr(A) ::= expr(A) between_op(N) expr(X) AND expr(Y). [BETWEEN] {
           */
           sqlite3ExprUnmapAndDelete(pParse, A);
           A = sqlite3Expr(pParse->db, TK_INTEGER, N ? "1" : "0");
    -    }else if( 0 && Y->nExpr==1 && sqlite3ExprIsConstant(Y->a[0].pExpr) ){
    +    }else if( Y->nExpr==1 && sqlite3ExprIsConstant(Y->a[0].pExpr) ){
           Expr *pRHS = Y->a[0].pExpr;
           Y->a[0].pExpr = 0;
           sqlite3ExprListDelete(pParse->db, Y);
    +      pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0);
           A = sqlite3PExpr(pParse, TK_EQ, A, pRHS);
           if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0);
         }else{
    diff --git a/src/pragma.c b/src/pragma.c
    index 60e18e7..161a241 100644
    --- a/src/pragma.c
    +++ b/src/pragma.c
    @@ -555,7 +555,7 @@ void sqlite3Pragma(
           ** buffer that the pager module resizes using sqlite3_realloc().
           */
           db->nextPagesize = sqlite3Atoi(zRight);
    -      if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){
    +      if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,0,0) ){
             sqlite3OomFault(db);
           }
         }
    @@ -1729,7 +1729,6 @@ void sqlite3Pragma(
             }
             sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
             sqlite3VdbeJumpHere(v, loopTop-1);
    -#ifndef SQLITE_OMIT_BTREECOUNT
             if( !isQuick ){
               sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
               for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
    @@ -1743,7 +1742,6 @@ void sqlite3Pragma(
                 sqlite3VdbeJumpHere(v, addr);
               }
             }
    -#endif /* SQLITE_OMIT_BTREECOUNT */
           } 
         }
         {
    @@ -1824,21 +1822,12 @@ void sqlite3Pragma(
           ** will be overwritten when the schema is next loaded. If it does not
           ** already exists, it will be created to use the new encoding value.
           */
    -      int canChangeEnc = 1;  /* True if allowed to change the encoding */
    -      int i;                 /* For looping over all attached databases */
    -      for(i=0; inDb; i++){
    -        if( db->aDb[i].pBt!=0
    -         && DbHasProperty(db,i,DB_SchemaLoaded)
    -         && !DbHasProperty(db,i,DB_Empty)
    -        ){
    -          canChangeEnc = 0;
    -        }
    -      }
    -      if( canChangeEnc ){
    +      if( (db->mDbFlags & DBFLAG_EncodingFixed)==0 ){
             for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
               if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
    -            SCHEMA_ENC(db) = ENC(db) =
    -                pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
    +            u8 enc = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
    +            SCHEMA_ENC(db) = enc;
    +            sqlite3SetTextEncoding(db, enc);
                 break;
               }
             }
    @@ -2187,6 +2176,25 @@ void sqlite3Pragma(
         break;
       }
     
    +  /*
    +  **   PRAGMA analysis_limit
    +  **   PRAGMA analysis_limit = N
    +  **
    +  ** Configure the maximum number of rows that ANALYZE will examine
    +  ** in each index that it looks at.  Return the new limit.
    +  */
    +  case PragTyp_ANALYSIS_LIMIT: {
    +    sqlite3_int64 N;
    +    if( zRight
    +     && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK
    +     && N>=0
    +    ){
    +      db->nAnalysisLimit = (int)(N&0x7fffffff);
    +    }
    +    returnSingleInt(v, db->nAnalysisLimit);
    +    break;
    +  }
    +
     #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
       /*
       ** Report the current state of file logs for all databases
    diff --git a/src/pragma.h b/src/pragma.h
    index 7046695..0d7cae0 100644
    --- a/src/pragma.h
    +++ b/src/pragma.h
    @@ -6,49 +6,50 @@
     
     /* The various pragma types */
     #define PragTyp_ACTIVATE_EXTENSIONS            0
    -#define PragTyp_HEADER_VALUE                   1
    -#define PragTyp_AUTO_VACUUM                    2
    -#define PragTyp_FLAG                           3
    -#define PragTyp_BUSY_TIMEOUT                   4
    -#define PragTyp_CACHE_SIZE                     5
    -#define PragTyp_CACHE_SPILL                    6
    -#define PragTyp_CASE_SENSITIVE_LIKE            7
    -#define PragTyp_COLLATION_LIST                 8
    -#define PragTyp_COMPILE_OPTIONS                9
    -#define PragTyp_DATA_STORE_DIRECTORY          10
    -#define PragTyp_DATABASE_LIST                 11
    -#define PragTyp_DEFAULT_CACHE_SIZE            12
    -#define PragTyp_ENCODING                      13
    -#define PragTyp_FOREIGN_KEY_CHECK             14
    -#define PragTyp_FOREIGN_KEY_LIST              15
    -#define PragTyp_FUNCTION_LIST                 16
    -#define PragTyp_HARD_HEAP_LIMIT               17
    -#define PragTyp_INCREMENTAL_VACUUM            18
    -#define PragTyp_INDEX_INFO                    19
    -#define PragTyp_INDEX_LIST                    20
    -#define PragTyp_INTEGRITY_CHECK               21
    -#define PragTyp_JOURNAL_MODE                  22
    -#define PragTyp_JOURNAL_SIZE_LIMIT            23
    -#define PragTyp_LOCK_PROXY_FILE               24
    -#define PragTyp_LOCKING_MODE                  25
    -#define PragTyp_PAGE_COUNT                    26
    -#define PragTyp_MMAP_SIZE                     27
    -#define PragTyp_MODULE_LIST                   28
    -#define PragTyp_OPTIMIZE                      29
    -#define PragTyp_PAGE_SIZE                     30
    -#define PragTyp_PRAGMA_LIST                   31
    -#define PragTyp_SECURE_DELETE                 32
    -#define PragTyp_SHRINK_MEMORY                 33
    -#define PragTyp_SOFT_HEAP_LIMIT               34
    -#define PragTyp_SYNCHRONOUS                   35
    -#define PragTyp_TABLE_INFO                    36
    -#define PragTyp_TEMP_STORE                    37
    -#define PragTyp_TEMP_STORE_DIRECTORY          38
    -#define PragTyp_THREADS                       39
    -#define PragTyp_WAL_AUTOCHECKPOINT            40
    -#define PragTyp_WAL_CHECKPOINT                41
    -#define PragTyp_LOCK_STATUS                   42
    -#define PragTyp_STATS                         43
    +#define PragTyp_ANALYSIS_LIMIT                 1
    +#define PragTyp_HEADER_VALUE                   2
    +#define PragTyp_AUTO_VACUUM                    3
    +#define PragTyp_FLAG                           4
    +#define PragTyp_BUSY_TIMEOUT                   5
    +#define PragTyp_CACHE_SIZE                     6
    +#define PragTyp_CACHE_SPILL                    7
    +#define PragTyp_CASE_SENSITIVE_LIKE            8
    +#define PragTyp_COLLATION_LIST                 9
    +#define PragTyp_COMPILE_OPTIONS               10
    +#define PragTyp_DATA_STORE_DIRECTORY          11
    +#define PragTyp_DATABASE_LIST                 12
    +#define PragTyp_DEFAULT_CACHE_SIZE            13
    +#define PragTyp_ENCODING                      14
    +#define PragTyp_FOREIGN_KEY_CHECK             15
    +#define PragTyp_FOREIGN_KEY_LIST              16
    +#define PragTyp_FUNCTION_LIST                 17
    +#define PragTyp_HARD_HEAP_LIMIT               18
    +#define PragTyp_INCREMENTAL_VACUUM            19
    +#define PragTyp_INDEX_INFO                    20
    +#define PragTyp_INDEX_LIST                    21
    +#define PragTyp_INTEGRITY_CHECK               22
    +#define PragTyp_JOURNAL_MODE                  23
    +#define PragTyp_JOURNAL_SIZE_LIMIT            24
    +#define PragTyp_LOCK_PROXY_FILE               25
    +#define PragTyp_LOCKING_MODE                  26
    +#define PragTyp_PAGE_COUNT                    27
    +#define PragTyp_MMAP_SIZE                     28
    +#define PragTyp_MODULE_LIST                   29
    +#define PragTyp_OPTIMIZE                      30
    +#define PragTyp_PAGE_SIZE                     31
    +#define PragTyp_PRAGMA_LIST                   32
    +#define PragTyp_SECURE_DELETE                 33
    +#define PragTyp_SHRINK_MEMORY                 34
    +#define PragTyp_SOFT_HEAP_LIMIT               35
    +#define PragTyp_SYNCHRONOUS                   36
    +#define PragTyp_TABLE_INFO                    37
    +#define PragTyp_TEMP_STORE                    38
    +#define PragTyp_TEMP_STORE_DIRECTORY          39
    +#define PragTyp_THREADS                       40
    +#define PragTyp_WAL_AUTOCHECKPOINT            41
    +#define PragTyp_WAL_CHECKPOINT                42
    +#define PragTyp_LOCK_STATUS                   43
    +#define PragTyp_STATS                         44
     
     /* Property flags associated with various pragma. */
     #define PragFlg_NeedSchema 0x01 /* Force schema load before running */
    @@ -139,6 +140,11 @@ static const PragmaName aPragmaName[] = {
       /* ColNames:  */ 0, 0,
       /* iArg:      */ 0 },
     #endif
    + {/* zName:     */ "analysis_limit",
    +  /* ePragTyp:  */ PragTyp_ANALYSIS_LIMIT,
    +  /* ePragFlg:  */ PragFlg_Result0,
    +  /* ColNames:  */ 0, 0,
    +  /* iArg:      */ 0 },
     #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
      {/* zName:     */ "application_id",
       /* ePragTyp:  */ PragTyp_HEADER_VALUE,
    @@ -639,4 +645,4 @@ static const PragmaName aPragmaName[] = {
       /* iArg:      */ SQLITE_WriteSchema|SQLITE_NoSchemaError },
     #endif
     };
    -/* Number of pragmas: 66 on by default, 76 total. */
    +/* Number of pragmas: 67 on by default, 77 total. */
    diff --git a/src/prepare.c b/src/prepare.c
    index 2d928f1..228d148 100644
    --- a/src/prepare.c
    +++ b/src/prepare.c
    @@ -91,7 +91,7 @@ int sqlite3InitCallback(void *pInit, int argc, char **argv, char **NotUsed){
       assert( argc==5 );
       UNUSED_PARAMETER2(NotUsed, argc);
       assert( sqlite3_mutex_held(db->mutex) );
    -  DbClearProperty(db, iDb, DB_Empty);
    +  db->mDbFlags |= DBFLAG_EncodingFixed;
       pData->nInitRow++;
       if( db->mallocFailed ){
         corruptSchema(pData, argv[1], 0);
    @@ -179,6 +179,7 @@ int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg, u32 mFlags){
       InitData initData;
       const char *zMasterName;
       int openedTransaction = 0;
    +  int mask = ((db->mDbFlags & DBFLAG_EncodingFixed) | ~DBFLAG_EncodingFixed);
     
       assert( (db->mDbFlags & DBFLAG_SchemaKnownOk)==0 );
       assert( iDb>=0 && iDbnDb );
    @@ -207,6 +208,7 @@ int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg, u32 mFlags){
       initData.mInitFlags = mFlags;
       initData.nInitRow = 0;
       sqlite3InitCallback(&initData, 5, (char **)azArg, 0);
    +  db->mDbFlags &= mask;
       if( initData.rc ){
         rc = initData.rc;
         goto error_out;
    @@ -266,27 +268,25 @@ int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg, u32 mFlags){
       ** as sqlite3.enc.
       */
       if( meta[BTREE_TEXT_ENCODING-1] ){  /* text encoding */
    -    if( iDb==0 ){
    -#ifndef SQLITE_OMIT_UTF16
    +    if( iDb==0 && (db->mDbFlags & DBFLAG_EncodingFixed)==0 ){
           u8 encoding;
    +#ifndef SQLITE_OMIT_UTF16
           /* If opening the main database, set ENC(db). */
           encoding = (u8)meta[BTREE_TEXT_ENCODING-1] & 3;
           if( encoding==0 ) encoding = SQLITE_UTF8;
    -      ENC(db) = encoding;
     #else
    -      ENC(db) = SQLITE_UTF8;
    +      encoding = SQLITE_UTF8;
     #endif
    +      sqlite3SetTextEncoding(db, encoding);
         }else{
           /* If opening an attached database, the encoding much match ENC(db) */
    -      if( meta[BTREE_TEXT_ENCODING-1]!=ENC(db) ){
    +      if( (meta[BTREE_TEXT_ENCODING-1] & 3)!=ENC(db) ){
             sqlite3SetString(pzErrMsg, db, "attached databases must use the same"
                 " text encoding as main database");
             rc = SQLITE_ERROR;
             goto initone_error_out;
           }
         }
    -  }else{
    -    DbSetProperty(db, iDb, DB_Empty);
       }
       pDb->pSchema->enc = ENC(db);
     
    @@ -398,8 +398,7 @@ error_out:
     ** error occurs, write an error message into *pzErrMsg.
     **
     ** After a database is initialized, the DB_SchemaLoaded bit is set
    -** bit is set in the flags field of the Db structure. If the database
    -** file was of zero-length, then the DB_Empty flag is also set.
    +** bit is set in the flags field of the Db structure. 
     */
     int sqlite3Init(sqlite3 *db, char **pzErrMsg){
       int i, rc;
    diff --git a/src/printf.c b/src/printf.c
    index fc77f68..fd42bd2 100644
    --- a/src/printf.c
    +++ b/src/printf.c
    @@ -924,7 +924,7 @@ static int sqlite3StrAccumEnlarge(StrAccum *p, int N){
         if( p->db ){
           zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
         }else{
    -      zNew = sqlite3_realloc64(zOld, p->nAlloc);
    +      zNew = sqlite3Realloc(zOld, p->nAlloc);
         }
         if( zNew ){
           assert( p->zText!=0 || p->nChar==0 );
    @@ -1266,7 +1266,7 @@ void sqlite3_log(int iErrCode, const char *zFormat, ...){
     void sqlite3DebugPrintf(const char *zFormat, ...){
       va_list ap;
       StrAccum acc;
    -  char zBuf[500];
    +  char zBuf[SQLITE_PRINT_BUF_SIZE*10];
       sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
       va_start(ap,zFormat);
       sqlite3_str_vappendf(&acc, zFormat, ap);
    diff --git a/src/resolve.c b/src/resolve.c
    index 119a07f..60fed0b 100644
    --- a/src/resolve.c
    +++ b/src/resolve.c
    @@ -140,7 +140,7 @@ int sqlite3MatchEName(
     ){
       int n;
       const char *zSpan;
    -  if( NEVER(pItem->eEName!=ENAME_TAB) ) return 0;
    +  if( pItem->eEName!=ENAME_TAB ) return 0;
       zSpan = pItem->zEName;
       for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
       if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
    @@ -175,6 +175,31 @@ static int areDoubleQuotedStringsEnabled(sqlite3 *db, NameContext *pTopNC){
       }
     }
     
    +/*
    +** The argument is guaranteed to be a non-NULL Expr node of type TK_COLUMN.
    +** return the appropriate colUsed mask.
    +*/
    +Bitmask sqlite3ExprColUsed(Expr *pExpr){
    +  int n;
    +  Table *pExTab;
    +
    +  n = pExpr->iColumn;
    +  pExTab = pExpr->y.pTab;
    +  assert( pExTab!=0 );
    +  if( (pExTab->tabFlags & TF_HasGenerated)!=0
    +   && (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0 
    +  ){
    +    testcase( pExTab->nCol==BMS-1 );
    +    testcase( pExTab->nCol==BMS );
    +    return pExTab->nCol>=BMS ? ALLBITS : MASKBIT(pExTab->nCol)-1;
    +  }else{
    +    testcase( n==BMS-1 );
    +    testcase( n==BMS );
    +    if( n>=BMS ) n = BMS-1;
    +    return ((Bitmask)1)<nDb && sqlite3StrICmp("main", zDb)==0 ){
    +        /* This branch is taken when the main database has been renamed
    +        ** using SQLITE_DBCONFIG_MAINDBNAME. */
    +        pSchema = db->aDb[0].pSchema;
    +        zDb = db->aDb[0].zDbSName;
    +      }
         }
       }
     
    @@ -263,6 +294,7 @@ static int lookupName(
     
         if( pSrcList ){
           for(i=0, pItem=pSrcList->a; inSrc; i++, pItem++){
    +        u8 hCol;
             pTab = pItem->pTab;
             assert( pTab!=0 && pTab->zName!=0 );
             assert( pTab->nCol>0 );
    @@ -296,8 +328,9 @@ static int lookupName(
             if( 0==(cntTab++) ){
               pMatch = pItem;
             }
    +        hCol = sqlite3StrIHash(zCol);
             for(j=0, pCol=pTab->aCol; jnCol; j++, pCol++){
    -          if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
    +          if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){
                 /* If there has been exactly one prior match and this match
                 ** is for the right-hand table of a NATURAL JOIN or is in a 
                 ** USING clause, then skip this match.
    @@ -358,10 +391,11 @@ static int lookupName(
     
           if( pTab ){ 
             int iCol;
    +        u8 hCol = sqlite3StrIHash(zCol);
             pSchema = pTab->pSchema;
             cntTab++;
             for(iCol=0, pCol=pTab->aCol; iColnCol; iCol++, pCol++){
    -          if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
    +          if( pCol->hName==hCol && sqlite3StrICmp(pCol->zName, zCol)==0 ){
                 if( iCol==pTab->iPKey ){
                   iCol = -1;
                 }
    @@ -571,22 +605,7 @@ static int lookupName(
       ** of the table.
       */
       if( pExpr->iColumn>=0 && pMatch!=0 ){
    -    int n = pExpr->iColumn;
    -    Table *pExTab = pExpr->y.pTab;
    -    assert( pExTab!=0 );
    -    assert( pMatch->iCursor==pExpr->iTable );
    -    if( (pExTab->tabFlags & TF_HasGenerated)!=0
    -     && (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0 
    -    ){
    -      testcase( pExTab->nCol==BMS-1 );
    -      testcase( pExTab->nCol==BMS );
    -      pMatch->colUsed = pExTab->nCol>=BMS ? ALLBITS : MASKBIT(pExTab->nCol)-1;
    -    }else{
    -      testcase( n==BMS-1 );
    -      testcase( n==BMS );
    -      if( n>=BMS ) n = BMS-1;
    -      pMatch->colUsed |= ((Bitmask)1)<colUsed |= sqlite3ExprColUsed(pExpr);
       }
     
       /* Clean up and return
    @@ -1051,7 +1070,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
           assert( !ExprHasProperty(pExpr, EP_Reduced) );
           /* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE",
           ** and "x IS NOT FALSE". */
    -      if( pRight->op==TK_ID ){
    +      if( pRight && pRight->op==TK_ID ){
             int rc = resolveExprStep(pWalker, pRight);
             if( rc==WRC_Abort ) return WRC_Abort;
             if( pRight->op==TK_TRUEFALSE ){
    @@ -1177,7 +1196,7 @@ static int resolveOrderByTermToExprList(
       nc.nErr = 0;
       db = pParse->db;
       savedSuppErr = db->suppressErr;
    -  db->suppressErr = 1;
    +  if( IN_RENAME_OBJECT==0 ) db->suppressErr = 1;
       rc = sqlite3ResolveExprNames(&nc, pE);
       db->suppressErr = savedSuppErr;
       if( rc ) return 0;
    @@ -1812,11 +1831,41 @@ int sqlite3ResolveExprListNames(
       ExprList *pList         /* The expression list to be analyzed. */
     ){
       int i;
    -  if( pList ){
    -    for(i=0; inExpr; i++){
    -      if( sqlite3ResolveExprNames(pNC, pList->a[i].pExpr) ) return WRC_Abort;
    +  int savedHasAgg = 0;
    +  Walker w;
    +  if( pList==0 ) return WRC_Continue;
    +  w.pParse = pNC->pParse;
    +  w.xExprCallback = resolveExprStep;
    +  w.xSelectCallback = resolveSelectStep;
    +  w.xSelectCallback2 = 0;
    +  w.u.pNC = pNC;
    +  savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
    +  pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
    +  for(i=0; inExpr; i++){
    +    Expr *pExpr = pList->a[i].pExpr;
    +    if( pExpr==0 ) continue;
    +#if SQLITE_MAX_EXPR_DEPTH>0
    +    w.pParse->nHeight += pExpr->nHeight;
    +    if( sqlite3ExprCheckHeight(w.pParse, w.pParse->nHeight) ){
    +      return WRC_Abort;
         }
    +#endif
    +    sqlite3WalkExpr(&w, pExpr);
    +#if SQLITE_MAX_EXPR_DEPTH>0
    +    w.pParse->nHeight -= pExpr->nHeight;
    +#endif
    +    assert( EP_Agg==NC_HasAgg );
    +    assert( EP_Win==NC_HasWin );
    +    testcase( pNC->ncFlags & NC_HasAgg );
    +    testcase( pNC->ncFlags & NC_HasWin );
    +    if( pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin) ){
    +      ExprSetProperty(pExpr, pNC->ncFlags & (NC_HasAgg|NC_HasWin) );
    +      savedHasAgg |= pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
    +      pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
    +    }
    +    if( pNC->nErr>0 || w.pParse->nErr>0 ) return WRC_Abort;
       }
    +  pNC->ncFlags |= savedHasAgg;
       return WRC_Continue;
     }
     
    diff --git a/src/rowset.c b/src/rowset.c
    index 703cf49..0562320 100644
    --- a/src/rowset.c
    +++ b/src/rowset.c
    @@ -177,7 +177,7 @@ void sqlite3RowSetDelete(void *pArg){
     /*
     ** Allocate a new RowSetEntry object that is associated with the
     ** given RowSet.  Return a pointer to the new and completely uninitialized
    -** objected.
    +** object.
     **
     ** In an OOM situation, the RowSet.db->mallocFailed flag is set and this
     ** routine returns NULL.
    @@ -453,7 +453,7 @@ int sqlite3RowSetTest(RowSet *pRowSet, int iBatch, sqlite3_int64 iRowid){
         if( p ){
           struct RowSetEntry **ppPrevTree = &pRowSet->pForest;
           if( (pRowSet->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/
    -        /* Only sort the current set of entiries if they need it */
    +        /* Only sort the current set of entries if they need it */
             p = rowSetEntrySort(p);
           }
           for(pTree = pRowSet->pForest; pTree; pTree=pTree->pRight){
    diff --git a/src/select.c b/src/select.c
    index 595b6eb..869984f 100644
    --- a/src/select.c
    +++ b/src/select.c
    @@ -103,7 +103,6 @@ static void clearSelect(sqlite3 *db, Select *p, int bFree){
         if( OK_IF_ALWAYS_TRUE(p->pWinDefn) ){
           sqlite3WindowListDelete(db, p->pWinDefn);
         }
    -    assert( p->pWin==0 );
     #endif
         if( OK_IF_ALWAYS_TRUE(p->pWith) ) sqlite3WithDelete(db, p->pWith);
         if( bFree ) sqlite3DbFreeNN(db, p);
    @@ -2024,6 +2023,7 @@ int sqlite3ColumnsFromExprList(
           if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
         }
         pCol->zName = zName;
    +    pCol->hName = sqlite3StrIHash(zName);
         sqlite3ColumnPropertiesFromName(0, pCol);
         if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){
           sqlite3OomFault(db);
    @@ -2806,6 +2806,7 @@ static int multiSelect(
             /* Generate code to take the intersection of the two temporary
             ** tables.
             */
    +        if( rc ) break;
             assert( p->pEList );
             iBreak = sqlite3VdbeMakeLabel(pParse);
             iCont = sqlite3VdbeMakeLabel(pParse);
    @@ -3476,7 +3477,10 @@ static Expr *substExpr(
       ){
         pExpr->iRightJoinTable = pSubst->iNewTable;
       }
    -  if( pExpr->op==TK_COLUMN && pExpr->iTable==pSubst->iTable ){
    +  if( pExpr->op==TK_COLUMN
    +   && pExpr->iTable==pSubst->iTable
    +   && !ExprHasProperty(pExpr, EP_FixedCol)
    +  ){
         if( pExpr->iColumn<0 ){
           pExpr->op = TK_NULL;
         }else{
    @@ -3494,6 +3498,7 @@ static Expr *substExpr(
               ifNullRow.op = TK_IF_NULL_ROW;
               ifNullRow.pLeft = pCopy;
               ifNullRow.iTable = pSubst->iNewTable;
    +          ifNullRow.flags = EP_Skip;
               pCopy = &ifNullRow;
             }
             testcase( ExprHasProperty(pCopy, EP_Subquery) );
    @@ -3580,6 +3585,38 @@ static void substSelect(
     }
     #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
     
    +#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
    +/*
    +** pSelect is a SELECT statement and pSrcItem is one item in the FROM
    +** clause of that SELECT.
    +**
    +** This routine scans the entire SELECT statement and recomputes the
    +** pSrcItem->colUsed mask.
    +*/
    +static int recomputeColumnsUsedExpr(Walker *pWalker, Expr *pExpr){
    +  struct SrcList_item *pItem;
    +  if( pExpr->op!=TK_COLUMN ) return WRC_Continue;
    +  pItem = pWalker->u.pSrcItem;
    +  if( pItem->iCursor!=pExpr->iTable ) return WRC_Continue;
    +  if( pExpr->iColumn<0 ) return WRC_Continue;
    +  pItem->colUsed |= sqlite3ExprColUsed(pExpr);
    +  return WRC_Continue;
    +}
    +static void recomputeColumnsUsed(
    +  Select *pSelect,                 /* The complete SELECT statement */
    +  struct SrcList_item *pSrcItem    /* Which FROM clause item to recompute */
    +){
    +  Walker w;
    +  if( NEVER(pSrcItem->pTab==0) ) return;
    +  memset(&w, 0, sizeof(w));
    +  w.xExprCallback = recomputeColumnsUsedExpr;
    +  w.xSelectCallback = sqlite3SelectWalkNoop;
    +  w.u.pSrcItem = pSrcItem;
    +  pSrcItem->colUsed = 0;
    +  sqlite3WalkSelect(&w, pSelect);
    +}
    +#endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
    +
     #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
     /*
     ** This routine attempts to flatten subqueries as a performance optimization.
    @@ -4118,6 +4155,12 @@ static int flattenSubquery(
           pParent->pLimit = pSub->pLimit;
           pSub->pLimit = 0;
         }
    +
    +    /* Recompute the SrcList_item.colUsed masks for the flattened
    +    ** tables. */
    +    for(i=0; ia[i+iFrom]);
    +    }
       }
     
       /* Finially, delete what is left of the subquery and return
    @@ -4166,9 +4209,8 @@ static void constInsert(
       assert( pColumn->op==TK_COLUMN );
       assert( sqlite3ExprIsConstant(pValue) );
     
    -  if( !ExprHasProperty(pValue, EP_FixedCol) && sqlite3ExprAffinity(pValue)!=0 ){
    -    return;
    -  }
    +  if( ExprHasProperty(pColumn, EP_FixedCol) ) return;
    +  if( sqlite3ExprAffinity(pValue)!=0 ) return;
       if( !sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr)) ){
         return;
       }
    @@ -4191,9 +4233,6 @@ static void constInsert(
       if( pConst->apExpr==0 ){
         pConst->nConst = 0;
       }else{
    -    if( ExprHasProperty(pValue, EP_FixedCol) ){
    -      pValue = pValue->pLeft;
    -    }
         pConst->apExpr[pConst->nConst*2-2] = pColumn;
         pConst->apExpr[pConst->nConst*2-1] = pValue;
       }
    @@ -4469,7 +4508,7 @@ static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){
       ExprList *pEList = pFunc->x.pList;    /* Arguments to agg function */
       const char *zFunc;                    /* Name of aggregate function pFunc */
       ExprList *pOrderBy;
    -  u8 sortFlags;
    +  u8 sortFlags = 0;
     
       assert( *ppMinMax==0 );
       assert( pFunc->op==TK_AGG_FUNCTION );
    @@ -4480,7 +4519,9 @@ static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){
       zFunc = pFunc->u.zToken;
       if( sqlite3StrICmp(zFunc, "min")==0 ){
         eRet = WHERE_ORDERBY_MIN;
    -    sortFlags = KEYINFO_ORDER_BIGNULL;
    +    if( sqlite3ExprCanBeNull(pEList->a[0].pExpr) ){
    +      sortFlags = KEYINFO_ORDER_BIGNULL;
    +    }
       }else if( sqlite3StrICmp(zFunc, "max")==0 ){
         eRet = WHERE_ORDERBY_MAX;
         sortFlags = KEYINFO_ORDER_DESC;
    @@ -5148,7 +5189,7 @@ static int selectExpander(Walker *pWalker, Select *p){
                 pNew = sqlite3ExprListAppend(pParse, pNew, pExpr);
                 sqlite3TokenInit(&sColname, zColname);
                 sqlite3ExprListSetName(pParse, pNew, &sColname, 0);
    -            if( pNew && (p->selFlags & SF_NestedFrom)!=0 ){
    +            if( pNew && (p->selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){
                   struct ExprList_item *pX = &pNew->a[pNew->nExpr-1];
                   sqlite3DbFree(db, pX->zEName);
                   if( pSub ){
    @@ -5352,6 +5393,7 @@ static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){
       struct AggInfo_func *pFunc;
       int nReg = pAggInfo->nFunc + pAggInfo->nColumn;
       if( nReg==0 ) return;
    +  if( pParse->nErr ) return;
     #ifdef SQLITE_DEBUG
       /* Verify that all AggInfo registers are within the range specified by
       ** AggInfo.mnReg..AggInfo.mxReg */
    @@ -5493,7 +5535,7 @@ static void updateAccumulator(Parse *pParse, int regAcc, AggInfo *pAggInfo){
     
       pAggInfo->directMode = 0;
       if( addrHitTest ){
    -    sqlite3VdbeJumpHere(v, addrHitTest);
    +    sqlite3VdbeJumpHereOrPopInst(v, addrHitTest);
       }
     }
     
    @@ -6621,7 +6663,6 @@ int sqlite3Select(
          
         } /* endif pGroupBy.  Begin aggregate queries without GROUP BY: */
         else {
    -#ifndef SQLITE_OMIT_BTREECOUNT
           Table *pTab;
           if( (pTab = isSimpleCount(p, &sAggInfo))!=0 ){
             /* If isSimpleCount() returns a pointer to a Table structure, then
    @@ -6657,13 +6698,15 @@ int sqlite3Select(
             ** passed to keep OP_OpenRead happy.
             */
             if( !HasRowid(pTab) ) pBest = sqlite3PrimaryKeyIndex(pTab);
    -        for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
    -          if( pIdx->bUnordered==0
    -           && pIdx->szIdxRowszTabRow
    -           && pIdx->pPartIdxWhere==0
    -           && (!pBest || pIdx->szIdxRowszIdxRow)
    -          ){
    -            pBest = pIdx;
    +        if( !p->pSrc->a[0].fg.notIndexed ){
    +          for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
    +            if( pIdx->bUnordered==0
    +             && pIdx->szIdxRowszTabRow
    +             && pIdx->pPartIdxWhere==0
    +             && (!pBest || pIdx->szIdxRowszIdxRow)
    +            ){
    +              pBest = pIdx;
    +            }
               }
             }
             if( pBest ){
    @@ -6679,9 +6722,7 @@ int sqlite3Select(
             sqlite3VdbeAddOp2(v, OP_Count, iCsr, sAggInfo.aFunc[0].iMem);
             sqlite3VdbeAddOp1(v, OP_Close, iCsr);
             explainSimpleCount(pParse, pTab, pBest);
    -      }else
    -#endif /* SQLITE_OMIT_BTREECOUNT */
    -      {
    +      }else{
             int regAcc = 0;           /* "populate accumulators" flag */
     
             /* If there are accumulator registers but no min() or max() functions
    diff --git a/src/shell.c.in b/src/shell.c.in
    index 0532f04..5858296 100644
    --- a/src/shell.c.in
    +++ b/src/shell.c.in
    @@ -17,6 +17,14 @@
     #define _CRT_SECURE_NO_WARNINGS
     #endif
     
    +/*
    +** Determine if we are dealing with WinRT, which provides only a subset of
    +** the full Win32 API.
    +*/
    +#if !defined(SQLITE_OS_WINRT)
    +# define SQLITE_OS_WINRT 0
    +#endif
    +
     /*
     ** Warning pragmas copied from msvc.h in the core.
     */
    @@ -129,22 +137,26 @@ typedef unsigned char u8;
     
     
     #if defined(_WIN32) || defined(WIN32)
    -# include 
    -# include 
    -# define isatty(h) _isatty(h)
    -# ifndef access
    -#  define access(f,m) _access((f),(m))
    +# if SQLITE_OS_WINRT
    +#  define SQLITE_OMIT_POPEN 1
    +# else
    +#  include 
    +#  include 
    +#  define isatty(h) _isatty(h)
    +#  ifndef access
    +#   define access(f,m) _access((f),(m))
    +#  endif
    +#  ifndef unlink
    +#   define unlink _unlink
    +#  endif
    +#  ifndef strdup
    +#   define strdup _strdup
    +#  endif
    +#  undef popen
    +#  define popen _popen
    +#  undef pclose
    +#  define pclose _pclose
     # endif
    -# ifndef unlink
    -#  define unlink _unlink
    -# endif
    -# ifndef strdup
    -#  define strdup _strdup
    -# endif
    -# undef popen
    -# define popen _popen
    -# undef pclose
    -# define pclose _pclose
     #else
      /* Make sure isatty() has a prototype. */
      extern int isatty(int);
    @@ -173,6 +185,9 @@ typedef unsigned char u8;
     #define ToLower(X)  (char)tolower((unsigned char)X)
     
     #if defined(_WIN32) || defined(WIN32)
    +#if SQLITE_OS_WINRT
    +#include 
    +#endif
     #include 
     
     /* string conversion routines only needed on Win32 */
    @@ -188,7 +203,7 @@ extern LPWSTR sqlite3_win32_utf8_to_unicode(const char *zText);
     ** rendering quoted strings that contain \n characters).  The following
     ** routines take care of that.
     */
    -#if defined(_WIN32) || defined(WIN32)
    +#if (defined(_WIN32) || defined(WIN32)) && !SQLITE_OS_WINRT
     static void setBinaryMode(FILE *file, int isOutput){
       if( isOutput ) fflush(file);
       _setmode(_fileno(file), _O_BINARY);
    @@ -292,6 +307,7 @@ static int hasTimer(void){
       if( getProcessTimesAddr ){
         return 1;
       } else {
    +#if !SQLITE_OS_WINRT
         /* GetProcessTimes() isn't supported in WIN95 and some other Windows
         ** versions. See if the version we are running on has it, and if it
         ** does, save off a pointer to it and the current process handle.
    @@ -308,6 +324,7 @@ static int hasTimer(void){
             FreeLibrary(hinstLib);
           }
         }
    +#endif
       }
       return 0;
     }
    @@ -397,6 +414,15 @@ static sqlite3 *globalDb = 0;
     */
     static volatile int seenInterrupt = 0;
     
    +#ifdef SQLITE_DEBUG
    +/*
    +** Out-of-memory simulator variables
    +*/
    +static unsigned int oomCounter = 0;    /* Simulate OOM when equals 1 */
    +static unsigned int oomRepeat = 0;     /* Number of OOMs in a row */
    +static void*(*defaultMalloc)(int) = 0; /* The low-level malloc routine */
    +#endif /* SQLITE_DEBUG */
    +
     /*
     ** This is the name of our program. It is set in main(), used
     ** in a number of other places, mostly for error messages.
    @@ -448,6 +474,49 @@ static void shell_out_of_memory(void){
       exit(1);
     }
     
    +#ifdef SQLITE_DEBUG
    +/* This routine is called when a simulated OOM occurs.  It is broken
    +** out as a separate routine to make it easy to set a breakpoint on
    +** the OOM
    +*/
    +void shellOomFault(void){
    +  if( oomRepeat>0 ){
    +    oomRepeat--;
    +  }else{
    +    oomCounter--;
    +  }
    +}
    +#endif /* SQLITE_DEBUG */
    +
    +#ifdef SQLITE_DEBUG
    +/* This routine is a replacement malloc() that is used to simulate
    +** Out-Of-Memory (OOM) errors for testing purposes.
    +*/
    +static void *oomMalloc(int nByte){
    +  if( oomCounter ){
    +    if( oomCounter==1 ){
    +      shellOomFault();
    +      return 0;
    +    }else{
    +      oomCounter--;
    +    }
    +  }
    +  return defaultMalloc(nByte);
    +}
    +#endif /* SQLITE_DEBUG */
    +
    +#ifdef SQLITE_DEBUG
    +/* Register the OOM simulator.  This must occur before any memory
    +** allocations */
    +static void registerOomSimulator(void){
    +  sqlite3_mem_methods mem;
    +  sqlite3_config(SQLITE_CONFIG_GETMALLOC, &mem);
    +  defaultMalloc = mem.xMalloc;
    +  mem.xMalloc = oomMalloc;
    +  sqlite3_config(SQLITE_CONFIG_MALLOC, &mem);
    +}
    +#endif
    +
     /*
     ** Write I/O traces to the following stream.
     */
    @@ -941,6 +1010,7 @@ INCLUDE ../ext/misc/fileio.c
     INCLUDE ../ext/misc/completion.c
     INCLUDE ../ext/misc/appendvfs.c
     INCLUDE ../ext/misc/memtrace.c
    +INCLUDE ../ext/misc/uint.c
     #ifdef SQLITE_HAVE_ZLIB
     INCLUDE ../ext/misc/zipfile.c
     INCLUDE ../ext/misc/sqlar.c
    @@ -1037,6 +1107,7 @@ struct ShellState {
       unsigned mxProgress;   /* Maximum progress callbacks before failing */
       unsigned flgProgress;  /* Flags for the progress callback */
       unsigned shellFlgs;    /* Various flags */
    +  unsigned priorShFlgs;  /* Saved copy of flags */
       sqlite3_int64 szMax;   /* --maxsize argument to .open */
       char *zDestTable;      /* Name of destination table when MODE_Insert */
       char *zTempFile;       /* Temporary file that might need deleting */
    @@ -1337,11 +1408,13 @@ edit_func_end:
     */
     static void outputModePush(ShellState *p){
       p->modePrior = p->mode;
    +  p->priorShFlgs = p->shellFlgs;
       memcpy(p->colSepPrior, p->colSeparator, sizeof(p->colSeparator));
       memcpy(p->rowSepPrior, p->rowSeparator, sizeof(p->rowSeparator));
     }
     static void outputModePop(ShellState *p){
       p->mode = p->modePrior;
    +  p->shellFlgs = p->priorShFlgs;
       memcpy(p->colSeparator, p->colSepPrior, sizeof(p->colSeparator));
       memcpy(p->rowSeparator, p->rowSepPrior, sizeof(p->rowSeparator));
     }
    @@ -2306,8 +2379,7 @@ static void set_table_name(ShellState *p, const char *zName){
     */
     static int run_table_dump_query(
       ShellState *p,           /* Query context */
    -  const char *zSelect,     /* SELECT statement to extract content */
    -  const char *zFirstRow    /* Print before first row, if not NULL */
    +  const char *zSelect      /* SELECT statement to extract content */
     ){
       sqlite3_stmt *pSelect;
       int rc;
    @@ -2324,10 +2396,6 @@ static int run_table_dump_query(
       rc = sqlite3_step(pSelect);
       nResult = sqlite3_column_count(pSelect);
       while( rc==SQLITE_ROW ){
    -    if( zFirstRow ){
    -      utf8_printf(p->out, "%s", zFirstRow);
    -      zFirstRow = 0;
    -    }
         z = (const char*)sqlite3_column_text(pSelect, 0);
         utf8_printf(p->out, "%s", z);
         for(i=1; idb, 0, 0);
         sqlite3_shathree_init(p->db, 0, 0);
         sqlite3_completion_init(p->db, 0, 0);
    +    sqlite3_uint_init(p->db, 0, 0);
     #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
         sqlite3_dbdata_init(p->db, 0, 0);
     #endif
    @@ -4508,6 +4601,8 @@ struct ImportCtx {
       int n;              /* Number of bytes in z */
       int nAlloc;         /* Space allocated for z[] */
       int nLine;          /* Current line number */
    +  int nRow;           /* Number of rows imported */
    +  int nErr;           /* Number of errors encountered */
       int bNotFirst;      /* True if one or more bytes already read */
       int cTerm;          /* Character that terminated the most recent field */
       int cColSep;        /* The column separator character.  (Usually ",") */
    @@ -4889,11 +4984,15 @@ static void output_reset(ShellState *p){
           zCmd = sqlite3_mprintf("%s %s", zXdgOpenCmd, p->zTempFile);
           if( system(zCmd) ){
             utf8_printf(stderr, "Failed: [%s]\n", zCmd);
    +      }else{
    +        /* Give the start/open/xdg-open command some time to get
    +        ** going before we continue, and potential delete the
    +        ** p->zTempFile data file out from under it */
    +        sqlite3_sleep(2000);
           }
           sqlite3_free(zCmd);
           outputModePop(p);
           p->doXdgOpen = 0;
    -      sqlite3_sleep(100);
         }
     #endif /* !defined(SQLITE_NOHAVE_SYSTEM) */
       }
    @@ -4969,12 +5068,7 @@ static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){
                  "SELECT data FROM sqlite_dbpage(?1) WHERE pgno=1",
                  -1, &pStmt, 0);
       if( rc ){
    -    if( !sqlite3_compileoption_used("ENABLE_DBPAGE_VTAB") ){
    -      utf8_printf(stderr, "the \".dbinfo\" command requires the "
    -                          "-DSQLITE_ENABLE_DBPAGE_VTAB compile-time options\n");
    -    }else{
    -      utf8_printf(stderr, "error: %s\n", sqlite3_errmsg(p->db));
    -    }
    +    utf8_printf(stderr, "error: %s\n", sqlite3_errmsg(p->db));
         sqlite3_finalize(pStmt);
         return 1;
       }
    @@ -5183,9 +5277,21 @@ static void newTempFile(ShellState *p, const char *zSuffix){
         sqlite3_file_control(p->db, 0, SQLITE_FCNTL_TEMPFILENAME, &p->zTempFile);
       }
       if( p->zTempFile==0 ){
    +    /* If p->db is an in-memory database then the TEMPFILENAME file-control
    +    ** will not work and we will need to fallback to guessing */
    +    char *zTemp;
         sqlite3_uint64 r;
         sqlite3_randomness(sizeof(r), &r);
    -    p->zTempFile = sqlite3_mprintf("temp%llx.%s", r, zSuffix);
    +    zTemp = getenv("TEMP");
    +    if( zTemp==0 ) zTemp = getenv("TMP");
    +    if( zTemp==0 ){
    +#ifdef _WIN32
    +      zTemp = "\\tmp";
    +#else
    +      zTemp = "/tmp";
    +#endif
    +    }
    +    p->zTempFile = sqlite3_mprintf("%s/temp%llx.%s", zTemp, r, zSuffix);
       }else{
         p->zTempFile = sqlite3_mprintf("%z.%s", p->zTempFile, zSuffix);
       }
    @@ -7209,7 +7315,8 @@ static int do_meta_command(char *zLine, ShellState *p){
     #endif /* !(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) */
     
       if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){
    -    const char *zLike = 0;
    +    char *zLike = 0;
    +    char *zSql;
         int i;
         int savedShowHeader = p->showHeader;
         int savedShellFlags = p->shellFlgs;
    @@ -7237,12 +7344,10 @@ static int do_meta_command(char *zLine, ShellState *p){
               goto meta_command_exit;
             }
           }else if( zLike ){
    -        raw_printf(stderr, "Usage: .dump ?--preserve-rowids? "
    -                           "?--newlines? ?LIKE-PATTERN?\n");
    -        rc = 1;
    -        goto meta_command_exit;
    +        zLike = sqlite3_mprintf("%z OR name LIKE %Q ESCAPE '\\'",
    +                zLike, azArg[i]);
           }else{
    -        zLike = azArg[i];
    +        zLike = sqlite3_mprintf("name LIKE %Q ESCAPE '\\'", azArg[i]);
           }
         }
     
    @@ -7260,35 +7365,25 @@ static int do_meta_command(char *zLine, ShellState *p){
         ** corrupt. */
         sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
         p->nErr = 0;
    -    if( zLike==0 ){
    -      run_schema_dump_query(p,
    -        "SELECT name, type, sql FROM sqlite_master "
    -        "WHERE sql NOT NULL AND type=='table' AND name!='sqlite_sequence'"
    -      );
    -      run_schema_dump_query(p,
    -        "SELECT name, type, sql FROM sqlite_master "
    -        "WHERE name=='sqlite_sequence'"
    -      );
    -      run_table_dump_query(p,
    -        "SELECT sql FROM sqlite_master "
    -        "WHERE sql NOT NULL AND type IN ('index','trigger','view')", 0
    -      );
    -    }else{
    -      char *zSql;
    -      zSql = sqlite3_mprintf(
    -        "SELECT name, type, sql FROM sqlite_master "
    -        "WHERE tbl_name LIKE %Q AND type=='table'"
    -        "  AND sql NOT NULL", zLike);
    -      run_schema_dump_query(p,zSql);
    -      sqlite3_free(zSql);
    -      zSql = sqlite3_mprintf(
    -        "SELECT sql FROM sqlite_master "
    -        "WHERE sql NOT NULL"
    -        "  AND type IN ('index','trigger','view')"
    -        "  AND tbl_name LIKE %Q", zLike);
    -      run_table_dump_query(p, zSql, 0);
    -      sqlite3_free(zSql);
    -    }
    +    if( zLike==0 ) zLike = sqlite3_mprintf("true");
    +    zSql = sqlite3_mprintf(
    +      "SELECT name, type, sql FROM sqlite_master "
    +      "WHERE (%s) AND type=='table'"
    +      "  AND sql NOT NULL"
    +      " ORDER BY tbl_name='sqlite_sequence', rowid",
    +      zLike
    +    );
    +    run_schema_dump_query(p,zSql);
    +    sqlite3_free(zSql);
    +    zSql = sqlite3_mprintf(
    +      "SELECT sql FROM sqlite_master "
    +      "WHERE (%s) AND sql NOT NULL"
    +      "  AND type IN ('index','trigger','view')",
    +      zLike
    +    );
    +    run_table_dump_query(p, zSql);
    +    sqlite3_free(zSql);
    +    sqlite3_free(zLike);
         if( p->writableSchema ){
           raw_printf(p->out, "PRAGMA writable_schema=OFF;\n");
           p->writableSchema = 0;
    @@ -7391,6 +7486,7 @@ static int do_meta_command(char *zLine, ShellState *p){
           { "tempfilename",   SQLITE_FCNTL_TEMPFILENAME,    ""               },
           { "has_moved",      SQLITE_FCNTL_HAS_MOVED,       ""               },  
           { "lock_timeout",   SQLITE_FCNTL_LOCK_TIMEOUT,    "MILLISEC"       },
    +      { "reserve_bytes",  SQLITE_FCNTL_RESERVE_BYTES,   "[N]"            },
         };
         int filectrl = -1;
         int iCtrl = -1;
    @@ -7398,10 +7494,21 @@ static int do_meta_command(char *zLine, ShellState *p){
         int isOk = 0;            /* 0: usage  1: %lld  2: no-result */
         int n2, i;
         const char *zCmd = 0;
    +    const char *zSchema = 0;
     
         open_db(p, 0);
         zCmd = nArg>=2 ? azArg[1] : "help";
     
    +    if( zCmd[0]=='-' 
    +     && (strcmp(zCmd,"--schema")==0 || strcmp(zCmd,"-schema")==0)
    +     && nArg>=4
    +    ){
    +      zSchema = azArg[2];
    +      for(i=3; idb, 0, SQLITE_FCNTL_SIZE_LIMIT, &iRes);
    +          sqlite3_file_control(p->db, zSchema, SQLITE_FCNTL_SIZE_LIMIT, &iRes);
               isOk = 1;
               break;
             }
    @@ -7452,7 +7559,7 @@ static int do_meta_command(char *zLine, ShellState *p){
               int x;
               if( nArg!=3 ) break;
               x = (int)integerValue(azArg[2]);
    -          sqlite3_file_control(p->db, 0, filectrl, &x);
    +          sqlite3_file_control(p->db, zSchema, filectrl, &x);
               isOk = 2;
               break;
             }
    @@ -7461,7 +7568,7 @@ static int do_meta_command(char *zLine, ShellState *p){
               int x;
               if( nArg!=2 && nArg!=3 ) break;
               x = nArg==3 ? booleanValue(azArg[2]) : -1;
    -          sqlite3_file_control(p->db, 0, filectrl, &x);
    +          sqlite3_file_control(p->db, zSchema, filectrl, &x);
               iRes = x;
               isOk = 1;
               break;
    @@ -7469,7 +7576,7 @@ static int do_meta_command(char *zLine, ShellState *p){
             case SQLITE_FCNTL_HAS_MOVED: {
               int x;
               if( nArg!=2 ) break;
    -          sqlite3_file_control(p->db, 0, filectrl, &x);
    +          sqlite3_file_control(p->db, zSchema, filectrl, &x);
               iRes = x;
               isOk = 1;
               break;
    @@ -7477,7 +7584,7 @@ static int do_meta_command(char *zLine, ShellState *p){
             case SQLITE_FCNTL_TEMPFILENAME: {
               char *z = 0;
               if( nArg!=2 ) break;
    -          sqlite3_file_control(p->db, 0, filectrl, &z);
    +          sqlite3_file_control(p->db, zSchema, filectrl, &z);
               if( z ){
                 utf8_printf(p->out, "%s\n", z);
                 sqlite3_free(z);
    @@ -7485,6 +7592,18 @@ static int do_meta_command(char *zLine, ShellState *p){
               isOk = 2;
               break;
             }
    +        case SQLITE_FCNTL_RESERVE_BYTES: {
    +          int x;
    +          if( nArg>=3 ){
    +            x = atoi(azArg[2]);
    +            sqlite3_file_control(p->db, zSchema, filectrl, &x);
    +          }
    +          x = -1;
    +          sqlite3_file_control(p->db, zSchema, filectrl, &x);
    +          utf8_printf(p->out,"%d\n", x);
    +          isOk = 2;
    +          break;
    +        }
           }
         }
         if( isOk==0 && iCtrl>=0 ){
    @@ -7568,8 +7687,8 @@ static int do_meta_command(char *zLine, ShellState *p){
       }else
     
       if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
    -    char *zTable;               /* Insert data into this table */
    -    char *zFile;                /* Name of file to extra content from */
    +    char *zTable = 0;           /* Insert data into this table */
    +    char *zFile = 0;            /* Name of file to extra content from */
         sqlite3_stmt *pStmt = NULL; /* A statement */
         int nCol;                   /* Number of columns in the table */
         int nByte;                  /* Number of bytes in an SQL string */
    @@ -7580,51 +7699,108 @@ static int do_meta_command(char *zLine, ShellState *p){
         ImportCtx sCtx;             /* Reader context */
         char *(SQLITE_CDECL *xRead)(ImportCtx*); /* Func to read one value */
         int (SQLITE_CDECL *xCloser)(FILE*);      /* Func to close file */
    +    int eVerbose = 0;           /* Larger for more console output */
    +    int nSkip = 0;              /* Initial lines to skip */
    +    int useOutputMode = 1;      /* Use output mode to determine separators */
     
    -    if( nArg!=3 ){
    -      raw_printf(stderr, "Usage: .import FILE TABLE\n");
    +    memset(&sCtx, 0, sizeof(sCtx));
    +    if( p->mode==MODE_Ascii ){
    +      xRead = ascii_read_one_field;
    +    }else{
    +      xRead = csv_read_one_field;
    +    }
    +    for(i=1; iout, "ERROR: extra argument: \"%s\".  Usage:\n", z);
    +          showHelp(p->out, "import");
    +          rc = 1;
    +          goto meta_command_exit;
    +        }
    +      }else if( strcmp(z,"-v")==0 ){
    +        eVerbose++;
    +      }else if( strcmp(z,"-skip")==0 && iout, "ERROR: unknown option: \"%s\".  Usage:\n", z);
    +        showHelp(p->out, "import");
    +        rc = 1;
    +        goto meta_command_exit;
    +      }
    +    }
    +    if( zTable==0 ){
    +      utf8_printf(p->out, "ERROR: missing %s argument. Usage:\n",
    +                  zFile==0 ? "FILE" : "TABLE");
    +      showHelp(p->out, "import");
    +      rc = 1;
           goto meta_command_exit;
         }
    -    zFile = azArg[1];
    -    zTable = azArg[2];
         seenInterrupt = 0;
    -    memset(&sCtx, 0, sizeof(sCtx));
         open_db(p, 0);
    -    nSep = strlen30(p->colSeparator);
    -    if( nSep==0 ){
    -      raw_printf(stderr,
    -                 "Error: non-null column separator required for import\n");
    -      return 1;
    -    }
    -    if( nSep>1 ){
    -      raw_printf(stderr, "Error: multi-character column separators not allowed"
    -                      " for import\n");
    -      return 1;
    -    }
    -    nSep = strlen30(p->rowSeparator);
    -    if( nSep==0 ){
    -      raw_printf(stderr, "Error: non-null row separator required for import\n");
    -      return 1;
    -    }
    -    if( nSep==2 && p->mode==MODE_Csv && strcmp(p->rowSeparator, SEP_CrLf)==0 ){
    -      /* When importing CSV (only), if the row separator is set to the
    -      ** default output row separator, change it to the default input
    -      ** row separator.  This avoids having to maintain different input
    -      ** and output row separators. */
    -      sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
    +    if( useOutputMode ){
    +      /* If neither the --csv or --ascii options are specified, then set
    +      ** the column and row separator characters from the output mode. */
    +      nSep = strlen30(p->colSeparator);
    +      if( nSep==0 ){
    +        raw_printf(stderr,
    +                   "Error: non-null column separator required for import\n");
    +        rc = 1;
    +        goto meta_command_exit;
    +      }
    +      if( nSep>1 ){
    +        raw_printf(stderr, 
    +              "Error: multi-character column separators not allowed"
    +              " for import\n");
    +        rc = 1;
    +        goto meta_command_exit;
    +      }
           nSep = strlen30(p->rowSeparator);
    -    }
    -    if( nSep>1 ){
    -      raw_printf(stderr, "Error: multi-character row separators not allowed"
    -                      " for import\n");
    -      return 1;
    +      if( nSep==0 ){
    +        raw_printf(stderr,
    +            "Error: non-null row separator required for import\n");
    +        rc = 1;
    +        goto meta_command_exit;
    +      }
    +      if( nSep==2 && p->mode==MODE_Csv && strcmp(p->rowSeparator,SEP_CrLf)==0 ){
    +        /* When importing CSV (only), if the row separator is set to the
    +        ** default output row separator, change it to the default input
    +        ** row separator.  This avoids having to maintain different input
    +        ** and output row separators. */
    +        sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
    +        nSep = strlen30(p->rowSeparator);
    +      }
    +      if( nSep>1 ){
    +        raw_printf(stderr, "Error: multi-character row separators not allowed"
    +                           " for import\n");
    +        rc = 1;
    +        goto meta_command_exit;
    +      }
    +      sCtx.cColSep = p->colSeparator[0];
    +      sCtx.cRowSep = p->rowSeparator[0];
         }
         sCtx.zFile = zFile;
         sCtx.nLine = 1;
         if( sCtx.zFile[0]=='|' ){
     #ifdef SQLITE_OMIT_POPEN
           raw_printf(stderr, "Error: pipes are not supported in this OS\n");
    -      return 1;
    +      rc = 1;
    +      goto meta_command_exit;
     #else
           sCtx.in = popen(sCtx.zFile+1, "r");
           sCtx.zFile = "";
    @@ -7634,17 +7810,26 @@ static int do_meta_command(char *zLine, ShellState *p){
           sCtx.in = fopen(sCtx.zFile, "rb");
           xCloser = fclose;
         }
    -    if( p->mode==MODE_Ascii ){
    -      xRead = ascii_read_one_field;
    -    }else{
    -      xRead = csv_read_one_field;
    -    }
         if( sCtx.in==0 ){
           utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
    -      return 1;
    +      rc = 1;
    +      goto meta_command_exit;
    +    }
    +    if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
    +      char zSep[2];
    +      zSep[1] = 0;
    +      zSep[0] = sCtx.cColSep;
    +      utf8_printf(p->out, "Column separator ");
    +      output_c_string(p->out, zSep);
    +      utf8_printf(p->out, ", row separator ");
    +      zSep[0] = sCtx.cRowSep;
    +      output_c_string(p->out, zSep);
    +      utf8_printf(p->out, "\n");
    +    }
    +    while( (nSkip--)>0 ){
    +      while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){}
    +      sCtx.nLine++;
         }
    -    sCtx.cColSep = p->colSeparator[0];
    -    sCtx.cRowSep = p->rowSeparator[0];
         zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
         if( zSql==0 ){
           xCloser(sCtx.in);
    @@ -7666,9 +7851,13 @@ static int do_meta_command(char *zLine, ShellState *p){
             sqlite3_free(sCtx.z);
             xCloser(sCtx.in);
             utf8_printf(stderr,"%s: empty file\n", sCtx.zFile);
    -        return 1;
    +        rc = 1;
    +        goto meta_command_exit;
           }
           zCreate = sqlite3_mprintf("%z\n)", zCreate);
    +      if( eVerbose>=1 ){
    +        utf8_printf(p->out, "%s\n", zCreate);
    +      }
           rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
           sqlite3_free(zCreate);
           if( rc ){
    @@ -7676,7 +7865,8 @@ static int do_meta_command(char *zLine, ShellState *p){
                     sqlite3_errmsg(p->db));
             sqlite3_free(sCtx.z);
             xCloser(sCtx.in);
    -        return 1;
    +        rc = 1;
    +        goto meta_command_exit;
           }
           rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
         }
    @@ -7685,7 +7875,8 @@ static int do_meta_command(char *zLine, ShellState *p){
           if (pStmt) sqlite3_finalize(pStmt);
           utf8_printf(stderr,"Error: %s\n", sqlite3_errmsg(p->db));
           xCloser(sCtx.in);
    -      return 1;
    +      rc = 1;
    +      goto meta_command_exit;
         }
         nCol = sqlite3_column_count(pStmt);
         sqlite3_finalize(pStmt);
    @@ -7704,13 +7895,17 @@ static int do_meta_command(char *zLine, ShellState *p){
         }
         zSql[j++] = ')';
         zSql[j] = 0;
    +    if( eVerbose>=2 ){
    +      utf8_printf(p->out, "Insert using: %s\n", zSql);
    +    }
         rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
         sqlite3_free(zSql);
         if( rc ){
           utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
           if (pStmt) sqlite3_finalize(pStmt);
           xCloser(sCtx.in);
    -      return 1;
    +      rc = 1;
    +      goto meta_command_exit;
         }
         needCommit = sqlite3_get_autocommit(p->db);
         if( needCommit ) sqlite3_exec(p->db, "BEGIN", 0, 0, 0);
    @@ -7753,6 +7948,9 @@ static int do_meta_command(char *zLine, ShellState *p){
             if( rc!=SQLITE_OK ){
               utf8_printf(stderr, "%s:%d: INSERT failed: %s\n", sCtx.zFile,
                           startLine, sqlite3_errmsg(p->db));
    +          sCtx.nErr++;
    +        }else{
    +          sCtx.nRow++;
             }
           }
         }while( sCtx.cTerm!=EOF );
    @@ -7761,6 +7959,11 @@ static int do_meta_command(char *zLine, ShellState *p){
         sqlite3_free(sCtx.z);
         sqlite3_finalize(pStmt);
         if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
    +    if( eVerbose>0 ){
    +      utf8_printf(p->out,
    +          "Added %d rows with %d errors using %d lines of input\n",
    +          sCtx.nRow, sCtx.nErr, sCtx.nLine-1);
    +    }
       }else
     
     #ifndef SQLITE_UNTESTABLE
    @@ -8039,6 +8242,34 @@ static int do_meta_command(char *zLine, ShellState *p){
         }
       }else
     
    +#ifdef SQLITE_DEBUG
    +  if( c=='o' && strcmp(azArg[0],"oom")==0 ){
    +    int i;
    +    for(i=1; iout, "missing argument on \"%s\"\n", azArg[i]);
    +          rc = 1;
    +        }else{
    +          oomRepeat = (int)integerValue(azArg[++i]);
    +        }
    +      }else if( IsDigit(z[0]) ){
    +        oomCounter = (int)integerValue(azArg[i]);
    +      }else{
    +        raw_printf(p->out, "unknown argument: \"%s\"\n", azArg[i]);
    +        raw_printf(p->out, "Usage: .oom [--repeat N] [M]\n");
    +        rc = 1;
    +      }
    +    }
    +    if( rc==0 ){
    +      raw_printf(p->out, "oomCounter = %d\n", oomCounter);
    +      raw_printf(p->out, "oomRepeat  = %d\n", oomRepeat);
    +    }
    +  }else
    +#endif /* SQLITE_DEBUG */
    +
       if( c=='o' && strncmp(azArg[0], "open", n)==0 && n>=2 ){
         char *zNewFilename;  /* Name of the database file to open */
         int iName = 1;       /* Index in azArg[] of the filename */
    @@ -8106,42 +8337,66 @@ static int do_meta_command(char *zLine, ShellState *p){
             && (strncmp(azArg[0], "output", n)==0||strncmp(azArg[0], "once", n)==0))
        || (c=='e' && n==5 && strcmp(azArg[0],"excel")==0)
       ){
    -    const char *zFile = nArg>=2 ? azArg[1] : "stdout";
    +    const char *zFile = 0;
         int bTxtMode = 0;
    -    if( azArg[0][0]=='e' ){
    -      /* Transform the ".excel" command into ".once -x" */
    -      nArg = 2;
    -      azArg[0] = "once";
    -      zFile = azArg[1] = "-x";
    -      n = 4;
    +    int i;
    +    int eMode = 0;
    +    int bBOM = 0;
    +    int bOnce = 0;  /* 0: .output, 1: .once, 2: .excel */
    +
    +    if( c=='e' ){
    +      eMode = 'x';
    +      bOnce = 2;
    +    }else if( strncmp(azArg[0],"once",n)==0 ){
    +      bOnce = 1;
         }
    -    if( nArg>2 ){
    -      utf8_printf(stderr, "Usage: .%s [-e|-x|FILE]\n", azArg[0]);
    -      rc = 1;
    -      goto meta_command_exit;
    -    }
    -    if( n>1 && strncmp(azArg[0], "once", n)==0 ){
    -      if( nArg<2 ){
    -        raw_printf(stderr, "Usage: .once (-e|-x|FILE)\n");
    +    for(i=1; iout, "ERROR: unknown option: \"%s\".  Usage:\n",
    +                      azArg[i]);
    +          showHelp(p->out, azArg[0]);
    +          rc = 1;
    +          goto meta_command_exit;
    +        }
    +      }else if( zFile==0 ){
    +        zFile = z;
    +      }else{
    +        utf8_printf(p->out,"ERROR: extra parameter: \"%s\".  Usage:\n",
    +                    azArg[i]);
    +        showHelp(p->out, azArg[0]);
             rc = 1;
             goto meta_command_exit;
           }
    +    }
    +    if( zFile==0 ) zFile = "stdout";
    +    if( bOnce ){
           p->outCount = 2;
         }else{
           p->outCount = 0;
         }
         output_reset(p);
    -    if( zFile[0]=='-' && zFile[1]=='-' ) zFile++;
     #ifndef SQLITE_NOHAVE_SYSTEM
    -    if( strcmp(zFile, "-e")==0 || strcmp(zFile, "-x")==0 ){
    +    if( eMode=='e' || eMode=='x' ){
           p->doXdgOpen = 1;
           outputModePush(p);
    -      if( zFile[1]=='x' ){
    +      if( eMode=='x' ){
    +        /* spreadsheet mode.  Output as CSV. */
             newTempFile(p, "csv");
    +        ShellClearFlag(p, SHFLG_Echo);
             p->mode = MODE_Csv;
             sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
             sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf);
           }else{
    +        /* text editor mode */
             newTempFile(p, "txt");
             bTxtMode = 1;
           }
    @@ -8160,6 +8415,7 @@ static int do_meta_command(char *zLine, ShellState *p){
             p->out = stdout;
             rc = 1;
           }else{
    +        if( bBOM ) fprintf(p->out,"\357\273\277");
             sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
           }
     #endif
    @@ -8172,6 +8428,7 @@ static int do_meta_command(char *zLine, ShellState *p){
             p->out = stdout;
             rc = 1;
           } else {
    +        if( bBOM ) fprintf(p->out,"\357\273\277");
             sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
           }
         }
    @@ -9235,7 +9492,6 @@ static int do_meta_command(char *zLine, ShellState *p){
           { "prng_restore",       SQLITE_TESTCTRL_PRNG_RESTORE,  ""               },
           { "prng_save",          SQLITE_TESTCTRL_PRNG_SAVE,     ""               },
           { "prng_seed",          SQLITE_TESTCTRL_PRNG_SEED,     "SEED ?db?"      },
    -      { "reserve",            SQLITE_TESTCTRL_RESERVE,      "BYTES-OF-RESERVE"},
         };
         int testctrl = -1;
         int iCtrl = -1;
    @@ -9288,7 +9544,6 @@ static int do_meta_command(char *zLine, ShellState *p){
     
             /* sqlite3_test_control(int, db, int) */
             case SQLITE_TESTCTRL_OPTIMIZATIONS:
    -        case SQLITE_TESTCTRL_RESERVE:
               if( nArg==3 ){
                 int opt = (int)strtol(azArg[2], 0, 0);
                 rc2 = sqlite3_test_control(testctrl, p->db, opt);
    @@ -10060,14 +10315,18 @@ static void main_init(ShellState *data) {
     */
     #ifdef _WIN32
     static void printBold(const char *zText){
    +#if !SQLITE_OS_WINRT
       HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
       CONSOLE_SCREEN_BUFFER_INFO defaultScreenInfo;
       GetConsoleScreenBufferInfo(out, &defaultScreenInfo);
       SetConsoleTextAttribute(out,
              FOREGROUND_RED|FOREGROUND_INTENSITY
       );
    +#endif
       printf("%s", zText);
    +#if !SQLITE_OS_WINRT
       SetConsoleTextAttribute(out, defaultScreenInfo.wAttributes);
    +#endif
     }
     #else
     static void printBold(const char *zText){
    @@ -10122,6 +10381,10 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
       stdin_is_interactive = isatty(0);
       stdout_is_console = isatty(1);
     
    +#ifdef SQLITE_DEBUG
    +  registerOomSimulator();
    +#endif
    +
     #if !defined(_WIN32_WCE)
       if( getenv("SQLITE_DEBUG_BREAK") ){
         if( isatty(0) && isatty(2) ){
    @@ -10131,7 +10394,11 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
           fgetc(stdin);
         }else{
     #if defined(_WIN32) || defined(WIN32)
    +#if SQLITE_OS_WINRT
    +      __debugbreak();
    +#else
           DebugBreak();
    +#endif
     #elif defined(SIGTRAP)
           raise(SIGTRAP);
     #endif
    diff --git a/src/sqlite.h.in b/src/sqlite.h.in
    index 367242b..0b08cd5 100644
    --- a/src/sqlite.h.in
    +++ b/src/sqlite.h.in
    @@ -299,26 +299,22 @@ typedef sqlite_uint64 sqlite3_uint64;
     ** the [sqlite3] object is successfully destroyed and all associated
     ** resources are deallocated.
     **
    -** ^If the database connection is associated with unfinalized prepared
    -** statements or unfinished sqlite3_backup objects then sqlite3_close()
    -** will leave the database connection open and return [SQLITE_BUSY].
    -** ^If sqlite3_close_v2() is called with unfinalized prepared statements
    -** and/or unfinished sqlite3_backups, then the database connection becomes
    -** an unusable "zombie" which will automatically be deallocated when the
    -** last prepared statement is finalized or the last sqlite3_backup is
    -** finished.  The sqlite3_close_v2() interface is intended for use with
    -** host languages that are garbage collected, and where the order in which
    -** destructors are called is arbitrary.
    -**
    -** Applications should [sqlite3_finalize | finalize] all [prepared statements],
    -** [sqlite3_blob_close | close] all [BLOB handles], and 
    +** Ideally, applications should [sqlite3_finalize | finalize] all
    +** [prepared statements], [sqlite3_blob_close | close] all [BLOB handles], and 
     ** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated
    -** with the [sqlite3] object prior to attempting to close the object.  ^If
    -** sqlite3_close_v2() is called on a [database connection] that still has
    -** outstanding [prepared statements], [BLOB handles], and/or
    -** [sqlite3_backup] objects then it returns [SQLITE_OK] and the deallocation
    -** of resources is deferred until all [prepared statements], [BLOB handles],
    -** and [sqlite3_backup] objects are also destroyed.
    +** with the [sqlite3] object prior to attempting to close the object.
    +** ^If the database connection is associated with unfinalized prepared
    +** statements, BLOB handlers, and/or unfinished sqlite3_backup objects then
    +** sqlite3_close() will leave the database connection open and return
    +** [SQLITE_BUSY]. ^If sqlite3_close_v2() is called with unfinalized prepared
    +** statements, unclosed BLOB handlers, and/or unfinished sqlite3_backups,
    +** it returns [SQLITE_OK] regardless, but instead of deallocating the database
    +** connection immediately, it marks the database connection as an unusable
    +** "zombie" and makes arrangements to automatically deallocate the database
    +** connection after all prepared statements are finalized, all BLOB handles
    +** are closed, and all backups have finished. The sqlite3_close_v2() interface
    +** is intended for use with host languages that are garbage collected, and
    +** where the order in which destructors are called is arbitrary.
     **
     ** ^If an [sqlite3] object is destroyed while a transaction is open,
     ** the transaction is automatically rolled back.
    @@ -507,10 +503,12 @@ int sqlite3_exec(
     #define SQLITE_IOERR_BEGIN_ATOMIC      (SQLITE_IOERR | (29<<8))
     #define SQLITE_IOERR_COMMIT_ATOMIC     (SQLITE_IOERR | (30<<8))
     #define SQLITE_IOERR_ROLLBACK_ATOMIC   (SQLITE_IOERR | (31<<8))
    +#define SQLITE_IOERR_DATA              (SQLITE_IOERR | (32<<8))
     #define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED |  (1<<8))
     #define SQLITE_LOCKED_VTAB             (SQLITE_LOCKED |  (2<<8))
     #define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
     #define SQLITE_BUSY_SNAPSHOT           (SQLITE_BUSY   |  (2<<8))
    +#define SQLITE_BUSY_TIMEOUT            (SQLITE_BUSY   |  (3<<8))
     #define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
     #define SQLITE_CANTOPEN_ISDIR          (SQLITE_CANTOPEN | (2<<8))
     #define SQLITE_CANTOPEN_FULLPATH       (SQLITE_CANTOPEN | (3<<8))
    @@ -519,6 +517,7 @@ int sqlite3_exec(
     #define SQLITE_CANTOPEN_SYMLINK        (SQLITE_CANTOPEN | (6<<8))
     #define SQLITE_CORRUPT_VTAB            (SQLITE_CORRUPT | (1<<8))
     #define SQLITE_CORRUPT_SEQUENCE        (SQLITE_CORRUPT | (2<<8))
    +#define SQLITE_CORRUPT_INDEX           (SQLITE_CORRUPT | (3<<8))
     #define SQLITE_READONLY_RECOVERY       (SQLITE_READONLY | (1<<8))
     #define SQLITE_READONLY_CANTLOCK       (SQLITE_READONLY | (2<<8))
     #define SQLITE_READONLY_ROLLBACK       (SQLITE_READONLY | (3<<8))
    @@ -1087,10 +1086,12 @@ struct sqlite3_io_methods {
     ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
     **
     ** 
  • [[SQLITE_FCNTL_LOCK_TIMEOUT]] -** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode causes attempts to obtain -** a file lock using the xLock or xShmLock methods of the VFS to wait -** for up to M milliseconds before failing, where M is the single -** unsigned integer parameter. +** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode is used to configure a VFS +** to block for up to M milliseconds before failing when attempting to +** obtain a file lock using the xLock or xShmLock methods of the VFS. +** The parameter is a pointer to a 32-bit signed integer that contains +** the value that M is to be set to. Before returning, the 32-bit signed +** integer is overwritten with the previous value of M. ** **
  • [[SQLITE_FCNTL_DATA_VERSION]] ** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to @@ -1112,6 +1113,11 @@ struct sqlite3_io_methods { ** happen either internally or externally and that are associated with ** a particular attached database. ** +**
  • [[SQLITE_FCNTL_CKPT_START]] +** The [SQLITE_FCNTL_CKPT_START] opcode is invoked from within a checkpoint +** in wal mode before the client starts to copy pages from the wal +** file to the database file. +** **
  • [[SQLITE_FCNTL_CKPT_DONE]] ** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint ** in wal mode after the client has finished copying pages from the wal @@ -1155,6 +1161,8 @@ struct sqlite3_io_methods { #define SQLITE_FCNTL_DATA_VERSION 35 #define SQLITE_FCNTL_SIZE_LIMIT 36 #define SQLITE_FCNTL_CKPT_DONE 37 +#define SQLITE_FCNTL_RESERVE_BYTES 38 +#define SQLITE_FCNTL_CKPT_START 39 /* deprecated names */ #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE @@ -3533,8 +3541,19 @@ int sqlite3_open_v2( ** that check if a database file was a URI that contained a specific query ** parameter, and if so obtains the value of that query parameter. ** -** If F is the database filename pointer passed into the xOpen() method of -** a VFS implementation or it is the return value of [sqlite3_db_filename()] +** The first parameter to these interfaces (hereafter referred to +** as F) must be one of: +**
      +**
    • A database filename pointer created by the SQLite core and +** passed into the xOpen() method of a VFS implemention, or +**
    • A filename obtained from [sqlite3_db_filename()], or +**
    • A new filename constructed using [sqlite3_create_filename()]. +**
    +** If the F parameter is not one of the above, then the behavior is +** undefined and probably undesirable. Older versions of SQLite were +** more tolerant of invalid F parameters than newer versions. +** +** If F is a suitable filename (as described in the previous paragraph) ** and if P is the name of the query parameter, then ** sqlite3_uri_parameter(F,P) returns the value of the P ** parameter if it exists or a NULL pointer if P does not appear as a @@ -3617,6 +3636,78 @@ const char *sqlite3_filename_database(const char*); const char *sqlite3_filename_journal(const char*); const char *sqlite3_filename_wal(const char*); +/* +** CAPI3REF: Database File Corresponding To A Journal +** +** ^If X is the name of a rollback or WAL-mode journal file that is +** passed into the xOpen method of [sqlite3_vfs], then +** sqlite3_database_file_object(X) returns a pointer to the [sqlite3_file] +** object that represents the main database file. +** +** This routine is intended for use in custom [VFS] implementations +** only. It is not a general-purpose interface. +** The argument sqlite3_file_object(X) must be a filename pointer that +** has been passed into [sqlite3_vfs].xOpen method where the +** flags parameter to xOpen contains one of the bits +** [SQLITE_OPEN_MAIN_JOURNAL] or [SQLITE_OPEN_WAL]. Any other use +** of this routine results in undefined and probably undesirable +** behavior. +*/ +sqlite3_file *sqlite3_database_file_object(const char*); + +/* +** CAPI3REF: Create and Destroy VFS Filenames +** +** These interfces are provided for use by [VFS shim] implementations and +** are not useful outside of that context. +** +** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of +** database filename D with corresponding journal file J and WAL file W and +** with N URI parameters key/values pairs in the array P. The result from +** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that +** is safe to pass to routines like: +**
      +**
    • [sqlite3_uri_parameter()], +**
    • [sqlite3_uri_boolean()], +**
    • [sqlite3_uri_int64()], +**
    • [sqlite3_uri_key()], +**
    • [sqlite3_filename_database()], +**
    • [sqlite3_filename_journal()], or +**
    • [sqlite3_filename_wal()]. +**
    +** If a memory allocation error occurs, sqlite3_create_filename() might +** return a NULL pointer. The memory obtained from sqlite3_create_filename(X) +** must be released by a corresponding call to sqlite3_free_filename(Y). +** +** The P parameter in sqlite3_create_filename(D,J,W,N,P) should be an array +** of 2*N pointers to strings. Each pair of pointers in this array corresponds +** to a key and value for a query parameter. The P parameter may be a NULL +** pointer if N is zero. None of the 2*N pointers in the P array may be +** NULL pointers and key pointers should not be empty strings. +** None of the D, J, or W parameters to sqlite3_create_filename(D,J,W,N,P) may +** be NULL pointers, though they can be empty strings. +** +** The sqlite3_free_filename(Y) routine releases a memory allocation +** previously obtained from sqlite3_create_filename(). Invoking +** sqlite3_free_filename(Y) where Y is a NULL pointer is a harmless no-op. +** +** If the Y parameter to sqlite3_free_filename(Y) is anything other +** than a NULL pointer or a pointer previously acquired from +** sqlite3_create_filename(), then bad things such as heap +** corruption or segfaults may occur. The value Y should be +** used again after sqlite3_free_filename(Y) has been called. This means +** that if the [sqlite3_vfs.xOpen()] method of a VFS has been called using Y, +** then the corresponding [sqlite3_module.xClose() method should also be +** invoked prior to calling sqlite3_free_filename(Y). +*/ +char *sqlite3_create_filename( + const char *zDatabase, + const char *zJournal, + const char *zWal, + int nParam, + const char **azParam +); +void sqlite3_free_filename(char*); /* ** CAPI3REF: Error Codes And Messages @@ -4199,12 +4290,30 @@ typedef struct sqlite3_context sqlite3_context; ** [sqlite3_bind_parameter_index()] API if desired. ^The index ** for "?NNN" parameters is the value of NNN. ** ^The NNN value must be between 1 and the [sqlite3_limit()] -** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999). +** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 32766). ** ** ^The third argument is the value to bind to the parameter. ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16() ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter ** is ignored and the end result is the same as sqlite3_bind_null(). +** ^If the third parameter to sqlite3_bind_text() is not NULL, then +** it should be a pointer to well-formed UTF8 text. +** ^If the third parameter to sqlite3_bind_text16() is not NULL, then +** it should be a pointer to well-formed UTF16 text. +** ^If the third parameter to sqlite3_bind_text64() is not NULL, then +** it should be a pointer to a well-formed unicode string that is +** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16 +** otherwise. +** +** [[byte-order determination rules]] ^The byte-order of +** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF) +** found in first character, which is removed, or in the absence of a BOM +** the byte order is the native byte order of the host +** machine for sqlite3_bind_text16() or the byte order specified in +** the 6th parameter for sqlite3_bind_text64().)^ +** ^If UTF16 input text contains invalid unicode +** characters, then SQLite might change those invalid characters +** into the unicode replacement character: U+FFFD. ** ** ^(In those routines that have a fourth argument, its value is the ** number of bytes in the parameter. To be clear: the value is the @@ -4218,7 +4327,7 @@ typedef struct sqlite3_context sqlite3_context; ** or sqlite3_bind_text16() or sqlite3_bind_text64() then ** that parameter must be the byte offset ** where the NUL terminator would occur assuming the string were NUL -** terminated. If any NUL characters occur at byte offsets less than +** terminated. If any NUL characters occurs at byte offsets less than ** the value of the fourth parameter then the resulting string value will ** contain embedded NULs. The result of expressions involving strings ** with embedded NULs is undefined. @@ -5386,7 +5495,7 @@ void sqlite3_value_free(sqlite3_value*); ** ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is ** determined by the N parameter on first successful call. Changing the -** value of N in any subsequents call to sqlite3_aggregate_context() within +** value of N in any subsequent call to sqlite3_aggregate_context() within ** the same aggregate function instance will not resize the memory ** allocation.)^ Within the xFinal callback, it is customary to set ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no @@ -5543,8 +5652,9 @@ typedef void (*sqlite3_destructor_type)(void*); ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16() ** as the text of an error message. ^SQLite interprets the error ** message string from sqlite3_result_error() as UTF-8. ^SQLite -** interprets the string from sqlite3_result_error16() as UTF-16 in native -** byte order. ^If the third parameter to sqlite3_result_error() +** interprets the string from sqlite3_result_error16() as UTF-16 using +** the same [byte-order determination rules] as [sqlite3_bind_text16()]. +** ^If the third parameter to sqlite3_result_error() ** or sqlite3_result_error16() is negative then SQLite takes as the error ** message all text up through the first zero character. ** ^If the third parameter to sqlite3_result_error() or @@ -5612,6 +5722,25 @@ typedef void (*sqlite3_destructor_type)(void*); ** then SQLite makes a copy of the result into space obtained ** from [sqlite3_malloc()] before it returns. ** +** ^For the sqlite3_result_text16(), sqlite3_result_text16le(), and +** sqlite3_result_text16be() routines, and for sqlite3_result_text64() +** when the encoding is not UTF8, if the input UTF16 begins with a +** byte-order mark (BOM, U+FEFF) then the BOM is removed from the +** string and the rest of the string is interpreted according to the +** byte-order specified by the BOM. ^The byte-order specified by +** the BOM at the beginning of the text overrides the byte-order +** specified by the interface procedure. ^So, for example, if +** sqlite3_result_text16le() is invoked with text that begins +** with bytes 0xfe, 0xff (a big-endian byte-order mark) then the +** first two bytes of input are skipped and the remaining input +** is interpreted as UTF16BE text. +** +** ^For UTF16 input text to the sqlite3_result_text16(), +** sqlite3_result_text16be(), sqlite3_result_text16le(), and +** sqlite3_result_text64() routines, if the text contains invalid +** UTF16 characters, the invalid characters might be converted +** into the unicode replacement character, U+FFFD. +** ** ^The sqlite3_result_value() interface sets the result of ** the application-defined function to be a copy of the ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The @@ -7559,7 +7688,7 @@ int sqlite3_test_control(int op, ...); #define SQLITE_TESTCTRL_PENDING_BYTE 11 #define SQLITE_TESTCTRL_ASSERT 12 #define SQLITE_TESTCTRL_ALWAYS 13 -#define SQLITE_TESTCTRL_RESERVE 14 +#define SQLITE_TESTCTRL_RESERVE 14 /* NOT USED */ #define SQLITE_TESTCTRL_OPTIMIZATIONS 15 #define SQLITE_TESTCTRL_ISKEYWORD 16 /* NOT USED */ #define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */ diff --git a/src/sqlite3ext.h b/src/sqlite3ext.h index bdd0a85..78c19a0 100644 --- a/src/sqlite3ext.h +++ b/src/sqlite3ext.h @@ -330,6 +330,11 @@ struct sqlite3_api_routines { const char *(*filename_database)(const char*); const char *(*filename_journal)(const char*); const char *(*filename_wal)(const char*); + /* Version 3.32.0 and later */ + char *(*create_filename)(const char*,const char*,const char*, + int,const char**); + void (*free_filename)(char*); + sqlite3_file *(*database_file_object)(const char*); }; /* @@ -630,6 +635,10 @@ typedef int (*sqlite3_loadext_entry)( #define sqlite3_filename_database sqlite3_api->filename_database #define sqlite3_filename_journal sqlite3_api->filename_journal #define sqlite3_filename_wal sqlite3_api->filename_wal +/* Version 3.32.0 and later */ +#define sqlite3_create_filename sqlite3_api->create_filename +#define sqlite3_free_filename sqlite3_api->free_filename +#define sqlite3_database_file_object sqlite3_api->database_file_object #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 76b37cb..2b1c483 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -186,6 +186,21 @@ #pragma warn -spa /* Suspicious pointer arithmetic */ #endif +/* +** WAL mode depends on atomic aligned 32-bit loads and stores in a few +** places. The following macros try to make this explicit. +*/ +#ifndef __has_feature +# define __has_feature(x) 0 /* compatibility with non-clang compilers */ +#endif +#if GCC_VERSION>=4007000 || __has_feature(c_atomic) +# define AtomicLoad(PTR) __atomic_load_n((PTR),__ATOMIC_RELAXED) +# define AtomicStore(PTR,VAL) __atomic_store_n((PTR),(VAL),__ATOMIC_RELAXED) +#else +# define AtomicLoad(PTR) (*(PTR)) +# define AtomicStore(PTR,VAL) (*(PTR) = (VAL)) +#endif + /* ** Include standard header files as necessary */ @@ -979,7 +994,6 @@ struct BusyHandler { int (*xBusyHandler)(void *,int); /* The busy callback */ void *pBusyArg; /* First arg to busy callback */ int nBusy; /* Incremented with each busy call */ - u8 bExtraFileArg; /* Include sqlite3_file as callback arg */ }; /* @@ -1264,7 +1278,6 @@ struct Schema { */ #define DB_SchemaLoaded 0x0001 /* The schema has been loaded */ #define DB_UnresetViews 0x0002 /* Some views have defined column names */ -#define DB_Empty 0x0004 /* The file is empty (length 0 bytes) */ #define DB_ResetWanted 0x0008 /* Reset the schema when nSchemaLock==0 */ /* @@ -1422,7 +1435,7 @@ void sqlite3CryptFunc(sqlite3_context*,int,sqlite3_value**); struct sqlite3 { sqlite3_vfs *pVfs; /* OS Interface */ struct Vdbe *pVdbe; /* List of active virtual machines */ - CollSeq *pDfltColl; /* The default collating sequence (BINARY) */ + CollSeq *pDfltColl; /* BINARY collseq for the database encoding */ sqlite3_mutex *mutex; /* Connection mutex */ Db *aDb; /* All backends */ int nDb; /* Number of backends currently in use */ @@ -1525,6 +1538,7 @@ struct sqlite3 { BusyHandler busyHandler; /* Busy callback */ Db aDbStatic[2]; /* Static space for the 2 default backends */ Savepoint *pSavepoint; /* List of active savepoints */ + int nAnalysisLimit; /* Number of index rows to ANALYZE */ int busyTimeout; /* Busy handler timeout, in msec */ int nSavepoint; /* Number of non-transaction savepoints */ int nStatement; /* Number of nested statement-transactions */ @@ -1631,6 +1645,7 @@ struct sqlite3 { #define DBFLAG_VacuumInto 0x0008 /* Currently running VACUUM INTO */ #define DBFLAG_SchemaKnownOk 0x0010 /* Schema is known to be valid */ #define DBFLAG_InternalFunc 0x0020 /* Allow use of internal functions */ +#define DBFLAG_EncodingFixed 0x0040 /* No longer possible to change enc. */ /* ** Bits of the sqlite3.dbOptFlags field that are used by the @@ -1749,7 +1764,7 @@ struct FuncDestructor { #define SQLITE_FUNC_LENGTH 0x0040 /* Built-in length() function */ #define SQLITE_FUNC_TYPEOF 0x0080 /* Built-in typeof() function */ #define SQLITE_FUNC_COUNT 0x0100 /* Built-in count(*) aggregate */ -#define SQLITE_FUNC_COALESCE 0x0200 /* Built-in coalesce() or ifnull() */ +/* 0x0200 -- available for reuse */ #define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */ #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */ #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */ @@ -1770,6 +1785,7 @@ struct FuncDestructor { #define INLINEFUNC_expr_implies_expr 2 #define INLINEFUNC_expr_compare 3 #define INLINEFUNC_affinity 4 +#define INLINEFUNC_iif 5 #define INLINEFUNC_unlikely 99 /* Default case */ /* @@ -1934,6 +1950,7 @@ struct Column { u8 notNull; /* An OE_ code for handling a NOT NULL constraint */ char affinity; /* One of the SQLITE_AFF_... values */ u8 szEst; /* Estimated size of value in this column. sizeof(INT)==1 */ + u8 hName; /* Column name hash for faster lookup */ u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */ }; @@ -2153,8 +2170,11 @@ struct Table { */ #ifndef SQLITE_OMIT_VIRTUALTABLE # define IsVirtual(X) ((X)->nModuleArg) +# define ExprIsVtab(X) \ + ((X)->op==TK_COLUMN && (X)->y.pTab!=0 && (X)->y.pTab->nModuleArg) #else # define IsVirtual(X) 0 +# define ExprIsVtab(X) 0 #endif /* @@ -2512,10 +2532,10 @@ struct AggInfo { ** it uses less memory in the Expr object, which is a big memory user ** in systems with lots of prepared statements. And few applications ** need more than about 10 or 20 variables. But some extreme users want -** to have prepared statements with over 32767 variables, and for them +** to have prepared statements with over 32766 variables, and for them ** the option is available (at compile-time). */ -#if SQLITE_MAX_VARIABLE_NUMBER<=32767 +#if SQLITE_MAX_VARIABLE_NUMBER<32767 typedef i16 ynVar; #else typedef int ynVar; @@ -2591,6 +2611,9 @@ struct Expr { ** TK_COLUMN: the value of p5 for OP_Column ** TK_AGG_FUNCTION: nesting depth ** TK_FUNCTION: NC_SelfRef flag if needs OP_PureFunc */ +#ifdef SQLITE_DEBUG + u8 vvaFlags; /* Verification flags. */ +#endif u32 flags; /* Various flags. EP_* See below */ union { char *zToken; /* Token value. Zero terminated and dequoted */ @@ -2665,7 +2688,7 @@ struct Expr { #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */ #define EP_Win 0x008000 /* Contains window functions */ #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */ -#define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */ + /* 0x020000 // available for reuse */ #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */ #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */ #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */ @@ -2679,6 +2702,7 @@ struct Expr { #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */ #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */ #define EP_FromDDL 0x40000000 /* Originates from sqlite_master */ + /* 0x80000000 // Available */ /* ** The EP_Propagate mask is a set of properties that automatically propagate @@ -2697,14 +2721,24 @@ struct Expr { #define ExprAlwaysTrue(E) (((E)->flags&(EP_FromJoin|EP_IsTrue))==EP_IsTrue) #define ExprAlwaysFalse(E) (((E)->flags&(EP_FromJoin|EP_IsFalse))==EP_IsFalse) + +/* Flags for use with Expr.vvaFlags +*/ +#define EP_NoReduce 0x01 /* Cannot EXPRDUP_REDUCE this Expr */ +#define EP_Immutable 0x02 /* Do not change this Expr node */ + /* The ExprSetVVAProperty() macro is used for Verification, Validation, ** and Accreditation only. It works like ExprSetProperty() during VVA ** processes but is a no-op for delivery. */ #ifdef SQLITE_DEBUG -# define ExprSetVVAProperty(E,P) (E)->flags|=(P) +# define ExprSetVVAProperty(E,P) (E)->vvaFlags|=(P) +# define ExprHasVVAProperty(E,P) (((E)->vvaFlags&(P))!=0) +# define ExprClearVVAProperties(E) (E)->vvaFlags = 0 #else # define ExprSetVVAProperty(E,P) +# define ExprHasVVAProperty(E,P) 0 +# define ExprClearVVAProperties(E) #endif /* @@ -3678,6 +3712,7 @@ struct Walker { struct WhereConst *pConst; /* WHERE clause constants */ struct RenameCtx *pRename; /* RENAME COLUMN context */ struct Table *pTab; /* Table of generated column */ + struct SrcList_item *pSrcItem; /* A single FROM clause item */ } u; }; @@ -4222,7 +4257,7 @@ void sqlite3ExprCodeGeneratedColumn(Parse*, Column*, int); #endif void sqlite3ExprCodeCopy(Parse*, Expr*, int); void sqlite3ExprCodeFactorable(Parse*, Expr*, int); -int sqlite3ExprCodeAtInit(Parse*, Expr*, int); +int sqlite3ExprCodeRunJustOnce(Parse*, Expr*, int); int sqlite3ExprCodeTemp(Parse*, Expr*, int*); int sqlite3ExprCodeTarget(Parse*, Expr*, int); int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8); @@ -4377,6 +4412,7 @@ void sqlite3DeferForeignKey(Parse*, int); # define sqlite3AuthContextPush(a,b,c) # define sqlite3AuthContextPop(a) ((void)(a)) #endif +int sqlite3DbIsNamed(sqlite3 *db, int iDb, const char *zName); void sqlite3Attach(Parse*, Expr*, Expr*, Expr*); void sqlite3Detach(Parse*, Expr*); void sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*); @@ -4436,10 +4472,10 @@ int sqlite3VarintLen(u64 v); const char *sqlite3IndexAffinityStr(sqlite3*, Index*); void sqlite3TableAffinity(Vdbe*, Table*, int); -char sqlite3CompareAffinity(Expr *pExpr, char aff2); -int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity); +char sqlite3CompareAffinity(const Expr *pExpr, char aff2); +int sqlite3IndexAffinityOk(const Expr *pExpr, char idx_affinity); char sqlite3TableColumnAffinity(Table*,int); -char sqlite3ExprAffinity(Expr *pExpr); +char sqlite3ExprAffinity(const Expr *pExpr); int sqlite3Atoi64(const char*, i64*, int, u8); int sqlite3DecOrHexToI64(const char*, i64*); void sqlite3ErrorWithMsg(sqlite3*, int, const char*,...); @@ -4462,9 +4498,10 @@ int sqlite3ReadSchema(Parse *pParse); CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); int sqlite3IsBinary(const CollSeq*); CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName); -CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr); -CollSeq *sqlite3ExprNNCollSeq(Parse *pParse, Expr *pExpr); -int sqlite3ExprCollSeqMatch(Parse*,Expr*,Expr*); +void sqlite3SetTextEncoding(sqlite3 *db, u8); +CollSeq *sqlite3ExprCollSeq(Parse *pParse, const Expr *pExpr); +CollSeq *sqlite3ExprNNCollSeq(Parse *pParse, const Expr *pExpr); +int sqlite3ExprCollSeqMatch(Parse*,const Expr*,const Expr*); Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, const Token*, int); Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*); Expr *sqlite3ExprSkipCollate(Expr*); @@ -4531,6 +4568,8 @@ int sqlite3MatchEName( const char*, const char* ); +Bitmask sqlite3ExprColUsed(Expr*); +u8 sqlite3StrIHash(const char*); int sqlite3ResolveExprNames(NameContext*, Expr*); int sqlite3ResolveExprListNames(NameContext*, ExprList*); void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*); @@ -4546,7 +4585,7 @@ void sqlite3RenameExprlistUnmap(Parse*, ExprList*); CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*); char sqlite3AffinityType(const char*, Column*); void sqlite3Analyze(Parse*, Token*, Token*); -int sqlite3InvokeBusyHandler(BusyHandler*, sqlite3_file*); +int sqlite3InvokeBusyHandler(BusyHandler*); int sqlite3FindDb(sqlite3*, Token*); int sqlite3FindDbName(sqlite3 *, const char *); int sqlite3AnalysisLoad(sqlite3*,int iDB); @@ -4671,8 +4710,10 @@ void sqlite3AutoLoadExtensions(sqlite3*); int sqlite3ReadOnlyShadowTables(sqlite3 *db); #ifndef SQLITE_OMIT_VIRTUALTABLE int sqlite3ShadowTableName(sqlite3 *db, const char *zName); + int sqlite3IsShadowTableOf(sqlite3*,Table*,const char*); #else # define sqlite3ShadowTableName(A,B) 0 +# define sqlite3IsShadowTableOf(A,B,C) 0 #endif int sqlite3VtabEponymousTableInit(Parse*,Module*); void sqlite3VtabEponymousTableClear(sqlite3*,Module*); @@ -4695,8 +4736,8 @@ char *sqlite3Normalize(Vdbe*, const char*); #endif int sqlite3Reprepare(Vdbe*); void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*); -CollSeq *sqlite3ExprCompareCollSeq(Parse*,Expr*); -CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *); +CollSeq *sqlite3ExprCompareCollSeq(Parse*,const Expr*); +CollSeq *sqlite3BinaryCompareCollSeq(Parse *, const Expr*, const Expr*); int sqlite3TempInMemory(const sqlite3*); const char *sqlite3JournalModename(int); #ifndef SQLITE_OMIT_WAL diff --git a/src/sqliteLimit.h b/src/sqliteLimit.h index 28e7a41..a730257 100644 --- a/src/sqliteLimit.h +++ b/src/sqliteLimit.h @@ -131,9 +131,12 @@ /* ** The maximum value of a ?nnn wildcard that the parser will accept. +** If the value exceeds 32767 then extra space is required for the Expr +** structure. But otherwise, we believe that the number can be as large +** as a signed 32-bit integer can hold. */ #ifndef SQLITE_MAX_VARIABLE_NUMBER -# define SQLITE_MAX_VARIABLE_NUMBER 999 +# define SQLITE_MAX_VARIABLE_NUMBER 32766 #endif /* Maximum page size. The upper bound on this value is 65536. This a limit diff --git a/src/table.c b/src/table.c index c79255f..db60a82 100644 --- a/src/table.c +++ b/src/table.c @@ -56,7 +56,7 @@ static int sqlite3_get_table_cb(void *pArg, int nCol, char **argv, char **colv){ if( p->nData + need > p->nAlloc ){ char **azNew; p->nAlloc = p->nAlloc*2 + need; - azNew = sqlite3_realloc64( p->azResult, sizeof(char*)*p->nAlloc ); + azNew = sqlite3Realloc( p->azResult, sizeof(char*)*p->nAlloc ); if( azNew==0 ) goto malloc_failed; p->azResult = azNew; } @@ -165,7 +165,7 @@ int sqlite3_get_table( } if( res.nAlloc>res.nData ){ char **azNew; - azNew = sqlite3_realloc64( res.azResult, sizeof(char*)*res.nData ); + azNew = sqlite3Realloc( res.azResult, sizeof(char*)*res.nData ); if( azNew==0 ){ sqlite3_free_table(&res.azResult[1]); db->errCode = SQLITE_NOMEM; diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 69da2cc..d80c252 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -3699,6 +3699,7 @@ static int SQLITE_TCLAPI DbMain( const char *zFile = 0; const char *zVfs = 0; int flags; + int bTranslateFileName = 1; Tcl_DString translatedFilename; int rc; @@ -3796,6 +3797,10 @@ static int SQLITE_TCLAPI DbMain( }else{ flags &= ~SQLITE_OPEN_URI; } + }else if( strcmp(zArg, "-translatefilename")==0 ){ + if( Tcl_GetBooleanFromObj(interp, objv[i], &bTranslateFileName) ){ + return TCL_ERROR; + } }else{ Tcl_AppendResult(interp, "unknown option: ", zArg, (char*)0); return TCL_ERROR; @@ -3805,9 +3810,13 @@ static int SQLITE_TCLAPI DbMain( p = (SqliteDb*)Tcl_Alloc( sizeof(*p) ); memset(p, 0, sizeof(*p)); if( zFile==0 ) zFile = ""; - zFile = Tcl_TranslateFileName(interp, zFile, &translatedFilename); + if( bTranslateFileName ){ + zFile = Tcl_TranslateFileName(interp, zFile, &translatedFilename); + } rc = sqlite3_open_v2(zFile, &p->db, flags, zVfs); - Tcl_DStringFree(&translatedFilename); + if( bTranslateFileName ){ + Tcl_DStringFree(&translatedFilename); + } if( p->db ){ if( SQLITE_OK!=sqlite3_errcode(p->db) ){ zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(p->db)); diff --git a/src/test_multiplex.c b/src/test_multiplex.c index 56e78c3..3c9aa03 100644 --- a/src/test_multiplex.c +++ b/src/test_multiplex.c @@ -267,11 +267,14 @@ static int multiplexSubFilename(multiplexGroup *pGroup, int iChunk){ if( pGroup->zName && pGroup->aReal[iChunk].z==0 ){ char *z; int n = pGroup->nName; - pGroup->aReal[iChunk].z = z = sqlite3_malloc64( n+5 ); + z = sqlite3_malloc64( n+5 ); if( z==0 ){ return SQLITE_NOMEM; } multiplexFilename(pGroup->zName, pGroup->nName, pGroup->flags, iChunk, z); + pGroup->aReal[iChunk].z = sqlite3_create_filename(z,"","",0,0); + sqlite3_free(z); + if( pGroup->aReal[iChunk].z==0 ) return SQLITE_NOMEM; } return SQLITE_OK; } @@ -438,7 +441,7 @@ static void multiplexSubClose( } sqlite3_free(pGroup->aReal[iChunk].p); } - sqlite3_free(pGroup->aReal[iChunk].z); + sqlite3_free_filename(pGroup->aReal[iChunk].z); memset(&pGroup->aReal[iChunk], 0, sizeof(pGroup->aReal[iChunk])); } diff --git a/src/tokenize.c b/src/tokenize.c index 48f9221..8467c0f 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -568,7 +568,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){ assert( zSql!=0 ); mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH]; if( db->nVdbeActive==0 ){ - db->u1.isInterrupted = 0; + AtomicStore(&db->u1.isInterrupted, 0); } pParse->rc = SQLITE_OK; pParse->zTail = zSql; @@ -613,7 +613,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){ if( tokenType>=TK_SPACE ){ assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL ); #endif /* SQLITE_OMIT_WINDOWFUNC */ - if( db->u1.isInterrupted ){ + if( AtomicLoad(&db->u1.isInterrupted) ){ pParse->rc = SQLITE_INTERRUPT; break; } diff --git a/src/treeview.c b/src/treeview.c index 90a1d2d..45c0d74 100644 --- a/src/treeview.c +++ b/src/treeview.c @@ -138,8 +138,8 @@ void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc){ sqlite3_str_appendf(&x, " %s", pItem->zName); } if( pItem->pTab ){ - sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p", - pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab); + sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx", + pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed); } if( pItem->zAlias ){ sqlite3_str_appendf(&x, " (AS %s)", pItem->zAlias); @@ -398,14 +398,14 @@ void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){ void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){ const char *zBinOp = 0; /* Binary operator */ const char *zUniOp = 0; /* Unary operator */ - char zFlgs[60]; + char zFlgs[200]; pView = sqlite3TreeViewPush(pView, moreToFollow); if( pExpr==0 ){ sqlite3TreeViewLine(pView, "nil"); sqlite3TreeViewPop(pView); return; } - if( pExpr->flags || pExpr->affExpr ){ + if( pExpr->flags || pExpr->affExpr || pExpr->vvaFlags ){ StrAccum x; sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0); sqlite3_str_appendf(&x, " fg.af=%x.%c", @@ -416,6 +416,9 @@ void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){ if( ExprHasProperty(pExpr, EP_FromDDL) ){ sqlite3_str_appendf(&x, " DDL"); } + if( ExprHasVVAProperty(pExpr, EP_Immutable) ){ + sqlite3_str_appendf(&x, " IMMUTABLE"); + } sqlite3StrAccumFinish(&x); }else{ zFlgs[0] = 0; @@ -522,6 +525,7 @@ void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){ case TK_RSHIFT: zBinOp = "RSHIFT"; break; case TK_CONCAT: zBinOp = "CONCAT"; break; case TK_DOT: zBinOp = "DOT"; break; + case TK_LIMIT: zBinOp = "LIMIT"; break; case TK_UMINUS: zUniOp = "UMINUS"; break; case TK_UPLUS: zUniOp = "UPLUS"; break; diff --git a/src/trigger.c b/src/trigger.c index 458aa29..646d694 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -580,7 +580,7 @@ void sqlite3DropTrigger(Parse *pParse, SrcList *pName, int noErr){ assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) ); for(i=OMIT_TEMPDB; inDb; i++){ int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ - if( zDb && sqlite3StrICmp(db->aDb[j].zDbSName, zDb) ) continue; + if( zDb && sqlite3DbIsNamed(db, j, zDb)==0 ) continue; assert( sqlite3SchemaMutexHeld(db, j, 0) ); pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName); if( pTrigger ) break; diff --git a/src/update.c b/src/update.c index 61b1740..470370f 100644 --- a/src/update.c +++ b/src/update.c @@ -53,10 +53,10 @@ static void updateVirtualTable( ** function is capable of transforming these types of expressions into ** sqlite3_value objects. ** -** If parameter iReg is not negative, code an OP_RealAffinity instruction -** on register iReg. This is used when an equivalent integer value is -** stored in place of an 8-byte floating point value in order to save -** space. +** If column as REAL affinity and the table is an ordinary b-tree table +** (not a virtual table) then the value might have been stored as an +** integer. In that case, add an OP_RealAffinity opcode to make sure +** it has been converted into REAL. */ void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i, int iReg){ assert( pTab!=0 ); @@ -73,7 +73,7 @@ void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i, int iReg){ } } #ifndef SQLITE_OMIT_FLOATING_POINT - if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){ + if( pTab->aCol[i].affinity==SQLITE_AFF_REAL && !IsVirtual(pTab) ){ sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg); } #endif @@ -616,7 +616,9 @@ void sqlite3Update( } sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, 0, iBaseCur, aToOpen, 0, 0); - if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce); + if( addrOnce ){ + sqlite3VdbeJumpHereOrPopInst(v, addrOnce); + } } /* Top of the update loop */ diff --git a/src/utf.c b/src/utf.c index f5fb3ef..3a2becf 100644 --- a/src/utf.c +++ b/src/utf.c @@ -105,26 +105,6 @@ static const unsigned char sqlite3Utf8Trans1[] = { } \ } -#define READ_UTF16LE(zIn, TERM, c){ \ - c = (*zIn++); \ - c += ((*zIn++)<<8); \ - if( c>=0xD800 && c<0xE000 && TERM ){ \ - int c2 = (*zIn++); \ - c2 += ((*zIn++)<<8); \ - c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); \ - } \ -} - -#define READ_UTF16BE(zIn, TERM, c){ \ - c = ((*zIn++)<<8); \ - c += (*zIn++); \ - if( c>=0xD800 && c<0xE000 && TERM ){ \ - int c2 = ((*zIn++)<<8); \ - c2 += (*zIn++); \ - c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); \ - } \ -} - /* ** Translate a single UTF-8 character. Return the unicode value. ** @@ -301,13 +281,59 @@ SQLITE_NOINLINE int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){ if( pMem->enc==SQLITE_UTF16LE ){ /* UTF-16 Little-endian -> UTF-8 */ while( zIn=0xd800 && c<0xe000 ){ +#ifdef SQLITE_REPLACE_INVALID_UTF + if( c>=0xdc00 || zIn>=zTerm ){ + c = 0xfffd; + }else{ + int c2 = *(zIn++); + c2 += (*(zIn++))<<8; + if( c2<0xdc00 || c2>=0xe000 ){ + zIn -= 2; + c = 0xfffd; + }else{ + c = ((c&0x3ff)<<10) + (c2&0x3ff) + 0x10000; + } + } +#else + if( zIn UTF-8 */ while( zIn=0xd800 && c<0xe000 ){ +#ifdef SQLITE_REPLACE_INVALID_UTF + if( c>=0xdc00 || zIn>=zTerm ){ + c = 0xfffd; + }else{ + int c2 = (*(zIn++))<<8; + c2 += *(zIn++); + if( c2<0xdc00 || c2>=0xe000 ){ + zIn -= 2; + c = 0xfffd; + }else{ + c = ((c&0x3ff)<<10) + (c2&0x3ff) + 0x10000; + } + } +#else + if( zIn=0xd8 && c<0xdc && z[0]>=0xdc && z[0]<0xe0 ) z += 2; + n++; } - return (int)(z-(unsigned char const *)zIn); + return (int)(z-(unsigned char const *)zIn) + - (SQLITE_UTF16NATIVE==SQLITE_UTF16LE); } #if defined(SQLITE_TEST) @@ -507,30 +530,6 @@ void sqlite3UtfSelfTest(void){ assert( c==t ); assert( (z-zBuf)==n ); } - for(i=0; i<0x00110000; i++){ - if( i>=0xD800 && i<0xE000 ) continue; - z = zBuf; - WRITE_UTF16LE(z, i); - n = (int)(z-zBuf); - assert( n>0 && n<=4 ); - z[0] = 0; - z = zBuf; - READ_UTF16LE(z, 1, c); - assert( c==i ); - assert( (z-zBuf)==n ); - } - for(i=0; i<0x00110000; i++){ - if( i>=0xD800 && i<0xE000 ) continue; - z = zBuf; - WRITE_UTF16BE(z, i); - n = (int)(z-zBuf); - assert( n>0 && n<=4 ); - z[0] = 0; - z = zBuf; - READ_UTF16BE(z, 1, c); - assert( c==i ); - assert( (z-zBuf)==n ); - } } #endif /* SQLITE_TEST */ #endif /* SQLITE_OMIT_UTF16 */ diff --git a/src/util.c b/src/util.c index 693759b..09520d1 100644 --- a/src/util.c +++ b/src/util.c @@ -317,6 +317,19 @@ int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){ return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b]; } +/* +** Compute an 8-bit hash on a string that is insensitive to case differences +*/ +u8 sqlite3StrIHash(const char *z){ + u8 h = 0; + if( z==0 ) return 0; + while( z[0] ){ + h += UpperToLower[(unsigned char)z[0]]; + z++; + } + return h; +} + /* ** Compute 10 to the E-th power. Examples: E==1 results in 10. ** E==2 results in 100. E==50 results in 1.0e50. diff --git a/src/vacuum.c b/src/vacuum.c index ce9db64..920a98e 100644 --- a/src/vacuum.c +++ b/src/vacuum.c @@ -233,7 +233,7 @@ SQLITE_NOINLINE int sqlite3RunVacuum( } db->mDbFlags |= DBFLAG_VacuumInto; } - nRes = sqlite3BtreeGetOptimalReserve(pMain); + nRes = sqlite3BtreeGetRequestedReserve(pMain); sqlite3BtreeSetCacheSize(pTemp, db->aDb[iDb].pSchema->cache_size); sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0)); @@ -377,7 +377,7 @@ end_of_vacuum: db->nChange = saved_nChange; db->nTotalChange = saved_nTotalChange; db->mTrace = saved_mTrace; - sqlite3BtreeSetPageSize(pMain, -1, -1, 1); + sqlite3BtreeSetPageSize(pMain, -1, 0, 1); /* Currently there is an SQL level transaction open on the vacuum ** database. No locks are held on any other files (since the main file diff --git a/src/vdbe.c b/src/vdbe.c index e3a920f..ce96439 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -707,7 +707,7 @@ int sqlite3VdbeExec( assert( p->explain==0 ); p->pResultSet = 0; db->busyHandler.nBusy = 0; - if( db->u1.isInterrupted ) goto abort_due_to_interrupt; + if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt; sqlite3VdbeIOTraceSql(p); #ifdef SQLITE_DEBUG sqlite3BeginBenignMalloc(); @@ -891,7 +891,7 @@ jump_to_p2_and_check_for_interrupt: ** checks on every opcode. This helps sqlite3_step() to run about 1.5% ** faster according to "valgrind --tool=cachegrind" */ check_for_interrupt: - if( db->u1.isInterrupted ) goto abort_due_to_interrupt; + if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt; #ifndef SQLITE_OMIT_PROGRESS_CALLBACK /* Call the progress callback if it is configured and the required number ** of VDBE ops have been executed (either since this invocation of @@ -1544,7 +1544,6 @@ case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */ pIn1 = &aMem[pOp->p1]; pIn2 = &aMem[pOp->p2]; pOut = &aMem[pOp->p3]; - testcase( pIn1==pIn2 ); testcase( pOut==pIn2 ); assert( pIn1!=pOut ); flags1 = pIn1->flags; @@ -3188,13 +3187,16 @@ case OP_MakeRecord: { break; } -/* Opcode: Count P1 P2 * * * +/* Opcode: Count P1 P2 p3 * * ** Synopsis: r[P2]=count() ** ** Store the number of entries (an integer value) in the table or index -** opened by cursor P1 in register P2 +** opened by cursor P1 in register P2. +** +** If P3==0, then an exact count is obtained, which involves visiting +** every btree page of the table. But if P3 is non-zero, an estimate +** is returned based on the current cursor position. */ -#ifndef SQLITE_OMIT_BTREECOUNT case OP_Count: { /* out2 */ i64 nEntry; BtCursor *pCrsr; @@ -3202,14 +3204,17 @@ case OP_Count: { /* out2 */ assert( p->apCsr[pOp->p1]->eCurType==CURTYPE_BTREE ); pCrsr = p->apCsr[pOp->p1]->uc.pCursor; assert( pCrsr ); - nEntry = 0; /* Not needed. Only used to silence a warning. */ - rc = sqlite3BtreeCount(db, pCrsr, &nEntry); - if( rc ) goto abort_due_to_error; + if( pOp->p3 ){ + nEntry = sqlite3BtreeRowCountEst(pCrsr); + }else{ + nEntry = 0; /* Not needed. Only used to silence a warning. */ + rc = sqlite3BtreeCount(db, pCrsr, &nEntry); + if( rc ) goto abort_due_to_error; + } pOut = out2Prerelease(p, pOp); pOut->u.i = nEntry; goto check_for_interrupt; } -#endif /* Opcode: Savepoint P1 * * P4 * ** @@ -3665,7 +3670,7 @@ case OP_SetCookie: { **
      **
    • 0x02 OPFLAG_SEEKEQ: This cursor will only be used for ** equality lookups (implemented as a pair of opcodes OP_SeekGE/OP_IdxGT -** of OP_SeekLE/OP_IdxGT) +** of OP_SeekLE/OP_IdxLT) **
    ** ** The P4 value may be either an integer (P4_INT32) or a pointer to @@ -3695,7 +3700,7 @@ case OP_SetCookie: { **
      **
    • 0x02 OPFLAG_SEEKEQ: This cursor will only be used for ** equality lookups (implemented as a pair of opcodes OP_SeekGE/OP_IdxGT -** of OP_SeekLE/OP_IdxGT) +** of OP_SeekLE/OP_IdxLT) **
    ** ** See also: OP_OpenRead, OP_OpenWrite @@ -3719,7 +3724,7 @@ case OP_SetCookie: { **