/ Check-in [4f922944]
Login

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

Overview
Comment:Merge in the IS-operator enhancements and other recent changes from trunk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sessions
Files: files | file ages | folders
SHA1: 4f9229445c293b39c80b2a662901f608c85b36ef
User & Date: drh 2015-05-14 15:17:20
Context
2015-05-19
22:42
Merge recent trunk changes, include the R-Tree enhancement that allows 8-byte BLOB arguments to geometry functions, and the fix for the TEXT affinity problem that could cause corrupt indexes. check-in: 0a0de8b7 user: drh tags: sessions
2015-05-14
15:17
Merge in the IS-operator enhancements and other recent changes from trunk. check-in: 4f922944 user: drh tags: sessions
14:32
The IS operator can now use indexes the same as the == operator. check-in: 3428043c user: drh tags: trunk
2015-05-07
12:29
Merge in the 3.8.10 release changes. check-in: 0404ef88 user: drh tags: sessions
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

   514    514     $(TOP)/ext/fts3/fts3_tokenizer.h
   515    515   EXTHDR += \
   516    516     $(TOP)/ext/rtree/rtree.h
   517    517   EXTHDR += \
   518    518     $(TOP)/ext/icu/sqliteicu.h
   519    519   EXTHDR += \
   520    520     $(TOP)/ext/rtree/sqlite3rtree.h
          521  +
          522  +# executables needed for testing
          523  +#
          524  +TESTPROGS = \
          525  +  testfixture$(TEXE) \
          526  +  sqlite3$(TEXE) \
          527  +  sqlite3_analyzer$(TEXE) \
          528  +  sqldiff$(TEXE)
          529  +
   521    530   
   522    531   # This is the default Makefile target.  The objects listed here
   523    532   # are what get build when you type just "make" with no arguments.
   524    533   #
   525    534   all:	sqlite3.h libsqlite3.la sqlite3$(TEXE) $(HAVE_TCL:1=libtclsqlite3.la)
   526    535   
   527    536   Makefile: $(TOP)/Makefile.in
................................................................................
   964    973   TESTFIXTURE_SRC += $(TESTFIXTURE_SRC$(USE_AMALGAMATION))
   965    974   
   966    975   testfixture$(TEXE):	$(TESTFIXTURE_SRC)
   967    976   	$(LTLINK) -DSQLITE_NO_SYNC=1 $(TEMP_STORE) $(TESTFIXTURE_FLAGS) \
   968    977   		-o $@ $(TESTFIXTURE_SRC) $(LIBTCL) $(TLIBS)
   969    978   
   970    979   # A very detailed test running most or all test cases
   971         -fulltest:	testfixture$(TEXE) sqlite3$(TEXE) fuzztest
          980  +fulltest:	$(TESTPROGS) fuzztest
   972    981   	./testfixture$(TEXE) $(TOP)/test/all.test
   973    982   
   974    983   # Really really long testing
   975         -soaktest:	testfixture$(TEXE) sqlite3$(TEXE) fuzzoomtest
          984  +soaktest:	$(TESTPROGS) fuzzoomtest
   976    985   	./testfixture$(TEXE) $(TOP)/test/all.test -soak=1
   977    986   
   978         -# Do extra testing but not aeverything.
   979         -fulltestonly:	testfixture$(TEXE) sqlite3$(TEXE)
          987  +# Do extra testing but not everything.
          988  +fulltestonly:	$(TESTPROGS)
   980    989   	./testfixture$(TEXE) $(TOP)/test/full.test
   981    990   
   982    991   # Fuzz testing
   983    992   fuzztest:	fuzzershell$(TEXE)
   984    993   	./fuzzershell$(TEXE) $(TOP)/test/fuzzdata1.txt $(TOP)/test/fuzzdata2.txt
   985    994   
   986    995   fuzzoomtest:	fuzzershell$(TEXE)
   987    996   	./fuzzershell$(TEXE) -f $(TOP)/test/fuzzdata1.txt --oom
   988    997   
   989    998   # This is the common case.  Run many tests but not those that take
   990    999   # a really long time.
   991   1000   #
   992         -test:	testfixture$(TEXE) sqlite3$(TEXE) fuzztest
         1001  +test:	$(TESTPROGS) fuzztest
   993   1002   	./testfixture$(TEXE) $(TOP)/test/veryquick.test
   994   1003   
   995   1004   # Run a test using valgrind.  This can take a really long time
   996   1005   # because valgrind is so much slower than a native machine.
   997   1006   #
   998         -valgrindtest:	testfixture$(TEXE) sqlite3$(TEXE) fuzzershell$(TEXE)
         1007  +valgrindtest:	$(TESTPROGS) fuzzershell$(TEXE)
   999   1008   	valgrind -v ./fuzzershell$(TEXE) -f $(TOP)/test/fuzzdata1.txt
  1000   1009   	OMIT_MISUSE=1 valgrind -v ./testfixture$(TEXE) $(TOP)/test/permutations.test valgrind
  1001   1010   
  1002   1011   # A very fast test that checks basic sanity.  The name comes from
  1003   1012   # the 60s-era electronics testing:  "Turn it on and see if smoke
  1004   1013   # comes out."
  1005   1014   #
  1006         -smoketest:	testfixture$(TEXE) fuzzershell$(TEXE)
         1015  +smoketest:	$(TESTPROGS) fuzzershell$(TEXE)
  1007   1016   	./testfixture$(TEXE) $(TOP)/test/main.test
  1008   1017   
  1009   1018   sqlite3_analyzer.c: sqlite3.c $(TOP)/src/tclsqlite.c $(TOP)/tool/spaceanal.tcl
  1010   1019   	echo "#define TCLSH 2" > $@
  1011         -	echo "#define SQLITE_ENABLE_DBSTAT_VTAB" >> $@
         1020  +	echo "#define SQLITE_ENABLE_DBSTAT_VTAB 1" >> $@
  1012   1021   	cat sqlite3.c $(TOP)/src/tclsqlite.c >> $@
  1013   1022   	echo "static const char *tclsh_main_loop(void){" >> $@
  1014   1023   	echo "static const char *zMainloop = " >> $@
  1015   1024   	$(NAWK) -f $(TOP)/tool/tostr.awk $(TOP)/tool/spaceanal.tcl >> $@
  1016   1025   	echo "; return zMainloop; }" >> $@
  1017   1026   
  1018   1027   sqlite3_analyzer$(TEXE): sqlite3_analyzer.c
................................................................................
  1118   1127   	rm -f sqlite3.dll sqlite3.lib sqlite3.exp sqlite3.def
  1119   1128   	rm -f sqlite3.c
  1120   1129   	rm -f sqlite3rc.h
  1121   1130   	rm -f shell.c sqlite3ext.h
  1122   1131   	rm -f sqlite3_analyzer$(TEXE) sqlite3_analyzer.c
  1123   1132   	rm -f sqlite-*-output.vsix
  1124   1133   	rm -f mptester mptester.exe
         1134  +	rm -f fuzzershell fuzzershell.exe
         1135  +	rm -f sqldiff sqldiff.exe
  1125   1136   
  1126   1137   distclean:	clean
  1127   1138   	rm -f config.log config.status libtool Makefile sqlite3.pc
  1128   1139   
  1129   1140   #
  1130   1141   # Windows section
  1131   1142   #

Changes to Makefile.msc.

    31     31   
    32     32   # Set this non-0 to have the shell executable link against the core dynamic
    33     33   # link library.
    34     34   #
    35     35   !IFNDEF DYNAMIC_SHELL
    36     36   DYNAMIC_SHELL = 0
    37     37   !ENDIF
           38  +
           39  +# Set this non-0 to enable extra code that attempts to detect misuse of the
           40  +# SQLite API.
           41  +#
           42  +!IFNDEF API_ARMOR
           43  +API_ARMOR = 0
           44  +!ENDIF
    38     45   
    39     46   # If necessary, create a list of harmless compiler warnings to disable when
    40     47   # compiling the various tools.  For the SQLite source code itself, warnings,
    41     48   # if any, will be disabled from within it.
    42     49   #
    43     50   !IFNDEF NO_WARN
    44     51   !IF $(USE_FULLWARN)!=0
................................................................................
   489    496   #
   490    497   !IF $(DEBUG)==0
   491    498   TCC = $(TCC) -DNDEBUG
   492    499   BCC = $(BCC) -DNDEBUG
   493    500   RCC = $(RCC) -DNDEBUG
   494    501   !ENDIF
   495    502   
   496         -!IF $(DEBUG)>0
   497         -TCC = $(TCC) -DSQLITE_ENABLE_API_ARMOR
   498         -RCC = $(RCC) -DSQLITE_ENABLE_API_ARMOR
          503  +!IF $(DEBUG)>0 || $(API_ARMOR)!=0
          504  +TCC = $(TCC) -DSQLITE_ENABLE_API_ARMOR=1
          505  +RCC = $(RCC) -DSQLITE_ENABLE_API_ARMOR=1
   499    506   !ENDIF
   500    507   
   501    508   !IF $(DEBUG)>2
   502         -TCC = $(TCC) -DSQLITE_DEBUG
   503         -RCC = $(RCC) -DSQLITE_DEBUG
          509  +TCC = $(TCC) -DSQLITE_DEBUG=1
          510  +RCC = $(RCC) -DSQLITE_DEBUG=1
   504    511   !ENDIF
   505    512   
   506    513   !IF $(DEBUG)>4 || $(OSTRACE)!=0
   507    514   TCC = $(TCC) -DSQLITE_FORCE_OS_TRACE=1 -DSQLITE_DEBUG_OS_TRACE=1
   508    515   RCC = $(RCC) -DSQLITE_FORCE_OS_TRACE=1 -DSQLITE_DEBUG_OS_TRACE=1
   509    516   !ENDIF
   510    517   
   511    518   !IF $(DEBUG)>5
   512         -TCC = $(TCC) -DSQLITE_ENABLE_IOTRACE
   513         -RCC = $(RCC) -DSQLITE_ENABLE_IOTRACE
          519  +TCC = $(TCC) -DSQLITE_ENABLE_IOTRACE=1
          520  +RCC = $(RCC) -DSQLITE_ENABLE_IOTRACE=1
   514    521   !ENDIF
   515    522   
   516    523   # Prevent warnings about "insecure" MSVC runtime library functions
   517    524   # being used.
   518    525   #
   519    526   TCC = $(TCC) -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS
   520    527   BCC = $(BCC) -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS
................................................................................
  1191   1198     $(TOP)\ext\rtree\rtree.h
  1192   1199   EXTHDR = $(EXTHDR) \
  1193   1200     $(TOP)\ext\icu\sqliteicu.h
  1194   1201   EXTHDR = $(EXTHDR) \
  1195   1202     $(TOP)\ext\rtree\sqlite3rtree.h
  1196   1203   EXTHDR = $(EXTHDR) \
  1197   1204     $(TOP)\ext\session\sqlite3session.h
         1205  +
         1206  +# executables needed for testing
         1207  +#
         1208  +TESTPROGS = \
         1209  +  testfixture.exe \
         1210  +  sqlite3.exe \
         1211  +  sqlite3_analyzer.exe \
         1212  +  sqldiff.exe
         1213  +
  1198   1214   
  1199   1215   # This is the default Makefile target.  The objects listed here
  1200   1216   # are what get build when you type just "make" with no arguments.
  1201   1217   #
  1202   1218   all:	dll libsqlite3.lib sqlite3.exe libtclsqlite3.lib
  1203   1219   
  1204   1220   libsqlite3.lib:	$(LIBOBJ)
................................................................................
  1659   1675   		-DBUILD_sqlite -I$(TCLINCDIR) \
  1660   1676   		$(TESTFIXTURE_SRC) \
  1661   1677   		/link $(LTLINKOPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LTLIBS) $(TLIBS)
  1662   1678   
  1663   1679   extensiontest: testfixture.exe testloadext.dll
  1664   1680   	.\testfixture.exe $(TOP)\test\loadext.test
  1665   1681   
  1666         -fulltest:	testfixture.exe sqlite3.exe fuzztest
         1682  +fulltest:	$(TESTPROGS) fuzztest
  1667   1683   	.\testfixture.exe $(TOP)\test\all.test
  1668   1684   
  1669         -soaktest:	testfixture.exe sqlite3.exe fuzzoomtest
         1685  +soaktest:	$(TESTPROGS) fuzzoomtest
  1670   1686   	.\testfixture.exe $(TOP)\test\all.test -soak=1
  1671   1687   
  1672         -fulltestonly:	testfixture.exe sqlite3.exe fuzztest
         1688  +fulltestonly:	$(TESTPROGS) fuzztest
  1673   1689   	.\testfixture.exe $(TOP)\test\full.test
  1674   1690   
  1675   1691   queryplantest:	testfixture.exe sqlite3.exe
  1676   1692   	.\testfixture.exe $(TOP)\test\permutations.test queryplanner
  1677   1693   
  1678   1694   fuzztest:	fuzzershell.exe
  1679   1695   	.\fuzzershell.exe $(TOP)\test\fuzzdata1.txt $(TOP)\test\fuzzdata2.txt
  1680   1696   
  1681   1697   fuzzoomtest:	fuzzershell.exe
  1682   1698   	.\fuzzershell.exe -f $(TOP)\test\fuzzdata1.txt --oom
  1683   1699   
  1684         -test:	testfixture.exe sqlite3.exe fuzztest
         1700  +test:	$(TESTPROGS) fuzztest
  1685   1701   	.\testfixture.exe $(TOP)\test\veryquick.test
  1686   1702   
  1687         -smoketest:	testfixture.exe
         1703  +smoketest:	$(TESTPROGS) fuzzershell.exe
  1688   1704   	.\testfixture.exe $(TOP)\test\main.test
  1689   1705   
  1690   1706   sqlite3_analyzer.c: $(SQLITE3C) $(TOP)\src\tclsqlite.c $(TOP)\tool\spaceanal.tcl
  1691         -	copy $(SQLITE3C) + $(TOP)\src\tclsqlite.c $@
         1707  +	echo #define TCLSH 2 > $@
         1708  +	echo #define SQLITE_ENABLE_DBSTAT_VTAB 1 >> $@
         1709  +	copy $@ + $(SQLITE3C) + $(TOP)\src\tclsqlite.c $@
  1692   1710   	echo static const char *tclsh_main_loop(void){ >> $@
  1693   1711   	echo static const char *zMainloop = >> $@
  1694   1712   	$(NAWK) -f $(TOP)\tool\tostr.awk $(TOP)\tool\spaceanal.tcl >> $@
  1695   1713   	echo ; return zMainloop; } >> $@
  1696   1714   
  1697   1715   sqlite3_analyzer.exe:	sqlite3_analyzer.c $(LIBRESOBJS)
  1698         -	$(LTLINK) $(NO_WARN) -DBUILD_sqlite -DSQLITE_ENABLE_DBSTAT_VTAB -DTCLSH=2 -I$(TCLINCDIR) sqlite3_analyzer.c \
         1716  +	$(LTLINK) $(NO_WARN) -DBUILD_sqlite -I$(TCLINCDIR) sqlite3_analyzer.c \
  1699   1717   		/link $(LTLINKOPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LTLIBS) $(TLIBS)
  1700   1718   
  1701   1719   testloadext.lo:	$(TOP)\src\test_loadext.c
  1702   1720   	$(LTCOMPILE) $(NO_WARN) -c $(TOP)\src\test_loadext.c
  1703   1721   
  1704   1722   testloadext.dll: testloadext.lo
  1705   1723   	$(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL /OUT:$@ testloadext.lo
................................................................................
  1766   1784   	del /Q mptester.exe wordcount.exe 2>NUL
  1767   1785   	del /Q sqlite3.exe sqlite3.dll sqlite3.def 2>NUL
  1768   1786   	del /Q sqlite3.c sqlite3-*.c 2>NUL
  1769   1787   	del /Q sqlite3rc.h 2>NUL
  1770   1788   	del /Q shell.c sqlite3ext.h 2>NUL
  1771   1789   	del /Q sqlite3_analyzer.exe sqlite3_analyzer.c 2>NUL
  1772   1790   	del /Q sqlite-*-output.vsix 2>NUL
         1791  +	del /Q fuzzershell.exe sqldiff.exe 2>NUL
  1773   1792   
  1774   1793   # Dynamic link library section.
  1775   1794   #
  1776   1795   dll: sqlite3.dll
  1777   1796   
  1778   1797   sqlite3.def: libsqlite3.lib
  1779   1798   	echo EXPORTS > sqlite3.def
  1780   1799   	dumpbin /all libsqlite3.lib \
  1781   1800   		| $(NAWK) "/ 1 _?sqlite3_/ { sub(/^.* _?/,\"\");print }" \
  1782   1801   		| sort >> sqlite3.def
  1783   1802   
  1784   1803   sqlite3.dll: $(LIBOBJ) $(LIBRESOBJS) $(CORE_LINK_DEP)
  1785   1804   	$(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL $(CORE_LINK_OPTS) /OUT:$@ $(LIBOBJ) $(LIBRESOBJS) $(LTLIBS) $(TLIBS)

Changes to VERSION.

     1         -3.8.10
            1  +3.8.10.1

Changes to autoconf/Makefile.am.

     2      2   AM_CFLAGS = @THREADSAFE_FLAGS@ @DYNAMIC_EXTENSION_FLAGS@ -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_RTREE
     3      3   
     4      4   lib_LTLIBRARIES = libsqlite3.la
     5      5   libsqlite3_la_SOURCES = sqlite3.c
     6      6   libsqlite3_la_LDFLAGS = -no-undefined -version-info 8:6:8
     7      7   
     8      8   bin_PROGRAMS = sqlite3
     9         -sqlite3_SOURCES = shell.c sqlite3.h
    10         -sqlite3_LDADD = sqlite3.$(OBJEXT) @READLINE_LIBS@
            9  +sqlite3_SOURCES = shell.c sqlite3.c sqlite3.h
           10  +sqlite3_LDADD = @READLINE_LIBS@
           11  +sqlite3_CFLAGS = $(AM_CFLAGS)
    11     12   
    12     13   include_HEADERS = sqlite3.h sqlite3ext.h
    13     14   
    14     15   EXTRA_DIST = sqlite3.1 tea
    15     16   pkgconfigdir = ${libdir}/pkgconfig
    16     17   pkgconfig_DATA = sqlite3.pc
    17     18   
    18     19   man_MANS = sqlite3.1

Changes to configure.

     1      1   #! /bin/sh
     2      2   # Guess values for system-dependent variables and create Makefiles.
     3         -# Generated by GNU Autoconf 2.62 for sqlite 3.8.10.
            3  +# Generated by GNU Autoconf 2.62 for sqlite 3.8.10.1.
     4      4   #
     5      5   # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
     6      6   # 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
     7      7   # This configure script is free software; the Free Software Foundation
     8      8   # gives unlimited permission to copy, distribute and modify it.
     9      9   ## --------------------- ##
    10     10   ## M4sh Initialization.  ##
................................................................................
   739    739   MFLAGS=
   740    740   MAKEFLAGS=
   741    741   SHELL=${CONFIG_SHELL-/bin/sh}
   742    742   
   743    743   # Identity of this package.
   744    744   PACKAGE_NAME='sqlite'
   745    745   PACKAGE_TARNAME='sqlite'
   746         -PACKAGE_VERSION='3.8.10'
   747         -PACKAGE_STRING='sqlite 3.8.10'
          746  +PACKAGE_VERSION='3.8.10.1'
          747  +PACKAGE_STRING='sqlite 3.8.10.1'
   748    748   PACKAGE_BUGREPORT=''
   749    749   
   750    750   # Factoring default headers for most tests.
   751    751   ac_includes_default="\
   752    752   #include <stdio.h>
   753    753   #ifdef HAVE_SYS_TYPES_H
   754    754   # include <sys/types.h>
................................................................................
  1477   1477   #
  1478   1478   # Report the --help message.
  1479   1479   #
  1480   1480   if test "$ac_init_help" = "long"; then
  1481   1481     # Omit some internal or obsolete options to make the list less imposing.
  1482   1482     # This message is too long to be a string in the A/UX 3.1 sh.
  1483   1483     cat <<_ACEOF
  1484         -\`configure' configures sqlite 3.8.10 to adapt to many kinds of systems.
         1484  +\`configure' configures sqlite 3.8.10.1 to adapt to many kinds of systems.
  1485   1485   
  1486   1486   Usage: $0 [OPTION]... [VAR=VALUE]...
  1487   1487   
  1488   1488   To assign environment variables (e.g., CC, CFLAGS...), specify them as
  1489   1489   VAR=VALUE.  See below for descriptions of some of the useful variables.
  1490   1490   
  1491   1491   Defaults for the options are specified in brackets.
................................................................................
  1542   1542     --build=BUILD     configure for building on BUILD [guessed]
  1543   1543     --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  1544   1544   _ACEOF
  1545   1545   fi
  1546   1546   
  1547   1547   if test -n "$ac_init_help"; then
  1548   1548     case $ac_init_help in
  1549         -     short | recursive ) echo "Configuration of sqlite 3.8.10:";;
         1549  +     short | recursive ) echo "Configuration of sqlite 3.8.10.1:";;
  1550   1550      esac
  1551   1551     cat <<\_ACEOF
  1552   1552   
  1553   1553   Optional Features:
  1554   1554     --disable-option-checking  ignore unrecognized --enable/--with options
  1555   1555     --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  1556   1556     --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
................................................................................
  1656   1656       cd "$ac_pwd" || { ac_status=$?; break; }
  1657   1657     done
  1658   1658   fi
  1659   1659   
  1660   1660   test -n "$ac_init_help" && exit $ac_status
  1661   1661   if $ac_init_version; then
  1662   1662     cat <<\_ACEOF
  1663         -sqlite configure 3.8.10
         1663  +sqlite configure 3.8.10.1
  1664   1664   generated by GNU Autoconf 2.62
  1665   1665   
  1666   1666   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
  1667   1667   2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
  1668   1668   This configure script is free software; the Free Software Foundation
  1669   1669   gives unlimited permission to copy, distribute and modify it.
  1670   1670   _ACEOF
  1671   1671     exit
  1672   1672   fi
  1673   1673   cat >config.log <<_ACEOF
  1674   1674   This file contains any messages produced by compilers while
  1675   1675   running configure, to aid debugging if configure makes a mistake.
  1676   1676   
  1677         -It was created by sqlite $as_me 3.8.10, which was
         1677  +It was created by sqlite $as_me 3.8.10.1, which was
  1678   1678   generated by GNU Autoconf 2.62.  Invocation command line was
  1679   1679   
  1680   1680     $ $0 $@
  1681   1681   
  1682   1682   _ACEOF
  1683   1683   exec 5>>config.log
  1684   1684   {
................................................................................
 13949  13949   
 13950  13950   exec 6>&1
 13951  13951   
 13952  13952   # Save the log message, to keep $[0] and so on meaningful, and to
 13953  13953   # report actual input values of CONFIG_FILES etc. instead of their
 13954  13954   # values after options handling.
 13955  13955   ac_log="
 13956         -This file was extended by sqlite $as_me 3.8.10, which was
        13956  +This file was extended by sqlite $as_me 3.8.10.1, which was
 13957  13957   generated by GNU Autoconf 2.62.  Invocation command line was
 13958  13958   
 13959  13959     CONFIG_FILES    = $CONFIG_FILES
 13960  13960     CONFIG_HEADERS  = $CONFIG_HEADERS
 13961  13961     CONFIG_LINKS    = $CONFIG_LINKS
 13962  13962     CONFIG_COMMANDS = $CONFIG_COMMANDS
 13963  13963     $ $0 $@
................................................................................
 14002  14002   $config_commands
 14003  14003   
 14004  14004   Report bugs to <bug-autoconf@gnu.org>."
 14005  14005   
 14006  14006   _ACEOF
 14007  14007   cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 14008  14008   ac_cs_version="\\
 14009         -sqlite config.status 3.8.10
        14009  +sqlite config.status 3.8.10.1
 14010  14010   configured by $0, generated by GNU Autoconf 2.62,
 14011  14011     with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
 14012  14012   
 14013  14013   Copyright (C) 2008 Free Software Foundation, Inc.
 14014  14014   This config.status script is free software; the Free Software Foundation
 14015  14015   gives unlimited permission to copy, distribute and modify it."
 14016  14016   

Changes to ext/fts3/fts3.c.

  1671   1671   static int fts3CloseMethod(sqlite3_vtab_cursor *pCursor){
  1672   1672     Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
  1673   1673     assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
  1674   1674     sqlite3_finalize(pCsr->pStmt);
  1675   1675     sqlite3Fts3ExprFree(pCsr->pExpr);
  1676   1676     sqlite3Fts3FreeDeferredTokens(pCsr);
  1677   1677     sqlite3_free(pCsr->aDoclist);
  1678         -  sqlite3_free(pCsr->aMatchinfo);
         1678  +  sqlite3Fts3MIBufferFree(pCsr->pMIBuffer);
  1679   1679     assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
  1680   1680     sqlite3_free(pCsr);
  1681   1681     return SQLITE_OK;
  1682   1682   }
  1683   1683   
  1684   1684   /*
  1685   1685   ** If pCsr->pStmt has not been prepared (i.e. if pCsr->pStmt==0), then
................................................................................
  3172   3172     if( idxNum & FTS3_HAVE_DOCID_GE ) pDocidGe = apVal[iIdx++];
  3173   3173     if( idxNum & FTS3_HAVE_DOCID_LE ) pDocidLe = apVal[iIdx++];
  3174   3174     assert( iIdx==nVal );
  3175   3175   
  3176   3176     /* In case the cursor has been used before, clear it now. */
  3177   3177     sqlite3_finalize(pCsr->pStmt);
  3178   3178     sqlite3_free(pCsr->aDoclist);
  3179         -  sqlite3_free(pCsr->aMatchinfo);
         3179  +  sqlite3Fts3MIBufferFree(pCsr->pMIBuffer);
  3180   3180     sqlite3Fts3ExprFree(pCsr->pExpr);
  3181   3181     memset(&pCursor[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor));
  3182   3182   
  3183   3183     /* Set the lower and upper bounds on docids to return */
  3184   3184     pCsr->iMinDocid = fts3DocidRange(pDocidGe, SMALLEST_INT64);
  3185   3185     pCsr->iMaxDocid = fts3DocidRange(pDocidLe, LARGEST_INT64);
  3186   3186   

Changes to ext/fts3/fts3Int.h.

   193    193   
   194    194   typedef struct Fts3Doclist Fts3Doclist;
   195    195   typedef struct Fts3SegFilter Fts3SegFilter;
   196    196   typedef struct Fts3DeferredToken Fts3DeferredToken;
   197    197   typedef struct Fts3SegReader Fts3SegReader;
   198    198   typedef struct Fts3MultiSegReader Fts3MultiSegReader;
   199    199   
          200  +typedef struct MatchinfoBuffer MatchinfoBuffer;
          201  +
   200    202   /*
   201    203   ** A connection to a fulltext index is an instance of the following
   202    204   ** structure. The xCreate and xConnect methods create an instance
   203    205   ** of this structure and xDestroy and xDisconnect free that instance.
   204    206   ** All other methods receive a pointer to the structure as one of their
   205    207   ** arguments.
   206    208   */
................................................................................
   302    304     u8 bDesc;                       /* True to sort in descending order */
   303    305     int eEvalmode;                  /* An FTS3_EVAL_XX constant */
   304    306     int nRowAvg;                    /* Average size of database rows, in pages */
   305    307     sqlite3_int64 nDoc;             /* Documents in table */
   306    308     i64 iMinDocid;                  /* Minimum docid to return */
   307    309     i64 iMaxDocid;                  /* Maximum docid to return */
   308    310     int isMatchinfoNeeded;          /* True when aMatchinfo[] needs filling in */
   309         -  u32 *aMatchinfo;                /* Information about most recent match */
   310         -  int nMatchinfo;                 /* Number of elements in aMatchinfo[] */
   311         -  char *zMatchinfo;               /* Matchinfo specification */
          311  +  MatchinfoBuffer *pMIBuffer;     /* Buffer for matchinfo data */
   312    312   };
   313    313   
   314    314   #define FTS3_EVAL_FILTER    0
   315    315   #define FTS3_EVAL_NEXT      1
   316    316   #define FTS3_EVAL_MATCHINFO 2
   317    317   
   318    318   /*
................................................................................
   424    424   
   425    425     /* The following are used by the fts3_eval.c module. */
   426    426     sqlite3_int64 iDocid;      /* Current docid */
   427    427     u8 bEof;                   /* True this expression is at EOF already */
   428    428     u8 bStart;                 /* True if iDocid is valid */
   429    429     u8 bDeferred;              /* True if this expression is entirely deferred */
   430    430   
   431         -  u32 *aMI;
          431  +  /* The following are used by the fts3_snippet.c module. */
          432  +  int iPhrase;               /* Index of this phrase in matchinfo() results */
          433  +  u32 *aMI;                  /* See above */
   432    434   };
   433    435   
   434    436   /*
   435    437   ** Candidate values for Fts3Query.eType. Note that the order of the first
   436    438   ** four values is in order of precedence when parsing expressions. For 
   437    439   ** example, the following:
   438    440   **
................................................................................
   560    562   
   561    563   /* fts3_snippet.c */
   562    564   void sqlite3Fts3Offsets(sqlite3_context*, Fts3Cursor*);
   563    565   void sqlite3Fts3Snippet(sqlite3_context *, Fts3Cursor *, const char *,
   564    566     const char *, const char *, int, int
   565    567   );
   566    568   void sqlite3Fts3Matchinfo(sqlite3_context *, Fts3Cursor *, const char *);
          569  +void sqlite3Fts3MIBufferFree(MatchinfoBuffer *p);
   567    570   
   568    571   /* fts3_expr.c */
   569    572   int sqlite3Fts3ExprParse(sqlite3_tokenizer *, int,
   570    573     char **, int, int, int, const char *, int, Fts3Expr **, char **
   571    574   );
   572    575   void sqlite3Fts3ExprFree(Fts3Expr *);
   573    576   #ifdef SQLITE_TEST

Changes to ext/fts3/fts3_snippet.c.

    24     24   #define FTS3_MATCHINFO_NCOL      'c'        /* 1 value */
    25     25   #define FTS3_MATCHINFO_NDOC      'n'        /* 1 value */
    26     26   #define FTS3_MATCHINFO_AVGLENGTH 'a'        /* nCol values */
    27     27   #define FTS3_MATCHINFO_LENGTH    'l'        /* nCol values */
    28     28   #define FTS3_MATCHINFO_LCS       's'        /* nCol values */
    29     29   #define FTS3_MATCHINFO_HITS      'x'        /* 3*nCol*nPhrase values */
    30     30   #define FTS3_MATCHINFO_LHITS     'y'        /* nCol*nPhrase values */
           31  +#define FTS3_MATCHINFO_LHITS_BM  'b'        /* nCol*nPhrase values */
    31     32   
    32     33   /*
    33     34   ** The default value for the second argument to matchinfo(). 
    34     35   */
    35     36   #define FTS3_MATCHINFO_DEFAULT   "pcx"
    36     37   
    37     38   
................................................................................
    85     86   */
    86     87   typedef struct MatchInfo MatchInfo;
    87     88   struct MatchInfo {
    88     89     Fts3Cursor *pCursor;            /* FTS3 Cursor */
    89     90     int nCol;                       /* Number of columns in table */
    90     91     int nPhrase;                    /* Number of matchable phrases in query */
    91     92     sqlite3_int64 nDoc;             /* Number of docs in database */
           93  +  char flag;
    92     94     u32 *aMatchinfo;                /* Pre-allocated buffer */
    93     95   };
    94     96   
           97  +/*
           98  +** An instance of this structure is used to manage a pair of buffers, each
           99  +** (nElem * sizeof(u32)) bytes in size. See the MatchinfoBuffer code below
          100  +** for details.
          101  +*/
          102  +struct MatchinfoBuffer {
          103  +  u8 aRef[3];
          104  +  int nElem;
          105  +  int bGlobal;                    /* Set if global data is loaded */
          106  +  char *zMatchinfo;
          107  +  u32 aMatchinfo[0];
          108  +};
    95    109   
    96    110   
    97    111   /*
    98    112   ** The snippet() and offsets() functions both return text values. An instance
    99    113   ** of the following structure is used to accumulate those values while the
   100    114   ** functions are running. See fts3StringAppend() for details.
   101    115   */
................................................................................
   102    116   typedef struct StrBuffer StrBuffer;
   103    117   struct StrBuffer {
   104    118     char *z;                        /* Pointer to buffer containing string */
   105    119     int n;                          /* Length of z in bytes (excl. nul-term) */
   106    120     int nAlloc;                     /* Allocated size of buffer z in bytes */
   107    121   };
   108    122   
          123  +
          124  +/*************************************************************************
          125  +** Start of MatchinfoBuffer code.
          126  +*/
          127  +
          128  +/*
          129  +** Allocate a two-slot MatchinfoBuffer object.
          130  +*/
          131  +static MatchinfoBuffer *fts3MIBufferNew(int nElem, const char *zMatchinfo){
          132  +  MatchinfoBuffer *pRet;
          133  +  int nByte = sizeof(u32) * (2*nElem + 2) + sizeof(MatchinfoBuffer);
          134  +  int nStr = strlen(zMatchinfo);
          135  +
          136  +  pRet = sqlite3_malloc(nByte + nStr+1);
          137  +  if( pRet ){
          138  +    memset(pRet, 0, nByte);
          139  +    pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet;
          140  +    pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0] + sizeof(u32)*(nElem+1);
          141  +    pRet->nElem = nElem;
          142  +    pRet->zMatchinfo = ((char*)pRet) + nByte;
          143  +    memcpy(pRet->zMatchinfo, zMatchinfo, nStr+1);
          144  +    pRet->aRef[0] = 1;
          145  +  }
          146  +
          147  +  return pRet;
          148  +}
          149  +
          150  +static void fts3MIBufferFree(void *p){
          151  +  MatchinfoBuffer *pBuf = (MatchinfoBuffer*)((u8*)p - ((u32*)p)[-1]);
          152  +
          153  +  assert( (u32*)p==&pBuf->aMatchinfo[1] 
          154  +       || (u32*)p==&pBuf->aMatchinfo[pBuf->nElem+2] 
          155  +  );
          156  +  if( (u32*)p==&pBuf->aMatchinfo[1] ){
          157  +    pBuf->aRef[1] = 0;
          158  +  }else{
          159  +    pBuf->aRef[2] = 0;
          160  +  }
          161  +
          162  +  if( pBuf->aRef[0]==0 && pBuf->aRef[1]==0 && pBuf->aRef[2]==0 ){
          163  +    sqlite3_free(pBuf);
          164  +  }
          165  +}
          166  +
          167  +static void (*fts3MIBufferAlloc(MatchinfoBuffer *p, u32 **paOut))(void*){
          168  +  void (*xRet)(void*) = 0;
          169  +  u32 *aOut = 0;
          170  +
          171  +  if( p->aRef[1]==0 ){
          172  +    p->aRef[1] = 1;
          173  +    aOut = &p->aMatchinfo[1];
          174  +    xRet = fts3MIBufferFree;
          175  +  }
          176  +  else if( p->aRef[2]==0 ){
          177  +    p->aRef[2] = 1;
          178  +    aOut = &p->aMatchinfo[p->nElem+2];
          179  +    xRet = fts3MIBufferFree;
          180  +  }else{
          181  +    aOut = (u32*)sqlite3_malloc(p->nElem * sizeof(u32));
          182  +    if( aOut ){
          183  +      xRet = sqlite3_free;
          184  +      if( p->bGlobal ) memcpy(aOut, &p->aMatchinfo[1], p->nElem*sizeof(u32));
          185  +    }
          186  +  }
          187  +
          188  +  *paOut = aOut;
          189  +  return xRet;
          190  +}
          191  +
          192  +static void fts3MIBufferSetGlobal(MatchinfoBuffer *p){
          193  +  p->bGlobal = 1;
          194  +  memcpy(&p->aMatchinfo[2+p->nElem], &p->aMatchinfo[1], p->nElem*sizeof(u32));
          195  +}
          196  +
          197  +/*
          198  +** Free a MatchinfoBuffer object allocated using fts3MIBufferNew()
          199  +*/
          200  +void sqlite3Fts3MIBufferFree(MatchinfoBuffer *p){
          201  +  if( p ){
          202  +    assert( p->aRef[0]==1 );
          203  +    p->aRef[0] = 0;
          204  +    if( p->aRef[0]==0 && p->aRef[1]==0 && p->aRef[2]==0 ){
          205  +      sqlite3_free(p);
          206  +    }
          207  +  }
          208  +}
          209  +
          210  +/* 
          211  +** End of MatchinfoBuffer code.
          212  +*************************************************************************/
          213  +
   109    214   
   110    215   /*
   111    216   ** This function is used to help iterate through a position-list. A position
   112    217   ** list is a list of unique integers, sorted from smallest to largest. Each
   113    218   ** element of the list is represented by an FTS3 varint that takes the value
   114    219   ** of the difference between the current element and the previous one plus
   115    220   ** two. For example, to store the position-list:
................................................................................
   139    244   static int fts3ExprIterate2(
   140    245     Fts3Expr *pExpr,                /* Expression to iterate phrases of */
   141    246     int *piPhrase,                  /* Pointer to phrase counter */
   142    247     int (*x)(Fts3Expr*,int,void*),  /* Callback function to invoke for phrases */
   143    248     void *pCtx                      /* Second argument to pass to callback */
   144    249   ){
   145    250     int rc;                         /* Return code */
   146         -  int eType = pExpr->eType;       /* Type of expression node pExpr */
          251  +  int eType = pExpr->eType;     /* Type of expression node pExpr */
   147    252   
   148    253     if( eType!=FTSQUERY_PHRASE ){
   149    254       assert( pExpr->pLeft && pExpr->pRight );
   150    255       rc = fts3ExprIterate2(pExpr->pLeft, piPhrase, x, pCtx);
   151    256       if( rc==SQLITE_OK && eType!=FTSQUERY_NOT ){
   152    257         rc = fts3ExprIterate2(pExpr->pRight, piPhrase, x, pCtx);
   153    258       }
................................................................................
   172    277     Fts3Expr *pExpr,                /* Expression to iterate phrases of */
   173    278     int (*x)(Fts3Expr*,int,void*),  /* Callback function to invoke for phrases */
   174    279     void *pCtx                      /* Second argument to pass to callback */
   175    280   ){
   176    281     int iPhrase = 0;                /* Variable used as the phrase counter */
   177    282     return fts3ExprIterate2(pExpr, &iPhrase, x, pCtx);
   178    283   }
          284  +
   179    285   
   180    286   /*
   181    287   ** This is an fts3ExprIterate() callback used while loading the doclists
   182    288   ** for each phrase into Fts3Expr.aDoclist[]/nDoclist. See also
   183    289   ** fts3ExprLoadDoclists().
   184    290   */
   185    291   static int fts3ExprLoadDoclistsCb(Fts3Expr *pExpr, int iPhrase, void *ctx){
................................................................................
   217    323     if( pnPhrase ) *pnPhrase = sCtx.nPhrase;
   218    324     if( pnToken ) *pnToken = sCtx.nToken;
   219    325     return rc;
   220    326   }
   221    327   
   222    328   static int fts3ExprPhraseCountCb(Fts3Expr *pExpr, int iPhrase, void *ctx){
   223    329     (*(int *)ctx)++;
   224         -  UNUSED_PARAMETER(pExpr);
   225         -  UNUSED_PARAMETER(iPhrase);
          330  +  pExpr->iPhrase = iPhrase;
   226    331     return SQLITE_OK;
   227    332   }
   228    333   static int fts3ExprPhraseCount(Fts3Expr *pExpr){
   229    334     int nPhrase = 0;
   230    335     (void)fts3ExprIterate(pExpr, fts3ExprPhraseCountCb, (void *)&nPhrase);
   231    336     return nPhrase;
   232    337   }
................................................................................
   439    544     ** the set of phrases in the expression to populate the aPhrase[] array.
   440    545     */
   441    546     sIter.pCsr = pCsr;
   442    547     sIter.iCol = iCol;
   443    548     sIter.nSnippet = nSnippet;
   444    549     sIter.nPhrase = nList;
   445    550     sIter.iCurrent = -1;
   446         -  rc = fts3ExprIterate(pCsr->pExpr, fts3SnippetFindPositions, (void *)&sIter);
          551  +  rc = fts3ExprIterate(pCsr->pExpr, fts3SnippetFindPositions, (void*)&sIter);
   447    552     if( rc==SQLITE_OK ){
   448    553   
   449    554       /* Set the *pmSeen output variable. */
   450    555       for(i=0; i<nList; i++){
   451    556         if( sIter.aPhrase[i].pHead ){
   452    557           *pmSeen |= (u64)1 << i;
   453    558         }
................................................................................
   739    844       c = *pEnd++ & 0x80;
   740    845       if( !c ) nEntry++;
   741    846     }
   742    847   
   743    848     *ppCollist = pEnd;
   744    849     return nEntry;
   745    850   }
          851  +
          852  +/*
          853  +** This function gathers 'y' or 'b' data for a single phrase.
          854  +*/
          855  +static void fts3ExprLHits(
          856  +  Fts3Expr *pExpr,                /* Phrase expression node */
          857  +  MatchInfo *p                    /* Matchinfo context */
          858  +){
          859  +  Fts3Table *pTab = (Fts3Table *)p->pCursor->base.pVtab;
          860  +  int iStart;
          861  +  Fts3Phrase *pPhrase = pExpr->pPhrase;
          862  +  char *pIter = pPhrase->doclist.pList;
          863  +  int iCol = 0;
          864  +
          865  +  assert( p->flag==FTS3_MATCHINFO_LHITS_BM || p->flag==FTS3_MATCHINFO_LHITS );
          866  +  if( p->flag==FTS3_MATCHINFO_LHITS ){
          867  +    iStart = pExpr->iPhrase * p->nCol;
          868  +  }else{
          869  +    iStart = pExpr->iPhrase * ((p->nCol + 31) / 32);
          870  +  }
          871  +
          872  +  while( 1 ){
          873  +    int nHit = fts3ColumnlistCount(&pIter);
          874  +    if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){
          875  +      if( p->flag==FTS3_MATCHINFO_LHITS ){
          876  +        p->aMatchinfo[iStart + iCol] = (u32)nHit;
          877  +      }else if( nHit ){
          878  +        p->aMatchinfo[iStart + (iCol+1)/32] |= (1 << (iCol&0x1F));
          879  +      }
          880  +    }
          881  +    assert( *pIter==0x00 || *pIter==0x01 );
          882  +    if( *pIter!=0x01 ) break;
          883  +    pIter++;
          884  +    pIter += fts3GetVarint32(pIter, &iCol);
          885  +  }
          886  +}
          887  +
          888  +/*
          889  +** Gather the results for matchinfo directives 'y' and 'b'.
          890  +*/
          891  +static void fts3ExprLHitGather(
          892  +  Fts3Expr *pExpr,
          893  +  MatchInfo *p
          894  +){
          895  +  assert( (pExpr->pLeft==0)==(pExpr->pRight==0) );
          896  +  if( pExpr->bEof==0 && pExpr->iDocid==p->pCursor->iPrevId ){
          897  +    if( pExpr->pLeft ){
          898  +      fts3ExprLHitGather(pExpr->pLeft, p);
          899  +      fts3ExprLHitGather(pExpr->pRight, p);
          900  +    }else{
          901  +      fts3ExprLHits(pExpr, p);
          902  +    }
          903  +  }
          904  +}
   746    905   
   747    906   /*
   748    907   ** fts3ExprIterate() callback used to collect the "global" matchinfo stats
   749    908   ** for a single query. 
   750    909   **
   751    910   ** fts3ExprIterate() callback to load the 'global' elements of a
   752    911   ** FTS3_MATCHINFO_HITS matchinfo array. The global stats are those elements 
................................................................................
   806    965         p->aMatchinfo[iStart+i*3] = 0;
   807    966       }
   808    967     }
   809    968   
   810    969     return rc;
   811    970   }
   812    971   
   813         -/*
   814         -** fts3ExprIterate() callback used to gather information for the matchinfo
   815         -** directive 'y'.
   816         -*/
   817         -static int fts3ExprLHitsCb(
   818         -  Fts3Expr *pExpr,                /* Phrase expression node */
   819         -  int iPhrase,                    /* Phrase number */
   820         -  void *pCtx                      /* Pointer to MatchInfo structure */
   821         -){
   822         -  MatchInfo *p = (MatchInfo *)pCtx;
   823         -  Fts3Table *pTab = (Fts3Table *)p->pCursor->base.pVtab;
   824         -  int rc = SQLITE_OK;
   825         -  int iStart = iPhrase * p->nCol;
   826         -  Fts3Expr *pEof;                 /* Ancestor node already at EOF */
   827         -  
   828         -  /* This must be a phrase */
   829         -  assert( pExpr->pPhrase );
   830         -
   831         -  /* Initialize all output integers to zero. */
   832         -  memset(&p->aMatchinfo[iStart], 0, sizeof(u32) * p->nCol);
   833         -
   834         -  /* Check if this or any parent node is at EOF. If so, then all output
   835         -  ** values are zero.  */
   836         -  for(pEof=pExpr; pEof && pEof->bEof==0; pEof=pEof->pParent);
   837         -
   838         -  if( pEof==0 && pExpr->iDocid==p->pCursor->iPrevId ){
   839         -    Fts3Phrase *pPhrase = pExpr->pPhrase;
   840         -    char *pIter = pPhrase->doclist.pList;
   841         -    int iCol = 0;
   842         -
   843         -    while( 1 ){
   844         -      int nHit = fts3ColumnlistCount(&pIter);
   845         -      if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){
   846         -        p->aMatchinfo[iStart + iCol] = (u32)nHit;
   847         -      }
   848         -      assert( *pIter==0x00 || *pIter==0x01 );
   849         -      if( *pIter!=0x01 ) break;
   850         -      pIter++;
   851         -      pIter += fts3GetVarint32(pIter, &iCol);
   852         -    }
   853         -  }
   854         -
   855         -  return rc;
   856         -}
   857         -
   858    972   static int fts3MatchinfoCheck(
   859    973     Fts3Table *pTab, 
   860    974     char cArg,
   861    975     char **pzErr
   862    976   ){
   863    977     if( (cArg==FTS3_MATCHINFO_NPHRASE)
   864    978      || (cArg==FTS3_MATCHINFO_NCOL)
   865    979      || (cArg==FTS3_MATCHINFO_NDOC && pTab->bFts4)
   866    980      || (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bFts4)
   867    981      || (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize)
   868    982      || (cArg==FTS3_MATCHINFO_LCS)
   869    983      || (cArg==FTS3_MATCHINFO_HITS)
   870    984      || (cArg==FTS3_MATCHINFO_LHITS)
          985  +   || (cArg==FTS3_MATCHINFO_LHITS_BM)
   871    986     ){
   872    987       return SQLITE_OK;
   873    988     }
   874    989     sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg);
   875    990     return SQLITE_ERROR;
   876    991   }
   877    992   
................................................................................
   890   1005       case FTS3_MATCHINFO_LCS:
   891   1006         nVal = pInfo->nCol;
   892   1007         break;
   893   1008   
   894   1009       case FTS3_MATCHINFO_LHITS:
   895   1010         nVal = pInfo->nCol * pInfo->nPhrase;
   896   1011         break;
         1012  +
         1013  +    case FTS3_MATCHINFO_LHITS_BM:
         1014  +      nVal = pInfo->nPhrase * ((pInfo->nCol + 31) / 32);
         1015  +      break;
   897   1016   
   898   1017       default:
   899   1018         assert( cArg==FTS3_MATCHINFO_HITS );
   900   1019         nVal = pInfo->nCol * pInfo->nPhrase * 3;
   901   1020         break;
   902   1021     }
   903   1022   
................................................................................
  1085   1204   ){
  1086   1205     int rc = SQLITE_OK;
  1087   1206     int i;
  1088   1207     Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab;
  1089   1208     sqlite3_stmt *pSelect = 0;
  1090   1209   
  1091   1210     for(i=0; rc==SQLITE_OK && zArg[i]; i++){
  1092         -
         1211  +    pInfo->flag = zArg[i];
  1093   1212       switch( zArg[i] ){
  1094   1213         case FTS3_MATCHINFO_NPHRASE:
  1095   1214           if( bGlobal ) pInfo->aMatchinfo[0] = pInfo->nPhrase;
  1096   1215           break;
  1097   1216   
  1098   1217         case FTS3_MATCHINFO_NCOL:
  1099   1218           if( bGlobal ) pInfo->aMatchinfo[0] = pInfo->nCol;
................................................................................
  1145   1264         case FTS3_MATCHINFO_LCS:
  1146   1265           rc = fts3ExprLoadDoclists(pCsr, 0, 0);
  1147   1266           if( rc==SQLITE_OK ){
  1148   1267             rc = fts3MatchinfoLcs(pCsr, pInfo);
  1149   1268           }
  1150   1269           break;
  1151   1270   
  1152         -      case FTS3_MATCHINFO_LHITS:
  1153         -        (void)fts3ExprIterate(pCsr->pExpr, fts3ExprLHitsCb, (void*)pInfo);
         1271  +      case FTS3_MATCHINFO_LHITS_BM:
         1272  +      case FTS3_MATCHINFO_LHITS: {
         1273  +        int nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
         1274  +        memset(pInfo->aMatchinfo, 0, nZero);
         1275  +        fts3ExprLHitGather(pCsr->pExpr, pInfo);
  1154   1276           break;
         1277  +      }
  1155   1278   
  1156   1279         default: {
  1157   1280           Fts3Expr *pExpr;
  1158   1281           assert( zArg[i]==FTS3_MATCHINFO_HITS );
  1159   1282           pExpr = pCsr->pExpr;
  1160   1283           rc = fts3ExprLoadDoclists(pCsr, 0, 0);
  1161   1284           if( rc!=SQLITE_OK ) break;
................................................................................
  1180   1303   }
  1181   1304   
  1182   1305   
  1183   1306   /*
  1184   1307   ** Populate pCsr->aMatchinfo[] with data for the current row. The 
  1185   1308   ** 'matchinfo' data is an array of 32-bit unsigned integers (C type u32).
  1186   1309   */
  1187         -static int fts3GetMatchinfo(
         1310  +static void fts3GetMatchinfo(
         1311  +  sqlite3_context *pCtx,        /* Return results here */
  1188   1312     Fts3Cursor *pCsr,               /* FTS3 Cursor object */
  1189   1313     const char *zArg                /* Second argument to matchinfo() function */
  1190   1314   ){
  1191   1315     MatchInfo sInfo;
  1192   1316     Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab;
  1193   1317     int rc = SQLITE_OK;
  1194   1318     int bGlobal = 0;                /* Collect 'global' stats as well as local */
  1195   1319   
         1320  +  u32 *aOut = 0;
         1321  +  void (*xDestroyOut)(void*) = 0;
         1322  +
  1196   1323     memset(&sInfo, 0, sizeof(MatchInfo));
  1197   1324     sInfo.pCursor = pCsr;
  1198   1325     sInfo.nCol = pTab->nColumn;
  1199   1326   
  1200   1327     /* If there is cached matchinfo() data, but the format string for the 
  1201   1328     ** cache does not match the format string for this request, discard 
  1202   1329     ** the cached data. */
  1203         -  if( pCsr->zMatchinfo && strcmp(pCsr->zMatchinfo, zArg) ){
  1204         -    assert( pCsr->aMatchinfo );
  1205         -    sqlite3_free(pCsr->aMatchinfo);
  1206         -    pCsr->zMatchinfo = 0;
  1207         -    pCsr->aMatchinfo = 0;
         1330  +  if( pCsr->pMIBuffer && strcmp(pCsr->pMIBuffer->zMatchinfo, zArg) ){
         1331  +    sqlite3Fts3MIBufferFree(pCsr->pMIBuffer);
         1332  +    pCsr->pMIBuffer = 0;
  1208   1333     }
  1209   1334   
  1210         -  /* If Fts3Cursor.aMatchinfo[] is NULL, then this is the first time the
         1335  +  /* If Fts3Cursor.pMIBuffer is NULL, then this is the first time the
  1211   1336     ** matchinfo function has been called for this query. In this case 
  1212   1337     ** allocate the array used to accumulate the matchinfo data and
  1213   1338     ** initialize those elements that are constant for every row.
  1214   1339     */
  1215         -  if( pCsr->aMatchinfo==0 ){
         1340  +  if( pCsr->pMIBuffer==0 ){
  1216   1341       int nMatchinfo = 0;           /* Number of u32 elements in match-info */
  1217         -    int nArg;                     /* Bytes in zArg */
  1218   1342       int i;                        /* Used to iterate through zArg */
  1219   1343   
  1220   1344       /* Determine the number of phrases in the query */
  1221   1345       pCsr->nPhrase = fts3ExprPhraseCount(pCsr->pExpr);
  1222   1346       sInfo.nPhrase = pCsr->nPhrase;
  1223   1347   
  1224   1348       /* Determine the number of integers in the buffer returned by this call. */
  1225   1349       for(i=0; zArg[i]; i++){
         1350  +      char *zErr = 0;
         1351  +      if( fts3MatchinfoCheck(pTab, zArg[i], &zErr) ){
         1352  +        sqlite3_result_error(pCtx, zErr, -1);
         1353  +        sqlite3_free(zErr);
         1354  +        return;
         1355  +      }
  1226   1356         nMatchinfo += fts3MatchinfoSize(&sInfo, zArg[i]);
  1227   1357       }
  1228   1358   
  1229   1359       /* Allocate space for Fts3Cursor.aMatchinfo[] and Fts3Cursor.zMatchinfo. */
  1230         -    nArg = (int)strlen(zArg);
  1231         -    pCsr->aMatchinfo = (u32 *)sqlite3_malloc(sizeof(u32)*nMatchinfo + nArg + 1);
  1232         -    if( !pCsr->aMatchinfo ) return SQLITE_NOMEM;
         1360  +    pCsr->pMIBuffer = fts3MIBufferNew(nMatchinfo, zArg);
         1361  +    if( !pCsr->pMIBuffer ) rc = SQLITE_NOMEM;
  1233   1362   
  1234         -    pCsr->zMatchinfo = (char *)&pCsr->aMatchinfo[nMatchinfo];
  1235         -    pCsr->nMatchinfo = nMatchinfo;
  1236         -    memcpy(pCsr->zMatchinfo, zArg, nArg+1);
  1237         -    memset(pCsr->aMatchinfo, 0, sizeof(u32)*nMatchinfo);
  1238   1363       pCsr->isMatchinfoNeeded = 1;
  1239   1364       bGlobal = 1;
  1240   1365     }
  1241   1366   
  1242         -  sInfo.aMatchinfo = pCsr->aMatchinfo;
  1243         -  sInfo.nPhrase = pCsr->nPhrase;
  1244         -  if( pCsr->isMatchinfoNeeded ){
         1367  +  if( rc==SQLITE_OK ){
         1368  +    xDestroyOut = fts3MIBufferAlloc(pCsr->pMIBuffer, &aOut);
         1369  +    if( xDestroyOut==0 ){
         1370  +      rc = SQLITE_NOMEM;
         1371  +    }
         1372  +  }
         1373  +
         1374  +  if( rc==SQLITE_OK ){
         1375  +    sInfo.aMatchinfo = aOut;
         1376  +    sInfo.nPhrase = pCsr->nPhrase;
  1245   1377       rc = fts3MatchinfoValues(pCsr, bGlobal, &sInfo, zArg);
  1246         -    pCsr->isMatchinfoNeeded = 0;
         1378  +    if( bGlobal ){
         1379  +      fts3MIBufferSetGlobal(pCsr->pMIBuffer);
         1380  +    }
  1247   1381     }
  1248   1382   
  1249         -  return rc;
         1383  +  if( rc!=SQLITE_OK ){
         1384  +    sqlite3_result_error_code(pCtx, rc);
         1385  +    if( xDestroyOut ) xDestroyOut(aOut);
         1386  +  }else{
         1387  +    int n = pCsr->pMIBuffer->nElem * sizeof(u32);
         1388  +    sqlite3_result_blob(pCtx, aOut, n, xDestroyOut);
         1389  +  }
  1250   1390   }
  1251   1391   
  1252   1392   /*
  1253   1393   ** Implementation of snippet() function.
  1254   1394   */
  1255   1395   void sqlite3Fts3Snippet(
  1256   1396     sqlite3_context *pCtx,          /* SQLite function call context */
................................................................................
  1448   1588   
  1449   1589       /* Initialize the contents of sCtx.aTerm[] for column iCol. There is 
  1450   1590       ** no way that this operation can fail, so the return code from
  1451   1591       ** fts3ExprIterate() can be discarded.
  1452   1592       */
  1453   1593       sCtx.iCol = iCol;
  1454   1594       sCtx.iTerm = 0;
  1455         -    (void)fts3ExprIterate(pCsr->pExpr, fts3ExprTermOffsetInit, (void *)&sCtx);
         1595  +    (void)fts3ExprIterate(pCsr->pExpr, fts3ExprTermOffsetInit, (void*)&sCtx);
  1456   1596   
  1457   1597       /* Retreive the text stored in column iCol. If an SQL NULL is stored 
  1458   1598       ** in column iCol, jump immediately to the next iteration of the loop.
  1459   1599       ** If an OOM occurs while retrieving the data (this can happen if SQLite
  1460   1600       ** needs to transform the data from utf-16 to utf-8), return SQLITE_NOMEM 
  1461   1601       ** to the caller. 
  1462   1602       */
................................................................................
  1540   1680   */
  1541   1681   void sqlite3Fts3Matchinfo(
  1542   1682     sqlite3_context *pContext,      /* Function call context */
  1543   1683     Fts3Cursor *pCsr,               /* FTS3 table cursor */
  1544   1684     const char *zArg                /* Second arg to matchinfo() function */
  1545   1685   ){
  1546   1686     Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab;
  1547         -  int rc;
  1548         -  int i;
  1549   1687     const char *zFormat;
  1550   1688   
  1551   1689     if( zArg ){
  1552         -    for(i=0; zArg[i]; i++){
  1553         -      char *zErr = 0;
  1554         -      if( fts3MatchinfoCheck(pTab, zArg[i], &zErr) ){
  1555         -        sqlite3_result_error(pContext, zErr, -1);
  1556         -        sqlite3_free(zErr);
  1557         -        return;
  1558         -      }
  1559         -    }
  1560   1690       zFormat = zArg;
  1561   1691     }else{
  1562   1692       zFormat = FTS3_MATCHINFO_DEFAULT;
  1563   1693     }
  1564   1694   
  1565   1695     if( !pCsr->pExpr ){
  1566   1696       sqlite3_result_blob(pContext, "", 0, SQLITE_STATIC);
  1567   1697       return;
  1568         -  }
  1569         -
  1570         -  /* Retrieve matchinfo() data. */
  1571         -  rc = fts3GetMatchinfo(pCsr, zFormat);
  1572         -  sqlite3Fts3SegmentsClose(pTab);
  1573         -
  1574         -  if( rc!=SQLITE_OK ){
  1575         -    sqlite3_result_error_code(pContext, rc);
  1576   1698     }else{
  1577         -    int n = pCsr->nMatchinfo * sizeof(u32);
  1578         -    sqlite3_result_blob(pContext, pCsr->aMatchinfo, n, SQLITE_TRANSIENT);
         1699  +    /* Retrieve matchinfo() data. */
         1700  +    fts3GetMatchinfo(pContext, pCsr, zFormat);
         1701  +    sqlite3Fts3SegmentsClose(pTab);
  1579   1702     }
  1580   1703   }
  1581   1704   
  1582   1705   #endif

Changes to ext/rtree/rtree9.test.

    83     83   
    84     84   
    85     85   #-------------------------------------------------------------------------
    86     86   # Test the example 2d "circle" geometry callback.
    87     87   #
    88     88   register_circle_geom db
    89     89   
    90         -breakpoint
    91     90   do_execsql_test rtree9-5.1 {
    92     91     CREATE VIRTUAL TABLE rt2 USING rtree(id, xmin, xmax, ymin, ymax);
    93     92   
    94     93     INSERT INTO rt2 VALUES(1,    1,   2,  1,  2);
    95     94     INSERT INTO rt2 VALUES(2,    1,   2, -2, -1);
    96     95     INSERT INTO rt2 VALUES(3,    -2, -1, -2, -1);
    97     96     INSERT INTO rt2 VALUES(4,    -2, -1,  1,  2);

Changes to main.mk.

   394    394     $(TOP)/ext/fts3/fts3_tokenizer.h
   395    395   EXTHDR += \
   396    396     $(TOP)/ext/rtree/rtree.h
   397    397   EXTHDR += \
   398    398     $(TOP)/ext/icu/sqliteicu.h
   399    399   EXTHDR += \
   400    400     $(TOP)/ext/userauth/sqlite3userauth.h
          401  +
          402  +# executables needed for testing
          403  +#
          404  +TESTPROGS = \
          405  +  testfixture$(EXE) \
          406  +  sqlite3$(EXE) \
          407  +  sqlite3_analyzer$(EXE) \
          408  +  sqldiff$(EXE)
   401    409   
   402    410   # This is the default Makefile target.  The objects listed here
   403    411   # are what get build when you type just "make" with no arguments.
   404    412   #
   405    413   all:	sqlite3.h libsqlite3.a sqlite3$(EXE)
   406    414   
   407    415   libsqlite3.a:	$(LIBOBJ)
................................................................................
   645    653   
   646    654   fts3-testfixture$(EXE): sqlite3.c fts3amal.c $(TESTSRC) $(TOP)/src/tclsqlite.c
   647    655   	$(TCCX) $(TCL_FLAGS) -DTCLSH=1 $(TESTFIXTURE_FLAGS)                  \
   648    656   	-DSQLITE_ENABLE_FTS3=1                                               \
   649    657   		$(TESTSRC) $(TOP)/src/tclsqlite.c sqlite3.c fts3amal.c       \
   650    658   		-o testfixture$(EXE) $(LIBTCL) $(THREADLIB)
   651    659   
   652         -fulltest:	testfixture$(EXE) sqlite3$(EXE) fuzztest
          660  +fulltest:	$(TESTPROGS) fuzztest
   653    661   	./testfixture$(EXE) $(TOP)/test/all.test
   654    662   
   655         -soaktest:	testfixture$(EXE) sqlite3$(EXE) fuzzoomtest
          663  +soaktest:	$(TESTPROGS) fuzzoomtest
   656    664   	./testfixture$(EXE) $(TOP)/test/all.test -soak=1
   657    665   
   658         -fulltestonly:	testfixture$(EXE) sqlite3$(EXE) fuzztest
          666  +fulltestonly:	$(TESTPROGS) fuzztest
   659    667   	./testfixture$(EXE) $(TOP)/test/full.test
   660    668   
   661    669   queryplantest:	testfixture$(EXE) sqlite3$(EXE)
   662    670   	./testfixture$(EXE) $(TOP)/test/permutations.test queryplanner
   663    671   
   664    672   fuzztest:	fuzzershell$(EXE)
   665    673   	./fuzzershell$(EXE) $(TOP)/test/fuzzdata1.txt $(TOP)/test/fuzzdata2.txt
   666    674   
   667    675   fuzzoomtest:	fuzzershell$(EXE)
   668    676   	./fuzzershell$(EXE) -f $(TOP)/test/fuzzdata1.txt --oom
   669    677   
   670         -test:	testfixture$(EXE) sqlite3$(EXE) fuzztest
          678  +test:	$(TESTPROGS) fuzztest
   671    679   	./testfixture$(EXE) $(TOP)/test/veryquick.test
   672    680   
   673    681   # Run a test using valgrind.  This can take a really long time
   674    682   # because valgrind is so much slower than a native machine.
   675    683   #
   676         -valgrindtest:	testfixture$(EXE) sqlite3$(EXE) fuzzershell$(EXE)
          684  +valgrindtest:	$(TESTPROGS) fuzzershell$(EXE)
   677    685   	valgrind -v ./fuzzershell$(EXE) -f $(TOP)/test/fuzzdata1.txt
   678    686   	OMIT_MISUSE=1 valgrind -v ./testfixture$(EXE) $(TOP)/test/permutations.test valgrind
          687  +
          688  +# A very fast test that checks basic sanity.  The name comes from
          689  +# the 60s-era electronics testing:  "Turn it on and see if smoke
          690  +# comes out."
          691  +#
          692  +smoketest:	$(TESTPROGS) fuzzershell$(EXE)
          693  +	./testfixture$(EXE) $(TOP)/test/main.test
   679    694   
   680    695   # The next two rules are used to support the "threadtest" target. Building
   681    696   # threadtest runs a few thread-safety tests that are implemented in C. This
   682    697   # target is invoked by the releasetest.tcl script.
   683    698   # 
   684    699   THREADTEST3_SRC = $(TOP)/test/threadtest3.c    \
   685    700                     $(TOP)/test/tt3_checkpoint.c \
................................................................................
   784    799   	rm -f wordcount wordcount.exe
   785    800   	rm -f sqlite3.c sqlite3-*.c fts?amal.c tclsqlite3.c
   786    801   	rm -f sqlite3rc.h
   787    802   	rm -f shell.c sqlite3ext.h
   788    803   	rm -f sqlite3_analyzer sqlite3_analyzer.exe sqlite3_analyzer.c
   789    804   	rm -f sqlite-*-output.vsix
   790    805   	rm -f mptester mptester.exe
          806  +	rm -f fuzzershell fuzzershell.exe
          807  +	rm -f sqldiff sqldiff.exe

Changes to src/ctime.c.

    70     70     "ENABLE_ATOMIC_WRITE",
    71     71   #endif
    72     72   #if SQLITE_ENABLE_CEROD
    73     73     "ENABLE_CEROD",
    74     74   #endif
    75     75   #if SQLITE_ENABLE_COLUMN_METADATA
    76     76     "ENABLE_COLUMN_METADATA",
           77  +#endif
           78  +#if SQLITE_ENABLE_DBSTAT_VTAB
           79  +  "ENABLE_DBSTAT_VTAB",
    77     80   #endif
    78     81   #if SQLITE_ENABLE_EXPENSIVE_ASSERT
    79     82     "ENABLE_EXPENSIVE_ASSERT",
    80     83   #endif
    81     84   #if SQLITE_ENABLE_FTS1
    82     85     "ENABLE_FTS1",
    83     86   #endif

Changes to src/dbstat.c.

    14     14   **
    15     15   ** The dbstat virtual table is used to extract low-level formatting
    16     16   ** information from an SQLite database in order to implement the
    17     17   ** "sqlite3_analyzer" utility.  See the ../tool/spaceanal.tcl script
    18     18   ** for an example implementation.
    19     19   */
    20     20   
           21  +#include "sqliteInt.h"   /* Requires access to internal data structures */
    21     22   #if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \
    22     23       && !defined(SQLITE_OMIT_VIRTUALTABLE)
    23         -#include "sqliteInt.h"   /* Requires access to internal data structures */
    24     24   
    25     25   /*
    26     26   ** Page paths:
    27     27   ** 
    28     28   **   The value of the 'path' column describes the path taken from the 
    29     29   **   root-node of the b-tree structure to each page. The value of the 
    30     30   **   root-node path is '/'.
................................................................................
   118    118     i64 iOffset;                    /* Value of 'pgOffset' column */
   119    119     int szPage;                     /* Value of 'pgSize' column */
   120    120   };
   121    121   
   122    122   struct StatTable {
   123    123     sqlite3_vtab base;
   124    124     sqlite3 *db;
          125  +  int iDb;                        /* Index of database to analyze */
   125    126   };
   126    127   
   127    128   #ifndef get2byte
   128    129   # define get2byte(x)   ((x)[0]<<8 | (x)[1])
   129    130   #endif
   130    131   
   131    132   /*
................................................................................
   136    137     void *pAux,
   137    138     int argc, const char *const*argv,
   138    139     sqlite3_vtab **ppVtab,
   139    140     char **pzErr
   140    141   ){
   141    142     StatTable *pTab = 0;
   142    143     int rc = SQLITE_OK;
          144  +  int iDb;
   143    145   
          146  +  if( argc>=4 ){
          147  +    iDb = sqlite3FindDbName(db, argv[3]);
          148  +    if( iDb<0 ){
          149  +      *pzErr = sqlite3_mprintf("no such database: %s", argv[3]);
          150  +      return SQLITE_ERROR;
          151  +    }
          152  +  }else{
          153  +    iDb = 0;
          154  +  }
   144    155     rc = sqlite3_declare_vtab(db, VTAB_SCHEMA);
   145    156     if( rc==SQLITE_OK ){
   146    157       pTab = (StatTable *)sqlite3_malloc64(sizeof(StatTable));
   147    158       if( pTab==0 ) rc = SQLITE_NOMEM;
   148    159     }
   149    160   
   150    161     assert( rc==SQLITE_OK || pTab==0 );
   151    162     if( rc==SQLITE_OK ){
   152    163       memset(pTab, 0, sizeof(StatTable));
   153    164       pTab->db = db;
          165  +    pTab->iDb = iDb;
   154    166     }
   155    167   
   156    168     *ppVtab = (sqlite3_vtab*)pTab;
   157    169     return rc;
   158    170   }
   159    171   
   160    172   /*
................................................................................
   201    213     StatCursor *pCsr;
   202    214     int rc;
   203    215   
   204    216     pCsr = (StatCursor *)sqlite3_malloc64(sizeof(StatCursor));
   205    217     if( pCsr==0 ){
   206    218       rc = SQLITE_NOMEM;
   207    219     }else{
          220  +    char *zSql;
   208    221       memset(pCsr, 0, sizeof(StatCursor));
   209    222       pCsr->base.pVtab = pVTab;
   210    223   
   211         -    rc = sqlite3_prepare_v2(pTab->db, 
          224  +    zSql = sqlite3_mprintf(
   212    225           "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
   213    226           "  UNION ALL  "
   214         -        "SELECT name, rootpage, type FROM sqlite_master WHERE rootpage!=0"
   215         -        "  ORDER BY name", -1,
   216         -        &pCsr->pStmt, 0
   217         -        );
          227  +        "SELECT name, rootpage, type"
          228  +        "  FROM \"%w\".sqlite_master WHERE rootpage!=0"
          229  +        "  ORDER BY name", pTab->db->aDb[pTab->iDb].zName);
          230  +    if( zSql==0 ){
          231  +      rc = SQLITE_NOMEM;
          232  +    }else{
          233  +      rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
          234  +      sqlite3_free(zSql);
          235  +    }
   218    236       if( rc!=SQLITE_OK ){
   219    237         sqlite3_free(pCsr);
   220    238         pCsr = 0;
   221    239       }
   222    240     }
   223    241   
   224    242     *ppCursor = (sqlite3_vtab_cursor *)pCsr;
................................................................................
   376    394   
   377    395   /*
   378    396   ** Populate the pCsr->iOffset and pCsr->szPage member variables. Based on
   379    397   ** the current value of pCsr->iPageno.
   380    398   */
   381    399   static void statSizeAndOffset(StatCursor *pCsr){
   382    400     StatTable *pTab = (StatTable *)((sqlite3_vtab_cursor *)pCsr)->pVtab;
   383         -  Btree *pBt = pTab->db->aDb[0].pBt;
          401  +  Btree *pBt = pTab->db->aDb[pTab->iDb].pBt;
   384    402     Pager *pPager = sqlite3BtreePager(pBt);
   385    403     sqlite3_file *fd;
   386    404     sqlite3_int64 x[2];
   387    405   
   388    406     /* The default page size and offset */
   389    407     pCsr->szPage = sqlite3BtreeGetPageSize(pBt);
   390    408     pCsr->iOffset = (i64)pCsr->szPage * (pCsr->iPageno - 1);
   391    409   
   392    410     /* If connected to a ZIPVFS backend, override the page size and
   393    411     ** offset with actual values obtained from ZIPVFS.
   394    412     */
   395    413     fd = sqlite3PagerFile(pPager);
   396    414     x[0] = pCsr->iPageno;
   397         -  if( sqlite3OsFileControl(fd, 230440, &x)==SQLITE_OK ){
          415  +  if( fd->pMethods!=0 && sqlite3OsFileControl(fd, 230440, &x)==SQLITE_OK ){
   398    416       pCsr->iOffset = x[0];
   399    417       pCsr->szPage = (int)x[1];
   400    418     }
   401    419   }
   402    420   
   403    421   /*
   404    422   ** Move a statvfs cursor to the next entry in the file.
   405    423   */
   406    424   static int statNext(sqlite3_vtab_cursor *pCursor){
   407    425     int rc;
   408    426     int nPayload;
          427  +  char *z;
   409    428     StatCursor *pCsr = (StatCursor *)pCursor;
   410    429     StatTable *pTab = (StatTable *)pCursor->pVtab;
   411         -  Btree *pBt = pTab->db->aDb[0].pBt;
          430  +  Btree *pBt = pTab->db->aDb[pTab->iDb].pBt;
   412    431     Pager *pPager = sqlite3BtreePager(pBt);
   413    432   
   414    433     sqlite3_free(pCsr->zPath);
   415    434     pCsr->zPath = 0;
   416    435   
   417    436   statNextRestart:
   418    437     if( pCsr->aPage[0].pPg==0 ){
................................................................................
   424    443         if( nPage==0 ){
   425    444           pCsr->isEof = 1;
   426    445           return sqlite3_reset(pCsr->pStmt);
   427    446         }
   428    447         rc = sqlite3PagerGet(pPager, iRoot, &pCsr->aPage[0].pPg);
   429    448         pCsr->aPage[0].iPgno = iRoot;
   430    449         pCsr->aPage[0].iCell = 0;
   431         -      pCsr->aPage[0].zPath = sqlite3_mprintf("/");
          450  +      pCsr->aPage[0].zPath = z = sqlite3_mprintf("/");
   432    451         pCsr->iPage = 0;
          452  +      if( z==0 ) rc = SQLITE_NOMEM;
   433    453       }else{
   434    454         pCsr->isEof = 1;
   435    455         return sqlite3_reset(pCsr->pStmt);
   436    456       }
   437    457     }else{
   438    458   
   439    459       /* Page p itself has already been visited. */
................................................................................
   448    468                           sqlite3BtreeGetReserveNoMutex(pBt);
   449    469           sqlite3BtreeLeave(pBt);
   450    470           pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0);
   451    471           pCsr->iPageno = pCell->aOvfl[pCell->iOvfl];
   452    472           pCsr->zPagetype = "overflow";
   453    473           pCsr->nCell = 0;
   454    474           pCsr->nMxPayload = 0;
   455         -        pCsr->zPath = sqlite3_mprintf(
          475  +        pCsr->zPath = z = sqlite3_mprintf(
   456    476               "%s%.3x+%.6x", p->zPath, p->iCell, pCell->iOvfl
   457    477           );
   458    478           if( pCell->iOvfl<pCell->nOvfl-1 ){
   459    479             pCsr->nUnused = 0;
   460    480             pCsr->nPayload = nUsable - 4;
   461    481           }else{
   462    482             pCsr->nPayload = pCell->nLastOvfl;
   463    483             pCsr->nUnused = nUsable - 4 - pCsr->nPayload;
   464    484           }
   465    485           pCell->iOvfl++;
   466    486           statSizeAndOffset(pCsr);
   467         -        return SQLITE_OK;
          487  +        return z==0 ? SQLITE_NOMEM : SQLITE_OK;
   468    488         }
   469    489         if( p->iRightChildPg ) break;
   470    490         p->iCell++;
   471    491       }
   472    492   
   473    493       if( !p->iRightChildPg || p->iCell>p->nCell ){
   474    494         statClearPage(p);
................................................................................
   482    502       if( p->iCell==p->nCell ){
   483    503         p[1].iPgno = p->iRightChildPg;
   484    504       }else{
   485    505         p[1].iPgno = p->aCell[p->iCell].iChildPg;
   486    506       }
   487    507       rc = sqlite3PagerGet(pPager, p[1].iPgno, &p[1].pPg);
   488    508       p[1].iCell = 0;
   489         -    p[1].zPath = sqlite3_mprintf("%s%.3x/", p->zPath, p->iCell);
          509  +    p[1].zPath = z = sqlite3_mprintf("%s%.3x/", p->zPath, p->iCell);
   490    510       p->iCell++;
          511  +    if( z==0 ) rc = SQLITE_NOMEM;
   491    512     }
   492    513   
   493    514   
   494    515     /* Populate the StatCursor fields with the values to be returned
   495    516     ** by the xColumn() and xRowid() methods.
   496    517     */
   497    518     if( rc==SQLITE_OK ){
................................................................................
   516    537           default:
   517    538             pCsr->zPagetype = "corrupted";
   518    539             break;
   519    540         }
   520    541         pCsr->nCell = p->nCell;
   521    542         pCsr->nUnused = p->nUnused;
   522    543         pCsr->nMxPayload = p->nMxPayload;
   523         -      pCsr->zPath = sqlite3_mprintf("%s", p->zPath);
          544  +      pCsr->zPath = z = sqlite3_mprintf("%s", p->zPath);
          545  +      if( z==0 ) rc = SQLITE_NOMEM;
   524    546         nPayload = 0;
   525    547         for(i=0; i<p->nCell; i++){
   526    548           nPayload += p->aCell[i].nLocal;
   527    549         }
   528    550         pCsr->nPayload = nPayload;
   529    551       }
   530    552     }
................................................................................
   552    574     sqlite3_vtab_cursor *pCursor, 
   553    575     sqlite3_context *ctx, 
   554    576     int i
   555    577   ){
   556    578     StatCursor *pCsr = (StatCursor *)pCursor;
   557    579     switch( i ){
   558    580       case 0:            /* name */
   559         -      sqlite3_result_text(ctx, pCsr->zName, -1, SQLITE_STATIC);
          581  +      sqlite3_result_text(ctx, pCsr->zName, -1, SQLITE_TRANSIENT);
   560    582         break;
   561    583       case 1:            /* path */
   562    584         sqlite3_result_text(ctx, pCsr->zPath, -1, SQLITE_TRANSIENT);
   563    585         break;
   564    586       case 2:            /* pageno */
   565    587         sqlite3_result_int64(ctx, pCsr->iPageno);
   566    588         break;
................................................................................
   578    600         break;
   579    601       case 7:            /* mx_payload */
   580    602         sqlite3_result_int(ctx, pCsr->nMxPayload);
   581    603         break;
   582    604       case 8:            /* pgoffset */
   583    605         sqlite3_result_int64(ctx, pCsr->iOffset);
   584    606         break;
   585         -    case 9:            /* pgsize */
          607  +    default:           /* pgsize */
          608  +      assert( i==9 );
   586    609         sqlite3_result_int(ctx, pCsr->szPage);
   587    610         break;
   588    611     }
   589    612     return SQLITE_OK;
   590    613   }
   591    614   
   592    615   static int statRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
................................................................................
   594    617     *pRowid = pCsr->iPageno;
   595    618     return SQLITE_OK;
   596    619   }
   597    620   
   598    621   /*
   599    622   ** Invoke this routine to register the "dbstat" virtual table module
   600    623   */
   601         -int sqlite3_dbstat_register(sqlite3 *db){
          624  +int sqlite3DbstatRegister(sqlite3 *db){
   602    625     static sqlite3_module dbstat_module = {
   603    626       0,                            /* iVersion */
   604    627       statConnect,                  /* xCreate */
   605    628       statConnect,                  /* xConnect */
   606    629       statBestIndex,                /* xBestIndex */
   607    630       statDisconnect,               /* xDisconnect */
   608    631       statDisconnect,               /* xDestroy */
................................................................................
   619    642       0,                            /* xCommit */
   620    643       0,                            /* xRollback */
   621    644       0,                            /* xFindMethod */
   622    645       0,                            /* xRename */
   623    646     };
   624    647     return sqlite3_create_module(db, "dbstat", &dbstat_module, 0);
   625    648   }
          649  +#elif defined(SQLITE_ENABLE_DBSTAT_VTAB)
          650  +int sqlite3DbstatRegister(sqlite3 *db){ return SQLITE_OK; }
   626    651   #endif /* SQLITE_ENABLE_DBSTAT_VTAB */

Changes to src/main.c.

  2895   2895     if( !db->mallocFailed && rc==SQLITE_OK){
  2896   2896       rc = sqlite3RtreeInit(db);
  2897   2897     }
  2898   2898   #endif
  2899   2899   
  2900   2900   #ifdef SQLITE_ENABLE_DBSTAT_VTAB
  2901   2901     if( !db->mallocFailed && rc==SQLITE_OK){
  2902         -    int sqlite3_dbstat_register(sqlite3*);
  2903         -    rc = sqlite3_dbstat_register(db);
         2902  +    rc = sqlite3DbstatRegister(db);
  2904   2903     }
  2905   2904   #endif
  2906   2905   
  2907   2906     /* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
  2908   2907     ** mode.  -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
  2909   2908     ** mode.  Doing nothing at all also makes NORMAL the default.
  2910   2909     */

Changes to src/malloc.c.

   222    222     memset(&mem0, 0, sizeof(mem0));
   223    223   }
   224    224   
   225    225   /*
   226    226   ** Return the amount of memory currently checked out.
   227    227   */
   228    228   sqlite3_int64 sqlite3_memory_used(void){
   229         -  int n, mx;
   230         -  sqlite3_int64 res;
   231         -  sqlite3_status(SQLITE_STATUS_MEMORY_USED, &n, &mx, 0);
   232         -  res = (sqlite3_int64)n;  /* Work around bug in Borland C. Ticket #3216 */
          229  +  sqlite3_int64 res, mx;
          230  +  sqlite3_status64(SQLITE_STATUS_MEMORY_USED, &res, &mx, 0);
   233    231     return res;
   234    232   }
   235    233   
   236    234   /*
   237    235   ** Return the maximum amount of memory that has ever been
   238    236   ** checked out since either the beginning of this process
   239    237   ** or since the most recent reset.
   240    238   */
   241    239   sqlite3_int64 sqlite3_memory_highwater(int resetFlag){
   242         -  int n, mx;
   243         -  sqlite3_int64 res;
   244         -  sqlite3_status(SQLITE_STATUS_MEMORY_USED, &n, &mx, resetFlag);
   245         -  res = (sqlite3_int64)mx;  /* Work around bug in Borland C. Ticket #3216 */
   246         -  return res;
          240  +  sqlite3_int64 res, mx;
          241  +  sqlite3_status64(SQLITE_STATUS_MEMORY_USED, &res, &mx, resetFlag);
          242  +  return mx;
   247    243   }
   248    244   
   249    245   /*
   250    246   ** Trigger the alarm 
   251    247   */
   252    248   static void sqlite3MallocAlarm(int nByte){
   253    249     void (*xCallback)(void*,sqlite3_int64,int);

Changes to src/os_win.c.

  5407   5407       n += sizeof(i);
  5408   5408     }
  5409   5409   #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && SQLITE_WIN32_USE_UUID
  5410   5410     if( sizeof(UUID)<=nBuf-n ){
  5411   5411       UUID id;
  5412   5412       memset(&id, 0, sizeof(UUID));
  5413   5413       osUuidCreate(&id);
  5414         -    memcpy(zBuf, &id, sizeof(UUID));
         5414  +    memcpy(&zBuf[n], &id, sizeof(UUID));
  5415   5415       n += sizeof(UUID);
  5416   5416     }
  5417   5417     if( sizeof(UUID)<=nBuf-n ){
  5418   5418       UUID id;
  5419   5419       memset(&id, 0, sizeof(UUID));
  5420   5420       osUuidCreateSequential(&id);
  5421         -    memcpy(zBuf, &id, sizeof(UUID));
         5421  +    memcpy(&zBuf[n], &id, sizeof(UUID));
  5422   5422       n += sizeof(UUID);
  5423   5423     }
  5424   5424   #endif
  5425   5425   #endif /* defined(SQLITE_TEST) || defined(SQLITE_ZERO_PRNG_SEED) */
  5426   5426     return n;
  5427   5427   }
  5428   5428   

Changes to src/shell.c.

  3343   3343           fprintf(stderr, "unknown limit: \"%s\"\n"
  3344   3344                           "enter \".limits\" with no arguments for a list.\n",
  3345   3345                            azArg[1]);
  3346   3346           rc = 1;
  3347   3347           goto meta_command_exit;
  3348   3348         }
  3349   3349         if( nArg==3 ){
  3350         -        sqlite3_limit(p->db, aLimit[iLimit].limitCode, integerValue(azArg[2]));
         3350  +        sqlite3_limit(p->db, aLimit[iLimit].limitCode,
         3351  +                      (int)integerValue(azArg[2]));
  3351   3352         }
  3352   3353         printf("%20s %d\n", aLimit[iLimit].zLimitName,
  3353   3354                sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1));
  3354   3355       }
  3355   3356     }else
  3356   3357   
  3357   3358   #ifndef SQLITE_OMIT_LOAD_EXTENSION

Changes to src/sqlite.h.in.

  3889   3889   #define SQLITE3_TEXT     3
  3890   3890   
  3891   3891   /*
  3892   3892   ** CAPI3REF: Result Values From A Query
  3893   3893   ** KEYWORDS: {column access functions}
  3894   3894   ** METHOD: sqlite3_stmt
  3895   3895   **
  3896         -** These routines form the "result set" interface.
  3897         -**
  3898   3896   ** ^These routines return information about a single column of the current
  3899   3897   ** result row of a query.  ^In every case the first argument is a pointer
  3900   3898   ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
  3901   3899   ** that was returned from [sqlite3_prepare_v2()] or one of its variants)
  3902   3900   ** and the second argument is the index of the column for which information
  3903   3901   ** should be returned. ^The leftmost column of the result set has the index 0.
  3904   3902   ** ^The number of columns in the result can be determined using
................................................................................
  3950   3948   ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of
  3951   3949   ** bytes in the string, not the number of characters.
  3952   3950   **
  3953   3951   ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
  3954   3952   ** even empty strings, are always zero-terminated.  ^The return
  3955   3953   ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
  3956   3954   **
  3957         -** ^The object returned by [sqlite3_column_value()] is an
  3958         -** [unprotected sqlite3_value] object.  An unprotected sqlite3_value object
  3959         -** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()].
         3955  +** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an
         3956  +** [unprotected sqlite3_value] object.  In a multithreaded environment,
         3957  +** an unprotected sqlite3_value object may only be used safely with
         3958  +** [sqlite3_bind_value()] and [sqlite3_result_value()].
  3960   3959   ** If the [unprotected sqlite3_value] object returned by
  3961   3960   ** [sqlite3_column_value()] is used in any other way, including calls
  3962   3961   ** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
  3963         -** or [sqlite3_value_bytes()], then the behavior is undefined.
         3962  +** or [sqlite3_value_bytes()], the behavior is not threadsafe.
  3964   3963   **
  3965   3964   ** These routines attempt to convert the value where appropriate.  ^For
  3966   3965   ** example, if the internal representation is FLOAT and a text result
  3967   3966   ** is requested, [sqlite3_snprintf()] is used internally to perform the
  3968   3967   ** conversion automatically.  ^(The following table details the conversions
  3969   3968   ** that are applied:
  3970   3969   **
................................................................................
  3987   3986   ** <tr><td>  TEXT    <td>   BLOB    <td> No change
  3988   3987   ** <tr><td>  BLOB    <td> INTEGER   <td> [CAST] to INTEGER
  3989   3988   ** <tr><td>  BLOB    <td>  FLOAT    <td> [CAST] to REAL
  3990   3989   ** <tr><td>  BLOB    <td>   TEXT    <td> Add a zero terminator if needed
  3991   3990   ** </table>
  3992   3991   ** </blockquote>)^
  3993   3992   **
  3994         -** The table above makes reference to standard C library functions atoi()
  3995         -** and atof().  SQLite does not really use these functions.  It has its
  3996         -** own equivalent internal routines.  The atoi() and atof() names are
  3997         -** used in the table for brevity and because they are familiar to most
  3998         -** C programmers.
  3999         -**
  4000   3993   ** Note that when type conversions occur, pointers returned by prior
  4001   3994   ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
  4002   3995   ** sqlite3_column_text16() may be invalidated.
  4003   3996   ** Type conversions and pointer invalidations might occur
  4004   3997   ** in the following cases:
  4005   3998   **
  4006   3999   ** <ul>
................................................................................
  4017   4010   **
  4018   4011   ** ^Conversions between UTF-16be and UTF-16le are always done in place and do
  4019   4012   ** not invalidate a prior pointer, though of course the content of the buffer
  4020   4013   ** that the prior pointer references will have been modified.  Other kinds
  4021   4014   ** of conversion are done in place when it is possible, but sometimes they
  4022   4015   ** are not possible and in those cases prior pointers are invalidated.
  4023   4016   **
  4024         -** The safest and easiest to remember policy is to invoke these routines
         4017  +** The safest policy is to invoke these routines
  4025   4018   ** in one of the following ways:
  4026   4019   **
  4027   4020   ** <ul>
  4028   4021   **  <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
  4029   4022   **  <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
  4030   4023   **  <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
  4031   4024   ** </ul>
................................................................................
  4037   4030   ** to sqlite3_column_text() or sqlite3_column_blob() with calls to
  4038   4031   ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
  4039   4032   ** with calls to sqlite3_column_bytes().
  4040   4033   **
  4041   4034   ** ^The pointers returned are valid until a type conversion occurs as
  4042   4035   ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
  4043   4036   ** [sqlite3_finalize()] is called.  ^The memory space used to hold strings
  4044         -** and BLOBs is freed automatically.  Do <b>not</b> pass the pointers returned
         4037  +** and BLOBs is freed automatically.  Do <em>not</em> pass the pointers returned
  4045   4038   ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
  4046   4039   ** [sqlite3_free()].
  4047   4040   **
  4048   4041   ** ^(If a memory allocation error occurs during the evaluation of any
  4049   4042   ** of these routines, a default value is returned.  The default value
  4050   4043   ** is either the integer 0, the floating point number 0.0, or a NULL
  4051   4044   ** pointer.  Subsequent calls to [sqlite3_errcode()] will return

Changes to src/sqliteInt.h.

  3874   3874   /*
  3875   3875   ** Threading interface
  3876   3876   */
  3877   3877   #if SQLITE_MAX_WORKER_THREADS>0
  3878   3878   int sqlite3ThreadCreate(SQLiteThread**,void*(*)(void*),void*);
  3879   3879   int sqlite3ThreadJoin(SQLiteThread*, void**);
  3880   3880   #endif
         3881  +
         3882  +#if defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)
         3883  +int sqlite3DbstatRegister(sqlite3*);
         3884  +#endif
  3881   3885   
  3882   3886   #endif /* _SQLITEINT_H_ */

Changes to src/tclsqlite.c.

  3848   3848     }
  3849   3849     Tcl_SetResult(interp, zBuf, TCL_VOLATILE);
  3850   3850   
  3851   3851     return TCL_OK;
  3852   3852   }
  3853   3853   #endif /* SQLITE_TEST */
  3854   3854   
  3855         -#if defined(SQLITE_TEST) || defined(SQLITE_ENABLE_DBSTAT_VTAB)
  3856         -/*
  3857         -** tclcmd:   register_dbstat_vtab DB
  3858         -**
  3859         -** Cause the dbstat virtual table to be available on the connection DB
  3860         -*/
  3861         -static int sqlite3RegisterDbstatCmd(
  3862         -  void *clientData,
  3863         -  Tcl_Interp *interp,
  3864         -  int objc,
  3865         -  Tcl_Obj *CONST objv[]
  3866         -){
  3867         -#ifdef SQLITE_OMIT_VIRTUALTABLE
  3868         -  Tcl_AppendResult(interp, "dbstat not available because of "
  3869         -                           "SQLITE_OMIT_VIRTUALTABLE", (void*)0);
  3870         -  return TCL_ERROR;
  3871         -#else
  3872         -  struct SqliteDb { sqlite3 *db; };
  3873         -  char *zDb;
  3874         -  Tcl_CmdInfo cmdInfo;
  3875         -
  3876         -  if( objc!=2 ){
  3877         -    Tcl_WrongNumArgs(interp, 1, objv, "DB");
  3878         -    return TCL_ERROR;
  3879         -  }
  3880         -
  3881         -  zDb = Tcl_GetString(objv[1]);
  3882         -  if( Tcl_GetCommandInfo(interp, zDb, &cmdInfo) ){
  3883         -    int sqlite3_dbstat_register(sqlite3*);
  3884         -    sqlite3* db = ((struct SqliteDb*)cmdInfo.objClientData)->db;
  3885         -    sqlite3_dbstat_register(db);
  3886         -  }
  3887         -  return TCL_OK;
  3888         -#endif /* SQLITE_OMIT_VIRTUALTABLE */
  3889         -}
  3890         -#endif /* defined(SQLITE_TEST) || defined(SQLITE_ENABLE_DBSTAT_VTAB) */
  3891         -
  3892   3855   /*
  3893   3856   ** Configure the interpreter passed as the first argument to have access
  3894   3857   ** to the commands and linked variables that make up:
  3895   3858   **
  3896   3859   **   * the [sqlite3] extension itself, 
  3897   3860   **
  3898   3861   **   * If SQLITE_TCLMD5 or SQLITE_TEST is defined, the Md5 commands, and
................................................................................
  3901   3864   **     test suite.
  3902   3865   */
  3903   3866   static void init_all(Tcl_Interp *interp){
  3904   3867     Sqlite3_Init(interp);
  3905   3868   
  3906   3869   #if defined(SQLITE_TEST) || defined(SQLITE_TCLMD5)
  3907   3870     Md5_Init(interp);
  3908         -#endif
  3909         -
  3910         -  /* Install the [register_dbstat_vtab] command to access the implementation
  3911         -  ** of virtual table dbstat (source file test_stat.c). This command is
  3912         -  ** required for testfixture and sqlite3_analyzer, but not by the production
  3913         -  ** Tcl extension.  */
  3914         -#if defined(SQLITE_TEST) || defined(SQLITE_ENABLE_DBSTAT_VTAB)
  3915         -  Tcl_CreateObjCommand(
  3916         -      interp, "register_dbstat_vtab", sqlite3RegisterDbstatCmd, 0, 0
  3917         -  );
  3918   3871   #endif
  3919   3872   
  3920   3873   #ifdef SQLITE_TEST
  3921   3874     {
  3922   3875       extern int Sqliteconfig_Init(Tcl_Interp*);
  3923   3876       extern int Sqlitetest1_Init(Tcl_Interp*);
  3924   3877       extern int Sqlitetest2_Init(Tcl_Interp*);

Changes to src/test1.c.

  6676   6676       case 4: {
  6677   6677         Tcl_Panic("Deliberate panic");
  6678   6678         break;
  6679   6679       }
  6680   6680     }
  6681   6681     return TCL_OK;
  6682   6682   }  
  6683         -  
         6683  +
         6684  +/*
         6685  +** tclcmd:   register_dbstat_vtab DB
         6686  +**
         6687  +** Cause the dbstat virtual table to be available on the connection DB
         6688  +*/
         6689  +static int test_register_dbstat_vtab(
         6690  +  void *clientData,
         6691  +  Tcl_Interp *interp,
         6692  +  int objc,
         6693  +  Tcl_Obj *CONST objv[]
         6694  +){
         6695  +#ifdef SQLITE_OMIT_VIRTUALTABLE
         6696  +  Tcl_AppendResult(interp, "dbstat not available because of "
         6697  +                           "SQLITE_OMIT_VIRTUALTABLE", (void*)0);
         6698  +  return TCL_ERROR;
         6699  +#else
         6700  +  struct SqliteDb { sqlite3 *db; };
         6701  +  char *zDb;
         6702  +  Tcl_CmdInfo cmdInfo;
         6703  +
         6704  +  if( objc!=2 ){
         6705  +    Tcl_WrongNumArgs(interp, 1, objv, "DB");
         6706  +    return TCL_ERROR;
         6707  +  }
         6708  +
         6709  +  zDb = Tcl_GetString(objv[1]);
         6710  +  if( Tcl_GetCommandInfo(interp, zDb, &cmdInfo) ){
         6711  +    sqlite3* db = ((struct SqliteDb*)cmdInfo.objClientData)->db;
         6712  +    sqlite3DbstatRegister(db);
         6713  +  }
         6714  +  return TCL_OK;
         6715  +#endif /* SQLITE_OMIT_VIRTUALTABLE */
         6716  +}
  6684   6717   
  6685   6718   /*
  6686   6719   ** Register commands with the TCL interpreter.
  6687   6720   */
  6688   6721   int Sqlitetest1_Init(Tcl_Interp *interp){
  6689   6722     extern int sqlite3_search_count;
  6690   6723     extern int sqlite3_found_count;
................................................................................
  6748   6781     };
  6749   6782     static struct {
  6750   6783        char *zName;
  6751   6784        Tcl_ObjCmdProc *xProc;
  6752   6785        void *clientData;
  6753   6786     } aObjCmd[] = {
  6754   6787        { "bad_behavior",                  test_bad_behavior,  (void*)&iZero },
         6788  +     { "register_dbstat_vtab",          test_register_dbstat_vtab  },
  6755   6789        { "sqlite3_connection_pointer",    get_sqlite_pointer, 0 },
  6756   6790        { "sqlite3_bind_int",              test_bind_int,      0 },
  6757   6791        { "sqlite3_bind_zeroblob",         test_bind_zeroblob, 0 },
  6758   6792        { "sqlite3_bind_int64",            test_bind_int64,    0 },
  6759   6793        { "sqlite3_bind_double",           test_bind_double,   0 },
  6760   6794        { "sqlite3_bind_null",             test_bind_null     ,0 },
  6761   6795        { "sqlite3_bind_text",             test_bind_text     ,0 },

Changes to src/where.c.

   359    359   ** "=", "<", ">", "<=", ">=", "IN", and "IS NULL"
   360    360   */
   361    361   static int allowedOp(int op){
   362    362     assert( TK_GT>TK_EQ && TK_GT<TK_GE );
   363    363     assert( TK_LT>TK_EQ && TK_LT<TK_GE );
   364    364     assert( TK_LE>TK_EQ && TK_LE<TK_GE );
   365    365     assert( TK_GE==TK_EQ+4 );
   366         -  return op==TK_IN || (op>=TK_EQ && op<=TK_GE) || op==TK_ISNULL;
          366  +  return op==TK_IN || (op>=TK_EQ && op<=TK_GE) || op==TK_ISNULL || op==TK_IS;
   367    367   }
   368    368   
   369    369   /*
   370    370   ** Commute a comparison operator.  Expressions of the form "X op Y"
   371    371   ** are converted into "Y op X".
   372    372   **
   373    373   ** If left/right precedence rules come into play when determining the
................................................................................
   412    412   static u16 operatorMask(int op){
   413    413     u16 c;
   414    414     assert( allowedOp(op) );
   415    415     if( op==TK_IN ){
   416    416       c = WO_IN;
   417    417     }else if( op==TK_ISNULL ){
   418    418       c = WO_ISNULL;
          419  +  }else if( op==TK_IS ){
          420  +    c = WO_IS;
   419    421     }else{
   420    422       assert( (WO_EQ<<(op-TK_EQ)) < 0x7fff );
   421    423       c = (u16)(WO_EQ<<(op-TK_EQ));
   422    424     }
   423    425     assert( op!=TK_ISNULL || c==WO_ISNULL );
   424    426     assert( op!=TK_IN || c==WO_IN );
   425    427     assert( op!=TK_EQ || c==WO_EQ );
   426    428     assert( op!=TK_LT || c==WO_LT );
   427    429     assert( op!=TK_LE || c==WO_LE );
   428    430     assert( op!=TK_GT || c==WO_GT );
   429    431     assert( op!=TK_GE || c==WO_GE );
          432  +  assert( op!=TK_IS || c==WO_IS );
   430    433     return c;
   431    434   }
   432    435   
   433    436   /*
   434    437   ** Advance to the next WhereTerm that matches according to the criteria
   435    438   ** established when the pScan object was initialized by whereScanInit().
   436    439   ** Return NULL if there are no more matching WhereTerms.
................................................................................
   483    486                 pColl = sqlite3BinaryCompareCollSeq(pParse,
   484    487                                                     pX->pLeft, pX->pRight);
   485    488                 if( pColl==0 ) pColl = pParse->db->pDfltColl;
   486    489                 if( sqlite3StrICmp(pColl->zName, pScan->zCollName) ){
   487    490                   continue;
   488    491                 }
   489    492               }
   490         -            if( (pTerm->eOperator & WO_EQ)!=0
          493  +            if( (pTerm->eOperator & (WO_EQ|WO_IS))!=0
   491    494                && (pX = pTerm->pExpr->pRight)->op==TK_COLUMN
   492    495                && pX->iTable==pScan->aEquiv[0]
   493    496                && pX->iColumn==pScan->aEquiv[1]
   494    497               ){
          498  +              testcase( pTerm->eOperator & WO_IS );
   495    499                 continue;
   496    500               }
   497    501               pScan->k = k+1;
   498    502               return pTerm;
   499    503             }
   500    504           }
   501    505         }
................................................................................
   589    593     Index *pIdx           /* Must be compatible with this index, if not NULL */
   590    594   ){
   591    595     WhereTerm *pResult = 0;
   592    596     WhereTerm *p;
   593    597     WhereScan scan;
   594    598   
   595    599     p = whereScanInit(&scan, pWC, iCur, iColumn, op, pIdx);
          600  +  op &= WO_EQ|WO_IS;
   596    601     while( p ){
   597    602       if( (p->prereqRight & notReady)==0 ){
   598         -      if( p->prereqRight==0 && (p->eOperator&WO_EQ)!=0 ){
          603  +      if( p->prereqRight==0 && (p->eOperator&op)!=0 ){
          604  +        testcase( p->eOperator & WO_IS );
   599    605           return p;
   600    606         }
   601    607         if( pResult==0 ) pResult = p;
   602    608       }
   603    609       p = whereScanNext(&scan);
   604    610     }
   605    611     return pResult;
................................................................................
  1250   1256       Expr *pRight = sqlite3ExprSkipCollate(pExpr->pRight);
  1251   1257       u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
  1252   1258       if( pLeft->op==TK_COLUMN ){
  1253   1259         pTerm->leftCursor = pLeft->iTable;
  1254   1260         pTerm->u.leftColumn = pLeft->iColumn;
  1255   1261         pTerm->eOperator = operatorMask(op) & opMask;
  1256   1262       }
         1263  +    if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
  1257   1264       if( pRight && pRight->op==TK_COLUMN ){
  1258   1265         WhereTerm *pNew;
  1259   1266         Expr *pDup;
  1260   1267         u16 eExtraOp = 0;        /* Extra bits for pNew->eOperator */
  1261   1268         if( pTerm->leftCursor>=0 ){
  1262   1269           int idxNew;
  1263   1270           pDup = sqlite3ExprDup(db, pExpr, 0);
................................................................................
  1267   1274           }
  1268   1275           idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC);
  1269   1276           if( idxNew==0 ) return;
  1270   1277           pNew = &pWC->a[idxNew];
  1271   1278           markTermAsChild(pWC, idxNew, idxTerm);
  1272   1279           pTerm = &pWC->a[idxTerm];
  1273   1280           pTerm->wtFlags |= TERM_COPIED;
  1274         -        if( pExpr->op==TK_EQ
         1281  +        if( (op==TK_EQ || op==TK_IS)
  1275   1282            && !ExprHasProperty(pExpr, EP_FromJoin)
  1276   1283            && OptimizationEnabled(db, SQLITE_Transitive)
  1277   1284           ){
  1278   1285             pTerm->eOperator |= WO_EQUIV;
  1279   1286             eExtraOp = WO_EQUIV;
  1280   1287           }
         1288  +        if( op==TK_IS ) pNew->wtFlags |= TERM_IS;
  1281   1289         }else{
  1282   1290           pDup = pExpr;
  1283   1291           pNew = pTerm;
  1284   1292         }
  1285   1293         exprCommute(pParse, pDup);
  1286   1294         pLeft = sqlite3ExprSkipCollate(pDup->pLeft);
  1287   1295         pNew->leftCursor = pLeft->iTable;
................................................................................
  1464   1472   
  1465   1473   #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
  1466   1474     /* When sqlite_stat3 histogram data is available an operator of the
  1467   1475     ** form "x IS NOT NULL" can sometimes be evaluated more efficiently
  1468   1476     ** as "x>NULL" if x is not an INTEGER PRIMARY KEY.  So construct a
  1469   1477     ** virtual term of that form.
  1470   1478     **
  1471         -  ** Note that the virtual term must be tagged with TERM_VNULL.  This
  1472         -  ** TERM_VNULL tag will suppress the not-null check at the beginning
  1473         -  ** of the loop.  Without the TERM_VNULL flag, the not-null check at
  1474         -  ** the start of the loop will prevent any results from being returned.
         1479  +  ** Note that the virtual term must be tagged with TERM_VNULL.
  1475   1480     */
  1476   1481     if( pExpr->op==TK_NOTNULL
  1477   1482      && pExpr->pLeft->op==TK_COLUMN
  1478   1483      && pExpr->pLeft->iColumn>=0
  1479   1484      && OptimizationEnabled(db, SQLITE_Stat34)
  1480   1485     ){
  1481   1486       Expr *pNewExpr;
................................................................................
  1671   1676   static int termCanDriveIndex(
  1672   1677     WhereTerm *pTerm,              /* WHERE clause term to check */
  1673   1678     struct SrcList_item *pSrc,     /* Table we are trying to access */
  1674   1679     Bitmask notReady               /* Tables in outer loops of the join */
  1675   1680   ){
  1676   1681     char aff;
  1677   1682     if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
  1678         -  if( (pTerm->eOperator & WO_EQ)==0 ) return 0;
         1683  +  if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) return 0;
  1679   1684     if( (pTerm->prereqRight & notReady)!=0 ) return 0;
  1680   1685     if( pTerm->u.leftColumn<0 ) return 0;
  1681   1686     aff = pSrc->pTab->aCol[pTerm->u.leftColumn].affinity;
  1682   1687     if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0;
         1688  +  testcase( pTerm->pExpr->op==TK_IS );
  1683   1689     return 1;
  1684   1690   }
  1685   1691   #endif
  1686   1692   
  1687   1693   
  1688   1694   #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
  1689   1695   /*
................................................................................
  1892   1898     /* Count the number of possible WHERE clause constraints referring
  1893   1899     ** to this virtual table */
  1894   1900     for(i=nTerm=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
  1895   1901       if( pTerm->leftCursor != pSrc->iCursor ) continue;
  1896   1902       assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
  1897   1903       testcase( pTerm->eOperator & WO_IN );
  1898   1904       testcase( pTerm->eOperator & WO_ISNULL );
         1905  +    testcase( pTerm->eOperator & WO_IS );
  1899   1906       testcase( pTerm->eOperator & WO_ALL );
  1900         -    if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV))==0 ) continue;
         1907  +    if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV|WO_IS))==0 ) continue;
  1901   1908       if( pTerm->wtFlags & TERM_VNULL ) continue;
  1902   1909       nTerm++;
  1903   1910     }
  1904   1911   
  1905   1912     /* If the ORDER BY clause contains only columns in the current 
  1906   1913     ** virtual table then allocate space for the aOrderBy part of
  1907   1914     ** the sqlite3_index_info structure.
................................................................................
  1944   1951                                                                      pUsage;
  1945   1952   
  1946   1953     for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
  1947   1954       u8 op;
  1948   1955       if( pTerm->leftCursor != pSrc->iCursor ) continue;
  1949   1956       assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
  1950   1957       testcase( pTerm->eOperator & WO_IN );
         1958  +    testcase( pTerm->eOperator & WO_IS );
  1951   1959       testcase( pTerm->eOperator & WO_ISNULL );
  1952   1960       testcase( pTerm->eOperator & WO_ALL );
  1953         -    if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV))==0 ) continue;
         1961  +    if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV|WO_IS))==0 ) continue;
  1954   1962       if( pTerm->wtFlags & TERM_VNULL ) continue;
  1955   1963       pIdxCons[j].iColumn = pTerm->u.leftColumn;
  1956   1964       pIdxCons[j].iTermOffset = i;
  1957   1965       op = (u8)pTerm->eOperator & WO_ALL;
  1958   1966       if( op==WO_IN ) op = WO_EQ;
  1959   1967       pIdxCons[j].op = op;
  1960   1968       /* The direct assignment in the previous line is possible only because
................................................................................
  2788   2796     int iTarget         /* Attempt to leave results in this register */
  2789   2797   ){
  2790   2798     Expr *pX = pTerm->pExpr;
  2791   2799     Vdbe *v = pParse->pVdbe;
  2792   2800     int iReg;                  /* Register holding results */
  2793   2801   
  2794   2802     assert( iTarget>0 );
  2795         -  if( pX->op==TK_EQ ){
         2803  +  if( pX->op==TK_EQ || pX->op==TK_IS ){
  2796   2804       iReg = sqlite3ExprCodeTarget(pParse, pX->pRight, iTarget);
  2797   2805     }else if( pX->op==TK_ISNULL ){
  2798   2806       iReg = iTarget;
  2799   2807       sqlite3VdbeAddOp2(v, OP_Null, 0, iReg);
  2800   2808   #ifndef SQLITE_OMIT_SUBQUERY
  2801   2809     }else{
  2802   2810       int eType;
................................................................................
  2973   2981           sqlite3VdbeAddOp2(v, OP_SCopy, r1, regBase+j);
  2974   2982         }
  2975   2983       }
  2976   2984       testcase( pTerm->eOperator & WO_ISNULL );
  2977   2985       testcase( pTerm->eOperator & WO_IN );
  2978   2986       if( (pTerm->eOperator & (WO_ISNULL|WO_IN))==0 ){
  2979   2987         Expr *pRight = pTerm->pExpr->pRight;
  2980         -      if( sqlite3ExprCanBeNull(pRight) ){
         2988  +      if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){
  2981   2989           sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
  2982   2990           VdbeCoverage(v);
  2983   2991         }
  2984   2992         if( zAff ){
  2985   2993           if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_NONE ){
  2986   2994             zAff[j] = SQLITE_AFF_NONE;
  2987   2995           }
................................................................................
  4095   4103     ** then we cannot use the "t1.a=t2.b" constraint, but we can code
  4096   4104     ** the implied "t1.a=123" constraint.
  4097   4105     */
  4098   4106     for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
  4099   4107       Expr *pE, *pEAlt;
  4100   4108       WhereTerm *pAlt;
  4101   4109       if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
  4102         -    if( pTerm->eOperator!=(WO_EQUIV|WO_EQ) ) continue;
         4110  +    if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) continue;
         4111  +    if( (pTerm->eOperator & WO_EQUIV)==0 ) continue;
  4103   4112       if( pTerm->leftCursor!=iCur ) continue;
  4104   4113       if( pLevel->iLeftJoin ) continue;
  4105   4114       pE = pTerm->pExpr;
  4106   4115       assert( !ExprHasProperty(pE, EP_FromJoin) );
  4107   4116       assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
  4108         -    pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady, WO_EQ|WO_IN, 0);
         4117  +    pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady,
         4118  +                    WO_EQ|WO_IN|WO_IS, 0);
  4109   4119       if( pAlt==0 ) continue;
  4110   4120       if( pAlt->wtFlags & (TERM_CODED) ) continue;
  4111   4121       testcase( pAlt->eOperator & WO_EQ );
         4122  +    testcase( pAlt->eOperator & WO_IS );
  4112   4123       testcase( pAlt->eOperator & WO_IN );
  4113   4124       VdbeModuleComment((v, "begin transitive constraint"));
  4114   4125       pEAlt = sqlite3StackAllocRaw(db, sizeof(*pEAlt));
  4115   4126       if( pEAlt ){
  4116   4127         *pEAlt = *pAlt->pExpr;
  4117   4128         pEAlt->pLeft = pE->pLeft;
  4118   4129         sqlite3ExprIfFalse(pParse, pEAlt, addrCont, SQLITE_JUMPIFNULL);
................................................................................
  4154   4165       sqlite3DebugPrintf("TERM-%-3d NULL\n", iTerm);
  4155   4166     }else{
  4156   4167       char zType[4];
  4157   4168       memcpy(zType, "...", 4);
  4158   4169       if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
  4159   4170       if( pTerm->eOperator & WO_EQUIV  ) zType[1] = 'E';
  4160   4171       if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';
  4161         -    sqlite3DebugPrintf("TERM-%-3d %p %s cursor=%-3d prob=%-3d op=0x%03x\n",
  4162         -                       iTerm, pTerm, zType, pTerm->leftCursor, pTerm->truthProb,
  4163         -                       pTerm->eOperator);
         4172  +    sqlite3DebugPrintf(
         4173  +       "TERM-%-3d %p %s cursor=%-3d prob=%-3d op=0x%03x wtFlags=0x%04x\n",
         4174  +       iTerm, pTerm, zType, pTerm->leftCursor, pTerm->truthProb,
         4175  +       pTerm->eOperator, pTerm->wtFlags);
  4164   4176       sqlite3TreeViewExpr(0, pTerm->pExpr, 0);
  4165   4177     }
  4166   4178   }
  4167   4179   #endif
  4168   4180   
  4169   4181   #ifdef WHERETRACE_ENABLED
  4170   4182   /*
................................................................................
  4646   4658           /* If a truth probability is specified using the likelihood() hints,
  4647   4659           ** then use the probability provided by the application. */
  4648   4660           pLoop->nOut += pTerm->truthProb;
  4649   4661         }else{
  4650   4662           /* In the absence of explicit truth probabilities, use heuristics to
  4651   4663           ** guess a reasonable truth probability. */
  4652   4664           pLoop->nOut--;
  4653         -        if( pTerm->eOperator&WO_EQ ){
         4665  +        if( pTerm->eOperator&(WO_EQ|WO_IS) ){
  4654   4666             Expr *pRight = pTerm->pExpr->pRight;
         4667  +          testcase( pTerm->pExpr->op==TK_IS );
  4655   4668             if( sqlite3ExprIsInteger(pRight, &k) && k>=(-1) && k<=1 ){
  4656   4669               k = 10;
  4657   4670             }else{
  4658   4671               k = 20;
  4659   4672             }
  4660   4673             if( iReduce<k ) iReduce = k;
  4661   4674           }
................................................................................
  4715   4728     pNew = pBuilder->pNew;
  4716   4729     if( db->mallocFailed ) return SQLITE_NOMEM;
  4717   4730   
  4718   4731     assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
  4719   4732     assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 );
  4720   4733     if( pNew->wsFlags & WHERE_BTM_LIMIT ){
  4721   4734       opMask = WO_LT|WO_LE;
  4722         -  }else if( pProbe->tnum<=0 || (pSrc->jointype & JT_LEFT)!=0 ){
         4735  +  }else if( /*pProbe->tnum<=0 ||*/ (pSrc->jointype & JT_LEFT)!=0 ){
  4723   4736       opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE;
  4724   4737     }else{
  4725         -    opMask = WO_EQ|WO_IN|WO_ISNULL|WO_GT|WO_GE|WO_LT|WO_LE;
         4738  +    opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE|WO_ISNULL|WO_IS;
  4726   4739     }
  4727   4740     if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE);
  4728   4741   
  4729   4742     assert( pNew->u.btree.nEq<pProbe->nColumn );
  4730   4743     iCol = pProbe->aiColumn[pNew->u.btree.nEq];
  4731   4744   
  4732   4745     pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol,
................................................................................
  4781   4794         }else if( ALWAYS(pExpr->x.pList && pExpr->x.pList->nExpr) ){
  4782   4795           /* "x IN (value, value, ...)" */
  4783   4796           nIn = sqlite3LogEst(pExpr->x.pList->nExpr);
  4784   4797         }
  4785   4798         assert( nIn>0 );  /* RHS always has 2 or more terms...  The parser
  4786   4799                           ** changes "x IN (?)" into "x=?". */
  4787   4800   
  4788         -    }else if( eOp & (WO_EQ) ){
         4801  +    }else if( eOp & (WO_EQ|WO_IS) ){
  4789   4802         pNew->wsFlags |= WHERE_COLUMN_EQ;
  4790   4803         if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){
  4791   4804           if( iCol>=0 && pProbe->uniqNotNull==0 ){
  4792   4805             pNew->wsFlags |= WHERE_UNQ_WANTED;
  4793   4806           }else{
  4794   4807             pNew->wsFlags |= WHERE_ONEROW;
  4795   4808           }
................................................................................
  4831   4844       assert( pNew->nOut==saved_nOut );
  4832   4845       if( pNew->wsFlags & WHERE_COLUMN_RANGE ){
  4833   4846         /* Adjust nOut using stat3/stat4 data. Or, if there is no stat3/stat4
  4834   4847         ** data, using some other estimate.  */
  4835   4848         whereRangeScanEst(pParse, pBuilder, pBtm, pTop, pNew);
  4836   4849       }else{
  4837   4850         int nEq = ++pNew->u.btree.nEq;
  4838         -      assert( eOp & (WO_ISNULL|WO_EQ|WO_IN) );
         4851  +      assert( eOp & (WO_ISNULL|WO_EQ|WO_IN|WO_IS) );
  4839   4852   
  4840   4853         assert( pNew->nOut==saved_nOut );
  4841   4854         if( pTerm->truthProb<=0 && iCol>=0 ){
  4842   4855           assert( (eOp & WO_IN) || nIn==0 );
  4843   4856           testcase( eOp & WO_IN );
  4844   4857           pNew->nOut += pTerm->truthProb;
  4845   4858           pNew->nOut -= nIn;
................................................................................
  4848   4861           tRowcnt nOut = 0;
  4849   4862           if( nInMul==0 
  4850   4863            && pProbe->nSample 
  4851   4864            && pNew->u.btree.nEq<=pProbe->nSampleCol
  4852   4865            && ((eOp & WO_IN)==0 || !ExprHasProperty(pTerm->pExpr, EP_xIsSelect))
  4853   4866           ){
  4854   4867             Expr *pExpr = pTerm->pExpr;
  4855         -          if( (eOp & (WO_EQ|WO_ISNULL))!=0 ){
         4868  +          if( (eOp & (WO_EQ|WO_ISNULL|WO_IS))!=0 ){
  4856   4869               testcase( eOp & WO_EQ );
         4870  +            testcase( eOp & WO_IS );
  4857   4871               testcase( eOp & WO_ISNULL );
  4858   4872               rc = whereEqualScanEst(pParse, pBuilder, pExpr->pRight, &nOut);
  4859   4873             }else{
  4860   4874               rc = whereInScanEst(pParse, pBuilder, pExpr->x.pList, &nOut);
  4861   4875             }
  4862   4876             if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
  4863   4877             if( rc!=SQLITE_OK ) break;          /* Jump out of the pTerm loop */
................................................................................
  5686   5700       */
  5687   5701       for(i=0; i<nOrderBy; i++){
  5688   5702         if( MASKBIT(i) & obSat ) continue;
  5689   5703         pOBExpr = sqlite3ExprSkipCollate(pOrderBy->a[i].pExpr);
  5690   5704         if( pOBExpr->op!=TK_COLUMN ) continue;
  5691   5705         if( pOBExpr->iTable!=iCur ) continue;
  5692   5706         pTerm = findTerm(&pWInfo->sWC, iCur, pOBExpr->iColumn,
  5693         -                       ~ready, WO_EQ|WO_ISNULL, 0);
         5707  +                       ~ready, WO_EQ|WO_ISNULL|WO_IS, 0);
  5694   5708         if( pTerm==0 ) continue;
  5695         -      if( (pTerm->eOperator&WO_EQ)!=0 && pOBExpr->iColumn>=0 ){
         5709  +      if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0 && pOBExpr->iColumn>=0 ){
  5696   5710           const char *z1, *z2;
  5697   5711           pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr);
  5698   5712           if( !pColl ) pColl = db->pDfltColl;
  5699   5713           z1 = pColl->zName;
  5700   5714           pColl = sqlite3ExprCollSeq(pWInfo->pParse, pTerm->pExpr);
  5701   5715           if( !pColl ) pColl = db->pDfltColl;
  5702   5716           z2 = pColl->zName;
  5703   5717           if( sqlite3StrICmp(z1, z2)!=0 ) continue;
         5718  +        testcase( pTerm->pExpr->op==TK_IS );
  5704   5719         }
  5705   5720         obSat |= MASKBIT(i);
  5706   5721       }
  5707   5722   
  5708   5723       if( (pLoop->wsFlags & WHERE_ONEROW)==0 ){
  5709   5724         if( pLoop->wsFlags & WHERE_IPK ){
  5710   5725           pIndex = 0;
................................................................................
  5727   5742         distinctColumns = 0;
  5728   5743         for(j=0; j<nColumn; j++){
  5729   5744           u8 bOnce;   /* True to run the ORDER BY search loop */
  5730   5745   
  5731   5746           /* Skip over == and IS NULL terms */
  5732   5747           if( j<pLoop->u.btree.nEq
  5733   5748            && pLoop->nSkip==0
  5734         -         && ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0
         5749  +         && ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL|WO_IS))!=0
  5735   5750           ){
  5736   5751             if( i & WO_ISNULL ){
  5737   5752               testcase( isOrderDistinct );
  5738   5753               isOrderDistinct = 0;
  5739   5754             }
  5740   5755             continue;  
  5741   5756           }
................................................................................
  6300   6315     if( IsVirtual(pTab) ) return 0;
  6301   6316     if( pItem->zIndex ) return 0;
  6302   6317     iCur = pItem->iCursor;
  6303   6318     pWC = &pWInfo->sWC;
  6304   6319     pLoop = pBuilder->pNew;
  6305   6320     pLoop->wsFlags = 0;
  6306   6321     pLoop->nSkip = 0;
  6307         -  pTerm = findTerm(pWC, iCur, -1, 0, WO_EQ, 0);
         6322  +  pTerm = findTerm(pWC, iCur, -1, 0, WO_EQ|WO_IS, 0);
  6308   6323     if( pTerm ){
         6324  +    testcase( pTerm->eOperator & WO_IS );
  6309   6325       pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW;
  6310   6326       pLoop->aLTerm[0] = pTerm;
  6311   6327       pLoop->nLTerm = 1;
  6312   6328       pLoop->u.btree.nEq = 1;
  6313   6329       /* TUNING: Cost of a rowid lookup is 10 */
  6314   6330       pLoop->rRun = 33;  /* 33==sqlite3LogEst(10) */
  6315   6331     }else{
................................................................................
  6316   6332       for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
  6317   6333         assert( pLoop->aLTermSpace==pLoop->aLTerm );
  6318   6334         if( !IsUniqueIndex(pIdx)
  6319   6335          || pIdx->pPartIdxWhere!=0 
  6320   6336          || pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace) 
  6321   6337         ) continue;
  6322   6338         for(j=0; j<pIdx->nKeyCol; j++){
  6323         -        pTerm = findTerm(pWC, iCur, pIdx->aiColumn[j], 0, WO_EQ, pIdx);
         6339  +        pTerm = findTerm(pWC, iCur, pIdx->aiColumn[j], 0, WO_EQ|WO_IS, pIdx);
  6324   6340           if( pTerm==0 ) break;
         6341  +         testcase( pTerm->eOperator & WO_IS );
  6325   6342           pLoop->aLTerm[j] = pTerm;
  6326   6343         }
  6327   6344         if( j!=pIdx->nKeyCol ) continue;
  6328   6345         pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_ONEROW|WHERE_INDEXED;
  6329   6346         if( pIdx->isCovering || (pItem->colUsed & ~columnsInIndex(pIdx))==0 ){
  6330   6347           pLoop->wsFlags |= WHERE_IDX_ONLY;
  6331   6348         }

Changes to src/whereInt.h.

   276    276   #  define TERM_VNULL    0x80   /* Manufactured x>NULL or x<=NULL term */
   277    277   #else
   278    278   #  define TERM_VNULL    0x00   /* Disabled if not using stat3 */
   279    279   #endif
   280    280   #define TERM_LIKEOPT    0x100  /* Virtual terms from the LIKE optimization */
   281    281   #define TERM_LIKECOND   0x200  /* Conditionally this LIKE operator term */
   282    282   #define TERM_LIKE       0x400  /* The original LIKE operator */
          283  +#define TERM_IS         0x800  /* Term.pExpr is an IS operator */
   283    284   
   284    285   /*
   285    286   ** An instance of the WhereScan object is used as an iterator for locating
   286    287   ** terms in the WHERE clause that are useful to the query planner.
   287    288   */
   288    289   struct WhereScan {
   289    290     WhereClause *pOrigWC;      /* Original, innermost WhereClause */
................................................................................
   424    425   
   425    426   /*
   426    427   ** Bitmasks for the operators on WhereTerm objects.  These are all
   427    428   ** operators that are of interest to the query planner.  An
   428    429   ** OR-ed combination of these values can be used when searching for
   429    430   ** particular WhereTerms within a WhereClause.
   430    431   */
   431         -#define WO_IN     0x001
   432         -#define WO_EQ     0x002
          432  +#define WO_IN     0x0001
          433  +#define WO_EQ     0x0002
   433    434   #define WO_LT     (WO_EQ<<(TK_LT-TK_EQ))
   434    435   #define WO_LE     (WO_EQ<<(TK_LE-TK_EQ))
   435    436   #define WO_GT     (WO_EQ<<(TK_GT-TK_EQ))
   436    437   #define WO_GE     (WO_EQ<<(TK_GE-TK_EQ))
   437         -#define WO_MATCH  0x040
   438         -#define WO_ISNULL 0x080
   439         -#define WO_OR     0x100       /* Two or more OR-connected terms */
   440         -#define WO_AND    0x200       /* Two or more AND-connected terms */
   441         -#define WO_EQUIV  0x400       /* Of the form A==B, both columns */
   442         -#define WO_NOOP   0x800       /* This term does not restrict search space */
          438  +#define WO_MATCH  0x0040
          439  +#define WO_IS     0x0080
          440  +#define WO_ISNULL 0x0100
          441  +#define WO_OR     0x0200       /* Two or more OR-connected terms */
          442  +#define WO_AND    0x0400       /* Two or more AND-connected terms */
          443  +#define WO_EQUIV  0x0800       /* Of the form A==B, both columns */
          444  +#define WO_NOOP   0x1000       /* This term does not restrict search space */
   443    445   
   444         -#define WO_ALL    0xfff       /* Mask of all possible WO_* values */
   445         -#define WO_SINGLE 0x0ff       /* Mask of all non-compound WO_* values */
          446  +#define WO_ALL    0x1fff       /* Mask of all possible WO_* values */
          447  +#define WO_SINGLE 0x01ff       /* Mask of all non-compound WO_* values */
   446    448   
   447    449   /*
   448    450   ** These are definitions of bits in the WhereLoop.wsFlags field.
   449    451   ** The particular combination of bits in each WhereLoop help to
   450    452   ** determine the algorithm that WhereLoop represents.
   451    453   */
   452    454   #define WHERE_COLUMN_EQ    0x00000001  /* x=EXPR */

Added test/analyzer1.test.

            1  +# 2015-05-11
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +#
           12  +# Quick tests for the sqlite3_analyzer tool
           13  +#
           14  +set testdir [file dirname $argv0]
           15  +source $testdir/tester.tcl
           16  +
           17  +ifcapable !vtab {
           18  +  finish_test
           19  +  return
           20  +}
           21  +
           22  +if {$tcl_platform(platform)=="windows"} {
           23  +  set PROG "sqlite3_analyzer.exe"
           24  +} else {
           25  +  set PROG "./sqlite3_analyzer"
           26  +}
           27  +db close
           28  +forcedelete test.db test.db-journal test.db-wal
           29  +sqlite3 db test.db
           30  +
           31  +do_test analyzer1-1.0 {
           32  +  db eval {
           33  +    CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
           34  +    CREATE TABLE t2(a INT PRIMARY KEY, b) WITHOUT ROWID;
           35  +    WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<250)
           36  +    INSERT INTO t1(a,b) SELECT x, randomblob(200) FROM c;
           37  +    INSERT INTO t2(a,b) SELECT a, b FROM t1;
           38  +  }
           39  +  set line "exec $PROG test.db"
           40  +  unset -nocomplain ::MSG
           41  +  catch {eval $line} ::MSG
           42  +} {0}
           43  +do_test analyzer1-1.1 {
           44  +  regexp {^/\*\* Disk-Space Utilization.*COMMIT;\W*$} $::MSG
           45  +} {1}
           46  +
           47  +finish_test

Changes to test/fts3matchinfo.test.

   503    503     7 "a OR (a AND b)" {
   504    504         1 {1 2 1 2 0 1}   2 {1 0 1 0 1 0}   3 {0 1 0 1 1 2}   4 {1 0 1 0 0 1}   
   505    505         5 {1 0 1 0 0 1}   6 {1 0 1 0 2 2}   7 {2 1 0 0 0 0}   8 {1 2 1 2 2 1}   
   506    506         9 {1 1 1 1 1 3}  10 {1 3 0 0 0 0}
   507    507     }
   508    508   
   509    509   } {
   510         -  do_execsql_test 11.1.$tn  {
          510  +  do_execsql_test 11.1.$tn.1  {
   511    511       SELECT rowid, mit(matchinfo(tt, 'y')) FROM tt WHERE tt MATCH $expr
   512    512     } $res
          513  +
          514  +  set r2 [list]
          515  +  foreach {rowid L} $res {
          516  +    lappend r2 $rowid
          517  +    set M [list]
          518  +    foreach {a b} $L {
          519  +      lappend M [expr ($a ? 1 : 0) + ($b ? 2 : 0)]
          520  +    }
          521  +    lappend r2 $M
          522  +  }
          523  +
          524  +  do_execsql_test 11.1.$tn.2  {
          525  +    SELECT rowid, mit(matchinfo(tt, 'b')) FROM tt WHERE tt MATCH $expr
          526  +  } $r2
          527  +  breakpoint
          528  +
          529  +  do_execsql_test 11.1.$tn.2  {
          530  +    SELECT rowid, mit(matchinfo(tt, 'b')) FROM tt WHERE tt MATCH $expr
          531  +  } $r2
   513    532   }
   514    533   set sqlite_fts3_enable_parentheses 0
   515    534   
          535  +#---------------------------------------------------------------------------
          536  +# Test the 'b' matchinfo flag
          537  +#
          538  +set sqlite_fts3_enable_parentheses 1
          539  +reset_db
          540  +db func mit mit
          541  +
          542  +do_test 12.0 {
          543  +  set cols [list]
          544  +  for {set i 0} {$i < 50} {incr i} { lappend cols "c$i" }
          545  +  execsql "CREATE VIRTUAL TABLE tt USING fts3([join $cols ,])"
          546  +} {}
          547  +
          548  +do_execsql_test 12.1 {
          549  +  INSERT INTO tt (rowid, c4, c45) VALUES(1, 'abc', 'abc');
          550  +  SELECT mit(matchinfo(tt, 'b')) FROM tt WHERE tt MATCH 'abc';
          551  +} [list [list [expr 1<<4] [expr 1<<(45-32)]]]
          552  +
          553  +set sqlite_fts3_enable_parentheses 0
   516    554   finish_test
          555  +

Changes to test/fts3query.test.

   169    169   } {
   170    170     1 "SELECT matchinfo(content) FROM t2 WHERE t2 MATCH 'history'" matchinfo
   171    171     2 "SELECT offsets(content) FROM t2 WHERE t2 MATCH 'history'"   offsets
   172    172     3 "SELECT snippet(content) FROM t2 WHERE t2 MATCH 'history'"   snippet
   173    173     4 "SELECT optimize(content) FROM t2 WHERE t2 MATCH 'history'"  optimize
   174    174   }
   175    175   do_catchsql_test 5.5.1 {
   176         -  SELECT matchinfo(t2, 'abc') FROM t2 WHERE t2 MATCH 'history'
   177         -} {1 {unrecognized matchinfo request: b}}
          176  +  SELECT matchinfo(t2, 'abcd') FROM t2 WHERE t2 MATCH 'history'
          177  +} {1 {unrecognized matchinfo request: d}}
   178    178   
   179    179   do_execsql_test 5.5 { DROP TABLE t2 }
   180    180   
   181    181   
   182    182   # Test the snippet() function with 1 to 6 arguments.
   183    183   # 
   184    184   do_execsql_test 6.1 {

Changes to test/jrnlmode.test.

   555    555   do_execsql_test jrnlmode-8.29 { COMMIT }                        {}
   556    556   do_execsql_test jrnlmode-8.30 { PRAGMA journal_mode=DELETE }    {delete}
   557    557   
   558    558   # Assertion fault on 2015-05-01
   559    559   do_test jrnlmode-9.1 {
   560    560     forcedelete test2.db
   561    561     sqlite3 db2 test2.db
   562         -  breakpoint
   563    562     db2 eval {CREATE TEMP TABLE t(l); PRAGMA journal_mode=off;}
   564    563     db2 close
   565    564   } {}
   566    565   do_execsql_test jrnlmode-9.2 {
   567    566     PRAGMA locking_mode = exclusive;
   568    567     CREATE TABLE tx(a);
   569    568     PRAGMA journal_mode = off;
   570    569   } {exclusive off}
   571    570   
   572    571   
   573    572   finish_test

Added test/sqldiff1.test.

            1  +# 2015-05-11
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +#
           12  +# Quick tests for the sqldiff tool
           13  +#
           14  +set testdir [file dirname $argv0]
           15  +source $testdir/tester.tcl
           16  +
           17  +if {$tcl_platform(platform)=="windows"} {
           18  +  set PROG "sqldiff.exe"
           19  +} else {
           20  +  set PROG "./sqldiff"
           21  +}
           22  +db close
           23  +forcedelete test.db test2.db
           24  +sqlite3 db test.db
           25  +
           26  +do_test sqldiff-1.0 {
           27  +  db eval {
           28  +    CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
           29  +    CREATE TABLE t2(a INT PRIMARY KEY, b) WITHOUT ROWID;
           30  +    WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100)
           31  +    INSERT INTO t1(a,b) SELECT x, printf('abc-%d-xyz',x) FROM c;
           32  +    INSERT INTO t2(a,b) SELECT a, b FROM t1;
           33  +  }
           34  +  db backup test2.db
           35  +  db eval {
           36  +    ATTACH 'test2.db' AS x2;
           37  +    DELETE FROM x2.t1 WHERE a=49;
           38  +    DELETE FROM x2.t2 WHERE a=48;
           39  +    INSERT INTO x2.t1(a,b) VALUES(1234,'hello');
           40  +    INSERT INTO x2.t2(a,b) VALUES(50.5,'xyzzy');
           41  +    CREATE TABLE x2.t3(a,b,c);
           42  +    INSERT INTO x2.t3 VALUES(111,222,333);
           43  +    CREATE TABLE main.t4(x,y,z);
           44  +    INSERT INTO t4 SELECT * FROM t3;
           45  +  }
           46  +  set line "exec $PROG test.db test2.db"
           47  +  unset -nocomplain ::MSG
           48  +  catch {eval $line} ::MSG
           49  +} {0}
           50  +do_test sqldiff-1.1 {
           51  +  set ::MSG
           52  +} {DELETE FROM t1 WHERE a=49;
           53  +INSERT INTO t1(a,b) VALUES(1234,'hello');
           54  +DELETE FROM t2 WHERE a=48;
           55  +INSERT INTO t2(a,b) VALUES(50.5,'xyzzy');
           56  +CREATE TABLE t3(a,b,c);
           57  +INSERT INTO t3(rowid,a,b,c) VALUES(1,111,222,333);
           58  +DROP TABLE t4;}
           59  +
           60  +finish_test

Changes to test/stat.test.

   162    162   
   163    163   db close
   164    164   forcedelete test.db
   165    165   sqlite3 db test.db
   166    166   register_dbstat_vtab db
   167    167   do_execsql_test stat-5.1 {
   168    168     PRAGMA auto_vacuum = OFF;
   169         -  CREATE VIRTUAL TABLE temp.stat USING dbstat;
   170         -  CREATE TABLE t1(x);
          169  +  CREATE TABLE tx(y);
          170  +  ATTACH ':memory:' AS aux1;
          171  +  CREATE VIRTUAL TABLE temp.stat USING dbstat(aux1);
          172  +  CREATE TABLE aux1.t1(x);
   171    173     INSERT INTO t1 VALUES(zeroblob(1513));
   172    174     INSERT INTO t1 VALUES(zeroblob(1514));
   173    175     SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
   174    176       FROM stat WHERE name = 't1';
   175    177   } [list \
   176    178     t1 / 2 leaf 2 993 5 1517                \
   177    179     t1 /000+000000 3 overflow 0 1020 0 0    \
   178    180     t1 /001+000000 4 overflow 0 1020 0 0    \
   179    181   ]
   180    182   
          183  +do_catchsql_test stat-6.1 {
          184  +  CREATE VIRTUAL TABLE temp.s2 USING dbstat(mainx);
          185  +} {1 {no such database: mainx}}
          186  +
   181    187   finish_test

Changes to test/transitive1.test.

    61     61      ORDER BY +w;
    62     62   } {1 2 1 3 3 4 3 6 5 6 5 7}
    63     63   do_execsql_test transitive1-301 {
    64     64     SELECT *
    65     65       FROM t301 CROSS JOIN t302
    66     66      WHERE w=y AND y IS NOT NULL
    67     67      ORDER BY w;
           68  +} {1 2 1 3 3 4 3 6 5 6 5 7}
           69  +do_execsql_test transitive1-302 {
           70  +  SELECT *
           71  +    FROM t301 CROSS JOIN t302
           72  +   WHERE w IS y AND y IS NOT NULL
           73  +   ORDER BY w;
    68     74   } {1 2 1 3 3 4 3 6 5 6 5 7}
    69     75   do_execsql_test transitive1-310 {
    70     76     SELECT *
    71     77       FROM t301 CROSS JOIN t302 ON w=y
    72     78      WHERE y>1
    73     79      ORDER BY +w
    74     80   } {3 4 3 6 5 6 5 7}
................................................................................
    99    105     SELECT *
   100    106       FROM t301 CROSS JOIN t302 ON w=y
   101    107      WHERE y BETWEEN 1 AND 4
   102    108      ORDER BY w DESC;
   103    109   } {3 4 3 6 1 2 1 3}
   104    110   
   105    111   # Ticket [c620261b5b5dc] circa 2013-10-28.
   106         -# Make sureconstraints are not used with LEFT JOINs.
          112  +# Make sure constraints are not used with LEFT JOINs.
   107    113   #
   108    114   # The next case is from the ticket report.  It outputs no rows in 3.8.1
   109    115   # prior to the bug-fix.
   110    116   #
   111    117   do_execsql_test transitive1-400 {
   112    118     CREATE TABLE t401(a);
   113    119     CREATE TABLE t402(b);
   114    120     CREATE TABLE t403(c INTEGER PRIMARY KEY);
   115    121     INSERT INTO t401 VALUES(1);
   116    122     INSERT INTO t403 VALUES(1);
   117    123     SELECT '1-row' FROM t401 LEFT JOIN t402 ON b=a JOIN t403 ON c=a;
   118    124   } {1-row}
          125  +do_execsql_test transitive1-401 {
          126  +  SELECT '1-row' FROM t401 LEFT JOIN t402 ON b IS a JOIN t403 ON c=a;
          127  +} {1-row}
          128  +do_execsql_test transitive1-402 {
          129  +  SELECT '1-row' FROM t401 LEFT JOIN t402 ON b=a JOIN t403 ON c IS a;
          130  +} {1-row}
          131  +do_execsql_test transitive1-403 {
          132  +  SELECT '1-row' FROM t401 LEFT JOIN t402 ON b IS a JOIN t403 ON c IS a;
          133  +} {1-row}
          134  +
   119    135   
   120    136   # The following is a script distilled from the XBMC project where the
   121    137   # bug was originally encountered.  The correct answer is a single row
   122    138   # of output.  Before the bug was fixed, zero rows were generated.
   123    139   #
   124    140   do_execsql_test transitive1-410 {
   125    141     CREATE TABLE bookmark ( idBookmark integer primary key, idFile integer, timeInSeconds double, totalTimeInSeconds double, thumbNailImage text, player text, playerState text, type integer);

Changes to test/vtab1.test.

  1081   1081   } {{} 15 16}
  1082   1082   do_test vtab1.13-3 {
  1083   1083     execsql { 
  1084   1084       INSERT INTO c VALUES(15, NULL, 16);
  1085   1085       SELECT * FROM echo_c WHERE b IS NULL 
  1086   1086     }
  1087   1087   } {15 {} 16}
  1088         -do_test vtab1.13-3 {
         1088  +do_test vtab1.13-4 {
         1089  +  unset -nocomplain null
         1090  +  execsql { 
         1091  +    SELECT * FROM echo_c WHERE b IS $null
         1092  +  }
         1093  +} {15 {} 16}
         1094  +do_test vtab1.13-5 {
  1089   1095     execsql { 
  1090   1096       SELECT * FROM echo_c WHERE b IS NULL AND a = 15;
  1091   1097     }
         1098  +} {15 {} 16}
         1099  +do_test vtab1.13-6 {
         1100  +  execsql { 
         1101  +    SELECT * FROM echo_c WHERE NULL IS b AND a IS 15;
         1102  +  }
  1092   1103   } {15 {} 16}
  1093   1104   
  1094   1105   
  1095   1106   do_test vtab1-14.001 {
  1096   1107     execsql {SELECT rowid, * FROM echo_c WHERE +rowid IN (1,2,3)}
  1097   1108   } {1 3 G H 2 {} 15 16 3 15 {} 16}
  1098   1109   do_test vtab1-14.002 {

Changes to test/vtab2.test.

   100    100   do_test vtab2-3.2 {
   101    101     execsql {
   102    102       SELECT *, b.rowid
   103    103         FROM schema a LEFT JOIN schema b ON a.dflt_value=b.dflt_value
   104    104        WHERE a.rowid=1
   105    105     }
   106    106   } {main schema 0 database {} 0 {} 0 {} {} {} {} {} {} {} {} {}}
          107  +do_test vtab2-3.3 {
          108  +  execsql {
          109  +    SELECT *, b.rowid
          110  +      FROM schema a LEFT JOIN schema b ON a.dflt_value IS b.dflt_value
          111  +                                      AND a.dflt_value IS NOT NULL
          112  +     WHERE a.rowid=1
          113  +  }
          114  +} {main schema 0 database {} 0 {} 0 {} {} {} {} {} {} {} {} {}}
   107    115   
   108    116   do_test vtab2-4.1 {
   109    117     execsql {
   110    118       BEGIN TRANSACTION;
   111    119       CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, UNIQUE(b, c));
   112    120       CREATE TABLE fkey(
   113    121         to_tbl,
................................................................................
   149    157       sqlite3_exec_hex db { CREATE VIRTUAL TABLE %C9 USING s }
   150    158     } {/1 {malformed database schema.* already exists}/}
   151    159   }
   152    160   
   153    161   
   154    162   
   155    163   finish_test
   156         -

Changes to test/vtab6.test.

   228    228       SELECT * FROM t1 NATURAL RIGHT OUTER JOIN t2;
   229    229     }
   230    230   } {1 {RIGHT and FULL OUTER JOINs are not currently supported}}
   231    231   do_test vtab6-2.4 {
   232    232     execsql {
   233    233       SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.d
   234    234     }
          235  +} {1 2 3 {} {} {} 2 3 4 {} {} {} 3 4 5 1 2 3}
          236  +do_test vtab6-2.4.1 {
          237  +  execsql {
          238  +    SELECT * FROM t1 LEFT JOIN t2 ON t1.a IS t2.d
          239  +  }
   235    240   } {1 2 3 {} {} {} 2 3 4 {} {} {} 3 4 5 1 2 3}
   236    241   do_test vtab6-2.5 {
   237    242     execsql {
   238    243       SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.d WHERE t1.a>1
   239    244     }
   240    245   } {2 3 4 {} {} {} 3 4 5 1 2 3}
   241    246   do_test vtab6-2.6 {

Changes to test/where.test.

    61     61   # "sqlite_search_count" which tallys the number of executions of MoveTo
    62     62   # and Next operators in the VDBE.  By verifing that the search count is
    63     63   # small we can be assured that indices are being used properly.
    64     64   #
    65     65   do_test where-1.1.1 {
    66     66     count {SELECT x, y, w FROM t1 WHERE w=10}
    67     67   } {3 121 10 3}
           68  +do_test where-1.1.1b {
           69  +  count {SELECT x, y, w FROM t1 WHERE w IS 10}
           70  +} {3 121 10 3}
    68     71   do_eqp_test where-1.1.2 {
    69     72     SELECT x, y, w FROM t1 WHERE w=10
    70     73   } {*SEARCH TABLE t1 USING INDEX i1w (w=?)*}
           74  +do_eqp_test where-1.1.2b {
           75  +  SELECT x, y, w FROM t1 WHERE w IS 10
           76  +} {*SEARCH TABLE t1 USING INDEX i1w (w=?)*}
    71     77   do_test where-1.1.3 {
    72     78     db status step
    73     79   } {0}
    74     80   do_test where-1.1.4 {
    75     81     db eval {SELECT x, y, w FROM t1 WHERE +w=10}
    76     82   } {3 121 10}
    77     83   do_test where-1.1.5 {
................................................................................
    97    103   } {3 144 11 3}
    98    104   do_test where-1.3.1 {
    99    105     count {SELECT x, y, w AS abc FROM t1 WHERE 11=w}
   100    106   } {3 144 11 3}
   101    107   do_test where-1.3.2 {
   102    108     count {SELECT x, y, w AS abc FROM t1 WHERE 11=abc}
   103    109   } {3 144 11 3}
          110  +do_test where-1.3.3 {
          111  +  count {SELECT x, y, w AS abc FROM t1 WHERE 11 IS abc}
          112  +} {3 144 11 3}
   104    113   do_test where-1.4.1 {
   105    114     count {SELECT w, x, y FROM t1 WHERE 11=w AND x>2}
   106    115   } {11 3 144 3}
          116  +do_test where-1.4.1b {
          117  +  count {SELECT w, x, y FROM t1 WHERE 11 IS w AND x>2}
          118  +} {11 3 144 3}
   107    119   do_eqp_test where-1.4.2 {
   108    120     SELECT w, x, y FROM t1 WHERE 11=w AND x>2
   109    121   } {*SEARCH TABLE t1 USING INDEX i1w (w=?)*}
          122  +do_eqp_test where-1.4.2b {
          123  +  SELECT w, x, y FROM t1 WHERE 11 IS w AND x>2
          124  +} {*SEARCH TABLE t1 USING INDEX i1w (w=?)*}
   110    125   do_test where-1.4.3 {
   111    126     count {SELECT w AS a, x AS b, y FROM t1 WHERE 11=a AND b>2}
   112    127   } {11 3 144 3}
   113    128   do_eqp_test where-1.4.4 {
   114    129     SELECT w AS a, x AS b, y FROM t1 WHERE 11=a AND b>2
   115    130   } {*SEARCH TABLE t1 USING INDEX i1w (w=?)*}
   116    131   do_test where-1.5 {
................................................................................
   139    154   } {3 144 3}
   140    155   do_test where-1.10 {
   141    156     count {SELECT x, y FROM t1 WHERE x=3 AND w>=10 AND y=121}
   142    157   } {3 121 3}
   143    158   do_test where-1.11 {
   144    159     count {SELECT x, y FROM t1 WHERE x=3 AND y=100 AND w<10}
   145    160   } {3 100 3}
          161  +do_test where-1.11b {
          162  +  count {SELECT x, y FROM t1 WHERE x IS 3 AND y IS 100 AND w<10}
          163  +} {3 100 3}
   146    164   
   147    165   # New for SQLite version 2.1: Verify that that inequality constraints
   148    166   # are used correctly.
   149    167   #
   150    168   do_test where-1.12 {
   151    169     count {SELECT w FROM t1 WHERE x=3 AND y<100}
   152    170   } {8 3}
          171  +do_test where-1.12b {
          172  +  count {SELECT w FROM t1 WHERE x IS 3 AND y<100}
          173  +} {8 3}
   153    174   do_test where-1.13 {
   154    175     count {SELECT w FROM t1 WHERE x=3 AND 100>y}
   155    176   } {8 3}
   156    177   do_test where-1.14 {
   157    178     count {SELECT w FROM t1 WHERE 3=x AND y<100}
   158    179   } {8 3}
          180  +do_test where-1.14b {
          181  +  count {SELECT w FROM t1 WHERE 3 IS x AND y<100}
          182  +} {8 3}
   159    183   do_test where-1.15 {
   160    184     count {SELECT w FROM t1 WHERE 3=x AND 100>y}
   161    185   } {8 3}
   162    186   do_test where-1.16 {
   163    187     count {SELECT w FROM t1 WHERE x=3 AND y<=100}
   164    188   } {8 9 5}
   165    189   do_test where-1.17 {
   166    190     count {SELECT w FROM t1 WHERE x=3 AND 100>=y}
   167    191   } {8 9 5}
   168    192   do_test where-1.18 {
   169    193     count {SELECT w FROM t1 WHERE x=3 AND y>225}
   170    194   } {15 3}
          195  +do_test where-1.18b {
          196  +  count {SELECT w FROM t1 WHERE x IS 3 AND y>225}
          197  +} {15 3}
   171    198   do_test where-1.19 {
   172    199     count {SELECT w FROM t1 WHERE x=3 AND 225<y}
   173    200   } {15 3}
   174    201   do_test where-1.20 {
   175    202     count {SELECT w FROM t1 WHERE x=3 AND y>=225}
   176    203   } {14 15 5}
   177    204   do_test where-1.21 {
   178    205     count {SELECT w FROM t1 WHERE x=3 AND 225<=y}
   179    206   } {14 15 5}
   180    207   do_test where-1.22 {
   181    208     count {SELECT w FROM t1 WHERE x=3 AND y>121 AND y<196}
   182    209   } {11 12 5}
          210  +do_test where-1.22b {
          211  +  count {SELECT w FROM t1 WHERE x IS 3 AND y>121 AND y<196}
          212  +} {11 12 5}
   183    213   do_test where-1.23 {
   184    214     count {SELECT w FROM t1 WHERE x=3 AND y>=121 AND y<=196}
   185    215   } {10 11 12 13 9}
   186    216   do_test where-1.24 {
   187    217     count {SELECT w FROM t1 WHERE x=3 AND 121<y AND 196>y}
   188    218   } {11 12 5}
   189    219   do_test where-1.25 {

Changes to test/where4.test.

    53     53   # "sqlite_search_count" which tallys the number of executions of MoveTo
    54     54   # and Next operators in the VDBE.  By verifing that the search count is
    55     55   # small we can be assured that indices are being used properly.
    56     56   #
    57     57   do_test where4-1.1 {
    58     58     count {SELECT rowid FROM t1 WHERE w IS NULL}
    59     59   } {7 2}
           60  +do_test where4-1.1b {
           61  +  unset -nocomplain null
           62  +  count {SELECT rowid FROM t1 WHERE w IS $null}
           63  +} {7 2}
    60     64   do_test where4-1.2 {
    61     65     count {SELECT rowid FROM t1 WHERE +w IS NULL}
    62     66   } {7 6}
    63     67   do_test where4-1.3 {
    64     68     count {SELECT rowid FROM t1 WHERE w=1 AND x IS NULL}
    65     69   } {2 2}
    66     70   do_test where4-1.4 {
................................................................................
   138    142       SELECT * FROM t2 LEFT JOIN t3 ON a=x WHERE +y IS NULL;
   139    143     }
   140    144   } {2 2 {} 3 {} {}}
   141    145   do_test where4-3.2 {
   142    146     execsql {
   143    147       SELECT * FROM t2 LEFT JOIN t3 ON a=x WHERE y IS NULL;
   144    148     }
          149  +} {2 2 {} 3 {} {}}
          150  +do_test where4-3.3 {
          151  +  execsql {
          152  +    SELECT * FROM t2 LEFT JOIN t3 ON a=x WHERE NULL is y;
          153  +  }
          154  +} {2 2 {} 3 {} {}}
          155  +do_test where4-3.4 {
          156  +  unset -nocomplain null
          157  +  execsql {
          158  +    SELECT * FROM t2 LEFT JOIN t3 ON a=x WHERE y IS $null;
          159  +  }
   145    160   } {2 2 {} 3 {} {}}
   146    161   
   147    162   # Ticket #2189.  Probably the same bug as #2177.
   148    163   #
   149    164   do_test where4-4.1 {
   150    165     execsql {
   151    166       CREATE TABLE test(col1 TEXT PRIMARY KEY);

Changes to test/whereC.test.

    55     55     8   "SELECT i FROM t1 WHERE a=2 AND b=2 AND i BETWEEN 10 AND 12" {10 11 12}
    56     56     9   "SELECT i FROM t1 WHERE a=2 AND b=2 AND i BETWEEN 11 AND 12" {11 12}
    57     57    10   "SELECT i FROM t1 WHERE a=2 AND b=2 AND i BETWEEN 10 AND 11" {10 11}
    58     58    11   "SELECT i FROM t1 WHERE a=2 AND b=2 AND i BETWEEN 12 AND 10" {}
    59     59    12   "SELECT i FROM t1 WHERE a=2 AND b=2 AND i<NULL"      {}
    60     60    13   "SELECT i FROM t1 WHERE a=2 AND b=2 AND i>=NULL"     {}
    61     61    14   "SELECT i FROM t1 WHERE a=1 AND b='2' AND i<4.5"     {3 4}
           62  + 15   "SELECT i FROM t1 WHERE rowid IS '12'"               {12}
    62     63   } {
    63     64     do_execsql_test 1.$tn.1 $sql $res
    64     65     do_execsql_test 1.$tn.2 "$sql ORDER BY i ASC"  [lsort -integer -inc  $res]
    65     66     do_execsql_test 1.$tn.3 "$sql ORDER BY i DESC" [lsort -integer -dec  $res]
    66     67   }
    67     68   
    68     69   
    69     70   finish_test

Changes to tool/spaceanal.tcl.

    84     84   
    85     85   # Open the database
    86     86   #
    87     87   if {[catch {sqlite3 db $file_to_analyze -uri 1} msg]} {
    88     88     puts stderr "error trying to open $file_to_analyze: $msg"
    89     89     exit 1
    90     90   }
    91         -register_dbstat_vtab db
    92     91   
    93     92   db eval {SELECT count(*) FROM sqlite_master}
    94     93   set pageSize [expr {wide([db one {PRAGMA page_size}])}]
    95     94   
    96     95   if {$flags(-pageinfo)} {
    97     96     db eval {CREATE VIRTUAL TABLE temp.stat USING dbstat}
    98     97     db eval {SELECT name, path, pageno FROM temp.stat ORDER BY pageno} {

Changes to tool/sqldiff.c.

  1135   1135     char *zTab = 0;
  1136   1136     FILE *out = stdout;
  1137   1137     void (*xDiff)(const char*,FILE*) = diff_one_table;
  1138   1138     int nExt = 0;
  1139   1139     char **azExt = 0;
  1140   1140   
  1141   1141     g.zArgv0 = argv[0];
         1142  +  sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
  1142   1143     for(i=1; i<argc; i++){
  1143   1144       const char *z = argv[i];
  1144   1145       if( z[0]=='-' ){
  1145   1146         z++;
  1146   1147         if( z[0]=='-' ) z++;
  1147   1148         if( strcmp(z,"changeset")==0 ){
  1148   1149           if( i==argc-1 ) cmdlineError("missing argument to %s", argv[i]);
................................................................................
  1154   1155           if( i==argc-1 ) cmdlineError("missing argument to %s", argv[i]);
  1155   1156           g.fDebug = strtol(argv[++i], 0, 0);
  1156   1157         }else
  1157   1158         if( strcmp(z,"help")==0 ){
  1158   1159           showHelp();
  1159   1160           return 0;
  1160   1161         }else
         1162  +#ifndef SQLITE_OMIT_LOAD_EXTENSION
  1161   1163         if( strcmp(z,"lib")==0 || strcmp(z,"L")==0 ){
  1162   1164           if( i==argc-1 ) cmdlineError("missing argument to %s", argv[i]);
  1163   1165           azExt = realloc(azExt, sizeof(azExt[0])*(nExt+1));
  1164   1166           if( azExt==0 ) cmdlineError("out of memory");
  1165   1167           azExt[nExt++] = argv[++i];
  1166   1168         }else
         1169  +#endif
  1167   1170         if( strcmp(z,"primarykey")==0 ){
  1168   1171           g.bSchemaPK = 1;
  1169   1172         }else
  1170   1173         if( strcmp(z,"schema")==0 ){
  1171   1174           g.bSchemaOnly = 1;
  1172   1175         }else
  1173   1176         if( strcmp(z,"summary")==0 ){
................................................................................
  1195   1198     if( rc ){
  1196   1199       cmdlineError("cannot open database file \"%s\"", zDb1);
  1197   1200     }
  1198   1201     rc = sqlite3_exec(g.db, "SELECT * FROM sqlite_master", 0, 0, &zErrMsg);
  1199   1202     if( rc || zErrMsg ){
  1200   1203       cmdlineError("\"%s\" does not appear to be a valid SQLite database", zDb1);
  1201   1204     }
         1205  +#ifndef SQLITE_OMIT_LOAD_EXTENSION
  1202   1206     sqlite3_enable_load_extension(g.db, 1);
  1203   1207     for(i=0; i<nExt; i++){
  1204   1208       rc = sqlite3_load_extension(g.db, azExt[i], 0, &zErrMsg);
  1205   1209       if( rc || zErrMsg ){
  1206   1210         cmdlineError("error loading %s: %s", azExt[i], zErrMsg);
  1207   1211       }
  1208   1212     }
         1213  +#endif
  1209   1214     free(azExt);
  1210   1215     zSql = sqlite3_mprintf("ATTACH %Q as aux;", zDb2);
  1211   1216     rc = sqlite3_exec(g.db, zSql, 0, 0, &zErrMsg);
  1212   1217     if( rc || zErrMsg ){
  1213   1218       cmdlineError("cannot attach database \"%s\"", zDb2);
  1214   1219     }
  1215   1220     rc = sqlite3_exec(g.db, "SELECT * FROM aux.sqlite_master", 0, 0, &zErrMsg);