sqlite: update from amalgamation 3.13.0 to 3.19.3
authorEdouard Tisserant <edouard@pep-project.org>
Fri, 07 Jul 2017 17:01:17 +0200
changeset 1912b2f4e198adef
parent 1911 db8b70e61f55
child 1913 57585bd12bd1
sqlite: update from amalgamation 3.13.0 to 3.19.3
src/sqlite3.c
src/sqlite3.h
     1.1 --- a/src/sqlite3.c	Fri Jul 07 16:17:10 2017 +0200
     1.2 +++ b/src/sqlite3.c	Fri Jul 07 17:01:17 2017 +0200
     1.3 @@ -1,6 +1,6 @@
     1.4  /******************************************************************************
     1.5  ** This file is an amalgamation of many separate C source files from SQLite
     1.6 -** version 3.13.0.  By combining all the individual C code files into this 
     1.7 +** version 3.19.3.  By combining all the individual C code files into this
     1.8  ** single large file, the entire code can be compiled as a single translation
     1.9  ** unit.  This allows many compilers to do optimizations that would not be
    1.10  ** possible if the files were compiled separately.  Performance improvements
    1.11 @@ -9,7 +9,7 @@
    1.12  **
    1.13  ** This file is all you need to compile SQLite.  To use SQLite in other
    1.14  ** programs, you need this file and the "sqlite3.h" header file that defines
    1.15 -** the programming interface to the SQLite library.  (If you do not have 
    1.16 +** the programming interface to the SQLite library.  (If you do not have
    1.17  ** the "sqlite3.h" header file at hand, you will find a copy embedded within
    1.18  ** the text of this file.  Search for "Begin file sqlite3.h" to find the start
    1.19  ** of the embedded sqlite3.h header file.) Additional code files may be needed
    1.20 @@ -37,8 +37,8 @@
    1.21  ** Internal interface definitions for SQLite.
    1.22  **
    1.23  */
    1.24 -#ifndef _SQLITEINT_H_
    1.25 -#define _SQLITEINT_H_
    1.26 +#ifndef SQLITEINT_H
    1.27 +#define SQLITEINT_H
    1.28  
    1.29  /* Special Comments:
    1.30  **
    1.31 @@ -68,6 +68,14 @@
    1.32  */
    1.33  
    1.34  /*
    1.35 +** Make sure the Tcl calling convention macro is defined.  This macro is
    1.36 +** only used by test code and Tcl integration code.
    1.37 +*/
    1.38 +#ifndef SQLITE_TCLAPI
    1.39 +#  define SQLITE_TCLAPI
    1.40 +#endif
    1.41 +
    1.42 +/*
    1.43  ** Make sure that rand_s() is available on Windows systems with MSVC 2005
    1.44  ** or higher.
    1.45  */
    1.46 @@ -97,8 +105,8 @@
    1.47  **
    1.48  ** This file contains code that is specific to MSVC.
    1.49  */
    1.50 -#ifndef _MSVC_H_
    1.51 -#define _MSVC_H_
    1.52 +#ifndef SQLITE_MSVC_H
    1.53 +#define SQLITE_MSVC_H
    1.54  
    1.55  #if defined(_MSC_VER)
    1.56  #pragma warning(disable : 4054)
    1.57 @@ -118,7 +126,7 @@
    1.58  #pragma warning(disable : 4706)
    1.59  #endif /* defined(_MSC_VER) */
    1.60  
    1.61 -#endif /* _MSVC_H_ */
    1.62 +#endif /* SQLITE_MSVC_H */
    1.63  
    1.64  /************** End of msvc.h ************************************************/
    1.65  /************** Continuing where we left off in sqliteInt.h ******************/
    1.66 @@ -196,12 +204,29 @@
    1.67  # define _LARGEFILE_SOURCE 1
    1.68  #endif
    1.69  
    1.70 -/* What version of GCC is being used.  0 means GCC is not being used */
    1.71 -#ifdef __GNUC__
    1.72 +/* The GCC_VERSION and MSVC_VERSION macros are used to
    1.73 +** conditionally include optimizations for each of these compilers.  A
    1.74 +** value of 0 means that compiler is not being used.  The
    1.75 +** SQLITE_DISABLE_INTRINSIC macro means do not use any compiler-specific
    1.76 +** optimizations, and hence set all compiler macros to 0
    1.77 +**
    1.78 +** There was once also a CLANG_VERSION macro.  However, we learn that the
    1.79 +** version numbers in clang are for "marketing" only and are inconsistent
    1.80 +** and unreliable.  Fortunately, all versions of clang also recognize the
    1.81 +** gcc version numbers and have reasonable settings for gcc version numbers,
    1.82 +** so the GCC_VERSION macro will be set to a correct non-zero value even
    1.83 +** when compiling with clang.
    1.84 +*/
    1.85 +#if defined(__GNUC__) && !defined(SQLITE_DISABLE_INTRINSIC)
    1.86  # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__)
    1.87  #else
    1.88  # define GCC_VERSION 0
    1.89  #endif
    1.90 +#if defined(_MSC_VER) && !defined(SQLITE_DISABLE_INTRINSIC)
    1.91 +# define MSVC_VERSION _MSC_VER
    1.92 +#else
    1.93 +# define MSVC_VERSION 0
    1.94 +#endif
    1.95  
    1.96  /* Needed for various definitions... */
    1.97  #if defined(__GNUC__) && !defined(_GNU_SOURCE)
    1.98 @@ -282,8 +307,8 @@
    1.99  ** the version number) and changes its name to "sqlite3.h" as
   1.100  ** part of the build process.
   1.101  */
   1.102 -#ifndef _SQLITE3_H_
   1.103 -#define _SQLITE3_H_
   1.104 +#ifndef SQLITE3_H
   1.105 +#define SQLITE3_H
   1.106  #include <stdarg.h>     /* Needed for the definition of va_list */
   1.107  
   1.108  /*
   1.109 @@ -306,8 +331,17 @@
   1.110  #ifndef SQLITE_CDECL
   1.111  # define SQLITE_CDECL
   1.112  #endif
   1.113 +#ifndef SQLITE_APICALL
   1.114 +# define SQLITE_APICALL
   1.115 +#endif
   1.116  #ifndef SQLITE_STDCALL
   1.117 -# define SQLITE_STDCALL
   1.118 +# define SQLITE_STDCALL SQLITE_APICALL
   1.119 +#endif
   1.120 +#ifndef SQLITE_CALLBACK
   1.121 +# define SQLITE_CALLBACK
   1.122 +#endif
   1.123 +#ifndef SQLITE_SYSAPI
   1.124 +# define SQLITE_SYSAPI
   1.125  #endif
   1.126  
   1.127  /*
   1.128 @@ -351,25 +385,26 @@
   1.129  ** be held constant and Z will be incremented or else Y will be incremented
   1.130  ** and Z will be reset to zero.
   1.131  **
   1.132 -** Since version 3.6.18, SQLite source code has been stored in the
   1.133 +** Since [version 3.6.18] ([dateof:3.6.18]), 
   1.134 +** SQLite source code has been stored in the
   1.135  ** <a href="http://www.fossil-scm.org/">Fossil configuration management
   1.136  ** system</a>.  ^The SQLITE_SOURCE_ID macro evaluates to
   1.137  ** a string which identifies a particular check-in of SQLite
   1.138  ** within its configuration management system.  ^The SQLITE_SOURCE_ID
   1.139 -** string contains the date and time of the check-in (UTC) and an SHA1
   1.140 -** hash of the entire source tree.
   1.141 +** string contains the date and time of the check-in (UTC) and a SHA1
   1.142 +** or SHA3-256 hash of the entire source tree.
   1.143  **
   1.144  ** See also: [sqlite3_libversion()],
   1.145  ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   1.146  ** [sqlite_version()] and [sqlite_source_id()].
   1.147  */
   1.148 -#define SQLITE_VERSION        "3.13.0"
   1.149 -#define SQLITE_VERSION_NUMBER 3013000
   1.150 -#define SQLITE_SOURCE_ID      "2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2"
   1.151 +#define SQLITE_VERSION        "3.19.3"
   1.152 +#define SQLITE_VERSION_NUMBER 3019003
   1.153 +#define SQLITE_SOURCE_ID      "2017-06-08 14:26:16 0ee482a1e0eae22e08edc8978c9733a96603d4509645f348ebf55b579e89636b"
   1.154  
   1.155  /*
   1.156  ** CAPI3REF: Run-Time Library Version Numbers
   1.157 -** KEYWORDS: sqlite3_version, sqlite3_sourceid
   1.158 +** KEYWORDS: sqlite3_version sqlite3_sourceid
   1.159  **
   1.160  ** These interfaces provide the same information as the [SQLITE_VERSION],
   1.161  ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
   1.162 @@ -398,9 +433,9 @@
   1.163  ** See also: [sqlite_version()] and [sqlite_source_id()].
   1.164  */
   1.165  SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
   1.166 -SQLITE_API const char *SQLITE_STDCALL sqlite3_libversion(void);
   1.167 -SQLITE_API const char *SQLITE_STDCALL sqlite3_sourceid(void);
   1.168 -SQLITE_API int SQLITE_STDCALL sqlite3_libversion_number(void);
   1.169 +SQLITE_API const char *sqlite3_libversion(void);
   1.170 +SQLITE_API const char *sqlite3_sourceid(void);
   1.171 +SQLITE_API int sqlite3_libversion_number(void);
   1.172  
   1.173  /*
   1.174  ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
   1.175 @@ -425,8 +460,8 @@
   1.176  ** [sqlite_compileoption_get()] and the [compile_options pragma].
   1.177  */
   1.178  #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
   1.179 -SQLITE_API int SQLITE_STDCALL sqlite3_compileoption_used(const char *zOptName);
   1.180 -SQLITE_API const char *SQLITE_STDCALL sqlite3_compileoption_get(int N);
   1.181 +SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
   1.182 +SQLITE_API const char *sqlite3_compileoption_get(int N);
   1.183  #endif
   1.184  
   1.185  /*
   1.186 @@ -465,7 +500,7 @@
   1.187  **
   1.188  ** See the [threading mode] documentation for additional information.
   1.189  */
   1.190 -SQLITE_API int SQLITE_STDCALL sqlite3_threadsafe(void);
   1.191 +SQLITE_API int sqlite3_threadsafe(void);
   1.192  
   1.193  /*
   1.194  ** CAPI3REF: Database Connection Handle
   1.195 @@ -501,7 +536,11 @@
   1.196  */
   1.197  #ifdef SQLITE_INT64_TYPE
   1.198    typedef SQLITE_INT64_TYPE sqlite_int64;
   1.199 -  typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
   1.200 +# ifdef SQLITE_UINT64_TYPE
   1.201 +    typedef SQLITE_UINT64_TYPE sqlite_uint64;
   1.202 +# else  
   1.203 +    typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
   1.204 +# endif
   1.205  #elif defined(_MSC_VER) || defined(__BORLANDC__)
   1.206    typedef __int64 sqlite_int64;
   1.207    typedef unsigned __int64 sqlite_uint64;
   1.208 @@ -562,8 +601,8 @@
   1.209  ** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer
   1.210  ** argument is a harmless no-op.
   1.211  */
   1.212 -SQLITE_API int SQLITE_STDCALL sqlite3_close(sqlite3*);
   1.213 -SQLITE_API int SQLITE_STDCALL sqlite3_close_v2(sqlite3*);
   1.214 +SQLITE_API int sqlite3_close(sqlite3*);
   1.215 +SQLITE_API int sqlite3_close_v2(sqlite3*);
   1.216  
   1.217  /*
   1.218  ** The type for a callback function.
   1.219 @@ -634,7 +673,7 @@
   1.220  **      the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
   1.221  ** </ul>
   1.222  */
   1.223 -SQLITE_API int SQLITE_STDCALL sqlite3_exec(
   1.224 +SQLITE_API int sqlite3_exec(
   1.225    sqlite3*,                                  /* An open database */
   1.226    const char *sql,                           /* SQL to be evaluated */
   1.227    int (*callback)(void*,int,char**,char**),  /* Callback function */
   1.228 @@ -695,7 +734,8 @@
   1.229  ** [result codes].  However, experience has shown that many of
   1.230  ** these result codes are too coarse-grained.  They do not provide as
   1.231  ** much information about problems as programmers might like.  In an effort to
   1.232 -** address this, newer versions of SQLite (version 3.3.8 and later) include
   1.233 +** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8]
   1.234 +** and later) include
   1.235  ** support for additional result codes that provide more detailed information
   1.236  ** about errors. These [extended result codes] are enabled or disabled
   1.237  ** on a per database connection basis using the
   1.238 @@ -758,6 +798,7 @@
   1.239  #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
   1.240  #define SQLITE_WARNING_AUTOINDEX       (SQLITE_WARNING | (1<<8))
   1.241  #define SQLITE_AUTH_USER               (SQLITE_AUTH | (1<<8))
   1.242 +#define SQLITE_OK_LOAD_PERMANENTLY     (SQLITE_OK | (1<<8))
   1.243  
   1.244  /*
   1.245  ** CAPI3REF: Flags For File Open Operations
   1.246 @@ -812,7 +853,7 @@
   1.247  ** file that were written at the application level might have changed
   1.248  ** and that adjacent bytes, even bytes within the same sector are
   1.249  ** guaranteed to be unchanged.  The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
   1.250 -** flag indicate that a file cannot be deleted when open.  The
   1.251 +** flag indicates that a file cannot be deleted when open.  The
   1.252  ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
   1.253  ** read-only media and cannot be changed even by processes with
   1.254  ** elevated privileges.
   1.255 @@ -962,6 +1003,9 @@
   1.256  ** <li> [SQLITE_IOCAP_ATOMIC64K]
   1.257  ** <li> [SQLITE_IOCAP_SAFE_APPEND]
   1.258  ** <li> [SQLITE_IOCAP_SEQUENTIAL]
   1.259 +** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
   1.260 +** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
   1.261 +** <li> [SQLITE_IOCAP_IMMUTABLE]
   1.262  ** </ul>
   1.263  **
   1.264  ** The SQLITE_IOCAP_ATOMIC property means that all writes of
   1.265 @@ -1090,7 +1134,7 @@
   1.266  ** opcode allows these two values (10 retries and 25 milliseconds of delay)
   1.267  ** to be adjusted.  The values are changed for all database connections
   1.268  ** within the same process.  The argument is a pointer to an array of two
   1.269 -** integers where the first integer i the new retry count and the second
   1.270 +** integers where the first integer is the new retry count and the second
   1.271  ** integer is the delay.  If either integer is negative, then the setting
   1.272  ** is not changed but instead the prior value of that setting is written
   1.273  ** into the array entry, allowing the current retry settings to be
   1.274 @@ -1218,6 +1262,12 @@
   1.275  ** on whether or not the file has been renamed, moved, or deleted since it
   1.276  ** was first opened.
   1.277  **
   1.278 +** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]]
   1.279 +** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the
   1.280 +** underlying native file handle associated with a file handle.  This file
   1.281 +** control interprets its argument as a pointer to a native file handle and
   1.282 +** writes the resulting value there.
   1.283 +**
   1.284  ** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
   1.285  ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging.  This
   1.286  ** opcode causes the xFileControl method to swap the file handle with the one
   1.287 @@ -1268,6 +1318,8 @@
   1.288  #define SQLITE_FCNTL_RBU                    26
   1.289  #define SQLITE_FCNTL_VFS_POINTER            27
   1.290  #define SQLITE_FCNTL_JOURNAL_POINTER        28
   1.291 +#define SQLITE_FCNTL_WIN32_GET_HANDLE       29
   1.292 +#define SQLITE_FCNTL_PDB                    30
   1.293  
   1.294  /* deprecated names */
   1.295  #define SQLITE_GET_LOCKPROXYFILE      SQLITE_FCNTL_GET_LOCKPROXYFILE
   1.296 @@ -1288,6 +1340,16 @@
   1.297  typedef struct sqlite3_mutex sqlite3_mutex;
   1.298  
   1.299  /*
   1.300 +** CAPI3REF: Loadable Extension Thunk
   1.301 +**
   1.302 +** A pointer to the opaque sqlite3_api_routines structure is passed as
   1.303 +** the third parameter to entry points of [loadable extensions].  This
   1.304 +** structure must be typedefed in order to work around compiler warnings
   1.305 +** on some platforms.
   1.306 +*/
   1.307 +typedef struct sqlite3_api_routines sqlite3_api_routines;
   1.308 +
   1.309 +/*
   1.310  ** CAPI3REF: OS Interface Object
   1.311  **
   1.312  ** An instance of the sqlite3_vfs object defines the interface between
   1.313 @@ -1622,10 +1684,10 @@
   1.314  ** must return [SQLITE_OK] on success and some other [error code] upon
   1.315  ** failure.
   1.316  */
   1.317 -SQLITE_API int SQLITE_STDCALL sqlite3_initialize(void);
   1.318 -SQLITE_API int SQLITE_STDCALL sqlite3_shutdown(void);
   1.319 -SQLITE_API int SQLITE_STDCALL sqlite3_os_init(void);
   1.320 -SQLITE_API int SQLITE_STDCALL sqlite3_os_end(void);
   1.321 +SQLITE_API int sqlite3_initialize(void);
   1.322 +SQLITE_API int sqlite3_shutdown(void);
   1.323 +SQLITE_API int sqlite3_os_init(void);
   1.324 +SQLITE_API int sqlite3_os_end(void);
   1.325  
   1.326  /*
   1.327  ** CAPI3REF: Configuring The SQLite Library
   1.328 @@ -1658,7 +1720,7 @@
   1.329  ** ^If the option is unknown or SQLite is unable to set the option
   1.330  ** then this routine returns a non-zero [error code].
   1.331  */
   1.332 -SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
   1.333 +SQLITE_API int sqlite3_config(int, ...);
   1.334  
   1.335  /*
   1.336  ** CAPI3REF: Configure database connections
   1.337 @@ -1677,7 +1739,7 @@
   1.338  ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
   1.339  ** the call is considered successful.
   1.340  */
   1.341 -SQLITE_API int SQLITE_CDECL sqlite3_db_config(sqlite3*, int op, ...);
   1.342 +SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
   1.343  
   1.344  /*
   1.345  ** CAPI3REF: Memory Allocation Routines
   1.346 @@ -2191,7 +2253,7 @@
   1.347  ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
   1.348  ** There should be two additional arguments.
   1.349  ** When the first argument to this interface is 1, then only the C-API is
   1.350 -** enabled and the SQL function remains disabled.  If the first argment to
   1.351 +** enabled and the SQL function remains disabled.  If the first argument to
   1.352  ** this interface is 0, then both the C-API and the SQL function are disabled.
   1.353  ** If the first argument is -1, then no changes are made to state of either the
   1.354  ** C-API or the SQL function.
   1.355 @@ -2201,13 +2263,36 @@
   1.356  ** be a NULL pointer, in which case the new setting is not reported back.
   1.357  ** </dd>
   1.358  **
   1.359 +** <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
   1.360 +** <dd> ^This option is used to change the name of the "main" database
   1.361 +** schema.  ^The sole argument is a pointer to a constant UTF8 string
   1.362 +** which will become the new schema name in place of "main".  ^SQLite
   1.363 +** does not make a copy of the new main schema name string, so the application
   1.364 +** must ensure that the argument passed into this DBCONFIG option is unchanged
   1.365 +** until after the database connection closes.
   1.366 +** </dd>
   1.367 +**
   1.368 +** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
   1.369 +** <dd> Usually, when a database in wal mode is closed or detached from a 
   1.370 +** database handle, SQLite checks if this will mean that there are now no 
   1.371 +** connections at all to the database. If so, it performs a checkpoint 
   1.372 +** operation before closing the connection. This option may be used to
   1.373 +** override this behaviour. The first parameter passed to this operation
   1.374 +** is an integer - non-zero to disable checkpoints-on-close, or zero (the
   1.375 +** default) to enable them. The second parameter is a pointer to an integer
   1.376 +** into which is written 0 or 1 to indicate whether checkpoints-on-close
   1.377 +** have been disabled - 0 if they are not disabled, 1 if they are.
   1.378 +** </dd>
   1.379 +**
   1.380  ** </dl>
   1.381  */
   1.382 +#define SQLITE_DBCONFIG_MAINDBNAME            1000 /* const char* */
   1.383  #define SQLITE_DBCONFIG_LOOKASIDE             1001 /* void* int int */
   1.384  #define SQLITE_DBCONFIG_ENABLE_FKEY           1002 /* int int* */
   1.385  #define SQLITE_DBCONFIG_ENABLE_TRIGGER        1003 /* int int* */
   1.386  #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
   1.387  #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
   1.388 +#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE      1006 /* int int* */
   1.389  
   1.390  
   1.391  /*
   1.392 @@ -2218,7 +2303,7 @@
   1.393  ** [extended result codes] feature of SQLite. ^The extended result
   1.394  ** codes are disabled by default for historical compatibility.
   1.395  */
   1.396 -SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
   1.397 +SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
   1.398  
   1.399  /*
   1.400  ** CAPI3REF: Last Insert Rowid
   1.401 @@ -2232,20 +2317,30 @@
   1.402  ** the table has a column of type [INTEGER PRIMARY KEY] then that column
   1.403  ** is another alias for the rowid.
   1.404  **
   1.405 -** ^The sqlite3_last_insert_rowid(D) interface returns the [rowid] of the 
   1.406 -** most recent successful [INSERT] into a rowid table or [virtual table]
   1.407 -** on database connection D.
   1.408 -** ^Inserts into [WITHOUT ROWID] tables are not recorded.
   1.409 -** ^If no successful [INSERT]s into rowid tables
   1.410 -** have ever occurred on the database connection D, 
   1.411 -** then sqlite3_last_insert_rowid(D) returns zero.
   1.412 -**
   1.413 -** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
   1.414 -** method, then this routine will return the [rowid] of the inserted
   1.415 -** row as long as the trigger or virtual table method is running.
   1.416 -** But once the trigger or virtual table method ends, the value returned 
   1.417 -** by this routine reverts to what it was before the trigger or virtual
   1.418 -** table method began.)^
   1.419 +** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of
   1.420 +** the most recent successful [INSERT] into a rowid table or [virtual table]
   1.421 +** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not
   1.422 +** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred 
   1.423 +** on the database connection D, then sqlite3_last_insert_rowid(D) returns 
   1.424 +** zero.
   1.425 +**
   1.426 +** As well as being set automatically as rows are inserted into database
   1.427 +** tables, the value returned by this function may be set explicitly by
   1.428 +** [sqlite3_set_last_insert_rowid()]
   1.429 +**
   1.430 +** Some virtual table implementations may INSERT rows into rowid tables as
   1.431 +** part of committing a transaction (e.g. to flush data accumulated in memory
   1.432 +** to disk). In this case subsequent calls to this function return the rowid
   1.433 +** associated with these internal INSERT operations, which leads to 
   1.434 +** unintuitive results. Virtual table implementations that do write to rowid
   1.435 +** tables in this way can avoid this problem by restoring the original 
   1.436 +** rowid value using [sqlite3_set_last_insert_rowid()] before returning 
   1.437 +** control to the user.
   1.438 +**
   1.439 +** ^(If an [INSERT] occurs within a trigger then this routine will 
   1.440 +** return the [rowid] of the inserted row as long as the trigger is 
   1.441 +** running. Once the trigger program ends, the value returned 
   1.442 +** by this routine reverts to what it was before the trigger was fired.)^
   1.443  **
   1.444  ** ^An [INSERT] that fails due to a constraint violation is not a
   1.445  ** successful [INSERT] and does not change the value returned by this
   1.446 @@ -2270,7 +2365,17 @@
   1.447  ** unpredictable and might not equal either the old or the new
   1.448  ** last insert [rowid].
   1.449  */
   1.450 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
   1.451 +SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
   1.452 +
   1.453 +/*
   1.454 +** CAPI3REF: Set the Last Insert Rowid value.
   1.455 +** METHOD: sqlite3
   1.456 +**
   1.457 +** The sqlite3_set_last_insert_rowid(D, R) method allows the application to
   1.458 +** set the value returned by calling sqlite3_last_insert_rowid(D) to R 
   1.459 +** without inserting a row into the database.
   1.460 +*/
   1.461 +SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);
   1.462  
   1.463  /*
   1.464  ** CAPI3REF: Count The Number Of Rows Modified
   1.465 @@ -2323,7 +2428,7 @@
   1.466  ** while [sqlite3_changes()] is running then the value returned
   1.467  ** is unpredictable and not meaningful.
   1.468  */
   1.469 -SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
   1.470 +SQLITE_API int sqlite3_changes(sqlite3*);
   1.471  
   1.472  /*
   1.473  ** CAPI3REF: Total Number Of Rows Modified
   1.474 @@ -2347,7 +2452,7 @@
   1.475  ** while [sqlite3_total_changes()] is running then the value
   1.476  ** returned is unpredictable and not meaningful.
   1.477  */
   1.478 -SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
   1.479 +SQLITE_API int sqlite3_total_changes(sqlite3*);
   1.480  
   1.481  /*
   1.482  ** CAPI3REF: Interrupt A Long-Running Query
   1.483 @@ -2383,11 +2488,8 @@
   1.484  ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
   1.485  ** SQL statements is a no-op and has no effect on SQL statements
   1.486  ** that are started after the sqlite3_interrupt() call returns.
   1.487 -**
   1.488 -** If the database connection closes while [sqlite3_interrupt()]
   1.489 -** is running then bad things will likely happen.
   1.490 -*/
   1.491 -SQLITE_API void SQLITE_STDCALL sqlite3_interrupt(sqlite3*);
   1.492 +*/
   1.493 +SQLITE_API void sqlite3_interrupt(sqlite3*);
   1.494  
   1.495  /*
   1.496  ** CAPI3REF: Determine If An SQL Statement Is Complete
   1.497 @@ -2422,8 +2524,8 @@
   1.498  ** The input to [sqlite3_complete16()] must be a zero-terminated
   1.499  ** UTF-16 string in native byte order.
   1.500  */
   1.501 -SQLITE_API int SQLITE_STDCALL sqlite3_complete(const char *sql);
   1.502 -SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
   1.503 +SQLITE_API int sqlite3_complete(const char *sql);
   1.504 +SQLITE_API int sqlite3_complete16(const void *sql);
   1.505  
   1.506  /*
   1.507  ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
   1.508 @@ -2484,7 +2586,7 @@
   1.509  ** A busy handler must not close the database connection
   1.510  ** or [prepared statement] that invoked the busy handler.
   1.511  */
   1.512 -SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
   1.513 +SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*);
   1.514  
   1.515  /*
   1.516  ** CAPI3REF: Set A Busy Timeout
   1.517 @@ -2507,7 +2609,7 @@
   1.518  **
   1.519  ** See also:  [PRAGMA busy_timeout]
   1.520  */
   1.521 -SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
   1.522 +SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
   1.523  
   1.524  /*
   1.525  ** CAPI3REF: Convenience Routines For Running Queries
   1.526 @@ -2582,7 +2684,7 @@
   1.527  ** reflected in subsequent calls to [sqlite3_errcode()] or
   1.528  ** [sqlite3_errmsg()].
   1.529  */
   1.530 -SQLITE_API int SQLITE_STDCALL sqlite3_get_table(
   1.531 +SQLITE_API int sqlite3_get_table(
   1.532    sqlite3 *db,          /* An open database */
   1.533    const char *zSql,     /* SQL to be evaluated */
   1.534    char ***pazResult,    /* Results of the query */
   1.535 @@ -2590,7 +2692,7 @@
   1.536    int *pnColumn,        /* Number of result columns written here */
   1.537    char **pzErrmsg       /* Error msg written here */
   1.538  );
   1.539 -SQLITE_API void SQLITE_STDCALL sqlite3_free_table(char **result);
   1.540 +SQLITE_API void sqlite3_free_table(char **result);
   1.541  
   1.542  /*
   1.543  ** CAPI3REF: Formatted String Printing Functions
   1.544 @@ -2696,10 +2798,10 @@
   1.545  ** addition that after the string has been read and copied into
   1.546  ** the result, [sqlite3_free()] is called on the input string.)^
   1.547  */
   1.548 -SQLITE_API char *SQLITE_CDECL sqlite3_mprintf(const char*,...);
   1.549 -SQLITE_API char *SQLITE_STDCALL sqlite3_vmprintf(const char*, va_list);
   1.550 -SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int,char*,const char*, ...);
   1.551 -SQLITE_API char *SQLITE_STDCALL sqlite3_vsnprintf(int,char*,const char*, va_list);
   1.552 +SQLITE_API char *sqlite3_mprintf(const char*,...);
   1.553 +SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
   1.554 +SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
   1.555 +SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
   1.556  
   1.557  /*
   1.558  ** CAPI3REF: Memory Allocation Subsystem
   1.559 @@ -2789,12 +2891,12 @@
   1.560  ** a block of memory after it has been released using
   1.561  ** [sqlite3_free()] or [sqlite3_realloc()].
   1.562  */
   1.563 -SQLITE_API void *SQLITE_STDCALL sqlite3_malloc(int);
   1.564 -SQLITE_API void *SQLITE_STDCALL sqlite3_malloc64(sqlite3_uint64);
   1.565 -SQLITE_API void *SQLITE_STDCALL sqlite3_realloc(void*, int);
   1.566 -SQLITE_API void *SQLITE_STDCALL sqlite3_realloc64(void*, sqlite3_uint64);
   1.567 -SQLITE_API void SQLITE_STDCALL sqlite3_free(void*);
   1.568 -SQLITE_API sqlite3_uint64 SQLITE_STDCALL sqlite3_msize(void*);
   1.569 +SQLITE_API void *sqlite3_malloc(int);
   1.570 +SQLITE_API void *sqlite3_malloc64(sqlite3_uint64);
   1.571 +SQLITE_API void *sqlite3_realloc(void*, int);
   1.572 +SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64);
   1.573 +SQLITE_API void sqlite3_free(void*);
   1.574 +SQLITE_API sqlite3_uint64 sqlite3_msize(void*);
   1.575  
   1.576  /*
   1.577  ** CAPI3REF: Memory Allocator Statistics
   1.578 @@ -2819,8 +2921,8 @@
   1.579  ** by [sqlite3_memory_highwater(1)] is the high-water mark
   1.580  ** prior to the reset.
   1.581  */
   1.582 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_used(void);
   1.583 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_highwater(int resetFlag);
   1.584 +SQLITE_API sqlite3_int64 sqlite3_memory_used(void);
   1.585 +SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
   1.586  
   1.587  /*
   1.588  ** CAPI3REF: Pseudo-Random Number Generator
   1.589 @@ -2843,11 +2945,12 @@
   1.590  ** internally and without recourse to the [sqlite3_vfs] xRandomness
   1.591  ** method.
   1.592  */
   1.593 -SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
   1.594 +SQLITE_API void sqlite3_randomness(int N, void *P);
   1.595  
   1.596  /*
   1.597  ** CAPI3REF: Compile-Time Authorization Callbacks
   1.598  ** METHOD: sqlite3
   1.599 +** KEYWORDS: {authorizer callback}
   1.600  **
   1.601  ** ^This routine registers an authorizer callback with a particular
   1.602  ** [database connection], supplied in the first argument.
   1.603 @@ -2875,8 +2978,10 @@
   1.604  ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
   1.605  ** to the callback is an integer [SQLITE_COPY | action code] that specifies
   1.606  ** the particular action to be authorized. ^The third through sixth parameters
   1.607 -** to the callback are zero-terminated strings that contain additional
   1.608 -** details about the action to be authorized.
   1.609 +** to the callback are either NULL pointers or zero-terminated strings
   1.610 +** that contain additional details about the action to be authorized.
   1.611 +** Applications must always be prepared to encounter a NULL pointer in any
   1.612 +** of the third through the sixth parameters of the authorization callback.
   1.613  **
   1.614  ** ^If the action code is [SQLITE_READ]
   1.615  ** and the callback returns [SQLITE_IGNORE] then the
   1.616 @@ -2885,6 +2990,10 @@
   1.617  ** been read if [SQLITE_OK] had been returned.  The [SQLITE_IGNORE]
   1.618  ** return can be used to deny an untrusted user access to individual
   1.619  ** columns of a table.
   1.620 +** ^When a table is referenced by a [SELECT] but no column values are
   1.621 +** extracted from that table (for example in a query like
   1.622 +** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
   1.623 +** is invoked once for that table with a column name that is an empty string.
   1.624  ** ^If the action code is [SQLITE_DELETE] and the callback returns
   1.625  ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
   1.626  ** [truncate optimization] is disabled and all rows are deleted individually.
   1.627 @@ -2926,7 +3035,7 @@
   1.628  ** as stated in the previous paragraph, sqlite3_step() invokes
   1.629  ** sqlite3_prepare_v2() to reprepare a statement after a schema change.
   1.630  */
   1.631 -SQLITE_API int SQLITE_STDCALL sqlite3_set_authorizer(
   1.632 +SQLITE_API int sqlite3_set_authorizer(
   1.633    sqlite3*,
   1.634    int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
   1.635    void *pUserData
   1.636 @@ -3006,6 +3115,9 @@
   1.637  ** CAPI3REF: Tracing And Profiling Functions
   1.638  ** METHOD: sqlite3
   1.639  **
   1.640 +** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
   1.641 +** instead of the routines described here.
   1.642 +**
   1.643  ** These routines register callback functions that can be used for
   1.644  ** tracing and profiling the execution of SQL statements.
   1.645  **
   1.646 @@ -3031,11 +3143,105 @@
   1.647  ** sqlite3_profile() function is considered experimental and is
   1.648  ** subject to change in future versions of SQLite.
   1.649  */
   1.650 -SQLITE_API void *SQLITE_STDCALL sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
   1.651 -SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
   1.652 +SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*,
   1.653 +   void(*xTrace)(void*,const char*), void*);
   1.654 +SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*,
   1.655     void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
   1.656  
   1.657  /*
   1.658 +** CAPI3REF: SQL Trace Event Codes
   1.659 +** KEYWORDS: SQLITE_TRACE
   1.660 +**
   1.661 +** These constants identify classes of events that can be monitored
   1.662 +** using the [sqlite3_trace_v2()] tracing logic.  The third argument
   1.663 +** to [sqlite3_trace_v2()] is an OR-ed combination of one or more of
   1.664 +** the following constants.  ^The first argument to the trace callback
   1.665 +** is one of the following constants.
   1.666 +**
   1.667 +** New tracing constants may be added in future releases.
   1.668 +**
   1.669 +** ^A trace callback has four arguments: xCallback(T,C,P,X).
   1.670 +** ^The T argument is one of the integer type codes above.
   1.671 +** ^The C argument is a copy of the context pointer passed in as the
   1.672 +** fourth argument to [sqlite3_trace_v2()].
   1.673 +** The P and X arguments are pointers whose meanings depend on T.
   1.674 +**
   1.675 +** <dl>
   1.676 +** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt>
   1.677 +** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement
   1.678 +** first begins running and possibly at other times during the
   1.679 +** execution of the prepared statement, such as at the start of each
   1.680 +** trigger subprogram. ^The P argument is a pointer to the
   1.681 +** [prepared statement]. ^The X argument is a pointer to a string which
   1.682 +** is the unexpanded SQL text of the prepared statement or an SQL comment 
   1.683 +** that indicates the invocation of a trigger.  ^The callback can compute
   1.684 +** the same text that would have been returned by the legacy [sqlite3_trace()]
   1.685 +** interface by using the X argument when X begins with "--" and invoking
   1.686 +** [sqlite3_expanded_sql(P)] otherwise.
   1.687 +**
   1.688 +** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
   1.689 +** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
   1.690 +** information as is provided by the [sqlite3_profile()] callback.
   1.691 +** ^The P argument is a pointer to the [prepared statement] and the
   1.692 +** X argument points to a 64-bit integer which is the estimated of
   1.693 +** the number of nanosecond that the prepared statement took to run.
   1.694 +** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
   1.695 +**
   1.696 +** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
   1.697 +** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
   1.698 +** statement generates a single row of result.  
   1.699 +** ^The P argument is a pointer to the [prepared statement] and the
   1.700 +** X argument is unused.
   1.701 +**
   1.702 +** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt>
   1.703 +** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database
   1.704 +** connection closes.
   1.705 +** ^The P argument is a pointer to the [database connection] object
   1.706 +** and the X argument is unused.
   1.707 +** </dl>
   1.708 +*/
   1.709 +#define SQLITE_TRACE_STMT       0x01
   1.710 +#define SQLITE_TRACE_PROFILE    0x02
   1.711 +#define SQLITE_TRACE_ROW        0x04
   1.712 +#define SQLITE_TRACE_CLOSE      0x08
   1.713 +
   1.714 +/*
   1.715 +** CAPI3REF: SQL Trace Hook
   1.716 +** METHOD: sqlite3
   1.717 +**
   1.718 +** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback
   1.719 +** function X against [database connection] D, using property mask M
   1.720 +** and context pointer P.  ^If the X callback is
   1.721 +** NULL or if the M mask is zero, then tracing is disabled.  The
   1.722 +** M argument should be the bitwise OR-ed combination of
   1.723 +** zero or more [SQLITE_TRACE] constants.
   1.724 +**
   1.725 +** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides 
   1.726 +** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2().
   1.727 +**
   1.728 +** ^The X callback is invoked whenever any of the events identified by 
   1.729 +** mask M occur.  ^The integer return value from the callback is currently
   1.730 +** ignored, though this may change in future releases.  Callback
   1.731 +** implementations should return zero to ensure future compatibility.
   1.732 +**
   1.733 +** ^A trace callback is invoked with four arguments: callback(T,C,P,X).
   1.734 +** ^The T argument is one of the [SQLITE_TRACE]
   1.735 +** constants to indicate why the callback was invoked.
   1.736 +** ^The C argument is a copy of the context pointer.
   1.737 +** The P and X arguments are pointers whose meanings depend on T.
   1.738 +**
   1.739 +** The sqlite3_trace_v2() interface is intended to replace the legacy
   1.740 +** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which
   1.741 +** are deprecated.
   1.742 +*/
   1.743 +SQLITE_API int sqlite3_trace_v2(
   1.744 +  sqlite3*,
   1.745 +  unsigned uMask,
   1.746 +  int(*xCallback)(unsigned,void*,void*,void*),
   1.747 +  void *pCtx
   1.748 +);
   1.749 +
   1.750 +/*
   1.751  ** CAPI3REF: Query Progress Callbacks
   1.752  ** METHOD: sqlite3
   1.753  **
   1.754 @@ -3067,7 +3273,7 @@
   1.755  ** database connections for the meaning of "modify" in this paragraph.
   1.756  **
   1.757  */
   1.758 -SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
   1.759 +SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
   1.760  
   1.761  /*
   1.762  ** CAPI3REF: Opening A New Database Connection
   1.763 @@ -3296,15 +3502,15 @@
   1.764  **
   1.765  ** See also: [sqlite3_temp_directory]
   1.766  */
   1.767 -SQLITE_API int SQLITE_STDCALL sqlite3_open(
   1.768 +SQLITE_API int sqlite3_open(
   1.769    const char *filename,   /* Database filename (UTF-8) */
   1.770    sqlite3 **ppDb          /* OUT: SQLite db handle */
   1.771  );
   1.772 -SQLITE_API int SQLITE_STDCALL sqlite3_open16(
   1.773 +SQLITE_API int sqlite3_open16(
   1.774    const void *filename,   /* Database filename (UTF-16) */
   1.775    sqlite3 **ppDb          /* OUT: SQLite db handle */
   1.776  );
   1.777 -SQLITE_API int SQLITE_STDCALL sqlite3_open_v2(
   1.778 +SQLITE_API int sqlite3_open_v2(
   1.779    const char *filename,   /* Database filename (UTF-8) */
   1.780    sqlite3 **ppDb,         /* OUT: SQLite db handle */
   1.781    int flags,              /* Flags */
   1.782 @@ -3350,9 +3556,9 @@
   1.783  ** VFS method, then the behavior of this routine is undefined and probably
   1.784  ** undesirable.
   1.785  */
   1.786 -SQLITE_API const char *SQLITE_STDCALL sqlite3_uri_parameter(const char *zFilename, const char *zParam);
   1.787 -SQLITE_API int SQLITE_STDCALL sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
   1.788 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
   1.789 +SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
   1.790 +SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
   1.791 +SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
   1.792  
   1.793  
   1.794  /*
   1.795 @@ -3396,11 +3602,11 @@
   1.796  ** was invoked incorrectly by the application.  In that case, the
   1.797  ** error code and message may or may not be set.
   1.798  */
   1.799 -SQLITE_API int SQLITE_STDCALL sqlite3_errcode(sqlite3 *db);
   1.800 -SQLITE_API int SQLITE_STDCALL sqlite3_extended_errcode(sqlite3 *db);
   1.801 -SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
   1.802 -SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
   1.803 -SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
   1.804 +SQLITE_API int sqlite3_errcode(sqlite3 *db);
   1.805 +SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
   1.806 +SQLITE_API const char *sqlite3_errmsg(sqlite3*);
   1.807 +SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
   1.808 +SQLITE_API const char *sqlite3_errstr(int);
   1.809  
   1.810  /*
   1.811  ** CAPI3REF: Prepared Statement Object
   1.812 @@ -3468,7 +3674,7 @@
   1.813  **
   1.814  ** New run-time limit categories may be added in future releases.
   1.815  */
   1.816 -SQLITE_API int SQLITE_STDCALL sqlite3_limit(sqlite3*, int id, int newVal);
   1.817 +SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
   1.818  
   1.819  /*
   1.820  ** CAPI3REF: Run-Time Limit Categories
   1.821 @@ -3499,9 +3705,9 @@
   1.822  **
   1.823  ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
   1.824  ** <dd>The maximum number of instructions in a virtual machine program
   1.825 -** used to implement an SQL statement.  This limit is not currently
   1.826 -** enforced, though that might be added in some future release of
   1.827 -** SQLite.</dd>)^
   1.828 +** used to implement an SQL statement.  If [sqlite3_prepare_v2()] or
   1.829 +** the equivalent tries to allocate space for more than this many opcodes
   1.830 +** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^
   1.831  **
   1.832  ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
   1.833  ** <dd>The maximum number of arguments on a function.</dd>)^
   1.834 @@ -3539,6 +3745,7 @@
   1.835  #define SQLITE_LIMIT_TRIGGER_DEPTH            10
   1.836  #define SQLITE_LIMIT_WORKER_THREADS           11
   1.837  
   1.838 +
   1.839  /*
   1.840  ** CAPI3REF: Compiling An SQL Statement
   1.841  ** KEYWORDS: {SQL statement compiler}
   1.842 @@ -3620,28 +3827,28 @@
   1.843  ** </li>
   1.844  ** </ol>
   1.845  */
   1.846 -SQLITE_API int SQLITE_STDCALL sqlite3_prepare(
   1.847 +SQLITE_API int sqlite3_prepare(
   1.848    sqlite3 *db,            /* Database handle */
   1.849    const char *zSql,       /* SQL statement, UTF-8 encoded */
   1.850    int nByte,              /* Maximum length of zSql in bytes. */
   1.851    sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
   1.852    const char **pzTail     /* OUT: Pointer to unused portion of zSql */
   1.853  );
   1.854 -SQLITE_API int SQLITE_STDCALL sqlite3_prepare_v2(
   1.855 +SQLITE_API int sqlite3_prepare_v2(
   1.856    sqlite3 *db,            /* Database handle */
   1.857    const char *zSql,       /* SQL statement, UTF-8 encoded */
   1.858    int nByte,              /* Maximum length of zSql in bytes. */
   1.859    sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
   1.860    const char **pzTail     /* OUT: Pointer to unused portion of zSql */
   1.861  );
   1.862 -SQLITE_API int SQLITE_STDCALL sqlite3_prepare16(
   1.863 +SQLITE_API int sqlite3_prepare16(
   1.864    sqlite3 *db,            /* Database handle */
   1.865    const void *zSql,       /* SQL statement, UTF-16 encoded */
   1.866    int nByte,              /* Maximum length of zSql in bytes. */
   1.867    sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
   1.868    const void **pzTail     /* OUT: Pointer to unused portion of zSql */
   1.869  );
   1.870 -SQLITE_API int SQLITE_STDCALL sqlite3_prepare16_v2(
   1.871 +SQLITE_API int sqlite3_prepare16_v2(
   1.872    sqlite3 *db,            /* Database handle */
   1.873    const void *zSql,       /* SQL statement, UTF-16 encoded */
   1.874    int nByte,              /* Maximum length of zSql in bytes. */
   1.875 @@ -3653,11 +3860,35 @@
   1.876  ** CAPI3REF: Retrieving Statement SQL
   1.877  ** METHOD: sqlite3_stmt
   1.878  **
   1.879 -** ^This interface can be used to retrieve a saved copy of the original
   1.880 -** SQL text used to create a [prepared statement] if that statement was
   1.881 -** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
   1.882 -*/
   1.883 -SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
   1.884 +** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8
   1.885 +** SQL text used to create [prepared statement] P if P was
   1.886 +** created by either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
   1.887 +** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8
   1.888 +** string containing the SQL text of prepared statement P with
   1.889 +** [bound parameters] expanded.
   1.890 +**
   1.891 +** ^(For example, if a prepared statement is created using the SQL
   1.892 +** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345
   1.893 +** and parameter :xyz is unbound, then sqlite3_sql() will return
   1.894 +** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
   1.895 +** will return "SELECT 2345,NULL".)^
   1.896 +**
   1.897 +** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
   1.898 +** is available to hold the result, or if the result would exceed the
   1.899 +** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
   1.900 +**
   1.901 +** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
   1.902 +** bound parameter expansions.  ^The [SQLITE_OMIT_TRACE] compile-time
   1.903 +** option causes sqlite3_expanded_sql() to always return NULL.
   1.904 +**
   1.905 +** ^The string returned by sqlite3_sql(P) is managed by SQLite and is
   1.906 +** automatically freed when the prepared statement is finalized.
   1.907 +** ^The string returned by sqlite3_expanded_sql(P), on the other hand,
   1.908 +** is obtained from [sqlite3_malloc()] and must be free by the application
   1.909 +** by passing it to [sqlite3_free()].
   1.910 +*/
   1.911 +SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
   1.912 +SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt);
   1.913  
   1.914  /*
   1.915  ** CAPI3REF: Determine If An SQL Statement Writes The Database
   1.916 @@ -3688,8 +3919,12 @@
   1.917  ** sqlite3_stmt_readonly() to return true since, while those statements
   1.918  ** change the configuration of a database connection, they do not make 
   1.919  ** changes to the content of the database files on disk.
   1.920 -*/
   1.921 -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
   1.922 +** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
   1.923 +** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
   1.924 +** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
   1.925 +** sqlite3_stmt_readonly() returns false for those commands.
   1.926 +*/
   1.927 +SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
   1.928  
   1.929  /*
   1.930  ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
   1.931 @@ -3710,7 +3945,7 @@
   1.932  ** for example, in diagnostic routines to search for prepared 
   1.933  ** statements that are holding a transaction open.
   1.934  */
   1.935 -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_busy(sqlite3_stmt*);
   1.936 +SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*);
   1.937  
   1.938  /*
   1.939  ** CAPI3REF: Dynamically Typed Value Object
   1.940 @@ -3751,7 +3986,7 @@
   1.941  ** The [sqlite3_value_blob | sqlite3_value_type()] family of
   1.942  ** interfaces require protected sqlite3_value objects.
   1.943  */
   1.944 -typedef struct Mem sqlite3_value;
   1.945 +typedef struct sqlite3_value sqlite3_value;
   1.946  
   1.947  /*
   1.948  ** CAPI3REF: SQL Function Context Object
   1.949 @@ -3874,20 +4109,20 @@
   1.950  ** See also: [sqlite3_bind_parameter_count()],
   1.951  ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
   1.952  */
   1.953 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
   1.954 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
   1.955 +SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
   1.956 +SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
   1.957                          void(*)(void*));
   1.958 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_double(sqlite3_stmt*, int, double);
   1.959 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_int(sqlite3_stmt*, int, int);
   1.960 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
   1.961 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_null(sqlite3_stmt*, int);
   1.962 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
   1.963 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
   1.964 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
   1.965 +SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
   1.966 +SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
   1.967 +SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
   1.968 +SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
   1.969 +SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
   1.970 +SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
   1.971 +SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
   1.972                           void(*)(void*), unsigned char encoding);
   1.973 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
   1.974 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
   1.975 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
   1.976 +SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
   1.977 +SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
   1.978 +SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
   1.979  
   1.980  /*
   1.981  ** CAPI3REF: Number Of SQL Parameters
   1.982 @@ -3908,7 +4143,7 @@
   1.983  ** [sqlite3_bind_parameter_name()], and
   1.984  ** [sqlite3_bind_parameter_index()].
   1.985  */
   1.986 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
   1.987 +SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*);
   1.988  
   1.989  /*
   1.990  ** CAPI3REF: Name Of A Host Parameter
   1.991 @@ -3936,7 +4171,7 @@
   1.992  ** [sqlite3_bind_parameter_count()], and
   1.993  ** [sqlite3_bind_parameter_index()].
   1.994  */
   1.995 -SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
   1.996 +SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
   1.997  
   1.998  /*
   1.999  ** CAPI3REF: Index Of A Parameter With A Given Name
  1.1000 @@ -3953,7 +4188,7 @@
  1.1001  ** [sqlite3_bind_parameter_count()], and
  1.1002  ** [sqlite3_bind_parameter_name()].
  1.1003  */
  1.1004 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
  1.1005 +SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
  1.1006  
  1.1007  /*
  1.1008  ** CAPI3REF: Reset All Bindings On A Prepared Statement
  1.1009 @@ -3963,19 +4198,23 @@
  1.1010  ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
  1.1011  ** ^Use this routine to reset all host parameters to NULL.
  1.1012  */
  1.1013 -SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
  1.1014 +SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);
  1.1015  
  1.1016  /*
  1.1017  ** CAPI3REF: Number Of Columns In A Result Set
  1.1018  ** METHOD: sqlite3_stmt
  1.1019  **
  1.1020  ** ^Return the number of columns in the result set returned by the
  1.1021 -** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
  1.1022 -** statement that does not return data (for example an [UPDATE]).
  1.1023 +** [prepared statement]. ^If this routine returns 0, that means the 
  1.1024 +** [prepared statement] returns no data (for example an [UPDATE]).
  1.1025 +** ^However, just because this routine returns a positive number does not
  1.1026 +** mean that one or more rows of data will be returned.  ^A SELECT statement
  1.1027 +** will always have a positive sqlite3_column_count() but depending on the
  1.1028 +** WHERE clause constraints and the table content, it might return no rows.
  1.1029  **
  1.1030  ** See also: [sqlite3_data_count()]
  1.1031  */
  1.1032 -SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
  1.1033 +SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
  1.1034  
  1.1035  /*
  1.1036  ** CAPI3REF: Column Names In A Result Set
  1.1037 @@ -4004,8 +4243,8 @@
  1.1038  ** then the name of the column is unspecified and may change from
  1.1039  ** one release of SQLite to the next.
  1.1040  */
  1.1041 -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
  1.1042 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
  1.1043 +SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);
  1.1044 +SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);
  1.1045  
  1.1046  /*
  1.1047  ** CAPI3REF: Source Of Data In A Query Result
  1.1048 @@ -4053,12 +4292,12 @@
  1.1049  ** for the same [prepared statement] and result column
  1.1050  ** at the same time then the results are undefined.
  1.1051  */
  1.1052 -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_database_name(sqlite3_stmt*,int);
  1.1053 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_database_name16(sqlite3_stmt*,int);
  1.1054 -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_table_name(sqlite3_stmt*,int);
  1.1055 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_table_name16(sqlite3_stmt*,int);
  1.1056 -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
  1.1057 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
  1.1058 +SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int);
  1.1059 +SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
  1.1060 +SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int);
  1.1061 +SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
  1.1062 +SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
  1.1063 +SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
  1.1064  
  1.1065  /*
  1.1066  ** CAPI3REF: Declared Datatype Of A Query Result
  1.1067 @@ -4090,8 +4329,8 @@
  1.1068  ** is associated with individual values, not with the containers
  1.1069  ** used to hold those values.
  1.1070  */
  1.1071 -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
  1.1072 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
  1.1073 +SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int);
  1.1074 +SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
  1.1075  
  1.1076  /*
  1.1077  ** CAPI3REF: Evaluate An SQL Statement
  1.1078 @@ -4152,7 +4391,8 @@
  1.1079  ** other than [SQLITE_ROW] before any subsequent invocation of
  1.1080  ** sqlite3_step().  Failure to reset the prepared statement using 
  1.1081  ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
  1.1082 -** sqlite3_step().  But after version 3.6.23.1, sqlite3_step() began
  1.1083 +** sqlite3_step().  But after [version 3.6.23.1] ([dateof:3.6.23.1],
  1.1084 +** sqlite3_step() began
  1.1085  ** calling [sqlite3_reset()] automatically in this circumstance rather
  1.1086  ** than returning [SQLITE_MISUSE].  This is not considered a compatibility
  1.1087  ** break because any application that ever receives an SQLITE_MISUSE error
  1.1088 @@ -4171,7 +4411,7 @@
  1.1089  ** then the more specific [error codes] are returned directly
  1.1090  ** by sqlite3_step().  The use of the "v2" interface is recommended.
  1.1091  */
  1.1092 -SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
  1.1093 +SQLITE_API int sqlite3_step(sqlite3_stmt*);
  1.1094  
  1.1095  /*
  1.1096  ** CAPI3REF: Number of columns in a result set
  1.1097 @@ -4192,7 +4432,7 @@
  1.1098  **
  1.1099  ** See also: [sqlite3_column_count()]
  1.1100  */
  1.1101 -SQLITE_API int SQLITE_STDCALL sqlite3_data_count(sqlite3_stmt *pStmt);
  1.1102 +SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
  1.1103  
  1.1104  /*
  1.1105  ** CAPI3REF: Fundamental Datatypes
  1.1106 @@ -4382,16 +4622,16 @@
  1.1107  ** pointer.  Subsequent calls to [sqlite3_errcode()] will return
  1.1108  ** [SQLITE_NOMEM].)^
  1.1109  */
  1.1110 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_blob(sqlite3_stmt*, int iCol);
  1.1111 -SQLITE_API int SQLITE_STDCALL sqlite3_column_bytes(sqlite3_stmt*, int iCol);
  1.1112 -SQLITE_API int SQLITE_STDCALL sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
  1.1113 -SQLITE_API double SQLITE_STDCALL sqlite3_column_double(sqlite3_stmt*, int iCol);
  1.1114 -SQLITE_API int SQLITE_STDCALL sqlite3_column_int(sqlite3_stmt*, int iCol);
  1.1115 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_column_int64(sqlite3_stmt*, int iCol);
  1.1116 -SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_column_text(sqlite3_stmt*, int iCol);
  1.1117 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_text16(sqlite3_stmt*, int iCol);
  1.1118 -SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
  1.1119 -SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
  1.1120 +SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
  1.1121 +SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
  1.1122 +SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
  1.1123 +SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol);
  1.1124 +SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol);
  1.1125 +SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
  1.1126 +SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
  1.1127 +SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
  1.1128 +SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);
  1.1129 +SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
  1.1130  
  1.1131  /*
  1.1132  ** CAPI3REF: Destroy A Prepared Statement Object
  1.1133 @@ -4419,7 +4659,7 @@
  1.1134  ** statement after it has been finalized can result in undefined and
  1.1135  ** undesirable behavior such as segfaults and heap corruption.
  1.1136  */
  1.1137 -SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
  1.1138 +SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
  1.1139  
  1.1140  /*
  1.1141  ** CAPI3REF: Reset A Prepared Statement Object
  1.1142 @@ -4446,7 +4686,7 @@
  1.1143  ** ^The [sqlite3_reset(S)] interface does not change the values
  1.1144  ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
  1.1145  */
  1.1146 -SQLITE_API int SQLITE_STDCALL sqlite3_reset(sqlite3_stmt *pStmt);
  1.1147 +SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
  1.1148  
  1.1149  /*
  1.1150  ** CAPI3REF: Create Or Redefine SQL Functions
  1.1151 @@ -4546,7 +4786,7 @@
  1.1152  ** close the database connection nor finalize or reset the prepared
  1.1153  ** statement in which the function is running.
  1.1154  */
  1.1155 -SQLITE_API int SQLITE_STDCALL sqlite3_create_function(
  1.1156 +SQLITE_API int sqlite3_create_function(
  1.1157    sqlite3 *db,
  1.1158    const char *zFunctionName,
  1.1159    int nArg,
  1.1160 @@ -4556,7 +4796,7 @@
  1.1161    void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  1.1162    void (*xFinal)(sqlite3_context*)
  1.1163  );
  1.1164 -SQLITE_API int SQLITE_STDCALL sqlite3_create_function16(
  1.1165 +SQLITE_API int sqlite3_create_function16(
  1.1166    sqlite3 *db,
  1.1167    const void *zFunctionName,
  1.1168    int nArg,
  1.1169 @@ -4566,7 +4806,7 @@
  1.1170    void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  1.1171    void (*xFinal)(sqlite3_context*)
  1.1172  );
  1.1173 -SQLITE_API int SQLITE_STDCALL sqlite3_create_function_v2(
  1.1174 +SQLITE_API int sqlite3_create_function_v2(
  1.1175    sqlite3 *db,
  1.1176    const char *zFunctionName,
  1.1177    int nArg,
  1.1178 @@ -4612,12 +4852,12 @@
  1.1179  ** these functions, we will not explain what they do.
  1.1180  */
  1.1181  #ifndef SQLITE_OMIT_DEPRECATED
  1.1182 -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_aggregate_count(sqlite3_context*);
  1.1183 -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_expired(sqlite3_stmt*);
  1.1184 -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
  1.1185 -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_global_recover(void);
  1.1186 -SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_thread_cleanup(void);
  1.1187 -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
  1.1188 +SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
  1.1189 +SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
  1.1190 +SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
  1.1191 +SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
  1.1192 +SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
  1.1193 +SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
  1.1194                        void*,sqlite3_int64);
  1.1195  #endif
  1.1196  
  1.1197 @@ -4667,18 +4907,18 @@
  1.1198  ** These routines must be called from the same thread as
  1.1199  ** the SQL function that supplied the [sqlite3_value*] parameters.
  1.1200  */
  1.1201 -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_blob(sqlite3_value*);
  1.1202 -SQLITE_API int SQLITE_STDCALL sqlite3_value_bytes(sqlite3_value*);
  1.1203 -SQLITE_API int SQLITE_STDCALL sqlite3_value_bytes16(sqlite3_value*);
  1.1204 -SQLITE_API double SQLITE_STDCALL sqlite3_value_double(sqlite3_value*);
  1.1205 -SQLITE_API int SQLITE_STDCALL sqlite3_value_int(sqlite3_value*);
  1.1206 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_value_int64(sqlite3_value*);
  1.1207 -SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_value_text(sqlite3_value*);
  1.1208 -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16(sqlite3_value*);
  1.1209 -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16le(sqlite3_value*);
  1.1210 -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16be(sqlite3_value*);
  1.1211 -SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
  1.1212 -SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
  1.1213 +SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
  1.1214 +SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
  1.1215 +SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
  1.1216 +SQLITE_API double sqlite3_value_double(sqlite3_value*);
  1.1217 +SQLITE_API int sqlite3_value_int(sqlite3_value*);
  1.1218 +SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
  1.1219 +SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
  1.1220 +SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
  1.1221 +SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
  1.1222 +SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
  1.1223 +SQLITE_API int sqlite3_value_type(sqlite3_value*);
  1.1224 +SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
  1.1225  
  1.1226  /*
  1.1227  ** CAPI3REF: Finding The Subtype Of SQL Values
  1.1228 @@ -4694,7 +4934,7 @@
  1.1229  ** from the result of one [application-defined SQL function] into the
  1.1230  ** input of another.
  1.1231  */
  1.1232 -SQLITE_API unsigned int SQLITE_STDCALL sqlite3_value_subtype(sqlite3_value*);
  1.1233 +SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*);
  1.1234  
  1.1235  /*
  1.1236  ** CAPI3REF: Copy And Free SQL Values
  1.1237 @@ -4710,8 +4950,8 @@
  1.1238  ** previously obtained from [sqlite3_value_dup()].  ^If V is a NULL pointer
  1.1239  ** then sqlite3_value_free(V) is a harmless no-op.
  1.1240  */
  1.1241 -SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_value_dup(const sqlite3_value*);
  1.1242 -SQLITE_API void SQLITE_STDCALL sqlite3_value_free(sqlite3_value*);
  1.1243 +SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value*);
  1.1244 +SQLITE_API void sqlite3_value_free(sqlite3_value*);
  1.1245  
  1.1246  /*
  1.1247  ** CAPI3REF: Obtain Aggregate Function Context
  1.1248 @@ -4756,7 +4996,7 @@
  1.1249  ** This routine must be called from the same thread in which
  1.1250  ** the aggregate SQL function is running.
  1.1251  */
  1.1252 -SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
  1.1253 +SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
  1.1254  
  1.1255  /*
  1.1256  ** CAPI3REF: User Data For Functions
  1.1257 @@ -4771,7 +5011,7 @@
  1.1258  ** This routine must be called from the same thread in which
  1.1259  ** the application-defined function is running.
  1.1260  */
  1.1261 -SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
  1.1262 +SQLITE_API void *sqlite3_user_data(sqlite3_context*);
  1.1263  
  1.1264  /*
  1.1265  ** CAPI3REF: Database Connection For Functions
  1.1266 @@ -4783,7 +5023,7 @@
  1.1267  ** and [sqlite3_create_function16()] routines that originally
  1.1268  ** registered the application defined function.
  1.1269  */
  1.1270 -SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
  1.1271 +SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
  1.1272  
  1.1273  /*
  1.1274  ** CAPI3REF: Function Auxiliary Data
  1.1275 @@ -4800,10 +5040,11 @@
  1.1276  ** the compiled regular expression can be reused on multiple
  1.1277  ** invocations of the same function.
  1.1278  **
  1.1279 -** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
  1.1280 -** associated by the sqlite3_set_auxdata() function with the Nth argument
  1.1281 -** value to the application-defined function. ^If there is no metadata
  1.1282 -** associated with the function argument, this sqlite3_get_auxdata() interface
  1.1283 +** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata
  1.1284 +** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument
  1.1285 +** value to the application-defined function.  ^N is zero for the left-most
  1.1286 +** function argument.  ^If there is no metadata
  1.1287 +** associated with the function argument, the sqlite3_get_auxdata(C,N) interface
  1.1288  ** returns a NULL pointer.
  1.1289  **
  1.1290  ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
  1.1291 @@ -4815,12 +5056,13 @@
  1.1292  ** SQLite will invoke the destructor function X with parameter P exactly
  1.1293  ** once, when the metadata is discarded.
  1.1294  ** SQLite is free to discard the metadata at any time, including: <ul>
  1.1295 -** <li> when the corresponding function parameter changes, or
  1.1296 -** <li> when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
  1.1297 -**      SQL statement, or
  1.1298 -** <li> when sqlite3_set_auxdata() is invoked again on the same parameter, or
  1.1299 -** <li> during the original sqlite3_set_auxdata() call when a memory 
  1.1300 -**      allocation error occurs. </ul>)^
  1.1301 +** <li> ^(when the corresponding function parameter changes)^, or
  1.1302 +** <li> ^(when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
  1.1303 +**      SQL statement)^, or
  1.1304 +** <li> ^(when sqlite3_set_auxdata() is invoked again on the same
  1.1305 +**       parameter)^, or
  1.1306 +** <li> ^(during the original sqlite3_set_auxdata() call when a memory 
  1.1307 +**      allocation error occurs.)^ </ul>
  1.1308  **
  1.1309  ** Note the last bullet in particular.  The destructor X in 
  1.1310  ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
  1.1311 @@ -4833,11 +5075,15 @@
  1.1312  ** function parameters that are compile-time constants, including literal
  1.1313  ** values and [parameters] and expressions composed from the same.)^
  1.1314  **
  1.1315 +** The value of the N parameter to these interfaces should be non-negative.
  1.1316 +** Future enhancements may make use of negative N values to define new
  1.1317 +** kinds of function caching behavior.
  1.1318 +**
  1.1319  ** These routines must be called from the same thread in which
  1.1320  ** the SQL function is running.
  1.1321  */
  1.1322 -SQLITE_API void *SQLITE_STDCALL sqlite3_get_auxdata(sqlite3_context*, int N);
  1.1323 -SQLITE_API void SQLITE_STDCALL sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
  1.1324 +SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
  1.1325 +SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
  1.1326  
  1.1327  
  1.1328  /*
  1.1329 @@ -4973,27 +5219,27 @@
  1.1330  ** than the one containing the application-defined function that received
  1.1331  ** the [sqlite3_context] pointer, the results are undefined.
  1.1332  */
  1.1333 -SQLITE_API void SQLITE_STDCALL sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
  1.1334 -SQLITE_API void SQLITE_STDCALL sqlite3_result_blob64(sqlite3_context*,const void*,
  1.1335 +SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
  1.1336 +SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,
  1.1337                             sqlite3_uint64,void(*)(void*));
  1.1338 -SQLITE_API void SQLITE_STDCALL sqlite3_result_double(sqlite3_context*, double);
  1.1339 -SQLITE_API void SQLITE_STDCALL sqlite3_result_error(sqlite3_context*, const char*, int);
  1.1340 -SQLITE_API void SQLITE_STDCALL sqlite3_result_error16(sqlite3_context*, const void*, int);
  1.1341 -SQLITE_API void SQLITE_STDCALL sqlite3_result_error_toobig(sqlite3_context*);
  1.1342 -SQLITE_API void SQLITE_STDCALL sqlite3_result_error_nomem(sqlite3_context*);
  1.1343 -SQLITE_API void SQLITE_STDCALL sqlite3_result_error_code(sqlite3_context*, int);
  1.1344 -SQLITE_API void SQLITE_STDCALL sqlite3_result_int(sqlite3_context*, int);
  1.1345 -SQLITE_API void SQLITE_STDCALL sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
  1.1346 -SQLITE_API void SQLITE_STDCALL sqlite3_result_null(sqlite3_context*);
  1.1347 -SQLITE_API void SQLITE_STDCALL sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
  1.1348 -SQLITE_API void SQLITE_STDCALL sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,
  1.1349 +SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
  1.1350 +SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
  1.1351 +SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
  1.1352 +SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
  1.1353 +SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
  1.1354 +SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);
  1.1355 +SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
  1.1356 +SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
  1.1357 +SQLITE_API void sqlite3_result_null(sqlite3_context*);
  1.1358 +SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
  1.1359 +SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,
  1.1360                             void(*)(void*), unsigned char encoding);
  1.1361 -SQLITE_API void SQLITE_STDCALL sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
  1.1362 -SQLITE_API void SQLITE_STDCALL sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
  1.1363 -SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
  1.1364 -SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
  1.1365 -SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
  1.1366 -SQLITE_API int SQLITE_STDCALL sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
  1.1367 +SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
  1.1368 +SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
  1.1369 +SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
  1.1370 +SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
  1.1371 +SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
  1.1372 +SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
  1.1373  
  1.1374  
  1.1375  /*
  1.1376 @@ -5008,7 +5254,7 @@
  1.1377  ** The number of subtype bytes preserved by SQLite might increase
  1.1378  ** in future releases of SQLite.
  1.1379  */
  1.1380 -SQLITE_API void SQLITE_STDCALL sqlite3_result_subtype(sqlite3_context*,unsigned int);
  1.1381 +SQLITE_API void sqlite3_result_subtype(sqlite3_context*,unsigned int);
  1.1382  
  1.1383  /*
  1.1384  ** CAPI3REF: Define New Collating Sequences
  1.1385 @@ -5090,14 +5336,14 @@
  1.1386  **
  1.1387  ** See also:  [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
  1.1388  */
  1.1389 -SQLITE_API int SQLITE_STDCALL sqlite3_create_collation(
  1.1390 +SQLITE_API int sqlite3_create_collation(
  1.1391    sqlite3*, 
  1.1392    const char *zName, 
  1.1393    int eTextRep, 
  1.1394    void *pArg,
  1.1395    int(*xCompare)(void*,int,const void*,int,const void*)
  1.1396  );
  1.1397 -SQLITE_API int SQLITE_STDCALL sqlite3_create_collation_v2(
  1.1398 +SQLITE_API int sqlite3_create_collation_v2(
  1.1399    sqlite3*, 
  1.1400    const char *zName, 
  1.1401    int eTextRep, 
  1.1402 @@ -5105,7 +5351,7 @@
  1.1403    int(*xCompare)(void*,int,const void*,int,const void*),
  1.1404    void(*xDestroy)(void*)
  1.1405  );
  1.1406 -SQLITE_API int SQLITE_STDCALL sqlite3_create_collation16(
  1.1407 +SQLITE_API int sqlite3_create_collation16(
  1.1408    sqlite3*, 
  1.1409    const void *zName,
  1.1410    int eTextRep, 
  1.1411 @@ -5140,12 +5386,12 @@
  1.1412  ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
  1.1413  ** [sqlite3_create_collation_v2()].
  1.1414  */
  1.1415 -SQLITE_API int SQLITE_STDCALL sqlite3_collation_needed(
  1.1416 +SQLITE_API int sqlite3_collation_needed(
  1.1417    sqlite3*, 
  1.1418    void*, 
  1.1419    void(*)(void*,sqlite3*,int eTextRep,const char*)
  1.1420  );
  1.1421 -SQLITE_API int SQLITE_STDCALL sqlite3_collation_needed16(
  1.1422 +SQLITE_API int sqlite3_collation_needed16(
  1.1423    sqlite3*, 
  1.1424    void*,
  1.1425    void(*)(void*,sqlite3*,int eTextRep,const void*)
  1.1426 @@ -5159,11 +5405,11 @@
  1.1427  ** The code to implement this API is not available in the public release
  1.1428  ** of SQLite.
  1.1429  */
  1.1430 -SQLITE_API int SQLITE_STDCALL sqlite3_key(
  1.1431 +SQLITE_API int sqlite3_key(
  1.1432    sqlite3 *db,                   /* Database to be rekeyed */
  1.1433    const void *pKey, int nKey     /* The key */
  1.1434  );
  1.1435 -SQLITE_API int SQLITE_STDCALL sqlite3_key_v2(
  1.1436 +SQLITE_API int sqlite3_key_v2(
  1.1437    sqlite3 *db,                   /* Database to be rekeyed */
  1.1438    const char *zDbName,           /* Name of the database */
  1.1439    const void *pKey, int nKey     /* The key */
  1.1440 @@ -5177,11 +5423,11 @@
  1.1441  ** The code to implement this API is not available in the public release
  1.1442  ** of SQLite.
  1.1443  */
  1.1444 -SQLITE_API int SQLITE_STDCALL sqlite3_rekey(
  1.1445 +SQLITE_API int sqlite3_rekey(
  1.1446    sqlite3 *db,                   /* Database to be rekeyed */
  1.1447    const void *pKey, int nKey     /* The new key */
  1.1448  );
  1.1449 -SQLITE_API int SQLITE_STDCALL sqlite3_rekey_v2(
  1.1450 +SQLITE_API int sqlite3_rekey_v2(
  1.1451    sqlite3 *db,                   /* Database to be rekeyed */
  1.1452    const char *zDbName,           /* Name of the database */
  1.1453    const void *pKey, int nKey     /* The new key */
  1.1454 @@ -5191,7 +5437,7 @@
  1.1455  ** Specify the activation key for a SEE database.  Unless 
  1.1456  ** activated, none of the SEE routines will work.
  1.1457  */
  1.1458 -SQLITE_API void SQLITE_STDCALL sqlite3_activate_see(
  1.1459 +SQLITE_API void sqlite3_activate_see(
  1.1460    const char *zPassPhrase        /* Activation phrase */
  1.1461  );
  1.1462  #endif
  1.1463 @@ -5201,7 +5447,7 @@
  1.1464  ** Specify the activation key for a CEROD database.  Unless 
  1.1465  ** activated, none of the CEROD routines will work.
  1.1466  */
  1.1467 -SQLITE_API void SQLITE_STDCALL sqlite3_activate_cerod(
  1.1468 +SQLITE_API void sqlite3_activate_cerod(
  1.1469    const char *zPassPhrase        /* Activation phrase */
  1.1470  );
  1.1471  #endif
  1.1472 @@ -5223,7 +5469,7 @@
  1.1473  ** all, then the behavior of sqlite3_sleep() may deviate from the description
  1.1474  ** in the previous paragraphs.
  1.1475  */
  1.1476 -SQLITE_API int SQLITE_STDCALL sqlite3_sleep(int);
  1.1477 +SQLITE_API int sqlite3_sleep(int);
  1.1478  
  1.1479  /*
  1.1480  ** CAPI3REF: Name Of The Folder Holding Temporary Files
  1.1481 @@ -5342,7 +5588,7 @@
  1.1482  ** connection while this routine is running, then the return value
  1.1483  ** is undefined.
  1.1484  */
  1.1485 -SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
  1.1486 +SQLITE_API int sqlite3_get_autocommit(sqlite3*);
  1.1487  
  1.1488  /*
  1.1489  ** CAPI3REF: Find The Database Handle Of A Prepared Statement
  1.1490 @@ -5355,7 +5601,7 @@
  1.1491  ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
  1.1492  ** create the statement in the first place.
  1.1493  */
  1.1494 -SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
  1.1495 +SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
  1.1496  
  1.1497  /*
  1.1498  ** CAPI3REF: Return The Filename For A Database Connection
  1.1499 @@ -5372,7 +5618,7 @@
  1.1500  ** will be an absolute pathname, even if the filename used
  1.1501  ** to open the database originally was a URI or relative pathname.
  1.1502  */
  1.1503 -SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
  1.1504 +SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
  1.1505  
  1.1506  /*
  1.1507  ** CAPI3REF: Determine if a database is read-only
  1.1508 @@ -5382,7 +5628,7 @@
  1.1509  ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
  1.1510  ** the name of a database on connection D.
  1.1511  */
  1.1512 -SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
  1.1513 +SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
  1.1514  
  1.1515  /*
  1.1516  ** CAPI3REF: Find the next prepared statement
  1.1517 @@ -5398,7 +5644,7 @@
  1.1518  ** [sqlite3_next_stmt(D,S)] must refer to an open database
  1.1519  ** connection and in particular must not be a NULL pointer.
  1.1520  */
  1.1521 -SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
  1.1522 +SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
  1.1523  
  1.1524  /*
  1.1525  ** CAPI3REF: Commit And Rollback Notification Callbacks
  1.1526 @@ -5447,8 +5693,8 @@
  1.1527  **
  1.1528  ** See also the [sqlite3_update_hook()] interface.
  1.1529  */
  1.1530 -SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
  1.1531 -SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
  1.1532 +SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
  1.1533 +SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
  1.1534  
  1.1535  /*
  1.1536  ** CAPI3REF: Data Change Notification Callbacks
  1.1537 @@ -5478,7 +5724,7 @@
  1.1538  ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
  1.1539  **
  1.1540  ** ^In the current implementation, the update hook
  1.1541 -** is not invoked when duplication rows are deleted because of an
  1.1542 +** is not invoked when conflicting rows are deleted because of an
  1.1543  ** [ON CONFLICT | ON CONFLICT REPLACE] clause.  ^Nor is the update hook
  1.1544  ** invoked when rows are deleted using the [truncate optimization].
  1.1545  ** The exceptions defined in this paragraph might change in a future
  1.1546 @@ -5499,7 +5745,7 @@
  1.1547  ** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()],
  1.1548  ** and [sqlite3_preupdate_hook()] interfaces.
  1.1549  */
  1.1550 -SQLITE_API void *SQLITE_STDCALL sqlite3_update_hook(
  1.1551 +SQLITE_API void *sqlite3_update_hook(
  1.1552    sqlite3*, 
  1.1553    void(*)(void *,int ,char const *,char const *,sqlite3_int64),
  1.1554    void*
  1.1555 @@ -5514,7 +5760,8 @@
  1.1556  ** and disabled if the argument is false.)^
  1.1557  **
  1.1558  ** ^Cache sharing is enabled and disabled for an entire process.
  1.1559 -** This is a change as of SQLite version 3.5.0. In prior versions of SQLite,
  1.1560 +** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]). 
  1.1561 +** In prior versions of SQLite,
  1.1562  ** sharing was enabled or disabled for each thread separately.
  1.1563  **
  1.1564  ** ^(The cache sharing mode set by this interface effects all subsequent
  1.1565 @@ -5539,7 +5786,7 @@
  1.1566  **
  1.1567  ** See Also:  [SQLite Shared-Cache Mode]
  1.1568  */
  1.1569 -SQLITE_API int SQLITE_STDCALL sqlite3_enable_shared_cache(int);
  1.1570 +SQLITE_API int sqlite3_enable_shared_cache(int);
  1.1571  
  1.1572  /*
  1.1573  ** CAPI3REF: Attempt To Free Heap Memory
  1.1574 @@ -5555,7 +5802,7 @@
  1.1575  **
  1.1576  ** See also: [sqlite3_db_release_memory()]
  1.1577  */
  1.1578 -SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
  1.1579 +SQLITE_API int sqlite3_release_memory(int);
  1.1580  
  1.1581  /*
  1.1582  ** CAPI3REF: Free Memory Used By A Database Connection
  1.1583 @@ -5569,7 +5816,7 @@
  1.1584  **
  1.1585  ** See also: [sqlite3_release_memory()]
  1.1586  */
  1.1587 -SQLITE_API int SQLITE_STDCALL sqlite3_db_release_memory(sqlite3*);
  1.1588 +SQLITE_API int sqlite3_db_release_memory(sqlite3*);
  1.1589  
  1.1590  /*
  1.1591  ** CAPI3REF: Impose A Limit On Heap Size
  1.1592 @@ -5608,7 +5855,8 @@
  1.1593  **      from the heap.
  1.1594  ** </ul>)^
  1.1595  **
  1.1596 -** Beginning with SQLite version 3.7.3, the soft heap limit is enforced
  1.1597 +** Beginning with SQLite [version 3.7.3] ([dateof:3.7.3]), 
  1.1598 +** the soft heap limit is enforced
  1.1599  ** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
  1.1600  ** compile-time option is invoked.  With [SQLITE_ENABLE_MEMORY_MANAGEMENT],
  1.1601  ** the soft heap limit is enforced on every memory allocation.  Without
  1.1602 @@ -5621,7 +5869,7 @@
  1.1603  ** The circumstances under which SQLite will enforce the soft heap limit may
  1.1604  ** changes in future releases of SQLite.
  1.1605  */
  1.1606 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_soft_heap_limit64(sqlite3_int64 N);
  1.1607 +SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
  1.1608  
  1.1609  /*
  1.1610  ** CAPI3REF: Deprecated Soft Heap Limit Interface
  1.1611 @@ -5632,7 +5880,7 @@
  1.1612  ** only.  All new applications should use the
  1.1613  ** [sqlite3_soft_heap_limit64()] interface rather than this one.
  1.1614  */
  1.1615 -SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
  1.1616 +SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N);
  1.1617  
  1.1618  
  1.1619  /*
  1.1620 @@ -5647,7 +5895,7 @@
  1.1621  ** column exists.  ^The sqlite3_table_column_metadata() interface returns
  1.1622  ** SQLITE_ERROR and if the specified column does not exist.
  1.1623  ** ^If the column-name parameter to sqlite3_table_column_metadata() is a
  1.1624 -** NULL pointer, then this routine simply checks for the existance of the
  1.1625 +** NULL pointer, then this routine simply checks for the existence of the
  1.1626  ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
  1.1627  ** does not.
  1.1628  **
  1.1629 @@ -5702,7 +5950,7 @@
  1.1630  ** parsed, if that has not already been done, and returns an error if
  1.1631  ** any errors are encountered while loading the schema.
  1.1632  */
  1.1633 -SQLITE_API int SQLITE_STDCALL sqlite3_table_column_metadata(
  1.1634 +SQLITE_API int sqlite3_table_column_metadata(
  1.1635    sqlite3 *db,                /* Connection handle */
  1.1636    const char *zDbName,        /* Database name or NULL */
  1.1637    const char *zTableName,     /* Table name */
  1.1638 @@ -5758,7 +6006,7 @@
  1.1639  **
  1.1640  ** See also the [load_extension() SQL function].
  1.1641  */
  1.1642 -SQLITE_API int SQLITE_STDCALL sqlite3_load_extension(
  1.1643 +SQLITE_API int sqlite3_load_extension(
  1.1644    sqlite3 *db,          /* Load the extension into this database connection */
  1.1645    const char *zFile,    /* Name of the shared library containing extension */
  1.1646    const char *zProc,    /* Entry point.  Derived from zFile if 0 */
  1.1647 @@ -5781,8 +6029,8 @@
  1.1648  **
  1.1649  ** ^This interface enables or disables both the C-API
  1.1650  ** [sqlite3_load_extension()] and the SQL function [load_extension()].
  1.1651 -** Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
  1.1652 -** to enable or disable only the C-API.
  1.1653 +** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
  1.1654 +** to enable or disable only the C-API.)^
  1.1655  **
  1.1656  ** <b>Security warning:</b> It is recommended that extension loading
  1.1657  ** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
  1.1658 @@ -5790,7 +6038,7 @@
  1.1659  ** remains disabled. This will prevent SQL injections from giving attackers
  1.1660  ** access to extension loading capabilities.
  1.1661  */
  1.1662 -SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
  1.1663 +SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
  1.1664  
  1.1665  /*
  1.1666  ** CAPI3REF: Automatically Load Statically Linked Extensions
  1.1667 @@ -5802,7 +6050,7 @@
  1.1668  **
  1.1669  ** ^(Even though the function prototype shows that xEntryPoint() takes
  1.1670  ** no arguments and returns void, SQLite invokes xEntryPoint() with three
  1.1671 -** arguments and expects and integer result as if the signature of the
  1.1672 +** arguments and expects an integer result as if the signature of the
  1.1673  ** entry point where as follows:
  1.1674  **
  1.1675  ** <blockquote><pre>
  1.1676 @@ -5828,7 +6076,7 @@
  1.1677  ** See also: [sqlite3_reset_auto_extension()]
  1.1678  ** and [sqlite3_cancel_auto_extension()]
  1.1679  */
  1.1680 -SQLITE_API int SQLITE_STDCALL sqlite3_auto_extension(void (*xEntryPoint)(void));
  1.1681 +SQLITE_API int sqlite3_auto_extension(void(*xEntryPoint)(void));
  1.1682  
  1.1683  /*
  1.1684  ** CAPI3REF: Cancel Automatic Extension Loading
  1.1685 @@ -5840,7 +6088,7 @@
  1.1686  ** unregistered and it returns 0 if X was not on the list of initialization
  1.1687  ** routines.
  1.1688  */
  1.1689 -SQLITE_API int SQLITE_STDCALL sqlite3_cancel_auto_extension(void (*xEntryPoint)(void));
  1.1690 +SQLITE_API int sqlite3_cancel_auto_extension(void(*xEntryPoint)(void));
  1.1691  
  1.1692  /*
  1.1693  ** CAPI3REF: Reset Automatic Extension Loading
  1.1694 @@ -5848,7 +6096,7 @@
  1.1695  ** ^This interface disables all automatic extensions previously
  1.1696  ** registered using [sqlite3_auto_extension()].
  1.1697  */
  1.1698 -SQLITE_API void SQLITE_STDCALL sqlite3_reset_auto_extension(void);
  1.1699 +SQLITE_API void sqlite3_reset_auto_extension(void);
  1.1700  
  1.1701  /*
  1.1702  ** The interface to the virtual-table mechanism is currently considered
  1.1703 @@ -6002,13 +6250,15 @@
  1.1704  ** the xUpdate method are automatically rolled back by SQLite.
  1.1705  **
  1.1706  ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
  1.1707 -** structure for SQLite version 3.8.2. If a virtual table extension is
  1.1708 +** structure for SQLite [version 3.8.2] ([dateof:3.8.2]). 
  1.1709 +** If a virtual table extension is
  1.1710  ** used with an SQLite version earlier than 3.8.2, the results of attempting 
  1.1711  ** to read or write the estimatedRows field are undefined (but are likely 
  1.1712  ** to included crashing the application). The estimatedRows field should
  1.1713  ** therefore only be used if [sqlite3_libversion_number()] returns a
  1.1714  ** value greater than or equal to 3008002. Similarly, the idxFlags field
  1.1715 -** was added for version 3.9.0. It may therefore only be used if
  1.1716 +** was added for [version 3.9.0] ([dateof:3.9.0]). 
  1.1717 +** It may therefore only be used if
  1.1718  ** sqlite3_libversion_number() returns a value greater than or equal to
  1.1719  ** 3009000.
  1.1720  */
  1.1721 @@ -6093,13 +6343,13 @@
  1.1722  ** interface is equivalent to sqlite3_create_module_v2() with a NULL
  1.1723  ** destructor.
  1.1724  */
  1.1725 -SQLITE_API int SQLITE_STDCALL sqlite3_create_module(
  1.1726 +SQLITE_API int sqlite3_create_module(
  1.1727    sqlite3 *db,               /* SQLite connection to register module with */
  1.1728    const char *zName,         /* Name of the module */
  1.1729    const sqlite3_module *p,   /* Methods for the module */
  1.1730    void *pClientData          /* Client data for xCreate/xConnect */
  1.1731  );
  1.1732 -SQLITE_API int SQLITE_STDCALL sqlite3_create_module_v2(
  1.1733 +SQLITE_API int sqlite3_create_module_v2(
  1.1734    sqlite3 *db,               /* SQLite connection to register module with */
  1.1735    const char *zName,         /* Name of the module */
  1.1736    const sqlite3_module *p,   /* Methods for the module */
  1.1737 @@ -6162,7 +6412,7 @@
  1.1738  ** to declare the format (the names and datatypes of the columns) of
  1.1739  ** the virtual tables they implement.
  1.1740  */
  1.1741 -SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
  1.1742 +SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
  1.1743  
  1.1744  /*
  1.1745  ** CAPI3REF: Overload A Function For A Virtual Table
  1.1746 @@ -6181,7 +6431,7 @@
  1.1747  ** purpose is to be a placeholder function that can be overloaded
  1.1748  ** by a [virtual table].
  1.1749  */
  1.1750 -SQLITE_API int SQLITE_STDCALL sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
  1.1751 +SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
  1.1752  
  1.1753  /*
  1.1754  ** The interface to the virtual-table mechanism defined above (back up
  1.1755 @@ -6256,6 +6506,12 @@
  1.1756  ** [database connection] error code and message accessible via 
  1.1757  ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. 
  1.1758  **
  1.1759 +** A BLOB referenced by sqlite3_blob_open() may be read using the
  1.1760 +** [sqlite3_blob_read()] interface and modified by using
  1.1761 +** [sqlite3_blob_write()].  The [BLOB handle] can be moved to a
  1.1762 +** different row of the same table using the [sqlite3_blob_reopen()]
  1.1763 +** interface.  However, the column, table, or database of a [BLOB handle]
  1.1764 +** cannot be changed after the [BLOB handle] is opened.
  1.1765  **
  1.1766  ** ^(If the row that a BLOB handle points to is modified by an
  1.1767  ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
  1.1768 @@ -6279,8 +6535,12 @@
  1.1769  **
  1.1770  ** To avoid a resource leak, every open [BLOB handle] should eventually
  1.1771  ** be released by a call to [sqlite3_blob_close()].
  1.1772 -*/
  1.1773 -SQLITE_API int SQLITE_STDCALL sqlite3_blob_open(
  1.1774 +**
  1.1775 +** See also: [sqlite3_blob_close()],
  1.1776 +** [sqlite3_blob_reopen()], [sqlite3_blob_read()],
  1.1777 +** [sqlite3_blob_bytes()], [sqlite3_blob_write()].
  1.1778 +*/
  1.1779 +SQLITE_API int sqlite3_blob_open(
  1.1780    sqlite3*,
  1.1781    const char *zDb,
  1.1782    const char *zTable,
  1.1783 @@ -6294,11 +6554,11 @@
  1.1784  ** CAPI3REF: Move a BLOB Handle to a New Row
  1.1785  ** METHOD: sqlite3_blob
  1.1786  **
  1.1787 -** ^This function is used to move an existing blob handle so that it points
  1.1788 +** ^This function is used to move an existing [BLOB handle] so that it points
  1.1789  ** to a different row of the same database table. ^The new row is identified
  1.1790  ** by the rowid value passed as the second argument. Only the row can be
  1.1791  ** changed. ^The database, table and column on which the blob handle is open
  1.1792 -** remain the same. Moving an existing blob handle to a new row can be
  1.1793 +** remain the same. Moving an existing [BLOB handle] to a new row is
  1.1794  ** faster than closing the existing handle and opening a new one.
  1.1795  **
  1.1796  ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -
  1.1797 @@ -6313,7 +6573,7 @@
  1.1798  **
  1.1799  ** ^This function sets the database handle error code and message.
  1.1800  */
  1.1801 -SQLITE_API int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
  1.1802 +SQLITE_API int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
  1.1803  
  1.1804  /*
  1.1805  ** CAPI3REF: Close A BLOB Handle
  1.1806 @@ -6336,7 +6596,7 @@
  1.1807  ** is passed a valid open blob handle, the values returned by the 
  1.1808  ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
  1.1809  */
  1.1810 -SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
  1.1811 +SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
  1.1812  
  1.1813  /*
  1.1814  ** CAPI3REF: Return The Size Of An Open BLOB
  1.1815 @@ -6352,7 +6612,7 @@
  1.1816  ** been closed by [sqlite3_blob_close()].  Passing any other pointer in
  1.1817  ** to this routine results in undefined and probably undesirable behavior.
  1.1818  */
  1.1819 -SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
  1.1820 +SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *);
  1.1821  
  1.1822  /*
  1.1823  ** CAPI3REF: Read Data From A BLOB Incrementally
  1.1824 @@ -6381,7 +6641,7 @@
  1.1825  **
  1.1826  ** See also: [sqlite3_blob_write()].
  1.1827  */
  1.1828 -SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
  1.1829 +SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
  1.1830  
  1.1831  /*
  1.1832  ** CAPI3REF: Write Data Into A BLOB Incrementally
  1.1833 @@ -6423,7 +6683,7 @@
  1.1834  **
  1.1835  ** See also: [sqlite3_blob_read()].
  1.1836  */
  1.1837 -SQLITE_API int SQLITE_STDCALL sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
  1.1838 +SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
  1.1839  
  1.1840  /*
  1.1841  ** CAPI3REF: Virtual File System Objects
  1.1842 @@ -6454,9 +6714,9 @@
  1.1843  ** ^(If the default VFS is unregistered, another VFS is chosen as
  1.1844  ** the default.  The choice for the new VFS is arbitrary.)^
  1.1845  */
  1.1846 -SQLITE_API sqlite3_vfs *SQLITE_STDCALL sqlite3_vfs_find(const char *zVfsName);
  1.1847 -SQLITE_API int SQLITE_STDCALL sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
  1.1848 -SQLITE_API int SQLITE_STDCALL sqlite3_vfs_unregister(sqlite3_vfs*);
  1.1849 +SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);
  1.1850 +SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
  1.1851 +SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*);
  1.1852  
  1.1853  /*
  1.1854  ** CAPI3REF: Mutexes
  1.1855 @@ -6572,11 +6832,11 @@
  1.1856  **
  1.1857  ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
  1.1858  */
  1.1859 -SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_mutex_alloc(int);
  1.1860 -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_free(sqlite3_mutex*);
  1.1861 -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_enter(sqlite3_mutex*);
  1.1862 -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_try(sqlite3_mutex*);
  1.1863 -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_leave(sqlite3_mutex*);
  1.1864 +SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int);
  1.1865 +SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*);
  1.1866 +SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*);
  1.1867 +SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
  1.1868 +SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
  1.1869  
  1.1870  /*
  1.1871  ** CAPI3REF: Mutex Methods Object
  1.1872 @@ -6686,8 +6946,8 @@
  1.1873  ** interface should also return 1 when given a NULL pointer.
  1.1874  */
  1.1875  #ifndef NDEBUG
  1.1876 -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_held(sqlite3_mutex*);
  1.1877 -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_notheld(sqlite3_mutex*);
  1.1878 +SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
  1.1879 +SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
  1.1880  #endif
  1.1881  
  1.1882  /*
  1.1883 @@ -6706,7 +6966,7 @@
  1.1884  #define SQLITE_MUTEX_STATIC_MEM       3  /* sqlite3_malloc() */
  1.1885  #define SQLITE_MUTEX_STATIC_MEM2      4  /* NOT USED */
  1.1886  #define SQLITE_MUTEX_STATIC_OPEN      4  /* sqlite3BtreeOpen() */
  1.1887 -#define SQLITE_MUTEX_STATIC_PRNG      5  /* sqlite3_random() */
  1.1888 +#define SQLITE_MUTEX_STATIC_PRNG      5  /* sqlite3_randomness() */
  1.1889  #define SQLITE_MUTEX_STATIC_LRU       6  /* lru page list */
  1.1890  #define SQLITE_MUTEX_STATIC_LRU2      7  /* NOT USED */
  1.1891  #define SQLITE_MUTEX_STATIC_PMEM      7  /* sqlite3PageMalloc() */
  1.1892 @@ -6727,7 +6987,7 @@
  1.1893  ** ^If the [threading mode] is Single-thread or Multi-thread then this
  1.1894  ** routine returns a NULL pointer.
  1.1895  */
  1.1896 -SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
  1.1897 +SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*);
  1.1898  
  1.1899  /*
  1.1900  ** CAPI3REF: Low-Level Control Of Database Files
  1.1901 @@ -6762,7 +7022,7 @@
  1.1902  **
  1.1903  ** See also: [SQLITE_FCNTL_LOCKSTATE]
  1.1904  */
  1.1905 -SQLITE_API int SQLITE_STDCALL sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
  1.1906 +SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
  1.1907  
  1.1908  /*
  1.1909  ** CAPI3REF: Testing Interface
  1.1910 @@ -6781,7 +7041,7 @@
  1.1911  ** Unlike most of the SQLite API, this function is not guaranteed to
  1.1912  ** operate consistently from one release to the next.
  1.1913  */
  1.1914 -SQLITE_API int SQLITE_CDECL sqlite3_test_control(int op, ...);
  1.1915 +SQLITE_API int sqlite3_test_control(int op, ...);
  1.1916  
  1.1917  /*
  1.1918  ** CAPI3REF: Testing Interface Operation Codes
  1.1919 @@ -6810,6 +7070,7 @@
  1.1920  #define SQLITE_TESTCTRL_SCRATCHMALLOC           17
  1.1921  #define SQLITE_TESTCTRL_LOCALTIME_FAULT         18
  1.1922  #define SQLITE_TESTCTRL_EXPLAIN_STMT            19  /* NOT USED */
  1.1923 +#define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD    19
  1.1924  #define SQLITE_TESTCTRL_NEVER_CORRUPT           20
  1.1925  #define SQLITE_TESTCTRL_VDBE_COVERAGE           21
  1.1926  #define SQLITE_TESTCTRL_BYTEORDER               22
  1.1927 @@ -6844,8 +7105,8 @@
  1.1928  **
  1.1929  ** See also: [sqlite3_db_status()]
  1.1930  */
  1.1931 -SQLITE_API int SQLITE_STDCALL sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
  1.1932 -SQLITE_API int SQLITE_STDCALL sqlite3_status64(
  1.1933 +SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
  1.1934 +SQLITE_API int sqlite3_status64(
  1.1935    int op,
  1.1936    sqlite3_int64 *pCurrent,
  1.1937    sqlite3_int64 *pHighwater,
  1.1938 @@ -6970,7 +7231,7 @@
  1.1939  **
  1.1940  ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
  1.1941  */
  1.1942 -SQLITE_API int SQLITE_STDCALL sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
  1.1943 +SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
  1.1944  
  1.1945  /*
  1.1946  ** CAPI3REF: Status Parameters for database connections
  1.1947 @@ -7016,6 +7277,18 @@
  1.1948  ** memory used by all pager caches associated with the database connection.)^
  1.1949  ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
  1.1950  **
  1.1951 +** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]] 
  1.1952 +** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt>
  1.1953 +** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a
  1.1954 +** pager cache is shared between two or more connections the bytes of heap
  1.1955 +** memory used by that pager cache is divided evenly between the attached
  1.1956 +** connections.)^  In other words, if none of the pager caches associated
  1.1957 +** with the database connection are shared, this request returns the same
  1.1958 +** value as DBSTATUS_CACHE_USED. Or, if one or more or the pager caches are
  1.1959 +** shared, the value returned by this call will be smaller than that returned
  1.1960 +** by DBSTATUS_CACHE_USED. ^The highwater mark associated with
  1.1961 +** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.
  1.1962 +**
  1.1963  ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
  1.1964  ** <dd>This parameter returns the approximate number of bytes of heap
  1.1965  ** memory used to store the schema for all databases associated
  1.1966 @@ -7073,7 +7346,8 @@
  1.1967  #define SQLITE_DBSTATUS_CACHE_MISS           8
  1.1968  #define SQLITE_DBSTATUS_CACHE_WRITE          9
  1.1969  #define SQLITE_DBSTATUS_DEFERRED_FKS        10
  1.1970 -#define SQLITE_DBSTATUS_MAX                 10   /* Largest defined DBSTATUS */
  1.1971 +#define SQLITE_DBSTATUS_CACHE_USED_SHARED   11
  1.1972 +#define SQLITE_DBSTATUS_MAX                 11   /* Largest defined DBSTATUS */
  1.1973  
  1.1974  
  1.1975  /*
  1.1976 @@ -7100,7 +7374,7 @@
  1.1977  **
  1.1978  ** See also: [sqlite3_status()] and [sqlite3_db_status()].
  1.1979  */
  1.1980 -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
  1.1981 +SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
  1.1982  
  1.1983  /*
  1.1984  ** CAPI3REF: Status Parameters for prepared statements
  1.1985 @@ -7569,16 +7843,16 @@
  1.1986  ** same time as another thread is invoking sqlite3_backup_step() it is
  1.1987  ** possible that they return invalid values.
  1.1988  */
  1.1989 -SQLITE_API sqlite3_backup *SQLITE_STDCALL sqlite3_backup_init(
  1.1990 +SQLITE_API sqlite3_backup *sqlite3_backup_init(
  1.1991    sqlite3 *pDest,                        /* Destination database handle */
  1.1992    const char *zDestName,                 /* Destination database name */
  1.1993    sqlite3 *pSource,                      /* Source database handle */
  1.1994    const char *zSourceName                /* Source database name */
  1.1995  );
  1.1996 -SQLITE_API int SQLITE_STDCALL sqlite3_backup_step(sqlite3_backup *p, int nPage);
  1.1997 -SQLITE_API int SQLITE_STDCALL sqlite3_backup_finish(sqlite3_backup *p);
  1.1998 -SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
  1.1999 -SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
  1.2000 +SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage);
  1.2001 +SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p);
  1.2002 +SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
  1.2003 +SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
  1.2004  
  1.2005  /*
  1.2006  ** CAPI3REF: Unlock Notification
  1.2007 @@ -7695,7 +7969,7 @@
  1.2008  ** the special "DROP TABLE/INDEX" case, the extended error code is just 
  1.2009  ** SQLITE_LOCKED.)^
  1.2010  */
  1.2011 -SQLITE_API int SQLITE_STDCALL sqlite3_unlock_notify(
  1.2012 +SQLITE_API int sqlite3_unlock_notify(
  1.2013    sqlite3 *pBlocked,                          /* Waiting connection */
  1.2014    void (*xNotify)(void **apArg, int nArg),    /* Callback function to invoke */
  1.2015    void *pNotifyArg                            /* Argument to pass to xNotify */
  1.2016 @@ -7710,8 +7984,8 @@
  1.2017  ** strings in a case-independent fashion, using the same definition of "case
  1.2018  ** independence" that SQLite uses internally when comparing identifiers.
  1.2019  */
  1.2020 -SQLITE_API int SQLITE_STDCALL sqlite3_stricmp(const char *, const char *);
  1.2021 -SQLITE_API int SQLITE_STDCALL sqlite3_strnicmp(const char *, const char *, int);
  1.2022 +SQLITE_API int sqlite3_stricmp(const char *, const char *);
  1.2023 +SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
  1.2024  
  1.2025  /*
  1.2026  ** CAPI3REF: String Globbing
  1.2027 @@ -7728,7 +8002,7 @@
  1.2028  **
  1.2029  ** See also: [sqlite3_strlike()].
  1.2030  */
  1.2031 -SQLITE_API int SQLITE_STDCALL sqlite3_strglob(const char *zGlob, const char *zStr);
  1.2032 +SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr);
  1.2033  
  1.2034  /*
  1.2035  ** CAPI3REF: String LIKE Matching
  1.2036 @@ -7751,7 +8025,7 @@
  1.2037  **
  1.2038  ** See also: [sqlite3_strglob()].
  1.2039  */
  1.2040 -SQLITE_API int SQLITE_STDCALL sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc);
  1.2041 +SQLITE_API int sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc);
  1.2042  
  1.2043  /*
  1.2044  ** CAPI3REF: Error Logging Interface
  1.2045 @@ -7774,7 +8048,7 @@
  1.2046  ** a few hundred characters, it will be truncated to the length of the
  1.2047  ** buffer.
  1.2048  */
  1.2049 -SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
  1.2050 +SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...);
  1.2051  
  1.2052  /*
  1.2053  ** CAPI3REF: Write-Ahead Log Commit Hook
  1.2054 @@ -7810,7 +8084,7 @@
  1.2055  ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
  1.2056  ** overwrite any prior [sqlite3_wal_hook()] settings.
  1.2057  */
  1.2058 -SQLITE_API void *SQLITE_STDCALL sqlite3_wal_hook(
  1.2059 +SQLITE_API void *sqlite3_wal_hook(
  1.2060    sqlite3*, 
  1.2061    int(*)(void *,sqlite3*,const char*,int),
  1.2062    void*
  1.2063 @@ -7845,7 +8119,7 @@
  1.2064  ** is only necessary if the default setting is found to be suboptimal
  1.2065  ** for a particular application.
  1.2066  */
  1.2067 -SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
  1.2068 +SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
  1.2069  
  1.2070  /*
  1.2071  ** CAPI3REF: Checkpoint a database
  1.2072 @@ -7867,7 +8141,7 @@
  1.2073  ** start a callback but which do not need the full power (and corresponding
  1.2074  ** complication) of [sqlite3_wal_checkpoint_v2()].
  1.2075  */
  1.2076 -SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
  1.2077 +SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
  1.2078  
  1.2079  /*
  1.2080  ** CAPI3REF: Checkpoint a database
  1.2081 @@ -7961,7 +8235,7 @@
  1.2082  ** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface
  1.2083  ** from SQL.
  1.2084  */
  1.2085 -SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint_v2(
  1.2086 +SQLITE_API int sqlite3_wal_checkpoint_v2(
  1.2087    sqlite3 *db,                    /* Database handle */
  1.2088    const char *zDb,                /* Name of attached database (or NULL) */
  1.2089    int eMode,                      /* SQLITE_CHECKPOINT_* value */
  1.2090 @@ -7997,7 +8271,7 @@
  1.2091  ** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].)  Further options
  1.2092  ** may be added in the future.
  1.2093  */
  1.2094 -SQLITE_API int SQLITE_CDECL sqlite3_vtab_config(sqlite3*, int op, ...);
  1.2095 +SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...);
  1.2096  
  1.2097  /*
  1.2098  ** CAPI3REF: Virtual Table Configuration Options
  1.2099 @@ -8050,7 +8324,7 @@
  1.2100  ** of the SQL statement that triggered the call to the [xUpdate] method of the
  1.2101  ** [virtual table].
  1.2102  */
  1.2103 -SQLITE_API int SQLITE_STDCALL sqlite3_vtab_on_conflict(sqlite3 *);
  1.2104 +SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
  1.2105  
  1.2106  /*
  1.2107  ** CAPI3REF: Conflict resolution modes
  1.2108 @@ -8155,7 +8429,7 @@
  1.2109  **
  1.2110  ** See also: [sqlite3_stmt_scanstatus_reset()]
  1.2111  */
  1.2112 -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_scanstatus(
  1.2113 +SQLITE_API int sqlite3_stmt_scanstatus(
  1.2114    sqlite3_stmt *pStmt,      /* Prepared statement for which info desired */
  1.2115    int idx,                  /* Index of loop to report on */
  1.2116    int iScanStatusOp,        /* Information desired.  SQLITE_SCANSTAT_* */
  1.2117 @@ -8171,7 +8445,7 @@
  1.2118  ** This API is only available if the library is built with pre-processor
  1.2119  ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
  1.2120  */
  1.2121 -SQLITE_API void SQLITE_STDCALL sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
  1.2122 +SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
  1.2123  
  1.2124  /*
  1.2125  ** CAPI3REF: Flush caches to disk mid-transaction
  1.2126 @@ -8203,7 +8477,7 @@
  1.2127  ** ^This function does not set the database handle error code or message
  1.2128  ** returned by the [sqlite3_errcode()] and [sqlite3_errmsg()] functions.
  1.2129  */
  1.2130 -SQLITE_API int SQLITE_STDCALL sqlite3_db_cacheflush(sqlite3*);
  1.2131 +SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
  1.2132  
  1.2133  /*
  1.2134  ** CAPI3REF: The pre-update hook.
  1.2135 @@ -8213,7 +8487,7 @@
  1.2136  **
  1.2137  ** ^The [sqlite3_preupdate_hook()] interface registers a callback function
  1.2138  ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation
  1.2139 -** on a [rowid table].
  1.2140 +** on a database table.
  1.2141  ** ^At most one preupdate hook may be registered at a time on a single
  1.2142  ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides
  1.2143  ** the previous setting.
  1.2144 @@ -8222,14 +8496,14 @@
  1.2145  ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
  1.2146  ** the first parameter to callbacks.
  1.2147  **
  1.2148 -** ^The preupdate hook only fires for changes to [rowid tables]; the preupdate
  1.2149 -** hook is not invoked for changes to [virtual tables] or [WITHOUT ROWID]
  1.2150 -** tables.
  1.2151 +** ^The preupdate hook only fires for changes to real database tables; the
  1.2152 +** preupdate hook is not invoked for changes to [virtual tables] or to
  1.2153 +** system tables like sqlite_master or sqlite_stat1.
  1.2154  **
  1.2155  ** ^The second parameter to the preupdate callback is a pointer to
  1.2156  ** the [database connection] that registered the preupdate hook.
  1.2157  ** ^The third parameter to the preupdate callback is one of the constants
  1.2158 -** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to indentify the
  1.2159 +** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
  1.2160  ** kind of update operation that is about to occur.
  1.2161  ** ^(The fourth parameter to the preupdate callback is the name of the
  1.2162  ** database within the database connection that is being modified.  This
  1.2163 @@ -8238,12 +8512,16 @@
  1.2164  ** databases.)^
  1.2165  ** ^The fifth parameter to the preupdate callback is the name of the
  1.2166  ** table that is being modified.
  1.2167 -** ^The sixth parameter to the preupdate callback is the initial [rowid] of the
  1.2168 -** row being changes for SQLITE_UPDATE and SQLITE_DELETE changes and is
  1.2169 -** undefined for SQLITE_INSERT changes.
  1.2170 -** ^The seventh parameter to the preupdate callback is the final [rowid] of
  1.2171 -** the row being changed for SQLITE_UPDATE and SQLITE_INSERT changes and is
  1.2172 -** undefined for SQLITE_DELETE changes.
  1.2173 +**
  1.2174 +** For an UPDATE or DELETE operation on a [rowid table], the sixth
  1.2175 +** parameter passed to the preupdate callback is the initial [rowid] of the 
  1.2176 +** row being modified or deleted. For an INSERT operation on a rowid table,
  1.2177 +** or any operation on a WITHOUT ROWID table, the value of the sixth 
  1.2178 +** parameter is undefined. For an INSERT or UPDATE on a rowid table the
  1.2179 +** seventh parameter is the final rowid value of the row being inserted
  1.2180 +** or updated. The value of the seventh parameter passed to the callback
  1.2181 +** function is not defined for operations on WITHOUT ROWID tables, or for
  1.2182 +** INSERT operations on rowid tables.
  1.2183  **
  1.2184  ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
  1.2185  ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
  1.2186 @@ -8283,7 +8561,8 @@
  1.2187  **
  1.2188  ** See also:  [sqlite3_update_hook()]
  1.2189  */
  1.2190 -SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_preupdate_hook(
  1.2191 +#if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
  1.2192 +SQLITE_API void *sqlite3_preupdate_hook(
  1.2193    sqlite3 *db,
  1.2194    void(*xPreUpdate)(
  1.2195      void *pCtx,                   /* Copy of third arg to preupdate_hook() */
  1.2196 @@ -8296,10 +8575,11 @@
  1.2197    ),
  1.2198    void*
  1.2199  );
  1.2200 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
  1.2201 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_count(sqlite3 *);
  1.2202 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_depth(sqlite3 *);
  1.2203 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
  1.2204 +SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
  1.2205 +SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
  1.2206 +SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
  1.2207 +SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
  1.2208 +#endif
  1.2209  
  1.2210  /*
  1.2211  ** CAPI3REF: Low-level system error code
  1.2212 @@ -8311,11 +8591,11 @@
  1.2213  ** called to get back the underlying "errno" that caused the problem, such
  1.2214  ** as ENOSPC, EAUTH, EISDIR, and so forth.  
  1.2215  */
  1.2216 -SQLITE_API int SQLITE_STDCALL sqlite3_system_errno(sqlite3*);
  1.2217 +SQLITE_API int sqlite3_system_errno(sqlite3*);
  1.2218  
  1.2219  /*
  1.2220  ** CAPI3REF: Database Snapshot
  1.2221 -** KEYWORDS: {snapshot}
  1.2222 +** KEYWORDS: {snapshot} {sqlite3_snapshot}
  1.2223  ** EXPERIMENTAL
  1.2224  **
  1.2225  ** An instance of the snapshot object records the state of a [WAL mode]
  1.2226 @@ -8339,7 +8619,9 @@
  1.2227  ** to an historical snapshot (if possible).  The destructor for 
  1.2228  ** sqlite3_snapshot objects is [sqlite3_snapshot_free()].
  1.2229  */
  1.2230 -typedef struct sqlite3_snapshot sqlite3_snapshot;
  1.2231 +typedef struct sqlite3_snapshot {
  1.2232 +  unsigned char hidden[48];
  1.2233 +} sqlite3_snapshot;
  1.2234  
  1.2235  /*
  1.2236  ** CAPI3REF: Record A Database Snapshot
  1.2237 @@ -8350,9 +8632,32 @@
  1.2238  ** schema S in database connection D.  ^On success, the
  1.2239  ** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly
  1.2240  ** created [sqlite3_snapshot] object into *P and returns SQLITE_OK.
  1.2241 -** ^If schema S of [database connection] D is not a [WAL mode] database
  1.2242 -** that is in a read transaction, then [sqlite3_snapshot_get(D,S,P)]
  1.2243 -** leaves the *P value unchanged and returns an appropriate [error code].
  1.2244 +** If there is not already a read-transaction open on schema S when
  1.2245 +** this function is called, one is opened automatically. 
  1.2246 +**
  1.2247 +** The following must be true for this function to succeed. If any of
  1.2248 +** the following statements are false when sqlite3_snapshot_get() is
  1.2249 +** called, SQLITE_ERROR is returned. The final value of *P is undefined
  1.2250 +** in this case. 
  1.2251 +**
  1.2252 +** <ul>
  1.2253 +**   <li> The database handle must be in [autocommit mode].
  1.2254 +**
  1.2255 +**   <li> Schema S of [database connection] D must be a [WAL mode] database.
  1.2256 +**
  1.2257 +**   <li> There must not be a write transaction open on schema S of database
  1.2258 +**        connection D.
  1.2259 +**
  1.2260 +**   <li> One or more transactions must have been written to the current wal
  1.2261 +**        file since it was created on disk (by any connection). This means
  1.2262 +**        that a snapshot cannot be taken on a wal mode database with no wal 
  1.2263 +**        file immediately after it is first opened. At least one transaction
  1.2264 +**        must be written to it first.
  1.2265 +** </ul>
  1.2266 +**
  1.2267 +** This function may also return SQLITE_NOMEM.  If it is called with the
  1.2268 +** database handle in autocommit mode but fails for some other reason, 
  1.2269 +** whether or not a read transaction is opened on schema S is undefined.
  1.2270  **
  1.2271  ** The [sqlite3_snapshot] object returned from a successful call to
  1.2272  ** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()]
  1.2273 @@ -8361,7 +8666,7 @@
  1.2274  ** The [sqlite3_snapshot_get()] interface is only available when the
  1.2275  ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
  1.2276  */
  1.2277 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_get(
  1.2278 +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get(
  1.2279    sqlite3 *db,
  1.2280    const char *zSchema,
  1.2281    sqlite3_snapshot **ppSnapshot
  1.2282 @@ -8399,7 +8704,7 @@
  1.2283  ** The [sqlite3_snapshot_open()] interface is only available when the
  1.2284  ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
  1.2285  */
  1.2286 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_open(
  1.2287 +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open(
  1.2288    sqlite3 *db,
  1.2289    const char *zSchema,
  1.2290    sqlite3_snapshot *pSnapshot
  1.2291 @@ -8416,7 +8721,7 @@
  1.2292  ** The [sqlite3_snapshot_free()] interface is only available when the
  1.2293  ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
  1.2294  */
  1.2295 -SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3_snapshot*);
  1.2296 +SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free(sqlite3_snapshot*);
  1.2297  
  1.2298  /*
  1.2299  ** CAPI3REF: Compare the ages of two snapshot handles.
  1.2300 @@ -8440,12 +8745,34 @@
  1.2301  ** snapshot than P2, zero if the two handles refer to the same database
  1.2302  ** snapshot, and a positive value if P1 is a newer snapshot than P2.
  1.2303  */
  1.2304 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_cmp(
  1.2305 +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(
  1.2306    sqlite3_snapshot *p1,
  1.2307    sqlite3_snapshot *p2
  1.2308  );
  1.2309  
  1.2310  /*
  1.2311 +** CAPI3REF: Recover snapshots from a wal file
  1.2312 +** EXPERIMENTAL
  1.2313 +**
  1.2314 +** If all connections disconnect from a database file but do not perform
  1.2315 +** a checkpoint, the existing wal file is opened along with the database
  1.2316 +** file the next time the database is opened. At this point it is only
  1.2317 +** possible to successfully call sqlite3_snapshot_open() to open the most
  1.2318 +** recent snapshot of the database (the one at the head of the wal file),
  1.2319 +** even though the wal file may contain other valid snapshots for which
  1.2320 +** clients have sqlite3_snapshot handles.
  1.2321 +**
  1.2322 +** This function attempts to scan the wal file associated with database zDb
  1.2323 +** of database handle db and make all valid snapshots available to
  1.2324 +** sqlite3_snapshot_open(). It is an error if there is already a read
  1.2325 +** transaction open on the database, or if the database is not a wal mode
  1.2326 +** database.
  1.2327 +**
  1.2328 +** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
  1.2329 +*/
  1.2330 +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
  1.2331 +
  1.2332 +/*
  1.2333  ** Undo the hack that converts floating point types to integer for
  1.2334  ** builds on processors without floating point support.
  1.2335  */
  1.2336 @@ -8456,7 +8783,7 @@
  1.2337  #if 0
  1.2338  }  /* End of the 'extern "C"' block */
  1.2339  #endif
  1.2340 -#endif /* _SQLITE3_H_ */
  1.2341 +#endif /* SQLITE3_H */
  1.2342  
  1.2343  /******** Begin file sqlite3rtree.h *********/
  1.2344  /*
  1.2345 @@ -8498,7 +8825,7 @@
  1.2346  **
  1.2347  **   SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
  1.2348  */
  1.2349 -SQLITE_API int SQLITE_STDCALL sqlite3_rtree_geometry_callback(
  1.2350 +SQLITE_API int sqlite3_rtree_geometry_callback(
  1.2351    sqlite3 *db,
  1.2352    const char *zGeom,
  1.2353    int (*xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*),
  1.2354 @@ -8524,7 +8851,7 @@
  1.2355  **
  1.2356  **   SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...)
  1.2357  */
  1.2358 -SQLITE_API int SQLITE_STDCALL sqlite3_rtree_query_callback(
  1.2359 +SQLITE_API int sqlite3_rtree_query_callback(
  1.2360    sqlite3 *db,
  1.2361    const char *zQueryFunc,
  1.2362    int (*xQueryFunc)(sqlite3_rtree_query_info*),
  1.2363 @@ -8630,7 +8957,7 @@
  1.2364  ** attached database. It is not an error if database zDb is not attached
  1.2365  ** to the database when the session object is created.
  1.2366  */
  1.2367 -int sqlite3session_create(
  1.2368 +SQLITE_API int sqlite3session_create(
  1.2369    sqlite3 *db,                    /* Database handle */
  1.2370    const char *zDb,                /* Name of db (e.g. "main") */
  1.2371    sqlite3_session **ppSession     /* OUT: New session object */
  1.2372 @@ -8648,7 +8975,7 @@
  1.2373  ** are attached is closed. Refer to the documentation for 
  1.2374  ** [sqlite3session_create()] for details.
  1.2375  */
  1.2376 -void sqlite3session_delete(sqlite3_session *pSession);
  1.2377 +SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
  1.2378  
  1.2379  
  1.2380  /*
  1.2381 @@ -8668,7 +8995,7 @@
  1.2382  ** The return value indicates the final state of the session object: 0 if 
  1.2383  ** the session is disabled, or 1 if it is enabled.
  1.2384  */
  1.2385 -int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
  1.2386 +SQLITE_API int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
  1.2387  
  1.2388  /*
  1.2389  ** CAPI3REF: Set Or Clear the Indirect Change Flag
  1.2390 @@ -8697,7 +9024,7 @@
  1.2391  ** The return value indicates the final state of the indirect flag: 0 if 
  1.2392  ** it is clear, or 1 if it is set.
  1.2393  */
  1.2394 -int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
  1.2395 +SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
  1.2396  
  1.2397  /*
  1.2398  ** CAPI3REF: Attach A Table To A Session Object
  1.2399 @@ -8727,7 +9054,7 @@
  1.2400  ** SQLITE_OK is returned if the call completes without error. Or, if an error 
  1.2401  ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
  1.2402  */
  1.2403 -int sqlite3session_attach(
  1.2404 +SQLITE_API int sqlite3session_attach(
  1.2405    sqlite3_session *pSession,      /* Session object */
  1.2406    const char *zTab                /* Table name */
  1.2407  );
  1.2408 @@ -8736,12 +9063,12 @@
  1.2409  ** CAPI3REF: Set a table filter on a Session Object.
  1.2410  **
  1.2411  ** The second argument (xFilter) is the "filter callback". For changes to rows 
  1.2412 -** in tables that are not attached to the Session oject, the filter is called
  1.2413 +** in tables that are not attached to the Session object, the filter is called
  1.2414  ** to determine whether changes to the table's rows should be tracked or not. 
  1.2415  ** If xFilter returns 0, changes is not tracked. Note that once a table is 
  1.2416  ** attached, xFilter will not be called again.
  1.2417  */
  1.2418 -void sqlite3session_table_filter(
  1.2419 +SQLITE_API void sqlite3session_table_filter(
  1.2420    sqlite3_session *pSession,      /* Session object */
  1.2421    int(*xFilter)(
  1.2422      void *pCtx,                   /* Copy of third arg to _filter_table() */
  1.2423 @@ -8854,7 +9181,7 @@
  1.2424  ** another field of the same row is updated while the session is enabled, the
  1.2425  ** resulting changeset will contain an UPDATE change that updates both fields.
  1.2426  */
  1.2427 -int sqlite3session_changeset(
  1.2428 +SQLITE_API int sqlite3session_changeset(
  1.2429    sqlite3_session *pSession,      /* Session object */
  1.2430    int *pnChangeset,               /* OUT: Size of buffer at *ppChangeset */
  1.2431    void **ppChangeset              /* OUT: Buffer containing changeset */
  1.2432 @@ -8898,7 +9225,8 @@
  1.2433  **     the from-table, a DELETE record is added to the session object.
  1.2434  **
  1.2435  **   <li> For each row (primary key) that exists in both tables, but features 
  1.2436 -**     different in each, an UPDATE record is added to the session.
  1.2437 +**     different non-PK values in each, an UPDATE record is added to the
  1.2438 +**     session.  
  1.2439  ** </ul>
  1.2440  **
  1.2441  ** To clarify, if this function is called and then a changeset constructed
  1.2442 @@ -8915,7 +9243,7 @@
  1.2443  ** message. It is the responsibility of the caller to free this buffer using
  1.2444  ** sqlite3_free().
  1.2445  */
  1.2446 -int sqlite3session_diff(
  1.2447 +SQLITE_API int sqlite3session_diff(
  1.2448    sqlite3_session *pSession,
  1.2449    const char *zFromDb,
  1.2450    const char *zTbl,
  1.2451 @@ -8951,7 +9279,7 @@
  1.2452  ** a single table are grouped together, tables appear in the order in which
  1.2453  ** they were attached to the session object).
  1.2454  */
  1.2455 -int sqlite3session_patchset(
  1.2456 +SQLITE_API int sqlite3session_patchset(
  1.2457    sqlite3_session *pSession,      /* Session object */
  1.2458    int *pnPatchset,                /* OUT: Size of buffer at *ppChangeset */
  1.2459    void **ppPatchset               /* OUT: Buffer containing changeset */
  1.2460 @@ -8972,7 +9300,7 @@
  1.2461  ** guaranteed that a call to sqlite3session_changeset() will return a 
  1.2462  ** changeset containing zero changes.
  1.2463  */
  1.2464 -int sqlite3session_isempty(sqlite3_session *pSession);
  1.2465 +SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession);
  1.2466  
  1.2467  /*
  1.2468  ** CAPI3REF: Create An Iterator To Traverse A Changeset 
  1.2469 @@ -9002,12 +9330,12 @@
  1.2470  ** [sqlite3changeset_invert()] functions, all changes within the changeset 
  1.2471  ** that apply to a single table are grouped together. This means that when 
  1.2472  ** an application iterates through a changeset using an iterator created by 
  1.2473 -** this function, all changes that relate to a single table are visted 
  1.2474 +** this function, all changes that relate to a single table are visited 
  1.2475  ** consecutively. There is no chance that the iterator will visit a change 
  1.2476  ** the applies to table X, then one for table Y, and then later on visit 
  1.2477  ** another change for table X.
  1.2478  */
  1.2479 -int sqlite3changeset_start(
  1.2480 +SQLITE_API int sqlite3changeset_start(
  1.2481    sqlite3_changeset_iter **pp,    /* OUT: New changeset iterator handle */
  1.2482    int nChangeset,                 /* Size of changeset blob in bytes */
  1.2483    void *pChangeset                /* Pointer to blob containing changeset */
  1.2484 @@ -9036,7 +9364,7 @@
  1.2485  ** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or 
  1.2486  ** SQLITE_NOMEM.
  1.2487  */
  1.2488 -int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
  1.2489 +SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
  1.2490  
  1.2491  /*
  1.2492  ** CAPI3REF: Obtain The Current Operation From A Changeset Iterator
  1.2493 @@ -9064,7 +9392,7 @@
  1.2494  ** SQLite error code is returned. The values of the output variables may not
  1.2495  ** be trusted in this case.
  1.2496  */
  1.2497 -int sqlite3changeset_op(
  1.2498 +SQLITE_API int sqlite3changeset_op(
  1.2499    sqlite3_changeset_iter *pIter,  /* Iterator object */
  1.2500    const char **pzTab,             /* OUT: Pointer to table name */
  1.2501    int *pnCol,                     /* OUT: Number of columns in table */
  1.2502 @@ -9089,7 +9417,7 @@
  1.2503  ** 0x01 if the corresponding column is part of the tables primary key, or
  1.2504  ** 0x00 if it is not.
  1.2505  **
  1.2506 -** If argumet pnCol is not NULL, then *pnCol is set to the number of columns
  1.2507 +** If argument pnCol is not NULL, then *pnCol is set to the number of columns
  1.2508  ** in the table.
  1.2509  **
  1.2510  ** If this function is called when the iterator does not point to a valid
  1.2511 @@ -9097,7 +9425,7 @@
  1.2512  ** SQLITE_OK is returned and the output variables populated as described
  1.2513  ** above.
  1.2514  */
  1.2515 -int sqlite3changeset_pk(
  1.2516 +SQLITE_API int sqlite3changeset_pk(
  1.2517    sqlite3_changeset_iter *pIter,  /* Iterator object */
  1.2518    unsigned char **pabPK,          /* OUT: Array of boolean - true for PK cols */
  1.2519    int *pnCol                      /* OUT: Number of entries in output array */
  1.2520 @@ -9127,7 +9455,7 @@
  1.2521  ** If some other error occurs (e.g. an OOM condition), an SQLite error code
  1.2522  ** is returned and *ppValue is set to NULL.
  1.2523  */
  1.2524 -int sqlite3changeset_old(
  1.2525 +SQLITE_API int sqlite3changeset_old(
  1.2526    sqlite3_changeset_iter *pIter,  /* Changeset iterator */
  1.2527    int iVal,                       /* Column number */
  1.2528    sqlite3_value **ppValue         /* OUT: Old value (or NULL pointer) */
  1.2529 @@ -9160,7 +9488,7 @@
  1.2530  ** If some other error occurs (e.g. an OOM condition), an SQLite error code
  1.2531  ** is returned and *ppValue is set to NULL.
  1.2532  */
  1.2533 -int sqlite3changeset_new(
  1.2534 +SQLITE_API int sqlite3changeset_new(
  1.2535    sqlite3_changeset_iter *pIter,  /* Changeset iterator */
  1.2536    int iVal,                       /* Column number */
  1.2537    sqlite3_value **ppValue         /* OUT: New value (or NULL pointer) */
  1.2538 @@ -9187,7 +9515,7 @@
  1.2539  ** If some other error occurs (e.g. an OOM condition), an SQLite error code
  1.2540  ** is returned and *ppValue is set to NULL.
  1.2541  */
  1.2542 -int sqlite3changeset_conflict(
  1.2543 +SQLITE_API int sqlite3changeset_conflict(
  1.2544    sqlite3_changeset_iter *pIter,  /* Changeset iterator */
  1.2545    int iVal,                       /* Column number */
  1.2546    sqlite3_value **ppValue         /* OUT: Value from conflicting row */
  1.2547 @@ -9203,7 +9531,7 @@
  1.2548  **
  1.2549  ** In all other cases this function returns SQLITE_MISUSE.
  1.2550  */
  1.2551 -int sqlite3changeset_fk_conflicts(
  1.2552 +SQLITE_API int sqlite3changeset_fk_conflicts(
  1.2553    sqlite3_changeset_iter *pIter,  /* Changeset iterator */
  1.2554    int *pnOut                      /* OUT: Number of FK violations */
  1.2555  );
  1.2556 @@ -9236,7 +9564,7 @@
  1.2557  **     // An error has occurred 
  1.2558  **   }
  1.2559  */
  1.2560 -int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
  1.2561 +SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
  1.2562  
  1.2563  /*
  1.2564  ** CAPI3REF: Invert A Changeset
  1.2565 @@ -9266,7 +9594,7 @@
  1.2566  ** WARNING/TODO: This function currently assumes that the input is a valid
  1.2567  ** changeset. If it is not, the results are undefined.
  1.2568  */
  1.2569 -int sqlite3changeset_invert(
  1.2570 +SQLITE_API int sqlite3changeset_invert(
  1.2571    int nIn, const void *pIn,       /* Input changeset */
  1.2572    int *pnOut, void **ppOut        /* OUT: Inverse of input */
  1.2573  );
  1.2574 @@ -9295,7 +9623,7 @@
  1.2575  **
  1.2576  ** Refer to the sqlite3_changegroup documentation below for details.
  1.2577  */
  1.2578 -int sqlite3changeset_concat(
  1.2579 +SQLITE_API int sqlite3changeset_concat(
  1.2580    int nA,                         /* Number of bytes in buffer pA */
  1.2581    void *pA,                       /* Pointer to buffer containing changeset A */
  1.2582    int nB,                         /* Number of bytes in buffer pB */
  1.2583 @@ -9306,12 +9634,12 @@
  1.2584  
  1.2585  
  1.2586  /*
  1.2587 -** Changegroup handle.
  1.2588 +** CAPI3REF: Changegroup Handle
  1.2589  */
  1.2590  typedef struct sqlite3_changegroup sqlite3_changegroup;
  1.2591  
  1.2592  /*
  1.2593 -** CAPI3REF: Combine two or more changesets into a single changeset.
  1.2594 +** CAPI3REF: Create A New Changegroup Object
  1.2595  **
  1.2596  ** An sqlite3_changegroup object is used to combine two or more changesets
  1.2597  ** (or patchsets) into a single changeset (or patchset). A single changegroup
  1.2598 @@ -9345,9 +9673,11 @@
  1.2599  ** sqlite3changegroup_output() functions, also available are the streaming
  1.2600  ** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
  1.2601  */
  1.2602 -int sqlite3changegroup_new(sqlite3_changegroup **pp);
  1.2603 -
  1.2604 -/*
  1.2605 +SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp);
  1.2606 +
  1.2607 +/*
  1.2608 +** CAPI3REF: Add A Changeset To A Changegroup
  1.2609 +**
  1.2610  ** Add all changes within the changeset (or patchset) in buffer pData (size
  1.2611  ** nData bytes) to the changegroup. 
  1.2612  **
  1.2613 @@ -9362,7 +9692,7 @@
  1.2614  ** apply to the same row as a change already present in the changegroup if
  1.2615  ** the two rows have the same primary key.
  1.2616  **
  1.2617 -** Changes to rows that that do not already appear in the changegroup are
  1.2618 +** Changes to rows that do not already appear in the changegroup are
  1.2619  ** simply copied into it. Or, if both the new changeset and the changegroup
  1.2620  ** contain changes that apply to a single row, the final contents of the
  1.2621  ** changegroup depends on the type of each change, as follows:
  1.2622 @@ -9420,9 +9750,11 @@
  1.2623  **
  1.2624  ** If no error occurs, SQLITE_OK is returned.
  1.2625  */
  1.2626 -int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
  1.2627 -
  1.2628 -/*
  1.2629 +SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
  1.2630 +
  1.2631 +/*
  1.2632 +** CAPI3REF: Obtain A Composite Changeset From A Changegroup
  1.2633 +**
  1.2634  ** Obtain a buffer containing a changeset (or patchset) representing the
  1.2635  ** current contents of the changegroup. If the inputs to the changegroup
  1.2636  ** were themselves changesets, the output is a changeset. Or, if the
  1.2637 @@ -9444,16 +9776,16 @@
  1.2638  ** responsibility of the caller to eventually free the buffer using a
  1.2639  ** call to sqlite3_free().
  1.2640  */
  1.2641 -int sqlite3changegroup_output(
  1.2642 +SQLITE_API int sqlite3changegroup_output(
  1.2643    sqlite3_changegroup*,
  1.2644    int *pnData,                    /* OUT: Size of output buffer in bytes */
  1.2645    void **ppData                   /* OUT: Pointer to output buffer */
  1.2646  );
  1.2647  
  1.2648  /*
  1.2649 -** Delete a changegroup object.
  1.2650 -*/
  1.2651 -void sqlite3changegroup_delete(sqlite3_changegroup*);
  1.2652 +** CAPI3REF: Delete A Changegroup Object
  1.2653 +*/
  1.2654 +SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*);
  1.2655  
  1.2656  /*
  1.2657  ** CAPI3REF: Apply A Changeset To A Database
  1.2658 @@ -9479,7 +9811,7 @@
  1.2659  ** <ul>
  1.2660  **   <li> The table has the same name as the name recorded in the 
  1.2661  **        changeset, and
  1.2662 -**   <li> The table has the same number of columns as recorded in the 
  1.2663 +**   <li> The table has at least as many columns as recorded in the 
  1.2664  **        changeset, and
  1.2665  **   <li> The table has primary key columns in the same position as 
  1.2666  **        recorded in the changeset.
  1.2667 @@ -9524,7 +9856,11 @@
  1.2668  **   If a row with matching primary key values is found, but one or more of
  1.2669  **   the non-primary key fields contains a value different from the original
  1.2670  **   row value stored in the changeset, the conflict-handler function is
  1.2671 -**   invoked with [SQLITE_CHANGESET_DATA] as the second argument.
  1.2672 +**   invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the
  1.2673 +**   database table has more columns than are recorded in the changeset,
  1.2674 +**   only the values of those non-primary key fields are compared against
  1.2675 +**   the current database contents - any trailing database table columns
  1.2676 +**   are ignored.
  1.2677  **
  1.2678  **   If no row with matching primary key values is found in the database,
  1.2679  **   the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
  1.2680 @@ -9539,7 +9875,9 @@
  1.2681  **
  1.2682  ** <dt>INSERT Changes<dd>
  1.2683  **   For each INSERT change, an attempt is made to insert the new row into
  1.2684 -**   the database.
  1.2685 +**   the database. If the changeset row contains fewer fields than the
  1.2686 +**   database table, the trailing fields are populated with their default
  1.2687 +**   values.
  1.2688  **
  1.2689  **   If the attempt to insert the row fails because the database already 
  1.2690  **   contains a row with the same primary key values, the conflict handler
  1.2691 @@ -9557,13 +9895,13 @@
  1.2692  **   For each UPDATE change, this function checks if the target database 
  1.2693  **   contains a row with the same primary key value (or values) as the 
  1.2694  **   original row values stored in the changeset. If it does, and the values 
  1.2695 -**   stored in all non-primary key columns also match the values stored in 
  1.2696 -**   the changeset the row is updated within the target database.
  1.2697 +**   stored in all modified non-primary key columns also match the values
  1.2698 +**   stored in the changeset the row is updated within the target database.
  1.2699  **
  1.2700  **   If a row with matching primary key values is found, but one or more of
  1.2701 -**   the non-primary key fields contains a value different from an original
  1.2702 -**   row value stored in the changeset, the conflict-handler function is
  1.2703 -**   invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
  1.2704 +**   the modified non-primary key fields contains a value different from an
  1.2705 +**   original row value stored in the changeset, the conflict-handler function
  1.2706 +**   is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
  1.2707  **   UPDATE changes only contain values for non-primary key fields that are
  1.2708  **   to be modified, only those fields need to match the original values to
  1.2709  **   avoid the SQLITE_CHANGESET_DATA conflict-handler callback.
  1.2710 @@ -9591,7 +9929,7 @@
  1.2711  ** rolled back, restoring the target database to its original state, and an 
  1.2712  ** SQLite error code returned.
  1.2713  */
  1.2714 -int sqlite3changeset_apply(
  1.2715 +SQLITE_API int sqlite3changeset_apply(
  1.2716    sqlite3 *db,                    /* Apply change to "main" db of this handle */
  1.2717    int nChangeset,                 /* Size of changeset in bytes */
  1.2718    void *pChangeset,               /* Changeset blob */
  1.2719 @@ -9792,7 +10130,7 @@
  1.2720  ** parameter set to a value less than or equal to zero. Other than this,
  1.2721  ** no guarantees are made as to the size of the chunks of data returned.
  1.2722  */
  1.2723 -int sqlite3changeset_apply_strm(
  1.2724 +SQLITE_API int sqlite3changeset_apply_strm(
  1.2725    sqlite3 *db,                    /* Apply change to "main" db of this handle */
  1.2726    int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
  1.2727    void *pIn,                                          /* First arg for xInput */
  1.2728 @@ -9807,7 +10145,7 @@
  1.2729    ),
  1.2730    void *pCtx                      /* First argument passed to xConflict */
  1.2731  );
  1.2732 -int sqlite3changeset_concat_strm(
  1.2733 +SQLITE_API int sqlite3changeset_concat_strm(
  1.2734    int (*xInputA)(void *pIn, void *pData, int *pnData),
  1.2735    void *pInA,
  1.2736    int (*xInputB)(void *pIn, void *pData, int *pnData),
  1.2737 @@ -9815,32 +10153,32 @@
  1.2738    int (*xOutput)(void *pOut, const void *pData, int nData),
  1.2739    void *pOut
  1.2740  );
  1.2741 -int sqlite3changeset_invert_strm(
  1.2742 +SQLITE_API int sqlite3changeset_invert_strm(
  1.2743    int (*xInput)(void *pIn, void *pData, int *pnData),
  1.2744    void *pIn,
  1.2745    int (*xOutput)(void *pOut, const void *pData, int nData),
  1.2746    void *pOut
  1.2747  );
  1.2748 -int sqlite3changeset_start_strm(
  1.2749 +SQLITE_API int sqlite3changeset_start_strm(
  1.2750    sqlite3_changeset_iter **pp,
  1.2751    int (*xInput)(void *pIn, void *pData, int *pnData),
  1.2752    void *pIn
  1.2753  );
  1.2754 -int sqlite3session_changeset_strm(
  1.2755 +SQLITE_API int sqlite3session_changeset_strm(
  1.2756    sqlite3_session *pSession,
  1.2757    int (*xOutput)(void *pOut, const void *pData, int nData),
  1.2758    void *pOut
  1.2759  );
  1.2760 -int sqlite3session_patchset_strm(
  1.2761 +SQLITE_API int sqlite3session_patchset_strm(
  1.2762    sqlite3_session *pSession,
  1.2763    int (*xOutput)(void *pOut, const void *pData, int nData),
  1.2764    void *pOut
  1.2765  );
  1.2766 -int sqlite3changegroup_add_strm(sqlite3_changegroup*, 
  1.2767 +SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup*, 
  1.2768      int (*xInput)(void *pIn, void *pData, int *pnData),
  1.2769      void *pIn
  1.2770  );
  1.2771 -int sqlite3changegroup_output_strm(sqlite3_changegroup*,
  1.2772 +SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*,
  1.2773      int (*xOutput)(void *pOut, const void *pData, int nData), 
  1.2774      void *pOut
  1.2775  );
  1.2776 @@ -10176,7 +10514,7 @@
  1.2777  ** behaviour. The structure methods are expected to function as follows:
  1.2778  **
  1.2779  ** xCreate:
  1.2780 -**   This function is used to allocate and inititalize a tokenizer instance.
  1.2781 +**   This function is used to allocate and initialize a tokenizer instance.
  1.2782  **   A tokenizer instance is required to actually tokenize text.
  1.2783  **
  1.2784  **   The first argument passed to this function is a copy of the (void*)
  1.2785 @@ -10436,7 +10774,6 @@
  1.2786  
  1.2787  #endif /* _FTS5_H */
  1.2788  
  1.2789 -
  1.2790  /******** End of fts5.h *********/
  1.2791  
  1.2792  /************** End of sqlite3.h *********************************************/
  1.2793 @@ -10541,7 +10878,7 @@
  1.2794  ** Not currently enforced.
  1.2795  */
  1.2796  #ifndef SQLITE_MAX_VDBE_OP
  1.2797 -# define SQLITE_MAX_VDBE_OP 25000
  1.2798 +# define SQLITE_MAX_VDBE_OP 250000000
  1.2799  #endif
  1.2800  
  1.2801  /*
  1.2802 @@ -10734,11 +11071,12 @@
  1.2803  ** the SQLITE_DISABLE_INTRINSIC define.
  1.2804  */
  1.2805  #if !defined(SQLITE_DISABLE_INTRINSIC)
  1.2806 -#  if defined(_MSC_VER) && _MSC_VER>=1300
  1.2807 +#  if defined(_MSC_VER) && _MSC_VER>=1400
  1.2808  #    if !defined(_WIN32_WCE)
  1.2809  #      include <intrin.h>
  1.2810  #      pragma intrinsic(_byteswap_ushort)
  1.2811  #      pragma intrinsic(_byteswap_ulong)
  1.2812 +#      pragma intrinsic(_byteswap_uint64)
  1.2813  #      pragma intrinsic(_ReadWriteBarrier)
  1.2814  #    else
  1.2815  #      include <cmnintrin.h>
  1.2816 @@ -11011,8 +11349,8 @@
  1.2817  ** This is the header file for the generic hash-table implementation
  1.2818  ** used in SQLite.
  1.2819  */
  1.2820 -#ifndef _SQLITE_HASH_H_
  1.2821 -#define _SQLITE_HASH_H_
  1.2822 +#ifndef SQLITE_HASH_H
  1.2823 +#define SQLITE_HASH_H
  1.2824  
  1.2825  /* Forward declarations of structures. */
  1.2826  typedef struct Hash Hash;
  1.2827 @@ -11092,7 +11430,7 @@
  1.2828  */
  1.2829  /* #define sqliteHashCount(H)  ((H)->count) // NOT USED */
  1.2830  
  1.2831 -#endif /* _SQLITE_HASH_H_ */
  1.2832 +#endif /* SQLITE_HASH_H */
  1.2833  
  1.2834  /************** End of hash.h ************************************************/
  1.2835  /************** Continuing where we left off in sqliteInt.h ******************/
  1.2836 @@ -11124,76 +11462,76 @@
  1.2837  #define TK_AS                              24
  1.2838  #define TK_WITHOUT                         25
  1.2839  #define TK_COMMA                           26
  1.2840 -#define TK_OR                              27
  1.2841 -#define TK_AND                             28
  1.2842 -#define TK_IS                              29
  1.2843 -#define TK_MATCH                           30
  1.2844 -#define TK_LIKE_KW                         31
  1.2845 -#define TK_BETWEEN                         32
  1.2846 -#define TK_IN                              33
  1.2847 -#define TK_ISNULL                          34
  1.2848 -#define TK_NOTNULL                         35
  1.2849 -#define TK_NE                              36
  1.2850 -#define TK_EQ                              37
  1.2851 -#define TK_GT                              38
  1.2852 -#define TK_LE                              39
  1.2853 -#define TK_LT                              40
  1.2854 -#define TK_GE                              41
  1.2855 -#define TK_ESCAPE                          42
  1.2856 -#define TK_BITAND                          43
  1.2857 -#define TK_BITOR                           44
  1.2858 -#define TK_LSHIFT                          45
  1.2859 -#define TK_RSHIFT                          46
  1.2860 -#define TK_PLUS                            47
  1.2861 -#define TK_MINUS                           48
  1.2862 -#define TK_STAR                            49
  1.2863 -#define TK_SLASH                           50
  1.2864 -#define TK_REM                             51
  1.2865 -#define TK_CONCAT                          52
  1.2866 -#define TK_COLLATE                         53
  1.2867 -#define TK_BITNOT                          54
  1.2868 -#define TK_ID                              55
  1.2869 -#define TK_INDEXED                         56
  1.2870 -#define TK_ABORT                           57
  1.2871 -#define TK_ACTION                          58
  1.2872 -#define TK_AFTER                           59
  1.2873 -#define TK_ANALYZE                         60
  1.2874 -#define TK_ASC                             61
  1.2875 -#define TK_ATTACH                          62
  1.2876 -#define TK_BEFORE                          63
  1.2877 -#define TK_BY                              64
  1.2878 -#define TK_CASCADE                         65
  1.2879 -#define TK_CAST                            66
  1.2880 -#define TK_COLUMNKW                        67
  1.2881 -#define TK_CONFLICT                        68
  1.2882 -#define TK_DATABASE                        69
  1.2883 -#define TK_DESC                            70
  1.2884 -#define TK_DETACH                          71
  1.2885 -#define TK_EACH                            72
  1.2886 -#define TK_FAIL                            73
  1.2887 -#define TK_FOR                             74
  1.2888 -#define TK_IGNORE                          75
  1.2889 -#define TK_INITIALLY                       76
  1.2890 -#define TK_INSTEAD                         77
  1.2891 -#define TK_NO                              78
  1.2892 -#define TK_KEY                             79
  1.2893 -#define TK_OF                              80
  1.2894 -#define TK_OFFSET                          81
  1.2895 -#define TK_PRAGMA                          82
  1.2896 -#define TK_RAISE                           83
  1.2897 -#define TK_RECURSIVE                       84
  1.2898 -#define TK_REPLACE                         85
  1.2899 -#define TK_RESTRICT                        86
  1.2900 -#define TK_ROW                             87
  1.2901 -#define TK_TRIGGER                         88
  1.2902 -#define TK_VACUUM                          89
  1.2903 -#define TK_VIEW                            90
  1.2904 -#define TK_VIRTUAL                         91
  1.2905 -#define TK_WITH                            92
  1.2906 -#define TK_REINDEX                         93
  1.2907 -#define TK_RENAME                          94
  1.2908 -#define TK_CTIME_KW                        95
  1.2909 -#define TK_ANY                             96
  1.2910 +#define TK_ID                              27
  1.2911 +#define TK_ABORT                           28
  1.2912 +#define TK_ACTION                          29
  1.2913 +#define TK_AFTER                           30
  1.2914 +#define TK_ANALYZE                         31
  1.2915 +#define TK_ASC                             32
  1.2916 +#define TK_ATTACH                          33
  1.2917 +#define TK_BEFORE                          34
  1.2918 +#define TK_BY                              35
  1.2919 +#define TK_CASCADE                         36
  1.2920 +#define TK_CAST                            37
  1.2921 +#define TK_COLUMNKW                        38
  1.2922 +#define TK_CONFLICT                        39
  1.2923 +#define TK_DATABASE                        40
  1.2924 +#define TK_DESC                            41
  1.2925 +#define TK_DETACH                          42
  1.2926 +#define TK_EACH                            43
  1.2927 +#define TK_FAIL                            44
  1.2928 +#define TK_FOR                             45
  1.2929 +#define TK_IGNORE                          46
  1.2930 +#define TK_INITIALLY                       47
  1.2931 +#define TK_INSTEAD                         48
  1.2932 +#define TK_LIKE_KW                         49
  1.2933 +#define TK_MATCH                           50
  1.2934 +#define TK_NO                              51
  1.2935 +#define TK_KEY                             52
  1.2936 +#define TK_OF                              53
  1.2937 +#define TK_OFFSET                          54
  1.2938 +#define TK_PRAGMA                          55
  1.2939 +#define TK_RAISE                           56
  1.2940 +#define TK_RECURSIVE                       57
  1.2941 +#define TK_REPLACE                         58
  1.2942 +#define TK_RESTRICT                        59
  1.2943 +#define TK_ROW                             60
  1.2944 +#define TK_TRIGGER                         61
  1.2945 +#define TK_VACUUM                          62
  1.2946 +#define TK_VIEW                            63
  1.2947 +#define TK_VIRTUAL                         64
  1.2948 +#define TK_WITH                            65
  1.2949 +#define TK_REINDEX                         66
  1.2950 +#define TK_RENAME                          67
  1.2951 +#define TK_CTIME_KW                        68
  1.2952 +#define TK_ANY                             69
  1.2953 +#define TK_OR                              70
  1.2954 +#define TK_AND                             71
  1.2955 +#define TK_IS                              72
  1.2956 +#define TK_BETWEEN                         73
  1.2957 +#define TK_IN                              74
  1.2958 +#define TK_ISNULL                          75
  1.2959 +#define TK_NOTNULL                         76
  1.2960 +#define TK_NE                              77
  1.2961 +#define TK_EQ                              78
  1.2962 +#define TK_GT                              79
  1.2963 +#define TK_LE                              80
  1.2964 +#define TK_LT                              81
  1.2965 +#define TK_GE                              82
  1.2966 +#define TK_ESCAPE                          83
  1.2967 +#define TK_BITAND                          84
  1.2968 +#define TK_BITOR                           85
  1.2969 +#define TK_LSHIFT                          86
  1.2970 +#define TK_RSHIFT                          87
  1.2971 +#define TK_PLUS                            88
  1.2972 +#define TK_MINUS                           89
  1.2973 +#define TK_STAR                            90
  1.2974 +#define TK_SLASH                           91
  1.2975 +#define TK_REM                             92
  1.2976 +#define TK_CONCAT                          93
  1.2977 +#define TK_COLLATE                         94
  1.2978 +#define TK_BITNOT                          95
  1.2979 +#define TK_INDEXED                         96
  1.2980  #define TK_STRING                          97
  1.2981  #define TK_JOIN_KW                         98
  1.2982  #define TK_CONSTRAINT                      99
  1.2983 @@ -11229,9 +11567,9 @@
  1.2984  #define TK_LIMIT                          129
  1.2985  #define TK_WHERE                          130
  1.2986  #define TK_INTO                           131
  1.2987 -#define TK_INTEGER                        132
  1.2988 -#define TK_FLOAT                          133
  1.2989 -#define TK_BLOB                           134
  1.2990 +#define TK_FLOAT                          132
  1.2991 +#define TK_BLOB                           133
  1.2992 +#define TK_INTEGER                        134
  1.2993  #define TK_VARIABLE                       135
  1.2994  #define TK_CASE                           136
  1.2995  #define TK_WHEN                           137
  1.2996 @@ -11255,10 +11593,13 @@
  1.2997  #define TK_UMINUS                         155
  1.2998  #define TK_UPLUS                          156
  1.2999  #define TK_REGISTER                       157
  1.3000 -#define TK_ASTERISK                       158
  1.3001 -#define TK_SPAN                           159
  1.3002 -#define TK_SPACE                          160
  1.3003 -#define TK_ILLEGAL                        161
  1.3004 +#define TK_VECTOR                         158
  1.3005 +#define TK_SELECT_COLUMN                  159
  1.3006 +#define TK_IF_NULL_ROW                    160
  1.3007 +#define TK_ASTERISK                       161
  1.3008 +#define TK_SPAN                           162
  1.3009 +#define TK_SPACE                          163
  1.3010 +#define TK_ILLEGAL                        164
  1.3011  
  1.3012  /* The token codes above must all fit in 8 bits */
  1.3013  #define TKFLG_MASK           0xff  
  1.3014 @@ -11276,6 +11617,18 @@
  1.3015  #include <stddef.h>
  1.3016  
  1.3017  /*
  1.3018 +** Use a macro to replace memcpy() if compiled with SQLITE_INLINE_MEMCPY.
  1.3019 +** This allows better measurements of where memcpy() is used when running
  1.3020 +** cachegrind.  But this macro version of memcpy() is very slow so it
  1.3021 +** should not be used in production.  This is a performance measurement
  1.3022 +** hack only.
  1.3023 +*/
  1.3024 +#ifdef SQLITE_INLINE_MEMCPY
  1.3025 +# define memcpy(D,S,N) {char*xxd=(char*)(D);const char*xxs=(const char*)(S);\
  1.3026 +                        int xxn=(N);while(xxn-->0)*(xxd++)=*(xxs++);}
  1.3027 +#endif
  1.3028 +
  1.3029 +/*
  1.3030  ** If compiling for a processor that lacks floating point support,
  1.3031  ** substitute integer for floating-point
  1.3032  */
  1.3033 @@ -11359,9 +11712,12 @@
  1.3034  ** pagecaches for each database connection.  A positive number is the
  1.3035  ** number of pages.  A negative number N translations means that a buffer
  1.3036  ** of -1024*N bytes is allocated and used for as many pages as it will hold.
  1.3037 +**
  1.3038 +** The default value of "20" was choosen to minimize the run-time of the
  1.3039 +** speedtest1 test program with options: --shrink-memory --reprepare
  1.3040  */
  1.3041  #ifndef SQLITE_DEFAULT_PCACHE_INITSZ
  1.3042 -# define SQLITE_DEFAULT_PCACHE_INITSZ 100
  1.3043 +# define SQLITE_DEFAULT_PCACHE_INITSZ 20
  1.3044  #endif
  1.3045  
  1.3046  /*
  1.3047 @@ -11536,32 +11892,35 @@
  1.3048  **
  1.3049  ** For best performance, an attempt is made to guess at the byte-order
  1.3050  ** using C-preprocessor macros.  If that is unsuccessful, or if
  1.3051 -** -DSQLITE_RUNTIME_BYTEORDER=1 is set, then byte-order is determined
  1.3052 +** -DSQLITE_BYTEORDER=0 is set, then byte-order is determined
  1.3053  ** at run-time.
  1.3054  */
  1.3055 -#if (defined(i386)     || defined(__i386__)   || defined(_M_IX86) ||    \
  1.3056 +#ifndef SQLITE_BYTEORDER
  1.3057 +# if defined(i386)     || defined(__i386__)   || defined(_M_IX86) ||    \
  1.3058       defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)  ||    \
  1.3059       defined(_M_AMD64) || defined(_M_ARM)     || defined(__x86)   ||    \
  1.3060 -     defined(__arm__)) && !defined(SQLITE_RUNTIME_BYTEORDER)
  1.3061 -# define SQLITE_BYTEORDER    1234
  1.3062 +     defined(__arm__)
  1.3063 +#   define SQLITE_BYTEORDER    1234
  1.3064 +# elif defined(sparc)    || defined(__ppc__)
  1.3065 +#   define SQLITE_BYTEORDER    4321
  1.3066 +# else
  1.3067 +#   define SQLITE_BYTEORDER 0
  1.3068 +# endif
  1.3069 +#endif
  1.3070 +#if SQLITE_BYTEORDER==4321
  1.3071 +# define SQLITE_BIGENDIAN    1
  1.3072 +# define SQLITE_LITTLEENDIAN 0
  1.3073 +# define SQLITE_UTF16NATIVE  SQLITE_UTF16BE
  1.3074 +#elif SQLITE_BYTEORDER==1234
  1.3075  # define SQLITE_BIGENDIAN    0
  1.3076  # define SQLITE_LITTLEENDIAN 1
  1.3077  # define SQLITE_UTF16NATIVE  SQLITE_UTF16LE
  1.3078 -#endif
  1.3079 -#if (defined(sparc)    || defined(__ppc__))  \
  1.3080 -    && !defined(SQLITE_RUNTIME_BYTEORDER)
  1.3081 -# define SQLITE_BYTEORDER    4321
  1.3082 -# define SQLITE_BIGENDIAN    1
  1.3083 -# define SQLITE_LITTLEENDIAN 0
  1.3084 -# define SQLITE_UTF16NATIVE  SQLITE_UTF16BE
  1.3085 -#endif
  1.3086 -#if !defined(SQLITE_BYTEORDER)
  1.3087 +#else
  1.3088  # ifdef SQLITE_AMALGAMATION
  1.3089    const int sqlite3one = 1;
  1.3090  # else
  1.3091    extern const int sqlite3one;
  1.3092  # endif
  1.3093 -# define SQLITE_BYTEORDER    0     /* 0 means "unknown at compile-time" */
  1.3094  # define SQLITE_BIGENDIAN    (*(char *)(&sqlite3one)==0)
  1.3095  # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
  1.3096  # define SQLITE_UTF16NATIVE  (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
  1.3097 @@ -11740,8 +12099,8 @@
  1.3098    #define SQLITE_WSD const
  1.3099    #define GLOBAL(t,v) (*(t*)sqlite3_wsd_find((void*)&(v), sizeof(v)))
  1.3100    #define sqlite3GlobalConfig GLOBAL(struct Sqlite3Config, sqlite3Config)
  1.3101 -SQLITE_API int SQLITE_STDCALL sqlite3_wsd_init(int N, int J);
  1.3102 -SQLITE_API void *SQLITE_STDCALL sqlite3_wsd_find(void *K, int L);
  1.3103 +SQLITE_API int sqlite3_wsd_init(int N, int J);
  1.3104 +SQLITE_API void *sqlite3_wsd_find(void *K, int L);
  1.3105  #else
  1.3106    #define SQLITE_WSD
  1.3107    #define GLOBAL(t,v) v
  1.3108 @@ -11818,6 +12177,14 @@
  1.3109  typedef struct WhereInfo WhereInfo;
  1.3110  typedef struct With With;
  1.3111  
  1.3112 +/* A VList object records a mapping between parameters/variables/wildcards
  1.3113 +** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
  1.3114 +** variable number associated with that parameter.  See the format description
  1.3115 +** on the sqlite3VListAdd() routine for more information.  A VList is really
  1.3116 +** just an array of integers.
  1.3117 +*/
  1.3118 +typedef int VList;
  1.3119 +
  1.3120  /*
  1.3121  ** Defer sourcing vdbe.h and btree.h until after the "u8" and
  1.3122  ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
  1.3123 @@ -11840,8 +12207,8 @@
  1.3124  ** subsystem.  See comments in the source code for a detailed description
  1.3125  ** of what each interface routine does.
  1.3126  */
  1.3127 -#ifndef _BTREE_H_
  1.3128 -#define _BTREE_H_
  1.3129 +#ifndef SQLITE_BTREE_H
  1.3130 +#define SQLITE_BTREE_H
  1.3131  
  1.3132  /* TODO: This definition is just included so other modules compile. It
  1.3133  ** needs to be revisited.
  1.3134 @@ -11866,6 +12233,7 @@
  1.3135  typedef struct Btree Btree;
  1.3136  typedef struct BtCursor BtCursor;
  1.3137  typedef struct BtShared BtShared;
  1.3138 +typedef struct BtreePayload BtreePayload;
  1.3139  
  1.3140  
  1.3141  SQLITE_PRIVATE int sqlite3BtreeOpen(
  1.3142 @@ -11916,7 +12284,9 @@
  1.3143  SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*);
  1.3144  SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
  1.3145  SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *pBtree);
  1.3146 +#ifndef SQLITE_OMIT_SHARED_CACHE
  1.3147  SQLITE_PRIVATE int sqlite3BtreeLockTable(Btree *pBtree, int iTab, u8 isWriteLock);
  1.3148 +#endif
  1.3149  SQLITE_PRIVATE int sqlite3BtreeSavepoint(Btree *, int, int);
  1.3150  
  1.3151  SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *);
  1.3152 @@ -12073,30 +12443,60 @@
  1.3153  SQLITE_PRIVATE int sqlite3BtreeCursorRestore(BtCursor*, int*);
  1.3154  SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*, u8 flags);
  1.3155  
  1.3156 -/* Allowed flags for the 2nd argument to sqlite3BtreeDelete() */
  1.3157 +/* Allowed flags for sqlite3BtreeDelete() and sqlite3BtreeInsert() */
  1.3158  #define BTREE_SAVEPOSITION 0x02  /* Leave cursor pointing at NEXT or PREV */
  1.3159  #define BTREE_AUXDELETE    0x04  /* not the primary delete operation */
  1.3160 -
  1.3161 -SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
  1.3162 -                                  const void *pData, int nData,
  1.3163 -                                  int nZero, int bias, int seekResult);
  1.3164 +#define BTREE_APPEND       0x08  /* Insert is likely an append */
  1.3165 +
  1.3166 +/* An instance of the BtreePayload object describes the content of a single
  1.3167 +** entry in either an index or table btree.
  1.3168 +**
  1.3169 +** Index btrees (used for indexes and also WITHOUT ROWID tables) contain
  1.3170 +** an arbitrary key and no data.  These btrees have pKey,nKey set to their
  1.3171 +** key and pData,nData,nZero set to zero.
  1.3172 +**
  1.3173 +** Table btrees (used for rowid tables) contain an integer rowid used as
  1.3174 +** the key and passed in the nKey field.  The pKey field is zero.  
  1.3175 +** pData,nData hold the content of the new entry.  nZero extra zero bytes
  1.3176 +** are appended to the end of the content when constructing the entry.
  1.3177 +**
  1.3178 +** This object is used to pass information into sqlite3BtreeInsert().  The
  1.3179 +** same information used to be passed as five separate parameters.  But placing
  1.3180 +** the information into this object helps to keep the interface more 
  1.3181 +** organized and understandable, and it also helps the resulting code to
  1.3182 +** run a little faster by using fewer registers for parameter passing.
  1.3183 +*/
  1.3184 +struct BtreePayload {
  1.3185 +  const void *pKey;       /* Key content for indexes.  NULL for tables */
  1.3186 +  sqlite3_int64 nKey;     /* Size of pKey for indexes.  PRIMARY KEY for tabs */
  1.3187 +  const void *pData;      /* Data for tables.  NULL for indexes */
  1.3188 +  sqlite3_value *aMem;    /* First of nMem value in the unpacked pKey */
  1.3189 +  u16 nMem;               /* Number of aMem[] value.  Might be zero */
  1.3190 +  int nData;              /* Size of pData.  0 if none. */
  1.3191 +  int nZero;              /* Extra zero data appended after pData,nData */
  1.3192 +};
  1.3193 +
  1.3194 +SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
  1.3195 +                       int flags, int seekResult);
  1.3196  SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
  1.3197  SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
  1.3198  SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
  1.3199  SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
  1.3200  SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
  1.3201 -SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
  1.3202 -SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
  1.3203 -SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, u32 *pAmt);
  1.3204 -SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, u32 *pAmt);
  1.3205 -SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
  1.3206 -SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
  1.3207 +SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
  1.3208 +SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
  1.3209 +SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
  1.3210 +SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
  1.3211  
  1.3212  SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
  1.3213  SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
  1.3214 -
  1.3215 +SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*);
  1.3216 +
  1.3217 +#ifndef SQLITE_OMIT_INCRBLOB
  1.3218 +SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*);
  1.3219  SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
  1.3220  SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *);
  1.3221 +#endif
  1.3222  SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *);
  1.3223  SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
  1.3224  SQLITE_PRIVATE int sqlite3BtreeCursorHasHint(BtCursor*, unsigned int mask);
  1.3225 @@ -12106,6 +12506,7 @@
  1.3226  #ifndef NDEBUG
  1.3227  SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*);
  1.3228  #endif
  1.3229 +SQLITE_PRIVATE int sqlite3BtreeCursorIsValidNN(BtCursor*);
  1.3230  
  1.3231  #ifndef SQLITE_OMIT_BTREECOUNT
  1.3232  SQLITE_PRIVATE int sqlite3BtreeCount(BtCursor *, i64 *);
  1.3233 @@ -12130,11 +12531,13 @@
  1.3234  SQLITE_PRIVATE   void sqlite3BtreeEnterAll(sqlite3*);
  1.3235  SQLITE_PRIVATE   int sqlite3BtreeSharable(Btree*);
  1.3236  SQLITE_PRIVATE   void sqlite3BtreeEnterCursor(BtCursor*);
  1.3237 +SQLITE_PRIVATE   int sqlite3BtreeConnectionCount(Btree*);
  1.3238  #else
  1.3239  # define sqlite3BtreeEnter(X) 
  1.3240  # define sqlite3BtreeEnterAll(X)
  1.3241  # define sqlite3BtreeSharable(X) 0
  1.3242  # define sqlite3BtreeEnterCursor(X)
  1.3243 +# define sqlite3BtreeConnectionCount(X) 1
  1.3244  #endif
  1.3245  
  1.3246  #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE
  1.3247 @@ -12159,7 +12562,7 @@
  1.3248  #endif
  1.3249  
  1.3250  
  1.3251 -#endif /* _BTREE_H_ */
  1.3252 +#endif /* SQLITE_BTREE_H */
  1.3253  
  1.3254  /************** End of btree.h ***********************************************/
  1.3255  /************** Continuing where we left off in sqliteInt.h ******************/
  1.3256 @@ -12182,8 +12585,8 @@
  1.3257  ** or VDBE.  The VDBE implements an abstract machine that runs a
  1.3258  ** simple program to access and modify the underlying database.
  1.3259  */
  1.3260 -#ifndef _SQLITE_VDBE_H_
  1.3261 -#define _SQLITE_VDBE_H_
  1.3262 +#ifndef SQLITE_VDBE_H
  1.3263 +#define SQLITE_VDBE_H
  1.3264  /* #include <stdio.h> */
  1.3265  
  1.3266  /*
  1.3267 @@ -12197,7 +12600,7 @@
  1.3268  ** The names of the following types declared in vdbeInt.h are required
  1.3269  ** for the VdbeOp definition.
  1.3270  */
  1.3271 -typedef struct Mem Mem;
  1.3272 +typedef struct sqlite3_value Mem;
  1.3273  typedef struct SubProgram SubProgram;
  1.3274  
  1.3275  /*
  1.3276 @@ -12208,8 +12611,7 @@
  1.3277  struct VdbeOp {
  1.3278    u8 opcode;          /* What operation to perform */
  1.3279    signed char p4type; /* One of the P4_xxx constants for p4 */
  1.3280 -  u8 notUsed1;
  1.3281 -  u8 p5;              /* Fifth parameter is an unsigned character */
  1.3282 +  u16 p5;             /* Fifth parameter is an unsigned 16-bit integer */
  1.3283    int p1;             /* First operand */
  1.3284    int p2;             /* Second parameter (often the jump destination) */
  1.3285    int p3;             /* The third parameter */
  1.3286 @@ -12255,7 +12657,7 @@
  1.3287    int nOp;                      /* Elements in aOp[] */
  1.3288    int nMem;                     /* Number of memory cells required */
  1.3289    int nCsr;                     /* Number of cursors required */
  1.3290 -  int nOnce;                    /* Number of OP_Once instructions */
  1.3291 +  u8 *aOnce;                    /* Array of OP_Once flags */
  1.3292    void *token;                  /* id that may be used to recursive triggers */
  1.3293    SubProgram *pNext;            /* Next sub-program already visited */
  1.3294  };
  1.3295 @@ -12278,22 +12680,21 @@
  1.3296  #define P4_NOTUSED    0   /* The P4 parameter is not used */
  1.3297  #define P4_DYNAMIC  (-1)  /* Pointer to a string obtained from sqliteMalloc() */
  1.3298  #define P4_STATIC   (-2)  /* Pointer to a static string */
  1.3299 -#define P4_COLLSEQ  (-4)  /* P4 is a pointer to a CollSeq structure */
  1.3300 -#define P4_FUNCDEF  (-5)  /* P4 is a pointer to a FuncDef structure */
  1.3301 -#define P4_KEYINFO  (-6)  /* P4 is a pointer to a KeyInfo structure */
  1.3302 -#define P4_EXPR     (-7)  /* P4 is a pointer to an Expr tree */
  1.3303 -#define P4_MEM      (-8)  /* P4 is a pointer to a Mem*    structure */
  1.3304 +#define P4_COLLSEQ  (-3)  /* P4 is a pointer to a CollSeq structure */
  1.3305 +#define P4_FUNCDEF  (-4)  /* P4 is a pointer to a FuncDef structure */
  1.3306 +#define P4_KEYINFO  (-5)  /* P4 is a pointer to a KeyInfo structure */
  1.3307 +#define P4_EXPR     (-6)  /* P4 is a pointer to an Expr tree */
  1.3308 +#define P4_MEM      (-7)  /* P4 is a pointer to a Mem*    structure */
  1.3309  #define P4_TRANSIENT  0   /* P4 is a pointer to a transient string */
  1.3310 -#define P4_VTAB     (-10) /* P4 is a pointer to an sqlite3_vtab structure */
  1.3311 -#define P4_MPRINTF  (-11) /* P4 is a string obtained from sqlite3_mprintf() */
  1.3312 -#define P4_REAL     (-12) /* P4 is a 64-bit floating point value */
  1.3313 -#define P4_INT64    (-13) /* P4 is a 64-bit signed integer */
  1.3314 -#define P4_INT32    (-14) /* P4 is a 32-bit signed integer */
  1.3315 -#define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
  1.3316 -#define P4_SUBPROGRAM  (-18) /* P4 is a pointer to a SubProgram structure */
  1.3317 -#define P4_ADVANCE  (-19) /* P4 is a pointer to BtreeNext() or BtreePrev() */
  1.3318 -#define P4_TABLE    (-20) /* P4 is a pointer to a Table structure */
  1.3319 -#define P4_FUNCCTX  (-21) /* P4 is a pointer to an sqlite3_context object */
  1.3320 +#define P4_VTAB     (-8) /* P4 is a pointer to an sqlite3_vtab structure */
  1.3321 +#define P4_REAL     (-9) /* P4 is a 64-bit floating point value */
  1.3322 +#define P4_INT64    (-10) /* P4 is a 64-bit signed integer */
  1.3323 +#define P4_INT32    (-11) /* P4 is a 32-bit signed integer */
  1.3324 +#define P4_INTARRAY (-12) /* P4 is a vector of 32-bit integers */
  1.3325 +#define P4_SUBPROGRAM  (-13) /* P4 is a pointer to a SubProgram structure */
  1.3326 +#define P4_ADVANCE  (-14) /* P4 is a pointer to BtreeNext() or BtreePrev() */
  1.3327 +#define P4_TABLE    (-15) /* P4 is a pointer to a Table structure */
  1.3328 +#define P4_FUNCCTX  (-16) /* P4 is a pointer to an sqlite3_context object */
  1.3329  
  1.3330  /* Error message codes for OP_Halt */
  1.3331  #define P5_ConstraintNotNull 1
  1.3332 @@ -12359,144 +12760,149 @@
  1.3333  #define OP_Once           20
  1.3334  #define OP_If             21
  1.3335  #define OP_IfNot          22
  1.3336 -#define OP_SeekLT         23 /* synopsis: key=r[P3@P4]                     */
  1.3337 -#define OP_SeekLE         24 /* synopsis: key=r[P3@P4]                     */
  1.3338 -#define OP_SeekGE         25 /* synopsis: key=r[P3@P4]                     */
  1.3339 -#define OP_SeekGT         26 /* synopsis: key=r[P3@P4]                     */
  1.3340 -#define OP_Or             27 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
  1.3341 -#define OP_And            28 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
  1.3342 -#define OP_NoConflict     29 /* synopsis: key=r[P3@P4]                     */
  1.3343 -#define OP_NotFound       30 /* synopsis: key=r[P3@P4]                     */
  1.3344 -#define OP_Found          31 /* synopsis: key=r[P3@P4]                     */
  1.3345 +#define OP_IfNullRow      23 /* synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
  1.3346 +#define OP_SeekLT         24 /* synopsis: key=r[P3@P4]                     */
  1.3347 +#define OP_SeekLE         25 /* synopsis: key=r[P3@P4]                     */
  1.3348 +#define OP_SeekGE         26 /* synopsis: key=r[P3@P4]                     */
  1.3349 +#define OP_SeekGT         27 /* synopsis: key=r[P3@P4]                     */
  1.3350 +#define OP_NoConflict     28 /* synopsis: key=r[P3@P4]                     */
  1.3351 +#define OP_NotFound       29 /* synopsis: key=r[P3@P4]                     */
  1.3352 +#define OP_Found          30 /* synopsis: key=r[P3@P4]                     */
  1.3353 +#define OP_SeekRowid      31 /* synopsis: intkey=r[P3]                     */
  1.3354  #define OP_NotExists      32 /* synopsis: intkey=r[P3]                     */
  1.3355  #define OP_Last           33
  1.3356 -#define OP_IsNull         34 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
  1.3357 -#define OP_NotNull        35 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
  1.3358 -#define OP_Ne             36 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
  1.3359 -#define OP_Eq             37 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
  1.3360 -#define OP_Gt             38 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
  1.3361 -#define OP_Le             39 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
  1.3362 -#define OP_Lt             40 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
  1.3363 -#define OP_Ge             41 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
  1.3364 -#define OP_SorterSort     42
  1.3365 -#define OP_BitAnd         43 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
  1.3366 -#define OP_BitOr          44 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
  1.3367 -#define OP_ShiftLeft      45 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
  1.3368 -#define OP_ShiftRight     46 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
  1.3369 -#define OP_Add            47 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
  1.3370 -#define OP_Subtract       48 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
  1.3371 -#define OP_Multiply       49 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
  1.3372 -#define OP_Divide         50 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
  1.3373 -#define OP_Remainder      51 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
  1.3374 -#define OP_Concat         52 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
  1.3375 -#define OP_Sort           53
  1.3376 -#define OP_BitNot         54 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
  1.3377 -#define OP_Rewind         55
  1.3378 -#define OP_IdxLE          56 /* synopsis: key=r[P3@P4]                     */
  1.3379 -#define OP_IdxGT          57 /* synopsis: key=r[P3@P4]                     */
  1.3380 -#define OP_IdxLT          58 /* synopsis: key=r[P3@P4]                     */
  1.3381 -#define OP_IdxGE          59 /* synopsis: key=r[P3@P4]                     */
  1.3382 -#define OP_RowSetRead     60 /* synopsis: r[P3]=rowset(P1)                 */
  1.3383 -#define OP_RowSetTest     61 /* synopsis: if r[P3] in rowset(P1) goto P2   */
  1.3384 -#define OP_Program        62
  1.3385 -#define OP_FkIfZero       63 /* synopsis: if fkctr[P1]==0 goto P2          */
  1.3386 -#define OP_IfPos          64 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
  1.3387 -#define OP_IfNotZero      65 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */
  1.3388 -#define OP_DecrJumpZero   66 /* synopsis: if (--r[P1])==0 goto P2          */
  1.3389 -#define OP_IncrVacuum     67
  1.3390 -#define OP_VNext          68
  1.3391 -#define OP_Init           69 /* synopsis: Start at P2                      */
  1.3392 -#define OP_Return         70
  1.3393 -#define OP_EndCoroutine   71
  1.3394 -#define OP_HaltIfNull     72 /* synopsis: if r[P3]=null halt               */
  1.3395 -#define OP_Halt           73
  1.3396 -#define OP_Integer        74 /* synopsis: r[P2]=P1                         */
  1.3397 -#define OP_Int64          75 /* synopsis: r[P2]=P4                         */
  1.3398 -#define OP_String         76 /* synopsis: r[P2]='P4' (len=P1)              */
  1.3399 -#define OP_Null           77 /* synopsis: r[P2..P3]=NULL                   */
  1.3400 -#define OP_SoftNull       78 /* synopsis: r[P1]=NULL                       */
  1.3401 -#define OP_Blob           79 /* synopsis: r[P2]=P4 (len=P1)                */
  1.3402 -#define OP_Variable       80 /* synopsis: r[P2]=parameter(P1,P4)           */
  1.3403 -#define OP_Move           81 /* synopsis: r[P2@P3]=r[P1@P3]                */
  1.3404 -#define OP_Copy           82 /* synopsis: r[P2@P3+1]=r[P1@P3+1]            */
  1.3405 -#define OP_SCopy          83 /* synopsis: r[P2]=r[P1]                      */
  1.3406 -#define OP_IntCopy        84 /* synopsis: r[P2]=r[P1]                      */
  1.3407 -#define OP_ResultRow      85 /* synopsis: output=r[P1@P2]                  */
  1.3408 -#define OP_CollSeq        86
  1.3409 -#define OP_Function0      87 /* synopsis: r[P3]=func(r[P2@P5])             */
  1.3410 -#define OP_Function       88 /* synopsis: r[P3]=func(r[P2@P5])             */
  1.3411 -#define OP_AddImm         89 /* synopsis: r[P1]=r[P1]+P2                   */
  1.3412 -#define OP_RealAffinity   90
  1.3413 -#define OP_Cast           91 /* synopsis: affinity(r[P1])                  */
  1.3414 -#define OP_Permutation    92
  1.3415 -#define OP_Compare        93 /* synopsis: r[P1@P3] <-> r[P2@P3]            */
  1.3416 -#define OP_Column         94 /* synopsis: r[P3]=PX                         */
  1.3417 -#define OP_Affinity       95 /* synopsis: affinity(r[P1@P2])               */
  1.3418 -#define OP_MakeRecord     96 /* synopsis: r[P3]=mkrec(r[P1@P2])            */
  1.3419 +#define OP_IfSmaller      34
  1.3420 +#define OP_SorterSort     35
  1.3421 +#define OP_Sort           36
  1.3422 +#define OP_Rewind         37
  1.3423 +#define OP_IdxLE          38 /* synopsis: key=r[P3@P4]                     */
  1.3424 +#define OP_IdxGT          39 /* synopsis: key=r[P3@P4]                     */
  1.3425 +#define OP_IdxLT          40 /* synopsis: key=r[P3@P4]                     */
  1.3426 +#define OP_IdxGE          41 /* synopsis: key=r[P3@P4]                     */
  1.3427 +#define OP_RowSetRead     42 /* synopsis: r[P3]=rowset(P1)                 */
  1.3428 +#define OP_RowSetTest     43 /* synopsis: if r[P3] in rowset(P1) goto P2   */
  1.3429 +#define OP_Program        44
  1.3430 +#define OP_FkIfZero       45 /* synopsis: if fkctr[P1]==0 goto P2          */
  1.3431 +#define OP_IfPos          46 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
  1.3432 +#define OP_IfNotZero      47 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
  1.3433 +#define OP_DecrJumpZero   48 /* synopsis: if (--r[P1])==0 goto P2          */
  1.3434 +#define OP_IncrVacuum     49
  1.3435 +#define OP_VNext          50
  1.3436 +#define OP_Init           51 /* synopsis: Start at P2                      */
  1.3437 +#define OP_Return         52
  1.3438 +#define OP_EndCoroutine   53
  1.3439 +#define OP_HaltIfNull     54 /* synopsis: if r[P3]=null halt               */
  1.3440 +#define OP_Halt           55
  1.3441 +#define OP_Integer        56 /* synopsis: r[P2]=P1                         */
  1.3442 +#define OP_Int64          57 /* synopsis: r[P2]=P4                         */
  1.3443 +#define OP_String         58 /* synopsis: r[P2]='P4' (len=P1)              */
  1.3444 +#define OP_Null           59 /* synopsis: r[P2..P3]=NULL                   */
  1.3445 +#define OP_SoftNull       60 /* synopsis: r[P1]=NULL                       */
  1.3446 +#define OP_Blob           61 /* synopsis: r[P2]=P4 (len=P1)                */
  1.3447 +#define OP_Variable       62 /* synopsis: r[P2]=parameter(P1,P4)           */
  1.3448 +#define OP_Move           63 /* synopsis: r[P2@P3]=r[P1@P3]                */
  1.3449 +#define OP_Copy           64 /* synopsis: r[P2@P3+1]=r[P1@P3+1]            */
  1.3450 +#define OP_SCopy          65 /* synopsis: r[P2]=r[P1]                      */
  1.3451 +#define OP_IntCopy        66 /* synopsis: r[P2]=r[P1]                      */
  1.3452 +#define OP_ResultRow      67 /* synopsis: output=r[P1@P2]                  */
  1.3453 +#define OP_CollSeq        68
  1.3454 +#define OP_Function0      69 /* synopsis: r[P3]=func(r[P2@P5])             */
  1.3455 +#define OP_Or             70 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
  1.3456 +#define OP_And            71 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
  1.3457 +#define OP_Function       72 /* synopsis: r[P3]=func(r[P2@P5])             */
  1.3458 +#define OP_AddImm         73 /* synopsis: r[P1]=r[P1]+P2                   */
  1.3459 +#define OP_RealAffinity   74
  1.3460 +#define OP_IsNull         75 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
  1.3461 +#define OP_NotNull        76 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
  1.3462 +#define OP_Ne             77 /* same as TK_NE, synopsis: IF r[P3]!=r[P1]   */
  1.3463 +#define OP_Eq             78 /* same as TK_EQ, synopsis: IF r[P3]==r[P1]   */
  1.3464 +#define OP_Gt             79 /* same as TK_GT, synopsis: IF r[P3]>r[P1]    */
  1.3465 +#define OP_Le             80 /* same as TK_LE, synopsis: IF r[P3]<=r[P1]   */
  1.3466 +#define OP_Lt             81 /* same as TK_LT, synopsis: IF r[P3]<r[P1]    */
  1.3467 +#define OP_Ge             82 /* same as TK_GE, synopsis: IF r[P3]>=r[P1]   */
  1.3468 +#define OP_ElseNotEq      83 /* same as TK_ESCAPE                          */
  1.3469 +#define OP_BitAnd         84 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
  1.3470 +#define OP_BitOr          85 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
  1.3471 +#define OP_ShiftLeft      86 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
  1.3472 +#define OP_ShiftRight     87 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
  1.3473 +#define OP_Add            88 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
  1.3474 +#define OP_Subtract       89 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
  1.3475 +#define OP_Multiply       90 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
  1.3476 +#define OP_Divide         91 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
  1.3477 +#define OP_Remainder      92 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
  1.3478 +#define OP_Concat         93 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
  1.3479 +#define OP_Cast           94 /* synopsis: affinity(r[P1])                  */
  1.3480 +#define OP_BitNot         95 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
  1.3481 +#define OP_Permutation    96
  1.3482  #define OP_String8        97 /* same as TK_STRING, synopsis: r[P2]='P4'    */
  1.3483 -#define OP_Count          98 /* synopsis: r[P2]=count()                    */
  1.3484 -#define OP_ReadCookie     99
  1.3485 -#define OP_SetCookie     100
  1.3486 -#define OP_ReopenIdx     101 /* synopsis: root=P2 iDb=P3                   */
  1.3487 -#define OP_OpenRead      102 /* synopsis: root=P2 iDb=P3                   */
  1.3488 -#define OP_OpenWrite     103 /* synopsis: root=P2 iDb=P3                   */
  1.3489 -#define OP_OpenAutoindex 104 /* synopsis: nColumn=P2                       */
  1.3490 -#define OP_OpenEphemeral 105 /* synopsis: nColumn=P2                       */
  1.3491 -#define OP_SorterOpen    106
  1.3492 -#define OP_SequenceTest  107 /* synopsis: if( cursor[P1].ctr++ ) pc = P2   */
  1.3493 -#define OP_OpenPseudo    108 /* synopsis: P3 columns in r[P2]              */
  1.3494 -#define OP_Close         109
  1.3495 -#define OP_ColumnsUsed   110
  1.3496 -#define OP_Sequence      111 /* synopsis: r[P2]=cursor[P1].ctr++           */
  1.3497 -#define OP_NewRowid      112 /* synopsis: r[P2]=rowid                      */
  1.3498 -#define OP_Insert        113 /* synopsis: intkey=r[P3] data=r[P2]          */
  1.3499 -#define OP_InsertInt     114 /* synopsis: intkey=P3 data=r[P2]             */
  1.3500 -#define OP_Delete        115
  1.3501 -#define OP_ResetCount    116
  1.3502 -#define OP_SorterCompare 117 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
  1.3503 -#define OP_SorterData    118 /* synopsis: r[P2]=data                       */
  1.3504 -#define OP_RowKey        119 /* synopsis: r[P2]=key                        */
  1.3505 -#define OP_RowData       120 /* synopsis: r[P2]=data                       */
  1.3506 -#define OP_Rowid         121 /* synopsis: r[P2]=rowid                      */
  1.3507 -#define OP_NullRow       122
  1.3508 -#define OP_SorterInsert  123
  1.3509 -#define OP_IdxInsert     124 /* synopsis: key=r[P2]                        */
  1.3510 -#define OP_IdxDelete     125 /* synopsis: key=r[P2@P3]                     */
  1.3511 -#define OP_Seek          126 /* synopsis: Move P3 to P1.rowid              */
  1.3512 -#define OP_IdxRowid      127 /* synopsis: r[P2]=rowid                      */
  1.3513 -#define OP_Destroy       128
  1.3514 -#define OP_Clear         129
  1.3515 -#define OP_ResetSorter   130
  1.3516 -#define OP_CreateIndex   131 /* synopsis: r[P2]=root iDb=P1                */
  1.3517 -#define OP_CreateTable   132 /* synopsis: r[P2]=root iDb=P1                */
  1.3518 -#define OP_Real          133 /* same as TK_FLOAT, synopsis: r[P2]=P4       */
  1.3519 -#define OP_ParseSchema   134
  1.3520 -#define OP_LoadAnalysis  135
  1.3521 -#define OP_DropTable     136
  1.3522 -#define OP_DropIndex     137
  1.3523 -#define OP_DropTrigger   138
  1.3524 -#define OP_IntegrityCk   139
  1.3525 -#define OP_RowSetAdd     140 /* synopsis: rowset(P1)=r[P2]                 */
  1.3526 -#define OP_Param         141
  1.3527 -#define OP_FkCounter     142 /* synopsis: fkctr[P1]+=P2                    */
  1.3528 -#define OP_MemMax        143 /* synopsis: r[P1]=max(r[P1],r[P2])           */
  1.3529 -#define OP_OffsetLimit   144 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
  1.3530 -#define OP_AggStep0      145 /* synopsis: accum=r[P3] step(r[P2@P5])       */
  1.3531 -#define OP_AggStep       146 /* synopsis: accum=r[P3] step(r[P2@P5])       */
  1.3532 -#define OP_AggFinal      147 /* synopsis: accum=r[P1] N=P2                 */
  1.3533 -#define OP_Expire        148
  1.3534 -#define OP_TableLock     149 /* synopsis: iDb=P1 root=P2 write=P3          */
  1.3535 -#define OP_VBegin        150
  1.3536 -#define OP_VCreate       151
  1.3537 -#define OP_VDestroy      152
  1.3538 -#define OP_VOpen         153
  1.3539 -#define OP_VColumn       154 /* synopsis: r[P3]=vcolumn(P2)                */
  1.3540 -#define OP_VRename       155
  1.3541 -#define OP_Pagecount     156
  1.3542 -#define OP_MaxPgcnt      157
  1.3543 -#define OP_CursorHint    158
  1.3544 -#define OP_Noop          159
  1.3545 -#define OP_Explain       160
  1.3546 +#define OP_Compare        98 /* synopsis: r[P1@P3] <-> r[P2@P3]            */
  1.3547 +#define OP_Column         99 /* synopsis: r[P3]=PX                         */
  1.3548 +#define OP_Affinity      100 /* synopsis: affinity(r[P1@P2])               */
  1.3549 +#define OP_MakeRecord    101 /* synopsis: r[P3]=mkrec(r[P1@P2])            */
  1.3550 +#define OP_Count         102 /* synopsis: r[P2]=count()                    */
  1.3551 +#define OP_ReadCookie    103
  1.3552 +#define OP_SetCookie     104
  1.3553 +#define OP_ReopenIdx     105 /* synopsis: root=P2 iDb=P3                   */
  1.3554 +#define OP_OpenRead      106 /* synopsis: root=P2 iDb=P3                   */
  1.3555 +#define OP_OpenWrite     107 /* synopsis: root=P2 iDb=P3                   */
  1.3556 +#define OP_OpenDup       108
  1.3557 +#define OP_OpenAutoindex 109 /* synopsis: nColumn=P2                       */
  1.3558 +#define OP_OpenEphemeral 110 /* synopsis: nColumn=P2                       */
  1.3559 +#define OP_SorterOpen    111
  1.3560 +#define OP_SequenceTest  112 /* synopsis: if( cursor[P1].ctr++ ) pc = P2   */
  1.3561 +#define OP_OpenPseudo    113 /* synopsis: P3 columns in r[P2]              */
  1.3562 +#define OP_Close         114
  1.3563 +#define OP_ColumnsUsed   115
  1.3564 +#define OP_Sequence      116 /* synopsis: r[P2]=cursor[P1].ctr++           */
  1.3565 +#define OP_NewRowid      117 /* synopsis: r[P2]=rowid                      */
  1.3566 +#define OP_Insert        118 /* synopsis: intkey=r[P3] data=r[P2]          */
  1.3567 +#define OP_InsertInt     119 /* synopsis: intkey=P3 data=r[P2]             */
  1.3568 +#define OP_Delete        120
  1.3569 +#define OP_ResetCount    121
  1.3570 +#define OP_SorterCompare 122 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
  1.3571 +#define OP_SorterData    123 /* synopsis: r[P2]=data                       */
  1.3572 +#define OP_RowData       124 /* synopsis: r[P2]=data                       */
  1.3573 +#define OP_Rowid         125 /* synopsis: r[P2]=rowid                      */
  1.3574 +#define OP_NullRow       126
  1.3575 +#define OP_SorterInsert  127 /* synopsis: key=r[P2]                        */
  1.3576 +#define OP_IdxInsert     128 /* synopsis: key=r[P2]                        */
  1.3577 +#define OP_IdxDelete     129 /* synopsis: key=r[P2@P3]                     */
  1.3578 +#define OP_Seek          130 /* synopsis: Move P3 to P1.rowid              */
  1.3579 +#define OP_IdxRowid      131 /* synopsis: r[P2]=rowid                      */
  1.3580 +#define OP_Real          132 /* same as TK_FLOAT, synopsis: r[P2]=P4       */
  1.3581 +#define OP_Destroy       133
  1.3582 +#define OP_Clear         134
  1.3583 +#define OP_ResetSorter   135
  1.3584 +#define OP_CreateIndex   136 /* synopsis: r[P2]=root iDb=P1                */
  1.3585 +#define OP_CreateTable   137 /* synopsis: r[P2]=root iDb=P1                */
  1.3586 +#define OP_SqlExec       138
  1.3587 +#define OP_ParseSchema   139
  1.3588 +#define OP_LoadAnalysis  140
  1.3589 +#define OP_DropTable     141
  1.3590 +#define OP_DropIndex     142
  1.3591 +#define OP_DropTrigger   143
  1.3592 +#define OP_IntegrityCk   144
  1.3593 +#define OP_RowSetAdd     145 /* synopsis: rowset(P1)=r[P2]                 */
  1.3594 +#define OP_Param         146
  1.3595 +#define OP_FkCounter     147 /* synopsis: fkctr[P1]+=P2                    */
  1.3596 +#define OP_MemMax        148 /* synopsis: r[P1]=max(r[P1],r[P2])           */
  1.3597 +#define OP_OffsetLimit   149 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
  1.3598 +#define OP_AggStep0      150 /* synopsis: accum=r[P3] step(r[P2@P5])       */
  1.3599 +#define OP_AggStep       151 /* synopsis: accum=r[P3] step(r[P2@P5])       */
  1.3600 +#define OP_AggFinal      152 /* synopsis: accum=r[P1] N=P2                 */
  1.3601 +#define OP_Expire        153
  1.3602 +#define OP_TableLock     154 /* synopsis: iDb=P1 root=P2 write=P3          */
  1.3603 +#define OP_VBegin        155
  1.3604 +#define OP_VCreate       156
  1.3605 +#define OP_VDestroy      157
  1.3606 +#define OP_VOpen         158
  1.3607 +#define OP_VColumn       159 /* synopsis: r[P3]=vcolumn(P2)                */
  1.3608 +#define OP_VRename       160
  1.3609 +#define OP_Pagecount     161
  1.3610 +#define OP_MaxPgcnt      162
  1.3611 +#define OP_CursorHint    163
  1.3612 +#define OP_Noop          164
  1.3613 +#define OP_Explain       165
  1.3614  
  1.3615  /* Properties such as "out2" or "jump" that are specified in
  1.3616  ** comments following the "case" for each opcode in the vdbe.c
  1.3617 @@ -12511,25 +12917,25 @@
  1.3618  #define OPFLG_INITIALIZER {\
  1.3619  /*   0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
  1.3620  /*   8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\
  1.3621 -/*  16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x09,\
  1.3622 -/*  24 */ 0x09, 0x09, 0x09, 0x26, 0x26, 0x09, 0x09, 0x09,\
  1.3623 -/*  32 */ 0x09, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
  1.3624 -/*  40 */ 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26, 0x26,\
  1.3625 -/*  48 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x01, 0x12, 0x01,\
  1.3626 -/*  56 */ 0x01, 0x01, 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01,\
  1.3627 -/*  64 */ 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x02, 0x02,\
  1.3628 -/*  72 */ 0x08, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10,\
  1.3629 -/*  80 */ 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,\
  1.3630 -/*  88 */ 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,\
  1.3631 -/*  96 */ 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
  1.3632 -/* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
  1.3633 -/* 112 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
  1.3634 -/* 120 */ 0x00, 0x10, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10,\
  1.3635 -/* 128 */ 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
  1.3636 -/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
  1.3637 -/* 144 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
  1.3638 -/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
  1.3639 -/* 160 */ 0x00,}
  1.3640 +/*  16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x01,\
  1.3641 +/*  24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
  1.3642 +/*  32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
  1.3643 +/*  40 */ 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01, 0x03, 0x03,\
  1.3644 +/*  48 */ 0x03, 0x01, 0x01, 0x01, 0x02, 0x02, 0x08, 0x00,\
  1.3645 +/*  56 */ 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00,\
  1.3646 +/*  64 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x26, 0x26,\
  1.3647 +/*  72 */ 0x00, 0x02, 0x02, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
  1.3648 +/*  80 */ 0x0b, 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26,\
  1.3649 +/*  88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x02, 0x12,\
  1.3650 +/*  96 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
  1.3651 +/* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
  1.3652 +/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
  1.3653 +/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x04,\
  1.3654 +/* 128 */ 0x04, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
  1.3655 +/* 136 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
  1.3656 +/* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00,\
  1.3657 +/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
  1.3658 +/* 160 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,}
  1.3659  
  1.3660  /* The sqlite3P2Values() routine is able to run faster if it knows
  1.3661  ** the value of the largest JUMP opcode.  The smaller the maximum
  1.3662 @@ -12537,7 +12943,7 @@
  1.3663  ** generated this include file strives to group all JUMP opcodes
  1.3664  ** together near the beginning of the list.
  1.3665  */
  1.3666 -#define SQLITE_MX_JUMP_OPCODE  69  /* Maximum JUMP opcode */
  1.3667 +#define SQLITE_MX_JUMP_OPCODE  83  /* Maximum JUMP opcode */
  1.3668  
  1.3669  /************** End of opcodes.h *********************************************/
  1.3670  /************** Continuing where we left off in vdbe.h ***********************/
  1.3671 @@ -12560,8 +12966,10 @@
  1.3672  SQLITE_PRIVATE void sqlite3VdbeEndCoroutine(Vdbe*,int);
  1.3673  #if defined(SQLITE_DEBUG) && !defined(SQLITE_TEST_REALLOC_STRESS)
  1.3674  SQLITE_PRIVATE   void sqlite3VdbeVerifyNoMallocRequired(Vdbe *p, int N);
  1.3675 +SQLITE_PRIVATE   void sqlite3VdbeVerifyNoResultRow(Vdbe *p);
  1.3676  #else
  1.3677  # define sqlite3VdbeVerifyNoMallocRequired(A,B)
  1.3678 +# define sqlite3VdbeVerifyNoResultRow(A)
  1.3679  #endif
  1.3680  SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno);
  1.3681  SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
  1.3682 @@ -12569,11 +12977,12 @@
  1.3683  SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
  1.3684  SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
  1.3685  SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
  1.3686 -SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
  1.3687 +SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
  1.3688  SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
  1.3689  SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
  1.3690  SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
  1.3691  SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
  1.3692 +SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
  1.3693  SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
  1.3694  SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
  1.3695  SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
  1.3696 @@ -12609,7 +13018,7 @@
  1.3697  SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
  1.3698  SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
  1.3699  SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
  1.3700 -SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
  1.3701 +SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*);
  1.3702  
  1.3703  typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
  1.3704  SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
  1.3705 @@ -12684,7 +13093,7 @@
  1.3706  # define sqlite3VdbeScanStatus(a,b,c,d,e)
  1.3707  #endif
  1.3708  
  1.3709 -#endif
  1.3710 +#endif /* SQLITE_VDBE_H */
  1.3711  
  1.3712  /************** End of vdbe.h ************************************************/
  1.3713  /************** Continuing where we left off in sqliteInt.h ******************/
  1.3714 @@ -12706,8 +13115,8 @@
  1.3715  ** at a time and provides a journal for rollback.
  1.3716  */
  1.3717  
  1.3718 -#ifndef _PAGER_H_
  1.3719 -#define _PAGER_H_
  1.3720 +#ifndef SQLITE_PAGER_H
  1.3721 +#define SQLITE_PAGER_H
  1.3722  
  1.3723  /*
  1.3724  ** Default maximum size for persistent journal files. A negative 
  1.3725 @@ -12814,7 +13223,7 @@
  1.3726    int,
  1.3727    void(*)(DbPage*)
  1.3728  );
  1.3729 -SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager);
  1.3730 +SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager, sqlite3*);
  1.3731  SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
  1.3732  
  1.3733  /* Functions used to configure a Pager object. */
  1.3734 @@ -12865,15 +13274,21 @@
  1.3735  SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
  1.3736  
  1.3737  #ifndef SQLITE_OMIT_WAL
  1.3738 -SQLITE_PRIVATE   int sqlite3PagerCheckpoint(Pager *pPager, int, int*, int*);
  1.3739 +SQLITE_PRIVATE   int sqlite3PagerCheckpoint(Pager *pPager, sqlite3*, int, int*, int*);
  1.3740  SQLITE_PRIVATE   int sqlite3PagerWalSupported(Pager *pPager);
  1.3741  SQLITE_PRIVATE   int sqlite3PagerWalCallback(Pager *pPager);
  1.3742  SQLITE_PRIVATE   int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen);
  1.3743 -SQLITE_PRIVATE   int sqlite3PagerCloseWal(Pager *pPager);
  1.3744 +SQLITE_PRIVATE   int sqlite3PagerCloseWal(Pager *pPager, sqlite3*);
  1.3745 +# ifdef SQLITE_DIRECT_OVERFLOW_READ
  1.3746 +SQLITE_PRIVATE   int sqlite3PagerUseWal(Pager *pPager, Pgno);
  1.3747 +# endif
  1.3748  # ifdef SQLITE_ENABLE_SNAPSHOT
  1.3749  SQLITE_PRIVATE   int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot);
  1.3750  SQLITE_PRIVATE   int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot);
  1.3751 +SQLITE_PRIVATE   int sqlite3PagerSnapshotRecover(Pager *pPager);
  1.3752  # endif
  1.3753 +#else
  1.3754 +# define sqlite3PagerUseWal(x,y) 0
  1.3755  #endif
  1.3756  
  1.3757  #ifdef SQLITE_ENABLE_ZIPVFS
  1.3758 @@ -12895,7 +13310,7 @@
  1.3759  SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
  1.3760  SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*);
  1.3761  SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *);
  1.3762 -SQLITE_PRIVATE void sqlite3PagerClearCache(Pager *);
  1.3763 +SQLITE_PRIVATE void sqlite3PagerClearCache(Pager*);
  1.3764  SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *);
  1.3765  
  1.3766  /* Functions used to truncate the database file. */
  1.3767 @@ -12922,7 +13337,7 @@
  1.3768  # define enable_simulated_io_errors()
  1.3769  #endif
  1.3770  
  1.3771 -#endif /* _PAGER_H_ */
  1.3772 +#endif /* SQLITE_PAGER_H */
  1.3773  
  1.3774  /************** End of pager.h ***********************************************/
  1.3775  /************** Continuing where we left off in sqliteInt.h ******************/
  1.3776 @@ -13160,8 +13575,8 @@
  1.3777  ** This file contains pre-processor directives related to operating system
  1.3778  ** detection and/or setup.
  1.3779  */
  1.3780 -#ifndef _OS_SETUP_H_
  1.3781 -#define _OS_SETUP_H_
  1.3782 +#ifndef SQLITE_OS_SETUP_H
  1.3783 +#define SQLITE_OS_SETUP_H
  1.3784  
  1.3785  /*
  1.3786  ** Figure out if we are dealing with Unix, Windows, or some other operating
  1.3787 @@ -13201,7 +13616,7 @@
  1.3788  #  endif
  1.3789  #endif
  1.3790  
  1.3791 -#endif /* _OS_SETUP_H_ */
  1.3792 +#endif /* SQLITE_OS_SETUP_H */
  1.3793  
  1.3794  /************** End of os_setup.h ********************************************/
  1.3795  /************** Continuing where we left off in os.h *************************/
  1.3796 @@ -13492,7 +13907,7 @@
  1.3797  ** and the one-based values are used internally.
  1.3798  */
  1.3799  #ifndef SQLITE_DEFAULT_SYNCHRONOUS
  1.3800 -# define SQLITE_DEFAULT_SYNCHRONOUS (PAGER_SYNCHRONOUS_FULL-1)
  1.3801 +# define SQLITE_DEFAULT_SYNCHRONOUS 2
  1.3802  #endif
  1.3803  #ifndef SQLITE_DEFAULT_WAL_SYNCHRONOUS
  1.3804  # define SQLITE_DEFAULT_WAL_SYNCHRONOUS SQLITE_DEFAULT_SYNCHRONOUS
  1.3805 @@ -13506,7 +13921,7 @@
  1.3806  ** databases may be attached.
  1.3807  */
  1.3808  struct Db {
  1.3809 -  char *zName;         /* Name of this database */
  1.3810 +  char *zDbSName;      /* Name of this database. (schema name, not filename) */
  1.3811    Btree *pBt;          /* The B*Tree structure for this database file */
  1.3812    u8 safety_level;     /* How aggressive at syncing data to disk */
  1.3813    u8 bSyncSet;         /* True if "PRAGMA synchronous=N" has been run */
  1.3814 @@ -13658,6 +14073,15 @@
  1.3815                                 const char*);
  1.3816  #endif
  1.3817  
  1.3818 +#ifndef SQLITE_OMIT_DEPRECATED
  1.3819 +/* This is an extra SQLITE_TRACE macro that indicates "legacy" tracing
  1.3820 +** in the style of sqlite3_trace()
  1.3821 +*/
  1.3822 +#define SQLITE_TRACE_LEGACY  0x80
  1.3823 +#else
  1.3824 +#define SQLITE_TRACE_LEGACY  0
  1.3825 +#endif /* SQLITE_OMIT_DEPRECATED */
  1.3826 +
  1.3827  
  1.3828  /*
  1.3829  ** Each database connection is an instance of the following structure.
  1.3830 @@ -13687,6 +14111,9 @@
  1.3831    u8 suppressErr;               /* Do not issue error messages if true */
  1.3832    u8 vtabOnConflict;            /* Value to return for s3_vtab_on_conflict() */
  1.3833    u8 isTransactionSavepoint;    /* True if the outermost savepoint is a TS */
  1.3834 +  u8 mTrace;                    /* zero or more SQLITE_TRACE flags */
  1.3835 +  u8 skipBtreeMutex;            /* True if no shared-cache backends */
  1.3836 +  u8 nSqlExec;                  /* Number of pending OP_SqlExec opcodes */
  1.3837    int nextPagesize;             /* Pagesize after VACUUM if >0 */
  1.3838    u32 magic;                    /* Magic number for detect library misuse */
  1.3839    int nChange;                  /* Value returned by sqlite3_changes() */
  1.3840 @@ -13707,7 +14134,7 @@
  1.3841    int nVDestroy;                /* Number of active OP_VDestroy operations */
  1.3842    int nExtension;               /* Number of loaded extensions */
  1.3843    void **aExtension;            /* Array of shared library handles */
  1.3844 -  void (*xTrace)(void*,const char*);        /* Trace function */
  1.3845 +  int (*xTrace)(u32,void*,void*,void*);     /* Trace function */
  1.3846    void *pTraceArg;                          /* Argument to the trace function */
  1.3847    void (*xProfile)(void*,const char*,u64);  /* Profiling function */
  1.3848    void *pProfileArg;                        /* Argument to profile function */
  1.3849 @@ -13834,6 +14261,7 @@
  1.3850  #define SQLITE_Vacuum         0x10000000  /* Currently in a VACUUM */
  1.3851  #define SQLITE_CellSizeCk     0x20000000  /* Check btree cell sizes on load */
  1.3852  #define SQLITE_Fts3Tokenizer  0x40000000  /* Enable fts3_tokenizer(2) */
  1.3853 +#define SQLITE_NoCkptOnClose  0x80000000  /* No checkpoint on close()/DETACH */
  1.3854  
  1.3855  
  1.3856  /*
  1.3857 @@ -13859,13 +14287,8 @@
  1.3858  /*
  1.3859  ** Macros for testing whether or not optimizations are enabled or disabled.
  1.3860  */
  1.3861 -#ifndef SQLITE_OMIT_BUILTIN_TEST
  1.3862  #define OptimizationDisabled(db, mask)  (((db)->dbOptFlags&(mask))!=0)
  1.3863  #define OptimizationEnabled(db, mask)   (((db)->dbOptFlags&(mask))==0)
  1.3864 -#else
  1.3865 -#define OptimizationDisabled(db, mask)  0
  1.3866 -#define OptimizationEnabled(db, mask)   1
  1.3867 -#endif
  1.3868  
  1.3869  /*
  1.3870  ** Return true if it OK to factor constant expressions into the initialization
  1.3871 @@ -13956,6 +14379,7 @@
  1.3872  #define SQLITE_FUNC_MINMAX   0x1000 /* True for min() and max() aggregates */
  1.3873  #define SQLITE_FUNC_SLOCHNG  0x2000 /* "Slow Change". Value constant during a
  1.3874                                      ** single query - might change over time */
  1.3875 +#define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
  1.3876  
  1.3877  /*
  1.3878  ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
  1.3879 @@ -14132,6 +14556,7 @@
  1.3880  ** operator is NULL.  It is added to certain comparison operators to
  1.3881  ** prove that the operands are always NOT NULL.
  1.3882  */
  1.3883 +#define SQLITE_KEEPNULL     0x08  /* Used by vector == or <> */
  1.3884  #define SQLITE_JUMPIFNULL   0x10  /* jumps if either operand is NULL */
  1.3885  #define SQLITE_STOREP2      0x20  /* Store result in reg[P2] rather than jump */
  1.3886  #define SQLITE_NULLEQ       0x80  /* NULL=NULL */
  1.3887 @@ -14203,15 +14628,15 @@
  1.3888    ExprList *pCheck;    /* All CHECK constraints */
  1.3889                         /*   ... also used as column name list in a VIEW */
  1.3890    int tnum;            /* Root BTree page for this table */
  1.3891 +  u32 nTabRef;         /* Number of pointers to this Table */
  1.3892 +  u32 tabFlags;        /* Mask of TF_* values */
  1.3893    i16 iPKey;           /* If not negative, use aCol[iPKey] as the rowid */
  1.3894    i16 nCol;            /* Number of columns in this table */
  1.3895 -  u16 nRef;            /* Number of pointers to this Table */
  1.3896    LogEst nRowLogEst;   /* Estimated rows in table - from sqlite_stat1 table */
  1.3897    LogEst szTabRow;     /* Estimated size of each table row in bytes */
  1.3898  #ifdef SQLITE_ENABLE_COSTMULT
  1.3899    LogEst costMult;     /* Cost multiplier for using this table */
  1.3900  #endif
  1.3901 -  u8 tabFlags;         /* Mask of TF_* values */
  1.3902    u8 keyConf;          /* What to do in case of uniqueness conflict on iPKey */
  1.3903  #ifndef SQLITE_OMIT_ALTERTABLE
  1.3904    int addColOffset;    /* Offset in CREATE TABLE stmt to add a new column */
  1.3905 @@ -14235,15 +14660,17 @@
  1.3906  ** the TF_OOOHidden attribute would apply in this case.  Such tables require
  1.3907  ** special handling during INSERT processing.
  1.3908  */
  1.3909 -#define TF_Readonly        0x01    /* Read-only system table */
  1.3910 -#define TF_Ephemeral       0x02    /* An ephemeral table */
  1.3911 -#define TF_HasPrimaryKey   0x04    /* Table has a primary key */
  1.3912 -#define TF_Autoincrement   0x08    /* Integer primary key is autoincrement */
  1.3913 -#define TF_Virtual         0x10    /* Is a virtual table */
  1.3914 -#define TF_WithoutRowid    0x20    /* No rowid.  PRIMARY KEY is the key */
  1.3915 -#define TF_NoVisibleRowid  0x40    /* No user-visible "rowid" column */
  1.3916 -#define TF_OOOHidden       0x80    /* Out-of-Order hidden columns */
  1.3917 -
  1.3918 +#define TF_Readonly        0x0001    /* Read-only system table */
  1.3919 +#define TF_Ephemeral       0x0002    /* An ephemeral table */
  1.3920 +#define TF_HasPrimaryKey   0x0004    /* Table has a primary key */
  1.3921 +#define TF_Autoincrement   0x0008    /* Integer primary key is autoincrement */
  1.3922 +#define TF_HasStat1        0x0010    /* nRowLogEst set from sqlite_stat1 */
  1.3923 +#define TF_WithoutRowid    0x0020    /* No rowid.  PRIMARY KEY is the key */
  1.3924 +#define TF_NoVisibleRowid  0x0040    /* No user-visible "rowid" column */
  1.3925 +#define TF_OOOHidden       0x0080    /* Out-of-Order hidden columns */
  1.3926 +#define TF_StatsUsed       0x0100    /* Query planner decisions affected by
  1.3927 +                                     ** Index.aiRowLogEst[] values */
  1.3928 +#define TF_HasNotNull      0x0200    /* Contains NOT NULL constraints */
  1.3929  
  1.3930  /*
  1.3931  ** Test to see whether or not a table is a virtual table.  This is
  1.3932 @@ -14251,7 +14678,7 @@
  1.3933  ** table support is omitted from the build.
  1.3934  */
  1.3935  #ifndef SQLITE_OMIT_VIRTUALTABLE
  1.3936 -#  define IsVirtual(X)      (((X)->tabFlags & TF_Virtual)!=0)
  1.3937 +#  define IsVirtual(X)      ((X)->nModuleArg)
  1.3938  #else
  1.3939  #  define IsVirtual(X)      0
  1.3940  #endif
  1.3941 @@ -14486,6 +14913,7 @@
  1.3942    unsigned isResized:1;    /* True if resizeIndexObject() has been called */
  1.3943    unsigned isCovering:1;   /* True if this is a covering index */
  1.3944    unsigned noSkipScan:1;   /* Do not try to use skip-scan if true */
  1.3945 +  unsigned hasStat1:1;     /* aiRowLogEst values come from sqlite_stat1 */
  1.3946  #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
  1.3947    int nSample;             /* Number of elements in aSample[] */
  1.3948    int nSampleCol;          /* Size of IndexSample.anEq[] and so on */
  1.3949 @@ -14696,9 +15124,11 @@
  1.3950    int iTable;            /* TK_COLUMN: cursor number of table holding column
  1.3951                           ** TK_REGISTER: register number
  1.3952                           ** TK_TRIGGER: 1 -> new, 0 -> old
  1.3953 -                         ** EP_Unlikely:  134217728 times likelihood */
  1.3954 +                         ** EP_Unlikely:  134217728 times likelihood
  1.3955 +                         ** TK_SELECT: 1st register of result vector */
  1.3956    ynVar iColumn;         /* TK_COLUMN: column index.  -1 for rowid.
  1.3957 -                         ** TK_VARIABLE: variable number (always >= 1). */
  1.3958 +                         ** TK_VARIABLE: variable number (always >= 1).
  1.3959 +                         ** TK_SELECT_COLUMN: column of the result vector */
  1.3960    i16 iAgg;              /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
  1.3961    i16 iRightJoinTable;   /* If EP_FromJoin, the right table of the join */
  1.3962    u8 op2;                /* TK_REGISTER: original value of Expr.op
  1.3963 @@ -14734,6 +15164,7 @@
  1.3964  #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
  1.3965  #define EP_Subquery  0x200000 /* Tree contains a TK_SELECT operator */
  1.3966  #define EP_Alias     0x400000 /* Is an alias for a result set column */
  1.3967 +#define EP_Leaf      0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
  1.3968  
  1.3969  /*
  1.3970  ** Combinations of two or more EP_* flags
  1.3971 @@ -14792,8 +15223,9 @@
  1.3972  */
  1.3973  struct ExprList {
  1.3974    int nExpr;             /* Number of expressions on the list */
  1.3975 +  int nAlloc;            /* Number of a[] slots allocated */
  1.3976    struct ExprList_item { /* For each expression in the list */
  1.3977 -    Expr *pExpr;            /* The list of expressions */
  1.3978 +    Expr *pExpr;            /* The parse tree for this expression */
  1.3979      char *zName;            /* Token associated with this expression */
  1.3980      char *zSpan;            /* Original text of the expression */
  1.3981      u8 sortOrder;           /* 1 for DESC or 0 for ASC */
  1.3982 @@ -14807,7 +15239,7 @@
  1.3983        } x;
  1.3984        int iConstExprReg;      /* Register in which Expr value is cached */
  1.3985      } u;
  1.3986 -  } *a;                  /* Alloc a power of two greater or equal to nExpr */
  1.3987 +  } a[1];                  /* One slot for each expression in the list */
  1.3988  };
  1.3989  
  1.3990  /*
  1.3991 @@ -14902,7 +15334,7 @@
  1.3992      int regReturn;    /* Register holding return address of addrFillSub */
  1.3993      int regResult;    /* Registers holding results of a co-routine */
  1.3994      struct {
  1.3995 -      u8 jointype;      /* Type of join between this able and the previous */
  1.3996 +      u8 jointype;      /* Type of join between this table and the previous */
  1.3997        unsigned notIndexed :1;    /* True if there is a NOT INDEXED clause */
  1.3998        unsigned isIndexedBy :1;   /* True if there is an INDEXED BY clause */
  1.3999        unsigned isTabFunc :1;     /* True if table-valued-function syntax */
  1.4000 @@ -14948,19 +15380,20 @@
  1.4001  #define WHERE_ORDERBY_MIN      0x0001 /* ORDER BY processing for min() func */
  1.4002  #define WHERE_ORDERBY_MAX      0x0002 /* ORDER BY processing for max() func */
  1.4003  #define WHERE_ONEPASS_DESIRED  0x0004 /* Want to do one-pass UPDATE/DELETE */
  1.4004 -#define WHERE_DUPLICATES_OK    0x0008 /* Ok to return a row more than once */
  1.4005 -#define WHERE_OMIT_OPEN_CLOSE  0x0010 /* Table cursors are already open */
  1.4006 -#define WHERE_FORCE_TABLE      0x0020 /* Do not use an index-only search */
  1.4007 -#define WHERE_ONETABLE_ONLY    0x0040 /* Only code the 1st table in pTabList */
  1.4008 -#define WHERE_NO_AUTOINDEX     0x0080 /* Disallow automatic indexes */
  1.4009 -#define WHERE_GROUPBY          0x0100 /* pOrderBy is really a GROUP BY */
  1.4010 -#define WHERE_DISTINCTBY       0x0200 /* pOrderby is really a DISTINCT clause */
  1.4011 -#define WHERE_WANT_DISTINCT    0x0400 /* All output needs to be distinct */
  1.4012 -#define WHERE_SORTBYGROUP      0x0800 /* Support sqlite3WhereIsSorted() */
  1.4013 -#define WHERE_REOPEN_IDX       0x1000 /* Try to use OP_ReopenIdx */
  1.4014 -#define WHERE_ONEPASS_MULTIROW 0x2000 /* ONEPASS is ok with multiple rows */
  1.4015 -#define WHERE_USE_LIMIT        0x4000 /* There is a constant LIMIT clause */
  1.4016 -#define WHERE_SEEK_TABLE       0x8000 /* Do not defer seeks on main table */
  1.4017 +#define WHERE_ONEPASS_MULTIROW 0x0008 /* ONEPASS is ok with multiple rows */
  1.4018 +#define WHERE_DUPLICATES_OK    0x0010 /* Ok to return a row more than once */
  1.4019 +#define WHERE_OR_SUBCLAUSE     0x0020 /* Processing a sub-WHERE as part of
  1.4020 +                                      ** the OR optimization  */
  1.4021 +#define WHERE_GROUPBY          0x0040 /* pOrderBy is really a GROUP BY */
  1.4022 +#define WHERE_DISTINCTBY       0x0080 /* pOrderby is really a DISTINCT clause */
  1.4023 +#define WHERE_WANT_DISTINCT    0x0100 /* All output needs to be distinct */
  1.4024 +#define WHERE_SORTBYGROUP      0x0200 /* Support sqlite3WhereIsSorted() */
  1.4025 +#define WHERE_SEEK_TABLE       0x0400 /* Do not defer seeks on main table */
  1.4026 +#define WHERE_ORDERBY_LIMIT    0x0800 /* ORDERBY+LIMIT on the inner loop */
  1.4027 +#define WHERE_SEEK_UNIQ_TABLE  0x1000 /* Do not defer seeks if unique */
  1.4028 +                        /*     0x2000    not currently used */
  1.4029 +#define WHERE_USE_LIMIT        0x4000 /* Use the LIMIT in cost estimates */
  1.4030 +                        /*     0x8000    not currently used */
  1.4031  
  1.4032  /* Allowed return values from sqlite3WhereIsDistinct()
  1.4033  */
  1.4034 @@ -15178,7 +15611,7 @@
  1.4035  */
  1.4036  struct SelectDest {
  1.4037    u8 eDest;            /* How to dispose of the results.  On of SRT_* above. */
  1.4038 -  char affSdst;        /* Affinity used when eDest==SRT_Set */
  1.4039 +  char *zAffSdst;      /* Affinity used when eDest==SRT_Set */
  1.4040    int iSDParm;         /* A parameter used by the eDest disposal method */
  1.4041    int iSdst;           /* Base register where results are written */
  1.4042    int nSdst;           /* Number of registers allocated */
  1.4043 @@ -15284,36 +15717,23 @@
  1.4044    u8 okConstFactor;    /* OK to factor out constants */
  1.4045    u8 disableLookaside; /* Number of times lookaside has been disabled */
  1.4046    u8 nColCache;        /* Number of entries in aColCache[] */
  1.4047 -  int aTempReg[8];     /* Holding area for temporary registers */
  1.4048    int nRangeReg;       /* Size of the temporary register block */
  1.4049    int iRangeReg;       /* First register in temporary register block */
  1.4050    int nErr;            /* Number of errors seen */
  1.4051    int nTab;            /* Number of previously allocated VDBE cursors */
  1.4052    int nMem;            /* Number of memory cells used so far */
  1.4053 -  int nSet;            /* Number of sets used so far */
  1.4054 -  int nOnce;           /* Number of OP_Once instructions so far */
  1.4055    int nOpAlloc;        /* Number of slots allocated for Vdbe.aOp[] */
  1.4056    int szOpAlloc;       /* Bytes of memory space allocated for Vdbe.aOp[] */
  1.4057 -  int iFixedOp;        /* Never back out opcodes iFixedOp-1 or earlier */
  1.4058    int ckBase;          /* Base register of data during check constraints */
  1.4059    int iSelfTab;        /* Table of an index whose exprs are being coded */
  1.4060    int iCacheLevel;     /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
  1.4061    int iCacheCnt;       /* Counter used to generate aColCache[].lru values */
  1.4062    int nLabel;          /* Number of labels used */
  1.4063    int *aLabel;         /* Space to hold the labels */
  1.4064 -  struct yColCache {
  1.4065 -    int iTable;           /* Table cursor number */
  1.4066 -    i16 iColumn;          /* Table column number */
  1.4067 -    u8 tempReg;           /* iReg is a temp register that needs to be freed */
  1.4068 -    int iLevel;           /* Nesting level */
  1.4069 -    int iReg;             /* Reg with value of this column. 0 means none. */
  1.4070 -    int lru;              /* Least recently used entry has the smallest value */
  1.4071 -  } aColCache[SQLITE_N_COLCACHE];  /* One for each column cache entry */
  1.4072    ExprList *pConstExpr;/* Constant expressions */
  1.4073    Token constraintName;/* Name of the constraint currently being parsed */
  1.4074    yDbMask writeMask;   /* Start a write transaction on these databases */
  1.4075    yDbMask cookieMask;  /* Bitmask of schema verified databases */
  1.4076 -  int cookieValue[SQLITE_MAX_ATTACHED+2];  /* Values of cookies to verify */
  1.4077    int regRowid;        /* Register holding rowid of CREATE TABLE entry */
  1.4078    int regRoot;         /* Register holding root page number for new objects */
  1.4079    int nMaxArg;         /* Max args passed to user function by sub-program */
  1.4080 @@ -15326,8 +15746,6 @@
  1.4081    TableLock *aTableLock; /* Required table locks for shared-cache mode */
  1.4082  #endif
  1.4083    AutoincInfo *pAinc;  /* Information about AUTOINCREMENT counters */
  1.4084 -
  1.4085 -  /* Information used while coding trigger programs. */
  1.4086    Parse *pToplevel;    /* Parse structure for main program (or NULL) */
  1.4087    Table *pTriggerTab;  /* Table triggers are being coded for */
  1.4088    int addrCrTab;       /* Address of OP_CreateTable opcode on CREATE TABLE */
  1.4089 @@ -15338,35 +15756,50 @@
  1.4090    u8 eOrconf;          /* Default ON CONFLICT policy for trigger steps */
  1.4091    u8 disableTriggers;  /* True to disable triggers */
  1.4092  
  1.4093 +  /**************************************************************************
  1.4094 +  ** Fields above must be initialized to zero.  The fields that follow,
  1.4095 +  ** down to the beginning of the recursive section, do not need to be
  1.4096 +  ** initialized as they will be set before being used.  The boundary is
  1.4097 +  ** determined by offsetof(Parse,aColCache).
  1.4098 +  **************************************************************************/
  1.4099 +
  1.4100 +  struct yColCache {
  1.4101 +    int iTable;           /* Table cursor number */
  1.4102 +    i16 iColumn;          /* Table column number */
  1.4103 +    u8 tempReg;           /* iReg is a temp register that needs to be freed */
  1.4104 +    int iLevel;           /* Nesting level */
  1.4105 +    int iReg;             /* Reg with value of this column. 0 means none. */
  1.4106 +    int lru;              /* Least recently used entry has the smallest value */
  1.4107 +  } aColCache[SQLITE_N_COLCACHE];  /* One for each column cache entry */
  1.4108 +  int aTempReg[8];        /* Holding area for temporary registers */
  1.4109 +  Token sNameToken;       /* Token with unqualified schema object name */
  1.4110 +
  1.4111    /************************************************************************
  1.4112    ** Above is constant between recursions.  Below is reset before and after
  1.4113    ** each recursion.  The boundary between these two regions is determined
  1.4114 -  ** using offsetof(Parse,nVar) so the nVar field must be the first field
  1.4115 -  ** in the recursive region.
  1.4116 +  ** using offsetof(Parse,sLastToken) so the sLastToken field must be the
  1.4117 +  ** first field in the recursive region.
  1.4118    ************************************************************************/
  1.4119  
  1.4120 +  Token sLastToken;       /* The last token parsed */
  1.4121    ynVar nVar;               /* Number of '?' variables seen in the SQL so far */
  1.4122 -  int nzVar;                /* Number of available slots in azVar[] */
  1.4123    u8 iPkSortOrder;          /* ASC or DESC for INTEGER PRIMARY KEY */
  1.4124    u8 explain;               /* True if the EXPLAIN flag is found on the query */
  1.4125  #ifndef SQLITE_OMIT_VIRTUALTABLE
  1.4126    u8 declareVtab;           /* True if inside sqlite3_declare_vtab() */
  1.4127    int nVtabLock;            /* Number of virtual tables to lock */
  1.4128  #endif
  1.4129 -  int nAlias;               /* Number of aliased result set columns */
  1.4130    int nHeight;              /* Expression tree height of current sub-select */
  1.4131  #ifndef SQLITE_OMIT_EXPLAIN
  1.4132    int iSelectId;            /* ID of current select for EXPLAIN output */
  1.4133    int iNextSelectId;        /* Next available select ID for EXPLAIN output */
  1.4134  #endif
  1.4135 -  char **azVar;             /* Pointers to names of parameters */
  1.4136 +  VList *pVList;            /* Mapping between variable names and numbers */
  1.4137    Vdbe *pReprepare;         /* VM being reprepared (sqlite3Reprepare()) */
  1.4138    const char *zTail;        /* All SQL text past the last semicolon parsed */
  1.4139    Table *pNewTable;         /* A table being constructed by CREATE TABLE */
  1.4140    Trigger *pNewTrigger;     /* Trigger under construct by a CREATE TRIGGER */
  1.4141    const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
  1.4142 -  Token sNameToken;         /* Token with unqualified schema object name */
  1.4143 -  Token sLastToken;         /* The last token parsed */
  1.4144  #ifndef SQLITE_OMIT_VIRTUALTABLE
  1.4145    Token sArg;               /* Complete text of a module argument */
  1.4146    Table **apVtabLock;       /* Pointer to virtual tables needing locking */
  1.4147 @@ -15378,6 +15811,14 @@
  1.4148  };
  1.4149  
  1.4150  /*
  1.4151 +** Sizes and pointers of various parts of the Parse object.
  1.4152 +*/
  1.4153 +#define PARSE_HDR_SZ offsetof(Parse,aColCache) /* Recursive part w/o aColCache*/
  1.4154 +#define PARSE_RECURSE_SZ offsetof(Parse,sLastToken)    /* Recursive part */
  1.4155 +#define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */
  1.4156 +#define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ)  /* Pointer to tail */
  1.4157 +
  1.4158 +/*
  1.4159  ** Return true if currently inside an sqlite3_declare_vtab() call.
  1.4160  */
  1.4161  #ifdef SQLITE_OMIT_VIRTUALTABLE
  1.4162 @@ -15410,13 +15851,11 @@
  1.4163  #define OPFLAG_NCHANGE       0x01    /* OP_Insert: Set to update db->nChange */
  1.4164                                       /* Also used in P2 (not P5) of OP_Delete */
  1.4165  #define OPFLAG_EPHEM         0x01    /* OP_Column: Ephemeral output is ok */
  1.4166 -#define OPFLAG_LASTROWID     0x02    /* Set to update db->lastRowid */
  1.4167 +#define OPFLAG_LASTROWID     0x20    /* Set to update db->lastRowid */
  1.4168  #define OPFLAG_ISUPDATE      0x04    /* This OP_Insert is an sql UPDATE */
  1.4169  #define OPFLAG_APPEND        0x08    /* This is likely to be an append */
  1.4170  #define OPFLAG_USESEEKRESULT 0x10    /* Try to avoid a seek in BtreeInsert() */
  1.4171 -#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
  1.4172  #define OPFLAG_ISNOOP        0x40    /* OP_Delete does pre-update-hook only */
  1.4173 -#endif
  1.4174  #define OPFLAG_LENGTHARG     0x40    /* OP_Column only used for length() */
  1.4175  #define OPFLAG_TYPEOFARG     0x80    /* OP_Column only used for typeof() */
  1.4176  #define OPFLAG_BULKCSR       0x01    /* OP_Open** used to open bulk cursor */
  1.4177 @@ -15424,7 +15863,7 @@
  1.4178  #define OPFLAG_FORDELETE     0x08    /* OP_Open should use BTREE_FORDELETE */
  1.4179  #define OPFLAG_P2ISREG       0x10    /* P2 to OP_Open** is a register number */
  1.4180  #define OPFLAG_PERMUTE       0x01    /* OP_Compare: use the permutation */
  1.4181 -#define OPFLAG_SAVEPOSITION  0x02    /* OP_Delete: keep cursor position */
  1.4182 +#define OPFLAG_SAVEPOSITION  0x02    /* OP_Delete/Insert: save cursor pos */
  1.4183  #define OPFLAG_AUXDELETE     0x04    /* OP_Delete: index in a DELETE op */
  1.4184  
  1.4185  /*
  1.4186 @@ -15621,10 +16060,11 @@
  1.4187    void (*xVdbeBranch)(void*,int iSrcLine,u8 eThis,u8 eMx);  /* Callback */
  1.4188    void *pVdbeBranchArg;                                     /* 1st argument */
  1.4189  #endif
  1.4190 -#ifndef SQLITE_OMIT_BUILTIN_TEST
  1.4191 +#ifndef SQLITE_UNTESTABLE
  1.4192    int (*xTestCallback)(int);        /* Invoked by sqlite3FaultSim() */
  1.4193  #endif
  1.4194    int bLocaltimeFault;              /* True to fail localtime() calls */
  1.4195 +  int iOnceResetThreshold;          /* When to reset OP_Once counters */
  1.4196  };
  1.4197  
  1.4198  /*
  1.4199 @@ -15656,13 +16096,17 @@
  1.4200    int walkerDepth;                          /* Number of subqueries */
  1.4201    u8 eCode;                                 /* A small processing code */
  1.4202    union {                                   /* Extra data for callback */
  1.4203 -    NameContext *pNC;                          /* Naming context */
  1.4204 -    int n;                                     /* A counter */
  1.4205 -    int iCur;                                  /* A cursor number */
  1.4206 -    SrcList *pSrcList;                         /* FROM clause */
  1.4207 -    struct SrcCount *pSrcCount;                /* Counting column references */
  1.4208 -    struct CCurHint *pCCurHint;                /* Used by codeCursorHint() */
  1.4209 -    int *aiCol;                                /* array of column indexes */
  1.4210 +    NameContext *pNC;                         /* Naming context */
  1.4211 +    int n;                                    /* A counter */
  1.4212 +    int iCur;                                 /* A cursor number */
  1.4213 +    SrcList *pSrcList;                        /* FROM clause */
  1.4214 +    struct SrcCount *pSrcCount;               /* Counting column references */
  1.4215 +    struct CCurHint *pCCurHint;               /* Used by codeCursorHint() */
  1.4216 +    int *aiCol;                               /* array of column indexes */
  1.4217 +    struct IdxCover *pIdxCover;               /* Check for index coverage */
  1.4218 +    struct IdxExprTrans *pIdxTrans;           /* Convert indexed expr to column */
  1.4219 +    ExprList *pGroupBy;                       /* GROUP BY clause */
  1.4220 +    struct HavingToWhereCtx *pHavingCtx;      /* HAVING to WHERE clause ctx */
  1.4221    } u;
  1.4222  };
  1.4223  
  1.4224 @@ -15816,6 +16260,7 @@
  1.4225  SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
  1.4226  SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
  1.4227  SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
  1.4228 +SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
  1.4229  SQLITE_PRIVATE int sqlite3MallocSize(void*);
  1.4230  SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*);
  1.4231  SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
  1.4232 @@ -15823,7 +16268,7 @@
  1.4233  SQLITE_PRIVATE void *sqlite3PageMalloc(int);
  1.4234  SQLITE_PRIVATE void sqlite3PageFree(void*);
  1.4235  SQLITE_PRIVATE void sqlite3MemSetDefault(void);
  1.4236 -#ifndef SQLITE_OMIT_BUILTIN_TEST
  1.4237 +#ifndef SQLITE_UNTESTABLE
  1.4238  SQLITE_PRIVATE void sqlite3BenignMallocHooks(void (*)(void), void (*)(void));
  1.4239  #endif
  1.4240  SQLITE_PRIVATE int sqlite3HeapNearlyFull(void);
  1.4241 @@ -15846,12 +16291,16 @@
  1.4242  # define sqlite3StackFree(D,P)       sqlite3DbFree(D,P)
  1.4243  #endif
  1.4244  
  1.4245 +/* Do not allow both MEMSYS5 and MEMSYS3 to be defined together.  If they
  1.4246 +** are, disable MEMSYS3
  1.4247 +*/
  1.4248 +#ifdef SQLITE_ENABLE_MEMSYS5
  1.4249 +SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
  1.4250 +#undef SQLITE_ENABLE_MEMSYS3
  1.4251 +#endif
  1.4252  #ifdef SQLITE_ENABLE_MEMSYS3
  1.4253  SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetMemsys3(void);
  1.4254  #endif
  1.4255 -#ifdef SQLITE_ENABLE_MEMSYS5
  1.4256 -SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
  1.4257 -#endif
  1.4258  
  1.4259  
  1.4260  #ifndef SQLITE_MUTEX_OMIT
  1.4261 @@ -15905,6 +16354,7 @@
  1.4262  
  1.4263  #if defined(SQLITE_DEBUG)
  1.4264  SQLITE_PRIVATE   void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
  1.4265 +SQLITE_PRIVATE   void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*);
  1.4266  SQLITE_PRIVATE   void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*);
  1.4267  SQLITE_PRIVATE   void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
  1.4268  SQLITE_PRIVATE   void sqlite3TreeViewWith(TreeView*, const With*, u8);
  1.4269 @@ -15929,13 +16379,14 @@
  1.4270  SQLITE_PRIVATE Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int);
  1.4271  SQLITE_PRIVATE Expr *sqlite3Expr(sqlite3*,int,const char*);
  1.4272  SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
  1.4273 -SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
  1.4274 +SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*);
  1.4275  SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*);
  1.4276  SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
  1.4277  SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
  1.4278 -SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*);
  1.4279 +SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
  1.4280  SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
  1.4281  SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
  1.4282 +SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*);
  1.4283  SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int);
  1.4284  SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
  1.4285  SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
  1.4286 @@ -15944,6 +16395,9 @@
  1.4287  SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
  1.4288  SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
  1.4289  SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
  1.4290 +#ifndef SQLITE_OMIT_VIRTUALTABLE
  1.4291 +SQLITE_PRIVATE Module *sqlite3PragmaVtabRegister(sqlite3*,const char *zName);
  1.4292 +#endif
  1.4293  SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*);
  1.4294  SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
  1.4295  SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
  1.4296 @@ -15971,9 +16425,8 @@
  1.4297  SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
  1.4298                      sqlite3_vfs**,char**,char **);
  1.4299  SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*);
  1.4300 -SQLITE_PRIVATE int sqlite3CodeOnce(Parse *);
  1.4301 -
  1.4302 -#ifdef SQLITE_OMIT_BUILTIN_TEST
  1.4303 +
  1.4304 +#ifdef SQLITE_UNTESTABLE
  1.4305  # define sqlite3FaultSim(X) SQLITE_OK
  1.4306  #else
  1.4307  SQLITE_PRIVATE   int sqlite3FaultSim(int);
  1.4308 @@ -15986,7 +16439,7 @@
  1.4309  SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec*, u32, void*);
  1.4310  SQLITE_PRIVATE void sqlite3BitvecDestroy(Bitvec*);
  1.4311  SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec*);
  1.4312 -#ifndef SQLITE_OMIT_BUILTIN_TEST
  1.4313 +#ifndef SQLITE_UNTESTABLE
  1.4314  SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int,int*);
  1.4315  #endif
  1.4316  
  1.4317 @@ -16033,8 +16486,8 @@
  1.4318  SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*);
  1.4319  SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*);
  1.4320  SQLITE_PRIVATE Index *sqlite3AllocateIndexObject(sqlite3*,i16,int,char**);
  1.4321 -SQLITE_PRIVATE Index *sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
  1.4322 -                          Expr*, int, int);
  1.4323 +SQLITE_PRIVATE void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
  1.4324 +                          Expr*, int, int, u8);
  1.4325  SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
  1.4326  SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
  1.4327  SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
  1.4328 @@ -16053,6 +16506,7 @@
  1.4329  SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo*);
  1.4330  SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*);
  1.4331  SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
  1.4332 +SQLITE_PRIVATE int sqlite3WhereOrderedInnerLoop(WhereInfo*);
  1.4333  SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo*);
  1.4334  SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*);
  1.4335  SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*);
  1.4336 @@ -16074,7 +16528,7 @@
  1.4337  SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
  1.4338  SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int);
  1.4339  SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
  1.4340 -SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
  1.4341 +SQLITE_PRIVATE int sqlite3ExprCodeAtInit(Parse*, Expr*, int);
  1.4342  SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
  1.4343  SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
  1.4344  SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
  1.4345 @@ -16082,26 +16536,31 @@
  1.4346  #define SQLITE_ECEL_DUP      0x01  /* Deep, not shallow copies */
  1.4347  #define SQLITE_ECEL_FACTOR   0x02  /* Factor out constant terms */
  1.4348  #define SQLITE_ECEL_REF      0x04  /* Use ExprList.u.x.iOrderByCol */
  1.4349 +#define SQLITE_ECEL_OMITREF  0x08  /* Omit if ExprList.u.x.iOrderByCol */
  1.4350  SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
  1.4351  SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
  1.4352  SQLITE_PRIVATE void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int);
  1.4353  SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
  1.4354 -SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
  1.4355 -SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *);
  1.4356 +#define LOCATE_VIEW    0x01
  1.4357 +#define LOCATE_NOERR   0x02
  1.4358 +SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,u32 flags,const char*, const char*);
  1.4359 +SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,u32 flags,struct SrcList_item *);
  1.4360  SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
  1.4361  SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
  1.4362  SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
  1.4363 -SQLITE_PRIVATE void sqlite3Vacuum(Parse*);
  1.4364 -SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*);
  1.4365 +SQLITE_PRIVATE void sqlite3Vacuum(Parse*,Token*);
  1.4366 +SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*, int);
  1.4367  SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
  1.4368  SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*, int);
  1.4369 +SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*, Expr*, int);
  1.4370  SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
  1.4371  SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Expr*, Expr*, int);
  1.4372  SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
  1.4373  SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
  1.4374 +SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
  1.4375  SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
  1.4376  SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
  1.4377 -#ifndef SQLITE_OMIT_BUILTIN_TEST
  1.4378 +#ifndef SQLITE_UNTESTABLE
  1.4379  SQLITE_PRIVATE void sqlite3PrngSaveState(void);
  1.4380  SQLITE_PRIVATE void sqlite3PrngRestoreState(void);
  1.4381  #endif
  1.4382 @@ -16117,6 +16576,7 @@
  1.4383  SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
  1.4384  SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
  1.4385  SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
  1.4386 +SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
  1.4387  SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
  1.4388  #ifdef SQLITE_ENABLE_CURSOR_HINTS
  1.4389  SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
  1.4390 @@ -16132,6 +16592,11 @@
  1.4391  SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel(Parse*,int);
  1.4392  SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
  1.4393                                       u8,u8,int,int*,int*);
  1.4394 +#ifdef SQLITE_ENABLE_NULL_TRIM
  1.4395 +SQLITE_PRIVATE   void sqlite3SetMakeRecordP5(Vdbe*,Table*);
  1.4396 +#else
  1.4397 +# define sqlite3SetMakeRecordP5(A,B)
  1.4398 +#endif
  1.4399  SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int);
  1.4400  SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, u8, int, u8*, int*, int*);
  1.4401  SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int);
  1.4402 @@ -16238,6 +16703,9 @@
  1.4403      defined(SQLITE_EXPLAIN_ESTIMATED_ROWS)
  1.4404  SQLITE_PRIVATE u64 sqlite3LogEstToInt(LogEst);
  1.4405  #endif
  1.4406 +SQLITE_PRIVATE VList *sqlite3VListAdd(sqlite3*,VList*,const char*,int,int);
  1.4407 +SQLITE_PRIVATE const char *sqlite3VListNumToName(VList*,int);
  1.4408 +SQLITE_PRIVATE int sqlite3VListNameToNum(VList*,const char*,int);
  1.4409  
  1.4410  /*
  1.4411  ** Routines to read and write variable-length integers.  These used to
  1.4412 @@ -16267,6 +16735,7 @@
  1.4413  SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
  1.4414  SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
  1.4415  SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
  1.4416 +SQLITE_PRIVATE char sqlite3TableColumnAffinity(Table*,int);
  1.4417  SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
  1.4418  SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
  1.4419  SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char*, i64*);
  1.4420 @@ -16332,7 +16801,7 @@
  1.4421  SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *);
  1.4422  SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
  1.4423  SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*);
  1.4424 -SQLITE_PRIVATE int sqlite3CodeSubselect(Parse *, Expr *, int, int);
  1.4425 +SQLITE_PRIVATE int sqlite3CodeSubselect(Parse*, Expr *, int, int);
  1.4426  SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
  1.4427  SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
  1.4428  SQLITE_PRIVATE int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
  1.4429 @@ -16387,19 +16856,29 @@
  1.4430  SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *);
  1.4431  SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *);
  1.4432  
  1.4433 +#ifndef SQLITE_OMIT_SUBQUERY
  1.4434 +SQLITE_PRIVATE int sqlite3ExprCheckIN(Parse*, Expr*);
  1.4435 +#else
  1.4436 +# define sqlite3ExprCheckIN(x,y) SQLITE_OK
  1.4437 +#endif
  1.4438 +
  1.4439  #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
  1.4440  SQLITE_PRIVATE void sqlite3AnalyzeFunctions(void);
  1.4441 -SQLITE_PRIVATE int sqlite3Stat4ProbeSetValue(Parse*,Index*,UnpackedRecord**,Expr*,u8,int,int*);
  1.4442 +SQLITE_PRIVATE int sqlite3Stat4ProbeSetValue(
  1.4443 +    Parse*,Index*,UnpackedRecord**,Expr*,int,int,int*);
  1.4444  SQLITE_PRIVATE int sqlite3Stat4ValueFromExpr(Parse*, Expr*, u8, sqlite3_value**);
  1.4445  SQLITE_PRIVATE void sqlite3Stat4ProbeFree(UnpackedRecord*);
  1.4446  SQLITE_PRIVATE int sqlite3Stat4Column(sqlite3*, const void*, int, int, sqlite3_value**);
  1.4447 +SQLITE_PRIVATE char sqlite3IndexColumnAffinity(sqlite3*, Index*, int);
  1.4448  #endif
  1.4449  
  1.4450  /*
  1.4451  ** The interface to the LEMON-generated parser
  1.4452  */
  1.4453 -SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(u64));
  1.4454 -SQLITE_PRIVATE void sqlite3ParserFree(void*, void(*)(void*));
  1.4455 +#ifndef SQLITE_AMALGAMATION
  1.4456 +SQLITE_PRIVATE   void *sqlite3ParserAlloc(void*(*)(u64));
  1.4457 +SQLITE_PRIVATE   void sqlite3ParserFree(void*, void(*)(void*));
  1.4458 +#endif
  1.4459  SQLITE_PRIVATE void sqlite3Parser(void*, int, Token, Parse*);
  1.4460  #ifdef YYTRACKMAXSTACKDEPTH
  1.4461  SQLITE_PRIVATE   int sqlite3ParserStackPeak(void*);
  1.4462 @@ -16445,6 +16924,13 @@
  1.4463  SQLITE_PRIVATE    int sqlite3VtabSavepoint(sqlite3 *, int, int);
  1.4464  SQLITE_PRIVATE    void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*);
  1.4465  SQLITE_PRIVATE    VTable *sqlite3GetVTable(sqlite3*, Table*);
  1.4466 +SQLITE_PRIVATE    Module *sqlite3VtabCreateModule(
  1.4467 +     sqlite3*,
  1.4468 +     const char*,
  1.4469 +     const sqlite3_module*,
  1.4470 +     void*,
  1.4471 +     void(*)(void*)
  1.4472 +   );
  1.4473  #  define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
  1.4474  #endif
  1.4475  SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*);
  1.4476 @@ -16502,6 +16988,7 @@
  1.4477    #define sqlite3FkDropTable(a,b,c)
  1.4478    #define sqlite3FkOldmask(a,b)         0
  1.4479    #define sqlite3FkRequired(a,b,c,d)    0
  1.4480 +  #define sqlite3FkReferences(a)        0
  1.4481  #endif
  1.4482  #ifndef SQLITE_OMIT_FOREIGN_KEY
  1.4483  SQLITE_PRIVATE   void sqlite3FkDelete(sqlite3 *, Table*);
  1.4484 @@ -16520,10 +17007,10 @@
  1.4485  
  1.4486  /*
  1.4487  ** The interface to the code in fault.c used for identifying "benign"
  1.4488 -** malloc failures. This is only present if SQLITE_OMIT_BUILTIN_TEST
  1.4489 +** malloc failures. This is only present if SQLITE_UNTESTABLE
  1.4490  ** is not defined.
  1.4491  */
  1.4492 -#ifndef SQLITE_OMIT_BUILTIN_TEST
  1.4493 +#ifndef SQLITE_UNTESTABLE
  1.4494  SQLITE_PRIVATE   void sqlite3BeginBenignMalloc(void);
  1.4495  SQLITE_PRIVATE   void sqlite3EndBenignMalloc(void);
  1.4496  #else
  1.4497 @@ -16545,7 +17032,7 @@
  1.4498  #define IN_INDEX_NOOP_OK     0x0001  /* OK to return IN_INDEX_NOOP */
  1.4499  #define IN_INDEX_MEMBERSHIP  0x0002  /* IN operator used for membership test */
  1.4500  #define IN_INDEX_LOOP        0x0004  /* IN operator used as a loop */
  1.4501 -SQLITE_PRIVATE int sqlite3FindInIndex(Parse *, Expr *, u32, int*);
  1.4502 +SQLITE_PRIVATE int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*);
  1.4503  
  1.4504  SQLITE_PRIVATE int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
  1.4505  SQLITE_PRIVATE int sqlite3JournalSize(sqlite3_vfs *);
  1.4506 @@ -16650,7 +17137,13 @@
  1.4507  SQLITE_PRIVATE int sqlite3DbstatRegister(sqlite3*);
  1.4508  #endif
  1.4509  
  1.4510 -#endif /* _SQLITEINT_H_ */
  1.4511 +SQLITE_PRIVATE int sqlite3ExprVectorSize(Expr *pExpr);
  1.4512 +SQLITE_PRIVATE int sqlite3ExprIsVector(Expr *pExpr);
  1.4513 +SQLITE_PRIVATE Expr *sqlite3VectorFieldSubexpr(Expr*, int);
  1.4514 +SQLITE_PRIVATE Expr *sqlite3ExprForVectorField(Parse*,Expr*,int);
  1.4515 +SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse*, Expr*);
  1.4516 +
  1.4517 +#endif /* SQLITEINT_H */
  1.4518  
  1.4519  /************** End of sqliteInt.h *******************************************/
  1.4520  /************** Begin file global.c ******************************************/
  1.4521 @@ -16735,16 +17228,13 @@
  1.4522  **
  1.4523  **   (x & ~(map[x]&0x20))
  1.4524  **
  1.4525 -** Standard function tolower() is implemented using the sqlite3UpperToLower[]
  1.4526 +** The equivalent of tolower() is implemented using the sqlite3UpperToLower[]
  1.4527  ** array. tolower() is used more often than toupper() by SQLite.
  1.4528  **
  1.4529 -** Bit 0x40 is set if the character non-alphanumeric and can be used in an 
  1.4530 +** Bit 0x40 is set if the character is non-alphanumeric and can be used in an 
  1.4531  ** SQLite identifier.  Identifiers are alphanumerics, "_", "$", and any
  1.4532  ** non-ASCII UTF character. Hence the test for whether or not a character is
  1.4533  ** part of an identifier is 0x46.
  1.4534 -**
  1.4535 -** SQLite's versions are identical to the standard versions assuming a
  1.4536 -** locale of "C". They are implemented as macros in sqliteInt.h.
  1.4537  */
  1.4538  #ifdef SQLITE_ASCII
  1.4539  SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256] = {
  1.4540 @@ -16796,9 +17286,16 @@
  1.4541  ** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally
  1.4542  ** disabled. The default value may be changed by compiling with the
  1.4543  ** SQLITE_USE_URI symbol defined.
  1.4544 +**
  1.4545 +** URI filenames are enabled by default if SQLITE_HAS_CODEC is
  1.4546 +** enabled.
  1.4547  */
  1.4548  #ifndef SQLITE_USE_URI
  1.4549 -# define  SQLITE_USE_URI 0
  1.4550 +# ifdef SQLITE_HAS_CODEC
  1.4551 +#  define SQLITE_USE_URI 1
  1.4552 +# else
  1.4553 +#  define SQLITE_USE_URI 0
  1.4554 +# endif
  1.4555  #endif
  1.4556  
  1.4557  /* EVIDENCE-OF: R-38720-18127 The default setting is determined by the
  1.4558 @@ -16817,7 +17314,7 @@
  1.4559  #endif
  1.4560  
  1.4561  /* Statement journals spill to disk when their size exceeds the following
  1.4562 -** threashold (in bytes). 0 means that statement journals are created and
  1.4563 +** threshold (in bytes). 0 means that statement journals are created and
  1.4564  ** written to disk immediately (the default behavior for SQLite versions
  1.4565  ** before 3.12.0).  -1 means always keep the entire statement journal in
  1.4566  ** memory.  (The statement journal is also always held entirely in memory
  1.4567 @@ -16829,6 +17326,19 @@
  1.4568  #endif
  1.4569  
  1.4570  /*
  1.4571 +** The default lookaside-configuration, the format "SZ,N".  SZ is the
  1.4572 +** number of bytes in each lookaside slot (should be a multiple of 8)
  1.4573 +** and N is the number of slots.  The lookaside-configuration can be
  1.4574 +** changed as start-time using sqlite3_config(SQLITE_CONFIG_LOOKASIDE)
  1.4575 +** or at run-time for an individual database connection using
  1.4576 +** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE);
  1.4577 +*/
  1.4578 +#ifndef SQLITE_DEFAULT_LOOKASIDE
  1.4579 +# define SQLITE_DEFAULT_LOOKASIDE 1200,100
  1.4580 +#endif
  1.4581 +
  1.4582 +
  1.4583 +/*
  1.4584  ** The following singleton contains the global configuration for
  1.4585  ** the SQLite library.
  1.4586  */
  1.4587 @@ -16840,8 +17350,7 @@
  1.4588     SQLITE_ALLOW_COVERING_INDEX_SCAN,   /* bUseCis */
  1.4589     0x7ffffffe,                /* mxStrlen */
  1.4590     0,                         /* neverCorrupt */
  1.4591 -   128,                       /* szLookaside */
  1.4592 -   500,                       /* nLookaside */
  1.4593 +   SQLITE_DEFAULT_LOOKASIDE,  /* szLookaside, nLookaside */
  1.4594     SQLITE_STMTJRNL_SPILL,     /* nStmtSpill */
  1.4595     {0,0,0,0,0,0,0,0},         /* m */
  1.4596     {0,0,0,0,0,0,0,0,0},       /* mutex */
  1.4597 @@ -16878,10 +17387,11 @@
  1.4598     0,                         /* xVdbeBranch */
  1.4599     0,                         /* pVbeBranchArg */
  1.4600  #endif
  1.4601 -#ifndef SQLITE_OMIT_BUILTIN_TEST
  1.4602 +#ifndef SQLITE_UNTESTABLE
  1.4603     0,                         /* xTestCallback */
  1.4604  #endif
  1.4605 -   0                          /* bLocaltimeFault */
  1.4606 +   0,                         /* bLocaltimeFault */
  1.4607 +   0x7ffffffe                 /* iOnceResetThreshold */
  1.4608  };
  1.4609  
  1.4610  /*
  1.4611 @@ -16904,7 +17414,7 @@
  1.4612  ** The value of the "pending" byte must be 0x40000000 (1 byte past the
  1.4613  ** 1-gibabyte boundary) in a compatible database.  SQLite never uses
  1.4614  ** the database page that contains the pending byte.  It never attempts
  1.4615 -** to read or write that page.  The pending byte page is set assign
  1.4616 +** to read or write that page.  The pending byte page is set aside
  1.4617  ** for use by the VFS layers as space for managing file locks.
  1.4618  **
  1.4619  ** During testing, it is often desirable to move the pending byte to
  1.4620 @@ -16985,10 +17495,19 @@
  1.4621  #if SQLITE_CHECK_PAGES
  1.4622    "CHECK_PAGES",
  1.4623  #endif
  1.4624 +#if defined(__clang__) && defined(__clang_major__)
  1.4625 +  "COMPILER=clang-" CTIMEOPT_VAL(__clang_major__) "."
  1.4626 +                    CTIMEOPT_VAL(__clang_minor__) "."
  1.4627 +                    CTIMEOPT_VAL(__clang_patchlevel__),
  1.4628 +#elif defined(_MSC_VER)
  1.4629 +  "COMPILER=msvc-" CTIMEOPT_VAL(_MSC_VER),
  1.4630 +#elif defined(__GNUC__) && defined(__VERSION__)
  1.4631 +  "COMPILER=gcc-" __VERSION__,
  1.4632 +#endif
  1.4633  #if SQLITE_COVERAGE_TEST
  1.4634    "COVERAGE_TEST",
  1.4635  #endif
  1.4636 -#if SQLITE_DEBUG
  1.4637 +#ifdef SQLITE_DEBUG
  1.4638    "DEBUG",
  1.4639  #endif
  1.4640  #if SQLITE_DEFAULT_LOCKING_MODE
  1.4641 @@ -16997,6 +17516,15 @@
  1.4642  #if defined(SQLITE_DEFAULT_MMAP_SIZE) && !defined(SQLITE_DEFAULT_MMAP_SIZE_xc)
  1.4643    "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE),
  1.4644  #endif
  1.4645 +#if SQLITE_DEFAULT_SYNCHRONOUS
  1.4646 +  "DEFAULT_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_SYNCHRONOUS),
  1.4647 +#endif
  1.4648 +#if SQLITE_DEFAULT_WAL_SYNCHRONOUS
  1.4649 +  "DEFAULT_WAL_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_WAL_SYNCHRONOUS),
  1.4650 +#endif
  1.4651 +#if SQLITE_DIRECT_OVERFLOW_READ
  1.4652 +  "DIRECT_OVERFLOW_READ",
  1.4653 +#endif
  1.4654  #if SQLITE_DISABLE_DIRSYNC
  1.4655    "DISABLE_DIRSYNC",
  1.4656  #endif
  1.4657 @@ -17004,7 +17532,7 @@
  1.4658    "DISABLE_LFS",
  1.4659  #endif
  1.4660  #if SQLITE_ENABLE_8_3_NAMES
  1.4661 -  "ENABLE_8_3_NAMES",
  1.4662 +  "ENABLE_8_3_NAMES=" CTIMEOPT_VAL(SQLITE_ENABLE_8_3_NAMES),
  1.4663  #endif
  1.4664  #if SQLITE_ENABLE_API_ARMOR
  1.4665    "ENABLE_API_ARMOR",
  1.4666 @@ -17083,6 +17611,9 @@
  1.4667  #if SQLITE_ENABLE_UPDATE_DELETE_LIMIT
  1.4668    "ENABLE_UPDATE_DELETE_LIMIT",
  1.4669  #endif
  1.4670 +#if defined(SQLITE_ENABLE_URI_00_ERROR)
  1.4671 +  "ENABLE_URI_00_ERROR",
  1.4672 +#endif
  1.4673  #if SQLITE_HAS_CODEC
  1.4674    "HAS_CODEC",
  1.4675  #endif
  1.4676 @@ -17158,9 +17689,6 @@
  1.4677  #if SQLITE_OMIT_BTREECOUNT
  1.4678    "OMIT_BTREECOUNT",
  1.4679  #endif
  1.4680 -#if SQLITE_OMIT_BUILTIN_TEST
  1.4681 -  "OMIT_BUILTIN_TEST",
  1.4682 -#endif
  1.4683  #if SQLITE_OMIT_CAST
  1.4684    "OMIT_CAST",
  1.4685  #endif
  1.4686 @@ -17323,6 +17851,9 @@
  1.4687  #if defined(SQLITE_THREADSAFE)
  1.4688    "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
  1.4689  #endif
  1.4690 +#if SQLITE_UNTESTABLE
  1.4691 +  "UNTESTABLE"
  1.4692 +#endif
  1.4693  #if SQLITE_USE_ALLOCA
  1.4694    "USE_ALLOCA",
  1.4695  #endif
  1.4696 @@ -17344,7 +17875,7 @@
  1.4697  ** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix
  1.4698  ** is not required for a match.
  1.4699  */
  1.4700 -SQLITE_API int SQLITE_STDCALL sqlite3_compileoption_used(const char *zOptName){
  1.4701 +SQLITE_API int sqlite3_compileoption_used(const char *zOptName){
  1.4702    int i, n;
  1.4703  
  1.4704  #if SQLITE_ENABLE_API_ARMOR
  1.4705 @@ -17372,7 +17903,7 @@
  1.4706  ** Return the N-th compile-time option string.  If N is out of range,
  1.4707  ** return a NULL pointer.
  1.4708  */
  1.4709 -SQLITE_API const char *SQLITE_STDCALL sqlite3_compileoption_get(int N){
  1.4710 +SQLITE_API const char *sqlite3_compileoption_get(int N){
  1.4711    if( N>=0 && N<ArraySize(azCompileOpt) ){
  1.4712      return azCompileOpt[N];
  1.4713    }
  1.4714 @@ -17418,8 +17949,8 @@
  1.4715  ** 6000 lines long) it was split up into several smaller files and
  1.4716  ** this header information was factored out.
  1.4717  */
  1.4718 -#ifndef _VDBEINT_H_
  1.4719 -#define _VDBEINT_H_
  1.4720 +#ifndef SQLITE_VDBEINT_H
  1.4721 +#define SQLITE_VDBEINT_H
  1.4722  
  1.4723  /*
  1.4724  ** The maximum number of times that a statement will try to reparse
  1.4725 @@ -17455,9 +17986,6 @@
  1.4726  /* Opaque type used by code in vdbesort.c */
  1.4727  typedef struct VdbeSorter VdbeSorter;
  1.4728  
  1.4729 -/* Opaque type used by the explainer */
  1.4730 -typedef struct Explain Explain;
  1.4731 -
  1.4732  /* Elements of the linked list at Vdbe.pAuxData */
  1.4733  typedef struct AuxData AuxData;
  1.4734  
  1.4735 @@ -17479,58 +18007,67 @@
  1.4736  */
  1.4737  typedef struct VdbeCursor VdbeCursor;
  1.4738  struct VdbeCursor {
  1.4739 -  u8 eCurType;          /* One of the CURTYPE_* values above */
  1.4740 -  i8 iDb;               /* Index of cursor database in db->aDb[] (or -1) */
  1.4741 -  u8 nullRow;           /* True if pointing to a row with no data */
  1.4742 -  u8 deferredMoveto;    /* A call to sqlite3BtreeMoveto() is needed */
  1.4743 -  u8 isTable;           /* True for rowid tables.  False for indexes */
  1.4744 +  u8 eCurType;            /* One of the CURTYPE_* values above */
  1.4745 +  i8 iDb;                 /* Index of cursor database in db->aDb[] (or -1) */
  1.4746 +  u8 nullRow;             /* True if pointing to a row with no data */
  1.4747 +  u8 deferredMoveto;      /* A call to sqlite3BtreeMoveto() is needed */
  1.4748 +  u8 isTable;             /* True for rowid tables.  False for indexes */
  1.4749  #ifdef SQLITE_DEBUG
  1.4750 -  u8 seekOp;            /* Most recent seek operation on this cursor */
  1.4751 -  u8 wrFlag;            /* The wrFlag argument to sqlite3BtreeCursor() */
  1.4752 -#endif
  1.4753 -  Bool isEphemeral:1;   /* True for an ephemeral table */
  1.4754 -  Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
  1.4755 -  Bool isOrdered:1;     /* True if the table is not BTREE_UNORDERED */
  1.4756 -  Pgno pgnoRoot;        /* Root page of the open btree cursor */
  1.4757 -  i16 nField;           /* Number of fields in the header */
  1.4758 -  u16 nHdrParsed;       /* Number of header fields parsed so far */
  1.4759 +  u8 seekOp;              /* Most recent seek operation on this cursor */
  1.4760 +  u8 wrFlag;              /* The wrFlag argument to sqlite3BtreeCursor() */
  1.4761 +#endif
  1.4762 +  Bool isEphemeral:1;     /* True for an ephemeral table */
  1.4763 +  Bool useRandomRowid:1;  /* Generate new record numbers semi-randomly */
  1.4764 +  Bool isOrdered:1;       /* True if the table is not BTREE_UNORDERED */
  1.4765 +  Btree *pBtx;            /* Separate file holding temporary table */
  1.4766 +  i64 seqCount;           /* Sequence counter */
  1.4767 +  int *aAltMap;           /* Mapping from table to index column numbers */
  1.4768 +
  1.4769 +  /* Cached OP_Column parse information is only valid if cacheStatus matches
  1.4770 +  ** Vdbe.cacheCtr.  Vdbe.cacheCtr will never take on the value of
  1.4771 +  ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
  1.4772 +  ** the cache is out of date. */
  1.4773 +  u32 cacheStatus;        /* Cache is valid if this matches Vdbe.cacheCtr */
  1.4774 +  int seekResult;         /* Result of previous sqlite3BtreeMoveto() or 0
  1.4775 +                          ** if there have been no prior seeks on the cursor. */
  1.4776 +  /* NB: seekResult does not distinguish between "no seeks have ever occurred
  1.4777 +  ** on this cursor" and "the most recent seek was an exact match". */
  1.4778 +
  1.4779 +  /* When a new VdbeCursor is allocated, only the fields above are zeroed.
  1.4780 +  ** The fields that follow are uninitialized, and must be individually
  1.4781 +  ** initialized prior to first use. */
  1.4782 +  VdbeCursor *pAltCursor; /* Associated index cursor from which to read */
  1.4783    union {
  1.4784      BtCursor *pCursor;          /* CURTYPE_BTREE.  Btree cursor */
  1.4785      sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB.   Vtab cursor */
  1.4786      int pseudoTableReg;         /* CURTYPE_PSEUDO. Reg holding content. */
  1.4787      VdbeSorter *pSorter;        /* CURTYPE_SORTER. Sorter object */
  1.4788    } uc;
  1.4789 -  Btree *pBt;           /* Separate file holding temporary table */
  1.4790 -  KeyInfo *pKeyInfo;    /* Info about index keys needed by index cursors */
  1.4791 -  int seekResult;       /* Result of previous sqlite3BtreeMoveto() */
  1.4792 -  i64 seqCount;         /* Sequence counter */
  1.4793 -  i64 movetoTarget;     /* Argument to the deferred sqlite3BtreeMoveto() */
  1.4794 -  VdbeCursor *pAltCursor; /* Associated index cursor from which to read */
  1.4795 -  int *aAltMap;           /* Mapping from table to index column numbers */
  1.4796 +  KeyInfo *pKeyInfo;      /* Info about index keys needed by index cursors */
  1.4797 +  u32 iHdrOffset;         /* Offset to next unparsed byte of the header */
  1.4798 +  Pgno pgnoRoot;          /* Root page of the open btree cursor */
  1.4799 +  i16 nField;             /* Number of fields in the header */
  1.4800 +  u16 nHdrParsed;         /* Number of header fields parsed so far */
  1.4801 +  i64 movetoTarget;       /* Argument to the deferred sqlite3BtreeMoveto() */
  1.4802 +  u32 *aOffset;           /* Pointer to aType[nField] */
  1.4803 +  const u8 *aRow;         /* Data for the current row, if all on one page */
  1.4804 +  u32 payloadSize;        /* Total number of bytes in the record */
  1.4805 +  u32 szRow;              /* Byte available in aRow */
  1.4806  #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
  1.4807 -  u64 maskUsed;         /* Mask of columns used by this cursor */
  1.4808 -#endif
  1.4809 -
  1.4810 -  /* Cached information about the header for the data record that the
  1.4811 -  ** cursor is currently pointing to.  Only valid if cacheStatus matches
  1.4812 -  ** Vdbe.cacheCtr.  Vdbe.cacheCtr will never take on the value of
  1.4813 -  ** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that
  1.4814 -  ** the cache is out of date.
  1.4815 -  **
  1.4816 -  ** aRow might point to (ephemeral) data for the current row, or it might
  1.4817 -  ** be NULL.
  1.4818 -  */
  1.4819 -  u32 cacheStatus;      /* Cache is valid if this matches Vdbe.cacheCtr */
  1.4820 -  u32 payloadSize;      /* Total number of bytes in the record */
  1.4821 -  u32 szRow;            /* Byte available in aRow */
  1.4822 -  u32 iHdrOffset;       /* Offset to next unparsed byte of the header */
  1.4823 -  const u8 *aRow;       /* Data for the current row, if all on one page */
  1.4824 -  u32 *aOffset;         /* Pointer to aType[nField] */
  1.4825 -  u32 aType[1];         /* Type values for all entries in the record */
  1.4826 +  u64 maskUsed;           /* Mask of columns used by this cursor */
  1.4827 +#endif
  1.4828 +
  1.4829    /* 2*nField extra array elements allocated for aType[], beyond the one
  1.4830    ** static element declared in the structure.  nField total array slots for
  1.4831    ** aType[] and nField+1 array slots for aOffset[] */
  1.4832 -};
  1.4833 +  u32 aType[1];           /* Type values record decode.  MUST BE LAST */
  1.4834 +};
  1.4835 +
  1.4836 +
  1.4837 +/*
  1.4838 +** A value for VdbeCursor.cacheStatus that means the cache is always invalid.
  1.4839 +*/
  1.4840 +#define CACHE_STALE 0
  1.4841  
  1.4842  /*
  1.4843  ** When a sub-program is executed (OP_Program), a structure of this type
  1.4844 @@ -17560,8 +18097,8 @@
  1.4845    Op *aOp;                /* Program instructions for parent frame */
  1.4846    i64 *anExec;            /* Event counters from parent frame */
  1.4847    Mem *aMem;              /* Array of memory cells for parent frame */
  1.4848 -  u8 *aOnceFlag;          /* Array of OP_Once flags for parent frame */
  1.4849    VdbeCursor **apCsr;     /* Array of Vdbe cursors for parent frame */
  1.4850 +  u8 *aOnce;              /* Bitmask used by OP_Once */
  1.4851    void *token;            /* Copy of SubProgram.token */
  1.4852    i64 lastRowid;          /* Last insert rowid (sqlite3.lastRowid) */
  1.4853    AuxData *pAuxData;      /* Linked list of auxdata allocations */
  1.4854 @@ -17569,7 +18106,6 @@
  1.4855    int pc;                 /* Program Counter in parent (calling) frame */
  1.4856    int nOp;                /* Size of aOp array */
  1.4857    int nMem;               /* Number of entries in aMem */
  1.4858 -  int nOnceFlag;          /* Number of entries in aOnceFlag */
  1.4859    int nChildMem;          /* Number of memory cells for child frame */
  1.4860    int nChildCsr;          /* Number of cursors for child frame */
  1.4861    int nChange;            /* Statement changes (Vdbe.nChange)     */
  1.4862 @@ -17579,16 +18115,11 @@
  1.4863  #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
  1.4864  
  1.4865  /*
  1.4866 -** A value for VdbeCursor.cacheValid that means the cache is always invalid.
  1.4867 -*/
  1.4868 -#define CACHE_STALE 0
  1.4869 -
  1.4870 -/*
  1.4871  ** Internally, the vdbe manipulates nearly all SQL values as Mem
  1.4872  ** structures. Each Mem struct may cache multiple representations (string,
  1.4873  ** integer etc.) of the same value.
  1.4874  */
  1.4875 -struct Mem {
  1.4876 +struct sqlite3_value {
  1.4877    union MemValue {
  1.4878      double r;           /* Real value used when MEM_Real is set in flags */
  1.4879      i64 i;              /* Integer value used when MEM_Int is set in flags */
  1.4880 @@ -17690,11 +18221,11 @@
  1.4881  ** when the VM is halted (if not before).
  1.4882  */
  1.4883  struct AuxData {
  1.4884 -  int iOp;                        /* Instruction number of OP_Function opcode */
  1.4885 -  int iArg;                       /* Index of function argument. */
  1.4886 +  int iAuxOp;                     /* Instruction number of OP_Function opcode */
  1.4887 +  int iAuxArg;                    /* Index of function argument. */
  1.4888    void *pAux;                     /* Aux data pointer */
  1.4889 -  void (*xDelete)(void *);        /* Destructor for the aux data */
  1.4890 -  AuxData *pNext;                 /* Next element in list */
  1.4891 +  void (*xDeleteAux)(void*);      /* Destructor for the aux data */
  1.4892 +  AuxData *pNextAux;              /* Next element in list */
  1.4893  };
  1.4894  
  1.4895  /*
  1.4896 @@ -17723,18 +18254,6 @@
  1.4897    sqlite3_value *argv[1]; /* Argument set */
  1.4898  };
  1.4899  
  1.4900 -/*
  1.4901 -** An Explain object accumulates indented output which is helpful
  1.4902 -** in describing recursive data structures.
  1.4903 -*/
  1.4904 -struct Explain {
  1.4905 -  Vdbe *pVdbe;       /* Attach the explanation to this Vdbe */
  1.4906 -  StrAccum str;      /* The string being accumulated */
  1.4907 -  int nIndent;       /* Number of elements in aIndent */
  1.4908 -  u16 aIndent[100];  /* Levels of indentation */
  1.4909 -  char zBase[100];   /* Initial space */
  1.4910 -};
  1.4911 -
  1.4912  /* A bitfield type for use inside of structures.  Always follow with :N where
  1.4913  ** N is the number of bits.
  1.4914  */
  1.4915 @@ -17759,34 +18278,46 @@
  1.4916  */
  1.4917  struct Vdbe {
  1.4918    sqlite3 *db;            /* The database connection that owns this statement */
  1.4919 +  Vdbe *pPrev,*pNext;     /* Linked list of VDBEs with the same Vdbe.db */
  1.4920 +  Parse *pParse;          /* Parsing context used to create this Vdbe */
  1.4921 +  ynVar nVar;             /* Number of entries in aVar[] */
  1.4922 +  u32 magic;              /* Magic number for sanity checking */
  1.4923 +  int nMem;               /* Number of memory locations currently allocated */
  1.4924 +  int nCursor;            /* Number of slots in apCsr[] */
  1.4925 +  u32 cacheCtr;           /* VdbeCursor row cache generation counter */
  1.4926 +  int pc;                 /* The program counter */
  1.4927 +  int rc;                 /* Value to return */
  1.4928 +  int nChange;            /* Number of db changes made since last reset */
  1.4929 +  int iStatement;         /* Statement number (or 0 if has not opened stmt) */
  1.4930 +  i64 iCurrentTime;       /* Value of julianday('now') for this statement */
  1.4931 +  i64 nFkConstraint;      /* Number of imm. FK constraints this VM */
  1.4932 +  i64 nStmtDefCons;       /* Number of def. constraints when stmt started */
  1.4933 +  i64 nStmtDefImmCons;    /* Number of def. imm constraints when stmt started */
  1.4934 +
  1.4935 +  /* When allocating a new Vdbe object, all of the fields below should be
  1.4936 +  ** initialized to zero or NULL */
  1.4937 +
  1.4938    Op *aOp;                /* Space to hold the virtual machine's program */
  1.4939    Mem *aMem;              /* The memory locations */
  1.4940    Mem **apArg;            /* Arguments to currently executing user function */
  1.4941    Mem *aColName;          /* Column names to return */
  1.4942    Mem *pResultSet;        /* Pointer to an array of results */
  1.4943 -  Parse *pParse;          /* Parsing context used to create this Vdbe */
  1.4944 -  int nMem;               /* Number of memory locations currently allocated */
  1.4945 -  int nOp;                /* Number of instructions in the program */
  1.4946 -  int nCursor;            /* Number of slots in apCsr[] */
  1.4947 -  u32 magic;              /* Magic number for sanity checking */
  1.4948    char *zErrMsg;          /* Error message written here */
  1.4949 -  Vdbe *pPrev,*pNext;     /* Linked list of VDBEs with the same Vdbe.db */
  1.4950    VdbeCursor **apCsr;     /* One element of this array for each open cursor */
  1.4951    Mem *aVar;              /* Values for the OP_Variable opcode. */
  1.4952 -  char **azVar;           /* Name of variables */
  1.4953 -  ynVar nVar;             /* Number of entries in aVar[] */
  1.4954 -  ynVar nzVar;            /* Number of entries in azVar[] */
  1.4955 -  u32 cacheCtr;           /* VdbeCursor row cache generation counter */
  1.4956 -  int pc;                 /* The program counter */
  1.4957 -  int rc;                 /* Value to return */
  1.4958 +  VList *pVList;          /* Name of variables */
  1.4959 +#ifndef SQLITE_OMIT_TRACE
  1.4960 +  i64 startTime;          /* Time when query started - used for profiling */
  1.4961 +#endif
  1.4962 +  int nOp;                /* Number of instructions in the program */
  1.4963  #ifdef SQLITE_DEBUG
  1.4964    int rcApp;              /* errcode set by sqlite3_result_error_code() */
  1.4965  #endif
  1.4966    u16 nResColumn;         /* Number of columns in one row of the result set */
  1.4967    u8 errorAction;         /* Recovery action to do in case of an error */
  1.4968 +  u8 minWriteFileFormat;  /* Minimum file format for writable database files */
  1.4969    bft expired:1;          /* True if the VM needs to be recompiled */
  1.4970    bft doingRerun:1;       /* True if rerunning after an auto-reprepare */
  1.4971 -  u8 minWriteFileFormat;  /* Minimum file format for writable database files */
  1.4972    bft explain:2;          /* True if EXPLAIN present on SQL command */
  1.4973    bft changeCntOn:1;      /* True to update the change-counter */
  1.4974    bft runOnlyOnce:1;      /* Automatically expire on reset */
  1.4975 @@ -17794,18 +18325,9 @@
  1.4976    bft readOnly:1;         /* True for statements that do not write */
  1.4977    bft bIsReader:1;        /* True for statements that read */
  1.4978    bft isPrepareV2:1;      /* True if prepared with prepare_v2() */
  1.4979 -  int nChange;            /* Number of db changes made since last reset */
  1.4980    yDbMask btreeMask;      /* Bitmask of db->aDb[] entries referenced */
  1.4981    yDbMask lockMask;       /* Subset of btreeMask that requires a lock */
  1.4982 -  int iStatement;         /* Statement number (or 0 if has not opened stmt) */
  1.4983    u32 aCounter[5];        /* Counters used by sqlite3_stmt_status() */
  1.4984 -#ifndef SQLITE_OMIT_TRACE
  1.4985 -  i64 startTime;          /* Time when query started - used for profiling */
  1.4986 -#endif
  1.4987 -  i64 iCurrentTime;       /* Value of julianday('now') for this statement */
  1.4988 -  i64 nFkConstraint;      /* Number of imm. FK constraints this VM */
  1.4989 -  i64 nStmtDefCons;       /* Number of def. constraints when stmt started */
  1.4990 -  i64 nStmtDefImmCons;    /* Number of def. imm constraints when stmt started */
  1.4991    char *zSql;             /* Text of the SQL statement that generated this */
  1.4992    void *pFree;            /* Free this when deleting the vdbe */
  1.4993    VdbeFrame *pFrame;      /* Parent frame */
  1.4994 @@ -17813,8 +18335,6 @@
  1.4995    int nFrame;             /* Number of frames in pFrame list */
  1.4996    u32 expmask;            /* Binding to these vars invalidates VM */
  1.4997    SubProgram *pProgram;   /* Linked list of all sub-programs used by VM */
  1.4998 -  int nOnceFlag;          /* Size of array aOnceFlag[] */
  1.4999 -  u8 *aOnceFlag;          /* Flags for OP_Once */
  1.5000    AuxData *pAuxData;      /* Linked list of auxdata allocations */
  1.5001  #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
  1.5002    i64 *anExec;            /* Number of times each op has been executed */
  1.5003 @@ -17826,10 +18346,11 @@
  1.5004  /*
  1.5005  ** The following are allowed values for Vdbe.magic
  1.5006  */
  1.5007 -#define VDBE_MAGIC_INIT     0x26bceaa5    /* Building a VDBE program */
  1.5008 -#define VDBE_MAGIC_RUN      0xbdf20da3    /* VDBE is ready to execute */
  1.5009 -#define VDBE_MAGIC_HALT     0x519c2973    /* VDBE has completed execution */
  1.5010 -#define VDBE_MAGIC_DEAD     0xb606c3c8    /* The VDBE has been deallocated */
  1.5011 +#define VDBE_MAGIC_INIT     0x16bceaa5    /* Building a VDBE program */
  1.5012 +#define VDBE_MAGIC_RUN      0x2df20da3    /* VDBE is ready to execute */
  1.5013 +#define VDBE_MAGIC_HALT     0x319c2973    /* VDBE has completed execution */
  1.5014 +#define VDBE_MAGIC_RESET    0x48fa9f76    /* Reset and ready to run again */
  1.5015 +#define VDBE_MAGIC_DEAD     0x5606c3c8    /* The VDBE has been deallocated */
  1.5016  
  1.5017  /*
  1.5018  ** Structure used to store the context required by the 
  1.5019 @@ -17846,8 +18367,9 @@
  1.5020    int iNewReg;                    /* Register for new.* values */
  1.5021    i64 iKey1;                      /* First key value passed to hook */
  1.5022    i64 iKey2;                      /* Second key value passed to hook */
  1.5023 -  int iPKey;                      /* If not negative index of IPK column */
  1.5024    Mem *aNew;                      /* Array of new.* values */
  1.5025 +  Table *pTab;                    /* Schema object being upated */          
  1.5026 +  Index *pPk;                     /* PK index if pTab is WITHOUT ROWID */
  1.5027  };
  1.5028  
  1.5029  /*
  1.5030 @@ -17900,7 +18422,7 @@
  1.5031  SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
  1.5032  SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
  1.5033  SQLITE_PRIVATE void sqlite3VdbeMemCast(Mem*,u8,u8);
  1.5034 -SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*);
  1.5035 +SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);
  1.5036  SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
  1.5037  SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
  1.5038  SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
  1.5039 @@ -17961,7 +18483,7 @@
  1.5040    #define ExpandBlob(P) SQLITE_OK
  1.5041  #endif
  1.5042  
  1.5043 -#endif /* !defined(_VDBEINT_H_) */
  1.5044 +#endif /* !defined(SQLITE_VDBEINT_H) */
  1.5045  
  1.5046  /************** End of vdbeInt.h *********************************************/
  1.5047  /************** Continuing where we left off in status.c *********************/
  1.5048 @@ -18082,7 +18604,7 @@
  1.5049  /*
  1.5050  ** Query status information.
  1.5051  */
  1.5052 -SQLITE_API int SQLITE_STDCALL sqlite3_status64(
  1.5053 +SQLITE_API int sqlite3_status64(
  1.5054    int op,
  1.5055    sqlite3_int64 *pCurrent,
  1.5056    sqlite3_int64 *pHighwater,
  1.5057 @@ -18107,8 +18629,8 @@
  1.5058    (void)pMutex;  /* Prevent warning when SQLITE_THREADSAFE=0 */
  1.5059    return SQLITE_OK;
  1.5060  }
  1.5061 -SQLITE_API int SQLITE_STDCALL sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
  1.5062 -  sqlite3_int64 iCur, iHwtr;
  1.5063 +SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
  1.5064 +  sqlite3_int64 iCur = 0, iHwtr = 0;
  1.5065    int rc;
  1.5066  #ifdef SQLITE_ENABLE_API_ARMOR
  1.5067    if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT;
  1.5068 @@ -18124,7 +18646,7 @@
  1.5069  /*
  1.5070  ** Query status information for a single database connection
  1.5071  */
  1.5072 -SQLITE_API int SQLITE_STDCALL sqlite3_db_status(
  1.5073 +SQLITE_API int sqlite3_db_status(
  1.5074    sqlite3 *db,          /* The database connection whose status is desired */
  1.5075    int op,               /* Status verb */
  1.5076    int *pCurrent,        /* Write current value here */
  1.5077 @@ -18169,6 +18691,7 @@
  1.5078      ** by all pagers associated with the given database connection.  The
  1.5079      ** highwater mark is meaningless and is returned as zero.
  1.5080      */
  1.5081 +    case SQLITE_DBSTATUS_CACHE_USED_SHARED:
  1.5082      case SQLITE_DBSTATUS_CACHE_USED: {
  1.5083        int totalUsed = 0;
  1.5084        int i;
  1.5085 @@ -18177,7 +18700,11 @@
  1.5086          Btree *pBt = db->aDb[i].pBt;
  1.5087          if( pBt ){
  1.5088            Pager *pPager = sqlite3BtreePager(pBt);
  1.5089 -          totalUsed += sqlite3PagerMemUsed(pPager);
  1.5090 +          int nByte = sqlite3PagerMemUsed(pPager);
  1.5091 +          if( op==SQLITE_DBSTATUS_CACHE_USED_SHARED ){
  1.5092 +            nByte = nByte / sqlite3BtreeConnectionCount(pBt);
  1.5093 +          }
  1.5094 +          totalUsed += nByte;
  1.5095          }
  1.5096        }
  1.5097        sqlite3BtreeLeaveAll(db);
  1.5098 @@ -18364,16 +18891,18 @@
  1.5099  */
  1.5100  typedef struct DateTime DateTime;
  1.5101  struct DateTime {
  1.5102 -  sqlite3_int64 iJD; /* The julian day number times 86400000 */
  1.5103 -  int Y, M, D;       /* Year, month, and day */
  1.5104 -  int h, m;          /* Hour and minutes */
  1.5105 -  int tz;            /* Timezone offset in minutes */
  1.5106 -  double s;          /* Seconds */
  1.5107 -  char validYMD;     /* True (1) if Y,M,D are valid */
  1.5108 -  char validHMS;     /* True (1) if h,m,s are valid */
  1.5109 -  char validJD;      /* True (1) if iJD is valid */
  1.5110 -  char validTZ;      /* True (1) if tz is valid */
  1.5111 -  char tzSet;        /* Timezone was set explicitly */
  1.5112 +  sqlite3_int64 iJD;  /* The julian day number times 86400000 */
  1.5113 +  int Y, M, D;        /* Year, month, and day */
  1.5114 +  int h, m;           /* Hour and minutes */
  1.5115 +  int tz;             /* Timezone offset in minutes */
  1.5116 +  double s;           /* Seconds */
  1.5117 +  char validJD;       /* True (1) if iJD is valid */
  1.5118 +  char rawS;          /* Raw numeric value stored in s */
  1.5119 +  char validYMD;      /* True (1) if Y,M,D are valid */
  1.5120 +  char validHMS;      /* True (1) if h,m,s are valid */
  1.5121 +  char validTZ;       /* True (1) if tz is valid */
  1.5122 +  char tzSet;         /* Timezone was set explicitly */
  1.5123 +  char isError;       /* An overflow has occurred */
  1.5124  };
  1.5125  
  1.5126  
  1.5127 @@ -18521,6 +19050,7 @@
  1.5128      s = 0;
  1.5129    }
  1.5130    p->validJD = 0;
  1.5131 +  p->rawS = 0;
  1.5132    p->validHMS = 1;
  1.5133    p->h = h;
  1.5134    p->m = m;
  1.5135 @@ -18531,6 +19061,14 @@
  1.5136  }
  1.5137  
  1.5138  /*
  1.5139 +** Put the DateTime object into its error state.
  1.5140 +*/
  1.5141 +static void datetimeError(DateTime *p){
  1.5142 +  memset(p, 0, sizeof(*p));
  1.5143 +  p->isError = 1;
  1.5144 +}
  1.5145 +
  1.5146 +/*
  1.5147  ** Convert from YYYY-MM-DD HH:MM:SS to julian day.  We always assume
  1.5148  ** that the YYYY-MM-DD is according to the Gregorian calendar.
  1.5149  **
  1.5150 @@ -18549,6 +19087,10 @@
  1.5151      M = 1;
  1.5152      D = 1;
  1.5153    }
  1.5154 +  if( Y<-4713 || Y>9999 || p->rawS ){
  1.5155 +    datetimeError(p);
  1.5156 +    return;
  1.5157 +  }
  1.5158    if( M<=2 ){
  1.5159      Y--;
  1.5160      M += 12;
  1.5161 @@ -18630,6 +19172,21 @@
  1.5162  }
  1.5163  
  1.5164  /*
  1.5165 +** Input "r" is a numeric quantity which might be a julian day number,
  1.5166 +** or the number of seconds since 1970.  If the value if r is within
  1.5167 +** range of a julian day number, install it as such and set validJD.
  1.5168 +** If the value is a valid unix timestamp, put it in p->s and set p->rawS.
  1.5169 +*/
  1.5170 +static void setRawDateNumber(DateTime *p, double r){
  1.5171 +  p->s = r;
  1.5172 +  p->rawS = 1;
  1.5173 +  if( r>=0.0 && r<5373484.5 ){
  1.5174 +    p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
  1.5175 +    p->validJD = 1;
  1.5176 +  }
  1.5177 +}
  1.5178 +
  1.5179 +/*
  1.5180  ** Attempt to parse the given string into a julian day number.  Return
  1.5181  ** the number of errors.
  1.5182  **
  1.5183 @@ -18658,13 +19215,30 @@
  1.5184    }else if( sqlite3StrICmp(zDate,"now")==0){
  1.5185      return setDateTimeToCurrent(context, p);
  1.5186    }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){
  1.5187 -    p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
  1.5188 -    p->validJD = 1;
  1.5189 +    setRawDateNumber(p, r);
  1.5190      return 0;
  1.5191    }
  1.5192    return 1;
  1.5193  }
  1.5194  
  1.5195 +/* The julian day number for 9999-12-31 23:59:59.999 is 5373484.4999999.
  1.5196 +** Multiplying this by 86400000 gives 464269060799999 as the maximum value
  1.5197 +** for DateTime.iJD.
  1.5198 +**
  1.5199 +** But some older compilers (ex: gcc 4.2.1 on older Macs) cannot deal with 
  1.5200 +** such a large integer literal, so we have to encode it.
  1.5201 +*/
  1.5202 +#define INT_464269060799999  ((((i64)0x1a640)<<32)|0x1072fdff)
  1.5203 +
  1.5204 +/*
  1.5205 +** Return TRUE if the given julian day number is within range.
  1.5206 +**
  1.5207 +** The input is the JulianDay times 86400000.
  1.5208 +*/
  1.5209 +static int validJulianDay(sqlite3_int64 iJD){
  1.5210 +  return iJD>=0 && iJD<=INT_464269060799999;
  1.5211 +}
  1.5212 +
  1.5213  /*
  1.5214  ** Compute the Year, Month, and Day from the julian day number.
  1.5215  */
  1.5216 @@ -18675,6 +19249,9 @@
  1.5217      p->Y = 2000;
  1.5218      p->M = 1;
  1.5219      p->D = 1;
  1.5220 +  }else if( !validJulianDay(p->iJD) ){
  1.5221 +    datetimeError(p);
  1.5222 +    return;
  1.5223    }else{
  1.5224      Z = (int)((p->iJD + 43200000)/86400000);
  1.5225      A = (int)((Z - 1867216.25)/36524.25);
  1.5226 @@ -18706,6 +19283,7 @@
  1.5227    s -= p->h*3600;
  1.5228    p->m = s/60;
  1.5229    p->s += s - p->m*60;
  1.5230 +  p->rawS = 0;
  1.5231    p->validHMS = 1;
  1.5232  }
  1.5233  
  1.5234 @@ -18767,14 +19345,14 @@
  1.5235  #endif
  1.5236    sqlite3_mutex_enter(mutex);
  1.5237    pX = localtime(t);
  1.5238 -#ifndef SQLITE_OMIT_BUILTIN_TEST
  1.5239 +#ifndef SQLITE_UNTESTABLE
  1.5240    if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0;
  1.5241  #endif
  1.5242    if( pX ) *pTm = *pX;
  1.5243    sqlite3_mutex_leave(mutex);
  1.5244    rc = pX==0;
  1.5245  #else
  1.5246 -#ifndef SQLITE_OMIT_BUILTIN_TEST
  1.5247 +#ifndef SQLITE_UNTESTABLE
  1.5248    if( sqlite3GlobalConfig.bLocaltimeFault ) return 1;
  1.5249  #endif
  1.5250  #if HAVE_LOCALTIME_R
  1.5251 @@ -18845,7 +19423,9 @@
  1.5252    y.validYMD = 1;
  1.5253    y.validHMS = 1;
  1.5254    y.validJD = 0;
  1.5255 +  y.rawS = 0;
  1.5256    y.validTZ = 0;
  1.5257 +  y.isError = 0;
  1.5258    computeJD(&y);
  1.5259    *pRc = SQLITE_OK;
  1.5260    return y.iJD - x.iJD;
  1.5261 @@ -18853,6 +19433,29 @@
  1.5262  #endif /* SQLITE_OMIT_LOCALTIME */
  1.5263  
  1.5264  /*
  1.5265 +** The following table defines various date transformations of the form
  1.5266 +**
  1.5267 +**            'NNN days'
  1.5268 +**
  1.5269 +** Where NNN is an arbitrary floating-point number and "days" can be one
  1.5270 +** of several units of time.
  1.5271 +*/
  1.5272 +static const struct {
  1.5273 +  u8 eType;           /* Transformation type code */
  1.5274 +  u8 nName;           /* Length of th name */
  1.5275 +  char *zName;        /* Name of the transformation */
  1.5276 +  double rLimit;      /* Maximum NNN value for this transform */
  1.5277 +  double rXform;      /* Constant used for this transform */
  1.5278 +} aXformType[] = {
  1.5279 +  { 0, 6, "second", 464269060800.0, 86400000.0/(24.0*60.0*60.0) },
  1.5280 +  { 0, 6, "minute", 7737817680.0,   86400000.0/(24.0*60.0)      },
  1.5281 +  { 0, 4, "hour",   128963628.0,    86400000.0/24.0             },
  1.5282 +  { 0, 3, "day",    5373485.0,      86400000.0                  },
  1.5283 +  { 1, 5, "month",  176546.0,       30.0*86400000.0             },
  1.5284 +  { 2, 4, "year",   14713.0,        365.0*86400000.0            },
  1.5285 +};
  1.5286 +
  1.5287 +/*
  1.5288  ** Process a modifier to a date-time stamp.  The modifiers are
  1.5289  ** as follows:
  1.5290  **
  1.5291 @@ -18876,17 +19479,15 @@
  1.5292  ** to context pCtx. If the error is an unrecognized modifier, no error is
  1.5293  ** written to pCtx.
  1.5294  */
  1.5295 -static int parseModifier(sqlite3_context *pCtx, const char *zMod, DateTime *p){
  1.5296 +static int parseModifier(
  1.5297 +  sqlite3_context *pCtx,      /* Function context */
  1.5298 +  const char *z,              /* The text of the modifier */
  1.5299 +  int n,                      /* Length of zMod in bytes */
  1.5300 +  DateTime *p                 /* The date/time value to be modified */
  1.5301 +){
  1.5302    int rc = 1;
  1.5303 -  int n;
  1.5304    double r;
  1.5305 -  char *z, zBuf[30];
  1.5306 -  z = zBuf;
  1.5307 -  for(n=0; n<ArraySize(zBuf)-1 && zMod[n]; n++){
  1.5308 -    z[n] = (char)sqlite3UpperToLower[(u8)zMod[n]];
  1.5309 -  }
  1.5310 -  z[n] = 0;
  1.5311 -  switch( z[0] ){
  1.5312 +  switch(sqlite3UpperToLower[(u8)z[0]] ){
  1.5313  #ifndef SQLITE_OMIT_LOCALTIME
  1.5314      case 'l': {
  1.5315        /*    localtime
  1.5316 @@ -18894,7 +19495,7 @@
  1.5317        ** Assuming the current time value is UTC (a.k.a. GMT), shift it to
  1.5318        ** show local time.
  1.5319        */
  1.5320 -      if( strcmp(z, "localtime")==0 ){
  1.5321 +      if( sqlite3_stricmp(z, "localtime")==0 ){
  1.5322          computeJD(p);
  1.5323          p->iJD += localtimeOffset(p, pCtx, &rc);
  1.5324          clearYMD_HMS_TZ(p);
  1.5325 @@ -18906,16 +19507,21 @@
  1.5326        /*
  1.5327        **    unixepoch
  1.5328        **
  1.5329 -      ** Treat the current value of p->iJD as the number of
  1.5330 +      ** Treat the current value of p->s as the number of
  1.5331        ** seconds since 1970.  Convert to a real julian day number.
  1.5332        */
  1.5333 -      if( strcmp(z, "unixepoch")==0 && p->validJD ){
  1.5334 -        p->iJD = (p->iJD + 43200)/86400 + 21086676*(i64)10000000;
  1.5335 -        clearYMD_HMS_TZ(p);
  1.5336 -        rc = 0;
  1.5337 +      if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){
  1.5338 +        r = p->s*1000.0 + 210866760000000.0;
  1.5339 +        if( r>=0.0 && r<464269060800000.0 ){
  1.5340 +          clearYMD_HMS_TZ(p);
  1.5341 +          p->iJD = (sqlite3_int64)r;
  1.5342 +          p->validJD = 1;
  1.5343 +          p->rawS = 0;
  1.5344 +          rc = 0;
  1.5345 +        }
  1.5346        }
  1.5347  #ifndef SQLITE_OMIT_LOCALTIME
  1.5348 -      else if( strcmp(z, "utc")==0 ){
  1.5349 +      else if( sqlite3_stricmp(z, "utc")==0 ){
  1.5350          if( p->tzSet==0 ){
  1.5351            sqlite3_int64 c1;
  1.5352            computeJD(p);
  1.5353 @@ -18941,7 +19547,7 @@
  1.5354        ** weekday N where 0==Sunday, 1==Monday, and so forth.  If the
  1.5355        ** date is already on the appropriate weekday, this is a no-op.
  1.5356        */
  1.5357 -      if( strncmp(z, "weekday ", 8)==0
  1.5358 +      if( sqlite3_strnicmp(z, "weekday ", 8)==0
  1.5359                 && sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8)
  1.5360                 && (n=(int)r)==r && n>=0 && r<7 ){
  1.5361          sqlite3_int64 Z;
  1.5362 @@ -18964,23 +19570,24 @@
  1.5363        ** Move the date backwards to the beginning of the current day,
  1.5364        ** or month or year.
  1.5365        */
  1.5366 -      if( strncmp(z, "start of ", 9)!=0 ) break;
  1.5367 +      if( sqlite3_strnicmp(z, "start of ", 9)!=0 ) break;
  1.5368 +      if( !p->validJD && !p->validYMD && !p->validHMS ) break;
  1.5369        z += 9;
  1.5370        computeYMD(p);
  1.5371        p->validHMS = 1;
  1.5372        p->h = p->m = 0;
  1.5373        p->s = 0.0;
  1.5374 +      p->rawS = 0;
  1.5375        p->validTZ = 0;
  1.5376        p->validJD = 0;
  1.5377 -      if( strcmp(z,"month")==0 ){
  1.5378 +      if( sqlite3_stricmp(z,"month")==0 ){
  1.5379          p->D = 1;
  1.5380          rc = 0;
  1.5381 -      }else if( strcmp(z,"year")==0 ){
  1.5382 -        computeYMD(p);
  1.5383 +      }else if( sqlite3_stricmp(z,"year")==0 ){
  1.5384          p->M = 1;
  1.5385          p->D = 1;
  1.5386          rc = 0;
  1.5387 -      }else if( strcmp(z,"day")==0 ){
  1.5388 +      }else if( sqlite3_stricmp(z,"day")==0 ){
  1.5389          rc = 0;
  1.5390        }
  1.5391        break;
  1.5392 @@ -18998,6 +19605,7 @@
  1.5393      case '8':
  1.5394      case '9': {
  1.5395        double rRounder;
  1.5396 +      int i;
  1.5397        for(n=1; z[n] && z[n]!=':' && !sqlite3Isspace(z[n]); n++){}
  1.5398        if( !sqlite3AtoF(z, &r, n, SQLITE_UTF8) ){
  1.5399          rc = 1;
  1.5400 @@ -19026,46 +19634,48 @@
  1.5401          rc = 0;
  1.5402          break;
  1.5403        }
  1.5404 +
  1.5405 +      /* If control reaches this point, it means the transformation is
  1.5406 +      ** one of the forms like "+NNN days".  */
  1.5407        z += n;
  1.5408        while( sqlite3Isspace(*z) ) z++;
  1.5409        n = sqlite3Strlen30(z);
  1.5410        if( n>10 || n<3 ) break;
  1.5411 -      if( z[n-1]=='s' ){ z[n-1] = 0; n--; }
  1.5412 +      if( sqlite3UpperToLower[(u8)z[n-1]]=='s' ) n--;
  1.5413        computeJD(p);
  1.5414 -      rc = 0;
  1.5415 +      rc = 1;
  1.5416        rRounder = r<0 ? -0.5 : +0.5;
  1.5417 -      if( n==3 && strcmp(z,"day")==0 ){
  1.5418 -        p->iJD += (sqlite3_int64)(r*86400000.0 + rRounder);
  1.5419 -      }else if( n==4 && strcmp(z,"hour")==0 ){
  1.5420 -        p->iJD += (sqlite3_int64)(r*(86400000.0/24.0) + rRounder);
  1.5421 -      }else if( n==6 && strcmp(z,"minute")==0 ){
  1.5422 -        p->iJD += (sqlite3_int64)(r*(86400000.0/(24.0*60.0)) + rRounder);
  1.5423 -      }else if( n==6 && strcmp(z,"second")==0 ){
  1.5424 -        p->iJD += (sqlite3_int64)(r*(86400000.0/(24.0*60.0*60.0)) + rRounder);
  1.5425 -      }else if( n==5 && strcmp(z,"month")==0 ){
  1.5426 -        int x, y;
  1.5427 -        computeYMD_HMS(p);
  1.5428 -        p->M += (int)r;
  1.5429 -        x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
  1.5430 -        p->Y += x;
  1.5431 -        p->M -= x*12;
  1.5432 -        p->validJD = 0;
  1.5433 -        computeJD(p);
  1.5434 -        y = (int)r;
  1.5435 -        if( y!=r ){
  1.5436 -          p->iJD += (sqlite3_int64)((r - y)*30.0*86400000.0 + rRounder);
  1.5437 -        }
  1.5438 -      }else if( n==4 && strcmp(z,"year")==0 ){
  1.5439 -        int y = (int)r;
  1.5440 -        computeYMD_HMS(p);
  1.5441 -        p->Y += y;
  1.5442 -        p->validJD = 0;
  1.5443 -        computeJD(p);
  1.5444 -        if( y!=r ){
  1.5445 -          p->iJD += (sqlite3_int64)((r - y)*365.0*86400000.0 + rRounder);
  1.5446 -        }
  1.5447 -      }else{
  1.5448 -        rc = 1;
  1.5449 +      for(i=0; i<ArraySize(aXformType); i++){
  1.5450 +        if( aXformType[i].nName==n
  1.5451 +         && sqlite3_strnicmp(aXformType[i].zName, z, n)==0
  1.5452 +         && r>-aXformType[i].rLimit && r<aXformType[i].rLimit
  1.5453 +        ){
  1.5454 +          switch( aXformType[i].eType ){
  1.5455 +            case 1: { /* Special processing to add months */
  1.5456 +              int x;
  1.5457 +              computeYMD_HMS(p);
  1.5458 +              p->M += (int)r;
  1.5459 +              x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
  1.5460 +              p->Y += x;
  1.5461 +              p->M -= x*12;
  1.5462 +              p->validJD = 0;
  1.5463 +              r -= (int)r;
  1.5464 +              break;
  1.5465 +            }
  1.5466 +            case 2: { /* Special processing to add years */
  1.5467 +              int y = (int)r;
  1.5468 +              computeYMD_HMS(p);
  1.5469 +              p->Y += y;
  1.5470 +              p->validJD = 0;
  1.5471 +              r -= (int)r;
  1.5472 +              break;
  1.5473 +            }
  1.5474 +          }
  1.5475 +          computeJD(p);
  1.5476 +          p->iJD += (sqlite3_int64)(r*aXformType[i].rXform + rRounder);
  1.5477 +          rc = 0;
  1.5478 +          break;
  1.5479 +        }
  1.5480        }
  1.5481        clearYMD_HMS_TZ(p);
  1.5482        break;
  1.5483 @@ -19092,7 +19702,7 @@
  1.5484    sqlite3_value **argv, 
  1.5485    DateTime *p
  1.5486  ){
  1.5487 -  int i;
  1.5488 +  int i, n;
  1.5489    const unsigned char *z;
  1.5490    int eType;
  1.5491    memset(p, 0, sizeof(*p));
  1.5492 @@ -19101,8 +19711,7 @@
  1.5493    }
  1.5494    if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
  1.5495                     || eType==SQLITE_INTEGER ){
  1.5496 -    p->iJD = (sqlite3_int64)(sqlite3_value_double(argv[0])*86400000.0 + 0.5);
  1.5497 -    p->validJD = 1;
  1.5498 +    setRawDateNumber(p, sqlite3_value_double(argv[0]));
  1.5499    }else{
  1.5500      z = sqlite3_value_text(argv[0]);
  1.5501      if( !z || parseDateOrTime(context, (char*)z, p) ){
  1.5502 @@ -19111,8 +19720,11 @@
  1.5503    }
  1.5504    for(i=1; i<argc; i++){
  1.5505      z = sqlite3_value_text(argv[i]);
  1.5506 -    if( z==0 || parseModifier(context, (char*)z, p) ) return 1;
  1.5507 -  }
  1.5508 +    n = sqlite3_value_bytes(argv[i]);
  1.5509 +    if( z==0 || parseModifier(context, (char*)z, n, p) ) return 1;
  1.5510 +  }
  1.5511 +  computeJD(p);
  1.5512 +  if( p->isError || !validJulianDay(p->iJD) ) return 1;
  1.5513    return 0;
  1.5514  }
  1.5515  
  1.5516 @@ -19411,7 +20023,6 @@
  1.5517  ){
  1.5518    time_t t;
  1.5519    char *zFormat = (char *)sqlite3_user_data(context);
  1.5520 -  sqlite3 *db;
  1.5521    sqlite3_int64 iT;
  1.5522    struct tm *pTm;
  1.5523    struct tm sNow;
  1.5524 @@ -19480,9 +20091,7 @@
  1.5525  ** This file contains OS interface code that is common to all
  1.5526  ** architectures.
  1.5527  */
  1.5528 -#define _SQLITE_OS_C_ 1
  1.5529  /* #include "sqliteInt.h" */
  1.5530 -#undef _SQLITE_OS_C_
  1.5531  
  1.5532  /*
  1.5533  ** If we compile with the SQLITE_TEST macro set, then the following block
  1.5534 @@ -19799,7 +20408,7 @@
  1.5535  ** Locate a VFS by name.  If no name is given, simply return the
  1.5536  ** first VFS on the list.
  1.5537  */
  1.5538 -SQLITE_API sqlite3_vfs *SQLITE_STDCALL sqlite3_vfs_find(const char *zVfs){
  1.5539 +SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfs){
  1.5540    sqlite3_vfs *pVfs = 0;
  1.5541  #if SQLITE_THREADSAFE
  1.5542    sqlite3_mutex *mutex;
  1.5543 @@ -19845,7 +20454,7 @@
  1.5544  ** VFS multiple times.  The new VFS becomes the default if makeDflt is
  1.5545  ** true.
  1.5546  */
  1.5547 -SQLITE_API int SQLITE_STDCALL sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){
  1.5548 +SQLITE_API int sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){
  1.5549    MUTEX_LOGIC(sqlite3_mutex *mutex;)
  1.5550  #ifndef SQLITE_OMIT_AUTOINIT
  1.5551    int rc = sqlite3_initialize();
  1.5552 @@ -19873,7 +20482,7 @@
  1.5553  /*
  1.5554  ** Unregister a VFS so that it is no longer accessible.
  1.5555  */
  1.5556 -SQLITE_API int SQLITE_STDCALL sqlite3_vfs_unregister(sqlite3_vfs *pVfs){
  1.5557 +SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs *pVfs){
  1.5558  #if SQLITE_THREADSAFE
  1.5559    sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
  1.5560  #endif
  1.5561 @@ -19913,7 +20522,7 @@
  1.5562  
  1.5563  /* #include "sqliteInt.h" */
  1.5564  
  1.5565 -#ifndef SQLITE_OMIT_BUILTIN_TEST
  1.5566 +#ifndef SQLITE_UNTESTABLE
  1.5567  
  1.5568  /*
  1.5569  ** Global variables.
  1.5570 @@ -19971,7 +20580,7 @@
  1.5571    }
  1.5572  }
  1.5573  
  1.5574 -#endif   /* #ifndef SQLITE_OMIT_BUILTIN_TEST */
  1.5575 +#endif   /* #ifndef SQLITE_UNTESTABLE */
  1.5576  
  1.5577  /************** End of fault.c ***********************************************/
  1.5578  /************** Begin file mem0.c ********************************************/
  1.5579 @@ -20096,7 +20705,9 @@
  1.5580  */
  1.5581  #include <sys/sysctl.h>
  1.5582  #include <malloc/malloc.h>
  1.5583 +#ifdef SQLITE_MIGHT_BE_SINGLE_CORE
  1.5584  #include <libkern/OSAtomic.h>
  1.5585 +#endif /* SQLITE_MIGHT_BE_SINGLE_CORE */
  1.5586  static malloc_zone_t* _sqliteZone_;
  1.5587  #define SQLITE_MALLOC(x) malloc_zone_malloc(_sqliteZone_, (x))
  1.5588  #define SQLITE_FREE(x) malloc_zone_free(_sqliteZone_, (x));
  1.5589 @@ -20164,7 +20775,9 @@
  1.5590  */
  1.5591  static void *sqlite3MemMalloc(int nByte){
  1.5592  #ifdef SQLITE_MALLOCSIZE
  1.5593 -  void *p = SQLITE_MALLOC( nByte );
  1.5594 +  void *p;
  1.5595 +  testcase( ROUND8(nByte)==nByte );
  1.5596 +  p = SQLITE_MALLOC( nByte );
  1.5597    if( p==0 ){
  1.5598      testcase( sqlite3GlobalConfig.xLog!=0 );
  1.5599      sqlite3_log(SQLITE_NOMEM, "failed to allocate %u bytes of memory", nByte);
  1.5600 @@ -20173,7 +20786,7 @@
  1.5601  #else
  1.5602    sqlite3_int64 *p;
  1.5603    assert( nByte>0 );
  1.5604 -  nByte = ROUND8(nByte);
  1.5605 +  testcase( ROUND8(nByte)!=nByte );
  1.5606    p = SQLITE_MALLOC( nByte+8 );
  1.5607    if( p ){
  1.5608      p[0] = nByte;
  1.5609 @@ -20287,19 +20900,10 @@
  1.5610    }else{
  1.5611      /* only 1 core, use our own zone to contention over global locks, 
  1.5612      ** e.g. we have our own dedicated locks */
  1.5613 -    bool success;
  1.5614 -    malloc_zone_t* newzone = malloc_create_zone(4096, 0);
  1.5615 -    malloc_set_zone_name(newzone, "Sqlite_Heap");
  1.5616 -    do{
  1.5617 -      success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone, 
  1.5618 -                                 (void * volatile *)&_sqliteZone_);
  1.5619 -    }while(!_sqliteZone_);
  1.5620 -    if( !success ){
  1.5621 -      /* somebody registered a zone first */
  1.5622 -      malloc_destroy_zone(newzone);
  1.5623 -    }
  1.5624 -  }
  1.5625 -#endif
  1.5626 +    _sqliteZone_ = malloc_create_zone(4096, 0);
  1.5627 +    malloc_set_zone_name(_sqliteZone_, "Sqlite_Heap");
  1.5628 +  }
  1.5629 +#endif /*  defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC) */
  1.5630    UNUSED_PARAMETER(NotUsed);
  1.5631    return SQLITE_OK;
  1.5632  }
  1.5633 @@ -22224,7 +22828,7 @@
  1.5634  /*
  1.5635  ** Retrieve a pointer to a static mutex or allocate a new dynamic one.
  1.5636  */
  1.5637 -SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_mutex_alloc(int id){
  1.5638 +SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int id){
  1.5639  #ifndef SQLITE_OMIT_AUTOINIT
  1.5640    if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0;
  1.5641    if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0;
  1.5642 @@ -22245,7 +22849,7 @@
  1.5643  /*
  1.5644  ** Free a dynamic mutex.
  1.5645  */
  1.5646 -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_free(sqlite3_mutex *p){
  1.5647 +SQLITE_API void sqlite3_mutex_free(sqlite3_mutex *p){
  1.5648    if( p ){
  1.5649      assert( sqlite3GlobalConfig.mutex.xMutexFree );
  1.5650      sqlite3GlobalConfig.mutex.xMutexFree(p);
  1.5651 @@ -22256,7 +22860,7 @@
  1.5652  ** Obtain the mutex p. If some other thread already has the mutex, block
  1.5653  ** until it can be obtained.
  1.5654  */
  1.5655 -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_enter(sqlite3_mutex *p){
  1.5656 +SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex *p){
  1.5657    if( p ){
  1.5658      assert( sqlite3GlobalConfig.mutex.xMutexEnter );
  1.5659      sqlite3GlobalConfig.mutex.xMutexEnter(p);
  1.5660 @@ -22267,7 +22871,7 @@
  1.5661  ** Obtain the mutex p. If successful, return SQLITE_OK. Otherwise, if another
  1.5662  ** thread holds the mutex and it cannot be obtained, return SQLITE_BUSY.
  1.5663  */
  1.5664 -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_try(sqlite3_mutex *p){
  1.5665 +SQLITE_API int sqlite3_mutex_try(sqlite3_mutex *p){
  1.5666    int rc = SQLITE_OK;
  1.5667    if( p ){
  1.5668      assert( sqlite3GlobalConfig.mutex.xMutexTry );
  1.5669 @@ -22282,7 +22886,7 @@
  1.5670  ** is not currently entered. If a NULL pointer is passed as an argument
  1.5671  ** this function is a no-op.
  1.5672  */
  1.5673 -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_leave(sqlite3_mutex *p){
  1.5674 +SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex *p){
  1.5675    if( p ){
  1.5676      assert( sqlite3GlobalConfig.mutex.xMutexLeave );
  1.5677      sqlite3GlobalConfig.mutex.xMutexLeave(p);
  1.5678 @@ -22294,11 +22898,11 @@
  1.5679  ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
  1.5680  ** intended for use inside assert() statements.
  1.5681  */
  1.5682 -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_held(sqlite3_mutex *p){
  1.5683 +SQLITE_API int sqlite3_mutex_held(sqlite3_mutex *p){
  1.5684    assert( p==0 || sqlite3GlobalConfig.mutex.xMutexHeld );
  1.5685    return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p);
  1.5686  }
  1.5687 -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_notheld(sqlite3_mutex *p){
  1.5688 +SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex *p){
  1.5689    assert( p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld );
  1.5690    return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p);
  1.5691  }
  1.5692 @@ -22995,8 +23599,8 @@
  1.5693  ** This file contains inline asm code for retrieving "high-performance"
  1.5694  ** counters for x86 class CPUs.
  1.5695  */
  1.5696 -#ifndef _HWTIME_H_
  1.5697 -#define _HWTIME_H_
  1.5698 +#ifndef SQLITE_HWTIME_H
  1.5699 +#define SQLITE_HWTIME_H
  1.5700  
  1.5701  /*
  1.5702  ** The following routine only works on pentium-class (or newer) processors.
  1.5703 @@ -23064,7 +23668,7 @@
  1.5704  
  1.5705  #endif
  1.5706  
  1.5707 -#endif /* !defined(_HWTIME_H_) */
  1.5708 +#endif /* !defined(SQLITE_HWTIME_H) */
  1.5709  
  1.5710  /************** End of hwtime.h **********************************************/
  1.5711  /************** Continuing where we left off in os_common.h ******************/
  1.5712 @@ -23154,8 +23758,8 @@
  1.5713  **
  1.5714  ** This file contains code that is specific to Windows.
  1.5715  */
  1.5716 -#ifndef _OS_WIN_H_
  1.5717 -#define _OS_WIN_H_
  1.5718 +#ifndef SQLITE_OS_WIN_H
  1.5719 +#define SQLITE_OS_WIN_H
  1.5720  
  1.5721  /*
  1.5722  ** Include the primary Windows SDK header file.
  1.5723 @@ -23227,7 +23831,7 @@
  1.5724  # define SQLITE_OS_WIN_THREADS 0
  1.5725  #endif
  1.5726  
  1.5727 -#endif /* _OS_WIN_H_ */
  1.5728 +#endif /* SQLITE_OS_WIN_H */
  1.5729  
  1.5730  /************** End of os_win.h **********************************************/
  1.5731  /************** Continuing where we left off in mutex_w32.c ******************/
  1.5732 @@ -23295,8 +23899,7 @@
  1.5733    SQLITE_MEMORY_BARRIER;
  1.5734  #elif defined(__GNUC__)
  1.5735    __sync_synchronize();
  1.5736 -#elif !defined(SQLITE_DISABLE_INTRINSIC) && \
  1.5737 -      defined(_MSC_VER) && _MSC_VER>=1300
  1.5738 +#elif MSVC_VERSION>=1300
  1.5739    _ReadWriteBarrier();
  1.5740  #elif defined(MemoryBarrier)
  1.5741    MemoryBarrier();
  1.5742 @@ -23330,8 +23933,8 @@
  1.5743  */
  1.5744  static LONG SQLITE_WIN32_VOLATILE winMutex_lock = 0;
  1.5745  
  1.5746 -SQLITE_API int SQLITE_STDCALL sqlite3_win32_is_nt(void); /* os_win.c */
  1.5747 -SQLITE_API void SQLITE_STDCALL sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */
  1.5748 +SQLITE_API int sqlite3_win32_is_nt(void); /* os_win.c */
  1.5749 +SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */
  1.5750  
  1.5751  static int winMutexInit(void){
  1.5752    /* The first to increment to 1 does actual initialization */
  1.5753 @@ -23507,8 +24110,8 @@
  1.5754    p->owner = tid;
  1.5755    p->nRef++;
  1.5756    if( p->trace ){
  1.5757 -    OSTRACE(("ENTER-MUTEX tid=%lu, mutex=%p (%d), nRef=%d\n",
  1.5758 -             tid, p, p->trace, p->nRef));
  1.5759 +    OSTRACE(("ENTER-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n",
  1.5760 +             tid, p->id, p, p->trace, p->nRef));
  1.5761    }
  1.5762  #endif
  1.5763  }
  1.5764 @@ -23550,8 +24153,8 @@
  1.5765  #endif
  1.5766  #ifdef SQLITE_DEBUG
  1.5767    if( p->trace ){
  1.5768 -    OSTRACE(("TRY-MUTEX tid=%lu, mutex=%p (%d), owner=%lu, nRef=%d, rc=%s\n",
  1.5769 -             tid, p, p->trace, p->owner, p->nRef, sqlite3ErrName(rc)));
  1.5770 +    OSTRACE(("TRY-MUTEX tid=%lu, mutex(%d)=%p (%d), owner=%lu, nRef=%d, rc=%s\n",
  1.5771 +             tid, p->id, p, p->trace, p->owner, p->nRef, sqlite3ErrName(rc)));
  1.5772    }
  1.5773  #endif
  1.5774    return rc;
  1.5775 @@ -23579,8 +24182,8 @@
  1.5776    LeaveCriticalSection(&p->mutex);
  1.5777  #ifdef SQLITE_DEBUG
  1.5778    if( p->trace ){
  1.5779 -    OSTRACE(("LEAVE-MUTEX tid=%lu, mutex=%p (%d), nRef=%d\n",
  1.5780 -             tid, p, p->trace, p->nRef));
  1.5781 +    OSTRACE(("LEAVE-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n",
  1.5782 +             tid, p->id, p, p->trace, p->nRef));
  1.5783    }
  1.5784  #endif
  1.5785  }
  1.5786 @@ -23631,7 +24234,7 @@
  1.5787  ** held by SQLite. An example of non-essential memory is memory used to
  1.5788  ** cache database pages that are not currently in use.
  1.5789  */
  1.5790 -SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int n){
  1.5791 +SQLITE_API int sqlite3_release_memory(int n){
  1.5792  #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
  1.5793    return sqlite3PcacheReleaseMemory(n);
  1.5794  #else
  1.5795 @@ -23690,7 +24293,7 @@
  1.5796  ** that was invoked when memory usage grew too large.  Now it is a
  1.5797  ** no-op.
  1.5798  */
  1.5799 -SQLITE_API int SQLITE_STDCALL sqlite3_memory_alarm(
  1.5800 +SQLITE_API int sqlite3_memory_alarm(
  1.5801    void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
  1.5802    void *pArg,
  1.5803    sqlite3_int64 iThreshold
  1.5804 @@ -23706,7 +24309,7 @@
  1.5805  ** Set the soft heap-size limit for the library. Passing a zero or 
  1.5806  ** negative value indicates no limit.
  1.5807  */
  1.5808 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_soft_heap_limit64(sqlite3_int64 n){
  1.5809 +SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 n){
  1.5810    sqlite3_int64 priorLimit;
  1.5811    sqlite3_int64 excess;
  1.5812    sqlite3_int64 nUsed;
  1.5813 @@ -23728,7 +24331,7 @@
  1.5814    if( excess>0 ) sqlite3_release_memory((int)(excess & 0x7fffffff));
  1.5815    return priorLimit;
  1.5816  }
  1.5817 -SQLITE_API void SQLITE_STDCALL sqlite3_soft_heap_limit(int n){
  1.5818 +SQLITE_API void sqlite3_soft_heap_limit(int n){
  1.5819    if( n<0 ) n = 0;
  1.5820    sqlite3_soft_heap_limit64(n);
  1.5821  }
  1.5822 @@ -23797,7 +24400,7 @@
  1.5823  /*
  1.5824  ** Return the amount of memory currently checked out.
  1.5825  */
  1.5826 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_used(void){
  1.5827 +SQLITE_API sqlite3_int64 sqlite3_memory_used(void){
  1.5828    sqlite3_int64 res, mx;
  1.5829    sqlite3_status64(SQLITE_STATUS_MEMORY_USED, &res, &mx, 0);
  1.5830    return res;
  1.5831 @@ -23808,7 +24411,7 @@
  1.5832  ** checked out since either the beginning of this process
  1.5833  ** or since the most recent reset.
  1.5834  */
  1.5835 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_highwater(int resetFlag){
  1.5836 +SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag){
  1.5837    sqlite3_int64 res, mx;
  1.5838    sqlite3_status64(SQLITE_STATUS_MEMORY_USED, &res, &mx, resetFlag);
  1.5839    return mx;
  1.5840 @@ -23828,11 +24431,26 @@
  1.5841  ** Do a memory allocation with statistics and alarms.  Assume the
  1.5842  ** lock is already held.
  1.5843  */
  1.5844 -static int mallocWithAlarm(int n, void **pp){
  1.5845 +static void mallocWithAlarm(int n, void **pp){
  1.5846 +  void *p;
  1.5847    int nFull;
  1.5848 -  void *p;
  1.5849    assert( sqlite3_mutex_held(mem0.mutex) );
  1.5850 +  assert( n>0 );
  1.5851 +
  1.5852 +  /* In Firefox (circa 2017-02-08), xRoundup() is remapped to an internal
  1.5853 +  ** implementation of malloc_good_size(), which must be called in debug
  1.5854 +  ** mode and specifically when the DMD "Dark Matter Detector" is enabled
  1.5855 +  ** or else a crash results.  Hence, do not attempt to optimize out the
  1.5856 +  ** following xRoundup() call. */
  1.5857    nFull = sqlite3GlobalConfig.m.xRoundup(n);
  1.5858 +
  1.5859 +#ifdef SQLITE_MAX_MEMORY
  1.5860 +  if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nFull>SQLITE_MAX_MEMORY ){
  1.5861 +    *pp = 0;
  1.5862 +    return;
  1.5863 +  }
  1.5864 +#endif
  1.5865 +
  1.5866    sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n);
  1.5867    if( mem0.alarmThreshold>0 ){
  1.5868      sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
  1.5869 @@ -23856,7 +24474,6 @@
  1.5870      sqlite3StatusUp(SQLITE_STATUS_MALLOC_COUNT, 1);
  1.5871    }
  1.5872    *pp = p;
  1.5873 -  return nFull;
  1.5874  }
  1.5875  
  1.5876  /*
  1.5877 @@ -23888,13 +24505,13 @@
  1.5878  ** First make sure the memory subsystem is initialized, then do the
  1.5879  ** allocation.
  1.5880  */
  1.5881 -SQLITE_API void *SQLITE_STDCALL sqlite3_malloc(int n){
  1.5882 +SQLITE_API void *sqlite3_malloc(int n){
  1.5883  #ifndef SQLITE_OMIT_AUTOINIT
  1.5884    if( sqlite3_initialize() ) return 0;
  1.5885  #endif
  1.5886    return n<=0 ? 0 : sqlite3Malloc(n);
  1.5887  }
  1.5888 -SQLITE_API void *SQLITE_STDCALL sqlite3_malloc64(sqlite3_uint64 n){
  1.5889 +SQLITE_API void *sqlite3_malloc64(sqlite3_uint64 n){
  1.5890  #ifndef SQLITE_OMIT_AUTOINIT
  1.5891    if( sqlite3_initialize() ) return 0;
  1.5892  #endif
  1.5893 @@ -24022,7 +24639,7 @@
  1.5894  SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
  1.5895    assert( p!=0 );
  1.5896    if( db==0 || !isLookaside(db,p) ){
  1.5897 -#if SQLITE_DEBUG
  1.5898 +#ifdef SQLITE_DEBUG
  1.5899      if( db==0 ){
  1.5900        assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
  1.5901        assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
  1.5902 @@ -24037,7 +24654,7 @@
  1.5903      return db->lookaside.sz;
  1.5904    }
  1.5905  }
  1.5906 -SQLITE_API sqlite3_uint64 SQLITE_STDCALL sqlite3_msize(void *p){
  1.5907 +SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){
  1.5908    assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
  1.5909    assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
  1.5910    return p ? sqlite3GlobalConfig.m.xSize(p) : 0;
  1.5911 @@ -24046,7 +24663,7 @@
  1.5912  /*
  1.5913  ** Free memory previously obtained from sqlite3Malloc().
  1.5914  */
  1.5915 -SQLITE_API void SQLITE_STDCALL sqlite3_free(void *p){
  1.5916 +SQLITE_API void sqlite3_free(void *p){
  1.5917    if( p==0 ) return;  /* IMP: R-49053-54554 */
  1.5918    assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
  1.5919    assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
  1.5920 @@ -24071,11 +24688,12 @@
  1.5921  
  1.5922  /*
  1.5923  ** Free memory that might be associated with a particular database
  1.5924 -** connection.
  1.5925 -*/
  1.5926 -SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
  1.5927 +** connection.  Calling sqlite3DbFree(D,X) for X==0 is a harmless no-op.
  1.5928 +** The sqlite3DbFreeNN(D,X) version requires that X be non-NULL.
  1.5929 +*/
  1.5930 +SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3 *db, void *p){
  1.5931    assert( db==0 || sqlite3_mutex_held(db->mutex) );
  1.5932 -  if( p==0 ) return;
  1.5933 +  assert( p!=0 );
  1.5934    if( db ){
  1.5935      if( db->pnBytesFreed ){
  1.5936        measureAllocationSize(db, p);
  1.5937 @@ -24083,7 +24701,7 @@
  1.5938      }
  1.5939      if( isLookaside(db, p) ){
  1.5940        LookasideSlot *pBuf = (LookasideSlot*)p;
  1.5941 -#if SQLITE_DEBUG
  1.5942 +#ifdef SQLITE_DEBUG
  1.5943        /* Trash all content in the buffer being freed */
  1.5944        memset(p, 0xaa, db->lookaside.sz);
  1.5945  #endif
  1.5946 @@ -24099,6 +24717,10 @@
  1.5947    sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
  1.5948    sqlite3_free(p);
  1.5949  }
  1.5950 +SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
  1.5951 +  assert( db==0 || sqlite3_mutex_held(db->mutex) );
  1.5952 +  if( p ) sqlite3DbFreeNN(db, p);
  1.5953 +}
  1.5954  
  1.5955  /*
  1.5956  ** Change the size of an existing memory allocation
  1.5957 @@ -24130,7 +24752,7 @@
  1.5958      sqlite3_mutex_enter(mem0.mutex);
  1.5959      sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, (int)nBytes);
  1.5960      nDiff = nNew - nOld;
  1.5961 -    if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= 
  1.5962 +    if( nDiff>0 && sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= 
  1.5963            mem0.alarmThreshold-nDiff ){
  1.5964        sqlite3MallocAlarm(nDiff);
  1.5965      }
  1.5966 @@ -24155,14 +24777,14 @@
  1.5967  ** The public interface to sqlite3Realloc.  Make sure that the memory
  1.5968  ** subsystem is initialized prior to invoking sqliteRealloc.
  1.5969  */
  1.5970 -SQLITE_API void *SQLITE_STDCALL sqlite3_realloc(void *pOld, int n){
  1.5971 +SQLITE_API void *sqlite3_realloc(void *pOld, int n){
  1.5972  #ifndef SQLITE_OMIT_AUTOINIT
  1.5973    if( sqlite3_initialize() ) return 0;
  1.5974  #endif
  1.5975    if( n<0 ) n = 0;  /* IMP: R-26507-47431 */
  1.5976    return sqlite3Realloc(pOld, n);
  1.5977  }
  1.5978 -SQLITE_API void *SQLITE_STDCALL sqlite3_realloc64(void *pOld, sqlite3_uint64 n){
  1.5979 +SQLITE_API void *sqlite3_realloc64(void *pOld, sqlite3_uint64 n){
  1.5980  #ifndef SQLITE_OMIT_AUTOINIT
  1.5981    if( sqlite3_initialize() ) return 0;
  1.5982  #endif
  1.5983 @@ -24337,9 +24959,8 @@
  1.5984    if( z==0 ){
  1.5985      return 0;
  1.5986    }
  1.5987 -  n = sqlite3Strlen30(z) + 1;
  1.5988 -  assert( (n&0x7fffffff)==n );
  1.5989 -  zNew = sqlite3DbMallocRaw(db, (int)n);
  1.5990 +  n = strlen(z) + 1;
  1.5991 +  zNew = sqlite3DbMallocRaw(db, n);
  1.5992    if( zNew ){
  1.5993      memcpy(zNew, z, n);
  1.5994    }
  1.5995 @@ -24453,7 +25074,7 @@
  1.5996  ** Conversion types fall into various categories as defined by the
  1.5997  ** following enumeration.
  1.5998  */
  1.5999 -#define etRADIX       0 /* Integer types.  %d, %x, %o, and so forth */
  1.6000 +#define etRADIX       0 /* non-decimal integer types.  %x %o */
  1.6001  #define etFLOAT       1 /* Floating point.  %f */
  1.6002  #define etEXP         2 /* Exponentional notation. %e and %E */
  1.6003  #define etGENERIC     3 /* Floating or exponential, depending on exponent. %g */
  1.6004 @@ -24471,8 +25092,9 @@
  1.6005  #define etPOINTER    13 /* The %p conversion */
  1.6006  #define etSQLESCAPE3 14 /* %w -> Strings with '\"' doubled */
  1.6007  #define etORDINAL    15 /* %r -> 1st, 2nd, 3rd, 4th, etc.  English only */
  1.6008 -
  1.6009 -#define etINVALID    16 /* Any unrecognized conversion type */
  1.6010 +#define etDECIMAL    16 /* %d or %u, but not %x, %o */
  1.6011 +
  1.6012 +#define etINVALID    17 /* Any unrecognized conversion type */
  1.6013  
  1.6014  
  1.6015  /*
  1.6016 @@ -24496,9 +25118,8 @@
  1.6017  /*
  1.6018  ** Allowed values for et_info.flags
  1.6019  */
  1.6020 -#define FLAG_SIGNED  1     /* True if the value to convert is signed */
  1.6021 -#define FLAG_INTERN  2     /* True if for internal use only */
  1.6022 -#define FLAG_STRING  4     /* Allow infinity precision */
  1.6023 +#define FLAG_SIGNED    1     /* True if the value to convert is signed */
  1.6024 +#define FLAG_STRING    4     /* Allow infinite precision */
  1.6025  
  1.6026  
  1.6027  /*
  1.6028 @@ -24508,7 +25129,7 @@
  1.6029  static const char aDigits[] = "0123456789ABCDEF0123456789abcdef";
  1.6030  static const char aPrefix[] = "-x0\000X0";
  1.6031  static const et_info fmtinfo[] = {
  1.6032 -  {  'd', 10, 1, etRADIX,      0,  0 },
  1.6033 +  {  'd', 10, 1, etDECIMAL,    0,  0 },
  1.6034    {  's',  0, 4, etSTRING,     0,  0 },
  1.6035    {  'g',  0, 1, etGENERIC,    30, 0 },
  1.6036    {  'z',  0, 4, etDYNSTRING,  0,  0 },
  1.6037 @@ -24517,7 +25138,7 @@
  1.6038    {  'w',  0, 4, etSQLESCAPE3, 0,  0 },
  1.6039    {  'c',  0, 0, etCHARX,      0,  0 },
  1.6040    {  'o',  8, 0, etRADIX,      0,  2 },
  1.6041 -  {  'u', 10, 0, etRADIX,      0,  0 },
  1.6042 +  {  'u', 10, 0, etDECIMAL,    0,  0 },
  1.6043    {  'x', 16, 0, etRADIX,      16, 1 },
  1.6044    {  'X', 16, 0, etRADIX,      0,  4 },
  1.6045  #ifndef SQLITE_OMIT_FLOATING_POINT
  1.6046 @@ -24526,16 +25147,15 @@
  1.6047    {  'E',  0, 1, etEXP,        14, 0 },
  1.6048    {  'G',  0, 1, etGENERIC,    14, 0 },
  1.6049  #endif
  1.6050 -  {  'i', 10, 1, etRADIX,      0,  0 },
  1.6051 +  {  'i', 10, 1, etDECIMAL,    0,  0 },
  1.6052    {  'n',  0, 0, etSIZE,       0,  0 },
  1.6053    {  '%',  0, 0, etPERCENT,    0,  0 },
  1.6054    {  'p', 16, 0, etPOINTER,    0,  1 },
  1.6055  
  1.6056 -/* All the rest have the FLAG_INTERN bit set and are thus for internal
  1.6057 -** use only */
  1.6058 -  {  'T',  0, 2, etTOKEN,      0,  0 },
  1.6059 -  {  'S',  0, 2, etSRCLIST,    0,  0 },
  1.6060 -  {  'r', 10, 3, etORDINAL,    0,  0 },
  1.6061 +  /* All the rest are undocumented and are for internal use only */
  1.6062 +  {  'T',  0, 0, etTOKEN,      0,  0 },
  1.6063 +  {  'S',  0, 0, etSRCLIST,    0,  0 },
  1.6064 +  {  'r', 10, 1, etORDINAL,    0,  0 },
  1.6065  };
  1.6066  
  1.6067  /*
  1.6068 @@ -24619,17 +25239,15 @@
  1.6069    int idx;                   /* A general purpose loop counter */
  1.6070    int width;                 /* Width of the current field */
  1.6071    etByte flag_leftjustify;   /* True if "-" flag is present */
  1.6072 -  etByte flag_plussign;      /* True if "+" flag is present */
  1.6073 -  etByte flag_blanksign;     /* True if " " flag is present */
  1.6074 +  etByte flag_prefix;        /* '+' or ' ' or 0 for prefix */
  1.6075    etByte flag_alternateform; /* True if "#" flag is present */
  1.6076    etByte flag_altform2;      /* True if "!" flag is present */
  1.6077    etByte flag_zeropad;       /* True if field width constant starts with zero */
  1.6078 -  etByte flag_long;          /* True if "l" flag is present */
  1.6079 -  etByte flag_longlong;      /* True if the "ll" flag is present */
  1.6080 +  etByte flag_long;          /* 1 for the "l" flag, 2 for "ll", 0 by default */
  1.6081    etByte done;               /* Loop termination flag */
  1.6082 +  etByte cThousand;          /* Thousands separator for %d and %u */
  1.6083    etByte xtype = etINVALID;  /* Conversion paradigm */
  1.6084    u8 bArgList;               /* True for SQLITE_PRINTF_SQLFUNC */
  1.6085 -  u8 useIntern;              /* Ok to use internal conversions (ex: %T) */
  1.6086    char prefix;               /* Prefix character.  "+" or "-" or " " or '\0'. */
  1.6087    sqlite_uint64 longvalue;   /* Value for integer types */
  1.6088    LONGDOUBLE_TYPE realvalue; /* Value for real types */
  1.6089 @@ -24648,13 +25266,11 @@
  1.6090    char buf[etBUFSIZE];       /* Conversion buffer */
  1.6091  
  1.6092    bufpt = 0;
  1.6093 -  if( pAccum->printfFlags ){
  1.6094 -    if( (bArgList = (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
  1.6095 -      pArgList = va_arg(ap, PrintfArguments*);
  1.6096 -    }
  1.6097 -    useIntern = pAccum->printfFlags & SQLITE_PRINTF_INTERNAL;
  1.6098 -  }else{
  1.6099 -    bArgList = useIntern = 0;
  1.6100 +  if( (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC)!=0 ){
  1.6101 +    pArgList = va_arg(ap, PrintfArguments*);
  1.6102 +    bArgList = 1;
  1.6103 +  }else{
  1.6104 +    bArgList = 0;
  1.6105    }
  1.6106    for(; (c=(*fmt))!=0; ++fmt){
  1.6107      if( c!='%' ){
  1.6108 @@ -24672,17 +25288,18 @@
  1.6109        break;
  1.6110      }
  1.6111      /* Find out what flags are present */
  1.6112 -    flag_leftjustify = flag_plussign = flag_blanksign = 
  1.6113 +    flag_leftjustify = flag_prefix = cThousand =
  1.6114       flag_alternateform = flag_altform2 = flag_zeropad = 0;
  1.6115      done = 0;
  1.6116      do{
  1.6117        switch( c ){
  1.6118          case '-':   flag_leftjustify = 1;     break;
  1.6119 -        case '+':   flag_plussign = 1;        break;
  1.6120 -        case ' ':   flag_blanksign = 1;       break;
  1.6121 +        case '+':   flag_prefix = '+';        break;
  1.6122 +        case ' ':   flag_prefix = ' ';        break;
  1.6123          case '#':   flag_alternateform = 1;   break;
  1.6124          case '!':   flag_altform2 = 1;        break;
  1.6125          case '0':   flag_zeropad = 1;         break;
  1.6126 +        case ',':   cThousand = ',';          break;
  1.6127          default:    done = 1;                 break;
  1.6128        }
  1.6129      }while( !done && (c=(*++fmt))!=0 );
  1.6130 @@ -24752,13 +25369,11 @@
  1.6131        flag_long = 1;
  1.6132        c = *++fmt;
  1.6133        if( c=='l' ){
  1.6134 -        flag_longlong = 1;
  1.6135 +        flag_long = 2;
  1.6136          c = *++fmt;
  1.6137 -      }else{
  1.6138 -        flag_longlong = 0;
  1.6139 -      }
  1.6140 -    }else{
  1.6141 -      flag_long = flag_longlong = 0;
  1.6142 +      }
  1.6143 +    }else{
  1.6144 +      flag_long = 0;
  1.6145      }
  1.6146      /* Fetch the info entry for the field */
  1.6147      infop = &fmtinfo[0];
  1.6148 @@ -24766,11 +25381,7 @@
  1.6149      for(idx=0; idx<ArraySize(fmtinfo); idx++){
  1.6150        if( c==fmtinfo[idx].fmttype ){
  1.6151          infop = &fmtinfo[idx];
  1.6152 -        if( useIntern || (infop->flags & FLAG_INTERN)==0 ){
  1.6153 -          xtype = infop->type;
  1.6154 -        }else{
  1.6155 -          return;
  1.6156 -        }
  1.6157 +        xtype = infop->type;
  1.6158          break;
  1.6159        }
  1.6160      }
  1.6161 @@ -24780,15 +25391,11 @@
  1.6162      **
  1.6163      **   flag_alternateform          TRUE if a '#' is present.
  1.6164      **   flag_altform2               TRUE if a '!' is present.
  1.6165 -    **   flag_plussign               TRUE if a '+' is present.
  1.6166 +    **   flag_prefix                 '+' or ' ' or zero
  1.6167      **   flag_leftjustify            TRUE if a '-' is present or if the
  1.6168      **                               field width was negative.
  1.6169      **   flag_zeropad                TRUE if the width began with 0.
  1.6170 -    **   flag_long                   TRUE if the letter 'l' (ell) prefixed
  1.6171 -    **                               the conversion character.
  1.6172 -    **   flag_longlong               TRUE if the letter 'll' (ell ell) prefixed
  1.6173 -    **                               the conversion character.
  1.6174 -    **   flag_blanksign              TRUE if a ' ' is present.
  1.6175 +    **   flag_long                   1 for "l", 2 for "ll"
  1.6176      **   width                       The specified field width.  This is
  1.6177      **                               always non-negative.  Zero is the default.
  1.6178      **   precision                   The specified precision.  The default
  1.6179 @@ -24798,19 +25405,24 @@
  1.6180      */
  1.6181      switch( xtype ){
  1.6182        case etPOINTER:
  1.6183 -        flag_longlong = sizeof(char*)==sizeof(i64);
  1.6184 -        flag_long = sizeof(char*)==sizeof(long int);
  1.6185 +        flag_long = sizeof(char*)==sizeof(i64) ? 2 :
  1.6186 +                     sizeof(char*)==sizeof(long int) ? 1 : 0;
  1.6187          /* Fall through into the next case */
  1.6188        case etORDINAL:
  1.6189 -      case etRADIX:
  1.6190 +      case etRADIX:      
  1.6191 +        cThousand = 0;
  1.6192 +        /* Fall through into the next case */
  1.6193 +      case etDECIMAL:
  1.6194          if( infop->flags & FLAG_SIGNED ){
  1.6195            i64 v;
  1.6196            if( bArgList ){
  1.6197              v = getIntArg(pArgList);
  1.6198 -          }else if( flag_longlong ){
  1.6199 -            v = va_arg(ap,i64);
  1.6200            }else if( flag_long ){
  1.6201 -            v = va_arg(ap,long int);
  1.6202 +            if( flag_long==2 ){
  1.6203 +              v = va_arg(ap,i64) ;
  1.6204 +            }else{
  1.6205 +              v = va_arg(ap,long int);
  1.6206 +            }
  1.6207            }else{
  1.6208              v = va_arg(ap,int);
  1.6209            }
  1.6210 @@ -24823,17 +25435,17 @@
  1.6211              prefix = '-';
  1.6212            }else{
  1.6213              longvalue = v;
  1.6214 -            if( flag_plussign )        prefix = '+';
  1.6215 -            else if( flag_blanksign )  prefix = ' ';
  1.6216 -            else                       prefix = 0;
  1.6217 +            prefix = flag_prefix;
  1.6218            }
  1.6219          }else{
  1.6220            if( bArgList ){
  1.6221              longvalue = (u64)getIntArg(pArgList);
  1.6222 -          }else if( flag_longlong ){
  1.6223 -            longvalue = va_arg(ap,u64);
  1.6224            }else if( flag_long ){
  1.6225 -            longvalue = va_arg(ap,unsigned long int);
  1.6226 +            if( flag_long==2 ){
  1.6227 +              longvalue = va_arg(ap,u64);
  1.6228 +            }else{
  1.6229 +              longvalue = va_arg(ap,unsigned long int);
  1.6230 +            }
  1.6231            }else{
  1.6232              longvalue = va_arg(ap,unsigned int);
  1.6233            }
  1.6234 @@ -24843,16 +25455,17 @@
  1.6235          if( flag_zeropad && precision<width-(prefix!=0) ){
  1.6236            precision = width-(prefix!=0);
  1.6237          }
  1.6238 -        if( precision<etBUFSIZE-10 ){
  1.6239 +        if( precision<etBUFSIZE-10-etBUFSIZE/3 ){
  1.6240            nOut = etBUFSIZE;
  1.6241            zOut = buf;
  1.6242          }else{
  1.6243 -          nOut = precision + 10;
  1.6244 -          zOut = zExtra = sqlite3Malloc( nOut );
  1.6245 +          u64 n = (u64)precision + 10 + precision/3;
  1.6246 +          zOut = zExtra = sqlite3Malloc( n );
  1.6247            if( zOut==0 ){
  1.6248              setStrAccumError(pAccum, STRACCUM_NOMEM);
  1.6249              return;
  1.6250            }
  1.6251 +          nOut = (int)n;
  1.6252          }
  1.6253          bufpt = &zOut[nOut-1];
  1.6254          if( xtype==etORDINAL ){
  1.6255 @@ -24873,8 +25486,23 @@
  1.6256            }while( longvalue>0 );
  1.6257          }
  1.6258          length = (int)(&zOut[nOut-1]-bufpt);
  1.6259 -        for(idx=precision-length; idx>0; idx--){
  1.6260 +        while( precision>length ){
  1.6261            *(--bufpt) = '0';                             /* Zero pad */
  1.6262 +          length++;
  1.6263 +        }
  1.6264 +        if( cThousand ){
  1.6265 +          int nn = (length - 1)/3;  /* Number of "," to insert */
  1.6266 +          int ix = (length - 1)%3 + 1;
  1.6267 +          bufpt -= nn;
  1.6268 +          for(idx=0; nn>0; idx++){
  1.6269 +            bufpt[idx] = bufpt[idx+nn];
  1.6270 +            ix--;
  1.6271 +            if( ix==0 ){
  1.6272 +              bufpt[++idx] = cThousand;
  1.6273 +              nn--;
  1.6274 +              ix = 3;
  1.6275 +            }
  1.6276 +          }
  1.6277          }
  1.6278          if( prefix ) *(--bufpt) = prefix;               /* Add sign */
  1.6279          if( flag_alternateform && infop->prefix ){      /* Add "0" or "0x" */
  1.6280 @@ -24901,9 +25529,7 @@
  1.6281            realvalue = -realvalue;
  1.6282            prefix = '-';
  1.6283          }else{
  1.6284 -          if( flag_plussign )          prefix = '+';
  1.6285 -          else if( flag_blanksign )    prefix = ' ';
  1.6286 -          else                         prefix = 0;
  1.6287 +          prefix = flag_prefix;
  1.6288          }
  1.6289          if( xtype==etGENERIC && precision>0 ) precision--;
  1.6290          testcase( precision>0xfff );
  1.6291 @@ -25139,7 +25765,9 @@
  1.6292          break;
  1.6293        }
  1.6294        case etTOKEN: {
  1.6295 -        Token *pToken = va_arg(ap, Token*);
  1.6296 +        Token *pToken;
  1.6297 +        if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
  1.6298 +        pToken = va_arg(ap, Token*);
  1.6299          assert( bArgList==0 );
  1.6300          if( pToken && pToken->n ){
  1.6301            sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
  1.6302 @@ -25148,9 +25776,13 @@
  1.6303          break;
  1.6304        }
  1.6305        case etSRCLIST: {
  1.6306 -        SrcList *pSrc = va_arg(ap, SrcList*);
  1.6307 -        int k = va_arg(ap, int);
  1.6308 -        struct SrcList_item *pItem = &pSrc->a[k];
  1.6309 +        SrcList *pSrc;
  1.6310 +        int k;
  1.6311 +        struct SrcList_item *pItem;
  1.6312 +        if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
  1.6313 +        pSrc = va_arg(ap, SrcList*);
  1.6314 +        k = va_arg(ap, int);
  1.6315 +        pItem = &pSrc->a[k];
  1.6316          assert( bArgList==0 );
  1.6317          assert( k>=0 && k<pSrc->nSrc );
  1.6318          if( pItem->zDatabase ){
  1.6319 @@ -25172,9 +25804,13 @@
  1.6320      ** the output.
  1.6321      */
  1.6322      width -= length;
  1.6323 -    if( width>0 && !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
  1.6324 -    sqlite3StrAccumAppend(pAccum, bufpt, length);
  1.6325 -    if( width>0 && flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
  1.6326 +    if( width>0 ){
  1.6327 +      if( !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
  1.6328 +      sqlite3StrAccumAppend(pAccum, bufpt, length);
  1.6329 +      if( flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
  1.6330 +    }else{
  1.6331 +      sqlite3StrAccumAppend(pAccum, bufpt, length);
  1.6332 +    }
  1.6333  
  1.6334      if( zExtra ){
  1.6335        sqlite3DbFree(pAccum->db, zExtra);
  1.6336 @@ -25279,7 +25915,7 @@
  1.6337    assert( p->accError==0 || p->nAlloc==0 );
  1.6338    if( p->nChar+N >= p->nAlloc ){
  1.6339      enlargeAndAppend(p,z,N);
  1.6340 -  }else{
  1.6341 +  }else if( N ){
  1.6342      assert( p->zText );
  1.6343      p->nChar += N;
  1.6344      memcpy(&p->zText[p->nChar-N], z, N);
  1.6345 @@ -25299,18 +25935,23 @@
  1.6346  ** Return a pointer to the resulting string.  Return a NULL
  1.6347  ** pointer if any kind of error was encountered.
  1.6348  */
  1.6349 +static SQLITE_NOINLINE char *strAccumFinishRealloc(StrAccum *p){
  1.6350 +  assert( p->mxAlloc>0 && !isMalloced(p) );
  1.6351 +  p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
  1.6352 +  if( p->zText ){
  1.6353 +    memcpy(p->zText, p->zBase, p->nChar+1);
  1.6354 +    p->printfFlags |= SQLITE_PRINTF_MALLOCED;
  1.6355 +  }else{
  1.6356 +    setStrAccumError(p, STRACCUM_NOMEM);
  1.6357 +  }
  1.6358 +  return p->zText;
  1.6359 +}
  1.6360  SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
  1.6361    if( p->zText ){
  1.6362      assert( (p->zText==p->zBase)==!isMalloced(p) );
  1.6363      p->zText[p->nChar] = 0;
  1.6364      if( p->mxAlloc>0 && !isMalloced(p) ){
  1.6365 -      p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
  1.6366 -      if( p->zText ){
  1.6367 -        memcpy(p->zText, p->zBase, p->nChar+1);
  1.6368 -        p->printfFlags |= SQLITE_PRINTF_MALLOCED;
  1.6369 -      }else{
  1.6370 -        setStrAccumError(p, STRACCUM_NOMEM);
  1.6371 -      }
  1.6372 +      return strAccumFinishRealloc(p);
  1.6373      }
  1.6374    }
  1.6375    return p->zText;
  1.6376 @@ -25389,7 +26030,7 @@
  1.6377  ** Print into memory obtained from sqlite3_malloc().  Omit the internal
  1.6378  ** %-conversion extensions.
  1.6379  */
  1.6380 -SQLITE_API char *SQLITE_STDCALL sqlite3_vmprintf(const char *zFormat, va_list ap){
  1.6381 +SQLITE_API char *sqlite3_vmprintf(const char *zFormat, va_list ap){
  1.6382    char *z;
  1.6383    char zBase[SQLITE_PRINT_BUF_SIZE];
  1.6384    StrAccum acc;
  1.6385 @@ -25413,7 +26054,7 @@
  1.6386  ** Print into memory obtained from sqlite3_malloc()().  Omit the internal
  1.6387  ** %-conversion extensions.
  1.6388  */
  1.6389 -SQLITE_API char *SQLITE_CDECL sqlite3_mprintf(const char *zFormat, ...){
  1.6390 +SQLITE_API char *sqlite3_mprintf(const char *zFormat, ...){
  1.6391    va_list ap;
  1.6392    char *z;
  1.6393  #ifndef SQLITE_OMIT_AUTOINIT
  1.6394 @@ -25438,7 +26079,7 @@
  1.6395  **
  1.6396  ** sqlite3_vsnprintf() is the varargs version.
  1.6397  */
  1.6398 -SQLITE_API char *SQLITE_STDCALL sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){
  1.6399 +SQLITE_API char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){
  1.6400    StrAccum acc;
  1.6401    if( n<=0 ) return zBuf;
  1.6402  #ifdef SQLITE_ENABLE_API_ARMOR
  1.6403 @@ -25450,9 +26091,10 @@
  1.6404  #endif
  1.6405    sqlite3StrAccumInit(&acc, 0, zBuf, n, 0);
  1.6406    sqlite3VXPrintf(&acc, zFormat, ap);
  1.6407 -  return sqlite3StrAccumFinish(&acc);
  1.6408 -}
  1.6409 -SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
  1.6410 +  zBuf[acc.nChar] = 0;
  1.6411 +  return zBuf;
  1.6412 +}
  1.6413 +SQLITE_API char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
  1.6414    char *z;
  1.6415    va_list ap;
  1.6416    va_start(ap,zFormat);
  1.6417 @@ -25488,7 +26130,7 @@
  1.6418  /*
  1.6419  ** Format and write a message to the log if logging is enabled.
  1.6420  */
  1.6421 -SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...){
  1.6422 +SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...){
  1.6423    va_list ap;                             /* Vararg list */
  1.6424    if( sqlite3GlobalConfig.xLog ){
  1.6425      va_start(ap, zFormat);
  1.6426 @@ -25598,6 +26240,7 @@
  1.6427    va_start(ap, zFormat);
  1.6428    sqlite3VXPrintf(&acc, zFormat, ap);
  1.6429    va_end(ap);
  1.6430 +  assert( acc.nChar>0 );
  1.6431    if( zBuf[acc.nChar-1]!='\n' ) sqlite3StrAccumAppend(&acc, "\n", 1);
  1.6432    sqlite3StrAccumFinish(&acc);
  1.6433    fprintf(stdout,"%s", zBuf);
  1.6434 @@ -25653,11 +26296,15 @@
  1.6435  
  1.6436  
  1.6437  /*
  1.6438 -** Generate a human-readable description of a the Select object.
  1.6439 +** Generate a human-readable description of a Select object.
  1.6440  */
  1.6441  SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
  1.6442    int n = 0;
  1.6443    int cnt = 0;
  1.6444 +  if( p==0 ){
  1.6445 +    sqlite3TreeViewLine(pView, "nil-SELECT");
  1.6446 +    return;
  1.6447 +  } 
  1.6448    pView = sqlite3TreeViewPush(pView, moreToFollow);
  1.6449    if( p->pWith ){
  1.6450      sqlite3TreeViewWith(pView, p->pWith, 1);
  1.6451 @@ -25766,7 +26413,7 @@
  1.6452  SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
  1.6453    const char *zBinOp = 0;   /* Binary operator */
  1.6454    const char *zUniOp = 0;   /* Unary operator */
  1.6455 -  char zFlgs[30];
  1.6456 +  char zFlgs[60];
  1.6457    pView = sqlite3TreeViewPush(pView, moreToFollow);
  1.6458    if( pExpr==0 ){
  1.6459      sqlite3TreeViewLine(pView, "nil");
  1.6460 @@ -25774,7 +26421,12 @@
  1.6461      return;
  1.6462    }
  1.6463    if( pExpr->flags ){
  1.6464 -    sqlite3_snprintf(sizeof(zFlgs),zFlgs,"  flags=0x%x",pExpr->flags);
  1.6465 +    if( ExprHasProperty(pExpr, EP_FromJoin) ){
  1.6466 +      sqlite3_snprintf(sizeof(zFlgs),zFlgs,"  flags=0x%x iRJT=%d",
  1.6467 +                       pExpr->flags, pExpr->iRightJoinTable);
  1.6468 +    }else{
  1.6469 +      sqlite3_snprintf(sizeof(zFlgs),zFlgs,"  flags=0x%x",pExpr->flags);
  1.6470 +    }
  1.6471    }else{
  1.6472      zFlgs[0] = 0;
  1.6473    }
  1.6474 @@ -25978,6 +26630,26 @@
  1.6475        break;
  1.6476      }
  1.6477  #endif
  1.6478 +    case TK_MATCH: {
  1.6479 +      sqlite3TreeViewLine(pView, "MATCH {%d:%d}%s",
  1.6480 +                          pExpr->iTable, pExpr->iColumn, zFlgs);
  1.6481 +      sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
  1.6482 +      break;
  1.6483 +    }
  1.6484 +    case TK_VECTOR: {
  1.6485 +      sqlite3TreeViewBareExprList(pView, pExpr->x.pList, "VECTOR");
  1.6486 +      break;
  1.6487 +    }
  1.6488 +    case TK_SELECT_COLUMN: {
  1.6489 +      sqlite3TreeViewLine(pView, "SELECT-COLUMN %d", pExpr->iColumn);
  1.6490 +      sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
  1.6491 +      break;
  1.6492 +    }
  1.6493 +    case TK_IF_NULL_ROW: {
  1.6494 +      sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable);
  1.6495 +      sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
  1.6496 +      break;
  1.6497 +    }
  1.6498      default: {
  1.6499        sqlite3TreeViewLine(pView, "op=%d", pExpr->op);
  1.6500        break;
  1.6501 @@ -25994,21 +26666,20 @@
  1.6502    sqlite3TreeViewPop(pView);
  1.6503  }
  1.6504  
  1.6505 +
  1.6506  /*
  1.6507  ** Generate a human-readable explanation of an expression list.
  1.6508  */
  1.6509 -SQLITE_PRIVATE void sqlite3TreeViewExprList(
  1.6510 +SQLITE_PRIVATE void sqlite3TreeViewBareExprList(
  1.6511    TreeView *pView,
  1.6512    const ExprList *pList,
  1.6513 -  u8 moreToFollow,
  1.6514    const char *zLabel
  1.6515  ){
  1.6516 -  int i;
  1.6517 -  pView = sqlite3TreeViewPush(pView, moreToFollow);
  1.6518    if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST";
  1.6519    if( pList==0 ){
  1.6520      sqlite3TreeViewLine(pView, "%s (empty)", zLabel);
  1.6521    }else{
  1.6522 +    int i;
  1.6523      sqlite3TreeViewLine(pView, "%s", zLabel);
  1.6524      for(i=0; i<pList->nExpr; i++){
  1.6525        int j = pList->a[i].u.x.iOrderByCol;
  1.6526 @@ -26020,6 +26691,15 @@
  1.6527        if( j ) sqlite3TreeViewPop(pView);
  1.6528      }
  1.6529    }
  1.6530 +}
  1.6531 +SQLITE_PRIVATE void sqlite3TreeViewExprList(
  1.6532 +  TreeView *pView,
  1.6533 +  const ExprList *pList,
  1.6534 +  u8 moreToFollow,
  1.6535 +  const char *zLabel
  1.6536 +){
  1.6537 +  pView = sqlite3TreeViewPush(pView, moreToFollow);
  1.6538 +  sqlite3TreeViewBareExprList(pView, pList, zLabel);
  1.6539    sqlite3TreeViewPop(pView);
  1.6540  }
  1.6541  
  1.6542 @@ -26059,7 +26739,7 @@
  1.6543  /*
  1.6544  ** Return N random bytes.
  1.6545  */
  1.6546 -SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *pBuf){
  1.6547 +SQLITE_API void sqlite3_randomness(int N, void *pBuf){
  1.6548    unsigned char t;
  1.6549    unsigned char *zBuf = pBuf;
  1.6550  
  1.6551 @@ -26135,7 +26815,7 @@
  1.6552    sqlite3_mutex_leave(mutex);
  1.6553  }
  1.6554  
  1.6555 -#ifndef SQLITE_OMIT_BUILTIN_TEST
  1.6556 +#ifndef SQLITE_UNTESTABLE
  1.6557  /*
  1.6558  ** For testing purposes, we sometimes want to preserve the state of
  1.6559  ** PRNG and restore the PRNG to its saved state at a later time, or
  1.6560 @@ -26160,7 +26840,7 @@
  1.6561      sizeof(sqlite3Prng)
  1.6562    );
  1.6563  }
  1.6564 -#endif /* SQLITE_OMIT_BUILTIN_TEST */
  1.6565 +#endif /* SQLITE_UNTESTABLE */
  1.6566  
  1.6567  /************** End of random.c **********************************************/
  1.6568  /************** Begin file threads.c *****************************************/
  1.6569 @@ -27018,7 +27698,7 @@
  1.6570  ** Return whatever integer value the test callback returns, or return
  1.6571  ** SQLITE_OK if no test callback is installed.
  1.6572  */
  1.6573 -#ifndef SQLITE_OMIT_BUILTIN_TEST
  1.6574 +#ifndef SQLITE_UNTESTABLE
  1.6575  SQLITE_PRIVATE int sqlite3FaultSim(int iTest){
  1.6576    int (*xCallback)(int) = sqlite3GlobalConfig.xTestCallback;
  1.6577    return xCallback ? xCallback(iTest) : SQLITE_OK;
  1.6578 @@ -27262,7 +27942,7 @@
  1.6579  ** case-independent fashion, using the same definition of "case
  1.6580  ** independence" that SQLite uses internally when comparing identifiers.
  1.6581  */
  1.6582 -SQLITE_API int SQLITE_STDCALL sqlite3_stricmp(const char *zLeft, const char *zRight){
  1.6583 +SQLITE_API int sqlite3_stricmp(const char *zLeft, const char *zRight){
  1.6584    if( zLeft==0 ){
  1.6585      return zRight ? -1 : 0;
  1.6586    }else if( zRight==0 ){
  1.6587 @@ -27283,7 +27963,7 @@
  1.6588    }
  1.6589    return c;
  1.6590  }
  1.6591 -SQLITE_API int SQLITE_STDCALL sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){
  1.6592 +SQLITE_API int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){
  1.6593    register unsigned char *a, *b;
  1.6594    if( zLeft==0 ){
  1.6595      return zRight ? -1 : 0;
  1.6596 @@ -27689,6 +28369,7 @@
  1.6597      }
  1.6598    }
  1.6599  #endif
  1.6600 +  if( !sqlite3Isdigit(zNum[0]) ) return 0;
  1.6601    while( zNum[0]=='0' ) zNum++;
  1.6602    for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
  1.6603      v = v*10 + c;
  1.6604 @@ -28116,13 +28797,11 @@
  1.6605    u32 x;
  1.6606    memcpy(&x,p,4);
  1.6607    return x;
  1.6608 -#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
  1.6609 -    && defined(__GNUC__) && GCC_VERSION>=4003000
  1.6610 +#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
  1.6611    u32 x;
  1.6612    memcpy(&x,p,4);
  1.6613    return __builtin_bswap32(x);
  1.6614 -#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
  1.6615 -    && defined(_MSC_VER) && _MSC_VER>=1300
  1.6616 +#elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
  1.6617    u32 x;
  1.6618    memcpy(&x,p,4);
  1.6619    return _byteswap_ulong(x);
  1.6620 @@ -28134,12 +28813,10 @@
  1.6621  SQLITE_PRIVATE void sqlite3Put4byte(unsigned char *p, u32 v){
  1.6622  #if SQLITE_BYTEORDER==4321
  1.6623    memcpy(p,&v,4);
  1.6624 -#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
  1.6625 -    && defined(__GNUC__) && GCC_VERSION>=4003000
  1.6626 +#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
  1.6627    u32 x = __builtin_bswap32(v);
  1.6628    memcpy(p,&x,4);
  1.6629 -#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
  1.6630 -    && defined(_MSC_VER) && _MSC_VER>=1300
  1.6631 +#elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
  1.6632    u32 x = _byteswap_ulong(v);
  1.6633    memcpy(p,&x,4);
  1.6634  #else
  1.6635 @@ -28255,6 +28932,9 @@
  1.6636  ** overflow, leave *pA unchanged and return 1.
  1.6637  */
  1.6638  SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){
  1.6639 +#if GCC_VERSION>=5004000
  1.6640 +  return __builtin_add_overflow(*pA, iB, pA);
  1.6641 +#else
  1.6642    i64 iA = *pA;
  1.6643    testcase( iA==0 ); testcase( iA==1 );
  1.6644    testcase( iB==-1 ); testcase( iB==0 );
  1.6645 @@ -28269,8 +28949,12 @@
  1.6646    }
  1.6647    *pA += iB;
  1.6648    return 0; 
  1.6649 +#endif
  1.6650  }
  1.6651  SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){
  1.6652 +#if GCC_VERSION>=5004000
  1.6653 +  return __builtin_sub_overflow(*pA, iB, pA);
  1.6654 +#else
  1.6655    testcase( iB==SMALLEST_INT64+1 );
  1.6656    if( iB==SMALLEST_INT64 ){
  1.6657      testcase( (*pA)==(-1) ); testcase( (*pA)==0 );
  1.6658 @@ -28280,38 +28964,28 @@
  1.6659    }else{
  1.6660      return sqlite3AddInt64(pA, -iB);
  1.6661    }
  1.6662 -}
  1.6663 -#define TWOPOWER32 (((i64)1)<<32)
  1.6664 -#define TWOPOWER31 (((i64)1)<<31)
  1.6665 +#endif
  1.6666 +}
  1.6667  SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){
  1.6668 +#if GCC_VERSION>=5004000
  1.6669 +  return __builtin_mul_overflow(*pA, iB, pA);
  1.6670 +#else
  1.6671    i64 iA = *pA;
  1.6672 -  i64 iA1, iA0, iB1, iB0, r;
  1.6673 -
  1.6674 -  iA1 = iA/TWOPOWER32;
  1.6675 -  iA0 = iA % TWOPOWER32;
  1.6676 -  iB1 = iB/TWOPOWER32;
  1.6677 -  iB0 = iB % TWOPOWER32;
  1.6678 -  if( iA1==0 ){
  1.6679 -    if( iB1==0 ){
  1.6680 -      *pA *= iB;
  1.6681 -      return 0;
  1.6682 -    }
  1.6683 -    r = iA0*iB1;
  1.6684 -  }else if( iB1==0 ){
  1.6685 -    r = iA1*iB0;
  1.6686 -  }else{
  1.6687 -    /* If both iA1 and iB1 are non-zero, overflow will result */
  1.6688 -    return 1;
  1.6689 -  }
  1.6690 -  testcase( r==(-TWOPOWER31)-1 );
  1.6691 -  testcase( r==(-TWOPOWER31) );
  1.6692 -  testcase( r==TWOPOWER31 );
  1.6693 -  testcase( r==TWOPOWER31-1 );
  1.6694 -  if( r<(-TWOPOWER31) || r>=TWOPOWER31 ) return 1;
  1.6695 -  r *= TWOPOWER32;
  1.6696 -  if( sqlite3AddInt64(&r, iA0*iB0) ) return 1;
  1.6697 -  *pA = r;
  1.6698 +  if( iB>0 ){
  1.6699 +    if( iA>LARGEST_INT64/iB ) return 1;
  1.6700 +    if( iA<SMALLEST_INT64/iB ) return 1;
  1.6701 +  }else if( iB<0 ){
  1.6702 +    if( iA>0 ){
  1.6703 +      if( iB<SMALLEST_INT64/iA ) return 1;
  1.6704 +    }else if( iA<0 ){
  1.6705 +      if( iB==SMALLEST_INT64 ) return 1;
  1.6706 +      if( iA==SMALLEST_INT64 ) return 1;
  1.6707 +      if( -iA>LARGEST_INT64/-iB ) return 1;
  1.6708 +    }
  1.6709 +  }
  1.6710 +  *pA = iA*iB;
  1.6711    return 0;
  1.6712 +#endif
  1.6713  }
  1.6714  
  1.6715  /*
  1.6716 @@ -28445,6 +29119,109 @@
  1.6717  }
  1.6718  #endif /* defined SCANSTAT or STAT4 or ESTIMATED_ROWS */
  1.6719  
  1.6720 +/*
  1.6721 +** Add a new name/number pair to a VList.  This might require that the
  1.6722 +** VList object be reallocated, so return the new VList.  If an OOM
  1.6723 +** error occurs, the original VList returned and the
  1.6724 +** db->mallocFailed flag is set.
  1.6725 +**
  1.6726 +** A VList is really just an array of integers.  To destroy a VList,
  1.6727 +** simply pass it to sqlite3DbFree().
  1.6728 +**
  1.6729 +** The first integer is the number of integers allocated for the whole
  1.6730 +** VList.  The second integer is the number of integers actually used.
  1.6731 +** Each name/number pair is encoded by subsequent groups of 3 or more
  1.6732 +** integers.
  1.6733 +**
  1.6734 +** Each name/number pair starts with two integers which are the numeric
  1.6735 +** value for the pair and the size of the name/number pair, respectively.
  1.6736 +** The text name overlays one or more following integers.  The text name
  1.6737 +** is always zero-terminated.
  1.6738 +**
  1.6739 +** Conceptually:
  1.6740 +**
  1.6741 +**    struct VList {
  1.6742 +**      int nAlloc;   // Number of allocated slots 
  1.6743 +**      int nUsed;    // Number of used slots 
  1.6744 +**      struct VListEntry {
  1.6745 +**        int iValue;    // Value for this entry
  1.6746 +**        int nSlot;     // Slots used by this entry
  1.6747 +**        // ... variable name goes here
  1.6748 +**      } a[0];
  1.6749 +**    }
  1.6750 +**
  1.6751 +** During code generation, pointers to the variable names within the
  1.6752 +** VList are taken.  When that happens, nAlloc is set to zero as an 
  1.6753 +** indication that the VList may never again be enlarged, since the
  1.6754 +** accompanying realloc() would invalidate the pointers.
  1.6755 +*/
  1.6756 +SQLITE_PRIVATE VList *sqlite3VListAdd(
  1.6757 +  sqlite3 *db,           /* The database connection used for malloc() */
  1.6758 +  VList *pIn,            /* The input VList.  Might be NULL */
  1.6759 +  const char *zName,     /* Name of symbol to add */
  1.6760 +  int nName,             /* Bytes of text in zName */
  1.6761 +  int iVal               /* Value to associate with zName */
  1.6762 +){
  1.6763 +  int nInt;              /* number of sizeof(int) objects needed for zName */
  1.6764 +  char *z;               /* Pointer to where zName will be stored */
  1.6765 +  int i;                 /* Index in pIn[] where zName is stored */
  1.6766 +
  1.6767 +  nInt = nName/4 + 3;
  1.6768 +  assert( pIn==0 || pIn[0]>=3 );  /* Verify ok to add new elements */
  1.6769 +  if( pIn==0 || pIn[1]+nInt > pIn[0] ){
  1.6770 +    /* Enlarge the allocation */
  1.6771 +    int nAlloc = (pIn ? pIn[0]*2 : 10) + nInt;
  1.6772 +    VList *pOut = sqlite3DbRealloc(db, pIn, nAlloc*sizeof(int));
  1.6773 +    if( pOut==0 ) return pIn;
  1.6774 +    if( pIn==0 ) pOut[1] = 2;
  1.6775 +    pIn = pOut;
  1.6776 +    pIn[0] = nAlloc;
  1.6777 +  }
  1.6778 +  i = pIn[1];
  1.6779 +  pIn[i] = iVal;
  1.6780 +  pIn[i+1] = nInt;
  1.6781 +  z = (char*)&pIn[i+2];
  1.6782 +  pIn[1] = i+nInt;
  1.6783 +  assert( pIn[1]<=pIn[0] );
  1.6784 +  memcpy(z, zName, nName);
  1.6785 +  z[nName] = 0;
  1.6786 +  return pIn;
  1.6787 +}
  1.6788 +
  1.6789 +/*
  1.6790 +** Return a pointer to the name of a variable in the given VList that
  1.6791 +** has the value iVal.  Or return a NULL if there is no such variable in
  1.6792 +** the list
  1.6793 +*/
  1.6794 +SQLITE_PRIVATE const char *sqlite3VListNumToName(VList *pIn, int iVal){
  1.6795 +  int i, mx;
  1.6796 +  if( pIn==0 ) return 0;
  1.6797 +  mx = pIn[1];
  1.6798 +  i = 2;
  1.6799 +  do{
  1.6800 +    if( pIn[i]==iVal ) return (char*)&pIn[i+2];
  1.6801 +    i += pIn[i+1];
  1.6802 +  }while( i<mx );
  1.6803 +  return 0;
  1.6804 +}
  1.6805 +
  1.6806 +/*
  1.6807 +** Return the number of the variable named zName, if it is in VList.
  1.6808 +** or return 0 if there is no such variable.
  1.6809 +*/
  1.6810 +SQLITE_PRIVATE int sqlite3VListNameToNum(VList *pIn, const char *zName, int nName){
  1.6811 +  int i, mx;
  1.6812 +  if( pIn==0 ) return 0;
  1.6813 +  mx = pIn[1];
  1.6814 +  i = 2;
  1.6815 +  do{
  1.6816 +    const char *z = (const char*)&pIn[i+2];
  1.6817 +    if( strncmp(z,zName,nName)==0 && z[nName]==0 ) return pIn[i];
  1.6818 +    i += pIn[i+1];
  1.6819 +  }while( i<mx );
  1.6820 +  return 0;
  1.6821 +}
  1.6822 +
  1.6823  /************** End of util.c ************************************************/
  1.6824  /************** Begin file hash.c ********************************************/
  1.6825  /*
  1.6826 @@ -28505,7 +29282,11 @@
  1.6827    unsigned int h = 0;
  1.6828    unsigned char c;
  1.6829    while( (c = (unsigned char)*z++)!=0 ){     /*OPTIMIZATION-IF-TRUE*/
  1.6830 -    h = (h<<3) ^ h ^ sqlite3UpperToLower[c];
  1.6831 +    /* Knuth multiplicative hashing.  (Sorting & Searching, p. 510).
  1.6832 +    ** 0x9e3779b1 is 2654435761 which is the closest prime number to
  1.6833 +    ** (2**32)*golden_ratio, where golden_ratio = (sqrt(5) - 1)/2. */
  1.6834 +    h += sqlite3UpperToLower[c];
  1.6835 +    h *= 0x9e3779b1;
  1.6836    }
  1.6837    return h;
  1.6838  }
  1.6839 @@ -28752,144 +29533,149 @@
  1.6840      /*  20 */ "Once"             OpHelp(""),
  1.6841      /*  21 */ "If"               OpHelp(""),
  1.6842      /*  22 */ "IfNot"            OpHelp(""),
  1.6843 -    /*  23 */ "SeekLT"           OpHelp("key=r[P3@P4]"),
  1.6844 -    /*  24 */ "SeekLE"           OpHelp("key=r[P3@P4]"),
  1.6845 -    /*  25 */ "SeekGE"           OpHelp("key=r[P3@P4]"),
  1.6846 -    /*  26 */ "SeekGT"           OpHelp("key=r[P3@P4]"),
  1.6847 -    /*  27 */ "Or"               OpHelp("r[P3]=(r[P1] || r[P2])"),
  1.6848 -    /*  28 */ "And"              OpHelp("r[P3]=(r[P1] && r[P2])"),
  1.6849 -    /*  29 */ "NoConflict"       OpHelp("key=r[P3@P4]"),
  1.6850 -    /*  30 */ "NotFound"         OpHelp("key=r[P3@P4]"),
  1.6851 -    /*  31 */ "Found"            OpHelp("key=r[P3@P4]"),
  1.6852 +    /*  23 */ "IfNullRow"        OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
  1.6853 +    /*  24 */ "SeekLT"           OpHelp("key=r[P3@P4]"),
  1.6854 +    /*  25 */ "SeekLE"           OpHelp("key=r[P3@P4]"),
  1.6855 +    /*  26 */ "SeekGE"           OpHelp("key=r[P3@P4]"),
  1.6856 +    /*  27 */ "SeekGT"           OpHelp("key=r[P3@P4]"),
  1.6857 +    /*  28 */ "NoConflict"       OpHelp("key=r[P3@P4]"),
  1.6858 +    /*  29 */ "NotFound"         OpHelp("key=r[P3@P4]"),
  1.6859 +    /*  30 */ "Found"            OpHelp("key=r[P3@P4]"),
  1.6860 +    /*  31 */ "SeekRowid"        OpHelp("intkey=r[P3]"),
  1.6861      /*  32 */ "NotExists"        OpHelp("intkey=r[P3]"),
  1.6862      /*  33 */ "Last"             OpHelp(""),
  1.6863 -    /*  34 */ "IsNull"           OpHelp("if r[P1]==NULL goto P2"),
  1.6864 -    /*  35 */ "NotNull"          OpHelp("if r[P1]!=NULL goto P2"),
  1.6865 -    /*  36 */ "Ne"               OpHelp("if r[P1]!=r[P3] goto P2"),
  1.6866 -    /*  37 */ "Eq"               OpHelp("if r[P1]==r[P3] goto P2"),
  1.6867 -    /*  38 */ "Gt"               OpHelp("if r[P1]>r[P3] goto P2"),
  1.6868 -    /*  39 */ "Le"               OpHelp("if r[P1]<=r[P3] goto P2"),
  1.6869 -    /*  40 */ "Lt"               OpHelp("if r[P1]<r[P3] goto P2"),
  1.6870 -    /*  41 */ "Ge"               OpHelp("if r[P1]>=r[P3] goto P2"),
  1.6871 -    /*  42 */ "SorterSort"       OpHelp(""),
  1.6872 -    /*  43 */ "BitAnd"           OpHelp("r[P3]=r[P1]&r[P2]"),
  1.6873 -    /*  44 */ "BitOr"            OpHelp("r[P3]=r[P1]|r[P2]"),
  1.6874 -    /*  45 */ "ShiftLeft"        OpHelp("r[P3]=r[P2]<<r[P1]"),
  1.6875 -    /*  46 */ "ShiftRight"       OpHelp("r[P3]=r[P2]>>r[P1]"),
  1.6876 -    /*  47 */ "Add"              OpHelp("r[P3]=r[P1]+r[P2]"),
  1.6877 -    /*  48 */ "Subtract"         OpHelp("r[P3]=r[P2]-r[P1]"),
  1.6878 -    /*  49 */ "Multiply"         OpHelp("r[P3]=r[P1]*r[P2]"),
  1.6879 -    /*  50 */ "Divide"           OpHelp("r[P3]=r[P2]/r[P1]"),
  1.6880 -    /*  51 */ "Remainder"        OpHelp("r[P3]=r[P2]%r[P1]"),
  1.6881 -    /*  52 */ "Concat"           OpHelp("r[P3]=r[P2]+r[P1]"),
  1.6882 -    /*  53 */ "Sort"             OpHelp(""),
  1.6883 -    /*  54 */ "BitNot"           OpHelp("r[P1]= ~r[P1]"),
  1.6884 -    /*  55 */ "Rewind"           OpHelp(""),
  1.6885 -    /*  56 */ "IdxLE"            OpHelp("key=r[P3@P4]"),
  1.6886 -    /*  57 */ "IdxGT"            OpHelp("key=r[P3@P4]"),
  1.6887 -    /*  58 */ "IdxLT"            OpHelp("key=r[P3@P4]"),
  1.6888 -    /*  59 */ "IdxGE"            OpHelp("key=r[P3@P4]"),
  1.6889 -    /*  60 */ "RowSetRead"       OpHelp("r[P3]=rowset(P1)"),
  1.6890 -    /*  61 */ "RowSetTest"       OpHelp("if r[P3] in rowset(P1) goto P2"),
  1.6891 -    /*  62 */ "Program"          OpHelp(""),
  1.6892 -    /*  63 */ "FkIfZero"         OpHelp("if fkctr[P1]==0 goto P2"),
  1.6893 -    /*  64 */ "IfPos"            OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
  1.6894 -    /*  65 */ "IfNotZero"        OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"),
  1.6895 -    /*  66 */ "DecrJumpZero"     OpHelp("if (--r[P1])==0 goto P2"),
  1.6896 -    /*  67 */ "IncrVacuum"       OpHelp(""),
  1.6897 -    /*  68 */ "VNext"            OpHelp(""),
  1.6898 -    /*  69 */ "Init"             OpHelp("Start at P2"),
  1.6899 -    /*  70 */ "Return"           OpHelp(""),
  1.6900 -    /*  71 */ "EndCoroutine"     OpHelp(""),
  1.6901 -    /*  72 */ "HaltIfNull"       OpHelp("if r[P3]=null halt"),
  1.6902 -    /*  73 */ "Halt"             OpHelp(""),
  1.6903 -    /*  74 */ "Integer"          OpHelp("r[P2]=P1"),
  1.6904 -    /*  75 */ "Int64"            OpHelp("r[P2]=P4"),
  1.6905 -    /*  76 */ "String"           OpHelp("r[P2]='P4' (len=P1)"),
  1.6906 -    /*  77 */ "Null"             OpHelp("r[P2..P3]=NULL"),
  1.6907 -    /*  78 */ "SoftNull"         OpHelp("r[P1]=NULL"),
  1.6908 -    /*  79 */ "Blob"             OpHelp("r[P2]=P4 (len=P1)"),
  1.6909 -    /*  80 */ "Variable"         OpHelp("r[P2]=parameter(P1,P4)"),
  1.6910 -    /*  81 */ "Move"             OpHelp("r[P2@P3]=r[P1@P3]"),
  1.6911 -    /*  82 */ "Copy"             OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
  1.6912 -    /*  83 */ "SCopy"            OpHelp("r[P2]=r[P1]"),
  1.6913 -    /*  84 */ "IntCopy"          OpHelp("r[P2]=r[P1]"),
  1.6914 -    /*  85 */ "ResultRow"        OpHelp("output=r[P1@P2]"),
  1.6915 -    /*  86 */ "CollSeq"          OpHelp(""),
  1.6916 -    /*  87 */ "Function0"        OpHelp("r[P3]=func(r[P2@P5])"),
  1.6917 -    /*  88 */ "Function"         OpHelp("r[P3]=func(r[P2@P5])"),
  1.6918 -    /*  89 */ "AddImm"           OpHelp("r[P1]=r[P1]+P2"),
  1.6919 -    /*  90 */ "RealAffinity"     OpHelp(""),
  1.6920 -    /*  91 */ "Cast"             OpHelp("affinity(r[P1])"),
  1.6921 -    /*  92 */ "Permutation"      OpHelp(""),
  1.6922 -    /*  93 */ "Compare"          OpHelp("r[P1@P3] <-> r[P2@P3]"),
  1.6923 -    /*  94 */ "Column"           OpHelp("r[P3]=PX"),
  1.6924 -    /*  95 */ "Affinity"         OpHelp("affinity(r[P1@P2])"),
  1.6925 -    /*  96 */ "MakeRecord"       OpHelp("r[P3]=mkrec(r[P1@P2])"),
  1.6926 +    /*  34 */ "IfSmaller"        OpHelp(""),
  1.6927 +    /*  35 */ "SorterSort"       OpHelp(""),
  1.6928 +    /*  36 */ "Sort"             OpHelp(""),
  1.6929 +    /*  37 */ "Rewind"           OpHelp(""),
  1.6930 +    /*  38 */ "IdxLE"            OpHelp("key=r[P3@P4]"),
  1.6931 +    /*  39 */ "IdxGT"            OpHelp("key=r[P3@P4]"),
  1.6932 +    /*  40 */ "IdxLT"            OpHelp("key=r[P3@P4]"),
  1.6933 +    /*  41 */ "IdxGE"            OpHelp("key=r[P3@P4]"),
  1.6934 +    /*  42 */ "RowSetRead"       OpHelp("r[P3]=rowset(P1)"),
  1.6935 +    /*  43 */ "RowSetTest"       OpHelp("if r[P3] in rowset(P1) goto P2"),
  1.6936 +    /*  44 */ "Program"          OpHelp(""),
  1.6937 +    /*  45 */ "FkIfZero"         OpHelp("if fkctr[P1]==0 goto P2"),
  1.6938 +    /*  46 */ "IfPos"            OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
  1.6939 +    /*  47 */ "IfNotZero"        OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
  1.6940 +    /*  48 */ "DecrJumpZero"     OpHelp("if (--r[P1])==0 goto P2"),
  1.6941 +    /*  49 */ "IncrVacuum"       OpHelp(""),
  1.6942 +    /*  50 */ "VNext"            OpHelp(""),
  1.6943 +    /*  51 */ "Init"             OpHelp("Start at P2"),
  1.6944 +    /*  52 */ "Return"           OpHelp(""),
  1.6945 +    /*  53 */ "EndCoroutine"     OpHelp(""),
  1.6946 +    /*  54 */ "HaltIfNull"       OpHelp("if r[P3]=null halt"),
  1.6947 +    /*  55 */ "Halt"             OpHelp(""),
  1.6948 +    /*  56 */ "Integer"          OpHelp("r[P2]=P1"),
  1.6949 +    /*  57 */ "Int64"            OpHelp("r[P2]=P4"),
  1.6950 +    /*  58 */ "String"           OpHelp("r[P2]='P4' (len=P1)"),
  1.6951 +    /*  59 */ "Null"             OpHelp("r[P2..P3]=NULL"),
  1.6952 +    /*  60 */ "SoftNull"         OpHelp("r[P1]=NULL"),
  1.6953 +    /*  61 */ "Blob"             OpHelp("r[P2]=P4 (len=P1)"),
  1.6954 +    /*  62 */ "Variable"         OpHelp("r[P2]=parameter(P1,P4)"),
  1.6955 +    /*  63 */ "Move"             OpHelp("r[P2@P3]=r[P1@P3]"),
  1.6956 +    /*  64 */ "Copy"             OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
  1.6957 +    /*  65 */ "SCopy"            OpHelp("r[P2]=r[P1]"),
  1.6958 +    /*  66 */ "IntCopy"          OpHelp("r[P2]=r[P1]"),
  1.6959 +    /*  67 */ "ResultRow"        OpHelp("output=r[P1@P2]"),
  1.6960 +    /*  68 */ "CollSeq"          OpHelp(""),
  1.6961 +    /*  69 */ "Function0"        OpHelp("r[P3]=func(r[P2@P5])"),
  1.6962 +    /*  70 */ "Or"               OpHelp("r[P3]=(r[P1] || r[P2])"),
  1.6963 +    /*  71 */ "And"              OpHelp("r[P3]=(r[P1] && r[P2])"),
  1.6964 +    /*  72 */ "Function"         OpHelp("r[P3]=func(r[P2@P5])"),
  1.6965 +    /*  73 */ "AddImm"           OpHelp("r[P1]=r[P1]+P2"),
  1.6966 +    /*  74 */ "RealAffinity"     OpHelp(""),
  1.6967 +    /*  75 */ "IsNull"           OpHelp("if r[P1]==NULL goto P2"),
  1.6968 +    /*  76 */ "NotNull"          OpHelp("if r[P1]!=NULL goto P2"),
  1.6969 +    /*  77 */ "Ne"               OpHelp("IF r[P3]!=r[P1]"),
  1.6970 +    /*  78 */ "Eq"               OpHelp("IF r[P3]==r[P1]"),
  1.6971 +    /*  79 */ "Gt"               OpHelp("IF r[P3]>r[P1]"),
  1.6972 +    /*  80 */ "Le"               OpHelp("IF r[P3]<=r[P1]"),
  1.6973 +    /*  81 */ "Lt"               OpHelp("IF r[P3]<r[P1]"),
  1.6974 +    /*  82 */ "Ge"               OpHelp("IF r[P3]>=r[P1]"),
  1.6975 +    /*  83 */ "ElseNotEq"        OpHelp(""),
  1.6976 +    /*  84 */ "BitAnd"           OpHelp("r[P3]=r[P1]&r[P2]"),
  1.6977 +    /*  85 */ "BitOr"            OpHelp("r[P3]=r[P1]|r[P2]"),
  1.6978 +    /*  86 */ "ShiftLeft"        OpHelp("r[P3]=r[P2]<<r[P1]"),
  1.6979 +    /*  87 */ "ShiftRight"       OpHelp("r[P3]=r[P2]>>r[P1]"),
  1.6980 +    /*  88 */ "Add"              OpHelp("r[P3]=r[P1]+r[P2]"),
  1.6981 +    /*  89 */ "Subtract"         OpHelp("r[P3]=r[P2]-r[P1]"),
  1.6982 +    /*  90 */ "Multiply"         OpHelp("r[P3]=r[P1]*r[P2]"),
  1.6983 +    /*  91 */ "Divide"           OpHelp("r[P3]=r[P2]/r[P1]"),
  1.6984 +    /*  92 */ "Remainder"        OpHelp("r[P3]=r[P2]%r[P1]"),
  1.6985 +    /*  93 */ "Concat"           OpHelp("r[P3]=r[P2]+r[P1]"),
  1.6986 +    /*  94 */ "Cast"             OpHelp("affinity(r[P1])"),
  1.6987 +    /*  95 */ "BitNot"           OpHelp("r[P1]= ~r[P1]"),
  1.6988 +    /*  96 */ "Permutation"      OpHelp(""),
  1.6989      /*  97 */ "String8"          OpHelp("r[P2]='P4'"),
  1.6990 -    /*  98 */ "Count"            OpHelp("r[P2]=count()"),
  1.6991 -    /*  99 */ "ReadCookie"       OpHelp(""),
  1.6992 -    /* 100 */ "SetCookie"        OpHelp(""),
  1.6993 -    /* 101 */ "ReopenIdx"        OpHelp("root=P2 iDb=P3"),
  1.6994 -    /* 102 */ "OpenRead"         OpHelp("root=P2 iDb=P3"),
  1.6995 -    /* 103 */ "OpenWrite"        OpHelp("root=P2 iDb=P3"),
  1.6996 -    /* 104 */ "OpenAutoindex"    OpHelp("nColumn=P2"),
  1.6997 -    /* 105 */ "OpenEphemeral"    OpHelp("nColumn=P2"),
  1.6998 -    /* 106 */ "SorterOpen"       OpHelp(""),
  1.6999 -    /* 107 */ "SequenceTest"     OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
  1.7000 -    /* 108 */ "OpenPseudo"       OpHelp("P3 columns in r[P2]"),
  1.7001 -    /* 109 */ "Close"            OpHelp(""),
  1.7002 -    /* 110 */ "ColumnsUsed"      OpHelp(""),
  1.7003 -    /* 111 */ "Sequence"         OpHelp("r[P2]=cursor[P1].ctr++"),
  1.7004 -    /* 112 */ "NewRowid"         OpHelp("r[P2]=rowid"),
  1.7005 -    /* 113 */ "Insert"           OpHelp("intkey=r[P3] data=r[P2]"),
  1.7006 -    /* 114 */ "InsertInt"        OpHelp("intkey=P3 data=r[P2]"),
  1.7007 -    /* 115 */ "Delete"           OpHelp(""),
  1.7008 -    /* 116 */ "ResetCount"       OpHelp(""),
  1.7009 -    /* 117 */ "SorterCompare"    OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
  1.7010 -    /* 118 */ "SorterData"       OpHelp("r[P2]=data"),
  1.7011 -    /* 119 */ "RowKey"           OpHelp("r[P2]=key"),
  1.7012 -    /* 120 */ "RowData"          OpHelp("r[P2]=data"),
  1.7013 -    /* 121 */ "Rowid"            OpHelp("r[P2]=rowid"),
  1.7014 -    /* 122 */ "NullRow"          OpHelp(""),
  1.7015 -    /* 123 */ "SorterInsert"     OpHelp(""),
  1.7016 -    /* 124 */ "IdxInsert"        OpHelp("key=r[P2]"),
  1.7017 -    /* 125 */ "IdxDelete"        OpHelp("key=r[P2@P3]"),
  1.7018 -    /* 126 */ "Seek"             OpHelp("Move P3 to P1.rowid"),
  1.7019 -    /* 127 */ "IdxRowid"         OpHelp("r[P2]=rowid"),
  1.7020 -    /* 128 */ "Destroy"          OpHelp(""),
  1.7021 -    /* 129 */ "Clear"            OpHelp(""),
  1.7022 -    /* 130 */ "ResetSorter"      OpHelp(""),
  1.7023 -    /* 131 */ "CreateIndex"      OpHelp("r[P2]=root iDb=P1"),
  1.7024 -    /* 132 */ "CreateTable"      OpHelp("r[P2]=root iDb=P1"),
  1.7025 -    /* 133 */ "Real"             OpHelp("r[P2]=P4"),
  1.7026 -    /* 134 */ "ParseSchema"      OpHelp(""),
  1.7027 -    /* 135 */ "LoadAnalysis"     OpHelp(""),
  1.7028 -    /* 136 */ "DropTable"        OpHelp(""),
  1.7029 -    /* 137 */ "DropIndex"        OpHelp(""),
  1.7030 -    /* 138 */ "DropTrigger"      OpHelp(""),
  1.7031 -    /* 139 */ "IntegrityCk"      OpHelp(""),
  1.7032 -    /* 140 */ "RowSetAdd"        OpHelp("rowset(P1)=r[P2]"),
  1.7033 -    /* 141 */ "Param"            OpHelp(""),
  1.7034 -    /* 142 */ "FkCounter"        OpHelp("fkctr[P1]+=P2"),
  1.7035 -    /* 143 */ "MemMax"           OpHelp("r[P1]=max(r[P1],r[P2])"),
  1.7036 -    /* 144 */ "OffsetLimit"      OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
  1.7037 -    /* 145 */ "AggStep0"         OpHelp("accum=r[P3] step(r[P2@P5])"),
  1.7038 -    /* 146 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2@P5])"),
  1.7039 -    /* 147 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
  1.7040 -    /* 148 */ "Expire"           OpHelp(""),
  1.7041 -    /* 149 */ "TableLock"        OpHelp("iDb=P1 root=P2 write=P3"),
  1.7042 -    /* 150 */ "VBegin"           OpHelp(""),
  1.7043 -    /* 151 */ "VCreate"          OpHelp(""),
  1.7044 -    /* 152 */ "VDestroy"         OpHelp(""),
  1.7045 -    /* 153 */ "VOpen"            OpHelp(""),
  1.7046 -    /* 154 */ "VColumn"          OpHelp("r[P3]=vcolumn(P2)"),
  1.7047 -    /* 155 */ "VRename"          OpHelp(""),
  1.7048 -    /* 156 */ "Pagecount"        OpHelp(""),
  1.7049 -    /* 157 */ "MaxPgcnt"         OpHelp(""),
  1.7050 -    /* 158 */ "CursorHint"       OpHelp(""),
  1.7051 -    /* 159 */ "Noop"             OpHelp(""),
  1.7052 -    /* 160 */ "Explain"          OpHelp(""),
  1.7053 +    /*  98 */ "Compare"          OpHelp("r[P1@P3] <-> r[P2@P3]"),
  1.7054 +    /*  99 */ "Column"           OpHelp("r[P3]=PX"),
  1.7055 +    /* 100 */ "Affinity"         OpHelp("affinity(r[P1@P2])"),
  1.7056 +    /* 101 */ "MakeRecord"       OpHelp("r[P3]=mkrec(r[P1@P2])"),
  1.7057 +    /* 102 */ "Count"            OpHelp("r[P2]=count()"),
  1.7058 +    /* 103 */ "ReadCookie"       OpHelp(""),
  1.7059 +    /* 104 */ "SetCookie"        OpHelp(""),
  1.7060 +    /* 105 */ "ReopenIdx"        OpHelp("root=P2 iDb=P3"),
  1.7061 +    /* 106 */ "OpenRead"         OpHelp("root=P2 iDb=P3"),
  1.7062 +    /* 107 */ "OpenWrite"        OpHelp("root=P2 iDb=P3"),
  1.7063 +    /* 108 */ "OpenDup"          OpHelp(""),
  1.7064 +    /* 109 */ "OpenAutoindex"    OpHelp("nColumn=P2"),
  1.7065 +    /* 110 */ "OpenEphemeral"    OpHelp("nColumn=P2"),
  1.7066 +    /* 111 */ "SorterOpen"       OpHelp(""),
  1.7067 +    /* 112 */ "SequenceTest"     OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
  1.7068 +    /* 113 */ "OpenPseudo"       OpHelp("P3 columns in r[P2]"),
  1.7069 +    /* 114 */ "Close"            OpHelp(""),
  1.7070 +    /* 115 */ "ColumnsUsed"      OpHelp(""),
  1.7071 +    /* 116 */ "Sequence"         OpHelp("r[P2]=cursor[P1].ctr++"),
  1.7072 +    /* 117 */ "NewRowid"         OpHelp("r[P2]=rowid"),
  1.7073 +    /* 118 */ "Insert"           OpHelp("intkey=r[P3] data=r[P2]"),
  1.7074 +    /* 119 */ "InsertInt"        OpHelp("intkey=P3 data=r[P2]"),
  1.7075 +    /* 120 */ "Delete"           OpHelp(""),
  1.7076 +    /* 121 */ "ResetCount"       OpHelp(""),
  1.7077 +    /* 122 */ "SorterCompare"    OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
  1.7078 +    /* 123 */ "SorterData"       OpHelp("r[P2]=data"),
  1.7079 +    /* 124 */ "RowData"          OpHelp("r[P2]=data"),
  1.7080 +    /* 125 */ "Rowid"            OpHelp("r[P2]=rowid"),
  1.7081 +    /* 126 */ "NullRow"          OpHelp(""),
  1.7082 +    /* 127 */ "SorterInsert"     OpHelp("key=r[P2]"),
  1.7083 +    /* 128 */ "IdxInsert"        OpHelp("key=r[P2]"),
  1.7084 +    /* 129 */ "IdxDelete"        OpHelp("key=r[P2@P3]"),
  1.7085 +    /* 130 */ "Seek"             OpHelp("Move P3 to P1.rowid"),
  1.7086 +    /* 131 */ "IdxRowid"         OpHelp("r[P2]=rowid"),
  1.7087 +    /* 132 */ "Real"             OpHelp("r[P2]=P4"),
  1.7088 +    /* 133 */ "Destroy"          OpHelp(""),
  1.7089 +    /* 134 */ "Clear"            OpHelp(""),
  1.7090 +    /* 135 */ "ResetSorter"      OpHelp(""),
  1.7091 +    /* 136 */ "CreateIndex"      OpHelp("r[P2]=root iDb=P1"),
  1.7092 +    /* 137 */ "CreateTable"      OpHelp("r[P2]=root iDb=P1"),
  1.7093 +    /* 138 */ "SqlExec"          OpHelp(""),
  1.7094 +    /* 139 */ "ParseSchema"      OpHelp(""),
  1.7095 +    /* 140 */ "LoadAnalysis"     OpHelp(""),
  1.7096 +    /* 141 */ "DropTable"        OpHelp(""),
  1.7097 +    /* 142 */ "DropIndex"        OpHelp(""),
  1.7098 +    /* 143 */ "DropTrigger"      OpHelp(""),
  1.7099 +    /* 144 */ "IntegrityCk"      OpHelp(""),
  1.7100 +    /* 145 */ "RowSetAdd"        OpHelp("rowset(P1)=r[P2]"),
  1.7101 +    /* 146 */ "Param"            OpHelp(""),
  1.7102 +    /* 147 */ "FkCounter"        OpHelp("fkctr[P1]+=P2"),
  1.7103 +    /* 148 */ "MemMax"           OpHelp("r[P1]=max(r[P1],r[P2])"),
  1.7104 +    /* 149 */ "OffsetLimit"      OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
  1.7105 +    /* 150 */ "AggStep0"         OpHelp("accum=r[P3] step(r[P2@P5])"),
  1.7106 +    /* 151 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2@P5])"),
  1.7107 +    /* 152 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
  1.7108 +    /* 153 */ "Expire"           OpHelp(""),
  1.7109 +    /* 154 */ "TableLock"        OpHelp("iDb=P1 root=P2 write=P3"),
  1.7110 +    /* 155 */ "VBegin"           OpHelp(""),
  1.7111 +    /* 156 */ "VCreate"          OpHelp(""),
  1.7112 +    /* 157 */ "VDestroy"         OpHelp(""),
  1.7113 +    /* 158 */ "VOpen"            OpHelp(""),
  1.7114 +    /* 159 */ "VColumn"          OpHelp("r[P3]=vcolumn(P2)"),
  1.7115 +    /* 160 */ "VRename"          OpHelp(""),
  1.7116 +    /* 161 */ "Pagecount"        OpHelp(""),
  1.7117 +    /* 162 */ "MaxPgcnt"         OpHelp(""),
  1.7118 +    /* 163 */ "CursorHint"       OpHelp(""),
  1.7119 +    /* 164 */ "Noop"             OpHelp(""),
  1.7120 +    /* 165 */ "Explain"          OpHelp(""),
  1.7121    };
  1.7122    return azName[i];
  1.7123  }
  1.7124 @@ -29239,8 +30025,8 @@
  1.7125  ** This file contains inline asm code for retrieving "high-performance"
  1.7126  ** counters for x86 class CPUs.
  1.7127  */
  1.7128 -#ifndef _HWTIME_H_
  1.7129 -#define _HWTIME_H_
  1.7130 +#ifndef SQLITE_HWTIME_H
  1.7131 +#define SQLITE_HWTIME_H
  1.7132  
  1.7133  /*
  1.7134  ** The following routine only works on pentium-class (or newer) processors.
  1.7135 @@ -29308,7 +30094,7 @@
  1.7136  
  1.7137  #endif
  1.7138  
  1.7139 -#endif /* !defined(_HWTIME_H_) */
  1.7140 +#endif /* !defined(SQLITE_HWTIME_H) */
  1.7141  
  1.7142  /************** End of hwtime.h **********************************************/
  1.7143  /************** Continuing where we left off in os_common.h ******************/
  1.7144 @@ -30158,7 +30944,14 @@
  1.7145  #if OS_VXWORKS
  1.7146    struct vxworksFileId *pId;  /* Unique file ID for vxworks. */
  1.7147  #else
  1.7148 -  ino_t ino;                  /* Inode number */
  1.7149 +  /* We are told that some versions of Android contain a bug that
  1.7150 +  ** sizes ino_t at only 32-bits instead of 64-bits. (See
  1.7151 +  ** https://android-review.googlesource.com/#/c/115351/3/dist/sqlite3.c)
  1.7152 +  ** To work around this, always allocate 64-bits for the inode number.  
  1.7153 +  ** On small machines that only have 32-bit inodes, this wastes 4 bytes,
  1.7154 +  ** but that should not be a big deal. */
  1.7155 +  /* WAS:  ino_t ino;   */
  1.7156 +  u64 ino;                   /* Inode number */
  1.7157  #endif
  1.7158  };
  1.7159  
  1.7160 @@ -30403,7 +31196,7 @@
  1.7161  #if OS_VXWORKS
  1.7162    fileId.pId = pFile->pId;
  1.7163  #else
  1.7164 -  fileId.ino = statbuf.st_ino;
  1.7165 +  fileId.ino = (u64)statbuf.st_ino;
  1.7166  #endif
  1.7167    pInode = inodeList;
  1.7168    while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
  1.7169 @@ -30437,7 +31230,8 @@
  1.7170  #else
  1.7171    struct stat buf;
  1.7172    return pFile->pInode!=0 &&
  1.7173 -      (osStat(pFile->zPath, &buf)!=0 || buf.st_ino!=pFile->pInode->fileId.ino);
  1.7174 +      (osStat(pFile->zPath, &buf)!=0 
  1.7175 +         || (u64)buf.st_ino!=pFile->pInode->fileId.ino);
  1.7176  #endif
  1.7177  }
  1.7178  
  1.7179 @@ -34609,7 +35403,7 @@
  1.7180      unixEnterMutex();
  1.7181      pInode = inodeList;
  1.7182      while( pInode && (pInode->fileId.dev!=sStat.st_dev
  1.7183 -                     || pInode->fileId.ino!=sStat.st_ino) ){
  1.7184 +                     || pInode->fileId.ino!=(u64)sStat.st_ino) ){
  1.7185         pInode = pInode->pNext;
  1.7186      }
  1.7187      if( pInode ){
  1.7188 @@ -34627,6 +35421,27 @@
  1.7189  }
  1.7190  
  1.7191  /*
  1.7192 +** Find the mode, uid and gid of file zFile. 
  1.7193 +*/
  1.7194 +static int getFileMode(
  1.7195 +  const char *zFile,              /* File name */
  1.7196 +  mode_t *pMode,                  /* OUT: Permissions of zFile */
  1.7197 +  uid_t *pUid,                    /* OUT: uid of zFile. */
  1.7198 +  gid_t *pGid                     /* OUT: gid of zFile. */
  1.7199 +){
  1.7200 +  struct stat sStat;              /* Output of stat() on database file */
  1.7201 +  int rc = SQLITE_OK;
  1.7202 +  if( 0==osStat(zFile, &sStat) ){
  1.7203 +    *pMode = sStat.st_mode & 0777;
  1.7204 +    *pUid = sStat.st_uid;
  1.7205 +    *pGid = sStat.st_gid;
  1.7206 +  }else{
  1.7207 +    rc = SQLITE_IOERR_FSTAT;
  1.7208 +  }
  1.7209 +  return rc;
  1.7210 +}
  1.7211 +
  1.7212 +/*
  1.7213  ** This function is called by unixOpen() to determine the unix permissions
  1.7214  ** to create new files with. If no error occurs, then SQLITE_OK is returned
  1.7215  ** and a value suitable for passing as the third argument to open(2) is
  1.7216 @@ -34661,7 +35476,6 @@
  1.7217    if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
  1.7218      char zDb[MAX_PATHNAME+1];     /* Database file path */
  1.7219      int nDb;                      /* Number of valid bytes in zDb */
  1.7220 -    struct stat sStat;            /* Output of stat() on database file */
  1.7221  
  1.7222      /* zPath is a path to a WAL or journal file. The following block derives
  1.7223      ** the path to the associated database file from zPath. This block handles
  1.7224 @@ -34692,15 +35506,18 @@
  1.7225      memcpy(zDb, zPath, nDb);
  1.7226      zDb[nDb] = '\0';
  1.7227  
  1.7228 -    if( 0==osStat(zDb, &sStat) ){
  1.7229 -      *pMode = sStat.st_mode & 0777;
  1.7230 -      *pUid = sStat.st_uid;
  1.7231 -      *pGid = sStat.st_gid;
  1.7232 -    }else{
  1.7233 -      rc = SQLITE_IOERR_FSTAT;
  1.7234 -    }
  1.7235 +    rc = getFileMode(zDb, pMode, pUid, pGid);
  1.7236    }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
  1.7237      *pMode = 0600;
  1.7238 +  }else if( flags & SQLITE_OPEN_URI ){
  1.7239 +    /* If this is a main database file and the file was opened using a URI
  1.7240 +    ** filename, check for the "modeof" parameter. If present, interpret
  1.7241 +    ** its value as a filename and try to copy the mode, uid and gid from
  1.7242 +    ** that file.  */
  1.7243 +    const char *z = sqlite3_uri_parameter(zPath, "modeof");
  1.7244 +    if( z ){
  1.7245 +      rc = getFileMode(z, pMode, pUid, pGid);
  1.7246 +    }
  1.7247    }
  1.7248    return rc;
  1.7249  }
  1.7250 @@ -36581,7 +37398,7 @@
  1.7251  ** necessarily been initialized when this routine is called, and so they
  1.7252  ** should not be used.
  1.7253  */
  1.7254 -SQLITE_API int SQLITE_STDCALL sqlite3_os_init(void){ 
  1.7255 +SQLITE_API int sqlite3_os_init(void){ 
  1.7256    /* 
  1.7257    ** The following macro defines an initializer for an sqlite3_vfs object.
  1.7258    ** The name of the VFS is NAME.  The pAppData is a pointer to a pointer
  1.7259 @@ -36680,7 +37497,7 @@
  1.7260  ** to release dynamically allocated objects.  But not on unix.
  1.7261  ** This routine is a no-op for unix.
  1.7262  */
  1.7263 -SQLITE_API int SQLITE_STDCALL sqlite3_os_end(void){ 
  1.7264 +SQLITE_API int sqlite3_os_end(void){ 
  1.7265    return SQLITE_OK; 
  1.7266  }
  1.7267   
  1.7268 @@ -36768,8 +37585,8 @@
  1.7269  ** This file contains inline asm code for retrieving "high-performance"
  1.7270  ** counters for x86 class CPUs.
  1.7271  */
  1.7272 -#ifndef _HWTIME_H_
  1.7273 -#define _HWTIME_H_
  1.7274 +#ifndef SQLITE_HWTIME_H
  1.7275 +#define SQLITE_HWTIME_H
  1.7276  
  1.7277  /*
  1.7278  ** The following routine only works on pentium-class (or newer) processors.
  1.7279 @@ -36837,7 +37654,7 @@
  1.7280  
  1.7281  #endif
  1.7282  
  1.7283 -#endif /* !defined(_HWTIME_H_) */
  1.7284 +#endif /* !defined(SQLITE_HWTIME_H) */
  1.7285  
  1.7286  /************** End of hwtime.h **********************************************/
  1.7287  /************** Continuing where we left off in os_common.h ******************/
  1.7288 @@ -37179,6 +37996,17 @@
  1.7289  };
  1.7290  
  1.7291  /*
  1.7292 +** The winVfsAppData structure is used for the pAppData member for all of the
  1.7293 +** Win32 VFS variants.
  1.7294 +*/
  1.7295 +typedef struct winVfsAppData winVfsAppData;
  1.7296 +struct winVfsAppData {
  1.7297 +  const sqlite3_io_methods *pMethod; /* The file I/O methods to use. */
  1.7298 +  void *pAppData;                    /* The extra pAppData, if any. */
  1.7299 +  BOOL bNoLock;                      /* Non-zero if locking is disabled. */
  1.7300 +};
  1.7301 +
  1.7302 +/*
  1.7303  ** Allowed values for winFile.ctrlFlags
  1.7304  */
  1.7305  #define WINFILE_RDONLY          0x02   /* Connection is read only */
  1.7306 @@ -37229,7 +38057,34 @@
  1.7307   ******************************************************************************
  1.7308   */
  1.7309  #ifndef SQLITE_WIN32_HEAP_CREATE
  1.7310 -#  define SQLITE_WIN32_HEAP_CREATE    (TRUE)
  1.7311 +#  define SQLITE_WIN32_HEAP_CREATE        (TRUE)
  1.7312 +#endif
  1.7313 +
  1.7314 +/*
  1.7315 + * This is the maximum possible initial size of the Win32-specific heap, in
  1.7316 + * bytes.
  1.7317 + */
  1.7318 +#ifndef SQLITE_WIN32_HEAP_MAX_INIT_SIZE
  1.7319 +#  define SQLITE_WIN32_HEAP_MAX_INIT_SIZE (4294967295U)
  1.7320 +#endif
  1.7321 +
  1.7322 +/*
  1.7323 + * This is the extra space for the initial size of the Win32-specific heap,
  1.7324 + * in bytes.  This value may be zero.
  1.7325 + */
  1.7326 +#ifndef SQLITE_WIN32_HEAP_INIT_EXTRA
  1.7327 +#  define SQLITE_WIN32_HEAP_INIT_EXTRA  (4194304)
  1.7328 +#endif
  1.7329 +
  1.7330 +/*
  1.7331 + * Calculate the maximum legal cache size, in pages, based on the maximum
  1.7332 + * possible initial heap size and the default page size, setting aside the
  1.7333 + * needed extra space.
  1.7334 + */
  1.7335 +#ifndef SQLITE_WIN32_MAX_CACHE_SIZE
  1.7336 +#  define SQLITE_WIN32_MAX_CACHE_SIZE   (((SQLITE_WIN32_HEAP_MAX_INIT_SIZE) - \
  1.7337 +                                          (SQLITE_WIN32_HEAP_INIT_EXTRA)) / \
  1.7338 +                                         (SQLITE_DEFAULT_PAGE_SIZE))
  1.7339  #endif
  1.7340  
  1.7341  /*
  1.7342 @@ -37238,25 +38093,36 @@
  1.7343   */
  1.7344  #ifndef SQLITE_WIN32_CACHE_SIZE
  1.7345  #  if SQLITE_DEFAULT_CACHE_SIZE>=0
  1.7346 -#    define SQLITE_WIN32_CACHE_SIZE (SQLITE_DEFAULT_CACHE_SIZE)
  1.7347 +#    define SQLITE_WIN32_CACHE_SIZE     (SQLITE_DEFAULT_CACHE_SIZE)
  1.7348  #  else
  1.7349 -#    define SQLITE_WIN32_CACHE_SIZE (-(SQLITE_DEFAULT_CACHE_SIZE))
  1.7350 +#    define SQLITE_WIN32_CACHE_SIZE     (-(SQLITE_DEFAULT_CACHE_SIZE))
  1.7351  #  endif
  1.7352  #endif
  1.7353  
  1.7354  /*
  1.7355 + * Make sure that the calculated cache size, in pages, cannot cause the
  1.7356 + * initial size of the Win32-specific heap to exceed the maximum amount
  1.7357 + * of memory that can be specified in the call to HeapCreate.
  1.7358 + */
  1.7359 +#if SQLITE_WIN32_CACHE_SIZE>SQLITE_WIN32_MAX_CACHE_SIZE
  1.7360 +#  undef SQLITE_WIN32_CACHE_SIZE
  1.7361 +#  define SQLITE_WIN32_CACHE_SIZE       (2000)
  1.7362 +#endif
  1.7363 +
  1.7364 +/*
  1.7365   * The initial size of the Win32-specific heap.  This value may be zero.
  1.7366   */
  1.7367  #ifndef SQLITE_WIN32_HEAP_INIT_SIZE
  1.7368 -#  define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_WIN32_CACHE_SIZE) * \
  1.7369 -                                       (SQLITE_DEFAULT_PAGE_SIZE) + 4194304)
  1.7370 +#  define SQLITE_WIN32_HEAP_INIT_SIZE   ((SQLITE_WIN32_CACHE_SIZE) * \
  1.7371 +                                         (SQLITE_DEFAULT_PAGE_SIZE) + \
  1.7372 +                                         (SQLITE_WIN32_HEAP_INIT_EXTRA))
  1.7373  #endif
  1.7374  
  1.7375  /*
  1.7376   * The maximum size of the Win32-specific heap.  This value may be zero.
  1.7377   */
  1.7378  #ifndef SQLITE_WIN32_HEAP_MAX_SIZE
  1.7379 -#  define SQLITE_WIN32_HEAP_MAX_SIZE  (0)
  1.7380 +#  define SQLITE_WIN32_HEAP_MAX_SIZE    (0)
  1.7381  #endif
  1.7382  
  1.7383  /*
  1.7384 @@ -37264,7 +38130,7 @@
  1.7385   * zero for the default behavior.
  1.7386   */
  1.7387  #ifndef SQLITE_WIN32_HEAP_FLAGS
  1.7388 -#  define SQLITE_WIN32_HEAP_FLAGS     (0)
  1.7389 +#  define SQLITE_WIN32_HEAP_FLAGS       (0)
  1.7390  #endif
  1.7391  
  1.7392  
  1.7393 @@ -38104,7 +38970,7 @@
  1.7394  ** "pnLargest" argument, if non-zero, will be used to return the size of the
  1.7395  ** largest committed free block in the heap, in bytes.
  1.7396  */
  1.7397 -SQLITE_API int SQLITE_STDCALL sqlite3_win32_compact_heap(LPUINT pnLargest){
  1.7398 +SQLITE_API int sqlite3_win32_compact_heap(LPUINT pnLargest){
  1.7399    int rc = SQLITE_OK;
  1.7400    UINT nLargest = 0;
  1.7401    HANDLE hHeap;
  1.7402 @@ -38144,7 +39010,7 @@
  1.7403  ** the sqlite3_memory_used() function does not return zero, SQLITE_BUSY will
  1.7404  ** be returned and no changes will be made to the Win32 native heap.
  1.7405  */
  1.7406 -SQLITE_API int SQLITE_STDCALL sqlite3_win32_reset_heap(){
  1.7407 +SQLITE_API int sqlite3_win32_reset_heap(){
  1.7408    int rc;
  1.7409    MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
  1.7410    MUTEX_LOGIC( sqlite3_mutex *pMem; )    /* The memsys static mutex */
  1.7411 @@ -38189,7 +39055,7 @@
  1.7412  ** (if available).
  1.7413  */
  1.7414  
  1.7415 -SQLITE_API void SQLITE_STDCALL sqlite3_win32_write_debug(const char *zBuf, int nBuf){
  1.7416 +SQLITE_API void sqlite3_win32_write_debug(const char *zBuf, int nBuf){
  1.7417    char zDbgBuf[SQLITE_WIN32_DBG_BUF_SIZE];
  1.7418    int nMin = MIN(nBuf, (SQLITE_WIN32_DBG_BUF_SIZE - 1)); /* may be negative. */
  1.7419    if( nMin<-1 ) nMin = -1; /* all negative values become -1. */
  1.7420 @@ -38235,7 +39101,7 @@
  1.7421  static HANDLE sleepObj = NULL;
  1.7422  #endif
  1.7423  
  1.7424 -SQLITE_API void SQLITE_STDCALL sqlite3_win32_sleep(DWORD milliseconds){
  1.7425 +SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds){
  1.7426  #if SQLITE_OS_WINRT
  1.7427    if ( sleepObj==NULL ){
  1.7428      sleepObj = osCreateEventExW(NULL, NULL, CREATE_EVENT_MANUAL_RESET,
  1.7429 @@ -38284,7 +39150,7 @@
  1.7430  ** This function determines if the machine is running a version of Windows
  1.7431  ** based on the NT kernel.
  1.7432  */
  1.7433 -SQLITE_API int SQLITE_STDCALL sqlite3_win32_is_nt(void){
  1.7434 +SQLITE_API int sqlite3_win32_is_nt(void){
  1.7435  #if SQLITE_OS_WINRT
  1.7436    /*
  1.7437    ** NOTE: The WinRT sub-platform is always assumed to be based on the NT
  1.7438 @@ -38672,7 +39538,7 @@
  1.7439  /*
  1.7440  ** This is a public wrapper for the winUtf8ToUnicode() function.
  1.7441  */
  1.7442 -SQLITE_API LPWSTR SQLITE_STDCALL sqlite3_win32_utf8_to_unicode(const char *zText){
  1.7443 +SQLITE_API LPWSTR sqlite3_win32_utf8_to_unicode(const char *zText){
  1.7444  #ifdef SQLITE_ENABLE_API_ARMOR
  1.7445    if( !zText ){
  1.7446      (void)SQLITE_MISUSE_BKPT;
  1.7447 @@ -38688,7 +39554,7 @@
  1.7448  /*
  1.7449  ** This is a public wrapper for the winUnicodeToUtf8() function.
  1.7450  */
  1.7451 -SQLITE_API char *SQLITE_STDCALL sqlite3_win32_unicode_to_utf8(LPCWSTR zWideText){
  1.7452 +SQLITE_API char *sqlite3_win32_unicode_to_utf8(LPCWSTR zWideText){
  1.7453  #ifdef SQLITE_ENABLE_API_ARMOR
  1.7454    if( !zWideText ){
  1.7455      (void)SQLITE_MISUSE_BKPT;
  1.7456 @@ -38704,7 +39570,7 @@
  1.7457  /*
  1.7458  ** This is a public wrapper for the winMbcsToUtf8() function.
  1.7459  */
  1.7460 -SQLITE_API char *SQLITE_STDCALL sqlite3_win32_mbcs_to_utf8(const char *zText){
  1.7461 +SQLITE_API char *sqlite3_win32_mbcs_to_utf8(const char *zText){
  1.7462  #ifdef SQLITE_ENABLE_API_ARMOR
  1.7463    if( !zText ){
  1.7464      (void)SQLITE_MISUSE_BKPT;
  1.7465 @@ -38720,7 +39586,7 @@
  1.7466  /*
  1.7467  ** This is a public wrapper for the winMbcsToUtf8() function.
  1.7468  */
  1.7469 -SQLITE_API char *SQLITE_STDCALL sqlite3_win32_mbcs_to_utf8_v2(const char *zText, int useAnsi){
  1.7470 +SQLITE_API char *sqlite3_win32_mbcs_to_utf8_v2(const char *zText, int useAnsi){
  1.7471  #ifdef SQLITE_ENABLE_API_ARMOR
  1.7472    if( !zText ){
  1.7473      (void)SQLITE_MISUSE_BKPT;
  1.7474 @@ -38736,7 +39602,7 @@
  1.7475  /*
  1.7476  ** This is a public wrapper for the winUtf8ToMbcs() function.
  1.7477  */
  1.7478 -SQLITE_API char *SQLITE_STDCALL sqlite3_win32_utf8_to_mbcs(const char *zText){
  1.7479 +SQLITE_API char *sqlite3_win32_utf8_to_mbcs(const char *zText){
  1.7480  #ifdef SQLITE_ENABLE_API_ARMOR
  1.7481    if( !zText ){
  1.7482      (void)SQLITE_MISUSE_BKPT;
  1.7483 @@ -38752,7 +39618,7 @@
  1.7484  /*
  1.7485  ** This is a public wrapper for the winUtf8ToMbcs() function.
  1.7486  */
  1.7487 -SQLITE_API char *SQLITE_STDCALL sqlite3_win32_utf8_to_mbcs_v2(const char *zText, int useAnsi){
  1.7488 +SQLITE_API char *sqlite3_win32_utf8_to_mbcs_v2(const char *zText, int useAnsi){
  1.7489  #ifdef SQLITE_ENABLE_API_ARMOR
  1.7490    if( !zText ){
  1.7491      (void)SQLITE_MISUSE_BKPT;
  1.7492 @@ -38772,7 +39638,7 @@
  1.7493  ** argument is the name of the directory to use.  The return value will be
  1.7494  ** SQLITE_OK if successful.
  1.7495  */
  1.7496 -SQLITE_API int SQLITE_STDCALL sqlite3_win32_set_directory(DWORD type, LPCWSTR zValue){
  1.7497 +SQLITE_API int sqlite3_win32_set_directory(DWORD type, LPCWSTR zValue){
  1.7498    char **ppDirectory = 0;
  1.7499  #ifndef SQLITE_OMIT_AUTOINIT
  1.7500    int rc = sqlite3_initialize();
  1.7501 @@ -39499,7 +40365,12 @@
  1.7502    }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) );
  1.7503  #if SQLITE_OS_WINCE
  1.7504  #define WINCE_DELETION_ATTEMPTS 3
  1.7505 -  winceDestroyLock(pFile);
  1.7506 +  {
  1.7507 +    winVfsAppData *pAppData = (winVfsAppData*)pFile->pVfs->pAppData;
  1.7508 +    if( pAppData==NULL || !pAppData->bNoLock ){
  1.7509 +      winceDestroyLock(pFile);
  1.7510 +    }
  1.7511 +  }
  1.7512    if( pFile->zDeleteOnClose ){
  1.7513      int cnt = 0;
  1.7514      while(
  1.7515 @@ -40231,6 +41102,44 @@
  1.7516    return rc;
  1.7517  }
  1.7518  
  1.7519 +/******************************************************************************
  1.7520 +****************************** No-op Locking **********************************
  1.7521 +**
  1.7522 +** Of the various locking implementations available, this is by far the
  1.7523 +** simplest:  locking is ignored.  No attempt is made to lock the database
  1.7524 +** file for reading or writing.
  1.7525 +**
  1.7526 +** This locking mode is appropriate for use on read-only databases
  1.7527 +** (ex: databases that are burned into CD-ROM, for example.)  It can
  1.7528 +** also be used if the application employs some external mechanism to
  1.7529 +** prevent simultaneous access of the same database by two or more
  1.7530 +** database connections.  But there is a serious risk of database
  1.7531 +** corruption if this locking mode is used in situations where multiple
  1.7532 +** database connections are accessing the same database file at the same
  1.7533 +** time and one or more of those connections are writing.
  1.7534 +*/
  1.7535 +
  1.7536 +static int winNolockLock(sqlite3_file *id, int locktype){
  1.7537 +  UNUSED_PARAMETER(id);
  1.7538 +  UNUSED_PARAMETER(locktype);
  1.7539 +  return SQLITE_OK;
  1.7540 +}
  1.7541 +
  1.7542 +static int winNolockCheckReservedLock(sqlite3_file *id, int *pResOut){
  1.7543 +  UNUSED_PARAMETER(id);
  1.7544 +  UNUSED_PARAMETER(pResOut);
  1.7545 +  return SQLITE_OK;
  1.7546 +}
  1.7547 +
  1.7548 +static int winNolockUnlock(sqlite3_file *id, int locktype){
  1.7549 +  UNUSED_PARAMETER(id);
  1.7550 +  UNUSED_PARAMETER(locktype);
  1.7551 +  return SQLITE_OK;
  1.7552 +}
  1.7553 +
  1.7554 +/******************* End of the no-op lock implementation *********************
  1.7555 +******************************************************************************/
  1.7556 +
  1.7557  /*
  1.7558  ** If *pArg is initially negative then this is a query.  Set *pArg to
  1.7559  ** 1 or 0 depending on whether or not bit mask of pFile->ctrlFlags is set.
  1.7560 @@ -40322,6 +41231,12 @@
  1.7561        OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
  1.7562        return SQLITE_OK;
  1.7563      }
  1.7564 +    case SQLITE_FCNTL_WIN32_GET_HANDLE: {
  1.7565 +      LPHANDLE phFile = (LPHANDLE)pArg;
  1.7566 +      *phFile = pFile->h;
  1.7567 +      OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
  1.7568 +      return SQLITE_OK;
  1.7569 +    }
  1.7570  #ifdef SQLITE_TEST
  1.7571      case SQLITE_FCNTL_WIN32_SET_HANDLE: {
  1.7572        LPHANDLE phFile = (LPHANDLE)pArg;
  1.7573 @@ -40509,12 +41424,12 @@
  1.7574  /*
  1.7575  ** Apply advisory locks for all n bytes beginning at ofst.
  1.7576  */
  1.7577 -#define _SHM_UNLCK  1
  1.7578 -#define _SHM_RDLCK  2
  1.7579 -#define _SHM_WRLCK  3
  1.7580 +#define WINSHM_UNLCK  1
  1.7581 +#define WINSHM_RDLCK  2
  1.7582 +#define WINSHM_WRLCK  3
  1.7583  static int winShmSystemLock(
  1.7584    winShmNode *pFile,    /* Apply locks to this open shared-memory segment */
  1.7585 -  int lockType,         /* _SHM_UNLCK, _SHM_RDLCK, or _SHM_WRLCK */
  1.7586 +  int lockType,         /* WINSHM_UNLCK, WINSHM_RDLCK, or WINSHM_WRLCK */
  1.7587    int ofst,             /* Offset to first byte to be locked/unlocked */
  1.7588    int nByte             /* Number of bytes to lock or unlock */
  1.7589  ){
  1.7590 @@ -40527,12 +41442,12 @@
  1.7591             pFile->hFile.h, lockType, ofst, nByte));
  1.7592  
  1.7593    /* Release/Acquire the system-level lock */
  1.7594 -  if( lockType==_SHM_UNLCK ){
  1.7595 +  if( lockType==WINSHM_UNLCK ){
  1.7596      rc = winUnlockFile(&pFile->hFile.h, ofst, 0, nByte, 0);
  1.7597    }else{
  1.7598      /* Initialize the locking parameters */
  1.7599      DWORD dwFlags = LOCKFILE_FAIL_IMMEDIATELY;
  1.7600 -    if( lockType == _SHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
  1.7601 +    if( lockType == WINSHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
  1.7602      rc = winLockFile(&pFile->hFile.h, dwFlags, ofst, 0, nByte, 0);
  1.7603    }
  1.7604  
  1.7605 @@ -40544,7 +41459,7 @@
  1.7606    }
  1.7607  
  1.7608    OSTRACE(("SHM-LOCK file=%p, func=%s, errno=%lu, rc=%s\n",
  1.7609 -           pFile->hFile.h, (lockType == _SHM_UNLCK) ? "winUnlockFile" :
  1.7610 +           pFile->hFile.h, (lockType == WINSHM_UNLCK) ? "winUnlockFile" :
  1.7611             "winLockFile", pFile->lastErrno, sqlite3ErrName(rc)));
  1.7612  
  1.7613    return rc;
  1.7614 @@ -40672,7 +41587,7 @@
  1.7615      /* Check to see if another process is holding the dead-man switch.
  1.7616      ** If not, truncate the file to zero length.
  1.7617      */
  1.7618 -    if( winShmSystemLock(pShmNode, _SHM_WRLCK, WIN_SHM_DMS, 1)==SQLITE_OK ){
  1.7619 +    if( winShmSystemLock(pShmNode, WINSHM_WRLCK, WIN_SHM_DMS, 1)==SQLITE_OK ){
  1.7620        rc = winTruncate((sqlite3_file *)&pShmNode->hFile, 0);
  1.7621        if( rc!=SQLITE_OK ){
  1.7622          rc = winLogError(SQLITE_IOERR_SHMOPEN, osGetLastError(),
  1.7623 @@ -40680,8 +41595,8 @@
  1.7624        }
  1.7625      }
  1.7626      if( rc==SQLITE_OK ){
  1.7627 -      winShmSystemLock(pShmNode, _SHM_UNLCK, WIN_SHM_DMS, 1);
  1.7628 -      rc = winShmSystemLock(pShmNode, _SHM_RDLCK, WIN_SHM_DMS, 1);
  1.7629 +      winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1);
  1.7630 +      rc = winShmSystemLock(pShmNode, WINSHM_RDLCK, WIN_SHM_DMS, 1);
  1.7631      }
  1.7632      if( rc ) goto shm_open_err;
  1.7633    }
  1.7634 @@ -40710,7 +41625,7 @@
  1.7635  
  1.7636    /* Jump here on any error */
  1.7637  shm_open_err:
  1.7638 -  winShmSystemLock(pShmNode, _SHM_UNLCK, WIN_SHM_DMS, 1);
  1.7639 +  winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1);
  1.7640    winShmPurge(pDbFd->pVfs, 0);      /* This call frees pShmNode if required */
  1.7641    sqlite3_free(p);
  1.7642    sqlite3_free(pNew);
  1.7643 @@ -40799,7 +41714,7 @@
  1.7644  
  1.7645      /* Unlock the system-level locks */
  1.7646      if( (mask & allMask)==0 ){
  1.7647 -      rc = winShmSystemLock(pShmNode, _SHM_UNLCK, ofst+WIN_SHM_BASE, n);
  1.7648 +      rc = winShmSystemLock(pShmNode, WINSHM_UNLCK, ofst+WIN_SHM_BASE, n);
  1.7649      }else{
  1.7650        rc = SQLITE_OK;
  1.7651      }
  1.7652 @@ -40827,7 +41742,7 @@
  1.7653      /* Get shared locks at the system level, if necessary */
  1.7654      if( rc==SQLITE_OK ){
  1.7655        if( (allShared & mask)==0 ){
  1.7656 -        rc = winShmSystemLock(pShmNode, _SHM_RDLCK, ofst+WIN_SHM_BASE, n);
  1.7657 +        rc = winShmSystemLock(pShmNode, WINSHM_RDLCK, ofst+WIN_SHM_BASE, n);
  1.7658        }else{
  1.7659          rc = SQLITE_OK;
  1.7660        }
  1.7661 @@ -40852,7 +41767,7 @@
  1.7662      ** also mark the local connection as being locked.
  1.7663      */
  1.7664      if( rc==SQLITE_OK ){
  1.7665 -      rc = winShmSystemLock(pShmNode, _SHM_WRLCK, ofst+WIN_SHM_BASE, n);
  1.7666 +      rc = winShmSystemLock(pShmNode, WINSHM_WRLCK, ofst+WIN_SHM_BASE, n);
  1.7667        if( rc==SQLITE_OK ){
  1.7668          assert( (p->sharedMask & mask)==0 );
  1.7669          p->exclMask |= mask;
  1.7670 @@ -41295,6 +42210,44 @@
  1.7671    winUnfetch                      /* xUnfetch */
  1.7672  };
  1.7673  
  1.7674 +/*
  1.7675 +** This vector defines all the methods that can operate on an
  1.7676 +** sqlite3_file for win32 without performing any locking.
  1.7677 +*/
  1.7678 +static const sqlite3_io_methods winIoNolockMethod = {
  1.7679 +  3,                              /* iVersion */
  1.7680 +  winClose,                       /* xClose */
  1.7681 +  winRead,                        /* xRead */
  1.7682 +  winWrite,                       /* xWrite */
  1.7683 +  winTruncate,                    /* xTruncate */
  1.7684 +  winSync,                        /* xSync */
  1.7685 +  winFileSize,                    /* xFileSize */
  1.7686 +  winNolockLock,                  /* xLock */
  1.7687 +  winNolockUnlock,                /* xUnlock */
  1.7688 +  winNolockCheckReservedLock,     /* xCheckReservedLock */
  1.7689 +  winFileControl,                 /* xFileControl */
  1.7690 +  winSectorSize,                  /* xSectorSize */
  1.7691 +  winDeviceCharacteristics,       /* xDeviceCharacteristics */
  1.7692 +  winShmMap,                      /* xShmMap */
  1.7693 +  winShmLock,                     /* xShmLock */
  1.7694 +  winShmBarrier,                  /* xShmBarrier */
  1.7695 +  winShmUnmap,                    /* xShmUnmap */
  1.7696 +  winFetch,                       /* xFetch */
  1.7697 +  winUnfetch                      /* xUnfetch */
  1.7698 +};
  1.7699 +
  1.7700 +static winVfsAppData winAppData = {
  1.7701 +  &winIoMethod,       /* pMethod */
  1.7702 +  0,                  /* pAppData */
  1.7703 +  0                   /* bNoLock */
  1.7704 +};
  1.7705 +
  1.7706 +static winVfsAppData winNolockAppData = {
  1.7707 +  &winIoNolockMethod, /* pMethod */
  1.7708 +  0,                  /* pAppData */
  1.7709 +  1                   /* bNoLock */
  1.7710 +};
  1.7711 +
  1.7712  /****************************************************************************
  1.7713  **************************** sqlite3_vfs methods ****************************
  1.7714  **
  1.7715 @@ -41627,7 +42580,7 @@
  1.7716  ** Open a file.
  1.7717  */
  1.7718  static int winOpen(
  1.7719 -  sqlite3_vfs *pVfs,        /* Used to get maximum path name length */
  1.7720 +  sqlite3_vfs *pVfs,        /* Used to get maximum path length and AppData */
  1.7721    const char *zName,        /* Name of the file (UTF-8) */
  1.7722    sqlite3_file *id,         /* Write the SQLite file handle here */
  1.7723    int flags,                /* Open mode flags */
  1.7724 @@ -41642,6 +42595,7 @@
  1.7725  #if SQLITE_OS_WINCE
  1.7726    int isTemp = 0;
  1.7727  #endif
  1.7728 +  winVfsAppData *pAppData;
  1.7729    winFile *pFile = (winFile*)id;
  1.7730    void *zConverted;              /* Filename in OS encoding */
  1.7731    const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
  1.7732 @@ -41863,15 +42817,20 @@
  1.7733             "rc=%s\n", h, zUtf8Name, dwDesiredAccess, pOutFlags, pOutFlags ?
  1.7734             *pOutFlags : 0, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok"));
  1.7735  
  1.7736 +  pAppData = (winVfsAppData*)pVfs->pAppData;
  1.7737 +
  1.7738  #if SQLITE_OS_WINCE
  1.7739 -  if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB
  1.7740 -       && (rc = winceCreateLock(zName, pFile))!=SQLITE_OK
  1.7741 -  ){
  1.7742 -    osCloseHandle(h);
  1.7743 -    sqlite3_free(zConverted);
  1.7744 -    sqlite3_free(zTmpname);
  1.7745 -    OSTRACE(("OPEN-CE-LOCK name=%s, rc=%s\n", zName, sqlite3ErrName(rc)));
  1.7746 -    return rc;
  1.7747 +  {
  1.7748 +    if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB
  1.7749 +         && ((pAppData==NULL) || !pAppData->bNoLock)
  1.7750 +         && (rc = winceCreateLock(zName, pFile))!=SQLITE_OK
  1.7751 +    ){
  1.7752 +      osCloseHandle(h);
  1.7753 +      sqlite3_free(zConverted);
  1.7754 +      sqlite3_free(zTmpname);
  1.7755 +      OSTRACE(("OPEN-CE-LOCK name=%s, rc=%s\n", zName, sqlite3ErrName(rc)));
  1.7756 +      return rc;
  1.7757 +    }
  1.7758    }
  1.7759    if( isTemp ){
  1.7760      pFile->zDeleteOnClose = zConverted;
  1.7761 @@ -41882,7 +42841,7 @@
  1.7762    }
  1.7763  
  1.7764    sqlite3_free(zTmpname);
  1.7765 -  pFile->pMethod = &winIoMethod;
  1.7766 +  pFile->pMethod = pAppData ? pAppData->pMethod : &winIoMethod;
  1.7767    pFile->pVfs = pVfs;
  1.7768    pFile->h = h;
  1.7769    if( isReadonly ){
  1.7770 @@ -42157,6 +43116,18 @@
  1.7771    int nFull,                    /* Size of output buffer in bytes */
  1.7772    char *zFull                   /* Output buffer */
  1.7773  ){
  1.7774 +#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(__CYGWIN__)
  1.7775 +  DWORD nByte;
  1.7776 +  void *zConverted;
  1.7777 +  char *zOut;
  1.7778 +#endif
  1.7779 +
  1.7780 +  /* If this path name begins with "/X:", where "X" is any alphabetic
  1.7781 +  ** character, discard the initial "/" from the pathname.
  1.7782 +  */
  1.7783 +  if( zRelative[0]=='/' && winIsDriveLetterAndColon(zRelative+1) ){
  1.7784 +    zRelative++;
  1.7785 +  }
  1.7786  
  1.7787  #if defined(__CYGWIN__)
  1.7788    SimulateIOError( return SQLITE_ERROR );
  1.7789 @@ -42235,17 +43206,6 @@
  1.7790  #endif
  1.7791  
  1.7792  #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(__CYGWIN__)
  1.7793 -  DWORD nByte;
  1.7794 -  void *zConverted;
  1.7795 -  char *zOut;
  1.7796 -
  1.7797 -  /* If this path name begins with "/X:", where "X" is any alphabetic
  1.7798 -  ** character, discard the initial "/" from the pathname.
  1.7799 -  */
  1.7800 -  if( zRelative[0]=='/' && winIsDriveLetterAndColon(zRelative+1) ){
  1.7801 -    zRelative++;
  1.7802 -  }
  1.7803 -
  1.7804    /* It's odd to simulate an io-error here, but really this is just
  1.7805    ** using the io-error infrastructure to test that SQLite handles this
  1.7806    ** function failing. This function could fail if, for example, the
  1.7807 @@ -42602,55 +43562,105 @@
  1.7808  /*
  1.7809  ** Initialize and deinitialize the operating system interface.
  1.7810  */
  1.7811 -SQLITE_API int SQLITE_STDCALL sqlite3_os_init(void){
  1.7812 +SQLITE_API int sqlite3_os_init(void){
  1.7813    static sqlite3_vfs winVfs = {
  1.7814 -    3,                   /* iVersion */
  1.7815 -    sizeof(winFile),     /* szOsFile */
  1.7816 +    3,                     /* iVersion */
  1.7817 +    sizeof(winFile),       /* szOsFile */
  1.7818      SQLITE_WIN32_MAX_PATH_BYTES, /* mxPathname */
  1.7819 -    0,                   /* pNext */
  1.7820 -    "win32",             /* zName */
  1.7821 -    0,                   /* pAppData */
  1.7822 -    winOpen,             /* xOpen */
  1.7823 -    winDelete,           /* xDelete */
  1.7824 -    winAccess,           /* xAccess */
  1.7825 -    winFullPathname,     /* xFullPathname */
  1.7826 -    winDlOpen,           /* xDlOpen */
  1.7827 -    winDlError,          /* xDlError */
  1.7828 -    winDlSym,            /* xDlSym */
  1.7829 -    winDlClose,          /* xDlClose */
  1.7830 -    winRandomness,       /* xRandomness */
  1.7831 -    winSleep,            /* xSleep */
  1.7832 -    winCurrentTime,      /* xCurrentTime */
  1.7833 -    winGetLastError,     /* xGetLastError */
  1.7834 -    winCurrentTimeInt64, /* xCurrentTimeInt64 */
  1.7835 -    winSetSystemCall,    /* xSetSystemCall */
  1.7836 -    winGetSystemCall,    /* xGetSystemCall */
  1.7837 -    winNextSystemCall,   /* xNextSystemCall */
  1.7838 +    0,                     /* pNext */
  1.7839 +    "win32",               /* zName */
  1.7840 +    &winAppData,           /* pAppData */
  1.7841 +    winOpen,               /* xOpen */
  1.7842 +    winDelete,             /* xDelete */
  1.7843 +    winAccess,             /* xAccess */
  1.7844 +    winFullPathname,       /* xFullPathname */
  1.7845 +    winDlOpen,             /* xDlOpen */
  1.7846 +    winDlError,            /* xDlError */
  1.7847 +    winDlSym,              /* xDlSym */
  1.7848 +    winDlClose,            /* xDlClose */
  1.7849 +    winRandomness,         /* xRandomness */
  1.7850 +    winSleep,              /* xSleep */
  1.7851 +    winCurrentTime,        /* xCurrentTime */
  1.7852 +    winGetLastError,       /* xGetLastError */
  1.7853 +    winCurrentTimeInt64,   /* xCurrentTimeInt64 */
  1.7854 +    winSetSystemCall,      /* xSetSystemCall */
  1.7855 +    winGetSystemCall,      /* xGetSystemCall */
  1.7856 +    winNextSystemCall,     /* xNextSystemCall */
  1.7857    };
  1.7858  #if defined(SQLITE_WIN32_HAS_WIDE)
  1.7859    static sqlite3_vfs winLongPathVfs = {
  1.7860 -    3,                   /* iVersion */
  1.7861 -    sizeof(winFile),     /* szOsFile */
  1.7862 +    3,                     /* iVersion */
  1.7863 +    sizeof(winFile),       /* szOsFile */
  1.7864      SQLITE_WINNT_MAX_PATH_BYTES, /* mxPathname */
  1.7865 -    0,                   /* pNext */
  1.7866 -    "win32-longpath",    /* zName */
  1.7867 -    0,                   /* pAppData */
  1.7868 -    winOpen,             /* xOpen */
  1.7869 -    winDelete,           /* xDelete */
  1.7870 -    winAccess,           /* xAccess */
  1.7871 -    winFullPathname,     /* xFullPathname */
  1.7872 -    winDlOpen,           /* xDlOpen */
  1.7873 -    winDlError,          /* xDlError */
  1.7874 -    winDlSym,            /* xDlSym */
  1.7875 -    winDlClose,          /* xDlClose */
  1.7876 -    winRandomness,       /* xRandomness */
  1.7877 -    winSleep,            /* xSleep */
  1.7878 -    winCurrentTime,      /* xCurrentTime */
  1.7879 -    winGetLastError,     /* xGetLastError */
  1.7880 -    winCurrentTimeInt64, /* xCurrentTimeInt64 */
  1.7881 -    winSetSystemCall,    /* xSetSystemCall */
  1.7882 -    winGetSystemCall,    /* xGetSystemCall */
  1.7883 -    winNextSystemCall,   /* xNextSystemCall */
  1.7884 +    0,                     /* pNext */
  1.7885 +    "win32-longpath",      /* zName */
  1.7886 +    &winAppData,           /* pAppData */
  1.7887 +    winOpen,               /* xOpen */
  1.7888 +    winDelete,             /* xDelete */
  1.7889 +    winAccess,             /* xAccess */
  1.7890 +    winFullPathname,       /* xFullPathname */
  1.7891 +    winDlOpen,             /* xDlOpen */
  1.7892 +    winDlError,            /* xDlError */
  1.7893 +    winDlSym,              /* xDlSym */
  1.7894 +    winDlClose,            /* xDlClose */
  1.7895 +    winRandomness,         /* xRandomness */
  1.7896 +    winSleep,              /* xSleep */
  1.7897 +    winCurrentTime,        /* xCurrentTime */
  1.7898 +    winGetLastError,       /* xGetLastError */
  1.7899 +    winCurrentTimeInt64,   /* xCurrentTimeInt64 */
  1.7900 +    winSetSystemCall,      /* xSetSystemCall */
  1.7901 +    winGetSystemCall,      /* xGetSystemCall */
  1.7902 +    winNextSystemCall,     /* xNextSystemCall */
  1.7903 +  };
  1.7904 +#endif
  1.7905 +  static sqlite3_vfs winNolockVfs = {
  1.7906 +    3,                     /* iVersion */
  1.7907 +    sizeof(winFile),       /* szOsFile */
  1.7908 +    SQLITE_WIN32_MAX_PATH_BYTES, /* mxPathname */
  1.7909 +    0,                     /* pNext */
  1.7910 +    "win32-none",          /* zName */
  1.7911 +    &winNolockAppData,     /* pAppData */
  1.7912 +    winOpen,               /* xOpen */
  1.7913 +    winDelete,             /* xDelete */
  1.7914 +    winAccess,             /* xAccess */
  1.7915 +    winFullPathname,       /* xFullPathname */
  1.7916 +    winDlOpen,             /* xDlOpen */
  1.7917 +    winDlError,            /* xDlError */
  1.7918 +    winDlSym,              /* xDlSym */
  1.7919 +    winDlClose,            /* xDlClose */
  1.7920 +    winRandomness,         /* xRandomness */
  1.7921 +    winSleep,              /* xSleep */
  1.7922 +    winCurrentTime,        /* xCurrentTime */
  1.7923 +    winGetLastError,       /* xGetLastError */
  1.7924 +    winCurrentTimeInt64,   /* xCurrentTimeInt64 */
  1.7925 +    winSetSystemCall,      /* xSetSystemCall */
  1.7926 +    winGetSystemCall,      /* xGetSystemCall */
  1.7927 +    winNextSystemCall,     /* xNextSystemCall */
  1.7928 +  };
  1.7929 +#if defined(SQLITE_WIN32_HAS_WIDE)
  1.7930 +  static sqlite3_vfs winLongPathNolockVfs = {
  1.7931 +    3,                     /* iVersion */
  1.7932 +    sizeof(winFile),       /* szOsFile */
  1.7933 +    SQLITE_WINNT_MAX_PATH_BYTES, /* mxPathname */
  1.7934 +    0,                     /* pNext */
  1.7935 +    "win32-longpath-none", /* zName */
  1.7936 +    &winNolockAppData,     /* pAppData */
  1.7937 +    winOpen,               /* xOpen */
  1.7938 +    winDelete,             /* xDelete */
  1.7939 +    winAccess,             /* xAccess */
  1.7940 +    winFullPathname,       /* xFullPathname */
  1.7941 +    winDlOpen,             /* xDlOpen */
  1.7942 +    winDlError,            /* xDlError */
  1.7943 +    winDlSym,              /* xDlSym */
  1.7944 +    winDlClose,            /* xDlClose */
  1.7945 +    winRandomness,         /* xRandomness */
  1.7946 +    winSleep,              /* xSleep */
  1.7947 +    winCurrentTime,        /* xCurrentTime */
  1.7948 +    winGetLastError,       /* xGetLastError */
  1.7949 +    winCurrentTimeInt64,   /* xCurrentTimeInt64 */
  1.7950 +    winSetSystemCall,      /* xSetSystemCall */
  1.7951 +    winGetSystemCall,      /* xGetSystemCall */
  1.7952 +    winNextSystemCall,     /* xNextSystemCall */
  1.7953    };
  1.7954  #endif
  1.7955  
  1.7956 @@ -42674,10 +43684,16 @@
  1.7957    sqlite3_vfs_register(&winLongPathVfs, 0);
  1.7958  #endif
  1.7959  
  1.7960 -  return SQLITE_OK;
  1.7961 -}
  1.7962 -
  1.7963 -SQLITE_API int SQLITE_STDCALL sqlite3_os_end(void){
  1.7964 +  sqlite3_vfs_register(&winNolockVfs, 0);
  1.7965 +
  1.7966 +#if defined(SQLITE_WIN32_HAS_WIDE)
  1.7967 +  sqlite3_vfs_register(&winLongPathNolockVfs, 0);
  1.7968 +#endif
  1.7969 +
  1.7970 +  return SQLITE_OK;
  1.7971 +}
  1.7972 +
  1.7973 +SQLITE_API int sqlite3_os_end(void){
  1.7974  #if SQLITE_OS_WINRT
  1.7975    if( sleepObj!=NULL ){
  1.7976      osCloseHandle(sleepObj);
  1.7977 @@ -42986,7 +44002,7 @@
  1.7978    return p->iSize;
  1.7979  }
  1.7980  
  1.7981 -#ifndef SQLITE_OMIT_BUILTIN_TEST
  1.7982 +#ifndef SQLITE_UNTESTABLE
  1.7983  /*
  1.7984  ** Let V[] be an array of unsigned characters sufficient to hold
  1.7985  ** up to N bits.  Let I be an integer between 0 and N.  0<=I<N.
  1.7986 @@ -43101,7 +44117,7 @@
  1.7987    sqlite3BitvecDestroy(pBitvec);
  1.7988    return rc;
  1.7989  }
  1.7990 -#endif /* SQLITE_OMIT_BUILTIN_TEST */
  1.7991 +#endif /* SQLITE_UNTESTABLE */
  1.7992  
  1.7993  /************** End of bitvec.c **********************************************/
  1.7994  /************** Begin file pcache.c ******************************************/
  1.7995 @@ -43211,11 +44227,11 @@
  1.7996  **
  1.7997  **          assert( sqlite3PcachePageSanity(pPg) );
  1.7998  */
  1.7999 -#if SQLITE_DEBUG
  1.8000 +#ifdef SQLITE_DEBUG
  1.8001  SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr *pPg){
  1.8002    PCache *pCache;
  1.8003    assert( pPg!=0 );
  1.8004 -  assert( pPg->pgno>0 );    /* Page number is 1 or more */
  1.8005 +  assert( pPg->pgno>0 || pPg->pPager==0 );    /* Page number is 1 or more */
  1.8006    pCache = pPg->pCache;
  1.8007    assert( pCache!=0 );      /* Every page has an associated PCache */
  1.8008    if( pPg->flags & PGHDR_CLEAN ){
  1.8009 @@ -43391,6 +44407,12 @@
  1.8010  ** has already been allocated and is passed in as the p pointer. 
  1.8011  ** The caller discovers how much space needs to be allocated by 
  1.8012  ** calling sqlite3PcacheSize().
  1.8013 +**
  1.8014 +** szExtra is some extra space allocated for each page.  The first
  1.8015 +** 8 bytes of the extra space will be zeroed as the page is allocated,
  1.8016 +** but remaining content will be uninitialized.  Though it is opaque
  1.8017 +** to this module, the extra space really ends up being the MemPage
  1.8018 +** structure in the pager.
  1.8019  */
  1.8020  SQLITE_PRIVATE int sqlite3PcacheOpen(
  1.8021    int szPage,                  /* Size of every page */
  1.8022 @@ -43403,6 +44425,7 @@
  1.8023    memset(p, 0, sizeof(PCache));
  1.8024    p->szPage = 1;
  1.8025    p->szExtra = szExtra;
  1.8026 +  assert( szExtra>=8 );  /* First 8 bytes will be zeroed */
  1.8027    p->bPurgeable = bPurgeable;
  1.8028    p->eCreate = 2;
  1.8029    p->xStress = xStress;
  1.8030 @@ -43472,7 +44495,6 @@
  1.8031    assert( pCache!=0 );
  1.8032    assert( pCache->pCache!=0 );
  1.8033    assert( createFlag==3 || createFlag==0 );
  1.8034 -  assert( pgno>0 );
  1.8035    assert( pCache->eCreate==((pCache->bPurgeable && pCache->pDirty) ? 1 : 2) );
  1.8036  
  1.8037    /* eCreate defines what to do if the page does not exist.
  1.8038 @@ -43568,11 +44590,11 @@
  1.8039    assert( pPage!=0 );
  1.8040    pPgHdr = (PgHdr*)pPage->pExtra;
  1.8041    assert( pPgHdr->pPage==0 );
  1.8042 -  memset(pPgHdr, 0, sizeof(PgHdr));
  1.8043 +  memset(&pPgHdr->pDirty, 0, sizeof(PgHdr) - offsetof(PgHdr,pDirty));
  1.8044    pPgHdr->pPage = pPage;
  1.8045    pPgHdr->pData = pPage->pBuf;
  1.8046    pPgHdr->pExtra = (void *)&pPgHdr[1];
  1.8047 -  memset(pPgHdr->pExtra, 0, pCache->szExtra);
  1.8048 +  memset(pPgHdr->pExtra, 0, 8);
  1.8049    pPgHdr->pCache = pCache;
  1.8050    pPgHdr->pgno = pgno;
  1.8051    pPgHdr->flags = PGHDR_CLEAN;
  1.8052 @@ -43794,28 +44816,30 @@
  1.8053  
  1.8054  /*
  1.8055  ** Merge two lists of pages connected by pDirty and in pgno order.
  1.8056 -** Do not both fixing the pDirtyPrev pointers.
  1.8057 +** Do not bother fixing the pDirtyPrev pointers.
  1.8058  */
  1.8059  static PgHdr *pcacheMergeDirtyList(PgHdr *pA, PgHdr *pB){
  1.8060    PgHdr result, *pTail;
  1.8061    pTail = &result;
  1.8062 -  while( pA && pB ){
  1.8063 +  assert( pA!=0 && pB!=0 );
  1.8064 +  for(;;){
  1.8065      if( pA->pgno<pB->pgno ){
  1.8066        pTail->pDirty = pA;
  1.8067        pTail = pA;
  1.8068        pA = pA->pDirty;
  1.8069 +      if( pA==0 ){
  1.8070 +        pTail->pDirty = pB;
  1.8071 +        break;
  1.8072 +      }
  1.8073      }else{
  1.8074        pTail->pDirty = pB;
  1.8075        pTail = pB;
  1.8076        pB = pB->pDirty;
  1.8077 -    }
  1.8078 -  }
  1.8079 -  if( pA ){
  1.8080 -    pTail->pDirty = pA;
  1.8081 -  }else if( pB ){
  1.8082 -    pTail->pDirty = pB;
  1.8083 -  }else{
  1.8084 -    pTail->pDirty = 0;
  1.8085 +      if( pB==0 ){
  1.8086 +        pTail->pDirty = pA;
  1.8087 +        break;
  1.8088 +      }
  1.8089 +    }
  1.8090    }
  1.8091    return result.pDirty;