update sqlite amalgamation
authorDirk Zimmermann <dz@pep.security>
Tue, 18 Dec 2018 08:58:51 +0100
changeset 31928797e99f7ab2
parent 3183 324de911c575
child 3196 dea77b929e71
child 3216 f7a5d25e60d5
update sqlite amalgamation
src/sqlite3.c
src/sqlite3.h
     1.1 --- a/src/sqlite3.c	Tue Dec 11 14:19:34 2018 +0100
     1.2 +++ b/src/sqlite3.c	Tue Dec 18 08:58:51 2018 +0100
     1.3 @@ -1,6 +1,6 @@
     1.4  /******************************************************************************
     1.5  ** This file is an amalgamation of many separate C source files from SQLite
     1.6 -** version 3.19.3.  By combining all the individual C code files into this
     1.7 +** version 3.26.0.  By combining all the individual C code files into this
     1.8  ** single large file, the entire code can be compiled as a single translation
     1.9  ** unit.  This allows many compilers to do optimizations that would not be
    1.10  ** possible if the files were compiled separately.  Performance improvements
    1.11 @@ -22,6 +22,776 @@
    1.12  #ifndef SQLITE_PRIVATE
    1.13  # define SQLITE_PRIVATE static
    1.14  #endif
    1.15 +/************** Begin file ctime.c *******************************************/
    1.16 +/*
    1.17 +** 2010 February 23
    1.18 +**
    1.19 +** The author disclaims copyright to this source code.  In place of
    1.20 +** a legal notice, here is a blessing:
    1.21 +**
    1.22 +**    May you do good and not evil.
    1.23 +**    May you find forgiveness for yourself and forgive others.
    1.24 +**    May you share freely, never taking more than you give.
    1.25 +**
    1.26 +*************************************************************************
    1.27 +**
    1.28 +** This file implements routines used to report what compile-time options
    1.29 +** SQLite was built with.
    1.30 +*/
    1.31 +
    1.32 +#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
    1.33 +
    1.34 +/*
    1.35 +** Include the configuration header output by 'configure' if we're using the
    1.36 +** autoconf-based build
    1.37 +*/
    1.38 +#if defined(_HAVE_SQLITE_CONFIG_H) && !defined(SQLITECONFIG_H)
    1.39 +#include "config.h"
    1.40 +#define SQLITECONFIG_H 1
    1.41 +#endif
    1.42 +
    1.43 +/* These macros are provided to "stringify" the value of the define
    1.44 +** for those options in which the value is meaningful. */
    1.45 +#define CTIMEOPT_VAL_(opt) #opt
    1.46 +#define CTIMEOPT_VAL(opt) CTIMEOPT_VAL_(opt)
    1.47 +
    1.48 +/* Like CTIMEOPT_VAL, but especially for SQLITE_DEFAULT_LOOKASIDE. This
    1.49 +** option requires a separate macro because legal values contain a single
    1.50 +** comma. e.g. (-DSQLITE_DEFAULT_LOOKASIDE="100,100") */
    1.51 +#define CTIMEOPT_VAL2_(opt1,opt2) #opt1 "," #opt2
    1.52 +#define CTIMEOPT_VAL2(opt) CTIMEOPT_VAL2_(opt)
    1.53 +
    1.54 +/*
    1.55 +** An array of names of all compile-time options.  This array should 
    1.56 +** be sorted A-Z.
    1.57 +**
    1.58 +** This array looks large, but in a typical installation actually uses
    1.59 +** only a handful of compile-time options, so most times this array is usually
    1.60 +** rather short and uses little memory space.
    1.61 +*/
    1.62 +static const char * const sqlite3azCompileOpt[] = {
    1.63 +
    1.64 +/* 
    1.65 +** BEGIN CODE GENERATED BY tool/mkctime.tcl 
    1.66 +*/
    1.67 +#if SQLITE_32BIT_ROWID
    1.68 +  "32BIT_ROWID",
    1.69 +#endif
    1.70 +#if SQLITE_4_BYTE_ALIGNED_MALLOC
    1.71 +  "4_BYTE_ALIGNED_MALLOC",
    1.72 +#endif
    1.73 +#if SQLITE_64BIT_STATS
    1.74 +  "64BIT_STATS",
    1.75 +#endif
    1.76 +#if SQLITE_ALLOW_COVERING_INDEX_SCAN
    1.77 +  "ALLOW_COVERING_INDEX_SCAN",
    1.78 +#endif
    1.79 +#if SQLITE_ALLOW_URI_AUTHORITY
    1.80 +  "ALLOW_URI_AUTHORITY",
    1.81 +#endif
    1.82 +#ifdef SQLITE_BITMASK_TYPE
    1.83 +  "BITMASK_TYPE=" CTIMEOPT_VAL(SQLITE_BITMASK_TYPE),
    1.84 +#endif
    1.85 +#if SQLITE_BUG_COMPATIBLE_20160819
    1.86 +  "BUG_COMPATIBLE_20160819",
    1.87 +#endif
    1.88 +#if SQLITE_CASE_SENSITIVE_LIKE
    1.89 +  "CASE_SENSITIVE_LIKE",
    1.90 +#endif
    1.91 +#if SQLITE_CHECK_PAGES
    1.92 +  "CHECK_PAGES",
    1.93 +#endif
    1.94 +#if defined(__clang__) && defined(__clang_major__)
    1.95 +  "COMPILER=clang-" CTIMEOPT_VAL(__clang_major__) "."
    1.96 +                    CTIMEOPT_VAL(__clang_minor__) "."
    1.97 +                    CTIMEOPT_VAL(__clang_patchlevel__),
    1.98 +#elif defined(_MSC_VER)
    1.99 +  "COMPILER=msvc-" CTIMEOPT_VAL(_MSC_VER),
   1.100 +#elif defined(__GNUC__) && defined(__VERSION__)
   1.101 +  "COMPILER=gcc-" __VERSION__,
   1.102 +#endif
   1.103 +#if SQLITE_COVERAGE_TEST
   1.104 +  "COVERAGE_TEST",
   1.105 +#endif
   1.106 +#if SQLITE_DEBUG
   1.107 +  "DEBUG",
   1.108 +#endif
   1.109 +#if SQLITE_DEFAULT_AUTOMATIC_INDEX
   1.110 +  "DEFAULT_AUTOMATIC_INDEX",
   1.111 +#endif
   1.112 +#if SQLITE_DEFAULT_AUTOVACUUM
   1.113 +  "DEFAULT_AUTOVACUUM",
   1.114 +#endif
   1.115 +#ifdef SQLITE_DEFAULT_CACHE_SIZE
   1.116 +  "DEFAULT_CACHE_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_CACHE_SIZE),
   1.117 +#endif
   1.118 +#if SQLITE_DEFAULT_CKPTFULLFSYNC
   1.119 +  "DEFAULT_CKPTFULLFSYNC",
   1.120 +#endif
   1.121 +#ifdef SQLITE_DEFAULT_FILE_FORMAT
   1.122 +  "DEFAULT_FILE_FORMAT=" CTIMEOPT_VAL(SQLITE_DEFAULT_FILE_FORMAT),
   1.123 +#endif
   1.124 +#ifdef SQLITE_DEFAULT_FILE_PERMISSIONS
   1.125 +  "DEFAULT_FILE_PERMISSIONS=" CTIMEOPT_VAL(SQLITE_DEFAULT_FILE_PERMISSIONS),
   1.126 +#endif
   1.127 +#if SQLITE_DEFAULT_FOREIGN_KEYS
   1.128 +  "DEFAULT_FOREIGN_KEYS",
   1.129 +#endif
   1.130 +#ifdef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT
   1.131 +  "DEFAULT_JOURNAL_SIZE_LIMIT=" CTIMEOPT_VAL(SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT),
   1.132 +#endif
   1.133 +#ifdef SQLITE_DEFAULT_LOCKING_MODE
   1.134 +  "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE),
   1.135 +#endif
   1.136 +#ifdef SQLITE_DEFAULT_LOOKASIDE
   1.137 +  "DEFAULT_LOOKASIDE=" CTIMEOPT_VAL2(SQLITE_DEFAULT_LOOKASIDE),
   1.138 +#endif
   1.139 +#if SQLITE_DEFAULT_MEMSTATUS
   1.140 +  "DEFAULT_MEMSTATUS",
   1.141 +#endif
   1.142 +#ifdef SQLITE_DEFAULT_MMAP_SIZE
   1.143 +  "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE),
   1.144 +#endif
   1.145 +#ifdef SQLITE_DEFAULT_PAGE_SIZE
   1.146 +  "DEFAULT_PAGE_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_PAGE_SIZE),
   1.147 +#endif
   1.148 +#ifdef SQLITE_DEFAULT_PCACHE_INITSZ
   1.149 +  "DEFAULT_PCACHE_INITSZ=" CTIMEOPT_VAL(SQLITE_DEFAULT_PCACHE_INITSZ),
   1.150 +#endif
   1.151 +#ifdef SQLITE_DEFAULT_PROXYDIR_PERMISSIONS
   1.152 +  "DEFAULT_PROXYDIR_PERMISSIONS=" CTIMEOPT_VAL(SQLITE_DEFAULT_PROXYDIR_PERMISSIONS),
   1.153 +#endif
   1.154 +#if SQLITE_DEFAULT_RECURSIVE_TRIGGERS
   1.155 +  "DEFAULT_RECURSIVE_TRIGGERS",
   1.156 +#endif
   1.157 +#ifdef SQLITE_DEFAULT_ROWEST
   1.158 +  "DEFAULT_ROWEST=" CTIMEOPT_VAL(SQLITE_DEFAULT_ROWEST),
   1.159 +#endif
   1.160 +#ifdef SQLITE_DEFAULT_SECTOR_SIZE
   1.161 +  "DEFAULT_SECTOR_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_SECTOR_SIZE),
   1.162 +#endif
   1.163 +#ifdef SQLITE_DEFAULT_SYNCHRONOUS
   1.164 +  "DEFAULT_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_SYNCHRONOUS),
   1.165 +#endif
   1.166 +#ifdef SQLITE_DEFAULT_WAL_AUTOCHECKPOINT
   1.167 +  "DEFAULT_WAL_AUTOCHECKPOINT=" CTIMEOPT_VAL(SQLITE_DEFAULT_WAL_AUTOCHECKPOINT),
   1.168 +#endif
   1.169 +#ifdef SQLITE_DEFAULT_WAL_SYNCHRONOUS
   1.170 +  "DEFAULT_WAL_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_WAL_SYNCHRONOUS),
   1.171 +#endif
   1.172 +#ifdef SQLITE_DEFAULT_WORKER_THREADS
   1.173 +  "DEFAULT_WORKER_THREADS=" CTIMEOPT_VAL(SQLITE_DEFAULT_WORKER_THREADS),
   1.174 +#endif
   1.175 +#if SQLITE_DIRECT_OVERFLOW_READ
   1.176 +  "DIRECT_OVERFLOW_READ",
   1.177 +#endif
   1.178 +#if SQLITE_DISABLE_DIRSYNC
   1.179 +  "DISABLE_DIRSYNC",
   1.180 +#endif
   1.181 +#if SQLITE_DISABLE_FTS3_UNICODE
   1.182 +  "DISABLE_FTS3_UNICODE",
   1.183 +#endif
   1.184 +#if SQLITE_DISABLE_FTS4_DEFERRED
   1.185 +  "DISABLE_FTS4_DEFERRED",
   1.186 +#endif
   1.187 +#if SQLITE_DISABLE_INTRINSIC
   1.188 +  "DISABLE_INTRINSIC",
   1.189 +#endif
   1.190 +#if SQLITE_DISABLE_LFS
   1.191 +  "DISABLE_LFS",
   1.192 +#endif
   1.193 +#if SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
   1.194 +  "DISABLE_PAGECACHE_OVERFLOW_STATS",
   1.195 +#endif
   1.196 +#if SQLITE_DISABLE_SKIPAHEAD_DISTINCT
   1.197 +  "DISABLE_SKIPAHEAD_DISTINCT",
   1.198 +#endif
   1.199 +#ifdef SQLITE_ENABLE_8_3_NAMES
   1.200 +  "ENABLE_8_3_NAMES=" CTIMEOPT_VAL(SQLITE_ENABLE_8_3_NAMES),
   1.201 +#endif
   1.202 +#if SQLITE_ENABLE_API_ARMOR
   1.203 +  "ENABLE_API_ARMOR",
   1.204 +#endif
   1.205 +#if SQLITE_ENABLE_ATOMIC_WRITE
   1.206 +  "ENABLE_ATOMIC_WRITE",
   1.207 +#endif
   1.208 +#if SQLITE_ENABLE_BATCH_ATOMIC_WRITE
   1.209 +  "ENABLE_BATCH_ATOMIC_WRITE",
   1.210 +#endif
   1.211 +#if SQLITE_ENABLE_CEROD
   1.212 +  "ENABLE_CEROD=" CTIMEOPT_VAL(SQLITE_ENABLE_CEROD),
   1.213 +#endif
   1.214 +#if SQLITE_ENABLE_COLUMN_METADATA
   1.215 +  "ENABLE_COLUMN_METADATA",
   1.216 +#endif
   1.217 +#if SQLITE_ENABLE_COLUMN_USED_MASK
   1.218 +  "ENABLE_COLUMN_USED_MASK",
   1.219 +#endif
   1.220 +#if SQLITE_ENABLE_COSTMULT
   1.221 +  "ENABLE_COSTMULT",
   1.222 +#endif
   1.223 +#if SQLITE_ENABLE_CURSOR_HINTS
   1.224 +  "ENABLE_CURSOR_HINTS",
   1.225 +#endif
   1.226 +#if SQLITE_ENABLE_DBSTAT_VTAB
   1.227 +  "ENABLE_DBSTAT_VTAB",
   1.228 +#endif
   1.229 +#if SQLITE_ENABLE_EXPENSIVE_ASSERT
   1.230 +  "ENABLE_EXPENSIVE_ASSERT",
   1.231 +#endif
   1.232 +#if SQLITE_ENABLE_FTS1
   1.233 +  "ENABLE_FTS1",
   1.234 +#endif
   1.235 +#if SQLITE_ENABLE_FTS2
   1.236 +  "ENABLE_FTS2",
   1.237 +#endif
   1.238 +#if SQLITE_ENABLE_FTS3
   1.239 +  "ENABLE_FTS3",
   1.240 +#endif
   1.241 +#if SQLITE_ENABLE_FTS3_PARENTHESIS
   1.242 +  "ENABLE_FTS3_PARENTHESIS",
   1.243 +#endif
   1.244 +#if SQLITE_ENABLE_FTS3_TOKENIZER
   1.245 +  "ENABLE_FTS3_TOKENIZER",
   1.246 +#endif
   1.247 +#if SQLITE_ENABLE_FTS4
   1.248 +  "ENABLE_FTS4",
   1.249 +#endif
   1.250 +#if SQLITE_ENABLE_FTS5
   1.251 +  "ENABLE_FTS5",
   1.252 +#endif
   1.253 +#if SQLITE_ENABLE_GEOPOLY
   1.254 +  "ENABLE_GEOPOLY",
   1.255 +#endif
   1.256 +#if SQLITE_ENABLE_HIDDEN_COLUMNS
   1.257 +  "ENABLE_HIDDEN_COLUMNS",
   1.258 +#endif
   1.259 +#if SQLITE_ENABLE_ICU
   1.260 +  "ENABLE_ICU",
   1.261 +#endif
   1.262 +#if SQLITE_ENABLE_IOTRACE
   1.263 +  "ENABLE_IOTRACE",
   1.264 +#endif
   1.265 +#if SQLITE_ENABLE_JSON1
   1.266 +  "ENABLE_JSON1",
   1.267 +#endif
   1.268 +#if SQLITE_ENABLE_LOAD_EXTENSION
   1.269 +  "ENABLE_LOAD_EXTENSION",
   1.270 +#endif
   1.271 +#ifdef SQLITE_ENABLE_LOCKING_STYLE
   1.272 +  "ENABLE_LOCKING_STYLE=" CTIMEOPT_VAL(SQLITE_ENABLE_LOCKING_STYLE),
   1.273 +#endif
   1.274 +#if SQLITE_ENABLE_MEMORY_MANAGEMENT
   1.275 +  "ENABLE_MEMORY_MANAGEMENT",
   1.276 +#endif
   1.277 +#if SQLITE_ENABLE_MEMSYS3
   1.278 +  "ENABLE_MEMSYS3",
   1.279 +#endif
   1.280 +#if SQLITE_ENABLE_MEMSYS5
   1.281 +  "ENABLE_MEMSYS5",
   1.282 +#endif
   1.283 +#if SQLITE_ENABLE_MULTIPLEX
   1.284 +  "ENABLE_MULTIPLEX",
   1.285 +#endif
   1.286 +#if SQLITE_ENABLE_NORMALIZE
   1.287 +  "ENABLE_NORMALIZE",
   1.288 +#endif
   1.289 +#if SQLITE_ENABLE_NULL_TRIM
   1.290 +  "ENABLE_NULL_TRIM",
   1.291 +#endif
   1.292 +#if SQLITE_ENABLE_OVERSIZE_CELL_CHECK
   1.293 +  "ENABLE_OVERSIZE_CELL_CHECK",
   1.294 +#endif
   1.295 +#if SQLITE_ENABLE_PREUPDATE_HOOK
   1.296 +  "ENABLE_PREUPDATE_HOOK",
   1.297 +#endif
   1.298 +#if SQLITE_ENABLE_QPSG
   1.299 +  "ENABLE_QPSG",
   1.300 +#endif
   1.301 +#if SQLITE_ENABLE_RBU
   1.302 +  "ENABLE_RBU",
   1.303 +#endif
   1.304 +#if SQLITE_ENABLE_RTREE
   1.305 +  "ENABLE_RTREE",
   1.306 +#endif
   1.307 +#if SQLITE_ENABLE_SELECTTRACE
   1.308 +  "ENABLE_SELECTTRACE",
   1.309 +#endif
   1.310 +#if SQLITE_ENABLE_SESSION
   1.311 +  "ENABLE_SESSION",
   1.312 +#endif
   1.313 +#if SQLITE_ENABLE_SNAPSHOT
   1.314 +  "ENABLE_SNAPSHOT",
   1.315 +#endif
   1.316 +#if SQLITE_ENABLE_SORTER_REFERENCES
   1.317 +  "ENABLE_SORTER_REFERENCES",
   1.318 +#endif
   1.319 +#if SQLITE_ENABLE_SQLLOG
   1.320 +  "ENABLE_SQLLOG",
   1.321 +#endif
   1.322 +#if defined(SQLITE_ENABLE_STAT4)
   1.323 +  "ENABLE_STAT4",
   1.324 +#elif defined(SQLITE_ENABLE_STAT3)
   1.325 +  "ENABLE_STAT3",
   1.326 +#endif
   1.327 +#if SQLITE_ENABLE_STMTVTAB
   1.328 +  "ENABLE_STMTVTAB",
   1.329 +#endif
   1.330 +#if SQLITE_ENABLE_STMT_SCANSTATUS
   1.331 +  "ENABLE_STMT_SCANSTATUS",
   1.332 +#endif
   1.333 +#if SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
   1.334 +  "ENABLE_UNKNOWN_SQL_FUNCTION",
   1.335 +#endif
   1.336 +#if SQLITE_ENABLE_UNLOCK_NOTIFY
   1.337 +  "ENABLE_UNLOCK_NOTIFY",
   1.338 +#endif
   1.339 +#if SQLITE_ENABLE_UPDATE_DELETE_LIMIT
   1.340 +  "ENABLE_UPDATE_DELETE_LIMIT",
   1.341 +#endif
   1.342 +#if SQLITE_ENABLE_URI_00_ERROR
   1.343 +  "ENABLE_URI_00_ERROR",
   1.344 +#endif
   1.345 +#if SQLITE_ENABLE_VFSTRACE
   1.346 +  "ENABLE_VFSTRACE",
   1.347 +#endif
   1.348 +#if SQLITE_ENABLE_WHERETRACE
   1.349 +  "ENABLE_WHERETRACE",
   1.350 +#endif
   1.351 +#if SQLITE_ENABLE_ZIPVFS
   1.352 +  "ENABLE_ZIPVFS",
   1.353 +#endif
   1.354 +#if SQLITE_EXPLAIN_ESTIMATED_ROWS
   1.355 +  "EXPLAIN_ESTIMATED_ROWS",
   1.356 +#endif
   1.357 +#if SQLITE_EXTRA_IFNULLROW
   1.358 +  "EXTRA_IFNULLROW",
   1.359 +#endif
   1.360 +#ifdef SQLITE_EXTRA_INIT
   1.361 +  "EXTRA_INIT=" CTIMEOPT_VAL(SQLITE_EXTRA_INIT),
   1.362 +#endif
   1.363 +#ifdef SQLITE_EXTRA_SHUTDOWN
   1.364 +  "EXTRA_SHUTDOWN=" CTIMEOPT_VAL(SQLITE_EXTRA_SHUTDOWN),
   1.365 +#endif
   1.366 +#ifdef SQLITE_FTS3_MAX_EXPR_DEPTH
   1.367 +  "FTS3_MAX_EXPR_DEPTH=" CTIMEOPT_VAL(SQLITE_FTS3_MAX_EXPR_DEPTH),
   1.368 +#endif
   1.369 +#if SQLITE_FTS5_ENABLE_TEST_MI
   1.370 +  "FTS5_ENABLE_TEST_MI",
   1.371 +#endif
   1.372 +#if SQLITE_FTS5_NO_WITHOUT_ROWID
   1.373 +  "FTS5_NO_WITHOUT_ROWID",
   1.374 +#endif
   1.375 +#if SQLITE_HAS_CODEC
   1.376 +  "HAS_CODEC",
   1.377 +#endif
   1.378 +#if HAVE_ISNAN || SQLITE_HAVE_ISNAN
   1.379 +  "HAVE_ISNAN",
   1.380 +#endif
   1.381 +#if SQLITE_HOMEGROWN_RECURSIVE_MUTEX
   1.382 +  "HOMEGROWN_RECURSIVE_MUTEX",
   1.383 +#endif
   1.384 +#if SQLITE_IGNORE_AFP_LOCK_ERRORS
   1.385 +  "IGNORE_AFP_LOCK_ERRORS",
   1.386 +#endif
   1.387 +#if SQLITE_IGNORE_FLOCK_LOCK_ERRORS
   1.388 +  "IGNORE_FLOCK_LOCK_ERRORS",
   1.389 +#endif
   1.390 +#if SQLITE_INLINE_MEMCPY
   1.391 +  "INLINE_MEMCPY",
   1.392 +#endif
   1.393 +#if SQLITE_INT64_TYPE
   1.394 +  "INT64_TYPE",
   1.395 +#endif
   1.396 +#ifdef SQLITE_INTEGRITY_CHECK_ERROR_MAX
   1.397 +  "INTEGRITY_CHECK_ERROR_MAX=" CTIMEOPT_VAL(SQLITE_INTEGRITY_CHECK_ERROR_MAX),
   1.398 +#endif
   1.399 +#if SQLITE_LIKE_DOESNT_MATCH_BLOBS
   1.400 +  "LIKE_DOESNT_MATCH_BLOBS",
   1.401 +#endif
   1.402 +#if SQLITE_LOCK_TRACE
   1.403 +  "LOCK_TRACE",
   1.404 +#endif
   1.405 +#if SQLITE_LOG_CACHE_SPILL
   1.406 +  "LOG_CACHE_SPILL",
   1.407 +#endif
   1.408 +#ifdef SQLITE_MALLOC_SOFT_LIMIT
   1.409 +  "MALLOC_SOFT_LIMIT=" CTIMEOPT_VAL(SQLITE_MALLOC_SOFT_LIMIT),
   1.410 +#endif
   1.411 +#ifdef SQLITE_MAX_ATTACHED
   1.412 +  "MAX_ATTACHED=" CTIMEOPT_VAL(SQLITE_MAX_ATTACHED),
   1.413 +#endif
   1.414 +#ifdef SQLITE_MAX_COLUMN
   1.415 +  "MAX_COLUMN=" CTIMEOPT_VAL(SQLITE_MAX_COLUMN),
   1.416 +#endif
   1.417 +#ifdef SQLITE_MAX_COMPOUND_SELECT
   1.418 +  "MAX_COMPOUND_SELECT=" CTIMEOPT_VAL(SQLITE_MAX_COMPOUND_SELECT),
   1.419 +#endif
   1.420 +#ifdef SQLITE_MAX_DEFAULT_PAGE_SIZE
   1.421 +  "MAX_DEFAULT_PAGE_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_DEFAULT_PAGE_SIZE),
   1.422 +#endif
   1.423 +#ifdef SQLITE_MAX_EXPR_DEPTH
   1.424 +  "MAX_EXPR_DEPTH=" CTIMEOPT_VAL(SQLITE_MAX_EXPR_DEPTH),
   1.425 +#endif
   1.426 +#ifdef SQLITE_MAX_FUNCTION_ARG
   1.427 +  "MAX_FUNCTION_ARG=" CTIMEOPT_VAL(SQLITE_MAX_FUNCTION_ARG),
   1.428 +#endif
   1.429 +#ifdef SQLITE_MAX_LENGTH
   1.430 +  "MAX_LENGTH=" CTIMEOPT_VAL(SQLITE_MAX_LENGTH),
   1.431 +#endif
   1.432 +#ifdef SQLITE_MAX_LIKE_PATTERN_LENGTH
   1.433 +  "MAX_LIKE_PATTERN_LENGTH=" CTIMEOPT_VAL(SQLITE_MAX_LIKE_PATTERN_LENGTH),
   1.434 +#endif
   1.435 +#ifdef SQLITE_MAX_MEMORY
   1.436 +  "MAX_MEMORY=" CTIMEOPT_VAL(SQLITE_MAX_MEMORY),
   1.437 +#endif
   1.438 +#ifdef SQLITE_MAX_MMAP_SIZE
   1.439 +  "MAX_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE),
   1.440 +#endif
   1.441 +#ifdef SQLITE_MAX_MMAP_SIZE_
   1.442 +  "MAX_MMAP_SIZE_=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE_),
   1.443 +#endif
   1.444 +#ifdef SQLITE_MAX_PAGE_COUNT
   1.445 +  "MAX_PAGE_COUNT=" CTIMEOPT_VAL(SQLITE_MAX_PAGE_COUNT),
   1.446 +#endif
   1.447 +#ifdef SQLITE_MAX_PAGE_SIZE
   1.448 +  "MAX_PAGE_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_PAGE_SIZE),
   1.449 +#endif
   1.450 +#ifdef SQLITE_MAX_SCHEMA_RETRY
   1.451 +  "MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY),
   1.452 +#endif
   1.453 +#ifdef SQLITE_MAX_SQL_LENGTH
   1.454 +  "MAX_SQL_LENGTH=" CTIMEOPT_VAL(SQLITE_MAX_SQL_LENGTH),
   1.455 +#endif
   1.456 +#ifdef SQLITE_MAX_TRIGGER_DEPTH
   1.457 +  "MAX_TRIGGER_DEPTH=" CTIMEOPT_VAL(SQLITE_MAX_TRIGGER_DEPTH),
   1.458 +#endif
   1.459 +#ifdef SQLITE_MAX_VARIABLE_NUMBER
   1.460 +  "MAX_VARIABLE_NUMBER=" CTIMEOPT_VAL(SQLITE_MAX_VARIABLE_NUMBER),
   1.461 +#endif
   1.462 +#ifdef SQLITE_MAX_VDBE_OP
   1.463 +  "MAX_VDBE_OP=" CTIMEOPT_VAL(SQLITE_MAX_VDBE_OP),
   1.464 +#endif
   1.465 +#ifdef SQLITE_MAX_WORKER_THREADS
   1.466 +  "MAX_WORKER_THREADS=" CTIMEOPT_VAL(SQLITE_MAX_WORKER_THREADS),
   1.467 +#endif
   1.468 +#if SQLITE_MEMDEBUG
   1.469 +  "MEMDEBUG",
   1.470 +#endif
   1.471 +#if SQLITE_MIXED_ENDIAN_64BIT_FLOAT
   1.472 +  "MIXED_ENDIAN_64BIT_FLOAT",
   1.473 +#endif
   1.474 +#if SQLITE_MMAP_READWRITE
   1.475 +  "MMAP_READWRITE",
   1.476 +#endif
   1.477 +#if SQLITE_MUTEX_NOOP
   1.478 +  "MUTEX_NOOP",
   1.479 +#endif
   1.480 +#if SQLITE_MUTEX_NREF
   1.481 +  "MUTEX_NREF",
   1.482 +#endif
   1.483 +#if SQLITE_MUTEX_OMIT
   1.484 +  "MUTEX_OMIT",
   1.485 +#endif
   1.486 +#if SQLITE_MUTEX_PTHREADS
   1.487 +  "MUTEX_PTHREADS",
   1.488 +#endif
   1.489 +#if SQLITE_MUTEX_W32
   1.490 +  "MUTEX_W32",
   1.491 +#endif
   1.492 +#if SQLITE_NEED_ERR_NAME
   1.493 +  "NEED_ERR_NAME",
   1.494 +#endif
   1.495 +#if SQLITE_NOINLINE
   1.496 +  "NOINLINE",
   1.497 +#endif
   1.498 +#if SQLITE_NO_SYNC
   1.499 +  "NO_SYNC",
   1.500 +#endif
   1.501 +#if SQLITE_OMIT_ALTERTABLE
   1.502 +  "OMIT_ALTERTABLE",
   1.503 +#endif
   1.504 +#if SQLITE_OMIT_ANALYZE
   1.505 +  "OMIT_ANALYZE",
   1.506 +#endif
   1.507 +#if SQLITE_OMIT_ATTACH
   1.508 +  "OMIT_ATTACH",
   1.509 +#endif
   1.510 +#if SQLITE_OMIT_AUTHORIZATION
   1.511 +  "OMIT_AUTHORIZATION",
   1.512 +#endif
   1.513 +#if SQLITE_OMIT_AUTOINCREMENT
   1.514 +  "OMIT_AUTOINCREMENT",
   1.515 +#endif
   1.516 +#if SQLITE_OMIT_AUTOINIT
   1.517 +  "OMIT_AUTOINIT",
   1.518 +#endif
   1.519 +#if SQLITE_OMIT_AUTOMATIC_INDEX
   1.520 +  "OMIT_AUTOMATIC_INDEX",
   1.521 +#endif
   1.522 +#if SQLITE_OMIT_AUTORESET
   1.523 +  "OMIT_AUTORESET",
   1.524 +#endif
   1.525 +#if SQLITE_OMIT_AUTOVACUUM
   1.526 +  "OMIT_AUTOVACUUM",
   1.527 +#endif
   1.528 +#if SQLITE_OMIT_BETWEEN_OPTIMIZATION
   1.529 +  "OMIT_BETWEEN_OPTIMIZATION",
   1.530 +#endif
   1.531 +#if SQLITE_OMIT_BLOB_LITERAL
   1.532 +  "OMIT_BLOB_LITERAL",
   1.533 +#endif
   1.534 +#if SQLITE_OMIT_BTREECOUNT
   1.535 +  "OMIT_BTREECOUNT",
   1.536 +#endif
   1.537 +#if SQLITE_OMIT_CAST
   1.538 +  "OMIT_CAST",
   1.539 +#endif
   1.540 +#if SQLITE_OMIT_CHECK
   1.541 +  "OMIT_CHECK",
   1.542 +#endif
   1.543 +#if SQLITE_OMIT_COMPLETE
   1.544 +  "OMIT_COMPLETE",
   1.545 +#endif
   1.546 +#if SQLITE_OMIT_COMPOUND_SELECT
   1.547 +  "OMIT_COMPOUND_SELECT",
   1.548 +#endif
   1.549 +#if SQLITE_OMIT_CONFLICT_CLAUSE
   1.550 +  "OMIT_CONFLICT_CLAUSE",
   1.551 +#endif
   1.552 +#if SQLITE_OMIT_CTE
   1.553 +  "OMIT_CTE",
   1.554 +#endif
   1.555 +#if SQLITE_OMIT_DATETIME_FUNCS
   1.556 +  "OMIT_DATETIME_FUNCS",
   1.557 +#endif
   1.558 +#if SQLITE_OMIT_DECLTYPE
   1.559 +  "OMIT_DECLTYPE",
   1.560 +#endif
   1.561 +#if SQLITE_OMIT_DEPRECATED
   1.562 +  "OMIT_DEPRECATED",
   1.563 +#endif
   1.564 +#if SQLITE_OMIT_DISKIO
   1.565 +  "OMIT_DISKIO",
   1.566 +#endif
   1.567 +#if SQLITE_OMIT_EXPLAIN
   1.568 +  "OMIT_EXPLAIN",
   1.569 +#endif
   1.570 +#if SQLITE_OMIT_FLAG_PRAGMAS
   1.571 +  "OMIT_FLAG_PRAGMAS",
   1.572 +#endif
   1.573 +#if SQLITE_OMIT_FLOATING_POINT
   1.574 +  "OMIT_FLOATING_POINT",
   1.575 +#endif
   1.576 +#if SQLITE_OMIT_FOREIGN_KEY
   1.577 +  "OMIT_FOREIGN_KEY",
   1.578 +#endif
   1.579 +#if SQLITE_OMIT_GET_TABLE
   1.580 +  "OMIT_GET_TABLE",
   1.581 +#endif
   1.582 +#if SQLITE_OMIT_HEX_INTEGER
   1.583 +  "OMIT_HEX_INTEGER",
   1.584 +#endif
   1.585 +#if SQLITE_OMIT_INCRBLOB
   1.586 +  "OMIT_INCRBLOB",
   1.587 +#endif
   1.588 +#if SQLITE_OMIT_INTEGRITY_CHECK
   1.589 +  "OMIT_INTEGRITY_CHECK",
   1.590 +#endif
   1.591 +#if SQLITE_OMIT_LIKE_OPTIMIZATION
   1.592 +  "OMIT_LIKE_OPTIMIZATION",
   1.593 +#endif
   1.594 +#if SQLITE_OMIT_LOAD_EXTENSION
   1.595 +  "OMIT_LOAD_EXTENSION",
   1.596 +#endif
   1.597 +#if SQLITE_OMIT_LOCALTIME
   1.598 +  "OMIT_LOCALTIME",
   1.599 +#endif
   1.600 +#if SQLITE_OMIT_LOOKASIDE
   1.601 +  "OMIT_LOOKASIDE",
   1.602 +#endif
   1.603 +#if SQLITE_OMIT_MEMORYDB
   1.604 +  "OMIT_MEMORYDB",
   1.605 +#endif
   1.606 +#if SQLITE_OMIT_OR_OPTIMIZATION
   1.607 +  "OMIT_OR_OPTIMIZATION",
   1.608 +#endif
   1.609 +#if SQLITE_OMIT_PAGER_PRAGMAS
   1.610 +  "OMIT_PAGER_PRAGMAS",
   1.611 +#endif
   1.612 +#if SQLITE_OMIT_PARSER_TRACE
   1.613 +  "OMIT_PARSER_TRACE",
   1.614 +#endif
   1.615 +#if SQLITE_OMIT_POPEN
   1.616 +  "OMIT_POPEN",
   1.617 +#endif
   1.618 +#if SQLITE_OMIT_PRAGMA
   1.619 +  "OMIT_PRAGMA",
   1.620 +#endif
   1.621 +#if SQLITE_OMIT_PROGRESS_CALLBACK
   1.622 +  "OMIT_PROGRESS_CALLBACK",
   1.623 +#endif
   1.624 +#if SQLITE_OMIT_QUICKBALANCE
   1.625 +  "OMIT_QUICKBALANCE",
   1.626 +#endif
   1.627 +#if SQLITE_OMIT_REINDEX
   1.628 +  "OMIT_REINDEX",
   1.629 +#endif
   1.630 +#if SQLITE_OMIT_SCHEMA_PRAGMAS
   1.631 +  "OMIT_SCHEMA_PRAGMAS",
   1.632 +#endif
   1.633 +#if SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
   1.634 +  "OMIT_SCHEMA_VERSION_PRAGMAS",
   1.635 +#endif
   1.636 +#if SQLITE_OMIT_SHARED_CACHE
   1.637 +  "OMIT_SHARED_CACHE",
   1.638 +#endif
   1.639 +#if SQLITE_OMIT_SHUTDOWN_DIRECTORIES
   1.640 +  "OMIT_SHUTDOWN_DIRECTORIES",
   1.641 +#endif
   1.642 +#if SQLITE_OMIT_SUBQUERY
   1.643 +  "OMIT_SUBQUERY",
   1.644 +#endif
   1.645 +#if SQLITE_OMIT_TCL_VARIABLE
   1.646 +  "OMIT_TCL_VARIABLE",
   1.647 +#endif
   1.648 +#if SQLITE_OMIT_TEMPDB
   1.649 +  "OMIT_TEMPDB",
   1.650 +#endif
   1.651 +#if SQLITE_OMIT_TEST_CONTROL
   1.652 +  "OMIT_TEST_CONTROL",
   1.653 +#endif
   1.654 +#if SQLITE_OMIT_TRACE
   1.655 +  "OMIT_TRACE",
   1.656 +#endif
   1.657 +#if SQLITE_OMIT_TRIGGER
   1.658 +  "OMIT_TRIGGER",
   1.659 +#endif
   1.660 +#if SQLITE_OMIT_TRUNCATE_OPTIMIZATION
   1.661 +  "OMIT_TRUNCATE_OPTIMIZATION",
   1.662 +#endif
   1.663 +#if SQLITE_OMIT_UTF16
   1.664 +  "OMIT_UTF16",
   1.665 +#endif
   1.666 +#if SQLITE_OMIT_VACUUM
   1.667 +  "OMIT_VACUUM",
   1.668 +#endif
   1.669 +#if SQLITE_OMIT_VIEW
   1.670 +  "OMIT_VIEW",
   1.671 +#endif
   1.672 +#if SQLITE_OMIT_VIRTUALTABLE
   1.673 +  "OMIT_VIRTUALTABLE",
   1.674 +#endif
   1.675 +#if SQLITE_OMIT_WAL
   1.676 +  "OMIT_WAL",
   1.677 +#endif
   1.678 +#if SQLITE_OMIT_WSD
   1.679 +  "OMIT_WSD",
   1.680 +#endif
   1.681 +#if SQLITE_OMIT_XFER_OPT
   1.682 +  "OMIT_XFER_OPT",
   1.683 +#endif
   1.684 +#if SQLITE_PCACHE_SEPARATE_HEADER
   1.685 +  "PCACHE_SEPARATE_HEADER",
   1.686 +#endif
   1.687 +#if SQLITE_PERFORMANCE_TRACE
   1.688 +  "PERFORMANCE_TRACE",
   1.689 +#endif
   1.690 +#if SQLITE_POWERSAFE_OVERWRITE
   1.691 +  "POWERSAFE_OVERWRITE",
   1.692 +#endif
   1.693 +#if SQLITE_PREFER_PROXY_LOCKING
   1.694 +  "PREFER_PROXY_LOCKING",
   1.695 +#endif
   1.696 +#if SQLITE_PROXY_DEBUG
   1.697 +  "PROXY_DEBUG",
   1.698 +#endif
   1.699 +#if SQLITE_REVERSE_UNORDERED_SELECTS
   1.700 +  "REVERSE_UNORDERED_SELECTS",
   1.701 +#endif
   1.702 +#if SQLITE_RTREE_INT_ONLY
   1.703 +  "RTREE_INT_ONLY",
   1.704 +#endif
   1.705 +#if SQLITE_SECURE_DELETE
   1.706 +  "SECURE_DELETE",
   1.707 +#endif
   1.708 +#if SQLITE_SMALL_STACK
   1.709 +  "SMALL_STACK",
   1.710 +#endif
   1.711 +#ifdef SQLITE_SORTER_PMASZ
   1.712 +  "SORTER_PMASZ=" CTIMEOPT_VAL(SQLITE_SORTER_PMASZ),
   1.713 +#endif
   1.714 +#if SQLITE_SOUNDEX
   1.715 +  "SOUNDEX",
   1.716 +#endif
   1.717 +#ifdef SQLITE_STAT4_SAMPLES
   1.718 +  "STAT4_SAMPLES=" CTIMEOPT_VAL(SQLITE_STAT4_SAMPLES),
   1.719 +#endif
   1.720 +#ifdef SQLITE_STMTJRNL_SPILL
   1.721 +  "STMTJRNL_SPILL=" CTIMEOPT_VAL(SQLITE_STMTJRNL_SPILL),
   1.722 +#endif
   1.723 +#if SQLITE_SUBSTR_COMPATIBILITY
   1.724 +  "SUBSTR_COMPATIBILITY",
   1.725 +#endif
   1.726 +#if SQLITE_SYSTEM_MALLOC
   1.727 +  "SYSTEM_MALLOC",
   1.728 +#endif
   1.729 +#if SQLITE_TCL
   1.730 +  "TCL",
   1.731 +#endif
   1.732 +#ifdef SQLITE_TEMP_STORE
   1.733 +  "TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE),
   1.734 +#endif
   1.735 +#if SQLITE_TEST
   1.736 +  "TEST",
   1.737 +#endif
   1.738 +#if defined(SQLITE_THREADSAFE)
   1.739 +  "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
   1.740 +#elif defined(THREADSAFE)
   1.741 +  "THREADSAFE=" CTIMEOPT_VAL(THREADSAFE),
   1.742 +#else
   1.743 +  "THREADSAFE=1",
   1.744 +#endif
   1.745 +#if SQLITE_UNLINK_AFTER_CLOSE
   1.746 +  "UNLINK_AFTER_CLOSE",
   1.747 +#endif
   1.748 +#if SQLITE_UNTESTABLE
   1.749 +  "UNTESTABLE",
   1.750 +#endif
   1.751 +#if SQLITE_USER_AUTHENTICATION
   1.752 +  "USER_AUTHENTICATION",
   1.753 +#endif
   1.754 +#if SQLITE_USE_ALLOCA
   1.755 +  "USE_ALLOCA",
   1.756 +#endif
   1.757 +#if SQLITE_USE_FCNTL_TRACE
   1.758 +  "USE_FCNTL_TRACE",
   1.759 +#endif
   1.760 +#if SQLITE_USE_URI
   1.761 +  "USE_URI",
   1.762 +#endif
   1.763 +#if SQLITE_VDBE_COVERAGE
   1.764 +  "VDBE_COVERAGE",
   1.765 +#endif
   1.766 +#if SQLITE_WIN32_MALLOC
   1.767 +  "WIN32_MALLOC",
   1.768 +#endif
   1.769 +#if SQLITE_ZERO_MALLOC
   1.770 +  "ZERO_MALLOC",
   1.771 +#endif
   1.772 +/* 
   1.773 +** END CODE GENERATED BY tool/mkctime.tcl 
   1.774 +*/
   1.775 +};
   1.776 +
   1.777 +SQLITE_PRIVATE const char **sqlite3CompileOptions(int *pnOpt){
   1.778 +  *pnOpt = sizeof(sqlite3azCompileOpt) / sizeof(sqlite3azCompileOpt[0]);
   1.779 +  return (const char**)sqlite3azCompileOpt;
   1.780 +}
   1.781 +
   1.782 +#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
   1.783 +
   1.784 +/************** End of ctime.c ***********************************************/
   1.785  /************** Begin file sqliteInt.h ***************************************/
   1.786  /*
   1.787  ** 2001 September 15
   1.788 @@ -76,14 +846,6 @@
   1.789  #endif
   1.790  
   1.791  /*
   1.792 -** Make sure that rand_s() is available on Windows systems with MSVC 2005
   1.793 -** or higher.
   1.794 -*/
   1.795 -#if defined(_MSC_VER) && _MSC_VER>=1400
   1.796 -#  define _CRT_RAND_S
   1.797 -#endif
   1.798 -
   1.799 -/*
   1.800  ** Include the header file used to customize the compiler options for MSVC.
   1.801  ** This should be done first so that it can successfully prevent spurious
   1.802  ** compiler warnings due to subsequent content in this file and other files
   1.803 @@ -276,7 +1038,7 @@
   1.804  /************** Include sqlite3.h in the middle of sqliteInt.h ***************/
   1.805  /************** Begin file sqlite3.h *****************************************/
   1.806  /*
   1.807 -** 2001 September 15
   1.808 +** 2001-09-15
   1.809  **
   1.810  ** The author disclaims copyright to this source code.  In place of
   1.811  ** a legal notice, here is a blessing:
   1.812 @@ -392,15 +1154,17 @@
   1.813  ** a string which identifies a particular check-in of SQLite
   1.814  ** within its configuration management system.  ^The SQLITE_SOURCE_ID
   1.815  ** string contains the date and time of the check-in (UTC) and a SHA1
   1.816 -** or SHA3-256 hash of the entire source tree.
   1.817 +** or SHA3-256 hash of the entire source tree.  If the source code has
   1.818 +** been edited in any way since it was last checked in, then the last
   1.819 +** four hexadecimal digits of the hash may be modified.
   1.820  **
   1.821  ** See also: [sqlite3_libversion()],
   1.822  ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   1.823  ** [sqlite_version()] and [sqlite_source_id()].
   1.824  */
   1.825 -#define SQLITE_VERSION        "3.19.3"
   1.826 -#define SQLITE_VERSION_NUMBER 3019003
   1.827 -#define SQLITE_SOURCE_ID      "2017-06-08 14:26:16 0ee482a1e0eae22e08edc8978c9733a96603d4509645f348ebf55b579e89636b"
   1.828 +#define SQLITE_VERSION        "3.26.0"
   1.829 +#define SQLITE_VERSION_NUMBER 3026000
   1.830 +#define SQLITE_SOURCE_ID      "2018-12-01 12:34:55 bf8c1b2b7a5960c282e543b9c293686dccff272512d08865f4600fb58238b4f9"
   1.831  
   1.832  /*
   1.833  ** CAPI3REF: Run-Time Library Version Numbers
   1.834 @@ -416,7 +1180,7 @@
   1.835  **
   1.836  ** <blockquote><pre>
   1.837  ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
   1.838 -** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 );
   1.839 +** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
   1.840  ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
   1.841  ** </pre></blockquote>)^
   1.842  **
   1.843 @@ -426,9 +1190,11 @@
   1.844  ** function is provided for use in DLLs since DLL users usually do not have
   1.845  ** direct access to string constants within the DLL.  ^The
   1.846  ** sqlite3_libversion_number() function returns an integer equal to
   1.847 -** [SQLITE_VERSION_NUMBER].  ^The sqlite3_sourceid() function returns 
   1.848 +** [SQLITE_VERSION_NUMBER].  ^(The sqlite3_sourceid() function returns 
   1.849  ** a pointer to a string constant whose value is the same as the 
   1.850 -** [SQLITE_SOURCE_ID] C preprocessor macro.
   1.851 +** [SQLITE_SOURCE_ID] C preprocessor macro.  Except if SQLite is built
   1.852 +** using an edited copy of [the amalgamation], then the last four characters
   1.853 +** of the hash might be different from [SQLITE_SOURCE_ID].)^
   1.854  **
   1.855  ** See also: [sqlite_version()] and [sqlite_source_id()].
   1.856  */
   1.857 @@ -694,7 +1460,7 @@
   1.858  */
   1.859  #define SQLITE_OK           0   /* Successful result */
   1.860  /* beginning-of-error-codes */
   1.861 -#define SQLITE_ERROR        1   /* SQL error or missing database */
   1.862 +#define SQLITE_ERROR        1   /* Generic error */
   1.863  #define SQLITE_INTERNAL     2   /* Internal logic error in SQLite */
   1.864  #define SQLITE_PERM         3   /* Access permission denied */
   1.865  #define SQLITE_ABORT        4   /* Callback routine requested an abort */
   1.866 @@ -709,7 +1475,7 @@
   1.867  #define SQLITE_FULL        13   /* Insertion failed because database is full */
   1.868  #define SQLITE_CANTOPEN    14   /* Unable to open the database file */
   1.869  #define SQLITE_PROTOCOL    15   /* Database lock protocol error */
   1.870 -#define SQLITE_EMPTY       16   /* Database is empty */
   1.871 +#define SQLITE_EMPTY       16   /* Internal use only */
   1.872  #define SQLITE_SCHEMA      17   /* The database schema changed */
   1.873  #define SQLITE_TOOBIG      18   /* String or BLOB exceeds size limit */
   1.874  #define SQLITE_CONSTRAINT  19   /* Abort due to constraint violation */
   1.875 @@ -717,7 +1483,7 @@
   1.876  #define SQLITE_MISUSE      21   /* Library used incorrectly */
   1.877  #define SQLITE_NOLFS       22   /* Uses OS features not supported on host */
   1.878  #define SQLITE_AUTH        23   /* Authorization denied */
   1.879 -#define SQLITE_FORMAT      24   /* Auxiliary database format error */
   1.880 +#define SQLITE_FORMAT      24   /* Not used */
   1.881  #define SQLITE_RANGE       25   /* 2nd parameter to sqlite3_bind out of range */
   1.882  #define SQLITE_NOTADB      26   /* File opened that is not a database file */
   1.883  #define SQLITE_NOTICE      27   /* Notifications from sqlite3_log() */
   1.884 @@ -743,6 +1509,9 @@
   1.885  ** the most recent error can be obtained using
   1.886  ** [sqlite3_extended_errcode()].
   1.887  */
   1.888 +#define SQLITE_ERROR_MISSING_COLLSEQ   (SQLITE_ERROR | (1<<8))
   1.889 +#define SQLITE_ERROR_RETRY             (SQLITE_ERROR | (2<<8))
   1.890 +#define SQLITE_ERROR_SNAPSHOT          (SQLITE_ERROR | (3<<8))
   1.891  #define SQLITE_IOERR_READ              (SQLITE_IOERR | (1<<8))
   1.892  #define SQLITE_IOERR_SHORT_READ        (SQLITE_IOERR | (2<<8))
   1.893  #define SQLITE_IOERR_WRITE             (SQLITE_IOERR | (3<<8))
   1.894 @@ -771,18 +1540,26 @@
   1.895  #define SQLITE_IOERR_CONVPATH          (SQLITE_IOERR | (26<<8))
   1.896  #define SQLITE_IOERR_VNODE             (SQLITE_IOERR | (27<<8))
   1.897  #define SQLITE_IOERR_AUTH              (SQLITE_IOERR | (28<<8))
   1.898 +#define SQLITE_IOERR_BEGIN_ATOMIC      (SQLITE_IOERR | (29<<8))
   1.899 +#define SQLITE_IOERR_COMMIT_ATOMIC     (SQLITE_IOERR | (30<<8))
   1.900 +#define SQLITE_IOERR_ROLLBACK_ATOMIC   (SQLITE_IOERR | (31<<8))
   1.901  #define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED |  (1<<8))
   1.902 +#define SQLITE_LOCKED_VTAB             (SQLITE_LOCKED |  (2<<8))
   1.903  #define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
   1.904  #define SQLITE_BUSY_SNAPSHOT           (SQLITE_BUSY   |  (2<<8))
   1.905  #define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
   1.906  #define SQLITE_CANTOPEN_ISDIR          (SQLITE_CANTOPEN | (2<<8))
   1.907  #define SQLITE_CANTOPEN_FULLPATH       (SQLITE_CANTOPEN | (3<<8))
   1.908  #define SQLITE_CANTOPEN_CONVPATH       (SQLITE_CANTOPEN | (4<<8))
   1.909 +#define SQLITE_CANTOPEN_DIRTYWAL       (SQLITE_CANTOPEN | (5<<8)) /* Not Used */
   1.910  #define SQLITE_CORRUPT_VTAB            (SQLITE_CORRUPT | (1<<8))
   1.911 +#define SQLITE_CORRUPT_SEQUENCE        (SQLITE_CORRUPT | (2<<8))
   1.912  #define SQLITE_READONLY_RECOVERY       (SQLITE_READONLY | (1<<8))
   1.913  #define SQLITE_READONLY_CANTLOCK       (SQLITE_READONLY | (2<<8))
   1.914  #define SQLITE_READONLY_ROLLBACK       (SQLITE_READONLY | (3<<8))
   1.915  #define SQLITE_READONLY_DBMOVED        (SQLITE_READONLY | (4<<8))
   1.916 +#define SQLITE_READONLY_CANTINIT       (SQLITE_READONLY | (5<<8))
   1.917 +#define SQLITE_READONLY_DIRECTORY      (SQLITE_READONLY | (6<<8))
   1.918  #define SQLITE_ABORT_ROLLBACK          (SQLITE_ABORT | (2<<8))
   1.919  #define SQLITE_CONSTRAINT_CHECK        (SQLITE_CONSTRAINT | (1<<8))
   1.920  #define SQLITE_CONSTRAINT_COMMITHOOK   (SQLITE_CONSTRAINT | (2<<8))
   1.921 @@ -857,6 +1634,11 @@
   1.922  ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
   1.923  ** read-only media and cannot be changed even by processes with
   1.924  ** elevated privileges.
   1.925 +**
   1.926 +** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying
   1.927 +** filesystem supports doing multiple write operations atomically when those
   1.928 +** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and
   1.929 +** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].
   1.930  */
   1.931  #define SQLITE_IOCAP_ATOMIC                 0x00000001
   1.932  #define SQLITE_IOCAP_ATOMIC512              0x00000002
   1.933 @@ -872,6 +1654,7 @@
   1.934  #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN  0x00000800
   1.935  #define SQLITE_IOCAP_POWERSAFE_OVERWRITE    0x00001000
   1.936  #define SQLITE_IOCAP_IMMUTABLE              0x00002000
   1.937 +#define SQLITE_IOCAP_BATCH_ATOMIC           0x00004000
   1.938  
   1.939  /*
   1.940  ** CAPI3REF: File Locking Levels
   1.941 @@ -1006,6 +1789,7 @@
   1.942  ** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
   1.943  ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
   1.944  ** <li> [SQLITE_IOCAP_IMMUTABLE]
   1.945 +** <li> [SQLITE_IOCAP_BATCH_ATOMIC]
   1.946  ** </ul>
   1.947  **
   1.948  ** The SQLITE_IOCAP_ATOMIC property means that all writes of
   1.949 @@ -1143,7 +1927,8 @@
   1.950  ** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
   1.951  ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
   1.952  ** persistent [WAL | Write Ahead Log] setting.  By default, the auxiliary
   1.953 -** write ahead log and shared memory files used for transaction control
   1.954 +** write ahead log ([WAL file]) and shared memory
   1.955 +** files used for transaction control
   1.956  ** are automatically deleted when the latest connection to the database
   1.957  ** closes.  Setting persistent WAL mode causes those files to persist after
   1.958  ** close.  Persisting the files is useful when other processes that do not
   1.959 @@ -1289,6 +2074,66 @@
   1.960  ** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
   1.961  ** the RBU extension only.  All other VFS should return SQLITE_NOTFOUND for
   1.962  ** this opcode.  
   1.963 +**
   1.964 +** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]]
   1.965 +** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then
   1.966 +** the file descriptor is placed in "batch write mode", which
   1.967 +** means all subsequent write operations will be deferred and done
   1.968 +** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].  Systems
   1.969 +** that do not support batch atomic writes will return SQLITE_NOTFOUND.
   1.970 +** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to
   1.971 +** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or
   1.972 +** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make
   1.973 +** no VFS interface calls on the same [sqlite3_file] file descriptor
   1.974 +** except for calls to the xWrite method and the xFileControl method
   1.975 +** with [SQLITE_FCNTL_SIZE_HINT].
   1.976 +**
   1.977 +** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]]
   1.978 +** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write
   1.979 +** operations since the previous successful call to 
   1.980 +** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically.
   1.981 +** This file control returns [SQLITE_OK] if and only if the writes were
   1.982 +** all performed successfully and have been committed to persistent storage.
   1.983 +** ^Regardless of whether or not it is successful, this file control takes
   1.984 +** the file descriptor out of batch write mode so that all subsequent
   1.985 +** write operations are independent.
   1.986 +** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without
   1.987 +** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
   1.988 +**
   1.989 +** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]]
   1.990 +** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write
   1.991 +** operations since the previous successful call to 
   1.992 +** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back.
   1.993 +** ^This file control takes the file descriptor out of batch write mode
   1.994 +** so that all subsequent write operations are independent.
   1.995 +** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without
   1.996 +** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
   1.997 +**
   1.998 +** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]]
   1.999 +** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode causes attempts to obtain
  1.1000 +** a file lock using the xLock or xShmLock methods of the VFS to wait
  1.1001 +** for up to M milliseconds before failing, where M is the single 
  1.1002 +** unsigned integer parameter.
  1.1003 +**
  1.1004 +** <li>[[SQLITE_FCNTL_DATA_VERSION]]
  1.1005 +** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
  1.1006 +** a database file.  The argument is a pointer to a 32-bit unsigned integer.
  1.1007 +** The "data version" for the pager is written into the pointer.  The
  1.1008 +** "data version" changes whenever any change occurs to the corresponding
  1.1009 +** database file, either through SQL statements on the same database
  1.1010 +** connection or through transactions committed by separate database
  1.1011 +** connections possibly in other processes. The [sqlite3_total_changes()]
  1.1012 +** interface can be used to find if any database on the connection has changed,
  1.1013 +** but that interface responds to changes on TEMP as well as MAIN and does
  1.1014 +** not provide a mechanism to detect changes to MAIN only.  Also, the
  1.1015 +** [sqlite3_total_changes()] interface responds to internal changes only and
  1.1016 +** omits changes made by other database connections.  The
  1.1017 +** [PRAGMA data_version] command provide a mechanism to detect changes to
  1.1018 +** a single attached database that occur due to other database connections,
  1.1019 +** but omits changes implemented by the database connection on which it is
  1.1020 +** called.  This file control is the only mechanism to detect changes that
  1.1021 +** happen either internally or externally and that are associated with
  1.1022 +** a particular attached database.
  1.1023  ** </ul>
  1.1024  */
  1.1025  #define SQLITE_FCNTL_LOCKSTATE               1
  1.1026 @@ -1320,6 +2165,11 @@
  1.1027  #define SQLITE_FCNTL_JOURNAL_POINTER        28
  1.1028  #define SQLITE_FCNTL_WIN32_GET_HANDLE       29
  1.1029  #define SQLITE_FCNTL_PDB                    30
  1.1030 +#define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE     31
  1.1031 +#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE    32
  1.1032 +#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE  33
  1.1033 +#define SQLITE_FCNTL_LOCK_TIMEOUT           34
  1.1034 +#define SQLITE_FCNTL_DATA_VERSION           35
  1.1035  
  1.1036  /* deprecated names */
  1.1037  #define SQLITE_GET_LOCKPROXYFILE      SQLITE_FCNTL_GET_LOCKPROXYFILE
  1.1038 @@ -1357,12 +2207,18 @@
  1.1039  ** in the name of the object stands for "virtual file system".  See
  1.1040  ** the [VFS | VFS documentation] for further information.
  1.1041  **
  1.1042 -** The value of the iVersion field is initially 1 but may be larger in
  1.1043 -** future versions of SQLite.  Additional fields may be appended to this
  1.1044 -** object when the iVersion value is increased.  Note that the structure
  1.1045 -** of the sqlite3_vfs object changes in the transaction between
  1.1046 -** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not
  1.1047 -** modified.
  1.1048 +** The VFS interface is sometimes extended by adding new methods onto
  1.1049 +** the end.  Each time such an extension occurs, the iVersion field
  1.1050 +** is incremented.  The iVersion value started out as 1 in
  1.1051 +** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
  1.1052 +** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
  1.1053 +** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6].  Additional fields
  1.1054 +** may be appended to the sqlite3_vfs object and the iVersion value
  1.1055 +** may increase again in future versions of SQLite.
  1.1056 +** Note that the structure
  1.1057 +** of the sqlite3_vfs object changes in the transition from
  1.1058 +** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
  1.1059 +** and yet the iVersion field was not modified.
  1.1060  **
  1.1061  ** The szOsFile field is the size of the subclassed [sqlite3_file]
  1.1062  ** structure used by this VFS.  mxPathname is the maximum length of
  1.1063 @@ -1890,6 +2746,16 @@
  1.1064  ** routines with a wrapper that simulations memory allocation failure or
  1.1065  ** tracks memory usage, for example. </dd>
  1.1066  **
  1.1067 +** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>
  1.1068 +** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of
  1.1069 +** type int, interpreted as a boolean, which if true provides a hint to
  1.1070 +** SQLite that it should avoid large memory allocations if possible.
  1.1071 +** SQLite will run faster if it is free to make large memory allocations,
  1.1072 +** but some application might prefer to run slower in exchange for
  1.1073 +** guarantees about memory fragmentation that are possible if large
  1.1074 +** allocations are avoided.  This hint is normally off.
  1.1075 +** </dd>
  1.1076 +**
  1.1077  ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
  1.1078  ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
  1.1079  ** interpreted as a boolean, which enables or disables the collection of
  1.1080 @@ -1907,25 +2773,7 @@
  1.1081  ** </dd>
  1.1082  **
  1.1083  ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
  1.1084 -** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer
  1.1085 -** that SQLite can use for scratch memory.  ^(There are three arguments
  1.1086 -** to SQLITE_CONFIG_SCRATCH:  A pointer an 8-byte
  1.1087 -** aligned memory buffer from which the scratch allocations will be
  1.1088 -** drawn, the size of each scratch allocation (sz),
  1.1089 -** and the maximum number of scratch allocations (N).)^
  1.1090 -** The first argument must be a pointer to an 8-byte aligned buffer
  1.1091 -** of at least sz*N bytes of memory.
  1.1092 -** ^SQLite will not use more than one scratch buffers per thread.
  1.1093 -** ^SQLite will never request a scratch buffer that is more than 6
  1.1094 -** times the database page size.
  1.1095 -** ^If SQLite needs needs additional
  1.1096 -** scratch memory beyond what is provided by this configuration option, then 
  1.1097 -** [sqlite3_malloc()] will be used to obtain the memory needed.<p>
  1.1098 -** ^When the application provides any amount of scratch memory using
  1.1099 -** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large
  1.1100 -** [sqlite3_malloc|heap allocations].
  1.1101 -** This can help [Robson proof|prevent memory allocation failures] due to heap
  1.1102 -** fragmentation in low-memory embedded systems.
  1.1103 +** <dd> The SQLITE_CONFIG_SCRATCH option is no longer used.
  1.1104  ** </dd>
  1.1105  **
  1.1106  ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
  1.1107 @@ -1961,8 +2809,7 @@
  1.1108  ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
  1.1109  ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer 
  1.1110  ** that SQLite will use for all of its dynamic memory allocation needs
  1.1111 -** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and
  1.1112 -** [SQLITE_CONFIG_PAGECACHE].
  1.1113 +** beyond those provided for by [SQLITE_CONFIG_PAGECACHE].
  1.1114  ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
  1.1115  ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
  1.1116  ** [SQLITE_ERROR] if invoked otherwise.
  1.1117 @@ -2148,6 +2995,22 @@
  1.1118  ** I/O required to support statement rollback.
  1.1119  ** The default value for this setting is controlled by the
  1.1120  ** [SQLITE_STMTJRNL_SPILL] compile-time option.
  1.1121 +**
  1.1122 +** [[SQLITE_CONFIG_SORTERREF_SIZE]]
  1.1123 +** <dt>SQLITE_CONFIG_SORTERREF_SIZE
  1.1124 +** <dd>The SQLITE_CONFIG_SORTERREF_SIZE option accepts a single parameter
  1.1125 +** of type (int) - the new value of the sorter-reference size threshold.
  1.1126 +** Usually, when SQLite uses an external sort to order records according
  1.1127 +** to an ORDER BY clause, all fields required by the caller are present in the
  1.1128 +** sorted records. However, if SQLite determines based on the declared type
  1.1129 +** of a table column that its values are likely to be very large - larger
  1.1130 +** than the configured sorter-reference size threshold - then a reference
  1.1131 +** is stored in each sorted record and the required column values loaded
  1.1132 +** from the database as records are returned in sorted order. The default
  1.1133 +** value for this option is to never use this optimization. Specifying a 
  1.1134 +** negative value for this option restores the default behaviour.
  1.1135 +** This option is only available if SQLite is compiled with the
  1.1136 +** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
  1.1137  ** </dl>
  1.1138  */
  1.1139  #define SQLITE_CONFIG_SINGLETHREAD  1  /* nil */
  1.1140 @@ -2155,7 +3018,7 @@
  1.1141  #define SQLITE_CONFIG_SERIALIZED    3  /* nil */
  1.1142  #define SQLITE_CONFIG_MALLOC        4  /* sqlite3_mem_methods* */
  1.1143  #define SQLITE_CONFIG_GETMALLOC     5  /* sqlite3_mem_methods* */
  1.1144 -#define SQLITE_CONFIG_SCRATCH       6  /* void*, int sz, int N */
  1.1145 +#define SQLITE_CONFIG_SCRATCH       6  /* No longer used */
  1.1146  #define SQLITE_CONFIG_PAGECACHE     7  /* void*, int sz, int N */
  1.1147  #define SQLITE_CONFIG_HEAP          8  /* void*, int nByte, int min */
  1.1148  #define SQLITE_CONFIG_MEMSTATUS     9  /* boolean */
  1.1149 @@ -2176,6 +3039,8 @@
  1.1150  #define SQLITE_CONFIG_PCACHE_HDRSZ        24  /* int *psz */
  1.1151  #define SQLITE_CONFIG_PMASZ               25  /* unsigned int szPma */
  1.1152  #define SQLITE_CONFIG_STMTJRNL_SPILL      26  /* int nByte */
  1.1153 +#define SQLITE_CONFIG_SMALL_MALLOC        27  /* boolean */
  1.1154 +#define SQLITE_CONFIG_SORTERREF_SIZE      28  /* int nByte */
  1.1155  
  1.1156  /*
  1.1157  ** CAPI3REF: Database Connection Configuration Options
  1.1158 @@ -2191,6 +3056,7 @@
  1.1159  ** is invoked.
  1.1160  **
  1.1161  ** <dl>
  1.1162 +** [[SQLITE_DBCONFIG_LOOKASIDE]]
  1.1163  ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
  1.1164  ** <dd> ^This option takes three additional arguments that determine the 
  1.1165  ** [lookaside memory allocator] configuration for the [database connection].
  1.1166 @@ -2213,6 +3079,7 @@
  1.1167  ** memory is in use leaves the configuration unchanged and returns 
  1.1168  ** [SQLITE_BUSY].)^</dd>
  1.1169  **
  1.1170 +** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
  1.1171  ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
  1.1172  ** <dd> ^This option is used to enable or disable the enforcement of
  1.1173  ** [foreign key constraints].  There should be two additional arguments.
  1.1174 @@ -2223,6 +3090,7 @@
  1.1175  ** following this call.  The second parameter may be a NULL pointer, in
  1.1176  ** which case the FK enforcement setting is not reported back. </dd>
  1.1177  **
  1.1178 +** [[SQLITE_DBCONFIG_ENABLE_TRIGGER]]
  1.1179  ** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
  1.1180  ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
  1.1181  ** There should be two additional arguments.
  1.1182 @@ -2233,6 +3101,7 @@
  1.1183  ** following this call.  The second parameter may be a NULL pointer, in
  1.1184  ** which case the trigger setting is not reported back. </dd>
  1.1185  **
  1.1186 +** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
  1.1187  ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
  1.1188  ** <dd> ^This option is used to enable or disable the two-argument
  1.1189  ** version of the [fts3_tokenizer()] function which is part of the
  1.1190 @@ -2246,6 +3115,7 @@
  1.1191  ** following this call.  The second parameter may be a NULL pointer, in
  1.1192  ** which case the new setting is not reported back. </dd>
  1.1193  **
  1.1194 +** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]]
  1.1195  ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
  1.1196  ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
  1.1197  ** interface independently of the [load_extension()] SQL function.
  1.1198 @@ -2263,7 +3133,7 @@
  1.1199  ** be a NULL pointer, in which case the new setting is not reported back.
  1.1200  ** </dd>
  1.1201  **
  1.1202 -** <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
  1.1203 +** [[SQLITE_DBCONFIG_MAINDBNAME]] <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
  1.1204  ** <dd> ^This option is used to change the name of the "main" database
  1.1205  ** schema.  ^The sole argument is a pointer to a constant UTF8 string
  1.1206  ** which will become the new schema name in place of "main".  ^SQLite
  1.1207 @@ -2272,18 +3142,80 @@
  1.1208  ** until after the database connection closes.
  1.1209  ** </dd>
  1.1210  **
  1.1211 +** [[SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE]] 
  1.1212  ** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
  1.1213  ** <dd> Usually, when a database in wal mode is closed or detached from a 
  1.1214  ** database handle, SQLite checks if this will mean that there are now no 
  1.1215  ** connections at all to the database. If so, it performs a checkpoint 
  1.1216  ** operation before closing the connection. This option may be used to
  1.1217  ** override this behaviour. The first parameter passed to this operation
  1.1218 -** is an integer - non-zero to disable checkpoints-on-close, or zero (the
  1.1219 -** default) to enable them. The second parameter is a pointer to an integer
  1.1220 +** is an integer - positive to disable checkpoints-on-close, or zero (the
  1.1221 +** default) to enable them, and negative to leave the setting unchanged.
  1.1222 +** The second parameter is a pointer to an integer
  1.1223  ** into which is written 0 or 1 to indicate whether checkpoints-on-close
  1.1224  ** have been disabled - 0 if they are not disabled, 1 if they are.
  1.1225  ** </dd>
  1.1226  **
  1.1227 +** [[SQLITE_DBCONFIG_ENABLE_QPSG]] <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
  1.1228 +** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
  1.1229 +** the [query planner stability guarantee] (QPSG).  When the QPSG is active,
  1.1230 +** a single SQL query statement will always use the same algorithm regardless
  1.1231 +** of values of [bound parameters].)^ The QPSG disables some query optimizations
  1.1232 +** that look at the values of bound parameters, which can make some queries
  1.1233 +** slower.  But the QPSG has the advantage of more predictable behavior.  With
  1.1234 +** the QPSG active, SQLite will always use the same query plan in the field as
  1.1235 +** was used during testing in the lab.
  1.1236 +** The first argument to this setting is an integer which is 0 to disable 
  1.1237 +** the QPSG, positive to enable QPSG, or negative to leave the setting
  1.1238 +** unchanged. The second parameter is a pointer to an integer into which
  1.1239 +** is written 0 or 1 to indicate whether the QPSG is disabled or enabled
  1.1240 +** following this call.
  1.1241 +** </dd>
  1.1242 +**
  1.1243 +** [[SQLITE_DBCONFIG_TRIGGER_EQP]] <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
  1.1244 +** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not 
  1.1245 +** include output for any operations performed by trigger programs. This
  1.1246 +** option is used to set or clear (the default) a flag that governs this
  1.1247 +** behavior. The first parameter passed to this operation is an integer -
  1.1248 +** positive to enable output for trigger programs, or zero to disable it,
  1.1249 +** or negative to leave the setting unchanged.
  1.1250 +** The second parameter is a pointer to an integer into which is written 
  1.1251 +** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if 
  1.1252 +** it is not disabled, 1 if it is.  
  1.1253 +** </dd>
  1.1254 +**
  1.1255 +** [[SQLITE_DBCONFIG_RESET_DATABASE]] <dt>SQLITE_DBCONFIG_RESET_DATABASE</dt>
  1.1256 +** <dd> Set the SQLITE_DBCONFIG_RESET_DATABASE flag and then run
  1.1257 +** [VACUUM] in order to reset a database back to an empty database
  1.1258 +** with no schema and no content. The following process works even for
  1.1259 +** a badly corrupted database file:
  1.1260 +** <ol>
  1.1261 +** <li> If the database connection is newly opened, make sure it has read the
  1.1262 +**      database schema by preparing then discarding some query against the
  1.1263 +**      database, or calling sqlite3_table_column_metadata(), ignoring any
  1.1264 +**      errors.  This step is only necessary if the application desires to keep
  1.1265 +**      the database in WAL mode after the reset if it was in WAL mode before
  1.1266 +**      the reset.  
  1.1267 +** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
  1.1268 +** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);
  1.1269 +** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
  1.1270 +** </ol>
  1.1271 +** Because resetting a database is destructive and irreversible, the
  1.1272 +** process requires the use of this obscure API and multiple steps to help
  1.1273 +** ensure that it does not happen by accident.
  1.1274 +**
  1.1275 +** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>
  1.1276 +** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
  1.1277 +** "defensive" flag for a database connection.  When the defensive
  1.1278 +** flag is enabled, language features that allow ordinary SQL to 
  1.1279 +** deliberately corrupt the database file are disabled.  The disabled
  1.1280 +** features include but are not limited to the following:
  1.1281 +** <ul>
  1.1282 +** <li> The [PRAGMA writable_schema=ON] statement.
  1.1283 +** <li> Writes to the [sqlite_dbpage] virtual table.
  1.1284 +** <li> Direct writes to [shadow tables].
  1.1285 +** </ul>
  1.1286 +** </dd>
  1.1287  ** </dl>
  1.1288  */
  1.1289  #define SQLITE_DBCONFIG_MAINDBNAME            1000 /* const char* */
  1.1290 @@ -2293,7 +3225,11 @@
  1.1291  #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
  1.1292  #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
  1.1293  #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE      1006 /* int int* */
  1.1294 -
  1.1295 +#define SQLITE_DBCONFIG_ENABLE_QPSG           1007 /* int int* */
  1.1296 +#define SQLITE_DBCONFIG_TRIGGER_EQP           1008 /* int int* */
  1.1297 +#define SQLITE_DBCONFIG_RESET_DATABASE        1009 /* int int* */
  1.1298 +#define SQLITE_DBCONFIG_DEFENSIVE             1010 /* int int* */
  1.1299 +#define SQLITE_DBCONFIG_MAX                   1010 /* Largest DBCONFIG */
  1.1300  
  1.1301  /*
  1.1302  ** CAPI3REF: Enable Or Disable Extended Result Codes
  1.1303 @@ -2421,12 +3357,17 @@
  1.1304  ** program, the value returned reflects the number of rows modified by the 
  1.1305  ** previous INSERT, UPDATE or DELETE statement within the same trigger.
  1.1306  **
  1.1307 -** See also the [sqlite3_total_changes()] interface, the
  1.1308 -** [count_changes pragma], and the [changes() SQL function].
  1.1309 -**
  1.1310  ** If a separate thread makes changes on the same database connection
  1.1311  ** while [sqlite3_changes()] is running then the value returned
  1.1312  ** is unpredictable and not meaningful.
  1.1313 +**
  1.1314 +** See also:
  1.1315 +** <ul>
  1.1316 +** <li> the [sqlite3_total_changes()] interface
  1.1317 +** <li> the [count_changes pragma]
  1.1318 +** <li> the [changes() SQL function]
  1.1319 +** <li> the [data_version pragma]
  1.1320 +** </ul>
  1.1321  */
  1.1322  SQLITE_API int sqlite3_changes(sqlite3*);
  1.1323  
  1.1324 @@ -2444,13 +3385,26 @@
  1.1325  ** count, but those made as part of REPLACE constraint resolution are
  1.1326  ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers 
  1.1327  ** are not counted.
  1.1328 +**
  1.1329 +** This the [sqlite3_total_changes(D)] interface only reports the number
  1.1330 +** of rows that changed due to SQL statement run against database
  1.1331 +** connection D.  Any changes by other database connections are ignored.
  1.1332 +** To detect changes against a database file from other database
  1.1333 +** connections use the [PRAGMA data_version] command or the
  1.1334 +** [SQLITE_FCNTL_DATA_VERSION] [file control].
  1.1335  ** 
  1.1336 -** See also the [sqlite3_changes()] interface, the
  1.1337 -** [count_changes pragma], and the [total_changes() SQL function].
  1.1338 -**
  1.1339  ** If a separate thread makes changes on the same database connection
  1.1340  ** while [sqlite3_total_changes()] is running then the value
  1.1341  ** returned is unpredictable and not meaningful.
  1.1342 +**
  1.1343 +** See also:
  1.1344 +** <ul>
  1.1345 +** <li> the [sqlite3_changes()] interface
  1.1346 +** <li> the [count_changes pragma]
  1.1347 +** <li> the [changes() SQL function]
  1.1348 +** <li> the [data_version pragma]
  1.1349 +** <li> the [SQLITE_FCNTL_DATA_VERSION] [file control]
  1.1350 +** </ul>
  1.1351  */
  1.1352  SQLITE_API int sqlite3_total_changes(sqlite3*);
  1.1353  
  1.1354 @@ -2699,16 +3653,16 @@
  1.1355  **
  1.1356  ** These routines are work-alikes of the "printf()" family of functions
  1.1357  ** from the standard C library.
  1.1358 -** These routines understand most of the common K&R formatting options,
  1.1359 -** plus some additional non-standard formats, detailed below.
  1.1360 -** Note that some of the more obscure formatting options from recent
  1.1361 -** C-library standards are omitted from this implementation.
  1.1362 +** These routines understand most of the common formatting options from
  1.1363 +** the standard library printf() 
  1.1364 +** plus some additional non-standard formats ([%q], [%Q], [%w], and [%z]).
  1.1365 +** See the [built-in printf()] documentation for details.
  1.1366  **
  1.1367  ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
  1.1368 -** results into memory obtained from [sqlite3_malloc()].
  1.1369 +** results into memory obtained from [sqlite3_malloc64()].
  1.1370  ** The strings returned by these two routines should be
  1.1371  ** released by [sqlite3_free()].  ^Both routines return a
  1.1372 -** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
  1.1373 +** NULL pointer if [sqlite3_malloc64()] is unable to allocate enough
  1.1374  ** memory to hold the resulting string.
  1.1375  **
  1.1376  ** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from
  1.1377 @@ -2732,71 +3686,7 @@
  1.1378  **
  1.1379  ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
  1.1380  **
  1.1381 -** These routines all implement some additional formatting
  1.1382 -** options that are useful for constructing SQL statements.
  1.1383 -** All of the usual printf() formatting options apply.  In addition, there
  1.1384 -** is are "%q", "%Q", "%w" and "%z" options.
  1.1385 -**
  1.1386 -** ^(The %q option works like %s in that it substitutes a nul-terminated
  1.1387 -** string from the argument list.  But %q also doubles every '\'' character.
  1.1388 -** %q is designed for use inside a string literal.)^  By doubling each '\''
  1.1389 -** character it escapes that character and allows it to be inserted into
  1.1390 -** the string.
  1.1391 -**
  1.1392 -** For example, assume the string variable zText contains text as follows:
  1.1393 -**
  1.1394 -** <blockquote><pre>
  1.1395 -**  char *zText = "It's a happy day!";
  1.1396 -** </pre></blockquote>
  1.1397 -**
  1.1398 -** One can use this text in an SQL statement as follows:
  1.1399 -**
  1.1400 -** <blockquote><pre>
  1.1401 -**  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
  1.1402 -**  sqlite3_exec(db, zSQL, 0, 0, 0);
  1.1403 -**  sqlite3_free(zSQL);
  1.1404 -** </pre></blockquote>
  1.1405 -**
  1.1406 -** Because the %q format string is used, the '\'' character in zText
  1.1407 -** is escaped and the SQL generated is as follows:
  1.1408 -**
  1.1409 -** <blockquote><pre>
  1.1410 -**  INSERT INTO table1 VALUES('It''s a happy day!')
  1.1411 -** </pre></blockquote>
  1.1412 -**
  1.1413 -** This is correct.  Had we used %s instead of %q, the generated SQL
  1.1414 -** would have looked like this:
  1.1415 -**
  1.1416 -** <blockquote><pre>
  1.1417 -**  INSERT INTO table1 VALUES('It's a happy day!');
  1.1418 -** </pre></blockquote>
  1.1419 -**
  1.1420 -** This second example is an SQL syntax error.  As a general rule you should
  1.1421 -** always use %q instead of %s when inserting text into a string literal.
  1.1422 -**
  1.1423 -** ^(The %Q option works like %q except it also adds single quotes around
  1.1424 -** the outside of the total string.  Additionally, if the parameter in the
  1.1425 -** argument list is a NULL pointer, %Q substitutes the text "NULL" (without
  1.1426 -** single quotes).)^  So, for example, one could say:
  1.1427 -**
  1.1428 -** <blockquote><pre>
  1.1429 -**  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
  1.1430 -**  sqlite3_exec(db, zSQL, 0, 0, 0);
  1.1431 -**  sqlite3_free(zSQL);
  1.1432 -** </pre></blockquote>
  1.1433 -**
  1.1434 -** The code above will render a correct SQL statement in the zSQL
  1.1435 -** variable even if the zText variable is a NULL pointer.
  1.1436 -**
  1.1437 -** ^(The "%w" formatting option is like "%q" except that it expects to
  1.1438 -** be contained within double-quotes instead of single quotes, and it
  1.1439 -** escapes the double-quote character instead of the single-quote
  1.1440 -** character.)^  The "%w" formatting option is intended for safely inserting
  1.1441 -** table and column names into a constructed SQL statement.
  1.1442 -**
  1.1443 -** ^(The "%z" formatting option works like "%s" but with the
  1.1444 -** addition that after the string has been read and copied into
  1.1445 -** the result, [sqlite3_free()] is called on the input string.)^
  1.1446 +** See also:  [built-in printf()], [printf() SQL function]
  1.1447  */
  1.1448  SQLITE_API char *sqlite3_mprintf(const char*,...);
  1.1449  SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
  1.1450 @@ -2956,7 +3846,8 @@
  1.1451  ** [database connection], supplied in the first argument.
  1.1452  ** ^The authorizer callback is invoked as SQL statements are being compiled
  1.1453  ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
  1.1454 -** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()].  ^At various
  1.1455 +** [sqlite3_prepare_v3()], [sqlite3_prepare16()], [sqlite3_prepare16_v2()],
  1.1456 +** and [sqlite3_prepare16_v3()].  ^At various
  1.1457  ** points during the compilation process, as logic is being created
  1.1458  ** to perform various actions, the authorizer callback is invoked to
  1.1459  ** see if those actions are allowed.  ^The authorizer callback should
  1.1460 @@ -3153,8 +4044,8 @@
  1.1461  ** KEYWORDS: SQLITE_TRACE
  1.1462  **
  1.1463  ** These constants identify classes of events that can be monitored
  1.1464 -** using the [sqlite3_trace_v2()] tracing logic.  The third argument
  1.1465 -** to [sqlite3_trace_v2()] is an OR-ed combination of one or more of
  1.1466 +** using the [sqlite3_trace_v2()] tracing logic.  The M argument
  1.1467 +** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of
  1.1468  ** the following constants.  ^The first argument to the trace callback
  1.1469  ** is one of the following constants.
  1.1470  **
  1.1471 @@ -3363,10 +4254,10 @@
  1.1472  ** ^If [URI filename] interpretation is enabled, and the filename argument
  1.1473  ** begins with "file:", then the filename is interpreted as a URI. ^URI
  1.1474  ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
  1.1475 -** set in the fourth argument to sqlite3_open_v2(), or if it has
  1.1476 +** set in the third argument to sqlite3_open_v2(), or if it has
  1.1477  ** been enabled globally using the [SQLITE_CONFIG_URI] option with the
  1.1478  ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
  1.1479 -** As of SQLite version 3.7.7, URI filename interpretation is turned off
  1.1480 +** URI filename interpretation is turned off
  1.1481  ** by default, but future releases of SQLite might enable URI filename
  1.1482  ** interpretation by default.  See "[URI filenames]" for additional
  1.1483  ** information.
  1.1484 @@ -3569,13 +4460,24 @@
  1.1485  ** [database connection] D failed, then the sqlite3_errcode(D) interface
  1.1486  ** returns the numeric [result code] or [extended result code] for that
  1.1487  ** API call.
  1.1488 -** If the most recent API call was successful,
  1.1489 -** then the return value from sqlite3_errcode() is undefined.
  1.1490  ** ^The sqlite3_extended_errcode()
  1.1491  ** interface is the same except that it always returns the 
  1.1492  ** [extended result code] even when extended result codes are
  1.1493  ** disabled.
  1.1494  **
  1.1495 +** The values returned by sqlite3_errcode() and/or
  1.1496 +** sqlite3_extended_errcode() might change with each API call.
  1.1497 +** Except, there are some interfaces that are guaranteed to never
  1.1498 +** change the value of the error code.  The error-code preserving
  1.1499 +** interfaces are:
  1.1500 +**
  1.1501 +** <ul>
  1.1502 +** <li> sqlite3_errcode()
  1.1503 +** <li> sqlite3_extended_errcode()
  1.1504 +** <li> sqlite3_errmsg()
  1.1505 +** <li> sqlite3_errmsg16()
  1.1506 +** </ul>
  1.1507 +**
  1.1508  ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
  1.1509  ** text that describes the error, as either UTF-8 or UTF-16 respectively.
  1.1510  ** ^(Memory to hold the error message string is managed internally.
  1.1511 @@ -3745,6 +4647,39 @@
  1.1512  #define SQLITE_LIMIT_TRIGGER_DEPTH            10
  1.1513  #define SQLITE_LIMIT_WORKER_THREADS           11
  1.1514  
  1.1515 +/*
  1.1516 +** CAPI3REF: Prepare Flags
  1.1517 +**
  1.1518 +** These constants define various flags that can be passed into
  1.1519 +** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
  1.1520 +** [sqlite3_prepare16_v3()] interfaces.
  1.1521 +**
  1.1522 +** New flags may be added in future releases of SQLite.
  1.1523 +**
  1.1524 +** <dl>
  1.1525 +** [[SQLITE_PREPARE_PERSISTENT]] ^(<dt>SQLITE_PREPARE_PERSISTENT</dt>
  1.1526 +** <dd>The SQLITE_PREPARE_PERSISTENT flag is a hint to the query planner
  1.1527 +** that the prepared statement will be retained for a long time and
  1.1528 +** probably reused many times.)^ ^Without this flag, [sqlite3_prepare_v3()]
  1.1529 +** and [sqlite3_prepare16_v3()] assume that the prepared statement will 
  1.1530 +** be used just once or at most a few times and then destroyed using
  1.1531 +** [sqlite3_finalize()] relatively soon. The current implementation acts
  1.1532 +** on this hint by avoiding the use of [lookaside memory] so as not to
  1.1533 +** deplete the limited store of lookaside memory. Future versions of
  1.1534 +** SQLite may act on this hint differently.
  1.1535 +**
  1.1536 +** [[SQLITE_PREPARE_NORMALIZE]] ^(<dt>SQLITE_PREPARE_NORMALIZE</dt>
  1.1537 +** <dd>The SQLITE_PREPARE_NORMALIZE flag indicates that a normalized
  1.1538 +** representation of the SQL statement should be calculated and then
  1.1539 +** associated with the prepared statement, which can be obtained via
  1.1540 +** the [sqlite3_normalized_sql()] interface.)^  The semantics used to
  1.1541 +** normalize a SQL statement are unspecified and subject to change.
  1.1542 +** At a minimum, literal values will be replaced with suitable
  1.1543 +** placeholders.
  1.1544 +** </dl>
  1.1545 +*/
  1.1546 +#define SQLITE_PREPARE_PERSISTENT              0x01
  1.1547 +#define SQLITE_PREPARE_NORMALIZE               0x02
  1.1548  
  1.1549  /*
  1.1550  ** CAPI3REF: Compiling An SQL Statement
  1.1551 @@ -3752,17 +4687,29 @@
  1.1552  ** METHOD: sqlite3
  1.1553  ** CONSTRUCTOR: sqlite3_stmt
  1.1554  **
  1.1555 -** To execute an SQL query, it must first be compiled into a byte-code
  1.1556 -** program using one of these routines.
  1.1557 +** To execute an SQL statement, it must first be compiled into a byte-code
  1.1558 +** program using one of these routines.  Or, in other words, these routines
  1.1559 +** are constructors for the [prepared statement] object.
  1.1560 +**
  1.1561 +** The preferred routine to use is [sqlite3_prepare_v2()].  The
  1.1562 +** [sqlite3_prepare()] interface is legacy and should be avoided.
  1.1563 +** [sqlite3_prepare_v3()] has an extra "prepFlags" option that is used
  1.1564 +** for special purposes.
  1.1565 +**
  1.1566 +** The use of the UTF-8 interfaces is preferred, as SQLite currently
  1.1567 +** does all parsing using UTF-8.  The UTF-16 interfaces are provided
  1.1568 +** as a convenience.  The UTF-16 interfaces work by converting the
  1.1569 +** input text into UTF-8, then invoking the corresponding UTF-8 interface.
  1.1570  **
  1.1571  ** The first argument, "db", is a [database connection] obtained from a
  1.1572  ** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or
  1.1573  ** [sqlite3_open16()].  The database connection must not have been closed.
  1.1574  **
  1.1575  ** The second argument, "zSql", is the statement to be compiled, encoded
  1.1576 -** as either UTF-8 or UTF-16.  The sqlite3_prepare() and sqlite3_prepare_v2()
  1.1577 -** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2()
  1.1578 -** use UTF-16.
  1.1579 +** as either UTF-8 or UTF-16.  The sqlite3_prepare(), sqlite3_prepare_v2(),
  1.1580 +** and sqlite3_prepare_v3()
  1.1581 +** interfaces use UTF-8, and sqlite3_prepare16(), sqlite3_prepare16_v2(),
  1.1582 +** and sqlite3_prepare16_v3() use UTF-16.
  1.1583  **
  1.1584  ** ^If the nByte argument is negative, then zSql is read up to the
  1.1585  ** first zero terminator. ^If nByte is positive, then it is the
  1.1586 @@ -3789,10 +4736,11 @@
  1.1587  ** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];
  1.1588  ** otherwise an [error code] is returned.
  1.1589  **
  1.1590 -** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are
  1.1591 -** recommended for all new programs. The two older interfaces are retained
  1.1592 -** for backwards compatibility, but their use is discouraged.
  1.1593 -** ^In the "v2" interfaces, the prepared statement
  1.1594 +** The sqlite3_prepare_v2(), sqlite3_prepare_v3(), sqlite3_prepare16_v2(),
  1.1595 +** and sqlite3_prepare16_v3() interfaces are recommended for all new programs.
  1.1596 +** The older interfaces (sqlite3_prepare() and sqlite3_prepare16())
  1.1597 +** are retained for backwards compatibility, but their use is discouraged.
  1.1598 +** ^In the "vX" interfaces, the prepared statement
  1.1599  ** that is returned (the [sqlite3_stmt] object) contains a copy of the
  1.1600  ** original SQL text. This causes the [sqlite3_step()] interface to
  1.1601  ** behave differently in three ways:
  1.1602 @@ -3826,6 +4774,12 @@
  1.1603  ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
  1.1604  ** </li>
  1.1605  ** </ol>
  1.1606 +**
  1.1607 +** <p>^sqlite3_prepare_v3() differs from sqlite3_prepare_v2() only in having
  1.1608 +** the extra prepFlags parameter, which is a bit array consisting of zero or
  1.1609 +** more of the [SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_*] flags.  ^The
  1.1610 +** sqlite3_prepare_v2() interface works exactly the same as
  1.1611 +** sqlite3_prepare_v3() with a zero prepFlags parameter.
  1.1612  */
  1.1613  SQLITE_API int sqlite3_prepare(
  1.1614    sqlite3 *db,            /* Database handle */
  1.1615 @@ -3841,6 +4795,14 @@
  1.1616    sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  1.1617    const char **pzTail     /* OUT: Pointer to unused portion of zSql */
  1.1618  );
  1.1619 +SQLITE_API int sqlite3_prepare_v3(
  1.1620 +  sqlite3 *db,            /* Database handle */
  1.1621 +  const char *zSql,       /* SQL statement, UTF-8 encoded */
  1.1622 +  int nByte,              /* Maximum length of zSql in bytes. */
  1.1623 +  unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
  1.1624 +  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  1.1625 +  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
  1.1626 +);
  1.1627  SQLITE_API int sqlite3_prepare16(
  1.1628    sqlite3 *db,            /* Database handle */
  1.1629    const void *zSql,       /* SQL statement, UTF-16 encoded */
  1.1630 @@ -3855,6 +4817,14 @@
  1.1631    sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  1.1632    const void **pzTail     /* OUT: Pointer to unused portion of zSql */
  1.1633  );
  1.1634 +SQLITE_API int sqlite3_prepare16_v3(
  1.1635 +  sqlite3 *db,            /* Database handle */
  1.1636 +  const void *zSql,       /* SQL statement, UTF-16 encoded */
  1.1637 +  int nByte,              /* Maximum length of zSql in bytes. */
  1.1638 +  unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
  1.1639 +  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  1.1640 +  const void **pzTail     /* OUT: Pointer to unused portion of zSql */
  1.1641 +);
  1.1642  
  1.1643  /*
  1.1644  ** CAPI3REF: Retrieving Statement SQL
  1.1645 @@ -3862,10 +4832,16 @@
  1.1646  **
  1.1647  ** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8
  1.1648  ** SQL text used to create [prepared statement] P if P was
  1.1649 -** created by either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
  1.1650 +** created by [sqlite3_prepare_v2()], [sqlite3_prepare_v3()],
  1.1651 +** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
  1.1652  ** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8
  1.1653  ** string containing the SQL text of prepared statement P with
  1.1654  ** [bound parameters] expanded.
  1.1655 +** ^The sqlite3_normalized_sql(P) interface returns a pointer to a UTF-8
  1.1656 +** string containing the normalized SQL text of prepared statement P.  The
  1.1657 +** semantics used to normalize a SQL statement are unspecified and subject
  1.1658 +** to change.  At a minimum, literal values will be replaced with suitable
  1.1659 +** placeholders.
  1.1660  **
  1.1661  ** ^(For example, if a prepared statement is created using the SQL
  1.1662  ** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345
  1.1663 @@ -3881,14 +4857,16 @@
  1.1664  ** bound parameter expansions.  ^The [SQLITE_OMIT_TRACE] compile-time
  1.1665  ** option causes sqlite3_expanded_sql() to always return NULL.
  1.1666  **
  1.1667 -** ^The string returned by sqlite3_sql(P) is managed by SQLite and is
  1.1668 -** automatically freed when the prepared statement is finalized.
  1.1669 +** ^The strings returned by sqlite3_sql(P) and sqlite3_normalized_sql(P)
  1.1670 +** are managed by SQLite and are automatically freed when the prepared
  1.1671 +** statement is finalized.
  1.1672  ** ^The string returned by sqlite3_expanded_sql(P), on the other hand,
  1.1673  ** is obtained from [sqlite3_malloc()] and must be free by the application
  1.1674  ** by passing it to [sqlite3_free()].
  1.1675  */
  1.1676  SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
  1.1677  SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt);
  1.1678 +SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt);
  1.1679  
  1.1680  /*
  1.1681  ** CAPI3REF: Determine If An SQL Statement Writes The Database
  1.1682 @@ -3981,8 +4959,9 @@
  1.1683  ** implementation of [application-defined SQL functions] are protected.
  1.1684  ** ^The sqlite3_value object returned by
  1.1685  ** [sqlite3_column_value()] is unprotected.
  1.1686 -** Unprotected sqlite3_value objects may only be used with
  1.1687 -** [sqlite3_result_value()] and [sqlite3_bind_value()].
  1.1688 +** Unprotected sqlite3_value objects may only be used as arguments
  1.1689 +** to [sqlite3_result_value()], [sqlite3_bind_value()], and
  1.1690 +** [sqlite3_value_dup()].
  1.1691  ** The [sqlite3_value_blob | sqlite3_value_type()] family of
  1.1692  ** interfaces require protected sqlite3_value objects.
  1.1693  */
  1.1694 @@ -4088,6 +5067,15 @@
  1.1695  ** [sqlite3_blob_open | incremental BLOB I/O] routines.
  1.1696  ** ^A negative value for the zeroblob results in a zero-length BLOB.
  1.1697  **
  1.1698 +** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in
  1.1699 +** [prepared statement] S to have an SQL value of NULL, but to also be
  1.1700 +** associated with the pointer P of type T.  ^D is either a NULL pointer or
  1.1701 +** a pointer to a destructor function for P. ^SQLite will invoke the
  1.1702 +** destructor D with a single argument of P when it is finished using
  1.1703 +** P.  The T parameter should be a static string, preferably a string
  1.1704 +** literal. The sqlite3_bind_pointer() routine is part of the
  1.1705 +** [pointer passing interface] added for SQLite 3.20.0.
  1.1706 +**
  1.1707  ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
  1.1708  ** for the [prepared statement] or with a prepared statement for which
  1.1709  ** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
  1.1710 @@ -4121,6 +5109,7 @@
  1.1711  SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
  1.1712                           void(*)(void*), unsigned char encoding);
  1.1713  SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
  1.1714 +SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*));
  1.1715  SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
  1.1716  SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
  1.1717  
  1.1718 @@ -4164,8 +5153,8 @@
  1.1719  ** ^If the value N is out of range or if the N-th parameter is
  1.1720  ** nameless, then NULL is returned.  ^The returned string is
  1.1721  ** always in UTF-8 encoding even if the named parameter was
  1.1722 -** originally specified as UTF-16 in [sqlite3_prepare16()] or
  1.1723 -** [sqlite3_prepare16_v2()].
  1.1724 +** originally specified as UTF-16 in [sqlite3_prepare16()],
  1.1725 +** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
  1.1726  **
  1.1727  ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  1.1728  ** [sqlite3_bind_parameter_count()], and
  1.1729 @@ -4182,7 +5171,8 @@
  1.1730  ** parameter to [sqlite3_bind_blob|sqlite3_bind()].  ^A zero
  1.1731  ** is returned if no matching parameter is found.  ^The parameter
  1.1732  ** name must be given in UTF-8 even if the original statement
  1.1733 -** was prepared from UTF-16 text using [sqlite3_prepare16_v2()].
  1.1734 +** was prepared from UTF-16 text using [sqlite3_prepare16_v2()] or
  1.1735 +** [sqlite3_prepare16_v3()].
  1.1736  **
  1.1737  ** See also: [sqlite3_bind_blob|sqlite3_bind()],
  1.1738  ** [sqlite3_bind_parameter_count()], and
  1.1739 @@ -4336,16 +5326,18 @@
  1.1740  ** CAPI3REF: Evaluate An SQL Statement
  1.1741  ** METHOD: sqlite3_stmt
  1.1742  **
  1.1743 -** After a [prepared statement] has been prepared using either
  1.1744 -** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
  1.1745 +** After a [prepared statement] has been prepared using any of
  1.1746 +** [sqlite3_prepare_v2()], [sqlite3_prepare_v3()], [sqlite3_prepare16_v2()],
  1.1747 +** or [sqlite3_prepare16_v3()] or one of the legacy
  1.1748  ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
  1.1749  ** must be called one or more times to evaluate the statement.
  1.1750  **
  1.1751  ** The details of the behavior of the sqlite3_step() interface depend
  1.1752 -** on whether the statement was prepared using the newer "v2" interface
  1.1753 -** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy
  1.1754 -** interface [sqlite3_prepare()] and [sqlite3_prepare16()].  The use of the
  1.1755 -** new "v2" interface is recommended for new applications but the legacy
  1.1756 +** on whether the statement was prepared using the newer "vX" interfaces
  1.1757 +** [sqlite3_prepare_v3()], [sqlite3_prepare_v2()], [sqlite3_prepare16_v3()],
  1.1758 +** [sqlite3_prepare16_v2()] or the older legacy
  1.1759 +** interfaces [sqlite3_prepare()] and [sqlite3_prepare16()].  The use of the
  1.1760 +** new "vX" interface is recommended for new applications but the legacy
  1.1761  ** interface will continue to be supported.
  1.1762  **
  1.1763  ** ^In the legacy interface, the return value will be either [SQLITE_BUSY],
  1.1764 @@ -4406,10 +5398,11 @@
  1.1765  ** specific [error codes] that better describes the error.
  1.1766  ** We admit that this is a goofy design.  The problem has been fixed
  1.1767  ** with the "v2" interface.  If you prepare all of your SQL statements
  1.1768 -** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead
  1.1769 +** using [sqlite3_prepare_v3()] or [sqlite3_prepare_v2()]
  1.1770 +** or [sqlite3_prepare16_v2()] or [sqlite3_prepare16_v3()] instead
  1.1771  ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
  1.1772  ** then the more specific [error codes] are returned directly
  1.1773 -** by sqlite3_step().  The use of the "v2" interface is recommended.
  1.1774 +** by sqlite3_step().  The use of the "vX" interfaces is recommended.
  1.1775  */
  1.1776  SQLITE_API int sqlite3_step(sqlite3_stmt*);
  1.1777  
  1.1778 @@ -4471,6 +5464,28 @@
  1.1779  ** KEYWORDS: {column access functions}
  1.1780  ** METHOD: sqlite3_stmt
  1.1781  **
  1.1782 +** <b>Summary:</b>
  1.1783 +** <blockquote><table border=0 cellpadding=0 cellspacing=0>
  1.1784 +** <tr><td><b>sqlite3_column_blob</b><td>&rarr;<td>BLOB result
  1.1785 +** <tr><td><b>sqlite3_column_double</b><td>&rarr;<td>REAL result
  1.1786 +** <tr><td><b>sqlite3_column_int</b><td>&rarr;<td>32-bit INTEGER result
  1.1787 +** <tr><td><b>sqlite3_column_int64</b><td>&rarr;<td>64-bit INTEGER result
  1.1788 +** <tr><td><b>sqlite3_column_text</b><td>&rarr;<td>UTF-8 TEXT result
  1.1789 +** <tr><td><b>sqlite3_column_text16</b><td>&rarr;<td>UTF-16 TEXT result
  1.1790 +** <tr><td><b>sqlite3_column_value</b><td>&rarr;<td>The result as an 
  1.1791 +** [sqlite3_value|unprotected sqlite3_value] object.
  1.1792 +** <tr><td>&nbsp;<td>&nbsp;<td>&nbsp;
  1.1793 +** <tr><td><b>sqlite3_column_bytes</b><td>&rarr;<td>Size of a BLOB
  1.1794 +** or a UTF-8 TEXT result in bytes
  1.1795 +** <tr><td><b>sqlite3_column_bytes16&nbsp;&nbsp;</b>
  1.1796 +** <td>&rarr;&nbsp;&nbsp;<td>Size of UTF-16
  1.1797 +** TEXT in bytes
  1.1798 +** <tr><td><b>sqlite3_column_type</b><td>&rarr;<td>Default
  1.1799 +** datatype of the result
  1.1800 +** </table></blockquote>
  1.1801 +**
  1.1802 +** <b>Details:</b>
  1.1803 +**
  1.1804  ** ^These routines return information about a single column of the current
  1.1805  ** result row of a query.  ^In every case the first argument is a pointer
  1.1806  ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
  1.1807 @@ -4492,16 +5507,29 @@
  1.1808  ** are called from a different thread while any of these routines
  1.1809  ** are pending, then the results are undefined.
  1.1810  **
  1.1811 +** The first six interfaces (_blob, _double, _int, _int64, _text, and _text16)
  1.1812 +** each return the value of a result column in a specific data format.  If
  1.1813 +** the result column is not initially in the requested format (for example,
  1.1814 +** if the query returns an integer but the sqlite3_column_text() interface
  1.1815 +** is used to extract the value) then an automatic type conversion is performed.
  1.1816 +**
  1.1817  ** ^The sqlite3_column_type() routine returns the
  1.1818  ** [SQLITE_INTEGER | datatype code] for the initial data type
  1.1819  ** of the result column.  ^The returned value is one of [SQLITE_INTEGER],
  1.1820 -** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].  The value
  1.1821 -** returned by sqlite3_column_type() is only meaningful if no type
  1.1822 -** conversions have occurred as described below.  After a type conversion,
  1.1823 -** the value returned by sqlite3_column_type() is undefined.  Future
  1.1824 +** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].
  1.1825 +** The return value of sqlite3_column_type() can be used to decide which
  1.1826 +** of the first six interface should be used to extract the column value.
  1.1827 +** The value returned by sqlite3_column_type() is only meaningful if no
  1.1828 +** automatic type conversions have occurred for the value in question.  
  1.1829 +** After a type conversion, the result of calling sqlite3_column_type()
  1.1830 +** is undefined, though harmless.  Future
  1.1831  ** versions of SQLite may change the behavior of sqlite3_column_type()
  1.1832  ** following a type conversion.
  1.1833  **
  1.1834 +** If the result is a BLOB or a TEXT string, then the sqlite3_column_bytes()
  1.1835 +** or sqlite3_column_bytes16() interfaces can be used to determine the size
  1.1836 +** of that BLOB or string.
  1.1837 +**
  1.1838  ** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
  1.1839  ** routine returns the number of bytes in that BLOB or string.
  1.1840  ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
  1.1841 @@ -4538,9 +5566,13 @@
  1.1842  ** [sqlite3_column_value()] is used in any other way, including calls
  1.1843  ** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
  1.1844  ** or [sqlite3_value_bytes()], the behavior is not threadsafe.
  1.1845 -**
  1.1846 -** These routines attempt to convert the value where appropriate.  ^For
  1.1847 -** example, if the internal representation is FLOAT and a text result
  1.1848 +** Hence, the sqlite3_column_value() interface
  1.1849 +** is normally only useful within the implementation of 
  1.1850 +** [application-defined SQL functions] or [virtual tables], not within
  1.1851 +** top-level application code.
  1.1852 +**
  1.1853 +** The these routines may attempt to convert the datatype of the result.
  1.1854 +** ^For example, if the internal representation is FLOAT and a text result
  1.1855  ** is requested, [sqlite3_snprintf()] is used internally to perform the
  1.1856  ** conversion automatically.  ^(The following table details the conversions
  1.1857  ** that are applied:
  1.1858 @@ -4612,26 +5644,40 @@
  1.1859  ** ^The pointers returned are valid until a type conversion occurs as
  1.1860  ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
  1.1861  ** [sqlite3_finalize()] is called.  ^The memory space used to hold strings
  1.1862 -** and BLOBs is freed automatically.  Do <em>not</em> pass the pointers returned
  1.1863 +** and BLOBs is freed automatically.  Do not pass the pointers returned
  1.1864  ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
  1.1865  ** [sqlite3_free()].
  1.1866  **
  1.1867 -** ^(If a memory allocation error occurs during the evaluation of any
  1.1868 -** of these routines, a default value is returned.  The default value
  1.1869 -** is either the integer 0, the floating point number 0.0, or a NULL
  1.1870 -** pointer.  Subsequent calls to [sqlite3_errcode()] will return
  1.1871 -** [SQLITE_NOMEM].)^
  1.1872 +** As long as the input parameters are correct, these routines will only
  1.1873 +** fail if an out-of-memory error occurs during a format conversion.
  1.1874 +** Only the following subset of interfaces are subject to out-of-memory
  1.1875 +** errors:
  1.1876 +**
  1.1877 +** <ul>
  1.1878 +** <li> sqlite3_column_blob()
  1.1879 +** <li> sqlite3_column_text()
  1.1880 +** <li> sqlite3_column_text16()
  1.1881 +** <li> sqlite3_column_bytes()
  1.1882 +** <li> sqlite3_column_bytes16()
  1.1883 +** </ul>
  1.1884 +**
  1.1885 +** If an out-of-memory error occurs, then the return value from these
  1.1886 +** routines is the same as if the column had contained an SQL NULL value.
  1.1887 +** Valid SQL NULL returns can be distinguished from out-of-memory errors
  1.1888 +** by invoking the [sqlite3_errcode()] immediately after the suspect
  1.1889 +** return value is obtained and before any
  1.1890 +** other SQLite interface is called on the same [database connection].
  1.1891  */
  1.1892  SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
  1.1893 -SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
  1.1894 -SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
  1.1895  SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol);
  1.1896  SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol);
  1.1897  SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
  1.1898  SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
  1.1899  SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
  1.1900 +SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
  1.1901 +SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
  1.1902 +SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
  1.1903  SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);
  1.1904 -SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
  1.1905  
  1.1906  /*
  1.1907  ** CAPI3REF: Destroy A Prepared Statement Object
  1.1908 @@ -4697,11 +5743,13 @@
  1.1909  **
  1.1910  ** ^These functions (collectively known as "function creation routines")
  1.1911  ** are used to add SQL functions or aggregates or to redefine the behavior
  1.1912 -** of existing SQL functions or aggregates.  The only differences between
  1.1913 -** these routines are the text encoding expected for
  1.1914 -** the second parameter (the name of the function being created)
  1.1915 -** and the presence or absence of a destructor callback for
  1.1916 -** the application data pointer.
  1.1917 +** of existing SQL functions or aggregates. The only differences between
  1.1918 +** the three "sqlite3_create_function*" routines are the text encoding 
  1.1919 +** expected for the second parameter (the name of the function being 
  1.1920 +** created) and the presence or absence of a destructor callback for
  1.1921 +** the application data pointer. Function sqlite3_create_window_function()
  1.1922 +** is similar, but allows the user to supply the extra callback functions
  1.1923 +** needed by [aggregate window functions].
  1.1924  **
  1.1925  ** ^The first parameter is the [database connection] to which the SQL
  1.1926  ** function is to be added.  ^If an application uses more than one database
  1.1927 @@ -4747,7 +5795,8 @@
  1.1928  ** ^(The fifth parameter is an arbitrary pointer.  The implementation of the
  1.1929  ** function can gain access to this pointer using [sqlite3_user_data()].)^
  1.1930  **
  1.1931 -** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
  1.1932 +** ^The sixth, seventh and eighth parameters passed to the three
  1.1933 +** "sqlite3_create_function*" functions, xFunc, xStep and xFinal, are
  1.1934  ** pointers to C-language functions that implement the SQL function or
  1.1935  ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
  1.1936  ** callback only; NULL pointers must be passed as the xStep and xFinal
  1.1937 @@ -4756,15 +5805,24 @@
  1.1938  ** SQL function or aggregate, pass NULL pointers for all three function
  1.1939  ** callbacks.
  1.1940  **
  1.1941 -** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL,
  1.1942 -** then it is destructor for the application data pointer. 
  1.1943 -** The destructor is invoked when the function is deleted, either by being
  1.1944 -** overloaded or when the database connection closes.)^
  1.1945 -** ^The destructor is also invoked if the call to
  1.1946 -** sqlite3_create_function_v2() fails.
  1.1947 -** ^When the destructor callback of the tenth parameter is invoked, it
  1.1948 -** is passed a single argument which is a copy of the application data 
  1.1949 -** pointer which was the fifth parameter to sqlite3_create_function_v2().
  1.1950 +** ^The sixth, seventh, eighth and ninth parameters (xStep, xFinal, xValue 
  1.1951 +** and xInverse) passed to sqlite3_create_window_function are pointers to
  1.1952 +** C-language callbacks that implement the new function. xStep and xFinal
  1.1953 +** must both be non-NULL. xValue and xInverse may either both be NULL, in
  1.1954 +** which case a regular aggregate function is created, or must both be 
  1.1955 +** non-NULL, in which case the new function may be used as either an aggregate
  1.1956 +** or aggregate window function. More details regarding the implementation
  1.1957 +** of aggregate window functions are 
  1.1958 +** [user-defined window functions|available here].
  1.1959 +**
  1.1960 +** ^(If the final parameter to sqlite3_create_function_v2() or
  1.1961 +** sqlite3_create_window_function() is not NULL, then it is destructor for
  1.1962 +** the application data pointer. The destructor is invoked when the function 
  1.1963 +** is deleted, either by being overloaded or when the database connection 
  1.1964 +** closes.)^ ^The destructor is also invoked if the call to 
  1.1965 +** sqlite3_create_function_v2() fails.  ^When the destructor callback is
  1.1966 +** invoked, it is passed a single argument which is a copy of the application
  1.1967 +** data pointer which was the fifth parameter to sqlite3_create_function_v2().
  1.1968  **
  1.1969  ** ^It is permitted to register multiple implementations of the same
  1.1970  ** functions with the same name but with either differing numbers of
  1.1971 @@ -4817,6 +5875,18 @@
  1.1972    void (*xFinal)(sqlite3_context*),
  1.1973    void(*xDestroy)(void*)
  1.1974  );
  1.1975 +SQLITE_API int sqlite3_create_window_function(
  1.1976 +  sqlite3 *db,
  1.1977 +  const char *zFunctionName,
  1.1978 +  int nArg,
  1.1979 +  int eTextRep,
  1.1980 +  void *pApp,
  1.1981 +  void (*xStep)(sqlite3_context*,int,sqlite3_value**),
  1.1982 +  void (*xFinal)(sqlite3_context*),
  1.1983 +  void (*xValue)(sqlite3_context*),
  1.1984 +  void (*xInverse)(sqlite3_context*,int,sqlite3_value**),
  1.1985 +  void(*xDestroy)(void*)
  1.1986 +);
  1.1987  
  1.1988  /*
  1.1989  ** CAPI3REF: Text Encodings
  1.1990 @@ -4865,21 +5935,43 @@
  1.1991  ** CAPI3REF: Obtaining SQL Values
  1.1992  ** METHOD: sqlite3_value
  1.1993  **
  1.1994 -** The C-language implementation of SQL functions and aggregates uses
  1.1995 -** this set of interface routines to access the parameter values on
  1.1996 -** the function or aggregate.  
  1.1997 -**
  1.1998 -** The xFunc (for scalar functions) or xStep (for aggregates) parameters
  1.1999 -** to [sqlite3_create_function()] and [sqlite3_create_function16()]
  1.2000 -** define callbacks that implement the SQL functions and aggregates.
  1.2001 -** The 3rd parameter to these callbacks is an array of pointers to
  1.2002 -** [protected sqlite3_value] objects.  There is one [sqlite3_value] object for
  1.2003 -** each parameter to the SQL function.  These routines are used to
  1.2004 -** extract values from the [sqlite3_value] objects.
  1.2005 +** <b>Summary:</b>
  1.2006 +** <blockquote><table border=0 cellpadding=0 cellspacing=0>
  1.2007 +** <tr><td><b>sqlite3_value_blob</b><td>&rarr;<td>BLOB value
  1.2008 +** <tr><td><b>sqlite3_value_double</b><td>&rarr;<td>REAL value
  1.2009 +** <tr><td><b>sqlite3_value_int</b><td>&rarr;<td>32-bit INTEGER value
  1.2010 +** <tr><td><b>sqlite3_value_int64</b><td>&rarr;<td>64-bit INTEGER value
  1.2011 +** <tr><td><b>sqlite3_value_pointer</b><td>&rarr;<td>Pointer value
  1.2012 +** <tr><td><b>sqlite3_value_text</b><td>&rarr;<td>UTF-8 TEXT value
  1.2013 +** <tr><td><b>sqlite3_value_text16</b><td>&rarr;<td>UTF-16 TEXT value in
  1.2014 +** the native byteorder
  1.2015 +** <tr><td><b>sqlite3_value_text16be</b><td>&rarr;<td>UTF-16be TEXT value
  1.2016 +** <tr><td><b>sqlite3_value_text16le</b><td>&rarr;<td>UTF-16le TEXT value
  1.2017 +** <tr><td>&nbsp;<td>&nbsp;<td>&nbsp;
  1.2018 +** <tr><td><b>sqlite3_value_bytes</b><td>&rarr;<td>Size of a BLOB
  1.2019 +** or a UTF-8 TEXT in bytes
  1.2020 +** <tr><td><b>sqlite3_value_bytes16&nbsp;&nbsp;</b>
  1.2021 +** <td>&rarr;&nbsp;&nbsp;<td>Size of UTF-16
  1.2022 +** TEXT in bytes
  1.2023 +** <tr><td><b>sqlite3_value_type</b><td>&rarr;<td>Default
  1.2024 +** datatype of the value
  1.2025 +** <tr><td><b>sqlite3_value_numeric_type&nbsp;&nbsp;</b>
  1.2026 +** <td>&rarr;&nbsp;&nbsp;<td>Best numeric datatype of the value
  1.2027 +** <tr><td><b>sqlite3_value_nochange&nbsp;&nbsp;</b>
  1.2028 +** <td>&rarr;&nbsp;&nbsp;<td>True if the column is unchanged in an UPDATE
  1.2029 +** against a virtual table.
  1.2030 +** </table></blockquote>
  1.2031 +**
  1.2032 +** <b>Details:</b>
  1.2033 +**
  1.2034 +** These routines extract type, size, and content information from
  1.2035 +** [protected sqlite3_value] objects.  Protected sqlite3_value objects
  1.2036 +** are used to pass parameter information into implementation of
  1.2037 +** [application-defined SQL functions] and [virtual tables].
  1.2038  **
  1.2039  ** These routines work only with [protected sqlite3_value] objects.
  1.2040  ** Any attempt to use these routines on an [unprotected sqlite3_value]
  1.2041 -** object results in undefined behavior.
  1.2042 +** is not threadsafe.
  1.2043  **
  1.2044  ** ^These routines work just like the corresponding [column access functions]
  1.2045  ** except that these routines take a single [protected sqlite3_value] object
  1.2046 @@ -4890,6 +5982,24 @@
  1.2047  ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
  1.2048  ** extract UTF-16 strings as big-endian and little-endian respectively.
  1.2049  **
  1.2050 +** ^If [sqlite3_value] object V was initialized 
  1.2051 +** using [sqlite3_bind_pointer(S,I,P,X,D)] or [sqlite3_result_pointer(C,P,X,D)]
  1.2052 +** and if X and Y are strings that compare equal according to strcmp(X,Y),
  1.2053 +** then sqlite3_value_pointer(V,Y) will return the pointer P.  ^Otherwise,
  1.2054 +** sqlite3_value_pointer(V,Y) returns a NULL. The sqlite3_bind_pointer() 
  1.2055 +** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
  1.2056 +**
  1.2057 +** ^(The sqlite3_value_type(V) interface returns the
  1.2058 +** [SQLITE_INTEGER | datatype code] for the initial datatype of the
  1.2059 +** [sqlite3_value] object V. The returned value is one of [SQLITE_INTEGER],
  1.2060 +** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].)^
  1.2061 +** Other interfaces might change the datatype for an sqlite3_value object.
  1.2062 +** For example, if the datatype is initially SQLITE_INTEGER and
  1.2063 +** sqlite3_value_text(V) is called to extract a text value for that
  1.2064 +** integer, then subsequent calls to sqlite3_value_type(V) might return
  1.2065 +** SQLITE_TEXT.  Whether or not a persistent internal datatype conversion
  1.2066 +** occurs is undefined and may change from one release of SQLite to the next.
  1.2067 +**
  1.2068  ** ^(The sqlite3_value_numeric_type() interface attempts to apply
  1.2069  ** numeric affinity to the value.  This means that an attempt is
  1.2070  ** made to convert the value to an integer or floating point.  If
  1.2071 @@ -4898,6 +6008,19 @@
  1.2072  ** then the conversion is performed.  Otherwise no conversion occurs.
  1.2073  ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
  1.2074  **
  1.2075 +** ^Within the [xUpdate] method of a [virtual table], the
  1.2076 +** sqlite3_value_nochange(X) interface returns true if and only if
  1.2077 +** the column corresponding to X is unchanged by the UPDATE operation
  1.2078 +** that the xUpdate method call was invoked to implement and if
  1.2079 +** and the prior [xColumn] method call that was invoked to extracted
  1.2080 +** the value for that column returned without setting a result (probably
  1.2081 +** because it queried [sqlite3_vtab_nochange()] and found that the column
  1.2082 +** was unchanging).  ^Within an [xUpdate] method, any value for which
  1.2083 +** sqlite3_value_nochange(X) is true will in all other respects appear
  1.2084 +** to be a NULL value.  If sqlite3_value_nochange(X) is invoked anywhere other
  1.2085 +** than within an [xUpdate] method call for an UPDATE statement, then
  1.2086 +** the return value is arbitrary and meaningless.
  1.2087 +**
  1.2088  ** Please pay particular attention to the fact that the pointer returned
  1.2089  ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
  1.2090  ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
  1.2091 @@ -4906,19 +6029,43 @@
  1.2092  **
  1.2093  ** These routines must be called from the same thread as
  1.2094  ** the SQL function that supplied the [sqlite3_value*] parameters.
  1.2095 +**
  1.2096 +** As long as the input parameter is correct, these routines can only
  1.2097 +** fail if an out-of-memory error occurs during a format conversion.
  1.2098 +** Only the following subset of interfaces are subject to out-of-memory
  1.2099 +** errors:
  1.2100 +**
  1.2101 +** <ul>
  1.2102 +** <li> sqlite3_value_blob()
  1.2103 +** <li> sqlite3_value_text()
  1.2104 +** <li> sqlite3_value_text16()
  1.2105 +** <li> sqlite3_value_text16le()
  1.2106 +** <li> sqlite3_value_text16be()
  1.2107 +** <li> sqlite3_value_bytes()
  1.2108 +** <li> sqlite3_value_bytes16()
  1.2109 +** </ul>
  1.2110 +**
  1.2111 +** If an out-of-memory error occurs, then the return value from these
  1.2112 +** routines is the same as if the column had contained an SQL NULL value.
  1.2113 +** Valid SQL NULL returns can be distinguished from out-of-memory errors
  1.2114 +** by invoking the [sqlite3_errcode()] immediately after the suspect
  1.2115 +** return value is obtained and before any
  1.2116 +** other SQLite interface is called on the same [database connection].
  1.2117  */
  1.2118  SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
  1.2119 -SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
  1.2120 -SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
  1.2121  SQLITE_API double sqlite3_value_double(sqlite3_value*);
  1.2122  SQLITE_API int sqlite3_value_int(sqlite3_value*);
  1.2123  SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
  1.2124 +SQLITE_API void *sqlite3_value_pointer(sqlite3_value*, const char*);
  1.2125  SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
  1.2126  SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
  1.2127  SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
  1.2128  SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
  1.2129 +SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
  1.2130 +SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
  1.2131  SQLITE_API int sqlite3_value_type(sqlite3_value*);
  1.2132  SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
  1.2133 +SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
  1.2134  
  1.2135  /*
  1.2136  ** CAPI3REF: Finding The Subtype Of SQL Values
  1.2137 @@ -4929,10 +6076,6 @@
  1.2138  ** information can be used to pass a limited amount of context from
  1.2139  ** one SQL function to another.  Use the [sqlite3_result_subtype()]
  1.2140  ** routine to set the subtype for the return value of an SQL function.
  1.2141 -**
  1.2142 -** SQLite makes no use of subtype itself.  It merely passes the subtype
  1.2143 -** from the result of one [application-defined SQL function] into the
  1.2144 -** input of another.
  1.2145  */
  1.2146  SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*);
  1.2147  
  1.2148 @@ -5202,7 +6345,7 @@
  1.2149  ** when it has finished using that result.
  1.2150  ** ^If the 4th parameter to the sqlite3_result_text* interfaces
  1.2151  ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
  1.2152 -** then SQLite makes a copy of the result into space obtained from
  1.2153 +** then SQLite makes a copy of the result into space obtained
  1.2154  ** from [sqlite3_malloc()] before it returns.
  1.2155  **
  1.2156  ** ^The sqlite3_result_value() interface sets the result of
  1.2157 @@ -5215,6 +6358,17 @@
  1.2158  ** [unprotected sqlite3_value] object is required, so either
  1.2159  ** kind of [sqlite3_value] object can be used with this interface.
  1.2160  **
  1.2161 +** ^The sqlite3_result_pointer(C,P,T,D) interface sets the result to an
  1.2162 +** SQL NULL value, just like [sqlite3_result_null(C)], except that it
  1.2163 +** also associates the host-language pointer P or type T with that 
  1.2164 +** NULL value such that the pointer can be retrieved within an
  1.2165 +** [application-defined SQL function] using [sqlite3_value_pointer()].
  1.2166 +** ^If the D parameter is not NULL, then it is a pointer to a destructor
  1.2167 +** for the P parameter.  ^SQLite invokes D with P as its only argument
  1.2168 +** when SQLite is finished with P.  The T parameter should be a static
  1.2169 +** string and preferably a string literal. The sqlite3_result_pointer()
  1.2170 +** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
  1.2171 +**
  1.2172  ** If these routines are called from within the different thread
  1.2173  ** than the one containing the application-defined function that received
  1.2174  ** the [sqlite3_context] pointer, the results are undefined.
  1.2175 @@ -5238,6 +6392,7 @@
  1.2176  SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
  1.2177  SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
  1.2178  SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
  1.2179 +SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*,const char*,void(*)(void*));
  1.2180  SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
  1.2181  SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
  1.2182  
  1.2183 @@ -5567,6 +6722,41 @@
  1.2184  SQLITE_API char *sqlite3_data_directory;
  1.2185  
  1.2186  /*
  1.2187 +** CAPI3REF: Win32 Specific Interface
  1.2188 +**
  1.2189 +** These interfaces are available only on Windows.  The
  1.2190 +** [sqlite3_win32_set_directory] interface is used to set the value associated
  1.2191 +** with the [sqlite3_temp_directory] or [sqlite3_data_directory] variable, to
  1.2192 +** zValue, depending on the value of the type parameter.  The zValue parameter
  1.2193 +** should be NULL to cause the previous value to be freed via [sqlite3_free];
  1.2194 +** a non-NULL value will be copied into memory obtained from [sqlite3_malloc]
  1.2195 +** prior to being used.  The [sqlite3_win32_set_directory] interface returns
  1.2196 +** [SQLITE_OK] to indicate success, [SQLITE_ERROR] if the type is unsupported,
  1.2197 +** or [SQLITE_NOMEM] if memory could not be allocated.  The value of the
  1.2198 +** [sqlite3_data_directory] variable is intended to act as a replacement for
  1.2199 +** the current directory on the sub-platforms of Win32 where that concept is
  1.2200 +** not present, e.g. WinRT and UWP.  The [sqlite3_win32_set_directory8] and
  1.2201 +** [sqlite3_win32_set_directory16] interfaces behave exactly the same as the
  1.2202 +** sqlite3_win32_set_directory interface except the string parameter must be
  1.2203 +** UTF-8 or UTF-16, respectively.
  1.2204 +*/
  1.2205 +SQLITE_API int sqlite3_win32_set_directory(
  1.2206 +  unsigned long type, /* Identifier for directory being set or reset */
  1.2207 +  void *zValue        /* New value for directory being set or reset */
  1.2208 +);
  1.2209 +SQLITE_API int sqlite3_win32_set_directory8(unsigned long type, const char *zValue);
  1.2210 +SQLITE_API int sqlite3_win32_set_directory16(unsigned long type, const void *zValue);
  1.2211 +
  1.2212 +/*
  1.2213 +** CAPI3REF: Win32 Directory Types
  1.2214 +**
  1.2215 +** These macros are only available on Windows.  They define the allowed values
  1.2216 +** for the type argument to the [sqlite3_win32_set_directory] interface.
  1.2217 +*/
  1.2218 +#define SQLITE_WIN32_DATA_DIRECTORY_TYPE  1
  1.2219 +#define SQLITE_WIN32_TEMP_DIRECTORY_TYPE  2
  1.2220 +
  1.2221 +/*
  1.2222  ** CAPI3REF: Test For Auto-Commit Mode
  1.2223  ** KEYWORDS: {autocommit mode}
  1.2224  ** METHOD: sqlite3
  1.2225 @@ -5897,7 +7087,9 @@
  1.2226  ** ^If the column-name parameter to sqlite3_table_column_metadata() is a
  1.2227  ** NULL pointer, then this routine simply checks for the existence of the
  1.2228  ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
  1.2229 -** does not.
  1.2230 +** does not.  If the table name parameter T in a call to
  1.2231 +** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is
  1.2232 +** undefined behavior.
  1.2233  **
  1.2234  ** ^The column is identified by the second, third and fourth parameters to
  1.2235  ** this function. ^(The second parameter is either the name of the database
  1.2236 @@ -6164,6 +7356,9 @@
  1.2237    int (*xSavepoint)(sqlite3_vtab *pVTab, int);
  1.2238    int (*xRelease)(sqlite3_vtab *pVTab, int);
  1.2239    int (*xRollbackTo)(sqlite3_vtab *pVTab, int);
  1.2240 +  /* The methods above are in versions 1 and 2 of the sqlite_module object.
  1.2241 +  ** Those below are for version 3 and greater. */
  1.2242 +  int (*xShadowName)(const char*);
  1.2243  };
  1.2244  
  1.2245  /*
  1.2246 @@ -6296,6 +7491,10 @@
  1.2247  
  1.2248  /*
  1.2249  ** CAPI3REF: Virtual Table Scan Flags
  1.2250 +**
  1.2251 +** Virtual table implementations are allowed to set the 
  1.2252 +** [sqlite3_index_info].idxFlags field to some combination of
  1.2253 +** these bits.
  1.2254  */
  1.2255  #define SQLITE_INDEX_SCAN_UNIQUE      1     /* Scan visits at most 1 row */
  1.2256  
  1.2257 @@ -6307,15 +7506,21 @@
  1.2258  ** an operator that is part of a constraint term in the wHERE clause of
  1.2259  ** a query that uses a [virtual table].
  1.2260  */
  1.2261 -#define SQLITE_INDEX_CONSTRAINT_EQ      2
  1.2262 -#define SQLITE_INDEX_CONSTRAINT_GT      4
  1.2263 -#define SQLITE_INDEX_CONSTRAINT_LE      8
  1.2264 -#define SQLITE_INDEX_CONSTRAINT_LT     16
  1.2265 -#define SQLITE_INDEX_CONSTRAINT_GE     32
  1.2266 -#define SQLITE_INDEX_CONSTRAINT_MATCH  64
  1.2267 -#define SQLITE_INDEX_CONSTRAINT_LIKE   65
  1.2268 -#define SQLITE_INDEX_CONSTRAINT_GLOB   66
  1.2269 -#define SQLITE_INDEX_CONSTRAINT_REGEXP 67
  1.2270 +#define SQLITE_INDEX_CONSTRAINT_EQ         2
  1.2271 +#define SQLITE_INDEX_CONSTRAINT_GT         4
  1.2272 +#define SQLITE_INDEX_CONSTRAINT_LE         8
  1.2273 +#define SQLITE_INDEX_CONSTRAINT_LT        16
  1.2274 +#define SQLITE_INDEX_CONSTRAINT_GE        32
  1.2275 +#define SQLITE_INDEX_CONSTRAINT_MATCH     64
  1.2276 +#define SQLITE_INDEX_CONSTRAINT_LIKE      65
  1.2277 +#define SQLITE_INDEX_CONSTRAINT_GLOB      66
  1.2278 +#define SQLITE_INDEX_CONSTRAINT_REGEXP    67
  1.2279 +#define SQLITE_INDEX_CONSTRAINT_NE        68
  1.2280 +#define SQLITE_INDEX_CONSTRAINT_ISNOT     69
  1.2281 +#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70
  1.2282 +#define SQLITE_INDEX_CONSTRAINT_ISNULL    71
  1.2283 +#define SQLITE_INDEX_CONSTRAINT_IS        72
  1.2284 +#define SQLITE_INDEX_CONSTRAINT_FUNCTION 150
  1.2285  
  1.2286  /*
  1.2287  ** CAPI3REF: Register A Virtual Table Implementation
  1.2288 @@ -6992,6 +8197,7 @@
  1.2289  /*
  1.2290  ** CAPI3REF: Low-Level Control Of Database Files
  1.2291  ** METHOD: sqlite3
  1.2292 +** KEYWORDS: {file control}
  1.2293  **
  1.2294  ** ^The [sqlite3_file_control()] interface makes a direct call to the
  1.2295  ** xFileControl method for the [sqlite3_io_methods] object associated
  1.2296 @@ -7006,11 +8212,18 @@
  1.2297  ** the xFileControl method.  ^The return value of the xFileControl
  1.2298  ** method becomes the return value of this routine.
  1.2299  **
  1.2300 -** ^The SQLITE_FCNTL_FILE_POINTER value for the op parameter causes
  1.2301 +** A few opcodes for [sqlite3_file_control()] are handled directly
  1.2302 +** by the SQLite core and never invoke the 
  1.2303 +** sqlite3_io_methods.xFileControl method.
  1.2304 +** ^The [SQLITE_FCNTL_FILE_POINTER] value for the op parameter causes
  1.2305  ** a pointer to the underlying [sqlite3_file] object to be written into
  1.2306 -** the space pointed to by the 4th parameter.  ^The SQLITE_FCNTL_FILE_POINTER
  1.2307 -** case is a short-circuit path which does not actually invoke the
  1.2308 -** underlying sqlite3_io_methods.xFileControl method.
  1.2309 +** the space pointed to by the 4th parameter.  The
  1.2310 +** [SQLITE_FCNTL_JOURNAL_POINTER] works similarly except that it returns
  1.2311 +** the [sqlite3_file] object associated with the journal file instead of
  1.2312 +** the main database.  The [SQLITE_FCNTL_VFS_POINTER] opcode returns
  1.2313 +** a pointer to the underlying [sqlite3_vfs] object for the file.
  1.2314 +** The [SQLITE_FCNTL_DATA_VERSION] returns the data version counter
  1.2315 +** from the pager.
  1.2316  **
  1.2317  ** ^If the second parameter (zDbName) does not match the name of any
  1.2318  ** open database file, then SQLITE_ERROR is returned.  ^This error
  1.2319 @@ -7020,7 +8233,7 @@
  1.2320  ** an incorrect zDbName and an SQLITE_ERROR return from the underlying
  1.2321  ** xFileControl method.
  1.2322  **
  1.2323 -** See also: [SQLITE_FCNTL_LOCKSTATE]
  1.2324 +** See also: [file control opcodes]
  1.2325  */
  1.2326  SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
  1.2327  
  1.2328 @@ -7066,8 +8279,9 @@
  1.2329  #define SQLITE_TESTCTRL_ALWAYS                  13
  1.2330  #define SQLITE_TESTCTRL_RESERVE                 14
  1.2331  #define SQLITE_TESTCTRL_OPTIMIZATIONS           15
  1.2332 -#define SQLITE_TESTCTRL_ISKEYWORD               16
  1.2333 -#define SQLITE_TESTCTRL_SCRATCHMALLOC           17
  1.2334 +#define SQLITE_TESTCTRL_ISKEYWORD               16  /* NOT USED */
  1.2335 +#define SQLITE_TESTCTRL_SCRATCHMALLOC           17  /* NOT USED */
  1.2336 +#define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS      17
  1.2337  #define SQLITE_TESTCTRL_LOCALTIME_FAULT         18
  1.2338  #define SQLITE_TESTCTRL_EXPLAIN_STMT            19  /* NOT USED */
  1.2339  #define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD    19
  1.2340 @@ -7077,7 +8291,191 @@
  1.2341  #define SQLITE_TESTCTRL_ISINIT                  23
  1.2342  #define SQLITE_TESTCTRL_SORTER_MMAP             24
  1.2343  #define SQLITE_TESTCTRL_IMPOSTER                25
  1.2344 -#define SQLITE_TESTCTRL_LAST                    25
  1.2345 +#define SQLITE_TESTCTRL_PARSER_COVERAGE         26
  1.2346 +#define SQLITE_TESTCTRL_LAST                    26  /* Largest TESTCTRL */
  1.2347 +
  1.2348 +/*
  1.2349 +** CAPI3REF: SQL Keyword Checking
  1.2350 +**
  1.2351 +** These routines provide access to the set of SQL language keywords 
  1.2352 +** recognized by SQLite.  Applications can uses these routines to determine
  1.2353 +** whether or not a specific identifier needs to be escaped (for example,
  1.2354 +** by enclosing in double-quotes) so as not to confuse the parser.
  1.2355 +**
  1.2356 +** The sqlite3_keyword_count() interface returns the number of distinct
  1.2357 +** keywords understood by SQLite.
  1.2358 +**
  1.2359 +** The sqlite3_keyword_name(N,Z,L) interface finds the N-th keyword and
  1.2360 +** makes *Z point to that keyword expressed as UTF8 and writes the number
  1.2361 +** of bytes in the keyword into *L.  The string that *Z points to is not
  1.2362 +** zero-terminated.  The sqlite3_keyword_name(N,Z,L) routine returns
  1.2363 +** SQLITE_OK if N is within bounds and SQLITE_ERROR if not. If either Z
  1.2364 +** or L are NULL or invalid pointers then calls to
  1.2365 +** sqlite3_keyword_name(N,Z,L) result in undefined behavior.
  1.2366 +**
  1.2367 +** The sqlite3_keyword_check(Z,L) interface checks to see whether or not
  1.2368 +** the L-byte UTF8 identifier that Z points to is a keyword, returning non-zero
  1.2369 +** if it is and zero if not.
  1.2370 +**
  1.2371 +** The parser used by SQLite is forgiving.  It is often possible to use
  1.2372 +** a keyword as an identifier as long as such use does not result in a
  1.2373 +** parsing ambiguity.  For example, the statement
  1.2374 +** "CREATE TABLE BEGIN(REPLACE,PRAGMA,END);" is accepted by SQLite, and
  1.2375 +** creates a new table named "BEGIN" with three columns named
  1.2376 +** "REPLACE", "PRAGMA", and "END".  Nevertheless, best practice is to avoid
  1.2377 +** using keywords as identifiers.  Common techniques used to avoid keyword
  1.2378 +** name collisions include:
  1.2379 +** <ul>
  1.2380 +** <li> Put all identifier names inside double-quotes.  This is the official
  1.2381 +**      SQL way to escape identifier names.
  1.2382 +** <li> Put identifier names inside &#91;...&#93;.  This is not standard SQL,
  1.2383 +**      but it is what SQL Server does and so lots of programmers use this
  1.2384 +**      technique.
  1.2385 +** <li> Begin every identifier with the letter "Z" as no SQL keywords start
  1.2386 +**      with "Z".
  1.2387 +** <li> Include a digit somewhere in every identifier name.
  1.2388 +** </ul>
  1.2389 +**
  1.2390 +** Note that the number of keywords understood by SQLite can depend on
  1.2391 +** compile-time options.  For example, "VACUUM" is not a keyword if
  1.2392 +** SQLite is compiled with the [-DSQLITE_OMIT_VACUUM] option.  Also,
  1.2393 +** new keywords may be added to future releases of SQLite.
  1.2394 +*/
  1.2395 +SQLITE_API int sqlite3_keyword_count(void);
  1.2396 +SQLITE_API int sqlite3_keyword_name(int,const char**,int*);
  1.2397 +SQLITE_API int sqlite3_keyword_check(const char*,int);
  1.2398 +
  1.2399 +/*
  1.2400 +** CAPI3REF: Dynamic String Object
  1.2401 +** KEYWORDS: {dynamic string}
  1.2402 +**
  1.2403 +** An instance of the sqlite3_str object contains a dynamically-sized
  1.2404 +** string under construction.
  1.2405 +**
  1.2406 +** The lifecycle of an sqlite3_str object is as follows:
  1.2407 +** <ol>
  1.2408 +** <li> ^The sqlite3_str object is created using [sqlite3_str_new()].
  1.2409 +** <li> ^Text is appended to the sqlite3_str object using various
  1.2410 +** methods, such as [sqlite3_str_appendf()].
  1.2411 +** <li> ^The sqlite3_str object is destroyed and the string it created
  1.2412 +** is returned using the [sqlite3_str_finish()] interface.
  1.2413 +** </ol>
  1.2414 +*/
  1.2415 +typedef struct sqlite3_str sqlite3_str;
  1.2416 +
  1.2417 +/*
  1.2418 +** CAPI3REF: Create A New Dynamic String Object
  1.2419 +** CONSTRUCTOR: sqlite3_str
  1.2420 +**
  1.2421 +** ^The [sqlite3_str_new(D)] interface allocates and initializes
  1.2422 +** a new [sqlite3_str] object.  To avoid memory leaks, the object returned by
  1.2423 +** [sqlite3_str_new()] must be freed by a subsequent call to 
  1.2424 +** [sqlite3_str_finish(X)].
  1.2425 +**
  1.2426 +** ^The [sqlite3_str_new(D)] interface always returns a pointer to a
  1.2427 +** valid [sqlite3_str] object, though in the event of an out-of-memory
  1.2428 +** error the returned object might be a special singleton that will
  1.2429 +** silently reject new text, always return SQLITE_NOMEM from 
  1.2430 +** [sqlite3_str_errcode()], always return 0 for 
  1.2431 +** [sqlite3_str_length()], and always return NULL from
  1.2432 +** [sqlite3_str_finish(X)].  It is always safe to use the value
  1.2433 +** returned by [sqlite3_str_new(D)] as the sqlite3_str parameter
  1.2434 +** to any of the other [sqlite3_str] methods.
  1.2435 +**
  1.2436 +** The D parameter to [sqlite3_str_new(D)] may be NULL.  If the
  1.2437 +** D parameter in [sqlite3_str_new(D)] is not NULL, then the maximum
  1.2438 +** length of the string contained in the [sqlite3_str] object will be
  1.2439 +** the value set for [sqlite3_limit](D,[SQLITE_LIMIT_LENGTH]) instead
  1.2440 +** of [SQLITE_MAX_LENGTH].
  1.2441 +*/
  1.2442 +SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3*);
  1.2443 +
  1.2444 +/*
  1.2445 +** CAPI3REF: Finalize A Dynamic String
  1.2446 +** DESTRUCTOR: sqlite3_str
  1.2447 +**
  1.2448 +** ^The [sqlite3_str_finish(X)] interface destroys the sqlite3_str object X
  1.2449 +** and returns a pointer to a memory buffer obtained from [sqlite3_malloc64()]
  1.2450 +** that contains the constructed string.  The calling application should
  1.2451 +** pass the returned value to [sqlite3_free()] to avoid a memory leak.
  1.2452 +** ^The [sqlite3_str_finish(X)] interface may return a NULL pointer if any
  1.2453 +** errors were encountered during construction of the string.  ^The
  1.2454 +** [sqlite3_str_finish(X)] interface will also return a NULL pointer if the
  1.2455 +** string in [sqlite3_str] object X is zero bytes long.
  1.2456 +*/
  1.2457 +SQLITE_API char *sqlite3_str_finish(sqlite3_str*);
  1.2458 +
  1.2459 +/*
  1.2460 +** CAPI3REF: Add Content To A Dynamic String
  1.2461 +** METHOD: sqlite3_str
  1.2462 +**
  1.2463 +** These interfaces add content to an sqlite3_str object previously obtained
  1.2464 +** from [sqlite3_str_new()].
  1.2465 +**
  1.2466 +** ^The [sqlite3_str_appendf(X,F,...)] and 
  1.2467 +** [sqlite3_str_vappendf(X,F,V)] interfaces uses the [built-in printf]
  1.2468 +** functionality of SQLite to append formatted text onto the end of 
  1.2469 +** [sqlite3_str] object X.
  1.2470 +**
  1.2471 +** ^The [sqlite3_str_append(X,S,N)] method appends exactly N bytes from string S
  1.2472 +** onto the end of the [sqlite3_str] object X.  N must be non-negative.
  1.2473 +** S must contain at least N non-zero bytes of content.  To append a
  1.2474 +** zero-terminated string in its entirety, use the [sqlite3_str_appendall()]
  1.2475 +** method instead.
  1.2476 +**
  1.2477 +** ^The [sqlite3_str_appendall(X,S)] method appends the complete content of
  1.2478 +** zero-terminated string S onto the end of [sqlite3_str] object X.
  1.2479 +**
  1.2480 +** ^The [sqlite3_str_appendchar(X,N,C)] method appends N copies of the
  1.2481 +** single-byte character C onto the end of [sqlite3_str] object X.
  1.2482 +** ^This method can be used, for example, to add whitespace indentation.
  1.2483 +**
  1.2484 +** ^The [sqlite3_str_reset(X)] method resets the string under construction
  1.2485 +** inside [sqlite3_str] object X back to zero bytes in length.  
  1.2486 +**
  1.2487 +** These methods do not return a result code.  ^If an error occurs, that fact
  1.2488 +** is recorded in the [sqlite3_str] object and can be recovered by a
  1.2489 +** subsequent call to [sqlite3_str_errcode(X)].
  1.2490 +*/
  1.2491 +SQLITE_API void sqlite3_str_appendf(sqlite3_str*, const char *zFormat, ...);
  1.2492 +SQLITE_API void sqlite3_str_vappendf(sqlite3_str*, const char *zFormat, va_list);
  1.2493 +SQLITE_API void sqlite3_str_append(sqlite3_str*, const char *zIn, int N);
  1.2494 +SQLITE_API void sqlite3_str_appendall(sqlite3_str*, const char *zIn);
  1.2495 +SQLITE_API void sqlite3_str_appendchar(sqlite3_str*, int N, char C);
  1.2496 +SQLITE_API void sqlite3_str_reset(sqlite3_str*);
  1.2497 +
  1.2498 +/*
  1.2499 +** CAPI3REF: Status Of A Dynamic String
  1.2500 +** METHOD: sqlite3_str
  1.2501 +**
  1.2502 +** These interfaces return the current status of an [sqlite3_str] object.
  1.2503 +**
  1.2504 +** ^If any prior errors have occurred while constructing the dynamic string
  1.2505 +** in sqlite3_str X, then the [sqlite3_str_errcode(X)] method will return
  1.2506 +** an appropriate error code.  ^The [sqlite3_str_errcode(X)] method returns
  1.2507 +** [SQLITE_NOMEM] following any out-of-memory error, or
  1.2508 +** [SQLITE_TOOBIG] if the size of the dynamic string exceeds
  1.2509 +** [SQLITE_MAX_LENGTH], or [SQLITE_OK] if there have been no errors.
  1.2510 +**
  1.2511 +** ^The [sqlite3_str_length(X)] method returns the current length, in bytes,
  1.2512 +** of the dynamic string under construction in [sqlite3_str] object X.
  1.2513 +** ^The length returned by [sqlite3_str_length(X)] does not include the
  1.2514 +** zero-termination byte.
  1.2515 +**
  1.2516 +** ^The [sqlite3_str_value(X)] method returns a pointer to the current
  1.2517 +** content of the dynamic string under construction in X.  The value
  1.2518 +** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X
  1.2519 +** and might be freed or altered by any subsequent method on the same
  1.2520 +** [sqlite3_str] object.  Applications must not used the pointer returned
  1.2521 +** [sqlite3_str_value(X)] after any subsequent method call on the same
  1.2522 +** object.  ^Applications may change the content of the string returned
  1.2523 +** by [sqlite3_str_value(X)] as long as they do not write into any bytes
  1.2524 +** outside the range of 0 to [sqlite3_str_length(X)] and do not read or
  1.2525 +** write any byte after any subsequent sqlite3_str method call.
  1.2526 +*/
  1.2527 +SQLITE_API int sqlite3_str_errcode(sqlite3_str*);
  1.2528 +SQLITE_API int sqlite3_str_length(sqlite3_str*);
  1.2529 +SQLITE_API char *sqlite3_str_value(sqlite3_str*);
  1.2530  
  1.2531  /*
  1.2532  ** CAPI3REF: SQLite Runtime Status
  1.2533 @@ -7126,8 +8524,7 @@
  1.2534  ** <dd>This parameter is the current amount of memory checked out
  1.2535  ** using [sqlite3_malloc()], either directly or indirectly.  The
  1.2536  ** figure includes calls made to [sqlite3_malloc()] by the application
  1.2537 -** and internal memory usage by the SQLite library.  Scratch memory
  1.2538 -** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
  1.2539 +** and internal memory usage by the SQLite library.  Auxiliary page-cache
  1.2540  ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
  1.2541  ** this parameter.  The amount returned is the sum of the allocation
  1.2542  ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
  1.2543 @@ -7165,29 +8562,14 @@
  1.2544  ** *pHighwater parameter to [sqlite3_status()] is of interest.  
  1.2545  ** The value written into the *pCurrent parameter is undefined.</dd>)^
  1.2546  **
  1.2547 -** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
  1.2548 -** <dd>This parameter returns the number of allocations used out of the
  1.2549 -** [scratch memory allocator] configured using
  1.2550 -** [SQLITE_CONFIG_SCRATCH].  The value returned is in allocations, not
  1.2551 -** in bytes.  Since a single thread may only have one scratch allocation
  1.2552 -** outstanding at time, this parameter also reports the number of threads
  1.2553 -** using scratch memory at the same time.</dd>)^
  1.2554 +** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt>
  1.2555 +** <dd>No longer used.</dd>
  1.2556  **
  1.2557  ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
  1.2558 -** <dd>This parameter returns the number of bytes of scratch memory
  1.2559 -** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
  1.2560 -** buffer and where forced to overflow to [sqlite3_malloc()].  The values
  1.2561 -** returned include overflows because the requested allocation was too
  1.2562 -** larger (that is, because the requested allocation was larger than the
  1.2563 -** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
  1.2564 -** slots were available.
  1.2565 -** </dd>)^
  1.2566 -**
  1.2567 -** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
  1.2568 -** <dd>This parameter records the largest memory allocation request
  1.2569 -** handed to [scratch memory allocator].  Only the value returned in the
  1.2570 -** *pHighwater parameter to [sqlite3_status()] is of interest.  
  1.2571 -** The value written into the *pCurrent parameter is undefined.</dd>)^
  1.2572 +** <dd>No longer used.</dd>
  1.2573 +**
  1.2574 +** [[SQLITE_STATUS_SCRATCH_SIZE]] <dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
  1.2575 +** <dd>No longer used.</dd>
  1.2576  **
  1.2577  ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
  1.2578  ** <dd>The *pHighwater parameter records the deepest parser stack. 
  1.2579 @@ -7200,12 +8582,12 @@
  1.2580  #define SQLITE_STATUS_MEMORY_USED          0
  1.2581  #define SQLITE_STATUS_PAGECACHE_USED       1
  1.2582  #define SQLITE_STATUS_PAGECACHE_OVERFLOW   2
  1.2583 -#define SQLITE_STATUS_SCRATCH_USED         3
  1.2584 -#define SQLITE_STATUS_SCRATCH_OVERFLOW     4
  1.2585 +#define SQLITE_STATUS_SCRATCH_USED         3  /* NOT USED */
  1.2586 +#define SQLITE_STATUS_SCRATCH_OVERFLOW     4  /* NOT USED */
  1.2587  #define SQLITE_STATUS_MALLOC_SIZE          5
  1.2588  #define SQLITE_STATUS_PARSER_STACK         6
  1.2589  #define SQLITE_STATUS_PAGECACHE_SIZE       7
  1.2590 -#define SQLITE_STATUS_SCRATCH_SIZE         8
  1.2591 +#define SQLITE_STATUS_SCRATCH_SIZE         8  /* NOT USED */
  1.2592  #define SQLITE_STATUS_MALLOC_COUNT         9
  1.2593  
  1.2594  /*
  1.2595 @@ -7328,6 +8710,15 @@
  1.2596  ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.
  1.2597  ** </dd>
  1.2598  **
  1.2599 +** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(<dt>SQLITE_DBSTATUS_CACHE_SPILL</dt>
  1.2600 +** <dd>This parameter returns the number of dirty cache entries that have
  1.2601 +** been written to disk in the middle of a transaction due to the page
  1.2602 +** cache overflowing. Transactions are more efficient if they are written
  1.2603 +** to disk all at once. When pages spill mid-transaction, that introduces
  1.2604 +** additional overhead. This parameter can be used help identify
  1.2605 +** inefficiencies that can be resolve by increasing the cache size.
  1.2606 +** </dd>
  1.2607 +**
  1.2608  ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
  1.2609  ** <dd>This parameter returns zero for the current value if and only if
  1.2610  ** all foreign key constraints (deferred or immediate) have been
  1.2611 @@ -7347,7 +8738,8 @@
  1.2612  #define SQLITE_DBSTATUS_CACHE_WRITE          9
  1.2613  #define SQLITE_DBSTATUS_DEFERRED_FKS        10
  1.2614  #define SQLITE_DBSTATUS_CACHE_USED_SHARED   11
  1.2615 -#define SQLITE_DBSTATUS_MAX                 11   /* Largest defined DBSTATUS */
  1.2616 +#define SQLITE_DBSTATUS_CACHE_SPILL         12
  1.2617 +#define SQLITE_DBSTATUS_MAX                 12   /* Largest defined DBSTATUS */
  1.2618  
  1.2619  
  1.2620  /*
  1.2621 @@ -7410,6 +8802,24 @@
  1.2622  ** used as a proxy for the total work done by the prepared statement.
  1.2623  ** If the number of virtual machine operations exceeds 2147483647
  1.2624  ** then the value returned by this statement status code is undefined.
  1.2625 +**
  1.2626 +** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
  1.2627 +** <dd>^This is the number of times that the prepare statement has been
  1.2628 +** automatically regenerated due to schema changes or change to 
  1.2629 +** [bound parameters] that might affect the query plan.
  1.2630 +**
  1.2631 +** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
  1.2632 +** <dd>^This is the number of times that the prepared statement has
  1.2633 +** been run.  A single "run" for the purposes of this counter is one
  1.2634 +** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()].
  1.2635 +** The counter is incremented on the first [sqlite3_step()] call of each
  1.2636 +** cycle.
  1.2637 +**
  1.2638 +** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt>
  1.2639 +** <dd>^This is the approximate number of bytes of heap memory
  1.2640 +** used to store the prepared statement.  ^This value is not actually
  1.2641 +** a counter, and so the resetFlg parameter to sqlite3_stmt_status()
  1.2642 +** is ignored when the opcode is SQLITE_STMTSTATUS_MEMUSED.
  1.2643  ** </dd>
  1.2644  ** </dl>
  1.2645  */
  1.2646 @@ -7417,6 +8827,9 @@
  1.2647  #define SQLITE_STMTSTATUS_SORT              2
  1.2648  #define SQLITE_STMTSTATUS_AUTOINDEX         3
  1.2649  #define SQLITE_STMTSTATUS_VM_STEP           4
  1.2650 +#define SQLITE_STMTSTATUS_REPREPARE         5
  1.2651 +#define SQLITE_STMTSTATUS_RUN               6
  1.2652 +#define SQLITE_STMTSTATUS_MEMUSED           99
  1.2653  
  1.2654  /*
  1.2655  ** CAPI3REF: Custom Page Cache Object
  1.2656 @@ -8281,6 +9694,7 @@
  1.2657  ** can use to customize and optimize their behavior.
  1.2658  **
  1.2659  ** <dl>
  1.2660 +** [[SQLITE_VTAB_CONSTRAINT_SUPPORT]]
  1.2661  ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT
  1.2662  ** <dd>Calls of the form
  1.2663  ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
  1.2664 @@ -8327,6 +9741,40 @@
  1.2665  SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
  1.2666  
  1.2667  /*
  1.2668 +** CAPI3REF: Determine If Virtual Table Column Access Is For UPDATE
  1.2669 +**
  1.2670 +** If the sqlite3_vtab_nochange(X) routine is called within the [xColumn]
  1.2671 +** method of a [virtual table], then it returns true if and only if the
  1.2672 +** column is being fetched as part of an UPDATE operation during which the
  1.2673 +** column value will not change.  Applications might use this to substitute
  1.2674 +** a return value that is less expensive to compute and that the corresponding
  1.2675 +** [xUpdate] method understands as a "no-change" value.
  1.2676 +**
  1.2677 +** If the [xColumn] method calls sqlite3_vtab_nochange() and finds that
  1.2678 +** the column is not changed by the UPDATE statement, then the xColumn
  1.2679 +** method can optionally return without setting a result, without calling
  1.2680 +** any of the [sqlite3_result_int|sqlite3_result_xxxxx() interfaces].
  1.2681 +** In that case, [sqlite3_value_nochange(X)] will return true for the
  1.2682 +** same column in the [xUpdate] method.
  1.2683 +*/
  1.2684 +SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
  1.2685 +
  1.2686 +/*
  1.2687 +** CAPI3REF: Determine The Collation For a Virtual Table Constraint
  1.2688 +**
  1.2689 +** This function may only be called from within a call to the [xBestIndex]
  1.2690 +** method of a [virtual table]. 
  1.2691 +**
  1.2692 +** The first argument must be the sqlite3_index_info object that is the
  1.2693 +** first parameter to the xBestIndex() method. The second argument must be
  1.2694 +** an index into the aConstraint[] array belonging to the sqlite3_index_info
  1.2695 +** structure passed to xBestIndex. This function returns a pointer to a buffer 
  1.2696 +** containing the name of the collation sequence for the corresponding
  1.2697 +** constraint.
  1.2698 +*/
  1.2699 +SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
  1.2700 +
  1.2701 +/*
  1.2702  ** CAPI3REF: Conflict resolution modes
  1.2703  ** KEYWORDS: {conflict resolution mode}
  1.2704  **
  1.2705 @@ -8596,7 +10044,6 @@
  1.2706  /*
  1.2707  ** CAPI3REF: Database Snapshot
  1.2708  ** KEYWORDS: {snapshot} {sqlite3_snapshot}
  1.2709 -** EXPERIMENTAL
  1.2710  **
  1.2711  ** An instance of the snapshot object records the state of a [WAL mode]
  1.2712  ** database for some specific point in history.
  1.2713 @@ -8613,11 +10060,6 @@
  1.2714  ** version of the database file so that it is possible to later open a new read
  1.2715  ** transaction that sees that historical version of the database rather than
  1.2716  ** the most recent version.
  1.2717 -**
  1.2718 -** The constructor for this object is [sqlite3_snapshot_get()].  The
  1.2719 -** [sqlite3_snapshot_open()] method causes a fresh read transaction to refer
  1.2720 -** to an historical snapshot (if possible).  The destructor for 
  1.2721 -** sqlite3_snapshot objects is [sqlite3_snapshot_free()].
  1.2722  */
  1.2723  typedef struct sqlite3_snapshot {
  1.2724    unsigned char hidden[48];
  1.2725 @@ -8625,7 +10067,7 @@
  1.2726  
  1.2727  /*
  1.2728  ** CAPI3REF: Record A Database Snapshot
  1.2729 -** EXPERIMENTAL
  1.2730 +** CONSTRUCTOR: sqlite3_snapshot
  1.2731  **
  1.2732  ** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a
  1.2733  ** new [sqlite3_snapshot] object that records the current state of
  1.2734 @@ -8641,7 +10083,7 @@
  1.2735  ** in this case. 
  1.2736  **
  1.2737  ** <ul>
  1.2738 -**   <li> The database handle must be in [autocommit mode].
  1.2739 +**   <li> The database handle must not be in [autocommit mode].
  1.2740  **
  1.2741  **   <li> Schema S of [database connection] D must be a [WAL mode] database.
  1.2742  **
  1.2743 @@ -8664,7 +10106,7 @@
  1.2744  ** to avoid a memory leak.
  1.2745  **
  1.2746  ** The [sqlite3_snapshot_get()] interface is only available when the
  1.2747 -** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
  1.2748 +** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
  1.2749  */
  1.2750  SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get(
  1.2751    sqlite3 *db,
  1.2752 @@ -8674,24 +10116,35 @@
  1.2753  
  1.2754  /*
  1.2755  ** CAPI3REF: Start a read transaction on an historical snapshot
  1.2756 -** EXPERIMENTAL
  1.2757 -**
  1.2758 -** ^The [sqlite3_snapshot_open(D,S,P)] interface starts a
  1.2759 -** read transaction for schema S of
  1.2760 -** [database connection] D such that the read transaction
  1.2761 -** refers to historical [snapshot] P, rather than the most
  1.2762 -** recent change to the database.
  1.2763 -** ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK on success
  1.2764 -** or an appropriate [error code] if it fails.
  1.2765 -**
  1.2766 -** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be
  1.2767 -** the first operation following the [BEGIN] that takes the schema S
  1.2768 -** out of [autocommit mode].
  1.2769 -** ^In other words, schema S must not currently be in
  1.2770 -** a transaction for [sqlite3_snapshot_open(D,S,P)] to work, but the
  1.2771 -** database connection D must be out of [autocommit mode].
  1.2772 -** ^A [snapshot] will fail to open if it has been overwritten by a
  1.2773 -** [checkpoint].
  1.2774 +** METHOD: sqlite3_snapshot
  1.2775 +**
  1.2776 +** ^The [sqlite3_snapshot_open(D,S,P)] interface either starts a new read 
  1.2777 +** transaction or upgrades an existing one for schema S of 
  1.2778 +** [database connection] D such that the read transaction refers to 
  1.2779 +** historical [snapshot] P, rather than the most recent change to the 
  1.2780 +** database. ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK 
  1.2781 +** on success or an appropriate [error code] if it fails.
  1.2782 +**
  1.2783 +** ^In order to succeed, the database connection must not be in 
  1.2784 +** [autocommit mode] when [sqlite3_snapshot_open(D,S,P)] is called. If there
  1.2785 +** is already a read transaction open on schema S, then the database handle
  1.2786 +** must have no active statements (SELECT statements that have been passed
  1.2787 +** to sqlite3_step() but not sqlite3_reset() or sqlite3_finalize()). 
  1.2788 +** SQLITE_ERROR is returned if either of these conditions is violated, or
  1.2789 +** if schema S does not exist, or if the snapshot object is invalid.
  1.2790 +**
  1.2791 +** ^A call to sqlite3_snapshot_open() will fail to open if the specified
  1.2792 +** snapshot has been overwritten by a [checkpoint]. In this case 
  1.2793 +** SQLITE_ERROR_SNAPSHOT is returned.
  1.2794 +**
  1.2795 +** If there is already a read transaction open when this function is 
  1.2796 +** invoked, then the same read transaction remains open (on the same
  1.2797 +** database snapshot) if SQLITE_ERROR, SQLITE_BUSY or SQLITE_ERROR_SNAPSHOT
  1.2798 +** is returned. If another error code - for example SQLITE_PROTOCOL or an
  1.2799 +** SQLITE_IOERR error code - is returned, then the final state of the
  1.2800 +** read transaction is undefined. If SQLITE_OK is returned, then the 
  1.2801 +** read transaction is now open on database snapshot P.
  1.2802 +**
  1.2803  ** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the
  1.2804  ** database connection D does not know that the database file for
  1.2805  ** schema S is in [WAL mode].  A database connection might not know
  1.2806 @@ -8702,7 +10155,7 @@
  1.2807  ** database connection in order to make it ready to use snapshots.)
  1.2808  **
  1.2809  ** The [sqlite3_snapshot_open()] interface is only available when the
  1.2810 -** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
  1.2811 +** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
  1.2812  */
  1.2813  SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open(
  1.2814    sqlite3 *db,
  1.2815 @@ -8712,20 +10165,20 @@
  1.2816  
  1.2817  /*
  1.2818  ** CAPI3REF: Destroy a snapshot
  1.2819 -** EXPERIMENTAL
  1.2820 +** DESTRUCTOR: sqlite3_snapshot
  1.2821  **
  1.2822  ** ^The [sqlite3_snapshot_free(P)] interface destroys [sqlite3_snapshot] P.
  1.2823  ** The application must eventually free every [sqlite3_snapshot] object
  1.2824  ** using this routine to avoid a memory leak.
  1.2825  **
  1.2826  ** The [sqlite3_snapshot_free()] interface is only available when the
  1.2827 -** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
  1.2828 +** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
  1.2829  */
  1.2830  SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free(sqlite3_snapshot*);
  1.2831  
  1.2832  /*
  1.2833  ** CAPI3REF: Compare the ages of two snapshot handles.
  1.2834 -** EXPERIMENTAL
  1.2835 +** METHOD: sqlite3_snapshot
  1.2836  **
  1.2837  ** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages
  1.2838  ** of two valid snapshot handles. 
  1.2839 @@ -8744,6 +10197,9 @@
  1.2840  ** Otherwise, this API returns a negative value if P1 refers to an older
  1.2841  ** snapshot than P2, zero if the two handles refer to the same database
  1.2842  ** snapshot, and a positive value if P1 is a newer snapshot than P2.
  1.2843 +**
  1.2844 +** This interface is only available if SQLite is compiled with the
  1.2845 +** [SQLITE_ENABLE_SNAPSHOT] option.
  1.2846  */
  1.2847  SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(
  1.2848    sqlite3_snapshot *p1,
  1.2849 @@ -8752,27 +10208,152 @@
  1.2850  
  1.2851  /*
  1.2852  ** CAPI3REF: Recover snapshots from a wal file
  1.2853 -** EXPERIMENTAL
  1.2854 -**
  1.2855 -** If all connections disconnect from a database file but do not perform
  1.2856 -** a checkpoint, the existing wal file is opened along with the database
  1.2857 -** file the next time the database is opened. At this point it is only
  1.2858 -** possible to successfully call sqlite3_snapshot_open() to open the most
  1.2859 -** recent snapshot of the database (the one at the head of the wal file),
  1.2860 -** even though the wal file may contain other valid snapshots for which
  1.2861 -** clients have sqlite3_snapshot handles.
  1.2862 -**
  1.2863 -** This function attempts to scan the wal file associated with database zDb
  1.2864 +** METHOD: sqlite3_snapshot
  1.2865 +**
  1.2866 +** If a [WAL file] remains on disk after all database connections close
  1.2867 +** (either through the use of the [SQLITE_FCNTL_PERSIST_WAL] [file control]
  1.2868 +** or because the last process to have the database opened exited without
  1.2869 +** calling [sqlite3_close()]) and a new connection is subsequently opened
  1.2870 +** on that database and [WAL file], the [sqlite3_snapshot_open()] interface
  1.2871 +** will only be able to open the last transaction added to the WAL file
  1.2872 +** even though the WAL file contains other valid transactions.
  1.2873 +**
  1.2874 +** This function attempts to scan the WAL file associated with database zDb
  1.2875  ** of database handle db and make all valid snapshots available to
  1.2876  ** sqlite3_snapshot_open(). It is an error if there is already a read
  1.2877 -** transaction open on the database, or if the database is not a wal mode
  1.2878 +** transaction open on the database, or if the database is not a WAL mode
  1.2879  ** database.
  1.2880  **
  1.2881  ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
  1.2882 +**
  1.2883 +** This interface is only available if SQLite is compiled with the
  1.2884 +** [SQLITE_ENABLE_SNAPSHOT] option.
  1.2885  */
  1.2886  SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
  1.2887  
  1.2888  /*
  1.2889 +** CAPI3REF: Serialize a database
  1.2890 +**
  1.2891 +** The sqlite3_serialize(D,S,P,F) interface returns a pointer to memory
  1.2892 +** that is a serialization of the S database on [database connection] D.
  1.2893 +** If P is not a NULL pointer, then the size of the database in bytes
  1.2894 +** is written into *P.
  1.2895 +**
  1.2896 +** For an ordinary on-disk database file, the serialization is just a
  1.2897 +** copy of the disk file.  For an in-memory database or a "TEMP" database,
  1.2898 +** the serialization is the same sequence of bytes which would be written
  1.2899 +** to disk if that database where backed up to disk.
  1.2900 +**
  1.2901 +** The usual case is that sqlite3_serialize() copies the serialization of
  1.2902 +** the database into memory obtained from [sqlite3_malloc64()] and returns
  1.2903 +** a pointer to that memory.  The caller is responsible for freeing the
  1.2904 +** returned value to avoid a memory leak.  However, if the F argument
  1.2905 +** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations
  1.2906 +** are made, and the sqlite3_serialize() function will return a pointer
  1.2907 +** to the contiguous memory representation of the database that SQLite
  1.2908 +** is currently using for that database, or NULL if the no such contiguous
  1.2909 +** memory representation of the database exists.  A contiguous memory
  1.2910 +** representation of the database will usually only exist if there has
  1.2911 +** been a prior call to [sqlite3_deserialize(D,S,...)] with the same
  1.2912 +** values of D and S.
  1.2913 +** The size of the database is written into *P even if the 
  1.2914 +** SQLITE_SERIALIZE_NOCOPY bit is set but no contiguous copy
  1.2915 +** of the database exists.
  1.2916 +**
  1.2917 +** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the
  1.2918 +** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory
  1.2919 +** allocation error occurs.
  1.2920 +**
  1.2921 +** This interface is only available if SQLite is compiled with the
  1.2922 +** [SQLITE_ENABLE_DESERIALIZE] option.
  1.2923 +*/
  1.2924 +SQLITE_API unsigned char *sqlite3_serialize(
  1.2925 +  sqlite3 *db,           /* The database connection */
  1.2926 +  const char *zSchema,   /* Which DB to serialize. ex: "main", "temp", ... */
  1.2927 +  sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */
  1.2928 +  unsigned int mFlags    /* Zero or more SQLITE_SERIALIZE_* flags */
  1.2929 +);
  1.2930 +
  1.2931 +/*
  1.2932 +** CAPI3REF: Flags for sqlite3_serialize
  1.2933 +**
  1.2934 +** Zero or more of the following constants can be OR-ed together for
  1.2935 +** the F argument to [sqlite3_serialize(D,S,P,F)].
  1.2936 +**
  1.2937 +** SQLITE_SERIALIZE_NOCOPY means that [sqlite3_serialize()] will return
  1.2938 +** a pointer to contiguous in-memory database that it is currently using,
  1.2939 +** without making a copy of the database.  If SQLite is not currently using
  1.2940 +** a contiguous in-memory database, then this option causes
  1.2941 +** [sqlite3_serialize()] to return a NULL pointer.  SQLite will only be
  1.2942 +** using a contiguous in-memory database if it has been initialized by a
  1.2943 +** prior call to [sqlite3_deserialize()].
  1.2944 +*/
  1.2945 +#define SQLITE_SERIALIZE_NOCOPY 0x001   /* Do no memory allocations */
  1.2946 +
  1.2947 +/*
  1.2948 +** CAPI3REF: Deserialize a database
  1.2949 +**
  1.2950 +** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the 
  1.2951 +** [database connection] D to disconnect from database S and then
  1.2952 +** reopen S as an in-memory database based on the serialization contained
  1.2953 +** in P.  The serialized database P is N bytes in size.  M is the size of
  1.2954 +** the buffer P, which might be larger than N.  If M is larger than N, and
  1.2955 +** the SQLITE_DESERIALIZE_READONLY bit is not set in F, then SQLite is
  1.2956 +** permitted to add content to the in-memory database as long as the total
  1.2957 +** size does not exceed M bytes.
  1.2958 +**
  1.2959 +** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will
  1.2960 +** invoke sqlite3_free() on the serialization buffer when the database
  1.2961 +** connection closes.  If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then
  1.2962 +** SQLite will try to increase the buffer size using sqlite3_realloc64()
  1.2963 +** if writes on the database cause it to grow larger than M bytes.
  1.2964 +**
  1.2965 +** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the
  1.2966 +** database is currently in a read transaction or is involved in a backup
  1.2967 +** operation.
  1.2968 +**
  1.2969 +** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the 
  1.2970 +** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then
  1.2971 +** [sqlite3_free()] is invoked on argument P prior to returning.
  1.2972 +**
  1.2973 +** This interface is only available if SQLite is compiled with the
  1.2974 +** [SQLITE_ENABLE_DESERIALIZE] option.
  1.2975 +*/
  1.2976 +SQLITE_API int sqlite3_deserialize(
  1.2977 +  sqlite3 *db,            /* The database connection */
  1.2978 +  const char *zSchema,    /* Which DB to reopen with the deserialization */
  1.2979 +  unsigned char *pData,   /* The serialized database content */
  1.2980 +  sqlite3_int64 szDb,     /* Number bytes in the deserialization */
  1.2981 +  sqlite3_int64 szBuf,    /* Total size of buffer pData[] */
  1.2982 +  unsigned mFlags         /* Zero or more SQLITE_DESERIALIZE_* flags */
  1.2983 +);
  1.2984 +
  1.2985 +/*
  1.2986 +** CAPI3REF: Flags for sqlite3_deserialize()
  1.2987 +**
  1.2988 +** The following are allowed values for 6th argument (the F argument) to
  1.2989 +** the [sqlite3_deserialize(D,S,P,N,M,F)] interface.
  1.2990 +**
  1.2991 +** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization
  1.2992 +** in the P argument is held in memory obtained from [sqlite3_malloc64()]
  1.2993 +** and that SQLite should take ownership of this memory and automatically
  1.2994 +** free it when it has finished using it.  Without this flag, the caller
  1.2995 +** is responsible for freeing any dynamically allocated memory.
  1.2996 +**
  1.2997 +** The SQLITE_DESERIALIZE_RESIZEABLE flag means that SQLite is allowed to
  1.2998 +** grow the size of the database using calls to [sqlite3_realloc64()].  This
  1.2999 +** flag should only be used if SQLITE_DESERIALIZE_FREEONCLOSE is also used.
  1.3000 +** Without this flag, the deserialized database cannot increase in size beyond
  1.3001 +** the number of bytes specified by the M parameter.
  1.3002 +**
  1.3003 +** The SQLITE_DESERIALIZE_READONLY flag means that the deserialized database
  1.3004 +** should be treated as read-only.
  1.3005 +*/
  1.3006 +#define SQLITE_DESERIALIZE_FREEONCLOSE 1 /* Call sqlite3_free() on close */
  1.3007 +#define SQLITE_DESERIALIZE_RESIZEABLE  2 /* Resize using sqlite3_realloc64() */
  1.3008 +#define SQLITE_DESERIALIZE_READONLY    4 /* Database is read-only */
  1.3009 +
  1.3010 +/*
  1.3011  ** Undo the hack that converts floating point types to integer for
  1.3012  ** builds on processors without floating point support.
  1.3013  */
  1.3014 @@ -8883,7 +10464,7 @@
  1.3015    sqlite3_int64 iRowid;             /* Rowid for current entry */
  1.3016    sqlite3_rtree_dbl rParentScore;   /* Score of parent node */
  1.3017    int eParentWithin;                /* Visibility of parent node */
  1.3018 -  int eWithin;                      /* OUT: Visiblity */
  1.3019 +  int eWithin;                      /* OUT: Visibility */
  1.3020    sqlite3_rtree_dbl rScore;         /* OUT: Write the score here */
  1.3021    /* The following fields are only available in 3.8.11 and later */
  1.3022    sqlite3_value **apSqlParam;       /* Original SQL values of parameters */
  1.3023 @@ -8919,16 +10500,23 @@
  1.3024  
  1.3025  /*
  1.3026  ** CAPI3REF: Session Object Handle
  1.3027 +**
  1.3028 +** An instance of this object is a [session] that can be used to
  1.3029 +** record changes to a database.
  1.3030  */
  1.3031  typedef struct sqlite3_session sqlite3_session;
  1.3032  
  1.3033  /*
  1.3034  ** CAPI3REF: Changeset Iterator Handle
  1.3035 +**
  1.3036 +** An instance of this object acts as a cursor for iterating
  1.3037 +** over the elements of a [changeset] or [patchset].
  1.3038  */
  1.3039  typedef struct sqlite3_changeset_iter sqlite3_changeset_iter;
  1.3040  
  1.3041  /*
  1.3042  ** CAPI3REF: Create A New Session Object
  1.3043 +** CONSTRUCTOR: sqlite3_session
  1.3044  **
  1.3045  ** Create a new session object attached to database handle db. If successful,
  1.3046  ** a pointer to the new object is written to *ppSession and SQLITE_OK is
  1.3047 @@ -8965,6 +10553,7 @@
  1.3048  
  1.3049  /*
  1.3050  ** CAPI3REF: Delete A Session Object
  1.3051 +** DESTRUCTOR: sqlite3_session
  1.3052  **
  1.3053  ** Delete a session object previously allocated using 
  1.3054  ** [sqlite3session_create()]. Once a session object has been deleted, the
  1.3055 @@ -8980,6 +10569,7 @@
  1.3056  
  1.3057  /*
  1.3058  ** CAPI3REF: Enable Or Disable A Session Object
  1.3059 +** METHOD: sqlite3_session
  1.3060  **
  1.3061  ** Enable or disable the recording of changes by a session object. When
  1.3062  ** enabled, a session object records changes made to the database. When
  1.3063 @@ -8999,6 +10589,7 @@
  1.3064  
  1.3065  /*
  1.3066  ** CAPI3REF: Set Or Clear the Indirect Change Flag
  1.3067 +** METHOD: sqlite3_session
  1.3068  **
  1.3069  ** Each change recorded by a session object is marked as either direct or
  1.3070  ** indirect. A change is marked as indirect if either:
  1.3071 @@ -9028,6 +10619,7 @@
  1.3072  
  1.3073  /*
  1.3074  ** CAPI3REF: Attach A Table To A Session Object
  1.3075 +** METHOD: sqlite3_session
  1.3076  **
  1.3077  ** If argument zTab is not NULL, then it is the name of a table to attach
  1.3078  ** to the session object passed as the first argument. All subsequent changes 
  1.3079 @@ -9053,6 +10645,35 @@
  1.3080  **
  1.3081  ** SQLITE_OK is returned if the call completes without error. Or, if an error 
  1.3082  ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
  1.3083 +**
  1.3084 +** <h3>Special sqlite_stat1 Handling</h3>
  1.3085 +**
  1.3086 +** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to 
  1.3087 +** some of the rules above. In SQLite, the schema of sqlite_stat1 is:
  1.3088 +**  <pre>
  1.3089 +**  &nbsp;     CREATE TABLE sqlite_stat1(tbl,idx,stat)  
  1.3090 +**  </pre>
  1.3091 +**
  1.3092 +** Even though sqlite_stat1 does not have a PRIMARY KEY, changes are 
  1.3093 +** recorded for it as if the PRIMARY KEY is (tbl,idx). Additionally, changes 
  1.3094 +** are recorded for rows for which (idx IS NULL) is true. However, for such
  1.3095 +** rows a zero-length blob (SQL value X'') is stored in the changeset or
  1.3096 +** patchset instead of a NULL value. This allows such changesets to be
  1.3097 +** manipulated by legacy implementations of sqlite3changeset_invert(),
  1.3098 +** concat() and similar.
  1.3099 +**
  1.3100 +** The sqlite3changeset_apply() function automatically converts the 
  1.3101 +** zero-length blob back to a NULL value when updating the sqlite_stat1
  1.3102 +** table. However, if the application calls sqlite3changeset_new(),
  1.3103 +** sqlite3changeset_old() or sqlite3changeset_conflict on a changeset 
  1.3104 +** iterator directly (including on a changeset iterator passed to a
  1.3105 +** conflict-handler callback) then the X'' value is returned. The application
  1.3106 +** must translate X'' to NULL itself if required.
  1.3107 +**
  1.3108 +** Legacy (older than 3.22.0) versions of the sessions module cannot capture
  1.3109 +** changes made to the sqlite_stat1 table. Legacy versions of the
  1.3110 +** sqlite3changeset_apply() function silently ignore any modifications to the
  1.3111 +** sqlite_stat1 table that are part of a changeset or patchset.
  1.3112  */
  1.3113  SQLITE_API int sqlite3session_attach(
  1.3114    sqlite3_session *pSession,      /* Session object */
  1.3115 @@ -9061,6 +10682,7 @@
  1.3116  
  1.3117  /*
  1.3118  ** CAPI3REF: Set a table filter on a Session Object.
  1.3119 +** METHOD: sqlite3_session
  1.3120  **
  1.3121  ** The second argument (xFilter) is the "filter callback". For changes to rows 
  1.3122  ** in tables that are not attached to the Session object, the filter is called
  1.3123 @@ -9079,6 +10701,7 @@
  1.3124  
  1.3125  /*
  1.3126  ** CAPI3REF: Generate A Changeset From A Session Object
  1.3127 +** METHOD: sqlite3_session
  1.3128  **
  1.3129  ** Obtain a changeset containing changes to the tables attached to the 
  1.3130  ** session object passed as the first argument. If successful, 
  1.3131 @@ -9188,7 +10811,8 @@
  1.3132  );
  1.3133  
  1.3134  /*
  1.3135 -** CAPI3REF: Load The Difference Between Tables Into A Session 
  1.3136 +** CAPI3REF: Load The Difference Between Tables Into A Session
  1.3137 +** METHOD: sqlite3_session
  1.3138  **
  1.3139  ** If it is not already attached to the session object passed as the first
  1.3140  ** argument, this function attaches table zTbl in the same manner as the
  1.3141 @@ -9253,6 +10877,7 @@
  1.3142  
  1.3143  /*
  1.3144  ** CAPI3REF: Generate A Patchset From A Session Object
  1.3145 +** METHOD: sqlite3_session
  1.3146  **
  1.3147  ** The differences between a patchset and a changeset are that:
  1.3148  **
  1.3149 @@ -9281,8 +10906,8 @@
  1.3150  */
  1.3151  SQLITE_API int sqlite3session_patchset(
  1.3152    sqlite3_session *pSession,      /* Session object */
  1.3153 -  int *pnPatchset,                /* OUT: Size of buffer at *ppChangeset */
  1.3154 -  void **ppPatchset               /* OUT: Buffer containing changeset */
  1.3155 +  int *pnPatchset,                /* OUT: Size of buffer at *ppPatchset */
  1.3156 +  void **ppPatchset               /* OUT: Buffer containing patchset */
  1.3157  );
  1.3158  
  1.3159  /*
  1.3160 @@ -9304,6 +10929,7 @@
  1.3161  
  1.3162  /*
  1.3163  ** CAPI3REF: Create An Iterator To Traverse A Changeset 
  1.3164 +** CONSTRUCTOR: sqlite3_changeset_iter
  1.3165  **
  1.3166  ** Create an iterator used to iterate through the contents of a changeset.
  1.3167  ** If successful, *pp is set to point to the iterator handle and SQLITE_OK
  1.3168 @@ -9334,16 +10960,43 @@
  1.3169  ** consecutively. There is no chance that the iterator will visit a change 
  1.3170  ** the applies to table X, then one for table Y, and then later on visit 
  1.3171  ** another change for table X.
  1.3172 +**
  1.3173 +** The behavior of sqlite3changeset_start_v2() and its streaming equivalent
  1.3174 +** may be modified by passing a combination of
  1.3175 +** [SQLITE_CHANGESETSTART_INVERT | supported flags] as the 4th parameter.
  1.3176 +**
  1.3177 +** Note that the sqlite3changeset_start_v2() API is still <b>experimental</b>
  1.3178 +** and therefore subject to change.
  1.3179  */
  1.3180  SQLITE_API int sqlite3changeset_start(
  1.3181    sqlite3_changeset_iter **pp,    /* OUT: New changeset iterator handle */
  1.3182    int nChangeset,                 /* Size of changeset blob in bytes */
  1.3183    void *pChangeset                /* Pointer to blob containing changeset */
  1.3184  );
  1.3185 +SQLITE_API int sqlite3changeset_start_v2(
  1.3186 +  sqlite3_changeset_iter **pp,    /* OUT: New changeset iterator handle */
  1.3187 +  int nChangeset,                 /* Size of changeset blob in bytes */
  1.3188 +  void *pChangeset,               /* Pointer to blob containing changeset */
  1.3189 +  int flags                       /* SESSION_CHANGESETSTART_* flags */
  1.3190 +);
  1.3191 +
  1.3192 +/*
  1.3193 +** CAPI3REF: Flags for sqlite3changeset_start_v2
  1.3194 +**
  1.3195 +** The following flags may passed via the 4th parameter to
  1.3196 +** [sqlite3changeset_start_v2] and [sqlite3changeset_start_v2_strm]:
  1.3197 +**
  1.3198 +** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd>
  1.3199 +**   Invert the changeset while iterating through it. This is equivalent to
  1.3200 +**   inverting a changeset using sqlite3changeset_invert() before applying it.
  1.3201 +**   It is an error to specify this flag with a patchset.
  1.3202 +*/
  1.3203 +#define SQLITE_CHANGESETSTART_INVERT        0x0002
  1.3204  
  1.3205  
  1.3206  /*
  1.3207  ** CAPI3REF: Advance A Changeset Iterator
  1.3208 +** METHOD: sqlite3_changeset_iter
  1.3209  **
  1.3210  ** This function may only be used with iterators created by function
  1.3211  ** [sqlite3changeset_start()]. If it is called on an iterator passed to
  1.3212 @@ -9368,6 +11021,7 @@
  1.3213  
  1.3214  /*
  1.3215  ** CAPI3REF: Obtain The Current Operation From A Changeset Iterator
  1.3216 +** METHOD: sqlite3_changeset_iter
  1.3217  **
  1.3218  ** The pIter argument passed to this function may either be an iterator
  1.3219  ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
  1.3220 @@ -9402,6 +11056,7 @@
  1.3221  
  1.3222  /*
  1.3223  ** CAPI3REF: Obtain The Primary Key Definition Of A Table
  1.3224 +** METHOD: sqlite3_changeset_iter
  1.3225  **
  1.3226  ** For each modified table, a changeset includes the following:
  1.3227  **
  1.3228 @@ -9433,6 +11088,7 @@
  1.3229  
  1.3230  /*
  1.3231  ** CAPI3REF: Obtain old.* Values From A Changeset Iterator
  1.3232 +** METHOD: sqlite3_changeset_iter
  1.3233  **
  1.3234  ** The pIter argument passed to this function may either be an iterator
  1.3235  ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
  1.3236 @@ -9463,6 +11119,7 @@
  1.3237  
  1.3238  /*
  1.3239  ** CAPI3REF: Obtain new.* Values From A Changeset Iterator
  1.3240 +** METHOD: sqlite3_changeset_iter
  1.3241  **
  1.3242  ** The pIter argument passed to this function may either be an iterator
  1.3243  ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
  1.3244 @@ -9496,6 +11153,7 @@
  1.3245  
  1.3246  /*
  1.3247  ** CAPI3REF: Obtain Conflicting Row Values From A Changeset Iterator
  1.3248 +** METHOD: sqlite3_changeset_iter
  1.3249  **
  1.3250  ** This function should only be used with iterator objects passed to a
  1.3251  ** conflict-handler callback by [sqlite3changeset_apply()] with either
  1.3252 @@ -9523,6 +11181,7 @@
  1.3253  
  1.3254  /*
  1.3255  ** CAPI3REF: Determine The Number Of Foreign Key Constraint Violations
  1.3256 +** METHOD: sqlite3_changeset_iter
  1.3257  **
  1.3258  ** This function may only be called with an iterator passed to an
  1.3259  ** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case
  1.3260 @@ -9539,6 +11198,7 @@
  1.3261  
  1.3262  /*
  1.3263  ** CAPI3REF: Finalize A Changeset Iterator
  1.3264 +** METHOD: sqlite3_changeset_iter
  1.3265  **
  1.3266  ** This function is used to finalize an iterator allocated with
  1.3267  ** [sqlite3changeset_start()].
  1.3268 @@ -9555,6 +11215,7 @@
  1.3269  ** to that error is returned by this function. Otherwise, SQLITE_OK is
  1.3270  ** returned. This is to allow the following pattern (pseudo-code):
  1.3271  **
  1.3272 +** <pre>
  1.3273  **   sqlite3changeset_start();
  1.3274  **   while( SQLITE_ROW==sqlite3changeset_next() ){
  1.3275  **     // Do something with change.
  1.3276 @@ -9563,6 +11224,7 @@
  1.3277  **   if( rc!=SQLITE_OK ){
  1.3278  **     // An error has occurred 
  1.3279  **   }
  1.3280 +** </pre>
  1.3281  */
  1.3282  SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
  1.3283  
  1.3284 @@ -9610,6 +11272,7 @@
  1.3285  ** sqlite3_changegroup object. Calling it produces similar results as the
  1.3286  ** following code fragment:
  1.3287  **
  1.3288 +** <pre>
  1.3289  **   sqlite3_changegroup *pGrp;
  1.3290  **   rc = sqlite3_changegroup_new(&pGrp);
  1.3291  **   if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nA, pA);
  1.3292 @@ -9620,6 +11283,7 @@
  1.3293  **     *ppOut = 0;
  1.3294  **     *pnOut = 0;
  1.3295  **   }
  1.3296 +** </pre>
  1.3297  **
  1.3298  ** Refer to the sqlite3_changegroup documentation below for details.
  1.3299  */
  1.3300 @@ -9635,11 +11299,15 @@
  1.3301  
  1.3302  /*
  1.3303  ** CAPI3REF: Changegroup Handle
  1.3304 +**
  1.3305 +** A changegroup is an object used to combine two or more 
  1.3306 +** [changesets] or [patchsets]
  1.3307  */
  1.3308  typedef struct sqlite3_changegroup sqlite3_changegroup;
  1.3309  
  1.3310  /*
  1.3311  ** CAPI3REF: Create A New Changegroup Object
  1.3312 +** CONSTRUCTOR: sqlite3_changegroup
  1.3313  **
  1.3314  ** An sqlite3_changegroup object is used to combine two or more changesets
  1.3315  ** (or patchsets) into a single changeset (or patchset). A single changegroup
  1.3316 @@ -9677,6 +11345,7 @@
  1.3317  
  1.3318  /*
  1.3319  ** CAPI3REF: Add A Changeset To A Changegroup
  1.3320 +** METHOD: sqlite3_changegroup
  1.3321  **
  1.3322  ** Add all changes within the changeset (or patchset) in buffer pData (size
  1.3323  ** nData bytes) to the changegroup. 
  1.3324 @@ -9754,6 +11423,7 @@
  1.3325  
  1.3326  /*
  1.3327  ** CAPI3REF: Obtain A Composite Changeset From A Changegroup
  1.3328 +** METHOD: sqlite3_changegroup
  1.3329  **
  1.3330  ** Obtain a buffer containing a changeset (or patchset) representing the
  1.3331  ** current contents of the changegroup. If the inputs to the changegroup
  1.3332 @@ -9784,25 +11454,25 @@
  1.3333  
  1.3334  /*
  1.3335  ** CAPI3REF: Delete A Changegroup Object
  1.3336 +** DESTRUCTOR: sqlite3_changegroup
  1.3337  */
  1.3338  SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*);
  1.3339  
  1.3340  /*
  1.3341  ** CAPI3REF: Apply A Changeset To A Database
  1.3342  **
  1.3343 -** Apply a changeset to a database. This function attempts to update the
  1.3344 -** "main" database attached to handle db with the changes found in the
  1.3345 -** changeset passed via the second and third arguments.
  1.3346 -**
  1.3347 -** The fourth argument (xFilter) passed to this function is the "filter
  1.3348 +** Apply a changeset or patchset to a database. These functions attempt to
  1.3349 +** update the "main" database attached to handle db with the changes found in
  1.3350 +** the changeset passed via the second and third arguments. 
  1.3351 +**
  1.3352 +** The fourth argument (xFilter) passed to these functions is the "filter
  1.3353  ** callback". If it is not NULL, then for each table affected by at least one
  1.3354  ** change in the changeset, the filter callback is invoked with
  1.3355  ** the table name as the second argument, and a copy of the context pointer
  1.3356 -** passed as the sixth argument to this function as the first. If the "filter
  1.3357 -** callback" returns zero, then no attempt is made to apply any changes to 
  1.3358 -** the table. Otherwise, if the return value is non-zero or the xFilter
  1.3359 -** argument to this function is NULL, all changes related to the table are
  1.3360 -** attempted.
  1.3361 +** passed as the sixth argument as the first. If the "filter callback"
  1.3362 +** returns zero, then no attempt is made to apply any changes to the table.
  1.3363 +** Otherwise, if the return value is non-zero or the xFilter argument to
  1.3364 +** is NULL, all changes related to the table are attempted.
  1.3365  **
  1.3366  ** For each table that is not excluded by the filter callback, this function 
  1.3367  ** tests that the target database contains a compatible table. A table is 
  1.3368 @@ -9847,7 +11517,7 @@
  1.3369  **
  1.3370  ** <dl>
  1.3371  ** <dt>DELETE Changes<dd>
  1.3372 -**   For each DELETE change, this function checks if the target database 
  1.3373 +**   For each DELETE change, the function checks if the target database 
  1.3374  **   contains a row with the same primary key value (or values) as the 
  1.3375  **   original row values stored in the changeset. If it does, and the values 
  1.3376  **   stored in all non-primary key columns also match the values stored in 
  1.3377 @@ -9892,7 +11562,7 @@
  1.3378  **   [SQLITE_CHANGESET_REPLACE].
  1.3379  **
  1.3380  ** <dt>UPDATE Changes<dd>
  1.3381 -**   For each UPDATE change, this function checks if the target database 
  1.3382 +**   For each UPDATE change, the function checks if the target database 
  1.3383  **   contains a row with the same primary key value (or values) as the 
  1.3384  **   original row values stored in the changeset. If it does, and the values 
  1.3385  **   stored in all modified non-primary key columns also match the values
  1.3386 @@ -9923,11 +11593,28 @@
  1.3387  ** This can be used to further customize the applications conflict
  1.3388  ** resolution strategy.
  1.3389  **
  1.3390 -** All changes made by this function are enclosed in a savepoint transaction.
  1.3391 +** All changes made by these functions are enclosed in a savepoint transaction.
  1.3392  ** If any other error (aside from a constraint failure when attempting to
  1.3393  ** write to the target database) occurs, then the savepoint transaction is
  1.3394  ** rolled back, restoring the target database to its original state, and an 
  1.3395  ** SQLite error code returned.
  1.3396 +**
  1.3397 +** If the output parameters (ppRebase) and (pnRebase) are non-NULL and
  1.3398 +** the input is a changeset (not a patchset), then sqlite3changeset_apply_v2()
  1.3399 +** may set (*ppRebase) to point to a "rebase" that may be used with the 
  1.3400 +** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase)
  1.3401 +** is set to the size of the buffer in bytes. It is the responsibility of the
  1.3402 +** caller to eventually free any such buffer using sqlite3_free(). The buffer
  1.3403 +** is only allocated and populated if one or more conflicts were encountered
  1.3404 +** while applying the patchset. See comments surrounding the sqlite3_rebaser
  1.3405 +** APIs for further details.
  1.3406 +**
  1.3407 +** The behavior of sqlite3changeset_apply_v2() and its streaming equivalent
  1.3408 +** may be modified by passing a combination of
  1.3409 +** [SQLITE_CHANGESETAPPLY_NOSAVEPOINT | supported flags] as the 9th parameter.
  1.3410 +**
  1.3411 +** Note that the sqlite3changeset_apply_v2() API is still <b>experimental</b>
  1.3412 +** and therefore subject to change.
  1.3413  */
  1.3414  SQLITE_API int sqlite3changeset_apply(
  1.3415    sqlite3 *db,                    /* Apply change to "main" db of this handle */
  1.3416 @@ -9944,6 +11631,47 @@
  1.3417    ),
  1.3418    void *pCtx                      /* First argument passed to xConflict */
  1.3419  );
  1.3420 +SQLITE_API int sqlite3changeset_apply_v2(
  1.3421 +  sqlite3 *db,                    /* Apply change to "main" db of this handle */
  1.3422 +  int nChangeset,                 /* Size of changeset in bytes */
  1.3423 +  void *pChangeset,               /* Changeset blob */
  1.3424 +  int(*xFilter)(
  1.3425 +    void *pCtx,                   /* Copy of sixth arg to _apply() */
  1.3426 +    const char *zTab              /* Table name */
  1.3427 +  ),
  1.3428 +  int(*xConflict)(
  1.3429 +    void *pCtx,                   /* Copy of sixth arg to _apply() */
  1.3430 +    int eConflict,                /* DATA, MISSING, CONFLICT, CONSTRAINT */
  1.3431 +    sqlite3_changeset_iter *p     /* Handle describing change and conflict */
  1.3432 +  ),
  1.3433 +  void *pCtx,                     /* First argument passed to xConflict */
  1.3434 +  void **ppRebase, int *pnRebase, /* OUT: Rebase data */
  1.3435 +  int flags                       /* SESSION_CHANGESETAPPLY_* flags */
  1.3436 +);
  1.3437 +
  1.3438 +/*
  1.3439 +** CAPI3REF: Flags for sqlite3changeset_apply_v2
  1.3440 +**
  1.3441 +** The following flags may passed via the 9th parameter to
  1.3442 +** [sqlite3changeset_apply_v2] and [sqlite3changeset_apply_v2_strm]:
  1.3443 +**
  1.3444 +** <dl>
  1.3445 +** <dt>SQLITE_CHANGESETAPPLY_NOSAVEPOINT <dd>
  1.3446 +**   Usually, the sessions module encloses all operations performed by
  1.3447 +**   a single call to apply_v2() or apply_v2_strm() in a [SAVEPOINT]. The
  1.3448 +**   SAVEPOINT is committed if the changeset or patchset is successfully
  1.3449 +**   applied, or rolled back if an error occurs. Specifying this flag
  1.3450 +**   causes the sessions module to omit this savepoint. In this case, if the
  1.3451 +**   caller has an open transaction or savepoint when apply_v2() is called, 
  1.3452 +**   it may revert the partially applied changeset by rolling it back.
  1.3453 +**
  1.3454 +** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd>
  1.3455 +**   Invert the changeset before applying it. This is equivalent to inverting
  1.3456 +**   a changeset using sqlite3changeset_invert() before applying it. It is
  1.3457 +**   an error to specify this flag with a patchset.
  1.3458 +*/
  1.3459 +#define SQLITE_CHANGESETAPPLY_NOSAVEPOINT   0x0001
  1.3460 +#define SQLITE_CHANGESETAPPLY_INVERT        0x0002
  1.3461  
  1.3462  /* 
  1.3463  ** CAPI3REF: Constants Passed To The Conflict Handler
  1.3464 @@ -10041,6 +11769,161 @@
  1.3465  #define SQLITE_CHANGESET_REPLACE    1
  1.3466  #define SQLITE_CHANGESET_ABORT      2
  1.3467  
  1.3468 +/* 
  1.3469 +** CAPI3REF: Rebasing changesets
  1.3470 +** EXPERIMENTAL
  1.3471 +**
  1.3472 +** Suppose there is a site hosting a database in state S0. And that
  1.3473 +** modifications are made that move that database to state S1 and a
  1.3474 +** changeset recorded (the "local" changeset). Then, a changeset based
  1.3475 +** on S0 is received from another site (the "remote" changeset) and 
  1.3476 +** applied to the database. The database is then in state 
  1.3477 +** (S1+"remote"), where the exact state depends on any conflict
  1.3478 +** resolution decisions (OMIT or REPLACE) made while applying "remote".
  1.3479 +** Rebasing a changeset is to update it to take those conflict 
  1.3480 +** resolution decisions into account, so that the same conflicts
  1.3481 +** do not have to be resolved elsewhere in the network. 
  1.3482 +**
  1.3483 +** For example, if both the local and remote changesets contain an
  1.3484 +** INSERT of the same key on "CREATE TABLE t1(a PRIMARY KEY, b)":
  1.3485 +**
  1.3486 +**   local:  INSERT INTO t1 VALUES(1, 'v1');
  1.3487 +**   remote: INSERT INTO t1 VALUES(1, 'v2');
  1.3488 +**
  1.3489 +** and the conflict resolution is REPLACE, then the INSERT change is
  1.3490 +** removed from the local changeset (it was overridden). Or, if the
  1.3491 +** conflict resolution was "OMIT", then the local changeset is modified
  1.3492 +** to instead contain:
  1.3493 +**
  1.3494 +**           UPDATE t1 SET b = 'v2' WHERE a=1;
  1.3495 +**
  1.3496 +** Changes within the local changeset are rebased as follows:
  1.3497 +**
  1.3498 +** <dl>
  1.3499 +** <dt>Local INSERT<dd>
  1.3500 +**   This may only conflict with a remote INSERT. If the conflict 
  1.3501 +**   resolution was OMIT, then add an UPDATE change to the rebased
  1.3502 +**   changeset. Or, if the conflict resolution was REPLACE, add
  1.3503 +**   nothing to the rebased changeset.
  1.3504 +**
  1.3505 +** <dt>Local DELETE<dd>
  1.3506 +**   This may conflict with a remote UPDATE or DELETE. In both cases the
  1.3507 +**   only possible resolution is OMIT. If the remote operation was a
  1.3508 +**   DELETE, then add no change to the rebased changeset. If the remote
  1.3509 +**   operation was an UPDATE, then the old.* fields of change are updated
  1.3510 +**   to reflect the new.* values in the UPDATE.
  1.3511 +**
  1.3512 +** <dt>Local UPDATE<dd>
  1.3513 +**   This may conflict with a remote UPDATE or DELETE. If it conflicts
  1.3514 +**   with a DELETE, and the conflict resolution was OMIT, then the update
  1.3515 +**   is changed into an INSERT. Any undefined values in the new.* record
  1.3516 +**   from the update change are filled in using the old.* values from
  1.3517 +**   the conflicting DELETE. Or, if the conflict resolution was REPLACE,
  1.3518 +**   the UPDATE change is simply omitted from the rebased changeset.
  1.3519 +**
  1.3520 +**   If conflict is with a remote UPDATE and the resolution is OMIT, then
  1.3521 +**   the old.* values are rebased using the new.* values in the remote
  1.3522 +**   change. Or, if the resolution is REPLACE, then the change is copied
  1.3523 +**   into the rebased changeset with updates to columns also updated by
  1.3524 +**   the conflicting remote UPDATE removed. If this means no columns would 
  1.3525 +**   be updated, the change is omitted.
  1.3526 +** </dl>
  1.3527 +**
  1.3528 +** A local change may be rebased against multiple remote changes 
  1.3529 +** simultaneously. If a single key is modified by multiple remote 
  1.3530 +** changesets, they are combined as follows before the local changeset
  1.3531 +** is rebased:
  1.3532 +**
  1.3533 +** <ul>
  1.3534 +**    <li> If there has been one or more REPLACE resolutions on a
  1.3535 +**         key, it is rebased according to a REPLACE.
  1.3536 +**
  1.3537 +**    <li> If there have been no REPLACE resolutions on a key, then
  1.3538 +**         the local changeset is rebased according to the most recent
  1.3539 +**         of the OMIT resolutions.
  1.3540 +** </ul>
  1.3541 +**
  1.3542 +** Note that conflict resolutions from multiple remote changesets are 
  1.3543 +** combined on a per-field basis, not per-row. This means that in the 
  1.3544 +** case of multiple remote UPDATE operations, some fields of a single 
  1.3545 +** local change may be rebased for REPLACE while others are rebased for 
  1.3546 +** OMIT.
  1.3547 +**
  1.3548 +** In order to rebase a local changeset, the remote changeset must first
  1.3549 +** be applied to the local database using sqlite3changeset_apply_v2() and
  1.3550 +** the buffer of rebase information captured. Then:
  1.3551 +**
  1.3552 +** <ol>
  1.3553 +**   <li> An sqlite3_rebaser object is created by calling 
  1.3554 +**        sqlite3rebaser_create().
  1.3555 +**   <li> The new object is configured with the rebase buffer obtained from
  1.3556 +**        sqlite3changeset_apply_v2() by calling sqlite3rebaser_configure().
  1.3557 +**        If the local changeset is to be rebased against multiple remote
  1.3558 +**        changesets, then sqlite3rebaser_configure() should be called
  1.3559 +**        multiple times, in the same order that the multiple
  1.3560 +**        sqlite3changeset_apply_v2() calls were made.
  1.3561 +**   <li> Each local changeset is rebased by calling sqlite3rebaser_rebase().
  1.3562 +**   <li> The sqlite3_rebaser object is deleted by calling
  1.3563 +**        sqlite3rebaser_delete().
  1.3564 +** </ol>
  1.3565 +*/
  1.3566 +typedef struct sqlite3_rebaser sqlite3_rebaser;
  1.3567 +
  1.3568 +/*
  1.3569 +** CAPI3REF: Create a changeset rebaser object.
  1.3570 +** EXPERIMENTAL
  1.3571 +**
  1.3572 +** Allocate a new changeset rebaser object. If successful, set (*ppNew) to
  1.3573 +** point to the new object and return SQLITE_OK. Otherwise, if an error
  1.3574 +** occurs, return an SQLite error code (e.g. SQLITE_NOMEM) and set (*ppNew) 
  1.3575 +** to NULL. 
  1.3576 +*/
  1.3577 +SQLITE_API int sqlite3rebaser_create(sqlite3_rebaser **ppNew);
  1.3578 +
  1.3579 +/*
  1.3580 +** CAPI3REF: Configure a changeset rebaser object.
  1.3581 +** EXPERIMENTAL
  1.3582 +**
  1.3583 +** Configure the changeset rebaser object to rebase changesets according
  1.3584 +** to the conflict resolutions described by buffer pRebase (size nRebase
  1.3585 +** bytes), which must have been obtained from a previous call to
  1.3586 +** sqlite3changeset_apply_v2().
  1.3587 +*/
  1.3588 +SQLITE_API int sqlite3rebaser_configure(
  1.3589 +  sqlite3_rebaser*, 
  1.3590 +  int nRebase, const void *pRebase
  1.3591 +); 
  1.3592 +
  1.3593 +/*
  1.3594 +** CAPI3REF: Rebase a changeset
  1.3595 +** EXPERIMENTAL
  1.3596 +**
  1.3597 +** Argument pIn must point to a buffer containing a changeset nIn bytes
  1.3598 +** in size. This function allocates and populates a buffer with a copy
  1.3599 +** of the changeset rebased rebased according to the configuration of the
  1.3600 +** rebaser object passed as the first argument. If successful, (*ppOut)
  1.3601 +** is set to point to the new buffer containing the rebased changset and 
  1.3602 +** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
  1.3603 +** responsibility of the caller to eventually free the new buffer using
  1.3604 +** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
  1.3605 +** are set to zero and an SQLite error code returned.
  1.3606 +*/
  1.3607 +SQLITE_API int sqlite3rebaser_rebase(
  1.3608 +  sqlite3_rebaser*,
  1.3609 +  int nIn, const void *pIn, 
  1.3610 +  int *pnOut, void **ppOut 
  1.3611 +);
  1.3612 +
  1.3613 +/*
  1.3614 +** CAPI3REF: Delete a changeset rebaser object.
  1.3615 +** EXPERIMENTAL
  1.3616 +**
  1.3617 +** Delete the changeset rebaser object and all associated resources. There
  1.3618 +** should be one call to this function for each successful invocation
  1.3619 +** of sqlite3rebaser_create().
  1.3620 +*/
  1.3621 +SQLITE_API void sqlite3rebaser_delete(sqlite3_rebaser *p); 
  1.3622 +
  1.3623  /*
  1.3624  ** CAPI3REF: Streaming Versions of API functions.
  1.3625  **
  1.3626 @@ -10049,12 +11932,13 @@
  1.3627  **
  1.3628  ** <table border=1 style="margin-left:8ex;margin-right:8ex">
  1.3629  **   <tr><th>Streaming function<th>Non-streaming equivalent</th>
  1.3630 -**   <tr><td>sqlite3changeset_apply_str<td>[sqlite3changeset_apply] 
  1.3631 -**   <tr><td>sqlite3changeset_concat_str<td>[sqlite3changeset_concat] 
  1.3632 -**   <tr><td>sqlite3changeset_invert_str<td>[sqlite3changeset_invert] 
  1.3633 -**   <tr><td>sqlite3changeset_start_str<td>[sqlite3changeset_start] 
  1.3634 -**   <tr><td>sqlite3session_changeset_str<td>[sqlite3session_changeset] 
  1.3635 -**   <tr><td>sqlite3session_patchset_str<td>[sqlite3session_patchset] 
  1.3636 +**   <tr><td>sqlite3changeset_apply_strm<td>[sqlite3changeset_apply] 
  1.3637 +**   <tr><td>sqlite3changeset_apply_strm_v2<td>[sqlite3changeset_apply_v2] 
  1.3638 +**   <tr><td>sqlite3changeset_concat_strm<td>[sqlite3changeset_concat] 
  1.3639 +**   <tr><td>sqlite3changeset_invert_strm<td>[sqlite3changeset_invert] 
  1.3640 +**   <tr><td>sqlite3changeset_start_strm<td>[sqlite3changeset_start] 
  1.3641 +**   <tr><td>sqlite3session_changeset_strm<td>[sqlite3session_changeset] 
  1.3642 +**   <tr><td>sqlite3session_patchset_strm<td>[sqlite3session_patchset] 
  1.3643  ** </table>
  1.3644  **
  1.3645  ** Non-streaming functions that accept changesets (or patchsets) as input
  1.3646 @@ -10145,6 +12029,23 @@
  1.3647    ),
  1.3648    void *pCtx                      /* First argument passed to xConflict */
  1.3649  );
  1.3650 +SQLITE_API int sqlite3changeset_apply_v2_strm(
  1.3651 +  sqlite3 *db,                    /* Apply change to "main" db of this handle */
  1.3652 +  int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
  1.3653 +  void *pIn,                                          /* First arg for xInput */
  1.3654 +  int(*xFilter)(
  1.3655 +    void *pCtx,                   /* Copy of sixth arg to _apply() */
  1.3656 +    const char *zTab              /* Table name */
  1.3657 +  ),
  1.3658 +  int(*xConflict)(
  1.3659 +    void *pCtx,                   /* Copy of sixth arg to _apply() */
  1.3660 +    int eConflict,                /* DATA, MISSING, CONFLICT, CONSTRAINT */
  1.3661 +    sqlite3_changeset_iter *p     /* Handle describing change and conflict */
  1.3662 +  ),
  1.3663 +  void *pCtx,                     /* First argument passed to xConflict */
  1.3664 +  void **ppRebase, int *pnRebase,
  1.3665 +  int flags
  1.3666 +);
  1.3667  SQLITE_API int sqlite3changeset_concat_strm(
  1.3668    int (*xInputA)(void *pIn, void *pData, int *pnData),
  1.3669    void *pInA,
  1.3670 @@ -10164,6 +12065,12 @@
  1.3671    int (*xInput)(void *pIn, void *pData, int *pnData),
  1.3672    void *pIn
  1.3673  );
  1.3674 +SQLITE_API int sqlite3changeset_start_v2_strm(
  1.3675 +  sqlite3_changeset_iter **pp,
  1.3676 +  int (*xInput)(void *pIn, void *pData, int *pnData),
  1.3677 +  void *pIn,
  1.3678 +  int flags
  1.3679 +);
  1.3680  SQLITE_API int sqlite3session_changeset_strm(
  1.3681    sqlite3_session *pSession,
  1.3682    int (*xOutput)(void *pOut, const void *pData, int nData),
  1.3683 @@ -10182,7 +12089,53 @@
  1.3684      int (*xOutput)(void *pOut, const void *pData, int nData), 
  1.3685      void *pOut
  1.3686  );
  1.3687 -
  1.3688 +SQLITE_API int sqlite3rebaser_rebase_strm(
  1.3689 +  sqlite3_rebaser *pRebaser,
  1.3690 +  int (*xInput)(void *pIn, void *pData, int *pnData),
  1.3691 +  void *pIn,
  1.3692 +  int (*xOutput)(void *pOut, const void *pData, int nData),
  1.3693 +  void *pOut
  1.3694 +);
  1.3695 +
  1.3696 +/*
  1.3697 +** CAPI3REF: Configure global parameters
  1.3698 +**
  1.3699 +** The sqlite3session_config() interface is used to make global configuration
  1.3700 +** changes to the sessions module in order to tune it to the specific needs 
  1.3701 +** of the application.
  1.3702 +**
  1.3703 +** The sqlite3session_config() interface is not threadsafe. If it is invoked
  1.3704 +** while any other thread is inside any other sessions method then the
  1.3705 +** results are undefined. Furthermore, if it is invoked after any sessions
  1.3706 +** related objects have been created, the results are also undefined. 
  1.3707 +**
  1.3708 +** The first argument to the sqlite3session_config() function must be one
  1.3709 +** of the SQLITE_SESSION_CONFIG_XXX constants defined below. The 
  1.3710 +** interpretation of the (void*) value passed as the second parameter and
  1.3711 +** the effect of calling this function depends on the value of the first
  1.3712 +** parameter.
  1.3713 +**
  1.3714 +** <dl>
  1.3715 +** <dt>SQLITE_SESSION_CONFIG_STRMSIZE<dd>
  1.3716 +**    By default, the sessions module streaming interfaces attempt to input
  1.3717 +**    and output data in approximately 1 KiB chunks. This operand may be used
  1.3718 +**    to set and query the value of this configuration setting. The pointer
  1.3719 +**    passed as the second argument must point to a value of type (int).
  1.3720 +**    If this value is greater than 0, it is used as the new streaming data
  1.3721 +**    chunk size for both input and output. Before returning, the (int) value
  1.3722 +**    pointed to by pArg is set to the final value of the streaming interface
  1.3723 +**    chunk size.
  1.3724 +** </dl>
  1.3725 +**
  1.3726 +** This function returns SQLITE_OK if successful, or an SQLite error code
  1.3727 +** otherwise.
  1.3728 +*/
  1.3729 +SQLITE_API int sqlite3session_config(int op, void *pArg);
  1.3730 +
  1.3731 +/*
  1.3732 +** CAPI3REF: Values for sqlite3session_config().
  1.3733 +*/
  1.3734 +#define SQLITE_SESSION_CONFIG_STRMSIZE 1
  1.3735  
  1.3736  /*
  1.3737  ** Make sure we can call this stuff from C++.
  1.3738 @@ -10640,7 +12593,7 @@
  1.3739  **            This way, even if the tokenizer does not provide synonyms
  1.3740  **            when tokenizing query text (it should not - to do would be
  1.3741  **            inefficient), it doesn't matter if the user queries for 
  1.3742 -**            'first + place' or '1st + place', as there are entires in the
  1.3743 +**            'first + place' or '1st + place', as there are entries in the
  1.3744  **            FTS index corresponding to both forms of the first token.
  1.3745  **   </ol>
  1.3746  **
  1.3747 @@ -10668,7 +12621,7 @@
  1.3748  **   extra data to the FTS index or require FTS5 to query for multiple terms,
  1.3749  **   so it is efficient in terms of disk space and query speed. However, it
  1.3750  **   does not support prefix queries very well. If, as suggested above, the
  1.3751 -**   token "first" is subsituted for "1st" by the tokenizer, then the query:
  1.3752 +**   token "first" is substituted for "1st" by the tokenizer, then the query:
  1.3753  **
  1.3754  **   <codeblock>
  1.3755  **     ... MATCH '1s*'</codeblock>
  1.3756 @@ -10783,8 +12736,9 @@
  1.3757  ** Include the configuration header output by 'configure' if we're using the
  1.3758  ** autoconf-based build
  1.3759  */
  1.3760 -#ifdef _HAVE_SQLITE_CONFIG_H
  1.3761 -#include "config.h"
  1.3762 +#if defined(_HAVE_SQLITE_CONFIG_H) && !defined(SQLITECONFIG_H)
  1.3763 +/* #include "config.h" */
  1.3764 +#define SQLITECONFIG_H 1
  1.3765  #endif
  1.3766  
  1.3767  /************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/
  1.3768 @@ -11094,6 +13048,11 @@
  1.3769  **
  1.3770  ** Older versions of SQLite used an optional THREADSAFE macro.
  1.3771  ** We support that for legacy.
  1.3772 +**
  1.3773 +** To ensure that the correct value of "THREADSAFE" is reported when querying
  1.3774 +** for compile-time options at runtime (e.g. "PRAGMA compile_options"), this
  1.3775 +** logic is partially replicated in ctime.c. If it is updated here, it should
  1.3776 +** also be updated there.
  1.3777  */
  1.3778  #if !defined(SQLITE_THREADSAFE)
  1.3779  # if defined(THREADSAFE)
  1.3780 @@ -11269,6 +13228,21 @@
  1.3781  #endif
  1.3782  
  1.3783  /*
  1.3784 +** Some conditionals are optimizations only.  In other words, if the
  1.3785 +** conditionals are replaced with a constant 1 (true) or 0 (false) then
  1.3786 +** the correct answer is still obtained, though perhaps not as quickly.
  1.3787 +**
  1.3788 +** The following macros mark these optimizations conditionals.
  1.3789 +*/
  1.3790 +#if defined(SQLITE_MUTATION_TEST)
  1.3791 +# define OK_IF_ALWAYS_TRUE(X)  (1)
  1.3792 +# define OK_IF_ALWAYS_FALSE(X) (0)
  1.3793 +#else
  1.3794 +# define OK_IF_ALWAYS_TRUE(X)  (X)
  1.3795 +# define OK_IF_ALWAYS_FALSE(X) (X)
  1.3796 +#endif
  1.3797 +
  1.3798 +/*
  1.3799  ** Some malloc failures are only possible if SQLITE_TEST_REALLOC_STRESS is
  1.3800  ** defined.  We need to defend against those failures when testing with
  1.3801  ** SQLITE_TEST_REALLOC_STRESS, but we don't want the unreachable branches
  1.3802 @@ -11462,144 +13436,153 @@
  1.3803  #define TK_AS                              24
  1.3804  #define TK_WITHOUT                         25
  1.3805  #define TK_COMMA                           26
  1.3806 -#define TK_ID                              27
  1.3807 -#define TK_ABORT                           28
  1.3808 -#define TK_ACTION                          29
  1.3809 -#define TK_AFTER                           30
  1.3810 -#define TK_ANALYZE                         31
  1.3811 -#define TK_ASC                             32
  1.3812 -#define TK_ATTACH                          33
  1.3813 -#define TK_BEFORE                          34
  1.3814 -#define TK_BY                              35
  1.3815 -#define TK_CASCADE                         36
  1.3816 -#define TK_CAST                            37
  1.3817 -#define TK_COLUMNKW                        38
  1.3818 -#define TK_CONFLICT                        39
  1.3819 -#define TK_DATABASE                        40
  1.3820 -#define TK_DESC                            41
  1.3821 -#define TK_DETACH                          42
  1.3822 -#define TK_EACH                            43
  1.3823 -#define TK_FAIL                            44
  1.3824 -#define TK_FOR                             45
  1.3825 -#define TK_IGNORE                          46
  1.3826 -#define TK_INITIALLY                       47
  1.3827 -#define TK_INSTEAD                         48
  1.3828 -#define TK_LIKE_KW                         49
  1.3829 -#define TK_MATCH                           50
  1.3830 -#define TK_NO                              51
  1.3831 -#define TK_KEY                             52
  1.3832 -#define TK_OF                              53
  1.3833 -#define TK_OFFSET                          54
  1.3834 -#define TK_PRAGMA                          55
  1.3835 -#define TK_RAISE                           56
  1.3836 -#define TK_RECURSIVE                       57
  1.3837 -#define TK_REPLACE                         58
  1.3838 -#define TK_RESTRICT                        59
  1.3839 -#define TK_ROW                             60
  1.3840 -#define TK_TRIGGER                         61
  1.3841 -#define TK_VACUUM                          62
  1.3842 -#define TK_VIEW                            63
  1.3843 -#define TK_VIRTUAL                         64
  1.3844 -#define TK_WITH                            65
  1.3845 -#define TK_REINDEX                         66
  1.3846 -#define TK_RENAME                          67
  1.3847 -#define TK_CTIME_KW                        68
  1.3848 -#define TK_ANY                             69
  1.3849 -#define TK_OR                              70
  1.3850 -#define TK_AND                             71
  1.3851 -#define TK_IS                              72
  1.3852 -#define TK_BETWEEN                         73
  1.3853 -#define TK_IN                              74
  1.3854 -#define TK_ISNULL                          75
  1.3855 -#define TK_NOTNULL                         76
  1.3856 -#define TK_NE                              77
  1.3857 -#define TK_EQ                              78
  1.3858 -#define TK_GT                              79
  1.3859 -#define TK_LE                              80
  1.3860 -#define TK_LT                              81
  1.3861 -#define TK_GE                              82
  1.3862 -#define TK_ESCAPE                          83
  1.3863 -#define TK_BITAND                          84
  1.3864 -#define TK_BITOR                           85
  1.3865 -#define TK_LSHIFT                          86
  1.3866 -#define TK_RSHIFT                          87
  1.3867 -#define TK_PLUS                            88
  1.3868 -#define TK_MINUS                           89
  1.3869 -#define TK_STAR                            90
  1.3870 -#define TK_SLASH                           91
  1.3871 -#define TK_REM                             92
  1.3872 -#define TK_CONCAT                          93
  1.3873 -#define TK_COLLATE                         94
  1.3874 -#define TK_BITNOT                          95
  1.3875 -#define TK_INDEXED                         96
  1.3876 -#define TK_STRING                          97
  1.3877 -#define TK_JOIN_KW                         98
  1.3878 -#define TK_CONSTRAINT                      99
  1.3879 -#define TK_DEFAULT                        100
  1.3880 -#define TK_NULL                           101
  1.3881 -#define TK_PRIMARY                        102
  1.3882 -#define TK_UNIQUE                         103
  1.3883 -#define TK_CHECK                          104
  1.3884 -#define TK_REFERENCES                     105
  1.3885 -#define TK_AUTOINCR                       106
  1.3886 -#define TK_ON                             107
  1.3887 -#define TK_INSERT                         108
  1.3888 -#define TK_DELETE                         109
  1.3889 -#define TK_UPDATE                         110
  1.3890 -#define TK_SET                            111
  1.3891 -#define TK_DEFERRABLE                     112
  1.3892 -#define TK_FOREIGN                        113
  1.3893 -#define TK_DROP                           114
  1.3894 -#define TK_UNION                          115
  1.3895 -#define TK_ALL                            116
  1.3896 -#define TK_EXCEPT                         117
  1.3897 -#define TK_INTERSECT                      118
  1.3898 -#define TK_SELECT                         119
  1.3899 -#define TK_VALUES                         120
  1.3900 -#define TK_DISTINCT                       121
  1.3901 -#define TK_DOT                            122
  1.3902 -#define TK_FROM                           123
  1.3903 -#define TK_JOIN                           124
  1.3904 -#define TK_USING                          125
  1.3905 -#define TK_ORDER                          126
  1.3906 -#define TK_GROUP                          127
  1.3907 -#define TK_HAVING                         128
  1.3908 -#define TK_LIMIT                          129
  1.3909 -#define TK_WHERE                          130
  1.3910 -#define TK_INTO                           131
  1.3911 -#define TK_FLOAT                          132
  1.3912 -#define TK_BLOB                           133
  1.3913 -#define TK_INTEGER                        134
  1.3914 -#define TK_VARIABLE                       135
  1.3915 -#define TK_CASE                           136
  1.3916 -#define TK_WHEN                           137
  1.3917 -#define TK_THEN                           138
  1.3918 -#define TK_ELSE                           139
  1.3919 -#define TK_INDEX                          140
  1.3920 -#define TK_ALTER                          141
  1.3921 -#define TK_ADD                            142
  1.3922 -#define TK_TO_TEXT                        143
  1.3923 -#define TK_TO_BLOB                        144
  1.3924 -#define TK_TO_NUMERIC                     145
  1.3925 -#define TK_TO_INT                         146
  1.3926 -#define TK_TO_REAL                        147
  1.3927 -#define TK_ISNOT                          148
  1.3928 -#define TK_END_OF_FILE                    149
  1.3929 -#define TK_UNCLOSED_STRING                150
  1.3930 -#define TK_FUNCTION                       151
  1.3931 -#define TK_COLUMN                         152
  1.3932 -#define TK_AGG_FUNCTION                   153
  1.3933 -#define TK_AGG_COLUMN                     154
  1.3934 -#define TK_UMINUS                         155
  1.3935 -#define TK_UPLUS                          156
  1.3936 -#define TK_REGISTER                       157
  1.3937 -#define TK_VECTOR                         158
  1.3938 -#define TK_SELECT_COLUMN                  159
  1.3939 -#define TK_IF_NULL_ROW                    160
  1.3940 -#define TK_ASTERISK                       161
  1.3941 -#define TK_SPAN                           162
  1.3942 -#define TK_SPACE                          163
  1.3943 -#define TK_ILLEGAL                        164
  1.3944 +#define TK_ABORT                           27
  1.3945 +#define TK_ACTION                          28
  1.3946 +#define TK_AFTER                           29
  1.3947 +#define TK_ANALYZE                         30
  1.3948 +#define TK_ASC                             31
  1.3949 +#define TK_ATTACH                          32
  1.3950 +#define TK_BEFORE                          33
  1.3951 +#define TK_BY                              34
  1.3952 +#define TK_CASCADE                         35
  1.3953 +#define TK_CAST                            36
  1.3954 +#define TK_CONFLICT                        37
  1.3955 +#define TK_DATABASE                        38
  1.3956 +#define TK_DESC                            39
  1.3957 +#define TK_DETACH                          40
  1.3958 +#define TK_EACH                            41
  1.3959 +#define TK_FAIL                            42
  1.3960 +#define TK_OR                              43
  1.3961 +#define TK_AND                             44
  1.3962 +#define TK_IS                              45
  1.3963 +#define TK_MATCH                           46
  1.3964 +#define TK_LIKE_KW                         47
  1.3965 +#define TK_BETWEEN                         48
  1.3966 +#define TK_IN                              49
  1.3967 +#define TK_ISNULL                          50
  1.3968 +#define TK_NOTNULL                         51
  1.3969 +#define TK_NE                              52
  1.3970 +#define TK_EQ                              53
  1.3971 +#define TK_GT                              54
  1.3972 +#define TK_LE                              55
  1.3973 +#define TK_LT                              56
  1.3974 +#define TK_GE                              57
  1.3975 +#define TK_ESCAPE                          58
  1.3976 +#define TK_ID                              59
  1.3977 +#define TK_COLUMNKW                        60
  1.3978 +#define TK_DO                              61
  1.3979 +#define TK_FOR                             62
  1.3980 +#define TK_IGNORE                          63
  1.3981 +#define TK_INITIALLY                       64
  1.3982 +#define TK_INSTEAD                         65
  1.3983 +#define TK_NO                              66
  1.3984 +#define TK_KEY                             67
  1.3985 +#define TK_OF                              68
  1.3986 +#define TK_OFFSET                          69
  1.3987 +#define TK_PRAGMA                          70
  1.3988 +#define TK_RAISE                           71
  1.3989 +#define TK_RECURSIVE                       72
  1.3990 +#define TK_REPLACE                         73
  1.3991 +#define TK_RESTRICT                        74
  1.3992 +#define TK_ROW                             75
  1.3993 +#define TK_ROWS                            76
  1.3994 +#define TK_TRIGGER                         77
  1.3995 +#define TK_VACUUM                          78
  1.3996 +#define TK_VIEW                            79
  1.3997 +#define TK_VIRTUAL                         80
  1.3998 +#define TK_WITH                            81
  1.3999 +#define TK_CURRENT                         82
  1.4000 +#define TK_FOLLOWING                       83
  1.4001 +#define TK_PARTITION                       84
  1.4002 +#define TK_PRECEDING                       85
  1.4003 +#define TK_RANGE                           86
  1.4004 +#define TK_UNBOUNDED                       87
  1.4005 +#define TK_REINDEX                         88
  1.4006 +#define TK_RENAME                          89
  1.4007 +#define TK_CTIME_KW                        90
  1.4008 +#define TK_ANY                             91
  1.4009 +#define TK_BITAND                          92
  1.4010 +#define TK_BITOR                           93
  1.4011 +#define TK_LSHIFT                          94
  1.4012 +#define TK_RSHIFT                          95
  1.4013 +#define TK_PLUS                            96
  1.4014 +#define TK_MINUS                           97
  1.4015 +#define TK_STAR                            98
  1.4016 +#define TK_SLASH                           99
  1.4017 +#define TK_REM                            100
  1.4018 +#define TK_CONCAT                         101
  1.4019 +#define TK_COLLATE                        102
  1.4020 +#define TK_BITNOT                         103
  1.4021 +#define TK_ON                             104
  1.4022 +#define TK_INDEXED                        105
  1.4023 +#define TK_STRING                         106
  1.4024 +#define TK_JOIN_KW                        107
  1.4025 +#define TK_CONSTRAINT                     108
  1.4026 +#define TK_DEFAULT                        109
  1.4027 +#define TK_NULL                           110
  1.4028 +#define TK_PRIMARY                        111
  1.4029 +#define TK_UNIQUE                         112
  1.4030 +#define TK_CHECK                          113
  1.4031 +#define TK_REFERENCES                     114
  1.4032 +#define TK_AUTOINCR                       115
  1.4033 +#define TK_INSERT                         116
  1.4034 +#define TK_DELETE                         117
  1.4035 +#define TK_UPDATE                         118
  1.4036 +#define TK_SET                            119
  1.4037 +#define TK_DEFERRABLE                     120
  1.4038 +#define TK_FOREIGN                        121
  1.4039 +#define TK_DROP                           122
  1.4040 +#define TK_UNION                          123
  1.4041 +#define TK_ALL                            124
  1.4042 +#define TK_EXCEPT                         125
  1.4043 +#define TK_INTERSECT                      126
  1.4044 +#define TK_SELECT                         127
  1.4045 +#define TK_VALUES                         128
  1.4046 +#define TK_DISTINCT                       129
  1.4047 +#define TK_DOT                            130
  1.4048 +#define TK_FROM                           131
  1.4049 +#define TK_JOIN                           132
  1.4050 +#define TK_USING                          133
  1.4051 +#define TK_ORDER                          134
  1.4052 +#define TK_GROUP                          135
  1.4053 +#define TK_HAVING                         136
  1.4054 +#define TK_LIMIT                          137
  1.4055 +#define TK_WHERE                          138
  1.4056 +#define TK_INTO                           139
  1.4057 +#define TK_NOTHING                        140
  1.4058 +#define TK_FLOAT                          141
  1.4059 +#define TK_BLOB                           142
  1.4060 +#define TK_INTEGER                        143
  1.4061 +#define TK_VARIABLE                       144
  1.4062 +#define TK_CASE                           145
  1.4063 +#define TK_WHEN                           146
  1.4064 +#define TK_THEN                           147
  1.4065 +#define TK_ELSE                           148
  1.4066 +#define TK_INDEX                          149
  1.4067 +#define TK_ALTER                          150
  1.4068 +#define TK_ADD                            151
  1.4069 +#define TK_WINDOW                         152
  1.4070 +#define TK_OVER                           153
  1.4071 +#define TK_FILTER                         154
  1.4072 +#define TK_TRUEFALSE                      155
  1.4073 +#define TK_ISNOT                          156
  1.4074 +#define TK_FUNCTION                       157
  1.4075 +#define TK_COLUMN                         158
  1.4076 +#define TK_AGG_FUNCTION                   159
  1.4077 +#define TK_AGG_COLUMN                     160
  1.4078 +#define TK_UMINUS                         161
  1.4079 +#define TK_UPLUS                          162
  1.4080 +#define TK_TRUTH                          163
  1.4081 +#define TK_REGISTER                       164
  1.4082 +#define TK_VECTOR                         165
  1.4083 +#define TK_SELECT_COLUMN                  166
  1.4084 +#define TK_IF_NULL_ROW                    167
  1.4085 +#define TK_ASTERISK                       168
  1.4086 +#define TK_SPAN                           169
  1.4087 +#define TK_END_OF_FILE                    170
  1.4088 +#define TK_UNCLOSED_STRING                171
  1.4089 +#define TK_SPACE                          172
  1.4090 +#define TK_ILLEGAL                        173
  1.4091  
  1.4092  /* The token codes above must all fit in 8 bits */
  1.4093  #define TKFLG_MASK           0xff  
  1.4094 @@ -11684,7 +13667,6 @@
  1.4095  */
  1.4096  #ifndef SQLITE_TEMP_STORE
  1.4097  # define SQLITE_TEMP_STORE 1
  1.4098 -# define SQLITE_TEMP_STORE_xc 1  /* Exclude from ctime.c */
  1.4099  #endif
  1.4100  
  1.4101  /*
  1.4102 @@ -11721,6 +13703,22 @@
  1.4103  #endif
  1.4104  
  1.4105  /*
  1.4106 +** Default value for the SQLITE_CONFIG_SORTERREF_SIZE option.
  1.4107 +*/
  1.4108 +#ifndef SQLITE_DEFAULT_SORTERREF_SIZE
  1.4109 +# define SQLITE_DEFAULT_SORTERREF_SIZE 0x7fffffff
  1.4110 +#endif
  1.4111 +
  1.4112 +/*
  1.4113 +** The compile-time options SQLITE_MMAP_READWRITE and 
  1.4114 +** SQLITE_ENABLE_BATCH_ATOMIC_WRITE are not compatible with one another.
  1.4115 +** You must choose one or the other (or neither) but not both.
  1.4116 +*/
  1.4117 +#if defined(SQLITE_MMAP_READWRITE) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
  1.4118 +#error Cannot use both SQLITE_MMAP_READWRITE and SQLITE_ENABLE_BATCH_ATOMIC_WRITE
  1.4119 +#endif
  1.4120 +
  1.4121 +/*
  1.4122  ** GCC does not define the offsetof() macro so we'll have to do it
  1.4123  ** ourselves.
  1.4124  */
  1.4125 @@ -11858,7 +13856,8 @@
  1.4126  # if defined(__SIZEOF_POINTER__)
  1.4127  #   define SQLITE_PTRSIZE __SIZEOF_POINTER__
  1.4128  # elif defined(i386)     || defined(__i386__)   || defined(_M_IX86) ||    \
  1.4129 -       defined(_M_ARM)   || defined(__arm__)    || defined(__x86)
  1.4130 +       defined(_M_ARM)   || defined(__arm__)    || defined(__x86)   ||    \
  1.4131 +      (defined(__TOS_AIX__) && !defined(__64BIT__))
  1.4132  #   define SQLITE_PTRSIZE 4
  1.4133  # else
  1.4134  #   define SQLITE_PTRSIZE 8
  1.4135 @@ -11899,7 +13898,7 @@
  1.4136  # if defined(i386)     || defined(__i386__)   || defined(_M_IX86) ||    \
  1.4137       defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)  ||    \
  1.4138       defined(_M_AMD64) || defined(_M_ARM)     || defined(__x86)   ||    \
  1.4139 -     defined(__arm__)
  1.4140 +     defined(__arm__)  || defined(_M_ARM64)
  1.4141  #   define SQLITE_BYTEORDER    1234
  1.4142  # elif defined(sparc)    || defined(__ppc__)
  1.4143  #   define SQLITE_BYTEORDER    4321
  1.4144 @@ -11985,7 +13984,6 @@
  1.4145  # else
  1.4146  #   define SQLITE_MAX_MMAP_SIZE 0
  1.4147  # endif
  1.4148 -# define SQLITE_MAX_MMAP_SIZE_xc 1 /* exclude from ctime.c */
  1.4149  #endif
  1.4150  
  1.4151  /*
  1.4152 @@ -11995,7 +13993,6 @@
  1.4153  */
  1.4154  #ifndef SQLITE_DEFAULT_MMAP_SIZE
  1.4155  # define SQLITE_DEFAULT_MMAP_SIZE 0
  1.4156 -# define SQLITE_DEFAULT_MMAP_SIZE_xc 1  /* Exclude from ctime.c */
  1.4157  #endif
  1.4158  #if SQLITE_DEFAULT_MMAP_SIZE>SQLITE_MAX_MMAP_SIZE
  1.4159  # undef SQLITE_DEFAULT_MMAP_SIZE
  1.4160 @@ -12020,7 +14017,7 @@
  1.4161  ** SELECTTRACE_ENABLED will be either 1 or 0 depending on whether or not
  1.4162  ** the Select query generator tracing logic is turned on.
  1.4163  */
  1.4164 -#if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_SELECTTRACE)
  1.4165 +#if defined(SQLITE_ENABLE_SELECTTRACE)
  1.4166  # define SELECTTRACE_ENABLED 1
  1.4167  #else
  1.4168  # define SELECTTRACE_ENABLED 0
  1.4169 @@ -12037,9 +14034,10 @@
  1.4170  */
  1.4171  typedef struct BusyHandler BusyHandler;
  1.4172  struct BusyHandler {
  1.4173 -  int (*xFunc)(void *,int);  /* The busy callback */
  1.4174 -  void *pArg;                /* First arg to busy callback */
  1.4175 -  int nBusy;                 /* Incremented with each busy call */
  1.4176 +  int (*xBusyHandler)(void *,int);  /* The busy callback */
  1.4177 +  void *pBusyArg;                   /* First arg to busy callback */
  1.4178 +  int nBusy;                        /* Incremented with each busy call */
  1.4179 +  u8 bExtraFileArg;                 /* Include sqlite3_file as callback arg */
  1.4180  };
  1.4181  
  1.4182  /*
  1.4183 @@ -12139,7 +14137,6 @@
  1.4184  typedef struct Schema Schema;
  1.4185  typedef struct Expr Expr;
  1.4186  typedef struct ExprList ExprList;
  1.4187 -typedef struct ExprSpan ExprSpan;
  1.4188  typedef struct FKey FKey;
  1.4189  typedef struct FuncDestructor FuncDestructor;
  1.4190  typedef struct FuncDef FuncDef;
  1.4191 @@ -12156,13 +14153,14 @@
  1.4192  typedef struct Parse Parse;
  1.4193  typedef struct PreUpdate PreUpdate;
  1.4194  typedef struct PrintfArguments PrintfArguments;
  1.4195 +typedef struct RenameToken RenameToken;
  1.4196  typedef struct RowSet RowSet;
  1.4197  typedef struct Savepoint Savepoint;
  1.4198  typedef struct Select Select;
  1.4199  typedef struct SQLiteThread SQLiteThread;
  1.4200  typedef struct SelectDest SelectDest;
  1.4201  typedef struct SrcList SrcList;
  1.4202 -typedef struct StrAccum StrAccum;
  1.4203 +typedef struct sqlite3_str StrAccum; /* Internal alias for sqlite3_str */
  1.4204  typedef struct Table Table;
  1.4205  typedef struct TableLock TableLock;
  1.4206  typedef struct Token Token;
  1.4207 @@ -12171,12 +14169,40 @@
  1.4208  typedef struct TriggerPrg TriggerPrg;
  1.4209  typedef struct TriggerStep TriggerStep;
  1.4210  typedef struct UnpackedRecord UnpackedRecord;
  1.4211 +typedef struct Upsert Upsert;
  1.4212  typedef struct VTable VTable;
  1.4213  typedef struct VtabCtx VtabCtx;
  1.4214  typedef struct Walker Walker;
  1.4215  typedef struct WhereInfo WhereInfo;
  1.4216 +typedef struct Window Window;
  1.4217  typedef struct With With;
  1.4218  
  1.4219 +
  1.4220 +/*
  1.4221 +** The bitmask datatype defined below is used for various optimizations.
  1.4222 +**
  1.4223 +** Changing this from a 64-bit to a 32-bit type limits the number of
  1.4224 +** tables in a join to 32 instead of 64.  But it also reduces the size
  1.4225 +** of the library by 738 bytes on ix86.
  1.4226 +*/
  1.4227 +#ifdef SQLITE_BITMASK_TYPE
  1.4228 +  typedef SQLITE_BITMASK_TYPE Bitmask;
  1.4229 +#else
  1.4230 +  typedef u64 Bitmask;
  1.4231 +#endif
  1.4232 +
  1.4233 +/*
  1.4234 +** The number of bits in a Bitmask.  "BMS" means "BitMask Size".
  1.4235 +*/
  1.4236 +#define BMS  ((int)(sizeof(Bitmask)*8))
  1.4237 +
  1.4238 +/*
  1.4239 +** A bit in a Bitmask
  1.4240 +*/
  1.4241 +#define MASKBIT(n)   (((Bitmask)1)<<(n))
  1.4242 +#define MASKBIT32(n) (((unsigned int)1)<<(n))
  1.4243 +#define ALLBITS      ((Bitmask)-1)
  1.4244 +
  1.4245  /* A VList object records a mapping between parameters/variables/wildcards
  1.4246  ** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
  1.4247  ** variable number associated with that parameter.  See the format description
  1.4248 @@ -12272,7 +14298,7 @@
  1.4249  SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p);
  1.4250  SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
  1.4251  SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
  1.4252 -SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int);
  1.4253 +SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int,int*);
  1.4254  SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
  1.4255  SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int);
  1.4256  SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*);
  1.4257 @@ -12424,6 +14450,7 @@
  1.4258    struct KeyInfo*,                     /* First argument to compare function */
  1.4259    BtCursor *pCursor                    /* Space to write cursor structure */
  1.4260  );
  1.4261 +SQLITE_PRIVATE BtCursor *sqlite3BtreeFakeValidCursor(void);
  1.4262  SQLITE_PRIVATE int sqlite3BtreeCursorSize(void);
  1.4263  SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor*);
  1.4264  SQLITE_PRIVATE void sqlite3BtreeCursorHintFlags(BtCursor*, unsigned);
  1.4265 @@ -12452,13 +14479,28 @@
  1.4266  ** entry in either an index or table btree.
  1.4267  **
  1.4268  ** Index btrees (used for indexes and also WITHOUT ROWID tables) contain
  1.4269 -** an arbitrary key and no data.  These btrees have pKey,nKey set to their
  1.4270 -** key and pData,nData,nZero set to zero.
  1.4271 +** an arbitrary key and no data.  These btrees have pKey,nKey set to the
  1.4272 +** key and the pData,nData,nZero fields are uninitialized.  The aMem,nMem
  1.4273 +** fields give an array of Mem objects that are a decomposition of the key.
  1.4274 +** The nMem field might be zero, indicating that no decomposition is available.
  1.4275  **
  1.4276  ** Table btrees (used for rowid tables) contain an integer rowid used as
  1.4277  ** the key and passed in the nKey field.  The pKey field is zero.  
  1.4278  ** pData,nData hold the content of the new entry.  nZero extra zero bytes
  1.4279  ** are appended to the end of the content when constructing the entry.
  1.4280 +** The aMem,nMem fields are uninitialized for table btrees.
  1.4281 +**
  1.4282 +** Field usage summary:
  1.4283 +**
  1.4284 +**               Table BTrees                   Index Btrees
  1.4285 +**
  1.4286 +**   pKey        always NULL                    encoded key
  1.4287 +**   nKey        the ROWID                      length of pKey
  1.4288 +**   pData       data                           not used
  1.4289 +**   aMem        not used                       decomposed key value
  1.4290 +**   nMem        not used                       entries in aMem
  1.4291 +**   nData       length of pData                not used
  1.4292 +**   nZero       extra zeros after pData        not used
  1.4293  **
  1.4294  ** This object is used to pass information into sqlite3BtreeInsert().  The
  1.4295  ** same information used to be passed as five separate parameters.  But placing
  1.4296 @@ -12469,7 +14511,7 @@
  1.4297  struct BtreePayload {
  1.4298    const void *pKey;       /* Key content for indexes.  NULL for tables */
  1.4299    sqlite3_int64 nKey;     /* Size of pKey for indexes.  PRIMARY KEY for tabs */
  1.4300 -  const void *pData;      /* Data for tables.  NULL for indexes */
  1.4301 +  const void *pData;      /* Data for tables. */
  1.4302    sqlite3_value *aMem;    /* First of nMem value in the unpacked pKey */
  1.4303    u16 nMem;               /* Number of aMem[] value.  Might be zero */
  1.4304    int nData;              /* Size of pData.  0 if none. */
  1.4305 @@ -12479,11 +14521,17 @@
  1.4306  SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
  1.4307                         int flags, int seekResult);
  1.4308  SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
  1.4309 +#ifndef SQLITE_OMIT_WINDOWFUNC
  1.4310 +SQLITE_PRIVATE void sqlite3BtreeSkipNext(BtCursor*);
  1.4311 +#endif
  1.4312  SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
  1.4313 -SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
  1.4314 +SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int flags);
  1.4315  SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
  1.4316 -SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
  1.4317 +SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int flags);
  1.4318  SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
  1.4319 +#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
  1.4320 +SQLITE_PRIVATE i64 sqlite3BtreeOffset(BtCursor*);
  1.4321 +#endif
  1.4322  SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
  1.4323  SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
  1.4324  SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
  1.4325 @@ -12633,7 +14681,7 @@
  1.4326  #ifdef SQLITE_ENABLE_CURSOR_HINTS
  1.4327      Expr *pExpr;           /* Used when p4type is P4_EXPR */
  1.4328  #endif
  1.4329 -    int (*xAdvance)(BtCursor *, int *);
  1.4330 +    int (*xAdvance)(BtCursor *, int);
  1.4331    } p4;
  1.4332  #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
  1.4333    char *zComment;          /* Comment to improve readability */
  1.4334 @@ -12643,7 +14691,8 @@
  1.4335    u64 cycles;              /* Total time spent executing this instruction */
  1.4336  #endif
  1.4337  #ifdef SQLITE_VDBE_COVERAGE
  1.4338 -  int iSrcLine;            /* Source-code line that generated this opcode */
  1.4339 +  u32 iSrcLine;            /* Source-code line that generated this opcode
  1.4340 +                           ** with flags in the upper 8 bits */
  1.4341  #endif
  1.4342  };
  1.4343  typedef struct VdbeOp VdbeOp;
  1.4344 @@ -12677,24 +14726,27 @@
  1.4345  /*
  1.4346  ** Allowed values of VdbeOp.p4type
  1.4347  */
  1.4348 -#define P4_NOTUSED    0   /* The P4 parameter is not used */
  1.4349 -#define P4_DYNAMIC  (-1)  /* Pointer to a string obtained from sqliteMalloc() */
  1.4350 -#define P4_STATIC   (-2)  /* Pointer to a static string */
  1.4351 -#define P4_COLLSEQ  (-3)  /* P4 is a pointer to a CollSeq structure */
  1.4352 -#define P4_FUNCDEF  (-4)  /* P4 is a pointer to a FuncDef structure */
  1.4353 -#define P4_KEYINFO  (-5)  /* P4 is a pointer to a KeyInfo structure */
  1.4354 -#define P4_EXPR     (-6)  /* P4 is a pointer to an Expr tree */
  1.4355 -#define P4_MEM      (-7)  /* P4 is a pointer to a Mem*    structure */
  1.4356 -#define P4_TRANSIENT  0   /* P4 is a pointer to a transient string */
  1.4357 -#define P4_VTAB     (-8) /* P4 is a pointer to an sqlite3_vtab structure */
  1.4358 -#define P4_REAL     (-9) /* P4 is a 64-bit floating point value */
  1.4359 -#define P4_INT64    (-10) /* P4 is a 64-bit signed integer */
  1.4360 -#define P4_INT32    (-11) /* P4 is a 32-bit signed integer */
  1.4361 -#define P4_INTARRAY (-12) /* P4 is a vector of 32-bit integers */
  1.4362 -#define P4_SUBPROGRAM  (-13) /* P4 is a pointer to a SubProgram structure */
  1.4363 -#define P4_ADVANCE  (-14) /* P4 is a pointer to BtreeNext() or BtreePrev() */
  1.4364 -#define P4_TABLE    (-15) /* P4 is a pointer to a Table structure */
  1.4365 -#define P4_FUNCCTX  (-16) /* P4 is a pointer to an sqlite3_context object */
  1.4366 +#define P4_NOTUSED      0   /* The P4 parameter is not used */
  1.4367 +#define P4_TRANSIENT    0   /* P4 is a pointer to a transient string */
  1.4368 +#define P4_STATIC     (-1)  /* Pointer to a static string */
  1.4369 +#define P4_COLLSEQ    (-2)  /* P4 is a pointer to a CollSeq structure */
  1.4370 +#define P4_INT32      (-3)  /* P4 is a 32-bit signed integer */
  1.4371 +#define P4_SUBPROGRAM (-4)  /* P4 is a pointer to a SubProgram structure */
  1.4372 +#define P4_ADVANCE    (-5)  /* P4 is a pointer to BtreeNext() or BtreePrev() */
  1.4373 +#define P4_TABLE      (-6)  /* P4 is a pointer to a Table structure */
  1.4374 +/* Above do not own any resources.  Must free those below */
  1.4375 +#define P4_FREE_IF_LE (-7)
  1.4376 +#define P4_DYNAMIC    (-7)  /* Pointer to memory from sqliteMalloc() */
  1.4377 +#define P4_FUNCDEF    (-8)  /* P4 is a pointer to a FuncDef structure */
  1.4378 +#define P4_KEYINFO    (-9)  /* P4 is a pointer to a KeyInfo structure */
  1.4379 +#define P4_EXPR       (-10) /* P4 is a pointer to an Expr tree */
  1.4380 +#define P4_MEM        (-11) /* P4 is a pointer to a Mem*    structure */
  1.4381 +#define P4_VTAB       (-12) /* P4 is a pointer to an sqlite3_vtab structure */
  1.4382 +#define P4_REAL       (-13) /* P4 is a 64-bit floating point value */
  1.4383 +#define P4_INT64      (-14) /* P4 is a 64-bit signed integer */
  1.4384 +#define P4_INTARRAY   (-15) /* P4 is a vector of 32-bit integers */
  1.4385 +#define P4_FUNCCTX    (-16) /* P4 is a pointer to an sqlite3_context object */
  1.4386 +#define P4_DYNBLOB    (-17) /* Pointer to memory from sqliteMalloc() */
  1.4387  
  1.4388  /* Error message codes for OP_Halt */
  1.4389  #define P5_ConstraintNotNull 1
  1.4390 @@ -12740,169 +14792,177 @@
  1.4391  #define OP_Savepoint       0
  1.4392  #define OP_AutoCommit      1
  1.4393  #define OP_Transaction     2
  1.4394 -#define OP_SorterNext      3
  1.4395 -#define OP_PrevIfOpen      4
  1.4396 -#define OP_NextIfOpen      5
  1.4397 -#define OP_Prev            6
  1.4398 -#define OP_Next            7
  1.4399 -#define OP_Checkpoint      8
  1.4400 -#define OP_JournalMode     9
  1.4401 -#define OP_Vacuum         10
  1.4402 -#define OP_VFilter        11 /* synopsis: iplan=r[P3] zplan='P4'           */
  1.4403 -#define OP_VUpdate        12 /* synopsis: data=r[P3@P2]                    */
  1.4404 -#define OP_Goto           13
  1.4405 -#define OP_Gosub          14
  1.4406 -#define OP_InitCoroutine  15
  1.4407 -#define OP_Yield          16
  1.4408 -#define OP_MustBeInt      17
  1.4409 -#define OP_Jump           18
  1.4410 +#define OP_SorterNext      3 /* jump                                       */
  1.4411 +#define OP_Prev            4 /* jump                                       */
  1.4412 +#define OP_Next            5 /* jump                                       */
  1.4413 +#define OP_Checkpoint      6
  1.4414 +#define OP_JournalMode     7
  1.4415 +#define OP_Vacuum          8
  1.4416 +#define OP_VFilter         9 /* jump, synopsis: iplan=r[P3] zplan='P4'     */
  1.4417 +#define OP_VUpdate        10 /* synopsis: data=r[P3@P2]                    */
  1.4418 +#define OP_Goto           11 /* jump                                       */
  1.4419 +#define OP_Gosub          12 /* jump                                       */
  1.4420 +#define OP_InitCoroutine  13 /* jump                                       */
  1.4421 +#define OP_Yield          14 /* jump                                       */
  1.4422 +#define OP_MustBeInt      15 /* jump                                       */
  1.4423 +#define OP_Jump           16 /* jump                                       */
  1.4424 +#define OP_Once           17 /* jump                                       */
  1.4425 +#define OP_If             18 /* jump                                       */
  1.4426  #define OP_Not            19 /* same as TK_NOT, synopsis: r[P2]= !r[P1]    */
  1.4427 -#define OP_Once           20
  1.4428 -#define OP_If             21
  1.4429 -#define OP_IfNot          22
  1.4430 -#define OP_IfNullRow      23 /* synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
  1.4431 -#define OP_SeekLT         24 /* synopsis: key=r[P3@P4]                     */
  1.4432 -#define OP_SeekLE         25 /* synopsis: key=r[P3@P4]                     */
  1.4433 -#define OP_SeekGE         26 /* synopsis: key=r[P3@P4]                     */
  1.4434 -#define OP_SeekGT         27 /* synopsis: key=r[P3@P4]                     */
  1.4435 -#define OP_NoConflict     28 /* synopsis: key=r[P3@P4]                     */
  1.4436 -#define OP_NotFound       29 /* synopsis: key=r[P3@P4]                     */
  1.4437 -#define OP_Found          30 /* synopsis: key=r[P3@P4]                     */
  1.4438 -#define OP_SeekRowid      31 /* synopsis: intkey=r[P3]                     */
  1.4439 -#define OP_NotExists      32 /* synopsis: intkey=r[P3]                     */
  1.4440 -#define OP_Last           33
  1.4441 -#define OP_IfSmaller      34
  1.4442 -#define OP_SorterSort     35
  1.4443 -#define OP_Sort           36
  1.4444 -#define OP_Rewind         37
  1.4445 -#define OP_IdxLE          38 /* synopsis: key=r[P3@P4]                     */
  1.4446 -#define OP_IdxGT          39 /* synopsis: key=r[P3@P4]                     */
  1.4447 -#define OP_IdxLT          40 /* synopsis: key=r[P3@P4]                     */
  1.4448 -#define OP_IdxGE          41 /* synopsis: key=r[P3@P4]                     */
  1.4449 -#define OP_RowSetRead     42 /* synopsis: r[P3]=rowset(P1)                 */
  1.4450 -#define OP_RowSetTest     43 /* synopsis: if r[P3] in rowset(P1) goto P2   */
  1.4451 -#define OP_Program        44
  1.4452 -#define OP_FkIfZero       45 /* synopsis: if fkctr[P1]==0 goto P2          */
  1.4453 -#define OP_IfPos          46 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
  1.4454 -#define OP_IfNotZero      47 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
  1.4455 -#define OP_DecrJumpZero   48 /* synopsis: if (--r[P1])==0 goto P2          */
  1.4456 -#define OP_IncrVacuum     49
  1.4457 -#define OP_VNext          50
  1.4458 -#define OP_Init           51 /* synopsis: Start at P2                      */
  1.4459 -#define OP_Return         52
  1.4460 -#define OP_EndCoroutine   53
  1.4461 -#define OP_HaltIfNull     54 /* synopsis: if r[P3]=null halt               */
  1.4462 -#define OP_Halt           55
  1.4463 -#define OP_Integer        56 /* synopsis: r[P2]=P1                         */
  1.4464 -#define OP_Int64          57 /* synopsis: r[P2]=P4                         */
  1.4465 -#define OP_String         58 /* synopsis: r[P2]='P4' (len=P1)              */
  1.4466 -#define OP_Null           59 /* synopsis: r[P2..P3]=NULL                   */
  1.4467 -#define OP_SoftNull       60 /* synopsis: r[P1]=NULL                       */
  1.4468 -#define OP_Blob           61 /* synopsis: r[P2]=P4 (len=P1)                */
  1.4469 -#define OP_Variable       62 /* synopsis: r[P2]=parameter(P1,P4)           */
  1.4470 -#define OP_Move           63 /* synopsis: r[P2@P3]=r[P1@P3]                */
  1.4471 -#define OP_Copy           64 /* synopsis: r[P2@P3+1]=r[P1@P3+1]            */
  1.4472 -#define OP_SCopy          65 /* synopsis: r[P2]=r[P1]                      */
  1.4473 -#define OP_IntCopy        66 /* synopsis: r[P2]=r[P1]                      */
  1.4474 -#define OP_ResultRow      67 /* synopsis: output=r[P1@P2]                  */
  1.4475 -#define OP_CollSeq        68
  1.4476 -#define OP_Function0      69 /* synopsis: r[P3]=func(r[P2@P5])             */
  1.4477 -#define OP_Or             70 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
  1.4478 -#define OP_And            71 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
  1.4479 -#define OP_Function       72 /* synopsis: r[P3]=func(r[P2@P5])             */
  1.4480 -#define OP_AddImm         73 /* synopsis: r[P1]=r[P1]+P2                   */
  1.4481 -#define OP_RealAffinity   74
  1.4482 -#define OP_IsNull         75 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
  1.4483 -#define OP_NotNull        76 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
  1.4484 -#define OP_Ne             77 /* same as TK_NE, synopsis: IF r[P3]!=r[P1]   */
  1.4485 -#define OP_Eq             78 /* same as TK_EQ, synopsis: IF r[P3]==r[P1]   */
  1.4486 -#define OP_Gt             79 /* same as TK_GT, synopsis: IF r[P3]>r[P1]    */
  1.4487 -#define OP_Le             80 /* same as TK_LE, synopsis: IF r[P3]<=r[P1]   */
  1.4488 -#define OP_Lt             81 /* same as TK_LT, synopsis: IF r[P3]<r[P1]    */
  1.4489 -#define OP_Ge             82 /* same as TK_GE, synopsis: IF r[P3]>=r[P1]   */
  1.4490 -#define OP_ElseNotEq      83 /* same as TK_ESCAPE                          */
  1.4491 -#define OP_BitAnd         84 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
  1.4492 -#define OP_BitOr          85 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
  1.4493 -#define OP_ShiftLeft      86 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
  1.4494 -#define OP_ShiftRight     87 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
  1.4495 -#define OP_Add            88 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
  1.4496 -#define OP_Subtract       89 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
  1.4497 -#define OP_Multiply       90 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
  1.4498 -#define OP_Divide         91 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
  1.4499 -#define OP_Remainder      92 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
  1.4500 -#define OP_Concat         93 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
  1.4501 -#define OP_Cast           94 /* synopsis: affinity(r[P1])                  */
  1.4502 -#define OP_BitNot         95 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
  1.4503 -#define OP_Permutation    96
  1.4504 -#define OP_String8        97 /* same as TK_STRING, synopsis: r[P2]='P4'    */
  1.4505 -#define OP_Compare        98 /* synopsis: r[P1@P3] <-> r[P2@P3]            */
  1.4506 -#define OP_Column         99 /* synopsis: r[P3]=PX                         */
  1.4507 -#define OP_Affinity      100 /* synopsis: affinity(r[P1@P2])               */
  1.4508 -#define OP_MakeRecord    101 /* synopsis: r[P3]=mkrec(r[P1@P2])            */
  1.4509 -#define OP_Count         102 /* synopsis: r[P2]=count()                    */
  1.4510 -#define OP_ReadCookie    103
  1.4511 -#define OP_SetCookie     104
  1.4512 -#define OP_ReopenIdx     105 /* synopsis: root=P2 iDb=P3                   */
  1.4513 -#define OP_OpenRead      106 /* synopsis: root=P2 iDb=P3                   */
  1.4514 -#define OP_OpenWrite     107 /* synopsis: root=P2 iDb=P3                   */
  1.4515 -#define OP_OpenDup       108
  1.4516 -#define OP_OpenAutoindex 109 /* synopsis: nColumn=P2                       */
  1.4517 -#define OP_OpenEphemeral 110 /* synopsis: nColumn=P2                       */
  1.4518 -#define OP_SorterOpen    111
  1.4519 -#define OP_SequenceTest  112 /* synopsis: if( cursor[P1].ctr++ ) pc = P2   */
  1.4520 -#define OP_OpenPseudo    113 /* synopsis: P3 columns in r[P2]              */
  1.4521 -#define OP_Close         114
  1.4522 -#define OP_ColumnsUsed   115
  1.4523 -#define OP_Sequence      116 /* synopsis: r[P2]=cursor[P1].ctr++           */
  1.4524 -#define OP_NewRowid      117 /* synopsis: r[P2]=rowid                      */
  1.4525 -#define OP_Insert        118 /* synopsis: intkey=r[P3] data=r[P2]          */
  1.4526 -#define OP_InsertInt     119 /* synopsis: intkey=P3 data=r[P2]             */
  1.4527 -#define OP_Delete        120
  1.4528 -#define OP_ResetCount    121
  1.4529 -#define OP_SorterCompare 122 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
  1.4530 -#define OP_SorterData    123 /* synopsis: r[P2]=data                       */
  1.4531 -#define OP_RowData       124 /* synopsis: r[P2]=data                       */
  1.4532 -#define OP_Rowid         125 /* synopsis: r[P2]=rowid                      */
  1.4533 -#define OP_NullRow       126
  1.4534 -#define OP_SorterInsert  127 /* synopsis: key=r[P2]                        */
  1.4535 -#define OP_IdxInsert     128 /* synopsis: key=r[P2]                        */
  1.4536 -#define OP_IdxDelete     129 /* synopsis: key=r[P2@P3]                     */
  1.4537 -#define OP_Seek          130 /* synopsis: Move P3 to P1.rowid              */
  1.4538 -#define OP_IdxRowid      131 /* synopsis: r[P2]=rowid                      */
  1.4539 -#define OP_Real          132 /* same as TK_FLOAT, synopsis: r[P2]=P4       */
  1.4540 -#define OP_Destroy       133
  1.4541 -#define OP_Clear         134
  1.4542 -#define OP_ResetSorter   135
  1.4543 -#define OP_CreateIndex   136 /* synopsis: r[P2]=root iDb=P1                */
  1.4544 -#define OP_CreateTable   137 /* synopsis: r[P2]=root iDb=P1                */
  1.4545 -#define OP_SqlExec       138
  1.4546 -#define OP_ParseSchema   139
  1.4547 -#define OP_LoadAnalysis  140
  1.4548 -#define OP_DropTable     141
  1.4549 -#define OP_DropIndex     142
  1.4550 -#define OP_DropTrigger   143
  1.4551 -#define OP_IntegrityCk   144
  1.4552 -#define OP_RowSetAdd     145 /* synopsis: rowset(P1)=r[P2]                 */
  1.4553 -#define OP_Param         146
  1.4554 -#define OP_FkCounter     147 /* synopsis: fkctr[P1]+=P2                    */
  1.4555 -#define OP_MemMax        148 /* synopsis: r[P1]=max(r[P1],r[P2])           */
  1.4556 -#define OP_OffsetLimit   149 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
  1.4557 -#define OP_AggStep0      150 /* synopsis: accum=r[P3] step(r[P2@P5])       */
  1.4558 -#define OP_AggStep       151 /* synopsis: accum=r[P3] step(r[P2@P5])       */
  1.4559 -#define OP_AggFinal      152 /* synopsis: accum=r[P1] N=P2                 */
  1.4560 -#define OP_Expire        153
  1.4561 -#define OP_TableLock     154 /* synopsis: iDb=P1 root=P2 write=P3          */
  1.4562 -#define OP_VBegin        155
  1.4563 -#define OP_VCreate       156
  1.4564 -#define OP_VDestroy      157
  1.4565 -#define OP_VOpen         158
  1.4566 -#define OP_VColumn       159 /* synopsis: r[P3]=vcolumn(P2)                */
  1.4567 -#define OP_VRename       160
  1.4568 -#define OP_Pagecount     161
  1.4569 -#define OP_MaxPgcnt      162
  1.4570 -#define OP_CursorHint    163
  1.4571 -#define OP_Noop          164
  1.4572 -#define OP_Explain       165
  1.4573 +#define OP_IfNot          20 /* jump                                       */
  1.4574 +#define OP_IfNullRow      21 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
  1.4575 +#define OP_SeekLT         22 /* jump, synopsis: key=r[P3@P4]               */
  1.4576 +#define OP_SeekLE         23 /* jump, synopsis: key=r[P3@P4]               */
  1.4577 +#define OP_SeekGE         24 /* jump, synopsis: key=r[P3@P4]               */
  1.4578 +#define OP_SeekGT         25 /* jump, synopsis: key=r[P3@P4]               */
  1.4579 +#define OP_IfNoHope       26 /* jump, synopsis: key=r[P3@P4]               */
  1.4580 +#define OP_NoConflict     27 /* jump, synopsis: key=r[P3@P4]               */
  1.4581 +#define OP_NotFound       28 /* jump, synopsis: key=r[P3@P4]               */
  1.4582 +#define OP_Found          29 /* jump, synopsis: key=r[P3@P4]               */
  1.4583 +#define OP_SeekRowid      30 /* jump, synopsis: intkey=r[P3]               */
  1.4584 +#define OP_NotExists      31 /* jump, synopsis: intkey=r[P3]               */
  1.4585 +#define OP_Last           32 /* jump                                       */
  1.4586 +#define OP_IfSmaller      33 /* jump                                       */
  1.4587 +#define OP_SorterSort     34 /* jump                                       */
  1.4588 +#define OP_Sort           35 /* jump                                       */
  1.4589 +#define OP_Rewind         36 /* jump                                       */
  1.4590 +#define OP_IdxLE          37 /* jump, synopsis: key=r[P3@P4]               */
  1.4591 +#define OP_IdxGT          38 /* jump, synopsis: key=r[P3@P4]               */
  1.4592 +#define OP_IdxLT          39 /* jump, synopsis: key=r[P3@P4]               */
  1.4593 +#define OP_IdxGE          40 /* jump, synopsis: key=r[P3@P4]               */
  1.4594 +#define OP_RowSetRead     41 /* jump, synopsis: r[P3]=rowset(P1)           */
  1.4595 +#define OP_RowSetTest     42 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
  1.4596 +#define OP_Or             43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
  1.4597 +#define OP_And            44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
  1.4598 +#define OP_Program        45 /* jump                                       */
  1.4599 +#define OP_FkIfZero       46 /* jump, synopsis: if fkctr[P1]==0 goto P2    */
  1.4600 +#define OP_IfPos          47 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
  1.4601 +#define OP_IfNotZero      48 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
  1.4602 +#define OP_DecrJumpZero   49 /* jump, synopsis: if (--r[P1])==0 goto P2    */
  1.4603 +#define OP_IsNull         50 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
  1.4604 +#define OP_NotNull        51 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
  1.4605 +#define OP_Ne             52 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
  1.4606 +#define OP_Eq             53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
  1.4607 +#define OP_Gt             54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
  1.4608 +#define OP_Le             55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
  1.4609 +#define OP_Lt             56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
  1.4610 +#define OP_Ge             57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
  1.4611 +#define OP_ElseNotEq      58 /* jump, same as TK_ESCAPE                    */
  1.4612 +#define OP_IncrVacuum     59 /* jump                                       */
  1.4613 +#define OP_VNext          60 /* jump                                       */
  1.4614 +#define OP_Init           61 /* jump, synopsis: Start at P2                */
  1.4615 +#define OP_PureFunc0      62
  1.4616 +#define OP_Function0      63 /* synopsis: r[P3]=func(r[P2@P5])             */
  1.4617 +#define OP_PureFunc       64
  1.4618 +#define OP_Function       65 /* synopsis: r[P3]=func(r[P2@P5])             */
  1.4619 +#define OP_Return         66
  1.4620 +#define OP_EndCoroutine   67
  1.4621 +#define OP_HaltIfNull     68 /* synopsis: if r[P3]=null halt               */
  1.4622 +#define OP_Halt           69
  1.4623 +#define OP_Integer        70 /* synopsis: r[P2]=P1                         */
  1.4624 +#define OP_Int64          71 /* synopsis: r[P2]=P4                         */
  1.4625 +#define OP_String         72 /* synopsis: r[P2]='P4' (len=P1)              */
  1.4626 +#define OP_Null           73 /* synopsis: r[P2..P3]=NULL                   */
  1.4627 +#define OP_SoftNull       74 /* synopsis: r[P1]=NULL                       */
  1.4628 +#define OP_Blob           75 /* synopsis: r[P2]=P4 (len=P1)                */
  1.4629 +#define OP_Variable       76 /* synopsis: r[P2]=parameter(P1,P4)           */
  1.4630 +#define OP_Move           77 /* synopsis: r[P2@P3]=r[P1@P3]                */
  1.4631 +#define OP_Copy           78 /* synopsis: r[P2@P3+1]=r[P1@P3+1]            */
  1.4632 +#define OP_SCopy          79 /* synopsis: r[P2]=r[P1]                      */
  1.4633 +#define OP_IntCopy        80 /* synopsis: r[P2]=r[P1]                      */
  1.4634 +#define OP_ResultRow      81 /* synopsis: output=r[P1@P2]                  */
  1.4635 +#define OP_CollSeq        82
  1.4636 +#define OP_AddImm         83 /* synopsis: r[P1]=r[P1]+P2                   */
  1.4637 +#define OP_RealAffinity   84
  1.4638 +#define OP_Cast           85 /* synopsis: affinity(r[P1])                  */
  1.4639 +#define OP_Permutation    86
  1.4640 +#define OP_Compare        87 /* synopsis: r[P1@P3] <-> r[P2@P3]            */
  1.4641 +#define OP_IsTrue         88 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
  1.4642 +#define OP_Offset         89 /* synopsis: r[P3] = sqlite_offset(P1)        */
  1.4643 +#define OP_Column         90 /* synopsis: r[P3]=PX                         */
  1.4644 +#define OP_Affinity       91 /* synopsis: affinity(r[P1@P2])               */
  1.4645 +#define OP_BitAnd         92 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
  1.4646 +#define OP_BitOr          93 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
  1.4647 +#define OP_ShiftLeft      94 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
  1.4648 +#define OP_ShiftRight     95 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
  1.4649 +#define OP_Add            96 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
  1.4650 +#define OP_Subtract       97 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
  1.4651 +#define OP_Multiply       98 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
  1.4652 +#define OP_Divide         99 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
  1.4653 +#define OP_Remainder     100 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
  1.4654 +#define OP_Concat        101 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
  1.4655 +#define OP_MakeRecord    102 /* synopsis: r[P3]=mkrec(r[P1@P2])            */
  1.4656 +#define OP_BitNot        103 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
  1.4657 +#define OP_Count         104 /* synopsis: r[P2]=count()                    */
  1.4658 +#define OP_ReadCookie    105
  1.4659 +#define OP_String8       106 /* same as TK_STRING, synopsis: r[P2]='P4'    */
  1.4660 +#define OP_SetCookie     107
  1.4661 +#define OP_ReopenIdx     108 /* synopsis: root=P2 iDb=P3                   */
  1.4662 +#define OP_OpenRead      109 /* synopsis: root=P2 iDb=P3                   */
  1.4663 +#define OP_OpenWrite     110 /* synopsis: root=P2 iDb=P3                   */
  1.4664 +#define OP_OpenDup       111
  1.4665 +#define OP_OpenAutoindex 112 /* synopsis: nColumn=P2                       */
  1.4666 +#define OP_OpenEphemeral 113 /* synopsis: nColumn=P2                       */
  1.4667 +#define OP_SorterOpen    114
  1.4668 +#define OP_SequenceTest  115 /* synopsis: if( cursor[P1].ctr++ ) pc = P2   */
  1.4669 +#define OP_OpenPseudo    116 /* synopsis: P3 columns in r[P2]              */
  1.4670 +#define OP_Close         117
  1.4671 +#define OP_ColumnsUsed   118
  1.4672 +#define OP_SeekHit       119 /* synopsis: seekHit=P2                       */
  1.4673 +#define OP_Sequence      120 /* synopsis: r[P2]=cursor[P1].ctr++           */
  1.4674 +#define OP_NewRowid      121 /* synopsis: r[P2]=rowid                      */
  1.4675 +#define OP_Insert        122 /* synopsis: intkey=r[P3] data=r[P2]          */
  1.4676 +#define OP_InsertInt     123 /* synopsis: intkey=P3 data=r[P2]             */
  1.4677 +#define OP_Delete        124
  1.4678 +#define OP_ResetCount    125
  1.4679 +#define OP_SorterCompare 126 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
  1.4680 +#define OP_SorterData    127 /* synopsis: r[P2]=data                       */
  1.4681 +#define OP_RowData       128 /* synopsis: r[P2]=data                       */
  1.4682 +#define OP_Rowid         129 /* synopsis: r[P2]=rowid                      */
  1.4683 +#define OP_NullRow       130
  1.4684 +#define OP_SeekEnd       131
  1.4685 +#define OP_SorterInsert  132 /* synopsis: key=r[P2]                        */
  1.4686 +#define OP_IdxInsert     133 /* synopsis: key=r[P2]                        */
  1.4687 +#define OP_IdxDelete     134 /* synopsis: key=r[P2@P3]                     */
  1.4688 +#define OP_DeferredSeek  135 /* synopsis: Move P3 to P1.rowid if needed    */
  1.4689 +#define OP_IdxRowid      136 /* synopsis: r[P2]=rowid                      */
  1.4690 +#define OP_Destroy       137
  1.4691 +#define OP_Clear         138
  1.4692 +#define OP_ResetSorter   139
  1.4693 +#define OP_CreateBtree   140 /* synopsis: r[P2]=root iDb=P1 flags=P3       */
  1.4694 +#define OP_Real          141 /* same as TK_FLOAT, synopsis: r[P2]=P4       */
  1.4695 +#define OP_SqlExec       142
  1.4696 +#define OP_ParseSchema   143
  1.4697 +#define OP_LoadAnalysis  144
  1.4698 +#define OP_DropTable     145
  1.4699 +#define OP_DropIndex     146
  1.4700 +#define OP_DropTrigger   147
  1.4701 +#define OP_IntegrityCk   148
  1.4702 +#define OP_RowSetAdd     149 /* synopsis: rowset(P1)=r[P2]                 */
  1.4703 +#define OP_Param         150
  1.4704 +#define OP_FkCounter     151 /* synopsis: fkctr[P1]+=P2                    */
  1.4705 +#define OP_MemMax        152 /* synopsis: r[P1]=max(r[P1],r[P2])           */
  1.4706 +#define OP_OffsetLimit   153 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
  1.4707 +#define OP_AggInverse    154 /* synopsis: accum=r[P3] inverse(r[P2@P5])    */
  1.4708 +#define OP_AggStep       155 /* synopsis: accum=r[P3] step(r[P2@P5])       */
  1.4709 +#define OP_AggStep1      156 /* synopsis: accum=r[P3] step(r[P2@P5])       */
  1.4710 +#define OP_AggValue      157 /* synopsis: r[P3]=value N=P2                 */
  1.4711 +#define OP_AggFinal      158 /* synopsis: accum=r[P1] N=P2                 */
  1.4712 +#define OP_Expire        159
  1.4713 +#define OP_TableLock     160 /* synopsis: iDb=P1 root=P2 write=P3          */
  1.4714 +#define OP_VBegin        161
  1.4715 +#define OP_VCreate       162
  1.4716 +#define OP_VDestroy      163
  1.4717 +#define OP_VOpen         164
  1.4718 +#define OP_VColumn       165 /* synopsis: r[P3]=vcolumn(P2)                */
  1.4719 +#define OP_VRename       166
  1.4720 +#define OP_Pagecount     167
  1.4721 +#define OP_MaxPgcnt      168
  1.4722 +#define OP_Trace         169
  1.4723 +#define OP_CursorHint    170
  1.4724 +#define OP_Noop          171
  1.4725 +#define OP_Explain       172
  1.4726 +#define OP_Abortable     173
  1.4727  
  1.4728  /* Properties such as "out2" or "jump" that are specified in
  1.4729  ** comments following the "case" for each opcode in the vdbe.c
  1.4730 @@ -12915,27 +14975,28 @@
  1.4731  #define OPFLG_OUT2        0x10  /* out2:  P2 is an output */
  1.4732  #define OPFLG_OUT3        0x20  /* out3:  P3 is an output */
  1.4733  #define OPFLG_INITIALIZER {\
  1.4734 -/*   0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
  1.4735 -/*   8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\
  1.4736 -/*  16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x01,\
  1.4737 +/*   0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x10,\
  1.4738 +/*   8 */ 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03,\
  1.4739 +/*  16 */ 0x01, 0x01, 0x03, 0x12, 0x03, 0x01, 0x09, 0x09,\
  1.4740  /*  24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
  1.4741 -/*  32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
  1.4742 -/*  40 */ 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01, 0x03, 0x03,\
  1.4743 -/*  48 */ 0x03, 0x01, 0x01, 0x01, 0x02, 0x02, 0x08, 0x00,\
  1.4744 -/*  56 */ 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00,\
  1.4745 -/*  64 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x26, 0x26,\
  1.4746 -/*  72 */ 0x00, 0x02, 0x02, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
  1.4747 -/*  80 */ 0x0b, 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26,\
  1.4748 -/*  88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x02, 0x12,\
  1.4749 -/*  96 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
  1.4750 -/* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
  1.4751 -/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
  1.4752 -/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x04,\
  1.4753 -/* 128 */ 0x04, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
  1.4754 -/* 136 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
  1.4755 -/* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00,\
  1.4756 -/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
  1.4757 -/* 160 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,}
  1.4758 +/*  32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
  1.4759 +/*  40 */ 0x01, 0x23, 0x0b, 0x26, 0x26, 0x01, 0x01, 0x03,\
  1.4760 +/*  48 */ 0x03, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
  1.4761 +/*  56 */ 0x0b, 0x0b, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,\
  1.4762 +/*  64 */ 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10,\
  1.4763 +/*  72 */ 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10,\
  1.4764 +/*  80 */ 0x10, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\
  1.4765 +/*  88 */ 0x12, 0x20, 0x00, 0x00, 0x26, 0x26, 0x26, 0x26,\
  1.4766 +/*  96 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00, 0x12,\
  1.4767 +/* 104 */ 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
  1.4768 +/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
  1.4769 +/* 120 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
  1.4770 +/* 128 */ 0x00, 0x10, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00,\
  1.4771 +/* 136 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
  1.4772 +/* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00,\
  1.4773 +/* 152 */ 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
  1.4774 +/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
  1.4775 +/* 168 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,}
  1.4776  
  1.4777  /* The sqlite3P2Values() routine is able to run faster if it knows
  1.4778  ** the value of the largest JUMP opcode.  The smaller the maximum
  1.4779 @@ -12943,12 +15004,18 @@
  1.4780  ** generated this include file strives to group all JUMP opcodes
  1.4781  ** together near the beginning of the list.
  1.4782  */
  1.4783 -#define SQLITE_MX_JUMP_OPCODE  83  /* Maximum JUMP opcode */
  1.4784 +#define SQLITE_MX_JUMP_OPCODE  61  /* Maximum JUMP opcode */
  1.4785  
  1.4786  /************** End of opcodes.h *********************************************/
  1.4787  /************** Continuing where we left off in vdbe.h ***********************/
  1.4788  
  1.4789  /*
  1.4790 +** Additional non-public SQLITE_PREPARE_* flags
  1.4791 +*/
  1.4792 +#define SQLITE_PREPARE_SAVESQL  0x80  /* Preserve SQL text */
  1.4793 +#define SQLITE_PREPARE_MASK     0x0f  /* Mask of public flags */
  1.4794 +
  1.4795 +/*
  1.4796  ** Prototypes for the VDBE interface.  See comments on the implementation
  1.4797  ** for a description of what each of these routines does.
  1.4798  */
  1.4799 @@ -12971,7 +15038,24 @@
  1.4800  # define sqlite3VdbeVerifyNoMallocRequired(A,B)
  1.4801  # define sqlite3VdbeVerifyNoResultRow(A)
  1.4802  #endif
  1.4803 -SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno);
  1.4804 +#if defined(SQLITE_DEBUG)
  1.4805 +SQLITE_PRIVATE   void sqlite3VdbeVerifyAbortable(Vdbe *p, int);
  1.4806 +#else
  1.4807 +# define sqlite3VdbeVerifyAbortable(A,B)
  1.4808 +#endif
  1.4809 +SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp,int iLineno);
  1.4810 +#ifndef SQLITE_OMIT_EXPLAIN
  1.4811 +SQLITE_PRIVATE   void sqlite3VdbeExplain(Parse*,u8,const char*,...);
  1.4812 +SQLITE_PRIVATE   void sqlite3VdbeExplainPop(Parse*);
  1.4813 +SQLITE_PRIVATE   int sqlite3VdbeExplainParent(Parse*);
  1.4814 +# define ExplainQueryPlan(P)        sqlite3VdbeExplain P
  1.4815 +# define ExplainQueryPlanPop(P)     sqlite3VdbeExplainPop(P)
  1.4816 +# define ExplainQueryPlanParent(P)  sqlite3VdbeExplainParent(P)
  1.4817 +#else
  1.4818 +# define ExplainQueryPlan(P)
  1.4819 +# define ExplainQueryPlanPop(P)
  1.4820 +# define ExplainQueryPlanParent(P) 0
  1.4821 +#endif
  1.4822  SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
  1.4823  SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe*, u32 addr, u8);
  1.4824  SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
  1.4825 @@ -13005,7 +15089,8 @@
  1.4826  SQLITE_PRIVATE int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, void(*)(void*));
  1.4827  SQLITE_PRIVATE void sqlite3VdbeCountChanges(Vdbe*);
  1.4828  SQLITE_PRIVATE sqlite3 *sqlite3VdbeDb(Vdbe*);
  1.4829 -SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe*, const char *z, int n, int);
  1.4830 +SQLITE_PRIVATE u8 sqlite3VdbePrepareFlags(Vdbe*);
  1.4831 +SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe*, const char *z, int n, u8);
  1.4832  SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe*,Vdbe*);
  1.4833  SQLITE_PRIVATE VdbeOp *sqlite3VdbeTakeOpArray(Vdbe*, int*, int*);
  1.4834  SQLITE_PRIVATE sqlite3_value *sqlite3VdbeGetBoundValue(Vdbe*, int, u8);
  1.4835 @@ -13014,6 +15099,7 @@
  1.4836  SQLITE_PRIVATE   char *sqlite3VdbeExpandSql(Vdbe*, const char*);
  1.4837  #endif
  1.4838  SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
  1.4839 +SQLITE_PRIVATE int sqlite3BlobCompare(const Mem*, const Mem*);
  1.4840  
  1.4841  SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
  1.4842  SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
  1.4843 @@ -13027,6 +15113,8 @@
  1.4844  SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
  1.4845  #endif
  1.4846  
  1.4847 +SQLITE_PRIVATE int sqlite3NotPureFunc(sqlite3_context*);
  1.4848 +
  1.4849  /* Use SQLITE_ENABLE_COMMENTS to enable generation of extra comments on
  1.4850  ** each VDBE opcode.
  1.4851  **
  1.4852 @@ -13067,23 +15155,52 @@
  1.4853  **
  1.4854  **    VdbeCoverageNeverTaken(v)        // Previous branch is never taken
  1.4855  **
  1.4856 +**    VdbeCoverageNeverNull(v)         // Previous three-way branch is only
  1.4857 +**                                     // taken on the first two ways.  The
  1.4858 +**                                     // NULL option is not possible
  1.4859 +**
  1.4860 +**    VdbeCoverageEqNe(v)              // Previous OP_Jump is only interested
  1.4861 +**                                     // in distingishing equal and not-equal.
  1.4862 +**
  1.4863  ** Every VDBE branch operation must be tagged with one of the macros above.
  1.4864  ** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and
  1.4865  ** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch()
  1.4866  ** routine in vdbe.c, alerting the developer to the missed tag.
  1.4867 +**
  1.4868 +** During testing, the test application will invoke
  1.4869 +** sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE,...) to set a callback
  1.4870 +** routine that is invoked as each bytecode branch is taken.  The callback
  1.4871 +** contains the sqlite3.c source line number ov the VdbeCoverage macro and
  1.4872 +** flags to indicate whether or not the branch was taken.  The test application
  1.4873 +** is responsible for keeping track of this and reporting byte-code branches
  1.4874 +** that are never taken.
  1.4875 +**
  1.4876 +** See the VdbeBranchTaken() macro and vdbeTakeBranch() function in the
  1.4877 +** vdbe.c source file for additional information.
  1.4878  */
  1.4879  #ifdef SQLITE_VDBE_COVERAGE
  1.4880  SQLITE_PRIVATE   void sqlite3VdbeSetLineNumber(Vdbe*,int);
  1.4881  # define VdbeCoverage(v) sqlite3VdbeSetLineNumber(v,__LINE__)
  1.4882  # define VdbeCoverageIf(v,x) if(x)sqlite3VdbeSetLineNumber(v,__LINE__)
  1.4883 -# define VdbeCoverageAlwaysTaken(v) sqlite3VdbeSetLineNumber(v,2);
  1.4884 -# define VdbeCoverageNeverTaken(v) sqlite3VdbeSetLineNumber(v,1);
  1.4885 +# define VdbeCoverageAlwaysTaken(v) \
  1.4886 +         sqlite3VdbeSetLineNumber(v,__LINE__|0x5000000);
  1.4887 +# define VdbeCoverageNeverTaken(v) \
  1.4888 +         sqlite3VdbeSetLineNumber(v,__LINE__|0x6000000);
  1.4889 +# define VdbeCoverageNeverNull(v) \
  1.4890 +         sqlite3VdbeSetLineNumber(v,__LINE__|0x4000000);
  1.4891 +# define VdbeCoverageNeverNullIf(v,x) \
  1.4892 +         if(x)sqlite3VdbeSetLineNumber(v,__LINE__|0x4000000);
  1.4893 +# define VdbeCoverageEqNe(v) \
  1.4894 +         sqlite3VdbeSetLineNumber(v,__LINE__|0x8000000);
  1.4895  # define VDBE_OFFSET_LINENO(x) (__LINE__+x)
  1.4896  #else
  1.4897  # define VdbeCoverage(v)
  1.4898  # define VdbeCoverageIf(v,x)
  1.4899  # define VdbeCoverageAlwaysTaken(v)
  1.4900  # define VdbeCoverageNeverTaken(v)
  1.4901 +# define VdbeCoverageNeverNull(v)
  1.4902 +# define VdbeCoverageNeverNullIf(v,x)
  1.4903 +# define VdbeCoverageEqNe(v)
  1.4904  # define VDBE_OFFSET_LINENO(x) 0
  1.4905  #endif
  1.4906  
  1.4907 @@ -13093,6 +15210,10 @@
  1.4908  # define sqlite3VdbeScanStatus(a,b,c,d,e)
  1.4909  #endif
  1.4910  
  1.4911 +#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
  1.4912 +SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, VdbeOp*);
  1.4913 +#endif
  1.4914 +
  1.4915  #endif /* SQLITE_VDBE_H */
  1.4916  
  1.4917  /************** End of vdbe.h ************************************************/
  1.4918 @@ -13227,7 +15348,7 @@
  1.4919  SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
  1.4920  
  1.4921  /* Functions used to configure a Pager object. */
  1.4922 -SQLITE_PRIVATE void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *);
  1.4923 +SQLITE_PRIVATE void sqlite3PagerSetBusyHandler(Pager*, int(*)(void *), void *);
  1.4924  SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int);
  1.4925  #ifdef SQLITE_HAS_CODEC
  1.4926  SQLITE_PRIVATE void sqlite3PagerAlignReserve(Pager*,Pager*);
  1.4927 @@ -13252,6 +15373,7 @@
  1.4928  SQLITE_PRIVATE void sqlite3PagerRef(DbPage*);
  1.4929  SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*);
  1.4930  SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage*);
  1.4931 +SQLITE_PRIVATE void sqlite3PagerUnrefPageOne(DbPage*);
  1.4932  
  1.4933  /* Operations on page references. */
  1.4934  SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
  1.4935 @@ -13279,16 +15401,17 @@
  1.4936  SQLITE_PRIVATE   int sqlite3PagerWalCallback(Pager *pPager);
  1.4937  SQLITE_PRIVATE   int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen);
  1.4938  SQLITE_PRIVATE   int sqlite3PagerCloseWal(Pager *pPager, sqlite3*);
  1.4939 -# ifdef SQLITE_DIRECT_OVERFLOW_READ
  1.4940 -SQLITE_PRIVATE   int sqlite3PagerUseWal(Pager *pPager, Pgno);
  1.4941 -# endif
  1.4942  # ifdef SQLITE_ENABLE_SNAPSHOT
  1.4943  SQLITE_PRIVATE   int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot);
  1.4944  SQLITE_PRIVATE   int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot);
  1.4945  SQLITE_PRIVATE   int sqlite3PagerSnapshotRecover(Pager *pPager);
  1.4946 +SQLITE_PRIVATE   int sqlite3PagerSnapshotCheck(Pager *pPager, sqlite3_snapshot *pSnapshot);
  1.4947 +SQLITE_PRIVATE   void sqlite3PagerSnapshotUnlock(Pager *pPager);
  1.4948  # endif
  1.4949 -#else
  1.4950 -# define sqlite3PagerUseWal(x,y) 0
  1.4951 +#endif
  1.4952 +
  1.4953 +#ifdef SQLITE_DIRECT_OVERFLOW_READ
  1.4954 +SQLITE_PRIVATE   int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno);
  1.4955  #endif
  1.4956  
  1.4957  #ifdef SQLITE_ENABLE_ZIPVFS
  1.4958 @@ -13312,6 +15435,11 @@
  1.4959  SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *);
  1.4960  SQLITE_PRIVATE void sqlite3PagerClearCache(Pager*);
  1.4961  SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *);
  1.4962 +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
  1.4963 +SQLITE_PRIVATE void sqlite3PagerResetLockTimeout(Pager *pPager);
  1.4964 +#else
  1.4965 +# define sqlite3PagerResetLockTimeout(X)
  1.4966 +#endif
  1.4967  
  1.4968  /* Functions used to truncate the database file. */
  1.4969  SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
  1.4970 @@ -13371,6 +15499,7 @@
  1.4971    sqlite3_pcache_page *pPage;    /* Pcache object page handle */
  1.4972    void *pData;                   /* Page data */
  1.4973    void *pExtra;                  /* Extra content */
  1.4974 +  PCache *pCache;                /* PRIVATE: Cache that owns this page */
  1.4975    PgHdr *pDirty;                 /* Transient list of dirty sorted by pgno */
  1.4976    Pager *pPager;                 /* The pager this page is part of */
  1.4977    Pgno pgno;                     /* Page number for this page */
  1.4978 @@ -13380,14 +15509,15 @@
  1.4979    u16 flags;                     /* PGHDR flags defined below */
  1.4980  
  1.4981    /**********************************************************************
  1.4982 -  ** Elements above are public.  All that follows is private to pcache.c
  1.4983 -  ** and should not be accessed by other modules.
  1.4984 +  ** Elements above, except pCache, are public.  All that follow are 
  1.4985 +  ** private to pcache.c and should not be accessed by other modules.
  1.4986 +  ** pCache is grouped with the public elements for efficiency.
  1.4987    */
  1.4988    i16 nRef;                      /* Number of users of this page */
  1.4989 -  PCache *pCache;                /* Cache that owns this page */
  1.4990 -
  1.4991    PgHdr *pDirtyNext;             /* Next element in list of dirty pages */
  1.4992    PgHdr *pDirtyPrev;             /* Previous element in list of dirty pages */
  1.4993 +                          /* NB: pDirtyNext and pDirtyPrev are undefined if the
  1.4994 +                          ** PgHdr object is not dirty */
  1.4995  };
  1.4996  
  1.4997  /* Bit values for PgHdr.flags */
  1.4998 @@ -13526,6 +15656,10 @@
  1.4999  /* Number of dirty pages as a percentage of the configured cache size */
  1.5000  SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache*);
  1.5001  
  1.5002 +#ifdef SQLITE_DIRECT_OVERFLOW_READ
  1.5003 +SQLITE_PRIVATE int sqlite3PCacheIsDirty(PCache *pCache);
  1.5004 +#endif
  1.5005 +
  1.5006  #endif /* _PCACHE_H_ */
  1.5007  
  1.5008  /************** End of pcache.h **********************************************/
  1.5009 @@ -13769,10 +15903,12 @@
  1.5010  #define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0
  1.5011  SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id);
  1.5012  SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id);
  1.5013 +#ifndef SQLITE_OMIT_WAL
  1.5014  SQLITE_PRIVATE int sqlite3OsShmMap(sqlite3_file *,int,int,int,void volatile **);
  1.5015  SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int, int, int);
  1.5016  SQLITE_PRIVATE void sqlite3OsShmBarrier(sqlite3_file *id);
  1.5017  SQLITE_PRIVATE int sqlite3OsShmUnmap(sqlite3_file *id, int);
  1.5018 +#endif /* SQLITE_OMIT_WAL */
  1.5019  SQLITE_PRIVATE int sqlite3OsFetch(sqlite3_file *id, i64, int, void **);
  1.5020  SQLITE_PRIVATE int sqlite3OsUnfetch(sqlite3_file *, i64, void *);
  1.5021  
  1.5022 @@ -13981,6 +16117,7 @@
  1.5023  #define DB_SchemaLoaded    0x0001  /* The schema has been loaded */
  1.5024  #define DB_UnresetViews    0x0002  /* Some views have defined column names */
  1.5025  #define DB_Empty           0x0004  /* The file is empty (length 0 bytes) */
  1.5026 +#define DB_ResetWanted     0x0008  /* Reset the schema when nSchemaLock==0 */
  1.5027  
  1.5028  /*
  1.5029  ** The number of different kinds of things that can be limited
  1.5030 @@ -14012,9 +16149,9 @@
  1.5031    u32 bDisable;           /* Only operate the lookaside when zero */
  1.5032    u16 sz;                 /* Size of each buffer in bytes */
  1.5033    u8 bMalloced;           /* True if pStart obtained from sqlite3_malloc() */
  1.5034 -  int nOut;               /* Number of buffers currently checked out */
  1.5035 -  int mxOut;              /* Highwater mark for nOut */
  1.5036 -  int anStat[3];          /* 0: hits.  1: size misses.  2: full misses */
  1.5037 +  u32 nSlot;              /* Number of lookaside slots allocated */
  1.5038 +  u32 anStat[3];          /* 0: hits.  1: size misses.  2: full misses */
  1.5039 +  LookasideSlot *pInit;   /* List of buffers not previously used */
  1.5040    LookasideSlot *pFree;   /* List of available buffers */
  1.5041    void *pStart;           /* First byte of available memory space */
  1.5042    void *pEnd;             /* First byte past end of available space */
  1.5043 @@ -14028,12 +16165,14 @@
  1.5044  ** functions use a regular table table from hash.h.)
  1.5045  **
  1.5046  ** Hash each FuncDef structure into one of the FuncDefHash.a[] slots.
  1.5047 -** Collisions are on the FuncDef.u.pHash chain.
  1.5048 +** Collisions are on the FuncDef.u.pHash chain.  Use the SQLITE_FUNC_HASH()
  1.5049 +** macro to compute a hash on the function name.
  1.5050  */
  1.5051  #define SQLITE_FUNC_HASH_SZ 23
  1.5052  struct FuncDefHash {
  1.5053    FuncDef *a[SQLITE_FUNC_HASH_SZ];       /* Hash table for functions */
  1.5054  };
  1.5055 +#define SQLITE_FUNC_HASH(C,L) (((C)+(L))%SQLITE_FUNC_HASH_SZ)
  1.5056  
  1.5057  #ifdef SQLITE_USER_AUTHENTICATION
  1.5058  /*
  1.5059 @@ -14093,9 +16232,11 @@
  1.5060    sqlite3_mutex *mutex;         /* Connection mutex */
  1.5061    Db *aDb;                      /* All backends */
  1.5062    int nDb;                      /* Number of backends currently in use */
  1.5063 -  int flags;                    /* Miscellaneous flags. See below */
  1.5064 +  u32 mDbFlags;                 /* flags recording internal state */
  1.5065 +  u64 flags;                    /* flags settable by pragmas. See below */
  1.5066    i64 lastRowid;                /* ROWID of most recent insert (see above) */
  1.5067    i64 szMmap;                   /* Default mmap_size setting */
  1.5068 +  u32 nSchemaLock;              /* Do not reset the schema when non-zero */
  1.5069    unsigned int openFlags;       /* Flags passed to sqlite3_vfs.xOpen() */
  1.5070    int errCode;                  /* Most recent error code (SQLITE_*) */
  1.5071    int errMask;                  /* & result codes with this before returning */
  1.5072 @@ -14112,7 +16253,7 @@
  1.5073    u8 vtabOnConflict;            /* Value to return for s3_vtab_on_conflict() */
  1.5074    u8 isTransactionSavepoint;    /* True if the outermost savepoint is a TS */
  1.5075    u8 mTrace;                    /* zero or more SQLITE_TRACE flags */
  1.5076 -  u8 skipBtreeMutex;            /* True if no shared-cache backends */
  1.5077 +  u8 noSharedCache;             /* True if no shared-cache backends */
  1.5078    u8 nSqlExec;                  /* Number of pending OP_SqlExec opcodes */
  1.5079    int nextPagesize;             /* Pagesize after VACUUM if >0 */
  1.5080    u32 magic;                    /* Magic number for detect library misuse */
  1.5081 @@ -14124,8 +16265,9 @@
  1.5082      int newTnum;                /* Rootpage of table being initialized */
  1.5083      u8 iDb;                     /* Which db file is being initialized */
  1.5084      u8 busy;                    /* TRUE if currently initializing */
  1.5085 -    u8 orphanTrigger;           /* Last statement is orphaned TEMP trigger */
  1.5086 -    u8 imposterTable;           /* Building an imposter table */
  1.5087 +    unsigned orphanTrigger : 1; /* Last statement is orphaned TEMP trigger */
  1.5088 +    unsigned imposterTable : 1; /* Building an imposter table */
  1.5089 +    unsigned reopenMemdb : 1;   /* ATTACH is really a reopen using MemDB */
  1.5090    } init;
  1.5091    int nVdbeActive;              /* Number of VDBEs currently running */
  1.5092    int nVdbeRead;                /* Number of active VDBEs that read or write */
  1.5093 @@ -14178,7 +16320,7 @@
  1.5094    Hash aModule;                 /* populated by sqlite3_create_module() */
  1.5095    VtabCtx *pVtabCtx;            /* Context for active vtab connect/create */
  1.5096    VTable **aVTrans;             /* Virtual tables with open transactions */
  1.5097 -  VTable *pDisconnect;    /* Disconnect these in next sqlite3_prepare() */
  1.5098 +  VTable *pDisconnect;          /* Disconnect these in next sqlite3_prepare() */
  1.5099  #endif
  1.5100    Hash aFunc;                   /* Hash table of connection functions */
  1.5101    Hash aCollSeq;                /* All collating sequences */
  1.5102 @@ -14227,8 +16369,8 @@
  1.5103  **      SQLITE_CkptFullFSync == PAGER_CKPT_FULLFSYNC
  1.5104  **      SQLITE_CacheSpill    == PAGER_CACHE_SPILL
  1.5105  */
  1.5106 -#define SQLITE_VdbeTrace      0x00000001  /* True to trace VDBE execution */
  1.5107 -#define SQLITE_InternChanges  0x00000002  /* Uncommitted Hash table changes */
  1.5108 +#define SQLITE_WriteSchema    0x00000001  /* OK to update SQLITE_MASTER */
  1.5109 +#define SQLITE_LegacyFileFmt  0x00000002  /* Create new databases in format 1 */
  1.5110  #define SQLITE_FullColNames   0x00000004  /* Show full column names on SELECT */
  1.5111  #define SQLITE_FullFSync      0x00000008  /* Use full fsync on the backend */
  1.5112  #define SQLITE_CkptFullFSync  0x00000010  /* Use full fsync for checkpoint */
  1.5113 @@ -14239,30 +16381,44 @@
  1.5114                                            /*   the count using a callback. */
  1.5115  #define SQLITE_NullCallback   0x00000100  /* Invoke the callback once if the */
  1.5116                                            /*   result set is empty */
  1.5117 -#define SQLITE_SqlTrace       0x00000200  /* Debug print SQL as it executes */
  1.5118 -#define SQLITE_VdbeListing    0x00000400  /* Debug listings of VDBE programs */
  1.5119 -#define SQLITE_WriteSchema    0x00000800  /* OK to update SQLITE_MASTER */
  1.5120 -#define SQLITE_VdbeAddopTrace 0x00001000  /* Trace sqlite3VdbeAddOp() calls */
  1.5121 -#define SQLITE_IgnoreChecks   0x00002000  /* Do not enforce check constraints */
  1.5122 -#define SQLITE_ReadUncommitted 0x0004000  /* For shared-cache mode */
  1.5123 -#define SQLITE_LegacyFileFmt  0x00008000  /* Create new databases in format 1 */
  1.5124 -#define SQLITE_RecoveryMode   0x00010000  /* Ignore schema errors */
  1.5125 -#define SQLITE_ReverseOrder   0x00020000  /* Reverse unordered SELECTs */
  1.5126 -#define SQLITE_RecTriggers    0x00040000  /* Enable recursive triggers */
  1.5127 -#define SQLITE_ForeignKeys    0x00080000  /* Enforce foreign key constraints  */
  1.5128 -#define SQLITE_AutoIndex      0x00100000  /* Enable automatic indexes */
  1.5129 -#define SQLITE_PreferBuiltin  0x00200000  /* Preference to built-in funcs */
  1.5130 -#define SQLITE_LoadExtension  0x00400000  /* Enable load_extension */
  1.5131 -#define SQLITE_LoadExtFunc    0x00800000  /* Enable load_extension() SQL func */
  1.5132 -#define SQLITE_EnableTrigger  0x01000000  /* True to enable triggers */
  1.5133 -#define SQLITE_DeferFKs       0x02000000  /* Defer all FK constraints */
  1.5134 -#define SQLITE_QueryOnly      0x04000000  /* Disable database changes */
  1.5135 -#define SQLITE_VdbeEQP        0x08000000  /* Debug EXPLAIN QUERY PLAN */
  1.5136 -#define SQLITE_Vacuum         0x10000000  /* Currently in a VACUUM */
  1.5137 -#define SQLITE_CellSizeCk     0x20000000  /* Check btree cell sizes on load */
  1.5138 -#define SQLITE_Fts3Tokenizer  0x40000000  /* Enable fts3_tokenizer(2) */
  1.5139 -#define SQLITE_NoCkptOnClose  0x80000000  /* No checkpoint on close()/DETACH */
  1.5140 -
  1.5141 +#define SQLITE_IgnoreChecks   0x00000200  /* Do not enforce check constraints */
  1.5142 +#define SQLITE_ReadUncommit   0x00000400  /* READ UNCOMMITTED in shared-cache */
  1.5143 +#define SQLITE_NoCkptOnClose  0x00000800  /* No checkpoint on close()/DETACH */
  1.5144 +#define SQLITE_ReverseOrder   0x00001000  /* Reverse unordered SELECTs */
  1.5145 +#define SQLITE_RecTriggers    0x00002000  /* Enable recursive triggers */
  1.5146 +#define SQLITE_ForeignKeys    0x00004000  /* Enforce foreign key constraints  */
  1.5147 +#define SQLITE_AutoIndex      0x00008000  /* Enable automatic indexes */
  1.5148 +#define SQLITE_LoadExtension  0x00010000  /* Enable load_extension */
  1.5149 +#define SQLITE_LoadExtFunc    0x00020000  /* Enable load_extension() SQL func */
  1.5150 +#define SQLITE_EnableTrigger  0x00040000  /* True to enable triggers */
  1.5151 +#define SQLITE_DeferFKs       0x00080000  /* Defer all FK constraints */
  1.5152 +#define SQLITE_QueryOnly      0x00100000  /* Disable database changes */
  1.5153 +#define SQLITE_CellSizeCk     0x00200000  /* Check btree cell sizes on load */
  1.5154 +#define SQLITE_Fts3Tokenizer  0x00400000  /* Enable fts3_tokenizer(2) */
  1.5155 +#define SQLITE_EnableQPSG     0x00800000  /* Query Planner Stability Guarantee*/
  1.5156 +#define SQLITE_TriggerEQP     0x01000000  /* Show trigger EXPLAIN QUERY PLAN */
  1.5157 +#define SQLITE_ResetDatabase  0x02000000  /* Reset the database */
  1.5158 +#define SQLITE_LegacyAlter    0x04000000  /* Legacy ALTER TABLE behaviour */
  1.5159 +#define SQLITE_NoSchemaError  0x08000000  /* Do not report schema parse errors*/
  1.5160 +#define SQLITE_Defensive      0x10000000  /* Input SQL is likely hostile */
  1.5161 +
  1.5162 +/* Flags used only if debugging */
  1.5163 +#define HI(X)  ((u64)(X)<<32)
  1.5164 +#ifdef SQLITE_DEBUG
  1.5165 +#define SQLITE_SqlTrace       HI(0x0001)  /* Debug print SQL as it executes */
  1.5166 +#define SQLITE_VdbeListing    HI(0x0002)  /* Debug listings of VDBE progs */
  1.5167 +#define SQLITE_VdbeTrace      HI(0x0004)  /* True to trace VDBE execution */
  1.5168 +#define SQLITE_VdbeAddopTrace HI(0x0008)  /* Trace sqlite3VdbeAddOp() calls */
  1.5169 +#define SQLITE_VdbeEQP        HI(0x0010)  /* Debug EXPLAIN QUERY PLAN */
  1.5170 +#endif
  1.5171 +
  1.5172 +/*
  1.5173 +** Allowed values for sqlite3.mDbFlags
  1.5174 +*/
  1.5175 +#define DBFLAG_SchemaChange   0x0001  /* Uncommitted Hash table changes */
  1.5176 +#define DBFLAG_PreferBuiltin  0x0002  /* Preference to built-in funcs */
  1.5177 +#define DBFLAG_Vacuum         0x0004  /* Currently in a VACUUM */
  1.5178 +#define DBFLAG_SchemaKnownOk  0x0008  /* Schema is known to be valid */
  1.5179  
  1.5180  /*
  1.5181  ** Bits of the sqlite3.dbOptFlags field that are used by the
  1.5182 @@ -14270,18 +16426,22 @@
  1.5183  ** selectively disable various optimizations.
  1.5184  */
  1.5185  #define SQLITE_QueryFlattener 0x0001   /* Query flattening */
  1.5186 -#define SQLITE_ColumnCache    0x0002   /* Column cache */
  1.5187 +                          /*  0x0002   available for reuse */
  1.5188  #define SQLITE_GroupByOrder   0x0004   /* GROUPBY cover of ORDERBY */
  1.5189  #define SQLITE_FactorOutConst 0x0008   /* Constant factoring */
  1.5190 -/*                not used    0x0010   // Was: SQLITE_IdxRealAsInt */
  1.5191 -#define SQLITE_DistinctOpt    0x0020   /* DISTINCT using indexes */
  1.5192 -#define SQLITE_CoverIdxScan   0x0040   /* Covering index scans */
  1.5193 -#define SQLITE_OrderByIdxJoin 0x0080   /* ORDER BY of joins via index */
  1.5194 -#define SQLITE_SubqCoroutine  0x0100   /* Evaluate subqueries as coroutines */
  1.5195 -#define SQLITE_Transitive     0x0200   /* Transitive constraints */
  1.5196 -#define SQLITE_OmitNoopJoin   0x0400   /* Omit unused tables in joins */
  1.5197 +#define SQLITE_DistinctOpt    0x0010   /* DISTINCT using indexes */
  1.5198 +#define SQLITE_CoverIdxScan   0x0020   /* Covering index scans */
  1.5199 +#define SQLITE_OrderByIdxJoin 0x0040   /* ORDER BY of joins via index */
  1.5200 +#define SQLITE_Transitive     0x0080   /* Transitive constraints */
  1.5201 +#define SQLITE_OmitNoopJoin   0x0100   /* Omit unused tables in joins */
  1.5202 +#define SQLITE_CountOfView    0x0200   /* The count-of-view optimization */
  1.5203 +#define SQLITE_CursorHints    0x0400   /* Add OP_CursorHint opcodes */
  1.5204  #define SQLITE_Stat34         0x0800   /* Use STAT3 or STAT4 data */
  1.5205 -#define SQLITE_CursorHints    0x2000   /* Add OP_CursorHint opcodes */
  1.5206 +   /* TH3 expects the Stat34  ^^^^^^ value to be 0x0800.  Don't change it */
  1.5207 +#define SQLITE_PushDown       0x1000   /* The push-down optimization */
  1.5208 +#define SQLITE_SimplifyJoin   0x2000   /* Convert LEFT JOIN to JOIN */
  1.5209 +#define SQLITE_SkipScan       0x4000   /* Skip-scans */
  1.5210 +#define SQLITE_PropagateConst 0x8000   /* The constant propagation opt */
  1.5211  #define SQLITE_AllOpts        0xffff   /* All optimizations */
  1.5212  
  1.5213  /*
  1.5214 @@ -14320,11 +16480,13 @@
  1.5215  */
  1.5216  struct FuncDef {
  1.5217    i8 nArg;             /* Number of arguments.  -1 means unlimited */
  1.5218 -  u16 funcFlags;       /* Some combination of SQLITE_FUNC_* */
  1.5219 +  u32 funcFlags;       /* Some combination of SQLITE_FUNC_* */
  1.5220    void *pUserData;     /* User data parameter */
  1.5221    FuncDef *pNext;      /* Next function with same name */
  1.5222    void (*xSFunc)(sqlite3_context*,int,sqlite3_value**); /* func or agg-step */
  1.5223    void (*xFinalize)(sqlite3_context*);                  /* Agg finalizer */
  1.5224 +  void (*xValue)(sqlite3_context*);                     /* Current agg value */
  1.5225 +  void (*xInverse)(sqlite3_context*,int,sqlite3_value**); /* inverse agg-step */
  1.5226    const char *zName;   /* SQL name of the function. */
  1.5227    union {
  1.5228      FuncDef *pHash;      /* Next with a different name but the same hash */
  1.5229 @@ -14380,6 +16542,10 @@
  1.5230  #define SQLITE_FUNC_SLOCHNG  0x2000 /* "Slow Change". Value constant during a
  1.5231                                      ** single query - might change over time */
  1.5232  #define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
  1.5233 +#define SQLITE_FUNC_OFFSET   0x8000 /* Built-in sqlite_offset() function */
  1.5234 +#define SQLITE_FUNC_WINDOW   0x00010000 /* Built-in window-only function */
  1.5235 +#define SQLITE_FUNC_WINDOW_SIZE 0x20000 /* Requires partition size as arg. */
  1.5236 +#define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
  1.5237  
  1.5238  /*
  1.5239  ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
  1.5240 @@ -14399,7 +16565,14 @@
  1.5241  **     Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
  1.5242  **     adds the SQLITE_FUNC_SLOCHNG flag.  Used for date & time functions
  1.5243  **     and functions like sqlite_version() that can change, but not during
  1.5244 -**     a single query.
  1.5245 +**     a single query.  The iArg is ignored.  The user-data is always set
  1.5246 +**     to a NULL pointer.  The bNC parameter is not used.
  1.5247 +**
  1.5248 +**   PURE_DATE(zName, nArg, iArg, bNC, xFunc)
  1.5249 +**     Used for "pure" date/time functions, this macro is like DFUNCTION
  1.5250 +**     except that it does set the SQLITE_FUNC_CONSTANT flags.  iArg is
  1.5251 +**     ignored and the user-data for these functions is set to an 
  1.5252 +**     arbitrary non-NULL pointer.  The bNC parameter is not used.
  1.5253  **
  1.5254  **   AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
  1.5255  **     Used to create an aggregate function definition implemented by
  1.5256 @@ -14407,6 +16580,12 @@
  1.5257  **     are interpreted in the same way as the first 4 parameters to
  1.5258  **     FUNCTION().
  1.5259  **
  1.5260 +**   WFUNCTION(zName, nArg, iArg, xStep, xFinal, xValue, xInverse)
  1.5261 +**     Used to create an aggregate function definition implemented by
  1.5262 +**     the C functions xStep and xFinal. The first four parameters
  1.5263 +**     are interpreted in the same way as the first 4 parameters to
  1.5264 +**     FUNCTION().
  1.5265 +**
  1.5266  **   LIKEFUNC(zName, nArg, pArg, flags)
  1.5267  **     Used to create a scalar function definition of a function zName
  1.5268  **     that accepts nArg arguments and is implemented by a call to C
  1.5269 @@ -14417,28 +16596,38 @@
  1.5270  */
  1.5271  #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
  1.5272    {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
  1.5273 -   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
  1.5274 +   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
  1.5275  #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
  1.5276    {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
  1.5277 -   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
  1.5278 +   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
  1.5279  #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
  1.5280 -  {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
  1.5281 -   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
  1.5282 +  {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \
  1.5283 +   0, 0, xFunc, 0, 0, 0, #zName, {0} }
  1.5284 +#define PURE_DATE(zName, nArg, iArg, bNC, xFunc) \
  1.5285 +  {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
  1.5286 +   (void*)&sqlite3Config, 0, xFunc, 0, 0, 0, #zName, {0} }
  1.5287  #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
  1.5288    {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
  1.5289 -   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} }
  1.5290 +   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
  1.5291  #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
  1.5292    {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
  1.5293 -   pArg, 0, xFunc, 0, #zName, }
  1.5294 +   pArg, 0, xFunc, 0, 0, 0, #zName, }
  1.5295  #define LIKEFUNC(zName, nArg, arg, flags) \
  1.5296    {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
  1.5297 -   (void *)arg, 0, likeFunc, 0, #zName, {0} }
  1.5298 -#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
  1.5299 +   (void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} }
  1.5300 +#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue) \
  1.5301    {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
  1.5302 -   SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,#zName, {0}}
  1.5303 +   SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,0,#zName, {0}}
  1.5304  #define AGGREGATE2(zName, nArg, arg, nc, xStep, xFinal, extraFlags) \
  1.5305    {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
  1.5306 -   SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,#zName, {0}}
  1.5307 +   SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xFinal,0,#zName, {0}}
  1.5308 +#define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f) \
  1.5309 +  {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \
  1.5310 +   SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,xInverse,#zName, {0}}
  1.5311 +#define INTERNAL_FUNCTION(zName, nArg, xFunc) \
  1.5312 +  {nArg, SQLITE_FUNC_INTERNAL|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
  1.5313 +   0, 0, xFunc, 0, 0, 0, #zName, {0} }
  1.5314 +
  1.5315  
  1.5316  /*
  1.5317  ** All current savepoints are stored in a linked list starting at
  1.5318 @@ -14494,6 +16683,8 @@
  1.5319  #define COLFLAG_PRIMKEY  0x0001    /* Column is part of the primary key */
  1.5320  #define COLFLAG_HIDDEN   0x0002    /* A hidden column in a virtual table */
  1.5321  #define COLFLAG_HASTYPE  0x0004    /* Type name follows column name */
  1.5322 +#define COLFLAG_UNIQUE   0x0008    /* Column def contains "UNIQUE" or "PK" */
  1.5323 +#define COLFLAG_SORTERREF 0x0010   /* Use sorter-refs with this column */
  1.5324  
  1.5325  /*
  1.5326  ** A "Collating Sequence" is defined by an instance of the following
  1.5327 @@ -14621,6 +16812,9 @@
  1.5328  struct Table {
  1.5329    char *zName;         /* Name of the table or view */
  1.5330    Column *aCol;        /* Information about each column */
  1.5331 +#ifdef SQLITE_ENABLE_NORMALIZE
  1.5332 +  Hash *pColHash;      /* All columns indexed by name */
  1.5333 +#endif
  1.5334    Index *pIndex;       /* List of SQL indexes on this table. */
  1.5335    Select *pSelect;     /* NULL for tables.  Points to definition if a view. */
  1.5336    FKey *pFKey;         /* Linked list of all foreign keys in this table */
  1.5337 @@ -14671,6 +16865,7 @@
  1.5338  #define TF_StatsUsed       0x0100    /* Query planner decisions affected by
  1.5339                                       ** Index.aiRowLogEst[] values */
  1.5340  #define TF_HasNotNull      0x0200    /* Contains NOT NULL constraints */
  1.5341 +#define TF_Shadow          0x0400    /* True for a shadow table */
  1.5342  
  1.5343  /*
  1.5344  ** Test to see whether or not a table is a virtual table.  This is
  1.5345 @@ -14781,13 +16976,12 @@
  1.5346  #define OE_Fail     3   /* Stop the operation but leave all prior changes */
  1.5347  #define OE_Ignore   4   /* Ignore the error. Do not do the INSERT or UPDATE */
  1.5348  #define OE_Replace  5   /* Delete existing record, then do INSERT or UPDATE */
  1.5349 -
  1.5350 -#define OE_Restrict 6   /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */
  1.5351 -#define OE_SetNull  7   /* Set the foreign key value to NULL */
  1.5352 -#define OE_SetDflt  8   /* Set the foreign key value to its default */
  1.5353 -#define OE_Cascade  9   /* Cascade the changes */
  1.5354 -
  1.5355 -#define OE_Default  10  /* Do whatever the default action is */
  1.5356 +#define OE_Update   6   /* Process as a DO UPDATE in an upsert */
  1.5357 +#define OE_Restrict 7   /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */
  1.5358 +#define OE_SetNull  8   /* Set the foreign key value to NULL */
  1.5359 +#define OE_SetDflt  9   /* Set the foreign key value to its default */
  1.5360 +#define OE_Cascade  10  /* Cascade the changes */
  1.5361 +#define OE_Default  11  /* Do whatever the default action is */
  1.5362  
  1.5363  
  1.5364  /*
  1.5365 @@ -14802,8 +16996,8 @@
  1.5366  struct KeyInfo {
  1.5367    u32 nRef;           /* Number of references to this KeyInfo object */
  1.5368    u8 enc;             /* Text encoding - one of the SQLITE_UTF* values */
  1.5369 -  u16 nField;         /* Number of key columns in the index */
  1.5370 -  u16 nXField;        /* Number of columns beyond the key columns */
  1.5371 +  u16 nKeyField;      /* Number of key columns in the index */
  1.5372 +  u16 nAllField;      /* Total columns, including key plus others */
  1.5373    sqlite3 *db;        /* The database connection */
  1.5374    u8 *aSortOrder;     /* Sort order for each column. */
  1.5375    CollSeq *aColl[1];  /* Collating sequence for each term of the key */
  1.5376 @@ -14850,8 +17044,8 @@
  1.5377    u16 nField;         /* Number of entries in apMem[] */
  1.5378    i8 default_rc;      /* Comparison result if keys are equal */
  1.5379    u8 errCode;         /* Error detected by xRecordCompare (CORRUPT or NOMEM) */
  1.5380 -  i8 r1;              /* Value to return if (lhs > rhs) */
  1.5381 -  i8 r2;              /* Value to return if (rhs < lhs) */
  1.5382 +  i8 r1;              /* Value to return if (lhs < rhs) */
  1.5383 +  i8 r2;              /* Value to return if (lhs > rhs) */
  1.5384    u8 eqSeen;          /* True if an equality comparison has been seen */
  1.5385  };
  1.5386  
  1.5387 @@ -14914,6 +17108,7 @@
  1.5388    unsigned isCovering:1;   /* True if this is a covering index */
  1.5389    unsigned noSkipScan:1;   /* Do not try to use skip-scan if true */
  1.5390    unsigned hasStat1:1;     /* aiRowLogEst values come from sqlite_stat1 */
  1.5391 +  unsigned bNoQuery:1;     /* Do not use this index to optimize queries */
  1.5392  #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
  1.5393    int nSample;             /* Number of elements in aSample[] */
  1.5394    int nSampleCol;          /* Size of IndexSample.anEq[] and so on */
  1.5395 @@ -14922,6 +17117,7 @@
  1.5396    tRowcnt *aiRowEst;       /* Non-logarithmic stat1 data for this index */
  1.5397    tRowcnt nRowEst0;        /* Non-logarithmic number of rows in the index */
  1.5398  #endif
  1.5399 +  Bitmask colNotIdxed;     /* 0 for unindexed columns in pTab */
  1.5400  };
  1.5401  
  1.5402  /*
  1.5403 @@ -14957,12 +17153,20 @@
  1.5404  };
  1.5405  
  1.5406  /*
  1.5407 +** Possible values to use within the flags argument to sqlite3GetToken().
  1.5408 +*/
  1.5409 +#define SQLITE_TOKEN_QUOTED    0x1 /* Token is a quoted identifier. */
  1.5410 +#define SQLITE_TOKEN_KEYWORD   0x2 /* Token is a keyword. */
  1.5411 +
  1.5412 +/*
  1.5413  ** Each token coming out of the lexer is an instance of
  1.5414  ** this structure.  Tokens are also used as part of an expression.
  1.5415  **
  1.5416 -** Note if Token.z==0 then Token.dyn and Token.n are undefined and
  1.5417 -** may contain random values.  Do not make any assumptions about Token.dyn
  1.5418 -** and Token.n when Token.z==0.
  1.5419 +** The memory that "z" points to is owned by other objects.  Take care
  1.5420 +** that the owner of the "z" string does not deallocate the string before
  1.5421 +** the Token goes out of scope!  Very often, the "z" points to some place
  1.5422 +** in the middle of the Parse.zSql text.  But it might also point to a
  1.5423 +** static string.
  1.5424  */
  1.5425  struct Token {
  1.5426    const char *z;     /* Text of the token.  Not NULL-terminated! */
  1.5427 @@ -15135,7 +17339,11 @@
  1.5428                           ** TK_COLUMN: the value of p5 for OP_Column
  1.5429                           ** TK_AGG_FUNCTION: nesting depth */
  1.5430    AggInfo *pAggInfo;     /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
  1.5431 -  Table *pTab;           /* Table for TK_COLUMN expressions. */
  1.5432 +  union {
  1.5433 +    Table *pTab;           /* TK_COLUMN: Table containing column. Can be NULL
  1.5434 +                           ** for a column of an index on an expression */
  1.5435 +    Window *pWin;          /* TK_FUNCTION: Window definition for the func */
  1.5436 +  } y;
  1.5437  };
  1.5438  
  1.5439  /*
  1.5440 @@ -15143,8 +17351,8 @@
  1.5441  */
  1.5442  #define EP_FromJoin  0x000001 /* Originates in ON/USING clause of outer join */
  1.5443  #define EP_Agg       0x000002 /* Contains one or more aggregate functions */
  1.5444 -#define EP_Resolved  0x000004 /* IDs have been resolved to COLUMNs */
  1.5445 -#define EP_Error     0x000008 /* Expression contains one or more errors */
  1.5446 +#define EP_HasFunc   0x000004 /* Contains one or more functions of any kind */
  1.5447 +#define EP_FixedCol  0x000008 /* TK_Column with a known fixed value */
  1.5448  #define EP_Distinct  0x000010 /* Aggregate function with DISTINCT keyword */
  1.5449  #define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
  1.5450  #define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
  1.5451 @@ -15165,11 +17373,13 @@
  1.5452  #define EP_Subquery  0x200000 /* Tree contains a TK_SELECT operator */
  1.5453  #define EP_Alias     0x400000 /* Is an alias for a result set column */
  1.5454  #define EP_Leaf      0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
  1.5455 -
  1.5456 -/*
  1.5457 -** Combinations of two or more EP_* flags
  1.5458 -*/
  1.5459 -#define EP_Propagate (EP_Collate|EP_Subquery) /* Propagate these bits up tree */
  1.5460 +#define EP_WinFunc  0x1000000 /* TK_FUNCTION with Expr.y.pWin set */
  1.5461 +
  1.5462 +/*
  1.5463 +** The EP_Propagate mask is a set of properties that automatically propagate
  1.5464 +** upwards into parent nodes.
  1.5465 +*/
  1.5466 +#define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc)
  1.5467  
  1.5468  /*
  1.5469  ** These macros can be used to test, set, or clear bits in the
  1.5470 @@ -15223,7 +17433,6 @@
  1.5471  */
  1.5472  struct ExprList {
  1.5473    int nExpr;             /* Number of expressions on the list */
  1.5474 -  int nAlloc;            /* Number of a[] slots allocated */
  1.5475    struct ExprList_item { /* For each expression in the list */
  1.5476      Expr *pExpr;            /* The parse tree for this expression */
  1.5477      char *zName;            /* Token associated with this expression */
  1.5478 @@ -15232,6 +17441,7 @@
  1.5479      unsigned done :1;       /* A flag to indicate when processing is finished */
  1.5480      unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
  1.5481      unsigned reusable :1;   /* Constant expression is reusable */
  1.5482 +    unsigned bSorterRef :1; /* Defer evaluation until after sorting */
  1.5483      union {
  1.5484        struct {
  1.5485          u16 iOrderByCol;      /* For ORDER BY, column number in result set */
  1.5486 @@ -15243,17 +17453,6 @@
  1.5487  };
  1.5488  
  1.5489  /*
  1.5490 -** An instance of this structure is used by the parser to record both
  1.5491 -** the parse tree for an expression and the span of input text for an
  1.5492 -** expression.
  1.5493 -*/
  1.5494 -struct ExprSpan {
  1.5495 -  Expr *pExpr;          /* The expression parse tree */
  1.5496 -  const char *zStart;   /* First character of input text */
  1.5497 -  const char *zEnd;     /* One character past the end of input text */
  1.5498 -};
  1.5499 -
  1.5500 -/*
  1.5501  ** An instance of this structure can hold a simple list of identifiers,
  1.5502  ** such as the list "a,b,c" in the following statements:
  1.5503  **
  1.5504 @@ -15277,31 +17476,6 @@
  1.5505  };
  1.5506  
  1.5507  /*
  1.5508 -** The bitmask datatype defined below is used for various optimizations.
  1.5509 -**
  1.5510 -** Changing this from a 64-bit to a 32-bit type limits the number of
  1.5511 -** tables in a join to 32 instead of 64.  But it also reduces the size
  1.5512 -** of the library by 738 bytes on ix86.
  1.5513 -*/
  1.5514 -#ifdef SQLITE_BITMASK_TYPE
  1.5515 -  typedef SQLITE_BITMASK_TYPE Bitmask;
  1.5516 -#else
  1.5517 -  typedef u64 Bitmask;
  1.5518 -#endif
  1.5519 -
  1.5520 -/*
  1.5521 -** The number of bits in a Bitmask.  "BMS" means "BitMask Size".
  1.5522 -*/
  1.5523 -#define BMS  ((int)(sizeof(Bitmask)*8))
  1.5524 -
  1.5525 -/*
  1.5526 -** A bit in a Bitmask
  1.5527 -*/
  1.5528 -#define MASKBIT(n)   (((Bitmask)1)<<(n))
  1.5529 -#define MASKBIT32(n) (((unsigned int)1)<<(n))
  1.5530 -#define ALLBITS      ((Bitmask)-1)
  1.5531 -
  1.5532 -/*
  1.5533  ** The following structure describes the FROM clause of a SELECT statement.
  1.5534  ** Each table or subquery in the FROM clause is a separate element of
  1.5535  ** the SrcList.a[] array.
  1.5536 @@ -15342,9 +17516,6 @@
  1.5537        unsigned viaCoroutine :1;  /* Implemented as a co-routine */
  1.5538        unsigned isRecursive :1;   /* True for recursive reference in WITH */
  1.5539      } fg;
  1.5540 -#ifndef SQLITE_OMIT_EXPLAIN
  1.5541 -    u8 iSelectId;     /* If pSelect!=0, the id of the sub-select in EQP */
  1.5542 -#endif
  1.5543      int iCursor;      /* The VDBE cursor number used to access this table */
  1.5544      Expr *pOn;        /* The ON clause of a join */
  1.5545      IdList *pUsing;   /* The USING clause of a join */
  1.5546 @@ -15426,12 +17597,16 @@
  1.5547  struct NameContext {
  1.5548    Parse *pParse;       /* The parser */
  1.5549    SrcList *pSrcList;   /* One or more tables used to resolve names */
  1.5550 -  ExprList *pEList;    /* Optional list of result-set columns */
  1.5551 -  AggInfo *pAggInfo;   /* Information about aggregates at this level */
  1.5552 +  union {
  1.5553 +    ExprList *pEList;    /* Optional list of result-set columns */
  1.5554 +    AggInfo *pAggInfo;   /* Information about aggregates at this level */
  1.5555 +    Upsert *pUpsert;     /* ON CONFLICT clause information from an upsert */
  1.5556 +  } uNC;
  1.5557    NameContext *pNext;  /* Next outer name context.  NULL for outermost */
  1.5558    int nRef;            /* Number of names resolved by this context */
  1.5559    int nErr;            /* Number of errors encountered while resolving names */
  1.5560    u16 ncFlags;         /* Zero or more NC_* flags defined below */
  1.5561 +  Select *pWinSelect;  /* SELECT statement for any window functions */
  1.5562  };
  1.5563  
  1.5564  /*
  1.5565 @@ -15449,17 +17624,49 @@
  1.5566  #define NC_HasAgg    0x0010  /* One or more aggregate functions seen */
  1.5567  #define NC_IdxExpr   0x0020  /* True if resolving columns of CREATE INDEX */
  1.5568  #define NC_VarSelect 0x0040  /* A correlated subquery has been seen */
  1.5569 +#define NC_UEList    0x0080  /* True if uNC.pEList is used */
  1.5570 +#define NC_UAggInfo  0x0100  /* True if uNC.pAggInfo is used */
  1.5571 +#define NC_UUpsert   0x0200  /* True if uNC.pUpsert is used */
  1.5572  #define NC_MinMaxAgg 0x1000  /* min/max aggregates seen.  See note above */
  1.5573 +#define NC_Complex   0x2000  /* True if a function or subquery seen */
  1.5574 +#define NC_AllowWin  0x4000  /* Window functions are allowed here */
  1.5575 +
  1.5576 +/*
  1.5577 +** An instance of the following object describes a single ON CONFLICT
  1.5578 +** clause in an upsert.
  1.5579 +**
  1.5580 +** The pUpsertTarget field is only set if the ON CONFLICT clause includes
  1.5581 +** conflict-target clause.  (In "ON CONFLICT(a,b)" the "(a,b)" is the
  1.5582 +** conflict-target clause.)  The pUpsertTargetWhere is the optional
  1.5583 +** WHERE clause used to identify partial unique indexes.
  1.5584 +**
  1.5585 +** pUpsertSet is the list of column=expr terms of the UPDATE statement. 
  1.5586 +** The pUpsertSet field is NULL for a ON CONFLICT DO NOTHING.  The
  1.5587 +** pUpsertWhere is the WHERE clause for the UPDATE and is NULL if the
  1.5588 +** WHERE clause is omitted.
  1.5589 +*/
  1.5590 +struct Upsert {
  1.5591 +  ExprList *pUpsertTarget;  /* Optional description of conflicting index */
  1.5592 +  Expr *pUpsertTargetWhere; /* WHERE clause for partial index targets */
  1.5593 +  ExprList *pUpsertSet;     /* The SET clause from an ON CONFLICT UPDATE */
  1.5594 +  Expr *pUpsertWhere;       /* WHERE clause for the ON CONFLICT UPDATE */
  1.5595 +  /* The fields above comprise the parse tree for the upsert clause.
  1.5596 +  ** The fields below are used to transfer information from the INSERT
  1.5597 +  ** processing down into the UPDATE processing while generating code.
  1.5598 +  ** Upsert owns the memory allocated above, but not the memory below. */
  1.5599 +  Index *pUpsertIdx;        /* Constraint that pUpsertTarget identifies */
  1.5600 +  SrcList *pUpsertSrc;      /* Table to be updated */
  1.5601 +  int regData;              /* First register holding array of VALUES */
  1.5602 +  int iDataCur;             /* Index of the data cursor */
  1.5603 +  int iIdxCur;              /* Index of the first index cursor */
  1.5604 +};
  1.5605  
  1.5606  /*
  1.5607  ** An instance of the following structure contains all information
  1.5608  ** needed to generate code for a single SELECT statement.
  1.5609  **
  1.5610 -** nLimit is set to -1 if there is no LIMIT clause.  nOffset is set to 0.
  1.5611 -** If there is a LIMIT clause, the parser sets nLimit to the value of the
  1.5612 -** limit and nOffset to the value of the offset (or 0 if there is not
  1.5613 -** offset).  But later on, nLimit and nOffset become the memory locations
  1.5614 -** in the VDBE that record the limit and offset counters.
  1.5615 +** See the header comment on the computeLimitRegisters() routine for a
  1.5616 +** detailed description of the meaning of the iLimit and iOffset fields.
  1.5617  **
  1.5618  ** addrOpenEphm[] entries contain the address of OP_OpenEphemeral opcodes.
  1.5619  ** These addresses must be stored so that we can go back and fill in
  1.5620 @@ -15477,9 +17684,7 @@
  1.5621    LogEst nSelectRow;     /* Estimated number of result rows */
  1.5622    u32 selFlags;          /* Various SF_* values */
  1.5623    int iLimit, iOffset;   /* Memory registers holding LIMIT & OFFSET counters */
  1.5624 -#if SELECTTRACE_ENABLED
  1.5625 -  char zSelName[12];     /* Symbolic name of this SELECT use for debugging */
  1.5626 -#endif
  1.5627 +  u32 selId;             /* Unique identifier number for this SELECT */
  1.5628    int addrOpenEphm[2];   /* OP_OpenEphem opcodes related to this select */
  1.5629    SrcList *pSrc;         /* The FROM clause */
  1.5630    Expr *pWhere;          /* The WHERE clause */
  1.5631 @@ -15489,8 +17694,11 @@
  1.5632    Select *pPrior;        /* Prior select in a compound select statement */
  1.5633    Select *pNext;         /* Next select to the left in a compound */
  1.5634    Expr *pLimit;          /* LIMIT expression. NULL means not used. */
  1.5635 -  Expr *pOffset;         /* OFFSET expression. NULL means not used. */
  1.5636    With *pWith;           /* WITH clause attached to this select. Or NULL. */
  1.5637 +#ifndef SQLITE_OMIT_WINDOWFUNC
  1.5638 +  Window *pWin;          /* List of window functions */
  1.5639 +  Window *pWinDefn;      /* List of named window definitions */
  1.5640 +#endif
  1.5641  };
  1.5642  
  1.5643  /*
  1.5644 @@ -15520,7 +17728,7 @@
  1.5645  #define SF_MaybeConvert   0x08000  /* Need convertCompoundSelectToSubquery() */
  1.5646  #define SF_Converted      0x10000  /* By convertCompoundSelectToSubquery() */
  1.5647  #define SF_IncludeHidden  0x20000  /* Include hidden columns in output */
  1.5648 -
  1.5649 +#define SF_ComplexResult  0x40000  /* Result contains subquery or function */
  1.5650  
  1.5651  /*
  1.5652  ** The results of a SELECT can be distributed in several ways, as defined
  1.5653 @@ -15611,10 +17819,10 @@
  1.5654  */
  1.5655  struct SelectDest {
  1.5656    u8 eDest;            /* How to dispose of the results.  On of SRT_* above. */
  1.5657 -  char *zAffSdst;      /* Affinity used when eDest==SRT_Set */
  1.5658    int iSDParm;         /* A parameter used by the eDest disposal method */
  1.5659    int iSdst;           /* Base register where results are written */
  1.5660    int nSdst;           /* Number of registers allocated */
  1.5661 +  char *zAffSdst;      /* Affinity used when eDest==SRT_Set */
  1.5662    ExprList *pOrderBy;  /* Key columns for SRT_Queue and SRT_DistQueue */
  1.5663  };
  1.5664  
  1.5665 @@ -15635,13 +17843,6 @@
  1.5666  };
  1.5667  
  1.5668  /*
  1.5669 -** Size of the column cache
  1.5670 -*/
  1.5671 -#ifndef SQLITE_N_COLCACHE
  1.5672 -# define SQLITE_N_COLCACHE 10
  1.5673 -#endif
  1.5674 -
  1.5675 -/*
  1.5676  ** At least one instance of the following structure is created for each
  1.5677  ** trigger that may be fired while parsing an INSERT, UPDATE or DELETE
  1.5678  ** statement. All such objects are stored in the linked list headed at
  1.5679 @@ -15716,7 +17917,6 @@
  1.5680    u8 hasCompound;      /* Need to invoke convertCompoundSelectToSubquery() */
  1.5681    u8 okConstFactor;    /* OK to factor out constants */
  1.5682    u8 disableLookaside; /* Number of times lookaside has been disabled */
  1.5683 -  u8 nColCache;        /* Number of entries in aColCache[] */
  1.5684    int nRangeReg;       /* Size of the temporary register block */
  1.5685    int iRangeReg;       /* First register in temporary register block */
  1.5686    int nErr;            /* Number of errors seen */
  1.5687 @@ -15724,10 +17924,8 @@
  1.5688    int nMem;            /* Number of memory cells used so far */
  1.5689    int nOpAlloc;        /* Number of slots allocated for Vdbe.aOp[] */
  1.5690    int szOpAlloc;       /* Bytes of memory space allocated for Vdbe.aOp[] */
  1.5691 -  int ckBase;          /* Base register of data during check constraints */
  1.5692 -  int iSelfTab;        /* Table of an index whose exprs are being coded */
  1.5693 -  int iCacheLevel;     /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
  1.5694 -  int iCacheCnt;       /* Counter used to generate aColCache[].lru values */
  1.5695 +  int iSelfTab;        /* Table associated with an index on expr, or negative
  1.5696 +                       ** of the base register during check-constraint eval */
  1.5697    int nLabel;          /* Number of labels used */
  1.5698    int *aLabel;         /* Space to hold the labels */
  1.5699    ExprList *pConstExpr;/* Constant expressions */
  1.5700 @@ -15737,10 +17935,7 @@
  1.5701    int regRowid;        /* Register holding rowid of CREATE TABLE entry */
  1.5702    int regRoot;         /* Register holding root page number for new objects */
  1.5703    int nMaxArg;         /* Max args passed to user function by sub-program */
  1.5704 -#if SELECTTRACE_ENABLED
  1.5705 -  int nSelect;         /* Number of SELECT statements seen */
  1.5706 -  int nSelectIndent;   /* How far to indent SELECTTRACE() output */
  1.5707 -#endif
  1.5708 +  int nSelect;         /* Number of SELECT stmts. Counter for Select.selId */
  1.5709  #ifndef SQLITE_OMIT_SHARED_CACHE
  1.5710    int nTableLock;        /* Number of locks in aTableLock */
  1.5711    TableLock *aTableLock; /* Required table locks for shared-cache mode */
  1.5712 @@ -15748,7 +17943,7 @@
  1.5713    AutoincInfo *pAinc;  /* Information about AUTOINCREMENT counters */
  1.5714    Parse *pToplevel;    /* Parse structure for main program (or NULL) */
  1.5715    Table *pTriggerTab;  /* Table triggers are being coded for */
  1.5716 -  int addrCrTab;       /* Address of OP_CreateTable opcode on CREATE TABLE */
  1.5717 +  int addrCrTab;       /* Address of OP_CreateBtree opcode on CREATE TABLE */
  1.5718    u32 nQueryLoop;      /* Est number of iterations of a query (10*log2(N)) */
  1.5719    u32 oldmask;         /* Mask of old.* columns referenced */
  1.5720    u32 newmask;         /* Mask of new.* columns referenced */
  1.5721 @@ -15760,17 +17955,9 @@
  1.5722    ** Fields above must be initialized to zero.  The fields that follow,
  1.5723    ** down to the beginning of the recursive section, do not need to be
  1.5724    ** initialized as they will be set before being used.  The boundary is
  1.5725 -  ** determined by offsetof(Parse,aColCache).
  1.5726 +  ** determined by offsetof(Parse,aTempReg).
  1.5727    **************************************************************************/
  1.5728  
  1.5729 -  struct yColCache {
  1.5730 -    int iTable;           /* Table cursor number */
  1.5731 -    i16 iColumn;          /* Table column number */
  1.5732 -    u8 tempReg;           /* iReg is a temp register that needs to be freed */
  1.5733 -    int iLevel;           /* Nesting level */
  1.5734 -    int iReg;             /* Reg with value of this column. 0 means none. */
  1.5735 -    int lru;              /* Least recently used entry has the smallest value */
  1.5736 -  } aColCache[SQLITE_N_COLCACHE];  /* One for each column cache entry */
  1.5737    int aTempReg[8];        /* Holding area for temporary registers */
  1.5738    Token sNameToken;       /* Token with unqualified schema object name */
  1.5739  
  1.5740 @@ -15785,19 +17972,21 @@
  1.5741    ynVar nVar;               /* Number of '?' variables seen in the SQL so far */
  1.5742    u8 iPkSortOrder;          /* ASC or DESC for INTEGER PRIMARY KEY */
  1.5743    u8 explain;               /* True if the EXPLAIN flag is found on the query */
  1.5744 +#if !(defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_OMIT_ALTERTABLE))
  1.5745 +  u8 eParseMode;            /* PARSE_MODE_XXX constant */
  1.5746 +#endif
  1.5747  #ifndef SQLITE_OMIT_VIRTUALTABLE
  1.5748 -  u8 declareVtab;           /* True if inside sqlite3_declare_vtab() */
  1.5749    int nVtabLock;            /* Number of virtual tables to lock */
  1.5750  #endif
  1.5751    int nHeight;              /* Expression tree height of current sub-select */
  1.5752  #ifndef SQLITE_OMIT_EXPLAIN
  1.5753 -  int iSelectId;            /* ID of current select for EXPLAIN output */
  1.5754 -  int iNextSelectId;        /* Next available select ID for EXPLAIN output */
  1.5755 +  int addrExplain;          /* Address of current OP_Explain opcode */
  1.5756  #endif
  1.5757    VList *pVList;            /* Mapping between variable names and numbers */
  1.5758    Vdbe *pReprepare;         /* VM being reprepared (sqlite3Reprepare()) */
  1.5759    const char *zTail;        /* All SQL text past the last semicolon parsed */
  1.5760    Table *pNewTable;         /* A table being constructed by CREATE TABLE */
  1.5761 +  Index *pNewIndex;         /* An index being constructed by CREATE INDEX */
  1.5762    Trigger *pNewTrigger;     /* Trigger under construct by a CREATE TRIGGER */
  1.5763    const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
  1.5764  #ifndef SQLITE_OMIT_VIRTUALTABLE
  1.5765 @@ -15808,12 +17997,20 @@
  1.5766    TriggerPrg *pTriggerPrg;  /* Linked list of coded triggers */
  1.5767    With *pWith;              /* Current WITH clause, or NULL */
  1.5768    With *pWithToFree;        /* Free this WITH object at the end of the parse */
  1.5769 -};
  1.5770 +#ifndef SQLITE_OMIT_ALTERTABLE
  1.5771 +  RenameToken *pRename;     /* Tokens subject to renaming by ALTER TABLE */
  1.5772 +#endif
  1.5773 +};
  1.5774 +
  1.5775 +#define PARSE_MODE_NORMAL        0
  1.5776 +#define PARSE_MODE_DECLARE_VTAB  1
  1.5777 +#define PARSE_MODE_RENAME_COLUMN 2
  1.5778 +#define PARSE_MODE_RENAME_TABLE  3
  1.5779  
  1.5780  /*
  1.5781  ** Sizes and pointers of various parts of the Parse object.
  1.5782  */
  1.5783 -#define PARSE_HDR_SZ offsetof(Parse,aColCache) /* Recursive part w/o aColCache*/
  1.5784 +#define PARSE_HDR_SZ offsetof(Parse,aTempReg) /* Recursive part w/o aColCache*/
  1.5785  #define PARSE_RECURSE_SZ offsetof(Parse,sLastToken)    /* Recursive part */
  1.5786  #define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */
  1.5787  #define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ)  /* Pointer to tail */
  1.5788 @@ -15824,7 +18021,19 @@
  1.5789  #ifdef SQLITE_OMIT_VIRTUALTABLE
  1.5790    #define IN_DECLARE_VTAB 0
  1.5791  #else
  1.5792 -  #define IN_DECLARE_VTAB (pParse->declareVtab)
  1.5793 +  #define IN_DECLARE_VTAB (pParse->eParseMode==PARSE_MODE_DECLARE_VTAB)
  1.5794 +#endif
  1.5795 +
  1.5796 +#if defined(SQLITE_OMIT_ALTERTABLE)
  1.5797 +  #define IN_RENAME_OBJECT 0
  1.5798 +#else
  1.5799 +  #define IN_RENAME_OBJECT (pParse->eParseMode>=PARSE_MODE_RENAME_COLUMN)
  1.5800 +#endif
  1.5801 +
  1.5802 +#if defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_OMIT_ALTERTABLE)
  1.5803 +  #define IN_SPECIAL_PARSE 0
  1.5804 +#else
  1.5805 +  #define IN_SPECIAL_PARSE (pParse->eParseMode!=PARSE_MODE_NORMAL)
  1.5806  #endif
  1.5807  
  1.5808  /*
  1.5809 @@ -15850,6 +18059,7 @@
  1.5810  */
  1.5811  #define OPFLAG_NCHANGE       0x01    /* OP_Insert: Set to update db->nChange */
  1.5812                                       /* Also used in P2 (not P5) of OP_Delete */
  1.5813 +#define OPFLAG_NOCHNG        0x01    /* OP_VColumn nochange for UPDATE */
  1.5814  #define OPFLAG_EPHEM         0x01    /* OP_Column: Ephemeral output is ok */
  1.5815  #define OPFLAG_LASTROWID     0x20    /* Set to update db->lastRowid */
  1.5816  #define OPFLAG_ISUPDATE      0x04    /* This OP_Insert is an sql UPDATE */
  1.5817 @@ -15865,6 +18075,7 @@
  1.5818  #define OPFLAG_PERMUTE       0x01    /* OP_Compare: use the permutation */
  1.5819  #define OPFLAG_SAVEPOSITION  0x02    /* OP_Delete/Insert: save cursor pos */
  1.5820  #define OPFLAG_AUXDELETE     0x04    /* OP_Delete: index in a DELETE op */
  1.5821 +#define OPFLAG_NOCHNG_MAGIC  0x6d    /* OP_MakeRecord: serialtype 10 is ok */
  1.5822  
  1.5823  /*
  1.5824   * Each trigger present in the database schema is stored as an instance of
  1.5825 @@ -15950,8 +18161,10 @@
  1.5826    Select *pSelect;     /* SELECT statement or RHS of INSERT INTO SELECT ... */
  1.5827    char *zTarget;       /* Target table for DELETE, UPDATE, INSERT */
  1.5828    Expr *pWhere;        /* The WHERE clause for DELETE or UPDATE steps */
  1.5829 -  ExprList *pExprList; /* SET clause for UPDATE. */
  1.5830 +  ExprList *pExprList; /* SET clause for UPDATE */
  1.5831    IdList *pIdList;     /* Column names for INSERT */
  1.5832 +  Upsert *pUpsert;     /* Upsert clauses on an INSERT */
  1.5833 +  char *zSpan;         /* Original SQL text of this command */
  1.5834    TriggerStep *pNext;  /* Next in the link-list */
  1.5835    TriggerStep *pLast;  /* Last element in link-list. Valid for 1st elem only */
  1.5836  };
  1.5837 @@ -15975,18 +18188,15 @@
  1.5838  ** An objected used to accumulate the text of a string where we
  1.5839  ** do not necessarily know how big the string will be in the end.
  1.5840  */
  1.5841 -struct StrAccum {
  1.5842 +struct sqlite3_str {
  1.5843    sqlite3 *db;         /* Optional database for lookaside.  Can be NULL */
  1.5844 -  char *zBase;         /* A base allocation.  Not from malloc. */
  1.5845    char *zText;         /* The string collected so far */
  1.5846 -  u32  nChar;          /* Length of the string so far */
  1.5847    u32  nAlloc;         /* Amount of space allocated in zText */
  1.5848    u32  mxAlloc;        /* Maximum allowed allocation.  0 for no malloc usage */
  1.5849 -  u8   accError;       /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
  1.5850 +  u32  nChar;          /* Length of the string so far */
  1.5851 +  u8   accError;       /* SQLITE_NOMEM or SQLITE_TOOBIG */
  1.5852    u8   printfFlags;    /* SQLITE_PRINTF flags below */
  1.5853  };
  1.5854 -#define STRACCUM_NOMEM   1
  1.5855 -#define STRACCUM_TOOBIG  2
  1.5856  #define SQLITE_PRINTF_INTERNAL 0x01  /* Internal-use-only converters allowed */
  1.5857  #define SQLITE_PRINTF_SQLFUNC  0x02  /* SQL function arguments to VXPrintf */
  1.5858  #define SQLITE_PRINTF_MALLOCED 0x04  /* True if xText is allocated space */
  1.5859 @@ -16003,9 +18213,15 @@
  1.5860    char **pzErrMsg;    /* Error message stored here */
  1.5861    int iDb;            /* 0 for main database.  1 for TEMP, 2.. for ATTACHed */
  1.5862    int rc;             /* Result code stored here */
  1.5863 +  u32 mInitFlags;     /* Flags controlling error messages */
  1.5864  } InitData;
  1.5865  
  1.5866  /*
  1.5867 +** Allowed values for mInitFlags
  1.5868 +*/
  1.5869 +#define INITFLAG_AlterTable   0x0001  /* This is a reparse after ALTER TABLE */
  1.5870 +
  1.5871 +/*
  1.5872  ** Structure containing global configuration data for the SQLite library.
  1.5873  **
  1.5874  ** This structure also contains some state information.
  1.5875 @@ -16016,6 +18232,7 @@
  1.5876    int bFullMutex;                   /* True to enable full mutexing */
  1.5877    int bOpenUri;                     /* True to interpret filenames as URIs */
  1.5878    int bUseCis;                      /* Use covering indices for full-scans */
  1.5879 +  int bSmallMalloc;                 /* Avoid large memory allocations if true */
  1.5880    int mxStrlen;                     /* Maximum string length */
  1.5881    int neverCorrupt;                 /* Database is always well-formed */
  1.5882    int szLookaside;                  /* Default lookaside buffer size */
  1.5883 @@ -16029,9 +18246,6 @@
  1.5884    int mnReq, mxReq;                 /* Min and max heap requests sizes */
  1.5885    sqlite3_int64 szMmap;             /* mmap() space per open file */
  1.5886    sqlite3_int64 mxMmap;             /* Maximum value for szMmap */
  1.5887 -  void *pScratch;                   /* Scratch memory */
  1.5888 -  int szScratch;                    /* Size of each scratch buffer */
  1.5889 -  int nScratch;                     /* Number of scratch buffers */
  1.5890    void *pPage;                      /* Page cache memory */
  1.5891    int szPage;                       /* Size of each page in pPage[] */
  1.5892    int nPage;                        /* Number of pages in pPage[] */
  1.5893 @@ -16057,14 +18271,16 @@
  1.5894    /* The following callback (if not NULL) is invoked on every VDBE branch
  1.5895    ** operation.  Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE.
  1.5896    */
  1.5897 -  void (*xVdbeBranch)(void*,int iSrcLine,u8 eThis,u8 eMx);  /* Callback */
  1.5898 +  void (*xVdbeBranch)(void*,unsigned iSrcLine,u8 eThis,u8 eMx);  /* Callback */
  1.5899    void *pVdbeBranchArg;                                     /* 1st argument */
  1.5900  #endif
  1.5901  #ifndef SQLITE_UNTESTABLE
  1.5902    int (*xTestCallback)(int);        /* Invoked by sqlite3FaultSim() */
  1.5903  #endif
  1.5904    int bLocaltimeFault;              /* True to fail localtime() calls */
  1.5905 +  int bInternalFunctions;           /* Internal SQL functions are visible */
  1.5906    int iOnceResetThreshold;          /* When to reset OP_Once counters */
  1.5907 +  u32 szSorterRef;                  /* Min size in bytes to use sorter-refs */
  1.5908  };
  1.5909  
  1.5910  /*
  1.5911 @@ -16104,9 +18320,12 @@
  1.5912      struct CCurHint *pCCurHint;               /* Used by codeCursorHint() */
  1.5913      int *aiCol;                               /* array of column indexes */
  1.5914      struct IdxCover *pIdxCover;               /* Check for index coverage */
  1.5915 -    struct IdxExprTrans *pIdxTrans;           /* Convert indexed expr to column */
  1.5916 +    struct IdxExprTrans *pIdxTrans;           /* Convert idxed expr to column */
  1.5917      ExprList *pGroupBy;                       /* GROUP BY clause */
  1.5918 -    struct HavingToWhereCtx *pHavingCtx;      /* HAVING to WHERE clause ctx */
  1.5919 +    Select *pSelect;                          /* HAVING to WHERE clause ctx */
  1.5920 +    struct WindowRewrite *pRewrite;           /* Window rewrite context */
  1.5921 +    struct WhereConst *pConst;                /* WHERE clause constants */
  1.5922 +    struct RenameCtx *pRename;                /* RENAME COLUMN context */
  1.5923    } u;
  1.5924  };
  1.5925  
  1.5926 @@ -16117,6 +18336,11 @@
  1.5927  SQLITE_PRIVATE int sqlite3WalkSelectExpr(Walker*, Select*);
  1.5928  SQLITE_PRIVATE int sqlite3WalkSelectFrom(Walker*, Select*);
  1.5929  SQLITE_PRIVATE int sqlite3ExprWalkNoop(Walker*, Expr*);
  1.5930 +SQLITE_PRIVATE int sqlite3SelectWalkNoop(Walker*, Select*);
  1.5931 +SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker*, Select*);
  1.5932 +#ifdef SQLITE_DEBUG
  1.5933 +SQLITE_PRIVATE void sqlite3SelectWalkAssert2(Walker*, Select*);
  1.5934 +#endif
  1.5935  
  1.5936  /*
  1.5937  ** Return code from the parse-tree walking primitives and their
  1.5938 @@ -16153,6 +18377,68 @@
  1.5939  #endif /* SQLITE_DEBUG */
  1.5940  
  1.5941  /*
  1.5942 +** This object is used in varioius ways, all related to window functions
  1.5943 +**
  1.5944 +**   (1) A single instance of this structure is attached to the
  1.5945 +**       the Expr.pWin field for each window function in an expression tree.
  1.5946 +**       This object holds the information contained in the OVER clause,
  1.5947 +**       plus additional fields used during code generation.
  1.5948 +**
  1.5949 +**   (2) All window functions in a single SELECT form a linked-list
  1.5950 +**       attached to Select.pWin.  The Window.pFunc and Window.pExpr
  1.5951 +**       fields point back to the expression that is the window function.
  1.5952 +**
  1.5953 +**   (3) The terms of the WINDOW clause of a SELECT are instances of this
  1.5954 +**       object on a linked list attached to Select.pWinDefn.
  1.5955 +**
  1.5956 +** The uses (1) and (2) are really the same Window object that just happens
  1.5957 +** to be accessible in two different ways.  Use (3) is are separate objects.
  1.5958 +*/
  1.5959 +struct Window {
  1.5960 +  char *zName;            /* Name of window (may be NULL) */
  1.5961 +  ExprList *pPartition;   /* PARTITION BY clause */
  1.5962 +  ExprList *pOrderBy;     /* ORDER BY clause */
  1.5963 +  u8 eType;               /* TK_RANGE or TK_ROWS */
  1.5964 +  u8 eStart;              /* UNBOUNDED, CURRENT, PRECEDING or FOLLOWING */
  1.5965 +  u8 eEnd;                /* UNBOUNDED, CURRENT, PRECEDING or FOLLOWING */
  1.5966 +  Expr *pStart;           /* Expression for "<expr> PRECEDING" */
  1.5967 +  Expr *pEnd;             /* Expression for "<expr> FOLLOWING" */
  1.5968 +  Window *pNextWin;       /* Next window function belonging to this SELECT */
  1.5969 +  Expr *pFilter;          /* The FILTER expression */
  1.5970 +  FuncDef *pFunc;         /* The function */
  1.5971 +  int iEphCsr;            /* Partition buffer or Peer buffer */
  1.5972 +  int regAccum;
  1.5973 +  int regResult;
  1.5974 +  int csrApp;             /* Function cursor (used by min/max) */
  1.5975 +  int regApp;             /* Function register (also used by min/max) */
  1.5976 +  int regPart;            /* First in a set of registers holding PARTITION BY
  1.5977 +                          ** and ORDER BY values for the window */
  1.5978 +  Expr *pOwner;           /* Expression object this window is attached to */
  1.5979 +  int nBufferCol;         /* Number of columns in buffer table */
  1.5980 +  int iArgCol;            /* Offset of first argument for this function */
  1.5981 +};
  1.5982 +
  1.5983 +#ifndef SQLITE_OMIT_WINDOWFUNC
  1.5984 +SQLITE_PRIVATE void sqlite3WindowDelete(sqlite3*, Window*);
  1.5985 +SQLITE_PRIVATE void sqlite3WindowListDelete(sqlite3 *db, Window *p);
  1.5986 +SQLITE_PRIVATE Window *sqlite3WindowAlloc(Parse*, int, int, Expr*, int , Expr*);
  1.5987 +SQLITE_PRIVATE void sqlite3WindowAttach(Parse*, Expr*, Window*);
  1.5988 +SQLITE_PRIVATE int sqlite3WindowCompare(Parse*, Window*, Window*);
  1.5989 +SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse*, Window*);
  1.5990 +SQLITE_PRIVATE void sqlite3WindowCodeStep(Parse*, Select*, WhereInfo*, int, int);
  1.5991 +SQLITE_PRIVATE int sqlite3WindowRewrite(Parse*, Select*);
  1.5992 +SQLITE_PRIVATE int sqlite3ExpandSubquery(Parse*, struct SrcList_item*);
  1.5993 +SQLITE_PRIVATE void sqlite3WindowUpdate(Parse*, Window*, Window*, FuncDef*);
  1.5994 +SQLITE_PRIVATE Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p);
  1.5995 +SQLITE_PRIVATE Window *sqlite3WindowListDup(sqlite3 *db, Window *p);
  1.5996 +SQLITE_PRIVATE void sqlite3WindowFunctions(void);
  1.5997 +#else
  1.5998 +# define sqlite3WindowDelete(a,b)
  1.5999 +# define sqlite3WindowFunctions()
  1.6000 +# define sqlite3WindowAttach(a,b,c)
  1.6001 +#endif
  1.6002 +
  1.6003 +/*
  1.6004  ** Assuming zIn points to the first byte of a UTF-8 character,
  1.6005  ** advance zIn to point to the first byte of the next UTF-8 character.
  1.6006  */
  1.6007 @@ -16169,6 +18455,7 @@
  1.6008  ** using sqlite3_log().  The routines also provide a convenient place
  1.6009  ** to set a debugger breakpoint.
  1.6010  */
  1.6011 +SQLITE_PRIVATE int sqlite3ReportError(int iErr, int lineno, const char *zType);
  1.6012  SQLITE_PRIVATE int sqlite3CorruptError(int);
  1.6013  SQLITE_PRIVATE int sqlite3MisuseError(int);
  1.6014  SQLITE_PRIVATE int sqlite3CantopenError(int);
  1.6015 @@ -16178,11 +18465,14 @@
  1.6016  #ifdef SQLITE_DEBUG
  1.6017  SQLITE_PRIVATE   int sqlite3NomemError(int);
  1.6018  SQLITE_PRIVATE   int sqlite3IoerrnomemError(int);
  1.6019 +SQLITE_PRIVATE   int sqlite3CorruptPgnoError(int,Pgno);
  1.6020  # define SQLITE_NOMEM_BKPT sqlite3NomemError(__LINE__)
  1.6021  # define SQLITE_IOERR_NOMEM_BKPT sqlite3IoerrnomemError(__LINE__)
  1.6022 +# define SQLITE_CORRUPT_PGNO(P) sqlite3CorruptPgnoError(__LINE__,(P))
  1.6023  #else
  1.6024  # define SQLITE_NOMEM_BKPT SQLITE_NOMEM
  1.6025  # define SQLITE_IOERR_NOMEM_BKPT SQLITE_IOERR_NOMEM
  1.6026 +# define SQLITE_CORRUPT_PGNO(P) sqlite3CorruptError(__LINE__)
  1.6027  #endif
  1.6028  
  1.6029  /*
  1.6030 @@ -16235,15 +18525,14 @@
  1.6031  # define sqlite3Tolower(x)   tolower((unsigned char)(x))
  1.6032  # define sqlite3Isquote(x)   ((x)=='"'||(x)=='\''||(x)=='['||(x)=='`')
  1.6033  #endif
  1.6034 -#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
  1.6035  SQLITE_PRIVATE int sqlite3IsIdChar(u8);
  1.6036 -#endif
  1.6037  
  1.6038  /*
  1.6039  ** Internal function prototypes
  1.6040  */
  1.6041  SQLITE_PRIVATE int sqlite3StrICmp(const char*,const char*);
  1.6042  SQLITE_PRIVATE int sqlite3Strlen30(const char*);
  1.6043 +#define sqlite3Strlen30NN(C) (strlen(C)&0x3fffffff)
  1.6044  SQLITE_PRIVATE char *sqlite3ColumnType(Column*,char*);
  1.6045  #define sqlite3StrNICmp sqlite3_strnicmp
  1.6046  
  1.6047 @@ -16256,6 +18545,7 @@
  1.6048  SQLITE_PRIVATE void *sqlite3DbMallocRawNN(sqlite3*, u64);
  1.6049  SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3*,const char*);
  1.6050  SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, u64);
  1.6051 +SQLITE_PRIVATE char *sqlite3DbSpanDup(sqlite3*,const char*,const char*);
  1.6052  SQLITE_PRIVATE void *sqlite3Realloc(void*, u64);
  1.6053  SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
  1.6054  SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
  1.6055 @@ -16263,8 +18553,6 @@
  1.6056  SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
  1.6057  SQLITE_PRIVATE int sqlite3MallocSize(void*);
  1.6058  SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*);
  1.6059 -SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
  1.6060 -SQLITE_PRIVATE void sqlite3ScratchFree(void*);
  1.6061  SQLITE_PRIVATE void *sqlite3PageMalloc(int);
  1.6062  SQLITE_PRIVATE void sqlite3PageFree(void*);
  1.6063  SQLITE_PRIVATE void sqlite3MemSetDefault(void);
  1.6064 @@ -16320,11 +18608,18 @@
  1.6065  SQLITE_PRIVATE void sqlite3StatusUp(int, int);
  1.6066  SQLITE_PRIVATE void sqlite3StatusDown(int, int);
  1.6067  SQLITE_PRIVATE void sqlite3StatusHighwater(int, int);
  1.6068 +SQLITE_PRIVATE int sqlite3LookasideUsed(sqlite3*,int*);
  1.6069  
  1.6070  /* Access to mutexes used by sqlite3_status() */
  1.6071  SQLITE_PRIVATE sqlite3_mutex *sqlite3Pcache1Mutex(void);
  1.6072  SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void);
  1.6073  
  1.6074 +#if defined(SQLITE_ENABLE_MULTITHREADED_CHECKS) && !defined(SQLITE_MUTEX_OMIT)
  1.6075 +SQLITE_PRIVATE void sqlite3MutexWarnOnContention(sqlite3_mutex*);
  1.6076 +#else
  1.6077 +# define sqlite3MutexWarnOnContention(x)
  1.6078 +#endif
  1.6079 +
  1.6080  #ifndef SQLITE_OMIT_FLOATING_POINT
  1.6081  SQLITE_PRIVATE   int sqlite3IsNaN(double);
  1.6082  #else
  1.6083 @@ -16341,8 +18636,6 @@
  1.6084    sqlite3_value **apArg;   /* The argument values */
  1.6085  };
  1.6086  
  1.6087 -SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, const char*, va_list);
  1.6088 -SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, const char*, ...);
  1.6089  SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
  1.6090  SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
  1.6091  #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
  1.6092 @@ -16356,8 +18649,13 @@
  1.6093  SQLITE_PRIVATE   void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
  1.6094  SQLITE_PRIVATE   void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*);
  1.6095  SQLITE_PRIVATE   void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*);
  1.6096 +SQLITE_PRIVATE   void sqlite3TreeViewSrcList(TreeView*, const SrcList*);
  1.6097  SQLITE_PRIVATE   void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
  1.6098  SQLITE_PRIVATE   void sqlite3TreeViewWith(TreeView*, const With*, u8);
  1.6099 +#ifndef SQLITE_OMIT_WINDOWFUNC
  1.6100 +SQLITE_PRIVATE   void sqlite3TreeViewWindow(TreeView*, const Window*, u8);
  1.6101 +SQLITE_PRIVATE   void sqlite3TreeViewWinFunc(TreeView*, const Window*, u8);
  1.6102 +#endif
  1.6103  #endif
  1.6104  
  1.6105  
  1.6106 @@ -16382,18 +18680,19 @@
  1.6107  SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*);
  1.6108  SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*);
  1.6109  SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
  1.6110 -SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
  1.6111 +SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*, int);
  1.6112  SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
  1.6113  SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
  1.6114  SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
  1.6115  SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*);
  1.6116  SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int);
  1.6117  SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
  1.6118 -SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
  1.6119 +SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*);
  1.6120  SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
  1.6121  SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
  1.6122  SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
  1.6123  SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
  1.6124 +SQLITE_PRIVATE int sqlite3InitOne(sqlite3*, int, char**, u32);
  1.6125  SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
  1.6126  #ifndef SQLITE_OMIT_VIRTUALTABLE
  1.6127  SQLITE_PRIVATE Module *sqlite3PragmaVtabRegister(sqlite3*,const char *zName);
  1.6128 @@ -16419,7 +18718,7 @@
  1.6129  SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int);
  1.6130  SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
  1.6131  SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*);
  1.6132 -SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,ExprSpan*);
  1.6133 +SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*);
  1.6134  SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
  1.6135  SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);
  1.6136  SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
  1.6137 @@ -16443,8 +18742,9 @@
  1.6138  SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int,int*);
  1.6139  #endif
  1.6140  
  1.6141 -SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3*, void*, unsigned int);
  1.6142 -SQLITE_PRIVATE void sqlite3RowSetClear(RowSet*);
  1.6143 +SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3*);
  1.6144 +SQLITE_PRIVATE void sqlite3RowSetDelete(void*);
  1.6145 +SQLITE_PRIVATE void sqlite3RowSetClear(void*);
  1.6146  SQLITE_PRIVATE void sqlite3RowSetInsert(RowSet*, i64);
  1.6147  SQLITE_PRIVATE int sqlite3RowSetTest(RowSet*, int iBatch, i64);
  1.6148  SQLITE_PRIVATE int sqlite3RowSetNext(RowSet*, i64*);
  1.6149 @@ -16463,6 +18763,7 @@
  1.6150  SQLITE_PRIVATE void sqlite3DropTable(Parse*, SrcList*, int, int);
  1.6151  SQLITE_PRIVATE void sqlite3CodeDropTable(Parse*, Table*, int, int);
  1.6152  SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3*, Table*);
  1.6153 +SQLITE_PRIVATE void sqlite3FreeIndex(sqlite3*, Index*);
  1.6154  #ifndef SQLITE_OMIT_AUTOINCREMENT
  1.6155  SQLITE_PRIVATE   void sqlite3AutoincrementBegin(Parse *pParse);
  1.6156  SQLITE_PRIVATE   void sqlite3AutoincrementEnd(Parse *pParse);
  1.6157 @@ -16470,9 +18771,9 @@
  1.6158  # define sqlite3AutoincrementBegin(X)
  1.6159  # define sqlite3AutoincrementEnd(X)
  1.6160  #endif
  1.6161 -SQLITE_PRIVATE void sqlite3Insert(Parse*, SrcList*, Select*, IdList*, int);
  1.6162 +SQLITE_PRIVATE void sqlite3Insert(Parse*, SrcList*, Select*, IdList*, int, Upsert*);
  1.6163  SQLITE_PRIVATE void *sqlite3ArrayAllocate(sqlite3*,void*,int,int*,int*);
  1.6164 -SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
  1.6165 +SQLITE_PRIVATE IdList *sqlite3IdListAppend(Parse*, IdList*, Token*);
  1.6166  SQLITE_PRIVATE int sqlite3IdListIndex(IdList*,const char*);
  1.6167  SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
  1.6168  SQLITE_PRIVATE SrcList *sqlite3SrcListAppend(sqlite3*, SrcList*, Token*, Token*);
  1.6169 @@ -16491,22 +18792,23 @@
  1.6170  SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
  1.6171  SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
  1.6172  SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
  1.6173 -                         Expr*,ExprList*,u32,Expr*,Expr*);
  1.6174 +                         Expr*,ExprList*,u32,Expr*);
  1.6175  SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3*, Select*);
  1.6176  SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*);
  1.6177  SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, int);
  1.6178  SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
  1.6179  #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
  1.6180 -SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,Expr*,char*);
  1.6181 -#endif
  1.6182 -SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
  1.6183 -SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
  1.6184 +SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,char*);
  1.6185 +#endif
  1.6186 +SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*, ExprList*, Expr*);
  1.6187 +SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*,Expr*,int,ExprList*,Expr*,
  1.6188 +                   Upsert*);
  1.6189  SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,ExprList*,u16,int);
  1.6190  SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*);
  1.6191  SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo*);
  1.6192  SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*);
  1.6193  SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
  1.6194 -SQLITE_PRIVATE int sqlite3WhereOrderedInnerLoop(WhereInfo*);
  1.6195 +SQLITE_PRIVATE int sqlite3WhereOrderByLimitOptLabel(WhereInfo*);
  1.6196  SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo*);
  1.6197  SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*);
  1.6198  SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*);
  1.6199 @@ -16516,15 +18818,8 @@
  1.6200  #define ONEPASS_MULTI    2        /* ONEPASS is valid for multiple rows */
  1.6201  SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int);
  1.6202  SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
  1.6203 -SQLITE_PRIVATE void sqlite3ExprCodeGetColumnToReg(Parse*, Table*, int, int, int);
  1.6204  SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
  1.6205  SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
  1.6206 -SQLITE_PRIVATE void sqlite3ExprCacheStore(Parse*, int, int, int);
  1.6207 -SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
  1.6208 -SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*);
  1.6209 -SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
  1.6210 -SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
  1.6211 -SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
  1.6212  SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
  1.6213  SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int);
  1.6214  SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
  1.6215 @@ -16551,10 +18846,11 @@
  1.6216  SQLITE_PRIVATE void sqlite3Vacuum(Parse*,Token*);
  1.6217  SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*, int);
  1.6218  SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
  1.6219 -SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*, int);
  1.6220 +SQLITE_PRIVATE int sqlite3ExprCompare(Parse*,Expr*, Expr*, int);
  1.6221  SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*, Expr*, int);
  1.6222  SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
  1.6223 -SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Expr*, Expr*, int);
  1.6224 +SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Parse*,Expr*, Expr*, int);
  1.6225 +SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int);
  1.6226  SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
  1.6227  SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
  1.6228  SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
  1.6229 @@ -16568,11 +18864,12 @@
  1.6230  SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int);
  1.6231  SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb);
  1.6232  SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int);
  1.6233 -SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*);
  1.6234 -SQLITE_PRIVATE void sqlite3RollbackTransaction(Parse*);
  1.6235 +SQLITE_PRIVATE void sqlite3EndTransaction(Parse*,int);
  1.6236  SQLITE_PRIVATE void sqlite3Savepoint(Parse*, int, Token*);
  1.6237  SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
  1.6238  SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
  1.6239 +SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr*);
  1.6240 +SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr*);
  1.6241  SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
  1.6242  SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
  1.6243  SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
  1.6244 @@ -16585,13 +18882,17 @@
  1.6245  SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
  1.6246  SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
  1.6247  SQLITE_PRIVATE int sqlite3IsRowid(const char*);
  1.6248 +#ifdef SQLITE_ENABLE_NORMALIZE
  1.6249 +SQLITE_PRIVATE int sqlite3IsRowidN(const char*, int);
  1.6250 +#endif
  1.6251  SQLITE_PRIVATE void sqlite3GenerateRowDelete(
  1.6252      Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8,int);
  1.6253  SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*, int);
  1.6254  SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int);
  1.6255  SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel(Parse*,int);
  1.6256 +SQLITE_PRIVATE int sqlite3ExprReferencesUpdatedColumn(Expr*,int*,int);
  1.6257  SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
  1.6258 -                                     u8,u8,int,int*,int*);
  1.6259 +                                     u8,u8,int,int*,int*,Upsert*);
  1.6260  #ifdef SQLITE_ENABLE_NULL_TRIM
  1.6261  SQLITE_PRIVATE   void sqlite3SetMakeRecordP5(Vdbe*,Table*);
  1.6262  #else
  1.6263 @@ -16610,10 +18911,8 @@
  1.6264  SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int);
  1.6265  SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3*,IdList*);
  1.6266  SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3*,Select*,int);
  1.6267 -#if SELECTTRACE_ENABLED
  1.6268 -SQLITE_PRIVATE void sqlite3SelectSetName(Select*,const char*);
  1.6269 -#else
  1.6270 -# define sqlite3SelectSetName(A,B)
  1.6271 +#ifdef SQLITE_ENABLE_NORMALIZE
  1.6272 +SQLITE_PRIVATE FuncDef *sqlite3FunctionSearchN(int,const char*,int);
  1.6273  #endif
  1.6274  SQLITE_PRIVATE void sqlite3InsertBuiltinFuncs(FuncDef*,int);
  1.6275  SQLITE_PRIVATE FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,u8,u8);
  1.6276 @@ -16625,7 +18924,7 @@
  1.6277  SQLITE_PRIVATE void sqlite3ChangeCookie(Parse*, int);
  1.6278  
  1.6279  #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
  1.6280 -SQLITE_PRIVATE void sqlite3MaterializeView(Parse*, Table*, Expr*, int);
  1.6281 +SQLITE_PRIVATE void sqlite3MaterializeView(Parse*, Table*, Expr*, ExprList*,Expr*,int);
  1.6282  #endif
  1.6283  
  1.6284  #ifndef SQLITE_OMIT_TRIGGER
  1.6285 @@ -16641,11 +18940,15 @@
  1.6286  SQLITE_PRIVATE   void sqlite3CodeRowTriggerDirect(Parse *, Trigger *, Table *, int, int, int);
  1.6287    void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*);
  1.6288  SQLITE_PRIVATE   void sqlite3DeleteTriggerStep(sqlite3*, TriggerStep*);
  1.6289 -SQLITE_PRIVATE   TriggerStep *sqlite3TriggerSelectStep(sqlite3*,Select*);
  1.6290 -SQLITE_PRIVATE   TriggerStep *sqlite3TriggerInsertStep(sqlite3*,Token*, IdList*,
  1.6291 -                                        Select*,u8);
  1.6292 -SQLITE_PRIVATE   TriggerStep *sqlite3TriggerUpdateStep(sqlite3*,Token*,ExprList*, Expr*, u8);
  1.6293 -SQLITE_PRIVATE   TriggerStep *sqlite3TriggerDeleteStep(sqlite3*,Token*, Expr*);
  1.6294 +SQLITE_PRIVATE   TriggerStep *sqlite3TriggerSelectStep(sqlite3*,Select*,
  1.6295 +                                        const char*,const char*);
  1.6296 +SQLITE_PRIVATE   TriggerStep *sqlite3TriggerInsertStep(Parse*,Token*, IdList*,
  1.6297 +                                        Select*,u8,Upsert*,
  1.6298 +                                        const char*,const char*);
  1.6299 +SQLITE_PRIVATE   TriggerStep *sqlite3TriggerUpdateStep(Parse*,Token*,ExprList*, Expr*, u8,
  1.6300 +                                        const char*,const char*);
  1.6301 +SQLITE_PRIVATE   TriggerStep *sqlite3TriggerDeleteStep(Parse*,Token*, Expr*,
  1.6302 +                                        const char*,const char*);
  1.6303  SQLITE_PRIVATE   void sqlite3DeleteTrigger(sqlite3*, Trigger*);
  1.6304  SQLITE_PRIVATE   void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*);
  1.6305  SQLITE_PRIVATE   u32 sqlite3TriggerColmask(Parse*,Trigger*,ExprList*,int,int,Table*,int);
  1.6306 @@ -16690,7 +18993,9 @@
  1.6307  SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8);
  1.6308  SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
  1.6309  SQLITE_PRIVATE int sqlite3Atoi(const char*);
  1.6310 +#ifndef SQLITE_OMIT_UTF16
  1.6311  SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nChar);
  1.6312 +#endif
  1.6313  SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte);
  1.6314  SQLITE_PRIVATE u32 sqlite3Utf8Read(const u8**);
  1.6315  SQLITE_PRIVATE LogEst sqlite3LogEst(u64);
  1.6316 @@ -16750,15 +19055,23 @@
  1.6317  SQLITE_PRIVATE const char *sqlite3ErrName(int);
  1.6318  #endif
  1.6319  
  1.6320 +#ifdef SQLITE_ENABLE_DESERIALIZE
  1.6321 +SQLITE_PRIVATE int sqlite3MemdbInit(void);
  1.6322 +#endif
  1.6323 +
  1.6324  SQLITE_PRIVATE const char *sqlite3ErrStr(int);
  1.6325  SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
  1.6326  SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int);
  1.6327 +SQLITE_PRIVATE int sqlite3IsBinary(const CollSeq*);
  1.6328  SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
  1.6329  SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr);
  1.6330 +SQLITE_PRIVATE CollSeq *sqlite3ExprNNCollSeq(Parse *pParse, Expr *pExpr);
  1.6331 +SQLITE_PRIVATE int sqlite3ExprCollSeqMatch(Parse*,Expr*,Expr*);
  1.6332  SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, const Token*, int);
  1.6333  SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*);
  1.6334  SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr*);
  1.6335  SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *);
  1.6336 +SQLITE_PRIVATE int sqlite3WritableSchema(sqlite3*);
  1.6337  SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *);
  1.6338  SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int);
  1.6339  SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64);
  1.6340 @@ -16779,7 +19092,9 @@
  1.6341  SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value*);
  1.6342  SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*);
  1.6343  SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *);
  1.6344 +#ifndef SQLITE_OMIT_UTF16
  1.6345  SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8);
  1.6346 +#endif
  1.6347  SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **);
  1.6348  SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
  1.6349  #ifndef SQLITE_AMALGAMATION
  1.6350 @@ -16794,13 +19109,20 @@
  1.6351  SQLITE_PRIVATE int sqlite3PendingByte;
  1.6352  #endif
  1.6353  #endif
  1.6354 +#ifdef VDBE_PROFILE
  1.6355 +SQLITE_PRIVATE sqlite3_uint64 sqlite3NProfileCnt;
  1.6356 +#endif
  1.6357  SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3*, int, int, int);
  1.6358  SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*);
  1.6359  SQLITE_PRIVATE void sqlite3AlterFunctions(void);
  1.6360  SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
  1.6361 +SQLITE_PRIVATE void sqlite3AlterRenameColumn(Parse*, SrcList*, Token*, Token*);
  1.6362  SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *);
  1.6363 +#ifdef SQLITE_ENABLE_NORMALIZE
  1.6364 +SQLITE_PRIVATE int sqlite3GetTokenNormalized(const unsigned char *, int *, int *);
  1.6365 +#endif
  1.6366  SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
  1.6367 -SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*);
  1.6368 +SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int);
  1.6369  SQLITE_PRIVATE int sqlite3CodeSubselect(Parse*, Expr *, int, int);
  1.6370  SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
  1.6371  SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
  1.6372 @@ -16813,10 +19135,14 @@
  1.6373  SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
  1.6374  SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *, Token *);
  1.6375  SQLITE_PRIVATE void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
  1.6376 +SQLITE_PRIVATE void *sqlite3RenameTokenMap(Parse*, void*, Token*);
  1.6377 +SQLITE_PRIVATE void sqlite3RenameTokenRemap(Parse*, void *pTo, void *pFrom);
  1.6378 +SQLITE_PRIVATE void sqlite3RenameExprUnmap(Parse*, Expr*);
  1.6379 +SQLITE_PRIVATE void sqlite3RenameExprlistUnmap(Parse*, ExprList*);
  1.6380  SQLITE_PRIVATE CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*);
  1.6381 -SQLITE_PRIVATE char sqlite3AffinityType(const char*, u8*);
  1.6382 +SQLITE_PRIVATE char sqlite3AffinityType(const char*, Column*);
  1.6383  SQLITE_PRIVATE void sqlite3Analyze(Parse*, Token*, Token*);
  1.6384 -SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler*);
  1.6385 +SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler*, sqlite3_file*);
  1.6386  SQLITE_PRIVATE int sqlite3FindDb(sqlite3*, Token*);
  1.6387  SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *, const char *);
  1.6388  SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3*,int iDB);
  1.6389 @@ -16831,25 +19157,27 @@
  1.6390  SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo*);
  1.6391  SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoRef(KeyInfo*);
  1.6392  SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse*, Index*);
  1.6393 +SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoFromExprList(Parse*, ExprList*, int, int);
  1.6394 +
  1.6395  #ifdef SQLITE_DEBUG
  1.6396  SQLITE_PRIVATE int sqlite3KeyInfoIsWriteable(KeyInfo*);
  1.6397  #endif
  1.6398  SQLITE_PRIVATE int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *,
  1.6399    void (*)(sqlite3_context*,int,sqlite3_value **),
  1.6400 -  void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*),
  1.6401 +  void (*)(sqlite3_context*,int,sqlite3_value **), 
  1.6402 +  void (*)(sqlite3_context*),
  1.6403 +  void (*)(sqlite3_context*),
  1.6404 +  void (*)(sqlite3_context*,int,sqlite3_value **), 
  1.6405    FuncDestructor *pDestructor
  1.6406  );
  1.6407 +SQLITE_PRIVATE void sqlite3NoopDestructor(void*);
  1.6408  SQLITE_PRIVATE void sqlite3OomFault(sqlite3*);
  1.6409  SQLITE_PRIVATE void sqlite3OomClear(sqlite3*);
  1.6410  SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
  1.6411  SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
  1.6412  
  1.6413  SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
  1.6414 -SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
  1.6415 -SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
  1.6416 -SQLITE_PRIVATE void sqlite3AppendChar(StrAccum*,int,char);
  1.6417  SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
  1.6418 -SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
  1.6419  SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
  1.6420  SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
  1.6421  
  1.6422 @@ -16876,10 +19204,11 @@
  1.6423  ** The interface to the LEMON-generated parser
  1.6424  */
  1.6425  #ifndef SQLITE_AMALGAMATION
  1.6426 -SQLITE_PRIVATE   void *sqlite3ParserAlloc(void*(*)(u64));
  1.6427 +SQLITE_PRIVATE   void *sqlite3ParserAlloc(void*(*)(u64), Parse*);
  1.6428  SQLITE_PRIVATE   void sqlite3ParserFree(void*, void(*)(void*));
  1.6429  #endif
  1.6430 -SQLITE_PRIVATE void sqlite3Parser(void*, int, Token, Parse*);
  1.6431 +SQLITE_PRIVATE void sqlite3Parser(void*, int, Token);
  1.6432 +SQLITE_PRIVATE int sqlite3ParserFallback(int);
  1.6433  #ifdef YYTRACKMAXSTACKDEPTH
  1.6434  SQLITE_PRIVATE   int sqlite3ParserStackPeak(void*);
  1.6435  #endif
  1.6436 @@ -16945,11 +19274,13 @@
  1.6437  SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3*, int, const char *);
  1.6438  SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, VTable *);
  1.6439  SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
  1.6440 -SQLITE_PRIVATE void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
  1.6441  SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
  1.6442  SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
  1.6443  SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
  1.6444  SQLITE_PRIVATE void sqlite3ParserReset(Parse*);
  1.6445 +#ifdef SQLITE_ENABLE_NORMALIZE
  1.6446 +SQLITE_PRIVATE void sqlite3Normalize(Vdbe*, const char*, int, u8);
  1.6447 +#endif
  1.6448  SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
  1.6449  SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*);
  1.6450  SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
  1.6451 @@ -16967,6 +19298,18 @@
  1.6452  #define sqlite3WithPush(x,y,z)
  1.6453  #define sqlite3WithDelete(x,y)
  1.6454  #endif
  1.6455 +#ifndef SQLITE_OMIT_UPSERT
  1.6456 +SQLITE_PRIVATE   Upsert *sqlite3UpsertNew(sqlite3*,ExprList*,Expr*,ExprList*,Expr*);
  1.6457 +SQLITE_PRIVATE   void sqlite3UpsertDelete(sqlite3*,Upsert*);
  1.6458 +SQLITE_PRIVATE   Upsert *sqlite3UpsertDup(sqlite3*,Upsert*);
  1.6459 +SQLITE_PRIVATE   int sqlite3UpsertAnalyzeTarget(Parse*,SrcList*,Upsert*);
  1.6460 +SQLITE_PRIVATE   void sqlite3UpsertDoUpdate(Parse*,Upsert*,Table*,Index*,int);
  1.6461 +#else
  1.6462 +#define sqlite3UpsertNew(v,w,x,y,z) ((Upsert*)0)
  1.6463 +#define sqlite3UpsertDelete(x,y)
  1.6464 +#define sqlite3UpsertDup(x,y)       ((Upsert*)0)
  1.6465 +#endif
  1.6466 +
  1.6467  
  1.6468  /* Declarations for functions in fkey.c. All of these are replaced by
  1.6469  ** no-op macros if OMIT_FOREIGN_KEY is defined. In this case no foreign
  1.6470 @@ -17036,7 +19379,8 @@
  1.6471  
  1.6472  SQLITE_PRIVATE int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
  1.6473  SQLITE_PRIVATE int sqlite3JournalSize(sqlite3_vfs *);
  1.6474 -#ifdef SQLITE_ENABLE_ATOMIC_WRITE
  1.6475 +#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
  1.6476 + || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
  1.6477  SQLITE_PRIVATE   int sqlite3JournalCreate(sqlite3_file *);
  1.6478  #endif
  1.6479  
  1.6480 @@ -17068,6 +19412,9 @@
  1.6481  #ifdef SQLITE_DEBUG
  1.6482  SQLITE_PRIVATE   void sqlite3ParserTrace(FILE*, char *);
  1.6483  #endif
  1.6484 +#if defined(YYCOVERAGE)
  1.6485 +SQLITE_PRIVATE   int sqlite3ParserCoverage(FILE*);
  1.6486 +#endif
  1.6487  
  1.6488  /*
  1.6489  ** If the SQLITE_ENABLE IOTRACE exists then the global variable
  1.6490 @@ -17122,8 +19469,7 @@
  1.6491  #endif
  1.6492  #define MEMTYPE_HEAP       0x01  /* General heap allocations */
  1.6493  #define MEMTYPE_LOOKASIDE  0x02  /* Heap that might have been lookaside */
  1.6494 -#define MEMTYPE_SCRATCH    0x04  /* Scratch allocations */
  1.6495 -#define MEMTYPE_PCACHE     0x08  /* Page cache allocations */
  1.6496 +#define MEMTYPE_PCACHE     0x04  /* Page cache allocations */
  1.6497  
  1.6498  /*
  1.6499  ** Threading interface
  1.6500 @@ -17133,6 +19479,9 @@
  1.6501  SQLITE_PRIVATE int sqlite3ThreadJoin(SQLiteThread*, void**);
  1.6502  #endif
  1.6503  
  1.6504 +#if defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)
  1.6505 +SQLITE_PRIVATE int sqlite3DbpageRegister(sqlite3*);
  1.6506 +#endif
  1.6507  #if defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)
  1.6508  SQLITE_PRIVATE int sqlite3DbstatRegister(sqlite3*);
  1.6509  #endif
  1.6510 @@ -17143,6 +19492,10 @@
  1.6511  SQLITE_PRIVATE Expr *sqlite3ExprForVectorField(Parse*,Expr*,int);
  1.6512  SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse*, Expr*);
  1.6513  
  1.6514 +#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
  1.6515 +SQLITE_PRIVATE const char **sqlite3CompileOptions(int *pnOpt);
  1.6516 +#endif
  1.6517 +
  1.6518  #endif /* SQLITEINT_H */
  1.6519  
  1.6520  /************** End of sqliteInt.h *******************************************/
  1.6521 @@ -17348,6 +19701,7 @@
  1.6522     SQLITE_THREADSAFE==1,      /* bFullMutex */
  1.6523     SQLITE_USE_URI,            /* bOpenUri */
  1.6524     SQLITE_ALLOW_COVERING_INDEX_SCAN,   /* bUseCis */
  1.6525 +   0,                         /* bSmallMalloc */
  1.6526     0x7ffffffe,                /* mxStrlen */
  1.6527     0,                         /* neverCorrupt */
  1.6528     SQLITE_DEFAULT_LOOKASIDE,  /* szLookaside, nLookaside */
  1.6529 @@ -17360,9 +19714,6 @@
  1.6530     0, 0,                      /* mnHeap, mxHeap */
  1.6531     SQLITE_DEFAULT_MMAP_SIZE,  /* szMmap */
  1.6532     SQLITE_MAX_MMAP_SIZE,      /* mxMmap */
  1.6533 -   (void*)0,                  /* pScratch */
  1.6534 -   0,                         /* szScratch */
  1.6535 -   0,                         /* nScratch */
  1.6536     (void*)0,                  /* pPage */
  1.6537     0,                         /* szPage */
  1.6538     SQLITE_DEFAULT_PCACHE_INITSZ, /* nPage */
  1.6539 @@ -17391,7 +19742,9 @@
  1.6540     0,                         /* xTestCallback */
  1.6541  #endif
  1.6542     0,                         /* bLocaltimeFault */
  1.6543 -   0x7ffffffe                 /* iOnceResetThreshold */
  1.6544 +   0,                         /* bInternalFunctions */
  1.6545 +   0x7ffffffe,                /* iOnceResetThreshold */
  1.6546 +   SQLITE_DEFAULT_SORTERREF_SIZE   /* szSorterRef */
  1.6547  };
  1.6548  
  1.6549  /*
  1.6550 @@ -17409,6 +19762,13 @@
  1.6551     { "1", 1 }
  1.6552  };
  1.6553  
  1.6554 +#ifdef VDBE_PROFILE
  1.6555 +/*
  1.6556 +** The following performance counter can be used in place of
  1.6557 +** sqlite3Hwtime() for profiling.  This is a no-op on standard builds.
  1.6558 +*/
  1.6559 +SQLITE_PRIVATE sqlite3_uint64 sqlite3NProfileCnt = 0;
  1.6560 +#endif
  1.6561  
  1.6562  /*
  1.6563  ** The value of the "pending" byte must be 0x40000000 (1 byte past the
  1.6564 @@ -17447,472 +19807,6 @@
  1.6565  SQLITE_PRIVATE const char sqlite3StrBINARY[] = "BINARY";
  1.6566  
  1.6567  /************** End of global.c **********************************************/
  1.6568 -/************** Begin file ctime.c *******************************************/
  1.6569 -/*
  1.6570 -** 2010 February 23
  1.6571 -**
  1.6572 -** The author disclaims copyright to this source code.  In place of
  1.6573 -** a legal notice, here is a blessing:
  1.6574 -**
  1.6575 -**    May you do good and not evil.
  1.6576 -**    May you find forgiveness for yourself and forgive others.
  1.6577 -**    May you share freely, never taking more than you give.
  1.6578 -**
  1.6579 -*************************************************************************
  1.6580 -**
  1.6581 -** This file implements routines used to report what compile-time options
  1.6582 -** SQLite was built with.
  1.6583 -*/
  1.6584 -
  1.6585 -#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
  1.6586 -
  1.6587 -/* #include "sqliteInt.h" */
  1.6588 -
  1.6589 -/*
  1.6590 -** An array of names of all compile-time options.  This array should 
  1.6591 -** be sorted A-Z.
  1.6592 -**
  1.6593 -** This array looks large, but in a typical installation actually uses
  1.6594 -** only a handful of compile-time options, so most times this array is usually
  1.6595 -** rather short and uses little memory space.
  1.6596 -*/
  1.6597 -static const char * const azCompileOpt[] = {
  1.6598 -
  1.6599 -/* These macros are provided to "stringify" the value of the define
  1.6600 -** for those options in which the value is meaningful. */
  1.6601 -#define CTIMEOPT_VAL_(opt) #opt
  1.6602 -#define CTIMEOPT_VAL(opt) CTIMEOPT_VAL_(opt)
  1.6603 -
  1.6604 -#if SQLITE_32BIT_ROWID
  1.6605 -  "32BIT_ROWID",
  1.6606 -#endif
  1.6607 -#if SQLITE_4_BYTE_ALIGNED_MALLOC
  1.6608 -  "4_BYTE_ALIGNED_MALLOC",
  1.6609 -#endif
  1.6610 -#if SQLITE_CASE_SENSITIVE_LIKE
  1.6611 -  "CASE_SENSITIVE_LIKE",
  1.6612 -#endif
  1.6613 -#if SQLITE_CHECK_PAGES
  1.6614 -  "CHECK_PAGES",
  1.6615 -#endif
  1.6616 -#if defined(__clang__) && defined(__clang_major__)
  1.6617 -  "COMPILER=clang-" CTIMEOPT_VAL(__clang_major__) "."
  1.6618 -                    CTIMEOPT_VAL(__clang_minor__) "."
  1.6619 -                    CTIMEOPT_VAL(__clang_patchlevel__),
  1.6620 -#elif defined(_MSC_VER)
  1.6621 -  "COMPILER=msvc-" CTIMEOPT_VAL(_MSC_VER),
  1.6622 -#elif defined(__GNUC__) && defined(__VERSION__)
  1.6623 -  "COMPILER=gcc-" __VERSION__,
  1.6624 -#endif
  1.6625 -#if SQLITE_COVERAGE_TEST
  1.6626 -  "COVERAGE_TEST",
  1.6627 -#endif
  1.6628 -#ifdef SQLITE_DEBUG
  1.6629 -  "DEBUG",
  1.6630 -#endif
  1.6631 -#if SQLITE_DEFAULT_LOCKING_MODE
  1.6632 -  "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE),
  1.6633 -#endif
  1.6634 -#if defined(SQLITE_DEFAULT_MMAP_SIZE) && !defined(SQLITE_DEFAULT_MMAP_SIZE_xc)
  1.6635 -  "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE),
  1.6636 -#endif
  1.6637 -#if SQLITE_DEFAULT_SYNCHRONOUS
  1.6638 -  "DEFAULT_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_SYNCHRONOUS),
  1.6639 -#endif
  1.6640 -#if SQLITE_DEFAULT_WAL_SYNCHRONOUS
  1.6641 -  "DEFAULT_WAL_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_WAL_SYNCHRONOUS),
  1.6642 -#endif
  1.6643 -#if SQLITE_DIRECT_OVERFLOW_READ
  1.6644 -  "DIRECT_OVERFLOW_READ",
  1.6645 -#endif
  1.6646 -#if SQLITE_DISABLE_DIRSYNC
  1.6647 -  "DISABLE_DIRSYNC",
  1.6648 -#endif
  1.6649 -#if SQLITE_DISABLE_LFS
  1.6650 -  "DISABLE_LFS",
  1.6651 -#endif
  1.6652 -#if SQLITE_ENABLE_8_3_NAMES
  1.6653 -  "ENABLE_8_3_NAMES=" CTIMEOPT_VAL(SQLITE_ENABLE_8_3_NAMES),
  1.6654 -#endif
  1.6655 -#if SQLITE_ENABLE_API_ARMOR
  1.6656 -  "ENABLE_API_ARMOR",
  1.6657 -#endif
  1.6658 -#if SQLITE_ENABLE_ATOMIC_WRITE
  1.6659 -  "ENABLE_ATOMIC_WRITE",
  1.6660 -#endif
  1.6661 -#if SQLITE_ENABLE_CEROD
  1.6662 -  "ENABLE_CEROD",
  1.6663 -#endif
  1.6664 -#if SQLITE_ENABLE_COLUMN_METADATA
  1.6665 -  "ENABLE_COLUMN_METADATA",
  1.6666 -#endif
  1.6667 -#if SQLITE_ENABLE_DBSTAT_VTAB
  1.6668 -  "ENABLE_DBSTAT_VTAB",
  1.6669 -#endif
  1.6670 -#if SQLITE_ENABLE_EXPENSIVE_ASSERT
  1.6671 -  "ENABLE_EXPENSIVE_ASSERT",
  1.6672 -#endif
  1.6673 -#if SQLITE_ENABLE_FTS1
  1.6674 -  "ENABLE_FTS1",
  1.6675 -#endif
  1.6676 -#if SQLITE_ENABLE_FTS2
  1.6677 -  "ENABLE_FTS2",
  1.6678 -#endif
  1.6679 -#if SQLITE_ENABLE_FTS3
  1.6680 -  "ENABLE_FTS3",
  1.6681 -#endif
  1.6682 -#if SQLITE_ENABLE_FTS3_PARENTHESIS
  1.6683 -  "ENABLE_FTS3_PARENTHESIS",
  1.6684 -#endif
  1.6685 -#if SQLITE_ENABLE_FTS4
  1.6686 -  "ENABLE_FTS4",
  1.6687 -#endif
  1.6688 -#if SQLITE_ENABLE_FTS5
  1.6689 -  "ENABLE_FTS5",
  1.6690 -#endif
  1.6691 -#if SQLITE_ENABLE_ICU
  1.6692 -  "ENABLE_ICU",
  1.6693 -#endif
  1.6694 -#if SQLITE_ENABLE_IOTRACE
  1.6695 -  "ENABLE_IOTRACE",
  1.6696 -#endif
  1.6697 -#if SQLITE_ENABLE_JSON1
  1.6698 -  "ENABLE_JSON1",
  1.6699 -#endif
  1.6700 -#if SQLITE_ENABLE_LOAD_EXTENSION
  1.6701 -  "ENABLE_LOAD_EXTENSION",
  1.6702 -#endif
  1.6703 -#if SQLITE_ENABLE_LOCKING_STYLE
  1.6704 -  "ENABLE_LOCKING_STYLE=" CTIMEOPT_VAL(SQLITE_ENABLE_LOCKING_STYLE),
  1.6705 -#endif
  1.6706 -#if SQLITE_ENABLE_MEMORY_MANAGEMENT
  1.6707 -  "ENABLE_MEMORY_MANAGEMENT",
  1.6708 -#endif
  1.6709 -#if SQLITE_ENABLE_MEMSYS3
  1.6710 -  "ENABLE_MEMSYS3",
  1.6711 -#endif
  1.6712 -#if SQLITE_ENABLE_MEMSYS5
  1.6713 -  "ENABLE_MEMSYS5",
  1.6714 -#endif
  1.6715 -#if SQLITE_ENABLE_OVERSIZE_CELL_CHECK
  1.6716 -  "ENABLE_OVERSIZE_CELL_CHECK",
  1.6717 -#endif
  1.6718 -#if SQLITE_ENABLE_RTREE
  1.6719 -  "ENABLE_RTREE",
  1.6720 -#endif
  1.6721 -#if defined(SQLITE_ENABLE_STAT4)
  1.6722 -  "ENABLE_STAT4",
  1.6723 -#elif defined(SQLITE_ENABLE_STAT3)
  1.6724 -  "ENABLE_STAT3",
  1.6725 -#endif
  1.6726 -#if SQLITE_ENABLE_UNLOCK_NOTIFY
  1.6727 -  "ENABLE_UNLOCK_NOTIFY",
  1.6728 -#endif
  1.6729 -#if SQLITE_ENABLE_UPDATE_DELETE_LIMIT
  1.6730 -  "ENABLE_UPDATE_DELETE_LIMIT",
  1.6731 -#endif
  1.6732 -#if defined(SQLITE_ENABLE_URI_00_ERROR)
  1.6733 -  "ENABLE_URI_00_ERROR",
  1.6734 -#endif
  1.6735 -#if SQLITE_HAS_CODEC
  1.6736 -  "HAS_CODEC",
  1.6737 -#endif
  1.6738 -#if HAVE_ISNAN || SQLITE_HAVE_ISNAN
  1.6739 -  "HAVE_ISNAN",
  1.6740 -#endif
  1.6741 -#if SQLITE_HOMEGROWN_RECURSIVE_MUTEX
  1.6742 -  "HOMEGROWN_RECURSIVE_MUTEX",
  1.6743 -#endif
  1.6744 -#if SQLITE_IGNORE_AFP_LOCK_ERRORS
  1.6745 -  "IGNORE_AFP_LOCK_ERRORS",
  1.6746 -#endif
  1.6747 -#if SQLITE_IGNORE_FLOCK_LOCK_ERRORS
  1.6748 -  "IGNORE_FLOCK_LOCK_ERRORS",
  1.6749 -#endif
  1.6750 -#ifdef SQLITE_INT64_TYPE
  1.6751 -  "INT64_TYPE",
  1.6752 -#endif
  1.6753 -#ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS
  1.6754 -  "LIKE_DOESNT_MATCH_BLOBS",
  1.6755 -#endif
  1.6756 -#if SQLITE_LOCK_TRACE
  1.6757 -  "LOCK_TRACE",
  1.6758 -#endif
  1.6759 -#if defined(SQLITE_MAX_MMAP_SIZE) && !defined(SQLITE_MAX_MMAP_SIZE_xc)
  1.6760 -  "MAX_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE),
  1.6761 -#endif
  1.6762 -#ifdef SQLITE_MAX_SCHEMA_RETRY
  1.6763 -  "MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY),
  1.6764 -#endif
  1.6765 -#if SQLITE_MEMDEBUG
  1.6766 -  "MEMDEBUG",
  1.6767 -#endif
  1.6768 -#if SQLITE_MIXED_ENDIAN_64BIT_FLOAT
  1.6769 -  "MIXED_ENDIAN_64BIT_FLOAT",
  1.6770 -#endif
  1.6771 -#if SQLITE_NO_SYNC
  1.6772 -  "NO_SYNC",
  1.6773 -#endif
  1.6774 -#if SQLITE_OMIT_ALTERTABLE
  1.6775 -  "OMIT_ALTERTABLE",
  1.6776 -#endif
  1.6777 -#if SQLITE_OMIT_ANALYZE
  1.6778 -  "OMIT_ANALYZE",
  1.6779 -#endif
  1.6780 -#if SQLITE_OMIT_ATTACH
  1.6781 -  "OMIT_ATTACH",
  1.6782 -#endif
  1.6783 -#if SQLITE_OMIT_AUTHORIZATION
  1.6784 -  "OMIT_AUTHORIZATION",
  1.6785 -#endif
  1.6786 -#if SQLITE_OMIT_AUTOINCREMENT
  1.6787 -  "OMIT_AUTOINCREMENT",
  1.6788 -#endif
  1.6789 -#if SQLITE_OMIT_AUTOINIT
  1.6790 -  "OMIT_AUTOINIT",
  1.6791 -#endif
  1.6792 -#if SQLITE_OMIT_AUTOMATIC_INDEX
  1.6793 -  "OMIT_AUTOMATIC_INDEX",
  1.6794 -#endif
  1.6795 -#if SQLITE_OMIT_AUTORESET
  1.6796 -  "OMIT_AUTORESET",
  1.6797 -#endif
  1.6798 -#if SQLITE_OMIT_AUTOVACUUM
  1.6799 -  "OMIT_AUTOVACUUM",
  1.6800 -#endif
  1.6801 -#if SQLITE_OMIT_BETWEEN_OPTIMIZATION
  1.6802 -  "OMIT_BETWEEN_OPTIMIZATION",
  1.6803 -#endif
  1.6804 -#if SQLITE_OMIT_BLOB_LITERAL
  1.6805 -  "OMIT_BLOB_LITERAL",
  1.6806 -#endif
  1.6807 -#if SQLITE_OMIT_BTREECOUNT
  1.6808 -  "OMIT_BTREECOUNT",
  1.6809 -#endif
  1.6810 -#if SQLITE_OMIT_CAST
  1.6811 -  "OMIT_CAST",
  1.6812 -#endif
  1.6813 -#if SQLITE_OMIT_CHECK
  1.6814 -  "OMIT_CHECK",
  1.6815 -#endif
  1.6816 -#if SQLITE_OMIT_COMPLETE
  1.6817 -  "OMIT_COMPLETE",
  1.6818 -#endif
  1.6819 -#if SQLITE_OMIT_COMPOUND_SELECT
  1.6820 -  "OMIT_COMPOUND_SELECT",
  1.6821 -#endif
  1.6822 -#if SQLITE_OMIT_CTE
  1.6823 -  "OMIT_CTE",
  1.6824 -#endif
  1.6825 -#if SQLITE_OMIT_DATETIME_FUNCS
  1.6826 -  "OMIT_DATETIME_FUNCS",
  1.6827 -#endif
  1.6828 -#if SQLITE_OMIT_DECLTYPE
  1.6829 -  "OMIT_DECLTYPE",
  1.6830 -#endif
  1.6831 -#if SQLITE_OMIT_DEPRECATED
  1.6832 -  "OMIT_DEPRECATED",
  1.6833 -#endif
  1.6834 -#if SQLITE_OMIT_DISKIO
  1.6835 -  "OMIT_DISKIO",
  1.6836 -#endif
  1.6837 -#if SQLITE_OMIT_EXPLAIN
  1.6838 -  "OMIT_EXPLAIN",
  1.6839 -#endif
  1.6840 -#if SQLITE_OMIT_FLAG_PRAGMAS
  1.6841 -  "OMIT_FLAG_PRAGMAS",
  1.6842 -#endif
  1.6843 -#if SQLITE_OMIT_FLOATING_POINT
  1.6844 -  "OMIT_FLOATING_POINT",
  1.6845 -#endif
  1.6846 -#if SQLITE_OMIT_FOREIGN_KEY
  1.6847 -  "OMIT_FOREIGN_KEY",
  1.6848 -#endif
  1.6849 -#if SQLITE_OMIT_GET_TABLE
  1.6850 -  "OMIT_GET_TABLE",
  1.6851 -#endif
  1.6852 -#if SQLITE_OMIT_INCRBLOB
  1.6853 -  "OMIT_INCRBLOB",
  1.6854 -#endif
  1.6855 -#if SQLITE_OMIT_INTEGRITY_CHECK
  1.6856 -  "OMIT_INTEGRITY_CHECK",
  1.6857 -#endif
  1.6858 -#if SQLITE_OMIT_LIKE_OPTIMIZATION
  1.6859 -  "OMIT_LIKE_OPTIMIZATION",
  1.6860 -#endif
  1.6861 -#if SQLITE_OMIT_LOAD_EXTENSION
  1.6862 -  "OMIT_LOAD_EXTENSION",
  1.6863 -#endif
  1.6864 -#if SQLITE_OMIT_LOCALTIME
  1.6865 -  "OMIT_LOCALTIME",
  1.6866 -#endif
  1.6867 -#if SQLITE_OMIT_LOOKASIDE
  1.6868 -  "OMIT_LOOKASIDE",
  1.6869 -#endif
  1.6870 -#if SQLITE_OMIT_MEMORYDB
  1.6871 -  "OMIT_MEMORYDB",
  1.6872 -#endif
  1.6873 -#if SQLITE_OMIT_OR_OPTIMIZATION
  1.6874 -  "OMIT_OR_OPTIMIZATION",
  1.6875 -#endif
  1.6876 -#if SQLITE_OMIT_PAGER_PRAGMAS
  1.6877 -  "OMIT_PAGER_PRAGMAS",
  1.6878 -#endif
  1.6879 -#if SQLITE_OMIT_PRAGMA
  1.6880 -  "OMIT_PRAGMA",
  1.6881 -#endif
  1.6882 -#if SQLITE_OMIT_PROGRESS_CALLBACK
  1.6883 -  "OMIT_PROGRESS_CALLBACK",
  1.6884 -#endif
  1.6885 -#if SQLITE_OMIT_QUICKBALANCE
  1.6886 -  "OMIT_QUICKBALANCE",
  1.6887 -#endif
  1.6888 -#if SQLITE_OMIT_REINDEX
  1.6889 -  "OMIT_REINDEX",
  1.6890 -#endif
  1.6891 -#if SQLITE_OMIT_SCHEMA_PRAGMAS
  1.6892 -  "OMIT_SCHEMA_PRAGMAS",
  1.6893 -#endif
  1.6894 -#if SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
  1.6895 -  "OMIT_SCHEMA_VERSION_PRAGMAS",
  1.6896 -#endif
  1.6897 -#if SQLITE_OMIT_SHARED_CACHE
  1.6898 -  "OMIT_SHARED_CACHE",
  1.6899 -#endif
  1.6900 -#if SQLITE_OMIT_SUBQUERY
  1.6901 -  "OMIT_SUBQUERY",
  1.6902 -#endif
  1.6903 -#if SQLITE_OMIT_TCL_VARIABLE
  1.6904 -  "OMIT_TCL_VARIABLE",
  1.6905 -#endif
  1.6906 -#if SQLITE_OMIT_TEMPDB
  1.6907 -  "OMIT_TEMPDB",
  1.6908 -#endif
  1.6909 -#if SQLITE_OMIT_TRACE
  1.6910 -  "OMIT_TRACE",
  1.6911 -#endif
  1.6912 -#if SQLITE_OMIT_TRIGGER
  1.6913 -  "OMIT_TRIGGER",
  1.6914 -#endif
  1.6915 -#if SQLITE_OMIT_TRUNCATE_OPTIMIZATION
  1.6916 -  "OMIT_TRUNCATE_OPTIMIZATION",
  1.6917 -#endif
  1.6918 -#if SQLITE_OMIT_UTF16
  1.6919 -  "OMIT_UTF16",
  1.6920 -#endif
  1.6921 -#if SQLITE_OMIT_VACUUM
  1.6922 -  "OMIT_VACUUM",
  1.6923 -#endif
  1.6924 -#if SQLITE_OMIT_VIEW
  1.6925 -  "OMIT_VIEW",
  1.6926 -#endif
  1.6927 -#if SQLITE_OMIT_VIRTUALTABLE
  1.6928 -  "OMIT_VIRTUALTABLE",
  1.6929 -#endif
  1.6930 -#if SQLITE_OMIT_WAL
  1.6931 -  "OMIT_WAL",
  1.6932 -#endif
  1.6933 -#if SQLITE_OMIT_WSD
  1.6934 -  "OMIT_WSD",
  1.6935 -#endif
  1.6936 -#if SQLITE_OMIT_XFER_OPT
  1.6937 -  "OMIT_XFER_OPT",
  1.6938 -#endif
  1.6939 -#if SQLITE_PERFORMANCE_TRACE
  1.6940 -  "PERFORMANCE_TRACE",
  1.6941 -#endif
  1.6942 -#if SQLITE_PROXY_DEBUG
  1.6943 -  "PROXY_DEBUG",
  1.6944 -#endif
  1.6945 -#if SQLITE_RTREE_INT_ONLY
  1.6946 -  "RTREE_INT_ONLY",
  1.6947 -#endif
  1.6948 -#if SQLITE_SECURE_DELETE
  1.6949 -  "SECURE_DELETE",
  1.6950 -#endif
  1.6951 -#if SQLITE_SMALL_STACK
  1.6952 -  "SMALL_STACK",
  1.6953 -#endif
  1.6954 -#if SQLITE_SOUNDEX
  1.6955 -  "SOUNDEX",
  1.6956 -#endif
  1.6957 -#if SQLITE_SYSTEM_MALLOC
  1.6958 -  "SYSTEM_MALLOC",
  1.6959 -#endif
  1.6960 -#if SQLITE_TCL
  1.6961 -  "TCL",
  1.6962 -#endif
  1.6963 -#if defined(SQLITE_TEMP_STORE) && !defined(SQLITE_TEMP_STORE_xc)
  1.6964 -  "TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE),
  1.6965 -#endif
  1.6966 -#if SQLITE_TEST
  1.6967 -  "TEST",
  1.6968 -#endif
  1.6969 -#if defined(SQLITE_THREADSAFE)
  1.6970 -  "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
  1.6971 -#endif
  1.6972 -#if SQLITE_UNTESTABLE
  1.6973 -  "UNTESTABLE"
  1.6974 -#endif
  1.6975 -#if SQLITE_USE_ALLOCA
  1.6976 -  "USE_ALLOCA",
  1.6977 -#endif
  1.6978 -#if SQLITE_USER_AUTHENTICATION
  1.6979 -  "USER_AUTHENTICATION",
  1.6980 -#endif
  1.6981 -#if SQLITE_WIN32_MALLOC
  1.6982 -  "WIN32_MALLOC",
  1.6983 -#endif
  1.6984 -#if SQLITE_ZERO_MALLOC
  1.6985 -  "ZERO_MALLOC"
  1.6986 -#endif
  1.6987 -};
  1.6988 -
  1.6989 -/*
  1.6990 -** Given the name of a compile-time option, return true if that option
  1.6991 -** was used and false if not.
  1.6992 -**
  1.6993 -** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix
  1.6994 -** is not required for a match.
  1.6995 -*/
  1.6996 -SQLITE_API int sqlite3_compileoption_used(const char *zOptName){
  1.6997 -  int i, n;
  1.6998 -
  1.6999 -#if SQLITE_ENABLE_API_ARMOR
  1.7000 -  if( zOptName==0 ){
  1.7001 -    (void)SQLITE_MISUSE_BKPT;
  1.7002 -    return 0;
  1.7003 -  }
  1.7004 -#endif
  1.7005 -  if( sqlite3StrNICmp(zOptName, "SQLITE_", 7)==0 ) zOptName += 7;
  1.7006 -  n = sqlite3Strlen30(zOptName);
  1.7007 -
  1.7008 -  /* Since ArraySize(azCompileOpt) is normally in single digits, a
  1.7009 -  ** linear search is adequate.  No need for a binary search. */
  1.7010 -  for(i=0; i<ArraySize(azCompileOpt); i++){
  1.7011 -    if( sqlite3StrNICmp(zOptName, azCompileOpt[i], n)==0
  1.7012 -     && sqlite3IsIdChar((unsigned char)azCompileOpt[i][n])==0
  1.7013 -    ){
  1.7014 -      return 1;
  1.7015 -    }
  1.7016 -  }
  1.7017 -  return 0;
  1.7018 -}
  1.7019 -
  1.7020 -/*
  1.7021 -** Return the N-th compile-time option string.  If N is out of range,
  1.7022 -** return a NULL pointer.
  1.7023 -*/
  1.7024 -SQLITE_API const char *sqlite3_compileoption_get(int N){
  1.7025 -  if( N>=0 && N<ArraySize(azCompileOpt) ){
  1.7026 -    return azCompileOpt[N];
  1.7027 -  }
  1.7028 -  return 0;
  1.7029 -}
  1.7030 -
  1.7031 -#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
  1.7032 -
  1.7033 -/************** End of ctime.c ***********************************************/
  1.7034  /************** Begin file status.c ******************************************/
  1.7035  /*
  1.7036  ** 2008 June 18
  1.7037 @@ -18019,6 +19913,7 @@
  1.7038    Bool isEphemeral:1;     /* True for an ephemeral table */
  1.7039    Bool useRandomRowid:1;  /* Generate new record numbers semi-randomly */
  1.7040    Bool isOrdered:1;       /* True if the table is not BTREE_UNORDERED */
  1.7041 +  Bool seekHit:1;         /* See the OP_SeekHit and OP_IfNoHope opcodes */
  1.7042    Btree *pBtx;            /* Separate file holding temporary table */
  1.7043    i64 seqCount;           /* Sequence counter */
  1.7044    int *aAltMap;           /* Mapping from table to index column numbers */
  1.7045 @@ -18030,18 +19925,18 @@
  1.7046    u32 cacheStatus;        /* Cache is valid if this matches Vdbe.cacheCtr */
  1.7047    int seekResult;         /* Result of previous sqlite3BtreeMoveto() or 0
  1.7048                            ** if there have been no prior seeks on the cursor. */
  1.7049 -  /* NB: seekResult does not distinguish between "no seeks have ever occurred
  1.7050 -  ** on this cursor" and "the most recent seek was an exact match". */
  1.7051 +  /* seekResult does not distinguish between "no seeks have ever occurred
  1.7052 +  ** on this cursor" and "the most recent seek was an exact match".
  1.7053 +  ** For CURTYPE_PSEUDO, seekResult is the register holding the record */
  1.7054  
  1.7055    /* When a new VdbeCursor is allocated, only the fields above are zeroed.
  1.7056    ** The fields that follow are uninitialized, and must be individually
  1.7057    ** initialized prior to first use. */
  1.7058    VdbeCursor *pAltCursor; /* Associated index cursor from which to read */
  1.7059    union {
  1.7060 -    BtCursor *pCursor;          /* CURTYPE_BTREE.  Btree cursor */
  1.7061 -    sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB.   Vtab cursor */
  1.7062 -    int pseudoTableReg;         /* CURTYPE_PSEUDO. Reg holding content. */
  1.7063 -    VdbeSorter *pSorter;        /* CURTYPE_SORTER. Sorter object */
  1.7064 +    BtCursor *pCursor;          /* CURTYPE_BTREE or _PSEUDO.  Btree cursor */
  1.7065 +    sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB.              Vtab cursor */
  1.7066 +    VdbeSorter *pSorter;        /* CURTYPE_SORTER.            Sorter object */
  1.7067    } uc;
  1.7068    KeyInfo *pKeyInfo;      /* Info about index keys needed by index cursors */
  1.7069    u32 iHdrOffset;         /* Offset to next unparsed byte of the header */
  1.7070 @@ -18102,6 +19997,9 @@
  1.7071    void *token;            /* Copy of SubProgram.token */
  1.7072    i64 lastRowid;          /* Last insert rowid (sqlite3.lastRowid) */
  1.7073    AuxData *pAuxData;      /* Linked list of auxdata allocations */
  1.7074 +#if SQLITE_DEBUG
  1.7075 +  u32 iFrameMagic;        /* magic number for sanity checking */
  1.7076 +#endif
  1.7077    int nCursor;            /* Number of entries in apCsr */
  1.7078    int pc;                 /* Program Counter in parent (calling) frame */
  1.7079    int nOp;                /* Size of aOp array */
  1.7080 @@ -18112,6 +20010,13 @@
  1.7081    int nDbChange;          /* Value of db->nChange */
  1.7082  };
  1.7083  
  1.7084 +/* Magic number for sanity checking on VdbeFrame objects */
  1.7085 +#define SQLITE_FRAME_MAGIC 0x879fb71e
  1.7086 +
  1.7087 +/*
  1.7088 +** Return a pointer to the array of registers allocated for use
  1.7089 +** by a VdbeFrame.
  1.7090 +*/
  1.7091  #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
  1.7092  
  1.7093  /*
  1.7094 @@ -18123,10 +20028,9 @@
  1.7095    union MemValue {
  1.7096      double r;           /* Real value used when MEM_Real is set in flags */
  1.7097      i64 i;              /* Integer value used when MEM_Int is set in flags */
  1.7098 -    int nZero;          /* Used when bit MEM_Zero is set in flags */
  1.7099 +    int nZero;          /* Extra zero bytes when MEM_Zero and MEM_Blob set */
  1.7100 +    const char *zPType; /* Pointer type when MEM_Term|MEM_Subtype|MEM_Null */
  1.7101      FuncDef *pDef;      /* Used only when flags==MEM_Agg */
  1.7102 -    RowSet *pRowSet;    /* Used only when flags==MEM_RowSet */
  1.7103 -    VdbeFrame *pFrame;  /* Used when flags==MEM_Frame */
  1.7104    } u;
  1.7105    u16 flags;          /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
  1.7106    u8  enc;            /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
  1.7107 @@ -18141,7 +20045,7 @@
  1.7108    void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
  1.7109  #ifdef SQLITE_DEBUG
  1.7110    Mem *pScopyFrom;    /* This Mem is a shallow copy of pScopyFrom */
  1.7111 -  void *pFiller;      /* So that sizeof(Mem) is a multiple of 8 */
  1.7112 +  u16 mScopyFlags;    /* flags value immediately after the shallow copy */
  1.7113  #endif
  1.7114  };
  1.7115  
  1.7116 @@ -18155,7 +20059,8 @@
  1.7117  ** representations of the value stored in the Mem struct.
  1.7118  **
  1.7119  ** If the MEM_Null flag is set, then the value is an SQL NULL value.
  1.7120 -** No other flags may be set in this case.
  1.7121 +** For a pointer type created using sqlite3_bind_pointer() or
  1.7122 +** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set.
  1.7123  **
  1.7124  ** If the MEM_Str flag is set then Mem.z points at a string representation.
  1.7125  ** Usually this is encoded in the same unicode encoding as the main
  1.7126 @@ -18163,17 +20068,17 @@
  1.7127  ** set, then the string is nul terminated. The MEM_Int and MEM_Real 
  1.7128  ** flags may coexist with the MEM_Str flag.
  1.7129  */
  1.7130 -#define MEM_Null      0x0001   /* Value is NULL */
  1.7131 +#define MEM_Null      0x0001   /* Value is NULL (or a pointer) */
  1.7132  #define MEM_Str       0x0002   /* Value is a string */
  1.7133  #define MEM_Int       0x0004   /* Value is an integer */
  1.7134  #define MEM_Real      0x0008   /* Value is a real number */
  1.7135  #define MEM_Blob      0x0010   /* Value is a BLOB */
  1.7136  #define MEM_AffMask   0x001f   /* Mask of affinity bits */
  1.7137 -#define MEM_RowSet    0x0020   /* Value is a RowSet object */
  1.7138 -#define MEM_Frame     0x0040   /* Value is a VdbeFrame object */
  1.7139 +/* Available          0x0020   */
  1.7140 +/* Available          0x0040   */
  1.7141  #define MEM_Undefined 0x0080   /* Value is undefined */
  1.7142  #define MEM_Cleared   0x0100   /* NULL set by OP_Null, not from data */
  1.7143 -#define MEM_TypeMask  0x81ff   /* Mask of type bits */
  1.7144 +#define MEM_TypeMask  0xc1ff   /* Mask of type bits */
  1.7145  
  1.7146  
  1.7147  /* Whenever Mem contains a valid string or blob representation, one of
  1.7148 @@ -18181,7 +20086,7 @@
  1.7149  ** policy for Mem.z.  The MEM_Term flag tells us whether or not the
  1.7150  ** string is \000 or \u0000 terminated
  1.7151  */
  1.7152 -#define MEM_Term      0x0200   /* String rep is nul terminated */
  1.7153 +#define MEM_Term      0x0200   /* String in Mem.z is zero terminated */
  1.7154  #define MEM_Dyn       0x0400   /* Need to call Mem.xDel() on Mem.z */
  1.7155  #define MEM_Static    0x0800   /* Mem.z points to a static string */
  1.7156  #define MEM_Ephem     0x1000   /* Mem.z points to an ephemeral string */
  1.7157 @@ -18197,7 +20102,7 @@
  1.7158  ** that needs to be deallocated to avoid a leak.
  1.7159  */
  1.7160  #define VdbeMemDynamic(X)  \
  1.7161 -  (((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame))!=0)
  1.7162 +  (((X)->flags&(MEM_Agg|MEM_Dyn))!=0)
  1.7163  
  1.7164  /*
  1.7165  ** Clear any existing type flags from a Mem and replace them with f
  1.7166 @@ -18249,7 +20154,6 @@
  1.7167    int iOp;                /* Instruction number of OP_Function */
  1.7168    int isError;            /* Error code returned by the function. */
  1.7169    u8 skipFlag;            /* Skip accumulator loading if true */
  1.7170 -  u8 fErrorOrAux;         /* isError!=0 or pVdbe->pAuxData modified */
  1.7171    u8 argc;                /* Number of arguments */
  1.7172    sqlite3_value *argv[1]; /* Argument set */
  1.7173  };
  1.7174 @@ -18312,23 +20216,27 @@
  1.7175    int nOp;                /* Number of instructions in the program */
  1.7176  #ifdef SQLITE_DEBUG
  1.7177    int rcApp;              /* errcode set by sqlite3_result_error_code() */
  1.7178 +  u32 nWrite;             /* Number of write operations that have occurred */
  1.7179  #endif
  1.7180    u16 nResColumn;         /* Number of columns in one row of the result set */
  1.7181    u8 errorAction;         /* Recovery action to do in case of an error */
  1.7182    u8 minWriteFileFormat;  /* Minimum file format for writable database files */
  1.7183 -  bft expired:1;          /* True if the VM needs to be recompiled */
  1.7184 +  u8 prepFlags;           /* SQLITE_PREPARE_* flags */
  1.7185 +  bft expired:2;          /* 1: recompile VM immediately  2: when convenient */
  1.7186 +  bft explain:2;          /* True if EXPLAIN present on SQL command */
  1.7187    bft doingRerun:1;       /* True if rerunning after an auto-reprepare */
  1.7188 -  bft explain:2;          /* True if EXPLAIN present on SQL command */
  1.7189    bft changeCntOn:1;      /* True to update the change-counter */
  1.7190    bft runOnlyOnce:1;      /* Automatically expire on reset */
  1.7191    bft usesStmtJournal:1;  /* True if uses a statement journal */
  1.7192    bft readOnly:1;         /* True for statements that do not write */
  1.7193    bft bIsReader:1;        /* True for statements that read */
  1.7194 -  bft isPrepareV2:1;      /* True if prepared with prepare_v2() */
  1.7195    yDbMask btreeMask;      /* Bitmask of db->aDb[] entries referenced */
  1.7196    yDbMask lockMask;       /* Subset of btreeMask that requires a lock */
  1.7197 -  u32 aCounter[5];        /* Counters used by sqlite3_stmt_status() */
  1.7198 +  u32 aCounter[7];        /* Counters used by sqlite3_stmt_status() */
  1.7199    char *zSql;             /* Text of the SQL statement that generated this */
  1.7200 +#ifdef SQLITE_ENABLE_NORMALIZE
  1.7201 +  char *zNormSql;         /* Normalization of the associated SQL statement */
  1.7202 +#endif
  1.7203    void *pFree;            /* Free this when deleting the vdbe */
  1.7204    VdbeFrame *pFrame;      /* Parent frame */
  1.7205    VdbeFrame *pDelFrame;   /* List of frame objects to free on VM reset */
  1.7206 @@ -18380,9 +20288,6 @@
  1.7207  void sqliteVdbePopStack(Vdbe*,int);
  1.7208  SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor**, int*);
  1.7209  SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*);
  1.7210 -#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
  1.7211 -SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
  1.7212 -#endif
  1.7213  SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
  1.7214  SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8);
  1.7215  SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int, u32*);
  1.7216 @@ -18394,7 +20299,9 @@
  1.7217  SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(sqlite3*,VdbeCursor*,UnpackedRecord*,int*);
  1.7218  SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor*, i64*);
  1.7219  SQLITE_PRIVATE int sqlite3VdbeExec(Vdbe*);
  1.7220 +#ifndef SQLITE_OMIT_EXPLAIN
  1.7221  SQLITE_PRIVATE int sqlite3VdbeList(Vdbe*);
  1.7222 +#endif
  1.7223  SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe*);
  1.7224  SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *, int);
  1.7225  SQLITE_PRIVATE int sqlite3VdbeMemTooBig(Mem*);
  1.7226 @@ -18409,15 +20316,20 @@
  1.7227  #else
  1.7228  SQLITE_PRIVATE   void sqlite3VdbeMemSetDouble(Mem*, double);
  1.7229  #endif
  1.7230 +SQLITE_PRIVATE void sqlite3VdbeMemSetPointer(Mem*, void*, const char*, void(*)(void*));
  1.7231  SQLITE_PRIVATE void sqlite3VdbeMemInit(Mem*,sqlite3*,u16);
  1.7232  SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem*);
  1.7233  SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem*,int);
  1.7234 -SQLITE_PRIVATE void sqlite3VdbeMemSetRowSet(Mem*);
  1.7235 +#ifdef SQLITE_DEBUG
  1.7236 +SQLITE_PRIVATE int sqlite3VdbeMemIsRowSet(const Mem*);
  1.7237 +#endif
  1.7238 +SQLITE_PRIVATE int sqlite3VdbeMemSetRowSet(Mem*);
  1.7239  SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*);
  1.7240  SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, u8, u8);
  1.7241  SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem*);
  1.7242  SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
  1.7243  SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
  1.7244 +SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem*, int ifNull);
  1.7245  SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
  1.7246  SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
  1.7247  SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
  1.7248 @@ -18425,11 +20337,20 @@
  1.7249  SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);
  1.7250  SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
  1.7251  SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
  1.7252 +#ifndef SQLITE_OMIT_WINDOWFUNC
  1.7253 +SQLITE_PRIVATE int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*);
  1.7254 +#endif
  1.7255 +#ifndef SQLITE_OMIT_EXPLAIN
  1.7256  SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
  1.7257 +#endif
  1.7258  SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
  1.7259  SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int n);
  1.7260  SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
  1.7261 -SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
  1.7262 +#ifdef SQLITE_DEBUG
  1.7263 +SQLITE_PRIVATE int sqlite3VdbeFrameIsValid(VdbeFrame*);
  1.7264 +#endif
  1.7265 +SQLITE_PRIVATE void sqlite3VdbeFrameMemDel(void*);      /* Destructor on Mem */
  1.7266 +SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*); /* Actually deletes the Frame */
  1.7267  SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
  1.7268  #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
  1.7269  SQLITE_PRIVATE void sqlite3VdbePreUpdateHook(Vdbe*,VdbeCursor*,int,const char*,Table*,i64,int);
  1.7270 @@ -18440,11 +20361,19 @@
  1.7271  SQLITE_PRIVATE void sqlite3VdbeSorterReset(sqlite3 *, VdbeSorter *);
  1.7272  SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
  1.7273  SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);
  1.7274 -SQLITE_PRIVATE int sqlite3VdbeSorterNext(sqlite3 *, const VdbeCursor *, int *);
  1.7275 +SQLITE_PRIVATE int sqlite3VdbeSorterNext(sqlite3 *, const VdbeCursor *);
  1.7276  SQLITE_PRIVATE int sqlite3VdbeSorterRewind(const VdbeCursor *, int *);
  1.7277  SQLITE_PRIVATE int sqlite3VdbeSorterWrite(const VdbeCursor *, Mem *);
  1.7278  SQLITE_PRIVATE int sqlite3VdbeSorterCompare(const VdbeCursor *, Mem *, int, int *);
  1.7279  
  1.7280 +#ifdef SQLITE_DEBUG
  1.7281 +SQLITE_PRIVATE   void sqlite3VdbeIncrWriteCounter(Vdbe*, VdbeCursor*);
  1.7282 +SQLITE_PRIVATE   void sqlite3VdbeAssertAbortable(Vdbe*);
  1.7283 +#else
  1.7284 +# define sqlite3VdbeIncrWriteCounter(V,C)
  1.7285 +# define sqlite3VdbeAssertAbortable(V)
  1.7286 +#endif
  1.7287 +
  1.7288  #if !defined(SQLITE_OMIT_SHARED_CACHE) 
  1.7289  SQLITE_PRIVATE   void sqlite3VdbeEnter(Vdbe*);
  1.7290  #else
  1.7291 @@ -18468,12 +20397,14 @@
  1.7292  # define sqlite3VdbeCheckFk(p,i) 0
  1.7293  #endif
  1.7294  
  1.7295 -SQLITE_PRIVATE int sqlite3VdbeMemTranslate(Mem*, u8);
  1.7296  #ifdef SQLITE_DEBUG
  1.7297  SQLITE_PRIVATE   void sqlite3VdbePrintSql(Vdbe*);
  1.7298  SQLITE_PRIVATE   void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf);
  1.7299  #endif
  1.7300 -SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem);
  1.7301 +#ifndef SQLITE_OMIT_UTF16
  1.7302 +SQLITE_PRIVATE   int sqlite3VdbeMemTranslate(Mem*, u8);
  1.7303 +SQLITE_PRIVATE   int sqlite3VdbeMemHandleBom(Mem *pMem);
  1.7304 +#endif
  1.7305  
  1.7306  #ifndef SQLITE_OMIT_INCRBLOB
  1.7307  SQLITE_PRIVATE   int sqlite3VdbeMemExpandBlob(Mem *);
  1.7308 @@ -18594,7 +20525,6 @@
  1.7309                                             : sqlite3MallocMutex()) );
  1.7310    assert( op==SQLITE_STATUS_MALLOC_SIZE
  1.7311            || op==SQLITE_STATUS_PAGECACHE_SIZE
  1.7312 -          || op==SQLITE_STATUS_SCRATCH_SIZE
  1.7313            || op==SQLITE_STATUS_PARSER_STACK );
  1.7314    if( newValue>wsdStat.mxValue[op] ){
  1.7315      wsdStat.mxValue[op] = newValue;
  1.7316 @@ -18644,6 +20574,28 @@
  1.7317  }
  1.7318  
  1.7319  /*
  1.7320 +** Return the number of LookasideSlot elements on the linked list
  1.7321 +*/
  1.7322 +static u32 countLookasideSlots(LookasideSlot *p){
  1.7323 +  u32 cnt = 0;
  1.7324 +  while( p ){
  1.7325 +    p = p->pNext;
  1.7326 +    cnt++;
  1.7327 +  }
  1.7328 +  return cnt;
  1.7329 +}
  1.7330 +
  1.7331 +/*
  1.7332 +** Count the number of slots of lookaside memory that are outstanding
  1.7333 +*/
  1.7334 +SQLITE_PRIVATE int sqlite3LookasideUsed(sqlite3 *db, int *pHighwater){
  1.7335 +  u32 nInit = countLookasideSlots(db->lookaside.pInit);
  1.7336 +  u32 nFree = countLookasideSlots(db->lookaside.pFree);
  1.7337 +  if( pHighwater ) *pHighwater = db->lookaside.nSlot - nInit;
  1.7338 +  return db->lookaside.nSlot - (nInit+nFree);
  1.7339 +}
  1.7340 +
  1.7341 +/*
  1.7342  ** Query status information for a single database connection
  1.7343  */
  1.7344  SQLITE_API int sqlite3_db_status(
  1.7345 @@ -18662,10 +20614,15 @@
  1.7346    sqlite3_mutex_enter(db->mutex);
  1.7347    switch( op ){
  1.7348      case SQLITE_DBSTATUS_LOOKASIDE_USED: {
  1.7349 -      *pCurrent = db->lookaside.nOut;
  1.7350 -      *pHighwater = db->lookaside.mxOut;
  1.7351 +      *pCurrent = sqlite3LookasideUsed(db, pHighwater);
  1.7352        if( resetFlag ){
  1.7353 -        db->lookaside.mxOut = db->lookaside.nOut;
  1.7354 +        LookasideSlot *p = db->lookaside.pFree;
  1.7355 +        if( p ){
  1.7356 +          while( p->pNext ) p = p->pNext;
  1.7357 +          p->pNext = db->lookaside.pInit;
  1.7358 +          db->lookaside.pInit = db->lookaside.pFree;
  1.7359 +          db->lookaside.pFree = 0;
  1.7360 +        }
  1.7361        }
  1.7362        break;
  1.7363      }
  1.7364 @@ -18783,6 +20740,9 @@
  1.7365      ** pagers the database handle is connected to. *pHighwater is always set 
  1.7366      ** to zero.
  1.7367      */
  1.7368 +    case SQLITE_DBSTATUS_CACHE_SPILL:
  1.7369 +      op = SQLITE_DBSTATUS_CACHE_WRITE+1;
  1.7370 +      /* Fall through into the next case */
  1.7371      case SQLITE_DBSTATUS_CACHE_HIT:
  1.7372      case SQLITE_DBSTATUS_CACHE_MISS:
  1.7373      case SQLITE_DBSTATUS_CACHE_WRITE:{
  1.7374 @@ -18865,7 +20825,7 @@
  1.7375  **
  1.7376  **      Jean Meeus
  1.7377  **      Astronomical Algorithms, 2nd Edition, 1998
  1.7378 -**      ISBM 0-943396-61-1
  1.7379 +**      ISBN 0-943396-61-1
  1.7380  **      Willmann-Bell, Inc
  1.7381  **      Richmond, Virginia (USA)
  1.7382  */
  1.7383 @@ -19212,7 +21172,7 @@
  1.7384      return 0;
  1.7385    }else if( parseHhMmSs(zDate, p)==0 ){
  1.7386      return 0;
  1.7387 -  }else if( sqlite3StrICmp(zDate,"now")==0){
  1.7388 +  }else if( sqlite3StrICmp(zDate,"now")==0 && sqlite3NotPureFunc(context) ){
  1.7389      return setDateTimeToCurrent(context, p);
  1.7390    }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){
  1.7391      setRawDateNumber(p, r);
  1.7392 @@ -19495,7 +21455,7 @@
  1.7393        ** Assuming the current time value is UTC (a.k.a. GMT), shift it to
  1.7394        ** show local time.
  1.7395        */
  1.7396 -      if( sqlite3_stricmp(z, "localtime")==0 ){
  1.7397 +      if( sqlite3_stricmp(z, "localtime")==0 && sqlite3NotPureFunc(pCtx) ){
  1.7398          computeJD(p);
  1.7399          p->iJD += localtimeOffset(p, pCtx, &rc);
  1.7400          clearYMD_HMS_TZ(p);
  1.7401 @@ -19521,7 +21481,7 @@
  1.7402          }
  1.7403        }
  1.7404  #ifndef SQLITE_OMIT_LOCALTIME
  1.7405 -      else if( sqlite3_stricmp(z, "utc")==0 ){
  1.7406 +      else if( sqlite3_stricmp(z, "utc")==0 && sqlite3NotPureFunc(pCtx) ){
  1.7407          if( p->tzSet==0 ){
  1.7408            sqlite3_int64 c1;
  1.7409            computeJD(p);
  1.7410 @@ -20057,11 +22017,11 @@
  1.7411  SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void){
  1.7412    static FuncDef aDateTimeFuncs[] = {
  1.7413  #ifndef SQLITE_OMIT_DATETIME_FUNCS
  1.7414 -    DFUNCTION(julianday,        -1, 0, 0, juliandayFunc ),
  1.7415 -    DFUNCTION(date,             -1, 0, 0, dateFunc      ),
  1.7416 -    DFUNCTION(time,             -1, 0, 0, timeFunc      ),
  1.7417 -    DFUNCTION(datetime,         -1, 0, 0, datetimeFunc  ),
  1.7418 -    DFUNCTION(strftime,         -1, 0, 0, strftimeFunc  ),
  1.7419 +    PURE_DATE(julianday,        -1, 0, 0, juliandayFunc ),
  1.7420 +    PURE_DATE(date,             -1, 0, 0, dateFunc      ),
  1.7421 +    PURE_DATE(time,             -1, 0, 0, timeFunc      ),
  1.7422 +    PURE_DATE(datetime,         -1, 0, 0, datetimeFunc  ),
  1.7423 +    PURE_DATE(strftime,         -1, 0, 0, strftimeFunc  ),
  1.7424      DFUNCTION(current_time,      0, 0, 0, ctimeFunc     ),
  1.7425      DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
  1.7426      DFUNCTION(current_date,      0, 0, 0, cdateFunc     ),
  1.7427 @@ -20176,7 +22136,7 @@
  1.7428  }
  1.7429  SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file *id, int flags){
  1.7430    DO_OS_MALLOC_TEST(id);
  1.7431 -  return id->pMethods->xSync(id, flags);
  1.7432 +  return flags ? id->pMethods->xSync(id, flags) : SQLITE_OK;
  1.7433  }
  1.7434  SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file *id, i64 *pSize){
  1.7435    DO_OS_MALLOC_TEST(id);
  1.7436 @@ -20203,8 +22163,11 @@
  1.7437  ** routine has no return value since the return value would be meaningless.
  1.7438  */
  1.7439  SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){
  1.7440 +  if( id->pMethods==0 ) return SQLITE_NOTFOUND;
  1.7441  #ifdef SQLITE_TEST
  1.7442 -  if( op!=SQLITE_FCNTL_COMMIT_PHASETWO ){
  1.7443 +  if( op!=SQLITE_FCNTL_COMMIT_PHASETWO
  1.7444 +   && op!=SQLITE_FCNTL_LOCK_TIMEOUT
  1.7445 +  ){
  1.7446      /* Faults are not injected into COMMIT_PHASETWO because, assuming SQLite
  1.7447      ** is using a regular VFS, it is called after the corresponding
  1.7448      ** transaction has been committed. Injecting a fault at this point
  1.7449 @@ -20221,7 +22184,7 @@
  1.7450    return id->pMethods->xFileControl(id, op, pArg);
  1.7451  }
  1.7452  SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file *id, int op, void *pArg){
  1.7453 -  (void)id->pMethods->xFileControl(id, op, pArg);
  1.7454 +  if( id->pMethods ) (void)id->pMethods->xFileControl(id, op, pArg);
  1.7455  }
  1.7456  
  1.7457  SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id){
  1.7458 @@ -20231,6 +22194,7 @@
  1.7459  SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id){
  1.7460    return id->pMethods->xDeviceCharacteristics(id);
  1.7461  }
  1.7462 +#ifndef SQLITE_OMIT_WAL
  1.7463  SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int offset, int n, int flags){
  1.7464    return id->pMethods->xShmLock(id, offset, n, flags);
  1.7465  }
  1.7466 @@ -20250,6 +22214,7 @@
  1.7467    DO_OS_MALLOC_TEST(id);
  1.7468    return id->pMethods->xShmMap(id, iPage, pgsz, bExtend, pp);
  1.7469  }
  1.7470 +#endif /* SQLITE_OMIT_WAL */
  1.7471  
  1.7472  #if SQLITE_MAX_MMAP_SIZE>0
  1.7473  /* The real implementation of xFetch and xUnfetch */
  1.7474 @@ -20483,9 +22448,12 @@
  1.7475  ** Unregister a VFS so that it is no longer accessible.
  1.7476  */
  1.7477  SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs *pVfs){
  1.7478 -#if SQLITE_THREADSAFE
  1.7479 -  sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
  1.7480 -#endif
  1.7481 +  MUTEX_LOGIC(sqlite3_mutex *mutex;)
  1.7482 +#ifndef SQLITE_OMIT_AUTOINIT
  1.7483 +  int rc = sqlite3_initialize();
  1.7484 +  if( rc ) return rc;
  1.7485 +#endif
  1.7486 +  MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
  1.7487    sqlite3_mutex_enter(mutex);
  1.7488    vfsUnlink(pVfs);
  1.7489    sqlite3_mutex_leave(mutex);
  1.7490 @@ -22768,6 +24736,193 @@
  1.7491  
  1.7492  
  1.7493  #ifndef SQLITE_MUTEX_OMIT
  1.7494 +
  1.7495 +#ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS
  1.7496 +/*
  1.7497 +** This block (enclosed by SQLITE_ENABLE_MULTITHREADED_CHECKS) contains
  1.7498 +** the implementation of a wrapper around the system default mutex
  1.7499 +** implementation (sqlite3DefaultMutex()). 
  1.7500 +**
  1.7501 +** Most calls are passed directly through to the underlying default
  1.7502 +** mutex implementation. Except, if a mutex is configured by calling
  1.7503 +** sqlite3MutexWarnOnContention() on it, then if contention is ever
  1.7504 +** encountered within xMutexEnter() a warning is emitted via sqlite3_log().
  1.7505 +**
  1.7506 +** This type of mutex is used as the database handle mutex when testing
  1.7507 +** apps that usually use SQLITE_CONFIG_MULTITHREAD mode.
  1.7508 +*/
  1.7509 +
  1.7510 +/* 
  1.7511 +** Type for all mutexes used when SQLITE_ENABLE_MULTITHREADED_CHECKS
  1.7512 +** is defined. Variable CheckMutex.mutex is a pointer to the real mutex
  1.7513 +** allocated by the system mutex implementation. Variable iType is usually set
  1.7514 +** to the type of mutex requested - SQLITE_MUTEX_RECURSIVE, SQLITE_MUTEX_FAST
  1.7515 +** or one of the static mutex identifiers. Or, if this is a recursive mutex
  1.7516 +** that has been configured using sqlite3MutexWarnOnContention(), it is
  1.7517 +** set to SQLITE_MUTEX_WARNONCONTENTION.
  1.7518 +*/
  1.7519 +typedef struct CheckMutex CheckMutex;
  1.7520 +struct CheckMutex {
  1.7521 +  int iType;
  1.7522 +  sqlite3_mutex *mutex;
  1.7523 +};
  1.7524 +
  1.7525 +#define SQLITE_MUTEX_WARNONCONTENTION  (-1)
  1.7526 +
  1.7527 +/* 
  1.7528 +** Pointer to real mutex methods object used by the CheckMutex
  1.7529 +** implementation. Set by checkMutexInit(). 
  1.7530 +*/
  1.7531 +static SQLITE_WSD const sqlite3_mutex_methods *pGlobalMutexMethods;
  1.7532 +
  1.7533 +#ifdef SQLITE_DEBUG
  1.7534 +static int checkMutexHeld(sqlite3_mutex *p){
  1.7535 +  return pGlobalMutexMethods->xMutexHeld(((CheckMutex*)p)->mutex);
  1.7536 +}
  1.7537 +static int checkMutexNotheld(sqlite3_mutex *p){
  1.7538 +  return pGlobalMutexMethods->xMutexNotheld(((CheckMutex*)p)->mutex);
  1.7539 +}
  1.7540 +#endif
  1.7541 +
  1.7542 +/*
  1.7543 +** Initialize and deinitialize the mutex subsystem.
  1.7544 +*/
  1.7545 +static int checkMutexInit(void){ 
  1.7546 +  pGlobalMutexMethods = sqlite3DefaultMutex();
  1.7547 +  return SQLITE_OK; 
  1.7548 +}
  1.7549 +static int checkMutexEnd(void){ 
  1.7550 +  pGlobalMutexMethods = 0;
  1.7551 +  return SQLITE_OK; 
  1.7552 +}
  1.7553 +
  1.7554 +/*
  1.7555 +** Allocate a mutex.
  1.7556 +*/
  1.7557 +static sqlite3_mutex *checkMutexAlloc(int iType){
  1.7558 +  static CheckMutex staticMutexes[] = {
  1.7559 +    {2, 0}, {3, 0}, {4, 0}, {5, 0},
  1.7560 +    {6, 0}, {7, 0}, {8, 0}, {9, 0},
  1.7561 +    {10, 0}, {11, 0}, {12, 0}, {13, 0}
  1.7562 +  };
  1.7563 +  CheckMutex *p = 0;
  1.7564 +
  1.7565 +  assert( SQLITE_MUTEX_RECURSIVE==1 && SQLITE_MUTEX_FAST==0 );
  1.7566 +  if( iType<2 ){
  1.7567 +    p = sqlite3MallocZero(sizeof(CheckMutex));
  1.7568 +    if( p==0 ) return 0;
  1.7569 +    p->iType = iType;
  1.7570 +  }else{
  1.7571 +#ifdef SQLITE_ENABLE_API_ARMOR
  1.7572 +    if( iType-2>=ArraySize(staticMutexes) ){
  1.7573 +      (void)SQLITE_MISUSE_BKPT;
  1.7574 +      return 0;
  1.7575 +    }
  1.7576 +#endif
  1.7577 +    p = &staticMutexes[iType-2];
  1.7578 +  }
  1.7579 +
  1.7580 +  if( p->mutex==0 ){
  1.7581 +    p->mutex = pGlobalMutexMethods->xMutexAlloc(iType);
  1.7582 +    if( p->mutex==0 ){
  1.7583 +      if( iType<2 ){
  1.7584 +        sqlite3_free(p);
  1.7585 +      }
  1.7586 +      p = 0;
  1.7587 +    }
  1.7588 +  }
  1.7589 +
  1.7590 +  return (sqlite3_mutex*)p;
  1.7591 +}
  1.7592 +
  1.7593 +/*
  1.7594 +** Free a mutex.
  1.7595 +*/
  1.7596 +static void checkMutexFree(sqlite3_mutex *p){
  1.7597 +  assert( SQLITE_MUTEX_RECURSIVE<2 );
  1.7598 +  assert( SQLITE_MUTEX_FAST<2 );
  1.7599 +  assert( SQLITE_MUTEX_WARNONCONTENTION<2 );
  1.7600 +
  1.7601 +#if SQLITE_ENABLE_API_ARMOR
  1.7602 +  if( ((CheckMutex*)p)->iType<2 )
  1.7603 +#endif
  1.7604 +  {
  1.7605 +    CheckMutex *pCheck = (CheckMutex*)p;
  1.7606 +    pGlobalMutexMethods->xMutexFree(pCheck->mutex);
  1.7607 +    sqlite3_free(pCheck);
  1.7608 +  }
  1.7609 +#ifdef SQLITE_ENABLE_API_ARMOR
  1.7610 +  else{
  1.7611 +    (void)SQLITE_MISUSE_BKPT;
  1.7612 +  }
  1.7613 +#endif
  1.7614 +}
  1.7615 +
  1.7616 +/*
  1.7617 +** Enter the mutex.
  1.7618 +*/
  1.7619 +static void checkMutexEnter(sqlite3_mutex *p){
  1.7620 +  CheckMutex *pCheck = (CheckMutex*)p;
  1.7621 +  if( pCheck->iType==SQLITE_MUTEX_WARNONCONTENTION ){
  1.7622 +    if( SQLITE_OK==pGlobalMutexMethods->xMutexTry(pCheck->mutex) ){
  1.7623 +      return;
  1.7624 +    }
  1.7625 +    sqlite3_log(SQLITE_MISUSE, 
  1.7626 +        "illegal multi-threaded access to database connection"
  1.7627 +    );
  1.7628 +  }
  1.7629 +  pGlobalMutexMethods->xMutexEnter(pCheck->mutex);
  1.7630 +}
  1.7631 +
  1.7632 +/*
  1.7633 +** Enter the mutex (do not block).
  1.7634 +*/
  1.7635 +static int checkMutexTry(sqlite3_mutex *p){
  1.7636 +  CheckMutex *pCheck = (CheckMutex*)p;
  1.7637 +  return pGlobalMutexMethods->xMutexTry(pCheck->mutex);
  1.7638 +}
  1.7639 +
  1.7640 +/*
  1.7641 +** Leave the mutex.
  1.7642 +*/
  1.7643 +static void checkMutexLeave(sqlite3_mutex *p){
  1.7644 +  CheckMutex *pCheck = (CheckMutex*)p;
  1.7645 +  pGlobalMutexMethods->xMutexLeave(pCheck->mutex);
  1.7646 +}
  1.7647 +
  1.7648 +sqlite3_mutex_methods const *multiThreadedCheckMutex(void){
  1.7649 +  static const sqlite3_mutex_methods sMutex = {
  1.7650 +    checkMutexInit,
  1.7651 +    checkMutexEnd,
  1.7652 +    checkMutexAlloc,
  1.7653 +    checkMutexFree,
  1.7654 +    checkMutexEnter,
  1.7655 +    checkMutexTry,
  1.7656 +    checkMutexLeave,
  1.7657 +#ifdef SQLITE_DEBUG
  1.7658 +    checkMutexHeld,
  1.7659 +    checkMutexNotheld
  1.7660 +#else
  1.7661 +    0,
  1.7662 +    0
  1.7663 +#endif
  1.7664 +  };
  1.7665 +  return &sMutex;
  1.7666 +}
  1.7667 +
  1.7668 +/*
  1.7669 +** Mark the SQLITE_MUTEX_RECURSIVE mutex passed as the only argument as
  1.7670 +** one on which there should be no contention.
  1.7671 +*/
  1.7672 +SQLITE_PRIVATE void sqlite3MutexWarnOnContention(sqlite3_mutex *p){
  1.7673 +  if( sqlite3GlobalConfig.mutex.xMutexAlloc==checkMutexAlloc ){
  1.7674 +    CheckMutex *pCheck = (CheckMutex*)p;
  1.7675 +    assert( pCheck->iType==SQLITE_MUTEX_RECURSIVE );
  1.7676 +    pCheck->iType = SQLITE_MUTEX_WARNONCONTENTION;
  1.7677 +  }
  1.7678 +}
  1.7679 +#endif   /* ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS */
  1.7680 +
  1.7681  /*
  1.7682  ** Initialize the mutex system.
  1.7683  */
  1.7684 @@ -22783,7 +24938,11 @@
  1.7685      sqlite3_mutex_methods *pTo = &sqlite3GlobalConfig.mutex;
  1.7686  
  1.7687      if( sqlite3GlobalConfig.bCoreMutex ){
  1.7688 +#ifdef SQLITE_ENABLE_MULTITHREADED_CHECKS
  1.7689 +      pFrom = multiThreadedCheckMutex();
  1.7690 +#else
  1.7691        pFrom = sqlite3DefaultMutex();
  1.7692 +#endif
  1.7693      }else{
  1.7694        pFrom = sqlite3NoopMutex();
  1.7695      }
  1.7696 @@ -23182,11 +25341,12 @@
  1.7697  #endif
  1.7698  };
  1.7699  #if SQLITE_MUTEX_NREF
  1.7700 -#define SQLITE3_MUTEX_INITIALIZER {PTHREAD_MUTEX_INITIALIZER,0,0,(pthread_t)0,0}
  1.7701 +# define SQLITE3_MUTEX_INITIALIZER(id) \
  1.7702 +     {PTHREAD_MUTEX_INITIALIZER,id,0,(pthread_t)0,0}
  1.7703  #elif defined(SQLITE_ENABLE_API_ARMOR)
  1.7704 -#define SQLITE3_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0 }
  1.7705 -#else
  1.7706 -#define SQLITE3_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER }
  1.7707 +# define SQLITE3_MUTEX_INITIALIZER(id) { PTHREAD_MUTEX_INITIALIZER, id }
  1.7708 +#else
  1.7709 +#define SQLITE3_MUTEX_INITIALIZER(id) { PTHREAD_MUTEX_INITIALIZER }
  1.7710  #endif
  1.7711  
  1.7712  /*
  1.7713 @@ -23283,18 +25443,18 @@
  1.7714  */
  1.7715  static sqlite3_mutex *pthreadMutexAlloc(int iType){
  1.7716    static sqlite3_mutex staticMutexes[] = {
  1.7717 -    SQLITE3_MUTEX_INITIALIZER,
  1.7718 -    SQLITE3_MUTEX_INITIALIZER,
  1.7719 -    SQLITE3_MUTEX_INITIALIZER,
  1.7720 -    SQLITE3_MUTEX_INITIALIZER,
  1.7721 -    SQLITE3_MUTEX_INITIALIZER,
  1.7722 -    SQLITE3_MUTEX_INITIALIZER,
  1.7723 -    SQLITE3_MUTEX_INITIALIZER,
  1.7724 -    SQLITE3_MUTEX_INITIALIZER,
  1.7725 -    SQLITE3_MUTEX_INITIALIZER,
  1.7726 -    SQLITE3_MUTEX_INITIALIZER,
  1.7727 -    SQLITE3_MUTEX_INITIALIZER,
  1.7728 -    SQLITE3_MUTEX_INITIALIZER
  1.7729 +    SQLITE3_MUTEX_INITIALIZER(2),
  1.7730 +    SQLITE3_MUTEX_INITIALIZER(3),
  1.7731 +    SQLITE3_MUTEX_INITIALIZER(4),
  1.7732 +    SQLITE3_MUTEX_INITIALIZER(5),
  1.7733 +    SQLITE3_MUTEX_INITIALIZER(6),
  1.7734 +    SQLITE3_MUTEX_INITIALIZER(7),
  1.7735 +    SQLITE3_MUTEX_INITIALIZER(8),
  1.7736 +    SQLITE3_MUTEX_INITIALIZER(9),
  1.7737 +    SQLITE3_MUTEX_INITIALIZER(10),
  1.7738 +    SQLITE3_MUTEX_INITIALIZER(11),
  1.7739 +    SQLITE3_MUTEX_INITIALIZER(12),
  1.7740 +    SQLITE3_MUTEX_INITIALIZER(13)
  1.7741    };
  1.7742    sqlite3_mutex *p;
  1.7743    switch( iType ){
  1.7744 @@ -23313,6 +25473,9 @@
  1.7745          pthread_mutex_init(&p->mutex, &recursiveAttr);
  1.7746          pthread_mutexattr_destroy(&recursiveAttr);
  1.7747  #endif
  1.7748 +#if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR)
  1.7749 +        p->id = SQLITE_MUTEX_RECURSIVE;
  1.7750 +#endif
  1.7751        }
  1.7752        break;
  1.7753      }
  1.7754 @@ -23320,6 +25483,9 @@
  1.7755        p = sqlite3MallocZero( sizeof(*p) );
  1.7756        if( p ){
  1.7757          pthread_mutex_init(&p->mutex, 0);
  1.7758 +#if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR)
  1.7759 +        p->id = SQLITE_MUTEX_FAST;
  1.7760 +#endif
  1.7761        }
  1.7762        break;
  1.7763      }
  1.7764 @@ -23335,7 +25501,7 @@
  1.7765      }
  1.7766    }
  1.7767  #if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR)
  1.7768 -  if( p ) p->id = iType;
  1.7769 +  assert( p==0 || p->id==iType );
  1.7770  #endif
  1.7771    return p;
  1.7772  }
  1.7773 @@ -23852,7 +26018,7 @@
  1.7774  #ifdef SQLITE_DEBUG
  1.7775    volatile int nRef;         /* Number of enterances */
  1.7776    volatile DWORD owner;      /* Thread holding this mutex */
  1.7777 -  volatile int trace;        /* True to trace changes */
  1.7778 +  volatile LONG trace;       /* True to trace changes */
  1.7779  #endif
  1.7780  };
  1.7781  
  1.7782 @@ -23864,10 +26030,10 @@
  1.7783  #define SQLITE_W32_MUTEX_INITIALIZER { 0 }
  1.7784  
  1.7785  #ifdef SQLITE_DEBUG
  1.7786 -#define SQLITE3_MUTEX_INITIALIZER { SQLITE_W32_MUTEX_INITIALIZER, 0, \
  1.7787 +#define SQLITE3_MUTEX_INITIALIZER(id) { SQLITE_W32_MUTEX_INITIALIZER, id, \
  1.7788                                      0L, (DWORD)0, 0 }
  1.7789  #else
  1.7790 -#define SQLITE3_MUTEX_INITIALIZER { SQLITE_W32_MUTEX_INITIALIZER, 0 }
  1.7791 +#define SQLITE3_MUTEX_INITIALIZER(id) { SQLITE_W32_MUTEX_INITIALIZER, id }
  1.7792  #endif
  1.7793  
  1.7794  #ifdef SQLITE_DEBUG
  1.7795 @@ -23910,18 +26076,18 @@
  1.7796  ** Initialize and deinitialize the mutex subsystem.
  1.7797  */
  1.7798  static sqlite3_mutex winMutex_staticMutexes[] = {
  1.7799 -  SQLITE3_MUTEX_INITIALIZER,
  1.7800 -  SQLITE3_MUTEX_INITIALIZER,
  1.7801 -  SQLITE3_MUTEX_INITIALIZER,
  1.7802 -  SQLITE3_MUTEX_INITIALIZER,
  1.7803 -  SQLITE3_MUTEX_INITIALIZER,
  1.7804 -  SQLITE3_MUTEX_INITIALIZER,
  1.7805 -  SQLITE3_MUTEX_INITIALIZER,
  1.7806 -  SQLITE3_MUTEX_INITIALIZER,
  1.7807 -  SQLITE3_MUTEX_INITIALIZER,
  1.7808 -  SQLITE3_MUTEX_INITIALIZER,
  1.7809 -  SQLITE3_MUTEX_INITIALIZER,
  1.7810 -  SQLITE3_MUTEX_INITIALIZER
  1.7811 +  SQLITE3_MUTEX_INITIALIZER(2),
  1.7812 +  SQLITE3_MUTEX_INITIALIZER(3),
  1.7813 +  SQLITE3_MUTEX_INITIALIZER(4),
  1.7814 +  SQLITE3_MUTEX_INITIALIZER(5),
  1.7815 +  SQLITE3_MUTEX_INITIALIZER(6),
  1.7816 +  SQLITE3_MUTEX_INITIALIZER(7),
  1.7817 +  SQLITE3_MUTEX_INITIALIZER(8),
  1.7818 +  SQLITE3_MUTEX_INITIALIZER(9),
  1.7819 +  SQLITE3_MUTEX_INITIALIZER(10),
  1.7820 +  SQLITE3_MUTEX_INITIALIZER(11),
  1.7821 +  SQLITE3_MUTEX_INITIALIZER(12),
  1.7822 +  SQLITE3_MUTEX_INITIALIZER(13)
  1.7823  };
  1.7824  
  1.7825  static int winMutex_isInit = 0;
  1.7826 @@ -24051,15 +26217,15 @@
  1.7827        }