| Index: third_party/sqlite/src/src/sqliteInt.h | 
| diff --git a/third_party/sqlite/src/src/sqliteInt.h b/third_party/sqlite/src/src/sqliteInt.h | 
| index 684fa57f6d8cb479a7a8faf5a20da626cd88eb8b..9d6a7d82b29ca682990ad8dc53c46c8efba44a74 100644 | 
| --- a/third_party/sqlite/src/src/sqliteInt.h | 
| +++ b/third_party/sqlite/src/src/sqliteInt.h | 
| @@ -32,6 +32,11 @@ | 
| ** in Red Hat 6.0, so the code won't work.  Hence, for maximum binary | 
| ** portability you should omit LFS. | 
| ** | 
| +** The previous paragraph was written in 2005.  (This paragraph is written | 
| +** on 2008-11-28.) These days, all Linux kernels support large files, so | 
| +** you should probably leave LFS enabled.  But some embedded platforms might | 
| +** lack LFS in which case the SQLITE_DISABLE_LFS macro might still be useful. | 
| +** | 
| ** Similar is true for Mac OS X.  LFS is only supported on Mac OS X 9 and later. | 
| */ | 
| #ifndef SQLITE_DISABLE_LFS | 
| @@ -42,6 +47,53 @@ | 
| # define _LARGEFILE_SOURCE 1 | 
| #endif | 
|  | 
| +/* Needed for various definitions... */ | 
| +#if defined(__GNUC__) && !defined(_GNU_SOURCE) | 
| +# define _GNU_SOURCE | 
| +#endif | 
| + | 
| +#if defined(__OpenBSD__) && !defined(_BSD_SOURCE) | 
| +# define _BSD_SOURCE | 
| +#endif | 
| + | 
| +/* | 
| +** For MinGW, check to see if we can include the header file containing its | 
| +** version information, among other things.  Normally, this internal MinGW | 
| +** header file would [only] be included automatically by other MinGW header | 
| +** files; however, the contained version information is now required by this | 
| +** header file to work around binary compatibility issues (see below) and | 
| +** this is the only known way to reliably obtain it.  This entire #if block | 
| +** would be completely unnecessary if there was any other way of detecting | 
| +** MinGW via their preprocessor (e.g. if they customized their GCC to define | 
| +** some MinGW-specific macros).  When compiling for MinGW, either the | 
| +** _HAVE_MINGW_H or _HAVE__MINGW_H (note the extra underscore) macro must be | 
| +** defined; otherwise, detection of conditions specific to MinGW will be | 
| +** disabled. | 
| +*/ | 
| +#if defined(_HAVE_MINGW_H) | 
| +# include "mingw.h" | 
| +#elif defined(_HAVE__MINGW_H) | 
| +# include "_mingw.h" | 
| +#endif | 
| + | 
| +/* | 
| +** For MinGW version 4.x (and higher), check to see if the _USE_32BIT_TIME_T | 
| +** define is required to maintain binary compatibility with the MSVC runtime | 
| +** library in use (e.g. for Windows XP). | 
| +*/ | 
| +#if !defined(_USE_32BIT_TIME_T) && !defined(_USE_64BIT_TIME_T) && \ | 
| +    defined(_WIN32) && !defined(_WIN64) && \ | 
| +    defined(__MINGW_MAJOR_VERSION) && __MINGW_MAJOR_VERSION >= 4 && \ | 
| +    defined(__MSVCRT__) | 
| +# define _USE_32BIT_TIME_T | 
| +#endif | 
| + | 
| +/* The public SQLite interface.  The _FILE_OFFSET_BITS macro must appear | 
| +** first in QNX.  Also, the _USE_32BIT_TIME_T macro must appear first for | 
| +** MinGW. | 
| +*/ | 
| +#include "sqlite3.h" | 
| + | 
| /* | 
| ** Include the configuration header output by 'configure' if we're using the | 
| ** autoconf-based build | 
| @@ -61,11 +113,6 @@ | 
| #pragma warn -spa /* Suspicious pointer arithmetic */ | 
| #endif | 
|  | 
| -/* Needed for various definitions... */ | 
| -#ifndef _GNU_SOURCE | 
| -# define _GNU_SOURCE | 
| -#endif | 
| - | 
| /* | 
| ** Include standard header files as necessary | 
| */ | 
| @@ -77,13 +124,6 @@ | 
| #endif | 
|  | 
| /* | 
| -** The number of samples of an index that SQLite takes in order to | 
| -** construct a histogram of the table content when running ANALYZE | 
| -** and with SQLITE_ENABLE_STAT2 | 
| -*/ | 
| -#define SQLITE_INDEX_SAMPLES 10 | 
| - | 
| -/* | 
| ** The following macros are used to cast pointers to integers and | 
| ** integers to pointers.  The way you do this varies from one compiler | 
| ** to the next, so we have developed the following set of #if statements | 
| @@ -114,10 +154,22 @@ | 
| #endif | 
|  | 
| /* | 
| +** A macro to hint to the compiler that a function should not be | 
| +** inlined. | 
| +*/ | 
| +#if defined(__GNUC__) | 
| +#  define SQLITE_NOINLINE  __attribute__((noinline)) | 
| +#elif defined(_MSC_VER) && _MSC_VER>=1310 | 
| +#  define SQLITE_NOINLINE  __declspec(noinline) | 
| +#else | 
| +#  define SQLITE_NOINLINE | 
| +#endif | 
| + | 
| +/* | 
| ** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2. | 
| ** 0 means mutexes are permanently disable and the library is never | 
| ** threadsafe.  1 means the library is serialized which is the highest | 
| -** level of threadsafety.  2 means the libary is multithreaded - multiple | 
| +** level of threadsafety.  2 means the library is multithreaded - multiple | 
| ** threads can use SQLite as long as no two threads try to use the same | 
| ** database connection at the same time. | 
| ** | 
| @@ -125,11 +177,19 @@ | 
| ** We support that for legacy. | 
| */ | 
| #if !defined(SQLITE_THREADSAFE) | 
| -#if defined(THREADSAFE) | 
| -# define SQLITE_THREADSAFE THREADSAFE | 
| -#else | 
| -# define SQLITE_THREADSAFE 1 /* IMP: R-07272-22309 */ | 
| +# if defined(THREADSAFE) | 
| +#   define SQLITE_THREADSAFE THREADSAFE | 
| +# else | 
| +#   define SQLITE_THREADSAFE 1 /* IMP: R-07272-22309 */ | 
| +# endif | 
| #endif | 
| + | 
| +/* | 
| +** Powersafe overwrite is on by default.  But can be turned off using | 
| +** the -DSQLITE_POWERSAFE_OVERWRITE=0 command-line option. | 
| +*/ | 
| +#ifndef SQLITE_POWERSAFE_OVERWRITE | 
| +# define SQLITE_POWERSAFE_OVERWRITE 1 | 
| #endif | 
|  | 
| /* | 
| @@ -147,19 +207,31 @@ | 
| ** specify which memory allocation subsystem to use. | 
| ** | 
| **     SQLITE_SYSTEM_MALLOC          // Use normal system malloc() | 
| +**     SQLITE_WIN32_MALLOC           // Use Win32 native heap API | 
| +**     SQLITE_ZERO_MALLOC            // Use a stub allocator that always fails | 
| **     SQLITE_MEMDEBUG               // Debugging version of system malloc() | 
| ** | 
| -** (Historical note:  There used to be several other options, but we've | 
| -** pared it down to just these two.) | 
| +** On Windows, if the SQLITE_WIN32_MALLOC_VALIDATE macro is defined and the | 
| +** assert() macro is enabled, each call into the Win32 native heap subsystem | 
| +** will cause HeapValidate to be called.  If heap validation should fail, an | 
| +** assertion will be triggered. | 
| ** | 
| ** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as | 
| ** the default. | 
| */ | 
| -#if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)>1 | 
| -# error "At most one of the following compile-time configuration options\ | 
| - is allows: SQLITE_SYSTEM_MALLOC, SQLITE_MEMDEBUG" | 
| -#endif | 
| -#if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)==0 | 
| +#if defined(SQLITE_SYSTEM_MALLOC) \ | 
| +  + defined(SQLITE_WIN32_MALLOC) \ | 
| +  + defined(SQLITE_ZERO_MALLOC) \ | 
| +  + defined(SQLITE_MEMDEBUG)>1 | 
| +# error "Two or more of the following compile-time configuration options\ | 
| + are defined but at most one is allowed:\ | 
| + SQLITE_SYSTEM_MALLOC, SQLITE_WIN32_MALLOC, SQLITE_MEMDEBUG,\ | 
| + SQLITE_ZERO_MALLOC" | 
| +#endif | 
| +#if defined(SQLITE_SYSTEM_MALLOC) \ | 
| +  + defined(SQLITE_WIN32_MALLOC) \ | 
| +  + defined(SQLITE_ZERO_MALLOC) \ | 
| +  + defined(SQLITE_MEMDEBUG)==0 | 
| # define SQLITE_SYSTEM_MALLOC 1 | 
| #endif | 
|  | 
| @@ -173,37 +245,37 @@ | 
|  | 
| /* | 
| ** We need to define _XOPEN_SOURCE as follows in order to enable | 
| -** recursive mutexes on most Unix systems.  But Mac OS X is different. | 
| -** The _XOPEN_SOURCE define causes problems for Mac OS X we are told, | 
| -** so it is omitted there.  See ticket #2673. | 
| -** | 
| -** Later we learn that _XOPEN_SOURCE is poorly or incorrectly | 
| -** implemented on some systems.  So we avoid defining it at all | 
| -** if it is already defined or if it is unneeded because we are | 
| -** not doing a threadsafe build.  Ticket #2681. | 
| -** | 
| -** See also ticket #2741. | 
| +** recursive mutexes on most Unix systems and fchmod() on OpenBSD. | 
| +** But _XOPEN_SOURCE define causes problems for Mac OS X, so omit | 
| +** it. | 
| */ | 
| -#if !defined(_XOPEN_SOURCE) && !defined(__DARWIN__) && !defined(__APPLE__) && SQLITE_THREADSAFE | 
| -#  define _XOPEN_SOURCE 500  /* Needed to enable pthread recursive mutexes */ | 
| +#if !defined(_XOPEN_SOURCE) && !defined(__DARWIN__) && !defined(__APPLE__) | 
| +#  define _XOPEN_SOURCE 600 | 
| #endif | 
|  | 
| /* | 
| -** The TCL headers are only needed when compiling the TCL bindings. | 
| +** NDEBUG and SQLITE_DEBUG are opposites.  It should always be true that | 
| +** defined(NDEBUG)==!defined(SQLITE_DEBUG).  If this is not currently true, | 
| +** make it true by defining or undefining NDEBUG. | 
| +** | 
| +** Setting NDEBUG makes the code smaller and faster by disabling the | 
| +** assert() statements in the code.  So we want the default action | 
| +** to be for NDEBUG to be set and NDEBUG to be undefined only if SQLITE_DEBUG | 
| +** is set.  Thus NDEBUG becomes an opt-in rather than an opt-out | 
| +** feature. | 
| */ | 
| -#if defined(SQLITE_TCL) || defined(TCLSH) | 
| -# include <tcl.h> | 
| +#if !defined(NDEBUG) && !defined(SQLITE_DEBUG) | 
| +# define NDEBUG 1 | 
| +#endif | 
| +#if defined(NDEBUG) && defined(SQLITE_DEBUG) | 
| +# undef NDEBUG | 
| #endif | 
|  | 
| /* | 
| -** Many people are failing to set -DNDEBUG=1 when compiling SQLite. | 
| -** Setting NDEBUG makes the code smaller and run faster.  So the following | 
| -** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1 | 
| -** option is set.  Thus NDEBUG becomes an opt-in rather than an opt-out | 
| -** feature. | 
| +** Enable SQLITE_ENABLE_EXPLAIN_COMMENTS if SQLITE_DEBUG is turned on. | 
| */ | 
| -#if !defined(NDEBUG) && !defined(SQLITE_DEBUG) | 
| -# define NDEBUG 1 | 
| +#if !defined(SQLITE_ENABLE_EXPLAIN_COMMENTS) && defined(SQLITE_DEBUG) | 
| +# define SQLITE_ENABLE_EXPLAIN_COMMENTS 1 | 
| #endif | 
|  | 
| /* | 
| @@ -264,7 +336,7 @@ | 
| ** In other words, ALWAYS and NEVER are added for defensive code. | 
| ** | 
| ** When doing coverage testing ALWAYS and NEVER are hard-coded to | 
| -** be true and false so that the unreachable code then specify will | 
| +** be true and false so that the unreachable code they specify will | 
| ** not be counted as untested code. | 
| */ | 
| #if defined(SQLITE_COVERAGE_TEST) | 
| @@ -279,7 +351,7 @@ | 
| #endif | 
|  | 
| /* | 
| -** Return true (non-zero) if the input is a integer that is too large | 
| +** Return true (non-zero) if the input is an integer that is too large | 
| ** to fit in 32-bits.  This macro is used inside of various testcase() | 
| ** macros to verify that we have tested SQLite for large-file support. | 
| */ | 
| @@ -288,18 +360,13 @@ | 
| /* | 
| ** The macro unlikely() is a hint that surrounds a boolean | 
| ** expression that is usually false.  Macro likely() surrounds | 
| -** a boolean expression that is usually true.  GCC is able to | 
| -** use these hints to generate better code, sometimes. | 
| +** a boolean expression that is usually true.  These hints could, | 
| +** in theory, be used by the compiler to generate better code, but | 
| +** currently they are just comments for human readers. | 
| */ | 
| -#if defined(__GNUC__) && 0 | 
| -# define likely(X)    __builtin_expect((X),1) | 
| -# define unlikely(X)  __builtin_expect((X),0) | 
| -#else | 
| -# define likely(X)    !!(X) | 
| -# define unlikely(X)  !!(X) | 
| -#endif | 
| +#define likely(X)    (X) | 
| +#define unlikely(X)  (X) | 
|  | 
| -#include "sqlite3.h" | 
| #include "hash.h" | 
| #include "parse.h" | 
| #include <stdio.h> | 
| @@ -347,7 +414,7 @@ | 
| */ | 
| #define SQLITE_MAX_FILE_FORMAT 4 | 
| #ifndef SQLITE_DEFAULT_FILE_FORMAT | 
| -# define SQLITE_DEFAULT_FILE_FORMAT 1 | 
| +# define SQLITE_DEFAULT_FILE_FORMAT 4 | 
| #endif | 
|  | 
| /* | 
| @@ -364,7 +431,29 @@ | 
| */ | 
| #ifndef SQLITE_TEMP_STORE | 
| # define SQLITE_TEMP_STORE 1 | 
| +# define SQLITE_TEMP_STORE_xc 1  /* Exclude from ctime.c */ | 
| +#endif | 
| + | 
| +/* | 
| +** If no value has been provided for SQLITE_MAX_WORKER_THREADS, or if | 
| +** SQLITE_TEMP_STORE is set to 3 (never use temporary files), set it | 
| +** to zero. | 
| +*/ | 
| +#if SQLITE_TEMP_STORE==3 || SQLITE_THREADSAFE==0 | 
| +# undef SQLITE_MAX_WORKER_THREADS | 
| +# define SQLITE_MAX_WORKER_THREADS 0 | 
| +#endif | 
| +#ifndef SQLITE_MAX_WORKER_THREADS | 
| +# define SQLITE_MAX_WORKER_THREADS 8 | 
| +#endif | 
| +#ifndef SQLITE_DEFAULT_WORKER_THREADS | 
| +# define SQLITE_DEFAULT_WORKER_THREADS 0 | 
| #endif | 
| +#if SQLITE_DEFAULT_WORKER_THREADS>SQLITE_MAX_WORKER_THREADS | 
| +# undef SQLITE_MAX_WORKER_THREADS | 
| +# define SQLITE_MAX_WORKER_THREADS SQLITE_DEFAULT_WORKER_THREADS | 
| +#endif | 
| + | 
|  | 
| /* | 
| ** GCC does not define the offsetof() macro so we'll have to do it | 
| @@ -375,6 +464,17 @@ | 
| #endif | 
|  | 
| /* | 
| +** Macros to compute minimum and maximum of two numbers. | 
| +*/ | 
| +#define MIN(A,B) ((A)<(B)?(A):(B)) | 
| +#define MAX(A,B) ((A)>(B)?(A):(B)) | 
| + | 
| +/* | 
| +** Swap two objects of type TYPE. | 
| +*/ | 
| +#define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;} | 
| + | 
| +/* | 
| ** Check to see if this machine uses EBCDIC.  (Yes, believe it or | 
| ** not, there are still machines out there that use EBCDIC.) | 
| */ | 
| @@ -446,23 +546,77 @@ typedef INT8_TYPE i8;              /* 1-byte signed integer */ | 
| #define SQLITE_MAX_U32  ((((u64)1)<<32)-1) | 
|  | 
| /* | 
| +** The datatype used to store estimates of the number of rows in a | 
| +** table or index.  This is an unsigned integer type.  For 99.9% of | 
| +** the world, a 32-bit integer is sufficient.  But a 64-bit integer | 
| +** can be used at compile-time if desired. | 
| +*/ | 
| +#ifdef SQLITE_64BIT_STATS | 
| + typedef u64 tRowcnt;    /* 64-bit only if requested at compile-time */ | 
| +#else | 
| + typedef u32 tRowcnt;    /* 32-bit is the default */ | 
| +#endif | 
| + | 
| +/* | 
| +** Estimated quantities used for query planning are stored as 16-bit | 
| +** logarithms.  For quantity X, the value stored is 10*log2(X).  This | 
| +** gives a possible range of values of approximately 1.0e986 to 1e-986. | 
| +** But the allowed values are "grainy".  Not every value is representable. | 
| +** For example, quantities 16 and 17 are both represented by a LogEst | 
| +** of 40.  However, since LogEst quantaties are suppose to be estimates, | 
| +** not exact values, this imprecision is not a problem. | 
| +** | 
| +** "LogEst" is short for "Logarithmic Estimate". | 
| +** | 
| +** Examples: | 
| +**      1 -> 0              20 -> 43          10000 -> 132 | 
| +**      2 -> 10             25 -> 46          25000 -> 146 | 
| +**      3 -> 16            100 -> 66        1000000 -> 199 | 
| +**      4 -> 20           1000 -> 99        1048576 -> 200 | 
| +**     10 -> 33           1024 -> 100    4294967296 -> 320 | 
| +** | 
| +** The LogEst can be negative to indicate fractional values. | 
| +** Examples: | 
| +** | 
| +**    0.5 -> -10           0.1 -> -33        0.0625 -> -40 | 
| +*/ | 
| +typedef INT16_TYPE LogEst; | 
| + | 
| +/* | 
| ** Macros to determine whether the machine is big or little endian, | 
| -** evaluated at runtime. | 
| +** and whether or not that determination is run-time or compile-time. | 
| +** | 
| +** For best performance, an attempt is made to guess at the byte-order | 
| +** using C-preprocessor macros.  If that is unsuccessful, or if | 
| +** -DSQLITE_RUNTIME_BYTEORDER=1 is set, then byte-order is determined | 
| +** at run-time. | 
| */ | 
| #ifdef SQLITE_AMALGAMATION | 
| const int sqlite3one = 1; | 
| #else | 
| extern const int sqlite3one; | 
| #endif | 
| -#if defined(i386) || defined(__i386__) || defined(_M_IX86)\ | 
| -                             || defined(__x86_64) || defined(__x86_64__) | 
| +#if (defined(i386)     || defined(__i386__)   || defined(_M_IX86) ||    \ | 
| +     defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)  ||    \ | 
| +     defined(_M_AMD64) || defined(_M_ARM)     || defined(__x86)   ||    \ | 
| +     defined(__arm__)) && !defined(SQLITE_RUNTIME_BYTEORDER) | 
| +# define SQLITE_BYTEORDER    1234 | 
| # define SQLITE_BIGENDIAN    0 | 
| # define SQLITE_LITTLEENDIAN 1 | 
| # define SQLITE_UTF16NATIVE  SQLITE_UTF16LE | 
| -#else | 
| +#endif | 
| +#if (defined(sparc)    || defined(__ppc__))  \ | 
| +    && !defined(SQLITE_RUNTIME_BYTEORDER) | 
| +# define SQLITE_BYTEORDER    4321 | 
| +# define SQLITE_BIGENDIAN    1 | 
| +# define SQLITE_LITTLEENDIAN 0 | 
| +# define SQLITE_UTF16NATIVE  SQLITE_UTF16BE | 
| +#endif | 
| +#if !defined(SQLITE_BYTEORDER) | 
| +# define SQLITE_BYTEORDER    0     /* 0 means "unknown at compile-time" */ | 
| # define SQLITE_BIGENDIAN    (*(char *)(&sqlite3one)==0) | 
| # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1) | 
| -# define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE) | 
| +# define SQLITE_UTF16NATIVE  (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE) | 
| #endif | 
|  | 
| /* | 
| @@ -490,7 +644,7 @@ extern const int sqlite3one; | 
| ** all alignment restrictions correct. | 
| ** | 
| ** Except, if SQLITE_4_BYTE_ALIGNED_MALLOC is defined, then the | 
| -** underlying malloc() implemention might return us 4-byte aligned | 
| +** underlying malloc() implementation might return us 4-byte aligned | 
| ** pointers.  In that case, only verify 4-byte alignment. | 
| */ | 
| #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC | 
| @@ -499,6 +653,73 @@ extern const int sqlite3one; | 
| # define EIGHT_BYTE_ALIGNMENT(X)   ((((char*)(X) - (char*)0)&7)==0) | 
| #endif | 
|  | 
| +/* | 
| +** Disable MMAP on platforms where it is known to not work | 
| +*/ | 
| +#if defined(__OpenBSD__) || defined(__QNXNTO__) | 
| +# undef SQLITE_MAX_MMAP_SIZE | 
| +# define SQLITE_MAX_MMAP_SIZE 0 | 
| +#endif | 
| + | 
| +/* | 
| +** Default maximum size of memory used by memory-mapped I/O in the VFS | 
| +*/ | 
| +#ifdef __APPLE__ | 
| +# include <TargetConditionals.h> | 
| +# if TARGET_OS_IPHONE | 
| +#   undef SQLITE_MAX_MMAP_SIZE | 
| +#   define SQLITE_MAX_MMAP_SIZE 0 | 
| +# endif | 
| +#endif | 
| +#ifndef SQLITE_MAX_MMAP_SIZE | 
| +# if defined(__linux__) \ | 
| +  || defined(_WIN32) \ | 
| +  || (defined(__APPLE__) && defined(__MACH__)) \ | 
| +  || defined(__sun) | 
| +#   define SQLITE_MAX_MMAP_SIZE 0x7fff0000  /* 2147418112 */ | 
| +# else | 
| +#   define SQLITE_MAX_MMAP_SIZE 0 | 
| +# endif | 
| +# define SQLITE_MAX_MMAP_SIZE_xc 1 /* exclude from ctime.c */ | 
| +#endif | 
| + | 
| +/* | 
| +** The default MMAP_SIZE is zero on all platforms.  Or, even if a larger | 
| +** default MMAP_SIZE is specified at compile-time, make sure that it does | 
| +** not exceed the maximum mmap size. | 
| +*/ | 
| +#ifndef SQLITE_DEFAULT_MMAP_SIZE | 
| +# define SQLITE_DEFAULT_MMAP_SIZE 0 | 
| +# define SQLITE_DEFAULT_MMAP_SIZE_xc 1  /* Exclude from ctime.c */ | 
| +#endif | 
| +#if SQLITE_DEFAULT_MMAP_SIZE>SQLITE_MAX_MMAP_SIZE | 
| +# undef SQLITE_DEFAULT_MMAP_SIZE | 
| +# define SQLITE_DEFAULT_MMAP_SIZE SQLITE_MAX_MMAP_SIZE | 
| +#endif | 
| + | 
| +/* | 
| +** Only one of SQLITE_ENABLE_STAT3 or SQLITE_ENABLE_STAT4 can be defined. | 
| +** Priority is given to SQLITE_ENABLE_STAT4.  If either are defined, also | 
| +** define SQLITE_ENABLE_STAT3_OR_STAT4 | 
| +*/ | 
| +#ifdef SQLITE_ENABLE_STAT4 | 
| +# undef SQLITE_ENABLE_STAT3 | 
| +# define SQLITE_ENABLE_STAT3_OR_STAT4 1 | 
| +#elif SQLITE_ENABLE_STAT3 | 
| +# define SQLITE_ENABLE_STAT3_OR_STAT4 1 | 
| +#elif SQLITE_ENABLE_STAT3_OR_STAT4 | 
| +# undef SQLITE_ENABLE_STAT3_OR_STAT4 | 
| +#endif | 
| + | 
| +/* | 
| +** SELECTTRACE_ENABLED will be either 1 or 0 depending on whether or not | 
| +** the Select query generator tracing logic is turned on. | 
| +*/ | 
| +#if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_SELECTTRACE) | 
| +# define SELECTTRACE_ENABLED 1 | 
| +#else | 
| +# define SELECTTRACE_ENABLED 0 | 
| +#endif | 
|  | 
| /* | 
| ** An instance of the following structure is used to store the busy-handler | 
| @@ -541,10 +762,19 @@ struct BusyHandler { | 
| #define ArraySize(X)    ((int)(sizeof(X)/sizeof(X[0]))) | 
|  | 
| /* | 
| +** Determine if the argument is a power of two | 
| +*/ | 
| +#define IsPowerOfTwo(X) (((X)&((X)-1))==0) | 
| + | 
| +/* | 
| ** The following value as a destructor means to use sqlite3DbFree(). | 
| -** This is an internal extension to SQLITE_STATIC and SQLITE_TRANSIENT. | 
| +** The sqlite3DbFree() routine requires two parameters instead of the | 
| +** one parameter that destructors normally want.  So we have to introduce | 
| +** this magic value that the code knows to handle differently.  Any | 
| +** pointer will work here as long as it is distinct from SQLITE_STATIC | 
| +** and SQLITE_TRANSIENT. | 
| */ | 
| -#define SQLITE_DYNAMIC   ((sqlite3_destructor_type)sqlite3DbFree) | 
| +#define SQLITE_DYNAMIC   ((sqlite3_destructor_type)sqlite3MallocSize) | 
|  | 
| /* | 
| ** When SQLITE_OMIT_WSD is defined, it means that the target platform does | 
| @@ -619,23 +849,27 @@ typedef struct LookasideSlot LookasideSlot; | 
| typedef struct Module Module; | 
| typedef struct NameContext NameContext; | 
| typedef struct Parse Parse; | 
| +typedef struct PrintfArguments PrintfArguments; | 
| typedef struct RowSet RowSet; | 
| typedef struct Savepoint Savepoint; | 
| typedef struct Select Select; | 
| +typedef struct SQLiteThread SQLiteThread; | 
| +typedef struct SelectDest SelectDest; | 
| typedef struct SrcList SrcList; | 
| typedef struct StrAccum StrAccum; | 
| typedef struct Table Table; | 
| typedef struct TableLock TableLock; | 
| typedef struct Token Token; | 
| +typedef struct TreeView TreeView; | 
| typedef struct Trigger Trigger; | 
| typedef struct TriggerPrg TriggerPrg; | 
| typedef struct TriggerStep TriggerStep; | 
| typedef struct UnpackedRecord UnpackedRecord; | 
| typedef struct VTable VTable; | 
| +typedef struct VtabCtx VtabCtx; | 
| typedef struct Walker Walker; | 
| -typedef struct WherePlan WherePlan; | 
| typedef struct WhereInfo WhereInfo; | 
| -typedef struct WhereLevel WhereLevel; | 
| +typedef struct With With; | 
|  | 
| /* | 
| ** Defer sourcing vdbe.h and btree.h until after the "u8" and | 
| @@ -661,7 +895,6 @@ typedef struct WhereLevel WhereLevel; | 
| struct Db { | 
| char *zName;         /* Name of this database */ | 
| Btree *pBt;          /* The B*Tree structure for this database file */ | 
| -  u8 inTrans;          /* 0: not writable.  1: Transaction.  2: Checkpoint */ | 
| u8 safety_level;     /* How aggressive at syncing data to disk */ | 
| Schema *pSchema;     /* Pointer to database schema (possibly shared) */ | 
| }; | 
| @@ -681,7 +914,7 @@ struct Db { | 
| ** A thread must be holding a mutex on the corresponding Btree in order | 
| ** to access Schema content.  This implies that the thread must also be | 
| ** holding a mutex on the sqlite3 connection pointer that owns the Btree. | 
| -** For a TEMP Schema, on the connection mutex is required. | 
| +** For a TEMP Schema, only the connection mutex is required. | 
| */ | 
| struct Schema { | 
| int schema_cookie;   /* Database schema version number for this file */ | 
| @@ -693,7 +926,7 @@ struct Schema { | 
| Table *pSeqTab;      /* The sqlite_sequence table used by AUTOINCREMENT */ | 
| u8 file_format;      /* Schema format version for this file */ | 
| u8 enc;              /* Text encoding used by this database */ | 
| -  u16 flags;           /* Flags associated with this schema */ | 
| +  u16 schemaFlags;     /* Flags associated with this schema */ | 
| int cache_size;      /* Number of pages to use in the cache */ | 
| }; | 
|  | 
| @@ -701,10 +934,10 @@ struct Schema { | 
| ** These macros can be used to test, set, or clear bits in the | 
| ** Db.pSchema->flags field. | 
| */ | 
| -#define DbHasProperty(D,I,P)     (((D)->aDb[I].pSchema->flags&(P))==(P)) | 
| -#define DbHasAnyProperty(D,I,P)  (((D)->aDb[I].pSchema->flags&(P))!=0) | 
| -#define DbSetProperty(D,I,P)     (D)->aDb[I].pSchema->flags|=(P) | 
| -#define DbClearProperty(D,I,P)   (D)->aDb[I].pSchema->flags&=~(P) | 
| +#define DbHasProperty(D,I,P)     (((D)->aDb[I].pSchema->schemaFlags&(P))==(P)) | 
| +#define DbHasAnyProperty(D,I,P)  (((D)->aDb[I].pSchema->schemaFlags&(P))!=0) | 
| +#define DbSetProperty(D,I,P)     (D)->aDb[I].pSchema->schemaFlags|=(P) | 
| +#define DbClearProperty(D,I,P)   (D)->aDb[I].pSchema->schemaFlags&=~(P) | 
|  | 
| /* | 
| ** Allowed values for the DB.pSchema->flags field. | 
| @@ -724,7 +957,7 @@ struct Schema { | 
| ** The number of different kinds of things that can be limited | 
| ** using the sqlite3_limit() interface. | 
| */ | 
| -#define SQLITE_N_LIMIT (SQLITE_LIMIT_TRIGGER_DEPTH+1) | 
| +#define SQLITE_N_LIMIT (SQLITE_LIMIT_WORKER_THREADS+1) | 
|  | 
| /* | 
| ** Lookaside malloc is a set of fixed-size buffers that can be used | 
| @@ -771,67 +1004,88 @@ struct FuncDefHash { | 
| FuncDef *a[23];       /* Hash table for functions */ | 
| }; | 
|  | 
| +#ifdef SQLITE_USER_AUTHENTICATION | 
| +/* | 
| +** Information held in the "sqlite3" database connection object and used | 
| +** to manage user authentication. | 
| +*/ | 
| +typedef struct sqlite3_userauth sqlite3_userauth; | 
| +struct sqlite3_userauth { | 
| +  u8 authLevel;                 /* Current authentication level */ | 
| +  int nAuthPW;                  /* Size of the zAuthPW in bytes */ | 
| +  char *zAuthPW;                /* Password used to authenticate */ | 
| +  char *zAuthUser;              /* User name used to authenticate */ | 
| +}; | 
| + | 
| +/* Allowed values for sqlite3_userauth.authLevel */ | 
| +#define UAUTH_Unknown     0     /* Authentication not yet checked */ | 
| +#define UAUTH_Fail        1     /* User authentication failed */ | 
| +#define UAUTH_User        2     /* Authenticated as a normal user */ | 
| +#define UAUTH_Admin       3     /* Authenticated as an administrator */ | 
| + | 
| +/* Functions used only by user authorization logic */ | 
| +int sqlite3UserAuthTable(const char*); | 
| +int sqlite3UserAuthCheckLogin(sqlite3*,const char*,u8*); | 
| +void sqlite3UserAuthInit(sqlite3*); | 
| +void sqlite3CryptFunc(sqlite3_context*,int,sqlite3_value**); | 
| + | 
| +#endif /* SQLITE_USER_AUTHENTICATION */ | 
| + | 
| +/* | 
| +** typedef for the authorization callback function. | 
| +*/ | 
| +#ifdef SQLITE_USER_AUTHENTICATION | 
| +  typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*, | 
| +                               const char*, const char*); | 
| +#else | 
| +  typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*, | 
| +                               const char*); | 
| +#endif | 
| + | 
| + | 
| /* | 
| ** Each database connection is an instance of the following structure. | 
| -** | 
| -** The sqlite.lastRowid records the last insert rowid generated by an | 
| -** insert statement.  Inserts on views do not affect its value.  Each | 
| -** trigger has its own context, so that lastRowid can be updated inside | 
| -** triggers as usual.  The previous value will be restored once the trigger | 
| -** exits.  Upon entering a before or instead of trigger, lastRowid is no | 
| -** longer (since after version 2.8.12) reset to -1. | 
| -** | 
| -** The sqlite.nChange does not count changes within triggers and keeps no | 
| -** context.  It is reset at start of sqlite3_exec. | 
| -** The sqlite.lsChange represents the number of changes made by the last | 
| -** insert, update, or delete statement.  It remains constant throughout the | 
| -** length of a statement and is then updated by OP_SetCounts.  It keeps a | 
| -** context stack just like lastRowid so that the count of changes | 
| -** within a trigger is not seen outside the trigger.  Changes to views do not | 
| -** affect the value of lsChange. | 
| -** The sqlite.csChange keeps track of the number of current changes (since | 
| -** the last statement) and is used to update sqlite_lsChange. | 
| -** | 
| -** The member variables sqlite.errCode, sqlite.zErrMsg and sqlite.zErrMsg16 | 
| -** store the most recent error code and, if applicable, string. The | 
| -** internal function sqlite3Error() is used to set these variables | 
| -** consistently. | 
| */ | 
| struct sqlite3 { | 
| sqlite3_vfs *pVfs;            /* OS Interface */ | 
| -  int nDb;                      /* Number of backends currently in use */ | 
| +  struct Vdbe *pVdbe;           /* List of active virtual machines */ | 
| +  CollSeq *pDfltColl;           /* The default collating sequence (BINARY) */ | 
| +  sqlite3_mutex *mutex;         /* Connection mutex */ | 
| Db *aDb;                      /* All backends */ | 
| +  int nDb;                      /* Number of backends currently in use */ | 
| int flags;                    /* Miscellaneous flags. See below */ | 
| -  int openFlags;                /* Flags passed to sqlite3_vfs.xOpen() */ | 
| +  i64 lastRowid;                /* ROWID of most recent insert (see above) */ | 
| +  i64 szMmap;                   /* Default mmap_size setting */ | 
| +  unsigned int openFlags;       /* Flags passed to sqlite3_vfs.xOpen() */ | 
| int errCode;                  /* Most recent error code (SQLITE_*) */ | 
| int errMask;                  /* & result codes with this before returning */ | 
| +  u16 dbOptFlags;               /* Flags to enable/disable optimizations */ | 
| u8 autoCommit;                /* The auto-commit flag. */ | 
| u8 temp_store;                /* 1: file 2: memory 0: default */ | 
| u8 mallocFailed;              /* True if we have seen a malloc failure */ | 
| u8 dfltLockMode;              /* Default locking-mode for attached dbs */ | 
| signed char nextAutovac;      /* Autovac setting after VACUUM if >=0 */ | 
| u8 suppressErr;               /* Do not issue error messages if true */ | 
| +  u8 vtabOnConflict;            /* Value to return for s3_vtab_on_conflict() */ | 
| +  u8 isTransactionSavepoint;    /* True if the outermost savepoint is a TS */ | 
| int nextPagesize;             /* Pagesize after VACUUM if >0 */ | 
| -  int nTable;                   /* Number of tables in the database */ | 
| -  CollSeq *pDfltColl;           /* The default collating sequence (BINARY) */ | 
| -  i64 lastRowid;                /* ROWID of most recent insert (see above) */ | 
| u32 magic;                    /* Magic number for detect library misuse */ | 
| int nChange;                  /* Value returned by sqlite3_changes() */ | 
| int nTotalChange;             /* Value returned by sqlite3_total_changes() */ | 
| -  sqlite3_mutex *mutex;         /* Connection mutex */ | 
| int aLimit[SQLITE_N_LIMIT];   /* Limits */ | 
| +  int nMaxSorterMmap;           /* Maximum size of regions mapped by sorter */ | 
| struct sqlite3InitInfo {      /* Information used during initialization */ | 
| -    int iDb;                    /* When back is being initialized */ | 
| int newTnum;                /* Rootpage of table being initialized */ | 
| +    u8 iDb;                     /* Which db file is being initialized */ | 
| u8 busy;                    /* TRUE if currently initializing */ | 
| u8 orphanTrigger;           /* Last statement is orphaned TEMP trigger */ | 
| } init; | 
| +  int nVdbeActive;              /* Number of VDBEs currently running */ | 
| +  int nVdbeRead;                /* Number of active VDBEs that read or write */ | 
| +  int nVdbeWrite;               /* Number of active VDBEs that read and write */ | 
| +  int nVdbeExec;                /* Number of nested calls to VdbeExec() */ | 
| int nExtension;               /* Number of loaded extensions */ | 
| void **aExtension;            /* Array of shared library handles */ | 
| -  struct Vdbe *pVdbe;           /* List of active virtual machines */ | 
| -  int activeVdbeCnt;            /* Number of VDBEs currently executing */ | 
| -  int writeVdbeCnt;             /* Number of active VDBEs that are writing */ | 
| -  int vdbeExecCnt;              /* Number of nested calls to VdbeExec() */ | 
| void (*xTrace)(void*,const char*);        /* Trace function */ | 
| void *pTraceArg;                          /* Argument to the trace function */ | 
| void (*xProfile)(void*,const char*,u64);  /* Profiling function */ | 
| @@ -850,42 +1104,38 @@ struct sqlite3 { | 
| void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*); | 
| void *pCollNeededArg; | 
| sqlite3_value *pErr;          /* Most recent error message */ | 
| -  char *zErrMsg;                /* Most recent error message (UTF-8 encoded) */ | 
| -  char *zErrMsg16;              /* Most recent error message (UTF-16 encoded) */ | 
| union { | 
| volatile int isInterrupted; /* True if sqlite3_interrupt has been called */ | 
| double notUsed1;            /* Spacer */ | 
| } u1; | 
| Lookaside lookaside;          /* Lookaside malloc configuration */ | 
| #ifndef SQLITE_OMIT_AUTHORIZATION | 
| -  int (*xAuth)(void*,int,const char*,const char*,const char*,const char*); | 
| -                                /* Access authorization function */ | 
| +  sqlite3_xauth xAuth;          /* Access authorization function */ | 
| void *pAuthArg;               /* 1st argument to the access auth function */ | 
| #endif | 
| #ifndef SQLITE_OMIT_PROGRESS_CALLBACK | 
| int (*xProgress)(void *);     /* The progress callback */ | 
| void *pProgressArg;           /* Argument to the progress callback */ | 
| -  int nProgressOps;             /* Number of opcodes for progress callback */ | 
| +  unsigned nProgressOps;        /* Number of opcodes for progress callback */ | 
| #endif | 
| #ifndef SQLITE_OMIT_VIRTUALTABLE | 
| +  int nVTrans;                  /* Allocated size of aVTrans */ | 
| Hash aModule;                 /* populated by sqlite3_create_module() */ | 
| -  Table *pVTab;                 /* vtab with active Connect/Create method */ | 
| +  VtabCtx *pVtabCtx;            /* Context for active vtab connect/create */ | 
| VTable **aVTrans;             /* Virtual tables with open transactions */ | 
| -  int nVTrans;                  /* Allocated size of aVTrans */ | 
| VTable *pDisconnect;    /* Disconnect these in next sqlite3_prepare() */ | 
| #endif | 
| FuncDefHash aFunc;            /* Hash table of connection functions */ | 
| Hash aCollSeq;                /* All collating sequences */ | 
| BusyHandler busyHandler;      /* Busy callback */ | 
| -  int busyTimeout;              /* Busy handler timeout, in msec */ | 
| Db aDbStatic[2];              /* Static space for the 2 default backends */ | 
| Savepoint *pSavepoint;        /* List of active savepoints */ | 
| +  int busyTimeout;              /* Busy handler timeout, in msec */ | 
| int nSavepoint;               /* Number of non-transaction savepoints */ | 
| int nStatement;               /* Number of nested statement-transactions  */ | 
| -  u8 isTransactionSavepoint;    /* True if the outermost savepoint is a TS */ | 
| i64 nDeferredCons;            /* Net deferred constraints this transaction. */ | 
| +  i64 nDeferredImmCons;         /* Net deferred immediate constraints */ | 
| int *pnBytesFreed;            /* If not NULL, increment this in DbFree() */ | 
| - | 
| #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY | 
| /* The following variables are all protected by the STATIC_MASTER | 
| ** mutex, not by sqlite3.mutex. They are used by code in notify.c. | 
| @@ -903,6 +1153,9 @@ struct sqlite3 { | 
| void (*xUnlockNotify)(void **, int);  /* Unlock notify callback */ | 
| sqlite3 *pNextBlocked;        /* Next in list of all blocked connections */ | 
| #endif | 
| +#ifdef SQLITE_USER_AUTHENTICATION | 
| +  sqlite3_userauth auth;        /* User authentication information */ | 
| +#endif | 
| }; | 
|  | 
| /* | 
| @@ -913,47 +1166,73 @@ struct sqlite3 { | 
| /* | 
| ** Possible values for the sqlite3.flags. | 
| */ | 
| -#define SQLITE_VdbeTrace      0x00000100  /* True to trace VDBE execution */ | 
| -#define SQLITE_InternChanges  0x00000200  /* Uncommitted Hash table changes */ | 
| -#define SQLITE_FullColNames   0x00000400  /* Show full column names on SELECT */ | 
| -#define SQLITE_ShortColNames  0x00000800  /* Show short columns names */ | 
| -#define SQLITE_CountRows      0x00001000  /* Count rows changed by INSERT, */ | 
| +#define SQLITE_VdbeTrace      0x00000001  /* True to trace VDBE execution */ | 
| +#define SQLITE_InternChanges  0x00000002  /* Uncommitted Hash table changes */ | 
| +#define SQLITE_FullFSync      0x00000004  /* Use full fsync on the backend */ | 
| +#define SQLITE_CkptFullFSync  0x00000008  /* Use full fsync for checkpoint */ | 
| +#define SQLITE_CacheSpill     0x00000010  /* OK to spill pager cache */ | 
| +#define SQLITE_FullColNames   0x00000020  /* Show full column names on SELECT */ | 
| +#define SQLITE_ShortColNames  0x00000040  /* Show short columns names */ | 
| +#define SQLITE_CountRows      0x00000080  /* Count rows changed by INSERT, */ | 
| /*   DELETE, or UPDATE and return */ | 
| /*   the count using a callback. */ | 
| -#define SQLITE_NullCallback   0x00002000  /* Invoke the callback once if the */ | 
| +#define SQLITE_NullCallback   0x00000100  /* Invoke the callback once if the */ | 
| /*   result set is empty */ | 
| -#define SQLITE_SqlTrace       0x00004000  /* Debug print SQL as it executes */ | 
| -#define SQLITE_VdbeListing    0x00008000  /* Debug listings of VDBE programs */ | 
| -#define SQLITE_WriteSchema    0x00010000  /* OK to update SQLITE_MASTER */ | 
| -#define SQLITE_NoReadlock     0x00020000  /* Readlocks are omitted when | 
| -                                          ** accessing read-only databases */ | 
| -#define SQLITE_IgnoreChecks   0x00040000  /* Do not enforce check constraints */ | 
| -#define SQLITE_ReadUncommitted 0x0080000  /* For shared-cache mode */ | 
| -#define SQLITE_LegacyFileFmt  0x00100000  /* Create new databases in format 1 */ | 
| -#define SQLITE_FullFSync      0x00200000  /* Use full fsync on the backend */ | 
| -#define SQLITE_CkptFullFSync  0x00400000  /* Use full fsync for checkpoint */ | 
| -#define SQLITE_RecoveryMode   0x00800000  /* Ignore schema errors */ | 
| -#define SQLITE_ReverseOrder   0x01000000  /* Reverse unordered SELECTs */ | 
| -#define SQLITE_RecTriggers    0x02000000  /* Enable recursive triggers */ | 
| -#define SQLITE_ForeignKeys    0x04000000  /* Enforce foreign key constraints  */ | 
| -#define SQLITE_AutoIndex      0x08000000  /* Enable automatic indexes */ | 
| -#define SQLITE_PreferBuiltin  0x10000000  /* Preference to built-in funcs */ | 
| -#define SQLITE_LoadExtension  0x20000000  /* Enable load_extension */ | 
| -#define SQLITE_EnableTrigger  0x40000000  /* True to enable triggers */ | 
| - | 
| -/* | 
| -** Bits of the sqlite3.flags field that are used by the | 
| -** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface. | 
| -** These must be the low-order bits of the flags field. | 
| -*/ | 
| -#define SQLITE_QueryFlattener 0x01        /* Disable query flattening */ | 
| -#define SQLITE_ColumnCache    0x02        /* Disable the column cache */ | 
| -#define SQLITE_IndexSort      0x04        /* Disable indexes for sorting */ | 
| -#define SQLITE_IndexSearch    0x08        /* Disable indexes for searching */ | 
| -#define SQLITE_IndexCover     0x10        /* Disable index covering table */ | 
| -#define SQLITE_GroupByOrder   0x20        /* Disable GROUPBY cover of ORDERBY */ | 
| -#define SQLITE_FactorOutConst 0x40        /* Disable factoring out constants */ | 
| -#define SQLITE_OptMask        0xff        /* Mask of all disablable opts */ | 
| +#define SQLITE_SqlTrace       0x00000200  /* Debug print SQL as it executes */ | 
| +#define SQLITE_VdbeListing    0x00000400  /* Debug listings of VDBE programs */ | 
| +#define SQLITE_WriteSchema    0x00000800  /* OK to update SQLITE_MASTER */ | 
| +#define SQLITE_VdbeAddopTrace 0x00001000  /* Trace sqlite3VdbeAddOp() calls */ | 
| +#define SQLITE_IgnoreChecks   0x00002000  /* Do not enforce check constraints */ | 
| +#define SQLITE_ReadUncommitted 0x0004000  /* For shared-cache mode */ | 
| +#define SQLITE_LegacyFileFmt  0x00008000  /* Create new databases in format 1 */ | 
| +#define SQLITE_RecoveryMode   0x00010000  /* Ignore schema errors */ | 
| +#define SQLITE_ReverseOrder   0x00020000  /* Reverse unordered SELECTs */ | 
| +#define SQLITE_RecTriggers    0x00040000  /* Enable recursive triggers */ | 
| +#define SQLITE_ForeignKeys    0x00080000  /* Enforce foreign key constraints  */ | 
| +#define SQLITE_AutoIndex      0x00100000  /* Enable automatic indexes */ | 
| +#define SQLITE_PreferBuiltin  0x00200000  /* Preference to built-in funcs */ | 
| +#define SQLITE_LoadExtension  0x00400000  /* Enable load_extension */ | 
| +#define SQLITE_EnableTrigger  0x00800000  /* True to enable triggers */ | 
| +#define SQLITE_DeferFKs       0x01000000  /* Defer all FK constraints */ | 
| +#define SQLITE_QueryOnly      0x02000000  /* Disable database changes */ | 
| +#define SQLITE_VdbeEQP        0x04000000  /* Debug EXPLAIN QUERY PLAN */ | 
| + | 
| + | 
| +/* | 
| +** Bits of the sqlite3.dbOptFlags field that are used by the | 
| +** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to | 
| +** selectively disable various optimizations. | 
| +*/ | 
| +#define SQLITE_QueryFlattener 0x0001   /* Query flattening */ | 
| +#define SQLITE_ColumnCache    0x0002   /* Column cache */ | 
| +#define SQLITE_GroupByOrder   0x0004   /* GROUPBY cover of ORDERBY */ | 
| +#define SQLITE_FactorOutConst 0x0008   /* Constant factoring */ | 
| +/*                not used    0x0010   // Was: SQLITE_IdxRealAsInt */ | 
| +#define SQLITE_DistinctOpt    0x0020   /* DISTINCT using indexes */ | 
| +#define SQLITE_CoverIdxScan   0x0040   /* Covering index scans */ | 
| +#define SQLITE_OrderByIdxJoin 0x0080   /* ORDER BY of joins via index */ | 
| +#define SQLITE_SubqCoroutine  0x0100   /* Evaluate subqueries as coroutines */ | 
| +#define SQLITE_Transitive     0x0200   /* Transitive constraints */ | 
| +#define SQLITE_OmitNoopJoin   0x0400   /* Omit unused tables in joins */ | 
| +#define SQLITE_Stat3          0x0800   /* Use the SQLITE_STAT3 table */ | 
| +#define SQLITE_AllOpts        0xffff   /* All optimizations */ | 
| + | 
| +/* | 
| +** Macros for testing whether or not optimizations are enabled or disabled. | 
| +*/ | 
| +#ifndef SQLITE_OMIT_BUILTIN_TEST | 
| +#define OptimizationDisabled(db, mask)  (((db)->dbOptFlags&(mask))!=0) | 
| +#define OptimizationEnabled(db, mask)   (((db)->dbOptFlags&(mask))==0) | 
| +#else | 
| +#define OptimizationDisabled(db, mask)  0 | 
| +#define OptimizationEnabled(db, mask)   1 | 
| +#endif | 
| + | 
| +/* | 
| +** Return true if it OK to factor constant expressions into the initialization | 
| +** code. The argument is a Parse object for the code generator. | 
| +*/ | 
| +#define ConstFactorOk(P) ((P)->okConstFactor) | 
|  | 
| /* | 
| ** Possible values for the sqlite.magic field. | 
| @@ -965,6 +1244,7 @@ struct sqlite3 { | 
| #define SQLITE_MAGIC_SICK     0x4b771290  /* Error and awaiting close */ | 
| #define SQLITE_MAGIC_BUSY     0xf03b7906  /* Database currently in use */ | 
| #define SQLITE_MAGIC_ERROR    0xb5357930  /* An SQLITE_MISUSE error occurred */ | 
| +#define SQLITE_MAGIC_ZOMBIE   0x64cffc7f  /* Close with last statement close */ | 
|  | 
| /* | 
| ** Each SQL function is defined by an instance of the following | 
| @@ -974,8 +1254,7 @@ struct sqlite3 { | 
| */ | 
| struct FuncDef { | 
| i16 nArg;            /* Number of arguments.  -1 means unlimited */ | 
| -  u8 iPrefEnc;         /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */ | 
| -  u8 flags;            /* Some combination of SQLITE_FUNC_* */ | 
| +  u16 funcFlags;       /* Some combination of SQLITE_FUNC_* */ | 
| void *pUserData;     /* User data parameter */ | 
| FuncDef *pNext;      /* Next function with same name */ | 
| void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */ | 
| @@ -1007,15 +1286,22 @@ struct FuncDestructor { | 
| }; | 
|  | 
| /* | 
| -** Possible values for FuncDef.flags | 
| +** Possible values for FuncDef.flags.  Note that the _LENGTH and _TYPEOF | 
| +** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG.  There | 
| +** are assert() statements in the code to verify this. | 
| */ | 
| -#define SQLITE_FUNC_LIKE     0x01 /* Candidate for the LIKE optimization */ | 
| -#define SQLITE_FUNC_CASE     0x02 /* Case-sensitive LIKE-type function */ | 
| -#define SQLITE_FUNC_EPHEM    0x04 /* Ephemeral.  Delete with VDBE */ | 
| -#define SQLITE_FUNC_NEEDCOLL 0x08 /* sqlite3GetFuncCollSeq() might be called */ | 
| -#define SQLITE_FUNC_PRIVATE  0x10 /* Allowed for internal use only */ | 
| -#define SQLITE_FUNC_COUNT    0x20 /* Built-in count(*) aggregate */ | 
| -#define SQLITE_FUNC_COALESCE 0x40 /* Built-in coalesce() or ifnull() function */ | 
| +#define SQLITE_FUNC_ENCMASK  0x003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */ | 
| +#define SQLITE_FUNC_LIKE     0x004 /* Candidate for the LIKE optimization */ | 
| +#define SQLITE_FUNC_CASE     0x008 /* Case-sensitive LIKE-type function */ | 
| +#define SQLITE_FUNC_EPHEM    0x010 /* Ephemeral.  Delete with VDBE */ | 
| +#define SQLITE_FUNC_NEEDCOLL 0x020 /* sqlite3GetFuncCollSeq() might be called */ | 
| +#define SQLITE_FUNC_LENGTH   0x040 /* Built-in length() function */ | 
| +#define SQLITE_FUNC_TYPEOF   0x080 /* Built-in typeof() function */ | 
| +#define SQLITE_FUNC_COUNT    0x100 /* Built-in count(*) aggregate */ | 
| +#define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */ | 
| +#define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */ | 
| +#define SQLITE_FUNC_CONSTANT 0x800 /* Constant inputs give a constant output */ | 
| +#define SQLITE_FUNC_MINMAX  0x1000 /* True for min() and max() aggregates */ | 
|  | 
| /* | 
| ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are | 
| @@ -1028,6 +1314,9 @@ struct FuncDestructor { | 
| **     as the user-data (sqlite3_user_data()) for the function. If | 
| **     argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set. | 
| ** | 
| +**   VFUNCTION(zName, nArg, iArg, bNC, xFunc) | 
| +**     Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag. | 
| +** | 
| **   AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal) | 
| **     Used to create an aggregate function definition implemented by | 
| **     the C functions xStep and xFinal. The first four parameters | 
| @@ -1043,15 +1332,25 @@ struct FuncDestructor { | 
| **     parameter. | 
| */ | 
| #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \ | 
| -  {nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \ | 
| +  {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ | 
| +   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} | 
| +#define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \ | 
| +  {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ | 
| +   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} | 
| +#define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \ | 
| +  {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\ | 
| SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} | 
| #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \ | 
| -  {nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \ | 
| +  {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ | 
| pArg, 0, xFunc, 0, 0, #zName, 0, 0} | 
| #define LIKEFUNC(zName, nArg, arg, flags) \ | 
| -  {nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0} | 
| +  {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \ | 
| +   (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0} | 
| #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \ | 
| -  {nArg, SQLITE_UTF8, nc*SQLITE_FUNC_NEEDCOLL, \ | 
| +  {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \ | 
| +   SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0} | 
| +#define AGGREGATE2(zName, nArg, arg, nc, xStep, xFinal, extraFlags) \ | 
| +  {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|extraFlags, \ | 
| SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0} | 
|  | 
| /* | 
| @@ -1063,6 +1362,7 @@ struct FuncDestructor { | 
| struct Savepoint { | 
| char *zName;                        /* Savepoint name (nul-terminated) */ | 
| i64 nDeferredCons;                  /* Number of deferred fk violations */ | 
| +  i64 nDeferredImmCons;               /* Number of deferred imm fk. */ | 
| Savepoint *pNext;                   /* Parent savepoint (if any) */ | 
| }; | 
|  | 
| @@ -1097,53 +1397,35 @@ struct Column { | 
| char *zDflt;     /* Original text of the default value */ | 
| char *zType;     /* Data type for this column */ | 
| char *zColl;     /* Collating sequence.  If NULL, use the default */ | 
| -  u8 notNull;      /* True if there is a NOT NULL constraint */ | 
| -  u8 isPrimKey;    /* True if this column is part of the PRIMARY KEY */ | 
| +  u8 notNull;      /* An OE_ code for handling a NOT NULL constraint */ | 
| char affinity;   /* One of the SQLITE_AFF_... values */ | 
| -#ifndef SQLITE_OMIT_VIRTUALTABLE | 
| -  u8 isHidden;     /* True if this column is 'hidden' */ | 
| -#endif | 
| +  u8 szEst;        /* Estimated size of this column.  INT==1 */ | 
| +  u8 colFlags;     /* Boolean properties.  See COLFLAG_ defines below */ | 
| }; | 
|  | 
| +/* Allowed values for Column.colFlags: | 
| +*/ | 
| +#define COLFLAG_PRIMKEY  0x0001    /* Column is part of the primary key */ | 
| +#define COLFLAG_HIDDEN   0x0002    /* A hidden column in a virtual table */ | 
| + | 
| /* | 
| ** A "Collating Sequence" is defined by an instance of the following | 
| ** structure. Conceptually, a collating sequence consists of a name and | 
| ** a comparison routine that defines the order of that sequence. | 
| ** | 
| -** There may two separate implementations of the collation function, one | 
| -** that processes text in UTF-8 encoding (CollSeq.xCmp) and another that | 
| -** processes text encoded in UTF-16 (CollSeq.xCmp16), using the machine | 
| -** native byte order. When a collation sequence is invoked, SQLite selects | 
| -** the version that will require the least expensive encoding | 
| -** translations, if any. | 
| -** | 
| -** The CollSeq.pUser member variable is an extra parameter that passed in | 
| -** as the first argument to the UTF-8 comparison function, xCmp. | 
| -** CollSeq.pUser16 is the equivalent for the UTF-16 comparison function, | 
| -** xCmp16. | 
| -** | 
| -** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the | 
| +** If CollSeq.xCmp is NULL, it means that the | 
| ** collating sequence is undefined.  Indices built on an undefined | 
| ** collating sequence may not be read or written. | 
| */ | 
| struct CollSeq { | 
| char *zName;          /* Name of the collating sequence, UTF-8 encoded */ | 
| u8 enc;               /* Text encoding handled by xCmp() */ | 
| -  u8 type;              /* One of the SQLITE_COLL_... values below */ | 
| void *pUser;          /* First argument to xCmp() */ | 
| int (*xCmp)(void*,int, const void*, int, const void*); | 
| void (*xDel)(void*);  /* Destructor for pUser */ | 
| }; | 
|  | 
| /* | 
| -** Allowed values of CollSeq.type: | 
| -*/ | 
| -#define SQLITE_COLL_BINARY  1  /* The default memcmp() collating sequence */ | 
| -#define SQLITE_COLL_NOCASE  2  /* The built-in NOCASE collating sequence */ | 
| -#define SQLITE_COLL_REVERSE 3  /* The built-in REVERSE collating sequence */ | 
| -#define SQLITE_COLL_USER    0  /* Any other user-defined collating sequence */ | 
| - | 
| -/* | 
| ** A sort order can be either ASC or DESC. | 
| */ | 
| #define SQLITE_SO_ASC       0  /* Sort in ascending order */ | 
| @@ -1156,18 +1438,18 @@ struct CollSeq { | 
| ** 't' for SQLITE_AFF_TEXT.  But we can save a little space and improve | 
| ** the speed a little by numbering the values consecutively. | 
| ** | 
| -** But rather than start with 0 or 1, we begin with 'a'.  That way, | 
| +** But rather than start with 0 or 1, we begin with 'A'.  That way, | 
| ** when multiple affinity types are concatenated into a string and | 
| ** used as the P4 operand, they will be more readable. | 
| ** | 
| ** Note also that the numeric types are grouped together so that testing | 
| -** for a numeric type is a single comparison. | 
| +** for a numeric type is a single comparison.  And the NONE type is first. | 
| */ | 
| -#define SQLITE_AFF_TEXT     'a' | 
| -#define SQLITE_AFF_NONE     'b' | 
| -#define SQLITE_AFF_NUMERIC  'c' | 
| -#define SQLITE_AFF_INTEGER  'd' | 
| -#define SQLITE_AFF_REAL     'e' | 
| +#define SQLITE_AFF_NONE     'A' | 
| +#define SQLITE_AFF_TEXT     'B' | 
| +#define SQLITE_AFF_NUMERIC  'C' | 
| +#define SQLITE_AFF_INTEGER  'D' | 
| +#define SQLITE_AFF_REAL     'E' | 
|  | 
| #define sqlite3IsNumericAffinity(X)  ((X)>=SQLITE_AFF_NUMERIC) | 
|  | 
| @@ -1175,15 +1457,21 @@ struct CollSeq { | 
| ** The SQLITE_AFF_MASK values masks off the significant bits of an | 
| ** affinity value. | 
| */ | 
| -#define SQLITE_AFF_MASK     0x67 | 
| +#define SQLITE_AFF_MASK     0x47 | 
|  | 
| /* | 
| ** Additional bit values that can be ORed with an affinity without | 
| ** changing the affinity. | 
| +** | 
| +** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL. | 
| +** It causes an assert() to fire if either operand to a comparison | 
| +** operator is NULL.  It is added to certain comparison operators to | 
| +** prove that the operands are always NOT NULL. | 
| */ | 
| -#define SQLITE_JUMPIFNULL   0x08  /* jumps if either operand is NULL */ | 
| -#define SQLITE_STOREP2      0x10  /* Store result in reg[P2] rather than jump */ | 
| +#define SQLITE_JUMPIFNULL   0x10  /* jumps if either operand is NULL */ | 
| +#define SQLITE_STOREP2      0x20  /* Store result in reg[P2] rather than jump */ | 
| #define SQLITE_NULLEQ       0x80  /* NULL=NULL */ | 
| +#define SQLITE_NOTNULL      0x90  /* Assert that operands are never NULL */ | 
|  | 
| /* | 
| ** An object of this type is created for each virtual table present in | 
| @@ -1232,6 +1520,8 @@ struct VTable { | 
| Module *pMod;             /* Pointer to module implementation */ | 
| sqlite3_vtab *pVtab;      /* Pointer to vtab instance */ | 
| int nRef;                 /* Number of pointers to this structure */ | 
| +  u8 bConstraint;           /* True if constraints are supported */ | 
| +  int iSavepoint;           /* Depth of the SAVEPOINT stack */ | 
| VTable *pNext;            /* Next in linked list (see above) */ | 
| }; | 
|  | 
| @@ -1267,28 +1557,32 @@ struct VTable { | 
| */ | 
| struct Table { | 
| char *zName;         /* Name of the table or view */ | 
| -  int iPKey;           /* If not negative, use aCol[iPKey] as the primary key */ | 
| -  int nCol;            /* Number of columns in this table */ | 
| Column *aCol;        /* Information about each column */ | 
| Index *pIndex;       /* List of SQL indexes on this table. */ | 
| -  int tnum;            /* Root BTree node for this table (see note above) */ | 
| -  unsigned nRowEst;    /* Estimated rows in table - from sqlite_stat1 table */ | 
| Select *pSelect;     /* NULL for tables.  Points to definition if a view. */ | 
| -  u16 nRef;            /* Number of pointers to this Table */ | 
| -  u8 tabFlags;         /* Mask of TF_* values */ | 
| -  u8 keyConf;          /* What to do in case of uniqueness conflict on iPKey */ | 
| FKey *pFKey;         /* Linked list of all foreign keys in this table */ | 
| char *zColAff;       /* String defining the affinity of each column */ | 
| #ifndef SQLITE_OMIT_CHECK | 
| -  Expr *pCheck;        /* The AND of all CHECK constraints */ | 
| +  ExprList *pCheck;    /* All CHECK constraints */ | 
| #endif | 
| +  LogEst nRowLogEst;   /* Estimated rows in table - from sqlite_stat1 table */ | 
| +  int tnum;            /* Root BTree node for this table (see note above) */ | 
| +  i16 iPKey;           /* If not negative, use aCol[iPKey] as the primary key */ | 
| +  i16 nCol;            /* Number of columns in this table */ | 
| +  u16 nRef;            /* Number of pointers to this Table */ | 
| +  LogEst szTabRow;     /* Estimated size of each table row in bytes */ | 
| +#ifdef SQLITE_ENABLE_COSTMULT | 
| +  LogEst costMult;     /* Cost multiplier for using this table */ | 
| +#endif | 
| +  u8 tabFlags;         /* Mask of TF_* values */ | 
| +  u8 keyConf;          /* What to do in case of uniqueness conflict on iPKey */ | 
| #ifndef SQLITE_OMIT_ALTERTABLE | 
| int addColOffset;    /* Offset in CREATE TABLE stmt to add a new column */ | 
| #endif | 
| #ifndef SQLITE_OMIT_VIRTUALTABLE | 
| -  VTable *pVTable;     /* List of VTable objects. */ | 
| int nModuleArg;      /* Number of arguments to the module */ | 
| char **azModuleArg;  /* Text of all module args. [0] is module name */ | 
| +  VTable *pVTable;     /* List of VTable objects. */ | 
| #endif | 
| Trigger *pTrigger;   /* List of triggers stored in pSchema */ | 
| Schema *pSchema;     /* Schema that contains this table */ | 
| @@ -1296,15 +1590,14 @@ struct Table { | 
| }; | 
|  | 
| /* | 
| -** Allowed values for Tabe.tabFlags. | 
| +** Allowed values for Table.tabFlags. | 
| */ | 
| #define TF_Readonly        0x01    /* Read-only system table */ | 
| #define TF_Ephemeral       0x02    /* An ephemeral table */ | 
| #define TF_HasPrimaryKey   0x04    /* Table has a primary key */ | 
| #define TF_Autoincrement   0x08    /* Integer primary key is autoincrement */ | 
| #define TF_Virtual         0x10    /* Is a virtual table */ | 
| -#define TF_NeedMetadata    0x20    /* aCol[].zType and aCol[].pColl missing */ | 
| - | 
| +#define TF_WithoutRowid    0x20    /* No rowid used. PRIMARY KEY is the key */ | 
|  | 
|  | 
| /* | 
| @@ -1314,12 +1607,15 @@ struct Table { | 
| */ | 
| #ifndef SQLITE_OMIT_VIRTUALTABLE | 
| #  define IsVirtual(X)      (((X)->tabFlags & TF_Virtual)!=0) | 
| -#  define IsHiddenColumn(X) ((X)->isHidden) | 
| +#  define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) | 
| #else | 
| #  define IsVirtual(X)      0 | 
| #  define IsHiddenColumn(X) 0 | 
| #endif | 
|  | 
| +/* Does the table have a rowid */ | 
| +#define HasRowid(X)     (((X)->tabFlags & TF_WithoutRowid)==0) | 
| + | 
| /* | 
| ** Each foreign key constraint is an instance of the following structure. | 
| ** | 
| @@ -1334,26 +1630,35 @@ struct Table { | 
| **     ); | 
| ** | 
| ** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2". | 
| +** Equivalent names: | 
| +** | 
| +**     from-table == child-table | 
| +**       to-table == parent-table | 
| ** | 
| ** Each REFERENCES clause generates an instance of the following structure | 
| ** which is attached to the from-table.  The to-table need not exist when | 
| ** the from-table is created.  The existence of the to-table is not checked. | 
| +** | 
| +** The list of all parents for child Table X is held at X.pFKey. | 
| +** | 
| +** A list of all children for a table named Z (which might not even exist) | 
| +** is held in Schema.fkeyHash with a hash key of Z. | 
| */ | 
| struct FKey { | 
| Table *pFrom;     /* Table containing the REFERENCES clause (aka: Child) */ | 
| -  FKey *pNextFrom;  /* Next foreign key in pFrom */ | 
| +  FKey *pNextFrom;  /* Next FKey with the same in pFrom. Next parent of pFrom */ | 
| char *zTo;        /* Name of table that the key points to (aka: Parent) */ | 
| -  FKey *pNextTo;    /* Next foreign key on table named zTo */ | 
| -  FKey *pPrevTo;    /* Previous foreign key on table named zTo */ | 
| +  FKey *pNextTo;    /* Next with the same zTo. Next child of zTo. */ | 
| +  FKey *pPrevTo;    /* Previous with the same zTo */ | 
| int nCol;         /* Number of columns in this key */ | 
| /* EV: R-30323-21917 */ | 
| -  u8 isDeferred;    /* True if constraint checking is deferred till COMMIT */ | 
| -  u8 aAction[2];          /* ON DELETE and ON UPDATE actions, respectively */ | 
| -  Trigger *apTrigger[2];  /* Triggers for aAction[] actions */ | 
| -  struct sColMap {  /* Mapping of columns in pFrom to columns in zTo */ | 
| -    int iFrom;         /* Index of column in pFrom */ | 
| -    char *zCol;        /* Name of column in zTo.  If 0 use PRIMARY KEY */ | 
| -  } aCol[1];        /* One entry for each of nCol column s */ | 
| +  u8 isDeferred;       /* True if constraint checking is deferred till COMMIT */ | 
| +  u8 aAction[2];        /* ON DELETE and ON UPDATE actions, respectively */ | 
| +  Trigger *apTrigger[2];/* Triggers for aAction[] actions */ | 
| +  struct sColMap {      /* Mapping of columns in pFrom to columns in zTo */ | 
| +    int iFrom;            /* Index of column in pFrom */ | 
| +    char *zCol;           /* Name of column in zTo.  If NULL use PRIMARY KEY */ | 
| +  } aCol[1];            /* One entry for each of nCol columns */ | 
| }; | 
|  | 
| /* | 
| @@ -1393,19 +1698,25 @@ struct FKey { | 
| #define OE_SetDflt  8   /* Set the foreign key value to its default */ | 
| #define OE_Cascade  9   /* Cascade the changes */ | 
|  | 
| -#define OE_Default  99  /* Do whatever the default action is */ | 
| +#define OE_Default  10  /* Do whatever the default action is */ | 
|  | 
|  | 
| /* | 
| ** An instance of the following structure is passed as the first | 
| ** argument to sqlite3VdbeKeyCompare and is used to control the | 
| ** comparison of the two index keys. | 
| +** | 
| +** Note that aSortOrder[] and aColl[] have nField+1 slots.  There | 
| +** are nField slots for the columns of an index then one extra slot | 
| +** for the rowid at the end. | 
| */ | 
| struct KeyInfo { | 
| -  sqlite3 *db;        /* The database connection */ | 
| +  u32 nRef;           /* Number of references to this KeyInfo object */ | 
| u8 enc;             /* Text encoding - one of the SQLITE_UTF* values */ | 
| -  u16 nField;         /* Number of entries in aColl[] */ | 
| -  u8 *aSortOrder;     /* Sort order for each column.  May be NULL */ | 
| +  u16 nField;         /* Number of key columns in the index */ | 
| +  u16 nXField;        /* Number of columns beyond the key columns */ | 
| +  sqlite3 *db;        /* The database connection */ | 
| +  u8 *aSortOrder;     /* Sort order for each column. */ | 
| CollSeq *aColl[1];  /* Collating sequence for each term of the key */ | 
| }; | 
|  | 
| @@ -1422,24 +1733,20 @@ struct KeyInfo { | 
| ** | 
| ** This structure holds a record that has already been disassembled | 
| ** into its constituent fields. | 
| +** | 
| +** The r1 and r2 member variables are only used by the optimized comparison | 
| +** functions vdbeRecordCompareInt() and vdbeRecordCompareString(). | 
| */ | 
| struct UnpackedRecord { | 
| KeyInfo *pKeyInfo;  /* Collation and sort-order information */ | 
| u16 nField;         /* Number of entries in apMem[] */ | 
| -  u16 flags;          /* Boolean settings.  UNPACKED_... below */ | 
| -  i64 rowid;          /* Used by UNPACKED_PREFIX_SEARCH */ | 
| +  i8 default_rc;      /* Comparison result if keys are equal */ | 
| +  u8 errCode;         /* Error detected by xRecordCompare (CORRUPT or NOMEM) */ | 
| Mem *aMem;          /* Values */ | 
| +  int r1;             /* Value to return if (lhs > rhs) */ | 
| +  int r2;             /* Value to return if (rhs < lhs) */ | 
| }; | 
|  | 
| -/* | 
| -** Allowed values of UnpackedRecord.flags | 
| -*/ | 
| -#define UNPACKED_NEED_FREE     0x0001  /* Memory is from sqlite3Malloc() */ | 
| -#define UNPACKED_NEED_DESTROY  0x0002  /* apMem[]s should all be destroyed */ | 
| -#define UNPACKED_IGNORE_ROWID  0x0004  /* Ignore trailing rowid on key1 */ | 
| -#define UNPACKED_INCRKEY       0x0008  /* Make this key an epsilon larger */ | 
| -#define UNPACKED_PREFIX_MATCH  0x0010  /* A prefix match is considered OK */ | 
| -#define UNPACKED_PREFIX_SEARCH 0x0020  /* A prefix match is considered OK */ | 
|  | 
| /* | 
| ** Each SQL index is represented in memory by an | 
| @@ -1468,34 +1775,60 @@ struct UnpackedRecord { | 
| ** element. | 
| */ | 
| struct Index { | 
| -  char *zName;     /* Name of this index */ | 
| -  int nColumn;     /* Number of columns in the table used by this index */ | 
| -  int *aiColumn;   /* Which columns are used by this index.  1st is 0 */ | 
| -  unsigned *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */ | 
| -  Table *pTable;   /* The SQL table being indexed */ | 
| -  int tnum;        /* Page containing root of this index in database file */ | 
| -  u8 onError;      /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ | 
| -  u8 autoIndex;    /* True if is automatically created (ex: by UNIQUE) */ | 
| -  u8 bUnordered;   /* Use this index for == or IN queries only */ | 
| -  char *zColAff;   /* String defining the affinity of each column */ | 
| -  Index *pNext;    /* The next index associated with the same table */ | 
| -  Schema *pSchema; /* Schema containing this index */ | 
| -  u8 *aSortOrder;  /* Array of size Index.nColumn. True==DESC, False==ASC */ | 
| -  char **azColl;   /* Array of collation sequence names for index */ | 
| -  IndexSample *aSample;    /* Array of SQLITE_INDEX_SAMPLES samples */ | 
| +  char *zName;             /* Name of this index */ | 
| +  i16 *aiColumn;           /* Which columns are used by this index.  1st is 0 */ | 
| +  LogEst *aiRowLogEst;     /* From ANALYZE: Est. rows selected by each column */ | 
| +  Table *pTable;           /* The SQL table being indexed */ | 
| +  char *zColAff;           /* String defining the affinity of each column */ | 
| +  Index *pNext;            /* The next index associated with the same table */ | 
| +  Schema *pSchema;         /* Schema containing this index */ | 
| +  u8 *aSortOrder;          /* for each column: True==DESC, False==ASC */ | 
| +  char **azColl;           /* Array of collation sequence names for index */ | 
| +  Expr *pPartIdxWhere;     /* WHERE clause for partial indices */ | 
| +  KeyInfo *pKeyInfo;       /* A KeyInfo object suitable for this index */ | 
| +  int tnum;                /* DB Page containing root of this index */ | 
| +  LogEst szIdxRow;         /* Estimated average row size in bytes */ | 
| +  u16 nKeyCol;             /* Number of columns forming the key */ | 
| +  u16 nColumn;             /* Number of columns stored in the index */ | 
| +  u8 onError;              /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ | 
| +  unsigned idxType:2;      /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */ | 
| +  unsigned bUnordered:1;   /* Use this index for == or IN queries only */ | 
| +  unsigned uniqNotNull:1;  /* True if UNIQUE and NOT NULL for all columns */ | 
| +  unsigned isResized:1;    /* True if resizeIndexObject() has been called */ | 
| +  unsigned isCovering:1;   /* True if this is a covering index */ | 
| +#ifdef SQLITE_ENABLE_STAT3_OR_STAT4 | 
| +  int nSample;             /* Number of elements in aSample[] */ | 
| +  int nSampleCol;          /* Size of IndexSample.anEq[] and so on */ | 
| +  tRowcnt *aAvgEq;         /* Average nEq values for keys not in aSample */ | 
| +  IndexSample *aSample;    /* Samples of the left-most key */ | 
| +  tRowcnt *aiRowEst;       /* Non-logarithmic stat1 data for this table */ | 
| +#endif | 
| }; | 
|  | 
| /* | 
| -** Each sample stored in the sqlite_stat2 table is represented in memory | 
| -** using a structure of this type. | 
| +** Allowed values for Index.idxType | 
| +*/ | 
| +#define SQLITE_IDXTYPE_APPDEF      0   /* Created using CREATE INDEX */ | 
| +#define SQLITE_IDXTYPE_UNIQUE      1   /* Implements a UNIQUE constraint */ | 
| +#define SQLITE_IDXTYPE_PRIMARYKEY  2   /* Is the PRIMARY KEY for the table */ | 
| + | 
| +/* Return true if index X is a PRIMARY KEY index */ | 
| +#define IsPrimaryKeyIndex(X)  ((X)->idxType==SQLITE_IDXTYPE_PRIMARYKEY) | 
| + | 
| +/* Return true if index X is a UNIQUE index */ | 
| +#define IsUniqueIndex(X)      ((X)->onError!=OE_None) | 
| + | 
| +/* | 
| +** Each sample stored in the sqlite_stat3 table is represented in memory | 
| +** using a structure of this type.  See documentation at the top of the | 
| +** analyze.c source file for additional information. | 
| */ | 
| struct IndexSample { | 
| -  union { | 
| -    char *z;        /* Value if eType is SQLITE_TEXT or SQLITE_BLOB */ | 
| -    double r;       /* Value if eType is SQLITE_FLOAT or SQLITE_INTEGER */ | 
| -  } u; | 
| -  u8 eType;         /* SQLITE_NULL, SQLITE_INTEGER ... etc. */ | 
| -  u8 nByte;         /* Size in byte of text or blob. */ | 
| +  void *p;          /* Pointer to sampled record */ | 
| +  int n;            /* Size of record in bytes */ | 
| +  tRowcnt *anEq;    /* Est. number of rows where the key equals this sample */ | 
| +  tRowcnt *anLt;    /* Est. number of rows where key is less than this sample */ | 
| +  tRowcnt *anDLt;   /* Est. number of distinct keys less than this sample */ | 
| }; | 
|  | 
| /* | 
| @@ -1530,8 +1863,10 @@ struct AggInfo { | 
| u8 useSortingIdx;       /* In direct mode, reference the sorting index rather | 
| ** than the source table */ | 
| int sortingIdx;         /* Cursor number of the sorting index */ | 
| -  ExprList *pGroupBy;     /* The group by clause */ | 
| +  int sortingIdxPTab;     /* Cursor number of pseudo-table */ | 
| int nSortingColumn;     /* Number of columns in the sorting index */ | 
| +  int mnReg, mxReg;       /* Range of registers allocated for aCol and aFunc */ | 
| +  ExprList *pGroupBy;     /* The group by clause */ | 
| struct AggInfo_col {    /* For each column used in source tables */ | 
| Table *pTab;             /* Source table */ | 
| int iTable;              /* Cursor number of the source table */ | 
| @@ -1541,7 +1876,6 @@ struct AggInfo { | 
| Expr *pExpr;             /* The original expression */ | 
| } *aCol; | 
| int nColumn;            /* Number of used entries in aCol[] */ | 
| -  int nColumnAlloc;       /* Number of slots allocated for aCol[] */ | 
| int nAccumulator;       /* Number of columns that show through to the output. | 
| ** Additional columns are used only as parameters to | 
| ** aggregate functions */ | 
| @@ -1552,7 +1886,6 @@ struct AggInfo { | 
| int iDistinct;           /* Ephemeral table used to enforce DISTINCT */ | 
| } *aFunc; | 
| int nFunc;              /* Number of entries in aFunc[] */ | 
| -  int nFuncAlloc;         /* Number of slots allocated for aFunc[] */ | 
| }; | 
|  | 
| /* | 
| @@ -1637,7 +1970,7 @@ typedef int ynVar; | 
| struct Expr { | 
| u8 op;                 /* Operation performed by this node */ | 
| char affinity;         /* The affinity of the column or 0 if not a column */ | 
| -  u16 flags;             /* Various flags.  EP_* See below */ | 
| +  u32 flags;             /* Various flags.  EP_* See below */ | 
| union { | 
| char *zToken;          /* Token value. Zero terminated and dequoted */ | 
| int iValue;            /* Non-negative integer value if EP_IntValue */ | 
| @@ -1651,80 +1984,78 @@ struct Expr { | 
| Expr *pLeft;           /* Left subnode */ | 
| Expr *pRight;          /* Right subnode */ | 
| union { | 
| -    ExprList *pList;     /* Function arguments or in "<expr> IN (<expr-list)" */ | 
| -    Select *pSelect;     /* Used for sub-selects and "<expr> IN (<select>)" */ | 
| +    ExprList *pList;     /* op = IN, EXISTS, SELECT, CASE, FUNCTION, BETWEEN */ | 
| +    Select *pSelect;     /* EP_xIsSelect and op = IN, EXISTS, SELECT */ | 
| } x; | 
| -  CollSeq *pColl;        /* The collation type of the column or 0 */ | 
|  | 
| /* If the EP_Reduced flag is set in the Expr.flags mask, then no | 
| ** space is allocated for the fields below this point. An attempt to | 
| ** access them will result in a segfault or malfunction. | 
| *********************************************************************/ | 
|  | 
| +#if SQLITE_MAX_EXPR_DEPTH>0 | 
| +  int nHeight;           /* Height of the tree headed by this node */ | 
| +#endif | 
| int iTable;            /* TK_COLUMN: cursor number of table holding column | 
| ** TK_REGISTER: register number | 
| -                         ** TK_TRIGGER: 1 -> new, 0 -> old */ | 
| +                         ** TK_TRIGGER: 1 -> new, 0 -> old | 
| +                         ** EP_Unlikely:  1000 times likelihood */ | 
| ynVar iColumn;         /* TK_COLUMN: column index.  -1 for rowid. | 
| ** TK_VARIABLE: variable number (always >= 1). */ | 
| i16 iAgg;              /* Which entry in pAggInfo->aCol[] or ->aFunc[] */ | 
| i16 iRightJoinTable;   /* If EP_FromJoin, the right table of the join */ | 
| -  u8 flags2;             /* Second set of flags.  EP2_... */ | 
| -  u8 op2;                /* If a TK_REGISTER, the original value of Expr.op */ | 
| +  u8 op2;                /* TK_REGISTER: original value of Expr.op | 
| +                         ** TK_COLUMN: the value of p5 for OP_Column | 
| +                         ** TK_AGG_FUNCTION: nesting depth */ | 
| AggInfo *pAggInfo;     /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */ | 
| Table *pTab;           /* Table for TK_COLUMN expressions. */ | 
| -#if SQLITE_MAX_EXPR_DEPTH>0 | 
| -  int nHeight;           /* Height of the tree headed by this node */ | 
| -#endif | 
| }; | 
|  | 
| /* | 
| ** The following are the meanings of bits in the Expr.flags field. | 
| */ | 
| -#define EP_FromJoin   0x0001  /* Originated in ON or USING clause of a join */ | 
| -#define EP_Agg        0x0002  /* Contains one or more aggregate functions */ | 
| -#define EP_Resolved   0x0004  /* IDs have been resolved to COLUMNs */ | 
| -#define EP_Error      0x0008  /* Expression contains one or more errors */ | 
| -#define EP_Distinct   0x0010  /* Aggregate function with DISTINCT keyword */ | 
| -#define EP_VarSelect  0x0020  /* pSelect is correlated, not constant */ | 
| -#define EP_DblQuoted  0x0040  /* token.z was originally in "..." */ | 
| -#define EP_InfixFunc  0x0080  /* True for an infix function: LIKE, GLOB, etc */ | 
| -#define EP_ExpCollate 0x0100  /* Collating sequence specified explicitly */ | 
| -#define EP_FixedDest  0x0200  /* Result needed in a specific register */ | 
| -#define EP_IntValue   0x0400  /* Integer value contained in u.iValue */ | 
| -#define EP_xIsSelect  0x0800  /* x.pSelect is valid (otherwise x.pList is) */ | 
| - | 
| -#define EP_Reduced    0x1000  /* Expr struct is EXPR_REDUCEDSIZE bytes only */ | 
| -#define EP_TokenOnly  0x2000  /* Expr struct is EXPR_TOKENONLYSIZE bytes only */ | 
| -#define EP_Static     0x4000  /* Held in memory not obtained from malloc() */ | 
| +#define EP_FromJoin  0x000001 /* Originates in ON/USING clause of outer join */ | 
| +#define EP_Agg       0x000002 /* Contains one or more aggregate functions */ | 
| +#define EP_Resolved  0x000004 /* IDs have been resolved to COLUMNs */ | 
| +#define EP_Error     0x000008 /* Expression contains one or more errors */ | 
| +#define EP_Distinct  0x000010 /* Aggregate function with DISTINCT keyword */ | 
| +#define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */ | 
| +#define EP_DblQuoted 0x000040 /* token.z was originally in "..." */ | 
| +#define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */ | 
| +#define EP_Collate   0x000100 /* Tree contains a TK_COLLATE operator */ | 
| +#define EP_Generic   0x000200 /* Ignore COLLATE or affinity on this tree */ | 
| +#define EP_IntValue  0x000400 /* Integer value contained in u.iValue */ | 
| +#define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */ | 
| +#define EP_Skip      0x001000 /* COLLATE, AS, or UNLIKELY */ | 
| +#define EP_Reduced   0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */ | 
| +#define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */ | 
| +#define EP_Static    0x008000 /* Held in memory not obtained from malloc() */ | 
| +#define EP_MemToken  0x010000 /* Need to sqlite3DbFree() Expr.zToken */ | 
| +#define EP_NoReduce  0x020000 /* Cannot EXPRDUP_REDUCE this Expr */ | 
| +#define EP_Unlikely  0x040000 /* unlikely() or likelihood() function */ | 
| +#define EP_Constant  0x080000 /* Node is a constant */ | 
| +#define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */ | 
|  | 
| /* | 
| -** The following are the meanings of bits in the Expr.flags2 field. | 
| +** These macros can be used to test, set, or clear bits in the | 
| +** Expr.flags field. | 
| */ | 
| -#define EP2_MallocedToken  0x0001  /* Need to sqlite3DbFree() Expr.zToken */ | 
| -#define EP2_Irreducible    0x0002  /* Cannot EXPRDUP_REDUCE this Expr */ | 
| +#define ExprHasProperty(E,P)     (((E)->flags&(P))!=0) | 
| +#define ExprHasAllProperty(E,P)  (((E)->flags&(P))==(P)) | 
| +#define ExprSetProperty(E,P)     (E)->flags|=(P) | 
| +#define ExprClearProperty(E,P)   (E)->flags&=~(P) | 
|  | 
| -/* | 
| -** The pseudo-routine sqlite3ExprSetIrreducible sets the EP2_Irreducible | 
| -** flag on an expression structure.  This flag is used for VV&A only.  The | 
| -** routine is implemented as a macro that only works when in debugging mode, | 
| -** so as not to burden production code. | 
| +/* The ExprSetVVAProperty() macro is used for Verification, Validation, | 
| +** and Accreditation only.  It works like ExprSetProperty() during VVA | 
| +** processes but is a no-op for delivery. | 
| */ | 
| #ifdef SQLITE_DEBUG | 
| -# define ExprSetIrreducible(X)  (X)->flags2 |= EP2_Irreducible | 
| +# define ExprSetVVAProperty(E,P)  (E)->flags|=(P) | 
| #else | 
| -# define ExprSetIrreducible(X) | 
| +# define ExprSetVVAProperty(E,P) | 
| #endif | 
|  | 
| /* | 
| -** These macros can be used to test, set, or clear bits in the | 
| -** Expr.flags field. | 
| -*/ | 
| -#define ExprHasProperty(E,P)     (((E)->flags&(P))==(P)) | 
| -#define ExprHasAnyProperty(E,P)  (((E)->flags&(P))!=0) | 
| -#define ExprSetProperty(E,P)     (E)->flags|=(P) | 
| -#define ExprClearProperty(E,P)   (E)->flags&=~(P) | 
| - | 
| -/* | 
| ** Macros to determine the number of bytes required by a normal Expr | 
| ** struct, an Expr struct with the EP_Reduced flag set in Expr.flags | 
| ** and an Expr struct with the EP_TokenOnly flag set. | 
| @@ -1746,20 +2077,33 @@ struct Expr { | 
| ** list of "ID = expr" items in an UPDATE.  A list of expressions can | 
| ** also be used as the argument to a function, in which case the a.zName | 
| ** field is not used. | 
| +** | 
| +** By default the Expr.zSpan field holds a human-readable description of | 
| +** the expression that is used in the generation of error messages and | 
| +** column labels.  In this case, Expr.zSpan is typically the text of a | 
| +** column expression as it exists in a SELECT statement.  However, if | 
| +** the bSpanIsTab flag is set, then zSpan is overloaded to mean the name | 
| +** of the result column in the form: DATABASE.TABLE.COLUMN.  This later | 
| +** form is used for name resolution with nested FROM clauses. | 
| */ | 
| struct ExprList { | 
| int nExpr;             /* Number of expressions on the list */ | 
| -  int nAlloc;            /* Number of entries allocated below */ | 
| -  int iECursor;          /* VDBE Cursor associated with this ExprList */ | 
| -  struct ExprList_item { | 
| -    Expr *pExpr;           /* The list of expressions */ | 
| -    char *zName;           /* Token associated with this expression */ | 
| -    char *zSpan;           /* Original text of the expression */ | 
| -    u8 sortOrder;          /* 1 for DESC or 0 for ASC */ | 
| -    u8 done;               /* A flag to indicate when processing is finished */ | 
| -    u16 iCol;              /* For ORDER BY, column number in result set */ | 
| -    u16 iAlias;            /* Index into Parse.aAlias[] for zName */ | 
| -  } *a;                  /* One entry for each expression */ | 
| +  struct ExprList_item { /* For each expression in the list */ | 
| +    Expr *pExpr;            /* The list of expressions */ | 
| +    char *zName;            /* Token associated with this expression */ | 
| +    char *zSpan;            /* Original text of the expression */ | 
| +    u8 sortOrder;           /* 1 for DESC or 0 for ASC */ | 
| +    unsigned done :1;       /* A flag to indicate when processing is finished */ | 
| +    unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */ | 
| +    unsigned reusable :1;   /* Constant expression is reusable */ | 
| +    union { | 
| +      struct { | 
| +        u16 iOrderByCol;      /* For ORDER BY, column number in result set */ | 
| +        u16 iAlias;           /* Index into Parse.aAlias[] for zName */ | 
| +      } x; | 
| +      int iConstExprReg;      /* Register in which Expr value is cached */ | 
| +    } u; | 
| +  } *a;                  /* Alloc a power of two greater or equal to nExpr */ | 
| }; | 
|  | 
| /* | 
| @@ -1794,7 +2138,6 @@ struct IdList { | 
| int idx;          /* Index in some Table.aCol[] of a column named zName */ | 
| } *a; | 
| int nId;         /* Number of identifiers on the list */ | 
| -  int nAlloc;      /* Number of entries allocated for a[] below */ | 
| }; | 
|  | 
| /* | 
| @@ -1812,6 +2155,12 @@ typedef u64 Bitmask; | 
| #define BMS  ((int)(sizeof(Bitmask)*8)) | 
|  | 
| /* | 
| +** A bit in a Bitmask | 
| +*/ | 
| +#define MASKBIT(n)   (((Bitmask)1)<<(n)) | 
| +#define MASKBIT32(n) (((unsigned int)1)<<(n)) | 
| + | 
| +/* | 
| ** The following structure describes the FROM clause of a SELECT statement. | 
| ** Each table or subquery in the FROM clause is a separate element of | 
| ** the SrcList.a[] array. | 
| @@ -1831,17 +2180,23 @@ typedef u64 Bitmask; | 
| ** contains more than 63 columns and the 64-th or later column is used. | 
| */ | 
| struct SrcList { | 
| -  i16 nSrc;        /* Number of tables or subqueries in the FROM clause */ | 
| -  i16 nAlloc;      /* Number of entries allocated in a[] below */ | 
| +  int nSrc;        /* Number of tables or subqueries in the FROM clause */ | 
| +  u32 nAlloc;      /* Number of entries allocated in a[] below */ | 
| struct SrcList_item { | 
| +    Schema *pSchema;  /* Schema to which this item is fixed */ | 
| char *zDatabase;  /* Name of database holding this table */ | 
| char *zName;      /* Name of the table */ | 
| char *zAlias;     /* The "B" part of a "A AS B" phrase.  zName is the "A" */ | 
| Table *pTab;      /* An SQL table corresponding to zName */ | 
| Select *pSelect;  /* A SELECT statement used in place of a table name */ | 
| -    u8 isPopulated;   /* Temporary table associated with SELECT is populated */ | 
| +    int addrFillSub;  /* Address of subroutine to manifest a subquery */ | 
| +    int regReturn;    /* Register holding return address of addrFillSub */ | 
| +    int regResult;    /* Registers holding results of a co-routine */ | 
| u8 jointype;      /* Type of join between this able and the previous */ | 
| -    u8 notIndexed;    /* True if there is a NOT INDEXED clause */ | 
| +    unsigned notIndexed :1;    /* True if there is a NOT INDEXED clause */ | 
| +    unsigned isCorrelated :1;  /* True if sub-query is correlated */ | 
| +    unsigned viaCoroutine :1;  /* Implemented as a co-routine */ | 
| +    unsigned isRecursive :1;   /* True for recursive reference in WITH */ | 
| #ifndef SQLITE_OMIT_EXPLAIN | 
| u8 iSelectId;     /* If pSelect!=0, the id of the sub-select in EQP */ | 
| #endif | 
| @@ -1867,75 +2222,6 @@ struct SrcList { | 
|  | 
|  | 
| /* | 
| -** A WherePlan object holds information that describes a lookup | 
| -** strategy. | 
| -** | 
| -** This object is intended to be opaque outside of the where.c module. | 
| -** It is included here only so that that compiler will know how big it | 
| -** is.  None of the fields in this object should be used outside of | 
| -** the where.c module. | 
| -** | 
| -** Within the union, pIdx is only used when wsFlags&WHERE_INDEXED is true. | 
| -** pTerm is only used when wsFlags&WHERE_MULTI_OR is true.  And pVtabIdx | 
| -** is only used when wsFlags&WHERE_VIRTUALTABLE is true.  It is never the | 
| -** case that more than one of these conditions is true. | 
| -*/ | 
| -struct WherePlan { | 
| -  u32 wsFlags;                   /* WHERE_* flags that describe the strategy */ | 
| -  u32 nEq;                       /* Number of == constraints */ | 
| -  double nRow;                   /* Estimated number of rows (for EQP) */ | 
| -  union { | 
| -    Index *pIdx;                   /* Index when WHERE_INDEXED is true */ | 
| -    struct WhereTerm *pTerm;       /* WHERE clause term for OR-search */ | 
| -    sqlite3_index_info *pVtabIdx;  /* Virtual table index to use */ | 
| -  } u; | 
| -}; | 
| - | 
| -/* | 
| -** For each nested loop in a WHERE clause implementation, the WhereInfo | 
| -** structure contains a single instance of this structure.  This structure | 
| -** is intended to be private the the where.c module and should not be | 
| -** access or modified by other modules. | 
| -** | 
| -** The pIdxInfo field is used to help pick the best index on a | 
| -** virtual table.  The pIdxInfo pointer contains indexing | 
| -** information for the i-th table in the FROM clause before reordering. | 
| -** All the pIdxInfo pointers are freed by whereInfoFree() in where.c. | 
| -** All other information in the i-th WhereLevel object for the i-th table | 
| -** after FROM clause ordering. | 
| -*/ | 
| -struct WhereLevel { | 
| -  WherePlan plan;       /* query plan for this element of the FROM clause */ | 
| -  int iLeftJoin;        /* Memory cell used to implement LEFT OUTER JOIN */ | 
| -  int iTabCur;          /* The VDBE cursor used to access the table */ | 
| -  int iIdxCur;          /* The VDBE cursor used to access pIdx */ | 
| -  int addrBrk;          /* Jump here to break out of the loop */ | 
| -  int addrNxt;          /* Jump here to start the next IN combination */ | 
| -  int addrCont;         /* Jump here to continue with the next loop cycle */ | 
| -  int addrFirst;        /* First instruction of interior of the loop */ | 
| -  u8 iFrom;             /* Which entry in the FROM clause */ | 
| -  u8 op, p5;            /* Opcode and P5 of the opcode that ends the loop */ | 
| -  int p1, p2;           /* Operands of the opcode used to ends the loop */ | 
| -  union {               /* Information that depends on plan.wsFlags */ | 
| -    struct { | 
| -      int nIn;              /* Number of entries in aInLoop[] */ | 
| -      struct InLoop { | 
| -        int iCur;              /* The VDBE cursor used by this IN operator */ | 
| -        int addrInTop;         /* Top of the IN loop */ | 
| -      } *aInLoop;           /* Information about each nested IN operator */ | 
| -    } in;                 /* Used when plan.wsFlags&WHERE_IN_ABLE */ | 
| -  } u; | 
| - | 
| -  /* The following field is really not part of the current level.  But | 
| -  ** we need a place to cache virtual table index information for each | 
| -  ** virtual table in the FROM clause and the WhereLevel structure is | 
| -  ** a convenient place since there is one WhereLevel for each FROM clause | 
| -  ** element. | 
| -  */ | 
| -  sqlite3_index_info *pIdxInfo;  /* Index info for n-th source table */ | 
| -}; | 
| - | 
| -/* | 
| ** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin() | 
| ** and the WhereInfo.wctrlFlags member. | 
| */ | 
| @@ -1944,33 +2230,22 @@ struct WhereLevel { | 
| #define WHERE_ORDERBY_MAX      0x0002 /* ORDER BY processing for max() func */ | 
| #define WHERE_ONEPASS_DESIRED  0x0004 /* Want to do one-pass UPDATE/DELETE */ | 
| #define WHERE_DUPLICATES_OK    0x0008 /* Ok to return a row more than once */ | 
| -#define WHERE_OMIT_OPEN        0x0010 /* Table cursors are already open */ | 
| -#define WHERE_OMIT_CLOSE       0x0020 /* Omit close of table & index cursors */ | 
| -#define WHERE_FORCE_TABLE      0x0040 /* Do not use an index-only search */ | 
| -#define WHERE_ONETABLE_ONLY    0x0080 /* Only code the 1st table in pTabList */ | 
| - | 
| -/* | 
| -** The WHERE clause processing routine has two halves.  The | 
| -** first part does the start of the WHERE loop and the second | 
| -** half does the tail of the WHERE loop.  An instance of | 
| -** this structure is returned by the first half and passed | 
| -** into the second half to give some continuity. | 
| -*/ | 
| -struct WhereInfo { | 
| -  Parse *pParse;       /* Parsing and code generating context */ | 
| -  u16 wctrlFlags;      /* Flags originally passed to sqlite3WhereBegin() */ | 
| -  u8 okOnePass;        /* Ok to use one-pass algorithm for UPDATE or DELETE */ | 
| -  u8 untestedTerms;    /* Not all WHERE terms resolved by outer loop */ | 
| -  SrcList *pTabList;             /* List of tables in the join */ | 
| -  int iTop;                      /* The very beginning of the WHERE loop */ | 
| -  int iContinue;                 /* Jump here to continue with next record */ | 
| -  int iBreak;                    /* Jump here to break out of the loop */ | 
| -  int nLevel;                    /* Number of nested loop */ | 
| -  struct WhereClause *pWC;       /* Decomposition of the WHERE clause */ | 
| -  double savedNQueryLoop;        /* pParse->nQueryLoop outside the WHERE loop */ | 
| -  double nRowOut;                /* Estimated number of output rows */ | 
| -  WhereLevel a[1];               /* Information about each nest loop in WHERE */ | 
| -}; | 
| +#define WHERE_OMIT_OPEN_CLOSE  0x0010 /* Table cursors are already open */ | 
| +#define WHERE_FORCE_TABLE      0x0020 /* Do not use an index-only search */ | 
| +#define WHERE_ONETABLE_ONLY    0x0040 /* Only code the 1st table in pTabList */ | 
| +                          /*   0x0080 // not currently used */ | 
| +#define WHERE_GROUPBY          0x0100 /* pOrderBy is really a GROUP BY */ | 
| +#define WHERE_DISTINCTBY       0x0200 /* pOrderby is really a DISTINCT clause */ | 
| +#define WHERE_WANT_DISTINCT    0x0400 /* All output needs to be distinct */ | 
| +#define WHERE_SORTBYGROUP      0x0800 /* Support sqlite3WhereIsSorted() */ | 
| +#define WHERE_REOPEN_IDX       0x1000 /* Try to use OP_ReopenIdx */ | 
| + | 
| +/* Allowed return values from sqlite3WhereIsDistinct() | 
| +*/ | 
| +#define WHERE_DISTINCT_NOOP      0  /* DISTINCT keyword not used */ | 
| +#define WHERE_DISTINCT_UNIQUE    1  /* No duplicates */ | 
| +#define WHERE_DISTINCT_ORDERED   2  /* All duplicates are adjacent */ | 
| +#define WHERE_DISTINCT_UNORDERED 3  /* Duplicates are scattered */ | 
|  | 
| /* | 
| ** A NameContext defines a context in which to resolve table and column | 
| @@ -1996,18 +2271,29 @@ struct WhereInfo { | 
| struct NameContext { | 
| Parse *pParse;       /* The parser */ | 
| SrcList *pSrcList;   /* One or more tables used to resolve names */ | 
| -  ExprList *pEList;    /* Optional list of named expressions */ | 
| -  int nRef;            /* Number of names resolved by this context */ | 
| -  int nErr;            /* Number of errors encountered while resolving names */ | 
| -  u8 allowAgg;         /* Aggregate functions allowed here */ | 
| -  u8 hasAgg;           /* True if aggregates are seen */ | 
| -  u8 isCheck;          /* True if resolving names in a CHECK constraint */ | 
| -  int nDepth;          /* Depth of subquery recursion. 1 for no recursion */ | 
| +  ExprList *pEList;    /* Optional list of result-set columns */ | 
| AggInfo *pAggInfo;   /* Information about aggregates at this level */ | 
| NameContext *pNext;  /* Next outer name context.  NULL for outermost */ | 
| +  int nRef;            /* Number of names resolved by this context */ | 
| +  int nErr;            /* Number of errors encountered while resolving names */ | 
| +  u16 ncFlags;         /* Zero or more NC_* flags defined below */ | 
| }; | 
|  | 
| /* | 
| +** Allowed values for the NameContext, ncFlags field. | 
| +** | 
| +** Note:  NC_MinMaxAgg must have the same value as SF_MinMaxAgg and | 
| +** SQLITE_FUNC_MINMAX. | 
| +** | 
| +*/ | 
| +#define NC_AllowAgg  0x0001  /* Aggregate functions are allowed here */ | 
| +#define NC_HasAgg    0x0002  /* One or more aggregate functions seen */ | 
| +#define NC_IsCheck   0x0004  /* True if resolving names in a CHECK constraint */ | 
| +#define NC_InAggFunc 0x0008  /* True if analyzing arguments to an agg func */ | 
| +#define NC_PartIdx   0x0010  /* True if resolving a partial index WHERE */ | 
| +#define NC_MinMaxAgg 0x1000  /* min/max aggregates seen.  See note above */ | 
| + | 
| +/* | 
| ** An instance of the following structure contains all information | 
| ** needed to generate code for a single SELECT statement. | 
| ** | 
| @@ -2024,14 +2310,19 @@ struct NameContext { | 
| ** as the OP_OpenEphm instruction is coded because not | 
| ** enough information about the compound query is known at that point. | 
| ** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences | 
| -** for the result set.  The KeyInfo for addrOpenTran[2] contains collating | 
| +** for the result set.  The KeyInfo for addrOpenEphm[2] contains collating | 
| ** sequences for the ORDER BY clause. | 
| */ | 
| struct Select { | 
| ExprList *pEList;      /* The fields of the result */ | 
| u8 op;                 /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */ | 
| -  char affinity;         /* MakeRecord with this affinity for SRT_Set */ | 
| u16 selFlags;          /* Various SF_* values */ | 
| +  int iLimit, iOffset;   /* Memory registers holding LIMIT & OFFSET counters */ | 
| +#if SELECTTRACE_ENABLED | 
| +  char zSelName[12];     /* Symbolic name of this SELECT use for debugging */ | 
| +#endif | 
| +  int addrOpenEphm[2];   /* OP_OpenEphem opcodes related to this select */ | 
| +  u64 nSelectRow;        /* Estimated number of result rows */ | 
| SrcList *pSrc;         /* The FROM clause */ | 
| Expr *pWhere;          /* The WHERE clause */ | 
| ExprList *pGroupBy;    /* The GROUP BY clause */ | 
| @@ -2039,12 +2330,9 @@ struct Select { | 
| ExprList *pOrderBy;    /* The ORDER BY clause */ | 
| Select *pPrior;        /* Prior select in a compound select statement */ | 
| Select *pNext;         /* Next select to the left in a compound */ | 
| -  Select *pRightmost;    /* Right-most select in a compound select statement */ | 
| Expr *pLimit;          /* LIMIT expression. NULL means not used. */ | 
| Expr *pOffset;         /* OFFSET expression. NULL means not used. */ | 
| -  int iLimit, iOffset;   /* Memory registers holding LIMIT & OFFSET counters */ | 
| -  int addrOpenEphm[3];   /* OP_OpenEphem opcodes related to this select */ | 
| -  double nSelectRow;     /* Estimated number of result rows */ | 
| +  With *pWith;           /* WITH clause attached to this select. Or NULL. */ | 
| }; | 
|  | 
| /* | 
| @@ -2057,38 +2345,109 @@ struct Select { | 
| #define SF_UsesEphemeral   0x0008  /* Uses the OpenEphemeral opcode */ | 
| #define SF_Expanded        0x0010  /* sqlite3SelectExpand() called on this */ | 
| #define SF_HasTypeInfo     0x0020  /* FROM subqueries have Table metadata */ | 
| +#define SF_Compound        0x0040  /* Part of a compound query */ | 
| +#define SF_Values          0x0080  /* Synthesized from VALUES clause */ | 
| +                    /*     0x0100  NOT USED */ | 
| +#define SF_NestedFrom      0x0200  /* Part of a parenthesized FROM clause */ | 
| +#define SF_MaybeConvert    0x0400  /* Need convertCompoundSelectToSubquery() */ | 
| +#define SF_Recursive       0x0800  /* The recursive part of a recursive CTE */ | 
| +#define SF_MinMaxAgg       0x1000  /* Aggregate containing min() or max() */ | 
|  | 
|  | 
| /* | 
| -** The results of a select can be distributed in several ways.  The | 
| -** "SRT" prefix means "SELECT Result Type". | 
| +** The results of a SELECT can be distributed in several ways, as defined | 
| +** by one of the following macros.  The "SRT" prefix means "SELECT Result | 
| +** Type". | 
| +** | 
| +**     SRT_Union       Store results as a key in a temporary index | 
| +**                     identified by pDest->iSDParm. | 
| +** | 
| +**     SRT_Except      Remove results from the temporary index pDest->iSDParm. | 
| +** | 
| +**     SRT_Exists      Store a 1 in memory cell pDest->iSDParm if the result | 
| +**                     set is not empty. | 
| +** | 
| +**     SRT_Discard     Throw the results away.  This is used by SELECT | 
| +**                     statements within triggers whose only purpose is | 
| +**                     the side-effects of functions. | 
| +** | 
| +** All of the above are free to ignore their ORDER BY clause. Those that | 
| +** follow must honor the ORDER BY clause. | 
| +** | 
| +**     SRT_Output      Generate a row of output (using the OP_ResultRow | 
| +**                     opcode) for each row in the result set. | 
| +** | 
| +**     SRT_Mem         Only valid if the result is a single column. | 
| +**                     Store the first column of the first result row | 
| +**                     in register pDest->iSDParm then abandon the rest | 
| +**                     of the query.  This destination implies "LIMIT 1". | 
| +** | 
| +**     SRT_Set         The result must be a single column.  Store each | 
| +**                     row of result as the key in table pDest->iSDParm. | 
| +**                     Apply the affinity pDest->affSdst before storing | 
| +**                     results.  Used to implement "IN (SELECT ...)". | 
| +** | 
| +**     SRT_EphemTab    Create an temporary table pDest->iSDParm and store | 
| +**                     the result there. The cursor is left open after | 
| +**                     returning.  This is like SRT_Table except that | 
| +**                     this destination uses OP_OpenEphemeral to create | 
| +**                     the table first. | 
| +** | 
| +**     SRT_Coroutine   Generate a co-routine that returns a new row of | 
| +**                     results each time it is invoked.  The entry point | 
| +**                     of the co-routine is stored in register pDest->iSDParm | 
| +**                     and the result row is stored in pDest->nDest registers | 
| +**                     starting with pDest->iSdst. | 
| +** | 
| +**     SRT_Table       Store results in temporary table pDest->iSDParm. | 
| +**     SRT_Fifo        This is like SRT_EphemTab except that the table | 
| +**                     is assumed to already be open.  SRT_Fifo has | 
| +**                     the additional property of being able to ignore | 
| +**                     the ORDER BY clause. | 
| +** | 
| +**     SRT_DistFifo    Store results in a temporary table pDest->iSDParm. | 
| +**                     But also use temporary table pDest->iSDParm+1 as | 
| +**                     a record of all prior results and ignore any duplicate | 
| +**                     rows.  Name means:  "Distinct Fifo". | 
| +** | 
| +**     SRT_Queue       Store results in priority queue pDest->iSDParm (really | 
| +**                     an index).  Append a sequence number so that all entries | 
| +**                     are distinct. | 
| +** | 
| +**     SRT_DistQueue   Store results in priority queue pDest->iSDParm only if | 
| +**                     the same record has never been stored before.  The | 
| +**                     index at pDest->iSDParm+1 hold all prior stores. | 
| */ | 
| #define SRT_Union        1  /* Store result as keys in an index */ | 
| #define SRT_Except       2  /* Remove result from a UNION index */ | 
| #define SRT_Exists       3  /* Store 1 if the result is not empty */ | 
| #define SRT_Discard      4  /* Do not save the results anywhere */ | 
| +#define SRT_Fifo         5  /* Store result as data with an automatic rowid */ | 
| +#define SRT_DistFifo     6  /* Like SRT_Fifo, but unique results only */ | 
| +#define SRT_Queue        7  /* Store result in an queue */ | 
| +#define SRT_DistQueue    8  /* Like SRT_Queue, but unique results only */ | 
|  | 
| /* The ORDER BY clause is ignored for all of the above */ | 
| -#define IgnorableOrderby(X) ((X->eDest)<=SRT_Discard) | 
| +#define IgnorableOrderby(X) ((X->eDest)<=SRT_DistQueue) | 
|  | 
| -#define SRT_Output       5  /* Output each row of result */ | 
| -#define SRT_Mem          6  /* Store result in a memory cell */ | 
| -#define SRT_Set          7  /* Store results as keys in an index */ | 
| -#define SRT_Table        8  /* Store result as data with an automatic rowid */ | 
| -#define SRT_EphemTab     9  /* Create transient tab and store like SRT_Table */ | 
| -#define SRT_Coroutine   10  /* Generate a single row of result */ | 
| +#define SRT_Output       9  /* Output each row of result */ | 
| +#define SRT_Mem         10  /* Store result in a memory cell */ | 
| +#define SRT_Set         11  /* Store results as keys in an index */ | 
| +#define SRT_EphemTab    12  /* Create transient tab and store like SRT_Table */ | 
| +#define SRT_Coroutine   13  /* Generate a single row of result */ | 
| +#define SRT_Table       14  /* Store result as data with an automatic rowid */ | 
|  | 
| /* | 
| -** A structure used to customize the behavior of sqlite3Select(). See | 
| -** comments above sqlite3Select() for details. | 
| +** An instance of this object describes where to put of the results of | 
| +** a SELECT statement. | 
| */ | 
| -typedef struct SelectDest SelectDest; | 
| struct SelectDest { | 
| -  u8 eDest;         /* How to dispose of the results */ | 
| -  u8 affinity;      /* Affinity used when eDest==SRT_Set */ | 
| -  int iParm;        /* A parameter used by the eDest disposal method */ | 
| -  int iMem;         /* Base register where results are written */ | 
| -  int nMem;         /* Number of registers allocated */ | 
| +  u8 eDest;            /* How to dispose of the results.  On of SRT_* above. */ | 
| +  char affSdst;        /* Affinity used when eDest==SRT_Set */ | 
| +  int iSDParm;         /* A parameter used by the eDest disposal method */ | 
| +  int iSdst;           /* Base register where results are written */ | 
| +  int nSdst;           /* Number of registers allocated */ | 
| +  ExprList *pOrderBy;  /* Key columns for SRT_Queue and SRT_DistQueue */ | 
| }; | 
|  | 
| /* | 
| @@ -2134,19 +2493,29 @@ struct AutoincInfo { | 
| */ | 
| struct TriggerPrg { | 
| Trigger *pTrigger;      /* Trigger this program was coded from */ | 
| -  int orconf;             /* Default ON CONFLICT policy */ | 
| +  TriggerPrg *pNext;      /* Next entry in Parse.pTriggerPrg list */ | 
| SubProgram *pProgram;   /* Program implementing pTrigger/orconf */ | 
| +  int orconf;             /* Default ON CONFLICT policy */ | 
| u32 aColmask[2];        /* Masks of old.*, new.* columns accessed */ | 
| -  TriggerPrg *pNext;      /* Next entry in Parse.pTriggerPrg list */ | 
| }; | 
|  | 
| /* | 
| ** The yDbMask datatype for the bitmask of all attached databases. | 
| */ | 
| #if SQLITE_MAX_ATTACHED>30 | 
| -  typedef sqlite3_uint64 yDbMask; | 
| +  typedef unsigned char yDbMask[(SQLITE_MAX_ATTACHED+9)/8]; | 
| +# define DbMaskTest(M,I)    (((M)[(I)/8]&(1<<((I)&7)))!=0) | 
| +# define DbMaskZero(M)      memset((M),0,sizeof(M)) | 
| +# define DbMaskSet(M,I)     (M)[(I)/8]|=(1<<((I)&7)) | 
| +# define DbMaskAllZero(M)   sqlite3DbMaskAllZero(M) | 
| +# define DbMaskNonZero(M)   (sqlite3DbMaskAllZero(M)==0) | 
| #else | 
| typedef unsigned int yDbMask; | 
| +# define DbMaskTest(M,I)    (((M)&(((yDbMask)1)<<(I)))!=0) | 
| +# define DbMaskZero(M)      (M)=0 | 
| +# define DbMaskSet(M,I)     (M)|=(((yDbMask)1)<<(I)) | 
| +# define DbMaskAllZero(M)   (M)==0 | 
| +# define DbMaskNonZero(M)   (M)!=0 | 
| #endif | 
|  | 
| /* | 
| @@ -2167,16 +2536,17 @@ struct TriggerPrg { | 
| */ | 
| struct Parse { | 
| sqlite3 *db;         /* The main database structure */ | 
| -  int rc;              /* Return code from execution */ | 
| char *zErrMsg;       /* An error message */ | 
| Vdbe *pVdbe;         /* An engine for executing database bytecode */ | 
| +  int rc;              /* Return code from execution */ | 
| u8 colNamesSet;      /* TRUE after OP_ColumnName has been issued to pVdbe */ | 
| -  u8 nameClash;        /* A permanent table name clashes with temp table name */ | 
| u8 checkSchema;      /* Causes schema cookie check after an error */ | 
| u8 nested;           /* Number of nested calls to the parser/code generator */ | 
| -  u8 parseError;       /* True after a parsing error.  Ticket #1794 */ | 
| u8 nTempReg;         /* Number of temporary registers in aTempReg[] */ | 
| -  u8 nTempInUse;       /* Number of aTempReg[] currently checked out */ | 
| +  u8 isMultiWrite;     /* True if statement may modify/insert multiple rows */ | 
| +  u8 mayAbort;         /* True if statement may throw an ABORT exception */ | 
| +  u8 hasCompound;      /* Need to invoke convertCompoundSelectToSubquery() */ | 
| +  u8 okConstFactor;    /* OK to factor out constants */ | 
| int aTempReg[8];     /* Holding area for temporary registers */ | 
| int nRangeReg;       /* Size of the temporary register block */ | 
| int iRangeReg;       /* First register in temporary register block */ | 
| @@ -2184,78 +2554,95 @@ struct Parse { | 
| int nTab;            /* Number of previously allocated VDBE cursors */ | 
| int nMem;            /* Number of memory cells used so far */ | 
| int nSet;            /* Number of sets used so far */ | 
| +  int nOnce;           /* Number of OP_Once instructions so far */ | 
| +  int nOpAlloc;        /* Number of slots allocated for Vdbe.aOp[] */ | 
| +  int iFixedOp;        /* Never back out opcodes iFixedOp-1 or earlier */ | 
| int ckBase;          /* Base register of data during check constraints */ | 
| +  int iPartIdxTab;     /* Table corresponding to a partial index */ | 
| int iCacheLevel;     /* ColCache valid when aColCache[].iLevel<=iCacheLevel */ | 
| int iCacheCnt;       /* Counter used to generate aColCache[].lru values */ | 
| -  u8 nColCache;        /* Number of entries in the column cache */ | 
| -  u8 iColCache;        /* Next entry of the cache to replace */ | 
| +  int nLabel;          /* Number of labels used */ | 
| +  int *aLabel;         /* Space to hold the labels */ | 
| struct yColCache { | 
| int iTable;           /* Table cursor number */ | 
| -    int iColumn;          /* Table column number */ | 
| +    i16 iColumn;          /* Table column number */ | 
| u8 tempReg;           /* iReg is a temp register that needs to be freed */ | 
| int iLevel;           /* Nesting level */ | 
| int iReg;             /* Reg with value of this column. 0 means none. */ | 
| int lru;              /* Least recently used entry has the smallest value */ | 
| } aColCache[SQLITE_N_COLCACHE];  /* One for each column cache entry */ | 
| +  ExprList *pConstExpr;/* Constant expressions */ | 
| +  Token constraintName;/* Name of the constraint currently being parsed */ | 
| yDbMask writeMask;   /* Start a write transaction on these databases */ | 
| yDbMask cookieMask;  /* Bitmask of schema verified databases */ | 
| -  u8 isMultiWrite;     /* True if statement may affect/insert multiple rows */ | 
| -  u8 mayAbort;         /* True if statement may throw an ABORT exception */ | 
| -  int cookieGoto;      /* Address of OP_Goto to cookie verifier subroutine */ | 
| int cookieValue[SQLITE_MAX_ATTACHED+2];  /* Values of cookies to verify */ | 
| +  int regRowid;        /* Register holding rowid of CREATE TABLE entry */ | 
| +  int regRoot;         /* Register holding root page number for new objects */ | 
| +  int nMaxArg;         /* Max args passed to user function by sub-program */ | 
| +#if SELECTTRACE_ENABLED | 
| +  int nSelect;         /* Number of SELECT statements seen */ | 
| +  int nSelectIndent;   /* How far to indent SELECTTRACE() output */ | 
| +#endif | 
| #ifndef SQLITE_OMIT_SHARED_CACHE | 
| int nTableLock;        /* Number of locks in aTableLock */ | 
| TableLock *aTableLock; /* Required table locks for shared-cache mode */ | 
| #endif | 
| -  int regRowid;        /* Register holding rowid of CREATE TABLE entry */ | 
| -  int regRoot;         /* Register holding root page number for new objects */ | 
| AutoincInfo *pAinc;  /* Information about AUTOINCREMENT counters */ | 
| -  int nMaxArg;         /* Max args passed to user function by sub-program */ | 
|  | 
| /* Information used while coding trigger programs. */ | 
| Parse *pToplevel;    /* Parse structure for main program (or NULL) */ | 
| Table *pTriggerTab;  /* Table triggers are being coded for */ | 
| +  int addrCrTab;       /* Address of OP_CreateTable opcode on CREATE TABLE */ | 
| +  int addrSkipPK;      /* Address of instruction to skip PRIMARY KEY index */ | 
| +  u32 nQueryLoop;      /* Est number of iterations of a query (10*log2(N)) */ | 
| u32 oldmask;         /* Mask of old.* columns referenced */ | 
| u32 newmask;         /* Mask of new.* columns referenced */ | 
| u8 eTriggerOp;       /* TK_UPDATE, TK_INSERT or TK_DELETE */ | 
| u8 eOrconf;          /* Default ON CONFLICT policy for trigger steps */ | 
| u8 disableTriggers;  /* True to disable triggers */ | 
| -  double nQueryLoop;   /* Estimated number of iterations of a query */ | 
| - | 
| -  /* Above is constant between recursions.  Below is reset before and after | 
| -  ** each recursion */ | 
| - | 
| -  int nVar;            /* Number of '?' variables seen in the SQL so far */ | 
| -  int nVarExpr;        /* Number of used slots in apVarExpr[] */ | 
| -  int nVarExprAlloc;   /* Number of allocated slots in apVarExpr[] */ | 
| -  Expr **apVarExpr;    /* Pointers to :aaa and $aaaa wildcard expressions */ | 
| -  Vdbe *pReprepare;    /* VM being reprepared (sqlite3Reprepare()) */ | 
| -  int nAlias;          /* Number of aliased result set columns */ | 
| -  int nAliasAlloc;     /* Number of allocated slots for aAlias[] */ | 
| -  int *aAlias;         /* Register used to hold aliased result */ | 
| -  u8 explain;          /* True if the EXPLAIN flag is found on the query */ | 
| -  Token sNameToken;    /* Token with unqualified schema object name */ | 
| -  Token sLastToken;    /* The last token parsed */ | 
| -  const char *zTail;   /* All SQL text past the last semicolon parsed */ | 
| -  Table *pNewTable;    /* A table being constructed by CREATE TABLE */ | 
| -  Trigger *pNewTrigger;     /* Trigger under construct by a CREATE TRIGGER */ | 
| -  const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */ | 
| + | 
| +  /************************************************************************ | 
| +  ** Above is constant between recursions.  Below is reset before and after | 
| +  ** each recursion.  The boundary between these two regions is determined | 
| +  ** using offsetof(Parse,nVar) so the nVar field must be the first field | 
| +  ** in the recursive region. | 
| +  ************************************************************************/ | 
| + | 
| +  int nVar;                 /* Number of '?' variables seen in the SQL so far */ | 
| +  int nzVar;                /* Number of available slots in azVar[] */ | 
| +  u8 iPkSortOrder;          /* ASC or DESC for INTEGER PRIMARY KEY */ | 
| +  u8 bFreeWith;             /* True if pWith should be freed with parser */ | 
| +  u8 explain;               /* True if the EXPLAIN flag is found on the query */ | 
| #ifndef SQLITE_OMIT_VIRTUALTABLE | 
| -  Token sArg;                /* Complete text of a module argument */ | 
| -  u8 declareVtab;            /* True if inside sqlite3_declare_vtab() */ | 
| -  int nVtabLock;             /* Number of virtual tables to lock */ | 
| -  Table **apVtabLock;        /* Pointer to virtual tables needing locking */ | 
| +  u8 declareVtab;           /* True if inside sqlite3_declare_vtab() */ | 
| +  int nVtabLock;            /* Number of virtual tables to lock */ | 
| #endif | 
| -  int nHeight;            /* Expression tree height of current sub-select */ | 
| -  Table *pZombieTab;      /* List of Table objects to delete after code gen */ | 
| -  TriggerPrg *pTriggerPrg;    /* Linked list of coded triggers */ | 
| - | 
| +  int nAlias;               /* Number of aliased result set columns */ | 
| +  int nHeight;              /* Expression tree height of current sub-select */ | 
| #ifndef SQLITE_OMIT_EXPLAIN | 
| -  int iSelectId; | 
| -  int iNextSelectId; | 
| +  int iSelectId;            /* ID of current select for EXPLAIN output */ | 
| +  int iNextSelectId;        /* Next available select ID for EXPLAIN output */ | 
| #endif | 
| +  char **azVar;             /* Pointers to names of parameters */ | 
| +  Vdbe *pReprepare;         /* VM being reprepared (sqlite3Reprepare()) */ | 
| +  const char *zTail;        /* All SQL text past the last semicolon parsed */ | 
| +  Table *pNewTable;         /* A table being constructed by CREATE TABLE */ | 
| +  Trigger *pNewTrigger;     /* Trigger under construct by a CREATE TRIGGER */ | 
| +  const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */ | 
| +  Token sNameToken;         /* Token with unqualified schema object name */ | 
| +  Token sLastToken;         /* The last token parsed */ | 
| +#ifndef SQLITE_OMIT_VIRTUALTABLE | 
| +  Token sArg;               /* Complete text of a module argument */ | 
| +  Table **apVtabLock;       /* Pointer to virtual tables needing locking */ | 
| +#endif | 
| +  Table *pZombieTab;        /* List of Table objects to delete after code gen */ | 
| +  TriggerPrg *pTriggerPrg;  /* Linked list of coded triggers */ | 
| +  With *pWith;              /* Current WITH clause, or NULL */ | 
| }; | 
|  | 
| +/* | 
| +** Return true if currently inside an sqlite3_declare_vtab() call. | 
| +*/ | 
| #ifdef SQLITE_OMIT_VIRTUALTABLE | 
| #define IN_DECLARE_VTAB 0 | 
| #else | 
| @@ -2272,14 +2659,19 @@ struct AuthContext { | 
| }; | 
|  | 
| /* | 
| -** Bitfield flags for P5 value in OP_Insert and OP_Delete | 
| +** Bitfield flags for P5 value in various opcodes. | 
| */ | 
| #define OPFLAG_NCHANGE       0x01    /* Set to update db->nChange */ | 
| +#define OPFLAG_EPHEM         0x01    /* OP_Column: Ephemeral output is ok */ | 
| #define OPFLAG_LASTROWID     0x02    /* Set to update db->lastRowid */ | 
| #define OPFLAG_ISUPDATE      0x04    /* This OP_Insert is an sql UPDATE */ | 
| #define OPFLAG_APPEND        0x08    /* This is likely to be an append */ | 
| #define OPFLAG_USESEEKRESULT 0x10    /* Try to avoid a seek in BtreeInsert() */ | 
| -#define OPFLAG_CLEARCACHE    0x20    /* Clear pseudo-table cache in OP_Column */ | 
| +#define OPFLAG_LENGTHARG     0x40    /* OP_Column only used for length() */ | 
| +#define OPFLAG_TYPEOFARG     0x80    /* OP_Column only used for typeof() */ | 
| +#define OPFLAG_BULKCSR       0x01    /* OP_Open** used to open bulk cursor */ | 
| +#define OPFLAG_P2ISREG       0x02    /* P2 to OP_Open** is a register number */ | 
| +#define OPFLAG_PERMUTE       0x01    /* OP_Compare: use the permutation */ | 
|  | 
| /* | 
| * Each trigger present in the database schema is stored as an instance of | 
| @@ -2365,7 +2757,7 @@ struct TriggerStep { | 
| Select *pSelect;     /* SELECT statment or RHS of INSERT INTO .. SELECT ... */ | 
| Token target;        /* Target table for DELETE, UPDATE, INSERT */ | 
| Expr *pWhere;        /* The WHERE clause for DELETE or UPDATE steps */ | 
| -  ExprList *pExprList; /* SET clause for UPDATE.  VALUES clause for INSERT */ | 
| +  ExprList *pExprList; /* SET clause for UPDATE. */ | 
| IdList *pIdList;     /* Column names for INSERT */ | 
| TriggerStep *pNext;  /* Next in the link-list */ | 
| TriggerStep *pLast;  /* Last element in link-list. Valid for 1st elem only */ | 
| @@ -2379,6 +2771,8 @@ struct TriggerStep { | 
| typedef struct DbFixer DbFixer; | 
| struct DbFixer { | 
| Parse *pParse;      /* The parsing context.  Error messages written here */ | 
| +  Schema *pSchema;    /* Fix items to this schema */ | 
| +  int bVarOnly;       /* Check for variable references only */ | 
| const char *zDb;    /* Make sure all objects are contained in this database */ | 
| const char *zType;  /* Type of the container - used for error messages */ | 
| const Token *pName; /* Name of the container - used for error messages */ | 
| @@ -2395,10 +2789,11 @@ struct StrAccum { | 
| int  nChar;          /* Length of the string so far */ | 
| int  nAlloc;         /* Amount of space allocated in zText */ | 
| int  mxAlloc;        /* Maximum allowed string length */ | 
| -  u8   mallocFailed;   /* Becomes true if any memory allocation fails */ | 
| u8   useMalloc;      /* 0: none,  1: sqlite3DbMalloc,  2: sqlite3_malloc */ | 
| -  u8   tooBig;         /* Becomes true if string size exceeds limits */ | 
| +  u8   accError;       /* STRACCUM_NOMEM or STRACCUM_TOOBIG */ | 
| }; | 
| +#define STRACCUM_NOMEM   1 | 
| +#define STRACCUM_TOOBIG  2 | 
|  | 
| /* | 
| ** A pointer to this structure is used to communicate information | 
| @@ -2406,8 +2801,8 @@ struct StrAccum { | 
| */ | 
| typedef struct { | 
| sqlite3 *db;        /* The database being initialized */ | 
| -  int iDb;            /* 0 for main database.  1 for TEMP, 2.. for ATTACHed */ | 
| char **pzErrMsg;    /* Error message stored here */ | 
| +  int iDb;            /* 0 for main database.  1 for TEMP, 2.. for ATTACHed */ | 
| int rc;             /* Result code stored here */ | 
| } InitData; | 
|  | 
| @@ -2420,15 +2815,20 @@ struct Sqlite3Config { | 
| int bMemstat;                     /* True to enable memory status */ | 
| int bCoreMutex;                   /* True to enable core mutexing */ | 
| int bFullMutex;                   /* True to enable full mutexing */ | 
| +  int bOpenUri;                     /* True to interpret filenames as URIs */ | 
| +  int bUseCis;                      /* Use covering indices for full-scans */ | 
| int mxStrlen;                     /* Maximum string length */ | 
| +  int neverCorrupt;                 /* Database is always well-formed */ | 
| int szLookaside;                  /* Default lookaside buffer size */ | 
| int nLookaside;                   /* Default lookaside buffer count */ | 
| sqlite3_mem_methods m;            /* Low-level memory allocation interface */ | 
| sqlite3_mutex_methods mutex;      /* Low-level mutex interface */ | 
| -  sqlite3_pcache_methods pcache;    /* Low-level page-cache interface */ | 
| +  sqlite3_pcache_methods2 pcache2;  /* Low-level page-cache interface */ | 
| void *pHeap;                      /* Heap storage space */ | 
| int nHeap;                        /* Size of pHeap[] */ | 
| int mnReq, mxReq;                 /* Min and max heap requests sizes */ | 
| +  sqlite3_int64 szMmap;             /* mmap() space per open file */ | 
| +  sqlite3_int64 mxMmap;             /* Maximum value for szMmap */ | 
| void *pScratch;                   /* Scratch memory */ | 
| int szScratch;                    /* Size of each scratch buffer */ | 
| int nScratch;                     /* Number of scratch buffers */ | 
| @@ -2444,22 +2844,59 @@ struct Sqlite3Config { | 
| int isMutexInit;                  /* True after mutexes are initialized */ | 
| int isMallocInit;                 /* True after malloc is initialized */ | 
| int isPCacheInit;                 /* True after malloc is initialized */ | 
| -  sqlite3_mutex *pInitMutex;        /* Mutex used by sqlite3_initialize() */ | 
| int nRefInitMutex;                /* Number of users of pInitMutex */ | 
| +  sqlite3_mutex *pInitMutex;        /* Mutex used by sqlite3_initialize() */ | 
| void (*xLog)(void*,int,const char*); /* Function for logging */ | 
| void *pLogArg;                       /* First argument to xLog() */ | 
| +#ifdef SQLITE_ENABLE_SQLLOG | 
| +  void(*xSqllog)(void*,sqlite3*,const char*, int); | 
| +  void *pSqllogArg; | 
| +#endif | 
| +#ifdef SQLITE_VDBE_COVERAGE | 
| +  /* The following callback (if not NULL) is invoked on every VDBE branch | 
| +  ** operation.  Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE. | 
| +  */ | 
| +  void (*xVdbeBranch)(void*,int iSrcLine,u8 eThis,u8 eMx);  /* Callback */ | 
| +  void *pVdbeBranchArg;                                     /* 1st argument */ | 
| +#endif | 
| +#ifndef SQLITE_OMIT_BUILTIN_TEST | 
| +  int (*xTestCallback)(int);        /* Invoked by sqlite3FaultSim() */ | 
| +#endif | 
| +  int bLocaltimeFault;              /* True to fail localtime() calls */ | 
| }; | 
|  | 
| /* | 
| +** This macro is used inside of assert() statements to indicate that | 
| +** the assert is only valid on a well-formed database.  Instead of: | 
| +** | 
| +**     assert( X ); | 
| +** | 
| +** One writes: | 
| +** | 
| +**     assert( X || CORRUPT_DB ); | 
| +** | 
| +** CORRUPT_DB is true during normal operation.  CORRUPT_DB does not indicate | 
| +** that the database is definitely corrupt, only that it might be corrupt. | 
| +** For most test cases, CORRUPT_DB is set to false using a special | 
| +** sqlite3_test_control().  This enables assert() statements to prove | 
| +** things that are always true for well-formed databases. | 
| +*/ | 
| +#define CORRUPT_DB  (sqlite3Config.neverCorrupt==0) | 
| + | 
| +/* | 
| ** Context pointer passed down through the tree-walk. | 
| */ | 
| struct Walker { | 
| int (*xExprCallback)(Walker*, Expr*);     /* Callback for expressions */ | 
| int (*xSelectCallback)(Walker*,Select*);  /* Callback for SELECTs */ | 
| +  void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */ | 
| Parse *pParse;                            /* Parser context.  */ | 
| +  int walkerDepth;                          /* Number of subqueries */ | 
| union {                                   /* Extra data for callback */ | 
| NameContext *pNC;                          /* Naming context */ | 
| int i;                                     /* Integer value */ | 
| +    SrcList *pSrcList;                         /* FROM clause */ | 
| +    struct SrcCount *pSrcCount;                /* Counting column references */ | 
| } u; | 
| }; | 
|  | 
| @@ -2479,6 +2916,32 @@ int sqlite3WalkSelectFrom(Walker*, Select*); | 
| #define WRC_Abort       2   /* Abandon the tree walk */ | 
|  | 
| /* | 
| +** An instance of this structure represents a set of one or more CTEs | 
| +** (common table expressions) created by a single WITH clause. | 
| +*/ | 
| +struct With { | 
| +  int nCte;                       /* Number of CTEs in the WITH clause */ | 
| +  With *pOuter;                   /* Containing WITH clause, or NULL */ | 
| +  struct Cte {                    /* For each CTE in the WITH clause.... */ | 
| +    char *zName;                    /* Name of this CTE */ | 
| +    ExprList *pCols;                /* List of explicit column names, or NULL */ | 
| +    Select *pSelect;                /* The definition of this CTE */ | 
| +    const char *zErr;               /* Error message for circular references */ | 
| +  } a[1]; | 
| +}; | 
| + | 
| +#ifdef SQLITE_DEBUG | 
| +/* | 
| +** An instance of the TreeView object is used for printing the content of | 
| +** data structures on sqlite3DebugPrintf() using a tree-like view. | 
| +*/ | 
| +struct TreeView { | 
| +  int iLevel;             /* Which level of the tree we are on */ | 
| +  u8  bLine[100];         /* Draw vertical in column i if bLine[i] is true */ | 
| +}; | 
| +#endif /* SQLITE_DEBUG */ | 
| + | 
| +/* | 
| ** Assuming zIn points to the first byte of a UTF-8 character, | 
| ** advance zIn to point to the first byte of the next UTF-8 character. | 
| */ | 
| @@ -2505,8 +2968,8 @@ int sqlite3CantopenError(int); | 
|  | 
| /* | 
| ** FTS4 is really an extension for FTS3.  It is enabled using the | 
| -** SQLITE_ENABLE_FTS3 macro.  But to avoid confusion we also all | 
| -** the SQLITE_ENABLE_FTS4 macro to serve as an alisse for SQLITE_ENABLE_FTS3. | 
| +** SQLITE_ENABLE_FTS3 macro.  But to avoid confusion we also call | 
| +** the SQLITE_ENABLE_FTS4 macro to serve as an alias for SQLITE_ENABLE_FTS3. | 
| */ | 
| #if defined(SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3) | 
| # define SQLITE_ENABLE_FTS3 | 
| @@ -2553,25 +3016,26 @@ int sqlite3CantopenError(int); | 
| # define sqlite3Isxdigit(x)  isxdigit((unsigned char)(x)) | 
| # define sqlite3Tolower(x)   tolower((unsigned char)(x)) | 
| #endif | 
| +int sqlite3IsIdChar(u8); | 
|  | 
| /* | 
| ** Internal function prototypes | 
| */ | 
| -int sqlite3StrICmp(const char *, const char *); | 
| +#define sqlite3StrICmp sqlite3_stricmp | 
| int sqlite3Strlen30(const char*); | 
| #define sqlite3StrNICmp sqlite3_strnicmp | 
|  | 
| int sqlite3MallocInit(void); | 
| void sqlite3MallocEnd(void); | 
| -void *sqlite3Malloc(int); | 
| -void *sqlite3MallocZero(int); | 
| -void *sqlite3DbMallocZero(sqlite3*, int); | 
| -void *sqlite3DbMallocRaw(sqlite3*, int); | 
| +void *sqlite3Malloc(u64); | 
| +void *sqlite3MallocZero(u64); | 
| +void *sqlite3DbMallocZero(sqlite3*, u64); | 
| +void *sqlite3DbMallocRaw(sqlite3*, u64); | 
| char *sqlite3DbStrDup(sqlite3*,const char*); | 
| -char *sqlite3DbStrNDup(sqlite3*,const char*, int); | 
| -void *sqlite3Realloc(void*, int); | 
| -void *sqlite3DbReallocOrFree(sqlite3 *, void *, int); | 
| -void *sqlite3DbRealloc(sqlite3 *, void *, int); | 
| +char *sqlite3DbStrNDup(sqlite3*,const char*, u64); | 
| +void *sqlite3Realloc(void*, u64); | 
| +void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64); | 
| +void *sqlite3DbRealloc(sqlite3 *, void *, u64); | 
| void sqlite3DbFree(sqlite3*, void*); | 
| int sqlite3MallocSize(void*); | 
| int sqlite3DbMallocSize(sqlite3*, void*); | 
| @@ -2627,10 +3091,20 @@ void sqlite3StatusSet(int, int); | 
| # define sqlite3IsNaN(X)  0 | 
| #endif | 
|  | 
| -void sqlite3VXPrintf(StrAccum*, int, const char*, va_list); | 
| -#ifndef SQLITE_OMIT_TRACE | 
| -void sqlite3XPrintf(StrAccum*, const char*, ...); | 
| -#endif | 
| +/* | 
| +** An instance of the following structure holds information about SQL | 
| +** functions arguments that are the parameters to the printf() function. | 
| +*/ | 
| +struct PrintfArguments { | 
| +  int nArg;                /* Total number of arguments */ | 
| +  int nUsed;               /* Number of arguments used so far */ | 
| +  sqlite3_value **apArg;   /* The argument values */ | 
| +}; | 
| + | 
| +#define SQLITE_PRINTF_INTERNAL 0x01 | 
| +#define SQLITE_PRINTF_SQLFUNC  0x02 | 
| +void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list); | 
| +void sqlite3XPrintf(StrAccum*, u32, const char*, ...); | 
| char *sqlite3MPrintf(sqlite3*,const char*, ...); | 
| char *sqlite3VMPrintf(sqlite3*,const char*, va_list); | 
| char *sqlite3MAppendf(sqlite3*,char*,const char*,...); | 
| @@ -2640,6 +3114,18 @@ char *sqlite3MAppendf(sqlite3*,char*,const char*,...); | 
| #if defined(SQLITE_TEST) | 
| void *sqlite3TestTextToPtr(const char*); | 
| #endif | 
| + | 
| +#if defined(SQLITE_DEBUG) | 
| +  TreeView *sqlite3TreeViewPush(TreeView*,u8); | 
| +  void sqlite3TreeViewPop(TreeView*); | 
| +  void sqlite3TreeViewLine(TreeView*, const char*, ...); | 
| +  void sqlite3TreeViewItem(TreeView*, const char*, u8); | 
| +  void sqlite3TreeViewExpr(TreeView*, const Expr*, u8); | 
| +  void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*); | 
| +  void sqlite3TreeViewSelect(TreeView*, const Select*, u8); | 
| +#endif | 
| + | 
| + | 
| void sqlite3SetString(char **, sqlite3*, const char*, ...); | 
| void sqlite3ErrorMsg(Parse*, const char*, ...); | 
| int sqlite3Dequote(char*); | 
| @@ -2650,6 +3136,7 @@ int sqlite3GetTempReg(Parse*); | 
| void sqlite3ReleaseTempReg(Parse*,int); | 
| int sqlite3GetTempRange(Parse*,int); | 
| void sqlite3ReleaseTempRange(Parse*,int,int); | 
| +void sqlite3ClearTempRegCache(Parse*); | 
| Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int); | 
| Expr *sqlite3Expr(sqlite3*,int,const char*); | 
| void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*); | 
| @@ -2665,11 +3152,15 @@ void sqlite3ExprListDelete(sqlite3*, ExprList*); | 
| int sqlite3Init(sqlite3*, char**); | 
| int sqlite3InitCallback(void*, int, char**, char**); | 
| void sqlite3Pragma(Parse*,Token*,Token*,Token*,int); | 
| -void sqlite3ResetInternalSchema(sqlite3*, int); | 
| +void sqlite3ResetAllSchemasOfConnection(sqlite3*); | 
| +void sqlite3ResetOneSchema(sqlite3*,int); | 
| +void sqlite3CollapseDatabaseArray(sqlite3*); | 
| void sqlite3BeginParse(Parse*,int); | 
| void sqlite3CommitInternalChanges(sqlite3*); | 
| Table *sqlite3ResultSetOfSelect(Parse*,Select*); | 
| void sqlite3OpenMasterTable(Parse *, int); | 
| +Index *sqlite3PrimaryKeyIndex(Table*); | 
| +i16 sqlite3ColumnOfIndex(Index*, i16); | 
| void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int); | 
| void sqlite3AddColumn(Parse*,Token*); | 
| void sqlite3AddNotNull(Parse*, int); | 
| @@ -2678,7 +3169,17 @@ void sqlite3AddCheckConstraint(Parse*, Expr*); | 
| void sqlite3AddColumnType(Parse*,Token*); | 
| void sqlite3AddDefaultValue(Parse*,ExprSpan*); | 
| void sqlite3AddCollateType(Parse*, Token*); | 
| -void sqlite3EndTable(Parse*,Token*,Token*,Select*); | 
| +void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*); | 
| +int sqlite3ParseUri(const char*,const char*,unsigned int*, | 
| +                    sqlite3_vfs**,char**,char **); | 
| +Btree *sqlite3DbNameToBtree(sqlite3*,const char*); | 
| +int sqlite3CodeOnce(Parse *); | 
| + | 
| +#ifdef SQLITE_OMIT_BUILTIN_TEST | 
| +# define sqlite3FaultSim(X) SQLITE_OK | 
| +#else | 
| +  int sqlite3FaultSim(int); | 
| +#endif | 
|  | 
| Bitvec *sqlite3BitvecCreate(u32); | 
| int sqlite3BitvecTest(Bitvec*, u32); | 
| @@ -2691,7 +3192,7 @@ int sqlite3BitvecBuiltinTest(int,int*); | 
| RowSet *sqlite3RowSetInit(sqlite3*, void*, unsigned int); | 
| void sqlite3RowSetClear(RowSet*); | 
| void sqlite3RowSetInsert(RowSet*, i64); | 
| -int sqlite3RowSetTest(RowSet*, u8 iBatch, i64); | 
| +int sqlite3RowSetTest(RowSet*, int iBatch, i64); | 
| int sqlite3RowSetNext(RowSet*, i64*); | 
|  | 
| void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int,int); | 
| @@ -2702,7 +3203,11 @@ void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int,int); | 
| # define sqlite3ViewGetColumnNames(A,B) 0 | 
| #endif | 
|  | 
| +#if SQLITE_MAX_ATTACHED>30 | 
| +  int sqlite3DbMaskAllZero(yDbMask); | 
| +#endif | 
| void sqlite3DropTable(Parse*, SrcList*, int, int); | 
| +void sqlite3CodeDropTable(Parse*, Table*, int, int); | 
| void sqlite3DeleteTable(sqlite3*, Table*); | 
| #ifndef SQLITE_OMIT_AUTOINCREMENT | 
| void sqlite3AutoincrementBegin(Parse *pParse); | 
| @@ -2711,8 +3216,8 @@ void sqlite3DeleteTable(sqlite3*, Table*); | 
| # define sqlite3AutoincrementBegin(X) | 
| # define sqlite3AutoincrementEnd(X) | 
| #endif | 
| -void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int); | 
| -void *sqlite3ArrayAllocate(sqlite3*,void*,int,int,int*,int*,int*); | 
| +void sqlite3Insert(Parse*, SrcList*, Select*, IdList*, int); | 
| +void *sqlite3ArrayAllocate(sqlite3*,void*,int,int*,int*); | 
| IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*); | 
| int sqlite3IdListIndex(IdList*,const char*); | 
| SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int); | 
| @@ -2725,58 +3230,70 @@ void sqlite3SrcListShiftJoinType(SrcList*); | 
| void sqlite3SrcListAssignCursors(Parse*, SrcList*); | 
| void sqlite3IdListDelete(sqlite3*, IdList*); | 
| void sqlite3SrcListDelete(sqlite3*, SrcList*); | 
| +Index *sqlite3AllocateIndexObject(sqlite3*,i16,int,char**); | 
| Index *sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*, | 
| -                        Token*, int, int); | 
| +                          Expr*, int, int); | 
| void sqlite3DropIndex(Parse*, SrcList*, int); | 
| int sqlite3Select(Parse*, Select*, SelectDest*); | 
| Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*, | 
| -                         Expr*,ExprList*,int,Expr*,Expr*); | 
| +                         Expr*,ExprList*,u16,Expr*,Expr*); | 
| void sqlite3SelectDelete(sqlite3*, Select*); | 
| Table *sqlite3SrcListLookup(Parse*, SrcList*); | 
| int sqlite3IsReadOnly(Parse*, Table*, int); | 
| void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int); | 
| #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) | 
| -Expr *sqlite3LimitWhere(Parse *, SrcList *, Expr *, ExprList *, Expr *, Expr *, char *); | 
| +Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,Expr*,char*); | 
| #endif | 
| void sqlite3DeleteFrom(Parse*, SrcList*, Expr*); | 
| void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int); | 
| -WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**, u16); | 
| +WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,ExprList*,u16,int); | 
| void sqlite3WhereEnd(WhereInfo*); | 
| -int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int); | 
| +u64 sqlite3WhereOutputRowCount(WhereInfo*); | 
| +int sqlite3WhereIsDistinct(WhereInfo*); | 
| +int sqlite3WhereIsOrdered(WhereInfo*); | 
| +int sqlite3WhereIsSorted(WhereInfo*); | 
| +int sqlite3WhereContinueLabel(WhereInfo*); | 
| +int sqlite3WhereBreakLabel(WhereInfo*); | 
| +int sqlite3WhereOkOnePass(WhereInfo*, int*); | 
| +int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8); | 
| void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int); | 
| void sqlite3ExprCodeMove(Parse*, int, int, int); | 
| -void sqlite3ExprCodeCopy(Parse*, int, int, int); | 
| void sqlite3ExprCacheStore(Parse*, int, int, int); | 
| void sqlite3ExprCachePush(Parse*); | 
| -void sqlite3ExprCachePop(Parse*, int); | 
| +void sqlite3ExprCachePop(Parse*); | 
| void sqlite3ExprCacheRemove(Parse*, int, int); | 
| void sqlite3ExprCacheClear(Parse*); | 
| void sqlite3ExprCacheAffinityChange(Parse*, int, int); | 
| -int sqlite3ExprCode(Parse*, Expr*, int); | 
| +void sqlite3ExprCode(Parse*, Expr*, int); | 
| +void sqlite3ExprCodeFactorable(Parse*, Expr*, int); | 
| +void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8); | 
| int sqlite3ExprCodeTemp(Parse*, Expr*, int*); | 
| int sqlite3ExprCodeTarget(Parse*, Expr*, int); | 
| -int sqlite3ExprCodeAndCache(Parse*, Expr*, int); | 
| -void sqlite3ExprCodeConstants(Parse*, Expr*); | 
| -int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int); | 
| +void sqlite3ExprCodeAndCache(Parse*, Expr*, int); | 
| +int sqlite3ExprCodeExprList(Parse*, ExprList*, int, u8); | 
| +#define SQLITE_ECEL_DUP      0x01  /* Deep, not shallow copies */ | 
| +#define SQLITE_ECEL_FACTOR   0x02  /* Factor out constant terms */ | 
| void sqlite3ExprIfTrue(Parse*, Expr*, int, int); | 
| void sqlite3ExprIfFalse(Parse*, Expr*, int, int); | 
| Table *sqlite3FindTable(sqlite3*,const char*, const char*); | 
| Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*); | 
| +Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *); | 
| Index *sqlite3FindIndex(sqlite3*,const char*, const char*); | 
| void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*); | 
| void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*); | 
| void sqlite3Vacuum(Parse*); | 
| int sqlite3RunVacuum(char**, sqlite3*); | 
| char *sqlite3NameFromToken(sqlite3*, Token*); | 
| -int sqlite3ExprCompare(Expr*, Expr*); | 
| -int sqlite3ExprListCompare(ExprList*, ExprList*); | 
| +int sqlite3ExprCompare(Expr*, Expr*, int); | 
| +int sqlite3ExprListCompare(ExprList*, ExprList*, int); | 
| +int sqlite3ExprImpliesExpr(Expr*, Expr*, int); | 
| void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); | 
| void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); | 
| +int sqlite3FunctionUsesThisSrc(Expr*, SrcList*); | 
| Vdbe *sqlite3GetVdbe(Parse*); | 
| void sqlite3PrngSaveState(void); | 
| void sqlite3PrngRestoreState(void); | 
| -void sqlite3PrngResetState(void); | 
| -void sqlite3RollbackAll(sqlite3*); | 
| +void sqlite3RollbackAll(sqlite3*,int); | 
| void sqlite3CodeVerifySchema(Parse*, int); | 
| void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb); | 
| void sqlite3BeginTransaction(Parse*, int); | 
| @@ -2784,32 +3301,40 @@ void sqlite3CommitTransaction(Parse*); | 
| void sqlite3RollbackTransaction(Parse*); | 
| void sqlite3Savepoint(Parse*, int, Token*); | 
| void sqlite3CloseSavepoints(sqlite3 *); | 
| +void sqlite3LeaveMutexAndCloseZombie(sqlite3*); | 
| int sqlite3ExprIsConstant(Expr*); | 
| int sqlite3ExprIsConstantNotJoin(Expr*); | 
| -int sqlite3ExprIsConstantOrFunction(Expr*); | 
| +int sqlite3ExprIsConstantOrFunction(Expr*, u8); | 
| int sqlite3ExprIsInteger(Expr*, int*); | 
| int sqlite3ExprCanBeNull(const Expr*); | 
| -void sqlite3ExprCodeIsNullJump(Vdbe*, const Expr*, int, int); | 
| int sqlite3ExprNeedsNoAffinityChange(const Expr*, char); | 
| int sqlite3IsRowid(const char*); | 
| -void sqlite3GenerateRowDelete(Parse*, Table*, int, int, int, Trigger *, int); | 
| -void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int*); | 
| -int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int); | 
| -void sqlite3GenerateConstraintChecks(Parse*,Table*,int,int, | 
| -                                     int*,int,int,int,int,int*); | 
| -void sqlite3CompleteInsertion(Parse*, Table*, int, int, int*, int, int, int); | 
| -int sqlite3OpenTableAndIndices(Parse*, Table*, int, int); | 
| +void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8); | 
| +void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*); | 
| +int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int); | 
| +void sqlite3ResolvePartIdxLabel(Parse*,int); | 
| +void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int, | 
| +                                     u8,u8,int,int*); | 
| +void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int); | 
| +int sqlite3OpenTableAndIndices(Parse*, Table*, int, int, u8*, int*, int*); | 
| void sqlite3BeginWriteOperation(Parse*, int, int); | 
| void sqlite3MultiWrite(Parse*); | 
| void sqlite3MayAbort(Parse*); | 
| -void sqlite3HaltConstraint(Parse*, int, char*, int); | 
| +void sqlite3HaltConstraint(Parse*, int, int, char*, i8, u8); | 
| +void sqlite3UniqueConstraint(Parse*, int, Index*); | 
| +void sqlite3RowidConstraint(Parse*, int, Table*); | 
| Expr *sqlite3ExprDup(sqlite3*,Expr*,int); | 
| ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int); | 
| SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int); | 
| IdList *sqlite3IdListDup(sqlite3*,IdList*); | 
| Select *sqlite3SelectDup(sqlite3*,Select*,int); | 
| +#if SELECTTRACE_ENABLED | 
| +void sqlite3SelectSetName(Select*,const char*); | 
| +#else | 
| +# define sqlite3SelectSetName(A,B) | 
| +#endif | 
| void sqlite3FuncDefInsert(FuncDefHash*, FuncDef*); | 
| -FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,int); | 
| +FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,u8); | 
| void sqlite3RegisterBuiltinFunctions(sqlite3*); | 
| void sqlite3RegisterDateTimeFunctions(void); | 
| void sqlite3RegisterGlobalFunctions(void); | 
| @@ -2836,7 +3361,7 @@ void sqlite3MaterializeView(Parse*, Table*, Expr*, int); | 
| void sqlite3DeleteTriggerStep(sqlite3*, TriggerStep*); | 
| TriggerStep *sqlite3TriggerSelectStep(sqlite3*,Select*); | 
| TriggerStep *sqlite3TriggerInsertStep(sqlite3*,Token*, IdList*, | 
| -                                        ExprList*,Select*,u8); | 
| +                                        Select*,u8); | 
| TriggerStep *sqlite3TriggerUpdateStep(sqlite3*,Token*,ExprList*, Expr*, u8); | 
| TriggerStep *sqlite3TriggerDeleteStep(sqlite3*,Token*, Expr*); | 
| void sqlite3DeleteTrigger(sqlite3*, Trigger*); | 
| @@ -2872,7 +3397,7 @@ void sqlite3DeferForeignKey(Parse*, int); | 
| #endif | 
| void sqlite3Attach(Parse*, Expr*, Expr*, Expr*); | 
| void sqlite3Detach(Parse*, Expr*); | 
| -int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*); | 
| +void sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*); | 
| int sqlite3FixSrcList(DbFixer*, SrcList*); | 
| int sqlite3FixSelect(DbFixer*, Select*); | 
| int sqlite3FixExpr(DbFixer*, Expr*); | 
| @@ -2883,60 +3408,63 @@ int sqlite3GetInt32(const char *, int*); | 
| int sqlite3Atoi(const char*); | 
| int sqlite3Utf16ByteLen(const void *pData, int nChar); | 
| int sqlite3Utf8CharLen(const char *pData, int nByte); | 
| -int sqlite3Utf8Read(const u8*, const u8**); | 
| +u32 sqlite3Utf8Read(const u8**); | 
| +LogEst sqlite3LogEst(u64); | 
| +LogEst sqlite3LogEstAdd(LogEst,LogEst); | 
| +#ifndef SQLITE_OMIT_VIRTUALTABLE | 
| +LogEst sqlite3LogEstFromDouble(double); | 
| +#endif | 
| +u64 sqlite3LogEstToInt(LogEst); | 
|  | 
| /* | 
| ** Routines to read and write variable-length integers.  These used to | 
| ** be defined locally, but now we use the varint routines in the util.c | 
| -** file.  Code should use the MACRO forms below, as the Varint32 versions | 
| -** are coded to assume the single byte case is already handled (which | 
| -** the MACRO form does). | 
| +** file. | 
| */ | 
| int sqlite3PutVarint(unsigned char*, u64); | 
| -int sqlite3PutVarint32(unsigned char*, u32); | 
| u8 sqlite3GetVarint(const unsigned char *, u64 *); | 
| u8 sqlite3GetVarint32(const unsigned char *, u32 *); | 
| int sqlite3VarintLen(u64 v); | 
|  | 
| /* | 
| -** The header of a record consists of a sequence variable-length integers. | 
| -** These integers are almost always small and are encoded as a single byte. | 
| -** The following macros take advantage this fact to provide a fast encode | 
| -** and decode of the integers in a record header.  It is faster for the common | 
| -** case where the integer is a single byte.  It is a little slower when the | 
| -** integer is two or more bytes.  But overall it is faster. | 
| -** | 
| -** The following expressions are equivalent: | 
| -** | 
| -**     x = sqlite3GetVarint32( A, &B ); | 
| -**     x = sqlite3PutVarint32( A, B ); | 
| -** | 
| -**     x = getVarint32( A, B ); | 
| -**     x = putVarint32( A, B ); | 
| -** | 
| +** The common case is for a varint to be a single byte.  They following | 
| +** macros handle the common case without a procedure call, but then call | 
| +** the procedure for larger varints. | 
| */ | 
| -#define getVarint32(A,B)  (u8)((*(A)<(u8)0x80) ? ((B) = (u32)*(A)),1 : sqlite3GetVarint32((A), (u32 *)&(B))) | 
| -#define putVarint32(A,B)  (u8)(((u32)(B)<(u32)0x80) ? (*(A) = (unsigned char)(B)),1 : sqlite3PutVarint32((A), (B))) | 
| +#define getVarint32(A,B)  \ | 
| +  (u8)((*(A)<(u8)0x80)?((B)=(u32)*(A)),1:sqlite3GetVarint32((A),(u32 *)&(B))) | 
| +#define putVarint32(A,B)  \ | 
| +  (u8)(((u32)(B)<(u32)0x80)?(*(A)=(unsigned char)(B)),1:\ | 
| +  sqlite3PutVarint((A),(B))) | 
| #define getVarint    sqlite3GetVarint | 
| #define putVarint    sqlite3PutVarint | 
|  | 
|  | 
| const char *sqlite3IndexAffinityStr(Vdbe *, Index *); | 
| -void sqlite3TableAffinityStr(Vdbe *, Table *); | 
| +void sqlite3TableAffinity(Vdbe*, Table*, int); | 
| char sqlite3CompareAffinity(Expr *pExpr, char aff2); | 
| int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity); | 
| char sqlite3ExprAffinity(Expr *pExpr); | 
| int sqlite3Atoi64(const char*, i64*, int, u8); | 
| -void sqlite3Error(sqlite3*, int, const char*,...); | 
| +int sqlite3DecOrHexToI64(const char*, i64*); | 
| +void sqlite3ErrorWithMsg(sqlite3*, int, const char*,...); | 
| +void sqlite3Error(sqlite3*,int); | 
| void *sqlite3HexToBlob(sqlite3*, const char *z, int n); | 
| +u8 sqlite3HexToInt(int h); | 
| int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); | 
| + | 
| +#if defined(SQLITE_TEST) | 
| +const char *sqlite3ErrName(int); | 
| +#endif | 
| + | 
| const char *sqlite3ErrStr(int); | 
| int sqlite3ReadSchema(Parse *pParse); | 
| CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); | 
| CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName); | 
| CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr); | 
| -Expr *sqlite3ExprSetColl(Expr*, CollSeq*); | 
| -Expr *sqlite3ExprSetCollByToken(Parse *pParse, Expr*, Token*); | 
| +Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, const Token*); | 
| +Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*); | 
| +Expr *sqlite3ExprSkipCollate(Expr*); | 
| int sqlite3CheckCollSeq(Parse *, CollSeq *); | 
| int sqlite3CheckObjectName(Parse *, const char *); | 
| void sqlite3VdbeSetChanges(sqlite3 *, int); | 
| @@ -2944,17 +3472,21 @@ int sqlite3AddInt64(i64*,i64); | 
| int sqlite3SubInt64(i64*,i64); | 
| int sqlite3MulInt64(i64*,i64); | 
| int sqlite3AbsInt32(int); | 
| +#ifdef SQLITE_ENABLE_8_3_NAMES | 
| +void sqlite3FileSuffix3(const char*, char*); | 
| +#else | 
| +# define sqlite3FileSuffix3(X,Y) | 
| +#endif | 
| +u8 sqlite3GetBoolean(const char *z,u8); | 
|  | 
| const void *sqlite3ValueText(sqlite3_value*, u8); | 
| int sqlite3ValueBytes(sqlite3_value*, u8); | 
| void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, | 
| void(*)(void*)); | 
| +void sqlite3ValueSetNull(sqlite3_value*); | 
| void sqlite3ValueFree(sqlite3_value*); | 
| sqlite3_value *sqlite3ValueNew(sqlite3 *); | 
| char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8); | 
| -#ifdef SQLITE_ENABLE_STAT2 | 
| -char *sqlite3Utf8to16(sqlite3 *, u8, char *, int, int *); | 
| -#endif | 
| int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **); | 
| void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); | 
| #ifndef SQLITE_AMALGAMATION | 
| @@ -2977,14 +3509,16 @@ void sqlite3NestedParse(Parse*, const char*, ...); | 
| void sqlite3ExpirePreparedStatements(sqlite3*); | 
| int sqlite3CodeSubselect(Parse *, Expr *, int, int); | 
| void sqlite3SelectPrep(Parse*, Select*, NameContext*); | 
| +int sqlite3MatchSpanName(const char*, const char*, const char*, const char*); | 
| int sqlite3ResolveExprNames(NameContext*, Expr*); | 
| void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*); | 
| +void sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*); | 
| int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*); | 
| void sqlite3ColumnDefault(Vdbe *, Table *, int, int); | 
| void sqlite3AlterFinishAddColumn(Parse *, Token *); | 
| void sqlite3AlterBeginAddColumn(Parse *, SrcList *); | 
| -CollSeq *sqlite3GetCollSeq(sqlite3*, u8, CollSeq *, const char*); | 
| -char sqlite3AffinityType(const char*); | 
| +CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*); | 
| +char sqlite3AffinityType(const char*, u8*); | 
| void sqlite3Analyze(Parse*, Token*, Token*); | 
| int sqlite3InvokeBusyHandler(BusyHandler*); | 
| int sqlite3FindDb(sqlite3*, Token*); | 
| @@ -2998,7 +3532,13 @@ void sqlite3MinimumFileFormat(Parse*, int, int); | 
| void sqlite3SchemaClear(void *); | 
| Schema *sqlite3SchemaGet(sqlite3 *, Btree *); | 
| int sqlite3SchemaToIndex(sqlite3 *db, Schema *); | 
| -KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *); | 
| +KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int,int); | 
| +void sqlite3KeyInfoUnref(KeyInfo*); | 
| +KeyInfo *sqlite3KeyInfoRef(KeyInfo*); | 
| +KeyInfo *sqlite3KeyInfoOfIndex(Parse*, Index*); | 
| +#ifdef SQLITE_DEBUG | 
| +int sqlite3KeyInfoIsWriteable(KeyInfo*); | 
| +#endif | 
| int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *, | 
| void (*)(sqlite3_context*,int,sqlite3_value **), | 
| void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*), | 
| @@ -3009,6 +3549,8 @@ int sqlite3OpenTempDatabase(Parse *); | 
|  | 
| void sqlite3StrAccumInit(StrAccum*, char*, int, int); | 
| void sqlite3StrAccumAppend(StrAccum*,const char*,int); | 
| +void sqlite3StrAccumAppendAll(StrAccum*,const char*); | 
| +void sqlite3AppendChar(StrAccum*,int,char); | 
| char *sqlite3StrAccumFinish(StrAccum*); | 
| void sqlite3StrAccumReset(StrAccum*); | 
| void sqlite3SelectDestInit(SelectDest*,int,int); | 
| @@ -3017,10 +3559,18 @@ Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int); | 
| void sqlite3BackupRestart(sqlite3_backup *); | 
| void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *); | 
|  | 
| +#ifdef SQLITE_ENABLE_STAT3_OR_STAT4 | 
| +void sqlite3AnalyzeFunctions(void); | 
| +int sqlite3Stat4ProbeSetValue(Parse*,Index*,UnpackedRecord**,Expr*,u8,int,int*); | 
| +int sqlite3Stat4ValueFromExpr(Parse*, Expr*, u8, sqlite3_value**); | 
| +void sqlite3Stat4ProbeFree(UnpackedRecord*); | 
| +int sqlite3Stat4Column(sqlite3*, const void*, int, int, sqlite3_value**); | 
| +#endif | 
| + | 
| /* | 
| ** The interface to the LEMON-generated parser | 
| */ | 
| -void *sqlite3ParserAlloc(void*(*)(size_t)); | 
| +void *sqlite3ParserAlloc(void*(*)(u64)); | 
| void sqlite3ParserFree(void*, void(*)(void*)); | 
| void sqlite3Parser(void*, int, Token, Parse*); | 
| #ifdef YYTRACKMAXSTACKDEPTH | 
| @@ -3053,18 +3603,24 @@ void sqlite3AutoLoadExtensions(sqlite3*); | 
| #  define sqlite3VtabLock(X) | 
| #  define sqlite3VtabUnlock(X) | 
| #  define sqlite3VtabUnlockList(X) | 
| +#  define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK | 
| +#  define sqlite3GetVTable(X,Y)  ((VTable*)0) | 
| #else | 
| void sqlite3VtabClear(sqlite3 *db, Table*); | 
| -   int sqlite3VtabSync(sqlite3 *db, char **); | 
| +   void sqlite3VtabDisconnect(sqlite3 *db, Table *p); | 
| +   int sqlite3VtabSync(sqlite3 *db, Vdbe*); | 
| int sqlite3VtabRollback(sqlite3 *db); | 
| int sqlite3VtabCommit(sqlite3 *db); | 
| void sqlite3VtabLock(VTable *); | 
| void sqlite3VtabUnlock(VTable *); | 
| void sqlite3VtabUnlockList(sqlite3*); | 
| +   int sqlite3VtabSavepoint(sqlite3 *, int, int); | 
| +   void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*); | 
| +   VTable *sqlite3GetVTable(sqlite3*, Table*); | 
| #  define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0) | 
| #endif | 
| void sqlite3VtabMakeWritable(Parse*,Table*); | 
| -void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*); | 
| +void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int); | 
| void sqlite3VtabFinishParse(Parse*, Token*); | 
| void sqlite3VtabArgInit(Parse*); | 
| void sqlite3VtabArgExtend(Parse*, Token*); | 
| @@ -3074,16 +3630,27 @@ int sqlite3VtabCallDestroy(sqlite3*, int, const char *); | 
| int sqlite3VtabBegin(sqlite3 *, VTable *); | 
| FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*); | 
| void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**); | 
| +sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*); | 
| int sqlite3VdbeParameterIndex(Vdbe*, const char*, int); | 
| int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *); | 
| +void sqlite3ParserReset(Parse*); | 
| int sqlite3Reprepare(Vdbe*); | 
| void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*); | 
| CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *); | 
| int sqlite3TempInMemory(const sqlite3*); | 
| -VTable *sqlite3GetVTable(sqlite3*, Table*); | 
| const char *sqlite3JournalModename(int); | 
| -int sqlite3Checkpoint(sqlite3*, int, int, int*, int*); | 
| -int sqlite3WalDefaultHook(void*,sqlite3*,const char*,int); | 
| +#ifndef SQLITE_OMIT_WAL | 
| +  int sqlite3Checkpoint(sqlite3*, int, int, int*, int*); | 
| +  int sqlite3WalDefaultHook(void*,sqlite3*,const char*,int); | 
| +#endif | 
| +#ifndef SQLITE_OMIT_CTE | 
| +  With *sqlite3WithAdd(Parse*,With*,Token*,ExprList*,Select*); | 
| +  void sqlite3WithDelete(sqlite3*,With*); | 
| +  void sqlite3WithPush(Parse*, With*, u8); | 
| +#else | 
| +#define sqlite3WithPush(x,y,z) | 
| +#define sqlite3WithDelete(x,y) | 
| +#endif | 
|  | 
| /* Declarations for functions in fkey.c. All of these are replaced by | 
| ** no-op macros if OMIT_FOREIGN_KEY is defined. In this case no foreign | 
| @@ -3093,23 +3660,25 @@ int sqlite3WalDefaultHook(void*,sqlite3*,const char*,int); | 
| ** provided (enforcement of FK constraints requires the triggers sub-system). | 
| */ | 
| #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) | 
| -  void sqlite3FkCheck(Parse*, Table*, int, int); | 
| +  void sqlite3FkCheck(Parse*, Table*, int, int, int*, int); | 
| void sqlite3FkDropTable(Parse*, SrcList *, Table*); | 
| -  void sqlite3FkActions(Parse*, Table*, ExprList*, int); | 
| +  void sqlite3FkActions(Parse*, Table*, ExprList*, int, int*, int); | 
| int sqlite3FkRequired(Parse*, Table*, int*, int); | 
| u32 sqlite3FkOldmask(Parse*, Table*); | 
| FKey *sqlite3FkReferences(Table *); | 
| #else | 
| -  #define sqlite3FkActions(a,b,c,d) | 
| -  #define sqlite3FkCheck(a,b,c,d) | 
| +  #define sqlite3FkActions(a,b,c,d,e,f) | 
| +  #define sqlite3FkCheck(a,b,c,d,e,f) | 
| #define sqlite3FkDropTable(a,b,c) | 
| -  #define sqlite3FkOldmask(a,b)      0 | 
| -  #define sqlite3FkRequired(a,b,c,d) 0 | 
| +  #define sqlite3FkOldmask(a,b)         0 | 
| +  #define sqlite3FkRequired(a,b,c,d)    0 | 
| #endif | 
| #ifndef SQLITE_OMIT_FOREIGN_KEY | 
| void sqlite3FkDelete(sqlite3 *, Table*); | 
| +  int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**); | 
| #else | 
| #define sqlite3FkDelete(a,b) | 
| +  #define sqlite3FkLocateIndex(a,b,c,d,e) | 
| #endif | 
|  | 
|  | 
| @@ -3132,17 +3701,30 @@ int sqlite3WalDefaultHook(void*,sqlite3*,const char*,int); | 
| #define sqlite3EndBenignMalloc() | 
| #endif | 
|  | 
| -#define IN_INDEX_ROWID           1 | 
| -#define IN_INDEX_EPH             2 | 
| -#define IN_INDEX_INDEX           3 | 
| -int sqlite3FindInIndex(Parse *, Expr *, int*); | 
| +/* | 
| +** Allowed return values from sqlite3FindInIndex() | 
| +*/ | 
| +#define IN_INDEX_ROWID        1   /* Search the rowid of the table */ | 
| +#define IN_INDEX_EPH          2   /* Search an ephemeral b-tree */ | 
| +#define IN_INDEX_INDEX_ASC    3   /* Existing index ASCENDING */ | 
| +#define IN_INDEX_INDEX_DESC   4   /* Existing index DESCENDING */ | 
| +#define IN_INDEX_NOOP         5   /* No table available. Use comparisons */ | 
| +/* | 
| +** Allowed flags for the 3rd parameter to sqlite3FindInIndex(). | 
| +*/ | 
| +#define IN_INDEX_NOOP_OK     0x0001  /* OK to return IN_INDEX_NOOP */ | 
| +#define IN_INDEX_MEMBERSHIP  0x0002  /* IN operator used for membership test */ | 
| +#define IN_INDEX_LOOP        0x0004  /* IN operator used as a loop */ | 
| +int sqlite3FindInIndex(Parse *, Expr *, u32, int*); | 
|  | 
| #ifdef SQLITE_ENABLE_ATOMIC_WRITE | 
| int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int); | 
| int sqlite3JournalSize(sqlite3_vfs *); | 
| int sqlite3JournalCreate(sqlite3_file *); | 
| +  int sqlite3JournalExists(sqlite3_file *p); | 
| #else | 
| #define sqlite3JournalSize(pVfs) ((pVfs)->szOsFile) | 
| +  #define sqlite3JournalExists(p) 1 | 
| #endif | 
|  | 
| void sqlite3MemJournalOpen(sqlite3_file *); | 
| @@ -3228,9 +3810,16 @@ SQLITE_EXTERN void (*sqlite3IoTrace)(const char*,...); | 
| # define sqlite3MemdebugNoType(X,Y)   1 | 
| #endif | 
| #define MEMTYPE_HEAP       0x01  /* General heap allocations */ | 
| -#define MEMTYPE_LOOKASIDE  0x02  /* Might have been lookaside memory */ | 
| +#define MEMTYPE_LOOKASIDE  0x02  /* Heap that might have been lookaside */ | 
| #define MEMTYPE_SCRATCH    0x04  /* Scratch allocations */ | 
| #define MEMTYPE_PCACHE     0x08  /* Page cache allocations */ | 
| -#define MEMTYPE_DB         0x10  /* Uses sqlite3DbMalloc, not sqlite_malloc */ | 
| + | 
| +/* | 
| +** Threading interface | 
| +*/ | 
| +#if SQLITE_MAX_WORKER_THREADS>0 | 
| +int sqlite3ThreadCreate(SQLiteThread**,void*(*)(void*),void*); | 
| +int sqlite3ThreadJoin(SQLiteThread*, void**); | 
| +#endif | 
|  | 
| #endif /* _SQLITEINT_H_ */ | 
|  |