@cryptotaxi247 / netdata-1 / commits / e54be0e6f

Update to SQLITE version 3.40.1 (#14282)

Update to sqlite3 version 3.40.1

Stelios Fragkakis committed Jan 20, 2023 at 12:12 UTC e54be0e6f5dd724470f4ff02d725994d08aae10a
2 files changed +9180 -4934
database/sqlite/sqlite3.c
+9056 -4898
@@ -1,6 +1,6 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 -** version 3.38.5. By combining all the individual C code files into this
3 +** version 3.40.1. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
@@ -27,7 +27,6 @@
27 #define SQLITE_ENABLE_UPDATE_DELETE_LIMIT 1
28 #define SQLITE_OMIT_LOAD_EXTENSION 1
29 #define SQLITE_ENABLE_DBSTAT_VTAB 1
30 -
30 /************** Begin file sqliteInt.h ***************************************/
31 /*
32 ** 2001 September 15
@@ -458,9 +457,9 @@ extern "C" {
457 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
458 ** [sqlite_version()] and [sqlite_source_id()].
459 */
461 -#define SQLITE_VERSION "3.38.5"
462 -#define SQLITE_VERSION_NUMBER 3038005
463 -#define SQLITE_SOURCE_ID "2022-05-06 15:25:27 78d9c993d404cdfaa7fdd2973fa1052e3da9f66215cff9c5540ebe55c407d9fe"
460 +#define SQLITE_VERSION "3.40.1"
461 +#define SQLITE_VERSION_NUMBER 3040001
462 +#define SQLITE_SOURCE_ID "2022-12-28 14:03:47 df5c253c0b3dd24916e4ec7cf77d3db5294cc9fd45ae7b9c5e82ad8197f38a24"
463
464 /*
465 ** CAPI3REF: Run-Time Library Version Numbers
@@ -982,13 +981,17 @@ SQLITE_API int sqlite3_exec(
981 **
982 ** SQLite uses one of these integer values as the second
983 ** argument to calls it makes to the xLock() and xUnlock() methods
985 -** of an [sqlite3_io_methods] object.
984 +** of an [sqlite3_io_methods] object. These values are ordered from
985 +** lest restrictive to most restrictive.
986 +**
987 +** The argument to xLock() is always SHARED or higher. The argument to
988 +** xUnlock is either SHARED or NONE.
989 */
987 -#define SQLITE_LOCK_NONE 0
988 -#define SQLITE_LOCK_SHARED 1
989 -#define SQLITE_LOCK_RESERVED 2
990 -#define SQLITE_LOCK_PENDING 3
991 -#define SQLITE_LOCK_EXCLUSIVE 4
990 +#define SQLITE_LOCK_NONE 0 /* xUnlock() only */
991 +#define SQLITE_LOCK_SHARED 1 /* xLock() or xUnlock() */
992 +#define SQLITE_LOCK_RESERVED 2 /* xLock() only */
993 +#define SQLITE_LOCK_PENDING 3 /* xLock() only */
994 +#define SQLITE_LOCK_EXCLUSIVE 4 /* xLock() only */
995
996 /*
997 ** CAPI3REF: Synchronization Type Flags
@@ -1066,7 +1069,14 @@ struct sqlite3_file {
1069 ** <li> [SQLITE_LOCK_PENDING], or
1070 ** <li> [SQLITE_LOCK_EXCLUSIVE].
1071 ** </ul>
1069 -** xLock() increases the lock. xUnlock() decreases the lock.
1072 +** xLock() upgrades the database file lock. In other words, xLock() moves the
1073 +** database file lock in the direction NONE toward EXCLUSIVE. The argument to
1074 +** xLock() is always on of SHARED, RESERVED, PENDING, or EXCLUSIVE, never
1075 +** SQLITE_LOCK_NONE. If the database file lock is already at or above the
1076 +** requested lock, then the call to xLock() is a no-op.
1077 +** xUnlock() downgrades the database file lock to either SHARED or NONE.
1078 +* If the lock is already at or below the requested lock state, then the call
1079 +** to xUnlock() is a no-op.
1080 ** The xCheckReservedLock() method checks whether any database connection,
1081 ** either in this process or in some other process, is holding a RESERVED,
1082 ** PENDING, or EXCLUSIVE lock on the file. It returns true
@@ -1171,9 +1181,8 @@ struct sqlite3_io_methods {
1181 ** opcode causes the xFileControl method to write the current state of
1182 ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
1183 ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
1174 -** into an integer that the pArg argument points to. This capability
1175 -** is used during testing and is only available when the SQLITE_TEST
1176 -** compile-time option is used.
1184 +** into an integer that the pArg argument points to.
1185 +** This capability is only available if SQLite is compiled with [SQLITE_DEBUG].
1186 **
1187 ** <li>[[SQLITE_FCNTL_SIZE_HINT]]
1188 ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
@@ -1494,6 +1503,12 @@ struct sqlite3_io_methods {
1503 **
1504 ** <li>[[SQLITE_FCNTL_CKSM_FILE]]
1505 ** Used by the cksmvfs VFS module only.
1506 +**
1507 +** <li>[[SQLITE_FCNTL_RESET_CACHE]]
1508 +** If there is currently no transaction open on the database, and the
1509 +** database is not a temp db, then this file-control purges the contents
1510 +** of the in-memory page cache. If there is an open transaction, or if
1511 +** the db is a temp-db, it is a no-op, not an error.
1512 ** </ul>
1513 */
1514 #define SQLITE_FCNTL_LOCKSTATE 1
@@ -1536,6 +1551,7 @@ struct sqlite3_io_methods {
1551 #define SQLITE_FCNTL_CKPT_START 39
1552 #define SQLITE_FCNTL_EXTERNAL_READER 40
1553 #define SQLITE_FCNTL_CKSM_FILE 41
1554 +#define SQLITE_FCNTL_RESET_CACHE 42
1555
1556 /* deprecated names */
1557 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
@@ -1565,6 +1581,26 @@ typedef struct sqlite3_mutex sqlite3_mutex;
1581 */
1582 typedef struct sqlite3_api_routines sqlite3_api_routines;
1583
1584 +/*
1585 +** CAPI3REF: File Name
1586 +**
1587 +** Type [sqlite3_filename] is used by SQLite to pass filenames to the
1588 +** xOpen method of a [VFS]. It may be cast to (const char*) and treated
1589 +** as a normal, nul-terminated, UTF-8 buffer containing the filename, but
1590 +** may also be passed to special APIs such as:
1591 +**
1592 +** <ul>
1593 +** <li> sqlite3_filename_database()
1594 +** <li> sqlite3_filename_journal()
1595 +** <li> sqlite3_filename_wal()
1596 +** <li> sqlite3_uri_parameter()
1597 +** <li> sqlite3_uri_boolean()
1598 +** <li> sqlite3_uri_int64()
1599 +** <li> sqlite3_uri_key()
1600 +** </ul>
1601 +*/
1602 +typedef const char *sqlite3_filename;
1603 +
1604 /*
1605 ** CAPI3REF: OS Interface Object
1606 **
@@ -1743,7 +1779,7 @@ struct sqlite3_vfs {
1779 sqlite3_vfs *pNext; /* Next registered VFS */
1780 const char *zName; /* Name of this virtual file system */
1781 void *pAppData; /* Pointer to application-specific data */
1746 - int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
1782 + int (*xOpen)(sqlite3_vfs*, sqlite3_filename zName, sqlite3_file*,
1783 int flags, int *pOutFlags);
1784 int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
1785 int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
@@ -2621,6 +2657,7 @@ struct sqlite3_mem_methods {
2657 ** <ul>
2658 ** <li> The [PRAGMA writable_schema=ON] statement.
2659 ** <li> The [PRAGMA journal_mode=OFF] statement.
2660 +** <li> The [PRAGMA schema_version=N] statement.
2661 ** <li> Writes to the [sqlite_dbpage] virtual table.
2662 ** <li> Direct writes to [shadow tables].
2663 ** </ul>
@@ -3736,6 +3773,9 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
3773 ** <dd>The database is opened [shared cache] enabled, overriding
3774 ** the default shared cache setting provided by
3775 ** [sqlite3_enable_shared_cache()].)^
3776 +** The [use of shared cache mode is discouraged] and hence shared cache
3777 +** capabilities may be omitted from many builds of SQLite. In such cases,
3778 +** this option is a no-op.
3779 **
3780 ** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
3781 ** <dd>The database is opened [shared cache] disabled, overriding
@@ -3751,7 +3791,7 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
3791 ** to return an extended result code.</dd>
3792 **
3793 ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
3754 -** <dd>The database filename is not allowed to be a symbolic link</dd>
3794 +** <dd>The database filename is not allowed to contain a symbolic link</dd>
3795 ** </dl>)^
3796 **
3797 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
@@ -4010,10 +4050,10 @@ SQLITE_API int sqlite3_open_v2(
4050 **
4051 ** See the [URI filename] documentation for additional information.
4052 */
4013 -SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
4014 -SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
4015 -SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
4016 -SQLITE_API const char *sqlite3_uri_key(const char *zFilename, int N);
4053 +SQLITE_API const char *sqlite3_uri_parameter(sqlite3_filename z, const char *zParam);
4054 +SQLITE_API int sqlite3_uri_boolean(sqlite3_filename z, const char *zParam, int bDefault);
4055 +SQLITE_API sqlite3_int64 sqlite3_uri_int64(sqlite3_filename, const char*, sqlite3_int64);
4056 +SQLITE_API const char *sqlite3_uri_key(sqlite3_filename z, int N);
4057
4058 /*
4059 ** CAPI3REF: Translate filenames
@@ -4042,9 +4082,9 @@ SQLITE_API const char *sqlite3_uri_key(const char *zFilename, int N);
4082 ** return value from [sqlite3_db_filename()], then the result is
4083 ** undefined and is likely a memory access violation.
4084 */
4045 -SQLITE_API const char *sqlite3_filename_database(const char*);
4046 -SQLITE_API const char *sqlite3_filename_journal(const char*);
4047 -SQLITE_API const char *sqlite3_filename_wal(const char*);
4085 +SQLITE_API const char *sqlite3_filename_database(sqlite3_filename);
4086 +SQLITE_API const char *sqlite3_filename_journal(sqlite3_filename);
4087 +SQLITE_API const char *sqlite3_filename_wal(sqlite3_filename);
4088
4089 /*
4090 ** CAPI3REF: Database File Corresponding To A Journal
@@ -4110,14 +4150,14 @@ SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*);
4150 ** then the corresponding [sqlite3_module.xClose() method should also be
4151 ** invoked prior to calling sqlite3_free_filename(Y).
4152 */
4113 -SQLITE_API char *sqlite3_create_filename(
4153 +SQLITE_API sqlite3_filename sqlite3_create_filename(
4154 const char *zDatabase,
4155 const char *zJournal,
4156 const char *zWal,
4157 int nParam,
4158 const char **azParam
4159 );
4120 -SQLITE_API void sqlite3_free_filename(char*);
4160 +SQLITE_API void sqlite3_free_filename(sqlite3_filename);
4161
4162 /*
4163 ** CAPI3REF: Error Codes And Messages
@@ -5820,6 +5860,16 @@ SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int6
5860 ** then the conversion is performed. Otherwise no conversion occurs.
5861 ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
5862 **
5863 +** ^(The sqlite3_value_encoding(X) interface returns one of [SQLITE_UTF8],
5864 +** [SQLITE_UTF16BE], or [SQLITE_UTF16LE] according to the current encoding
5865 +** of the value X, assuming that X has type TEXT.)^ If sqlite3_value_type(X)
5866 +** returns something other than SQLITE_TEXT, then the return value from
5867 +** sqlite3_value_encoding(X) is meaningless. ^Calls to
5868 +** sqlite3_value_text(X), sqlite3_value_text16(X), sqlite3_value_text16be(X),
5869 +** sqlite3_value_text16le(X), sqlite3_value_bytes(X), or
5870 +** sqlite3_value_bytes16(X) might change the encoding of the value X and
5871 +** thus change the return from subsequent calls to sqlite3_value_encoding(X).
5872 +**
5873 ** ^Within the [xUpdate] method of a [virtual table], the
5874 ** sqlite3_value_nochange(X) interface returns true if and only if
5875 ** the column corresponding to X is unchanged by the UPDATE operation
@@ -5884,6 +5934,7 @@ SQLITE_API int sqlite3_value_type(sqlite3_value*);
5934 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
5935 SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
5936 SQLITE_API int sqlite3_value_frombind(sqlite3_value*);
5937 +SQLITE_API int sqlite3_value_encoding(sqlite3_value*);
5938
5939 /*
5940 ** CAPI3REF: Finding The Subtype Of SQL Values
@@ -5905,7 +5956,8 @@ SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*);
5956 ** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
5957 ** is a [protected sqlite3_value] object even if the input is not.
5958 ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
5908 -** memory allocation fails.
5959 +** memory allocation fails. ^If V is a [pointer value], then the result
5960 +** of sqlite3_value_dup(V) is a NULL value.
5961 **
5962 ** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
5963 ** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer
@@ -5936,7 +5988,7 @@ SQLITE_API void sqlite3_value_free(sqlite3_value*);
5988 **
5989 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
5990 ** when first called if N is less than or equal to zero or if a memory
5939 -** allocate error occurs.
5991 +** allocation error occurs.
5992 **
5993 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
5994 ** determined by the N parameter on first successful call. Changing the
@@ -6141,9 +6193,10 @@ typedef void (*sqlite3_destructor_type)(void*);
6193 ** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE].
6194 ** ^SQLite takes the text result from the application from
6195 ** the 2nd parameter of the sqlite3_result_text* interfaces.
6144 -** ^If the 3rd parameter to the sqlite3_result_text* interfaces
6145 -** is negative, then SQLite takes result text from the 2nd parameter
6146 -** through the first zero character.
6196 +** ^If the 3rd parameter to any of the sqlite3_result_text* interfaces
6197 +** other than sqlite3_result_text64() is negative, then SQLite computes
6198 +** the string length itself by searching the 2nd parameter for the first
6199 +** zero character.
6200 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
6201 ** is non-negative, then as many bytes (not characters) of the text
6202 ** pointed to by the 2nd parameter are taken as the application-defined
@@ -6587,6 +6640,28 @@ SQLITE_API int sqlite3_get_autocommit(sqlite3*);
6640 */
6641 SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
6642
6643 +/*
6644 +** CAPI3REF: Return The Schema Name For A Database Connection
6645 +** METHOD: sqlite3
6646 +**
6647 +** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
6648 +** for the N-th database on database connection D, or a NULL pointer of N is
6649 +** out of range. An N value of 0 means the main database file. An N of 1 is
6650 +** the "temp" schema. Larger values of N correspond to various ATTACH-ed
6651 +** databases.
6652 +**
6653 +** Space to hold the string that is returned by sqlite3_db_name() is managed
6654 +** by SQLite itself. The string might be deallocated by any operation that
6655 +** changes the schema, including [ATTACH] or [DETACH] or calls to
6656 +** [sqlite3_serialize()] or [sqlite3_deserialize()], even operations that
6657 +** occur on a different thread. Applications that need to
6658 +** remember the string long-term should make their own copy. Applications that
6659 +** are accessing the same database connection simultaneously on multiple
6660 +** threads should mutex-protect calls to this API and should make their own
6661 +** private copy of the result prior to releasing the mutex.
6662 +*/
6663 +SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N);
6664 +
6665 /*
6666 ** CAPI3REF: Return The Filename For A Database Connection
6667 ** METHOD: sqlite3
@@ -6617,7 +6692,7 @@ SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
6692 ** <li> [sqlite3_filename_wal()]
6693 ** </ul>
6694 */
6620 -SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
6695 +SQLITE_API sqlite3_filename sqlite3_db_filename(sqlite3 *db, const char *zDbName);
6696
6697 /*
6698 ** CAPI3REF: Determine if a database is read-only
@@ -6754,7 +6829,7 @@ SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
6829 ** function C that is invoked prior to each autovacuum of the database
6830 ** file. ^The callback is passed a copy of the generic data pointer (P),
6831 ** the schema-name of the attached database that is being autovacuumed,
6757 -** the the size of the database file in pages, the number of free pages,
6832 +** the size of the database file in pages, the number of free pages,
6833 ** and the number of bytes per page, respectively. The callback should
6834 ** return the number of free pages that should be removed by the
6835 ** autovacuum. ^If the callback returns zero, then no autovacuum happens.
@@ -6875,6 +6950,11 @@ SQLITE_API void *sqlite3_update_hook(
6950 ** to the same database. Sharing is enabled if the argument is true
6951 ** and disabled if the argument is false.)^
6952 **
6953 +** This interface is omitted if SQLite is compiled with
6954 +** [-DSQLITE_OMIT_SHARED_CACHE]. The [-DSQLITE_OMIT_SHARED_CACHE]
6955 +** compile-time option is recommended because the
6956 +** [use of shared cache mode is discouraged].
6957 +**
6958 ** ^Cache sharing is enabled and disabled for an entire process.
6959 ** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]).
6960 ** In prior versions of SQLite,
@@ -6973,7 +7053,7 @@ SQLITE_API int sqlite3_db_release_memory(sqlite3*);
7053 ** ^The soft heap limit may not be greater than the hard heap limit.
7054 ** ^If the hard heap limit is enabled and if sqlite3_soft_heap_limit(N)
7055 ** is invoked with a value of N that is greater than the hard heap limit,
6976 -** the the soft heap limit is set to the value of the hard heap limit.
7056 +** the soft heap limit is set to the value of the hard heap limit.
7057 ** ^The soft heap limit is automatically enabled whenever the hard heap
7058 ** limit is enabled. ^When sqlite3_hard_heap_limit64(N) is invoked and
7059 ** the soft heap limit is outside the range of 1..N, then the soft heap
@@ -9268,7 +9348,7 @@ typedef struct sqlite3_backup sqlite3_backup;
9348 ** if the application incorrectly accesses the destination [database connection]
9349 ** and so no error code is reported, but the operations may malfunction
9350 ** nevertheless. Use of the destination database connection while a
9271 -** backup is in progress might also also cause a mutex deadlock.
9351 +** backup is in progress might also cause a mutex deadlock.
9352 **
9353 ** If running in [shared cache mode], the application must
9354 ** guarantee that the shared cache used by the destination database
@@ -9696,7 +9776,7 @@ SQLITE_API int sqlite3_wal_checkpoint_v2(
9776 */
9777 #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
9778 #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
9699 -#define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */
9779 +#define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for readers */
9780 #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
9781
9782 /*
@@ -9866,8 +9946,8 @@ SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_
9946 ** of a [virtual table] implementation. The result of calling this
9947 ** interface from outside of xBestIndex() is undefined and probably harmful.
9948 **
9869 -** ^The sqlite3_vtab_distinct() interface returns an integer that is
9870 -** either 0, 1, or 2. The integer returned by sqlite3_vtab_distinct()
9949 +** ^The sqlite3_vtab_distinct() interface returns an integer between 0 and
9950 +** 3. The integer returned by sqlite3_vtab_distinct()
9951 ** gives the virtual table additional information about how the query
9952 ** planner wants the output to be ordered. As long as the virtual table
9953 ** can meet the ordering requirements of the query planner, it may set
@@ -9899,6 +9979,13 @@ SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_
9979 ** that have the same value for all columns identified by "aOrderBy".
9980 ** ^However omitting the extra rows is optional.
9981 ** This mode is used for a DISTINCT query.
9982 +** <li value="3"><p>
9983 +** ^(If the sqlite3_vtab_distinct() interface returns 3, that means
9984 +** that the query planner needs only distinct rows but it does need the
9985 +** rows to be sorted.)^ ^The virtual table implementation is free to omit
9986 +** rows that are identical in all aOrderBy columns, if it wants to, but
9987 +** it is not required to omit any rows. This mode is used for queries
9988 +** that have both DISTINCT and ORDER BY clauses.
9989 ** </ol>
9990 **
9991 ** ^For the purposes of comparing virtual table output values to see if the
@@ -13120,12 +13207,17 @@ struct fts5_api {
13207 /************** End of sqlite3.h *********************************************/
13208 /************** Continuing where we left off in sqliteInt.h ******************/
13209
13210 +/*
13211 +** Reuse the STATIC_LRU for mutex access to sqlite3_temp_directory.
13212 +*/
13213 +#define SQLITE_MUTEX_STATIC_TEMPDIR SQLITE_MUTEX_STATIC_VFS1
13214 +
13215 /*
13216 ** Include the configuration header output by 'configure' if we're using the
13217 ** autoconf-based build
13218 */
13219 #if defined(_HAVE_SQLITE_CONFIG_H) && !defined(SQLITECONFIG_H)
13128 -#include "config.h"
13220 +#include "sqlite_cfg.h"
13221 #define SQLITECONFIG_H 1
13222 #endif
13223
@@ -14363,8 +14455,19 @@ typedef INT16_TYPE LogEst;
14455 /*
14456 ** Round up a number to the next larger multiple of 8. This is used
14457 ** to force 8-byte alignment on 64-bit architectures.
14458 +**
14459 +** ROUND8() always does the rounding, for any argument.
14460 +**
14461 +** ROUND8P() assumes that the argument is already an integer number of
14462 +** pointers in size, and so it is a no-op on systems where the pointer
14463 +** size is 8.
14464 */
14465 #define ROUND8(x) (((x)+7)&~7)
14466 +#if SQLITE_PTRSIZE==8
14467 +# define ROUND8P(x) (x)
14468 +#else
14469 +# define ROUND8P(x) (((x)+7)&~7)
14470 +#endif
14471
14472 /*
14473 ** Round down to the nearest multiple of 8
@@ -14427,22 +14530,23 @@ typedef INT16_TYPE LogEst;
14530 #endif
14531
14532 /*
14430 -** SELECTTRACE_ENABLED will be either 1 or 0 depending on whether or not
14431 -** the Select query generator tracing logic is turned on.
14533 +** TREETRACE_ENABLED will be either 1 or 0 depending on whether or not
14534 +** the Abstract Syntax Tree tracing logic is turned on.
14535 */
14536 #if !defined(SQLITE_AMALGAMATION)
14434 -SQLITE_PRIVATE u32 sqlite3SelectTrace;
14537 +SQLITE_PRIVATE u32 sqlite3TreeTrace;
14538 #endif
14539 #if defined(SQLITE_DEBUG) \
14437 - && (defined(SQLITE_TEST) || defined(SQLITE_ENABLE_SELECTTRACE))
14438 -# define SELECTTRACE_ENABLED 1
14540 + && (defined(SQLITE_TEST) || defined(SQLITE_ENABLE_SELECTTRACE) \
14541 + || defined(SQLITE_ENABLE_TREETRACE))
14542 +# define TREETRACE_ENABLED 1
14543 # define SELECTTRACE(K,P,S,X) \
14440 - if(sqlite3SelectTrace&(K)) \
14544 + if(sqlite3TreeTrace&(K)) \
14545 sqlite3DebugPrintf("%u/%d/%p: ",(S)->selId,(P)->addrExplain,(S)),\
14546 sqlite3DebugPrintf X
14547 #else
14548 # define SELECTTRACE(K,P,S,X)
14445 -# define SELECTTRACE_ENABLED 0
14549 +# define TREETRACE_ENABLED 0
14550 #endif
14551
14552 /*
@@ -14527,7 +14631,7 @@ struct BusyHandler {
14631 ** pointer will work here as long as it is distinct from SQLITE_STATIC
14632 ** and SQLITE_TRANSIENT.
14633 */
14530 -#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3OomFault)
14634 +#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3OomClear)
14635
14636 /*
14637 ** When SQLITE_OMIT_WSD is defined, it means that the target platform does
@@ -14596,6 +14700,7 @@ typedef struct FuncDef FuncDef;
14700 typedef struct FuncDefHash FuncDefHash;
14701 typedef struct IdList IdList;
14702 typedef struct Index Index;
14703 +typedef struct IndexedExpr IndexedExpr;
14704 typedef struct IndexSample IndexSample;
14705 typedef struct KeyClass KeyClass;
14706 typedef struct KeyInfo KeyInfo;
@@ -14603,6 +14708,7 @@ typedef struct Lookaside Lookaside;
14708 typedef struct LookasideSlot LookasideSlot;
14709 typedef struct Module Module;
14710 typedef struct NameContext NameContext;
14711 +typedef struct OnOrUsing OnOrUsing;
14712 typedef struct Parse Parse;
14713 typedef struct ParseCleanup ParseCleanup;
14714 typedef struct PreUpdate PreUpdate;
@@ -14660,6 +14766,7 @@ typedef struct With With;
14766 #define MASKBIT32(n) (((unsigned int)1)<<(n))
14767 #define SMASKBIT32(n) ((n)<=31?((unsigned int)1)<<(n):0)
14768 #define ALLBITS ((Bitmask)-1)
14769 +#define TOPBIT (((Bitmask)1)<<(BMS-1))
14770
14771 /* A VList object records a mapping between parameters/variables/wildcards
14772 ** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
@@ -14674,6 +14781,331 @@ typedef int VList;
14781 ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
14782 ** pointer types (i.e. FuncDef) defined above.
14783 */
14784 +/************** Include os.h in the middle of sqliteInt.h ********************/
14785 +/************** Begin file os.h **********************************************/
14786 +/*
14787 +** 2001 September 16
14788 +**
14789 +** The author disclaims copyright to this source code. In place of
14790 +** a legal notice, here is a blessing:
14791 +**
14792 +** May you do good and not evil.
14793 +** May you find forgiveness for yourself and forgive others.
14794 +** May you share freely, never taking more than you give.
14795 +**
14796 +******************************************************************************
14797 +**
14798 +** This header file (together with is companion C source-code file
14799 +** "os.c") attempt to abstract the underlying operating system so that
14800 +** the SQLite library will work on both POSIX and windows systems.
14801 +**
14802 +** This header file is #include-ed by sqliteInt.h and thus ends up
14803 +** being included by every source file.
14804 +*/
14805 +#ifndef _SQLITE_OS_H_
14806 +#define _SQLITE_OS_H_
14807 +
14808 +/*
14809 +** Attempt to automatically detect the operating system and setup the
14810 +** necessary pre-processor macros for it.
14811 +*/
14812 +/************** Include os_setup.h in the middle of os.h *********************/
14813 +/************** Begin file os_setup.h ****************************************/
14814 +/*
14815 +** 2013 November 25
14816 +**
14817 +** The author disclaims copyright to this source code. In place of
14818 +** a legal notice, here is a blessing:
14819 +**
14820 +** May you do good and not evil.
14821 +** May you find forgiveness for yourself and forgive others.
14822 +** May you share freely, never taking more than you give.
14823 +**
14824 +******************************************************************************
14825 +**
14826 +** This file contains pre-processor directives related to operating system
14827 +** detection and/or setup.
14828 +*/
14829 +#ifndef SQLITE_OS_SETUP_H
14830 +#define SQLITE_OS_SETUP_H
14831 +
14832 +/*
14833 +** Figure out if we are dealing with Unix, Windows, or some other operating
14834 +** system.
14835 +**
14836 +** After the following block of preprocess macros, all of
14837 +**
14838 +** SQLITE_OS_KV
14839 +** SQLITE_OS_OTHER
14840 +** SQLITE_OS_UNIX
14841 +** SQLITE_OS_WIN
14842 +**
14843 +** will defined to either 1 or 0. One of them will be 1. The others will be 0.
14844 +** If none of the macros are initially defined, then select either
14845 +** SQLITE_OS_UNIX or SQLITE_OS_WIN depending on the target platform.
14846 +**
14847 +** If SQLITE_OS_OTHER=1 is specified at compile-time, then the application
14848 +** must provide its own VFS implementation together with sqlite3_os_init()
14849 +** and sqlite3_os_end() routines.
14850 +*/
14851 +#if !defined(SQLITE_OS_KV) && !defined(SQLITE_OS_OTHER) && \
14852 + !defined(SQLITE_OS_UNIX) && !defined(SQLITE_OS_WIN)
14853 +# if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || \
14854 + defined(__MINGW32__) || defined(__BORLANDC__)
14855 +# define SQLITE_OS_WIN 1
14856 +# define SQLITE_OS_UNIX 0
14857 +# else
14858 +# define SQLITE_OS_WIN 0
14859 +# define SQLITE_OS_UNIX 1
14860 +# endif
14861 +#endif
14862 +#if SQLITE_OS_OTHER+1>1
14863 +# undef SQLITE_OS_KV
14864 +# define SQLITE_OS_KV 0
14865 +# undef SQLITE_OS_UNIX
14866 +# define SQLITE_OS_UNIX 0
14867 +# undef SQLITE_OS_WIN
14868 +# define SQLITE_OS_WIN 0
14869 +#endif
14870 +#if SQLITE_OS_KV+1>1
14871 +# undef SQLITE_OS_OTHER
14872 +# define SQLITE_OS_OTHER 0
14873 +# undef SQLITE_OS_UNIX
14874 +# define SQLITE_OS_UNIX 0
14875 +# undef SQLITE_OS_WIN
14876 +# define SQLITE_OS_WIN 0
14877 +# define SQLITE_OMIT_LOAD_EXTENSION 1
14878 +# define SQLITE_OMIT_WAL 1
14879 +# define SQLITE_OMIT_DEPRECATED 1
14880 +# undef SQLITE_TEMP_STORE
14881 +# define SQLITE_TEMP_STORE 3 /* Always use memory for temporary storage */
14882 +# define SQLITE_DQS 0
14883 +# define SQLITE_OMIT_SHARED_CACHE 1
14884 +# define SQLITE_OMIT_AUTOINIT 1
14885 +#endif
14886 +#if SQLITE_OS_UNIX+1>1
14887 +# undef SQLITE_OS_KV
14888 +# define SQLITE_OS_KV 0
14889 +# undef SQLITE_OS_OTHER
14890 +# define SQLITE_OS_OTHER 0
14891 +# undef SQLITE_OS_WIN
14892 +# define SQLITE_OS_WIN 0
14893 +#endif
14894 +#if SQLITE_OS_WIN+1>1
14895 +# undef SQLITE_OS_KV
14896 +# define SQLITE_OS_KV 0
14897 +# undef SQLITE_OS_OTHER
14898 +# define SQLITE_OS_OTHER 0
14899 +# undef SQLITE_OS_UNIX
14900 +# define SQLITE_OS_UNIX 0
14901 +#endif
14902 +
14903 +
14904 +#endif /* SQLITE_OS_SETUP_H */
14905 +
14906 +/************** End of os_setup.h ********************************************/
14907 +/************** Continuing where we left off in os.h *************************/
14908 +
14909 +/* If the SET_FULLSYNC macro is not defined above, then make it
14910 +** a no-op
14911 +*/
14912 +#ifndef SET_FULLSYNC
14913 +# define SET_FULLSYNC(x,y)
14914 +#endif
14915 +
14916 +/* Maximum pathname length. Note: FILENAME_MAX defined by stdio.h
14917 +*/
14918 +#ifndef SQLITE_MAX_PATHLEN
14919 +# define SQLITE_MAX_PATHLEN FILENAME_MAX
14920 +#endif
14921 +
14922 +/* Maximum number of symlinks that will be resolved while trying to
14923 +** expand a filename in xFullPathname() in the VFS.
14924 +*/
14925 +#ifndef SQLITE_MAX_SYMLINK
14926 +# define SQLITE_MAX_SYMLINK 200
14927 +#endif
14928 +
14929 +/*
14930 +** The default size of a disk sector
14931 +*/
14932 +#ifndef SQLITE_DEFAULT_SECTOR_SIZE
14933 +# define SQLITE_DEFAULT_SECTOR_SIZE 4096
14934 +#endif
14935 +
14936 +/*
14937 +** Temporary files are named starting with this prefix followed by 16 random
14938 +** alphanumeric characters, and no file extension. They are stored in the
14939 +** OS's standard temporary file directory, and are deleted prior to exit.
14940 +** If sqlite is being embedded in another program, you may wish to change the
14941 +** prefix to reflect your program's name, so that if your program exits
14942 +** prematurely, old temporary files can be easily identified. This can be done
14943 +** using -DSQLITE_TEMP_FILE_PREFIX=myprefix_ on the compiler command line.
14944 +**
14945 +** 2006-10-31: The default prefix used to be "sqlite_". But then
14946 +** Mcafee started using SQLite in their anti-virus product and it
14947 +** started putting files with the "sqlite" name in the c:/temp folder.
14948 +** This annoyed many windows users. Those users would then do a
14949 +** Google search for "sqlite", find the telephone numbers of the
14950 +** developers and call to wake them up at night and complain.
14951 +** For this reason, the default name prefix is changed to be "sqlite"
14952 +** spelled backwards. So the temp files are still identified, but
14953 +** anybody smart enough to figure out the code is also likely smart
14954 +** enough to know that calling the developer will not help get rid
14955 +** of the file.
14956 +*/
14957 +#ifndef SQLITE_TEMP_FILE_PREFIX
14958 +# define SQLITE_TEMP_FILE_PREFIX "etilqs_"
14959 +#endif
14960 +
14961 +/*
14962 +** The following values may be passed as the second argument to
14963 +** sqlite3OsLock(). The various locks exhibit the following semantics:
14964 +**
14965 +** SHARED: Any number of processes may hold a SHARED lock simultaneously.
14966 +** RESERVED: A single process may hold a RESERVED lock on a file at
14967 +** any time. Other processes may hold and obtain new SHARED locks.
14968 +** PENDING: A single process may hold a PENDING lock on a file at
14969 +** any one time. Existing SHARED locks may persist, but no new
14970 +** SHARED locks may be obtained by other processes.
14971 +** EXCLUSIVE: An EXCLUSIVE lock precludes all other locks.
14972 +**
14973 +** PENDING_LOCK may not be passed directly to sqlite3OsLock(). Instead, a
14974 +** process that requests an EXCLUSIVE lock may actually obtain a PENDING
14975 +** lock. This can be upgraded to an EXCLUSIVE lock by a subsequent call to
14976 +** sqlite3OsLock().
14977 +*/
14978 +#define NO_LOCK 0
14979 +#define SHARED_LOCK 1
14980 +#define RESERVED_LOCK 2
14981 +#define PENDING_LOCK 3
14982 +#define EXCLUSIVE_LOCK 4
14983 +
14984 +/*
14985 +** File Locking Notes: (Mostly about windows but also some info for Unix)
14986 +**
14987 +** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because
14988 +** those functions are not available. So we use only LockFile() and
14989 +** UnlockFile().
14990 +**
14991 +** LockFile() prevents not just writing but also reading by other processes.
14992 +** A SHARED_LOCK is obtained by locking a single randomly-chosen
14993 +** byte out of a specific range of bytes. The lock byte is obtained at
14994 +** random so two separate readers can probably access the file at the
14995 +** same time, unless they are unlucky and choose the same lock byte.
14996 +** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range.
14997 +** There can only be one writer. A RESERVED_LOCK is obtained by locking
14998 +** a single byte of the file that is designated as the reserved lock byte.
14999 +** A PENDING_LOCK is obtained by locking a designated byte different from
15000 +** the RESERVED_LOCK byte.
15001 +**
15002 +** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available,
15003 +** which means we can use reader/writer locks. When reader/writer locks
15004 +** are used, the lock is placed on the same range of bytes that is used
15005 +** for probabilistic locking in Win95/98/ME. Hence, the locking scheme
15006 +** will support two or more Win95 readers or two or more WinNT readers.
15007 +** But a single Win95 reader will lock out all WinNT readers and a single
15008 +** WinNT reader will lock out all other Win95 readers.
15009 +**
15010 +** The following #defines specify the range of bytes used for locking.
15011 +** SHARED_SIZE is the number of bytes available in the pool from which
15012 +** a random byte is selected for a shared lock. The pool of bytes for
15013 +** shared locks begins at SHARED_FIRST.
15014 +**
15015 +** The same locking strategy and
15016 +** byte ranges are used for Unix. This leaves open the possibility of having
15017 +** clients on win95, winNT, and unix all talking to the same shared file
15018 +** and all locking correctly. To do so would require that samba (or whatever
15019 +** tool is being used for file sharing) implements locks correctly between
15020 +** windows and unix. I'm guessing that isn't likely to happen, but by
15021 +** using the same locking range we are at least open to the possibility.
15022 +**
15023 +** Locking in windows is manditory. For this reason, we cannot store
15024 +** actual data in the bytes used for locking. The pager never allocates
15025 +** the pages involved in locking therefore. SHARED_SIZE is selected so
15026 +** that all locks will fit on a single page even at the minimum page size.
15027 +** PENDING_BYTE defines the beginning of the locks. By default PENDING_BYTE
15028 +** is set high so that we don't have to allocate an unused page except
15029 +** for very large databases. But one should test the page skipping logic
15030 +** by setting PENDING_BYTE low and running the entire regression suite.
15031 +**
15032 +** Changing the value of PENDING_BYTE results in a subtly incompatible
15033 +** file format. Depending on how it is changed, you might not notice
15034 +** the incompatibility right away, even running a full regression test.
15035 +** The default location of PENDING_BYTE is the first byte past the
15036 +** 1GB boundary.
15037 +**
15038 +*/
15039 +#ifdef SQLITE_OMIT_WSD
15040 +# define PENDING_BYTE (0x40000000)
15041 +#else
15042 +# define PENDING_BYTE sqlite3PendingByte
15043 +#endif
15044 +#define RESERVED_BYTE (PENDING_BYTE+1)
15045 +#define SHARED_FIRST (PENDING_BYTE+2)
15046 +#define SHARED_SIZE 510
15047 +
15048 +/*
15049 +** Wrapper around OS specific sqlite3_os_init() function.
15050 +*/
15051 +SQLITE_PRIVATE int sqlite3OsInit(void);
15052 +
15053 +/*
15054 +** Functions for accessing sqlite3_file methods
15055 +*/
15056 +SQLITE_PRIVATE void sqlite3OsClose(sqlite3_file*);
15057 +SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset);
15058 +SQLITE_PRIVATE int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offset);
15059 +SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file*, i64 size);
15060 +SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file*, int);
15061 +SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize);
15062 +SQLITE_PRIVATE int sqlite3OsLock(sqlite3_file*, int);
15063 +SQLITE_PRIVATE int sqlite3OsUnlock(sqlite3_file*, int);
15064 +SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut);
15065 +SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file*,int,void*);
15066 +SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file*,int,void*);
15067 +#define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0
15068 +SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id);
15069 +SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id);
15070 +#ifndef SQLITE_OMIT_WAL
15071 +SQLITE_PRIVATE int sqlite3OsShmMap(sqlite3_file *,int,int,int,void volatile **);
15072 +SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int, int, int);
15073 +SQLITE_PRIVATE void sqlite3OsShmBarrier(sqlite3_file *id);
15074 +SQLITE_PRIVATE int sqlite3OsShmUnmap(sqlite3_file *id, int);
15075 +#endif /* SQLITE_OMIT_WAL */
15076 +SQLITE_PRIVATE int sqlite3OsFetch(sqlite3_file *id, i64, int, void **);
15077 +SQLITE_PRIVATE int sqlite3OsUnfetch(sqlite3_file *, i64, void *);
15078 +
15079 +
15080 +/*
15081 +** Functions for accessing sqlite3_vfs methods
15082 +*/
15083 +SQLITE_PRIVATE int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *);
15084 +SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *, const char *, int);
15085 +SQLITE_PRIVATE int sqlite3OsAccess(sqlite3_vfs *, const char *, int, int *pResOut);
15086 +SQLITE_PRIVATE int sqlite3OsFullPathname(sqlite3_vfs *, const char *, int, char *);
15087 +#ifndef SQLITE_OMIT_LOAD_EXTENSION
15088 +SQLITE_PRIVATE void *sqlite3OsDlOpen(sqlite3_vfs *, const char *);
15089 +SQLITE_PRIVATE void sqlite3OsDlError(sqlite3_vfs *, int, char *);
15090 +SQLITE_PRIVATE void (*sqlite3OsDlSym(sqlite3_vfs *, void *, const char *))(void);
15091 +SQLITE_PRIVATE void sqlite3OsDlClose(sqlite3_vfs *, void *);
15092 +#endif /* SQLITE_OMIT_LOAD_EXTENSION */
15093 +SQLITE_PRIVATE int sqlite3OsRandomness(sqlite3_vfs *, int, char *);
15094 +SQLITE_PRIVATE int sqlite3OsSleep(sqlite3_vfs *, int);
15095 +SQLITE_PRIVATE int sqlite3OsGetLastError(sqlite3_vfs*);
15096 +SQLITE_PRIVATE int sqlite3OsCurrentTimeInt64(sqlite3_vfs *, sqlite3_int64*);
15097 +
15098 +/*
15099 +** Convenience functions for opening and closing files using
15100 +** sqlite3_malloc() to obtain space for the file-handle structure.
15101 +*/
15102 +SQLITE_PRIVATE int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int,int*);
15103 +SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *);
15104 +
15105 +#endif /* _SQLITE_OS_H_ */
15106 +
15107 +/************** End of os.h **************************************************/
15108 +/************** Continuing where we left off in sqliteInt.h ******************/
15109 /************** Include pager.h in the middle of sqliteInt.h *****************/
15110 /************** Begin file pager.h *******************************************/
15111 /*
@@ -14721,14 +15153,15 @@ typedef struct Pager Pager;
15153 typedef struct PgHdr DbPage;
15154
15155 /*
14724 -** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
15156 +** Page number PAGER_SJ_PGNO is never used in an SQLite database (it is
15157 ** reserved for working around a windows/posix incompatibility). It is
15158 ** used in the journal to signify that the remainder of the journal file
15159 ** is devoted to storing a super-journal name - there are no more pages to
15160 ** roll back. See comments for function writeSuperJournal() in pager.c
15161 ** for details.
15162 */
14731 -#define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
15163 +#define PAGER_SJ_PGNO_COMPUTED(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
15164 +#define PAGER_SJ_PGNO(x) ((x)->lckPgno)
15165
15166 /*
15167 ** Allowed values for the flags parameter to sqlite3PagerOpen().
@@ -15293,6 +15726,8 @@ SQLITE_PRIVATE int sqlite3BtreeCheckpoint(Btree*, int, int *, int *);
15726
15727 SQLITE_PRIVATE int sqlite3BtreeTransferRow(BtCursor*, BtCursor*, i64);
15728
15729 +SQLITE_PRIVATE void sqlite3BtreeClearCache(Btree*);
15730 +
15731 /*
15732 ** If we are not using shared cache, then there is no need to
15733 ** use mutexes to access the BtShared structures. So make the
@@ -15405,7 +15840,6 @@ struct VdbeOp {
15840 #ifdef SQLITE_ENABLE_CURSOR_HINTS
15841 Expr *pExpr; /* Used when p4type is P4_EXPR */
15842 #endif
15408 - int (*xAdvance)(BtCursor *, int);
15843 } p4;
15844 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
15845 char *zComment; /* Comment to improve readability */
@@ -15456,21 +15890,19 @@ typedef struct VdbeOpList VdbeOpList;
15890 #define P4_COLLSEQ (-2) /* P4 is a pointer to a CollSeq structure */
15891 #define P4_INT32 (-3) /* P4 is a 32-bit signed integer */
15892 #define P4_SUBPROGRAM (-4) /* P4 is a pointer to a SubProgram structure */
15459 -#define P4_ADVANCE (-5) /* P4 is a pointer to BtreeNext() or BtreePrev() */
15460 -#define P4_TABLE (-6) /* P4 is a pointer to a Table structure */
15893 +#define P4_TABLE (-5) /* P4 is a pointer to a Table structure */
15894 /* Above do not own any resources. Must free those below */
15462 -#define P4_FREE_IF_LE (-7)
15463 -#define P4_DYNAMIC (-7) /* Pointer to memory from sqliteMalloc() */
15464 -#define P4_FUNCDEF (-8) /* P4 is a pointer to a FuncDef structure */
15465 -#define P4_KEYINFO (-9) /* P4 is a pointer to a KeyInfo structure */
15466 -#define P4_EXPR (-10) /* P4 is a pointer to an Expr tree */
15467 -#define P4_MEM (-11) /* P4 is a pointer to a Mem* structure */
15468 -#define P4_VTAB (-12) /* P4 is a pointer to an sqlite3_vtab structure */
15469 -#define P4_REAL (-13) /* P4 is a 64-bit floating point value */
15470 -#define P4_INT64 (-14) /* P4 is a 64-bit signed integer */
15471 -#define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
15472 -#define P4_FUNCCTX (-16) /* P4 is a pointer to an sqlite3_context object */
15473 -#define P4_DYNBLOB (-17) /* Pointer to memory from sqliteMalloc() */
15895 +#define P4_FREE_IF_LE (-6)
15896 +#define P4_DYNAMIC (-6) /* Pointer to memory from sqliteMalloc() */
15897 +#define P4_FUNCDEF (-7) /* P4 is a pointer to a FuncDef structure */
15898 +#define P4_KEYINFO (-8) /* P4 is a pointer to a KeyInfo structure */
15899 +#define P4_EXPR (-9) /* P4 is a pointer to an Expr tree */
15900 +#define P4_MEM (-10) /* P4 is a pointer to a Mem* structure */
15901 +#define P4_VTAB (-11) /* P4 is a pointer to an sqlite3_vtab structure */
15902 +#define P4_REAL (-12) /* P4 is a 64-bit floating point value */
15903 +#define P4_INT64 (-13) /* P4 is a 64-bit signed integer */
15904 +#define P4_INTARRAY (-14) /* P4 is a vector of 32-bit integers */
15905 +#define P4_FUNCCTX (-15) /* P4 is a pointer to an sqlite3_context object */
15906
15907 /* Error message codes for OP_Halt */
15908 #define P5_ConstraintNotNull 1
@@ -15515,53 +15947,53 @@ typedef struct VdbeOpList VdbeOpList;
15947 #define OP_Savepoint 0
15948 #define OP_AutoCommit 1
15949 #define OP_Transaction 2
15518 -#define OP_SorterNext 3 /* jump */
15519 -#define OP_Prev 4 /* jump */
15520 -#define OP_Next 5 /* jump */
15521 -#define OP_Checkpoint 6
15522 -#define OP_JournalMode 7
15523 -#define OP_Vacuum 8
15524 -#define OP_VFilter 9 /* jump, synopsis: iplan=r[P3] zplan='P4' */
15525 -#define OP_VUpdate 10 /* synopsis: data=r[P3@P2] */
15526 -#define OP_Goto 11 /* jump */
15527 -#define OP_Gosub 12 /* jump */
15528 -#define OP_InitCoroutine 13 /* jump */
15529 -#define OP_Yield 14 /* jump */
15530 -#define OP_MustBeInt 15 /* jump */
15531 -#define OP_Jump 16 /* jump */
15532 -#define OP_Once 17 /* jump */
15533 -#define OP_If 18 /* jump */
15950 +#define OP_Checkpoint 3
15951 +#define OP_JournalMode 4
15952 +#define OP_Vacuum 5
15953 +#define OP_VFilter 6 /* jump, synopsis: iplan=r[P3] zplan='P4' */
15954 +#define OP_VUpdate 7 /* synopsis: data=r[P3@P2] */
15955 +#define OP_Init 8 /* jump, synopsis: Start at P2 */
15956 +#define OP_Goto 9 /* jump */
15957 +#define OP_Gosub 10 /* jump */
15958 +#define OP_InitCoroutine 11 /* jump */
15959 +#define OP_Yield 12 /* jump */
15960 +#define OP_MustBeInt 13 /* jump */
15961 +#define OP_Jump 14 /* jump */
15962 +#define OP_Once 15 /* jump */
15963 +#define OP_If 16 /* jump */
15964 +#define OP_IfNot 17 /* jump */
15965 +#define OP_IsType 18 /* jump, synopsis: if typeof(P1.P3) in P5 goto P2 */
15966 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
15535 -#define OP_IfNot 20 /* jump */
15536 -#define OP_IsNullOrType 21 /* jump, synopsis: if typeof(r[P1]) IN (P3,5) goto P2 */
15537 -#define OP_IfNullRow 22 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
15538 -#define OP_SeekLT 23 /* jump, synopsis: key=r[P3@P4] */
15539 -#define OP_SeekLE 24 /* jump, synopsis: key=r[P3@P4] */
15540 -#define OP_SeekGE 25 /* jump, synopsis: key=r[P3@P4] */
15541 -#define OP_SeekGT 26 /* jump, synopsis: key=r[P3@P4] */
15542 -#define OP_IfNotOpen 27 /* jump, synopsis: if( !csr[P1] ) goto P2 */
15543 -#define OP_IfNoHope 28 /* jump, synopsis: key=r[P3@P4] */
15544 -#define OP_NoConflict 29 /* jump, synopsis: key=r[P3@P4] */
15545 -#define OP_NotFound 30 /* jump, synopsis: key=r[P3@P4] */
15546 -#define OP_Found 31 /* jump, synopsis: key=r[P3@P4] */
15547 -#define OP_SeekRowid 32 /* jump, synopsis: intkey=r[P3] */
15548 -#define OP_NotExists 33 /* jump, synopsis: intkey=r[P3] */
15549 -#define OP_Last 34 /* jump */
15550 -#define OP_IfSmaller 35 /* jump */
15551 -#define OP_SorterSort 36 /* jump */
15552 -#define OP_Sort 37 /* jump */
15553 -#define OP_Rewind 38 /* jump */
15554 -#define OP_IdxLE 39 /* jump, synopsis: key=r[P3@P4] */
15555 -#define OP_IdxGT 40 /* jump, synopsis: key=r[P3@P4] */
15556 -#define OP_IdxLT 41 /* jump, synopsis: key=r[P3@P4] */
15557 -#define OP_IdxGE 42 /* jump, synopsis: key=r[P3@P4] */
15967 +#define OP_IfNullRow 20 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
15968 +#define OP_SeekLT 21 /* jump, synopsis: key=r[P3@P4] */
15969 +#define OP_SeekLE 22 /* jump, synopsis: key=r[P3@P4] */
15970 +#define OP_SeekGE 23 /* jump, synopsis: key=r[P3@P4] */
15971 +#define OP_SeekGT 24 /* jump, synopsis: key=r[P3@P4] */
15972 +#define OP_IfNotOpen 25 /* jump, synopsis: if( !csr[P1] ) goto P2 */
15973 +#define OP_IfNoHope 26 /* jump, synopsis: key=r[P3@P4] */
15974 +#define OP_NoConflict 27 /* jump, synopsis: key=r[P3@P4] */
15975 +#define OP_NotFound 28 /* jump, synopsis: key=r[P3@P4] */
15976 +#define OP_Found 29 /* jump, synopsis: key=r[P3@P4] */
15977 +#define OP_SeekRowid 30 /* jump, synopsis: intkey=r[P3] */
15978 +#define OP_NotExists 31 /* jump, synopsis: intkey=r[P3] */
15979 +#define OP_Last 32 /* jump */
15980 +#define OP_IfSmaller 33 /* jump */
15981 +#define OP_SorterSort 34 /* jump */
15982 +#define OP_Sort 35 /* jump */
15983 +#define OP_Rewind 36 /* jump */
15984 +#define OP_SorterNext 37 /* jump */
15985 +#define OP_Prev 38 /* jump */
15986 +#define OP_Next 39 /* jump */
15987 +#define OP_IdxLE 40 /* jump, synopsis: key=r[P3@P4] */
15988 +#define OP_IdxGT 41 /* jump, synopsis: key=r[P3@P4] */
15989 +#define OP_IdxLT 42 /* jump, synopsis: key=r[P3@P4] */
15990 #define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
15991 #define OP_And 44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
15560 -#define OP_RowSetRead 45 /* jump, synopsis: r[P3]=rowset(P1) */
15561 -#define OP_RowSetTest 46 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
15562 -#define OP_Program 47 /* jump */
15563 -#define OP_FkIfZero 48 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
15564 -#define OP_IfPos 49 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
15992 +#define OP_IdxGE 45 /* jump, synopsis: key=r[P3@P4] */
15993 +#define OP_RowSetRead 46 /* jump, synopsis: r[P3]=rowset(P1) */
15994 +#define OP_RowSetTest 47 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
15995 +#define OP_Program 48 /* jump */
15996 +#define OP_FkIfZero 49 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
15997 #define OP_IsNull 50 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
15998 #define OP_NotNull 51 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
15999 #define OP_Ne 52 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
@@ -15571,12 +16003,12 @@ typedef struct VdbeOpList VdbeOpList;
16003 #define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
16004 #define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
16005 #define OP_ElseEq 58 /* jump, same as TK_ESCAPE */
15574 -#define OP_IfNotZero 59 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
15575 -#define OP_DecrJumpZero 60 /* jump, synopsis: if (--r[P1])==0 goto P2 */
15576 -#define OP_IncrVacuum 61 /* jump */
15577 -#define OP_VNext 62 /* jump */
15578 -#define OP_Filter 63 /* jump, synopsis: if key(P3@P4) not in filter(P1) goto P2 */
15579 -#define OP_Init 64 /* jump, synopsis: Start at P2 */
16006 +#define OP_IfPos 59 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
16007 +#define OP_IfNotZero 60 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
16008 +#define OP_DecrJumpZero 61 /* jump, synopsis: if (--r[P1])==0 goto P2 */
16009 +#define OP_IncrVacuum 62 /* jump */
16010 +#define OP_VNext 63 /* jump */
16011 +#define OP_Filter 64 /* jump, synopsis: if key(P3@P4) not in filter(P1) goto P2 */
16012 #define OP_PureFunc 65 /* synopsis: r[P3]=func(r[P2@NP]) */
16013 #define OP_Function 66 /* synopsis: r[P3]=func(r[P2@NP]) */
16014 #define OP_Return 67
@@ -15586,34 +16018,34 @@ typedef struct VdbeOpList VdbeOpList;
16018 #define OP_Integer 71 /* synopsis: r[P2]=P1 */
16019 #define OP_Int64 72 /* synopsis: r[P2]=P4 */
16020 #define OP_String 73 /* synopsis: r[P2]='P4' (len=P1) */
15589 -#define OP_Null 74 /* synopsis: r[P2..P3]=NULL */
15590 -#define OP_SoftNull 75 /* synopsis: r[P1]=NULL */
15591 -#define OP_Blob 76 /* synopsis: r[P2]=P4 (len=P1) */
15592 -#define OP_Variable 77 /* synopsis: r[P2]=parameter(P1,P4) */
15593 -#define OP_Move 78 /* synopsis: r[P2@P3]=r[P1@P3] */
15594 -#define OP_Copy 79 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
15595 -#define OP_SCopy 80 /* synopsis: r[P2]=r[P1] */
15596 -#define OP_IntCopy 81 /* synopsis: r[P2]=r[P1] */
15597 -#define OP_FkCheck 82
15598 -#define OP_ResultRow 83 /* synopsis: output=r[P1@P2] */
15599 -#define OP_CollSeq 84
15600 -#define OP_AddImm 85 /* synopsis: r[P1]=r[P1]+P2 */
15601 -#define OP_RealAffinity 86
15602 -#define OP_Cast 87 /* synopsis: affinity(r[P1]) */
15603 -#define OP_Permutation 88
15604 -#define OP_Compare 89 /* synopsis: r[P1@P3] <-> r[P2@P3] */
15605 -#define OP_IsTrue 90 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
15606 -#define OP_ZeroOrNull 91 /* synopsis: r[P2] = 0 OR NULL */
15607 -#define OP_Offset 92 /* synopsis: r[P3] = sqlite_offset(P1) */
15608 -#define OP_Column 93 /* synopsis: r[P3]=PX */
15609 -#define OP_TypeCheck 94 /* synopsis: typecheck(r[P1@P2]) */
15610 -#define OP_Affinity 95 /* synopsis: affinity(r[P1@P2]) */
15611 -#define OP_MakeRecord 96 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
15612 -#define OP_Count 97 /* synopsis: r[P2]=count() */
15613 -#define OP_ReadCookie 98
15614 -#define OP_SetCookie 99
15615 -#define OP_ReopenIdx 100 /* synopsis: root=P2 iDb=P3 */
15616 -#define OP_OpenRead 101 /* synopsis: root=P2 iDb=P3 */
16021 +#define OP_BeginSubrtn 74 /* synopsis: r[P2]=NULL */
16022 +#define OP_Null 75 /* synopsis: r[P2..P3]=NULL */
16023 +#define OP_SoftNull 76 /* synopsis: r[P1]=NULL */
16024 +#define OP_Blob 77 /* synopsis: r[P2]=P4 (len=P1) */
16025 +#define OP_Variable 78 /* synopsis: r[P2]=parameter(P1,P4) */
16026 +#define OP_Move 79 /* synopsis: r[P2@P3]=r[P1@P3] */
16027 +#define OP_Copy 80 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
16028 +#define OP_SCopy 81 /* synopsis: r[P2]=r[P1] */
16029 +#define OP_IntCopy 82 /* synopsis: r[P2]=r[P1] */
16030 +#define OP_FkCheck 83
16031 +#define OP_ResultRow 84 /* synopsis: output=r[P1@P2] */
16032 +#define OP_CollSeq 85
16033 +#define OP_AddImm 86 /* synopsis: r[P1]=r[P1]+P2 */
16034 +#define OP_RealAffinity 87
16035 +#define OP_Cast 88 /* synopsis: affinity(r[P1]) */
16036 +#define OP_Permutation 89
16037 +#define OP_Compare 90 /* synopsis: r[P1@P3] <-> r[P2@P3] */
16038 +#define OP_IsTrue 91 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
16039 +#define OP_ZeroOrNull 92 /* synopsis: r[P2] = 0 OR NULL */
16040 +#define OP_Offset 93 /* synopsis: r[P3] = sqlite_offset(P1) */
16041 +#define OP_Column 94 /* synopsis: r[P3]=PX cursor P1 column P2 */
16042 +#define OP_TypeCheck 95 /* synopsis: typecheck(r[P1@P2]) */
16043 +#define OP_Affinity 96 /* synopsis: affinity(r[P1@P2]) */
16044 +#define OP_MakeRecord 97 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
16045 +#define OP_Count 98 /* synopsis: r[P2]=count() */
16046 +#define OP_ReadCookie 99
16047 +#define OP_SetCookie 100
16048 +#define OP_ReopenIdx 101 /* synopsis: root=P2 iDb=P3 */
16049 #define OP_BitAnd 102 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
16050 #define OP_BitOr 103 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
16051 #define OP_ShiftLeft 104 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
@@ -15624,79 +16056,81 @@ typedef struct VdbeOpList VdbeOpList;
16056 #define OP_Divide 109 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
16057 #define OP_Remainder 110 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
16058 #define OP_Concat 111 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
15627 -#define OP_OpenWrite 112 /* synopsis: root=P2 iDb=P3 */
15628 -#define OP_OpenDup 113
16059 +#define OP_OpenRead 112 /* synopsis: root=P2 iDb=P3 */
16060 +#define OP_OpenWrite 113 /* synopsis: root=P2 iDb=P3 */
16061 #define OP_BitNot 114 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
15630 -#define OP_OpenAutoindex 115 /* synopsis: nColumn=P2 */
15631 -#define OP_OpenEphemeral 116 /* synopsis: nColumn=P2 */
16062 +#define OP_OpenDup 115
16063 +#define OP_OpenAutoindex 116 /* synopsis: nColumn=P2 */
16064 #define OP_String8 117 /* same as TK_STRING, synopsis: r[P2]='P4' */
15633 -#define OP_SorterOpen 118
15634 -#define OP_SequenceTest 119 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
15635 -#define OP_OpenPseudo 120 /* synopsis: P3 columns in r[P2] */
15636 -#define OP_Close 121
15637 -#define OP_ColumnsUsed 122
15638 -#define OP_SeekScan 123 /* synopsis: Scan-ahead up to P1 rows */
15639 -#define OP_SeekHit 124 /* synopsis: set P2<=seekHit<=P3 */
15640 -#define OP_Sequence 125 /* synopsis: r[P2]=cursor[P1].ctr++ */
15641 -#define OP_NewRowid 126 /* synopsis: r[P2]=rowid */
15642 -#define OP_Insert 127 /* synopsis: intkey=r[P3] data=r[P2] */
15643 -#define OP_RowCell 128
15644 -#define OP_Delete 129
15645 -#define OP_ResetCount 130
15646 -#define OP_SorterCompare 131 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
15647 -#define OP_SorterData 132 /* synopsis: r[P2]=data */
15648 -#define OP_RowData 133 /* synopsis: r[P2]=data */
15649 -#define OP_Rowid 134 /* synopsis: r[P2]=rowid */
15650 -#define OP_NullRow 135
15651 -#define OP_SeekEnd 136
15652 -#define OP_IdxInsert 137 /* synopsis: key=r[P2] */
15653 -#define OP_SorterInsert 138 /* synopsis: key=r[P2] */
15654 -#define OP_IdxDelete 139 /* synopsis: key=r[P2@P3] */
15655 -#define OP_DeferredSeek 140 /* synopsis: Move P3 to P1.rowid if needed */
15656 -#define OP_IdxRowid 141 /* synopsis: r[P2]=rowid */
15657 -#define OP_FinishSeek 142
15658 -#define OP_Destroy 143
15659 -#define OP_Clear 144
15660 -#define OP_ResetSorter 145
15661 -#define OP_CreateBtree 146 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
15662 -#define OP_SqlExec 147
15663 -#define OP_ParseSchema 148
15664 -#define OP_LoadAnalysis 149
15665 -#define OP_DropTable 150
15666 -#define OP_DropIndex 151
15667 -#define OP_DropTrigger 152
16065 +#define OP_OpenEphemeral 118 /* synopsis: nColumn=P2 */
16066 +#define OP_SorterOpen 119
16067 +#define OP_SequenceTest 120 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
16068 +#define OP_OpenPseudo 121 /* synopsis: P3 columns in r[P2] */
16069 +#define OP_Close 122
16070 +#define OP_ColumnsUsed 123
16071 +#define OP_SeekScan 124 /* synopsis: Scan-ahead up to P1 rows */
16072 +#define OP_SeekHit 125 /* synopsis: set P2<=seekHit<=P3 */
16073 +#define OP_Sequence 126 /* synopsis: r[P2]=cursor[P1].ctr++ */
16074 +#define OP_NewRowid 127 /* synopsis: r[P2]=rowid */
16075 +#define OP_Insert 128 /* synopsis: intkey=r[P3] data=r[P2] */
16076 +#define OP_RowCell 129
16077 +#define OP_Delete 130
16078 +#define OP_ResetCount 131
16079 +#define OP_SorterCompare 132 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
16080 +#define OP_SorterData 133 /* synopsis: r[P2]=data */
16081 +#define OP_RowData 134 /* synopsis: r[P2]=data */
16082 +#define OP_Rowid 135 /* synopsis: r[P2]=PX rowid of P1 */
16083 +#define OP_NullRow 136
16084 +#define OP_SeekEnd 137
16085 +#define OP_IdxInsert 138 /* synopsis: key=r[P2] */
16086 +#define OP_SorterInsert 139 /* synopsis: key=r[P2] */
16087 +#define OP_IdxDelete 140 /* synopsis: key=r[P2@P3] */
16088 +#define OP_DeferredSeek 141 /* synopsis: Move P3 to P1.rowid if needed */
16089 +#define OP_IdxRowid 142 /* synopsis: r[P2]=rowid */
16090 +#define OP_FinishSeek 143
16091 +#define OP_Destroy 144
16092 +#define OP_Clear 145
16093 +#define OP_ResetSorter 146
16094 +#define OP_CreateBtree 147 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
16095 +#define OP_SqlExec 148
16096 +#define OP_ParseSchema 149
16097 +#define OP_LoadAnalysis 150
16098 +#define OP_DropTable 151
16099 +#define OP_DropIndex 152
16100 #define OP_Real 153 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
15669 -#define OP_IntegrityCk 154
15670 -#define OP_RowSetAdd 155 /* synopsis: rowset(P1)=r[P2] */
15671 -#define OP_Param 156
15672 -#define OP_FkCounter 157 /* synopsis: fkctr[P1]+=P2 */
15673 -#define OP_MemMax 158 /* synopsis: r[P1]=max(r[P1],r[P2]) */
15674 -#define OP_OffsetLimit 159 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
15675 -#define OP_AggInverse 160 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */
15676 -#define OP_AggStep 161 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15677 -#define OP_AggStep1 162 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15678 -#define OP_AggValue 163 /* synopsis: r[P3]=value N=P2 */
15679 -#define OP_AggFinal 164 /* synopsis: accum=r[P1] N=P2 */
15680 -#define OP_Expire 165
15681 -#define OP_CursorLock 166
15682 -#define OP_CursorUnlock 167
15683 -#define OP_TableLock 168 /* synopsis: iDb=P1 root=P2 write=P3 */
15684 -#define OP_VBegin 169
15685 -#define OP_VCreate 170
15686 -#define OP_VDestroy 171
15687 -#define OP_VOpen 172
15688 -#define OP_VInitIn 173 /* synopsis: r[P2]=ValueList(P1,P3) */
15689 -#define OP_VColumn 174 /* synopsis: r[P3]=vcolumn(P2) */
15690 -#define OP_VRename 175
15691 -#define OP_Pagecount 176
15692 -#define OP_MaxPgcnt 177
15693 -#define OP_FilterAdd 178 /* synopsis: filter(P1) += key(P3@P4) */
15694 -#define OP_Trace 179
15695 -#define OP_CursorHint 180
15696 -#define OP_ReleaseReg 181 /* synopsis: release r[P1@P2] mask P3 */
15697 -#define OP_Noop 182
15698 -#define OP_Explain 183
15699 -#define OP_Abortable 184
16101 +#define OP_DropTrigger 154
16102 +#define OP_IntegrityCk 155
16103 +#define OP_RowSetAdd 156 /* synopsis: rowset(P1)=r[P2] */
16104 +#define OP_Param 157
16105 +#define OP_FkCounter 158 /* synopsis: fkctr[P1]+=P2 */
16106 +#define OP_MemMax 159 /* synopsis: r[P1]=max(r[P1],r[P2]) */
16107 +#define OP_OffsetLimit 160 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
16108 +#define OP_AggInverse 161 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */
16109 +#define OP_AggStep 162 /* synopsis: accum=r[P3] step(r[P2@P5]) */
16110 +#define OP_AggStep1 163 /* synopsis: accum=r[P3] step(r[P2@P5]) */
16111 +#define OP_AggValue 164 /* synopsis: r[P3]=value N=P2 */
16112 +#define OP_AggFinal 165 /* synopsis: accum=r[P1] N=P2 */
16113 +#define OP_Expire 166
16114 +#define OP_CursorLock 167
16115 +#define OP_CursorUnlock 168
16116 +#define OP_TableLock 169 /* synopsis: iDb=P1 root=P2 write=P3 */
16117 +#define OP_VBegin 170
16118 +#define OP_VCreate 171
16119 +#define OP_VDestroy 172
16120 +#define OP_VOpen 173
16121 +#define OP_VInitIn 174 /* synopsis: r[P2]=ValueList(P1,P3) */
16122 +#define OP_VColumn 175 /* synopsis: r[P3]=vcolumn(P2) */
16123 +#define OP_VRename 176
16124 +#define OP_Pagecount 177
16125 +#define OP_MaxPgcnt 178
16126 +#define OP_ClrSubtype 179 /* synopsis: r[P1].subtype = 0 */
16127 +#define OP_FilterAdd 180 /* synopsis: filter(P1) += key(P3@P4) */
16128 +#define OP_Trace 181
16129 +#define OP_CursorHint 182
16130 +#define OP_ReleaseReg 183 /* synopsis: release r[P1@P2] mask P3 */
16131 +#define OP_Noop 184
16132 +#define OP_Explain 185
16133 +#define OP_Abortable 186
16134
16135 /* Properties such as "out2" or "jump" that are specified in
16136 ** comments following the "case" for each opcode in the vdbe.c
@@ -15709,30 +16143,30 @@ typedef struct VdbeOpList VdbeOpList;
16143 #define OPFLG_OUT2 0x10 /* out2: P2 is an output */
16144 #define OPFLG_OUT3 0x20 /* out3: P3 is an output */
16145 #define OPFLG_INITIALIZER {\
15712 -/* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x10,\
15713 -/* 8 */ 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03,\
15714 -/* 16 */ 0x01, 0x01, 0x03, 0x12, 0x03, 0x03, 0x01, 0x09,\
15715 -/* 24 */ 0x09, 0x09, 0x09, 0x01, 0x09, 0x09, 0x09, 0x09,\
15716 -/* 32 */ 0x09, 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
15717 -/* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x23, 0x0b, 0x01,\
15718 -/* 48 */ 0x01, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
15719 -/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x01, 0x01, 0x01,\
16146 +/* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\
16147 +/* 8 */ 0x01, 0x01, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01,\
16148 +/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x09, 0x09, 0x09,\
16149 +/* 24 */ 0x09, 0x01, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
16150 +/* 32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
16151 +/* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x01, 0x23, 0x0b,\
16152 +/* 48 */ 0x01, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
16153 +/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01,\
16154 /* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\
15721 -/* 72 */ 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00,\
15722 -/* 80 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02,\
15723 -/* 88 */ 0x00, 0x00, 0x12, 0x1e, 0x20, 0x00, 0x00, 0x00,\
15724 -/* 96 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x26, 0x26,\
16155 +/* 72 */ 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10, 0x00,\
16156 +/* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02,\
16157 +/* 88 */ 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x00, 0x00,\
16158 +/* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x26, 0x26,\
16159 /* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\
16160 /* 112 */ 0x00, 0x00, 0x12, 0x00, 0x00, 0x10, 0x00, 0x00,\
15727 -/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
15728 -/* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\
15729 -/* 136 */ 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00, 0x10,\
15730 -/* 144 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
15731 -/* 152 */ 0x00, 0x10, 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a,\
15732 -/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15733 -/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,\
15734 -/* 176 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15735 -/* 184 */ 0x00,}
16161 +/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
16162 +/* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
16163 +/* 136 */ 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00,\
16164 +/* 144 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
16165 +/* 152 */ 0x00, 0x10, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
16166 +/* 160 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
16167 +/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\
16168 +/* 176 */ 0x00, 0x10, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00,\
16169 +/* 184 */ 0x00, 0x00, 0x00,}
16170
16171 /* The resolve3P2Values() routine is able to run faster if it knows
16172 ** the value of the largest JUMP opcode. The smaller the maximum
@@ -15778,8 +16212,10 @@ SQLITE_PRIVATE void sqlite3VdbeVerifyNoResultRow(Vdbe *p);
16212 #endif
16213 #if defined(SQLITE_DEBUG)
16214 SQLITE_PRIVATE void sqlite3VdbeVerifyAbortable(Vdbe *p, int);
16215 +SQLITE_PRIVATE void sqlite3VdbeNoJumpsOutsideSubrtn(Vdbe*,int,int,int);
16216 #else
16217 # define sqlite3VdbeVerifyAbortable(A,B)
16218 +# define sqlite3VdbeNoJumpsOutsideSubrtn(A,B,C,D)
16219 #endif
16220 SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp,int iLineno);
16221 #ifndef SQLITE_OMIT_EXPLAIN
@@ -15806,6 +16242,7 @@ SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
16242 SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
16243 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3);
16244 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
16245 +SQLITE_PRIVATE void sqlite3VdbeTypeofColumn(Vdbe*, int);
16246 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
16247 SQLITE_PRIVATE void sqlite3VdbeJumpHereOrPopInst(Vdbe*, int addr);
16248 SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
@@ -15820,11 +16257,11 @@ SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
16257 SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
16258 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
16259 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
16260 +SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetLastOp(Vdbe*);
16261 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Parse*);
16262 SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*);
16263 SQLITE_PRIVATE void sqlite3VdbeReusable(Vdbe*);
16264 SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe*);
15827 -SQLITE_PRIVATE void sqlite3VdbeClearObject(sqlite3*,Vdbe*);
16265 SQLITE_PRIVATE void sqlite3VdbeMakeReady(Vdbe*,Parse*);
16266 SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*);
16267 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int);
@@ -16169,290 +16606,6 @@ SQLITE_PRIVATE int sqlite3PCacheIsDirty(PCache *pCache);
16606
16607 /************** End of pcache.h **********************************************/
16608 /************** Continuing where we left off in sqliteInt.h ******************/
16172 -/************** Include os.h in the middle of sqliteInt.h ********************/
16173 -/************** Begin file os.h **********************************************/
16174 -/*
16175 -** 2001 September 16
16176 -**
16177 -** The author disclaims copyright to this source code. In place of
16178 -** a legal notice, here is a blessing:
16179 -**
16180 -** May you do good and not evil.
16181 -** May you find forgiveness for yourself and forgive others.
16182 -** May you share freely, never taking more than you give.
16183 -**
16184 -******************************************************************************
16185 -**
16186 -** This header file (together with is companion C source-code file
16187 -** "os.c") attempt to abstract the underlying operating system so that
16188 -** the SQLite library will work on both POSIX and windows systems.
16189 -**
16190 -** This header file is #include-ed by sqliteInt.h and thus ends up
16191 -** being included by every source file.
16192 -*/
16193 -#ifndef _SQLITE_OS_H_
16194 -#define _SQLITE_OS_H_
16195 -
16196 -/*
16197 -** Attempt to automatically detect the operating system and setup the
16198 -** necessary pre-processor macros for it.
16199 -*/
16200 -/************** Include os_setup.h in the middle of os.h *********************/
16201 -/************** Begin file os_setup.h ****************************************/
16202 -/*
16203 -** 2013 November 25
16204 -**
16205 -** The author disclaims copyright to this source code. In place of
16206 -** a legal notice, here is a blessing:
16207 -**
16208 -** May you do good and not evil.
16209 -** May you find forgiveness for yourself and forgive others.
16210 -** May you share freely, never taking more than you give.
16211 -**
16212 -******************************************************************************
16213 -**
16214 -** This file contains pre-processor directives related to operating system
16215 -** detection and/or setup.
16216 -*/
16217 -#ifndef SQLITE_OS_SETUP_H
16218 -#define SQLITE_OS_SETUP_H
16219 -
16220 -/*
16221 -** Figure out if we are dealing with Unix, Windows, or some other operating
16222 -** system.
16223 -**
16224 -** After the following block of preprocess macros, all of SQLITE_OS_UNIX,
16225 -** SQLITE_OS_WIN, and SQLITE_OS_OTHER will defined to either 1 or 0. One of
16226 -** the three will be 1. The other two will be 0.
16227 -*/
16228 -#if defined(SQLITE_OS_OTHER)
16229 -# if SQLITE_OS_OTHER==1
16230 -# undef SQLITE_OS_UNIX
16231 -# define SQLITE_OS_UNIX 0
16232 -# undef SQLITE_OS_WIN
16233 -# define SQLITE_OS_WIN 0
16234 -# else
16235 -# undef SQLITE_OS_OTHER
16236 -# endif
16237 -#endif
16238 -#if !defined(SQLITE_OS_UNIX) && !defined(SQLITE_OS_OTHER)
16239 -# define SQLITE_OS_OTHER 0
16240 -# ifndef SQLITE_OS_WIN
16241 -# if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || \
16242 - defined(__MINGW32__) || defined(__BORLANDC__)
16243 -# define SQLITE_OS_WIN 1
16244 -# define SQLITE_OS_UNIX 0
16245 -# else
16246 -# define SQLITE_OS_WIN 0
16247 -# define SQLITE_OS_UNIX 1
16248 -# endif
16249 -# else
16250 -# define SQLITE_OS_UNIX 0
16251 -# endif
16252 -#else
16253 -# ifndef SQLITE_OS_WIN
16254 -# define SQLITE_OS_WIN 0
16255 -# endif
16256 -#endif
16257 -
16258 -#endif /* SQLITE_OS_SETUP_H */
16259 -
16260 -/************** End of os_setup.h ********************************************/
16261 -/************** Continuing where we left off in os.h *************************/
16262 -
16263 -/* If the SET_FULLSYNC macro is not defined above, then make it
16264 -** a no-op
16265 -*/
16266 -#ifndef SET_FULLSYNC
16267 -# define SET_FULLSYNC(x,y)
16268 -#endif
16269 -
16270 -/* Maximum pathname length. Note: FILENAME_MAX defined by stdio.h
16271 -*/
16272 -#ifndef SQLITE_MAX_PATHLEN
16273 -# define SQLITE_MAX_PATHLEN FILENAME_MAX
16274 -#endif
16275 -
16276 -/*
16277 -** The default size of a disk sector
16278 -*/
16279 -#ifndef SQLITE_DEFAULT_SECTOR_SIZE
16280 -# define SQLITE_DEFAULT_SECTOR_SIZE 4096
16281 -#endif
16282 -
16283 -/*
16284 -** Temporary files are named starting with this prefix followed by 16 random
16285 -** alphanumeric characters, and no file extension. They are stored in the
16286 -** OS's standard temporary file directory, and are deleted prior to exit.
16287 -** If sqlite is being embedded in another program, you may wish to change the
16288 -** prefix to reflect your program's name, so that if your program exits
16289 -** prematurely, old temporary files can be easily identified. This can be done
16290 -** using -DSQLITE_TEMP_FILE_PREFIX=myprefix_ on the compiler command line.
16291 -**
16292 -** 2006-10-31: The default prefix used to be "sqlite_". But then
16293 -** Mcafee started using SQLite in their anti-virus product and it
16294 -** started putting files with the "sqlite" name in the c:/temp folder.
16295 -** This annoyed many windows users. Those users would then do a
16296 -** Google search for "sqlite", find the telephone numbers of the
16297 -** developers and call to wake them up at night and complain.
16298 -** For this reason, the default name prefix is changed to be "sqlite"
16299 -** spelled backwards. So the temp files are still identified, but
16300 -** anybody smart enough to figure out the code is also likely smart
16301 -** enough to know that calling the developer will not help get rid
16302 -** of the file.
16303 -*/
16304 -#ifndef SQLITE_TEMP_FILE_PREFIX
16305 -# define SQLITE_TEMP_FILE_PREFIX "etilqs_"
16306 -#endif
16307 -
16308 -/*
16309 -** The following values may be passed as the second argument to
16310 -** sqlite3OsLock(). The various locks exhibit the following semantics:
16311 -**
16312 -** SHARED: Any number of processes may hold a SHARED lock simultaneously.
16313 -** RESERVED: A single process may hold a RESERVED lock on a file at
16314 -** any time. Other processes may hold and obtain new SHARED locks.
16315 -** PENDING: A single process may hold a PENDING lock on a file at
16316 -** any one time. Existing SHARED locks may persist, but no new
16317 -** SHARED locks may be obtained by other processes.
16318 -** EXCLUSIVE: An EXCLUSIVE lock precludes all other locks.
16319 -**
16320 -** PENDING_LOCK may not be passed directly to sqlite3OsLock(). Instead, a
16321 -** process that requests an EXCLUSIVE lock may actually obtain a PENDING
16322 -** lock. This can be upgraded to an EXCLUSIVE lock by a subsequent call to
16323 -** sqlite3OsLock().
16324 -*/
16325 -#define NO_LOCK 0
16326 -#define SHARED_LOCK 1
16327 -#define RESERVED_LOCK 2
16328 -#define PENDING_LOCK 3
16329 -#define EXCLUSIVE_LOCK 4
16330 -
16331 -/*
16332 -** File Locking Notes: (Mostly about windows but also some info for Unix)
16333 -**
16334 -** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because
16335 -** those functions are not available. So we use only LockFile() and
16336 -** UnlockFile().
16337 -**
16338 -** LockFile() prevents not just writing but also reading by other processes.
16339 -** A SHARED_LOCK is obtained by locking a single randomly-chosen
16340 -** byte out of a specific range of bytes. The lock byte is obtained at
16341 -** random so two separate readers can probably access the file at the
16342 -** same time, unless they are unlucky and choose the same lock byte.
16343 -** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range.
16344 -** There can only be one writer. A RESERVED_LOCK is obtained by locking
16345 -** a single byte of the file that is designated as the reserved lock byte.
16346 -** A PENDING_LOCK is obtained by locking a designated byte different from
16347 -** the RESERVED_LOCK byte.
16348 -**
16349 -** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available,
16350 -** which means we can use reader/writer locks. When reader/writer locks
16351 -** are used, the lock is placed on the same range of bytes that is used
16352 -** for probabilistic locking in Win95/98/ME. Hence, the locking scheme
16353 -** will support two or more Win95 readers or two or more WinNT readers.
16354 -** But a single Win95 reader will lock out all WinNT readers and a single
16355 -** WinNT reader will lock out all other Win95 readers.
16356 -**
16357 -** The following #defines specify the range of bytes used for locking.
16358 -** SHARED_SIZE is the number of bytes available in the pool from which
16359 -** a random byte is selected for a shared lock. The pool of bytes for
16360 -** shared locks begins at SHARED_FIRST.
16361 -**
16362 -** The same locking strategy and
16363 -** byte ranges are used for Unix. This leaves open the possibility of having
16364 -** clients on win95, winNT, and unix all talking to the same shared file
16365 -** and all locking correctly. To do so would require that samba (or whatever
16366 -** tool is being used for file sharing) implements locks correctly between
16367 -** windows and unix. I'm guessing that isn't likely to happen, but by
16368 -** using the same locking range we are at least open to the possibility.
16369 -**
16370 -** Locking in windows is manditory. For this reason, we cannot store
16371 -** actual data in the bytes used for locking. The pager never allocates
16372 -** the pages involved in locking therefore. SHARED_SIZE is selected so
16373 -** that all locks will fit on a single page even at the minimum page size.
16374 -** PENDING_BYTE defines the beginning of the locks. By default PENDING_BYTE
16375 -** is set high so that we don't have to allocate an unused page except
16376 -** for very large databases. But one should test the page skipping logic
16377 -** by setting PENDING_BYTE low and running the entire regression suite.
16378 -**
16379 -** Changing the value of PENDING_BYTE results in a subtly incompatible
16380 -** file format. Depending on how it is changed, you might not notice
16381 -** the incompatibility right away, even running a full regression test.
16382 -** The default location of PENDING_BYTE is the first byte past the
16383 -** 1GB boundary.
16384 -**
16385 -*/
16386 -#ifdef SQLITE_OMIT_WSD
16387 -# define PENDING_BYTE (0x40000000)
16388 -#else
16389 -# define PENDING_BYTE sqlite3PendingByte
16390 -#endif
16391 -#define RESERVED_BYTE (PENDING_BYTE+1)
16392 -#define SHARED_FIRST (PENDING_BYTE+2)
16393 -#define SHARED_SIZE 510
16394 -
16395 -/*
16396 -** Wrapper around OS specific sqlite3_os_init() function.
16397 -*/
16398 -SQLITE_PRIVATE int sqlite3OsInit(void);
16399 -
16400 -/*
16401 -** Functions for accessing sqlite3_file methods
16402 -*/
16403 -SQLITE_PRIVATE void sqlite3OsClose(sqlite3_file*);
16404 -SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset);
16405 -SQLITE_PRIVATE int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offset);
16406 -SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file*, i64 size);
16407 -SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file*, int);
16408 -SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize);
16409 -SQLITE_PRIVATE int sqlite3OsLock(sqlite3_file*, int);
16410 -SQLITE_PRIVATE int sqlite3OsUnlock(sqlite3_file*, int);
16411 -SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut);
16412 -SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file*,int,void*);
16413 -SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file*,int,void*);
16414 -#define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0
16415 -SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id);
16416 -SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id);
16417 -#ifndef SQLITE_OMIT_WAL
16418 -SQLITE_PRIVATE int sqlite3OsShmMap(sqlite3_file *,int,int,int,void volatile **);
16419 -SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int, int, int);
16420 -SQLITE_PRIVATE void sqlite3OsShmBarrier(sqlite3_file *id);
16421 -SQLITE_PRIVATE int sqlite3OsShmUnmap(sqlite3_file *id, int);
16422 -#endif /* SQLITE_OMIT_WAL */
16423 -SQLITE_PRIVATE int sqlite3OsFetch(sqlite3_file *id, i64, int, void **);
16424 -SQLITE_PRIVATE int sqlite3OsUnfetch(sqlite3_file *, i64, void *);
16425 -
16426 -
16427 -/*
16428 -** Functions for accessing sqlite3_vfs methods
16429 -*/
16430 -SQLITE_PRIVATE int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *);
16431 -SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *, const char *, int);
16432 -SQLITE_PRIVATE int sqlite3OsAccess(sqlite3_vfs *, const char *, int, int *pResOut);
16433 -SQLITE_PRIVATE int sqlite3OsFullPathname(sqlite3_vfs *, const char *, int, char *);
16434 -#ifndef SQLITE_OMIT_LOAD_EXTENSION
16435 -SQLITE_PRIVATE void *sqlite3OsDlOpen(sqlite3_vfs *, const char *);
16436 -SQLITE_PRIVATE void sqlite3OsDlError(sqlite3_vfs *, int, char *);
16437 -SQLITE_PRIVATE void (*sqlite3OsDlSym(sqlite3_vfs *, void *, const char *))(void);
16438 -SQLITE_PRIVATE void sqlite3OsDlClose(sqlite3_vfs *, void *);
16439 -#endif /* SQLITE_OMIT_LOAD_EXTENSION */
16440 -SQLITE_PRIVATE int sqlite3OsRandomness(sqlite3_vfs *, int, char *);
16441 -SQLITE_PRIVATE int sqlite3OsSleep(sqlite3_vfs *, int);
16442 -SQLITE_PRIVATE int sqlite3OsGetLastError(sqlite3_vfs*);
16443 -SQLITE_PRIVATE int sqlite3OsCurrentTimeInt64(sqlite3_vfs *, sqlite3_int64*);
16444 -
16445 -/*
16446 -** Convenience functions for opening and closing files using
16447 -** sqlite3_malloc() to obtain space for the file-handle structure.
16448 -*/
16449 -SQLITE_PRIVATE int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int,int*);
16450 -SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *);
16451 -
16452 -#endif /* _SQLITE_OS_H_ */
16453 -
16454 -/************** End of os.h **************************************************/
16455 -/************** Continuing where we left off in sqliteInt.h ******************/
16609 /************** Include mutex.h in the middle of sqliteInt.h *****************/
16610 /************** Begin file mutex.h *******************************************/
16611 /*
@@ -16698,6 +16851,7 @@ struct Lookaside {
16851 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
16852 void *pStart; /* First byte of available memory space */
16853 void *pEnd; /* First byte past end of available space */
16854 + void *pTrueEnd; /* True value of pEnd, when db->pnBytesFreed!=0 */
16855 };
16856 struct LookasideSlot {
16857 LookasideSlot *pNext; /* Next buffer in the list of free buffers */
@@ -17039,6 +17193,10 @@ struct sqlite3 {
17193 #define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filter on searches */
17194 #define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */
17195 #define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */
17196 +#define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */
17197 +#define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */
17198 + /* TH3 expects this value ^^^^^^^^^^ See flatten04.test */
17199 +#define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */
17200 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
17201
17202 /*
@@ -17141,7 +17299,7 @@ struct FuncDestructor {
17299 #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
17300 ** single query - might change over time */
17301 #define SQLITE_FUNC_TEST 0x4000 /* Built-in testing functions */
17144 -#define SQLITE_FUNC_OFFSET 0x8000 /* Built-in sqlite_offset() function */
17302 +/* 0x8000 -- available for reuse */
17303 #define SQLITE_FUNC_WINDOW 0x00010000 /* Built-in window-only function */
17304 #define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
17305 #define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */
@@ -17158,6 +17316,7 @@ struct FuncDestructor {
17316 #define INLINEFUNC_expr_compare 3
17317 #define INLINEFUNC_affinity 4
17318 #define INLINEFUNC_iif 5
17319 +#define INLINEFUNC_sqlite_offset 6
17320 #define INLINEFUNC_unlikely 99 /* Default case */
17321
17322 /*
@@ -17384,6 +17543,7 @@ struct Column {
17543 #define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */
17544 #define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */
17545 #define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */
17546 +#define COLFLAG_NOEXPAND 0x0400 /* Omit this column when expanding "*" */
17547 #define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */
17548 #define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
17549
@@ -17609,7 +17769,7 @@ struct Table {
17769 #ifndef SQLITE_OMIT_VIRTUALTABLE
17770 # define IsVirtual(X) ((X)->eTabType==TABTYP_VTAB)
17771 # define ExprIsVtab(X) \
17612 - ((X)->op==TK_COLUMN && (X)->y.pTab!=0 && (X)->y.pTab->eTabType==TABTYP_VTAB)
17772 + ((X)->op==TK_COLUMN && (X)->y.pTab->eTabType==TABTYP_VTAB)
17773 #else
17774 # define IsVirtual(X) 0
17775 # define ExprIsVtab(X) 0
@@ -17790,6 +17950,11 @@ struct KeyInfo {
17950 struct UnpackedRecord {
17951 KeyInfo *pKeyInfo; /* Collation and sort-order information */
17952 Mem *aMem; /* Values */
17953 + union {
17954 + char *z; /* Cache of aMem[0].z for vdbeRecordCompareString() */
17955 + i64 i; /* Cache of aMem[0].u.i for vdbeRecordCompareInt() */
17956 + } u;
17957 + int n; /* Cache of aMem[0].n used by vdbeRecordCompareString() */
17958 u16 nField; /* Number of entries in apMem[] */
17959 i8 default_rc; /* Comparison result if keys are equal */
17960 u8 errCode; /* Error detected by xRecordCompare (CORRUPT or NOMEM) */
@@ -17821,10 +17986,22 @@ struct UnpackedRecord {
17986 ** The Index.onError field determines whether or not the indexed columns
17987 ** must be unique and what to do if they are not. When Index.onError=OE_None,
17988 ** it means this is not a unique index. Otherwise it is a unique index
17824 -** and the value of Index.onError indicate the which conflict resolution
17825 -** algorithm to employ whenever an attempt is made to insert a non-unique
17989 +** and the value of Index.onError indicates which conflict resolution
17990 +** algorithm to employ when an attempt is made to insert a non-unique
17991 ** element.
17992 **
17993 +** The colNotIdxed bitmask is used in combination with SrcItem.colUsed
17994 +** for a fast test to see if an index can serve as a covering index.
17995 +** colNotIdxed has a 1 bit for every column of the original table that
17996 +** is *not* available in the index. Thus the expression
17997 +** "colUsed & colNotIdxed" will be non-zero if the index is not a
17998 +** covering index. The most significant bit of of colNotIdxed will always
17999 +** be true (note-20221022-a). If a column beyond the 63rd column of the
18000 +** table is used, the "colUsed & colNotIdxed" test will always be non-zero
18001 +** and we have to assume either that the index is not covering, or use
18002 +** an alternative (slower) algorithm to determine whether or not
18003 +** the index is covering.
18004 +**
18005 ** While parsing a CREATE TABLE or CREATE INDEX statement in order to
18006 ** generate VDBE code (as opposed to parsing one read from an sqlite_schema
18007 ** table as part of parsing an existing database schema), transient instances
@@ -17860,6 +18037,8 @@ struct Index {
18037 unsigned bNoQuery:1; /* Do not use this index to optimize queries */
18038 unsigned bAscKeyBug:1; /* True if the bba7b69f9849b5bf bug applies */
18039 unsigned bHasVCol:1; /* Index references one or more VIRTUAL columns */
18040 + unsigned bHasExpr:1; /* Index contains an expression, either a literal
18041 + ** expression, or a reference to a VIRTUAL column */
18042 #ifdef SQLITE_ENABLE_STAT4
18043 int nSample; /* Number of elements in aSample[] */
18044 int nSampleCol; /* Size of IndexSample.anEq[] and so on */
@@ -17868,7 +18047,7 @@ struct Index {
18047 tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this index */
18048 tRowcnt nRowEst0; /* Non-logarithmic number of rows in the index */
18049 #endif
17871 - Bitmask colNotIdxed; /* 0 for unindexed columns in pTab */
18050 + Bitmask colNotIdxed; /* Unindexed columns in pTab */
18051 };
18052
18053 /*
@@ -18098,7 +18277,7 @@ struct Expr {
18277 ** TK_SELECT_COLUMN: column of the result vector */
18278 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
18279 union {
18101 - int iRightJoinTable; /* If EP_FromJoin, the right table of the join */
18280 + int iJoin; /* If EP_OuterON or EP_InnerON, the right table */
18281 int iOfst; /* else: start of token from start of statement */
18282 } w;
18283 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
@@ -18119,29 +18298,29 @@ struct Expr {
18298 ** EP_Agg == NC_HasAgg == SF_HasAgg
18299 ** EP_Win == NC_HasWin
18300 */
18122 -#define EP_FromJoin 0x000001 /* Originates in ON/USING clause of outer join */
18123 -#define EP_Distinct 0x000002 /* Aggregate function with DISTINCT keyword */
18124 -#define EP_HasFunc 0x000004 /* Contains one or more functions of any kind */
18125 -#define EP_FixedCol 0x000008 /* TK_Column with a known fixed value */
18301 +#define EP_OuterON 0x000001 /* Originates in ON/USING clause of outer join */
18302 +#define EP_InnerON 0x000002 /* Originates in ON/USING of an inner join */
18303 +#define EP_Distinct 0x000004 /* Aggregate function with DISTINCT keyword */
18304 +#define EP_HasFunc 0x000008 /* Contains one or more functions of any kind */
18305 #define EP_Agg 0x000010 /* Contains one or more aggregate functions */
18127 -#define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
18128 -#define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
18129 -#define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */
18130 -#define EP_Collate 0x000100 /* Tree contains a TK_COLLATE operator */
18131 -#define EP_Commuted 0x000200 /* Comparison operator has been commuted */
18132 -#define EP_IntValue 0x000400 /* Integer value contained in u.iValue */
18133 -#define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */
18134 -#define EP_Skip 0x001000 /* Operator does not contribute to affinity */
18135 -#define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
18136 -#define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
18306 +#define EP_FixedCol 0x000020 /* TK_Column with a known fixed value */
18307 +#define EP_VarSelect 0x000040 /* pSelect is correlated, not constant */
18308 +#define EP_DblQuoted 0x000080 /* token.z was originally in "..." */
18309 +#define EP_InfixFunc 0x000100 /* True for an infix function: LIKE, GLOB, etc */
18310 +#define EP_Collate 0x000200 /* Tree contains a TK_COLLATE operator */
18311 +#define EP_Commuted 0x000400 /* Comparison operator has been commuted */
18312 +#define EP_IntValue 0x000800 /* Integer value contained in u.iValue */
18313 +#define EP_xIsSelect 0x001000 /* x.pSelect is valid (otherwise x.pList is) */
18314 +#define EP_Skip 0x002000 /* Operator does not contribute to affinity */
18315 +#define EP_Reduced 0x004000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
18316 #define EP_Win 0x008000 /* Contains window functions */
18138 -#define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
18139 -#define EP_IfNullRow 0x020000 /* The TK_IF_NULL_ROW opcode */
18140 -#define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
18141 -#define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
18142 -#define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
18143 -#define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */
18144 - /* 0x400000 // Available */
18317 +#define EP_TokenOnly 0x010000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
18318 + /* 0x020000 // Available for reuse */
18319 +#define EP_IfNullRow 0x040000 /* The TK_IF_NULL_ROW opcode */
18320 +#define EP_Unlikely 0x080000 /* unlikely() or likelihood() function */
18321 +#define EP_ConstFunc 0x100000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
18322 +#define EP_CanBeNull 0x200000 /* Can be null despite NOT NULL constraint */
18323 +#define EP_Subquery 0x400000 /* Tree contains a TK_SELECT operator */
18324 #define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
18325 #define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */
18326 #define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
@@ -18164,8 +18343,8 @@ struct Expr {
18343 #define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P))
18344 #define ExprSetProperty(E,P) (E)->flags|=(P)
18345 #define ExprClearProperty(E,P) (E)->flags&=~(P)
18167 -#define ExprAlwaysTrue(E) (((E)->flags&(EP_FromJoin|EP_IsTrue))==EP_IsTrue)
18168 -#define ExprAlwaysFalse(E) (((E)->flags&(EP_FromJoin|EP_IsFalse))==EP_IsFalse)
18346 +#define ExprAlwaysTrue(E) (((E)->flags&(EP_OuterON|EP_IsTrue))==EP_IsTrue)
18347 +#define ExprAlwaysFalse(E) (((E)->flags&(EP_OuterON|EP_IsFalse))==EP_IsFalse)
18348
18349 /* Macros used to ensure that the correct members of unions are accessed
18350 ** in Expr.
@@ -18252,12 +18431,18 @@ struct ExprList {
18431 struct ExprList_item { /* For each expression in the list */
18432 Expr *pExpr; /* The parse tree for this expression */
18433 char *zEName; /* Token associated with this expression */
18255 - u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
18256 - unsigned eEName :2; /* Meaning of zEName */
18257 - unsigned done :1; /* A flag to indicate when processing is finished */
18258 - unsigned reusable :1; /* Constant expression is reusable */
18259 - unsigned bSorterRef :1; /* Defer evaluation until after sorting */
18260 - unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */
18434 + struct {
18435 + u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
18436 + unsigned eEName :2; /* Meaning of zEName */
18437 + unsigned done :1; /* Indicates when processing is finished */
18438 + unsigned reusable :1; /* Constant expression is reusable */
18439 + unsigned bSorterRef :1; /* Defer evaluation until after sorting */
18440 + unsigned bNulls :1; /* True if explicit "NULLS FIRST/LAST" */
18441 + unsigned bUsed :1; /* This column used in a SF_NestedFrom subquery */
18442 + unsigned bUsingTerm:1; /* Term from the USING clause of a NestedFrom */
18443 + unsigned bNoExpand: 1; /* Term is an auxiliary in NestedFrom and should
18444 + ** not be expanded by "*" in parent queries */
18445 + } fg;
18446 union {
18447 struct { /* Used by any ExprList other than Parse.pConsExpr */
18448 u16 iOrderByCol; /* For ORDER BY, column number in result set */
@@ -18292,17 +18477,37 @@ struct ExprList {
18477 ** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.
18478 */
18479 struct IdList {
18480 + int nId; /* Number of identifiers on the list */
18481 + u8 eU4; /* Which element of a.u4 is valid */
18482 struct IdList_item {
18483 char *zName; /* Name of the identifier */
18297 - int idx; /* Index in some Table.aCol[] of a column named zName */
18298 - } *a;
18299 - int nId; /* Number of identifiers on the list */
18484 + union {
18485 + int idx; /* Index in some Table.aCol[] of a column named zName */
18486 + Expr *pExpr; /* Expr to implement a USING variable -- NOT USED */
18487 + } u4;
18488 + } a[1];
18489 };
18490
18491 +/*
18492 +** Allowed values for IdList.eType, which determines which value of the a.u4
18493 +** is valid.
18494 +*/
18495 +#define EU4_NONE 0 /* Does not use IdList.a.u4 */
18496 +#define EU4_IDX 1 /* Uses IdList.a.u4.idx */
18497 +#define EU4_EXPR 2 /* Uses IdList.a.u4.pExpr -- NOT CURRENTLY USED */
18498 +
18499 /*
18500 ** The SrcItem object represents a single term in the FROM clause of a query.
18501 ** The SrcList object is mostly an array of SrcItems.
18502 **
18503 +** The jointype starts out showing the join type between the current table
18504 +** and the next table on the list. The parser builds the list this way.
18505 +** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each
18506 +** jointype expresses the join between the table and the previous table.
18507 +**
18508 +** In the colUsed field, the high-order bit (bit 63) is set if the table
18509 +** contains more than 63 columns and the 64-th or later column is used.
18510 +**
18511 ** Union member validity:
18512 **
18513 ** u1.zIndexedBy fg.isIndexedBy && !fg.isTabFunc
@@ -18326,44 +18531,48 @@ struct SrcItem {
18531 unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */
18532 unsigned isTabFunc :1; /* True if table-valued-function syntax */
18533 unsigned isCorrelated :1; /* True if sub-query is correlated */
18534 + unsigned isMaterialized:1; /* This is a materialized view */
18535 unsigned viaCoroutine :1; /* Implemented as a co-routine */
18536 unsigned isRecursive :1; /* True for recursive reference in WITH */
18537 unsigned fromDDL :1; /* Comes from sqlite_schema */
18538 unsigned isCte :1; /* This is a CTE */
18539 unsigned notCte :1; /* This item may not match a CTE */
18540 + unsigned isUsing :1; /* u3.pUsing is valid */
18541 + unsigned isOn :1; /* u3.pOn was once valid and non-NULL */
18542 + unsigned isSynthUsing :1; /* u3.pUsing is synthensized from NATURAL */
18543 + unsigned isNestedFrom :1; /* pSelect is a SF_NestedFrom subquery */
18544 } fg;
18545 int iCursor; /* The VDBE cursor number used to access this table */
18336 - Expr *pOn; /* The ON clause of a join */
18337 - IdList *pUsing; /* The USING clause of a join */
18338 - Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
18546 + union {
18547 + Expr *pOn; /* fg.isUsing==0 => The ON clause of a join */
18548 + IdList *pUsing; /* fg.isUsing==1 => The USING clause of a join */
18549 + } u3;
18550 + Bitmask colUsed; /* Bit N set if column N used. Details above for N>62 */
18551 union {
18552 char *zIndexedBy; /* Identifier from "INDEXED BY <zIndex>" clause */
18553 ExprList *pFuncArg; /* Arguments to table-valued-function */
18554 } u1;
18555 union {
18556 Index *pIBIndex; /* Index structure corresponding to u1.zIndexedBy */
18345 - CteUse *pCteUse; /* CTE Usage info info fg.isCte is true */
18557 + CteUse *pCteUse; /* CTE Usage info when fg.isCte is true */
18558 } u2;
18559 };
18560
18561 /*
18350 -** The following structure describes the FROM clause of a SELECT statement.
18351 -** Each table or subquery in the FROM clause is a separate element of
18352 -** the SrcList.a[] array.
18353 -**
18354 -** With the addition of multiple database support, the following structure
18355 -** can also be used to describe a particular table such as the table that
18356 -** is modified by an INSERT, DELETE, or UPDATE statement. In standard SQL,
18357 -** such a table must be a simple name: ID. But in SQLite, the table can
18358 -** now be identified by a database name, a dot, then the table name: ID.ID.
18359 -**
18360 -** The jointype starts out showing the join type between the current table
18361 -** and the next table on the list. The parser builds the list this way.
18362 -** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each
18363 -** jointype expresses the join between the table and the previous table.
18562 +** The OnOrUsing object represents either an ON clause or a USING clause.
18563 +** It can never be both at the same time, but it can be neither.
18564 +*/
18565 +struct OnOrUsing {
18566 + Expr *pOn; /* The ON clause of a join */
18567 + IdList *pUsing; /* The USING clause of a join */
18568 +};
18569 +
18570 +/*
18571 +** This object represents one or more tables that are the source of
18572 +** content for an SQL statement. For example, a single SrcList object
18573 +** is used to hold the FROM clause of a SELECT statement. SrcList also
18574 +** represents the target tables for DELETE, INSERT, and UPDATE statements.
18575 **
18365 -** In the colUsed field, the high-order bit (bit 63) is set if the table
18366 -** contains more than 63 columns and the 64-th or later column is used.
18576 */
18577 struct SrcList {
18578 int nSrc; /* Number of tables or subqueries in the FROM clause */
@@ -18374,14 +18583,15 @@ struct SrcList {
18583 /*
18584 ** Permitted values of the SrcList.a.jointype field
18585 */
18377 -#define JT_INNER 0x0001 /* Any kind of inner or cross join */
18378 -#define JT_CROSS 0x0002 /* Explicit use of the CROSS keyword */
18379 -#define JT_NATURAL 0x0004 /* True for a "natural" join */
18380 -#define JT_LEFT 0x0008 /* Left outer join */
18381 -#define JT_RIGHT 0x0010 /* Right outer join */
18382 -#define JT_OUTER 0x0020 /* The "OUTER" keyword is present */
18383 -#define JT_ERROR 0x0040 /* unknown or unsupported join type */
18384 -
18586 +#define JT_INNER 0x01 /* Any kind of inner or cross join */
18587 +#define JT_CROSS 0x02 /* Explicit use of the CROSS keyword */
18588 +#define JT_NATURAL 0x04 /* True for a "natural" join */
18589 +#define JT_LEFT 0x08 /* Left outer join */
18590 +#define JT_RIGHT 0x10 /* Right outer join */
18591 +#define JT_OUTER 0x20 /* The "OUTER" keyword is present */
18592 +#define JT_LTORJ 0x40 /* One of the LEFT operands of a RIGHT JOIN
18593 + ** Mnemonic: Left Table Of Right Join */
18594 +#define JT_ERROR 0x80 /* unknown or unsupported join type */
18595
18596 /*
18597 ** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin()
@@ -18404,7 +18614,7 @@ struct SrcList {
18614 #define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */
18615 #define WHERE_AGG_DISTINCT 0x0400 /* Query is "SELECT agg(DISTINCT ...)" */
18616 #define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */
18407 - /* 0x1000 not currently used */
18617 +#define WHERE_RIGHT_JOIN 0x1000 /* Processing a RIGHT JOIN */
18618 /* 0x2000 not currently used */
18619 #define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */
18620 /* 0x8000 not currently used */
@@ -18600,6 +18810,9 @@ struct Select {
18810 #define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */
18811 #define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */
18812
18813 +/* True if S exists and has SF_NestedFrom */
18814 +#define IsNestedFrom(S) ((S)!=0 && ((S)->selFlags&SF_NestedFrom)!=0)
18815 +
18816 /*
18817 ** The results of a SELECT can be distributed in several ways, as defined
18818 ** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -18704,7 +18917,7 @@ struct SelectDest {
18917 int iSDParm2; /* A second parameter for the eDest disposal method */
18918 int iSdst; /* Base register where results are written */
18919 int nSdst; /* Number of registers allocated */
18707 - char *zAffSdst; /* Affinity used when eDest==SRT_Set */
18920 + char *zAffSdst; /* Affinity used for SRT_Set, SRT_Table, and similar */
18921 ExprList *pOrderBy; /* Key columns for SRT_Queue and SRT_DistQueue */
18922 };
18923
@@ -18769,6 +18982,28 @@ struct TriggerPrg {
18982 # define DbMaskNonZero(M) (M)!=0
18983 #endif
18984
18985 +/*
18986 +** For each index X that has as one of its arguments either an expression
18987 +** or the name of a virtual generated column, and if X is in scope such that
18988 +** the value of the expression can simply be read from the index, then
18989 +** there is an instance of this object on the Parse.pIdxExpr list.
18990 +**
18991 +** During code generation, while generating code to evaluate expressions,
18992 +** this list is consulted and if a matching expression is found, the value
18993 +** is read from the index rather than being recomputed.
18994 +*/
18995 +struct IndexedExpr {
18996 + Expr *pExpr; /* The expression contained in the index */
18997 + int iDataCur; /* The data cursor associated with the index */
18998 + int iIdxCur; /* The index cursor */
18999 + int iIdxCol; /* The index column that contains value of pExpr */
19000 + u8 bMaybeNullRow; /* True if we need an OP_IfNullRow check */
19001 + IndexedExpr *pIENext; /* Next in a list of all indexed expressions */
19002 +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
19003 + const char *zIdxName; /* Name of index, used only for bytecode comments */
19004 +#endif
19005 +};
19006 +
19007 /*
19008 ** An instance of the ParseCleanup object specifies an operation that
19009 ** should be performed after parsing to deallocation resources obtained
@@ -18810,7 +19045,8 @@ struct Parse {
19045 u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
19046 u8 okConstFactor; /* OK to factor out constants */
19047 u8 disableLookaside; /* Number of times lookaside has been disabled */
18813 - u8 disableVtab; /* Disable all virtual tables for this parse */
19048 + u8 prepFlags; /* SQLITE_PREPARE_* flags */
19049 + u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
19050 #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
19051 u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */
19052 #endif
@@ -18826,6 +19062,7 @@ struct Parse {
19062 int nLabelAlloc; /* Number of slots in aLabel */
19063 int *aLabel; /* Space to hold the labels */
19064 ExprList *pConstExpr;/* Constant expressions */
19065 + IndexedExpr *pIdxExpr;/* List of expressions used by active indexes */
19066 Token constraintName;/* Name of the constraint currently being parsed */
19067 yDbMask writeMask; /* Start a write transaction on these databases */
19068 yDbMask cookieMask; /* Bitmask of schema verified databases */
@@ -18983,20 +19220,20 @@ struct AuthContext {
19220 #define OPFLAG_PREFORMAT 0x80 /* OP_Insert uses preformatted cell */
19221
19222 /*
18986 - * Each trigger present in the database schema is stored as an instance of
18987 - * struct Trigger.
18988 - *
18989 - * Pointers to instances of struct Trigger are stored in two ways.
18990 - * 1. In the "trigHash" hash table (part of the sqlite3* that represents the
18991 - * database). This allows Trigger structures to be retrieved by name.
18992 - * 2. All triggers associated with a single table form a linked list, using the
18993 - * pNext member of struct Trigger. A pointer to the first element of the
18994 - * linked list is stored as the "pTrigger" member of the associated
18995 - * struct Table.
18996 - *
18997 - * The "step_list" member points to the first element of a linked list
18998 - * containing the SQL statements specified as the trigger program.
18999 - */
19223 +** Each trigger present in the database schema is stored as an instance of
19224 +** struct Trigger.
19225 +**
19226 +** Pointers to instances of struct Trigger are stored in two ways.
19227 +** 1. In the "trigHash" hash table (part of the sqlite3* that represents the
19228 +** database). This allows Trigger structures to be retrieved by name.
19229 +** 2. All triggers associated with a single table form a linked list, using the
19230 +** pNext member of struct Trigger. A pointer to the first element of the
19231 +** linked list is stored as the "pTrigger" member of the associated
19232 +** struct Table.
19233 +**
19234 +** The "step_list" member points to the first element of a linked list
19235 +** containing the SQL statements specified as the trigger program.
19236 +*/
19237 struct Trigger {
19238 char *zName; /* The name of the trigger */
19239 char *table; /* The table or view to which the trigger applies */
@@ -19023,43 +19260,48 @@ struct Trigger {
19260 #define TRIGGER_AFTER 2
19261
19262 /*
19026 - * An instance of struct TriggerStep is used to store a single SQL statement
19027 - * that is a part of a trigger-program.
19028 - *
19029 - * Instances of struct TriggerStep are stored in a singly linked list (linked
19030 - * using the "pNext" member) referenced by the "step_list" member of the
19031 - * associated struct Trigger instance. The first element of the linked list is
19032 - * the first step of the trigger-program.
19033 - *
19034 - * The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or
19035 - * "SELECT" statement. The meanings of the other members is determined by the
19036 - * value of "op" as follows:
19037 - *
19038 - * (op == TK_INSERT)
19039 - * orconf -> stores the ON CONFLICT algorithm
19040 - * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then
19041 - * this stores a pointer to the SELECT statement. Otherwise NULL.
19042 - * zTarget -> Dequoted name of the table to insert into.
19043 - * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then
19044 - * this stores values to be inserted. Otherwise NULL.
19045 - * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ...
19046 - * statement, then this stores the column-names to be
19047 - * inserted into.
19048 - *
19049 - * (op == TK_DELETE)
19050 - * zTarget -> Dequoted name of the table to delete from.
19051 - * pWhere -> The WHERE clause of the DELETE statement if one is specified.
19052 - * Otherwise NULL.
19053 - *
19054 - * (op == TK_UPDATE)
19055 - * zTarget -> Dequoted name of the table to update.
19056 - * pWhere -> The WHERE clause of the UPDATE statement if one is specified.
19057 - * Otherwise NULL.
19058 - * pExprList -> A list of the columns to update and the expressions to update
19059 - * them to. See sqlite3Update() documentation of "pChanges"
19060 - * argument.
19061 - *
19062 - */
19263 +** An instance of struct TriggerStep is used to store a single SQL statement
19264 +** that is a part of a trigger-program.
19265 +**
19266 +** Instances of struct TriggerStep are stored in a singly linked list (linked
19267 +** using the "pNext" member) referenced by the "step_list" member of the
19268 +** associated struct Trigger instance. The first element of the linked list is
19269 +** the first step of the trigger-program.
19270 +**
19271 +** The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or
19272 +** "SELECT" statement. The meanings of the other members is determined by the
19273 +** value of "op" as follows:
19274 +**
19275 +** (op == TK_INSERT)
19276 +** orconf -> stores the ON CONFLICT algorithm
19277 +** pSelect -> The content to be inserted - either a SELECT statement or
19278 +** a VALUES clause.
19279 +** zTarget -> Dequoted name of the table to insert into.
19280 +** pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ...
19281 +** statement, then this stores the column-names to be
19282 +** inserted into.
19283 +** pUpsert -> The ON CONFLICT clauses for an Upsert
19284 +**
19285 +** (op == TK_DELETE)
19286 +** zTarget -> Dequoted name of the table to delete from.
19287 +** pWhere -> The WHERE clause of the DELETE statement if one is specified.
19288 +** Otherwise NULL.
19289 +**
19290 +** (op == TK_UPDATE)
19291 +** zTarget -> Dequoted name of the table to update.
19292 +** pWhere -> The WHERE clause of the UPDATE statement if one is specified.
19293 +** Otherwise NULL.
19294 +** pExprList -> A list of the columns to update and the expressions to update
19295 +** them to. See sqlite3Update() documentation of "pChanges"
19296 +** argument.
19297 +**
19298 +** (op == TK_SELECT)
19299 +** pSelect -> The SELECT statement
19300 +**
19301 +** (op == TK_RETURNING)
19302 +** pExprList -> The list of expressions that follow the RETURNING keyword.
19303 +**
19304 +*/
19305 struct TriggerStep {
19306 u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT,
19307 ** or TK_RETURNING */
@@ -19256,15 +19498,15 @@ struct Walker {
19498 struct RefSrcList *pRefSrcList; /* sqlite3ReferencesSrcList() */
19499 int *aiCol; /* array of column indexes */
19500 struct IdxCover *pIdxCover; /* Check for index coverage */
19259 - struct IdxExprTrans *pIdxTrans; /* Convert idxed expr to column */
19501 ExprList *pGroupBy; /* GROUP BY clause */
19502 Select *pSelect; /* HAVING to WHERE clause ctx */
19503 struct WindowRewrite *pRewrite; /* Window rewrite context */
19504 struct WhereConst *pConst; /* WHERE clause constants */
19505 struct RenameCtx *pRename; /* RENAME COLUMN context */
19506 struct Table *pTab; /* Table of generated column */
19507 + struct CoveringIndexCheck *pCovIdxCk; /* Check for covering index */
19508 SrcItem *pSrcItem; /* A single FROM clause item */
19267 - DbFixer *pFix;
19509 + DbFixer *pFix; /* See sqlite3FixSelect() */
19510 } u;
19511 };
19512
@@ -19414,7 +19656,7 @@ struct Window {
19656 Window **ppThis; /* Pointer to this object in Select.pWin list */
19657 Window *pNextWin; /* Next window function belonging to this SELECT */
19658 Expr *pFilter; /* The FILTER expression */
19417 - FuncDef *pFunc; /* The function */
19659 + FuncDef *pWFunc; /* The function */
19660 int iEphCsr; /* Partition buffer or Peer buffer */
19661 int regAccum; /* Accumulator */
19662 int regResult; /* Interim result */
@@ -19570,6 +19812,7 @@ SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
19812 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
19813 SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
19814 SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
19815 +SQLITE_PRIVATE void sqlite3DbNNFreeNN(sqlite3*, void*);
19816 SQLITE_PRIVATE int sqlite3MallocSize(const void*);
19817 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, const void*);
19818 SQLITE_PRIVATE void *sqlite3PageMalloc(int);
@@ -19590,12 +19833,16 @@ SQLITE_PRIVATE int sqlite3HeapNearlyFull(void);
19833 */
19834 #ifdef SQLITE_USE_ALLOCA
19835 # define sqlite3StackAllocRaw(D,N) alloca(N)
19836 +# define sqlite3StackAllocRawNN(D,N) alloca(N)
19837 # define sqlite3StackAllocZero(D,N) memset(alloca(N), 0, N)
19838 # define sqlite3StackFree(D,P)
19839 +# define sqlite3StackFreeNN(D,P)
19840 #else
19841 # define sqlite3StackAllocRaw(D,N) sqlite3DbMallocRaw(D,N)
19842 +# define sqlite3StackAllocRawNN(D,N) sqlite3DbMallocRawNN(D,N)
19843 # define sqlite3StackAllocZero(D,N) sqlite3DbMallocZero(D,N)
19844 # define sqlite3StackFree(D,P) sqlite3DbFree(D,P)
19845 +# define sqlite3StackFreeNN(D,P) sqlite3DbFreeNN(D,P)
19846 #endif
19847
19848 /* Do not allow both MEMSYS5 and MEMSYS3 to be defined together. If they
@@ -19669,18 +19916,53 @@ SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*);
19916 #endif
19917
19918 #if defined(SQLITE_DEBUG)
19919 +SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView*, const char *zFormat, ...);
19920 SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
19921 SQLITE_PRIVATE void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*);
19922 SQLITE_PRIVATE void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*);
19923 +SQLITE_PRIVATE void sqlite3TreeViewBareIdList(TreeView*, const IdList*, const char*);
19924 +SQLITE_PRIVATE void sqlite3TreeViewIdList(TreeView*, const IdList*, u8, const char*);
19925 +SQLITE_PRIVATE void sqlite3TreeViewColumnList(TreeView*, const Column*, int, u8);
19926 SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView*, const SrcList*);
19927 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
19928 SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView*, const With*, u8);
19929 +SQLITE_PRIVATE void sqlite3TreeViewUpsert(TreeView*, const Upsert*, u8);
19930 +#if TREETRACE_ENABLED
19931 +SQLITE_PRIVATE void sqlite3TreeViewDelete(const With*, const SrcList*, const Expr*,
19932 + const ExprList*,const Expr*, const Trigger*);
19933 +SQLITE_PRIVATE void sqlite3TreeViewInsert(const With*, const SrcList*,
19934 + const IdList*, const Select*, const ExprList*,
19935 + int, const Upsert*, const Trigger*);
19936 +SQLITE_PRIVATE void sqlite3TreeViewUpdate(const With*, const SrcList*, const ExprList*,
19937 + const Expr*, int, const ExprList*, const Expr*,
19938 + const Upsert*, const Trigger*);
19939 +#endif
19940 +#ifndef SQLITE_OMIT_TRIGGER
19941 +SQLITE_PRIVATE void sqlite3TreeViewTriggerStep(TreeView*, const TriggerStep*, u8, u8);
19942 +SQLITE_PRIVATE void sqlite3TreeViewTrigger(TreeView*, const Trigger*, u8, u8);
19943 +#endif
19944 #ifndef SQLITE_OMIT_WINDOWFUNC
19945 SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView*, const Window*, u8);
19946 SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView*, const Window*, u8);
19947 #endif
19948 +SQLITE_PRIVATE void sqlite3ShowExpr(const Expr*);
19949 +SQLITE_PRIVATE void sqlite3ShowExprList(const ExprList*);
19950 +SQLITE_PRIVATE void sqlite3ShowIdList(const IdList*);
19951 +SQLITE_PRIVATE void sqlite3ShowSrcList(const SrcList*);
19952 +SQLITE_PRIVATE void sqlite3ShowSelect(const Select*);
19953 +SQLITE_PRIVATE void sqlite3ShowWith(const With*);
19954 +SQLITE_PRIVATE void sqlite3ShowUpsert(const Upsert*);
19955 +#ifndef SQLITE_OMIT_TRIGGER
19956 +SQLITE_PRIVATE void sqlite3ShowTriggerStep(const TriggerStep*);
19957 +SQLITE_PRIVATE void sqlite3ShowTriggerStepList(const TriggerStep*);
19958 +SQLITE_PRIVATE void sqlite3ShowTrigger(const Trigger*);
19959 +SQLITE_PRIVATE void sqlite3ShowTriggerList(const Trigger*);
19960 +#endif
19961 +#ifndef SQLITE_OMIT_WINDOWFUNC
19962 +SQLITE_PRIVATE void sqlite3ShowWindow(const Window*);
19963 +SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window*);
19964 +#endif
19965 #endif
19683 -
19966
19967 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
19968 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
@@ -19829,13 +20111,14 @@ SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(Parse*, SrcList*, int, int);
20111 SQLITE_PRIVATE SrcList *sqlite3SrcListAppendList(Parse *pParse, SrcList *p1, SrcList *p2);
20112 SQLITE_PRIVATE SrcList *sqlite3SrcListAppend(Parse*, SrcList*, Token*, Token*);
20113 SQLITE_PRIVATE SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*,
19832 - Token*, Select*, Expr*, IdList*);
20114 + Token*, Select*, OnOrUsing*);
20115 SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token *);
20116 SQLITE_PRIVATE void sqlite3SrcListFuncArgs(Parse*, SrcList*, ExprList*);
20117 SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, SrcItem *);
19836 -SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList*);
20118 +SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(Parse*,SrcList*);
20119 SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse*, SrcList*);
20120 SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*);
20121 +SQLITE_PRIVATE void sqlite3ClearOnOrUsing(sqlite3*, OnOrUsing*);
20122 SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*);
20123 SQLITE_PRIVATE Index *sqlite3AllocateIndexObject(sqlite3*,i16,int,char**);
20124 SQLITE_PRIVATE void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
@@ -20033,7 +20316,8 @@ SQLITE_PRIVATE SrcList *sqlite3TriggerStepSrc(Parse*, TriggerStep*);
20316
20317 SQLITE_PRIVATE int sqlite3JoinType(Parse*, Token*, Token*, Token*);
20318 SQLITE_PRIVATE int sqlite3ColumnIndex(Table *pTab, const char *zCol);
20036 -SQLITE_PRIVATE void sqlite3SetJoinExpr(Expr*,int);
20319 +SQLITE_PRIVATE void sqlite3SrcItemColumnUsed(SrcItem*,int);
20320 +SQLITE_PRIVATE void sqlite3SetJoinExpr(Expr*,int,u32);
20321 SQLITE_PRIVATE void sqlite3CreateForeignKey(Parse*, ExprList*, Token*, ExprList*, int);
20322 SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse*, int);
20323 #ifndef SQLITE_OMIT_AUTHORIZATION
@@ -20057,6 +20341,7 @@ SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*);
20341 SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*);
20342 SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
20343 SQLITE_PRIVATE int sqlite3RealSameAsInt(double,sqlite3_int64);
20344 +SQLITE_PRIVATE i64 sqlite3RealToI64(double);
20345 SQLITE_PRIVATE void sqlite3Int64ToText(i64,char*);
20346 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8);
20347 SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
@@ -20102,6 +20387,7 @@ SQLITE_PRIVATE int sqlite3VarintLen(u64 v);
20387
20388
20389 SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(sqlite3*, Index*);
20390 +SQLITE_PRIVATE char *sqlite3TableAffinityStr(sqlite3*,const Table*);
20391 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
20392 SQLITE_PRIVATE char sqlite3CompareAffinity(const Expr *pExpr, char aff2);
20393 SQLITE_PRIVATE int sqlite3IndexAffinityOk(const Expr *pExpr, char idx_affinity);
@@ -20173,7 +20459,6 @@ SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[];
20459 SQLITE_PRIVATE const char sqlite3StrBINARY[];
20460 SQLITE_PRIVATE const unsigned char sqlite3StdTypeLen[];
20461 SQLITE_PRIVATE const char sqlite3StdTypeAffinity[];
20176 -SQLITE_PRIVATE const char sqlite3StdTypeMap[];
20462 SQLITE_PRIVATE const char *sqlite3StdType[];
20463 SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[];
20464 SQLITE_PRIVATE const unsigned char *sqlite3aLTb;
@@ -20379,7 +20664,7 @@ SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, VTable *);
20664 SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
20665 #if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \
20666 && !defined(SQLITE_OMIT_VIRTUALTABLE)
20382 -SQLITE_PRIVATE void sqlite3VtabWriteAll(sqlite3_index_info*);
20667 +SQLITE_PRIVATE void sqlite3VtabUsesAllSchemas(sqlite3_index_info*);
20668 #endif
20669 SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
20670 SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
@@ -20617,6 +20902,10 @@ SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse*, Expr*);
20902 SQLITE_PRIVATE const char **sqlite3CompileOptions(int *pnOpt);
20903 #endif
20904
20905 +#if SQLITE_OS_UNIX && defined(SQLITE_OS_KV_OPTIONAL)
20906 +SQLITE_PRIVATE int sqlite3KvvfsInit(void);
20907 +#endif
20908 +
20909 #endif /* SQLITEINT_H */
20910
20911 /************** End of sqliteInt.h *******************************************/
@@ -20848,7 +21137,7 @@ SQLITE_API extern int sqlite3_open_file_count;
21137 ** autoconf-based build
21138 */
21139 #if defined(_HAVE_SQLITE_CONFIG_H) && !defined(SQLITECONFIG_H)
20851 -/* #include "config.h" */
21140 +/* #include "sqlite_cfg.h" */
21141 #define SQLITECONFIG_H 1
21142 #endif
21143
@@ -21013,6 +21302,9 @@ static const char * const sqlite3azCompileOpt[] = {
21302 #ifdef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
21303 "DISABLE_SKIPAHEAD_DISTINCT",
21304 #endif
21305 +#ifdef SQLITE_DQS
21306 + "DQS=" CTIMEOPT_VAL(SQLITE_DQS),
21307 +#endif
21308 #ifdef SQLITE_ENABLE_8_3_NAMES
21309 "ENABLE_8_3_NAMES=" CTIMEOPT_VAL(SQLITE_ENABLE_8_3_NAMES),
21310 #endif
@@ -21127,9 +21419,6 @@ static const char * const sqlite3azCompileOpt[] = {
21419 #ifdef SQLITE_ENABLE_RTREE
21420 "ENABLE_RTREE",
21421 #endif
21130 -#ifdef SQLITE_ENABLE_SELECTTRACE
21131 - "ENABLE_SELECTTRACE",
21132 -#endif
21422 #ifdef SQLITE_ENABLE_SESSION
21423 "ENABLE_SESSION",
21424 #endif
@@ -21151,6 +21440,9 @@ static const char * const sqlite3azCompileOpt[] = {
21440 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
21441 "ENABLE_STMT_SCANSTATUS",
21442 #endif
21443 +#ifdef SQLITE_ENABLE_TREETRACE
21444 + "ENABLE_TREETRACE",
21445 +#endif
21446 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
21447 "ENABLE_UNKNOWN_SQL_FUNCTION",
21448 #endif
@@ -21503,9 +21795,6 @@ static const char * const sqlite3azCompileOpt[] = {
21795 #ifdef SQLITE_OMIT_XFER_OPT
21796 "OMIT_XFER_OPT",
21797 #endif
21506 -#ifdef SQLITE_PCACHE_SEPARATE_HEADER
21507 - "PCACHE_SEPARATE_HEADER",
21508 -#endif
21798 #ifdef SQLITE_PERFORMANCE_TRACE
21799 "PERFORMANCE_TRACE",
21800 #endif
@@ -21900,6 +22189,9 @@ SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
22189 0x7ffffffe, /* iOnceResetThreshold */
22190 SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */
22191 0, /* iPrngSeed */
22192 +#ifdef SQLITE_DEBUG
22193 + {0,0,0,0,0,0} /* aTune */
22194 +#endif
22195 };
22196
22197 /*
@@ -21954,7 +22246,7 @@ SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000;
22246 /*
22247 ** Tracing flags set by SQLITE_TESTCTRL_TRACEFLAGS.
22248 */
21957 -SQLITE_PRIVATE u32 sqlite3SelectTrace = 0;
22249 +SQLITE_PRIVATE u32 sqlite3TreeTrace = 0;
22250 SQLITE_PRIVATE u32 sqlite3WhereTrace = 0;
22251
22252 /* #include "opcodes.h" */
@@ -21982,10 +22274,6 @@ SQLITE_PRIVATE const char sqlite3StrBINARY[] = "BINARY";
22274 **
22275 ** sqlite3StdTypeAffinity[] The affinity associated with each entry
22276 ** in sqlite3StdType[].
21985 -**
21986 -** sqlite3StdTypeMap[] The type value (as returned from
21987 -** sqlite3_column_type() or sqlite3_value_type())
21988 -** for each entry in sqlite3StdType[].
22277 */
22278 SQLITE_PRIVATE const unsigned char sqlite3StdTypeLen[] = { 3, 4, 3, 7, 4, 4 };
22279 SQLITE_PRIVATE const char sqlite3StdTypeAffinity[] = {
@@ -21996,14 +22284,6 @@ SQLITE_PRIVATE const char sqlite3StdTypeAffinity[] = {
22284 SQLITE_AFF_REAL,
22285 SQLITE_AFF_TEXT
22286 };
21999 -SQLITE_PRIVATE const char sqlite3StdTypeMap[] = {
22000 - 0,
22001 - SQLITE_BLOB,
22002 - SQLITE_INTEGER,
22003 - SQLITE_INTEGER,
22004 - SQLITE_FLOAT,
22005 - SQLITE_TEXT
22006 -};
22287 SQLITE_PRIVATE const char *sqlite3StdType[] = {
22288 "ANY",
22289 "BLOB",
@@ -22121,7 +22401,7 @@ struct VdbeCursor {
22401 Bool isEphemeral:1; /* True for an ephemeral table */
22402 Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */
22403 Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */
22124 - Bool hasBeenDuped:1; /* This cursor was source or target of OP_OpenDup */
22404 + Bool noReuse:1; /* OpenEphemeral may not reuse this cursor */
22405 u16 seekHit; /* See the OP_SeekHit and OP_IfNoHope opcodes */
22406 union { /* pBtx for isEphermeral. pAltMap otherwise */
22407 Btree *pBtx; /* Separate file holding temporary table */
@@ -22169,6 +22449,11 @@ struct VdbeCursor {
22449 u32 aType[1]; /* Type values record decode. MUST BE LAST */
22450 };
22451
22452 +/* Return true if P is a null-only cursor
22453 +*/
22454 +#define IsNullCursor(P) \
22455 + ((P)->eCurType==CURTYPE_PSEUDO && (P)->nullRow && (P)->seekResult==0)
22456 +
22457
22458 /*
22459 ** A value for VdbeCursor.cacheStatus that means the cache is always invalid.
@@ -22243,16 +22528,16 @@ struct sqlite3_value {
22528 const char *zPType; /* Pointer type when MEM_Term|MEM_Subtype|MEM_Null */
22529 FuncDef *pDef; /* Used only when flags==MEM_Agg */
22530 } u;
22531 + char *z; /* String or BLOB value */
22532 + int n; /* Number of characters in string value, excluding '\0' */
22533 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
22534 u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
22535 u8 eSubtype; /* Subtype for this value */
22249 - int n; /* Number of characters in string value, excluding '\0' */
22250 - char *z; /* String or BLOB value */
22536 /* ShallowCopy only needs to copy the information above */
22252 - char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
22537 + sqlite3 *db; /* The associated database connection */
22538 int szMalloc; /* Size of the zMalloc allocation */
22539 u32 uTemp; /* Transient storage for serial_type in OP_MakeRecord */
22255 - sqlite3 *db; /* The associated database connection */
22540 + char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
22541 void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
22542 #ifdef SQLITE_DEBUG
22543 Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
@@ -22264,11 +22549,43 @@ struct sqlite3_value {
22549 ** Size of struct Mem not including the Mem.zMalloc member or anything that
22550 ** follows.
22551 */
22267 -#define MEMCELLSIZE offsetof(Mem,zMalloc)
22552 +#define MEMCELLSIZE offsetof(Mem,db)
22553
22269 -/* One or more of the following flags are set to indicate the validOK
22554 +/* One or more of the following flags are set to indicate the
22555 ** representations of the value stored in the Mem struct.
22556 **
22557 +** * MEM_Null An SQL NULL value
22558 +**
22559 +** * MEM_Null|MEM_Zero An SQL NULL with the virtual table
22560 +** UPDATE no-change flag set
22561 +**
22562 +** * MEM_Null|MEM_Term| An SQL NULL, but also contains a
22563 +** MEM_Subtype pointer accessible using
22564 +** sqlite3_value_pointer().
22565 +**
22566 +** * MEM_Null|MEM_Cleared Special SQL NULL that compares non-equal
22567 +** to other NULLs even using the IS operator.
22568 +**
22569 +** * MEM_Str A string, stored in Mem.z with
22570 +** length Mem.n. Zero-terminated if
22571 +** MEM_Term is set. This flag is
22572 +** incompatible with MEM_Blob and
22573 +** MEM_Null, but can appear with MEM_Int,
22574 +** MEM_Real, and MEM_IntReal.
22575 +**
22576 +** * MEM_Blob A blob, stored in Mem.z length Mem.n.
22577 +** Incompatible with MEM_Str, MEM_Null,
22578 +** MEM_Int, MEM_Real, and MEM_IntReal.
22579 +**
22580 +** * MEM_Blob|MEM_Zero A blob in Mem.z of length Mem.n plus
22581 +** MEM.u.i extra 0x00 bytes at the end.
22582 +**
22583 +** * MEM_Int Integer stored in Mem.u.i.
22584 +**
22585 +** * MEM_Real Real stored in Mem.u.r.
22586 +**
22587 +** * MEM_IntReal Real stored as an integer in Mem.u.i.
22588 +**
22589 ** If the MEM_Null flag is set, then the value is an SQL NULL value.
22590 ** For a pointer type created using sqlite3_bind_pointer() or
22591 ** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set.
@@ -22279,6 +22596,7 @@ struct sqlite3_value {
22596 ** set, then the string is nul terminated. The MEM_Int and MEM_Real
22597 ** flags may coexist with the MEM_Str flag.
22598 */
22599 +#define MEM_Undefined 0x0000 /* Value is undefined */
22600 #define MEM_Null 0x0001 /* Value is NULL (or a pointer) */
22601 #define MEM_Str 0x0002 /* Value is a string */
22602 #define MEM_Int 0x0004 /* Value is an integer */
@@ -22286,28 +22604,24 @@ struct sqlite3_value {
22604 #define MEM_Blob 0x0010 /* Value is a BLOB */
22605 #define MEM_IntReal 0x0020 /* MEM_Int that stringifies like MEM_Real */
22606 #define MEM_AffMask 0x003f /* Mask of affinity bits */
22607 +
22608 +/* Extra bits that modify the meanings of the core datatypes above
22609 +*/
22610 #define MEM_FromBind 0x0040 /* Value originates from sqlite3_bind() */
22290 -#define MEM_Undefined 0x0080 /* Value is undefined */
22611 + /* 0x0080 // Available */
22612 #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
22292 -#define MEM_TypeMask 0xc1bf /* Mask of type bits */
22293 -
22613 +#define MEM_Term 0x0200 /* String in Mem.z is zero terminated */
22614 +#define MEM_Zero 0x0400 /* Mem.i contains count of 0s appended to blob */
22615 +#define MEM_Subtype 0x0800 /* Mem.eSubtype is valid */
22616 +#define MEM_TypeMask 0x0dbf /* Mask of type bits */
22617
22295 -/* Whenever Mem contains a valid string or blob representation, one of
22296 -** the following flags must be set to determine the memory management
22297 -** policy for Mem.z. The MEM_Term flag tells us whether or not the
22298 -** string is \000 or \u0000 terminated
22618 +/* Bits that determine the storage for Mem.z for a string or blob or
22619 +** aggregate accumulator.
22620 */
22300 -#define MEM_Term 0x0200 /* String in Mem.z is zero terminated */
22301 -#define MEM_Dyn 0x0400 /* Need to call Mem.xDel() on Mem.z */
22302 -#define MEM_Static 0x0800 /* Mem.z points to a static string */
22303 -#define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
22304 -#define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
22305 -#define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
22306 -#define MEM_Subtype 0x8000 /* Mem.eSubtype is valid */
22307 -#ifdef SQLITE_OMIT_INCRBLOB
22308 - #undef MEM_Zero
22309 - #define MEM_Zero 0x0000
22310 -#endif
22621 +#define MEM_Dyn 0x1000 /* Need to call Mem.xDel() on Mem.z */
22622 +#define MEM_Static 0x2000 /* Mem.z points to a static string */
22623 +#define MEM_Ephem 0x4000 /* Mem.z points to an ephemeral string */
22624 +#define MEM_Agg 0x8000 /* Mem.z points to an agg function context */
22625
22626 /* Return TRUE if Mem X contains dynamically allocated content - anything
22627 ** that needs to be deallocated to avoid a leak.
@@ -22329,11 +22643,15 @@ struct sqlite3_value {
22643 && (X)->n==0 && (X)->u.nZero==0)
22644
22645 /*
22332 -** Return true if a memory cell is not marked as invalid. This macro
22646 +** Return true if a memory cell has been initialized and is valid.
22647 ** is for use inside assert() statements only.
22648 +**
22649 +** A Memory cell is initialized if at least one of the
22650 +** MEM_Null, MEM_Str, MEM_Int, MEM_Real, MEM_Blob, or MEM_IntReal bits
22651 +** is set. It is "undefined" if all those bits are zero.
22652 */
22653 #ifdef SQLITE_DEBUG
22336 -#define memIsValid(M) ((M)->flags & MEM_Undefined)==0
22654 +#define memIsValid(M) ((M)->flags & MEM_AffMask)!=0
22655 #endif
22656
22657 /*
@@ -22371,6 +22689,7 @@ struct sqlite3_context {
22689 Vdbe *pVdbe; /* The VM that owns this context */
22690 int iOp; /* Instruction number of OP_Function */
22691 int isError; /* Error code returned by the function. */
22692 + u8 enc; /* Encoding to use for results */
22693 u8 skipFlag; /* Skip accumulator loading if true */
22694 u8 argc; /* Number of arguments */
22695 sqlite3_value *argv[1]; /* Argument set */
@@ -22416,10 +22735,9 @@ struct DblquoteStr {
22735 */
22736 struct Vdbe {
22737 sqlite3 *db; /* The database connection that owns this statement */
22419 - Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
22738 + Vdbe **ppVPrev,*pVNext; /* Linked list of VDBEs with the same Vdbe.db */
22739 Parse *pParse; /* Parsing context used to create this Vdbe */
22740 ynVar nVar; /* Number of entries in aVar[] */
22422 - u32 iVdbeMagic; /* Magic number defining state of the SQL statement */
22741 int nMem; /* Number of memory locations currently allocated */
22742 int nCursor; /* Number of slots in apCsr[] */
22743 u32 cacheCtr; /* VdbeCursor row cache generation counter */
@@ -22457,11 +22775,10 @@ struct Vdbe {
22775 u8 errorAction; /* Recovery action to do in case of an error */
22776 u8 minWriteFileFormat; /* Minimum file format for writable database files */
22777 u8 prepFlags; /* SQLITE_PREPARE_* flags */
22460 - u8 doingRerun; /* True if rerunning after an auto-reprepare */
22778 + u8 eVdbeState; /* On of the VDBE_*_STATE values */
22779 bft expired:2; /* 1: recompile VM immediately 2: when convenient */
22780 bft explain:2; /* True if EXPLAIN present on SQL command */
22781 bft changeCntOn:1; /* True to update the change-counter */
22464 - bft runOnlyOnce:1; /* Automatically expire on reset */
22782 bft usesStmtJournal:1; /* True if uses a statement journal */
22783 bft readOnly:1; /* True for statements that do not write */
22784 bft bIsReader:1; /* True for statements that read */
@@ -22488,13 +22805,12 @@ struct Vdbe {
22805 };
22806
22807 /*
22491 -** The following are allowed values for Vdbe.magic
22808 +** The following are allowed values for Vdbe.eVdbeState
22809 */
22493 -#define VDBE_MAGIC_INIT 0x16bceaa5 /* Building a VDBE program */
22494 -#define VDBE_MAGIC_RUN 0x2df20da3 /* VDBE is ready to execute */
22495 -#define VDBE_MAGIC_HALT 0x319c2973 /* VDBE has completed execution */
22496 -#define VDBE_MAGIC_RESET 0x48fa9f76 /* Reset and ready to run again */
22497 -#define VDBE_MAGIC_DEAD 0x5606c3c8 /* The VDBE has been deallocated */
22810 +#define VDBE_INIT_STATE 0 /* Prepared statement under construction */
22811 +#define VDBE_READY_STATE 1 /* Ready to run but not yet started */
22812 +#define VDBE_RUN_STATE 2 /* Run in progress */
22813 +#define VDBE_HALT_STATE 3 /* Finished. Need reset() or finalize() */
22814
22815 /*
22816 ** Structure used to store the context required by the
@@ -22535,18 +22851,31 @@ struct ValueList {
22851 sqlite3_value *pOut; /* Register to hold each decoded output value */
22852 };
22853
22854 +/* Size of content associated with serial types that fit into a
22855 +** single-byte varint.
22856 +*/
22857 +#ifndef SQLITE_AMALGAMATION
22858 +SQLITE_PRIVATE const u8 sqlite3SmallTypeSizes[];
22859 +#endif
22860 +
22861 /*
22862 ** Function prototypes
22863 */
22864 SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...);
22865 SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
22866 +SQLITE_PRIVATE void sqlite3VdbeFreeCursorNN(Vdbe*,VdbeCursor*);
22867 void sqliteVdbePopStack(Vdbe*,int);
22868 +SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeHandleMovedCursor(VdbeCursor *p);
22869 SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*);
22545 -SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor**, u32*);
22870 SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*);
22871 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
22872 SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8);
22549 -SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
22873 +#ifdef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
22874 +SQLITE_PRIVATE u64 sqlite3FloatSwap(u64 in);
22875 +# define swapMixedEndianFloat(X) X = sqlite3FloatSwap(X)
22876 +#else
22877 +# define swapMixedEndianFloat(X)
22878 +#endif
22879 SQLITE_PRIVATE void sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
22880 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(sqlite3*, AuxData**, int, int);
22881
@@ -22604,6 +22933,7 @@ SQLITE_PRIVATE int sqlite3VdbeMemCast(Mem*,u8,u8);
22933 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);
22934 SQLITE_PRIVATE int sqlite3VdbeMemFromBtreeZeroOffset(BtCursor*,u32,Mem*);
22935 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
22936 +SQLITE_PRIVATE void sqlite3VdbeMemReleaseMalloc(Mem*p);
22937 SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
22938 #ifndef SQLITE_OMIT_WINDOWFUNC
22939 SQLITE_PRIVATE int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*);
@@ -22963,6 +23293,8 @@ SQLITE_API int sqlite3_db_status(
23293
23294 sqlite3BtreeEnterAll(db);
23295 db->pnBytesFreed = &nByte;
23296 + assert( db->lookaside.pEnd==db->lookaside.pTrueEnd );
23297 + db->lookaside.pEnd = db->lookaside.pStart;
23298 for(i=0; i<db->nDb; i++){
23299 Schema *pSchema = db->aDb[i].pSchema;
23300 if( ALWAYS(pSchema!=0) ){
@@ -22988,6 +23320,7 @@ SQLITE_API int sqlite3_db_status(
23320 }
23321 }
23322 db->pnBytesFreed = 0;
23323 + db->lookaside.pEnd = db->lookaside.pTrueEnd;
23324 sqlite3BtreeLeaveAll(db);
23325
23326 *pHighwater = 0;
@@ -23005,10 +23338,12 @@ SQLITE_API int sqlite3_db_status(
23338 int nByte = 0; /* Used to accumulate return value */
23339
23340 db->pnBytesFreed = &nByte;
23008 - for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){
23009 - sqlite3VdbeClearObject(db, pVdbe);
23010 - sqlite3DbFree(db, pVdbe);
23341 + assert( db->lookaside.pEnd==db->lookaside.pTrueEnd );
23342 + db->lookaside.pEnd = db->lookaside.pStart;
23343 + for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pVNext){
23344 + sqlite3VdbeDelete(pVdbe);
23345 }
23346 + db->lookaside.pEnd = db->lookaside.pTrueEnd;
23347 db->pnBytesFreed = 0;
23348
23349 *pHighwater = 0; /* IMP: R-64479-57858 */
@@ -23344,7 +23679,7 @@ static void computeJD(DateTime *p){
23679 p->iJD = (sqlite3_int64)((X1 + X2 + D + B - 1524.5 ) * 86400000);
23680 p->validJD = 1;
23681 if( p->validHMS ){
23347 - p->iJD += p->h*3600000 + p->m*60000 + (sqlite3_int64)(p->s*1000);
23682 + p->iJD += p->h*3600000 + p->m*60000 + (sqlite3_int64)(p->s*1000 + 0.5);
23683 if( p->validTZ ){
23684 p->iJD -= p->tz*60000;
23685 p->validYMD = 0;
@@ -23853,7 +24188,7 @@ static int parseModifier(
24188 */
24189 if( sqlite3_strnicmp(z, "weekday ", 8)==0
24190 && sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8)>0
23856 - && (n=(int)r)==r && n>=0 && r<7 ){
24191 + && r>=0.0 && r<7.0 && (n=(int)r)==r ){
24192 sqlite3_int64 Z;
24193 computeYMD_HMS(p);
24194 p->validTZ = 0;
@@ -24534,9 +24869,11 @@ SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file *id, i64 *pSize){
24869 }
24870 SQLITE_PRIVATE int sqlite3OsLock(sqlite3_file *id, int lockType){
24871 DO_OS_MALLOC_TEST(id);
24872 + assert( lockType>=SQLITE_LOCK_SHARED && lockType<=SQLITE_LOCK_EXCLUSIVE );
24873 return id->pMethods->xLock(id, lockType);
24874 }
24875 SQLITE_PRIVATE int sqlite3OsUnlock(sqlite3_file *id, int lockType){
24876 + assert( lockType==SQLITE_LOCK_NONE || lockType==SQLITE_LOCK_SHARED );
24877 return id->pMethods->xUnlock(id, lockType);
24878 }
24879 SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut){
@@ -24651,6 +24988,7 @@ SQLITE_PRIVATE int sqlite3OsOpen(
24988 ** down into the VFS layer. Some SQLITE_OPEN_ flags (for example,
24989 ** SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_SHAREDCACHE) are blocked before
24990 ** reaching the VFS. */
24991 + assert( zPath || (flags & SQLITE_OPEN_EXCLUSIVE) );
24992 rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x1087f7f, pFlagsOut);
24993 assert( rc==SQLITE_OK || pFile->pMethods==0 );
24994 return rc;
@@ -26962,8 +27300,17 @@ static void *memsys5Realloc(void *pPrior, int nBytes){
27300 */
27301 static int memsys5Roundup(int n){
27302 int iFullSz;
26965 - if( n > 0x40000000 ) return 0;
26966 - for(iFullSz=mem5.szAtom; iFullSz<n; iFullSz *= 2);
27303 + if( n<=mem5.szAtom*2 ){
27304 + if( n<=mem5.szAtom ) return mem5.szAtom;
27305 + return mem5.szAtom*2;
27306 + }
27307 + if( n>0x10000000 ){
27308 + if( n>0x40000000 ) return 0;
27309 + if( n>0x20000000 ) return 0x40000000;
27310 + return 0x20000000;
27311 + }
27312 + for(iFullSz=mem5.szAtom*8; iFullSz<n; iFullSz *= 4);
27313 + if( (iFullSz/2)>=(i64)n ) return iFullSz/2;
27314 return iFullSz;
27315 }
27316
@@ -28864,18 +29211,34 @@ static void mallocWithAlarm(int n, void **pp){
29211 *pp = p;
29212 }
29213
29214 +/*
29215 +** Maximum size of any single memory allocation.
29216 +**
29217 +** This is not a limit on the total amount of memory used. This is
29218 +** a limit on the size parameter to sqlite3_malloc() and sqlite3_realloc().
29219 +**
29220 +** The upper bound is slightly less than 2GiB: 0x7ffffeff == 2,147,483,391
29221 +** This provides a 256-byte safety margin for defense against 32-bit
29222 +** signed integer overflow bugs when computing memory allocation sizes.
29223 +** Parnoid applications might want to reduce the maximum allocation size
29224 +** further for an even larger safety margin. 0x3fffffff or 0x0fffffff
29225 +** or even smaller would be reasonable upper bounds on the size of a memory
29226 +** allocations for most applications.
29227 +*/
29228 +#ifndef SQLITE_MAX_ALLOCATION_SIZE
29229 +# define SQLITE_MAX_ALLOCATION_SIZE 2147483391
29230 +#endif
29231 +#if SQLITE_MAX_ALLOCATION_SIZE>2147483391
29232 +# error Maximum size for SQLITE_MAX_ALLOCATION_SIZE is 2147483391
29233 +#endif
29234 +
29235 /*
29236 ** Allocate memory. This routine is like sqlite3_malloc() except that it
29237 ** assumes the memory subsystem has already been initialized.
29238 */
29239 SQLITE_PRIVATE void *sqlite3Malloc(u64 n){
29240 void *p;
28873 - if( n==0 || n>=0x7fffff00 ){
28874 - /* A memory allocation of a number of bytes which is near the maximum
28875 - ** signed integer value might cause an integer overflow inside of the
28876 - ** xMalloc(). Hence we limit the maximum size to 0x7fffff00, giving
28877 - ** 255 bytes of overhead. SQLite itself will never use anything near
28878 - ** this amount. The only way to reach the limit is with sqlite3_malloc() */
29241 + if( n==0 || n>SQLITE_MAX_ALLOCATION_SIZE ){
29242 p = 0;
29243 }else if( sqlite3GlobalConfig.bMemstat ){
29244 sqlite3_mutex_enter(mem0.mutex);
@@ -28911,7 +29274,7 @@ SQLITE_API void *sqlite3_malloc64(sqlite3_uint64 n){
29274 */
29275 #ifndef SQLITE_OMIT_LOOKASIDE
29276 static int isLookaside(sqlite3 *db, const void *p){
28914 - return SQLITE_WITHIN(p, db->lookaside.pStart, db->lookaside.pEnd);
29277 + return SQLITE_WITHIN(p, db->lookaside.pStart, db->lookaside.pTrueEnd);
29278 }
29279 #else
29280 #define isLookaside(A,B) 0
@@ -28935,18 +29298,16 @@ static int lookasideMallocSize(sqlite3 *db, const void *p){
29298 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, const void *p){
29299 assert( p!=0 );
29300 #ifdef SQLITE_DEBUG
28938 - if( db==0 || !isLookaside(db,p) ){
28939 - if( db==0 ){
28940 - assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
28941 - assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
28942 - }else{
28943 - assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
28944 - assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
28945 - }
29301 + if( db==0 ){
29302 + assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
29303 + assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
29304 + }else if( !isLookaside(db,p) ){
29305 + assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
29306 + assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
29307 }
29308 #endif
29309 if( db ){
28949 - if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
29310 + if( ((uptr)p)<(uptr)(db->lookaside.pTrueEnd) ){
29311 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
29312 if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
29313 assert( sqlite3_mutex_held(db->mutex) );
@@ -29002,14 +29363,11 @@ SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3 *db, void *p){
29363 assert( db==0 || sqlite3_mutex_held(db->mutex) );
29364 assert( p!=0 );
29365 if( db ){
29005 - if( db->pnBytesFreed ){
29006 - measureAllocationSize(db, p);
29007 - return;
29008 - }
29366 if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
29367 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
29368 if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
29369 LookasideSlot *pBuf = (LookasideSlot*)p;
29370 + assert( db->pnBytesFreed==0 );
29371 #ifdef SQLITE_DEBUG
29372 memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */
29373 #endif
@@ -29020,6 +29378,7 @@ SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3 *db, void *p){
29378 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
29379 if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){
29380 LookasideSlot *pBuf = (LookasideSlot*)p;
29381 + assert( db->pnBytesFreed==0 );
29382 #ifdef SQLITE_DEBUG
29383 memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */
29384 #endif
@@ -29028,6 +29387,10 @@ SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3 *db, void *p){
29387 return;
29388 }
29389 }
29390 + if( db->pnBytesFreed ){
29391 + measureAllocationSize(db, p);
29392 + return;
29393 + }
29394 }
29395 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
29396 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
@@ -29035,6 +29398,43 @@ SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3 *db, void *p){
29398 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
29399 sqlite3_free(p);
29400 }
29401 +SQLITE_PRIVATE void sqlite3DbNNFreeNN(sqlite3 *db, void *p){
29402 + assert( db!=0 );
29403 + assert( sqlite3_mutex_held(db->mutex) );
29404 + assert( p!=0 );
29405 + if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
29406 +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
29407 + if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
29408 + LookasideSlot *pBuf = (LookasideSlot*)p;
29409 + assert( db->pnBytesFreed==0 );
29410 +#ifdef SQLITE_DEBUG
29411 + memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */
29412 +#endif
29413 + pBuf->pNext = db->lookaside.pSmallFree;
29414 + db->lookaside.pSmallFree = pBuf;
29415 + return;
29416 + }
29417 +#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
29418 + if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){
29419 + LookasideSlot *pBuf = (LookasideSlot*)p;
29420 + assert( db->pnBytesFreed==0 );
29421 +#ifdef SQLITE_DEBUG
29422 + memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */
29423 +#endif
29424 + pBuf->pNext = db->lookaside.pFree;
29425 + db->lookaside.pFree = pBuf;
29426 + return;
29427 + }
29428 + }
29429 + if( db->pnBytesFreed ){
29430 + measureAllocationSize(db, p);
29431 + return;
29432 + }
29433 + assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
29434 + assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
29435 + sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
29436 + sqlite3_free(p);
29437 +}
29438 SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
29439 assert( db==0 || sqlite3_mutex_held(db->mutex) );
29440 if( p ) sqlite3DbFreeNN(db, p);
@@ -29370,8 +29770,13 @@ SQLITE_PRIVATE void *sqlite3OomFault(sqlite3 *db){
29770 }
29771 DisableLookaside;
29772 if( db->pParse ){
29773 + Parse *pParse;
29774 sqlite3ErrorMsg(db->pParse, "out of memory");
29775 db->pParse->rc = SQLITE_NOMEM_BKPT;
29776 + for(pParse=db->pParse->pOuterParse; pParse; pParse = pParse->pOuterParse){
29777 + pParse->nErr++;
29778 + pParse->rc = SQLITE_NOMEM;
29779 + }
29780 }
29781 }
29782 return 0;
@@ -30237,8 +30642,8 @@ SQLITE_API void sqlite3_str_vappendf(
30642 case etSQLESCAPE: /* %q: Escape ' characters */
30643 case etSQLESCAPE2: /* %Q: Escape ' and enclose in '...' */
30644 case etSQLESCAPE3: { /* %w: Escape " characters */
30240 - int i, j, k, n, isnull;
30241 - int needQuote;
30645 + i64 i, j, k, n;
30646 + int needQuote, isnull;
30647 char ch;
30648 char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
30649 char *escarg;
@@ -30318,8 +30723,14 @@ SQLITE_API void sqlite3_str_vappendf(
30723 sqlite3_str_appendall(pAccum, pItem->zName);
30724 }else if( pItem->zAlias ){
30725 sqlite3_str_appendall(pAccum, pItem->zAlias);
30321 - }else if( ALWAYS(pItem->pSelect) ){
30322 - sqlite3_str_appendf(pAccum, "SUBQUERY %u", pItem->pSelect->selId);
30726 + }else{
30727 + Select *pSel = pItem->pSelect;
30728 + assert( pSel!=0 );
30729 + if( pSel->selFlags & SF_NestedFrom ){
30730 + sqlite3_str_appendf(pAccum, "(join-%u)", pSel->selId);
30731 + }else{
30732 + sqlite3_str_appendf(pAccum, "(subquery-%u)", pSel->selId);
30733 + }
30734 }
30735 length = width = 0;
30736 break;
@@ -30382,7 +30793,9 @@ SQLITE_PRIVATE void sqlite3RecordErrorByteOffset(sqlite3 *db, const char *z){
30793 ** as the error offset.
30794 */
30795 SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3 *db, const Expr *pExpr){
30385 - while( pExpr && (ExprHasProperty(pExpr,EP_FromJoin) || pExpr->w.iOfst<=0) ){
30796 + while( pExpr
30797 + && (ExprHasProperty(pExpr,EP_OuterON|EP_InnerON) || pExpr->w.iOfst<=0)
30798 + ){
30799 pExpr = pExpr->pLeft;
30800 }
30801 if( pExpr==0 ) return;
@@ -30842,40 +31255,44 @@ SQLITE_API void sqlite3_str_appendf(StrAccum *p, const char *zFormat, ...){
31255 ** Add a new subitem to the tree. The moreToFollow flag indicates that this
31256 ** is not the last item in the tree.
31257 */
30845 -static TreeView *sqlite3TreeViewPush(TreeView *p, u8 moreToFollow){
31258 +static void sqlite3TreeViewPush(TreeView **pp, u8 moreToFollow){
31259 + TreeView *p = *pp;
31260 if( p==0 ){
30847 - p = sqlite3_malloc64( sizeof(*p) );
30848 - if( p==0 ) return 0;
31261 + *pp = p = sqlite3_malloc64( sizeof(*p) );
31262 + if( p==0 ) return;
31263 memset(p, 0, sizeof(*p));
31264 }else{
31265 p->iLevel++;
31266 }
31267 assert( moreToFollow==0 || moreToFollow==1 );
30854 - if( p->iLevel<sizeof(p->bLine) ) p->bLine[p->iLevel] = moreToFollow;
30855 - return p;
31268 + if( p->iLevel<(int)sizeof(p->bLine) ) p->bLine[p->iLevel] = moreToFollow;
31269 }
31270
31271 /*
31272 ** Finished with one layer of the tree
31273 */
30861 -static void sqlite3TreeViewPop(TreeView *p){
31274 +static void sqlite3TreeViewPop(TreeView **pp){
31275 + TreeView *p = *pp;
31276 if( p==0 ) return;
31277 p->iLevel--;
30864 - if( p->iLevel<0 ) sqlite3_free(p);
31278 + if( p->iLevel<0 ){
31279 + sqlite3_free(p);
31280 + *pp = 0;
31281 + }
31282 }
31283
31284 /*
31285 ** Generate a single line of output for the tree, with a prefix that contains
31286 ** all the appropriate tree lines
31287 */
30871 -static void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){
31288 +SQLITE_PRIVATE void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){
31289 va_list ap;
31290 int i;
31291 StrAccum acc;
30875 - char zBuf[500];
31292 + char zBuf[1000];
31293 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
31294 if( p ){
30878 - for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){
31295 + for(i=0; i<p->iLevel && i<(int)sizeof(p->bLine)-1; i++){
31296 sqlite3_str_append(&acc, p->bLine[i] ? "| " : " ", 4);
31297 }
31298 sqlite3_str_append(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
@@ -30896,10 +31313,57 @@ static void sqlite3TreeViewLine(TreeView *p, const char *zFormat, ...){
31313 ** Shorthand for starting a new tree item that consists of a single label
31314 */
31315 static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){
30899 - p = sqlite3TreeViewPush(p, moreFollows);
31316 + sqlite3TreeViewPush(&p, moreFollows);
31317 sqlite3TreeViewLine(p, "%s", zLabel);
31318 }
31319
31320 +/*
31321 +** Show a list of Column objects in tree format.
31322 +*/
31323 +SQLITE_PRIVATE void sqlite3TreeViewColumnList(
31324 + TreeView *pView,
31325 + const Column *aCol,
31326 + int nCol,
31327 + u8 moreToFollow
31328 +){
31329 + int i;
31330 + sqlite3TreeViewPush(&pView, moreToFollow);
31331 + sqlite3TreeViewLine(pView, "COLUMNS");
31332 + for(i=0; i<nCol; i++){
31333 + u16 flg = aCol[i].colFlags;
31334 + int colMoreToFollow = i<(nCol - 1);
31335 + sqlite3TreeViewPush(&pView, colMoreToFollow);
31336 + sqlite3TreeViewLine(pView, 0);
31337 + printf(" %s", aCol[i].zCnName);
31338 + switch( aCol[i].eCType ){
31339 + case COLTYPE_ANY: printf(" ANY"); break;
31340 + case COLTYPE_BLOB: printf(" BLOB"); break;
31341 + case COLTYPE_INT: printf(" INT"); break;
31342 + case COLTYPE_INTEGER: printf(" INTEGER"); break;
31343 + case COLTYPE_REAL: printf(" REAL"); break;
31344 + case COLTYPE_TEXT: printf(" TEXT"); break;
31345 + case COLTYPE_CUSTOM: {
31346 + if( flg & COLFLAG_HASTYPE ){
31347 + const char *z = aCol[i].zCnName;
31348 + z += strlen(z)+1;
31349 + printf(" X-%s", z);
31350 + break;
31351 + }
31352 + }
31353 + }
31354 + if( flg & COLFLAG_PRIMKEY ) printf(" PRIMARY KEY");
31355 + if( flg & COLFLAG_HIDDEN ) printf(" HIDDEN");
31356 +#ifdef COLFLAG_NOEXPAND
31357 + if( flg & COLFLAG_NOEXPAND ) printf(" NO-EXPAND");
31358 +#endif
31359 + if( flg ) printf(" flags=%04x", flg);
31360 + printf("\n");
31361 + fflush(stdout);
31362 + sqlite3TreeViewPop(&pView);
31363 + }
31364 + sqlite3TreeViewPop(&pView);
31365 +}
31366 +
31367 /*
31368 ** Generate a human-readable description of a WITH clause.
31369 */
@@ -30913,7 +31377,7 @@ SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 m
31377 sqlite3TreeViewLine(pView, "WITH (0x%p)", pWith);
31378 }
31379 if( pWith->nCte>0 ){
30916 - pView = sqlite3TreeViewPush(pView, 1);
31380 + sqlite3TreeViewPush(&pView, moreToFollow);
31381 for(i=0; i<pWith->nCte; i++){
31382 StrAccum x;
31383 char zLine[1000];
@@ -30929,6 +31393,10 @@ SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 m
31393 }
31394 sqlite3_str_appendf(&x, ")");
31395 }
31396 + if( pCte->eM10d!=M10d_Any ){
31397 + sqlite3_str_appendf(&x, " %sMATERIALIZED",
31398 + pCte->eM10d==M10d_No ? "NOT " : "");
31399 + }
31400 if( pCte->pUse ){
31401 sqlite3_str_appendf(&x, " (pUse=0x%p, nUse=%d)", pCte->pUse,
31402 pCte->pUse->nUse);
@@ -30936,9 +31404,9 @@ SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 m
31404 sqlite3StrAccumFinish(&x);
31405 sqlite3TreeViewItem(pView, zLine, i<pWith->nCte-1);
31406 sqlite3TreeViewSelect(pView, pCte->pSelect, 0);
30939 - sqlite3TreeViewPop(pView);
31407 + sqlite3TreeViewPop(&pView);
31408 }
30941 - sqlite3TreeViewPop(pView);
31409 + sqlite3TreeViewPop(&pView);
31410 }
31411 }
31412
@@ -30947,10 +31415,12 @@ SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 m
31415 */
31416 SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc){
31417 int i;
31418 + if( pSrc==0 ) return;
31419 for(i=0; i<pSrc->nSrc; i++){
31420 const SrcItem *pItem = &pSrc->a[i];
31421 StrAccum x;
30953 - char zLine[100];
31422 + int n = 0;
31423 + char zLine[1000];
31424 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
31425 x.printfFlags |= SQLITE_PRINTF_INTERNAL;
31426 sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
@@ -30958,26 +31428,48 @@ SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc)
31428 sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx",
31429 pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed);
31430 }
30961 - if( pItem->fg.jointype & JT_LEFT ){
31431 + if( (pItem->fg.jointype & (JT_LEFT|JT_RIGHT))==(JT_LEFT|JT_RIGHT) ){
31432 + sqlite3_str_appendf(&x, " FULL-OUTER-JOIN");
31433 + }else if( pItem->fg.jointype & JT_LEFT ){
31434 sqlite3_str_appendf(&x, " LEFT-JOIN");
31435 + }else if( pItem->fg.jointype & JT_RIGHT ){
31436 + sqlite3_str_appendf(&x, " RIGHT-JOIN");
31437 }else if( pItem->fg.jointype & JT_CROSS ){
31438 sqlite3_str_appendf(&x, " CROSS-JOIN");
31439 }
31440 + if( pItem->fg.jointype & JT_LTORJ ){
31441 + sqlite3_str_appendf(&x, " LTORJ");
31442 + }
31443 if( pItem->fg.fromDDL ){
31444 sqlite3_str_appendf(&x, " DDL");
31445 }
31446 if( pItem->fg.isCte ){
31447 sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse);
31448 }
31449 + if( pItem->fg.isOn || (pItem->fg.isUsing==0 && pItem->u3.pOn!=0) ){
31450 + sqlite3_str_appendf(&x, " ON");
31451 + }
31452 sqlite3StrAccumFinish(&x);
31453 sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
31454 + n = 0;
31455 + if( pItem->pSelect ) n++;
31456 + if( pItem->fg.isTabFunc ) n++;
31457 + if( pItem->fg.isUsing ) n++;
31458 + if( pItem->fg.isUsing ){
31459 + sqlite3TreeViewIdList(pView, pItem->u3.pUsing, (--n)>0, "USING");
31460 + }
31461 if( pItem->pSelect ){
30975 - sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
31462 + if( pItem->pTab ){
31463 + Table *pTab = pItem->pTab;
31464 + sqlite3TreeViewColumnList(pView, pTab->aCol, pTab->nCol, 1);
31465 + }
31466 + assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
31467 + sqlite3TreeViewSelect(pView, pItem->pSelect, (--n)>0);
31468 }
31469 if( pItem->fg.isTabFunc ){
31470 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
31471 }
30980 - sqlite3TreeViewPop(pView);
31472 + sqlite3TreeViewPop(&pView);
31473 }
31474 }
31475
@@ -30991,11 +31483,11 @@ SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 m
31483 sqlite3TreeViewLine(pView, "nil-SELECT");
31484 return;
31485 }
30994 - pView = sqlite3TreeViewPush(pView, moreToFollow);
31486 + sqlite3TreeViewPush(&pView, moreToFollow);
31487 if( p->pWith ){
31488 sqlite3TreeViewWith(pView, p->pWith, 1);
31489 cnt = 1;
30998 - sqlite3TreeViewPush(pView, 1);
31490 + sqlite3TreeViewPush(&pView, 1);
31491 }
31492 do{
31493 if( p->selFlags & SF_WhereBegin ){
@@ -31009,7 +31501,7 @@ SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 m
31501 (int)p->nSelectRow
31502 );
31503 }
31012 - if( cnt++ ) sqlite3TreeViewPop(pView);
31504 + if( cnt++ ) sqlite3TreeViewPop(&pView);
31505 if( p->pPrior ){
31506 n = 1000;
31507 }else{
@@ -31032,24 +31524,24 @@ SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 m
31524 #ifndef SQLITE_OMIT_WINDOWFUNC
31525 if( p->pWin ){
31526 Window *pX;
31035 - pView = sqlite3TreeViewPush(pView, (n--)>0);
31527 + sqlite3TreeViewPush(&pView, (n--)>0);
31528 sqlite3TreeViewLine(pView, "window-functions");
31529 for(pX=p->pWin; pX; pX=pX->pNextWin){
31530 sqlite3TreeViewWinFunc(pView, pX, pX->pNextWin!=0);
31531 }
31040 - sqlite3TreeViewPop(pView);
31532 + sqlite3TreeViewPop(&pView);
31533 }
31534 #endif
31535 if( p->pSrc && p->pSrc->nSrc ){
31044 - pView = sqlite3TreeViewPush(pView, (n--)>0);
31536 + sqlite3TreeViewPush(&pView, (n--)>0);
31537 sqlite3TreeViewLine(pView, "FROM");
31538 sqlite3TreeViewSrcList(pView, p->pSrc);
31047 - sqlite3TreeViewPop(pView);
31539 + sqlite3TreeViewPop(&pView);
31540 }
31541 if( p->pWhere ){
31542 sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
31543 sqlite3TreeViewExpr(pView, p->pWhere, 0);
31052 - sqlite3TreeViewPop(pView);
31544 + sqlite3TreeViewPop(&pView);
31545 }
31546 if( p->pGroupBy ){
31547 sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY");
@@ -31057,7 +31549,7 @@ SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 m
31549 if( p->pHaving ){
31550 sqlite3TreeViewItem(pView, "HAVING", (n--)>0);
31551 sqlite3TreeViewExpr(pView, p->pHaving, 0);
31060 - sqlite3TreeViewPop(pView);
31552 + sqlite3TreeViewPop(&pView);
31553 }
31554 #ifndef SQLITE_OMIT_WINDOWFUNC
31555 if( p->pWinDefn ){
@@ -31066,7 +31558,7 @@ SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 m
31558 for(pX=p->pWinDefn; pX; pX=pX->pNextWin){
31559 sqlite3TreeViewWindow(pView, pX, pX->pNextWin!=0);
31560 }
31069 - sqlite3TreeViewPop(pView);
31561 + sqlite3TreeViewPop(&pView);
31562 }
31563 #endif
31564 if( p->pOrderBy ){
@@ -31078,9 +31570,9 @@ SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 m
31570 if( p->pLimit->pRight ){
31571 sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
31572 sqlite3TreeViewExpr(pView, p->pLimit->pRight, 0);
31081 - sqlite3TreeViewPop(pView);
31573 + sqlite3TreeViewPop(&pView);
31574 }
31083 - sqlite3TreeViewPop(pView);
31575 + sqlite3TreeViewPop(&pView);
31576 }
31577 if( p->pPrior ){
31578 const char *zOp = "UNION";
@@ -31093,7 +31585,7 @@ SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 m
31585 }
31586 p = p->pPrior;
31587 }while( p!=0 );
31096 - sqlite3TreeViewPop(pView);
31588 + sqlite3TreeViewPop(&pView);
31589 }
31590
31591 #ifndef SQLITE_OMIT_WINDOWFUNC
@@ -31109,24 +31601,24 @@ SQLITE_PRIVATE void sqlite3TreeViewBound(
31601 switch( eBound ){
31602 case TK_UNBOUNDED: {
31603 sqlite3TreeViewItem(pView, "UNBOUNDED", moreToFollow);
31112 - sqlite3TreeViewPop(pView);
31604 + sqlite3TreeViewPop(&pView);
31605 break;
31606 }
31607 case TK_CURRENT: {
31608 sqlite3TreeViewItem(pView, "CURRENT", moreToFollow);
31117 - sqlite3TreeViewPop(pView);
31609 + sqlite3TreeViewPop(&pView);
31610 break;
31611 }
31612 case TK_PRECEDING: {
31613 sqlite3TreeViewItem(pView, "PRECEDING", moreToFollow);
31614 sqlite3TreeViewExpr(pView, pExpr, 0);
31123 - sqlite3TreeViewPop(pView);
31615 + sqlite3TreeViewPop(&pView);
31616 break;
31617 }
31618 case TK_FOLLOWING: {
31619 sqlite3TreeViewItem(pView, "FOLLOWING", moreToFollow);
31620 sqlite3TreeViewExpr(pView, pExpr, 0);
31129 - sqlite3TreeViewPop(pView);
31621 + sqlite3TreeViewPop(&pView);
31622 break;
31623 }
31624 }
@@ -31139,12 +31631,13 @@ SQLITE_PRIVATE void sqlite3TreeViewBound(
31631 */
31632 SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){
31633 int nElement = 0;
31634 + if( pWin==0 ) return;
31635 if( pWin->pFilter ){
31636 sqlite3TreeViewItem(pView, "FILTER", 1);
31637 sqlite3TreeViewExpr(pView, pWin->pFilter, 0);
31145 - sqlite3TreeViewPop(pView);
31638 + sqlite3TreeViewPop(&pView);
31639 }
31147 - pView = sqlite3TreeViewPush(pView, more);
31640 + sqlite3TreeViewPush(&pView, more);
31641 if( pWin->zName ){
31642 sqlite3TreeViewLine(pView, "OVER %s (%p)", pWin->zName, pWin);
31643 }else{
@@ -31155,9 +31648,9 @@ SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u
31648 if( pWin->eFrmType ) nElement++;
31649 if( pWin->eExclude ) nElement++;
31650 if( pWin->zBase ){
31158 - sqlite3TreeViewPush(pView, (--nElement)>0);
31651 + sqlite3TreeViewPush(&pView, (--nElement)>0);
31652 sqlite3TreeViewLine(pView, "window: %s", pWin->zBase);
31160 - sqlite3TreeViewPop(pView);
31653 + sqlite3TreeViewPop(&pView);
31654 }
31655 if( pWin->pPartition ){
31656 sqlite3TreeViewExprList(pView, pWin->pPartition, nElement>0,"PARTITION-BY");
@@ -31175,7 +31668,7 @@ SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u
31668 sqlite3TreeViewItem(pView, zBuf, (--nElement)>0);
31669 sqlite3TreeViewBound(pView, pWin->eStart, pWin->pStart, 1);
31670 sqlite3TreeViewBound(pView, pWin->eEnd, pWin->pEnd, 0);
31178 - sqlite3TreeViewPop(pView);
31671 + sqlite3TreeViewPop(&pView);
31672 }
31673 if( pWin->eExclude ){
31674 char zBuf[30];
@@ -31190,11 +31683,11 @@ SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u
31683 zExclude = zBuf;
31684 break;
31685 }
31193 - sqlite3TreeViewPush(pView, 0);
31686 + sqlite3TreeViewPush(&pView, 0);
31687 sqlite3TreeViewLine(pView, "EXCLUDE %s", zExclude);
31195 - sqlite3TreeViewPop(pView);
31688 + sqlite3TreeViewPop(&pView);
31689 }
31197 - sqlite3TreeViewPop(pView);
31690 + sqlite3TreeViewPop(&pView);
31691 }
31692 #endif /* SQLITE_OMIT_WINDOWFUNC */
31693
@@ -31203,11 +31696,12 @@ SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u
31696 ** Generate a human-readable explanation for a Window Function object
31697 */
31698 SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){
31206 - pView = sqlite3TreeViewPush(pView, more);
31699 + if( pWin==0 ) return;
31700 + sqlite3TreeViewPush(&pView, more);
31701 sqlite3TreeViewLine(pView, "WINFUNC %s(%d)",
31208 - pWin->pFunc->zName, pWin->pFunc->nArg);
31702 + pWin->pWFunc->zName, pWin->pWFunc->nArg);
31703 sqlite3TreeViewWindow(pView, pWin, 0);
31210 - sqlite3TreeViewPop(pView);
31704 + sqlite3TreeViewPop(&pView);
31705 }
31706 #endif /* SQLITE_OMIT_WINDOWFUNC */
31707
@@ -31218,10 +31712,10 @@ SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 m
31712 const char *zBinOp = 0; /* Binary operator */
31713 const char *zUniOp = 0; /* Unary operator */
31714 char zFlgs[200];
31221 - pView = sqlite3TreeViewPush(pView, moreToFollow);
31715 + sqlite3TreeViewPush(&pView, moreToFollow);
31716 if( pExpr==0 ){
31717 sqlite3TreeViewLine(pView, "nil");
31224 - sqlite3TreeViewPop(pView);
31718 + sqlite3TreeViewPop(&pView);
31719 return;
31720 }
31721 if( pExpr->flags || pExpr->affExpr || pExpr->vvaFlags ){
@@ -31229,8 +31723,11 @@ SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 m
31723 sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0);
31724 sqlite3_str_appendf(&x, " fg.af=%x.%c",
31725 pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n');
31232 - if( ExprHasProperty(pExpr, EP_FromJoin) ){
31233 - sqlite3_str_appendf(&x, " iRJT=%d", pExpr->w.iRightJoinTable);
31726 + if( ExprHasProperty(pExpr, EP_OuterON) ){
31727 + sqlite3_str_appendf(&x, " outer.iJoin=%d", pExpr->w.iJoin);
31728 + }
31729 + if( ExprHasProperty(pExpr, EP_InnerON) ){
31730 + sqlite3_str_appendf(&x, " inner.iJoin=%d", pExpr->w.iJoin);
31731 }
31732 if( ExprHasProperty(pExpr, EP_FromDDL) ){
31733 sqlite3_str_appendf(&x, " DDL");
@@ -31454,7 +31951,17 @@ SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 m
31951 break;
31952 }
31953 case TK_IN: {
31457 - sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags);
31954 + sqlite3_str *pStr = sqlite3_str_new(0);
31955 + char *z;
31956 + sqlite3_str_appendf(pStr, "IN flags=0x%x", pExpr->flags);
31957 + if( pExpr->iTable ) sqlite3_str_appendf(pStr, " iTable=%d",pExpr->iTable);
31958 + if( ExprHasProperty(pExpr, EP_Subrtn) ){
31959 + sqlite3_str_appendf(pStr, " subrtn(%d,%d)",
31960 + pExpr->y.sub.regReturn, pExpr->y.sub.iAddr);
31961 + }
31962 + z = sqlite3_str_finish(pStr);
31963 + sqlite3TreeViewLine(pView, z);
31964 + sqlite3_free(z);
31965 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
31966 if( ExprUseXSelect(pExpr) ){
31967 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
@@ -31578,7 +32085,7 @@ SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 m
32085 sqlite3TreeViewLine(pView, "%s%s", zUniOp, zFlgs);
32086 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
32087 }
31581 - sqlite3TreeViewPop(pView);
32088 + sqlite3TreeViewPop(&pView);
32089 }
32090
32091
@@ -31600,13 +32107,25 @@ SQLITE_PRIVATE void sqlite3TreeViewBareExprList(
32107 int j = pList->a[i].u.x.iOrderByCol;
32108 char *zName = pList->a[i].zEName;
32109 int moreToFollow = i<pList->nExpr - 1;
31603 - if( pList->a[i].eEName!=ENAME_NAME ) zName = 0;
32110 if( j || zName ){
31605 - sqlite3TreeViewPush(pView, moreToFollow);
32111 + sqlite3TreeViewPush(&pView, moreToFollow);
32112 moreToFollow = 0;
32113 sqlite3TreeViewLine(pView, 0);
32114 if( zName ){
31609 - fprintf(stdout, "AS %s ", zName);
32115 + switch( pList->a[i].fg.eEName ){
32116 + default:
32117 + fprintf(stdout, "AS %s ", zName);
32118 + break;
32119 + case ENAME_TAB:
32120 + fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName);
32121 + if( pList->a[i].fg.bUsed ) fprintf(stdout, "(used) ");
32122 + if( pList->a[i].fg.bUsingTerm ) fprintf(stdout, "(USING-term) ");
32123 + if( pList->a[i].fg.bNoExpand ) fprintf(stdout, "(NoExpand) ");
32124 + break;
32125 + case ENAME_SPAN:
32126 + fprintf(stdout, "SPAN(\"%s\") ", zName);
32127 + break;
32128 + }
32129 }
32130 if( j ){
32131 fprintf(stdout, "iOrderByCol=%d", j);
@@ -31616,7 +32135,7 @@ SQLITE_PRIVATE void sqlite3TreeViewBareExprList(
32135 }
32136 sqlite3TreeViewExpr(pView, pList->a[i].pExpr, moreToFollow);
32137 if( j || zName ){
31619 - sqlite3TreeViewPop(pView);
32138 + sqlite3TreeViewPop(&pView);
32139 }
32140 }
32141 }
@@ -31627,10 +32146,377 @@ SQLITE_PRIVATE void sqlite3TreeViewExprList(
32146 u8 moreToFollow,
32147 const char *zLabel
32148 ){
31630 - pView = sqlite3TreeViewPush(pView, moreToFollow);
32149 + sqlite3TreeViewPush(&pView, moreToFollow);
32150 sqlite3TreeViewBareExprList(pView, pList, zLabel);
31632 - sqlite3TreeViewPop(pView);
32151 + sqlite3TreeViewPop(&pView);
32152 +}
32153 +
32154 +/*
32155 +** Generate a human-readable explanation of an id-list.
32156 +*/
32157 +SQLITE_PRIVATE void sqlite3TreeViewBareIdList(
32158 + TreeView *pView,
32159 + const IdList *pList,
32160 + const char *zLabel
32161 +){
32162 + if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST";
32163 + if( pList==0 ){
32164 + sqlite3TreeViewLine(pView, "%s (empty)", zLabel);
32165 + }else{
32166 + int i;
32167 + sqlite3TreeViewLine(pView, "%s", zLabel);
32168 + for(i=0; i<pList->nId; i++){
32169 + char *zName = pList->a[i].zName;
32170 + int moreToFollow = i<pList->nId - 1;
32171 + if( zName==0 ) zName = "(null)";
32172 + sqlite3TreeViewPush(&pView, moreToFollow);
32173 + sqlite3TreeViewLine(pView, 0);
32174 + if( pList->eU4==EU4_NONE ){
32175 + fprintf(stdout, "%s\n", zName);
32176 + }else if( pList->eU4==EU4_IDX ){
32177 + fprintf(stdout, "%s (%d)\n", zName, pList->a[i].u4.idx);
32178 + }else{
32179 + assert( pList->eU4==EU4_EXPR );
32180 + if( pList->a[i].u4.pExpr==0 ){
32181 + fprintf(stdout, "%s (pExpr=NULL)\n", zName);
32182 + }else{
32183 + fprintf(stdout, "%s\n", zName);
32184 + sqlite3TreeViewPush(&pView, i<pList->nId-1);
32185 + sqlite3TreeViewExpr(pView, pList->a[i].u4.pExpr, 0);
32186 + sqlite3TreeViewPop(&pView);
32187 + }
32188 + }
32189 + sqlite3TreeViewPop(&pView);
32190 + }
32191 + }
32192 +}
32193 +SQLITE_PRIVATE void sqlite3TreeViewIdList(
32194 + TreeView *pView,
32195 + const IdList *pList,
32196 + u8 moreToFollow,
32197 + const char *zLabel
32198 +){
32199 + sqlite3TreeViewPush(&pView, moreToFollow);
32200 + sqlite3TreeViewBareIdList(pView, pList, zLabel);
32201 + sqlite3TreeViewPop(&pView);
32202 +}
32203 +
32204 +/*
32205 +** Generate a human-readable explanation of a list of Upsert objects
32206 +*/
32207 +SQLITE_PRIVATE void sqlite3TreeViewUpsert(
32208 + TreeView *pView,
32209 + const Upsert *pUpsert,
32210 + u8 moreToFollow
32211 +){
32212 + if( pUpsert==0 ) return;
32213 + sqlite3TreeViewPush(&pView, moreToFollow);
32214 + while( pUpsert ){
32215 + int n;
32216 + sqlite3TreeViewPush(&pView, pUpsert->pNextUpsert!=0 || moreToFollow);
32217 + sqlite3TreeViewLine(pView, "ON CONFLICT DO %s",
32218 + pUpsert->isDoUpdate ? "UPDATE" : "NOTHING");
32219 + n = (pUpsert->pUpsertSet!=0) + (pUpsert->pUpsertWhere!=0);
32220 + sqlite3TreeViewExprList(pView, pUpsert->pUpsertTarget, (n--)>0, "TARGET");
32221 + sqlite3TreeViewExprList(pView, pUpsert->pUpsertSet, (n--)>0, "SET");
32222 + if( pUpsert->pUpsertWhere ){
32223 + sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
32224 + sqlite3TreeViewExpr(pView, pUpsert->pUpsertWhere, 0);
32225 + sqlite3TreeViewPop(&pView);
32226 + }
32227 + sqlite3TreeViewPop(&pView);
32228 + pUpsert = pUpsert->pNextUpsert;
32229 + }
32230 + sqlite3TreeViewPop(&pView);
32231 +}
32232 +
32233 +#if TREETRACE_ENABLED
32234 +/*
32235 +** Generate a human-readable diagram of the data structure that go
32236 +** into generating an DELETE statement.
32237 +*/
32238 +SQLITE_PRIVATE void sqlite3TreeViewDelete(
32239 + const With *pWith,
32240 + const SrcList *pTabList,
32241 + const Expr *pWhere,
32242 + const ExprList *pOrderBy,
32243 + const Expr *pLimit,
32244 + const Trigger *pTrigger
32245 +){
32246 + int n = 0;
32247 + TreeView *pView = 0;
32248 + sqlite3TreeViewPush(&pView, 0);
32249 + sqlite3TreeViewLine(pView, "DELETE");
32250 + if( pWith ) n++;
32251 + if( pTabList ) n++;
32252 + if( pWhere ) n++;
32253 + if( pOrderBy ) n++;
32254 + if( pLimit ) n++;
32255 + if( pTrigger ) n++;
32256 + if( pWith ){
32257 + sqlite3TreeViewPush(&pView, (--n)>0);
32258 + sqlite3TreeViewWith(pView, pWith, 0);
32259 + sqlite3TreeViewPop(&pView);
32260 + }
32261 + if( pTabList ){
32262 + sqlite3TreeViewPush(&pView, (--n)>0);
32263 + sqlite3TreeViewLine(pView, "FROM");
32264 + sqlite3TreeViewSrcList(pView, pTabList);
32265 + sqlite3TreeViewPop(&pView);
32266 + }
32267 + if( pWhere ){
32268 + sqlite3TreeViewPush(&pView, (--n)>0);
32269 + sqlite3TreeViewLine(pView, "WHERE");
32270 + sqlite3TreeViewExpr(pView, pWhere, 0);
32271 + sqlite3TreeViewPop(&pView);
32272 + }
32273 + if( pOrderBy ){
32274 + sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY");
32275 + }
32276 + if( pLimit ){
32277 + sqlite3TreeViewPush(&pView, (--n)>0);
32278 + sqlite3TreeViewLine(pView, "LIMIT");
32279 + sqlite3TreeViewExpr(pView, pLimit, 0);
32280 + sqlite3TreeViewPop(&pView);
32281 + }
32282 + if( pTrigger ){
32283 + sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
32284 + }
32285 + sqlite3TreeViewPop(&pView);
32286 }
32287 +#endif /* TREETRACE_ENABLED */
32288 +
32289 +#if TREETRACE_ENABLED
32290 +/*
32291 +** Generate a human-readable diagram of the data structure that go
32292 +** into generating an INSERT statement.
32293 +*/
32294 +SQLITE_PRIVATE void sqlite3TreeViewInsert(
32295 + const With *pWith,
32296 + const SrcList *pTabList,
32297 + const IdList *pColumnList,
32298 + const Select *pSelect,
32299 + const ExprList *pExprList,
32300 + int onError,
32301 + const Upsert *pUpsert,
32302 + const Trigger *pTrigger
32303 +){
32304 + TreeView *pView = 0;
32305 + int n = 0;
32306 + const char *zLabel = "INSERT";
32307 + switch( onError ){
32308 + case OE_Replace: zLabel = "REPLACE"; break;
32309 + case OE_Ignore: zLabel = "INSERT OR IGNORE"; break;
32310 + case OE_Rollback: zLabel = "INSERT OR ROLLBACK"; break;
32311 + case OE_Abort: zLabel = "INSERT OR ABORT"; break;
32312 + case OE_Fail: zLabel = "INSERT OR FAIL"; break;
32313 + }
32314 + sqlite3TreeViewPush(&pView, 0);
32315 + sqlite3TreeViewLine(pView, zLabel);
32316 + if( pWith ) n++;
32317 + if( pTabList ) n++;
32318 + if( pColumnList ) n++;
32319 + if( pSelect ) n++;
32320 + if( pExprList ) n++;
32321 + if( pUpsert ) n++;
32322 + if( pTrigger ) n++;
32323 + if( pWith ){
32324 + sqlite3TreeViewPush(&pView, (--n)>0);
32325 + sqlite3TreeViewWith(pView, pWith, 0);
32326 + sqlite3TreeViewPop(&pView);
32327 + }
32328 + if( pTabList ){
32329 + sqlite3TreeViewPush(&pView, (--n)>0);
32330 + sqlite3TreeViewLine(pView, "INTO");
32331 + sqlite3TreeViewSrcList(pView, pTabList);
32332 + sqlite3TreeViewPop(&pView);
32333 + }
32334 + if( pColumnList ){
32335 + sqlite3TreeViewIdList(pView, pColumnList, (--n)>0, "COLUMNS");
32336 + }
32337 + if( pSelect ){
32338 + sqlite3TreeViewPush(&pView, (--n)>0);
32339 + sqlite3TreeViewLine(pView, "DATA-SOURCE");
32340 + sqlite3TreeViewSelect(pView, pSelect, 0);
32341 + sqlite3TreeViewPop(&pView);
32342 + }
32343 + if( pExprList ){
32344 + sqlite3TreeViewExprList(pView, pExprList, (--n)>0, "VALUES");
32345 + }
32346 + if( pUpsert ){
32347 + sqlite3TreeViewPush(&pView, (--n)>0);
32348 + sqlite3TreeViewLine(pView, "UPSERT");
32349 + sqlite3TreeViewUpsert(pView, pUpsert, 0);
32350 + sqlite3TreeViewPop(&pView);
32351 + }
32352 + if( pTrigger ){
32353 + sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
32354 + }
32355 + sqlite3TreeViewPop(&pView);
32356 +}
32357 +#endif /* TREETRACE_ENABLED */
32358 +
32359 +#if TREETRACE_ENABLED
32360 +/*
32361 +** Generate a human-readable diagram of the data structure that go
32362 +** into generating an UPDATE statement.
32363 +*/
32364 +SQLITE_PRIVATE void sqlite3TreeViewUpdate(
32365 + const With *pWith,
32366 + const SrcList *pTabList,
32367 + const ExprList *pChanges,
32368 + const Expr *pWhere,
32369 + int onError,
32370 + const ExprList *pOrderBy,
32371 + const Expr *pLimit,
32372 + const Upsert *pUpsert,
32373 + const Trigger *pTrigger
32374 +){
32375 + int n = 0;
32376 + TreeView *pView = 0;
32377 + const char *zLabel = "UPDATE";
32378 + switch( onError ){
32379 + case OE_Replace: zLabel = "UPDATE OR REPLACE"; break;
32380 + case OE_Ignore: zLabel = "UPDATE OR IGNORE"; break;
32381 + case OE_Rollback: zLabel = "UPDATE OR ROLLBACK"; break;
32382 + case OE_Abort: zLabel = "UPDATE OR ABORT"; break;
32383 + case OE_Fail: zLabel = "UPDATE OR FAIL"; break;
32384 + }
32385 + sqlite3TreeViewPush(&pView, 0);
32386 + sqlite3TreeViewLine(pView, zLabel);
32387 + if( pWith ) n++;
32388 + if( pTabList ) n++;
32389 + if( pChanges ) n++;
32390 + if( pWhere ) n++;
32391 + if( pOrderBy ) n++;
32392 + if( pLimit ) n++;
32393 + if( pUpsert ) n++;
32394 + if( pTrigger ) n++;
32395 + if( pWith ){
32396 + sqlite3TreeViewPush(&pView, (--n)>0);
32397 + sqlite3TreeViewWith(pView, pWith, 0);
32398 + sqlite3TreeViewPop(&pView);
32399 + }
32400 + if( pTabList ){
32401 + sqlite3TreeViewPush(&pView, (--n)>0);
32402 + sqlite3TreeViewLine(pView, "FROM");
32403 + sqlite3TreeViewSrcList(pView, pTabList);
32404 + sqlite3TreeViewPop(&pView);
32405 + }
32406 + if( pChanges ){
32407 + sqlite3TreeViewExprList(pView, pChanges, (--n)>0, "SET");
32408 + }
32409 + if( pWhere ){
32410 + sqlite3TreeViewPush(&pView, (--n)>0);
32411 + sqlite3TreeViewLine(pView, "WHERE");
32412 + sqlite3TreeViewExpr(pView, pWhere, 0);
32413 + sqlite3TreeViewPop(&pView);
32414 + }
32415 + if( pOrderBy ){
32416 + sqlite3TreeViewExprList(pView, pOrderBy, (--n)>0, "ORDER-BY");
32417 + }
32418 + if( pLimit ){
32419 + sqlite3TreeViewPush(&pView, (--n)>0);
32420 + sqlite3TreeViewLine(pView, "LIMIT");
32421 + sqlite3TreeViewExpr(pView, pLimit, 0);
32422 + sqlite3TreeViewPop(&pView);
32423 + }
32424 + if( pUpsert ){
32425 + sqlite3TreeViewPush(&pView, (--n)>0);
32426 + sqlite3TreeViewLine(pView, "UPSERT");
32427 + sqlite3TreeViewUpsert(pView, pUpsert, 0);
32428 + sqlite3TreeViewPop(&pView);
32429 + }
32430 + if( pTrigger ){
32431 + sqlite3TreeViewTrigger(pView, pTrigger, (--n)>0, 1);
32432 + }
32433 + sqlite3TreeViewPop(&pView);
32434 +}
32435 +#endif /* TREETRACE_ENABLED */
32436 +
32437 +#ifndef SQLITE_OMIT_TRIGGER
32438 +/*
32439 +** Show a human-readable graph of a TriggerStep
32440 +*/
32441 +SQLITE_PRIVATE void sqlite3TreeViewTriggerStep(
32442 + TreeView *pView,
32443 + const TriggerStep *pStep,
32444 + u8 moreToFollow,
32445 + u8 showFullList
32446 +){
32447 + int cnt = 0;
32448 + if( pStep==0 ) return;
32449 + sqlite3TreeViewPush(&pView,
32450 + moreToFollow || (showFullList && pStep->pNext!=0));
32451 + do{
32452 + if( cnt++ && pStep->pNext==0 ){
32453 + sqlite3TreeViewPop(&pView);
32454 + sqlite3TreeViewPush(&pView, 0);
32455 + }
32456 + sqlite3TreeViewLine(pView, "%s", pStep->zSpan ? pStep->zSpan : "RETURNING");
32457 + }while( showFullList && (pStep = pStep->pNext)!=0 );
32458 + sqlite3TreeViewPop(&pView);
32459 +}
32460 +
32461 +/*
32462 +** Show a human-readable graph of a Trigger
32463 +*/
32464 +SQLITE_PRIVATE void sqlite3TreeViewTrigger(
32465 + TreeView *pView,
32466 + const Trigger *pTrigger,
32467 + u8 moreToFollow,
32468 + u8 showFullList
32469 +){
32470 + int cnt = 0;
32471 + if( pTrigger==0 ) return;
32472 + sqlite3TreeViewPush(&pView,
32473 + moreToFollow || (showFullList && pTrigger->pNext!=0));
32474 + do{
32475 + if( cnt++ && pTrigger->pNext==0 ){
32476 + sqlite3TreeViewPop(&pView);
32477 + sqlite3TreeViewPush(&pView, 0);
32478 + }
32479 + sqlite3TreeViewLine(pView, "TRIGGER %s", pTrigger->zName);
32480 + sqlite3TreeViewPush(&pView, 0);
32481 + sqlite3TreeViewTriggerStep(pView, pTrigger->step_list, 0, 1);
32482 + sqlite3TreeViewPop(&pView);
32483 + }while( showFullList && (pTrigger = pTrigger->pNext)!=0 );
32484 + sqlite3TreeViewPop(&pView);
32485 +}
32486 +#endif /* SQLITE_OMIT_TRIGGER */
32487 +
32488 +
32489 +/*
32490 +** These simplified versions of the tree-view routines omit unnecessary
32491 +** parameters. These variants are intended to be used from a symbolic
32492 +** debugger, such as "gdb", during interactive debugging sessions.
32493 +**
32494 +** This routines are given external linkage so that they will always be
32495 +** accessible to the debugging, and to avoid warnings about unused
32496 +** functions. But these routines only exist in debugging builds, so they
32497 +** do not contaminate the interface.
32498 +*/
32499 +SQLITE_PRIVATE void sqlite3ShowExpr(const Expr *p){ sqlite3TreeViewExpr(0,p,0); }
32500 +SQLITE_PRIVATE void sqlite3ShowExprList(const ExprList *p){ sqlite3TreeViewExprList(0,p,0,0);}
32501 +SQLITE_PRIVATE void sqlite3ShowIdList(const IdList *p){ sqlite3TreeViewIdList(0,p,0,0); }
32502 +SQLITE_PRIVATE void sqlite3ShowSrcList(const SrcList *p){ sqlite3TreeViewSrcList(0,p); }
32503 +SQLITE_PRIVATE void sqlite3ShowSelect(const Select *p){ sqlite3TreeViewSelect(0,p,0); }
32504 +SQLITE_PRIVATE void sqlite3ShowWith(const With *p){ sqlite3TreeViewWith(0,p,0); }
32505 +SQLITE_PRIVATE void sqlite3ShowUpsert(const Upsert *p){ sqlite3TreeViewUpsert(0,p,0); }
32506 +#ifndef SQLITE_OMIT_TRIGGER
32507 +SQLITE_PRIVATE void sqlite3ShowTriggerStep(const TriggerStep *p){
32508 + sqlite3TreeViewTriggerStep(0,p,0,0);
32509 +}
32510 +SQLITE_PRIVATE void sqlite3ShowTriggerStepList(const TriggerStep *p){
32511 + sqlite3TreeViewTriggerStep(0,p,0,1);
32512 +}
32513 +SQLITE_PRIVATE void sqlite3ShowTrigger(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,0); }
32514 +SQLITE_PRIVATE void sqlite3ShowTriggerList(const Trigger *p){ sqlite3TreeViewTrigger(0,p,0,1);}
32515 +#endif
32516 +#ifndef SQLITE_OMIT_WINDOWFUNC
32517 +SQLITE_PRIVATE void sqlite3ShowWindow(const Window *p){ sqlite3TreeViewWindow(0,p,0); }
32518 +SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window *p){ sqlite3TreeViewWinFunc(0,p,0); }
32519 +#endif
32520
32521 #endif /* SQLITE_DEBUG */
32522
@@ -31660,16 +32546,41 @@ SQLITE_PRIVATE void sqlite3TreeViewExprList(
32546 ** This structure is the current state of the generator.
32547 */
32548 static SQLITE_WSD struct sqlite3PrngType {
31663 - unsigned char isInit; /* True if initialized */
31664 - unsigned char i, j; /* State variables */
31665 - unsigned char s[256]; /* State variables */
32549 + u32 s[16]; /* 64 bytes of chacha20 state */
32550 + u8 out[64]; /* Output bytes */
32551 + u8 n; /* Output bytes remaining */
32552 } sqlite3Prng;
32553
32554 +
32555 +/* The RFC-7539 ChaCha20 block function
32556 +*/
32557 +#define ROTL(a,b) (((a) << (b)) | ((a) >> (32 - (b))))
32558 +#define QR(a, b, c, d) ( \
32559 + a += b, d ^= a, d = ROTL(d,16), \
32560 + c += d, b ^= c, b = ROTL(b,12), \
32561 + a += b, d ^= a, d = ROTL(d, 8), \
32562 + c += d, b ^= c, b = ROTL(b, 7))
32563 +static void chacha_block(u32 *out, const u32 *in){
32564 + int i;
32565 + u32 x[16];
32566 + memcpy(x, in, 64);
32567 + for(i=0; i<10; i++){
32568 + QR(x[0], x[4], x[ 8], x[12]);
32569 + QR(x[1], x[5], x[ 9], x[13]);
32570 + QR(x[2], x[6], x[10], x[14]);
32571 + QR(x[3], x[7], x[11], x[15]);
32572 + QR(x[0], x[5], x[10], x[15]);
32573 + QR(x[1], x[6], x[11], x[12]);
32574 + QR(x[2], x[7], x[ 8], x[13]);
32575 + QR(x[3], x[4], x[ 9], x[14]);
32576 + }
32577 + for(i=0; i<16; i++) out[i] = x[i]+in[i];
32578 +}
32579 +
32580 /*
32581 ** Return N random bytes.
32582 */
32583 SQLITE_API void sqlite3_randomness(int N, void *pBuf){
31672 - unsigned char t;
32584 unsigned char *zBuf = pBuf;
32585
32586 /* The "wsdPrng" macro will resolve to the pseudo-random number generator
@@ -31699,53 +32610,46 @@ SQLITE_API void sqlite3_randomness(int N, void *pBuf){
32610
32611 sqlite3_mutex_enter(mutex);
32612 if( N<=0 || pBuf==0 ){
31702 - wsdPrng.isInit = 0;
32613 + wsdPrng.s[0] = 0;
32614 sqlite3_mutex_leave(mutex);
32615 return;
32616 }
32617
32618 /* Initialize the state of the random number generator once,
31708 - ** the first time this routine is called. The seed value does
31709 - ** not need to contain a lot of randomness since we are not
31710 - ** trying to do secure encryption or anything like that...
31711 - **
31712 - ** Nothing in this file or anywhere else in SQLite does any kind of
31713 - ** encryption. The RC4 algorithm is being used as a PRNG (pseudo-random
31714 - ** number generator) not as an encryption device.
32619 + ** the first time this routine is called.
32620 */
31716 - if( !wsdPrng.isInit ){
32621 + if( wsdPrng.s[0]==0 ){
32622 sqlite3_vfs *pVfs = sqlite3_vfs_find(0);
31718 - int i;
31719 - char k[256];
31720 - wsdPrng.j = 0;
31721 - wsdPrng.i = 0;
32623 + static const u32 chacha20_init[] = {
32624 + 0x61707865, 0x3320646e, 0x79622d32, 0x6b206574
32625 + };
32626 + memcpy(&wsdPrng.s[0], chacha20_init, 16);
32627 if( NEVER(pVfs==0) ){
31723 - memset(k, 0, sizeof(k));
32628 + memset(&wsdPrng.s[4], 0, 44);
32629 }else{
31725 - sqlite3OsRandomness(pVfs, 256, k);
31726 - }
31727 - for(i=0; i<256; i++){
31728 - wsdPrng.s[i] = (u8)i;
31729 - }
31730 - for(i=0; i<256; i++){
31731 - wsdPrng.j += wsdPrng.s[i] + k[i];
31732 - t = wsdPrng.s[wsdPrng.j];
31733 - wsdPrng.s[wsdPrng.j] = wsdPrng.s[i];
31734 - wsdPrng.s[i] = t;
32630 + sqlite3OsRandomness(pVfs, 44, (char*)&wsdPrng.s[4]);
32631 }
31736 - wsdPrng.isInit = 1;
32632 + wsdPrng.s[15] = wsdPrng.s[12];
32633 + wsdPrng.s[12] = 0;
32634 + wsdPrng.n = 0;
32635 }
32636
32637 assert( N>0 );
31740 - do{
31741 - wsdPrng.i++;
31742 - t = wsdPrng.s[wsdPrng.i];
31743 - wsdPrng.j += t;
31744 - wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j];
31745 - wsdPrng.s[wsdPrng.j] = t;
31746 - t += wsdPrng.s[wsdPrng.i];
31747 - *(zBuf++) = wsdPrng.s[t];
31748 - }while( --N );
32638 + while( 1 /* exit by break */ ){
32639 + if( N<=wsdPrng.n ){
32640 + memcpy(zBuf, &wsdPrng.out[wsdPrng.n-N], N);
32641 + wsdPrng.n -= N;
32642 + break;
32643 + }
32644 + if( wsdPrng.n>0 ){
32645 + memcpy(zBuf, wsdPrng.out, wsdPrng.n);
32646 + N -= wsdPrng.n;
32647 + zBuf += wsdPrng.n;
32648 + }
32649 + wsdPrng.s[12]++;
32650 + chacha_block((u32*)wsdPrng.out, wsdPrng.s);
32651 + wsdPrng.n = 64;
32652 + }
32653 sqlite3_mutex_leave(mutex);
32654 }
32655
@@ -32785,7 +33689,7 @@ SQLITE_PRIVATE void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){
33689 va_list ap;
33690 sqlite3 *db = pParse->db;
33691 assert( db!=0 );
32788 - assert( db->pParse==pParse );
33692 + assert( db->pParse==pParse || db->pParse->pToplevel==pParse );
33693 db->errByteOffset = -2;
33694 va_start(ap, zFormat);
33695 zMsg = sqlite3VMPrintf(db, zFormat, ap);
@@ -34598,53 +35502,53 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
35502 /* 0 */ "Savepoint" OpHelp(""),
35503 /* 1 */ "AutoCommit" OpHelp(""),
35504 /* 2 */ "Transaction" OpHelp(""),
34601 - /* 3 */ "SorterNext" OpHelp(""),
34602 - /* 4 */ "Prev" OpHelp(""),
34603 - /* 5 */ "Next" OpHelp(""),
34604 - /* 6 */ "Checkpoint" OpHelp(""),
34605 - /* 7 */ "JournalMode" OpHelp(""),
34606 - /* 8 */ "Vacuum" OpHelp(""),
34607 - /* 9 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"),
34608 - /* 10 */ "VUpdate" OpHelp("data=r[P3@P2]"),
34609 - /* 11 */ "Goto" OpHelp(""),
34610 - /* 12 */ "Gosub" OpHelp(""),
34611 - /* 13 */ "InitCoroutine" OpHelp(""),
34612 - /* 14 */ "Yield" OpHelp(""),
34613 - /* 15 */ "MustBeInt" OpHelp(""),
34614 - /* 16 */ "Jump" OpHelp(""),
34615 - /* 17 */ "Once" OpHelp(""),
34616 - /* 18 */ "If" OpHelp(""),
35505 + /* 3 */ "Checkpoint" OpHelp(""),
35506 + /* 4 */ "JournalMode" OpHelp(""),
35507 + /* 5 */ "Vacuum" OpHelp(""),
35508 + /* 6 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"),
35509 + /* 7 */ "VUpdate" OpHelp("data=r[P3@P2]"),
35510 + /* 8 */ "Init" OpHelp("Start at P2"),
35511 + /* 9 */ "Goto" OpHelp(""),
35512 + /* 10 */ "Gosub" OpHelp(""),
35513 + /* 11 */ "InitCoroutine" OpHelp(""),
35514 + /* 12 */ "Yield" OpHelp(""),
35515 + /* 13 */ "MustBeInt" OpHelp(""),
35516 + /* 14 */ "Jump" OpHelp(""),
35517 + /* 15 */ "Once" OpHelp(""),
35518 + /* 16 */ "If" OpHelp(""),
35519 + /* 17 */ "IfNot" OpHelp(""),
35520 + /* 18 */ "IsType" OpHelp("if typeof(P1.P3) in P5 goto P2"),
35521 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
34618 - /* 20 */ "IfNot" OpHelp(""),
34619 - /* 21 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"),
34620 - /* 22 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
34621 - /* 23 */ "SeekLT" OpHelp("key=r[P3@P4]"),
34622 - /* 24 */ "SeekLE" OpHelp("key=r[P3@P4]"),
34623 - /* 25 */ "SeekGE" OpHelp("key=r[P3@P4]"),
34624 - /* 26 */ "SeekGT" OpHelp("key=r[P3@P4]"),
34625 - /* 27 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"),
34626 - /* 28 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
34627 - /* 29 */ "NoConflict" OpHelp("key=r[P3@P4]"),
34628 - /* 30 */ "NotFound" OpHelp("key=r[P3@P4]"),
34629 - /* 31 */ "Found" OpHelp("key=r[P3@P4]"),
34630 - /* 32 */ "SeekRowid" OpHelp("intkey=r[P3]"),
34631 - /* 33 */ "NotExists" OpHelp("intkey=r[P3]"),
34632 - /* 34 */ "Last" OpHelp(""),
34633 - /* 35 */ "IfSmaller" OpHelp(""),
34634 - /* 36 */ "SorterSort" OpHelp(""),
34635 - /* 37 */ "Sort" OpHelp(""),
34636 - /* 38 */ "Rewind" OpHelp(""),
34637 - /* 39 */ "IdxLE" OpHelp("key=r[P3@P4]"),
34638 - /* 40 */ "IdxGT" OpHelp("key=r[P3@P4]"),
34639 - /* 41 */ "IdxLT" OpHelp("key=r[P3@P4]"),
34640 - /* 42 */ "IdxGE" OpHelp("key=r[P3@P4]"),
35522 + /* 20 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
35523 + /* 21 */ "SeekLT" OpHelp("key=r[P3@P4]"),
35524 + /* 22 */ "SeekLE" OpHelp("key=r[P3@P4]"),
35525 + /* 23 */ "SeekGE" OpHelp("key=r[P3@P4]"),
35526 + /* 24 */ "SeekGT" OpHelp("key=r[P3@P4]"),
35527 + /* 25 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"),
35528 + /* 26 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
35529 + /* 27 */ "NoConflict" OpHelp("key=r[P3@P4]"),
35530 + /* 28 */ "NotFound" OpHelp("key=r[P3@P4]"),
35531 + /* 29 */ "Found" OpHelp("key=r[P3@P4]"),
35532 + /* 30 */ "SeekRowid" OpHelp("intkey=r[P3]"),
35533 + /* 31 */ "NotExists" OpHelp("intkey=r[P3]"),
35534 + /* 32 */ "Last" OpHelp(""),
35535 + /* 33 */ "IfSmaller" OpHelp(""),
35536 + /* 34 */ "SorterSort" OpHelp(""),
35537 + /* 35 */ "Sort" OpHelp(""),
35538 + /* 36 */ "Rewind" OpHelp(""),
35539 + /* 37 */ "SorterNext" OpHelp(""),
35540 + /* 38 */ "Prev" OpHelp(""),
35541 + /* 39 */ "Next" OpHelp(""),
35542 + /* 40 */ "IdxLE" OpHelp("key=r[P3@P4]"),
35543 + /* 41 */ "IdxGT" OpHelp("key=r[P3@P4]"),
35544 + /* 42 */ "IdxLT" OpHelp("key=r[P3@P4]"),
35545 /* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
35546 /* 44 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
34643 - /* 45 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
34644 - /* 46 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
34645 - /* 47 */ "Program" OpHelp(""),
34646 - /* 48 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
34647 - /* 49 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
35547 + /* 45 */ "IdxGE" OpHelp("key=r[P3@P4]"),
35548 + /* 46 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
35549 + /* 47 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
35550 + /* 48 */ "Program" OpHelp(""),
35551 + /* 49 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
35552 /* 50 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
35553 /* 51 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
35554 /* 52 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
@@ -34654,12 +35558,12 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
35558 /* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
35559 /* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
35560 /* 58 */ "ElseEq" OpHelp(""),
34657 - /* 59 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
34658 - /* 60 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
34659 - /* 61 */ "IncrVacuum" OpHelp(""),
34660 - /* 62 */ "VNext" OpHelp(""),
34661 - /* 63 */ "Filter" OpHelp("if key(P3@P4) not in filter(P1) goto P2"),
34662 - /* 64 */ "Init" OpHelp("Start at P2"),
35561 + /* 59 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
35562 + /* 60 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
35563 + /* 61 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
35564 + /* 62 */ "IncrVacuum" OpHelp(""),
35565 + /* 63 */ "VNext" OpHelp(""),
35566 + /* 64 */ "Filter" OpHelp("if key(P3@P4) not in filter(P1) goto P2"),
35567 /* 65 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"),
35568 /* 66 */ "Function" OpHelp("r[P3]=func(r[P2@NP])"),
35569 /* 67 */ "Return" OpHelp(""),
@@ -34669,34 +35573,34 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
35573 /* 71 */ "Integer" OpHelp("r[P2]=P1"),
35574 /* 72 */ "Int64" OpHelp("r[P2]=P4"),
35575 /* 73 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
34672 - /* 74 */ "Null" OpHelp("r[P2..P3]=NULL"),
34673 - /* 75 */ "SoftNull" OpHelp("r[P1]=NULL"),
34674 - /* 76 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
34675 - /* 77 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
34676 - /* 78 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
34677 - /* 79 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
34678 - /* 80 */ "SCopy" OpHelp("r[P2]=r[P1]"),
34679 - /* 81 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
34680 - /* 82 */ "FkCheck" OpHelp(""),
34681 - /* 83 */ "ResultRow" OpHelp("output=r[P1@P2]"),
34682 - /* 84 */ "CollSeq" OpHelp(""),
34683 - /* 85 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
34684 - /* 86 */ "RealAffinity" OpHelp(""),
34685 - /* 87 */ "Cast" OpHelp("affinity(r[P1])"),
34686 - /* 88 */ "Permutation" OpHelp(""),
34687 - /* 89 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
34688 - /* 90 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
34689 - /* 91 */ "ZeroOrNull" OpHelp("r[P2] = 0 OR NULL"),
34690 - /* 92 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
34691 - /* 93 */ "Column" OpHelp("r[P3]=PX"),
34692 - /* 94 */ "TypeCheck" OpHelp("typecheck(r[P1@P2])"),
34693 - /* 95 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
34694 - /* 96 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
34695 - /* 97 */ "Count" OpHelp("r[P2]=count()"),
34696 - /* 98 */ "ReadCookie" OpHelp(""),
34697 - /* 99 */ "SetCookie" OpHelp(""),
34698 - /* 100 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
34699 - /* 101 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
35576 + /* 74 */ "BeginSubrtn" OpHelp("r[P2]=NULL"),
35577 + /* 75 */ "Null" OpHelp("r[P2..P3]=NULL"),
35578 + /* 76 */ "SoftNull" OpHelp("r[P1]=NULL"),
35579 + /* 77 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
35580 + /* 78 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
35581 + /* 79 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
35582 + /* 80 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
35583 + /* 81 */ "SCopy" OpHelp("r[P2]=r[P1]"),
35584 + /* 82 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
35585 + /* 83 */ "FkCheck" OpHelp(""),
35586 + /* 84 */ "ResultRow" OpHelp("output=r[P1@P2]"),
35587 + /* 85 */ "CollSeq" OpHelp(""),
35588 + /* 86 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
35589 + /* 87 */ "RealAffinity" OpHelp(""),
35590 + /* 88 */ "Cast" OpHelp("affinity(r[P1])"),
35591 + /* 89 */ "Permutation" OpHelp(""),
35592 + /* 90 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
35593 + /* 91 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
35594 + /* 92 */ "ZeroOrNull" OpHelp("r[P2] = 0 OR NULL"),
35595 + /* 93 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
35596 + /* 94 */ "Column" OpHelp("r[P3]=PX cursor P1 column P2"),
35597 + /* 95 */ "TypeCheck" OpHelp("typecheck(r[P1@P2])"),
35598 + /* 96 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
35599 + /* 97 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
35600 + /* 98 */ "Count" OpHelp("r[P2]=count()"),
35601 + /* 99 */ "ReadCookie" OpHelp(""),
35602 + /* 100 */ "SetCookie" OpHelp(""),
35603 + /* 101 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
35604 /* 102 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
35605 /* 103 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
35606 /* 104 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
@@ -34707,85 +35611,1062 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
35611 /* 109 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
35612 /* 110 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
35613 /* 111 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
34710 - /* 112 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
34711 - /* 113 */ "OpenDup" OpHelp(""),
35614 + /* 112 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
35615 + /* 113 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
35616 /* 114 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
34713 - /* 115 */ "OpenAutoindex" OpHelp("nColumn=P2"),
34714 - /* 116 */ "OpenEphemeral" OpHelp("nColumn=P2"),
35617 + /* 115 */ "OpenDup" OpHelp(""),
35618 + /* 116 */ "OpenAutoindex" OpHelp("nColumn=P2"),
35619 /* 117 */ "String8" OpHelp("r[P2]='P4'"),
34716 - /* 118 */ "SorterOpen" OpHelp(""),
34717 - /* 119 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
34718 - /* 120 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
34719 - /* 121 */ "Close" OpHelp(""),
34720 - /* 122 */ "ColumnsUsed" OpHelp(""),
34721 - /* 123 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"),
34722 - /* 124 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"),
34723 - /* 125 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
34724 - /* 126 */ "NewRowid" OpHelp("r[P2]=rowid"),
34725 - /* 127 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
34726 - /* 128 */ "RowCell" OpHelp(""),
34727 - /* 129 */ "Delete" OpHelp(""),
34728 - /* 130 */ "ResetCount" OpHelp(""),
34729 - /* 131 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
34730 - /* 132 */ "SorterData" OpHelp("r[P2]=data"),
34731 - /* 133 */ "RowData" OpHelp("r[P2]=data"),
34732 - /* 134 */ "Rowid" OpHelp("r[P2]=rowid"),
34733 - /* 135 */ "NullRow" OpHelp(""),
34734 - /* 136 */ "SeekEnd" OpHelp(""),
34735 - /* 137 */ "IdxInsert" OpHelp("key=r[P2]"),
34736 - /* 138 */ "SorterInsert" OpHelp("key=r[P2]"),
34737 - /* 139 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
34738 - /* 140 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
34739 - /* 141 */ "IdxRowid" OpHelp("r[P2]=rowid"),
34740 - /* 142 */ "FinishSeek" OpHelp(""),
34741 - /* 143 */ "Destroy" OpHelp(""),
34742 - /* 144 */ "Clear" OpHelp(""),
34743 - /* 145 */ "ResetSorter" OpHelp(""),
34744 - /* 146 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
34745 - /* 147 */ "SqlExec" OpHelp(""),
34746 - /* 148 */ "ParseSchema" OpHelp(""),
34747 - /* 149 */ "LoadAnalysis" OpHelp(""),
34748 - /* 150 */ "DropTable" OpHelp(""),
34749 - /* 151 */ "DropIndex" OpHelp(""),
34750 - /* 152 */ "DropTrigger" OpHelp(""),
35620 + /* 118 */ "OpenEphemeral" OpHelp("nColumn=P2"),
35621 + /* 119 */ "SorterOpen" OpHelp(""),
35622 + /* 120 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
35623 + /* 121 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
35624 + /* 122 */ "Close" OpHelp(""),
35625 + /* 123 */ "ColumnsUsed" OpHelp(""),
35626 + /* 124 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"),
35627 + /* 125 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"),
35628 + /* 126 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
35629 + /* 127 */ "NewRowid" OpHelp("r[P2]=rowid"),
35630 + /* 128 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
35631 + /* 129 */ "RowCell" OpHelp(""),
35632 + /* 130 */ "Delete" OpHelp(""),
35633 + /* 131 */ "ResetCount" OpHelp(""),
35634 + /* 132 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
35635 + /* 133 */ "SorterData" OpHelp("r[P2]=data"),
35636 + /* 134 */ "RowData" OpHelp("r[P2]=data"),
35637 + /* 135 */ "Rowid" OpHelp("r[P2]=PX rowid of P1"),
35638 + /* 136 */ "NullRow" OpHelp(""),
35639 + /* 137 */ "SeekEnd" OpHelp(""),
35640 + /* 138 */ "IdxInsert" OpHelp("key=r[P2]"),
35641 + /* 139 */ "SorterInsert" OpHelp("key=r[P2]"),
35642 + /* 140 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
35643 + /* 141 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
35644 + /* 142 */ "IdxRowid" OpHelp("r[P2]=rowid"),
35645 + /* 143 */ "FinishSeek" OpHelp(""),
35646 + /* 144 */ "Destroy" OpHelp(""),
35647 + /* 145 */ "Clear" OpHelp(""),
35648 + /* 146 */ "ResetSorter" OpHelp(""),
35649 + /* 147 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
35650 + /* 148 */ "SqlExec" OpHelp(""),
35651 + /* 149 */ "ParseSchema" OpHelp(""),
35652 + /* 150 */ "LoadAnalysis" OpHelp(""),
35653 + /* 151 */ "DropTable" OpHelp(""),
35654 + /* 152 */ "DropIndex" OpHelp(""),
35655 /* 153 */ "Real" OpHelp("r[P2]=P4"),
34752 - /* 154 */ "IntegrityCk" OpHelp(""),
34753 - /* 155 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
34754 - /* 156 */ "Param" OpHelp(""),
34755 - /* 157 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
34756 - /* 158 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
34757 - /* 159 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
34758 - /* 160 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"),
34759 - /* 161 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
34760 - /* 162 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"),
34761 - /* 163 */ "AggValue" OpHelp("r[P3]=value N=P2"),
34762 - /* 164 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
34763 - /* 165 */ "Expire" OpHelp(""),
34764 - /* 166 */ "CursorLock" OpHelp(""),
34765 - /* 167 */ "CursorUnlock" OpHelp(""),
34766 - /* 168 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
34767 - /* 169 */ "VBegin" OpHelp(""),
34768 - /* 170 */ "VCreate" OpHelp(""),
34769 - /* 171 */ "VDestroy" OpHelp(""),
34770 - /* 172 */ "VOpen" OpHelp(""),
34771 - /* 173 */ "VInitIn" OpHelp("r[P2]=ValueList(P1,P3)"),
34772 - /* 174 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
34773 - /* 175 */ "VRename" OpHelp(""),
34774 - /* 176 */ "Pagecount" OpHelp(""),
34775 - /* 177 */ "MaxPgcnt" OpHelp(""),
34776 - /* 178 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"),
34777 - /* 179 */ "Trace" OpHelp(""),
34778 - /* 180 */ "CursorHint" OpHelp(""),
34779 - /* 181 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
34780 - /* 182 */ "Noop" OpHelp(""),
34781 - /* 183 */ "Explain" OpHelp(""),
34782 - /* 184 */ "Abortable" OpHelp(""),
35656 + /* 154 */ "DropTrigger" OpHelp(""),
35657 + /* 155 */ "IntegrityCk" OpHelp(""),
35658 + /* 156 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
35659 + /* 157 */ "Param" OpHelp(""),
35660 + /* 158 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
35661 + /* 159 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
35662 + /* 160 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
35663 + /* 161 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"),
35664 + /* 162 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
35665 + /* 163 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"),
35666 + /* 164 */ "AggValue" OpHelp("r[P3]=value N=P2"),
35667 + /* 165 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
35668 + /* 166 */ "Expire" OpHelp(""),
35669 + /* 167 */ "CursorLock" OpHelp(""),
35670 + /* 168 */ "CursorUnlock" OpHelp(""),
35671 + /* 169 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
35672 + /* 170 */ "VBegin" OpHelp(""),
35673 + /* 171 */ "VCreate" OpHelp(""),
35674 + /* 172 */ "VDestroy" OpHelp(""),
35675 + /* 173 */ "VOpen" OpHelp(""),
35676 + /* 174 */ "VInitIn" OpHelp("r[P2]=ValueList(P1,P3)"),
35677 + /* 175 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
35678 + /* 176 */ "VRename" OpHelp(""),
35679 + /* 177 */ "Pagecount" OpHelp(""),
35680 + /* 178 */ "MaxPgcnt" OpHelp(""),
35681 + /* 179 */ "ClrSubtype" OpHelp("r[P1].subtype = 0"),
35682 + /* 180 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"),
35683 + /* 181 */ "Trace" OpHelp(""),
35684 + /* 182 */ "CursorHint" OpHelp(""),
35685 + /* 183 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
35686 + /* 184 */ "Noop" OpHelp(""),
35687 + /* 185 */ "Explain" OpHelp(""),
35688 + /* 186 */ "Abortable" OpHelp(""),
35689 };
35690 return azName[i];
35691 }
35692 #endif
35693
35694 /************** End of opcodes.c *********************************************/
35695 +/************** Begin file os_kv.c *******************************************/
35696 +/*
35697 +** 2022-09-06
35698 +**
35699 +** The author disclaims copyright to this source code. In place of
35700 +** a legal notice, here is a blessing:
35701 +**
35702 +** May you do good and not evil.
35703 +** May you find forgiveness for yourself and forgive others.
35704 +** May you share freely, never taking more than you give.
35705 +**
35706 +******************************************************************************
35707 +**
35708 +** This file contains an experimental VFS layer that operates on a
35709 +** Key/Value storage engine where both keys and values must be pure
35710 +** text.
35711 +*/
35712 +/* #include <sqliteInt.h> */
35713 +#if SQLITE_OS_KV || (SQLITE_OS_UNIX && defined(SQLITE_OS_KV_OPTIONAL))
35714 +
35715 +/*****************************************************************************
35716 +** Debugging logic
35717 +*/
35718 +
35719 +/* SQLITE_KV_TRACE() is used for tracing calls to kvstorage routines. */
35720 +#if 0
35721 +#define SQLITE_KV_TRACE(X) printf X
35722 +#else
35723 +#define SQLITE_KV_TRACE(X)
35724 +#endif
35725 +
35726 +/* SQLITE_KV_LOG() is used for tracing calls to the VFS interface */
35727 +#if 0
35728 +#define SQLITE_KV_LOG(X) printf X
35729 +#else
35730 +#define SQLITE_KV_LOG(X)
35731 +#endif
35732 +
35733 +
35734 +/*
35735 +** Forward declaration of objects used by this VFS implementation
35736 +*/
35737 +typedef struct KVVfsFile KVVfsFile;
35738 +
35739 +/* A single open file. There are only two files represented by this
35740 +** VFS - the database and the rollback journal.
35741 +*/
35742 +struct KVVfsFile {
35743 + sqlite3_file base; /* IO methods */
35744 + const char *zClass; /* Storage class */
35745 + int isJournal; /* True if this is a journal file */
35746 + unsigned int nJrnl; /* Space allocated for aJrnl[] */
35747 + char *aJrnl; /* Journal content */
35748 + int szPage; /* Last known page size */
35749 + sqlite3_int64 szDb; /* Database file size. -1 means unknown */
35750 +};
35751 +
35752 +/*
35753 +** Methods for KVVfsFile
35754 +*/
35755 +static int kvvfsClose(sqlite3_file*);
35756 +static int kvvfsReadDb(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
35757 +static int kvvfsReadJrnl(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
35758 +static int kvvfsWriteDb(sqlite3_file*,const void*,int iAmt, sqlite3_int64);
35759 +static int kvvfsWriteJrnl(sqlite3_file*,const void*,int iAmt, sqlite3_int64);
35760 +static int kvvfsTruncateDb(sqlite3_file*, sqlite3_int64 size);
35761 +static int kvvfsTruncateJrnl(sqlite3_file*, sqlite3_int64 size);
35762 +static int kvvfsSyncDb(sqlite3_file*, int flags);
35763 +static int kvvfsSyncJrnl(sqlite3_file*, int flags);
35764 +static int kvvfsFileSizeDb(sqlite3_file*, sqlite3_int64 *pSize);
35765 +static int kvvfsFileSizeJrnl(sqlite3_file*, sqlite3_int64 *pSize);
35766 +static int kvvfsLock(sqlite3_file*, int);
35767 +static int kvvfsUnlock(sqlite3_file*, int);
35768 +static int kvvfsCheckReservedLock(sqlite3_file*, int *pResOut);
35769 +static int kvvfsFileControlDb(sqlite3_file*, int op, void *pArg);
35770 +static int kvvfsFileControlJrnl(sqlite3_file*, int op, void *pArg);
35771 +static int kvvfsSectorSize(sqlite3_file*);
35772 +static int kvvfsDeviceCharacteristics(sqlite3_file*);
35773 +
35774 +/*
35775 +** Methods for sqlite3_vfs
35776 +*/
35777 +static int kvvfsOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *);
35778 +static int kvvfsDelete(sqlite3_vfs*, const char *zName, int syncDir);
35779 +static int kvvfsAccess(sqlite3_vfs*, const char *zName, int flags, int *);
35780 +static int kvvfsFullPathname(sqlite3_vfs*, const char *zName, int, char *zOut);
35781 +static void *kvvfsDlOpen(sqlite3_vfs*, const char *zFilename);
35782 +static int kvvfsRandomness(sqlite3_vfs*, int nByte, char *zOut);
35783 +static int kvvfsSleep(sqlite3_vfs*, int microseconds);
35784 +static int kvvfsCurrentTime(sqlite3_vfs*, double*);
35785 +static int kvvfsCurrentTimeInt64(sqlite3_vfs*, sqlite3_int64*);
35786 +
35787 +static sqlite3_vfs sqlite3OsKvvfsObject = {
35788 + 1, /* iVersion */
35789 + sizeof(KVVfsFile), /* szOsFile */
35790 + 1024, /* mxPathname */
35791 + 0, /* pNext */
35792 + "kvvfs", /* zName */
35793 + 0, /* pAppData */
35794 + kvvfsOpen, /* xOpen */
35795 + kvvfsDelete, /* xDelete */
35796 + kvvfsAccess, /* xAccess */
35797 + kvvfsFullPathname, /* xFullPathname */
35798 + kvvfsDlOpen, /* xDlOpen */
35799 + 0, /* xDlError */
35800 + 0, /* xDlSym */
35801 + 0, /* xDlClose */
35802 + kvvfsRandomness, /* xRandomness */
35803 + kvvfsSleep, /* xSleep */
35804 + kvvfsCurrentTime, /* xCurrentTime */
35805 + 0, /* xGetLastError */
35806 + kvvfsCurrentTimeInt64 /* xCurrentTimeInt64 */
35807 +};
35808 +
35809 +/* Methods for sqlite3_file objects referencing a database file
35810 +*/
35811 +static sqlite3_io_methods kvvfs_db_io_methods = {
35812 + 1, /* iVersion */
35813 + kvvfsClose, /* xClose */
35814 + kvvfsReadDb, /* xRead */
35815 + kvvfsWriteDb, /* xWrite */
35816 + kvvfsTruncateDb, /* xTruncate */
35817 + kvvfsSyncDb, /* xSync */
35818 + kvvfsFileSizeDb, /* xFileSize */
35819 + kvvfsLock, /* xLock */
35820 + kvvfsUnlock, /* xUnlock */
35821 + kvvfsCheckReservedLock, /* xCheckReservedLock */
35822 + kvvfsFileControlDb, /* xFileControl */
35823 + kvvfsSectorSize, /* xSectorSize */
35824 + kvvfsDeviceCharacteristics, /* xDeviceCharacteristics */
35825 + 0, /* xShmMap */
35826 + 0, /* xShmLock */
35827 + 0, /* xShmBarrier */
35828 + 0, /* xShmUnmap */
35829 + 0, /* xFetch */
35830 + 0 /* xUnfetch */
35831 +};
35832 +
35833 +/* Methods for sqlite3_file objects referencing a rollback journal
35834 +*/
35835 +static sqlite3_io_methods kvvfs_jrnl_io_methods = {
35836 + 1, /* iVersion */
35837 + kvvfsClose, /* xClose */
35838 + kvvfsReadJrnl, /* xRead */
35839 + kvvfsWriteJrnl, /* xWrite */
35840 + kvvfsTruncateJrnl, /* xTruncate */
35841 + kvvfsSyncJrnl, /* xSync */
35842 + kvvfsFileSizeJrnl, /* xFileSize */
35843 + kvvfsLock, /* xLock */
35844 + kvvfsUnlock, /* xUnlock */
35845 + kvvfsCheckReservedLock, /* xCheckReservedLock */
35846 + kvvfsFileControlJrnl, /* xFileControl */
35847 + kvvfsSectorSize, /* xSectorSize */
35848 + kvvfsDeviceCharacteristics, /* xDeviceCharacteristics */
35849 + 0, /* xShmMap */
35850 + 0, /* xShmLock */
35851 + 0, /* xShmBarrier */
35852 + 0, /* xShmUnmap */
35853 + 0, /* xFetch */
35854 + 0 /* xUnfetch */
35855 +};
35856 +
35857 +/****** Storage subsystem **************************************************/
35858 +#include <sys/types.h>
35859 +#include <sys/stat.h>
35860 +#include <unistd.h>
35861 +
35862 +/* Forward declarations for the low-level storage engine
35863 +*/
35864 +static int kvstorageWrite(const char*, const char *zKey, const char *zData);
35865 +static int kvstorageDelete(const char*, const char *zKey);
35866 +static int kvstorageRead(const char*, const char *zKey, char *zBuf, int nBuf);
35867 +#define KVSTORAGE_KEY_SZ 32
35868 +
35869 +/* Expand the key name with an appropriate prefix and put the result
35870 +** zKeyOut[]. The zKeyOut[] buffer is assumed to hold at least
35871 +** KVSTORAGE_KEY_SZ bytes.
35872 +*/
35873 +static void kvstorageMakeKey(
35874 + const char *zClass,
35875 + const char *zKeyIn,
35876 + char *zKeyOut
35877 +){
35878 + sqlite3_snprintf(KVSTORAGE_KEY_SZ, zKeyOut, "kvvfs-%s-%s", zClass, zKeyIn);
35879 +}
35880 +
35881 +/* Write content into a key. zClass is the particular namespace of the
35882 +** underlying key/value store to use - either "local" or "session".
35883 +**
35884 +** Both zKey and zData are zero-terminated pure text strings.
35885 +**
35886 +** Return the number of errors.
35887 +*/
35888 +static int kvstorageWrite(
35889 + const char *zClass,
35890 + const char *zKey,
35891 + const char *zData
35892 +){
35893 + FILE *fd;
35894 + char zXKey[KVSTORAGE_KEY_SZ];
35895 + kvstorageMakeKey(zClass, zKey, zXKey);
35896 + fd = fopen(zXKey, "wb");
35897 + if( fd ){
35898 + SQLITE_KV_TRACE(("KVVFS-WRITE %-15s (%d) %.50s%s\n", zXKey,
35899 + (int)strlen(zData), zData,
35900 + strlen(zData)>50 ? "..." : ""));
35901 + fputs(zData, fd);
35902 + fclose(fd);
35903 + return 0;
35904 + }else{
35905 + return 1;
35906 + }
35907 +}
35908 +
35909 +/* Delete a key (with its corresponding data) from the key/value
35910 +** namespace given by zClass. If the key does not previously exist,
35911 +** this routine is a no-op.
35912 +*/
35913 +static int kvstorageDelete(const char *zClass, const char *zKey){
35914 + char zXKey[KVSTORAGE_KEY_SZ];
35915 + kvstorageMakeKey(zClass, zKey, zXKey);
35916 + unlink(zXKey);
35917 + SQLITE_KV_TRACE(("KVVFS-DELETE %-15s\n", zXKey));
35918 + return 0;
35919 +}
35920 +
35921 +/* Read the value associated with a zKey from the key/value namespace given
35922 +** by zClass and put the text data associated with that key in the first
35923 +** nBuf bytes of zBuf[]. The value might be truncated if zBuf is not large
35924 +** enough to hold it all. The value put into zBuf must always be zero
35925 +** terminated, even if it gets truncated because nBuf is not large enough.
35926 +**
35927 +** Return the total number of bytes in the data, without truncation, and
35928 +** not counting the final zero terminator. Return -1 if the key does
35929 +** not exist.
35930 +**
35931 +** If nBuf<=0 then this routine simply returns the size of the data without
35932 +** actually reading it.
35933 +*/
35934 +static int kvstorageRead(
35935 + const char *zClass,
35936 + const char *zKey,
35937 + char *zBuf,
35938 + int nBuf
35939 +){
35940 + FILE *fd;
35941 + struct stat buf;
35942 + char zXKey[KVSTORAGE_KEY_SZ];
35943 + kvstorageMakeKey(zClass, zKey, zXKey);
35944 + if( access(zXKey, R_OK)!=0
35945 + || stat(zXKey, &buf)!=0
35946 + || !S_ISREG(buf.st_mode)
35947 + ){
35948 + SQLITE_KV_TRACE(("KVVFS-READ %-15s (-1)\n", zXKey));
35949 + return -1;
35950 + }
35951 + if( nBuf<=0 ){
35952 + return (int)buf.st_size;
35953 + }else if( nBuf==1 ){
35954 + zBuf[0] = 0;
35955 + SQLITE_KV_TRACE(("KVVFS-READ %-15s (%d)\n", zXKey,
35956 + (int)buf.st_size));
35957 + return (int)buf.st_size;
35958 + }
35959 + if( nBuf > buf.st_size + 1 ){
35960 + nBuf = buf.st_size + 1;
35961 + }
35962 + fd = fopen(zXKey, "rb");
35963 + if( fd==0 ){
35964 + SQLITE_KV_TRACE(("KVVFS-READ %-15s (-1)\n", zXKey));
35965 + return -1;
35966 + }else{
35967 + sqlite3_int64 n = fread(zBuf, 1, nBuf-1, fd);
35968 + fclose(fd);
35969 + zBuf[n] = 0;
35970 + SQLITE_KV_TRACE(("KVVFS-READ %-15s (%lld) %.50s%s\n", zXKey,
35971 + n, zBuf, n>50 ? "..." : ""));
35972 + return (int)n;
35973 + }
35974 +}
35975 +
35976 +/*
35977 +** An internal level of indirection which enables us to replace the
35978 +** kvvfs i/o methods with JavaScript implementations in WASM builds.
35979 +** Maintenance reminder: if this struct changes in any way, the JSON
35980 +** rendering of its structure must be updated in
35981 +** sqlite3_wasm_enum_json(). There are no binary compatibility
35982 +** concerns, so it does not need an iVersion member. This file is
35983 +** necessarily always compiled together with sqlite3_wasm_enum_json(),
35984 +** and JS code dynamically creates the mapping of members based on
35985 +** that JSON description.
35986 +*/
35987 +typedef struct sqlite3_kvvfs_methods sqlite3_kvvfs_methods;
35988 +struct sqlite3_kvvfs_methods {
35989 + int (*xRead)(const char *zClass, const char *zKey, char *zBuf, int nBuf);
35990 + int (*xWrite)(const char *zClass, const char *zKey, const char *zData);
35991 + int (*xDelete)(const char *zClass, const char *zKey);
35992 + const int nKeySize;
35993 +};
35994 +
35995 +/*
35996 +** This object holds the kvvfs I/O methods which may be swapped out
35997 +** for JavaScript-side implementations in WASM builds. In such builds
35998 +** it cannot be const, but in native builds it should be so that
35999 +** the compiler can hopefully optimize this level of indirection out.
36000 +** That said, kvvfs is intended primarily for use in WASM builds.
36001 +**
36002 +** Note that this is not explicitly flagged as static because the
36003 +** amalgamation build will tag it with SQLITE_PRIVATE.
36004 +*/
36005 +#ifndef SQLITE_WASM
36006 +const
36007 +#endif
36008 +SQLITE_PRIVATE sqlite3_kvvfs_methods sqlite3KvvfsMethods = {
36009 +kvstorageRead,
36010 +kvstorageWrite,
36011 +kvstorageDelete,
36012 +KVSTORAGE_KEY_SZ
36013 +};
36014 +
36015 +/****** Utility subroutines ************************************************/
36016 +
36017 +/*
36018 +** Encode binary into the text encoded used to persist on disk.
36019 +** The output text is stored in aOut[], which must be at least
36020 +** nData+1 bytes in length.
36021 +**
36022 +** Return the actual length of the encoded text, not counting the
36023 +** zero terminator at the end.
36024 +**
36025 +** Encoding format
36026 +** ---------------
36027 +**
36028 +** * Non-zero bytes are encoded as upper-case hexadecimal
36029 +**
36030 +** * A sequence of one or more zero-bytes that are not at the
36031 +** beginning of the buffer are encoded as a little-endian
36032 +** base-26 number using a..z. "a" means 0. "b" means 1,
36033 +** "z" means 25. "ab" means 26. "ac" means 52. And so forth.
36034 +**
36035 +** * Because there is no overlap between the encoding characters
36036 +** of hexadecimal and base-26 numbers, it is always clear where
36037 +** one stops and the next begins.
36038 +*/
36039 +static int kvvfsEncode(const char *aData, int nData, char *aOut){
36040 + int i, j;
36041 + const unsigned char *a = (const unsigned char*)aData;
36042 + for(i=j=0; i<nData; i++){
36043 + unsigned char c = a[i];
36044 + if( c!=0 ){
36045 + aOut[j++] = "0123456789ABCDEF"[c>>4];
36046 + aOut[j++] = "0123456789ABCDEF"[c&0xf];
36047 + }else{
36048 + /* A sequence of 1 or more zeros is stored as a little-endian
36049 + ** base-26 number using a..z as the digits. So one zero is "b".
36050 + ** Two zeros is "c". 25 zeros is "z", 26 zeros is "ab", 27 is "bb",
36051 + ** and so forth.
36052 + */
36053 + int k;
36054 + for(k=1; i+k<nData && a[i+k]==0; k++){}
36055 + i += k-1;
36056 + while( k>0 ){
36057 + aOut[j++] = 'a'+(k%26);
36058 + k /= 26;
36059 + }
36060 + }
36061 + }
36062 + aOut[j] = 0;
36063 + return j;
36064 +}
36065 +
36066 +static const signed char kvvfsHexValue[256] = {
36067 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36068 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36069 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36070 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
36071 + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36072 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36073 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36074 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36075 +
36076 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36077 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36078 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36079 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36080 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36081 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36082 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36083 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
36084 +};
36085 +
36086 +/*
36087 +** Decode the text encoding back to binary. The binary content is
36088 +** written into pOut, which must be at least nOut bytes in length.
36089 +**
36090 +** The return value is the number of bytes actually written into aOut[].
36091 +*/
36092 +static int kvvfsDecode(const char *a, char *aOut, int nOut){
36093 + int i, j;
36094 + int c;
36095 + const unsigned char *aIn = (const unsigned char*)a;
36096 + i = 0;
36097 + j = 0;
36098 + while( 1 ){
36099 + c = kvvfsHexValue[aIn[i]];
36100 + if( c<0 ){
36101 + int n = 0;
36102 + int mult = 1;
36103 + c = aIn[i];
36104 + if( c==0 ) break;
36105 + while( c>='a' && c<='z' ){
36106 + n += (c - 'a')*mult;
36107 + mult *= 26;
36108 + c = aIn[++i];
36109 + }
36110 + if( j+n>nOut ) return -1;
36111 + memset(&aOut[j], 0, n);
36112 + j += n;
36113 + c = aIn[i];
36114 + if( c==0 ) break;
36115 + }else{
36116 + aOut[j] = c<<4;
36117 + c = kvvfsHexValue[aIn[++i]];
36118 + if( c<0 ) break;
36119 + aOut[j++] += c;
36120 + i++;
36121 + }
36122 + }
36123 + return j;
36124 +}
36125 +
36126 +/*
36127 +** Decode a complete journal file. Allocate space in pFile->aJrnl
36128 +** and store the decoding there. Or leave pFile->aJrnl set to NULL
36129 +** if an error is encountered.
36130 +**
36131 +** The first few characters of the text encoding will be a little-endian
36132 +** base-26 number (digits a..z) that is the total number of bytes
36133 +** in the decoded journal file image. This base-26 number is followed
36134 +** by a single space, then the encoding of the journal. The space
36135 +** separator is required to act as a terminator for the base-26 number.
36136 +*/
36137 +static void kvvfsDecodeJournal(
36138 + KVVfsFile *pFile, /* Store decoding in pFile->aJrnl */
36139 + const char *zTxt, /* Text encoding. Zero-terminated */
36140 + int nTxt /* Bytes in zTxt, excluding zero terminator */
36141 +){
36142 + unsigned int n = 0;
36143 + int c, i, mult;
36144 + i = 0;
36145 + mult = 1;
36146 + while( (c = zTxt[i++])>='a' && c<='z' ){
36147 + n += (zTxt[i] - 'a')*mult;
36148 + mult *= 26;
36149 + }
36150 + sqlite3_free(pFile->aJrnl);
36151 + pFile->aJrnl = sqlite3_malloc64( n );
36152 + if( pFile->aJrnl==0 ){
36153 + pFile->nJrnl = 0;
36154 + return;
36155 + }
36156 + pFile->nJrnl = n;
36157 + n = kvvfsDecode(zTxt+i, pFile->aJrnl, pFile->nJrnl);
36158 + if( n<pFile->nJrnl ){
36159 + sqlite3_free(pFile->aJrnl);
36160 + pFile->aJrnl = 0;
36161 + pFile->nJrnl = 0;
36162 + }
36163 +}
36164 +
36165 +/*
36166 +** Read or write the "sz" element, containing the database file size.
36167 +*/
36168 +static sqlite3_int64 kvvfsReadFileSize(KVVfsFile *pFile){
36169 + char zData[50];
36170 + zData[0] = 0;
36171 + sqlite3KvvfsMethods.xRead(pFile->zClass, "sz", zData, sizeof(zData)-1);
36172 + return strtoll(zData, 0, 0);
36173 +}
36174 +static int kvvfsWriteFileSize(KVVfsFile *pFile, sqlite3_int64 sz){
36175 + char zData[50];
36176 + sqlite3_snprintf(sizeof(zData), zData, "%lld", sz);
36177 + return sqlite3KvvfsMethods.xWrite(pFile->zClass, "sz", zData);
36178 +}
36179 +
36180 +/****** sqlite3_io_methods methods ******************************************/
36181 +
36182 +/*
36183 +** Close an kvvfs-file.
36184 +*/
36185 +static int kvvfsClose(sqlite3_file *pProtoFile){
36186 + KVVfsFile *pFile = (KVVfsFile *)pProtoFile;
36187 +
36188 + SQLITE_KV_LOG(("xClose %s %s\n", pFile->zClass,
36189 + pFile->isJournal ? "journal" : "db"));
36190 + sqlite3_free(pFile->aJrnl);
36191 + return SQLITE_OK;
36192 +}
36193 +
36194 +/*
36195 +** Read from the -journal file.
36196 +*/
36197 +static int kvvfsReadJrnl(
36198 + sqlite3_file *pProtoFile,
36199 + void *zBuf,
36200 + int iAmt,
36201 + sqlite_int64 iOfst
36202 +){
36203 + KVVfsFile *pFile = (KVVfsFile*)pProtoFile;
36204 + assert( pFile->isJournal );
36205 + SQLITE_KV_LOG(("xRead('%s-journal',%d,%lld)\n", pFile->zClass, iAmt, iOfst));
36206 + if( pFile->aJrnl==0 ){
36207 + int szTxt = kvstorageRead(pFile->zClass, "jrnl", 0, 0);
36208 + char *aTxt;
36209 + if( szTxt<=4 ){
36210 + return SQLITE_IOERR;
36211 + }
36212 + aTxt = sqlite3_malloc64( szTxt+1 );
36213 + if( aTxt==0 ) return SQLITE_NOMEM;
36214 + kvstorageRead(pFile->zClass, "jrnl", aTxt, szTxt+1);
36215 + kvvfsDecodeJournal(pFile, aTxt, szTxt);
36216 + sqlite3_free(aTxt);
36217 + if( pFile->aJrnl==0 ) return SQLITE_IOERR;
36218 + }
36219 + if( iOfst+iAmt>pFile->nJrnl ){
36220 + return SQLITE_IOERR_SHORT_READ;
36221 + }
36222 + memcpy(zBuf, pFile->aJrnl+iOfst, iAmt);
36223 + return SQLITE_OK;
36224 +}
36225 +
36226 +/*
36227 +** Read from the database file.
36228 +*/
36229 +static int kvvfsReadDb(
36230 + sqlite3_file *pProtoFile,
36231 + void *zBuf,
36232 + int iAmt,
36233 + sqlite_int64 iOfst
36234 +){
36235 + KVVfsFile *pFile = (KVVfsFile*)pProtoFile;
36236 + unsigned int pgno;
36237 + int got, n;
36238 + char zKey[30];
36239 + char aData[133073];
36240 + assert( iOfst>=0 );
36241 + assert( iAmt>=0 );
36242 + SQLITE_KV_LOG(("xRead('%s-db',%d,%lld)\n", pFile->zClass, iAmt, iOfst));
36243 + if( iOfst+iAmt>=512 ){
36244 + if( (iOfst % iAmt)!=0 ){
36245 + return SQLITE_IOERR_READ;
36246 + }
36247 + if( (iAmt & (iAmt-1))!=0 || iAmt<512 || iAmt>65536 ){
36248 + return SQLITE_IOERR_READ;
36249 + }
36250 + pFile->szPage = iAmt;
36251 + pgno = 1 + iOfst/iAmt;
36252 + }else{
36253 + pgno = 1;
36254 + }
36255 + sqlite3_snprintf(sizeof(zKey), zKey, "%u", pgno);
36256 + got = sqlite3KvvfsMethods.xRead(pFile->zClass, zKey, aData, sizeof(aData)-1);
36257 + if( got<0 ){
36258 + n = 0;
36259 + }else{
36260 + aData[got] = 0;
36261 + if( iOfst+iAmt<512 ){
36262 + int k = iOfst+iAmt;
36263 + aData[k*2] = 0;
36264 + n = kvvfsDecode(aData, &aData[2000], sizeof(aData)-2000);
36265 + if( n>=iOfst+iAmt ){
36266 + memcpy(zBuf, &aData[2000+iOfst], iAmt);
36267 + n = iAmt;
36268 + }else{
36269 + n = 0;
36270 + }
36271 + }else{
36272 + n = kvvfsDecode(aData, zBuf, iAmt);
36273 + }
36274 + }
36275 + if( n<iAmt ){
36276 + memset(zBuf+n, 0, iAmt-n);
36277 + return SQLITE_IOERR_SHORT_READ;
36278 + }
36279 + return SQLITE_OK;
36280 +}
36281 +
36282 +
36283 +/*
36284 +** Write into the -journal file.
36285 +*/
36286 +static int kvvfsWriteJrnl(
36287 + sqlite3_file *pProtoFile,
36288 + const void *zBuf,
36289 + int iAmt,
36290 + sqlite_int64 iOfst
36291 +){
36292 + KVVfsFile *pFile = (KVVfsFile*)pProtoFile;
36293 + sqlite3_int64 iEnd = iOfst+iAmt;
36294 + SQLITE_KV_LOG(("xWrite('%s-journal',%d,%lld)\n", pFile->zClass, iAmt, iOfst));
36295 + if( iEnd>=0x10000000 ) return SQLITE_FULL;
36296 + if( pFile->aJrnl==0 || pFile->nJrnl<iEnd ){
36297 + char *aNew = sqlite3_realloc(pFile->aJrnl, iEnd);
36298 + if( aNew==0 ){
36299 + return SQLITE_IOERR_NOMEM;
36300 + }
36301 + pFile->aJrnl = aNew;
36302 + if( pFile->nJrnl<iOfst ){
36303 + memset(pFile->aJrnl+pFile->nJrnl, 0, iOfst-pFile->nJrnl);
36304 + }
36305 + pFile->nJrnl = iEnd;
36306 + }
36307 + memcpy(pFile->aJrnl+iOfst, zBuf, iAmt);
36308 + return SQLITE_OK;
36309 +}
36310 +
36311 +/*
36312 +** Write into the database file.
36313 +*/
36314 +static int kvvfsWriteDb(
36315 + sqlite3_file *pProtoFile,
36316 + const void *zBuf,
36317 + int iAmt,
36318 + sqlite_int64 iOfst
36319 +){
36320 + KVVfsFile *pFile = (KVVfsFile*)pProtoFile;
36321 + unsigned int pgno;
36322 + char zKey[30];
36323 + char aData[131073];
36324 + SQLITE_KV_LOG(("xWrite('%s-db',%d,%lld)\n", pFile->zClass, iAmt, iOfst));
36325 + assert( iAmt>=512 && iAmt<=65536 );
36326 + assert( (iAmt & (iAmt-1))==0 );
36327 + assert( pFile->szPage<0 || pFile->szPage==iAmt );
36328 + pFile->szPage = iAmt;
36329 + pgno = 1 + iOfst/iAmt;
36330 + sqlite3_snprintf(sizeof(zKey), zKey, "%u", pgno);
36331 + kvvfsEncode(zBuf, iAmt, aData);
36332 + if( sqlite3KvvfsMethods.xWrite(pFile->zClass, zKey, aData) ){
36333 + return SQLITE_IOERR;
36334 + }
36335 + if( iOfst+iAmt > pFile->szDb ){
36336 + pFile->szDb = iOfst + iAmt;
36337 + }
36338 + return SQLITE_OK;
36339 +}
36340 +
36341 +/*
36342 +** Truncate an kvvfs-file.
36343 +*/
36344 +static int kvvfsTruncateJrnl(sqlite3_file *pProtoFile, sqlite_int64 size){
36345 + KVVfsFile *pFile = (KVVfsFile *)pProtoFile;
36346 + SQLITE_KV_LOG(("xTruncate('%s-journal',%lld)\n", pFile->zClass, size));
36347 + assert( size==0 );
36348 + sqlite3KvvfsMethods.xDelete(pFile->zClass, "jrnl");
36349 + sqlite3_free(pFile->aJrnl);
36350 + pFile->aJrnl = 0;
36351 + pFile->nJrnl = 0;
36352 + return SQLITE_OK;
36353 +}
36354 +static int kvvfsTruncateDb(sqlite3_file *pProtoFile, sqlite_int64 size){
36355 + KVVfsFile *pFile = (KVVfsFile *)pProtoFile;
36356 + if( pFile->szDb>size
36357 + && pFile->szPage>0
36358 + && (size % pFile->szPage)==0
36359 + ){
36360 + char zKey[50];
36361 + unsigned int pgno, pgnoMax;
36362 + SQLITE_KV_LOG(("xTruncate('%s-db',%lld)\n", pFile->zClass, size));
36363 + pgno = 1 + size/pFile->szPage;
36364 + pgnoMax = 2 + pFile->szDb/pFile->szPage;
36365 + while( pgno<=pgnoMax ){
36366 + sqlite3_snprintf(sizeof(zKey), zKey, "%u", pgno);
36367 + sqlite3KvvfsMethods.xDelete(pFile->zClass, zKey);
36368 + pgno++;
36369 + }
36370 + pFile->szDb = size;
36371 + return kvvfsWriteFileSize(pFile, size) ? SQLITE_IOERR : SQLITE_OK;
36372 + }
36373 + return SQLITE_IOERR;
36374 +}
36375 +
36376 +/*
36377 +** Sync an kvvfs-file.
36378 +*/
36379 +static int kvvfsSyncJrnl(sqlite3_file *pProtoFile, int flags){
36380 + int i, n;
36381 + KVVfsFile *pFile = (KVVfsFile *)pProtoFile;
36382 + char *zOut;
36383 + SQLITE_KV_LOG(("xSync('%s-journal')\n", pFile->zClass));
36384 + if( pFile->nJrnl<=0 ){
36385 + return kvvfsTruncateJrnl(pProtoFile, 0);
36386 + }
36387 + zOut = sqlite3_malloc64( pFile->nJrnl*2 + 50 );
36388 + if( zOut==0 ){
36389 + return SQLITE_IOERR_NOMEM;
36390 + }
36391 + n = pFile->nJrnl;
36392 + i = 0;
36393 + do{
36394 + zOut[i++] = 'a' + (n%26);
36395 + n /= 26;
36396 + }while( n>0 );
36397 + zOut[i++] = ' ';
36398 + kvvfsEncode(pFile->aJrnl, pFile->nJrnl, &zOut[i]);
36399 + i = sqlite3KvvfsMethods.xWrite(pFile->zClass, "jrnl", zOut);
36400 + sqlite3_free(zOut);
36401 + return i ? SQLITE_IOERR : SQLITE_OK;
36402 +}
36403 +static int kvvfsSyncDb(sqlite3_file *pProtoFile, int flags){

This file is too large to show in full.

database/sqlite/sqlite3.h
+124 -36
@@ -146,9 +146,9 @@ extern "C" {
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 -#define SQLITE_VERSION "3.38.5"
150 -#define SQLITE_VERSION_NUMBER 3038005
151 -#define SQLITE_SOURCE_ID "2022-05-06 15:25:27 78d9c993d404cdfaa7fdd2973fa1052e3da9f66215cff9c5540ebe55c407d9fe"
149 +#define SQLITE_VERSION "3.40.1"
150 +#define SQLITE_VERSION_NUMBER 3040001
151 +#define SQLITE_SOURCE_ID "2022-12-28 14:03:47 df5c253c0b3dd24916e4ec7cf77d3db5294cc9fd45ae7b9c5e82ad8197f38a24"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
@@ -670,13 +670,17 @@ SQLITE_API int sqlite3_exec(
670 **
671 ** SQLite uses one of these integer values as the second
672 ** argument to calls it makes to the xLock() and xUnlock() methods
673 -** of an [sqlite3_io_methods] object.
673 +** of an [sqlite3_io_methods] object. These values are ordered from
674 +** lest restrictive to most restrictive.
675 +**
676 +** The argument to xLock() is always SHARED or higher. The argument to
677 +** xUnlock is either SHARED or NONE.
678 */
675 -#define SQLITE_LOCK_NONE 0
676 -#define SQLITE_LOCK_SHARED 1
677 -#define SQLITE_LOCK_RESERVED 2
678 -#define SQLITE_LOCK_PENDING 3
679 -#define SQLITE_LOCK_EXCLUSIVE 4
679 +#define SQLITE_LOCK_NONE 0 /* xUnlock() only */
680 +#define SQLITE_LOCK_SHARED 1 /* xLock() or xUnlock() */
681 +#define SQLITE_LOCK_RESERVED 2 /* xLock() only */
682 +#define SQLITE_LOCK_PENDING 3 /* xLock() only */
683 +#define SQLITE_LOCK_EXCLUSIVE 4 /* xLock() only */
684
685 /*
686 ** CAPI3REF: Synchronization Type Flags
@@ -754,7 +758,14 @@ struct sqlite3_file {
758 ** <li> [SQLITE_LOCK_PENDING], or
759 ** <li> [SQLITE_LOCK_EXCLUSIVE].
760 ** </ul>
757 -** xLock() increases the lock. xUnlock() decreases the lock.
761 +** xLock() upgrades the database file lock. In other words, xLock() moves the
762 +** database file lock in the direction NONE toward EXCLUSIVE. The argument to
763 +** xLock() is always on of SHARED, RESERVED, PENDING, or EXCLUSIVE, never
764 +** SQLITE_LOCK_NONE. If the database file lock is already at or above the
765 +** requested lock, then the call to xLock() is a no-op.
766 +** xUnlock() downgrades the database file lock to either SHARED or NONE.
767 +* If the lock is already at or below the requested lock state, then the call
768 +** to xUnlock() is a no-op.
769 ** The xCheckReservedLock() method checks whether any database connection,
770 ** either in this process or in some other process, is holding a RESERVED,
771 ** PENDING, or EXCLUSIVE lock on the file. It returns true
@@ -859,9 +870,8 @@ struct sqlite3_io_methods {
870 ** opcode causes the xFileControl method to write the current state of
871 ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
872 ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
862 -** into an integer that the pArg argument points to. This capability
863 -** is used during testing and is only available when the SQLITE_TEST
864 -** compile-time option is used.
873 +** into an integer that the pArg argument points to.
874 +** This capability is only available if SQLite is compiled with [SQLITE_DEBUG].
875 **
876 ** <li>[[SQLITE_FCNTL_SIZE_HINT]]
877 ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
@@ -1182,6 +1192,12 @@ struct sqlite3_io_methods {
1192 **
1193 ** <li>[[SQLITE_FCNTL_CKSM_FILE]]
1194 ** Used by the cksmvfs VFS module only.
1195 +**
1196 +** <li>[[SQLITE_FCNTL_RESET_CACHE]]
1197 +** If there is currently no transaction open on the database, and the
1198 +** database is not a temp db, then this file-control purges the contents
1199 +** of the in-memory page cache. If there is an open transaction, or if
1200 +** the db is a temp-db, it is a no-op, not an error.
1201 ** </ul>
1202 */
1203 #define SQLITE_FCNTL_LOCKSTATE 1
@@ -1224,6 +1240,7 @@ struct sqlite3_io_methods {
1240 #define SQLITE_FCNTL_CKPT_START 39
1241 #define SQLITE_FCNTL_EXTERNAL_READER 40
1242 #define SQLITE_FCNTL_CKSM_FILE 41
1243 +#define SQLITE_FCNTL_RESET_CACHE 42
1244
1245 /* deprecated names */
1246 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
@@ -1253,6 +1270,26 @@ typedef struct sqlite3_mutex sqlite3_mutex;
1270 */
1271 typedef struct sqlite3_api_routines sqlite3_api_routines;
1272
1273 +/*
1274 +** CAPI3REF: File Name
1275 +**
1276 +** Type [sqlite3_filename] is used by SQLite to pass filenames to the
1277 +** xOpen method of a [VFS]. It may be cast to (const char*) and treated
1278 +** as a normal, nul-terminated, UTF-8 buffer containing the filename, but
1279 +** may also be passed to special APIs such as:
1280 +**
1281 +** <ul>
1282 +** <li> sqlite3_filename_database()
1283 +** <li> sqlite3_filename_journal()
1284 +** <li> sqlite3_filename_wal()
1285 +** <li> sqlite3_uri_parameter()
1286 +** <li> sqlite3_uri_boolean()
1287 +** <li> sqlite3_uri_int64()
1288 +** <li> sqlite3_uri_key()
1289 +** </ul>
1290 +*/
1291 +typedef const char *sqlite3_filename;
1292 +
1293 /*
1294 ** CAPI3REF: OS Interface Object
1295 **
@@ -1431,7 +1468,7 @@ struct sqlite3_vfs {
1468 sqlite3_vfs *pNext; /* Next registered VFS */
1469 const char *zName; /* Name of this virtual file system */
1470 void *pAppData; /* Pointer to application-specific data */
1434 - int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
1471 + int (*xOpen)(sqlite3_vfs*, sqlite3_filename zName, sqlite3_file*,
1472 int flags, int *pOutFlags);
1473 int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
1474 int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
@@ -2309,6 +2346,7 @@ struct sqlite3_mem_methods {
2346 ** <ul>
2347 ** <li> The [PRAGMA writable_schema=ON] statement.
2348 ** <li> The [PRAGMA journal_mode=OFF] statement.
2349 +** <li> The [PRAGMA schema_version=N] statement.
2350 ** <li> Writes to the [sqlite_dbpage] virtual table.
2351 ** <li> Direct writes to [shadow tables].
2352 ** </ul>
@@ -3424,6 +3462,9 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
3462 ** <dd>The database is opened [shared cache] enabled, overriding
3463 ** the default shared cache setting provided by
3464 ** [sqlite3_enable_shared_cache()].)^
3465 +** The [use of shared cache mode is discouraged] and hence shared cache
3466 +** capabilities may be omitted from many builds of SQLite. In such cases,
3467 +** this option is a no-op.
3468 **
3469 ** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
3470 ** <dd>The database is opened [shared cache] disabled, overriding
@@ -3439,7 +3480,7 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
3480 ** to return an extended result code.</dd>
3481 **
3482 ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
3442 -** <dd>The database filename is not allowed to be a symbolic link</dd>
3483 +** <dd>The database filename is not allowed to contain a symbolic link</dd>
3484 ** </dl>)^
3485 **
3486 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
@@ -3698,10 +3739,10 @@ SQLITE_API int sqlite3_open_v2(
3739 **
3740 ** See the [URI filename] documentation for additional information.
3741 */
3701 -SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
3702 -SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
3703 -SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
3704 -SQLITE_API const char *sqlite3_uri_key(const char *zFilename, int N);
3742 +SQLITE_API const char *sqlite3_uri_parameter(sqlite3_filename z, const char *zParam);
3743 +SQLITE_API int sqlite3_uri_boolean(sqlite3_filename z, const char *zParam, int bDefault);
3744 +SQLITE_API sqlite3_int64 sqlite3_uri_int64(sqlite3_filename, const char*, sqlite3_int64);
3745 +SQLITE_API const char *sqlite3_uri_key(sqlite3_filename z, int N);
3746
3747 /*
3748 ** CAPI3REF: Translate filenames
@@ -3730,9 +3771,9 @@ SQLITE_API const char *sqlite3_uri_key(const char *zFilename, int N);
3771 ** return value from [sqlite3_db_filename()], then the result is
3772 ** undefined and is likely a memory access violation.
3773 */
3733 -SQLITE_API const char *sqlite3_filename_database(const char*);
3734 -SQLITE_API const char *sqlite3_filename_journal(const char*);
3735 -SQLITE_API const char *sqlite3_filename_wal(const char*);
3774 +SQLITE_API const char *sqlite3_filename_database(sqlite3_filename);
3775 +SQLITE_API const char *sqlite3_filename_journal(sqlite3_filename);
3776 +SQLITE_API const char *sqlite3_filename_wal(sqlite3_filename);
3777
3778 /*
3779 ** CAPI3REF: Database File Corresponding To A Journal
@@ -3798,14 +3839,14 @@ SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*);
3839 ** then the corresponding [sqlite3_module.xClose() method should also be
3840 ** invoked prior to calling sqlite3_free_filename(Y).
3841 */
3801 -SQLITE_API char *sqlite3_create_filename(
3842 +SQLITE_API sqlite3_filename sqlite3_create_filename(
3843 const char *zDatabase,
3844 const char *zJournal,
3845 const char *zWal,
3846 int nParam,
3847 const char **azParam
3848 );
3808 -SQLITE_API void sqlite3_free_filename(char*);
3849 +SQLITE_API void sqlite3_free_filename(sqlite3_filename);
3850
3851 /*
3852 ** CAPI3REF: Error Codes And Messages
@@ -5508,6 +5549,16 @@ SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int6
5549 ** then the conversion is performed. Otherwise no conversion occurs.
5550 ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
5551 **
5552 +** ^(The sqlite3_value_encoding(X) interface returns one of [SQLITE_UTF8],
5553 +** [SQLITE_UTF16BE], or [SQLITE_UTF16LE] according to the current encoding
5554 +** of the value X, assuming that X has type TEXT.)^ If sqlite3_value_type(X)
5555 +** returns something other than SQLITE_TEXT, then the return value from
5556 +** sqlite3_value_encoding(X) is meaningless. ^Calls to
5557 +** sqlite3_value_text(X), sqlite3_value_text16(X), sqlite3_value_text16be(X),
5558 +** sqlite3_value_text16le(X), sqlite3_value_bytes(X), or
5559 +** sqlite3_value_bytes16(X) might change the encoding of the value X and
5560 +** thus change the return from subsequent calls to sqlite3_value_encoding(X).
5561 +**
5562 ** ^Within the [xUpdate] method of a [virtual table], the
5563 ** sqlite3_value_nochange(X) interface returns true if and only if
5564 ** the column corresponding to X is unchanged by the UPDATE operation
@@ -5572,6 +5623,7 @@ SQLITE_API int sqlite3_value_type(sqlite3_value*);
5623 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
5624 SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
5625 SQLITE_API int sqlite3_value_frombind(sqlite3_value*);
5626 +SQLITE_API int sqlite3_value_encoding(sqlite3_value*);
5627
5628 /*
5629 ** CAPI3REF: Finding The Subtype Of SQL Values
@@ -5593,7 +5645,8 @@ SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*);
5645 ** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
5646 ** is a [protected sqlite3_value] object even if the input is not.
5647 ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
5596 -** memory allocation fails.
5648 +** memory allocation fails. ^If V is a [pointer value], then the result
5649 +** of sqlite3_value_dup(V) is a NULL value.
5650 **
5651 ** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
5652 ** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer
@@ -5624,7 +5677,7 @@ SQLITE_API void sqlite3_value_free(sqlite3_value*);
5677 **
5678 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
5679 ** when first called if N is less than or equal to zero or if a memory
5627 -** allocate error occurs.
5680 +** allocation error occurs.
5681 **
5682 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
5683 ** determined by the N parameter on first successful call. Changing the
@@ -5829,9 +5882,10 @@ typedef void (*sqlite3_destructor_type)(void*);
5882 ** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE].
5883 ** ^SQLite takes the text result from the application from
5884 ** the 2nd parameter of the sqlite3_result_text* interfaces.
5832 -** ^If the 3rd parameter to the sqlite3_result_text* interfaces
5833 -** is negative, then SQLite takes result text from the 2nd parameter
5834 -** through the first zero character.
5885 +** ^If the 3rd parameter to any of the sqlite3_result_text* interfaces
5886 +** other than sqlite3_result_text64() is negative, then SQLite computes
5887 +** the string length itself by searching the 2nd parameter for the first
5888 +** zero character.
5889 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
5890 ** is non-negative, then as many bytes (not characters) of the text
5891 ** pointed to by the 2nd parameter are taken as the application-defined
@@ -6275,6 +6329,28 @@ SQLITE_API int sqlite3_get_autocommit(sqlite3*);
6329 */
6330 SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
6331
6332 +/*
6333 +** CAPI3REF: Return The Schema Name For A Database Connection
6334 +** METHOD: sqlite3
6335 +**
6336 +** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
6337 +** for the N-th database on database connection D, or a NULL pointer of N is
6338 +** out of range. An N value of 0 means the main database file. An N of 1 is
6339 +** the "temp" schema. Larger values of N correspond to various ATTACH-ed
6340 +** databases.
6341 +**
6342 +** Space to hold the string that is returned by sqlite3_db_name() is managed
6343 +** by SQLite itself. The string might be deallocated by any operation that
6344 +** changes the schema, including [ATTACH] or [DETACH] or calls to
6345 +** [sqlite3_serialize()] or [sqlite3_deserialize()], even operations that
6346 +** occur on a different thread. Applications that need to
6347 +** remember the string long-term should make their own copy. Applications that
6348 +** are accessing the same database connection simultaneously on multiple
6349 +** threads should mutex-protect calls to this API and should make their own
6350 +** private copy of the result prior to releasing the mutex.
6351 +*/
6352 +SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N);
6353 +
6354 /*
6355 ** CAPI3REF: Return The Filename For A Database Connection
6356 ** METHOD: sqlite3
@@ -6305,7 +6381,7 @@ SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
6381 ** <li> [sqlite3_filename_wal()]
6382 ** </ul>
6383 */
6308 -SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
6384 +SQLITE_API sqlite3_filename sqlite3_db_filename(sqlite3 *db, const char *zDbName);
6385
6386 /*
6387 ** CAPI3REF: Determine if a database is read-only
@@ -6442,7 +6518,7 @@ SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
6518 ** function C that is invoked prior to each autovacuum of the database
6519 ** file. ^The callback is passed a copy of the generic data pointer (P),
6520 ** the schema-name of the attached database that is being autovacuumed,
6445 -** the the size of the database file in pages, the number of free pages,
6521 +** the size of the database file in pages, the number of free pages,
6522 ** and the number of bytes per page, respectively. The callback should
6523 ** return the number of free pages that should be removed by the
6524 ** autovacuum. ^If the callback returns zero, then no autovacuum happens.
@@ -6563,6 +6639,11 @@ SQLITE_API void *sqlite3_update_hook(
6639 ** to the same database. Sharing is enabled if the argument is true
6640 ** and disabled if the argument is false.)^
6641 **
6642 +** This interface is omitted if SQLite is compiled with
6643 +** [-DSQLITE_OMIT_SHARED_CACHE]. The [-DSQLITE_OMIT_SHARED_CACHE]
6644 +** compile-time option is recommended because the
6645 +** [use of shared cache mode is discouraged].
6646 +**
6647 ** ^Cache sharing is enabled and disabled for an entire process.
6648 ** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]).
6649 ** In prior versions of SQLite,
@@ -6661,7 +6742,7 @@ SQLITE_API int sqlite3_db_release_memory(sqlite3*);
6742 ** ^The soft heap limit may not be greater than the hard heap limit.
6743 ** ^If the hard heap limit is enabled and if sqlite3_soft_heap_limit(N)
6744 ** is invoked with a value of N that is greater than the hard heap limit,
6664 -** the the soft heap limit is set to the value of the hard heap limit.
6745 +** the soft heap limit is set to the value of the hard heap limit.
6746 ** ^The soft heap limit is automatically enabled whenever the hard heap
6747 ** limit is enabled. ^When sqlite3_hard_heap_limit64(N) is invoked and
6748 ** the soft heap limit is outside the range of 1..N, then the soft heap
@@ -8956,7 +9037,7 @@ typedef struct sqlite3_backup sqlite3_backup;
9037 ** if the application incorrectly accesses the destination [database connection]
9038 ** and so no error code is reported, but the operations may malfunction
9039 ** nevertheless. Use of the destination database connection while a
8959 -** backup is in progress might also also cause a mutex deadlock.
9040 +** backup is in progress might also cause a mutex deadlock.
9041 **
9042 ** If running in [shared cache mode], the application must
9043 ** guarantee that the shared cache used by the destination database
@@ -9384,7 +9465,7 @@ SQLITE_API int sqlite3_wal_checkpoint_v2(
9465 */
9466 #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
9467 #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
9387 -#define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */
9468 +#define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for readers */
9469 #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
9470
9471 /*
@@ -9554,8 +9635,8 @@ SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_
9635 ** of a [virtual table] implementation. The result of calling this
9636 ** interface from outside of xBestIndex() is undefined and probably harmful.
9637 **
9557 -** ^The sqlite3_vtab_distinct() interface returns an integer that is
9558 -** either 0, 1, or 2. The integer returned by sqlite3_vtab_distinct()
9638 +** ^The sqlite3_vtab_distinct() interface returns an integer between 0 and
9639 +** 3. The integer returned by sqlite3_vtab_distinct()
9640 ** gives the virtual table additional information about how the query
9641 ** planner wants the output to be ordered. As long as the virtual table
9642 ** can meet the ordering requirements of the query planner, it may set
@@ -9587,6 +9668,13 @@ SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_
9668 ** that have the same value for all columns identified by "aOrderBy".
9669 ** ^However omitting the extra rows is optional.
9670 ** This mode is used for a DISTINCT query.
9671 +** <li value="3"><p>
9672 +** ^(If the sqlite3_vtab_distinct() interface returns 3, that means
9673 +** that the query planner needs only distinct rows but it does need the
9674 +** rows to be sorted.)^ ^The virtual table implementation is free to omit
9675 +** rows that are identical in all aOrderBy columns, if it wants to, but
9676 +** it is not required to omit any rows. This mode is used for queries
9677 +** that have both DISTINCT and ORDER BY clauses.
9678 ** </ol>
9679 **
9680 ** ^For the purposes of comparing virtual table output values to see if the