/ Check-in [51e3e83549]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Merge the latest trunk changes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | begin-concurrent-pnu
Files: files | file ages | folders
SHA3-256: 51e3e835490a12dca6359ca02b8cbf31091fc4376b265995a986d002d376fad9
User & Date: drh 2019-03-26 12:16:24
Context
2019-03-26
13:28
Bring this branch into closer alignment with begin-concurrent. check-in: 6433d36617 user: drh tags: begin-concurrent-pnu
12:16
Merge the latest trunk changes. check-in: 51e3e83549 user: drh tags: begin-concurrent-pnu
2019-03-25
22:05
Fix an obsolete comment in the CLI. No code changes. check-in: fade103cba user: drh tags: trunk
2019-03-08
15:30
Merge all the latest enhancements from trunk. check-in: 667cce3dce user: drh tags: begin-concurrent-pnu
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Added LICENSE.md.

            1  +The author disclaims copyright to this source code.  In place of
            2  +a legal notice, here is a blessing:
            3  +
            4  +  *   May you do good and not evil.
            5  +  *   May you find forgiveness for yourself and forgive others.
            6  +  *   May you share freely, never taking more than you give.

Changes to Makefile.in.

  1145   1145   
  1146   1146   fts3_write.lo:	$(TOP)/ext/fts3/fts3_write.c $(HDR) $(EXTHDR)
  1147   1147   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_write.c
  1148   1148   
  1149   1149   rtree.lo:	$(TOP)/ext/rtree/rtree.c $(HDR) $(EXTHDR)
  1150   1150   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/rtree/rtree.c
  1151   1151   
  1152         -sqlite3session.lo:	$(TOP)/ext/userauth/userauth.c $(HDR) $(EXTHDR)
         1152  +userauth.lo:	$(TOP)/ext/userauth/userauth.c $(HDR) $(EXTHDR)
  1153   1153   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/userauth/userauth.c
  1154   1154   
  1155         -userauth.lo:	$(TOP)/ext/session/sqlite3session.c $(HDR) $(EXTHDR)
         1155  +sqlite3session.lo:	$(TOP)/ext/session/sqlite3session.c $(HDR) $(EXTHDR)
  1156   1156   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/session/sqlite3session.c
  1157   1157   
  1158   1158   json1.lo:	$(TOP)/ext/misc/json1.c
  1159   1159   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/misc/json1.c
  1160   1160   
  1161   1161   stmt.lo:	$(TOP)/ext/misc/stmt.c
  1162   1162   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/misc/stmt.c

Changes to README.md.

     1      1   <h1 align="center">SQLite Source Repository</h1>
     2      2   
     3      3   This repository contains the complete source code for the 
     4      4   [SQLite database engine](https://sqlite.org/).  Some test scripts 
     5      5   are also included.  However, many other test scripts
     6      6   and most of the documentation are managed separately.
     7      7   
     8         -SQLite [does not use Git](https://sqlite.org/whynotgit.html).
     9         -If you are reading this on GitHub, then you are looking at an
    10         -unofficial mirror. See <https://sqlite.org/src> for the official
    11         -repository.
    12         -
    13         -## Obtaining The Code
            8  +## Version Control
    14      9   
    15     10   SQLite sources are managed using the
    16     11   [Fossil](https://www.fossil-scm.org/), a distributed version control system
    17         -that was specifically designed to support SQLite development.
           12  +that was specifically designed and written to support SQLite development.
           13  +The [Fossil repository](https://sqlite.org/src/timeline) contains the urtext.
           14  +
           15  +If you are reading this on GitHub or some other Git repository or service,
           16  +then you are looking at a mirror.  The names of check-ins and
           17  +other artifacts in a Git mirror are different from the official
           18  +names for those objects.  The offical names for check-ins are
           19  +found in a footer on the check-in comment for authorized mirrors.
           20  +The official check-in name can also be seen in the `manifest.uuid` file
           21  +in the root of the tree.  Always use the official name, not  the
           22  +Git-name, when communicating about an SQLite check-in.
           23  +
           24  +If you pulled your SQLite source code from a secondary source and want to
           25  +verify its integrity, there are hints on how to do that in the
           26  +[Verifying Code Authenticity](#vauth) section below.
           27  +
           28  +## Obtaining The Code
           29  +
    18     30   If you do not want to use Fossil, you can download tarballs or ZIP
    19     31   archives or [SQLite archives](https://sqlite.org/cli.html#sqlar) as follows:
    20     32   
    21     33     *  Lastest trunk check-in as
    22     34        [Tarball](https://www.sqlite.org/src/tarball/sqlite.tar.gz),
    23     35        [ZIP-archive](https://www.sqlite.org/src/zip/sqlite.zip), or
    24     36        [SQLite-archive](https://www.sqlite.org/src/sqlar/sqlite.sqlar).
................................................................................
   290    302   
   291    303     *  **ext/misc/json1.c** - This file implements the various JSON functions
   292    304        that are build into SQLite.
   293    305   
   294    306   There are many other source files.  Each has a succinct header comment that
   295    307   describes its purpose and role within the larger system.
   296    308   
          309  +<a name="vauth"></a>
          310  +## Verifying Code Authenticity
          311  +
          312  +If you obtained an SQLite source tree from a secondary source, such as a
          313  +GitHub mirror, and you want to verify that it has not been altered, there
          314  +are a couple of ways to do that.
          315  +
          316  +If you have an official release version of SQLite, and you are using the
          317  +`sqlite3.c` amalgamation, then SHA3-256 hashes for the amalgamation are
          318  +available in the [change log](https://www.sqlite.org/changes.html) on
          319  +the official website.  After building the `sqlite3.c` file, you can check
          320  +that is authentic by comparing the hash.  This does not ensure that the
          321  +test scripts are unaltered, but it does validate the deliverable part of
          322  +the code and only involves computing and comparing a single hash.
          323  +
          324  +For versions other than an official release, or if you are building the
          325  +`sqlite3.c` amalgamation using non-standard build options, the verification
          326  +process is a little more involved.  The `manifest` file at the root directory
          327  +of the source tree ([example](https://sqlite.org/src/artifact/bd49a8271d650fa8))
          328  +contains either a SHA3-256 hash (for newer files) or a SHA1 hash (for 
          329  +older files) for every source file in the repository.  You can write a script
          330  +to extracts hashes from `manifest` and verifies the hashes against the 
          331  +corresponding files in the source tree.  The SHA3-256 hash of the `manifest`
          332  +file itself is the official name of the version of the source tree that you
          333  +have.  The `manifest.uuid` file should contain the SHA3-256 hash of the
          334  +`manifest` file.  If all of the above hash comparisons are correct, then
          335  +you can be confident that your source tree is authentic and unadulterated.
   297    336   
   298    337   ## Contacts
   299    338   
   300    339   The main SQLite webpage is [http://www.sqlite.org/](http://www.sqlite.org/)
   301    340   with geographically distributed backups at
   302    341   [http://www2.sqlite.org/](http://www2.sqlite.org) and
   303    342   [http://www3.sqlite.org/](http://www3.sqlite.org).

Changes to configure.

   859    859   pdfdir
   860    860   dvidir
   861    861   htmldir
   862    862   infodir
   863    863   docdir
   864    864   oldincludedir
   865    865   includedir
          866  +runstatedir
   866    867   localstatedir
   867    868   sharedstatedir
   868    869   sysconfdir
   869    870   datadir
   870    871   datarootdir
   871    872   libexecdir
   872    873   sbindir
................................................................................
   960    961   sbindir='${exec_prefix}/sbin'
   961    962   libexecdir='${exec_prefix}/libexec'
   962    963   datarootdir='${prefix}/share'
   963    964   datadir='${datarootdir}'
   964    965   sysconfdir='${prefix}/etc'
   965    966   sharedstatedir='${prefix}/com'
   966    967   localstatedir='${prefix}/var'
          968  +runstatedir='${localstatedir}/run'
   967    969   includedir='${prefix}/include'
   968    970   oldincludedir='/usr/include'
   969    971   docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
   970    972   infodir='${datarootdir}/info'
   971    973   htmldir='${docdir}'
   972    974   dvidir='${docdir}'
   973    975   pdfdir='${docdir}'
................................................................................
  1211   1213       ac_prev=psdir ;;
  1212   1214     -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)
  1213   1215       psdir=$ac_optarg ;;
  1214   1216   
  1215   1217     -q | -quiet | --quiet | --quie | --qui | --qu | --q \
  1216   1218     | -silent | --silent | --silen | --sile | --sil)
  1217   1219       silent=yes ;;
         1220  +
         1221  +  -runstatedir | --runstatedir | --runstatedi | --runstated \
         1222  +  | --runstate | --runstat | --runsta | --runst | --runs \
         1223  +  | --run | --ru | --r)
         1224  +    ac_prev=runstatedir ;;
         1225  +  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
         1226  +  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
         1227  +  | --run=* | --ru=* | --r=*)
         1228  +    runstatedir=$ac_optarg ;;
  1218   1229   
  1219   1230     -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
  1220   1231       ac_prev=sbindir ;;
  1221   1232     -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
  1222   1233     | --sbi=* | --sb=*)
  1223   1234       sbindir=$ac_optarg ;;
  1224   1235   
................................................................................
  1349   1360     esac
  1350   1361   fi
  1351   1362   
  1352   1363   # Check all directory arguments for consistency.
  1353   1364   for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
  1354   1365   		datadir sysconfdir sharedstatedir localstatedir includedir \
  1355   1366   		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
  1356         -		libdir localedir mandir
         1367  +		libdir localedir mandir runstatedir
  1357   1368   do
  1358   1369     eval ac_val=\$$ac_var
  1359   1370     # Remove trailing slashes.
  1360   1371     case $ac_val in
  1361   1372       */ )
  1362   1373         ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'`
  1363   1374         eval $ac_var=\$ac_val;;
................................................................................
  1502   1513   Fine tuning of the installation directories:
  1503   1514     --bindir=DIR            user executables [EPREFIX/bin]
  1504   1515     --sbindir=DIR           system admin executables [EPREFIX/sbin]
  1505   1516     --libexecdir=DIR        program executables [EPREFIX/libexec]
  1506   1517     --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  1507   1518     --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  1508   1519     --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
         1520  +  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
  1509   1521     --libdir=DIR            object code libraries [EPREFIX/lib]
  1510   1522     --includedir=DIR        C header files [PREFIX/include]
  1511   1523     --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  1512   1524     --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  1513   1525     --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  1514   1526     --infodir=DIR           info documentation [DATAROOTDIR/info]
  1515   1527     --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
................................................................................
  3930   3942   { $as_echo "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5
  3931   3943   $as_echo_n "checking the name lister ($NM) interface... " >&6; }
  3932   3944   if ${lt_cv_nm_interface+:} false; then :
  3933   3945     $as_echo_n "(cached) " >&6
  3934   3946   else
  3935   3947     lt_cv_nm_interface="BSD nm"
  3936   3948     echo "int some_variable = 0;" > conftest.$ac_ext
  3937         -  (eval echo "\"\$as_me:3937: $ac_compile\"" >&5)
         3949  +  (eval echo "\"\$as_me:3949: $ac_compile\"" >&5)
  3938   3950     (eval "$ac_compile" 2>conftest.err)
  3939   3951     cat conftest.err >&5
  3940         -  (eval echo "\"\$as_me:3940: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
         3952  +  (eval echo "\"\$as_me:3952: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
  3941   3953     (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
  3942   3954     cat conftest.err >&5
  3943         -  (eval echo "\"\$as_me:3943: output\"" >&5)
         3955  +  (eval echo "\"\$as_me:3955: output\"" >&5)
  3944   3956     cat conftest.out >&5
  3945   3957     if $GREP 'External.*some_variable' conftest.out > /dev/null; then
  3946   3958       lt_cv_nm_interface="MS dumpbin"
  3947   3959     fi
  3948   3960     rm -f conftest*
  3949   3961   fi
  3950   3962   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5
................................................................................
  5142   5154   	;;
  5143   5155       esac
  5144   5156     fi
  5145   5157     rm -rf conftest*
  5146   5158     ;;
  5147   5159   *-*-irix6*)
  5148   5160     # Find out which ABI we are using.
  5149         -  echo '#line 5149 "configure"' > conftest.$ac_ext
         5161  +  echo '#line 5161 "configure"' > conftest.$ac_ext
  5150   5162     if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
  5151   5163     (eval $ac_compile) 2>&5
  5152   5164     ac_status=$?
  5153   5165     $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  5154   5166     test $ac_status = 0; }; then
  5155   5167       if test "$lt_cv_prog_gnu_ld" = yes; then
  5156   5168         case `/usr/bin/file conftest.$ac_objext` in
................................................................................
  6667   6679      # Note that $ac_compile itself does not contain backslashes and begins
  6668   6680      # with a dollar sign (not a hyphen), so the echo should work correctly.
  6669   6681      # The option is referenced via a variable to avoid confusing sed.
  6670   6682      lt_compile=`echo "$ac_compile" | $SED \
  6671   6683      -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
  6672   6684      -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
  6673   6685      -e 's:$: $lt_compiler_flag:'`
  6674         -   (eval echo "\"\$as_me:6674: $lt_compile\"" >&5)
         6686  +   (eval echo "\"\$as_me:6686: $lt_compile\"" >&5)
  6675   6687      (eval "$lt_compile" 2>conftest.err)
  6676   6688      ac_status=$?
  6677   6689      cat conftest.err >&5
  6678         -   echo "$as_me:6678: \$? = $ac_status" >&5
         6690  +   echo "$as_me:6690: \$? = $ac_status" >&5
  6679   6691      if (exit $ac_status) && test -s "$ac_outfile"; then
  6680   6692        # The compiler can only warn and ignore the option if not recognized
  6681   6693        # So say no if there are warnings other than the usual output.
  6682   6694        $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
  6683   6695        $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
  6684   6696        if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
  6685   6697          lt_cv_prog_compiler_rtti_exceptions=yes
................................................................................
  7006   7018      # Note that $ac_compile itself does not contain backslashes and begins
  7007   7019      # with a dollar sign (not a hyphen), so the echo should work correctly.
  7008   7020      # The option is referenced via a variable to avoid confusing sed.
  7009   7021      lt_compile=`echo "$ac_compile" | $SED \
  7010   7022      -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
  7011   7023      -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
  7012   7024      -e 's:$: $lt_compiler_flag:'`
  7013         -   (eval echo "\"\$as_me:7013: $lt_compile\"" >&5)
         7025  +   (eval echo "\"\$as_me:7025: $lt_compile\"" >&5)
  7014   7026      (eval "$lt_compile" 2>conftest.err)
  7015   7027      ac_status=$?
  7016   7028      cat conftest.err >&5
  7017         -   echo "$as_me:7017: \$? = $ac_status" >&5
         7029  +   echo "$as_me:7029: \$? = $ac_status" >&5
  7018   7030      if (exit $ac_status) && test -s "$ac_outfile"; then
  7019   7031        # The compiler can only warn and ignore the option if not recognized
  7020   7032        # So say no if there are warnings other than the usual output.
  7021   7033        $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
  7022   7034        $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
  7023   7035        if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
  7024   7036          lt_cv_prog_compiler_pic_works=yes
................................................................................
  7111   7123      # (2) before a word containing "conftest.", or (3) at the end.
  7112   7124      # Note that $ac_compile itself does not contain backslashes and begins
  7113   7125      # with a dollar sign (not a hyphen), so the echo should work correctly.
  7114   7126      lt_compile=`echo "$ac_compile" | $SED \
  7115   7127      -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
  7116   7128      -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
  7117   7129      -e 's:$: $lt_compiler_flag:'`
  7118         -   (eval echo "\"\$as_me:7118: $lt_compile\"" >&5)
         7130  +   (eval echo "\"\$as_me:7130: $lt_compile\"" >&5)
  7119   7131      (eval "$lt_compile" 2>out/conftest.err)
  7120   7132      ac_status=$?
  7121   7133      cat out/conftest.err >&5
  7122         -   echo "$as_me:7122: \$? = $ac_status" >&5
         7134  +   echo "$as_me:7134: \$? = $ac_status" >&5
  7123   7135      if (exit $ac_status) && test -s out/conftest2.$ac_objext
  7124   7136      then
  7125   7137        # The compiler can only warn and ignore the option if not recognized
  7126   7138        # So say no if there are warnings
  7127   7139        $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
  7128   7140        $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
  7129   7141        if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
................................................................................
  7166   7178      # (2) before a word containing "conftest.", or (3) at the end.
  7167   7179      # Note that $ac_compile itself does not contain backslashes and begins
  7168   7180      # with a dollar sign (not a hyphen), so the echo should work correctly.
  7169   7181      lt_compile=`echo "$ac_compile" | $SED \
  7170   7182      -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
  7171   7183      -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
  7172   7184      -e 's:$: $lt_compiler_flag:'`
  7173         -   (eval echo "\"\$as_me:7173: $lt_compile\"" >&5)
         7185  +   (eval echo "\"\$as_me:7185: $lt_compile\"" >&5)
  7174   7186      (eval "$lt_compile" 2>out/conftest.err)
  7175   7187      ac_status=$?
  7176   7188      cat out/conftest.err >&5
  7177         -   echo "$as_me:7177: \$? = $ac_status" >&5
         7189  +   echo "$as_me:7189: \$? = $ac_status" >&5
  7178   7190      if (exit $ac_status) && test -s out/conftest2.$ac_objext
  7179   7191      then
  7180   7192        # The compiler can only warn and ignore the option if not recognized
  7181   7193        # So say no if there are warnings
  7182   7194        $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
  7183   7195        $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
  7184   7196        if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
................................................................................
  9546   9558   else
  9547   9559     	  if test "$cross_compiling" = yes; then :
  9548   9560     lt_cv_dlopen_self=cross
  9549   9561   else
  9550   9562     lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
  9551   9563     lt_status=$lt_dlunknown
  9552   9564     cat > conftest.$ac_ext <<_LT_EOF
  9553         -#line 9553 "configure"
         9565  +#line 9565 "configure"
  9554   9566   #include "confdefs.h"
  9555   9567   
  9556   9568   #if HAVE_DLFCN_H
  9557   9569   #include <dlfcn.h>
  9558   9570   #endif
  9559   9571   
  9560   9572   #include <stdio.h>
................................................................................
  9642   9654   else
  9643   9655     	  if test "$cross_compiling" = yes; then :
  9644   9656     lt_cv_dlopen_self_static=cross
  9645   9657   else
  9646   9658     lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
  9647   9659     lt_status=$lt_dlunknown
  9648   9660     cat > conftest.$ac_ext <<_LT_EOF
  9649         -#line 9649 "configure"
         9661  +#line 9661 "configure"
  9650   9662   #include "confdefs.h"
  9651   9663   
  9652   9664   #if HAVE_DLFCN_H
  9653   9665   #include <dlfcn.h>
  9654   9666   #endif
  9655   9667   
  9656   9668   #include <stdio.h>
................................................................................
  9991  10003   	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  9992  10004   /* end confdefs.h.  */
  9993  10005   #include <sys/types.h>
  9994  10006    /* Check that off_t can represent 2**63 - 1 correctly.
  9995  10007       We can't simply define LARGE_OFF_T to be 9223372036854775807,
  9996  10008       since some C++ compilers masquerading as C compilers
  9997  10009       incorrectly reject 9223372036854775807.  */
  9998         -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
        10010  +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
  9999  10011     int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
 10000  10012   		       && LARGE_OFF_T % 2147483647 == 1)
 10001  10013   		      ? 1 : -1];
 10002  10014   int
 10003  10015   main ()
 10004  10016   {
 10005  10017   
................................................................................
 10037  10049     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 10038  10050   /* end confdefs.h.  */
 10039  10051   #include <sys/types.h>
 10040  10052    /* Check that off_t can represent 2**63 - 1 correctly.
 10041  10053       We can't simply define LARGE_OFF_T to be 9223372036854775807,
 10042  10054       since some C++ compilers masquerading as C compilers
 10043  10055       incorrectly reject 9223372036854775807.  */
 10044         -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
        10056  +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
 10045  10057     int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
 10046  10058   		       && LARGE_OFF_T % 2147483647 == 1)
 10047  10059   		      ? 1 : -1];
 10048  10060   int
 10049  10061   main ()
 10050  10062   {
 10051  10063   
................................................................................
 10061  10073   /* end confdefs.h.  */
 10062  10074   #define _FILE_OFFSET_BITS 64
 10063  10075   #include <sys/types.h>
 10064  10076    /* Check that off_t can represent 2**63 - 1 correctly.
 10065  10077       We can't simply define LARGE_OFF_T to be 9223372036854775807,
 10066  10078       since some C++ compilers masquerading as C compilers
 10067  10079       incorrectly reject 9223372036854775807.  */
 10068         -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
        10080  +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
 10069  10081     int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
 10070  10082   		       && LARGE_OFF_T % 2147483647 == 1)
 10071  10083   		      ? 1 : -1];
 10072  10084   int
 10073  10085   main ()
 10074  10086   {
 10075  10087   
................................................................................
 10106  10118     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 10107  10119   /* end confdefs.h.  */
 10108  10120   #include <sys/types.h>
 10109  10121    /* Check that off_t can represent 2**63 - 1 correctly.
 10110  10122       We can't simply define LARGE_OFF_T to be 9223372036854775807,
 10111  10123       since some C++ compilers masquerading as C compilers
 10112  10124       incorrectly reject 9223372036854775807.  */
 10113         -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
        10125  +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
 10114  10126     int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
 10115  10127   		       && LARGE_OFF_T % 2147483647 == 1)
 10116  10128   		      ? 1 : -1];
 10117  10129   int
 10118  10130   main ()
 10119  10131   {
 10120  10132   
................................................................................
 10130  10142   /* end confdefs.h.  */
 10131  10143   #define _LARGE_FILES 1
 10132  10144   #include <sys/types.h>
 10133  10145    /* Check that off_t can represent 2**63 - 1 correctly.
 10134  10146       We can't simply define LARGE_OFF_T to be 9223372036854775807,
 10135  10147       since some C++ compilers masquerading as C compilers
 10136  10148       incorrectly reject 9223372036854775807.  */
 10137         -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
        10149  +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
 10138  10150     int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
 10139  10151   		       && LARGE_OFF_T % 2147483647 == 1)
 10140  10152   		      ? 1 : -1];
 10141  10153   int
 10142  10154   main ()
 10143  10155   {
 10144  10156   

Changes to ext/fts3/fts3_term.c.

    94     94   
    95     95     rc = sqlite3_declare_vtab(db, FTS3_TERMS_SCHEMA);
    96     96     if( rc!=SQLITE_OK ) return rc;
    97     97   
    98     98     nByte = sizeof(Fts3termTable) + sizeof(Fts3Table) + nDb + nFts3 + 2;
    99     99     p = (Fts3termTable *)sqlite3_malloc64(nByte);
   100    100     if( !p ) return SQLITE_NOMEM;
   101         -  memset(p, 0, nByte);
          101  +  memset(p, 0, (size_t)nByte);
   102    102   
   103    103     p->pFts3Tab = (Fts3Table *)&p[1];
   104    104     p->pFts3Tab->zDb = (char *)&p->pFts3Tab[1];
   105    105     p->pFts3Tab->zName = &p->pFts3Tab->zDb[nDb+1];
   106    106     p->pFts3Tab->db = db;
   107    107     p->pFts3Tab->nIndex = iIndex+1;
   108    108     p->iIndex = iIndex;

Changes to ext/fts3/unicode/mkunicode.tcl.

   734    734       void sqlite3Fts5UnicodeAscii(u8 *aArray, u8 *aAscii){
   735    735         int i = 0;
   736    736         int iTbl = 0;
   737    737         while( i<128 ){
   738    738           int bToken = aArray[ aFts5UnicodeData[iTbl] & 0x1F ];
   739    739           int n = (aFts5UnicodeData[iTbl] >> 5) + i;
   740    740           for(; i<128 && i<n; i++){
   741         -          aAscii[i] = bToken;
          741  +          aAscii[i] = (u8)bToken;
   742    742           }
   743    743           iTbl++;
   744    744         }
   745    745       }
   746    746     }]
   747    747   }
   748    748   

Changes to ext/fts5/fts5Int.h.

   579    579   /*
   580    580   ** Empty (but do not delete) a hash table.
   581    581   */
   582    582   void sqlite3Fts5HashClear(Fts5Hash*);
   583    583   
   584    584   int sqlite3Fts5HashQuery(
   585    585     Fts5Hash*,                      /* Hash table to query */
          586  +  int nPre,
   586    587     const char *pTerm, int nTerm,   /* Query term */
   587         -  const u8 **ppDoclist,           /* OUT: Pointer to doclist for pTerm */
          588  +  void **ppObj,                   /* OUT: Pointer to doclist for pTerm */
   588    589     int *pnDoclist                  /* OUT: Size of doclist in bytes */
   589    590   );
   590    591   
   591    592   int sqlite3Fts5HashScanInit(
   592    593     Fts5Hash*,                      /* Hash table to query */
   593    594     const char *pTerm, int nTerm    /* Query prefix */
   594    595   );

Changes to ext/fts5/fts5_aux.c.

   349    349     }
   350    350   
   351    351     *pnScore = nScore;
   352    352     if( piPos ){
   353    353       sqlite3_int64 iAdj = iFirst - (nToken - (iLast-iFirst)) / 2;
   354    354       if( (iAdj+nToken)>nDocsize ) iAdj = nDocsize - nToken;
   355    355       if( iAdj<0 ) iAdj = 0;
   356         -    *piPos = iAdj;
          356  +    *piPos = (int)iAdj;
   357    357     }
   358    358   
   359    359     return rc;
   360    360   }
   361    361   
   362    362   /*
   363    363   ** Return the value in pVal interpreted as utf-8 text. Except, if pVal 
................................................................................
   577    577       /* Allocate the Fts5Bm25Data object */
   578    578       nPhrase = pApi->xPhraseCount(pFts);
   579    579       nByte = sizeof(Fts5Bm25Data) + nPhrase*2*sizeof(double);
   580    580       p = (Fts5Bm25Data*)sqlite3_malloc64(nByte);
   581    581       if( p==0 ){
   582    582         rc = SQLITE_NOMEM;
   583    583       }else{
   584         -      memset(p, 0, nByte);
          584  +      memset(p, 0, (size_t)nByte);
   585    585         p->nPhrase = nPhrase;
   586    586         p->aIDF = (double*)&p[1];
   587    587         p->aFreq = &p->aIDF[nPhrase];
   588    588       }
   589    589   
   590    590       /* Calculate the average document length for this FTS5 table */
   591    591       if( rc==SQLITE_OK ) rc = pApi->xRowCount(pFts, &nRow);

Changes to ext/fts5/fts5_buffer.c.

    23     23         nNew = nNew * 2;
    24     24       }
    25     25       pNew = sqlite3_realloc64(pBuf->p, nNew);
    26     26       if( pNew==0 ){
    27     27         *pRc = SQLITE_NOMEM;
    28     28         return 1;
    29     29       }else{
    30         -      pBuf->nSpace = nNew;
           30  +      pBuf->nSpace = (int)nNew;
    31     31         pBuf->p = pNew;
    32     32       }
    33     33     }
    34     34     return 0;
    35     35   }
    36     36   
    37     37   
................................................................................
   247    247   void *sqlite3Fts5MallocZero(int *pRc, sqlite3_int64 nByte){
   248    248     void *pRet = 0;
   249    249     if( *pRc==SQLITE_OK ){
   250    250       pRet = sqlite3_malloc64(nByte);
   251    251       if( pRet==0 ){
   252    252         if( nByte>0 ) *pRc = SQLITE_NOMEM;
   253    253       }else{
   254         -      memset(pRet, 0, nByte);
          254  +      memset(pRet, 0, (size_t)nByte);
   255    255       }
   256    256     }
   257    257     return pRet;
   258    258   }
   259    259   
   260    260   /*
   261    261   ** Return a nul-terminated copy of the string indicated by pIn. If nIn

Changes to ext/fts5/fts5_config.c.

   321    321             }
   322    322           }
   323    323           if( p==0 ){
   324    324             *pzErr = sqlite3_mprintf("parse error in tokenize directive");
   325    325             rc = SQLITE_ERROR;
   326    326           }else{
   327    327             rc = sqlite3Fts5GetTokenizer(pGlobal, 
   328         -              (const char**)azArg, nArg, &pConfig->pTok, &pConfig->pTokApi,
          328  +              (const char**)azArg, (int)nArg, &pConfig->pTok, &pConfig->pTokApi,
   329    329                 pzErr
   330    330             );
   331    331           }
   332    332         }
   333    333       }
   334    334   
   335    335       sqlite3_free(azArg);
................................................................................
   431    431     assert( *pRc==SQLITE_OK );
   432    432     *pbQuoted = 0;
   433    433     *pzOut = 0;
   434    434   
   435    435     if( zOut==0 ){
   436    436       *pRc = SQLITE_NOMEM;
   437    437     }else{
   438         -    memcpy(zOut, zIn, nIn+1);
          438  +    memcpy(zOut, zIn, (size_t)(nIn+1));
   439    439       if( fts5_isopenquote(zOut[0]) ){
   440    440         int ii = fts5Dequote(zOut);
   441    441         zRet = &zIn[ii];
   442    442         *pbQuoted = 1;
   443    443       }else{
   444    444         zRet = fts5ConfigSkipBareword(zIn);
   445    445         if( zRet ){

Changes to ext/fts5/fts5_expr.c.

  1483   1483       if( pNear==0 ){
  1484   1484         sqlite3_int64 nByte;
  1485   1485         nByte = sizeof(Fts5ExprNearset) + SZALLOC * sizeof(Fts5ExprPhrase*);
  1486   1486         pRet = sqlite3_malloc64(nByte);
  1487   1487         if( pRet==0 ){
  1488   1488           pParse->rc = SQLITE_NOMEM;
  1489   1489         }else{
  1490         -        memset(pRet, 0, nByte);
         1490  +        memset(pRet, 0, (size_t)nByte);
  1491   1491         }
  1492   1492       }else if( (pNear->nPhrase % SZALLOC)==0 ){
  1493   1493         int nNew = pNear->nPhrase + SZALLOC;
  1494   1494         sqlite3_int64 nByte;
  1495   1495   
  1496   1496         nByte = sizeof(Fts5ExprNearset) + nNew * sizeof(Fts5ExprPhrase*);
  1497   1497         pRet = (Fts5ExprNearset*)sqlite3_realloc64(pNear, nByte);
................................................................................
  1559   1559     if( pPhrase && pPhrase->nTerm>0 && (tflags & FTS5_TOKEN_COLOCATED) ){
  1560   1560       Fts5ExprTerm *pSyn;
  1561   1561       sqlite3_int64 nByte = sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer) + nToken+1;
  1562   1562       pSyn = (Fts5ExprTerm*)sqlite3_malloc64(nByte);
  1563   1563       if( pSyn==0 ){
  1564   1564         rc = SQLITE_NOMEM;
  1565   1565       }else{
  1566         -      memset(pSyn, 0, nByte);
         1566  +      memset(pSyn, 0, (size_t)nByte);
  1567   1567         pSyn->zTerm = ((char*)pSyn) + sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer);
  1568   1568         memcpy(pSyn->zTerm, pToken, nToken);
  1569   1569         pSyn->pSynonym = pPhrase->aTerm[pPhrase->nTerm-1].pSynonym;
  1570   1570         pPhrase->aTerm[pPhrase->nTerm-1].pSynonym = pSyn;
  1571   1571       }
  1572   1572     }else{
  1573   1573       Fts5ExprTerm *pTerm;
................................................................................
  1719   1719       Fts5Colset *pColsetOrig = pOrig->pNode->pNear->pColset;
  1720   1720       if( pColsetOrig ){
  1721   1721         sqlite3_int64 nByte;
  1722   1722         Fts5Colset *pColset;
  1723   1723         nByte = sizeof(Fts5Colset) + (pColsetOrig->nCol-1) * sizeof(int);
  1724   1724         pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
  1725   1725         if( pColset ){ 
  1726         -        memcpy(pColset, pColsetOrig, nByte);
         1726  +        memcpy(pColset, pColsetOrig, (size_t)nByte);
  1727   1727         }
  1728   1728         pNew->pRoot->pNear->pColset = pColset;
  1729   1729       }
  1730   1730     }
  1731   1731   
  1732   1732     if( pOrig->nTerm ){
  1733   1733       int i;                          /* Used to iterate through phrase terms */
................................................................................
  1936   1936   */
  1937   1937   static Fts5Colset *fts5CloneColset(int *pRc, Fts5Colset *pOrig){
  1938   1938     Fts5Colset *pRet;
  1939   1939     if( pOrig ){
  1940   1940       sqlite3_int64 nByte = sizeof(Fts5Colset) + (pOrig->nCol-1) * sizeof(int);
  1941   1941       pRet = (Fts5Colset*)sqlite3Fts5MallocZero(pRc, nByte);
  1942   1942       if( pRet ){ 
  1943         -      memcpy(pRet, pOrig, nByte);
         1943  +      memcpy(pRet, pOrig, (size_t)nByte);
  1944   1944       }
  1945   1945     }else{
  1946   1946       pRet = 0;
  1947   1947     }
  1948   1948     return pRet;
  1949   1949   }
  1950   1950   

Changes to ext/fts5/fts5_hash.c.

    99     99       nByte = sizeof(Fts5HashEntry*) * pNew->nSlot;
   100    100       pNew->aSlot = (Fts5HashEntry**)sqlite3_malloc64(nByte);
   101    101       if( pNew->aSlot==0 ){
   102    102         sqlite3_free(pNew);
   103    103         *ppNew = 0;
   104    104         rc = SQLITE_NOMEM;
   105    105       }else{
   106         -      memset(pNew->aSlot, 0, nByte);
          106  +      memset(pNew->aSlot, 0, (size_t)nByte);
   107    107       }
   108    108     }
   109    109     return rc;
   110    110   }
   111    111   
   112    112   /*
   113    113   ** Free a hash table object.
................................................................................
   183    183   
   184    184     sqlite3_free(apOld);
   185    185     pHash->nSlot = nNew;
   186    186     pHash->aSlot = apNew;
   187    187     return SQLITE_OK;
   188    188   }
   189    189   
   190         -static void fts5HashAddPoslistSize(Fts5Hash *pHash, Fts5HashEntry *p){
          190  +static int fts5HashAddPoslistSize(
          191  +  Fts5Hash *pHash, 
          192  +  Fts5HashEntry *p,
          193  +  Fts5HashEntry *p2
          194  +){
          195  +  int nRet = 0;
   191    196     if( p->iSzPoslist ){
   192         -    u8 *pPtr = (u8*)p;
          197  +    u8 *pPtr = p2 ? (u8*)p2 : (u8*)p;
          198  +    int nData = p->nData;
   193    199       if( pHash->eDetail==FTS5_DETAIL_NONE ){
   194         -      assert( p->nData==p->iSzPoslist );
          200  +      assert( nData==p->iSzPoslist );
   195    201         if( p->bDel ){
   196         -        pPtr[p->nData++] = 0x00;
          202  +        pPtr[nData++] = 0x00;
   197    203           if( p->bContent ){
   198         -          pPtr[p->nData++] = 0x00;
          204  +          pPtr[nData++] = 0x00;
   199    205           }
   200    206         }
   201    207       }else{
   202         -      int nSz = (p->nData - p->iSzPoslist - 1);       /* Size in bytes */
          208  +      int nSz = (nData - p->iSzPoslist - 1);       /* Size in bytes */
   203    209         int nPos = nSz*2 + p->bDel;                     /* Value of nPos field */
   204    210   
   205    211         assert( p->bDel==0 || p->bDel==1 );
   206    212         if( nPos<=127 ){
   207    213           pPtr[p->iSzPoslist] = (u8)nPos;
   208    214         }else{
   209    215           int nByte = sqlite3Fts5GetVarintLen((u32)nPos);
   210    216           memmove(&pPtr[p->iSzPoslist + nByte], &pPtr[p->iSzPoslist + 1], nSz);
   211    217           sqlite3Fts5PutVarint(&pPtr[p->iSzPoslist], nPos);
   212         -        p->nData += (nByte-1);
          218  +        nData += (nByte-1);
   213    219         }
   214    220       }
   215    221   
   216         -    p->iSzPoslist = 0;
   217         -    p->bDel = 0;
   218         -    p->bContent = 0;
          222  +    nRet = nData - p->nData;
          223  +    if( p2==0 ){
          224  +      p->iSzPoslist = 0;
          225  +      p->bDel = 0;
          226  +      p->bContent = 0;
          227  +      p->nData = nData;
          228  +    }
   219    229     }
          230  +  return nRet;
   220    231   }
   221    232   
   222    233   /*
   223    234   ** Add an entry to the in-memory hash table. The key is the concatenation
   224    235   ** of bByte and (pToken/nToken). The value is (iRowid/iCol/iPos).
   225    236   **
   226    237   **     (bByte || pToken) -> (iRowid,iCol,iPos)
................................................................................
   269    280         iHash = fts5HashKey2(pHash->nSlot, (u8)bByte, (const u8*)pToken, nToken);
   270    281       }
   271    282   
   272    283       /* Allocate new Fts5HashEntry and add it to the hash table. */
   273    284       p = (Fts5HashEntry*)sqlite3_malloc64(nByte);
   274    285       if( !p ) return SQLITE_NOMEM;
   275    286       memset(p, 0, sizeof(Fts5HashEntry));
   276         -    p->nAlloc = nByte;
          287  +    p->nAlloc = (int)nByte;
   277    288       zKey = fts5EntryKey(p);
   278    289       zKey[0] = bByte;
   279    290       memcpy(&zKey[1], pToken, nToken);
   280    291       assert( iHash==fts5HashKey(pHash->nSlot, (u8*)zKey, nToken+1) );
   281    292       p->nKey = nToken;
   282    293       zKey[nToken+1] = '\0';
   283    294       p->nData = nToken+1 + 1 + sizeof(Fts5HashEntry);
................................................................................
   324    335     assert( (p->nAlloc - p->nData) >= (9 + 4 + 1 + 3 + 5) );
   325    336   
   326    337     pPtr = (u8*)p;
   327    338   
   328    339     /* If this is a new rowid, append the 4-byte size field for the previous
   329    340     ** entry, and the new rowid for this entry.  */
   330    341     if( iRowid!=p->iRowid ){
   331         -    fts5HashAddPoslistSize(pHash, p);
          342  +    fts5HashAddPoslistSize(pHash, p, 0);
   332    343       p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iRowid - p->iRowid);
   333    344       p->iRowid = iRowid;
   334    345       bNew = 1;
   335    346       p->iSzPoslist = p->nData;
   336    347       if( pHash->eDetail!=FTS5_DETAIL_NONE ){
   337    348         p->nData += 1;
   338    349         p->iCol = (pHash->eDetail==FTS5_DETAIL_FULL ? 0 : -1);
................................................................................
   441    452     ap = sqlite3_malloc64(sizeof(Fts5HashEntry*) * nMergeSlot);
   442    453     if( !ap ) return SQLITE_NOMEM;
   443    454     memset(ap, 0, sizeof(Fts5HashEntry*) * nMergeSlot);
   444    455   
   445    456     for(iSlot=0; iSlot<pHash->nSlot; iSlot++){
   446    457       Fts5HashEntry *pIter;
   447    458       for(pIter=pHash->aSlot[iSlot]; pIter; pIter=pIter->pHashNext){
   448         -      if( pTerm==0 || 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm) ){
          459  +      if( pTerm==0 
          460  +       || (pIter->nKey+1>=nTerm && 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm))
          461  +      ){
   449    462           Fts5HashEntry *pEntry = pIter;
   450    463           pEntry->pScanNext = 0;
   451    464           for(i=0; ap[i]; i++){
   452    465             pEntry = fts5HashEntryMerge(pEntry, ap[i]);
   453    466             ap[i] = 0;
   454    467           }
   455    468           ap[i] = pEntry;
................................................................................
   469    482   }
   470    483   
   471    484   /*
   472    485   ** Query the hash table for a doclist associated with term pTerm/nTerm.
   473    486   */
   474    487   int sqlite3Fts5HashQuery(
   475    488     Fts5Hash *pHash,                /* Hash table to query */
          489  +  int nPre,
   476    490     const char *pTerm, int nTerm,   /* Query term */
   477         -  const u8 **ppDoclist,           /* OUT: Pointer to doclist for pTerm */
          491  +  void **ppOut,                   /* OUT: Pointer to new object */
   478    492     int *pnDoclist                  /* OUT: Size of doclist in bytes */
   479    493   ){
   480    494     unsigned int iHash = fts5HashKey(pHash->nSlot, (const u8*)pTerm, nTerm);
   481    495     char *zKey = 0;
   482    496     Fts5HashEntry *p;
   483    497   
   484    498     for(p=pHash->aSlot[iHash]; p; p=p->pHashNext){
   485    499       zKey = fts5EntryKey(p);
   486    500       assert( p->nKey+1==(int)strlen(zKey) );
   487    501       if( nTerm==p->nKey+1 && memcmp(zKey, pTerm, nTerm)==0 ) break;
   488    502     }
   489    503   
   490    504     if( p ){
   491         -    fts5HashAddPoslistSize(pHash, p);
   492         -    *ppDoclist = (const u8*)&zKey[nTerm+1];
   493         -    *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
          505  +    int nHashPre = sizeof(Fts5HashEntry) + nTerm + 1;
          506  +    int nList = p->nData - nHashPre;
          507  +    u8 *pRet = (u8*)(*ppOut = sqlite3_malloc64(nPre + nList + 10));
          508  +    if( pRet ){
          509  +      Fts5HashEntry *pFaux = (Fts5HashEntry*)&pRet[nPre-nHashPre];
          510  +      memcpy(&pRet[nPre], &((u8*)p)[nHashPre], nList);
          511  +      nList += fts5HashAddPoslistSize(pHash, p, pFaux);
          512  +      *pnDoclist = nList;
          513  +    }else{
          514  +      *pnDoclist = 0;
          515  +      return SQLITE_NOMEM;
          516  +    }
   494    517     }else{
   495         -    *ppDoclist = 0;
          518  +    *ppOut = 0;
   496    519       *pnDoclist = 0;
   497    520     }
   498    521   
   499    522     return SQLITE_OK;
   500    523   }
   501    524   
   502    525   int sqlite3Fts5HashScanInit(
................................................................................
   521    544     const u8 **ppDoclist,           /* OUT: pointer to doclist */
   522    545     int *pnDoclist                  /* OUT: size of doclist in bytes */
   523    546   ){
   524    547     Fts5HashEntry *p;
   525    548     if( (p = pHash->pScan) ){
   526    549       char *zKey = fts5EntryKey(p);
   527    550       int nTerm = (int)strlen(zKey);
   528         -    fts5HashAddPoslistSize(pHash, p);
          551  +    fts5HashAddPoslistSize(pHash, p, 0);
   529    552       *pzTerm = zKey;
   530    553       *ppDoclist = (const u8*)&zKey[nTerm+1];
   531    554       *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
   532    555     }else{
   533    556       *pzTerm = 0;
   534    557       *ppDoclist = 0;
   535    558       *pnDoclist = 0;
   536    559     }
   537    560   }

Changes to ext/fts5/fts5_index.c.

  2453   2453   */
  2454   2454   static void fts5SegIterHashInit(
  2455   2455     Fts5Index *p,                   /* FTS5 backend */
  2456   2456     const u8 *pTerm, int nTerm,     /* Term to seek to */
  2457   2457     int flags,                      /* Mask of FTS5INDEX_XXX flags */
  2458   2458     Fts5SegIter *pIter              /* Object to populate */
  2459   2459   ){
  2460         -  const u8 *pList = 0;
  2461   2460     int nList = 0;
  2462   2461     const u8 *z = 0;
  2463   2462     int n = 0;
         2463  +  Fts5Data *pLeaf = 0;
  2464   2464   
  2465   2465     assert( p->pHash );
  2466   2466     assert( p->rc==SQLITE_OK );
  2467   2467   
  2468   2468     if( pTerm==0 || (flags & FTS5INDEX_QUERY_SCAN) ){
         2469  +    const u8 *pList = 0;
         2470  +
  2469   2471       p->rc = sqlite3Fts5HashScanInit(p->pHash, (const char*)pTerm, nTerm);
  2470   2472       sqlite3Fts5HashScanEntry(p->pHash, (const char**)&z, &pList, &nList);
  2471   2473       n = (z ? (int)strlen((const char*)z) : 0);
         2474  +    if( pList ){
         2475  +      pLeaf = fts5IdxMalloc(p, sizeof(Fts5Data));
         2476  +      if( pLeaf ){
         2477  +        pLeaf->p = (u8*)pList;
         2478  +      }
         2479  +    }
  2472   2480     }else{
  2473         -    pIter->flags |= FTS5_SEGITER_ONETERM;
  2474         -    sqlite3Fts5HashQuery(p->pHash, (const char*)pTerm, nTerm, &pList, &nList);
         2481  +    p->rc = sqlite3Fts5HashQuery(p->pHash, sizeof(Fts5Data), 
         2482  +        (const char*)pTerm, nTerm, (void**)&pLeaf, &nList
         2483  +    );
         2484  +    if( pLeaf ){
         2485  +      pLeaf->p = (u8*)&pLeaf[1];
         2486  +    }
  2475   2487       z = pTerm;
  2476   2488       n = nTerm;
         2489  +    pIter->flags |= FTS5_SEGITER_ONETERM;
  2477   2490     }
  2478   2491   
  2479         -  if( pList ){
  2480         -    Fts5Data *pLeaf;
         2492  +  if( pLeaf ){
  2481   2493       sqlite3Fts5BufferSet(&p->rc, &pIter->term, n, z);
  2482         -    pLeaf = fts5IdxMalloc(p, sizeof(Fts5Data));
  2483         -    if( pLeaf==0 ) return;
  2484         -    pLeaf->p = (u8*)pList;
  2485   2494       pLeaf->nn = pLeaf->szLeaf = nList;
  2486   2495       pIter->pLeaf = pLeaf;
  2487   2496       pIter->iLeafOffset = fts5GetVarint(pLeaf->p, (u64*)&pIter->iRowid);
  2488   2497       pIter->iEndofDoclist = pLeaf->nn;
  2489   2498   
  2490   2499       if( flags & FTS5INDEX_QUERY_DESC ){
  2491   2500         pIter->flags |= FTS5_SEGITER_REVERSE;

Changes to ext/fts5/fts5_main.c.

   629    629   
   630    630     rc = fts5NewTransaction(pTab);
   631    631     if( rc==SQLITE_OK ){
   632    632       nByte = sizeof(Fts5Cursor) + pConfig->nCol * sizeof(int);
   633    633       pCsr = (Fts5Cursor*)sqlite3_malloc64(nByte);
   634    634       if( pCsr ){
   635    635         Fts5Global *pGlobal = pTab->pGlobal;
   636         -      memset(pCsr, 0, nByte);
          636  +      memset(pCsr, 0, (size_t)nByte);
   637    637         pCsr->aColumnSize = (int*)&pCsr[1];
   638    638         pCsr->pNext = pGlobal->pCsr;
   639    639         pGlobal->pCsr = pCsr;
   640    640         pCsr->iCsrId = ++pGlobal->iNextId;
   641    641       }else{
   642    642         rc = SQLITE_NOMEM;
   643    643       }
................................................................................
   910    910     const char *zRank = pCsr->zRank;
   911    911     const char *zRankArgs = pCsr->zRankArgs;
   912    912     
   913    913     nPhrase = sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
   914    914     nByte = sizeof(Fts5Sorter) + sizeof(int) * (nPhrase-1);
   915    915     pSorter = (Fts5Sorter*)sqlite3_malloc64(nByte);
   916    916     if( pSorter==0 ) return SQLITE_NOMEM;
   917         -  memset(pSorter, 0, nByte);
          917  +  memset(pSorter, 0, (size_t)nByte);
   918    918     pSorter->nIdx = nPhrase;
   919    919   
   920    920     /* TODO: It would be better to have some system for reusing statement
   921    921     ** handles here, rather than preparing a new one for each query. But that
   922    922     ** is not possible as SQLite reference counts the virtual table objects.
   923    923     ** And since the statement required here reads from this very virtual 
   924    924     ** table, saving it creates a circular reference.

Changes to ext/fts5/fts5_storage.c.

   285    285     sqlite3_int64 nByte;            /* Bytes of space to allocate */
   286    286   
   287    287     nByte = sizeof(Fts5Storage)               /* Fts5Storage object */
   288    288           + pConfig->nCol * sizeof(i64);      /* Fts5Storage.aTotalSize[] */
   289    289     *pp = p = (Fts5Storage*)sqlite3_malloc64(nByte);
   290    290     if( !p ) return SQLITE_NOMEM;
   291    291   
   292         -  memset(p, 0, nByte);
          292  +  memset(p, 0, (size_t)nByte);
   293    293     p->aTotalSize = (i64*)&p[1];
   294    294     p->pConfig = pConfig;
   295    295     p->pIndex = pIndex;
   296    296   
   297    297     if( bCreate ){
   298    298       if( pConfig->eContent==FTS5_CONTENT_NORMAL ){
   299    299         int nDefn = 32 + pConfig->nCol*10;

Changes to ext/fts5/fts5_unicode2.c.

   765    765   void sqlite3Fts5UnicodeAscii(u8 *aArray, u8 *aAscii){
   766    766     int i = 0;
   767    767     int iTbl = 0;
   768    768     while( i<128 ){
   769    769       int bToken = aArray[ aFts5UnicodeData[iTbl] & 0x1F ];
   770    770       int n = (aFts5UnicodeData[iTbl] >> 5) + i;
   771    771       for(; i<128 && i<n; i++){
   772         -      aAscii[i] = bToken;
          772  +      aAscii[i] = (u8)bToken;
   773    773       }
   774    774       iTbl++;
   775    775     }
   776    776   }

Changes to ext/fts5/test/fts5aa.test.

   423    423     INSERT INTO n1 VALUES('a b c d');
   424    424   }
   425    425   
   426    426   proc funk {} {
   427    427     db eval { UPDATE n1_config SET v=50 WHERE k='version' }
   428    428     set fd [db incrblob main n1_data block 10]
   429    429     fconfigure $fd -encoding binary -translation binary
   430         -  puts -nonewline $fd "\x44\x45"
          430  +#  puts -nonewline $fd "\x44\x45"
   431    431     close $fd
   432    432   }
   433    433   db func funk funk
   434    434   
   435    435   # This test case corrupts the structure record within the first invocation
   436    436   # of function funk(). Which used to cause the bm25() function to throw an
   437    437   # exception. But since bm25() can now used the cached structure record,
................................................................................
   598    598   }
   599    599   do_execsql_test 23.1 {
   600    600     SELECT * FROM t11, t10 WHERE t11.x = t10.x AND t10.rowid IS NULL;
   601    601   }
   602    602   do_execsql_test 23.2 {
   603    603     SELECT * FROM t11, t10 WHERE t10.rowid IS NULL;
   604    604   }
          605  +
          606  +#-------------------------------------------------------------------------
          607  +do_execsql_test 24.0 {
          608  +  CREATE VIRTUAL TABLE t12 USING fts5(x, detail=%DETAIL%);
          609  +  INSERT INTO t12 VALUES('aaaa');
          610  +}
          611  +do_execsql_test 24.1 {
          612  +  BEGIN;
          613  +    DELETE FROM t12 WHERE rowid=1;
          614  +    SELECT * FROM t12('aaaa');
          615  +    INSERT INTO t12 VALUES('aaaa');
          616  +  END;
          617  +}
          618  +do_execsql_test 24.2 {
          619  +  INSERT INTO t12(t12) VALUES('integrity-check');
          620  +}
          621  +do_execsql_test 24.3 {
          622  +    SELECT * FROM t12('aaaa');
          623  +} {aaaa}
          624  +
          625  +#-------------------------------------------------------------------------
          626  +do_execsql_test 25.0 {
          627  +  CREATE VIRTUAL TABLE t13 USING fts5(x, detail=%DETAIL%);
          628  +}
          629  +do_execsql_test 25.1 {
          630  +  BEGIN;
          631  +  INSERT INTO t13 VALUES('AAAA');
          632  +SELECT * FROM t13('BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB*');
          633  +
          634  +  END;
          635  +}
          636  +
   605    637   
   606    638   }
   607    639   
   608    640   expand_all_sql db
   609    641   finish_test

Changes to ext/misc/amatch.c.

   743    743   
   744    744     nIn = strlen(zIn);
   745    745     zOut = sqlite3_malloc64(nIn+1);
   746    746     if( zOut ){
   747    747       char q = zIn[0];              /* Quote character (if any ) */
   748    748   
   749    749       if( q!='[' && q!= '\'' && q!='"' && q!='`' ){
   750         -      memcpy(zOut, zIn, nIn+1);
          750  +      memcpy(zOut, zIn, (size_t)(nIn+1));
   751    751       }else{
   752    752         int iOut = 0;               /* Index of next byte to write to output */
   753    753         int iIn;                    /* Index of next byte to read from input */
   754    754   
   755    755         if( q=='[' ) q = ']';
   756    756         for(iIn=1; iIn<nIn; iIn++){
   757    757           if( zIn[iIn]==q ) iIn++;

Changes to ext/misc/closure.c.

   427    427   
   428    428     nIn = strlen(zIn);
   429    429     zOut = sqlite3_malloc64(nIn+1);
   430    430     if( zOut ){
   431    431       char q = zIn[0];              /* Quote character (if any ) */
   432    432   
   433    433       if( q!='[' && q!= '\'' && q!='"' && q!='`' ){
   434         -      memcpy(zOut, zIn, nIn+1);
          434  +      memcpy(zOut, zIn, (size_t)(nIn+1));
   435    435       }else{
   436    436         int iOut = 0;               /* Index of next byte to write to output */
   437    437         int iIn;                    /* Index of next byte to read from input */
   438    438   
   439    439         if( q=='[' ) q = ']';
   440    440         for(iIn=1; iIn<nIn; iIn++){
   441    441           if( zIn[iIn]==q ) iIn++;

Changes to ext/misc/fileio.c.

   154    154     }
   155    155     pBuf = sqlite3_malloc64( nIn ? nIn : 1 );
   156    156     if( pBuf==0 ){
   157    157       sqlite3_result_error_nomem(ctx);
   158    158       fclose(in);
   159    159       return;
   160    160     }
   161         -  if( nIn==fread(pBuf, 1, nIn, in) ){
          161  +  if( nIn==fread(pBuf, 1, (size_t)nIn, in) ){
   162    162       sqlite3_result_blob64(ctx, pBuf, nIn, sqlite3_free);
   163    163     }else{
   164    164       sqlite3_result_error_code(ctx, SQLITE_IOERR);
   165    165       sqlite3_free(pBuf);
   166    166     }
   167    167     fclose(in);
   168    168   }
................................................................................
   289    289   #endif
   290    290   }
   291    291   
   292    292   /*
   293    293   ** Argument zFile is the name of a file that will be created and/or written
   294    294   ** by SQL function writefile(). This function ensures that the directory
   295    295   ** zFile will be written to exists, creating it if required. The permissions
   296         -** for any path components created by this function are set to (mode&0777).
          296  +** for any path components created by this function are set in accordance
          297  +** with the current umask.
   297    298   **
   298    299   ** If an OOM condition is encountered, SQLITE_NOMEM is returned. Otherwise,
   299    300   ** SQLITE_OK is returned if the directory is successfully created, or
   300    301   ** SQLITE_ERROR otherwise.
   301    302   */
   302    303   static int makeDirectory(
   303         -  const char *zFile,
   304         -  mode_t mode
          304  +  const char *zFile
   305    305   ){
   306    306     char *zCopy = sqlite3_mprintf("%s", zFile);
   307    307     int rc = SQLITE_OK;
   308    308   
   309    309     if( zCopy==0 ){
   310    310       rc = SQLITE_NOMEM;
   311    311     }else{
................................................................................
   318    318   
   319    319         for(; zCopy[i]!='/' && i<nCopy; i++);
   320    320         if( i==nCopy ) break;
   321    321         zCopy[i] = '\0';
   322    322   
   323    323         rc2 = fileStat(zCopy, &sStat);
   324    324         if( rc2!=0 ){
   325         -        if( mkdir(zCopy, mode & 0777) ) rc = SQLITE_ERROR;
          325  +        if( mkdir(zCopy, 0777) ) rc = SQLITE_ERROR;
   326    326         }else{
   327    327           if( !S_ISDIR(sStat.st_mode) ) rc = SQLITE_ERROR;
   328    328         }
   329    329         zCopy[i] = '/';
   330    330         i++;
   331    331       }
   332    332   
................................................................................
   476    476     }
   477    477     if( argc==4 ){
   478    478       mtime = sqlite3_value_int64(argv[3]);
   479    479     }
   480    480   
   481    481     res = writeFile(context, zFile, argv[1], mode, mtime);
   482    482     if( res==1 && errno==ENOENT ){
   483         -    if( makeDirectory(zFile, mode)==SQLITE_OK ){
          483  +    if( makeDirectory(zFile)==SQLITE_OK ){
   484    484         res = writeFile(context, zFile, argv[1], mode, mtime);
   485    485       }
   486    486     }
   487    487   
   488    488     if( argc>2 && res!=0 ){
   489    489       if( S_ISLNK(mode) ){
   490    490         ctxErrorMsg(context, "failed to create symlink: %s", zFile);

Changes to ext/misc/fuzzer.c.

   452    452   
   453    453     nIn = strlen(zIn);
   454    454     zOut = sqlite3_malloc64(nIn+1);
   455    455     if( zOut ){
   456    456       char q = zIn[0];              /* Quote character (if any ) */
   457    457   
   458    458       if( q!='[' && q!= '\'' && q!='"' && q!='`' ){
   459         -      memcpy(zOut, zIn, nIn+1);
          459  +      memcpy(zOut, zIn, (size_t)(nIn+1));
   460    460       }else{
   461    461         int iOut = 0;               /* Index of next byte to write to output */
   462    462         int iIn;                    /* Index of next byte to read from input */
   463    463   
   464    464         if( q=='[' ) q = ']';
   465    465         for(iIn=1; iIn<nIn; iIn++){
   466    466           if( zIn[iIn]==q ) iIn++;
................................................................................
   520    520       if( pNew==0 ){
   521    521         rc = SQLITE_NOMEM;
   522    522       }else{
   523    523         char *zTab;                 /* Dequoted name of fuzzer data table */
   524    524   
   525    525         memset(pNew, 0, sizeof(*pNew));
   526    526         pNew->zClassName = (char*)&pNew[1];
   527         -      memcpy(pNew->zClassName, zModule, nModule+1);
          527  +      memcpy(pNew->zClassName, zModule, (size_t)(nModule+1));
   528    528   
   529    529         zTab = fuzzerDequote(argv[3]);
   530    530         if( zTab==0 ){
   531    531           rc = SQLITE_NOMEM;
   532    532         }else{
   533    533           rc = fuzzerLoadRules(db, pNew, zDb, zTab, pzErr);
   534    534           sqlite3_free(zTab);

Changes to ext/misc/unionvtab.c.

   252    252   */
   253    253   static void *unionMalloc(int *pRc, sqlite3_int64 nByte){
   254    254     void *pRet;
   255    255     assert( nByte>0 );
   256    256     if( *pRc==SQLITE_OK ){
   257    257       pRet = sqlite3_malloc64(nByte);
   258    258       if( pRet ){
   259         -      memset(pRet, 0, nByte);
          259  +      memset(pRet, 0, (size_t)nByte);
   260    260       }else{
   261    261         *pRc = SQLITE_NOMEM;
   262    262       }
   263    263     }else{
   264    264       pRet = 0;
   265    265     }
   266    266     return pRet;
................................................................................
   275    275   */
   276    276   static char *unionStrdup(int *pRc, const char *zIn){
   277    277     char *zRet = 0;
   278    278     if( zIn ){
   279    279       sqlite3_int64 nByte = strlen(zIn) + 1;
   280    280       zRet = unionMalloc(pRc, nByte);
   281    281       if( zRet ){
   282         -      memcpy(zRet, zIn, nByte);
          282  +      memcpy(zRet, zIn, (size_t)nByte);
   283    283       }
   284    284     }
   285    285     return zRet;
   286    286   }
   287    287   
   288    288   /*
   289    289   ** If the first character of the string passed as the only argument to this

Changes to ext/rtree/rtree.c.

  3751   3751   **
  3752   3752   ** The human readable string takes the form of a Tcl list with one
  3753   3753   ** entry for each cell in the r-tree node. Each entry is itself a
  3754   3754   ** list, containing the 8-byte rowid/pageno followed by the 
  3755   3755   ** <num-dimension>*2 coordinates.
  3756   3756   */
  3757   3757   static void rtreenode(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){
  3758         -  char *zText = 0;
  3759   3758     RtreeNode node;
  3760   3759     Rtree tree;
  3761   3760     int ii;
         3761  +  int nData;
         3762  +  int errCode;
         3763  +  sqlite3_str *pOut;
  3762   3764   
  3763   3765     UNUSED_PARAMETER(nArg);
  3764   3766     memset(&node, 0, sizeof(RtreeNode));
  3765   3767     memset(&tree, 0, sizeof(Rtree));
  3766   3768     tree.nDim = (u8)sqlite3_value_int(apArg[0]);
         3769  +  if( tree.nDim<1 || tree.nDim>5 ) return;
  3767   3770     tree.nDim2 = tree.nDim*2;
  3768   3771     tree.nBytesPerCell = 8 + 8 * tree.nDim;
  3769   3772     node.zData = (u8 *)sqlite3_value_blob(apArg[1]);
         3773  +  nData = sqlite3_value_bytes(apArg[1]);
         3774  +  if( nData<4 ) return;
         3775  +  if( nData<NCELL(&node)*tree.nBytesPerCell ) return;
  3770   3776   
         3777  +  pOut = sqlite3_str_new(0);
  3771   3778     for(ii=0; ii<NCELL(&node); ii++){
  3772         -    char zCell[512];
  3773         -    int nCell = 0;
  3774   3779       RtreeCell cell;
  3775   3780       int jj;
  3776   3781   
  3777   3782       nodeGetCell(&tree, &node, ii, &cell);
  3778         -    sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid);
  3779         -    nCell = (int)strlen(zCell);
         3783  +    if( ii>0 ) sqlite3_str_append(pOut, " ", 1);
         3784  +    sqlite3_str_appendf(pOut, "{%lld", cell.iRowid);
  3780   3785       for(jj=0; jj<tree.nDim2; jj++){
  3781   3786   #ifndef SQLITE_RTREE_INT_ONLY
  3782         -      sqlite3_snprintf(512-nCell,&zCell[nCell], " %g",
  3783         -                       (double)cell.aCoord[jj].f);
         3787  +      sqlite3_str_appendf(pOut, " %g", (double)cell.aCoord[jj].f);
  3784   3788   #else
  3785         -      sqlite3_snprintf(512-nCell,&zCell[nCell], " %d",
  3786         -                       cell.aCoord[jj].i);
         3789  +      sqlite3_str_appendf(pOut, " %d", cell.aCoord[jj].i);
  3787   3790   #endif
  3788         -      nCell = (int)strlen(zCell);
  3789   3791       }
  3790         -
  3791         -    if( zText ){
  3792         -      char *zTextNew = sqlite3_mprintf("%s {%s}", zText, zCell);
  3793         -      sqlite3_free(zText);
  3794         -      zText = zTextNew;
  3795         -    }else{
  3796         -      zText = sqlite3_mprintf("{%s}", zCell);
  3797         -    }
         3792  +    sqlite3_str_append(pOut, "}", 1);
  3798   3793     }
  3799         -  
  3800         -  sqlite3_result_text(ctx, zText, -1, sqlite3_free);
         3794  +  errCode = sqlite3_str_errcode(pOut);
         3795  +  sqlite3_result_text(ctx, sqlite3_str_finish(pOut), -1, sqlite3_free);
         3796  +  sqlite3_result_error_code(ctx, errCode);
  3801   3797   }
  3802   3798   
  3803   3799   /* This routine implements an SQL function that returns the "depth" parameter
  3804   3800   ** from the front of a blob that is an r-tree node.  For example:
  3805   3801   **
  3806   3802   **     SELECT rtreedepth(data) FROM rt_node WHERE nodeno=1;
  3807   3803   **

Changes to ext/session/changeset.c.

    51     51     }
    52     52     fseek(f, 0, SEEK_END);
    53     53     sz = ftell(f);
    54     54     rewind(f);
    55     55     pBuf = sqlite3_malloc64( sz ? sz : 1 );
    56     56     if( pBuf==0 ){
    57     57       fprintf(stderr, "cannot allocate %d to hold content of \"%s\"\n",
    58         -            sz, zFilename);
           58  +            (int)sz, zFilename);
    59     59       exit(1);
    60     60     }
    61     61     if( sz>0 ){
    62         -    if( fread(pBuf, sz, 1, f)!=1 ){
    63         -      fprintf(stderr, "cannot read all %d bytes of \"%s\"\n", sz, zFilename);
           62  +    if( fread(pBuf, (size_t)sz, 1, f)!=1 ){
           63  +      fprintf(stderr, "cannot read all %d bytes of \"%s\"\n",
           64  +              (int)sz, zFilename);
    64     65         exit(1);
    65     66       }
    66     67       fclose(f);
    67     68     }
    68         -  *pSz = sz;
           69  +  *pSz = (int)sz;
    69     70     *ppBuf = pBuf;
    70     71   }
    71     72   
    72     73   /* Array for converting from half-bytes (nybbles) into ASCII hex
    73     74   ** digits. */
    74     75   static const char hexdigits[] = {
    75     76     '0', '1', '2', '3', '4', '5', '6', '7',

Changes to src/alter.c.

   162    162       pVTab = sqlite3GetVTable(db, pTab);
   163    163       if( pVTab->pVtab->pModule->xRename==0 ){
   164    164         pVTab = 0;
   165    165       }
   166    166     }
   167    167   #endif
   168    168   
   169         -  /* Begin a transaction for database iDb. 
   170         -  ** Then modify the schema cookie (since the ALTER TABLE modifies the
   171         -  ** schema). Open a statement transaction if the table is a virtual
   172         -  ** table.
   173         -  */
          169  +  /* Begin a transaction for database iDb. Then modify the schema cookie
          170  +  ** (since the ALTER TABLE modifies the schema). Call sqlite3MayAbort(),
          171  +  ** as the scalar functions (e.g. sqlite_rename_table()) invoked by the 
          172  +  ** nested SQL may raise an exception.  */
   174    173     v = sqlite3GetVdbe(pParse);
   175    174     if( v==0 ){
   176    175       goto exit_rename_table;
   177    176     }
          177  +  sqlite3MayAbort(pParse);
   178    178   
   179    179     /* figure out how many UTF-8 characters are in zName */
   180    180     zTabName = pTab->zName;
   181    181     nTabName = sqlite3Utf8CharLen(zTabName, -1);
   182    182   
   183    183     /* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in
   184    184     ** the schema to use the new table name.  */
................................................................................
   239    239     ** SQLite tables) that are identified by the name of the virtual table.
   240    240     */
   241    241   #ifndef SQLITE_OMIT_VIRTUALTABLE
   242    242     if( pVTab ){
   243    243       int i = ++pParse->nMem;
   244    244       sqlite3VdbeLoadString(v, i, zName);
   245    245       sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
   246         -    sqlite3MayAbort(pParse);
   247    246     }
   248    247   #endif
   249    248   
   250    249     renameReloadSchema(pParse, iDb);
   251    250     renameTestSchema(pParse, zDb, iDb==1);
   252    251   
   253    252   exit_rename_table:
................................................................................
   560    559       goto exit_rename_column;
   561    560     }
   562    561   
   563    562     /* Do the rename operation using a recursive UPDATE statement that
   564    563     ** uses the sqlite_rename_column() SQL function to compute the new
   565    564     ** CREATE statement text for the sqlite_master table.
   566    565     */
          566  +  sqlite3MayAbort(pParse);
   567    567     zNew = sqlite3NameFromToken(db, pNew);
   568    568     if( !zNew ) goto exit_rename_column;
   569    569     assert( pNew->n>0 );
   570    570     bQuote = sqlite3Isquote(pNew->z[0]);
   571    571     sqlite3NestedParse(pParse, 
   572    572         "UPDATE \"%w\".%s SET "
   573    573         "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) "

Changes to src/attach.c.

   230    230     ** remove the entry from the db->aDb[] array. i.e. put everything back the
   231    231     ** way we found it.
   232    232     */
   233    233     if( rc==SQLITE_OK ){
   234    234       sqlite3BtreeEnterAll(db);
   235    235       db->init.iDb = 0;
   236    236       db->mDbFlags &= ~(DBFLAG_SchemaKnownOk);
   237         -    rc = sqlite3Init(db, &zErrDyn);
          237  +    if( !REOPEN_AS_MEMDB(db) ){
          238  +      rc = sqlite3Init(db, &zErrDyn);
          239  +    }
   238    240       sqlite3BtreeLeaveAll(db);
   239    241       assert( zErrDyn==0 || rc!=SQLITE_OK );
   240    242     }
   241    243   #ifdef SQLITE_USER_AUTHENTICATION
   242    244     if( rc==SQLITE_OK ){
   243    245       u8 newAuth = 0;
   244    246       rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth);

Changes to src/btree.c.

  1691   1691           }
  1692   1692           if( iFree2 ){
  1693   1693             if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage);
  1694   1694             sz2 = get2byte(&data[iFree2+2]);
  1695   1695             if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage);
  1696   1696             memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
  1697   1697             sz += sz2;
         1698  +        }else if( iFree+sz>usableSize ){
         1699  +          return SQLITE_CORRUPT_PAGE(pPage);
  1698   1700           }
         1701  +
  1699   1702           cbrk = top+sz;
  1700   1703           assert( cbrk+(iFree-top) <= usableSize );
  1701   1704           memmove(&data[cbrk], &data[top], iFree-top);
  1702   1705           for(pAddr=&data[cellOffset]; pAddr<pEnd; pAddr+=2){
  1703   1706             pc = get2byte(pAddr);
  1704   1707             if( pc<iFree ){ put2byte(pAddr, pc+sz); }
  1705   1708             else if( pc<iFree2 ){ put2byte(pAddr, pc+sz2); }
................................................................................
  1809   1812           ** for the portion used by the new allocation. */
  1810   1813           put2byte(&aData[pc+2], x);
  1811   1814         }
  1812   1815         return &aData[pc + x];
  1813   1816       }
  1814   1817       iAddr = pc;
  1815   1818       pc = get2byte(&aData[pc]);
  1816         -    if( pc<iAddr+size ){
         1819  +    if( pc<=iAddr+size ){
  1817   1820         if( pc ){
  1818   1821           /* The next slot in the chain is not past the end of the current slot */
  1819   1822           *pRc = SQLITE_CORRUPT_PAGE(pPg);
  1820   1823         }
  1821   1824         return 0;
  1822   1825       }
  1823   1826     }
................................................................................
  2249   2252     }
  2250   2253     testcase( pPage->nCell==MX_CELL(pBt) );
  2251   2254     /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
  2252   2255     ** possible for a root page of a table that contains no rows) then the
  2253   2256     ** offset to the cell content area will equal the page size minus the
  2254   2257     ** bytes of reserved space. */
  2255   2258     assert( pPage->nCell>0
  2256         -       || get2byteNotZero(&data[5])==pBt->usableSize
         2259  +       || get2byteNotZero(&data[5])==(int)pBt->usableSize
  2257   2260          || CORRUPT_DB );
  2258   2261     pPage->nFree = -1;  /* Indicate that this value is yet uncomputed */
  2259   2262     pPage->isInit = 1;
  2260   2263     if( pBt->db->flags & SQLITE_CellSizeCk ){
  2261   2264       return btreeCellSizeCheck(pPage);
  2262   2265     }
  2263   2266     return SQLITE_OK;
................................................................................
  6654   6657     int rc;                             /* Return Code */
  6655   6658     int nFree;                          /* Initial number of pages on free-list */
  6656   6659   
  6657   6660     assert( sqlite3_mutex_held(pBt->mutex) );
  6658   6661     assert( CORRUPT_DB || iPage>1 );
  6659   6662     assert( !pMemPage || pMemPage->pgno==iPage );
  6660   6663   
  6661         -  if( iPage<2 ) return SQLITE_CORRUPT_BKPT;
         6664  +  if( iPage<2 || iPage>pBt->nPage ){
         6665  +    return SQLITE_CORRUPT_BKPT;
         6666  +  }
  6662   6667     if( pMemPage ){
  6663   6668       pPage = pMemPage;
  6664   6669       sqlite3PagerRef(pPage->pDbPage);
  6665   6670     }else{
  6666   6671       pPage = btreePageLookup(pBt, iPage);
  6667   6672     }
  6668   6673   
................................................................................
  8023   8028         rc = btreeComputeFreeSpace(apOld[i]);
  8024   8029         if( rc ){
  8025   8030           memset(apOld, 0, (i)*sizeof(MemPage*));
  8026   8031           goto balance_cleanup;
  8027   8032         }
  8028   8033       }
  8029   8034       setMempageRoot(apOld[i], pgnoRoot);
  8030         -
  8031         -    nMaxCells += 1+apOld[i]->nCell+apOld[i]->nOverflow;
  8032   8035       if( (i--)==0 ) break;
  8033   8036   
  8034   8037       if( pParent->nOverflow && i+nxDiv==pParent->aiOvfl[0] ){
  8035   8038         apDiv[i] = pParent->apOvfl[0];
  8036   8039         pgno = get4byte(apDiv[i]);
  8037   8040         szNew[i] = pParent->xCellSize(pParent, apDiv[i]);
  8038   8041         pParent->nOverflow = 0;
................................................................................
  8068   8071         }
  8069   8072         dropCell(pParent, i+nxDiv-pParent->nOverflow, szNew[i], &rc);
  8070   8073       }
  8071   8074     }
  8072   8075   
  8073   8076     /* Make nMaxCells a multiple of 4 in order to preserve 8-byte
  8074   8077     ** alignment */
         8078  +  nMaxCells = nOld*(MX_CELL(pBt) + ArraySize(pParent->apOvfl));
  8075   8079     nMaxCells = (nMaxCells + 3)&~3;
  8076   8080   
  8077   8081     /*
  8078   8082     ** Allocate space for memory structures
  8079   8083     */
  8080   8084     szScratch =
  8081   8085          nMaxCells*sizeof(u8*)                       /* b.apCell */
  8082   8086        + nMaxCells*sizeof(u16)                       /* b.szCell */
  8083   8087        + pBt->pageSize;                              /* aSpace1 */
  8084   8088   
  8085         -  assert( szScratch<=6*(int)pBt->pageSize );
         8089  +  assert( szScratch<=7*(int)pBt->pageSize );
  8086   8090     b.apCell = sqlite3StackAllocRaw(0, szScratch );
  8087   8091     if( b.apCell==0 ){
  8088   8092       rc = SQLITE_NOMEM_BKPT;
  8089   8093       goto balance_cleanup;
  8090   8094     }
  8091   8095     b.szCell = (u16*)&b.apCell[nMaxCells];
  8092   8096     aSpace1 = (u8*)&b.szCell[nMaxCells];
................................................................................
  8628   8632       ** by smaller than the child due to the database header, and so all the
  8629   8633       ** free space needs to be up front.
  8630   8634       */
  8631   8635       assert( nNew==1 || CORRUPT_DB );
  8632   8636       rc = defragmentPage(apNew[0], -1);
  8633   8637       testcase( rc!=SQLITE_OK );
  8634   8638       assert( apNew[0]->nFree == 
  8635         -        (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2)
         8639  +        (get2byteNotZero(&apNew[0]->aData[5]) - apNew[0]->cellOffset
         8640  +          - apNew[0]->nCell*2)
  8636   8641         || rc!=SQLITE_OK
  8637   8642       );
  8638   8643       copyNodeContent(apNew[0], pParent, &rc);
  8639   8644       freePage(apNew[0], &rc);
  8640   8645     }else if( REQUIRE_PTRMAP && !leafCorrection ){
  8641   8646       /* Fix the pointer map entries associated with the right-child of each
  8642   8647       ** sibling page. All other pointer map entries have already been taken

Changes to src/build.c.

  1402   1402     }
  1403   1403     if( nTerm==1
  1404   1404      && pCol
  1405   1405      && sqlite3StrICmp(sqlite3ColumnType(pCol,""), "INTEGER")==0
  1406   1406      && sortOrder!=SQLITE_SO_DESC
  1407   1407     ){
  1408   1408       if( IN_RENAME_OBJECT && pList ){
  1409         -      sqlite3RenameTokenRemap(pParse, &pTab->iPKey, pList->a[0].pExpr);
         1409  +      Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[0].pExpr);
         1410  +      sqlite3RenameTokenRemap(pParse, &pTab->iPKey, pCExpr);
  1410   1411       }
  1411   1412       pTab->iPKey = iCol;
  1412   1413       pTab->keyConf = (u8)onError;
  1413   1414       assert( autoInc==0 || autoInc==1 );
  1414   1415       pTab->tabFlags |= autoInc*TF_Autoincrement;
  1415   1416       if( pList ) pParse->iPkSortOrder = pList->a[0].sortOrder;
  1416   1417     }else if( autoInc ){
................................................................................
  3151   3152     }
  3152   3153     pDb = &db->aDb[iDb];
  3153   3154   
  3154   3155     assert( pTab!=0 );
  3155   3156     assert( pParse->nErr==0 );
  3156   3157     if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 
  3157   3158          && db->init.busy==0
         3159  +       && pTblName!=0
  3158   3160   #if SQLITE_USER_AUTHENTICATION
  3159   3161          && sqlite3UserAuthTable(pTab->zName)==0
  3160   3162   #endif
  3161   3163   #ifdef SQLITE_ALLOW_SQLITE_MASTER_INDEX
  3162   3164          && sqlite3StrICmp(&pTab->zName[7],"master")!=0
  3163   3165   #endif
  3164         -       && sqlite3StrNICmp(&pTab->zName[7],"altertab_",9)!=0
  3165   3166    ){
  3166   3167       sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
  3167   3168       goto exit_create_index;
  3168   3169     }
  3169   3170   #ifndef SQLITE_OMIT_VIEW
  3170   3171     if( pTab->pSelect ){
  3171   3172       sqlite3ErrorMsg(pParse, "views may not be indexed");

Changes to src/main.c.

   839    839           { SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_Fts3Tokenizer  },
   840    840           { SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_LoadExtension  },
   841    841           { SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE,      SQLITE_NoCkptOnClose  },
   842    842           { SQLITE_DBCONFIG_ENABLE_QPSG,           SQLITE_EnableQPSG     },
   843    843           { SQLITE_DBCONFIG_TRIGGER_EQP,           SQLITE_TriggerEQP     },
   844    844           { SQLITE_DBCONFIG_RESET_DATABASE,        SQLITE_ResetDatabase  },
   845    845           { SQLITE_DBCONFIG_DEFENSIVE,             SQLITE_Defensive      },
          846  +        { SQLITE_DBCONFIG_WRITABLE_SCHEMA,       SQLITE_WriteSchema|
          847  +                                                 SQLITE_NoSchemaError  },
   846    848         };
   847    849         unsigned int i;
   848    850         rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
   849    851         for(i=0; i<ArraySize(aFlagOp); i++){
   850    852           if( aFlagOp[i].op==op ){
   851    853             int onoff = va_arg(ap, int);
   852    854             int *pRes = va_arg(ap, int*);

Changes to src/os_unix.c.

  7868   7868     ** array cannot be const.
  7869   7869     */
  7870   7870     static sqlite3_vfs aVfs[] = {
  7871   7871   #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
  7872   7872       UNIXVFS("unix",          autolockIoFinder ),
  7873   7873   #elif OS_VXWORKS
  7874   7874       UNIXVFS("unix",          vxworksIoFinder ),
  7875         -#elif __Fuchsia__
  7876         -    /* We are told that Fuchsia only supports dot-file locking */
  7877         -    UNIXVFS("unix",          dotlockIoFinder ),
  7878   7875   #else
  7879   7876       UNIXVFS("unix",          posixIoFinder ),
  7880   7877   #endif
  7881   7878       UNIXVFS("unix-none",     nolockIoFinder ),
  7882   7879       UNIXVFS("unix-dotfile",  dotlockIoFinder ),
  7883   7880       UNIXVFS("unix-excl",     posixIoFinder ),
  7884   7881   #if OS_VXWORKS

Changes to src/shell.c.in.

  2743   2743     sqlite3SelectTrace = savedSelectTrace;
  2744   2744   #endif
  2745   2745   #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
  2746   2746     sqlite3WhereTrace = savedWhereTrace;
  2747   2747   #endif
  2748   2748   }
  2749   2749   
  2750         -/* Name of the TEMP table that holds bind parameter values */
  2751         -#define BIND_PARAM_TABLE "$Parameters"
  2752         -
  2753   2750   /* Create the TEMP table used to store parameter bindings */
  2754   2751   static void bind_table_init(ShellState *p){
         2752  +  int wrSchema = 0;
         2753  +  sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
         2754  +  sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
  2755   2755     sqlite3_exec(p->db,
  2756         -    "CREATE TABLE IF NOT EXISTS temp.[" BIND_PARAM_TABLE "](\n"
         2756  +    "CREATE TABLE IF NOT EXISTS temp.sqlite_parameters(\n"
  2757   2757       "  key TEXT PRIMARY KEY,\n"
  2758   2758       "  value ANY\n"
  2759   2759       ") WITHOUT ROWID;",
  2760   2760       0, 0, 0);
         2761  +  sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
  2761   2762   }
  2762   2763   
  2763   2764   /*
  2764   2765   ** Bind parameters on a prepared statement.
  2765   2766   **
  2766   2767   ** Parameter bindings are taken from a TEMP table of the form:
  2767   2768   **
  2768         -**    CREATE TEMP TABLE "$Parameters"(key TEXT PRIMARY KEY, value)
         2769  +**    CREATE TEMP TABLE sqlite_parameters(key TEXT PRIMARY KEY, value)
  2769   2770   **    WITHOUT ROWID;
  2770   2771   **
  2771   2772   ** No bindings occur if this table does not exist.  The special character '$'
  2772   2773   ** is included in the table name to help prevent collisions with actual tables.
  2773   2774   ** The table must be in the TEMP schema.
  2774   2775   */
  2775   2776   static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){
................................................................................
  2776   2777     int nVar;
  2777   2778     int i;
  2778   2779     int rc;
  2779   2780     sqlite3_stmt *pQ = 0;
  2780   2781   
  2781   2782     nVar = sqlite3_bind_parameter_count(pStmt);
  2782   2783     if( nVar==0 ) return;  /* Nothing to do */
  2783         -  if( sqlite3_table_column_metadata(pArg->db, "TEMP", BIND_PARAM_TABLE,
         2784  +  if( sqlite3_table_column_metadata(pArg->db, "TEMP", "sqlite_parameters",
  2784   2785                                       "key", 0, 0, 0, 0, 0)!=SQLITE_OK ){
  2785   2786       return; /* Parameter table does not exist */
  2786   2787     }
  2787   2788     rc = sqlite3_prepare_v2(pArg->db,
  2788         -          "SELECT value FROM temp.\"" BIND_PARAM_TABLE "\""
         2789  +          "SELECT value FROM temp.sqlite_parameters"
  2789   2790             " WHERE key=?1", -1, &pQ, 0);
  2790   2791     if( rc || pQ==0 ) return;
  2791   2792     for(i=1; i<=nVar; i++){
  2792   2793       char zNum[30];
  2793   2794       const char *zVar = sqlite3_bind_parameter_name(pStmt, i);
  2794   2795       if( zVar==0 ){
  2795   2796         sqlite3_snprintf(sizeof(zNum),zNum,"?%d",i);
................................................................................
  3448   3449   ** start of the description of what that command does.
  3449   3450   */
  3450   3451   static const char *(azHelp[]) = {
  3451   3452   #if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE)
  3452   3453     ".archive ...             Manage SQL archives",
  3453   3454     "   Each command must have exactly one of the following options:",
  3454   3455     "     -c, --create               Create a new archive",
  3455         -  "     -u, --update               Update or add files to an existing archive",
         3456  +  "     -u, --update               Add files or update files with changed mtime",
         3457  +  "     -i, --insert               Like -u but always add even if mtime unchanged",
  3456   3458     "     -t, --list                 List contents of archive",
  3457   3459     "     -x, --extract              Extract files from archive",
  3458   3460     "   Optional arguments:",
  3459   3461     "     -v, --verbose              Print each filename as it is processed",
  3460   3462     "     -f FILE, --file FILE       Operate on archive FILE (default is current db)",
  3461   3463     "     -a FILE, --append FILE     Operate on FILE opened using the apndvfs VFS",
  3462   3464     "     -C DIR, --directory DIR    Change to directory DIR to read/extract files",
................................................................................
  4769   4771        { "number of triggers:",
  4770   4772          "SELECT count(*) FROM %s WHERE type='trigger'" },
  4771   4773        { "number of views:",
  4772   4774          "SELECT count(*) FROM %s WHERE type='view'" },
  4773   4775        { "schema size:",
  4774   4776          "SELECT total(length(sql)) FROM %s" },
  4775   4777     };
  4776         -  int i;
         4778  +  int i, rc;
  4777   4779     unsigned iDataVersion;
  4778   4780     char *zSchemaTab;
  4779   4781     char *zDb = nArg>=2 ? azArg[1] : "main";
  4780   4782     sqlite3_stmt *pStmt = 0;
  4781   4783     unsigned char aHdr[100];
  4782   4784     open_db(p, 0);
  4783   4785     if( p->db==0 ) return 1;
  4784         -  sqlite3_prepare_v2(p->db,"SELECT data FROM sqlite_dbpage(?1) WHERE pgno=1",
  4785         -                     -1, &pStmt, 0);
         4786  +  rc = sqlite3_prepare_v2(p->db,
         4787  +             "SELECT data FROM sqlite_dbpage(?1) WHERE pgno=1",
         4788  +             -1, &pStmt, 0);
         4789  +  if( rc ){
         4790  +    if( !sqlite3_compileoption_used("ENABLE_DBPAGE_VTAB") ){
         4791  +      utf8_printf(stderr, "the \".dbinfo\" command requires the "
         4792  +                          "-DSQLITE_ENABLE_DBPAGE_VTAB compile-time options\n");
         4793  +    }else{
         4794  +      utf8_printf(stderr, "error: %s\n", sqlite3_errmsg(p->db));
         4795  +    }
         4796  +    sqlite3_finalize(pStmt);
         4797  +    return 1;
         4798  +  }
  4786   4799     sqlite3_bind_text(pStmt, 1, zDb, -1, SQLITE_STATIC);
  4787   4800     if( sqlite3_step(pStmt)==SQLITE_ROW
  4788   4801      && sqlite3_column_bytes(pStmt,0)>100
  4789   4802     ){
  4790   4803       memcpy(aHdr, sqlite3_column_blob(pStmt,0), 100);
  4791   4804       sqlite3_finalize(pStmt);
  4792   4805     }else{
................................................................................
  5372   5385     return SQLITE_ERROR;
  5373   5386   }
  5374   5387   
  5375   5388   /*
  5376   5389   ** Values for ArCommand.eCmd.
  5377   5390   */
  5378   5391   #define AR_CMD_CREATE       1
  5379         -#define AR_CMD_EXTRACT      2
  5380         -#define AR_CMD_LIST         3
  5381         -#define AR_CMD_UPDATE       4
  5382         -#define AR_CMD_HELP         5
         5392  +#define AR_CMD_UPDATE       2
         5393  +#define AR_CMD_INSERT       3
         5394  +#define AR_CMD_EXTRACT      4
         5395  +#define AR_CMD_LIST         5
         5396  +#define AR_CMD_HELP         6
  5383   5397   
  5384   5398   /*
  5385   5399   ** Other (non-command) switches.
  5386   5400   */
  5387         -#define AR_SWITCH_VERBOSE     6
  5388         -#define AR_SWITCH_FILE        7
  5389         -#define AR_SWITCH_DIRECTORY   8
  5390         -#define AR_SWITCH_APPEND      9
  5391         -#define AR_SWITCH_DRYRUN     10
         5401  +#define AR_SWITCH_VERBOSE     7
         5402  +#define AR_SWITCH_FILE        8
         5403  +#define AR_SWITCH_DIRECTORY   9
         5404  +#define AR_SWITCH_APPEND     10
         5405  +#define AR_SWITCH_DRYRUN     11
  5392   5406   
  5393   5407   static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){
  5394   5408     switch( eSwitch ){
  5395   5409       case AR_CMD_CREATE:
  5396   5410       case AR_CMD_EXTRACT:
  5397   5411       case AR_CMD_LIST:
  5398   5412       case AR_CMD_UPDATE:
         5413  +    case AR_CMD_INSERT:
  5399   5414       case AR_CMD_HELP:
  5400   5415         if( pAr->eCmd ){
  5401   5416           return arErrorMsg(pAr, "multiple command options");
  5402   5417         }
  5403   5418         pAr->eCmd = eSwitch;
  5404   5419         break;
  5405   5420   
................................................................................
  5438   5453       const char *zLong;
  5439   5454       char cShort;
  5440   5455       u8 eSwitch;
  5441   5456       u8 bArg;
  5442   5457     } aSwitch[] = {
  5443   5458       { "create",    'c', AR_CMD_CREATE,       0 },
  5444   5459       { "extract",   'x', AR_CMD_EXTRACT,      0 },
         5460  +    { "insert",    'i', AR_CMD_INSERT,       0 },
  5445   5461       { "list",      't', AR_CMD_LIST,         0 },
  5446   5462       { "update",    'u', AR_CMD_UPDATE,       0 },
  5447   5463       { "help",      'h', AR_CMD_HELP,         0 },
  5448   5464       { "verbose",   'v', AR_SWITCH_VERBOSE,   0 },
  5449   5465       { "file",      'f', AR_SWITCH_FILE,      1 },
  5450   5466       { "append",    'a', AR_SWITCH_APPEND,    1 },
  5451   5467       { "directory", 'C', AR_SWITCH_DIRECTORY, 1 },
................................................................................
  5773   5789       }
  5774   5790     }
  5775   5791     return rc;
  5776   5792   }
  5777   5793   
  5778   5794   
  5779   5795   /*
  5780         -** Implementation of .ar "create" and "update" commands.
         5796  +** Implementation of .ar "create", "insert", and "update" commands.
         5797  +**
         5798  +**     create    ->     Create a new SQL archive
         5799  +**     insert    ->     Insert or reinsert all files listed
         5800  +**     update    ->     Insert files that have changed or that were not
         5801  +**                      previously in the archive
  5781   5802   **
  5782   5803   ** Create the "sqlar" table in the database if it does not already exist.
  5783   5804   ** Then add each file in the azFile[] array to the archive. Directories
  5784   5805   ** are added recursively. If argument bVerbose is non-zero, a message is
  5785   5806   ** printed on stdout for each file archived.
  5786   5807   **
  5787   5808   ** The create command is the same as update, except that it drops
  5788         -** any existing "sqlar" table before beginning.
         5809  +** any existing "sqlar" table before beginning.  The "insert" command
         5810  +** always overwrites every file named on the command-line, where as
         5811  +** "update" only overwrites if the size or mtime or mode has changed.
  5789   5812   */
  5790   5813   static int arCreateOrUpdateCommand(
  5791   5814     ArCommand *pAr,                 /* Command arguments and options */
  5792         -  int bUpdate                     /* true for a --create.  false for --update */
         5815  +  int bUpdate,                    /* true for a --create. */
         5816  +  int bOnlyIfChanged              /* Only update if file has changed */
  5793   5817   ){
  5794   5818     const char *zCreate = 
  5795   5819         "CREATE TABLE IF NOT EXISTS sqlar(\n"
  5796   5820         "  name TEXT PRIMARY KEY,  -- name of the file\n"
  5797   5821         "  mode INT,               -- access permissions\n"
  5798   5822         "  mtime INT,              -- last modification time\n"
  5799   5823         "  sz INT,                 -- original file size\n"
................................................................................
  5807   5831        "    mode,\n"
  5808   5832        "    mtime,\n"
  5809   5833        "    CASE substr(lsmode(mode),1,1)\n"
  5810   5834        "      WHEN '-' THEN length(data)\n"
  5811   5835        "      WHEN 'd' THEN 0\n"
  5812   5836        "      ELSE -1 END,\n"
  5813   5837        "    sqlar_compress(data)\n"
  5814         -     "  FROM fsdir(%Q,%Q)\n"
  5815         -     "  WHERE lsmode(mode) NOT LIKE '?%%';",
         5838  +     "  FROM fsdir(%Q,%Q) AS disk\n"
         5839  +     "  WHERE lsmode(mode) NOT LIKE '?%%'%s;"
         5840  +     ,
  5816   5841        "REPLACE INTO %s(name,mode,mtime,data)\n"
  5817   5842        "  SELECT\n"
  5818   5843        "    %s,\n"
  5819   5844        "    mode,\n"
  5820   5845        "    mtime,\n"
  5821   5846        "    data\n"
  5822         -     "  FROM fsdir(%Q,%Q)\n"
  5823         -     "  WHERE lsmode(mode) NOT LIKE '?%%';"
         5847  +     "  FROM fsdir(%Q,%Q) AS disk\n"
         5848  +     "  WHERE lsmode(mode) NOT LIKE '?%%'%s;"
  5824   5849     };
  5825   5850     int i;                          /* For iterating through azFile[] */
  5826   5851     int rc;                         /* Return code */
  5827   5852     const char *zTab = 0;           /* SQL table into which to insert */
  5828   5853     char *zSql;
  5829   5854     char zTemp[50];
         5855  +  char *zExists = 0;
  5830   5856   
  5831   5857     arExecSql(pAr, "PRAGMA page_size=512");
  5832   5858     rc = arExecSql(pAr, "SAVEPOINT ar;");
  5833   5859     if( rc!=SQLITE_OK ) return rc;
  5834   5860     zTemp[0] = 0; 
  5835   5861     if( pAr->bZip ){
  5836   5862       /* Initialize the zipfile virtual table, if necessary */
................................................................................
  5853   5879       zTab = "sqlar";
  5854   5880       if( bUpdate==0 ){
  5855   5881         rc = arExecSql(pAr, zDrop);
  5856   5882         if( rc!=SQLITE_OK ) goto end_ar_transaction;
  5857   5883       }
  5858   5884       rc = arExecSql(pAr, zCreate);
  5859   5885     }
         5886  +  if( bOnlyIfChanged ){
         5887  +    zExists = sqlite3_mprintf(
         5888  +      " AND NOT EXISTS("
         5889  +          "SELECT 1 FROM %s AS mem"
         5890  +          " WHERE mem.name=disk.name"
         5891  +          " AND mem.mtime=disk.mtime"
         5892  +          " AND mem.mode=disk.mode)", zTab);
         5893  +  }else{
         5894  +    zExists = sqlite3_mprintf("");
         5895  +  }
         5896  +  if( zExists==0 ) rc = SQLITE_NOMEM;
  5860   5897     for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){
  5861   5898       char *zSql2 = sqlite3_mprintf(zInsertFmt[pAr->bZip], zTab,
  5862   5899           pAr->bVerbose ? "shell_putsnl(name)" : "name",
  5863         -        pAr->azArg[i], pAr->zDir);
         5900  +        pAr->azArg[i], pAr->zDir, zExists);
  5864   5901       rc = arExecSql(pAr, zSql2);
  5865   5902       sqlite3_free(zSql2);
  5866   5903     }
  5867   5904   end_ar_transaction:
  5868   5905     if( rc!=SQLITE_OK ){
  5869   5906       sqlite3_exec(pAr->db, "ROLLBACK TO ar; RELEASE ar;", 0, 0, 0);
  5870   5907     }else{
................................................................................
  5871   5908       rc = arExecSql(pAr, "RELEASE ar;");
  5872   5909       if( pAr->bZip && pAr->zFile ){
  5873   5910         zSql = sqlite3_mprintf("DROP TABLE %s", zTemp);
  5874   5911         arExecSql(pAr, zSql);
  5875   5912         sqlite3_free(zSql);
  5876   5913       }
  5877   5914     }
         5915  +  sqlite3_free(zExists);
  5878   5916     return rc;
  5879   5917   }
  5880   5918   
  5881   5919   /*
  5882   5920   ** Implementation of ".ar" dot command.
  5883   5921   */
  5884   5922   static int arDotCommand(
................................................................................
  5909   5947             cmd.zSrcTable = sqlite3_mprintf("zipfile(%Q)", cmd.zFile);
  5910   5948           }
  5911   5949         }
  5912   5950         cmd.bZip = 1;
  5913   5951       }else if( cmd.zFile ){
  5914   5952         int flags;
  5915   5953         if( cmd.bAppend ) eDbType = SHELL_OPEN_APPENDVFS;
  5916         -      if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_UPDATE ){
         5954  +      if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_INSERT 
         5955  +           || cmd.eCmd==AR_CMD_UPDATE ){
  5917   5956           flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
  5918   5957         }else{
  5919   5958           flags = SQLITE_OPEN_READONLY;
  5920   5959         }
  5921   5960         cmd.db = 0;
  5922   5961         if( cmd.bDryRun ){
  5923   5962           utf8_printf(pState->out, "-- open database '%s'%s\n", cmd.zFile,
................................................................................
  5946   5985           goto end_ar_command;
  5947   5986         }
  5948   5987         cmd.zSrcTable = sqlite3_mprintf("sqlar");
  5949   5988       }
  5950   5989   
  5951   5990       switch( cmd.eCmd ){
  5952   5991         case AR_CMD_CREATE:
  5953         -        rc = arCreateOrUpdateCommand(&cmd, 0);
         5992  +        rc = arCreateOrUpdateCommand(&cmd, 0, 0);
  5954   5993           break;
  5955   5994   
  5956   5995         case AR_CMD_EXTRACT:
  5957   5996           rc = arExtractCommand(&cmd);
  5958   5997           break;
  5959   5998   
  5960   5999         case AR_CMD_LIST:
................................................................................
  5961   6000           rc = arListCommand(&cmd);
  5962   6001           break;
  5963   6002   
  5964   6003         case AR_CMD_HELP:
  5965   6004           arUsage(pState->out);
  5966   6005           break;
  5967   6006   
         6007  +      case AR_CMD_INSERT:
         6008  +        rc = arCreateOrUpdateCommand(&cmd, 1, 0);
         6009  +        break;
         6010  +
  5968   6011         default:
  5969   6012           assert( cmd.eCmd==AR_CMD_UPDATE );
  5970         -        rc = arCreateOrUpdateCommand(&cmd, 1);
         6013  +        rc = arCreateOrUpdateCommand(&cmd, 1, 1);
  5971   6014           break;
  5972   6015       }
  5973   6016     }
  5974   6017   end_ar_command:
  5975   6018     if( cmd.db!=pState->db ){
  5976   6019       close_db(cmd.db);
  5977   6020     }
................................................................................
  7096   7139       open_db(p,0);
  7097   7140       if( nArg<=1 ) goto parameter_syntax_error;
  7098   7141   
  7099   7142       /* .parameter clear
  7100   7143       ** Clear all bind parameters by dropping the TEMP table that holds them.
  7101   7144       */
  7102   7145       if( nArg==2 && strcmp(azArg[1],"clear")==0 ){
  7103         -      sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp.[" BIND_PARAM_TABLE "];",
         7146  +      int wrSchema = 0;
         7147  +      sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
         7148  +      sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
         7149  +      sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp.sqlite_parameters;",
  7104   7150                      0, 0, 0);
         7151  +      sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
  7105   7152       }else
  7106   7153   
  7107   7154       /* .parameter list
  7108   7155       ** List all bind parameters.
  7109   7156       */
  7110   7157       if( nArg==2 && strcmp(azArg[1],"list")==0 ){
  7111   7158         sqlite3_stmt *pStmt = 0;
  7112   7159         int rx;
  7113   7160         int len = 0;
  7114   7161         rx = sqlite3_prepare_v2(p->db,
  7115   7162                "SELECT max(length(key)) "
  7116         -             "FROM temp.[" BIND_PARAM_TABLE "];", -1, &pStmt, 0);
         7163  +             "FROM temp.sqlite_parameters;", -1, &pStmt, 0);
  7117   7164         if( rx==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
  7118   7165           len = sqlite3_column_int(pStmt, 0);
  7119   7166           if( len>40 ) len = 40;
  7120   7167         }
  7121   7168         sqlite3_finalize(pStmt);
  7122   7169         pStmt = 0;
  7123   7170         if( len ){
  7124   7171           rx = sqlite3_prepare_v2(p->db,
  7125   7172                "SELECT key, quote(value) "
  7126         -             "FROM temp.[" BIND_PARAM_TABLE "];", -1, &pStmt, 0);
         7173  +             "FROM temp.sqlite_parameters;", -1, &pStmt, 0);
  7127   7174           while( sqlite3_step(pStmt)==SQLITE_ROW ){
  7128   7175             utf8_printf(p->out, "%-*s %s\n", len, sqlite3_column_text(pStmt,0),
  7129   7176                         sqlite3_column_text(pStmt,1));
  7130   7177           }
  7131   7178           sqlite3_finalize(pStmt);
  7132   7179         }
  7133   7180       }else
................................................................................
  7150   7197         int rx;
  7151   7198         char *zSql;
  7152   7199         sqlite3_stmt *pStmt;
  7153   7200         const char *zKey = azArg[2];
  7154   7201         const char *zValue = azArg[3];
  7155   7202         bind_table_init(p);
  7156   7203         zSql = sqlite3_mprintf(
  7157         -                  "REPLACE INTO temp.[" BIND_PARAM_TABLE "](key,value)"
         7204  +                  "REPLACE INTO temp.sqlite_parameters(key,value)"
  7158   7205                     "VALUES(%Q,%s);", zKey, zValue);
  7159   7206         if( zSql==0 ) shell_out_of_memory();
  7160   7207         pStmt = 0;
  7161   7208         rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
  7162   7209         sqlite3_free(zSql);
  7163   7210         if( rx!=SQLITE_OK ){
  7164   7211           sqlite3_finalize(pStmt);
  7165   7212           pStmt = 0;
  7166   7213           zSql = sqlite3_mprintf(
  7167         -                   "REPLACE INTO temp.[" BIND_PARAM_TABLE "](key,value)"
         7214  +                   "REPLACE INTO temp.sqlite_parameters(key,value)"
  7168   7215                      "VALUES(%Q,%Q);", zKey, zValue);
  7169   7216           if( zSql==0 ) shell_out_of_memory();
  7170   7217           rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
  7171   7218           sqlite3_free(zSql);
  7172   7219           if( rx!=SQLITE_OK ){
  7173   7220             utf8_printf(p->out, "Error: %s\n", sqlite3_errmsg(p->db));
  7174   7221             sqlite3_finalize(pStmt);
................................................................................
  7182   7229   
  7183   7230       /* .parameter unset NAME
  7184   7231       ** Remove the NAME binding from the parameter binding table, if it
  7185   7232       ** exists.
  7186   7233       */
  7187   7234       if( nArg==3 && strcmp(azArg[1],"unset")==0 ){
  7188   7235         char *zSql = sqlite3_mprintf(
  7189         -          "DELETE FROM temp.[" BIND_PARAM_TABLE "] WHERE key=%Q", azArg[2]);
         7236  +          "DELETE FROM temp.sqlite_parameters WHERE key=%Q", azArg[2]);
  7190   7237         if( zSql==0 ) shell_out_of_memory();
  7191   7238         sqlite3_exec(p->db, zSql, 0, 0, 0);
  7192   7239         sqlite3_free(zSql);
  7193   7240       }else
  7194   7241       /* If no command name matches, show a syntax error */
  7195   7242       parameter_syntax_error:
  7196   7243       showHelp(p->out, "parameter");

Changes to src/sqlite.h.in.

  2195   2195   ** features include but are not limited to the following:
  2196   2196   ** <ul>
  2197   2197   ** <li> The [PRAGMA writable_schema=ON] statement.
  2198   2198   ** <li> Writes to the [sqlite_dbpage] virtual table.
  2199   2199   ** <li> Direct writes to [shadow tables].
  2200   2200   ** </ul>
  2201   2201   ** </dd>
         2202  +**
         2203  +** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt>
         2204  +** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the
         2205  +** "writable_schema" flag. This has the same effect and is logically equivalent
         2206  +** to setting [PRAGMA writable_schema=ON] or [PRAGMA writable_schema=OFF].
         2207  +** The first argument to this setting is an integer which is 0 to disable 
         2208  +** the writable_schema, positive to enable writable_schema, or negative to
         2209  +** leave the setting unchanged. The second parameter is a pointer to an
         2210  +** integer into which is written 0 or 1 to indicate whether the writable_schema
         2211  +** is enabled or disabled following this call.
         2212  +** </dd>
  2202   2213   ** </dl>
  2203   2214   */
  2204   2215   #define SQLITE_DBCONFIG_MAINDBNAME            1000 /* const char* */
  2205   2216   #define SQLITE_DBCONFIG_LOOKASIDE             1001 /* void* int int */
  2206   2217   #define SQLITE_DBCONFIG_ENABLE_FKEY           1002 /* int int* */
  2207   2218   #define SQLITE_DBCONFIG_ENABLE_TRIGGER        1003 /* int int* */
  2208   2219   #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
  2209   2220   #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
  2210   2221   #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE      1006 /* int int* */
  2211   2222   #define SQLITE_DBCONFIG_ENABLE_QPSG           1007 /* int int* */
  2212   2223   #define SQLITE_DBCONFIG_TRIGGER_EQP           1008 /* int int* */
  2213   2224   #define SQLITE_DBCONFIG_RESET_DATABASE        1009 /* int int* */
  2214   2225   #define SQLITE_DBCONFIG_DEFENSIVE             1010 /* int int* */
  2215         -#define SQLITE_DBCONFIG_MAX                   1010 /* Largest DBCONFIG */
         2226  +#define SQLITE_DBCONFIG_WRITABLE_SCHEMA       1011 /* int int* */
         2227  +#define SQLITE_DBCONFIG_MAX                   1011 /* Largest DBCONFIG */
  2216   2228   
  2217   2229   /*
  2218   2230   ** CAPI3REF: Enable Or Disable Extended Result Codes
  2219   2231   ** METHOD: sqlite3
  2220   2232   **
  2221   2233   ** ^The sqlite3_extended_result_codes() routine enables or disables the
  2222   2234   ** [extended result codes] feature of SQLite. ^The extended result
................................................................................
  4041   4053   ** the value of the fourth parameter then the resulting string value will
  4042   4054   ** contain embedded NULs.  The result of expressions involving strings
  4043   4055   ** with embedded NULs is undefined.
  4044   4056   **
  4045   4057   ** ^The fifth argument to the BLOB and string binding interfaces
  4046   4058   ** is a destructor used to dispose of the BLOB or
  4047   4059   ** string after SQLite has finished with it.  ^The destructor is called
  4048         -** to dispose of the BLOB or string even if the call to bind API fails.
         4060  +** to dispose of the BLOB or string even if the call to the bind API fails,
         4061  +** except the destructor is not called if the third parameter is a NULL
         4062  +** pointer or the fourth parameter is negative.
  4049   4063   ** ^If the fifth argument is
  4050   4064   ** the special value [SQLITE_STATIC], then SQLite assumes that the
  4051   4065   ** information is in static, unmanaged space and does not need to be freed.
  4052   4066   ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
  4053   4067   ** SQLite makes its own private copy of the data immediately, before
  4054   4068   ** the sqlite3_bind_*() routine returns.
  4055   4069   **
................................................................................
  5799   5813   ** CAPI3REF: Return The Filename For A Database Connection
  5800   5814   ** METHOD: sqlite3
  5801   5815   **
  5802   5816   ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
  5803   5817   ** associated with database N of connection D.  ^The main database file
  5804   5818   ** has the name "main".  If there is no attached database N on the database
  5805   5819   ** connection D, or if database N is a temporary or in-memory database, then
  5806         -** a NULL pointer is returned.
         5820  +** this function will return either a NULL pointer or an empty string.
  5807   5821   **
  5808   5822   ** ^The filename returned by this function is the output of the
  5809   5823   ** xFullPathname method of the [VFS].  ^In other words, the filename
  5810   5824   ** will be an absolute pathname, even if the filename used
  5811   5825   ** to open the database originally was a URI or relative pathname.
  5812   5826   */
  5813   5827   const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);

Changes to src/test_fs.c.

   233    233   ** Skip the cursor to the next entry.
   234    234   */
   235    235   static int fsdirNext(sqlite3_vtab_cursor *cur){
   236    236     FsdirCsr *pCsr = (FsdirCsr*)cur;
   237    237   
   238    238     if( pCsr->pDir ){
   239    239       struct DIRENT *pRes = 0;
   240         -#if defined(__MINGW_H)
   241    240       pRes = readdir(pCsr->pDir);
   242    241       if( pRes!=0 ){
   243    242         memcpy(&pCsr->entry, pRes, sizeof(struct DIRENT));
   244    243       }
   245         -#else
   246         -    readdir_r(pCsr->pDir, &pCsr->entry, &pRes);
   247         -#endif
   248    244       if( pRes==0 ){
   249    245         closedir(pCsr->pDir);
   250    246         pCsr->pDir = 0;
   251    247       }
   252    248       pCsr->iRowid++;
   253    249     }
   254    250   

Changes to src/vacuum.c.

   139    139   /*
   140    140   ** This routine implements the OP_Vacuum opcode of the VDBE.
   141    141   */
   142    142   int sqlite3RunVacuum(
   143    143     char **pzErrMsg,        /* Write error message here */
   144    144     sqlite3 *db,            /* Database connection */
   145    145     int iDb,                /* Which attached DB to vacuum */
   146         -  sqlite3_value *pOut     /* Write results here, if not NULL */
          146  +  sqlite3_value *pOut     /* Write results here, if not NULL. VACUUM INTO */
   147    147   ){
   148    148     int rc = SQLITE_OK;     /* Return code from service routines */
   149    149     Btree *pMain;           /* The database being vacuumed */
   150    150     Btree *pTemp;           /* The temporary database we vacuum into */
   151    151     u32 saved_mDbFlags;     /* Saved value of db->mDbFlags */
   152    152     u64 saved_flags;        /* Saved value of db->flags */
   153    153     int saved_nChange;      /* Saved value of db->nChange */
   154    154     int saved_nTotalChange; /* Saved value of db->nTotalChange */
          155  +  u32 saved_openFlags;    /* Saved value of db->openFlags */
   155    156     u8 saved_mTrace;        /* Saved trace settings */
   156    157     Db *pDb = 0;            /* Database to detach at end of vacuum */
   157    158     int isMemDb;            /* True if vacuuming a :memory: database */
   158    159     int nRes;               /* Bytes of reserved space at the end of each page */
   159    160     int nDb;                /* Number of attached databases */
   160    161     const char *zDbMain;    /* Schema name of database to vacuum */
   161    162     const char *zOut;       /* Name of output file */
................................................................................
   164    165       sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
   165    166       return SQLITE_ERROR;
   166    167     }
   167    168     if( db->nVdbeActive>1 ){
   168    169       sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
   169    170       return SQLITE_ERROR;
   170    171     }
          172  +  saved_openFlags = db->openFlags;
   171    173     if( pOut ){
   172    174       if( sqlite3_value_type(pOut)!=SQLITE_TEXT ){
   173    175         sqlite3SetString(pzErrMsg, db, "non-text filename");
   174    176         return SQLITE_ERROR;
   175    177       }
   176    178       zOut = (const char*)sqlite3_value_text(pOut);
          179  +    db->openFlags &= ~SQLITE_OPEN_READONLY;
          180  +    db->openFlags |= SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE;
   177    181     }else{
   178    182       zOut = "";
   179    183     }
   180    184   
   181    185     /* Save the current value of the database flags so that it can be 
   182    186     ** restored before returning. Then set the writable-schema flag, and
   183    187     ** disable CHECK and foreign key constraints.  */
................................................................................
   208    212     ** actually occurs when doing a vacuum since the vacuum_db is initially
   209    213     ** empty.  Only the journal header is written.  Apparently it takes more
   210    214     ** time to parse and run the PRAGMA to turn journalling off than it does
   211    215     ** to write the journal header file.
   212    216     */
   213    217     nDb = db->nDb;
   214    218     rc = execSqlF(db, pzErrMsg, "ATTACH %Q AS vacuum_db", zOut);
          219  +  db->openFlags = saved_openFlags;
   215    220     if( rc!=SQLITE_OK ) goto end_of_vacuum;
   216    221     assert( (db->nDb-1)==nDb );
   217    222     pDb = &db->aDb[nDb];
   218    223     assert( strcmp(pDb->zDbSName,"vacuum_db")==0 );
   219    224     pTemp = pDb->pBt;
   220    225     if( pOut ){
   221    226       sqlite3_file *id = sqlite3PagerFile(sqlite3BtreePager(pTemp));

Changes to src/vdbeaux.c.

   633    633     memset(&sIter, 0, sizeof(sIter));
   634    634     sIter.v = v;
   635    635   
   636    636     while( (pOp = opIterNext(&sIter))!=0 ){
   637    637       int opcode = pOp->opcode;
   638    638       if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename 
   639    639        || opcode==OP_VDestroy
          640  +     || (opcode==OP_Function0 && pOp->p4.pFunc->funcFlags&SQLITE_FUNC_INTERNAL)
   640    641        || ((opcode==OP_Halt || opcode==OP_HaltIfNull) 
   641    642         && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
   642    643       ){
   643    644         hasAbort = 1;
   644    645         break;
   645    646       }
   646    647       if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1;

Changes to src/wherecode.c.

  1156   1156       sqlite3WalkExpr(&w, pWInfo->pWhere);
  1157   1157       sqlite3WalkExprList(&w, pWInfo->pOrderBy);
  1158   1158       sqlite3WalkExprList(&w, pWInfo->pResultSet);
  1159   1159     }
  1160   1160   }
  1161   1161   
  1162   1162   /*
  1163         -** The pTruth expression is always tree because it is the WHERE clause
         1163  +** The pTruth expression is always true because it is the WHERE clause
  1164   1164   ** a partial index that is driving a query loop.  Look through all of the
  1165   1165   ** WHERE clause terms on the query, and if any of those terms must be
  1166   1166   ** true because pTruth is true, then mark those WHERE clause terms as
  1167   1167   ** coded.
  1168   1168   */
  1169   1169   static void whereApplyPartialIndexConstraints(
  1170   1170     Expr *pTruth,

Changes to src/whereexpr.c.

  1516   1516       assert( p->x.pList==0 );
  1517   1517     }else if( ExprHasProperty(p, EP_xIsSelect) ){
  1518   1518       if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1;
  1519   1519       mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
  1520   1520     }else if( p->x.pList ){
  1521   1521       mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
  1522   1522     }
         1523  +#ifndef SQLITE_OMIT_WINDOWFUNC
         1524  +  if( p->op==TK_FUNCTION && p->y.pWin ){
         1525  +    mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition);
         1526  +    mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy);
         1527  +  }
         1528  +#endif
  1523   1529     return mask;
  1524   1530   }
  1525   1531   Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
  1526   1532     return p ? sqlite3WhereExprUsageNN(pMaskSet,p) : 0;
  1527   1533   }
  1528   1534   Bitmask sqlite3WhereExprListUsage(WhereMaskSet *pMaskSet, ExprList *pList){
  1529   1535     int i;

Changes to test/altertab3.test.

    77     77     ALTER TABLE t1 RENAME b TO bbb;
    78     78   }
    79     79   
    80     80   do_execsql_test 3.2 {
    81     81     SELECT sql FROM sqlite_master WHERE name = 'v1'
    82     82   } {{CREATE VIEW v1 AS SELECT * FROM t1 WHERE a=1 OR (bbb IN ())}}
    83     83   
           84  +#-------------------------------------------------------------------------
           85  +reset_db
           86  +do_execsql_test 4.0 {
           87  +  CREATE TABLE t1(a, b);
           88  +  CREATE TABLE t3(e, f);
           89  +  CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
           90  +    INSERT INTO t2 VALUES(new.a, new.b);
           91  +  END;
           92  +}
           93  +
           94  +do_catchsql_test 4.1.2 {
           95  +  BEGIN;
           96  +    ALTER TABLE t3 RENAME TO t4;
           97  +} {1 {error in trigger tr1: no such table: main.t2}}
           98  +do_execsql_test 4.1.2 {
           99  +  COMMIT;
          100  +}
          101  +do_execsql_test 4.1.3 {
          102  +  SELECT * FROM sqlite_master WHERE type='table' AND name!='t1';
          103  +} {table t3 t3 3 {CREATE TABLE t3(e, f)}}
          104  +
          105  +
          106  +do_catchsql_test 4.2.1 {
          107  +  BEGIN;
          108  +    ALTER TABLE t3 RENAME e TO eee;
          109  +} {1 {error in trigger tr1: no such table: main.t2}}
          110  +do_execsql_test 4.2.2 {
          111  +  COMMIT;
          112  +}
          113  +do_execsql_test 4.2.3 {
          114  +  SELECT * FROM sqlite_master WHERE type='table' AND name!='t1';
          115  +} {table t3 t3 3 {CREATE TABLE t3(e, f)}}
          116  +
          117  +#-------------------------------------------------------------------------
          118  +reset_db
          119  +do_execsql_test 5.0 {
          120  +  CREATE TABLE t1 (
          121  +      c1 integer, c2, PRIMARY KEY(c1 collate rtrim),
          122  +      UNIQUE(c2)
          123  +  )
          124  +}
          125  +do_execsql_test 5.1 {
          126  +  ALTER TABLE t1 RENAME c1 TO c3;
          127  +}
          128  +
          129  +#-------------------------------------------------------------------------
          130  +reset_db
          131  +do_execsql_test 6.0 {
          132  +  CREATE TEMPORARY TABLE Table0 (
          133  +    Col0 INTEGER, 
          134  +    PRIMARY KEY(Col0 COLLATE RTRIM), 
          135  +    FOREIGN KEY (Col0) REFERENCES Table0
          136  +  );
          137  +}
    84    138   
          139  +do_execsql_test 6.1 {
          140  +  ALTER TABLE Table0 RENAME Col0 TO Col0;
          141  +}
    85    142   
    86    143   finish_test
    87    144   
    88    145   

Changes to test/corruptL.test.

   119    119   |   2512: 00 00 00 00 00 00 00 00 aa 00 00 00 00 00 00 00   ................
   120    120   | end crash-acaae0347204ae.db
   121    121   }]} {}
   122    122   
   123    123   do_catchsql_test 1.1 {
   124    124     PRAGMA cell_size_check = off;
   125    125     DROP INDEX t1x1;
   126         -} {1 {no such index: t1x1}}
          126  +} {1 {database disk image is malformed}}
   127    127   
   128    128   do_catchsql_test 1.2 {
   129    129     SELECT sum(s+length(b)) FROM t1 WHERE a IN (110,10,150) AND q IS NULL;
   130         -} {1 {no such table: t1}}
          130  +} {1 {database disk image is malformed}}
   131    131   
   132    132   do_catchsql_test 1.3 {
   133    133     REINDEX t1;
   134         -} {1 {unable to identify the object to be reindexed}}
          134  +} {1 {database disk image is malformed}}
          135  +
          136  +do_catchsql_test 1.4 {
          137  +  PRAGMA integrity_check
          138  +} {1 {database disk image is malformed}}
          139  +
   135    140   
   136    141   #-------------------------------------------------------------------------
   137    142   reset_db
   138    143   do_test 2.0 {
   139    144     sqlite3 db {}
   140    145     db deserialize [decode_hexdb {
   141    146   | size 20480 pagesize 4096 filename crash.txt.db
................................................................................
   717    722   |      0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00   ................
   718    723   | end crash-8391315d75edff.db
   719    724   }]} {}
   720    725   
   721    726   do_catchsql_test 7.1 {
   722    727     SELECT * FROM sqlite_master;
   723    728   } {1 {malformed database schema (t1x1) - invalid rootpage}}
          729  +
          730  +#-------------------------------------------------------------------------
          731  +reset_db
          732  +do_test 8.0 {
          733  +  sqlite3 db {}
          734  +  db deserialize [decode_hexdb {
          735  +| size 2048 pagesize 512 filename a.db
          736  +| page 1 offset 0
          737  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          738  +|     16: 02 00 01 01 00 40 20 20 ff ff 00 0c 00 00 00 07   .....@  ........
          739  +|     32: 0b 00 00 00 00 00 00 00 00 00 00 08 9c 00 00 04   ................
          740  +|     48: 00 00 00 e0 09 00 00 01 00 00 00 01 00 00 00 00   ................
          741  +|     64: 00 00 00 00 f2 ff 00 00 00 00 00 00 00 00 00 00   ................
          742  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c   ................
          743  +|     96: 00 2e 2c 50 0d 00 00 00 06 01 06 00 01 da 01 b0   ..,P............
          744  +|    112: 05 56 01 86 01 2a 01 06 00 00 00 00 00 06 00 00   .V...*..........
          745  +|    128: 00 ff 00 00 ff ff ff e1 00 00 00 00 00 00 00 00   ................
          746  +|    144: 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00   ................
          747  +|    160: 00 00 00 00 00 00 00 00 f2 00 00 00 00 00 00 00   ................
          748  +|    176: 00 00 f9 ff ff ff ff ff ff ff 00 00 00 5f 00 fb   ............._..
          749  +|    192: 00 00 00 00 00 00 00 00 00 e1 ff 00 00 00 00 00   ................
          750  +|    208: 00 00 10 00 00 00 00 00 1e 00 00 00 fe 00 00 00   ................
          751  +|    224: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ca 00   ................
          752  +|    240: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 35   ...............5
          753  +|    256: 00 00 00 00 ef ff 22 07 06 17 11 11 01 30 39 38   .............098
          754  +|    272: 62 6c 65 74 38 38 74 04 43 52 45 41 54 45 20 54   blet88t.CREATE T
          755  +|    288: 41 42 4c 45 20 74 34 28 87 29 2a 06 06 17 13 11   ABLE t4(.)*.....
          756  +|    304: 01 3f 69 4f 64 65 78 74 33 78 74 40 05 43 52 45   .?iOdext3xt@.CRE
          757  +|    320: 41 54 45 20 49 6e 44 45 58 20 74 33 78 20 4f 4e   ATE InDEX t3x ON
          758  +|    336: 20 74 33 28 78 29 2e 04 06 17 15 11 01 45 69 6e    t3(x).......Ein
          759  +|    352: 00 04 00 00 34 63 64 74 3d 05 43 52 45 41 54 45   ....4cdt=.CREATE
          760  +|    368: 20 49 4e 44 45 58 20 63 74 64 32 20 4f 4e 20 74    INDEX ctd2 ON t
          761  +|    384: 32 28 0a 0c 44 29 28 05 06 17 11 11 01 3d 74 6c   2(..D)(......=tl
          762  +|    400: 62 61 d4 65 33 74 33 04 43 52 45 41 54 45 20 54   ba.e3t3.CREATE T
          763  +|    416: 41 42 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29   ABLE t3(c,x,e,f)
          764  +|    432: 28 02 06 17 11 11 01 3d 74 61 62 6c 65 74 32 74   (......=tablet2t
          765  +|    448: 32 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74   2.CREATE TABLE t
          766  +|    464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11   2(c,d,e,f)$.....
          767  +|    480: 01 35 74 60 62 6c 65 74 31 74 31 02 43 52 45 41   .5t`blet1t1.CREA
          768  +|    496: 54 45 20 54 41 42 4c 45 20 74 30 28 61 2c 62 29   TE TABLE t0(a,b)
          769  +| page 2 offset 512
          770  +|      0: 0d 00 ff 11 04 01 cf 80 01 fa 01 09 00 de 01 cf   ................
          771  +|     16: 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00   ................
          772  +|     32: 00 00 08 00 00 00 00 00 00 11 00 00 00 00 00 13   ................
          773  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 e0 ff ff   ................
          774  +|     64: ff d2 ff ff ff 00 f8 ff ff ff 00 00 00 00 00 00   ................
          775  +|     80: 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
          776  +|     96: 00 00 00 00 ff de 00 00 00 00 00 00 00 00 00 00   ................
          777  +|    112: 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00 00   .............@..
          778  +|    128: 2a 00 00 00 00 00 00 00 00 f7 00 00 00 00 00 00   *...............
          779  +|    144: 00 00 00 00 00 21 00 00 00 00 00 00 00 00 00 00   .....!..........
          780  +|    160: 01 64 00 00 00 00 04 80 ff ff ff 00 00 00 00 00   .d..............
          781  +|    176: 00 00 00 00 00 00 00 00 1f 00 00 00 00 00 00 00   ................
          782  +|    192: 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00   ..@.............
          783  +|    208: b5 00 00 00 00 00 00 40 00 00 00 00 00 00 00 00   .......@........
          784  +|    224: 00 00 00 f6 00 ee ff ff ff 00 00 00 00 00 00 00   ................
          785  +|    272: f2 00 00 00 00 00 00 00 00 00 f9 ff ff ff ff ff   ................
          786  +|    288: ff ff 00 00 00 5f 00 fb 00 00 00 00 00 00 00 00   ....._..........
          787  +|    320: 1e 00 00 00 fe 00 00 00 00 00 00 00 00 00 00 00   ................
          788  +|    336: 00 00 00 00 00 00 ca 00 00 00 00 00 00 00 ff ec   ................
          789  +|    352: 00 00 00 00 00 00 00 32 00 00 00 00 ef ff 22 07   .......2........
          790  +|    368: 06 17 11 11 01 30 74 61 62 6c 65 74 38 38 74 04   .....0tablet88t.
          791  +|    384: 43 52 45 41 54 45 20 54 41 42 4c 45 20 8c cb d7   CREATE TABLE ...
          792  +|    400: 78 d6 d5 f9 f9 17 13 11 01 3f 69 4f 64 65 78 74   x........?iOdext
          793  +|    416: 33 78 74 33 05 43 52 45 41 54 45 26 49 6e 44 45   3xt3.CREATE&InDE
          794  +|    432: 58 20 74 33 78 00 00 00 00 00 00 00 00 00 00 00   X t3x...........
          795  +|    464: 00 00 00 00 00 13 76 65 6e 65 69 67 68 74 13 03   ......veneight..
          796  +|    480: 03 40 07 07 15 00 54 45 20 49 4e 44 45 58 20 74   .@....TE INDEX t
          797  +|    496: 31 63 64 20 4f 4e 20 74 ce d7 f5 f0 44 09 01 02   1cd ON t....D...
          798  +| page 3 offset 1024
          799  +|      0: 0d 00 00 00 48 01 54 00 01 f6 e2 ec 01 c5 01 aa   ....H.T.........
          800  +|     16: 30 34 28 87 29 32 06 f5 16 13 11 01 8e 61 24 64   04(.)2.......a$d
          801  +|     32: 65 78 74 37 78 1f 33 6d 6d 6d 6d 6d 00 00 04 06   ext7x.3mmmmm....
          802  +|     48: 6d 41 6d 6d 6e 6d 6d 00 00 02 00 6d 6d 6d 6d 6d   mAmmnmm....mmmmm
          803  +|     64: 15 11 01 45 45 45 45 45 45 45 45 45 45 45 45 45   ...EEEEEEEEEEEEE
          804  +|     80: 45 45 45 45 45 45 45 45 45 45 45 00 45 63 74 64   EEEEEEEEEEE.Ectd
          805  +|     96: 34 20 4f 4e 20 61 62 6c 5d 74 38 38 74 04 43 52   4 ON abl]t88t.CR
          806  +|    112: 45 41 54 45 20 54 41 42 4c 45 20 74 34 28 87 29   EATE TABLE t4(.)
          807  +|    128: 2a 06 06 13 13 01 00 00 00 4f 64 6e 78 74 33 44   *........Odnxt3D
          808  +|    144: 74 13 05 43 52 45 41 54 45 20 49 6e 44 45 00 00   t..CREATE InDE..
          809  +|    160: 00 00 00 00 00 00 00 f9 ff ff ff ff ff ff ff 00   ................
          810  +|    176: 00 00 5f 00 fb 00 00 2d 00 00 00 00 00 00 00 00   .._....-........
          811  +|    192: 00 00 00 00 00 00 00 00 00 00 00 00 00 1e 00 00   ................
          812  +|    208: 00 fe 00 00 00 00 17 15 11 01 45 69 6e 64 65 2e   ..........Einde.
          813  +|    224: 5b 38 63 64 74 3d 05 43 52 45 41 54 45 20 49 4e   [8cdt=.CREATE IN
          814  +|    240: 44 45 58 20 63 20 64 32 20 4f 4e 20 74 32 28 0a   DEX c d2 ON t2(.
          815  +|    256: 0c 44 32 05 00 10 00 00 11 11 3d 74 6c 62 61 d4   .D2.......=tlba.
          816  +|    272: 65 33 74 33 04 43 52 45 41 54 45 20 54 41 42 4c   e3t3.CREATE TABL
          817  +|    288: 45 20 74 36 ff ff 7f ff 43 52 45 41 54 45 20 49   E t6....CREATE I
          818  +|    304: 73 71 6c 69 74 65 5f 73 65 71 75 65 6e 63 65 28   sqlite_sequence(
          819  +|    320: 0a 0c 44 29 28 05 06 17 11 11 01 3d 74 6c 62 61   ..D)(......=tlba
          820  +|    336: 20 00 00 00 33 04 43 52 45 41 54 45 20 54 41 42    ...3.CREATE TAB
          821  +|    352: 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29 28 02   LE t3(c,x,e,f)(.
          822  +|    368: 06 00 00 7f ff 40 41 54 45 20 49 6e 44 45 58 20   .....@ATE InDEX 
          823  +|    384: 74 33 78 20 4f 4e 20 74 31 28 78 29 2e 04 06 17   t3x ON t1(x)....
          824  +|    400: 15 11 01 45 69 6e 64 65 2e 74 34 63 64 74 3d 05   ...Einde.t4cdt=.
          825  +|    416: 00 00 00 00 00 00 00 00 00 00 00 4d 00 00 00 00   ...........M....
          826  +|    432: 01 00 00 00 00 00 00 05 00 00 10 00 00 00 00 00   ................
          827  +|    448: 00 01 00 00 00 00 01 00 00 00 00 07 40 14 00 00   ............@...
          828  +|    464: 00 00 21 00 40 18 00 00 00 00 00 00 40 1c 00 00   ..!.@.......@...
          829  +|    480: 00 00 ff ff ff 00 00 00 5f 00 fb 00 00 2d 00 00   ........_....-..
          830  +|    496: 00 00 00 1e 00 00 00 fe 00 00 64 00 00 ff fb 02   ..........d.....
          831  +| page 4 offset 1536
          832  +|      0: 0d 00 39 00 00 02 00 00 00 00 00 00 00 00 00 00   ..9.............
          833  +| end a.db
          834  +}]} {}
          835  +
          836  +
          837  +do_catchsql_test 8.1 {
          838  +  INSERT INTO t3 SELECT * FROM t2;
          839  +} {1 {database disk image is malformed}}
   724    840   
   725    841   finish_test

Changes to test/dbfuzz2.c.

    70     70   
    71     71   /* True to activate PRAGMA vdbe_debug=on */
    72     72   static int bVdbeDebug = 0;
    73     73   
    74     74   /* Maximum size of the in-memory database file */
    75     75   static sqlite3_int64 szMax = 104857600;
    76     76   
           77  +/* Progress handler callback data */
           78  +static int nCb = 0;                  /* Number of callbacks seen so far */
           79  +static int mxCb = 250000;            /* Maximum allowed callbacks */
           80  +
    77     81   /***** Copy/paste from ext/misc/memtrace.c ***************************/
    78     82   /* The original memory allocation routines */
    79     83   static sqlite3_mem_methods memtraceBase;
    80     84   static FILE *memtraceOut;
    81     85   
    82     86   /* Methods that trace memory allocations */
    83     87   static void *memtraceMalloc(int n){
................................................................................
   152    156         memset(&memtraceBase, 0, sizeof(memtraceBase));
   153    157       }
   154    158     }
   155    159     memtraceOut = 0;
   156    160     return rc;
   157    161   }
   158    162   /***** End copy/paste from ext/misc/memtrace.c ***************************/
          163  +
          164  +/*
          165  +** Progress handler callback
          166  +**
          167  +** Count the number of callbacks and cause an abort once the limit is
          168  +** reached.
          169  +*/
          170  +static int progress_handler(void *pNotUsed){
          171  +  nCb++;
          172  +  if( nCb<mxCb ) return 0;
          173  +  if( eVerbosity>=1 ){
          174  +    printf("-- Progress limit of %d reached\n", mxCb);
          175  +  }
          176  +  return 1;
          177  +}
   159    178   
   160    179   /* libFuzzer invokes this routine with fuzzed database files (in aData).
   161    180   ** This routine run SQLite against the malformed database to see if it
   162    181   ** can provoke a failure or malfunction.
   163    182   */
   164    183   int LLVMFuzzerTestOneInput(const uint8_t *aData, size_t nByte){
   165    184     unsigned char *a;
................................................................................
   185    204     x = szMax;
   186    205   #ifdef SQLITE_FCNTL_SIZE_LIMIT
   187    206     sqlite3_file_control(db, "main", SQLITE_FCNTL_SIZE_LIMIT, &x);
   188    207   #endif
   189    208     if( bVdbeDebug ){
   190    209       sqlite3_exec(db, "PRAGMA vdbe_debug=ON", 0, 0, 0);
   191    210     }
          211  +  if( mxCb>0 ){
          212  +    sqlite3_progress_handler(db, 10, progress_handler, 0);
          213  +  }
   192    214     for(i=0; i<sizeof(azSql)/sizeof(azSql[0]); i++){
   193    215       if( eVerbosity>=1 ){
   194    216         printf("%s\n", azSql[i]);
   195    217         fflush(stdout);
   196    218       }
   197    219       zErr = 0;
          220  +    nCb = 0;
   198    221       rc = sqlite3_exec(db, azSql[i], 0, 0, &zErr);
   199    222       if( rc && eVerbosity>=1 ){
   200    223         printf("-- rc=%d zErr=%s\n", rc, zErr);
   201    224       }
   202    225       sqlite3_free(zErr);
   203    226     }
   204    227     rc = sqlite3_close(db);
................................................................................
   244    267         if( z[0]=='v' && (n = numberOfVChar(z))>0 ){
   245    268           eVerbosity += n;
   246    269           continue;
   247    270         }
   248    271         if( strcmp(z,"vdbe-debug")==0 ){
   249    272           bVdbeDebug = 1;
   250    273           continue;
          274  +      }
          275  +      if( strcmp(z,"limit")==0 ){
          276  +        if( i+1==argc ){
          277  +          fprintf(stderr, "missing argument to %s\n", argv[i]);
          278  +          exit(1);
          279  +        }
          280  +        mxCb = strtol(argv[++i], 0, 0);
          281  +        continue;
   251    282         }
   252    283         if( strcmp(z,"memtrace")==0 ){
   253    284           sqlite3MemTraceActivate(stdout);
   254    285           continue;
   255    286         }
   256    287         if( strcmp(z,"mem")==0 ){
   257    288           bVdbeDebug = 1;

Changes to test/fuzzcheck.c.

   527    527     if( nIn<4 ) return -1;
   528    528     n = (unsigned int)nIn;
   529    529     a = sqlite3_malloc64( nAlloc );
   530    530     if( a==0 ){
   531    531       fprintf(stderr, "Out of memory!\n");
   532    532       exit(1);
   533    533     }
   534         -  memset(a, 0, nAlloc);
          534  +  memset(a, 0, (size_t)nAlloc);
   535    535     for(i=k=0; i<n; i++){
   536    536       unsigned char c = (unsigned char)zIn[i];
   537    537       if( isxdigit(c) ){
   538    538         k++;
   539    539         if( k & 1 ){
   540    540           b = hexToInt(c)*16;
   541    541         }else{
................................................................................
   564    564             }
   565    565             a = sqlite3_realloc64( a, newSize );
   566    566             if( a==0 ){
   567    567               fprintf(stderr, "Out of memory!\n");
   568    568               exit(1);
   569    569             }
   570    570             assert( newSize > nAlloc );
   571         -          memset(a+nAlloc, 0, newSize - nAlloc);
          571  +          memset(a+nAlloc, 0, (size_t)(newSize - nAlloc));
   572    572             nAlloc = newSize;
   573    573           }
   574    574           if( j>=(unsigned)mx ){
   575    575             mx = (j + 4095)&~4095;
   576    576             if( mx>MX_FILE_SZ ) mx = MX_FILE_SZ;
   577    577           }
   578    578           assert( j<nAlloc );

Changes to test/fuzzdata7.db.

cannot compute difference between binary files

Changes to test/fuzzdata8.db.

cannot compute difference between binary files

Changes to test/memdb1.test.

   180    180     set rc [catch {db deserialize a b c} msg]
   181    181     lappend rc $msg
   182    182   } {1 {unknown option: a}}
   183    183   do_test 620 {
   184    184     set rc [catch {db serialize a b} msg]
   185    185     lappend rc $msg
   186    186   } {1 {wrong # args: should be "db serialize ?DATABASE?"}}
          187  +
          188  +#-------------------------------------------------------------------------
          189  +reset_db
          190  +do_execsql_test 700 {
          191  +  CREATE TABLE t1(a, b);
          192  +  PRAGMA schema_version = 0;
          193  +}
          194  +do_test 710 {
          195  +  set ser [db serialize main]
          196  +  db close
          197  +  sqlite3 db
          198  +  db deserialize main $ser
          199  +  catchsql {
          200  +    CREATE VIRTUAL TABLE t1 USING rtree(id, a, b, c, d);
          201  +  }
          202  +} {1 {table t1 already exists}}
   187    203   
   188    204   finish_test

Changes to test/sessionfuzz.c.

   826    826   static int conflictCall(
   827    827     void *NotUsed,
   828    828     int eConflict,
   829    829     sqlite3_changeset_iter *p
   830    830   ){
   831    831     (void)NotUsed;
   832    832     (void)p;
   833         -  printf("Conflict %d\n", eConflict);
   834    833     return SQLITE_CHANGESET_OMIT;
   835    834   }
   836    835   
   837    836   /*
   838    837   ** Reset the database file
   839    838   */
   840    839   static void db_reset(sqlite3 *db){

Changes to test/vacuum-into.test.

    82     82     execsql { VACUUM INTO target() }
    83     83     file exists test.db2
    84     84   } 1
    85     85   do_catchsql_test vacuum-into-420 {
    86     86     VACUUM INTO target2()
    87     87   } {1 {no such function: target2}}
    88     88   
           89  +# The ability to VACUUM INTO a read-only database
           90  +db close
           91  +sqlite3 db test.db -readonly 1
           92  +forcedelete test.db2
           93  +do_execsql_test vacuum-into-500 {
           94  +  VACUUM INTO 'test.db2';
           95  +}
           96  +sqlite3 db2 test.db2
           97  +do_test vacuum-into-510 {
           98  +  db2 eval {SELECT name FROM sqlite_master ORDER BY 1}
           99  +} {t1 t1b t2}
          100  +db2 close
          101  +db close
    89    102   
    90    103   finish_test

Changes to test/window1.test.

   715    715   } {6 6 6}
   716    716   
   717    717   do_execsql_test 17.3 {
   718    718     SELECT 10+sum(a) OVER (ORDER BY a) 
   719    719     FROM t8 
   720    720     ORDER BY 10+sum(a) OVER (ORDER BY a) DESC;
   721    721   } {16 13 11}
          722  +
          723  +#-------------------------------------------------------------------------
          724  +#
          725  +reset_db
          726  +do_execsql_test 18.0 {
          727  +  CREATE TABLE t1 ( t1_id INTEGER PRIMARY KEY );
          728  +  CREATE TABLE t2 ( t2_id INTEGER PRIMARY KEY );
          729  +  CREATE TABLE t3 ( t3_id INTEGER PRIMARY KEY );
          730  +
          731  +  INSERT INTO t1 VALUES(1),  (3), (5);
          732  +  INSERT INTO t2 VALUES      (3), (5);
          733  +  INSERT INTO t3 VALUES(10), (11), (12);
          734  +}
          735  +
          736  +do_execsql_test 18.1 {
          737  +  SELECT t1.* FROM t1, t2 WHERE 
          738  +    t1_id=t2_id AND t1_id IN (
          739  +        SELECT t1_id + row_number() OVER ( ORDER BY t1_id ) FROM t3
          740  +    )
          741  +}
          742  +
          743  +do_execsql_test 18.2 {
          744  +  SELECT t1.* FROM t1, t2 WHERE 
          745  +    t1_id=t2_id AND t1_id IN (
          746  +        SELECT         row_number() OVER ( ORDER BY t1_id ) FROM t3
          747  +    )
          748  +} {3}
   722    749   
   723    750   
   724    751   finish_test

Changes to tool/cg_anno.tcl.

     1         -#!/usr/bin/tclsh
            1  +#!/bin/sh
            2  +# \
            3  +exec tclsh "$0" ${1+"$@"}
     2      4   #
     3      5   # A wrapper around cg_annotate that sets appropriate command-line options
     4      6   # and rearranges the output so that annotated files occur in a consistent
     5      7   # sorted order.  Used by the speed-check.tcl script.
     6      8   #
     7      9   
     8     10   set in [open "|cg_annotate --show=Ir --auto=yes --context=40 $argv" r]