/ Check-in [5cf5f180]
Login

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

Overview
Comment:Merge latest trunk changes into this branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | exp-window-functions
Files: files | file ages | folders
SHA3-256:5cf5f1808a51f9c2cfc98dd49b4f1ce860b53e935287f89868ce2fdbace8eb06
User & Date: dan 2018-06-14 14:30:51
Context
2018-06-14
19:06
Fix problem with window functions min() and max() when used with a PARTITION clause and a frame starting point other than "UNBOUNDED PRECEDING". check-in: 43eb1e75 user: dan tags: exp-window-functions
14:30
Merge latest trunk changes into this branch. check-in: 5cf5f180 user: dan tags: exp-window-functions
14:27
Improve comments and code legibility in new file window.c. check-in: bb915854 user: dan tags: exp-window-functions
2018-06-13
17:19
Output infinity as 1e999 in the ".dump" command of the command-line shell. check-in: ee431d55 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to autoconf/Makefile.am.

     1      1   
     2         -AM_CFLAGS = @THREADSAFE_FLAGS@ @DYNAMIC_EXTENSION_FLAGS@ @FTS5_FLAGS@ @JSON1_FLAGS@ @ZLIB_FLAGS@ @SESSION_FLAGS@ -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_RTREE @DEBUG_FLAGS@
     3         -
            2  +AM_CFLAGS = @BUILD_CFLAGS@ 
     4      3   lib_LTLIBRARIES = libsqlite3.la
     5      4   libsqlite3_la_SOURCES = sqlite3.c
     6      5   libsqlite3_la_LDFLAGS = -no-undefined -version-info 8:6:8
     7      6   
     8      7   bin_PROGRAMS = sqlite3
     9      8   sqlite3_SOURCES = shell.c sqlite3.h
    10      9   EXTRA_sqlite3_SOURCES = sqlite3.c

Changes to autoconf/configure.ac.

    25     25   AC_PROG_MKDIR_P
    26     26   
    27     27   # Check for library functions that SQLite can optionally use.
    28     28   AC_CHECK_FUNCS([fdatasync usleep fullfsync localtime_r gmtime_r])
    29     29   AC_FUNC_STRERROR_R
    30     30   
    31     31   AC_CONFIG_FILES([Makefile sqlite3.pc])
           32  +BUILD_CFLAGS=
    32     33   AC_SUBST(BUILD_CFLAGS)
    33     34   
    34     35   #-------------------------------------------------------------------------
    35     36   # Two options to enable readline compatible libraries: 
    36     37   #
    37     38   #   --enable-editline
    38     39   #   --enable-readline
................................................................................
    82     83   
    83     84   #-----------------------------------------------------------------------
    84     85   #   --enable-threadsafe
    85     86   #
    86     87   AC_ARG_ENABLE(threadsafe, [AS_HELP_STRING(
    87     88     [--enable-threadsafe], [build a thread-safe library [default=yes]])], 
    88     89     [], [enable_threadsafe=yes])
    89         -THREADSAFE_FLAGS=-DSQLITE_THREADSAFE=0
    90     90   if test x"$enable_threadsafe" != "xno"; then
    91         -  THREADSAFE_FLAGS="-D_REENTRANT=1 -DSQLITE_THREADSAFE=1"
           91  +  BUILD_CFLAGS="$BUILD_CFLAGS -D_REENTRANT=1 -DSQLITE_THREADSAFE=1"
    92     92     AC_SEARCH_LIBS(pthread_create, pthread)
    93     93     AC_SEARCH_LIBS(pthread_mutexattr_init, pthread)
    94     94   fi
    95         -AC_SUBST(THREADSAFE_FLAGS)
    96     95   #-----------------------------------------------------------------------
    97     96   
    98     97   #-----------------------------------------------------------------------
    99     98   #   --enable-dynamic-extensions
   100     99   #
   101    100   AC_ARG_ENABLE(dynamic-extensions, [AS_HELP_STRING(
   102    101     [--enable-dynamic-extensions], [support loadable extensions [default=yes]])], 
   103    102     [], [enable_dynamic_extensions=yes])
   104    103   if test x"$enable_dynamic_extensions" != "xno"; then
   105    104     AC_SEARCH_LIBS(dlopen, dl)
   106    105   else
   107         -  DYNAMIC_EXTENSION_FLAGS=-DSQLITE_OMIT_LOAD_EXTENSION=1
          106  +  BUILD_CFLAGS="$BUILD_CFLAGS -DSQLITE_OMIT_LOAD_EXTENSION=1"
   108    107   fi
   109    108   AC_MSG_CHECKING([for whether to support dynamic extensions])
   110    109   AC_MSG_RESULT($enable_dynamic_extensions)
   111         -AC_SUBST(DYNAMIC_EXTENSION_FLAGS)
          110  +#-----------------------------------------------------------------------
          111  +
          112  +#-----------------------------------------------------------------------
          113  +#   --enable-fts4
          114  +#
          115  +AC_ARG_ENABLE(fts4, [AS_HELP_STRING(
          116  +  [--enable-fts4], [include fts4 support [default=yes]])], 
          117  +  [], [enable_fts4=yes])
          118  +if test x"$enable_fts4" = "xyes"; then
          119  +  BUILD_CFLAGS="$BUILD_CFLAGS -DSQLITE_ENABLE_FTS4"
          120  +fi
          121  +#-----------------------------------------------------------------------
          122  +
          123  +#-----------------------------------------------------------------------
          124  +#   --enable-fts3
          125  +#
          126  +AC_ARG_ENABLE(fts3, [AS_HELP_STRING(
          127  +  [--enable-fts3], [include fts3 support [default=no]])], 
          128  +  [], [])
          129  +if test x"$enable_fts3" = "xyes" -a x"$enable_fts4" = "xno"; then
          130  +  BUILD_CFLAGS="$BUILD_CFLAGS -DSQLITE_ENABLE_FTS3"
          131  +fi
   112    132   #-----------------------------------------------------------------------
   113    133   
   114    134   #-----------------------------------------------------------------------
   115    135   #   --enable-fts5
   116    136   #
   117    137   AC_ARG_ENABLE(fts5, [AS_HELP_STRING(
   118    138     [--enable-fts5], [include fts5 support [default=yes]])], 
   119    139     [], [enable_fts5=yes])
   120    140   if test x"$enable_fts5" = "xyes"; then
   121    141     AC_SEARCH_LIBS(log, m)
   122         -  FTS5_FLAGS=-DSQLITE_ENABLE_FTS5
          142  +  BUILD_CFLAGS="$BUILD_CFLAGS -DSQLITE_ENABLE_FTS5"
   123    143   fi
   124         -AC_SUBST(FTS5_FLAGS)
   125    144   #-----------------------------------------------------------------------
   126    145   
   127    146   #-----------------------------------------------------------------------
   128    147   #   --enable-json1
   129    148   #
   130    149   AC_ARG_ENABLE(json1, [AS_HELP_STRING(
   131    150     [--enable-json1], [include json1 support [default=yes]])], 
   132         -  [], [enable_json1=yes])
          151  +  [],[enable_json1=yes])
   133    152   if test x"$enable_json1" = "xyes"; then
   134         -  JSON1_FLAGS=-DSQLITE_ENABLE_JSON1
          153  +  BUILD_CFLAGS="$BUILD_CFLAGS -DSQLITE_ENABLE_JSON1"
   135    154   fi
   136         -AC_SUBST(JSON1_FLAGS)
          155  +#-----------------------------------------------------------------------
          156  +
          157  +#-----------------------------------------------------------------------
          158  +#   --enable-rtree
          159  +#
          160  +AC_ARG_ENABLE(rtree, [AS_HELP_STRING(
          161  +  [--enable-rtree], [include rtree support [default=yes]])], 
          162  +  [], [enable_rtree=yes])
          163  +if test x"$enable_rtree" = "xyes"; then
          164  +  BUILD_CFLAGS="$BUILD_CFLAGS -DSQLITE_ENABLE_RTREE"
          165  +fi
   137    166   #-----------------------------------------------------------------------
   138    167   
   139    168   #-----------------------------------------------------------------------
   140    169   #   --enable-session
   141    170   #
   142    171   AC_ARG_ENABLE(session, [AS_HELP_STRING(
   143    172     [--enable-session], [enable the session extension [default=no]])], 
   144         -  [], [enable_session=no])
          173  +  [], [])
   145    174   if test x"$enable_session" = "xyes"; then
   146         -  SESSION_FLAGS="-DSQLITE_ENABLE_SESSION -DSQLITE_ENABLE_PREUPDATE_HOOK"
          175  +  BUILD_CFLAGS="$BUILD_CFLAGS-DSQLITE_ENABLE_SESSION -DSQLITE_ENABLE_PREUPDATE_HOOK"
   147    176   fi
   148         -AC_SUBST(SESSION_FLAGS)
   149    177   #-----------------------------------------------------------------------
   150    178   
   151    179   #-----------------------------------------------------------------------
   152    180   #   --enable-debug
   153    181   #
   154    182   AC_ARG_ENABLE(debug, [AS_HELP_STRING(
   155    183     [--enable-debug], [build with debugging features enabled [default=no]])], 
   156         -  [], [enable_session=no])
          184  +  [], [])
   157    185   if test x"$enable_debug" = "xyes"; then
   158         -  DEBUG_FLAGS="-DSQLITE_DEBUG -DSQLITE_ENABLE_SELECTTRACE -DSQLITE_ENABLE_WHERETRACE"
          186  +  BUILD_CFLAGS="$BUILD_CFLAGS -DSQLITE_DEBUG -DSQLITE_ENABLE_SELECTTRACE -DSQLITE_ENABLE_WHERETRACE"
          187  +  CFLAGS="-g -O0"
   159    188   fi
   160         -AC_SUBST(DEBUG_FLAGS)
   161    189   #-----------------------------------------------------------------------
   162    190   
   163    191   #-----------------------------------------------------------------------
   164    192   #   --enable-static-shell
   165    193   #
   166    194   AC_ARG_ENABLE(static-shell, [AS_HELP_STRING(
   167    195     [--enable-static-shell], 
................................................................................
   173    201     EXTRA_SHELL_OBJ=libsqlite3.la
   174    202   fi
   175    203   AC_SUBST(EXTRA_SHELL_OBJ)
   176    204   #-----------------------------------------------------------------------
   177    205   
   178    206   AC_CHECK_FUNCS(posix_fallocate)
   179    207   AC_CHECK_HEADERS(zlib.h,[
   180         -  AC_SEARCH_LIBS(deflate,z,[ZLIB_FLAGS="-DSQLITE_HAVE_ZLIB"])
          208  +  AC_SEARCH_LIBS(deflate,z,[BUILD_CFLAGS="$BUILD_CFLAGS -DSQLITE_HAVE_ZLIB"])
   181    209   ])
   182         -AC_SUBST(ZLIB_FLAGS)
   183    210   
   184    211   AC_SEARCH_LIBS(system,,,[SHELL_CFLAGS="-DSQLITE_NOHAVE_SYSTEM"])
   185    212   AC_SUBST(SHELL_CFLAGS)
   186    213   
   187    214   #-----------------------------------------------------------------------
   188    215   # UPDATE: Maybe it's better if users just set CFLAGS before invoking
   189    216   # configure. This option doesn't really add much...

Changes to configure.

 10451  10451   
 10452  10452   ##########
 10453  10453   # Do we want to support multithreaded use of sqlite
 10454  10454   #
 10455  10455   # Check whether --enable-threadsafe was given.
 10456  10456   if test "${enable_threadsafe+set}" = set; then :
 10457  10457     enableval=$enable_threadsafe;
 10458         -else
 10459         -  enable_threadsafe=yes
 10460  10458   fi
 10461  10459   
 10462  10460   { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to support threadsafe operation" >&5
 10463  10461   $as_echo_n "checking whether to support threadsafe operation... " >&6; }
 10464  10462   if test "$enable_threadsafe" = "no"; then
 10465  10463     SQLITE_THREADSAFE=0
 10466  10464     { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
................................................................................
 11245  11243   fi
 11246  11244   
 11247  11245   
 11248  11246   #########
 11249  11247   # check for debug enabled
 11250  11248   # Check whether --enable-debug was given.
 11251  11249   if test "${enable_debug+set}" = set; then :
 11252         -  enableval=$enable_debug; use_debug=$enableval
 11253         -else
 11254         -  use_debug=no
        11250  +  enableval=$enable_debug;
 11255  11251   fi
 11256  11252   
 11257         -if test "${use_debug}" = "yes" ; then
        11253  +if test "${enable_debug}" = "yes" ; then
 11258  11254     TARGET_DEBUG="-DSQLITE_DEBUG=1 -DSQLITE_ENABLE_SELECTTRACE -DSQLITE_ENABLE_WHERETRACE -O0"
 11259  11255   else
 11260  11256     TARGET_DEBUG="-DNDEBUG"
 11261  11257   fi
 11262  11258   
 11263  11259   
 11264  11260   #########
 11265  11261   # See whether we should use the amalgamation to build
 11266  11262   # Check whether --enable-amalgamation was given.
 11267  11263   if test "${enable_amalgamation+set}" = set; then :
 11268         -  enableval=$enable_amalgamation; use_amalgamation=$enableval
 11269         -else
 11270         -  use_amalgamation=yes
        11264  +  enableval=$enable_amalgamation;
 11271  11265   fi
 11272  11266   
 11273         -if test "${use_amalgamation}" != "yes" ; then
        11267  +if test "${enable_amalgamation}" == "no" ; then
 11274  11268     USE_AMALGAMATION=0
 11275  11269   fi
 11276  11270   
 11277  11271   
 11278  11272   #########
 11279  11273   # Look for zlib.  Only needed by extensions and by the sqlite3.exe shell
 11280  11274   for ac_header in zlib.h
................................................................................
 11349  11343   
 11350  11344   
 11351  11345   
 11352  11346   #########
 11353  11347   # See whether we should allow loadable extensions
 11354  11348   # Check whether --enable-load-extension was given.
 11355  11349   if test "${enable_load_extension+set}" = set; then :
 11356         -  enableval=$enable_load_extension; use_loadextension=$enableval
        11350  +  enableval=$enable_load_extension;
 11357  11351   else
 11358         -  use_loadextension=yes
        11352  +  enable_load_extension=yes
 11359  11353   fi
 11360  11354   
 11361         -if test "${use_loadextension}" = "yes" ; then
        11355  +if test "${enable_load_extension}" = "yes" ; then
 11362  11356     OPT_FEATURE_FLAGS=""
 11363  11357     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing dlopen" >&5
 11364  11358   $as_echo_n "checking for library containing dlopen... " >&6; }
 11365  11359   if ${ac_cv_search_dlopen+:} false; then :
 11366  11360     $as_echo_n "(cached) " >&6
 11367  11361   else
 11368  11362     ac_func_search_save_LIBS=$LIBS
................................................................................
 11421  11415   fi
 11422  11416   
 11423  11417   ##########
 11424  11418   # Do we want to support memsys3 and/or memsys5
 11425  11419   #
 11426  11420   # Check whether --enable-memsys5 was given.
 11427  11421   if test "${enable_memsys5+set}" = set; then :
 11428         -  enableval=$enable_memsys5; enable_memsys5=yes
 11429         -else
 11430         -  enable_memsys5=no
        11422  +  enableval=$enable_memsys5;
 11431  11423   fi
 11432  11424   
 11433  11425   { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to support MEMSYS5" >&5
 11434  11426   $as_echo_n "checking whether to support MEMSYS5... " >&6; }
 11435  11427   if test "${enable_memsys5}" = "yes"; then
 11436  11428     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_MEMSYS5"
 11437  11429     { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
................................................................................
 11438  11430   $as_echo "yes" >&6; }
 11439  11431   else
 11440  11432     { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 11441  11433   $as_echo "no" >&6; }
 11442  11434   fi
 11443  11435   # Check whether --enable-memsys3 was given.
 11444  11436   if test "${enable_memsys3+set}" = set; then :
 11445         -  enableval=$enable_memsys3; enable_memsys3=yes
 11446         -else
 11447         -  enable_memsys3=no
        11437  +  enableval=$enable_memsys3;
 11448  11438   fi
 11449  11439   
 11450  11440   { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to support MEMSYS3" >&5
 11451  11441   $as_echo_n "checking whether to support MEMSYS3... " >&6; }
 11452  11442   if test "${enable_memsys3}" = "yes" -a "${enable_memsys5}" = "no"; then
 11453  11443     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_MEMSYS3"
 11454  11444     { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
................................................................................
 11458  11448   $as_echo "no" >&6; }
 11459  11449   fi
 11460  11450   
 11461  11451   #########
 11462  11452   # See whether we should enable Full Text Search extensions
 11463  11453   # Check whether --enable-fts3 was given.
 11464  11454   if test "${enable_fts3+set}" = set; then :
 11465         -  enableval=$enable_fts3; enable_fts3=yes
 11466         -else
 11467         -  enable_fts3=no
        11455  +  enableval=$enable_fts3;
 11468  11456   fi
 11469  11457   
 11470  11458   if test "${enable_fts3}" = "yes" ; then
 11471  11459     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS3"
 11472  11460   fi
 11473  11461   # Check whether --enable-fts4 was given.
 11474  11462   if test "${enable_fts4+set}" = set; then :
 11475         -  enableval=$enable_fts4; enable_fts4=yes
 11476         -else
 11477         -  enable_fts4=no
        11463  +  enableval=$enable_fts4;
 11478  11464   fi
 11479  11465   
 11480  11466   if test "${enable_fts4}" = "yes" ; then
 11481  11467     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS4"
 11482  11468     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing log" >&5
 11483  11469   $as_echo_n "checking for library containing log... " >&6; }
 11484  11470   if ${ac_cv_search_log+:} false; then :
................................................................................
 11534  11520     test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
 11535  11521   
 11536  11522   fi
 11537  11523   
 11538  11524   fi
 11539  11525   # Check whether --enable-fts5 was given.
 11540  11526   if test "${enable_fts5+set}" = set; then :
 11541         -  enableval=$enable_fts5; enable_fts5=yes
 11542         -else
 11543         -  enable_fts5=no
        11527  +  enableval=$enable_fts5;
 11544  11528   fi
 11545  11529   
 11546  11530   if test "${enable_fts5}" = "yes" ; then
 11547  11531     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS5"
 11548  11532     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing log" >&5
 11549  11533   $as_echo_n "checking for library containing log... " >&6; }
 11550  11534   if ${ac_cv_search_log+:} false; then :
................................................................................
 11603  11587   
 11604  11588   fi
 11605  11589   
 11606  11590   #########
 11607  11591   # See whether we should enable JSON1
 11608  11592   # Check whether --enable-json1 was given.
 11609  11593   if test "${enable_json1+set}" = set; then :
 11610         -  enableval=$enable_json1; enable_json1=yes
 11611         -else
 11612         -  enable_json1=no
        11594  +  enableval=$enable_json1;
 11613  11595   fi
 11614  11596   
 11615  11597   if test "${enable_json1}" = "yes" ; then
 11616  11598     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_JSON1"
 11617  11599   fi
 11618  11600   
 11619  11601   #########
 11620  11602   # See whether we should enable the LIMIT clause on UPDATE and DELETE
 11621  11603   # statements.
 11622  11604   # Check whether --enable-update-limit was given.
 11623  11605   if test "${enable_update_limit+set}" = set; then :
 11624         -  enableval=$enable_update_limit; enable_udlimit=yes
 11625         -else
 11626         -  enable_udlimit=no
        11606  +  enableval=$enable_update_limit;
 11627  11607   fi
 11628  11608   
 11629  11609   if test "${enable_udlimit}" = "yes" ; then
 11630  11610     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT"
 11631  11611   fi
 11632  11612   
 11633  11613   #########
 11634  11614   # See whether we should enable RTREE
 11635  11615   # Check whether --enable-rtree was given.
 11636  11616   if test "${enable_rtree+set}" = set; then :
 11637         -  enableval=$enable_rtree; enable_rtree=yes
 11638         -else
 11639         -  enable_rtree=no
        11617  +  enableval=$enable_rtree;
 11640  11618   fi
 11641  11619   
 11642  11620   if test "${enable_rtree}" = "yes" ; then
 11643  11621     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_RTREE"
 11644  11622   fi
 11645  11623   
 11646  11624   #########
 11647  11625   # See whether we should enable the SESSION extension
 11648  11626   # Check whether --enable-session was given.
 11649  11627   if test "${enable_session+set}" = set; then :
 11650         -  enableval=$enable_session; enable_session=yes
 11651         -else
 11652         -  enable_session=no
        11628  +  enableval=$enable_session;
 11653  11629   fi
 11654  11630   
 11655  11631   if test "${enable_session}" = "yes" ; then
 11656  11632     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_SESSION"
 11657  11633     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_PREUPDATE_HOOK"
 11658  11634   fi
 11659  11635   
................................................................................
 11708  11684   BUILD_CFLAGS=$ac_temp_BUILD_CFLAGS
 11709  11685   
 11710  11686   
 11711  11687   #########
 11712  11688   # See whether we should use GCOV
 11713  11689   # Check whether --enable-gcov was given.
 11714  11690   if test "${enable_gcov+set}" = set; then :
 11715         -  enableval=$enable_gcov; use_gcov=$enableval
 11716         -else
 11717         -  use_gcov=no
        11691  +  enableval=$enable_gcov;
 11718  11692   fi
 11719  11693   
 11720  11694   if test "${use_gcov}" = "yes" ; then
 11721  11695     USE_GCOV=1
 11722  11696   else
 11723  11697     USE_GCOV=0
 11724  11698   fi

Changes to configure.ac.

   178    178   fi
   179    179   AC_SUBST(BUILD_CC)
   180    180   
   181    181   ##########
   182    182   # Do we want to support multithreaded use of sqlite
   183    183   #
   184    184   AC_ARG_ENABLE(threadsafe, 
   185         -AC_HELP_STRING([--disable-threadsafe],[Disable mutexing]),,enable_threadsafe=yes)
          185  +AC_HELP_STRING([--disable-threadsafe],[Disable mutexing]))
   186    186   AC_MSG_CHECKING([whether to support threadsafe operation])
   187    187   if test "$enable_threadsafe" = "no"; then
   188    188     SQLITE_THREADSAFE=0
   189    189     AC_MSG_RESULT([no])
   190    190   else
   191    191     SQLITE_THREADSAFE=1
   192    192     AC_MSG_RESULT([yes])
................................................................................
   553    553   # Figure out what C libraries are required to compile programs
   554    554   # that use "fdatasync()" function.
   555    555   #
   556    556   AC_SEARCH_LIBS(fdatasync, [rt])
   557    557   
   558    558   #########
   559    559   # check for debug enabled
   560         -AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug],[enable debugging & verbose explain]),
   561         -      [use_debug=$enableval],[use_debug=no])
   562         -if test "${use_debug}" = "yes" ; then
          560  +AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug],[enable debugging & verbose explain]))
          561  +if test "${enable_debug}" = "yes" ; then
   563    562     TARGET_DEBUG="-DSQLITE_DEBUG=1 -DSQLITE_ENABLE_SELECTTRACE -DSQLITE_ENABLE_WHERETRACE -O0"
   564    563   else
   565    564     TARGET_DEBUG="-DNDEBUG"
   566    565   fi
   567    566   AC_SUBST(TARGET_DEBUG)
   568    567   
   569    568   #########
   570    569   # See whether we should use the amalgamation to build
   571    570   AC_ARG_ENABLE(amalgamation, AC_HELP_STRING([--disable-amalgamation],
   572         -      [Disable the amalgamation and instead build all files separately]),
   573         -      [use_amalgamation=$enableval],[use_amalgamation=yes])
   574         -if test "${use_amalgamation}" != "yes" ; then
          571  +      [Disable the amalgamation and instead build all files separately]))
          572  +if test "${enable_amalgamation}" == "no" ; then
   575    573     USE_AMALGAMATION=0
   576    574   fi
   577    575   AC_SUBST(USE_AMALGAMATION)
   578    576   
   579    577   #########
   580    578   # Look for zlib.  Only needed by extensions and by the sqlite3.exe shell
   581    579   AC_CHECK_HEADERS(zlib.h)
   582    580   AC_SEARCH_LIBS(deflate, z, [HAVE_ZLIB="-DSQLITE_HAVE_ZLIB=1"], [HAVE_ZLIB=""])
   583    581   AC_SUBST(HAVE_ZLIB)
   584    582   
   585    583   #########
   586    584   # See whether we should allow loadable extensions
   587    585   AC_ARG_ENABLE(load-extension, AC_HELP_STRING([--disable-load-extension],
   588         -      [Disable loading of external extensions]),
   589         -      [use_loadextension=$enableval],[use_loadextension=yes])
   590         -if test "${use_loadextension}" = "yes" ; then
          586  +      [Disable loading of external extensions]),,[enable_load_extension=yes])
          587  +if test "${enable_load_extension}" = "yes" ; then
   591    588     OPT_FEATURE_FLAGS=""
   592    589     AC_SEARCH_LIBS(dlopen, dl)
   593    590   else
   594    591     OPT_FEATURE_FLAGS="-DSQLITE_OMIT_LOAD_EXTENSION=1"
   595    592   fi
   596    593   
   597    594   ##########
   598    595   # Do we want to support memsys3 and/or memsys5
   599    596   #
   600    597   AC_ARG_ENABLE(memsys5, 
   601         -  AC_HELP_STRING([--enable-memsys5],[Enable MEMSYS5]),
   602         -  [enable_memsys5=yes],[enable_memsys5=no])
          598  +  AC_HELP_STRING([--enable-memsys5],[Enable MEMSYS5]))
   603    599   AC_MSG_CHECKING([whether to support MEMSYS5])
   604    600   if test "${enable_memsys5}" = "yes"; then
   605    601     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_MEMSYS5"
   606    602     AC_MSG_RESULT([yes])
   607    603   else
   608    604     AC_MSG_RESULT([no])
   609    605   fi
   610    606   AC_ARG_ENABLE(memsys3, 
   611         -  AC_HELP_STRING([--enable-memsys3],[Enable MEMSYS3]),
   612         -  [enable_memsys3=yes],[enable_memsys3=no])
          607  +  AC_HELP_STRING([--enable-memsys3],[Enable MEMSYS3]))
   613    608   AC_MSG_CHECKING([whether to support MEMSYS3])
   614    609   if test "${enable_memsys3}" = "yes" -a "${enable_memsys5}" = "no"; then
   615    610     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_MEMSYS3"
   616    611     AC_MSG_RESULT([yes])
   617    612   else
   618    613     AC_MSG_RESULT([no])
   619    614   fi
   620    615   
   621    616   #########
   622    617   # See whether we should enable Full Text Search extensions
   623    618   AC_ARG_ENABLE(fts3, AC_HELP_STRING([--enable-fts3],
   624         -      [Enable the FTS3 extension]),
   625         -      [enable_fts3=yes],[enable_fts3=no])
          619  +      [Enable the FTS3 extension]))
   626    620   if test "${enable_fts3}" = "yes" ; then
   627    621     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS3"
   628    622   fi
   629    623   AC_ARG_ENABLE(fts4, AC_HELP_STRING([--enable-fts4],
   630         -      [Enable the FTS4 extension]),
   631         -      [enable_fts4=yes],[enable_fts4=no])
          624  +      [Enable the FTS4 extension]))
   632    625   if test "${enable_fts4}" = "yes" ; then
   633    626     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS4"
   634    627     AC_SEARCH_LIBS([log],[m])
   635    628   fi
   636    629   AC_ARG_ENABLE(fts5, AC_HELP_STRING([--enable-fts5],
   637         -      [Enable the FTS5 extension]),
   638         -      [enable_fts5=yes],[enable_fts5=no])
          630  +      [Enable the FTS5 extension]))
   639    631   if test "${enable_fts5}" = "yes" ; then
   640    632     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS5"
   641    633     AC_SEARCH_LIBS([log],[m])
   642    634   fi
   643    635   
   644    636   #########
   645    637   # See whether we should enable JSON1
   646         -AC_ARG_ENABLE(json1, AC_HELP_STRING([--enable-json1],
   647         -      [Enable the JSON1 extension]),
   648         -      [enable_json1=yes],[enable_json1=no])
          638  +AC_ARG_ENABLE(json1, AC_HELP_STRING([--enable-json1],[Enable the JSON1 extension]))
   649    639   if test "${enable_json1}" = "yes" ; then
   650    640     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_JSON1"
   651    641   fi
   652    642   
   653    643   #########
   654    644   # See whether we should enable the LIMIT clause on UPDATE and DELETE
   655    645   # statements.
   656    646   AC_ARG_ENABLE(update-limit, AC_HELP_STRING([--enable-update-limit],
   657         -      [Enable the UPDATE/DELETE LIMIT clause]),
   658         -      [enable_udlimit=yes],[enable_udlimit=no])
          647  +      [Enable the UPDATE/DELETE LIMIT clause]))
   659    648   if test "${enable_udlimit}" = "yes" ; then
   660    649     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT"
   661    650   fi
   662    651   
   663    652   #########
   664    653   # See whether we should enable RTREE
   665    654   AC_ARG_ENABLE(rtree, AC_HELP_STRING([--enable-rtree],
   666         -      [Enable the RTREE extension]),
   667         -      [enable_rtree=yes],[enable_rtree=no])
          655  +      [Enable the RTREE extension]))
   668    656   if test "${enable_rtree}" = "yes" ; then
   669    657     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_RTREE"
   670    658   fi
   671    659   
   672    660   #########
   673    661   # See whether we should enable the SESSION extension
   674    662   AC_ARG_ENABLE(session, AC_HELP_STRING([--enable-session],
   675         -      [Enable the SESSION extension]),
   676         -      [enable_session=yes],[enable_session=no])
          663  +      [Enable the SESSION extension]))
   677    664   if test "${enable_session}" = "yes" ; then
   678    665     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_SESSION"
   679    666     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_PREUPDATE_HOOK"
   680    667   fi
   681    668   
   682    669   #########
   683    670   # attempt to duplicate any OMITS and ENABLES into the ${OPT_FEATURE_FLAGS} parameter
................................................................................
   729    716   done
   730    717   BUILD_CFLAGS=$ac_temp_BUILD_CFLAGS
   731    718   
   732    719   
   733    720   #########
   734    721   # See whether we should use GCOV
   735    722   AC_ARG_ENABLE(gcov, AC_HELP_STRING([--enable-gcov],
   736         -      [Enable coverage testing using gcov]),
   737         -      [use_gcov=$enableval],[use_gcov=no])
          723  +      [Enable coverage testing using gcov]))
   738    724   if test "${use_gcov}" = "yes" ; then
   739    725     USE_GCOV=1
   740    726   else
   741    727     USE_GCOV=0
   742    728   fi
   743    729   AC_SUBST(USE_GCOV)
   744    730   

Changes to ext/expert/expert1.test.

   328    328     $expert destroy
   329    329   
   330    330     uplevel [list do_test $tn [list set {} $candidates] $res]
   331    331   }
   332    332   
   333    333   
   334    334   reset_db
   335         -do_execsql_test 3.0 {
          335  +do_execsql_test 4.0 {
   336    336     CREATE TABLE t1(a, b);
   337    337     CREATE TABLE t2(c, d);
   338    338   
   339    339     WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<100)
   340    340     INSERT INTO t1 SELECT (i-1)/50, (i-1)/20 FROM s;
   341    341   
   342    342     WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<100)
   343    343     INSERT INTO t2 SELECT (i-1)/20, (i-1)/5 FROM s;
   344    344   }
   345         -do_candidates_test 3.1 {
          345  +do_candidates_test 4.1 {
   346    346     SELECT * FROM t1,t2 WHERE (b=? OR a=?) AND (c=? OR d=?)
   347    347   } {
   348    348     CREATE INDEX t1_idx_00000062 ON t1(b); -- stat1: 100 20 
   349    349     CREATE INDEX t1_idx_00000061 ON t1(a); -- stat1: 100 50 
   350    350     CREATE INDEX t2_idx_00000063 ON t2(c); -- stat1: 100 20 
   351    351     CREATE INDEX t2_idx_00000064 ON t2(d); -- stat1: 100 5
   352    352   }
   353    353   
   354         -do_candidates_test 3.2 {
          354  +do_candidates_test 4.2 {
   355    355     SELECT * FROM t1,t2 WHERE a=? AND b=? AND c=? AND d=?
   356    356   } {
   357    357     CREATE INDEX t1_idx_000123a7 ON t1(a, b); -- stat1: 100 50 17
   358    358     CREATE INDEX t2_idx_0001295b ON t2(c, d); -- stat1: 100 20 5
   359    359   }
   360    360   
   361         -do_execsql_test 3.2 {
          361  +do_execsql_test 4.3 {
   362    362     CREATE INDEX t1_idx_00000061 ON t1(a); -- stat1: 100 50 
   363    363     CREATE INDEX t1_idx_00000062 ON t1(b); -- stat1: 100 20 
   364    364     CREATE INDEX t1_idx_000123a7 ON t1(a, b); -- stat1: 100 50 16
   365    365   
   366    366     CREATE INDEX t2_idx_00000063 ON t2(c); -- stat1: 100 20 
   367    367     CREATE INDEX t2_idx_00000064 ON t2(d); -- stat1: 100 5
   368    368     CREATE INDEX t2_idx_0001295b ON t2(c, d); -- stat1: 100 20 5

Changes to ext/misc/dbdump.c.

   481    481             switch( sqlite3_column_type(pStmt,i) ){
   482    482               case SQLITE_INTEGER: {
   483    483                 output_formatted(p, "%lld", sqlite3_column_int64(pStmt,i));
   484    484                 break;
   485    485               }
   486    486               case SQLITE_FLOAT: {
   487    487                 double r = sqlite3_column_double(pStmt,i);
   488         -              output_formatted(p, "%!.20g", r);
          488  +              sqlite3_uint64 ur;
          489  +              memcpy(&ur,&r,sizeof(r));
          490  +              if( ur==0x7ff0000000000000LL ){
          491  +                p->xCallback("1e999", p->pArg);
          492  +              }else if( ur==0xfff0000000000000LL ){
          493  +                p->xCallback("-1e999", p->pArg);
          494  +              }else{
          495  +                output_formatted(p, "%!.20g", r);
          496  +              }
   489    497                 break;
   490    498               }
   491    499               case SQLITE_NULL: {
   492    500                 p->xCallback("NULL", p->pArg);
   493    501                 break;
   494    502               }
   495    503               case SQLITE_TEXT: {

Changes to src/expr.c.

  3207   3207     ** that the object will never already be in cache.  Verify this guarantee.
  3208   3208     */
  3209   3209   #ifndef NDEBUG
  3210   3210     for(i=0, p=pParse->aColCache; i<pParse->nColCache; i++, p++){
  3211   3211       assert( p->iTable!=iTab || p->iColumn!=iCol );
  3212   3212     }
  3213   3213   #endif
         3214  +
         3215  +#ifdef SQLITE_DEBUG_COLUMNCACHE
         3216  +  /* Add a SetTabCol opcode for run-time verification that the column
         3217  +  ** cache is working correctly.
         3218  +  */
         3219  +  sqlite3VdbeAddOp3(pParse->pVdbe, OP_SetTabCol, iTab, iCol, iReg);
         3220  +#endif
  3214   3221   
  3215   3222     /* If the cache is already full, delete the least recently used entry */
  3216   3223     if( pParse->nColCache>=SQLITE_N_COLCACHE ){
  3217   3224       minLru = 0x7fffffff;
  3218   3225       idxLru = -1;
  3219   3226       for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
  3220   3227         if( p->lru<minLru ){
................................................................................
  3381   3388     int i;
  3382   3389     struct yColCache *p;
  3383   3390   
  3384   3391     for(i=0, p=pParse->aColCache; i<pParse->nColCache; i++, p++){
  3385   3392       if( p->iTable==iTable && p->iColumn==iColumn ){
  3386   3393         p->lru = pParse->iCacheCnt++;
  3387   3394         sqlite3ExprCachePinRegister(pParse, p->iReg);
         3395  +#ifdef SQLITE_DEBUG_COLUMNCACHE
         3396  +      sqlite3VdbeAddOp3(v, OP_VerifyTabCol, iTable, iColumn, p->iReg);
         3397  +#endif
  3388   3398         return p->iReg;
  3389   3399       }
  3390   3400     }  
  3391   3401     assert( v!=0 );
  3392   3402     sqlite3ExprCodeGetColumnOfTable(v, pTab, iTable, iColumn, iReg);
  3393   3403     if( p5 ){
  3394   3404       sqlite3VdbeChangeP5(v, p5);

Changes to src/insert.c.

  1529   1529   
  1530   1530       /* Check to see if the new rowid already exists in the table.  Skip
  1531   1531       ** the following conflict logic if it does not. */
  1532   1532       VdbeNoopComment((v, "uniqueness check for ROWID"));
  1533   1533       sqlite3VdbeVerifyAbortable(v, onError);
  1534   1534       sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, addrRowidOk, regNewData);
  1535   1535       VdbeCoverage(v);
         1536  +    sqlite3ExprCachePush(pParse);
  1536   1537   
  1537   1538       switch( onError ){
  1538   1539         default: {
  1539   1540           onError = OE_Abort;
  1540   1541           /* Fall thru into the next case */
  1541   1542         }
  1542   1543         case OE_Rollback:
................................................................................
  1605   1606   #endif
  1606   1607         case OE_Ignore: {
  1607   1608           testcase( onError==OE_Ignore );
  1608   1609           sqlite3VdbeGoto(v, ignoreDest);
  1609   1610           break;
  1610   1611         }
  1611   1612       }
         1613  +    sqlite3ExprCachePop(pParse);
  1612   1614       sqlite3VdbeResolveLabel(v, addrRowidOk);
  1613   1615       if( sAddr.ipkTop ){
  1614   1616         sAddr.ipkBtm = sqlite3VdbeAddOp0(v, OP_Goto);
  1615   1617         sqlite3VdbeJumpHere(v, sAddr.ipkTop-1);
  1616   1618       }
  1617   1619     }
  1618   1620   

Changes to src/os.c.

   406    406     return SQLITE_OK;
   407    407   }
   408    408   
   409    409   /*
   410    410   ** Unregister a VFS so that it is no longer accessible.
   411    411   */
   412    412   int sqlite3_vfs_unregister(sqlite3_vfs *pVfs){
   413         -#if SQLITE_THREADSAFE
   414         -  sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
          413  +  MUTEX_LOGIC(sqlite3_mutex *mutex;)
          414  +#ifndef SQLITE_OMIT_AUTOINIT
          415  +  int rc = sqlite3_initialize();
          416  +  if( rc ) return rc;
   415    417   #endif
          418  +  MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
   416    419     sqlite3_mutex_enter(mutex);
   417    420     vfsUnlink(pVfs);
   418    421     sqlite3_mutex_leave(mutex);
   419    422     return SQLITE_OK;
   420    423   }

Changes to src/shell.c.in.

  2029   2029               output_quoted_escaped_string(p->out, azArg[i]);
  2030   2030             }
  2031   2031           }else if( aiType && aiType[i]==SQLITE_INTEGER ){
  2032   2032             utf8_printf(p->out,"%s", azArg[i]);
  2033   2033           }else if( aiType && aiType[i]==SQLITE_FLOAT ){
  2034   2034             char z[50];
  2035   2035             double r = sqlite3_column_double(p->pStmt, i);
  2036         -          sqlite3_snprintf(50,z,"%!.20g", r);
  2037         -          raw_printf(p->out, "%s", z);
         2036  +          sqlite3_uint64 ur;
         2037  +          memcpy(&ur,&r,sizeof(r));
         2038  +          if( ur==0x7ff0000000000000LL ){
         2039  +            raw_printf(p->out, "1e999");
         2040  +          }else if( ur==0xfff0000000000000LL ){
         2041  +            raw_printf(p->out, "-1e999");
         2042  +          }else{
         2043  +            sqlite3_snprintf(50,z,"%!.20g", r);
         2044  +            raw_printf(p->out, "%s", z);
         2045  +          }
  2038   2046           }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
  2039   2047             const void *pBlob = sqlite3_column_blob(p->pStmt, i);
  2040   2048             int nBlob = sqlite3_column_bytes(p->pStmt, i);
  2041   2049             output_hex_blob(p->out, pBlob, nBlob);
  2042   2050           }else if( isNumber(azArg[i], 0) ){
  2043   2051             utf8_printf(p->out,"%s", azArg[i]);
  2044   2052           }else if( ShellHasFlag(p, SHFLG_Newlines) ){

Changes to src/sqlite.h.in.

   507    507   #define SQLITE_LOCKED_VTAB             (SQLITE_LOCKED |  (2<<8))
   508    508   #define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
   509    509   #define SQLITE_BUSY_SNAPSHOT           (SQLITE_BUSY   |  (2<<8))
   510    510   #define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
   511    511   #define SQLITE_CANTOPEN_ISDIR          (SQLITE_CANTOPEN | (2<<8))
   512    512   #define SQLITE_CANTOPEN_FULLPATH       (SQLITE_CANTOPEN | (3<<8))
   513    513   #define SQLITE_CANTOPEN_CONVPATH       (SQLITE_CANTOPEN | (4<<8))
          514  +#define SQLITE_CANTOPEN_DIRTYWAL       (SQLITE_CANTOPEN | (5<<8)) /* Not Used */
   514    515   #define SQLITE_CORRUPT_VTAB            (SQLITE_CORRUPT | (1<<8))
   515    516   #define SQLITE_CORRUPT_SEQUENCE        (SQLITE_CORRUPT | (2<<8))
   516    517   #define SQLITE_READONLY_RECOVERY       (SQLITE_READONLY | (1<<8))
   517    518   #define SQLITE_READONLY_CANTLOCK       (SQLITE_READONLY | (2<<8))
   518    519   #define SQLITE_READONLY_ROLLBACK       (SQLITE_READONLY | (3<<8))
   519    520   #define SQLITE_READONLY_DBMOVED        (SQLITE_READONLY | (4<<8))
   520    521   #define SQLITE_READONLY_CANTINIT       (SQLITE_READONLY | (5<<8))
................................................................................
  3350   3351   ** CAPI3REF: Error Codes And Messages
  3351   3352   ** METHOD: sqlite3
  3352   3353   **
  3353   3354   ** ^If the most recent sqlite3_* API call associated with 
  3354   3355   ** [database connection] D failed, then the sqlite3_errcode(D) interface
  3355   3356   ** returns the numeric [result code] or [extended result code] for that
  3356   3357   ** API call.
  3357         -** If the most recent API call was successful,
  3358         -** then the return value from sqlite3_errcode() is undefined.
  3359   3358   ** ^The sqlite3_extended_errcode()
  3360   3359   ** interface is the same except that it always returns the 
  3361   3360   ** [extended result code] even when extended result codes are
  3362   3361   ** disabled.
         3362  +**
         3363  +** The values returned by sqlite3_errcode() and/or
         3364  +** sqlite3_extended_errcode() might change with each API call.
         3365  +** Except, there are some interfaces that are guaranteed to never
         3366  +** change the value of the error code.  The error-code preserving
         3367  +** interfaces are:
         3368  +**
         3369  +** <ul>
         3370  +** <li> sqlite3_errcode()
         3371  +** <li> sqlite3_extended_errcode()
         3372  +** <li> sqlite3_errmsg()
         3373  +** <li> sqlite3_errmsg16()
         3374  +** </ul>
  3363   3375   **
  3364   3376   ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
  3365   3377   ** text that describes the error, as either UTF-8 or UTF-16 respectively.
  3366   3378   ** ^(Memory to hold the error message string is managed internally.
  3367   3379   ** The application does not need to worry about freeing the result.
  3368   3380   ** However, the error string might be overwritten or deallocated by
  3369   3381   ** subsequent calls to other SQLite interface functions.)^
................................................................................
  4510   4522   ** ^The pointers returned are valid until a type conversion occurs as
  4511   4523   ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
  4512   4524   ** [sqlite3_finalize()] is called.  ^The memory space used to hold strings
  4513   4525   ** and BLOBs is freed automatically.  Do not pass the pointers returned
  4514   4526   ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
  4515   4527   ** [sqlite3_free()].
  4516   4528   **
  4517         -** ^(If a memory allocation error occurs during the evaluation of any
  4518         -** of these routines, a default value is returned.  The default value
  4519         -** is either the integer 0, the floating point number 0.0, or a NULL
  4520         -** pointer.  Subsequent calls to [sqlite3_errcode()] will return
  4521         -** [SQLITE_NOMEM].)^
         4529  +** As long as the input parameters are correct, these routines will only
         4530  +** fail if an out-of-memory error occurs during a format conversion.
         4531  +** Only the following subset of interfaces are subject to out-of-memory
         4532  +** errors:
         4533  +**
         4534  +** <ul>
         4535  +** <li> sqlite3_column_blob()
         4536  +** <li> sqlite3_column_text()
         4537  +** <li> sqlite3_column_text16()
         4538  +** <li> sqlite3_column_bytes()
         4539  +** <li> sqlite3_column_bytes16()
         4540  +** </ul>
         4541  +**
         4542  +** If an out-of-memory error occurs, then the return value from these
         4543  +** routines is the same as if the column had contained an SQL NULL value.
         4544  +** Valid SQL NULL returns can be distinguished from out-of-memory errors
         4545  +** by invoking the [sqlite3_errcode()] immediately after the suspect
         4546  +** return value is obtained and before any
         4547  +** other SQLite interface is called on the same [database connection].
  4522   4548   */
  4523   4549   const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
  4524   4550   double sqlite3_column_double(sqlite3_stmt*, int iCol);
  4525   4551   int sqlite3_column_int(sqlite3_stmt*, int iCol);
  4526   4552   sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
  4527   4553   const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
  4528   4554   const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
................................................................................
  4853   4879   ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
  4854   4880   ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
  4855   4881   ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
  4856   4882   ** or [sqlite3_value_text16()].
  4857   4883   **
  4858   4884   ** These routines must be called from the same thread as
  4859   4885   ** the SQL function that supplied the [sqlite3_value*] parameters.
         4886  +**
         4887  +** As long as the input parameter is correct, these routines can only
         4888  +** fail if an out-of-memory error occurs during a format conversion.
         4889  +** Only the following subset of interfaces are subject to out-of-memory
         4890  +** errors:
         4891  +**
         4892  +** <ul>
         4893  +** <li> sqlite3_value_blob()
         4894  +** <li> sqlite3_value_text()
         4895  +** <li> sqlite3_value_text16()
         4896  +** <li> sqlite3_value_text16le()
         4897  +** <li> sqlite3_value_text16be()
         4898  +** <li> sqlite3_value_bytes()
         4899  +** <li> sqlite3_value_bytes16()
         4900  +** </ul>
         4901  +**
         4902  +** If an out-of-memory error occurs, then the return value from these
         4903  +** routines is the same as if the column had contained an SQL NULL value.
         4904  +** Valid SQL NULL returns can be distinguished from out-of-memory errors
         4905  +** by invoking the [sqlite3_errcode()] immediately after the suspect
         4906  +** return value is obtained and before any
         4907  +** other SQLite interface is called on the same [database connection].
  4860   4908   */
  4861   4909   const void *sqlite3_value_blob(sqlite3_value*);
  4862   4910   double sqlite3_value_double(sqlite3_value*);
  4863   4911   int sqlite3_value_int(sqlite3_value*);
  4864   4912   sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
  4865   4913   void *sqlite3_value_pointer(sqlite3_value*, const char*);
  4866   4914   const unsigned char *sqlite3_value_text(sqlite3_value*);

Changes to src/sqliteInt.h.

   362    362   */
   363    363   #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
   364    364   # define NDEBUG 1
   365    365   #endif
   366    366   #if defined(NDEBUG) && defined(SQLITE_DEBUG)
   367    367   # undef NDEBUG
   368    368   #endif
          369  +
          370  +/* SQLITE_DEBUG_COLUMNCACHE is synomous with SQLITE_DEBUG.  The 
          371  +** SQLITE_DEBUG_COLUMNCACHE symbol only exists to provide a convenient
          372  +** way to search for all code that deals with verifying correct behavior
          373  +** of the column cache.
          374  +*/
          375  +#ifdef SQLITE_DEBUG
          376  +# define SQLITE_DEBUG_COLUMNCACHE 1
          377  +#else
          378  +# undef SQLIT_DEBUG_COLUMNCACHE
          379  +#endif
   369    380   
   370    381   /*
   371    382   ** Enable SQLITE_ENABLE_EXPLAIN_COMMENTS if SQLITE_DEBUG is turned on.
   372    383   */
   373    384   #if !defined(SQLITE_ENABLE_EXPLAIN_COMMENTS) && defined(SQLITE_DEBUG)
   374    385   # define SQLITE_ENABLE_EXPLAIN_COMMENTS 1
   375    386   #endif

Changes to src/vdbe.c.

    32     32   */
    33     33   #ifdef SQLITE_DEBUG
    34     34   # define memAboutToChange(P,M) sqlite3VdbeMemAboutToChange(P,M)
    35     35   #else
    36     36   # define memAboutToChange(P,M)
    37     37   #endif
    38     38   
           39  +/*
           40  +** Given a cursor number and a column for a table or index, compute a
           41  +** hash value for use in the Mem.iTabColHash value.  The iTabColHash
           42  +** column is only used for verification - it is omitted from production
           43  +** builds.  Collisions are harmless in the sense that the correct answer
           44  +** still results.  The only harm of collisions is that they can potential
           45  +** reduce column-cache error detection during SQLITE_DEBUG builds.
           46  +**
           47  +** No valid hash should be 0.
           48  +*/
           49  +#define TableColumnHash(T,C)  (((u32)(T)<<16)^(u32)(C+2))
           50  +
    39     51   /*
    40     52   ** The following global variable is incremented every time a cursor
    41     53   ** moves, either by the OP_SeekXX, OP_Next, or OP_Prev opcodes.  The test
    42     54   ** procedures use this information to make sure that indices are
    43     55   ** working correctly.  This variable has no function other than to
    44     56   ** help verify the correct operation of the library.
    45     57   */
................................................................................
  1260   1272     int n;
  1261   1273   
  1262   1274     n = pOp->p3;
  1263   1275     pIn1 = &aMem[pOp->p1];
  1264   1276     pOut = &aMem[pOp->p2];
  1265   1277     assert( pOut!=pIn1 );
  1266   1278     while( 1 ){
         1279  +    memAboutToChange(p, pOut);
  1267   1280       sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
  1268   1281       Deephemeralize(pOut);
  1269   1282   #ifdef SQLITE_DEBUG
  1270   1283       pOut->pScopyFrom = 0;
         1284  +    pOut->iTabColHash = 0;
  1271   1285   #endif
  1272   1286       REGISTER_TRACE(pOp->p2+pOp->p3-n, pOut);
  1273   1287       if( (n--)==0 ) break;
  1274   1288       pOut++;
  1275   1289       pIn1++;
  1276   1290     }
  1277   1291     break;
................................................................................
  1292   1306   */
  1293   1307   case OP_SCopy: {            /* out2 */
  1294   1308     pIn1 = &aMem[pOp->p1];
  1295   1309     pOut = &aMem[pOp->p2];
  1296   1310     assert( pOut!=pIn1 );
  1297   1311     sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
  1298   1312   #ifdef SQLITE_DEBUG
  1299         -  if( pOut->pScopyFrom==0 ) pOut->pScopyFrom = pIn1;
         1313  +  pOut->pScopyFrom = pIn1;
         1314  +  pOut->mScopyFlags = pIn1->flags;
  1300   1315   #endif
  1301   1316     break;
  1302   1317   }
  1303   1318   
  1304   1319   /* Opcode: IntCopy P1 P2 * * *
  1305   1320   ** Synopsis: r[P2]=r[P1]
  1306   1321   **
................................................................................
  2241   2256     }else{
  2242   2257       sqlite3VdbeMemSetNull(pOut);
  2243   2258     }
  2244   2259     break;
  2245   2260   }
  2246   2261   
  2247   2262   /* Opcode: BitNot P1 P2 * * *
  2248         -** Synopsis: r[P1]= ~r[P1]
         2263  +** Synopsis: r[P2]= ~r[P1]
  2249   2264   **
  2250   2265   ** Interpret the content of register P1 as an integer.  Store the
  2251   2266   ** ones-complement of the P1 value into register P2.  If P1 holds
  2252   2267   ** a NULL then store a NULL in P2.
  2253   2268   */
  2254   2269   case OP_BitNot: {             /* same as TK_BITNOT, in1, out2 */
  2255   2270     pIn1 = &aMem[pOp->p1];
................................................................................
  6986   7001     Mem **apArg;
  6987   7002     Mem *pX;
  6988   7003   
  6989   7004     assert( pOp->p2==1        || pOp->p5==OE_Fail   || pOp->p5==OE_Rollback 
  6990   7005          || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace
  6991   7006     );
  6992   7007     assert( p->readOnly==0 );
         7008  +  if( db->mallocFailed ) goto no_mem;
  6993   7009     sqlite3VdbeIncrWriteCounter(p, 0);
  6994   7010     pVtab = pOp->p4.pVtab->pVtab;
  6995   7011     if( pVtab==0 || NEVER(pVtab->pModule==0) ){
  6996   7012       rc = SQLITE_LOCKED;
  6997   7013       goto abort_due_to_error;
  6998   7014     }
  6999   7015     pModule = pVtab->pModule;
................................................................................
  7319   7335   ** an active statement journal.
  7320   7336   */
  7321   7337   case OP_Abortable: {
  7322   7338     sqlite3VdbeAssertAbortable(p);
  7323   7339     break;
  7324   7340   }
  7325   7341   #endif
         7342  +
         7343  +#ifdef SQLITE_DEBUG_COLUMNCACHE
         7344  +/* Opcode:  SetTabCol   P1 P2 P3 * *
         7345  +**
         7346  +** Set a flag in register REG[P3] indicating that it holds the value
         7347  +** of column P2 from the table on cursor P1.  This flag is checked
         7348  +** by a subsequent VerifyTabCol opcode.
         7349  +**
         7350  +** This opcode only appears SQLITE_DEBUG builds.  It is used to verify
         7351  +** that the expression table column cache is working correctly.
         7352  +*/
         7353  +case OP_SetTabCol: {
         7354  +  aMem[pOp->p3].iTabColHash = TableColumnHash(pOp->p1,pOp->p2);
         7355  +  break;
         7356  +}
         7357  +/* Opcode:  VerifyTabCol   P1 P2 P3 * *
         7358  +**
         7359  +** Verify that register REG[P3] contains the value of column P2 from
         7360  +** cursor P1.  Assert() if this is not the case.
         7361  +**
         7362  +** This opcode only appears SQLITE_DEBUG builds.  It is used to verify
         7363  +** that the expression table column cache is working correctly.
         7364  +*/
         7365  +case OP_VerifyTabCol: {
         7366  +  assert( aMem[pOp->p3].iTabColHash == TableColumnHash(pOp->p1,pOp->p2) );
         7367  +  break;
         7368  +}
         7369  +#endif
  7326   7370   
  7327   7371   /* Opcode: Noop * * * * *
  7328   7372   **
  7329   7373   ** Do nothing.  This instruction is often useful as a jump
  7330   7374   ** destination.
  7331   7375   */
  7332   7376   /*

Changes to src/vdbe.h.

   257    257   VdbeOp *sqlite3VdbeTakeOpArray(Vdbe*, int*, int*);
   258    258   sqlite3_value *sqlite3VdbeGetBoundValue(Vdbe*, int, u8);
   259    259   void sqlite3VdbeSetVarmask(Vdbe*, int);
   260    260   #ifndef SQLITE_OMIT_TRACE
   261    261     char *sqlite3VdbeExpandSql(Vdbe*, const char*);
   262    262   #endif
   263    263   int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
          264  +int sqlite3BlobCompare(const Mem*, const Mem*);
   264    265   
   265    266   void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
   266    267   int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
   267    268   int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
   268    269   UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*);
   269    270   
   270    271   typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
................................................................................
   337    338   #endif
   338    339   
   339    340   #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
   340    341   void sqlite3VdbeScanStatus(Vdbe*, int, int, int, LogEst, const char*);
   341    342   #else
   342    343   # define sqlite3VdbeScanStatus(a,b,c,d,e)
   343    344   #endif
          345  +
          346  +#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
          347  +void sqlite3VdbePrintOp(FILE*, int, VdbeOp*);
          348  +#endif
   344    349   
   345    350   #endif /* SQLITE_VDBE_H */

Changes to src/vdbeInt.h.

   205    205     char *zMalloc;      /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
   206    206     int szMalloc;       /* Size of the zMalloc allocation */
   207    207     u32 uTemp;          /* Transient storage for serial_type in OP_MakeRecord */
   208    208     sqlite3 *db;        /* The associated database connection */
   209    209     void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
   210    210   #ifdef SQLITE_DEBUG
   211    211     Mem *pScopyFrom;    /* This Mem is a shallow copy of pScopyFrom */
   212         -  void *pFiller;      /* So that sizeof(Mem) is a multiple of 8 */
          212  +  u16 mScopyFlags;    /* flags value immediately after the shallow copy */
          213  +#endif
          214  +#ifdef SQLITE_DEBUG_COLUMNCACHE
          215  +  u32 iTabColHash;    /* Hash of table.column that is origin of this value */
          216  +  u32 iPadding;       /* sqlite3_value objects must be 8-byte aligned */
   213    217   #endif
   214    218   };
   215    219   
   216    220   /*
   217    221   ** Size of struct Mem not including the Mem.zMalloc member or anything that
   218    222   ** follows.
   219    223   */
................................................................................
   445    449   ** Function prototypes
   446    450   */
   447    451   void sqlite3VdbeError(Vdbe*, const char *, ...);
   448    452   void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
   449    453   void sqliteVdbePopStack(Vdbe*,int);
   450    454   int sqlite3VdbeCursorMoveto(VdbeCursor**, int*);
   451    455   int sqlite3VdbeCursorRestore(VdbeCursor*);
   452         -#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
   453         -void sqlite3VdbePrintOp(FILE*, int, Op*);
   454         -#endif
   455    456   u32 sqlite3VdbeSerialTypeLen(u32);
   456    457   u8 sqlite3VdbeOneByteSerialTypeLen(u8);
   457    458   u32 sqlite3VdbeSerialType(Mem*, int, u32*);
   458    459   u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
   459    460   u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
   460    461   void sqlite3VdbeDeleteAuxData(sqlite3*, AuxData**, int, int);
   461    462   

Changes to src/vdbeapi.c.

   966    966           /* .zMalloc    = */ (char*)0,
   967    967           /* .szMalloc   = */ (int)0,
   968    968           /* .uTemp      = */ (u32)0,
   969    969           /* .db         = */ (sqlite3*)0,
   970    970           /* .xDel       = */ (void(*)(void*))0,
   971    971   #ifdef SQLITE_DEBUG
   972    972           /* .pScopyFrom = */ (Mem*)0,
   973         -        /* .pFiller    = */ (void*)0,
          973  +        /* .mScopyFlags= */ 0,
          974  +#endif
          975  +#ifdef SQLITE_DEBUG_COLUMNCACHE
          976  +        /* .iTabColHash= */ 0,
   974    977   #endif
   975    978         };
   976    979     return &nullMem;
   977    980   }
   978    981   
   979    982   /*
   980    983   ** Check to see if column iCol of the given statement is valid.  If

Changes to src/vdbeaux.c.

  1609   1609   }
  1610   1610   #endif
  1611   1611   
  1612   1612   #if defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
  1613   1613   /*
  1614   1614   ** Print a single opcode.  This routine is used for debugging only.
  1615   1615   */
  1616         -void sqlite3VdbePrintOp(FILE *pOut, int pc, Op *pOp){
         1616  +void sqlite3VdbePrintOp(FILE *pOut, int pc, VdbeOp *pOp){
  1617   1617     char *zP4;
  1618   1618     char zPtr[50];
  1619   1619     char zCom[100];
  1620   1620     static const char *zFormat1 = "%4d %-13s %4d %4d %4d %-13s %.2X %s\n";
  1621   1621     if( pOut==0 ) pOut = stdout;
  1622   1622     zP4 = displayP4(pOp, zPtr, sizeof(zPtr));
  1623   1623   #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
................................................................................
  1642   1642   static void initMemArray(Mem *p, int N, sqlite3 *db, u16 flags){
  1643   1643     while( (N--)>0 ){
  1644   1644       p->db = db;
  1645   1645       p->flags = flags;
  1646   1646       p->szMalloc = 0;
  1647   1647   #ifdef SQLITE_DEBUG
  1648   1648       p->pScopyFrom = 0;
         1649  +#endif
         1650  +#ifdef SQLITE_DEBUG_COLUMNCACHE
         1651  +    p->iTabColHash = 0;
  1649   1652   #endif
  1650   1653       p++;
  1651   1654     }
  1652   1655   }
  1653   1656   
  1654   1657   /*
  1655   1658   ** Release an array of N Mem elements
................................................................................
  3908   3911   }
  3909   3912   
  3910   3913   /*
  3911   3914   ** Compare two blobs.  Return negative, zero, or positive if the first
  3912   3915   ** is less than, equal to, or greater than the second, respectively.
  3913   3916   ** If one blob is a prefix of the other, then the shorter is the lessor.
  3914   3917   */
  3915         -static SQLITE_NOINLINE int sqlite3BlobCompare(const Mem *pB1, const Mem *pB2){
         3918  +SQLITE_NOINLINE int sqlite3BlobCompare(const Mem *pB1, const Mem *pB2){
  3916   3919     int c;
  3917   3920     int n1 = pB1->n;
  3918   3921     int n2 = pB2->n;
  3919   3922   
  3920   3923     /* It is possible to have a Blob value that has some non-zero content
  3921   3924     ** followed by zero content.  But that only comes up for Blobs formed
  3922   3925     ** by the OP_MakeRecord opcode, and such Blobs never get passed into

Changes to src/vdbemem.c.

   899    899   ** copies are not misused.
   900    900   */
   901    901   void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){
   902    902     int i;
   903    903     Mem *pX;
   904    904     for(i=0, pX=pVdbe->aMem; i<pVdbe->nMem; i++, pX++){
   905    905       if( pX->pScopyFrom==pMem ){
   906         -      pX->flags |= MEM_Undefined;
          906  +      /* If pX is marked as a shallow copy of pMem, then verify that
          907  +      ** no significant changes have been made to pX since the OP_SCopy.
          908  +      ** A significant change would indicated a missed call to this
          909  +      ** function for pX.  Minor changes, such as adding or removing a
          910  +      ** dual type, are allowed, as long as the underlying value is the
          911  +      ** same. */
          912  +      u16 mFlags = pMem->flags & pX->flags & pX->mScopyFlags;
          913  +      assert( (mFlags&MEM_Int)==0 || pMem->u.i==pX->u.i );
          914  +      assert( (mFlags&MEM_Real)==0 || pMem->u.r==pX->u.r );
          915  +      assert( (mFlags&MEM_Str)==0  || (pMem->n==pX->n && pMem->z==pX->z) );
          916  +      assert( (mFlags&MEM_Blob)==0  || sqlite3BlobCompare(pMem,pX)==0 );
          917  +      
          918  +      /* pMem is the register that is changing.  But also mark pX as
          919  +      ** undefined so that we can quickly detect the shallow-copy error */
          920  +      pX->flags = MEM_Undefined;
   907    921         pX->pScopyFrom = 0;
   908    922       }
   909    923     }
   910    924     pMem->pScopyFrom = 0;
          925  +#ifdef SQLITE_DEBUG_COLUMN_CACHE
          926  +  pMem->iTabColHash = 0;
          927  +#endif
   911    928   }
   912    929   #endif /* SQLITE_DEBUG */
   913    930   
   914    931   
   915    932   /*
   916    933   ** Make an shallow copy of pFrom into pTo.  Prior contents of
   917    934   ** pTo are freed.  The pFrom->z field is not duplicated.  If
................................................................................
   924    941     sqlite3VdbeMemShallowCopy(pTo, pFrom, eType);
   925    942   }
   926    943   void sqlite3VdbeMemShallowCopy(Mem *pTo, const Mem *pFrom, int srcType){
   927    944     assert( (pFrom->flags & MEM_RowSet)==0 );
   928    945     assert( pTo->db==pFrom->db );
   929    946     if( VdbeMemDynamic(pTo) ){ vdbeClrCopy(pTo,pFrom,srcType); return; }
   930    947     memcpy(pTo, pFrom, MEMCELLSIZE);
          948  +#ifdef SQLITE_DEBUG_COLUMNCACHE
          949  +  pTo->iTabColHash = pFrom->iTabColHash;
          950  +#endif
   931    951     if( (pFrom->flags&MEM_Static)==0 ){
   932    952       pTo->flags &= ~(MEM_Dyn|MEM_Static|MEM_Ephem);
   933    953       assert( srcType==MEM_Ephem || srcType==MEM_Static );
   934    954       pTo->flags |= srcType;
   935    955     }
   936    956   }
   937    957   
................................................................................
   941    961   */
   942    962   int sqlite3VdbeMemCopy(Mem *pTo, const Mem *pFrom){
   943    963     int rc = SQLITE_OK;
   944    964   
   945    965     assert( (pFrom->flags & MEM_RowSet)==0 );
   946    966     if( VdbeMemDynamic(pTo) ) vdbeMemClearExternAndSetNull(pTo);
   947    967     memcpy(pTo, pFrom, MEMCELLSIZE);
          968  +#ifdef SQLITE_DEBUG_COLUMNCACHE
          969  +  pTo->iTabColHash = pFrom->iTabColHash;
          970  +#endif
   948    971     pTo->flags &= ~MEM_Dyn;
   949    972     if( pTo->flags&(MEM_Str|MEM_Blob) ){
   950    973       if( 0==(pFrom->flags&MEM_Static) ){
   951    974         pTo->flags |= MEM_Ephem;
   952    975         rc = sqlite3VdbeMemMakeWriteable(pTo);
   953    976       }
   954    977     }

Changes to src/where.c.

  5029   5029     if( pWInfo ){
  5030   5030       pParse->nQueryLoop = pWInfo->savedNQueryLoop;
  5031   5031       whereInfoFree(db, pWInfo);
  5032   5032     }
  5033   5033     return 0;
  5034   5034   }
  5035   5035   
         5036  +/*
         5037  +** Part of sqlite3WhereEnd() will rewrite opcodes to reference the
         5038  +** index rather than the main table.  In SQLITE_DEBUG mode, we want
         5039  +** to trace those changes if PRAGMA vdbe_addoptrace=on.  This routine
         5040  +** does that.
         5041  +*/
         5042  +#ifndef SQLITE_DEBUG
         5043  +# define OpcodeRewriteTrace(D,K,P) /* no-op */
         5044  +#else
         5045  +# define OpcodeRewriteTrace(D,K,P) sqlite3WhereOpcodeRewriteTrace(D,K,P)
         5046  +  static void sqlite3WhereOpcodeRewriteTrace(
         5047  +    sqlite3 *db,
         5048  +    int pc,
         5049  +    VdbeOp *pOp
         5050  +  ){
         5051  +    if( (db->flags & SQLITE_VdbeAddopTrace)==0 ) return;
         5052  +    sqlite3VdbePrintOp(0, pc, pOp);
         5053  +  }
         5054  +#endif
         5055  +
  5036   5056   /*
  5037   5057   ** Generate the end of the WHERE loop.  See comments on 
  5038   5058   ** sqlite3WhereBegin() for additional information.
  5039   5059   */
  5040   5060   void sqlite3WhereEnd(WhereInfo *pWInfo){
  5041   5061     Parse *pParse = pWInfo->pParse;
  5042   5062     Vdbe *v = pParse->pVdbe;
................................................................................
  5197   5217       }
  5198   5218       if( pIdx
  5199   5219        && (pWInfo->eOnePass==ONEPASS_OFF || !HasRowid(pIdx->pTable))
  5200   5220        && !db->mallocFailed
  5201   5221       ){
  5202   5222         last = sqlite3VdbeCurrentAddr(v);
  5203   5223         k = pLevel->addrBody;
         5224  +#ifdef SQLITE_DEBUG
         5225  +      if( db->flags & SQLITE_VdbeAddopTrace ){
         5226  +        printf("TRANSLATE opcodes in range %d..%d\n", k, last-1);
         5227  +      }
         5228  +#endif
  5204   5229         pOp = sqlite3VdbeGetOp(v, k);
  5205   5230         for(; k<last; k++, pOp++){
  5206   5231           if( pOp->p1!=pLevel->iTabCur ) continue;
  5207   5232           if( pOp->opcode==OP_Column
  5208   5233   #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
  5209   5234            || pOp->opcode==OP_Offset
  5210   5235   #endif
................................................................................
  5216   5241               x = pPk->aiColumn[x];
  5217   5242               assert( x>=0 );
  5218   5243             }
  5219   5244             x = sqlite3ColumnOfIndex(pIdx, x);
  5220   5245             if( x>=0 ){
  5221   5246               pOp->p2 = x;
  5222   5247               pOp->p1 = pLevel->iIdxCur;
         5248  +            OpcodeRewriteTrace(db, k, pOp);
  5223   5249             }
  5224   5250             assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0 
  5225   5251                 || pWInfo->eOnePass );
  5226   5252           }else if( pOp->opcode==OP_Rowid ){
  5227   5253             pOp->p1 = pLevel->iIdxCur;
  5228   5254             pOp->opcode = OP_IdxRowid;
         5255  +          OpcodeRewriteTrace(db, k, pOp);
  5229   5256           }else if( pOp->opcode==OP_IfNullRow ){
  5230   5257             pOp->p1 = pLevel->iIdxCur;
         5258  +          OpcodeRewriteTrace(db, k, pOp);
  5231   5259           }
  5232   5260         }
         5261  +#ifdef SQLITE_DEBUG
         5262  +      if( db->flags & SQLITE_VdbeAddopTrace ) printf("TRANSLATE complete\n");
         5263  +#endif
  5233   5264       }
  5234   5265     }
  5235   5266   
  5236   5267     /* Final cleanup
  5237   5268     */
  5238   5269     pParse->nQueryLoop = pWInfo->savedNQueryLoop;
  5239   5270     whereInfoFree(db, pWInfo);
  5240   5271     return;
  5241   5272   }

Changes to src/whereexpr.c.

  1405   1405   ** Initialize a preallocated WhereClause structure.
  1406   1406   */
  1407   1407   void sqlite3WhereClauseInit(
  1408   1408     WhereClause *pWC,        /* The WhereClause to be initialized */
  1409   1409     WhereInfo *pWInfo        /* The WHERE processing context */
  1410   1410   ){
  1411   1411     pWC->pWInfo = pWInfo;
         1412  +  pWC->hasOr = 0;
  1412   1413     pWC->pOuter = 0;
  1413   1414     pWC->nTerm = 0;
  1414   1415     pWC->nSlot = ArraySize(pWC->aStatic);
  1415   1416     pWC->a = pWC->aStatic;
  1416   1417   }
  1417   1418   
  1418   1419   /*

Changes to test/insert.test.

   431    431   } {11 22}
   432    432   do_execsql_test insert-12.3 {
   433    433     CREATE TABLE t12c(a, b DEFAULT 'xyzzy', c);
   434    434     INSERT INTO t12c(a, rowid, c) SELECT 'one', 999, 'two';
   435    435     SELECT * FROM t12c;
   436    436   } {one xyzzy two}
   437    437   
          438  +# 2018-06-11.  From OSSFuzz.  A column cache malfunction in
          439  +# the constraint checking on an index of expressions causes
          440  +# an assertion fault in a REPLACE.  Ticket
          441  +# https://www.sqlite.org/src/info/c2432ef9089ee73b
          442  +#
          443  +do_execsql_test insert-13.1 {
          444  +  DROP TABLE IF EXISTS t13;
          445  +  CREATE TABLE t13(a INTEGER PRIMARY KEY,b UNIQUE);
          446  +  CREATE INDEX t13x1 ON t13(-b=b);
          447  +  INSERT INTO t13 VALUES(1,5),(6,2);
          448  +  REPLACE INTO t13 SELECT b,0 FROM t13;
          449  +  SELECT * FROM t13 ORDER BY +b;
          450  +} {2 0 6 2 1 5}
   438    451   
   439    452   integrity_check insert-99.0
   440    453   
   441    454   finish_test

Changes to test/releasetest.tcl.

   123    123       -DSQLITE_ENABLE_RTREE=1
   124    124       -DSQLITE_ENABLE_MEMSYS5=1
   125    125       -DSQLITE_ENABLE_COLUMN_METADATA=1
   126    126       -DSQLITE_ENABLE_STAT4
   127    127       -DSQLITE_ENABLE_HIDDEN_COLUMNS
   128    128       -DSQLITE_MAX_ATTACHED=125
   129    129       -DSQLITE_MUTATION_TEST
          130  +    --enable-fts5 --enable-json1
   130    131     }
   131    132     "Fast-One" {
   132    133       -O6
   133    134       -DSQLITE_ENABLE_FTS4=1
   134    135       -DSQLITE_ENABLE_RTREE=1
   135    136       -DSQLITE_ENABLE_STAT4
   136    137       -DSQLITE_ENABLE_RBU