Index: CHANGES.md ================================================================== --- CHANGES.md +++ CHANGES.md @@ -1,32 +1,5 @@ -**fnc 0.11** 2022-05-08 - -- handle diff of non-versioned files outside the work tree (reported by Dan) -- replace getpagesize() with portable sysconf(_SC_PAGESIZE) (patch by mgagnon) -- improve robustness by guarding against piped input abuse (reported by Dan) -- improve documentation regarding UTF-8 character encoding and fonts -- implement horizontal scroll of the log message summary line in timeline view -- fix out-of-bounds UB on 32-bit builds (reported by mgagnon) -- convert unified diff renderer to the improved line_type interface -- fix format specifier bug evinced on 32-bit builds (reported by mgagnon) -- improve unicode handling in terminals w/o UTF-8 support (reported by mgagnon) -- handle window resizing of horizontal and vertical splits (reported by mgagnon) -- improve regexp used to identify commit meta lines -- implement `fnc stash` to interactively select hunks to stash (cf. git add -p) -- fix diff regression introduced with `fnc stash` implementation [2870235eef78] -- simplify handling of diff driver error codes (i.e., binary, type, range) -- improve curses WINDOW reporter interface -- dynamically place help dialog title depending on viewport width -- improve return code RC macro to detect empty varargs token -- fix signed/unsigned comparison introduced in [41dfeb9ebb3d] -- display hunk index in `fnc stash` input prompt -- documentation improvements in README -- update in-tree SQLite lib to 3.38.5 with multiple bug fixes -- add `apply` alias for `fnc stash get` to facilitate Fossiler muscle memory -- simplify error, and tailor usage, reporting when handling invalid input -- remove redundant fcli_has_unused_args() call in main() - **fnc 0.10** 2022-03-24 - fix gcc 9.3 compiler warnings (i.e., unused variable) (reported by stephan) - restrict `C` key map for diffing local changes to check-in artifacts - ensure timeline --branch option ignores cancelled branches (reported by sean) Index: README.md ================================================================== --- README.md +++ README.md @@ -1,8 +1,8 @@ # README -# fnc 0.11 +# fnc 0.10 ## An interactive ncurses browser for [Fossil][0] repositories. `fnc` uses [libfossil][1] to create a [`fossil ui`][2] experience in the terminal. @@ -51,27 +51,10 @@ signed tarballs of the source code and binaries for some of the abovementioned platforms are available to [download][3]. # Doc -Commands available in **fnc**: - -1. [**stash**](/uv/resources/doc/fnc.1.html#stash) - - interactively select hunks to stash from the diff of local changes on disk -2. [**timeline**](/uv/resources/doc/fnc.1.html#timeline) - - hyperlinked chronological commit history of the repository -3. [**diff**](/uv/resources/doc/fnc.1.html#diff) - - diff of all changes between commits or blobs -4. [**blame**](/uv/resources/doc/fnc.1.html#blame) - - annotated file displaying commit attribution history of each line -5. [**tree**](/uv/resources/doc/fnc.1.html#tree) - - navigable file hierarchy of the repository tree -6. [**branch**](/uv/resources/doc/fnc.1.html#branch) - - hyperlinked list of all public and private branches -7. [**config**](/uv/resources/doc/fnc.1.html#config) - - configure or view fnc settings - See `fnc --help` for a quick reference, and the [fnc(1)][4] manual page for more comprehensive documentation. In-app help can also be accessed with the `?`, `F1`, or `H` key binding. The following video briefly demonstrates some of the key bindings in use. @@ -100,13 +83,10 @@ user interfaces) should concomitantly include updating documentation affected by the change. # Screenshots -![stash](https://fnc.bsdbox.org/uv/resources/img/fnc-stash.png "fnc stash") -![stash more](https://fnc.bsdbox.org/uv/resources/img/fnc-stash-more.png "stash more") -![stash help](https://fnc.bsdbox.org/uv/resources/img/fnc-stash-help.png "stash help") ![diff vsplit](https://fnc.bsdbox.org/uv/resources/img/fnc-diff-vsplit.png "diff vertical split") ![diff hsplit renamed](https://fnc.bsdbox.org/uv/resources/img/fnc-diff-hsplit-renamed.png "diff horizontal split file renamed") ![diff vsplit added](https://fnc.bsdbox.org/uv/resources/img/fnc-diff-vsplit-added.png "diff vertical split file added") ![diff vsplit removed](https://fnc.bsdbox.org/uv/resources/img/fnc-diff-vsplit-removed.png "diff vertical split file removed") ![blame vsplit](https://fnc.bsdbox.org/uv/resources/img/fnc-blame-vsplit.png "blame vertical split") Index: fnc.bld.mk ================================================================== --- fnc.bld.mk +++ fnc.bld.mk @@ -4,11 +4,11 @@ # CONFIGURATION CC ?= cc PREFIX ?= /usr/local MANDIR ?= /share/man -VERSION ?= 0.11 +VERSION ?= 0.10 # FLAGS NEEDED TO BUILD SQLITE3 SQLITE_CFLAGS = ${CFLAGS} -Wall -Werror -Wno-sign-compare -pedantic -std=c99 \ -DNDEBUG=1 \ -DSQLITE_DQS=0 \ Index: include/diff.h ================================================================== --- include/diff.h +++ include/diff.h @@ -38,11 +38,11 @@ struct diff_out_state { fsl_output_f out; /* Output callback */ void *state; /* State for this->out() */ enum line_type *lines; /* Diff line type (e.g., minus, plus) */ - uint32_t nlines; /* Index into this->lines */ + uint32_t *idx; /* Index into this->lines */ int rc; /* Error reporting */ char ansi; /* ANSI colour code */ struct { const fsl_buffer *file; /* Diffed file */ char *signature; /* Matching function */ @@ -96,11 +96,12 @@ int unidiff_lineno(struct diff_out_state *, int, int, bool); int unidiff_txt( struct diff_out_state *const, char, fsl_dline *, int, void *); int sbsdiff(fsl__diff_cx *, struct diff_out_state *, void *, uint16_t, uint64_t); -int max_sbs_width(fsl__diff_cx *, int *, uint16_t); +int alloc_lines_and_width(fsl__diff_cx *, int *, uint16_t, + uint32_t, enum line_type **); unsigned short etcount(const char *str, unsigned short n); int sbsdiff_width(uint64_t); int sbsdiff_separator(struct sbsline *, int, int); int sbsdiff_lineno(struct sbsline *, int, int); void sbsdiff_shift_left(struct sbsline *, const char *); @@ -113,6 +114,5 @@ int sbsdiff_marker(struct sbsline *, const char *, const char *); int sbsdiff_close_gap(int *); unsigned char *sbsdiff_align(fsl_dline *, int, fsl_dline *, int); int sbsdiff_write_change(struct sbsline *, fsl_dline *, int, fsl_dline *, int); -int add_line_type(enum line_type **, uint32_t *, enum line_type); Index: lib/sqlite3.c ================================================================== --- lib/sqlite3.c +++ lib/sqlite3.c @@ -1,8 +1,8 @@ /****************************************************************************** ** This file is an amalgamation of many separate C source files from SQLite -** version 3.38.5. By combining all the individual C code files into this +** version 3.37.0. By combining all the individual C code files into this ** single large file, the entire code can be compiled as a single translation ** unit. This allows many compilers to do optimizations that would not be ** possible if the files were compiled separately. Performance improvements ** of 5% or more are commonly seen when SQLite is compiled as a single ** translation unit. @@ -450,13 +450,13 @@ ** ** See also: [sqlite3_libversion()], ** [sqlite3_libversion_number()], [sqlite3_sourceid()], ** [sqlite_version()] and [sqlite_source_id()]. */ -#define SQLITE_VERSION "3.38.5" -#define SQLITE_VERSION_NUMBER 3038005 -#define SQLITE_SOURCE_ID "2022-05-06 15:25:27 78d9c993d404cdfaa7fdd2973fa1052e3da9f66215cff9c5540ebe55c407d9fe" +#define SQLITE_VERSION "3.37.0" +#define SQLITE_VERSION_NUMBER 3037000 +#define SQLITE_SOURCE_ID "2021-10-04 11:10:15 8b24c177061c38361588f419eda9b7943b72a0c6b2855b6f39272451b8a1b813" /* ** CAPI3REF: Run-Time Library Version Numbers ** KEYWORDS: sqlite3_version sqlite3_sourceid ** @@ -843,10 +843,11 @@ #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */ #define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8)) +#define SQLITE_CANTOPEN_EXISTS (SQLITE_CANTOPEN | (7<<8)) #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8)) #define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8)) #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) @@ -870,31 +871,18 @@ #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8)) #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8)) #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8)) -#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */ +#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* ** CAPI3REF: Flags For File Open Operations ** ** These bit values are intended for use in the ** 3rd parameter to the [sqlite3_open_v2()] interface and ** in the 4th parameter to the [sqlite3_vfs.xOpen] method. -** -** Only those flags marked as "Ok for sqlite3_open_v2()" may be -** used as the third argument to the [sqlite3_open_v2()] interface. -** The other flags have historically been ignored by sqlite3_open_v2(), -** though future versions of SQLite might change so that an error is -** raised if any of the disallowed bits are passed into sqlite3_open_v2(). -** Applications should not depend on the historical behavior. -** -** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into -** [sqlite3_open_v2()] does *not* cause the underlying database file -** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into -** [sqlite3_open_v2()] has historically be a no-op and might become an -** error in future versions of SQLite. */ #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ @@ -913,11 +901,10 @@ #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ #define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */ -#define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */ /* Reserved: 0x00F00000 */ /* Legacy compatibility: */ #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ @@ -3734,34 +3721,24 @@ ** ^(
[SQLITE_OPEN_PRIVATECACHE]
**
The database is opened [shared cache] disabled, overriding ** the default shared cache setting provided by ** [sqlite3_enable_shared_cache()].)^ ** -** [[OPEN_EXRESCODE]] ^(
[SQLITE_OPEN_EXRESCODE]
-**
The database connection comes up in "extended result code mode". -** In other words, the database behaves has if -** [sqlite3_extended_result_codes(db,1)] where called on the database -** connection as soon as the connection is created. In addition to setting -** the extended result code mode, this flag also causes [sqlite3_open_v2()] -** to return an extended result code.
-** ** [[OPEN_NOFOLLOW]] ^(
[SQLITE_OPEN_NOFOLLOW]
**
The database filename is not allowed to be a symbolic link
+** +** [[OPEN_EXCLUSIVE]] ^(
[SQLITE_OPEN_EXCLUSIVE]
+**
This flag causes the open to fail if the database file already +** exists. The open will only be success if this flag is used in combination +** with the SQLITE_OPEN_CREATE and SQLITE_OPEN_READWRITE flags and if +** the file does not previously exist.
** )^ ** ** If the 3rd parameter to sqlite3_open_v2() is not one of the ** required combinations shown above optionally combined with other ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits] -** then the behavior is undefined. Historic versions of SQLite -** have silently ignored surplus bits in the flags parameter to -** sqlite3_open_v2(), however that behavior might not be carried through -** into future versions of SQLite and so applications should not rely -** upon it. Note in particular that the SQLITE_OPEN_EXCLUSIVE flag is a no-op -** for sqlite3_open_v2(). The SQLITE_OPEN_EXCLUSIVE does *not* cause -** the open to fail if the database already exists. The SQLITE_OPEN_EXCLUSIVE -** flag is intended for use by the [sqlite3_vfs|VFS interface] only, and not -** by sqlite3_open_v2(). +** then the behavior is undefined. ** ** ^The fourth parameter to sqlite3_open_v2() is the name of the ** [sqlite3_vfs] object that defines the operating system interface that ** the new database connection should use. ^If the fourth parameter is ** a NULL pointer then the default [sqlite3_vfs] object is used. @@ -4128,18 +4105,17 @@ ** ** The values returned by sqlite3_errcode() and/or ** sqlite3_extended_errcode() might change with each API call. ** Except, there are some interfaces that are guaranteed to never ** change the value of the error code. The error-code preserving -** interfaces include the following: +** interfaces are: ** ** ** ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language ** text that describes the error, as either UTF-8 or UTF-16 respectively. ** ^(Memory to hold the error message string is managed internally. @@ -4150,17 +4126,10 @@ ** ^The sqlite3_errstr() interface returns the English-language text ** that describes the [result code], as UTF-8. ** ^(Memory to hold the error message string is managed internally ** and must not be freed by the application)^. ** -** ^If the most recent error references a specific token in the input -** SQL, the sqlite3_error_offset() interface returns the byte offset -** of the start of that token. ^The byte offset returned by -** sqlite3_error_offset() assumes that the input SQL is UTF8. -** ^If the most recent error does not reference a specific token in the input -** SQL, then the sqlite3_error_offset() function returns -1. -** ** When the serialized [threading mode] is in use, it might be the ** case that a second error occurs on a separate thread in between ** the time of the first error and the call to these interfaces. ** When that happens, the second error will be reported since these ** interfaces always report the most recent result. To avoid @@ -4176,11 +4145,10 @@ SQLITE_API int sqlite3_errcode(sqlite3 *db); SQLITE_API int sqlite3_extended_errcode(sqlite3 *db); SQLITE_API const char *sqlite3_errmsg(sqlite3*); SQLITE_API const void *sqlite3_errmsg16(sqlite3*); SQLITE_API const char *sqlite3_errstr(int); -SQLITE_API int sqlite3_error_offset(sqlite3 *db); /* ** CAPI3REF: Prepared Statement Object ** KEYWORDS: {prepared statement} {prepared statements} ** @@ -4588,14 +4556,10 @@ ** ^For example, an UPDATE statement might have a WHERE clause that ** makes it a no-op, but the sqlite3_stmt_readonly() result would still ** be false. ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a ** read-only no-op if the table already exists, but ** sqlite3_stmt_readonly() still returns false for such a statement. -** -** ^If prepared statement X is an [EXPLAIN] or [EXPLAIN QUERY PLAN] -** statement, then sqlite3_stmt_readonly(X) returns the same value as -** if the EXPLAIN or EXPLAIN QUERY PLAN prefix were omitted. */ SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); /* ** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement @@ -4660,12 +4624,10 @@ ** still make the distinction between protected and unprotected ** sqlite3_value objects even when not strictly required. ** ** ^The sqlite3_value objects that are passed as parameters into the ** implementation of [application-defined SQL functions] are protected. -** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()] -** are protected. ** ^The sqlite3_value object returned by ** [sqlite3_column_value()] is unprotected. ** Unprotected sqlite3_value objects may only be used as arguments ** to [sqlite3_result_value()], [sqlite3_bind_value()], and ** [sqlite3_value_dup()]. @@ -5283,14 +5245,10 @@ ** ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(), ** even empty strings, are always zero-terminated. ^The return ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer. ** -** ^Strings returned by sqlite3_column_text16() always have the endianness -** which is native to the platform, regardless of the text encoding set -** for the database. -** ** Warning: ^The object returned by [sqlite3_column_value()] is an ** [unprotected sqlite3_value] object. In a multithreaded environment, ** an unprotected sqlite3_value object may only be used safely with ** [sqlite3_bind_value()] and [sqlite3_result_value()]. ** If the [unprotected sqlite3_value] object returned by @@ -5300,11 +5258,11 @@ ** Hence, the sqlite3_column_value() interface ** is normally only useful within the implementation of ** [application-defined SQL functions] or [virtual tables], not within ** top-level application code. ** -** These routines may attempt to convert the datatype of the result. +** The these routines may attempt to convert the datatype of the result. ** ^For example, if the internal representation is FLOAT and a text result ** is requested, [sqlite3_snprintf()] is used internally to perform the ** conversion automatically. ^(The following table details the conversions ** that are applied: ** @@ -5325,11 +5283,11 @@ ** TEXT INTEGER [CAST] to INTEGER ** TEXT FLOAT [CAST] to REAL ** TEXT BLOB No change ** BLOB INTEGER [CAST] to INTEGER ** BLOB FLOAT [CAST] to REAL -** BLOB TEXT [CAST] to TEXT, ensure zero terminator +** BLOB TEXT Add a zero terminator if needed ** ** )^ ** ** Note that when type conversions occur, pointers returned by prior ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or @@ -6737,76 +6695,10 @@ ** ** See also the [sqlite3_update_hook()] interface. */ SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); - -/* -** CAPI3REF: Autovacuum Compaction Amount Callback -** METHOD: sqlite3 -** -** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback -** function C that is invoked prior to each autovacuum of the database -** file. ^The callback is passed a copy of the generic data pointer (P), -** the schema-name of the attached database that is being autovacuumed, -** the the size of the database file in pages, the number of free pages, -** and the number of bytes per page, respectively. The callback should -** return the number of free pages that should be removed by the -** autovacuum. ^If the callback returns zero, then no autovacuum happens. -** ^If the value returned is greater than or equal to the number of -** free pages, then a complete autovacuum happens. -** -**

^If there are multiple ATTACH-ed database files that are being -** modified as part of a transaction commit, then the autovacuum pages -** callback is invoked separately for each file. -** -**

The callback is not reentrant. The callback function should -** not attempt to invoke any other SQLite interface. If it does, bad -** things may happen, including segmentation faults and corrupt database -** files. The callback function should be a simple function that -** does some arithmetic on its input parameters and returns a result. -** -** ^The X parameter to sqlite3_autovacuum_pages(D,C,P,X) is an optional -** destructor for the P parameter. ^If X is not NULL, then X(P) is -** invoked whenever the database connection closes or when the callback -** is overwritten by another invocation of sqlite3_autovacuum_pages(). -** -**

^There is only one autovacuum pages callback per database connection. -** ^Each call to the sqlite3_autovacuum_pages() interface overrides all -** previous invocations for that database connection. ^If the callback -** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer, -** then the autovacuum steps callback is cancelled. The return value -** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might -** be some other error code if something goes wrong. The current -** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other -** return codes might be added in future releases. -** -**

If no autovacuum pages callback is specified (the usual case) or -** a NULL pointer is provided for the callback, -** then the default behavior is to vacuum all free pages. So, in other -** words, the default behavior is the same as if the callback function -** were something like this: -** -**

-**     unsigned int demonstration_autovac_pages_callback(
-**       void *pClientData,
-**       const char *zSchema,
-**       unsigned int nDbPage,
-**       unsigned int nFreePage,
-**       unsigned int nBytePerPage
-**     ){
-**       return nFreePage;
-**     }
-** 
-*/ -SQLITE_API int sqlite3_autovacuum_pages( - sqlite3 *db, - unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int), - void*, - void(*)(void*) -); - /* ** CAPI3REF: Data Change Notification Callbacks ** METHOD: sqlite3 ** @@ -7445,60 +7337,28 @@ /* ** CAPI3REF: Virtual Table Constraint Operator Codes ** ** These macros define the allowed values for the ** [sqlite3_index_info].aConstraint[].op field. Each value represents -** an operator that is part of a constraint term in the WHERE clause of +** an operator that is part of a constraint term in the wHERE clause of ** a query that uses a [virtual table]. -** -** ^The left-hand operand of the operator is given by the corresponding -** aConstraint[].iColumn field. ^An iColumn of -1 indicates the left-hand -** operand is the rowid. -** The SQLITE_INDEX_CONSTRAINT_LIMIT and SQLITE_INDEX_CONSTRAINT_OFFSET -** operators have no left-hand operand, and so for those operators the -** corresponding aConstraint[].iColumn is meaningless and should not be -** used. -** -** All operator values from SQLITE_INDEX_CONSTRAINT_FUNCTION through -** value 255 are reserved to represent functions that are overloaded -** by the [xFindFunction|xFindFunction method] of the virtual table -** implementation. -** -** The right-hand operands for each constraint might be accessible using -** the [sqlite3_vtab_rhs_value()] interface. Usually the right-hand -** operand is only available if it appears as a single constant literal -** in the input SQL. If the right-hand operand is another column or an -** expression (even a constant expression) or a parameter, then the -** sqlite3_vtab_rhs_value() probably will not be able to extract it. -** ^The SQLITE_INDEX_CONSTRAINT_ISNULL and -** SQLITE_INDEX_CONSTRAINT_ISNOTNULL operators have no right-hand operand -** and hence calls to sqlite3_vtab_rhs_value() for those operators will -** always return SQLITE_NOTFOUND. -** -** The collating sequence to be used for comparison can be found using -** the [sqlite3_vtab_collation()] interface. For most real-world virtual -** tables, the collating sequence of constraints does not matter (for example -** because the constraints are numeric) and so the sqlite3_vtab_collation() -** interface is no commonly needed. */ -#define SQLITE_INDEX_CONSTRAINT_EQ 2 -#define SQLITE_INDEX_CONSTRAINT_GT 4 -#define SQLITE_INDEX_CONSTRAINT_LE 8 -#define SQLITE_INDEX_CONSTRAINT_LT 16 -#define SQLITE_INDEX_CONSTRAINT_GE 32 -#define SQLITE_INDEX_CONSTRAINT_MATCH 64 -#define SQLITE_INDEX_CONSTRAINT_LIKE 65 -#define SQLITE_INDEX_CONSTRAINT_GLOB 66 -#define SQLITE_INDEX_CONSTRAINT_REGEXP 67 -#define SQLITE_INDEX_CONSTRAINT_NE 68 -#define SQLITE_INDEX_CONSTRAINT_ISNOT 69 -#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70 -#define SQLITE_INDEX_CONSTRAINT_ISNULL 71 -#define SQLITE_INDEX_CONSTRAINT_IS 72 -#define SQLITE_INDEX_CONSTRAINT_LIMIT 73 -#define SQLITE_INDEX_CONSTRAINT_OFFSET 74 -#define SQLITE_INDEX_CONSTRAINT_FUNCTION 150 +#define SQLITE_INDEX_CONSTRAINT_EQ 2 +#define SQLITE_INDEX_CONSTRAINT_GT 4 +#define SQLITE_INDEX_CONSTRAINT_LE 8 +#define SQLITE_INDEX_CONSTRAINT_LT 16 +#define SQLITE_INDEX_CONSTRAINT_GE 32 +#define SQLITE_INDEX_CONSTRAINT_MATCH 64 +#define SQLITE_INDEX_CONSTRAINT_LIKE 65 +#define SQLITE_INDEX_CONSTRAINT_GLOB 66 +#define SQLITE_INDEX_CONSTRAINT_REGEXP 67 +#define SQLITE_INDEX_CONSTRAINT_NE 68 +#define SQLITE_INDEX_CONSTRAINT_ISNOT 69 +#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70 +#define SQLITE_INDEX_CONSTRAINT_ISNULL 71 +#define SQLITE_INDEX_CONSTRAINT_IS 72 +#define SQLITE_INDEX_CONSTRAINT_FUNCTION 150 /* ** CAPI3REF: Register A Virtual Table Implementation ** METHOD: sqlite3 ** @@ -7523,11 +7383,11 @@ ** ^The sqlite3_create_module() ** interface is equivalent to sqlite3_create_module_v2() with a NULL ** destructor. ** ** ^If the third parameter (the pointer to the sqlite3_module object) is -** NULL then no new module is created and any existing modules with the +** NULL then no new module is create and any existing modules with the ** same name are dropped. ** ** See also: [sqlite3_drop_modules()] */ SQLITE_API int sqlite3_create_module( @@ -8299,12 +8159,11 @@ #define SQLITE_TESTCTRL_PRNG_SEED 28 #define SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS 29 #define SQLITE_TESTCTRL_SEEK_COUNT 30 #define SQLITE_TESTCTRL_TRACEFLAGS 31 #define SQLITE_TESTCTRL_TUNE 32 -#define SQLITE_TESTCTRL_LOGEST 33 -#define SQLITE_TESTCTRL_LAST 33 /* Largest TESTCTRL */ +#define SQLITE_TESTCTRL_LAST 32 /* Largest TESTCTRL */ /* ** CAPI3REF: SQL Keyword Checking ** ** These routines provide access to the set of SQL language keywords @@ -8823,20 +8682,10 @@ ** been run. A single "run" for the purposes of this counter is one ** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()]. ** The counter is incremented on the first [sqlite3_step()] call of each ** cycle. ** -** [[SQLITE_STMTSTATUS_FILTER_MISS]] -** [[SQLITE_STMTSTATUS_FILTER HIT]] -**
SQLITE_STMTSTATUS_FILTER_HIT
-** SQLITE_STMTSTATUS_FILTER_MISS
-**
^SQLITE_STMTSTATUS_FILTER_HIT is the number of times that a join -** step was bypassed because a Bloom filter returned not-found. The -** corresponding SQLITE_STMTSTATUS_FILTER_MISS value is the number of -** times that the Bloom filter returned a find, and thus the join step -** had to be processed as normal. -** ** [[SQLITE_STMTSTATUS_MEMUSED]]
SQLITE_STMTSTATUS_MEMUSED
**
^This is the approximate number of bytes of heap memory ** used to store the prepared statement. ^This value is not actually ** a counter, and so the resetFlg parameter to sqlite3_stmt_status() ** is ignored when the opcode is SQLITE_STMTSTATUS_MEMUSED. @@ -8847,12 +8696,10 @@ #define SQLITE_STMTSTATUS_SORT 2 #define SQLITE_STMTSTATUS_AUTOINDEX 3 #define SQLITE_STMTSTATUS_VM_STEP 4 #define SQLITE_STMTSTATUS_REPREPARE 5 #define SQLITE_STMTSTATUS_RUN 6 -#define SQLITE_STMTSTATUS_FILTER_MISS 7 -#define SQLITE_STMTSTATUS_FILTER_HIT 8 #define SQLITE_STMTSTATUS_MEMUSED 99 /* ** CAPI3REF: Custom Page Cache Object ** @@ -9817,272 +9664,22 @@ */ SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*); /* ** CAPI3REF: Determine The Collation For a Virtual Table Constraint -** METHOD: sqlite3_index_info ** ** This function may only be called from within a call to the [xBestIndex] -** method of a [virtual table]. This function returns a pointer to a string -** that is the name of the appropriate collation sequence to use for text -** comparisons on the constraint identified by its arguments. -** -** The first argument must be the pointer to the [sqlite3_index_info] object -** that is the first parameter to the xBestIndex() method. The second argument -** must be an index into the aConstraint[] array belonging to the -** sqlite3_index_info structure passed to xBestIndex. -** -** Important: -** The first parameter must be the same pointer that is passed into the -** xBestMethod() method. The first parameter may not be a pointer to a -** different [sqlite3_index_info] object, even an exact copy. -** -** The return value is computed as follows: -** -**
    -**
  1. If the constraint comes from a WHERE clause expression that contains -** a [COLLATE operator], then the name of the collation specified by -** that COLLATE operator is returned. -**

  2. If there is no COLLATE operator, but the column that is the subject -** of the constraint specifies an alternative collating sequence via -** a [COLLATE clause] on the column definition within the CREATE TABLE -** statement that was passed into [sqlite3_declare_vtab()], then the -** name of that alternative collating sequence is returned. -**

  3. Otherwise, "BINARY" is returned. -**

-*/ -SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int); - -/* -** CAPI3REF: Determine if a virtual table query is DISTINCT -** METHOD: sqlite3_index_info -** -** This API may only be used from within an [xBestIndex|xBestIndex method] -** of a [virtual table] implementation. The result of calling this -** interface from outside of xBestIndex() is undefined and probably harmful. -** -** ^The sqlite3_vtab_distinct() interface returns an integer that is -** either 0, 1, or 2. The integer returned by sqlite3_vtab_distinct() -** gives the virtual table additional information about how the query -** planner wants the output to be ordered. As long as the virtual table -** can meet the ordering requirements of the query planner, it may set -** the "orderByConsumed" flag. -** -**
  1. -** ^If the sqlite3_vtab_distinct() interface returns 0, that means -** that the query planner needs the virtual table to return all rows in the -** sort order defined by the "nOrderBy" and "aOrderBy" fields of the -** [sqlite3_index_info] object. This is the default expectation. If the -** virtual table outputs all rows in sorted order, then it is always safe for -** the xBestIndex method to set the "orderByConsumed" flag, regardless of -** the return value from sqlite3_vtab_distinct(). -**

  2. -** ^(If the sqlite3_vtab_distinct() interface returns 1, that means -** that the query planner does not need the rows to be returned in sorted order -** as long as all rows with the same values in all columns identified by the -** "aOrderBy" field are adjacent.)^ This mode is used when the query planner -** is doing a GROUP BY. -**

  3. -** ^(If the sqlite3_vtab_distinct() interface returns 2, that means -** that the query planner does not need the rows returned in any particular -** order, as long as rows with the same values in all "aOrderBy" columns -** are adjacent.)^ ^(Furthermore, only a single row for each particular -** combination of values in the columns identified by the "aOrderBy" field -** needs to be returned.)^ ^It is always ok for two or more rows with the same -** values in all "aOrderBy" columns to be returned, as long as all such rows -** are adjacent. ^The virtual table may, if it chooses, omit extra rows -** that have the same value for all columns identified by "aOrderBy". -** ^However omitting the extra rows is optional. -** This mode is used for a DISTINCT query. -**

-** -** ^For the purposes of comparing virtual table output values to see if the -** values are same value for sorting purposes, two NULL values are considered -** to be the same. In other words, the comparison operator is "IS" -** (or "IS NOT DISTINCT FROM") and not "==". -** -** If a virtual table implementation is unable to meet the requirements -** specified above, then it must not set the "orderByConsumed" flag in the -** [sqlite3_index_info] object or an incorrect answer may result. -** -** ^A virtual table implementation is always free to return rows in any order -** it wants, as long as the "orderByConsumed" flag is not set. ^When the -** the "orderByConsumed" flag is unset, the query planner will add extra -** [bytecode] to ensure that the final results returned by the SQL query are -** ordered correctly. The use of the "orderByConsumed" flag and the -** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful -** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed" -** flag might help queries against a virtual table to run faster. Being -** overly aggressive and setting the "orderByConsumed" flag when it is not -** valid to do so, on the other hand, might cause SQLite to return incorrect -** results. -*/ -SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*); - -/* -** CAPI3REF: Identify and handle IN constraints in xBestIndex -** -** This interface may only be used from within an -** [xBestIndex|xBestIndex() method] of a [virtual table] implementation. -** The result of invoking this interface from any other context is -** undefined and probably harmful. -** -** ^(A constraint on a virtual table of the form -** "[IN operator|column IN (...)]" is -** communicated to the xBestIndex method as a -** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use -** this constraint, it must set the corresponding -** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under -** the usual mode of handling IN operators, SQLite generates [bytecode] -** that invokes the [xFilter|xFilter() method] once for each value -** on the right-hand side of the IN operator.)^ Thus the virtual table -** only sees a single value from the right-hand side of the IN operator -** at a time. -** -** In some cases, however, it would be advantageous for the virtual -** table to see all values on the right-hand of the IN operator all at -** once. The sqlite3_vtab_in() interfaces facilitates this in two ways: -** -**
    -**
  1. -** ^A call to sqlite3_vtab_in(P,N,-1) will return true (non-zero) -** if and only if the [sqlite3_index_info|P->aConstraint][N] constraint -** is an [IN operator] that can be processed all at once. ^In other words, -** sqlite3_vtab_in() with -1 in the third argument is a mechanism -** by which the virtual table can ask SQLite if all-at-once processing -** of the IN operator is even possible. -** -**

  2. -** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates -** to SQLite that the virtual table does or does not want to process -** the IN operator all-at-once, respectively. ^Thus when the third -** parameter (F) is non-negative, this interface is the mechanism by -** which the virtual table tells SQLite how it wants to process the -** IN operator. -**

-** -** ^The sqlite3_vtab_in(P,N,F) interface can be invoked multiple times -** within the same xBestIndex method call. ^For any given P,N pair, -** the return value from sqlite3_vtab_in(P,N,F) will always be the same -** within the same xBestIndex call. ^If the interface returns true -** (non-zero), that means that the constraint is an IN operator -** that can be processed all-at-once. ^If the constraint is not an IN -** operator or cannot be processed all-at-once, then the interface returns -** false. -** -** ^(All-at-once processing of the IN operator is selected if both of the -** following conditions are met: -** -**
    -**
  1. The P->aConstraintUsage[N].argvIndex value is set to a positive -** integer. This is how the virtual table tells SQLite that it wants to -** use the N-th constraint. -** -**

  2. The last call to sqlite3_vtab_in(P,N,F) for which F was -** non-negative had F>=1. -**

)^ -** -** ^If either or both of the conditions above are false, then SQLite uses -** the traditional one-at-a-time processing strategy for the IN constraint. -** ^If both conditions are true, then the argvIndex-th parameter to the -** xFilter method will be an [sqlite3_value] that appears to be NULL, -** but which can be passed to [sqlite3_vtab_in_first()] and -** [sqlite3_vtab_in_next()] to find all values on the right-hand side -** of the IN constraint. -*/ -SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle); - -/* -** CAPI3REF: Find all elements on the right-hand side of an IN constraint. -** -** These interfaces are only useful from within the -** [xFilter|xFilter() method] of a [virtual table] implementation. -** The result of invoking these interfaces from any other context -** is undefined and probably harmful. -** -** The X parameter in a call to sqlite3_vtab_in_first(X,P) or -** sqlite3_vtab_in_next(X,P) must be one of the parameters to the -** xFilter method which invokes these routines, and specifically -** a parameter that was previously selected for all-at-once IN constraint -** processing use the [sqlite3_vtab_in()] interface in the -** [xBestIndex|xBestIndex method]. ^(If the X parameter is not -** an xFilter argument that was selected for all-at-once IN constraint -** processing, then these routines return [SQLITE_MISUSE])^ or perhaps -** exhibit some other undefined or harmful behavior. -** -** ^(Use these routines to access all values on the right-hand side -** of the IN constraint using code like the following: -** -**
-**    for(rc=sqlite3_vtab_in_first(pList, &pVal);
-**        rc==SQLITE_OK && pVal
-**        rc=sqlite3_vtab_in_next(pList, &pVal)
-**    ){
-**      // do something with pVal
-**    }
-**    if( rc!=SQLITE_OK ){
-**      // an error has occurred
-**    }
-** 
)^ -** -** ^On success, the sqlite3_vtab_in_first(X,P) and sqlite3_vtab_in_next(X,P) -** routines return SQLITE_OK and set *P to point to the first or next value -** on the RHS of the IN constraint. ^If there are no more values on the -** right hand side of the IN constraint, then *P is set to NULL and these -** routines return [SQLITE_DONE]. ^The return value might be -** some other value, such as SQLITE_NOMEM, in the event of a malfunction. -** -** The *ppOut values returned by these routines are only valid until the -** next call to either of these routines or until the end of the xFilter -** method from which these routines were called. If the virtual table -** implementation needs to retain the *ppOut values for longer, it must make -** copies. The *ppOut values are [protected sqlite3_value|protected]. -*/ -SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut); -SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut); - -/* -** CAPI3REF: Constraint values in xBestIndex() -** METHOD: sqlite3_index_info -** -** This API may only be used from within the [xBestIndex|xBestIndex method] -** of a [virtual table] implementation. The result of calling this interface -** from outside of an xBestIndex method are undefined and probably harmful. -** -** ^When the sqlite3_vtab_rhs_value(P,J,V) interface is invoked from within -** the [xBestIndex] method of a [virtual table] implementation, with P being -** a copy of the [sqlite3_index_info] object pointer passed into xBestIndex and -** J being a 0-based index into P->aConstraint[], then this routine -** attempts to set *V to the value of the right-hand operand of -** that constraint if the right-hand operand is known. ^If the -** right-hand operand is not known, then *V is set to a NULL pointer. -** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if -** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V) -** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th -** constraint is not available. ^The sqlite3_vtab_rhs_value() interface -** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if -** something goes wrong. -** -** The sqlite3_vtab_rhs_value() interface is usually only successful if -** the right-hand operand of a constraint is a literal value in the original -** SQL statement. If the right-hand operand is an expression or a reference -** to some other column or a [host parameter], then sqlite3_vtab_rhs_value() -** will probably return [SQLITE_NOTFOUND]. -** -** ^(Some constraints, such as [SQLITE_INDEX_CONSTRAINT_ISNULL] and -** [SQLITE_INDEX_CONSTRAINT_ISNOTNULL], have no right-hand operand. For such -** constraints, sqlite3_vtab_rhs_value() always returns SQLITE_NOTFOUND.)^ -** -** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value -** and remains valid for the duration of the xBestIndex method call. -** ^When xBestIndex returns, the sqlite3_value object returned by -** sqlite3_vtab_rhs_value() is automatically deallocated. -** -** The "_rhs_" in the name of this routine is an abbreviation for -** "Right-Hand Side". -*/ -SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal); +** method of a [virtual table]. +** +** The first argument must be the sqlite3_index_info object that is the +** first parameter to the xBestIndex() method. The second argument must be +** an index into the aConstraint[] array belonging to the sqlite3_index_info +** structure passed to xBestIndex. This function returns a pointer to a buffer +** containing the name of the collation sequence for the corresponding +** constraint. +*/ +SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int); /* ** CAPI3REF: Conflict resolution modes ** KEYWORDS: {conflict resolution mode} ** @@ -13563,16 +13160,15 @@ ** can be used to make sure boundary values are tested. For ** bitmask tests, testcase() can be used to make sure each bit ** is significant and used at least once. On switch statements ** where multiple cases go to the same block of code, testcase() ** can insure that all cases are evaluated. +** */ -#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG) -# ifndef SQLITE_AMALGAMATION - extern unsigned int sqlite3CoverageCounter; -# endif -# define testcase(X) if( X ){ sqlite3CoverageCounter += (unsigned)__LINE__; } +#ifdef SQLITE_COVERAGE_TEST +SQLITE_PRIVATE void sqlite3Coverage(int); +# define testcase(X) if( X ){ sqlite3Coverage(__LINE__); } #else # define testcase(X) #endif /* @@ -13598,18 +13194,10 @@ # define VVA_ONLY(X) X #else # define VVA_ONLY(X) #endif -/* -** Disable ALWAYS() and NEVER() (make them pass-throughs) for coverage -** and mutation testing -*/ -#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST) -# define SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS 1 -#endif - /* ** The ALWAYS and NEVER macros surround boolean expressions which ** are intended to always be true or false, respectively. Such ** expressions could be omitted from the code completely. But they ** are included in a few cases in order to enhance the resilience @@ -13621,11 +13209,11 @@ ** ** When doing coverage testing ALWAYS and NEVER are hard-coded to ** be true and false so that the unreachable code they specify will ** not be counted as untested code. */ -#if defined(SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS) +#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST) # define ALWAYS(X) (1) # define NEVER(X) (0) #elif !defined(NDEBUG) # define ALWAYS(X) ((X)?1:(assert(0),0)) # define NEVER(X) ((X)?(assert(0),1):0) @@ -13632,10 +13220,30 @@ #else # define ALWAYS(X) (X) # define NEVER(X) (X) #endif +/* +** The harmless(X) macro indicates that expression X is usually false +** but can be true without causing any problems, but we don't know of +** any way to cause X to be true. +** +** In debugging and testing builds, this macro will abort if X is ever +** true. In this way, developers are alerted to a possible test case +** that causes X to be true. If a harmless macro ever fails, that is +** an opportunity to change the macro into a testcase() and add a new +** test case to the test suite. +** +** For normal production builds, harmless(X) is a no-op, since it does +** not matter whether expression X is true or false. +*/ +#ifdef SQLITE_DEBUG +# define harmless(X) assert(!(X)); +#else +# define harmless(X) +#endif + /* ** Some conditionals are optimizations only. In other words, if the ** conditionals are replaced with a constant 1 (true) or 0 (false) then ** the correct answer is still obtained, though perhaps not as quickly. ** @@ -13814,11 +13422,11 @@ /* #define sqliteHashKeysize(E) ((E)->nKey) // NOT USED */ /* ** Number of entries in a hash table */ -#define sqliteHashCount(H) ((H)->count) +/* #define sqliteHashCount(H) ((H)->count) // NOT USED */ #endif /* SQLITE_HASH_H */ /************** End of hash.h ************************************************/ /************** Continuing where we left off in sqliteInt.h ******************/ @@ -13933,83 +13541,82 @@ #define TK_MINUS 107 #define TK_STAR 108 #define TK_SLASH 109 #define TK_REM 110 #define TK_CONCAT 111 -#define TK_PTR 112 -#define TK_COLLATE 113 -#define TK_BITNOT 114 -#define TK_ON 115 -#define TK_INDEXED 116 -#define TK_STRING 117 -#define TK_JOIN_KW 118 -#define TK_CONSTRAINT 119 -#define TK_DEFAULT 120 -#define TK_NULL 121 -#define TK_PRIMARY 122 -#define TK_UNIQUE 123 -#define TK_CHECK 124 -#define TK_REFERENCES 125 -#define TK_AUTOINCR 126 -#define TK_INSERT 127 -#define TK_DELETE 128 -#define TK_UPDATE 129 -#define TK_SET 130 -#define TK_DEFERRABLE 131 -#define TK_FOREIGN 132 -#define TK_DROP 133 -#define TK_UNION 134 -#define TK_ALL 135 -#define TK_EXCEPT 136 -#define TK_INTERSECT 137 -#define TK_SELECT 138 -#define TK_VALUES 139 -#define TK_DISTINCT 140 -#define TK_DOT 141 -#define TK_FROM 142 -#define TK_JOIN 143 -#define TK_USING 144 -#define TK_ORDER 145 -#define TK_GROUP 146 -#define TK_HAVING 147 -#define TK_LIMIT 148 -#define TK_WHERE 149 -#define TK_RETURNING 150 -#define TK_INTO 151 -#define TK_NOTHING 152 -#define TK_FLOAT 153 -#define TK_BLOB 154 -#define TK_INTEGER 155 -#define TK_VARIABLE 156 -#define TK_CASE 157 -#define TK_WHEN 158 -#define TK_THEN 159 -#define TK_ELSE 160 -#define TK_INDEX 161 -#define TK_ALTER 162 -#define TK_ADD 163 -#define TK_WINDOW 164 -#define TK_OVER 165 -#define TK_FILTER 166 -#define TK_COLUMN 167 -#define TK_AGG_FUNCTION 168 -#define TK_AGG_COLUMN 169 -#define TK_TRUEFALSE 170 -#define TK_ISNOT 171 -#define TK_FUNCTION 172 -#define TK_UMINUS 173 -#define TK_UPLUS 174 -#define TK_TRUTH 175 -#define TK_REGISTER 176 -#define TK_VECTOR 177 -#define TK_SELECT_COLUMN 178 -#define TK_IF_NULL_ROW 179 -#define TK_ASTERISK 180 -#define TK_SPAN 181 -#define TK_ERROR 182 -#define TK_SPACE 183 -#define TK_ILLEGAL 184 +#define TK_COLLATE 112 +#define TK_BITNOT 113 +#define TK_ON 114 +#define TK_INDEXED 115 +#define TK_STRING 116 +#define TK_JOIN_KW 117 +#define TK_CONSTRAINT 118 +#define TK_DEFAULT 119 +#define TK_NULL 120 +#define TK_PRIMARY 121 +#define TK_UNIQUE 122 +#define TK_CHECK 123 +#define TK_REFERENCES 124 +#define TK_AUTOINCR 125 +#define TK_INSERT 126 +#define TK_DELETE 127 +#define TK_UPDATE 128 +#define TK_SET 129 +#define TK_DEFERRABLE 130 +#define TK_FOREIGN 131 +#define TK_DROP 132 +#define TK_UNION 133 +#define TK_ALL 134 +#define TK_EXCEPT 135 +#define TK_INTERSECT 136 +#define TK_SELECT 137 +#define TK_VALUES 138 +#define TK_DISTINCT 139 +#define TK_DOT 140 +#define TK_FROM 141 +#define TK_JOIN 142 +#define TK_USING 143 +#define TK_ORDER 144 +#define TK_GROUP 145 +#define TK_HAVING 146 +#define TK_LIMIT 147 +#define TK_WHERE 148 +#define TK_RETURNING 149 +#define TK_INTO 150 +#define TK_NOTHING 151 +#define TK_FLOAT 152 +#define TK_BLOB 153 +#define TK_INTEGER 154 +#define TK_VARIABLE 155 +#define TK_CASE 156 +#define TK_WHEN 157 +#define TK_THEN 158 +#define TK_ELSE 159 +#define TK_INDEX 160 +#define TK_ALTER 161 +#define TK_ADD 162 +#define TK_WINDOW 163 +#define TK_OVER 164 +#define TK_FILTER 165 +#define TK_COLUMN 166 +#define TK_AGG_FUNCTION 167 +#define TK_AGG_COLUMN 168 +#define TK_TRUEFALSE 169 +#define TK_ISNOT 170 +#define TK_FUNCTION 171 +#define TK_UMINUS 172 +#define TK_UPLUS 173 +#define TK_TRUTH 174 +#define TK_REGISTER 175 +#define TK_VECTOR 176 +#define TK_SELECT_COLUMN 177 +#define TK_IF_NULL_ROW 178 +#define TK_ASTERISK 179 +#define TK_SPAN 180 +#define TK_ERROR 181 +#define TK_SPACE 182 +#define TK_ILLEGAL 183 /************** End of parse.h ***********************************************/ /************** Continuing where we left off in sqliteInt.h ******************/ #include #include @@ -14111,11 +13718,11 @@ ** The default initial allocation for the pagecache when using separate ** pagecaches for each database connection. A positive number is the ** number of pages. A negative number N translations means that a buffer ** of -1024*N bytes is allocated and used for as many pages as it will hold. ** -** The default value of "20" was chosen to minimize the run-time of the +** The default value of "20" was choosen to minimize the run-time of the ** speedtest1 test program with options: --shrink-memory --reprepare */ #ifndef SQLITE_DEFAULT_PCACHE_INITSZ # define SQLITE_DEFAULT_PCACHE_INITSZ 20 #endif @@ -14468,29 +14075,15 @@ int nBusy; /* Incremented with each busy call */ }; /* ** Name of table that holds the database schema. -** -** The PREFERRED names are used whereever possible. But LEGACY is also -** used for backwards compatibility. -** -** 1. Queries can use either the PREFERRED or the LEGACY names -** 2. The sqlite3_set_authorizer() callback uses the LEGACY name -** 3. The PRAGMA table_list statement uses the PREFERRED name -** -** The LEGACY names are stored in the internal symbol hash table -** in support of (2). Names are translated using sqlite3PreferredTableName() -** for (3). The sqlite3FindTable() function takes care of translating -** names for (1). -** -** Note that "sqlite_temp_schema" can also be called "temp.sqlite_schema". */ -#define LEGACY_SCHEMA_TABLE "sqlite_master" -#define LEGACY_TEMP_SCHEMA_TABLE "sqlite_temp_master" -#define PREFERRED_SCHEMA_TABLE "sqlite_schema" -#define PREFERRED_TEMP_SCHEMA_TABLE "sqlite_temp_schema" +#define DFLT_SCHEMA_TABLE "sqlite_master" +#define DFLT_TEMP_SCHEMA_TABLE "sqlite_temp_master" +#define ALT_SCHEMA_TABLE "sqlite_schema" +#define ALT_TEMP_SCHEMA_TABLE "sqlite_temp_schema" /* ** The root-page of the schema table. */ @@ -14498,11 +14091,11 @@ /* ** The name of the schema table. The name is different for TEMP. */ #define SCHEMA_TABLE(x) \ - ((!OMIT_TEMPDB)&&(x==1)?LEGACY_TEMP_SCHEMA_TABLE:LEGACY_SCHEMA_TABLE) + ((!OMIT_TEMPDB)&&(x==1)?DFLT_TEMP_SCHEMA_TABLE:DFLT_SCHEMA_TABLE) /* ** A convenience macro that returns the number of elements in ** an array. */ @@ -14647,15 +14240,14 @@ #define BMS ((int)(sizeof(Bitmask)*8)) /* ** A bit in a Bitmask */ -#define MASKBIT(n) (((Bitmask)1)<<(n)) -#define MASKBIT64(n) (((u64)1)<<(n)) -#define MASKBIT32(n) (((unsigned int)1)<<(n)) -#define SMASKBIT32(n) ((n)<=31?((unsigned int)1)<<(n):0) -#define ALLBITS ((Bitmask)-1) +#define MASKBIT(n) (((Bitmask)1)<<(n)) +#define MASKBIT64(n) (((u64)1)<<(n)) +#define MASKBIT32(n) (((unsigned int)1)<<(n)) +#define ALLBITS ((Bitmask)-1) /* A VList object records a mapping between parameters/variables/wildcards ** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer ** variable number associated with that parameter. See the format description ** on the sqlite3VListAdd() routine for more information. A VList is really @@ -15567,49 +15159,49 @@ #define OP_ElseEq 58 /* jump, same as TK_ESCAPE */ #define OP_IfNotZero 59 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */ #define OP_DecrJumpZero 60 /* jump, synopsis: if (--r[P1])==0 goto P2 */ #define OP_IncrVacuum 61 /* jump */ #define OP_VNext 62 /* jump */ -#define OP_Filter 63 /* jump, synopsis: if key(P3@P4) not in filter(P1) goto P2 */ -#define OP_Init 64 /* jump, synopsis: Start at P2 */ -#define OP_PureFunc 65 /* synopsis: r[P3]=func(r[P2@NP]) */ -#define OP_Function 66 /* synopsis: r[P3]=func(r[P2@NP]) */ -#define OP_Return 67 -#define OP_EndCoroutine 68 -#define OP_HaltIfNull 69 /* synopsis: if r[P3]=null halt */ -#define OP_Halt 70 -#define OP_Integer 71 /* synopsis: r[P2]=P1 */ -#define OP_Int64 72 /* synopsis: r[P2]=P4 */ -#define OP_String 73 /* synopsis: r[P2]='P4' (len=P1) */ -#define OP_Null 74 /* synopsis: r[P2..P3]=NULL */ -#define OP_SoftNull 75 /* synopsis: r[P1]=NULL */ -#define OP_Blob 76 /* synopsis: r[P2]=P4 (len=P1) */ -#define OP_Variable 77 /* synopsis: r[P2]=parameter(P1,P4) */ -#define OP_Move 78 /* synopsis: r[P2@P3]=r[P1@P3] */ -#define OP_Copy 79 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ -#define OP_SCopy 80 /* synopsis: r[P2]=r[P1] */ -#define OP_IntCopy 81 /* synopsis: r[P2]=r[P1] */ -#define OP_FkCheck 82 -#define OP_ResultRow 83 /* synopsis: output=r[P1@P2] */ -#define OP_CollSeq 84 -#define OP_AddImm 85 /* synopsis: r[P1]=r[P1]+P2 */ -#define OP_RealAffinity 86 -#define OP_Cast 87 /* synopsis: affinity(r[P1]) */ -#define OP_Permutation 88 -#define OP_Compare 89 /* synopsis: r[P1@P3] <-> r[P2@P3] */ -#define OP_IsTrue 90 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */ -#define OP_ZeroOrNull 91 /* synopsis: r[P2] = 0 OR NULL */ -#define OP_Offset 92 /* synopsis: r[P3] = sqlite_offset(P1) */ -#define OP_Column 93 /* synopsis: r[P3]=PX */ -#define OP_TypeCheck 94 /* synopsis: typecheck(r[P1@P2]) */ -#define OP_Affinity 95 /* synopsis: affinity(r[P1@P2]) */ -#define OP_MakeRecord 96 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ -#define OP_Count 97 /* synopsis: r[P2]=count() */ -#define OP_ReadCookie 98 -#define OP_SetCookie 99 -#define OP_ReopenIdx 100 /* synopsis: root=P2 iDb=P3 */ -#define OP_OpenRead 101 /* synopsis: root=P2 iDb=P3 */ +#define OP_Init 63 /* jump, synopsis: Start at P2 */ +#define OP_PureFunc 64 /* synopsis: r[P3]=func(r[P2@NP]) */ +#define OP_Function 65 /* synopsis: r[P3]=func(r[P2@NP]) */ +#define OP_Return 66 +#define OP_EndCoroutine 67 +#define OP_HaltIfNull 68 /* synopsis: if r[P3]=null halt */ +#define OP_Halt 69 +#define OP_Integer 70 /* synopsis: r[P2]=P1 */ +#define OP_Int64 71 /* synopsis: r[P2]=P4 */ +#define OP_String 72 /* synopsis: r[P2]='P4' (len=P1) */ +#define OP_Null 73 /* synopsis: r[P2..P3]=NULL */ +#define OP_SoftNull 74 /* synopsis: r[P1]=NULL */ +#define OP_Blob 75 /* synopsis: r[P2]=P4 (len=P1) */ +#define OP_Variable 76 /* synopsis: r[P2]=parameter(P1,P4) */ +#define OP_Move 77 /* synopsis: r[P2@P3]=r[P1@P3] */ +#define OP_Copy 78 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ +#define OP_SCopy 79 /* synopsis: r[P2]=r[P1] */ +#define OP_IntCopy 80 /* synopsis: r[P2]=r[P1] */ +#define OP_ChngCntRow 81 /* synopsis: output=r[P1] */ +#define OP_ResultRow 82 /* synopsis: output=r[P1@P2] */ +#define OP_CollSeq 83 +#define OP_AddImm 84 /* synopsis: r[P1]=r[P1]+P2 */ +#define OP_RealAffinity 85 +#define OP_Cast 86 /* synopsis: affinity(r[P1]) */ +#define OP_Permutation 87 +#define OP_Compare 88 /* synopsis: r[P1@P3] <-> r[P2@P3] */ +#define OP_IsTrue 89 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */ +#define OP_ZeroOrNull 90 /* synopsis: r[P2] = 0 OR NULL */ +#define OP_Offset 91 /* synopsis: r[P3] = sqlite_offset(P1) */ +#define OP_Column 92 /* synopsis: r[P3]=PX */ +#define OP_TypeCheck 93 /* synopsis: typecheck(r[P1@P2]) */ +#define OP_Affinity 94 /* synopsis: affinity(r[P1@P2]) */ +#define OP_MakeRecord 95 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ +#define OP_Count 96 /* synopsis: r[P2]=count() */ +#define OP_ReadCookie 97 +#define OP_SetCookie 98 +#define OP_ReopenIdx 99 /* synopsis: root=P2 iDb=P3 */ +#define OP_OpenRead 100 /* synopsis: root=P2 iDb=P3 */ +#define OP_OpenWrite 101 /* synopsis: root=P2 iDb=P3 */ #define OP_BitAnd 102 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */ #define OP_BitOr 103 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */ #define OP_ShiftLeft 104 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<>r[P1] */ #define OP_Add 106 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */ @@ -15616,83 +15208,80 @@ #define OP_Subtract 107 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */ #define OP_Multiply 108 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */ #define OP_Divide 109 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */ #define OP_Remainder 110 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */ #define OP_Concat 111 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */ -#define OP_OpenWrite 112 /* synopsis: root=P2 iDb=P3 */ -#define OP_OpenDup 113 -#define OP_BitNot 114 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */ -#define OP_OpenAutoindex 115 /* synopsis: nColumn=P2 */ -#define OP_OpenEphemeral 116 /* synopsis: nColumn=P2 */ -#define OP_String8 117 /* same as TK_STRING, synopsis: r[P2]='P4' */ -#define OP_SorterOpen 118 -#define OP_SequenceTest 119 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ -#define OP_OpenPseudo 120 /* synopsis: P3 columns in r[P2] */ -#define OP_Close 121 -#define OP_ColumnsUsed 122 -#define OP_SeekScan 123 /* synopsis: Scan-ahead up to P1 rows */ -#define OP_SeekHit 124 /* synopsis: set P2<=seekHit<=P3 */ -#define OP_Sequence 125 /* synopsis: r[P2]=cursor[P1].ctr++ */ -#define OP_NewRowid 126 /* synopsis: r[P2]=rowid */ -#define OP_Insert 127 /* synopsis: intkey=r[P3] data=r[P2] */ -#define OP_RowCell 128 -#define OP_Delete 129 -#define OP_ResetCount 130 -#define OP_SorterCompare 131 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ -#define OP_SorterData 132 /* synopsis: r[P2]=data */ -#define OP_RowData 133 /* synopsis: r[P2]=data */ -#define OP_Rowid 134 /* synopsis: r[P2]=rowid */ -#define OP_NullRow 135 -#define OP_SeekEnd 136 -#define OP_IdxInsert 137 /* synopsis: key=r[P2] */ -#define OP_SorterInsert 138 /* synopsis: key=r[P2] */ -#define OP_IdxDelete 139 /* synopsis: key=r[P2@P3] */ -#define OP_DeferredSeek 140 /* synopsis: Move P3 to P1.rowid if needed */ -#define OP_IdxRowid 141 /* synopsis: r[P2]=rowid */ -#define OP_FinishSeek 142 -#define OP_Destroy 143 -#define OP_Clear 144 -#define OP_ResetSorter 145 -#define OP_CreateBtree 146 /* synopsis: r[P2]=root iDb=P1 flags=P3 */ -#define OP_SqlExec 147 -#define OP_ParseSchema 148 -#define OP_LoadAnalysis 149 -#define OP_DropTable 150 -#define OP_DropIndex 151 -#define OP_DropTrigger 152 -#define OP_Real 153 /* same as TK_FLOAT, synopsis: r[P2]=P4 */ -#define OP_IntegrityCk 154 -#define OP_RowSetAdd 155 /* synopsis: rowset(P1)=r[P2] */ -#define OP_Param 156 -#define OP_FkCounter 157 /* synopsis: fkctr[P1]+=P2 */ -#define OP_MemMax 158 /* synopsis: r[P1]=max(r[P1],r[P2]) */ -#define OP_OffsetLimit 159 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ -#define OP_AggInverse 160 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */ -#define OP_AggStep 161 /* synopsis: accum=r[P3] step(r[P2@P5]) */ -#define OP_AggStep1 162 /* synopsis: accum=r[P3] step(r[P2@P5]) */ -#define OP_AggValue 163 /* synopsis: r[P3]=value N=P2 */ -#define OP_AggFinal 164 /* synopsis: accum=r[P1] N=P2 */ -#define OP_Expire 165 -#define OP_CursorLock 166 -#define OP_CursorUnlock 167 -#define OP_TableLock 168 /* synopsis: iDb=P1 root=P2 write=P3 */ -#define OP_VBegin 169 -#define OP_VCreate 170 -#define OP_VDestroy 171 -#define OP_VOpen 172 -#define OP_VInitIn 173 /* synopsis: r[P2]=ValueList(P1,P3) */ -#define OP_VColumn 174 /* synopsis: r[P3]=vcolumn(P2) */ -#define OP_VRename 175 -#define OP_Pagecount 176 -#define OP_MaxPgcnt 177 -#define OP_FilterAdd 178 /* synopsis: filter(P1) += key(P3@P4) */ -#define OP_Trace 179 -#define OP_CursorHint 180 -#define OP_ReleaseReg 181 /* synopsis: release r[P1@P2] mask P3 */ -#define OP_Noop 182 -#define OP_Explain 183 -#define OP_Abortable 184 +#define OP_OpenDup 112 +#define OP_BitNot 113 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */ +#define OP_OpenAutoindex 114 /* synopsis: nColumn=P2 */ +#define OP_OpenEphemeral 115 /* synopsis: nColumn=P2 */ +#define OP_String8 116 /* same as TK_STRING, synopsis: r[P2]='P4' */ +#define OP_SorterOpen 117 +#define OP_SequenceTest 118 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ +#define OP_OpenPseudo 119 /* synopsis: P3 columns in r[P2] */ +#define OP_Close 120 +#define OP_ColumnsUsed 121 +#define OP_SeekScan 122 /* synopsis: Scan-ahead up to P1 rows */ +#define OP_SeekHit 123 /* synopsis: set P2<=seekHit<=P3 */ +#define OP_Sequence 124 /* synopsis: r[P2]=cursor[P1].ctr++ */ +#define OP_NewRowid 125 /* synopsis: r[P2]=rowid */ +#define OP_Insert 126 /* synopsis: intkey=r[P3] data=r[P2] */ +#define OP_RowCell 127 +#define OP_Delete 128 +#define OP_ResetCount 129 +#define OP_SorterCompare 130 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ +#define OP_SorterData 131 /* synopsis: r[P2]=data */ +#define OP_RowData 132 /* synopsis: r[P2]=data */ +#define OP_Rowid 133 /* synopsis: r[P2]=rowid */ +#define OP_NullRow 134 +#define OP_SeekEnd 135 +#define OP_IdxInsert 136 /* synopsis: key=r[P2] */ +#define OP_SorterInsert 137 /* synopsis: key=r[P2] */ +#define OP_IdxDelete 138 /* synopsis: key=r[P2@P3] */ +#define OP_DeferredSeek 139 /* synopsis: Move P3 to P1.rowid if needed */ +#define OP_IdxRowid 140 /* synopsis: r[P2]=rowid */ +#define OP_FinishSeek 141 +#define OP_Destroy 142 +#define OP_Clear 143 +#define OP_ResetSorter 144 +#define OP_CreateBtree 145 /* synopsis: r[P2]=root iDb=P1 flags=P3 */ +#define OP_SqlExec 146 +#define OP_ParseSchema 147 +#define OP_LoadAnalysis 148 +#define OP_DropTable 149 +#define OP_DropIndex 150 +#define OP_DropTrigger 151 +#define OP_Real 152 /* same as TK_FLOAT, synopsis: r[P2]=P4 */ +#define OP_IntegrityCk 153 +#define OP_RowSetAdd 154 /* synopsis: rowset(P1)=r[P2] */ +#define OP_Param 155 +#define OP_FkCounter 156 /* synopsis: fkctr[P1]+=P2 */ +#define OP_MemMax 157 /* synopsis: r[P1]=max(r[P1],r[P2]) */ +#define OP_OffsetLimit 158 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ +#define OP_AggInverse 159 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */ +#define OP_AggStep 160 /* synopsis: accum=r[P3] step(r[P2@P5]) */ +#define OP_AggStep1 161 /* synopsis: accum=r[P3] step(r[P2@P5]) */ +#define OP_AggValue 162 /* synopsis: r[P3]=value N=P2 */ +#define OP_AggFinal 163 /* synopsis: accum=r[P1] N=P2 */ +#define OP_Expire 164 +#define OP_CursorLock 165 +#define OP_CursorUnlock 166 +#define OP_TableLock 167 /* synopsis: iDb=P1 root=P2 write=P3 */ +#define OP_VBegin 168 +#define OP_VCreate 169 +#define OP_VDestroy 170 +#define OP_VOpen 171 +#define OP_VColumn 172 /* synopsis: r[P3]=vcolumn(P2) */ +#define OP_VRename 173 +#define OP_Pagecount 174 +#define OP_MaxPgcnt 175 +#define OP_Trace 176 +#define OP_CursorHint 177 +#define OP_ReleaseReg 178 /* synopsis: release r[P1@P2] mask P3 */ +#define OP_Noop 179 +#define OP_Explain 180 +#define OP_Abortable 181 /* Properties such as "out2" or "jump" that are specified in ** comments following the "case" for each opcode in the vdbe.c ** are encoded into bitvectors as follows: */ @@ -15709,34 +15298,33 @@ /* 24 */ 0x09, 0x09, 0x09, 0x01, 0x09, 0x09, 0x09, 0x09,\ /* 32 */ 0x09, 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\ /* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x23, 0x0b, 0x01,\ /* 48 */ 0x01, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\ /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x01, 0x01, 0x01,\ -/* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\ -/* 72 */ 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00,\ -/* 80 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02,\ -/* 88 */ 0x00, 0x00, 0x12, 0x1e, 0x20, 0x00, 0x00, 0x00,\ -/* 96 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x26, 0x26,\ +/* 64 */ 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10,\ +/* 72 */ 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10,\ +/* 80 */ 0x10, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00,\ +/* 88 */ 0x00, 0x12, 0x1e, 0x20, 0x00, 0x00, 0x00, 0x00,\ +/* 96 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x26, 0x26,\ /* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\ -/* 112 */ 0x00, 0x00, 0x12, 0x00, 0x00, 0x10, 0x00, 0x00,\ -/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\ -/* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\ -/* 136 */ 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00, 0x10,\ -/* 144 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\ -/* 152 */ 0x00, 0x10, 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a,\ +/* 112 */ 0x00, 0x12, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,\ +/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\ +/* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,\ +/* 136 */ 0x04, 0x04, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00,\ +/* 144 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ +/* 152 */ 0x10, 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x00,\ /* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ -/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,\ -/* 176 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ -/* 184 */ 0x00,} +/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\ +/* 176 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,} /* The resolve3P2Values() routine is able to run faster if it knows ** the value of the largest JUMP opcode. The smaller the maximum ** JUMP opcode the better, so the mkopcodeh.tcl script that ** generated this include file strives to group all JUMP opcodes ** together near the beginning of the list. */ -#define SQLITE_MX_JUMP_OPCODE 64 /* Maximum JUMP opcode */ +#define SQLITE_MX_JUMP_OPCODE 63 /* Maximum JUMP opcode */ /************** End of opcodes.h *********************************************/ /************** Continuing where we left off in vdbe.h ***********************/ /* @@ -16793,11 +16381,10 @@ i64 lastRowid; /* ROWID of most recent insert (see above) */ i64 szMmap; /* Default mmap_size setting */ u32 nSchemaLock; /* Do not reset the schema when non-zero */ unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ int errCode; /* Most recent error code (SQLITE_*) */ - int errByteOffset; /* Byte offset of error in SQL statement */ int errMask; /* & result codes with this before returning */ int iSysErrno; /* Errno value from last system error */ u32 dbOptFlags; /* Flags to enable/disable optimizations */ u8 enc; /* Text encoding */ u8 autoCommit; /* The auto-commit flag. */ @@ -16833,14 +16420,14 @@ int nVdbeExec; /* Number of nested calls to VdbeExec() */ int nVDestroy; /* Number of active OP_VDestroy operations */ int nExtension; /* Number of loaded extensions */ void **aExtension; /* Array of shared library handles */ union { - void (*xLegacy)(void*,const char*); /* mTrace==SQLITE_TRACE_LEGACY */ - int (*xV2)(u32,void*,void*,void*); /* All other mTrace values */ + void (*xLegacy)(void*,const char*); /* Legacy trace function */ + int (*xV2)(u32,void*,void*,void*); /* V2 Trace function */ } trace; - void *pTraceArg; /* Argument to the trace function */ + void *pTraceArg; /* Argument to the trace function */ #ifndef SQLITE_OMIT_DEPRECATED void (*xProfile)(void*,const char*,u64); /* Profiling function */ void *pProfileArg; /* Argument to profile function */ #endif void *pCommitArg; /* Argument to xCommitCallback() */ @@ -16847,13 +16434,10 @@ int (*xCommitCallback)(void*); /* Invoked at every commit. */ void *pRollbackArg; /* Argument to xRollbackCallback() */ void (*xRollbackCallback)(void*); /* Invoked at every commit. */ void *pUpdateArg; void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64); - void *pAutovacPagesArg; /* Client argument to autovac_pages */ - void (*xAutovacDestr)(void*); /* Destructor for pAutovacPAgesArg */ - unsigned int (*xAutovacPages)(void*,const char*,u32,u32,u32); Parse *pParse; /* Current parse */ #ifdef SQLITE_ENABLE_PREUPDATE_HOOK void *pPreUpdateArg; /* First argument to xPreUpdateCallback */ void (*xPreUpdateCallback)( /* Registered using sqlite3_preupdate_hook() */ void*,sqlite3*,int,char const*,char const*,sqlite3_int64,sqlite3_int64 @@ -16979,11 +16563,10 @@ #define SQLITE_DqsDML 0x40000000 /* dbl-quoted strings allowed in DML*/ #define SQLITE_EnableView 0x80000000 /* Enable the use of views */ #define SQLITE_CountRows HI(0x00001) /* Count rows changed by INSERT, */ /* DELETE, or UPDATE and return */ /* the count using a callback. */ -#define SQLITE_CorruptRdOnly HI(0x00002) /* Prohibit writes due to error */ /* Flags used only if debugging */ #ifdef SQLITE_DEBUG #define SQLITE_SqlTrace HI(0x0100000) /* Debug print SQL as it executes */ #define SQLITE_VdbeListing HI(0x0200000) /* Debug listings of VDBE progs */ @@ -17028,13 +16611,10 @@ #define SQLITE_PropagateConst 0x00008000 /* The constant propagation opt */ #define SQLITE_MinMaxOpt 0x00010000 /* The min/max optimization */ #define SQLITE_SeekScan 0x00020000 /* The OP_SeekScan optimization */ #define SQLITE_OmitOrderBy 0x00040000 /* Omit pointless ORDER BY */ /* TH3 expects this value ^^^^^^^^^^ to be 0x40000. Coordinate any change */ -#define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filter on searches */ -#define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */ -#define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */ #define SQLITE_AllOpts 0xffffffff /* All optimizations */ /* ** Macros for testing whether or not optimizations are enabled or disabled. */ @@ -17079,11 +16659,11 @@ void (*xInverse)(sqlite3_context*,int,sqlite3_value**); /* inverse agg-step */ const char *zName; /* SQL name of the function. */ union { FuncDef *pHash; /* Next with a different name but the same hash */ FuncDestructor *pDestructor; /* Reference counted destructor function */ - } u; /* pHash if SQLITE_FUNC_BUILTIN, pDestructor otherwise */ + } u; }; /* ** This structure encapsulates a user-function destructor callback (as ** configured using create_function_v2()) and a reference counter. When @@ -17140,11 +16720,10 @@ #define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */ #define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */ #define SQLITE_FUNC_SUBTYPE 0x00100000 /* Result likely to have sub-type */ #define SQLITE_FUNC_UNSAFE 0x00200000 /* Function has side effects */ #define SQLITE_FUNC_INLINE 0x00400000 /* Functions implemented in-line */ -#define SQLITE_FUNC_BUILTIN 0x00800000 /* This is a built-in function */ #define SQLITE_FUNC_ANYORDER 0x08000000 /* count/min/max aggregate */ /* Identifier numbers for each in-line function */ #define INLINEFUNC_coalesce 0 #define INLINEFUNC_implies_nonnull_row 1 @@ -17204,11 +16783,11 @@ ** Used to create an aggregate function definition implemented by ** the C functions xStep and xFinal. The first four parameters ** are interpreted in the same way as the first 4 parameters to ** FUNCTION(). ** -** WAGGREGATE(zName, nArg, iArg, xStep, xFinal, xValue, xInverse) +** WFUNCTION(zName, nArg, iArg, xStep, xFinal, xValue, xInverse) ** Used to create an aggregate function definition implemented by ** the C functions xStep and xFinal. The first four parameters ** are interpreted in the same way as the first 4 parameters to ** FUNCTION(). ** @@ -17219,59 +16798,48 @@ ** available as the function user-data (sqlite3_user_data()). The ** FuncDef.flags variable is set to the value passed as the flags ** parameter. */ #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \ - {nArg, SQLITE_FUNC_BUILTIN|\ - SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ + {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \ - {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ + {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } #define SFUNCTION(zName, nArg, iArg, bNC, xFunc) \ - {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_DIRECTONLY|SQLITE_FUNC_UNSAFE, \ + {nArg, SQLITE_UTF8|SQLITE_DIRECTONLY|SQLITE_FUNC_UNSAFE, \ SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } #define MFUNCTION(zName, nArg, xPtr, xFunc) \ - {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \ + {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \ xPtr, 0, xFunc, 0, 0, 0, #zName, {0} } -#define JFUNCTION(zName, nArg, iArg, xFunc) \ - {nArg, SQLITE_FUNC_BUILTIN|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS|\ - SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \ - SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } #define INLINE_FUNC(zName, nArg, iArg, mFlags) \ - {nArg, SQLITE_FUNC_BUILTIN|\ - SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \ + {nArg, SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \ SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} } #define TEST_FUNC(zName, nArg, iArg, mFlags) \ - {nArg, SQLITE_FUNC_BUILTIN|\ - SQLITE_UTF8|SQLITE_FUNC_INTERNAL|SQLITE_FUNC_TEST| \ + {nArg, SQLITE_UTF8|SQLITE_FUNC_INTERNAL|SQLITE_FUNC_TEST| \ SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \ SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} } #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \ - {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \ + {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \ 0, 0, xFunc, 0, 0, 0, #zName, {0} } #define PURE_DATE(zName, nArg, iArg, bNC, xFunc) \ - {nArg, SQLITE_FUNC_BUILTIN|\ - SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \ + {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \ (void*)&sqlite3Config, 0, xFunc, 0, 0, 0, #zName, {0} } #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \ - {nArg, SQLITE_FUNC_BUILTIN|\ - SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\ + {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\ SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \ - {nArg, SQLITE_FUNC_BUILTIN|\ - SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ + {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ pArg, 0, xFunc, 0, 0, 0, #zName, } #define LIKEFUNC(zName, nArg, arg, flags) \ - {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \ + {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \ (void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} } #define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f) \ - {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \ + {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \ SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,xInverse,#zName, {0}} #define INTERNAL_FUNCTION(zName, nArg, xFunc) \ - {nArg, SQLITE_FUNC_BUILTIN|\ - SQLITE_FUNC_INTERNAL|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \ + {nArg, SQLITE_FUNC_INTERNAL|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \ 0, 0, xFunc, 0, 0, 0, #zName, {0} } /* ** All current savepoints are stored in a linked list starting at @@ -17990,14 +17558,14 @@ ** code representing the ">=" operator. This same integer code is reused ** to represent the greater-than-or-equal-to operator in the expression ** tree. ** ** If the expression is an SQL literal (TK_INTEGER, TK_FLOAT, TK_BLOB, -** or TK_STRING), then Expr.u.zToken contains the text of the SQL literal. If -** the expression is a variable (TK_VARIABLE), then Expr.u.zToken contains the +** or TK_STRING), then Expr.token contains the text of the SQL literal. If +** the expression is a variable (TK_VARIABLE), then Expr.token contains the ** variable name. Finally, if the expression is an SQL function (TK_FUNCTION), -** then Expr.u.zToken contains the name of the function. +** then Expr.token contains the name of the function. ** ** Expr.pRight and Expr.pLeft are the left and right subexpressions of a ** binary operator. Either or both may be NULL. ** ** Expr.x.pList is a list of arguments if the expression is an SQL function, @@ -18033,11 +17601,11 @@ ** ** Expr objects can use a lot of memory space in database schema. To ** help reduce memory requirements, sometimes an Expr object will be ** truncated. And to reduce the number of memory allocations, sometimes ** two or more Expr objects will be stored in a single memory allocation, -** together with Expr.u.zToken strings. +** together with Expr.zToken strings. ** ** If the EP_Reduced and EP_TokenOnly flags are set when ** an Expr object is truncated. When EP_Reduced is set, then all ** the child Expr objects in the Expr.pLeft and Expr.pRight subtrees ** are contained within the same memory allocation. Note, however, that @@ -18089,14 +17657,11 @@ ** TK_SELECT: 1st register of result vector */ ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid. ** TK_VARIABLE: variable number (always >= 1). ** TK_SELECT_COLUMN: column of the result vector */ i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */ - union { - int iRightJoinTable; /* If EP_FromJoin, the right table of the join */ - int iOfst; /* else: start of token from start of statement */ - } w; + int iRightJoinTable; /* If EP_FromJoin, the right table of the join */ AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */ union { Table *pTab; /* TK_COLUMN: Table containing column. Can be NULL ** for a column of an index on an expression */ Window *pWin; /* EP_WinFunc: Window/Filter defn for a function */ @@ -18105,11 +17670,12 @@ int regReturn; /* Register used to hold return address */ } sub; } y; }; -/* The following are the meanings of bits in the Expr.flags field. +/* +** The following are the meanings of bits in the Expr.flags field. ** Value restrictions: ** ** EP_Agg == NC_HasAgg == SF_HasAgg ** EP_Win == NC_HasWin */ @@ -18144,35 +17710,27 @@ #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */ #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */ #define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */ /* 0x80000000 // Available */ -/* The EP_Propagate mask is a set of properties that automatically propagate +/* +** The EP_Propagate mask is a set of properties that automatically propagate ** upwards into parent nodes. */ #define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc) -/* Macros can be used to test, set, or clear bits in the +/* +** These macros can be used to test, set, or clear bits in the ** Expr.flags field. */ #define ExprHasProperty(E,P) (((E)->flags&(P))!=0) #define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P)) #define ExprSetProperty(E,P) (E)->flags|=(P) #define ExprClearProperty(E,P) (E)->flags&=~(P) #define ExprAlwaysTrue(E) (((E)->flags&(EP_FromJoin|EP_IsTrue))==EP_IsTrue) #define ExprAlwaysFalse(E) (((E)->flags&(EP_FromJoin|EP_IsFalse))==EP_IsFalse) -/* Macros used to ensure that the correct members of unions are accessed -** in Expr. -*/ -#define ExprUseUToken(E) (((E)->flags&EP_IntValue)==0) -#define ExprUseUValue(E) (((E)->flags&EP_IntValue)!=0) -#define ExprUseXList(E) (((E)->flags&EP_xIsSelect)==0) -#define ExprUseXSelect(E) (((E)->flags&EP_xIsSelect)!=0) -#define ExprUseYTab(E) (((E)->flags&(EP_WinFunc|EP_Subrtn))==0) -#define ExprUseYWin(E) (((E)->flags&EP_WinFunc)!=0) -#define ExprUseYSub(E) (((E)->flags&EP_Subrtn)!=0) /* Flags for use with Expr.vvaFlags */ #define EP_NoReduce 0x01 /* Cannot EXPRDUP_REDUCE this Expr */ #define EP_Immutable 0x02 /* Do not change this Expr node */ @@ -18251,16 +17809,15 @@ unsigned done :1; /* A flag to indicate when processing is finished */ unsigned reusable :1; /* Constant expression is reusable */ unsigned bSorterRef :1; /* Defer evaluation until after sorting */ unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */ union { - struct { /* Used by any ExprList other than Parse.pConsExpr */ + struct { u16 iOrderByCol; /* For ORDER BY, column number in result set */ u16 iAlias; /* Index into Parse.aAlias[] for zName */ } x; - int iConstExprReg; /* Register in which Expr value is cached. Used only - ** by Parse.pConstExpr */ + int iConstExprReg; /* Register in which Expr value is cached */ } u; } a[1]; /* One slot for each expression in the list */ }; /* @@ -18294,17 +17851,10 @@ }; /* ** The SrcItem object represents a single term in the FROM clause of a query. ** The SrcList object is mostly an array of SrcItems. -** -** Union member validity: -** -** u1.zIndexedBy fg.isIndexedBy && !fg.isTabFunc -** u1.pFuncArg fg.isTabFunc && !fg.isIndexedBy -** u2.pIBIndex fg.isIndexedBy && !fg.isCte -** u2.pCteUse fg.isCte && !fg.isIndexedBy */ struct SrcItem { Schema *pSchema; /* Schema to which this item is fixed */ char *zDatabase; /* Name of database holding this table */ char *zName; /* Name of the table */ @@ -18832,12 +18382,11 @@ TableLock *aTableLock; /* Required table locks for shared-cache mode */ #endif AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */ Parse *pToplevel; /* Parse structure for main program (or NULL) */ Table *pTriggerTab; /* Table triggers are being coded for */ - TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */ - ParseCleanup *pCleanup; /* List of cleanup operations to run after parse */ + Parse *pParentParse; /* Parent parser if this parser is nested */ union { int addrCrTab; /* Address of OP_CreateBtree on CREATE TABLE */ Returning *pReturning; /* The RETURNING clause */ } u1; u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */ @@ -18854,11 +18403,10 @@ ** initialized as they will be set before being used. The boundary is ** determined by offsetof(Parse,aTempReg). **************************************************************************/ int aTempReg[8]; /* Holding area for temporary registers */ - Parse *pOuterParse; /* Outer Parse object when nested */ Token sNameToken; /* Token with unqualified schema object name */ /************************************************************************ ** Above is constant between recursions. Below is reset before and after ** each recursion. The boundary between these two regions is determined @@ -18889,28 +18437,27 @@ const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */ #ifndef SQLITE_OMIT_VIRTUALTABLE Token sArg; /* Complete text of a module argument */ Table **apVtabLock; /* Pointer to virtual tables needing locking */ #endif + TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */ With *pWith; /* Current WITH clause, or NULL */ + ParseCleanup *pCleanup; /* List of cleanup operations to run after parse */ #ifndef SQLITE_OMIT_ALTERTABLE RenameToken *pRename; /* Tokens subject to renaming by ALTER TABLE */ #endif }; -/* Allowed values for Parse.eParseMode -*/ #define PARSE_MODE_NORMAL 0 #define PARSE_MODE_DECLARE_VTAB 1 #define PARSE_MODE_RENAME 2 #define PARSE_MODE_UNMAP 3 /* ** Sizes and pointers of various parts of the Parse object. */ -#define PARSE_HDR(X) (((char*)(X))+offsetof(Parse,zErrMsg)) -#define PARSE_HDR_SZ (offsetof(Parse,aTempReg)-offsetof(Parse,zErrMsg)) /* Recursive part w/o aColCache*/ +#define PARSE_HDR_SZ offsetof(Parse,aTempReg) /* Recursive part w/o aColCache*/ #define PARSE_RECURSE_SZ offsetof(Parse,sLastToken) /* Recursive part */ #define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */ #define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */ /* @@ -19119,14 +18666,12 @@ } InitData; /* ** Allowed values for mInitFlags */ -#define INITFLAG_AlterMask 0x0003 /* Types of ALTER */ #define INITFLAG_AlterRename 0x0001 /* Reparse after a RENAME */ #define INITFLAG_AlterDrop 0x0002 /* Reparse after a DROP COLUMN */ -#define INITFLAG_AlterAdd 0x0003 /* Reparse after an ADD COLUMN */ /* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled ** on debug-builds of the CLI using ".testctrl tune ID VALUE". Tuning ** parameters are for temporary use during development, to help find ** optimial values for parameters in the query planner. The should not @@ -19201,11 +18746,10 @@ #endif #ifndef SQLITE_UNTESTABLE int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */ #endif int bLocaltimeFault; /* True to fail localtime() calls */ - int (*xAltLocaltime)(const void*,void*); /* Alternative localtime() routine */ int iOnceResetThreshold; /* When to reset OP_Once counters */ u32 szSorterRef; /* Min size in bytes to use sorter-refs */ unsigned int iPrngSeed; /* Alternative fixed seed for the PRNG */ /* vvvv--- must be last ---vvv */ #ifdef SQLITE_DEBUG @@ -19244,12 +18788,12 @@ union { /* Extra data for callback */ NameContext *pNC; /* Naming context */ int n; /* A counter */ int iCur; /* A cursor number */ SrcList *pSrcList; /* FROM clause */ + struct SrcCount *pSrcCount; /* Counting column references */ struct CCurHint *pCCurHint; /* Used by codeCursorHint() */ - struct RefSrcList *pRefSrcList; /* sqlite3ReferencesSrcList() */ int *aiCol; /* array of column indexes */ struct IdxCover *pIdxCover; /* Check for index coverage */ struct IdxExprTrans *pIdxTrans; /* Convert idxed expr to column */ ExprList *pGroupBy; /* GROUP BY clause */ Select *pSelect; /* HAVING to WHERE clause ctx */ @@ -19682,11 +19226,11 @@ SQLITE_PRIVATE void sqlite3Dequote(char*); SQLITE_PRIVATE void sqlite3DequoteExpr(Expr*); SQLITE_PRIVATE void sqlite3DequoteToken(Token*); SQLITE_PRIVATE void sqlite3TokenInit(Token*,char*); SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int); -SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*); +SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **); SQLITE_PRIVATE void sqlite3FinishCoding(Parse*); SQLITE_PRIVATE int sqlite3GetTempReg(Parse*); SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse*,int); SQLITE_PRIVATE int sqlite3GetTempRange(Parse*,int); SQLITE_PRIVATE void sqlite3ReleaseTempRange(Parse*,int,int); @@ -19843,16 +19387,14 @@ SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, int); SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int); #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,char*); #endif -SQLITE_PRIVATE void sqlite3CodeChangeCount(Vdbe*,int,const char*); SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*, ExprList*, Expr*); SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*,Expr*,int,ExprList*,Expr*, Upsert*); -SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*, - ExprList*,Select*,u16,int); +SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,ExprList*,u16,int); SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*); SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo*); SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*); SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*); SQLITE_PRIVATE int sqlite3WhereOrderByLimitOptLabel(WhereInfo*); @@ -19888,11 +19430,10 @@ SQLITE_PRIVATE void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int); SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*); #define LOCATE_VIEW 0x01 #define LOCATE_NOERR 0x02 SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,u32 flags,const char*, const char*); -SQLITE_PRIVATE const char *sqlite3PreferredTableName(const char*); SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,u32 flags,SrcItem *); SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*); SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*); SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*); SQLITE_PRIVATE void sqlite3Vacuum(Parse*,Token*,Expr*); @@ -19905,11 +19446,11 @@ SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int); SQLITE_PRIVATE void sqlite3AggInfoPersistWalkerInit(Walker*,Parse*); SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx); -SQLITE_PRIVATE int sqlite3ReferencesSrcList(Parse*, Expr*, SrcList*); +SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*); SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*); #ifndef SQLITE_UNTESTABLE SQLITE_PRIVATE void sqlite3PrngSaveState(void); SQLITE_PRIVATE void sqlite3PrngRestoreState(void); #endif @@ -19927,11 +19468,10 @@ SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*); SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*); SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8); SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*); SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int); -SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr*,const SrcItem*); #ifdef SQLITE_ENABLE_CURSOR_HINTS SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*); #endif SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*); SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*); @@ -19964,18 +19504,13 @@ SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3*,const IdList*); SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3*,const Select*,int); SQLITE_PRIVATE FuncDef *sqlite3FunctionSearch(int,const char*); SQLITE_PRIVATE void sqlite3InsertBuiltinFuncs(FuncDef*,int); SQLITE_PRIVATE FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,u8,u8); -SQLITE_PRIVATE void sqlite3QuoteValue(StrAccum*,sqlite3_value*); SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(void); SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void); -SQLITE_PRIVATE void sqlite3RegisterJsonFunctions(void); SQLITE_PRIVATE void sqlite3RegisterPerConnectionBuiltinFunctions(sqlite3*); -#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_JSON) -SQLITE_PRIVATE int sqlite3JsonTableFunctions(sqlite3*); -#endif SQLITE_PRIVATE int sqlite3SafetyCheckOk(sqlite3*); SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3*); SQLITE_PRIVATE void sqlite3ChangeCookie(Parse*, int); SQLITE_PRIVATE With *sqlite3WithDup(sqlite3 *db, With *p); @@ -20061,12 +19596,18 @@ #endif SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte); SQLITE_PRIVATE u32 sqlite3Utf8Read(const u8**); SQLITE_PRIVATE LogEst sqlite3LogEst(u64); SQLITE_PRIVATE LogEst sqlite3LogEstAdd(LogEst,LogEst); +#ifndef SQLITE_OMIT_VIRTUALTABLE SQLITE_PRIVATE LogEst sqlite3LogEstFromDouble(double); +#endif +#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || \ + defined(SQLITE_ENABLE_STAT4) || \ + defined(SQLITE_EXPLAIN_ESTIMATED_ROWS) SQLITE_PRIVATE u64 sqlite3LogEstToInt(LogEst); +#endif SQLITE_PRIVATE VList *sqlite3VListAdd(sqlite3*,VList*,const char*,int,int); SQLITE_PRIVATE const char *sqlite3VListNumToName(VList*,int); SQLITE_PRIVATE int sqlite3VListNameToNum(VList*,const char*,int); /* @@ -20249,24 +19790,21 @@ void (*)(sqlite3_context*), void (*)(sqlite3_context*,int,sqlite3_value **), FuncDestructor *pDestructor ); SQLITE_PRIVATE void sqlite3NoopDestructor(void*); -SQLITE_PRIVATE void *sqlite3OomFault(sqlite3*); +SQLITE_PRIVATE void sqlite3OomFault(sqlite3*); SQLITE_PRIVATE void sqlite3OomClear(sqlite3*); SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int); SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *); SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int); -SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum*, int); SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*); SQLITE_PRIVATE void sqlite3StrAccumSetError(StrAccum*, u8); SQLITE_PRIVATE void sqlite3ResultStrAccum(sqlite3_context*,StrAccum*); SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int); SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int); -SQLITE_PRIVATE void sqlite3RecordErrorByteOffset(sqlite3*,const char*); -SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3*,const Expr*); SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *); SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *); #ifndef SQLITE_OMIT_SUBQUERY @@ -20350,15 +19888,13 @@ #endif SQLITE_PRIVATE int sqlite3ReadOnlyShadowTables(sqlite3 *db); #ifndef SQLITE_OMIT_VIRTUALTABLE SQLITE_PRIVATE int sqlite3ShadowTableName(sqlite3 *db, const char *zName); SQLITE_PRIVATE int sqlite3IsShadowTableOf(sqlite3*,Table*,const char*); -SQLITE_PRIVATE void sqlite3MarkAllShadowTablesOf(sqlite3*, Table*); #else # define sqlite3ShadowTableName(A,B) 0 # define sqlite3IsShadowTableOf(A,B,C) 0 -# define sqlite3MarkAllShadowTablesOf(A,B) #endif SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*); SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3*,Module*); SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*); SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int); @@ -20367,21 +19903,15 @@ SQLITE_PRIVATE void sqlite3VtabArgExtend(Parse*, Token*); SQLITE_PRIVATE int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **); SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse*, Table*); SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3*, int, const char *); SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, VTable *); - SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*); -#if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \ - && !defined(SQLITE_OMIT_VIRTUALTABLE) -SQLITE_PRIVATE void sqlite3VtabWriteAll(sqlite3_index_info*); -#endif SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*); SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int); SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *); -SQLITE_PRIVATE void sqlite3ParseObjectInit(Parse*,sqlite3*); -SQLITE_PRIVATE void sqlite3ParseObjectReset(Parse*); +SQLITE_PRIVATE void sqlite3ParserReset(Parse*); SQLITE_PRIVATE void *sqlite3ParserAddCleanup(Parse*,void(*)(sqlite3*,void*),void*); #ifdef SQLITE_ENABLE_NORMALIZE SQLITE_PRIVATE char *sqlite3Normalize(Vdbe*, const char*); #endif SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*); @@ -20403,11 +19933,11 @@ #else # define sqlite3CteNew(P,T,E,S) ((void*)0) # define sqlite3CteDelete(D,C) # define sqlite3CteWithAdd(P,W,C) ((void*)0) # define sqlite3WithDelete(x,y) -# define sqlite3WithPush(x,y,z) ((void*)0) +# define sqlite3WithPush(x,y,z) #endif #ifndef SQLITE_OMIT_UPSERT SQLITE_PRIVATE Upsert *sqlite3UpsertNew(sqlite3*,ExprList*,Expr*,ExprList*,Expr*,Upsert*); SQLITE_PRIVATE void sqlite3UpsertDelete(sqlite3*,Upsert*); SQLITE_PRIVATE Upsert *sqlite3UpsertDup(sqlite3*,Upsert*); @@ -20436,19 +19966,17 @@ SQLITE_PRIVATE void sqlite3FkDropTable(Parse*, SrcList *, Table*); SQLITE_PRIVATE void sqlite3FkActions(Parse*, Table*, ExprList*, int, int*, int); SQLITE_PRIVATE int sqlite3FkRequired(Parse*, Table*, int*, int); SQLITE_PRIVATE u32 sqlite3FkOldmask(Parse*, Table*); SQLITE_PRIVATE FKey *sqlite3FkReferences(Table *); -SQLITE_PRIVATE void sqlite3FkClearTriggerCache(sqlite3*,int); #else #define sqlite3FkActions(a,b,c,d,e,f) #define sqlite3FkCheck(a,b,c,d,e,f) #define sqlite3FkDropTable(a,b,c) #define sqlite3FkOldmask(a,b) 0 #define sqlite3FkRequired(a,b,c,d) 0 #define sqlite3FkReferences(a) 0 - #define sqlite3FkClearTriggerCache(a,b) #endif #ifndef SQLITE_OMIT_FOREIGN_KEY SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*); SQLITE_PRIVATE int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**); #else @@ -20573,12 +20101,12 @@ ** All of this is no-op for a production build. It only comes into ** play when the SQLITE_MEMDEBUG compile-time option is used. */ #ifdef SQLITE_MEMDEBUG SQLITE_PRIVATE void sqlite3MemdebugSetType(void*,u8); -SQLITE_PRIVATE int sqlite3MemdebugHasType(const void*,u8); -SQLITE_PRIVATE int sqlite3MemdebugNoType(const void*,u8); +SQLITE_PRIVATE int sqlite3MemdebugHasType(void*,u8); +SQLITE_PRIVATE int sqlite3MemdebugNoType(void*,u8); #else # define sqlite3MemdebugSetType(X,Y) /* no-op */ # define sqlite3MemdebugHasType(X,Y) 1 # define sqlite3MemdebugNoType(X,Y) 1 #endif @@ -20810,18 +20338,10 @@ #endif /* !defined(_OS_COMMON_H_) */ /************** End of os_common.h *******************************************/ /************** Begin file ctime.c *******************************************/ -/* DO NOT EDIT! -** This file is automatically generated by the script in the canonical -** SQLite source tree at tool/mkctimec.tcl. -** -** To modify this header, edit any of the various lists in that script -** which specify categories of generated conditionals in this file. -*/ - /* ** 2010 February 23 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: @@ -20866,10 +20386,13 @@ ** only a handful of compile-time options, so most times this array is usually ** rather short and uses little memory space. */ static const char * const sqlite3azCompileOpt[] = { +/* +** BEGIN CODE GENERATED BY tool/mkctime.tcl +*/ #ifdef SQLITE_32BIT_ROWID "32BIT_ROWID", #endif #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC "4_BYTE_ALIGNED_MALLOC", @@ -21073,10 +20596,13 @@ #ifdef SQLITE_ENABLE_ICU "ENABLE_ICU", #endif #ifdef SQLITE_ENABLE_IOTRACE "ENABLE_IOTRACE", +#endif +#ifdef SQLITE_ENABLE_JSON1 + "ENABLE_JSON1", #endif #ifdef SQLITE_ENABLE_LOAD_EXTENSION "ENABLE_LOAD_EXTENSION", #endif #ifdef SQLITE_ENABLE_LOCKING_STYLE @@ -21397,13 +20923,10 @@ "OMIT_INTEGRITY_CHECK", #endif #ifdef SQLITE_OMIT_INTROSPECTION_PRAGMAS "OMIT_INTROSPECTION_PRAGMAS", #endif -#ifdef SQLITE_OMIT_JSON - "OMIT_JSON", -#endif #ifdef SQLITE_OMIT_LIKE_OPTIMIZATION "OMIT_LIKE_OPTIMIZATION", #endif #ifdef SQLITE_OMIT_LOAD_EXTENSION "OMIT_LOAD_EXTENSION", @@ -21588,12 +21111,14 @@ "WIN32_MALLOC", #endif #ifdef SQLITE_ZERO_MALLOC "ZERO_MALLOC", #endif - -} ; +/* +** END CODE GENERATED BY tool/mkctime.tcl +*/ +}; SQLITE_PRIVATE const char **sqlite3CompileOptions(int *pnOpt){ *pnOpt = sizeof(sqlite3azCompileOpt) / sizeof(sqlite3azCompileOpt[0]); return (const char**)sqlite3azCompileOpt; } @@ -21888,11 +21413,10 @@ #endif #ifndef SQLITE_UNTESTABLE 0, /* xTestCallback */ #endif 0, /* bLocaltimeFault */ - 0, /* xAltLocaltime */ 0x7ffffffe, /* iOnceResetThreshold */ SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */ 0, /* iPrngSeed */ }; @@ -21901,22 +21425,10 @@ ** database connections. After initialization, this table is ** read-only. */ SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions; -#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG) -/* -** Counter used for coverage testing. Does not come into play for -** release builds. -** -** Access to this global variable is not mutex protected. This might -** result in TSAN warnings. But as the variable does not exist in -** release builds, that should not be a concern. -*/ -SQLITE_PRIVATE unsigned int sqlite3CoverageCounter; -#endif /* SQLITE_COVERAGE_TEST || SQLITE_DEBUG */ - #ifdef VDBE_PROFILE /* ** The following performance counter can be used in place of ** sqlite3Hwtime() for profiling. This is a no-op on standard builds. */ @@ -22102,11 +21614,11 @@ ** * A one-row "pseudotable" stored in a single register */ typedef struct VdbeCursor VdbeCursor; struct VdbeCursor { u8 eCurType; /* One of the CURTYPE_* values above */ - i8 iDb; /* Index of cursor database in db->aDb[] */ + i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */ u8 nullRow; /* True if pointing to a row with no data */ u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */ u8 isTable; /* True for rowid tables. False for indexes */ #ifdef SQLITE_DEBUG u8 seekOp; /* Most recent seek operation on this cursor */ @@ -22115,15 +21627,13 @@ Bool isEphemeral:1; /* True for an ephemeral table */ Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */ Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */ Bool hasBeenDuped:1; /* This cursor was source or target of OP_OpenDup */ u16 seekHit; /* See the OP_SeekHit and OP_IfNoHope opcodes */ - union { /* pBtx for isEphermeral. pAltMap otherwise */ - Btree *pBtx; /* Separate file holding temporary table */ - u32 *aAltMap; /* Mapping from table to index column numbers */ - } ub; + Btree *pBtx; /* Separate file holding temporary table */ i64 seqCount; /* Sequence counter */ + u32 *aAltMap; /* Mapping from table to index column numbers */ /* Cached OP_Column parse information is only valid if cacheStatus matches ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that ** the cache is out of date. */ @@ -22459,11 +21969,11 @@ bft usesStmtJournal:1; /* True if uses a statement journal */ bft readOnly:1; /* True for statements that do not write */ bft bIsReader:1; /* True for statements that read */ yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */ yDbMask lockMask; /* Subset of btreeMask that requires a lock */ - u32 aCounter[9]; /* Counters used by sqlite3_stmt_status() */ + u32 aCounter[7]; /* Counters used by sqlite3_stmt_status() */ char *zSql; /* Text of the SQL statement that generated this */ #ifdef SQLITE_ENABLE_NORMALIZE char *zNormSql; /* Normalization of the associated SQL statement */ DblquoteStr *pDblStr; /* List of double-quoted string literals */ #endif @@ -22509,28 +22019,10 @@ Mem *aNew; /* Array of new.* values */ Table *pTab; /* Schema object being upated */ Index *pPk; /* PK index if pTab is WITHOUT ROWID */ }; -/* -** An instance of this object is used to pass an vector of values into -** OP_VFilter, the xFilter method of a virtual table. The vector is the -** set of values on the right-hand side of an IN constraint. -** -** The value as passed into xFilter is an sqlite3_value with a "pointer" -** type, such as is generated by sqlite3_result_pointer() and read by -** sqlite3_value_pointer. Such values have MEM_Term|MEM_Subtype|MEM_Null -** and a subtype of 'p'. The sqlite3_vtab_in_first() and _next() interfaces -** know how to use this object to step through all the values in the -** right operand of the IN constraint. -*/ -typedef struct ValueList ValueList; -struct ValueList { - BtCursor *pCsr; /* An ephemeral table holding all values */ - sqlite3_value *pOut; /* Register to hold each decoded output value */ -}; - /* ** Function prototypes */ SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...); SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*); @@ -22539,11 +22031,11 @@ SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor**, u32*); SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*); SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32); SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8); SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32); -SQLITE_PRIVATE void sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); +SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(sqlite3*, AuxData**, int, int); int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *); SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(sqlite3*,VdbeCursor*,UnpackedRecord*,int*); SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor*, i64*); @@ -22573,23 +22065,19 @@ SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem*, double); #endif SQLITE_PRIVATE void sqlite3VdbeMemSetPointer(Mem*, void*, const char*, void(*)(void*)); SQLITE_PRIVATE void sqlite3VdbeMemInit(Mem*,sqlite3*,u16); SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem*); -#ifndef SQLITE_OMIT_INCRBLOB SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem*,int); -#else -SQLITE_PRIVATE int sqlite3VdbeMemSetZeroBlob(Mem*,int); -#endif #ifdef SQLITE_DEBUG SQLITE_PRIVATE int sqlite3VdbeMemIsRowSet(const Mem*); #endif SQLITE_PRIVATE int sqlite3VdbeMemSetRowSet(Mem*); SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*); SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, u8, u8); SQLITE_PRIVATE int sqlite3IntFloatCompare(i64,double); -SQLITE_PRIVATE i64 sqlite3VdbeIntValue(const Mem*); +SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem*); SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*); SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*); SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem*, int ifNull); SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*); SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*); @@ -23563,14 +23051,12 @@ ** The following routine implements the rough equivalent of localtime_r() ** using whatever operating-system specific localtime facility that ** is available. This routine returns 0 on success and ** non-zero on any kind of error. ** -** If the sqlite3GlobalConfig.bLocaltimeFault variable is non-zero then this -** routine will always fail. If bLocaltimeFault is nonzero and -** sqlite3GlobalConfig.xAltLocaltime is not NULL, then xAltLocaltime() is -** invoked in place of the OS-defined localtime() function. +** If the sqlite3GlobalConfig.bLocaltimeFault variable is true then this +** routine will always fail. ** ** EVIDENCE-OF: R-62172-00036 In this implementation, the standard C ** library function localtime_r() is used to assist in the calculation of ** local time. */ @@ -23582,34 +23068,18 @@ sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); #endif sqlite3_mutex_enter(mutex); pX = localtime(t); #ifndef SQLITE_UNTESTABLE - if( sqlite3GlobalConfig.bLocaltimeFault ){ - if( sqlite3GlobalConfig.xAltLocaltime!=0 - && 0==sqlite3GlobalConfig.xAltLocaltime((const void*)t,(void*)pTm) - ){ - pX = pTm; - }else{ - pX = 0; - } - } + if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0; #endif if( pX ) *pTm = *pX; -#if SQLITE_THREADSAFE>0 sqlite3_mutex_leave(mutex); -#endif rc = pX==0; #else #ifndef SQLITE_UNTESTABLE - if( sqlite3GlobalConfig.bLocaltimeFault ){ - if( sqlite3GlobalConfig.xAltLocaltime!=0 ){ - return sqlite3GlobalConfig.xAltLocaltime((const void*)t,(void*)pTm); - }else{ - return 1; - } - } + if( sqlite3GlobalConfig.bLocaltimeFault ) return 1; #endif #if HAVE_LOCALTIME_R rc = localtime_r(t, pTm)==0; #else rc = localtime_s(pTm, t); @@ -23620,60 +23090,71 @@ #endif /* SQLITE_OMIT_LOCALTIME */ #ifndef SQLITE_OMIT_LOCALTIME /* -** Assuming the input DateTime is UTC, move it to its localtime equivalent. +** Compute the difference (in milliseconds) between localtime and UTC +** (a.k.a. GMT) for the time value p where p is in UTC. If no error occurs, +** return this value and set *pRc to SQLITE_OK. +** +** Or, if an error does occur, set *pRc to SQLITE_ERROR. The returned value +** is undefined in this case. */ -static int toLocaltime( - DateTime *p, /* Date at which to calculate offset */ - sqlite3_context *pCtx /* Write error here if one occurs */ +static sqlite3_int64 localtimeOffset( + DateTime *p, /* Date at which to calculate offset */ + sqlite3_context *pCtx, /* Write error here if one occurs */ + int *pRc /* OUT: Error code. SQLITE_OK or ERROR */ ){ + DateTime x, y; time_t t; struct tm sLocal; - int iYearDiff; /* Initialize the contents of sLocal to avoid a compiler warning. */ memset(&sLocal, 0, sizeof(sLocal)); - computeJD(p); - if( p->iJD<2108667600*(i64)100000 /* 1970-01-01 */ - || p->iJD>2130141456*(i64)100000 /* 2038-01-18 */ - ){ + x = *p; + computeYMD_HMS(&x); + if( x.Y<1971 || x.Y>=2038 ){ /* EVIDENCE-OF: R-55269-29598 The localtime_r() C function normally only ** works for years between 1970 and 2037. For dates outside this range, ** SQLite attempts to map the year into an equivalent year within this ** range, do the calculation, then map the year back. */ - DateTime x = *p; - computeYMD_HMS(&x); - iYearDiff = (2000 + x.Y%4) - x.Y; - x.Y += iYearDiff; - x.validJD = 0; - computeJD(&x); - t = (time_t)(x.iJD/1000 - 21086676*(i64)10000); - }else{ - iYearDiff = 0; - t = (time_t)(p->iJD/1000 - 21086676*(i64)10000); - } + x.Y = 2000; + x.M = 1; + x.D = 1; + x.h = 0; + x.m = 0; + x.s = 0.0; + } else { + int s = (int)(x.s + 0.5); + x.s = s; + } + x.tz = 0; + x.validJD = 0; + computeJD(&x); + t = (time_t)(x.iJD/1000 - 21086676*(i64)10000); if( osLocaltime(&t, &sLocal) ){ sqlite3_result_error(pCtx, "local time unavailable", -1); - return SQLITE_ERROR; - } - p->Y = sLocal.tm_year + 1900 - iYearDiff; - p->M = sLocal.tm_mon + 1; - p->D = sLocal.tm_mday; - p->h = sLocal.tm_hour; - p->m = sLocal.tm_min; - p->s = sLocal.tm_sec + (p->iJD%1000)*0.001; - p->validYMD = 1; - p->validHMS = 1; - p->validJD = 0; - p->rawS = 0; - p->validTZ = 0; - p->isError = 0; - return SQLITE_OK; + *pRc = SQLITE_ERROR; + return 0; + } + y.Y = sLocal.tm_year + 1900; + y.M = sLocal.tm_mon + 1; + y.D = sLocal.tm_mday; + y.h = sLocal.tm_hour; + y.m = sLocal.tm_min; + y.s = sLocal.tm_sec; + y.validYMD = 1; + y.validHMS = 1; + y.validJD = 0; + y.rawS = 0; + y.validTZ = 0; + y.isError = 0; + computeJD(&y); + *pRc = SQLITE_OK; + return y.iJD - x.iJD; } #endif /* SQLITE_OMIT_LOCALTIME */ /* ** The following table defines various date transformations of the form @@ -23682,21 +23163,22 @@ ** ** Where NNN is an arbitrary floating-point number and "days" can be one ** of several units of time. */ static const struct { - u8 nName; /* Length of the name */ - char zName[7]; /* Name of the transformation */ - float rLimit; /* Maximum NNN value for this transform */ - float rXform; /* Constant used for this transform */ + u8 eType; /* Transformation type code */ + u8 nName; /* Length of th name */ + char *zName; /* Name of the transformation */ + double rLimit; /* Maximum NNN value for this transform */ + double rXform; /* Constant used for this transform */ } aXformType[] = { - { 6, "second", 4.6427e+14, 1.0 }, - { 6, "minute", 7.7379e+12, 60.0 }, - { 4, "hour", 1.2897e+11, 3600.0 }, - { 3, "day", 5373485.0, 86400.0 }, - { 5, "month", 176546.0, 2592000.0 }, - { 4, "year", 14713.0, 31536000.0 }, + { 0, 6, "second", 464269060800.0, 1000.0 }, + { 0, 6, "minute", 7737817680.0, 60000.0 }, + { 0, 4, "hour", 128963628.0, 3600000.0 }, + { 0, 3, "day", 5373485.0, 86400000.0 }, + { 1, 5, "month", 176546.0, 2592000000.0 }, + { 2, 4, "year", 14713.0, 31536000000.0 }, }; /* ** Process a modifier to a date-time stamp. The modifiers are ** as follows: @@ -23723,68 +23205,26 @@ */ static int parseModifier( sqlite3_context *pCtx, /* Function context */ const char *z, /* The text of the modifier */ int n, /* Length of zMod in bytes */ - DateTime *p, /* The date/time value to be modified */ - int idx /* Parameter index of the modifier */ + DateTime *p /* The date/time value to be modified */ ){ int rc = 1; double r; switch(sqlite3UpperToLower[(u8)z[0]] ){ - case 'a': { - /* - ** auto - ** - ** If rawS is available, then interpret as a julian day number, or - ** a unix timestamp, depending on its magnitude. - */ - if( sqlite3_stricmp(z, "auto")==0 ){ - if( idx>1 ) return 1; /* IMP: R-33611-57934 */ - if( !p->rawS || p->validJD ){ - rc = 0; - p->rawS = 0; - }else if( p->s>=-21086676*(i64)10000 /* -4713-11-24 12:00:00 */ - && p->s<=(25340230*(i64)10000)+799 /* 9999-12-31 23:59:59 */ - ){ - r = p->s*1000.0 + 210866760000000.0; - clearYMD_HMS_TZ(p); - p->iJD = (sqlite3_int64)(r + 0.5); - p->validJD = 1; - p->rawS = 0; - rc = 0; - } - } - break; - } - case 'j': { - /* - ** julianday - ** - ** Always interpret the prior number as a julian-day value. If this - ** is not the first modifier, or if the prior argument is not a numeric - ** value in the allowed range of julian day numbers understood by - ** SQLite (0..5373484.5) then the result will be NULL. - */ - if( sqlite3_stricmp(z, "julianday")==0 ){ - if( idx>1 ) return 1; /* IMP: R-31176-64601 */ - if( p->validJD && p->rawS ){ - rc = 0; - p->rawS = 0; - } - } - break; - } #ifndef SQLITE_OMIT_LOCALTIME case 'l': { /* localtime ** ** Assuming the current time value is UTC (a.k.a. GMT), shift it to ** show local time. */ if( sqlite3_stricmp(z, "localtime")==0 && sqlite3NotPureFunc(pCtx) ){ - rc = toLocaltime(p, pCtx); + computeJD(p); + p->iJD += localtimeOffset(p, pCtx, &rc); + clearYMD_HMS_TZ(p); } break; } #endif case 'u': { @@ -23793,11 +23233,10 @@ ** ** Treat the current value of p->s as the number of ** seconds since 1970. Convert to a real julian day number. */ if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){ - if( idx>1 ) return 1; /* IMP: R-49255-55373 */ r = p->s*1000.0 + 210866760000000.0; if( r>=0.0 && r<464269060800000.0 ){ clearYMD_HMS_TZ(p); p->iJD = (sqlite3_int64)(r + 0.5); p->validJD = 1; @@ -23806,35 +23245,22 @@ } } #ifndef SQLITE_OMIT_LOCALTIME else if( sqlite3_stricmp(z, "utc")==0 && sqlite3NotPureFunc(pCtx) ){ if( p->tzSet==0 ){ - i64 iOrigJD; /* Original localtime */ - i64 iGuess; /* Guess at the corresponding utc time */ - int cnt = 0; /* Safety to prevent infinite loop */ - int iErr; /* Guess is off by this much */ - + sqlite3_int64 c1; computeJD(p); - iGuess = iOrigJD = p->iJD; - iErr = 0; - do{ - DateTime new; - memset(&new, 0, sizeof(new)); - iGuess -= iErr; - new.iJD = iGuess; - new.validJD = 1; - rc = toLocaltime(&new, pCtx); - if( rc ) return rc; - computeJD(&new); - iErr = new.iJD - iOrigJD; - }while( iErr && cnt++<3 ); - memset(p, 0, sizeof(*p)); - p->iJD = iGuess; - p->validJD = 1; + c1 = localtimeOffset(p, pCtx, &rc); + if( rc==SQLITE_OK ){ + p->iJD -= c1; + clearYMD_HMS_TZ(p); + p->iJD += c1 - localtimeOffset(p, pCtx, &rc); + } p->tzSet = 1; + }else{ + rc = SQLITE_OK; } - rc = SQLITE_OK; } #endif break; } case 'w': { @@ -23946,35 +23372,33 @@ for(i=0; i-aXformType[i].rLimit && rM += (int)r; x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12; p->Y += x; p->M -= x*12; p->validJD = 0; r -= (int)r; break; } - case 5: { /* Special processing to add years */ + case 2: { /* Special processing to add years */ int y = (int)r; - assert( strcmp(aXformType[i].zName,"year")==0 ); computeYMD_HMS(p); p->Y += y; p->validJD = 0; r -= (int)r; break; } } computeJD(p); - p->iJD += (sqlite3_int64)(r*1000.0*aXformType[i].rXform + rRounder); + p->iJD += (sqlite3_int64)(r*aXformType[i].rXform + rRounder); rc = 0; break; } } clearYMD_HMS_TZ(p); @@ -24020,11 +23444,11 @@ } } for(i=1; iisError || !validJulianDay(p->iJD) ) return 1; return 0; } @@ -24050,28 +23474,10 @@ computeJD(&x); sqlite3_result_double(context, x.iJD/86400000.0); } } -/* -** unixepoch( TIMESTRING, MOD, MOD, ...) -** -** Return the number of seconds (including fractional seconds) since -** the unix epoch of 1970-01-01 00:00:00 GMT. -*/ -static void unixepochFunc( - sqlite3_context *context, - int argc, - sqlite3_value **argv -){ - DateTime x; - if( isDate(context, argc, argv, &x)==0 ){ - computeJD(&x); - sqlite3_result_int64(context, x.iJD/1000 - 21086676*(i64)10000); - } -} - /* ** datetime( TIMESTRING, MOD, MOD, ...) ** ** Return YYYY-MM-DD HH:MM:SS */ @@ -24080,42 +23486,15 @@ int argc, sqlite3_value **argv ){ DateTime x; if( isDate(context, argc, argv, &x)==0 ){ - int Y, s; - char zBuf[24]; + char zBuf[100]; computeYMD_HMS(&x); - Y = x.Y; - if( Y<0 ) Y = -Y; - zBuf[1] = '0' + (Y/1000)%10; - zBuf[2] = '0' + (Y/100)%10; - zBuf[3] = '0' + (Y/10)%10; - zBuf[4] = '0' + (Y)%10; - zBuf[5] = '-'; - zBuf[6] = '0' + (x.M/10)%10; - zBuf[7] = '0' + (x.M)%10; - zBuf[8] = '-'; - zBuf[9] = '0' + (x.D/10)%10; - zBuf[10] = '0' + (x.D)%10; - zBuf[11] = ' '; - zBuf[12] = '0' + (x.h/10)%10; - zBuf[13] = '0' + (x.h)%10; - zBuf[14] = ':'; - zBuf[15] = '0' + (x.m/10)%10; - zBuf[16] = '0' + (x.m)%10; - zBuf[17] = ':'; - s = (int)x.s; - zBuf[18] = '0' + (s/10)%10; - zBuf[19] = '0' + (s)%10; - zBuf[20] = 0; - if( x.Y<0 ){ - zBuf[0] = '-'; - sqlite3_result_text(context, zBuf, 20, SQLITE_TRANSIENT); - }else{ - sqlite3_result_text(context, &zBuf[1], 19, SQLITE_TRANSIENT); - } + sqlite3_snprintf(sizeof(zBuf), zBuf, "%04d-%02d-%02d %02d:%02d:%02d", + x.Y, x.M, x.D, x.h, x.m, (int)(x.s)); + sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); } } /* ** time( TIMESTRING, MOD, MOD, ...) @@ -24127,24 +23506,14 @@ int argc, sqlite3_value **argv ){ DateTime x; if( isDate(context, argc, argv, &x)==0 ){ - int s; - char zBuf[16]; + char zBuf[100]; computeHMS(&x); - zBuf[0] = '0' + (x.h/10)%10; - zBuf[1] = '0' + (x.h)%10; - zBuf[2] = ':'; - zBuf[3] = '0' + (x.m/10)%10; - zBuf[4] = '0' + (x.m)%10; - zBuf[5] = ':'; - s = (int)x.s; - zBuf[6] = '0' + (s/10)%10; - zBuf[7] = '0' + (s)%10; - zBuf[8] = 0; - sqlite3_result_text(context, zBuf, 8, SQLITE_TRANSIENT); + sqlite3_snprintf(sizeof(zBuf), zBuf, "%02d:%02d:%02d", x.h, x.m, (int)x.s); + sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); } } /* ** date( TIMESTRING, MOD, MOD, ...) @@ -24156,32 +23525,14 @@ int argc, sqlite3_value **argv ){ DateTime x; if( isDate(context, argc, argv, &x)==0 ){ - int Y; - char zBuf[16]; + char zBuf[100]; computeYMD(&x); - Y = x.Y; - if( Y<0 ) Y = -Y; - zBuf[1] = '0' + (Y/1000)%10; - zBuf[2] = '0' + (Y/100)%10; - zBuf[3] = '0' + (Y/10)%10; - zBuf[4] = '0' + (Y)%10; - zBuf[5] = '-'; - zBuf[6] = '0' + (x.M/10)%10; - zBuf[7] = '0' + (x.M)%10; - zBuf[8] = '-'; - zBuf[9] = '0' + (x.D/10)%10; - zBuf[10] = '0' + (x.D)%10; - zBuf[11] = 0; - if( x.Y<0 ){ - zBuf[0] = '-'; - sqlite3_result_text(context, zBuf, 11, SQLITE_TRANSIENT); - }else{ - sqlite3_result_text(context, &zBuf[1], 10, SQLITE_TRANSIENT); - } + sqlite3_snprintf(sizeof(zBuf), zBuf, "%04d-%02d-%02d", x.Y, x.M, x.D); + sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); } } /* ** strftime( FORMAT, TIMESTRING, MOD, MOD, ...) @@ -24222,11 +23573,11 @@ computeJD(&x); computeYMD_HMS(&x); for(i=j=0; zFmt[i]; i++){ if( zFmt[i]!='%' ) continue; - if( jszOsFile); if( pFile ){ rc = sqlite3OsOpen(pVfs, zFile, pFile, flags, pOutFlags); if( rc!=SQLITE_OK ){ sqlite3_free(pFile); - *ppFile = 0; }else{ *ppFile = pFile; } }else{ - *ppFile = 0; rc = SQLITE_NOMEM_BKPT; } - assert( *ppFile!=0 || rc!=SQLITE_OK ); return rc; } SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *pFile){ assert( pFile ); sqlite3OsClose(pFile); @@ -25462,11 +24809,11 @@ ** Given an allocation, find the MemBlockHdr for that allocation. ** ** This routine checks the guards at either end of the allocation and ** if they are incorrect it asserts. */ -static struct MemBlockHdr *sqlite3MemsysGetHeader(const void *pAllocation){ +static struct MemBlockHdr *sqlite3MemsysGetHeader(void *pAllocation){ struct MemBlockHdr *p; int *pInt; u8 *pU8; int nReserve; @@ -25709,11 +25056,11 @@ ** This routine is designed for use within an assert() statement, to ** verify the type of an allocation. For example: ** ** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); */ -SQLITE_PRIVATE int sqlite3MemdebugHasType(const void *p, u8 eType){ +SQLITE_PRIVATE int sqlite3MemdebugHasType(void *p, u8 eType){ int rc = 1; if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){ struct MemBlockHdr *pHdr; pHdr = sqlite3MemsysGetHeader(p); assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */ @@ -25731,11 +25078,11 @@ ** This routine is designed for use within an assert() statement, to ** verify the type of an allocation. For example: ** ** assert( sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) ); */ -SQLITE_PRIVATE int sqlite3MemdebugNoType(const void *p, u8 eType){ +SQLITE_PRIVATE int sqlite3MemdebugNoType(void *p, u8 eType){ int rc = 1; if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){ struct MemBlockHdr *pHdr; pHdr = sqlite3MemsysGetHeader(p); assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */ @@ -29336,41 +28683,31 @@ /* ** Free any prior content in *pz and replace it with a copy of zNew. */ SQLITE_PRIVATE void sqlite3SetString(char **pz, sqlite3 *db, const char *zNew){ - char *z = sqlite3DbStrDup(db, zNew); sqlite3DbFree(db, *pz); - *pz = z; + *pz = sqlite3DbStrDup(db, zNew); } /* ** Call this routine to record the fact that an OOM (out-of-memory) error ** has happened. This routine will set db->mallocFailed, and also ** temporarily disable the lookaside memory allocator and interrupt ** any running VDBEs. -** -** Always return a NULL pointer so that this routine can be invoked using -** -** return sqlite3OomFault(db); -** -** and thereby avoid unnecessary stack frame allocations for the overwhelmingly -** common case where no OOM occurs. */ -SQLITE_PRIVATE void *sqlite3OomFault(sqlite3 *db){ +SQLITE_PRIVATE void sqlite3OomFault(sqlite3 *db){ if( db->mallocFailed==0 && db->bBenignMalloc==0 ){ db->mallocFailed = 1; if( db->nVdbeExec>0 ){ AtomicStore(&db->u1.isInterrupted, 1); } DisableLookaside; if( db->pParse ){ - sqlite3ErrorMsg(db->pParse, "out of memory"); db->pParse->rc = SQLITE_NOMEM_BKPT; } } - return 0; } /* ** This routine reactivates the memory allocator and clears the ** db->mallocFailed flag as necessary. @@ -30275,26 +29612,16 @@ bufpt[j] = 0; length = j; goto adjust_width_for_utf8; } case etTOKEN: { + Token *pToken; if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return; - if( flag_alternateform ){ - /* %#T means an Expr pointer that uses Expr.u.zToken */ - Expr *pExpr = va_arg(ap,Expr*); - if( ALWAYS(pExpr) && ALWAYS(!ExprHasProperty(pExpr,EP_IntValue)) ){ - sqlite3_str_appendall(pAccum, (const char*)pExpr->u.zToken); - sqlite3RecordErrorOffsetOfExpr(pAccum->db, pExpr); - } - }else{ - /* %T means a Token pointer */ - Token *pToken = va_arg(ap, Token*); - assert( bArgList==0 ); - if( pToken && pToken->n ){ - sqlite3_str_append(pAccum, (const char*)pToken->z, pToken->n); - sqlite3RecordErrorByteOffset(pAccum->db, pToken->z); - } + pToken = va_arg(ap, Token*); + assert( bArgList==0 ); + if( pToken && pToken->n ){ + sqlite3_str_append(pAccum, (const char*)pToken->z, pToken->n); } length = width = 0; break; } case etSRCITEM: { @@ -30345,54 +29672,18 @@ zExtra = 0; } }/* End for loop over the format string */ } /* End of function */ - -/* -** The z string points to the first character of a token that is -** associated with an error. If db does not already have an error -** byte offset recorded, try to compute the error byte offset for -** z and set the error byte offset in db. -*/ -SQLITE_PRIVATE void sqlite3RecordErrorByteOffset(sqlite3 *db, const char *z){ - const Parse *pParse; - const char *zText; - const char *zEnd; - assert( z!=0 ); - if( NEVER(db==0) ) return; - if( db->errByteOffset!=(-2) ) return; - pParse = db->pParse; - if( NEVER(pParse==0) ) return; - zText =pParse->zTail; - if( NEVER(zText==0) ) return; - zEnd = &zText[strlen(zText)]; - if( SQLITE_WITHIN(z,zText,zEnd) ){ - db->errByteOffset = (int)(z-zText); - } -} - -/* -** If pExpr has a byte offset for the start of a token, record that as -** as the error offset. -*/ -SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3 *db, const Expr *pExpr){ - while( pExpr && (ExprHasProperty(pExpr,EP_FromJoin) || pExpr->w.iOfst<=0) ){ - pExpr = pExpr->pLeft; - } - if( pExpr==0 ) return; - db->errByteOffset = pExpr->w.iOfst; -} - /* ** Enlarge the memory allocation on a StrAccum object so that it is ** able to accept at least N more bytes of text. ** ** Return the number of bytes of text that StrAccum is able to accept ** after the attempted enlargement. The value returned might be zero. */ -SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum *p, int N){ +static int sqlite3StrAccumEnlarge(StrAccum *p, int N){ char *zNew; assert( p->nChar+(i64)N >= p->nAlloc ); /* Only called if really needed */ if( p->accError ){ testcase(p->accError==SQLITE_TOOBIG); testcase(p->accError==SQLITE_NOMEM); @@ -31222,11 +30513,11 @@ StrAccum x; sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0); sqlite3_str_appendf(&x, " fg.af=%x.%c", pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n'); if( ExprHasProperty(pExpr, EP_FromJoin) ){ - sqlite3_str_appendf(&x, " iRJT=%d", pExpr->w.iRightJoinTable); + sqlite3_str_appendf(&x, " iRJT=%d", pExpr->iRightJoinTable); } if( ExprHasProperty(pExpr, EP_FromDDL) ){ sqlite3_str_appendf(&x, " DDL"); } if( ExprHasVVAProperty(pExpr, EP_Immutable) ){ @@ -31252,11 +30543,10 @@ zOp2[0] = 0; } sqlite3TreeViewLine(pView, "COLUMN(%d)%s%s", pExpr->iColumn, zFlgs, zOp2); }else{ - assert( ExprUseYTab(pExpr) ); sqlite3TreeViewLine(pView, "{%d:%d} pTab=%p%s", pExpr->iTable, pExpr->iColumn, pExpr->y.pTab, zFlgs); } if( ExprHasProperty(pExpr, EP_FixedCol) ){ @@ -31272,17 +30562,15 @@ } break; } #ifndef SQLITE_OMIT_FLOATING_POINT case TK_FLOAT: { - assert( !ExprHasProperty(pExpr, EP_IntValue) ); sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); break; } #endif case TK_STRING: { - assert( !ExprHasProperty(pExpr, EP_IntValue) ); sqlite3TreeViewLine(pView,"%Q", pExpr->u.zToken); break; } case TK_NULL: { sqlite3TreeViewLine(pView,"NULL"); @@ -31293,34 +30581,30 @@ sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE", zFlgs); break; } #ifndef SQLITE_OMIT_BLOB_LITERAL case TK_BLOB: { - assert( !ExprHasProperty(pExpr, EP_IntValue) ); sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); break; } #endif case TK_VARIABLE: { - assert( !ExprHasProperty(pExpr, EP_IntValue) ); sqlite3TreeViewLine(pView,"VARIABLE(%s,%d)", pExpr->u.zToken, pExpr->iColumn); break; } case TK_REGISTER: { sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable); break; } case TK_ID: { - assert( !ExprHasProperty(pExpr, EP_IntValue) ); sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken); break; } #ifndef SQLITE_OMIT_CAST case TK_CAST: { /* Expressions of the form: CAST(pLeft AS token) */ - assert( !ExprHasProperty(pExpr, EP_IntValue) ); sqlite3TreeViewLine(pView,"CAST %Q", pExpr->u.zToken); sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); break; } #endif /* SQLITE_OMIT_CAST */ @@ -31366,11 +30650,10 @@ zUniOp = azOp[x]; break; } case TK_SPAN: { - assert( !ExprHasProperty(pExpr, EP_IntValue) ); sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken); sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); break; } @@ -31378,11 +30661,10 @@ /* COLLATE operators without the EP_Collate flag are intended to ** emulate collation associated with a table column. These show ** up in the treeview output as "SOFT-COLLATE". Explicit COLLATE ** operators that appear in the original SQL always have the ** EP_Collate bit set and appear in treeview output as just "COLLATE" */ - assert( !ExprHasProperty(pExpr, EP_IntValue) ); sqlite3TreeViewLine(pView, "%sCOLLATE %Q%s", !ExprHasProperty(pExpr, EP_Collate) ? "SOFT-" : "", pExpr->u.zToken, zFlgs); sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); break; @@ -31394,19 +30676,17 @@ Window *pWin; if( ExprHasProperty(pExpr, EP_TokenOnly) ){ pFarg = 0; pWin = 0; }else{ - assert( ExprUseXList(pExpr) ); pFarg = pExpr->x.pList; #ifndef SQLITE_OMIT_WINDOWFUNC pWin = ExprHasProperty(pExpr, EP_WinFunc) ? pExpr->y.pWin : 0; #else pWin = 0; #endif } - assert( !ExprHasProperty(pExpr, EP_IntValue) ); if( pExpr->op==TK_AGG_FUNCTION ){ sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s agg=%d[%d]/%p", pExpr->op2, pExpr->u.zToken, zFlgs, pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0, pExpr->iAgg, pExpr->pAggInfo); @@ -31434,25 +30714,23 @@ #endif break; } #ifndef SQLITE_OMIT_SUBQUERY case TK_EXISTS: { - assert( ExprUseXSelect(pExpr) ); sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags); sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); break; } case TK_SELECT: { - assert( ExprUseXSelect(pExpr) ); sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags); sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); break; } case TK_IN: { sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags); sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); - if( ExprUseXSelect(pExpr) ){ + if( ExprHasProperty(pExpr, EP_xIsSelect) ){ sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); }else{ sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); } break; @@ -31469,16 +30747,13 @@ ** X is stored in pExpr->pLeft. ** Y is stored in pExpr->pList->a[0].pExpr. ** Z is stored in pExpr->pList->a[1].pExpr. */ case TK_BETWEEN: { - const Expr *pX, *pY, *pZ; - pX = pExpr->pLeft; - assert( ExprUseXList(pExpr) ); - assert( pExpr->x.pList->nExpr==2 ); - pY = pExpr->x.pList->a[0].pExpr; - pZ = pExpr->x.pList->a[1].pExpr; + Expr *pX = pExpr->pLeft; + Expr *pY = pExpr->x.pList->a[0].pExpr; + Expr *pZ = pExpr->x.pList->a[1].pExpr; sqlite3TreeViewLine(pView, "BETWEEN"); sqlite3TreeViewExpr(pView, pX, 1); sqlite3TreeViewExpr(pView, pY, 1); sqlite3TreeViewExpr(pView, pZ, 0); break; @@ -31496,11 +30771,10 @@ break; } case TK_CASE: { sqlite3TreeViewLine(pView, "CASE"); sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); - assert( ExprUseXList(pExpr) ); sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); break; } #ifndef SQLITE_OMIT_TRIGGER case TK_RAISE: { @@ -31509,11 +30783,10 @@ case OE_Rollback: zType = "rollback"; break; case OE_Abort: zType = "abort"; break; case OE_Fail: zType = "fail"; break; case OE_Ignore: zType = "ignore"; break; } - assert( !ExprHasProperty(pExpr, EP_IntValue) ); sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken); break; } #endif case TK_MATCH: { @@ -31522,20 +30795,18 @@ sqlite3TreeViewExpr(pView, pExpr->pRight, 0); break; } case TK_VECTOR: { char *z = sqlite3_mprintf("VECTOR%s",zFlgs); - assert( ExprUseXList(pExpr) ); sqlite3TreeViewBareExprList(pView, pExpr->x.pList, z); sqlite3_free(z); break; } case TK_SELECT_COLUMN: { sqlite3TreeViewLine(pView, "SELECT-COLUMN %d of [0..%d]%s", pExpr->iColumn, pExpr->iTable-1, pExpr->pRight==pExpr->pLeft ? " (SELECT-owner)" : ""); - assert( ExprUseXSelect(pExpr->pLeft) ); sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0); break; } case TK_IF_NULL_ROW: { sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable); @@ -32608,10 +31879,20 @@ /* #include */ #ifndef SQLITE_OMIT_FLOATING_POINT #include #endif +/* +** Routine needed to support the testcase() macro. +*/ +#ifdef SQLITE_COVERAGE_TEST +SQLITE_PRIVATE void sqlite3Coverage(int x){ + static unsigned dummy = 0; + dummy += (unsigned)x; +} +#endif + /* ** Calls to sqlite3FaultSim() are used to simulate a failure during testing, ** or to bypass normal error detection during testing in order to let ** execute proceed futher downstream. ** @@ -32704,25 +31985,20 @@ ** that would be appropriate. */ SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code){ assert( db!=0 ); db->errCode = err_code; - if( err_code || db->pErr ){ - sqlite3ErrorFinish(db, err_code); - }else{ - db->errByteOffset = -1; - } + if( err_code || db->pErr ) sqlite3ErrorFinish(db, err_code); } /* ** The equivalent of sqlite3Error(db, SQLITE_OK). Clear the error state ** and error message. */ SQLITE_PRIVATE void sqlite3ErrorClear(sqlite3 *db){ assert( db!=0 ); db->errCode = SQLITE_OK; - db->errByteOffset = -1; if( db->pErr ) sqlite3ValueSetNull(db->pErr); } /* ** Load the sqlite3.iSysErrno field if that is an appropriate thing @@ -32739,12 +32015,21 @@ /* ** Set the most recent error code and error string for the sqlite ** handle "db". The error code is set to "err_code". ** ** If it is not NULL, string zFormat specifies the format of the -** error string. zFormat and any string tokens that follow it are -** assumed to be encoded in UTF-8. +** error string in the style of the printf functions: The following +** format characters are allowed: +** +** %s Insert a string +** %z A string that should be freed after use +** %d Insert an integer +** %T Insert a token +** %S Insert the first element of a SrcList +** +** zFormat and any string tokens that follow it are assumed to be +** encoded in UTF-8. ** ** To clear the most recent error for sqlite handle "db", sqlite3Error ** should be called with err_code set to SQLITE_OK and zFormat set ** to NULL. */ @@ -32764,10 +32049,17 @@ } } /* ** Add an error message to pParse->zErrMsg and increment pParse->nErr. +** The following formatting characters are allowed: +** +** %s Insert a string +** %z A string that should be freed after use +** %d Insert an integer +** %T Insert a token +** %S Insert the first element of a SrcList ** ** This function should be used to report any error that occurs while ** compiling an SQL statement (i.e. within sqlite3_prepare()). The ** last thing the sqlite3_prepare() function does is copy the error ** stored by this function into the database handle using sqlite3Error(). @@ -32776,23 +32068,15 @@ */ SQLITE_PRIVATE void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){ char *zMsg; va_list ap; sqlite3 *db = pParse->db; - assert( db!=0 ); - assert( db->pParse==pParse ); - db->errByteOffset = -2; va_start(ap, zFormat); zMsg = sqlite3VMPrintf(db, zFormat, ap); va_end(ap); - if( db->errByteOffset<-1 ) db->errByteOffset = -1; if( db->suppressErr ){ sqlite3DbFree(db, zMsg); - if( db->mallocFailed ){ - pParse->nErr++; - pParse->rc = SQLITE_NOMEM; - } }else{ pParse->nErr++; sqlite3DbFree(db, pParse->zErrMsg); pParse->zErrMsg = zMsg; pParse->rc = SQLITE_ERROR; @@ -32851,11 +32135,10 @@ } } z[j] = 0; } SQLITE_PRIVATE void sqlite3DequoteExpr(Expr *p){ - assert( !ExprHasProperty(p, EP_IntValue) ); assert( sqlite3Isquote(p->u.zToken[0]) ); p->flags |= p->u.zToken[0]=='"' ? EP_Quoted|EP_DblQuoted : EP_Quoted; sqlite3Dequote(p->u.zToken); } @@ -34170,10 +33453,11 @@ #endif } return a[x&7] + y - 10; } +#ifndef SQLITE_OMIT_VIRTUALTABLE /* ** Convert a double into a LogEst ** In other words, compute an approximation for 10*log2(x). */ SQLITE_PRIVATE LogEst sqlite3LogEstFromDouble(double x){ @@ -34184,23 +33468,38 @@ if( x<=2000000000 ) return sqlite3LogEst((u64)x); memcpy(&a, &x, 8); e = (a>>52) - 1022; return e*10; } +#endif /* SQLITE_OMIT_VIRTUALTABLE */ +#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || \ + defined(SQLITE_ENABLE_STAT4) || \ + defined(SQLITE_EXPLAIN_ESTIMATED_ROWS) /* ** Convert a LogEst into an integer. +** +** Note that this routine is only used when one or more of various +** non-standard compile-time options is enabled. */ SQLITE_PRIVATE u64 sqlite3LogEstToInt(LogEst x){ u64 n; n = x%10; x /= 10; if( n>=5 ) n -= 2; else if( n>=1 ) n -= 1; +#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || \ + defined(SQLITE_EXPLAIN_ESTIMATED_ROWS) if( x>60 ) return (u64)LARGEST_INT64; +#else + /* If only SQLITE_ENABLE_STAT4 is on, then the largest input + ** possible to this routine is 310, resulting in a maximum x of 31 */ + assert( x<=60 ); +#endif return x>=3 ? (n+8)<<(x-3) : (n+8)>>(3-x); } +#endif /* defined SCANSTAT or STAT4 or ESTIMATED_ROWS */ /* ** Add a new name/number pair to a VList. This might require that the ** VList object be reallocated, so return the new VList. If an OOM ** error occurs, the original VList returned and the @@ -34650,49 +33949,49 @@ /* 58 */ "ElseEq" OpHelp(""), /* 59 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"), /* 60 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"), /* 61 */ "IncrVacuum" OpHelp(""), /* 62 */ "VNext" OpHelp(""), - /* 63 */ "Filter" OpHelp("if key(P3@P4) not in filter(P1) goto P2"), - /* 64 */ "Init" OpHelp("Start at P2"), - /* 65 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"), - /* 66 */ "Function" OpHelp("r[P3]=func(r[P2@NP])"), - /* 67 */ "Return" OpHelp(""), - /* 68 */ "EndCoroutine" OpHelp(""), - /* 69 */ "HaltIfNull" OpHelp("if r[P3]=null halt"), - /* 70 */ "Halt" OpHelp(""), - /* 71 */ "Integer" OpHelp("r[P2]=P1"), - /* 72 */ "Int64" OpHelp("r[P2]=P4"), - /* 73 */ "String" OpHelp("r[P2]='P4' (len=P1)"), - /* 74 */ "Null" OpHelp("r[P2..P3]=NULL"), - /* 75 */ "SoftNull" OpHelp("r[P1]=NULL"), - /* 76 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), - /* 77 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), - /* 78 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), - /* 79 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), - /* 80 */ "SCopy" OpHelp("r[P2]=r[P1]"), - /* 81 */ "IntCopy" OpHelp("r[P2]=r[P1]"), - /* 82 */ "FkCheck" OpHelp(""), - /* 83 */ "ResultRow" OpHelp("output=r[P1@P2]"), - /* 84 */ "CollSeq" OpHelp(""), - /* 85 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), - /* 86 */ "RealAffinity" OpHelp(""), - /* 87 */ "Cast" OpHelp("affinity(r[P1])"), - /* 88 */ "Permutation" OpHelp(""), - /* 89 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"), - /* 90 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"), - /* 91 */ "ZeroOrNull" OpHelp("r[P2] = 0 OR NULL"), - /* 92 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"), - /* 93 */ "Column" OpHelp("r[P3]=PX"), - /* 94 */ "TypeCheck" OpHelp("typecheck(r[P1@P2])"), - /* 95 */ "Affinity" OpHelp("affinity(r[P1@P2])"), - /* 96 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), - /* 97 */ "Count" OpHelp("r[P2]=count()"), - /* 98 */ "ReadCookie" OpHelp(""), - /* 99 */ "SetCookie" OpHelp(""), - /* 100 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), - /* 101 */ "OpenRead" OpHelp("root=P2 iDb=P3"), + /* 63 */ "Init" OpHelp("Start at P2"), + /* 64 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"), + /* 65 */ "Function" OpHelp("r[P3]=func(r[P2@NP])"), + /* 66 */ "Return" OpHelp(""), + /* 67 */ "EndCoroutine" OpHelp(""), + /* 68 */ "HaltIfNull" OpHelp("if r[P3]=null halt"), + /* 69 */ "Halt" OpHelp(""), + /* 70 */ "Integer" OpHelp("r[P2]=P1"), + /* 71 */ "Int64" OpHelp("r[P2]=P4"), + /* 72 */ "String" OpHelp("r[P2]='P4' (len=P1)"), + /* 73 */ "Null" OpHelp("r[P2..P3]=NULL"), + /* 74 */ "SoftNull" OpHelp("r[P1]=NULL"), + /* 75 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), + /* 76 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), + /* 77 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), + /* 78 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), + /* 79 */ "SCopy" OpHelp("r[P2]=r[P1]"), + /* 80 */ "IntCopy" OpHelp("r[P2]=r[P1]"), + /* 81 */ "ChngCntRow" OpHelp("output=r[P1]"), + /* 82 */ "ResultRow" OpHelp("output=r[P1@P2]"), + /* 83 */ "CollSeq" OpHelp(""), + /* 84 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), + /* 85 */ "RealAffinity" OpHelp(""), + /* 86 */ "Cast" OpHelp("affinity(r[P1])"), + /* 87 */ "Permutation" OpHelp(""), + /* 88 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"), + /* 89 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"), + /* 90 */ "ZeroOrNull" OpHelp("r[P2] = 0 OR NULL"), + /* 91 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"), + /* 92 */ "Column" OpHelp("r[P3]=PX"), + /* 93 */ "TypeCheck" OpHelp("typecheck(r[P1@P2])"), + /* 94 */ "Affinity" OpHelp("affinity(r[P1@P2])"), + /* 95 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), + /* 96 */ "Count" OpHelp("r[P2]=count()"), + /* 97 */ "ReadCookie" OpHelp(""), + /* 98 */ "SetCookie" OpHelp(""), + /* 99 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), + /* 100 */ "OpenRead" OpHelp("root=P2 iDb=P3"), + /* 101 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), /* 102 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"), /* 103 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"), /* 104 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<>r[P1]"), /* 106 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"), @@ -34699,83 +33998,80 @@ /* 107 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"), /* 108 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"), /* 109 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"), /* 110 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"), /* 111 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"), - /* 112 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), - /* 113 */ "OpenDup" OpHelp(""), - /* 114 */ "BitNot" OpHelp("r[P2]= ~r[P1]"), - /* 115 */ "OpenAutoindex" OpHelp("nColumn=P2"), - /* 116 */ "OpenEphemeral" OpHelp("nColumn=P2"), - /* 117 */ "String8" OpHelp("r[P2]='P4'"), - /* 118 */ "SorterOpen" OpHelp(""), - /* 119 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), - /* 120 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), - /* 121 */ "Close" OpHelp(""), - /* 122 */ "ColumnsUsed" OpHelp(""), - /* 123 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"), - /* 124 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"), - /* 125 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), - /* 126 */ "NewRowid" OpHelp("r[P2]=rowid"), - /* 127 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), - /* 128 */ "RowCell" OpHelp(""), - /* 129 */ "Delete" OpHelp(""), - /* 130 */ "ResetCount" OpHelp(""), - /* 131 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), - /* 132 */ "SorterData" OpHelp("r[P2]=data"), - /* 133 */ "RowData" OpHelp("r[P2]=data"), - /* 134 */ "Rowid" OpHelp("r[P2]=rowid"), - /* 135 */ "NullRow" OpHelp(""), - /* 136 */ "SeekEnd" OpHelp(""), - /* 137 */ "IdxInsert" OpHelp("key=r[P2]"), - /* 138 */ "SorterInsert" OpHelp("key=r[P2]"), - /* 139 */ "IdxDelete" OpHelp("key=r[P2@P3]"), - /* 140 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), - /* 141 */ "IdxRowid" OpHelp("r[P2]=rowid"), - /* 142 */ "FinishSeek" OpHelp(""), - /* 143 */ "Destroy" OpHelp(""), - /* 144 */ "Clear" OpHelp(""), - /* 145 */ "ResetSorter" OpHelp(""), - /* 146 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"), - /* 147 */ "SqlExec" OpHelp(""), - /* 148 */ "ParseSchema" OpHelp(""), - /* 149 */ "LoadAnalysis" OpHelp(""), - /* 150 */ "DropTable" OpHelp(""), - /* 151 */ "DropIndex" OpHelp(""), - /* 152 */ "DropTrigger" OpHelp(""), - /* 153 */ "Real" OpHelp("r[P2]=P4"), - /* 154 */ "IntegrityCk" OpHelp(""), - /* 155 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), - /* 156 */ "Param" OpHelp(""), - /* 157 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), - /* 158 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), - /* 159 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), - /* 160 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"), - /* 161 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), - /* 162 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"), - /* 163 */ "AggValue" OpHelp("r[P3]=value N=P2"), - /* 164 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), - /* 165 */ "Expire" OpHelp(""), - /* 166 */ "CursorLock" OpHelp(""), - /* 167 */ "CursorUnlock" OpHelp(""), - /* 168 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), - /* 169 */ "VBegin" OpHelp(""), - /* 170 */ "VCreate" OpHelp(""), - /* 171 */ "VDestroy" OpHelp(""), - /* 172 */ "VOpen" OpHelp(""), - /* 173 */ "VInitIn" OpHelp("r[P2]=ValueList(P1,P3)"), - /* 174 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), - /* 175 */ "VRename" OpHelp(""), - /* 176 */ "Pagecount" OpHelp(""), - /* 177 */ "MaxPgcnt" OpHelp(""), - /* 178 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"), - /* 179 */ "Trace" OpHelp(""), - /* 180 */ "CursorHint" OpHelp(""), - /* 181 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"), - /* 182 */ "Noop" OpHelp(""), - /* 183 */ "Explain" OpHelp(""), - /* 184 */ "Abortable" OpHelp(""), + /* 112 */ "OpenDup" OpHelp(""), + /* 113 */ "BitNot" OpHelp("r[P2]= ~r[P1]"), + /* 114 */ "OpenAutoindex" OpHelp("nColumn=P2"), + /* 115 */ "OpenEphemeral" OpHelp("nColumn=P2"), + /* 116 */ "String8" OpHelp("r[P2]='P4'"), + /* 117 */ "SorterOpen" OpHelp(""), + /* 118 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), + /* 119 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), + /* 120 */ "Close" OpHelp(""), + /* 121 */ "ColumnsUsed" OpHelp(""), + /* 122 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"), + /* 123 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"), + /* 124 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), + /* 125 */ "NewRowid" OpHelp("r[P2]=rowid"), + /* 126 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), + /* 127 */ "RowCell" OpHelp(""), + /* 128 */ "Delete" OpHelp(""), + /* 129 */ "ResetCount" OpHelp(""), + /* 130 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), + /* 131 */ "SorterData" OpHelp("r[P2]=data"), + /* 132 */ "RowData" OpHelp("r[P2]=data"), + /* 133 */ "Rowid" OpHelp("r[P2]=rowid"), + /* 134 */ "NullRow" OpHelp(""), + /* 135 */ "SeekEnd" OpHelp(""), + /* 136 */ "IdxInsert" OpHelp("key=r[P2]"), + /* 137 */ "SorterInsert" OpHelp("key=r[P2]"), + /* 138 */ "IdxDelete" OpHelp("key=r[P2@P3]"), + /* 139 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), + /* 140 */ "IdxRowid" OpHelp("r[P2]=rowid"), + /* 141 */ "FinishSeek" OpHelp(""), + /* 142 */ "Destroy" OpHelp(""), + /* 143 */ "Clear" OpHelp(""), + /* 144 */ "ResetSorter" OpHelp(""), + /* 145 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"), + /* 146 */ "SqlExec" OpHelp(""), + /* 147 */ "ParseSchema" OpHelp(""), + /* 148 */ "LoadAnalysis" OpHelp(""), + /* 149 */ "DropTable" OpHelp(""), + /* 150 */ "DropIndex" OpHelp(""), + /* 151 */ "DropTrigger" OpHelp(""), + /* 152 */ "Real" OpHelp("r[P2]=P4"), + /* 153 */ "IntegrityCk" OpHelp(""), + /* 154 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), + /* 155 */ "Param" OpHelp(""), + /* 156 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), + /* 157 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), + /* 158 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), + /* 159 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"), + /* 160 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), + /* 161 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"), + /* 162 */ "AggValue" OpHelp("r[P3]=value N=P2"), + /* 163 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), + /* 164 */ "Expire" OpHelp(""), + /* 165 */ "CursorLock" OpHelp(""), + /* 166 */ "CursorUnlock" OpHelp(""), + /* 167 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), + /* 168 */ "VBegin" OpHelp(""), + /* 169 */ "VCreate" OpHelp(""), + /* 170 */ "VDestroy" OpHelp(""), + /* 171 */ "VOpen" OpHelp(""), + /* 172 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), + /* 173 */ "VRename" OpHelp(""), + /* 174 */ "Pagecount" OpHelp(""), + /* 175 */ "MaxPgcnt" OpHelp(""), + /* 176 */ "Trace" OpHelp(""), + /* 177 */ "CursorHint" OpHelp(""), + /* 178 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"), + /* 179 */ "Noop" OpHelp(""), + /* 180 */ "Explain" OpHelp(""), + /* 181 */ "Abortable" OpHelp(""), }; return azName[i]; } #endif @@ -38732,13 +38028,11 @@ } } /* Forward declaration */ static int unixGetTempname(int nBuf, char *zBuf); -#ifndef SQLITE_OMIT_WAL - static int unixFcntlExternalReader(unixFile*, int*); -#endif +static int unixFcntlExternalReader(unixFile*, int*); /* ** Information and control of an open file handle. */ static int unixFileControl(sqlite3_file *id, int op, void *pArg){ @@ -38853,16 +38147,11 @@ return proxyFileControl(id,op,pArg); } #endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */ case SQLITE_FCNTL_EXTERNAL_READER: { -#ifndef SQLITE_OMIT_WAL return unixFcntlExternalReader((unixFile*)id, (int*)pArg); -#else - *(int*)pArg = 0; - return SQLITE_OK; -#endif } } return SQLITE_NOTFOUND; } @@ -39691,21 +38980,15 @@ int ofst, /* First lock to acquire or release */ int n, /* Number of locks to acquire or release */ int flags /* What to do with the lock */ ){ unixFile *pDbFd = (unixFile*)fd; /* Connection holding shared memory */ - unixShm *p; /* The shared memory being locked */ - unixShmNode *pShmNode; /* The underlying file iNode */ + unixShm *p = pDbFd->pShm; /* The shared memory being locked */ + unixShmNode *pShmNode = p->pShmNode; /* The underlying file iNode */ int rc = SQLITE_OK; /* Result code */ u16 mask; /* Mask of locks to take or release */ - int *aLock; - - p = pDbFd->pShm; - if( p==0 ) return SQLITE_IOERR_SHMLOCK; - pShmNode = p->pShmNode; - if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK; - aLock = pShmNode->aLock; + int *aLock = pShmNode->aLock; assert( pShmNode==pDbFd->pInode->pShmNode ); assert( pShmNode->pInode==pDbFd->pInode ); assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK ); assert( n>=1 ); @@ -40585,49 +39868,39 @@ verifyDbFile(pNew); } return rc; } -/* -** Directories to consider for temp files. -*/ -static const char *azTempDirs[] = { - 0, - 0, - "/var/tmp", - "/usr/tmp", - "/tmp", - "." -}; - -/* -** Initialize first two members of azTempDirs[] array. -*/ -static void unixTempFileInit(void){ - azTempDirs[0] = getenv("SQLITE_TMPDIR"); - azTempDirs[1] = getenv("TMPDIR"); -} - /* ** Return the name of a directory in which to put temporary files. ** If no suitable temporary file directory can be found, return NULL. */ static const char *unixTempFileDir(void){ + static const char *azDirs[] = { + 0, + 0, + "/var/tmp", + "/usr/tmp", + "/tmp", + "." + }; unsigned int i = 0; struct stat buf; const char *zDir = sqlite3_temp_directory; + if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR"); + if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR"); while(1){ if( zDir!=0 && osStat(zDir, &buf)==0 && S_ISDIR(buf.st_mode) && osAccess(zDir, 03)==0 ){ return zDir; } - if( i>=sizeof(azTempDirs)/sizeof(azTempDirs[0]) ) break; - zDir = azTempDirs[i++]; + if( i>=sizeof(azDirs)/sizeof(azDirs[0]) ) break; + zDir = azDirs[i++]; } return 0; } /* @@ -40929,15 +40202,10 @@ randomnessPid = osGetpid(0); sqlite3_randomness(0,0); } memset(p, 0, sizeof(unixFile)); -#ifdef SQLITE_ASSERT_NO_FILES - /* Applications that never read or write a persistent disk files */ - assert( zName==0 ); -#endif - if( eType==SQLITE_OPEN_MAIN_DB ){ UnixUnusedFd *pUnused; pUnused = findReusableFd(zName, flags); if( pUnused ){ fd = pUnused->fd; @@ -40994,10 +40262,12 @@ if( fd<0 ){ if( isNewJrnl && errno==EACCES && osAccess(zName, F_OK) ){ /* If unable to create a journal because the directory is not ** writable, change the error code to indicate that. */ rc = SQLITE_READONLY_DIRECTORY; + }else if( errno==EEXIST ){ + rc = SQLITE_CANTOPEN_EXISTS; }else if( errno!=EISDIR && isReadWrite ){ /* Failed to open the file for read/write access. Try read-only. */ flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE); openFlags &= ~(O_RDWR|O_CREAT); flags |= SQLITE_OPEN_READONLY; @@ -42895,13 +42165,10 @@ ** DMS UNIX_SHM_BASE+8 128 */ assert( UNIX_SHM_DMS==128 ); /* Byte offset of the deadman-switch */ #endif - /* Initialize temp file dir array. */ - unixTempFileInit(); - return SQLITE_OK; } /* ** Shutdown the operating system interface. @@ -46989,18 +46256,14 @@ int flags /* What to do with the lock */ ){ winFile *pDbFd = (winFile*)fd; /* Connection holding shared memory */ winShm *p = pDbFd->pShm; /* The shared memory being locked */ winShm *pX; /* For looping over all siblings */ - winShmNode *pShmNode; + winShmNode *pShmNode = p->pShmNode; int rc = SQLITE_OK; /* Result code */ u16 mask; /* Mask of locks to take or release */ - if( p==0 ) return SQLITE_IOERR_SHMLOCK; - pShmNode = p->pShmNode; - if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK; - assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK ); assert( n>=1 ); assert( flags==(SQLITE_SHM_LOCK | SQLITE_SHM_SHARED) || flags==(SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE) || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED) @@ -49352,11 +48615,11 @@ /* ** Try to enlarge the memory allocation to hold at least sz bytes */ static int memdbEnlarge(MemStore *p, sqlite3_int64 newSz){ unsigned char *pNew; - if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || NEVER(p->nMmap>0) ){ + if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || p->nMmap>0 ){ return SQLITE_FULL; } if( newSz>p->szMax ){ return SQLITE_FULL; } @@ -49411,13 +48674,12 @@ */ static int memdbTruncate(sqlite3_file *pFile, sqlite_int64 size){ MemStore *p = ((MemFile*)pFile)->pStore; int rc = SQLITE_OK; memdbEnter(p); - if( size>p->sz ){ - /* This can only happen with a corrupt wal mode db */ - rc = SQLITE_CORRUPT; + if( NEVER(size>p->sz) ){ + rc = SQLITE_FULL; }else{ p->sz = size; } memdbLeave(p); return rc; @@ -49552,11 +48814,11 @@ int iAmt, void **pp ){ MemStore *p = ((MemFile*)pFile)->pStore; memdbEnter(p); - if( iOfst+iAmt>p->sz || (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)!=0 ){ + if( iOfst+iAmt>p->sz ){ *pp = 0; }else{ p->nMmap++; *pp = (void*)(p->aData + iOfst); } @@ -49586,12 +48848,13 @@ int *pOutFlags ){ MemFile *pFile = (MemFile*)pFd; MemStore *p = 0; int szName; - UNUSED_PARAMETER(pVfs); - + if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){ + return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFd, flags, pOutFlags); + } memset(pFile, 0, sizeof(*pFile)); szName = sqlite3Strlen30(zName); if( szName>1 && zName[0]=='/' ){ int i; #ifndef SQLITE_MUTEX_OMIT @@ -49647,13 +48910,12 @@ memset(p, 0, sizeof(*p)); p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE; p->szMax = sqlite3GlobalConfig.mxMemdbSize; } pFile->pStore = p; - if( pOutFlags!=0 ){ - *pOutFlags = flags | SQLITE_OPEN_MEMORY; - } + assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */ + *pOutFlags = flags | SQLITE_OPEN_MEMORY; pFd->pMethods = &memdb_io_methods; memdbLeave(p); return SQLITE_OK; } @@ -50314,11 +49576,11 @@ /* NULL pBitvec tests */ sqlite3BitvecSet(0, 1); sqlite3BitvecClear(0, 1, pTmpSpace); /* Run the program */ - pc = i = 0; + pc = 0; while( (op = aOp[pc])!=0 ){ switch( op ){ case 1: case 2: case 5: { @@ -50926,12 +50188,11 @@ /* ** Make sure the page is marked as dirty. If it isn't dirty already, ** make it so. */ SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr *p){ - assert( p->nRef>0 || p->pCache->bPurgeable==0 ); - testcase( p->nRef==0 ); + assert( p->nRef>0 ); assert( sqlite3PcachePageSanity(p) ); if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ /*OPTIMIZATION-IF-FALSE*/ p->flags &= ~PGHDR_DONT_WRITE; if( p->flags & PGHDR_CLEAN ){ p->flags ^= (PGHDR_DIRTY|PGHDR_CLEAN); @@ -53845,11 +53106,10 @@ u8 walSyncFlags; /* See description above */ u8 tempFile; /* zFilename is a temporary or immutable file */ u8 noLock; /* Do not lock (except in WAL mode) */ u8 readOnly; /* True for a read-only database */ u8 memDb; /* True to inhibit all file I/O */ - u8 memVfs; /* VFS-implemented memory database */ /************************************************************************** ** The following block contains those class members that change during ** routine operation. Class members not in this block are either fixed ** when the pager is first created or else only change when there is a @@ -56059,13 +55319,10 @@ rc = pager_truncate(pPager, mxPg); if( rc!=SQLITE_OK ){ goto end_playback; } pPager->dbSize = mxPg; - if( pPager->mxPgnomxPgno = mxPg; - } } /* Copy original pages out of the journal and back into the ** database file and/or page cache. */ @@ -56243,11 +55500,10 @@ ** routine which only updates the change-counter if the update is actually ** needed, as determined by the pPager->changeCountDone state variable. */ static void pager_write_changecounter(PgHdr *pPg){ u32 change_counter; - if( NEVER(pPg==0) ) return; /* Increment the value just read and write it back to byte 24. */ change_counter = sqlite3Get4byte((u8*)pPg->pPager->dbFileVers)+1; put32bits(((char*)pPg->pData)+24, change_counter); @@ -57118,11 +56374,12 @@ ** ** a) The page number is less than or equal to the size of the ** current database image, in pages, OR ** ** b) if the page content were written at this time, it would not -** be necessary to write the current content out to the sub-journal. +** be necessary to write the current content out to the sub-journal +** (as determined by function subjRequiresPage()). ** ** If the condition asserted by this function were not true, and the ** dirty page were to be discarded from the cache via the pagerStress() ** routine, pagerStress() would not write the current page content to ** the database file. If a savepoint transaction were rolled back after @@ -57133,20 +56390,12 @@ ** database image would become corrupt. It is therefore fortunate that ** this circumstance cannot arise. */ #if defined(SQLITE_DEBUG) static void assertTruncateConstraintCb(PgHdr *pPg){ - Pager *pPager = pPg->pPager; assert( pPg->flags&PGHDR_DIRTY ); - if( pPg->pgno>pPager->dbSize ){ /* if (a) is false */ - Pgno pgno = pPg->pgno; - int i; - for(i=0; ipPager->nSavepoint; i++){ - PagerSavepoint *p = &pPager->aSavepoint[i]; - assert( p->nOrigpInSavepoint,pgno) ); - } - } + assert( !subjRequiresPage(pPg) || pPg->pgno<=pPg->pPager->dbSize ); } static void assertTruncateConstraint(Pager *pPager){ sqlite3PcacheIterateDirty(pPager->pPCache, assertTruncateConstraintCb); } #else @@ -57164,10 +56413,11 @@ ** rolled back or committed. It is not safe to call this function and ** then continue writing to the database. */ SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){ assert( pPager->dbSize>=nPage || CORRUPT_DB ); + testcase( pPager->dbSizeeState>=PAGER_WRITER_CACHEMOD ); pPager->dbSize = nPage; /* At one point the code here called assertTruncateConstraint() to ** ensure that all pages being truncated away by this operation are, @@ -58097,11 +57347,11 @@ if( zFilename && zFilename[0] ){ int fout = 0; /* VFS flags returned by xOpen() */ rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout); assert( !memDb ); #ifndef SQLITE_OMIT_DESERIALIZE - pPager->memVfs = memJM = (fout&SQLITE_OPEN_MEMORY)!=0; + memJM = (fout&SQLITE_OPEN_MEMORY)!=0; #endif readOnly = (fout&SQLITE_OPEN_READONLY)!=0; /* If the file was successfully opened for read/write access, ** choose a default page size in case we have to create the @@ -58482,11 +57732,11 @@ ** other connection managed to get in and roll it back before ** this connection obtained the exclusive lock above. Or, it ** may mean that the pager was in the error-state when this ** function was called and the journal file does not exist. */ - if( !isOpen(pPager->jfd) && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){ + if( !isOpen(pPager->jfd) ){ sqlite3_vfs * const pVfs = pPager->pVfs; int bExists; /* True if journal file exists */ rc = sqlite3OsAccess( pVfs, pPager->zJournal, SQLITE_ACCESS_EXISTS, &bExists); if( rc==SQLITE_OK && bExists ){ @@ -58884,11 +58134,10 @@ Pager *pPager, /* The pager open on the database file */ Pgno pgno, /* Page number to fetch */ DbPage **ppPage, /* Write a pointer to the page here */ int flags /* PAGER_GET_XXX flags */ ){ - /* printf("PAGE %u\n", pgno); fflush(stdout); */ return pPager->xGet(pPager, pgno, ppPage, flags); } /* ** Acquire a page if it is already in the in-memory cache. Do @@ -60035,11 +59284,11 @@ /* ** Return true if this is an in-memory or temp-file backed pager. */ SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager *pPager){ - return pPager->tempFile || pPager->memVfs; + return pPager->tempFile; } /* ** Check that there are at least nSavepoint savepoints open. If there are ** currently less than nSavepoints open, then open one or more savepoints @@ -60355,11 +59604,11 @@ */ pPg->flags &= ~PGHDR_NEED_SYNC; pPgOld = sqlite3PagerLookup(pPager, pgno); assert( !pPgOld || pPgOld->nRef==1 || CORRUPT_DB ); if( pPgOld ){ - if( NEVER(pPgOld->nRef>1) ){ + if( pPgOld->nRef>1 ){ sqlite3PagerUnrefNotNull(pPgOld); return SQLITE_CORRUPT_BKPT; } pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC); if( pPager->tempFile ){ @@ -60490,16 +59739,16 @@ */ SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *pPager, int eMode){ u8 eOld = pPager->journalMode; /* Prior journalmode */ /* The eMode parameter is always valid */ - assert( eMode==PAGER_JOURNALMODE_DELETE /* 0 */ - || eMode==PAGER_JOURNALMODE_PERSIST /* 1 */ - || eMode==PAGER_JOURNALMODE_OFF /* 2 */ - || eMode==PAGER_JOURNALMODE_TRUNCATE /* 3 */ - || eMode==PAGER_JOURNALMODE_MEMORY /* 4 */ - || eMode==PAGER_JOURNALMODE_WAL /* 5 */ ); + assert( eMode==PAGER_JOURNALMODE_DELETE + || eMode==PAGER_JOURNALMODE_TRUNCATE + || eMode==PAGER_JOURNALMODE_PERSIST + || eMode==PAGER_JOURNALMODE_OFF + || eMode==PAGER_JOURNALMODE_WAL + || eMode==PAGER_JOURNALMODE_MEMORY ); /* This routine is only called from the OP_JournalMode opcode, and ** the logic there will never allow a temporary file to be changed ** to WAL mode. */ @@ -60532,10 +59781,11 @@ assert( (PAGER_JOURNALMODE_OFF & 5)==0 ); assert( (PAGER_JOURNALMODE_WAL & 5)==5 ); assert( isOpen(pPager->fd) || pPager->exclusiveMode ); if( !pPager->exclusiveMode && (eOld & 5)==1 && (eMode & 1)==0 ){ + /* In this case we would like to delete the journal file. If it is ** not possible, then that is not a problem. Deleting the journal file ** here is an optimization only. ** ** Before deleting the journal file, obtain a RESERVED lock on the @@ -60643,22 +59893,10 @@ int eMode, /* Type of checkpoint */ int *pnLog, /* OUT: Final number of frames in log */ int *pnCkpt /* OUT: Final number of checkpointed frames */ ){ int rc = SQLITE_OK; - if( pPager->pWal==0 && pPager->journalMode==PAGER_JOURNALMODE_WAL ){ - /* This only happens when a database file is zero bytes in size opened and - ** then "PRAGMA journal_mode=WAL" is run and then sqlite3_wal_checkpoint() - ** is invoked without any intervening transactions. We need to start - ** a transaction to initialize pWal. The PRAGMA table_list statement is - ** used for this since it starts transactions on every database file, - ** including all ATTACHed databases. This seems expensive for a single - ** sqlite3_wal_checkpoint() call, but it happens very rarely. - ** https://sqlite.org/forum/forumpost/fd0f19d229156939 - */ - sqlite3_exec(db, "PRAGMA table_list",0,0,0); - } if( pPager->pWal ){ rc = sqlite3WalCheckpoint(pPager->pWal, db, eMode, (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler), pPager->pBusyHandlerArg, pPager->walSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace, @@ -61571,17 +60809,13 @@ ** If the wal-index is currently smaller the iPage pages then the size ** of the wal-index might be increased, but only if it is safe to do ** so. It is safe to enlarge the wal-index if pWal->writeLock is true ** or pWal->exclusiveMode==WAL_HEAPMEMORY_MODE. ** -** Three possible result scenarios: -** -** (1) rc==SQLITE_OK and *ppPage==Requested-Wal-Index-Page -** (2) rc>=SQLITE_ERROR and *ppPage==NULL -** (3) rc==SQLITE_OK and *ppPage==NULL // only if iPage==0 -** -** Scenario (3) can only occur when pWal->writeLock is false and iPage==0 +** If this call is successful, *ppPage is set to point to the wal-index +** page and SQLITE_OK is returned. If an error (an OOM or VFS error) occurs, +** then an SQLite error code is returned and *ppPage is set to 0. */ static SQLITE_NOINLINE int walIndexPageRealloc( Wal *pWal, /* The WAL context */ int iPage, /* The page we seek */ volatile u32 **ppPage /* Write the page pointer here */ @@ -61610,13 +60844,11 @@ if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM_BKPT; }else{ rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ, pWal->writeLock, (void volatile **)&pWal->apWiData[iPage] ); - assert( pWal->apWiData[iPage]!=0 - || rc!=SQLITE_OK - || (pWal->writeLock==0 && iPage==0) ); + assert( pWal->apWiData[iPage]!=0 || rc!=SQLITE_OK || pWal->writeLock==0 ); testcase( pWal->apWiData[iPage]==0 && rc==SQLITE_OK ); if( rc==SQLITE_OK ){ if( iPage>0 && sqlite3FaultSim(600) ) rc = SQLITE_NOMEM; }else if( (rc&0xff)==SQLITE_READONLY ){ pWal->readOnly |= WAL_SHM_RDONLY; @@ -61951,12 +61183,12 @@ ** in the wal-index file. Set pLoc->iZero to one less than the frame ** number of the first frame indexed by this hash table. If a ** slot in the hash table is set to N, it refers to frame number ** (pLoc->iZero+N) in the log. ** -** Finally, set pLoc->aPgno so that pLoc->aPgno[0] is the page number of the -** first frame indexed by the hash table, frame (pLoc->iZero). +** Finally, set pLoc->aPgno so that pLoc->aPgno[1] is the page number of the +** first frame indexed by the hash table, frame (pLoc->iZero+1). */ static int walHashGet( Wal *pWal, /* WAL handle */ int iHash, /* Find the iHash'th table */ WalHashLoc *pLoc /* OUT: Hash table location */ @@ -61964,20 +61196,19 @@ int rc; /* Return code */ rc = walIndexPage(pWal, iHash, &pLoc->aPgno); assert( rc==SQLITE_OK || iHash>0 ); - if( pLoc->aPgno ){ + if( rc==SQLITE_OK ){ pLoc->aHash = (volatile ht_slot *)&pLoc->aPgno[HASHTABLE_NPAGE]; if( iHash==0 ){ pLoc->aPgno = &pLoc->aPgno[WALINDEX_HDR_SIZE/sizeof(u32)]; pLoc->iZero = 0; }else{ pLoc->iZero = HASHTABLE_NPAGE_ONE + (iHash-1)*HASHTABLE_NPAGE; } - }else if( NEVER(rc==SQLITE_OK) ){ - rc = SQLITE_ERROR; + pLoc->aPgno = &pLoc->aPgno[-1]; } return rc; } /* @@ -62055,26 +61286,25 @@ } /* Zero the entries in the aPgno array that correspond to frames with ** frame numbers greater than pWal->hdr.mxFrame. */ - nByte = (int)((char *)sLoc.aHash - (char *)&sLoc.aPgno[iLimit]); - assert( nByte>=0 ); - memset((void *)&sLoc.aPgno[iLimit], 0, nByte); + nByte = (int)((char *)sLoc.aHash - (char *)&sLoc.aPgno[iLimit+1]); + memset((void *)&sLoc.aPgno[iLimit+1], 0, nByte); #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT /* Verify that the every entry in the mapping region is still reachable ** via the hash table even after the cleanup. */ if( iLimit ){ int j; /* Loop counter */ int iKey; /* Hash key */ - for(j=0; j=0 ); - memset((void*)sLoc.aPgno, 0, nByte); + int nByte = (int)((u8 *)&sLoc.aHash[HASHTABLE_NSLOT] + - (u8 *)&sLoc.aPgno[1]); + memset((void*)&sLoc.aPgno[1], 0, nByte); } /* If the entry in aPgno[] is already set, then the previous writer ** must have exited unexpectedly in the middle of a transaction (after ** writing one or more dirty pages to the WAL to free up memory). ** Remove the remnants of that writers uncommitted transaction from ** the hash-table before writing any new entries. */ - if( sLoc.aPgno[idx-1] ){ + if( sLoc.aPgno[idx] ){ walCleanupHash(pWal); - assert( !sLoc.aPgno[idx-1] ); + assert( !sLoc.aPgno[idx] ); } /* Write the aPgno[] array entry and the hash-table slot. */ nCollide = idx; for(iKey=walHash(iPage); sLoc.aHash[iKey]; iKey=walNextHash(iKey)){ if( (nCollide--)==0 ) return SQLITE_CORRUPT_BKPT; } - sLoc.aPgno[idx-1] = iPage; + sLoc.aPgno[idx] = iPage; AtomicStore(&sLoc.aHash[iKey], (ht_slot)idx); #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT /* Verify that the number of entries in the hash table exactly equals ** the number of entries in the mapping region. @@ -62144,21 +61374,22 @@ ** thing to check, so only do this occasionally - not on every ** iteration. */ if( (idx&0x3ff)==0 ){ int i; /* Loop counter */ - for(i=0; iapWiData[iPg] = aPrivate; for(iFrame=iFirst; iFrame<=iLast; iFrame++){ i64 iOffset = walFrameOffset(iFrame, szPage); u32 pgno; /* Database page number for frame */ @@ -62774,10 +62004,11 @@ if( rc==SQLITE_OK ){ int j; /* Counter variable */ int nEntry; /* Number of entries in this segment */ ht_slot *aIndex; /* Sorted index for this segment */ + sLoc.aPgno++; if( (i+1)==nSegment ){ nEntry = (int)(iLast - sLoc.iZero); }else{ nEntry = (int)((u32*)sLoc.aHash - (u32*)sLoc.aPgno); } @@ -63554,13 +62785,11 @@ rc = WAL_RETRY; goto begin_unreliable_shm_out; } /* Allocate a buffer to read frames into */ - assert( (pWal->szPage & (pWal->szPage-1))==0 ); - assert( pWal->szPage>=512 && pWal->szPage<=65536 ); - szFrame = pWal->szPage + WAL_FRAME_HDRSIZE; + szFrame = pWal->hdr.szPage + WAL_FRAME_HDRSIZE; aFrame = (u8 *)sqlite3_malloc64(szFrame); if( aFrame==0 ){ rc = SQLITE_NOMEM_BKPT; goto begin_unreliable_shm_out; } @@ -63570,11 +62799,11 @@ ** wal file since the heap-memory wal-index was created. If so, the ** heap-memory wal-index is discarded and WAL_RETRY returned to ** the caller. */ aSaveCksum[0] = pWal->hdr.aFrameCksum[0]; aSaveCksum[1] = pWal->hdr.aFrameCksum[1]; - for(iOffset=walFrameOffset(pWal->hdr.mxFrame+1, pWal->szPage); + for(iOffset=walFrameOffset(pWal->hdr.mxFrame+1, pWal->hdr.szPage); iOffset+szFrame<=szWal; iOffset+=szFrame ){ u32 pgno; /* Database page number for frame */ u32 nTruncate; /* dbsize field from frame header */ @@ -63914,12 +63143,11 @@ i64 iDbOff; /* Offset of db file entry */ i64 iWalOff; /* Offset of wal file entry */ rc = walHashGet(pWal, walFramePage(i), &sLoc); if( rc!=SQLITE_OK ) break; - assert( i - sLoc.iZero - 1 >=0 ); - pgno = sLoc.aPgno[i-sLoc.iZero-1]; + pgno = sLoc.aPgno[i-sLoc.iZero]; iDbOff = (i64)(pgno-1) * szPage; if( iDbOff+szPage<=szDb ){ iWalOff = walFrameOffset(i, szPage) + WAL_FRAME_HDRSIZE; rc = sqlite3OsRead(pWal->pWalFd, pBuf1, szPage, iWalOff); @@ -64148,11 +63376,11 @@ } nCollide = HASHTABLE_NSLOT; iKey = walHash(pgno); while( (iH = AtomicLoad(&sLoc.aHash[iKey]))!=0 ){ u32 iFrame = iH + sLoc.iZero; - if( iFrame<=iLast && iFrame>=pWal->minFrame && sLoc.aPgno[iH-1]==pgno ){ + if( iFrame<=iLast && iFrame>=pWal->minFrame && sLoc.aPgno[iH]==pgno ){ assert( iFrame>iRead || CORRUPT_DB ); iRead = iFrame; } if( (nCollide--)==0 ){ return SQLITE_CORRUPT_BKPT; @@ -65400,10 +64628,11 @@ ** Access to all fields of this structure is controlled by the mutex ** stored in MemPage.pBt->mutex. */ struct MemPage { u8 isInit; /* True if previously initialized. MUST BE FIRST! */ + u8 bBusy; /* Prevent endless loops on corrupt database files */ u8 intKey; /* True if table b-trees. False for index b-trees */ u8 intKeyLeaf; /* True if the leaf of an intKey table */ Pgno pgno; /* Page number for this page */ /* Only the first 8 bytes (above) are zeroed by pager.c when a new page ** is allocated. All fields that follow must be initialized before use */ @@ -65421,13 +64650,11 @@ u16 aiOvfl[4]; /* Insert the i-th overflow cell before the aiOvfl-th ** non-overflow cell */ u8 *apOvfl[4]; /* Pointers to the body of overflow cells */ BtShared *pBt; /* Pointer to BtShared that this page is part of */ u8 *aData; /* Pointer to disk image of the page data */ - u8 *aDataEnd; /* One byte past the end of the entire page - not just - ** the usable space, the entire page. Used to prevent - ** corruption-induced of buffer overflow. */ + u8 *aDataEnd; /* One byte past the end of usable data */ u8 *aCellIdx; /* The cell index area */ u8 *aDataOfst; /* Same as aData for leaves. aData+4 for interior */ DbPage *pDbPage; /* Pager page handle */ u16 (*xCellSize)(MemPage*,u8*); /* cellSizePtr method */ void (*xParseCell)(MemPage*,u8*,CellInfo*); /* btreeParseCell method */ @@ -67380,46 +66607,32 @@ /* The next block of code is equivalent to: ** ** pIter += getVarint(pIter, (u64*)&pInfo->nKey); ** - ** The code is inlined and the loop is unrolled for performance. - ** This routine is a high-runner. + ** The code is inlined to avoid a function call. */ iKey = *pIter; if( iKey>=0x80 ){ - u8 x; - iKey = ((iKey&0x7f)<<7) | ((x = *++pIter) & 0x7f); - if( x>=0x80 ){ - iKey = (iKey<<7) | ((x =*++pIter) & 0x7f); - if( x>=0x80 ){ - iKey = (iKey<<7) | ((x = *++pIter) & 0x7f); - if( x>=0x80 ){ - iKey = (iKey<<7) | ((x = *++pIter) & 0x7f); - if( x>=0x80 ){ - iKey = (iKey<<7) | ((x = *++pIter) & 0x7f); - if( x>=0x80 ){ - iKey = (iKey<<7) | ((x = *++pIter) & 0x7f); - if( x>=0x80 ){ - iKey = (iKey<<7) | ((x = *++pIter) & 0x7f); - if( x>=0x80 ){ - iKey = (iKey<<8) | (*++pIter); - } - } - } - } - } + u8 *pEnd = &pIter[7]; + iKey &= 0x7f; + while(1){ + iKey = (iKey<<7) | (*++pIter & 0x7f); + if( (*pIter)<0x80 ) break; + if( pIter>=pEnd ){ + iKey = (iKey<<8) | *++pIter; + break; } } } pIter++; pInfo->nKey = *(i64*)&iKey; pInfo->nPayload = nPayload; pInfo->pPayload = pIter; testcase( nPayload==pPage->maxLocal ); - testcase( nPayload==(u32)pPage->maxLocal+1 ); + testcase( nPayload==pPage->maxLocal+1 ); if( nPayload<=pPage->maxLocal ){ /* This is the (easy) common case where the entire payload fits ** on the local page. No overflow is required. */ pInfo->nSize = nPayload + (u16)(pIter - pCell); @@ -67452,11 +66665,11 @@ pIter++; pInfo->nKey = nPayload; pInfo->nPayload = nPayload; pInfo->pPayload = pIter; testcase( nPayload==pPage->maxLocal ); - testcase( nPayload==(u32)pPage->maxLocal+1 ); + testcase( nPayload==pPage->maxLocal+1 ); if( nPayload<=pPage->maxLocal ){ /* This is the (easy) common case where the entire payload fits ** on the local page. No overflow is required. */ pInfo->nSize = nPayload + (u16)(pIter - pCell); @@ -67515,19 +66728,19 @@ ** past the end of the key value. */ pEnd = &pIter[9]; while( (*pIter++)&0x80 && pItermaxLocal ); - testcase( nSize==(u32)pPage->maxLocal+1 ); + testcase( nSize==pPage->maxLocal+1 ); if( nSize<=pPage->maxLocal ){ nSize += (u32)(pIter - pCell); if( nSize<4 ) nSize = 4; }else{ int minLocal = pPage->minLocal; nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4); testcase( nSize==pPage->maxLocal ); - testcase( nSize==(u32)pPage->maxLocal+1 ); + testcase( nSize==pPage->maxLocal+1 ); if( nSize>pPage->maxLocal ){ nSize = minLocal; } nSize += 4 + (u16)(pIter - pCell); } @@ -67657,11 +66870,11 @@ if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage); sz2 = get2byte(&data[iFree2+2]); if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage); memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz)); sz += sz2; - }else if( NEVER(iFree+sz>usableSize) ){ + }else if( iFree+sz>usableSize ){ return SQLITE_CORRUPT_PAGE(pPage); } cbrk = top+sz; assert( cbrk+(iFree-top) <= usableSize ); @@ -67764,12 +66977,10 @@ /* Remove the slot from the free-list. Update the number of ** fragmented bytes within the page. */ memcpy(&aData[iAddr], &aData[pc], 2); aData[hdr+7] += (u8)x; - testcase( pc+x>maxPC ); - return &aData[pc]; }else if( x+pc > maxPC ){ /* This slot extends off the end of the usable part of the page */ *pRc = SQLITE_CORRUPT_PAGE(pPg); return 0; }else{ @@ -67939,11 +67150,11 @@ iPtr = iFreeBlk; } if( iFreeBlk>pPage->pBt->usableSize-4 ){ /* TH3: corrupt081.100 */ return SQLITE_CORRUPT_PAGE(pPage); } - assert( iFreeBlk>iPtr || iFreeBlk==0 || CORRUPT_DB ); + assert( iFreeBlk>iPtr || iFreeBlk==0 ); /* At this point: ** iFreeBlk: First freeblock after iStart, or zero if none ** iPtr: The address of a pointer to iFreeBlk ** @@ -68210,11 +67421,11 @@ assert( pBt->pageSize>=512 && pBt->pageSize<=65536 ); pPage->maskPage = (u16)(pBt->pageSize - 1); pPage->nOverflow = 0; pPage->cellOffset = pPage->hdrOffset + 8 + pPage->childPtrSize; pPage->aCellIdx = data + pPage->childPtrSize + 8; - pPage->aDataEnd = pPage->aData + pBt->pageSize; + pPage->aDataEnd = pPage->aData + pBt->usableSize; pPage->aDataOfst = pPage->aData + pPage->childPtrSize; /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the ** number of cells on the page. */ pPage->nCell = get2byte(&data[3]); if( pPage->nCell>MX_CELL(pBt) ){ @@ -68245,11 +67456,11 @@ unsigned char *data = pPage->aData; BtShared *pBt = pPage->pBt; u8 hdr = pPage->hdrOffset; u16 first; - assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno || CORRUPT_DB ); + assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno ); assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage ); assert( sqlite3PagerGetData(pPage->pDbPage) == data ); assert( sqlite3PagerIswriteable(pPage->pDbPage) ); assert( sqlite3_mutex_held(pBt->mutex) ); if( pBt->btsFlags & BTS_FAST_SECURE ){ @@ -68261,11 +67472,11 @@ data[hdr+7] = 0; put2byte(&data[hdr+5], pBt->usableSize); pPage->nFree = (u16)(pBt->usableSize - first); decodeFlags(pPage, flags); pPage->cellOffset = first; - pPage->aDataEnd = &data[pBt->pageSize]; + pPage->aDataEnd = &data[pBt->usableSize]; pPage->aCellIdx = &data[first]; pPage->aDataOfst = &data[pPage->childPtrSize]; pPage->nOverflow = 0; assert( pBt->pageSize>=512 && pBt->pageSize<=65536 ); pPage->maskPage = (u16)(pBt->pageSize - 1); @@ -68387,11 +67598,11 @@ rc = btreeInitPage(*ppPage); if( rc!=SQLITE_OK ){ goto getAndInitPage_error2; } } - assert( (*ppPage)->pgno==pgno || CORRUPT_DB ); + assert( (*ppPage)->pgno==pgno ); assert( (*ppPage)->aData==sqlite3PagerGetData(pDbPage) ); /* If obtaining a child page for a cursor, we must verify that the page is ** compatible with the root page. */ if( pCur && ((*ppPage)->nCell<1 || (*ppPage)->intKey!=pCur->curIntKey) ){ @@ -68864,42 +68075,34 @@ /* ** Make sure pBt->pTmpSpace points to an allocation of ** MX_CELL_SIZE(pBt) bytes with a 4-byte prefix for a left-child ** pointer. */ -static SQLITE_NOINLINE int allocateTempSpace(BtShared *pBt){ - assert( pBt!=0 ); - assert( pBt->pTmpSpace==0 ); - /* This routine is called only by btreeCursor() when allocating the - ** first write cursor for the BtShared object */ - assert( pBt->pCursor!=0 && (pBt->pCursor->curFlags & BTCF_WriteFlag)!=0 ); - pBt->pTmpSpace = sqlite3PageMalloc( pBt->pageSize ); - if( pBt->pTmpSpace==0 ){ - BtCursor *pCur = pBt->pCursor; - pBt->pCursor = pCur->pNext; /* Unlink the cursor */ - memset(pCur, 0, sizeof(*pCur)); - return SQLITE_NOMEM_BKPT; - } - - /* One of the uses of pBt->pTmpSpace is to format cells before - ** inserting them into a leaf page (function fillInCell()). If - ** a cell is less than 4 bytes in size, it is rounded up to 4 bytes - ** by the various routines that manipulate binary cells. Which - ** can mean that fillInCell() only initializes the first 2 or 3 - ** bytes of pTmpSpace, but that the first 4 bytes are copied from - ** it into a database page. This is not actually a problem, but it - ** does cause a valgrind error when the 1 or 2 bytes of unitialized - ** data is passed to system call write(). So to avoid this error, - ** zero the first 4 bytes of temp space here. - ** - ** Also: Provide four bytes of initialized space before the - ** beginning of pTmpSpace as an area available to prepend the - ** left-child pointer to the beginning of a cell. - */ - memset(pBt->pTmpSpace, 0, 8); - pBt->pTmpSpace += 4; - return SQLITE_OK; +static void allocateTempSpace(BtShared *pBt){ + if( !pBt->pTmpSpace ){ + pBt->pTmpSpace = sqlite3PageMalloc( pBt->pageSize ); + + /* One of the uses of pBt->pTmpSpace is to format cells before + ** inserting them into a leaf page (function fillInCell()). If + ** a cell is less than 4 bytes in size, it is rounded up to 4 bytes + ** by the various routines that manipulate binary cells. Which + ** can mean that fillInCell() only initializes the first 2 or 3 + ** bytes of pTmpSpace, but that the first 4 bytes are copied from + ** it into a database page. This is not actually a problem, but it + ** does cause a valgrind error when the 1 or 2 bytes of unitialized + ** data is passed to system call write(). So to avoid this error, + ** zero the first 4 bytes of temp space here. + ** + ** Also: Provide four bytes of initialized space before the + ** beginning of pTmpSpace as an area available to prepend the + ** left-child pointer to the beginning of a cell. + */ + if( pBt->pTmpSpace ){ + memset(pBt->pTmpSpace, 0, 8); + pBt->pTmpSpace += 4; + } + } } /* ** Free the pBt->pTmpSpace allocation */ @@ -69274,10 +68477,11 @@ static int lockBtree(BtShared *pBt){ int rc; /* Result code from subfunctions */ MemPage *pPage1; /* Page 1 of the database file */ u32 nPage; /* Number of pages in the database */ u32 nPageFile = 0; /* Number of pages in the database file */ + u32 nPageHeader; /* Number of pages in the database according to hdr */ assert( sqlite3_mutex_held(pBt->mutex) ); assert( pBt->pPage1==0 ); rc = sqlite3PagerSharedLock(pBt->pPager); if( rc!=SQLITE_OK ) return rc; @@ -69285,11 +68489,11 @@ if( rc!=SQLITE_OK ) return rc; /* Do some checking to help insure the file we opened really is ** a valid database file. */ - nPage = get4byte(28+(u8*)pPage1->aData); + nPage = nPageHeader = get4byte(28+(u8*)pPage1->aData); sqlite3PagerPagecount(pBt->pPager, (int*)&nPageFile); if( nPage==0 || memcmp(24+(u8*)pPage1->aData, 92+(u8*)pPage1->aData,4)!=0 ){ nPage = nPageFile; } if( (pBt->db->flags & SQLITE_ResetDatabase)!=0 ){ @@ -69392,17 +68596,13 @@ freeTempSpace(pBt); rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, pageSize-usableSize); return rc; } - if( nPage>nPageFile ){ - if( sqlite3WritableSchema(pBt->db)==0 ){ - rc = SQLITE_CORRUPT_BKPT; - goto page1_init_failed; - }else{ - nPage = nPageFile; - } + if( sqlite3WritableSchema(pBt->db)==0 && nPage>nPageFile ){ + rc = SQLITE_CORRUPT_BKPT; + goto page1_init_failed; } /* EVIDENCE-OF: R-28312-64704 However, the usable size is not allowed to ** be less than 480. In other words, if the page size is 512, then the ** reserved space size cannot exceed 32. */ if( usableSize<480 ){ @@ -70122,30 +69322,27 @@ } /* ** This routine is called prior to sqlite3PagerCommit when a transaction ** is committed for an auto-vacuum database. +** +** If SQLITE_OK is returned, then *pnTrunc is set to the number of pages +** the database file should be truncated to during the commit process. +** i.e. the database has been reorganized so that only the first *pnTrunc +** pages are in use. */ -static int autoVacuumCommit(Btree *p){ +static int autoVacuumCommit(BtShared *pBt){ int rc = SQLITE_OK; - Pager *pPager; - BtShared *pBt; - sqlite3 *db; - VVA_ONLY( int nRef ); - - assert( p!=0 ); - pBt = p->pBt; - pPager = pBt->pPager; - VVA_ONLY( nRef = sqlite3PagerRefcount(pPager); ) + Pager *pPager = pBt->pPager; + VVA_ONLY( int nRef = sqlite3PagerRefcount(pPager); ) assert( sqlite3_mutex_held(pBt->mutex) ); invalidateAllOverflowCache(pBt); assert(pBt->autoVacuum); if( !pBt->incrVacuum ){ Pgno nFin; /* Number of pages in database after autovacuuming */ Pgno nFree; /* Number of pages on the freelist initially */ - Pgno nVac; /* Number of pages to vacuum */ Pgno iFree; /* The next page to be freed */ Pgno nOrig; /* Database size before freeing */ nOrig = btreePagecount(pBt); if( PTRMAP_ISPAGE(pBt, nOrig) || nOrig==PENDING_BYTE_PAGE(pBt) ){ @@ -70155,46 +69352,22 @@ */ return SQLITE_CORRUPT_BKPT; } nFree = get4byte(&pBt->pPage1->aData[36]); - db = p->db; - if( db->xAutovacPages ){ - int iDb; - for(iDb=0; ALWAYS(iDbnDb); iDb++){ - if( db->aDb[iDb].pBt==p ) break; - } - nVac = db->xAutovacPages( - db->pAutovacPagesArg, - db->aDb[iDb].zDbSName, - nOrig, - nFree, - pBt->pageSize - ); - if( nVac>nFree ){ - nVac = nFree; - } - if( nVac==0 ){ - return SQLITE_OK; - } - }else{ - nVac = nFree; - } - nFin = finalDbSize(pBt, nOrig, nVac); + nFin = finalDbSize(pBt, nOrig, nFree); if( nFin>nOrig ) return SQLITE_CORRUPT_BKPT; if( nFinnFin && rc==SQLITE_OK; iFree--){ - rc = incrVacuumStep(pBt, nFin, iFree, nVac==nFree); + rc = incrVacuumStep(pBt, nFin, iFree, 1); } if( (rc==SQLITE_DONE || rc==SQLITE_OK) && nFree>0 ){ rc = sqlite3PagerWrite(pBt->pPage1->pDbPage); - if( nVac==nFree ){ - put4byte(&pBt->pPage1->aData[32], 0); - put4byte(&pBt->pPage1->aData[36], 0); - } + put4byte(&pBt->pPage1->aData[32], 0); + put4byte(&pBt->pPage1->aData[36], 0); put4byte(&pBt->pPage1->aData[28], nFin); pBt->bDoTruncate = 1; pBt->nPage = nFin; } if( rc!=SQLITE_OK ){ @@ -70241,11 +69414,11 @@ if( p->inTrans==TRANS_WRITE ){ BtShared *pBt = p->pBt; sqlite3BtreeEnter(p); #ifndef SQLITE_OMIT_AUTOVACUUM if( pBt->autoVacuum ){ - rc = autoVacuumCommit(p); + rc = autoVacuumCommit(pBt); if( rc!=SQLITE_OK ){ sqlite3BtreeLeave(p); return rc; } } @@ -70428,11 +69601,11 @@ */ static void btreeSetNPage(BtShared *pBt, MemPage *pPage1){ int nPage = get4byte(&pPage1->aData[28]); testcase( nPage==0 ); if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage); - testcase( pBt->nPage!=(u32)nPage ); + testcase( pBt->nPage!=nPage ); pBt->nPage = nPage; } /* ** Rollback the transaction in progress. @@ -70640,10 +69813,14 @@ assert( p->inTrans>TRANS_NONE ); assert( wrFlag==0 || p->inTrans==TRANS_WRITE ); assert( pBt->pPage1 && pBt->pPage1->aData ); assert( wrFlag==0 || (pBt->btsFlags & BTS_READ_ONLY)==0 ); + if( wrFlag ){ + allocateTempSpace(pBt); + if( pBt->pTmpSpace==0 ) return SQLITE_NOMEM_BKPT; + } if( iTable<=1 ){ if( iTable<1 ){ return SQLITE_CORRUPT_BKPT; }else if( btreePagecount(pBt)==0 ){ assert( wrFlag==0 ); @@ -70656,29 +69833,23 @@ pCur->pgnoRoot = iTable; pCur->iPage = -1; pCur->pKeyInfo = pKeyInfo; pCur->pBtree = p; pCur->pBt = pBt; - pCur->curFlags = 0; + pCur->curFlags = wrFlag ? BTCF_WriteFlag : 0; + pCur->curPagerFlags = wrFlag ? 0 : PAGER_GET_READONLY; /* If there are two or more cursors on the same btree, then all such ** cursors *must* have the BTCF_Multiple flag set. */ for(pX=pBt->pCursor; pX; pX=pX->pNext){ if( pX->pgnoRoot==iTable ){ pX->curFlags |= BTCF_Multiple; - pCur->curFlags = BTCF_Multiple; + pCur->curFlags |= BTCF_Multiple; } } - pCur->eState = CURSOR_INVALID; pCur->pNext = pBt->pCursor; pBt->pCursor = pCur; - if( wrFlag ){ - pCur->curFlags |= BTCF_WriteFlag; - pCur->curPagerFlags = 0; - if( pBt->pTmpSpace==0 ) return allocateTempSpace(pBt); - }else{ - pCur->curPagerFlags = PAGER_GET_READONLY; - } + pCur->eState = CURSOR_INVALID; return SQLITE_OK; } static int btreeCursorWithLock( Btree *p, /* The btree */ Pgno iTable, /* Root page of table to open */ @@ -71048,13 +70219,11 @@ #endif assert( pPage ); assert( eOp==0 || eOp==1 ); assert( pCur->eState==CURSOR_VALID ); - if( pCur->ix>=pPage->nCell ){ - return SQLITE_CORRUPT_PAGE(pPage); - } + assert( pCur->ixnCell ); assert( cursorHoldsMutex(pCur) ); getCellInfo(pCur); aPayload = pCur->info.pPayload; assert( offset+amt <= pCur->info.nPayload ); @@ -71237,10 +70406,11 @@ */ SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){ assert( cursorHoldsMutex(pCur) ); assert( pCur->eState==CURSOR_VALID ); assert( pCur->iPage>=0 && pCur->pPage ); + assert( pCur->ixpPage->nCell ); return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0); } /* ** This variant of sqlite3BtreePayload() works even if the cursor has not @@ -71298,11 +70468,11 @@ int amt; assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage); assert( pCur->eState==CURSOR_VALID ); assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); assert( cursorOwnsBtShared(pCur) ); - assert( pCur->ixpPage->nCell || CORRUPT_DB ); + assert( pCur->ixpPage->nCell ); assert( pCur->info.nSize>0 ); assert( pCur->info.pPayload>pCur->pPage->aData || CORRUPT_DB ); assert( pCur->info.pPayloadpPage->aDataEnd ||CORRUPT_DB); amt = pCur->info.nLocal; if( amt>(int)(pCur->pPage->aDataEnd - pCur->info.pPayload) ){ @@ -71449,11 +70619,11 @@ if( pCur->iPage ){ releasePageNotNull(pCur->pPage); while( --pCur->iPage ){ releasePageNotNull(pCur->apPage[pCur->iPage]); } - pRoot = pCur->pPage = pCur->apPage[0]; + pCur->pPage = pCur->apPage[0]; goto skip_init; } }else if( pCur->pgnoRoot==0 ){ pCur->eState = CURSOR_INVALID; return SQLITE_EMPTY; @@ -71474,11 +70644,11 @@ } pCur->iPage = 0; pCur->curIntKey = pCur->pPage->intKey; } pRoot = pCur->pPage; - assert( pRoot->pgno==pCur->pgnoRoot || CORRUPT_DB ); + assert( pRoot->pgno==pCur->pgnoRoot ); /* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor ** expected to open it on an index b-tree. Otherwise, if pKeyInfo is ** NULL, the caller expects a table b-tree. If this is not the case, ** return an SQLITE_CORRUPT error. @@ -71496,10 +70666,11 @@ skip_init: pCur->ix = 0; pCur->info.nSize = 0; pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidNKey|BTCF_ValidOvfl); + pRoot = pCur->pPage; if( pRoot->nCell>0 ){ pCur->eState = CURSOR_VALID; }else if( !pRoot->leaf ){ Pgno subpage; if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT; @@ -71736,10 +70907,11 @@ assert( pPage->intKey ); lwr = 0; upr = pPage->nCell-1; assert( biasRight==0 || biasRight==1 ); idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */ + pCur->ix = (u16)idx; for(;;){ i64 nCellKey; pCell = findCellPastPtr(pPage, idx); if( pPage->intKeyLeaf ){ while( 0x80 <= *(pCell++) ){ @@ -71877,10 +71049,11 @@ assert( pPage->nCell>0 ); assert( pPage->intKey==(pIdxKey==0) ); lwr = 0; upr = pPage->nCell-1; idx = upr>>1; /* idx = (lwr+upr)/2; */ + pCur->ix = (u16)idx; for(;;){ int nCell; /* Size of the pCell cell in bytes */ pCell = findCellPastPtr(pPage, idx); /* The maximum supported page-size is 65536 bytes. This means that @@ -71965,11 +71138,11 @@ idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2 */ } assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) ); assert( pPage->isInit ); if( pPage->leaf ){ - assert( pCur->ixpPage->nCell || CORRUPT_DB ); + assert( pCur->ixpPage->nCell ); pCur->ix = (u16)idx; *pRes = c; rc = SQLITE_OK; goto moveto_index_finish; } @@ -72080,10 +71253,20 @@ ** has pages in common with the table being queried. See TH3 ** module cov1/btree78.test testcase 220 (2018-06-08) for an ** example. */ return SQLITE_CORRUPT_BKPT; } + + /* If the database file is corrupt, it is possible for the value of idx + ** to be invalid here. This can only occur if a second cursor modifies + ** the page while cursor pCur is holding a reference to it. Which can + ** only happen if the database is corrupt in such a way as to link the + ** page into more than one b-tree structure. + ** + ** Update 2019-12-23: appears to long longer be possible after the + ** addition of anotherValidCursor() condition on balance_deeper(). */ + harmless( idx>pPage->nCell ); if( idx>=pPage->nCell ){ if( !pPage->leaf ){ rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8])); if( rc ) return rc; @@ -72992,28 +72175,20 @@ u8 *ptr; /* Used to move bytes around within data[] */ int rc; /* The return code */ int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */ if( *pRC ) return; - assert( idx>=0 ); - assert( idxnCell ); + assert( idx>=0 && idxnCell ); assert( CORRUPT_DB || sz==cellSize(pPage, idx) ); assert( sqlite3PagerIswriteable(pPage->pDbPage) ); assert( sqlite3_mutex_held(pPage->pBt->mutex) ); assert( pPage->nFree>=0 ); data = pPage->aData; ptr = &pPage->aCellIdx[2*idx]; - assert( pPage->pBt->usableSize > (u32)(ptr-data) ); pc = get2byte(ptr); hdr = pPage->hdrOffset; -#if 0 /* Not required. Omit for efficiency */ - if( pcnCell*2 ){ - *pRC = SQLITE_CORRUPT_BKPT; - return; - } -#endif - testcase( pc==(u32)get2byte(&data[hdr+5]) ); + testcase( pc==get2byte(&data[hdr+5]) ); testcase( pc+sz==pPage->pBt->usableSize ); if( pc+sz > pPage->pBt->usableSize ){ *pRC = SQLITE_CORRUPT_BKPT; return; } @@ -73301,11 +72476,11 @@ int k; /* Current slot in pCArray->apEnd[] */ u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */ assert( i(u32)usableSize ){ j = 0; } + if( NEVER(j>(u32)usableSize) ){ j = 0; } memcpy(&pTmp[j], &aData[j], usableSize - j); for(k=0; pCArray->ixNx[k]<=i && ALWAYS(kapEnd[k]; @@ -73532,11 +72707,11 @@ nCell -= nTail; } pData = &aData[get2byteNotZero(&aData[hdr+5])]; if( pDatapPg->aDataEnd ) goto editpage_fail; + if( NEVER(pData>pPg->aDataEnd) ) goto editpage_fail; /* Add cells to the start of the page */ if( iNewpBt; assert( sqlite3_mutex_held(pBt->mutex) ); assert( sqlite3PagerIswriteable(pParent->pDbPage) ); /* At this point pParent may have at most one overflow cell. And if @@ -74489,11 +73665,11 @@ } } iOvflSpace += sz; assert( sz<=pBt->maxLocal+23 ); assert( iOvflSpace <= (int)pBt->pageSize ); - for(k=0; b.ixNx[k]<=j && ALWAYS(kpKeyInfo==0 ); + if( pCur->eState==CURSOR_FAULT ){ + assert( pCur->skipNext!=SQLITE_OK ); + return pCur->skipNext; + } + + assert( cursorOwnsBtShared(pCur) ); + assert( (pCur->curFlags & BTCF_WriteFlag)!=0 + && pBt->inTransaction==TRANS_WRITE + && (pBt->btsFlags & BTS_READ_ONLY)==0 ); + assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) ); + + /* Assert that the caller has been consistent. If this cursor was opened + ** expecting an index b-tree, then the caller should be inserting blob + ** keys with no associated data. If the cursor was opened expecting an + ** intkey table, the caller should be inserting integer keys with a + ** blob of associated data. */ + assert( (flags & BTREE_PREFORMAT) || (pX->pKey==0)==(pCur->pKeyInfo==0) ); + /* Save the positions of any other cursors open on this table. ** ** In some cases, the call to btreeMoveto() below is a no-op. For ** example, when inserting data into a table with auto-generated integer ** keys, the VDBE layer invokes sqlite3BtreeLast() to figure out the @@ -75029,28 +74223,10 @@ ** set the flag, load the schema, and then unset the flag. */ return SQLITE_CORRUPT_BKPT; } } - if( pCur->eState>=CURSOR_REQUIRESEEK ){ - rc = moveToRoot(pCur); - if( rc && rc!=SQLITE_EMPTY ) return rc; - } - - assert( cursorOwnsBtShared(pCur) ); - assert( (pCur->curFlags & BTCF_WriteFlag)!=0 - && pBt->inTransaction==TRANS_WRITE - && (pBt->btsFlags & BTS_READ_ONLY)==0 ); - assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) ); - - /* Assert that the caller has been consistent. If this cursor was opened - ** expecting an index b-tree, then the caller should be inserting blob - ** keys with no associated data. If the cursor was opened expecting an - ** intkey table, the caller should be inserting integer keys with a - ** blob of associated data. */ - assert( (flags & BTREE_PREFORMAT) || (pX->pKey==0)==(pCur->pKeyInfo==0) ); - if( pCur->pKeyInfo==0 ){ assert( pX->pKey==0 ); /* If this is an insert into a table b-tree, invalidate any incrblob ** cursors open on the row being replaced */ if( p->hasIncrblobCur ){ @@ -75135,17 +74311,18 @@ return btreeOverwriteCell(pCur, &x2); } } } assert( pCur->eState==CURSOR_VALID - || (pCur->eState==CURSOR_INVALID && loc) ); + || (pCur->eState==CURSOR_INVALID && loc) + || CORRUPT_DB ); pPage = pCur->pPage; assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) ); assert( pPage->leaf || !pPage->intKey ); if( pPage->nFree<0 ){ - if( pCur->eState>CURSOR_INVALID ){ + if( NEVER(pCur->eState>CURSOR_INVALID) ){ rc = SQLITE_CORRUPT_BKPT; }else{ rc = btreeComputeFreeSpace(pPage); } if( rc ) return rc; @@ -75176,14 +74353,11 @@ assert( szNew==pPage->xCellSize(pPage, newCell) ); assert( szNew <= MX_CELL_SIZE(pBt) ); idx = pCur->ix; if( loc==0 ){ CellInfo info; - assert( idx>=0 ); - if( idx>=pPage->nCell ){ - return SQLITE_CORRUPT_BKPT; - } + assert( idxnCell ); rc = sqlite3PagerWrite(pPage->pDbPage); if( rc ){ goto end_insert; } oldCell = findCell(pPage, idx); @@ -75407,64 +74581,48 @@ ** but which might be used by alternative storage engines. */ SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){ Btree *p = pCur->pBtree; BtShared *pBt = p->pBt; - int rc; /* Return code */ - MemPage *pPage; /* Page to delete cell from */ - unsigned char *pCell; /* Pointer to cell to delete */ - int iCellIdx; /* Index of cell to delete */ - int iCellDepth; /* Depth of node containing pCell */ - CellInfo info; /* Size of the cell being deleted */ - u8 bPreserve; /* Keep cursor valid. 2 for CURSOR_SKIPNEXT */ + int rc; /* Return code */ + MemPage *pPage; /* Page to delete cell from */ + unsigned char *pCell; /* Pointer to cell to delete */ + int iCellIdx; /* Index of cell to delete */ + int iCellDepth; /* Depth of node containing pCell */ + CellInfo info; /* Size of the cell being deleted */ + int bSkipnext = 0; /* Leaf cursor in SKIPNEXT state */ + u8 bPreserve = flags & BTREE_SAVEPOSITION; /* Keep cursor valid */ assert( cursorOwnsBtShared(pCur) ); assert( pBt->inTransaction==TRANS_WRITE ); assert( (pBt->btsFlags & BTS_READ_ONLY)==0 ); assert( pCur->curFlags & BTCF_WriteFlag ); assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) ); assert( !hasReadConflicts(p, pCur->pgnoRoot) ); assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 ); - if( pCur->eState!=CURSOR_VALID ){ - if( pCur->eState>=CURSOR_REQUIRESEEK ){ - rc = btreeRestoreCursorPosition(pCur); - assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID ); - if( rc || pCur->eState!=CURSOR_VALID ) return rc; - }else{ - return SQLITE_CORRUPT_BKPT; - } - } - assert( pCur->eState==CURSOR_VALID ); + if( pCur->eState==CURSOR_REQUIRESEEK ){ + rc = btreeRestoreCursorPosition(pCur); + assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID ); + if( rc || pCur->eState!=CURSOR_VALID ) return rc; + } + assert( CORRUPT_DB || pCur->eState==CURSOR_VALID ); iCellDepth = pCur->iPage; iCellIdx = pCur->ix; pPage = pCur->pPage; - if( pPage->nCell<=iCellIdx ){ - return SQLITE_CORRUPT_BKPT; - } pCell = findCell(pPage, iCellIdx); - if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ){ - return SQLITE_CORRUPT_BKPT; - } + if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ) return SQLITE_CORRUPT; - /* If the BTREE_SAVEPOSITION bit is on, then the cursor position must + /* If the bPreserve flag is set to true, then the cursor position must ** be preserved following this delete operation. If the current delete ** will cause a b-tree rebalance, then this is done by saving the cursor ** key and leaving the cursor in CURSOR_REQUIRESEEK state before ** returning. ** - ** If the current delete will not cause a rebalance, then the cursor + ** Or, if the current delete will not cause a rebalance, then the cursor ** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately - ** before or after the deleted entry. - ** - ** The bPreserve value records which path is required: - ** - ** bPreserve==0 Not necessary to save the cursor position - ** bPreserve==1 Use CURSOR_REQUIRESEEK to save the cursor position - ** bPreserve==2 Cursor won't move. Set CURSOR_SKIPNEXT. - */ - bPreserve = (flags & BTREE_SAVEPOSITION)!=0; + ** before or after the deleted entry. In this case set bSkipnext to true. */ if( bPreserve ){ if( !pPage->leaf || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3) || pPage->nCell==1 /* See dbfuzz001.test for a test case */ ){ @@ -75471,11 +74629,11 @@ /* A b-tree rebalance will be required after deleting this entry. ** Save the cursor key. */ rc = saveCursorKey(pCur); if( rc ) return rc; }else{ - bPreserve = 2; + bSkipnext = 1; } } /* If the page containing the entry to delete is not a leaf page, move ** the cursor to the largest entry in the tree that is smaller than @@ -75571,12 +74729,12 @@ pCur->pPage = pCur->apPage[pCur->iPage]; rc = balance(pCur); } if( rc==SQLITE_OK ){ - if( bPreserve>1 ){ - assert( (pCur->iPage==iCellDepth || CORRUPT_DB) ); + if( bSkipnext ){ + assert( bPreserve && (pCur->iPage==iCellDepth || CORRUPT_DB) ); assert( pPage==pCur->pPage || CORRUPT_DB ); assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell ); pCur->eState = CURSOR_SKIPNEXT; if( iCellIdx>=pPage->nCell ){ pCur->skipNext = -1; @@ -75781,16 +74939,15 @@ if( pgno>btreePagecount(pBt) ){ return SQLITE_CORRUPT_BKPT; } rc = getAndInitPage(pBt, pgno, &pPage, 0, 0); if( rc ) return rc; - if( (pBt->openFlags & BTREE_SINGLE)==0 - && sqlite3PagerPageRefcount(pPage->pDbPage) != (1 + (pgno==1)) - ){ + if( pPage->bBusy ){ rc = SQLITE_CORRUPT_BKPT; goto cleardatabasepage_out; } + pPage->bBusy = 1; hdr = pPage->hdrOffset; for(i=0; inCell; i++){ pCell = findCell(pPage, i); if( !pPage->leaf ){ rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange); @@ -75813,10 +74970,11 @@ }else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){ zeroPage(pPage, pPage->aData[hdr] | PTF_LEAF); } cleardatabasepage_out: + pPage->bBusy = 0; releasePage(pPage); return rc; } /* @@ -75891,14 +75049,14 @@ assert( iTable>=2 ); if( iTable>btreePagecount(pBt) ){ return SQLITE_CORRUPT_BKPT; } - rc = sqlite3BtreeClearTable(p, iTable, 0); - if( rc ) return rc; rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0); - if( NEVER(rc) ){ + if( rc ) return rc; + rc = sqlite3BtreeClearTable(p, iTable, 0); + if( rc ){ releasePage(pPage); return rc; } *piMoved = 0; @@ -77162,17 +76320,18 @@ int i = sqlite3FindDbName(pDb, zDb); if( i==1 ){ Parse sParse; int rc = 0; - sqlite3ParseObjectInit(&sParse,pDb); + memset(&sParse, 0, sizeof(sParse)); + sParse.db = pDb; if( sqlite3OpenTempDatabase(&sParse) ){ sqlite3ErrorWithMsg(pErrorDb, sParse.rc, "%s", sParse.zErrMsg); rc = SQLITE_ERROR; } sqlite3DbFree(pErrorDb, sParse.zErrMsg); - sqlite3ParseObjectReset(&sParse); + sqlite3ParserReset(&sParse); if( rc ){ return 0; } } @@ -78050,19 +77209,14 @@ */ SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){ #ifndef SQLITE_OMIT_UTF16 int rc; #endif - assert( pMem!=0 ); assert( !sqlite3VdbeMemIsRowSet(pMem) ); assert( desiredEnc==SQLITE_UTF8 || desiredEnc==SQLITE_UTF16LE || desiredEnc==SQLITE_UTF16BE ); - if( !(pMem->flags&MEM_Str) ){ - pMem->enc = desiredEnc; - return SQLITE_OK; - } - if( pMem->enc==desiredEnc ){ + if( !(pMem->flags&MEM_Str) || pMem->enc==desiredEnc ){ return SQLITE_OK; } assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); #ifdef SQLITE_OMIT_UTF16 return SQLITE_ERROR; @@ -78187,11 +77341,10 @@ ** MEM.zMalloc, where it can be safely written. ** ** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails. */ SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem *pMem){ - assert( pMem!=0 ); assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); assert( !sqlite3VdbeMemIsRowSet(pMem) ); if( (pMem->flags & (MEM_Str|MEM_Blob))!=0 ){ if( ExpandBlob(pMem) ) return SQLITE_NOMEM; if( pMem->szMalloc==0 || pMem->z!=pMem->zMalloc ){ @@ -78212,11 +77365,10 @@ ** blob stored in dynamically allocated space. */ #ifndef SQLITE_OMIT_INCRBLOB SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *pMem){ int nByte; - assert( pMem!=0 ); assert( pMem->flags & MEM_Zero ); assert( (pMem->flags&MEM_Blob)!=0 || MemNullNochng(pMem) ); testcase( sqlite3_value_nochange(pMem) ); assert( !sqlite3VdbeMemIsRowSet(pMem) ); assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); @@ -78228,12 +77380,10 @@ nByte = 1; } if( sqlite3VdbeMemGrow(pMem, nByte, 1) ){ return SQLITE_NOMEM_BKPT; } - assert( pMem->z!=0 ); - assert( sqlite3DbMallocSize(pMem->db,pMem->z) >= nByte ); memset(&pMem->z[pMem->n], 0, pMem->u.nZero); pMem->n += pMem->u.nZero; pMem->flags &= ~(MEM_Zero|MEM_Term); return SQLITE_OK; @@ -78242,11 +77392,10 @@ /* ** Make sure the given Mem is \u0000 terminated. */ SQLITE_PRIVATE int sqlite3VdbeMemNulTerminate(Mem *pMem){ - assert( pMem!=0 ); assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); testcase( (pMem->flags & (MEM_Term|MEM_Str))==(MEM_Term|MEM_Str) ); testcase( (pMem->flags & (MEM_Term|MEM_Str))==0 ); if( (pMem->flags & (MEM_Term|MEM_Str))!=MEM_Str ){ return SQLITE_OK; /* Nothing to do */ @@ -78270,11 +77419,10 @@ ** user and the latter is an internal programming error. */ SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem *pMem, u8 enc, u8 bForce){ const int nByte = 32; - assert( pMem!=0 ); assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); assert( !(pMem->flags&MEM_Zero) ); assert( !(pMem->flags&(MEM_Str|MEM_Blob)) ); assert( pMem->flags&(MEM_Int|MEM_Real|MEM_IntReal) ); assert( !sqlite3VdbeMemIsRowSet(pMem) ); @@ -78306,11 +77454,10 @@ */ SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem *pMem, FuncDef *pFunc){ sqlite3_context ctx; Mem t; assert( pFunc!=0 ); - assert( pMem!=0 ); assert( pFunc->xFinalize!=0 ); assert( (pMem->flags & MEM_Null)!=0 || pFunc==pMem->u.pDef ); assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); memset(&ctx, 0, sizeof(ctx)); memset(&t, 0, sizeof(t)); @@ -78450,18 +77597,17 @@ ** it into an integer and return that. If pMem represents an ** an SQL-NULL value, return 0. ** ** If pMem represents a string value, its encoding might be changed. */ -static SQLITE_NOINLINE i64 memIntValue(const Mem *pMem){ +static SQLITE_NOINLINE i64 memIntValue(Mem *pMem){ i64 value = 0; sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc); return value; } -SQLITE_PRIVATE i64 sqlite3VdbeIntValue(const Mem *pMem){ +SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem *pMem){ int flags; - assert( pMem!=0 ); assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); assert( EIGHT_BYTE_ALIGNMENT(pMem) ); flags = pMem->flags; if( flags & (MEM_Int|MEM_IntReal) ){ testcase( flags & MEM_IntReal ); @@ -78486,11 +77632,10 @@ double val = (double)0; sqlite3AtoF(pMem->z, &val, pMem->n, pMem->enc); return val; } SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){ - assert( pMem!=0 ); assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); assert( EIGHT_BYTE_ALIGNMENT(pMem) ); if( pMem->flags & MEM_Real ){ return pMem->u.r; }else if( pMem->flags & (MEM_Int|MEM_IntReal) ){ @@ -78519,11 +77664,10 @@ ** The MEM structure is already a MEM_Real. Try to also make it a ** MEM_Int if we can. */ SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem *pMem){ i64 ix; - assert( pMem!=0 ); assert( pMem->flags & MEM_Real ); assert( !sqlite3VdbeMemIsRowSet(pMem) ); assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); assert( EIGHT_BYTE_ALIGNMENT(pMem) ); @@ -78547,11 +77691,10 @@ /* ** Convert pMem to type integer. Invalidate any prior representations. */ SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem *pMem){ - assert( pMem!=0 ); assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); assert( !sqlite3VdbeMemIsRowSet(pMem) ); assert( EIGHT_BYTE_ALIGNMENT(pMem) ); pMem->u.i = sqlite3VdbeIntValue(pMem); @@ -78562,11 +77705,10 @@ /* ** Convert pMem so that it is of type MEM_Real. ** Invalidate any prior representations. */ SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem *pMem){ - assert( pMem!=0 ); assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); assert( EIGHT_BYTE_ALIGNMENT(pMem) ); pMem->u.r = sqlite3VdbeRealValue(pMem); MemSetTypeFlag(pMem, MEM_Real); @@ -78596,11 +77738,10 @@ ** Every effort is made to force the conversion, even if the input ** is a string that does not look completely like a number. Convert ** as much of the string as we can and ignore the rest. */ SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem *pMem){ - assert( pMem!=0 ); testcase( pMem->flags & MEM_Int ); testcase( pMem->flags & MEM_Real ); testcase( pMem->flags & MEM_IntReal ); testcase( pMem->flags & MEM_Null ); if( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null))==0 ){ @@ -78706,35 +77847,19 @@ /* ** Delete any previous value and set the value to be a BLOB of length ** n containing all zeros. */ -#ifndef SQLITE_OMIT_INCRBLOB SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){ sqlite3VdbeMemRelease(pMem); pMem->flags = MEM_Blob|MEM_Zero; pMem->n = 0; if( n<0 ) n = 0; pMem->u.nZero = n; pMem->enc = SQLITE_UTF8; pMem->z = 0; } -#else -SQLITE_PRIVATE int sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){ - int nByte = n>0?n:1; - if( sqlite3VdbeMemGrow(pMem, nByte, 0) ){ - return SQLITE_NOMEM_BKPT; - } - assert( pMem->z!=0 ); - assert( sqlite3DbMallocSize(pMem->db, pMem->z)>=nByte ); - memset(pMem->z, 0, nByte); - pMem->n = n>0?n:0; - pMem->flags = MEM_Blob; - pMem->enc = SQLITE_UTF8; - return SQLITE_OK; -} -#endif /* ** The pMem is known to contain content that needs to be destroyed prior ** to a value change. So invoke the destructor, then set the value to ** a 64-bit integer. @@ -78770,11 +77895,10 @@ void *pPtr, const char *zPType, void (*xDestructor)(void*) ){ assert( pMem->flags==MEM_Null ); - vdbeMemClear(pMem); pMem->u.zPType = zPType ? zPType : ""; pMem->z = pPtr; pMem->flags = MEM_Null|MEM_Dyn|MEM_Subtype|MEM_Term; pMem->eSubtype = 'p'; pMem->xDel = xDestructor ? xDestructor : sqlite3NoopDestructor; @@ -78965,11 +78089,10 @@ ){ i64 nByte = n; /* New value for pMem->n */ int iLimit; /* Maximum allowed string or blob size */ u16 flags = 0; /* New value for pMem->flags */ - assert( pMem!=0 ); assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); assert( !sqlite3VdbeMemIsRowSet(pMem) ); /* If z is a NULL pointer, set pMem to contain an SQL NULL. */ if( !z ){ @@ -79291,14 +78414,12 @@ ExprList *pList = 0; /* Function arguments */ int i; /* Iterator variable */ assert( pCtx!=0 ); assert( (p->flags & EP_TokenOnly)==0 ); - assert( ExprUseXList(p) ); pList = p->x.pList; if( pList ) nVal = pList->nExpr; - assert( !ExprHasProperty(p, EP_IntValue) ); pFunc = sqlite3FindFunction(db, p->u.zToken, nVal, enc, 0); assert( pFunc ); if( (pFunc->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0 || (pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL) ){ @@ -79385,22 +78506,24 @@ const char *zNeg = ""; int rc = SQLITE_OK; assert( pExpr!=0 ); while( (op = pExpr->op)==TK_UPLUS || op==TK_SPAN ) pExpr = pExpr->pLeft; +#if defined(SQLITE_ENABLE_STAT4) if( op==TK_REGISTER ) op = pExpr->op2; +#else + if( NEVER(op==TK_REGISTER) ) op = pExpr->op2; +#endif /* Compressed expressions only appear when parsing the DEFAULT clause ** on a table column definition, and hence only when pCtx==0. This ** check ensures that an EP_TokenOnly expression is never passed down ** into valueFromFunction(). */ assert( (pExpr->flags & EP_TokenOnly)==0 || pCtx==0 ); if( op==TK_CAST ){ - u8 aff; - assert( !ExprHasProperty(pExpr, EP_IntValue) ); - aff = sqlite3AffinityType(pExpr->u.zToken,0); + u8 aff = sqlite3AffinityType(pExpr->u.zToken,0); rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx); testcase( rc!=SQLITE_OK ); if( *ppVal ){ sqlite3VdbeMemCast(*ppVal, aff, SQLITE_UTF8); sqlite3ValueApplyAffinity(*ppVal, affinity, SQLITE_UTF8); @@ -79469,11 +78592,10 @@ sqlite3VdbeMemSetNull(pVal); } #ifndef SQLITE_OMIT_BLOB_LITERAL else if( op==TK_BLOB ){ int nVal; - assert( !ExprHasProperty(pExpr, EP_IntValue) ); assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' ); assert( pExpr->u.zToken[1]=='\'' ); pVal = valueNew(db, pCtx); if( !pVal ) goto no_mem; zVal = &pExpr->u.zToken[2]; @@ -79487,11 +78609,10 @@ else if( op==TK_FUNCTION && pCtx!=0 ){ rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx); } #endif else if( op==TK_TRUEFALSE ){ - assert( !ExprHasProperty(pExpr, EP_IntValue) ); pVal = valueNew(db, pCtx); if( pVal ){ pVal->flags = MEM_Int; pVal->u.i = pExpr->u.zToken[4]==0; } @@ -79500,11 +78621,11 @@ *ppVal = pVal; return rc; no_mem: #ifdef SQLITE_ENABLE_STAT4 - if( pCtx==0 || NEVER(pCtx->pParse->nErr==0) ) + if( pCtx==0 || pCtx->pParse->nErr==0 ) #endif sqlite3OomFault(db); sqlite3DbFree(db, zVal); assert( *ppVal==0 ); #ifdef SQLITE_ENABLE_STAT4 @@ -80041,14 +79162,12 @@ assert( p->iVdbeMagic==VDBE_MAGIC_INIT ); assert( op>=0 && op<0xff ); if( p->nOpAlloc<=i ){ return growOp3(p, op, p1, p2, p3); } - assert( p->aOp!=0 ); p->nOp++; pOp = &p->aOp[i]; - assert( pOp!=0 ); pOp->opcode = (u8)op; pOp->p5 = 0; pOp->p1 = p1; pOp->p2 = p2; pOp->p3 = p3; @@ -81178,11 +80297,12 @@ ** makes the code easier to read during debugging. None of this happens ** in a production build. */ static void vdbeVComment(Vdbe *p, const char *zFormat, va_list ap){ assert( p->nOp>0 || p->aOp==0 ); - assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->pParse->nErr>0 ); + assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed + || p->pParse->nErr>0 ); if( p->nOp ){ assert( p->aOp ); sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment); p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap); } @@ -81286,11 +80406,11 @@ zOpName = sqlite3OpcodeName(pOp->opcode); nOpName = sqlite3Strlen30(zOpName); if( zOpName[nOpName+1] ){ int seenCom = 0; char c; - zSynopsis = zOpName + nOpName + 1; + zSynopsis = zOpName += nOpName + 1; if( strncmp(zSynopsis,"IF ",3)==0 ){ sqlite3_snprintf(sizeof(zAlt), zAlt, "if %s goto P2", zSynopsis+3); zSynopsis = zAlt; } for(ii=0; (c = zSynopsis[ii])!=0; ii++){ @@ -81359,11 +80479,10 @@ */ static void displayP4Expr(StrAccum *p, Expr *pExpr){ const char *zOp = 0; switch( pExpr->op ){ case TK_STRING: - assert( !ExprHasProperty(pExpr, EP_IntValue) ); sqlite3_str_appendf(p, "%Q", pExpr->u.zToken); break; case TK_INTEGER: sqlite3_str_appendf(p, "%d", pExpr->u.iValue); break; @@ -81706,12 +80825,12 @@ ** with no indexes using a single prepared INSERT statement, bind() ** and reset(). Inserts are grouped into a transaction. */ testcase( p->flags & MEM_Agg ); testcase( p->flags & MEM_Dyn ); + testcase( p->xDel==sqlite3VdbeFrameMemDel ); if( p->flags&(MEM_Agg|MEM_Dyn) ){ - testcase( (p->flags & MEM_Dyn)!=0 && p->xDel==sqlite3VdbeFrameMemDel ); sqlite3VdbeMemRelease(p); }else if( p->szMalloc ){ sqlite3DbFreeNN(db, p->zMalloc); p->szMalloc = 0; } @@ -82269,10 +81388,12 @@ */ SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){ if( pCx==0 ){ return; } + assert( pCx->pBtx==0 || pCx->eCurType==CURTYPE_BTREE ); + assert( pCx->pBtx==0 || pCx->isEphemeral ); switch( pCx->eCurType ){ case CURTYPE_SORTER: { sqlite3VdbeSorterClose(p->db, pCx); break; } @@ -82853,19 +81974,13 @@ /* Lock all btrees used by the statement */ sqlite3VdbeEnter(p); /* Check for one of the special errors */ - if( p->rc ){ - mrc = p->rc & 0xff; - isSpecialError = mrc==SQLITE_NOMEM - || mrc==SQLITE_IOERR - || mrc==SQLITE_INTERRUPT - || mrc==SQLITE_FULL; - }else{ - mrc = isSpecialError = 0; - } + mrc = p->rc & 0xff; + isSpecialError = mrc==SQLITE_NOMEM || mrc==SQLITE_IOERR + || mrc==SQLITE_INTERRUPT || mrc==SQLITE_FULL; if( isSpecialError ){ /* If the query was read-only and the error code is SQLITE_INTERRUPT, ** no rollback is necessary. Otherwise, at least a savepoint ** transaction must be rolled back to restore the database to a ** consistent state. @@ -82913,13 +82028,10 @@ if( NEVER(p->readOnly) ){ sqlite3VdbeLeave(p); return SQLITE_ERROR; } rc = SQLITE_CONSTRAINT_FOREIGNKEY; - }else if( db->flags & SQLITE_CorruptRdOnly ){ - rc = SQLITE_CORRUPT; - db->flags &= ~SQLITE_CorruptRdOnly; }else{ /* The auto-commit flag is true, the vdbe program was successful ** or hit an 'OR FAIL' constraint and there are no deferred foreign ** key constraints to hold up the transaction. This means a commit ** is required. */ @@ -83049,11 +82161,10 @@ db->bBenignMalloc--; }else if( db->pErr ){ sqlite3ValueSetNull(db->pErr); } db->errCode = rc; - db->errByteOffset = -1; return rc; } #ifdef SQLITE_ENABLE_SQLLOG /* @@ -83371,11 +82482,11 @@ VdbeCursor *p = *pp; assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO ); if( p->deferredMoveto ){ u32 iMap; assert( !p->isEphemeral ); - if( p->ub.aAltMap && (iMap = p->ub.aAltMap[1+*piCol])>0 && !p->nullRow ){ + if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 && !p->nullRow ){ *pp = p->pAltCursor; *piCol = iMap - 1; return SQLITE_OK; } return sqlite3VdbeFinishMoveto(p); @@ -83649,18 +82760,18 @@ #define FOUR_BYTE_UINT(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3]) #define FOUR_BYTE_INT(x) (16777216*(i8)((x)[0])|((x)[1]<<16)|((x)[2]<<8)|(x)[3]) /* ** Deserialize the data blob pointed to by buf as serial type serial_type -** and store the result in pMem. +** and store the result in pMem. Return the number of bytes read. ** ** This function is implemented as two separate routines for performance. ** The few cases that require local variables are broken out into a separate ** routine so that in most cases the overhead of moving the stack pointer ** is avoided. */ -static void serialGet( +static u32 serialGet( const unsigned char *buf, /* Buffer to deserialize from */ u32 serial_type, /* Serial type to deserialize */ Mem *pMem /* Memory cell to write value into */ ){ u64 x = FOUR_BYTE_UINT(buf); @@ -83690,12 +82801,13 @@ assert( sizeof(x)==8 && sizeof(pMem->u.r)==8 ); swapMixedEndianFloat(x); memcpy(&pMem->u.r, &x, sizeof(x)); pMem->flags = IsNaN(x) ? MEM_Null : MEM_Real; } + return 8; } -SQLITE_PRIVATE void sqlite3VdbeSerialGet( +SQLITE_PRIVATE u32 sqlite3VdbeSerialGet( const unsigned char *buf, /* Buffer to deserialize from */ u32 serial_type, /* Serial type to deserialize */ Mem *pMem /* Memory cell to write value into */ ){ switch( serial_type ){ @@ -83702,41 +82814,41 @@ case 10: { /* Internal use only: NULL with virtual table ** UPDATE no-change flag set */ pMem->flags = MEM_Null|MEM_Zero; pMem->n = 0; pMem->u.nZero = 0; - return; + break; } case 11: /* Reserved for future use */ case 0: { /* Null */ /* EVIDENCE-OF: R-24078-09375 Value is a NULL. */ pMem->flags = MEM_Null; - return; + break; } case 1: { /* EVIDENCE-OF: R-44885-25196 Value is an 8-bit twos-complement ** integer. */ pMem->u.i = ONE_BYTE_INT(buf); pMem->flags = MEM_Int; testcase( pMem->u.i<0 ); - return; + return 1; } case 2: { /* 2-byte signed integer */ /* EVIDENCE-OF: R-49794-35026 Value is a big-endian 16-bit ** twos-complement integer. */ pMem->u.i = TWO_BYTE_INT(buf); pMem->flags = MEM_Int; testcase( pMem->u.i<0 ); - return; + return 2; } case 3: { /* 3-byte signed integer */ /* EVIDENCE-OF: R-37839-54301 Value is a big-endian 24-bit ** twos-complement integer. */ pMem->u.i = THREE_BYTE_INT(buf); pMem->flags = MEM_Int; testcase( pMem->u.i<0 ); - return; + return 3; } case 4: { /* 4-byte signed integer */ /* EVIDENCE-OF: R-01849-26079 Value is a big-endian 32-bit ** twos-complement integer. */ pMem->u.i = FOUR_BYTE_INT(buf); @@ -83744,34 +82856,33 @@ /* Work around a sign-extension bug in the HP compiler for HP/UX */ if( buf[0]&0x80 ) pMem->u.i |= 0xffffffff80000000LL; #endif pMem->flags = MEM_Int; testcase( pMem->u.i<0 ); - return; + return 4; } case 5: { /* 6-byte signed integer */ /* EVIDENCE-OF: R-50385-09674 Value is a big-endian 48-bit ** twos-complement integer. */ pMem->u.i = FOUR_BYTE_UINT(buf+2) + (((i64)1)<<32)*TWO_BYTE_INT(buf); pMem->flags = MEM_Int; testcase( pMem->u.i<0 ); - return; + return 6; } case 6: /* 8-byte signed integer */ case 7: { /* IEEE floating point */ /* These use local variables, so do them in a separate routine ** to avoid having to move the frame pointer in the common case */ - serialGet(buf,serial_type,pMem); - return; + return serialGet(buf,serial_type,pMem); } case 8: /* Integer 0 */ case 9: { /* Integer 1 */ /* EVIDENCE-OF: R-12976-22893 Value is the integer 0. */ /* EVIDENCE-OF: R-18143-12121 Value is the integer 1. */ pMem->u.i = serial_type-8; pMem->flags = MEM_Int; - return; + return 0; } default: { /* EVIDENCE-OF: R-14606-31564 Value is a BLOB that is (N-12)/2 bytes in ** length. ** EVIDENCE-OF: R-28401-00140 Value is a string in the text encoding and @@ -83778,14 +82889,14 @@ ** (N-13)/2 bytes in length. */ static const u16 aFlag[] = { MEM_Blob|MEM_Ephem, MEM_Str|MEM_Ephem }; pMem->z = (char *)buf; pMem->n = (serial_type-12)/2; pMem->flags = aFlag[serial_type&1]; - return; + return pMem->n; } } - return; + return 0; } /* ** This routine is used to allocate sufficient space for an UnpackedRecord ** structure large enough to be used with sqlite3VdbeRecordUnpack() if ** the first argument is a pointer to KeyInfo structure pKeyInfo. @@ -83844,12 +82955,11 @@ pMem->enc = pKeyInfo->enc; pMem->db = pKeyInfo->db; /* pMem->flags = 0; // sqlite3VdbeSerialGet() will set this for us */ pMem->szMalloc = 0; pMem->z = 0; - sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem); - d += sqlite3VdbeSerialTypeLen(serial_type); + d += sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem); pMem++; if( (++u)>=p->nField ) break; } if( d>(u32)nKey && u ){ assert( CORRUPT_DB ); @@ -83929,12 +83039,11 @@ break; } /* Extract the values to be compared. */ - sqlite3VdbeSerialGet(&aKey1[d1], serial_type1, &mem1); - d1 += sqlite3VdbeSerialTypeLen(serial_type1); + d1 += sqlite3VdbeSerialGet(&aKey1[d1], serial_type1, &mem1); /* Do the comparison */ rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i], pKeyInfo->nAllField>i ? pKeyInfo->aColl[i] : 0); @@ -84734,11 +83843,11 @@ } /* The index entry must begin with a header size */ getVarint32NR((u8*)m.z, szHdr); testcase( szHdr==3 ); - testcase( szHdr==(u32)m.n ); + testcase( szHdr==m.n ); testcase( szHdr>0x7fffffff ); assert( m.n>=0 ); if( unlikely(szHdr<3 || szHdr>(unsigned)m.n) ){ goto idx_rowid_corruption; } @@ -85023,12 +84132,10 @@ }else{ iKey2 = iKey1; } } - assert( pCsr!=0 ); - assert( pCsr->eCurType==CURTYPE_BTREE ); assert( pCsr->nField==pTab->nCol || (pCsr->nField==pTab->nCol+1 && op==SQLITE_DELETE && iReg==-1) ); preupdate.v = v; @@ -85424,12 +84531,12 @@ /**************************** sqlite3_result_ ******************************* ** The following routines are used by user-defined functions to specify ** the function result. ** ** The setStrOrError() function calls sqlite3VdbeMemSetStr() to store the -** result as a string or blob. Appropriate errors are set if the string/blob -** is too big or if an OOM occurs. +** result as a string or blob but if the string or blob is too large, it +** then sets the error code to SQLITE_TOOBIG ** ** The invokeValueDestructor(P,X) routine invokes destructor function X() ** on value P is not going to be used and need to be destroyed. */ static void setResultStrOrError( @@ -85437,20 +84544,12 @@ const char *z, /* String pointer */ int n, /* Bytes in string, or negative */ u8 enc, /* Encoding of z. 0 for BLOBs */ void (*xDel)(void*) /* Destructor function */ ){ - int rc = sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel); - if( rc ){ - if( rc==SQLITE_TOOBIG ){ - sqlite3_result_error_toobig(pCtx); - }else{ - /* The only errors possible from sqlite3VdbeMemSetStr are - ** SQLITE_TOOBIG and SQLITE_NOMEM */ - assert( rc==SQLITE_NOMEM ); - sqlite3_result_error_nomem(pCtx); - } + if( sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel)==SQLITE_TOOBIG ){ + sqlite3_result_error_toobig(pCtx); } } static int invokeValueDestructor( const void *p, /* Value to destroy */ void (*xDel)(void*), /* The destructor */ @@ -85603,16 +84702,12 @@ Mem *pOut = pCtx->pOut; assert( sqlite3_mutex_held(pOut->db->mutex) ); if( n>(u64)pOut->db->aLimit[SQLITE_LIMIT_LENGTH] ){ return SQLITE_TOOBIG; } -#ifndef SQLITE_OMIT_INCRBLOB sqlite3VdbeMemSetZeroBlob(pCtx->pOut, (int)n); return SQLITE_OK; -#else - return sqlite3VdbeMemSetZeroBlob(pCtx->pOut, (int)n); -#endif } SQLITE_API void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){ pCtx->isError = errCode ? errCode : -1; #ifdef SQLITE_DEBUG if( pCtx->pVdbe ) pCtx->pVdbe->rcApp = errCode; @@ -85908,74 +85003,10 @@ SQLITE_API int sqlite3_vtab_nochange(sqlite3_context *p){ assert( p ); return sqlite3_value_nochange(p->pOut); } -/* -** Implementation of sqlite3_vtab_in_first() (if bNext==0) and -** sqlite3_vtab_in_next() (if bNext!=0). -*/ -static int valueFromValueList( - sqlite3_value *pVal, /* Pointer to the ValueList object */ - sqlite3_value **ppOut, /* Store the next value from the list here */ - int bNext /* 1 for _next(). 0 for _first() */ -){ - int rc; - ValueList *pRhs; - - *ppOut = 0; - if( pVal==0 ) return SQLITE_MISUSE; - pRhs = (ValueList*)sqlite3_value_pointer(pVal, "ValueList"); - if( pRhs==0 ) return SQLITE_MISUSE; - if( bNext ){ - rc = sqlite3BtreeNext(pRhs->pCsr, 0); - }else{ - int dummy = 0; - rc = sqlite3BtreeFirst(pRhs->pCsr, &dummy); - assert( rc==SQLITE_OK || sqlite3BtreeEof(pRhs->pCsr) ); - if( sqlite3BtreeEof(pRhs->pCsr) ) rc = SQLITE_DONE; - } - if( rc==SQLITE_OK ){ - u32 sz; /* Size of current row in bytes */ - Mem sMem; /* Raw content of current row */ - memset(&sMem, 0, sizeof(sMem)); - sz = sqlite3BtreePayloadSize(pRhs->pCsr); - rc = sqlite3VdbeMemFromBtreeZeroOffset(pRhs->pCsr,(int)sz,&sMem); - if( rc==SQLITE_OK ){ - u8 *zBuf = (u8*)sMem.z; - u32 iSerial; - sqlite3_value *pOut = pRhs->pOut; - int iOff = 1 + getVarint32(&zBuf[1], iSerial); - sqlite3VdbeSerialGet(&zBuf[iOff], iSerial, pOut); - pOut->enc = ENC(pOut->db); - if( (pOut->flags & MEM_Ephem)!=0 && sqlite3VdbeMemMakeWriteable(pOut) ){ - rc = SQLITE_NOMEM; - }else{ - *ppOut = pOut; - } - } - sqlite3VdbeMemRelease(&sMem); - } - return rc; -} - -/* -** Set the iterator value pVal to point to the first value in the set. -** Set (*ppOut) to point to this value before returning. -*/ -SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut){ - return valueFromValueList(pVal, ppOut, 0); -} - -/* -** Set the iterator value pVal to point to the next value in the set. -** Set (*ppOut) to point to this value before returning. -*/ -SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut){ - return valueFromValueList(pVal, ppOut, 1); -} - /* ** Return the current time for a statement. If the current time ** is requested more than once within the same run of a single prepared ** statement, the exact same time is returned for each invocation regardless ** of the amount of time that elapses between invocations. In other words, @@ -86656,14 +85687,11 @@ case SQLITE_INTEGER: { rc = sqlite3_bind_int64(pStmt, i, pValue->u.i); break; } case SQLITE_FLOAT: { - assert( pValue->flags & (MEM_Real|MEM_IntReal) ); - rc = sqlite3_bind_double(pStmt, i, - (pValue->flags & MEM_Real) ? pValue->u.r : (double)pValue->u.i - ); + rc = sqlite3_bind_double(pStmt, i, pValue->u.r); break; } case SQLITE_BLOB: { if( pValue->flags & MEM_Zero ){ rc = sqlite3_bind_zeroblob(pStmt, i, pValue->u.nZero); @@ -86687,15 +85715,11 @@ SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt *pStmt, int i, int n){ int rc; Vdbe *p = (Vdbe *)pStmt; rc = vdbeUnbind(p, i); if( rc==SQLITE_OK ){ -#ifndef SQLITE_OMIT_INCRBLOB sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n); -#else - rc = sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n); -#endif sqlite3_mutex_leave(p->db->mutex); } return rc; } SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt *pStmt, int i, sqlite3_uint64 n){ @@ -86979,11 +86003,10 @@ /* If the old.* record has not yet been loaded into memory, do so now. */ if( p->pUnpacked==0 ){ u32 nRec; u8 *aRec; - assert( p->pCsr->eCurType==CURTYPE_BTREE ); nRec = sqlite3BtreePayloadSize(p->pCsr->uc.pCursor); aRec = sqlite3DbMallocRaw(db, nRec); if( !aRec ) goto preupdate_old_out; rc = sqlite3BtreePayload(p->pCsr->uc.pCursor, 0, nRec, aRec); if( rc==SQLITE_OK ){ @@ -87639,10 +86662,11 @@ */ static VdbeCursor *allocateCursor( Vdbe *p, /* The virtual machine */ int iCur, /* Index of the new VdbeCursor */ int nField, /* Number of fields in the table or index */ + int iDb, /* Database the cursor belongs to, or -1 */ u8 eCurType /* Type of the new cursor */ ){ /* Find the memory cell that will be used to store the blob of memory ** required for this VdbeCursor structure. It is convenient to use a ** vdbe memory cell to manage the memory allocation required for a @@ -87695,10 +86719,11 @@ } p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->zMalloc; memset(pCx, 0, offsetof(VdbeCursor,pAltCursor)); pCx->eCurType = eCurType; + pCx->iDb = iDb; pCx->nField = nField; pCx->aOffset = &pCx->aType[nField]; if( eCurType==CURTYPE_BTREE ){ pCx->uc.pCursor = (BtCursor*) &pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField]; @@ -88067,33 +87092,10 @@ pOut->flags = MEM_Int; return pOut; } } -/* -** Compute a bloom filter hash using pOp->p4.i registers from aMem[] beginning -** with pOp->p3. Return the hash. -*/ -static u64 filterHash(const Mem *aMem, const Op *pOp){ - int i, mx; - u64 h = 0; - - assert( pOp->p4type==P4_INT32 ); - for(i=pOp->p3, mx=i+pOp->p4.i; iflags & (MEM_Int|MEM_IntReal) ){ - h += p->u.i; - }else if( p->flags & MEM_Real ){ - h += sqlite3VdbeIntValue(p); - }else if( p->flags & (MEM_Str|MEM_Blob) ){ - h += p->n; - if( p->flags & MEM_Zero ) h += p->u.nZero; - } - } - return h; -} - /* ** Return the symbolic name for the data type of a pMem */ static const char *vdbeMemTypeName(Mem *pMem){ static const char *azTypes[] = { @@ -88385,12 +87387,10 @@ REGISTER_TRACE(pOp->p1, pIn1); /* Most jump operations do a goto to this spot in order to update ** the pOp pointer. */ jump_to_p2: - assert( pOp->p2>0 ); /* There are never any jumps to instruction 0 */ - assert( pOp->p2nOp ); /* Jumps must be in range */ pOp = &aOp[pOp->p2 - 1]; break; } /* Opcode: Return P1 * * * * @@ -88746,22 +87746,16 @@ /* Opcode: Blob P1 P2 * P4 * ** Synopsis: r[P2]=P4 (len=P1) ** ** P4 points to a blob of data P1 bytes long. Store this -** blob in register P2. If P4 is a NULL pointer, then construct -** a zero-filled blob that is P1 bytes long in P2. +** blob in register P2. */ case OP_Blob: { /* out2 */ assert( pOp->p1 <= SQLITE_MAX_LENGTH ); pOut = out2Prerelease(p, pOp); - if( pOp->p4.z==0 ){ - sqlite3VdbeMemSetZeroBlob(pOut, pOp->p1); - if( sqlite3VdbeMemExpandBlob(pOut) ) goto no_mem; - }else{ - sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0); - } + sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0); pOut->enc = encoding; UPDATE_MAX_BLOBSIZE(pOut); break; } @@ -88906,26 +87900,28 @@ pOut = &aMem[pOp->p2]; sqlite3VdbeMemSetInt64(pOut, pIn1->u.i); break; } -/* Opcode: FkCheck * * * * * -** -** Halt with an SQLITE_CONSTRAINT error if there are any unresolved -** foreign key constraint violations. If there are no foreign key -** constraint violations, this is a no-op. -** -** FK constraint violations are also checked when the prepared statement -** exits. This opcode is used to raise foreign key constraint errors prior -** to returning results such as a row change count or the result of a -** RETURNING clause. -*/ -case OP_FkCheck: { +/* Opcode: ChngCntRow P1 P2 * * * +** Synopsis: output=r[P1] +** +** Output value in register P1 as the chance count for a DML statement, +** due to the "PRAGMA count_changes=ON" setting. Or, if there was a +** foreign key error in the statement, trigger the error now. +** +** This opcode is a variant of OP_ResultRow that checks the foreign key +** immediate constraint count and throws an error if the count is +** non-zero. The P2 opcode must be 1. +*/ +case OP_ChngCntRow: { + assert( pOp->p2==1 ); if( (rc = sqlite3VdbeCheckFk(p,0))!=SQLITE_OK ){ goto abort_due_to_error; } - break; + /* Fall through to the next case, OP_ResultRow */ + /* no break */ deliberate_fall_through } /* Opcode: ResultRow P1 P2 * * * ** Synopsis: output=r[P1@P2] ** @@ -89559,11 +88555,11 @@ testcase( pIn1->flags & MEM_Real ); testcase( pIn1->flags & MEM_IntReal ); sqlite3VdbeMemStringify(pIn1, encoding, 1); testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) ); flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask); - if( pIn1==pIn3 ) flags3 = flags1 | MEM_Str; + if( NEVER(pIn1==pIn3) ) flags3 = flags1 | MEM_Str; } if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){ testcase( pIn3->flags & MEM_Int ); testcase( pIn3->flags & MEM_Real ); testcase( pIn3->flags & MEM_IntReal ); @@ -90027,22 +89023,14 @@ case OP_Offset: { /* out3 */ VdbeCursor *pC; /* The VDBE cursor */ assert( pOp->p1>=0 && pOp->p1nCursor ); pC = p->apCsr[pOp->p1]; pOut = &p->aMem[pOp->p3]; - if( pC==0 || pC->eCurType!=CURTYPE_BTREE ){ + if( NEVER(pC==0) || pC->eCurType!=CURTYPE_BTREE ){ sqlite3VdbeMemSetNull(pOut); }else{ - if( pC->deferredMoveto ){ - rc = sqlite3VdbeFinishMoveto(pC); - if( rc ) goto abort_due_to_error; - } - if( sqlite3BtreeEof(pC->uc.pCursor) ){ - sqlite3VdbeMemSetNull(pOut); - }else{ - sqlite3VdbeMemSetInt64(pOut, sqlite3BtreeOffset(pC->uc.pCursor)); - } + sqlite3VdbeMemSetInt64(pOut, sqlite3BtreeOffset(pC->uc.pCursor)); } break; } #endif /* SQLITE_ENABLE_OFFSET_SQL_FUNC */ @@ -90097,11 +89085,10 @@ pDest = &aMem[pOp->p3]; memAboutToChange(p, pDest); assert( pC!=0 ); assert( p2<(u32)pC->nField ); aOffset = pC->aOffset; - assert( aOffset==pC->aType+pC->nField ); assert( pC->eCurType!=CURTYPE_VTAB ); assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow ); assert( pC->eCurType!=CURTYPE_SORTER ); if( pC->cacheStatus!=p->cacheCtr ){ /*OPTIMIZATION-IF-FALSE*/ @@ -90333,11 +89320,11 @@ rc = SQLITE_CORRUPT_BKPT; goto abort_due_to_error; } } -/* Opcode: TypeCheck P1 P2 P3 P4 * +/* Opcode: TypeCheck P1 P2 * P4 * ** Synopsis: typecheck(r[P1@P2]) ** ** Apply affinities to the range of P2 registers beginning with P1. ** Take the affinities from the Table object in P4. If any value ** cannot be coerced into the correct type, then raise an error. @@ -90344,15 +89331,10 @@ ** ** This opcode is similar to OP_Affinity except that this opcode ** forces the register type to the Table column type. This is used ** to implement "strict affinity". ** -** GENERATED ALWAYS AS ... STATIC columns are only checked if P3 -** is zero. When P3 is non-zero, no type checking occurs for -** static generated columns. Virtual columns are computed at query time -** and so they are never checked. -** ** Preconditions: ** **
    **
  • P2 should be the number of non-virtual columns in the ** table of P4. @@ -90371,14 +89353,11 @@ assert( pTab->tabFlags & TF_Strict ); assert( pTab->nNVCol==pOp->p2 ); aCol = pTab->aCol; pIn1 = &aMem[pOp->p1]; for(i=0; inCol; i++){ - if( aCol[i].colFlags & COLFLAG_GENERATED ){ - if( aCol[i].colFlags & COLFLAG_VIRTUAL ) continue; - if( pOp->p3 ){ pIn1++; continue; } - } + if( aCol[i].colFlags & COLFLAG_VIRTUAL ) continue; assert( pIn1 < &aMem[pOp->p1+pOp->p2] ); applyAffinity(pIn1, aCol[i].affinity, encoding); if( (pIn1->flags & MEM_Null)==0 ){ switch( aCol[i].eCType ){ case COLTYPE_BLOB: { @@ -90393,12 +89372,10 @@ case COLTYPE_TEXT: { if( (pIn1->flags & MEM_Str)==0 ) goto vdbe_type_error; break; } case COLTYPE_REAL: { - testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_Real ); - testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_IntReal ); if( pIn1->flags & MEM_Int ){ /* When applying REAL affinity, if the result is still an MEM_Int ** that will fit in 6 bytes, then change the type to MEM_IntReal ** so that we keep the high-resolution integer value but know that ** the type really wants to be REAL. */ @@ -90412,11 +89389,11 @@ }else{ pIn1->u.r = (double)pIn1->u.i; pIn1->flags |= MEM_Real; pIn1->flags &= ~MEM_Int; } - }else if( (pIn1->flags & (MEM_Real|MEM_IntReal))==0 ){ + }else if( (pIn1->flags & MEM_Real)==0 ){ goto vdbe_type_error; } break; } default: { @@ -90651,11 +89628,11 @@ } nHdr++; testcase( uu==127 ); testcase( uu==128 ); testcase( uu==32767 ); testcase( uu==32768 ); testcase( uu==8388607 ); testcase( uu==8388608 ); - testcase( uu==2147483647 ); testcase( uu==2147483648LL ); + testcase( uu==2147483647 ); testcase( uu==2147483648 ); testcase( uu==140737488355327LL ); testcase( uu==140737488355328LL ); if( uu<=127 ){ if( (i&1)==i && file_format>=4 ){ pRec->uTemp = 8+(u32)uu; }else{ @@ -90779,11 +89756,11 @@ assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) ); REGISTER_TRACE(pOp->p3, pOut); break; } -/* Opcode: Count P1 P2 P3 * * +/* Opcode: Count P1 P2 p3 * * ** Synopsis: r[P2]=count() ** ** Store the number of entries (an integer value) in the table or index ** opened by cursor P1 in register P2. ** @@ -91100,20 +90077,12 @@ assert( p->bIsReader ); assert( p->readOnly==0 || pOp->p2==0 ); assert( pOp->p2>=0 && pOp->p2<=2 ); assert( pOp->p1>=0 && pOp->p1nDb ); assert( DbMaskTest(p->btreeMask, pOp->p1) ); - assert( rc==SQLITE_OK ); - if( pOp->p2 && (db->flags & (SQLITE_QueryOnly|SQLITE_CorruptRdOnly))!=0 ){ - if( db->flags & SQLITE_QueryOnly ){ - /* Writes prohibited by the "PRAGMA query_only=TRUE" statement */ - rc = SQLITE_READONLY; - }else{ - /* Writes prohibited due to a prior SQLITE_CORRUPT in the current - ** transaction */ - rc = SQLITE_CORRUPT; - } + if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){ + rc = SQLITE_READONLY; goto abort_due_to_error; } pBt = db->aDb[pOp->p1].pBt; if( pBt ){ @@ -91151,12 +90120,11 @@ p->nStmtDefCons = db->nDeferredCons; p->nStmtDefImmCons = db->nDeferredImmCons; } } assert( pOp->p5==0 || pOp->p4type==P4_INT32 ); - if( rc==SQLITE_OK - && pOp->p5 + if( pOp->p5 && (iMeta!=pOp->p3 || db->aDb[pOp->p1].pSchema->iGeneration!=pOp->p4.i) ){ /* ** IMPLEMENTATION-OF: R-03189-51135 As each SQL statement runs, the schema @@ -91249,11 +90217,10 @@ rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, pOp->p3); if( pOp->p2==BTREE_SCHEMA_VERSION ){ /* When the schema cookie changes, record the new cookie internally */ pDb->pSchema->schema_cookie = pOp->p3 - pOp->p5; db->mDbFlags |= DBFLAG_SchemaChange; - sqlite3FkClearTriggerCache(db, pOp->p1); }else if( pOp->p2==BTREE_FILE_FORMAT ){ /* Record changes in the file format */ pDb->pSchema->file_format = pOp->p3; } if( pOp->p1==1 ){ @@ -91427,13 +90394,12 @@ nField = pOp->p4.i; } assert( pOp->p1>=0 ); assert( nField>=0 ); testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */ - pCur = allocateCursor(p, pOp->p1, nField, CURTYPE_BTREE); + pCur = allocateCursor(p, pOp->p1, nField, iDb, CURTYPE_BTREE); if( pCur==0 ) goto no_mem; - pCur->iDb = iDb; pCur->nullRow = 1; pCur->isOrdered = 1; pCur->pgnoRoot = p2; #ifdef SQLITE_DEBUG pCur->wrFlag = wrFlag; @@ -91471,22 +90437,22 @@ pOrig = p->apCsr[pOp->p2]; assert( pOrig ); assert( pOrig->isEphemeral ); /* Only ephemeral cursors can be duplicated */ - pCx = allocateCursor(p, pOp->p1, pOrig->nField, CURTYPE_BTREE); + pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE); if( pCx==0 ) goto no_mem; pCx->nullRow = 1; pCx->isEphemeral = 1; pCx->pKeyInfo = pOrig->pKeyInfo; pCx->isTable = pOrig->isTable; pCx->pgnoRoot = pOrig->pgnoRoot; pCx->isOrdered = pOrig->isOrdered; - pCx->ub.pBtx = pOrig->ub.pBtx; + pCx->pBtx = pOrig->pBtx; pCx->hasBeenDuped = 1; pOrig->hasBeenDuped = 1; - rc = sqlite3BtreeCursor(pCx->ub.pBtx, pCx->pgnoRoot, BTREE_WRCSR, + rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR, pCx->pKeyInfo, pCx->uc.pCursor); /* The sqlite3BtreeCursor() routine can only fail for the first cursor ** opened for a database. Since there is already an open cursor when this ** opcode is run, the sqlite3BtreeCursor() cannot fail */ assert( rc==SQLITE_OK ); @@ -91548,55 +90514,55 @@ assert( aMem[pOp->p3].flags & MEM_Null ); aMem[pOp->p3].n = 0; aMem[pOp->p3].z = ""; } pCx = p->apCsr[pOp->p1]; - if( pCx && !pCx->hasBeenDuped && ALWAYS(pOp->p2<=pCx->nField) ){ + if( pCx && !pCx->hasBeenDuped ){ /* If the ephermeral table is already open and has no duplicates from ** OP_OpenDup, then erase all existing content so that the table is ** empty again, rather than creating a new table. */ assert( pCx->isEphemeral ); pCx->seqCount = 0; pCx->cacheStatus = CACHE_STALE; - rc = sqlite3BtreeClearTable(pCx->ub.pBtx, pCx->pgnoRoot, 0); + rc = sqlite3BtreeClearTable(pCx->pBtx, pCx->pgnoRoot, 0); }else{ - pCx = allocateCursor(p, pOp->p1, pOp->p2, CURTYPE_BTREE); + pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE); if( pCx==0 ) goto no_mem; pCx->isEphemeral = 1; - rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->ub.pBtx, + rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBtx, BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags); if( rc==SQLITE_OK ){ - rc = sqlite3BtreeBeginTrans(pCx->ub.pBtx, 1, 0); + rc = sqlite3BtreeBeginTrans(pCx->pBtx, 1, 0); if( rc==SQLITE_OK ){ /* If a transient index is required, create it by calling ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before ** opening it. If a transient table is required, just use the ** automatically created table with root-page 1 (an BLOB_INTKEY table). */ if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){ assert( pOp->p4type==P4_KEYINFO ); - rc = sqlite3BtreeCreateTable(pCx->ub.pBtx, &pCx->pgnoRoot, + rc = sqlite3BtreeCreateTable(pCx->pBtx, &pCx->pgnoRoot, BTREE_BLOBKEY | pOp->p5); if( rc==SQLITE_OK ){ assert( pCx->pgnoRoot==SCHEMA_ROOT+1 ); assert( pKeyInfo->db==db ); assert( pKeyInfo->enc==ENC(db) ); - rc = sqlite3BtreeCursor(pCx->ub.pBtx, pCx->pgnoRoot, BTREE_WRCSR, + rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR, pKeyInfo, pCx->uc.pCursor); } pCx->isTable = 0; }else{ pCx->pgnoRoot = SCHEMA_ROOT; - rc = sqlite3BtreeCursor(pCx->ub.pBtx, SCHEMA_ROOT, BTREE_WRCSR, + rc = sqlite3BtreeCursor(pCx->pBtx, SCHEMA_ROOT, BTREE_WRCSR, 0, pCx->uc.pCursor); pCx->isTable = 1; } } pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED); if( rc ){ - sqlite3BtreeClose(pCx->ub.pBtx); + sqlite3BtreeClose(pCx->pBtx); } } } if( rc ) goto abort_due_to_error; pCx->nullRow = 1; @@ -91616,11 +90582,11 @@ case OP_SorterOpen: { VdbeCursor *pCx; assert( pOp->p1>=0 ); assert( pOp->p2>=0 ); - pCx = allocateCursor(p, pOp->p1, pOp->p2, CURTYPE_SORTER); + pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_SORTER); if( pCx==0 ) goto no_mem; pCx->pKeyInfo = pOp->p4.pKeyInfo; assert( pCx->pKeyInfo->db==db ); assert( pCx->pKeyInfo->enc==ENC(db) ); rc = sqlite3VdbeSorterInit(db, pOp->p3, pCx); @@ -91665,11 +90631,11 @@ case OP_OpenPseudo: { VdbeCursor *pCx; assert( pOp->p1>=0 ); assert( pOp->p3>=0 ); - pCx = allocateCursor(p, pOp->p1, pOp->p3, CURTYPE_PSEUDO); + pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, CURTYPE_PSEUDO); if( pCx==0 ) goto no_mem; pCx->nullRow = 1; pCx->seekResult = pOp->p2; pCx->isTable = 1; /* Give this pseudo-cursor a fake BtCursor pointer so that pCx @@ -92711,11 +91677,11 @@ zDb = db->aDb[pC->iDb].zDbSName; pTab = pOp->p4.pTab; assert( (pOp->p5 & OPFLAG_ISNOOP) || HasRowid(pTab) ); }else{ pTab = 0; - zDb = 0; + zDb = 0; /* Not needed. Silence a compiler warning. */ } #ifdef SQLITE_ENABLE_PREUPDATE_HOOK /* Invoke the pre-update hook, if any */ if( pTab ){ @@ -92864,18 +91830,17 @@ pTab = pOp->p4.pTab; if( (pOp->p5 & OPFLAG_SAVEPOSITION)!=0 && pC->isTable ){ pC->movetoTarget = sqlite3BtreeIntegerKey(pC->uc.pCursor); } }else{ - zDb = 0; - pTab = 0; + zDb = 0; /* Not needed. Silence a compiler warning. */ + pTab = 0; /* Not needed. Silence a compiler warning. */ } #ifdef SQLITE_ENABLE_PREUPDATE_HOOK /* Invoke the pre-update-hook if required. */ - assert( db->xPreUpdateCallback==0 || pTab==pOp->p4.pTab ); - if( db->xPreUpdateCallback && pTab ){ + if( db->xPreUpdateCallback && pOp->p4.pTab ){ assert( !(opflags & OPFLAG_ISUPDATE) || HasRowid(pTab)==0 || (aMem[pOp->p3].flags & MEM_Int) ); sqlite3VdbePreUpdateHook(p, pC, @@ -92912,11 +91877,11 @@ if( rc ) goto abort_due_to_error; /* Invoke the update-hook if required. */ if( opflags & OPFLAG_NCHANGE ){ p->nChange++; - if( db->xUpdateCallback && ALWAYS(pTab!=0) && HasRowid(pTab) ){ + if( db->xUpdateCallback && HasRowid(pTab) ){ db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, zDb, pTab->zName, pC->movetoTarget); assert( pC->iDb>=0 ); } } @@ -93117,14 +92082,10 @@ /* Opcode: NullRow P1 * * * * ** ** Move the cursor P1 to a null row. Any OP_Column operations ** that occur while the cursor is on the null row will always ** write a NULL. -** -** Or, if P1 is a Pseudo-Cursor (a cursor opened using OP_OpenPseudo) -** just reset the cache for that cursor. This causes the row of -** content held by the pseudo-cursor to be reparsed. */ case OP_NullRow: { VdbeCursor *pC; assert( pOp->p1>=0 && pOp->p1nCursor ); @@ -93609,13 +92570,13 @@ assert( pTabCur->isTable ); pTabCur->nullRow = 0; pTabCur->movetoTarget = rowid; pTabCur->deferredMoveto = 1; assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 ); - assert( !pTabCur->isEphemeral ); - pTabCur->ub.aAltMap = pOp->p4.ai; + pTabCur->aAltMap = pOp->p4.ai; assert( !pC->isEphemeral ); + assert( !pTabCur->isEphemeral ); pTabCur->pAltCursor = pC; }else{ pOut = out2Prerelease(p, pOp); pOut->u.i = rowid; } @@ -93964,11 +92925,11 @@ db->mDbFlags |= DBFLAG_SchemaChange; p->expired = 0; }else #endif { - zSchema = LEGACY_SCHEMA_TABLE; + zSchema = DFLT_SCHEMA_TABLE; initData.db = db; initData.iDb = iDb; initData.pzErrMsg = &p->zErrMsg; initData.mInitFlags = 0; initData.mxPage = sqlite3BtreeLastPage(db->aDb[iDb].pBt); @@ -95133,11 +94094,11 @@ /* Initialize sqlite3_vtab_cursor base class */ pVCur->pVtab = pVtab; /* Initialize vdbe cursor object */ - pCur = allocateCursor(p, pOp->p1, 0, CURTYPE_VTAB); + pCur = allocateCursor(p, pOp->p1, 0, -1, CURTYPE_VTAB); if( pCur ){ pCur->uc.pVCur = pVCur; pVtab->nRef++; }else{ assert( db->mallocFailed ); @@ -95145,38 +94106,10 @@ goto no_mem; } break; } #endif /* SQLITE_OMIT_VIRTUALTABLE */ - -#ifndef SQLITE_OMIT_VIRTUALTABLE -/* Opcode: VInitIn P1 P2 P3 * * -** Synopsis: r[P2]=ValueList(P1,P3) -** -** Set register P2 to be a pointer to a ValueList object for cursor P1 -** with cache register P3 and output register P3+1. This ValueList object -** can be used as the first argument to sqlite3_vtab_in_first() and -** sqlite3_vtab_in_next() to extract all of the values stored in the P1 -** cursor. Register P3 is used to hold the values returned by -** sqlite3_vtab_in_first() and sqlite3_vtab_in_next(). -*/ -case OP_VInitIn: { /* out2 */ - VdbeCursor *pC; /* The cursor containing the RHS values */ - ValueList *pRhs; /* New ValueList object to put in reg[P2] */ - - pC = p->apCsr[pOp->p1]; - pRhs = sqlite3_malloc64( sizeof(*pRhs) ); - if( pRhs==0 ) goto no_mem; - pRhs->pCsr = pC->uc.pCursor; - pRhs->pOut = &aMem[pOp->p3]; - pOut = out2Prerelease(p, pOp); - pOut->flags = MEM_Null; - sqlite3VdbeMemSetPointer(pOut, pRhs, "ValueList", sqlite3_free); - break; -} -#endif /* SQLITE_OMIT_VIRTUALTABLE */ - #ifndef SQLITE_OMIT_VIRTUALTABLE /* Opcode: VFilter P1 P2 P3 P4 * ** Synopsis: iplan=r[P3] zplan='P4' ** @@ -95212,11 +94145,10 @@ pQuery = &aMem[pOp->p3]; pArgc = &pQuery[1]; pCur = p->apCsr[pOp->p1]; assert( memIsValid(pQuery) ); REGISTER_TRACE(pOp->p3, pQuery); - assert( pCur!=0 ); assert( pCur->eCurType==CURTYPE_VTAB ); pVCur = pCur->uc.pVCur; pVtab = pVCur->pVtab; pModule = pVtab->pModule; @@ -95261,11 +94193,10 @@ const sqlite3_module *pModule; Mem *pDest; sqlite3_context sContext; VdbeCursor *pCur = p->apCsr[pOp->p1]; - assert( pCur!=0 ); assert( pCur->eCurType==CURTYPE_VTAB ); assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) ); pDest = &aMem[pOp->p3]; memAboutToChange(p, pDest); if( pCur->nullRow ){ @@ -95315,11 +94246,10 @@ const sqlite3_module *pModule; int res; VdbeCursor *pCur; pCur = p->apCsr[pOp->p1]; - assert( pCur!=0 ); assert( pCur->eCurType==CURTYPE_VTAB ); if( pCur->nullRow ){ break; } pVtab = pCur->uc.pVCur->pVtab; @@ -95411,11 +94341,11 @@ case OP_VUpdate: { sqlite3_vtab *pVtab; const sqlite3_module *pModule; int nArg; int i; - sqlite_int64 rowid = 0; + sqlite_int64 rowid; Mem **apArg; Mem *pX; assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace @@ -95596,81 +94526,10 @@ if( sqlite3VdbeMemTooBig(pOut) ) goto too_big; } REGISTER_TRACE(pOp->p3, pOut); UPDATE_MAX_BLOBSIZE(pOut); - break; -} - -/* Opcode: FilterAdd P1 * P3 P4 * -** Synopsis: filter(P1) += key(P3@P4) -** -** Compute a hash on the P4 registers starting with r[P3] and -** add that hash to the bloom filter contained in r[P1]. -*/ -case OP_FilterAdd: { - u64 h; - - assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) ); - pIn1 = &aMem[pOp->p1]; - assert( pIn1->flags & MEM_Blob ); - assert( pIn1->n>0 ); - h = filterHash(aMem, pOp); -#ifdef SQLITE_DEBUG - if( db->flags&SQLITE_VdbeTrace ){ - int ii; - for(ii=pOp->p3; iip3+pOp->p4.i; ii++){ - registerTrace(ii, &aMem[ii]); - } - printf("hash: %llu modulo %d -> %u\n", h, pIn1->n, (int)(h%pIn1->n)); - } -#endif - h %= pIn1->n; - pIn1->z[h/8] |= 1<<(h&7); - break; -} - -/* Opcode: Filter P1 P2 P3 P4 * -** Synopsis: if key(P3@P4) not in filter(P1) goto P2 -** -** Compute a hash on the key contained in the P4 registers starting -** with r[P3]. Check to see if that hash is found in the -** bloom filter hosted by register P1. If it is not present then -** maybe jump to P2. Otherwise fall through. -** -** False negatives are harmless. It is always safe to fall through, -** even if the value is in the bloom filter. A false negative causes -** more CPU cycles to be used, but it should still yield the correct -** answer. However, an incorrect answer may well arise from a -** false positive - if the jump is taken when it should fall through. -*/ -case OP_Filter: { /* jump */ - u64 h; - - assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) ); - pIn1 = &aMem[pOp->p1]; - assert( (pIn1->flags & MEM_Blob)!=0 ); - assert( pIn1->n >= 1 ); - h = filterHash(aMem, pOp); -#ifdef SQLITE_DEBUG - if( db->flags&SQLITE_VdbeTrace ){ - int ii; - for(ii=pOp->p3; iip3+pOp->p4.i; ii++){ - registerTrace(ii, &aMem[ii]); - } - printf("hash: %llu modulo %d -> %u\n", h, pIn1->n, (int)(h%pIn1->n)); - } -#endif - h %= pIn1->n; - if( (pIn1->z[h/8] & (1<<(h&7)))==0 ){ - VdbeBranchTaken(1, 2); - p->aCounter[SQLITE_STMTSTATUS_FILTER_HIT]++; - goto jump_to_p2; - }else{ - p->aCounter[SQLITE_STMTSTATUS_FILTER_MISS]++; - VdbeBranchTaken(0, 2); - } break; } /* Opcode: Trace P1 P2 * P4 * ** @@ -95929,18 +94788,11 @@ rc = SQLITE_CORRUPT_BKPT; } assert( rc ); #ifdef SQLITE_DEBUG if( db->flags & SQLITE_VdbeTrace ){ - const char *zTrace = p->zSql; - if( zTrace==0 ){ - if( aOp[0].opcode==OP_Trace ){ - zTrace = aOp[0].p4.z; - } - if( zTrace==0 ) zTrace = "???"; - } - printf("ABORT-due-to-error (rc=%d): %s\n", rc, zTrace); + printf("ABORT-due-to-error. rc=%d\n", rc); } #endif if( p->zErrMsg==0 && rc!=SQLITE_IOERR_NOMEM ){ sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc)); } @@ -95949,13 +94801,10 @@ testcase( sqlite3GlobalConfig.xLog!=0 ); sqlite3_log(rc, "statement aborts at %d: [%s] %s", (int)(pOp - aOp), p->zSql, p->zErrMsg); sqlite3VdbeHalt(p); if( rc==SQLITE_IOERR_NOMEM ) sqlite3OomFault(db); - if( rc==SQLITE_CORRUPT && db->autoCommit==0 ){ - db->flags |= SQLITE_CorruptRdOnly; - } rc = SQLITE_ERROR; if( resetSchemaOnFault>0 ){ sqlite3ResetOneSchema(db, resetSchemaOnFault-1); } @@ -96083,14 +94932,11 @@ }else{ rc = sqlite3_step(p->pStmt); } if( rc==SQLITE_ROW ){ VdbeCursor *pC = v->apCsr[0]; - u32 type; - assert( pC!=0 ); - assert( pC->eCurType==CURTYPE_BTREE ); - type = pC->nHdrParsed>p->iCol ? pC->aType[p->iCol] : 0; + u32 type = pC->nHdrParsed>p->iCol ? pC->aType[p->iCol] : 0; testcase( pC->nHdrParsed==p->iCol ); testcase( pC->nHdrParsed==p->iCol+1 ); if( type<12 ){ zErr = sqlite3MPrintf(p->db, "cannot open value of type %s", type==0?"null": type==7?"real": "integer" @@ -96160,13 +95006,14 @@ wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */ sqlite3_mutex_enter(db->mutex); pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob)); - while(1){ - sqlite3ParseObjectInit(&sParse,db); + do { + memset(&sParse, 0, sizeof(Parse)); if( !pBlob ) goto blob_open_out; + sParse.db = db; sqlite3DbFree(db, zErr); zErr = 0; sqlite3BtreeEnterAll(db); pTab = sqlite3LocateTable(&sParse, 0, zTable, zDb); @@ -96222,11 +95069,11 @@ /* Check that the column is not part of an FK child key definition. It ** is not necessary to check if it is part of a parent key, as parent ** key columns must be indexed. The check below will pick up this ** case. */ FKey *pFKey; - assert( IsOrdinaryTable(pTab) ); + assert( !IsVirtual(pTab) ); for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ int j; for(j=0; jnCol; j++){ if( pFKey->aCol[j].iFrom==iCol ){ zFault = "foreign key"; @@ -96339,13 +95186,11 @@ sqlite3BtreeLeaveAll(db); if( db->mallocFailed ){ goto blob_open_out; } rc = blobSeekToRow(pBlob, iRow, &zErr); - if( (++nAttempt)>=SQLITE_MAX_SCHEMA_RETRY || rc!=SQLITE_SCHEMA ) break; - sqlite3ParseObjectReset(&sParse); - } + } while( (++nAttempt)mallocFailed==0 ){ *ppBlob = (sqlite3_blob *)pBlob; }else{ @@ -96352,11 +95197,11 @@ if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt); sqlite3DbFree(db, pBlob); } sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr); sqlite3DbFree(db, zErr); - sqlite3ParseObjectReset(&sParse); + sqlite3ParserReset(&sParse); rc = sqlite3ApiExit(db, rc); sqlite3_mutex_leave(db->mutex); return rc; } @@ -96432,12 +95277,10 @@ ** using the incremental-blob API, this works. For the sessions module ** anyhow. */ sqlite3_int64 iKey; iKey = sqlite3BtreeIntegerKey(p->pCsr); - assert( v->apCsr[0]!=0 ); - assert( v->apCsr[0]->eCurType==CURTYPE_BTREE ); sqlite3VdbePreUpdateHook( v, v->apCsr[0], SQLITE_DELETE, p->zDb, p->pTab, iKey, -1, p->iCol ); } #endif @@ -97487,12 +96330,11 @@ if( nWorker>=SORTER_MAX_MERGE_COUNT ){ nWorker = SORTER_MAX_MERGE_COUNT-1; } #endif - assert( pCsr->pKeyInfo ); - assert( !pCsr->isEphemeral ); + assert( pCsr->pKeyInfo && pCsr->pBtx==0 ); assert( pCsr->eCurType==CURTYPE_SORTER ); szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nKeyField-1)*sizeof(CollSeq*); sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask); pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo); @@ -97817,11 +96659,11 @@ void *p = 0; int chunksize = 4*1024; sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_CHUNK_SIZE, &chunksize); sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_SIZE_HINT, &nByte); sqlite3OsFetch(pFd, 0, (int)nByte, &p); - if( p ) sqlite3OsUnfetch(pFd, 0, p); + sqlite3OsUnfetch(pFd, 0, p); } } #else # define vdbeSorterExtendFile(x,y,z) #endif @@ -98535,11 +97377,10 @@ pTask->file2.iEof += pIncr->mxSz; }else{ vdbeMergeEngineFree(pMerger); rc = SQLITE_NOMEM_BKPT; } - assert( *ppOut!=0 || rc!=SQLITE_OK ); return rc; } #if SQLITE_MAX_WORKER_THREADS>0 /* @@ -99901,13 +98742,10 @@ } return rc; } -/* Forward reference */ -static int memjrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size); - /* ** Write data to the file. */ static int memjrnlWrite( sqlite3_file *pJfd, /* The journal file into which to write */ @@ -99934,24 +98772,26 @@ /* An in-memory journal file should only ever be appended to. Random ** access writes are not required. The only exception to this is when ** the in-memory journal is being used by a connection using the ** atomic-write optimization. In this case the first 28 bytes of the ** journal file may be written as part of committing the transaction. */ - assert( iOfst<=p->endpoint.iOffset ); - if( iOfst>0 && iOfst!=p->endpoint.iOffset ){ - memjrnlTruncate(pJfd, iOfst); - } + assert( iOfst==p->endpoint.iOffset || iOfst==0 ); +#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \ + || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE) if( iOfst==0 && p->pFirst ){ assert( p->nChunkSize>iAmt ); memcpy((u8*)p->pFirst->zChunk, zBuf, iAmt); - }else{ + }else +#else + assert( iOfst>0 || p->pFirst==0 ); +#endif + { while( nWrite>0 ){ FileChunk *pChunk = p->endpoint.pChunk; int iChunkOffset = (int)(p->endpoint.iOffset%p->nChunkSize); int iSpace = MIN(nWrite, p->nChunkSize - iChunkOffset); - assert( pChunk!=0 || iChunkOffset==0 ); if( iChunkOffset==0 ){ /* New chunk is required to extend the file. */ FileChunk *pNew = sqlite3_malloc(fileChunkSize(p->nChunkSize)); if( !pNew ){ return SQLITE_IOERR_NOMEM_BKPT; @@ -99962,15 +98802,14 @@ pChunk->pNext = pNew; }else{ assert( !p->pFirst ); p->pFirst = pNew; } - pChunk = p->endpoint.pChunk = pNew; + p->endpoint.pChunk = pNew; } - assert( pChunk!=0 ); - memcpy((u8*)pChunk->zChunk + iChunkOffset, zWrite, iSpace); + memcpy((u8*)p->endpoint.pChunk->zChunk + iChunkOffset, zWrite, iSpace); zWrite += iSpace; nWrite -= iSpace; p->endpoint.iOffset += iSpace; } } @@ -99990,11 +98829,11 @@ if( size==0 ){ memjrnlFreeChunks(p->pFirst); p->pFirst = 0; }else{ i64 iOff = p->nChunkSize; - for(pIter=p->pFirst; ALWAYS(pIter) && iOffpNext){ + for(pIter=p->pFirst; ALWAYS(pIter) && iOff<=size; pIter=pIter->pNext){ iOff += p->nChunkSize; } if( ALWAYS(pIter) ){ memjrnlFreeChunks(pIter->pNext); pIter->pNext = 0; @@ -100239,11 +99078,11 @@ if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort; if( pExpr->pRight ){ assert( !ExprHasProperty(pExpr, EP_WinFunc) ); pExpr = pExpr->pRight; continue; - }else if( ExprUseXSelect(pExpr) ){ + }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){ assert( !ExprHasProperty(pExpr, EP_WinFunc) ); if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort; }else{ if( pExpr->x.pList ){ if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort; @@ -100511,11 +99350,10 @@ sqlite3ExprDelete(db, pDup); pDup = 0; }else{ incrAggFunctionDepth(pDup, nSubquery); if( pExpr->op==TK_COLLATE ){ - assert( !ExprHasProperty(pExpr, EP_IntValue) ); pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken); } /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This ** prevents ExprDelete() from deleting the Expr structure itself, @@ -100615,11 +99453,10 @@ SQLITE_PRIVATE Bitmask sqlite3ExprColUsed(Expr *pExpr){ int n; Table *pExTab; n = pExpr->iColumn; - assert( ExprUseYTab(pExpr) ); pExTab = pExpr->y.pTab; assert( pExTab!=0 ); if( (pExTab->tabFlags & TF_HasGenerated)!=0 && (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0 ){ @@ -100744,21 +99581,19 @@ hit = 1; } } if( hit || zTab==0 ) continue; } - if( zDb ){ - if( pTab->pSchema!=pSchema ) continue; - if( pSchema==0 && strcmp(zDb,"*")!=0 ) continue; + if( zDb && pTab->pSchema!=pSchema ){ + continue; } if( zTab ){ const char *zTabName = pItem->zAlias ? pItem->zAlias : pTab->zName; assert( zTabName!=0 ); if( sqlite3StrICmp(zTabName, zTab)!=0 ){ continue; } - assert( ExprUseYTab(pExpr) ); if( IN_RENAME_OBJECT && pItem->zAlias ){ sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab); } } hCol = sqlite3StrIHash(zCol); @@ -100786,11 +99621,10 @@ pMatch = pItem; } } if( pMatch ){ pExpr->iTable = pMatch->iCursor; - assert( ExprUseYTab(pExpr) ); pExpr->y.pTab = pMatch->pTab; /* RIGHT JOIN not (yet) supported */ assert( (pMatch->fg.jointype & JT_RIGHT)==0 ); if( (pMatch->fg.jointype & JT_LEFT)!=0 ){ ExprSetProperty(pExpr, EP_CanBeNull); @@ -100860,11 +99694,10 @@ cnt++; pMatch = 0; #ifndef SQLITE_OMIT_UPSERT if( pExpr->iTable==EXCLUDED_TABLE_NUMBER ){ testcase( iCol==(-1) ); - assert( ExprUseYTab(pExpr) ); if( IN_RENAME_OBJECT ){ pExpr->iColumn = iCol; pExpr->y.pTab = pTab; eNewExprOp = TK_COLUMN; }else{ @@ -100873,15 +99706,13 @@ eNewExprOp = TK_REGISTER; } }else #endif /* SQLITE_OMIT_UPSERT */ { - assert( ExprUseYTab(pExpr) ); pExpr->y.pTab = pTab; if( pParse->bReturning ){ eNewExprOp = TK_REGISTER; - pExpr->op2 = TK_COLUMN; pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable + sqlite3TableColumnToStorage(pTab, iCol) + 1; }else{ pExpr->iColumn = (i16)iCol; eNewExprOp = TK_TRIGGER; @@ -100949,12 +99780,12 @@ if( pEList->a[j].eEName==ENAME_NAME && sqlite3_stricmp(zAs, zCol)==0 ){ Expr *pOrig; assert( pExpr->pLeft==0 && pExpr->pRight==0 ); - assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 ); - assert( ExprUseXSelect(pExpr)==0 || pExpr->x.pSelect==0 ); + assert( pExpr->x.pList==0 ); + assert( pExpr->x.pSelect==0 ); pOrig = pEList->a[j].pExpr; if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){ sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs); return WRC_Abort; } @@ -101022,11 +99853,11 @@ "double-quoted string literal: \"%w\"", zCol); #ifdef SQLITE_ENABLE_NORMALIZE sqlite3VdbeAddDblquoteStr(db, pParse->pVdbe, zCol); #endif pExpr->op = TK_STRING; - memset(&pExpr->y, 0, sizeof(pExpr->y)); + pExpr->y.pTab = 0; return WRC_Prune; } if( sqlite3ExprIdToTrueFalse(pExpr) ){ return WRC_Prune; } @@ -101044,11 +99875,10 @@ }else if( zTab ){ sqlite3ErrorMsg(pParse, "%s: %s.%s", zErr, zTab, zCol); }else{ sqlite3ErrorMsg(pParse, "%s: %s", zErr, zCol); } - sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr); pParse->checkSchema = 1; pTopNC->nNcErr++; } /* If a column from a table in pSrcList is referenced, then record @@ -101109,13 +99939,11 @@ */ SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){ Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0); if( p ){ SrcItem *pItem = &pSrc->a[iSrc]; - Table *pTab; - assert( ExprUseYTab(p) ); - pTab = p->y.pTab = pItem->pTab; + Table *pTab = p->y.pTab = pItem->pTab; p->iTable = pItem->iCursor; if( p->y.pTab->iPKey==iCol ){ p->iColumn = -1; }else{ p->iColumn = (ynVar)iCol; @@ -101153,12 +99981,11 @@ */ static void notValidImpl( Parse *pParse, /* Leave error message here */ NameContext *pNC, /* The name context */ const char *zMsg, /* Type of error */ - Expr *pExpr, /* Invalidate this expression on error */ - Expr *pError /* Associate error with this expression */ + Expr *pExpr /* Invalidate this expression on error */ ){ const char *zIn = "partial index WHERE clauses"; if( pNC->ncFlags & NC_IdxExpr ) zIn = "index expressions"; #ifndef SQLITE_OMIT_CHECK else if( pNC->ncFlags & NC_IsCheck ) zIn = "CHECK constraints"; @@ -101166,25 +99993,23 @@ #ifndef SQLITE_OMIT_GENERATED_COLUMNS else if( pNC->ncFlags & NC_GenCol ) zIn = "generated columns"; #endif sqlite3ErrorMsg(pParse, "%s prohibited in %s", zMsg, zIn); if( pExpr ) pExpr->op = TK_NULL; - sqlite3RecordErrorOffsetOfExpr(pParse->db, pError); } -#define sqlite3ResolveNotValid(P,N,M,X,E,R) \ +#define sqlite3ResolveNotValid(P,N,M,X,E) \ assert( ((X)&~(NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol))==0 ); \ - if( ((N)->ncFlags & (X))!=0 ) notValidImpl(P,N,M,E,R); + if( ((N)->ncFlags & (X))!=0 ) notValidImpl(P,N,M,E); /* ** Expression p should encode a floating point value between 1.0 and 0.0. ** Return 1024 times this value. Or return -1 if p is not a floating point ** value between 1.0 and 0.0. */ static int exprProbability(Expr *p){ double r = -1.0; if( p->op!=TK_FLOAT ) return -1; - assert( !ExprHasProperty(p, EP_IntValue) ); sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8); assert( r>=0.0 ); if( r>1.0 ) return -1; return (int)(r*134217728.0); } @@ -101229,11 +100054,10 @@ SrcList *pSrcList = pNC->pSrcList; SrcItem *pItem; assert( pSrcList && pSrcList->nSrc>=1 ); pItem = pSrcList->a; pExpr->op = TK_COLUMN; - assert( ExprUseYTab(pExpr) ); pExpr->y.pTab = pItem->pTab; pExpr->iTable = pItem->iCursor; pExpr->iColumn--; pExpr->affExpr = SQLITE_AFF_INTEGER; break; @@ -101262,11 +100086,10 @@ anRef[i] = p->nRef; } sqlite3WalkExpr(pWalker, pExpr->pLeft); if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){ testcase( ExprHasProperty(pExpr, EP_FromJoin) ); - assert( !ExprHasProperty(pExpr, EP_IntValue) ); if( pExpr->op==TK_NOTNULL ){ pExpr->u.zToken = "true"; ExprSetProperty(pExpr, EP_IsTrue); }else{ pExpr->u.zToken = "false"; @@ -101298,32 +100121,28 @@ Expr *pRight; if( pExpr->op==TK_ID ){ zDb = 0; zTable = 0; - assert( !ExprHasProperty(pExpr, EP_IntValue) ); zColumn = pExpr->u.zToken; }else{ Expr *pLeft = pExpr->pLeft; testcase( pNC->ncFlags & NC_IdxExpr ); testcase( pNC->ncFlags & NC_GenCol ); sqlite3ResolveNotValid(pParse, pNC, "the \".\" operator", - NC_IdxExpr|NC_GenCol, 0, pExpr); + NC_IdxExpr|NC_GenCol, 0); pRight = pExpr->pRight; if( pRight->op==TK_ID ){ zDb = 0; }else{ assert( pRight->op==TK_DOT ); - assert( !ExprHasProperty(pRight, EP_IntValue) ); zDb = pLeft->u.zToken; pLeft = pRight->pLeft; pRight = pRight->pRight; } - assert( ExprUseUToken(pLeft) && ExprUseUToken(pRight) ); zTable = pLeft->u.zToken; zColumn = pRight->u.zToken; - assert( ExprUseYTab(pExpr) ); if( IN_RENAME_OBJECT ){ sqlite3RenameTokenRemap(pParse, (void*)pExpr, (void*)pRight); sqlite3RenameTokenRemap(pParse, (void*)&pExpr->y.pTab, (void*)pLeft); } } @@ -101336,19 +100155,21 @@ ExprList *pList = pExpr->x.pList; /* The argument list */ int n = pList ? pList->nExpr : 0; /* Number of arguments */ int no_such_func = 0; /* True if no such function exists */ int wrong_num_args = 0; /* True if wrong number of arguments */ int is_agg = 0; /* True if is an aggregate function */ + int nId; /* Number of characters in function name */ const char *zId; /* The function name. */ FuncDef *pDef; /* Information about the function */ u8 enc = ENC(pParse->db); /* The database encoding */ int savedAllowFlags = (pNC->ncFlags & (NC_AllowAgg | NC_AllowWin)); #ifndef SQLITE_OMIT_WINDOWFUNC Window *pWin = (IsWindowFunc(pExpr) ? pExpr->y.pWin : 0); #endif - assert( !ExprHasProperty(pExpr, EP_xIsSelect|EP_IntValue) ); + assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); zId = pExpr->u.zToken; + nId = sqlite3Strlen30(zId); pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0); if( pDef==0 ){ pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0); if( pDef==0 ){ no_such_func = 1; @@ -101361,12 +100182,12 @@ ExprSetProperty(pExpr, EP_Unlikely); if( n==2 ){ pExpr->iTable = exprProbability(pList->a[1].pExpr); if( pExpr->iTable<0 ){ sqlite3ErrorMsg(pParse, - "second argument to %#T() must be a " - "constant between 0.0 and 1.0", pExpr); + "second argument to likelihood() must be a " + "constant between 0.0 and 1.0"); pNC->nNcErr++; } }else{ /* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is ** equivalent to likelihood(X, 0.0625). @@ -101383,12 +100204,12 @@ #ifndef SQLITE_OMIT_AUTHORIZATION { int auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0,pDef->zName,0); if( auth!=SQLITE_OK ){ if( auth==SQLITE_DENY ){ - sqlite3ErrorMsg(pParse, "not authorized to use function: %#T", - pExpr); + sqlite3ErrorMsg(pParse, "not authorized to use function: %s", + pDef->zName); pNC->nNcErr++; } pExpr->op = TK_NULL; return WRC_Prune; } @@ -101407,11 +100228,11 @@ ** sqlite_version() that might change over time cannot be used ** in an index or generated column. Curiously, they can be used ** in a CHECK constraint. SQLServer, MySQL, and PostgreSQL all ** all this. */ sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions", - NC_IdxExpr|NC_PartIdx|NC_GenCol, 0, pExpr); + NC_IdxExpr|NC_PartIdx|NC_GenCol, 0); }else{ assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */ pExpr->op2 = pNC->ncFlags & NC_SelfRef; if( pNC->ncFlags & NC_FromDDL ) ExprSetProperty(pExpr, EP_FromDDL); } @@ -101420,11 +100241,11 @@ && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0 ){ /* Internal-use-only functions are disallowed unless the ** SQL is being compiled using sqlite3NestedParse() or ** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be - ** used to activate internal functions for testing purposes */ + ** used to activate internal functionsn for testing purposes */ no_such_func = 1; pDef = 0; }else if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0 && !IN_RENAME_OBJECT @@ -101439,11 +100260,11 @@ || (pDef->xValue==0 && pDef->xInverse==0) || (pDef->xValue && pDef->xInverse && pDef->xSFunc && pDef->xFinalize) ); if( pDef && pDef->xValue==0 && pWin ){ sqlite3ErrorMsg(pParse, - "%#T() may not be used as a window function", pExpr + "%.*s() may not be used as a window function", nId, zId ); pNC->nNcErr++; }else if( (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) || (is_agg && (pDef->funcFlags&SQLITE_FUNC_WINDOW) && !pWin) @@ -101453,38 +100274,38 @@ if( (pDef->funcFlags & SQLITE_FUNC_WINDOW) || pWin ){ zType = "window"; }else{ zType = "aggregate"; } - sqlite3ErrorMsg(pParse, "misuse of %s function %#T()",zType,pExpr); + sqlite3ErrorMsg(pParse, "misuse of %s function %.*s()",zType,nId,zId); pNC->nNcErr++; is_agg = 0; } #else if( (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) ){ - sqlite3ErrorMsg(pParse,"misuse of aggregate function %#T()",pExpr); + sqlite3ErrorMsg(pParse,"misuse of aggregate function %.*s()",nId,zId); pNC->nNcErr++; is_agg = 0; } #endif else if( no_such_func && pParse->db->init.busy==0 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION && pParse->explain==0 #endif ){ - sqlite3ErrorMsg(pParse, "no such function: %#T", pExpr); + sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId); pNC->nNcErr++; }else if( wrong_num_args ){ - sqlite3ErrorMsg(pParse,"wrong number of arguments to function %#T()", - pExpr); + sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()", + nId, zId); pNC->nNcErr++; } #ifndef SQLITE_OMIT_WINDOWFUNC else if( is_agg==0 && ExprHasProperty(pExpr, EP_WinFunc) ){ sqlite3ErrorMsg(pParse, - "FILTER may not be used with non-aggregate %#T()", - pExpr + "FILTER may not be used with non-aggregate %.*s()", + nId, zId ); pNC->nNcErr++; } #endif if( is_agg ){ @@ -101506,11 +100327,11 @@ sqlite3WalkExprList(pWalker, pList); if( is_agg ){ #ifndef SQLITE_OMIT_WINDOWFUNC if( pWin ){ Select *pSel = pNC->pWinSelect; - assert( pWin==0 || (ExprUseYWin(pExpr) && pWin==pExpr->y.pWin) ); + assert( pWin==pExpr->y.pWin ); if( IN_RENAME_OBJECT==0 ){ sqlite3WindowUpdate(pParse, pSel ? pSel->pWinDefn : 0, pWin, pDef); if( pParse->db->mallocFailed ) break; } sqlite3WalkExprList(pWalker, pWin->pPartition); @@ -101519,22 +100340,19 @@ sqlite3WindowLink(pSel, pWin); pNC->ncFlags |= NC_HasWin; }else #endif /* SQLITE_OMIT_WINDOWFUNC */ { - NameContext *pNC2; /* For looping up thru outer contexts */ + NameContext *pNC2 = pNC; pExpr->op = TK_AGG_FUNCTION; pExpr->op2 = 0; #ifndef SQLITE_OMIT_WINDOWFUNC if( ExprHasProperty(pExpr, EP_WinFunc) ){ sqlite3WalkExpr(pWalker, pExpr->y.pWin->pFilter); } #endif - pNC2 = pNC; - while( pNC2 - && sqlite3ReferencesSrcList(pParse, pExpr, pNC2->pSrcList)==0 - ){ + while( pNC2 && !sqlite3FunctionUsesThisSrc(pExpr, pNC2->pSrcList) ){ pExpr->op2++; pNC2 = pNC2->pNext; } assert( pDef!=0 || IN_RENAME_OBJECT ); if( pNC2 && pDef ){ @@ -101558,18 +100376,18 @@ case TK_SELECT: case TK_EXISTS: testcase( pExpr->op==TK_EXISTS ); #endif case TK_IN: { testcase( pExpr->op==TK_IN ); - if( ExprUseXSelect(pExpr) ){ + if( ExprHasProperty(pExpr, EP_xIsSelect) ){ int nRef = pNC->nRef; testcase( pNC->ncFlags & NC_IsCheck ); testcase( pNC->ncFlags & NC_PartIdx ); testcase( pNC->ncFlags & NC_IdxExpr ); testcase( pNC->ncFlags & NC_GenCol ); if( pNC->ncFlags & NC_SelfRef ){ - notValidImpl(pParse, pNC, "subqueries", pExpr, pExpr); + notValidImpl(pParse, pNC, "subqueries", pExpr); }else{ sqlite3WalkSelect(pWalker, pExpr->x.pSelect); } assert( pNC->nRef>=nRef ); if( nRef!=pNC->nRef ){ @@ -101583,11 +100401,11 @@ testcase( pNC->ncFlags & NC_IsCheck ); testcase( pNC->ncFlags & NC_PartIdx ); testcase( pNC->ncFlags & NC_IdxExpr ); testcase( pNC->ncFlags & NC_GenCol ); sqlite3ResolveNotValid(pParse, pNC, "parameters", - NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol, pExpr, pExpr); + NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol, pExpr); break; } case TK_IS: case TK_ISNOT: { Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight); @@ -101615,11 +100433,10 @@ int nLeft, nRight; if( pParse->db->mallocFailed ) break; assert( pExpr->pLeft!=0 ); nLeft = sqlite3ExprVectorSize(pExpr->pLeft); if( pExpr->op==TK_BETWEEN ){ - assert( ExprUseXList(pExpr) ); nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[0].pExpr); if( nRight==nLeft ){ nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[1].pExpr); } }else{ @@ -101635,17 +100452,15 @@ testcase( pExpr->op==TK_GE ); testcase( pExpr->op==TK_IS ); testcase( pExpr->op==TK_ISNOT ); testcase( pExpr->op==TK_BETWEEN ); sqlite3ErrorMsg(pParse, "row value misused"); - sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr); } break; } } - assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 ); - return pParse->nErr ? WRC_Abort : WRC_Continue; + return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue; } /* ** pEList is a list of expressions which are really the result set of the ** a SELECT statement. pE is a term in an ORDER BY or GROUP BY clause. @@ -101666,13 +100481,11 @@ int i; /* Loop counter */ UNUSED_PARAMETER(pParse); if( pE->op==TK_ID ){ - const char *zCol; - assert( !ExprHasProperty(pE, EP_IntValue) ); - zCol = pE->u.zToken; + char *zCol = pE->u.zToken; for(i=0; inExpr; i++){ if( pEList->a[i].eEName==ENAME_NAME && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0 ){ return i+1; @@ -101749,17 +100562,15 @@ */ static void resolveOutOfRangeError( Parse *pParse, /* The error context into which to write the error */ const char *zType, /* "ORDER" or "GROUP" */ int i, /* The index (1-based) of the term out of range */ - int mx, /* Largest permissible value of i */ - Expr *pError /* Associate the error with the expression */ + int mx /* Largest permissible value of i */ ){ sqlite3ErrorMsg(pParse, "%r %s BY term out of range - should be " "between 1 and %d", i, zType, mx); - sqlite3RecordErrorOffsetOfExpr(pParse->db, pError); } /* ** Analyze the ORDER BY clause in a compound SELECT statement. Modify ** each term of the ORDER BY clause is a constant integer between 1 @@ -101811,11 +100622,11 @@ if( pItem->done ) continue; pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr); if( NEVER(pE==0) ) continue; if( sqlite3ExprIsInteger(pE, &iCol) ){ if( iCol<=0 || iCol>pEList->nExpr ){ - resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr, pE); + resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr); return 1; } }else{ iCol = resolveAsName(pParse, pEList, pE); if( iCol==0 ){ @@ -101907,11 +100718,11 @@ pEList = pSelect->pEList; assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */ for(i=0, pItem=pOrderBy->a; inExpr; i++, pItem++){ if( pItem->u.x.iOrderByCol ){ if( pItem->u.x.iOrderByCol>pEList->nExpr ){ - resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr, 0); + resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr); return 1; } resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr,0); } } @@ -101999,11 +100810,11 @@ if( sqlite3ExprIsInteger(pE2, &iCol) ){ /* The ORDER BY term is an integer constant. Again, set the column ** number so that sqlite3ResolveOrderGroupBy() will convert the ** order-by term to a copy of the result-set expression */ if( iCol<1 || iCol>0xffff ){ - resolveOutOfRangeError(pParse, zType, i+1, nResult, pE2); + resolveOutOfRangeError(pParse, zType, i+1, nResult); return 1; } pItem->u.x.iOrderByCol = (u16)iCol; continue; } @@ -102057,11 +100868,11 @@ ** sqlite3SelectPrep() will invoke both sqlite3SelectExpand() and ** this routine in the correct order. */ if( (p->selFlags & SF_Expanded)==0 ){ sqlite3SelectPrep(pParse, p, pOuterNC); - return pParse->nErr ? WRC_Abort : WRC_Prune; + return (pParse->nErr || db->mallocFailed) ? WRC_Abort : WRC_Prune; } isCompound = p->pPrior!=0; nCompound = 0; pLeftmost = p; @@ -102105,12 +100916,11 @@ const char *zSavedContext = pParse->zAuthContext; if( pItem->zName ) pParse->zAuthContext = pItem->zName; sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC); pParse->zAuthContext = zSavedContext; - if( pParse->nErr ) return WRC_Abort; - assert( db->mallocFailed==0 ); + if( pParse->nErr || db->mallocFailed ) return WRC_Abort; /* If the number of references to the outer context changed when ** expressions in the sub-select were resolved, the sub-select ** is correlated. It is not required to check the refcount on any ** but the innermost outer context object, as lookupName() increments @@ -102505,12 +101315,12 @@ /* ** Return the affinity character for a single column of a table. */ SQLITE_PRIVATE char sqlite3TableColumnAffinity(const Table *pTab, int iCol){ - if( iCol<0 || NEVER(iCol>=pTab->nCol) ) return SQLITE_AFF_INTEGER; - return pTab->aCol[iCol].affinity; + assert( iColnCol ); + return iCol>=0 ? pTab->aCol[iCol].affinity : SQLITE_AFF_INTEGER; } /* ** Return the 'affinity' of the expression pExpr if any. ** @@ -102536,18 +101346,15 @@ pExpr = pExpr->pLeft; assert( pExpr!=0 ); } op = pExpr->op; if( op==TK_REGISTER ) op = pExpr->op2; - if( op==TK_COLUMN || op==TK_AGG_COLUMN ){ - assert( ExprUseYTab(pExpr) ); - if( pExpr->y.pTab ){ - return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn); - } + if( (op==TK_COLUMN || op==TK_AGG_COLUMN) && pExpr->y.pTab ){ + return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn); } if( op==TK_SELECT ){ - assert( ExprUseXSelect(pExpr) ); + assert( pExpr->flags&EP_xIsSelect ); assert( pExpr->x.pSelect!=0 ); assert( pExpr->x.pSelect->pEList!=0 ); assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 ); return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr); } @@ -102556,19 +101363,18 @@ assert( !ExprHasProperty(pExpr, EP_IntValue) ); return sqlite3AffinityType(pExpr->u.zToken, 0); } #endif if( op==TK_SELECT_COLUMN ){ - assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) ); + assert( pExpr->pLeft->flags&EP_xIsSelect ); assert( pExpr->iColumn < pExpr->iTable ); assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr ); return sqlite3ExprAffinity( pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr ); } if( op==TK_VECTOR ){ - assert( ExprUseXList(pExpr) ); return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr); } return pExpr->affExpr; } @@ -102624,11 +101430,11 @@ ** expression. */ SQLITE_PRIVATE Expr *sqlite3ExprSkipCollateAndLikely(Expr *pExpr){ while( pExpr && ExprHasProperty(pExpr, EP_Skip|EP_Unlikely) ){ if( ExprHasProperty(pExpr, EP_Unlikely) ){ - assert( ExprUseXList(pExpr) ); + assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); assert( pExpr->x.pList->nExpr>0 ); assert( pExpr->op==TK_FUNCTION ); pExpr = pExpr->x.pList->a[0].pExpr; }else{ assert( pExpr->op==TK_COLLATE ); @@ -102657,46 +101463,45 @@ CollSeq *pColl = 0; const Expr *p = pExpr; while( p ){ int op = p->op; if( op==TK_REGISTER ) op = p->op2; - if( op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_TRIGGER ){ - assert( ExprUseYTab(p) ); - if( p->y.pTab!=0 ){ - /* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally - ** a TK_COLUMN but was previously evaluated and cached in a register */ - int j = p->iColumn; - if( j>=0 ){ - const char *zColl = sqlite3ColumnColl(&p->y.pTab->aCol[j]); - pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0); - } - break; - } + if( (op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_TRIGGER) + && p->y.pTab!=0 + ){ + /* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally + ** a TK_COLUMN but was previously evaluated and cached in a register */ + int j = p->iColumn; + if( j>=0 ){ + const char *zColl = sqlite3ColumnColl(&p->y.pTab->aCol[j]); + pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0); + } + break; } if( op==TK_CAST || op==TK_UPLUS ){ p = p->pLeft; continue; } if( op==TK_VECTOR ){ - assert( ExprUseXList(p) ); p = p->x.pList->a[0].pExpr; continue; } if( op==TK_COLLATE ){ - assert( !ExprHasProperty(p, EP_IntValue) ); pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken); break; } if( p->flags & EP_Collate ){ if( p->pLeft && (p->pLeft->flags & EP_Collate)!=0 ){ p = p->pLeft; }else{ Expr *pNext = p->pRight; /* The Expr.x union is never used at the same time as Expr.pRight */ - assert( ExprUseXList(p) ); assert( p->x.pList==0 || p->pRight==0 ); - if( p->x.pList!=0 && !db->mallocFailed ){ + if( p->x.pList!=0 + && !db->mallocFailed + && ALWAYS(!ExprHasProperty(p, EP_xIsSelect)) + ){ int i; for(i=0; ALWAYS(ix.pList->nExpr); i++){ if( ExprHasProperty(p->x.pList->a[i].pExpr, EP_Collate) ){ pNext = p->x.pList->a[i].pExpr; break; @@ -102775,11 +101580,11 @@ pExpr->op==TK_NE || pExpr->op==TK_IS || pExpr->op==TK_ISNOT ); assert( pExpr->pLeft ); aff = sqlite3ExprAffinity(pExpr->pLeft); if( pExpr->pRight ){ aff = sqlite3CompareAffinity(pExpr->pRight, aff); - }else if( ExprUseXSelect(pExpr) ){ + }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){ aff = sqlite3CompareAffinity(pExpr->x.pSelect->pEList->a[0].pExpr, aff); }else if( aff==0 ){ aff = SQLITE_AFF_BLOB; } return aff; @@ -102915,14 +101720,12 @@ */ SQLITE_PRIVATE int sqlite3ExprVectorSize(const Expr *pExpr){ u8 op = pExpr->op; if( op==TK_REGISTER ) op = pExpr->op2; if( op==TK_VECTOR ){ - assert( ExprUseXList(pExpr) ); return pExpr->x.pList->nExpr; }else if( op==TK_SELECT ){ - assert( ExprUseXSelect(pExpr) ); return pExpr->x.pSelect->pEList->nExpr; }else{ return 1; } } @@ -102945,14 +101748,12 @@ SQLITE_PRIVATE Expr *sqlite3VectorFieldSubexpr(Expr *pVector, int i){ assert( iop==TK_ERROR ); if( sqlite3ExprIsVector(pVector) ){ assert( pVector->op2==0 || pVector->op==TK_REGISTER ); if( pVector->op==TK_SELECT || pVector->op2==TK_SELECT ){ - assert( ExprUseXSelect(pVector) ); return pVector->x.pSelect->pEList->a[i].pExpr; }else{ - assert( ExprUseXList(pVector) ); return pVector->x.pList->a[i].pExpr; } } return pVector; } @@ -102984,11 +101785,11 @@ int iField, /* Which column of the vector to return */ int nField /* Total number of columns in the vector */ ){ Expr *pRet; if( pVector->op==TK_SELECT ){ - assert( ExprUseXSelect(pVector) ); + assert( pVector->flags & EP_xIsSelect ); /* The TK_SELECT_COLUMN Expr node: ** ** pLeft: pVector containing TK_SELECT. Not deleted. ** pRight: not used. But recursively deleted. ** iColumn: Index of a column in pVector @@ -103009,13 +101810,11 @@ pRet->iColumn = iField; pRet->pLeft = pVector; } }else{ if( pVector->op==TK_VECTOR ){ - Expr **ppVector; - assert( ExprUseXList(pVector) ); - ppVector = &pVector->x.pList->a[iField].pExpr; + Expr **ppVector = &pVector->x.pList->a[iField].pExpr; pVector = *ppVector; if( IN_RENAME_OBJECT ){ /* This must be a vector UPDATE inside a trigger */ *ppVector = 0; return pVector; @@ -103075,16 +101874,14 @@ if( op==TK_REGISTER ){ *ppExpr = sqlite3VectorFieldSubexpr(pVector, iField); return pVector->iTable+iField; } if( op==TK_SELECT ){ - assert( ExprUseXSelect(pVector) ); *ppExpr = pVector->x.pSelect->pEList->a[iField].pExpr; return regSelect+iField; } if( op==TK_VECTOR ){ - assert( ExprUseXList(pVector) ); *ppExpr = pVector->x.pList->a[iField].pExpr; return sqlite3ExprCodeTemp(pParse, *ppExpr, pRegFree); } return 0; } @@ -103252,13 +102049,14 @@ ** ** Also propagate EP_Propagate flags up from Expr.x.pList to Expr.flags, ** if appropriate. */ static void exprSetHeight(Expr *p){ - int nHeight = p->pLeft ? p->pLeft->nHeight : 0; - if( p->pRight && p->pRight->nHeight>nHeight ) nHeight = p->pRight->nHeight; - if( ExprUseXSelect(p) ){ + int nHeight = 0; + heightOfExpr(p->pLeft, &nHeight); + heightOfExpr(p->pRight, &nHeight); + if( ExprHasProperty(p, EP_xIsSelect) ){ heightOfSelect(p->x.pSelect, &nHeight); }else if( p->x.pList ){ heightOfExprList(p->x.pList, &nHeight); p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList); } @@ -103293,11 +102091,11 @@ ** Propagate all EP_Propagate flags from the Expr.x.pList into ** Expr.flags. */ SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){ if( pParse->nErr ) return; - if( p && ExprUseXList(p) && p->x.pList ){ + if( p && p->x.pList && !ExprHasProperty(p, EP_xIsSelect) ){ p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList); } } #define exprSetHeight(y) #endif /* SQLITE_MAX_EXPR_DEPTH>0 */ @@ -103477,24 +102275,17 @@ Select *pRet = 0; assert( nElem>1 ); for(ii=0; iinExpr; ii++){ Select *pSel; Expr *pExpr = pEList->a[ii].pExpr; - int nExprElem; - if( pExpr->op==TK_VECTOR ){ - assert( ExprUseXList(pExpr) ); - nExprElem = pExpr->x.pList->nExpr; - }else{ - nExprElem = 1; - } + int nExprElem = (pExpr->op==TK_VECTOR ? pExpr->x.pList->nExpr : 1); if( nExprElem!=nElem ){ sqlite3ErrorMsg(pParse, "IN(...) element has %d term%s - expected %d", nExprElem, nExprElem>1?"s":"", nElem ); break; } - assert( ExprUseXList(pExpr) ); pSel = sqlite3SelectNew(pParse, pExpr->x.pList, 0, 0, 0, 0, 0, SF_Values,0); pExpr->x.pList = 0; if( pSel ){ if( pRet ){ pSel->op = TK_ALL; @@ -103552,20 +102343,19 @@ pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1); if( pNew==0 ){ sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */ return 0; } - pNew->w.iOfst = (int)(pToken->z - pParse->zTail); if( pList && pList->nExpr > pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] && !pParse->nested ){ sqlite3ErrorMsg(pParse, "too many arguments on function %T", pToken); } pNew->x.pList = pList; ExprSetProperty(pNew, EP_HasFunc); - assert( ExprUseXList(pNew) ); + assert( !ExprHasProperty(pNew, EP_xIsSelect) ); sqlite3ExprSetHeightAndFlags(pParse, pNew); if( eDistinct==SF_Distinct ) ExprSetProperty(pNew, EP_Distinct); return pNew; } @@ -103596,11 +102386,11 @@ ** (2) not tagged with SQLITE_INNOCUOUS (which means it ** is tagged with SQLITE_FUNC_UNSAFE) and ** SQLITE_DBCONFIG_TRUSTED_SCHEMA is off (meaning ** that the schema is possibly tainted). */ - sqlite3ErrorMsg(pParse, "unsafe use of %#T()", pExpr); + sqlite3ErrorMsg(pParse, "unsafe use of %s()", pDef->zName); } } } /* @@ -103652,11 +102442,10 @@ testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 ); testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ); if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){ sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d", db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]); - sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr); return; } x = (ynVar)i; if( x>pParse->nVar ){ pParse->nVar = (int)x; @@ -103680,39 +102469,39 @@ } } pExpr->iColumn = x; if( x>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){ sqlite3ErrorMsg(pParse, "too many SQL variables"); - sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr); } } /* ** Recursively delete an expression tree. */ static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){ assert( p!=0 ); - assert( !ExprUseUValue(p) || p->u.iValue>=0 ); - assert( !ExprUseYWin(p) || !ExprUseYSub(p) ); - assert( !ExprUseYWin(p) || p->y.pWin!=0 || db->mallocFailed ); - assert( p->op!=TK_FUNCTION || !ExprUseYSub(p) ); + /* Sanity check: Assert that the IntValue is non-negative if it exists */ + assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 ); + + assert( !ExprHasProperty(p, EP_WinFunc) || p->y.pWin!=0 || db->mallocFailed ); + assert( p->op!=TK_FUNCTION || ExprHasProperty(p, EP_TokenOnly|EP_Reduced) + || p->y.pWin==0 || ExprHasProperty(p, EP_WinFunc) ); #ifdef SQLITE_DEBUG if( ExprHasProperty(p, EP_Leaf) && !ExprHasProperty(p, EP_TokenOnly) ){ assert( p->pLeft==0 ); assert( p->pRight==0 ); - assert( !ExprUseXSelect(p) || p->x.pSelect==0 ); - assert( !ExprUseXList(p) || p->x.pList==0 ); + assert( p->x.pSelect==0 ); } #endif if( !ExprHasProperty(p, (EP_TokenOnly|EP_Leaf)) ){ /* The Expr.x union is never used at the same time as Expr.pRight */ - assert( (ExprUseXList(p) && p->x.pList==0) || p->pRight==0 ); + assert( p->x.pList==0 || p->pRight==0 ); if( p->pLeft && p->op!=TK_SELECT_COLUMN ) sqlite3ExprDeleteNN(db, p->pLeft); if( p->pRight ){ assert( !ExprHasProperty(p, EP_WinFunc) ); sqlite3ExprDeleteNN(db, p->pRight); - }else if( ExprUseXSelect(p) ){ + }else if( ExprHasProperty(p, EP_xIsSelect) ){ assert( !ExprHasProperty(p, EP_WinFunc) ); sqlite3SelectDelete(db, p->x.pSelect); }else{ sqlite3ExprListDelete(db, p->x.pList); #ifndef SQLITE_OMIT_WINDOWFUNC @@ -103720,14 +102509,11 @@ sqlite3WindowDelete(db, p->y.pWin); } #endif } } - if( ExprHasProperty(p, EP_MemToken) ){ - assert( !ExprHasProperty(p, EP_IntValue) ); - sqlite3DbFree(db, p->u.zToken); - } + if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken); if( !ExprHasProperty(p, EP_Static) ){ sqlite3DbFreeNN(db, p); } } SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){ @@ -103939,11 +102725,11 @@ memcpy(zToken, p->u.zToken, nToken); } if( 0==((p->flags|pNew->flags) & (EP_TokenOnly|EP_Leaf)) ){ /* Fill in the pNew->x.pSelect or pNew->x.pList member. */ - if( ExprUseXSelect(p) ){ + if( ExprHasProperty(p, EP_xIsSelect) ){ pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, dupFlags); }else{ pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, dupFlags); } } @@ -104233,11 +103019,11 @@ } return pRet; } #else -SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, const Select *p, int flags){ +SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){ assert( p==0 ); return 0; } #endif @@ -104566,11 +103352,11 @@ ** the conversion happened, and zero if the expression is unaltered. */ SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr *pExpr){ u32 v; assert( pExpr->op==TK_ID || pExpr->op==TK_STRING ); - if( !ExprHasProperty(pExpr, EP_Quoted|EP_IntValue) + if( !ExprHasProperty(pExpr, EP_Quoted) && (v = sqlite3IsTrueOrFalse(pExpr->u.zToken))!=0 ){ pExpr->op = TK_TRUEFALSE; ExprSetProperty(pExpr, v); return 1; @@ -104583,11 +103369,10 @@ ** and 0 if it is FALSE. */ SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr *pExpr){ pExpr = sqlite3ExprSkipCollate((Expr*)pExpr); assert( pExpr->op==TK_TRUEFALSE ); - assert( !ExprHasProperty(pExpr, EP_IntValue) ); assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0 || sqlite3StrICmp(pExpr->u.zToken,"false")==0 ); return pExpr->u.zToken[4]==0; } @@ -104767,42 +103552,10 @@ */ SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){ return exprIsConst(p, 3, iCur); } -/* -** Check pExpr to see if it is an invariant constraint on data source pSrc. -** This is an optimization. False negatives will perhaps cause slower -** queries, but false positives will yield incorrect answers. So when in -** double, return 0. -** -** To be an invariant constraint, the following must be true: -** -** (1) pExpr cannot refer to any table other than pSrc->iCursor. -** -** (2) pExpr cannot use subqueries or non-deterministic functions. -** -** (*) ** Not applicable to this branch ** -** -** (4) If pSrc is the right operand of a LEFT JOIN, then... -** (4a) pExpr must come from an ON clause.. -** (4b) and specifically the ON clause associated with the LEFT JOIN. -** -** (5) If pSrc is not the right operand of a LEFT JOIN or the left -** operand of a RIGHT JOIN, then pExpr must be from the WHERE -** clause, not an ON clause. -*/ -SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr *pExpr, const SrcItem *pSrc){ - if( pSrc->fg.jointype & JT_LEFT ){ - if( !ExprHasProperty(pExpr, EP_FromJoin) ) return 0; /* rule (4a) */ - if( pExpr->w.iRightJoinTable!=pSrc->iCursor ) return 0; /* rule (4b) */ - }else{ - if( ExprHasProperty(pExpr, EP_FromJoin) ) return 0; /* rule (5) */ - } - return sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor); /* rules (1), (2) */ -} - /* ** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy(). */ static int exprNodeIsConstantOrGroupBy(Walker *pWalker, Expr *pExpr){ @@ -104820,11 +103573,11 @@ } } } /* Check if pExpr is a sub-select. If so, consider it variable. */ - if( ExprUseXSelect(pExpr) ){ + if( ExprHasProperty(pExpr, EP_xIsSelect) ){ pWalker->eCode = 0; return WRC_Abort; } return exprNodeIsConstant(pWalker, pExpr); @@ -104927,13 +103680,13 @@ case TK_UPLUS: { rc = sqlite3ExprIsInteger(p->pLeft, pValue); break; } case TK_UMINUS: { - int v = 0; + int v; if( sqlite3ExprIsInteger(p->pLeft, &v) ){ - assert( ((unsigned int)v)!=0x80000000 ); + assert( v!=(-2147483647-1) ); *pValue = -v; rc = 1; } break; } @@ -104970,15 +103723,14 @@ case TK_STRING: case TK_FLOAT: case TK_BLOB: return 0; case TK_COLUMN: - assert( ExprUseYTab(p) ); return ExprHasProperty(p, EP_CanBeNull) || p->y.pTab==0 || /* Reference to column of index on expression */ (p->iColumn>=0 - && p->y.pTab->aCol!=0 /* Possible due to prior error */ + && ALWAYS(p->y.pTab->aCol!=0) /* Defense against OOM problems */ && p->y.pTab->aCol[p->iColumn].notNull==0); default: return 1; } } @@ -105048,11 +103800,11 @@ Select *p; SrcList *pSrc; ExprList *pEList; Table *pTab; int i; - if( !ExprUseXSelect(pX) ) return 0; /* Not a subquery */ + if( !ExprHasProperty(pX, EP_xIsSelect) ) return 0; /* Not a subquery */ if( ExprHasProperty(pX, EP_VarSelect) ) return 0; /* Correlated subq */ p = pX->x.pSelect; if( p->pPrior ) return 0; /* Not a compound SELECT */ if( p->selFlags & (SF_Distinct|SF_Aggregate) ){ testcase( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct ); @@ -105219,11 +103971,11 @@ /* If the RHS of this IN(...) operator is a SELECT, and if it matters ** whether or not the SELECT result contains NULL values, check whether ** or not NULL is actually possible (it may not be, for example, due ** to NOT NULL constraints in the schema). If no NULL values are possible, ** set prRhsHasNull to 0 before continuing. */ - if( prRhsHasNull && ExprUseXSelect(pX) ){ + if( prRhsHasNull && (pX->flags & EP_xIsSelect) ){ int i; ExprList *pEList = pX->x.pSelect->pEList; for(i=0; inExpr; i++){ if( sqlite3ExprCanBeNull(pEList->a[i].pExpr) ) break; } @@ -105375,11 +104127,11 @@ ** then it is not worth creating an ephemeral table to evaluate ** the IN operator so return IN_INDEX_NOOP. */ if( eType==0 && (inFlags & IN_INDEX_NOOP_OK) - && ExprUseXList(pX) + && !ExprHasProperty(pX, EP_xIsSelect) && (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2) ){ eType = IN_INDEX_NOOP; } @@ -105423,11 +104175,11 @@ ** string is eventually freed using sqlite3DbFree(). */ static char *exprINAffinity(Parse *pParse, const Expr *pExpr){ Expr *pLeft = pExpr->pLeft; int nVal = sqlite3ExprVectorSize(pLeft); - Select *pSelect = ExprUseXSelect(pExpr) ? pExpr->x.pSelect : 0; + Select *pSelect = (pExpr->flags & EP_xIsSelect) ? pExpr->x.pSelect : 0; char *zRet; assert( pExpr->op==TK_IN ); zRet = sqlite3DbMallocRaw(pParse->db, nVal+1); if( zRet ){ @@ -105473,11 +104225,11 @@ ** ** "row value misused" */ SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse *pParse, Expr *pExpr){ #ifndef SQLITE_OMIT_SUBQUERY - if( ExprUseXSelect(pExpr) ){ + if( pExpr->flags & EP_xIsSelect ){ sqlite3SubselectError(pParse, pExpr->x.pSelect->pEList->nExpr, 1); }else #endif { sqlite3ErrorMsg(pParse, "row value misused"); @@ -105537,24 +104289,22 @@ /* If this routine has already been coded, but the previous code ** might not have been invoked yet, so invoke it now as a subroutine. */ if( ExprHasProperty(pExpr, EP_Subrtn) ){ addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v); - if( ExprUseXSelect(pExpr) ){ + if( ExprHasProperty(pExpr, EP_xIsSelect) ){ ExplainQueryPlan((pParse, 0, "REUSE LIST SUBQUERY %d", pExpr->x.pSelect->selId)); } - assert( ExprUseYSub(pExpr) ); sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn, pExpr->y.sub.iAddr); sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable); sqlite3VdbeJumpHere(v, addrOnce); return; } /* Begin coding the subroutine */ - assert( !ExprUseYWin(pExpr) ); ExprSetProperty(pExpr, EP_Subrtn); assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) ); pExpr->y.sub.regReturn = ++pParse->nMem; pExpr->y.sub.iAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1; @@ -105571,19 +104321,19 @@ ** RHS of the IN operator. */ pExpr->iTable = iTab; addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, nVal); #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS - if( ExprUseXSelect(pExpr) ){ + if( ExprHasProperty(pExpr, EP_xIsSelect) ){ VdbeComment((v, "Result of SELECT %u", pExpr->x.pSelect->selId)); }else{ VdbeComment((v, "RHS of IN operator")); } #endif pKeyInfo = sqlite3KeyInfoAlloc(pParse->db, nVal, 1); - if( ExprUseXSelect(pExpr) ){ + if( ExprHasProperty(pExpr, EP_xIsSelect) ){ /* Case 1: expr IN (SELECT ...) ** ** Generate code to write the results of the select into the temporary ** table allocated and opened above. */ @@ -105677,11 +104427,10 @@ sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO); } if( addrOnce ){ sqlite3VdbeJumpHere(v, addrOnce); /* Subroutine return */ - assert( ExprUseYSub(pExpr) ); sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn); sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1); sqlite3ClearTempRegCache(pParse); } } @@ -105714,26 +104463,23 @@ assert( v!=0 ); if( pParse->nErr ) return 0; testcase( pExpr->op==TK_EXISTS ); testcase( pExpr->op==TK_SELECT ); assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT ); - assert( ExprUseXSelect(pExpr) ); + assert( ExprHasProperty(pExpr, EP_xIsSelect) ); pSel = pExpr->x.pSelect; /* If this routine has already been coded, then invoke it as a ** subroutine. */ if( ExprHasProperty(pExpr, EP_Subrtn) ){ ExplainQueryPlan((pParse, 0, "REUSE SUBQUERY %d", pSel->selId)); - assert( ExprUseYSub(pExpr) ); sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn, pExpr->y.sub.iAddr); return pExpr->iTable; } /* Begin coding the subroutine */ - assert( !ExprUseYWin(pExpr) ); - assert( !ExprHasProperty(pExpr, EP_Reduced|EP_TokenOnly) ); ExprSetProperty(pExpr, EP_Subrtn); pExpr->y.sub.regReturn = ++pParse->nMem; pExpr->y.sub.iAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1; VdbeComment((v, "return address")); @@ -105796,22 +104542,23 @@ pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1"); pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0); } pSel->iLimit = 0; if( sqlite3Select(pParse, pSel, &dest) ){ - pExpr->op2 = pExpr->op; - pExpr->op = TK_ERROR; + if( pParse->nErr ){ + pExpr->op2 = pExpr->op; + pExpr->op = TK_ERROR; + } return 0; } pExpr->iTable = rReg = dest.iSDParm; ExprSetVVAProperty(pExpr, EP_NoReduce); if( addrOnce ){ sqlite3VdbeJumpHere(v, addrOnce); } /* Subroutine return */ - assert( ExprUseYSub(pExpr) ); sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn); sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1); sqlite3ClearTempRegCache(pParse); return rReg; } @@ -105824,11 +104571,11 @@ ** columns as the vector on the LHS. Or, if the RHS of the IN() is not ** a sub-query, that the LHS is a vector of size 1. */ SQLITE_PRIVATE int sqlite3ExprCheckIN(Parse *pParse, Expr *pIn){ int nVector = sqlite3ExprVectorSize(pIn->pLeft); - if( ExprUseXSelect(pIn) && !pParse->db->mallocFailed ){ + if( (pIn->flags & EP_xIsSelect)!=0 && !pParse->db->mallocFailed ){ if( nVector!=pIn->x.pSelect->pEList->nExpr ){ sqlite3SubselectError(pParse, pIn->x.pSelect->pEList->nExpr, nVector); return 1; } }else if( nVector!=1 ){ @@ -105958,19 +104705,17 @@ ** sequence of comparisons. ** ** This is step (1) in the in-operator.md optimized algorithm. */ if( eType==IN_INDEX_NOOP ){ - ExprList *pList; - CollSeq *pColl; + ExprList *pList = pExpr->x.pList; + CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft); int labelOk = sqlite3VdbeMakeLabel(pParse); int r2, regToFree; int regCkNull = 0; int ii; - assert( ExprUseXList(pExpr) ); - pList = pExpr->x.pList; - pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft); + assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); if( destIfNull!=destIfFalse ){ regCkNull = sqlite3GetTempReg(pParse); sqlite3VdbeAddOp3(v, OP_BitAnd, rLhs, rLhs, regCkNull); } for(ii=0; iinExpr; ii++){ @@ -106014,13 +104759,14 @@ if( destIfNull==destIfFalse ){ destStep2 = destIfFalse; }else{ destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse); } + if( pParse->nErr ) goto sqlite3ExprCodeIN_finished; for(i=0; ipLeft, i); - if( pParse->nErr ) goto sqlite3ExprCodeIN_oom_error; + if( pParse->db->mallocFailed ) goto sqlite3ExprCodeIN_oom_error; if( sqlite3ExprCanBeNull(p) ){ sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2); VdbeCoverage(v); } } @@ -106154,16 +104900,15 @@ const char *z = pExpr->u.zToken; assert( z!=0 ); c = sqlite3DecOrHexToI64(z, &value); if( (c==3 && !negFlag) || (c==2) || (negFlag && value==SMALLEST_INT64)){ #ifdef SQLITE_OMIT_FLOATING_POINT - sqlite3ErrorMsg(pParse, "oversized integer: %s%#T", negFlag?"-":"",pExpr); + sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z); #else #ifndef SQLITE_OMIT_HEX_INTEGER if( sqlite3_strnicmp(z,"0x",2)==0 ){ - sqlite3ErrorMsg(pParse, "hex literal too big: %s%#T", - negFlag?"-":"",pExpr); + sqlite3ErrorMsg(pParse, "hex literal too big: %s%s", negFlag?"-":"",z); }else #endif { codeReal(v, z, negFlag, iMem); } @@ -106352,11 +105097,10 @@ #endif }else{ int i; iResult = pParse->nMem+1; pParse->nMem += nResult; - assert( ExprUseXList(p) ); for(i=0; ix.pList->a[i].pExpr, i+iResult); } } } @@ -106551,11 +105295,10 @@ ** datatype by applying the Affinity of the table column to the ** constant. */ int aff; iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target); - assert( ExprUseYTab(pExpr) ); if( pExpr->y.pTab ){ aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn); }else{ aff = pExpr->affExpr; } @@ -106575,15 +105318,13 @@ ** The row is unpacked into registers beginning at ** 0-(pParse->iSelfTab). The rowid (if any) is in a register ** immediately prior to the first column. */ Column *pCol; - Table *pTab; + Table *pTab = pExpr->y.pTab; int iSrc; int iCol = pExpr->iColumn; - assert( ExprUseYTab(pExpr) ); - pTab = pExpr->y.pTab; assert( pTab!=0 ); assert( iCol>=XN_ROWID ); assert( iColnCol ); if( iCol<0 ){ return -1-pParse->iSelfTab; @@ -106617,11 +105358,10 @@ /* Coding an expression that is part of an index where column names ** in the index refer to the table to which the index belongs */ iTab = pParse->iSelfTab - 1; } } - assert( ExprUseYTab(pExpr) ); iReg = sqlite3ExprCodeGetColumn(pParse, pExpr->y.pTab, pExpr->iColumn, iTab, target, pExpr->op2); if( pExpr->y.pTab==0 && pExpr->affExpr==SQLITE_AFF_REAL ){ sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg); @@ -106695,11 +105435,10 @@ inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target); if( inReg!=target ){ sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target); inReg = target; } - assert( !ExprHasProperty(pExpr, EP_IntValue) ); sqlite3VdbeAddOp2(v, OP_Cast, target, sqlite3AffinityType(pExpr->u.zToken, 0)); return inReg; } #endif /* SQLITE_OMIT_CAST */ @@ -106835,11 +105574,11 @@ if( pInfo==0 || NEVER(pExpr->iAgg<0) || NEVER(pExpr->iAgg>=pInfo->nFunc) ){ assert( !ExprHasProperty(pExpr, EP_IntValue) ); - sqlite3ErrorMsg(pParse, "misuse of aggregate: %#T()", pExpr); + sqlite3ErrorMsg(pParse, "misuse of aggregate: %s()", pExpr->u.zToken); }else{ return pInfo->aFunc[pExpr->iAgg].iMem; } break; } @@ -106863,12 +105602,12 @@ if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){ /* SQL functions can be expensive. So try to avoid running them ** multiple times if we know they always give the same result */ return sqlite3ExprCodeRunJustOnce(pParse, pExpr, -1); } + assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); assert( !ExprHasProperty(pExpr, EP_TokenOnly) ); - assert( ExprUseXList(pExpr) ); pFarg = pExpr->x.pList; nFarg = pFarg ? pFarg->nExpr : 0; assert( !ExprHasProperty(pExpr, EP_IntValue) ); zId = pExpr->u.zToken; pDef = sqlite3FindFunction(db, zId, nFarg, enc, 0); @@ -106876,11 +105615,11 @@ if( pDef==0 && pParse->explain ){ pDef = sqlite3FindFunction(db, "unknown", nFarg, enc, 0); } #endif if( pDef==0 || pDef->xFinalize!=0 ){ - sqlite3ErrorMsg(pParse, "unknown function: %#T()", pExpr); + sqlite3ErrorMsg(pParse, "unknown function: %s()", zId); break; } if( pDef->funcFlags & SQLITE_FUNC_INLINE ){ assert( (pDef->funcFlags & SQLITE_FUNC_UNSAFE)==0 ); assert( (pDef->funcFlags & SQLITE_FUNC_DIRECT)==0 ); @@ -106953,11 +105692,11 @@ if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){ if( !pColl ) pColl = db->pDfltColl; sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ); } #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC - if( (pDef->funcFlags & SQLITE_FUNC_OFFSET)!=0 && ALWAYS(pFarg!=0) ){ + if( pDef->funcFlags & SQLITE_FUNC_OFFSET ){ Expr *pArg = pFarg->a[0].pExpr; if( pArg->op==TK_COLUMN ){ sqlite3VdbeAddOp3(v, OP_Offset, pArg->iTable, pArg->iColumn, target); }else{ sqlite3VdbeAddOp2(v, OP_Null, 0, target); @@ -106983,14 +105722,11 @@ int nCol; testcase( op==TK_EXISTS ); testcase( op==TK_SELECT ); if( pParse->db->mallocFailed ){ return 0; - }else if( op==TK_SELECT - && ALWAYS( ExprUseXSelect(pExpr) ) - && (nCol = pExpr->x.pSelect->pEList->nExpr)!=1 - ){ + }else if( op==TK_SELECT && (nCol = pExpr->x.pSelect->pEList->nExpr)!=1 ){ sqlite3SubselectError(pParse, nCol, 1); }else{ return sqlite3CodeSubselect(pParse, pExpr); } break; @@ -107068,18 +105804,13 @@ ** ** p1==0 -> old.rowid p1==3 -> new.rowid ** p1==1 -> old.a p1==4 -> new.a ** p1==2 -> old.b p1==5 -> new.b */ - Table *pTab; - int iCol; - int p1; - - assert( ExprUseYTab(pExpr) ); - pTab = pExpr->y.pTab; - iCol = pExpr->iColumn; - p1 = pExpr->iTable * (pTab->nCol+1) + 1 + Table *pTab = pExpr->y.pTab; + int iCol = pExpr->iColumn; + int p1 = pExpr->iTable * (pTab->nCol+1) + 1 + sqlite3TableColumnToStorage(pTab, iCol); assert( pExpr->iTable==0 || pExpr->iTable==1 ); assert( iCol>=-1 && iColnCol ); assert( pTab->iPKey<0 || iCol!=pTab->iPKey ); @@ -107163,11 +105894,11 @@ Expr *pX; /* The X expression */ Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */ Expr *pDel = 0; sqlite3 *db = pParse->db; - assert( ExprUseXList(pExpr) && pExpr->x.pList!=0 ); + assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList ); assert(pExpr->x.pList->nExpr > 0); pEList = pExpr->x.pList; aListelem = pEList->a; nExpr = pEList->nExpr; endLabel = sqlite3VdbeMakeLabel(pParse); @@ -107508,11 +106239,11 @@ memset(&compLeft, 0, sizeof(Expr)); memset(&compRight, 0, sizeof(Expr)); memset(&exprAnd, 0, sizeof(Expr)); - assert( ExprUseXList(pExpr) ); + assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); pDel = sqlite3ExprDup(db, pExpr->pLeft, 0); if( db->mallocFailed==0 ){ exprAnd.op = TK_AND; exprAnd.pLeft = &compLeft; exprAnd.pRight = &compRight; @@ -107983,13 +106714,11 @@ if( pB->op==TK_COLLATE && sqlite3ExprCompare(pParse, pA,pB->pLeft,iTab)<2 ){ return 1; } return 2; } - assert( !ExprHasProperty(pA, EP_IntValue) ); - assert( !ExprHasProperty(pB, EP_IntValue) ); - if( pA->u.zToken ){ + if( pA->op!=TK_COLUMN && pA->op!=TK_AGG_COLUMN && pA->u.zToken ){ if( pA->op==TK_FUNCTION || pA->op==TK_AGG_FUNCTION ){ if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2; #ifndef SQLITE_OMIT_WINDOWFUNC assert( pA->op==pB->op ); if( ExprHasProperty(pA,EP_WinFunc)!=ExprHasProperty(pB,EP_WinFunc) ){ @@ -108003,16 +106732,11 @@ #endif }else if( pA->op==TK_NULL ){ return 0; }else if( pA->op==TK_COLLATE ){ if( sqlite3_stricmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2; - }else - if( pB->u.zToken!=0 - && pA->op!=TK_COLUMN - && pA->op!=TK_AGG_COLUMN - && strcmp(pA->u.zToken,pB->u.zToken)!=0 - ){ + }else if( ALWAYS(pB->u.zToken!=0) && strcmp(pA->u.zToken,pB->u.zToken)!=0 ){ return 2; } } if( (pA->flags & (EP_Distinct|EP_Commuted)) != (pB->flags & (EP_Distinct|EP_Commuted)) ) return 2; @@ -108097,17 +106821,16 @@ return pNN->op!=TK_NULL; } switch( p->op ){ case TK_IN: { if( seenNot && ExprHasProperty(p, EP_xIsSelect) ) return 0; - assert( ExprUseXSelect(p) || (p->x.pList!=0 && p->x.pList->nExpr>0) ); + assert( ExprHasProperty(p,EP_xIsSelect) + || (p->x.pList!=0 && p->x.pList->nExpr>0) ); return exprImpliesNotNull(pParse, p->pLeft, pNN, iTab, 1); } case TK_BETWEEN: { - ExprList *pList; - assert( ExprUseXList(p) ); - pList = p->x.pList; + ExprList *pList = p->x.pList; assert( pList!=0 ); assert( pList->nExpr==2 ); if( seenNot ) return 0; if( exprImpliesNotNull(pParse, pList->a[0].pExpr, pNN, iTab, 1) || exprImpliesNotNull(pParse, pList->a[1].pExpr, pNN, iTab, 1) @@ -108280,18 +107003,14 @@ testcase( pExpr->op==TK_LE ); testcase( pExpr->op==TK_GT ); testcase( pExpr->op==TK_GE ); /* The y.pTab=0 assignment in wherecode.c always happens after the ** impliesNotNullRow() test */ - assert( pLeft->op!=TK_COLUMN || ExprUseYTab(pLeft) ); - assert( pRight->op!=TK_COLUMN || ExprUseYTab(pRight) ); - if( (pLeft->op==TK_COLUMN - && pLeft->y.pTab!=0 - && IsVirtual(pLeft->y.pTab)) - || (pRight->op==TK_COLUMN - && pRight->y.pTab!=0 - && IsVirtual(pRight->y.pTab)) + if( (pLeft->op==TK_COLUMN && pLeft->y.pTab!=0 + && IsVirtual(pLeft->y.pTab)) + || (pRight->op==TK_COLUMN && pRight->y.pTab!=0 + && IsVirtual(pRight->y.pTab)) ){ return WRC_Prune; } /* no break */ deliberate_fall_through } @@ -108396,129 +107115,92 @@ sqlite3WalkExpr(&w, pExpr); return !w.eCode; } -/* Structure used to pass information throught the Walker in order to -** implement sqlite3ReferencesSrcList(). +/* +** An instance of the following structure is used by the tree walker +** to count references to table columns in the arguments of an +** aggregate function, in order to implement the +** sqlite3FunctionThisSrc() routine. */ -struct RefSrcList { - sqlite3 *db; /* Database connection used for sqlite3DbRealloc() */ - SrcList *pRef; /* Looking for references to these tables */ - i64 nExclude; /* Number of tables to exclude from the search */ - int *aiExclude; /* Cursor IDs for tables to exclude from the search */ +struct SrcCount { + SrcList *pSrc; /* One particular FROM clause in a nested query */ + int iSrcInner; /* Smallest cursor number in this context */ + int nThis; /* Number of references to columns in pSrcList */ + int nOther; /* Number of references to columns in other FROM clauses */ }; /* -** Walker SELECT callbacks for sqlite3ReferencesSrcList(). -** -** When entering a new subquery on the pExpr argument, add all FROM clause -** entries for that subquery to the exclude list. -** -** When leaving the subquery, remove those entries from the exclude list. +** xSelect callback for sqlite3FunctionUsesThisSrc(). If this is the first +** SELECT with a FROM clause encountered during this iteration, set +** SrcCount.iSrcInner to the cursor number of the leftmost object in +** the FROM cause. */ -static int selectRefEnter(Walker *pWalker, Select *pSelect){ - struct RefSrcList *p = pWalker->u.pRefSrcList; - SrcList *pSrc = pSelect->pSrc; - i64 i, j; - int *piNew; - if( pSrc->nSrc==0 ) return WRC_Continue; - j = p->nExclude; - p->nExclude += pSrc->nSrc; - piNew = sqlite3DbRealloc(p->db, p->aiExclude, p->nExclude*sizeof(int)); - if( piNew==0 ){ - p->nExclude = 0; - return WRC_Abort; - }else{ - p->aiExclude = piNew; - } - for(i=0; inSrc; i++, j++){ - p->aiExclude[j] = pSrc->a[i].iCursor; +static int selectSrcCount(Walker *pWalker, Select *pSel){ + struct SrcCount *p = pWalker->u.pSrcCount; + if( p->iSrcInner==0x7FFFFFFF && ALWAYS(pSel->pSrc) && pSel->pSrc->nSrc ){ + pWalker->u.pSrcCount->iSrcInner = pSel->pSrc->a[0].iCursor; } return WRC_Continue; } -static void selectRefLeave(Walker *pWalker, Select *pSelect){ - struct RefSrcList *p = pWalker->u.pRefSrcList; - SrcList *pSrc = pSelect->pSrc; - if( p->nExclude ){ - assert( p->nExclude>=pSrc->nSrc ); - p->nExclude -= pSrc->nSrc; - } -} - -/* This is the Walker EXPR callback for sqlite3ReferencesSrcList(). -** -** Set the 0x01 bit of pWalker->eCode if there is a reference to any -** of the tables shown in RefSrcList.pRef. -** -** Set the 0x02 bit of pWalker->eCode if there is a reference to a -** table is in neither RefSrcList.pRef nor RefSrcList.aiExclude. -*/ -static int exprRefToSrcList(Walker *pWalker, Expr *pExpr){ - if( pExpr->op==TK_COLUMN - || pExpr->op==TK_AGG_COLUMN - ){ - int i; - struct RefSrcList *p = pWalker->u.pRefSrcList; - SrcList *pSrc = p->pRef; + +/* +** Count the number of references to columns. +*/ +static int exprSrcCount(Walker *pWalker, Expr *pExpr){ + /* There was once a NEVER() on the second term on the grounds that + ** sqlite3FunctionUsesThisSrc() was always called before + ** sqlite3ExprAnalyzeAggregates() and so the TK_COLUMNs have not yet + ** been converted into TK_AGG_COLUMN. But this is no longer true due + ** to window functions - sqlite3WindowRewrite() may now indirectly call + ** FunctionUsesThisSrc() when creating a new sub-select. */ + if( pExpr->op==TK_COLUMN || pExpr->op==TK_AGG_COLUMN ){ + int i; + struct SrcCount *p = pWalker->u.pSrcCount; + SrcList *pSrc = p->pSrc; int nSrc = pSrc ? pSrc->nSrc : 0; for(i=0; iiTable==pSrc->a[i].iCursor ){ - pWalker->eCode |= 1; - return WRC_Continue; - } - } - for(i=0; inExclude && p->aiExclude[i]!=pExpr->iTable; i++){} - if( i>=p->nExclude ){ - pWalker->eCode |= 2; + if( pExpr->iTable==pSrc->a[i].iCursor ) break; + } + if( inThis++; + }else if( pExpr->iTableiSrcInner ){ + /* In a well-formed parse tree (no name resolution errors), + ** TK_COLUMN nodes with smaller Expr.iTable values are in an + ** outer context. Those are the only ones to count as "other" */ + p->nOther++; } } return WRC_Continue; } /* -** Check to see if pExpr references any tables in pSrcList. -** Possible return values: -** -** 1 pExpr does references a table in pSrcList. -** -** 0 pExpr references some table that is not defined in either -** pSrcList or in subqueries of pExpr itself. -** -** -1 pExpr only references no tables at all, or it only -** references tables defined in subqueries of pExpr itself. -** -** As currently used, pExpr is always an aggregate function call. That -** fact is exploited for efficiency. +** Determine if any of the arguments to the pExpr Function reference +** pSrcList. Return true if they do. Also return true if the function +** has no arguments or has only constant arguments. Return false if pExpr +** references columns but not columns of tables found in pSrcList. */ -SQLITE_PRIVATE int sqlite3ReferencesSrcList(Parse *pParse, Expr *pExpr, SrcList *pSrcList){ +SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr *pExpr, SrcList *pSrcList){ Walker w; - struct RefSrcList x; + struct SrcCount cnt; + assert( pExpr->op==TK_AGG_FUNCTION ); memset(&w, 0, sizeof(w)); - memset(&x, 0, sizeof(x)); - w.xExprCallback = exprRefToSrcList; - w.xSelectCallback = selectRefEnter; - w.xSelectCallback2 = selectRefLeave; - w.u.pRefSrcList = &x; - x.db = pParse->db; - x.pRef = pSrcList; - assert( pExpr->op==TK_AGG_FUNCTION ); - assert( ExprUseXList(pExpr) ); + w.xExprCallback = exprSrcCount; + w.xSelectCallback = selectSrcCount; + w.u.pSrcCount = &cnt; + cnt.pSrc = pSrcList; + cnt.iSrcInner = (pSrcList&&pSrcList->nSrc)?pSrcList->a[0].iCursor:0x7FFFFFFF; + cnt.nThis = 0; + cnt.nOther = 0; sqlite3WalkExprList(&w, pExpr->x.pList); #ifndef SQLITE_OMIT_WINDOWFUNC if( ExprHasProperty(pExpr, EP_WinFunc) ){ sqlite3WalkExpr(&w, pExpr->y.pWin->pFilter); } #endif - sqlite3DbFree(pParse->db, x.aiExclude); - if( w.eCode & 0x01 ){ - return 1; - }else if( w.eCode ){ - return 0; - }else{ - return -1; - } + return cnt.nThis>0 || cnt.nOther==0; } /* ** This is a Walker expression node callback. ** @@ -108649,11 +107331,10 @@ } if( (k>=pAggInfo->nColumn) && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0 ){ pCol = &pAggInfo->aCol[k]; - assert( ExprUseYTab(pExpr) ); pCol->pTab = pExpr->y.pTab; pCol->iTable = pExpr->iTable; pCol->iColumn = pExpr->iColumn; pCol->iMem = ++pParse->nMem; pCol->iSorterColumn = -1; @@ -108713,11 +107394,11 @@ if( i>=0 ){ assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); pItem = &pAggInfo->aFunc[i]; pItem->pFExpr = pExpr; pItem->iMem = ++pParse->nMem; - assert( ExprUseUToken(pExpr) ); + assert( !ExprHasProperty(pExpr, EP_IntValue) ); pItem->pFunc = sqlite3FindFunction(pParse->db, pExpr->u.zToken, pExpr->x.pList ? pExpr->x.pList->nExpr : 0, enc, 0); if( pExpr->flags & EP_Distinct ){ pItem->iDistinct = pParse->nTab++; @@ -108928,11 +107609,11 @@ int bNoDQS /* Do not allow DQS in the schema */ ){ pParse->colNamesSet = 1; sqlite3NestedParse(pParse, "SELECT 1 " - "FROM \"%w\"." LEGACY_SCHEMA_TABLE " " + "FROM \"%w\"." DFLT_SCHEMA_TABLE " " "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" " AND sql NOT LIKE 'create virtual%%'" " AND sqlite_rename_test(%Q, sql, type, name, %d, %Q, %d)=NULL ", zDb, zDb, bTemp, zWhen, bNoDQS @@ -108939,11 +107620,11 @@ ); if( bTemp==0 ){ sqlite3NestedParse(pParse, "SELECT 1 " - "FROM temp." LEGACY_SCHEMA_TABLE " " + "FROM temp." DFLT_SCHEMA_TABLE " " "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" " AND sql NOT LIKE 'create virtual%%'" " AND sqlite_rename_test(%Q, sql, type, name, 1, %Q, %d)=NULL ", zDb, zWhen, bNoDQS ); @@ -108957,18 +107638,18 @@ ** not true, similarly update all SQL statements in the sqlite_schema table ** of the temp db. */ static void renameFixQuotes(Parse *pParse, const char *zDb, int bTemp){ sqlite3NestedParse(pParse, - "UPDATE \"%w\"." LEGACY_SCHEMA_TABLE + "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET sql = sqlite_rename_quotefix(%Q, sql)" "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" " AND sql NOT LIKE 'create virtual%%'" , zDb, zDb ); if( bTemp==0 ){ sqlite3NestedParse(pParse, - "UPDATE temp." LEGACY_SCHEMA_TABLE + "UPDATE temp." DFLT_SCHEMA_TABLE " SET sql = sqlite_rename_quotefix('temp', sql)" "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" " AND sql NOT LIKE 'create virtual%%'" ); } @@ -109082,21 +107763,21 @@ nTabName = sqlite3Utf8CharLen(zTabName, -1); /* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in ** the schema to use the new table name. */ sqlite3NestedParse(pParse, - "UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET " + "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET " "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, %d) " "WHERE (type!='index' OR tbl_name=%Q COLLATE nocase)" "AND name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" , zDb, zDb, zTabName, zName, (iDb==1), zTabName ); /* Update the tbl_name and name columns of the sqlite_schema table ** as required. */ sqlite3NestedParse(pParse, - "UPDATE %Q." LEGACY_SCHEMA_TABLE " SET " + "UPDATE %Q." DFLT_SCHEMA_TABLE " SET " "tbl_name = %Q, " "name = CASE " "WHEN type='table' THEN %Q " "WHEN name LIKE 'sqliteX_autoindex%%' ESCAPE 'X' " " AND type='index' THEN " @@ -109192,13 +107873,11 @@ sqlite3 *db; /* The database connection; */ Vdbe *v; /* The prepared statement under construction */ int r1; /* Temporary registers */ db = pParse->db; - assert( db->pParse==pParse ); - if( pParse->nErr ) return; - assert( db->mallocFailed==0 ); + if( pParse->nErr || db->mallocFailed ) return; pNew = pParse->pNewTable; assert( pNew ); assert( sqlite3BtreeHoldsAllMutexes(db) ); iDb = sqlite3SchemaToIndex(db, pNew->pSchema); @@ -109237,11 +107916,10 @@ */ assert( pDflt==0 || pDflt->op==TK_SPAN ); if( pDflt && pDflt->pLeft->op==TK_NULL ){ pDflt = 0; } - assert( IsOrdinaryTable(pNew) ); if( (db->flags&SQLITE_ForeignKeys) && pNew->u.tab.pFKey && pDflt ){ sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, "Cannot add a REFERENCES column with non-NULL default value"); } if( pCol->notNull && !pDflt ){ @@ -109280,14 +107958,13 @@ while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){ *zEnd-- = '\0'; } /* substr() operations on characters, but addColOffset is in bytes. So we ** have to use printf() to translate between these units: */ - assert( IsOrdinaryTable(pTab) ); - assert( IsOrdinaryTable(pNew) ); + assert( !IsVirtual(pTab) ); sqlite3NestedParse(pParse, - "UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET " + "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET " "sql = printf('%%.%ds, ',sql) || %Q" " || substr(sql,1+length(printf('%%.%ds',sql))) " "WHERE type = 'table' AND name = %Q", zDb, pNew->u.tab.addColOffset, zCol, pNew->u.tab.addColOffset, zTab @@ -109309,11 +107986,11 @@ VdbeCoverage(v); sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, 3); sqlite3ReleaseTempReg(pParse, r1); /* Reload the table definition */ - renameReloadSchema(pParse, iDb, INITFLAG_AlterAdd); + renameReloadSchema(pParse, iDb, INITFLAG_AlterRename); /* Verify that constraints are still satisfied */ if( pNew->pCheck!=0 || (pCol->notNull && (pCol->colFlags & COLFLAG_GENERATED)!=0) ){ @@ -109320,11 +107997,11 @@ sqlite3NestedParse(pParse, "SELECT CASE WHEN quick_check GLOB 'CHECK*'" " THEN raise(ABORT,'CHECK constraint failed')" " ELSE raise(ABORT,'NOT NULL constraint failed')" " END" - " FROM pragma_quick_check(%Q,%Q)" + " FROM pragma_quick_check(\"%w\",\"%w\")" " WHERE quick_check GLOB 'CHECK*' OR quick_check GLOB 'NULL*'", zTab, zDb ); } } @@ -109375,11 +108052,10 @@ if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){ goto exit_begin_add_column; } sqlite3MayAbort(pParse); - assert( IsOrdinaryTable(pTab) ); assert( pTab->u.tab.addColOffset>0 ); iDb = sqlite3SchemaToIndex(db, pTab->pSchema); /* Put a copy of the Table struct in Parse.pNewTable for the ** sqlite3AddColumn() function and friends to modify. But modify @@ -109406,11 +108082,11 @@ for(i=0; inCol; i++){ Column *pCol = &pNew->aCol[i]; pCol->zCnName = sqlite3DbStrDup(db, pCol->zCnName); pCol->hName = sqlite3StrIHash(pCol->zCnName); } - assert( IsOrdinaryTable(pNew) ); + assert( !IsVirtual(pNew) ); pNew->u.tab.pDfltList = sqlite3ExprListDup(db, pTab->u.tab.pDfltList, 0); pNew->pSchema = db->aDb[iDb].pSchema; pNew->u.tab.addColOffset = pTab->u.tab.addColOffset; pNew->nTabRef = 1; @@ -109499,11 +108175,11 @@ if( !zOld ) goto exit_rename_column; for(iCol=0; iColnCol; iCol++){ if( 0==sqlite3StrICmp(pTab->aCol[iCol].zCnName, zOld) ) break; } if( iCol==pTab->nCol ){ - sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pOld); + sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zOld); goto exit_rename_column; } /* Ensure the schema contains no double-quoted strings */ renameTestSchema(pParse, zDb, iSchema==1, "", 0); @@ -109517,21 +108193,21 @@ zNew = sqlite3NameFromToken(db, pNew); if( !zNew ) goto exit_rename_column; assert( pNew->n>0 ); bQuote = sqlite3Isquote(pNew->z[0]); sqlite3NestedParse(pParse, - "UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET " + "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET " "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) " "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' " " AND (type != 'index' OR tbl_name = %Q)", zDb, zDb, pTab->zName, iCol, zNew, bQuote, iSchema==1, pTab->zName ); sqlite3NestedParse(pParse, - "UPDATE temp." LEGACY_SCHEMA_TABLE " SET " + "UPDATE temp." DFLT_SCHEMA_TABLE " SET " "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, 1) " "WHERE type IN ('trigger', 'view')", zDb, pTab->zName, iCol, zNew, bQuote ); @@ -109605,13 +108281,11 @@ ** ** Technically, as x no longer points into a valid object or to the byte ** following a valid object, it may not be used in comparison operations. */ static void renameTokenCheckAll(Parse *pParse, const void *pPtr){ - assert( pParse==pParse->db->pParse ); - assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 ); - if( pParse->nErr==0 ){ + if( pParse->nErr==0 && pParse->db->mallocFailed==0 ){ const RenameToken *p; u8 i = 0; for(p=pParse->pRename; p; p=p->pNext){ if( p->p ){ assert( p->p!=pPtr ); @@ -109677,13 +108351,11 @@ ** Walker callback used by sqlite3RenameExprUnmap(). */ static int renameUnmapExprCb(Walker *pWalker, Expr *pExpr){ Parse *pParse = pWalker->pParse; sqlite3RenameTokenRemap(pParse, 0, (const void*)pExpr); - if( ExprUseYTab(pExpr) ){ - sqlite3RenameTokenRemap(pParse, 0, (const void*)&pExpr->y.pTab); - } + sqlite3RenameTokenRemap(pParse, 0, (const void*)&pExpr->y.pTab); return WRC_Continue; } /* ** Iterate through the Select objects that are part of WITH clauses attached @@ -109741,13 +108413,11 @@ */ static int renameUnmapSelectCb(Walker *pWalker, Select *p){ Parse *pParse = pWalker->pParse; int i; if( pParse->nErr ) return WRC_Abort; - testcase( p->selFlags & SF_View ); - testcase( p->selFlags & SF_CopyCte ); - if( p->selFlags & (SF_View|SF_CopyCte) ){ + if( NEVER(p->selFlags & (SF_View|SF_CopyCte)) ){ return WRC_Prune; } if( ALWAYS(p->pEList) ){ ExprList *pList = p->pEList; for(i=0; inExpr; i++){ @@ -109880,11 +108550,10 @@ && pWalker->pParse->pTriggerTab==p->pTab ){ renameTokenFind(pWalker->pParse, p, (void*)pExpr); }else if( pExpr->op==TK_COLUMN && pExpr->iColumn==p->iCol - && ALWAYS(ExprUseYTab(pExpr)) && p->pTab==pExpr->y.pTab ){ renameTokenFind(pWalker->pParse, p, (void*)pExpr); } return WRC_Continue; @@ -109929,16 +108598,16 @@ ){ const char *zT = (const char*)sqlite3_value_text(pType); const char *zN = (const char*)sqlite3_value_text(pObject); char *zErr; - zErr = sqlite3MPrintf(pParse->db, "error in %s %s%s%s: %s", + zErr = sqlite3_mprintf("error in %s %s%s%s: %s", zT, zN, (zWhen[0] ? " " : ""), zWhen, pParse->zErrMsg ); sqlite3_result_error(pCtx, zErr, -1); - sqlite3DbFree(pParse->db, zErr); + sqlite3_free(zErr); } /* ** For each name in the the expression-list pEList (i.e. each ** pEList->a[i].zName) that matches the string in zOld, extract the @@ -109998,26 +108667,28 @@ sqlite3 *db, /* Database handle */ const char *zSql, /* SQL to parse */ int bTemp /* True if SQL is from temp schema */ ){ int rc; - - sqlite3ParseObjectInit(p, db); - if( zSql==0 ){ - return SQLITE_NOMEM; - } - if( sqlite3StrNICmp(zSql,"CREATE ",7)!=0 ){ - return SQLITE_CORRUPT_BKPT; - } + char *zErr = 0; + db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb); + + /* Parse the SQL statement passed as the first argument. If no error + ** occurs and the parse does not result in a new table, index or + ** trigger object, the database must be corrupt. */ + memset(p, 0, sizeof(Parse)); p->eParseMode = PARSE_MODE_RENAME; p->db = db; p->nQueryLoop = 1; - rc = sqlite3RunParser(p, zSql); + rc = zSql ? sqlite3RunParser(p, zSql, &zErr) : SQLITE_NOMEM; + assert( p->zErrMsg==0 ); + assert( rc!=SQLITE_OK || zErr==0 ); + p->zErrMsg = zErr; if( db->mallocFailed ) rc = SQLITE_NOMEM; if( rc==SQLITE_OK - && NEVER(p->pNewTable==0 && p->pNewIndex==0 && p->pNewTrigger==0) + && p->pNewTable==0 && p->pNewIndex==0 && p->pNewTrigger==0 ){ rc = SQLITE_CORRUPT_BKPT; } #ifdef SQLITE_DEBUG @@ -110203,13 +108874,10 @@ p->pTab->nTabRef++; rc = sqlite3ViewGetColumnNames(pParse, p->pTab); } } } - if( rc==SQLITE_OK && db->mallocFailed ){ - rc = SQLITE_NOMEM; - } sNC.pSrcList = pSrc; if( rc==SQLITE_OK && pStep->pWhere ){ rc = sqlite3ResolveExprNames(&sNC, pStep->pWhere); } if( rc==SQLITE_OK ){ @@ -110291,17 +108959,17 @@ sqlite3FreeIndex(db, pIdx); } sqlite3DeleteTrigger(db, pParse->pNewTrigger); sqlite3DbFree(db, pParse->zErrMsg); renameTokenFree(db, pParse->pRename); - sqlite3ParseObjectReset(pParse); + sqlite3ParserReset(pParse); } /* ** SQL function: ** -** sqlite_rename_column(SQL,TYPE,OBJ,DB,TABLE,COL,NEWNAME,QUOTE,TEMP) +** sqlite_rename_column(zSql, iCol, bQuote, zNew, zTable, zOld) ** ** 0. zSql: SQL statement to rewrite ** 1. type: Type of object ("table", "view" etc.) ** 2. object: Name of object ** 3. Database: Database name (e.g. "main") @@ -110315,12 +108983,11 @@ ** The iCol-th column (left-most is 0) of table zTable is renamed from zCol ** into zNew. The name should be quoted if bQuote is true. ** ** This function is used internally by the ALTER TABLE RENAME COLUMN command. ** It is only accessible to SQL created using sqlite3NestedParse(). It is -** not reachable from ordinary SQL passed into sqlite3_prepare() unless the -** SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test setting is enabled. +** not reachable from ordinary SQL passed into sqlite3_prepare(). */ static void renameColumnFunc( sqlite3_context *context, int NotUsed, sqlite3_value **argv @@ -110413,11 +109080,11 @@ sqlite3WalkExpr(&sWalker, pExpr); } #endif } - assert( IsOrdinaryTable(sParse.pNewTable) ); + assert( !IsVirtual(sParse.pNewTable) ); for(pFKey=sParse.pNewTable->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ for(i=0; inCol; i++){ if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){ renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]); } @@ -110465,13 +109132,11 @@ assert( rc==SQLITE_OK ); rc = renameEditSql(context, &sCtx, zSql, zNew, bQuote); renameColumnFunc_done: if( rc!=SQLITE_OK ){ - if( rc==SQLITE_ERROR && sqlite3WritableSchema(db) ){ - sqlite3_result_value(context, argv[0]); - }else if( sParse.zErrMsg ){ + if( sParse.zErrMsg ){ renameColumnParseError(context, "", argv[1], argv[2], &sParse); }else{ sqlite3_result_error_code(context, rc); } } @@ -110487,14 +109152,11 @@ /* ** Walker expression callback used by "RENAME TABLE". */ static int renameTableExprCb(Walker *pWalker, Expr *pExpr){ RenameCtx *p = pWalker->u.pRename; - if( pExpr->op==TK_COLUMN - && ALWAYS(ExprUseYTab(pExpr)) - && p->pTab==pExpr->y.pTab - ){ + if( pExpr->op==TK_COLUMN && p->pTab==pExpr->y.pTab ){ renameTokenFind(pWalker->pParse, p, (void*)&pExpr->y.pTab); } return WRC_Continue; } @@ -110608,11 +109270,11 @@ #ifndef SQLITE_OMIT_FOREIGN_KEY if( (isLegacy==0 || (db->flags & SQLITE_ForeignKeys)) && !IsVirtual(pTab) ){ FKey *pFKey; - assert( IsOrdinaryTable(pTab) ); + assert( !IsVirtual(pTab) ); for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){ renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo); } } @@ -110666,13 +109328,11 @@ if( rc==SQLITE_OK ){ rc = renameEditSql(context, &sCtx, zInput, zNew, bQuote); } if( rc!=SQLITE_OK ){ - if( rc==SQLITE_ERROR && sqlite3WritableSchema(db) ){ - sqlite3_result_value(context, argv[3]); - }else if( sParse.zErrMsg ){ + if( sParse.zErrMsg ){ renameColumnParseError(context, "", argv[1], argv[2], &sParse); }else{ sqlite3_result_error_code(context, rc); } } @@ -110693,14 +109353,14 @@ renameTokenFind(pWalker->pParse, pWalker->u.pRename, (const void*)pExpr); } return WRC_Continue; } -/* SQL function: sqlite_rename_quotefix(DB,SQL) -** -** Rewrite the DDL statement "SQL" so that any string literals that use -** double-quotes use single quotes instead. +/* +** The implementation of an SQL scalar function that rewrites DDL statements +** so that any string literals that use double-quotes are modified so that +** they use single quotes. ** ** Two arguments must be passed: ** ** 0: Database name ("main", "temp" etc.). ** 1: SQL statement to edit. @@ -110715,14 +109375,10 @@ ** ); ** ** returns the string: ** ** CREATE VIEW v1 AS SELECT "a", 'string' FROM t1 -** -** If there is a error in the input SQL, then raise an error, except -** if PRAGMA writable_schema=ON, then just return the input string -** unmodified following an error. */ static void renameQuotefixFunc( sqlite3_context *context, int NotUsed, sqlite3_value **argv @@ -110793,15 +109449,11 @@ rc = renameEditSql(context, &sCtx, zInput, 0, 0); } renameTokenFree(db, sCtx.pList); } if( rc!=SQLITE_OK ){ - if( sqlite3WritableSchema(db) && rc==SQLITE_ERROR ){ - sqlite3_result_value(context, argv[1]); - }else{ - sqlite3_result_error_code(context, rc); - } + sqlite3_result_error_code(context, rc); } renameParseCleanup(&sParse); } #ifndef SQLITE_OMIT_AUTHORIZATION @@ -110809,12 +109461,11 @@ #endif sqlite3BtreeLeaveAll(db); } -/* Function: sqlite_rename_test(DB,SQL,TYPE,NAME,ISTEMP,WHEN,DQS) -** +/* ** An SQL user function that checks that there are no parse or symbol ** resolution problems in a CREATE TRIGGER|TABLE|VIEW|INDEX statement. ** After an ALTER TABLE .. RENAME operation is performed and the schema ** reloaded, this function is called on each SQL statement in the schema ** to ensure that it is still usable. @@ -110825,17 +109476,15 @@ ** 3: Object name. ** 4: True if object is from temp schema. ** 5: "when" part of error message. ** 6: True to disable the DQS quirk when parsing SQL. ** -** The return value is computed as follows: +** Unless it finds an error, this function normally returns NULL. However, it +** returns integer value 1 if: ** -** A. If an error is seen and not in PRAGMA writable_schema=ON mode, -** then raise the error. -** B. Else if a trigger is created and the the table that the trigger is -** attached to is in database zDb, then return 1. -** C. Otherwise return NULL. +** * the SQL argument creates a trigger, and +** * the table that the trigger is attached to is in database zDb. */ static void renameTableTest( sqlite3_context *context, int NotUsed, sqlite3_value **argv @@ -110876,20 +109525,16 @@ rc = renameResolveTrigger(&sParse); } if( rc==SQLITE_OK ){ int i1 = sqlite3SchemaToIndex(db, sParse.pNewTrigger->pTabSchema); int i2 = sqlite3FindDbName(db, zDb); - if( i1==i2 ){ - /* Handle output case B */ - sqlite3_result_int(context, 1); - } + if( i1==i2 ) sqlite3_result_int(context, 1); } } } - if( rc!=SQLITE_OK && zWhen && !sqlite3WritableSchema(db) ){ - /* Output case A */ + if( rc!=SQLITE_OK && zWhen ){ renameColumnParseError(context, zWhen, argv[2], argv[3],&sParse); } renameParseCleanup(&sParse); } @@ -110946,11 +109591,11 @@ if( iColnCol-1 ){ RenameToken *pEnd; pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zCnName); zEnd = (const char*)pEnd->t.z; }else{ - assert( IsOrdinaryTable(pTab) ); + assert( !IsVirtual(pTab) ); zEnd = (const char*)&zSql[pTab->u.tab.addColOffset]; while( ALWAYS(pCol->t.z[0]!=0) && pCol->t.z[0]!=',' ) pCol->t.z--; } zNew = sqlite3MPrintf(db, "%.*s%s", pCol->t.z-zSql, zSql, zEnd); @@ -111001,11 +109646,11 @@ assert( db->mallocFailed ); goto exit_drop_column; } iCol = sqlite3ColumnIndex(pTab, zCol); if( iCol<0 ){ - sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pName); + sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zCol); goto exit_drop_column; } /* Do not allow the user to drop a PRIMARY KEY column or a column ** constrained by a UNIQUE constraint. */ @@ -111025,20 +109670,14 @@ /* Edit the sqlite_schema table */ iDb = sqlite3SchemaToIndex(db, pTab->pSchema); assert( iDb>=0 ); zDb = db->aDb[iDb].zDbSName; -#ifndef SQLITE_OMIT_AUTHORIZATION - /* Invoke the authorization callback. */ - if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, zCol) ){ - goto exit_drop_column; - } -#endif renameTestSchema(pParse, zDb, iDb==1, "", 0); renameFixQuotes(pParse, zDb, iDb==1); sqlite3NestedParse(pParse, - "UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET " + "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET " "sql = sqlite_drop_column(%d, sql, %d) " "WHERE (type=='table' AND tbl_name=%Q COLLATE nocase)" , zDb, iDb, iCol, pTab->zName ); @@ -112127,11 +110766,11 @@ pParse->nMem = MAX(pParse->nMem, iMem); v = sqlite3GetVdbe(pParse); if( v==0 || NEVER(pTab==0) ){ return; } - if( !IsOrdinaryTable(pTab) ){ + if( pTab->tnum==0 ){ /* Do not gather statistics on views or virtual tables */ return; } if( sqlite3_strlike("sqlite\\_%", pTab->zName, '\\')==0 ){ /* Do not gather statistics on system tables */ @@ -113410,22 +112049,21 @@ if( pParse->nErr ) goto attach_end; memset(&sName, 0, sizeof(NameContext)); sName.pParse = pParse; if( - SQLITE_OK!=resolveAttachExpr(&sName, pFilename) || - SQLITE_OK!=resolveAttachExpr(&sName, pDbname) || - SQLITE_OK!=resolveAttachExpr(&sName, pKey) + SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) || + SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) || + SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey)) ){ goto attach_end; } #ifndef SQLITE_OMIT_AUTHORIZATION - if( ALWAYS(pAuthArg) ){ + if( pAuthArg ){ char *zAuthArg; if( pAuthArg->op==TK_STRING ){ - assert( !ExprHasProperty(pAuthArg, EP_IntValue) ); zAuthArg = pAuthArg->u.zToken; }else{ zAuthArg = 0; } rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0); @@ -114079,17 +112717,15 @@ sqlite3 *db; Vdbe *v; assert( pParse->pToplevel==0 ); db = pParse->db; - assert( db->pParse==pParse ); if( pParse->nested ) return; - if( pParse->nErr ){ - if( db->mallocFailed ) pParse->rc = SQLITE_NOMEM; + if( db->mallocFailed || pParse->nErr ){ + if( pParse->rc==SQLITE_OK ) pParse->rc = SQLITE_ERROR; return; } - assert( db->mallocFailed==0 ); /* Begin by generating some termination code at the end of the ** vdbe program */ v = pParse->pVdbe; @@ -114108,26 +112744,21 @@ Returning *pReturning = pParse->u1.pReturning; int addrRewind; int i; int reg; - if( NEVER(pReturning->nRetCol==0) ){ - assert( CORRUPT_DB ); - }else{ - sqlite3VdbeAddOp0(v, OP_FkCheck); - addrRewind = - sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur); - VdbeCoverage(v); - reg = pReturning->iRetReg; - for(i=0; inRetCol; i++){ - sqlite3VdbeAddOp3(v, OP_Column, pReturning->iRetCur, i, reg+i); - } - sqlite3VdbeAddOp2(v, OP_ResultRow, reg, i); - sqlite3VdbeAddOp2(v, OP_Next, pReturning->iRetCur, addrRewind+1); - VdbeCoverage(v); - sqlite3VdbeJumpHere(v, addrRewind); - } + addrRewind = + sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur); + VdbeCoverage(v); + reg = pReturning->iRetReg; + for(i=0; inRetCol; i++){ + sqlite3VdbeAddOp3(v, OP_Column, pReturning->iRetCur, i, reg+i); + } + sqlite3VdbeAddOp2(v, OP_ResultRow, reg, i); + sqlite3VdbeAddOp2(v, OP_Next, pReturning->iRetCur, addrRewind+1); + VdbeCoverage(v); + sqlite3VdbeJumpHere(v, addrRewind); } sqlite3VdbeAddOp0(v, OP_Halt); #if SQLITE_USER_AUTHENTICATION if( pParse->nTableLock>0 && db->init.busy==0 ){ @@ -114204,27 +112835,21 @@ } } if( pParse->bReturning ){ Returning *pRet = pParse->u1.pReturning; - if( NEVER(pRet->nRetCol==0) ){ - assert( CORRUPT_DB ); - }else{ - sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol); - } + sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol); } /* Finally, jump back to the beginning of the executable code. */ sqlite3VdbeGoto(v, 1); } } /* Get the VDBE program ready for execution */ - assert( v!=0 || pParse->nErr ); - assert( db->mallocFailed==0 || pParse->nErr ); - if( pParse->nErr==0 ){ + if( v && pParse->nErr==0 && !db->mallocFailed ){ /* A minimum of one cursor is required if autoincrement is used * See ticket [a696379c1f08866] */ assert( pParse->pAinc==0 || pParse->nTab>0 ); sqlite3VdbeMakeReady(v, pParse); pParse->rc = SQLITE_DONE; @@ -114247,10 +112872,11 @@ ** built-in function. */ SQLITE_PRIVATE void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){ va_list ap; char *zSql; + char *zErrMsg = 0; sqlite3 *db = pParse->db; u32 savedDbFlags = db->mDbFlags; char saveBuf[PARSE_TAIL_SZ]; if( pParse->nErr ) return; @@ -114268,14 +112894,13 @@ } pParse->nested++; memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ); memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ); db->mDbFlags |= DBFLAG_PreferBuiltin; - sqlite3RunParser(pParse, zSql); - sqlite3DbFree(db, pParse->zErrMsg); - pParse->zErrMsg = 0; + sqlite3RunParser(pParse, zSql, &zErrMsg); db->mDbFlags = savedDbFlags; + sqlite3DbFree(db, zErrMsg); sqlite3DbFree(db, zSql); memcpy(PARSE_TAIL(pParse), saveBuf, PARSE_TAIL_SZ); pParse->nested--; } @@ -114328,21 +112953,21 @@ } } p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName); if( p==0 && sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){ if( i==1 ){ - if( sqlite3StrICmp(zName+7, &PREFERRED_TEMP_SCHEMA_TABLE[7])==0 - || sqlite3StrICmp(zName+7, &PREFERRED_SCHEMA_TABLE[7])==0 - || sqlite3StrICmp(zName+7, &LEGACY_SCHEMA_TABLE[7])==0 + if( sqlite3StrICmp(zName+7, &ALT_TEMP_SCHEMA_TABLE[7])==0 + || sqlite3StrICmp(zName+7, &ALT_SCHEMA_TABLE[7])==0 + || sqlite3StrICmp(zName+7, &DFLT_SCHEMA_TABLE[7])==0 ){ p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, - LEGACY_TEMP_SCHEMA_TABLE); + DFLT_TEMP_SCHEMA_TABLE); } }else{ - if( sqlite3StrICmp(zName+7, &PREFERRED_SCHEMA_TABLE[7])==0 ){ + if( sqlite3StrICmp(zName+7, &ALT_SCHEMA_TABLE[7])==0 ){ p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, - LEGACY_SCHEMA_TABLE); + DFLT_SCHEMA_TABLE); } } } }else{ /* Match against TEMP first */ @@ -114356,15 +112981,15 @@ assert( sqlite3SchemaMutexHeld(db, i, 0) ); p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName); if( p ) break; } if( p==0 && sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){ - if( sqlite3StrICmp(zName+7, &PREFERRED_SCHEMA_TABLE[7])==0 ){ - p = sqlite3HashFind(&db->aDb[0].pSchema->tblHash, LEGACY_SCHEMA_TABLE); - }else if( sqlite3StrICmp(zName+7, &PREFERRED_TEMP_SCHEMA_TABLE[7])==0 ){ + if( sqlite3StrICmp(zName+7, &ALT_SCHEMA_TABLE[7])==0 ){ + p = sqlite3HashFind(&db->aDb[0].pSchema->tblHash, DFLT_SCHEMA_TABLE); + }else if( sqlite3StrICmp(zName+7, &ALT_TEMP_SCHEMA_TABLE[7])==0 ){ p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, - LEGACY_TEMP_SCHEMA_TABLE); + DFLT_TEMP_SCHEMA_TABLE); } } } return p; } @@ -114456,26 +113081,10 @@ zDb = p->zDatabase; } return sqlite3LocateTable(pParse, flags, p->zName, zDb); } -/* -** Return the preferred table name for system tables. Translate legacy -** names into the new preferred names, as appropriate. -*/ -SQLITE_PRIVATE const char *sqlite3PreferredTableName(const char *zName){ - if( sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){ - if( sqlite3StrICmp(zName+7, &LEGACY_SCHEMA_TABLE[7])==0 ){ - return PREFERRED_SCHEMA_TABLE; - } - if( sqlite3StrICmp(zName+7, &LEGACY_TEMP_SCHEMA_TABLE[7])==0 ){ - return PREFERRED_TEMP_SCHEMA_TABLE; - } - } - return zName; -} - /* ** Locate the in-memory structure that describes ** a particular index given the name of that index ** and the name of the database that contains the index. ** Return NULL if not found. @@ -114648,11 +113257,11 @@ Table *pTab, /* The table containing the column */ Column *pCol, /* The column to receive the new DEFAULT expression */ Expr *pExpr /* The new default expression */ ){ ExprList *pList; - assert( IsOrdinaryTable(pTab) ); + assert( !IsVirtual(pTab) ); pList = pTab->u.tab.pDfltList; if( pCol->iDflt==0 || NEVER(pList==0) || NEVER(pList->nExpriDflt) ){ @@ -114669,11 +113278,11 @@ ** the DEFAULT clause or the AS clause of a generated column. ** Return NULL if the column has no associated expression. */ SQLITE_PRIVATE Expr *sqlite3ColumnExpr(Table *pTab, Column *pCol){ if( pCol->iDflt==0 ) return 0; - if( NEVER(!IsOrdinaryTable(pTab)) ) return 0; + if( NEVER(IsVirtual(pTab)) ) return 0; if( NEVER(pTab->u.tab.pDfltList==0) ) return 0; if( NEVER(pTab->u.tab.pDfltList->nExpriDflt) ) return 0; return pTab->u.tab.pDfltList->a[pCol->iDflt-1].pExpr; } @@ -114683,12 +113292,12 @@ SQLITE_PRIVATE void sqlite3ColumnSetColl( sqlite3 *db, Column *pCol, const char *zColl ){ - i64 nColl; - i64 n; + int nColl; + int n; char *zNew; assert( zColl!=0 ); n = sqlite3Strlen30(pCol->zCnName) + 1; if( pCol->colFlags & COLFLAG_HASTYPE ){ n += sqlite3Strlen30(pCol->zCnName+n) + 1; @@ -114728,17 +113337,17 @@ for(i=0; inCol; i++, pCol++){ assert( pCol->zCnName==0 || pCol->hName==sqlite3StrIHash(pCol->zCnName) ); sqlite3DbFree(db, pCol->zCnName); } sqlite3DbFree(db, pTable->aCol); - if( IsOrdinaryTable(pTable) ){ + if( !IsVirtual(pTable) ){ sqlite3ExprListDelete(db, pTable->u.tab.pDfltList); } if( db==0 || db->pnBytesFreed==0 ){ pTable->aCol = 0; pTable->nCol = 0; - if( IsOrdinaryTable(pTable) ){ + if( !IsVirtual(pTable) ){ pTable->u.tab.pDfltList = 0; } } } } @@ -114870,11 +113479,11 @@ ** Open the sqlite_schema table stored in database number iDb for ** writing. The table is opened using cursor 0. */ SQLITE_PRIVATE void sqlite3OpenSchemaTable(Parse *p, int iDb){ Vdbe *v = sqlite3GetVdbe(p); - sqlite3TableLock(p, iDb, SCHEMA_ROOT, 1, LEGACY_SCHEMA_TABLE); + sqlite3TableLock(p, iDb, SCHEMA_ROOT, 1, DFLT_SCHEMA_TABLE); sqlite3VdbeAddOp4Int(v, OP_OpenWrite, 0, SCHEMA_ROOT, iDb, 5); if( p->nTab==0 ){ p->nTab = 1; } } @@ -115231,12 +113840,11 @@ goto begin_table_error; } pTable = sqlite3FindTable(db, zName, zDb); if( pTable ){ if( !noErr ){ - sqlite3ErrorMsg(pParse, "%s %T already exists", - (IsView(pTable)? "view" : "table"), pName); + sqlite3ErrorMsg(pParse, "table %T already exists", pName); }else{ assert( !db->init.busy || CORRUPT_DB ); sqlite3CodeVerifySchema(pParse, iDb); sqlite3ForceNotReadOnly(pParse); } @@ -115490,11 +114098,11 @@ break; } } } - z = sqlite3DbMallocRaw(db, (i64)sName.n + 1 + (i64)sType.n + (sType.n>0) ); + z = sqlite3DbMallocRaw(db, sName.n + 1 + sType.n + (sType.n>0) ); if( z==0 ) return; if( IN_RENAME_OBJECT ) sqlite3RenameTokenMap(pParse, (void*)z, &sName); memcpy(z, sName.z, sName.n); z[sName.n] = 0; sqlite3Dequote(z); @@ -115504,11 +114112,11 @@ sqlite3ErrorMsg(pParse, "duplicate column name: %s", z); sqlite3DbFree(db, z); return; } } - aNew = sqlite3DbRealloc(db,p->aCol,((i64)p->nCol+1)*sizeof(p->aCol[0])); + aNew = sqlite3DbRealloc(db,p->aCol,(p->nCol+1)*sizeof(p->aCol[0])); if( aNew==0 ){ sqlite3DbFree(db, z); return; } p->aCol = aNew; @@ -115802,13 +114410,11 @@ for(i=0; ia[i].pExpr); assert( pCExpr!=0 ); sqlite3StringToId(pCExpr); if( pCExpr->op==TK_ID ){ - const char *zCName; - assert( !ExprHasProperty(pCExpr, EP_IntValue) ); - zCName = pCExpr->u.zToken; + const char *zCName = pCExpr->u.zToken; for(iCol=0; iColnCol; iCol++){ if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zCnName)==0 ){ pCol = &pTab->aCol[iCol]; makeColumnPartOfPrimaryKey(pParse, pCol); break; @@ -116176,10 +114782,11 @@ ** This is used to determine if the column number x appears in any of the ** first nCol entries of an index. */ static int hasColumn(const i16 *aiCol, int nCol, int x){ while( nCol-- > 0 ){ + assert( aiCol[0]>=0 ); if( x==*(aiCol++) ){ return 1; } } return 0; @@ -116327,15 +114934,14 @@ pList->a[0].sortFlags = pParse->iPkSortOrder; assert( pParse->pNewTable==pTab ); pTab->iPKey = -1; sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0, SQLITE_IDXTYPE_PRIMARYKEY); - if( pParse->nErr ){ + if( db->mallocFailed || pParse->nErr ){ pTab->tabFlags &= ~TF_WithoutRowid; return; } - assert( db->mallocFailed==0 ); pPk = sqlite3PrimaryKeyIndex(pTab); assert( pPk->nKeyCol==1 ); }else{ pPk = sqlite3PrimaryKeyIndex(pTab); assert( pPk!=0 ); @@ -116451,45 +115057,10 @@ if( pMod->pModule->xShadowName==0 ) return 0; return pMod->pModule->xShadowName(zName+nName+1); } #endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */ -#ifndef SQLITE_OMIT_VIRTUALTABLE -/* -** Table pTab is a virtual table. If it the virtual table implementation -** exists and has an xShadowName method, then loop over all other ordinary -** tables within the same schema looking for shadow tables of pTab, and mark -** any shadow tables seen using the TF_Shadow flag. -*/ -SQLITE_PRIVATE void sqlite3MarkAllShadowTablesOf(sqlite3 *db, Table *pTab){ - int nName; /* Length of pTab->zName */ - Module *pMod; /* Module for the virtual table */ - HashElem *k; /* For looping through the symbol table */ - - assert( IsVirtual(pTab) ); - pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->u.vtab.azArg[0]); - if( pMod==0 ) return; - if( NEVER(pMod->pModule==0) ) return; - if( pMod->pModule->iVersion<3 ) return; - if( pMod->pModule->xShadowName==0 ) return; - assert( pTab->zName!=0 ); - nName = sqlite3Strlen30(pTab->zName); - for(k=sqliteHashFirst(&pTab->pSchema->tblHash); k; k=sqliteHashNext(k)){ - Table *pOther = sqliteHashData(k); - assert( pOther->zName!=0 ); - if( !IsOrdinaryTable(pOther) ) continue; - if( pOther->tabFlags & TF_Shadow ) continue; - if( sqlite3StrNICmp(pOther->zName, pTab->zName, nName)==0 - && pOther->zName[nName]=='_' - && pMod->pModule->xShadowName(pOther->zName+nName+1) - ){ - pOther->tabFlags |= TF_Shadow; - } - } -} -#endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */ - #ifndef SQLITE_OMIT_VIRTUALTABLE /* ** Return true if zName is a shadow table name in the current database ** connection. ** @@ -116587,11 +115158,11 @@ ** ** If the root page number is 1, that means this is the sqlite_schema ** table itself. So mark it read-only. */ if( db->init.busy ){ - if( pSelect || (!IsOrdinaryTable(p) && db->init.newTnum) ){ + if( pSelect ){ sqlite3ErrorMsg(pParse, ""); return; } p->tnum = db->init.newTnum; if( p->tnum==1 ) p->tabFlags |= TF_Readonly; @@ -116762,15 +115333,10 @@ int regRec; /* A record to be insert into the new table */ int regRowid; /* Rowid of the next row to insert */ int addrInsLoop; /* Top of the loop for inserting rows */ Table *pSelTab; /* A table that describes the SELECT results */ - if( IN_SPECIAL_PARSE ){ - pParse->rc = SQLITE_ERROR; - pParse->nErr++; - return; - } regYield = ++pParse->nMem; regRec = ++pParse->nMem; regRowid = ++pParse->nMem; assert(pParse->nTab==1); sqlite3MayAbort(pParse); @@ -116819,11 +115385,11 @@ /* A slot for the record has already been allocated in the ** schema table. We just need to update that slot with all ** the information we've collected. */ sqlite3NestedParse(pParse, - "UPDATE %Q." LEGACY_SCHEMA_TABLE + "UPDATE %Q." DFLT_SCHEMA_TABLE " SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q" " WHERE rowid=#%d", db->aDb[iDb].zDbSName, zType, p->zName, @@ -117005,16 +115571,17 @@ #endif assert( pTable ); #ifndef SQLITE_OMIT_VIRTUALTABLE - if( IsVirtual(pTable) ){ - db->nSchemaLock++; - rc = sqlite3VtabCallConnect(pParse, pTable); - db->nSchemaLock--; - return rc; + db->nSchemaLock++; + rc = sqlite3VtabCallConnect(pParse, pTable); + db->nSchemaLock--; + if( rc ){ + return 1; } + if( IsVirtual(pTable) ) return 0; #endif #ifndef SQLITE_OMIT_VIEW /* A positive nCol means the columns names for this view are ** already known. @@ -117077,14 +115644,14 @@ ** normally holds CHECK constraints on an ordinary table, but for ** a VIEW it holds the list of column names. */ sqlite3ColumnsFromExprList(pParse, pTable->pCheck, &pTable->nCol, &pTable->aCol); - if( pParse->nErr==0 + if( db->mallocFailed==0 + && pParse->nErr==0 && pTable->nCol==pSel->pEList->nExpr ){ - assert( db->mallocFailed==0 ); sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel, SQLITE_AFF_NONE); } }else{ /* CREATE VIEW name AS... without an argument list. Construct @@ -117198,11 +115765,11 @@ ** The "#NNN" in the SQL is a special constant that means whatever value ** is in register NNN. See grammar rules associated with the TK_REGISTER ** token for additional information. */ sqlite3NestedParse(pParse, - "UPDATE %Q." LEGACY_SCHEMA_TABLE + "UPDATE %Q." DFLT_SCHEMA_TABLE " SET rootpage=%d WHERE #%d AND rootpage=#%d", pParse->db->aDb[iDb].zDbSName, iTable, r1, r1); #endif sqlite3ReleaseTempReg(pParse, r1); } @@ -117333,11 +115900,11 @@ ** dropped. Triggers are handled separately because a trigger can be ** created in the temp database that refers to a table in another ** database. */ sqlite3NestedParse(pParse, - "DELETE FROM %Q." LEGACY_SCHEMA_TABLE + "DELETE FROM %Q." DFLT_SCHEMA_TABLE " WHERE tbl_name=%Q and type!='trigger'", pDb->zDbSName, pTab->zName); if( !isView && !IsVirtual(pTab) ){ destroyTable(pParse, pTab); } @@ -117381,13 +115948,10 @@ return 1; } if( (pTab->tabFlags & TF_Shadow)!=0 && sqlite3ReadOnlyShadowTables(db) ){ return 1; } - if( pTab->tabFlags & TF_Eponymous ){ - return 1; - } return 0; } /* ** This routine is called to do the work of a DROP TABLE statement. @@ -117523,11 +116087,11 @@ sqlite3 *db = pParse->db; #ifndef SQLITE_OMIT_FOREIGN_KEY FKey *pFKey = 0; FKey *pNextTo; Table *p = pParse->pNewTable; - i64 nByte; + int nByte; int i; int nCol; char *z; assert( pTo!=0 ); @@ -117559,11 +116123,10 @@ pFKey = sqlite3DbMallocZero(db, nByte ); if( pFKey==0 ){ goto fk_end; } pFKey->pFrom = p; - assert( IsOrdinaryTable(p) ); pFKey->pNextFrom = p->u.tab.pFKey; z = (char*)&pFKey->aCol[nCol]; pFKey->zTo = z; if( IN_RENAME_OBJECT ){ sqlite3RenameTokenMap(pParse, (void*)z, pTo); @@ -117625,11 +116188,11 @@ pNextTo->pPrevTo = pFKey; } /* Link the foreign key to the table as the last step. */ - assert( IsOrdinaryTable(p) ); + assert( !IsVirtual(p) ); p->u.tab.pFKey = pFKey; pFKey = 0; fk_end: sqlite3DbFree(db, pFKey); @@ -117648,11 +116211,11 @@ SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse *pParse, int isDeferred){ #ifndef SQLITE_OMIT_FOREIGN_KEY Table *pTab; FKey *pFKey; if( (pTab = pParse->pNewTable)==0 ) return; - if( NEVER(!IsOrdinaryTable(pTab)) ) return; + if( NEVER(IsVirtual(pTab)) ) return; if( (pFKey = pTab->u.tab.pFKey)==0 ) return; assert( isDeferred==0 || isDeferred==1 ); /* EV: R-30323-21917 */ pFKey->isDeferred = (u8)isDeferred; #endif } @@ -117699,11 +116262,11 @@ tnum = (Pgno)memRootPage; }else{ tnum = pIndex->tnum; } pKey = sqlite3KeyInfoOfIndex(pParse, pIndex); - assert( pKey!=0 || pParse->nErr ); + assert( pKey!=0 || db->mallocFailed || pParse->nErr ); /* Open the sorter cursor if we are to use one. */ iSorter = pParse->nTab++; sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, pIndex->nKeyCol, (char*) sqlite3KeyInfoRef(pKey), P4_KEYINFO); @@ -117863,15 +116426,13 @@ int nExtra = 0; /* Space allocated for zExtra[] */ int nExtraCol; /* Number of extra columns needed */ char *zExtra = 0; /* Extra space after the Index object */ Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */ - assert( db->pParse==pParse ); - if( pParse->nErr ){ + if( db->mallocFailed || pParse->nErr>0 ){ goto exit_create_index; } - assert( db->mallocFailed==0 ); if( IN_DECLARE_VTAB && idxType!=SQLITE_IDXTYPE_PRIMARYKEY ){ goto exit_create_index; } if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){ goto exit_create_index; @@ -117931,10 +116492,11 @@ iDb = sqlite3SchemaToIndex(db, pTab->pSchema); } pDb = &db->aDb[iDb]; assert( pTab!=0 ); + assert( pParse->nErr==0 ); if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 && db->init.busy==0 && pTblName!=0 #if SQLITE_USER_AUTHENTICATION && sqlite3UserAuthTable(pTab->zName)==0 @@ -118051,11 +116613,10 @@ */ for(i=0; inExpr; i++){ Expr *pExpr = pList->a[i].pExpr; assert( pExpr!=0 ); if( pExpr->op==TK_COLLATE ){ - assert( !ExprHasProperty(pExpr, EP_IntValue) ); nExtra += (1 + sqlite3Strlen30(pExpr->u.zToken)); } } /* @@ -118147,11 +116708,10 @@ pIndex->aiColumn[i] = (i16)j; } zColl = 0; if( pListItem->pExpr->op==TK_COLLATE ){ int nColl; - assert( !ExprHasProperty(pListItem->pExpr, EP_IntValue) ); zColl = pListItem->pExpr->u.zToken; nColl = sqlite3Strlen30(zColl) + 1; assert( nExtra>=nColl ); memcpy(zExtra, zColl, nColl); zColl = zExtra; @@ -118354,17 +116914,17 @@ } /* Add an entry in sqlite_schema for this index */ sqlite3NestedParse(pParse, - "INSERT INTO %Q." LEGACY_SCHEMA_TABLE " VALUES('index',%Q,%Q,#%d,%Q);", - db->aDb[iDb].zDbSName, - pIndex->zName, - pTab->zName, - iMem, - zStmt - ); + "INSERT INTO %Q." DFLT_SCHEMA_TABLE " VALUES('index',%Q,%Q,#%d,%Q);", + db->aDb[iDb].zDbSName, + pIndex->zName, + pTab->zName, + iMem, + zStmt + ); sqlite3DbFree(db, zStmt); /* Fill the index with data and reparse the schema. Code an OP_Expire ** to invalidate all pre-compiled statements. */ @@ -118494,14 +117054,14 @@ Index *pIndex; Vdbe *v; sqlite3 *db = pParse->db; int iDb; + assert( pParse->nErr==0 ); /* Never called with prior errors */ if( db->mallocFailed ){ goto exit_drop_index; } - assert( pParse->nErr==0 ); /* Never called with prior non-OOM errors */ assert( pName->nSrc==1 ); if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){ goto exit_drop_index; } pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase); @@ -118540,11 +117100,11 @@ /* Generate code to remove the index and from the schema table */ v = sqlite3GetVdbe(pParse); if( v ){ sqlite3BeginWriteOperation(pParse, 1, iDb); sqlite3NestedParse(pParse, - "DELETE FROM %Q." LEGACY_SCHEMA_TABLE " WHERE name=%Q AND type='index'", + "DELETE FROM %Q." DFLT_SCHEMA_TABLE " WHERE name=%Q AND type='index'", db->aDb[iDb].zDbSName, pIndex->zName ); sqlite3ClearStatTables(pParse, iDb, "idx", pIndex->zName); sqlite3ChangeCookie(pParse, iDb); destroyRootPage(pParse, pIndex->tnum, iDb); @@ -118908,11 +117468,11 @@ pItem->pSelect = pSubquery; pItem->pOn = pOn; pItem->pUsing = pUsing; return p; -append_from_error: + append_from_error: assert( p==0 ); sqlite3ExprDelete(db, pOn); sqlite3IdListDelete(db, pUsing); sqlite3SelectDelete(db, pSubquery); return 0; @@ -118936,11 +117496,10 @@ ** construct "indexed_opt" for details. */ pItem->fg.notIndexed = 1; }else{ pItem->u1.zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy); pItem->fg.isIndexedBy = 1; - assert( pItem->fg.isCte==0 ); /* No collision on union u2 */ } } } /* @@ -119917,11 +118476,10 @@ int h, /* Hash of the name */ const char *zFunc /* Name of function */ ){ FuncDef *p; for(p=sqlite3BuiltinFunctions.a[h]; p; p=p->u.pHash){ - assert( p->funcFlags & SQLITE_FUNC_BUILTIN ); if( sqlite3StrICmp(p->zName, zFunc)==0 ){ return p; } } return 0; @@ -119938,11 +118496,11 @@ for(i=0; i='a' && zName[0]<='z' ); pOther = sqlite3FunctionSearch(h, zName); if( pOther ){ assert( pOther!=&aDef[i] && pOther->pNext!=&aDef[i] ); aDef[i].pNext = pOther->pNext; pOther->pNext = &aDef[i]; @@ -120164,20 +118722,10 @@ } } return pTab; } -/* Generate byte-code that will report the number of rows modified -** by a DELETE, INSERT, or UPDATE statement. -*/ -SQLITE_PRIVATE void sqlite3CodeChangeCount(Vdbe *v, int regCounter, const char *zColName){ - sqlite3VdbeAddOp0(v, OP_FkCheck); - sqlite3VdbeAddOp2(v, OP_ResultRow, regCounter, 1); - sqlite3VdbeSetNumCols(v, 1); - sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zColName, SQLITE_STATIC); -} - /* Return true if table pTab is read-only. ** ** A table is read-only if any of the following are true: ** ** 1) It is a virtual table and no implementation of the xUpdate method @@ -120340,11 +118888,10 @@ ** and the SELECT subtree. */ pSrc->a[0].pTab = 0; pSelectSrc = sqlite3SrcListDup(db, pSrc, 0); pSrc->a[0].pTab = pTab; if( pSrc->a[0].fg.isIndexedBy ){ - assert( pSrc->a[0].fg.isCte==0 ); pSrc->a[0].u2.pIBIndex = 0; pSrc->a[0].fg.isIndexedBy = 0; sqlite3DbFree(db, pSrc->a[0].u1.zIndexedBy); }else if( pSrc->a[0].fg.isCte ){ pSrc->a[0].u2.pCteUse->nUse++; @@ -120413,15 +118960,13 @@ Trigger *pTrigger; /* List of table triggers, if required */ #endif memset(&sContext, 0, sizeof(sContext)); db = pParse->db; - assert( db->pParse==pParse ); - if( pParse->nErr ){ + if( pParse->nErr || db->mallocFailed ){ goto delete_from_cleanup; } - assert( db->mallocFailed==0 ); assert( pTabList->nSrc==1 ); /* Locate the table which we want to delete. This table has to be ** put in an SrcList structure because some of the subroutines we @@ -120598,11 +119143,11 @@ ** ** ONEPASS_OFF: Two-pass approach - use a FIFO for rowids/PK values. ** ONEPASS_SINGLE: One-pass approach - at most one row deleted. ** ONEPASS_MULTI: One-pass approach - any number of rows may be deleted. */ - pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,0,wcf,iTabCur+1); + pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, wcf, iTabCur+1); if( pWInfo==0 ) goto delete_from_cleanup; eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass); assert( IsVirtual(pTab)==0 || eOnePass!=ONEPASS_MULTI ); assert( IsVirtual(pTab) || bComplex || eOnePass!=ONEPASS_OFF ); if( eOnePass!=ONEPASS_SINGLE ) sqlite3MultiWrite(pParse); @@ -120751,11 +119296,13 @@ /* Return the number of rows that were deleted. If this routine is ** generating code because of a call to sqlite3NestedParse(), do not ** invoke the callback function. */ if( memCnt ){ - sqlite3CodeChangeCount(v, memCnt, "rows deleted"); + sqlite3VdbeAddOp2(v, OP_ChngCntRow, memCnt, 1); + sqlite3VdbeSetNumCols(v, 1); + sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows deleted", SQLITE_STATIC); } delete_from_cleanup: sqlite3AuthContextPop(&sContext); sqlite3SrcListDelete(db, pTabList); @@ -121202,22 +119749,10 @@ ** V. The returned value is one of SQLITE_INTEGER, SQLITE_FLOAT, ** SQLITE_TEXT, SQLITE_BLOB, or SQLITE_NULL. */ sqlite3_result_text(context, azType[i], -1, SQLITE_STATIC); } -/* subtype(X) -** -** Return the subtype of X -*/ -static void subtypeFunc( - sqlite3_context *context, - int argc, - sqlite3_value **argv -){ - UNUSED_PARAMETER(argc); - sqlite3_result_int(context, sqlite3_value_subtype(argv[0])); -} /* ** Implementation of the length() function */ static void lengthFunc( @@ -121375,11 +119910,11 @@ sqlite3_result_error_nomem(context); goto endInstr; } /* -** Implementation of the printf() (a.k.a. format()) SQL function. +** Implementation of the printf() function. */ static void printfFunc( sqlite3_context *context, int argc, sqlite3_value **argv @@ -122144,97 +120679,88 @@ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; /* -** Append to pStr text that is the SQL literal representation of the -** value contained in pValue. +** Implementation of the QUOTE() function. This function takes a single +** argument. If the argument is numeric, the return value is the same as +** the argument. If the argument is NULL, the return value is the string +** "NULL". Otherwise, the argument is enclosed in single quotes with +** single-quote escapes. */ -SQLITE_PRIVATE void sqlite3QuoteValue(StrAccum *pStr, sqlite3_value *pValue){ - /* As currently implemented, the string must be initially empty. - ** we might relax this requirement in the future, but that will - ** require enhancements to the implementation. */ - assert( pStr!=0 && pStr->nChar==0 ); - - switch( sqlite3_value_type(pValue) ){ +static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ + assert( argc==1 ); + UNUSED_PARAMETER(argc); + switch( sqlite3_value_type(argv[0]) ){ case SQLITE_FLOAT: { double r1, r2; - const char *zVal; - r1 = sqlite3_value_double(pValue); - sqlite3_str_appendf(pStr, "%!.15g", r1); - zVal = sqlite3_str_value(pStr); - if( zVal ){ - sqlite3AtoF(zVal, &r2, pStr->nChar, SQLITE_UTF8); - if( r1!=r2 ){ - sqlite3_str_reset(pStr); - sqlite3_str_appendf(pStr, "%!.20e", r1); - } - } + char zBuf[50]; + r1 = sqlite3_value_double(argv[0]); + sqlite3_snprintf(sizeof(zBuf), zBuf, "%!.15g", r1); + sqlite3AtoF(zBuf, &r2, 20, SQLITE_UTF8); + if( r1!=r2 ){ + sqlite3_snprintf(sizeof(zBuf), zBuf, "%!.20e", r1); + } + sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); break; } case SQLITE_INTEGER: { - sqlite3_str_appendf(pStr, "%lld", sqlite3_value_int64(pValue)); + sqlite3_result_value(context, argv[0]); break; } case SQLITE_BLOB: { - char const *zBlob = sqlite3_value_blob(pValue); - int nBlob = sqlite3_value_bytes(pValue); - assert( zBlob==sqlite3_value_blob(pValue) ); /* No encoding change */ - sqlite3StrAccumEnlarge(pStr, nBlob*2 + 4); - if( pStr->accError==0 ){ - char *zText = pStr->zText; + char *zText = 0; + char const *zBlob = sqlite3_value_blob(argv[0]); + int nBlob = sqlite3_value_bytes(argv[0]); + assert( zBlob==sqlite3_value_blob(argv[0]) ); /* No encoding change */ + zText = (char *)contextMalloc(context, (2*(i64)nBlob)+4); + if( zText ){ int i; for(i=0; i>4)&0x0F]; zText[(i*2)+3] = hexdigits[(zBlob[i])&0x0F]; } zText[(nBlob*2)+2] = '\''; zText[(nBlob*2)+3] = '\0'; zText[0] = 'X'; zText[1] = '\''; - pStr->nChar = nBlob*2 + 3; + sqlite3_result_text(context, zText, -1, SQLITE_TRANSIENT); + sqlite3_free(zText); } break; } case SQLITE_TEXT: { - const unsigned char *zArg = sqlite3_value_text(pValue); - sqlite3_str_appendf(pStr, "%Q", zArg); + int i,j; + u64 n; + const unsigned char *zArg = sqlite3_value_text(argv[0]); + char *z; + + if( zArg==0 ) return; + for(i=0, n=0; zArg[i]; i++){ if( zArg[i]=='\'' ) n++; } + z = contextMalloc(context, ((i64)i)+((i64)n)+3); + if( z ){ + z[0] = '\''; + for(i=0, j=1; zArg[i]; i++){ + z[j++] = zArg[i]; + if( zArg[i]=='\'' ){ + z[j++] = '\''; + } + } + z[j++] = '\''; + z[j] = 0; + sqlite3_result_text(context, z, j, sqlite3_free); + } break; } default: { - assert( sqlite3_value_type(pValue)==SQLITE_NULL ); - sqlite3_str_append(pStr, "NULL", 4); + assert( sqlite3_value_type(argv[0])==SQLITE_NULL ); + sqlite3_result_text(context, "NULL", 4, SQLITE_STATIC); break; } } } -/* -** Implementation of the QUOTE() function. -** -** The quote(X) function returns the text of an SQL literal which is the -** value of its argument suitable for inclusion into an SQL statement. -** Strings are surrounded by single-quotes with escapes on interior quotes -** as needed. BLOBs are encoded as hexadecimal literals. Strings with -** embedded NUL characters cannot be represented as string literals in SQL -** and hence the returned string literal is truncated prior to the first NUL. -*/ -static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ - sqlite3_str str; - sqlite3 *db = sqlite3_context_db_handle(context); - assert( argc==1 ); - UNUSED_PARAMETER(argc); - sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]); - sqlite3QuoteValue(&str,argv[0]); - sqlite3_result_text(context, sqlite3StrAccumFinish(&str), str.nChar, - SQLITE_DYNAMIC); - if( str.accError!=SQLITE_OK ){ - sqlite3_result_null(context); - sqlite3_result_error_code(context, str.accError); - } -} - /* ** The unicode() function. Return the integer unicode code-point value ** for the first character of the input string. */ static void unicodeFunc( @@ -122946,15 +121472,11 @@ if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; pGCC = (GroupConcatCtx*)sqlite3_aggregate_context(context, sizeof(*pGCC)); /* pGCC is always non-NULL since groupConcatStep() will have always ** run frist to initialize it */ if( ALWAYS(pGCC) ){ - int nVS; - /* Must call sqlite3_value_text() to convert the argument into text prior - ** to invoking sqlite3_value_bytes(), in case the text encoding is UTF16 */ - (void)sqlite3_value_text(argv[0]); - nVS = sqlite3_value_bytes(argv[0]); + int nVS = sqlite3_value_bytes(argv[0]); pGCC->nAccum -= 1; if( pGCC->pnSepLengths!=0 ){ assert(pGCC->nAccum >= 0); if( pGCC->nAccum>0 ){ nVS += *pGCC->pnSepLengths; @@ -123065,16 +121587,15 @@ SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){ FuncDef *pDef; int nExpr; assert( pExpr!=0 ); assert( pExpr->op==TK_FUNCTION ); - assert( ExprUseXList(pExpr) ); if( !pExpr->x.pList ){ return 0; } + assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); nExpr = pExpr->x.pList->nExpr; - assert( !ExprHasProperty(pExpr, EP_IntValue) ); pDef = sqlite3FindFunction(db, pExpr->u.zToken, nExpr, SQLITE_UTF8, 0); #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION if( pDef==0 ) return 0; #endif if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){ @@ -123094,11 +121615,10 @@ aWc[3] = 0; }else{ Expr *pEscape = pExpr->x.pList->a[2].pExpr; char *zEscape; if( pEscape->op!=TK_STRING ) return 0; - assert( !ExprHasProperty(pEscape, EP_IntValue) ); zEscape = pEscape->u.zToken; if( zEscape[0]==0 || zEscape[1]!=0 ) return 0; if( zEscape[0]==aWc[0] ) return 0; if( zEscape[0]==aWc[1] ) return 0; aWc[3] = zEscape[0]; @@ -123346,12 +121866,12 @@ #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ INLINE_FUNC(unlikely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY), INLINE_FUNC(likelihood, 2, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY), INLINE_FUNC(likely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY), #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC - {1, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_OFFSET|SQLITE_FUNC_TYPEOF, - 0, 0, noopFunc, 0, 0, 0, "sqlite_offset", {0} }, + FUNCTION2(sqlite_offset, 1, 0, 0, noopFunc, SQLITE_FUNC_OFFSET| + SQLITE_FUNC_TYPEOF), #endif FUNCTION(ltrim, 1, 1, 0, trimFunc ), FUNCTION(ltrim, 2, 1, 0, trimFunc ), FUNCTION(rtrim, 1, 2, 0, trimFunc ), FUNCTION(rtrim, 2, 2, 0, trimFunc ), @@ -123364,15 +121884,13 @@ FUNCTION(max, -1, 1, 1, minmaxFunc ), FUNCTION(max, 0, 1, 1, 0 ), WAGGREGATE(max, 1, 1, 1, minmaxStep, minMaxFinalize, minMaxValue, 0, SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER ), FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF), - FUNCTION2(subtype, 1, 0, 0, subtypeFunc, SQLITE_FUNC_TYPEOF), FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH), FUNCTION(instr, 2, 0, 0, instrFunc ), FUNCTION(printf, -1, 0, 0, printfFunc ), - FUNCTION(format, -1, 0, 0, printfFunc ), FUNCTION(unicode, 1, 0, 0, unicodeFunc ), FUNCTION(char, -1, 0, 0, charFunc ), FUNCTION(abs, 1, 0, 0, absFunc ), #ifndef SQLITE_OMIT_FLOATING_POINT FUNCTION(round, 1, 0, 0, roundFunc ), @@ -123467,11 +121985,10 @@ #ifndef SQLITE_OMIT_ALTERTABLE sqlite3AlterFunctions(); #endif sqlite3WindowFunctions(); sqlite3RegisterDateTimeFunctions(); - sqlite3RegisterJsonFunctions(); sqlite3InsertBuiltinFuncs(aBuiltinFunc, ArraySize(aBuiltinFunc)); #if 0 /* Enable to print out how the built-in functions are hashed */ { int i; @@ -123479,11 +121996,10 @@ for(i=0; iu.pHash){ int n = sqlite3Strlen30(p->zName); int h = p->zName[0] + n; - assert( p->funcFlags & SQLITE_FUNC_BUILTIN ); printf(" %s(%d)", p->zName, h); } printf("\n"); } } @@ -124002,11 +122518,10 @@ int iCursor, /* The open cursor on the table */ i16 iCol /* The column that is wanted */ ){ Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0); if( pExpr ){ - assert( ExprUseYTab(pExpr) ); pExpr->y.pTab = pTab; pExpr->iTable = iCursor; pExpr->iColumn = iCol; } return pExpr; @@ -124143,11 +122658,11 @@ /* Create VDBE to loop through the entries in pSrc that match the WHERE ** clause. For each row found, increment either the deferred or immediate ** foreign key constraint counter. */ if( pParse->nErr==0 ){ - pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0, 0); + pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0); sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr); if( pWInfo ){ sqlite3WhereEnd(pWInfo); } } @@ -124194,29 +122709,10 @@ sqlite3ExprDelete(dbMem, p->pWhen); sqlite3DbFree(dbMem, p); } } -/* -** Clear the apTrigger[] cache of CASCADE triggers for all foreign keys -** in a particular database. This needs to happen when the schema -** changes. -*/ -SQLITE_PRIVATE void sqlite3FkClearTriggerCache(sqlite3 *db, int iDb){ - HashElem *k; - Hash *pHash = &db->aDb[iDb].pSchema->tblHash; - for(k=sqliteHashFirst(pHash); k; k=sqliteHashNext(k)){ - Table *pTab = sqliteHashData(k); - FKey *pFKey; - if( !IsOrdinaryTable(pTab) ) continue; - for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ - fkTriggerDelete(db, pFKey->apTrigger[0]); pFKey->apTrigger[0] = 0; - fkTriggerDelete(db, pFKey->apTrigger[1]); pFKey->apTrigger[1] = 0; - } - } -} - /* ** This function is called to generate code that runs when table pTab is ** being dropped from the database. The SrcList passed as the second argument ** to this function contains a single entry guaranteed to resolve to ** table pTab. @@ -124232,16 +122728,17 @@ ** the table from the database. Triggers are disabled while running this ** DELETE, but foreign key actions are not. */ SQLITE_PRIVATE void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){ sqlite3 *db = pParse->db; - if( (db->flags&SQLITE_ForeignKeys) && IsOrdinaryTable(pTab) ){ + if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) ){ int iSkip = 0; Vdbe *v = sqlite3GetVdbe(pParse); assert( v ); /* VDBE has already been allocated */ - assert( IsOrdinaryTable(pTab) ); + assert( !IsView(pTab) ); /* Not a view */ + assert( !IsVirtual(pTab) ); if( sqlite3FkReferences(pTab)==0 ){ /* Search for a deferred foreign key constraint for which this table ** is the child table. If one cannot be found, return without ** generating any VDBE code. If one can be found, then jump over ** the entire DELETE if there are no outstanding deferred constraints @@ -124401,17 +122898,17 @@ /* Exactly one of regOld and regNew should be non-zero. */ assert( (regOld==0)!=(regNew==0) ); /* If foreign-keys are disabled, this function is a no-op. */ if( (db->flags&SQLITE_ForeignKeys)==0 ) return; - if( !IsOrdinaryTable(pTab) ) return; iDb = sqlite3SchemaToIndex(db, pTab->pSchema); zDb = db->aDb[iDb].zDbSName; /* Loop through all the foreign key constraints for which pTab is the ** child table (the table that the foreign key definition is part of). */ + assert( !IsVirtual(pTab) ); for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ Table *pTo; /* Parent table of foreign key pFKey */ Index *pIdx = 0; /* Index on key columns in pTo */ int *aiFree = 0; int *aiCol; @@ -124590,13 +123087,14 @@ SQLITE_PRIVATE u32 sqlite3FkOldmask( Parse *pParse, /* Parse context */ Table *pTab /* Table being modified */ ){ u32 mask = 0; - if( pParse->db->flags&SQLITE_ForeignKeys && IsOrdinaryTable(pTab) ){ + if( pParse->db->flags&SQLITE_ForeignKeys ){ FKey *p; int i; + assert( !IsVirtual(pTab) ); for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){ for(i=0; inCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom); } for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){ Index *pIdx = 0; @@ -124643,11 +123141,11 @@ int *aChange, /* Non-NULL for UPDATE operations */ int chngRowid /* True for UPDATE that affects rowid */ ){ int eRet = 1; /* Value to return if bHaveFK is true */ int bHaveFK = 0; /* If FK processing is required */ - if( pParse->db->flags&SQLITE_ForeignKeys && IsOrdinaryTable(pTab) ){ + if( pParse->db->flags&SQLITE_ForeignKeys && !IsVirtual(pTab) ){ if( !aChange ){ /* A DELETE operation. Foreign key processing is required if the ** table in question is either the child or parent table for any ** foreign key constraint. */ bHaveFK = (sqlite3FkReferences(pTab) || pTab->u.tab.pFKey); @@ -124931,11 +123429,11 @@ */ SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){ FKey *pFKey; /* Iterator variable */ FKey *pNext; /* Copy of pFKey->pNextFrom */ - assert( IsOrdinaryTable(pTab) ); + assert( !IsVirtual(pTab) ); for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pNext){ assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) ); /* Remove the FK from the fkeyHash hash table. */ if( !db || db->pnBytesFreed==0 ){ @@ -125013,11 +123511,11 @@ sqlite3VdbeAddOp4Int(v, opcode, iCur, pTab->tnum, iDb, pTab->nNVCol); VdbeComment((v, "%s", pTab->zName)); }else{ Index *pPk = sqlite3PrimaryKeyIndex(pTab); assert( pPk!=0 ); - assert( pPk->tnum==pTab->tnum || CORRUPT_DB ); + assert( pPk->tnum==pTab->tnum ); sqlite3VdbeAddOp3(v, opcode, iCur, pPk->tnum, iDb); sqlite3VdbeSetP4KeyInfo(pParse, pPk); VdbeComment((v, "%s", pTab->zName)); } } @@ -125151,11 +123649,11 @@ sqlite3OomFault(db); return; } for(i=j=0; inCol; i++){ - assert( pTab->aCol[i].affinity!=0 || sqlite3VdbeParser(v)->nErr>0 ); + assert( pTab->aCol[i].affinity!=0 ); if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){ zColAff[j++] = pTab->aCol[i].affinity; } } do{ @@ -125252,34 +123750,28 @@ /* Before computing generated columns, first go through and make sure ** that appropriate affinity has been applied to the regular columns */ sqlite3TableAffinity(pParse->pVdbe, pTab, iRegStore); - if( (pTab->tabFlags & TF_HasStored)!=0 ){ - pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1); - if( pOp->opcode==OP_Affinity ){ - /* Change the OP_Affinity argument to '@' (NONE) for all stored - ** columns. '@' is the no-op affinity and those columns have not - ** yet been computed. */ - int ii, jj; - char *zP4 = pOp->p4.z; - assert( zP4!=0 ); - assert( pOp->p4type==P4_DYNAMIC ); - for(ii=jj=0; zP4[jj]; ii++){ - if( pTab->aCol[ii].colFlags & COLFLAG_VIRTUAL ){ - continue; - } - if( pTab->aCol[ii].colFlags & COLFLAG_STORED ){ - zP4[jj] = SQLITE_AFF_NONE; - } - jj++; - } - }else if( pOp->opcode==OP_TypeCheck ){ - /* If an OP_TypeCheck was generated because the table is STRICT, - ** then set the P3 operand to indicate that generated columns should - ** not be checked */ - pOp->p3 = 1; + if( (pTab->tabFlags & TF_HasStored)!=0 + && (pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1))->opcode==OP_Affinity + ){ + /* Change the OP_Affinity argument to '@' (NONE) for all stored + ** columns. '@' is the no-op affinity and those columns have not + ** yet been computed. */ + int ii, jj; + char *zP4 = pOp->p4.z; + assert( zP4!=0 ); + assert( pOp->p4type==P4_DYNAMIC ); + for(ii=jj=0; zP4[jj]; ii++){ + if( pTab->aCol[ii].colFlags & COLFLAG_VIRTUAL ){ + continue; + } + if( pTab->aCol[ii].colFlags & COLFLAG_STORED ){ + zP4[jj] = SQLITE_AFF_NONE; + } + jj++; } } /* Because there can be multiple generated columns that refer to one another, ** this is a two-pass algorithm. On the first pass, mark all generated @@ -125685,15 +124177,13 @@ Trigger *pTrigger; /* List of triggers on pTab, if required */ int tmask; /* Mask of trigger times */ #endif db = pParse->db; - assert( db->pParse==pParse ); - if( pParse->nErr ){ + if( pParse->nErr || db->mallocFailed ){ goto insert_cleanup; } - assert( db->mallocFailed==0 ); dest.iSDParm = 0; /* Suppress a harmless compiler warning */ /* If the Select object is really just a simple VALUES() list with a ** single row (the common case) then keep that one row of values ** and discard the other (unused) parts of the pSelect object @@ -125765,15 +124255,11 @@ ** Then special optimizations can be applied that make the transfer ** very fast and which reduce fragmentation of indices. ** ** This is the 2nd template. */ - if( pColumn==0 - && pSelect!=0 - && pTrigger==0 - && xferOptimization(pParse, pTab, pSelect, onError, iDb) - ){ + if( pColumn==0 && xferOptimization(pParse, pTab, pSelect, onError, iDb) ){ assert( !pTrigger ); assert( pList==0 ); goto insert_end; } #endif /* SQLITE_OMIT_XFER_OPT */ @@ -125869,13 +124355,11 @@ sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield); dest.iSdst = bIdListInOrder ? regData : 0; dest.nSdst = pTab->nCol; rc = sqlite3Select(pParse, pSelect, &dest); regFromSelect = dest.iSdst; - assert( db->pParse==pParse ); - if( rc || pParse->nErr ) goto insert_cleanup; - assert( db->mallocFailed==0 ); + if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup; sqlite3VdbeEndCoroutine(v, regYield); sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */ assert( pSelect->pEList ); nColumn = pSelect->pEList->nExpr; @@ -126360,11 +124844,13 @@ ** Return the number of rows inserted. If this routine is ** generating code because of a call to sqlite3NestedParse(), do not ** invoke the callback function. */ if( regRowCount ){ - sqlite3CodeChangeCount(v, regRowCount, "rows inserted"); + sqlite3VdbeAddOp2(v, OP_ChngCntRow, regRowCount, 1); + sqlite3VdbeSetNumCols(v, 1); + sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows inserted", SQLITE_STATIC); } insert_cleanup: sqlite3SrcListDelete(db, pTabList); sqlite3ExprListDelete(db, pList); @@ -126985,11 +125471,10 @@ ** the UNIQUE constraints have run. */ if( onError==OE_Replace /* IPK rule is REPLACE */ && onError!=overrideError /* Rules for other constraints are different */ && pTab->pIndex /* There exist other constraints */ - && !upsertIpkDelay /* IPK check already deferred by UPSERT */ ){ ipkTop = sqlite3VdbeAddOp0(v, OP_Goto)+1; VdbeComment((v, "defer IPK REPLACE until last")); } @@ -127203,11 +125688,10 @@ ** (5) No FK constraint counters need to be updated if a conflict occurs. ** ** This is not possible for ENABLE_PREUPDATE_HOOK builds, as the row ** must be explicitly deleted in order to ensure any pre-update hook ** is invoked. */ - assert( IsOrdinaryTable(pTab) ); #ifndef SQLITE_ENABLE_PREUPDATE_HOOK if( (ix==0 && pIdx->pNext==0) /* Condition 3 */ && pPk==pIdx /* Condition 2 */ && onError==OE_Replace /* Condition 1 */ && ( 0==(db->flags&SQLITE_RecTriggers) || /* Condition 4 */ @@ -127310,12 +125794,11 @@ default: { int nConflictCk; /* Number of opcodes in conflict check logic */ assert( onError==OE_Replace ); nConflictCk = sqlite3VdbeCurrentAddr(v) - addrConflictCk; - assert( nConflictCk>0 || db->mallocFailed ); - testcase( nConflictCk<=0 ); + assert( nConflictCk>0 ); testcase( nConflictCk>1 ); if( regTrigCnt ){ sqlite3MultiWrite(pParse); nReplaceTrig++; } @@ -127394,11 +125877,10 @@ /* If the IPK constraint is a REPLACE, run it last */ if( ipkTop ){ sqlite3VdbeGoto(v, ipkTop); VdbeComment((v, "Do IPK REPLACE")); - assert( ipkBottom>0 ); sqlite3VdbeJumpHere(v, ipkBottom); } /* Recheck all uniqueness constraints after replace triggers have run */ testcase( regTrigCnt!=0 && nReplaceTrig==0 ); @@ -127525,10 +126007,11 @@ sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2); VdbeCoverage(v); } pik_flags = (useSeekResult ? OPFLAG_USESEEKRESULT : 0); if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){ + assert( pParse->nested==0 ); pik_flags |= OPFLAG_NCHANGE; pik_flags |= (update_flags & OPFLAG_SAVEPOSITION); if( update_flags==0 ){ codeWithoutRowidPreupdate(pParse, pTab, iIdxCur+i, aRegIdx[i]); } @@ -127597,13 +126080,12 @@ assert( op==OP_OpenRead || op==OP_OpenWrite ); assert( op==OP_OpenWrite || p5==0 ); if( IsVirtual(pTab) ){ /* This routine is a no-op for virtual tables. Leave the output - ** variables *piDataCur and *piIdxCur set to illegal cursor numbers - ** for improved error detection. */ - *piDataCur = *piIdxCur = -999; + ** variables *piDataCur and *piIdxCur uninitialized so that valgrind + ** can detect if they are used by mistake in the caller. */ return 0; } iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema); v = pParse->pVdbe; assert( v!=0 ); @@ -127740,17 +126222,22 @@ Vdbe *v; /* The VDBE we are building */ int regAutoinc; /* Memory register used by AUTOINC */ int destHasUniqueIdx = 0; /* True if pDest has a UNIQUE index */ int regData, regRowid; /* Registers holding data and rowid */ - assert( pSelect!=0 ); + if( pSelect==0 ){ + return 0; /* Must be of the form INSERT INTO ... SELECT ... */ + } if( pParse->pWith || pSelect->pWith ){ /* Do not attempt to process this query if there are an WITH clauses ** attached to it. Proceeding may generate a false "no such table: xxx" ** error if pSelect reads from a CTE named "xxx". */ return 0; } + if( sqlite3TriggerList(pParse, pDest) ){ + return 0; /* tab1 must not have triggers */ + } #ifndef SQLITE_OMIT_VIRTUALTABLE if( IsVirtual(pDest) ){ return 0; /* tab1 must not be a virtual table */ } #endif @@ -127881,13 +126368,11 @@ /* Default values for second and subsequent columns need to match. */ if( (pDestCol->colFlags & COLFLAG_GENERATED)==0 && i>0 ){ Expr *pDestExpr = sqlite3ColumnExpr(pDest, pDestCol); Expr *pSrcExpr = sqlite3ColumnExpr(pSrc, pSrcCol); assert( pDestExpr==0 || pDestExpr->op==TK_SPAN ); - assert( pDestExpr==0 || !ExprHasProperty(pDestExpr, EP_IntValue) ); assert( pSrcExpr==0 || pSrcExpr->op==TK_SPAN ); - assert( pSrcExpr==0 || !ExprHasProperty(pSrcExpr, EP_IntValue) ); if( (pDestExpr==0)!=(pSrcExpr==0) || (pDestExpr!=0 && strcmp(pDestExpr->u.zToken, pSrcExpr->u.zToken)!=0) ){ return 0; /* Default values must be the same for all columns */ @@ -127923,11 +126408,10 @@ ** But the main beneficiary of the transfer optimization is the VACUUM ** command, and the VACUUM command disables foreign key constraints. So ** the extra complication to make this rule less restrictive is probably ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e] */ - assert( IsOrdinaryTable(pDest) ); if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->u.tab.pFKey!=0 ){ return 0; } #endif if( (db->flags & SQLITE_CountRows)!=0 ){ @@ -128605,21 +127089,10 @@ /* Version 3.34.0 and later */ int (*txn_state)(sqlite3*,const char*); /* Version 3.36.1 and later */ sqlite3_int64 (*changes64)(sqlite3*); sqlite3_int64 (*total_changes64)(sqlite3*); - /* Version 3.37.0 and later */ - int (*autovacuum_pages)(sqlite3*, - unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int), - void*, void(*)(void*)); - /* Version 3.38.0 and later */ - int (*error_offset)(sqlite3*); - int (*vtab_rhs_value)(sqlite3_index_info*,int,sqlite3_value**); - int (*vtab_distinct)(sqlite3_index_info*); - int (*vtab_in)(sqlite3_index_info*,int,int); - int (*vtab_in_first)(sqlite3_value*,sqlite3_value**); - int (*vtab_in_next)(sqlite3_value*,sqlite3_value**); }; /* ** This is the function signature used for all extension entry points. It ** is also defined in the file "loadext.c". @@ -128922,22 +127395,10 @@ #define sqlite3_create_filename sqlite3_api->create_filename #define sqlite3_free_filename sqlite3_api->free_filename #define sqlite3_database_file_object sqlite3_api->database_file_object /* Version 3.34.0 and later */ #define sqlite3_txn_state sqlite3_api->txn_state -/* Version 3.36.1 and later */ -#define sqlite3_changes64 sqlite3_api->changes64 -#define sqlite3_total_changes64 sqlite3_api->total_changes64 -/* Version 3.37.0 and later */ -#define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages -/* Version 3.38.0 and later */ -#define sqlite3_error_offset sqlite3_api->error_offset -#define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value -#define sqlite3_vtab_distinct sqlite3_api->vtab_distinct -#define sqlite3_vtab_in sqlite3_api->vtab_in -#define sqlite3_vtab_in_first sqlite3_api->vtab_in_first -#define sqlite3_vtab_in_next sqlite3_api->vtab_in_next #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) /* This case when the file really is being compiled as a loadable ** extension */ @@ -129421,19 +127882,10 @@ /* Version 3.34.0 and later */ sqlite3_txn_state, /* Version 3.36.1 and later */ sqlite3_changes64, sqlite3_total_changes64, - /* Version 3.37.0 and later */ - sqlite3_autovacuum_pages, - /* Version 3.38.0 and later */ - sqlite3_error_offset, - sqlite3_vtab_rhs_value, - sqlite3_vtab_distinct, - sqlite3_vtab_in, - sqlite3_vtab_in_first, - sqlite3_vtab_in_next }; /* True if x is the directory separator character */ #if SQLITE_OS_WIN @@ -130419,11 +128871,11 @@ /* iArg: */ 0 }, {/* zName: */ "table_list", /* ePragTyp: */ PragTyp_TABLE_LIST, /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1, /* ColNames: */ 15, 6, - /* iArg: */ 0 }, + /* iArg: */ 1 }, {/* zName: */ "table_xinfo", /* ePragTyp: */ PragTyp_TABLE_INFO, /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt, /* ColNames: */ 8, 7, /* iArg: */ 1 }, @@ -130948,15 +129400,11 @@ goto pragma_out; } /* Locate the pragma in the lookup table */ pPragma = pragmaLocate(zLeft); - if( pPragma==0 ){ - /* IMP: R-43042-22504 No error messages are generated if an - ** unknown pragma is issued. */ - goto pragma_out; - } + if( pPragma==0 ) goto pragma_out; /* Make sure the database schema is loaded if the pragma requires that */ if( (pPragma->mPragFlg & PragFlg_NeedSchema)!=0 ){ if( sqlite3ReadSchema(pParse) ) goto pragma_out; } @@ -131602,18 +130050,10 @@ if( sqlite3GetBoolean(zRight, 0) ){ db->flags |= mask; }else{ db->flags &= ~mask; if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0; - if( (mask & SQLITE_WriteSchema)!=0 - && sqlite3_stricmp(zRight, "reset")==0 - ){ - /* IMP: R-60817-01178 If the argument is "RESET" then schema - ** writing is disabled (as with "PRAGMA writable_schema=OFF") and, - ** in addition, the schema is reloaded. */ - sqlite3ResetAllSchemasOfConnection(db); - } } /* Many of the flag-pragmas modify the code generated by the SQL ** compiler (eg. count_changes). So add an opcode to expire all ** compiled SQL statements after modifying a pragma value. @@ -131650,11 +130090,10 @@ Index *pPk = sqlite3PrimaryKeyIndex(pTab); pParse->nMem = 7; sqlite3ViewGetColumnNames(pParse, pTab); for(i=0, pCol=pTab->aCol; inCol; i++, pCol++){ int isHidden = 0; - const Expr *pColExpr; if( pCol->colFlags & COLFLAG_NOINSERT ){ if( pPragma->iArg==0 ){ nHidden++; continue; } @@ -131671,20 +130110,20 @@ }else if( pPk==0 ){ k = 1; }else{ for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){} } - pColExpr = sqlite3ColumnExpr(pTab,pCol); - assert( pColExpr==0 || pColExpr->op==TK_SPAN || isHidden>=2 ); - assert( pColExpr==0 || !ExprHasProperty(pColExpr, EP_IntValue) - || isHidden>=2 ); + assert( sqlite3ColumnExpr(pTab,pCol)==0 + || sqlite3ColumnExpr(pTab,pCol)->op==TK_SPAN + || isHidden>=2 ); sqlite3VdbeMultiLoad(v, 1, pPragma->iArg ? "issisii" : "issisi", i-nHidden, pCol->zCnName, sqlite3ColumnType(pCol,""), pCol->notNull ? 1 : 0, - (isHidden>=2 || pColExpr==0) ? 0 : pColExpr->u.zToken, + isHidden>=2 || sqlite3ColumnExpr(pTab,pCol)==0 ? 0 : + sqlite3ColumnExpr(pTab,pCol)->u.zToken, k, isHidden); } } } @@ -131708,43 +130147,12 @@ pParse->nMem = 6; sqlite3CodeVerifyNamedSchema(pParse, zDb); for(ii=0; iinDb; ii++){ HashElem *k; Hash *pHash; - int initNCol; if( zDb && sqlite3_stricmp(zDb, db->aDb[ii].zDbSName)!=0 ) continue; - - /* Ensure that the Table.nCol field is initialized for all views - ** and virtual tables. Each time we initialize a Table.nCol value - ** for a table, that can potentially disrupt the hash table, so restart - ** the initialization scan. - */ - pHash = &db->aDb[ii].pSchema->tblHash; - initNCol = sqliteHashCount(pHash); - while( initNCol-- ){ - for(k=sqliteHashFirst(pHash); 1; k=sqliteHashNext(k) ){ - Table *pTab; - if( k==0 ){ initNCol = 0; break; } - pTab = sqliteHashData(k); - if( pTab->nCol==0 ){ - char *zSql = sqlite3MPrintf(db, "SELECT*FROM\"%w\"", pTab->zName); - if( zSql ){ - sqlite3_stmt *pDummy = 0; - (void)sqlite3_prepare(db, zSql, -1, &pDummy, 0); - (void)sqlite3_finalize(pDummy); - sqlite3DbFree(db, zSql); - } - if( db->mallocFailed ){ - sqlite3ErrorMsg(db->pParse, "out of memory"); - db->pParse->rc = SQLITE_NOMEM_BKPT; - } - pHash = &db->aDb[ii].pSchema->tblHash; - break; - } - } - } - + pHash = &db->aDb[ii].pSchema->tblHash; for(k=sqliteHashFirst(pHash); k; k=sqliteHashNext(k) ){ Table *pTab = sqliteHashData(k); const char *zType; if( zRight && sqlite3_stricmp(zRight, pTab->zName)!=0 ) continue; if( IsView(pTab) ){ @@ -131756,11 +130164,11 @@ }else{ zType = "table"; } sqlite3VdbeMultiLoad(v, 1, "sssiii", db->aDb[ii].zDbSName, - sqlite3PreferredTableName(pTab->zName), + pTab->zName, zType, pTab->nCol, (pTab->tabFlags & TF_WithoutRowid)!=0, (pTab->tabFlags & TF_Strict)!=0 ); @@ -131776,11 +130184,11 @@ pParse->nMem = 5; sqlite3CodeVerifySchema(pParse, iDb); for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){ Table *pTab = sqliteHashData(i); sqlite3VdbeMultiLoad(v, 1, "ssiii", - sqlite3PreferredTableName(pTab->zName), + pTab->zName, 0, pTab->szTabRow, pTab->nRowLogEst, pTab->tabFlags); for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ @@ -131895,17 +130303,15 @@ FuncDef *p; int showInternFunc = (db->mDbFlags & DBFLAG_InternalFunc)!=0; pParse->nMem = 6; for(i=0; iu.pHash ){ - assert( p->funcFlags & SQLITE_FUNC_BUILTIN ); pragmaFunclistLine(v, p, 1, showInternFunc); } } for(j=sqliteHashFirst(&db->aFunc); j; j=sqliteHashNext(j)){ p = (FuncDef*)sqliteHashData(j); - assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 ); pragmaFunclistLine(v, p, 0, showInternFunc); } } break; @@ -131935,11 +130341,11 @@ #ifndef SQLITE_OMIT_FOREIGN_KEY case PragTyp_FOREIGN_KEY_LIST: if( zRight ){ FKey *pFK; Table *pTab; pTab = sqlite3FindTable(db, zRight, zDb); - if( pTab && IsOrdinaryTable(pTab) ){ + if( pTab && !IsVirtual(pTab) ){ pFK = pTab->u.tab.pFKey; if( pFK ){ int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema); int i = 0; pParse->nMem = 8; @@ -131995,19 +130401,19 @@ k = 0; }else{ pTab = (Table*)sqliteHashData(k); k = sqliteHashNext(k); } - if( pTab==0 || !IsOrdinaryTable(pTab) || pTab->u.tab.pFKey==0 ) continue; + if( pTab==0 || IsVirtual(pTab) || pTab->u.tab.pFKey==0 ) continue; iDb = sqlite3SchemaToIndex(db, pTab->pSchema); zDb = db->aDb[iDb].zDbSName; sqlite3CodeVerifySchema(pParse, iDb); sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow; sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead); sqlite3VdbeLoadString(v, regResult, pTab->zName); - assert( IsOrdinaryTable(pTab) ); + assert( !IsVirtual(pTab) ); for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){ pParent = sqlite3FindTable(db, pFK->zTo, zDb); if( pParent==0 ) continue; pIdx = 0; sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName); @@ -132026,11 +130432,11 @@ } assert( pParse->nErr>0 || pFK==0 ); if( pFK ) break; if( pParse->nTabnTab = i; addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v); - assert( IsOrdinaryTable(pTab) ); + assert( !IsVirtual(pTab) ); for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){ pParent = sqlite3FindTable(db, pFK->zTo, zDb); pIdx = 0; aiCols = 0; if( pParent ){ @@ -132230,11 +130636,11 @@ int loopTop; int iDataCur, iIdxCur; int r1 = -1; int bStrict; - if( !IsOrdinaryTable(pTab) ) continue; + if( pTab->tnum<1 ) continue; /* Skip VIEWs or VIRTUAL TABLEs */ if( pObjTab && pObjTab!=pTab ) continue; pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab); sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0, 1, 0, &iDataCur, &iIdxCur); /* reg[7] counts the number of entries in the table. @@ -132271,11 +130677,11 @@ if( pCol->notNull ){ jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v); zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName, pCol->zCnName); sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); - if( bStrict && pCol->eCType!=COLTYPE_ANY ){ + if( bStrict ){ sqlite3VdbeGoto(v, doError); }else{ integrityCheckResultRow(v); } sqlite3VdbeJumpHere(v, jmp2); @@ -132825,16 +131231,16 @@ ** in each index that it looks at. Return the new limit. */ case PragTyp_ANALYSIS_LIMIT: { sqlite3_int64 N; if( zRight - && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK /* IMP: R-40975-20399 */ + && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK && N>=0 ){ db->nAnalysisLimit = (int)(N&0x7fffffff); } - returnSingleInt(v, db->nAnalysisLimit); /* IMP: R-57594-65522 */ + returnSingleInt(v, db->nAnalysisLimit); break; } #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) /* @@ -133232,19 +131638,14 @@ sqlite3 *db = pData->db; if( db->mallocFailed ){ pData->rc = SQLITE_NOMEM_BKPT; }else if( pData->pzErrMsg[0]!=0 ){ /* A error message has already been generated. Do not overwrite it */ - }else if( pData->mInitFlags & (INITFLAG_AlterMask) ){ - static const char *azAlterType[] = { - "rename", - "drop column", - "add column" - }; + }else if( pData->mInitFlags & (INITFLAG_AlterRename|INITFLAG_AlterDrop) ){ *pData->pzErrMsg = sqlite3MPrintf(db, "error in %s %s after %s: %s", azObj[0], azObj[1], - azAlterType[(pData->mInitFlags&INITFLAG_AlterMask)-1], + (pData->mInitFlags & INITFLAG_AlterRename) ? "rename" : "drop column", zExtra ); pData->rc = SQLITE_ERROR; }else if( db->flags & SQLITE_WriteSchema ){ pData->rc = SQLITE_CORRUPT_BKPT; @@ -133592,11 +131993,11 @@ if( db->mallocFailed ){ rc = SQLITE_NOMEM_BKPT; sqlite3ResetAllSchemasOfConnection(db); pDb = &db->aDb[iDb]; }else - if( rc==SQLITE_OK || ((db->flags&SQLITE_NoSchemaError) && rc!=SQLITE_NOMEM)){ + if( rc==SQLITE_OK || (db->flags&SQLITE_NoSchemaError)){ /* Hack: If the SQLITE_NoSchemaError flag is set, then consider ** the schema loaded, even if errors (other than OOM) occurred. In ** this situation the current sqlite3_prepare() operation will fail, ** but the following one will attempt to compile the supplied statement ** against whatever subset of the schema was loaded before the error @@ -133771,18 +132172,12 @@ } /* ** Free all memory allocations in the pParse object */ -SQLITE_PRIVATE void sqlite3ParseObjectReset(Parse *pParse){ +SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){ sqlite3 *db = pParse->db; - assert( db!=0 ); - assert( db->pParse==pParse ); - assert( pParse->nested==0 ); -#ifndef SQLITE_OMIT_SHARED_CACHE - sqlite3DbFree(db, pParse->aTableLock); -#endif while( pParse->pCleanup ){ ParseCleanup *pCleanup = pParse->pCleanup; pParse->pCleanup = pCleanup->pNext; pCleanup->xCleanup(db, pCleanup->pPtr); sqlite3DbFreeNN(db, pCleanup); @@ -133789,16 +132184,15 @@ } sqlite3DbFree(db, pParse->aLabel); if( pParse->pConstExpr ){ sqlite3ExprListDelete(db, pParse->pConstExpr); } - assert( db->lookaside.bDisable >= pParse->disableLookaside ); - db->lookaside.bDisable -= pParse->disableLookaside; - db->lookaside.sz = db->lookaside.bDisable ? 0 : db->lookaside.szTrue; - assert( pParse->db->pParse==pParse ); - db->pParse = pParse->pOuterParse; - pParse->db = 0; + if( db ){ + assert( db->lookaside.bDisable >= pParse->disableLookaside ); + db->lookaside.bDisable -= pParse->disableLookaside; + db->lookaside.sz = db->lookaside.bDisable ? 0 : db->lookaside.szTrue; + } pParse->disableLookaside = 0; } /* ** Add a new cleanup operation to a Parser. The cleanup should happen when @@ -133807,11 +132201,11 @@ ** ** Use this mechanism for uncommon cleanups. There is a higher setup ** cost for this mechansim (an extra malloc), so it should not be used ** for common cleanups that happen on most calls. But for less ** common cleanups, we save a single NULL-pointer comparison in -** sqlite3ParseObjectReset(), which reduces the total CPU cycle count. +** sqlite3ParserReset(), which reduces the total CPU cycle count. ** ** If a memory allocation error occurs, then the cleanup happens immediately. ** When either SQLITE_DEBUG or SQLITE_COVERAGE_TEST are defined, the ** pParse->earlyCleanup flag is set in that case. Calling code show verify ** that test cases exist for which this happens, to guard against possible @@ -133847,37 +132241,10 @@ #endif } return pPtr; } -/* -** Turn bulk memory into a valid Parse object and link that Parse object -** into database connection db. -** -** Call sqlite3ParseObjectReset() to undo this operation. -** -** Caution: Do not confuse this routine with sqlite3ParseObjectInit() which -** is generated by Lemon. -*/ -SQLITE_PRIVATE void sqlite3ParseObjectInit(Parse *pParse, sqlite3 *db){ - memset(PARSE_HDR(pParse), 0, PARSE_HDR_SZ); - memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ); - assert( db->pParse!=pParse ); - pParse->pOuterParse = db->pParse; - db->pParse = pParse; - pParse->db = db; - if( db->mallocFailed ) sqlite3ErrorMsg(pParse, "out of memory"); -} - -/* -** Maximum number of times that we will try again to prepare a statement -** that returns SQLITE_ERROR_RETRY. -*/ -#ifndef SQLITE_MAX_PREPARE_RETRY -# define SQLITE_MAX_PREPARE_RETRY 25 -#endif - /* ** Compile the UTF-8 encoded SQL statement zSql into a statement handle. */ static int sqlite3Prepare( sqlite3 *db, /* Database handle. */ @@ -133886,23 +132253,20 @@ u32 prepFlags, /* Zero or more SQLITE_PREPARE_* flags */ Vdbe *pReprepare, /* VM being reprepared */ sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ const char **pzTail /* OUT: End of parsed string */ ){ + char *zErrMsg = 0; /* Error message */ int rc = SQLITE_OK; /* Result code */ int i; /* Loop counter */ Parse sParse; /* Parsing context */ - /* sqlite3ParseObjectInit(&sParse, db); // inlined for performance */ - memset(PARSE_HDR(&sParse), 0, PARSE_HDR_SZ); + memset(&sParse, 0, PARSE_HDR_SZ); memset(PARSE_TAIL(&sParse), 0, PARSE_TAIL_SZ); - sParse.pOuterParse = db->pParse; - db->pParse = &sParse; - sParse.db = db; sParse.pReprepare = pReprepare; assert( ppStmt && *ppStmt==0 ); - if( db->mallocFailed ) sqlite3ErrorMsg(&sParse, "out of memory"); + /* assert( !db->mallocFailed ); // not true with SQLITE_USE_ALLOCA */ assert( sqlite3_mutex_held(db->mutex) ); /* For a long-term use prepared statement avoid the use of ** lookaside memory. */ @@ -133951,10 +132315,11 @@ } } sqlite3VtabUnlockList(db); + sParse.db = db; if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){ char *zSqlCopy; int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH]; testcase( nBytes==mxLen ); testcase( nBytes==mxLen+1 ); @@ -133963,18 +132328,18 @@ rc = sqlite3ApiExit(db, SQLITE_TOOBIG); goto end_prepare; } zSqlCopy = sqlite3DbStrNDup(db, zSql, nBytes); if( zSqlCopy ){ - sqlite3RunParser(&sParse, zSqlCopy); + sqlite3RunParser(&sParse, zSqlCopy, &zErrMsg); sParse.zTail = &zSql[sParse.zTail-zSqlCopy]; sqlite3DbFree(db, zSqlCopy); }else{ sParse.zTail = &zSql[nBytes]; } }else{ - sqlite3RunParser(&sParse, zSql); + sqlite3RunParser(&sParse, zSql, &zErrMsg); } assert( 0==sParse.nQueryLoop ); if( pzTail ){ *pzTail = sParse.zTail; @@ -133986,26 +132351,26 @@ if( db->mallocFailed ){ sParse.rc = SQLITE_NOMEM_BKPT; sParse.checkSchema = 0; } if( sParse.rc!=SQLITE_OK && sParse.rc!=SQLITE_DONE ){ - if( sParse.checkSchema && db->init.busy==0 ){ + if( sParse.checkSchema ){ schemaIsValid(&sParse); } if( sParse.pVdbe ){ sqlite3VdbeFinalize(sParse.pVdbe); } assert( 0==(*ppStmt) ); rc = sParse.rc; - if( sParse.zErrMsg ){ - sqlite3ErrorWithMsg(db, rc, "%s", sParse.zErrMsg); - sqlite3DbFree(db, sParse.zErrMsg); + if( zErrMsg ){ + sqlite3ErrorWithMsg(db, rc, "%s", zErrMsg); + sqlite3DbFree(db, zErrMsg); }else{ sqlite3Error(db, rc); } }else{ - assert( sParse.zErrMsg==0 ); + assert( zErrMsg==0 ); *ppStmt = (sqlite3_stmt*)sParse.pVdbe; rc = SQLITE_OK; sqlite3ErrorClear(db); } @@ -134017,11 +132382,11 @@ sqlite3DbFree(db, pT); } end_prepare: - sqlite3ParseObjectReset(&sParse); + sqlite3ParserReset(&sParse); return rc; } static int sqlite3LockAndPrepare( sqlite3 *db, /* Database handle. */ const char *zSql, /* UTF-8 encoded SQL statement. */ @@ -134047,12 +132412,11 @@ /* Make multiple attempts to compile the SQL, until it either succeeds ** or encounters a permanent error. A schema problem after one schema ** reset is considered a permanent error. */ rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail); assert( rc==SQLITE_OK || *ppStmt==0 ); - if( rc==SQLITE_OK || db->mallocFailed ) break; - }while( (rc==SQLITE_ERROR_RETRY && (cnt++)errMask)==rc ); db->busyHandler.nBusy = 0; @@ -134622,29 +132986,29 @@ ** sqlite3PExpr(). */ if( pEq && isOuterJoin ){ ExprSetProperty(pEq, EP_FromJoin); assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) ); ExprSetVVAProperty(pEq, EP_NoReduce); - pEq->w.iRightJoinTable = pE2->iTable; + pEq->iRightJoinTable = pE2->iTable; } *ppWhere = sqlite3ExprAnd(pParse, *ppWhere, pEq); } /* ** Set the EP_FromJoin property on all terms of the given expression. -** And set the Expr.w.iRightJoinTable to iTable for every term in the +** And set the Expr.iRightJoinTable to iTable for every term in the ** expression. ** ** The EP_FromJoin property is used on terms of an expression to tell ** the LEFT OUTER JOIN processing logic that this term is part of the ** join restriction specified in the ON or USING clause and not a part ** of the more general WHERE clause. These terms are moved over to the ** WHERE clause during join processing but we need to remember that they ** originated in the ON or USING clause. ** -** The Expr.w.iRightJoinTable tells the WHERE clause processing that the -** expression depends on table w.iRightJoinTable even if that table is not +** The Expr.iRightJoinTable tells the WHERE clause processing that the +** expression depends on table iRightJoinTable even if that table is not ** explicitly mentioned in the expression. That information is needed ** for cases like this: ** ** SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.b AND t1.x=5 ** @@ -134658,47 +133022,41 @@ SQLITE_PRIVATE void sqlite3SetJoinExpr(Expr *p, int iTable){ while( p ){ ExprSetProperty(p, EP_FromJoin); assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) ); ExprSetVVAProperty(p, EP_NoReduce); - p->w.iRightJoinTable = iTable; - if( p->op==TK_FUNCTION ){ - assert( ExprUseXList(p) ); - if( p->x.pList ){ - int i; - for(i=0; ix.pList->nExpr; i++){ - sqlite3SetJoinExpr(p->x.pList->a[i].pExpr, iTable); - } + p->iRightJoinTable = iTable; + if( p->op==TK_FUNCTION && p->x.pList ){ + int i; + for(i=0; ix.pList->nExpr; i++){ + sqlite3SetJoinExpr(p->x.pList->a[i].pExpr, iTable); } } sqlite3SetJoinExpr(p->pLeft, iTable); p = p->pRight; } } /* Undo the work of sqlite3SetJoinExpr(). In the expression p, convert every -** term that is marked with EP_FromJoin and w.iRightJoinTable==iTable into +** term that is marked with EP_FromJoin and iRightJoinTable==iTable into ** an ordinary term that omits the EP_FromJoin mark. ** ** This happens when a LEFT JOIN is simplified into an ordinary JOIN. */ static void unsetJoinExpr(Expr *p, int iTable){ while( p ){ if( ExprHasProperty(p, EP_FromJoin) - && (iTable<0 || p->w.iRightJoinTable==iTable) ){ + && (iTable<0 || p->iRightJoinTable==iTable) ){ ExprClearProperty(p, EP_FromJoin); } if( p->op==TK_COLUMN && p->iTable==iTable ){ ExprClearProperty(p, EP_CanBeNull); } - if( p->op==TK_FUNCTION ){ - assert( ExprUseXList(p) ); - if( p->x.pList ){ - int i; - for(i=0; ix.pList->nExpr; i++){ - unsetJoinExpr(p->x.pList->a[i].pExpr, iTable); - } + if( p->op==TK_FUNCTION && p->x.pList ){ + int i; + for(i=0; ix.pList->nExpr; i++){ + unsetJoinExpr(p->x.pList->a[i].pExpr, iTable); } } unsetJoinExpr(p->pLeft, iTable); p = p->pRight; } @@ -135209,17 +133567,13 @@ ExprList *pExtra = 0; for(i=0; inExpr; i++){ struct ExprList_item *pItem = &pEList->a[i]; if( pItem->u.x.iOrderByCol==0 ){ Expr *pExpr = pItem->pExpr; - Table *pTab; - if( pExpr->op==TK_COLUMN - && pExpr->iColumn>=0 - && ALWAYS( ExprUseYTab(pExpr) ) - && (pTab = pExpr->y.pTab)!=0 - && IsOrdinaryTable(pTab) - && (pTab->aCol[pExpr->iColumn].colFlags & COLFLAG_SORTERREF)!=0 + Table *pTab = pExpr->y.pTab; + if( pExpr->op==TK_COLUMN && pExpr->iColumn>=0 && pTab && !IsVirtual(pTab) + && (pTab->aCol[pExpr->iColumn].colFlags & COLFLAG_SORTERREF) ){ int j; for(j=0; jaDefer[j].iCsr==pExpr->iTable ) break; } @@ -135236,11 +133590,10 @@ } for(k=0; kiTable = pExpr->iTable; - assert( ExprUseYTab(pNew) ); pNew->y.pTab = pExpr->y.pTab; pNew->iColumn = pPk ? pPk->aiColumn[k] : -1; pExtra = sqlite3ExprListAppend(pParse, pExtra, pNew); } } @@ -135672,11 +134025,11 @@ p->enc = ENC(db); p->db = db; p->nRef = 1; memset(&p[1], 0, nExtra); }else{ - return (KeyInfo*)sqlite3OomFault(db); + sqlite3OomFault(db); } return p; } /* @@ -135843,13 +134196,10 @@ } #endif iTab = pSort->iECursor; if( eDest==SRT_Output || eDest==SRT_Coroutine || eDest==SRT_Mem ){ - if( eDest==SRT_Mem && p->iOffset ){ - sqlite3VdbeAddOp2(v, OP_Null, 0, pDest->iSdst); - } regRowid = 0; regRow = pDest->iSdst; }else{ regRowid = sqlite3GetTempReg(pParse); if( eDest==SRT_EphemTab || eDest==SRT_Table ){ @@ -136088,11 +134438,11 @@ ** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT ** branch below. */ break; } - assert( pTab && ExprUseYTab(pExpr) && pExpr->y.pTab==pTab ); + assert( pTab && pExpr->y.pTab==pTab ); if( pS ){ /* The "table" is actually a sub-select or a view in the FROM clause ** of the SELECT statement. Return the declaration type and origin ** data for the result-set column of the sub-select. */ @@ -136148,15 +134498,13 @@ /* The expression is a sub-select. Return the declaration type and ** origin info for the single column in the result set of the SELECT ** statement. */ NameContext sNC; - Select *pS; - Expr *p; - assert( ExprUseXSelect(pExpr) ); - pS = pExpr->x.pSelect; - p = pS->pEList->a[0].pExpr; + Select *pS = pExpr->x.pSelect; + Expr *p = pS->pEList->a[0].pExpr; + assert( ExprHasProperty(pExpr, EP_xIsSelect) ); sNC.pSrcList = pS->pSrc; sNC.pNext = pNC; sNC.pParse = pNC->pParse; zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol); break; @@ -136281,12 +134629,11 @@ for(i=0; inExpr; i++){ Expr *p = pEList->a[i].pExpr; assert( p!=0 ); assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */ - assert( p->op!=TK_COLUMN - || (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */ + assert( p->op!=TK_COLUMN || p->y.pTab!=0 ); /* Covering idx not yet coded */ if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){ /* An AS clause always takes first priority */ char *zName = pEList->a[i].zEName; sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT); }else if( srcName && p->op==TK_COLUMN ){ @@ -136378,14 +134725,11 @@ Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr); while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){ pColExpr = pColExpr->pRight; assert( pColExpr!=0 ); } - if( pColExpr->op==TK_COLUMN - && ALWAYS( ExprUseYTab(pColExpr) ) - && (pTab = pColExpr->y.pTab)!=0 - ){ + if( pColExpr->op==TK_COLUMN && (pTab = pColExpr->y.pTab)!=0 ){ /* For columns use the column name name */ int iCol = pColExpr->iColumn; if( iCol<0 ) iCol = pTab->iPKey; zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid"; }else if( pColExpr->op==TK_ID ){ @@ -136467,11 +134811,11 @@ memset(&sNC, 0, sizeof(sNC)); sNC.pSrcList = pSelect->pSrc; a = pSelect->pEList->a; for(i=0, pCol=pTab->aCol; inCol; i++, pCol++){ const char *zType; - i64 n, m; + int n, m; pTab->tabFlags |= (pCol->colFlags & COLFLAG_NOINSERT); p = a[i].pExpr; zType = columnType(&sNC, p, 0, 0, 0); /* pCol->szEst = ... // Column size est for SELECT tables never used */ pCol->affinity = sqlite3ExprAffinity(p); @@ -136480,13 +134824,10 @@ n = sqlite3Strlen30(pCol->zCnName); pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2); if( pCol->zCnName ){ memcpy(&pCol->zCnName[n+1], zType, m+1); pCol->colFlags |= COLFLAG_HASTYPE; - }else{ - testcase( pCol->colFlags & COLFLAG_HASTYPE ); - pCol->colFlags &= ~(COLFLAG_HASTYPE|COLFLAG_HASCOLL); } } if( pCol->affinity<=SQLITE_AFF_NONE ) pCol->affinity = aff; pColl = sqlite3ExprCollSeq(pParse, p); if( pColl ){ @@ -136653,11 +134994,11 @@ ** function is responsible for ensuring that this structure is eventually ** freed. */ static KeyInfo *multiSelectOrderByKeyInfo(Parse *pParse, Select *p, int nExtra){ ExprList *pOrderBy = p->pOrderBy; - int nOrderBy = ALWAYS(pOrderBy!=0) ? pOrderBy->nExpr : 0; + int nOrderBy = p->pOrderBy->nExpr; sqlite3 *db = pParse->db; KeyInfo *pRet = sqlite3KeyInfoAlloc(db, nOrderBy+nExtra, 1); if( pRet ){ int i; for(i=0; iaColl[] */ int nCol; /* Number of columns in result set */ assert( p->pNext==0 ); - assert( p->pEList!=0 ); nCol = p->pEList->nExpr; pKeyInfo = sqlite3KeyInfoAlloc(db, nCol, 1); if( !pKeyInfo ){ rc = SQLITE_NOMEM_BKPT; goto multi_select_end; @@ -137567,12 +135907,10 @@ Select *p, /* The right-most of SELECTs to be coded */ SelectDest *pDest /* What to do with query results */ ){ int i, j; /* Loop counters */ Select *pPrior; /* Another SELECT immediately to our left */ - Select *pSplit; /* Left-most SELECT in the right-hand group */ - int nSelect; /* Number of SELECT statements in the compound */ Vdbe *v; /* Generate code to this VDBE */ SelectDest destA; /* Destination for coroutine A */ SelectDest destB; /* Destination for coroutine B */ int regAddrA; /* Address register for select-A coroutine */ int regAddrB; /* Address register for select-B coroutine */ @@ -137614,11 +135952,12 @@ /* Patch up the ORDER BY clause */ op = p->op; - assert( p->pPrior->pOrderBy==0 ); + pPrior = p->pPrior; + assert( pPrior->pOrderBy==0 ); pOrderBy = p->pOrderBy; assert( pOrderBy ); nOrderBy = pOrderBy->nExpr; /* For operators other than UNION ALL we have to make sure that @@ -137627,11 +135966,10 @@ */ if( op!=TK_ALL ){ for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){ struct ExprList_item *pItem; for(j=0, pItem=pOrderBy->a; ju.x.iOrderByCol>0 ); if( pItem->u.x.iOrderByCol==i ) break; } if( j==nOrderBy ){ Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0); @@ -137654,20 +135992,24 @@ aPermute = sqlite3DbMallocRawNN(db, sizeof(u32)*(nOrderBy + 1)); if( aPermute ){ struct ExprList_item *pItem; aPermute[0] = nOrderBy; for(i=1, pItem=pOrderBy->a; i<=nOrderBy; i++, pItem++){ - assert( pItem!=0 ); assert( pItem->u.x.iOrderByCol>0 ); assert( pItem->u.x.iOrderByCol<=p->pEList->nExpr ); aPermute[i] = pItem->u.x.iOrderByCol - 1; } pKeyMerge = multiSelectOrderByKeyInfo(pParse, p, 1); }else{ pKeyMerge = 0; } + /* Reattach the ORDER BY clause to the query. + */ + p->pOrderBy = pOrderBy; + pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0); + /* Allocate a range of temporary registers and the KeyInfo needed ** for the logic that removes duplicate result rows when the ** operator is UNION, EXCEPT, or INTERSECT (but not UNION ALL). */ if( op==TK_ALL ){ @@ -137688,34 +136030,16 @@ } } /* Separate the left and the right query from one another */ - nSelect = 1; - if( (op==TK_ALL || op==TK_UNION) - && OptimizationEnabled(db, SQLITE_BalancedMerge) - ){ - for(pSplit=p; pSplit->pPrior!=0 && pSplit->op==op; pSplit=pSplit->pPrior){ - nSelect++; - assert( pSplit->pPrior->pNext==pSplit ); - } - } - if( nSelect<=3 ){ - pSplit = p; - }else{ - pSplit = p; - for(i=2; ipPrior; } - } - pPrior = pSplit->pPrior; - assert( pPrior!=0 ); - pSplit->pPrior = 0; + p->pPrior = 0; pPrior->pNext = 0; - assert( p->pOrderBy == pOrderBy ); - assert( pOrderBy!=0 || db->mallocFailed ); - pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0); sqlite3ResolveOrderGroupBy(pParse, p, p->pOrderBy, "ORDER"); - sqlite3ResolveOrderGroupBy(pParse, pPrior, pPrior->pOrderBy, "ORDER"); + if( pPrior->pPrior==0 ){ + sqlite3ResolveOrderGroupBy(pParse, pPrior, pPrior->pOrderBy, "ORDER"); + } /* Compute the limit registers */ computeLimitRegisters(pParse, p, labelEnd); if( p->iLimit && op==TK_ALL ){ regLimitA = ++pParse->nMem; @@ -137862,15 +136186,16 @@ */ sqlite3VdbeResolveLabel(v, labelEnd); /* Reassembly the compound query so that it will be freed correctly ** by the calling function */ - if( pSplit->pPrior ){ - sqlite3SelectDelete(db, pSplit->pPrior); + if( p->pPrior ){ + sqlite3SelectDelete(db, p->pPrior); } - pSplit->pPrior = pPrior; - pPrior->pNext = pSplit; + p->pPrior = pPrior; + pPrior->pNext = p; + sqlite3ExprListDelete(db, pPrior->pOrderBy); pPrior->pOrderBy = 0; /*** TBD: Insert subroutine calls to close cursors on incomplete **** subqueries ****/ @@ -137916,13 +136241,13 @@ SubstContext *pSubst, /* Description of the substitution */ Expr *pExpr /* Expr in which substitution occurs */ ){ if( pExpr==0 ) return 0; if( ExprHasProperty(pExpr, EP_FromJoin) - && pExpr->w.iRightJoinTable==pSubst->iTable + && pExpr->iRightJoinTable==pSubst->iTable ){ - pExpr->w.iRightJoinTable = pSubst->iNewTable; + pExpr->iRightJoinTable = pSubst->iNewTable; } if( pExpr->op==TK_COLUMN && pExpr->iTable==pSubst->iTable && !ExprHasProperty(pExpr, EP_FixedCol) ){ @@ -137957,11 +136282,11 @@ } if( pSubst->isLeftJoin ){ ExprSetProperty(pNew, EP_CanBeNull); } if( ExprHasProperty(pExpr,EP_FromJoin) ){ - sqlite3SetJoinExpr(pNew, pExpr->w.iRightJoinTable); + sqlite3SetJoinExpr(pNew, pExpr->iRightJoinTable); } sqlite3ExprDelete(db, pExpr); pExpr = pNew; /* Ensure that the expression now has an implicit collation sequence, @@ -137979,11 +136304,11 @@ if( pExpr->op==TK_IF_NULL_ROW && pExpr->iTable==pSubst->iTable ){ pExpr->iTable = pSubst->iNewTable; } pExpr->pLeft = substExpr(pSubst, pExpr->pLeft); pExpr->pRight = substExpr(pSubst, pExpr->pRight); - if( ExprUseXSelect(pExpr) ){ + if( ExprHasProperty(pExpr, EP_xIsSelect) ){ substSelect(pSubst, pExpr->x.pSelect, 1); }else{ substExprList(pSubst, pExpr->x.pList); } #ifndef SQLITE_OMIT_WINDOWFUNC @@ -138122,11 +136447,11 @@ int op = pExpr->op; if( op==TK_COLUMN || op==TK_IF_NULL_ROW ){ renumberCursorDoMapping(pWalker, &pExpr->iTable); } if( ExprHasProperty(pExpr, EP_FromJoin) ){ - renumberCursorDoMapping(pWalker, &pExpr->w.iRightJoinTable); + renumberCursorDoMapping(pWalker, &pExpr->iRightJoinTable); } return WRC_Continue; } /* @@ -138466,11 +136791,11 @@ /* Restriction (23) */ if( (p->selFlags & SF_Recursive) ) return 0; if( pSrc->nSrc>1 ){ if( pParse->nSelect>500 ) return 0; - aCsrMap = sqlite3DbMallocZero(db, ((i64)pParse->nTab+1)*sizeof(int)); + aCsrMap = sqlite3DbMallocZero(db, (pParse->nTab+1)*sizeof(int)); if( aCsrMap ) aCsrMap[0] = pParse->nTab; } } /***** If we reach this point, flattening is permitted. *****/ @@ -139090,11 +137415,12 @@ */ static int pushDownWhereTerms( Parse *pParse, /* Parse context (for malloc() and error reporting) */ Select *pSubq, /* The subquery whose WHERE clause is to be augmented */ Expr *pWhere, /* The WHERE clause of the outer query */ - SrcItem *pSrc /* The subquery term of the outer FROM clause */ + int iCursor, /* Cursor number of the subquery */ + int isLeftJoin /* True if pSubq is the right term of a LEFT JOIN */ ){ Expr *pNew; int nChng = 0; if( pWhere==0 ) return 0; if( pSubq->selFlags & (SF_Recursive|SF_MultiPart) ) return 0; @@ -139125,38 +137451,33 @@ if( pSubq->pLimit!=0 ){ return 0; /* restriction (3) */ } while( pWhere->op==TK_AND ){ - nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, pSrc); + nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, + iCursor, isLeftJoin); pWhere = pWhere->pLeft; } - -#if 0 /* Legacy code. Checks now done by sqlite3ExprIsTableConstraint() */ if( isLeftJoin && (ExprHasProperty(pWhere,EP_FromJoin)==0 - || pWhere->w.iRightJoinTable!=iCursor) + || pWhere->iRightJoinTable!=iCursor) ){ return 0; /* restriction (4) */ } - if( ExprHasProperty(pWhere,EP_FromJoin) - && pWhere->w.iRightJoinTable!=iCursor - ){ + if( ExprHasProperty(pWhere,EP_FromJoin) && pWhere->iRightJoinTable!=iCursor ){ return 0; /* restriction (5) */ } -#endif - - if( sqlite3ExprIsTableConstraint(pWhere, pSrc) ){ + if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){ nChng++; pSubq->selFlags |= SF_PushDown; while( pSubq ){ SubstContext x; pNew = sqlite3ExprDup(pParse->db, pWhere, 0); unsetJoinExpr(pNew, -1); x.pParse = pParse; - x.iTable = pSrc->iCursor; - x.iNewTable = pSrc->iCursor; + x.iTable = iCursor; + x.iNewTable = iCursor; x.isLeftJoin = 0; x.pEList = pSubq->pEList; pNew = substExpr(&x, pNew); #ifndef SQLITE_OMIT_WINDOWFUNC if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){ @@ -139194,28 +137515,25 @@ ** located but before their arguments have been subjected to aggregate ** analysis. */ static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){ int eRet = WHERE_ORDERBY_NORMAL; /* Return value */ - ExprList *pEList; /* Arguments to agg function */ + ExprList *pEList = pFunc->x.pList; /* Arguments to agg function */ const char *zFunc; /* Name of aggregate function pFunc */ ExprList *pOrderBy; u8 sortFlags = 0; assert( *ppMinMax==0 ); assert( pFunc->op==TK_AGG_FUNCTION ); assert( !IsWindowFunc(pFunc) ); - assert( ExprUseXList(pFunc) ); - pEList = pFunc->x.pList; if( pEList==0 || pEList->nExpr!=1 || ExprHasProperty(pFunc, EP_WinFunc) || OptimizationDisabled(db, SQLITE_MinMaxOpt) ){ return eRet; } - assert( !ExprHasProperty(pFunc, EP_IntValue) ); zFunc = pFunc->u.zToken; if( sqlite3StrICmp(zFunc, "min")==0 ){ eRet = WHERE_ORDERBY_MIN; if( sqlite3ExprCanBeNull(pEList->a[0].pExpr) ){ sortFlags = KEYINFO_ORDER_BIGNULL; @@ -139239,44 +137557,31 @@ ** ** SELECT count(*) FROM ** ** where table is a database table, not a sub-select or view. If the query ** does match this pattern, then a pointer to the Table object representing -** is returned. Otherwise, NULL is returned. -** -** This routine checks to see if it is safe to use the count optimization. -** A correct answer is still obtained (though perhaps more slowly) if -** this routine returns NULL when it could have returned a table pointer. -** But returning the pointer when NULL should have been returned can -** result in incorrect answers and/or crashes. So, when in doubt, return NULL. +** is returned. Otherwise, 0 is returned. */ static Table *isSimpleCount(Select *p, AggInfo *pAggInfo){ Table *pTab; Expr *pExpr; assert( !p->pGroupBy ); - if( p->pWhere - || p->pEList->nExpr!=1 - || p->pSrc->nSrc!=1 - || p->pSrc->a[0].pSelect - || pAggInfo->nFunc!=1 + if( p->pWhere || p->pEList->nExpr!=1 + || p->pSrc->nSrc!=1 || p->pSrc->a[0].pSelect ){ return 0; } pTab = p->pSrc->a[0].pTab; - assert( pTab!=0 ); - assert( !IsView(pTab) ); - if( !IsOrdinaryTable(pTab) ) return 0; pExpr = p->pEList->a[0].pExpr; - assert( pExpr!=0 ); + assert( pTab && !IsView(pTab) && pExpr ); + + if( IsVirtual(pTab) ) return 0; if( pExpr->op!=TK_AGG_FUNCTION ) return 0; - if( pExpr->pAggInfo!=pAggInfo ) return 0; + if( NEVER(pAggInfo->nFunc==0) ) return 0; if( (pAggInfo->aFunc[0].pFunc->funcFlags&SQLITE_FUNC_COUNT)==0 ) return 0; - assert( pAggInfo->aFunc[0].pFExpr==pExpr ); - testcase( ExprHasProperty(pExpr, EP_Distinct) ); - testcase( ExprHasProperty(pExpr, EP_WinFunc) ); if( ExprHasProperty(pExpr, EP_Distinct|EP_WinFunc) ) return 0; return pTab; } @@ -139301,11 +137606,10 @@ if( !pIdx ){ sqlite3ErrorMsg(pParse, "no such index: %s", zIndexedBy, 0); pParse->checkSchema = 1; return SQLITE_ERROR; } - assert( pFrom->fg.isCte==0 ); pFrom->u2.pIBIndex = pIdx; return SQLITE_OK; } /* @@ -139559,14 +137863,10 @@ pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid; pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0); if( db->mallocFailed ) return 2; pFrom->pSelect->selFlags |= SF_CopyCte; assert( pFrom->pSelect ); - if( pFrom->fg.isIndexedBy ){ - sqlite3ErrorMsg(pParse, "no such index: \"%s\"", pFrom->u1.zIndexedBy); - return 2; - } pFrom->fg.isCte = 1; pFrom->u2.pCteUse = pCteUse; pCteUse->nUse++; if( pCteUse->nUse>=2 && pCteUse->eM10d==M10d_Any ){ pCteUse->eM10d = M10d_Yes; @@ -139860,12 +138160,11 @@ } } /* Process NATURAL keywords, and ON and USING clauses of joins. */ - assert( db->mallocFailed==0 || pParse->nErr!=0 ); - if( pParse->nErr || sqliteProcessJoin(pParse, p) ){ + if( pParse->nErr || db->mallocFailed || sqliteProcessJoin(pParse, p) ){ return WRC_Abort; } /* For every "*" that occurs in the column list, insert the names of ** all columns in all tables. And for every TABLE.* insert the names @@ -140158,17 +138457,16 @@ Parse *pParse, /* The parser context */ Select *p, /* The SELECT statement being coded. */ NameContext *pOuterNC /* Name context for container */ ){ assert( p!=0 || pParse->db->mallocFailed ); - assert( pParse->db->pParse==pParse ); if( pParse->db->mallocFailed ) return; if( p->selFlags & SF_HasTypeInfo ) return; sqlite3SelectExpand(pParse, p); - if( pParse->nErr ) return; + if( pParse->nErr || pParse->db->mallocFailed ) return; sqlite3ResolveSelectNames(pParse, p, pOuterNC); - if( pParse->nErr ) return; + if( pParse->nErr || pParse->db->mallocFailed ) return; sqlite3SelectAddTypeInfo(pParse, p); } /* ** Reset the aggregate accumulator. @@ -140181,14 +138479,12 @@ static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){ Vdbe *v = pParse->pVdbe; int i; struct AggInfo_func *pFunc; int nReg = pAggInfo->nFunc + pAggInfo->nColumn; - assert( pParse->db->pParse==pParse ); - assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 ); if( nReg==0 ) return; - if( pParse->nErr ) return; + if( pParse->nErr || pParse->db->mallocFailed ) return; #ifdef SQLITE_DEBUG /* Verify that all AggInfo registers are within the range specified by ** AggInfo.mnReg..AggInfo.mxReg */ assert( nReg==pAggInfo->mxReg-pAggInfo->mnReg+1 ); for(i=0; inColumn; i++){ @@ -140202,11 +138498,11 @@ #endif sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->mnReg, pAggInfo->mxReg); for(pFunc=pAggInfo->aFunc, i=0; inFunc; i++, pFunc++){ if( pFunc->iDistinct>=0 ){ Expr *pE = pFunc->pFExpr; - assert( ExprUseXList(pE) ); + assert( !ExprHasProperty(pE, EP_xIsSelect) ); if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){ sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one " "argument"); pFunc->iDistinct = -1; }else{ @@ -140227,13 +138523,12 @@ static void finalizeAggFunctions(Parse *pParse, AggInfo *pAggInfo){ Vdbe *v = pParse->pVdbe; int i; struct AggInfo_func *pF; for(i=0, pF=pAggInfo->aFunc; inFunc; i++, pF++){ - ExprList *pList; - assert( ExprUseXList(pF->pFExpr) ); - pList = pF->pFExpr->x.pList; + ExprList *pList = pF->pFExpr->x.pList; + assert( !ExprHasProperty(pF->pFExpr, EP_xIsSelect) ); sqlite3VdbeAddOp2(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0); sqlite3VdbeAppendP4(v, pF->pFunc, P4_FUNCDEF); } } @@ -140263,14 +138558,13 @@ pAggInfo->directMode = 1; for(i=0, pF=pAggInfo->aFunc; inFunc; i++, pF++){ int nArg; int addrNext = 0; int regAgg; - ExprList *pList; - assert( ExprUseXList(pF->pFExpr) ); + ExprList *pList = pF->pFExpr->x.pList; + assert( !ExprHasProperty(pF->pFExpr, EP_xIsSelect) ); assert( !IsWindowFunc(pF->pFExpr) ); - pList = pF->pFExpr->x.pList; if( ExprHasProperty(pF->pFExpr, EP_WinFunc) ){ Expr *pFilter = pF->pFExpr->y.pWin->pFilter; if( pAggInfo->nAccumulator && (pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL) && regAcc @@ -140512,13 +138806,11 @@ if( p->pEList->nExpr!=1 ) return 0; /* Single result column */ if( p->pWhere ) return 0; if( p->pGroupBy ) return 0; pExpr = p->pEList->a[0].pExpr; if( pExpr->op!=TK_AGG_FUNCTION ) return 0; /* Result is an aggregate */ - assert( ExprUseUToken(pExpr) ); if( sqlite3_stricmp(pExpr->u.zToken,"count") ) return 0; /* Is count() */ - assert( ExprUseXList(pExpr) ); if( pExpr->x.pList!=0 ) return 0; /* Must be count(*) */ if( p->pSrc->nSrc!=1 ) return 0; /* One table in FROM */ pSub = p->pSrc->a[0].pSelect; if( pSub==0 ) return 0; /* The FROM is a subquery */ if( pSub->pPrior==0 ) return 0; /* Must be a compound ry */ @@ -140607,16 +138899,14 @@ sqlite3 *db; /* The database connection */ ExprList *pMinMaxOrderBy = 0; /* Added ORDER BY for min/max queries */ u8 minMaxFlag; /* Flag for min/max queries */ db = pParse->db; - assert( pParse==db->pParse ); v = sqlite3GetVdbe(pParse); - if( p==0 || pParse->nErr ){ + if( p==0 || db->mallocFailed || pParse->nErr ){ return 1; } - assert( db->mallocFailed==0 ); if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1; #if SELECTTRACE_ENABLED SELECTTRACE(1,pParse,p, ("begin processing:\n", pParse->addrExplain)); if( sqlite3SelectTrace & 0x100 ){ sqlite3TreeViewSelect(0, p, 0); @@ -140647,14 +138937,13 @@ } p->selFlags &= ~SF_Distinct; p->selFlags |= SF_NoopOrderBy; } sqlite3SelectPrep(pParse, p, 0); - if( pParse->nErr ){ + if( pParse->nErr || db->mallocFailed ){ goto select_end; } - assert( db->mallocFailed==0 ); assert( p->pEList!=0 ); #if SELECTTRACE_ENABLED if( sqlite3SelectTrace & 0x104 ){ SELECTTRACE(0x104,pParse,p, ("after name resolution:\n")); sqlite3TreeViewSelect(0, p, 0); @@ -140694,11 +138983,11 @@ sqlite3GenerateColumnNames(pParse, p); } #ifndef SQLITE_OMIT_WINDOWFUNC if( sqlite3WindowRewrite(pParse, p) ){ - assert( pParse->nErr ); + assert( db->mallocFailed || pParse->nErr>0 ); goto select_end; } #if SELECTTRACE_ENABLED if( p->pWin && (sqlite3SelectTrace & 0x108)!=0 ){ SELECTTRACE(0x104,pParse,p, ("after window rewrite:\n")); @@ -140934,11 +139223,12 @@ ** inside the subquery. This can help the subquery to run more efficiently. */ if( OptimizationEnabled(db, SQLITE_PushDown) && (pItem->fg.isCte==0 || (pItem->u2.pCteUse->eM10d!=M10d_Yes && pItem->u2.pCteUse->nUse<2)) - && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem) + && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor, + (pItem->fg.jointype & JT_OUTER)!=0) ){ #if SELECTTRACE_ENABLED if( sqlite3SelectTrace & 0x100 ){ SELECTTRACE(0x100,pParse,p, ("After WHERE-clause push-down into subquery %d:\n", pSub->selId)); @@ -141169,11 +139459,11 @@ /* Begin the database scan. */ SELECTTRACE(1,pParse,p,("WhereBegin\n")); pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, sSort.pOrderBy, - p->pEList, p, wctrlFlags, p->nSelectRow); + p->pEList, wctrlFlags, p->nSelectRow); if( pWInfo==0 ) goto select_end; if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){ p->nSelectRow = sqlite3WhereOutputRowCount(pWInfo); } if( sDistinct.isTnct && sqlite3WhereIsDistinct(pWInfo) ){ @@ -141331,11 +139621,11 @@ }else{ minMaxFlag = WHERE_ORDERBY_NORMAL; } for(i=0; inFunc; i++){ Expr *pExpr = pAggInfo->aFunc[i].pFExpr; - assert( ExprUseXList(pExpr) ); + assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); sNC.ncFlags |= NC_InAggFunc; sqlite3ExprAnalyzeAggList(&sNC, pExpr->x.pList); #ifndef SQLITE_OMIT_WINDOWFUNC assert( !IsWindowFunc(pExpr) ); if( ExprHasProperty(pExpr, EP_WinFunc) ){ @@ -141386,13 +139676,11 @@ u16 distFlag = 0; int eDist = WHERE_DISTINCT_NOOP; if( pAggInfo->nFunc==1 && pAggInfo->aFunc[0].iDistinct>=0 - && ALWAYS(pAggInfo->aFunc[0].pFExpr!=0) - && ALWAYS(ExprUseXList(pAggInfo->aFunc[0].pFExpr)) - && pAggInfo->aFunc[0].pFExpr->x.pList!=0 + && pAggInfo->aFunc[0].pFExpr->x.pList ){ Expr *pExpr = pAggInfo->aFunc[0].pFExpr->x.pList->a[0].pExpr; pExpr = sqlite3ExprDup(db, pExpr, 0); pDistinct = sqlite3ExprListDup(db, pGroupBy, 0); pDistinct = sqlite3ExprListAppend(pParse, pDistinct, pExpr); @@ -141433,11 +139721,11 @@ ** in the right order to begin with. */ sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset); SELECTTRACE(1,pParse,p,("WhereBegin\n")); pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct, - 0, (WHERE_GROUPBY|(orderByGrp ? WHERE_SORTBYGROUP : 0)|distFlag), 0 + WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0 ); if( pWInfo==0 ){ sqlite3ExprListDelete(db, pDistinct); goto select_end; } @@ -141709,11 +139997,10 @@ if( i==pAggInfo->nFunc ){ regAcc = ++pParse->nMem; sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc); } }else if( pAggInfo->nFunc==1 && pAggInfo->aFunc[0].iDistinct>=0 ){ - assert( ExprUseXList(pAggInfo->aFunc[0].pFExpr) ); pDistinct = pAggInfo->aFunc[0].pFExpr->x.pList; distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0; } /* This case runs if the aggregate has no GROUP BY clause. The @@ -141731,11 +140018,11 @@ assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 ); assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 ); SELECTTRACE(1,pParse,p,("WhereBegin\n")); pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy, - pDistinct, 0, minMaxFlag|distFlag, 0); + pDistinct, minMaxFlag|distFlag, 0); if( pWInfo==0 ){ goto select_end; } SELECTTRACE(1,pParse,p,("WhereBegin returns\n")); eDist = sqlite3WhereIsDistinct(pWInfo); @@ -141788,11 +140075,11 @@ /* Control jumps to here if an error is encountered above, or upon ** successful coding of the SELECT. */ select_end: assert( db->mallocFailed==0 || db->mallocFailed==1 ); - assert( db->mallocFailed==0 || pParse->nErr!=0 ); + pParse->nErr += db->mallocFailed; sqlite3ExprListDelete(db, pMinMaxOrderBy); #ifdef SQLITE_DEBUG if( pAggInfo && !db->mallocFailed ){ for(i=0; inColumn; i++){ Expr *pExpr = pAggInfo->aCol[i].pCExpr; @@ -142383,11 +140670,11 @@ if( v==0 ) goto triggerfinish_cleanup; sqlite3BeginWriteOperation(pParse, 0, iDb); z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n); testcase( z==0 ); sqlite3NestedParse(pParse, - "INSERT INTO %Q." LEGACY_SCHEMA_TABLE + "INSERT INTO %Q." DFLT_SCHEMA_TABLE " VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')", db->aDb[iDb].zDbSName, zName, pTrig->table, z); sqlite3DbFree(db, z); sqlite3ChangeCookie(pParse, iDb); @@ -142468,11 +140755,10 @@ const char *zEnd /* End of SQL text */ ){ sqlite3 *db = pParse->db; TriggerStep *pTriggerStep; - if( pParse->nErr ) return 0; pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1); if( pTriggerStep ){ char *z = (char*)&pTriggerStep[1]; memcpy(z, pName->z, pName->n); sqlite3Dequote(z); @@ -142698,11 +140984,11 @@ /* Generate code to destroy the database record of the trigger. */ if( (v = sqlite3GetVdbe(pParse))!=0 ){ sqlite3NestedParse(pParse, - "DELETE FROM %Q." LEGACY_SCHEMA_TABLE " WHERE name=%Q AND type='trigger'", + "DELETE FROM %Q." DFLT_SCHEMA_TABLE " WHERE name=%Q AND type='trigger'", db->aDb[iDb].zDbSName, pTrigger->zName ); sqlite3ChangeCookie(pParse, iDb); sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0); } @@ -142941,11 +141227,10 @@ Select sSelect; SrcList sFrom; assert( v!=0 ); assert( pParse->bReturning ); - assert( db->pParse==pParse ); pReturning = pParse->u1.pReturning; assert( pTrigger == &(pReturning->retTrig) ); memset(&sSelect, 0, sizeof(sSelect)); memset(&sFrom, 0, sizeof(sFrom)); sSelect.pEList = sqlite3ExprListDup(db, pReturning->pReturnEL, 0); @@ -142952,17 +141237,16 @@ sSelect.pSrc = &sFrom; sFrom.nSrc = 1; sFrom.a[0].pTab = pTab; sFrom.a[0].iCursor = -1; sqlite3SelectPrep(pParse, &sSelect, 0); - if( pParse->nErr==0 ){ - assert( db->mallocFailed==0 ); + if( db->mallocFailed==0 && pParse->nErr==0 ){ sqlite3GenerateColumnNames(pParse, &sSelect); } sqlite3ExprListDelete(db, sSelect.pEList); pNew = sqlite3ExpandReturning(pParse, pReturning->pReturnEL, pTab); - if( !db->mallocFailed ){ + if( pNew ){ NameContext sNC; memset(&sNC, 0, sizeof(sNC)); if( pReturning->nRetCol==0 ){ pReturning->nRetCol = pNew->nExpr; pReturning->iRetCur = pParse->nTab++; @@ -142970,34 +141254,28 @@ sNC.pParse = pParse; sNC.uNC.iBaseReg = regIn; sNC.ncFlags = NC_UBaseReg; pParse->eTriggerOp = pTrigger->op; pParse->pTriggerTab = pTab; - if( sqlite3ResolveExprListNames(&sNC, pNew)==SQLITE_OK - && ALWAYS(!db->mallocFailed) - ){ + if( sqlite3ResolveExprListNames(&sNC, pNew)==SQLITE_OK ){ int i; int nCol = pNew->nExpr; int reg = pParse->nMem+1; pParse->nMem += nCol+2; pReturning->iRetReg = reg; for(i=0; ia[i].pExpr; - assert( pCol!=0 ); /* Due to !db->mallocFailed ~9 lines above */ sqlite3ExprCodeFactorable(pParse, pCol, reg+i); - if( sqlite3ExprAffinity(pCol)==SQLITE_AFF_REAL ){ - sqlite3VdbeAddOp1(v, OP_RealAffinity, reg+i); - } } sqlite3VdbeAddOp3(v, OP_MakeRecord, reg, i, reg+i); sqlite3VdbeAddOp2(v, OP_NewRowid, pReturning->iRetCur, reg+i+1); sqlite3VdbeAddOp3(v, OP_Insert, pReturning->iRetCur, reg+i, reg+i+1); } + sqlite3ExprListDelete(db, pNew); + pParse->eTriggerOp = 0; + pParse->pTriggerTab = 0; } - sqlite3ExprListDelete(db, pNew); - pParse->eTriggerOp = 0; - pParse->pTriggerTab = 0; } /* @@ -143135,12 +141413,12 @@ TriggerPrg *pPrg; /* Value to return */ Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */ Vdbe *v; /* Temporary VM */ NameContext sNC; /* Name context for sub-vdbe */ SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */ + Parse *pSubParse; /* Parse context for sub-vdbe */ int iEndTrigger = 0; /* Label to jump to if WHEN is false */ - Parse sSubParse; /* Parse context for sub-vdbe */ assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) ); assert( pTop->pVdbe ); /* Allocate the TriggerPrg and SubProgram objects. To ensure that they @@ -143158,21 +141436,23 @@ pPrg->aColmask[0] = 0xffffffff; pPrg->aColmask[1] = 0xffffffff; /* Allocate and populate a new Parse context to use for coding the ** trigger sub-program. */ - sqlite3ParseObjectInit(&sSubParse, db); + pSubParse = sqlite3StackAllocZero(db, sizeof(Parse)); + if( !pSubParse ) return 0; memset(&sNC, 0, sizeof(sNC)); - sNC.pParse = &sSubParse; - sSubParse.pTriggerTab = pTab; - sSubParse.pToplevel = pTop; - sSubParse.zAuthContext = pTrigger->zName; - sSubParse.eTriggerOp = pTrigger->op; - sSubParse.nQueryLoop = pParse->nQueryLoop; - sSubParse.disableVtab = pParse->disableVtab; - - v = sqlite3GetVdbe(&sSubParse); + sNC.pParse = pSubParse; + pSubParse->db = db; + pSubParse->pTriggerTab = pTab; + pSubParse->pToplevel = pTop; + pSubParse->zAuthContext = pTrigger->zName; + pSubParse->eTriggerOp = pTrigger->op; + pSubParse->nQueryLoop = pParse->nQueryLoop; + pSubParse->disableVtab = pParse->disableVtab; + + v = sqlite3GetVdbe(pSubParse); if( v ){ VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)", pTrigger->zName, onErrorText(orconf), (pTrigger->tr_tm==TRIGGER_BEFORE ? "BEFORE" : "AFTER"), (pTrigger->op==TK_UPDATE ? "UPDATE" : ""), @@ -143194,43 +141474,42 @@ if( pTrigger->pWhen ){ pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0); if( db->mallocFailed==0 && SQLITE_OK==sqlite3ResolveExprNames(&sNC, pWhen) ){ - iEndTrigger = sqlite3VdbeMakeLabel(&sSubParse); - sqlite3ExprIfFalse(&sSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL); + iEndTrigger = sqlite3VdbeMakeLabel(pSubParse); + sqlite3ExprIfFalse(pSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL); } sqlite3ExprDelete(db, pWhen); } /* Code the trigger program into the sub-vdbe. */ - codeTriggerProgram(&sSubParse, pTrigger->step_list, orconf); + codeTriggerProgram(pSubParse, pTrigger->step_list, orconf); /* Insert an OP_Halt at the end of the sub-program. */ if( iEndTrigger ){ sqlite3VdbeResolveLabel(v, iEndTrigger); } sqlite3VdbeAddOp0(v, OP_Halt); VdbeComment((v, "End: %s.%s", pTrigger->zName, onErrorText(orconf))); - transferParseError(pParse, &sSubParse); - if( pParse->nErr==0 ){ - assert( db->mallocFailed==0 ); + transferParseError(pParse, pSubParse); + if( db->mallocFailed==0 && pParse->nErr==0 ){ pProgram->aOp = sqlite3VdbeTakeOpArray(v, &pProgram->nOp, &pTop->nMaxArg); } - pProgram->nMem = sSubParse.nMem; - pProgram->nCsr = sSubParse.nTab; + pProgram->nMem = pSubParse->nMem; + pProgram->nCsr = pSubParse->nTab; pProgram->token = (void *)pTrigger; - pPrg->aColmask[0] = sSubParse.oldmask; - pPrg->aColmask[1] = sSubParse.newmask; + pPrg->aColmask[0] = pSubParse->oldmask; + pPrg->aColmask[1] = pSubParse->newmask; sqlite3VdbeDelete(v); - }else{ - transferParseError(pParse, &sSubParse); } - assert( !sSubParse.pTriggerPrg && !sSubParse.nMaxArg ); - sqlite3ParseObjectReset(&sSubParse); + assert( !pSubParse->pTriggerPrg && !pSubParse->nMaxArg ); + sqlite3ParserReset(pSubParse); + sqlite3StackFree(db, pSubParse); + return pPrg; } /* ** Return a pointer to a TriggerPrg object containing the sub-program for @@ -143259,11 +141538,10 @@ ); /* If an existing TriggerPrg could not be located, create a new one. */ if( !pPrg ){ pPrg = codeRowTrigger(pParse, pTrigger, pTab, orconf); - pParse->db->errByteOffset = -1; } return pPrg; } @@ -143282,11 +141560,11 @@ int ignoreJump /* Instruction to jump to for RAISE(IGNORE) */ ){ Vdbe *v = sqlite3GetVdbe(pParse); /* Main VM */ TriggerPrg *pPrg; pPrg = getRowTrigger(pParse, p, pTab, orconf); - assert( pPrg || pParse->nErr ); + assert( pPrg || pParse->nErr || pParse->db->mallocFailed ); /* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program ** is a pointer to the sub-vdbe containing the trigger program. */ if( pPrg ){ int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers)); @@ -143800,15 +142078,13 @@ int regRowSet = 0; /* Rowset of rows to be updated */ int regKey = 0; /* composite PRIMARY KEY value */ memset(&sContext, 0, sizeof(sContext)); db = pParse->db; - assert( db->pParse==pParse ); - if( pParse->nErr ){ + if( pParse->nErr || db->mallocFailed ){ goto update_cleanup; } - assert( db->mallocFailed==0 ); /* Locate the table which we want to update. */ pTab = sqlite3SrcListLookup(pParse, pTabList); if( pTab==0 ) goto update_cleanup; @@ -144176,11 +142452,11 @@ ** or index, causing a single-pass approach to malfunction. */ flags = WHERE_ONEPASS_DESIRED; if( !pParse->nested && !pTrigger && !hasFK && !chngKey && !bReplace ){ flags |= WHERE_ONEPASS_MULTIROW; } - pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere,0,0,0,flags,iIdxCur); + pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, flags,iIdxCur); if( pWInfo==0 ) goto update_cleanup; /* A one-pass strategy that might update more than one row may not ** be used if any column of the index used for the scan is being ** updated. Otherwise, if there is an index on "b", statements like @@ -144576,11 +142852,13 @@ /* ** Return the number of rows that were changed, if we are tracking ** that information. */ if( regRowCount ){ - sqlite3CodeChangeCount(v, regRowCount, "rows updated"); + sqlite3VdbeAddOp2(v, OP_ChngCntRow, regRowCount, 1); + sqlite3VdbeSetNumCols(v, 1); + sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows updated", SQLITE_STATIC); } update_cleanup: sqlite3AuthContextPop(&sContext); sqlite3DbFree(db, aXRef); /* Also frees aRegIdx[] and aToOpen[] */ @@ -144698,13 +142976,11 @@ }else{ regRec = ++pParse->nMem; regRowid = ++pParse->nMem; /* Start scanning the virtual table */ - pWInfo = sqlite3WhereBegin( - pParse, pSrc, pWhere, 0, 0, 0, WHERE_ONEPASS_DESIRED, 0 - ); + pWInfo = sqlite3WhereBegin(pParse, pSrc,pWhere,0,0,WHERE_ONEPASS_DESIRED,0); if( pWInfo==0 ) return; /* Populate the argument registers. */ for(i=0; inCol; i++){ assert( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 ); @@ -145361,13 +143637,11 @@ rc = sqlite3BtreeBeginTrans(pMain, pOut==0 ? 2 : 0, 0); if( rc!=SQLITE_OK ) goto end_of_vacuum; /* Do not attempt to change the page size for a WAL database */ if( sqlite3PagerGetJournalMode(sqlite3BtreePager(pMain)) - ==PAGER_JOURNALMODE_WAL - && pOut==0 - ){ + ==PAGER_JOURNALMODE_WAL ){ db->nextPagesize = 0; } if( sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain), nRes, 0) || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes, 0)) @@ -145748,14 +144022,11 @@ ** Except, if argument db is not NULL, then the entry associated with ** connection db is left in the p->u.vtab.p list. */ static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){ VTable *pRet = 0; - VTable *pVTable; - - assert( IsVirtual(p) ); - pVTable = p->u.vtab.p; + VTable *pVTable = p->u.vtab.p; p->u.vtab.p = 0; /* Assert that the mutex (if any) associated with the BtShared database ** that contains table p is held by the caller. See header comments ** above function sqlite3VtabUnlockList() for an explanation of why @@ -145859,11 +144130,10 @@ ** structure being xDisconnected and free). Any other VTable structures ** in the list are moved to the sqlite3.pDisconnect list of the associated ** database connection. */ SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){ - assert( IsVirtual(p) ); if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p); if( p->u.vtab.azArg ){ int i; for(i=0; iu.vtab.nArg; i++){ if( i!=1 ) sqlite3DbFree(db, p->u.vtab.azArg[i]); @@ -145877,16 +144147,13 @@ ** The string is not copied - the pointer is stored. The ** string will be freed automatically when the table is ** deleted. */ static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){ - sqlite3_int64 nBytes; + sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->u.vtab.nArg); char **azModuleArg; sqlite3 *db = pParse->db; - - assert( IsVirtual(pTable) ); - nBytes = sizeof(char *)*(2+pTable->u.vtab.nArg); if( pTable->u.vtab.nArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){ sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName); } azModuleArg = sqlite3DbRealloc(db, pTable->u.vtab.azArg, nBytes); if( azModuleArg==0 ){ @@ -145969,11 +144236,10 @@ SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){ Table *pTab = pParse->pNewTable; /* The table being constructed */ sqlite3 *db = pParse->db; /* The database connection */ if( pTab==0 ) return; - assert( IsVirtual(pTab) ); addArgumentToVtab(pParse); pParse->sArg.z = 0; if( pTab->u.vtab.nArg<1 ) return; /* If the CREATE VIRTUAL TABLE statement is being entered for the @@ -146005,11 +144271,11 @@ ** entry in the sqlite_schema table tht was created for this vtab ** by sqlite3StartTable(). */ iDb = sqlite3SchemaToIndex(db, pTab->pSchema); sqlite3NestedParse(pParse, - "UPDATE %Q." LEGACY_SCHEMA_TABLE " " + "UPDATE %Q." DFLT_SCHEMA_TABLE " " "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q " "WHERE rowid=#%d", db->aDb[iDb].zDbSName, pTab->zName, pTab->zName, @@ -146025,18 +144291,22 @@ sqlite3DbFree(db, zStmt); iReg = ++pParse->nMem; sqlite3VdbeLoadString(v, iReg, pTab->zName); sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg); - }else{ - /* If we are rereading the sqlite_schema table create the in-memory - ** record of the table. */ + } + + /* If we are rereading the sqlite_schema table create the in-memory + ** record of the table. The xConnect() method is not called until + ** the first time the virtual table is used in an SQL statement. This + ** allows a schema that contains virtual tables to be loaded before + ** the required virtual table implementations are registered. */ + else { Table *pOld; Schema *pSchema = pTab->pSchema; const char *zName = pTab->zName; - assert( zName!=0 ); - sqlite3MarkAllShadowTablesOf(db, pTab); + assert( sqlite3SchemaMutexHeld(db, 0, pSchema) ); pOld = sqlite3HashInsert(&pSchema->tblHash, zName, pTab); if( pOld ){ sqlite3OomFault(db); assert( pTab==pOld ); /* Malloc must have failed inside HashInsert() */ return; @@ -146083,20 +144353,17 @@ char **pzErr ){ VtabCtx sCtx; VTable *pVTable; int rc; - const char *const*azArg; + const char *const*azArg = (const char *const*)pTab->u.vtab.azArg; int nArg = pTab->u.vtab.nArg; char *zErr = 0; char *zModuleName; int iDb; VtabCtx *pCtx; - assert( IsVirtual(pTab) ); - azArg = (const char *const*)pTab->u.vtab.azArg; - /* Check that the virtual-table is not already being initialized */ for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){ if( pCtx->pTab==pTab ){ *pzErr = sqlite3MPrintf(db, "vtable constructor called recursively: %s", pTab->zName @@ -146216,12 +144483,11 @@ const char *zMod; Module *pMod; int rc; assert( pTab ); - assert( IsVirtual(pTab) ); - if( sqlite3GetVTable(db, pTab) ){ + if( !IsVirtual(pTab) || sqlite3GetVTable(db, pTab) ){ return SQLITE_OK; } /* Locate the required virtual table module */ zMod = pTab->u.vtab.azArg[0]; @@ -146327,10 +144593,11 @@ */ SQLITE_API int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ VtabCtx *pCtx; int rc = SQLITE_OK; Table *pTab; + char *zErr = 0; Parse sParse; int initBusy; #ifdef SQLITE_ENABLE_API_ARMOR if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){ @@ -146345,26 +144612,25 @@ return SQLITE_MISUSE_BKPT; } pTab = pCtx->pTab; assert( IsVirtual(pTab) ); - sqlite3ParseObjectInit(&sParse, db); + memset(&sParse, 0, sizeof(sParse)); sParse.eParseMode = PARSE_MODE_DECLARE_VTAB; - sParse.disableTriggers = 1; + sParse.db = db; /* We should never be able to reach this point while loading the ** schema. Nevertheless, defend against that (turn off db->init.busy) ** in case a bug arises. */ assert( db->init.busy==0 ); initBusy = db->init.busy; db->init.busy = 0; sParse.nQueryLoop = 1; - if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable) - && ALWAYS(sParse.pNewTable!=0) - && ALWAYS(!db->mallocFailed) + if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable, &zErr) + && sParse.pNewTable + && !db->mallocFailed && IsOrdinaryTable(sParse.pNewTable) ){ - assert( sParse.zErrMsg==0 ); if( !pTab->aCol ){ Table *pNew = sParse.pNewTable; Index *pIdx; pTab->aCol = pNew->aCol; sqlite3ExprListDelete(db, pNew->u.tab.pDfltList); @@ -146390,22 +144656,21 @@ pIdx->pTable = pTab; } } pCtx->bDeclared = 1; }else{ - sqlite3ErrorWithMsg(db, SQLITE_ERROR, - (sParse.zErrMsg ? "%s" : 0), sParse.zErrMsg); - sqlite3DbFree(db, sParse.zErrMsg); + sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr); + sqlite3DbFree(db, zErr); rc = SQLITE_ERROR; } sParse.eParseMode = PARSE_MODE_NORMAL; if( sParse.pVdbe ){ sqlite3VdbeFinalize(sParse.pVdbe); } sqlite3DeleteTable(db, sParse.pNewTable); - sqlite3ParseObjectReset(&sParse); + sqlite3ParserReset(&sParse); db->init.busy = initBusy; assert( (rc&0xff)==rc ); rc = sqlite3ApiExit(db, rc); sqlite3_mutex_leave(db->mutex); @@ -146422,14 +144687,11 @@ SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){ int rc = SQLITE_OK; Table *pTab; pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName); - if( ALWAYS(pTab!=0) - && ALWAYS(IsVirtual(pTab)) - && ALWAYS(pTab->u.vtab.p!=0) - ){ + if( pTab!=0 && ALWAYS(pTab->u.vtab.p!=0) ){ VTable *p; int (*xDestroy)(sqlite3_vtab *); for(p=pTab->u.vtab.p; p; p=p->pNext){ assert( p->pVtab ); if( p->pVtab->nRef>0 ){ @@ -146658,11 +144920,10 @@ int rc = 0; /* Check to see the left operand is a column in a virtual table */ if( NEVER(pExpr==0) ) return pDef; if( pExpr->op!=TK_COLUMN ) return pDef; - assert( ExprUseYTab(pExpr) ); pTab = pExpr->y.pTab; if( pTab==0 ) return pDef; if( !IsVirtual(pTab) ) return pDef; pVtab = sqlite3GetVTable(db, pTab)->pVtab; assert( pVtab!=0 ); @@ -146953,11 +145214,10 @@ int addrBignull; /* Jump here for next part of big-null scan */ #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS u32 iLikeRepCntr; /* LIKE range processing counter register (times 2) */ int addrLikeRep; /* LIKE range processing address */ #endif - int regFilter; /* Bloom filter */ u8 iFrom; /* Which entry in the FROM clause */ u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */ int p1, p2; /* Operands of the opcode used to end the loop */ union { /* Information that depends on pWLoop->wsFlags */ struct { @@ -146968,11 +145228,11 @@ int iBase; /* Base register of multi-key index record */ int nPrefix; /* Number of prior entires in the key */ u8 eEndLoopOp; /* IN Loop terminator. OP_Next or OP_Prev */ } *aInLoop; /* Information about each nested IN operator */ } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */ - Index *pCoveringIdx; /* Possible covering index for WHERE_MULTI_OR */ + Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */ } u; struct WhereLoop *pWLoop; /* The selected WhereLoop object */ Bitmask notReady; /* FROM entries not usable at this level */ #ifdef SQLITE_ENABLE_STMT_SCANSTATUS int addrVisit; /* Address at which row is visited */ @@ -147012,16 +145272,14 @@ u16 nDistinctCol; /* Index columns used to sort for DISTINCT */ Index *pIndex; /* Index used, or NULL */ } btree; struct { /* Information for virtual tables */ int idxNum; /* Index number */ - u32 needFree : 1; /* True if sqlite3_free(idxStr) is needed */ - u32 bOmitOffset : 1; /* True to let virtual table handle offset */ + u8 needFree; /* True if sqlite3_free(idxStr) is needed */ i8 isOrdered; /* True if satisfies ORDER BY */ u16 omitMask; /* Terms that may be omitted */ char *idxStr; /* Index identifier string */ - u32 mHandleIn; /* Terms to handle as IN(...) instead of == */ } vtab; } u; u32 wsFlags; /* WHERE_* flags describing the plan */ u16 nLTerm; /* Number of entries in aLTerm[] */ u16 nSkip; /* Number of NULL aLTerm[] entries */ @@ -147161,11 +145419,11 @@ #define TERM_VIRTUAL 0x0002 /* Added by the optimizer. Do not code */ #define TERM_CODED 0x0004 /* This term is already coded */ #define TERM_COPIED 0x0008 /* Has a child */ #define TERM_ORINFO 0x0010 /* Need to free the WhereTerm.u.pOrInfo object */ #define TERM_ANDINFO 0x0020 /* Need to free the WhereTerm.u.pAndInfo obj */ -#define TERM_OK 0x0040 /* Used during OR-clause processing */ +#define TERM_OR_OK 0x0040 /* Used during OR-clause processing */ #define TERM_VNULL 0x0080 /* Manufactured x>NULL or x<=NULL term */ #define TERM_LIKEOPT 0x0100 /* Virtual terms from the LIKE optimization */ #define TERM_LIKECOND 0x0200 /* Conditionally this LIKE operator term */ #define TERM_LIKE 0x0400 /* The original LIKE operator */ #define TERM_IS 0x0800 /* Term.pExpr is an IS operator */ @@ -147174,11 +145432,10 @@ #ifdef SQLITE_ENABLE_STAT4 # define TERM_HIGHTRUTH 0x4000 /* Term excludes few rows */ #else # define TERM_HIGHTRUTH 0 /* Only used with STAT4 */ #endif -#define TERM_SLICE 0x8000 /* One slice of a row-value/vector comparison */ /* ** An instance of the WhereScan object is used as an iterator for locating ** terms in the WHERE clause that are useful to the query planner. */ @@ -147185,15 +145442,15 @@ struct WhereScan { WhereClause *pOrigWC; /* Original, innermost WhereClause */ WhereClause *pWC; /* WhereClause currently being scanned */ const char *zCollName; /* Required collating sequence, if not NULL */ Expr *pIdxExpr; /* Search for this index expression */ - int k; /* Resume scanning at this->pWC->a[this->k] */ - u32 opMask; /* Acceptable operators */ char idxaff; /* Must match this affinity, if zCollName!=NULL */ - unsigned char iEquiv; /* Current slot in aiCur[] and aiColumn[] */ unsigned char nEquiv; /* Number of entries in aiCur[] and aiColumn[] */ + unsigned char iEquiv; /* Next unused slot in aiCur[] and aiColumn[] */ + u32 opMask; /* Acceptable operators */ + int k; /* Resume scanning at this->pWC->a[this->k] */ int aiCur[11]; /* Cursors in the equivalence class */ i16 aiColumn[11]; /* Corresponding column number in the eq-class */ }; /* @@ -147213,11 +145470,10 @@ WhereClause *pOuter; /* Outer conjunction */ u8 op; /* Split operator. TK_AND or TK_OR */ u8 hasOr; /* True if any a[].eOperator is WO_OR */ int nTerm; /* Number of terms */ int nSlot; /* Number of entries in a[] */ - int nBase; /* Number of terms through the last non-Virtual */ WhereTerm *a; /* Each a[] describes a term of the WHERE cluase */ #if defined(SQLITE_SMALL_STACK) WhereTerm aStatic[1]; /* Initial static space for a[] */ #else WhereTerm aStatic[8]; /* Initial static space for a[] */ @@ -147271,17 +145527,23 @@ int bVarSelect; /* Used by sqlite3WhereExprUsage() */ int n; /* Number of assigned cursor values */ int ix[BMS]; /* Cursor assigned to each bit */ }; +/* +** Initialize a WhereMaskSet object +*/ +#define initMaskSet(P) (P)->n=0 + /* ** This object is a convenience wrapper holding all information needed ** to construct WhereLoop objects for a particular query. */ struct WhereLoopBuilder { WhereInfo *pWInfo; /* Information about this WHERE */ WhereClause *pWC; /* WHERE clause terms */ + ExprList *pOrderBy; /* ORDER BY clause */ WhereLoop *pNew; /* Template WhereLoop */ WhereOrSet *pOrSet; /* Record best loops here, if not NULL */ #ifdef SQLITE_ENABLE_STAT4 UnpackedRecord *pRec; /* Probe for stat4 (if required) */ int nRecValid; /* Number of valid fields currently in pRec */ @@ -147345,13 +145607,10 @@ Parse *pParse; /* Parsing and code generating context */ SrcList *pTabList; /* List of tables in the join */ ExprList *pOrderBy; /* The ORDER BY clause or NULL */ ExprList *pResultSet; /* Result set of the query */ Expr *pWhere; /* The complete WHERE clause */ -#ifndef SQLITE_OMIT_VIRTUALTABLE - Select *pLimit; /* Used to access LIMIT expr/registers for vtabs */ -#endif int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */ int iContinue; /* Jump here to continue with next record */ int iBreak; /* Jump here to break out of the loop */ int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */ u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */ @@ -147401,18 +145660,12 @@ Parse *pParse, /* Parse context */ SrcList *pTabList, /* Table list this loop refers to */ WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */ u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */ ); -SQLITE_PRIVATE int sqlite3WhereExplainBloomFilter( - const Parse *pParse, /* Parse context */ - const WhereInfo *pWInfo, /* WHERE clause */ - const WhereLevel *pLevel /* Bloom filter on this level */ -); #else # define sqlite3WhereExplainOneScan(u,v,w,x) 0 -# define sqlite3WhereExplainBloomFilter(u,v,w) 0 #endif /* SQLITE_OMIT_EXPLAIN */ #ifdef SQLITE_ENABLE_STMT_SCANSTATUS SQLITE_PRIVATE void sqlite3WhereAddScanStatus( Vdbe *v, /* Vdbe to add scanstatus entry to */ SrcList *pSrclist, /* FROM clause pLvl reads data from */ @@ -147433,11 +145686,10 @@ /* whereexpr.c: */ SQLITE_PRIVATE void sqlite3WhereClauseInit(WhereClause*,WhereInfo*); SQLITE_PRIVATE void sqlite3WhereClauseClear(WhereClause*); SQLITE_PRIVATE void sqlite3WhereSplit(WhereClause*,Expr*,u8); -SQLITE_PRIVATE void sqlite3WhereAddLimit(WhereClause*, Select*); SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet*, Expr*); SQLITE_PRIVATE Bitmask sqlite3WhereExprUsageNN(WhereMaskSet*, Expr*); SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet*, ExprList*); SQLITE_PRIVATE void sqlite3WhereExprAnalyze(SrcList*, WhereClause*); SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(Parse*, SrcItem*, WhereClause*); @@ -147502,13 +145754,10 @@ #define WHERE_PARTIALIDX 0x00020000 /* The automatic index is partial */ #define WHERE_IN_EARLYOUT 0x00040000 /* Perhaps quit IN loops early */ #define WHERE_BIGNULL_SORT 0x00080000 /* Column nEq of index is BIGNULL */ #define WHERE_IN_SEEKSCAN 0x00100000 /* Seek-scan optimization for IN */ #define WHERE_TRANSCONS 0x00200000 /* Uses a transitive constraint */ -#define WHERE_BLOOMFILTER 0x00400000 /* Consider using a Bloom-filter */ -#define WHERE_SELFCULL 0x00800000 /* nOut reduced by extra WHERE terms */ -#define WHERE_OMIT_OFFSET 0x01000000 /* Set offset counter to zero */ #endif /* !defined(SQLITE_WHEREINT_H) */ /************** End of whereInt.h ********************************************/ /************** Continuing where we left off in wherecode.c ******************/ @@ -147667,31 +145916,23 @@ sqlite3_str_append(&str, " USING ", 7); sqlite3_str_appendf(&str, zFmt, pIdx->zName); explainIndexRange(&str, pLoop); } }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){ - char cRangeOp; -#if 0 /* Better output, but breaks many tests */ - const Table *pTab = pItem->pTab; - const char *zRowid = pTab->iPKey>=0 ? pTab->aCol[pTab->iPKey].zCnName: - "rowid"; -#else - const char *zRowid = "rowid"; -#endif - sqlite3_str_appendf(&str, " USING INTEGER PRIMARY KEY (%s", zRowid); + const char *zRangeOp; if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){ - cRangeOp = '='; + zRangeOp = "="; }else if( (flags&WHERE_BOTH_LIMIT)==WHERE_BOTH_LIMIT ){ - sqlite3_str_appendf(&str, ">? AND %s", zRowid); - cRangeOp = '<'; + zRangeOp = ">? AND rowid<"; }else if( flags&WHERE_BTM_LIMIT ){ - cRangeOp = '>'; + zRangeOp = ">"; }else{ assert( flags&WHERE_TOP_LIMIT); - cRangeOp = '<'; + zRangeOp = "<"; } - sqlite3_str_appendf(&str, "%c?)", cRangeOp); + sqlite3_str_appendf(&str, + " USING INTEGER PRIMARY KEY (rowid%s?)",zRangeOp); } #ifndef SQLITE_OMIT_VIRTUALTABLE else if( (flags & WHERE_VIRTUALTABLE)!=0 ){ sqlite3_str_appendf(&str, " VIRTUAL TABLE INDEX %d:%s", pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr); @@ -147710,60 +145951,10 @@ ret = sqlite3VdbeAddOp4(v, OP_Explain, sqlite3VdbeCurrentAddr(v), pParse->addrExplain, 0, zMsg,P4_DYNAMIC); } return ret; } - -/* -** Add a single OP_Explain opcode that describes a Bloom filter. -** -** Or if not processing EXPLAIN QUERY PLAN and not in a SQLITE_DEBUG and/or -** SQLITE_ENABLE_STMT_SCANSTATUS build, then OP_Explain opcodes are not -** required and this routine is a no-op. -** -** If an OP_Explain opcode is added to the VM, its address is returned. -** Otherwise, if no OP_Explain is coded, zero is returned. -*/ -SQLITE_PRIVATE int sqlite3WhereExplainBloomFilter( - const Parse *pParse, /* Parse context */ - const WhereInfo *pWInfo, /* WHERE clause */ - const WhereLevel *pLevel /* Bloom filter on this level */ -){ - int ret = 0; - SrcItem *pItem = &pWInfo->pTabList->a[pLevel->iFrom]; - Vdbe *v = pParse->pVdbe; /* VM being constructed */ - sqlite3 *db = pParse->db; /* Database handle */ - char *zMsg; /* Text to add to EQP output */ - int i; /* Loop counter */ - WhereLoop *pLoop; /* The where loop */ - StrAccum str; /* EQP output string */ - char zBuf[100]; /* Initial space for EQP output string */ - - sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH); - str.printfFlags = SQLITE_PRINTF_INTERNAL; - sqlite3_str_appendf(&str, "BLOOM FILTER ON %S (", pItem); - pLoop = pLevel->pWLoop; - if( pLoop->wsFlags & WHERE_IPK ){ - const Table *pTab = pItem->pTab; - if( pTab->iPKey>=0 ){ - sqlite3_str_appendf(&str, "%s=?", pTab->aCol[pTab->iPKey].zCnName); - }else{ - sqlite3_str_appendf(&str, "rowid=?"); - } - }else{ - for(i=pLoop->nSkip; iu.btree.nEq; i++){ - const char *z = explainIndexColumnName(pLoop->u.btree.pIndex, i); - if( i>pLoop->nSkip ) sqlite3_str_append(&str, " AND ", 5); - sqlite3_str_appendf(&str, "%s=?", z); - } - } - sqlite3_str_append(&str, ")", 1); - zMsg = sqlite3StrAccumFinish(&str); - ret = sqlite3VdbeAddOp4(v, OP_Explain, sqlite3VdbeCurrentAddr(v), - pParse->addrExplain, 0, zMsg,P4_DYNAMIC); - return ret; -} #endif /* SQLITE_OMIT_EXPLAIN */ #ifdef SQLITE_ENABLE_STMT_SCANSTATUS /* ** Configure the VM passed as the first argument with an @@ -147965,27 +146156,20 @@ ){ sqlite3 *db = pParse->db; Expr *pNew; pNew = sqlite3ExprDup(db, pX, 0); if( db->mallocFailed==0 ){ - ExprList *pOrigRhs; /* Original unmodified RHS */ - ExprList *pOrigLhs; /* Original unmodified LHS */ + ExprList *pOrigRhs = pNew->x.pSelect->pEList; /* Original unmodified RHS */ + ExprList *pOrigLhs = pNew->pLeft->x.pList; /* Original unmodified LHS */ ExprList *pRhs = 0; /* New RHS after modifications */ ExprList *pLhs = 0; /* New LHS after mods */ int i; /* Loop counter */ Select *pSelect; /* Pointer to the SELECT on the RHS */ - assert( ExprUseXSelect(pNew) ); - pOrigRhs = pNew->x.pSelect->pEList; - assert( pNew->pLeft!=0 ); - assert( ExprUseXList(pNew->pLeft) ); - pOrigLhs = pNew->pLeft->x.pList; for(i=iEq; inLTerm; i++){ if( pLoop->aLTerm[i]->pExpr==pX ){ - int iField; - assert( (pLoop->aLTerm[i]->eOperator & (WO_OR|WO_AND))==0 ); - iField = pLoop->aLTerm[i]->u.x.iField - 1; + int iField = pLoop->aLTerm[i]->u.x.iField - 1; if( pOrigRhs->a[iField].pExpr==0 ) continue; /* Duplicate PK column */ pRhs = sqlite3ExprListAppend(pParse, pRhs, pOrigRhs->a[iField].pExpr); pOrigRhs->a[iField].pExpr = 0; assert( pOrigLhs->a[iField].pExpr!=0 ); pLhs = sqlite3ExprListAppend(pParse, pLhs, pOrigLhs->a[iField].pExpr); @@ -148096,11 +146280,11 @@ assert( pLoop->aLTerm[i]!=0 ); if( pLoop->aLTerm[i]->pExpr==pX ) nEq++; } iTab = 0; - if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){ + if( (pX->flags & EP_xIsSelect)==0 || pX->x.pSelect->pEList->nExpr==1 ){ eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab); }else{ sqlite3 *db = pParse->db; pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX); @@ -148118,12 +146302,12 @@ bRev = !bRev; } sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0); VdbeCoverageIf(v, bRev); VdbeCoverageIf(v, !bRev); - assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 ); + pLoop->wsFlags |= WHERE_IN_ABLE; if( pLevel->u.in.nIn==0 ){ pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse); } if( iEq>0 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)==0 ){ @@ -148283,11 +146467,10 @@ sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur); VdbeCoverageIf(v, bRev==0); VdbeCoverageIf(v, bRev!=0); VdbeComment((v, "begin skip-scan on %s", pIdx->zName)); j = sqlite3VdbeAddOp0(v, OP_Goto); - assert( pLevel->addrSkip==0 ); pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLT:OP_SeekGT), iIdxCur, 0, regBase, nSkip); VdbeCoverageIf(v, bRev==0); VdbeCoverageIf(v, bRev!=0); sqlite3VdbeJumpHere(v, j); @@ -148316,13 +146499,10 @@ regBase = r1; }else{ sqlite3VdbeAddOp2(v, OP_Copy, r1, regBase+j); } } - } - for(j=nSkip; jaLTerm[j]; if( pTerm->eOperator & WO_IN ){ if( pTerm->pExpr->flags & EP_xIsSelect ){ /* No affinity ever needs to be (or should be) applied to a value ** from the RHS of an "? IN (SELECT ...)" expression. The ** sqlite3FindInIndex() routine has already ensured that the @@ -148333,12 +146513,11 @@ Expr *pRight = pTerm->pExpr->pRight; if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){ sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk); VdbeCoverage(v); } - if( pParse->nErr==0 ){ - assert( pParse->db->mallocFailed==0 ); + if( pParse->db->mallocFailed==0 && pParse->nErr==0 ){ if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_BLOB ){ zAff[j] = SQLITE_AFF_BLOB; } if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){ zAff[j] = SQLITE_AFF_BLOB; @@ -148524,11 +146703,11 @@ sHint.pIdx = pLoop->u.btree.pIndex; memset(&sWalker, 0, sizeof(sWalker)); sWalker.pParse = pParse; sWalker.u.pCCurHint = &sHint; pWC = &pWInfo->sWC; - for(i=0; inBase; i++){ + for(i=0; inTerm; i++){ pTerm = &pWC->a[i]; if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue; if( pTerm->prereqAll & pLevel->notReady ) continue; /* Any terms specified as part of the ON(...) clause for any LEFT @@ -148554,11 +146733,11 @@ ** are also excluded. See codeCursorHintIsOrFunction() for details. */ if( pTabItem->fg.jointype & JT_LEFT ){ Expr *pExpr = pTerm->pExpr; if( !ExprHasProperty(pExpr, EP_FromJoin) - || pExpr->w.iRightJoinTable!=pTabItem->iCursor + || pExpr->iRightJoinTable!=pTabItem->iCursor ){ sWalker.eCode = 0; sWalker.xExprCallback = codeCursorHintIsOrFunction; sqlite3WalkExpr(&sWalker, pTerm->pExpr); if( sWalker.eCode ) continue; @@ -148666,23 +146845,21 @@ */ static void codeExprOrVector(Parse *pParse, Expr *p, int iReg, int nReg){ assert( nReg>0 ); if( p && sqlite3ExprIsVector(p) ){ #ifndef SQLITE_OMIT_SUBQUERY - if( ExprUseXSelect(p) ){ + if( (p->flags & EP_xIsSelect) ){ Vdbe *v = pParse->pVdbe; int iSelect; assert( p->op==TK_SELECT ); iSelect = sqlite3CodeSubselect(pParse, p); sqlite3VdbeAddOp3(v, OP_Copy, iSelect, iReg, nReg-1); }else #endif { int i; - const ExprList *pList; - assert( ExprUseXList(p) ); - pList = p->x.pList; + ExprList *pList = p->x.pList; assert( nReg<=pList->nExpr ); for(i=0; ia[i].pExpr, iReg+i); } } @@ -148726,20 +146903,19 @@ ** that contains the value of pExpr. */ static int whereIndexExprTransNode(Walker *p, Expr *pExpr){ IdxExprTrans *pX = p->u.pIdxTrans; if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){ - pExpr = sqlite3ExprSkipCollate(pExpr); preserveExpr(pX, pExpr); pExpr->affExpr = sqlite3ExprAffinity(pExpr); pExpr->op = TK_COLUMN; pExpr->iTable = pX->iIdxCur; pExpr->iColumn = pX->iIdxCol; + pExpr->y.pTab = 0; testcase( ExprHasProperty(pExpr, EP_Skip) ); testcase( ExprHasProperty(pExpr, EP_Unlikely) ); - ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn); - pExpr->y.pTab = 0; + ExprClearProperty(pExpr, EP_Skip|EP_Unlikely); return WRC_Prune; }else{ return WRC_Continue; } } @@ -148750,11 +146926,11 @@ */ static int whereIndexExprTransColumn(Walker *p, Expr *pExpr){ if( pExpr->op==TK_COLUMN ){ IdxExprTrans *pX = p->u.pIdxTrans; if( pExpr->iTable==pX->iTabCur && pExpr->iColumn==pX->iTabCol ){ - assert( ExprUseYTab(pExpr) && pExpr->y.pTab!=0 ); + assert( pExpr->y.pTab!=0 ); preserveExpr(pX, pExpr); pExpr->affExpr = sqlite3TableColumnAffinity(pExpr->y.pTab,pExpr->iColumn); pExpr->iTable = pX->iIdxCur; pExpr->iColumn = pX->iIdxCol; pExpr->y.pTab = 0; @@ -148798,11 +146974,11 @@ x.pWInfo = pWInfo; x.db = pWInfo->pParse->db; for(iIdxCol=0; iIdxColnColumn; iIdxCol++){ i16 iRef = pIdx->aiColumn[iIdxCol]; if( iRef==XN_EXPR ){ - assert( aColExpr!=0 && aColExpr->a[iIdxCol].pExpr!=0 ); + assert( aColExpr->a[iIdxCol].pExpr!=0 ); x.pIdxExpr = aColExpr->a[iIdxCol].pExpr; if( sqlite3ExprIsConstant(x.pIdxExpr) ) continue; w.xExprCallback = whereIndexExprTransNode; #ifndef SQLITE_OMIT_GENERATED_COLUMNS }else if( iRef>=0 @@ -148856,72 +147032,10 @@ pTerm->wtFlags |= TERM_CODED; } } } -/* -** This routine is called right after An OP_Filter has been generated and -** before the corresponding index search has been performed. This routine -** checks to see if there are additional Bloom filters in inner loops that -** can be checked prior to doing the index lookup. If there are available -** inner-loop Bloom filters, then evaluate those filters now, before the -** index lookup. The idea is that a Bloom filter check is way faster than -** an index lookup, and the Bloom filter might return false, meaning that -** the index lookup can be skipped. -** -** We know that an inner loop uses a Bloom filter because it has the -** WhereLevel.regFilter set. If an inner-loop Bloom filter is checked, -** then clear the WhereLevel.regFilter value to prevent the Bloom filter -** from being checked a second time when the inner loop is evaluated. -*/ -static SQLITE_NOINLINE void filterPullDown( - Parse *pParse, /* Parsing context */ - WhereInfo *pWInfo, /* Complete information about the WHERE clause */ - int iLevel, /* Which level of pWInfo->a[] should be coded */ - int addrNxt, /* Jump here to bypass inner loops */ - Bitmask notReady /* Loops that are not ready */ -){ - while( ++iLevel < pWInfo->nLevel ){ - WhereLevel *pLevel = &pWInfo->a[iLevel]; - WhereLoop *pLoop = pLevel->pWLoop; - if( pLevel->regFilter==0 ) continue; - if( pLevel->pWLoop->nSkip ) continue; - /* ,--- Because sqlite3ConstructBloomFilter() has will not have set - ** vvvvv--' pLevel->regFilter if this were true. */ - if( NEVER(pLoop->prereq & notReady) ) continue; - assert( pLevel->addrBrk==0 ); - pLevel->addrBrk = addrNxt; - if( pLoop->wsFlags & WHERE_IPK ){ - WhereTerm *pTerm = pLoop->aLTerm[0]; - int regRowid; - assert( pTerm!=0 ); - assert( pTerm->pExpr!=0 ); - testcase( pTerm->wtFlags & TERM_VIRTUAL ); - regRowid = sqlite3GetTempReg(pParse); - regRowid = codeEqualityTerm(pParse, pTerm, pLevel, 0, 0, regRowid); - sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter, - addrNxt, regRowid, 1); - VdbeCoverage(pParse->pVdbe); - }else{ - u16 nEq = pLoop->u.btree.nEq; - int r1; - char *zStartAff; - - assert( pLoop->wsFlags & WHERE_INDEXED ); - assert( (pLoop->wsFlags & WHERE_COLUMN_IN)==0 ); - r1 = codeAllEqualityTerms(pParse,pLevel,0,0,&zStartAff); - codeApplyAffinity(pParse, r1, nEq, zStartAff); - sqlite3DbFree(pParse->db, zStartAff); - sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter, - addrNxt, r1, nEq); - VdbeCoverage(pParse->pVdbe); - } - pLevel->regFilter = 0; - pLevel->addrBrk = 0; - } -} - /* ** Generate code for the start of the iLevel-th loop in the WHERE clause ** implementation described by pWInfo. */ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart( @@ -149020,39 +147134,24 @@ ** to access the data. */ int iReg; /* P3 Value for OP_VFilter */ int addrNotFound; int nConstraint = pLoop->nLTerm; + int iIn; /* Counter for IN constraints */ iReg = sqlite3GetTempRange(pParse, nConstraint+2); addrNotFound = pLevel->addrBrk; for(j=0; jaLTerm[j]; if( NEVER(pTerm==0) ) continue; if( pTerm->eOperator & WO_IN ){ - if( SMASKBIT32(j) & pLoop->u.vtab.mHandleIn ){ - int iTab = pParse->nTab++; - int iCache = ++pParse->nMem; - sqlite3CodeRhsOfIN(pParse, pTerm->pExpr, iTab); - sqlite3VdbeAddOp3(v, OP_VInitIn, iTab, iTarget, iCache); - }else{ - codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, iTarget); - addrNotFound = pLevel->addrNxt; - } + codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, iTarget); + addrNotFound = pLevel->addrNxt; }else{ Expr *pRight = pTerm->pExpr->pRight; codeExprOrVector(pParse, pRight, iTarget, 1); - if( pTerm->eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET - && pLoop->u.vtab.bOmitOffset - ){ - assert( pTerm->eOperator==WO_AUX ); - assert( pWInfo->pLimit!=0 ); - assert( pWInfo->pLimit->iOffset>0 ); - sqlite3VdbeAddOp2(v, OP_Integer, 0, pWInfo->pLimit->iOffset); - VdbeComment((v,"Zero OFFSET counter")); - } } } sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg); sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1); sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg, @@ -149064,72 +147163,57 @@ ** the u.vtab.idxStr. NULL it out to prevent a use-after-free */ if( db->mallocFailed ) pLoop->u.vtab.idxStr = 0; pLevel->p1 = iCur; pLevel->op = pWInfo->eOnePass ? OP_Noop : OP_VNext; pLevel->p2 = sqlite3VdbeCurrentAddr(v); - assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 ); - - for(j=0; ju.in.nIn; + for(j=nConstraint-1; j>=0; j--){ pTerm = pLoop->aLTerm[j]; + if( (pTerm->eOperator & WO_IN)!=0 ) iIn--; if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){ disableTerm(pLevel, pTerm); - continue; - } - if( (pTerm->eOperator & WO_IN)!=0 - && (SMASKBIT32(j) & pLoop->u.vtab.mHandleIn)==0 - && !db->mallocFailed + }else if( (pTerm->eOperator & WO_IN)!=0 + && sqlite3ExprVectorSize(pTerm->pExpr->pLeft)==1 ){ Expr *pCompare; /* The comparison operator */ Expr *pRight; /* RHS of the comparison */ VdbeOp *pOp; /* Opcode to access the value of the IN constraint */ - int iIn; /* IN loop corresponding to the j-th constraint */ /* Reload the constraint value into reg[iReg+j+2]. The same value ** was loaded into the same register prior to the OP_VFilter, but ** the xFilter implementation might have changed the datatype or - ** encoding of the value in the register, so it *must* be reloaded. - */ - for(iIn=0; ALWAYS(iInu.in.nIn); iIn++){ + ** encoding of the value in the register, so it *must* be reloaded. */ + assert( pLevel->u.in.aInLoop!=0 || db->mallocFailed ); + if( !db->mallocFailed ){ + assert( iIn>=0 && iInu.in.nIn ); pOp = sqlite3VdbeGetOp(v, pLevel->u.in.aInLoop[iIn].addrInTop); - if( (pOp->opcode==OP_Column && pOp->p3==iReg+j+2) - || (pOp->opcode==OP_Rowid && pOp->p2==iReg+j+2) - ){ - testcase( pOp->opcode==OP_Rowid ); - sqlite3VdbeAddOp3(v, pOp->opcode, pOp->p1, pOp->p2, pOp->p3); - break; - } + assert( pOp->opcode==OP_Column || pOp->opcode==OP_Rowid ); + assert( pOp->opcode!=OP_Column || pOp->p3==iReg+j+2 ); + assert( pOp->opcode!=OP_Rowid || pOp->p2==iReg+j+2 ); + testcase( pOp->opcode==OP_Rowid ); + sqlite3VdbeAddOp3(v, pOp->opcode, pOp->p1, pOp->p2, pOp->p3); } /* Generate code that will continue to the next row if - ** the IN constraint is not satisfied - */ + ** the IN constraint is not satisfied */ pCompare = sqlite3PExpr(pParse, TK_EQ, 0, 0); - if( !db->mallocFailed ){ - int iFld = pTerm->u.x.iField; - Expr *pLeft = pTerm->pExpr->pLeft; - assert( pLeft!=0 ); - if( iFld>0 ){ - assert( pLeft->op==TK_VECTOR ); - assert( ExprUseXList(pLeft) ); - assert( iFld<=pLeft->x.pList->nExpr ); - pCompare->pLeft = pLeft->x.pList->a[iFld-1].pExpr; - }else{ - pCompare->pLeft = pLeft; - } + assert( pCompare!=0 || db->mallocFailed ); + if( pCompare ){ + pCompare->pLeft = pTerm->pExpr->pLeft; pCompare->pRight = pRight = sqlite3Expr(db, TK_REGISTER, 0); if( pRight ){ pRight->iTable = iReg+j+2; sqlite3ExprIfFalse( pParse, pCompare, pLevel->addrCont, SQLITE_JUMPIFNULL ); } pCompare->pLeft = 0; + sqlite3ExprDelete(db, pCompare); } - sqlite3ExprDelete(db, pCompare); } } - + assert( iIn==0 || db->mallocFailed ); /* These registers need to be preserved in case there is an IN operator ** loop. So we could deallocate the registers here (and potentially ** reuse them later) if (pLoop->wsFlags & WHERE_IN_ABLE)==0. But it seems ** simpler and safer to simply not reuse the registers. ** @@ -149153,16 +147237,10 @@ testcase( pTerm->wtFlags & TERM_VIRTUAL ); iReleaseReg = ++pParse->nMem; iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg); if( iRowidReg!=iReleaseReg ) sqlite3ReleaseTempReg(pParse, iReleaseReg); addrNxt = pLevel->addrNxt; - if( pLevel->regFilter ){ - sqlite3VdbeAddOp4Int(v, OP_Filter, pLevel->regFilter, addrNxt, - iRowidReg, 1); - VdbeCoverage(v); - filterPullDown(pParse, pWInfo, iLevel, addrNxt, notReady); - } sqlite3VdbeAddOp3(v, OP_SeekRowid, iCur, addrNxt, iRowidReg); VdbeCoverage(v); pLevel->op = OP_Noop; }else if( (pLoop->wsFlags & WHERE_IPK)!=0 && (pLoop->wsFlags & WHERE_COLUMN_RANGE)!=0 @@ -149484,16 +147562,10 @@ }else{ if( regBignull ){ sqlite3VdbeAddOp2(v, OP_Integer, 1, regBignull); VdbeComment((v, "NULL-scan pass ctr")); } - if( pLevel->regFilter ){ - sqlite3VdbeAddOp4Int(v, OP_Filter, pLevel->regFilter, addrNxt, - regBase, nEq); - VdbeCoverage(v); - filterPullDown(pParse, pWInfo, iLevel, addrNxt, notReady); - } op = aStartOp[(start_constraints<<2) + (startEq<<1) + bRev]; assert( op!=0 ); if( (pLoop->wsFlags & WHERE_IN_SEEKSCAN)!=0 && op==OP_SeekGE ){ assert( regBignull==0 ); @@ -149538,23 +147610,12 @@ /* Load the value for the inequality constraint at the end of the ** range (if any). */ nConstraint = nEq; - assert( pLevel->p2==0 ); if( pRangeEnd ){ Expr *pRight = pRangeEnd->pExpr->pRight; - if( addrSeekScan ){ - /* For a seek-scan that has a range on the lowest term of the index, - ** we have to make the top of the loop be code that sets the end - ** condition of the range. Otherwise, the OP_SeekScan might jump - ** over that initialization, leaving the range-end value set to the - ** range-start value, resulting in a wrong answer. - ** See ticket 5981a8c041a3c2f3 (2021-11-02). - */ - pLevel->p2 = sqlite3VdbeCurrentAddr(v); - } codeExprOrVector(pParse, pRight, regBase+nEq, nTop); whereLikeOptimizationStringFixup(v, pLevel, pRangeEnd); if( (pRangeEnd->wtFlags & TERM_VNULL)==0 && sqlite3ExprCanBeNull(pRight) ){ @@ -149584,11 +147645,11 @@ } sqlite3DbFree(db, zStartAff); sqlite3DbFree(db, zEndAff); /* Top of the loop body */ - if( pLevel->p2==0 ) pLevel->p2 = sqlite3VdbeCurrentAddr(v); + pLevel->p2 = sqlite3VdbeCurrentAddr(v); /* Check if the index cursor is past the end of the range. */ if( nConstraint ){ if( regBignull ){ /* Except, skip the end-of-range check while doing the NULL-scan */ @@ -149817,11 +147878,11 @@ regRowid = ++pParse->nMem; } iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn); /* If the original WHERE clause is z of the form: (x1 OR x2 OR ...) AND y - ** Then for every term xN, evaluate as the subexpression: xN AND y + ** Then for every term xN, evaluate as the subexpression: xN AND z ** That way, terms in y that are factored into the disjunction will ** be picked up by the recursive calls to sqlite3WhereBegin() below. ** ** Actually, each subexpression is converted to "xN AND w" where w is ** the "interesting" terms of z - terms that did not originate in the @@ -149829,38 +147890,21 @@ ** indices. ** ** This optimization also only applies if the (x1 OR x2 OR ...) term ** is not contained in the ON clause of a LEFT JOIN. ** See ticket http://www.sqlite.org/src/info/f2369304e4 - ** - ** 2022-02-04: Do not push down slices of a row-value comparison. - ** In other words, "w" or "y" may not be a slice of a vector. Otherwise, - ** the initialization of the right-hand operand of the vector comparison - ** might not occur, or might occur only in an OR branch that is not - ** taken. dbsqlfuzz 80a9fade844b4fb43564efc972bcb2c68270f5d1. - ** - ** 2022-03-03: Do not push down expressions that involve subqueries. - ** The subquery might get coded as a subroutine. Any table-references - ** in the subquery might be resolved to index-references for the index on - ** the OR branch in which the subroutine is coded. But if the subroutine - ** is invoked from a different OR branch that uses a different index, such - ** index-references will not work. tag-20220303a - ** https://sqlite.org/forum/forumpost/36937b197273d403 */ if( pWC->nTerm>1 ){ int iTerm; for(iTerm=0; iTermnTerm; iTerm++){ Expr *pExpr = pWC->a[iTerm].pExpr; if( &pWC->a[iTerm] == pTerm ) continue; testcase( pWC->a[iTerm].wtFlags & TERM_VIRTUAL ); testcase( pWC->a[iTerm].wtFlags & TERM_CODED ); - testcase( pWC->a[iTerm].wtFlags & TERM_SLICE ); - if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED|TERM_SLICE))!=0 ){ - continue; - } + if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED))!=0 ) continue; if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue; - if( ExprHasProperty(pExpr, EP_Subquery) ) continue; /* tag-20220303a */ + testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO ); pExpr = sqlite3ExprDup(db, pExpr, 0); pAndExpr = sqlite3ExprAnd(pParse, pAndExpr, pExpr); } if( pAndExpr ){ /* The extra 0x10000 bit on the opcode is masked off and does not @@ -149897,13 +147941,13 @@ pOrExpr = pAndExpr; } /* Loop through table entries that match term pOrTerm. */ ExplainQueryPlan((pParse, 1, "INDEX %d", ii+1)); WHERETRACE(0xffff, ("Subplan for OR-clause:\n")); - pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0, 0, + pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0, WHERE_OR_SUBCLAUSE, iCovCur); - assert( pSubWInfo || pParse->nErr ); + assert( pSubWInfo || pParse->nErr || db->mallocFailed ); if( pSubWInfo ){ WhereLoop *pSubLoop; int addrExplain = sqlite3WhereExplainOneScan( pParse, pOrTab, &pSubWInfo->a[0], 0 ); @@ -150008,14 +148052,11 @@ } sqlite3ExprDelete(db, pDelete); } } ExplainQueryPlanPop(pParse); - assert( pLevel->pWLoop==pLoop ); - assert( (pLoop->wsFlags & WHERE_MULTI_OR)!=0 ); - assert( (pLoop->wsFlags & WHERE_IN_ABLE)==0 ); - pLevel->u.pCoveringIdx = pCov; + pLevel->u.pCovidx = pCov; if( pCov ) pLevel->iIdxCur = iCovCur; if( pAndExpr ){ pAndExpr->pLeft = 0; sqlite3ExprDelete(db, pAndExpr); } @@ -150138,11 +148179,11 @@ ** Example: If the WHERE clause contains "t1.a=t2.b" and "t2.b=123" ** and we are coding the t1 loop and the t2 loop has not yet coded, ** then we cannot use the "t1.a=t2.b" constraint, but we can code ** the implied "t1.a=123" constraint. */ - for(pTerm=pWC->a, j=pWC->nBase; j>0; j--, pTerm++){ + for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){ Expr *pE, sEAlt; WhereTerm *pAlt; if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue; if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) continue; if( (pTerm->eOperator & WO_EQUIV)==0 ) continue; @@ -150155,17 +148196,16 @@ sqlite3WhereTermPrint(pTerm, pWC->nTerm-j); } #endif assert( !ExprHasProperty(pE, EP_FromJoin) ); assert( (pTerm->prereqRight & pLevel->notReady)!=0 ); - assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.x.leftColumn, notReady, WO_EQ|WO_IN|WO_IS, 0); if( pAlt==0 ) continue; if( pAlt->wtFlags & (TERM_CODED) ) continue; if( (pAlt->eOperator & WO_IN) - && ExprUseXSelect(pAlt->pExpr) + && (pAlt->pExpr->flags & EP_xIsSelect) && (pAlt->pExpr->x.pSelect->pEList->nExpr>1) ){ continue; } testcase( pAlt->eOperator & WO_EQ ); @@ -150183,11 +148223,11 @@ */ if( pLevel->iLeftJoin ){ pLevel->addrFirst = sqlite3VdbeCurrentAddr(v); sqlite3VdbeAddOp2(v, OP_Integer, 1, pLevel->iLeftJoin); VdbeComment((v, "record LEFT JOIN hit")); - for(pTerm=pWC->a, j=0; jnBase; j++, pTerm++){ + for(pTerm=pWC->a, j=0; jnTerm; j++, pTerm++){ testcase( pTerm->wtFlags & TERM_VIRTUAL ); testcase( pTerm->wtFlags & TERM_CODED ); if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue; if( (pTerm->prereqAll & pLevel->notReady)!=0 ){ assert( pWInfo->untestedTerms ); @@ -150294,11 +148334,10 @@ sqlite3DbFree(db, pOld); } pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]); } pTerm = &pWC->a[idx = pWC->nTerm++]; - if( (wtFlags & TERM_VIRTUAL)==0 ) pWC->nBase = pWC->nTerm; if( p && ExprHasProperty(p, EP_Unlikely) ){ pTerm->truthProb = sqlite3LogEst(p->iTable) - 270; }else{ pTerm->truthProb = 1; } @@ -150411,11 +148450,10 @@ return 0; } #ifdef SQLITE_EBCDIC if( *pnoCase ) return 0; #endif - assert( ExprUseXList(pExpr) ); pList = pExpr->x.pList; pLeft = pList->a[1].pExpr; pRight = sqlite3ExprSkipCollate(pList->a[0].pExpr); op = pRight->op; @@ -150427,12 +148465,11 @@ z = sqlite3_value_text(pVal); } sqlite3VdbeSetVarmask(pParse->pVdbe, iCol); assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER ); }else if( op==TK_STRING ){ - assert( !ExprHasProperty(pRight, EP_IntValue) ); - z = (u8*)pRight->u.zToken; + z = (u8*)pRight->u.zToken; } if( z ){ /* Count the number of prefix characters prior to the first wildcard */ cnt = 0; @@ -150457,13 +148494,11 @@ /* Get the pattern prefix. Remove all escapes from the prefix. */ pPrefix = sqlite3Expr(db, TK_STRING, (char*)z); if( pPrefix ){ int iFrom, iTo; - char *zNew; - assert( !ExprHasProperty(pPrefix, EP_IntValue) ); - zNew = pPrefix->u.zToken; + char *zNew = pPrefix->u.zToken; zNew[cnt] = 0; for(iFrom=iTo=0; iFromop!=TK_COLUMN || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT - || (ALWAYS( ExprUseYTab(pLeft) ) - && pLeft->y.pTab - && IsVirtual(pLeft->y.pTab)) /* Might be numeric */ + || (pLeft->y.pTab && IsVirtual(pLeft->y.pTab)) /* Might be numeric */ ){ int isNum; double rDummy; isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8); if( isNum<=0 ){ @@ -150513,11 +148546,10 @@ /* If the RHS pattern is a bound parameter, make arrangements to ** reprepare the statement when that parameter is rebound */ if( op==TK_VARIABLE ){ Vdbe *v = pParse->pVdbe; sqlite3VdbeSetVarmask(v, pRight->iColumn); - assert( !ExprHasProperty(pRight, EP_IntValue) ); if( *pisComplete && pRight->u.zToken[1] ){ /* If the rhs of the LIKE expression is a variable, and the current ** value of the variable means there is no need to invoke the LIKE ** function, then no OP_Variable will be added to the program. ** This causes problems for the sqlite3_bind_parameter_name() @@ -150587,11 +148619,10 @@ }; ExprList *pList; Expr *pCol; /* Column reference */ int i; - assert( ExprUseXList(pExpr) ); pList = pExpr->x.pList; if( pList==0 || pList->nExpr!=2 ){ return 0; } @@ -150601,15 +148632,13 @@ ** ** vtab_column MATCH expression ** MATCH(expression,vtab_column) */ pCol = pList->a[1].pExpr; - assert( pCol->op!=TK_COLUMN || ExprUseYTab(pCol) ); testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 ); if( ExprIsVtab(pCol) ){ for(i=0; iu.zToken, aOp[i].zOp)==0 ){ *peOp2 = aOp[i].eOp2; *ppRight = pList->a[0].pExpr; *ppLeft = pCol; return 1; @@ -150626,21 +148655,19 @@ ** Historically, xFindFunction expected to see lower-case function ** names. But for this use case, xFindFunction is expected to deal ** with function names in an arbitrary case. */ pCol = pList->a[0].pExpr; - assert( pCol->op!=TK_COLUMN || ExprUseYTab(pCol) ); testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 ); if( ExprIsVtab(pCol) ){ sqlite3_vtab *pVtab; sqlite3_module *pMod; void (*xNotUsed)(sqlite3_context*,int,sqlite3_value**); void *pNotUsed; pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab; assert( pVtab!=0 ); assert( pVtab->pModule!=0 ); - assert( !ExprHasProperty(pExpr, EP_IntValue) ); pMod = (sqlite3_module *)pVtab->pModule; if( pMod->xFindFunction!=0 ){ i = pMod->xFindFunction(pVtab,2, pExpr->u.zToken, &xNotUsed, &pNotUsed); if( i>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){ *peOp2 = i; @@ -150652,16 +148679,14 @@ } }else if( pExpr->op==TK_NE || pExpr->op==TK_ISNOT || pExpr->op==TK_NOTNULL ){ int res = 0; Expr *pLeft = pExpr->pLeft; Expr *pRight = pExpr->pRight; - assert( pLeft->op!=TK_COLUMN || ExprUseYTab(pLeft) ); testcase( pLeft->op==TK_COLUMN && pLeft->y.pTab==0 ); if( ExprIsVtab(pLeft) ){ res++; } - assert( pRight==0 || pRight->op!=TK_COLUMN || ExprUseYTab(pRight) ); testcase( pRight && pRight->op==TK_COLUMN && pRight->y.pTab==0 ); if( pRight && ExprIsVtab(pRight) ){ res++; SWAP(Expr*, pLeft, pRight); } @@ -150681,11 +148706,11 @@ ** a join, then transfer the appropriate markings over to derived. */ static void transferJoinMarkings(Expr *pDerived, Expr *pBase){ if( pDerived ){ pDerived->flags |= pBase->flags & EP_FromJoin; - pDerived->w.iRightJoinTable = pBase->w.iRightJoinTable; + pDerived->iRightJoinTable = pBase->iRightJoinTable; } } /* ** Mark term iChild as being a child of term iParent @@ -150910,11 +148935,10 @@ int j; Bitmask b = 0; pOrTerm->u.pAndInfo = pAndInfo; pOrTerm->wtFlags |= TERM_ANDINFO; pOrTerm->eOperator = WO_AND; - pOrTerm->leftCursor = -1; pAndWC = &pAndInfo->wc; memset(pAndWC->aStatic, 0, sizeof(pAndWC->aStatic)); sqlite3WhereClauseInit(pAndWC, pWC->pWInfo); sqlite3WhereSplit(pAndWC, pOrTerm->pExpr, TK_AND); sqlite3WhereExprAnalyze(pSrc, pAndWC); @@ -150953,14 +148977,15 @@ /* ** Record the set of tables that satisfy case 3. The set might be ** empty. */ pOrInfo->indexable = indexable; - pTerm->eOperator = WO_OR; - pTerm->leftCursor = -1; if( indexable ){ + pTerm->eOperator = WO_OR; pWC->hasOr = 1; + }else{ + pTerm->eOperator = WO_OR; } /* For a two-way OR, attempt to implementation case 2. */ if( indexable && pOrWc->nTerm==2 ){ @@ -151011,11 +149036,11 @@ for(j=0; j<2 && !okToChngToIN; j++){ Expr *pLeft = 0; pOrTerm = pOrWc->a; for(i=pOrWc->nTerm-1; i>=0; i--, pOrTerm++){ assert( pOrTerm->eOperator & WO_EQ ); - pOrTerm->wtFlags &= ~TERM_OK; + pOrTerm->wtFlags &= ~TERM_OR_OK; if( pOrTerm->leftCursor==iCursor ){ /* This is the 2-bit case and we are on the second iteration and ** current term is from the first iteration. So skip this term. */ assert( j==1 ); continue; @@ -151029,11 +149054,10 @@ testcase( pOrTerm->wtFlags & TERM_COPIED ); testcase( pOrTerm->wtFlags & TERM_VIRTUAL ); assert( pOrTerm->wtFlags & (TERM_COPIED|TERM_VIRTUAL) ); continue; } - assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 ); iColumn = pOrTerm->u.x.leftColumn; iCursor = pOrTerm->leftCursor; pLeft = pOrTerm->pExpr->pLeft; break; } @@ -151050,13 +149074,12 @@ /* We have found a candidate table and column. Check to see if that ** table and column is common to every term in the OR clause */ okToChngToIN = 1; for(; i>=0 && okToChngToIN; i--, pOrTerm++){ assert( pOrTerm->eOperator & WO_EQ ); - assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 ); if( pOrTerm->leftCursor!=iCursor ){ - pOrTerm->wtFlags &= ~TERM_OK; + pOrTerm->wtFlags &= ~TERM_OR_OK; }else if( pOrTerm->u.x.leftColumn!=iColumn || (iColumn==XN_EXPR && sqlite3ExprCompare(pParse, pOrTerm->pExpr->pLeft, pLeft, -1) )){ okToChngToIN = 0; }else{ @@ -151068,11 +149091,11 @@ affRight = sqlite3ExprAffinity(pOrTerm->pExpr->pRight); affLeft = sqlite3ExprAffinity(pOrTerm->pExpr->pLeft); if( affRight!=0 && affRight!=affLeft ){ okToChngToIN = 0; }else{ - pOrTerm->wtFlags |= TERM_OK; + pOrTerm->wtFlags |= TERM_OR_OK; } } } } @@ -151085,13 +149108,12 @@ ExprList *pList = 0; /* The RHS of the IN operator */ Expr *pLeft = 0; /* The LHS of the IN operator */ Expr *pNew; /* The complete IN operator */ for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0; i--, pOrTerm++){ - if( (pOrTerm->wtFlags & TERM_OK)==0 ) continue; + if( (pOrTerm->wtFlags & TERM_OR_OK)==0 ) continue; assert( pOrTerm->eOperator & WO_EQ ); - assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 ); assert( pOrTerm->leftCursor==iCursor ); assert( pOrTerm->u.x.leftColumn==iColumn ); pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0); pList = sqlite3ExprListAppend(pWInfo->pParse, pList, pDup); pLeft = pOrTerm->pExpr->pLeft; @@ -151100,11 +149122,11 @@ pDup = sqlite3ExprDup(db, pLeft, 0); pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0); if( pNew ){ int idxNew; transferJoinMarkings(pNew, pExpr); - assert( ExprUseXList(pNew) ); + assert( !ExprHasProperty(pNew, EP_xIsSelect) ); pNew->x.pList = pList; idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC); testcase( idxNew==0 ); exprAnalyze(pSrc, pWC, idxNew); /* pTerm = &pWC->a[idxTerm]; // would be needed if pTerm where reused */ @@ -151228,11 +149250,10 @@ ** on the first element of the vector. */ assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE ); assert( TK_ISop==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){ - assert( ExprUseXList(pExpr) ); pExpr = pExpr->x.pList->a[0].pExpr; } if( pExpr->op==TK_COLUMN ){ @@ -151286,51 +149307,34 @@ int nLeft; /* Number of elements on left side vector */ if( db->mallocFailed ){ return; } - assert( pWC->nTerm > idxTerm ); pTerm = &pWC->a[idxTerm]; pMaskSet = &pWInfo->sMaskSet; pExpr = pTerm->pExpr; - assert( pExpr!=0 ); /* Because malloc() has not failed */ assert( pExpr->op!=TK_AS && pExpr->op!=TK_COLLATE ); - pMaskSet->bVarSelect = 0; prereqLeft = sqlite3WhereExprUsage(pMaskSet, pExpr->pLeft); op = pExpr->op; if( op==TK_IN ){ assert( pExpr->pRight==0 ); if( sqlite3ExprCheckIN(pParse, pExpr) ) return; - if( ExprUseXSelect(pExpr) ){ + if( ExprHasProperty(pExpr, EP_xIsSelect) ){ pTerm->prereqRight = exprSelectUsage(pMaskSet, pExpr->x.pSelect); }else{ pTerm->prereqRight = sqlite3WhereExprListUsage(pMaskSet, pExpr->x.pList); } - prereqAll = prereqLeft | pTerm->prereqRight; + }else if( op==TK_ISNULL ){ + pTerm->prereqRight = 0; }else{ pTerm->prereqRight = sqlite3WhereExprUsage(pMaskSet, pExpr->pRight); - if( pExpr->pLeft==0 - || ExprHasProperty(pExpr, EP_xIsSelect|EP_IfNullRow) - || pExpr->x.pList!=0 - ){ - prereqAll = sqlite3WhereExprUsageNN(pMaskSet, pExpr); - }else{ - prereqAll = prereqLeft | pTerm->prereqRight; - } - } + } + pMaskSet->bVarSelect = 0; + prereqAll = sqlite3WhereExprUsageNN(pMaskSet, pExpr); if( pMaskSet->bVarSelect ) pTerm->wtFlags |= TERM_VARSELECT; - -#ifdef SQLITE_DEBUG - if( prereqAll!=sqlite3WhereExprUsageNN(pMaskSet, pExpr) ){ - printf("\n*** Incorrect prereqAll computed for:\n"); - sqlite3TreeViewExpr(0,pExpr,0); - abort(); - } -#endif - if( ExprHasProperty(pExpr, EP_FromJoin) ){ - Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->w.iRightJoinTable); + Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->iRightJoinTable); prereqAll |= x; extraRight = x-1; /* ON clause terms may not be used with an index ** on left table of a LEFT JOIN. Ticket #3015 */ if( (prereqAll>>1)>=x ){ sqlite3ErrorMsg(pParse, "ON clause references tables to its right"); @@ -151348,17 +149352,15 @@ u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV; if( pTerm->u.x.iField>0 ){ assert( op==TK_IN ); assert( pLeft->op==TK_VECTOR ); - assert( ExprUseXList(pLeft) ); pLeft = pLeft->x.pList->a[pTerm->u.x.iField-1].pExpr; } if( exprMightBeIndexed(pSrc, prereqLeft, aiCurCol, pLeft, op) ){ pTerm->leftCursor = aiCurCol[0]; - assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); pTerm->u.x.leftColumn = aiCurCol[1]; pTerm->eOperator = operatorMask(op) & opMask; } if( op==TK_IS ) pTerm->wtFlags |= TERM_IS; if( pRight @@ -151392,11 +149394,10 @@ pDup = pExpr; pNew = pTerm; } pNew->wtFlags |= exprCommute(pParse, pDup); pNew->leftCursor = aiCurCol[0]; - assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); pNew->u.x.leftColumn = aiCurCol[1]; testcase( (prereqLeft | extraRight) != prereqLeft ); pNew->prereqRight = prereqLeft | extraRight; pNew->prereqAll = prereqAll; pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask; @@ -151403,11 +149404,10 @@ }else if( op==TK_ISNULL && !ExprHasProperty(pExpr,EP_FromJoin) && 0==sqlite3ExprCanBeNull(pLeft) ){ - assert( !ExprHasProperty(pExpr, EP_IntValue) ); pExpr->op = TK_TRUEFALSE; pExpr->u.zToken = "false"; ExprSetProperty(pExpr, EP_IsFalse); pTerm->prereqAll = 0; pTerm->eOperator = 0; @@ -151429,15 +149429,13 @@ ** term. That means that if the BETWEEN term is coded, the children are ** skipped. Or, if the children are satisfied by an index, the original ** BETWEEN term is skipped. */ else if( pExpr->op==TK_BETWEEN && pWC->op==TK_AND ){ - ExprList *pList; + ExprList *pList = pExpr->x.pList; int i; static const u8 ops[] = {TK_GE, TK_LE}; - assert( ExprUseXList(pExpr) ); - pList = pExpr->x.pList; assert( pList!=0 ); assert( pList->nExpr==2 ); for(i=0; i<2; i++){ Expr *pNewExpr; int idxNew; @@ -151526,16 +149524,12 @@ int idxNew1; int idxNew2; const char *zCollSeqName; /* Name of collating sequence */ const u16 wtFlags = TERM_LIKEOPT | TERM_VIRTUAL | TERM_DYNAMIC; - assert( ExprUseXList(pExpr) ); pLeft = pExpr->x.pList->a[1].pExpr; pStr2 = sqlite3ExprDup(db, pStr1, 0); - assert( pStr1==0 || !ExprHasProperty(pStr1, EP_IntValue) ); - assert( pStr2==0 || !ExprHasProperty(pStr2, EP_IntValue) ); - /* Convert the lower bound to upper-case and the upper bound to ** lower-case (upper-case is less than lower-case in ASCII) so that ** the range constraints also work for BLOBs */ @@ -151594,14 +149588,11 @@ ** new terms for each component comparison - "a = ?" and "b = ?". The ** new terms completely replace the original vector comparison, which is ** no longer used. ** ** This is only required if at least one side of the comparison operation - ** is not a sub-select. - ** - ** tag-20220128a - */ + ** is not a sub-select. */ if( (pExpr->op==TK_EQ || pExpr->op==TK_IS) && (nLeft = sqlite3ExprVectorSize(pExpr->pLeft))>1 && sqlite3ExprVectorSize(pExpr->pRight)==nLeft && ( (pExpr->pLeft->flags & EP_xIsSelect)==0 || (pExpr->pRight->flags & EP_xIsSelect)==0) @@ -151614,11 +149605,11 @@ Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i, nLeft); Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i, nLeft); pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight); transferJoinMarkings(pNew, pExpr); - idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC|TERM_SLICE); + idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC); exprAnalyze(pSrc, pWC, idxNew); } pTerm = &pWC->a[idxTerm]; pTerm->wtFlags |= TERM_CODED|TERM_VIRTUAL; /* Disable the original */ pTerm->eOperator = 0; @@ -151634,21 +149625,20 @@ ** not use window functions. */ else if( pExpr->op==TK_IN && pTerm->u.x.iField==0 && pExpr->pLeft->op==TK_VECTOR - && ALWAYS( ExprUseXSelect(pExpr) ) && pExpr->x.pSelect->pPrior==0 #ifndef SQLITE_OMIT_WINDOWFUNC && pExpr->x.pSelect->pWin==0 #endif && pWC->op==TK_AND ){ int i; for(i=0; ipLeft); i++){ int idxNew; - idxNew = whereClauseInsert(pWC, pExpr, TERM_VIRTUAL|TERM_SLICE); + idxNew = whereClauseInsert(pWC, pExpr, TERM_VIRTUAL); pWC->a[idxNew].u.x.iField = i+1; exprAnalyze(pSrc, pWC, idxNew); markTermAsChild(pWC, idxNew, idxTerm); } } @@ -151677,11 +149667,11 @@ Expr *pNewExpr; pNewExpr = sqlite3PExpr(pParse, TK_MATCH, 0, sqlite3ExprDup(db, pRight, 0)); if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){ ExprSetProperty(pNewExpr, EP_FromJoin); - pNewExpr->w.iRightJoinTable = pExpr->w.iRightJoinTable; + pNewExpr->iRightJoinTable = pExpr->iRightJoinTable; } idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC); testcase( idxNew==0 ); pNewTerm = &pWC->a[idxNew]; pNewTerm->prereqRight = prereqExpr; @@ -151740,117 +149730,10 @@ sqlite3WhereSplit(pWC, pE2->pLeft, op); sqlite3WhereSplit(pWC, pE2->pRight, op); } } -/* -** Add either a LIMIT (if eMatchOp==SQLITE_INDEX_CONSTRAINT_LIMIT) or -** OFFSET (if eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET) term to the -** where-clause passed as the first argument. The value for the term -** is found in register iReg. -** -** In the common case where the value is a simple integer -** (example: "LIMIT 5 OFFSET 10") then the expression codes as a -** TK_INTEGER so that it will be available to sqlite3_vtab_rhs_value(). -** If not, then it codes as a TK_REGISTER expression. -*/ -static void whereAddLimitExpr( - WhereClause *pWC, /* Add the constraint to this WHERE clause */ - int iReg, /* Register that will hold value of the limit/offset */ - Expr *pExpr, /* Expression that defines the limit/offset */ - int iCsr, /* Cursor to which the constraint applies */ - int eMatchOp /* SQLITE_INDEX_CONSTRAINT_LIMIT or _OFFSET */ -){ - Parse *pParse = pWC->pWInfo->pParse; - sqlite3 *db = pParse->db; - Expr *pNew; - int iVal = 0; - - if( sqlite3ExprIsInteger(pExpr, &iVal) && iVal>=0 ){ - Expr *pVal = sqlite3Expr(db, TK_INTEGER, 0); - if( pVal==0 ) return; - ExprSetProperty(pVal, EP_IntValue); - pVal->u.iValue = iVal; - pNew = sqlite3PExpr(pParse, TK_MATCH, 0, pVal); - }else{ - Expr *pVal = sqlite3Expr(db, TK_REGISTER, 0); - if( pVal==0 ) return; - pVal->iTable = iReg; - pNew = sqlite3PExpr(pParse, TK_MATCH, 0, pVal); - } - if( pNew ){ - WhereTerm *pTerm; - int idx; - idx = whereClauseInsert(pWC, pNew, TERM_DYNAMIC|TERM_VIRTUAL); - pTerm = &pWC->a[idx]; - pTerm->leftCursor = iCsr; - pTerm->eOperator = WO_AUX; - pTerm->eMatchOp = eMatchOp; - } -} - -/* -** Possibly add terms corresponding to the LIMIT and OFFSET clauses of the -** SELECT statement passed as the second argument. These terms are only -** added if: -** -** 1. The SELECT statement has a LIMIT clause, and -** 2. The SELECT statement is not an aggregate or DISTINCT query, and -** 3. The SELECT statement has exactly one object in its from clause, and -** that object is a virtual table, and -** 4. There are no terms in the WHERE clause that will not be passed -** to the virtual table xBestIndex method. -** 5. The ORDER BY clause, if any, will be made available to the xBestIndex -** method. -** -** LIMIT and OFFSET terms are ignored by most of the planner code. They -** exist only so that they may be passed to the xBestIndex method of the -** single virtual table in the FROM clause of the SELECT. -*/ -SQLITE_PRIVATE void sqlite3WhereAddLimit(WhereClause *pWC, Select *p){ - assert( p==0 || (p->pGroupBy==0 && (p->selFlags & SF_Aggregate)==0) ); - if( (p && p->pLimit) /* 1 */ - && (p->selFlags & (SF_Distinct|SF_Aggregate))==0 /* 2 */ - && (p->pSrc->nSrc==1 && IsVirtual(p->pSrc->a[0].pTab)) /* 3 */ - ){ - ExprList *pOrderBy = p->pOrderBy; - int iCsr = p->pSrc->a[0].iCursor; - int ii; - - /* Check condition (4). Return early if it is not met. */ - for(ii=0; iinTerm; ii++){ - if( pWC->a[ii].wtFlags & TERM_CODED ){ - /* This term is a vector operation that has been decomposed into - ** other, subsequent terms. It can be ignored. See tag-20220128a */ - assert( pWC->a[ii].wtFlags & TERM_VIRTUAL ); - assert( pWC->a[ii].eOperator==0 ); - continue; - } - if( pWC->a[ii].leftCursor!=iCsr ) return; - } - - /* Check condition (5). Return early if it is not met. */ - if( pOrderBy ){ - for(ii=0; iinExpr; ii++){ - Expr *pExpr = pOrderBy->a[ii].pExpr; - if( pExpr->op!=TK_COLUMN ) return; - if( pExpr->iTable!=iCsr ) return; - if( pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_BIGNULL ) return; - } - } - - /* All conditions are met. Add the terms to the where-clause object. */ - assert( p->pLimit->op==TK_LIMIT ); - whereAddLimitExpr(pWC, p->iLimit, p->pLimit->pLeft, - iCsr, SQLITE_INDEX_CONSTRAINT_LIMIT); - if( p->iOffset>0 ){ - whereAddLimitExpr(pWC, p->iOffset, p->pLimit->pRight, - iCsr, SQLITE_INDEX_CONSTRAINT_OFFSET); - } - } -} - /* ** Initialize a preallocated WhereClause structure. */ SQLITE_PRIVATE void sqlite3WhereClauseInit( WhereClause *pWC, /* The WhereClause to be initialized */ @@ -151858,11 +149741,10 @@ ){ pWC->pWInfo = pWInfo; pWC->hasOr = 0; pWC->pOuter = 0; pWC->nTerm = 0; - pWC->nBase = 0; pWC->nSlot = ArraySize(pWC->aStatic); pWC->a = pWC->aStatic; } /* @@ -151869,38 +149751,21 @@ ** Deallocate a WhereClause structure. The WhereClause structure ** itself is not freed. This routine is the inverse of ** sqlite3WhereClauseInit(). */ SQLITE_PRIVATE void sqlite3WhereClauseClear(WhereClause *pWC){ + int i; + WhereTerm *a; sqlite3 *db = pWC->pWInfo->pParse->db; - assert( pWC->nTerm>=pWC->nBase ); - if( pWC->nTerm>0 ){ - WhereTerm *a = pWC->a; - WhereTerm *aLast = &pWC->a[pWC->nTerm-1]; -#ifdef SQLITE_DEBUG - int i; - /* Verify that every term past pWC->nBase is virtual */ - for(i=pWC->nBase; inTerm; i++){ - assert( (pWC->a[i].wtFlags & TERM_VIRTUAL)!=0 ); - } -#endif - while(1){ - assert( a->eMatchOp==0 || a->eOperator==WO_AUX ); - if( a->wtFlags & TERM_DYNAMIC ){ - sqlite3ExprDelete(db, a->pExpr); - } - if( a->wtFlags & (TERM_ORINFO|TERM_ANDINFO) ){ - if( a->wtFlags & TERM_ORINFO ){ - assert( (a->wtFlags & TERM_ANDINFO)==0 ); - whereOrInfoDelete(db, a->u.pOrInfo); - }else{ - assert( (a->wtFlags & TERM_ANDINFO)!=0 ); - whereAndInfoDelete(db, a->u.pAndInfo); - } - } - if( a==aLast ) break; - a++; + for(i=pWC->nTerm-1, a=pWC->a; i>=0; i--, a++){ + if( a->wtFlags & TERM_DYNAMIC ){ + sqlite3ExprDelete(db, a->pExpr); + } + if( a->wtFlags & TERM_ORINFO ){ + whereOrInfoDelete(db, a->u.pOrInfo); + }else if( a->wtFlags & TERM_ANDINFO ){ + whereAndInfoDelete(db, a->u.pAndInfo); } } if( pWC->a!=pWC->aStatic ){ sqlite3DbFree(db, pWC->a); } @@ -151909,72 +149774,39 @@ /* ** These routines walk (recursively) an expression tree and generate ** a bitmask indicating which tables are used in that expression ** tree. -** -** sqlite3WhereExprUsage(MaskSet, Expr) -> -** -** Return a Bitmask of all tables referenced by Expr. Expr can be -** be NULL, in which case 0 is returned. -** -** sqlite3WhereExprUsageNN(MaskSet, Expr) -> -** -** Same as sqlite3WhereExprUsage() except that Expr must not be -** NULL. The "NN" suffix on the name stands for "Not Null". -** -** sqlite3WhereExprListUsage(MaskSet, ExprList) -> -** -** Return a Bitmask of all tables referenced by every expression -** in the expression list ExprList. ExprList can be NULL, in which -** case 0 is returned. -** -** sqlite3WhereExprUsageFull(MaskSet, ExprList) -> -** -** Internal use only. Called only by sqlite3WhereExprUsageNN() for -** complex expressions that require pushing register values onto -** the stack. Many calls to sqlite3WhereExprUsageNN() do not need -** the more complex analysis done by this routine. Hence, the -** computations done by this routine are broken out into a separate -** "no-inline" function to avoid the stack push overhead in the -** common case where it is not needed. */ -static SQLITE_NOINLINE Bitmask sqlite3WhereExprUsageFull( - WhereMaskSet *pMaskSet, - Expr *p -){ +SQLITE_PRIVATE Bitmask sqlite3WhereExprUsageNN(WhereMaskSet *pMaskSet, Expr *p){ Bitmask mask; + if( p->op==TK_COLUMN && !ExprHasProperty(p, EP_FixedCol) ){ + return sqlite3WhereGetMask(pMaskSet, p->iTable); + }else if( ExprHasProperty(p, EP_TokenOnly|EP_Leaf) ){ + assert( p->op!=TK_IF_NULL_ROW ); + return 0; + } mask = (p->op==TK_IF_NULL_ROW) ? sqlite3WhereGetMask(pMaskSet, p->iTable) : 0; if( p->pLeft ) mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pLeft); if( p->pRight ){ mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pRight); assert( p->x.pList==0 ); - }else if( ExprUseXSelect(p) ){ + }else if( ExprHasProperty(p, EP_xIsSelect) ){ if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1; mask |= exprSelectUsage(pMaskSet, p->x.pSelect); }else if( p->x.pList ){ mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList); } #ifndef SQLITE_OMIT_WINDOWFUNC - if( (p->op==TK_FUNCTION || p->op==TK_AGG_FUNCTION) && ExprUseYWin(p) ){ - assert( p->y.pWin!=0 ); + if( (p->op==TK_FUNCTION || p->op==TK_AGG_FUNCTION) && p->y.pWin ){ mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition); mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy); mask |= sqlite3WhereExprUsage(pMaskSet, p->y.pWin->pFilter); } #endif return mask; } -SQLITE_PRIVATE Bitmask sqlite3WhereExprUsageNN(WhereMaskSet *pMaskSet, Expr *p){ - if( p->op==TK_COLUMN && !ExprHasProperty(p, EP_FixedCol) ){ - return sqlite3WhereGetMask(pMaskSet, p->iTable); - }else if( ExprHasProperty(p, EP_TokenOnly|EP_Leaf) ){ - assert( p->op!=TK_IF_NULL_ROW ); - return 0; - } - return sqlite3WhereExprUsageFull(pMaskSet, p); -} SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){ return p ? sqlite3WhereExprUsageNN(pMaskSet,p) : 0; } SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet *pMaskSet, ExprList *pList){ int i; @@ -152038,13 +149870,11 @@ } pColRef = sqlite3ExprAlloc(pParse->db, TK_COLUMN, 0, 0); if( pColRef==0 ) return; pColRef->iTable = pItem->iCursor; pColRef->iColumn = k++; - assert( ExprUseYTab(pColRef) ); pColRef->y.pTab = pTab; - pItem->colUsed |= sqlite3ExprColUsed(pColRef); pRhs = sqlite3PExpr(pParse, TK_UPLUS, sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0); pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs); if( pItem->fg.jointype & JT_LEFT ){ sqlite3SetJoinExpr(pTerm, pItem->iCursor); @@ -152085,18 +149915,12 @@ ** next. As long as allocateIndexInfo() and sqlite3_vtab_collation() ** agree on the structure, all will be well. */ typedef struct HiddenIndexInfo HiddenIndexInfo; struct HiddenIndexInfo { - WhereClause *pWC; /* The Where clause being analyzed */ - Parse *pParse; /* The parsing context */ - int eDistinct; /* Value to return from sqlite3_vtab_distinct() */ - u32 mIn; /* Mask of terms that are IN (...) */ - u32 mHandleIn; /* Terms that vtab will handle as IN (...) */ - sqlite3_value *aRhs[1]; /* RHS values for constraints. MUST BE LAST - ** because extra space is allocated to hold up - ** to nTerm such values */ + WhereClause *pWC; /* The Where clause being analyzed */ + Parse *pParse; /* The parsing context */ }; /* Forward declaration of methods */ static int whereLoopResize(sqlite3*, WhereLoop*, int); @@ -152295,16 +150119,11 @@ ** iCursor is not in the set. */ SQLITE_PRIVATE Bitmask sqlite3WhereGetMask(WhereMaskSet *pMaskSet, int iCursor){ int i; assert( pMaskSet->n<=(int)sizeof(Bitmask)*8 ); - assert( pMaskSet->n>0 || pMaskSet->ix[0]<0 ); - assert( iCursor>=-1 ); - if( pMaskSet->ix[0]==iCursor ){ - return 1; - } - for(i=1; in; i++){ + for(i=0; in; i++){ if( pMaskSet->ix[i]==iCursor ){ return MASKBIT(i); } } return 0; @@ -152352,14 +150171,12 @@ pWC = pScan->pWC; while(1){ iColumn = pScan->aiColumn[pScan->iEquiv-1]; iCur = pScan->aiCur[pScan->iEquiv-1]; assert( pWC!=0 ); - assert( iCur>=0 ); do{ for(pTerm=pWC->a+k; knTerm; k++, pTerm++){ - assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 || pTerm->leftCursor<0 ); if( pTerm->leftCursor==iCur && pTerm->u.x.leftColumn==iColumn && (iColumn!=XN_EXPR || sqlite3ExprCompareSkip(pTerm->pExpr->pLeft, pScan->pIdxExpr,iCur)==0) @@ -152397,12 +150214,11 @@ if( sqlite3StrICmp(pColl->zName, pScan->zCollName) ){ continue; } } if( (pTerm->eOperator & (WO_EQ|WO_IS))!=0 - && (pX = pTerm->pExpr->pRight, ALWAYS(pX!=0)) - && pX->op==TK_COLUMN + && (pX = pTerm->pExpr->pRight)->op==TK_COLUMN && pX->iTable==pScan->aiCur[0] && pX->iColumn==pScan->aiColumn[0] ){ testcase( pTerm->eOperator & WO_IS ); continue; @@ -152485,20 +150301,20 @@ pScan->nEquiv = 1; pScan->iEquiv = 1; if( pIdx ){ int j = iColumn; iColumn = pIdx->aiColumn[j]; - if( iColumn==pIdx->pTable->iPKey ){ + if( iColumn==XN_EXPR ){ + pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr; + pScan->zCollName = pIdx->azColl[j]; + pScan->aiColumn[0] = XN_EXPR; + return whereScanInitIndexExpr(pScan); + }else if( iColumn==pIdx->pTable->iPKey ){ iColumn = XN_ROWID; }else if( iColumn>=0 ){ pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity; pScan->zCollName = pIdx->azColl[j]; - }else if( iColumn==XN_EXPR ){ - pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr; - pScan->zCollName = pIdx->azColl[j]; - pScan->aiColumn[0] = XN_EXPR; - return whereScanInitIndexExpr(pScan); } }else if( iColumn==XN_EXPR ){ return 0; } pScan->aiColumn[0] = iColumn; @@ -152737,18 +150553,16 @@ #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(WHERETRACE_ENABLED) static void whereTraceIndexInfoInputs(sqlite3_index_info *p){ int i; if( !sqlite3WhereTrace ) return; for(i=0; inConstraint; i++){ - sqlite3DebugPrintf( - " constraint[%d]: col=%d termid=%d op=%d usabled=%d collseq=%s\n", + sqlite3DebugPrintf(" constraint[%d]: col=%d termid=%d op=%d usabled=%d\n", i, p->aConstraint[i].iColumn, p->aConstraint[i].iTermOffset, p->aConstraint[i].op, - p->aConstraint[i].usable, - sqlite3_vtab_collation(p,i)); + p->aConstraint[i].usable); } for(i=0; inOrderBy; i++){ sqlite3DebugPrintf(" orderby[%d]: col=%d desc=%d\n", i, p->aOrderBy[i].iColumn, @@ -152780,13 +150594,13 @@ ** Return TRUE if the WHERE clause term pTerm is of a form where it ** could be used with an index to access pSrc, assuming an appropriate ** index existed. */ static int termCanDriveIndex( - const WhereTerm *pTerm, /* WHERE clause term to check */ - const SrcItem *pSrc, /* Table we are trying to access */ - const Bitmask notReady /* Tables in outer loops of the join */ + WhereTerm *pTerm, /* WHERE clause term to check */ + SrcItem *pSrc, /* Table we are trying to access */ + Bitmask notReady /* Tables in outer loops of the join */ ){ char aff; if( pTerm->leftCursor!=pSrc->iCursor ) return 0; if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) return 0; if( (pSrc->fg.jointype & JT_LEFT) @@ -152797,11 +150611,10 @@ ** the RHS of a LEFT JOIN. Such a term can only be used if it is from ** the ON clause. */ return 0; } if( (pTerm->prereqRight & notReady)!=0 ) return 0; - assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); if( pTerm->u.x.leftColumn<0 ) return 0; aff = pSrc->pTab->aCol[pTerm->u.x.leftColumn].affinity; if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0; testcase( pTerm->pExpr->op==TK_IS ); return 1; @@ -152813,15 +150626,15 @@ /* ** Generate code to construct the Index object for an automatic index ** and to set up the WhereLevel object pLevel so that the code generator ** makes use of the automatic index. */ -static SQLITE_NOINLINE void constructAutomaticIndex( +static void constructAutomaticIndex( Parse *pParse, /* The parsing context */ - const WhereClause *pWC, /* The WHERE clause */ - const SrcItem *pSrc, /* The FROM clause term to get the next index */ - const Bitmask notReady, /* Mask of cursors that are not available */ + WhereClause *pWC, /* The WHERE clause */ + SrcItem *pSrc, /* The FROM clause term to get the next index */ + Bitmask notReady, /* Mask of cursors that are not available */ WhereLevel *pLevel /* Write new index here */ ){ int nKeyCol; /* Number of columns in the constructed index */ WhereTerm *pTerm; /* A single term of the WHERE clause */ WhereTerm *pWCEnd; /* End of pWC->a[] */ @@ -152859,25 +150672,23 @@ pWCEnd = &pWC->a[pWC->nTerm]; pLoop = pLevel->pWLoop; idxCols = 0; for(pTerm=pWC->a; pTermpExpr; - /* Make the automatic index a partial index if there are terms in the - ** WHERE clause (or the ON clause of a LEFT join) that constrain which - ** rows of the target table (pSrc) that can be used. */ - if( (pTerm->wtFlags & TERM_VIRTUAL)==0 - && sqlite3ExprIsTableConstraint(pExpr, pSrc) - ){ + assert( !ExprHasProperty(pExpr, EP_FromJoin) /* prereq always non-zero */ + || pExpr->iRightJoinTable!=pSrc->iCursor /* for the right-hand */ + || pLoop->prereq!=0 ); /* table of a LEFT JOIN */ + if( pLoop->prereq==0 + && (pTerm->wtFlags & TERM_VIRTUAL)==0 + && !ExprHasProperty(pExpr, EP_FromJoin) + && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor) ){ pPartial = sqlite3ExprAnd(pParse, pPartial, sqlite3ExprDup(pParse->db, pExpr, 0)); } if( termCanDriveIndex(pTerm, pSrc, notReady) ){ - int iCol; - Bitmask cMask; - assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); - iCol = pTerm->u.x.leftColumn; - cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol); + int iCol = pTerm->u.x.leftColumn; + Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol); testcase( iCol==BMS ); testcase( iCol==BMS-1 ); if( !sentWarning ){ sqlite3_log(SQLITE_WARNING_AUTOINDEX, "automatic index on %s(%s)", pTable->zName, @@ -152925,15 +150736,12 @@ pIdx->pTable = pTable; n = 0; idxCols = 0; for(pTerm=pWC->a; pTermeOperator & (WO_OR|WO_AND))==0 ); - iCol = pTerm->u.x.leftColumn; - cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol); + int iCol = pTerm->u.x.leftColumn; + Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol); testcase( iCol==BMS-1 ); testcase( iCol==BMS ); if( (idxCols & cMask)==0 ){ Expr *pX = pTerm->pExpr; idxCols |= cMask; @@ -152971,14 +150779,10 @@ assert( pLevel->iIdxCur>=0 ); pLevel->iIdxCur = pParse->nTab++; sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1); sqlite3VdbeSetP4KeyInfo(pParse, pIdx); VdbeComment((v, "for %s", pTable->zName)); - if( OptimizationEnabled(pParse->db, SQLITE_BloomFilter) ){ - pLevel->regFilter = ++pParse->nMem; - sqlite3VdbeAddOp2(v, OP_Blob, 10000, pLevel->regFilter); - } /* Fill the automatic index with content */ pTabItem = &pWC->pWInfo->pTabList->a[pLevel->iFrom]; if( pTabItem->fg.viaCoroutine ){ int regYield = pTabItem->regReturn; @@ -152997,14 +150801,10 @@ } regRecord = sqlite3GetTempReg(pParse); regBase = sqlite3GenerateIndexKey( pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0 ); - if( pLevel->regFilter ){ - sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0, - regBase, pLoop->u.btree.nEq); - } sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord); sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue); if( pTabItem->fg.viaCoroutine ){ sqlite3VdbeChangeP2(v, addrCounter, regBase+n); @@ -153026,201 +150826,50 @@ end_auto_index_create: sqlite3ExprDelete(pParse->db, pPartial); } #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */ - -/* -** Generate bytecode that will initialize a Bloom filter that is appropriate -** for pLevel. -** -** If there are inner loops within pLevel that have the WHERE_BLOOMFILTER -** flag set, initialize a Bloomfilter for them as well. Except don't do -** this recursive initialization if the SQLITE_BloomPulldown optimization has -** been turned off. -** -** When the Bloom filter is initialized, the WHERE_BLOOMFILTER flag is cleared -** from the loop, but the regFilter value is set to a register that implements -** the Bloom filter. When regFilter is positive, the -** sqlite3WhereCodeOneLoopStart() will generate code to test the Bloom filter -** and skip the subsequence B-Tree seek if the Bloom filter indicates that -** no matching rows exist. -** -** This routine may only be called if it has previously been determined that -** the loop would benefit from a Bloom filter, and the WHERE_BLOOMFILTER bit -** is set. -*/ -static SQLITE_NOINLINE void sqlite3ConstructBloomFilter( - WhereInfo *pWInfo, /* The WHERE clause */ - int iLevel, /* Index in pWInfo->a[] that is pLevel */ - WhereLevel *pLevel, /* Make a Bloom filter for this FROM term */ - Bitmask notReady /* Loops that are not ready */ -){ - int addrOnce; /* Address of opening OP_Once */ - int addrTop; /* Address of OP_Rewind */ - int addrCont; /* Jump here to skip a row */ - const WhereTerm *pTerm; /* For looping over WHERE clause terms */ - const WhereTerm *pWCEnd; /* Last WHERE clause term */ - Parse *pParse = pWInfo->pParse; /* Parsing context */ - Vdbe *v = pParse->pVdbe; /* VDBE under construction */ - WhereLoop *pLoop = pLevel->pWLoop; /* The loop being coded */ - int iCur; /* Cursor for table getting the filter */ - - assert( pLoop!=0 ); - assert( v!=0 ); - assert( pLoop->wsFlags & WHERE_BLOOMFILTER ); - - addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v); - do{ - const SrcItem *pItem; - const Table *pTab; - u64 sz; - sqlite3WhereExplainBloomFilter(pParse, pWInfo, pLevel); - addrCont = sqlite3VdbeMakeLabel(pParse); - iCur = pLevel->iTabCur; - pLevel->regFilter = ++pParse->nMem; - - /* The Bloom filter is a Blob held in a register. Initialize it - ** to zero-filled blob of at least 80K bits, but maybe more if the - ** estimated size of the table is larger. We could actually - ** measure the size of the table at run-time using OP_Count with - ** P3==1 and use that value to initialize the blob. But that makes - ** testing complicated. By basing the blob size on the value in the - ** sqlite_stat1 table, testing is much easier. - */ - pItem = &pWInfo->pTabList->a[pLevel->iFrom]; - assert( pItem!=0 ); - pTab = pItem->pTab; - assert( pTab!=0 ); - sz = sqlite3LogEstToInt(pTab->nRowLogEst); - if( sz<10000 ){ - sz = 10000; - }else if( sz>10000000 ){ - sz = 10000000; - } - sqlite3VdbeAddOp2(v, OP_Blob, (int)sz, pLevel->regFilter); - - addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v); - pWCEnd = &pWInfo->sWC.a[pWInfo->sWC.nTerm]; - for(pTerm=pWInfo->sWC.a; pTermpExpr; - if( (pTerm->wtFlags & TERM_VIRTUAL)==0 - && sqlite3ExprIsTableConstraint(pExpr, pItem) - ){ - sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL); - } - } - if( pLoop->wsFlags & WHERE_IPK ){ - int r1 = sqlite3GetTempReg(pParse); - sqlite3VdbeAddOp2(v, OP_Rowid, iCur, r1); - sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0, r1, 1); - sqlite3ReleaseTempReg(pParse, r1); - }else{ - Index *pIdx = pLoop->u.btree.pIndex; - int n = pLoop->u.btree.nEq; - int r1 = sqlite3GetTempRange(pParse, n); - int jj; - for(jj=0; jjaiColumn[jj]; - assert( pIdx->pTable==pItem->pTab ); - sqlite3ExprCodeGetColumnOfTable(v, pIdx->pTable, iCur, iCol,r1+jj); - } - sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0, r1, n); - sqlite3ReleaseTempRange(pParse, r1, n); - } - sqlite3VdbeResolveLabel(v, addrCont); - sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); - VdbeCoverage(v); - sqlite3VdbeJumpHere(v, addrTop); - pLoop->wsFlags &= ~WHERE_BLOOMFILTER; - if( OptimizationDisabled(pParse->db, SQLITE_BloomPulldown) ) break; - while( ++iLevel < pWInfo->nLevel ){ - const SrcItem *pTabItem; - pLevel = &pWInfo->a[iLevel]; - pTabItem = &pWInfo->pTabList->a[pLevel->iFrom]; - if( pTabItem->fg.jointype & JT_LEFT ) continue; - pLoop = pLevel->pWLoop; - if( NEVER(pLoop==0) ) continue; - if( pLoop->prereq & notReady ) continue; - if( (pLoop->wsFlags & (WHERE_BLOOMFILTER|WHERE_COLUMN_IN)) - ==WHERE_BLOOMFILTER - ){ - /* This is a candidate for bloom-filter pull-down (early evaluation). - ** The test that WHERE_COLUMN_IN is omitted is important, as we are - ** not able to do early evaluation of bloom filters that make use of - ** the IN operator */ - break; - } - } - }while( iLevel < pWInfo->nLevel ); - sqlite3VdbeJumpHere(v, addrOnce); -} - #ifndef SQLITE_OMIT_VIRTUALTABLE /* ** Allocate and populate an sqlite3_index_info structure. It is the ** responsibility of the caller to eventually release the structure -** by passing the pointer returned by this function to freeIndexInfo(). +** by passing the pointer returned by this function to sqlite3_free(). */ static sqlite3_index_info *allocateIndexInfo( - WhereInfo *pWInfo, /* The WHERE clause */ + Parse *pParse, /* The parsing context */ WhereClause *pWC, /* The WHERE clause being analyzed */ Bitmask mUnusable, /* Ignore terms with these prereqs */ SrcItem *pSrc, /* The FROM clause term that is the vtab */ + ExprList *pOrderBy, /* The ORDER BY clause */ u16 *pmNoOmit /* Mask of terms not to omit */ ){ int i, j; int nTerm; - Parse *pParse = pWInfo->pParse; struct sqlite3_index_constraint *pIdxCons; struct sqlite3_index_orderby *pIdxOrderBy; struct sqlite3_index_constraint_usage *pUsage; struct HiddenIndexInfo *pHidden; WhereTerm *pTerm; int nOrderBy; sqlite3_index_info *pIdxInfo; u16 mNoOmit = 0; - const Table *pTab; - int eDistinct = 0; - ExprList *pOrderBy = pWInfo->pOrderBy; - - assert( pSrc!=0 ); - pTab = pSrc->pTab; - assert( pTab!=0 ); - assert( IsVirtual(pTab) ); - - /* Find all WHERE clause constraints referring to this virtual table. - ** Mark each term with the TERM_OK flag. Set nTerm to the number of - ** terms found. - */ - for(i=nTerm=0, pTerm=pWC->a; inTerm; i++, pTerm++){ - pTerm->wtFlags &= ~TERM_OK; + + /* Count the number of possible WHERE clause constraints referring + ** to this virtual table */ + for(i=nTerm=0, pTerm=pWC->a; inTerm; i++, pTerm++){ if( pTerm->leftCursor != pSrc->iCursor ) continue; if( pTerm->prereqRight & mUnusable ) continue; assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) ); testcase( pTerm->eOperator & WO_IN ); testcase( pTerm->eOperator & WO_ISNULL ); testcase( pTerm->eOperator & WO_IS ); testcase( pTerm->eOperator & WO_ALL ); if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue; if( pTerm->wtFlags & TERM_VNULL ) continue; - - assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); - assert( pTerm->u.x.leftColumn>=XN_ROWID ); - assert( pTerm->u.x.leftColumnnCol ); - - /* tag-20191211-002: WHERE-clause constraints are not useful to the - ** right-hand table of a LEFT JOIN. See tag-20191211-001 for the - ** equivalent restriction for ordinary tables. */ - if( (pSrc->fg.jointype & JT_LEFT)!=0 - && !ExprHasProperty(pTerm->pExpr, EP_FromJoin) - ){ - continue; - } + assert( pTerm->u.x.leftColumn>=(-1) ); nTerm++; - pTerm->wtFlags |= TERM_OK; } /* If the ORDER BY clause contains only columns in the current ** virtual table then allocate space for the aOrderBy part of ** the sqlite3_index_info structure. @@ -153228,87 +150877,62 @@ nOrderBy = 0; if( pOrderBy ){ int n = pOrderBy->nExpr; for(i=0; ia[i].pExpr; - Expr *pE2; - - /* Skip over constant terms in the ORDER BY clause */ - if( sqlite3ExprIsConstant(pExpr) ){ - continue; - } - - /* Virtual tables are unable to deal with NULLS FIRST */ + if( pExpr->op!=TK_COLUMN || pExpr->iTable!=pSrc->iCursor ) break; if( pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL ) break; - - /* First case - a direct column references without a COLLATE operator */ - if( pExpr->op==TK_COLUMN && pExpr->iTable==pSrc->iCursor ){ - assert( pExpr->iColumn>=XN_ROWID && pExpr->iColumnnCol ); - continue; - } - - /* 2nd case - a column reference with a COLLATE operator. Only match - ** of the COLLATE operator matches the collation of the column. */ - if( pExpr->op==TK_COLLATE - && (pE2 = pExpr->pLeft)->op==TK_COLUMN - && pE2->iTable==pSrc->iCursor - ){ - const char *zColl; /* The collating sequence name */ - assert( !ExprHasProperty(pExpr, EP_IntValue) ); - assert( pExpr->u.zToken!=0 ); - assert( pE2->iColumn>=XN_ROWID && pE2->iColumnnCol ); - pExpr->iColumn = pE2->iColumn; - if( pE2->iColumn<0 ) continue; /* Collseq does not matter for rowid */ - zColl = sqlite3ColumnColl(&pTab->aCol[pE2->iColumn]); - if( zColl==0 ) zColl = sqlite3StrBINARY; - if( sqlite3_stricmp(pExpr->u.zToken, zColl)==0 ) continue; - } - - /* No matches cause a break out of the loop */ - break; - } - if( i==n ){ - nOrderBy = n; - if( (pWInfo->wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY)) ){ - eDistinct = 1 + ((pWInfo->wctrlFlags & WHERE_DISTINCTBY)!=0); - } + } + if( i==n){ + nOrderBy = n; } } /* Allocate the sqlite3_index_info structure */ pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo) + (sizeof(*pIdxCons) + sizeof(*pUsage))*nTerm - + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden) - + sizeof(sqlite3_value*)*nTerm ); + + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden) ); if( pIdxInfo==0 ){ sqlite3ErrorMsg(pParse, "out of memory"); return 0; } pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1]; - pIdxCons = (struct sqlite3_index_constraint*)&pHidden->aRhs[nTerm]; + pIdxCons = (struct sqlite3_index_constraint*)&pHidden[1]; pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm]; pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy]; + pIdxInfo->nOrderBy = nOrderBy; pIdxInfo->aConstraint = pIdxCons; pIdxInfo->aOrderBy = pIdxOrderBy; pIdxInfo->aConstraintUsage = pUsage; pHidden->pWC = pWC; pHidden->pParse = pParse; - pHidden->eDistinct = eDistinct; - pHidden->mIn = 0; for(i=j=0, pTerm=pWC->a; inTerm; i++, pTerm++){ u16 op; - if( (pTerm->wtFlags & TERM_OK)==0 ) continue; + if( pTerm->leftCursor != pSrc->iCursor ) continue; + if( pTerm->prereqRight & mUnusable ) continue; + assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) ); + testcase( pTerm->eOperator & WO_IN ); + testcase( pTerm->eOperator & WO_IS ); + testcase( pTerm->eOperator & WO_ISNULL ); + testcase( pTerm->eOperator & WO_ALL ); + if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue; + if( pTerm->wtFlags & TERM_VNULL ) continue; + + /* tag-20191211-002: WHERE-clause constraints are not useful to the + ** right-hand table of a LEFT JOIN. See tag-20191211-001 for the + ** equivalent restriction for ordinary tables. */ + if( (pSrc->fg.jointype & JT_LEFT)!=0 + && !ExprHasProperty(pTerm->pExpr, EP_FromJoin) + ){ + continue; + } + assert( pTerm->u.x.leftColumn>=(-1) ); pIdxCons[j].iColumn = pTerm->u.x.leftColumn; pIdxCons[j].iTermOffset = i; op = pTerm->eOperator & WO_ALL; - if( op==WO_IN ){ - if( (pTerm->wtFlags & TERM_SLICE)==0 ){ - pHidden->mIn |= SMASKBIT32(j); - } - op = WO_EQ; - } + if( op==WO_IN ) op = WO_EQ; if( op==WO_AUX ){ pIdxCons[j].op = pTerm->eMatchOp; }else if( op & (WO_ISNULL|WO_IS) ){ if( op==WO_ISNULL ){ pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_ISNULL; @@ -153337,46 +150961,21 @@ } } j++; } - assert( j==nTerm ); pIdxInfo->nConstraint = j; - for(i=j=0; ia[i].pExpr; - if( sqlite3ExprIsConstant(pExpr) ) continue; - assert( pExpr->op==TK_COLUMN - || (pExpr->op==TK_COLLATE && pExpr->pLeft->op==TK_COLUMN - && pExpr->iColumn==pExpr->pLeft->iColumn) ); - pIdxOrderBy[j].iColumn = pExpr->iColumn; - pIdxOrderBy[j].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC; - j++; - } - pIdxInfo->nOrderBy = j; + pIdxOrderBy[i].iColumn = pExpr->iColumn; + pIdxOrderBy[i].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC; + } *pmNoOmit = mNoOmit; return pIdxInfo; } -/* -** Free an sqlite3_index_info structure allocated by allocateIndexInfo() -** and possibly modified by xBestIndex methods. -*/ -static void freeIndexInfo(sqlite3 *db, sqlite3_index_info *pIdxInfo){ - HiddenIndexInfo *pHidden; - int i; - assert( pIdxInfo!=0 ); - pHidden = (HiddenIndexInfo*)&pIdxInfo[1]; - assert( pHidden->pParse!=0 ); - assert( pHidden->pParse->db==db ); - for(i=0; inConstraint; i++){ - sqlite3ValueFree(pHidden->aRhs[i]); /* IMP: R-14553-25174 */ - pHidden->aRhs[i] = 0; - } - sqlite3DbFree(db, pIdxInfo); -} - /* ** The table object reference passed as the second argument to this function ** must represent a virtual table. This function invokes the xBestIndex() ** method of the virtual table with the sqlite3_index_info object that ** comes in as the 3rd argument to this function. @@ -153394,13 +150993,11 @@ static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){ sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab; int rc; whereTraceIndexInfoInputs(p); - pParse->db->nSchemaLock++; rc = pVtab->pModule->xBestIndex(pVtab, p); - pParse->db->nSchemaLock--; whereTraceIndexInfoOutputs(p); if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){ if( rc==SQLITE_NOMEM ){ sqlite3OomFault(pParse->db); @@ -154090,11 +151687,10 @@ if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V'; if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E'; if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L'; if( pTerm->wtFlags & TERM_CODED ) zType[3] = 'C'; if( pTerm->eOperator & WO_SINGLE ){ - assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); sqlite3_snprintf(sizeof(zLeft),zLeft,"left={%d:%d}", pTerm->leftCursor, pTerm->u.x.leftColumn); }else if( (pTerm->eOperator & WO_OR)!=0 && pTerm->u.pOrInfo!=0 ){ sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%llx", pTerm->u.pOrInfo->indexable); @@ -154108,11 +151704,11 @@ ** shown about each Term */ if( sqlite3WhereTrace & 0x10000 ){ sqlite3DebugPrintf(" prob=%-3d prereq=%llx,%llx", pTerm->truthProb, (u64)pTerm->prereqAll, (u64)pTerm->prereqRight); } - if( (pTerm->eOperator & (WO_OR|WO_AND))==0 && pTerm->u.x.iField ){ + if( pTerm->u.x.iField ){ sqlite3DebugPrintf(" iField=%d", pTerm->u.x.iField); } if( pTerm->iParent>=0 ){ sqlite3DebugPrintf(" iParent=%d", pTerm->iParent); } @@ -154170,13 +151766,13 @@ } sqlite3DebugPrintf(" %-19s", z); sqlite3_free(z); } if( p->wsFlags & WHERE_SKIPSCAN ){ - sqlite3DebugPrintf(" f %06x %d-%d", p->wsFlags, p->nLTerm,p->nSkip); + sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->nSkip); }else{ - sqlite3DebugPrintf(" f %06x N %d", p->wsFlags, p->nLTerm); + sqlite3DebugPrintf(" f %05x N %d", p->wsFlags, p->nLTerm); } sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut); if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){ int i; for(i=0; inLTerm; i++){ @@ -154272,12 +151868,11 @@ static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){ int i; assert( pWInfo!=0 ); for(i=0; inLevel; i++){ WhereLevel *pLevel = &pWInfo->a[i]; - if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE)!=0 ){ - assert( (pLevel->pWLoop->wsFlags & WHERE_MULTI_OR)==0 ); + if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){ sqlite3DbFree(db, pLevel->u.in.aInLoop); } } sqlite3WhereClauseClear(&pWInfo->sWC); while( pWInfo->pLoops ){ @@ -154632,38 +152227,22 @@ Bitmask notAllowed = ~(pLoop->prereq|pLoop->maskSelf); int i, j; LogEst iReduce = 0; /* pLoop->nOut should not exceed nRow-iReduce */ assert( (pLoop->wsFlags & WHERE_AUTO_INDEX)==0 ); - for(i=pWC->nBase, pTerm=pWC->a; i>0; i--, pTerm++){ + for(i=pWC->nTerm, pTerm=pWC->a; i>0; i--, pTerm++){ assert( pTerm!=0 ); - if( (pTerm->prereqAll & notAllowed)!=0 ) continue; + if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break; if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue; - if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) continue; + if( (pTerm->prereqAll & notAllowed)!=0 ) continue; for(j=pLoop->nLTerm-1; j>=0; j--){ pX = pLoop->aLTerm[j]; if( pX==0 ) continue; if( pX==pTerm ) break; if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break; } if( j<0 ){ - if( pLoop->maskSelf==pTerm->prereqAll ){ - /* If there are extra terms in the WHERE clause not used by an index - ** that depend only on the table being scanned, and that will tend to - ** cause many rows to be omitted, then mark that table as - ** "self-culling". - ** - ** 2022-03-24: Self-culling only applies if either the extra terms - ** are straight comparison operators that are non-true with NULL - ** operand, or if the loop is not a LEFT JOIN. - */ - if( (pTerm->eOperator & 0x3f)!=0 - || (pWC->pWInfo->pTabList->a[pLoop->iTab].fg.jointype & JT_LEFT)==0 - ){ - pLoop->wsFlags |= WHERE_SELFCULL; - } - } if( pTerm->truthProb<=0 ){ /* If a truth probability is specified using the likelihood() hints, ** then use the probability provided by the application. */ pLoop->nOut += pTerm->truthProb; }else{ @@ -154687,13 +152266,11 @@ } } } } } - if( pLoop->nOut > nRow-iReduce ){ - pLoop->nOut = nRow - iReduce; - } + if( pLoop->nOut > nRow-iReduce ) pLoop->nOut = nRow - iReduce; } /* ** Term pTerm is a vector range comparison operation. The first comparison ** in the vector can be optimized using column nEq of the index. This @@ -154726,16 +152303,13 @@ /* Test if comparison i of pTerm is compatible with column (i+nEq) ** of the index. If not, exit the loop. */ char aff; /* Comparison affinity */ char idxaff = 0; /* Indexed columns affinity */ CollSeq *pColl; /* Comparison collation sequence */ - Expr *pLhs, *pRhs; - - assert( ExprUseXList(pTerm->pExpr->pLeft) ); - pLhs = pTerm->pExpr->pLeft->x.pList->a[i].pExpr; - pRhs = pTerm->pExpr->pRight; - if( ExprUseXSelect(pRhs) ){ + Expr *pLhs = pTerm->pExpr->pLeft->x.pList->a[i].pExpr; + Expr *pRhs = pTerm->pExpr->pRight; + if( pRhs->flags & EP_xIsSelect ){ pRhs = pRhs->x.pSelect->pEList->a[i].pExpr; }else{ pRhs = pRhs->x.pList->a[i].pExpr; } @@ -154892,11 +152466,11 @@ || (pNew->wsFlags & WHERE_SKIPSCAN)!=0 ); if( eOp & WO_IN ){ Expr *pExpr = pTerm->pExpr; - if( ExprUseXSelect(pExpr) ){ + if( ExprHasProperty(pExpr, EP_xIsSelect) ){ /* "x IN (SELECT ...)": TUNING: the SELECT returns 25 rows */ int i; nIn = 46; assert( 46==sqlite3LogEst(25) ); /* The expression may actually be of the form (x, y) IN (SELECT...). @@ -155033,11 +152607,11 @@ #ifdef SQLITE_ENABLE_STAT4 tRowcnt nOut = 0; if( nInMul==0 && pProbe->nSample && ALWAYS(pNew->u.btree.nEq<=pProbe->nSampleCol) - && ((eOp & WO_IN)==0 || ExprUseXList(pTerm->pExpr)) + && ((eOp & WO_IN)==0 || !ExprHasProperty(pTerm->pExpr, EP_xIsSelect)) && OptimizationEnabled(db, SQLITE_Stat4) ){ Expr *pExpr = pTerm->pExpr; if( (eOp & (WO_EQ|WO_ISNULL|WO_IS))!=0 ){ testcase( eOp & WO_EQ ); @@ -155234,11 +152808,11 @@ } if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0; for(i=0, pTerm=pWC->a; inTerm; i++, pTerm++){ Expr *pExpr; pExpr = pTerm->pExpr; - if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->w.iRightJoinTable==iTab) + if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab) && (isLeft==0 || ExprHasProperty(pExpr, EP_FromJoin)) && sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab) && (pTerm->wtFlags & TERM_VNULL)==0 ){ return 1; @@ -155309,11 +152883,10 @@ pTab = pSrc->pTab; pWC = pBuilder->pWC; assert( !IsVirtual(pSrc->pTab) ); if( pSrc->fg.isIndexedBy ){ - assert( pSrc->fg.isCte==0 ); /* An INDEXED BY clause specifies a particular index to use */ pProbe = pSrc->u2.pIBIndex; }else if( !HasRowid(pTab) ){ pProbe = pTab->pIndex; }else{ @@ -155536,19 +153109,10 @@ return rc; } #ifndef SQLITE_OMIT_VIRTUALTABLE -/* -** Return true if pTerm is a virtual table LIMIT or OFFSET term. -*/ -static int isLimitTerm(WhereTerm *pTerm){ - assert( pTerm->eOperator==WO_AUX || pTerm->eMatchOp==0 ); - return pTerm->eMatchOp>=SQLITE_INDEX_CONSTRAINT_LIMIT - && pTerm->eMatchOp<=SQLITE_INDEX_CONSTRAINT_OFFSET; -} - /* ** Argument pIdxInfo is already populated with all constraints that may ** be used by the virtual table identified by pBuilder->pNew->iTab. This ** function marks a subset of those constraints usable, invokes the ** xBestIndex method and adds the returned plan to pBuilder. @@ -155572,15 +153136,13 @@ Bitmask mPrereq, /* Mask of tables that must be used. */ Bitmask mUsable, /* Mask of usable tables */ u16 mExclude, /* Exclude terms using these operators */ sqlite3_index_info *pIdxInfo, /* Populated object for xBestIndex */ u16 mNoOmit, /* Do not omit these constraints */ - int *pbIn, /* OUT: True if plan uses an IN(...) op */ - int *pbRetryLimit /* OUT: Retry without LIMIT/OFFSET */ + int *pbIn /* OUT: True if plan uses an IN(...) op */ ){ WhereClause *pWC = pBuilder->pWC; - HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1]; struct sqlite3_index_constraint *pIdxCons; struct sqlite3_index_constraint_usage *pUsage = pIdxInfo->aConstraintUsage; int i; int mxTerm; int rc = SQLITE_OK; @@ -155599,11 +153161,10 @@ for(i=0; ia[pIdxCons->iTermOffset]; pIdxCons->usable = 0; if( (pTerm->prereqRight & mUsable)==pTerm->prereqRight && (pTerm->eOperator & mExclude)==0 - && (pbRetryLimit || !isLimitTerm(pTerm)) ){ pIdxCons->usable = 1; } } @@ -155615,11 +153176,10 @@ pIdxInfo->orderByConsumed = 0; pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2; pIdxInfo->estimatedRows = 25; pIdxInfo->idxFlags = 0; pIdxInfo->colUsed = (sqlite3_int64)pSrc->colUsed; - pHidden->mHandleIn = 0; /* Invoke the virtual table xBestIndex() method */ rc = vtabBestIndex(pParse, pSrc->pTab, pIdxInfo); if( rc ){ if( rc==SQLITE_CONSTRAINT ){ @@ -155633,12 +153193,12 @@ return rc; } mxTerm = -1; assert( pNew->nLSlot>=nConstraint ); - memset(pNew->aLTerm, 0, sizeof(pNew->aLTerm[0])*nConstraint ); - memset(&pNew->u.vtab, 0, sizeof(pNew->u.vtab)); + for(i=0; iaLTerm[i] = 0; + pNew->u.vtab.omitMask = 0; pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint; for(i=0; i=0 ){ WhereTerm *pTerm; @@ -155668,41 +153228,21 @@ testcase( i!=iTerm ); pNew->u.vtab.omitMask |= 1<eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET ){ - pNew->u.vtab.bOmitOffset = 1; - } } - if( SMASKBIT32(i) & pHidden->mHandleIn ){ - pNew->u.vtab.mHandleIn |= MASKBIT32(iTerm); - }else if( (pTerm->eOperator & WO_IN)!=0 ){ + if( (pTerm->eOperator & WO_IN)!=0 ){ /* A virtual table that is constrained by an IN clause may not ** consume the ORDER BY clause because (1) the order of IN terms ** is not necessarily related to the order of output terms and ** (2) Multiple outputs from a single IN value will not merge ** together. */ pIdxInfo->orderByConsumed = 0; pIdxInfo->idxFlags &= ~SQLITE_INDEX_SCAN_UNIQUE; *pbIn = 1; assert( (mExclude & WO_IN)==0 ); } - - if( isLimitTerm(pTerm) && *pbIn ){ - /* If there is an IN(...) term handled as an == (separate call to - ** xFilter for each value on the RHS of the IN) and a LIMIT or - ** OFFSET term handled as well, the plan is unusable. Set output - ** variable *pbRetryLimit to true to tell the caller to retry with - ** LIMIT and OFFSET disabled. */ - if( pIdxInfo->needToFreeIdxStr ){ - sqlite3_free(pIdxInfo->idxStr); - pIdxInfo->idxStr = 0; - pIdxInfo->needToFreeIdxStr = 0; - } - *pbRetryLimit = 1; - return SQLITE_OK; - } } } pNew->nLTerm = mxTerm+1; for(i=0; i<=mxTerm; i++){ @@ -155743,23 +153283,15 @@ return rc; } /* -** Return the collating sequence for a constraint passed into xBestIndex. -** -** pIdxInfo must be an sqlite3_index_info structure passed into xBestIndex. -** This routine depends on there being a HiddenIndexInfo structure immediately -** following the sqlite3_index_info structure. -** -** Return a pointer to the collation name: -** -** 1. If there is an explicit COLLATE operator on the constaint, return it. -** -** 2. Else, if the column has an alternative collation, return that. -** -** 3. Otherwise, return "BINARY". +** If this function is invoked from within an xBestIndex() callback, it +** returns a pointer to a buffer containing the name of the collation +** sequence associated with element iCons of the sqlite3_index_info.aConstraint +** array. Or, if iCons is out of range or there is no active xBestIndex +** call, return NULL. */ SQLITE_API const char *sqlite3_vtab_collation(sqlite3_index_info *pIdxInfo, int iCons){ HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1]; const char *zRet = 0; if( iCons>=0 && iConsnConstraint ){ @@ -155772,92 +153304,10 @@ zRet = (pC ? pC->zName : sqlite3StrBINARY); } return zRet; } -/* -** Return true if constraint iCons is really an IN(...) constraint, or -** false otherwise. If iCons is an IN(...) constraint, set (if bHandle!=0) -** or clear (if bHandle==0) the flag to handle it using an iterator. -*/ -SQLITE_API int sqlite3_vtab_in(sqlite3_index_info *pIdxInfo, int iCons, int bHandle){ - HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1]; - u32 m = SMASKBIT32(iCons); - if( m & pHidden->mIn ){ - if( bHandle==0 ){ - pHidden->mHandleIn &= ~m; - }else if( bHandle>0 ){ - pHidden->mHandleIn |= m; - } - return 1; - } - return 0; -} - -/* -** This interface is callable from within the xBestIndex callback only. -** -** If possible, set (*ppVal) to point to an object containing the value -** on the right-hand-side of constraint iCons. -*/ -SQLITE_API int sqlite3_vtab_rhs_value( - sqlite3_index_info *pIdxInfo, /* Copy of first argument to xBestIndex */ - int iCons, /* Constraint for which RHS is wanted */ - sqlite3_value **ppVal /* Write value extracted here */ -){ - HiddenIndexInfo *pH = (HiddenIndexInfo*)&pIdxInfo[1]; - sqlite3_value *pVal = 0; - int rc = SQLITE_OK; - if( iCons<0 || iCons>=pIdxInfo->nConstraint ){ - rc = SQLITE_MISUSE; /* EV: R-30545-25046 */ - }else{ - if( pH->aRhs[iCons]==0 ){ - WhereTerm *pTerm = &pH->pWC->a[pIdxInfo->aConstraint[iCons].iTermOffset]; - rc = sqlite3ValueFromExpr( - pH->pParse->db, pTerm->pExpr->pRight, ENC(pH->pParse->db), - SQLITE_AFF_BLOB, &pH->aRhs[iCons] - ); - testcase( rc!=SQLITE_OK ); - } - pVal = pH->aRhs[iCons]; - } - *ppVal = pVal; - - if( rc==SQLITE_OK && pVal==0 ){ /* IMP: R-19933-32160 */ - rc = SQLITE_NOTFOUND; /* IMP: R-36424-56542 */ - } - - return rc; -} - -/* -** Return true if ORDER BY clause may be handled as DISTINCT. -*/ -SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info *pIdxInfo){ - HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1]; - assert( pHidden->eDistinct==0 - || pHidden->eDistinct==1 - || pHidden->eDistinct==2 ); - return pHidden->eDistinct; -} - -#if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \ - && !defined(SQLITE_OMIT_VIRTUALTABLE) -/* -** Cause the prepared statement that is associated with a call to -** xBestIndex to open write transactions on all attached schemas. -** This is used by the (built-in) sqlite_dbpage virtual table. -*/ -SQLITE_PRIVATE void sqlite3VtabWriteAll(sqlite3_index_info *pIdxInfo){ - HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1]; - Parse *pParse = pHidden->pParse; - int nDb = pParse->db->nDb; - int i; - for(i=0; ipNew->iTab. That table is guaranteed to be a virtual table. ** ** If there are no LEFT or CROSS JOIN joins in the query, both mPrereq and @@ -155895,43 +153345,35 @@ int nConstraint; /* Number of constraints in p */ int bIn; /* True if plan uses IN(...) operator */ WhereLoop *pNew; Bitmask mBest; /* Tables used by best possible plan */ u16 mNoOmit; - int bRetry = 0; /* True to retry with LIMIT/OFFSET disabled */ assert( (mPrereq & mUnusable)==0 ); pWInfo = pBuilder->pWInfo; pParse = pWInfo->pParse; pWC = pBuilder->pWC; pNew = pBuilder->pNew; pSrc = &pWInfo->pTabList->a[pNew->iTab]; assert( IsVirtual(pSrc->pTab) ); - p = allocateIndexInfo(pWInfo, pWC, mUnusable, pSrc, &mNoOmit); + p = allocateIndexInfo(pParse, pWC, mUnusable, pSrc, pBuilder->pOrderBy, + &mNoOmit); if( p==0 ) return SQLITE_NOMEM_BKPT; pNew->rSetup = 0; pNew->wsFlags = WHERE_VIRTUALTABLE; pNew->nLTerm = 0; pNew->u.vtab.needFree = 0; nConstraint = p->nConstraint; if( whereLoopResize(pParse->db, pNew, nConstraint) ){ - freeIndexInfo(pParse->db, p); + sqlite3DbFree(pParse->db, p); return SQLITE_NOMEM_BKPT; } /* First call xBestIndex() with all constraints usable. */ WHERETRACE(0x800, ("BEGIN %s.addVirtual()\n", pSrc->pTab->zName)); WHERETRACE(0x40, (" VirtualOne: all usable\n")); - rc = whereLoopAddVirtualOne( - pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn, &bRetry - ); - if( bRetry ){ - assert( rc==SQLITE_OK ); - rc = whereLoopAddVirtualOne( - pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn, 0 - ); - } + rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn); /* If the call to xBestIndex() with all terms enabled produced a plan ** that does not require any source tables (IOW: a plan with mBest==0) ** and does not use an IN(...) operator, then there is no point in making ** any further calls to xBestIndex() since they will all return the same @@ -155945,11 +153387,11 @@ /* If the plan produced by the earlier call uses an IN(...) term, call ** xBestIndex again, this time with IN(...) terms disabled. */ if( bIn ){ WHERETRACE(0x40, (" VirtualOne: all usable w/o IN\n")); rc = whereLoopAddVirtualOne( - pBuilder, mPrereq, ALLBITS, WO_IN, p, mNoOmit, &bIn, 0); + pBuilder, mPrereq, ALLBITS, WO_IN, p, mNoOmit, &bIn); assert( bIn==0 ); mBestNoIn = pNew->prereq & ~mPrereq; if( mBestNoIn==0 ){ seenZero = 1; seenZeroNoIN = 1; @@ -155972,11 +153414,11 @@ if( mNext==ALLBITS ) break; if( mNext==mBest || mNext==mBestNoIn ) continue; WHERETRACE(0x40, (" VirtualOne: mPrev=%04llx mNext=%04llx\n", (sqlite3_uint64)mPrev, (sqlite3_uint64)mNext)); rc = whereLoopAddVirtualOne( - pBuilder, mPrereq, mNext|mPrereq, 0, p, mNoOmit, &bIn, 0); + pBuilder, mPrereq, mNext|mPrereq, 0, p, mNoOmit, &bIn); if( pNew->prereq==mPrereq ){ seenZero = 1; if( bIn==0 ) seenZeroNoIN = 1; } } @@ -155985,26 +153427,26 @@ ** that requires no source tables at all (i.e. one guaranteed to be ** usable), make a call here with all source tables disabled */ if( rc==SQLITE_OK && seenZero==0 ){ WHERETRACE(0x40, (" VirtualOne: all disabled\n")); rc = whereLoopAddVirtualOne( - pBuilder, mPrereq, mPrereq, 0, p, mNoOmit, &bIn, 0); + pBuilder, mPrereq, mPrereq, 0, p, mNoOmit, &bIn); if( bIn==0 ) seenZeroNoIN = 1; } /* If the calls to xBestIndex() have so far failed to find a plan ** that requires no source tables at all and does not use an IN(...) ** operator, make a final call to obtain one here. */ if( rc==SQLITE_OK && seenZeroNoIN==0 ){ WHERETRACE(0x40, (" VirtualOne: all disabled and w/o IN\n")); rc = whereLoopAddVirtualOne( - pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn, 0); + pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn); } } if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr); - freeIndexInfo(pParse->db, p); + sqlite3DbFreeNN(pParse->db, p); WHERETRACE(0x800, ("END %s.addVirtual(), rc=%d\n", pSrc->pTab->zName, rc)); return rc; } #endif /* SQLITE_OMIT_VIRTUALTABLE */ @@ -156044,10 +153486,11 @@ WhereTerm *pOrTerm; int once = 1; int i, j; sSubBuild = *pBuilder; + sSubBuild.pOrderBy = 0; sSubBuild.pOrSet = &sCur; WHERETRACE(0x200, ("Begin processing OR-clause %p\n", pTerm)); for(pOrTerm=pOrWC->a; pOrTermeOperator & WO_AND)!=0 ){ @@ -156055,11 +153498,10 @@ }else if( pOrTerm->leftCursor==iCur ){ tempWC.pWInfo = pWC->pWInfo; tempWC.pOuter = pWC; tempWC.op = TK_AND; tempWC.nTerm = 1; - tempWC.nBase = 1; tempWC.a = pOrTerm; sSubBuild.pWC = &tempWC; }else{ continue; } @@ -156527,11 +153969,11 @@ } } /* End the loop over all WhereLoops from outer-most down to inner-most */ if( obSat==obDone ) return (i8)nOrderBy; if( !isOrderDistinct ){ for(i=nOrderBy-1; i>0; i--){ - Bitmask m = ALWAYS(isWC; pLoop = pBuilder->pNew; pLoop->wsFlags = 0; pLoop->nSkip = 0; pTerm = whereScanInit(&scan, pWC, iCur, -1, WO_EQ|WO_IS, 0); - while( pTerm && pTerm->prereqRight ) pTerm = whereScanNext(&scan); if( pTerm ){ testcase( pTerm->eOperator & WO_IS ); + assert( pTerm->prereqRight==0 ); pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW; pLoop->aLTerm[0] = pTerm; pLoop->nLTerm = 1; pLoop->u.btree.nEq = 1; /* TUNING: Cost of a rowid lookup is 10 */ @@ -157163,154 +154605,10 @@ # define WHERETRACE_ALL_LOOPS(W,C) showAllWhereLoops(W,C) #else # define WHERETRACE_ALL_LOOPS(W,C) #endif -/* Attempt to omit tables from a join that do not affect the result. -** For a table to not affect the result, the following must be true: -** -** 1) The query must not be an aggregate. -** 2) The table must be the RHS of a LEFT JOIN. -** 3) Either the query must be DISTINCT, or else the ON or USING clause -** must contain a constraint that limits the scan of the table to -** at most a single row. -** 4) The table must not be referenced by any part of the query apart -** from its own USING or ON clause. -** -** For example, given: -** -** CREATE TABLE t1(ipk INTEGER PRIMARY KEY, v1); -** CREATE TABLE t2(ipk INTEGER PRIMARY KEY, v2); -** CREATE TABLE t3(ipk INTEGER PRIMARY KEY, v3); -** -** then table t2 can be omitted from the following: -** -** SELECT v1, v3 FROM t1 -** LEFT JOIN t2 ON (t1.ipk=t2.ipk) -** LEFT JOIN t3 ON (t1.ipk=t3.ipk) -** -** or from: -** -** SELECT DISTINCT v1, v3 FROM t1 -** LEFT JOIN t2 -** LEFT JOIN t3 ON (t1.ipk=t3.ipk) -*/ -static SQLITE_NOINLINE Bitmask whereOmitNoopJoin( - WhereInfo *pWInfo, - Bitmask notReady -){ - int i; - Bitmask tabUsed; - - /* Preconditions checked by the caller */ - assert( pWInfo->nLevel>=2 ); - assert( OptimizationEnabled(pWInfo->pParse->db, SQLITE_OmitNoopJoin) ); - - /* These two preconditions checked by the caller combine to guarantee - ** condition (1) of the header comment */ - assert( pWInfo->pResultSet!=0 ); - assert( 0==(pWInfo->wctrlFlags & WHERE_AGG_DISTINCT) ); - - tabUsed = sqlite3WhereExprListUsage(&pWInfo->sMaskSet, pWInfo->pResultSet); - if( pWInfo->pOrderBy ){ - tabUsed |= sqlite3WhereExprListUsage(&pWInfo->sMaskSet, pWInfo->pOrderBy); - } - for(i=pWInfo->nLevel-1; i>=1; i--){ - WhereTerm *pTerm, *pEnd; - SrcItem *pItem; - WhereLoop *pLoop; - pLoop = pWInfo->a[i].pWLoop; - pItem = &pWInfo->pTabList->a[pLoop->iTab]; - if( (pItem->fg.jointype & JT_LEFT)==0 ) continue; - if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)==0 - && (pLoop->wsFlags & WHERE_ONEROW)==0 - ){ - continue; - } - if( (tabUsed & pLoop->maskSelf)!=0 ) continue; - pEnd = pWInfo->sWC.a + pWInfo->sWC.nTerm; - for(pTerm=pWInfo->sWC.a; pTermprereqAll & pLoop->maskSelf)!=0 ){ - if( !ExprHasProperty(pTerm->pExpr, EP_FromJoin) - || pTerm->pExpr->w.iRightJoinTable!=pItem->iCursor - ){ - break; - } - } - } - if( pTerm drop loop %c not used\n", pLoop->cId)); - notReady &= ~pLoop->maskSelf; - for(pTerm=pWInfo->sWC.a; pTermprereqAll & pLoop->maskSelf)!=0 ){ - pTerm->wtFlags |= TERM_CODED; - } - } - if( i!=pWInfo->nLevel-1 ){ - int nByte = (pWInfo->nLevel-1-i) * sizeof(WhereLevel); - memmove(&pWInfo->a[i], &pWInfo->a[i+1], nByte); - } - pWInfo->nLevel--; - assert( pWInfo->nLevel>0 ); - } - return notReady; -} - -/* -** Check to see if there are any SEARCH loops that might benefit from -** using a Bloom filter. Consider a Bloom filter if: -** -** (1) The SEARCH happens more than N times where N is the number -** of rows in the table that is being considered for the Bloom -** filter. -** (2) Some searches are expected to find zero rows. (This is determined -** by the WHERE_SELFCULL flag on the term.) -** (3) Bloom-filter processing is not disabled. (Checked by the -** caller.) -** (4) The size of the table being searched is known by ANALYZE. -** -** This block of code merely checks to see if a Bloom filter would be -** appropriate, and if so sets the WHERE_BLOOMFILTER flag on the -** WhereLoop. The implementation of the Bloom filter comes further -** down where the code for each WhereLoop is generated. -*/ -static SQLITE_NOINLINE void whereCheckIfBloomFilterIsUseful( - const WhereInfo *pWInfo -){ - int i; - LogEst nSearch; - - assert( pWInfo->nLevel>=2 ); - assert( OptimizationEnabled(pWInfo->pParse->db, SQLITE_BloomFilter) ); - nSearch = pWInfo->a[0].pWLoop->nOut; - for(i=1; inLevel; i++){ - WhereLoop *pLoop = pWInfo->a[i].pWLoop; - const unsigned int reqFlags = (WHERE_SELFCULL|WHERE_COLUMN_EQ); - if( (pLoop->wsFlags & reqFlags)==reqFlags - /* vvvvvv--- Always the case if WHERE_COLUMN_EQ is defined */ - && ALWAYS((pLoop->wsFlags & (WHERE_IPK|WHERE_INDEXED))!=0) - ){ - SrcItem *pItem = &pWInfo->pTabList->a[pLoop->iTab]; - Table *pTab = pItem->pTab; - pTab->tabFlags |= TF_StatsUsed; - if( nSearch > pTab->nRowLogEst - && (pTab->tabFlags & TF_HasStat1)!=0 - ){ - testcase( pItem->fg.jointype & JT_LEFT ); - pLoop->wsFlags |= WHERE_BLOOMFILTER; - pLoop->wsFlags &= ~WHERE_IDX_ONLY; - WHERETRACE(0xffff, ( - "-> use Bloom-filter on loop %c because there are ~%.1e " - "lookups into %s which has only ~%.1e rows\n", - pLoop->cId, (double)sqlite3LogEstToInt(nSearch), pTab->zName, - (double)sqlite3LogEstToInt(pTab->nRowLogEst))); - } - } - nSearch += pLoop->nOut; - } -} - /* ** Generate the beginning of the loop used for WHERE clause processing. ** The return value is a pointer to an opaque structure that contains ** information needed to terminate the loop. Later, the calling routine ** should invoke sqlite3WhereEnd() with the return value of this function @@ -157401,11 +154699,10 @@ Parse *pParse, /* The parser context */ SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */ Expr *pWhere, /* The WHERE clause */ ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */ ExprList *pResultSet, /* Query result set. Req'd for DISTINCT */ - Select *pLimit, /* Use this LIMIT/OFFSET clause, if any */ u16 wctrlFlags, /* The WHERE_* flags defined in sqliteInt.h */ int iAuxArg /* If WHERE_OR_SUBCLAUSE is set, index cursor number ** If WHERE_USE_LIMIT, then the limit amount */ ){ int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */ @@ -157436,10 +154733,17 @@ memset(&sWLB, 0, sizeof(sWLB)); /* An ORDER/GROUP BY clause of more than 63 terms cannot be optimized */ testcase( pOrderBy && pOrderBy->nExpr==BMS-1 ); if( pOrderBy && pOrderBy->nExpr>=BMS ) pOrderBy = 0; + sWLB.pOrderBy = pOrderBy; + + /* Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via + ** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...) */ + if( OptimizationDisabled(db, SQLITE_DistinctOpt) ){ + wctrlFlags &= ~WHERE_WANT_DISTINCT; + } /* The number of tables in the FROM clause is limited by the number of ** bits in a Bitmask */ testcase( pTabList->nSrc==BMS ); @@ -157478,22 +154782,15 @@ pWInfo->nLevel = nTabList; pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(pParse); pWInfo->wctrlFlags = wctrlFlags; pWInfo->iLimit = iAuxArg; pWInfo->savedNQueryLoop = pParse->nQueryLoop; -#ifndef SQLITE_OMIT_VIRTUALTABLE - pWInfo->pLimit = pLimit; -#endif memset(&pWInfo->nOBSat, 0, offsetof(WhereInfo,sWC) - offsetof(WhereInfo,nOBSat)); memset(&pWInfo->a[0], 0, sizeof(WhereLoop)+nTabList*sizeof(WhereLevel)); assert( pWInfo->eOnePass==ONEPASS_OFF ); /* ONEPASS defaults to OFF */ pMaskSet = &pWInfo->sMaskSet; - pMaskSet->n = 0; - pMaskSet->ix[0] = -99; /* Initialize ix[0] to a value that can never be - ** a valid cursor number, to avoid an initial - ** test for pMaskSet->n==0 in sqlite3WhereGetMask() */ sWLB.pWInfo = pWInfo; sWLB.pWC = &pWInfo->sWC; sWLB.pNew = (WhereLoop*)(((char*)pWInfo)+nByteWInfo); assert( EIGHT_BYTE_ALIGNMENT(sWLB.pNew) ); whereLoopInit(sWLB.pNew); @@ -157502,20 +154799,19 @@ #endif /* Split the WHERE clause into separate subexpressions where each ** subexpression is separated by an AND operator. */ + initMaskSet(pMaskSet); sqlite3WhereClauseInit(&pWInfo->sWC, pWInfo); sqlite3WhereSplit(&pWInfo->sWC, pWhere, TK_AND); /* Special case: No FROM clause */ if( nTabList==0 ){ if( pOrderBy ) pWInfo->nOBSat = pOrderBy->nExpr; - if( (wctrlFlags & WHERE_WANT_DISTINCT)!=0 - && OptimizationEnabled(db, SQLITE_DistinctOpt) - ){ + if( wctrlFlags & WHERE_WANT_DISTINCT ){ pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE; } ExplainQueryPlan((pParse, 0, "SCAN CONSTANT ROW")); }else{ /* Assign a bit from the bitmask to every term in the FROM clause. @@ -157549,11 +154845,10 @@ #endif } /* Analyze all of the subexpressions. */ sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC); - sqlite3WhereAddLimit(&pWInfo->sWC, pLimit); if( db->mallocFailed ) goto whereBeginError; /* Special case: WHERE terms that do not refer to any tables in the join ** (constant expressions). Evaluate each such term, and jump over all the ** generated code if the result is not true. @@ -157563,26 +154858,21 @@ ** preserves SQLite's legacy behaviour in the following two cases: ** ** FROM ... WHERE random()>0; -- eval random() once per row ** FROM ... WHERE (SELECT random())>0; -- eval random() once overall */ - for(ii=0; iinBase; ii++){ + for(ii=0; iinTerm; ii++){ WhereTerm *pT = &sWLB.pWC->a[ii]; if( pT->wtFlags & TERM_VIRTUAL ) continue; if( pT->prereqAll==0 && (nTabList==0 || exprIsDeterministic(pT->pExpr)) ){ sqlite3ExprIfFalse(pParse, pT->pExpr, pWInfo->iBreak, SQLITE_JUMPIFNULL); pT->wtFlags |= TERM_CODED; } } if( wctrlFlags & WHERE_WANT_DISTINCT ){ - if( OptimizationDisabled(db, SQLITE_DistinctOpt) ){ - /* Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via - ** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...) */ - wctrlFlags &= ~WHERE_WANT_DISTINCT; - pWInfo->wctrlFlags &= ~WHERE_WANT_DISTINCT; - }else if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){ + if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){ /* The DISTINCT marking is pointless. Ignore it. */ pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE; }else if( pOrderBy==0 ){ /* Try to ORDER BY the result set to make distinct processing easier */ pWInfo->wctrlFlags |= WHERE_DISTINCTBY; @@ -157649,14 +154939,13 @@ } } if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){ pWInfo->revMask = ALLBITS; } - if( pParse->nErr ){ + if( pParse->nErr || db->mallocFailed ){ goto whereBeginError; } - assert( db->mallocFailed==0 ); #ifdef WHERETRACE_ENABLED if( sqlite3WhereTrace ){ sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut); if( pWInfo->nOBSat>0 ){ sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask); @@ -157680,40 +154969,88 @@ sqlite3WhereLoopPrint(pWInfo->a[ii].pWLoop, sWLB.pWC); } } #endif - /* Attempt to omit tables from a join that do not affect the result. - ** See the comment on whereOmitNoopJoin() for further information. + /* Attempt to omit tables from the join that do not affect the result. + ** For a table to not affect the result, the following must be true: ** - ** This query optimization is factored out into a separate "no-inline" - ** procedure to keep the sqlite3WhereBegin() procedure from becoming - ** too large. If sqlite3WhereBegin() becomes too large, that prevents - ** some C-compiler optimizers from in-lining the - ** sqlite3WhereCodeOneLoopStart() procedure, and it is important to - ** in-line sqlite3WhereCodeOneLoopStart() for performance reasons. + ** 1) The query must not be an aggregate. + ** 2) The table must be the RHS of a LEFT JOIN. + ** 3) Either the query must be DISTINCT, or else the ON or USING clause + ** must contain a constraint that limits the scan of the table to + ** at most a single row. + ** 4) The table must not be referenced by any part of the query apart + ** from its own USING or ON clause. + ** + ** For example, given: + ** + ** CREATE TABLE t1(ipk INTEGER PRIMARY KEY, v1); + ** CREATE TABLE t2(ipk INTEGER PRIMARY KEY, v2); + ** CREATE TABLE t3(ipk INTEGER PRIMARY KEY, v3); + ** + ** then table t2 can be omitted from the following: + ** + ** SELECT v1, v3 FROM t1 + ** LEFT JOIN t2 ON (t1.ipk=t2.ipk) + ** LEFT JOIN t3 ON (t1.ipk=t3.ipk) + ** + ** or from: + ** + ** SELECT DISTINCT v1, v3 FROM t1 + ** LEFT JOIN t2 + ** LEFT JOIN t3 ON (t1.ipk=t3.ipk) */ notReady = ~(Bitmask)0; if( pWInfo->nLevel>=2 && pResultSet!=0 /* these two combine to guarantee */ && 0==(wctrlFlags & WHERE_AGG_DISTINCT) /* condition (1) above */ && OptimizationEnabled(db, SQLITE_OmitNoopJoin) ){ - notReady = whereOmitNoopJoin(pWInfo, notReady); - nTabList = pWInfo->nLevel; - assert( nTabList>0 ); - } - - /* Check to see if there are any SEARCH loops that might benefit from - ** using a Bloom filter. - */ - if( pWInfo->nLevel>=2 - && OptimizationEnabled(db, SQLITE_BloomFilter) - ){ - whereCheckIfBloomFilterIsUseful(pWInfo); - } - + int i; + Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet); + if( sWLB.pOrderBy ){ + tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy); + } + for(i=pWInfo->nLevel-1; i>=1; i--){ + WhereTerm *pTerm, *pEnd; + SrcItem *pItem; + pLoop = pWInfo->a[i].pWLoop; + pItem = &pWInfo->pTabList->a[pLoop->iTab]; + if( (pItem->fg.jointype & JT_LEFT)==0 ) continue; + if( (wctrlFlags & WHERE_WANT_DISTINCT)==0 + && (pLoop->wsFlags & WHERE_ONEROW)==0 + ){ + continue; + } + if( (tabUsed & pLoop->maskSelf)!=0 ) continue; + pEnd = sWLB.pWC->a + sWLB.pWC->nTerm; + for(pTerm=sWLB.pWC->a; pTermprereqAll & pLoop->maskSelf)!=0 ){ + if( !ExprHasProperty(pTerm->pExpr, EP_FromJoin) + || pTerm->pExpr->iRightJoinTable!=pItem->iCursor + ){ + break; + } + } + } + if( pTerm drop loop %c not used\n", pLoop->cId)); + notReady &= ~pLoop->maskSelf; + for(pTerm=sWLB.pWC->a; pTermprereqAll & pLoop->maskSelf)!=0 ){ + pTerm->wtFlags |= TERM_CODED; + } + } + if( i!=pWInfo->nLevel-1 ){ + int nByte = (pWInfo->nLevel-1-i) * sizeof(WhereLevel); + memmove(&pWInfo->a[i], &pWInfo->a[i+1], nByte); + } + pWInfo->nLevel--; + nTabList--; + } + } #if defined(WHERETRACE_ENABLED) if( sqlite3WhereTrace & 0x100 ){ /* Display all terms of the WHERE clause */ sqlite3DebugPrintf("---- WHERE clause at end of analysis:\n"); sqlite3WhereClausePrint(sWLB.pWC); } @@ -157796,11 +155133,10 @@ testcase( pWInfo->eOnePass==ONEPASS_OFF && pTab->nCol==BMS-1 ); testcase( pWInfo->eOnePass==ONEPASS_OFF && pTab->nCol==BMS ); if( pWInfo->eOnePass==ONEPASS_OFF && pTab->nColtabFlags & (TF_HasGenerated|TF_WithoutRowid))==0 - && (pLoop->wsFlags & (WHERE_AUTO_INDEX|WHERE_BLOOMFILTER))==0 ){ /* If we know that only a prefix of the record will be used, ** it is advantageous to reduce the "column count" field in ** the P4 operand of the OP_OpenRead/Write opcode. */ Bitmask b = pTabItem->colUsed; @@ -157896,24 +155232,19 @@ ** program. */ for(ii=0; iinErr ) goto whereBeginError; pLevel = &pWInfo->a[ii]; wsFlags = pLevel->pWLoop->wsFlags; - if( (wsFlags & (WHERE_AUTO_INDEX|WHERE_BLOOMFILTER))!=0 ){ - if( (wsFlags & WHERE_AUTO_INDEX)!=0 ){ #ifndef SQLITE_OMIT_AUTOMATIC_INDEX - constructAutomaticIndex(pParse, &pWInfo->sWC, - &pTabList->a[pLevel->iFrom], notReady, pLevel); -#endif - }else{ - sqlite3ConstructBloomFilter(pWInfo, ii, pLevel, notReady); - } + if( (pLevel->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){ + constructAutomaticIndex(pParse, &pWInfo->sWC, + &pTabList->a[pLevel->iFrom], notReady, pLevel); if( db->mallocFailed ) goto whereBeginError; } +#endif addrExplain = sqlite3WhereExplainOneScan( pParse, pTabList, pLevel, wctrlFlags ); pLevel->addrBody = sqlite3VdbeCurrentAddr(v); notReady = sqlite3WhereCodeOneLoopStart(pParse,v,pWInfo,ii,pLevel,notReady); @@ -157957,30 +155288,10 @@ if( (db->flags & SQLITE_VdbeAddopTrace)==0 ) return; sqlite3VdbePrintOp(0, pc, pOp); } #endif -#ifdef SQLITE_DEBUG -/* -** Return true if cursor iCur is opened by instruction k of the -** bytecode. Used inside of assert() only. -*/ -static int cursorIsOpen(Vdbe *v, int iCur, int k){ - while( k>=0 ){ - VdbeOp *pOp = sqlite3VdbeGetOp(v,k--); - if( pOp->p1!=iCur ) continue; - if( pOp->opcode==OP_Close ) return 0; - if( pOp->opcode==OP_OpenRead ) return 1; - if( pOp->opcode==OP_OpenWrite ) return 1; - if( pOp->opcode==OP_OpenDup ) return 1; - if( pOp->opcode==OP_OpenAutoindex ) return 1; - if( pOp->opcode==OP_OpenEphemeral ) return 1; - } - return 0; -} -#endif /* SQLITE_DEBUG */ - /* ** Generate the end of the WHERE loop. See comments on ** sqlite3WhereBegin() for additional information. */ SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){ @@ -158042,11 +155353,11 @@ if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek); #endif }else{ sqlite3VdbeResolveLabel(v, pLevel->addrCont); } - if( (pLoop->wsFlags & WHERE_IN_ABLE)!=0 && pLevel->u.in.nIn>0 ){ + if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){ struct InLoop *pIn; int j; sqlite3VdbeResolveLabel(v, pLevel->addrNxt); for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){ assert( sqlite3VdbeGetOp(v, pIn->addrInTop+1)->opcode==OP_IsNull @@ -158111,14 +155422,14 @@ if( (ws & WHERE_IDX_ONLY)==0 ){ assert( pLevel->iTabCur==pTabList->a[pLevel->iFrom].iCursor ); sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iTabCur); } if( (ws & WHERE_INDEXED) - || ((ws & WHERE_MULTI_OR) && pLevel->u.pCoveringIdx) + || ((ws & WHERE_MULTI_OR) && pLevel->u.pCovidx) ){ if( ws & WHERE_MULTI_OR ){ - Index *pIx = pLevel->u.pCoveringIdx; + Index *pIx = pLevel->u.pCovidx; int iDb = sqlite3SchemaToIndex(db, pIx->pSchema); sqlite3VdbeAddOp3(v, OP_ReopenIdx, pLevel->iIdxCur, pIx->tnum, iDb); sqlite3VdbeSetP4KeyInfo(pParse, pIx); } sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur); @@ -158195,11 +155506,11 @@ ** reference the index. */ if( pLoop->wsFlags & (WHERE_INDEXED|WHERE_IDX_ONLY) ){ pIdx = pLoop->u.btree.pIndex; }else if( pLoop->wsFlags & WHERE_MULTI_OR ){ - pIdx = pLevel->u.pCoveringIdx; + pIdx = pLevel->u.pCovidx; } if( pIdx && !db->mallocFailed ){ if( pWInfo->eOnePass==ONEPASS_OFF || !HasRowid(pIdx->pTable) ){ @@ -158229,15 +155540,10 @@ || pOp->opcode==OP_Offset #endif ){ int x = pOp->p2; assert( pIdx->pTable==pTab ); -#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC - if( pOp->opcode==OP_Offset ){ - /* Do not need to translate the column number */ - }else -#endif if( !HasRowid(pTab) ){ Index *pPk = sqlite3PrimaryKeyIndex(pTab); x = pPk->aiColumn[x]; assert( x>=0 ); }else{ @@ -158247,26 +155553,13 @@ x = sqlite3TableColumnToIndex(pIdx, x); if( x>=0 ){ pOp->p2 = x; pOp->p1 = pLevel->iIdxCur; OpcodeRewriteTrace(db, k, pOp); - }else{ - /* Unable to translate the table reference into an index - ** reference. Verify that this is harmless - that the - ** table being referenced really is open. - */ -#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC - assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 - || cursorIsOpen(v,pOp->p1,k) - || pOp->opcode==OP_Offset - ); -#else - assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 - || cursorIsOpen(v,pOp->p1,k) - ); -#endif - } + } + assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0 + || pWInfo->eOnePass ); }else if( pOp->opcode==OP_Rowid ){ pOp->p1 = pLevel->iIdxCur; pOp->opcode = OP_IdxRowid; OpcodeRewriteTrace(db, k, pOp); }else if( pOp->opcode==OP_IfNullRow ){ @@ -158874,28 +156167,28 @@ static void noopValueFunc(sqlite3_context *p){ UNUSED_PARAMETER(p); /*no-op*/ } /* Window functions that use all window interfaces: xStep, xFinal, ** xValue, and xInverse */ #define WINDOWFUNCALL(name,nArg,extra) { \ - nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \ + nArg, (SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \ name ## StepFunc, name ## FinalizeFunc, name ## ValueFunc, \ name ## InvFunc, name ## Name, {0} \ } /* Window functions that are implemented using bytecode and thus have ** no-op routines for their methods */ #define WINDOWFUNCNOOP(name,nArg,extra) { \ - nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \ + nArg, (SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \ noopStepFunc, noopValueFunc, noopValueFunc, \ noopStepFunc, name ## Name, {0} \ } /* Window functions that use all window interfaces: xStep, the ** same routine for xFinalize and xValue and which never call ** xInverse. */ #define WINDOWFUNCX(name,nArg,extra) { \ - nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \ + nArg, (SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \ name ## StepFunc, name ## ValueFunc, name ## ValueFunc, \ noopStepFunc, name ## Name, {0} \ } @@ -159234,12 +156527,11 @@ return WRC_Continue; } static int disallowAggregatesInOrderByCb(Walker *pWalker, Expr *pExpr){ if( pExpr->op==TK_AGG_FUNCTION && pExpr->pAggInfo==0 ){ - assert( !ExprHasProperty(pExpr, EP_IntValue) ); - sqlite3ErrorMsg(pWalker->pParse, + sqlite3ErrorMsg(pWalker->pParse, "misuse of aggregate: %s()", pExpr->u.zToken); } return WRC_Continue; } @@ -159250,15 +156542,11 @@ ** are invoked in the correct order as described under "SELECT REWRITING" ** at the top of this file. */ SQLITE_PRIVATE int sqlite3WindowRewrite(Parse *pParse, Select *p){ int rc = SQLITE_OK; - if( p->pWin - && p->pPrior==0 - && ALWAYS((p->selFlags & SF_WinRewrite)==0) - && ALWAYS(!IN_RENAME_OBJECT) - ){ + if( p->pWin && p->pPrior==0 && ALWAYS((p->selFlags & SF_WinRewrite)==0) ){ Vdbe *v = sqlite3GetVdbe(pParse); sqlite3 *db = pParse->db; Select *pSub = 0; /* The subquery */ SrcList *pSrc = p->pSrc; Expr *pWhere = p->pWhere; @@ -159327,14 +156615,11 @@ /* Append the arguments passed to each window function to the ** sub-select expression list. Also allocate two registers for each ** window function - one for the accumulator, another for interim ** results. */ for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ - ExprList *pArgs; - assert( ExprUseXList(pWin->pOwner) ); - assert( pWin->pFunc!=0 ); - pArgs = pWin->pOwner->x.pList; + ExprList *pArgs = pWin->pOwner->x.pList; if( pWin->pFunc->funcFlags & SQLITE_FUNC_SUBTYPE ){ selectWindowRewriteEList(pParse, pMWin, pSrc, pArgs, pTab, &pSublist); pWin->iArgCol = (pSublist ? pSublist->nExpr : 0); pWin->bExprArgs = 1; }else{ @@ -159397,18 +156682,19 @@ } }else{ sqlite3SelectDelete(db, pSub); } if( db->mallocFailed ) rc = SQLITE_NOMEM; - - /* Defer deleting the temporary table pTab because if an error occurred, - ** there could still be references to that table embedded in the - ** result-set or ORDER BY clause of the SELECT statement p. */ - sqlite3ParserAddCleanup(pParse, sqlite3DbFree, pTab); + sqlite3DbFree(db, pTab); } - assert( rc==SQLITE_OK || pParse->nErr!=0 ); + if( rc ){ + if( pParse->nErr==0 ){ + assert( pParse->db->mallocFailed ); + sqlite3ErrorToParser(pParse->db, SQLITE_NOMEM); + } + } return rc; } /* ** Unlink the Window object from the Select to which it is attached, @@ -159722,15 +157008,12 @@ ** ** regApp+0: slot to copy min()/max() argument to for MakeRecord ** regApp+1: integer value used to ensure keys are unique ** regApp+2: output of MakeRecord */ - ExprList *pList; - KeyInfo *pKeyInfo; - assert( ExprUseXList(pWin->pOwner) ); - pList = pWin->pOwner->x.pList; - pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0); + ExprList *pList = pWin->pOwner->x.pList; + KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0); pWin->csrApp = pParse->nTab++; pWin->regApp = pParse->nMem+1; pParse->nMem += 3; if( pKeyInfo && pWin->pFunc->zName[1]=='i' ){ assert( pKeyInfo->aSortFlags[0]==0 ); @@ -159814,13 +157097,11 @@ /* ** Return the number of arguments passed to the window-function associated ** with the object passed as the only argument to this function. */ static int windowArgCount(Window *pWin){ - const ExprList *pList; - assert( ExprUseXList(pWin->pOwner) ); - pList = pWin->pOwner->x.pList; + ExprList *pList = pWin->pOwner->x.pList; return (pList ? pList->nExpr : 0); } typedef struct WindowCodeArg WindowCodeArg; typedef struct WindowCsrAndReg WindowCsrAndReg; @@ -160001,11 +157282,10 @@ sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1); }else if( pFunc->xSFunc!=noopStepFunc ){ int addrIf = 0; if( pWin->pFilter ){ int regTmp; - assert( ExprUseXList(pWin->pOwner) ); assert( pWin->bExprArgs || !nArg ||nArg==pWin->pOwner->x.pList->nExpr ); assert( pWin->bExprArgs || nArg ||pWin->pOwner->x.pList==0 ); regTmp = sqlite3GetTempReg(pParse); sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp); addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1); @@ -160015,26 +157295,24 @@ if( pWin->bExprArgs ){ int iOp = sqlite3VdbeCurrentAddr(v); int iEnd; - assert( ExprUseXList(pWin->pOwner) ); nArg = pWin->pOwner->x.pList->nExpr; regArg = sqlite3GetTempRange(pParse, nArg); sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0); for(iEnd=sqlite3VdbeCurrentAddr(v); iOpopcode==OP_Column && pOp->p1==pMWin->iEphCsr ){ + if( pOp->opcode==OP_Column && pOp->p1==pWin->iEphCsr ){ pOp->p1 = csr; } } } if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ CollSeq *pColl; assert( nArg>0 ); - assert( ExprUseXList(pWin->pOwner) ); pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr); sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ); } sqlite3VdbeAddOp3(v, bInverse? OP_AggInverse : OP_AggStep, bInverse, regArg, pWin->regAccum); @@ -160216,11 +157494,10 @@ Parse *pParse = p->pParse; Window *pWin; for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ FuncDef *pFunc = pWin->pFunc; - assert( ExprUseXList(pWin->pOwner) ); if( pFunc->zName==nth_valueName || pFunc->zName==first_valueName ){ int csr = pWin->csrApp; int lbl = sqlite3VdbeMakeLabel(pParse); @@ -161552,11 +158829,14 @@ } return pSelect; } - /* Construct a new Expr object from a single token */ + /* Construct a new Expr object from a single identifier. Use the + ** new Expr to populate pOut. Set the span of pOut to be the identifier + ** that created the expression. + */ static Expr *tokenExpr(Parse *pParse, int op, Token t){ Expr *p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)+t.n+1); if( p ){ /* memset(p, 0, sizeof(Expr)); */ p->op = (u8)op; @@ -161563,20 +158843,19 @@ p->affExpr = 0; p->flags = EP_Leaf; ExprClearVVAProperties(p); p->iAgg = -1; p->pLeft = p->pRight = 0; + p->x.pList = 0; p->pAggInfo = 0; - memset(&p->x, 0, sizeof(p->x)); - memset(&p->y, 0, sizeof(p->y)); + p->y.pTab = 0; p->op2 = 0; p->iTable = 0; p->iColumn = 0; p->u.zToken = (char*)&p[1]; memcpy(p->u.zToken, t.z, t.n); p->u.zToken[t.n] = 0; - p->w.iOfst = (int)(t.z - pParse->zTail); if( sqlite3Isquote(p->u.zToken[0]) ){ sqlite3DequoteExpr(p); } #if SQLITE_MAX_EXPR_DEPTH>0 p->nHeight = 1; @@ -161739,83 +159018,82 @@ #define TK_MINUS 107 #define TK_STAR 108 #define TK_SLASH 109 #define TK_REM 110 #define TK_CONCAT 111 -#define TK_PTR 112 -#define TK_COLLATE 113 -#define TK_BITNOT 114 -#define TK_ON 115 -#define TK_INDEXED 116 -#define TK_STRING 117 -#define TK_JOIN_KW 118 -#define TK_CONSTRAINT 119 -#define TK_DEFAULT 120 -#define TK_NULL 121 -#define TK_PRIMARY 122 -#define TK_UNIQUE 123 -#define TK_CHECK 124 -#define TK_REFERENCES 125 -#define TK_AUTOINCR 126 -#define TK_INSERT 127 -#define TK_DELETE 128 -#define TK_UPDATE 129 -#define TK_SET 130 -#define TK_DEFERRABLE 131 -#define TK_FOREIGN 132 -#define TK_DROP 133 -#define TK_UNION 134 -#define TK_ALL 135 -#define TK_EXCEPT 136 -#define TK_INTERSECT 137 -#define TK_SELECT 138 -#define TK_VALUES 139 -#define TK_DISTINCT 140 -#define TK_DOT 141 -#define TK_FROM 142 -#define TK_JOIN 143 -#define TK_USING 144 -#define TK_ORDER 145 -#define TK_GROUP 146 -#define TK_HAVING 147 -#define TK_LIMIT 148 -#define TK_WHERE 149 -#define TK_RETURNING 150 -#define TK_INTO 151 -#define TK_NOTHING 152 -#define TK_FLOAT 153 -#define TK_BLOB 154 -#define TK_INTEGER 155 -#define TK_VARIABLE 156 -#define TK_CASE 157 -#define TK_WHEN 158 -#define TK_THEN 159 -#define TK_ELSE 160 -#define TK_INDEX 161 -#define TK_ALTER 162 -#define TK_ADD 163 -#define TK_WINDOW 164 -#define TK_OVER 165 -#define TK_FILTER 166 -#define TK_COLUMN 167 -#define TK_AGG_FUNCTION 168 -#define TK_AGG_COLUMN 169 -#define TK_TRUEFALSE 170 -#define TK_ISNOT 171 -#define TK_FUNCTION 172 -#define TK_UMINUS 173 -#define TK_UPLUS 174 -#define TK_TRUTH 175 -#define TK_REGISTER 176 -#define TK_VECTOR 177 -#define TK_SELECT_COLUMN 178 -#define TK_IF_NULL_ROW 179 -#define TK_ASTERISK 180 -#define TK_SPAN 181 -#define TK_ERROR 182 -#define TK_SPACE 183 -#define TK_ILLEGAL 184 +#define TK_COLLATE 112 +#define TK_BITNOT 113 +#define TK_ON 114 +#define TK_INDEXED 115 +#define TK_STRING 116 +#define TK_JOIN_KW 117 +#define TK_CONSTRAINT 118 +#define TK_DEFAULT 119 +#define TK_NULL 120 +#define TK_PRIMARY 121 +#define TK_UNIQUE 122 +#define TK_CHECK 123 +#define TK_REFERENCES 124 +#define TK_AUTOINCR 125 +#define TK_INSERT 126 +#define TK_DELETE 127 +#define TK_UPDATE 128 +#define TK_SET 129 +#define TK_DEFERRABLE 130 +#define TK_FOREIGN 131 +#define TK_DROP 132 +#define TK_UNION 133 +#define TK_ALL 134 +#define TK_EXCEPT 135 +#define TK_INTERSECT 136 +#define TK_SELECT 137 +#define TK_VALUES 138 +#define TK_DISTINCT 139 +#define TK_DOT 140 +#define TK_FROM 141 +#define TK_JOIN 142 +#define TK_USING 143 +#define TK_ORDER 144 +#define TK_GROUP 145 +#define TK_HAVING 146 +#define TK_LIMIT 147 +#define TK_WHERE 148 +#define TK_RETURNING 149 +#define TK_INTO 150 +#define TK_NOTHING 151 +#define TK_FLOAT 152 +#define TK_BLOB 153 +#define TK_INTEGER 154 +#define TK_VARIABLE 155 +#define TK_CASE 156 +#define TK_WHEN 157 +#define TK_THEN 158 +#define TK_ELSE 159 +#define TK_INDEX 160 +#define TK_ALTER 161 +#define TK_ADD 162 +#define TK_WINDOW 163 +#define TK_OVER 164 +#define TK_FILTER 165 +#define TK_COLUMN 166 +#define TK_AGG_FUNCTION 167 +#define TK_AGG_COLUMN 168 +#define TK_TRUEFALSE 169 +#define TK_ISNOT 170 +#define TK_FUNCTION 171 +#define TK_UMINUS 172 +#define TK_UPLUS 173 +#define TK_TRUTH 174 +#define TK_REGISTER 175 +#define TK_VECTOR 176 +#define TK_SELECT_COLUMN 177 +#define TK_IF_NULL_ROW 178 +#define TK_ASTERISK 179 +#define TK_SPAN 180 +#define TK_ERROR 181 +#define TK_SPACE 182 +#define TK_ILLEGAL 183 #endif /**************** End token definitions ***************************************/ /* The next sections is a series of control #defines. ** various aspects of the generated parser. @@ -161871,34 +159149,34 @@ #ifndef INTERFACE # define INTERFACE 1 #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 319 +#define YYNOCODE 318 #define YYACTIONTYPE unsigned short int #define YYWILDCARD 101 #define sqlite3ParserTOKENTYPE Token typedef union { int yyinit; sqlite3ParserTOKENTYPE yy0; - TriggerStep* yy33; - Window* yy41; - Select* yy47; - SrcList* yy131; - struct TrigEvent yy180; - struct {int value; int mask;} yy231; - IdList* yy254; - u32 yy285; - ExprList* yy322; - Cte* yy385; - int yy394; - Upsert* yy444; - u8 yy516; - With* yy521; - const char* yy522; - Expr* yy528; - struct FrameBound yy595; + With* yy43; + u32 yy51; + int yy64; + struct FrameBound yy81; + struct {int value; int mask;} yy83; + TriggerStep* yy95; + Upsert* yy138; + IdList* yy240; + Cte* yy255; + Select* yy303; + Window* yy375; + u8 yy534; + ExprList* yy562; + struct TrigEvent yy570; + const char* yy600; + SrcList* yy607; + Expr* yy626; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 #endif #define sqlite3ParserARG_SDECL @@ -161910,22 +159188,22 @@ #define sqlite3ParserCTX_PDECL ,Parse *pParse #define sqlite3ParserCTX_PARAM ,pParse #define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse; #define sqlite3ParserCTX_STORE yypParser->pParse=pParse; #define YYFALLBACK 1 -#define YYNSTATE 574 -#define YYNRULE 402 -#define YYNRULE_WITH_ACTION 340 -#define YYNTOKEN 185 -#define YY_MAX_SHIFT 573 -#define YY_MIN_SHIFTREDUCE 831 -#define YY_MAX_SHIFTREDUCE 1232 -#define YY_ERROR_ACTION 1233 -#define YY_ACCEPT_ACTION 1234 -#define YY_NO_ACTION 1235 -#define YY_MIN_REDUCE 1236 -#define YY_MAX_REDUCE 1637 +#define YYNSTATE 572 +#define YYNRULE 401 +#define YYNRULE_WITH_ACTION 339 +#define YYNTOKEN 184 +#define YY_MAX_SHIFT 571 +#define YY_MIN_SHIFTREDUCE 829 +#define YY_MAX_SHIFTREDUCE 1229 +#define YY_ERROR_ACTION 1230 +#define YY_ACCEPT_ACTION 1231 +#define YY_NO_ACTION 1232 +#define YY_MIN_REDUCE 1233 +#define YY_MAX_REDUCE 1633 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) /* Define the yytestcase() macro to be a no-op if is not already defined ** otherwise. @@ -161988,616 +159266,610 @@ ** yy_reduce_ofst[] For each state, the offset into yy_action for ** shifting non-terminals after a reduce. ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (2070) +#define YY_ACTTAB_COUNT (2037) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 566, 1307, 566, 1286, 201, 201, 566, 116, 112, 222, - /* 10 */ 566, 1307, 377, 566, 116, 112, 222, 397, 408, 409, - /* 20 */ 1260, 378, 1269, 41, 41, 41, 41, 1412, 1517, 71, - /* 30 */ 71, 967, 1258, 41, 41, 491, 71, 71, 272, 968, - /* 40 */ 298, 476, 298, 123, 124, 114, 1210, 1210, 1044, 1047, - /* 50 */ 1036, 1036, 121, 121, 122, 122, 122, 122, 543, 409, - /* 60 */ 1234, 1, 1, 573, 2, 1238, 548, 116, 112, 222, - /* 70 */ 309, 480, 142, 548, 1272, 524, 116, 112, 222, 1320, - /* 80 */ 417, 523, 547, 123, 124, 114, 1210, 1210, 1044, 1047, - /* 90 */ 1036, 1036, 121, 121, 122, 122, 122, 122, 424, 116, - /* 100 */ 112, 222, 120, 120, 120, 120, 119, 119, 118, 118, - /* 110 */ 118, 117, 113, 444, 277, 277, 277, 277, 560, 560, - /* 120 */ 560, 1558, 376, 1560, 1186, 375, 1157, 563, 1157, 563, - /* 130 */ 409, 1558, 537, 252, 219, 1553, 99, 141, 449, 6, - /* 140 */ 365, 233, 120, 120, 120, 120, 119, 119, 118, 118, - /* 150 */ 118, 117, 113, 444, 123, 124, 114, 1210, 1210, 1044, - /* 160 */ 1047, 1036, 1036, 121, 121, 122, 122, 122, 122, 138, - /* 170 */ 289, 1186, 1546, 448, 118, 118, 118, 117, 113, 444, - /* 180 */ 125, 1186, 1187, 1188, 144, 465, 334, 566, 150, 127, - /* 190 */ 444, 122, 122, 122, 122, 115, 120, 120, 120, 120, - /* 200 */ 119, 119, 118, 118, 118, 117, 113, 444, 454, 419, - /* 210 */ 13, 13, 215, 120, 120, 120, 120, 119, 119, 118, - /* 220 */ 118, 118, 117, 113, 444, 422, 308, 557, 1186, 1187, - /* 230 */ 1188, 441, 440, 409, 1271, 122, 122, 122, 122, 120, - /* 240 */ 120, 120, 120, 119, 119, 118, 118, 118, 117, 113, - /* 250 */ 444, 1543, 98, 1033, 1033, 1045, 1048, 123, 124, 114, - /* 260 */ 1210, 1210, 1044, 1047, 1036, 1036, 121, 121, 122, 122, - /* 270 */ 122, 122, 566, 406, 405, 1186, 566, 409, 1217, 319, - /* 280 */ 1217, 80, 81, 120, 120, 120, 120, 119, 119, 118, - /* 290 */ 118, 118, 117, 113, 444, 70, 70, 1186, 1604, 71, - /* 300 */ 71, 123, 124, 114, 1210, 1210, 1044, 1047, 1036, 1036, - /* 310 */ 121, 121, 122, 122, 122, 122, 120, 120, 120, 120, - /* 320 */ 119, 119, 118, 118, 118, 117, 113, 444, 1037, 210, - /* 330 */ 1186, 365, 1186, 1187, 1188, 245, 548, 399, 504, 501, - /* 340 */ 500, 108, 558, 138, 4, 516, 933, 433, 499, 217, - /* 350 */ 514, 522, 352, 879, 1186, 1187, 1188, 383, 561, 566, - /* 360 */ 120, 120, 120, 120, 119, 119, 118, 118, 118, 117, - /* 370 */ 113, 444, 277, 277, 16, 16, 1598, 441, 440, 153, - /* 380 */ 409, 445, 13, 13, 1279, 563, 1214, 1186, 1187, 1188, - /* 390 */ 1003, 1216, 264, 555, 1574, 186, 566, 427, 138, 1215, - /* 400 */ 308, 557, 472, 138, 123, 124, 114, 1210, 1210, 1044, - /* 410 */ 1047, 1036, 1036, 121, 121, 122, 122, 122, 122, 55, - /* 420 */ 55, 413, 1023, 507, 1217, 1186, 1217, 474, 106, 106, - /* 430 */ 1312, 1312, 1186, 171, 566, 384, 107, 380, 445, 568, - /* 440 */ 567, 430, 1543, 1013, 332, 549, 565, 263, 280, 360, - /* 450 */ 510, 355, 509, 250, 491, 308, 557, 71, 71, 351, - /* 460 */ 308, 557, 374, 120, 120, 120, 120, 119, 119, 118, - /* 470 */ 118, 118, 117, 113, 444, 1013, 1013, 1015, 1016, 27, - /* 480 */ 277, 277, 1186, 1187, 1188, 1152, 566, 528, 409, 1186, - /* 490 */ 1187, 1188, 348, 563, 548, 1260, 533, 517, 1152, 1516, - /* 500 */ 317, 1152, 285, 550, 485, 569, 566, 569, 482, 51, - /* 510 */ 51, 207, 123, 124, 114, 1210, 1210, 1044, 1047, 1036, - /* 520 */ 1036, 121, 121, 122, 122, 122, 122, 171, 1412, 13, - /* 530 */ 13, 409, 277, 277, 1186, 505, 119, 119, 118, 118, - /* 540 */ 118, 117, 113, 444, 429, 563, 518, 220, 515, 1552, - /* 550 */ 365, 546, 1186, 6, 532, 123, 124, 114, 1210, 1210, - /* 560 */ 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, 122, - /* 570 */ 145, 120, 120, 120, 120, 119, 119, 118, 118, 118, - /* 580 */ 117, 113, 444, 245, 566, 474, 504, 501, 500, 566, - /* 590 */ 1481, 1186, 1187, 1188, 1310, 1310, 499, 1186, 149, 425, - /* 600 */ 1186, 480, 409, 274, 365, 952, 872, 56, 56, 1186, - /* 610 */ 1187, 1188, 71, 71, 120, 120, 120, 120, 119, 119, - /* 620 */ 118, 118, 118, 117, 113, 444, 123, 124, 114, 1210, - /* 630 */ 1210, 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, - /* 640 */ 122, 409, 541, 1552, 83, 865, 98, 6, 928, 529, - /* 650 */ 848, 543, 151, 927, 1186, 1187, 1188, 1186, 1187, 1188, - /* 660 */ 290, 1543, 187, 1633, 395, 123, 124, 114, 1210, 1210, - /* 670 */ 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, 122, - /* 680 */ 566, 954, 566, 453, 953, 120, 120, 120, 120, 119, - /* 690 */ 119, 118, 118, 118, 117, 113, 444, 1152, 221, 1186, - /* 700 */ 331, 453, 452, 13, 13, 13, 13, 1003, 365, 463, - /* 710 */ 1152, 193, 409, 1152, 382, 1543, 1170, 32, 297, 474, - /* 720 */ 195, 1527, 5, 952, 120, 120, 120, 120, 119, 119, - /* 730 */ 118, 118, 118, 117, 113, 444, 123, 124, 114, 1210, - /* 740 */ 1210, 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, - /* 750 */ 122, 409, 1067, 419, 1186, 1024, 1186, 1187, 1188, 1186, - /* 760 */ 419, 332, 460, 320, 544, 1545, 442, 442, 442, 566, - /* 770 */ 3, 117, 113, 444, 453, 123, 124, 114, 1210, 1210, - /* 780 */ 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, 122, - /* 790 */ 1473, 566, 15, 15, 293, 120, 120, 120, 120, 119, - /* 800 */ 119, 118, 118, 118, 117, 113, 444, 1186, 566, 1486, - /* 810 */ 1412, 1186, 1187, 1188, 13, 13, 1186, 1187, 1188, 1544, - /* 820 */ 271, 271, 409, 286, 308, 557, 1008, 1486, 1488, 196, - /* 830 */ 288, 71, 71, 563, 120, 120, 120, 120, 119, 119, - /* 840 */ 118, 118, 118, 117, 113, 444, 123, 124, 114, 1210, - /* 850 */ 1210, 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, - /* 860 */ 122, 409, 201, 1087, 1186, 1187, 1188, 1324, 304, 1529, - /* 870 */ 388, 278, 278, 450, 564, 402, 922, 922, 566, 563, - /* 880 */ 566, 426, 491, 480, 563, 123, 124, 114, 1210, 1210, - /* 890 */ 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, 122, - /* 900 */ 1486, 71, 71, 13, 13, 120, 120, 120, 120, 119, - /* 910 */ 119, 118, 118, 118, 117, 113, 444, 566, 545, 566, - /* 920 */ 1577, 573, 2, 1238, 1092, 1092, 488, 1480, 309, 1525, - /* 930 */ 142, 324, 409, 836, 837, 838, 312, 1320, 305, 363, - /* 940 */ 43, 43, 57, 57, 120, 120, 120, 120, 119, 119, - /* 950 */ 118, 118, 118, 117, 113, 444, 123, 124, 114, 1210, - /* 960 */ 1210, 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, - /* 970 */ 122, 12, 277, 277, 566, 1152, 409, 572, 428, 1238, - /* 980 */ 465, 334, 296, 474, 309, 563, 142, 249, 1152, 308, - /* 990 */ 557, 1152, 321, 1320, 323, 491, 455, 71, 71, 233, - /* 1000 */ 283, 101, 114, 1210, 1210, 1044, 1047, 1036, 1036, 121, - /* 1010 */ 121, 122, 122, 122, 122, 120, 120, 120, 120, 119, - /* 1020 */ 119, 118, 118, 118, 117, 113, 444, 1108, 277, 277, - /* 1030 */ 1412, 448, 394, 1230, 439, 277, 277, 248, 247, 246, - /* 1040 */ 1319, 563, 1109, 313, 198, 294, 491, 1318, 563, 464, - /* 1050 */ 566, 1427, 394, 1130, 1023, 233, 414, 1110, 295, 120, - /* 1060 */ 120, 120, 120, 119, 119, 118, 118, 118, 117, 113, - /* 1070 */ 444, 1014, 104, 71, 71, 1013, 322, 496, 908, 566, - /* 1080 */ 277, 277, 277, 277, 1108, 1261, 415, 448, 909, 361, - /* 1090 */ 1571, 1315, 409, 563, 952, 563, 9, 202, 255, 1109, - /* 1100 */ 316, 487, 44, 44, 249, 559, 415, 1013, 1013, 1015, - /* 1110 */ 443, 1231, 409, 1603, 1110, 897, 123, 124, 114, 1210, - /* 1120 */ 1210, 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, - /* 1130 */ 122, 1231, 409, 1207, 215, 554, 123, 124, 114, 1210, - /* 1140 */ 1210, 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, - /* 1150 */ 122, 1131, 1631, 470, 1631, 255, 123, 111, 114, 1210, - /* 1160 */ 1210, 1044, 1047, 1036, 1036, 121, 121, 122, 122, 122, - /* 1170 */ 122, 1131, 1632, 414, 1632, 120, 120, 120, 120, 119, - /* 1180 */ 119, 118, 118, 118, 117, 113, 444, 221, 209, 351, - /* 1190 */ 1207, 1207, 147, 1426, 491, 120, 120, 120, 120, 119, - /* 1200 */ 119, 118, 118, 118, 117, 113, 444, 1256, 539, 519, - /* 1210 */ 888, 551, 952, 12, 566, 120, 120, 120, 120, 119, - /* 1220 */ 119, 118, 118, 118, 117, 113, 444, 538, 566, 860, - /* 1230 */ 1129, 361, 1571, 346, 1356, 409, 1163, 58, 58, 339, - /* 1240 */ 1355, 508, 277, 277, 277, 277, 277, 277, 1207, 889, - /* 1250 */ 1129, 59, 59, 459, 363, 563, 566, 563, 96, 563, - /* 1260 */ 124, 114, 1210, 1210, 1044, 1047, 1036, 1036, 121, 121, - /* 1270 */ 122, 122, 122, 122, 566, 1412, 566, 281, 1186, 60, - /* 1280 */ 60, 110, 392, 392, 391, 266, 389, 860, 1163, 845, - /* 1290 */ 566, 481, 566, 436, 341, 1152, 344, 61, 61, 62, - /* 1300 */ 62, 967, 227, 1550, 315, 431, 540, 6, 1152, 968, - /* 1310 */ 566, 1152, 314, 45, 45, 46, 46, 512, 120, 120, - /* 1320 */ 120, 120, 119, 119, 118, 118, 118, 117, 113, 444, - /* 1330 */ 416, 173, 1532, 47, 47, 1186, 1187, 1188, 108, 558, - /* 1340 */ 325, 4, 229, 1551, 928, 566, 437, 6, 566, 927, - /* 1350 */ 164, 566, 1290, 137, 1190, 561, 566, 1549, 566, 1089, - /* 1360 */ 566, 6, 566, 1089, 531, 566, 868, 8, 49, 49, - /* 1370 */ 228, 50, 50, 566, 63, 63, 566, 457, 445, 64, - /* 1380 */ 64, 65, 65, 14, 14, 66, 66, 407, 129, 129, - /* 1390 */ 555, 566, 458, 566, 1505, 486, 67, 67, 566, 52, - /* 1400 */ 52, 546, 407, 467, 535, 410, 226, 1023, 566, 534, - /* 1410 */ 308, 557, 1190, 407, 68, 68, 69, 69, 566, 1023, - /* 1420 */ 566, 53, 53, 868, 1014, 106, 106, 525, 1013, 566, - /* 1430 */ 1504, 159, 159, 107, 451, 445, 568, 567, 471, 307, - /* 1440 */ 1013, 160, 160, 76, 76, 566, 1548, 466, 407, 407, - /* 1450 */ 6, 1225, 54, 54, 478, 276, 219, 566, 887, 886, - /* 1460 */ 1013, 1013, 1015, 84, 206, 1206, 230, 282, 72, 72, - /* 1470 */ 329, 483, 1013, 1013, 1015, 1016, 27, 1576, 1174, 447, - /* 1480 */ 130, 130, 281, 148, 105, 38, 103, 392, 392, 391, - /* 1490 */ 266, 389, 566, 1126, 845, 396, 566, 108, 558, 566, - /* 1500 */ 4, 311, 566, 30, 17, 566, 279, 227, 566, 315, - /* 1510 */ 108, 558, 468, 4, 561, 73, 73, 314, 566, 157, - /* 1520 */ 157, 566, 131, 131, 526, 132, 132, 561, 128, 128, - /* 1530 */ 566, 158, 158, 566, 31, 291, 566, 445, 330, 521, - /* 1540 */ 98, 152, 152, 420, 136, 136, 1005, 229, 254, 555, - /* 1550 */ 445, 479, 336, 135, 135, 164, 133, 133, 137, 134, - /* 1560 */ 134, 875, 555, 535, 566, 473, 566, 254, 536, 475, - /* 1570 */ 335, 254, 98, 894, 895, 228, 535, 566, 1023, 566, - /* 1580 */ 1074, 534, 210, 232, 106, 106, 1352, 75, 75, 77, - /* 1590 */ 77, 1023, 107, 340, 445, 568, 567, 106, 106, 1013, - /* 1600 */ 74, 74, 42, 42, 566, 107, 343, 445, 568, 567, - /* 1610 */ 410, 497, 1013, 251, 359, 308, 557, 1135, 349, 875, - /* 1620 */ 98, 1070, 345, 251, 358, 1591, 347, 48, 48, 1017, - /* 1630 */ 1303, 1013, 1013, 1015, 1016, 27, 1289, 1287, 1074, 451, - /* 1640 */ 961, 925, 254, 110, 1013, 1013, 1015, 1016, 27, 1174, - /* 1650 */ 447, 970, 971, 281, 108, 558, 1288, 4, 392, 392, - /* 1660 */ 391, 266, 389, 1343, 1086, 845, 1086, 1085, 858, 1085, - /* 1670 */ 146, 561, 926, 354, 110, 303, 364, 553, 227, 1364, - /* 1680 */ 315, 108, 558, 1411, 4, 1339, 492, 1017, 314, 1350, - /* 1690 */ 1565, 552, 1417, 1268, 445, 204, 1259, 1247, 561, 1246, - /* 1700 */ 1248, 1584, 269, 1336, 367, 369, 555, 371, 11, 212, - /* 1710 */ 393, 225, 1393, 284, 1398, 456, 287, 327, 229, 328, - /* 1720 */ 292, 445, 1386, 216, 333, 1403, 164, 477, 373, 137, - /* 1730 */ 1402, 400, 502, 555, 1286, 1023, 357, 1477, 199, 1587, - /* 1740 */ 211, 106, 106, 932, 1476, 1225, 228, 556, 175, 107, - /* 1750 */ 200, 445, 568, 567, 258, 387, 1013, 1524, 1522, 223, - /* 1760 */ 1222, 418, 1023, 83, 208, 79, 82, 184, 106, 106, - /* 1770 */ 1482, 169, 177, 461, 179, 462, 107, 1399, 445, 568, - /* 1780 */ 567, 410, 180, 1013, 495, 181, 308, 557, 1013, 1013, - /* 1790 */ 1015, 1016, 27, 182, 35, 235, 100, 558, 398, 4, - /* 1800 */ 96, 1405, 1404, 36, 484, 469, 1407, 188, 401, 1471, - /* 1810 */ 451, 89, 1493, 561, 239, 1013, 1013, 1015, 1016, 27, - /* 1820 */ 490, 338, 270, 241, 192, 342, 493, 242, 403, 1249, - /* 1830 */ 243, 511, 432, 1297, 1306, 91, 445, 1305, 1304, 879, - /* 1840 */ 217, 434, 435, 1570, 1276, 1602, 520, 1601, 555, 301, - /* 1850 */ 527, 404, 1275, 302, 356, 1274, 1600, 95, 1347, 366, - /* 1860 */ 1296, 362, 1348, 368, 256, 257, 1556, 1555, 438, 1346, - /* 1870 */ 370, 126, 1345, 10, 1371, 546, 381, 1023, 102, 1457, - /* 1880 */ 97, 530, 34, 106, 106, 570, 1180, 372, 265, 1329, - /* 1890 */ 379, 107, 203, 445, 568, 567, 1328, 385, 1013, 1370, - /* 1900 */ 386, 267, 268, 571, 1244, 161, 1239, 162, 1509, 1510, - /* 1910 */ 1508, 143, 1507, 299, 832, 213, 214, 78, 446, 205, - /* 1920 */ 310, 306, 163, 224, 1084, 140, 1082, 318, 165, 176, - /* 1930 */ 1013, 1013, 1015, 1016, 27, 178, 1206, 231, 911, 234, - /* 1940 */ 326, 1098, 183, 421, 166, 167, 411, 185, 85, 423, - /* 1950 */ 412, 86, 174, 87, 168, 88, 1101, 236, 1097, 237, - /* 1960 */ 154, 18, 238, 254, 337, 1219, 489, 1090, 240, 190, - /* 1970 */ 37, 847, 189, 494, 358, 244, 350, 506, 191, 877, - /* 1980 */ 90, 498, 19, 20, 503, 92, 353, 890, 300, 170, - /* 1990 */ 155, 93, 513, 94, 1168, 156, 1050, 1137, 39, 218, - /* 2000 */ 273, 275, 1136, 960, 194, 955, 110, 1154, 1158, 253, - /* 2010 */ 7, 1162, 1156, 21, 22, 1161, 1142, 23, 24, 25, - /* 2020 */ 33, 542, 26, 260, 197, 98, 1065, 1051, 1049, 1053, - /* 2030 */ 1107, 1054, 1106, 259, 28, 40, 562, 1018, 859, 109, - /* 2040 */ 29, 921, 390, 1176, 172, 139, 1175, 1235, 261, 1235, - /* 2050 */ 1235, 1235, 1235, 1235, 1235, 1235, 1235, 262, 1235, 1235, - /* 2060 */ 1235, 1235, 1235, 1235, 1235, 1235, 1235, 1235, 1593, 1592, + /* 0 */ 564, 115, 112, 220, 169, 199, 115, 112, 220, 564, + /* 10 */ 375, 1266, 564, 376, 564, 270, 1309, 1309, 406, 407, + /* 20 */ 1084, 199, 1513, 41, 41, 515, 489, 521, 558, 558, + /* 30 */ 558, 965, 41, 41, 395, 41, 41, 51, 51, 966, + /* 40 */ 296, 1269, 296, 122, 123, 113, 1207, 1207, 1041, 1044, + /* 50 */ 1034, 1034, 120, 120, 121, 121, 121, 121, 564, 407, + /* 60 */ 275, 275, 275, 275, 1268, 115, 112, 220, 115, 112, + /* 70 */ 220, 1512, 846, 561, 516, 561, 115, 112, 220, 250, + /* 80 */ 217, 71, 71, 122, 123, 113, 1207, 1207, 1041, 1044, + /* 90 */ 1034, 1034, 120, 120, 121, 121, 121, 121, 440, 440, + /* 100 */ 440, 1149, 119, 119, 119, 119, 118, 118, 117, 117, + /* 110 */ 117, 116, 442, 1183, 1149, 116, 442, 1149, 546, 513, + /* 120 */ 1548, 1554, 374, 442, 6, 1183, 1154, 522, 1154, 407, + /* 130 */ 1556, 461, 373, 1554, 535, 99, 463, 332, 121, 121, + /* 140 */ 121, 121, 119, 119, 119, 119, 118, 118, 117, 117, + /* 150 */ 117, 116, 442, 122, 123, 113, 1207, 1207, 1041, 1044, + /* 160 */ 1034, 1034, 120, 120, 121, 121, 121, 121, 1257, 1183, + /* 170 */ 1184, 1185, 243, 1064, 564, 502, 499, 498, 567, 124, + /* 180 */ 567, 1183, 1184, 1185, 474, 497, 119, 119, 119, 119, + /* 190 */ 118, 118, 117, 117, 117, 116, 442, 70, 70, 407, + /* 200 */ 121, 121, 121, 121, 114, 117, 117, 117, 116, 442, + /* 210 */ 1409, 1469, 119, 119, 119, 119, 118, 118, 117, 117, + /* 220 */ 117, 116, 442, 122, 123, 113, 1207, 1207, 1041, 1044, + /* 230 */ 1034, 1034, 120, 120, 121, 121, 121, 121, 407, 1031, + /* 240 */ 1031, 1042, 1045, 81, 382, 541, 378, 80, 119, 119, + /* 250 */ 119, 119, 118, 118, 117, 117, 117, 116, 442, 381, + /* 260 */ 463, 332, 122, 123, 113, 1207, 1207, 1041, 1044, 1034, + /* 270 */ 1034, 120, 120, 121, 121, 121, 121, 262, 215, 512, + /* 280 */ 1424, 422, 119, 119, 119, 119, 118, 118, 117, 117, + /* 290 */ 117, 116, 442, 1231, 1, 1, 571, 2, 1235, 1573, + /* 300 */ 571, 2, 1235, 307, 1149, 141, 1600, 307, 407, 141, + /* 310 */ 1183, 361, 1317, 1035, 866, 531, 1317, 1149, 359, 1567, + /* 320 */ 1149, 119, 119, 119, 119, 118, 118, 117, 117, 117, + /* 330 */ 116, 442, 122, 123, 113, 1207, 1207, 1041, 1044, 1034, + /* 340 */ 1034, 120, 120, 121, 121, 121, 121, 275, 275, 1001, + /* 350 */ 426, 275, 275, 1128, 1627, 1021, 1627, 137, 542, 1541, + /* 360 */ 561, 272, 950, 950, 561, 1423, 1183, 1184, 1185, 1594, + /* 370 */ 866, 1012, 530, 315, 231, 1011, 468, 1276, 231, 119, + /* 380 */ 119, 119, 119, 118, 118, 117, 117, 117, 116, 442, + /* 390 */ 1570, 119, 119, 119, 119, 118, 118, 117, 117, 117, + /* 400 */ 116, 442, 330, 359, 1567, 564, 446, 1011, 1011, 1013, + /* 410 */ 446, 207, 564, 306, 555, 407, 363, 1021, 363, 346, + /* 420 */ 184, 118, 118, 117, 117, 117, 116, 442, 71, 71, + /* 430 */ 439, 438, 1126, 1012, 472, 71, 71, 1011, 205, 122, + /* 440 */ 123, 113, 1207, 1207, 1041, 1044, 1034, 1034, 120, 120, + /* 450 */ 121, 121, 121, 121, 219, 219, 472, 1183, 407, 570, + /* 460 */ 1183, 1235, 503, 1477, 149, 546, 307, 489, 141, 1011, + /* 470 */ 1011, 1013, 546, 140, 545, 1317, 1214, 191, 1214, 950, + /* 480 */ 950, 514, 122, 123, 113, 1207, 1207, 1041, 1044, 1034, + /* 490 */ 1034, 120, 120, 121, 121, 121, 121, 563, 119, 119, + /* 500 */ 119, 119, 118, 118, 117, 117, 117, 116, 442, 283, + /* 510 */ 275, 275, 415, 1183, 1184, 1185, 1183, 1184, 1185, 372, + /* 520 */ 1183, 243, 344, 561, 502, 499, 498, 1539, 407, 1540, + /* 530 */ 1183, 288, 870, 143, 497, 1549, 185, 231, 9, 6, + /* 540 */ 253, 119, 119, 119, 119, 118, 118, 117, 117, 117, + /* 550 */ 116, 442, 122, 123, 113, 1207, 1207, 1041, 1044, 1034, + /* 560 */ 1034, 120, 120, 121, 121, 121, 121, 407, 137, 446, + /* 570 */ 447, 863, 169, 1183, 397, 1204, 1183, 1184, 1185, 931, + /* 580 */ 526, 1001, 98, 339, 564, 342, 1183, 1184, 1185, 306, + /* 590 */ 555, 122, 123, 113, 1207, 1207, 1041, 1044, 1034, 1034, + /* 600 */ 120, 120, 121, 121, 121, 121, 452, 71, 71, 275, + /* 610 */ 275, 119, 119, 119, 119, 118, 118, 117, 117, 117, + /* 620 */ 116, 442, 561, 417, 306, 555, 1183, 1307, 1307, 1183, + /* 630 */ 1184, 1185, 1204, 1149, 330, 458, 318, 407, 363, 470, + /* 640 */ 431, 1167, 32, 541, 527, 350, 1149, 1629, 393, 1149, + /* 650 */ 119, 119, 119, 119, 118, 118, 117, 117, 117, 116, + /* 660 */ 442, 122, 123, 113, 1207, 1207, 1041, 1044, 1034, 1034, + /* 670 */ 120, 120, 121, 121, 121, 121, 407, 199, 472, 1183, + /* 680 */ 1022, 472, 1183, 1184, 1185, 386, 151, 539, 1548, 277, + /* 690 */ 400, 137, 6, 317, 5, 564, 562, 3, 920, 920, + /* 700 */ 122, 123, 113, 1207, 1207, 1041, 1044, 1034, 1034, 120, + /* 710 */ 120, 121, 121, 121, 121, 411, 505, 83, 71, 71, + /* 720 */ 119, 119, 119, 119, 118, 118, 117, 117, 117, 116, + /* 730 */ 442, 1183, 218, 428, 1183, 1183, 1184, 1185, 363, 261, + /* 740 */ 278, 358, 508, 353, 507, 248, 407, 306, 555, 1539, + /* 750 */ 1006, 349, 363, 291, 489, 302, 293, 1542, 281, 119, + /* 760 */ 119, 119, 119, 118, 118, 117, 117, 117, 116, 442, + /* 770 */ 122, 123, 113, 1207, 1207, 1041, 1044, 1034, 1034, 120, + /* 780 */ 120, 121, 121, 121, 121, 407, 148, 1183, 1184, 1185, + /* 790 */ 1183, 1184, 1185, 275, 275, 1304, 1257, 1283, 483, 1476, + /* 800 */ 150, 489, 480, 564, 1187, 1304, 561, 1587, 1255, 122, + /* 810 */ 123, 113, 1207, 1207, 1041, 1044, 1034, 1034, 120, 120, + /* 820 */ 121, 121, 121, 121, 564, 886, 13, 13, 520, 119, + /* 830 */ 119, 119, 119, 118, 118, 117, 117, 117, 116, 442, + /* 840 */ 1183, 420, 417, 564, 269, 269, 1316, 13, 13, 1539, + /* 850 */ 1546, 16, 16, 322, 6, 407, 506, 561, 1089, 1089, + /* 860 */ 486, 1187, 425, 1539, 887, 292, 71, 71, 119, 119, + /* 870 */ 119, 119, 118, 118, 117, 117, 117, 116, 442, 122, + /* 880 */ 123, 113, 1207, 1207, 1041, 1044, 1034, 1034, 120, 120, + /* 890 */ 121, 121, 121, 121, 564, 12, 1183, 1184, 1185, 407, + /* 900 */ 275, 275, 451, 303, 834, 835, 836, 417, 489, 276, + /* 910 */ 276, 1547, 284, 561, 319, 6, 321, 71, 71, 429, + /* 920 */ 451, 450, 561, 952, 101, 113, 1207, 1207, 1041, 1044, + /* 930 */ 1034, 1034, 120, 120, 121, 121, 121, 121, 119, 119, + /* 940 */ 119, 119, 118, 118, 117, 117, 117, 116, 442, 1105, + /* 950 */ 1183, 489, 564, 1312, 437, 455, 478, 564, 246, 245, + /* 960 */ 244, 1409, 1545, 547, 1106, 405, 6, 1544, 196, 1258, + /* 970 */ 413, 6, 105, 462, 103, 71, 71, 286, 564, 1107, + /* 980 */ 13, 13, 119, 119, 119, 119, 118, 118, 117, 117, + /* 990 */ 117, 116, 442, 451, 104, 427, 337, 320, 275, 275, + /* 1000 */ 906, 13, 13, 564, 1482, 1105, 1183, 1184, 1185, 126, + /* 1010 */ 907, 561, 546, 564, 407, 478, 295, 1321, 253, 200, + /* 1020 */ 1106, 548, 1482, 1484, 280, 1409, 55, 55, 1287, 561, + /* 1030 */ 478, 380, 423, 951, 407, 1107, 71, 71, 122, 123, + /* 1040 */ 113, 1207, 1207, 1041, 1044, 1034, 1034, 120, 120, 121, + /* 1050 */ 121, 121, 121, 1204, 407, 287, 552, 309, 122, 123, + /* 1060 */ 113, 1207, 1207, 1041, 1044, 1034, 1034, 120, 120, 121, + /* 1070 */ 121, 121, 121, 441, 1128, 1628, 146, 1628, 122, 111, + /* 1080 */ 113, 1207, 1207, 1041, 1044, 1034, 1034, 120, 120, 121, + /* 1090 */ 121, 121, 121, 404, 403, 1482, 424, 119, 119, 119, + /* 1100 */ 119, 118, 118, 117, 117, 117, 116, 442, 1183, 564, + /* 1110 */ 1204, 544, 1086, 858, 329, 361, 1086, 119, 119, 119, + /* 1120 */ 119, 118, 118, 117, 117, 117, 116, 442, 564, 294, + /* 1130 */ 144, 523, 56, 56, 224, 564, 510, 119, 119, 119, + /* 1140 */ 119, 118, 118, 117, 117, 117, 116, 442, 484, 1409, + /* 1150 */ 537, 15, 15, 1126, 434, 439, 438, 407, 13, 13, + /* 1160 */ 1523, 12, 926, 1211, 1183, 1184, 1185, 925, 1213, 536, + /* 1170 */ 858, 557, 413, 193, 1525, 494, 1212, 448, 1160, 1222, + /* 1180 */ 1183, 564, 123, 113, 1207, 1207, 1041, 1044, 1034, 1034, + /* 1190 */ 120, 120, 121, 121, 121, 121, 1521, 1149, 564, 965, + /* 1200 */ 564, 1214, 247, 1214, 13, 13, 1409, 966, 538, 564, + /* 1210 */ 1149, 108, 556, 1149, 4, 310, 392, 1227, 17, 194, + /* 1220 */ 485, 43, 43, 57, 57, 306, 555, 524, 559, 1160, + /* 1230 */ 464, 564, 44, 44, 392, 1127, 1183, 1184, 1185, 479, + /* 1240 */ 119, 119, 119, 119, 118, 118, 117, 117, 117, 116, + /* 1250 */ 442, 443, 564, 327, 13, 13, 564, 418, 1315, 414, + /* 1260 */ 171, 564, 311, 553, 213, 529, 1253, 564, 517, 543, + /* 1270 */ 412, 108, 556, 137, 4, 58, 58, 435, 314, 59, + /* 1280 */ 59, 274, 217, 549, 60, 60, 349, 476, 559, 1353, + /* 1290 */ 61, 61, 1021, 275, 275, 1228, 213, 564, 106, 106, + /* 1300 */ 8, 275, 275, 275, 275, 107, 561, 443, 566, 565, + /* 1310 */ 564, 443, 1011, 1228, 561, 564, 561, 564, 275, 275, + /* 1320 */ 62, 62, 1352, 553, 247, 456, 564, 98, 110, 306, + /* 1330 */ 555, 561, 564, 45, 45, 405, 1203, 533, 46, 46, + /* 1340 */ 47, 47, 532, 465, 1011, 1011, 1013, 1014, 27, 49, + /* 1350 */ 49, 564, 1021, 405, 469, 50, 50, 564, 106, 106, + /* 1360 */ 305, 564, 84, 204, 405, 107, 564, 443, 566, 565, + /* 1370 */ 405, 564, 1011, 564, 63, 63, 564, 1599, 564, 895, + /* 1380 */ 64, 64, 457, 477, 65, 65, 147, 96, 38, 14, + /* 1390 */ 14, 1528, 412, 564, 66, 66, 128, 128, 926, 67, + /* 1400 */ 67, 52, 52, 925, 1011, 1011, 1013, 1014, 27, 1572, + /* 1410 */ 1171, 445, 208, 1123, 279, 394, 68, 68, 228, 390, + /* 1420 */ 390, 389, 264, 387, 1171, 445, 843, 877, 279, 108, + /* 1430 */ 556, 453, 4, 390, 390, 389, 264, 387, 564, 225, + /* 1440 */ 843, 313, 328, 1003, 98, 252, 559, 544, 471, 312, + /* 1450 */ 252, 564, 208, 225, 564, 313, 473, 30, 252, 279, + /* 1460 */ 466, 69, 69, 312, 390, 390, 389, 264, 387, 443, + /* 1470 */ 333, 843, 98, 564, 53, 53, 323, 157, 157, 227, + /* 1480 */ 495, 553, 249, 289, 225, 564, 313, 162, 31, 1501, + /* 1490 */ 135, 564, 1500, 227, 312, 533, 158, 158, 885, 884, + /* 1500 */ 534, 162, 873, 301, 135, 564, 481, 226, 76, 76, + /* 1510 */ 1021, 347, 1071, 98, 54, 54, 106, 106, 1067, 564, + /* 1520 */ 249, 226, 519, 107, 227, 443, 566, 565, 72, 72, + /* 1530 */ 1011, 334, 162, 564, 230, 135, 108, 556, 959, 4, + /* 1540 */ 252, 408, 129, 129, 564, 1349, 306, 555, 564, 923, + /* 1550 */ 564, 110, 226, 559, 564, 408, 73, 73, 564, 873, + /* 1560 */ 306, 555, 1011, 1011, 1013, 1014, 27, 130, 130, 1071, + /* 1570 */ 449, 131, 131, 127, 127, 357, 443, 156, 156, 892, + /* 1580 */ 893, 155, 155, 338, 449, 356, 408, 564, 553, 968, + /* 1590 */ 969, 306, 555, 1015, 341, 564, 108, 556, 564, 4, + /* 1600 */ 1132, 1286, 533, 564, 856, 343, 145, 532, 345, 1300, + /* 1610 */ 136, 136, 1083, 559, 1083, 449, 564, 1021, 134, 134, + /* 1620 */ 1284, 132, 132, 106, 106, 1285, 133, 133, 564, 352, + /* 1630 */ 107, 564, 443, 566, 565, 1340, 443, 1011, 362, 75, + /* 1640 */ 75, 1082, 564, 1082, 564, 924, 1561, 110, 553, 551, + /* 1650 */ 1015, 77, 77, 1361, 74, 74, 1408, 1336, 1347, 550, + /* 1660 */ 1414, 1265, 1256, 1244, 1243, 42, 42, 48, 48, 1011, + /* 1670 */ 1011, 1013, 1014, 27, 1245, 1580, 490, 1021, 267, 202, + /* 1680 */ 1333, 365, 11, 106, 106, 930, 367, 210, 369, 391, + /* 1690 */ 107, 1395, 443, 566, 565, 223, 1390, 1011, 500, 454, + /* 1700 */ 282, 1400, 285, 108, 556, 214, 4, 325, 1383, 1283, + /* 1710 */ 475, 355, 1473, 1583, 1472, 1399, 371, 1222, 326, 398, + /* 1720 */ 559, 290, 331, 197, 100, 556, 209, 4, 198, 1011, + /* 1730 */ 1011, 1013, 1014, 27, 385, 256, 1520, 1518, 554, 1219, + /* 1740 */ 416, 559, 83, 443, 173, 206, 182, 221, 459, 167, + /* 1750 */ 177, 460, 175, 493, 233, 553, 79, 178, 1396, 179, + /* 1760 */ 35, 180, 96, 1402, 443, 396, 36, 467, 1478, 1401, + /* 1770 */ 482, 237, 1404, 399, 82, 186, 553, 1467, 89, 488, + /* 1780 */ 190, 268, 239, 491, 1021, 340, 240, 401, 1246, 1489, + /* 1790 */ 106, 106, 336, 509, 1294, 241, 1303, 107, 430, 443, + /* 1800 */ 566, 565, 1302, 91, 1011, 1021, 1598, 1301, 1273, 215, + /* 1810 */ 1597, 106, 106, 402, 877, 432, 354, 1272, 107, 1271, + /* 1820 */ 443, 566, 565, 1596, 1566, 1011, 1293, 433, 518, 299, + /* 1830 */ 300, 360, 95, 525, 1344, 364, 1011, 1011, 1013, 1014, + /* 1840 */ 27, 254, 255, 1552, 436, 1551, 125, 544, 10, 379, + /* 1850 */ 1326, 1453, 102, 97, 1345, 528, 304, 1011, 1011, 1013, + /* 1860 */ 1014, 27, 366, 377, 1343, 1342, 368, 370, 1325, 384, + /* 1870 */ 201, 383, 34, 1368, 1367, 568, 1177, 266, 263, 265, + /* 1880 */ 1505, 159, 569, 1241, 1236, 1506, 160, 142, 1504, 1503, + /* 1890 */ 297, 211, 830, 161, 212, 78, 444, 203, 308, 222, + /* 1900 */ 1081, 139, 1079, 316, 174, 163, 1203, 229, 176, 909, + /* 1910 */ 324, 232, 1095, 181, 409, 410, 172, 164, 165, 419, + /* 1920 */ 183, 85, 86, 421, 166, 87, 88, 1098, 1094, 234, + /* 1930 */ 235, 152, 18, 236, 335, 1087, 1216, 252, 187, 487, + /* 1940 */ 238, 188, 37, 845, 492, 356, 242, 496, 351, 501, + /* 1950 */ 189, 90, 19, 504, 348, 20, 875, 92, 298, 168, + /* 1960 */ 888, 153, 93, 511, 94, 1165, 154, 1047, 1134, 39, + /* 1970 */ 216, 1133, 271, 273, 958, 192, 953, 110, 1151, 1155, + /* 1980 */ 251, 7, 21, 1159, 1139, 22, 1153, 33, 23, 24, + /* 1990 */ 25, 540, 1158, 195, 98, 1062, 26, 1048, 1046, 1050, + /* 2000 */ 1104, 1051, 1103, 257, 258, 28, 40, 1173, 1016, 857, + /* 2010 */ 109, 29, 560, 388, 138, 1172, 259, 170, 260, 1232, + /* 2020 */ 1232, 919, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, + /* 2030 */ 1232, 1232, 1589, 1232, 1232, 1232, 1588, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 193, 223, 193, 225, 193, 193, 193, 274, 275, 276, - /* 10 */ 193, 233, 219, 193, 274, 275, 276, 206, 206, 19, - /* 20 */ 193, 219, 216, 216, 217, 216, 217, 193, 295, 216, - /* 30 */ 217, 31, 205, 216, 217, 193, 216, 217, 213, 39, - /* 40 */ 228, 193, 230, 43, 44, 45, 46, 47, 48, 49, - /* 50 */ 50, 51, 52, 53, 54, 55, 56, 57, 193, 19, - /* 60 */ 185, 186, 187, 188, 189, 190, 253, 274, 275, 276, - /* 70 */ 195, 193, 197, 253, 216, 262, 274, 275, 276, 204, - /* 80 */ 238, 204, 262, 43, 44, 45, 46, 47, 48, 49, - /* 90 */ 50, 51, 52, 53, 54, 55, 56, 57, 264, 274, - /* 100 */ 275, 276, 102, 103, 104, 105, 106, 107, 108, 109, - /* 110 */ 110, 111, 112, 113, 239, 240, 239, 240, 210, 211, - /* 120 */ 212, 314, 315, 314, 59, 316, 86, 252, 88, 252, - /* 130 */ 19, 314, 315, 256, 257, 309, 25, 72, 296, 313, - /* 140 */ 193, 266, 102, 103, 104, 105, 106, 107, 108, 109, - /* 150 */ 110, 111, 112, 113, 43, 44, 45, 46, 47, 48, - /* 160 */ 49, 50, 51, 52, 53, 54, 55, 56, 57, 81, - /* 170 */ 292, 59, 307, 298, 108, 109, 110, 111, 112, 113, - /* 180 */ 69, 116, 117, 118, 72, 128, 129, 193, 241, 22, - /* 190 */ 113, 54, 55, 56, 57, 58, 102, 103, 104, 105, - /* 200 */ 106, 107, 108, 109, 110, 111, 112, 113, 120, 193, - /* 210 */ 216, 217, 25, 102, 103, 104, 105, 106, 107, 108, - /* 220 */ 109, 110, 111, 112, 113, 231, 138, 139, 116, 117, - /* 230 */ 118, 106, 107, 19, 216, 54, 55, 56, 57, 102, - /* 240 */ 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, - /* 250 */ 113, 304, 25, 46, 47, 48, 49, 43, 44, 45, - /* 260 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, - /* 270 */ 56, 57, 193, 106, 107, 59, 193, 19, 153, 263, - /* 280 */ 155, 67, 24, 102, 103, 104, 105, 106, 107, 108, - /* 290 */ 109, 110, 111, 112, 113, 216, 217, 59, 230, 216, - /* 300 */ 217, 43, 44, 45, 46, 47, 48, 49, 50, 51, - /* 310 */ 52, 53, 54, 55, 56, 57, 102, 103, 104, 105, - /* 320 */ 106, 107, 108, 109, 110, 111, 112, 113, 121, 142, - /* 330 */ 59, 193, 116, 117, 118, 119, 253, 204, 122, 123, - /* 340 */ 124, 19, 20, 81, 22, 262, 108, 19, 132, 165, - /* 350 */ 166, 193, 24, 126, 116, 117, 118, 278, 36, 193, - /* 360 */ 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, - /* 370 */ 112, 113, 239, 240, 216, 217, 215, 106, 107, 241, - /* 380 */ 19, 59, 216, 217, 223, 252, 115, 116, 117, 118, - /* 390 */ 73, 120, 26, 71, 193, 22, 193, 231, 81, 128, - /* 400 */ 138, 139, 269, 81, 43, 44, 45, 46, 47, 48, - /* 410 */ 49, 50, 51, 52, 53, 54, 55, 56, 57, 216, - /* 420 */ 217, 198, 100, 95, 153, 59, 155, 193, 106, 107, - /* 430 */ 235, 236, 59, 193, 193, 249, 114, 251, 116, 117, - /* 440 */ 118, 113, 304, 121, 127, 204, 193, 119, 120, 121, - /* 450 */ 122, 123, 124, 125, 193, 138, 139, 216, 217, 131, - /* 460 */ 138, 139, 193, 102, 103, 104, 105, 106, 107, 108, - /* 470 */ 109, 110, 111, 112, 113, 153, 154, 155, 156, 157, - /* 480 */ 239, 240, 116, 117, 118, 76, 193, 193, 19, 116, - /* 490 */ 117, 118, 23, 252, 253, 193, 87, 204, 89, 238, - /* 500 */ 193, 92, 268, 262, 281, 203, 193, 205, 285, 216, - /* 510 */ 217, 150, 43, 44, 45, 46, 47, 48, 49, 50, - /* 520 */ 51, 52, 53, 54, 55, 56, 57, 193, 193, 216, - /* 530 */ 217, 19, 239, 240, 59, 23, 106, 107, 108, 109, - /* 540 */ 110, 111, 112, 113, 231, 252, 253, 193, 308, 309, - /* 550 */ 193, 145, 59, 313, 145, 43, 44, 45, 46, 47, - /* 560 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - /* 570 */ 164, 102, 103, 104, 105, 106, 107, 108, 109, 110, - /* 580 */ 111, 112, 113, 119, 193, 193, 122, 123, 124, 193, - /* 590 */ 283, 116, 117, 118, 235, 236, 132, 59, 241, 264, - /* 600 */ 59, 193, 19, 23, 193, 25, 23, 216, 217, 116, - /* 610 */ 117, 118, 216, 217, 102, 103, 104, 105, 106, 107, - /* 620 */ 108, 109, 110, 111, 112, 113, 43, 44, 45, 46, - /* 630 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, - /* 640 */ 57, 19, 308, 309, 151, 23, 25, 313, 135, 253, - /* 650 */ 21, 193, 241, 140, 116, 117, 118, 116, 117, 118, - /* 660 */ 268, 304, 22, 301, 302, 43, 44, 45, 46, 47, - /* 670 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - /* 680 */ 193, 143, 193, 193, 143, 102, 103, 104, 105, 106, - /* 690 */ 107, 108, 109, 110, 111, 112, 113, 76, 118, 59, - /* 700 */ 292, 211, 212, 216, 217, 216, 217, 73, 193, 80, - /* 710 */ 89, 25, 19, 92, 193, 304, 23, 22, 231, 193, - /* 720 */ 231, 193, 22, 143, 102, 103, 104, 105, 106, 107, - /* 730 */ 108, 109, 110, 111, 112, 113, 43, 44, 45, 46, - /* 740 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, - /* 750 */ 57, 19, 123, 193, 59, 23, 116, 117, 118, 59, - /* 760 */ 193, 127, 128, 129, 306, 307, 210, 211, 212, 193, - /* 770 */ 22, 111, 112, 113, 284, 43, 44, 45, 46, 47, - /* 780 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - /* 790 */ 161, 193, 216, 217, 268, 102, 103, 104, 105, 106, - /* 800 */ 107, 108, 109, 110, 111, 112, 113, 59, 193, 193, - /* 810 */ 193, 116, 117, 118, 216, 217, 116, 117, 118, 304, - /* 820 */ 239, 240, 19, 263, 138, 139, 23, 211, 212, 231, - /* 830 */ 263, 216, 217, 252, 102, 103, 104, 105, 106, 107, - /* 840 */ 108, 109, 110, 111, 112, 113, 43, 44, 45, 46, - /* 850 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, - /* 860 */ 57, 19, 193, 11, 116, 117, 118, 240, 253, 193, - /* 870 */ 201, 239, 240, 193, 134, 206, 136, 137, 193, 252, - /* 880 */ 193, 264, 193, 193, 252, 43, 44, 45, 46, 47, - /* 890 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - /* 900 */ 284, 216, 217, 216, 217, 102, 103, 104, 105, 106, - /* 910 */ 107, 108, 109, 110, 111, 112, 113, 193, 231, 193, - /* 920 */ 187, 188, 189, 190, 127, 128, 129, 238, 195, 193, - /* 930 */ 197, 16, 19, 7, 8, 9, 193, 204, 253, 193, - /* 940 */ 216, 217, 216, 217, 102, 103, 104, 105, 106, 107, - /* 950 */ 108, 109, 110, 111, 112, 113, 43, 44, 45, 46, - /* 960 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, - /* 970 */ 57, 213, 239, 240, 193, 76, 19, 188, 232, 190, - /* 980 */ 128, 129, 292, 193, 195, 252, 197, 46, 89, 138, - /* 990 */ 139, 92, 77, 204, 79, 193, 269, 216, 217, 266, - /* 1000 */ 204, 159, 45, 46, 47, 48, 49, 50, 51, 52, - /* 1010 */ 53, 54, 55, 56, 57, 102, 103, 104, 105, 106, - /* 1020 */ 107, 108, 109, 110, 111, 112, 113, 12, 239, 240, - /* 1030 */ 193, 298, 22, 23, 253, 239, 240, 127, 128, 129, - /* 1040 */ 238, 252, 27, 193, 286, 204, 193, 204, 252, 291, - /* 1050 */ 193, 273, 22, 23, 100, 266, 115, 42, 268, 102, - /* 1060 */ 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, - /* 1070 */ 113, 117, 159, 216, 217, 121, 161, 19, 63, 193, - /* 1080 */ 239, 240, 239, 240, 12, 208, 209, 298, 73, 311, - /* 1090 */ 312, 238, 19, 252, 25, 252, 22, 24, 24, 27, - /* 1100 */ 193, 264, 216, 217, 46, 208, 209, 153, 154, 155, - /* 1110 */ 253, 101, 19, 23, 42, 25, 43, 44, 45, 46, - /* 1120 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, - /* 1130 */ 57, 101, 19, 59, 25, 63, 43, 44, 45, 46, - /* 1140 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, - /* 1150 */ 57, 22, 23, 115, 25, 24, 43, 44, 45, 46, - /* 1160 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, - /* 1170 */ 57, 22, 23, 115, 25, 102, 103, 104, 105, 106, - /* 1180 */ 107, 108, 109, 110, 111, 112, 113, 118, 150, 131, - /* 1190 */ 59, 117, 22, 273, 193, 102, 103, 104, 105, 106, - /* 1200 */ 107, 108, 109, 110, 111, 112, 113, 204, 66, 204, - /* 1210 */ 35, 204, 143, 213, 193, 102, 103, 104, 105, 106, - /* 1220 */ 107, 108, 109, 110, 111, 112, 113, 85, 193, 59, - /* 1230 */ 101, 311, 312, 16, 193, 19, 94, 216, 217, 238, - /* 1240 */ 193, 66, 239, 240, 239, 240, 239, 240, 117, 74, - /* 1250 */ 101, 216, 217, 193, 193, 252, 193, 252, 149, 252, - /* 1260 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, - /* 1270 */ 54, 55, 56, 57, 193, 193, 193, 5, 59, 216, - /* 1280 */ 217, 25, 10, 11, 12, 13, 14, 117, 146, 17, - /* 1290 */ 193, 291, 193, 232, 77, 76, 79, 216, 217, 216, - /* 1300 */ 217, 31, 30, 309, 32, 130, 87, 313, 89, 39, - /* 1310 */ 193, 92, 40, 216, 217, 216, 217, 108, 102, 103, - /* 1320 */ 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, - /* 1330 */ 299, 300, 193, 216, 217, 116, 117, 118, 19, 20, - /* 1340 */ 193, 22, 70, 309, 135, 193, 264, 313, 193, 140, - /* 1350 */ 78, 193, 226, 81, 59, 36, 193, 309, 193, 29, - /* 1360 */ 193, 313, 193, 33, 145, 193, 59, 48, 216, 217, - /* 1370 */ 98, 216, 217, 193, 216, 217, 193, 244, 59, 216, - /* 1380 */ 217, 216, 217, 216, 217, 216, 217, 254, 216, 217, - /* 1390 */ 71, 193, 244, 193, 193, 65, 216, 217, 193, 216, - /* 1400 */ 217, 145, 254, 244, 85, 133, 15, 100, 193, 90, - /* 1410 */ 138, 139, 117, 254, 216, 217, 216, 217, 193, 100, - /* 1420 */ 193, 216, 217, 116, 117, 106, 107, 19, 121, 193, - /* 1430 */ 193, 216, 217, 114, 162, 116, 117, 118, 244, 244, - /* 1440 */ 121, 216, 217, 216, 217, 193, 309, 129, 254, 254, - /* 1450 */ 313, 60, 216, 217, 19, 256, 257, 193, 120, 121, - /* 1460 */ 153, 154, 155, 149, 150, 25, 24, 99, 216, 217, - /* 1470 */ 152, 193, 153, 154, 155, 156, 157, 0, 1, 2, - /* 1480 */ 216, 217, 5, 22, 158, 24, 160, 10, 11, 12, - /* 1490 */ 13, 14, 193, 23, 17, 25, 193, 19, 20, 193, - /* 1500 */ 22, 133, 193, 22, 22, 193, 22, 30, 193, 32, - /* 1510 */ 19, 20, 129, 22, 36, 216, 217, 40, 193, 216, - /* 1520 */ 217, 193, 216, 217, 116, 216, 217, 36, 216, 217, - /* 1530 */ 193, 216, 217, 193, 53, 152, 193, 59, 23, 19, - /* 1540 */ 25, 216, 217, 61, 216, 217, 23, 70, 25, 71, - /* 1550 */ 59, 116, 193, 216, 217, 78, 216, 217, 81, 216, - /* 1560 */ 217, 59, 71, 85, 193, 23, 193, 25, 90, 23, - /* 1570 */ 23, 25, 25, 7, 8, 98, 85, 193, 100, 193, - /* 1580 */ 59, 90, 142, 141, 106, 107, 193, 216, 217, 216, - /* 1590 */ 217, 100, 114, 193, 116, 117, 118, 106, 107, 121, - /* 1600 */ 216, 217, 216, 217, 193, 114, 193, 116, 117, 118, - /* 1610 */ 133, 23, 121, 25, 121, 138, 139, 97, 23, 117, - /* 1620 */ 25, 23, 193, 25, 131, 141, 193, 216, 217, 59, - /* 1630 */ 193, 153, 154, 155, 156, 157, 226, 193, 117, 162, - /* 1640 */ 23, 23, 25, 25, 153, 154, 155, 156, 157, 1, - /* 1650 */ 2, 83, 84, 5, 19, 20, 226, 22, 10, 11, - /* 1660 */ 12, 13, 14, 258, 153, 17, 155, 153, 23, 155, - /* 1670 */ 25, 36, 23, 193, 25, 255, 193, 236, 30, 193, - /* 1680 */ 32, 19, 20, 193, 22, 193, 288, 117, 40, 193, - /* 1690 */ 318, 193, 193, 193, 59, 242, 193, 193, 36, 193, - /* 1700 */ 193, 193, 287, 255, 255, 255, 71, 255, 243, 214, - /* 1710 */ 191, 297, 267, 245, 271, 259, 259, 293, 70, 246, - /* 1720 */ 246, 59, 267, 229, 245, 271, 78, 293, 259, 81, - /* 1730 */ 271, 271, 220, 71, 225, 100, 219, 219, 249, 196, - /* 1740 */ 243, 106, 107, 108, 219, 60, 98, 280, 297, 114, - /* 1750 */ 249, 116, 117, 118, 141, 245, 121, 200, 200, 297, - /* 1760 */ 38, 200, 100, 151, 150, 294, 294, 22, 106, 107, - /* 1770 */ 283, 43, 234, 18, 237, 200, 114, 272, 116, 117, - /* 1780 */ 118, 133, 237, 121, 18, 237, 138, 139, 153, 154, - /* 1790 */ 155, 156, 157, 237, 270, 199, 19, 20, 246, 22, - /* 1800 */ 149, 272, 272, 270, 200, 246, 234, 234, 246, 246, - /* 1810 */ 162, 158, 290, 36, 199, 153, 154, 155, 156, 157, - /* 1820 */ 62, 289, 200, 199, 22, 200, 221, 199, 221, 200, - /* 1830 */ 199, 115, 64, 227, 218, 22, 59, 218, 218, 126, - /* 1840 */ 165, 24, 113, 312, 218, 224, 305, 224, 71, 282, - /* 1850 */ 144, 221, 220, 282, 218, 218, 218, 115, 261, 260, - /* 1860 */ 227, 221, 261, 260, 200, 91, 317, 317, 82, 261, - /* 1870 */ 260, 148, 261, 22, 265, 145, 200, 100, 158, 277, - /* 1880 */ 147, 146, 25, 106, 107, 202, 13, 260, 194, 250, - /* 1890 */ 249, 114, 248, 116, 117, 118, 250, 247, 121, 265, - /* 1900 */ 246, 194, 6, 192, 192, 207, 192, 207, 213, 213, - /* 1910 */ 213, 222, 213, 222, 4, 214, 214, 213, 3, 22, - /* 1920 */ 163, 279, 207, 15, 23, 16, 23, 139, 130, 151, - /* 1930 */ 153, 154, 155, 156, 157, 142, 25, 24, 20, 144, - /* 1940 */ 16, 1, 142, 61, 130, 130, 303, 151, 53, 37, - /* 1950 */ 303, 53, 300, 53, 130, 53, 116, 34, 1, 141, - /* 1960 */ 5, 22, 115, 25, 161, 75, 41, 68, 141, 115, - /* 1970 */ 24, 20, 68, 19, 131, 125, 23, 96, 22, 59, - /* 1980 */ 22, 67, 22, 22, 67, 22, 24, 28, 67, 37, - /* 1990 */ 23, 149, 22, 25, 23, 23, 23, 23, 22, 141, - /* 2000 */ 23, 23, 97, 116, 22, 143, 25, 88, 75, 34, - /* 2010 */ 44, 75, 86, 34, 34, 93, 23, 34, 34, 34, - /* 2020 */ 22, 24, 34, 22, 25, 25, 23, 23, 23, 23, - /* 2030 */ 23, 11, 23, 25, 22, 22, 25, 23, 23, 22, - /* 2040 */ 22, 135, 15, 1, 25, 23, 1, 319, 141, 319, - /* 2050 */ 319, 319, 319, 319, 319, 319, 319, 141, 319, 319, - /* 2060 */ 319, 319, 319, 319, 319, 319, 319, 319, 141, 141, - /* 2070 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, - /* 2080 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, - /* 2090 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, - /* 2100 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, - /* 2110 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, - /* 2120 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, - /* 2130 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, - /* 2140 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, - /* 2150 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, - /* 2160 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, - /* 2170 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, - /* 2180 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, - /* 2190 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, - /* 2200 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, - /* 2210 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, - /* 2220 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, - /* 2230 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, - /* 2240 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319, - /* 2250 */ 319, 319, 319, 319, 319, -}; -#define YY_SHIFT_COUNT (573) + /* 0 */ 192, 273, 274, 275, 192, 192, 273, 274, 275, 192, + /* 10 */ 218, 215, 192, 218, 192, 212, 234, 235, 205, 19, + /* 20 */ 11, 192, 294, 215, 216, 203, 192, 203, 209, 210, + /* 30 */ 211, 31, 215, 216, 205, 215, 216, 215, 216, 39, + /* 40 */ 227, 215, 229, 43, 44, 45, 46, 47, 48, 49, + /* 50 */ 50, 51, 52, 53, 54, 55, 56, 57, 192, 19, + /* 60 */ 238, 239, 238, 239, 215, 273, 274, 275, 273, 274, + /* 70 */ 275, 237, 21, 251, 252, 251, 273, 274, 275, 255, + /* 80 */ 256, 215, 216, 43, 44, 45, 46, 47, 48, 49, + /* 90 */ 50, 51, 52, 53, 54, 55, 56, 57, 209, 210, + /* 100 */ 211, 76, 102, 103, 104, 105, 106, 107, 108, 109, + /* 110 */ 110, 111, 112, 59, 89, 111, 112, 92, 252, 307, + /* 120 */ 308, 313, 314, 112, 312, 59, 86, 261, 88, 19, + /* 130 */ 313, 80, 315, 313, 314, 25, 127, 128, 54, 55, + /* 140 */ 56, 57, 102, 103, 104, 105, 106, 107, 108, 109, + /* 150 */ 110, 111, 112, 43, 44, 45, 46, 47, 48, 49, + /* 160 */ 50, 51, 52, 53, 54, 55, 56, 57, 192, 115, + /* 170 */ 116, 117, 118, 122, 192, 121, 122, 123, 202, 69, + /* 180 */ 204, 115, 116, 117, 192, 131, 102, 103, 104, 105, + /* 190 */ 106, 107, 108, 109, 110, 111, 112, 215, 216, 19, + /* 200 */ 54, 55, 56, 57, 58, 108, 109, 110, 111, 112, + /* 210 */ 192, 160, 102, 103, 104, 105, 106, 107, 108, 109, + /* 220 */ 110, 111, 112, 43, 44, 45, 46, 47, 48, 49, + /* 230 */ 50, 51, 52, 53, 54, 55, 56, 57, 19, 46, + /* 240 */ 47, 48, 49, 24, 248, 192, 250, 67, 102, 103, + /* 250 */ 104, 105, 106, 107, 108, 109, 110, 111, 112, 277, + /* 260 */ 127, 128, 43, 44, 45, 46, 47, 48, 49, 50, + /* 270 */ 51, 52, 53, 54, 55, 56, 57, 26, 164, 165, + /* 280 */ 272, 263, 102, 103, 104, 105, 106, 107, 108, 109, + /* 290 */ 110, 111, 112, 184, 185, 186, 187, 188, 189, 186, + /* 300 */ 187, 188, 189, 194, 76, 196, 229, 194, 19, 196, + /* 310 */ 59, 192, 203, 120, 59, 87, 203, 89, 310, 311, + /* 320 */ 92, 102, 103, 104, 105, 106, 107, 108, 109, 110, + /* 330 */ 111, 112, 43, 44, 45, 46, 47, 48, 49, 50, + /* 340 */ 51, 52, 53, 54, 55, 56, 57, 238, 239, 73, + /* 350 */ 231, 238, 239, 22, 23, 100, 25, 81, 305, 306, + /* 360 */ 251, 23, 25, 25, 251, 272, 115, 116, 117, 214, + /* 370 */ 115, 116, 144, 192, 265, 120, 114, 222, 265, 102, + /* 380 */ 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, + /* 390 */ 192, 102, 103, 104, 105, 106, 107, 108, 109, 110, + /* 400 */ 111, 112, 126, 310, 311, 192, 297, 152, 153, 154, + /* 410 */ 297, 149, 192, 137, 138, 19, 192, 100, 192, 23, + /* 420 */ 22, 106, 107, 108, 109, 110, 111, 112, 215, 216, + /* 430 */ 106, 107, 101, 116, 192, 215, 216, 120, 149, 43, + /* 440 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, + /* 450 */ 54, 55, 56, 57, 117, 117, 192, 59, 19, 187, + /* 460 */ 59, 189, 23, 282, 240, 252, 194, 192, 196, 152, + /* 470 */ 153, 154, 252, 72, 261, 203, 152, 25, 154, 142, + /* 480 */ 142, 261, 43, 44, 45, 46, 47, 48, 49, 50, + /* 490 */ 51, 52, 53, 54, 55, 56, 57, 192, 102, 103, + /* 500 */ 104, 105, 106, 107, 108, 109, 110, 111, 112, 267, + /* 510 */ 238, 239, 237, 115, 116, 117, 115, 116, 117, 192, + /* 520 */ 59, 118, 16, 251, 121, 122, 123, 303, 19, 303, + /* 530 */ 59, 267, 23, 72, 131, 308, 22, 265, 22, 312, + /* 540 */ 24, 102, 103, 104, 105, 106, 107, 108, 109, 110, + /* 550 */ 111, 112, 43, 44, 45, 46, 47, 48, 49, 50, + /* 560 */ 51, 52, 53, 54, 55, 56, 57, 19, 81, 297, + /* 570 */ 295, 23, 192, 59, 203, 59, 115, 116, 117, 108, + /* 580 */ 192, 73, 25, 77, 192, 79, 115, 116, 117, 137, + /* 590 */ 138, 43, 44, 45, 46, 47, 48, 49, 50, 51, + /* 600 */ 52, 53, 54, 55, 56, 57, 119, 215, 216, 238, + /* 610 */ 239, 102, 103, 104, 105, 106, 107, 108, 109, 110, + /* 620 */ 111, 112, 251, 192, 137, 138, 59, 234, 235, 115, + /* 630 */ 116, 117, 116, 76, 126, 127, 128, 19, 192, 268, + /* 640 */ 19, 23, 22, 192, 252, 24, 89, 300, 301, 92, + /* 650 */ 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + /* 660 */ 112, 43, 44, 45, 46, 47, 48, 49, 50, 51, + /* 670 */ 52, 53, 54, 55, 56, 57, 19, 192, 192, 59, + /* 680 */ 23, 192, 115, 116, 117, 200, 240, 307, 308, 22, + /* 690 */ 205, 81, 312, 262, 22, 192, 133, 22, 135, 136, + /* 700 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, + /* 710 */ 53, 54, 55, 56, 57, 197, 95, 150, 215, 216, + /* 720 */ 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + /* 730 */ 112, 59, 192, 112, 59, 115, 116, 117, 192, 118, + /* 740 */ 119, 120, 121, 122, 123, 124, 19, 137, 138, 303, + /* 750 */ 23, 130, 192, 267, 192, 252, 267, 306, 203, 102, + /* 760 */ 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, + /* 770 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, + /* 780 */ 53, 54, 55, 56, 57, 19, 240, 115, 116, 117, + /* 790 */ 115, 116, 117, 238, 239, 222, 192, 224, 280, 237, + /* 800 */ 240, 192, 284, 192, 59, 232, 251, 140, 204, 43, + /* 810 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, + /* 820 */ 54, 55, 56, 57, 192, 35, 215, 216, 192, 102, + /* 830 */ 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, + /* 840 */ 59, 230, 192, 192, 238, 239, 237, 215, 216, 303, + /* 850 */ 308, 215, 216, 16, 312, 19, 66, 251, 126, 127, + /* 860 */ 128, 116, 230, 303, 74, 203, 215, 216, 102, 103, + /* 870 */ 104, 105, 106, 107, 108, 109, 110, 111, 112, 43, + /* 880 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, + /* 890 */ 54, 55, 56, 57, 192, 212, 115, 116, 117, 19, + /* 900 */ 238, 239, 192, 252, 7, 8, 9, 192, 192, 238, + /* 910 */ 239, 308, 262, 251, 77, 312, 79, 215, 216, 129, + /* 920 */ 210, 211, 251, 142, 158, 45, 46, 47, 48, 49, + /* 930 */ 50, 51, 52, 53, 54, 55, 56, 57, 102, 103, + /* 940 */ 104, 105, 106, 107, 108, 109, 110, 111, 112, 12, + /* 950 */ 59, 192, 192, 237, 252, 243, 192, 192, 126, 127, + /* 960 */ 128, 192, 308, 203, 27, 253, 312, 308, 285, 207, + /* 970 */ 208, 312, 157, 290, 159, 215, 216, 262, 192, 42, + /* 980 */ 215, 216, 102, 103, 104, 105, 106, 107, 108, 109, + /* 990 */ 110, 111, 112, 283, 158, 230, 237, 160, 238, 239, + /* 1000 */ 63, 215, 216, 192, 192, 12, 115, 116, 117, 22, + /* 1010 */ 73, 251, 252, 192, 19, 192, 230, 239, 24, 24, + /* 1020 */ 27, 261, 210, 211, 99, 192, 215, 216, 225, 251, + /* 1030 */ 192, 192, 263, 142, 19, 42, 215, 216, 43, 44, + /* 1040 */ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + /* 1050 */ 55, 56, 57, 59, 19, 291, 63, 132, 43, 44, + /* 1060 */ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + /* 1070 */ 55, 56, 57, 252, 22, 23, 22, 25, 43, 44, + /* 1080 */ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, + /* 1090 */ 55, 56, 57, 106, 107, 283, 263, 102, 103, 104, + /* 1100 */ 105, 106, 107, 108, 109, 110, 111, 112, 59, 192, + /* 1110 */ 116, 144, 29, 59, 291, 192, 33, 102, 103, 104, + /* 1120 */ 105, 106, 107, 108, 109, 110, 111, 112, 192, 291, + /* 1130 */ 163, 19, 215, 216, 15, 192, 108, 102, 103, 104, + /* 1140 */ 105, 106, 107, 108, 109, 110, 111, 112, 65, 192, + /* 1150 */ 66, 215, 216, 101, 231, 106, 107, 19, 215, 216, + /* 1160 */ 192, 212, 134, 114, 115, 116, 117, 139, 119, 85, + /* 1170 */ 116, 207, 208, 230, 192, 19, 127, 192, 94, 60, + /* 1180 */ 59, 192, 44, 45, 46, 47, 48, 49, 50, 51, + /* 1190 */ 52, 53, 54, 55, 56, 57, 192, 76, 192, 31, + /* 1200 */ 192, 152, 46, 154, 215, 216, 192, 39, 87, 192, + /* 1210 */ 89, 19, 20, 92, 22, 192, 22, 23, 22, 230, + /* 1220 */ 263, 215, 216, 215, 216, 137, 138, 115, 36, 145, + /* 1230 */ 128, 192, 215, 216, 22, 23, 115, 116, 117, 290, + /* 1240 */ 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + /* 1250 */ 112, 59, 192, 151, 215, 216, 192, 61, 203, 298, + /* 1260 */ 299, 192, 192, 71, 25, 144, 203, 192, 203, 230, + /* 1270 */ 114, 19, 20, 81, 22, 215, 216, 263, 192, 215, + /* 1280 */ 216, 255, 256, 203, 215, 216, 130, 19, 36, 192, + /* 1290 */ 215, 216, 100, 238, 239, 101, 25, 192, 106, 107, + /* 1300 */ 48, 238, 239, 238, 239, 113, 251, 115, 116, 117, + /* 1310 */ 192, 59, 120, 101, 251, 192, 251, 192, 238, 239, + /* 1320 */ 215, 216, 192, 71, 46, 243, 192, 25, 25, 137, + /* 1330 */ 138, 251, 192, 215, 216, 253, 25, 85, 215, 216, + /* 1340 */ 215, 216, 90, 243, 152, 153, 154, 155, 156, 215, + /* 1350 */ 216, 192, 100, 253, 243, 215, 216, 192, 106, 107, + /* 1360 */ 243, 192, 148, 149, 253, 113, 192, 115, 116, 117, + /* 1370 */ 253, 192, 120, 192, 215, 216, 192, 23, 192, 25, + /* 1380 */ 215, 216, 192, 115, 215, 216, 22, 148, 24, 215, + /* 1390 */ 216, 192, 114, 192, 215, 216, 215, 216, 134, 215, + /* 1400 */ 216, 215, 216, 139, 152, 153, 154, 155, 156, 0, + /* 1410 */ 1, 2, 141, 23, 5, 25, 215, 216, 24, 10, + /* 1420 */ 11, 12, 13, 14, 1, 2, 17, 125, 5, 19, + /* 1430 */ 20, 268, 22, 10, 11, 12, 13, 14, 192, 30, + /* 1440 */ 17, 32, 23, 23, 25, 25, 36, 144, 23, 40, + /* 1450 */ 25, 192, 141, 30, 192, 32, 23, 22, 25, 5, + /* 1460 */ 128, 215, 216, 40, 10, 11, 12, 13, 14, 59, + /* 1470 */ 23, 17, 25, 192, 215, 216, 192, 215, 216, 70, + /* 1480 */ 23, 71, 25, 151, 30, 192, 32, 78, 53, 192, + /* 1490 */ 81, 192, 192, 70, 40, 85, 215, 216, 119, 120, + /* 1500 */ 90, 78, 59, 254, 81, 192, 192, 98, 215, 216, + /* 1510 */ 100, 23, 59, 25, 215, 216, 106, 107, 23, 192, + /* 1520 */ 25, 98, 19, 113, 70, 115, 116, 117, 215, 216, + /* 1530 */ 120, 192, 78, 192, 140, 81, 19, 20, 23, 22, + /* 1540 */ 25, 132, 215, 216, 192, 192, 137, 138, 192, 23, + /* 1550 */ 192, 25, 98, 36, 192, 132, 215, 216, 192, 116, + /* 1560 */ 137, 138, 152, 153, 154, 155, 156, 215, 216, 116, + /* 1570 */ 161, 215, 216, 215, 216, 120, 59, 215, 216, 7, + /* 1580 */ 8, 215, 216, 192, 161, 130, 132, 192, 71, 83, + /* 1590 */ 84, 137, 138, 59, 192, 192, 19, 20, 192, 22, + /* 1600 */ 97, 225, 85, 192, 23, 192, 25, 90, 192, 192, + /* 1610 */ 215, 216, 152, 36, 154, 161, 192, 100, 215, 216, + /* 1620 */ 192, 215, 216, 106, 107, 225, 215, 216, 192, 192, + /* 1630 */ 113, 192, 115, 116, 117, 257, 59, 120, 192, 215, + /* 1640 */ 216, 152, 192, 154, 192, 23, 317, 25, 71, 235, + /* 1650 */ 116, 215, 216, 192, 215, 216, 192, 192, 192, 192, + /* 1660 */ 192, 192, 192, 192, 192, 215, 216, 215, 216, 152, + /* 1670 */ 153, 154, 155, 156, 192, 192, 287, 100, 286, 241, + /* 1680 */ 254, 254, 242, 106, 107, 108, 254, 213, 254, 190, + /* 1690 */ 113, 270, 115, 116, 117, 296, 266, 120, 219, 258, + /* 1700 */ 244, 270, 258, 19, 20, 228, 22, 292, 266, 224, + /* 1710 */ 292, 218, 218, 195, 218, 270, 258, 60, 245, 270, + /* 1720 */ 36, 245, 244, 248, 19, 20, 242, 22, 248, 152, + /* 1730 */ 153, 154, 155, 156, 244, 140, 199, 199, 279, 38, + /* 1740 */ 199, 36, 150, 59, 296, 149, 22, 296, 18, 43, + /* 1750 */ 236, 199, 233, 18, 198, 71, 293, 236, 271, 236, + /* 1760 */ 269, 236, 148, 271, 59, 245, 269, 245, 282, 271, + /* 1770 */ 199, 198, 233, 245, 293, 233, 71, 245, 157, 62, + /* 1780 */ 22, 199, 198, 220, 100, 199, 198, 220, 199, 289, + /* 1790 */ 106, 107, 288, 114, 226, 198, 217, 113, 64, 115, + /* 1800 */ 116, 117, 217, 22, 120, 100, 223, 217, 217, 164, + /* 1810 */ 223, 106, 107, 220, 125, 24, 217, 219, 113, 217, + /* 1820 */ 115, 116, 117, 217, 311, 120, 226, 112, 304, 281, + /* 1830 */ 281, 220, 114, 143, 260, 259, 152, 153, 154, 155, + /* 1840 */ 156, 199, 91, 316, 82, 316, 147, 144, 22, 199, + /* 1850 */ 249, 276, 157, 146, 260, 145, 278, 152, 153, 154, + /* 1860 */ 155, 156, 259, 248, 260, 260, 259, 259, 249, 245, + /* 1870 */ 247, 246, 25, 264, 264, 201, 13, 6, 193, 193, + /* 1880 */ 212, 206, 191, 191, 191, 212, 206, 221, 212, 212, + /* 1890 */ 221, 213, 4, 206, 213, 212, 3, 22, 162, 15, + /* 1900 */ 23, 16, 23, 138, 150, 129, 25, 24, 141, 20, + /* 1910 */ 16, 143, 1, 141, 302, 302, 299, 129, 129, 61, + /* 1920 */ 150, 53, 53, 37, 129, 53, 53, 115, 1, 34, + /* 1930 */ 140, 5, 22, 114, 160, 68, 75, 25, 68, 41, + /* 1940 */ 140, 114, 24, 20, 19, 130, 124, 67, 24, 67, + /* 1950 */ 22, 22, 22, 96, 23, 22, 59, 22, 67, 37, + /* 1960 */ 28, 23, 148, 22, 25, 23, 23, 23, 23, 22, + /* 1970 */ 140, 97, 23, 23, 115, 22, 142, 25, 88, 75, + /* 1980 */ 34, 44, 34, 75, 23, 34, 86, 22, 34, 34, + /* 1990 */ 34, 24, 93, 25, 25, 23, 34, 23, 23, 23, + /* 2000 */ 23, 11, 23, 25, 22, 22, 22, 1, 23, 23, + /* 2010 */ 22, 22, 25, 15, 23, 1, 140, 25, 140, 318, + /* 2020 */ 318, 134, 318, 318, 318, 318, 318, 318, 318, 318, + /* 2030 */ 318, 318, 140, 318, 318, 318, 140, 318, 318, 318, + /* 2040 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, + /* 2050 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, + /* 2060 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, + /* 2070 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, + /* 2080 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, + /* 2090 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, + /* 2100 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, + /* 2110 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, + /* 2120 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, + /* 2130 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, + /* 2140 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, + /* 2150 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, + /* 2160 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, + /* 2170 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, + /* 2180 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, + /* 2190 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, + /* 2200 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, + /* 2210 */ 318, 318, 318, 318, 318, 318, 318, 318, 318, 318, + /* 2220 */ 318, +}; +#define YY_SHIFT_COUNT (571) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (2045) +#define YY_SHIFT_MAX (2014) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 1648, 1477, 1272, 322, 322, 262, 1319, 1478, 1491, 1662, - /* 10 */ 1662, 1662, 317, 0, 0, 214, 1093, 1662, 1662, 1662, - /* 20 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, - /* 30 */ 271, 271, 1219, 1219, 216, 88, 262, 262, 262, 262, - /* 40 */ 262, 40, 111, 258, 361, 469, 512, 583, 622, 693, - /* 50 */ 732, 803, 842, 913, 1073, 1093, 1093, 1093, 1093, 1093, - /* 60 */ 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, - /* 70 */ 1093, 1093, 1093, 1113, 1093, 1216, 957, 957, 1635, 1662, - /* 80 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, - /* 90 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, - /* 100 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, - /* 110 */ 1662, 1662, 1662, 1662, 1777, 1662, 1662, 1662, 1662, 1662, - /* 120 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 137, 181, - /* 130 */ 181, 181, 181, 181, 94, 430, 66, 65, 112, 366, - /* 140 */ 475, 475, 629, 1058, 475, 475, 125, 125, 475, 686, - /* 150 */ 686, 686, 660, 686, 57, 184, 184, 77, 77, 2070, - /* 160 */ 2070, 328, 328, 328, 493, 373, 373, 373, 373, 1015, - /* 170 */ 1015, 409, 366, 1129, 1149, 475, 475, 475, 475, 475, - /* 180 */ 475, 475, 475, 475, 475, 475, 475, 475, 475, 475, - /* 190 */ 475, 475, 475, 475, 475, 621, 621, 475, 852, 899, - /* 200 */ 899, 1295, 1295, 406, 851, 2070, 2070, 2070, 2070, 2070, - /* 210 */ 2070, 2070, 1307, 954, 954, 640, 464, 695, 238, 700, - /* 220 */ 538, 541, 748, 475, 475, 475, 475, 475, 475, 475, - /* 230 */ 475, 475, 475, 634, 475, 475, 475, 475, 475, 475, - /* 240 */ 475, 475, 475, 475, 475, 475, 1175, 1175, 1175, 475, - /* 250 */ 475, 475, 580, 475, 475, 475, 1074, 1142, 475, 475, - /* 260 */ 1072, 475, 475, 475, 475, 475, 475, 475, 475, 797, - /* 270 */ 1330, 740, 1131, 1131, 1131, 1131, 1069, 740, 740, 1209, - /* 280 */ 167, 926, 1391, 1038, 1314, 187, 1408, 1314, 1408, 1435, - /* 290 */ 1109, 1038, 1038, 1109, 1038, 187, 1435, 227, 1090, 941, - /* 300 */ 1270, 1270, 1270, 1408, 1256, 1256, 1326, 1440, 513, 1461, - /* 310 */ 1685, 1685, 1613, 1613, 1722, 1722, 1613, 1612, 1614, 1745, - /* 320 */ 1728, 1755, 1755, 1755, 1755, 1613, 1766, 1651, 1614, 1614, - /* 330 */ 1651, 1745, 1728, 1651, 1728, 1651, 1613, 1766, 1653, 1758, - /* 340 */ 1613, 1766, 1802, 1613, 1766, 1613, 1766, 1802, 1716, 1716, - /* 350 */ 1716, 1768, 1813, 1813, 1802, 1716, 1713, 1716, 1768, 1716, - /* 360 */ 1716, 1675, 1817, 1729, 1729, 1802, 1706, 1742, 1706, 1742, - /* 370 */ 1706, 1742, 1706, 1742, 1613, 1774, 1774, 1786, 1786, 1723, - /* 380 */ 1730, 1851, 1613, 1720, 1723, 1733, 1735, 1651, 1857, 1873, - /* 390 */ 1873, 1896, 1896, 1896, 2070, 2070, 2070, 2070, 2070, 2070, - /* 400 */ 2070, 2070, 2070, 2070, 2070, 2070, 2070, 2070, 2070, 207, - /* 410 */ 915, 1010, 1030, 1217, 910, 1170, 1470, 1368, 1481, 1442, - /* 420 */ 1318, 1383, 1515, 1482, 1523, 1542, 1546, 1547, 1588, 1595, - /* 430 */ 1502, 1338, 1566, 1493, 1520, 1521, 1598, 1617, 1568, 1618, - /* 440 */ 1511, 1514, 1645, 1649, 1570, 1484, 1910, 1915, 1897, 1757, - /* 450 */ 1908, 1909, 1901, 1903, 1788, 1778, 1798, 1911, 1911, 1913, - /* 460 */ 1793, 1918, 1795, 1924, 1940, 1800, 1814, 1911, 1815, 1882, - /* 470 */ 1912, 1911, 1796, 1895, 1898, 1900, 1902, 1824, 1840, 1923, - /* 480 */ 1818, 1957, 1955, 1939, 1847, 1803, 1899, 1938, 1904, 1890, - /* 490 */ 1925, 1827, 1854, 1946, 1951, 1954, 1843, 1850, 1956, 1914, - /* 500 */ 1958, 1960, 1953, 1961, 1917, 1920, 1962, 1881, 1959, 1963, - /* 510 */ 1921, 1952, 1967, 1842, 1970, 1971, 1972, 1973, 1968, 1974, - /* 520 */ 1976, 1905, 1858, 1977, 1978, 1887, 1975, 1982, 1862, 1981, - /* 530 */ 1979, 1980, 1983, 1984, 1919, 1933, 1926, 1966, 1936, 1922, - /* 540 */ 1985, 1993, 1998, 1997, 1999, 2000, 1988, 2003, 1981, 2004, - /* 550 */ 2005, 2006, 2007, 2008, 2009, 2001, 2020, 2012, 2013, 2014, - /* 560 */ 2015, 2017, 2018, 2011, 1906, 1907, 1916, 1927, 1928, 2019, - /* 570 */ 2022, 2027, 2042, 2045, -}; -#define YY_REDUCE_COUNT (408) -#define YY_REDUCE_MIN (-267) -#define YY_REDUCE_MAX (1715) + /* 0 */ 1423, 1409, 1454, 1192, 1192, 610, 1252, 1410, 1517, 1684, + /* 10 */ 1684, 1684, 276, 0, 0, 180, 1015, 1684, 1684, 1684, + /* 20 */ 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, + /* 30 */ 1049, 1049, 1121, 1121, 54, 487, 610, 610, 610, 610, + /* 40 */ 610, 40, 110, 219, 289, 396, 439, 509, 548, 618, + /* 50 */ 657, 727, 766, 836, 995, 1015, 1015, 1015, 1015, 1015, + /* 60 */ 1015, 1015, 1015, 1015, 1015, 1015, 1015, 1015, 1015, 1015, + /* 70 */ 1015, 1015, 1015, 1035, 1015, 1138, 880, 880, 1577, 1684, + /* 80 */ 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, + /* 90 */ 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, + /* 100 */ 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, 1684, + /* 110 */ 1684, 1684, 1684, 1705, 1684, 1684, 1684, 1684, 1684, 1684, + /* 120 */ 1684, 1684, 1684, 1684, 1684, 1684, 1684, 146, 84, 84, + /* 130 */ 84, 84, 84, 277, 315, 401, 97, 461, 251, 66, + /* 140 */ 66, 51, 1156, 66, 66, 324, 324, 66, 452, 452, + /* 150 */ 452, 452, 133, 114, 114, 4, 11, 2037, 2037, 621, + /* 160 */ 621, 621, 567, 398, 398, 398, 398, 937, 937, 228, + /* 170 */ 251, 331, 1052, 66, 66, 66, 66, 66, 66, 66, + /* 180 */ 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, + /* 190 */ 66, 66, 66, 557, 557, 66, 9, 25, 25, 745, + /* 200 */ 745, 967, 1088, 2037, 2037, 2037, 2037, 2037, 2037, 2037, + /* 210 */ 255, 317, 317, 514, 403, 620, 471, 672, 781, 891, + /* 220 */ 675, 66, 66, 66, 66, 66, 66, 66, 66, 66, + /* 230 */ 66, 508, 66, 66, 66, 66, 66, 66, 66, 66, + /* 240 */ 66, 66, 66, 66, 790, 790, 790, 66, 66, 66, + /* 250 */ 338, 66, 66, 66, 516, 1084, 66, 66, 993, 66, + /* 260 */ 66, 66, 66, 66, 66, 66, 66, 732, 1083, 563, + /* 270 */ 994, 994, 994, 994, 337, 563, 563, 1028, 987, 897, + /* 280 */ 1119, 262, 1214, 1271, 1112, 1214, 1112, 1268, 1239, 262, + /* 290 */ 262, 1239, 262, 1271, 1268, 1302, 1354, 1278, 1168, 1168, + /* 300 */ 1168, 1112, 1303, 1303, 815, 1311, 1264, 1364, 1657, 1657, + /* 310 */ 1595, 1595, 1701, 1701, 1595, 1592, 1596, 1724, 1706, 1730, + /* 320 */ 1730, 1730, 1730, 1595, 1735, 1614, 1596, 1596, 1614, 1724, + /* 330 */ 1706, 1614, 1706, 1614, 1595, 1735, 1621, 1717, 1595, 1735, + /* 340 */ 1758, 1595, 1735, 1595, 1735, 1758, 1679, 1679, 1679, 1734, + /* 350 */ 1781, 1781, 1758, 1679, 1689, 1679, 1734, 1679, 1679, 1645, + /* 360 */ 1791, 1715, 1715, 1758, 1690, 1718, 1690, 1718, 1690, 1718, + /* 370 */ 1690, 1718, 1595, 1751, 1751, 1762, 1762, 1699, 1703, 1826, + /* 380 */ 1595, 1695, 1699, 1707, 1710, 1614, 1847, 1863, 1863, 1871, + /* 390 */ 1871, 1871, 2037, 2037, 2037, 2037, 2037, 2037, 2037, 2037, + /* 400 */ 2037, 2037, 2037, 2037, 2037, 2037, 2037, 193, 837, 1194, + /* 410 */ 1212, 506, 832, 1054, 1390, 925, 1435, 1394, 1102, 1332, + /* 420 */ 1419, 1196, 1420, 1425, 1433, 1447, 1457, 1488, 1443, 1379, + /* 430 */ 1572, 1455, 1503, 1453, 1495, 1515, 1506, 1526, 1460, 1489, + /* 440 */ 1581, 1622, 1534, 667, 1888, 1893, 1875, 1736, 1884, 1885, + /* 450 */ 1877, 1879, 1765, 1754, 1776, 1881, 1881, 1883, 1767, 1889, + /* 460 */ 1768, 1894, 1911, 1772, 1788, 1881, 1789, 1858, 1886, 1881, + /* 470 */ 1770, 1868, 1869, 1872, 1873, 1795, 1812, 1895, 1790, 1927, + /* 480 */ 1926, 1910, 1819, 1774, 1867, 1912, 1870, 1861, 1898, 1800, + /* 490 */ 1827, 1918, 1923, 1925, 1815, 1822, 1928, 1880, 1929, 1930, + /* 500 */ 1931, 1933, 1882, 1897, 1924, 1857, 1932, 1935, 1891, 1922, + /* 510 */ 1938, 1814, 1941, 1942, 1943, 1944, 1939, 1945, 1947, 1874, + /* 520 */ 1830, 1949, 1950, 1859, 1946, 1953, 1834, 1952, 1948, 1951, + /* 530 */ 1954, 1955, 1890, 1904, 1900, 1937, 1908, 1899, 1956, 1961, + /* 540 */ 1965, 1967, 1968, 1969, 1962, 1972, 1952, 1974, 1975, 1976, + /* 550 */ 1977, 1978, 1979, 1982, 1990, 1983, 1984, 1985, 1986, 1988, + /* 560 */ 1989, 1987, 1887, 1876, 1878, 1892, 1896, 1992, 1991, 1998, + /* 570 */ 2006, 2014, +}; +#define YY_REDUCE_COUNT (406) +#define YY_REDUCE_MIN (-272) +#define YY_REDUCE_MAX (1693) static const short yy_reduce_ofst[] = { - /* 0 */ -125, 733, 789, 241, 293, -123, -193, -191, -183, -187, - /* 10 */ -180, 83, 133, -207, -198, -267, -175, -6, 166, 313, - /* 20 */ 487, 396, 489, 598, 615, 685, 687, 79, 781, 857, - /* 30 */ 490, 616, 240, 334, -188, 796, 841, 843, 1003, 1005, - /* 40 */ 1007, -260, -260, -260, -260, -260, -260, -260, -260, -260, - /* 50 */ -260, -260, -260, -260, -260, -260, -260, -260, -260, -260, - /* 60 */ -260, -260, -260, -260, -260, -260, -260, -260, -260, -260, - /* 70 */ -260, -260, -260, -260, -260, -260, -260, -260, 158, 203, - /* 80 */ 391, 576, 724, 726, 886, 1021, 1035, 1063, 1081, 1083, - /* 90 */ 1097, 1099, 1117, 1152, 1155, 1158, 1163, 1165, 1167, 1169, - /* 100 */ 1172, 1180, 1183, 1198, 1200, 1205, 1215, 1225, 1227, 1236, - /* 110 */ 1252, 1264, 1299, 1303, 1306, 1309, 1312, 1315, 1325, 1328, - /* 120 */ 1337, 1340, 1343, 1371, 1373, 1384, 1386, 1411, -260, -260, - /* 130 */ -260, -260, -260, -260, -260, -260, -260, -53, 138, 302, - /* 140 */ -158, 357, 223, -222, 411, 458, -92, 556, 669, 581, - /* 150 */ 632, 581, -260, 632, 758, 778, 920, -260, -260, -260, - /* 160 */ -260, 161, 161, 161, 307, 234, 392, 526, 790, 195, - /* 170 */ 359, -174, -173, 362, 362, -189, 16, 560, 567, 261, - /* 180 */ 689, 802, 853, -122, -166, 408, 335, 617, 690, 837, - /* 190 */ 1001, 746, 1061, 515, 1082, 994, 1034, -135, 1000, 1048, - /* 200 */ 1137, 877, 897, 186, 627, 1031, 1133, 1148, 1159, 1194, - /* 210 */ 1199, 1195, -194, -142, 18, -152, 68, 201, 253, 269, - /* 220 */ 294, 354, 521, 528, 676, 680, 736, 743, 850, 907, - /* 230 */ 1041, 1047, 1060, 727, 1139, 1147, 1201, 1237, 1278, 1359, - /* 240 */ 1393, 1400, 1413, 1429, 1433, 1437, 1126, 1410, 1430, 1444, - /* 250 */ 1480, 1483, 1405, 1486, 1490, 1492, 1420, 1372, 1496, 1498, - /* 260 */ 1441, 1499, 253, 1500, 1503, 1504, 1506, 1507, 1508, 1398, - /* 270 */ 1415, 1453, 1448, 1449, 1450, 1452, 1405, 1453, 1453, 1465, - /* 280 */ 1495, 1519, 1414, 1443, 1445, 1468, 1456, 1455, 1457, 1424, - /* 290 */ 1473, 1454, 1459, 1474, 1460, 1479, 1434, 1512, 1494, 1509, - /* 300 */ 1517, 1518, 1525, 1469, 1489, 1501, 1467, 1510, 1497, 1543, - /* 310 */ 1451, 1462, 1557, 1558, 1471, 1472, 1561, 1487, 1505, 1524, - /* 320 */ 1538, 1537, 1545, 1548, 1556, 1575, 1596, 1552, 1529, 1530, - /* 330 */ 1559, 1533, 1572, 1562, 1573, 1563, 1604, 1615, 1522, 1532, - /* 340 */ 1622, 1624, 1605, 1625, 1628, 1629, 1631, 1607, 1616, 1619, - /* 350 */ 1620, 1606, 1621, 1623, 1630, 1626, 1632, 1636, 1633, 1637, - /* 360 */ 1638, 1531, 1541, 1567, 1571, 1640, 1597, 1599, 1601, 1603, - /* 370 */ 1608, 1610, 1611, 1627, 1664, 1549, 1550, 1609, 1634, 1639, - /* 380 */ 1641, 1602, 1676, 1642, 1646, 1644, 1650, 1654, 1683, 1694, - /* 390 */ 1707, 1711, 1712, 1714, 1643, 1647, 1652, 1698, 1695, 1696, - /* 400 */ 1697, 1699, 1700, 1689, 1691, 1701, 1702, 1704, 1715, + /* 0 */ 109, 113, 272, 760, -178, -176, -192, -183, -180, -134, + /* 10 */ 213, 220, 371, -208, -205, -272, -197, 611, 632, 765, + /* 20 */ 786, 392, 943, 989, 503, 651, 1039, -18, 702, 821, + /* 30 */ 710, 812, -188, 380, -187, 555, 662, 1055, 1063, 1065, + /* 40 */ 1080, -267, -267, -267, -267, -267, -267, -267, -267, -267, + /* 50 */ -267, -267, -267, -267, -267, -267, -267, -267, -267, -267, + /* 60 */ -267, -267, -267, -267, -267, -267, -267, -267, -267, -267, + /* 70 */ -267, -267, -267, -267, -267, -267, -267, -267, 636, 811, + /* 80 */ 917, 936, 1006, 1008, 1017, 1060, 1064, 1069, 1075, 1105, + /* 90 */ 1118, 1123, 1125, 1134, 1140, 1159, 1165, 1169, 1174, 1179, + /* 100 */ 1181, 1184, 1186, 1201, 1246, 1259, 1262, 1281, 1293, 1299, + /* 110 */ 1313, 1327, 1341, 1352, 1356, 1358, 1362, 1366, 1395, 1403, + /* 120 */ 1406, 1411, 1424, 1436, 1439, 1450, 1452, -267, -267, -267, + /* 130 */ -267, -267, -267, -267, -267, 224, -267, 446, -24, 275, + /* 140 */ 546, 518, 573, 560, 53, -181, -111, 485, 606, 671, + /* 150 */ 606, 671, 683, 8, 93, -267, -267, -267, -267, 155, + /* 160 */ 155, 155, 181, 242, 264, 486, 489, -218, 393, 227, + /* 170 */ 604, 347, 347, -171, 431, 650, 715, -166, 562, 609, + /* 180 */ 716, 764, 18, 823, 769, 833, 838, 957, 759, 119, + /* 190 */ 923, 226, 1014, 542, 603, 451, 949, 654, 659, 762, + /* 200 */ 964, -4, 778, 961, 712, 1082, 1100, 1111, 1026, 1117, + /* 210 */ -204, -174, -151, -8, 77, 198, 305, 327, 388, 540, + /* 220 */ 839, 968, 982, 985, 1004, 1023, 1070, 1086, 1097, 1130, + /* 230 */ 1190, 1163, 1199, 1284, 1297, 1300, 1314, 1339, 1353, 1391, + /* 240 */ 1402, 1413, 1416, 1417, 803, 1376, 1400, 1428, 1437, 1446, + /* 250 */ 1378, 1461, 1464, 1465, 1249, 1329, 1466, 1467, 1414, 1468, + /* 260 */ 305, 1469, 1470, 1471, 1472, 1482, 1483, 1389, 1392, 1438, + /* 270 */ 1426, 1427, 1432, 1434, 1378, 1438, 1438, 1440, 1474, 1499, + /* 280 */ 1399, 1421, 1430, 1456, 1441, 1442, 1444, 1415, 1473, 1431, + /* 290 */ 1445, 1476, 1449, 1478, 1418, 1479, 1477, 1485, 1493, 1494, + /* 300 */ 1496, 1458, 1475, 1480, 1459, 1490, 1484, 1518, 1448, 1451, + /* 310 */ 1537, 1538, 1463, 1481, 1541, 1486, 1487, 1491, 1519, 1514, + /* 320 */ 1521, 1523, 1525, 1552, 1556, 1520, 1492, 1498, 1522, 1497, + /* 330 */ 1539, 1528, 1542, 1532, 1571, 1573, 1500, 1504, 1582, 1584, + /* 340 */ 1563, 1586, 1588, 1589, 1597, 1567, 1579, 1585, 1590, 1568, + /* 350 */ 1583, 1587, 1593, 1591, 1598, 1599, 1600, 1602, 1606, 1513, + /* 360 */ 1524, 1548, 1549, 1611, 1574, 1576, 1594, 1603, 1604, 1607, + /* 370 */ 1605, 1608, 1642, 1527, 1529, 1609, 1610, 1601, 1615, 1575, + /* 380 */ 1650, 1578, 1619, 1623, 1625, 1624, 1674, 1685, 1686, 1691, + /* 390 */ 1692, 1693, 1612, 1613, 1617, 1675, 1668, 1673, 1676, 1677, + /* 400 */ 1680, 1666, 1669, 1678, 1681, 1683, 1687, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1637, 1637, 1637, 1466, 1233, 1344, 1233, 1233, 1233, 1466, - /* 10 */ 1466, 1466, 1233, 1374, 1374, 1519, 1266, 1233, 1233, 1233, - /* 20 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1465, 1233, 1233, - /* 30 */ 1233, 1233, 1554, 1554, 1233, 1233, 1233, 1233, 1233, 1233, - /* 40 */ 1233, 1233, 1383, 1233, 1390, 1233, 1233, 1233, 1233, 1233, - /* 50 */ 1467, 1468, 1233, 1233, 1233, 1518, 1520, 1483, 1397, 1396, - /* 60 */ 1395, 1394, 1501, 1361, 1388, 1381, 1385, 1461, 1462, 1460, - /* 70 */ 1464, 1468, 1467, 1233, 1384, 1431, 1445, 1430, 1233, 1233, - /* 80 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, - /* 90 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, - /* 100 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, - /* 110 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, - /* 120 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1439, 1444, - /* 130 */ 1451, 1443, 1440, 1433, 1432, 1434, 1435, 1233, 1233, 1257, - /* 140 */ 1233, 1233, 1254, 1308, 1233, 1233, 1233, 1233, 1233, 1538, - /* 150 */ 1537, 1233, 1436, 1233, 1266, 1425, 1424, 1448, 1437, 1447, - /* 160 */ 1446, 1526, 1590, 1589, 1484, 1233, 1233, 1233, 1233, 1233, - /* 170 */ 1233, 1554, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, - /* 180 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, - /* 190 */ 1233, 1233, 1233, 1233, 1233, 1554, 1554, 1233, 1266, 1554, - /* 200 */ 1554, 1262, 1262, 1368, 1233, 1533, 1335, 1335, 1335, 1335, - /* 210 */ 1344, 1335, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, - /* 220 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1523, 1521, 1233, - /* 230 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, - /* 240 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, - /* 250 */ 1233, 1233, 1233, 1233, 1233, 1233, 1340, 1233, 1233, 1233, - /* 260 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1583, 1233, - /* 270 */ 1496, 1322, 1340, 1340, 1340, 1340, 1342, 1323, 1321, 1334, - /* 280 */ 1267, 1240, 1629, 1400, 1389, 1341, 1363, 1389, 1363, 1626, - /* 290 */ 1387, 1400, 1400, 1387, 1400, 1341, 1626, 1283, 1606, 1278, - /* 300 */ 1374, 1374, 1374, 1363, 1368, 1368, 1463, 1341, 1334, 1233, - /* 310 */ 1629, 1629, 1349, 1349, 1628, 1628, 1349, 1484, 1613, 1409, - /* 320 */ 1311, 1317, 1317, 1317, 1317, 1349, 1251, 1387, 1613, 1613, - /* 330 */ 1387, 1409, 1311, 1387, 1311, 1387, 1349, 1251, 1500, 1623, - /* 340 */ 1349, 1251, 1474, 1349, 1251, 1349, 1251, 1474, 1309, 1309, - /* 350 */ 1309, 1298, 1233, 1233, 1474, 1309, 1283, 1309, 1298, 1309, - /* 360 */ 1309, 1572, 1233, 1478, 1478, 1474, 1367, 1362, 1367, 1362, - /* 370 */ 1367, 1362, 1367, 1362, 1349, 1564, 1564, 1377, 1377, 1382, - /* 380 */ 1368, 1469, 1349, 1233, 1382, 1380, 1378, 1387, 1301, 1586, - /* 390 */ 1586, 1582, 1582, 1582, 1634, 1634, 1533, 1599, 1266, 1266, - /* 400 */ 1266, 1266, 1599, 1285, 1285, 1267, 1267, 1266, 1599, 1233, - /* 410 */ 1233, 1233, 1233, 1233, 1233, 1594, 1233, 1528, 1485, 1353, - /* 420 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, - /* 430 */ 1233, 1233, 1233, 1233, 1539, 1233, 1233, 1233, 1233, 1233, - /* 440 */ 1233, 1233, 1233, 1233, 1233, 1414, 1233, 1236, 1530, 1233, - /* 450 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1391, 1392, 1354, - /* 460 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1406, 1233, 1233, - /* 470 */ 1233, 1401, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, - /* 480 */ 1625, 1233, 1233, 1233, 1233, 1233, 1233, 1499, 1498, 1233, - /* 490 */ 1233, 1351, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, - /* 500 */ 1233, 1233, 1233, 1233, 1233, 1281, 1233, 1233, 1233, 1233, - /* 510 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, - /* 520 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1379, - /* 530 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, - /* 540 */ 1233, 1233, 1233, 1233, 1569, 1369, 1233, 1233, 1616, 1233, - /* 550 */ 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, 1233, - /* 560 */ 1233, 1233, 1233, 1610, 1325, 1416, 1233, 1415, 1419, 1255, - /* 570 */ 1233, 1245, 1233, 1233, + /* 0 */ 1633, 1633, 1633, 1462, 1230, 1341, 1230, 1230, 1230, 1462, + /* 10 */ 1462, 1462, 1230, 1371, 1371, 1515, 1263, 1230, 1230, 1230, + /* 20 */ 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1461, 1230, 1230, + /* 30 */ 1230, 1230, 1550, 1550, 1230, 1230, 1230, 1230, 1230, 1230, + /* 40 */ 1230, 1230, 1380, 1230, 1387, 1230, 1230, 1230, 1230, 1230, + /* 50 */ 1463, 1464, 1230, 1230, 1230, 1514, 1516, 1479, 1394, 1393, + /* 60 */ 1392, 1391, 1497, 1358, 1385, 1378, 1382, 1457, 1458, 1456, + /* 70 */ 1460, 1464, 1463, 1230, 1381, 1428, 1442, 1427, 1230, 1230, + /* 80 */ 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, + /* 90 */ 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, + /* 100 */ 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, + /* 110 */ 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, + /* 120 */ 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1436, 1441, 1447, + /* 130 */ 1440, 1437, 1430, 1429, 1431, 1230, 1432, 1230, 1254, 1230, + /* 140 */ 1230, 1251, 1305, 1230, 1230, 1230, 1230, 1230, 1534, 1533, + /* 150 */ 1230, 1230, 1263, 1422, 1421, 1433, 1434, 1444, 1443, 1522, + /* 160 */ 1586, 1585, 1480, 1230, 1230, 1230, 1230, 1230, 1230, 1550, + /* 170 */ 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, + /* 180 */ 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, + /* 190 */ 1230, 1230, 1230, 1550, 1550, 1230, 1263, 1550, 1550, 1259, + /* 200 */ 1259, 1365, 1230, 1529, 1332, 1332, 1332, 1332, 1341, 1332, + /* 210 */ 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, + /* 220 */ 1230, 1230, 1230, 1230, 1230, 1519, 1517, 1230, 1230, 1230, + /* 230 */ 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, + /* 240 */ 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, + /* 250 */ 1230, 1230, 1230, 1230, 1337, 1230, 1230, 1230, 1230, 1230, + /* 260 */ 1230, 1230, 1230, 1230, 1230, 1230, 1579, 1230, 1492, 1319, + /* 270 */ 1337, 1337, 1337, 1337, 1339, 1320, 1318, 1331, 1264, 1237, + /* 280 */ 1625, 1397, 1386, 1338, 1360, 1386, 1360, 1622, 1384, 1397, + /* 290 */ 1397, 1384, 1397, 1338, 1622, 1280, 1602, 1275, 1371, 1371, + /* 300 */ 1371, 1360, 1365, 1365, 1459, 1338, 1331, 1230, 1625, 1625, + /* 310 */ 1346, 1346, 1624, 1624, 1346, 1480, 1609, 1406, 1308, 1314, + /* 320 */ 1314, 1314, 1314, 1346, 1248, 1384, 1609, 1609, 1384, 1406, + /* 330 */ 1308, 1384, 1308, 1384, 1346, 1248, 1496, 1619, 1346, 1248, + /* 340 */ 1470, 1346, 1248, 1346, 1248, 1470, 1306, 1306, 1306, 1295, + /* 350 */ 1230, 1230, 1470, 1306, 1280, 1306, 1295, 1306, 1306, 1568, + /* 360 */ 1230, 1474, 1474, 1470, 1364, 1359, 1364, 1359, 1364, 1359, + /* 370 */ 1364, 1359, 1346, 1560, 1560, 1374, 1374, 1379, 1365, 1465, + /* 380 */ 1346, 1230, 1379, 1377, 1375, 1384, 1298, 1582, 1582, 1578, + /* 390 */ 1578, 1578, 1630, 1630, 1529, 1595, 1263, 1263, 1263, 1263, + /* 400 */ 1595, 1282, 1282, 1264, 1264, 1263, 1595, 1230, 1230, 1230, + /* 410 */ 1230, 1230, 1230, 1590, 1230, 1524, 1481, 1350, 1230, 1230, + /* 420 */ 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, + /* 430 */ 1230, 1230, 1535, 1230, 1230, 1230, 1230, 1230, 1230, 1230, + /* 440 */ 1230, 1230, 1230, 1411, 1230, 1233, 1526, 1230, 1230, 1230, + /* 450 */ 1230, 1230, 1230, 1230, 1230, 1388, 1389, 1351, 1230, 1230, + /* 460 */ 1230, 1230, 1230, 1230, 1230, 1403, 1230, 1230, 1230, 1398, + /* 470 */ 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1621, 1230, + /* 480 */ 1230, 1230, 1230, 1230, 1230, 1495, 1494, 1230, 1230, 1348, + /* 490 */ 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, + /* 500 */ 1230, 1230, 1230, 1278, 1230, 1230, 1230, 1230, 1230, 1230, + /* 510 */ 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, + /* 520 */ 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1376, 1230, 1230, + /* 530 */ 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, + /* 540 */ 1230, 1230, 1565, 1366, 1230, 1230, 1612, 1230, 1230, 1230, + /* 550 */ 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, 1230, + /* 560 */ 1230, 1606, 1322, 1413, 1230, 1412, 1416, 1252, 1230, 1242, + /* 570 */ 1230, 1230, }; /********** End of lemon-generated parsing tables *****************************/ /* The next table maps tokens (terminal symbols) into fallback tokens. ** If a construct like the following: @@ -162725,11 +159997,10 @@ 0, /* MINUS => nothing */ 0, /* STAR => nothing */ 0, /* SLASH => nothing */ 0, /* REM => nothing */ 0, /* CONCAT => nothing */ - 0, /* PTR => nothing */ 0, /* COLLATE => nothing */ 0, /* BITNOT => nothing */ 0, /* ON => nothing */ 0, /* INDEXED => nothing */ 0, /* STRING => nothing */ @@ -162849,13 +160120,13 @@ yyStackEntry *yystackEnd; /* Last entry in the stack */ #endif }; typedef struct yyParser yyParser; -/* #include */ #ifndef NDEBUG /* #include */ +/* #include */ static FILE *yyTraceFILE = 0; static char *yyTracePrompt = 0; #endif /* NDEBUG */ #ifndef NDEBUG @@ -162998,217 +160269,216 @@ /* 107 */ "MINUS", /* 108 */ "STAR", /* 109 */ "SLASH", /* 110 */ "REM", /* 111 */ "CONCAT", - /* 112 */ "PTR", - /* 113 */ "COLLATE", - /* 114 */ "BITNOT", - /* 115 */ "ON", - /* 116 */ "INDEXED", - /* 117 */ "STRING", - /* 118 */ "JOIN_KW", - /* 119 */ "CONSTRAINT", - /* 120 */ "DEFAULT", - /* 121 */ "NULL", - /* 122 */ "PRIMARY", - /* 123 */ "UNIQUE", - /* 124 */ "CHECK", - /* 125 */ "REFERENCES", - /* 126 */ "AUTOINCR", - /* 127 */ "INSERT", - /* 128 */ "DELETE", - /* 129 */ "UPDATE", - /* 130 */ "SET", - /* 131 */ "DEFERRABLE", - /* 132 */ "FOREIGN", - /* 133 */ "DROP", - /* 134 */ "UNION", - /* 135 */ "ALL", - /* 136 */ "EXCEPT", - /* 137 */ "INTERSECT", - /* 138 */ "SELECT", - /* 139 */ "VALUES", - /* 140 */ "DISTINCT", - /* 141 */ "DOT", - /* 142 */ "FROM", - /* 143 */ "JOIN", - /* 144 */ "USING", - /* 145 */ "ORDER", - /* 146 */ "GROUP", - /* 147 */ "HAVING", - /* 148 */ "LIMIT", - /* 149 */ "WHERE", - /* 150 */ "RETURNING", - /* 151 */ "INTO", - /* 152 */ "NOTHING", - /* 153 */ "FLOAT", - /* 154 */ "BLOB", - /* 155 */ "INTEGER", - /* 156 */ "VARIABLE", - /* 157 */ "CASE", - /* 158 */ "WHEN", - /* 159 */ "THEN", - /* 160 */ "ELSE", - /* 161 */ "INDEX", - /* 162 */ "ALTER", - /* 163 */ "ADD", - /* 164 */ "WINDOW", - /* 165 */ "OVER", - /* 166 */ "FILTER", - /* 167 */ "COLUMN", - /* 168 */ "AGG_FUNCTION", - /* 169 */ "AGG_COLUMN", - /* 170 */ "TRUEFALSE", - /* 171 */ "ISNOT", - /* 172 */ "FUNCTION", - /* 173 */ "UMINUS", - /* 174 */ "UPLUS", - /* 175 */ "TRUTH", - /* 176 */ "REGISTER", - /* 177 */ "VECTOR", - /* 178 */ "SELECT_COLUMN", - /* 179 */ "IF_NULL_ROW", - /* 180 */ "ASTERISK", - /* 181 */ "SPAN", - /* 182 */ "ERROR", - /* 183 */ "SPACE", - /* 184 */ "ILLEGAL", - /* 185 */ "input", - /* 186 */ "cmdlist", - /* 187 */ "ecmd", - /* 188 */ "cmdx", - /* 189 */ "explain", - /* 190 */ "cmd", - /* 191 */ "transtype", - /* 192 */ "trans_opt", - /* 193 */ "nm", - /* 194 */ "savepoint_opt", - /* 195 */ "create_table", - /* 196 */ "create_table_args", - /* 197 */ "createkw", - /* 198 */ "temp", - /* 199 */ "ifnotexists", - /* 200 */ "dbnm", - /* 201 */ "columnlist", - /* 202 */ "conslist_opt", - /* 203 */ "table_option_set", - /* 204 */ "select", - /* 205 */ "table_option", - /* 206 */ "columnname", - /* 207 */ "carglist", - /* 208 */ "typetoken", - /* 209 */ "typename", - /* 210 */ "signed", - /* 211 */ "plus_num", - /* 212 */ "minus_num", - /* 213 */ "scanpt", - /* 214 */ "scantok", - /* 215 */ "ccons", - /* 216 */ "term", - /* 217 */ "expr", - /* 218 */ "onconf", - /* 219 */ "sortorder", - /* 220 */ "autoinc", - /* 221 */ "eidlist_opt", - /* 222 */ "refargs", - /* 223 */ "defer_subclause", - /* 224 */ "generated", - /* 225 */ "refarg", - /* 226 */ "refact", - /* 227 */ "init_deferred_pred_opt", - /* 228 */ "conslist", - /* 229 */ "tconscomma", - /* 230 */ "tcons", - /* 231 */ "sortlist", - /* 232 */ "eidlist", - /* 233 */ "defer_subclause_opt", - /* 234 */ "orconf", - /* 235 */ "resolvetype", - /* 236 */ "raisetype", - /* 237 */ "ifexists", - /* 238 */ "fullname", - /* 239 */ "selectnowith", - /* 240 */ "oneselect", - /* 241 */ "wqlist", - /* 242 */ "multiselect_op", - /* 243 */ "distinct", - /* 244 */ "selcollist", - /* 245 */ "from", - /* 246 */ "where_opt", - /* 247 */ "groupby_opt", - /* 248 */ "having_opt", - /* 249 */ "orderby_opt", - /* 250 */ "limit_opt", - /* 251 */ "window_clause", - /* 252 */ "values", - /* 253 */ "nexprlist", - /* 254 */ "sclp", - /* 255 */ "as", - /* 256 */ "seltablist", - /* 257 */ "stl_prefix", - /* 258 */ "joinop", - /* 259 */ "indexed_opt", - /* 260 */ "on_opt", - /* 261 */ "using_opt", - /* 262 */ "exprlist", - /* 263 */ "xfullname", - /* 264 */ "idlist", - /* 265 */ "nulls", - /* 266 */ "with", - /* 267 */ "where_opt_ret", - /* 268 */ "setlist", - /* 269 */ "insert_cmd", - /* 270 */ "idlist_opt", - /* 271 */ "upsert", - /* 272 */ "returning", - /* 273 */ "filter_over", - /* 274 */ "likeop", - /* 275 */ "between_op", - /* 276 */ "in_op", - /* 277 */ "paren_exprlist", - /* 278 */ "case_operand", - /* 279 */ "case_exprlist", - /* 280 */ "case_else", - /* 281 */ "uniqueflag", - /* 282 */ "collate", - /* 283 */ "vinto", - /* 284 */ "nmnum", - /* 285 */ "trigger_decl", - /* 286 */ "trigger_cmd_list", - /* 287 */ "trigger_time", - /* 288 */ "trigger_event", - /* 289 */ "foreach_clause", - /* 290 */ "when_clause", - /* 291 */ "trigger_cmd", - /* 292 */ "trnm", - /* 293 */ "tridxby", - /* 294 */ "database_kw_opt", - /* 295 */ "key_opt", - /* 296 */ "add_column_fullname", - /* 297 */ "kwcolumn_opt", - /* 298 */ "create_vtab", - /* 299 */ "vtabarglist", - /* 300 */ "vtabarg", - /* 301 */ "vtabargtoken", - /* 302 */ "lp", - /* 303 */ "anylist", - /* 304 */ "wqitem", - /* 305 */ "wqas", - /* 306 */ "windowdefn_list", - /* 307 */ "windowdefn", - /* 308 */ "window", - /* 309 */ "frame_opt", - /* 310 */ "part_opt", - /* 311 */ "filter_clause", - /* 312 */ "over_clause", - /* 313 */ "range_or_rows", - /* 314 */ "frame_bound", - /* 315 */ "frame_bound_s", - /* 316 */ "frame_bound_e", - /* 317 */ "frame_exclude_opt", - /* 318 */ "frame_exclude", + /* 112 */ "COLLATE", + /* 113 */ "BITNOT", + /* 114 */ "ON", + /* 115 */ "INDEXED", + /* 116 */ "STRING", + /* 117 */ "JOIN_KW", + /* 118 */ "CONSTRAINT", + /* 119 */ "DEFAULT", + /* 120 */ "NULL", + /* 121 */ "PRIMARY", + /* 122 */ "UNIQUE", + /* 123 */ "CHECK", + /* 124 */ "REFERENCES", + /* 125 */ "AUTOINCR", + /* 126 */ "INSERT", + /* 127 */ "DELETE", + /* 128 */ "UPDATE", + /* 129 */ "SET", + /* 130 */ "DEFERRABLE", + /* 131 */ "FOREIGN", + /* 132 */ "DROP", + /* 133 */ "UNION", + /* 134 */ "ALL", + /* 135 */ "EXCEPT", + /* 136 */ "INTERSECT", + /* 137 */ "SELECT", + /* 138 */ "VALUES", + /* 139 */ "DISTINCT", + /* 140 */ "DOT", + /* 141 */ "FROM", + /* 142 */ "JOIN", + /* 143 */ "USING", + /* 144 */ "ORDER", + /* 145 */ "GROUP", + /* 146 */ "HAVING", + /* 147 */ "LIMIT", + /* 148 */ "WHERE", + /* 149 */ "RETURNING", + /* 150 */ "INTO", + /* 151 */ "NOTHING", + /* 152 */ "FLOAT", + /* 153 */ "BLOB", + /* 154 */ "INTEGER", + /* 155 */ "VARIABLE", + /* 156 */ "CASE", + /* 157 */ "WHEN", + /* 158 */ "THEN", + /* 159 */ "ELSE", + /* 160 */ "INDEX", + /* 161 */ "ALTER", + /* 162 */ "ADD", + /* 163 */ "WINDOW", + /* 164 */ "OVER", + /* 165 */ "FILTER", + /* 166 */ "COLUMN", + /* 167 */ "AGG_FUNCTION", + /* 168 */ "AGG_COLUMN", + /* 169 */ "TRUEFALSE", + /* 170 */ "ISNOT", + /* 171 */ "FUNCTION", + /* 172 */ "UMINUS", + /* 173 */ "UPLUS", + /* 174 */ "TRUTH", + /* 175 */ "REGISTER", + /* 176 */ "VECTOR", + /* 177 */ "SELECT_COLUMN", + /* 178 */ "IF_NULL_ROW", + /* 179 */ "ASTERISK", + /* 180 */ "SPAN", + /* 181 */ "ERROR", + /* 182 */ "SPACE", + /* 183 */ "ILLEGAL", + /* 184 */ "input", + /* 185 */ "cmdlist", + /* 186 */ "ecmd", + /* 187 */ "cmdx", + /* 188 */ "explain", + /* 189 */ "cmd", + /* 190 */ "transtype", + /* 191 */ "trans_opt", + /* 192 */ "nm", + /* 193 */ "savepoint_opt", + /* 194 */ "create_table", + /* 195 */ "create_table_args", + /* 196 */ "createkw", + /* 197 */ "temp", + /* 198 */ "ifnotexists", + /* 199 */ "dbnm", + /* 200 */ "columnlist", + /* 201 */ "conslist_opt", + /* 202 */ "table_option_set", + /* 203 */ "select", + /* 204 */ "table_option", + /* 205 */ "columnname", + /* 206 */ "carglist", + /* 207 */ "typetoken", + /* 208 */ "typename", + /* 209 */ "signed", + /* 210 */ "plus_num", + /* 211 */ "minus_num", + /* 212 */ "scanpt", + /* 213 */ "scantok", + /* 214 */ "ccons", + /* 215 */ "term", + /* 216 */ "expr", + /* 217 */ "onconf", + /* 218 */ "sortorder", + /* 219 */ "autoinc", + /* 220 */ "eidlist_opt", + /* 221 */ "refargs", + /* 222 */ "defer_subclause", + /* 223 */ "generated", + /* 224 */ "refarg", + /* 225 */ "refact", + /* 226 */ "init_deferred_pred_opt", + /* 227 */ "conslist", + /* 228 */ "tconscomma", + /* 229 */ "tcons", + /* 230 */ "sortlist", + /* 231 */ "eidlist", + /* 232 */ "defer_subclause_opt", + /* 233 */ "orconf", + /* 234 */ "resolvetype", + /* 235 */ "raisetype", + /* 236 */ "ifexists", + /* 237 */ "fullname", + /* 238 */ "selectnowith", + /* 239 */ "oneselect", + /* 240 */ "wqlist", + /* 241 */ "multiselect_op", + /* 242 */ "distinct", + /* 243 */ "selcollist", + /* 244 */ "from", + /* 245 */ "where_opt", + /* 246 */ "groupby_opt", + /* 247 */ "having_opt", + /* 248 */ "orderby_opt", + /* 249 */ "limit_opt", + /* 250 */ "window_clause", + /* 251 */ "values", + /* 252 */ "nexprlist", + /* 253 */ "sclp", + /* 254 */ "as", + /* 255 */ "seltablist", + /* 256 */ "stl_prefix", + /* 257 */ "joinop", + /* 258 */ "indexed_opt", + /* 259 */ "on_opt", + /* 260 */ "using_opt", + /* 261 */ "exprlist", + /* 262 */ "xfullname", + /* 263 */ "idlist", + /* 264 */ "nulls", + /* 265 */ "with", + /* 266 */ "where_opt_ret", + /* 267 */ "setlist", + /* 268 */ "insert_cmd", + /* 269 */ "idlist_opt", + /* 270 */ "upsert", + /* 271 */ "returning", + /* 272 */ "filter_over", + /* 273 */ "likeop", + /* 274 */ "between_op", + /* 275 */ "in_op", + /* 276 */ "paren_exprlist", + /* 277 */ "case_operand", + /* 278 */ "case_exprlist", + /* 279 */ "case_else", + /* 280 */ "uniqueflag", + /* 281 */ "collate", + /* 282 */ "vinto", + /* 283 */ "nmnum", + /* 284 */ "trigger_decl", + /* 285 */ "trigger_cmd_list", + /* 286 */ "trigger_time", + /* 287 */ "trigger_event", + /* 288 */ "foreach_clause", + /* 289 */ "when_clause", + /* 290 */ "trigger_cmd", + /* 291 */ "trnm", + /* 292 */ "tridxby", + /* 293 */ "database_kw_opt", + /* 294 */ "key_opt", + /* 295 */ "add_column_fullname", + /* 296 */ "kwcolumn_opt", + /* 297 */ "create_vtab", + /* 298 */ "vtabarglist", + /* 299 */ "vtabarg", + /* 300 */ "vtabargtoken", + /* 301 */ "lp", + /* 302 */ "anylist", + /* 303 */ "wqitem", + /* 304 */ "wqas", + /* 305 */ "windowdefn_list", + /* 306 */ "windowdefn", + /* 307 */ "window", + /* 308 */ "frame_opt", + /* 309 */ "part_opt", + /* 310 */ "filter_clause", + /* 311 */ "over_clause", + /* 312 */ "range_or_rows", + /* 313 */ "frame_bound", + /* 314 */ "frame_bound_s", + /* 315 */ "frame_bound_e", + /* 316 */ "frame_exclude_opt", + /* 317 */ "frame_exclude", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ #ifndef NDEBUG /* For tracing reduce actions, the names of all rules are required. @@ -163424,200 +160694,199 @@ /* 207 */ "expr ::= expr IS expr", /* 208 */ "expr ::= expr IS NOT expr", /* 209 */ "expr ::= NOT expr", /* 210 */ "expr ::= BITNOT expr", /* 211 */ "expr ::= PLUS|MINUS expr", - /* 212 */ "expr ::= expr PTR expr", - /* 213 */ "between_op ::= BETWEEN", - /* 214 */ "between_op ::= NOT BETWEEN", - /* 215 */ "expr ::= expr between_op expr AND expr", - /* 216 */ "in_op ::= IN", - /* 217 */ "in_op ::= NOT IN", - /* 218 */ "expr ::= expr in_op LP exprlist RP", - /* 219 */ "expr ::= LP select RP", - /* 220 */ "expr ::= expr in_op LP select RP", - /* 221 */ "expr ::= expr in_op nm dbnm paren_exprlist", - /* 222 */ "expr ::= EXISTS LP select RP", - /* 223 */ "expr ::= CASE case_operand case_exprlist case_else END", - /* 224 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr", - /* 225 */ "case_exprlist ::= WHEN expr THEN expr", - /* 226 */ "case_else ::= ELSE expr", - /* 227 */ "case_else ::=", - /* 228 */ "case_operand ::= expr", - /* 229 */ "case_operand ::=", - /* 230 */ "exprlist ::=", - /* 231 */ "nexprlist ::= nexprlist COMMA expr", - /* 232 */ "nexprlist ::= expr", - /* 233 */ "paren_exprlist ::=", - /* 234 */ "paren_exprlist ::= LP exprlist RP", - /* 235 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt", - /* 236 */ "uniqueflag ::= UNIQUE", - /* 237 */ "uniqueflag ::=", - /* 238 */ "eidlist_opt ::=", - /* 239 */ "eidlist_opt ::= LP eidlist RP", - /* 240 */ "eidlist ::= eidlist COMMA nm collate sortorder", - /* 241 */ "eidlist ::= nm collate sortorder", - /* 242 */ "collate ::=", - /* 243 */ "collate ::= COLLATE ID|STRING", - /* 244 */ "cmd ::= DROP INDEX ifexists fullname", - /* 245 */ "cmd ::= VACUUM vinto", - /* 246 */ "cmd ::= VACUUM nm vinto", - /* 247 */ "vinto ::= INTO expr", - /* 248 */ "vinto ::=", - /* 249 */ "cmd ::= PRAGMA nm dbnm", - /* 250 */ "cmd ::= PRAGMA nm dbnm EQ nmnum", - /* 251 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP", - /* 252 */ "cmd ::= PRAGMA nm dbnm EQ minus_num", - /* 253 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP", - /* 254 */ "plus_num ::= PLUS INTEGER|FLOAT", - /* 255 */ "minus_num ::= MINUS INTEGER|FLOAT", - /* 256 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END", - /* 257 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause", - /* 258 */ "trigger_time ::= BEFORE|AFTER", - /* 259 */ "trigger_time ::= INSTEAD OF", - /* 260 */ "trigger_time ::=", - /* 261 */ "trigger_event ::= DELETE|INSERT", - /* 262 */ "trigger_event ::= UPDATE", - /* 263 */ "trigger_event ::= UPDATE OF idlist", - /* 264 */ "when_clause ::=", - /* 265 */ "when_clause ::= WHEN expr", - /* 266 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI", - /* 267 */ "trigger_cmd_list ::= trigger_cmd SEMI", - /* 268 */ "trnm ::= nm DOT nm", - /* 269 */ "tridxby ::= INDEXED BY nm", - /* 270 */ "tridxby ::= NOT INDEXED", - /* 271 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt", - /* 272 */ "trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt", - /* 273 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt", - /* 274 */ "trigger_cmd ::= scanpt select scanpt", - /* 275 */ "expr ::= RAISE LP IGNORE RP", - /* 276 */ "expr ::= RAISE LP raisetype COMMA nm RP", - /* 277 */ "raisetype ::= ROLLBACK", - /* 278 */ "raisetype ::= ABORT", - /* 279 */ "raisetype ::= FAIL", - /* 280 */ "cmd ::= DROP TRIGGER ifexists fullname", - /* 281 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt", - /* 282 */ "cmd ::= DETACH database_kw_opt expr", - /* 283 */ "key_opt ::=", - /* 284 */ "key_opt ::= KEY expr", - /* 285 */ "cmd ::= REINDEX", - /* 286 */ "cmd ::= REINDEX nm dbnm", - /* 287 */ "cmd ::= ANALYZE", - /* 288 */ "cmd ::= ANALYZE nm dbnm", - /* 289 */ "cmd ::= ALTER TABLE fullname RENAME TO nm", - /* 290 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist", - /* 291 */ "cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm", - /* 292 */ "add_column_fullname ::= fullname", - /* 293 */ "cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm", - /* 294 */ "cmd ::= create_vtab", - /* 295 */ "cmd ::= create_vtab LP vtabarglist RP", - /* 296 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm", - /* 297 */ "vtabarg ::=", - /* 298 */ "vtabargtoken ::= ANY", - /* 299 */ "vtabargtoken ::= lp anylist RP", - /* 300 */ "lp ::= LP", - /* 301 */ "with ::= WITH wqlist", - /* 302 */ "with ::= WITH RECURSIVE wqlist", - /* 303 */ "wqas ::= AS", - /* 304 */ "wqas ::= AS MATERIALIZED", - /* 305 */ "wqas ::= AS NOT MATERIALIZED", - /* 306 */ "wqitem ::= nm eidlist_opt wqas LP select RP", - /* 307 */ "wqlist ::= wqitem", - /* 308 */ "wqlist ::= wqlist COMMA wqitem", - /* 309 */ "windowdefn_list ::= windowdefn", - /* 310 */ "windowdefn_list ::= windowdefn_list COMMA windowdefn", - /* 311 */ "windowdefn ::= nm AS LP window RP", - /* 312 */ "window ::= PARTITION BY nexprlist orderby_opt frame_opt", - /* 313 */ "window ::= nm PARTITION BY nexprlist orderby_opt frame_opt", - /* 314 */ "window ::= ORDER BY sortlist frame_opt", - /* 315 */ "window ::= nm ORDER BY sortlist frame_opt", - /* 316 */ "window ::= frame_opt", - /* 317 */ "window ::= nm frame_opt", - /* 318 */ "frame_opt ::=", - /* 319 */ "frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt", - /* 320 */ "frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt", - /* 321 */ "range_or_rows ::= RANGE|ROWS|GROUPS", - /* 322 */ "frame_bound_s ::= frame_bound", - /* 323 */ "frame_bound_s ::= UNBOUNDED PRECEDING", - /* 324 */ "frame_bound_e ::= frame_bound", - /* 325 */ "frame_bound_e ::= UNBOUNDED FOLLOWING", - /* 326 */ "frame_bound ::= expr PRECEDING|FOLLOWING", - /* 327 */ "frame_bound ::= CURRENT ROW", - /* 328 */ "frame_exclude_opt ::=", - /* 329 */ "frame_exclude_opt ::= EXCLUDE frame_exclude", - /* 330 */ "frame_exclude ::= NO OTHERS", - /* 331 */ "frame_exclude ::= CURRENT ROW", - /* 332 */ "frame_exclude ::= GROUP|TIES", - /* 333 */ "window_clause ::= WINDOW windowdefn_list", - /* 334 */ "filter_over ::= filter_clause over_clause", - /* 335 */ "filter_over ::= over_clause", - /* 336 */ "filter_over ::= filter_clause", - /* 337 */ "over_clause ::= OVER LP window RP", - /* 338 */ "over_clause ::= OVER nm", - /* 339 */ "filter_clause ::= FILTER LP WHERE expr RP", - /* 340 */ "input ::= cmdlist", - /* 341 */ "cmdlist ::= cmdlist ecmd", - /* 342 */ "cmdlist ::= ecmd", - /* 343 */ "ecmd ::= SEMI", - /* 344 */ "ecmd ::= cmdx SEMI", - /* 345 */ "ecmd ::= explain cmdx SEMI", - /* 346 */ "trans_opt ::=", - /* 347 */ "trans_opt ::= TRANSACTION", - /* 348 */ "trans_opt ::= TRANSACTION nm", - /* 349 */ "savepoint_opt ::= SAVEPOINT", - /* 350 */ "savepoint_opt ::=", - /* 351 */ "cmd ::= create_table create_table_args", - /* 352 */ "table_option_set ::= table_option", - /* 353 */ "columnlist ::= columnlist COMMA columnname carglist", - /* 354 */ "columnlist ::= columnname carglist", - /* 355 */ "nm ::= ID|INDEXED", - /* 356 */ "nm ::= STRING", - /* 357 */ "nm ::= JOIN_KW", - /* 358 */ "typetoken ::= typename", - /* 359 */ "typename ::= ID|STRING", - /* 360 */ "signed ::= plus_num", - /* 361 */ "signed ::= minus_num", - /* 362 */ "carglist ::= carglist ccons", - /* 363 */ "carglist ::=", - /* 364 */ "ccons ::= NULL onconf", - /* 365 */ "ccons ::= GENERATED ALWAYS AS generated", - /* 366 */ "ccons ::= AS generated", - /* 367 */ "conslist_opt ::= COMMA conslist", - /* 368 */ "conslist ::= conslist tconscomma tcons", - /* 369 */ "conslist ::= tcons", - /* 370 */ "tconscomma ::=", - /* 371 */ "defer_subclause_opt ::= defer_subclause", - /* 372 */ "resolvetype ::= raisetype", - /* 373 */ "selectnowith ::= oneselect", - /* 374 */ "oneselect ::= values", - /* 375 */ "sclp ::= selcollist COMMA", - /* 376 */ "as ::= ID|STRING", - /* 377 */ "returning ::=", - /* 378 */ "expr ::= term", - /* 379 */ "likeop ::= LIKE_KW|MATCH", - /* 380 */ "exprlist ::= nexprlist", - /* 381 */ "nmnum ::= plus_num", - /* 382 */ "nmnum ::= nm", - /* 383 */ "nmnum ::= ON", - /* 384 */ "nmnum ::= DELETE", - /* 385 */ "nmnum ::= DEFAULT", - /* 386 */ "plus_num ::= INTEGER|FLOAT", - /* 387 */ "foreach_clause ::=", - /* 388 */ "foreach_clause ::= FOR EACH ROW", - /* 389 */ "trnm ::= nm", - /* 390 */ "tridxby ::=", - /* 391 */ "database_kw_opt ::= DATABASE", - /* 392 */ "database_kw_opt ::=", - /* 393 */ "kwcolumn_opt ::=", - /* 394 */ "kwcolumn_opt ::= COLUMNKW", - /* 395 */ "vtabarglist ::= vtabarg", - /* 396 */ "vtabarglist ::= vtabarglist COMMA vtabarg", - /* 397 */ "vtabarg ::= vtabarg vtabargtoken", - /* 398 */ "anylist ::=", - /* 399 */ "anylist ::= anylist LP anylist RP", - /* 400 */ "anylist ::= anylist ANY", - /* 401 */ "with ::=", + /* 212 */ "between_op ::= BETWEEN", + /* 213 */ "between_op ::= NOT BETWEEN", + /* 214 */ "expr ::= expr between_op expr AND expr", + /* 215 */ "in_op ::= IN", + /* 216 */ "in_op ::= NOT IN", + /* 217 */ "expr ::= expr in_op LP exprlist RP", + /* 218 */ "expr ::= LP select RP", + /* 219 */ "expr ::= expr in_op LP select RP", + /* 220 */ "expr ::= expr in_op nm dbnm paren_exprlist", + /* 221 */ "expr ::= EXISTS LP select RP", + /* 222 */ "expr ::= CASE case_operand case_exprlist case_else END", + /* 223 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr", + /* 224 */ "case_exprlist ::= WHEN expr THEN expr", + /* 225 */ "case_else ::= ELSE expr", + /* 226 */ "case_else ::=", + /* 227 */ "case_operand ::= expr", + /* 228 */ "case_operand ::=", + /* 229 */ "exprlist ::=", + /* 230 */ "nexprlist ::= nexprlist COMMA expr", + /* 231 */ "nexprlist ::= expr", + /* 232 */ "paren_exprlist ::=", + /* 233 */ "paren_exprlist ::= LP exprlist RP", + /* 234 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt", + /* 235 */ "uniqueflag ::= UNIQUE", + /* 236 */ "uniqueflag ::=", + /* 237 */ "eidlist_opt ::=", + /* 238 */ "eidlist_opt ::= LP eidlist RP", + /* 239 */ "eidlist ::= eidlist COMMA nm collate sortorder", + /* 240 */ "eidlist ::= nm collate sortorder", + /* 241 */ "collate ::=", + /* 242 */ "collate ::= COLLATE ID|STRING", + /* 243 */ "cmd ::= DROP INDEX ifexists fullname", + /* 244 */ "cmd ::= VACUUM vinto", + /* 245 */ "cmd ::= VACUUM nm vinto", + /* 246 */ "vinto ::= INTO expr", + /* 247 */ "vinto ::=", + /* 248 */ "cmd ::= PRAGMA nm dbnm", + /* 249 */ "cmd ::= PRAGMA nm dbnm EQ nmnum", + /* 250 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP", + /* 251 */ "cmd ::= PRAGMA nm dbnm EQ minus_num", + /* 252 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP", + /* 253 */ "plus_num ::= PLUS INTEGER|FLOAT", + /* 254 */ "minus_num ::= MINUS INTEGER|FLOAT", + /* 255 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END", + /* 256 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause", + /* 257 */ "trigger_time ::= BEFORE|AFTER", + /* 258 */ "trigger_time ::= INSTEAD OF", + /* 259 */ "trigger_time ::=", + /* 260 */ "trigger_event ::= DELETE|INSERT", + /* 261 */ "trigger_event ::= UPDATE", + /* 262 */ "trigger_event ::= UPDATE OF idlist", + /* 263 */ "when_clause ::=", + /* 264 */ "when_clause ::= WHEN expr", + /* 265 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI", + /* 266 */ "trigger_cmd_list ::= trigger_cmd SEMI", + /* 267 */ "trnm ::= nm DOT nm", + /* 268 */ "tridxby ::= INDEXED BY nm", + /* 269 */ "tridxby ::= NOT INDEXED", + /* 270 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt", + /* 271 */ "trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt", + /* 272 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt", + /* 273 */ "trigger_cmd ::= scanpt select scanpt", + /* 274 */ "expr ::= RAISE LP IGNORE RP", + /* 275 */ "expr ::= RAISE LP raisetype COMMA nm RP", + /* 276 */ "raisetype ::= ROLLBACK", + /* 277 */ "raisetype ::= ABORT", + /* 278 */ "raisetype ::= FAIL", + /* 279 */ "cmd ::= DROP TRIGGER ifexists fullname", + /* 280 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt", + /* 281 */ "cmd ::= DETACH database_kw_opt expr", + /* 282 */ "key_opt ::=", + /* 283 */ "key_opt ::= KEY expr", + /* 284 */ "cmd ::= REINDEX", + /* 285 */ "cmd ::= REINDEX nm dbnm", + /* 286 */ "cmd ::= ANALYZE", + /* 287 */ "cmd ::= ANALYZE nm dbnm", + /* 288 */ "cmd ::= ALTER TABLE fullname RENAME TO nm", + /* 289 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist", + /* 290 */ "cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm", + /* 291 */ "add_column_fullname ::= fullname", + /* 292 */ "cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm", + /* 293 */ "cmd ::= create_vtab", + /* 294 */ "cmd ::= create_vtab LP vtabarglist RP", + /* 295 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm", + /* 296 */ "vtabarg ::=", + /* 297 */ "vtabargtoken ::= ANY", + /* 298 */ "vtabargtoken ::= lp anylist RP", + /* 299 */ "lp ::= LP", + /* 300 */ "with ::= WITH wqlist", + /* 301 */ "with ::= WITH RECURSIVE wqlist", + /* 302 */ "wqas ::= AS", + /* 303 */ "wqas ::= AS MATERIALIZED", + /* 304 */ "wqas ::= AS NOT MATERIALIZED", + /* 305 */ "wqitem ::= nm eidlist_opt wqas LP select RP", + /* 306 */ "wqlist ::= wqitem", + /* 307 */ "wqlist ::= wqlist COMMA wqitem", + /* 308 */ "windowdefn_list ::= windowdefn", + /* 309 */ "windowdefn_list ::= windowdefn_list COMMA windowdefn", + /* 310 */ "windowdefn ::= nm AS LP window RP", + /* 311 */ "window ::= PARTITION BY nexprlist orderby_opt frame_opt", + /* 312 */ "window ::= nm PARTITION BY nexprlist orderby_opt frame_opt", + /* 313 */ "window ::= ORDER BY sortlist frame_opt", + /* 314 */ "window ::= nm ORDER BY sortlist frame_opt", + /* 315 */ "window ::= frame_opt", + /* 316 */ "window ::= nm frame_opt", + /* 317 */ "frame_opt ::=", + /* 318 */ "frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt", + /* 319 */ "frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt", + /* 320 */ "range_or_rows ::= RANGE|ROWS|GROUPS", + /* 321 */ "frame_bound_s ::= frame_bound", + /* 322 */ "frame_bound_s ::= UNBOUNDED PRECEDING", + /* 323 */ "frame_bound_e ::= frame_bound", + /* 324 */ "frame_bound_e ::= UNBOUNDED FOLLOWING", + /* 325 */ "frame_bound ::= expr PRECEDING|FOLLOWING", + /* 326 */ "frame_bound ::= CURRENT ROW", + /* 327 */ "frame_exclude_opt ::=", + /* 328 */ "frame_exclude_opt ::= EXCLUDE frame_exclude", + /* 329 */ "frame_exclude ::= NO OTHERS", + /* 330 */ "frame_exclude ::= CURRENT ROW", + /* 331 */ "frame_exclude ::= GROUP|TIES", + /* 332 */ "window_clause ::= WINDOW windowdefn_list", + /* 333 */ "filter_over ::= filter_clause over_clause", + /* 334 */ "filter_over ::= over_clause", + /* 335 */ "filter_over ::= filter_clause", + /* 336 */ "over_clause ::= OVER LP window RP", + /* 337 */ "over_clause ::= OVER nm", + /* 338 */ "filter_clause ::= FILTER LP WHERE expr RP", + /* 339 */ "input ::= cmdlist", + /* 340 */ "cmdlist ::= cmdlist ecmd", + /* 341 */ "cmdlist ::= ecmd", + /* 342 */ "ecmd ::= SEMI", + /* 343 */ "ecmd ::= cmdx SEMI", + /* 344 */ "ecmd ::= explain cmdx SEMI", + /* 345 */ "trans_opt ::=", + /* 346 */ "trans_opt ::= TRANSACTION", + /* 347 */ "trans_opt ::= TRANSACTION nm", + /* 348 */ "savepoint_opt ::= SAVEPOINT", + /* 349 */ "savepoint_opt ::=", + /* 350 */ "cmd ::= create_table create_table_args", + /* 351 */ "table_option_set ::= table_option", + /* 352 */ "columnlist ::= columnlist COMMA columnname carglist", + /* 353 */ "columnlist ::= columnname carglist", + /* 354 */ "nm ::= ID|INDEXED", + /* 355 */ "nm ::= STRING", + /* 356 */ "nm ::= JOIN_KW", + /* 357 */ "typetoken ::= typename", + /* 358 */ "typename ::= ID|STRING", + /* 359 */ "signed ::= plus_num", + /* 360 */ "signed ::= minus_num", + /* 361 */ "carglist ::= carglist ccons", + /* 362 */ "carglist ::=", + /* 363 */ "ccons ::= NULL onconf", + /* 364 */ "ccons ::= GENERATED ALWAYS AS generated", + /* 365 */ "ccons ::= AS generated", + /* 366 */ "conslist_opt ::= COMMA conslist", + /* 367 */ "conslist ::= conslist tconscomma tcons", + /* 368 */ "conslist ::= tcons", + /* 369 */ "tconscomma ::=", + /* 370 */ "defer_subclause_opt ::= defer_subclause", + /* 371 */ "resolvetype ::= raisetype", + /* 372 */ "selectnowith ::= oneselect", + /* 373 */ "oneselect ::= values", + /* 374 */ "sclp ::= selcollist COMMA", + /* 375 */ "as ::= ID|STRING", + /* 376 */ "returning ::=", + /* 377 */ "expr ::= term", + /* 378 */ "likeop ::= LIKE_KW|MATCH", + /* 379 */ "exprlist ::= nexprlist", + /* 380 */ "nmnum ::= plus_num", + /* 381 */ "nmnum ::= nm", + /* 382 */ "nmnum ::= ON", + /* 383 */ "nmnum ::= DELETE", + /* 384 */ "nmnum ::= DEFAULT", + /* 385 */ "plus_num ::= INTEGER|FLOAT", + /* 386 */ "foreach_clause ::=", + /* 387 */ "foreach_clause ::= FOR EACH ROW", + /* 388 */ "trnm ::= nm", + /* 389 */ "tridxby ::=", + /* 390 */ "database_kw_opt ::= DATABASE", + /* 391 */ "database_kw_opt ::=", + /* 392 */ "kwcolumn_opt ::=", + /* 393 */ "kwcolumn_opt ::= COLUMNKW", + /* 394 */ "vtabarglist ::= vtabarg", + /* 395 */ "vtabarglist ::= vtabarglist COMMA vtabarg", + /* 396 */ "vtabarg ::= vtabarg vtabargtoken", + /* 397 */ "anylist ::=", + /* 398 */ "anylist ::= anylist LP anylist RP", + /* 399 */ "anylist ::= anylist ANY", + /* 400 */ "with ::=", }; #endif /* NDEBUG */ #if YYSTACKDEPTH<=0 @@ -163739,103 +161008,103 @@ ** Note: during a reduce, the only symbols destroyed are those ** which appear on the RHS of the rule, but which are *not* used ** inside the C code. */ /********* Begin destructor definitions ***************************************/ - case 204: /* select */ - case 239: /* selectnowith */ - case 240: /* oneselect */ - case 252: /* values */ -{ -sqlite3SelectDelete(pParse->db, (yypminor->yy47)); -} - break; - case 216: /* term */ - case 217: /* expr */ - case 246: /* where_opt */ - case 248: /* having_opt */ - case 260: /* on_opt */ - case 267: /* where_opt_ret */ - case 278: /* case_operand */ - case 280: /* case_else */ - case 283: /* vinto */ - case 290: /* when_clause */ - case 295: /* key_opt */ - case 311: /* filter_clause */ -{ -sqlite3ExprDelete(pParse->db, (yypminor->yy528)); -} - break; - case 221: /* eidlist_opt */ - case 231: /* sortlist */ - case 232: /* eidlist */ - case 244: /* selcollist */ - case 247: /* groupby_opt */ - case 249: /* orderby_opt */ - case 253: /* nexprlist */ - case 254: /* sclp */ - case 262: /* exprlist */ - case 268: /* setlist */ - case 277: /* paren_exprlist */ - case 279: /* case_exprlist */ - case 310: /* part_opt */ -{ -sqlite3ExprListDelete(pParse->db, (yypminor->yy322)); -} - break; - case 238: /* fullname */ - case 245: /* from */ - case 256: /* seltablist */ - case 257: /* stl_prefix */ - case 263: /* xfullname */ -{ -sqlite3SrcListDelete(pParse->db, (yypminor->yy131)); -} - break; - case 241: /* wqlist */ -{ -sqlite3WithDelete(pParse->db, (yypminor->yy521)); -} - break; - case 251: /* window_clause */ - case 306: /* windowdefn_list */ -{ -sqlite3WindowListDelete(pParse->db, (yypminor->yy41)); -} - break; - case 261: /* using_opt */ - case 264: /* idlist */ - case 270: /* idlist_opt */ -{ -sqlite3IdListDelete(pParse->db, (yypminor->yy254)); -} - break; - case 273: /* filter_over */ - case 307: /* windowdefn */ - case 308: /* window */ - case 309: /* frame_opt */ - case 312: /* over_clause */ -{ -sqlite3WindowDelete(pParse->db, (yypminor->yy41)); -} - break; - case 286: /* trigger_cmd_list */ - case 291: /* trigger_cmd */ -{ -sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy33)); -} - break; - case 288: /* trigger_event */ -{ -sqlite3IdListDelete(pParse->db, (yypminor->yy180).b); -} - break; - case 314: /* frame_bound */ - case 315: /* frame_bound_s */ - case 316: /* frame_bound_e */ -{ -sqlite3ExprDelete(pParse->db, (yypminor->yy595).pExpr); + case 203: /* select */ + case 238: /* selectnowith */ + case 239: /* oneselect */ + case 251: /* values */ +{ +sqlite3SelectDelete(pParse->db, (yypminor->yy303)); +} + break; + case 215: /* term */ + case 216: /* expr */ + case 245: /* where_opt */ + case 247: /* having_opt */ + case 259: /* on_opt */ + case 266: /* where_opt_ret */ + case 277: /* case_operand */ + case 279: /* case_else */ + case 282: /* vinto */ + case 289: /* when_clause */ + case 294: /* key_opt */ + case 310: /* filter_clause */ +{ +sqlite3ExprDelete(pParse->db, (yypminor->yy626)); +} + break; + case 220: /* eidlist_opt */ + case 230: /* sortlist */ + case 231: /* eidlist */ + case 243: /* selcollist */ + case 246: /* groupby_opt */ + case 248: /* orderby_opt */ + case 252: /* nexprlist */ + case 253: /* sclp */ + case 261: /* exprlist */ + case 267: /* setlist */ + case 276: /* paren_exprlist */ + case 278: /* case_exprlist */ + case 309: /* part_opt */ +{ +sqlite3ExprListDelete(pParse->db, (yypminor->yy562)); +} + break; + case 237: /* fullname */ + case 244: /* from */ + case 255: /* seltablist */ + case 256: /* stl_prefix */ + case 262: /* xfullname */ +{ +sqlite3SrcListDelete(pParse->db, (yypminor->yy607)); +} + break; + case 240: /* wqlist */ +{ +sqlite3WithDelete(pParse->db, (yypminor->yy43)); +} + break; + case 250: /* window_clause */ + case 305: /* windowdefn_list */ +{ +sqlite3WindowListDelete(pParse->db, (yypminor->yy375)); +} + break; + case 260: /* using_opt */ + case 263: /* idlist */ + case 269: /* idlist_opt */ +{ +sqlite3IdListDelete(pParse->db, (yypminor->yy240)); +} + break; + case 272: /* filter_over */ + case 306: /* windowdefn */ + case 307: /* window */ + case 308: /* frame_opt */ + case 311: /* over_clause */ +{ +sqlite3WindowDelete(pParse->db, (yypminor->yy375)); +} + break; + case 285: /* trigger_cmd_list */ + case 290: /* trigger_cmd */ +{ +sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy95)); +} + break; + case 287: /* trigger_event */ +{ +sqlite3IdListDelete(pParse->db, (yypminor->yy570).b); +} + break; + case 313: /* frame_bound */ + case 314: /* frame_bound_s */ + case 315: /* frame_bound_e */ +{ +sqlite3ExprDelete(pParse->db, (yypminor->yy81).pExpr); } break; /********* End destructor definitions *****************************************/ default: break; /* If no destructor action specified: do nothing */ } @@ -164122,412 +161391,411 @@ } /* For rule J, yyRuleInfoLhs[J] contains the symbol on the left-hand side ** of that rule */ static const YYCODETYPE yyRuleInfoLhs[] = { - 189, /* (0) explain ::= EXPLAIN */ - 189, /* (1) explain ::= EXPLAIN QUERY PLAN */ - 188, /* (2) cmdx ::= cmd */ - 190, /* (3) cmd ::= BEGIN transtype trans_opt */ - 191, /* (4) transtype ::= */ - 191, /* (5) transtype ::= DEFERRED */ - 191, /* (6) transtype ::= IMMEDIATE */ - 191, /* (7) transtype ::= EXCLUSIVE */ - 190, /* (8) cmd ::= COMMIT|END trans_opt */ - 190, /* (9) cmd ::= ROLLBACK trans_opt */ - 190, /* (10) cmd ::= SAVEPOINT nm */ - 190, /* (11) cmd ::= RELEASE savepoint_opt nm */ - 190, /* (12) cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */ - 195, /* (13) create_table ::= createkw temp TABLE ifnotexists nm dbnm */ - 197, /* (14) createkw ::= CREATE */ - 199, /* (15) ifnotexists ::= */ - 199, /* (16) ifnotexists ::= IF NOT EXISTS */ - 198, /* (17) temp ::= TEMP */ - 198, /* (18) temp ::= */ - 196, /* (19) create_table_args ::= LP columnlist conslist_opt RP table_option_set */ - 196, /* (20) create_table_args ::= AS select */ - 203, /* (21) table_option_set ::= */ - 203, /* (22) table_option_set ::= table_option_set COMMA table_option */ - 205, /* (23) table_option ::= WITHOUT nm */ - 205, /* (24) table_option ::= nm */ - 206, /* (25) columnname ::= nm typetoken */ - 208, /* (26) typetoken ::= */ - 208, /* (27) typetoken ::= typename LP signed RP */ - 208, /* (28) typetoken ::= typename LP signed COMMA signed RP */ - 209, /* (29) typename ::= typename ID|STRING */ - 213, /* (30) scanpt ::= */ - 214, /* (31) scantok ::= */ - 215, /* (32) ccons ::= CONSTRAINT nm */ - 215, /* (33) ccons ::= DEFAULT scantok term */ - 215, /* (34) ccons ::= DEFAULT LP expr RP */ - 215, /* (35) ccons ::= DEFAULT PLUS scantok term */ - 215, /* (36) ccons ::= DEFAULT MINUS scantok term */ - 215, /* (37) ccons ::= DEFAULT scantok ID|INDEXED */ - 215, /* (38) ccons ::= NOT NULL onconf */ - 215, /* (39) ccons ::= PRIMARY KEY sortorder onconf autoinc */ - 215, /* (40) ccons ::= UNIQUE onconf */ - 215, /* (41) ccons ::= CHECK LP expr RP */ - 215, /* (42) ccons ::= REFERENCES nm eidlist_opt refargs */ - 215, /* (43) ccons ::= defer_subclause */ - 215, /* (44) ccons ::= COLLATE ID|STRING */ - 224, /* (45) generated ::= LP expr RP */ - 224, /* (46) generated ::= LP expr RP ID */ - 220, /* (47) autoinc ::= */ - 220, /* (48) autoinc ::= AUTOINCR */ - 222, /* (49) refargs ::= */ - 222, /* (50) refargs ::= refargs refarg */ - 225, /* (51) refarg ::= MATCH nm */ - 225, /* (52) refarg ::= ON INSERT refact */ - 225, /* (53) refarg ::= ON DELETE refact */ - 225, /* (54) refarg ::= ON UPDATE refact */ - 226, /* (55) refact ::= SET NULL */ - 226, /* (56) refact ::= SET DEFAULT */ - 226, /* (57) refact ::= CASCADE */ - 226, /* (58) refact ::= RESTRICT */ - 226, /* (59) refact ::= NO ACTION */ - 223, /* (60) defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ - 223, /* (61) defer_subclause ::= DEFERRABLE init_deferred_pred_opt */ - 227, /* (62) init_deferred_pred_opt ::= */ - 227, /* (63) init_deferred_pred_opt ::= INITIALLY DEFERRED */ - 227, /* (64) init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ - 202, /* (65) conslist_opt ::= */ - 229, /* (66) tconscomma ::= COMMA */ - 230, /* (67) tcons ::= CONSTRAINT nm */ - 230, /* (68) tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */ - 230, /* (69) tcons ::= UNIQUE LP sortlist RP onconf */ - 230, /* (70) tcons ::= CHECK LP expr RP onconf */ - 230, /* (71) tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */ - 233, /* (72) defer_subclause_opt ::= */ - 218, /* (73) onconf ::= */ - 218, /* (74) onconf ::= ON CONFLICT resolvetype */ - 234, /* (75) orconf ::= */ - 234, /* (76) orconf ::= OR resolvetype */ - 235, /* (77) resolvetype ::= IGNORE */ - 235, /* (78) resolvetype ::= REPLACE */ - 190, /* (79) cmd ::= DROP TABLE ifexists fullname */ - 237, /* (80) ifexists ::= IF EXISTS */ - 237, /* (81) ifexists ::= */ - 190, /* (82) cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */ - 190, /* (83) cmd ::= DROP VIEW ifexists fullname */ - 190, /* (84) cmd ::= select */ - 204, /* (85) select ::= WITH wqlist selectnowith */ - 204, /* (86) select ::= WITH RECURSIVE wqlist selectnowith */ - 204, /* (87) select ::= selectnowith */ - 239, /* (88) selectnowith ::= selectnowith multiselect_op oneselect */ - 242, /* (89) multiselect_op ::= UNION */ - 242, /* (90) multiselect_op ::= UNION ALL */ - 242, /* (91) multiselect_op ::= EXCEPT|INTERSECT */ - 240, /* (92) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */ - 240, /* (93) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt window_clause orderby_opt limit_opt */ - 252, /* (94) values ::= VALUES LP nexprlist RP */ - 252, /* (95) values ::= values COMMA LP nexprlist RP */ - 243, /* (96) distinct ::= DISTINCT */ - 243, /* (97) distinct ::= ALL */ - 243, /* (98) distinct ::= */ - 254, /* (99) sclp ::= */ - 244, /* (100) selcollist ::= sclp scanpt expr scanpt as */ - 244, /* (101) selcollist ::= sclp scanpt STAR */ - 244, /* (102) selcollist ::= sclp scanpt nm DOT STAR */ - 255, /* (103) as ::= AS nm */ - 255, /* (104) as ::= */ - 245, /* (105) from ::= */ - 245, /* (106) from ::= FROM seltablist */ - 257, /* (107) stl_prefix ::= seltablist joinop */ - 257, /* (108) stl_prefix ::= */ - 256, /* (109) seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */ - 256, /* (110) seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */ - 256, /* (111) seltablist ::= stl_prefix LP select RP as on_opt using_opt */ - 256, /* (112) seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */ - 200, /* (113) dbnm ::= */ - 200, /* (114) dbnm ::= DOT nm */ - 238, /* (115) fullname ::= nm */ - 238, /* (116) fullname ::= nm DOT nm */ - 263, /* (117) xfullname ::= nm */ - 263, /* (118) xfullname ::= nm DOT nm */ - 263, /* (119) xfullname ::= nm DOT nm AS nm */ - 263, /* (120) xfullname ::= nm AS nm */ - 258, /* (121) joinop ::= COMMA|JOIN */ - 258, /* (122) joinop ::= JOIN_KW JOIN */ - 258, /* (123) joinop ::= JOIN_KW nm JOIN */ - 258, /* (124) joinop ::= JOIN_KW nm nm JOIN */ - 260, /* (125) on_opt ::= ON expr */ - 260, /* (126) on_opt ::= */ - 259, /* (127) indexed_opt ::= */ - 259, /* (128) indexed_opt ::= INDEXED BY nm */ - 259, /* (129) indexed_opt ::= NOT INDEXED */ - 261, /* (130) using_opt ::= USING LP idlist RP */ - 261, /* (131) using_opt ::= */ - 249, /* (132) orderby_opt ::= */ - 249, /* (133) orderby_opt ::= ORDER BY sortlist */ - 231, /* (134) sortlist ::= sortlist COMMA expr sortorder nulls */ - 231, /* (135) sortlist ::= expr sortorder nulls */ - 219, /* (136) sortorder ::= ASC */ - 219, /* (137) sortorder ::= DESC */ - 219, /* (138) sortorder ::= */ - 265, /* (139) nulls ::= NULLS FIRST */ - 265, /* (140) nulls ::= NULLS LAST */ - 265, /* (141) nulls ::= */ - 247, /* (142) groupby_opt ::= */ - 247, /* (143) groupby_opt ::= GROUP BY nexprlist */ - 248, /* (144) having_opt ::= */ - 248, /* (145) having_opt ::= HAVING expr */ - 250, /* (146) limit_opt ::= */ - 250, /* (147) limit_opt ::= LIMIT expr */ - 250, /* (148) limit_opt ::= LIMIT expr OFFSET expr */ - 250, /* (149) limit_opt ::= LIMIT expr COMMA expr */ - 190, /* (150) cmd ::= with DELETE FROM xfullname indexed_opt where_opt_ret */ - 246, /* (151) where_opt ::= */ - 246, /* (152) where_opt ::= WHERE expr */ - 267, /* (153) where_opt_ret ::= */ - 267, /* (154) where_opt_ret ::= WHERE expr */ - 267, /* (155) where_opt_ret ::= RETURNING selcollist */ - 267, /* (156) where_opt_ret ::= WHERE expr RETURNING selcollist */ - 190, /* (157) cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist from where_opt_ret */ - 268, /* (158) setlist ::= setlist COMMA nm EQ expr */ - 268, /* (159) setlist ::= setlist COMMA LP idlist RP EQ expr */ - 268, /* (160) setlist ::= nm EQ expr */ - 268, /* (161) setlist ::= LP idlist RP EQ expr */ - 190, /* (162) cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */ - 190, /* (163) cmd ::= with insert_cmd INTO xfullname idlist_opt DEFAULT VALUES returning */ - 271, /* (164) upsert ::= */ - 271, /* (165) upsert ::= RETURNING selcollist */ - 271, /* (166) upsert ::= ON CONFLICT LP sortlist RP where_opt DO UPDATE SET setlist where_opt upsert */ - 271, /* (167) upsert ::= ON CONFLICT LP sortlist RP where_opt DO NOTHING upsert */ - 271, /* (168) upsert ::= ON CONFLICT DO NOTHING returning */ - 271, /* (169) upsert ::= ON CONFLICT DO UPDATE SET setlist where_opt returning */ - 272, /* (170) returning ::= RETURNING selcollist */ - 269, /* (171) insert_cmd ::= INSERT orconf */ - 269, /* (172) insert_cmd ::= REPLACE */ - 270, /* (173) idlist_opt ::= */ - 270, /* (174) idlist_opt ::= LP idlist RP */ - 264, /* (175) idlist ::= idlist COMMA nm */ - 264, /* (176) idlist ::= nm */ - 217, /* (177) expr ::= LP expr RP */ - 217, /* (178) expr ::= ID|INDEXED */ - 217, /* (179) expr ::= JOIN_KW */ - 217, /* (180) expr ::= nm DOT nm */ - 217, /* (181) expr ::= nm DOT nm DOT nm */ - 216, /* (182) term ::= NULL|FLOAT|BLOB */ - 216, /* (183) term ::= STRING */ - 216, /* (184) term ::= INTEGER */ - 217, /* (185) expr ::= VARIABLE */ - 217, /* (186) expr ::= expr COLLATE ID|STRING */ - 217, /* (187) expr ::= CAST LP expr AS typetoken RP */ - 217, /* (188) expr ::= ID|INDEXED LP distinct exprlist RP */ - 217, /* (189) expr ::= ID|INDEXED LP STAR RP */ - 217, /* (190) expr ::= ID|INDEXED LP distinct exprlist RP filter_over */ - 217, /* (191) expr ::= ID|INDEXED LP STAR RP filter_over */ - 216, /* (192) term ::= CTIME_KW */ - 217, /* (193) expr ::= LP nexprlist COMMA expr RP */ - 217, /* (194) expr ::= expr AND expr */ - 217, /* (195) expr ::= expr OR expr */ - 217, /* (196) expr ::= expr LT|GT|GE|LE expr */ - 217, /* (197) expr ::= expr EQ|NE expr */ - 217, /* (198) expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ - 217, /* (199) expr ::= expr PLUS|MINUS expr */ - 217, /* (200) expr ::= expr STAR|SLASH|REM expr */ - 217, /* (201) expr ::= expr CONCAT expr */ - 274, /* (202) likeop ::= NOT LIKE_KW|MATCH */ - 217, /* (203) expr ::= expr likeop expr */ - 217, /* (204) expr ::= expr likeop expr ESCAPE expr */ - 217, /* (205) expr ::= expr ISNULL|NOTNULL */ - 217, /* (206) expr ::= expr NOT NULL */ - 217, /* (207) expr ::= expr IS expr */ - 217, /* (208) expr ::= expr IS NOT expr */ - 217, /* (209) expr ::= NOT expr */ - 217, /* (210) expr ::= BITNOT expr */ - 217, /* (211) expr ::= PLUS|MINUS expr */ - 217, /* (212) expr ::= expr PTR expr */ - 275, /* (213) between_op ::= BETWEEN */ - 275, /* (214) between_op ::= NOT BETWEEN */ - 217, /* (215) expr ::= expr between_op expr AND expr */ - 276, /* (216) in_op ::= IN */ - 276, /* (217) in_op ::= NOT IN */ - 217, /* (218) expr ::= expr in_op LP exprlist RP */ - 217, /* (219) expr ::= LP select RP */ - 217, /* (220) expr ::= expr in_op LP select RP */ - 217, /* (221) expr ::= expr in_op nm dbnm paren_exprlist */ - 217, /* (222) expr ::= EXISTS LP select RP */ - 217, /* (223) expr ::= CASE case_operand case_exprlist case_else END */ - 279, /* (224) case_exprlist ::= case_exprlist WHEN expr THEN expr */ - 279, /* (225) case_exprlist ::= WHEN expr THEN expr */ - 280, /* (226) case_else ::= ELSE expr */ - 280, /* (227) case_else ::= */ - 278, /* (228) case_operand ::= expr */ - 278, /* (229) case_operand ::= */ - 262, /* (230) exprlist ::= */ - 253, /* (231) nexprlist ::= nexprlist COMMA expr */ - 253, /* (232) nexprlist ::= expr */ - 277, /* (233) paren_exprlist ::= */ - 277, /* (234) paren_exprlist ::= LP exprlist RP */ - 190, /* (235) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */ - 281, /* (236) uniqueflag ::= UNIQUE */ - 281, /* (237) uniqueflag ::= */ - 221, /* (238) eidlist_opt ::= */ - 221, /* (239) eidlist_opt ::= LP eidlist RP */ - 232, /* (240) eidlist ::= eidlist COMMA nm collate sortorder */ - 232, /* (241) eidlist ::= nm collate sortorder */ - 282, /* (242) collate ::= */ - 282, /* (243) collate ::= COLLATE ID|STRING */ - 190, /* (244) cmd ::= DROP INDEX ifexists fullname */ - 190, /* (245) cmd ::= VACUUM vinto */ - 190, /* (246) cmd ::= VACUUM nm vinto */ - 283, /* (247) vinto ::= INTO expr */ - 283, /* (248) vinto ::= */ - 190, /* (249) cmd ::= PRAGMA nm dbnm */ - 190, /* (250) cmd ::= PRAGMA nm dbnm EQ nmnum */ - 190, /* (251) cmd ::= PRAGMA nm dbnm LP nmnum RP */ - 190, /* (252) cmd ::= PRAGMA nm dbnm EQ minus_num */ - 190, /* (253) cmd ::= PRAGMA nm dbnm LP minus_num RP */ - 211, /* (254) plus_num ::= PLUS INTEGER|FLOAT */ - 212, /* (255) minus_num ::= MINUS INTEGER|FLOAT */ - 190, /* (256) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */ - 285, /* (257) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */ - 287, /* (258) trigger_time ::= BEFORE|AFTER */ - 287, /* (259) trigger_time ::= INSTEAD OF */ - 287, /* (260) trigger_time ::= */ - 288, /* (261) trigger_event ::= DELETE|INSERT */ - 288, /* (262) trigger_event ::= UPDATE */ - 288, /* (263) trigger_event ::= UPDATE OF idlist */ - 290, /* (264) when_clause ::= */ - 290, /* (265) when_clause ::= WHEN expr */ - 286, /* (266) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */ - 286, /* (267) trigger_cmd_list ::= trigger_cmd SEMI */ - 292, /* (268) trnm ::= nm DOT nm */ - 293, /* (269) tridxby ::= INDEXED BY nm */ - 293, /* (270) tridxby ::= NOT INDEXED */ - 291, /* (271) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */ - 291, /* (272) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */ - 291, /* (273) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */ - 291, /* (274) trigger_cmd ::= scanpt select scanpt */ - 217, /* (275) expr ::= RAISE LP IGNORE RP */ - 217, /* (276) expr ::= RAISE LP raisetype COMMA nm RP */ - 236, /* (277) raisetype ::= ROLLBACK */ - 236, /* (278) raisetype ::= ABORT */ - 236, /* (279) raisetype ::= FAIL */ - 190, /* (280) cmd ::= DROP TRIGGER ifexists fullname */ - 190, /* (281) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */ - 190, /* (282) cmd ::= DETACH database_kw_opt expr */ - 295, /* (283) key_opt ::= */ - 295, /* (284) key_opt ::= KEY expr */ - 190, /* (285) cmd ::= REINDEX */ - 190, /* (286) cmd ::= REINDEX nm dbnm */ - 190, /* (287) cmd ::= ANALYZE */ - 190, /* (288) cmd ::= ANALYZE nm dbnm */ - 190, /* (289) cmd ::= ALTER TABLE fullname RENAME TO nm */ - 190, /* (290) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */ - 190, /* (291) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */ - 296, /* (292) add_column_fullname ::= fullname */ - 190, /* (293) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */ - 190, /* (294) cmd ::= create_vtab */ - 190, /* (295) cmd ::= create_vtab LP vtabarglist RP */ - 298, /* (296) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */ - 300, /* (297) vtabarg ::= */ - 301, /* (298) vtabargtoken ::= ANY */ - 301, /* (299) vtabargtoken ::= lp anylist RP */ - 302, /* (300) lp ::= LP */ - 266, /* (301) with ::= WITH wqlist */ - 266, /* (302) with ::= WITH RECURSIVE wqlist */ - 305, /* (303) wqas ::= AS */ - 305, /* (304) wqas ::= AS MATERIALIZED */ - 305, /* (305) wqas ::= AS NOT MATERIALIZED */ - 304, /* (306) wqitem ::= nm eidlist_opt wqas LP select RP */ - 241, /* (307) wqlist ::= wqitem */ - 241, /* (308) wqlist ::= wqlist COMMA wqitem */ - 306, /* (309) windowdefn_list ::= windowdefn */ - 306, /* (310) windowdefn_list ::= windowdefn_list COMMA windowdefn */ - 307, /* (311) windowdefn ::= nm AS LP window RP */ - 308, /* (312) window ::= PARTITION BY nexprlist orderby_opt frame_opt */ - 308, /* (313) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */ - 308, /* (314) window ::= ORDER BY sortlist frame_opt */ - 308, /* (315) window ::= nm ORDER BY sortlist frame_opt */ - 308, /* (316) window ::= frame_opt */ - 308, /* (317) window ::= nm frame_opt */ - 309, /* (318) frame_opt ::= */ - 309, /* (319) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */ - 309, /* (320) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */ - 313, /* (321) range_or_rows ::= RANGE|ROWS|GROUPS */ - 315, /* (322) frame_bound_s ::= frame_bound */ - 315, /* (323) frame_bound_s ::= UNBOUNDED PRECEDING */ - 316, /* (324) frame_bound_e ::= frame_bound */ - 316, /* (325) frame_bound_e ::= UNBOUNDED FOLLOWING */ - 314, /* (326) frame_bound ::= expr PRECEDING|FOLLOWING */ - 314, /* (327) frame_bound ::= CURRENT ROW */ - 317, /* (328) frame_exclude_opt ::= */ - 317, /* (329) frame_exclude_opt ::= EXCLUDE frame_exclude */ - 318, /* (330) frame_exclude ::= NO OTHERS */ - 318, /* (331) frame_exclude ::= CURRENT ROW */ - 318, /* (332) frame_exclude ::= GROUP|TIES */ - 251, /* (333) window_clause ::= WINDOW windowdefn_list */ - 273, /* (334) filter_over ::= filter_clause over_clause */ - 273, /* (335) filter_over ::= over_clause */ - 273, /* (336) filter_over ::= filter_clause */ - 312, /* (337) over_clause ::= OVER LP window RP */ - 312, /* (338) over_clause ::= OVER nm */ - 311, /* (339) filter_clause ::= FILTER LP WHERE expr RP */ - 185, /* (340) input ::= cmdlist */ - 186, /* (341) cmdlist ::= cmdlist ecmd */ - 186, /* (342) cmdlist ::= ecmd */ - 187, /* (343) ecmd ::= SEMI */ - 187, /* (344) ecmd ::= cmdx SEMI */ - 187, /* (345) ecmd ::= explain cmdx SEMI */ - 192, /* (346) trans_opt ::= */ - 192, /* (347) trans_opt ::= TRANSACTION */ - 192, /* (348) trans_opt ::= TRANSACTION nm */ - 194, /* (349) savepoint_opt ::= SAVEPOINT */ - 194, /* (350) savepoint_opt ::= */ - 190, /* (351) cmd ::= create_table create_table_args */ - 203, /* (352) table_option_set ::= table_option */ - 201, /* (353) columnlist ::= columnlist COMMA columnname carglist */ - 201, /* (354) columnlist ::= columnname carglist */ - 193, /* (355) nm ::= ID|INDEXED */ - 193, /* (356) nm ::= STRING */ - 193, /* (357) nm ::= JOIN_KW */ - 208, /* (358) typetoken ::= typename */ - 209, /* (359) typename ::= ID|STRING */ - 210, /* (360) signed ::= plus_num */ - 210, /* (361) signed ::= minus_num */ - 207, /* (362) carglist ::= carglist ccons */ - 207, /* (363) carglist ::= */ - 215, /* (364) ccons ::= NULL onconf */ - 215, /* (365) ccons ::= GENERATED ALWAYS AS generated */ - 215, /* (366) ccons ::= AS generated */ - 202, /* (367) conslist_opt ::= COMMA conslist */ - 228, /* (368) conslist ::= conslist tconscomma tcons */ - 228, /* (369) conslist ::= tcons */ - 229, /* (370) tconscomma ::= */ - 233, /* (371) defer_subclause_opt ::= defer_subclause */ - 235, /* (372) resolvetype ::= raisetype */ - 239, /* (373) selectnowith ::= oneselect */ - 240, /* (374) oneselect ::= values */ - 254, /* (375) sclp ::= selcollist COMMA */ - 255, /* (376) as ::= ID|STRING */ - 272, /* (377) returning ::= */ - 217, /* (378) expr ::= term */ - 274, /* (379) likeop ::= LIKE_KW|MATCH */ - 262, /* (380) exprlist ::= nexprlist */ - 284, /* (381) nmnum ::= plus_num */ - 284, /* (382) nmnum ::= nm */ - 284, /* (383) nmnum ::= ON */ - 284, /* (384) nmnum ::= DELETE */ - 284, /* (385) nmnum ::= DEFAULT */ - 211, /* (386) plus_num ::= INTEGER|FLOAT */ - 289, /* (387) foreach_clause ::= */ - 289, /* (388) foreach_clause ::= FOR EACH ROW */ - 292, /* (389) trnm ::= nm */ - 293, /* (390) tridxby ::= */ - 294, /* (391) database_kw_opt ::= DATABASE */ - 294, /* (392) database_kw_opt ::= */ - 297, /* (393) kwcolumn_opt ::= */ - 297, /* (394) kwcolumn_opt ::= COLUMNKW */ - 299, /* (395) vtabarglist ::= vtabarg */ - 299, /* (396) vtabarglist ::= vtabarglist COMMA vtabarg */ - 300, /* (397) vtabarg ::= vtabarg vtabargtoken */ - 303, /* (398) anylist ::= */ - 303, /* (399) anylist ::= anylist LP anylist RP */ - 303, /* (400) anylist ::= anylist ANY */ - 266, /* (401) with ::= */ + 188, /* (0) explain ::= EXPLAIN */ + 188, /* (1) explain ::= EXPLAIN QUERY PLAN */ + 187, /* (2) cmdx ::= cmd */ + 189, /* (3) cmd ::= BEGIN transtype trans_opt */ + 190, /* (4) transtype ::= */ + 190, /* (5) transtype ::= DEFERRED */ + 190, /* (6) transtype ::= IMMEDIATE */ + 190, /* (7) transtype ::= EXCLUSIVE */ + 189, /* (8) cmd ::= COMMIT|END trans_opt */ + 189, /* (9) cmd ::= ROLLBACK trans_opt */ + 189, /* (10) cmd ::= SAVEPOINT nm */ + 189, /* (11) cmd ::= RELEASE savepoint_opt nm */ + 189, /* (12) cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */ + 194, /* (13) create_table ::= createkw temp TABLE ifnotexists nm dbnm */ + 196, /* (14) createkw ::= CREATE */ + 198, /* (15) ifnotexists ::= */ + 198, /* (16) ifnotexists ::= IF NOT EXISTS */ + 197, /* (17) temp ::= TEMP */ + 197, /* (18) temp ::= */ + 195, /* (19) create_table_args ::= LP columnlist conslist_opt RP table_option_set */ + 195, /* (20) create_table_args ::= AS select */ + 202, /* (21) table_option_set ::= */ + 202, /* (22) table_option_set ::= table_option_set COMMA table_option */ + 204, /* (23) table_option ::= WITHOUT nm */ + 204, /* (24) table_option ::= nm */ + 205, /* (25) columnname ::= nm typetoken */ + 207, /* (26) typetoken ::= */ + 207, /* (27) typetoken ::= typename LP signed RP */ + 207, /* (28) typetoken ::= typename LP signed COMMA signed RP */ + 208, /* (29) typename ::= typename ID|STRING */ + 212, /* (30) scanpt ::= */ + 213, /* (31) scantok ::= */ + 214, /* (32) ccons ::= CONSTRAINT nm */ + 214, /* (33) ccons ::= DEFAULT scantok term */ + 214, /* (34) ccons ::= DEFAULT LP expr RP */ + 214, /* (35) ccons ::= DEFAULT PLUS scantok term */ + 214, /* (36) ccons ::= DEFAULT MINUS scantok term */ + 214, /* (37) ccons ::= DEFAULT scantok ID|INDEXED */ + 214, /* (38) ccons ::= NOT NULL onconf */ + 214, /* (39) ccons ::= PRIMARY KEY sortorder onconf autoinc */ + 214, /* (40) ccons ::= UNIQUE onconf */ + 214, /* (41) ccons ::= CHECK LP expr RP */ + 214, /* (42) ccons ::= REFERENCES nm eidlist_opt refargs */ + 214, /* (43) ccons ::= defer_subclause */ + 214, /* (44) ccons ::= COLLATE ID|STRING */ + 223, /* (45) generated ::= LP expr RP */ + 223, /* (46) generated ::= LP expr RP ID */ + 219, /* (47) autoinc ::= */ + 219, /* (48) autoinc ::= AUTOINCR */ + 221, /* (49) refargs ::= */ + 221, /* (50) refargs ::= refargs refarg */ + 224, /* (51) refarg ::= MATCH nm */ + 224, /* (52) refarg ::= ON INSERT refact */ + 224, /* (53) refarg ::= ON DELETE refact */ + 224, /* (54) refarg ::= ON UPDATE refact */ + 225, /* (55) refact ::= SET NULL */ + 225, /* (56) refact ::= SET DEFAULT */ + 225, /* (57) refact ::= CASCADE */ + 225, /* (58) refact ::= RESTRICT */ + 225, /* (59) refact ::= NO ACTION */ + 222, /* (60) defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ + 222, /* (61) defer_subclause ::= DEFERRABLE init_deferred_pred_opt */ + 226, /* (62) init_deferred_pred_opt ::= */ + 226, /* (63) init_deferred_pred_opt ::= INITIALLY DEFERRED */ + 226, /* (64) init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ + 201, /* (65) conslist_opt ::= */ + 228, /* (66) tconscomma ::= COMMA */ + 229, /* (67) tcons ::= CONSTRAINT nm */ + 229, /* (68) tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */ + 229, /* (69) tcons ::= UNIQUE LP sortlist RP onconf */ + 229, /* (70) tcons ::= CHECK LP expr RP onconf */ + 229, /* (71) tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */ + 232, /* (72) defer_subclause_opt ::= */ + 217, /* (73) onconf ::= */ + 217, /* (74) onconf ::= ON CONFLICT resolvetype */ + 233, /* (75) orconf ::= */ + 233, /* (76) orconf ::= OR resolvetype */ + 234, /* (77) resolvetype ::= IGNORE */ + 234, /* (78) resolvetype ::= REPLACE */ + 189, /* (79) cmd ::= DROP TABLE ifexists fullname */ + 236, /* (80) ifexists ::= IF EXISTS */ + 236, /* (81) ifexists ::= */ + 189, /* (82) cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */ + 189, /* (83) cmd ::= DROP VIEW ifexists fullname */ + 189, /* (84) cmd ::= select */ + 203, /* (85) select ::= WITH wqlist selectnowith */ + 203, /* (86) select ::= WITH RECURSIVE wqlist selectnowith */ + 203, /* (87) select ::= selectnowith */ + 238, /* (88) selectnowith ::= selectnowith multiselect_op oneselect */ + 241, /* (89) multiselect_op ::= UNION */ + 241, /* (90) multiselect_op ::= UNION ALL */ + 241, /* (91) multiselect_op ::= EXCEPT|INTERSECT */ + 239, /* (92) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */ + 239, /* (93) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt window_clause orderby_opt limit_opt */ + 251, /* (94) values ::= VALUES LP nexprlist RP */ + 251, /* (95) values ::= values COMMA LP nexprlist RP */ + 242, /* (96) distinct ::= DISTINCT */ + 242, /* (97) distinct ::= ALL */ + 242, /* (98) distinct ::= */ + 253, /* (99) sclp ::= */ + 243, /* (100) selcollist ::= sclp scanpt expr scanpt as */ + 243, /* (101) selcollist ::= sclp scanpt STAR */ + 243, /* (102) selcollist ::= sclp scanpt nm DOT STAR */ + 254, /* (103) as ::= AS nm */ + 254, /* (104) as ::= */ + 244, /* (105) from ::= */ + 244, /* (106) from ::= FROM seltablist */ + 256, /* (107) stl_prefix ::= seltablist joinop */ + 256, /* (108) stl_prefix ::= */ + 255, /* (109) seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */ + 255, /* (110) seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */ + 255, /* (111) seltablist ::= stl_prefix LP select RP as on_opt using_opt */ + 255, /* (112) seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */ + 199, /* (113) dbnm ::= */ + 199, /* (114) dbnm ::= DOT nm */ + 237, /* (115) fullname ::= nm */ + 237, /* (116) fullname ::= nm DOT nm */ + 262, /* (117) xfullname ::= nm */ + 262, /* (118) xfullname ::= nm DOT nm */ + 262, /* (119) xfullname ::= nm DOT nm AS nm */ + 262, /* (120) xfullname ::= nm AS nm */ + 257, /* (121) joinop ::= COMMA|JOIN */ + 257, /* (122) joinop ::= JOIN_KW JOIN */ + 257, /* (123) joinop ::= JOIN_KW nm JOIN */ + 257, /* (124) joinop ::= JOIN_KW nm nm JOIN */ + 259, /* (125) on_opt ::= ON expr */ + 259, /* (126) on_opt ::= */ + 258, /* (127) indexed_opt ::= */ + 258, /* (128) indexed_opt ::= INDEXED BY nm */ + 258, /* (129) indexed_opt ::= NOT INDEXED */ + 260, /* (130) using_opt ::= USING LP idlist RP */ + 260, /* (131) using_opt ::= */ + 248, /* (132) orderby_opt ::= */ + 248, /* (133) orderby_opt ::= ORDER BY sortlist */ + 230, /* (134) sortlist ::= sortlist COMMA expr sortorder nulls */ + 230, /* (135) sortlist ::= expr sortorder nulls */ + 218, /* (136) sortorder ::= ASC */ + 218, /* (137) sortorder ::= DESC */ + 218, /* (138) sortorder ::= */ + 264, /* (139) nulls ::= NULLS FIRST */ + 264, /* (140) nulls ::= NULLS LAST */ + 264, /* (141) nulls ::= */ + 246, /* (142) groupby_opt ::= */ + 246, /* (143) groupby_opt ::= GROUP BY nexprlist */ + 247, /* (144) having_opt ::= */ + 247, /* (145) having_opt ::= HAVING expr */ + 249, /* (146) limit_opt ::= */ + 249, /* (147) limit_opt ::= LIMIT expr */ + 249, /* (148) limit_opt ::= LIMIT expr OFFSET expr */ + 249, /* (149) limit_opt ::= LIMIT expr COMMA expr */ + 189, /* (150) cmd ::= with DELETE FROM xfullname indexed_opt where_opt_ret */ + 245, /* (151) where_opt ::= */ + 245, /* (152) where_opt ::= WHERE expr */ + 266, /* (153) where_opt_ret ::= */ + 266, /* (154) where_opt_ret ::= WHERE expr */ + 266, /* (155) where_opt_ret ::= RETURNING selcollist */ + 266, /* (156) where_opt_ret ::= WHERE expr RETURNING selcollist */ + 189, /* (157) cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist from where_opt_ret */ + 267, /* (158) setlist ::= setlist COMMA nm EQ expr */ + 267, /* (159) setlist ::= setlist COMMA LP idlist RP EQ expr */ + 267, /* (160) setlist ::= nm EQ expr */ + 267, /* (161) setlist ::= LP idlist RP EQ expr */ + 189, /* (162) cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */ + 189, /* (163) cmd ::= with insert_cmd INTO xfullname idlist_opt DEFAULT VALUES returning */ + 270, /* (164) upsert ::= */ + 270, /* (165) upsert ::= RETURNING selcollist */ + 270, /* (166) upsert ::= ON CONFLICT LP sortlist RP where_opt DO UPDATE SET setlist where_opt upsert */ + 270, /* (167) upsert ::= ON CONFLICT LP sortlist RP where_opt DO NOTHING upsert */ + 270, /* (168) upsert ::= ON CONFLICT DO NOTHING returning */ + 270, /* (169) upsert ::= ON CONFLICT DO UPDATE SET setlist where_opt returning */ + 271, /* (170) returning ::= RETURNING selcollist */ + 268, /* (171) insert_cmd ::= INSERT orconf */ + 268, /* (172) insert_cmd ::= REPLACE */ + 269, /* (173) idlist_opt ::= */ + 269, /* (174) idlist_opt ::= LP idlist RP */ + 263, /* (175) idlist ::= idlist COMMA nm */ + 263, /* (176) idlist ::= nm */ + 216, /* (177) expr ::= LP expr RP */ + 216, /* (178) expr ::= ID|INDEXED */ + 216, /* (179) expr ::= JOIN_KW */ + 216, /* (180) expr ::= nm DOT nm */ + 216, /* (181) expr ::= nm DOT nm DOT nm */ + 215, /* (182) term ::= NULL|FLOAT|BLOB */ + 215, /* (183) term ::= STRING */ + 215, /* (184) term ::= INTEGER */ + 216, /* (185) expr ::= VARIABLE */ + 216, /* (186) expr ::= expr COLLATE ID|STRING */ + 216, /* (187) expr ::= CAST LP expr AS typetoken RP */ + 216, /* (188) expr ::= ID|INDEXED LP distinct exprlist RP */ + 216, /* (189) expr ::= ID|INDEXED LP STAR RP */ + 216, /* (190) expr ::= ID|INDEXED LP distinct exprlist RP filter_over */ + 216, /* (191) expr ::= ID|INDEXED LP STAR RP filter_over */ + 215, /* (192) term ::= CTIME_KW */ + 216, /* (193) expr ::= LP nexprlist COMMA expr RP */ + 216, /* (194) expr ::= expr AND expr */ + 216, /* (195) expr ::= expr OR expr */ + 216, /* (196) expr ::= expr LT|GT|GE|LE expr */ + 216, /* (197) expr ::= expr EQ|NE expr */ + 216, /* (198) expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ + 216, /* (199) expr ::= expr PLUS|MINUS expr */ + 216, /* (200) expr ::= expr STAR|SLASH|REM expr */ + 216, /* (201) expr ::= expr CONCAT expr */ + 273, /* (202) likeop ::= NOT LIKE_KW|MATCH */ + 216, /* (203) expr ::= expr likeop expr */ + 216, /* (204) expr ::= expr likeop expr ESCAPE expr */ + 216, /* (205) expr ::= expr ISNULL|NOTNULL */ + 216, /* (206) expr ::= expr NOT NULL */ + 216, /* (207) expr ::= expr IS expr */ + 216, /* (208) expr ::= expr IS NOT expr */ + 216, /* (209) expr ::= NOT expr */ + 216, /* (210) expr ::= BITNOT expr */ + 216, /* (211) expr ::= PLUS|MINUS expr */ + 274, /* (212) between_op ::= BETWEEN */ + 274, /* (213) between_op ::= NOT BETWEEN */ + 216, /* (214) expr ::= expr between_op expr AND expr */ + 275, /* (215) in_op ::= IN */ + 275, /* (216) in_op ::= NOT IN */ + 216, /* (217) expr ::= expr in_op LP exprlist RP */ + 216, /* (218) expr ::= LP select RP */ + 216, /* (219) expr ::= expr in_op LP select RP */ + 216, /* (220) expr ::= expr in_op nm dbnm paren_exprlist */ + 216, /* (221) expr ::= EXISTS LP select RP */ + 216, /* (222) expr ::= CASE case_operand case_exprlist case_else END */ + 278, /* (223) case_exprlist ::= case_exprlist WHEN expr THEN expr */ + 278, /* (224) case_exprlist ::= WHEN expr THEN expr */ + 279, /* (225) case_else ::= ELSE expr */ + 279, /* (226) case_else ::= */ + 277, /* (227) case_operand ::= expr */ + 277, /* (228) case_operand ::= */ + 261, /* (229) exprlist ::= */ + 252, /* (230) nexprlist ::= nexprlist COMMA expr */ + 252, /* (231) nexprlist ::= expr */ + 276, /* (232) paren_exprlist ::= */ + 276, /* (233) paren_exprlist ::= LP exprlist RP */ + 189, /* (234) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */ + 280, /* (235) uniqueflag ::= UNIQUE */ + 280, /* (236) uniqueflag ::= */ + 220, /* (237) eidlist_opt ::= */ + 220, /* (238) eidlist_opt ::= LP eidlist RP */ + 231, /* (239) eidlist ::= eidlist COMMA nm collate sortorder */ + 231, /* (240) eidlist ::= nm collate sortorder */ + 281, /* (241) collate ::= */ + 281, /* (242) collate ::= COLLATE ID|STRING */ + 189, /* (243) cmd ::= DROP INDEX ifexists fullname */ + 189, /* (244) cmd ::= VACUUM vinto */ + 189, /* (245) cmd ::= VACUUM nm vinto */ + 282, /* (246) vinto ::= INTO expr */ + 282, /* (247) vinto ::= */ + 189, /* (248) cmd ::= PRAGMA nm dbnm */ + 189, /* (249) cmd ::= PRAGMA nm dbnm EQ nmnum */ + 189, /* (250) cmd ::= PRAGMA nm dbnm LP nmnum RP */ + 189, /* (251) cmd ::= PRAGMA nm dbnm EQ minus_num */ + 189, /* (252) cmd ::= PRAGMA nm dbnm LP minus_num RP */ + 210, /* (253) plus_num ::= PLUS INTEGER|FLOAT */ + 211, /* (254) minus_num ::= MINUS INTEGER|FLOAT */ + 189, /* (255) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */ + 284, /* (256) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */ + 286, /* (257) trigger_time ::= BEFORE|AFTER */ + 286, /* (258) trigger_time ::= INSTEAD OF */ + 286, /* (259) trigger_time ::= */ + 287, /* (260) trigger_event ::= DELETE|INSERT */ + 287, /* (261) trigger_event ::= UPDATE */ + 287, /* (262) trigger_event ::= UPDATE OF idlist */ + 289, /* (263) when_clause ::= */ + 289, /* (264) when_clause ::= WHEN expr */ + 285, /* (265) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */ + 285, /* (266) trigger_cmd_list ::= trigger_cmd SEMI */ + 291, /* (267) trnm ::= nm DOT nm */ + 292, /* (268) tridxby ::= INDEXED BY nm */ + 292, /* (269) tridxby ::= NOT INDEXED */ + 290, /* (270) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */ + 290, /* (271) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */ + 290, /* (272) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */ + 290, /* (273) trigger_cmd ::= scanpt select scanpt */ + 216, /* (274) expr ::= RAISE LP IGNORE RP */ + 216, /* (275) expr ::= RAISE LP raisetype COMMA nm RP */ + 235, /* (276) raisetype ::= ROLLBACK */ + 235, /* (277) raisetype ::= ABORT */ + 235, /* (278) raisetype ::= FAIL */ + 189, /* (279) cmd ::= DROP TRIGGER ifexists fullname */ + 189, /* (280) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */ + 189, /* (281) cmd ::= DETACH database_kw_opt expr */ + 294, /* (282) key_opt ::= */ + 294, /* (283) key_opt ::= KEY expr */ + 189, /* (284) cmd ::= REINDEX */ + 189, /* (285) cmd ::= REINDEX nm dbnm */ + 189, /* (286) cmd ::= ANALYZE */ + 189, /* (287) cmd ::= ANALYZE nm dbnm */ + 189, /* (288) cmd ::= ALTER TABLE fullname RENAME TO nm */ + 189, /* (289) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */ + 189, /* (290) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */ + 295, /* (291) add_column_fullname ::= fullname */ + 189, /* (292) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */ + 189, /* (293) cmd ::= create_vtab */ + 189, /* (294) cmd ::= create_vtab LP vtabarglist RP */ + 297, /* (295) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */ + 299, /* (296) vtabarg ::= */ + 300, /* (297) vtabargtoken ::= ANY */ + 300, /* (298) vtabargtoken ::= lp anylist RP */ + 301, /* (299) lp ::= LP */ + 265, /* (300) with ::= WITH wqlist */ + 265, /* (301) with ::= WITH RECURSIVE wqlist */ + 304, /* (302) wqas ::= AS */ + 304, /* (303) wqas ::= AS MATERIALIZED */ + 304, /* (304) wqas ::= AS NOT MATERIALIZED */ + 303, /* (305) wqitem ::= nm eidlist_opt wqas LP select RP */ + 240, /* (306) wqlist ::= wqitem */ + 240, /* (307) wqlist ::= wqlist COMMA wqitem */ + 305, /* (308) windowdefn_list ::= windowdefn */ + 305, /* (309) windowdefn_list ::= windowdefn_list COMMA windowdefn */ + 306, /* (310) windowdefn ::= nm AS LP window RP */ + 307, /* (311) window ::= PARTITION BY nexprlist orderby_opt frame_opt */ + 307, /* (312) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */ + 307, /* (313) window ::= ORDER BY sortlist frame_opt */ + 307, /* (314) window ::= nm ORDER BY sortlist frame_opt */ + 307, /* (315) window ::= frame_opt */ + 307, /* (316) window ::= nm frame_opt */ + 308, /* (317) frame_opt ::= */ + 308, /* (318) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */ + 308, /* (319) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */ + 312, /* (320) range_or_rows ::= RANGE|ROWS|GROUPS */ + 314, /* (321) frame_bound_s ::= frame_bound */ + 314, /* (322) frame_bound_s ::= UNBOUNDED PRECEDING */ + 315, /* (323) frame_bound_e ::= frame_bound */ + 315, /* (324) frame_bound_e ::= UNBOUNDED FOLLOWING */ + 313, /* (325) frame_bound ::= expr PRECEDING|FOLLOWING */ + 313, /* (326) frame_bound ::= CURRENT ROW */ + 316, /* (327) frame_exclude_opt ::= */ + 316, /* (328) frame_exclude_opt ::= EXCLUDE frame_exclude */ + 317, /* (329) frame_exclude ::= NO OTHERS */ + 317, /* (330) frame_exclude ::= CURRENT ROW */ + 317, /* (331) frame_exclude ::= GROUP|TIES */ + 250, /* (332) window_clause ::= WINDOW windowdefn_list */ + 272, /* (333) filter_over ::= filter_clause over_clause */ + 272, /* (334) filter_over ::= over_clause */ + 272, /* (335) filter_over ::= filter_clause */ + 311, /* (336) over_clause ::= OVER LP window RP */ + 311, /* (337) over_clause ::= OVER nm */ + 310, /* (338) filter_clause ::= FILTER LP WHERE expr RP */ + 184, /* (339) input ::= cmdlist */ + 185, /* (340) cmdlist ::= cmdlist ecmd */ + 185, /* (341) cmdlist ::= ecmd */ + 186, /* (342) ecmd ::= SEMI */ + 186, /* (343) ecmd ::= cmdx SEMI */ + 186, /* (344) ecmd ::= explain cmdx SEMI */ + 191, /* (345) trans_opt ::= */ + 191, /* (346) trans_opt ::= TRANSACTION */ + 191, /* (347) trans_opt ::= TRANSACTION nm */ + 193, /* (348) savepoint_opt ::= SAVEPOINT */ + 193, /* (349) savepoint_opt ::= */ + 189, /* (350) cmd ::= create_table create_table_args */ + 202, /* (351) table_option_set ::= table_option */ + 200, /* (352) columnlist ::= columnlist COMMA columnname carglist */ + 200, /* (353) columnlist ::= columnname carglist */ + 192, /* (354) nm ::= ID|INDEXED */ + 192, /* (355) nm ::= STRING */ + 192, /* (356) nm ::= JOIN_KW */ + 207, /* (357) typetoken ::= typename */ + 208, /* (358) typename ::= ID|STRING */ + 209, /* (359) signed ::= plus_num */ + 209, /* (360) signed ::= minus_num */ + 206, /* (361) carglist ::= carglist ccons */ + 206, /* (362) carglist ::= */ + 214, /* (363) ccons ::= NULL onconf */ + 214, /* (364) ccons ::= GENERATED ALWAYS AS generated */ + 214, /* (365) ccons ::= AS generated */ + 201, /* (366) conslist_opt ::= COMMA conslist */ + 227, /* (367) conslist ::= conslist tconscomma tcons */ + 227, /* (368) conslist ::= tcons */ + 228, /* (369) tconscomma ::= */ + 232, /* (370) defer_subclause_opt ::= defer_subclause */ + 234, /* (371) resolvetype ::= raisetype */ + 238, /* (372) selectnowith ::= oneselect */ + 239, /* (373) oneselect ::= values */ + 253, /* (374) sclp ::= selcollist COMMA */ + 254, /* (375) as ::= ID|STRING */ + 271, /* (376) returning ::= */ + 216, /* (377) expr ::= term */ + 273, /* (378) likeop ::= LIKE_KW|MATCH */ + 261, /* (379) exprlist ::= nexprlist */ + 283, /* (380) nmnum ::= plus_num */ + 283, /* (381) nmnum ::= nm */ + 283, /* (382) nmnum ::= ON */ + 283, /* (383) nmnum ::= DELETE */ + 283, /* (384) nmnum ::= DEFAULT */ + 210, /* (385) plus_num ::= INTEGER|FLOAT */ + 288, /* (386) foreach_clause ::= */ + 288, /* (387) foreach_clause ::= FOR EACH ROW */ + 291, /* (388) trnm ::= nm */ + 292, /* (389) tridxby ::= */ + 293, /* (390) database_kw_opt ::= DATABASE */ + 293, /* (391) database_kw_opt ::= */ + 296, /* (392) kwcolumn_opt ::= */ + 296, /* (393) kwcolumn_opt ::= COLUMNKW */ + 298, /* (394) vtabarglist ::= vtabarg */ + 298, /* (395) vtabarglist ::= vtabarglist COMMA vtabarg */ + 299, /* (396) vtabarg ::= vtabarg vtabargtoken */ + 302, /* (397) anylist ::= */ + 302, /* (398) anylist ::= anylist LP anylist RP */ + 302, /* (399) anylist ::= anylist ANY */ + 265, /* (400) with ::= */ }; /* For rule J, yyRuleInfoNRhs[J] contains the negative of the number ** of symbols on the right-hand side of that rule. */ static const signed char yyRuleInfoNRhs[] = { @@ -164741,200 +162009,199 @@ -3, /* (207) expr ::= expr IS expr */ -4, /* (208) expr ::= expr IS NOT expr */ -2, /* (209) expr ::= NOT expr */ -2, /* (210) expr ::= BITNOT expr */ -2, /* (211) expr ::= PLUS|MINUS expr */ - -3, /* (212) expr ::= expr PTR expr */ - -1, /* (213) between_op ::= BETWEEN */ - -2, /* (214) between_op ::= NOT BETWEEN */ - -5, /* (215) expr ::= expr between_op expr AND expr */ - -1, /* (216) in_op ::= IN */ - -2, /* (217) in_op ::= NOT IN */ - -5, /* (218) expr ::= expr in_op LP exprlist RP */ - -3, /* (219) expr ::= LP select RP */ - -5, /* (220) expr ::= expr in_op LP select RP */ - -5, /* (221) expr ::= expr in_op nm dbnm paren_exprlist */ - -4, /* (222) expr ::= EXISTS LP select RP */ - -5, /* (223) expr ::= CASE case_operand case_exprlist case_else END */ - -5, /* (224) case_exprlist ::= case_exprlist WHEN expr THEN expr */ - -4, /* (225) case_exprlist ::= WHEN expr THEN expr */ - -2, /* (226) case_else ::= ELSE expr */ - 0, /* (227) case_else ::= */ - -1, /* (228) case_operand ::= expr */ - 0, /* (229) case_operand ::= */ - 0, /* (230) exprlist ::= */ - -3, /* (231) nexprlist ::= nexprlist COMMA expr */ - -1, /* (232) nexprlist ::= expr */ - 0, /* (233) paren_exprlist ::= */ - -3, /* (234) paren_exprlist ::= LP exprlist RP */ - -12, /* (235) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */ - -1, /* (236) uniqueflag ::= UNIQUE */ - 0, /* (237) uniqueflag ::= */ - 0, /* (238) eidlist_opt ::= */ - -3, /* (239) eidlist_opt ::= LP eidlist RP */ - -5, /* (240) eidlist ::= eidlist COMMA nm collate sortorder */ - -3, /* (241) eidlist ::= nm collate sortorder */ - 0, /* (242) collate ::= */ - -2, /* (243) collate ::= COLLATE ID|STRING */ - -4, /* (244) cmd ::= DROP INDEX ifexists fullname */ - -2, /* (245) cmd ::= VACUUM vinto */ - -3, /* (246) cmd ::= VACUUM nm vinto */ - -2, /* (247) vinto ::= INTO expr */ - 0, /* (248) vinto ::= */ - -3, /* (249) cmd ::= PRAGMA nm dbnm */ - -5, /* (250) cmd ::= PRAGMA nm dbnm EQ nmnum */ - -6, /* (251) cmd ::= PRAGMA nm dbnm LP nmnum RP */ - -5, /* (252) cmd ::= PRAGMA nm dbnm EQ minus_num */ - -6, /* (253) cmd ::= PRAGMA nm dbnm LP minus_num RP */ - -2, /* (254) plus_num ::= PLUS INTEGER|FLOAT */ - -2, /* (255) minus_num ::= MINUS INTEGER|FLOAT */ - -5, /* (256) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */ - -11, /* (257) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */ - -1, /* (258) trigger_time ::= BEFORE|AFTER */ - -2, /* (259) trigger_time ::= INSTEAD OF */ - 0, /* (260) trigger_time ::= */ - -1, /* (261) trigger_event ::= DELETE|INSERT */ - -1, /* (262) trigger_event ::= UPDATE */ - -3, /* (263) trigger_event ::= UPDATE OF idlist */ - 0, /* (264) when_clause ::= */ - -2, /* (265) when_clause ::= WHEN expr */ - -3, /* (266) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */ - -2, /* (267) trigger_cmd_list ::= trigger_cmd SEMI */ - -3, /* (268) trnm ::= nm DOT nm */ - -3, /* (269) tridxby ::= INDEXED BY nm */ - -2, /* (270) tridxby ::= NOT INDEXED */ - -9, /* (271) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */ - -8, /* (272) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */ - -6, /* (273) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */ - -3, /* (274) trigger_cmd ::= scanpt select scanpt */ - -4, /* (275) expr ::= RAISE LP IGNORE RP */ - -6, /* (276) expr ::= RAISE LP raisetype COMMA nm RP */ - -1, /* (277) raisetype ::= ROLLBACK */ - -1, /* (278) raisetype ::= ABORT */ - -1, /* (279) raisetype ::= FAIL */ - -4, /* (280) cmd ::= DROP TRIGGER ifexists fullname */ - -6, /* (281) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */ - -3, /* (282) cmd ::= DETACH database_kw_opt expr */ - 0, /* (283) key_opt ::= */ - -2, /* (284) key_opt ::= KEY expr */ - -1, /* (285) cmd ::= REINDEX */ - -3, /* (286) cmd ::= REINDEX nm dbnm */ - -1, /* (287) cmd ::= ANALYZE */ - -3, /* (288) cmd ::= ANALYZE nm dbnm */ - -6, /* (289) cmd ::= ALTER TABLE fullname RENAME TO nm */ - -7, /* (290) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */ - -6, /* (291) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */ - -1, /* (292) add_column_fullname ::= fullname */ - -8, /* (293) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */ - -1, /* (294) cmd ::= create_vtab */ - -4, /* (295) cmd ::= create_vtab LP vtabarglist RP */ - -8, /* (296) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */ - 0, /* (297) vtabarg ::= */ - -1, /* (298) vtabargtoken ::= ANY */ - -3, /* (299) vtabargtoken ::= lp anylist RP */ - -1, /* (300) lp ::= LP */ - -2, /* (301) with ::= WITH wqlist */ - -3, /* (302) with ::= WITH RECURSIVE wqlist */ - -1, /* (303) wqas ::= AS */ - -2, /* (304) wqas ::= AS MATERIALIZED */ - -3, /* (305) wqas ::= AS NOT MATERIALIZED */ - -6, /* (306) wqitem ::= nm eidlist_opt wqas LP select RP */ - -1, /* (307) wqlist ::= wqitem */ - -3, /* (308) wqlist ::= wqlist COMMA wqitem */ - -1, /* (309) windowdefn_list ::= windowdefn */ - -3, /* (310) windowdefn_list ::= windowdefn_list COMMA windowdefn */ - -5, /* (311) windowdefn ::= nm AS LP window RP */ - -5, /* (312) window ::= PARTITION BY nexprlist orderby_opt frame_opt */ - -6, /* (313) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */ - -4, /* (314) window ::= ORDER BY sortlist frame_opt */ - -5, /* (315) window ::= nm ORDER BY sortlist frame_opt */ - -1, /* (316) window ::= frame_opt */ - -2, /* (317) window ::= nm frame_opt */ - 0, /* (318) frame_opt ::= */ - -3, /* (319) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */ - -6, /* (320) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */ - -1, /* (321) range_or_rows ::= RANGE|ROWS|GROUPS */ - -1, /* (322) frame_bound_s ::= frame_bound */ - -2, /* (323) frame_bound_s ::= UNBOUNDED PRECEDING */ - -1, /* (324) frame_bound_e ::= frame_bound */ - -2, /* (325) frame_bound_e ::= UNBOUNDED FOLLOWING */ - -2, /* (326) frame_bound ::= expr PRECEDING|FOLLOWING */ - -2, /* (327) frame_bound ::= CURRENT ROW */ - 0, /* (328) frame_exclude_opt ::= */ - -2, /* (329) frame_exclude_opt ::= EXCLUDE frame_exclude */ - -2, /* (330) frame_exclude ::= NO OTHERS */ - -2, /* (331) frame_exclude ::= CURRENT ROW */ - -1, /* (332) frame_exclude ::= GROUP|TIES */ - -2, /* (333) window_clause ::= WINDOW windowdefn_list */ - -2, /* (334) filter_over ::= filter_clause over_clause */ - -1, /* (335) filter_over ::= over_clause */ - -1, /* (336) filter_over ::= filter_clause */ - -4, /* (337) over_clause ::= OVER LP window RP */ - -2, /* (338) over_clause ::= OVER nm */ - -5, /* (339) filter_clause ::= FILTER LP WHERE expr RP */ - -1, /* (340) input ::= cmdlist */ - -2, /* (341) cmdlist ::= cmdlist ecmd */ - -1, /* (342) cmdlist ::= ecmd */ - -1, /* (343) ecmd ::= SEMI */ - -2, /* (344) ecmd ::= cmdx SEMI */ - -3, /* (345) ecmd ::= explain cmdx SEMI */ - 0, /* (346) trans_opt ::= */ - -1, /* (347) trans_opt ::= TRANSACTION */ - -2, /* (348) trans_opt ::= TRANSACTION nm */ - -1, /* (349) savepoint_opt ::= SAVEPOINT */ - 0, /* (350) savepoint_opt ::= */ - -2, /* (351) cmd ::= create_table create_table_args */ - -1, /* (352) table_option_set ::= table_option */ - -4, /* (353) columnlist ::= columnlist COMMA columnname carglist */ - -2, /* (354) columnlist ::= columnname carglist */ - -1, /* (355) nm ::= ID|INDEXED */ - -1, /* (356) nm ::= STRING */ - -1, /* (357) nm ::= JOIN_KW */ - -1, /* (358) typetoken ::= typename */ - -1, /* (359) typename ::= ID|STRING */ - -1, /* (360) signed ::= plus_num */ - -1, /* (361) signed ::= minus_num */ - -2, /* (362) carglist ::= carglist ccons */ - 0, /* (363) carglist ::= */ - -2, /* (364) ccons ::= NULL onconf */ - -4, /* (365) ccons ::= GENERATED ALWAYS AS generated */ - -2, /* (366) ccons ::= AS generated */ - -2, /* (367) conslist_opt ::= COMMA conslist */ - -3, /* (368) conslist ::= conslist tconscomma tcons */ - -1, /* (369) conslist ::= tcons */ - 0, /* (370) tconscomma ::= */ - -1, /* (371) defer_subclause_opt ::= defer_subclause */ - -1, /* (372) resolvetype ::= raisetype */ - -1, /* (373) selectnowith ::= oneselect */ - -1, /* (374) oneselect ::= values */ - -2, /* (375) sclp ::= selcollist COMMA */ - -1, /* (376) as ::= ID|STRING */ - 0, /* (377) returning ::= */ - -1, /* (378) expr ::= term */ - -1, /* (379) likeop ::= LIKE_KW|MATCH */ - -1, /* (380) exprlist ::= nexprlist */ - -1, /* (381) nmnum ::= plus_num */ - -1, /* (382) nmnum ::= nm */ - -1, /* (383) nmnum ::= ON */ - -1, /* (384) nmnum ::= DELETE */ - -1, /* (385) nmnum ::= DEFAULT */ - -1, /* (386) plus_num ::= INTEGER|FLOAT */ - 0, /* (387) foreach_clause ::= */ - -3, /* (388) foreach_clause ::= FOR EACH ROW */ - -1, /* (389) trnm ::= nm */ - 0, /* (390) tridxby ::= */ - -1, /* (391) database_kw_opt ::= DATABASE */ - 0, /* (392) database_kw_opt ::= */ - 0, /* (393) kwcolumn_opt ::= */ - -1, /* (394) kwcolumn_opt ::= COLUMNKW */ - -1, /* (395) vtabarglist ::= vtabarg */ - -3, /* (396) vtabarglist ::= vtabarglist COMMA vtabarg */ - -2, /* (397) vtabarg ::= vtabarg vtabargtoken */ - 0, /* (398) anylist ::= */ - -4, /* (399) anylist ::= anylist LP anylist RP */ - -2, /* (400) anylist ::= anylist ANY */ - 0, /* (401) with ::= */ + -1, /* (212) between_op ::= BETWEEN */ + -2, /* (213) between_op ::= NOT BETWEEN */ + -5, /* (214) expr ::= expr between_op expr AND expr */ + -1, /* (215) in_op ::= IN */ + -2, /* (216) in_op ::= NOT IN */ + -5, /* (217) expr ::= expr in_op LP exprlist RP */ + -3, /* (218) expr ::= LP select RP */ + -5, /* (219) expr ::= expr in_op LP select RP */ + -5, /* (220) expr ::= expr in_op nm dbnm paren_exprlist */ + -4, /* (221) expr ::= EXISTS LP select RP */ + -5, /* (222) expr ::= CASE case_operand case_exprlist case_else END */ + -5, /* (223) case_exprlist ::= case_exprlist WHEN expr THEN expr */ + -4, /* (224) case_exprlist ::= WHEN expr THEN expr */ + -2, /* (225) case_else ::= ELSE expr */ + 0, /* (226) case_else ::= */ + -1, /* (227) case_operand ::= expr */ + 0, /* (228) case_operand ::= */ + 0, /* (229) exprlist ::= */ + -3, /* (230) nexprlist ::= nexprlist COMMA expr */ + -1, /* (231) nexprlist ::= expr */ + 0, /* (232) paren_exprlist ::= */ + -3, /* (233) paren_exprlist ::= LP exprlist RP */ + -12, /* (234) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */ + -1, /* (235) uniqueflag ::= UNIQUE */ + 0, /* (236) uniqueflag ::= */ + 0, /* (237) eidlist_opt ::= */ + -3, /* (238) eidlist_opt ::= LP eidlist RP */ + -5, /* (239) eidlist ::= eidlist COMMA nm collate sortorder */ + -3, /* (240) eidlist ::= nm collate sortorder */ + 0, /* (241) collate ::= */ + -2, /* (242) collate ::= COLLATE ID|STRING */ + -4, /* (243) cmd ::= DROP INDEX ifexists fullname */ + -2, /* (244) cmd ::= VACUUM vinto */ + -3, /* (245) cmd ::= VACUUM nm vinto */ + -2, /* (246) vinto ::= INTO expr */ + 0, /* (247) vinto ::= */ + -3, /* (248) cmd ::= PRAGMA nm dbnm */ + -5, /* (249) cmd ::= PRAGMA nm dbnm EQ nmnum */ + -6, /* (250) cmd ::= PRAGMA nm dbnm LP nmnum RP */ + -5, /* (251) cmd ::= PRAGMA nm dbnm EQ minus_num */ + -6, /* (252) cmd ::= PRAGMA nm dbnm LP minus_num RP */ + -2, /* (253) plus_num ::= PLUS INTEGER|FLOAT */ + -2, /* (254) minus_num ::= MINUS INTEGER|FLOAT */ + -5, /* (255) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */ + -11, /* (256) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */ + -1, /* (257) trigger_time ::= BEFORE|AFTER */ + -2, /* (258) trigger_time ::= INSTEAD OF */ + 0, /* (259) trigger_time ::= */ + -1, /* (260) trigger_event ::= DELETE|INSERT */ + -1, /* (261) trigger_event ::= UPDATE */ + -3, /* (262) trigger_event ::= UPDATE OF idlist */ + 0, /* (263) when_clause ::= */ + -2, /* (264) when_clause ::= WHEN expr */ + -3, /* (265) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */ + -2, /* (266) trigger_cmd_list ::= trigger_cmd SEMI */ + -3, /* (267) trnm ::= nm DOT nm */ + -3, /* (268) tridxby ::= INDEXED BY nm */ + -2, /* (269) tridxby ::= NOT INDEXED */ + -9, /* (270) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */ + -8, /* (271) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */ + -6, /* (272) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */ + -3, /* (273) trigger_cmd ::= scanpt select scanpt */ + -4, /* (274) expr ::= RAISE LP IGNORE RP */ + -6, /* (275) expr ::= RAISE LP raisetype COMMA nm RP */ + -1, /* (276) raisetype ::= ROLLBACK */ + -1, /* (277) raisetype ::= ABORT */ + -1, /* (278) raisetype ::= FAIL */ + -4, /* (279) cmd ::= DROP TRIGGER ifexists fullname */ + -6, /* (280) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */ + -3, /* (281) cmd ::= DETACH database_kw_opt expr */ + 0, /* (282) key_opt ::= */ + -2, /* (283) key_opt ::= KEY expr */ + -1, /* (284) cmd ::= REINDEX */ + -3, /* (285) cmd ::= REINDEX nm dbnm */ + -1, /* (286) cmd ::= ANALYZE */ + -3, /* (287) cmd ::= ANALYZE nm dbnm */ + -6, /* (288) cmd ::= ALTER TABLE fullname RENAME TO nm */ + -7, /* (289) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */ + -6, /* (290) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */ + -1, /* (291) add_column_fullname ::= fullname */ + -8, /* (292) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */ + -1, /* (293) cmd ::= create_vtab */ + -4, /* (294) cmd ::= create_vtab LP vtabarglist RP */ + -8, /* (295) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */ + 0, /* (296) vtabarg ::= */ + -1, /* (297) vtabargtoken ::= ANY */ + -3, /* (298) vtabargtoken ::= lp anylist RP */ + -1, /* (299) lp ::= LP */ + -2, /* (300) with ::= WITH wqlist */ + -3, /* (301) with ::= WITH RECURSIVE wqlist */ + -1, /* (302) wqas ::= AS */ + -2, /* (303) wqas ::= AS MATERIALIZED */ + -3, /* (304) wqas ::= AS NOT MATERIALIZED */ + -6, /* (305) wqitem ::= nm eidlist_opt wqas LP select RP */ + -1, /* (306) wqlist ::= wqitem */ + -3, /* (307) wqlist ::= wqlist COMMA wqitem */ + -1, /* (308) windowdefn_list ::= windowdefn */ + -3, /* (309) windowdefn_list ::= windowdefn_list COMMA windowdefn */ + -5, /* (310) windowdefn ::= nm AS LP window RP */ + -5, /* (311) window ::= PARTITION BY nexprlist orderby_opt frame_opt */ + -6, /* (312) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */ + -4, /* (313) window ::= ORDER BY sortlist frame_opt */ + -5, /* (314) window ::= nm ORDER BY sortlist frame_opt */ + -1, /* (315) window ::= frame_opt */ + -2, /* (316) window ::= nm frame_opt */ + 0, /* (317) frame_opt ::= */ + -3, /* (318) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */ + -6, /* (319) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */ + -1, /* (320) range_or_rows ::= RANGE|ROWS|GROUPS */ + -1, /* (321) frame_bound_s ::= frame_bound */ + -2, /* (322) frame_bound_s ::= UNBOUNDED PRECEDING */ + -1, /* (323) frame_bound_e ::= frame_bound */ + -2, /* (324) frame_bound_e ::= UNBOUNDED FOLLOWING */ + -2, /* (325) frame_bound ::= expr PRECEDING|FOLLOWING */ + -2, /* (326) frame_bound ::= CURRENT ROW */ + 0, /* (327) frame_exclude_opt ::= */ + -2, /* (328) frame_exclude_opt ::= EXCLUDE frame_exclude */ + -2, /* (329) frame_exclude ::= NO OTHERS */ + -2, /* (330) frame_exclude ::= CURRENT ROW */ + -1, /* (331) frame_exclude ::= GROUP|TIES */ + -2, /* (332) window_clause ::= WINDOW windowdefn_list */ + -2, /* (333) filter_over ::= filter_clause over_clause */ + -1, /* (334) filter_over ::= over_clause */ + -1, /* (335) filter_over ::= filter_clause */ + -4, /* (336) over_clause ::= OVER LP window RP */ + -2, /* (337) over_clause ::= OVER nm */ + -5, /* (338) filter_clause ::= FILTER LP WHERE expr RP */ + -1, /* (339) input ::= cmdlist */ + -2, /* (340) cmdlist ::= cmdlist ecmd */ + -1, /* (341) cmdlist ::= ecmd */ + -1, /* (342) ecmd ::= SEMI */ + -2, /* (343) ecmd ::= cmdx SEMI */ + -3, /* (344) ecmd ::= explain cmdx SEMI */ + 0, /* (345) trans_opt ::= */ + -1, /* (346) trans_opt ::= TRANSACTION */ + -2, /* (347) trans_opt ::= TRANSACTION nm */ + -1, /* (348) savepoint_opt ::= SAVEPOINT */ + 0, /* (349) savepoint_opt ::= */ + -2, /* (350) cmd ::= create_table create_table_args */ + -1, /* (351) table_option_set ::= table_option */ + -4, /* (352) columnlist ::= columnlist COMMA columnname carglist */ + -2, /* (353) columnlist ::= columnname carglist */ + -1, /* (354) nm ::= ID|INDEXED */ + -1, /* (355) nm ::= STRING */ + -1, /* (356) nm ::= JOIN_KW */ + -1, /* (357) typetoken ::= typename */ + -1, /* (358) typename ::= ID|STRING */ + -1, /* (359) signed ::= plus_num */ + -1, /* (360) signed ::= minus_num */ + -2, /* (361) carglist ::= carglist ccons */ + 0, /* (362) carglist ::= */ + -2, /* (363) ccons ::= NULL onconf */ + -4, /* (364) ccons ::= GENERATED ALWAYS AS generated */ + -2, /* (365) ccons ::= AS generated */ + -2, /* (366) conslist_opt ::= COMMA conslist */ + -3, /* (367) conslist ::= conslist tconscomma tcons */ + -1, /* (368) conslist ::= tcons */ + 0, /* (369) tconscomma ::= */ + -1, /* (370) defer_subclause_opt ::= defer_subclause */ + -1, /* (371) resolvetype ::= raisetype */ + -1, /* (372) selectnowith ::= oneselect */ + -1, /* (373) oneselect ::= values */ + -2, /* (374) sclp ::= selcollist COMMA */ + -1, /* (375) as ::= ID|STRING */ + 0, /* (376) returning ::= */ + -1, /* (377) expr ::= term */ + -1, /* (378) likeop ::= LIKE_KW|MATCH */ + -1, /* (379) exprlist ::= nexprlist */ + -1, /* (380) nmnum ::= plus_num */ + -1, /* (381) nmnum ::= nm */ + -1, /* (382) nmnum ::= ON */ + -1, /* (383) nmnum ::= DELETE */ + -1, /* (384) nmnum ::= DEFAULT */ + -1, /* (385) plus_num ::= INTEGER|FLOAT */ + 0, /* (386) foreach_clause ::= */ + -3, /* (387) foreach_clause ::= FOR EACH ROW */ + -1, /* (388) trnm ::= nm */ + 0, /* (389) tridxby ::= */ + -1, /* (390) database_kw_opt ::= DATABASE */ + 0, /* (391) database_kw_opt ::= */ + 0, /* (392) kwcolumn_opt ::= */ + -1, /* (393) kwcolumn_opt ::= COLUMNKW */ + -1, /* (394) vtabarglist ::= vtabarg */ + -3, /* (395) vtabarglist ::= vtabarglist COMMA vtabarg */ + -2, /* (396) vtabarg ::= vtabarg vtabargtoken */ + 0, /* (397) anylist ::= */ + -4, /* (398) anylist ::= anylist LP anylist RP */ + -2, /* (399) anylist ::= anylist ANY */ + 0, /* (400) with ::= */ }; static void yy_accept(yyParser*); /* Forward Declaration */ /* @@ -164982,20 +162249,20 @@ break; case 2: /* cmdx ::= cmd */ { sqlite3FinishCoding(pParse); } break; case 3: /* cmd ::= BEGIN transtype trans_opt */ -{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy394);} +{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy64);} break; case 4: /* transtype ::= */ -{yymsp[1].minor.yy394 = TK_DEFERRED;} +{yymsp[1].minor.yy64 = TK_DEFERRED;} break; case 5: /* transtype ::= DEFERRED */ case 6: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==6); case 7: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==7); - case 321: /* range_or_rows ::= RANGE|ROWS|GROUPS */ yytestcase(yyruleno==321); -{yymsp[0].minor.yy394 = yymsp[0].major; /*A-overwrites-X*/} + case 320: /* range_or_rows ::= RANGE|ROWS|GROUPS */ yytestcase(yyruleno==320); +{yymsp[0].minor.yy64 = yymsp[0].major; /*A-overwrites-X*/} break; case 8: /* cmd ::= COMMIT|END trans_opt */ case 9: /* cmd ::= ROLLBACK trans_opt */ yytestcase(yyruleno==9); {sqlite3EndTransaction(pParse,yymsp[-1].major);} break; @@ -165014,11 +162281,11 @@ sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0); } break; case 13: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */ { - sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy394,0,0,yymsp[-2].minor.yy394); + sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy64,0,0,yymsp[-2].minor.yy64); } break; case 14: /* createkw ::= CREATE */ {disableLookaside(pParse);} break; @@ -165027,57 +162294,57 @@ case 47: /* autoinc ::= */ yytestcase(yyruleno==47); case 62: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==62); case 72: /* defer_subclause_opt ::= */ yytestcase(yyruleno==72); case 81: /* ifexists ::= */ yytestcase(yyruleno==81); case 98: /* distinct ::= */ yytestcase(yyruleno==98); - case 242: /* collate ::= */ yytestcase(yyruleno==242); -{yymsp[1].minor.yy394 = 0;} + case 241: /* collate ::= */ yytestcase(yyruleno==241); +{yymsp[1].minor.yy64 = 0;} break; case 16: /* ifnotexists ::= IF NOT EXISTS */ -{yymsp[-2].minor.yy394 = 1;} +{yymsp[-2].minor.yy64 = 1;} break; case 17: /* temp ::= TEMP */ -{yymsp[0].minor.yy394 = pParse->db->init.busy==0;} +{yymsp[0].minor.yy64 = pParse->db->init.busy==0;} break; case 19: /* create_table_args ::= LP columnlist conslist_opt RP table_option_set */ { - sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy285,0); + sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy51,0); } break; case 20: /* create_table_args ::= AS select */ { - sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy47); - sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy47); + sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy303); + sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy303); } break; case 21: /* table_option_set ::= */ -{yymsp[1].minor.yy285 = 0;} +{yymsp[1].minor.yy51 = 0;} break; case 22: /* table_option_set ::= table_option_set COMMA table_option */ -{yylhsminor.yy285 = yymsp[-2].minor.yy285|yymsp[0].minor.yy285;} - yymsp[-2].minor.yy285 = yylhsminor.yy285; +{yylhsminor.yy51 = yymsp[-2].minor.yy51|yymsp[0].minor.yy51;} + yymsp[-2].minor.yy51 = yylhsminor.yy51; break; case 23: /* table_option ::= WITHOUT nm */ { if( yymsp[0].minor.yy0.n==5 && sqlite3_strnicmp(yymsp[0].minor.yy0.z,"rowid",5)==0 ){ - yymsp[-1].minor.yy285 = TF_WithoutRowid | TF_NoVisibleRowid; + yymsp[-1].minor.yy51 = TF_WithoutRowid | TF_NoVisibleRowid; }else{ - yymsp[-1].minor.yy285 = 0; + yymsp[-1].minor.yy51 = 0; sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z); } } break; case 24: /* table_option ::= nm */ { if( yymsp[0].minor.yy0.n==6 && sqlite3_strnicmp(yymsp[0].minor.yy0.z,"strict",6)==0 ){ - yylhsminor.yy285 = TF_Strict; + yylhsminor.yy51 = TF_Strict; }else{ - yylhsminor.yy285 = 0; + yylhsminor.yy51 = 0; sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z); } } - yymsp[0].minor.yy285 = yylhsminor.yy285; + yymsp[0].minor.yy51 = yylhsminor.yy51; break; case 25: /* columnname ::= nm typetoken */ {sqlite3AddColumn(pParse,yymsp[-1].minor.yy0,yymsp[0].minor.yy0);} break; case 26: /* typetoken ::= */ @@ -165099,11 +162366,11 @@ {yymsp[-1].minor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);} break; case 30: /* scanpt ::= */ { assert( yyLookahead!=YYNOCODE ); - yymsp[1].minor.yy522 = yyLookaheadToken.z; + yymsp[1].minor.yy600 = yyLookaheadToken.z; } break; case 31: /* scantok ::= */ { assert( yyLookahead!=YYNOCODE ); @@ -165113,21 +162380,21 @@ case 32: /* ccons ::= CONSTRAINT nm */ case 67: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==67); {pParse->constraintName = yymsp[0].minor.yy0;} break; case 33: /* ccons ::= DEFAULT scantok term */ -{sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy528,yymsp[-1].minor.yy0.z,&yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n]);} +{sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy626,yymsp[-1].minor.yy0.z,&yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n]);} break; case 34: /* ccons ::= DEFAULT LP expr RP */ -{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy528,yymsp[-2].minor.yy0.z+1,yymsp[0].minor.yy0.z);} +{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy626,yymsp[-2].minor.yy0.z+1,yymsp[0].minor.yy0.z);} break; case 35: /* ccons ::= DEFAULT PLUS scantok term */ -{sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy528,yymsp[-2].minor.yy0.z,&yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n]);} +{sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy626,yymsp[-2].minor.yy0.z,&yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n]);} break; case 36: /* ccons ::= DEFAULT MINUS scantok term */ { - Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy528, 0); + Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy626, 0); sqlite3AddDefaultValue(pParse,p,yymsp[-2].minor.yy0.z,&yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n]); } break; case 37: /* ccons ::= DEFAULT scantok ID|INDEXED */ { @@ -165138,308 +162405,308 @@ } sqlite3AddDefaultValue(pParse,p,yymsp[0].minor.yy0.z,yymsp[0].minor.yy0.z+yymsp[0].minor.yy0.n); } break; case 38: /* ccons ::= NOT NULL onconf */ -{sqlite3AddNotNull(pParse, yymsp[0].minor.yy394);} +{sqlite3AddNotNull(pParse, yymsp[0].minor.yy64);} break; case 39: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */ -{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy394,yymsp[0].minor.yy394,yymsp[-2].minor.yy394);} +{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy64,yymsp[0].minor.yy64,yymsp[-2].minor.yy64);} break; case 40: /* ccons ::= UNIQUE onconf */ -{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy394,0,0,0,0, +{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy64,0,0,0,0, SQLITE_IDXTYPE_UNIQUE);} break; case 41: /* ccons ::= CHECK LP expr RP */ -{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy528,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy0.z);} +{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy626,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy0.z);} break; case 42: /* ccons ::= REFERENCES nm eidlist_opt refargs */ -{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy322,yymsp[0].minor.yy394);} +{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy562,yymsp[0].minor.yy64);} break; case 43: /* ccons ::= defer_subclause */ -{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy394);} +{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy64);} break; case 44: /* ccons ::= COLLATE ID|STRING */ {sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);} break; case 45: /* generated ::= LP expr RP */ -{sqlite3AddGenerated(pParse,yymsp[-1].minor.yy528,0);} +{sqlite3AddGenerated(pParse,yymsp[-1].minor.yy626,0);} break; case 46: /* generated ::= LP expr RP ID */ -{sqlite3AddGenerated(pParse,yymsp[-2].minor.yy528,&yymsp[0].minor.yy0);} +{sqlite3AddGenerated(pParse,yymsp[-2].minor.yy626,&yymsp[0].minor.yy0);} break; case 48: /* autoinc ::= AUTOINCR */ -{yymsp[0].minor.yy394 = 1;} +{yymsp[0].minor.yy64 = 1;} break; case 49: /* refargs ::= */ -{ yymsp[1].minor.yy394 = OE_None*0x0101; /* EV: R-19803-45884 */} +{ yymsp[1].minor.yy64 = OE_None*0x0101; /* EV: R-19803-45884 */} break; case 50: /* refargs ::= refargs refarg */ -{ yymsp[-1].minor.yy394 = (yymsp[-1].minor.yy394 & ~yymsp[0].minor.yy231.mask) | yymsp[0].minor.yy231.value; } +{ yymsp[-1].minor.yy64 = (yymsp[-1].minor.yy64 & ~yymsp[0].minor.yy83.mask) | yymsp[0].minor.yy83.value; } break; case 51: /* refarg ::= MATCH nm */ -{ yymsp[-1].minor.yy231.value = 0; yymsp[-1].minor.yy231.mask = 0x000000; } +{ yymsp[-1].minor.yy83.value = 0; yymsp[-1].minor.yy83.mask = 0x000000; } break; case 52: /* refarg ::= ON INSERT refact */ -{ yymsp[-2].minor.yy231.value = 0; yymsp[-2].minor.yy231.mask = 0x000000; } +{ yymsp[-2].minor.yy83.value = 0; yymsp[-2].minor.yy83.mask = 0x000000; } break; case 53: /* refarg ::= ON DELETE refact */ -{ yymsp[-2].minor.yy231.value = yymsp[0].minor.yy394; yymsp[-2].minor.yy231.mask = 0x0000ff; } +{ yymsp[-2].minor.yy83.value = yymsp[0].minor.yy64; yymsp[-2].minor.yy83.mask = 0x0000ff; } break; case 54: /* refarg ::= ON UPDATE refact */ -{ yymsp[-2].minor.yy231.value = yymsp[0].minor.yy394<<8; yymsp[-2].minor.yy231.mask = 0x00ff00; } +{ yymsp[-2].minor.yy83.value = yymsp[0].minor.yy64<<8; yymsp[-2].minor.yy83.mask = 0x00ff00; } break; case 55: /* refact ::= SET NULL */ -{ yymsp[-1].minor.yy394 = OE_SetNull; /* EV: R-33326-45252 */} +{ yymsp[-1].minor.yy64 = OE_SetNull; /* EV: R-33326-45252 */} break; case 56: /* refact ::= SET DEFAULT */ -{ yymsp[-1].minor.yy394 = OE_SetDflt; /* EV: R-33326-45252 */} +{ yymsp[-1].minor.yy64 = OE_SetDflt; /* EV: R-33326-45252 */} break; case 57: /* refact ::= CASCADE */ -{ yymsp[0].minor.yy394 = OE_Cascade; /* EV: R-33326-45252 */} +{ yymsp[0].minor.yy64 = OE_Cascade; /* EV: R-33326-45252 */} break; case 58: /* refact ::= RESTRICT */ -{ yymsp[0].minor.yy394 = OE_Restrict; /* EV: R-33326-45252 */} +{ yymsp[0].minor.yy64 = OE_Restrict; /* EV: R-33326-45252 */} break; case 59: /* refact ::= NO ACTION */ -{ yymsp[-1].minor.yy394 = OE_None; /* EV: R-33326-45252 */} +{ yymsp[-1].minor.yy64 = OE_None; /* EV: R-33326-45252 */} break; case 60: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ -{yymsp[-2].minor.yy394 = 0;} +{yymsp[-2].minor.yy64 = 0;} break; case 61: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */ case 76: /* orconf ::= OR resolvetype */ yytestcase(yyruleno==76); case 171: /* insert_cmd ::= INSERT orconf */ yytestcase(yyruleno==171); -{yymsp[-1].minor.yy394 = yymsp[0].minor.yy394;} +{yymsp[-1].minor.yy64 = yymsp[0].minor.yy64;} break; case 63: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ case 80: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==80); - case 214: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==214); - case 217: /* in_op ::= NOT IN */ yytestcase(yyruleno==217); - case 243: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==243); -{yymsp[-1].minor.yy394 = 1;} + case 213: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==213); + case 216: /* in_op ::= NOT IN */ yytestcase(yyruleno==216); + case 242: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==242); +{yymsp[-1].minor.yy64 = 1;} break; case 64: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ -{yymsp[-1].minor.yy394 = 0;} +{yymsp[-1].minor.yy64 = 0;} break; case 66: /* tconscomma ::= COMMA */ {pParse->constraintName.n = 0;} break; case 68: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */ -{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy322,yymsp[0].minor.yy394,yymsp[-2].minor.yy394,0);} +{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy562,yymsp[0].minor.yy64,yymsp[-2].minor.yy64,0);} break; case 69: /* tcons ::= UNIQUE LP sortlist RP onconf */ -{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy322,yymsp[0].minor.yy394,0,0,0,0, +{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy562,yymsp[0].minor.yy64,0,0,0,0, SQLITE_IDXTYPE_UNIQUE);} break; case 70: /* tcons ::= CHECK LP expr RP onconf */ -{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy528,yymsp[-3].minor.yy0.z,yymsp[-1].minor.yy0.z);} +{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy626,yymsp[-3].minor.yy0.z,yymsp[-1].minor.yy0.z);} break; case 71: /* tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */ { - sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy322, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy322, yymsp[-1].minor.yy394); - sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy394); + sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy562, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy562, yymsp[-1].minor.yy64); + sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy64); } break; case 73: /* onconf ::= */ case 75: /* orconf ::= */ yytestcase(yyruleno==75); -{yymsp[1].minor.yy394 = OE_Default;} +{yymsp[1].minor.yy64 = OE_Default;} break; case 74: /* onconf ::= ON CONFLICT resolvetype */ -{yymsp[-2].minor.yy394 = yymsp[0].minor.yy394;} +{yymsp[-2].minor.yy64 = yymsp[0].minor.yy64;} break; case 77: /* resolvetype ::= IGNORE */ -{yymsp[0].minor.yy394 = OE_Ignore;} +{yymsp[0].minor.yy64 = OE_Ignore;} break; case 78: /* resolvetype ::= REPLACE */ case 172: /* insert_cmd ::= REPLACE */ yytestcase(yyruleno==172); -{yymsp[0].minor.yy394 = OE_Replace;} +{yymsp[0].minor.yy64 = OE_Replace;} break; case 79: /* cmd ::= DROP TABLE ifexists fullname */ { - sqlite3DropTable(pParse, yymsp[0].minor.yy131, 0, yymsp[-1].minor.yy394); + sqlite3DropTable(pParse, yymsp[0].minor.yy607, 0, yymsp[-1].minor.yy64); } break; case 82: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */ { - sqlite3CreateView(pParse, &yymsp[-8].minor.yy0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy322, yymsp[0].minor.yy47, yymsp[-7].minor.yy394, yymsp[-5].minor.yy394); + sqlite3CreateView(pParse, &yymsp[-8].minor.yy0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy562, yymsp[0].minor.yy303, yymsp[-7].minor.yy64, yymsp[-5].minor.yy64); } break; case 83: /* cmd ::= DROP VIEW ifexists fullname */ { - sqlite3DropTable(pParse, yymsp[0].minor.yy131, 1, yymsp[-1].minor.yy394); + sqlite3DropTable(pParse, yymsp[0].minor.yy607, 1, yymsp[-1].minor.yy64); } break; case 84: /* cmd ::= select */ { SelectDest dest = {SRT_Output, 0, 0, 0, 0, 0, 0}; - sqlite3Select(pParse, yymsp[0].minor.yy47, &dest); - sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy47); + sqlite3Select(pParse, yymsp[0].minor.yy303, &dest); + sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy303); } break; case 85: /* select ::= WITH wqlist selectnowith */ -{yymsp[-2].minor.yy47 = attachWithToSelect(pParse,yymsp[0].minor.yy47,yymsp[-1].minor.yy521);} +{yymsp[-2].minor.yy303 = attachWithToSelect(pParse,yymsp[0].minor.yy303,yymsp[-1].minor.yy43);} break; case 86: /* select ::= WITH RECURSIVE wqlist selectnowith */ -{yymsp[-3].minor.yy47 = attachWithToSelect(pParse,yymsp[0].minor.yy47,yymsp[-1].minor.yy521);} +{yymsp[-3].minor.yy303 = attachWithToSelect(pParse,yymsp[0].minor.yy303,yymsp[-1].minor.yy43);} break; case 87: /* select ::= selectnowith */ { - Select *p = yymsp[0].minor.yy47; + Select *p = yymsp[0].minor.yy303; if( p ){ parserDoubleLinkSelect(pParse, p); } - yymsp[0].minor.yy47 = p; /*A-overwrites-X*/ + yymsp[0].minor.yy303 = p; /*A-overwrites-X*/ } break; case 88: /* selectnowith ::= selectnowith multiselect_op oneselect */ { - Select *pRhs = yymsp[0].minor.yy47; - Select *pLhs = yymsp[-2].minor.yy47; + Select *pRhs = yymsp[0].minor.yy303; + Select *pLhs = yymsp[-2].minor.yy303; if( pRhs && pRhs->pPrior ){ SrcList *pFrom; Token x; x.n = 0; parserDoubleLinkSelect(pParse, pRhs); pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0); pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0); } if( pRhs ){ - pRhs->op = (u8)yymsp[-1].minor.yy394; + pRhs->op = (u8)yymsp[-1].minor.yy64; pRhs->pPrior = pLhs; if( ALWAYS(pLhs) ) pLhs->selFlags &= ~SF_MultiValue; pRhs->selFlags &= ~SF_MultiValue; - if( yymsp[-1].minor.yy394!=TK_ALL ) pParse->hasCompound = 1; + if( yymsp[-1].minor.yy64!=TK_ALL ) pParse->hasCompound = 1; }else{ sqlite3SelectDelete(pParse->db, pLhs); } - yymsp[-2].minor.yy47 = pRhs; + yymsp[-2].minor.yy303 = pRhs; } break; case 89: /* multiselect_op ::= UNION */ case 91: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==91); -{yymsp[0].minor.yy394 = yymsp[0].major; /*A-overwrites-OP*/} +{yymsp[0].minor.yy64 = yymsp[0].major; /*A-overwrites-OP*/} break; case 90: /* multiselect_op ::= UNION ALL */ -{yymsp[-1].minor.yy394 = TK_ALL;} +{yymsp[-1].minor.yy64 = TK_ALL;} break; case 92: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */ { - yymsp[-8].minor.yy47 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy322,yymsp[-5].minor.yy131,yymsp[-4].minor.yy528,yymsp[-3].minor.yy322,yymsp[-2].minor.yy528,yymsp[-1].minor.yy322,yymsp[-7].minor.yy394,yymsp[0].minor.yy528); + yymsp[-8].minor.yy303 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy562,yymsp[-5].minor.yy607,yymsp[-4].minor.yy626,yymsp[-3].minor.yy562,yymsp[-2].minor.yy626,yymsp[-1].minor.yy562,yymsp[-7].minor.yy64,yymsp[0].minor.yy626); } break; case 93: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt window_clause orderby_opt limit_opt */ { - yymsp[-9].minor.yy47 = sqlite3SelectNew(pParse,yymsp[-7].minor.yy322,yymsp[-6].minor.yy131,yymsp[-5].minor.yy528,yymsp[-4].minor.yy322,yymsp[-3].minor.yy528,yymsp[-1].minor.yy322,yymsp[-8].minor.yy394,yymsp[0].minor.yy528); - if( yymsp[-9].minor.yy47 ){ - yymsp[-9].minor.yy47->pWinDefn = yymsp[-2].minor.yy41; + yymsp[-9].minor.yy303 = sqlite3SelectNew(pParse,yymsp[-7].minor.yy562,yymsp[-6].minor.yy607,yymsp[-5].minor.yy626,yymsp[-4].minor.yy562,yymsp[-3].minor.yy626,yymsp[-1].minor.yy562,yymsp[-8].minor.yy64,yymsp[0].minor.yy626); + if( yymsp[-9].minor.yy303 ){ + yymsp[-9].minor.yy303->pWinDefn = yymsp[-2].minor.yy375; }else{ - sqlite3WindowListDelete(pParse->db, yymsp[-2].minor.yy41); + sqlite3WindowListDelete(pParse->db, yymsp[-2].minor.yy375); } } break; case 94: /* values ::= VALUES LP nexprlist RP */ { - yymsp[-3].minor.yy47 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy322,0,0,0,0,0,SF_Values,0); + yymsp[-3].minor.yy303 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy562,0,0,0,0,0,SF_Values,0); } break; case 95: /* values ::= values COMMA LP nexprlist RP */ { - Select *pRight, *pLeft = yymsp[-4].minor.yy47; - pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy322,0,0,0,0,0,SF_Values|SF_MultiValue,0); + Select *pRight, *pLeft = yymsp[-4].minor.yy303; + pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy562,0,0,0,0,0,SF_Values|SF_MultiValue,0); if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue; if( pRight ){ pRight->op = TK_ALL; pRight->pPrior = pLeft; - yymsp[-4].minor.yy47 = pRight; + yymsp[-4].minor.yy303 = pRight; }else{ - yymsp[-4].minor.yy47 = pLeft; + yymsp[-4].minor.yy303 = pLeft; } } break; case 96: /* distinct ::= DISTINCT */ -{yymsp[0].minor.yy394 = SF_Distinct;} +{yymsp[0].minor.yy64 = SF_Distinct;} break; case 97: /* distinct ::= ALL */ -{yymsp[0].minor.yy394 = SF_All;} +{yymsp[0].minor.yy64 = SF_All;} break; case 99: /* sclp ::= */ case 132: /* orderby_opt ::= */ yytestcase(yyruleno==132); case 142: /* groupby_opt ::= */ yytestcase(yyruleno==142); - case 230: /* exprlist ::= */ yytestcase(yyruleno==230); - case 233: /* paren_exprlist ::= */ yytestcase(yyruleno==233); - case 238: /* eidlist_opt ::= */ yytestcase(yyruleno==238); -{yymsp[1].minor.yy322 = 0;} + case 229: /* exprlist ::= */ yytestcase(yyruleno==229); + case 232: /* paren_exprlist ::= */ yytestcase(yyruleno==232); + case 237: /* eidlist_opt ::= */ yytestcase(yyruleno==237); +{yymsp[1].minor.yy562 = 0;} break; case 100: /* selcollist ::= sclp scanpt expr scanpt as */ { - yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[-2].minor.yy528); - if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy322, &yymsp[0].minor.yy0, 1); - sqlite3ExprListSetSpan(pParse,yymsp[-4].minor.yy322,yymsp[-3].minor.yy522,yymsp[-1].minor.yy522); + yymsp[-4].minor.yy562 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy562, yymsp[-2].minor.yy626); + if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy562, &yymsp[0].minor.yy0, 1); + sqlite3ExprListSetSpan(pParse,yymsp[-4].minor.yy562,yymsp[-3].minor.yy600,yymsp[-1].minor.yy600); } break; case 101: /* selcollist ::= sclp scanpt STAR */ { Expr *p = sqlite3Expr(pParse->db, TK_ASTERISK, 0); - yymsp[-2].minor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy322, p); + yymsp[-2].minor.yy562 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy562, p); } break; case 102: /* selcollist ::= sclp scanpt nm DOT STAR */ { Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0); - Expr *pLeft = tokenExpr(pParse, TK_ID, yymsp[-2].minor.yy0); + Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1); Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight); - yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, pDot); + yymsp[-4].minor.yy562 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy562, pDot); } break; case 103: /* as ::= AS nm */ case 114: /* dbnm ::= DOT nm */ yytestcase(yyruleno==114); - case 254: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==254); - case 255: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==255); + case 253: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==253); + case 254: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==254); {yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;} break; case 105: /* from ::= */ case 108: /* stl_prefix ::= */ yytestcase(yyruleno==108); -{yymsp[1].minor.yy131 = 0;} +{yymsp[1].minor.yy607 = 0;} break; case 106: /* from ::= FROM seltablist */ { - yymsp[-1].minor.yy131 = yymsp[0].minor.yy131; - sqlite3SrcListShiftJoinType(yymsp[-1].minor.yy131); + yymsp[-1].minor.yy607 = yymsp[0].minor.yy607; + sqlite3SrcListShiftJoinType(yymsp[-1].minor.yy607); } break; case 107: /* stl_prefix ::= seltablist joinop */ { - if( ALWAYS(yymsp[-1].minor.yy131 && yymsp[-1].minor.yy131->nSrc>0) ) yymsp[-1].minor.yy131->a[yymsp[-1].minor.yy131->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy394; + if( ALWAYS(yymsp[-1].minor.yy607 && yymsp[-1].minor.yy607->nSrc>0) ) yymsp[-1].minor.yy607->a[yymsp[-1].minor.yy607->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy64; } break; case 109: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */ { - yymsp[-6].minor.yy131 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy131,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy528,yymsp[0].minor.yy254); - sqlite3SrcListIndexedBy(pParse, yymsp[-6].minor.yy131, &yymsp[-2].minor.yy0); + yymsp[-6].minor.yy607 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy607,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy626,yymsp[0].minor.yy240); + sqlite3SrcListIndexedBy(pParse, yymsp[-6].minor.yy607, &yymsp[-2].minor.yy0); } break; case 110: /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */ { - yymsp[-8].minor.yy131 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-8].minor.yy131,&yymsp[-7].minor.yy0,&yymsp[-6].minor.yy0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy528,yymsp[0].minor.yy254); - sqlite3SrcListFuncArgs(pParse, yymsp[-8].minor.yy131, yymsp[-4].minor.yy322); + yymsp[-8].minor.yy607 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-8].minor.yy607,&yymsp[-7].minor.yy0,&yymsp[-6].minor.yy0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy626,yymsp[0].minor.yy240); + sqlite3SrcListFuncArgs(pParse, yymsp[-8].minor.yy607, yymsp[-4].minor.yy562); } break; case 111: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */ { - yymsp[-6].minor.yy131 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy131,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy47,yymsp[-1].minor.yy528,yymsp[0].minor.yy254); + yymsp[-6].minor.yy607 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy607,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy303,yymsp[-1].minor.yy626,yymsp[0].minor.yy240); } break; case 112: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */ { - if( yymsp[-6].minor.yy131==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy528==0 && yymsp[0].minor.yy254==0 ){ - yymsp[-6].minor.yy131 = yymsp[-4].minor.yy131; - }else if( yymsp[-4].minor.yy131->nSrc==1 ){ - yymsp[-6].minor.yy131 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy131,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy528,yymsp[0].minor.yy254); - if( yymsp[-6].minor.yy131 ){ - SrcItem *pNew = &yymsp[-6].minor.yy131->a[yymsp[-6].minor.yy131->nSrc-1]; - SrcItem *pOld = yymsp[-4].minor.yy131->a; + if( yymsp[-6].minor.yy607==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy626==0 && yymsp[0].minor.yy240==0 ){ + yymsp[-6].minor.yy607 = yymsp[-4].minor.yy607; + }else if( yymsp[-4].minor.yy607->nSrc==1 ){ + yymsp[-6].minor.yy607 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy607,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy626,yymsp[0].minor.yy240); + if( yymsp[-6].minor.yy607 ){ + SrcItem *pNew = &yymsp[-6].minor.yy607->a[yymsp[-6].minor.yy607->nSrc-1]; + SrcItem *pOld = yymsp[-4].minor.yy607->a; pNew->zName = pOld->zName; pNew->zDatabase = pOld->zDatabase; pNew->pSelect = pOld->pSelect; if( pOld->fg.isTabFunc ){ pNew->u1.pFuncArg = pOld->u1.pFuncArg; @@ -165448,1013 +162715,1009 @@ pNew->fg.isTabFunc = 1; } pOld->zName = pOld->zDatabase = 0; pOld->pSelect = 0; } - sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy131); + sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy607); }else{ Select *pSubquery; - sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy131); - pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy131,0,0,0,0,SF_NestedFrom,0); - yymsp[-6].minor.yy131 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy131,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy528,yymsp[0].minor.yy254); + sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy607); + pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy607,0,0,0,0,SF_NestedFrom,0); + yymsp[-6].minor.yy607 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy607,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy626,yymsp[0].minor.yy240); } } break; case 113: /* dbnm ::= */ case 127: /* indexed_opt ::= */ yytestcase(yyruleno==127); {yymsp[1].minor.yy0.z=0; yymsp[1].minor.yy0.n=0;} break; case 115: /* fullname ::= nm */ { - yylhsminor.yy131 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0); - if( IN_RENAME_OBJECT && yylhsminor.yy131 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy131->a[0].zName, &yymsp[0].minor.yy0); + yylhsminor.yy607 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0); + if( IN_RENAME_OBJECT && yylhsminor.yy607 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy607->a[0].zName, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy131 = yylhsminor.yy131; + yymsp[0].minor.yy607 = yylhsminor.yy607; break; case 116: /* fullname ::= nm DOT nm */ { - yylhsminor.yy131 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); - if( IN_RENAME_OBJECT && yylhsminor.yy131 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy131->a[0].zName, &yymsp[0].minor.yy0); + yylhsminor.yy607 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); + if( IN_RENAME_OBJECT && yylhsminor.yy607 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy607->a[0].zName, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy131 = yylhsminor.yy131; + yymsp[-2].minor.yy607 = yylhsminor.yy607; break; case 117: /* xfullname ::= nm */ -{yymsp[0].minor.yy131 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0); /*A-overwrites-X*/} +{yymsp[0].minor.yy607 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0); /*A-overwrites-X*/} break; case 118: /* xfullname ::= nm DOT nm */ -{yymsp[-2].minor.yy131 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/} +{yymsp[-2].minor.yy607 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/} break; case 119: /* xfullname ::= nm DOT nm AS nm */ { - yymsp[-4].minor.yy131 = sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,&yymsp[-2].minor.yy0); /*A-overwrites-X*/ - if( yymsp[-4].minor.yy131 ) yymsp[-4].minor.yy131->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0); + yymsp[-4].minor.yy607 = sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,&yymsp[-2].minor.yy0); /*A-overwrites-X*/ + if( yymsp[-4].minor.yy607 ) yymsp[-4].minor.yy607->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0); } break; case 120: /* xfullname ::= nm AS nm */ { - yymsp[-2].minor.yy131 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,0); /*A-overwrites-X*/ - if( yymsp[-2].minor.yy131 ) yymsp[-2].minor.yy131->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0); + yymsp[-2].minor.yy607 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,0); /*A-overwrites-X*/ + if( yymsp[-2].minor.yy607 ) yymsp[-2].minor.yy607->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0); } break; case 121: /* joinop ::= COMMA|JOIN */ -{ yymsp[0].minor.yy394 = JT_INNER; } +{ yymsp[0].minor.yy64 = JT_INNER; } break; case 122: /* joinop ::= JOIN_KW JOIN */ -{yymsp[-1].minor.yy394 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); /*X-overwrites-A*/} +{yymsp[-1].minor.yy64 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); /*X-overwrites-A*/} break; case 123: /* joinop ::= JOIN_KW nm JOIN */ -{yymsp[-2].minor.yy394 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-overwrites-A*/} +{yymsp[-2].minor.yy64 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-overwrites-A*/} break; case 124: /* joinop ::= JOIN_KW nm nm JOIN */ -{yymsp[-3].minor.yy394 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/} +{yymsp[-3].minor.yy64 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/} break; case 125: /* on_opt ::= ON expr */ case 145: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==145); case 152: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==152); case 154: /* where_opt_ret ::= WHERE expr */ yytestcase(yyruleno==154); - case 226: /* case_else ::= ELSE expr */ yytestcase(yyruleno==226); - case 247: /* vinto ::= INTO expr */ yytestcase(yyruleno==247); -{yymsp[-1].minor.yy528 = yymsp[0].minor.yy528;} + case 225: /* case_else ::= ELSE expr */ yytestcase(yyruleno==225); + case 246: /* vinto ::= INTO expr */ yytestcase(yyruleno==246); +{yymsp[-1].minor.yy626 = yymsp[0].minor.yy626;} break; case 126: /* on_opt ::= */ case 144: /* having_opt ::= */ yytestcase(yyruleno==144); case 146: /* limit_opt ::= */ yytestcase(yyruleno==146); case 151: /* where_opt ::= */ yytestcase(yyruleno==151); case 153: /* where_opt_ret ::= */ yytestcase(yyruleno==153); - case 227: /* case_else ::= */ yytestcase(yyruleno==227); - case 229: /* case_operand ::= */ yytestcase(yyruleno==229); - case 248: /* vinto ::= */ yytestcase(yyruleno==248); -{yymsp[1].minor.yy528 = 0;} + case 226: /* case_else ::= */ yytestcase(yyruleno==226); + case 228: /* case_operand ::= */ yytestcase(yyruleno==228); + case 247: /* vinto ::= */ yytestcase(yyruleno==247); +{yymsp[1].minor.yy626 = 0;} break; case 128: /* indexed_opt ::= INDEXED BY nm */ {yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;} break; case 129: /* indexed_opt ::= NOT INDEXED */ {yymsp[-1].minor.yy0.z=0; yymsp[-1].minor.yy0.n=1;} break; case 130: /* using_opt ::= USING LP idlist RP */ -{yymsp[-3].minor.yy254 = yymsp[-1].minor.yy254;} +{yymsp[-3].minor.yy240 = yymsp[-1].minor.yy240;} break; case 131: /* using_opt ::= */ case 173: /* idlist_opt ::= */ yytestcase(yyruleno==173); -{yymsp[1].minor.yy254 = 0;} +{yymsp[1].minor.yy240 = 0;} break; case 133: /* orderby_opt ::= ORDER BY sortlist */ case 143: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==143); -{yymsp[-2].minor.yy322 = yymsp[0].minor.yy322;} +{yymsp[-2].minor.yy562 = yymsp[0].minor.yy562;} break; case 134: /* sortlist ::= sortlist COMMA expr sortorder nulls */ { - yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322,yymsp[-2].minor.yy528); - sqlite3ExprListSetSortOrder(yymsp[-4].minor.yy322,yymsp[-1].minor.yy394,yymsp[0].minor.yy394); + yymsp[-4].minor.yy562 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy562,yymsp[-2].minor.yy626); + sqlite3ExprListSetSortOrder(yymsp[-4].minor.yy562,yymsp[-1].minor.yy64,yymsp[0].minor.yy64); } break; case 135: /* sortlist ::= expr sortorder nulls */ { - yymsp[-2].minor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[-2].minor.yy528); /*A-overwrites-Y*/ - sqlite3ExprListSetSortOrder(yymsp[-2].minor.yy322,yymsp[-1].minor.yy394,yymsp[0].minor.yy394); + yymsp[-2].minor.yy562 = sqlite3ExprListAppend(pParse,0,yymsp[-2].minor.yy626); /*A-overwrites-Y*/ + sqlite3ExprListSetSortOrder(yymsp[-2].minor.yy562,yymsp[-1].minor.yy64,yymsp[0].minor.yy64); } break; case 136: /* sortorder ::= ASC */ -{yymsp[0].minor.yy394 = SQLITE_SO_ASC;} +{yymsp[0].minor.yy64 = SQLITE_SO_ASC;} break; case 137: /* sortorder ::= DESC */ -{yymsp[0].minor.yy394 = SQLITE_SO_DESC;} +{yymsp[0].minor.yy64 = SQLITE_SO_DESC;} break; case 138: /* sortorder ::= */ case 141: /* nulls ::= */ yytestcase(yyruleno==141); -{yymsp[1].minor.yy394 = SQLITE_SO_UNDEFINED;} +{yymsp[1].minor.yy64 = SQLITE_SO_UNDEFINED;} break; case 139: /* nulls ::= NULLS FIRST */ -{yymsp[-1].minor.yy394 = SQLITE_SO_ASC;} +{yymsp[-1].minor.yy64 = SQLITE_SO_ASC;} break; case 140: /* nulls ::= NULLS LAST */ -{yymsp[-1].minor.yy394 = SQLITE_SO_DESC;} +{yymsp[-1].minor.yy64 = SQLITE_SO_DESC;} break; case 147: /* limit_opt ::= LIMIT expr */ -{yymsp[-1].minor.yy528 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy528,0);} +{yymsp[-1].minor.yy626 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy626,0);} break; case 148: /* limit_opt ::= LIMIT expr OFFSET expr */ -{yymsp[-3].minor.yy528 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy528,yymsp[0].minor.yy528);} +{yymsp[-3].minor.yy626 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy626,yymsp[0].minor.yy626);} break; case 149: /* limit_opt ::= LIMIT expr COMMA expr */ -{yymsp[-3].minor.yy528 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy528,yymsp[-2].minor.yy528);} +{yymsp[-3].minor.yy626 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy626,yymsp[-2].minor.yy626);} break; case 150: /* cmd ::= with DELETE FROM xfullname indexed_opt where_opt_ret */ { - sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy131, &yymsp[-1].minor.yy0); - sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy131,yymsp[0].minor.yy528,0,0); + sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy607, &yymsp[-1].minor.yy0); + sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy607,yymsp[0].minor.yy626,0,0); } break; case 155: /* where_opt_ret ::= RETURNING selcollist */ -{sqlite3AddReturning(pParse,yymsp[0].minor.yy322); yymsp[-1].minor.yy528 = 0;} +{sqlite3AddReturning(pParse,yymsp[0].minor.yy562); yymsp[-1].minor.yy626 = 0;} break; case 156: /* where_opt_ret ::= WHERE expr RETURNING selcollist */ -{sqlite3AddReturning(pParse,yymsp[0].minor.yy322); yymsp[-3].minor.yy528 = yymsp[-2].minor.yy528;} +{sqlite3AddReturning(pParse,yymsp[0].minor.yy562); yymsp[-3].minor.yy626 = yymsp[-2].minor.yy626;} break; case 157: /* cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist from where_opt_ret */ { - sqlite3SrcListIndexedBy(pParse, yymsp[-5].minor.yy131, &yymsp[-4].minor.yy0); - sqlite3ExprListCheckLength(pParse,yymsp[-2].minor.yy322,"set list"); - yymsp[-5].minor.yy131 = sqlite3SrcListAppendList(pParse, yymsp[-5].minor.yy131, yymsp[-1].minor.yy131); - sqlite3Update(pParse,yymsp[-5].minor.yy131,yymsp[-2].minor.yy322,yymsp[0].minor.yy528,yymsp[-6].minor.yy394,0,0,0); + sqlite3SrcListIndexedBy(pParse, yymsp[-5].minor.yy607, &yymsp[-4].minor.yy0); + sqlite3ExprListCheckLength(pParse,yymsp[-2].minor.yy562,"set list"); + yymsp[-5].minor.yy607 = sqlite3SrcListAppendList(pParse, yymsp[-5].minor.yy607, yymsp[-1].minor.yy607); + sqlite3Update(pParse,yymsp[-5].minor.yy607,yymsp[-2].minor.yy562,yymsp[0].minor.yy626,yymsp[-6].minor.yy64,0,0,0); } break; case 158: /* setlist ::= setlist COMMA nm EQ expr */ { - yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[0].minor.yy528); - sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy322, &yymsp[-2].minor.yy0, 1); + yymsp[-4].minor.yy562 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy562, yymsp[0].minor.yy626); + sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy562, &yymsp[-2].minor.yy0, 1); } break; case 159: /* setlist ::= setlist COMMA LP idlist RP EQ expr */ { - yymsp[-6].minor.yy322 = sqlite3ExprListAppendVector(pParse, yymsp[-6].minor.yy322, yymsp[-3].minor.yy254, yymsp[0].minor.yy528); + yymsp[-6].minor.yy562 = sqlite3ExprListAppendVector(pParse, yymsp[-6].minor.yy562, yymsp[-3].minor.yy240, yymsp[0].minor.yy626); } break; case 160: /* setlist ::= nm EQ expr */ { - yylhsminor.yy322 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy528); - sqlite3ExprListSetName(pParse, yylhsminor.yy322, &yymsp[-2].minor.yy0, 1); + yylhsminor.yy562 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy626); + sqlite3ExprListSetName(pParse, yylhsminor.yy562, &yymsp[-2].minor.yy0, 1); } - yymsp[-2].minor.yy322 = yylhsminor.yy322; + yymsp[-2].minor.yy562 = yylhsminor.yy562; break; case 161: /* setlist ::= LP idlist RP EQ expr */ { - yymsp[-4].minor.yy322 = sqlite3ExprListAppendVector(pParse, 0, yymsp[-3].minor.yy254, yymsp[0].minor.yy528); + yymsp[-4].minor.yy562 = sqlite3ExprListAppendVector(pParse, 0, yymsp[-3].minor.yy240, yymsp[0].minor.yy626); } break; case 162: /* cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */ { - sqlite3Insert(pParse, yymsp[-3].minor.yy131, yymsp[-1].minor.yy47, yymsp[-2].minor.yy254, yymsp[-5].minor.yy394, yymsp[0].minor.yy444); + sqlite3Insert(pParse, yymsp[-3].minor.yy607, yymsp[-1].minor.yy303, yymsp[-2].minor.yy240, yymsp[-5].minor.yy64, yymsp[0].minor.yy138); } break; case 163: /* cmd ::= with insert_cmd INTO xfullname idlist_opt DEFAULT VALUES returning */ { - sqlite3Insert(pParse, yymsp[-4].minor.yy131, 0, yymsp[-3].minor.yy254, yymsp[-6].minor.yy394, 0); + sqlite3Insert(pParse, yymsp[-4].minor.yy607, 0, yymsp[-3].minor.yy240, yymsp[-6].minor.yy64, 0); } break; case 164: /* upsert ::= */ -{ yymsp[1].minor.yy444 = 0; } +{ yymsp[1].minor.yy138 = 0; } break; case 165: /* upsert ::= RETURNING selcollist */ -{ yymsp[-1].minor.yy444 = 0; sqlite3AddReturning(pParse,yymsp[0].minor.yy322); } +{ yymsp[-1].minor.yy138 = 0; sqlite3AddReturning(pParse,yymsp[0].minor.yy562); } break; case 166: /* upsert ::= ON CONFLICT LP sortlist RP where_opt DO UPDATE SET setlist where_opt upsert */ -{ yymsp[-11].minor.yy444 = sqlite3UpsertNew(pParse->db,yymsp[-8].minor.yy322,yymsp[-6].minor.yy528,yymsp[-2].minor.yy322,yymsp[-1].minor.yy528,yymsp[0].minor.yy444);} +{ yymsp[-11].minor.yy138 = sqlite3UpsertNew(pParse->db,yymsp[-8].minor.yy562,yymsp[-6].minor.yy626,yymsp[-2].minor.yy562,yymsp[-1].minor.yy626,yymsp[0].minor.yy138);} break; case 167: /* upsert ::= ON CONFLICT LP sortlist RP where_opt DO NOTHING upsert */ -{ yymsp[-8].minor.yy444 = sqlite3UpsertNew(pParse->db,yymsp[-5].minor.yy322,yymsp[-3].minor.yy528,0,0,yymsp[0].minor.yy444); } +{ yymsp[-8].minor.yy138 = sqlite3UpsertNew(pParse->db,yymsp[-5].minor.yy562,yymsp[-3].minor.yy626,0,0,yymsp[0].minor.yy138); } break; case 168: /* upsert ::= ON CONFLICT DO NOTHING returning */ -{ yymsp[-4].minor.yy444 = sqlite3UpsertNew(pParse->db,0,0,0,0,0); } +{ yymsp[-4].minor.yy138 = sqlite3UpsertNew(pParse->db,0,0,0,0,0); } break; case 169: /* upsert ::= ON CONFLICT DO UPDATE SET setlist where_opt returning */ -{ yymsp[-7].minor.yy444 = sqlite3UpsertNew(pParse->db,0,0,yymsp[-2].minor.yy322,yymsp[-1].minor.yy528,0);} +{ yymsp[-7].minor.yy138 = sqlite3UpsertNew(pParse->db,0,0,yymsp[-2].minor.yy562,yymsp[-1].minor.yy626,0);} break; case 170: /* returning ::= RETURNING selcollist */ -{sqlite3AddReturning(pParse,yymsp[0].minor.yy322);} +{sqlite3AddReturning(pParse,yymsp[0].minor.yy562);} break; case 174: /* idlist_opt ::= LP idlist RP */ -{yymsp[-2].minor.yy254 = yymsp[-1].minor.yy254;} +{yymsp[-2].minor.yy240 = yymsp[-1].minor.yy240;} break; case 175: /* idlist ::= idlist COMMA nm */ -{yymsp[-2].minor.yy254 = sqlite3IdListAppend(pParse,yymsp[-2].minor.yy254,&yymsp[0].minor.yy0);} +{yymsp[-2].minor.yy240 = sqlite3IdListAppend(pParse,yymsp[-2].minor.yy240,&yymsp[0].minor.yy0);} break; case 176: /* idlist ::= nm */ -{yymsp[0].minor.yy254 = sqlite3IdListAppend(pParse,0,&yymsp[0].minor.yy0); /*A-overwrites-Y*/} +{yymsp[0].minor.yy240 = sqlite3IdListAppend(pParse,0,&yymsp[0].minor.yy0); /*A-overwrites-Y*/} break; case 177: /* expr ::= LP expr RP */ -{yymsp[-2].minor.yy528 = yymsp[-1].minor.yy528;} +{yymsp[-2].minor.yy626 = yymsp[-1].minor.yy626;} break; case 178: /* expr ::= ID|INDEXED */ case 179: /* expr ::= JOIN_KW */ yytestcase(yyruleno==179); -{yymsp[0].minor.yy528=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/} +{yymsp[0].minor.yy626=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/} break; case 180: /* expr ::= nm DOT nm */ { - Expr *temp1 = tokenExpr(pParse,TK_ID,yymsp[-2].minor.yy0); - Expr *temp2 = tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); - yylhsminor.yy528 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2); + Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1); + Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1); + if( IN_RENAME_OBJECT ){ + sqlite3RenameTokenMap(pParse, (void*)temp2, &yymsp[0].minor.yy0); + sqlite3RenameTokenMap(pParse, (void*)temp1, &yymsp[-2].minor.yy0); + } + yylhsminor.yy626 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2); } - yymsp[-2].minor.yy528 = yylhsminor.yy528; + yymsp[-2].minor.yy626 = yylhsminor.yy626; break; case 181: /* expr ::= nm DOT nm DOT nm */ { - Expr *temp1 = tokenExpr(pParse,TK_ID,yymsp[-4].minor.yy0); - Expr *temp2 = tokenExpr(pParse,TK_ID,yymsp[-2].minor.yy0); - Expr *temp3 = tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); + Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-4].minor.yy0, 1); + Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1); + Expr *temp3 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1); Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3); if( IN_RENAME_OBJECT ){ - sqlite3RenameTokenRemap(pParse, 0, temp1); + sqlite3RenameTokenMap(pParse, (void*)temp3, &yymsp[0].minor.yy0); + sqlite3RenameTokenMap(pParse, (void*)temp2, &yymsp[-2].minor.yy0); } - yylhsminor.yy528 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4); + yylhsminor.yy626 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4); } - yymsp[-4].minor.yy528 = yylhsminor.yy528; + yymsp[-4].minor.yy626 = yylhsminor.yy626; break; case 182: /* term ::= NULL|FLOAT|BLOB */ case 183: /* term ::= STRING */ yytestcase(yyruleno==183); -{yymsp[0].minor.yy528=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/} +{yymsp[0].minor.yy626=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/} break; case 184: /* term ::= INTEGER */ { - yylhsminor.yy528 = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1); - if( yylhsminor.yy528 ) yylhsminor.yy528->w.iOfst = (int)(yymsp[0].minor.yy0.z - pParse->zTail); + yylhsminor.yy626 = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1); } - yymsp[0].minor.yy528 = yylhsminor.yy528; + yymsp[0].minor.yy626 = yylhsminor.yy626; break; case 185: /* expr ::= VARIABLE */ { if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){ u32 n = yymsp[0].minor.yy0.n; - yymsp[0].minor.yy528 = tokenExpr(pParse, TK_VARIABLE, yymsp[0].minor.yy0); - sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy528, n); + yymsp[0].minor.yy626 = tokenExpr(pParse, TK_VARIABLE, yymsp[0].minor.yy0); + sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy626, n); }else{ /* When doing a nested parse, one can include terms in an expression ** that look like this: #1 #2 ... These terms refer to registers ** in the virtual machine. #N is the N-th register. */ Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/ assert( t.n>=2 ); if( pParse->nested==0 ){ sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t); - yymsp[0].minor.yy528 = 0; + yymsp[0].minor.yy626 = 0; }else{ - yymsp[0].minor.yy528 = sqlite3PExpr(pParse, TK_REGISTER, 0, 0); - if( yymsp[0].minor.yy528 ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy528->iTable); + yymsp[0].minor.yy626 = sqlite3PExpr(pParse, TK_REGISTER, 0, 0); + if( yymsp[0].minor.yy626 ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy626->iTable); } } } break; case 186: /* expr ::= expr COLLATE ID|STRING */ { - yymsp[-2].minor.yy528 = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy528, &yymsp[0].minor.yy0, 1); + yymsp[-2].minor.yy626 = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy626, &yymsp[0].minor.yy0, 1); } break; case 187: /* expr ::= CAST LP expr AS typetoken RP */ { - yymsp[-5].minor.yy528 = sqlite3ExprAlloc(pParse->db, TK_CAST, &yymsp[-1].minor.yy0, 1); - sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy528, yymsp[-3].minor.yy528, 0); + yymsp[-5].minor.yy626 = sqlite3ExprAlloc(pParse->db, TK_CAST, &yymsp[-1].minor.yy0, 1); + sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy626, yymsp[-3].minor.yy626, 0); } break; case 188: /* expr ::= ID|INDEXED LP distinct exprlist RP */ { - yylhsminor.yy528 = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy322, &yymsp[-4].minor.yy0, yymsp[-2].minor.yy394); + yylhsminor.yy626 = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy562, &yymsp[-4].minor.yy0, yymsp[-2].minor.yy64); } - yymsp[-4].minor.yy528 = yylhsminor.yy528; + yymsp[-4].minor.yy626 = yylhsminor.yy626; break; case 189: /* expr ::= ID|INDEXED LP STAR RP */ { - yylhsminor.yy528 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0, 0); + yylhsminor.yy626 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0, 0); } - yymsp[-3].minor.yy528 = yylhsminor.yy528; + yymsp[-3].minor.yy626 = yylhsminor.yy626; break; case 190: /* expr ::= ID|INDEXED LP distinct exprlist RP filter_over */ { - yylhsminor.yy528 = sqlite3ExprFunction(pParse, yymsp[-2].minor.yy322, &yymsp[-5].minor.yy0, yymsp[-3].minor.yy394); - sqlite3WindowAttach(pParse, yylhsminor.yy528, yymsp[0].minor.yy41); + yylhsminor.yy626 = sqlite3ExprFunction(pParse, yymsp[-2].minor.yy562, &yymsp[-5].minor.yy0, yymsp[-3].minor.yy64); + sqlite3WindowAttach(pParse, yylhsminor.yy626, yymsp[0].minor.yy375); } - yymsp[-5].minor.yy528 = yylhsminor.yy528; + yymsp[-5].minor.yy626 = yylhsminor.yy626; break; case 191: /* expr ::= ID|INDEXED LP STAR RP filter_over */ { - yylhsminor.yy528 = sqlite3ExprFunction(pParse, 0, &yymsp[-4].minor.yy0, 0); - sqlite3WindowAttach(pParse, yylhsminor.yy528, yymsp[0].minor.yy41); + yylhsminor.yy626 = sqlite3ExprFunction(pParse, 0, &yymsp[-4].minor.yy0, 0); + sqlite3WindowAttach(pParse, yylhsminor.yy626, yymsp[0].minor.yy375); } - yymsp[-4].minor.yy528 = yylhsminor.yy528; + yymsp[-4].minor.yy626 = yylhsminor.yy626; break; case 192: /* term ::= CTIME_KW */ { - yylhsminor.yy528 = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0, 0); + yylhsminor.yy626 = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0, 0); } - yymsp[0].minor.yy528 = yylhsminor.yy528; + yymsp[0].minor.yy626 = yylhsminor.yy626; break; case 193: /* expr ::= LP nexprlist COMMA expr RP */ { - ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy322, yymsp[-1].minor.yy528); - yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0); - if( yymsp[-4].minor.yy528 ){ - yymsp[-4].minor.yy528->x.pList = pList; + ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy562, yymsp[-1].minor.yy626); + yymsp[-4].minor.yy626 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0); + if( yymsp[-4].minor.yy626 ){ + yymsp[-4].minor.yy626->x.pList = pList; if( ALWAYS(pList->nExpr) ){ - yymsp[-4].minor.yy528->flags |= pList->a[0].pExpr->flags & EP_Propagate; + yymsp[-4].minor.yy626->flags |= pList->a[0].pExpr->flags & EP_Propagate; } }else{ sqlite3ExprListDelete(pParse->db, pList); } } break; case 194: /* expr ::= expr AND expr */ -{yymsp[-2].minor.yy528=sqlite3ExprAnd(pParse,yymsp[-2].minor.yy528,yymsp[0].minor.yy528);} +{yymsp[-2].minor.yy626=sqlite3ExprAnd(pParse,yymsp[-2].minor.yy626,yymsp[0].minor.yy626);} break; case 195: /* expr ::= expr OR expr */ case 196: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==196); case 197: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==197); case 198: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==198); case 199: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==199); case 200: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==200); case 201: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==201); -{yymsp[-2].minor.yy528=sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy528,yymsp[0].minor.yy528);} +{yymsp[-2].minor.yy626=sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy626,yymsp[0].minor.yy626);} break; case 202: /* likeop ::= NOT LIKE_KW|MATCH */ {yymsp[-1].minor.yy0=yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n|=0x80000000; /*yymsp[-1].minor.yy0-overwrite-yymsp[0].minor.yy0*/} break; case 203: /* expr ::= expr likeop expr */ { ExprList *pList; int bNot = yymsp[-1].minor.yy0.n & 0x80000000; yymsp[-1].minor.yy0.n &= 0x7fffffff; - pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy528); - pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy528); - yymsp[-2].minor.yy528 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0, 0); - if( bNot ) yymsp[-2].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-2].minor.yy528, 0); - if( yymsp[-2].minor.yy528 ) yymsp[-2].minor.yy528->flags |= EP_InfixFunc; + pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy626); + pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy626); + yymsp[-2].minor.yy626 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0, 0); + if( bNot ) yymsp[-2].minor.yy626 = sqlite3PExpr(pParse, TK_NOT, yymsp[-2].minor.yy626, 0); + if( yymsp[-2].minor.yy626 ) yymsp[-2].minor.yy626->flags |= EP_InfixFunc; } break; case 204: /* expr ::= expr likeop expr ESCAPE expr */ { ExprList *pList; int bNot = yymsp[-3].minor.yy0.n & 0x80000000; yymsp[-3].minor.yy0.n &= 0x7fffffff; - pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy528); - pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy528); - pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy528); - yymsp[-4].minor.yy528 = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy0, 0); - if( bNot ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0); - if( yymsp[-4].minor.yy528 ) yymsp[-4].minor.yy528->flags |= EP_InfixFunc; + pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy626); + pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy626); + pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy626); + yymsp[-4].minor.yy626 = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy0, 0); + if( bNot ) yymsp[-4].minor.yy626 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy626, 0); + if( yymsp[-4].minor.yy626 ) yymsp[-4].minor.yy626->flags |= EP_InfixFunc; } break; case 205: /* expr ::= expr ISNULL|NOTNULL */ -{yymsp[-1].minor.yy528 = sqlite3PExpr(pParse,yymsp[0].major,yymsp[-1].minor.yy528,0);} +{yymsp[-1].minor.yy626 = sqlite3PExpr(pParse,yymsp[0].major,yymsp[-1].minor.yy626,0);} break; case 206: /* expr ::= expr NOT NULL */ -{yymsp[-2].minor.yy528 = sqlite3PExpr(pParse,TK_NOTNULL,yymsp[-2].minor.yy528,0);} +{yymsp[-2].minor.yy626 = sqlite3PExpr(pParse,TK_NOTNULL,yymsp[-2].minor.yy626,0);} break; case 207: /* expr ::= expr IS expr */ { - yymsp[-2].minor.yy528 = sqlite3PExpr(pParse,TK_IS,yymsp[-2].minor.yy528,yymsp[0].minor.yy528); - binaryToUnaryIfNull(pParse, yymsp[0].minor.yy528, yymsp[-2].minor.yy528, TK_ISNULL); + yymsp[-2].minor.yy626 = sqlite3PExpr(pParse,TK_IS,yymsp[-2].minor.yy626,yymsp[0].minor.yy626); + binaryToUnaryIfNull(pParse, yymsp[0].minor.yy626, yymsp[-2].minor.yy626, TK_ISNULL); } break; case 208: /* expr ::= expr IS NOT expr */ { - yymsp[-3].minor.yy528 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-3].minor.yy528,yymsp[0].minor.yy528); - binaryToUnaryIfNull(pParse, yymsp[0].minor.yy528, yymsp[-3].minor.yy528, TK_NOTNULL); + yymsp[-3].minor.yy626 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-3].minor.yy626,yymsp[0].minor.yy626); + binaryToUnaryIfNull(pParse, yymsp[0].minor.yy626, yymsp[-3].minor.yy626, TK_NOTNULL); } break; case 209: /* expr ::= NOT expr */ case 210: /* expr ::= BITNOT expr */ yytestcase(yyruleno==210); -{yymsp[-1].minor.yy528 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy528, 0);/*A-overwrites-B*/} +{yymsp[-1].minor.yy626 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy626, 0);/*A-overwrites-B*/} break; case 211: /* expr ::= PLUS|MINUS expr */ { - yymsp[-1].minor.yy528 = sqlite3PExpr(pParse, yymsp[-1].major==TK_PLUS ? TK_UPLUS : TK_UMINUS, yymsp[0].minor.yy528, 0); + yymsp[-1].minor.yy626 = sqlite3PExpr(pParse, yymsp[-1].major==TK_PLUS ? TK_UPLUS : TK_UMINUS, yymsp[0].minor.yy626, 0); /*A-overwrites-B*/ } break; - case 212: /* expr ::= expr PTR expr */ -{ - ExprList *pList = sqlite3ExprListAppend(pParse, 0, yymsp[-2].minor.yy528); - pList = sqlite3ExprListAppend(pParse, pList, yymsp[0].minor.yy528); - yylhsminor.yy528 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0, 0); -} - yymsp[-2].minor.yy528 = yylhsminor.yy528; - break; - case 213: /* between_op ::= BETWEEN */ - case 216: /* in_op ::= IN */ yytestcase(yyruleno==216); -{yymsp[0].minor.yy394 = 0;} - break; - case 215: /* expr ::= expr between_op expr AND expr */ -{ - ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy528); - pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy528); - yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy528, 0); - if( yymsp[-4].minor.yy528 ){ - yymsp[-4].minor.yy528->x.pList = pList; + case 212: /* between_op ::= BETWEEN */ + case 215: /* in_op ::= IN */ yytestcase(yyruleno==215); +{yymsp[0].minor.yy64 = 0;} + break; + case 214: /* expr ::= expr between_op expr AND expr */ +{ + ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy626); + pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy626); + yymsp[-4].minor.yy626 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy626, 0); + if( yymsp[-4].minor.yy626 ){ + yymsp[-4].minor.yy626->x.pList = pList; }else{ sqlite3ExprListDelete(pParse->db, pList); } - if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0); + if( yymsp[-3].minor.yy64 ) yymsp[-4].minor.yy626 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy626, 0); } break; - case 218: /* expr ::= expr in_op LP exprlist RP */ + case 217: /* expr ::= expr in_op LP exprlist RP */ { - if( yymsp[-1].minor.yy322==0 ){ + if( yymsp[-1].minor.yy562==0 ){ /* Expressions of the form ** ** expr1 IN () ** expr1 NOT IN () ** ** simplify to constants 0 (false) and 1 (true), respectively, ** regardless of the value of expr1. */ - sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy528); - yymsp[-4].minor.yy528 = sqlite3Expr(pParse->db, TK_INTEGER, yymsp[-3].minor.yy394 ? "1" : "0"); + sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy626); + yymsp[-4].minor.yy626 = sqlite3Expr(pParse->db, TK_INTEGER, yymsp[-3].minor.yy64 ? "1" : "0"); }else{ - Expr *pRHS = yymsp[-1].minor.yy322->a[0].pExpr; - if( yymsp[-1].minor.yy322->nExpr==1 && sqlite3ExprIsConstant(pRHS) && yymsp[-4].minor.yy528->op!=TK_VECTOR ){ - yymsp[-1].minor.yy322->a[0].pExpr = 0; - sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy322); + Expr *pRHS = yymsp[-1].minor.yy562->a[0].pExpr; + if( yymsp[-1].minor.yy562->nExpr==1 && sqlite3ExprIsConstant(pRHS) && yymsp[-4].minor.yy626->op!=TK_VECTOR ){ + yymsp[-1].minor.yy562->a[0].pExpr = 0; + sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy562); pRHS = sqlite3PExpr(pParse, TK_UPLUS, pRHS, 0); - yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_EQ, yymsp[-4].minor.yy528, pRHS); + yymsp[-4].minor.yy626 = sqlite3PExpr(pParse, TK_EQ, yymsp[-4].minor.yy626, pRHS); }else{ - yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy528, 0); - if( yymsp[-4].minor.yy528==0 ){ - sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy322); - }else if( yymsp[-4].minor.yy528->pLeft->op==TK_VECTOR ){ - int nExpr = yymsp[-4].minor.yy528->pLeft->x.pList->nExpr; - Select *pSelectRHS = sqlite3ExprListToValues(pParse, nExpr, yymsp[-1].minor.yy322); + yymsp[-4].minor.yy626 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy626, 0); + if( yymsp[-4].minor.yy626==0 ){ + sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy562); + }else if( yymsp[-4].minor.yy626->pLeft->op==TK_VECTOR ){ + int nExpr = yymsp[-4].minor.yy626->pLeft->x.pList->nExpr; + Select *pSelectRHS = sqlite3ExprListToValues(pParse, nExpr, yymsp[-1].minor.yy562); if( pSelectRHS ){ parserDoubleLinkSelect(pParse, pSelectRHS); - sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy528, pSelectRHS); - } - }else{ - yymsp[-4].minor.yy528->x.pList = yymsp[-1].minor.yy322; - sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy528); - } - } - if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0); - } - } - break; - case 219: /* expr ::= LP select RP */ -{ - yymsp[-2].minor.yy528 = sqlite3PExpr(pParse, TK_SELECT, 0, 0); - sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy528, yymsp[-1].minor.yy47); - } - break; - case 220: /* expr ::= expr in_op LP select RP */ -{ - yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy528, 0); - sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy528, yymsp[-1].minor.yy47); - if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0); - } - break; - case 221: /* expr ::= expr in_op nm dbnm paren_exprlist */ + sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy626, pSelectRHS); + } + }else{ + yymsp[-4].minor.yy626->x.pList = yymsp[-1].minor.yy562; + sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy626); + } + } + if( yymsp[-3].minor.yy64 ) yymsp[-4].minor.yy626 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy626, 0); + } + } + break; + case 218: /* expr ::= LP select RP */ +{ + yymsp[-2].minor.yy626 = sqlite3PExpr(pParse, TK_SELECT, 0, 0); + sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy626, yymsp[-1].minor.yy303); + } + break; + case 219: /* expr ::= expr in_op LP select RP */ +{ + yymsp[-4].minor.yy626 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy626, 0); + sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy626, yymsp[-1].minor.yy303); + if( yymsp[-3].minor.yy64 ) yymsp[-4].minor.yy626 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy626, 0); + } + break; + case 220: /* expr ::= expr in_op nm dbnm paren_exprlist */ { SrcList *pSrc = sqlite3SrcListAppend(pParse, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0); - if( yymsp[0].minor.yy322 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy322); - yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy528, 0); - sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy528, pSelect); - if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0); + if( yymsp[0].minor.yy562 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy562); + yymsp[-4].minor.yy626 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy626, 0); + sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy626, pSelect); + if( yymsp[-3].minor.yy64 ) yymsp[-4].minor.yy626 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy626, 0); } break; - case 222: /* expr ::= EXISTS LP select RP */ + case 221: /* expr ::= EXISTS LP select RP */ { Expr *p; - p = yymsp[-3].minor.yy528 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0); - sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy47); - } - break; - case 223: /* expr ::= CASE case_operand case_exprlist case_else END */ -{ - yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy528, 0); - if( yymsp[-4].minor.yy528 ){ - yymsp[-4].minor.yy528->x.pList = yymsp[-1].minor.yy528 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[-1].minor.yy528) : yymsp[-2].minor.yy322; - sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy528); - }else{ - sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy322); - sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy528); - } -} - break; - case 224: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */ -{ - yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[-2].minor.yy528); - yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[0].minor.yy528); -} - break; - case 225: /* case_exprlist ::= WHEN expr THEN expr */ -{ - yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy528); - yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322, yymsp[0].minor.yy528); -} - break; - case 228: /* case_operand ::= expr */ -{yymsp[0].minor.yy528 = yymsp[0].minor.yy528; /*A-overwrites-X*/} - break; - case 231: /* nexprlist ::= nexprlist COMMA expr */ -{yymsp[-2].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[0].minor.yy528);} - break; - case 232: /* nexprlist ::= expr */ -{yymsp[0].minor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy528); /*A-overwrites-Y*/} - break; - case 234: /* paren_exprlist ::= LP exprlist RP */ - case 239: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==239); -{yymsp[-2].minor.yy322 = yymsp[-1].minor.yy322;} - break; - case 235: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */ + p = yymsp[-3].minor.yy626 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0); + sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy303); + } + break; + case 222: /* expr ::= CASE case_operand case_exprlist case_else END */ +{ + yymsp[-4].minor.yy626 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy626, 0); + if( yymsp[-4].minor.yy626 ){ + yymsp[-4].minor.yy626->x.pList = yymsp[-1].minor.yy626 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy562,yymsp[-1].minor.yy626) : yymsp[-2].minor.yy562; + sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy626); + }else{ + sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy562); + sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy626); + } +} + break; + case 223: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */ +{ + yymsp[-4].minor.yy562 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy562, yymsp[-2].minor.yy626); + yymsp[-4].minor.yy562 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy562, yymsp[0].minor.yy626); +} + break; + case 224: /* case_exprlist ::= WHEN expr THEN expr */ +{ + yymsp[-3].minor.yy562 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy626); + yymsp[-3].minor.yy562 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy562, yymsp[0].minor.yy626); +} + break; + case 227: /* case_operand ::= expr */ +{yymsp[0].minor.yy626 = yymsp[0].minor.yy626; /*A-overwrites-X*/} + break; + case 230: /* nexprlist ::= nexprlist COMMA expr */ +{yymsp[-2].minor.yy562 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy562,yymsp[0].minor.yy626);} + break; + case 231: /* nexprlist ::= expr */ +{yymsp[0].minor.yy562 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy626); /*A-overwrites-Y*/} + break; + case 233: /* paren_exprlist ::= LP exprlist RP */ + case 238: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==238); +{yymsp[-2].minor.yy562 = yymsp[-1].minor.yy562;} + break; + case 234: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */ { sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, - sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy322, yymsp[-10].minor.yy394, - &yymsp[-11].minor.yy0, yymsp[0].minor.yy528, SQLITE_SO_ASC, yymsp[-8].minor.yy394, SQLITE_IDXTYPE_APPDEF); + sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy562, yymsp[-10].minor.yy64, + &yymsp[-11].minor.yy0, yymsp[0].minor.yy626, SQLITE_SO_ASC, yymsp[-8].minor.yy64, SQLITE_IDXTYPE_APPDEF); if( IN_RENAME_OBJECT && pParse->pNewIndex ){ sqlite3RenameTokenMap(pParse, pParse->pNewIndex->zName, &yymsp[-4].minor.yy0); } } break; - case 236: /* uniqueflag ::= UNIQUE */ - case 278: /* raisetype ::= ABORT */ yytestcase(yyruleno==278); -{yymsp[0].minor.yy394 = OE_Abort;} - break; - case 237: /* uniqueflag ::= */ -{yymsp[1].minor.yy394 = OE_None;} - break; - case 240: /* eidlist ::= eidlist COMMA nm collate sortorder */ -{ - yymsp[-4].minor.yy322 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy322, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy394, yymsp[0].minor.yy394); -} - break; - case 241: /* eidlist ::= nm collate sortorder */ -{ - yymsp[-2].minor.yy322 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy394, yymsp[0].minor.yy394); /*A-overwrites-Y*/ -} - break; - case 244: /* cmd ::= DROP INDEX ifexists fullname */ -{sqlite3DropIndex(pParse, yymsp[0].minor.yy131, yymsp[-1].minor.yy394);} - break; - case 245: /* cmd ::= VACUUM vinto */ -{sqlite3Vacuum(pParse,0,yymsp[0].minor.yy528);} - break; - case 246: /* cmd ::= VACUUM nm vinto */ -{sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy528);} - break; - case 249: /* cmd ::= PRAGMA nm dbnm */ + case 235: /* uniqueflag ::= UNIQUE */ + case 277: /* raisetype ::= ABORT */ yytestcase(yyruleno==277); +{yymsp[0].minor.yy64 = OE_Abort;} + break; + case 236: /* uniqueflag ::= */ +{yymsp[1].minor.yy64 = OE_None;} + break; + case 239: /* eidlist ::= eidlist COMMA nm collate sortorder */ +{ + yymsp[-4].minor.yy562 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy562, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy64, yymsp[0].minor.yy64); +} + break; + case 240: /* eidlist ::= nm collate sortorder */ +{ + yymsp[-2].minor.yy562 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy64, yymsp[0].minor.yy64); /*A-overwrites-Y*/ +} + break; + case 243: /* cmd ::= DROP INDEX ifexists fullname */ +{sqlite3DropIndex(pParse, yymsp[0].minor.yy607, yymsp[-1].minor.yy64);} + break; + case 244: /* cmd ::= VACUUM vinto */ +{sqlite3Vacuum(pParse,0,yymsp[0].minor.yy626);} + break; + case 245: /* cmd ::= VACUUM nm vinto */ +{sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy626);} + break; + case 248: /* cmd ::= PRAGMA nm dbnm */ {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);} break; - case 250: /* cmd ::= PRAGMA nm dbnm EQ nmnum */ + case 249: /* cmd ::= PRAGMA nm dbnm EQ nmnum */ {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);} break; - case 251: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */ + case 250: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */ {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);} break; - case 252: /* cmd ::= PRAGMA nm dbnm EQ minus_num */ + case 251: /* cmd ::= PRAGMA nm dbnm EQ minus_num */ {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);} break; - case 253: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */ + case 252: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */ {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);} break; - case 256: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */ + case 255: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */ { Token all; all.z = yymsp[-3].minor.yy0.z; all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n; - sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy33, &all); + sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy95, &all); } break; - case 257: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */ + case 256: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */ { - sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy394, yymsp[-4].minor.yy180.a, yymsp[-4].minor.yy180.b, yymsp[-2].minor.yy131, yymsp[0].minor.yy528, yymsp[-10].minor.yy394, yymsp[-8].minor.yy394); + sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy64, yymsp[-4].minor.yy570.a, yymsp[-4].minor.yy570.b, yymsp[-2].minor.yy607, yymsp[0].minor.yy626, yymsp[-10].minor.yy64, yymsp[-8].minor.yy64); yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/ } break; - case 258: /* trigger_time ::= BEFORE|AFTER */ -{ yymsp[0].minor.yy394 = yymsp[0].major; /*A-overwrites-X*/ } - break; - case 259: /* trigger_time ::= INSTEAD OF */ -{ yymsp[-1].minor.yy394 = TK_INSTEAD;} - break; - case 260: /* trigger_time ::= */ -{ yymsp[1].minor.yy394 = TK_BEFORE; } - break; - case 261: /* trigger_event ::= DELETE|INSERT */ - case 262: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==262); -{yymsp[0].minor.yy180.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy180.b = 0;} - break; - case 263: /* trigger_event ::= UPDATE OF idlist */ -{yymsp[-2].minor.yy180.a = TK_UPDATE; yymsp[-2].minor.yy180.b = yymsp[0].minor.yy254;} - break; - case 264: /* when_clause ::= */ - case 283: /* key_opt ::= */ yytestcase(yyruleno==283); -{ yymsp[1].minor.yy528 = 0; } - break; - case 265: /* when_clause ::= WHEN expr */ - case 284: /* key_opt ::= KEY expr */ yytestcase(yyruleno==284); -{ yymsp[-1].minor.yy528 = yymsp[0].minor.yy528; } - break; - case 266: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */ -{ - assert( yymsp[-2].minor.yy33!=0 ); - yymsp[-2].minor.yy33->pLast->pNext = yymsp[-1].minor.yy33; - yymsp[-2].minor.yy33->pLast = yymsp[-1].minor.yy33; -} - break; - case 267: /* trigger_cmd_list ::= trigger_cmd SEMI */ -{ - assert( yymsp[-1].minor.yy33!=0 ); - yymsp[-1].minor.yy33->pLast = yymsp[-1].minor.yy33; -} - break; - case 268: /* trnm ::= nm DOT nm */ + case 257: /* trigger_time ::= BEFORE|AFTER */ +{ yymsp[0].minor.yy64 = yymsp[0].major; /*A-overwrites-X*/ } + break; + case 258: /* trigger_time ::= INSTEAD OF */ +{ yymsp[-1].minor.yy64 = TK_INSTEAD;} + break; + case 259: /* trigger_time ::= */ +{ yymsp[1].minor.yy64 = TK_BEFORE; } + break; + case 260: /* trigger_event ::= DELETE|INSERT */ + case 261: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==261); +{yymsp[0].minor.yy570.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy570.b = 0;} + break; + case 262: /* trigger_event ::= UPDATE OF idlist */ +{yymsp[-2].minor.yy570.a = TK_UPDATE; yymsp[-2].minor.yy570.b = yymsp[0].minor.yy240;} + break; + case 263: /* when_clause ::= */ + case 282: /* key_opt ::= */ yytestcase(yyruleno==282); +{ yymsp[1].minor.yy626 = 0; } + break; + case 264: /* when_clause ::= WHEN expr */ + case 283: /* key_opt ::= KEY expr */ yytestcase(yyruleno==283); +{ yymsp[-1].minor.yy626 = yymsp[0].minor.yy626; } + break; + case 265: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */ +{ + assert( yymsp[-2].minor.yy95!=0 ); + yymsp[-2].minor.yy95->pLast->pNext = yymsp[-1].minor.yy95; + yymsp[-2].minor.yy95->pLast = yymsp[-1].minor.yy95; +} + break; + case 266: /* trigger_cmd_list ::= trigger_cmd SEMI */ +{ + assert( yymsp[-1].minor.yy95!=0 ); + yymsp[-1].minor.yy95->pLast = yymsp[-1].minor.yy95; +} + break; + case 267: /* trnm ::= nm DOT nm */ { yymsp[-2].minor.yy0 = yymsp[0].minor.yy0; sqlite3ErrorMsg(pParse, "qualified table names are not allowed on INSERT, UPDATE, and DELETE " "statements within triggers"); } break; - case 269: /* tridxby ::= INDEXED BY nm */ + case 268: /* tridxby ::= INDEXED BY nm */ { sqlite3ErrorMsg(pParse, "the INDEXED BY clause is not allowed on UPDATE or DELETE statements " "within triggers"); } break; - case 270: /* tridxby ::= NOT INDEXED */ + case 269: /* tridxby ::= NOT INDEXED */ { sqlite3ErrorMsg(pParse, "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements " "within triggers"); } break; - case 271: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */ -{yylhsminor.yy33 = sqlite3TriggerUpdateStep(pParse, &yymsp[-6].minor.yy0, yymsp[-2].minor.yy131, yymsp[-3].minor.yy322, yymsp[-1].minor.yy528, yymsp[-7].minor.yy394, yymsp[-8].minor.yy0.z, yymsp[0].minor.yy522);} - yymsp[-8].minor.yy33 = yylhsminor.yy33; - break; - case 272: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */ -{ - yylhsminor.yy33 = sqlite3TriggerInsertStep(pParse,&yymsp[-4].minor.yy0,yymsp[-3].minor.yy254,yymsp[-2].minor.yy47,yymsp[-6].minor.yy394,yymsp[-1].minor.yy444,yymsp[-7].minor.yy522,yymsp[0].minor.yy522);/*yylhsminor.yy33-overwrites-yymsp[-6].minor.yy394*/ -} - yymsp[-7].minor.yy33 = yylhsminor.yy33; - break; - case 273: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */ -{yylhsminor.yy33 = sqlite3TriggerDeleteStep(pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy528, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy522);} - yymsp[-5].minor.yy33 = yylhsminor.yy33; - break; - case 274: /* trigger_cmd ::= scanpt select scanpt */ -{yylhsminor.yy33 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy47, yymsp[-2].minor.yy522, yymsp[0].minor.yy522); /*yylhsminor.yy33-overwrites-yymsp[-1].minor.yy47*/} - yymsp[-2].minor.yy33 = yylhsminor.yy33; - break; - case 275: /* expr ::= RAISE LP IGNORE RP */ -{ - yymsp[-3].minor.yy528 = sqlite3PExpr(pParse, TK_RAISE, 0, 0); - if( yymsp[-3].minor.yy528 ){ - yymsp[-3].minor.yy528->affExpr = OE_Ignore; - } -} - break; - case 276: /* expr ::= RAISE LP raisetype COMMA nm RP */ -{ - yymsp[-5].minor.yy528 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1); - if( yymsp[-5].minor.yy528 ) { - yymsp[-5].minor.yy528->affExpr = (char)yymsp[-3].minor.yy394; - } -} - break; - case 277: /* raisetype ::= ROLLBACK */ -{yymsp[0].minor.yy394 = OE_Rollback;} - break; - case 279: /* raisetype ::= FAIL */ -{yymsp[0].minor.yy394 = OE_Fail;} - break; - case 280: /* cmd ::= DROP TRIGGER ifexists fullname */ -{ - sqlite3DropTrigger(pParse,yymsp[0].minor.yy131,yymsp[-1].minor.yy394); -} - break; - case 281: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */ -{ - sqlite3Attach(pParse, yymsp[-3].minor.yy528, yymsp[-1].minor.yy528, yymsp[0].minor.yy528); -} - break; - case 282: /* cmd ::= DETACH database_kw_opt expr */ -{ - sqlite3Detach(pParse, yymsp[0].minor.yy528); -} - break; - case 285: /* cmd ::= REINDEX */ + case 270: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */ +{yylhsminor.yy95 = sqlite3TriggerUpdateStep(pParse, &yymsp[-6].minor.yy0, yymsp[-2].minor.yy607, yymsp[-3].minor.yy562, yymsp[-1].minor.yy626, yymsp[-7].minor.yy64, yymsp[-8].minor.yy0.z, yymsp[0].minor.yy600);} + yymsp[-8].minor.yy95 = yylhsminor.yy95; + break; + case 271: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */ +{ + yylhsminor.yy95 = sqlite3TriggerInsertStep(pParse,&yymsp[-4].minor.yy0,yymsp[-3].minor.yy240,yymsp[-2].minor.yy303,yymsp[-6].minor.yy64,yymsp[-1].minor.yy138,yymsp[-7].minor.yy600,yymsp[0].minor.yy600);/*yylhsminor.yy95-overwrites-yymsp[-6].minor.yy64*/ +} + yymsp[-7].minor.yy95 = yylhsminor.yy95; + break; + case 272: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */ +{yylhsminor.yy95 = sqlite3TriggerDeleteStep(pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy626, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy600);} + yymsp[-5].minor.yy95 = yylhsminor.yy95; + break; + case 273: /* trigger_cmd ::= scanpt select scanpt */ +{yylhsminor.yy95 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy303, yymsp[-2].minor.yy600, yymsp[0].minor.yy600); /*yylhsminor.yy95-overwrites-yymsp[-1].minor.yy303*/} + yymsp[-2].minor.yy95 = yylhsminor.yy95; + break; + case 274: /* expr ::= RAISE LP IGNORE RP */ +{ + yymsp[-3].minor.yy626 = sqlite3PExpr(pParse, TK_RAISE, 0, 0); + if( yymsp[-3].minor.yy626 ){ + yymsp[-3].minor.yy626->affExpr = OE_Ignore; + } +} + break; + case 275: /* expr ::= RAISE LP raisetype COMMA nm RP */ +{ + yymsp[-5].minor.yy626 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1); + if( yymsp[-5].minor.yy626 ) { + yymsp[-5].minor.yy626->affExpr = (char)yymsp[-3].minor.yy64; + } +} + break; + case 276: /* raisetype ::= ROLLBACK */ +{yymsp[0].minor.yy64 = OE_Rollback;} + break; + case 278: /* raisetype ::= FAIL */ +{yymsp[0].minor.yy64 = OE_Fail;} + break; + case 279: /* cmd ::= DROP TRIGGER ifexists fullname */ +{ + sqlite3DropTrigger(pParse,yymsp[0].minor.yy607,yymsp[-1].minor.yy64); +} + break; + case 280: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */ +{ + sqlite3Attach(pParse, yymsp[-3].minor.yy626, yymsp[-1].minor.yy626, yymsp[0].minor.yy626); +} + break; + case 281: /* cmd ::= DETACH database_kw_opt expr */ +{ + sqlite3Detach(pParse, yymsp[0].minor.yy626); +} + break; + case 284: /* cmd ::= REINDEX */ {sqlite3Reindex(pParse, 0, 0);} break; - case 286: /* cmd ::= REINDEX nm dbnm */ + case 285: /* cmd ::= REINDEX nm dbnm */ {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);} break; - case 287: /* cmd ::= ANALYZE */ + case 286: /* cmd ::= ANALYZE */ {sqlite3Analyze(pParse, 0, 0);} break; - case 288: /* cmd ::= ANALYZE nm dbnm */ + case 287: /* cmd ::= ANALYZE nm dbnm */ {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);} break; - case 289: /* cmd ::= ALTER TABLE fullname RENAME TO nm */ + case 288: /* cmd ::= ALTER TABLE fullname RENAME TO nm */ { - sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy131,&yymsp[0].minor.yy0); + sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy607,&yymsp[0].minor.yy0); } break; - case 290: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */ + case 289: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */ { yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n; sqlite3AlterFinishAddColumn(pParse, &yymsp[-1].minor.yy0); } break; - case 291: /* cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */ + case 290: /* cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */ { - sqlite3AlterDropColumn(pParse, yymsp[-3].minor.yy131, &yymsp[0].minor.yy0); + sqlite3AlterDropColumn(pParse, yymsp[-3].minor.yy607, &yymsp[0].minor.yy0); } break; - case 292: /* add_column_fullname ::= fullname */ + case 291: /* add_column_fullname ::= fullname */ { disableLookaside(pParse); - sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy131); -} - break; - case 293: /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */ -{ - sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy131, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); -} - break; - case 294: /* cmd ::= create_vtab */ + sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy607); +} + break; + case 292: /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */ +{ + sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy607, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); +} + break; + case 293: /* cmd ::= create_vtab */ {sqlite3VtabFinishParse(pParse,0);} break; - case 295: /* cmd ::= create_vtab LP vtabarglist RP */ + case 294: /* cmd ::= create_vtab LP vtabarglist RP */ {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);} break; - case 296: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */ + case 295: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */ { - sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy394); + sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy64); } break; - case 297: /* vtabarg ::= */ + case 296: /* vtabarg ::= */ {sqlite3VtabArgInit(pParse);} break; - case 298: /* vtabargtoken ::= ANY */ - case 299: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==299); - case 300: /* lp ::= LP */ yytestcase(yyruleno==300); + case 297: /* vtabargtoken ::= ANY */ + case 298: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==298); + case 299: /* lp ::= LP */ yytestcase(yyruleno==299); {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);} break; - case 301: /* with ::= WITH wqlist */ - case 302: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==302); -{ sqlite3WithPush(pParse, yymsp[0].minor.yy521, 1); } - break; - case 303: /* wqas ::= AS */ -{yymsp[0].minor.yy516 = M10d_Any;} - break; - case 304: /* wqas ::= AS MATERIALIZED */ -{yymsp[-1].minor.yy516 = M10d_Yes;} - break; - case 305: /* wqas ::= AS NOT MATERIALIZED */ -{yymsp[-2].minor.yy516 = M10d_No;} - break; - case 306: /* wqitem ::= nm eidlist_opt wqas LP select RP */ -{ - yymsp[-5].minor.yy385 = sqlite3CteNew(pParse, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy322, yymsp[-1].minor.yy47, yymsp[-3].minor.yy516); /*A-overwrites-X*/ -} - break; - case 307: /* wqlist ::= wqitem */ -{ - yymsp[0].minor.yy521 = sqlite3WithAdd(pParse, 0, yymsp[0].minor.yy385); /*A-overwrites-X*/ -} - break; - case 308: /* wqlist ::= wqlist COMMA wqitem */ -{ - yymsp[-2].minor.yy521 = sqlite3WithAdd(pParse, yymsp[-2].minor.yy521, yymsp[0].minor.yy385); -} - break; - case 309: /* windowdefn_list ::= windowdefn */ -{ yylhsminor.yy41 = yymsp[0].minor.yy41; } - yymsp[0].minor.yy41 = yylhsminor.yy41; - break; - case 310: /* windowdefn_list ::= windowdefn_list COMMA windowdefn */ -{ - assert( yymsp[0].minor.yy41!=0 ); - sqlite3WindowChain(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy41); - yymsp[0].minor.yy41->pNextWin = yymsp[-2].minor.yy41; - yylhsminor.yy41 = yymsp[0].minor.yy41; -} - yymsp[-2].minor.yy41 = yylhsminor.yy41; - break; - case 311: /* windowdefn ::= nm AS LP window RP */ -{ - if( ALWAYS(yymsp[-1].minor.yy41) ){ - yymsp[-1].minor.yy41->zName = sqlite3DbStrNDup(pParse->db, yymsp[-4].minor.yy0.z, yymsp[-4].minor.yy0.n); - } - yylhsminor.yy41 = yymsp[-1].minor.yy41; -} - yymsp[-4].minor.yy41 = yylhsminor.yy41; - break; - case 312: /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */ -{ - yymsp[-4].minor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy322, yymsp[-1].minor.yy322, 0); -} - break; - case 313: /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */ -{ - yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy322, yymsp[-1].minor.yy322, &yymsp[-5].minor.yy0); -} - yymsp[-5].minor.yy41 = yylhsminor.yy41; - break; - case 314: /* window ::= ORDER BY sortlist frame_opt */ -{ - yymsp[-3].minor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, yymsp[-1].minor.yy322, 0); -} - break; - case 315: /* window ::= nm ORDER BY sortlist frame_opt */ -{ - yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, yymsp[-1].minor.yy322, &yymsp[-4].minor.yy0); -} - yymsp[-4].minor.yy41 = yylhsminor.yy41; - break; - case 316: /* window ::= frame_opt */ - case 335: /* filter_over ::= over_clause */ yytestcase(yyruleno==335); -{ - yylhsminor.yy41 = yymsp[0].minor.yy41; -} - yymsp[0].minor.yy41 = yylhsminor.yy41; - break; - case 317: /* window ::= nm frame_opt */ -{ - yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, 0, &yymsp[-1].minor.yy0); -} - yymsp[-1].minor.yy41 = yylhsminor.yy41; - break; - case 318: /* frame_opt ::= */ -{ - yymsp[1].minor.yy41 = sqlite3WindowAlloc(pParse, 0, TK_UNBOUNDED, 0, TK_CURRENT, 0, 0); -} - break; - case 319: /* frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */ -{ - yylhsminor.yy41 = sqlite3WindowAlloc(pParse, yymsp[-2].minor.yy394, yymsp[-1].minor.yy595.eType, yymsp[-1].minor.yy595.pExpr, TK_CURRENT, 0, yymsp[0].minor.yy516); -} - yymsp[-2].minor.yy41 = yylhsminor.yy41; - break; - case 320: /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */ -{ - yylhsminor.yy41 = sqlite3WindowAlloc(pParse, yymsp[-5].minor.yy394, yymsp[-3].minor.yy595.eType, yymsp[-3].minor.yy595.pExpr, yymsp[-1].minor.yy595.eType, yymsp[-1].minor.yy595.pExpr, yymsp[0].minor.yy516); -} - yymsp[-5].minor.yy41 = yylhsminor.yy41; - break; - case 322: /* frame_bound_s ::= frame_bound */ - case 324: /* frame_bound_e ::= frame_bound */ yytestcase(yyruleno==324); -{yylhsminor.yy595 = yymsp[0].minor.yy595;} - yymsp[0].minor.yy595 = yylhsminor.yy595; - break; - case 323: /* frame_bound_s ::= UNBOUNDED PRECEDING */ - case 325: /* frame_bound_e ::= UNBOUNDED FOLLOWING */ yytestcase(yyruleno==325); - case 327: /* frame_bound ::= CURRENT ROW */ yytestcase(yyruleno==327); -{yylhsminor.yy595.eType = yymsp[-1].major; yylhsminor.yy595.pExpr = 0;} - yymsp[-1].minor.yy595 = yylhsminor.yy595; - break; - case 326: /* frame_bound ::= expr PRECEDING|FOLLOWING */ -{yylhsminor.yy595.eType = yymsp[0].major; yylhsminor.yy595.pExpr = yymsp[-1].minor.yy528;} - yymsp[-1].minor.yy595 = yylhsminor.yy595; - break; - case 328: /* frame_exclude_opt ::= */ -{yymsp[1].minor.yy516 = 0;} - break; - case 329: /* frame_exclude_opt ::= EXCLUDE frame_exclude */ -{yymsp[-1].minor.yy516 = yymsp[0].minor.yy516;} - break; - case 330: /* frame_exclude ::= NO OTHERS */ - case 331: /* frame_exclude ::= CURRENT ROW */ yytestcase(yyruleno==331); -{yymsp[-1].minor.yy516 = yymsp[-1].major; /*A-overwrites-X*/} - break; - case 332: /* frame_exclude ::= GROUP|TIES */ -{yymsp[0].minor.yy516 = yymsp[0].major; /*A-overwrites-X*/} - break; - case 333: /* window_clause ::= WINDOW windowdefn_list */ -{ yymsp[-1].minor.yy41 = yymsp[0].minor.yy41; } - break; - case 334: /* filter_over ::= filter_clause over_clause */ -{ - if( yymsp[0].minor.yy41 ){ - yymsp[0].minor.yy41->pFilter = yymsp[-1].minor.yy528; - }else{ - sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy528); - } - yylhsminor.yy41 = yymsp[0].minor.yy41; -} - yymsp[-1].minor.yy41 = yylhsminor.yy41; - break; - case 336: /* filter_over ::= filter_clause */ -{ - yylhsminor.yy41 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window)); - if( yylhsminor.yy41 ){ - yylhsminor.yy41->eFrmType = TK_FILTER; - yylhsminor.yy41->pFilter = yymsp[0].minor.yy528; - }else{ - sqlite3ExprDelete(pParse->db, yymsp[0].minor.yy528); - } -} - yymsp[0].minor.yy41 = yylhsminor.yy41; - break; - case 337: /* over_clause ::= OVER LP window RP */ -{ - yymsp[-3].minor.yy41 = yymsp[-1].minor.yy41; - assert( yymsp[-3].minor.yy41!=0 ); -} - break; - case 338: /* over_clause ::= OVER nm */ -{ - yymsp[-1].minor.yy41 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window)); - if( yymsp[-1].minor.yy41 ){ - yymsp[-1].minor.yy41->zName = sqlite3DbStrNDup(pParse->db, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n); - } -} - break; - case 339: /* filter_clause ::= FILTER LP WHERE expr RP */ -{ yymsp[-4].minor.yy528 = yymsp[-1].minor.yy528; } + case 300: /* with ::= WITH wqlist */ + case 301: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==301); +{ sqlite3WithPush(pParse, yymsp[0].minor.yy43, 1); } + break; + case 302: /* wqas ::= AS */ +{yymsp[0].minor.yy534 = M10d_Any;} + break; + case 303: /* wqas ::= AS MATERIALIZED */ +{yymsp[-1].minor.yy534 = M10d_Yes;} + break; + case 304: /* wqas ::= AS NOT MATERIALIZED */ +{yymsp[-2].minor.yy534 = M10d_No;} + break; + case 305: /* wqitem ::= nm eidlist_opt wqas LP select RP */ +{ + yymsp[-5].minor.yy255 = sqlite3CteNew(pParse, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy562, yymsp[-1].minor.yy303, yymsp[-3].minor.yy534); /*A-overwrites-X*/ +} + break; + case 306: /* wqlist ::= wqitem */ +{ + yymsp[0].minor.yy43 = sqlite3WithAdd(pParse, 0, yymsp[0].minor.yy255); /*A-overwrites-X*/ +} + break; + case 307: /* wqlist ::= wqlist COMMA wqitem */ +{ + yymsp[-2].minor.yy43 = sqlite3WithAdd(pParse, yymsp[-2].minor.yy43, yymsp[0].minor.yy255); +} + break; + case 308: /* windowdefn_list ::= windowdefn */ +{ yylhsminor.yy375 = yymsp[0].minor.yy375; } + yymsp[0].minor.yy375 = yylhsminor.yy375; + break; + case 309: /* windowdefn_list ::= windowdefn_list COMMA windowdefn */ +{ + assert( yymsp[0].minor.yy375!=0 ); + sqlite3WindowChain(pParse, yymsp[0].minor.yy375, yymsp[-2].minor.yy375); + yymsp[0].minor.yy375->pNextWin = yymsp[-2].minor.yy375; + yylhsminor.yy375 = yymsp[0].minor.yy375; +} + yymsp[-2].minor.yy375 = yylhsminor.yy375; + break; + case 310: /* windowdefn ::= nm AS LP window RP */ +{ + if( ALWAYS(yymsp[-1].minor.yy375) ){ + yymsp[-1].minor.yy375->zName = sqlite3DbStrNDup(pParse->db, yymsp[-4].minor.yy0.z, yymsp[-4].minor.yy0.n); + } + yylhsminor.yy375 = yymsp[-1].minor.yy375; +} + yymsp[-4].minor.yy375 = yylhsminor.yy375; + break; + case 311: /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */ +{ + yymsp[-4].minor.yy375 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy375, yymsp[-2].minor.yy562, yymsp[-1].minor.yy562, 0); +} + break; + case 312: /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */ +{ + yylhsminor.yy375 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy375, yymsp[-2].minor.yy562, yymsp[-1].minor.yy562, &yymsp[-5].minor.yy0); +} + yymsp[-5].minor.yy375 = yylhsminor.yy375; + break; + case 313: /* window ::= ORDER BY sortlist frame_opt */ +{ + yymsp[-3].minor.yy375 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy375, 0, yymsp[-1].minor.yy562, 0); +} + break; + case 314: /* window ::= nm ORDER BY sortlist frame_opt */ +{ + yylhsminor.yy375 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy375, 0, yymsp[-1].minor.yy562, &yymsp[-4].minor.yy0); +} + yymsp[-4].minor.yy375 = yylhsminor.yy375; + break; + case 315: /* window ::= frame_opt */ + case 334: /* filter_over ::= over_clause */ yytestcase(yyruleno==334); +{ + yylhsminor.yy375 = yymsp[0].minor.yy375; +} + yymsp[0].minor.yy375 = yylhsminor.yy375; + break; + case 316: /* window ::= nm frame_opt */ +{ + yylhsminor.yy375 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy375, 0, 0, &yymsp[-1].minor.yy0); +} + yymsp[-1].minor.yy375 = yylhsminor.yy375; + break; + case 317: /* frame_opt ::= */ +{ + yymsp[1].minor.yy375 = sqlite3WindowAlloc(pParse, 0, TK_UNBOUNDED, 0, TK_CURRENT, 0, 0); +} + break; + case 318: /* frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */ +{ + yylhsminor.yy375 = sqlite3WindowAlloc(pParse, yymsp[-2].minor.yy64, yymsp[-1].minor.yy81.eType, yymsp[-1].minor.yy81.pExpr, TK_CURRENT, 0, yymsp[0].minor.yy534); +} + yymsp[-2].minor.yy375 = yylhsminor.yy375; + break; + case 319: /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */ +{ + yylhsminor.yy375 = sqlite3WindowAlloc(pParse, yymsp[-5].minor.yy64, yymsp[-3].minor.yy81.eType, yymsp[-3].minor.yy81.pExpr, yymsp[-1].minor.yy81.eType, yymsp[-1].minor.yy81.pExpr, yymsp[0].minor.yy534); +} + yymsp[-5].minor.yy375 = yylhsminor.yy375; + break; + case 321: /* frame_bound_s ::= frame_bound */ + case 323: /* frame_bound_e ::= frame_bound */ yytestcase(yyruleno==323); +{yylhsminor.yy81 = yymsp[0].minor.yy81;} + yymsp[0].minor.yy81 = yylhsminor.yy81; + break; + case 322: /* frame_bound_s ::= UNBOUNDED PRECEDING */ + case 324: /* frame_bound_e ::= UNBOUNDED FOLLOWING */ yytestcase(yyruleno==324); + case 326: /* frame_bound ::= CURRENT ROW */ yytestcase(yyruleno==326); +{yylhsminor.yy81.eType = yymsp[-1].major; yylhsminor.yy81.pExpr = 0;} + yymsp[-1].minor.yy81 = yylhsminor.yy81; + break; + case 325: /* frame_bound ::= expr PRECEDING|FOLLOWING */ +{yylhsminor.yy81.eType = yymsp[0].major; yylhsminor.yy81.pExpr = yymsp[-1].minor.yy626;} + yymsp[-1].minor.yy81 = yylhsminor.yy81; + break; + case 327: /* frame_exclude_opt ::= */ +{yymsp[1].minor.yy534 = 0;} + break; + case 328: /* frame_exclude_opt ::= EXCLUDE frame_exclude */ +{yymsp[-1].minor.yy534 = yymsp[0].minor.yy534;} + break; + case 329: /* frame_exclude ::= NO OTHERS */ + case 330: /* frame_exclude ::= CURRENT ROW */ yytestcase(yyruleno==330); +{yymsp[-1].minor.yy534 = yymsp[-1].major; /*A-overwrites-X*/} + break; + case 331: /* frame_exclude ::= GROUP|TIES */ +{yymsp[0].minor.yy534 = yymsp[0].major; /*A-overwrites-X*/} + break; + case 332: /* window_clause ::= WINDOW windowdefn_list */ +{ yymsp[-1].minor.yy375 = yymsp[0].minor.yy375; } + break; + case 333: /* filter_over ::= filter_clause over_clause */ +{ + if( yymsp[0].minor.yy375 ){ + yymsp[0].minor.yy375->pFilter = yymsp[-1].minor.yy626; + }else{ + sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy626); + } + yylhsminor.yy375 = yymsp[0].minor.yy375; +} + yymsp[-1].minor.yy375 = yylhsminor.yy375; + break; + case 335: /* filter_over ::= filter_clause */ +{ + yylhsminor.yy375 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window)); + if( yylhsminor.yy375 ){ + yylhsminor.yy375->eFrmType = TK_FILTER; + yylhsminor.yy375->pFilter = yymsp[0].minor.yy626; + }else{ + sqlite3ExprDelete(pParse->db, yymsp[0].minor.yy626); + } +} + yymsp[0].minor.yy375 = yylhsminor.yy375; + break; + case 336: /* over_clause ::= OVER LP window RP */ +{ + yymsp[-3].minor.yy375 = yymsp[-1].minor.yy375; + assert( yymsp[-3].minor.yy375!=0 ); +} + break; + case 337: /* over_clause ::= OVER nm */ +{ + yymsp[-1].minor.yy375 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window)); + if( yymsp[-1].minor.yy375 ){ + yymsp[-1].minor.yy375->zName = sqlite3DbStrNDup(pParse->db, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n); + } +} + break; + case 338: /* filter_clause ::= FILTER LP WHERE expr RP */ +{ yymsp[-4].minor.yy626 = yymsp[-1].minor.yy626; } break; default: - /* (340) input ::= cmdlist */ yytestcase(yyruleno==340); - /* (341) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==341); - /* (342) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=342); - /* (343) ecmd ::= SEMI */ yytestcase(yyruleno==343); - /* (344) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==344); - /* (345) ecmd ::= explain cmdx SEMI (NEVER REDUCES) */ assert(yyruleno!=345); - /* (346) trans_opt ::= */ yytestcase(yyruleno==346); - /* (347) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==347); - /* (348) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==348); - /* (349) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==349); - /* (350) savepoint_opt ::= */ yytestcase(yyruleno==350); - /* (351) cmd ::= create_table create_table_args */ yytestcase(yyruleno==351); - /* (352) table_option_set ::= table_option (OPTIMIZED OUT) */ assert(yyruleno!=352); - /* (353) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==353); - /* (354) columnlist ::= columnname carglist */ yytestcase(yyruleno==354); - /* (355) nm ::= ID|INDEXED */ yytestcase(yyruleno==355); - /* (356) nm ::= STRING */ yytestcase(yyruleno==356); - /* (357) nm ::= JOIN_KW */ yytestcase(yyruleno==357); - /* (358) typetoken ::= typename */ yytestcase(yyruleno==358); - /* (359) typename ::= ID|STRING */ yytestcase(yyruleno==359); - /* (360) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=360); - /* (361) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=361); - /* (362) carglist ::= carglist ccons */ yytestcase(yyruleno==362); - /* (363) carglist ::= */ yytestcase(yyruleno==363); - /* (364) ccons ::= NULL onconf */ yytestcase(yyruleno==364); - /* (365) ccons ::= GENERATED ALWAYS AS generated */ yytestcase(yyruleno==365); - /* (366) ccons ::= AS generated */ yytestcase(yyruleno==366); - /* (367) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==367); - /* (368) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==368); - /* (369) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=369); - /* (370) tconscomma ::= */ yytestcase(yyruleno==370); - /* (371) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=371); - /* (372) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=372); - /* (373) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=373); - /* (374) oneselect ::= values */ yytestcase(yyruleno==374); - /* (375) sclp ::= selcollist COMMA */ yytestcase(yyruleno==375); - /* (376) as ::= ID|STRING */ yytestcase(yyruleno==376); - /* (377) returning ::= */ yytestcase(yyruleno==377); - /* (378) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=378); - /* (379) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==379); - /* (380) exprlist ::= nexprlist */ yytestcase(yyruleno==380); - /* (381) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=381); - /* (382) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=382); - /* (383) nmnum ::= ON */ yytestcase(yyruleno==383); - /* (384) nmnum ::= DELETE */ yytestcase(yyruleno==384); - /* (385) nmnum ::= DEFAULT */ yytestcase(yyruleno==385); - /* (386) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==386); - /* (387) foreach_clause ::= */ yytestcase(yyruleno==387); - /* (388) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==388); - /* (389) trnm ::= nm */ yytestcase(yyruleno==389); - /* (390) tridxby ::= */ yytestcase(yyruleno==390); - /* (391) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==391); - /* (392) database_kw_opt ::= */ yytestcase(yyruleno==392); - /* (393) kwcolumn_opt ::= */ yytestcase(yyruleno==393); - /* (394) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==394); - /* (395) vtabarglist ::= vtabarg */ yytestcase(yyruleno==395); - /* (396) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==396); - /* (397) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==397); - /* (398) anylist ::= */ yytestcase(yyruleno==398); - /* (399) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==399); - /* (400) anylist ::= anylist ANY */ yytestcase(yyruleno==400); - /* (401) with ::= */ yytestcase(yyruleno==401); + /* (339) input ::= cmdlist */ yytestcase(yyruleno==339); + /* (340) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==340); + /* (341) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=341); + /* (342) ecmd ::= SEMI */ yytestcase(yyruleno==342); + /* (343) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==343); + /* (344) ecmd ::= explain cmdx SEMI (NEVER REDUCES) */ assert(yyruleno!=344); + /* (345) trans_opt ::= */ yytestcase(yyruleno==345); + /* (346) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==346); + /* (347) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==347); + /* (348) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==348); + /* (349) savepoint_opt ::= */ yytestcase(yyruleno==349); + /* (350) cmd ::= create_table create_table_args */ yytestcase(yyruleno==350); + /* (351) table_option_set ::= table_option (OPTIMIZED OUT) */ assert(yyruleno!=351); + /* (352) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==352); + /* (353) columnlist ::= columnname carglist */ yytestcase(yyruleno==353); + /* (354) nm ::= ID|INDEXED */ yytestcase(yyruleno==354); + /* (355) nm ::= STRING */ yytestcase(yyruleno==355); + /* (356) nm ::= JOIN_KW */ yytestcase(yyruleno==356); + /* (357) typetoken ::= typename */ yytestcase(yyruleno==357); + /* (358) typename ::= ID|STRING */ yytestcase(yyruleno==358); + /* (359) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=359); + /* (360) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=360); + /* (361) carglist ::= carglist ccons */ yytestcase(yyruleno==361); + /* (362) carglist ::= */ yytestcase(yyruleno==362); + /* (363) ccons ::= NULL onconf */ yytestcase(yyruleno==363); + /* (364) ccons ::= GENERATED ALWAYS AS generated */ yytestcase(yyruleno==364); + /* (365) ccons ::= AS generated */ yytestcase(yyruleno==365); + /* (366) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==366); + /* (367) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==367); + /* (368) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=368); + /* (369) tconscomma ::= */ yytestcase(yyruleno==369); + /* (370) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=370); + /* (371) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=371); + /* (372) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=372); + /* (373) oneselect ::= values */ yytestcase(yyruleno==373); + /* (374) sclp ::= selcollist COMMA */ yytestcase(yyruleno==374); + /* (375) as ::= ID|STRING */ yytestcase(yyruleno==375); + /* (376) returning ::= */ yytestcase(yyruleno==376); + /* (377) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=377); + /* (378) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==378); + /* (379) exprlist ::= nexprlist */ yytestcase(yyruleno==379); + /* (380) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=380); + /* (381) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=381); + /* (382) nmnum ::= ON */ yytestcase(yyruleno==382); + /* (383) nmnum ::= DELETE */ yytestcase(yyruleno==383); + /* (384) nmnum ::= DEFAULT */ yytestcase(yyruleno==384); + /* (385) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==385); + /* (386) foreach_clause ::= */ yytestcase(yyruleno==386); + /* (387) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==387); + /* (388) trnm ::= nm */ yytestcase(yyruleno==388); + /* (389) tridxby ::= */ yytestcase(yyruleno==389); + /* (390) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==390); + /* (391) database_kw_opt ::= */ yytestcase(yyruleno==391); + /* (392) kwcolumn_opt ::= */ yytestcase(yyruleno==392); + /* (393) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==393); + /* (394) vtabarglist ::= vtabarg */ yytestcase(yyruleno==394); + /* (395) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==395); + /* (396) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==396); + /* (397) anylist ::= */ yytestcase(yyruleno==397); + /* (398) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==398); + /* (399) anylist ::= anylist ANY */ yytestcase(yyruleno==399); + /* (400) with ::= */ yytestcase(yyruleno==400); break; /********** End reduce actions ************************************************/ }; assert( yyrulenoyytos>=yypParser->yystack ); assert( yyact==yypParser->yytos->stateno ); yyact = yy_find_shift_action((YYCODETYPE)yymajor,yyact); if( yyact >= YY_MIN_REDUCE ){ unsigned int yyruleno = yyact - YY_MIN_REDUCE; /* Reduce by this rule */ -#ifndef NDEBUG assert( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ); +#ifndef NDEBUG if( yyTraceFILE ){ int yysize = yyRuleInfoNRhs[yyruleno]; if( yysize ){ fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", yyTracePrompt, @@ -167573,13 +164836,10 @@ case CC_MINUS: { if( z[1]=='-' ){ for(i=2; (c=z[i])!=0 && c!='\n'; i++){} *tokenType = TK_SPACE; /* IMP: R-22934-25134 */ return i; - }else if( z[1]=='>' ){ - *tokenType = TK_PTR; - return 2 + (z[2]=='>'); } *tokenType = TK_MINUS; return 1; } case CC_LP: { @@ -167845,21 +165105,24 @@ *tokenType = TK_ID; return i; } /* -** Run the parser on the given SQL string. +** Run the parser on the given SQL string. The parser structure is +** passed in. An SQLITE_ status code is returned. If an error occurs +** then an and attempt is made to write an error message into +** memory obtained from sqlite3_malloc() and to make *pzErrMsg point to that +** error message. */ -SQLITE_PRIVATE int sqlite3RunParser(Parse *pParse, const char *zSql){ +SQLITE_PRIVATE int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){ int nErr = 0; /* Number of errors encountered */ void *pEngine; /* The LEMON-generated LALR(1) parser */ int n = 0; /* Length of the next token token */ int tokenType; /* type of the next token */ int lastTokenParsed = -1; /* type of the previous token */ sqlite3 *db = pParse->db; /* The database connection */ int mxSqlLen; /* Max length of an SQL string */ - Parse *pParentParse = 0; /* Outer parse context, if any */ #ifdef sqlite3Parser_ENGINEALWAYSONSTACK yyParser sEngine; /* Space to hold the Lemon-generated Parser object */ #endif VVA_ONLY( u8 startedWithOom = db->mallocFailed ); @@ -167868,10 +165131,11 @@ if( db->nVdbeActive==0 ){ AtomicStore(&db->u1.isInterrupted, 0); } pParse->rc = SQLITE_OK; pParse->zTail = zSql; + assert( pzErrMsg!=0 ); #ifdef SQLITE_DEBUG if( db->flags & SQLITE_ParserTrace ){ printf("parser: [[[%s]]]\n", zSql); sqlite3ParserTrace(stdout, "parser: "); }else{ @@ -167890,11 +165154,11 @@ #endif assert( pParse->pNewTable==0 ); assert( pParse->pNewTrigger==0 ); assert( pParse->nVar==0 ); assert( pParse->pVList==0 ); - pParentParse = db->pParse; + pParse->pParentParse = db->pParse; db->pParse = pParse; while( 1 ){ n = sqlite3GetToken((u8*)zSql, &tokenType); mxSqlLen -= n; if( mxSqlLen<0 ){ @@ -167910,11 +165174,10 @@ if( tokenType>=TK_SPACE ){ assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL ); #endif /* SQLITE_OMIT_WINDOWFUNC */ if( AtomicLoad(&db->u1.isInterrupted) ){ pParse->rc = SQLITE_INTERRUPT; - pParse->nErr++; break; } if( tokenType==TK_SPACE ){ zSql += n; continue; @@ -167940,14 +165203,11 @@ }else if( tokenType==TK_FILTER ){ assert( n==6 ); tokenType = analyzeFilterKeyword((const u8*)&zSql[6], lastTokenParsed); #endif /* SQLITE_OMIT_WINDOWFUNC */ }else{ - Token x; - x.z = zSql; - x.n = n; - sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"", &x); + sqlite3ErrorMsg(pParse, "unrecognized token: \"%.*s\"", n, zSql); break; } } pParse->sLastToken.z = zSql; pParse->sLastToken.n = n; @@ -167971,34 +165231,50 @@ sqlite3ParserFree(pEngine, sqlite3_free); #endif if( db->mallocFailed ){ pParse->rc = SQLITE_NOMEM_BKPT; } - if( pParse->zErrMsg || (pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE) ){ - if( pParse->zErrMsg==0 ){ - pParse->zErrMsg = sqlite3MPrintf(db, "%s", sqlite3ErrStr(pParse->rc)); - } - sqlite3_log(pParse->rc, "%s in \"%s\"", pParse->zErrMsg, pParse->zTail); + if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){ + pParse->zErrMsg = sqlite3MPrintf(db, "%s", sqlite3ErrStr(pParse->rc)); + } + assert( pzErrMsg!=0 ); + if( pParse->zErrMsg ){ + *pzErrMsg = pParse->zErrMsg; + sqlite3_log(pParse->rc, "%s in \"%s\"", + *pzErrMsg, pParse->zTail); + pParse->zErrMsg = 0; nErr++; } pParse->zTail = zSql; + if( pParse->pVdbe && pParse->nErr>0 && pParse->nested==0 ){ + sqlite3VdbeDelete(pParse->pVdbe); + pParse->pVdbe = 0; + } +#ifndef SQLITE_OMIT_SHARED_CACHE + if( pParse->nested==0 ){ + sqlite3DbFree(db, pParse->aTableLock); + pParse->aTableLock = 0; + pParse->nTableLock = 0; + } +#endif #ifndef SQLITE_OMIT_VIRTUALTABLE sqlite3_free(pParse->apVtabLock); #endif - if( pParse->pNewTable && !IN_SPECIAL_PARSE ){ + if( !IN_SPECIAL_PARSE ){ /* If the pParse->declareVtab flag is set, do not delete any table ** structure built up in pParse->pNewTable. The calling code (see vtab.c) ** will take responsibility for freeing the Table structure. */ sqlite3DeleteTable(db, pParse->pNewTable); } - if( pParse->pNewTrigger && !IN_RENAME_OBJECT ){ + if( !IN_RENAME_OBJECT ){ sqlite3DeleteTrigger(db, pParse->pNewTrigger); } sqlite3DbFree(db, pParse->pVList); - db->pParse = pParentParse; + db->pParse = pParse->pParentParse; + pParse->pParentParse = 0; assert( nErr==0 || pParse->rc!=SQLITE_OK ); return nErr; } @@ -168575,10 +165851,13 @@ SQLITE_PRIVATE int sqlite3Fts2Init(sqlite3*); #endif #ifdef SQLITE_ENABLE_FTS5 SQLITE_PRIVATE int sqlite3Fts5Init(sqlite3*); #endif +#ifdef SQLITE_ENABLE_JSON1 +SQLITE_PRIVATE int sqlite3Json1Init(sqlite3*); +#endif #ifdef SQLITE_ENABLE_STMTVTAB SQLITE_PRIVATE int sqlite3StmtVtabInit(sqlite3*); #endif /* @@ -168609,12 +165888,12 @@ #endif #ifdef SQLITE_ENABLE_DBSTAT_VTAB sqlite3DbstatRegister, #endif sqlite3TestExtInit, -#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_JSON) - sqlite3JsonTableFunctions, +#ifdef SQLITE_ENABLE_JSON1 + sqlite3Json1Init, #endif #ifdef SQLITE_ENABLE_STMTVTAB sqlite3StmtVtabInit, #endif #ifdef SQLITE_ENABLE_BYTECODE_VTAB @@ -169660,13 +166939,11 @@ ** if this is not the last copy of the function, do not invoke it. Multiple ** copies of a single function are created when create_function() is called ** with SQLITE_ANY as the encoding. */ static void functionDestroy(sqlite3 *db, FuncDef *p){ - FuncDestructor *pDestructor; - assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 ); - pDestructor = p->u.pDestructor; + FuncDestructor *pDestructor = p->u.pDestructor; if( pDestructor ){ pDestructor->nRef--; if( pDestructor->nRef==0 ){ pDestructor->xDestroy(pDestructor->pUserData); sqlite3DbFree(db, pDestructor); @@ -169925,13 +167202,10 @@ ** So it needs to be freed here. Todo: Why not roll the temp schema into ** the same sqliteMalloc() as the one that allocates the database ** structure? */ sqlite3DbFree(db, db->aDb[1].pSchema); - if( db->xAutovacDestr ){ - db->xAutovacDestr(db->pAutovacPagesArg); - } sqlite3_mutex_leave(db->mutex); db->eOpenState = SQLITE_STATE_CLOSED; sqlite3_mutex_free(db->mutex); assert( sqlite3LookasideUsed(db,0)==0 ); if( db->lookaside.bMalloced ){ @@ -169982,11 +167256,11 @@ sqlite3BtreeLeaveAll(db); /* Any deferred constraint violations have now been resolved. */ db->nDeferredCons = 0; db->nDeferredImmCons = 0; - db->flags &= ~(u64)(SQLITE_DeferFKs|SQLITE_CorruptRdOnly); + db->flags &= ~(u64)SQLITE_DeferFKs; /* If one has been configured, invoke the rollback-hook callback */ if( db->xRollbackCallback && (inTrans || !db->autoCommit) ){ db->xRollbackCallback(db->pRollbackArg); } @@ -170346,20 +167620,21 @@ void (*xValue)(sqlite3_context*), void (*xInverse)(sqlite3_context*,int,sqlite3_value **), FuncDestructor *pDestructor ){ FuncDef *p; + int nName; int extraFlags; assert( sqlite3_mutex_held(db->mutex) ); assert( xValue==0 || xSFunc==0 ); if( zFunctionName==0 /* Must have a valid name */ || (xSFunc!=0 && xFinal!=0) /* Not both xSFunc and xFinal */ || ((xFinal==0)!=(xStep==0)) /* Both or neither of xFinal and xStep */ || ((xValue==0)!=(xInverse==0)) /* Both or neither of xValue, xInverse */ || (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) - || (255pPreUpdateArg = pArg; sqlite3_mutex_leave(db->mutex); return pRet; } #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */ - -/* -** Register a function to be invoked prior to each autovacuum that -** determines the number of pages to vacuum. -*/ -SQLITE_API int sqlite3_autovacuum_pages( - sqlite3 *db, /* Attach the hook to this database */ - unsigned int (*xCallback)(void*,const char*,u32,u32,u32), - void *pArg, /* Argument to the function */ - void (*xDestructor)(void*) /* Destructor for pArg */ -){ -#ifdef SQLITE_ENABLE_API_ARMOR - if( !sqlite3SafetyCheckOk(db) ){ - if( xDestructor ) xDestructor(pArg); - return SQLITE_MISUSE_BKPT; - } -#endif - sqlite3_mutex_enter(db->mutex); - if( db->xAutovacDestr ){ - db->xAutovacDestr(db->pAutovacPagesArg); - } - db->xAutovacPages = xCallback; - db->pAutovacPagesArg = pArg; - db->xAutovacDestr = xDestructor; - sqlite3_mutex_leave(db->mutex); - return SQLITE_OK; -} - #ifndef SQLITE_OMIT_WAL /* ** The sqlite3_wal_hook() callback registered by sqlite3_wal_autocheckpoint(). ** Invoke sqlite3_wal_checkpoint if the number of frames in the log file @@ -171119,23 +168366,10 @@ } sqlite3_mutex_leave(db->mutex); return z; } -/* -** Return the byte offset of the most recent error -*/ -SQLITE_API int sqlite3_error_offset(sqlite3 *db){ - int iOffset = -1; - if( db && sqlite3SafetyCheckSickOrOk(db) && db->errCode ){ - sqlite3_mutex_enter(db->mutex); - iOffset = db->errByteOffset; - sqlite3_mutex_leave(db->mutex); - } - return iOffset; -} - #ifndef SQLITE_OMIT_UTF16 /* ** Return UTF-16 encoded English language explanation of the most recent ** error. */ @@ -171392,12 +168626,10 @@ } oldLimit = db->aLimit[limitId]; if( newLimit>=0 ){ /* IMP: R-52476-28732 */ if( newLimit>aHardLimit[limitId] ){ newLimit = aHardLimit[limitId]; /* IMP: R-51463-25634 */ - }else if( newLimit<1 && limitId==SQLITE_LIMIT_LENGTH ){ - newLimit = 1; } db->aLimit[limitId] = newLimit; } return oldLimit; /* IMP: R-53341-35419 */ } @@ -171665,11 +168897,11 @@ ** This routine does the core work of extracting URI parameters from a ** database filename for the sqlite3_uri_parameter() interface. */ static const char *uriParameter(const char *zFilename, const char *zParam){ zFilename += sqlite3Strlen30(zFilename) + 1; - while( ALWAYS(zFilename!=0) && zFilename[0] ){ + while( zFilename[0] ){ int x = strcmp(zFilename, zParam); zFilename += sqlite3Strlen30(zFilename) + 1; if( x==0 ) return zFilename; zFilename += sqlite3Strlen30(zFilename) + 1; } @@ -171725,15 +168957,14 @@ ** ** The SQLITE_OPEN_NOMUTEX and SQLITE_OPEN_FULLMUTEX flags were ** dealt with in the previous code block. Besides these, the only ** valid input flags for sqlite3_open_v2() are SQLITE_OPEN_READONLY, ** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE, - ** SQLITE_OPEN_PRIVATECACHE, SQLITE_OPEN_EXRESCODE, and some reserved - ** bits. Silently mask off all other flags. + ** SQLITE_OPEN_PRIVATECACHE, and some reserved bits. Silently mask + ** off all other flags. */ flags &= ~( SQLITE_OPEN_DELETEONCLOSE | - SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_MAIN_DB | SQLITE_OPEN_TEMP_DB | SQLITE_OPEN_TRANSIENT_DB | SQLITE_OPEN_MAIN_JOURNAL | SQLITE_OPEN_TEMP_JOURNAL | @@ -171761,11 +168992,11 @@ if( isThreadsafe==0 ){ sqlite3MutexWarnOnContention(db->mutex); } } sqlite3_mutex_enter(db->mutex); - db->errMask = (flags & SQLITE_OPEN_EXRESCODE)!=0 ? 0xffffffff : 0xff; + db->errMask = 0xff; db->nDb = 2; db->eOpenState = SQLITE_STATE_BUSY; db->aDb = db->aDbStatic; db->lookaside.bDisable = 1; db->lookaside.sz = 0; @@ -171993,12 +169224,12 @@ assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 ); sqlite3_mutex_leave(db->mutex); } rc = sqlite3_errcode(db); - assert( db!=0 || (rc&0xff)==SQLITE_NOMEM ); - if( (rc&0xff)==SQLITE_NOMEM ){ + assert( db!=0 || rc==SQLITE_NOMEM ); + if( rc==SQLITE_NOMEM ){ sqlite3_close(db); db = 0; }else if( rc!=SQLITE_OK ){ db->eOpenState = SQLITE_STATE_SICK; } @@ -172009,11 +169240,11 @@ void *pArg = sqlite3GlobalConfig.pSqllogArg; sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0); } #endif sqlite3_free_filename(zOpen); - return rc; + return rc & 0xff; } /* ** Open a new database handle. @@ -172554,20 +169785,16 @@ ** is called immediately after installing the new callback and the return ** value from sqlite3FaultSim(0) becomes the return from ** sqlite3_test_control(). */ case SQLITE_TESTCTRL_FAULT_INSTALL: { - /* A bug in MSVC prevents it from understanding pointers to functions - ** types in the second argument to va_arg(). Work around the problem - ** using a typedef. - ** http://support.microsoft.com/kb/47961 <-- dead hyperlink - ** Search at http://web.archive.org/ to find the 2015-03-16 archive - ** of the link above to see the original text. + /* MSVC is picky about pulling func ptrs from va lists. + ** http://support.microsoft.com/kb/47961 ** sqlite3GlobalConfig.xTestCallback = va_arg(ap, int(*)(int)); */ - typedef int(*sqlite3FaultFuncType)(int); - sqlite3GlobalConfig.xTestCallback = va_arg(ap, sqlite3FaultFuncType); + typedef int(*TESTCALLBACKFUNC_t)(int); + sqlite3GlobalConfig.xTestCallback = va_arg(ap, TESTCALLBACKFUNC_t); rc = sqlite3FaultSim(0); break; } /* @@ -172690,31 +169917,17 @@ sqlite3 *db = va_arg(ap, sqlite3*); db->dbOptFlags = va_arg(ap, u32); break; } - /* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, onoff, xAlt); - ** - ** If parameter onoff is 1, subsequent calls to localtime() fail. - ** If 2, then invoke xAlt() instead of localtime(). If 0, normal - ** processing. - ** - ** xAlt arguments are void pointers, but they really want to be: - ** - ** int xAlt(const time_t*, struct tm*); - ** - ** xAlt should write results in to struct tm object of its 2nd argument - ** and return zero on success, or return non-zero on failure. + /* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, int onoff); + ** + ** If parameter onoff is non-zero, subsequent calls to localtime() + ** and its variants fail. If onoff is zero, undo this setting. */ case SQLITE_TESTCTRL_LOCALTIME_FAULT: { sqlite3GlobalConfig.bLocaltimeFault = va_arg(ap, int); - if( sqlite3GlobalConfig.bLocaltimeFault==2 ){ - typedef int(*sqlite3LocaltimeType)(const void*,void*); - sqlite3GlobalConfig.xAltLocaltime = va_arg(ap, sqlite3LocaltimeType); - }else{ - sqlite3GlobalConfig.xAltLocaltime = 0; - } break; } /* sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, sqlite3*); ** @@ -172815,20 +170028,16 @@ ** the schema to be reparsed the next time it is needed. This has the ** effect of erasing all imposter tables. */ case SQLITE_TESTCTRL_IMPOSTER: { sqlite3 *db = va_arg(ap, sqlite3*); - int iDb; sqlite3_mutex_enter(db->mutex); - iDb = sqlite3FindDbName(db, va_arg(ap,const char*)); - if( iDb>=0 ){ - db->init.iDb = iDb; - db->init.busy = db->init.imposterTable = va_arg(ap,int); - db->init.newTnum = va_arg(ap,int); - if( db->init.busy==0 && db->init.newTnum>0 ){ - sqlite3ResetAllSchemasOfConnection(db); - } + db->init.iDb = sqlite3FindDbName(db, va_arg(ap,const char*)); + db->init.busy = db->init.imposterTable = va_arg(ap,int); + db->init.newTnum = va_arg(ap,int); + if( db->init.busy==0 && db->init.newTnum>0 ){ + sqlite3ResetAllSchemasOfConnection(db); } sqlite3_mutex_leave(db->mutex); break; } @@ -172899,30 +170108,10 @@ case 2: *ptr = sqlite3WhereTrace; break; case 3: sqlite3WhereTrace = *ptr; break; } break; } - - /* sqlite3_test_control(SQLITE_TESTCTRL_LOGEST, - ** double fIn, // Input value - ** int *pLogEst, // sqlite3LogEstFromDouble(fIn) - ** u64 *pInt, // sqlite3LogEstToInt(*pLogEst) - ** int *pLogEst2 // sqlite3LogEst(*pInt) - ** ); - ** - ** Test access for the LogEst conversion routines. - */ - case SQLITE_TESTCTRL_LOGEST: { - double rIn = va_arg(ap, double); - LogEst rLogEst = sqlite3LogEstFromDouble(rIn); - u64 iInt = sqlite3LogEstToInt(rLogEst); - va_arg(ap, int*)[0] = rLogEst; - va_arg(ap, u64*)[0] = iInt; - va_arg(ap, int*)[0] = sqlite3LogEst(iInt); - break; - } - #if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_WSD) /* sqlite3_test_control(SQLITE_TESTCTRL_TUNE, id, *piValue) ** ** If "id" is an integer between 1 and SQLITE_NTUNE then set the value @@ -173056,11 +170245,11 @@ */ SQLITE_API const char *sqlite3_uri_key(const char *zFilename, int N){ if( zFilename==0 || N<0 ) return 0; zFilename = databaseName(zFilename); zFilename += sqlite3Strlen30(zFilename) + 1; - while( ALWAYS(zFilename) && zFilename[0] && (N--)>0 ){ + while( zFilename[0] && (N--)>0 ){ zFilename += sqlite3Strlen30(zFilename) + 1; zFilename += sqlite3Strlen30(zFilename) + 1; } return zFilename[0] ? zFilename : 0; } @@ -173106,11 +170295,11 @@ } SQLITE_API const char *sqlite3_filename_journal(const char *zFilename){ if( zFilename==0 ) return 0; zFilename = databaseName(zFilename); zFilename += sqlite3Strlen30(zFilename) + 1; - while( ALWAYS(zFilename) && zFilename[0] ){ + while( zFilename[0] ){ zFilename += sqlite3Strlen30(zFilename) + 1; zFilename += sqlite3Strlen30(zFilename) + 1; } return zFilename + 1; } @@ -174410,22 +171599,21 @@ #ifndef SQLITE_AMALGAMATION /* ** Macros indicating that conditional expressions are always true or ** false. */ -#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST) -# define SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS 1 -#endif -#if defined(SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS) -# define ALWAYS(X) (1) -# define NEVER(X) (0) -#elif !defined(NDEBUG) -# define ALWAYS(X) ((X)?1:(assert(0),0)) -# define NEVER(X) ((X)?(assert(0),1):0) +#ifdef SQLITE_COVERAGE_TEST +# define ALWAYS(x) (1) +# define NEVER(X) (0) +#elif defined(SQLITE_DEBUG) +# define ALWAYS(x) sqlite3Fts3Always((x)!=0) +# define NEVER(x) sqlite3Fts3Never((x)!=0) +SQLITE_PRIVATE int sqlite3Fts3Always(int b); +SQLITE_PRIVATE int sqlite3Fts3Never(int b); #else -# define ALWAYS(X) (X) -# define NEVER(X) (X) +# define ALWAYS(x) (x) +# define NEVER(x) (x) #endif /* ** Internal types used by SQLite. */ @@ -174880,11 +172068,10 @@ SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *); #ifdef SQLITE_TEST SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db, Fts3Hash*); SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db); #endif -SQLITE_PRIVATE void *sqlite3Fts3MallocZero(i64 nByte); SQLITE_PRIVATE int sqlite3Fts3OpenTokenizer(sqlite3_tokenizer *, int, const char *, int, sqlite3_tokenizer_cursor ** ); @@ -174900,11 +172087,11 @@ SQLITE_PRIVATE int sqlite3Fts3EvalPhrasePoslist(Fts3Cursor *, Fts3Expr *, int iCol, char **); SQLITE_PRIVATE int sqlite3Fts3MsrOvfl(Fts3Cursor *, Fts3MultiSegReader *, int *); SQLITE_PRIVATE int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr); /* fts3_tokenize_vtab.c */ -SQLITE_PRIVATE int sqlite3Fts3InitTok(sqlite3*, Fts3Hash *, void(*xDestroy)(void*)); +SQLITE_PRIVATE int sqlite3Fts3InitTok(sqlite3*, Fts3Hash *); /* fts3_unicode2.c (functions generated by parsing unicode text files) */ #ifndef SQLITE_DISABLE_FTS3_UNICODE SQLITE_PRIVATE int sqlite3FtsUnicodeFold(int, int); SQLITE_PRIVATE int sqlite3FtsUnicodeIsalnum(int); @@ -174933,20 +172120,21 @@ #ifndef SQLITE_CORE /* # include "sqlite3ext.h" */ SQLITE_EXTENSION_INIT1 #endif -typedef struct Fts3HashWrapper Fts3HashWrapper; -struct Fts3HashWrapper { - Fts3Hash hash; /* Hash table */ - int nRef; /* Number of pointers to this object */ -}; - static int fts3EvalNext(Fts3Cursor *pCsr); static int fts3EvalStart(Fts3Cursor *pCsr); static int fts3TermSegReaderCursor( Fts3Cursor *, const char *, int, int, Fts3MultiSegReader **); + +#ifndef SQLITE_AMALGAMATION +# if defined(SQLITE_DEBUG) +SQLITE_PRIVATE int sqlite3Fts3Always(int b) { assert( b ); return b; } +SQLITE_PRIVATE int sqlite3Fts3Never(int b) { assert( !b ); return b; } +# endif +#endif /* ** This variable is set to false when running tests for which the on disk ** structures should not be corrupt. Otherwise, true. If it is false, extra ** assert() conditions in the fts3 code are activated - conditions that are @@ -175803,11 +172991,11 @@ int argc, /* Number of elements in argv array */ const char * const *argv, /* xCreate/xConnect argument array */ sqlite3_vtab **ppVTab, /* Write the resulting vtab structure here */ char **pzErr /* Write any error message here */ ){ - Fts3Hash *pHash = &((Fts3HashWrapper*)pAux)->hash; + Fts3Hash *pHash = (Fts3Hash *)pAux; Fts3Table *p = 0; /* Pointer to allocated vtab */ int rc = SQLITE_OK; /* Return code */ int i; /* Iterator variable */ sqlite3_int64 nByte; /* Size of allocation used for *p */ int iCol; /* Column index */ @@ -178638,16 +175826,13 @@ ** This function is registered as the module destructor (called when an ** FTS3 enabled database connection is closed). It frees the memory ** allocated for the tokenizer hash table. */ static void hashDestroy(void *p){ - Fts3HashWrapper *pHash = (Fts3HashWrapper *)p; - pHash->nRef--; - if( pHash->nRef<=0 ){ - sqlite3Fts3HashClear(&pHash->hash); - sqlite3_free(pHash); - } + Fts3Hash *pHash = (Fts3Hash *)p; + sqlite3Fts3HashClear(pHash); + sqlite3_free(pHash); } /* ** The fts3 built-in tokenizers - "simple", "porter" and "icu"- are ** implemented in files fts3_tokenizer1.c, fts3_porter.c and fts3_icu.c @@ -178673,11 +175858,11 @@ ** SQLite. If fts3 is built as a dynamically loadable extension, this ** function is called by the sqlite3_extension_init() entry point. */ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){ int rc = SQLITE_OK; - Fts3HashWrapper *pHash = 0; + Fts3Hash *pHash = 0; const sqlite3_tokenizer_module *pSimple = 0; const sqlite3_tokenizer_module *pPorter = 0; #ifndef SQLITE_DISABLE_FTS3_UNICODE const sqlite3_tokenizer_module *pUnicode = 0; #endif @@ -178701,74 +175886,70 @@ sqlite3Fts3SimpleTokenizerModule(&pSimple); sqlite3Fts3PorterTokenizerModule(&pPorter); /* Allocate and initialize the hash-table used to store tokenizers. */ - pHash = sqlite3_malloc(sizeof(Fts3HashWrapper)); + pHash = sqlite3_malloc(sizeof(Fts3Hash)); if( !pHash ){ rc = SQLITE_NOMEM; }else{ - sqlite3Fts3HashInit(&pHash->hash, FTS3_HASH_STRING, 1); - pHash->nRef = 0; + sqlite3Fts3HashInit(pHash, FTS3_HASH_STRING, 1); } /* Load the built-in tokenizers into the hash table */ if( rc==SQLITE_OK ){ - if( sqlite3Fts3HashInsert(&pHash->hash, "simple", 7, (void *)pSimple) - || sqlite3Fts3HashInsert(&pHash->hash, "porter", 7, (void *)pPorter) + if( sqlite3Fts3HashInsert(pHash, "simple", 7, (void *)pSimple) + || sqlite3Fts3HashInsert(pHash, "porter", 7, (void *)pPorter) #ifndef SQLITE_DISABLE_FTS3_UNICODE - || sqlite3Fts3HashInsert(&pHash->hash, "unicode61", 10, (void *)pUnicode) + || sqlite3Fts3HashInsert(pHash, "unicode61", 10, (void *)pUnicode) #endif #ifdef SQLITE_ENABLE_ICU - || (pIcu && sqlite3Fts3HashInsert(&pHash->hash, "icu", 4, (void *)pIcu)) + || (pIcu && sqlite3Fts3HashInsert(pHash, "icu", 4, (void *)pIcu)) #endif ){ rc = SQLITE_NOMEM; } } #ifdef SQLITE_TEST if( rc==SQLITE_OK ){ - rc = sqlite3Fts3ExprInitTestInterface(db, &pHash->hash); + rc = sqlite3Fts3ExprInitTestInterface(db, pHash); } #endif /* Create the virtual table wrapper around the hash-table and overload ** the four scalar functions. If this is successful, register the ** module with sqlite. */ if( SQLITE_OK==rc - && SQLITE_OK==(rc=sqlite3Fts3InitHashTable(db,&pHash->hash,"fts3_tokenizer")) + && SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer")) && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1)) && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1)) && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1)) && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 2)) && SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", 1)) ){ - pHash->nRef++; rc = sqlite3_create_module_v2( db, "fts3", &fts3Module, (void *)pHash, hashDestroy ); if( rc==SQLITE_OK ){ - pHash->nRef++; rc = sqlite3_create_module_v2( - db, "fts4", &fts3Module, (void *)pHash, hashDestroy + db, "fts4", &fts3Module, (void *)pHash, 0 ); } if( rc==SQLITE_OK ){ - pHash->nRef++; - rc = sqlite3Fts3InitTok(db, (void *)pHash, hashDestroy); + rc = sqlite3Fts3InitTok(db, (void *)pHash); } return rc; } /* An error has occurred. Delete the hash table and return the error code. */ assert( rc!=SQLITE_OK ); if( pHash ){ - sqlite3Fts3HashClear(&pHash->hash); + sqlite3Fts3HashClear(pHash); sqlite3_free(pHash); } return rc; } @@ -179111,11 +176292,11 @@ ){ char *p = *ppIter; assert( nDoclist>0 ); assert( *pbEof==0 ); - assert_fts3_nc( p || *piDocid==0 ); + assert( p || *piDocid==0 ); assert( !p || (p>aDoclist && p<&aDoclist[nDoclist]) ); if( p==0 ){ sqlite3_int64 iDocid = 0; char *pNext = 0; @@ -179975,12 +177156,12 @@ case FTSQUERY_OR: { Fts3Expr *pLeft = pExpr->pLeft; Fts3Expr *pRight = pExpr->pRight; sqlite3_int64 iCmp = DOCID_CMP(pLeft->iDocid, pRight->iDocid); - assert_fts3_nc( pLeft->bStart || pLeft->iDocid==pRight->iDocid ); - assert_fts3_nc( pRight->bStart || pLeft->iDocid==pRight->iDocid ); + assert( pLeft->bStart || pLeft->iDocid==pRight->iDocid ); + assert( pRight->bStart || pLeft->iDocid==pRight->iDocid ); if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){ fts3EvalNextRow(pCsr, pLeft, pRc); }else if( pLeft->bEof || iCmp>0 ){ fts3EvalNextRow(pCsr, pRight, pRc); @@ -180614,13 +177795,10 @@ while( rc==SQLITE_OK && !pNear->bEof ){ fts3EvalNextRow(pCsr, pNear, &rc); if( bEofSave==0 && pNear->iDocid==iDocid ) break; } assert( rc!=SQLITE_OK || pPhrase->bIncr==0 ); - if( rc==SQLITE_OK && pNear->bEof!=bEofSave ){ - rc = FTS_CORRUPT_VTAB; - } } if( bTreeEof ){ while( rc==SQLITE_OK && !pNear->bEof ){ fts3EvalNextRow(pCsr, pNear, &rc); } @@ -181039,11 +178217,10 @@ } if( fts3auxGrowStatArray(pCsr, 2) ) return SQLITE_NOMEM; memset(pCsr->aStat, 0, sizeof(struct Fts3auxColstats) * pCsr->nStat); iCol = 0; - rc = SQLITE_OK; while( iaStat[iCol+1].nDoc++; eState = 2; break; } } pCsr->iCol = 0; + rc = SQLITE_OK; }else{ pCsr->isEof = 1; } return rc; } @@ -181423,11 +178597,11 @@ /* ** Allocate nByte bytes of memory using sqlite3_malloc(). If successful, ** zero the memory before returning a pointer to it. If unsuccessful, ** return NULL. */ -SQLITE_PRIVATE void *sqlite3Fts3MallocZero(sqlite3_int64 nByte){ +static void *fts3MallocZero(sqlite3_int64 nByte){ void *pRet = sqlite3_malloc64(nByte); if( pRet ) memset(pRet, 0, nByte); return pRet; } @@ -181504,11 +178678,11 @@ sqlite3_int64 nByte; /* total space to allocate */ rc = pModule->xNext(pCursor, &zToken, &nToken, &iStart, &iEnd, &iPosition); if( rc==SQLITE_OK ){ nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase) + nToken; - pRet = (Fts3Expr *)sqlite3Fts3MallocZero(nByte); + pRet = (Fts3Expr *)fts3MallocZero(nByte); if( !pRet ){ rc = SQLITE_NOMEM; }else{ pRet->eType = FTSQUERY_PHRASE; pRet->pPhrase = (Fts3Phrase *)&pRet[1]; @@ -181759,11 +178933,11 @@ */ cNext = zInput[nKey]; if( fts3isspace(cNext) || cNext=='"' || cNext=='(' || cNext==')' || cNext==0 ){ - pRet = (Fts3Expr *)sqlite3Fts3MallocZero(sizeof(Fts3Expr)); + pRet = (Fts3Expr *)fts3MallocZero(sizeof(Fts3Expr)); if( !pRet ){ return SQLITE_NOMEM; } pRet->eType = pKey->eType; pRet->nNear = nNear; @@ -181938,11 +179112,11 @@ if( !sqlite3_fts3_enable_parentheses && p->eType==FTSQUERY_PHRASE && pParse->isNot ){ /* Create an implicit NOT operator. */ - Fts3Expr *pNot = sqlite3Fts3MallocZero(sizeof(Fts3Expr)); + Fts3Expr *pNot = fts3MallocZero(sizeof(Fts3Expr)); if( !pNot ){ sqlite3Fts3ExprFree(p); rc = SQLITE_NOMEM; goto exprparse_out; } @@ -181972,11 +179146,11 @@ if( isPhrase && !isRequirePhrase ){ /* Insert an implicit AND operator. */ Fts3Expr *pAnd; assert( pRet && pPrev ); - pAnd = sqlite3Fts3MallocZero(sizeof(Fts3Expr)); + pAnd = fts3MallocZero(sizeof(Fts3Expr)); if( !pAnd ){ sqlite3Fts3ExprFree(p); rc = SQLITE_NOMEM; goto exprparse_out; } @@ -184828,11 +182002,11 @@ /* ** Register the fts3tok module with database connection db. Return SQLITE_OK ** if successful or an error code if sqlite3_create_module() fails. */ -SQLITE_PRIVATE int sqlite3Fts3InitTok(sqlite3 *db, Fts3Hash *pHash, void(*xDestroy)(void*)){ +SQLITE_PRIVATE int sqlite3Fts3InitTok(sqlite3 *db, Fts3Hash *pHash){ static const sqlite3_module fts3tok_module = { 0, /* iVersion */ fts3tokConnectMethod, /* xCreate */ fts3tokConnectMethod, /* xConnect */ fts3tokBestIndexMethod, /* xBestIndex */ @@ -184857,13 +182031,11 @@ 0, /* xRollbackTo */ 0 /* xShadowName */ }; int rc; /* Return code */ - rc = sqlite3_create_module_v2( - db, "fts3tokenize", &fts3tok_module, (void*)pHash, xDestroy - ); + rc = sqlite3_create_module(db, "fts3tokenize", &fts3tok_module, (void*)pHash); return rc; } #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */ @@ -186204,22 +183376,12 @@ pReader->aNode = 0; if( pElem ){ char *aCopy; PendingList *pList = (PendingList *)fts3HashData(pElem); int nCopy = pList->nData+1; - - int nTerm = fts3HashKeysize(pElem); - if( (nTerm+1)>pReader->nTermAlloc ){ - sqlite3_free(pReader->zTerm); - pReader->zTerm = (char*)sqlite3_malloc((nTerm+1)*2); - if( !pReader->zTerm ) return SQLITE_NOMEM; - pReader->nTermAlloc = (nTerm+1)*2; - } - memcpy(pReader->zTerm, fts3HashKey(pElem), nTerm); - pReader->zTerm[nTerm] = '\0'; - pReader->nTerm = nTerm; - + pReader->zTerm = (char *)fts3HashKey(pElem); + pReader->nTerm = fts3HashKeysize(pElem); aCopy = (char*)sqlite3_malloc(nCopy); if( !aCopy ) return SQLITE_NOMEM; memcpy(aCopy, pList->aData, nCopy); pReader->nNode = pReader->nDoclist = nCopy; pReader->aNode = pReader->aDoclist = aCopy; @@ -186468,11 +183630,13 @@ ** Free all allocations associated with the iterator passed as the ** second argument. */ SQLITE_PRIVATE void sqlite3Fts3SegReaderFree(Fts3SegReader *pReader){ if( pReader ){ - sqlite3_free(pReader->zTerm); + if( !fts3SegReaderIsPending(pReader) ){ + sqlite3_free(pReader->zTerm); + } if( !fts3SegReaderIsRootOnly(pReader) ){ sqlite3_free(pReader->aNode); } sqlite3_blob_close(pReader->pBlob); } @@ -188660,11 +185824,11 @@ if( nPrefix>p->term.n || nSuffix>p->nNode-p->iOff || nSuffix==0 ){ return FTS_CORRUPT_VTAB; } blobGrowBuffer(&p->term, nPrefix+nSuffix, &rc); - if( rc==SQLITE_OK && ALWAYS(p->term.a!=0) ){ + if( rc==SQLITE_OK ){ memcpy(&p->term.a[nPrefix], &p->aNode[p->iOff], nSuffix); p->term.n = nPrefix+nSuffix; p->iOff += nSuffix; if( p->iChild==0 ){ p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &p->nDoclist); @@ -189054,15 +186218,11 @@ const char *zRhs, int nRhs /* RHS of comparison */ ){ int nCmp = MIN(nLhs, nRhs); int res; - if( nCmp && ALWAYS(zLhs) && ALWAYS(zRhs) ){ - res = memcmp(zLhs, zRhs, nCmp); - }else{ - res = 0; - } + res = (nCmp ? memcmp(zLhs, zRhs, nCmp) : 0); if( res==0 ) res = nLhs - nRhs; return res; } @@ -189702,11 +186862,11 @@ const char *aHint = sqlite3_column_blob(pSelect, 0); int nHint = sqlite3_column_bytes(pSelect, 0); if( aHint ){ blobGrowBuffer(pHint, nHint, &rc); if( rc==SQLITE_OK ){ - if( ALWAYS(pHint->a!=0) ) memcpy(pHint->a, aHint, nHint); + memcpy(pHint->a, aHint, nHint); pHint->n = nHint; } } } rc2 = sqlite3_reset(pSelect); @@ -190819,12 +187979,13 @@ MatchinfoBuffer *pRet; sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1) + sizeof(MatchinfoBuffer); sqlite3_int64 nStr = strlen(zMatchinfo); - pRet = sqlite3Fts3MallocZero(nByte + nStr+1); + pRet = sqlite3_malloc64(nByte + nStr+1); if( pRet ){ + memset(pRet, 0, nByte); pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet; pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0] + sizeof(u32)*((int)nElem+1); pRet->nElem = (int)nElem; pRet->zMatchinfo = ((char*)pRet) + nByte; @@ -191224,14 +188385,15 @@ /* Now that it is known how many phrases there are, allocate and zero ** the required space using malloc(). */ nByte = sizeof(SnippetPhrase) * nList; - sIter.aPhrase = (SnippetPhrase *)sqlite3Fts3MallocZero(nByte); + sIter.aPhrase = (SnippetPhrase *)sqlite3_malloc64(nByte); if( !sIter.aPhrase ){ return SQLITE_NOMEM; } + memset(sIter.aPhrase, 0, nByte); /* Initialize the contents of the SnippetIter object. Then iterate through ** the set of phrases in the expression to populate the aPhrase[] array. */ sIter.pCsr = pCsr; @@ -191791,16 +188953,14 @@ ** Advance the iterator passed as an argument to the next position. Return ** 1 if the iterator is at EOF or if it now points to the start of the ** position list for the next column. */ static int fts3LcsIteratorAdvance(LcsIterator *pIter){ - char *pRead; + char *pRead = pIter->pRead; sqlite3_int64 iRead; int rc = 0; - if( NEVER(pIter==0) ) return 1; - pRead = pIter->pRead; pRead += sqlite3Fts3GetVarint(pRead, &iRead); if( iRead==0 || iRead==1 ){ pRead = 0; rc = 1; }else{ @@ -191830,12 +188990,13 @@ int rc = SQLITE_OK; /* Allocate and populate the array of LcsIterator objects. The array ** contains one element for each matchable phrase in the query. **/ - aIter = sqlite3Fts3MallocZero(sizeof(LcsIterator) * pCsr->nPhrase); + aIter = sqlite3_malloc64(sizeof(LcsIterator) * pCsr->nPhrase); if( !aIter ) return SQLITE_NOMEM; + memset(aIter, 0, sizeof(LcsIterator) * pCsr->nPhrase); (void)fts3ExprIterate(pCsr->pExpr, fts3MatchinfoLcsCb, (void*)aIter); for(i=0; inPhrase; i++){ LcsIterator *pIter = &aIter[i]; nToken -= pIter->pExpr->pPhrase->nToken; @@ -192292,11 +189453,11 @@ /* Count the number of terms in the query */ rc = fts3ExprLoadDoclists(pCsr, 0, &nToken); if( rc!=SQLITE_OK ) goto offsets_out; /* Allocate the array of TermOffset iterators. */ - sCtx.aTerm = (TermOffset *)sqlite3Fts3MallocZero(sizeof(TermOffset)*nToken); + sCtx.aTerm = (TermOffset *)sqlite3_malloc64(sizeof(TermOffset)*nToken); if( 0==sCtx.aTerm ){ rc = SQLITE_NOMEM; goto offsets_out; } sCtx.iDocid = pCsr->iPrevId; @@ -192313,17 +189474,17 @@ int iEnd = 0; int iCurrent = 0; const char *zDoc; int nDoc; - /* Initialize the contents of sCtx.aTerm[] for column iCol. This - ** operation may fail if the database contains corrupt records. + /* Initialize the contents of sCtx.aTerm[] for column iCol. There is + ** no way that this operation can fail, so the return code from + ** fts3ExprIterate() can be discarded. */ sCtx.iCol = iCol; sCtx.iTerm = 0; - rc = fts3ExprIterate(pCsr->pExpr, fts3ExprTermOffsetInit, (void*)&sCtx); - if( rc!=SQLITE_OK ) goto offsets_out; + (void)fts3ExprIterate(pCsr->pExpr, fts3ExprTermOffsetInit, (void*)&sCtx); /* Retreive the text stored in column iCol. If an SQL NULL is stored ** in column iCol, jump immediately to the next iteration of the loop. ** If an OOM occurs while retrieving the data (this can happen if SQLite ** needs to transform the data from utf-16 to utf-8), return SQLITE_NOMEM @@ -193218,11 +190379,11 @@ } #endif /* defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) */ #endif /* !defined(SQLITE_DISABLE_FTS3_UNICODE) */ /************** End of fts3_unicode2.c ***************************************/ -/************** Begin file json.c ********************************************/ +/************** Begin file json1.c *******************************************/ /* ** 2015-08-12 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: @@ -193231,23 +190392,63 @@ ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ****************************************************************************** ** -** This SQLite JSON functions. +** This SQLite extension implements JSON functions. The interface is +** modeled after MySQL JSON functions: ** -** This file began as an extension in ext/misc/json1.c in 2015. That -** extension proved so useful that it has now been moved into the core. +** https://dev.mysql.com/doc/refman/5.7/en/json.html ** ** For the time being, all JSON is stored as pure text. (We might add ** a JSONB type in the future which stores a binary encoding of JSON in ** a BLOB, but there is no support for JSONB in the current implementation. ** This implementation parses JSON text at 250 MB/s, so it is hard to see ** how JSONB might improve on that.) */ -#ifndef SQLITE_OMIT_JSON -/* #include "sqliteInt.h" */ +#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_JSON1) +#if !defined(SQLITEINT_H) +/* #include "sqlite3ext.h" */ +#endif +SQLITE_EXTENSION_INIT1 +/* #include */ +/* #include */ +/* #include */ +/* #include */ + +/* Mark a function parameter as unused, to suppress nuisance compiler +** warnings. */ +#ifndef UNUSED_PARAM +# define UNUSED_PARAM(X) (void)(X) +#endif + +#ifndef LARGEST_INT64 +# define LARGEST_INT64 (0xffffffff|(((sqlite3_int64)0x7fffffff)<<32)) +# define SMALLEST_INT64 (((sqlite3_int64)-1) - LARGEST_INT64) +#endif + +#ifndef deliberate_fall_through +# define deliberate_fall_through +#endif + +/* +** Versions of isspace(), isalnum() and isdigit() to which it is safe +** to pass signed char values. +*/ +#ifdef sqlite3Isdigit + /* Use the SQLite core versions if this routine is part of the + ** SQLite amalgamation */ +# define safe_isdigit(x) sqlite3Isdigit(x) +# define safe_isalnum(x) sqlite3Isalnum(x) +# define safe_isxdigit(x) sqlite3Isxdigit(x) +#else + /* Use the standard library for separate compilation */ +#include /* amalgamator: keep */ +# define safe_isdigit(x) isdigit((unsigned char)(x)) +# define safe_isalnum(x) isalnum((unsigned char)(x)) +# define safe_isxdigit(x) isxdigit((unsigned char)(x)) +#endif /* ** Growing our own isspace() routine this way is twice as fast as ** the library isspace() function, resulting in a 7% overall performance ** increase for the parser. (Ubuntu14.10 gcc 4.8.4 x64 with -Os). @@ -193268,16 +190469,19 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -#define fast_isspace(x) (jsonIsSpace[(unsigned char)x]) +#define safe_isspace(x) (jsonIsSpace[(unsigned char)x]) -#if !defined(SQLITE_DEBUG) && !defined(SQLITE_COVERAGE_TEST) -# define VVA(X) -#else -# define VVA(X) X +#ifndef SQLITE_AMALGAMATION + /* Unsigned integer types. These are already defined in the sqliteInt.h, + ** but the definitions need to be repeated for separate compilation. */ + typedef sqlite3_uint64 u64; + typedef unsigned int u32; + typedef unsigned short int u16; + typedef unsigned char u8; #endif /* Objects */ typedef struct JsonString JsonString; typedef struct JsonNode JsonNode; @@ -193332,18 +190536,17 @@ /* A single node of parsed JSON */ struct JsonNode { u8 eType; /* One of the JSON_ type values */ u8 jnFlags; /* JNODE flags */ - u8 eU; /* Which union element to use */ u32 n; /* Bytes of content, or number of sub-nodes */ union { - const char *zJContent; /* 1: Content for INT, REAL, and STRING */ - u32 iAppend; /* 2: More terms for ARRAY and OBJECT */ - u32 iKey; /* 3: Key for ARRAY objects in json_tree() */ - u32 iReplace; /* 4: Replacement content for JNODE_REPLACE */ - JsonNode *pPatch; /* 5: Node chain of patch for JNODE_PATCH */ + const char *zJContent; /* Content for INT, REAL, and STRING */ + u32 iAppend; /* More terms for ARRAY and OBJECT */ + u32 iKey; /* Key for ARRAY objects in json_tree() */ + u32 iReplace; /* Replacement content for JNODE_REPLACE */ + JsonNode *pPatch; /* Node chain of patch for JNODE_PATCH */ } u; }; /* A completely parsed JSON string */ @@ -193617,18 +190820,15 @@ static void jsonRenderNode( JsonNode *pNode, /* The node to render */ JsonString *pOut, /* Write JSON here */ sqlite3_value **aReplace /* Replacement values */ ){ - assert( pNode!=0 ); if( pNode->jnFlags & (JNODE_REPLACE|JNODE_PATCH) ){ - if( (pNode->jnFlags & JNODE_REPLACE)!=0 && ALWAYS(aReplace!=0) ){ - assert( pNode->eU==4 ); + if( pNode->jnFlags & JNODE_REPLACE ){ jsonAppendValue(pOut, aReplace[pNode->u.iReplace]); return; } - assert( pNode->eU==5 ); pNode = pNode->u.pPatch; } switch( pNode->eType ){ default: { assert( pNode->eType==JSON_NULL ); @@ -193643,19 +190843,17 @@ jsonAppendRaw(pOut, "false", 5); break; } case JSON_STRING: { if( pNode->jnFlags & JNODE_RAW ){ - assert( pNode->eU==1 ); jsonAppendString(pOut, pNode->u.zJContent, pNode->n); break; } /* no break */ deliberate_fall_through } case JSON_REAL: case JSON_INT: { - assert( pNode->eU==1 ); jsonAppendRaw(pOut, pNode->u.zJContent, pNode->n); break; } case JSON_ARRAY: { u32 j = 1; @@ -193667,11 +190865,10 @@ jsonRenderNode(&pNode[j], pOut, aReplace); } j += jsonNodeSize(&pNode[j]); } if( (pNode->jnFlags & JNODE_APPEND)==0 ) break; - assert( pNode->eU==2 ); pNode = &pNode[pNode->u.iAppend]; j = 1; } jsonAppendChar(pOut, ']'); break; @@ -193688,11 +190885,10 @@ jsonRenderNode(&pNode[j+1], pOut, aReplace); } j += 1 + jsonNodeSize(&pNode[j+1]); } if( (pNode->jnFlags & JNODE_APPEND)==0 ) break; - assert( pNode->eU==2 ); pNode = &pNode[pNode->u.iAppend]; j = 1; } jsonAppendChar(pOut, '}'); break; @@ -193733,14 +190929,14 @@ /* ** Convert a 4-byte hex string into an integer */ static u32 jsonHexToInt4(const char *z){ u32 v; - assert( sqlite3Isxdigit(z[0]) ); - assert( sqlite3Isxdigit(z[1]) ); - assert( sqlite3Isxdigit(z[2]) ); - assert( sqlite3Isxdigit(z[3]) ); + assert( safe_isxdigit(z[0]) ); + assert( safe_isxdigit(z[1]) ); + assert( safe_isxdigit(z[2]) ); + assert( safe_isxdigit(z[3]) ); v = (jsonHexToInt(z[0])<<12) + (jsonHexToInt(z[1])<<8) + (jsonHexToInt(z[2])<<4) + jsonHexToInt(z[3]); return v; @@ -193768,13 +190964,11 @@ sqlite3_result_int(pCtx, 0); break; } case JSON_INT: { sqlite3_int64 i = 0; - const char *z; - assert( pNode->eU==1 ); - z = pNode->u.zJContent; + const char *z = pNode->u.zJContent; if( z[0]=='-' ){ z++; } while( z[0]>='0' && z[0]<='9' ){ unsigned v = *(z++) - '0'; if( i>=LARGEST_INT64/10 ){ if( i>LARGEST_INT64/10 ) goto int_as_real; @@ -193798,16 +190992,13 @@ int_as_real: ; /* no break */ deliberate_fall_through } case JSON_REAL: { double r; #ifdef SQLITE_AMALGAMATION - const char *z; - assert( pNode->eU==1 ); - z = pNode->u.zJContent; + const char *z = pNode->u.zJContent; sqlite3AtoF(z, &r, sqlite3Strlen30(z), SQLITE_UTF8); #else - assert( pNode->eU==1 ); r = strtod(pNode->u.zJContent, 0); #endif sqlite3_result_double(pCtx, r); break; } @@ -193814,30 +191005,26 @@ case JSON_STRING: { #if 0 /* Never happens because JNODE_RAW is only set by json_set(), ** json_insert() and json_replace() and those routines do not ** call jsonReturn() */ if( pNode->jnFlags & JNODE_RAW ){ - assert( pNode->eU==1 ); sqlite3_result_text(pCtx, pNode->u.zJContent, pNode->n, SQLITE_TRANSIENT); }else #endif assert( (pNode->jnFlags & JNODE_RAW)==0 ); if( (pNode->jnFlags & JNODE_ESCAPE)==0 ){ /* JSON formatted without any backslash-escapes */ - assert( pNode->eU==1 ); sqlite3_result_text(pCtx, pNode->u.zJContent+1, pNode->n-2, SQLITE_TRANSIENT); }else{ /* Translate JSON formatted string into raw text */ u32 i; u32 n = pNode->n; - const char *z; + const char *z = pNode->u.zJContent; char *zOut; u32 j; - assert( pNode->eU==1 ); - z = pNode->u.zJContent; zOut = sqlite3_malloc( n+1 ); if( zOut==0 ){ sqlite3_result_error_nomem(pCtx); break; } @@ -193954,17 +191141,16 @@ u32 eType, /* Node type */ u32 n, /* Content size or sub-node count */ const char *zContent /* Content */ ){ JsonNode *p; - if( pParse->aNode==0 || pParse->nNode>=pParse->nAlloc ){ + if( pParse->nNode>=pParse->nAlloc ){ return jsonParseAddNodeExpand(pParse, eType, n, zContent); } p = &pParse->aNode[pParse->nNode]; p->eType = (u8)eType; p->jnFlags = 0; - VVA( p->eU = zContent ? 1 : 0 ); p->n = n; p->u.zJContent = zContent; return pParse->nNode++; } @@ -193971,11 +191157,11 @@ /* ** Return true if z[] begins with 4 (or more) hexadecimal digits */ static int jsonIs4Hex(const char *z){ int i; - for(i=0; i<4; i++) if( !sqlite3Isxdigit(z[i]) ) return 0; + for(i=0; i<4; i++) if( !safe_isxdigit(z[i]) ) return 0; return 1; } /* ** Parse a single JSON value which begins at pParse->zJson[i]. Return the @@ -193990,17 +191176,17 @@ u32 j; int iThis; int x; JsonNode *pNode; const char *z = pParse->zJson; - while( fast_isspace(z[i]) ){ i++; } + while( safe_isspace(z[i]) ){ i++; } if( (c = z[i])=='{' ){ /* Parse object */ iThis = jsonParseAddNode(pParse, JSON_OBJECT, 0, 0); if( iThis<0 ) return -1; for(j=i+1;;j++){ - while( fast_isspace(z[j]) ){ j++; } + while( safe_isspace(z[j]) ){ j++; } if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1; x = jsonParseValue(pParse, j); if( x<0 ){ pParse->iDepth--; if( x==(-2) && pParse->nNode==(u32)iThis+1 ) return j+1; @@ -194009,18 +191195,18 @@ if( pParse->oom ) return -1; pNode = &pParse->aNode[pParse->nNode-1]; if( pNode->eType!=JSON_STRING ) return -1; pNode->jnFlags |= JNODE_LABEL; j = x; - while( fast_isspace(z[j]) ){ j++; } + while( safe_isspace(z[j]) ){ j++; } if( z[j]!=':' ) return -1; j++; x = jsonParseValue(pParse, j); pParse->iDepth--; if( x<0 ) return -1; j = x; - while( fast_isspace(z[j]) ){ j++; } + while( safe_isspace(z[j]) ){ j++; } c = z[j]; if( c==',' ) continue; if( c!='}' ) return -1; break; } @@ -194028,22 +191214,21 @@ return j+1; }else if( c=='[' ){ /* Parse array */ iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0); if( iThis<0 ) return -1; - memset(&pParse->aNode[iThis].u, 0, sizeof(pParse->aNode[iThis].u)); for(j=i+1;;j++){ - while( fast_isspace(z[j]) ){ j++; } + while( safe_isspace(z[j]) ){ j++; } if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1; x = jsonParseValue(pParse, j); pParse->iDepth--; if( x<0 ){ if( x==(-3) && pParse->nNode==(u32)iThis+1 ) return j+1; return -1; } j = x; - while( fast_isspace(z[j]) ){ j++; } + while( safe_isspace(z[j]) ){ j++; } c = z[j]; if( c==',' ) continue; if( c!=']' ) return -1; break; } @@ -194076,21 +191261,21 @@ jsonParseAddNode(pParse, JSON_STRING, j+1-i, &z[i]); if( !pParse->oom ) pParse->aNode[pParse->nNode-1].jnFlags = jnFlags; return j+1; }else if( c=='n' && strncmp(z+i,"null",4)==0 - && !sqlite3Isalnum(z[i+4]) ){ + && !safe_isalnum(z[i+4]) ){ jsonParseAddNode(pParse, JSON_NULL, 0, 0); return i+4; }else if( c=='t' && strncmp(z+i,"true",4)==0 - && !sqlite3Isalnum(z[i+4]) ){ + && !safe_isalnum(z[i+4]) ){ jsonParseAddNode(pParse, JSON_TRUE, 0, 0); return i+4; }else if( c=='f' && strncmp(z+i,"false",5)==0 - && !sqlite3Isalnum(z[i+5]) ){ + && !safe_isalnum(z[i+5]) ){ jsonParseAddNode(pParse, JSON_FALSE, 0, 0); return i+5; }else if( c=='-' || (c>='0' && c<='9') ){ /* Parse number */ u8 seenDP = 0; @@ -194157,11 +191342,11 @@ pParse->zJson = zJson; i = jsonParseValue(pParse, 0); if( pParse->oom ) i = -1; if( i>0 ){ assert( pParse->iDepth==0 ); - while( fast_isspace(zJson[i]) ) i++; + while( safe_isspace(zJson[i]) ) i++; if( zJson[i] ) i = -1; } if( i<=0 ){ if( pCtx!=0 ){ if( pParse->oom ){ @@ -194293,11 +191478,10 @@ /* ** Compare the OBJECT label at pNode against zKey,nKey. Return true on ** a match. */ static int jsonLabelCompare(JsonNode *pNode, const char *zKey, u32 nKey){ - assert( pNode->eU==1 ); if( pNode->jnFlags & JNODE_RAW ){ if( pNode->n!=nKey ) return 0; return strncmp(pNode->u.zJContent, zKey, nKey)==0; }else{ if( pNode->n!=nKey+2 ) return 0; @@ -194340,19 +191524,18 @@ i++; }else{ *pzErr = zPath; return 0; } - testcase( nKey==0 ); }else{ zKey = zPath; for(i=0; zPath[i] && zPath[i]!='.' && zPath[i]!='['; i++){} nKey = i; - if( nKey==0 ){ - *pzErr = zPath; - return 0; - } + } + if( nKey==0 ){ + *pzErr = zPath; + return 0; } j = 1; for(;;){ while( j<=pRoot->n ){ if( jsonLabelCompare(pRoot+j, zKey, nKey) ){ @@ -194360,11 +191543,10 @@ } j++; j += jsonNodeSize(&pRoot[j]); } if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break; - assert( pRoot->eU==2 ); iRoot += pRoot->u.iAppend; pRoot = &pParse->aNode[iRoot]; j = 1; } if( pApnd ){ @@ -194375,22 +191557,20 @@ zPath += i; pNode = jsonLookupAppend(pParse, zPath, pApnd, pzErr); if( pParse->oom ) return 0; if( pNode ){ pRoot = &pParse->aNode[iRoot]; - assert( pRoot->eU==0 ); pRoot->u.iAppend = iStart - iRoot; pRoot->jnFlags |= JNODE_APPEND; - VVA( pRoot->eU = 2 ); pParse->aNode[iLabel].jnFlags |= JNODE_RAW; } return pNode; } }else if( zPath[0]=='[' ){ i = 0; j = 1; - while( sqlite3Isdigit(zPath[j]) ){ + while( safe_isdigit(zPath[j]) ){ i = i*10 + zPath[j] - '0'; j++; } if( j<2 || zPath[j]!=']' ){ if( zPath[1]=='#' ){ @@ -194401,23 +191581,22 @@ while( j<=pBase->n ){ if( (pBase[j].jnFlags & JNODE_REMOVE)==0 ) i++; j += jsonNodeSize(&pBase[j]); } if( (pBase->jnFlags & JNODE_APPEND)==0 ) break; - assert( pBase->eU==2 ); iBase += pBase->u.iAppend; pBase = &pParse->aNode[iBase]; j = 1; } j = 2; - if( zPath[2]=='-' && sqlite3Isdigit(zPath[3]) ){ + if( zPath[2]=='-' && safe_isdigit(zPath[3]) ){ unsigned int x = 0; j = 3; do{ x = x*10 + zPath[j] - '0'; j++; - }while( sqlite3Isdigit(zPath[j]) ); + }while( safe_isdigit(zPath[j]) ); if( x>i ) return 0; i -= x; } if( zPath[j]!=']' ){ *pzErr = zPath; @@ -194435,11 +191614,10 @@ while( j<=pRoot->n && (i>0 || (pRoot[j].jnFlags & JNODE_REMOVE)!=0) ){ if( (pRoot[j].jnFlags & JNODE_REMOVE)==0 ) i--; j += jsonNodeSize(&pRoot[j]); } if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break; - assert( pRoot->eU==2 ); iRoot += pRoot->u.iAppend; pRoot = &pParse->aNode[iRoot]; j = 1; } if( j<=pRoot->n ){ @@ -194451,14 +191629,12 @@ iStart = jsonParseAddNode(pParse, JSON_ARRAY, 1, 0); pNode = jsonLookupAppend(pParse, zPath, pApnd, pzErr); if( pParse->oom ) return 0; if( pNode ){ pRoot = &pParse->aNode[iRoot]; - assert( pRoot->eU==0 ); pRoot->u.iAppend = iStart - iRoot; pRoot->jnFlags |= JNODE_APPEND; - VVA( pRoot->eU = 2 ); } return pNode; } }else{ *pzErr = zPath; @@ -194608,17 +191784,13 @@ }else{ zType = jsonType[x.aNode[i].eType]; } jsonPrintf(100, &s,"node %3u: %7s n=%-4d up=%-4d", i, zType, x.aNode[i].n, x.aUp[i]); - assert( x.aNode[i].eU==0 || x.aNode[i].eU==1 ); if( x.aNode[i].u.zJContent!=0 ){ - assert( x.aNode[i].eU==1 ); jsonAppendRaw(&s, " ", 1); jsonAppendRaw(&s, x.aNode[i].u.zJContent, x.aNode[i].n); - }else{ - assert( x.aNode[i].eU==0 ); } jsonAppendRaw(&s, "\n", 1); } jsonParseReset(&x); jsonResult(&s); @@ -194632,11 +191804,11 @@ static void jsonTest1Func( sqlite3_context *ctx, int argc, sqlite3_value **argv ){ - UNUSED_PARAMETER(argc); + UNUSED_PARAM(argc); sqlite3_result_int(ctx, sqlite3_value_subtype(argv[0])==JSON_SUBTYPE); } #endif /* SQLITE_DEBUG */ /**************************************************************************** @@ -194653,11 +191825,11 @@ sqlite3_context *ctx, int argc, sqlite3_value **argv ){ JsonString jx; - UNUSED_PARAMETER(argc); + UNUSED_PARAM(argc); jsonInit(&jx, ctx); jsonAppendValue(&jx, argv[0]); jsonResult(&jx); sqlite3_result_subtype(ctx, JSON_SUBTYPE); @@ -194724,118 +191896,55 @@ } } sqlite3_result_int64(ctx, n); } -/* -** Bit values for the flags passed into jsonExtractFunc() or -** jsonSetFunc() via the user-data value. -*/ -#define JSON_JSON 0x01 /* Result is always JSON */ -#define JSON_SQL 0x02 /* Result is always SQL */ -#define JSON_ABPATH 0x03 /* Allow abbreviated JSON path specs */ -#define JSON_ISSET 0x04 /* json_set(), not json_insert() */ - /* ** json_extract(JSON, PATH, ...) -** "->"(JSON,PATH) -** "->>"(JSON,PATH) -** -** Return the element described by PATH. Return NULL if that PATH element -** is not found. -** -** If JSON_JSON is set or if more that one PATH argument is supplied then -** always return a JSON representation of the result. If JSON_SQL is set, -** then always return an SQL representation of the result. If neither flag -** is present and argc==2, then return JSON for objects and arrays and SQL -** for all other values. -** -** When multiple PATH arguments are supplied, the result is a JSON array -** containing the result of each PATH. -** -** Abbreviated JSON path expressions are allows if JSON_ABPATH, for -** compatibility with PG. +** +** Return the element described by PATH. Return NULL if there is no +** PATH element. If there are multiple PATHs, then return a JSON array +** with the result from each path. Throw an error if the JSON or any PATH +** is malformed. */ static void jsonExtractFunc( sqlite3_context *ctx, int argc, sqlite3_value **argv ){ JsonParse *p; /* The parse */ JsonNode *pNode; const char *zPath; - int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(ctx)); JsonString jx; + int i; if( argc<2 ) return; p = jsonParseCached(ctx, argv, ctx); if( p==0 ) return; - if( argc==2 ){ - /* With a single PATH argument */ - zPath = (const char*)sqlite3_value_text(argv[1]); - if( zPath==0 ) return; - if( flags & JSON_ABPATH ){ - if( zPath[0]!='$' ){ - /* The -> and ->> operators accept abbreviated PATH arguments. This - ** is mostly for compatibility with PostgreSQL, but also for - ** convenience. - ** - ** NUMBER ==> $[NUMBER] // PG compatible - ** LABEL ==> $.LABEL // PG compatible - ** [NUMBER] ==> $[NUMBER] // Not PG. Purely for convenience - */ - jsonInit(&jx, ctx); - if( sqlite3Isdigit(zPath[0]) ){ - jsonAppendRaw(&jx, "$[", 2); - jsonAppendRaw(&jx, zPath, (int)strlen(zPath)); - jsonAppendRaw(&jx, "]", 2); - }else{ - jsonAppendRaw(&jx, "$.", 1 + (zPath[0]!='[')); - jsonAppendRaw(&jx, zPath, (int)strlen(zPath)); - jsonAppendChar(&jx, 0); - } - pNode = jx.bErr ? 0 : jsonLookup(p, jx.zBuf, 0, ctx); - jsonReset(&jx); - }else{ - pNode = jsonLookup(p, zPath, 0, ctx); - } - if( pNode ){ - if( flags & JSON_JSON ){ - jsonReturnJson(pNode, ctx, 0); - }else{ - jsonReturn(pNode, ctx, 0); - sqlite3_result_subtype(ctx, 0); - } - } - }else{ - pNode = jsonLookup(p, zPath, 0, ctx); - if( p->nErr==0 && pNode ) jsonReturn(pNode, ctx, 0); - } - }else{ - /* Two or more PATH arguments results in a JSON array with each - ** element of the array being the value selected by one of the PATHs */ - int i; - jsonInit(&jx, ctx); - jsonAppendChar(&jx, '['); - for(i=1; inErr ) break; + jsonInit(&jx, ctx); + jsonAppendChar(&jx, '['); + for(i=1; inErr ) break; + if( argc>2 ){ jsonAppendSeparator(&jx); if( pNode ){ jsonRenderNode(pNode, &jx, 0); }else{ jsonAppendRaw(&jx, "null", 4); } - } - if( i==argc ){ - jsonAppendChar(&jx, ']'); - jsonResult(&jx); - sqlite3_result_subtype(ctx, JSON_SUBTYPE); - } - jsonReset(&jx); - } + }else if( pNode ){ + jsonReturn(pNode, ctx, 0); + } + } + if( argc>2 && i==argc ){ + jsonAppendChar(&jx, ']'); + jsonResult(&jx); + sqlite3_result_subtype(ctx, JSON_SUBTYPE); + } + jsonReset(&jx); } /* This is the RFC 7396 MergePatch algorithm. */ static JsonNode *jsonMergePatch( @@ -194860,11 +191969,10 @@ for(i=1; in; i += jsonNodeSize(&pPatch[i+1])+1){ u32 nKey; const char *zKey; assert( pPatch[i].eType==JSON_STRING ); assert( pPatch[i].jnFlags & JNODE_LABEL ); - assert( pPatch[i].eU==1 ); nKey = pPatch[i].n; zKey = pPatch[i].u.zJContent; assert( (pPatch[i].jnFlags & JNODE_RAW)==0 ); for(j=1; jn; j += jsonNodeSize(&pTarget[j+1])+1 ){ assert( pTarget[j].eType==JSON_STRING ); @@ -194877,16 +191985,10 @@ }else{ JsonNode *pNew = jsonMergePatch(pParse, iTarget+j+1, &pPatch[i+1]); if( pNew==0 ) return 0; pTarget = &pParse->aNode[iTarget]; if( pNew!=&pTarget[j+1] ){ - assert( pTarget[j+1].eU==0 - || pTarget[j+1].eU==1 - || pTarget[j+1].eU==2 ); - testcase( pTarget[j+1].eU==1 ); - testcase( pTarget[j+1].eU==2 ); - VVA( pTarget[j+1].eU = 5 ); pTarget[j+1].u.pPatch = pNew; pTarget[j+1].jnFlags |= JNODE_PATCH; } } break; @@ -194898,18 +192000,13 @@ jsonParseAddNode(pParse, JSON_STRING, nKey, zKey); iPatch = jsonParseAddNode(pParse, JSON_TRUE, 0, 0); if( pParse->oom ) return 0; jsonRemoveAllNulls(pPatch); pTarget = &pParse->aNode[iTarget]; - assert( pParse->aNode[iRoot].eU==0 || pParse->aNode[iRoot].eU==2 ); - testcase( pParse->aNode[iRoot].eU==2 ); pParse->aNode[iRoot].jnFlags |= JNODE_APPEND; - VVA( pParse->aNode[iRoot].eU = 2 ); pParse->aNode[iRoot].u.iAppend = iStart - iRoot; iRoot = iStart; - assert( pParse->aNode[iPatch].eU==0 ); - VVA( pParse->aNode[iPatch].eU = 5 ); pParse->aNode[iPatch].jnFlags |= JNODE_PATCH; pParse->aNode[iPatch].u.pPatch = &pPatch[i+1]; } } return pTarget; @@ -194927,11 +192024,11 @@ ){ JsonParse x; /* The JSON that is being patched */ JsonParse y; /* The patch */ JsonNode *pResult; /* The result of the merge */ - UNUSED_PARAMETER(argc); + UNUSED_PARAM(argc); if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return; if( jsonParse(&y, ctx, (const char*)sqlite3_value_text(argv[1])) ){ jsonParseReset(&x); return; } @@ -195047,27 +192144,22 @@ for(i=1; i<(u32)argc; i+=2){ zPath = (const char*)sqlite3_value_text(argv[i]); pNode = jsonLookup(&x, zPath, 0, ctx); if( x.nErr ) goto replace_err; if( pNode ){ - assert( pNode->eU==0 || pNode->eU==1 || pNode->eU==4 ); - testcase( pNode->eU!=0 && pNode->eU!=1 ); pNode->jnFlags |= (u8)JNODE_REPLACE; - VVA( pNode->eU = 4 ); pNode->u.iReplace = i + 1; } } if( x.aNode[0].jnFlags & JNODE_REPLACE ){ - assert( x.aNode[0].eU==4 ); sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]); }else{ jsonReturnJson(x.aNode, ctx, argv); } replace_err: jsonParseReset(&x); } - /* ** json_set(JSON, PATH, VALUE, ...) ** ** Set the value at PATH to VALUE. Create the PATH if it does not already @@ -195087,11 +192179,11 @@ JsonParse x; /* The parse */ JsonNode *pNode; const char *zPath; u32 i; int bApnd; - int bIsSet = sqlite3_user_data(ctx)!=0; + int bIsSet = *(int*)sqlite3_user_data(ctx); if( argc<1 ) return; if( (argc&1)==0 ) { jsonWrongNumArgs(ctx, bIsSet ? "set" : "insert"); return; @@ -195106,19 +192198,15 @@ sqlite3_result_error_nomem(ctx); goto jsonSetDone; }else if( x.nErr ){ goto jsonSetDone; }else if( pNode && (bApnd || bIsSet) ){ - testcase( pNode->eU!=0 && pNode->eU!=1 ); - assert( pNode->eU!=3 && pNode->eU!=5 ); - VVA( pNode->eU = 4 ); pNode->jnFlags |= (u8)JNODE_REPLACE; pNode->u.iReplace = i + 1; } } if( x.aNode[0].jnFlags & JNODE_REPLACE ){ - assert( x.aNode[0].eU==4 ); sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]); }else{ jsonReturnJson(x.aNode, ctx, argv); } jsonSetDone: @@ -195127,12 +192215,12 @@ /* ** json_type(JSON) ** json_type(JSON, PATH) ** -** Return the top-level "type" of a JSON string. json_type() raises an -** error if either the JSON or PATH inputs are not well-formed. +** Return the top-level "type" of a JSON string. Throw an error if +** either the JSON or PATH inputs are not well-formed. */ static void jsonTypeFunc( sqlite3_context *ctx, int argc, sqlite3_value **argv @@ -195164,11 +192252,11 @@ sqlite3_context *ctx, int argc, sqlite3_value **argv ){ JsonParse *p; /* The parse */ - UNUSED_PARAMETER(argc); + UNUSED_PARAM(argc); p = jsonParseCached(ctx, argv, 0); sqlite3_result_int(ctx, p!=0); } @@ -195184,11 +192272,11 @@ sqlite3_context *ctx, int argc, sqlite3_value **argv ){ JsonString *pStr; - UNUSED_PARAMETER(argc); + UNUSED_PARAM(argc); pStr = (JsonString*)sqlite3_aggregate_context(ctx, sizeof(*pStr)); if( pStr ){ if( pStr->zBuf==0 ){ jsonInit(pStr, ctx); jsonAppendChar(pStr, '['); @@ -195244,12 +192332,12 @@ int inStr = 0; int nNest = 0; char *z; char c; JsonString *pStr; - UNUSED_PARAMETER(argc); - UNUSED_PARAMETER(argv); + UNUSED_PARAM(argc); + UNUSED_PARAM(argv); pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0); #ifdef NEVER /* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will ** always have been called to initalize it */ if( NEVER(!pStr) ) return; @@ -195289,11 +192377,11 @@ sqlite3_value **argv ){ JsonString *pStr; const char *z; u32 n; - UNUSED_PARAMETER(argc); + UNUSED_PARAM(argc); pStr = (JsonString*)sqlite3_aggregate_context(ctx, sizeof(*pStr)); if( pStr ){ if( pStr->zBuf==0 ){ jsonInit(pStr, ctx); jsonAppendChar(pStr, '{'); @@ -195380,14 +192468,14 @@ ** the last two columns in the table. Should this ever changes, be ** sure to update the xBestIndex method. */ #define JEACH_JSON 8 #define JEACH_ROOT 9 - UNUSED_PARAMETER(pzErr); - UNUSED_PARAMETER(argv); - UNUSED_PARAMETER(argc); - UNUSED_PARAMETER(pAux); + UNUSED_PARAM(pzErr); + UNUSED_PARAM(argv); + UNUSED_PARAM(argc); + UNUSED_PARAM(pAux); rc = sqlite3_declare_vtab(db, "CREATE TABLE x(key,value,type,atom,id,parent,fullkey,path," "json HIDDEN,root HIDDEN)"); if( rc==SQLITE_OK ){ pNew = *ppVtab = sqlite3_malloc( sizeof(*pNew) ); @@ -195406,11 +192494,11 @@ /* constructor for a JsonEachCursor object for json_each(). */ static int jsonEachOpenEach(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){ JsonEachCursor *pCur; - UNUSED_PARAMETER(p); + UNUSED_PARAM(p); pCur = sqlite3_malloc( sizeof(*pCur) ); if( pCur==0 ) return SQLITE_NOMEM; memset(pCur, 0, sizeof(*pCur)); *ppCursor = &pCur->base; return SQLITE_OK; @@ -195465,13 +192553,10 @@ if( p->iiEnd ){ u32 iUp = p->sParse.aUp[p->i]; JsonNode *pUp = &p->sParse.aNode[iUp]; p->eType = pUp->eType; if( pUp->eType==JSON_ARRAY ){ - assert( pUp->eU==0 || pUp->eU==3 ); - testcase( pUp->eU==3 ); - VVA( pUp->eU = 3 ); if( iUp==p->i-1 ){ pUp->u.iKey = 0; }else{ pUp->u.iKey++; } @@ -195496,37 +192581,10 @@ } } return SQLITE_OK; } -/* Append an object label to the JSON Path being constructed -** in pStr. -*/ -static void jsonAppendObjectPathElement( - JsonString *pStr, - JsonNode *pNode -){ - int jj, nn; - const char *z; - assert( pNode->eType==JSON_STRING ); - assert( pNode->jnFlags & JNODE_LABEL ); - assert( pNode->eU==1 ); - z = pNode->u.zJContent; - nn = pNode->n; - assert( nn>=2 ); - assert( z[0]=='"' ); - assert( z[nn-1]=='"' ); - if( nn>2 && sqlite3Isalpha(z[1]) ){ - for(jj=2; jjsParse.aUp[i]; jsonEachComputePath(p, pStr, iUp); pNode = &p->sParse.aNode[i]; pUp = &p->sParse.aNode[iUp]; if( pUp->eType==JSON_ARRAY ){ - assert( pUp->eU==3 || (pUp->eU==0 && pUp->u.iKey==0) ); - testcase( pUp->eU==0 ); jsonPrintf(30, pStr, "[%d]", pUp->u.iKey); }else{ assert( pUp->eType==JSON_OBJECT ); if( (pNode->jnFlags & JNODE_LABEL)==0 ) pNode--; - jsonAppendObjectPathElement(pStr, pNode); + assert( pNode->eType==JSON_STRING ); + assert( pNode->jnFlags & JNODE_LABEL ); + jsonPrintf(pNode->n+1, pStr, ".%.*s", pNode->n-2, pNode->u.zJContent+1); } } /* Return the value of a column */ static int jsonEachColumn( @@ -195568,11 +192626,10 @@ jsonReturn(pThis, ctx, 0); }else if( p->eType==JSON_ARRAY ){ u32 iKey; if( p->bRecursive ){ if( p->iRowid==0 ) break; - assert( p->sParse.aNode[p->sParse.aUp[p->i]].eU==3 ); iKey = p->sParse.aNode[p->sParse.aUp[p->i]].u.iKey; }else{ iKey = p->iRowid; } sqlite3_result_int64(ctx, (sqlite3_int64)iKey); @@ -195618,11 +192675,11 @@ jsonAppendChar(&x, '$'); } if( p->eType==JSON_ARRAY ){ jsonPrintf(30, &x, "[%d]", p->iRowid); }else if( p->eType==JSON_OBJECT ){ - jsonAppendObjectPathElement(&x, pThis); + jsonPrintf(pThis->n, &x, ".%.*s", pThis->n-2, pThis->u.zJContent+1); } } jsonResult(&x); break; } @@ -195676,20 +192733,19 @@ const struct sqlite3_index_constraint *pConstraint; /* This implementation assumes that JSON and ROOT are the last two ** columns in the table */ assert( JEACH_ROOT == JEACH_JSON+1 ); - UNUSED_PARAMETER(tab); + UNUSED_PARAM(tab); aIdx[0] = aIdx[1] = -1; pConstraint = pIdxInfo->aConstraint; for(i=0; inConstraint; i++, pConstraint++){ int iCol; int iMask; if( pConstraint->iColumn < JEACH_JSON ) continue; iCol = pConstraint->iColumn - JEACH_JSON; assert( iCol==0 || iCol==1 ); - testcase( iCol==0 ); iMask = 1 << iCol; if( pConstraint->usable==0 ){ unusableMask |= iMask; }else if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ ){ aIdx[iCol] = i; @@ -195732,12 +192788,12 @@ JsonEachCursor *p = (JsonEachCursor*)cur; const char *z; const char *zRoot = 0; sqlite3_int64 n; - UNUSED_PARAMETER(idxStr); - UNUSED_PARAMETER(argc); + UNUSED_PARAM(idxStr); + UNUSED_PARAM(argc); jsonEachCursorReset(p); if( idxNum==0 ) return SQLITE_OK; z = (const char*)sqlite3_value_text(argv[0]); if( z==0 ) return SQLITE_OK; n = sqlite3_value_bytes(argv[0]); @@ -195783,12 +192839,10 @@ pNode = p->sParse.aNode; } p->iBegin = p->i = (int)(pNode - p->sParse.aNode); p->eType = pNode->eType; if( p->eType>=JSON_ARRAY ){ - assert( pNode->eU==0 ); - VVA( pNode->eU = 3 ); pNode->u.iKey = 0; p->iEnd = p->i + pNode->n + 1; if( p->bRecursive ){ p->eType = p->sParse.aNode[p->sParse.aUp[p->i]].eType; if( p->i>0 && (p->sParse.aNode[p->i-1].jnFlags & JNODE_LABEL)!=0 ){ @@ -195858,72 +192912,112 @@ 0, /* xRelease */ 0, /* xRollbackTo */ 0 /* xShadowName */ }; #endif /* SQLITE_OMIT_VIRTUALTABLE */ -#endif /* !defined(SQLITE_OMIT_JSON) */ - -/* -** Register JSON functions. -*/ -SQLITE_PRIVATE void sqlite3RegisterJsonFunctions(void){ -#ifndef SQLITE_OMIT_JSON - static FuncDef aJsonFunc[] = { - JFUNCTION(json, 1, 0, jsonRemoveFunc), - JFUNCTION(json_array, -1, 0, jsonArrayFunc), - JFUNCTION(json_array_length, 1, 0, jsonArrayLengthFunc), - JFUNCTION(json_array_length, 2, 0, jsonArrayLengthFunc), - JFUNCTION(json_extract, -1, 0, jsonExtractFunc), - JFUNCTION(->, 2, JSON_JSON, jsonExtractFunc), - JFUNCTION(->>, 2, JSON_SQL, jsonExtractFunc), - JFUNCTION(json_insert, -1, 0, jsonSetFunc), - JFUNCTION(json_object, -1, 0, jsonObjectFunc), - JFUNCTION(json_patch, 2, 0, jsonPatchFunc), - JFUNCTION(json_quote, 1, 0, jsonQuoteFunc), - JFUNCTION(json_remove, -1, 0, jsonRemoveFunc), - JFUNCTION(json_replace, -1, 0, jsonReplaceFunc), - JFUNCTION(json_set, -1, JSON_ISSET, jsonSetFunc), - JFUNCTION(json_type, 1, 0, jsonTypeFunc), - JFUNCTION(json_type, 2, 0, jsonTypeFunc), - JFUNCTION(json_valid, 1, 0, jsonValidFunc), + +/**************************************************************************** +** The following routines are the only publically visible identifiers in this +** file. Call the following routines in order to register the various SQL +** functions and the virtual table implemented by this file. +****************************************************************************/ + +SQLITE_PRIVATE int sqlite3Json1Init(sqlite3 *db){ + int rc = SQLITE_OK; + unsigned int i; + static const struct { + const char *zName; + int nArg; + int flag; + void (*xFunc)(sqlite3_context*,int,sqlite3_value**); + } aFunc[] = { + { "json", 1, 0, jsonRemoveFunc }, + { "json_array", -1, 0, jsonArrayFunc }, + { "json_array_length", 1, 0, jsonArrayLengthFunc }, + { "json_array_length", 2, 0, jsonArrayLengthFunc }, + { "json_extract", -1, 0, jsonExtractFunc }, + { "json_insert", -1, 0, jsonSetFunc }, + { "json_object", -1, 0, jsonObjectFunc }, + { "json_patch", 2, 0, jsonPatchFunc }, + { "json_quote", 1, 0, jsonQuoteFunc }, + { "json_remove", -1, 0, jsonRemoveFunc }, + { "json_replace", -1, 0, jsonReplaceFunc }, + { "json_set", -1, 1, jsonSetFunc }, + { "json_type", 1, 0, jsonTypeFunc }, + { "json_type", 2, 0, jsonTypeFunc }, + { "json_valid", 1, 0, jsonValidFunc }, + #if SQLITE_DEBUG - JFUNCTION(json_parse, 1, 0, jsonParseFunc), - JFUNCTION(json_test1, 1, 0, jsonTest1Func), + /* DEBUG and TESTING functions */ + { "json_parse", 1, 0, jsonParseFunc }, + { "json_test1", 1, 0, jsonTest1Func }, #endif - WAGGREGATE(json_group_array, 1, 0, 0, - jsonArrayStep, jsonArrayFinal, jsonArrayValue, jsonGroupInverse, - SQLITE_SUBTYPE|SQLITE_UTF8|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS), - WAGGREGATE(json_group_object, 2, 0, 0, - jsonObjectStep, jsonObjectFinal, jsonObjectValue, jsonGroupInverse, - SQLITE_SUBTYPE|SQLITE_UTF8|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS) + }; + static const struct { + const char *zName; + int nArg; + void (*xStep)(sqlite3_context*,int,sqlite3_value**); + void (*xFinal)(sqlite3_context*); + void (*xValue)(sqlite3_context*); + } aAgg[] = { + { "json_group_array", 1, + jsonArrayStep, jsonArrayFinal, jsonArrayValue }, + { "json_group_object", 2, + jsonObjectStep, jsonObjectFinal, jsonObjectValue }, }; - sqlite3InsertBuiltinFuncs(aJsonFunc, ArraySize(aJsonFunc)); -#endif -} - -#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_JSON) -/* -** Register the JSON table-valued functions -*/ -SQLITE_PRIVATE int sqlite3JsonTableFunctions(sqlite3 *db){ - int rc = SQLITE_OK; +#ifndef SQLITE_OMIT_VIRTUALTABLE static const struct { - const char *zName; - sqlite3_module *pModule; + const char *zName; + sqlite3_module *pModule; } aMod[] = { { "json_each", &jsonEachModule }, { "json_tree", &jsonTreeModule }, }; - unsigned int i; +#endif + static const int enc = + SQLITE_UTF8 | + SQLITE_DETERMINISTIC | + SQLITE_INNOCUOUS; + for(i=0; iop==RTREE_FALSE ); assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */ switch( p->op ){ case RTREE_TRUE: return; /* Always satisfied */ case RTREE_FALSE: break; /* Never satisfied */ + case RTREE_LE: + case RTREE_LT: case RTREE_EQ: RTREE_DECODE_COORD(eInt, pCellData, val); /* val now holds the lower bound of the coordinate pair */ - if( p->u.rValue>=val ){ - pCellData += 4; - RTREE_DECODE_COORD(eInt, pCellData, val); - /* val now holds the upper bound of the coordinate pair */ - if( p->u.rValue<=val ) return; - } - break; - case RTREE_LE: - case RTREE_LT: - RTREE_DECODE_COORD(eInt, pCellData, val); - /* val now holds the lower bound of the coordinate pair */ if( p->u.rValue>=val ) return; - break; + if( p->op!=RTREE_EQ ) break; /* RTREE_LE and RTREE_LT end here */ + /* Fall through for the RTREE_EQ case */ - default: + default: /* RTREE_GT or RTREE_GE, or fallthrough of RTREE_EQ */ pCellData += 4; RTREE_DECODE_COORD(eInt, pCellData, val); /* val now holds the upper bound of the coordinate pair */ if( p->u.rValue<=val ) return; - break; } *peWithin = NOT_WITHIN; } /* @@ -198137,11 +195214,11 @@ RtreeDValue fMinGrowth = RTREE_ZERO; RtreeDValue fMinArea = RTREE_ZERO; int nCell = NCELL(pNode); RtreeCell cell; - RtreeNode *pChild = 0; + RtreeNode *pChild; RtreeCell *aCell = 0; /* Select the child node which will be enlarged the least if pCell ** is inserted into it. Resolve ties by choosing the entry with @@ -198495,11 +195572,10 @@ nodeRelease(pRtree, pChild->pParent); nodeReference(pNode); pChild->pParent = pNode; } } - if( NEVER(pNode==0) ) return SQLITE_ERROR; return xSetMapping(pRtree, iRowid, pNode->iNode); } static int SplitNode( Rtree *pRtree, @@ -199800,11 +196876,10 @@ tree.nDim = (u8)sqlite3_value_int(apArg[0]); if( tree.nDim<1 || tree.nDim>5 ) return; tree.nDim2 = tree.nDim*2; tree.nBytesPerCell = 8 + 8 * tree.nDim; node.zData = (u8 *)sqlite3_value_blob(apArg[1]); - if( node.zData==0 ) return; nData = sqlite3_value_bytes(apArg[1]); if( nData<4 ) return; if( nDataz[0]) ) p->z++; + while( safe_isspace(p->z[0]) ) p->z++; return p->z[0]; } /* Parse out a number. Write the value into *pVal if pVal!=0. ** return non-zero on success and zero if the next token is not a number. @@ -200629,18 +197707,17 @@ sqlite3_value *pVal, /* The value to decode */ int *pRc /* Write error here */ ){ GeoPoly *p = 0; int nByte; - testcase( pCtx==0 ); if( sqlite3_value_type(pVal)==SQLITE_BLOB && (nByte = sqlite3_value_bytes(pVal))>=(4+6*sizeof(GeoCoord)) ){ const unsigned char *a = sqlite3_value_blob(pVal); int nVertex; if( a==0 ){ - if( pCtx ) sqlite3_result_error_nomem(pCtx); + sqlite3_result_error_nomem(pCtx); return 0; } nVertex = (a[1]<<16) + (a[2]<<8) + a[3]; if( (a[0]==0 || a[0]==1) && (nVertex*2*sizeof(GeoCoord) + 4)==(unsigned int)nByte @@ -201463,15 +198540,15 @@ pActive = pSeg; needSort = 1; }else{ /* Remove a segment */ if( pActive==pThisEvent->pSeg ){ - pActive = ALWAYS(pActive) ? pActive->pNext : 0; + pActive = pActive->pNext; }else{ for(pSeg=pActive; pSeg; pSeg=pSeg->pNext){ if( pSeg->pNext==pThisEvent->pSeg ){ - pSeg->pNext = ALWAYS(pSeg->pNext) ? pSeg->pNext->pNext : 0; + pSeg->pNext = pSeg->pNext->pNext; break; } } } } @@ -201711,11 +198788,10 @@ rc = nodeAcquire(pRtree, 1, 0, &pRoot); if( rc==SQLITE_OK && idxNum<=3 ){ RtreeCoord bbox[4]; RtreeConstraint *p; assert( argc==1 ); - assert( argv[0]!=0 ); geopolyBBox(0, argv[0], bbox, &rc); if( rc ){ goto geopoly_filter_end; } pCsr->aConstraint = p = sqlite3_malloc(sizeof(RtreeConstraint)*4); @@ -201939,11 +199015,10 @@ if( nData>1 /* not a DELETE */ && (!oldRowidValid /* INSERT */ || !sqlite3_value_nochange(aData[2]) /* UPDATE _shape */ || oldRowid!=newRowid) /* Rowid change */ ){ - assert( aData[2]!=0 ); geopolyBBox(0, aData[2], cell.aCoord, &rc); if( rc ){ if( rc==SQLITE_ERROR ){ pVtab->zErrMsg = sqlite3_mprintf("_shape does not contain a valid polygon"); @@ -203866,17 +200941,10 @@ ** Swap two objects of type TYPE. */ #if !defined(SQLITE_AMALGAMATION) # define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;} #endif - -/* -** Name of the URI option that causes RBU to take an exclusive lock as -** part of the incremental checkpoint operation. -*/ -#define RBU_EXCLUSIVE_CHECKPOINT "rbu_exclusive_checkpoint" - /* ** The rbu_state table is used to save the state of a partially applied ** update so that it can be resumed later. The table consists of integer ** keys mapped to values as follows: @@ -205320,11 +202388,11 @@ ** ** If the expression cannot be created, NULL is returned. In this case, ** the caller has to use an OFFSET clause to extract only the required ** rows from the sourct table, just as it does for an RBU update operation. */ -static char *rbuVacuumIndexStart( +char *rbuVacuumIndexStart( sqlite3rbu *p, /* RBU handle */ RbuObjIter *pIter /* RBU iterator object */ ){ char *zOrder = 0; char *zLhs = 0; @@ -206520,23 +203588,17 @@ /* ** Open the database handle and attach the RBU database as "rbu". If an ** error occurs, leave an error code and message in the RBU handle. -** -** If argument dbMain is not NULL, then it is a database handle already -** open on the target database. Use this handle instead of opening a new -** one. */ -static void rbuOpenDatabase(sqlite3rbu *p, sqlite3 *dbMain, int *pbRetry){ +static void rbuOpenDatabase(sqlite3rbu *p, int *pbRetry){ assert( p->rc || (p->dbMain==0 && p->dbRbu==0) ); assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 ); - assert( dbMain==0 || rbuIsVacuum(p)==0 ); /* Open the RBU database */ p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1); - p->dbMain = dbMain; if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){ sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p); if( p->zState==0 ){ const char *zFile = sqlite3_db_filename(p->dbRbu, "main"); @@ -206898,35 +203960,19 @@ p->rc = pDb->pMethods->xWrite(pDb, p->aBuf, p->pgsz, iOff); } /* -** Take an EXCLUSIVE lock on the database file. Return SQLITE_OK if -** successful, or an SQLite error code otherwise. -*/ -static int rbuLockDatabase(sqlite3 *db){ - int rc = SQLITE_OK; - sqlite3_file *fd = 0; - sqlite3_file_control(db, "main", SQLITE_FCNTL_FILE_POINTER, &fd); - - if( fd->pMethods ){ - rc = fd->pMethods->xLock(fd, SQLITE_LOCK_SHARED); - if( rc==SQLITE_OK ){ - rc = fd->pMethods->xLock(fd, SQLITE_LOCK_EXCLUSIVE); - } - } - return rc; -} - -/* -** Return true if the database handle passed as the only argument -** was opened with the rbu_exclusive_checkpoint=1 URI parameter -** specified. Or false otherwise. -*/ -static int rbuExclusiveCheckpoint(sqlite3 *db){ - const char *zUri = sqlite3_db_filename(db, 0); - return sqlite3_uri_boolean(zUri, RBU_EXCLUSIVE_CHECKPOINT, 0); +** Take an EXCLUSIVE lock on the database file. +*/ +static void rbuLockDatabase(sqlite3rbu *p){ + sqlite3_file *pReal = p->pTargetFd->pReal; + assert( p->rc==SQLITE_OK ); + p->rc = pReal->pMethods->xLock(pReal, SQLITE_LOCK_SHARED); + if( p->rc==SQLITE_OK ){ + p->rc = pReal->pMethods->xLock(pReal, SQLITE_LOCK_EXCLUSIVE); + } } #if defined(_WIN32_WCE) static LPWSTR rbuWinUtf8ToUnicode(const char *zFilename){ int nChar; @@ -206980,28 +204026,22 @@ ** in WAL mode). So no other connection may be writing the db. ** ** In order to ensure that there are no database readers, an EXCLUSIVE ** lock is obtained here before the *-oal is moved to *-wal. */ - sqlite3 *dbMain = 0; - rbuFileSuffix3(zBase, zWal); - rbuFileSuffix3(zBase, zOal); - - /* Re-open the databases. */ - rbuObjIterFinalize(&p->objiter); - sqlite3_close(p->dbRbu); - sqlite3_close(p->dbMain); - p->dbMain = 0; - p->dbRbu = 0; - - dbMain = rbuOpenDbhandle(p, p->zTarget, 1); - if( dbMain ){ - assert( p->rc==SQLITE_OK ); - p->rc = rbuLockDatabase(dbMain); - } - + rbuLockDatabase(p); if( p->rc==SQLITE_OK ){ + rbuFileSuffix3(zBase, zWal); + rbuFileSuffix3(zBase, zOal); + + /* Re-open the databases. */ + rbuObjIterFinalize(&p->objiter); + sqlite3_close(p->dbRbu); + sqlite3_close(p->dbMain); + p->dbMain = 0; + p->dbRbu = 0; + #if defined(_WIN32_WCE) { LPWSTR zWideOal; LPWSTR zWideWal; @@ -207024,23 +204064,15 @@ } } #else p->rc = rename(zOal, zWal) ? SQLITE_IOERR : SQLITE_OK; #endif - } - - if( p->rc!=SQLITE_OK - || rbuIsVacuum(p) - || rbuExclusiveCheckpoint(dbMain)==0 - ){ - sqlite3_close(dbMain); - dbMain = 0; - } - - if( p->rc==SQLITE_OK ){ - rbuOpenDatabase(p, dbMain, 0); - rbuSetupCheckpoint(p, 0); + + if( p->rc==SQLITE_OK ){ + rbuOpenDatabase(p, 0); + rbuSetupCheckpoint(p, 0); + } } } sqlite3_free(zWal); sqlite3_free(zOal); @@ -207787,13 +204819,13 @@ ** to be a wal-mode db. But, this may have happened due to an earlier ** RBU vacuum operation leaving an old wal file in the directory. ** If this is the case, it will have been checkpointed and deleted ** when the handle was closed and a second attempt to open the ** database may succeed. */ - rbuOpenDatabase(p, 0, &bRetry); + rbuOpenDatabase(p, &bRetry); if( bRetry ){ - rbuOpenDatabase(p, 0, 0); + rbuOpenDatabase(p, 0); } } if( p->rc==SQLITE_OK ){ pState = rbuLoadState(p); @@ -207884,18 +204916,10 @@ } } }else if( p->eStage==RBU_STAGE_MOVE ){ /* no-op */ }else if( p->eStage==RBU_STAGE_CKPT ){ - if( !rbuIsVacuum(p) && rbuExclusiveCheckpoint(p->dbMain) ){ - /* If the rbu_exclusive_checkpoint=1 URI parameter was specified - ** and an incremental checkpoint is being resumed, attempt an - ** exclusive lock on the db file. If this fails, so be it. */ - p->eStage = RBU_STAGE_DONE; - rbuLockDatabase(p->dbMain); - p->eStage = RBU_STAGE_CKPT; - } rbuSetupCheckpoint(p, pState); }else if( p->eStage==RBU_STAGE_DONE ){ p->rc = SQLITE_DONE; }else{ p->rc = SQLITE_CORRUPT; @@ -207929,10 +204953,11 @@ const char *zTarget, const char *zRbu, const char *zState ){ if( zTarget==0 || zRbu==0 ){ return rbuMisuseError(); } + /* TODO: Check that zTarget and zRbu are non-NULL */ return openRbuHandle(zTarget, zRbu, zState); } /* ** Open a handle to begin or resume an RBU VACUUM operation. @@ -210165,11 +207190,10 @@ && pIdxInfo->aOrderBy[0].iColumn<=0 && pIdxInfo->aOrderBy[0].desc==0 ){ pIdxInfo->orderByConsumed = 1; } - sqlite3VtabWriteAll(pIdxInfo); return SQLITE_OK; } /* ** Open a new dbpagevfs cursor. @@ -210849,11 +207873,11 @@ if( z==0 && (eType!=SQLITE_BLOB || n>0) ) return SQLITE_NOMEM; nVarint = sessionVarintLen(n); if( aBuf ){ sessionVarintPut(&aBuf[1], n); - if( n>0 ) memcpy(&aBuf[nVarint + 1], z, n); + if( n ) memcpy(&aBuf[nVarint + 1], z, n); } nByte = 1 + nVarint + n; break; } @@ -211454,36 +208478,20 @@ "SELECT 2, 'stat', '', 0, '', 0" ); }else if( rc==SQLITE_ERROR ){ zPragma = sqlite3_mprintf(""); }else{ - *pazCol = 0; - *pabPK = 0; - *pnCol = 0; - if( pzTab ) *pzTab = 0; return rc; } }else{ zPragma = sqlite3_mprintf("PRAGMA '%q'.table_info('%q')", zDb, zThis); } - if( !zPragma ){ - *pazCol = 0; - *pabPK = 0; - *pnCol = 0; - if( pzTab ) *pzTab = 0; - return SQLITE_NOMEM; - } + if( !zPragma ) return SQLITE_NOMEM; rc = sqlite3_prepare_v2(db, zPragma, -1, &pStmt, 0); sqlite3_free(zPragma); - if( rc!=SQLITE_OK ){ - *pazCol = 0; - *pabPK = 0; - *pnCol = 0; - if( pzTab ) *pzTab = 0; - return rc; - } + if( rc!=SQLITE_OK ) return rc; nByte = nThis + 1; while( SQLITE_ROW==sqlite3_step(pStmt) ){ nByte += sqlite3_column_bytes(pStmt, 1); nDbCol++; @@ -211897,15 +208905,11 @@ if( pSession->xTableFilter==0 || pSession->xTableFilter(pSession->pFilterCtx, zName) ){ rc = sqlite3session_attach(pSession, zName); if( rc==SQLITE_OK ){ - pRet = pSession->pTable; - while( ALWAYS(pRet) && pRet->pNext ){ - pRet = pRet->pNext; - } - assert( pRet!=0 ); + for(pRet=pSession->pTable; pRet->pNext; pRet=pRet->pNext); assert( 0==sqlite3_strnicmp(pRet->zName, zName, nName+1) ); } } } @@ -212674,11 +209678,10 @@ int bNoop = 1; /* Set to zero if any values are modified */ int nRewind = pBuf->nBuf; /* Set to zero if any values are modified */ int i; /* Used to iterate through columns */ u8 *pCsr = p->aRecord; /* Used to iterate through old.* values */ - assert( abPK!=0 ); sessionAppendByte(pBuf, SQLITE_UPDATE, &rc); sessionAppendByte(pBuf, p->bIndirect, &rc); for(i=0; idb; /* Source database handle */ SessionTable *pTab; /* Used to iterate through attached tables */ SessionBuffer buf = {0,0,0}; /* Buffer in which to accumlate changeset */ int rc; /* Return code */ - assert( xOutput==0 || (pnChangeset==0 && ppChangeset==0) ); - assert( xOutput!=0 || (pnChangeset!=0 && ppChangeset!=0) ); + assert( xOutput==0 || (pnChangeset==0 && ppChangeset==0 ) ); /* Zero the output variables in case an error occurs. If this session ** object is already in the error state (sqlite3_session.rc != SQLITE_OK), ** this call will be a no-op. */ if( xOutput==0 ){ - assert( pnChangeset!=0 && ppChangeset!=0 ); *pnChangeset = 0; *ppChangeset = 0; } if( pSession->rc ) return pSession->rc; @@ -213000,12 +210001,12 @@ sqlite3_mutex_enter(sqlite3_db_mutex(db)); for(pTab=pSession->pTable; rc==SQLITE_OK && pTab; pTab=pTab->pNext){ if( pTab->nEntry ){ const char *zName = pTab->zName; - int nCol = 0; /* Number of columns in table */ - u8 *abPK = 0; /* Primary key array */ + int nCol; /* Number of columns in table */ + u8 *abPK; /* Primary key array */ const char **azCol = 0; /* Table columns */ int i; /* Used to iterate through hash buckets */ sqlite3_stmt *pSel = 0; /* SELECT statement to query table pTab */ int nRewind = buf.nBuf; /* Initial size of write buffer */ int nNoop; /* Size of buffer after writing tbl header */ @@ -213039,11 +210040,10 @@ sessionAppendByte(&buf, p->bIndirect, &rc); for(iCol=0; iColop!=SQLITE_INSERT ){ rc = sessionAppendDelete(&buf, bPatchset, p, nCol, abPK); } @@ -213100,14 +210100,11 @@ SQLITE_API int sqlite3session_changeset( sqlite3_session *pSession, /* Session object */ int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */ void **ppChangeset /* OUT: Buffer containing changeset */ ){ - int rc; - - if( pnChangeset==0 || ppChangeset==0 ) return SQLITE_MISUSE; - rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset,ppChangeset); + int rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset,ppChangeset); assert( rc || pnChangeset==0 || pSession->bEnableSize==0 || *pnChangeset<=pSession->nMaxChangesetSize ); return rc; } @@ -213118,11 +210115,10 @@ SQLITE_API int sqlite3session_changeset_strm( sqlite3_session *pSession, int (*xOutput)(void *pOut, const void *pData, int nData), void *pOut ){ - if( xOutput==0 ) return SQLITE_MISUSE; return sessionGenerateChangeset(pSession, 0, xOutput, pOut, 0, 0); } /* ** Streaming version of sqlite3session_patchset(). @@ -213130,11 +210126,10 @@ SQLITE_API int sqlite3session_patchset_strm( sqlite3_session *pSession, int (*xOutput)(void *pOut, const void *pData, int nData), void *pOut ){ - if( xOutput==0 ) return SQLITE_MISUSE; return sessionGenerateChangeset(pSession, 1, xOutput, pOut, 0, 0); } /* ** Obtain a patchset object containing all changes recorded by the @@ -213146,11 +210141,10 @@ SQLITE_API int sqlite3session_patchset( sqlite3_session *pSession, /* Session object */ int *pnPatchset, /* OUT: Size of buffer at *ppChangeset */ void **ppPatchset /* OUT: Buffer containing changeset */ ){ - if( pnPatchset==0 || ppPatchset==0 ) return SQLITE_MISUSE; return sessionGenerateChangeset(pSession, 1, 0, 0, pnPatchset, ppPatchset); } /* ** Enable or disable the session object passed as the first argument. @@ -214110,15 +211104,15 @@ if( rc!=SQLITE_OK ) goto finished_invert; } } assert( rc==SQLITE_OK ); - if( pnInverted && ALWAYS(ppInverted) ){ + if( pnInverted ){ *pnInverted = sOut.nBuf; *ppInverted = sOut.aBuf; sOut.aBuf = 0; - }else if( sOut.nBuf>0 && ALWAYS(xOutput!=0) ){ + }else if( sOut.nBuf>0 ){ rc = xOutput(pOut, sOut.aBuf, sOut.nBuf); } finished_invert: sqlite3_free(sOut.aBuf); @@ -214570,11 +211564,11 @@ ** in the code below. */ assert( xValue==sqlite3changeset_old || xValue==sqlite3changeset_new ); for(i=0; rc==SQLITE_OK && i0 ) rc = xOutput(pOut, buf.aBuf, buf.nBuf); - }else if( ppOut ){ + }else{ *ppOut = buf.aBuf; - if( pnOut ) *pnOut = buf.nBuf; + *pnOut = buf.nBuf; buf.aBuf = 0; } } sqlite3_free(buf.aBuf); @@ -216115,11 +213109,11 @@ if( rc==SQLITE_OK ){ if( xOutput ){ if( sOut.nBuf>0 ){ rc = xOutput(pOut, sOut.aBuf, sOut.nBuf); } - }else if( ppOut ){ + }else{ *ppOut = (void*)sOut.aBuf; *pnOut = sOut.nBuf; sOut.aBuf = 0; } } @@ -216858,24 +213852,12 @@ #ifndef ArraySize # define ArraySize(x) ((int)(sizeof(x) / sizeof(x[0]))) #endif #define testcase(x) - -#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST) -# define SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS 1 -#endif -#if defined(SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS) -# define ALWAYS(X) (1) -# define NEVER(X) (0) -#elif !defined(NDEBUG) -# define ALWAYS(X) ((X)?1:(assert(0),0)) -# define NEVER(X) ((X)?(assert(0),1):0) -#else -# define ALWAYS(X) (X) -# define NEVER(X) (X) -#endif +#define ALWAYS(x) 1 +#define NEVER(x) 0 #define MIN(x,y) (((x) < (y)) ? (x) : (y)) #define MAX(x,y) (((x) > (y)) ? (x) : (y)) /* @@ -216931,11 +213913,11 @@ /* ** A version of memcmp() that does not cause asan errors if one of the pointer ** parameters is NULL and the number of bytes to compare is zero. */ -#define fts5Memcmp(s1, s2, n) ((n)<=0 ? 0 : memcmp((s1), (s2), (n))) +#define fts5Memcmp(s1, s2, n) ((n)==0 ? 0 : memcmp((s1), (s2), (n))) /* Mark a function parameter as unused, to suppress nuisance compiler ** warnings. */ #ifndef UNUSED_PARAM # define UNUSED_PARAM(X) (void)(X) @@ -218050,13 +215032,13 @@ fts5yyStackEntry *fts5yystackEnd; /* Last entry in the stack */ #endif }; typedef struct fts5yyParser fts5yyParser; -/* #include */ #ifndef NDEBUG /* #include */ +/* #include */ static FILE *fts5yyTraceFILE = 0; static char *fts5yyTracePrompt = 0; #endif /* NDEBUG */ #ifndef NDEBUG @@ -218989,12 +215971,12 @@ assert( fts5yypParser->fts5yytos>=fts5yypParser->fts5yystack ); assert( fts5yyact==fts5yypParser->fts5yytos->stateno ); fts5yyact = fts5yy_find_shift_action((fts5YYCODETYPE)fts5yymajor,fts5yyact); if( fts5yyact >= fts5YY_MIN_REDUCE ){ unsigned int fts5yyruleno = fts5yyact - fts5YY_MIN_REDUCE; /* Reduce by this rule */ -#ifndef NDEBUG assert( fts5yyruleno<(int)(sizeof(fts5yyRuleName)/sizeof(fts5yyRuleName[0])) ); +#ifndef NDEBUG if( fts5yyTraceFILE ){ int fts5yysize = fts5yyRuleInfoNRhs[fts5yyruleno]; if( fts5yysize ){ fprintf(fts5yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", fts5yyTracePrompt, @@ -219957,10 +216939,11 @@ int *pRc, Fts5Buffer *pBuf, u32 nData, const u8 *pData ){ + assert_nc( *pRc || nData>=0 ); if( nData ){ if( fts5BufferGrow(pRc, pBuf, nData) ) return; memcpy(&pBuf->p[pBuf->n], pData, nData); pBuf->n += nData; } @@ -220068,10 +217051,11 @@ return 1; }else{ i64 iOff = *piOff; u32 iVal; fts5FastGetVarint32(a, i, iVal); + assert( iVal>=0 ); if( iVal<=1 ){ if( iVal==0 ){ *pi = i; return 0; } @@ -220862,11 +217846,10 @@ z = fts5ConfigGobbleWord(&rc, zOrig, &zOne, &bMustBeCol); z = fts5ConfigSkipWhitespace(z); if( z && *z=='=' ){ bOption = 1; - assert( zOne!=0 ); z++; if( bMustBeCol ) z = 0; } z = fts5ConfigSkipWhitespace(z); if( z && z[0] ){ @@ -220879,15 +217862,11 @@ if( z==0 ){ *pzErr = sqlite3_mprintf("parse error in \"%s\"", zOrig); rc = SQLITE_ERROR; }else{ if( bOption ){ - rc = fts5ConfigParseSpecial(pGlobal, pRet, - ALWAYS(zOne)?zOne:"", - zTwo?zTwo:"", - pzErr - ); + rc = fts5ConfigParseSpecial(pGlobal, pRet, zOne, zTwo?zTwo:"", pzErr); }else{ rc = fts5ConfigParseColumn(pRet, zOne, zTwo, pzErr); zOne = 0; } } @@ -221700,11 +218679,10 @@ static i64 fts5ExprSynonymRowid(Fts5ExprTerm *pTerm, int bDesc, int *pbEof){ i64 iRet = 0; int bRetValid = 0; Fts5ExprTerm *p; - assert( pTerm ); assert( pTerm->pSynonym ); assert( bDesc==0 || bDesc==1 ); for(p=pTerm; p; p=p->pSynonym){ if( 0==sqlite3Fts5IterEof(p->pIter) ){ i64 iRowid = p->pIter->iRowid; @@ -223141,11 +220119,11 @@ /* This happens when parsing a token or quoted phrase that contains ** no token characters at all. (e.g ... MATCH '""'). */ sCtx.pPhrase = sqlite3Fts5MallocZero(&rc, sizeof(Fts5ExprPhrase)); } - if( rc==SQLITE_OK && ALWAYS(sCtx.pPhrase) ){ + if( rc==SQLITE_OK ){ /* All the allocations succeeded. Put the expression object together. */ pNew->pIndex = pExpr->pIndex; pNew->pConfig = pExpr->pConfig; pNew->nPhrase = 1; pNew->apExprPhrase[0] = sCtx.pPhrase; @@ -224122,29 +221100,20 @@ Fts5PoslistWriter writer; int bOk; /* True if ok to populate */ int bMiss; }; -/* -** Clear the position lists associated with all phrases in the expression -** passed as the first argument. Argument bLive is true if the expression -** might be pointing to a real entry, otherwise it has just been reset. -** -** At present this function is only used for detail=col and detail=none -** fts5 tables. This implies that all phrases must be at most 1 token -** in size, as phrase matches are not supported without detail=full. -*/ static Fts5PoslistPopulator *sqlite3Fts5ExprClearPoslists(Fts5Expr *pExpr, int bLive){ Fts5PoslistPopulator *pRet; pRet = sqlite3_malloc64(sizeof(Fts5PoslistPopulator)*pExpr->nPhrase); if( pRet ){ int i; memset(pRet, 0, sizeof(Fts5PoslistPopulator)*pExpr->nPhrase); for(i=0; inPhrase; i++){ Fts5Buffer *pBuf = &pExpr->apExprPhrase[i]->poslist; Fts5ExprNode *pNode = pExpr->apExprPhrase[i]->pNode; - assert( pExpr->apExprPhrase[i]->nTerm<=1 ); + assert( pExpr->apExprPhrase[i]->nTerm==1 ); if( bLive && (pBuf->n==0 || pNode->iRowid!=pExpr->pRoot->iRowid || pNode->bEof) ){ pRet[i].bMiss = 1; }else{ @@ -224691,11 +221660,11 @@ if( iCol>=0 ){ if( pHash->eDetail==FTS5_DETAIL_NONE ){ p->bContent = 1; }else{ /* Append a new column value, if necessary */ - assert_nc( iCol>=p->iCol ); + assert( iCol>=p->iCol ); if( iCol!=p->iCol ){ if( pHash->eDetail==FTS5_DETAIL_FULL ){ pPtr[p->nData++] = 0x01; p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iCol); p->iCol = (i16)iCol; @@ -225496,15 +222465,12 @@ ** +ve if pRight is smaller than pLeft. In other words: ** ** res = *pLeft - *pRight */ static int fts5BufferCompare(Fts5Buffer *pLeft, Fts5Buffer *pRight){ - int nCmp, res; - nCmp = MIN(pLeft->n, pRight->n); - assert( nCmp<=0 || pLeft->p!=0 ); - assert( nCmp<=0 || pRight->p!=0 ); - res = fts5Memcmp(pLeft->p, pRight->p, nCmp); + int nCmp = MIN(pLeft->n, pRight->n); + int res = fts5Memcmp(pLeft->p, pRight->p, nCmp); return (res==0 ? (pLeft->n - pRight->n) : res); } static int fts5LeafFirstTermOff(Fts5Data *pLeaf){ int ret; @@ -225746,11 +222712,11 @@ ** an error occurs, (*pRc) is set to an SQLite error code before returning. */ static void fts5StructureMakeWritable(int *pRc, Fts5Structure **pp){ Fts5Structure *p = *pp; if( *pRc==SQLITE_OK && p->nRef>1 ){ - i64 nByte = sizeof(Fts5Structure)+(p->nLevel-1)*sizeof(Fts5StructureLevel); + int nByte = sizeof(Fts5Structure)+(p->nLevel-1)*sizeof(Fts5StructureLevel); Fts5Structure *pNew; pNew = (Fts5Structure*)sqlite3Fts5MallocZero(pRc, nByte); if( pNew ){ int i; memcpy(pNew, p, nByte); @@ -226672,11 +223638,10 @@ fts5SegIterNextPage(p, pIter); } if( p->rc==SQLITE_OK ){ pIter->iLeafOffset = 4; - assert( pIter->pLeaf!=0 ); assert_nc( pIter->pLeaf->nn>4 ); assert_nc( fts5LeafFirstTermOff(pIter->pLeaf)==4 ); pIter->iPgidxOff = pIter->pLeaf->szLeaf+1; fts5SegIterLoadTerm(p, pIter, 0); fts5SegIterLoadNPos(p, pIter); @@ -226775,16 +223740,12 @@ } }else{ int iRowidOff; iRowidOff = fts5LeafFirstRowidOff(pNew); if( iRowidOff ){ - if( iRowidOff>=pNew->szLeaf ){ - p->rc = FTS5_CORRUPT; - }else{ - pIter->pLeaf = pNew; - pIter->iLeafOffset = iRowidOff; - } + pIter->pLeaf = pNew; + pIter->iLeafOffset = iRowidOff; } } if( pIter->pLeaf ){ u8 *a = &pIter->pLeaf->p[pIter->iLeafOffset]; @@ -227181,24 +224142,25 @@ Fts5Index *p, /* Leave any error code here */ int bGe, /* True for a >= search */ Fts5SegIter *pIter, /* Iterator to seek */ const u8 *pTerm, int nTerm /* Term to search for */ ){ - u32 iOff; + int iOff; const u8 *a = pIter->pLeaf->p; - u32 n = (u32)pIter->pLeaf->nn; + int szLeaf = pIter->pLeaf->szLeaf; + int n = pIter->pLeaf->nn; u32 nMatch = 0; u32 nKeep = 0; u32 nNew = 0; u32 iTermOff; - u32 iPgidx; /* Current offset in pgidx */ + int iPgidx; /* Current offset in pgidx */ int bEndOfPage = 0; assert( p->rc==SQLITE_OK ); - iPgidx = (u32)pIter->pLeaf->szLeaf; + iPgidx = szLeaf; iPgidx += fts5GetVarint32(&a[iPgidx], iTermOff); iOff = iTermOff; if( iOff>n ){ p->rc = FTS5_CORRUPT; return; @@ -227260,19 +224222,19 @@ do { fts5SegIterNextPage(p, pIter); if( pIter->pLeaf==0 ) return; a = pIter->pLeaf->p; if( fts5LeafIsTermless(pIter->pLeaf)==0 ){ - iPgidx = (u32)pIter->pLeaf->szLeaf; + iPgidx = pIter->pLeaf->szLeaf; iPgidx += fts5GetVarint32(&pIter->pLeaf->p[iPgidx], iOff); - if( iOff<4 || (i64)iOff>=pIter->pLeaf->szLeaf ){ + if( iOff<4 || iOff>=pIter->pLeaf->szLeaf ){ p->rc = FTS5_CORRUPT; return; }else{ nKeep = 0; iTermOff = iOff; - n = (u32)pIter->pLeaf->nn; + n = pIter->pLeaf->nn; iOff += fts5GetVarint32(&a[iOff], nNew); break; } } }while( 1 ); @@ -227636,11 +224598,11 @@ pIter->pNextLeaf = 0; pIter->iLeafPgno = iLeafPgno-1; fts5SegIterNextPage(p, pIter); assert( p->rc!=SQLITE_OK || pIter->iLeafPgno==iLeafPgno ); - if( p->rc==SQLITE_OK && ALWAYS(pIter->pLeaf!=0) ){ + if( p->rc==SQLITE_OK ){ int iOff; u8 *a = pIter->pLeaf->p; int n = pIter->pLeaf->szLeaf; iOff = fts5LeafFirstRowidOff(pIter->pLeaf); @@ -228068,15 +225030,11 @@ Fts5Index *p, Fts5SegIter *pSeg, Fts5Colset *pColset, Fts5Buffer *pBuf ){ - assert( pBuf!=0 ); - assert( pSeg!=0 ); if( 0==fts5BufferGrow(&p->rc, pBuf, pSeg->nPos+FTS5_DATA_ZERO_PADDING) ){ - assert( pBuf->p!=0 ); - assert( pBuf->nSpace >= pBuf->n+pSeg->nPos+FTS5_DATA_ZERO_PADDING ); memset(&pBuf->p[pBuf->n+pSeg->nPos], 0, FTS5_DATA_ZERO_PADDING); if( pColset==0 ){ fts5ChunkIterate(p, pSeg, (void*)pBuf, fts5PoslistCallback); }else{ if( p->pConfig->eDetail==FTS5_DETAIL_FULL ){ @@ -228296,11 +225254,10 @@ pIter->base.nData = pIter->poslist.n; } } static void fts5IterSetOutputCb(int *pRc, Fts5Iter *pIter){ - assert( pIter!=0 || (*pRc)!=SQLITE_OK ); if( *pRc==SQLITE_OK ){ Fts5Config *pConfig = pIter->pIndex->pConfig; if( pConfig->eDetail==FTS5_DETAIL_NONE ){ pIter->xSetOutputs = fts5IterSetOutputs_None; } @@ -228368,14 +225325,11 @@ }else{ nSeg = MIN(pStruct->aLevel[iLevel].nSeg, nSegment); } } *ppOut = pNew = fts5MultiIterAlloc(p, nSeg); - if( pNew==0 ){ - assert( p->rc!=SQLITE_OK ); - goto fts5MultiIterNew_post_check; - } + if( pNew==0 ) return; pNew->bRev = (0!=(flags & FTS5INDEX_QUERY_DESC)); pNew->bSkipEmpty = (0!=(flags & FTS5INDEX_QUERY_SKIPEMPTY)); pNew->pColset = pColset; if( (flags & FTS5INDEX_QUERY_NOOUTPUT)==0 ){ fts5IterSetOutputCb(&p->rc, pNew); @@ -228435,14 +225389,10 @@ }else{ fts5MultiIterFree(pNew); *ppOut = 0; } - -fts5MultiIterNew_post_check: - assert( (*ppOut)!=0 || p->rc!=SQLITE_OK ); - return; } /* ** Create an Fts5Iter that iterates through the doclist provided ** as the second argument. @@ -228486,12 +225436,11 @@ /* ** Return true if the iterator is at EOF or if an error has occurred. ** False otherwise. */ static int fts5MultiIterEof(Fts5Index *p, Fts5Iter *pIter){ - assert( pIter!=0 || p->rc!=SQLITE_OK ); - assert( p->rc!=SQLITE_OK + assert( p->rc || (pIter->aSeg[ pIter->aFirst[1].iFirst ].pLeaf==0)==pIter->base.bEof ); return (p->rc || pIter->base.bEof); } @@ -229291,11 +226240,10 @@ /* Flush the last leaf page to disk. Set the output segment b-tree height ** and last leaf page number at the same time. */ fts5WriteFinish(p, &writer, &pSeg->pgnoLast); - assert( pIter!=0 || p->rc!=SQLITE_OK ); if( fts5MultiIterEof(p, pIter) ){ int i; /* Remove the redundant segments from the %_data table */ for(i=0; irc==SQLITE_OK && p->pConfig->nAutomerge>0 && ALWAYS((*ppStruct)!=0) ){ + if( p->rc==SQLITE_OK && p->pConfig->nAutomerge>0 ){ Fts5Structure *pStruct = *ppStruct; u64 nWrite; /* Initial value of write-counter */ int nWork; /* Number of work-quanta to perform */ int nRem; /* Number of leaf pages left to write */ @@ -230461,11 +227409,11 @@ assert( (flags & FTS5INDEX_QUERY_SCAN)==0 || flags==FTS5INDEX_QUERY_SCAN ); if( sqlite3Fts5BufferSize(&p->rc, &buf, nToken+1)==0 ){ int iIdx = 0; /* Index to search */ int iPrefixIdx = 0; /* +1 prefix index */ - if( nToken>0 ) memcpy(&buf.p[1], pToken, nToken); + if( nToken ) memcpy(&buf.p[1], pToken, nToken); /* Figure out which index to search and set iIdx accordingly. If this ** is a prefix query for which there is no prefix index, set iIdx to ** greater than pConfig->nPrefix to indicate that the query will be ** satisfied by scanning multiple terms in the main index. @@ -230502,19 +227450,15 @@ } }else{ /* Scan multiple terms in the main index */ int bDesc = (flags & FTS5INDEX_QUERY_DESC)!=0; fts5SetupPrefixIter(p, bDesc, iPrefixIdx, buf.p, nToken+1, pColset,&pRet); - if( pRet==0 ){ - assert( p->rc!=SQLITE_OK ); - }else{ - assert( pRet->pColset==0 ); - fts5IterSetOutputCb(&p->rc, pRet); - if( p->rc==SQLITE_OK ){ - Fts5SegIter *pSeg = &pRet->aSeg[pRet->aFirst[1].iFirst]; - if( pSeg->pLeaf ) pRet->xSetOutputs(pRet, pSeg); - } + assert( p->rc!=SQLITE_OK || pRet->pColset==0 ); + fts5IterSetOutputCb(&p->rc, pRet); + if( p->rc==SQLITE_OK ){ + Fts5SegIter *pSeg = &pRet->aSeg[pRet->aFirst[1].iFirst]; + if( pSeg->pLeaf ) pRet->xSetOutputs(pRet, pSeg); } } if( p->rc ){ sqlite3Fts5IterClose((Fts5IndexIter*)pRet); @@ -230758,11 +227702,11 @@ int eDetail = p->pConfig->eDetail; u64 cksum = *pCksum; Fts5IndexIter *pIter = 0; int rc = sqlite3Fts5IndexQuery(p, z, n, flags, 0, &pIter); - while( rc==SQLITE_OK && ALWAYS(pIter!=0) && 0==sqlite3Fts5IterEof(pIter) ){ + while( rc==SQLITE_OK && 0==sqlite3Fts5IterEof(pIter) ){ i64 rowid = pIter->iRowid; if( eDetail==FTS5_DETAIL_NONE ){ cksum ^= sqlite3Fts5IndexEntryCksum(rowid, 0, 0, iIdx, z, n); }else{ @@ -231123,11 +228067,10 @@ int eDetail = p->pConfig->eDetail; u64 cksum2 = 0; /* Checksum based on contents of indexes */ Fts5Buffer poslist = {0,0,0}; /* Buffer used to hold a poslist */ Fts5Iter *pIter; /* Used to iterate through entire index */ Fts5Structure *pStruct; /* Index structure */ - int iLvl, iSeg; #ifdef SQLITE_DEBUG /* Used by extra internal tests only run if NDEBUG is not defined */ u64 cksum3 = 0; /* Checksum based on contents of indexes */ Fts5Buffer term = {0,0,0}; /* Buffer used to hold most recent term */ @@ -231134,20 +228077,19 @@ #endif const int flags = FTS5INDEX_QUERY_NOOUTPUT; /* Load the FTS index structure */ pStruct = fts5StructureRead(p); - if( pStruct==0 ){ - assert( p->rc!=SQLITE_OK ); - return fts5IndexReturn(p); - } /* Check that the internal nodes of each segment match the leaves */ - for(iLvl=0; iLvlnLevel; iLvl++){ - for(iSeg=0; iSegaLevel[iLvl].nSeg; iSeg++){ - Fts5StructureSegment *pSeg = &pStruct->aLevel[iLvl].aSeg[iSeg]; - fts5IndexIntegrityCheckSegment(p, pSeg); + if( pStruct ){ + int iLvl, iSeg; + for(iLvl=0; iLvlnLevel; iLvl++){ + for(iSeg=0; iSegaLevel[iLvl].nSeg; iSeg++){ + Fts5StructureSegment *pSeg = &pStruct->aLevel[iLvl].aSeg[iSeg]; + fts5IndexIntegrityCheckSegment(p, pSeg); + } } } /* The cksum argument passed to this function is a checksum calculated ** based on all expected entries in the FTS index (including prefix index @@ -232520,11 +229462,11 @@ int rc; rc = sqlite3_step(pSorter->pStmt); if( rc==SQLITE_DONE ){ rc = SQLITE_OK; - CsrFlagSet(pCsr, FTS5CSR_EOF|FTS5CSR_REQUIRE_CONTENT); + CsrFlagSet(pCsr, FTS5CSR_EOF); }else if( rc==SQLITE_ROW ){ const u8 *a; const u8 *aBlob; int nBlob; int i; @@ -233090,12 +230032,11 @@ pCsr->ePlan = (pRowidEq ? FTS5_PLAN_ROWID : FTS5_PLAN_SCAN); rc = sqlite3Fts5StorageStmt( pTab->pStorage, fts5StmtType(pCsr), &pCsr->pStmt, &pTab->p.base.zErrMsg ); if( rc==SQLITE_OK ){ - if( pRowidEq!=0 ){ - assert( pCsr->ePlan==FTS5_PLAN_ROWID ); + if( pCsr->ePlan==FTS5_PLAN_ROWID ){ sqlite3_bind_value(pCsr->pStmt, 1, pRowidEq); }else{ sqlite3_bind_int64(pCsr->pStmt, 1, pCsr->iFirstRowid); sqlite3_bind_int64(pCsr->pStmt, 2, pCsr->iLastRowid); } @@ -234509,11 +231450,11 @@ int nArg, /* Number of args */ sqlite3_value **apUnused /* Function arguments */ ){ assert( nArg==0 ); UNUSED_PARAM2(nArg, apUnused); - sqlite3_result_text(pCtx, "fts5: 2022-05-06 15:25:27 78d9c993d404cdfaa7fdd2973fa1052e3da9f66215cff9c5540ebe55c407d9fe", -1, SQLITE_TRANSIENT); + sqlite3_result_text(pCtx, "fts5: 2021-10-04 11:10:15 8b24c177061c38361588f419eda9b7943b72a0c6b2855b6f39272451b8a1b813", -1, SQLITE_TRANSIENT); } /* ** Return true if zName is the extension on one of the shadow tables used ** by this module. @@ -235060,20 +232001,16 @@ rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 1, iDel); for(iCol=1; rc==SQLITE_OK && iCol<=pConfig->nCol; iCol++){ if( pConfig->abUnindexed[iCol-1]==0 ){ const char *zText; int nText; - assert( pSeek==0 || apVal==0 ); - assert( pSeek!=0 || apVal!=0 ); if( pSeek ){ zText = (const char*)sqlite3_column_text(pSeek, iCol); nText = sqlite3_column_bytes(pSeek, iCol); - }else if( ALWAYS(apVal) ){ + }else{ zText = (const char*)sqlite3_value_text(apVal[iCol-1]); nText = sqlite3_value_bytes(apVal[iCol-1]); - }else{ - continue; } ctx.szCol = 0; rc = sqlite3Fts5Tokenize(pConfig, FTS5_TOKENIZE_DOCUMENT, zText, nText, (void*)&ctx, fts5StorageInsertCallback ); @@ -235705,13 +232642,12 @@ sqlite3_stmt *pLookup = 0; /* Statement to query %_docsize */ int rc; /* Return Code */ assert( p->pConfig->bColumnsize ); rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP_DOCSIZE, &pLookup, 0); - if( pLookup ){ + if( rc==SQLITE_OK ){ int bCorrupt = 1; - assert( rc==SQLITE_OK ); sqlite3_bind_int64(pLookup, 1, iRowid); if( SQLITE_ROW==sqlite3_step(pLookup) ){ const u8 *aBlob = sqlite3_column_blob(pLookup, 0); int nBlob = sqlite3_column_bytes(pLookup, 0); if( 0==fts5StorageDecodeSizeArray(aCol, nCol, aBlob, nBlob) ){ @@ -235720,12 +232656,10 @@ } rc = sqlite3_reset(pLookup); if( bCorrupt && rc==SQLITE_OK ){ rc = FTS5_CORRUPT; } - }else{ - assert( rc!=SQLITE_OK ); } return rc; } @@ -238726,11 +235660,11 @@ rc = sqlite3Fts5FlushToDisk(pFts5); } } if( rc==SQLITE_OK ){ - i64 nByte = pFts5->pConfig->nCol * sizeof(i64)*2 + sizeof(Fts5VocabCursor); + int nByte = pFts5->pConfig->nCol * sizeof(i64)*2 + sizeof(Fts5VocabCursor); pCsr = (Fts5VocabCursor*)sqlite3Fts5MallocZero(&rc, nByte); } if( pCsr ){ pCsr->pFts5 = pFts5; Index: lib/sqlite3.h ================================================================== --- lib/sqlite3.h +++ lib/sqlite3.h @@ -144,13 +144,13 @@ ** ** See also: [sqlite3_libversion()], ** [sqlite3_libversion_number()], [sqlite3_sourceid()], ** [sqlite_version()] and [sqlite_source_id()]. */ -#define SQLITE_VERSION "3.38.5" -#define SQLITE_VERSION_NUMBER 3038005 -#define SQLITE_SOURCE_ID "2022-05-06 15:25:27 78d9c993d404cdfaa7fdd2973fa1052e3da9f66215cff9c5540ebe55c407d9fe" +#define SQLITE_VERSION "3.37.0" +#define SQLITE_VERSION_NUMBER 3037000 +#define SQLITE_SOURCE_ID "2021-10-04 11:10:15 8b24c177061c38361588f419eda9b7943b72a0c6b2855b6f39272451b8a1b813" /* ** CAPI3REF: Run-Time Library Version Numbers ** KEYWORDS: sqlite3_version sqlite3_sourceid ** @@ -537,10 +537,11 @@ #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */ #define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8)) +#define SQLITE_CANTOPEN_EXISTS (SQLITE_CANTOPEN | (7<<8)) #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8)) #define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8)) #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) @@ -564,31 +565,18 @@ #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8)) #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8)) #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8)) -#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */ +#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* ** CAPI3REF: Flags For File Open Operations ** ** These bit values are intended for use in the ** 3rd parameter to the [sqlite3_open_v2()] interface and ** in the 4th parameter to the [sqlite3_vfs.xOpen] method. -** -** Only those flags marked as "Ok for sqlite3_open_v2()" may be -** used as the third argument to the [sqlite3_open_v2()] interface. -** The other flags have historically been ignored by sqlite3_open_v2(), -** though future versions of SQLite might change so that an error is -** raised if any of the disallowed bits are passed into sqlite3_open_v2(). -** Applications should not depend on the historical behavior. -** -** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into -** [sqlite3_open_v2()] does *not* cause the underlying database file -** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into -** [sqlite3_open_v2()] has historically be a no-op and might become an -** error in future versions of SQLite. */ #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ @@ -607,11 +595,10 @@ #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ #define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */ -#define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */ /* Reserved: 0x00F00000 */ /* Legacy compatibility: */ #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ @@ -3428,34 +3415,24 @@ ** ^(
    [SQLITE_OPEN_PRIVATECACHE]
    **
    The database is opened [shared cache] disabled, overriding ** the default shared cache setting provided by ** [sqlite3_enable_shared_cache()].)^ ** -** [[OPEN_EXRESCODE]] ^(
    [SQLITE_OPEN_EXRESCODE]
    -**
    The database connection comes up in "extended result code mode". -** In other words, the database behaves has if -** [sqlite3_extended_result_codes(db,1)] where called on the database -** connection as soon as the connection is created. In addition to setting -** the extended result code mode, this flag also causes [sqlite3_open_v2()] -** to return an extended result code.
    -** ** [[OPEN_NOFOLLOW]] ^(
    [SQLITE_OPEN_NOFOLLOW]
    **
    The database filename is not allowed to be a symbolic link
    +** +** [[OPEN_EXCLUSIVE]] ^(
    [SQLITE_OPEN_EXCLUSIVE]
    +**
    This flag causes the open to fail if the database file already +** exists. The open will only be success if this flag is used in combination +** with the SQLITE_OPEN_CREATE and SQLITE_OPEN_READWRITE flags and if +** the file does not previously exist.
    ** )^ ** ** If the 3rd parameter to sqlite3_open_v2() is not one of the ** required combinations shown above optionally combined with other ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits] -** then the behavior is undefined. Historic versions of SQLite -** have silently ignored surplus bits in the flags parameter to -** sqlite3_open_v2(), however that behavior might not be carried through -** into future versions of SQLite and so applications should not rely -** upon it. Note in particular that the SQLITE_OPEN_EXCLUSIVE flag is a no-op -** for sqlite3_open_v2(). The SQLITE_OPEN_EXCLUSIVE does *not* cause -** the open to fail if the database already exists. The SQLITE_OPEN_EXCLUSIVE -** flag is intended for use by the [sqlite3_vfs|VFS interface] only, and not -** by sqlite3_open_v2(). +** then the behavior is undefined. ** ** ^The fourth parameter to sqlite3_open_v2() is the name of the ** [sqlite3_vfs] object that defines the operating system interface that ** the new database connection should use. ^If the fourth parameter is ** a NULL pointer then the default [sqlite3_vfs] object is used. @@ -3822,18 +3799,17 @@ ** ** The values returned by sqlite3_errcode() and/or ** sqlite3_extended_errcode() might change with each API call. ** Except, there are some interfaces that are guaranteed to never ** change the value of the error code. The error-code preserving -** interfaces include the following: +** interfaces are: ** **
      **
    • sqlite3_errcode() **
    • sqlite3_extended_errcode() **
    • sqlite3_errmsg() **
    • sqlite3_errmsg16() -**
    • sqlite3_error_offset() **
    ** ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language ** text that describes the error, as either UTF-8 or UTF-16 respectively. ** ^(Memory to hold the error message string is managed internally. @@ -3844,17 +3820,10 @@ ** ^The sqlite3_errstr() interface returns the English-language text ** that describes the [result code], as UTF-8. ** ^(Memory to hold the error message string is managed internally ** and must not be freed by the application)^. ** -** ^If the most recent error references a specific token in the input -** SQL, the sqlite3_error_offset() interface returns the byte offset -** of the start of that token. ^The byte offset returned by -** sqlite3_error_offset() assumes that the input SQL is UTF8. -** ^If the most recent error does not reference a specific token in the input -** SQL, then the sqlite3_error_offset() function returns -1. -** ** When the serialized [threading mode] is in use, it might be the ** case that a second error occurs on a separate thread in between ** the time of the first error and the call to these interfaces. ** When that happens, the second error will be reported since these ** interfaces always report the most recent result. To avoid @@ -3870,11 +3839,10 @@ SQLITE_API int sqlite3_errcode(sqlite3 *db); SQLITE_API int sqlite3_extended_errcode(sqlite3 *db); SQLITE_API const char *sqlite3_errmsg(sqlite3*); SQLITE_API const void *sqlite3_errmsg16(sqlite3*); SQLITE_API const char *sqlite3_errstr(int); -SQLITE_API int sqlite3_error_offset(sqlite3 *db); /* ** CAPI3REF: Prepared Statement Object ** KEYWORDS: {prepared statement} {prepared statements} ** @@ -4282,14 +4250,10 @@ ** ^For example, an UPDATE statement might have a WHERE clause that ** makes it a no-op, but the sqlite3_stmt_readonly() result would still ** be false. ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a ** read-only no-op if the table already exists, but ** sqlite3_stmt_readonly() still returns false for such a statement. -** -** ^If prepared statement X is an [EXPLAIN] or [EXPLAIN QUERY PLAN] -** statement, then sqlite3_stmt_readonly(X) returns the same value as -** if the EXPLAIN or EXPLAIN QUERY PLAN prefix were omitted. */ SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); /* ** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement @@ -4354,12 +4318,10 @@ ** still make the distinction between protected and unprotected ** sqlite3_value objects even when not strictly required. ** ** ^The sqlite3_value objects that are passed as parameters into the ** implementation of [application-defined SQL functions] are protected. -** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()] -** are protected. ** ^The sqlite3_value object returned by ** [sqlite3_column_value()] is unprotected. ** Unprotected sqlite3_value objects may only be used as arguments ** to [sqlite3_result_value()], [sqlite3_bind_value()], and ** [sqlite3_value_dup()]. @@ -4977,14 +4939,10 @@ ** ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(), ** even empty strings, are always zero-terminated. ^The return ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer. ** -** ^Strings returned by sqlite3_column_text16() always have the endianness -** which is native to the platform, regardless of the text encoding set -** for the database. -** ** Warning: ^The object returned by [sqlite3_column_value()] is an ** [unprotected sqlite3_value] object. In a multithreaded environment, ** an unprotected sqlite3_value object may only be used safely with ** [sqlite3_bind_value()] and [sqlite3_result_value()]. ** If the [unprotected sqlite3_value] object returned by @@ -4994,11 +4952,11 @@ ** Hence, the sqlite3_column_value() interface ** is normally only useful within the implementation of ** [application-defined SQL functions] or [virtual tables], not within ** top-level application code. ** -** These routines may attempt to convert the datatype of the result. +** The these routines may attempt to convert the datatype of the result. ** ^For example, if the internal representation is FLOAT and a text result ** is requested, [sqlite3_snprintf()] is used internally to perform the ** conversion automatically. ^(The following table details the conversions ** that are applied: ** @@ -5019,11 +4977,11 @@ ** TEXT INTEGER [CAST] to INTEGER ** TEXT FLOAT [CAST] to REAL ** TEXT BLOB No change ** BLOB INTEGER [CAST] to INTEGER ** BLOB FLOAT [CAST] to REAL -** BLOB TEXT [CAST] to TEXT, ensure zero terminator +** BLOB TEXT Add a zero terminator if needed ** ** )^ ** ** Note that when type conversions occur, pointers returned by prior ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or @@ -6431,76 +6389,10 @@ ** ** See also the [sqlite3_update_hook()] interface. */ SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); - -/* -** CAPI3REF: Autovacuum Compaction Amount Callback -** METHOD: sqlite3 -** -** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback -** function C that is invoked prior to each autovacuum of the database -** file. ^The callback is passed a copy of the generic data pointer (P), -** the schema-name of the attached database that is being autovacuumed, -** the the size of the database file in pages, the number of free pages, -** and the number of bytes per page, respectively. The callback should -** return the number of free pages that should be removed by the -** autovacuum. ^If the callback returns zero, then no autovacuum happens. -** ^If the value returned is greater than or equal to the number of -** free pages, then a complete autovacuum happens. -** -**

    ^If there are multiple ATTACH-ed database files that are being -** modified as part of a transaction commit, then the autovacuum pages -** callback is invoked separately for each file. -** -**

    The callback is not reentrant. The callback function should -** not attempt to invoke any other SQLite interface. If it does, bad -** things may happen, including segmentation faults and corrupt database -** files. The callback function should be a simple function that -** does some arithmetic on its input parameters and returns a result. -** -** ^The X parameter to sqlite3_autovacuum_pages(D,C,P,X) is an optional -** destructor for the P parameter. ^If X is not NULL, then X(P) is -** invoked whenever the database connection closes or when the callback -** is overwritten by another invocation of sqlite3_autovacuum_pages(). -** -**

    ^There is only one autovacuum pages callback per database connection. -** ^Each call to the sqlite3_autovacuum_pages() interface overrides all -** previous invocations for that database connection. ^If the callback -** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer, -** then the autovacuum steps callback is cancelled. The return value -** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might -** be some other error code if something goes wrong. The current -** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other -** return codes might be added in future releases. -** -**

    If no autovacuum pages callback is specified (the usual case) or -** a NULL pointer is provided for the callback, -** then the default behavior is to vacuum all free pages. So, in other -** words, the default behavior is the same as if the callback function -** were something like this: -** -**

    -**     unsigned int demonstration_autovac_pages_callback(
    -**       void *pClientData,
    -**       const char *zSchema,
    -**       unsigned int nDbPage,
    -**       unsigned int nFreePage,
    -**       unsigned int nBytePerPage
    -**     ){
    -**       return nFreePage;
    -**     }
    -** 
    -*/ -SQLITE_API int sqlite3_autovacuum_pages( - sqlite3 *db, - unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int), - void*, - void(*)(void*) -); - /* ** CAPI3REF: Data Change Notification Callbacks ** METHOD: sqlite3 ** @@ -7139,60 +7031,28 @@ /* ** CAPI3REF: Virtual Table Constraint Operator Codes ** ** These macros define the allowed values for the ** [sqlite3_index_info].aConstraint[].op field. Each value represents -** an operator that is part of a constraint term in the WHERE clause of +** an operator that is part of a constraint term in the wHERE clause of ** a query that uses a [virtual table]. -** -** ^The left-hand operand of the operator is given by the corresponding -** aConstraint[].iColumn field. ^An iColumn of -1 indicates the left-hand -** operand is the rowid. -** The SQLITE_INDEX_CONSTRAINT_LIMIT and SQLITE_INDEX_CONSTRAINT_OFFSET -** operators have no left-hand operand, and so for those operators the -** corresponding aConstraint[].iColumn is meaningless and should not be -** used. -** -** All operator values from SQLITE_INDEX_CONSTRAINT_FUNCTION through -** value 255 are reserved to represent functions that are overloaded -** by the [xFindFunction|xFindFunction method] of the virtual table -** implementation. -** -** The right-hand operands for each constraint might be accessible using -** the [sqlite3_vtab_rhs_value()] interface. Usually the right-hand -** operand is only available if it appears as a single constant literal -** in the input SQL. If the right-hand operand is another column or an -** expression (even a constant expression) or a parameter, then the -** sqlite3_vtab_rhs_value() probably will not be able to extract it. -** ^The SQLITE_INDEX_CONSTRAINT_ISNULL and -** SQLITE_INDEX_CONSTRAINT_ISNOTNULL operators have no right-hand operand -** and hence calls to sqlite3_vtab_rhs_value() for those operators will -** always return SQLITE_NOTFOUND. -** -** The collating sequence to be used for comparison can be found using -** the [sqlite3_vtab_collation()] interface. For most real-world virtual -** tables, the collating sequence of constraints does not matter (for example -** because the constraints are numeric) and so the sqlite3_vtab_collation() -** interface is no commonly needed. */ -#define SQLITE_INDEX_CONSTRAINT_EQ 2 -#define SQLITE_INDEX_CONSTRAINT_GT 4 -#define SQLITE_INDEX_CONSTRAINT_LE 8 -#define SQLITE_INDEX_CONSTRAINT_LT 16 -#define SQLITE_INDEX_CONSTRAINT_GE 32 -#define SQLITE_INDEX_CONSTRAINT_MATCH 64 -#define SQLITE_INDEX_CONSTRAINT_LIKE 65 -#define SQLITE_INDEX_CONSTRAINT_GLOB 66 -#define SQLITE_INDEX_CONSTRAINT_REGEXP 67 -#define SQLITE_INDEX_CONSTRAINT_NE 68 -#define SQLITE_INDEX_CONSTRAINT_ISNOT 69 -#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70 -#define SQLITE_INDEX_CONSTRAINT_ISNULL 71 -#define SQLITE_INDEX_CONSTRAINT_IS 72 -#define SQLITE_INDEX_CONSTRAINT_LIMIT 73 -#define SQLITE_INDEX_CONSTRAINT_OFFSET 74 -#define SQLITE_INDEX_CONSTRAINT_FUNCTION 150 +#define SQLITE_INDEX_CONSTRAINT_EQ 2 +#define SQLITE_INDEX_CONSTRAINT_GT 4 +#define SQLITE_INDEX_CONSTRAINT_LE 8 +#define SQLITE_INDEX_CONSTRAINT_LT 16 +#define SQLITE_INDEX_CONSTRAINT_GE 32 +#define SQLITE_INDEX_CONSTRAINT_MATCH 64 +#define SQLITE_INDEX_CONSTRAINT_LIKE 65 +#define SQLITE_INDEX_CONSTRAINT_GLOB 66 +#define SQLITE_INDEX_CONSTRAINT_REGEXP 67 +#define SQLITE_INDEX_CONSTRAINT_NE 68 +#define SQLITE_INDEX_CONSTRAINT_ISNOT 69 +#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70 +#define SQLITE_INDEX_CONSTRAINT_ISNULL 71 +#define SQLITE_INDEX_CONSTRAINT_IS 72 +#define SQLITE_INDEX_CONSTRAINT_FUNCTION 150 /* ** CAPI3REF: Register A Virtual Table Implementation ** METHOD: sqlite3 ** @@ -7217,11 +7077,11 @@ ** ^The sqlite3_create_module() ** interface is equivalent to sqlite3_create_module_v2() with a NULL ** destructor. ** ** ^If the third parameter (the pointer to the sqlite3_module object) is -** NULL then no new module is created and any existing modules with the +** NULL then no new module is create and any existing modules with the ** same name are dropped. ** ** See also: [sqlite3_drop_modules()] */ SQLITE_API int sqlite3_create_module( @@ -7993,12 +7853,11 @@ #define SQLITE_TESTCTRL_PRNG_SEED 28 #define SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS 29 #define SQLITE_TESTCTRL_SEEK_COUNT 30 #define SQLITE_TESTCTRL_TRACEFLAGS 31 #define SQLITE_TESTCTRL_TUNE 32 -#define SQLITE_TESTCTRL_LOGEST 33 -#define SQLITE_TESTCTRL_LAST 33 /* Largest TESTCTRL */ +#define SQLITE_TESTCTRL_LAST 32 /* Largest TESTCTRL */ /* ** CAPI3REF: SQL Keyword Checking ** ** These routines provide access to the set of SQL language keywords @@ -8517,20 +8376,10 @@ ** been run. A single "run" for the purposes of this counter is one ** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()]. ** The counter is incremented on the first [sqlite3_step()] call of each ** cycle. ** -** [[SQLITE_STMTSTATUS_FILTER_MISS]] -** [[SQLITE_STMTSTATUS_FILTER HIT]] -**
    SQLITE_STMTSTATUS_FILTER_HIT
    -** SQLITE_STMTSTATUS_FILTER_MISS
    -**
    ^SQLITE_STMTSTATUS_FILTER_HIT is the number of times that a join -** step was bypassed because a Bloom filter returned not-found. The -** corresponding SQLITE_STMTSTATUS_FILTER_MISS value is the number of -** times that the Bloom filter returned a find, and thus the join step -** had to be processed as normal. -** ** [[SQLITE_STMTSTATUS_MEMUSED]]
    SQLITE_STMTSTATUS_MEMUSED
    **
    ^This is the approximate number of bytes of heap memory ** used to store the prepared statement. ^This value is not actually ** a counter, and so the resetFlg parameter to sqlite3_stmt_status() ** is ignored when the opcode is SQLITE_STMTSTATUS_MEMUSED. @@ -8541,12 +8390,10 @@ #define SQLITE_STMTSTATUS_SORT 2 #define SQLITE_STMTSTATUS_AUTOINDEX 3 #define SQLITE_STMTSTATUS_VM_STEP 4 #define SQLITE_STMTSTATUS_REPREPARE 5 #define SQLITE_STMTSTATUS_RUN 6 -#define SQLITE_STMTSTATUS_FILTER_MISS 7 -#define SQLITE_STMTSTATUS_FILTER_HIT 8 #define SQLITE_STMTSTATUS_MEMUSED 99 /* ** CAPI3REF: Custom Page Cache Object ** @@ -9511,272 +9358,22 @@ */ SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*); /* ** CAPI3REF: Determine The Collation For a Virtual Table Constraint -** METHOD: sqlite3_index_info ** ** This function may only be called from within a call to the [xBestIndex] -** method of a [virtual table]. This function returns a pointer to a string -** that is the name of the appropriate collation sequence to use for text -** comparisons on the constraint identified by its arguments. -** -** The first argument must be the pointer to the [sqlite3_index_info] object -** that is the first parameter to the xBestIndex() method. The second argument -** must be an index into the aConstraint[] array belonging to the -** sqlite3_index_info structure passed to xBestIndex. -** -** Important: -** The first parameter must be the same pointer that is passed into the -** xBestMethod() method. The first parameter may not be a pointer to a -** different [sqlite3_index_info] object, even an exact copy. -** -** The return value is computed as follows: -** -**
      -**
    1. If the constraint comes from a WHERE clause expression that contains -** a [COLLATE operator], then the name of the collation specified by -** that COLLATE operator is returned. -**

    2. If there is no COLLATE operator, but the column that is the subject -** of the constraint specifies an alternative collating sequence via -** a [COLLATE clause] on the column definition within the CREATE TABLE -** statement that was passed into [sqlite3_declare_vtab()], then the -** name of that alternative collating sequence is returned. -**

    3. Otherwise, "BINARY" is returned. -**

    -*/ -SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int); - -/* -** CAPI3REF: Determine if a virtual table query is DISTINCT -** METHOD: sqlite3_index_info -** -** This API may only be used from within an [xBestIndex|xBestIndex method] -** of a [virtual table] implementation. The result of calling this -** interface from outside of xBestIndex() is undefined and probably harmful. -** -** ^The sqlite3_vtab_distinct() interface returns an integer that is -** either 0, 1, or 2. The integer returned by sqlite3_vtab_distinct() -** gives the virtual table additional information about how the query -** planner wants the output to be ordered. As long as the virtual table -** can meet the ordering requirements of the query planner, it may set -** the "orderByConsumed" flag. -** -**
    1. -** ^If the sqlite3_vtab_distinct() interface returns 0, that means -** that the query planner needs the virtual table to return all rows in the -** sort order defined by the "nOrderBy" and "aOrderBy" fields of the -** [sqlite3_index_info] object. This is the default expectation. If the -** virtual table outputs all rows in sorted order, then it is always safe for -** the xBestIndex method to set the "orderByConsumed" flag, regardless of -** the return value from sqlite3_vtab_distinct(). -**

    2. -** ^(If the sqlite3_vtab_distinct() interface returns 1, that means -** that the query planner does not need the rows to be returned in sorted order -** as long as all rows with the same values in all columns identified by the -** "aOrderBy" field are adjacent.)^ This mode is used when the query planner -** is doing a GROUP BY. -**

    3. -** ^(If the sqlite3_vtab_distinct() interface returns 2, that means -** that the query planner does not need the rows returned in any particular -** order, as long as rows with the same values in all "aOrderBy" columns -** are adjacent.)^ ^(Furthermore, only a single row for each particular -** combination of values in the columns identified by the "aOrderBy" field -** needs to be returned.)^ ^It is always ok for two or more rows with the same -** values in all "aOrderBy" columns to be returned, as long as all such rows -** are adjacent. ^The virtual table may, if it chooses, omit extra rows -** that have the same value for all columns identified by "aOrderBy". -** ^However omitting the extra rows is optional. -** This mode is used for a DISTINCT query. -**

    -** -** ^For the purposes of comparing virtual table output values to see if the -** values are same value for sorting purposes, two NULL values are considered -** to be the same. In other words, the comparison operator is "IS" -** (or "IS NOT DISTINCT FROM") and not "==". -** -** If a virtual table implementation is unable to meet the requirements -** specified above, then it must not set the "orderByConsumed" flag in the -** [sqlite3_index_info] object or an incorrect answer may result. -** -** ^A virtual table implementation is always free to return rows in any order -** it wants, as long as the "orderByConsumed" flag is not set. ^When the -** the "orderByConsumed" flag is unset, the query planner will add extra -** [bytecode] to ensure that the final results returned by the SQL query are -** ordered correctly. The use of the "orderByConsumed" flag and the -** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful -** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed" -** flag might help queries against a virtual table to run faster. Being -** overly aggressive and setting the "orderByConsumed" flag when it is not -** valid to do so, on the other hand, might cause SQLite to return incorrect -** results. -*/ -SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*); - -/* -** CAPI3REF: Identify and handle IN constraints in xBestIndex -** -** This interface may only be used from within an -** [xBestIndex|xBestIndex() method] of a [virtual table] implementation. -** The result of invoking this interface from any other context is -** undefined and probably harmful. -** -** ^(A constraint on a virtual table of the form -** "[IN operator|column IN (...)]" is -** communicated to the xBestIndex method as a -** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use -** this constraint, it must set the corresponding -** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under -** the usual mode of handling IN operators, SQLite generates [bytecode] -** that invokes the [xFilter|xFilter() method] once for each value -** on the right-hand side of the IN operator.)^ Thus the virtual table -** only sees a single value from the right-hand side of the IN operator -** at a time. -** -** In some cases, however, it would be advantageous for the virtual -** table to see all values on the right-hand of the IN operator all at -** once. The sqlite3_vtab_in() interfaces facilitates this in two ways: -** -**
      -**
    1. -** ^A call to sqlite3_vtab_in(P,N,-1) will return true (non-zero) -** if and only if the [sqlite3_index_info|P->aConstraint][N] constraint -** is an [IN operator] that can be processed all at once. ^In other words, -** sqlite3_vtab_in() with -1 in the third argument is a mechanism -** by which the virtual table can ask SQLite if all-at-once processing -** of the IN operator is even possible. -** -**

    2. -** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates -** to SQLite that the virtual table does or does not want to process -** the IN operator all-at-once, respectively. ^Thus when the third -** parameter (F) is non-negative, this interface is the mechanism by -** which the virtual table tells SQLite how it wants to process the -** IN operator. -**

    -** -** ^The sqlite3_vtab_in(P,N,F) interface can be invoked multiple times -** within the same xBestIndex method call. ^For any given P,N pair, -** the return value from sqlite3_vtab_in(P,N,F) will always be the same -** within the same xBestIndex call. ^If the interface returns true -** (non-zero), that means that the constraint is an IN operator -** that can be processed all-at-once. ^If the constraint is not an IN -** operator or cannot be processed all-at-once, then the interface returns -** false. -** -** ^(All-at-once processing of the IN operator is selected if both of the -** following conditions are met: -** -**
      -**
    1. The P->aConstraintUsage[N].argvIndex value is set to a positive -** integer. This is how the virtual table tells SQLite that it wants to -** use the N-th constraint. -** -**

    2. The last call to sqlite3_vtab_in(P,N,F) for which F was -** non-negative had F>=1. -**

    )^ -** -** ^If either or both of the conditions above are false, then SQLite uses -** the traditional one-at-a-time processing strategy for the IN constraint. -** ^If both conditions are true, then the argvIndex-th parameter to the -** xFilter method will be an [sqlite3_value] that appears to be NULL, -** but which can be passed to [sqlite3_vtab_in_first()] and -** [sqlite3_vtab_in_next()] to find all values on the right-hand side -** of the IN constraint. -*/ -SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle); - -/* -** CAPI3REF: Find all elements on the right-hand side of an IN constraint. -** -** These interfaces are only useful from within the -** [xFilter|xFilter() method] of a [virtual table] implementation. -** The result of invoking these interfaces from any other context -** is undefined and probably harmful. -** -** The X parameter in a call to sqlite3_vtab_in_first(X,P) or -** sqlite3_vtab_in_next(X,P) must be one of the parameters to the -** xFilter method which invokes these routines, and specifically -** a parameter that was previously selected for all-at-once IN constraint -** processing use the [sqlite3_vtab_in()] interface in the -** [xBestIndex|xBestIndex method]. ^(If the X parameter is not -** an xFilter argument that was selected for all-at-once IN constraint -** processing, then these routines return [SQLITE_MISUSE])^ or perhaps -** exhibit some other undefined or harmful behavior. -** -** ^(Use these routines to access all values on the right-hand side -** of the IN constraint using code like the following: -** -**
    -**    for(rc=sqlite3_vtab_in_first(pList, &pVal);
    -**        rc==SQLITE_OK && pVal
    -**        rc=sqlite3_vtab_in_next(pList, &pVal)
    -**    ){
    -**      // do something with pVal
    -**    }
    -**    if( rc!=SQLITE_OK ){
    -**      // an error has occurred
    -**    }
    -** 
    )^ -** -** ^On success, the sqlite3_vtab_in_first(X,P) and sqlite3_vtab_in_next(X,P) -** routines return SQLITE_OK and set *P to point to the first or next value -** on the RHS of the IN constraint. ^If there are no more values on the -** right hand side of the IN constraint, then *P is set to NULL and these -** routines return [SQLITE_DONE]. ^The return value might be -** some other value, such as SQLITE_NOMEM, in the event of a malfunction. -** -** The *ppOut values returned by these routines are only valid until the -** next call to either of these routines or until the end of the xFilter -** method from which these routines were called. If the virtual table -** implementation needs to retain the *ppOut values for longer, it must make -** copies. The *ppOut values are [protected sqlite3_value|protected]. -*/ -SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut); -SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut); - -/* -** CAPI3REF: Constraint values in xBestIndex() -** METHOD: sqlite3_index_info -** -** This API may only be used from within the [xBestIndex|xBestIndex method] -** of a [virtual table] implementation. The result of calling this interface -** from outside of an xBestIndex method are undefined and probably harmful. -** -** ^When the sqlite3_vtab_rhs_value(P,J,V) interface is invoked from within -** the [xBestIndex] method of a [virtual table] implementation, with P being -** a copy of the [sqlite3_index_info] object pointer passed into xBestIndex and -** J being a 0-based index into P->aConstraint[], then this routine -** attempts to set *V to the value of the right-hand operand of -** that constraint if the right-hand operand is known. ^If the -** right-hand operand is not known, then *V is set to a NULL pointer. -** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if -** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V) -** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th -** constraint is not available. ^The sqlite3_vtab_rhs_value() interface -** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if -** something goes wrong. -** -** The sqlite3_vtab_rhs_value() interface is usually only successful if -** the right-hand operand of a constraint is a literal value in the original -** SQL statement. If the right-hand operand is an expression or a reference -** to some other column or a [host parameter], then sqlite3_vtab_rhs_value() -** will probably return [SQLITE_NOTFOUND]. -** -** ^(Some constraints, such as [SQLITE_INDEX_CONSTRAINT_ISNULL] and -** [SQLITE_INDEX_CONSTRAINT_ISNOTNULL], have no right-hand operand. For such -** constraints, sqlite3_vtab_rhs_value() always returns SQLITE_NOTFOUND.)^ -** -** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value -** and remains valid for the duration of the xBestIndex method call. -** ^When xBestIndex returns, the sqlite3_value object returned by -** sqlite3_vtab_rhs_value() is automatically deallocated. -** -** The "_rhs_" in the name of this routine is an abbreviation for -** "Right-Hand Side". -*/ -SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal); +** method of a [virtual table]. +** +** The first argument must be the sqlite3_index_info object that is the +** first parameter to the xBestIndex() method. The second argument must be +** an index into the aConstraint[] array belonging to the sqlite3_index_info +** structure passed to xBestIndex. This function returns a pointer to a buffer +** containing the name of the collation sequence for the corresponding +** constraint. +*/ +SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int); /* ** CAPI3REF: Conflict resolution modes ** KEYWORDS: {conflict resolution mode} ** Index: lib/sqlite3ext.h ================================================================== --- lib/sqlite3ext.h +++ lib/sqlite3ext.h @@ -335,24 +335,10 @@ int,const char**); void (*free_filename)(char*); sqlite3_file *(*database_file_object)(const char*); /* Version 3.34.0 and later */ int (*txn_state)(sqlite3*,const char*); - /* Version 3.36.1 and later */ - sqlite3_int64 (*changes64)(sqlite3*); - sqlite3_int64 (*total_changes64)(sqlite3*); - /* Version 3.37.0 and later */ - int (*autovacuum_pages)(sqlite3*, - unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int), - void*, void(*)(void*)); - /* Version 3.38.0 and later */ - int (*error_offset)(sqlite3*); - int (*vtab_rhs_value)(sqlite3_index_info*,int,sqlite3_value**); - int (*vtab_distinct)(sqlite3_index_info*); - int (*vtab_in)(sqlite3_index_info*,int,int); - int (*vtab_in_first)(sqlite3_value*,sqlite3_value**); - int (*vtab_in_next)(sqlite3_value*,sqlite3_value**); }; /* ** This is the function signature used for all extension entry points. It ** is also defined in the file "loadext.c". @@ -655,22 +641,10 @@ #define sqlite3_create_filename sqlite3_api->create_filename #define sqlite3_free_filename sqlite3_api->free_filename #define sqlite3_database_file_object sqlite3_api->database_file_object /* Version 3.34.0 and later */ #define sqlite3_txn_state sqlite3_api->txn_state -/* Version 3.36.1 and later */ -#define sqlite3_changes64 sqlite3_api->changes64 -#define sqlite3_total_changes64 sqlite3_api->total_changes64 -/* Version 3.37.0 and later */ -#define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages -/* Version 3.38.0 and later */ -#define sqlite3_error_offset sqlite3_api->error_offset -#define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value -#define sqlite3_vtab_distinct sqlite3_api->vtab_distinct -#define sqlite3_vtab_in sqlite3_api->vtab_in -#define sqlite3_vtab_in_first sqlite3_api->vtab_in_first -#define sqlite3_vtab_in_next sqlite3_api->vtab_in_next #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) /* This case when the file really is being compiled as a loadable ** extension */ ADDED signify/fnc-09-release.pub Index: signify/fnc-09-release.pub ================================================================== --- signify/fnc-09-release.pub +++ signify/fnc-09-release.pub @@ -0,0 +1,2 @@ +untrusted comment: fnc 0.9 public key +RWR/Unt0CGtNwq8vE59836HrU7Jt8ETbuxx2mnap+FakP2TCZLEcaS4j DELETED signify/fnc-11-release.pub Index: signify/fnc-11-release.pub ================================================================== --- signify/fnc-11-release.pub +++ signify/fnc-11-release.pub @@ -1,2 +0,0 @@ -untrusted comment: fnc 0.11 public key -RWQIBA4rVoFFDlh8+FWU6Oeg79hcWqdRXv1cTOzrwTeSxKiIUhMd5rRE Index: src/diff.c ================================================================== --- src/diff.c +++ src/diff.c @@ -192,16 +192,22 @@ /* fsl__dump_triples(&c, __FILE__, __LINE__); */ /* DEBUG */ if (!FLAG_CHK(flags, FNC_DIFF_NOOPT)) fsl__diff_optimize(&c); /* fsl__dump_triples(&c, __FILE__, __LINE__); */ /* DEBUG */ - /* Encode longest line length in flags to set max sbs diff width */ + /* + * For SBS diffs, compute total number of lines and set file column + * width to the longest line in the diff and encode result in flags. + * XXX I'm ambivalent about converting unified diffs to the line_type + * interface as it's extra allocations for no immediate gain but creates + * opportunities to do cool things; leave it till we want to do them? + */ if ((!sbswidth && FLAG_CHK(flags, FNC_DIFF_SIDEBYSIDE)) || sbswidth < 0) { flags |= ((int)(sbswidth & 0xFFFF)) << 8; FLAG_SET(flags, FNC_DIFF_SIDEBYSIDE); - rc = max_sbs_width(&c, &flags, context); + rc = alloc_lines_and_width(&c, &flags, context, *nlines, lines); if (rc) goto end; } if (out) { @@ -215,18 +221,16 @@ dos.proto.file = blob1; } dos.out = out; dos.state = state; dos.lines = *lines; - dos.nlines = *nlines; + dos.idx = nlines; dos.ansi = !!(FLAG_CHK(flags, FNC_DIFF_ANSI_COLOR)); if (FLAG_CHK(flags, FNC_DIFF_SIDEBYSIDE)) rc = sbsdiff(&c, &dos, NULL /*regex*/, context, flags); else rc = unidiff(&c, &dos, NULL /*regex*/, context, flags); - *lines = dos.lines; /* realloc'd */ - *nlines = dos.nlines; } else if (rawdata) { /* Return array of COPY/DELETE/INSERT triples. */ *rawdata = c.aEdit; c.aEdit = NULL; } @@ -236,17 +240,22 @@ fsl_free(c.aEdit); return rc; } /* - * Find the longest line in the file and encode the length in *flags. + * Iterate copy elements in the c->aEdit 3-tuple to compute start and end lines, + * including surrounding ctxt, of each chunk in the diff. Add result to nlines, + * allocate the total and assign to *lines, which must be disposed of by the + * caller. For SBS diffs, find the longest line and encode the length in *flags. */ int -max_sbs_width(fsl__diff_cx *c, int *flags, uint16_t ctxt) +alloc_lines_and_width(fsl__diff_cx *c, int *flags, uint16_t ctxt, + uint32_t nlines, enum line_type **lines) { int i, j, k; int endl, endr, start; /* Start and end of l+r chunks */ + uint32_t n = 0; /* Number of lines in the diff */ unsigned short sz, sbswidth; /* Size of each line and max width */ j = endl = endr = start = 0; k = c->nEdit; sbswidth = (*flags & FNC_DIFF_SIDEBYSIDE) ? sbsdiff_width(*flags) : 0; @@ -273,10 +282,11 @@ endl += MAX(c->aEdit[j + 1], 0); /* End of left side chunk */ endr += MAX(c->aEdit[j + 2], 0); /* End of right side chunk */ s = MAX(start - ctxt, 0); /* Include leading ctxt */ e = MIN(endl + ctxt, c->nFrom); /* L include trailing ctxt */ e2 = MIN(endr + ctxt, c->nTo); /* R include trailing ctxt */ + n += MAX(MAX(e, e2) - s + ctxt + 2, 0); /* Max lines in chunk */ /* * Now find the longest line. We'll make both the left and right * columns the width of the longest line from either side. * XXX Consider keeping max width of both sides to make each @@ -304,11 +314,14 @@ start += c->aEdit[j + 2]; } while ((j += 3) < k - 3); *flags |= ((int)(sbswidth & 0xFFF)) << 16; /* Encode max width */ - return FSL_RC_OK; + *lines = fsl_realloc(*lines, (nlines + n) * sizeof(enum line_type *)); + memset((*lines + nlines), 0, sizeof(enum line_type *) * n); + + return *lines ? FSL_RC_OK : FSL_RC_ERROR; } /* * Convert str byte size n to actual column width by expanding tabs and * accounting for unicode continuation bytes. Return the result. @@ -316,11 +329,11 @@ unsigned short etcount(const char *str, unsigned short n) { unsigned short c = 0; - while (str && (str[c] != '\n' && str[c] != '\0')) { + while (str && str[c] != '\n') { /* Expand tabs */ if (str[c] == '\t') n += 8 - (c % 8); if (UTF_CONT(str[c])) --n; @@ -577,11 +590,11 @@ } } ++idx; } - if (dst) /* trim trailing '\n' when copying */ + if (dst) /* trim trailing when copying '\n' */ rc = fsl_buffer_append(dst, &src->mem[start], idx - start - 1); *offset = start; return rc; } @@ -671,24 +684,24 @@ fsl_buffer sbscols[5] = { fsl_buffer_empty_m, fsl_buffer_empty_m, fsl_buffer_empty_m, fsl_buffer_empty_m, fsl_buffer_empty_m }; - struct sbsline s; /* Output line buffer */ - static int chunks = 0; /* Number of chunks so far processed */ - int li, ri; /* Index of next line in l[] and r[] */ - int *c; /* copy/delete/insert triples */ - int ci; /* Index into c[] */ - int nc; /* number of c[] triples to process */ - int max_ci; /* Maximum value for ci */ - int nleft, nright; /* Number of l and r lines to output */ - int ntotal; /* Total number of lines to output */ - int skip; /* Number of lines to skip */ - int i, j, rc = FSL_RC_OK; - enum line_type **lines = &dst->lines; - uint32_t *nlines = &dst->nlines; - bool showsep = false; + struct sbsline s; /* Output line buffer */ + static int chunks = 0; /* Number of chunks so far processed */ + int li, ri; /* Index of next line in l[] and r[] */ + int *c; /* copy/delete/insert triples */ + int ci; /* Index into c[] */ + int nc; /* number of c[] triples to process */ + int max_ci; /* Maximum value for ci */ + int nleft, nright; /* Number of l and r lines to output */ + int ntotal; /* Total number of lines to output */ + int skip; /* Number of lines to skip */ + int i, j, rc = FSL_RC_OK; + uint32_t *idx = dst->idx; + enum line_type *lines = dst->lines; + bool showsep = false; li = ri = 0; memset(&s, 0, sizeof(s)); s.output = dst; s.width = sbsdiff_width(flags); @@ -778,13 +791,11 @@ nright += c[ci + i * 3]; } /* Draw separator between blocks except the first. */ if (showsep) { - rc = add_line_type(lines, nlines, LINE_DIFF_SEPARATOR); - if (rc) - goto end; + lines[(*idx)++] = LINE_DIFF_SEPARATOR; if (s.esc) { char ln[10]; fsl_snprintf(ln, sizeof(ln), "%d", li + skip + 1); rc = sbsdiff_separator(&s, fsl_strlen(ln), @@ -819,22 +830,22 @@ /* Show the initial common area */ li += skip; ri += skip; ntotal = c[ci] - skip; for (j = 0; !rc && j < ntotal; j++) { - rc = add_line_type(lines, nlines, LINE_DIFF_CONTEXT); - if (!rc) - rc = sbsdiff_lineno(&s, li + j, SBS_LLINE); + rc = sbsdiff_lineno(&s, li + j, SBS_LLINE); + if (rc) + break; s.idx = s.end = -1; - if (!rc) - rc = sbsdiff_txt(&s, &l[li + j], SBS_LTEXT); + rc = sbsdiff_txt(&s, &l[li + j], SBS_LTEXT); if (!rc) rc = sbsdiff_marker(&s, " ", ""); if (!rc) rc = sbsdiff_lineno(&s, ri + j, SBS_RLINE); if (!rc) rc = sbsdiff_txt(&s, &r[ri + j], SBS_RTEXT); + lines[(*idx)++] = LINE_DIFF_CONTEXT; } if (rc) goto end; li += ntotal; ri += ntotal; @@ -862,11 +873,11 @@ nright); if (!alignment) { rc = FSL_RC_OOM; goto end; } - for (j = 0; !rc && nleft + nright > 0; j++) { + for (j = 0; !rc && nleft + nright > 0; j++, (*idx)++) { char tag[30] = "", sizeof(tag)); s.tag = tag; s.end = LENGTH(&l[li]); + lines[*idx] = LINE_DIFF_MINUS; rc = sbsdiff_txt(&s, &l[li], SBS_LTEXT); - if (!rc) - rc = add_line_type(lines, - nlines, LINE_DIFF_MINUS); if (rc) goto end_align; rc = sbsdiff_marker(&s, " <", "<"); if (rc) goto end_align; @@ -908,14 +917,12 @@ goto end_align; s.idx = 0; fsl_strlcat(tag, "add\">", sizeof(tag)); s.tag = tag; s.end = LENGTH(&r[ri]); + lines[*idx] = LINE_DIFF_PLUS; rc = sbsdiff_txt(&s, &r[ri], SBS_RTEXT); - if (!rc) - rc = add_line_type(lines, - nlines, LINE_DIFF_PLUS); if (rc) goto end_align; assert(nright > 0); nright--; ri++; @@ -942,14 +949,12 @@ s.tag = tag; s.end = LENGTH(&l[li]); rc = sbsdiff_txt(&s, &l[li], SBS_LTEXT); if (rc) goto end_align; + lines[*idx] = LINE_DIFF_EDIT; rc = sbsdiff_marker(&s, " | ", "|"); - if (!rc) - rc = add_line_type(lines, - nlines, LINE_DIFF_EDIT); if (rc) goto end_align; rc = sbsdiff_lineno(&s, ri, SBS_RLINE); if (rc) goto end_align; @@ -971,30 +976,29 @@ fsl_free(alignment); if (rc) goto end; if (i < nc - 1) { ntotal = c[ci + i * 3 + 3]; - for (j = 0; !rc && j < ntotal; j++) { + for (j = 0; !rc && j < ntotal; j++, (*idx)++) { rc = sbsdiff_lineno(&s, li + j, SBS_LLINE); s.idx = s.end = -1; if (rc) goto end; + lines[*idx] = LINE_DIFF_CONTEXT; rc = sbsdiff_txt(&s, &l[li + j], SBS_LTEXT); - if (!rc) - rc = add_line_type(lines, - nlines, LINE_DIFF_CONTEXT); if (rc) goto end; rc = sbsdiff_marker(&s, " ", ""); if (rc) goto end; rc = sbsdiff_lineno(&s, ri + j, SBS_RLINE); if (rc) goto end; + lines[*idx] = LINE_DIFF_CONTEXT; rc = sbsdiff_txt(&s, &r[ri + j], SBS_RTEXT); if (rc) goto end; } @@ -1006,21 +1010,21 @@ /* Show the final common area */ assert(nc == i); ntotal = c[ci + nc * 3]; if (ntotal > context) ntotal = context; - for (j = 0; !rc && j < ntotal; j++) { - rc = add_line_type(lines, nlines, LINE_DIFF_CONTEXT); - if (!rc) - rc = sbsdiff_lineno(&s, li + j, SBS_LLINE); + for (j = 0; !rc && j < ntotal; j++, (*idx)++) { + rc = sbsdiff_lineno(&s, li + j, SBS_LLINE); s.idx = s.end = -1; + lines[*idx] = LINE_DIFF_CONTEXT; if (!rc) rc = sbsdiff_txt(&s, &l[li + j], SBS_LTEXT); if (!rc) rc = sbsdiff_marker(&s, " ", ""); if (!rc) rc = sbsdiff_lineno(&s, ri + j, SBS_RLINE); + lines[*idx] = LINE_DIFF_CONTEXT; if (!rc) rc = sbsdiff_txt(&s, &r[ri + j], SBS_RTEXT); if (rc) goto end; } @@ -1052,24 +1056,22 @@ */ int unidiff(fsl__diff_cx *cx, struct diff_out_state *dst, void *regex, uint16_t context, uint64_t flags) { - fsl_dline *l, *r; /* Left and right side of diff */ - static int chunks = 0; /* Number of chunks so far processed */ - int li, ri; /* Index of next line in l[] and r[] */ - int *c; /* copy/delete/insert triples */ - int ci; /* Index into c[] */ - int nc; /* number of c[] triples to process */ - int max_ci; /* Maximum value for ci */ - int nleft, nright; /* Number of l and r lines to output */ - int ntotal; /* Total number of lines to output */ - int skip; /* Number of lines to skip */ - int i, j, rc = FSL_RC_OK; - uint32_t *nlines = &dst->nlines; - enum line_type **lines = &dst->lines; - bool html, proto, showln, showsep = false; + fsl_dline *l, *r; /* Left and right side of diff */ + static int chunks = 0; /* Number of chunks so far processed */ + int li, ri; /* Index of next line in l[] and r[] */ + int *c; /* copy/delete/insert triples */ + int ci; /* Index into c[] */ + int nc; /* number of c[] triples to process */ + int max_ci; /* Maximum value for ci */ + int nleft, nright; /* Number of l and r lines to output */ + int ntotal; /* Total number of lines to output */ + int skip; /* Number of lines to skip */ + int i, j, rc = FSL_RC_OK; + bool html, proto, showln, showsep = false; proto = FLAG_CHK(flags, FNC_DIFF_PROTOTYPE); showln = FLAG_CHK(flags, FNC_DIFF_LINENO); html = FLAG_CHK(flags, FNC_DIFF_HTML); @@ -1156,16 +1158,12 @@ showsep = 1; /* Don't show a top divider */ else if (html) rc = diff_outf(dst, "%.*c\n", 80, '.'); - else { - rc = add_line_type(lines, nlines, - LINE_DIFF_SEPARATOR); - if (!rc) - rc = diff_outf(dst, "%.95c\n", '.'); - } + else + rc = diff_outf(dst, "%.95c\n", '.'); if (!rc && html) rc = diff_outf(dst, "", chunks); } else { @@ -1187,19 +1185,14 @@ * If the patch changes an empty file or results in * an empty file, the block header must use 0,0 as * position indicator and not 1,0. Otherwise, patch * would be confused and may reject the diff. */ - if (!rc) { - rc = diff_outf(dst, "@@ %s-%d,%d %s+%d,%d%s @@", - ansi1, nleft ? li + skip + 1 : 0, nleft, - ansi2, nright ? ri + skip + 1 : 0, - nright, ansi3); - if (!rc) - rc = add_line_type(lines, nlines, - LINE_DIFF_CHUNK); - } + if (!rc) + rc = diff_outf(dst,"@@ %s-%d,%d %s+%d,%d%s @@", + ansi1, nleft ? li+skip+1 : 0, nleft, ansi2, + nright ? ri+skip+1 : 0, nright, ansi3); if (!rc) { if (html) rc = diff_outf(dst, ""); if (proto && li + skip > 1) { @@ -1218,12 +1211,11 @@ /* Show the initial common area */ li += skip; ri += skip; ntotal = c[ci] - skip; for (j = 0; !rc && j < ntotal; j++) { - rc = add_line_type(lines, nlines, LINE_DIFF_CONTEXT); - if (!rc && showln) + if (showln) rc = unidiff_lineno(dst, li + j + 1, ri + j + 1, html); if (!rc) rc = unidiff_txt(dst, ' ', &l[li + j], html, 0); } @@ -1234,13 +1226,11 @@ /* Show the differences */ for (i = 0; i < nc; i++) { ntotal = c[ci + i * 3 + 1]; for (j = 0; !rc && j < ntotal; j++) { - rc = add_line_type(lines, nlines, - LINE_DIFF_MINUS); - if (!rc && showln) + if (showln) rc = unidiff_lineno(dst, li + j + 1, 0, html); if (!rc) rc = unidiff_txt(dst, '-', &l[li + j], html, regex); @@ -1248,13 +1238,11 @@ if (rc) return rc; li += ntotal; ntotal = c[ci + i * 3 + 2]; for (j = 0; !rc && j < ntotal; j++) { - rc = add_line_type(lines, nlines, - LINE_DIFF_PLUS); - if (!rc && showln) + if (showln) rc = unidiff_lineno(dst, 0, ri + j + 1, html); if (!rc) rc = unidiff_txt(dst, '+', &r[ri + j], html, regex); @@ -1263,13 +1251,11 @@ return rc; ri += ntotal; if (i < nc - 1) { ntotal = c[ci + i * 3 + 3]; for (j = 0; !rc && j < ntotal; j++) { - rc = add_line_type(lines, nlines, - LINE_DIFF_CONTEXT); - if (!rc && showln) + if (showln) rc = unidiff_lineno(dst, li + j + 1, ri + j + 1, html); if (!rc) rc = unidiff_txt(dst, ' ', @@ -1286,12 +1272,11 @@ assert(nc==i); ntotal = c[ci + nc * 3]; if (ntotal > context) ntotal = context; for (j = 0; !rc && j < ntotal; j++) { - rc = add_line_type(lines, nlines, LINE_DIFF_CONTEXT); - if (!rc && showln) + if (showln) rc = unidiff_lineno(dst, li + j + 1, ri + j + 1, html); if (!rc) rc = unidiff_txt(dst, ' ', &l[li + j], html, 0); } @@ -1600,12 +1585,12 @@ * left lines of text on the left * nleft number of lines on the left * right lines of text on the right * nright number of lines on the right */ -unsigned char * -sbsdiff_align(fsl_dline *left, int nleft, fsl_dline *right, int nright) +unsigned char +*sbsdiff_align(fsl_dline *left, int nleft, fsl_dline *right, int nright) { int buf[100]; /* left[] stack if nright not too big */ int *row; /* One row of the Wagner matrix */ int *ptr; /* Space that needs to be freed */ int nmatches; /* Number of matches */ @@ -1749,17 +1734,17 @@ */ int sbsdiff_write_change(struct sbsline *dst, fsl_dline *left, int llnno, fsl_dline *right, int rlnno) { - static const char tag_rm[] = ""; - static const char tag_add[] = ""; - static const char tag_chg[] = ""; - const char *ltxt; /* Text of the left line */ - const char *rtxt; /* Text of the right line */ - enum line_type **lines = &dst->output->lines; - uint32_t *nlines = &dst->output->nlines; + static const char tag_rm[] = ""; + static const char tag_add[] = ""; + static const char tag_chg[] = ""; + const char *ltxt; /* Text of the left line */ + const char *rtxt; /* Text of the right line */ + enum line_type *lines = dst->output->lines; + uint32_t *idx = dst->output->idx; int lcs[4] = {0, 0, 0, 0}; /* Bounds of common middle segment */ int leftsz; /* Length of left line in bytes */ int rightsz; /* Length of right line in bytes */ int shortest; /* Shortest of left and right */ int npfx; /* Length of common prefix */ @@ -1807,18 +1792,16 @@ return rc; dst->idx2 = dst->end2 = 0; dst->idx = dst->end = -1; rc = sbsdiff_txt(dst, left, SBS_LTEXT); if (!rc && leftsz == rightsz && ltxt[leftsz] == rtxt[rightsz]) { - rc = add_line_type(lines, nlines, LINE_DIFF_CONTEXT); - if (!rc) - rc = sbsdiff_marker(dst, " ", ""); + rc = sbsdiff_marker(dst, " ", ""); + lines[*idx] = LINE_DIFF_CONTEXT; } else { - rc = add_line_type(lines, nlines, LINE_DIFF_EDIT); - if (!rc) - rc = sbsdiff_marker(dst, " | ", "|"); + rc = sbsdiff_marker(dst, " | ", "|"); + lines[*idx] = LINE_DIFF_EDIT; } if (!rc) { rc = sbsdiff_lineno(dst, rlnno, SBS_RLINE); if (!rc) { @@ -1831,14 +1814,13 @@ return rc; } /* A single chunk of text deleted from the left */ if (npfx + nsfx == rightsz) { + lines[*idx] = LINE_DIFF_EDIT; /* Text deleted from the left */ rc = sbsdiff_lineno(dst, llnno, SBS_LLINE); - if (!rc) - rc = add_line_type(lines, nlines, LINE_DIFF_EDIT); if (rc) return rc; dst->idx2 = dst->end2 = 0; dst->idx = npfx; dst->end = leftsz - nsfx; @@ -1878,14 +1860,13 @@ dst->tag = tag_chg; dst->idx2 = npfx + lcs[1]; dst->end2 = leftsz - nsfx; dst->tag2 = lcs[3] == nright ? tag_rm : tag_chg; sbsdiff_simplify_line(dst, ltxt + npfx); + lines[*idx] = LINE_DIFF_EDIT; rc = sbsdiff_txt(dst, left, SBS_LTEXT); if (!rc) - rc = add_line_type(lines, nlines, LINE_DIFF_EDIT); - if (!rc) rc = sbsdiff_marker(dst, " | ", "|"); if (!rc) rc = sbsdiff_lineno(dst, rlnno, SBS_RLINE); if (rc) return rc; @@ -1905,17 +1886,17 @@ } /* If all else fails, show a single big change between left and right */ rc = sbsdiff_lineno(dst, llnno, SBS_LLINE); if (!rc) { + lines[*idx] = LINE_DIFF_EDIT; dst->idx2 = dst->end2 = 0; dst->idx = npfx; dst->end = leftsz - nsfx; dst->tag = tag_chg; rc = sbsdiff_txt(dst, left, SBS_LTEXT); if (!rc) { - rc = add_line_type(lines, nlines, LINE_DIFF_EDIT); rc = sbsdiff_marker(dst, " | ", "|"); if (!rc) { rc = sbsdiff_lineno(dst, rlnno, SBS_RLINE); if (!rc) { dst->end = rightsz - nsfx; @@ -2029,21 +2010,5 @@ rc = diff_out(dst, "\n", 1); } return rc; } - -int -add_line_type(enum line_type **lines, uint32_t *nlines, enum line_type type) -{ - enum line_type *p; - - p = fsl_realloc(*lines, (*nlines + 1) * sizeof(enum line_type)); - if (p == NULL) - return FSL_RC_ERROR; - *lines = p; - - (*lines)[*nlines] = type; - (*nlines)++; - - return FSL_RC_OK; -} Index: src/fnc.1 ================================================================== --- src/fnc.1 +++ src/fnc.1 @@ -24,19 +24,10 @@ .Op Ar command .Op Fl h | -help .Nm .Op Fl h | -help .Op Fl v | -version -.Nm -.Cm stash -.Sm off -.Oo -.Cm get | pop -.Li | -.Fl ChPx -.Sm on -.Oc .Nm .Cm config .Op Fl hu .Op Fl -ls .Op Fl R Ar path @@ -82,11 +73,11 @@ .Op Ar glob .Nm .Op Ar path .Sh DESCRIPTION .Nm -is an interactive interface for +is an interactive read-only browser for .Xr fossil 1 repositories, and supports multiple views to display repository data: .Bl -tag -width Ds .It Timeline view @@ -206,104 +197,10 @@ invocation. .It Fl u , -unset Clear the specified .Ar setting. .El -.Tg stash -.It Cm stash Oo Cm get Ns | Ns Cm pop Ns | Ns Oo Fl C | -no-colour Oc \ -Oo Fl h | -help Oc Oo Fl P | -no-prototype Oc Oo Fl x | -context Ar n Oc Oc -.Dl Pq aliases: Cm snapshot , Cm snap , Cm save , Cm sta -When run with neither the -.Cm get -nor -.Cm pop -subcommands, -.Nm -.Cm stash -will present an interactive view of the local changes on disk and iterate -each hunk in the diff, prompting the user to either stash or keep the current -change in the checkout. Valid answers are as follows: -.Bl -column -offset 2s YXZ description -.Sy b Ta scroll back Ns \(ha -.Sy m Ta show more of the current hunk Ns \(ha -.Sy y Ta yes, stash the current hunk -.Sy n Ta no, do not stash the current hunk -.Sy a Ta yes, stash this hunk and all remaining hunks in the file -.Sy k Ta no, do not stash this hunk nor any remaining hunks in the file -.Sy A Ta yes, stash this hunk and all remaining hunks in the diff -.Sy K Ta no, do not stash this hunk nor any remaining hunks in the diff -.Sy ? Ta display help dialog -.El -.Pp -\(haConditionally available when the current hunk occupies the previous -and/or following page. -.Pp -When all hunks have been selected, -.Nm -will prompt the user to enter a stash message. If not provided, a default -message of -.Qo -fnc stash HASH-PREFIX -.Qc , -where -.Qq HASH-PREFIX -is an abbreviated SHA UUID hash of the current checkout, -will be used. At any time prior to the final hunk being selected -.Po -i.e., before the stash message prompt -.Pc , -the operation can be aborted by opening the help dialog and entering -.Qq Q , -which will discard all selections and leave the checkout state unchanged. -.Pp -Available subcommands for -.Nm -.Cm stash -are as follows: -.Bl -ohang -width Ds -.It Cm get -.Dl Pq aliases: Cm apply -Retrieve the most recent stash entry and apply it to the current checkout. -.It Cm pop -Remove the most recent stash entry and apply it to the current checkout. -.El -.Pp -Options only apply to -.Nm -.Cm stash -.Po -i.e., -neither the -.Cm get -nor -.Cm pop -subcommands -.Pc -and are as follows: -.Bl -tag -width Ds -.It Fl C , -no-colour -Disable coloured output, which is enabled by default on supported terminals. -.It Fl h , -help -Display -.Cm stash -command help and usage information then exit. -.It Fl P , -no-prototype -Disable hunk header display of which function or scope each change is in, -which is enabled by default. The heuristic will produce reliable results for -all C-like languages -.Pq e.g., C/C++, Java, Python, JavaScript, Rust ; -however, Lisps and non-source code -.Pq e.g., Markdown, reStructuredText -will return meaningless results. -.It Fl x , -context Ar n -Set -.Ar n -context lines to be shown in the interactive stash diff display such that -0 \*(Le n \*(Le 64. By default, 5 context lines are shown. -Illegal values are a no-op. -.El -.Pp .Tg log .It Cm timeline Oo Fl C | -no-colour Oc Oo Fl T | -tag Ar tag Oc \ Oo Fl b | -branch Ar branch Oc Oo Fl c | -commit Ar commit Oc \ Oo Fl f | -filter Ar glob Oc Oo Fl h | -help Oc Oo Fl n | -limit Ar n Oc \ Oo Fl R | -repo Ar path Oc Oo Fl t | -type Ar type Oc \ @@ -457,21 +354,10 @@ .Bl -tag -width Ds .It Cm Arrow-down, j, >, \&. Move selection cursor down the timeline. .It Cm Arrow-up, k, <, \&, Move selection cursor up the timeline. -.It Cm Arrow-right, l -Scroll the view two columns to the right in the buffer. The comment field -moves left on the screen. -.It Cm Arrow-left, h -Scroll the view two columns to the left in the buffer. The comment field -moves right on the screen. -.It Cm $ -Scroll the view right to the end of the longest comment summary line on the -page. -.It Cm 0 -Scroll the view left to the beginning of the line. .It Cm C-f, Page-down Scroll timeline view one page downwards in the buffer. .It Cm C-b, Page-up Scroll timeline view one page upwards in the buffer. .It Cm C-d @@ -1414,28 +1300,13 @@ .El .Pp To clear environment variables, issue .Cm unset Ar ENVIRONMENT_VARIABLE in the shell. -.Pp -.Nm -displays best with UTF-8, and will detect whether UTF-8 is enabled to determine -which characters to draw in certain views. If UTF-8 is supported by your -terminal but is currently disabled, it can be enabled with -.Qq export LC_ALL=en_US.UTF-8 ; -If not available, -.Nm -will revert to ASCII. Relatedly, some fonts may render certain characters -poorly in the help screen; -.Li Monospace Regular , -.Li JetBrains Mono , -and -.Li Menlo -are known to render all characters well. .Sh EXIT STATUS .Ex -std fnc .Sh SEE ALSO .Xr fossil 1 , .Xr re_format 7 .Xr sqlite3 1 .Sh AUTHOR .An Mark Jamsek Aq Mt mark@jamsek.com Index: src/fnc.c ================================================================== --- src/fnc.c +++ src/fnc.c @@ -19,13 +19,10 @@ * _POSIX_C_SOURCE >= 199309L needed for sigaction() & sigemptyset() on Linux, * but glibc docs claim _XOPEN_SOURCE >= 700 has the same effect, plus we need * _XOPEN_SOURCE >= 500 for ncurses wchar APIs on linux. */ #ifdef __linux__ -# ifndef _BSD_SOURCE -# define _BSD_SOURCE /* mkstemps(3) on glibc <= 2.19 */ -# endif /* _BSD_SOURCE */ # ifndef _XOPEN_SOURCE # define _XOPEN_SOURCE 700 # endif /* _XOPEN_SOURCE */ # ifndef _DEFAULT_SOURCE # define _DEFAULT_SOURCE /* strsep() on glibc >= 2.19. */ @@ -35,10 +32,11 @@ # define HAVE_LANDLOCK # include # include # include # include +# include # include # endif /* LANDLOCK_H */ # endif /* __has_include */ #endif /* __linux__ */ @@ -47,20 +45,17 @@ #endif #include #include #include -#include -#include #ifdef _WIN32 #include #define ssleep(x) Sleep(x) #else #define ssleep(x) usleep((x) * 1000) #endif -#include #include #include #include #include #include @@ -93,21 +88,21 @@ #define MAX(_a, _b) ((_a) > (_b) ? (_a) : (_b)) #define ABS(_n) ((_n) >= 0 ? (_n) : -(_n)) #ifndef CTRL #define CTRL(key) ((key) & 037) /* CTRL+ input. */ #endif -#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) -#define ndigits(_d, _n) do { _d++; } while (_n /= 10) -#define STRINGIFYOUT(_s) #_s -#define STRINGIFY(_s) STRINGIFYOUT(_s) -#define CONCATOUT(_a, _b) _a ## _b -#define CONCAT(_a, _b) CONCATOUT(_a, _b) -#define FILE_POSITION __FILE__ ":" STRINGIFY(__LINE__) -#define FLAG_SET(_f, _b) ((_f) |= (_b)) -#define FLAG_CHK(_f, _b) ((_f) & (_b)) -#define FLAG_TOG(_f, _b) ((_f) ^= (_b)) -#define FLAG_CLR(_f, _b) ((_f) &= ~(_b)) +#define nitems(a) (sizeof((a)) / sizeof((a)[0])) +#define ndigits(_d, _n) do { _d++; } while (_n /= 10) +#define STRINGIFYOUT(s) #s +#define STRINGIFY(s) STRINGIFYOUT(s) +#define CONCATOUT(a, b) a ## b +#define CONCAT(a, b) CONCATOUT(a, b) +#define FILE_POSITION __FILE__ ":" STRINGIFY(__LINE__) +#define FLAG_SET(f, b) ((f) |= (b)) +#define FLAG_CHK(f, b) ((f) & (b)) +#define FLAG_TOG(f, b) ((f) ^= (b)) +#define FLAG_CLR(f, b) ((f) &= ~(b)) /* Application macros. */ #define PRINT_VERSION STRINGIFY(FNC_VERSION) #define DEF_DIFF_CTX 5 /* Default diff context lines. */ #define MAX_DIFF_CTX 64 /* Max diff context lines. */ @@ -117,18 +112,15 @@ #define MAX_PCT_LEN 7 /* Line position upto max len 99.99% */ #define SPINNER "\\|/-\0" #define NULL_DEVICE "/dev/null" #define NULL_DEVICELEN (sizeof(NULL_DEVICE) - 1) #define KEY_ESCAPE 27 -#define RC_RESET(_rc) do { fcli_err_reset(); _rc = FSL_RC_OK; } while (0) #if DEBUG -#define RC_DEBUG(_r, _fmt, ...) fcli_err_set(_r, "%s::%s " _fmt, \ - __func__, FILE_POSITION, __VA_ARGS__) -#define RC(_r, ...) RC_DEBUG(_r, __VA_ARGS__, "") +#define RC(r, fmt, ...) fcli_err_set(r, "%s::%s " fmt, \ + __func__, FILE_POSITION, __VA_ARGS__) #else -#define RC_REL(_r, _fmt, ...) fcli_err_set(_r, _fmt, __VA_ARGS__) -#define RC(_r, ...) RC_REL(_r, __VA_ARGS__, "") +#define RC(r, fmt, ...) fcli_err_set(r, fmt, __VA_ARGS__) #endif /* DEBUG */ /* fossil(1) db-related paths. */ #define REPODB fsl_cx_db_file_repo(fcli_cx(), NULL) #define REPODIR getdirname(REPODB, -1, false) @@ -142,11 +134,10 @@ # endif /* HAVE_STRTONUM */ #else # define inrange(n, min, max) true #endif /* OpenBSD */ -#define PRINTFV(fmt, args) __attribute__((format (printf, fmt, args))) #ifndef __dead #define __dead __attribute__((noreturn)) #endif #ifndef TAILQ_FOREACH_SAFE @@ -154,16 +145,10 @@ #define TAILQ_FOREACH_SAFE(var, head, field, tmp) \ for ((var) = ((head)->tqh_first); \ (var) != (NULL) && ((tmp) = TAILQ_NEXT(var, field), 1); \ (var) = (tmp)) #endif -#ifndef STAILQ_FOREACH_SAFE -#define STAILQ_FOREACH_SAFE(var, head, field, tmp) \ - for ((var) = ((head)->stqh_first); \ - (var) && ((tmp) = STAILQ_NEXT(var, field), 1); \ - (var) = (tmp)) -#endif /* * STAILQ was added to OpenBSD 6.9; fallback to SIMPLEQ for prior versions. * XXX This is an ugly hack; replace with a better solution. */ @@ -181,26 +166,23 @@ # define strlcpy(_d, _s, _sz) fsl_strlcpy(_d, _s, _sz) # endif /* strlcpy */ #endif /* __linux__ */ __dead static void usage(void); -static void help_stash(const fcli_command *); static void usage_timeline(void); static void usage_diff(void); static void usage_tree(void); static void usage_blame(void); static void usage_branch(void); static void usage_config(void); -static void usage_stash(void); static int fcli_flag_type_arg_cb(fcli_cliflag const *); static int cmd_timeline(fcli_command const *); static int cmd_diff(fcli_command const *); static int cmd_tree(fcli_command const *); static int cmd_blame(fcli_command const *); static int cmd_branch(fcli_command const *); static int cmd_config(fcli_command const *); -static int cmd_stash(fcli_command const *); /* * Singleton initialising global configuration and state for app startup. */ static struct fnc_setup { @@ -259,18 +241,17 @@ bool unset; /* Unset the specified setting. */ /* Command line flags and help. */ fcli_help_info fnc_help; /* Global help. */ fcli_cliflag cliflags_global[3]; /* Global options. */ - fcli_command cmd_args[8]; /* App commands. */ + fcli_command cmd_args[7]; /* App commands. */ fcli_cliflag cliflags_timeline[13]; /* Timeline options. */ fcli_cliflag cliflags_diff[12]; /* Diff options. */ fcli_cliflag cliflags_tree[5]; /* Tree options. */ fcli_cliflag cliflags_blame[8]; /* Blame options. */ fcli_cliflag cliflags_branch[11]; /* Branch options. */ fcli_cliflag cliflags_config[5]; /* Config options. */ - fcli_cliflag cliflags_stash[5]; /* Stash options. */ } fnc_init = { NULL, /* cmdarg copy of argv[1] to aid usage/error report. */ NULL, /* sym(bolic name) of commit to open defaults to tip. */ NULL, /* path for tree to open or timeline to find commits. */ 0, /* err fnc error state. */ @@ -292,11 +273,11 @@ false, /* eol defaults to acknowledge eol whitespace. */ false, /* nocolour defaults to off (i.e., use diff colours). */ true, /* verbose defaults to on. */ false, /* invert diff defaults to off. */ false, /* showln in diff defaults to off. */ - true, /* proto in diff hunk header defaults to on. */ + true, /* proto in diff chunk header defaults to on. */ NULL, /* before defaults to any time. */ NULL, /* after defaults to any time. */ NULL, /* sort by MRU or open/closed (dflt: lexicographical) */ false, /* closed only branches is off (defaults to all). */ false, /* open only branches is off by (defaults to all). */ @@ -334,14 +315,10 @@ "Show navigable list of repository branches.", cmd_branch, usage_branch, fnc_init.cliflags_branch}, {"config", "conf\0cfg\0settings\0set\0", "Configure or view currently available settings.", cmd_config, usage_config, fnc_init.cliflags_config}, - {"stash", "snapshot\0snap\0save\0sta\0", - "Interactively select hunks to stash from the diff of local " - "changes on\n disk.", - cmd_stash, usage_stash, fnc_init.cliflags_stash}, {NULL, NULL, NULL, NULL, NULL} /* Sentinel. */ }, { /* cliflags_timeline timeline command related options. */ FCLI_FLAG("b", "branch", "", &fnc_init.filter_branch, @@ -404,11 +381,11 @@ "toggled\n with the 'i' key binding in diff view."), FCLI_FLAG_BOOL("l", "line-numbers", &fnc_init.showln, "Show file line numbers in diff output. Line numbers can also be " "toggled\n with the 'L' key binding in diff view."), FCLI_FLAG_BOOL_INVERT("P", "no-prototype", &fnc_init.proto, - "Disable display of the enclosing function prototype in diff hunk " + "Disable display of the enclosing function prototype in diff chunk" "headers."), FCLI_FLAG_BOOL_INVERT("q", "quiet", &fnc_init.verbose, "Disable verbose diff output; that is, do not output complete" " content\n of newly added or deleted files. Verbosity can also" " be toggled with\n the 'v' key binding in diff view."), @@ -543,24 +520,10 @@ FCLI_FLAG_BOOL("u", "unset", &fnc_init.unset, "Unset (i.e., remove) the specified repository setting."), fcli_cliflag_empty_m }, /* End cliflags_tree. */ - { /* cliflags_stash stash command related options. */ - FCLI_FLAG_BOOL("C", "no-colour", &fnc_init.nocolour, - "Disable coloured diff output, which is enabled by default on\n " - "supported terminals."), - FCLI_FLAG_BOOL("h", "help", NULL, - "Display stash command help and usage."), - FCLI_FLAG_BOOL_INVERT("P", "no-prototype", &fnc_init.proto, - "Disable display of the enclosing function prototype in diff hunk " - "headers."), - FCLI_FLAG("x", "context", "", &fnc_init.context, - "Show context lines when displaying diff; is capped at 64." - "\n Negative values are a no-op."), - fcli_cliflag_empty_m - }, /* End cliflags_stash. */ }; enum date_string { ISO8601_DATE_ONLY = 10, ISO8601_DATE_HHMM = 16, @@ -595,49 +558,20 @@ FNC_DIFF_COMMIT, FNC_DIFF_BLOB, FNC_DIFF_WIKI }; -enum fnc_diff_mode { - DIFF_PLAIN, - COMMIT_META, - STASH_INTERACTIVE -}; - -enum fnc_diff_hunk { - HUNK_NONE, - HUNK_STASH, - HUNK_CKOUT -}; - -enum fnc_patch_rc { - PATCH_OK, - PATCH_MALFORMED, - PATCH_TRUNCATED, - NO_PATCH, - HUNK_FAILED, - PATCH_FAILED, -}; - -enum stash_opt { - NO_CHOICE, - KEEP_FILE, /* keep remaining hunks in file in ckout */ - KEEP_DIFF, /* keep remaining hunks in diff in ckout */ - STASH_FILE, /* stash the rest of the hunks in the file */ - STASH_DIFF /* stash the rest of the hunks in the diff */ -}; - struct input { void *data; char *prompt; enum input_type type; int flags; #define SR_CLREOL 1 << 0 #define SR_UPDATE 1 << 1 #define SR_SLEEP 1 << 2 #define SR_RESET 1 << 3 -#define SR_ALL (SR_CLREOL | SR_UPDATE | SR_SLEEP | SR_RESET) +#define SR_ALL SR_CLREOL | SR_UPDATE | SR_SLEEP | SR_RESET char buf[BUFSIZ]; long ret; }; struct fnc_colour { @@ -784,11 +718,10 @@ const char *curr_ckout_uuid; const char *glob; /* Match commits containing glob. */ char *path; /* Match commits involving path. */ int selected; int nscrolled; - uint16_t maxx; sig_atomic_t quit; pthread_t thread_id; bool colour; bool showmeta; }; @@ -806,70 +739,14 @@ off_t *offset; uint32_t n; uint32_t idx; }; -/* - * A stash context is comprised of two patch contexts: a (1) patch of all hunks - * selected to stash; and a (2) patch of all hunks kept in the checkout. Each - * patch has a queue of fnc_patch_file(s), one for each versioned file with - * hunks to be stashed or kept. Each fnc_patch_file has a queue of hunks with - * an array of all context, plus, and minus lines comprising the hunk. Each - * patch context produces a patch(1) file that gets applied to the base ckout. - */ -struct fnc_patch_hunk { - STAILQ_ENTRY(fnc_patch_hunk) entries; - char **lines; /* plus, minus, context lines */ - long offset; /* line offset into this hunk */ - size_t nlines; /* number of *lines */ - size_t cap; /* capacity of **lines */ - int_least32_t oldfrom; /* start line in "from" file */ - int_least32_t oldlines; /* number of lines from "oldfrom" */ - int_least32_t newfrom; /* start line in "new" file */ - int_least32_t newlines; /* number of lines from "newfrom" */ - bool nonl; /* line continuation flag */ - enum fnc_patch_rc rc; -}; - -STAILQ_HEAD(fnc_patch_hunk_head, fnc_patch_hunk); -struct fnc_patch_file { - STAILQ_ENTRY(fnc_patch_file) entries; - char old[PATH_MAX]; - char new[PATH_MAX]; - struct fnc_patch_hunk_head head; -}; - -typedef int (*fnc_patch_report_cb)(struct fnc_patch_file *, const char *, - const char *, char *); -STAILQ_HEAD(fnc_patch_file_head, fnc_patch_file); -struct patch_cx { - fnc_patch_report_cb report_cb; - struct fnc_patch_file *pf; /* current fnc_patch_file */ - struct fnc_patch_file_head head; /* queue of fnc_patch_file(s) */ - uint8_t context; /* MAX_DIFF_CTX lines = 64 */ - enum fnc_patch_rc rc; - bool report; -}; - -struct stash_cx { - struct patch_cx pcx; - struct index hunk; /* line indexes for each hunk in the diff */ - char patch[2][PATH_MAX]; /* stash & ckout patch filepath */ - unsigned char *stash; /* bit array into this.hunk->lineno */ -#define NBITS (sizeof(unsigned char) * 8) -#define nbytes(nbits) (((nbits) + 7) >> 3) -#define BIT_SET(_B, _i) (_B[(_i / NBITS)] |= (1 << (_i % NBITS))) -#define BIT_CLR(_B, _i) (_B[(_i / NBITS)] &= ~(1 << (_i % NBITS))) -#define BIT_CHK(_B, _i) (_B[(_i / NBITS)] & (1 << (_i % NBITS))) -}; - struct fnc_diff_view_state { - struct fnc_view *view; struct fnc_view *parent_view; struct fnc_commit_artifact *selected_entry; struct fnc_pathlist_head *paths; - struct stash_cx scx; fsl_buffer buf; struct fnc_colours colours; struct index index; FILE *f; fsl_uuid_str id1; @@ -887,15 +764,14 @@ uint32_t ndlines; size_t ncols; size_t nlines; enum line_type *dlines; enum line_attr sline; - enum fnc_diff_hunk stash; - enum fnc_diff_mode diff_mode; off_t *line_offsets; bool eof; bool colour; + bool showmeta; bool showln; bool patch; }; TAILQ_HEAD(fnc_parent_trees, fnc_parent_tree); @@ -1106,24 +982,22 @@ static void parse_emailaddr_username(char **); static int formatln(wchar_t **, int *, const char *, size_t, int, bool); static size_t expand_tab(char **, const char *, int); static int multibyte_to_wchar(const char *, wchar_t **, size_t *); -static int replace_unicode(char **, const char *); static int write_commit_line(struct fnc_view *, struct fnc_commit_artifact *, int); static int view_input(struct fnc_view **, int *, struct fnc_view *, struct view_tailhead *); static int cycle_view(struct fnc_view *); static int toggle_fullscreen(struct fnc_view **, struct fnc_view *); -static int stash_help(struct fnc_view *, int8_t); static int help(struct fnc_view *); -static int padpopup(struct fnc_view *, const char *[][2], - const char **, const char *, int8_t); -static int centerprint(WINDOW *, size_t, size_t, size_t, - const char *, chtype); +static int padpopup(struct fnc_view *, int, int, FILE *, + const char *); +static void centerprint(WINDOW *, int, int, int, const char *, + chtype); static int tl_input_handler(struct fnc_view **, struct fnc_view *, int); static int move_tl_cursor_down(struct fnc_view *, uint16_t); static void move_tl_cursor_up(struct fnc_view *, uint16_t, bool); static int timeline_scroll_down(struct fnc_view *, int); @@ -1146,33 +1020,34 @@ static int tl_search_next(struct fnc_view *); static bool find_commit_match(struct fnc_commit_artifact *, regex_t *); static int init_diff_view(struct fnc_view **, int, int, struct fnc_commit_artifact *, struct fnc_view *, - enum fnc_diff_mode); + bool); static int open_diff_view(struct fnc_view *, struct fnc_commit_artifact *, struct fnc_pathlist_head *, - struct fnc_view *, enum fnc_diff_mode); + struct fnc_view *, bool); static void set_diff_opt(struct fnc_diff_view_state *); static void show_diff_status(struct fnc_view *); static int create_diff(struct fnc_diff_view_state *); static int create_changeset(struct fnc_commit_artifact *); -static int make_stash_diff(struct fnc_diff_view_state *, char *); static int write_commit_meta(struct fnc_diff_view_state *); -/* static int countlines(const char *); */ +static int countlines(const char *); static int wrapline(char *, fsl_size_t, struct fnc_diff_view_state *, off_t *); static int add_line_offset(off_t **, size_t *, off_t); +static int add_line_type(enum line_type **, enum line_type, + uint32_t *, uint32_t, bool); static int diff_commit(struct fnc_diff_view_state *); static int diff_checkout(struct fnc_diff_view_state *); static int write_diff_meta(struct fnc_diff_view_state *, const char *, fsl_uuid_str, const char *, fsl_uuid_str, enum fsl_ckout_change_e); static int diff_file(struct fnc_diff_view_state *, fsl_buffer *, - const char *, const char *, fsl_uuid_str, - const char *, enum fsl_ckout_change_e); + const char *, fsl_uuid_str, const char *, + enum fsl_ckout_change_e); static int diff_non_checkin(struct fnc_diff_view_state *); static int diff_file_artifact(struct fnc_diff_view_state *, fsl_id_t, const fsl_card_F *, const fsl_card_F *, fsl_ckout_change_e); static int show_diff(struct fnc_view *); @@ -1184,67 +1059,10 @@ static void drawborder(struct fnc_view *); static int diff_input_handler(struct fnc_view **, struct fnc_view *, int); static int request_tl_commits(struct fnc_view *); static int reset_diff_view(struct fnc_view *, bool); -static int stash_get_rm_cb(fsl_ckout_unmanage_state const *); -static int stash_get_add_cb(fsl_ckout_manage_state const *, - bool *); -static int f__add_files_in_sfile(int *, int); -static int f__stash_get(bool); -static int fnc_stash(struct fnc_view *); -static int select_hunks(struct fnc_view *); -static int stash_input_handler(struct fnc_view *, bool *); -static void set_choice(struct fnc_diff_view_state *, bool *, - struct input *, struct index *, uint32_t *, - size_t *, size_t *, bool *, enum stash_opt *); -static unsigned char *alloc_bitstring(size_t); -static int generate_prompt(char ***, char *, size_t, short); -static void free_answers(char **); -static bool valid_input(const char *, char **); -static int revert_ckout(bool, bool); -static int rm_vfile_renames_cb(fsl_stmt *, void *); -static int fnc_patch(struct patch_cx *, const char *); -static int scan_patch(struct patch_cx *, FILE *); -static int find_patch_file(struct fnc_patch_file **, - struct patch_cx *, FILE *); -static int parse_filename(const char *, char **, int); -static int set_patch_paths(struct fnc_patch_file *, const char *, - const char *); -static int parse_hunk(struct fnc_patch_hunk **, FILE *, uint8_t, - bool *); -static int parse_hdr(char *, bool *, struct fnc_patch_hunk *); -static int strtolnum(char **, int_least32_t *); -static int pushline(struct fnc_patch_hunk *, const char *); -static int alloc_hunk_line(struct fnc_patch_hunk *, const char *); -static int peek_special_line(struct fnc_patch_hunk *, FILE *, int); -static int apply_patch(struct patch_cx *, struct fnc_patch_file *, - bool); -static int fnc_open_tmpfile(char **, FILE **, const char *, - const char *); -static int patch_file(struct fnc_patch_file *, const char *, - FILE *, int, mode_t *); -static int apply_hunk(FILE *, struct fnc_patch_hunk *, long *); -static int locate_hunk(FILE *, struct fnc_patch_hunk *, off_t *, - long *); -static int copyfile(FILE *, FILE *, off_t, off_t); -static int test_hunk(FILE *, struct fnc_patch_hunk *); -static int fnc_add_vfile(struct patch_cx *, const char *, bool); -static int fnc_addvfile_cb(const fsl_ckout_manage_state *, bool *); -static int fnc_rm_vfile(struct patch_cx *, const char *, bool); -static int fnc_rmvfile_cb(const fsl_ckout_unmanage_state *); -static int fnc_rename_vfile(const char *, const char *); -static int patch_reporter(struct fnc_patch_file *, - const char *, const char *, char *); -static int patch_report(const char *, const char *, - char *, long, long, long, long, long, - enum fnc_patch_rc); -static void free_patch(struct fnc_patch_file *); -static int f__stash_path(int, int, const char *); -static int f__check_stash_tables(void); -static int f__stash_create(const char *, int); -/* static int fnc_execp(const char *const *, const int); */ static int set_selected_commit(struct fnc_diff_view_state *, struct commit_entry *); static void diff_grep_init(struct fnc_view *); static int find_next_match(struct fnc_view *); static void grep_set_view(struct fnc_view *, FILE **, off_t **, @@ -1352,11 +1170,11 @@ static int close_tree_view(struct fnc_view *); static int close_timeline_view(struct fnc_view *); static int close_diff_view(struct fnc_view *); static void free_index(struct index *); static void free_tags(struct fnc_tl_view_state *, bool); -static int view_resize(struct fnc_view *, bool); +static int view_resize(struct fnc_view *, enum view_mode); static bool screen_is_split(struct fnc_view *); static bool screen_is_shared(struct fnc_view *); static void updatescreen(WINDOW *, bool, bool); static void fnc_resizeterm(void); static int join_tl_thread(struct fnc_tl_view_state *); @@ -1371,21 +1189,22 @@ static int strtonumcheck(long *, const char *, const int, const int); static int fnc_prompt_input(struct fnc_view *, struct input *); static int fnc_date_to_mtime(double *, const char *, int); static int cook_input(char *, int, WINDOW *); -static int PRINTFV(3, 4) sitrep(struct fnc_view *, int, const char *, ...); +static int sitrep(struct fnc_view *, const char *, int); static char *fnc_strsep (char **, const char *); static bool fnc_str_has_upper(const char *); static int fnc_make_sql_glob(char **, char **, const char *, bool); -static const char *gettzfile(void); #ifndef HAVE_LANDLOCK -static int init_unveil(const char **, const char **, int, bool); +static int init_unveil(const char *, const char *, bool); #else static int init_landlock(const char **, const int); -#define init_unveil(_p, _m, _n, _d) init_landlock(_p, _n) +static const char *gettzfile(void); +#define init_unveil(_r, _c, _s) \ + init_landlock((const char*[]){_r, _c, P_tmpdir, gettzfile()}, 4) #endif /* HAVE_LANDLOCK */ static const char *getdirname(const char *, fsl_int_t, bool); static int set_colours(struct fnc_colours *, enum fnc_view_id); static int set_colour_scheme(struct fnc_colours *, const int (*)[2], const char **, int); @@ -1409,20 +1228,11 @@ int main(int argc, const char **argv) { fcli_command *cmd = NULL; char *path = NULL; - int rc = FSL_RC_OK; - - /* - * XXX Guard against misuse. Will have to take another approach once - * the test harness is finished as we pipe input for our tests cases. - */ - if (!isatty(fileno(stdin))) { - rc = RC(FSL_RC_MISUSE, "invalid input device"); - goto end; - } + int rc = 0; if (!setlocale(LC_CTYPE, "")) fsl_fprintf(stderr, "[!] Warning: Can't set locale.\n"); fnc_init.cmdarg = argv[1]; /* Which cmd to show usage if needed. */ @@ -1435,79 +1245,82 @@ goto end; if (fnc_init.vflag) { fnc_show_version(); goto end; - } else if (fnc_init.hflag) { - rc = FCLI_RC_HELP; - goto end; - } + } else if (fnc_init.hflag) + usage(); + /* NOT REACHED */ + #ifdef __OpenBSD__ /* * See pledge(2). This is the most restrictive set we can operate under. * Look for any adverse impact & revise when implementing new features. * stdio (close, sigaction); rpath (chdir getcwd lstat); wpath (getcwd); * cpath (symlink); flock (open); tty (TIOCGWINSZ); unveil (unveil). - * XXX 'fnc stash' needs more perms, call pledge(2) from cmd_stash(). */ - if (!(!fsl_strcmp(fnc_init.cmdarg, "stash") || - fcli_cmd_aliascmp(&fnc_init.cmd_args[6], fnc_init.cmdarg)) && - pledge("stdio rpath wpath cpath flock tty unveil", NULL) == -1) { - rc = RC(fsl_errno_to_rc(errno, FSL_RC_ACCESS), "pledge"); + if (pledge("stdio rpath wpath cpath flock tty unveil", NULL) == -1) { + rc = RC(fsl_errno_to_rc(errno, FSL_RC_ACCESS), "%s", "pledge"); goto end; } #endif rc = fcli_fingerprint_check(true); + if (rc) + goto end; + if (argc == 1) cmd = &fnc_init.cmd_args[FNC_VIEW_TIMELINE]; - else if (!rc) { + else { rc = fcli_dispatch_commands(fnc_init.cmd_args, false); if (rc == FSL_RC_NOT_FOUND && argc == 2) { /* * Check if user entered fnc path/in/repo; if valid path * is found, assume fnc timeline path/in/repo was meant. */ rc = map_repo_path(&path); - if (rc == FSL_RC_UNKNOWN_RESOURCE || !path) { - rc = RC(FSL_RC_NOT_FOUND, + if (rc == FSL_RC_NOT_FOUND || !path) { + rc = RC(rc, "'%s' is not a valid command or path", argv[1]); - } else if (!rc) { - cmd = &fnc_init.cmd_args[FNC_VIEW_TIMELINE]; - fnc_init.path = path; - fcli_err_reset(); /* for fcli_process_flags */ - } - } - } - if (rc) - goto end; + fnc_init.err = rc; + usage(); + /* NOT REACHED */ + } else if (rc) + goto end; + cmd = &fnc_init.cmd_args[FNC_VIEW_TIMELINE]; + fnc_init.path = path; + fcli_err_reset(); /* cmd_timeline::fcli_process_flags */ + } else if (rc) + goto end; + } + + if ((rc = fcli_has_unused_args(false))) { + fnc_init.err = rc; + usage(); + /* NOT REACHED */ + } if (!fsl_cx_db_repo(fcli_cx())) { - rc = RC(FSL_RC_MISUSE, "repository database required"); + rc = RC(FSL_RC_MISUSE, "%s", "repository database required"); goto end; } if (cmd != NULL) rc = cmd->f(cmd); end: fsl_free(path); - !isendwin() ? endwin() : 0; /* may have been called in cmd_stash() */ + endwin(); if (rc) { - if (rc == FSL_RC_BREAK) { + if (rc == FCLI_RC_HELP) + rc = 0; + else if (rc == FSL_RC_BREAK) { const fsl_cx *const f = fcli_cx(); const char *errstr; fsl_error_get(&f->error, &errstr, NULL); fsl_fprintf(stdout, "%s", errstr); - RC_RESET(rc); /* for fcli_end_of_main() */ - } else if (rc == FSL_RC_UNKNOWN_RESOURCE) { - /* file not found by map_repo_path() */ - fcli_err_set(FSL_RC_NOT_FOUND, "%s", - fsl_buffer_cstr(&fcli_error()->msg)); - } else { - fnc_init.err = rc == FCLI_RC_HELP ? FSL_RC_OK : rc; - usage(); - /* NOT REACHED */ + fcli_err_reset(); /* For fcli_end_of_main() */ + rc = 0; } } putchar('\n'); return fcli_end_of_main(rc); } @@ -1549,12 +1362,11 @@ } rc = init_curses(); if (rc) goto end; - rc = init_unveil(((const char *[]){REPODB, CKOUTDIR, P_tmpdir, - gettzfile()}), ((const char *[]){"rw", "rwc", "rwc", "r"}), 4, true); + rc = init_unveil(REPODB, CKOUTDIR, false); if (rc) goto end; rc = init_timeline_view(&v, 0, 0, rid, path, glob); if (!rc) @@ -1571,11 +1383,11 @@ { int rc = FSL_RC_OK; *view = view_open(0, 0, y, x, FNC_VIEW_TIMELINE); if (view == NULL) - rc = RC(FSL_RC_ERROR, "view_open"); + rc = RC(FSL_RC_ERROR, "%s", "view_open"); if (!rc) rc = open_timeline_view(*view, rid, path, glob); return rc; } @@ -1601,17 +1413,17 @@ /* If no path argument is supplied, default to repository root. */ if (!fcli_next_arg(false)) { *requested_path = fsl_strdup("/"); if (*requested_path == NULL) - return RC(FSL_RC_ERROR, "fsl_strdup"); + return RC(FSL_RC_ERROR, "%s", "fsl_strdup"); return rc; } canonpath = fsl_strdup(fcli_next_arg(true)); if (canonpath == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_strdup"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_strdup"); goto end; } /* * If no checkout (e.g., 'fnc timeline -R') copy the path verbatim to @@ -1626,26 +1438,29 @@ path = realpath(canonpath, NULL); if (path == NULL && (errno == ENOENT || errno == ENOTDIR)) { /* Path is not on disk, assume it is relative to repo root. */ rc = fsl_file_canonical_name2(ckoutdir0, canonpath, &buf, NULL); if (rc) { - rc = RC(rc, "fsl_file_canonical_name2"); + rc = RC(rc, "%s", "fsl_file_canonical_name2"); goto end; } fsl_free(path); path = realpath(fsl_buffer_cstr(&buf), NULL); if (path) { /* Confirmed path is relative to repository root. */ fsl_free(path); path = fsl_strdup(canonpath); if (path == NULL) - rc = RC(FSL_RC_ERROR, "fsl_strdup"); - } else - rc = RC(FSL_RC_UNKNOWN_RESOURCE, + rc = RC(FSL_RC_ERROR, "%s", "fsl_strdup"); + } else { + rc = RC(fsl_errno_to_rc(errno, FSL_RC_NOT_FOUND), "'%s' not found in tree", canonpath); + *requested_path = fsl_strdup(canonpath); + } goto end; } + fsl_free(path); /* * Use the cwd as the virtual root to canonicalise the supplied path if * it is either: (a) relative; or (b) the root of the current checkout. * Otherwise, use the root of the current checkout. */ @@ -1657,18 +1472,17 @@ fsl_buffer_reuse(&buf); rc = fsl_ckout_filename_check(f, (canonpath[0] == '.' || !root) ? true : false, canonpath, &buf); if (rc) goto end; - fsl_free(path); fsl_free(canonpath); canonpath = fsl_strdup(fsl_buffer_str(&buf)); if (canonpath[0] == '\0') { path = fsl_strdup(canonpath); if (path == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_strdup"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_strdup"); goto end; } } else { fsl_buffer_reuse(&buf); rc = fsl_file_canonical_name2(f->ckout.dir, canonpath, &buf, @@ -1675,11 +1489,11 @@ false); if (rc) goto end; path = fsl_strdup(fsl_buffer_str(&buf)); if (path == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_strdup"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_strdup"); goto end; } if (access(path, F_OK) != 0) { rc = RC(fsl_errno_to_rc(errno, FSL_RC_ACCESS), "path does not exist or inaccessible [%s]", path); @@ -1692,11 +1506,11 @@ len = fsl_strlen(path); if (!fsl_strcmp(path, f->ckout.dir)) { fsl_free(path); path = fsl_strdup(""); if (path == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_strdup"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_strdup"); goto end; } } else if (len > f->ckout.dirLen && path_is_child(path, f->ckout.dir, f->ckout.dirLen)) { char *child; @@ -1724,29 +1538,29 @@ /* Trim trailing slash if it exists. */ if (path[fsl_strlen(path) - 1] == '/') path[fsl_strlen(path) - 1] = '\0'; end: - if (rc) { - *requested_path = fsl_strdup(canonpath); + fsl_buffer_clear(&buf); + fsl_free(canonpath); + fsl_free(ckoutdir); + if (rc) fsl_free(path); - } else { + else { /* Make path absolute from repository root. */ if (path[0] != '/' && (path[0] != '.' && path[1] != '/')) { char *abspath; if ((abspath = fsl_mprintf("/%s", path)) == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_mprintf"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_mprintf"); + goto end; } fsl_free(path); path = abspath; } *requested_path = path; } - fsl_buffer_clear(&buf); - fsl_free(canonpath); - fsl_free(ckoutdir); return rc; } static bool path_is_child(const char *child, const char *parent, size_t parentlen) @@ -1796,13 +1610,13 @@ while (abspath[parentlen] == '/') ++abspath; bufsz = len - parentlen + 1; *child = fsl_malloc(bufsz); if (*child == NULL) - return RC(FSL_RC_ERROR, "fsl_malloc"); + return RC(FSL_RC_ERROR, "%s", "fsl_malloc"); if (strlcpy(*child, abspath + parentlen, bufsz) >= bufsz) { - rc = RC(FSL_RC_RANGE, "strlcpy"); + rc = RC(FSL_RC_RANGE, "%s", "strlcpy"); fsl_free(*child); *child = NULL; } return rc; } @@ -1843,19 +1657,19 @@ fnc_set_signals(void) { if (sigaction(SIGPIPE, &(struct sigaction){{sigpipe_handler}}, NULL) == -1) return RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), - "sigaction(SIGPIPE)"); + "%s", "sigaction(SIGPIPE)"); if (sigaction(SIGWINCH, &(struct sigaction){{sigwinch_handler}}, NULL) == -1) return RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), - "sigaction(SIGWINCH)"); + "%s", "sigaction(SIGWINCH)"); if (sigaction(SIGCONT, &(struct sigaction){{sigcont_handler}}, NULL) == -1) return RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), - "sigaction(SIGCONT)"); + "%s", "sigaction(SIGCONT)"); return FSL_RC_OK; } static struct fnc_view * @@ -1904,11 +1718,11 @@ if (path != s->path) { fsl_free(s->path); s->path = fsl_strdup(path); if (s->path == NULL) - return RC(FSL_RC_ERROR, "fsl_strdup"); + return RC(FSL_RC_ERROR, "%s", "fsl_strdup"); } /* * TODO: See about opening this API. * If a path has been supplied, create a table of all path's @@ -1915,11 +1729,11 @@ * ancestors and add "AND blob.rid IN fsl_computed_ancestors" to query. */ /* if (path[1]) { */ /* rc = fsl_compute_ancestors(db, rid, 0, 0); */ /* if (rc) */ - /* return RC(FSL_RC_DB, "fsl_compute_ancestors"); */ + /* return RC(FSL_RC_DB, "%s", "fsl_compute_ancestors"); */ /* } */ s->thread_cx.q = NULL; /* s->selected = 0; */ /* Unnecessary? */ TAILQ_INIT(&s->commits.head); @@ -1964,15 +1778,17 @@ return RC(FSL_RC_NOT_FOUND, "'%s' invalid path in [%s]", path + 1, fnc_init.sym ? fnc_init.sym : "tip"); } if ((rc = pthread_cond_init(&s->thread_cx.commit_consumer, NULL))) { - RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), "pthread_cond_init"); + RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), + "%s", "pthread_cond_init"); goto end; } if ((rc = pthread_cond_init(&s->thread_cx.commit_producer, NULL))) { - RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), "pthread_cond_init"); + RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), + "%s", "pthread_cond_init"); goto end; } fsl_buffer_appendf(&sql, "SELECT " /* 0 */"uuid, " @@ -2120,23 +1936,23 @@ view->grep = tl_search_next; s->thread_cx.q = fsl_stmt_malloc(); rc = fsl_db_prepare(db, s->thread_cx.q, "%b", &sql); if (rc) { - rc = RC(rc, "fsl_db_prepare"); + rc = RC(rc, "%s", "fsl_db_prepare"); goto end; } rc = fsl_stmt_step(s->thread_cx.q); switch (rc) { case FSL_RC_STEP_ROW: rc = 0; break; case FSL_RC_STEP_ERROR: - rc = RC(rc, "fsl_stmt_step"); + rc = RC(rc, "%s", "fsl_stmt_step"); goto end; case FSL_RC_STEP_DONE: - rc = RC(FSL_RC_BREAK, "no matching records"); + rc = RC(FSL_RC_BREAK, "%s", "no matching records"); goto end; } s->colour = !fnc_init.nocolour && has_colors(); s->showmeta = true; @@ -2181,11 +1997,11 @@ struct fnc_view *new_view; int done = 0, err = 0, rc = 0; if ((rc = pthread_mutex_lock(&fnc_mutex))) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_mutex_lock"); + "%s", "pthread_mutex_lock"); TAILQ_INIT(&views); TAILQ_INSERT_HEAD(&views, view, entries); view->active = true; @@ -2208,11 +2024,11 @@ if (view->parent) { view->parent->child = NULL; view->parent->focus_child = false; /* Restore fullscreen line height. */ view->parent->nlines = view->parent->lines; - rc = view_resize(view->parent, false); + rc = view_resize(view->parent, VIEW_SPLIT_NONE); if (rc) goto end; } else TAILQ_REMOVE(&views, view, entries); @@ -2291,11 +2107,11 @@ view_close(view); } if ((err = pthread_mutex_unlock(&fnc_mutex)) && !rc) rc = RC(fsl_errno_to_rc(err, FSL_RC_ACCESS), - "pthread_mutex_unlock"); + "%s", "pthread_mutex_unlock"); return rc; } static int @@ -2307,11 +2123,11 @@ if (!s->thread_id) { rc = pthread_create(&s->thread_id, NULL, tl_producer_thread, &s->thread_cx); if (rc) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_create"); + "%s", "pthread_create"); if (s->thread_cx.ncommits_needed > 0) { rc = signal_tl_thread(view, 1); if (rc) return rc; } @@ -2349,11 +2165,11 @@ break; } if ((rc = pthread_mutex_lock(&fnc_mutex))) { rc = RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_mutex_lock"); + "%s", "pthread_mutex_lock"); break; } else if (*cx->first_commit_onscreen == NULL) { *cx->first_commit_onscreen = TAILQ_FIRST(&cx->commits->head); *cx->selected_entry = *cx->first_commit_onscreen; @@ -2360,11 +2176,11 @@ } else if (*cx->quit) done = true; if ((rc = pthread_cond_signal(&cx->commit_producer))) { rc = RC(fsl_errno_to_rc(rc, FSL_RC_MISUSE), - "pthread_cond_signal"); + "%s", "pthread_cond_signal"); pthread_mutex_unlock(&fnc_mutex); break; } if (done) @@ -2371,18 +2187,18 @@ cx->ncommits_needed = 0; else if (cx->ncommits_needed == 0) { if ((rc = pthread_cond_wait(&cx->commit_consumer, &fnc_mutex))) rc = RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_cond_wait"); + "%s", "pthread_cond_wait"); if (*cx->quit) done = true; } if ((rc = pthread_mutex_unlock(&fnc_mutex))) rc = RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_mutex_unlock"); + "%s", "pthread_mutex_unlock"); } cx->eotl = true; return (void *)(intptr_t)rc; } @@ -2391,24 +2207,28 @@ block_main_thread_signals(void) { sigset_t set; if (sigemptyset(&set) == -1) - return RC(fsl_errno_to_rc(errno, FSL_RC_MISUSE), "sigemptyset"); + return RC(fsl_errno_to_rc(errno, FSL_RC_MISUSE), "%s", + "sigemptyset"); /* Bespoke signal handlers for SIGWINCH and SIGCONT. */ if (sigaddset(&set, SIGWINCH) == -1) - return RC(fsl_errno_to_rc(errno, FSL_RC_MISUSE), "sigaddset"); + return RC(fsl_errno_to_rc(errno, FSL_RC_MISUSE), "%s", + "sigaddset"); if (sigaddset(&set, SIGCONT) == -1) - return RC(fsl_errno_to_rc(errno, FSL_RC_MISUSE), "sigaddset"); + return RC(fsl_errno_to_rc(errno, FSL_RC_MISUSE), "%s", + "sigaddset"); /* ncurses handles SIGTSTP. */ if (sigaddset(&set, SIGTSTP) == -1) - return RC(fsl_errno_to_rc(errno, FSL_RC_MISUSE), "sigaddset"); + return RC(fsl_errno_to_rc(errno, FSL_RC_MISUSE), "%s", + "sigaddset"); if (pthread_sigmask(SIG_BLOCK, &set, NULL)) - return RC(fsl_errno_to_rc(errno, FSL_RC_MISUSE), + return RC(fsl_errno_to_rc(errno, FSL_RC_MISUSE), "%s", "pthread_sigmask"); return FSL_RC_OK; } @@ -2426,14 +2246,14 @@ */ fsl_size_t loaded = cx->commits->ncommits + 1; cx->reset = false; rc = fsl_stmt_reset(cx->q); if (rc) - return RC(rc, "fsl_stmt_reset"); + return RC(rc, "%s", "fsl_stmt_reset"); while (loaded--) if ((rc = fsl_stmt_step(cx->q)) != FSL_RC_STEP_ROW) - return RC(rc, "fsl_stmt_step"); + return RC(rc, "%s", "fsl_stmt_step"); } /* * Step through the given SQL query, passing each row to the commit * builder to build commits for the timeline. */ @@ -2441,11 +2261,11 @@ struct fnc_commit_artifact *commit = NULL; struct commit_entry *dup_entry, *entry; rc = commit_builder(&commit, 0, cx->q); if (rc) - return RC(rc, "commit_builder"); + return RC(rc, "%s", "commit_builder"); /* * TODO: Find out why, without this, fnc reads and displays * the first (i.e., latest) commit twice. This hack checks to * see if the current row returned a UUID matching the last * commit added to the list to avoid adding a duplicate entry. @@ -2458,32 +2278,33 @@ continue; } entry = fsl_malloc(sizeof(*entry)); if (entry == NULL) - return RC(FSL_RC_ERROR, "fsl_malloc"); + return RC(FSL_RC_ERROR, "%s", "fsl_malloc"); entry->commit = commit; rc = pthread_mutex_lock(&fnc_mutex); if (rc) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_mutex_lock"); + "%s", "pthread_mutex_lock"); entry->idx = cx->commits->ncommits; TAILQ_INSERT_TAIL(&cx->commits->head, entry, entries); cx->commits->ncommits++; if (!cx->endjmp && *cx->searching == SEARCH_FORWARD && - *cx->search_status == SEARCH_WAITING) + *cx->search_status == SEARCH_WAITING) { if (find_commit_match(commit, cx->regex)) *cx->search_status = SEARCH_CONTINUE; + } rc = pthread_mutex_unlock(&fnc_mutex); if (rc) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_mutex_unlock"); + "%s", "pthread_mutex_unlock"); } while ((rc = fsl_stmt_step(cx->q)) == FSL_RC_STEP_ROW && *cx->searching == SEARCH_FORWARD && *cx->search_status == SEARCH_WAITING); @@ -2519,11 +2340,11 @@ "AND tagxref.tagtype > 0) as tags, " /*6*/"coalesce(ecomment, comment) AS comment " "FROM event JOIN blob WHERE blob.rid=%d AND event.objid=%d", fnc_init.utc ? "" : ", 'localtime'", rid, rid); if (rc) - return RC(FSL_RC_DB, "fsl_db_prepare"); + return RC(FSL_RC_DB, "%s", "fsl_db_prepare"); fsl_stmt_step(q); } type = fsl_stmt_g_text(q, 4, NULL); comment = fsl_stmt_g_text(q, 6, NULL); @@ -2571,22 +2392,22 @@ break; }; if (!rc && comment) rc = fsl_buffer_append(&buf, comment, -1); if (rc) { - rc = RC(rc, "fsl_buffer_append"); + rc = RC(rc, "%s", "fsl_buffer_append"); goto end; } commit = calloc(1, sizeof(*commit)); if (commit == NULL) { - rc = RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), "calloc"); + rc = RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), "%s", "calloc"); goto end; } if (!rid && (rc = fsl_stmt_get_id(q, 3, &rid))) { - rc = RC(rc, "fsl_stmt_get_id"); + rc = RC(rc, "%s", "fsl_stmt_get_id"); goto end; } /* Is there a more efficient way to get the parent? */ commit->puuid = fsl_db_g_text(db, NULL, "SELECT uuid FROM plink, blob WHERE plink.cid=%d " @@ -2622,11 +2443,11 @@ /* Wake timeline thread. */ rc = pthread_cond_signal(&cx->commit_consumer); if (rc) return RC(fsl_errno_to_rc(rc, FSL_RC_MISUSE), - "pthread_cond_signal"); + "%s", "pthread_cond_signal"); /* * Mutex will be released while view_loop().view_input() waits * in wgetch(), at which point the timeline thread will run. */ @@ -2640,11 +2461,11 @@ /* Wait while the next commit is being loaded. */ rc = pthread_cond_wait(&cx->commit_producer, &fnc_mutex); if (rc) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_cond_wait"); + "%s", "pthread_cond_wait"); /* Show status update in timeline view. */ show_timeline_view(view); update_panels(); doupdate(); @@ -2680,11 +2501,11 @@ if ((idxstr = fsl_mprintf(" [%d/%d] %s", entry ? entry->idx + 1 : 0, s->commits.ncommits, (view->searching && !view->search_status) ? "searching..." : view->search_status == SEARCH_ABORTED ? "aborted" : "loading...")) == NULL) { - rc = RC(FSL_RC_RANGE, "fsl_mprintf"); + rc = RC(FSL_RC_RANGE, "%s", "fsl_mprintf"); goto end; } } else { if (view->searching) { switch (view->search_status) { @@ -2705,11 +2526,11 @@ if ((idxstr = fsl_mprintf("%s [%d/%d] %s", !fsl_strcmp(uuid, s->curr_ckout_uuid) ? " [current]" : "", entry ? entry->idx + 1 : 0, s->commits.ncommits, search_str ? search_str : (branch ? branch : ""))) == NULL) { - rc = RC(FSL_RC_RANGE, "fsl_mprintf"); + rc = RC(FSL_RC_RANGE, "%s", "fsl_mprintf"); goto end; } } /* * Compute cols needed to fit all components of the headline to truncate @@ -2727,20 +2548,20 @@ type ? ' ' : SPINNER[tcx->spin_idx], view->ncols < ncols_needed ? view->ncols - (ncols_needed - FSL_STRLEN_K256) : FSL_STRLEN_K256, uuid ? uuid : "........................................", s->path, idxstr)) == NULL) { - rc = RC(FSL_RC_RANGE, "fsl_mprintf"); + rc = RC(FSL_RC_RANGE, "%s", "fsl_mprintf"); headln = NULL; goto end; } } else if ((headln = fsl_mprintf("%s%c%.*s%s", type ? type : "", type ? ' ' : SPINNER[tcx->spin_idx], view->ncols < ncols_needed ? view->ncols - (ncols_needed - FSL_STRLEN_K256) : FSL_STRLEN_K256, uuid ? uuid : "........................................", idxstr)) == NULL) { - rc = RC(FSL_RC_RANGE, "fsl_mprintf"); + rc = RC(FSL_RC_RANGE, "%s", "fsl_mprintf"); headln = NULL; goto end; } if (SPINNER[++tcx->spin_idx] == '\0') tcx->spin_idx = 0; @@ -2765,36 +2586,28 @@ wattroff(view->window, rx); fsl_free(wline); if (view->nlines <= 1) goto end; - /* - * Parse commits to be written on screen for the longest username, - * and the longest log message summary line (i.e., up to first '\n') - */ + /* Parse commits to be written on screen for the longest username. */ entry = s->first_commit_onscreen; - s->maxx = 0; /* length of longest summary commit message */ while (entry) { wchar_t *wstr; - char *end, *msg, *user; + char *user; int wusrlen; if (ncommits >= view->nlines - 1) break; user = fsl_strdup(entry->commit->user); if (user == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_strdup"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_strdup"); goto end; } if (strpbrk(user, "<@>") != NULL) parse_emailaddr_username(&user); rc = formatln(&wstr, &wusrlen, user, view->ncols, 0, false); - maxlen = MAX(maxlen, wusrlen); - msg = entry->commit->comment; - if ((end = strchr(msg, '\n'))) - s->maxx = MAX(s->maxx, end - msg); - else - s->maxx = MAX(s->maxx, fsl_strlen(msg)); + if (maxlen < wusrlen) + maxlen = wusrlen; fsl_free(wstr); fsl_free(user); ++ncommits; entry = TAILQ_NEXT(entry, entries); } @@ -2892,18 +2705,18 @@ if (wline[i] == L'\t') { width = TABSIZE - ((cols + start_column) % TABSIZE); } else { width = 1; - wline[i] = L'?'; + wline[i] = L'.'; } if (cols + width > column_limit) break; cols += width; i++; } else { - rc = RC(FSL_RC_RANGE, "wcwidth"); + rc = RC(FSL_RC_RANGE, "%s", "wcwidth"); goto end; } } wline[i] = L'\0'; if (wstrlen) @@ -2952,93 +2765,46 @@ } static int multibyte_to_wchar(const char *src, wchar_t **dst, size_t *dstlen) { - char *rep = NULL; - int rc = FSL_RC_OK; + int rc = 0; /* * mbstowcs POSIX extension specifies that the number of wchar that * would be written are returned when first arg is a null pointer: * https://en.cppreference.com/w/cpp/string/multibyte/mbstowcs */ *dstlen = mbstowcs(NULL, src, 0); if (*dstlen == (size_t)-1) { - if (errno != EILSEQ) - return RC(FSL_RC_MISUSE, "mbstowcs(%s)", src); - - if (replace_unicode(&rep, src)) - return rc; - - *dstlen = mbstowcs(NULL, rep, 0); - if (*dstlen == (size_t)-1) { - rc = RC(FSL_RC_RANGE, + if (errno == EILSEQ) + return RC(FSL_RC_RANGE, "invalid multibyte character [%s]", src); - goto end; - } + return RC(FSL_RC_MISUSE, "mbstowcs(%s)", src); } *dst = NULL; - *dst = fsl_malloc((*dstlen + 1) * sizeof(**dst)); + *dst = fsl_malloc(sizeof(wchar_t) * (*dstlen + 1)); if (*dst == NULL) { - rc = RC(FSL_RC_ERROR, "malloc"); + rc = RC(FSL_RC_ERROR, "%s", "malloc"); goto end; } - if (mbstowcs(*dst, rep ? rep : src, *dstlen) != *dstlen) + if (mbstowcs(*dst, src, *dstlen) != *dstlen) rc = RC(FSL_RC_SIZE_MISMATCH, "mbstowcs(%s)", src); end: - fsl_free(rep); if (rc) { fsl_free(*dst); *dst = NULL; *dstlen = 0; } return rc; } -/* - * Iterate mbs, writing each char to *ptr, and replace any non-printable or - * unicode characters that are invalid in the environment's current character - * encoding with a '?'. *ptr must eventually be disposed of by the caller. - */ -static int -replace_unicode(char **ptr, const char *mbs) -{ - const char *src; - char *dst; - wchar_t wc; - int width, len; - - len = fsl_strlen(mbs); - *ptr = fsl_malloc(len + 1); /* NUL */ - if (*ptr == NULL) - return RC(FSL_RC_ERROR, "fsl_malloc"); - - src = mbs; - dst = *ptr; - - while (*src) { - if ((len = mbtowc(&wc, src, MB_CUR_MAX)) == -1) { /* invalid */ - *dst++ = '?'; - ++src; - } else if (*src != '\r' && *src != '\n' && - (width = wcwidth(wc)) == -1) { /* not printable */ - *dst++ = '?'; - src += len; - } else /* valid */ - while (len-- > 0) - *dst++ = *src++; - } - *dst = '\0'; - return FSL_RC_OK; -} - /* * When the terminal is >= 110 columns wide, the commit summary line in the * timeline view will take the form: * * DATE UUID USERNAME COMMIT-COMMENT @@ -3057,11 +2823,11 @@ struct fnc_tl_view_state *s = &view->state.timeline; struct fnc_colour *c = NULL; wchar_t *wstr = NULL; char *comment0 = NULL, *comment = NULL; char *date = NULL; - char *eol = NULL, *user = NULL; + char *eol = NULL, *pad = NULL, *user = NULL; size_t i = 0; int col, limit, wlen; int rc = FSL_RC_OK; /* Trim time component from timestamp for the date field. */ @@ -3101,68 +2867,63 @@ user = fsl_strdup(commit->user); if (user == NULL) goto end; if (strpbrk(user, "<@>") != NULL) parse_emailaddr_username(&user); - rc = formatln(&wstr, &wlen, user, view->ncols - col, col, false); + rc = formatln(&wstr, &wlen, user, view->ncols - col, + col, false); if (rc) goto end; if (s->colour) c = get_colour(&s->colours, FNC_COLOUR_USER); if (c) wattr_on(view->window, COLOR_PAIR(c->scheme), NULL); waddwstr(view->window, wstr); - col += wlen; - while (col < view->ncols && wlen < maxlen + 2) { - waddch(view->window, ' '); - ++col; - ++wlen; - } + fsl_free(wstr); + pad = fsl_mprintf("%*c", maxlen - wlen + 2, ' '); + waddstr(view->window, pad); if (c) wattr_off(view->window, COLOR_PAIR(c->scheme), NULL); + col += (maxlen + 2); if (col > view->ncols) goto end; /* Only show comment up to the first newline character. */ comment0 = fsl_strdup(commit->comment); comment = comment0; - if (comment == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_strdup"); - goto end; - } + if (comment == NULL) + return RC(FSL_RC_ERROR, "%s", "fsl_strdup"); while (*comment == '\n') ++comment; eol = strchr(comment, '\n'); if (eol) *eol = '\0'; - limit = view->pos.col + view->ncols - col; - if (view->pos.col < (etcount(comment, fsl_strlen(comment)) - 1)) { - fsl_free(wstr); - rc = formatln(&wstr, &wlen, comment, limit, col, true); - if (rc) - goto end; - waddwstr(view->window, wstr + view->pos.col); - } - col += MAX(wlen - view->pos.col, 0); + limit = view->ncols - col; + rc = formatln(&wstr, &wlen, comment, limit, col, false); + if (rc) + goto end; + waddwstr(view->window, wstr); + col += wlen; while (col < view->ncols) { waddch(view->window, ' '); ++col; } end: fsl_free(date); fsl_free(user); fsl_free(wstr); + fsl_free(pad); fsl_free(comment0); return rc; } static int view_input(struct fnc_view **new, int *done, struct fnc_view *view, struct view_tailhead *views) { struct fnc_view *v; - int ch = 0, rc = 0; + int ch, rc = 0; *new = NULL; /* Clear search indicator string. */ if (view->search_status == SEARCH_COMPLETE || @@ -3170,52 +2931,42 @@ view->search_status = SEARCH_CONTINUE; if (view->searching && view->search_status == SEARCH_WAITING) { if ((rc = pthread_mutex_unlock(&fnc_mutex))) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_mutex_unlock"); + "%s", "pthread_mutex_unlock"); sched_yield(); if ((rc = pthread_mutex_lock(&fnc_mutex))) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_mutex_lock"); + "%s", "pthread_mutex_lock"); rc = view->grep(view); return rc; } nodelay(stdscr, FALSE); /* Allow thread to make progress while waiting for input. */ if ((rc = pthread_mutex_unlock(&fnc_mutex))) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_mutex_unlock"); - /* - * XXX This check is not yet needed, but is pre-empting the NYI feature - * of calling fnc_stash from the diff_input_handler() with a key map. - */ - if (view->state.diff.diff_mode != STASH_INTERACTIVE) - ch = wgetch(view->window); + "%s", "pthread_mutex_unlock"); + ch = wgetch(view->window); if ((rc = pthread_mutex_lock(&fnc_mutex))) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_mutex_lock"); + "%s", "pthread_mutex_lock"); if (rec_sigwinch || rec_sigcont) { fnc_resizeterm(); rec_sigwinch = 0; rec_sigcont = 0; TAILQ_FOREACH(v, views, entries) { - rc = view_resize(v, v->child && - screen_is_split(v->child)); - updatescreen(v->window, true, true); + rc = view_resize(v, v->mode); if (rc) return rc; rc = v->input(new, v, KEY_RESIZE); if (rc) return rc; if (v->child) { - rc = view_resize(v->child, v->child->active && - screen_is_shared(v->child)); - drawborder(v->child); - updatescreen(v->child->window, true, true); + rc = view_resize(v->child, v->child->mode); if (rc) return rc; rc = v->child->input(new, v->child, KEY_RESIZE); if (rc) return rc; @@ -3229,10 +2980,14 @@ break; case KEY_F(1): case 'H': case '?': rc = help(view); + if (rc == FSL_RC_BREAK) { + rc = FSL_RC_OK; + *done = 1; + } break; case 'q': if (view->parent && view->parent->vid == FNC_VIEW_TIMELINE && view->mode == VIEW_SPLIT_HRZN) { /* May need more commits to fill fullscreen. */ @@ -3274,14 +3029,10 @@ default: rc = view->input(new, view, ch); break; } - if (rc == FSL_RC_BREAK) { - rc = FSL_RC_OK; - *done = 1; - } return rc; } static int cycle_view(struct fnc_view *view) @@ -3344,64 +3095,14 @@ } return rc; } -static int -stash_help(struct fnc_view *view, int8_t scroll) -{ - char *title = NULL; - static const char *keys[][2] = { - {""}, - {""}, - {" b ", " ❬b❭ "}, - {" m ", " ❬m❭ "}, - {" y ", " ❬y❭ "}, - {" n ", " ❬n❭ "}, - {" a ", " ❬a❭ "}, - {" k ", " ❬k❭ "}, - {" A ", " ❬A❭ "}, - {" K ", " ❬K❭ "}, - {" ? ", " ❬?❭ "}, - {" q ", " ❬q❭ "}, - {" Q ", " ❬Q❭ "}, - {""}, - {""}, - {0} - }; - static const char *desc[] = { - "", - "Stash", - "- scroll back to the previous page^", - "- show more of this hunk on the next page^", - "- stash this hunk", - "- do not stash this hunk", - "- stash this hunk and all remaining hunks in the file", - "- do not stash this hunk nor any remaining hunks in the file", - "- stash this hunk and all remaining hunks in the diff", - "- do not stash this hunk nor any remaining hunks in the diff", - "- display this help screen", - "- exit this help screen", - "- exit help and quit fnc stash aborting any selections", - "", - "^conditionally available when hunks occupy multiple pages" - }; - int rc = FSL_RC_OK; - - title = fsl_mprintf("%s %s Help\n", fcli_progname(), PRINT_VERSION); - if (title == NULL) - return RC(FSL_RC_ERROR, "fsl_mprintf"); - - rc = padpopup(view, keys, desc, title, scroll); - - fsl_free(title); - return rc; -} - static int help(struct fnc_view *view) { + FILE *help = NULL; char *title = NULL; static const char *keys[][2] = { {""}, {""}, /* Global */ {" H,?,F1 ", " ❬H❭❬?❭❬F1❭ "}, @@ -3499,16 +3200,14 @@ "Scroll view down one page", "Scroll view up one half page", "Scroll view down one half page", "Jump to first line or start of the view", "Jump to last line or end of the view", - "Scroll the view right (timeline, diff, blame, help)", - "Scroll the view left (timeline, diff, blame, help)", - "Scroll right to the end of the longest line " - "(timeline, diff, blame, help)", - "Scroll left to the beginning of the line " - "(timeline, diff, blame, help)", + "Scroll the view right (diff, blame, help)", + "Scroll the view left (diff, blame, help)", + "Scroll right to the end of the longest line (diff, blame, help)", + "Scroll left to the beginning of the line (diff, blame, help)", "Switch focus between open views", "Toggle coloured output", "Toggle fullscreen", "Open prompt to enter search term (not available in this view)", "Find next line or token matching the current search term", @@ -3538,11 +3237,11 @@ "Open and populate branch view with all repository branches", "Open prompt to enter file number and navigate to file", "Toggle inversion of diff output", "Toggle display of file line numbers", "Prompt for path to write a patch of the currently viewed diff", - "Toggle display of function name in hunk header", + "Toggle display of function name in chunk header", "Display side-by-side formatted diff", "Toggle verbosity of diff output", "Toggle ignore end-of-line whitespace-only changes in diff", "Toggle ignore whitespace-only changes in diff", "Decrease the number of context lines", @@ -3577,17 +3276,40 @@ "Open a tree view of the currently selected branch", "Reload view with all repository branches and no filters applied", "", " See fnc(1) for complete list of options and key bindings." }; - int rc = FSL_RC_OK; + int cs, ln, width = 0, rc = 0; + + cs = (strcmp(nl_langinfo(CODESET), "UTF-8") == 0) ? 1 : 0; title = fsl_mprintf("%s %s Help\n", fcli_progname(), PRINT_VERSION); if (title == NULL) - return RC(FSL_RC_ERROR, "fsl_mprintf"); + return RC(FSL_RC_ERROR, "%s", "fsl_mprintf"); - rc = padpopup(view, keys, desc, title, -1); + help = tmpfile(); + if (help == NULL) + return RC(FSL_RC_IO, "%s", "tmpfile"); + + /* + * Format help text, and compute longest line and total number of + * lines in text to be displayed to determine pad dimensions. + */ + width = fsl_strlen(title); + for (ln = 0; keys[ln][0]; ++ln) { + if (keys[ln][1]) { + width = MAX((fsl_size_t)width, + fsl_strlen(keys[ln][cs]) + fsl_strlen(desc[ln])); + } + fsl_fprintf(help, "%s%s%c", keys[ln][cs], desc[ln], + keys[ln + 1] ? '\n' : 0); + } + rewind(help); + + rc = padpopup(view, width, ln, help, title); + if (fclose(help) == EOF) + rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), "%s", "fclose"); fsl_free(title); return rc; } @@ -3595,71 +3317,42 @@ * Create popup pad in which to write the supplied txt string and optional * title. The pad is contained within a window that is offset four columns in * and two lines down from the parent window. */ static int -padpopup(struct fnc_view *view, const char *keys[][2], const char **desc, - const char *title, int8_t stash) +padpopup(struct fnc_view *view, int width, int height, FILE *txt, + const char *title) { WINDOW *win, *content; - FILE *txt; char *line = NULL; ssize_t linelen; size_t linesz; - int ch, cury, curx, end, ln, width, wy, wx, x0, y0; - int cs, rc = FSL_RC_OK; - - txt = tmpfile(); - if (txt == NULL) - return RC(FSL_RC_IO, "tmpfile"); - - cs = (fsl_strcmp(nl_langinfo(CODESET), "UTF-8") == 0) ? 1 : 0; - - /* - * Format help text, and compute longest line and total number of - * lines in text to be displayed to determine pad dimensions. - */ - width = fsl_strlen(title); - for (ln = 0; keys[ln][0]; ++ln) { - if ((!stash && (ln == 2 || ln == 3)) || (stash < 1 && ln == 14) - || (stash == 1 && ln == 2) || (stash == 2 && ln == 3)) - continue; /* only show available stash keymaps */ - if (keys[ln][1]) { - width = MAX((fsl_size_t)width, - fsl_strlen(keys[ln][cs]) + fsl_strlen(desc[ln])); - } - fsl_fprintf(txt, "%s%s%c", keys[ln][cs], desc[ln], - keys[ln + 1] ? '\n' : 0); - } - ++width; - rewind(txt); - - x0 = 4; /* column number at which to start the help window */ - y0 = 2; /* line number at which to start the help window */ + int ch, cury, curx, end, wy, wx, x0, y0, rc = FSL_RC_OK; + + x0 = 4; /* Number of columns to border window. */ + y0 = 2; /* Number of lines to border window. */ cury = curx = 0; - wx = getmaxx(view->window) - ((x0 + 1) * 2); /* window width */ - wy = MIN(ln + 3, getmaxy(view->window) - ((y0 + 1) * 2)); /* height */ + wx = getmaxx(view->window) - ((x0 + 1) * 2); /* Width of window. */ + wy = getmaxy(view->window) - ((y0 + 1) * 2); /* Height of window */ ch = ERR; if ((win = newwin(wy, wx, y0, x0)) == 0) - return RC(FSL_RC_ERROR, "newwin"); - if ((content = newpad(ln + 1, width + 1)) == 0) { + return RC(FSL_RC_ERROR, "%s", "newwin"); + if ((content = newpad(height + 1, width + 1)) == 0) { delwin(win); - return RC(FSL_RC_ERROR, "newpad"); + return RC(FSL_RC_ERROR, "%s", "newpad"); } doupdate(); keypad(content, TRUE); /* Write text content to pad. */ if (title) - rc = centerprint(content, 0, 0, MIN(wx, width), title, 0); - while (!rc && (linelen = getline(&line, &linesz, txt)) != -1) - rc = waddstr(content, line); + centerprint(content, 0, 0, wx, title, 0); + while ((linelen = getline(&line, &linesz, txt)) != -1) + waddstr(content, line); fsl_free(line); - if (rc) - return rc; end = (getcury(content) - (wy - 3)); /* No. lines past end of pad. */ do { switch (ch) { case KEY_UP: @@ -3728,13 +3421,10 @@ pnoutrefresh(content, cury, curx, y0 + 1, x0 + 1, wy, wx); doupdate(); } while (!rc && (ch = wgetch(content)) != 'q' && ch != KEY_ESCAPE && ch != ERR); - if (fclose(txt) == EOF) - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), "fclose"); - /* Destroy window. */ werase(win); wrefresh(win); delwin(win); delwin(content); @@ -3745,30 +3435,30 @@ doupdate(); return rc; } -static int -centerprint(WINDOW *win, size_t starty, size_t startx, size_t width, - const char *str, chtype colour) +static void +centerprint(WINDOW *win, int starty, int startx, int cols, const char *str, + chtype colour) { - size_t len, x, y; + int x, y; if (win == NULL) win = stdscr; - len = fsl_strlen(str); - y = MAX(starty, 0); /* start line */ - x = startx ? startx : width > len ? (width - len) / 2 : 0; /* column */ + getyx(win, y, x); + x = startx ? startx : x; + y = starty ? starty : y; + if (!cols) + cols = getmaxx(win); + x = startx + (cols - fsl_strlen(str)) / 2; wattron(win, colour ? colour : A_UNDERLINE); - if (mvwprintw(win, y, x, "%s", str) == ERR) - return RC(FSL_RC_RANGE, "mvwprintw"); + mvwprintw(win, y, x, "%s", str); wattroff(win, colour ? colour : A_UNDERLINE); refresh(); - - return FSL_RC_OK; } static int tl_input_handler(struct fnc_view **new_view, struct fnc_view *view, int ch) { @@ -3777,25 +3467,10 @@ uint16_t nscroll = view->nlines - 2; free_tags(s, true); switch (ch) { - case '0': - view->pos.col = 0; - break; - case '$': - view->pos.col = MAX(s->maxx - view->ncols / 2, 0); - break; - case KEY_RIGHT: - case 'l': - if (view->pos.col + view->ncols / 2 < s->maxx) - view->pos.col += 2; - break; - case KEY_LEFT: - case 'h': - view->pos.col -= MIN(view->pos.col, 2); - break; case KEY_DOWN: case 'j': case '.': case '>': rc = move_tl_cursor_down(view, 0); @@ -3836,11 +3511,10 @@ case KEY_RESIZE: if (s->selected > view->nlines - 2) s->selected = view->nlines - 2; if (s->selected > s->commits.ncommits - 1) s->selected = s->commits.ncommits - 1; - s->selected = MAX(s->selected, 0); select_commit(s); if (s->commits.ncommits < view->nlines - 1 && !s->thread_cx.eotl) { s->thread_cx.ncommits_needed += (view->nlines - 1) - s->commits.ncommits; @@ -3847,12 +3521,12 @@ rc = signal_tl_thread(view, 1); } break; case 'C': { if (s->selected_entry->commit->type[0] != 'c') { - rc = sitrep(view, SR_ALL, - "-- requires check-in artifact --"); + rc = sitrep(view, "-- requires check-in artifact --", + SR_ALL); break; } fsl_cx *const f = fcli_cx(); /* * XXX This is not good but I can't think of an alternative @@ -3860,17 +3534,17 @@ * db lock error via fsl_vfile_changes_scan() when versioned * files are modified in-session. Clear it and notify user. */ rc = fsl_ckout_changes_scan(f); if (rc == FSL_RC_DB) { - rc = sitrep(view, SR_ALL, "-- checkout db busy --"); + rc = sitrep(view, "-- checkout db busy --", SR_ALL); break; } else if (rc) - return RC(rc, "fsl_ckout_changes_scan"); + return RC(rc, "%s", "fsl_ckout_changes_scan"); if (!fsl_ckout_has_changes(f)) { - sitrep(view, SR_CLREOL | SR_UPDATE | SR_SLEEP, - "-- no local changes --"); + sitrep(view, "-- no local changes --", + SR_CLREOL | SR_UPDATE | SR_SLEEP); break; } s->selected_entry->commit->diff_type = FNC_DIFF_CKOUT; } /* FALL THROUGH */ case ' ': @@ -3893,21 +3567,22 @@ if (rc) return rc; s->glob = input.buf; rc = request_view(new_view, view, FNC_VIEW_TIMELINE); if (rc == FSL_RC_BREAK) { - rc = sitrep(view, SR_ALL, "-- no matching commits --"); + rc = sitrep(view, "-- no matching commits --", SR_ALL); } break; } case 't': if (s->selected_entry == NULL) break; if (!fsl_rid_is_a_checkin(fcli_cx(), s->selected_entry->commit->rid)) - sitrep(view, SR_CLREOL | SR_UPDATE | SR_SLEEP, - "-- tree requires check-in artifact --"); + sitrep(view, + "-- tree requires check-in artifact --", + SR_CLREOL | SR_UPDATE | SR_SLEEP); else rc = request_view(new_view, view, FNC_VIEW_TREE); break; case 'q': s->quit = 1; @@ -4085,11 +3760,11 @@ case FNC_VIEW_DIFF: { struct fnc_tl_view_state *s = &view->state.timeline; if (s->selected_entry == NULL) break; rc = init_diff_view(new_view, x, y, s->selected_entry->commit, - view, s->showmeta ? COMMIT_META : DIFF_PLAIN); + view, s->showmeta); break; } case FNC_VIEW_BLAME: { struct fnc_tree_view_state *s = &view->state.tree; rc = blame_tree_entry(new_view, x, y, s->selected_entry, @@ -4114,11 +3789,11 @@ break; } case FNC_VIEW_BRANCH: { *new_view = view_open(0, 0, y, x, FNC_VIEW_BRANCH); if (*new_view == NULL) - return RC(FSL_RC_ERROR, "view_open"); + return RC(FSL_RC_ERROR, "%s", "view_open"); rc = open_branch_view(*new_view, BRANCH_LS_OPEN_CLOSED, NULL, 0, 0); /* FALL THROUGH */ } default: @@ -4160,11 +3835,11 @@ { int rc = FSL_RC_OK; view->mode = VIEW_SPLIT_HRZN; view->nlines = *start_ln; - rc = view_resize(view, false); + rc = view_resize(view, VIEW_SPLIT_NONE); if (!rc) { view->nlines = *start_ln - 1; rc = offset_selected_line(view); } @@ -4309,19 +3984,19 @@ view->nlines = LINES - view->start_ln; view->ncols = COLS - view->start_col; view->lines = LINES; view->cols = COLS; - rc = view_resize(view, false); + rc = view_resize(view, view->mode); if (rc) return rc; if (view->parent && view->mode == VIEW_SPLIT_HRZN) view->parent->nlines = view->lines - view->nlines - 1; if (mvwin(view->window, view->start_ln, view->start_col) == ERR) - return RC(FSL_RC_ERROR, "mvwin"); + return RC(FSL_RC_ERROR, "%s", "mvwin"); return rc; } static int @@ -4334,16 +4009,16 @@ view->nlines = LINES; view->ncols = COLS; view->lines = LINES; view->cols = COLS; - rc = view_resize(view, false); + rc = view_resize(view, VIEW_SPLIT_NONE); if (rc) return rc; if (mvwin(view->window, view->start_ln, view->start_col) == ERR) - return RC(FSL_RC_ERROR, "mvwin"); + return RC(FSL_RC_ERROR, "%s", "mvwin"); return rc; } /* @@ -4375,13 +4050,15 @@ height = fnc_conf_getopt(FNC_VIEW_SPLIT_HEIGHT, false); if (height && height[fsl_strlen(height) - 1] == '%') { n = strtol(height, NULL, 10); if (n > INT_MAX || (errno == ERANGE && n == LONG_MAX)) - rc = RC(fsl_errno_to_rc(errno, FSL_RC_RANGE), "strtol"); + rc = RC(fsl_errno_to_rc(errno, FSL_RC_RANGE), + "%s", "strtol"); if (n < INT_MIN || (errno == ERANGE && n == LONG_MIN)) - rc = RC(fsl_errno_to_rc(errno, FSL_RC_RANGE), "strtol"); + rc = RC(fsl_errno_to_rc(errno, FSL_RC_RANGE), + "%s", "strtol"); if (!rc) n = lines * ((float)n / 100); } else if (height) rc = strtonumcheck(&n, height, 0, lines); @@ -4457,15 +4134,15 @@ if (s->search_commit) { int ch; if ((rc = pthread_mutex_unlock(&fnc_mutex))) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_mutex_unlock"); + "%s", "pthread_mutex_unlock"); ch = wgetch(view->window); if ((rc = pthread_mutex_lock(&fnc_mutex))) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_mutex_lock"); + "%s", "pthread_mutex_lock"); if (ch == KEY_BACKSPACE) { view->search_status = SEARCH_ABORTED; goto end; } if (view->searching == SEARCH_FORWARD) @@ -4545,18 +4222,20 @@ cbreak(); return rc; } static bool -find_commit_match(struct fnc_commit_artifact *commit, regex_t *regex) +find_commit_match(struct fnc_commit_artifact *commit, +regex_t *regex) { regmatch_t regmatch; - if ((commit->branch && !regexec(regex, commit->branch, 1, ®match, 0)) - || !regexec(regex, commit->user, 1, ®match, 0) - || !regexec(regex, (char *)commit->uuid, 1, ®match, 0) - || !regexec(regex, commit->comment, 1, ®match, 0)) + if (regexec(regex, commit->user, 1, ®match, 0) == 0 || + regexec(regex, (char *)commit->uuid, 1, ®match, 0) == 0 || + regexec(regex, commit->comment, 1, ®match, 0) == 0 || + (commit->branch && regexec(regex, commit->branch, 1, ®match, 0) + == 0)) return true; return false; } @@ -4622,30 +4301,32 @@ if (s->thread_id) { s->quit = 1; if ((rc = pthread_cond_signal(&s->thread_cx.commit_consumer))) return RC(fsl_errno_to_rc(rc, FSL_RC_MISUSE), - "pthread_cond_signal"); + "%s", "pthread_cond_signal"); if ((rc = pthread_mutex_unlock(&fnc_mutex))) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_mutex_unlock"); + "%s", "pthread_mutex_unlock"); if ((rc = pthread_join(s->thread_id, &err)) || err == PTHREAD_CANCELED) return RC(fsl_errno_to_rc(rc, FSL_RC_MISUSE), - "pthread_join"); + "%s", "pthread_join"); if ((rc = pthread_mutex_lock(&fnc_mutex))) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_mutex_lock"); + "%s", "pthread_mutex_lock"); s->thread_id = 0; } if ((rc = pthread_cond_destroy(&s->thread_cx.commit_consumer))) - RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), "pthread_cond_destroy"); + RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), + "%s", "pthread_cond_destroy"); if ((rc = pthread_cond_destroy(&s->thread_cx.commit_producer))) - RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), "pthread_cond_destroy"); + RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), + "%s", "pthread_cond_destroy"); return rc; } static void @@ -4699,48 +4380,46 @@ } static int init_diff_view(struct fnc_view **new_view, int start_col, int start_ln, struct fnc_commit_artifact *commit, struct fnc_view *parent_view, - enum fnc_diff_mode mode) + bool showmeta) { struct fnc_view *diff_view; int rc = 0; diff_view = view_open(0, 0, start_ln, start_col, FNC_VIEW_DIFF); if (diff_view == NULL) - return RC(FSL_RC_ERROR, "view_open"); + return RC(FSL_RC_ERROR, "%s", "view_open"); - rc = open_diff_view(diff_view, commit, NULL, parent_view, mode); + rc = open_diff_view(diff_view, commit, NULL, parent_view, showmeta); if (!rc) *new_view = diff_view; return rc; } static int open_diff_view(struct fnc_view *view, struct fnc_commit_artifact *commit, struct fnc_pathlist_head *paths, struct fnc_view *parent_view, - enum fnc_diff_mode mode) + bool showmeta) { struct fnc_diff_view_state *s = &view->state.diff; int rc = FSL_RC_OK; set_diff_opt(s); s->index.n = 0; s->index.idx = 0; - s->scx.hunk.n = 0; s->paths = paths; s->selected_entry = commit; s->first_line_onscreen = 1; s->last_line_onscreen = view->nlines; s->selected_line = 1; s->f = NULL; - s->view = view; s->parent_view = parent_view; - s->diff_mode = mode; + s->showmeta = showmeta; if (s->colour) { STAILQ_INIT(&s->colours); rc = set_colours(&s->colours, FNC_VIEW_DIFF); if (rc) @@ -4878,29 +4557,28 @@ uint32_t idx = 0; int rc = 0; s->maxx = 0; - free_index(&s->index); free(s->dlines); - s->dlines = fsl_malloc(sizeof(enum line_type)); + s->dlines = fsl_malloc(sizeof(enum line_type *)); if (s->dlines == NULL) - return RC(FSL_RC_ERROR, "fsl_malloc"); + return RC(FSL_RC_ERROR, "%s", "fsl_malloc"); s->ndlines = 0; free(s->line_offsets); s->line_offsets = fsl_malloc(sizeof(off_t)); if (s->line_offsets == NULL) - return RC(FSL_RC_ERROR, "fsl_malloc"); + return RC(FSL_RC_ERROR, "%s", "fsl_malloc"); s->nlines = 0; fout = tmpfile(); if (fout == NULL) { - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), "tmpfile"); + rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), "%s", "tmpfile"); goto end; } if (s->f && fclose(s->f) == EOF) { - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), "fclose"); + rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), "%s", "fclose"); goto end; } s->f = fout; rc = add_line_offset(&s->line_offsets, &s->nlines, 0); @@ -4915,11 +4593,11 @@ !s->selected_entry->changeset.used) rc = create_changeset(s->selected_entry); else if (s->selected_entry->diff_type == FNC_DIFF_BLOB) rc = diff_file_artifact(s, s->selected_entry->prid, NULL, NULL, FSL_CKOUT_CHANGE_MOD); - if (!rc && s->diff_mode == COMMIT_META) + if (!rc && s->showmeta) rc = write_commit_meta(s); if (!rc && s->selected_entry->diff_type == FNC_DIFF_WIKI) rc = diff_non_checkin(s); if (rc) goto end; @@ -4930,26 +4608,26 @@ */ if (s->selected_entry->puuid) { fsl_free(s->id1); s->id1 = fsl_strdup(s->selected_entry->puuid); if (s->id1 == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_strdup"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_strdup"); goto end; } } else s->id1 = NULL; /* Initial commit, tag, technote, etc. */ if (s->selected_entry->uuid) { fsl_free(s->id2); s->id2 = fsl_strdup(s->selected_entry->uuid); if (s->id2 == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_strdup"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_strdup"); goto end; } } else s->id2 = NULL; /* Local work tree. */ - if (s->diff_mode != COMMIT_META) { + if (!s->showmeta) { s->index.offset = fsl_realloc(s->index.offset, (s->index.n + 1) * sizeof(off_t)); s->index.offset[s->index.n++] = 0; } @@ -4961,18 +4639,15 @@ if (s->selected_entry->diff_type == FNC_DIFF_COMMIT) diff_commit(s); else if (s->selected_entry->diff_type == FNC_DIFF_CKOUT) diff_checkout(s); - rc = add_line_type(&s->dlines, &s->ndlines, LINE_BLANK); /* eof \n */ - if (rc) - goto end; - if (s->patch) { char *dflt = fsl_mprintf("path [%.10s.patch]: ", s->id2); struct input in = {NULL, dflt, INPUT_ALPHA, SR_CLREOL}; - fnc_prompt_input(s->view, &in); + fnc_prompt_input(s->parent_view ? + s->parent_view->child : NULL, &in); fsl_free(dflt); if (!in.buf[0]) { fsl_strlcpy(in.buf, s->id2, 11); fsl_strlcat(in.buf, ".patch", sizeof(in.buf)); } @@ -4980,131 +4655,37 @@ rc = fsl_buffer_to_filename(&s->buf, in.buf); if (rc) goto end; } + /* + * Parse the diff buffer line-by-line to record byte offsets of each + * line for scrolling and searching in diff view. + */ st0 = fsl_strdup(fsl_buffer_str(&s->buf)); st = st0; - - if (s->stash) { - /* Arrived here via fnc_stash(); make diffs and return */ - rc = make_stash_diff(s, st); - goto end; - } - - /* - * Parse the diff buffer line-by-line to record byte offsets of each - * line for scrolling and searching in diff view. And save line offsets - * of each file in the diff for C-n/p key maps. - */ off = (s->line_offsets)[s->nlines - 1]; s->index.lineno = fsl_malloc(s->index.n * sizeof(size_t)); while ((line = fnc_strsep(&st, "\n")) != NULL) { int lineno, n = fprintf(s->f, "%s\n", line); - s->maxx = MAX(s->maxx, n); /* longest line for hscroll */ + s->maxx = MAX(s->maxx, n); if (s->index.offset && idx < s->index.n && off == s->index.offset[idx]) { lineno = s->nlines + (idx ? 1 : 0); s->index.lineno[idx++] = lineno; } off += n; rc = add_line_offset(&s->line_offsets, &s->nlines, off); if (rc) goto end; - /* If in stash mode, save line offsets for each hunk. */ - if (s->diff_mode == STASH_INTERACTIVE && - s->nlines < s->ndlines - 1 && - s->dlines[s->nlines] == LINE_DIFF_CHUNK) { - s->scx.hunk.lineno = fsl_realloc(s->scx.hunk.lineno, - (s->scx.hunk.n + 1) * sizeof(size_t)); - if (s->scx.hunk.lineno == NULL) { - rc = RC(FSL_RC_ERROR, "realloc"); - goto end; - } - s->scx.hunk.lineno[s->scx.hunk.n++] = s->nlines; - } } --s->nlines; /* Don't count EOF '\n' */ end: fsl_free(st0); fsl_buffer_clear(&s->buf); if (s->f && fflush(s->f) != 0 && rc == 0) - rc = RC(FSL_RC_IO, "fflush"); - return rc; -} - -/* - * Iterate lines in string st for each diff hunk line (i.e., @@ -w,x +y,z @@), - * and write a patch file at $TMPDIR/fnc-XXXXXX-{stash,ckout}.diff corresponding - * to the stash step identified by s->stash: - * 1. HUNK_STASH: diff of all hunks selected to stash - * 2. HUNK_CKOUT: diff of all hunks to be kept in the checkout - */ -static int -make_stash_diff(struct fnc_diff_view_state *s, char *st) -{ - FILE *f = NULL; - const char *line, *tmpd; - char *pp, *pp0, *tmppath; - size_t idx, lineno; - int i, rc = FSL_RC_OK; - bool drop; - - if ((tmpd = getenv("TMPDIR")) == NULL || *tmpd == '\0') - tmpd = P_tmpdir; - for (i = fsl_strlen(tmpd) - 1; i > 0 && tmpd[i] == '/'; i--) - /* nop */; - ++i; - - /* Make temp files for stash and ckout patches. */ - if (s->stash == HUNK_STASH) { - tmppath = fsl_mprintf("%.*s/fnc", i, tmpd); - rc = fnc_open_tmpfile(&pp, &f, tmppath, "-stash.diff"); - pp0 = s->scx.patch[0]; - } else { - tmppath = fsl_mprintf("%.*s/fnc", i, tmpd); - rc = fnc_open_tmpfile(&pp, &f, tmppath, "-ckout.diff"); - pp0 = s->scx.patch[1]; - } - fsl_free(tmppath); - if (rc) - return rc; - - fsl_strlcpy(pp0, pp, sizeof(s->scx.patch[0])); - fsl_free(pp); - - lineno = 0; - idx = 0; - while (!rc && lineno < s->ndlines && - (line = fnc_strsep(&st, "\n")) != NULL) { - /* - * Write all index headers irrespective of whether the file has - * any selected hunks, otherwise we end up with orphaned hunks. - */ - if (s->dlines[lineno] == LINE_DIFF_INDEX || - s->dlines[lineno] == LINE_DIFF_META) - drop = false; - if (s->dlines[lineno++] == LINE_DIFF_CHUNK) { - /* Stash diff and hunk not marked for stash? Drop it. */ - if (s->stash == HUNK_STASH) - drop = !BIT_CHK(s->scx.stash, idx) ? - true : false; - else /* ckout diff & hunk marked for stash? drop it */ - drop = BIT_CHK(s->scx.stash, idx) ? - true : false; - ++idx; - } - if (drop) - continue; - if (fprintf(f, "%s\n", line) < 0) - rc = RC(FSL_RC_RANGE, "fprintf"); - } - - if (f && fflush(f) != 0) - rc = RC(FSL_RC_IO, "fflush"); - fsl_fclose(f); - + rc = RC(FSL_RC_IO, "%s", "fflush"); return rc; } static int create_changeset(struct fnc_commit_artifact *commit) @@ -5124,11 +4705,11 @@ "WHERE mlink.mid=%d AND NOT mlink.isaux " "AND (mlink.fid > 0 " "OR mlink.fnid NOT IN (SELECT pfnid FROM mlink WHERE mid=%d)) " "ORDER BY name", commit->rid, commit->rid); if (rc) - return RC(FSL_RC_DB, "fsl_cx_prepare"); + return RC(FSL_RC_DB, "%s", "fsl_cx_prepare"); while ((rc = fsl_stmt_step(st)) == FSL_RC_STEP_ROW) { struct fsl_file_artifact *fdiff = NULL; const char *path, *oldpath, *olduuid, *uuid; /* TODO: Parse file mode to display in commit changeset. */ @@ -5174,13 +4755,15 @@ write_commit_meta(struct fnc_diff_view_state *s) { char *line = NULL, *st0 = NULL, *st = NULL; fsl_size_t linelen, idx = 0; off_t off = 0; - int n, rc = FSL_RC_OK; + int rc = FSL_RC_OK, n = 7; /* Min lines in commit meta */ - rc = add_line_type(&s->dlines, &s->ndlines, LINE_DIFF_META); + n += countlines(s->selected_entry->comment); + n += s->selected_entry->changeset.used; + rc = add_line_type(&s->dlines, LINE_DIFF_META, &s->ndlines, n, true); if (rc) goto end; if ((n = fprintf(s->f,"%s %s\n", s->selected_entry->type, s->selected_entry->uuid)) < 0) @@ -5191,49 +4774,48 @@ goto end; if ((n = fprintf(s->f,"user: %s\n", s->selected_entry->user)) < 0) goto end; off += n; - rc = add_line_type(&s->dlines, &s->ndlines, LINE_DIFF_USER); + rc = add_line_type(&s->dlines, LINE_DIFF_USER, &s->ndlines, 0, true); if (!rc) rc = add_line_offset(&s->line_offsets, &s->nlines, off); if (rc) goto end; if ((n = fprintf(s->f,"tags: %s\n", s->selected_entry->branch ? s->selected_entry->branch : "/dev/null")) < 0) goto end; off += n; - rc = add_line_type(&s->dlines, &s->ndlines, LINE_DIFF_TAGS); + rc = add_line_type(&s->dlines, LINE_DIFF_TAGS, &s->ndlines, 0, true); if (!rc) rc = add_line_offset(&s->line_offsets, &s->nlines, off); if (rc) goto end; if ((n = fprintf(s->f,"date: %s\n", s->selected_entry->timestamp)) < 0) goto end; off += n; - rc = add_line_type(&s->dlines, &s->ndlines, LINE_DIFF_DATE); + rc = add_line_type(&s->dlines, LINE_DIFF_DATE, &s->ndlines, 0, true); if (!rc) rc = add_line_offset(&s->line_offsets, &s->nlines, off); if (rc) goto end; - /* Add blank line between end of commit metadata and comment. */ fputc('\n', s->f); ++off; - rc = add_line_type(&s->dlines, &s->ndlines, LINE_BLANK); + rc = add_line_type(&s->dlines, LINE_BLANK, &s->ndlines, 0, true); if (!rc) rc = add_line_offset(&s->line_offsets, &s->nlines, off); if (rc) goto end; st0 = fsl_strdup(s->selected_entry->comment); st = st0; if (st == NULL) { - RC(FSL_RC_ERROR, "fsl_strdup"); + RC(FSL_RC_ERROR, "%s", "fsl_strdup"); goto end; } while ((line = fnc_strsep(&st, "\n")) != NULL) { linelen = fsl_strlen(line); if (linelen >= s->ncols) { @@ -5243,35 +4825,34 @@ } else { if ((n = fprintf(s->f, "%s\n", line)) < 0) goto end; off += n; - rc = add_line_type(&s->dlines, &s->ndlines, - LINE_DIFF_COMMENT); + rc = add_line_type(&s->dlines, LINE_DIFF_COMMENT, + &s->ndlines, 0, true); if (!rc) rc = add_line_offset(&s->line_offsets, &s->nlines, off); if (rc) goto end; } } - /* Add blank line between end of comment and changeset. */ fputc('\n', s->f); ++off; - rc = add_line_type(&s->dlines, &s->ndlines, LINE_BLANK); + rc = add_line_type(&s->dlines, LINE_BLANK, &s->ndlines, 0, true); if (!rc) rc = add_line_offset(&s->line_offsets, &s->nlines, off); if (rc) goto end; if (s->selected_entry->diff_type == FNC_DIFF_WIKI) goto end; /* No changeset for wiki commits. */ for (idx = 0; idx < s->selected_entry->changeset.used; ++idx) { - char *changeline, *t = NULL; + char *changeline; struct fsl_file_artifact *file_change; file_change = s->selected_entry->changeset.list[idx]; switch (file_change->change) { @@ -5280,37 +4861,36 @@ break; case FSL_CKOUT_CHANGE_ADDED: changeline = "[+] "; break; case FSL_CKOUT_CHANGE_RENAMED: - t = fsl_mprintf("[>] %s -> ", + changeline = fsl_mprintf("[>] %s -> ", file_change->fc->priorName); - changeline = t; break; case FSL_CKOUT_CHANGE_REMOVED: changeline = "[-] "; break; default: changeline = "[!] "; break; } - n = fprintf(s->f, "%s%s\n", changeline, file_change->fc->name); - fsl_free(t); - if (n < 0) + if ((n = fprintf(s->f, "%s%s\n", changeline, + file_change->fc->name)) < 0) goto end; off += n; - rc = add_line_type(&s->dlines, &s->ndlines, LINE_DIFF_META); + rc = add_line_type(&s->dlines, LINE_DIFF_META, &s->ndlines, 0, + true); if (!rc) rc = add_line_offset(&s->line_offsets, &s->nlines, off); if (rc) goto end; } /* Add blank line between end of changeset and diff. */ fputc('\n', s->f); ++off; - rc = add_line_type(&s->dlines, &s->ndlines, LINE_BLANK); + rc = add_line_type(&s->dlines, LINE_BLANK, &s->ndlines, 0, true); if (!rc) rc = add_line_offset(&s->line_offsets, &s->nlines, off); if (rc) goto end; s->index.offset = fsl_realloc(s->index.offset, @@ -5325,21 +4905,21 @@ s->nlines = 0; } return rc; } -/* static int */ -/* countlines(const char *str) */ -/* { */ -/* int n, idx; */ - -/* for (idx = 0, n = 1; str[idx]; ++idx) */ -/* if (str[idx] == '\n') */ -/* ++n; */ - -/* return str[idx - 1] == '\n' ? n : ++n; */ -/* } */ +static int +countlines(const char *str) +{ + int n, idx; + + for (idx = 0, n = 1; str[idx]; ++idx) + if (str[idx] == '\n') + ++n; + + return str[idx - 1] == '\n' ? n : ++n; +} /* * Wrap long lines at the terminal's available column width. The caller * must ensure the limit parameter has taken into account whether the * screen is currently split, and not mistakenly pass in the curses COLS macro @@ -5358,12 +4938,12 @@ while ((word = fnc_strsep(&line, " ")) != NULL) { wordlen = fsl_strlen(word); if ((cursor + wordlen) >= limit) { fputc('\n', s->f); ++(*off); - rc = add_line_type(&s->dlines, &s->ndlines, - LINE_DIFF_COMMENT); + rc = add_line_type(&s->dlines, LINE_DIFF_COMMENT, + &s->ndlines, 0, true); if (!rc) rc = add_line_offset(&s->line_offsets, &s->nlines, *off); if (rc) return rc; @@ -5374,31 +4954,51 @@ *off += n; cursor += n; } fputc('\n', s->f); ++(*off); - rc = add_line_type(&s->dlines, &s->ndlines, LINE_DIFF_COMMENT); + rc = add_line_type(&s->dlines, LINE_DIFF_COMMENT, &s->ndlines, 0, true); if (!rc) rc = add_line_offset(&s->line_offsets, &s->nlines, *off); return rc; } static int add_line_offset(off_t **line_offsets, size_t *nlines, off_t off) { - off_t *p; + off_t *p; p = fsl_realloc(*line_offsets, (*nlines + 1) * sizeof(off_t)); if (p == NULL) - return RC(FSL_RC_ERROR, "fsl_realloc"); + return RC(FSL_RC_ERROR, "%s", "fsl_realloc"); *line_offsets = p; (*line_offsets)[*nlines] = off; (*nlines)++; return 0; } + +static int +add_line_type(enum line_type **lines, enum line_type type, uint32_t *nlines, + uint32_t alloc, bool incr) +{ + if (alloc) { + enum line_type *p; + p = fsl_realloc(*lines, + (*nlines + alloc) * sizeof(enum line_type *)); + if (p == NULL) + return RC(FSL_RC_ERROR, "%s", "fsl_realloc"); + *lines = p; + } + + (*lines)[*nlines] = type; + if (incr) + (*nlines)++; + + return FSL_RC_OK; +} /* * Fill the buffer with the differences between commit->uuid and commit->puuid. * commit->rid (to load into deck d2) is the *this* version, and commit->puuid * (to be loaded into deck d1) is the version we diff against. Step through the @@ -5497,22 +5097,20 @@ rc = diff_file_artifact(s, id1, fc1, fc2, change); fsl_deck_F_next(&d1, &fc1); fsl_deck_F_next(&d2, &fc2); } - if (rc == FSL_RC_RANGE || rc == FSL_RC_DIFF_BINARY || - rc == FSL_RC_TYPE) { - fsl_buffer_append(&s->buf, rc == FSL_RC_RANGE ? - "\nDiff has too many changes\n" : - rc == FSL_RC_TYPE ? "\nNot a regular file\n" : - "\nBinary files cannot be diffed\n", -1); + if (rc == FSL_RC_RANGE) { + fsl_buffer_append(&s->buf, + "\nDiff has too many changes\n", -1); + rc = 0; fsl_cx_err_reset(f); - rc = add_line_type(&s->dlines, &s->ndlines, - LINE_DIFF_COMMENT); - if (!rc) - rc = add_line_type(&s->dlines, &s->ndlines, - LINE_BLANK); + } else if (rc == FSL_RC_DIFF_BINARY) { + fsl_buffer_append(&s->buf, + "\nBinary files cannot be diffed\n", -1); + rc = 0; + fsl_cx_err_reset(f); } else if (rc) goto end; } end: fsl_deck_finalize(&d1); @@ -5551,66 +5149,63 @@ if (vid != cid) { /* Keep vfile ckout state; but unload vid when finished. */ rc = fsl_vfile_load(f, vid, false, NULL); if (rc) goto unload; - fsl_buffer_appendf(&sql, "SELECT v2.pathname, v2.origname, " - " v2.deleted, v2.chnged, v2.rid == 0, v1.rid, v1.islink" + fsl_buffer_appendf(&sql, "SELECT v2.pathname, v2.deleted, " + "v2.chnged, v2.rid == 0, v1.rid, v1.islink" " FROM vfile v1, vfile v2" " WHERE v1.pathname=v2.pathname AND v1.vid=%d AND v2.vid=%d" " AND (v2.deleted OR v2.chnged OR v1.mrid != v2.rid)" " UNION " - "SELECT pathname, origname, 1, 0, 0, 0, islink" + "SELECT pathname, 1, 0, 0, 0, islink" " FROM vfile v1" " WHERE v1.vid = %d" " AND NOT EXISTS(SELECT 1 FROM vfile v2" " WHERE v2.vid = %d AND v2.pathname = v1.pathname)" " UNION " - "SELECT pathname, origname, 0, 0, 1, 0, islink" + "SELECT pathname, 0, 0, 1, 0, islink" " FROM vfile v2" " WHERE v2.vid = %d" " AND NOT EXISTS(SELECT 1 FROM vfile v1" " WHERE v1.vid = %d AND v1.pathname = v2.pathname)" " ORDER BY 1", vid, cid, vid, cid, cid, vid); } else { - fsl_buffer_appendf(&sql, "SELECT pathname, origname, deleted, " - "chnged, rid == 0, rid, islink" + fsl_buffer_appendf(&sql, "SELECT pathname, deleted, chnged, " + "rid == 0, rid, islink" " FROM vfile" " WHERE vid = %d" - " AND (deleted OR chnged OR rid==0" - " OR (origname IS NOT NULL AND origname<>pathname))" + " AND (deleted OR chnged OR rid == 0)" " ORDER BY pathname", cid); } st = fsl_stmt_malloc(); rc = fsl_cx_prepare(f, st, "%b", &sql); if (rc) { - rc = RC(rc, "fsl_cx_prepare"); + rc = RC(rc, "%s", "fsl_cx_prepare"); goto yield; } while ((rc = fsl_stmt_step(st)) == FSL_RC_STEP_ROW) { - const char *path, *ogpath; + const char *path; int deleted, changed, added, fid, symlink; enum fsl_ckout_change_e change; bool diff = true; path = fsl_stmt_g_text(st, 0, NULL); - ogpath = fsl_stmt_g_text(st, 1, NULL); - deleted = fsl_stmt_g_int32(st, 2); - changed = fsl_stmt_g_int32(st, 3); - added = fsl_stmt_g_int32(st, 4); - fid = fsl_stmt_g_int32(st, 5); - symlink = fsl_stmt_g_int32(st, 6); + deleted = fsl_stmt_g_int32(st, 1); + changed = fsl_stmt_g_int32(st, 2); + added = fsl_stmt_g_int32(st, 3); + fid = fsl_stmt_g_int32(st, 4); + symlink = fsl_stmt_g_int32(st, 5); rc = fsl_file_canonical_name2(f->ckout.dir, path, &abspath, false); if (rc) goto yield; - if (deleted) { - ogpath = path; + if (deleted) change = FSL_CKOUT_CHANGE_REMOVED; - } else if (fsl_file_access(fsl_buffer_cstr(&abspath), F_OK)) + else if (fsl_file_access(fsl_buffer_cstr(&abspath), F_OK)) change = FSL_CKOUT_CHANGE_MISSING; else if (added) { fid = 0; change = FSL_CKOUT_CHANGE_ADDED; } else if (changed == 3) { @@ -5617,13 +5212,11 @@ fid = 0; change = FSL_CKOUT_CHANGE_MERGE_ADD; } else if (changed == 5) { fid = 0; change = FSL_CKOUT_CHANGE_INTEGRATE_ADD; - } else if (fsl_strcmp(ogpath, path)) - change = FSL_CKOUT_CHANGE_RENAMED; - else + } else change = FSL_CKOUT_CHANGE_MOD; /* * For changed files of which this checkout is already aware, * grab their hash to make comparisons. For removed files, if @@ -5647,11 +5240,12 @@ do { fsl_deck_F_next(&d, &cf); if (cf && !fsl_strcmp(cf->name, path)) { xminus = fsl_strdup(cf->uuid); if (xminus == NULL) { - RC(FSL_RC_ERROR, "fsl_strdup"); + RC(FSL_RC_ERROR, "%s", + "fsl_strdup"); goto yield; } fid = fsl_uuid_to_rid(f, xminus); break; } @@ -5666,16 +5260,10 @@ allow_symlinks)) { rc = write_diff_meta(s, path, xminus, path, NULL_DEVICE, change); fsl_buffer_append(&s->buf, "\nSymbolic links cannot be diffed\n", -1); - if (!rc) - rc = add_line_type(&s->dlines, &s->ndlines, - LINE_DIFF_COMMENT); - if (!rc) - rc = add_line_type(&s->dlines, &s->ndlines, - LINE_BLANK); if (rc) goto yield; continue; } if (fid > 0 && change != FSL_CKOUT_CHANGE_ADDED) { @@ -5693,28 +5281,26 @@ diff = true; break; } } if (diff) - rc = diff_file(s, &bminus, ogpath, path, xminus, + rc = diff_file(s, &bminus, path, xminus, fsl_buffer_cstr(&abspath), change); fsl_buffer_reuse(&bminus); fsl_buffer_reuse(&abspath); fsl_free(xminus); xminus = NULL; - if (rc == FSL_RC_RANGE || rc == FSL_RC_DIFF_BINARY || - rc == FSL_RC_TYPE) { - fsl_buffer_append(&s->buf, rc == FSL_RC_RANGE ? - "\nDiff has too many changes\n" : - rc == FSL_RC_TYPE ? "\nNot a regular file\n" : - "\nBinary files cannot be diffed\n", -1); + if (rc == FSL_RC_RANGE) { + fsl_buffer_append(&s->buf, + "\nDiff has too many changes\n", -1); + rc = 0; fsl_cx_err_reset(f); - rc = add_line_type(&s->dlines, &s->ndlines, - LINE_DIFF_COMMENT); - if (!rc) - rc = add_line_type(&s->dlines, &s->ndlines, - LINE_BLANK); + } else if (rc == FSL_RC_DIFF_BINARY) { + fsl_buffer_append(&s->buf, + "\nBinary files cannot be diffed\n", -1); + rc = 0; + fsl_cx_err_reset(f); } else if (rc) goto yield; } yield: @@ -5774,12 +5360,10 @@ minus = xminus; plus = xplus; break; } - zminus = zminus ? zminus : zplus; - if FLAG_CHK(s->diff_flags, FNC_DIFF_INVERT) { const char *tmp = minus; minus = plus; plus = tmp; tmp = zminus; @@ -5786,30 +5370,19 @@ zminus = zplus; zplus = tmp; } if (!FLAG_CHK(s->diff_flags, FNC_DIFF_BRIEF)) { - int c; - enum line_type i; - - if (s->buf.used) { - /* - * There're previous files in the diff--I don't like - * Git's contiguous lines between files--so add a new - * line before this file's 'Index: file/path' line. - */ - rc = add_line_type(&s->dlines, &s->ndlines, LINE_BLANK); - if (!rc) - rc = fsl_buffer_append(&s->buf, "\n", 1); - } + int c, i; for (c = 0, i = 10; !rc && i < 14; ++c) { - rc = add_line_type(&s->dlines, &s->ndlines, i); + rc = add_line_type(&s->dlines, (enum line_type)i, + &s->ndlines, (!c ? 6 : 0), true); i += (c > 3 || c % 2) ? 1 : 0; } if (!rc) - rc = fsl_buffer_appendf(&s->buf, "Index: %s\n%.71c\n", - index, '='); + rc = fsl_buffer_appendf(&s->buf, "%sIndex: %s\n%.71c\n", + s->buf.used ? "\n" : "", index, '='); if (!rc) rc = fsl_buffer_appendf(&s->buf, "hash - %s\nhash + %s\n", minus, plus); if (!rc) rc = fsl_buffer_appendf(&s->buf, "--- %s\n+++ %s\n", @@ -5830,16 +5403,16 @@ * change enum denoting the versioning change of the file * diff_flags, context, and sbs are the same parameters as diff_file_artifact() */ static int diff_file(struct fnc_diff_view_state *s, fsl_buffer *bminus, const char *zminus, - const char *zplus, fsl_uuid_str xminus, const char *abspath, - enum fsl_ckout_change_e change) + fsl_uuid_str xminus, const char *abspath, enum fsl_ckout_change_e change) { fsl_cx *const f = fcli_cx(); fsl_buffer bplus = fsl_buffer_empty; fsl_buffer xplus = fsl_buffer_empty; + const char *zplus = NULL; int rc = 0; /* * If it exists, read content of abspath to diff EXCEPT for the content * of 'fossil rm FILE' files because they will either: (1) have the same @@ -5864,10 +5437,11 @@ * condition and uncomment the following three lines of code. */ /* if (change == FSL_CKOUT_CHANGE_REMOVED && */ /* !fsl_buffer_compare(bminus, &bplus)) */ /* fsl_buffer_clear(&bplus); */ + zplus = zminus; } switch (fsl_strlen(xminus)) { case FSL_STRLEN_K256: rc = fsl_sha3sum_buffer(&bplus, &xplus); @@ -5916,10 +5490,11 @@ (bminus->used && bplus.used)) rc = fnc_diff_text_to_buffer(bminus, &bplus, &s->buf, &s->dlines, &s->ndlines, s->context, s->sbs, s->diff_flags); end: + rc = add_line_type(&s->dlines, LINE_BLANK, &s->ndlines, 0, true); fsl_buffer_clear(&bplus); fsl_buffer_clear(&xplus); return rc; } @@ -5939,11 +5514,11 @@ int rc = 0; fsl_deck *d = NULL; d = fsl_deck_malloc(); if (d == NULL) - return RC(FSL_RC_ERROR, "fsl_deck_malloc"); + return RC(FSL_RC_ERROR, "%s", "fsl_deck_malloc"); fsl_deck_init(f, d, FSL_SATYPE_ANY); rc = fsl_deck_load_rid(f, d, s->selected_entry->rid, FSL_SATYPE_ANY); if (rc) goto end; @@ -5954,21 +5529,21 @@ */ if (d->type == FSL_SATYPE_TICKET) { for (idx = 0; idx < d->J.used; ++idx) { fsl_card_J *ticket = d->J.list[idx]; bool icom = !fsl_strncmp(ticket->field, "icom", 4); - fsl_buffer_appendf(&s->buf, "%llu. %s:%s%s%c\n", idx + 1, + fsl_buffer_appendf(&s->buf, "%d. %s:%s%s%c\n", idx + 1, ticket->field, icom ? "\n\n" : " ", ticket->value, icom ? '\n' : ' '); } goto end; } if (d->type == FSL_SATYPE_CONTROL) { for (idx = 0; idx < d->T.used; ++idx) { fsl_card_T *ctl = d->T.list[idx]; - fsl_buffer_appendf(&s->buf, "Tag %llu ", idx + 1); + fsl_buffer_appendf(&s->buf, "Tag %d ", idx + 1); switch (ctl->type) { case FSL_TAGTYPE_CANCEL: fsl_buffer_append(&s->buf, "[CANCEL]", -1); break; case FSL_TAGTYPE_ADD: @@ -6087,11 +5662,11 @@ zminus0 = fsl_strdup(fsl_stmt_g_text(&stmt, 0, NULL)); zminus = zminus0; } else if (rc == FSL_RC_STEP_DONE) rc = 0; else if (rc) { - rc = RC(rc, "fsl_stmt_step"); + rc = RC(rc, "%s", "fsl_stmt_step"); goto end; } xminus0 = fsl_rid_to_uuid(f, vid1); xminus = xminus0; fsl_stmt_finalize(&stmt); @@ -6117,11 +5692,11 @@ zplus0 = fsl_strdup(fsl_stmt_g_text(&stmt, 0, NULL)); zplus = zplus0; } else if (rc == FSL_RC_STEP_DONE) rc = 0; else if (rc) { - rc = RC(rc, "fsl_stmt_step"); + rc = RC(rc, "%s", "fsl_stmt_step"); goto end; } xplus0 = fsl_rid_to_uuid(f, vid2); xplus = xplus0; fsl_stmt_finalize(&stmt); @@ -6146,10 +5721,11 @@ RC(rc, "%s: fnc_diff_text_to_buffer\n" " -> %s [%s]\n -> %s [%s]", fsl_rc_cstr(rc), a ? a->name : NULL_DEVICE, a ? a->uuid : NULL_DEVICE, b ? b->name : NULL_DEVICE, b ? b->uuid : NULL_DEVICE); end: + rc = add_line_type(&s->dlines, LINE_BLANK, &s->ndlines, 0, true); fsl_free(zminus0); fsl_free(zplus0); fsl_free(xminus0); fsl_free(xplus0); fsl_buffer_clear(&fbuf1); @@ -6164,26 +5740,26 @@ char *headln, *id2, *id1 = NULL; /* Some diffs (e.g., technote, tag) have no parent hash to display. */ id1 = fsl_strdup(s->id1 ? s->id1 : "/dev/null"); if (id1 == NULL) - return RC(FSL_RC_ERROR, "fsl_strdup"); + return RC(FSL_RC_ERROR, "%s", "fsl_strdup"); /* * If diffing the work tree, we have no hash to display for it. * XXX Display "work tree" or "checkout" or "/dev/null" for clarity? */ id2 = fsl_strdup(s->id2 ? s->id2 : ""); if (id2 == NULL) { fsl_free(id1); - return RC(FSL_RC_ERROR, "fsl_strdup"); + return RC(FSL_RC_ERROR, "%s", "fsl_strdup"); } if ((headln = fsl_mprintf("diff %.40s %.40s", id1, id2)) == NULL) { fsl_free(id1); fsl_free(id2); - return RC(FSL_RC_RANGE, "fsl_mprintf"); + return RC(FSL_RC_RANGE, "%s", "fsl_mprintf"); } fsl_free(id1); fsl_free(id2); return write_diff(view, headln); @@ -6195,11 +5771,11 @@ struct fnc_diff_view_state *s = &view->state.diff; regmatch_t *regmatch = &view->regmatch; struct fnc_colour *c = NULL; wchar_t *wcstr; char *line; - size_t lidx, linesz = 0; + size_t linesz = 0; ssize_t linelen; off_t line_offset; attr_t rx = A_BOLD; int col, wstrlen, max_lines = view->nlines; int nlines = s->nlines; @@ -6207,30 +5783,27 @@ bool selected; s->lineno = s->first_line_onscreen - 1; line_offset = s->line_offsets[s->first_line_onscreen - 1]; if (fseeko(s->f, line_offset, SEEK_SET)) - return RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), "fseeko"); + return RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), "%s", "fseeko"); werase(view->window); if (headln) { static char pct[MAX_PCT_LEN]; double percent; int ln, pctlen; - ln = s->gtl ? s->gtl : s->lineno + s->selected_line; percent = 100.00 * ln / nlines; pctlen = snprintf(pct, MAX_PCT_LEN, "%.*lf%%", percent > 99.99 ? 0 : 2, percent); - if (pctlen < 0 || pctlen >= MAX_PCT_LEN) - return RC(fsl_errno_to_rc(errno, FSL_RC_RANGE), - "snprintf"); - + if (pctlen < 0) + return RC(FSL_RC_RANGE, "%s", "snprintf"); line = fsl_mprintf("[%d/%d] %s", ln, nlines, headln); if (line == NULL) - return RC(FSL_RC_RANGE, "fsl_mprintf"); + return RC(FSL_RC_RANGE, "%s", "fsl_mprintf"); rc = formatln(&wcstr, &wstrlen, line, view->ncols, 0, false); fsl_free(line); fsl_free(headln); if (rc) return rc; @@ -6262,11 +5835,11 @@ s->eof = true; break; } fsl_free(line); RC(ferror(s->f) ? fsl_errno_to_rc(errno, FSL_RC_IO) : - FSL_RC_IO, "getline"); + FSL_RC_IO, "%s", "getline"); return rc; } if (++s->lineno < s->first_line_onscreen) continue; @@ -6273,23 +5846,19 @@ if (s->gtl) if (!gotoline(view, &s->lineno, &nprinted)) continue; rx = 0; - lidx = s->lineno - 1; if ((selected = nprinted == s->selected_line - 1)) rx = A_BOLD | A_REVERSE; if (s->showln) col = draw_lineno(view, nlines, s->lineno, rx); - if (s->diff_mode == STASH_INTERACTIVE && - s->scx.hunk.lineno[s->scx.hunk.idx] == lidx) - rx = A_REVERSE; /* highlight current hunk to stash */ - if (s->colour) - c = get_colour(&s->colours, - s->dlines[MIN(s->ndlines - 1, lidx)]); + c = FLAG_CHK(s->diff_flags, FNC_DIFF_SIDEBYSIDE) ? + get_colour(&s->colours, s->dlines[s->lineno - 1]) : + match_colour(&s->colours, line); if (c && !(selected && s->sline == SLINE_MONO)) rx |= COLOR_PAIR(c->scheme); if (c || selected) wattron(view->window, rx); @@ -6580,11 +6149,11 @@ ++s->first_line_onscreen; if (linelen == -1) { if (!feof(s->f)) return RC(ferror(s->f) ? fsl_errno_to_rc(errno, FSL_RC_IO) : - FSL_RC_IO, "getline"); + FSL_RC_IO, "%s", "getline"); if (s->selected_line > nscroll) s->selected_line = view->nlines - 2; else s->selected_line = nscroll; s->eof = true; @@ -6677,11 +6246,11 @@ if (view_is_parent(view)) start_col = view_split_start_col(view->start_col); branch_view = view_open(view->nlines, view->ncols, view->start_ln, start_col, FNC_VIEW_BRANCH); if (branch_view == NULL) - return RC(FSL_RC_ERROR, "view_open"); + return RC(FSL_RC_ERROR, "%s", "view_open"); rc = open_branch_view(branch_view, BRANCH_LS_OPEN_CLOSED, NULL, 0, 0); if (rc) { view_close(branch_view); return rc; @@ -6799,2094 +6368,21 @@ } return rc; } -static int -f__stash_get(bool pop) -{ - fsl_cx *const f = fcli_cx(); - fsl_db *db = fsl_needs_ckout(f); - fsl_stmt q = fsl_stmt_empty; - int nadded, stashid, vid, rc0, rc = FSL_RC_OK; - uint32_t cc = 0; - - stashid = fsl_db_g_int32(db, 0, "SELECT max(stashid) FROM stash"); - if (!stashid) { - f_out(">> empty stash"); - return rc; - } - - vid = f->ckout.rid; - - rc = fsl_db_prepare(db, &q, "SELECT blob.rid, isRemoved, isExec," - " isLink, origname, newname, delta FROM stashfile, blob" - " WHERE stashid=%d AND blob.uuid=stashfile.hash UNION ALL" - " SELECT 0, isRemoved, isExec, isLink, origname, newname, delta" - " FROM stashfile WHERE stashid=%d AND stashfile.hash IS NULL", - stashid, stashid); - if (rc) - return RC(rc, "fsl_db_prepare"); - fsl_db_exec_multi(db, - "CREATE TEMP TABLE sfile(pathname TEXT PRIMARY KEY %s)", - fsl_cx_filename_collation(f)); - if (rc) - return RC(rc, "fsl_db_exec_multi"); - - while (fsl_stmt_step(&q) == FSL_RC_STEP_ROW) { - fsl_buffer delta = fsl_buffer_empty; - const void *blob = NULL; - const char *ogname = fsl_stmt_g_text(&q, 4, NULL); - const char *name = fsl_stmt_g_text(&q, 5, NULL); - int rid = fsl_stmt_g_int32(&q, 0); - int removed = fsl_stmt_g_int32(&q, 1); - int exec = fsl_stmt_g_int32(&q, 2); - int link = fsl_stmt_g_int32(&q, 3); - char *ogpath = fsl_mprintf("%s%s", CKOUTDIR, ogname); - char *path = fsl_mprintf("%s%s", CKOUTDIR, name); - fsl_size_t len = 0; - - if (!rid) { /* new file */ - rc = fsl_db_exec_multi(db, - "INSERT OR IGNORE INTO sfile(pathname) VALUES(%Q)", - name); - if (!rc) - rc = fsl_stmt_get_blob(&q, 6, &blob, &len); - fsl_buffer_external(&delta, blob, len); - if (!rc) - rc = fsl_buffer_to_filename(&delta, path); - if (!rc) - rc = fsl_file_exec_set(path, exec); - if (rc) { - rc = RC(rc, "new file: %s", name); - goto clear_delta; - } - } else if (removed) { - fsl_ckout_unmanage_opt opt = - fsl_ckout_unmanage_opt_empty; - opt.scanForChanges = false; - opt.vfileIds = NULL; - opt.relativeToCwd = false; - opt.callback = stash_get_rm_cb; - opt.callbackState = NULL; - opt.filename = ogname; - rc = fsl_ckout_unmanage(f, &opt); - if (rc) { - rc = RC(rc, "fsl_ckout_unmanage(%s)", ogname); - goto clear_delta; - } - /* - * XXX Unlike fossil(1), we don't want to rm the file - * from disk because removal has not been committed, - * only stashed. We've unmanaged it, let the user rm it. - */ - /* fsl_file_unlink(ogpath); */ - } else if (fsl__ckout_safe_file_check(f, path)) - /* nop--ignore unsafe path */; - else { - fsl_buffer a, b, out, disk; - fsl_error err; - int newlink = fsl_is_symlink(ogpath); - - a = b = out = disk = fsl_buffer_empty; - - rc = fsl_stmt_get_blob(&q, 6, &blob, &len); - fsl_buffer_external(&delta, blob, len); - if (rc) { - rc = RC(rc, "fsl_stmt_get_blob"); - goto clear_delta; - } - rc = fsl_buffer_fill_from_filename(&disk, ogpath); - if (rc == FSL_RC_NOT_FOUND) - rc = fsl_buffer_fill_from_filename(&disk, path); - if (rc) { - rc = RC(rc, "fsl_buffer_fill_from_filename(%s)", - ogpath); - goto clear_file; - } - rc = fsl_content_get(f, rid, &a); - if (rc) { - rc = RC(rc, "fsl_content_get(%d)", rid); - goto clear_file; - } - rc = fsl_buffer_delta_apply2(&a, &delta, &b, &err); - if (rc) { - rc = RC(err.code, "%s", - fsl_buffer_cstr(&err.msg)); - goto clear_file; - } - - if (link == newlink && !fsl_buffer_compare(&disk, &a)) { - if (link || newlink) - rc = fsl_file_unlink(path); - if (!rc && link) { - bool linkit = fsl_config_get_bool(f, - FSL_CONFDB_REPO, false, - "allow-symlinks"); - rc = fsl_symlink_create( - fsl_buffer_cstr(&b), path, linkit); - f_out("[>] %s -> %s\n", - fsl_buffer_cstr(&b), name); - } else if (!rc) - rc = fsl_buffer_to_filename(&b, path); - if (!rc) - rc = fsl_file_exec_set(path, exec); - if (rc) { - rc = RC(rc, "update file: %s", name); - goto clear_file; - } - if (ogname && fsl_strcmp(ogname, name)) - f_out("[>] %s -> %s\n", ogname, name); - else - f_out("[u] %s\n", name); - } else { - bool lnk = false; - if (link || newlink) { - lnk = true; - fsl_buffer_clear(&b); - /* f_out(">> cannot merge symlink %s\n", name); */ - } else { - rc = fsl_buffer_merge3(&a, &disk, &b, - &out, &cc); - if (!rc) - rc = fsl_buffer_to_filename(&out, - path); - if (!rc) - rc = fsl_file_exec_set(path, - exec); - if (rc) { - rc = RC(rc, "merge file: %s", - path); - goto clear_file; - } - } - if (cc) - f_out("[!] %s -> %u " - "merge conflict(s)\n", name, cc); - else if (lnk) - f_out("[!] %s -> symlink\n", name); - else if (ogname && fsl_strcmp(ogname, name)) - f_out("[~] %s -> %s\n", ogname, name); - else - f_out("[~] %s\n", name); - } -clear_file: - fsl_buffer_clear(&a); - fsl_buffer_clear(&b); - fsl_buffer_clear(&out); - fsl_buffer_clear(&disk); - if (rc) - goto clear_delta; - } -clear_delta: - fsl_buffer_clear(&delta); - if (!rc && fsl_strcmp(ogname, name)) { - fsl_file_unlink(ogpath); - if (rc) - rc = RC(rc, "fsl_file_unlink(%s)", ogpath); - rc = rc ? rc : fsl_db_exec_multi(db, - "UPDATE vfile SET pathname='%q', origname='%q'" - " WHERE pathname='%q' %s AND vid=%d", name, ogname, - ogname, fsl_cx_filename_collation(f), vid); - } - fsl_free(path); - fsl_free(ogpath); - if (rc) - break; - } - if (!rc) - rc = f__add_files_in_sfile(&nadded, vid); - rc0 = fsl_stmt_finalize(&q); - rc = rc ? rc : rc0; - - if (cc) - f_out("\n>> merge conflict(s): %u\n", cc); - - if (pop) { - rc = fsl_db_exec_multi(db, "DELETE FROM stash WHERE stashid=%d;" - "DELETE FROM stashfile WHERE stashid=%d;", - stashid, stashid); - } - return rc; -} - -static int -f__add_files_in_sfile(int *nadded, int vid) -{ - fsl_cx *const f = fcli_cx(); - fsl_db *db = fsl_needs_ckout(f); - int rc0, rc = FSL_RC_OK; - fsl_stmt loop = fsl_stmt_empty; /* SQL to loop over all files to add */ - - rc = fsl_db_prepare(db, &loop, - "SELECT pathname FROM sfile" - " WHERE pathname NOT IN" - " (SELECT sfile.pathname FROM vfile, sfile" - " WHERE vfile.islink AND NOT vfile.deleted" - " AND sfile.pathname>(vfile.pathname||'/')" - " AND sfile.pathname<(vfile.pathname||'0'))" - " ORDER BY pathname"); - if (rc) - return RC(rc, "fsl_db_prepare"); - - while (!rc && fsl_stmt_step(&loop) == FSL_RC_STEP_ROW) { - fsl_ckout_manage_opt opt = fsl_ckout_manage_opt_empty; - const char *add = fsl_stmt_g_text(&loop, 0, NULL); - if (!fsl_strcmp(add, REPODB)) - continue; - if (fsl_is_reserved_fn(add, -1)) - continue; - opt.filename = add; - opt.relativeToCwd = false; /* abs repo paths from fnc diff */ - opt.checkIgnoreGlobs = true; /* XXX make an 'fnc stash' opt */ - opt.callback = stash_get_add_cb; - rc = fsl_ckout_manage(f, &opt); - *nadded += opt.counts.added; - } - - rc0 = fsl_stmt_finalize(&loop); - return rc ? RC(rc, "fsl_ckout_manage") : rc0; -} - -static int -stash_get_rm_cb(fsl_ckout_unmanage_state const *st) -{ - f_out("[-] %s\n", st->filename); - return FSL_RC_OK; -} - -static int -stash_get_add_cb(fsl_ckout_manage_state const *cms, bool *include) -{ - *include = true; - f_out("[+] %s\n", cms->filename); - return FSL_RC_OK; -} - -/* - * Get hunks selected to stash from the user and make two patch(1) files: - * (1) diff of all hunks selected to stash; and (2) diff of all hunks to be - * kept in the checkout. Then revert the checkout and use patch files to: - * 1. apply patch of hunks selected to stash - * 2. stash (and revert) checkout - * 3. apply patch of hunks that were not selected to stash - * This produces a ckout with only those changes that were not selected - * to stash, achieving the same function as 'git add -p'. The user can - * now test the code, commit, then run 'fnc stash pop' and repeat. - */ -static int -fnc_stash(struct fnc_view *view) -{ - struct fnc_diff_view_state *s = &view->state.diff; - struct stash_cx *scx = &s->scx; - struct input in; - char *msg = NULL, *prompt = NULL; - int rc = FSL_RC_OK; - - scx->stash = alloc_bitstring(scx->hunk.n); - if (scx->stash == NULL) - return RC(FSL_RC_ERROR, "calloc"); - - rc = select_hunks(view); /* get hunks to stash */ - if (rc) - goto end; - - /* Use default stash msg of "fnc stash CKOUT-HASH" if not provided. */ - msg = fsl_mprintf("fnc stash %.11s", s->id2); - prompt = fsl_mprintf("stash message [%s]: ", msg); - in = (struct input){NULL, prompt, INPUT_ALPHA, SR_CLREOL}; - rc = fnc_prompt_input(view, &in); - if (in.buf[0]) { - fsl_free(msg); - msg = fsl_mprintf("%s", in.buf); - } - if (rc) { - rc = RC(rc, "fnc_prompt_input"); - goto end; - } - - s->stash = HUNK_STASH; /* make patch of hunks selected to stash */ - rc = create_diff(s); - s->stash = HUNK_CKOUT; /* make patch of hunks to keep in ckout */ - if (!rc) - rc = create_diff(s); - if (rc) - goto end; - - endwin(); /* restore tty so we can report progress to stdout */ - - /* Clean ckout to apply patches; vfile already scanned in cmd_stash() */ - rc = revert_ckout(true, false); - if (rc) { - rc = RC(rc, "revert_ckout"); - goto end; - } - - /* XXX With revert_ckout() finished, we can drop privileges further. */ - rc = init_unveil(((const char *[]){"/usr/bin/patch", "fossil"}), - ((const char *[]){"rx", "rx"}), 2, true); - if (rc) - goto end; - - scx->pcx.context = s->context; - scx->pcx.report = true; /* report files with changes stashed */ - rc = fnc_patch(&scx->pcx, scx->patch[0]); /* (1) apply stash patch */ - scx->pcx.report = false; /* don't report changes kept in ckout */ - if (!rc) { - /* fnc_execp((const char *const []) */ - /* {"fossil", "stash", "save", "-m", msg, (char *)NULL}, 10); */ - rc = f__stash_create(msg, fcli_cx()->ckout.rid); /* (2) */ - if (!rc) - rc = revert_ckout(false, false); - } - if (!rc) - rc = fnc_patch(&scx->pcx, scx->patch[1]); /* (3) ckout patch */ - rc = (rc == NO_PATCH ? FSL_RC_OK : rc); -end: - fsl_free(scx->stash); - fsl_free(scx->hunk.lineno); - fsl_free(msg); - fsl_free(prompt); - return rc; -} - -/* - * Allocate, zero, and return an unsigned char pointer of enough bytes - * to store n bits, which must eventually be disposed of by the caller. - */ -static unsigned char * -alloc_bitstring(size_t n) -{ - size_t idx; - unsigned char *bs; - - bs = (unsigned char *)calloc((size_t)nbytes(n), sizeof(unsigned char)); - - for (idx = 0; bs && idx < n; ++idx) - BIT_CLR(bs, idx); - - return bs; -} - -static int -select_hunks(struct fnc_view *view) -{ - int rc = FSL_RC_OK; - bool stashing = false; - - rc = stash_input_handler(view, &stashing); - - if (!rc && !stashing) - rc = RC(FSL_RC_BREAK, "No hunks selected to stash, " - "checkout state unchanged."); - - return rc; -} - -/* - * Iterate each hunk of changes in the local checkout, and prompt the user - * for their choice with: "stash this hunk (b,m,y,n,a,k,A,K,?)? [y]" - * b - scroll back (only available if hunk occupies previous page) - * m - show more (only available if hunk occupies following page) - * y - stash this hunk (default choice if [return] is pressed) - * n - do not stash this hunk - * a - stash this hunk and all remaining hunks in the _file_ - * k - do not stash this hunk nor any remaining hunks in the _file_ - * A - stash this hunk and all remaining hunks in the _diff_ - * K - do not stash this hunk nor any remaining hunks in the _diff_ - * ? - display stash help dialog box - * Key maps in the stash help dialog: - * q - quit the help - * Q - exit help and quit fnc stash _discarding_ any selections - * XXX This input handling and the set_choice() code is tricky! - */ -static int -stash_input_handler(struct fnc_view *view, bool *stashing) -{ - struct fnc_diff_view_state *s = &view->state.diff; - struct index *hunks; - struct input in; - size_t last, nxt = 0, nf = 0; - uint32_t *nh; - int hl, rc = FSL_RC_OK; - enum stash_opt choice = NO_CHOICE; - bool lastfile = false; - - hunks = &s->scx.hunk; - nh = &hunks->idx; - in = (struct input){NULL, NULL, INPUT_ALPHA, SR_CLREOL, "X"}; - - /* Iterate hunks and prompt user to stash or keep in ckout. */ - while (!rc && *nh < hunks->n) { - char **ans = NULL; - char prompt[64]; - int len; - enum { NONE, DOWN, UP, BOTH } scroll; - /* - * If not yet in the last file of the diff and the next hunk - * to choose is in the next file, reset any sticky file choice. - */ - if (!lastfile && nxt && hunks->lineno[*nh] >= nxt) { - nxt = 0; - *in.buf = 'X'; - choice = NO_CHOICE; - } - - /* - * Place hunk header, or file Index line if showing the - * first hunk in the file, at the top of the screen. - */ - s->first_line_onscreen = hunks->lineno[*nh] + 1; - if (s->dlines[hunks->lineno[*nh] - 5] == LINE_DIFF_INDEX) - s->first_line_onscreen = hunks->lineno[*nh] - 5; - s->selected_line = 1; - hl = s->first_line_onscreen; /* current hunk start line */ -redraw: - rc = view->show(view); - if (rc) - return rc; - updatescreen(view->window, true, true); - keypad(view->window, false); /* don't accept arrow keys */ - - last = s->last_line_onscreen; - len = snprintf(prompt, sizeof(prompt), - "[%u/%u] stash this hunk (", hunks->idx + 1, hunks->n); - if (len < 0 || (len > 0 && (size_t)len >= sizeof(prompt))) - return RC(fsl_errno_to_rc(errno, FSL_RC_RANGE), - "snprintf"); - scroll = NONE; - - /* Enable 'b,m' answers if hunk occupies multiple pages. */ - if (s->first_line_onscreen > hl) - scroll = UP; - if ((*nh < hunks->n - 1 && ((nf == s->index.n - 1 && - hunks->lineno[*nh] >= s->index.lineno[nf] + 5) || - last < s->index.lineno[nf]) && - last < hunks->lineno[*nh + 1]) || - (*nh == hunks->n - 1 && last < s->nlines)) - scroll = scroll ? BOTH : DOWN; - - rc = generate_prompt(&ans, prompt, sizeof(prompt), scroll); - if (rc) { - free_answers(ans); - return RC(rc, "generate_prompt(%s)", STRINGIFY(scroll)); - } - in.prompt = prompt; - - do { - if (choice || valid_input(in.buf, ans)) - break; /* ongoing persistent answer */ - - rc = fnc_prompt_input(view, &in); - - if (*in.buf == '?' || *in.buf == 'H' || - (int)*in.buf == (KEY_F(1))) - rc = stash_help(view, scroll); - - } while (!rc && !choice && !valid_input(in.buf, ans)); - - free_answers(ans); - if (*in.buf == 'm' || *in.buf == 'b') { /* scroll pgup/pgdn */ - s->first_line_onscreen = *in.buf == 'm' ? - s->last_line_onscreen : - MAX(hl, s->first_line_onscreen - view->nlines + 2); - *in.buf = 'X'; - goto redraw; - } - - set_choice(s, stashing, &in, hunks, nh, &nxt, &nf, &lastfile, - &choice); - } - return rc; -} - -/* - * Construct a set of valid answers based on scroll and assign to *ptr, and - * generate the corresponding prompt containing the available answers from - * which to choose. *ptr must eventually be disposed of by the caller. - */ -static int -generate_prompt(char ***ptr, char *prompt, size_t sz, short scroll) -{ - char **ans; - char *opts[10] = {"b", "m", "y", "n", "a", "k", "A", "K", "", NULL}; - size_t n, oi, ai = 0; - - /* Set valid answers. */ - switch (scroll) { - case 3: /* BOTH "bmynakAK?" */ - oi = 0; - n = 10; - break; - case 2: /* UP "bynakAK?" */ - opts[0] = "m"; - opts[1] = "b"; - /* FALL THROUGH */ - case 1: /* DOWN "mynakAK?" */ - oi = 1; - n = 9; - break; - case 0: /* NONE "ynakAK?" */ - oi = 2; - n = 8; - break; - } - - /* Generate valid answers array. */ - ans = calloc(n, sizeof(*ans)); - if (ans == NULL) - return RC(FSL_RC_ERROR, "calloc"); - while (ai < n) - ans[ai++] = fsl_strdup(opts[oi++]); - - /* Generate prompt string. */ - for (ai = 0; ai < n - 2; ++ai) { - char *t = fsl_mprintf("%s%c", ans[ai], ','); - if (t == NULL) - return RC(FSL_RC_ERROR, "fsl_mprintf"); - if (fsl_strlcat(prompt, t, sz) >= sz) - return RC(FSL_RC_RANGE, "fsl_strlcat(%s, %s, %lu)", - prompt, t, sz); - fsl_free(t); - } - if (fsl_strlcat(prompt, "?)? [y] ", sz) >= sz) - return RC(FSL_RC_RANGE, "fsl_strlcat(%s, %s, %lu)", - prompt, "?)? [y] ", sz); - - *ptr = ans; - return FSL_RC_OK;; -} - -/* - * Return true if in is found in valid, else return false. - * valid must be terminated with a sentinel (NULL) pointer. - */ -static bool -valid_input(const char *in, char **valid) -{ - size_t idx; - - for (idx = 0; valid[idx]; ++idx) - if (!fsl_strcmp(in, valid[idx])) - return true; - - return false; -} - -/* - * Set or clear the corresponding bit in bitstring s->scx.stash based on the - * answer in in.buf. If a persistent choice was made, assign it to *ch. Advance - * next file *nf in relation to next hunk *nh, and assign next file start line - * to *nxt. If the current file is the last file, set *lastfile. Advance *nh. - */ -static void -set_choice(struct fnc_diff_view_state *s, bool *stashing, struct input *in, - struct index *hunks, uint32_t *nh, size_t *nxt, size_t *nf, bool *lastfile, - enum stash_opt *ch) -{ - struct index *files; - unsigned char *bs; - - files = &s->index; - bs = s->scx.stash; - - /* Update bitstring based on ongoing persistent or single hunk choice */ - if (*in->buf != 'n' && *in->buf != 'k' && *in->buf != 'K') { - BIT_SET(bs, *nh); /* stash hunk */ - *stashing = true; - } else /* 'n' 'k' 'K' */ - BIT_CLR(bs, *nh); /* keep hunk in ckout */ - - /* Check for a new persistent choice. */ - if (*in->buf == 'a') - *ch = STASH_FILE; - else if (*in->buf == 'k') - *ch = KEEP_FILE; - else if (*in->buf == 'A') - *ch = STASH_DIFF; - else if (*in->buf == 'K') - *ch = KEEP_DIFF; - if (!*ch) - *in->buf = 'X'; /* no persistent choice; reset */ - - /* We're in the last file, so any persistent choice can stick */ - if (*nf == files->n - 1 && hunks->lineno[*nh] >= files->lineno[*nf]) - *lastfile = true; - - if ((*ch == STASH_FILE || *ch == KEEP_FILE) && - *in->buf != 'y' && *in->buf != 'n') { - *nxt = files->lineno[MIN(*nf + (*nf ? 0 : 1), files->n - 1)] + 5; - *in->buf = *ch == STASH_FILE ? 'y': 'n'; - } - - /* Update next file in relation to the next hunk. */ - while (*nf < files->n - 1 && *nh < hunks->n - 1 && - files->lineno[*nf] + 5 <= hunks->lineno[*nh + 1]) - ++(*nf); - - ++(*nh); -} - -static void -free_answers(char **ans) -{ - size_t i = 0; - - while (ans[i]) - fsl_free(ans[i++]); - fsl_free(ans); -} - -/* - * Revert the current checkout. If renames is set, don't revert files that are - * renamed with _no_ changes. If scan is set, scan for changes before reverting. - */ -static int -revert_ckout(bool renames, bool scan) -{ - fsl_cx *const f = fcli_cx(); - fsl_db *db = fsl_needs_ckout(f); - fsl_stmt q = fsl_stmt_empty; - fsl_ckout_revert_opt opt = fsl_ckout_revert_opt_empty; - fsl_id_bag idbag = fsl_id_bag_empty; - int rc = FSL_RC_OK; - - rc = fsl_ckout_vfile_ids(fcli.f, 0, &idbag, ".", false, true); - - if (!rc && renames) { - /* - * XXX Don't revert renamed files with _NO_ changes because - * we need to stash them, but there's no way to apply them - * with a diff as there's no hunks; however, we can apply our - * stash patch to the checkout with renames in the vfile. - */ - rc = fsl_db_prepare(db, &q, "SELECT id, origname, pathname" - " FROM vfile WHERE origname IS NOT NULL" - " AND origname<>pathname AND chnged=0"); - if (!rc) - rc = fsl_stmt_each(&q, rm_vfile_renames_cb, &idbag); - fsl_stmt_finalize(&q); - } - - opt.scanForChanges = scan; - opt.filename = NULL; - opt.callback = NULL; - opt.callbackState = NULL; - opt.vfileIds = &idbag; - if (!rc) - rc = fsl_ckout_revert(fcli_cx(), &opt); - - fsl_id_bag_clear(&idbag); - return rc; -} - -static int -rm_vfile_renames_cb(fsl_stmt *stmt, void *state) -{ - fsl_id_bag *bag = (fsl_id_bag *)state; - const char *ogname = fsl_stmt_g_text(stmt, 1, NULL); - const char *name = fsl_stmt_g_text(stmt, 2, NULL); - fsl_id_t id = fsl_stmt_g_id(stmt, 0); - - fsl_id_bag_remove(bag, id); - f_out("[s>] %s -> %s\n", ogname, name); - - return FSL_RC_OK; -} - -/* - * Scan patch(1) file found at path for valid patches, and populate patch - * context pcx with an fnc_patch_file queue of all diffed files, each - * containing an fnc_patch_hunk queue representing the file's changes. Iterate - * the file queue and apply each fnc_patch_file to the checkout. - */ -static int -fnc_patch(struct patch_cx *pcx, const char *path) -{ - struct fnc_patch_file *patch, *t; - FILE *fp; - int fd, rc = FSL_RC_OK; - - fd = open(path, O_RDONLY | O_CLOEXEC); - if (fd == -1) - return RC(fsl_errno_to_rc(errno, FSL_RC_IO), "open(%s)", path); - - if ((fp = fdopen(fd, "r")) == NULL) - return RC(fsl_errno_to_rc(errno, FSL_RC_IO), "fdopen"); - - pcx->report_cb = patch_reporter; - STAILQ_INIT(&pcx->head); /* queue of files to be patched */ - rc = scan_patch(pcx, fp); /* read patch file to construct patch ADTs */ - fclose(fp); - close(fd); - if (rc) - return rc; - - STAILQ_FOREACH_SAFE(patch, &pcx->head, entries, t) { - pcx->pf = patch; - rc = apply_patch(pcx, patch, false); - STAILQ_REMOVE(&pcx->head, patch, fnc_patch_file, entries); - free_patch(patch); - if (rc) - break; - } - - return rc; -} - -/* - * Scan patch file fp to construct an fnc_patch_file pf for each versioned - * file found with changes, and queue them in pcx->head. Parse each pf for - * valid hunks, and queue them in pf->head to produce a hierarchical ADT of - * files->hunks->lines to be patched. - */ -static int -scan_patch(struct patch_cx *pcx, FILE *fp) -{ - int rc = FSL_RC_OK; - bool eof = false, patch_found = false; - - while (!feof(fp)) { - struct fnc_patch_file *pf = NULL; - rc = find_patch_file(&pf, pcx, fp); - if (rc) { - fsl_free(pf); - goto end; - } - - STAILQ_INIT(&pf->head); /* queue of hunks per file to patch */ - patch_found = true; - for (;;) { - struct fnc_patch_hunk *h = NULL; - rc = parse_hunk(&h, fp, pcx->context, &eof); - if (rc) - goto end; - if (h) - STAILQ_INSERT_TAIL(&pf->head, h, entries); - if (eof) { - STAILQ_INSERT_TAIL(&pcx->head, pf, entries); - break; - } - } - } -end: - if (rc == NO_PATCH && patch_found) - rc = FSL_RC_OK; /* ignore valid case of index with no hunks */ - return rc; -} - -/* - * Find the next versioned file in patch(1) file fp by parsing the path from - * the diff ---/+++ header line. If found, construct and assign a new - * fnc_patch_file to *ptr, which must eventually be disposed of by the caller. - */ -static int -find_patch_file(struct fnc_patch_file **ptr, struct patch_cx *pcx, FILE *fp) -{ - struct fnc_patch_file *pf = NULL; - char *old = NULL, *new = NULL; - char *line = NULL; - size_t linesize = 0; - ssize_t linelen; - int create, rc = FSL_RC_OK; - - pf = calloc(1, sizeof(*pf)); - if (pf == NULL) - return RC(FSL_RC_ERROR, "fsl_malloc"); - - while ((linelen = getline(&line, &linesize, fp)) != -1) { - if (!strncmp(line, "--- ", 4)) { - fsl_free(old); - rc = parse_filename(line + 4, &old, 0); - } else if (!strncmp(line, "+++ ", 4)) { - fsl_free(new); - rc = parse_filename(line + 4, &new, 0); - } - - if (rc) - break; - - if (!strncmp(line, "@@ -", 4)) { - create = !fsl_strncmp(line + 4, "0,0", 3); - if ((old == NULL && new == NULL) || - (!create && old == NULL)) - rc = PATCH_MALFORMED; - else - rc = set_patch_paths(pf, old, new); - - if (rc) - break; - - /* Rewind to previous line. */ - if (fseek(fp, linelen * -1, SEEK_CUR) == -1) - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), - "fseek"); - break; - } - } - - if (!rc) - *ptr = pf; - - fsl_free(old); - fsl_free(new); - fsl_free(line); - - if (ferror(fp) && !rc) - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), "getline"); - if (feof(fp) && !rc) - rc = NO_PATCH; - - return rc; -} - -static int -parse_filename(const char *at, char **name, int strip) -{ - char *fullname, *t; - int l, tab, rc = FSL_RC_OK; - - *name = NULL; - if (*at == '\0') - return rc; - - while (isspace((unsigned char)*at)) - ++at; - - /* If path is /dev/null, file is being removed or created. */ - if (!fsl_strncmp(at, NULL_DEVICE, NULL_DEVICELEN)) - return rc; - - t = fsl_strdup(at); - if (t == NULL) - return RC(FSL_RC_ERROR, "fsl_strdup"); - *name = fullname = t; - tab = strchr(t, '\t') != NULL; - - /* Strip path components and NUL-terminate. */ - for (l = strip; - *t != '\0' && ((tab && *t != '\t') || !isspace((unsigned char)*t)); - ++t) { - if (t[0] == '/' && t[1] != '/' && t[1] != '\0') - if (--l >= 0) - *name = t + 1; - } - *t = '\0'; - - *name = fsl_strdup(*name); - fsl_free(fullname); - if (*name == NULL) - return RC(FSL_RC_ERROR, "fsl_strdup"); - - return rc; -} - -static int -set_patch_paths(struct fnc_patch_file *pf, const char *old, const char *new) -{ - int rc = FSL_RC_OK; - size_t ret = 0; - - /* Prefer the new name if it's neither /dev/null nor a renamed file. */ - if (new != NULL && old != NULL && !fsl_strcmp(new, old)) - ret = fsl_strlcpy(pf->old, new, sizeof(pf->old)); - else if (old != NULL) - ret = fsl_strlcpy(pf->old, old, sizeof(pf->old)); - if (ret >= sizeof(pf->old)) - rc = RC(FSL_RC_RANGE, "fsl_strlcpy"); - - if (!rc && new != NULL) - ret = fsl_strlcpy(pf->new, new, sizeof(pf->new)); - if (!rc && ret >= sizeof(pf->new)) - rc = RC(FSL_RC_RANGE, "fsl_strlcpy"); - - return rc; -} - -/* - * Parse patch(1) file fp and extract the changed lines data from each hunk - * header to construct an fnc_patch_hunk object and assign it to *ptr, which - * must eventually be dispoed of by the caller. Iterate the section of changed - * lines, and push each +/- and context line onto the hdr->lines array, which - * must also be disposed of by the caller. - */ -static int -parse_hunk(struct fnc_patch_hunk **ptr, FILE *fp, uint8_t context, bool *eof) -{ - struct fnc_patch_hunk *hdr = NULL; - char *line = NULL, ch; - size_t linesize = 0; - ssize_t linelen; - long leftold, leftnew; - int rc = FSL_RC_OK; - - linelen = getline(&line, &linesize, fp); - if (linelen == -1) { - *eof = true; /* end of this versioned file in the patch file */ - goto end; - } - - if ((hdr = calloc(1, sizeof(*hdr))) == NULL) { - rc = RC(FSL_RC_ERROR, "calloc"); - goto end; - } - - hdr->lines = NULL; - rc = parse_hdr(line, eof, hdr); - if (rc) - goto end; - - if (*eof) { - if (fseek(fp, linelen * -1, SEEK_CUR) == -1) - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), - "fseek"); - goto end; - } - - leftold = hdr->oldlines; - leftnew = hdr->newlines; - - while (leftold > 0 || leftnew > 0) { - linelen = getline(&line, &linesize, fp); - if (linelen == -1) { - if (ferror(fp)) { - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), - "getline"); - goto end; - } - - if (leftold < 3 && leftnew < 3) { - *eof = true; /* trim trailing newlines */ - break; - } - - rc = PATCH_TRUNCATED; - goto end; - } - if (line[linelen - 1] == '\n') - line[linelen - 1] = '\0'; - - ch = *line; - if (ch == '\t' || ch == '\0') - ch = ' '; /* leading space got eaten */ - - switch (ch) { - case '-': - leftold--; - break; - case ' ': - leftold--; - leftnew--; - break; - case '+': - leftnew--; - break; - default: - rc = PATCH_MALFORMED; - goto end; - } - - if (leftold < 0 || leftnew < 0) { - rc = PATCH_MALFORMED; - goto end; - } - - rc = pushline(hdr, line); - if (rc) - goto end; - - if ((ch == '-' && leftold == 0) || - (ch == '+' && leftnew == 0)) { - rc = peek_special_line(hdr, fp, ch == '+'); - if (rc) - goto end; - } - } -end: - /* - * XXX Check for hdr->lines as fnc diff adds a trailing empty newline - * between diffs (i.e., before the next file's Index line), which, if - * added, will produce a false negative in patch_file(). - */ - if (!rc && hdr && hdr->lines) - *ptr = hdr; - else - fsl_free(hdr); - fsl_free(line); - return rc; -} - -/* - * Parse hunk header line and assign corresponding new and old lines to - * hdr->{old,new}lines, respectively. - */ -static int -parse_hdr(char *s, bool *eof, struct fnc_patch_hunk *hdr) -{ - int rc = FSL_RC_OK; - - *eof = false; - if (fsl_strncmp(s, "@@ -", 4)) { - *eof = true; - return rc; - } - - s += 4; - if (!*s) - return rc; - - rc = strtolnum(&s, &hdr->oldfrom); - if (!rc && *s == ',') { - s++; - rc = strtolnum(&s, &hdr->oldlines); - } else - hdr->oldlines = 1; - if (rc) - return rc; - - if (*s == ' ') - ++s; - if (*s != '+' || !*++s) - return PATCH_MALFORMED; - - rc = strtolnum(&s, &hdr->newfrom); - if (!rc && *s == ',') { - s++; - rc = strtolnum(&s, &hdr->newlines); - } else - hdr->newlines = 1; - if (rc) - return rc; - - if (*s == ' ') - ++s; - if (*s != '@') - return PATCH_MALFORMED; - - if (hdr->oldfrom >= LONG_MAX - hdr->oldlines || - hdr->newfrom >= LONG_MAX - hdr->newlines || - hdr->oldlines >= LONG_MAX - hdr->newlines - 1) - rc = PATCH_MALFORMED; - - if (hdr->oldlines == 0) - hdr->oldfrom++; - - return rc; -} - -static int -strtolnum(char **str, int_least32_t *n) -{ - char *cmp, *p, c; - const char *errstr; -#ifdef __OpenBSD__ - cmp = NULL; /* strtonum() assigns last arg to NULL on success */ -#else - cmp = "\0"; /* strtol() assigns 2nd arg to NUL on success */ -#endif - - for (p = *str; isdigit((unsigned char)*p); ++p) - /* nop */; - - c = *p; - *p = '\0'; - - *n = strtonum(*str, 0, LONG_MAX, &errstr); - if ((errstr && *errstr != *cmp) || (!errstr && errstr != cmp)) - return PATCH_MALFORMED; - - *p = c; - *str = p; - return FSL_RC_OK; -} - -static int -pushline(struct fnc_patch_hunk *hdr, const char *line) -{ - static int rc = FSL_RC_OK; - char *p = NULL; - - if (*line != '+' && *line != '-' && *line != ' ' && *line != '\\') { - if ((p = fsl_mprintf(" %s", line)) == NULL) - return RC(FSL_RC_ERROR, "fsl_mprintf"); - line = p; - } - - rc = alloc_hunk_line(hdr, line); - - fsl_free(p); - return rc; -} - -static int -alloc_hunk_line(struct fnc_patch_hunk *h, const char *line) -{ - void *t; - size_t newcap; - - if (h->nlines == h->cap) { - if ((newcap = h->cap * 1.5) == 0) - newcap = 16; - t = fsl_realloc(h->lines, newcap * sizeof(char *)); - if (t == NULL) - return RC(FSL_RC_ERROR, "fsl_realloc"); - h->lines = t; - memset(h->lines + h->cap, 0, - sizeof(*h->lines) * (newcap - h->cap)); - h->cap = newcap; - } - - if ((t = fsl_strdup(line)) == NULL) - return RC(FSL_RC_ERROR, "fsl_strdup"); - - h->lines[h->nlines++] = t; - return FSL_RC_OK; -} - -static int -peek_special_line(struct fnc_patch_hunk *hdr, FILE *fp, - int send) -{ - int ch, rc = FSL_RC_OK; - - ch = fgetc(fp); - if (ch != EOF && ch != '\\') { - ungetc(ch, fp); - return rc; - } - - if (ch == '\\' && send) { - rc = pushline(hdr, "\\"); - if (rc) - return rc; - } - - while (ch != EOF && ch != '\n') - ch = fgetc(fp); - - if (ch != EOF || feof(fp)) - return rc; - return RC(FSL_RC_IO, "fgetc"); -} - -static int -apply_patch(struct patch_cx *pcx, struct fnc_patch_file *p, bool nop) -{ - const char *newpath, *oldpath; - char *parent = NULL, *tmppath = NULL, *template = NULL; - FILE *tmp = NULL; - int renamed = 0, rc = FSL_RC_OK; -#define DFLT_FILEMODE (S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) -#define DFLT_DIRMODE (S_IFDIR | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) - mode_t mode = DFLT_FILEMODE; - - newpath = p->new; - oldpath = p->old; - - if (oldpath[0]) - renamed = fsl_strcmp(oldpath, newpath); - - if ((template = fsl_mprintf("%sfnc-patch", - fcli_cx()->ckout.dir)) == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_mprintf"); - goto end; - } - - if (!nop) - rc = fnc_open_tmpfile(&tmppath, &tmp, template, NULL); - if (!rc) - rc = patch_file(p, oldpath, tmp, nop, &mode); - if (rc || nop) - goto end; - - if (p->old[0] && !p->new[0]) { /* file deleted */ - rc = fnc_rm_vfile(pcx, oldpath, false); - goto end; - } - - if (fchmod(fileno(tmp), mode) == -1) { - rc = RC(fsl_errno_to_rc(errno, FSL_RC_ACCESS), - "fchmod: %s %d", newpath, mode); - goto end; - } - - fclose(tmp); - - if (rename(tmppath, newpath) == -1) { - if (errno != ENOENT) { - rc = RC(fsl_errno_to_rc(errno, FSL_RC_ACCESS), - "rename(%s, %s)", tmppath, newpath); - goto end; - } - - rc = fsl_mkdir_for_file(newpath, true); - if (rc || rename(tmppath, newpath) == -1) { - rc = RC(fsl_errno_to_rc(errno, FSL_RC_ACCESS), - "rename(%s, %s)", tmppath, newpath); - goto end; - } - } - - if (renamed) { - /* - * XXX Removing the original name versioned file and adding - * the renamed version produces a verbose diff with "duplicate" - * entries showing the entire file contents of the previous - * name versioned file deleted, and the entire file contents, - * including any edits, added under the new name. This makes it - * difficult to discern changes. By performing a rename in the - * vfile table, we get a more useful diff with rename context. - */ - /* rc = fnc_rm_vfile(pcx, oldpath, false); */ - /* if (!rc) */ - /* rc = fnc_add_vfile(pcx, newpath, false); */ - rc = fnc_rename_vfile(oldpath, newpath); - if (!rc && pcx->report) - rc = patch_reporter(p, oldpath, newpath, "~"); - } else if (!p->old[0]) { /* file added */ - rc = fnc_add_vfile(pcx, newpath, false); - /* rc = fnc_execp((const char *const []) */ - /* {"fossil", "add", newpath, (char *)NULL}, 10); */ - } else if (pcx->report) - rc = patch_reporter(p, oldpath, newpath, "~"); -end: - fsl_free(parent); - fsl_free(template); - if (tmppath != NULL) - unlink(tmppath); - fsl_free(tmppath); - return rc; -} - -/* - * Open new tmp file at basepath, which is expected to be an absolute path, - * with optional suffix. The final filename will be "basepath-XXXXXX[SUFFIX]" - * where XXXXXX is a random character string populated by mkstemp(3) (or - * mkstemps(3) if suffix is not NULL). - */ -static int -fnc_open_tmpfile(char **path, FILE **outfile, const char *basepath, - const char *suffix) -{ - int fd, rc = FSL_RC_OK; - - *outfile = NULL; - - if ((*path = fsl_mprintf("%s-XXXXXX%s", basepath, - suffix ? suffix : "")) == NULL) - return RC(FSL_RC_ERROR, "fsl_mprintf"); - - if (suffix) - fd = mkstemps(*path, fsl_strlen(suffix)); - else - fd = mkstemp(*path); - if (fd == -1) { - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), "%s(%s)", - suffix ? "mkstemps" : "mkstemp", *path); - fsl_free(*path); - *path = NULL; - return rc; - } - - *outfile = fdopen(fd, "w+"); - if (*outfile == NULL) { - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), "fdopen: %s", *path); - fsl_free(*path); - *path = NULL; - } - - return rc; -} - -/* - * Apply patch file p to the versioned file at path by iterating and applying - * each hunk from p->head and creating thepatched file in tmp. Upon success, - * copy to the versioned file at path. - */ -static int -patch_file(struct fnc_patch_file *p, const char *path, FILE *tmp, int nop, - mode_t *mode) -{ - struct fnc_patch_hunk *h; - struct stat sb; - FILE *orig; - char *line = NULL; - off_t copypos, pos; - ssize_t linelen; - size_t linesize = 0; - long lineno = 0; - int rc = FSL_RC_OK; - - if (!p->old[0]) { /* create new versioned file */ - h = STAILQ_FIRST(&p->head); - if (h == NULL || STAILQ_NEXT(h, entries) != NULL) - return PATCH_MALFORMED; - if (nop) - return rc; - return apply_hunk(tmp, h, &lineno); - } - - if ((orig = fopen(path, "r")) == NULL) { - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), - "fopen(%s, \"r\")", path); - goto end; - } - - if (fstat(fileno(orig), &sb) == -1) { - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), "fstat(%s)", path); - goto end; - } - *mode = sb.st_mode; - - copypos = 0; - STAILQ_FOREACH(h, &p->head, entries) { - if (h->lines == NULL) - break; - - retry: - rc = locate_hunk(orig, h, &pos, &lineno); - if (rc && rc == HUNK_FAILED) - h->rc = rc; - if (rc) - goto end; - if (!nop) - rc = copyfile(tmp, orig, copypos, pos); - if (rc) - goto end; - copypos = pos; - - rc = test_hunk(orig, h); - if (rc && rc == HUNK_FAILED) { - /* - * Retry applying the hunk by starting the search - * after the previous partial match. - */ - if (fseek(orig, pos, SEEK_SET) == -1) { - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), - "fseek"); - goto end; - } - linelen = getline(&line, &linesize, orig); - if (linelen == -1) { - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), - "getline"); - goto end; - } - ++lineno; - goto retry; - } - if (rc) - goto end; - - if (lineno + 1 != h->oldfrom) - h->offset = lineno + 1 - h->oldfrom; - - if (!nop) - rc = apply_hunk(tmp, h, &lineno); - if (rc) - goto end; - - copypos = ftello(orig); - if (copypos == -1) { - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), "ftello"); - goto end; - } - } - - if (!p->new[0] && sb.st_size != copypos) { - h = STAILQ_FIRST(&p->head); - rc = h->rc = HUNK_FAILED; - } else if (!nop && !feof(orig)) /* success! copy to versioned file */ - rc = copyfile(tmp, orig, copypos, -1); -end: - if (orig != NULL) - fclose(orig); - return rc; -} - -static int -apply_hunk(FILE *tmp, struct fnc_patch_hunk *h, long *lineno) -{ - size_t i = 0; - - for (i = 0; i < h->nlines; ++i) { - switch (*h->lines[i]) { - case ' ': - if (fprintf(tmp, "%s\n", h->lines[i] + 1) < 0) - return RC(fsl_errno_to_rc(errno, FSL_RC_IO), - "fprintf"); - /* fallthrough */ - case '-': - (*lineno)++; - break; - case '+': - if (fprintf(tmp, "%s", h->lines[i] + 1) < 0) - return RC(fsl_errno_to_rc(errno, FSL_RC_IO), - "fprintf"); - if (i != h->nlines - 1 || !h->nonl) { - if (fprintf(tmp, "\n") < 0) - return RC(fsl_errno_to_rc(errno, - FSL_RC_IO), "fprintf"); - } - break; - } - } - return FSL_RC_OK; -} - -static int -locate_hunk(FILE *orig, struct fnc_patch_hunk *h, off_t *pos, long *lineno) -{ - char *line = NULL; - char mode = *h->lines[0]; - ssize_t linelen; - size_t linesize = 0; - off_t match = -1; - long match_lineno = -1; - int rc = FSL_RC_OK; - - for (;;) { - linelen = getline(&line, &linesize, orig); - if (linelen == -1) { - if (ferror(orig)) - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), - "getline"); - else if (match == -1) - rc = HUNK_FAILED; - break; - } - if (line[linelen - 1] == '\n') - line[linelen - 1] = '\0'; - (*lineno)++; - - if ((mode == ' ' && !fsl_strcmp(h->lines[0] + 1, line)) || - (mode == '-' && !fsl_strcmp(h->lines[0] + 1, line)) || - (mode == '+' && *lineno == h->oldfrom)) { - match = ftello(orig); - if (match == -1) { - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), - "ftello"); - break; - } - match -= linelen; - match_lineno = (*lineno) - 1; - } - - if (*lineno >= h->oldfrom && match != -1) - break; - } - - if (!rc) { - *pos = match; - *lineno = match_lineno; - if (fseek(orig, match, SEEK_SET) == -1) - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), "fseek"); - } - - fsl_free(line); - return rc; -} - -/* - * Starting at copypos until pos, copy data from orig into tmp. - * If pos is -1, copy until EOF. - */ -static int -copyfile(FILE *tmp, FILE *orig, off_t copypos, off_t pos) -{ - char buf[BUFSIZ]; - size_t len, r, w; - - if (fseek(orig, copypos, SEEK_SET) == -1) - return RC(fsl_errno_to_rc(errno, FSL_RC_IO), "fseek"); - - while (pos == -1 || copypos < pos) { - len = sizeof(buf); - if (pos > 0) - len = MIN(len, (size_t)pos - copypos); - r = fread(buf, 1, len, orig); - if (r != len && ferror(orig)) - return RC(fsl_errno_to_rc(errno, FSL_RC_IO), "fread"); - w = fwrite(buf, 1, r, tmp); - if (w != r) - return RC(fsl_errno_to_rc(errno, FSL_RC_IO), "fwrite"); - copypos += len; - if (r != len && feof(orig)) { - if (pos == -1) - return FSL_RC_OK; - return HUNK_FAILED; - } - } - return FSL_RC_OK; -} - -static int -test_hunk(FILE *orig, struct fnc_patch_hunk *h) -{ - char *line = NULL; - ssize_t linelen; - size_t linesize = 0, i = 0; - int rc = FSL_RC_OK; - - for (i = 0; i < h->nlines; ++i) { - switch (*h->lines[i]) { - case '+': - continue; - case ' ': - case '-': - linelen = getline(&line, &linesize, orig); - if (linelen == -1) { - if (ferror(orig)) - rc = RC(fsl_errno_to_rc(errno, - FSL_RC_IO), "getline"); - else - rc = HUNK_FAILED; - goto end; - } - if (line[linelen - 1] == '\n') - line[linelen - 1] = '\0'; - if (fsl_strcmp(h->lines[i] + 1, line)) { - rc = HUNK_FAILED; - goto end; - } - break; - } - } -end: - fsl_free(line); - return rc; -} - -static int -fnc_add_vfile(struct patch_cx *pcx, const char *path, bool nop) -{ - fsl_cx *const f = fcli_cx(); - fsl_db *db; - fsl_ckout_manage_opt opt = fsl_ckout_manage_opt_empty; - int rc = FSL_RC_OK; - bool trans = false; - - db = fsl_needs_ckout(f); - if (!db) - goto end; - - rc = fsl_db_transaction_begin(db); - if (rc) { - fsl_cx_uplift_db_error(f, db); - goto end; - } - trans = true; - - opt.filename = path; - opt.relativeToCwd = false; /* relative repo root paths from fnc diff */ - opt.checkIgnoreGlobs = true; /* XXX make an 'fnc stash' option? */ - opt.callbackState = pcx; /* patch context and report cb */ - opt.callback = fnc_addvfile_cb; - rc = fsl_ckout_manage(f, &opt); - if (rc) - goto end; - - if (nop) { - f_out("dry run...rolling back transaction.\n"); - fsl_db_transaction_rollback(db); - } else - rc = fsl_db_transaction_end(db, false); - trans = false; -end: - if (trans) { - const int rc2 = fsl_db_transaction_end(db, true); - rc = rc ? rc : rc2; - } - return rc; -} - -static int -fnc_addvfile_cb(fsl_ckout_manage_state const *cx, bool *include) -{ - struct patch_cx *pcx = cx->opt->callbackState; - int rc = FSL_RC_OK; - - if (pcx->report) - rc = pcx->report_cb(pcx->pf, pcx->pf->old, pcx->pf->new, "+"); - if (!rc) - *include = true; - - return rc; -} - -static int -fnc_rm_vfile(struct patch_cx *pcx, const char *path, bool nop) -{ - fsl_cx *const f = fcli_cx(); - fsl_db *db; - fsl_ckout_unmanage_opt opt = fsl_ckout_unmanage_opt_empty; - int rc = FSL_RC_OK; - bool trans = false; - - db = fsl_cx_db_ckout(f); - if (!db) { - rc = fsl_cx_err_set(f, FSL_RC_NOT_A_CKOUT, "ckout required"); - goto end; - } - - rc = fsl_cx_transaction_begin(f); - if (rc) - goto end; - trans = true; - - opt.filename = path; - opt.scanForChanges = false; - opt.vfileIds = NULL; - opt.relativeToCwd = false; /* relative repo root paths from fnc diff */ - opt.callback = fnc_rmvfile_cb; - opt.callbackState = pcx; - rc = fsl_ckout_unmanage(f, &opt); - if (rc) - goto end; - - if (nop) { - f_out("dry run...rolling back transaction.\n"); - fsl_db_transaction_rollback(db); - } else - rc = fsl_db_transaction_end(db, false); - trans = false; -end: - if (trans) { - const int rc2 = fsl_db_transaction_end(db, true); - rc = rc ? rc : rc2; - } - return rc; -} - -static int -fnc_rmvfile_cb(fsl_ckout_unmanage_state const *cx) -{ - struct patch_cx *pcx = cx->opt->callbackState; - int rc = FSL_RC_OK; - - if (pcx->report) - rc = pcx->report_cb(pcx->pf, pcx->pf->old, pcx->pf->new, "-"); - - return rc; -} - -static int -fnc_rename_vfile(const char *oldpath, const char *newpath) -{ - fsl_cx *const f = fcli_cx(); - fsl_db *db = fsl_needs_ckout(f); - int rc = FSL_RC_OK; - - rc = fsl_db_exec_multi(db, - "UPDATE vfile SET pathname='%q', origname='%q'" - " WHERE pathname='%q' %s AND vid=%d", newpath, oldpath, - oldpath, fsl_cx_filename_collation(f), f->ckout.rid); - if (rc) - fsl_file_unlink(newpath); - else { - const char *dir = getdirname(oldpath, -1, false); - rc = fsl_file_unlink(oldpath); - if (!fsl_dir_is_empty(dir)) - rc = fsl_rmdir(dir); - } - - return rc; -} - -static int -patch_reporter(struct fnc_patch_file *p, const char *old, const char *new, - char *status) -{ - struct fnc_patch_hunk *h; - int rc = FSL_RC_OK; - - rc = patch_report(old, new, status, 0, 0, 0, 0, 0, 0); - if (rc) - return rc; - - STAILQ_FOREACH(h, &p->head, entries) { - if (h->offset == 0 && !h->rc) - continue; - - rc = patch_report(old, new, 0, h->oldfrom, h->oldlines, - h->newfrom, h->newlines, h->offset, h->rc); - } - - return rc; -} - -static int -patch_report(const char *old, const char *new, char *status, - long oldfrom, long oldlines, long newfrom, long newlines, long offset, - enum fnc_patch_rc hunkrc) -{ - const char *path = !new[0] ? old : new; - - while (*path == '/') - path++; - - if (old[0] && new[0] && fsl_strcmp(old, new)) - printf("[s%s] %s -> %s\n", status, old, new); - else - printf("[s%s] %s\n", status, path); - - if (offset != 0 || hunkrc) { - printf("@@ -%ld,%ld +%ld,%ld @@ ", oldfrom, - oldlines, newfrom, newlines); - if (hunkrc) - printf("error %d: %s\n", hunkrc, STRINGIFY(hunkrc)); - else - printf("applied with offset %ld\n", offset); - } - fflush(stdout); - - return FSL_RC_OK; -} - -static void -free_patch(struct fnc_patch_file *p) -{ - struct fnc_patch_hunk *h; - size_t i; - - while (!STAILQ_EMPTY(&p->head)) { - h = STAILQ_FIRST(&p->head); - STAILQ_REMOVE_HEAD(&p->head, entries); - - for (i = 0; i < h->nlines; ++i) { - fsl_free(h->lines[i]); - h->lines[i] = NULL; - } - fsl_free(h->lines); - fsl_free(h); - h = NULL; - } - fsl_free(p); -} - -/* - * exec(2) arg[0] with args arg after a fork(2). Optionally wait wait seconds - * for child process to complete; set to zero or a negative integer to not wait. - */ -#if 0 -static int -fnc_execp(const char *const *arg, const int wait) -{ - pid_t pid; - int status, timeout, rc = FSL_RC_OK; - - pid = fork(); - if (pid == -1) - return RC(fsl_errno_to_rc(errno, FSL_RC_ACCESS), "fork"); - else if (pid == 0) - if (execvp(arg[0], (char *const *)arg) == -1) - return RC(fsl_errno_to_rc(errno, FSL_RC_ACCESS), - "ecexve"); - - if (wait < 1) - return rc; - - timeout = wait; - - while (waitpid(pid , &status , WNOHANG) == 0) { - if ( --timeout < 0 ) - return RC(FSL_RC_RANGE, "timeout for child [%d]", pid); - sleep(1); - } - - if (WIFEXITED(status) != 1 || WEXITSTATUS(status) != 0) - return RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), - "%s: WEXITSTATUS %d | WIFEXITED %d [status %d]", arg[0], - WEXITSTATUS(status), WIFEXITED(status), status); - - return rc; -} -#endif - -/* - * Create new stash of changes in checkout vid with stash message msg. - */ -static int -f__stash_create(const char *msg, int vid) -{ - fsl_cx *const f = fcli_cx(); - fsl_db *db = fsl_needs_ckout(f); - int stashid, rc = FSL_RC_OK; - - rc = f__check_stash_tables(); - if (rc) - return RC(rc, "check_stash_tables"); - - stashid = fsl_config_get_int32(f, FSL_CONFDB_CKOUT, 1, "stash-next"); - rc = fsl_config_set_id(f, FSL_CONFDB_CKOUT, "stash-next", stashid + 1); - if (!rc) - rc = fsl_ckout_changes_scan(f); - if (rc) - return rc; - - fsl_db_exec_multi(db, - "INSERT INTO stash(stashid, vid, hash, comment, ctime)" - " VALUES(%d, %d, (SELECT uuid FROM blob WHERE rid = %d)," - " %Q, julianday('now'))", stashid, vid, vid, msg); - - rc = f__stash_path(stashid, vid, "."); - - return rc; -} - -/* - * Check checkout database for up-to-date stash and stashfile tables. Create - * or upgrade if needed. - */ -static int -f__check_stash_tables(void) -{ - static const char stashtab[] = - "CREATE TABLE IF NOT EXISTS stash(\n" - " stashid INTEGER PRIMARY KEY, -- Unique stash identifier\n" - " vid INTEGER, -- Legacy baseline RID value. Do not use.\n" - " hash TEXT, -- The SHA hash for the baseline\n" - " comment TEXT, -- Comment for this stash. Or NULL\n" - " ctime TIMESTAMP -- When the stash was created\n" - ");\n" - "CREATE TABLE IF NOT EXISTS stashfile(\n" - " stashid INTEGER REFERENCES stash, -- Stash containing this file\n" - " isAdded BOOLEAN, -- True if this file is added\n" - " isRemoved BOOLEAN, -- True if this file is deleted\n" - " isExec BOOLEAN, -- True if file is executable\n" - " isLink BOOLEAN, -- True if file is a symlink\n" - " rid INTEGER, -- Legacy baseline RID value. Do not use\n" - " hash TEXT, -- Hash for baseline or NULL\n" - " origname TEXT, -- Original filename\n" - " newname TEXT, -- New name for file at next check-in\n" - " delta BLOB, -- Delta from baseline or raw content\n" - " PRIMARY KEY(newname, stashid)\n" - ");\n" - "INSERT OR IGNORE INTO vvar(name,value) VALUES('stash-next',1);\n"; - fsl_cx *const f = fcli_cx(); - fsl_db *db = fsl_needs_ckout(f); - int rc = FSL_RC_OK; - - if (fsl_db_table_has_column(db, "stashfile", "hash")) { - /* - * Schema is up-to-date, but an older version of Fossil that - * doesn't know about the stash.hash and stashfile.hash columns - * may have run since the schema was updated, and added entries - * with NULL hash columns. Check for this case, and input any - * missing hash values. - */ - if (fsl_db_g_int32(db, 0, "SELECT hash IS NULL FROM stash " - "ORDER BY stashid DESC LIMIT 1")) { - rc = fsl_db_exec_multi(db, "UPDATE stash" - " SET hash=(SELECT uuid FROM blob" - " WHERE blob.rid=stash.vid)" - " WHERE hash IS NULL;" - "UPDATE stashfile" - " SET hash=(SELECT uuid FROM blob" - " WHERE blob.rid=stashfile.rid)" - " WHERE hash IS NULL AND rid>0;"); - } - return rc; - } - - if (!fsl_db_table_exists(db, FSL_DBROLE_CKOUT, "stashfile") || - !fsl_db_table_exists(db, FSL_DBROLE_CKOUT, "stash")) { - /* Tables don't exist; create them from scratch. */ - rc = fsl_db_exec(db, "DROP TABLE IF EXISTS stash;"); - if (!rc) - rc = fsl_db_exec(db, "DROP TABLE IF EXISTS stashfile;"); - if (!rc) - rc = fsl_db_exec_multi(db, stashtab); - return rc; - } - - /* - * Tables exist but aren't necessarily current. Upgrade to the latest - * format. Assume the 2011-09-01 format that includes the column - * stashfile.isLink. Upgrade the PRIMARY KEY change on 2016-10-16 and - * the addition of the "hash" columns on 2019-01-19. - */ - rc = fsl_db_exec_multi(db, - "ALTER TABLE stash RENAME TO old_stash;" - "ALTER TABLE stashfile RENAME TO old_stashfile;"); - if (!rc) - rc = fsl_db_exec_multi(db, stashtab); - if (!rc) - rc = fsl_db_exec_multi(db, - "INSERT INTO stash(stashid,vid,hash,comment,ctime)" - " SELECT stashid, vid," - " (SELECT uuid FROM blob WHERE blob.rid=old_stash.vid)," - " comment, ctime FROM old_stash; " - "DROP TABLE old_stash;"); - if (!rc) - rc = fsl_db_exec_multi(db, - "INSERT INTO stashfile(stashid, isAdded, isRemoved," - " isExec, isLink, rid, hash, origname, newname, delta)" - " SELECT stashid, isAdded, isRemoved, isExec, isLink, rid," - " (SELECT uuid FROM blob WHERE blob.rid=old_stashfile.rid)," - " origname, newname, delta FROM old_stashfile; " - "DROP TABLE old_stashfile;"); - - return rc; -} - -/* - * Add file(s) at path to the stash changeset identified by stashid based on - * checkout vid. If path is a directory, all files in that dir will be added. - * If path is ".", the entire checkout will be stashed from the repository root. - */ -static int -f__stash_path(int stashid, int vid, const char *path) -{ - fsl_cx *const f = fcli_cx(); - fsl_db *db = fsl_needs_ckout(f); - fsl_buffer sql = fsl_buffer_empty; /* query statement */ - fsl_stmt q = fsl_stmt_empty; /* vfile statement */ - fsl_stmt ins = fsl_stmt_empty; /* insert statement */ - int rc = FSL_RC_OK; - - rc = fsl_buffer_appendf(&sql, - "SELECT deleted, isexe, islink, mrid, pathname," - " coalesce(origname,pathname)" - " FROM vfile WHERE vid=%d AND (chnged OR deleted OR" - " (origname IS NOT NULL AND origname<>pathname) OR mrid==0)", - vid); - if (!rc && fsl_strcmp(path, ".")) { /* specific file provided */ - rc = fsl_buffer_appendf(&sql, - " AND (pathname GLOB '%q/*' OR origname GLOB '%q/*'" - " OR pathname=%Q OR origname=%Q)", path, path, path, path); - } - if (rc) - return RC(rc, "fsl_buffer_appendf"); - - fsl_simplify_sql_buffer(&sql); - rc = fsl_db_prepare(db, &q, "%s", fsl_buffer_str(&sql)); - fsl_buffer_clear(&sql); - if (rc) - return RC(rc, "fsl_db_prepare(%s): %d", "stash query", vid); - - rc = fsl_db_prepare(db, &ins, - "INSERT INTO stashfile(stashid, isAdded, isRemoved, isExec, isLink," - " rid, hash, origname, newname, delta)" - "VALUES(%d,:isadd,:isrm,:isexe,:islink,:rid," - "(SELECT uuid FROM blob WHERE rid=:rid),:orig,:new,:content)", - stashid); - if (rc) - return RC(rc, "fsl_db_prepare(%s): %d", "stash insert", stashid); - - while (fsl_stmt_step(&q) == FSL_RC_STEP_ROW) { - fsl_buffer content = fsl_buffer_empty; - char path[PATH_MAX]; - int deleted = fsl_stmt_g_int32(&q, 0); - int rid = fsl_stmt_g_int32(&q, 3); - const char *name = fsl_stmt_g_text(&q, 4, NULL); - const char *ogname = fsl_stmt_g_text(&q, 5, NULL); - - fsl_strlcpy(path, CKOUTDIR, sizeof(path)); - fsl_strlcat(path, name, sizeof(path)); - - rc = fsl_stmt_bind_int32_name(&ins, ":rid", rid); - if (!rc) - rc = fsl_stmt_bind_int32_name(&ins, ":isadd", rid==0); - if (!rc) - rc = fsl_stmt_bind_int32_name(&ins, ":isrm", deleted); - if (!rc) - rc = fsl_stmt_bind_int32_name(&ins, ":isexe", - fsl_stmt_g_int32(&q, 1)); - if (!rc) - rc = fsl_stmt_bind_int32_name(&ins, ":islink", - fsl_stmt_g_int32(&q, 2)); - if (rc) { - rc = RC(rc, "fsl_stmt_bind_int32_name"); - goto end; - } - - rc = fsl_stmt_bind_text_name(&ins, ":orig", ogname, -1, false); - if (!rc) - rc = fsl_stmt_bind_text_name(&ins, ":new", name, -1, - false); - if (rc) { - rc = RC(rc, "fsl_stmt_bind_text_name"); - goto end; - } - - if (!rid) { /* new file */ - rc = fsl_buffer_fill_from_filename(&content, path); - if (rc) { - rc = RC(rc, "fsl_buffer_fill_from_filename(%s)", - path); - goto end; - } - rc = fsl_stmt_bind_blob_name(&ins, ":content", - content.mem, content.used, false); - if (rc) { - rc = RC(rc, "fsl_stmt_bind_blob_name"); - goto clear_delta; - } - } else if (deleted) { - fsl_buffer_clear(&content); - rc = fsl_stmt_bind_null_name(&ins, ":content"); - if (rc) { - rc = RC(rc, "fsl_stmt_bind_null_name"); - goto end; - } - } else { /* modified file */ - fsl_buffer orig = fsl_buffer_empty; - fsl_buffer disk = fsl_buffer_empty; - - rc = fsl_buffer_fill_from_filename(&disk, path); - if (rc) { - rc = RC(rc, "fsl_buffer_fill_from_filename(%s)", - path); - goto end; - } - rc = fsl_content_get(f, rid, &orig); - if (rc) { - rc = RC(rc, "fsl_content_get(%d)", rid); - goto clear_file; - } - rc = fsl_buffer_delta_create(&orig, &disk, &content); - if (rc) { - rc = RC(rc, "fsl_buffer_delta_create"); - goto clear_file; - } - rc = fsl_stmt_bind_blob_name(&ins, ":content", - content.mem, content.used, false); - if (rc) - rc = RC(rc, "fsl_stmt_bind_blob_name"); -clear_file: - fsl_buffer_clear(&orig); - fsl_buffer_clear(&disk); - } - if (rc) - goto clear_delta; - rc = fsl_stmt_bind_int32_name(&ins, ":islink", - fsl_is_symlink(path)); - if (rc) - rc = RC(rc, "fsl_stmt_bind_int32_name"); - else { - fsl_stmt_step(&ins); - fsl_stmt_reset(&ins); - } -clear_delta: - fsl_buffer_clear(&content); - if (rc) - goto end; - } -end: - fsl_stmt_finalize(&ins); - fsl_stmt_finalize(&q); - return rc; -} - static int reset_diff_view(struct fnc_view *view, bool stay) { struct fnc_diff_view_state *s = &view->state.diff; int n, rc = FSL_RC_OK; n = s->nlines; + free_index(&s->index); + fsl_free(s->dlines); + s->dlines = NULL; + s->ndlines = 0; show_diff_status(view); rc = create_diff(s); if (rc) return rc; @@ -8929,11 +6425,11 @@ set_selected_commit(struct fnc_diff_view_state *s, struct commit_entry *entry) { fsl_free(s->id2); s->id2 = fsl_strdup(entry->commit->uuid); if (s->id2 == NULL) - return RC(FSL_RC_ERROR, "fsl_strdup"); + return RC(FSL_RC_ERROR, "%s", "fsl_strdup"); fsl_free(s->id1); s->id1 = entry->commit->puuid ? fsl_strdup(entry->commit->puuid) : NULL; s->selected_entry = entry->commit; return 0; @@ -8996,11 +6492,12 @@ } offset = line_offsets[lineno - 1]; if (fseeko(f, offset, SEEK_SET) != 0) { fsl_free(line); - return RC(fsl_errno_to_rc(errno, FSL_RC_IO), "fseeko"); + return RC(fsl_errno_to_rc(errno, FSL_RC_IO), + "%s", "fseeko"); } /* Expand tabs for accurate rm_so/rm_eo offsets. */ linelen = getline(&line, &linesz, f); expand_tab(&exstr, line, linelen); if (linelen != -1 && regexec(&view->regex, exstr, 1, @@ -9083,11 +6580,11 @@ { struct fnc_diff_view_state *s = &view->state.diff; int rc = 0; if (s->f && fclose(s->f) == EOF) - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), "fclose"); + rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), "%s", "fclose"); fsl_free(s->id1); s->id1 = NULL; fsl_free(s->id2); s->id2 = NULL; fsl_free(s->line_offsets); @@ -9151,15 +6648,13 @@ } resize_term(lines, cols); } static int -view_resize(struct fnc_view *view, bool split) +view_resize(struct fnc_view *view, enum view_mode mode) { - int dif, nlines, ncols, rc = FSL_RC_OK; - - dif = LINES - view->lines; /* if resized, what's the line difference? */ + int nlines, ncols, rc = FSL_RC_OK; if (view->lines > LINES) nlines = view->nlines - (view->lines - LINES); else nlines = view->nlines + (LINES - view->lines); @@ -9168,21 +6663,21 @@ ncols = view->ncols - (view->cols - COLS); else ncols = view->ncols + (COLS - view->cols); if (wresize(view->window, nlines, ncols) == ERR) - /* recover by clearing and redrawing */; + return RC(FSL_RC_ERROR, "%s", "wresize"); if (replace_panel(view->panel, view->window) == ERR) - return RC(FSL_RC_ERROR, "replace_panel"); + return RC(FSL_RC_ERROR, "%s", "replace_panel"); wclear(view->window); view->nlines = nlines; view->ncols = ncols; view->lines = LINES; view->cols = COLS; - if (view->child) { + if (view->child && mode != VIEW_SPLIT_NONE) { view->child->start_col = view_split_start_col(view->start_col); if (view->mode == VIEW_SPLIT_HRZN || !view->child->start_col) { rc = make_fullscreen(view->child); if (view->child->active) show_panel(view->child->panel); @@ -9190,36 +6685,12 @@ show_panel(view->panel); } else { rc = make_splitscreen(view->child); show_panel(view->child->panel); } - /* - * If the terminal has been resized and it's a timeline view, - * and there aren't enough commits loaded to populate the view, - * request more commits now for the next screen redraw. - */ - if (view->vid == FNC_VIEW_TIMELINE && dif) { - struct fnc_tl_view_state *ts = &view->state.timeline; - if (ts->commits.ncommits < ts->selected_entry->idx + - view->lines - ts->selected) { - ts->nscrolled = ts->selected_entry->idx + - view->lines - ts->selected - - ts->commits.ncommits + ABS(dif); - rc = request_tl_commits(view); - } - } - /* - * If the terminal was resized with a horizontal split, for - * some reason unbeknownst to me, we need to reset the split - * screen dimensions now else it'll render a fullscreen view. - * XXX Delete this to force fullscreen when resizing a hsplit. - */ - if (!rc && split) { - rc = make_splitscreen(view->child); - show_panel(view->child->panel); - } - } + } + return rc; } /* * Consume repeatable arguments containing artifact type values used in @@ -9233,11 +6704,11 @@ { struct artifact_types *ft = &fnc_init.filter_types; const char *t = *((const char **)v->flagValue); /* Valid types: ci, e, f, g, t, w */ - if (strlen(t) > 2 || (t[1] && (*t != 'c' || t[1] != 'i')) || (!t[1] && + if (t[2] || (t[1] && (*t != 'c' || t[1] != 'i')) || (!t[1] && (*t != 'e' && *t != 'f' && *t != 'g' && *t != 't' && *t != 'w'))) { fnc_init.err = RC(FSL_RC_TYPE, "invalid type: %s", t); usage(); /* NOT REACHED */ } @@ -9294,22 +6765,19 @@ /* f->output = fsl_outputer_FILE; */ /* f->output.state.state = (fnc_init.err == true) ? stderr : stdout; */ FILE *f = fnc_init.err ? stderr : stdout; size_t idx = 0; - !isendwin() ? endwin() : 0; + endwin(); /* If a command was passed on the CLI, output its corresponding help. */ if (fnc_init.cmdarg) for (idx = 0; idx < nitems(fnc_init.cmd_args); ++idx) { fcli_command cmd = fnc_init.cmd_args[idx]; if (!fsl_strcmp(fnc_init.cmdarg, cmd.name) || fcli_cmd_aliascmp(&cmd, fnc_init.cmdarg)) { - if (!fsl_strcmp(cmd.name, "stash")) { - help_stash(&cmd); - } else - fcli_command_help(&cmd, true, true); + fcli_command_help(&cmd, true, true); exit(fcli_end_of_main(fnc_init.err)); } } /* Otherwise, output help/usage for all commands. */ @@ -9383,123 +6851,10 @@ "[setting [value|--unset]]\n" " e.g.: %s config FNC_COLOUR_COMMIT blue\n\n" , fcli_progname(), fcli_progname()); } -static void -usage_stash(void) -{ - fsl_fprintf(fnc_init.err ? stderr : stdout, - " usage: %s stash [get|pop | [-C|--no-colour] [-h|--help] " - "[-P|--no-prototype] [-x|--context n]]\n" - " e.g.: %s stash -x 10\n\n", fcli_progname(), fcli_progname()); -} - -static void -help_stash(const fcli_command *cmd) -{ - fcli_command_help(cmd, false, true); - f_out("[stash] subcommands:\n\n"); - f_out(" get\n " - "Apply the most recent stash changeset to the checkout.\n\n"); - f_out(" pop\n Remove the most recent stash changeset, " - "and apply to the checkout.\n\n"); - usage_stash(); -} - -static int -cmd_stash(fcli_command const *argv) -{ - fsl_cx *const f = fcli_cx(); - struct fnc_view *view = NULL; - struct fnc_commit_artifact *commit = NULL; - fsl_id_t prid = -1, rid = -1; - int rc = FSL_RC_OK; - enum fnc_diff_type diff_type = FNC_DIFF_CKOUT; - enum fnc_diff_mode diff_mode = STASH_INTERACTIVE; - -#ifdef __OpenBSD__ - if (pledge("stdio rpath wpath cpath fattr flock tty unveil", NULL) == -1) - return RC(fsl_errno_to_rc(errno, FSL_RC_ACCESS), "pledge"); -#endif - - rc = fcli_process_flags(argv->flags); - if (rc || (rc = fcli_has_unused_flags(false))) - return rc; - - if (fcli_next_arg(false)) { - const char *cmd; - bool pop = false; - if (fsl_strcmp((cmd = fcli_next_arg(true)), "get") && - fsl_strcmp(cmd, "apply") && !(pop = !fsl_strcmp(cmd, "pop"))) - return RC(FSL_RC_NOT_FOUND, - "invalid stash subcommand: %s", cmd); - return f__stash_get(pop); - } - - rc = fsl_sym_to_rid(f, "current", FSL_SATYPE_CHECKIN, &prid); - if (rc || prid < 0) - return RC(rc, "fsl_sym_to_rid"); - - fsl_ckout_version_info(f, &rid, NULL); - if ((rc = fsl_ckout_changes_scan(f))) - return RC(rc, "fsl_ckout_changes_scan"); - if (!fsl_ckout_has_changes(f)) { - fsl_fprintf(stdout, "No local changes.\n"); - return rc; - } - - commit = calloc(1, sizeof(*commit)); - if (commit == NULL) - return RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), "calloc"); - commit->prid = prid; - commit->rid = rid; - commit->puuid = fsl_rid_to_uuid(f, prid); - commit->uuid = fsl_rid_to_uuid(f, rid); - commit->type = fsl_strdup("blob"); - commit->diff_type = diff_type; - - rc = init_curses(); - if (rc) - goto end; - /* - * XXX revert_ckout:fsl_ckout_revert()^ walks the tree from / to the - * ckout stat(2)ing every dir so we need rx on root. Revoke privileges - * on root after returning from revert_ckout(). - * ^fsl__vfile_to_ckout:fsl_mkdir_for_file:fsl_dir_check() - */ - rc = init_unveil(((const char *[]){"/", REPODIR, CKOUTDIR, P_tmpdir, - gettzfile()}), ((const char *[]){"rx", "rwc", "rwc", "rwc", "r"}), - 5, false); - if (rc) - goto end; - - view = view_open(0, 0, 0, 0, FNC_VIEW_DIFF); - if (view == NULL) { - rc = RC(FSL_RC_ERROR, "view_open"); - goto end; - } - - rc = open_diff_view(view, commit, NULL, NULL, diff_mode); - if (!rc) { - rc = show_diff(view); - if (!rc) - rc = fnc_stash(view); - } -end: - /* - * We must check for changes based on file content--not mtime--else - * the lib will report files as unchanged in some cases. - */ - fsl_vfile_changes_scan(f, f->ckout.rid, FSL_VFILE_CKSIG_HASH); - if (commit) - fnc_commit_artifact_close(commit); - if (view) - view_close(view); - return rc; -} - static int cmd_diff(fcli_command const *argv) { fsl_cx *const f = fcli_cx(); struct fnc_view *view; @@ -9512,11 +6867,11 @@ char *path0 = NULL; fsl_id_t prid = -1, rid = -1; int rc = FSL_RC_OK; unsigned short blob = 0; enum fnc_diff_type diff_type = FNC_DIFF_CKOUT; - enum fnc_diff_mode diff_mode = DIFF_PLAIN; + bool showmeta = false; rc = fcli_process_flags(argv->flags); if (rc || (rc = fcli_has_unused_flags(false))) return rc; @@ -9544,26 +6899,28 @@ diff_type = FNC_DIFF_COMMIT; if (!fsl_rid_is_a_checkin(f, rid)) ++blob; } } - if (fcli_error()->code == FSL_RC_NOT_FOUND) - RC_RESET(rc); /* If args aren't symbols, treat as paths. */ + if (fcli_error()->code == FSL_RC_NOT_FOUND) { + fcli_err_reset(); /* If args aren't symbols, treat as paths. */ + rc = 0; + } if (blob == 2) diff_type = FNC_DIFF_BLOB; if (!artifact1 && diff_type != FNC_DIFF_BLOB) { artifact1 = "current"; rc = fsl_sym_to_rid(f, artifact1, FSL_SATYPE_CHECKIN, &prid); if (rc || prid < 0) { - rc = RC(rc, "fsl_sym_to_rid"); + rc = RC(rc, "%s", "fsl_sym_to_rid"); goto end; } } if (!artifact2 && diff_type != FNC_DIFF_BLOB) { fsl_ckout_version_info(f, &rid, NULL); if ((rc = fsl_ckout_changes_scan(f))) - return RC(rc, "fsl_ckout_changes_scan"); + return RC(rc, "%s", "fsl_ckout_changes_scan"); if (!fsl_strcmp(artifact1, "current") && !fsl_ckout_has_changes(f)) { fsl_fprintf(stdout, "No local changes.\n"); return rc; } @@ -9571,30 +6928,30 @@ while (fcli_next_arg(false) && diff_type != FNC_DIFF_BLOB) { struct fnc_pathlist_entry *ins; char *path, *path_to_diff; rc = map_repo_path(&path0); path = path0; + while (path[0] == '/') + ++path; if (rc) { - if (rc != FSL_RC_UNKNOWN_RESOURCE) { - if (!fsl_strcmp(artifact1, "current") && - !artifact2) { - rc = RC(rc, "invalid artifact hash: %s", - path); - } + if (rc != FSL_RC_NOT_FOUND || + (!fsl_strcmp(artifact1, "current") && !artifact2)) { + rc = RC(rc, "invalid artifact hash: %s", path); goto end; } - RC_RESET(rc); + rc = 0; + fcli_err_reset(); /* Path may be valid in tree of specified commit(s). */ const fsl_card_F *cf = NULL; rc = fsl_deck_load_sym(f, &d, artifact1, FSL_SATYPE_CHECKIN); if (rc) goto end; cf = fsl_deck_F_search(&d, path); if (cf == NULL) { if (!artifact2) { - rc = RC(FSL_RC_UNKNOWN_RESOURCE, + rc = RC(FSL_RC_NOT_FOUND, "'%s' not found in tree [%s]", path, artifact1); goto end; } fsl_deck_finalize(&d); @@ -9608,16 +6965,14 @@ "'%s' not found in trees [%s] [%s]", path, artifact1, artifact2); goto end; } } - } else - while (path[0] == '/') - ++path; + } path_to_diff = fsl_strdup(path); if (path_to_diff == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_strdup"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_strdup"); goto end; } rc = fnc_pathlist_insert(&ins, &paths, path_to_diff, NULL); if (rc || ins == NULL /* Duplicate path. */) fsl_free(path_to_diff); @@ -9629,21 +6984,21 @@ q = fsl_stmt_malloc(); rc = commit_builder(&commit, rid, q); if (rc) goto end; if (commit->prid == prid) - diff_mode = COMMIT_META; + showmeta = true; else { fsl_free(commit->puuid); commit->prid = prid; commit->puuid = fsl_rid_to_uuid(f, prid); } } else { commit = calloc(1, sizeof(*commit)); if (commit == NULL) { rc = RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), - "calloc"); + "%s", "calloc"); goto end; } commit->prid = prid; commit->rid = rid; commit->puuid = fsl_rid_to_uuid(f, prid); @@ -9653,22 +7008,21 @@ } rc = init_curses(); if (rc) goto end; - rc = init_unveil(((const char *[]){REPODB, CKOUTDIR, P_tmpdir, - gettzfile()}), ((const char *[]){"rw", "rwc", "rwc", "r"}), 4, true); + rc = init_unveil(REPODB, CKOUTDIR, false); if (rc) goto end; view = view_open(0, 0, 0, 0, FNC_VIEW_DIFF); if (view == NULL) { - rc = RC(FSL_RC_ERROR, "view_open"); + rc = RC(FSL_RC_ERROR, "%s", "view_open"); goto end; } - rc = open_diff_view(view, commit, &paths, NULL, diff_mode); + rc = open_diff_view(view, commit, &paths, NULL, showmeta); if (!rc) rc = view_loop(view); end: fsl_free(path0); fsl_deck_finalize(&d); @@ -9688,11 +7042,11 @@ struct fnc_view *tree_view; int rc = 0; tree_view = view_open(0, 0, start_ln, start_col, FNC_VIEW_TREE); if (tree_view == NULL) - return RC(FSL_RC_ERROR, "view_open"); + return RC(FSL_RC_ERROR, "%s", "view_open"); rc = open_tree_view(tree_view, path, entry->commit->rid); if (rc) return rc; @@ -9755,18 +7109,17 @@ } rc = init_curses(); if (rc) goto end; - rc = init_unveil(((const char *[]){REPODB, CKOUTDIR, P_tmpdir, - gettzfile()}), ((const char *[]){"rw", "rwc", "rwc", "r"}), 4, true); + rc = init_unveil(REPODB, CKOUTDIR, false); if (rc) goto end; view = view_open(0, 0, 0, 0, FNC_VIEW_TREE); if (view == NULL) { - RC(FSL_RC_ERROR, "view_open"); + RC(FSL_RC_ERROR, "%s", "view_open"); goto end; } rc = open_tree_view(view, path, rid); if (!rc) @@ -9787,11 +7140,11 @@ s->show_id = false; s->colour = !fnc_init.nocolour && has_colors(); s->rid = rid; s->commit_id = fsl_rid_to_uuid(f, rid); if (s->commit_id == NULL) - return RC(FSL_RC_AMBIGUOUS, "fsl_rid_to_uuid"); + return RC(FSL_RC_AMBIGUOUS, "%s", "fsl_rid_to_uuid"); /* * Construct tree of entire repository from which all (sub)tress will * be derived. This object will be released when this view closes. */ @@ -9818,11 +7171,11 @@ goto end; } if ((s->tree_label = fsl_mprintf("checkin %s", s->commit_id)) == NULL) { - rc = RC(FSL_RC_RANGE, "fsl_mprintf"); + rc = RC(FSL_RC_RANGE, "%s", "fsl_mprintf"); goto end; } s->first_entry_onscreen = &s->tree->entries[0]; s->selected_entry = &s->tree->entries[0]; @@ -9871,11 +7224,11 @@ if (slash == NULL) te_name = fsl_strdup(p); else te_name = fsl_strndup(p, slash - p); if (te_name == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_strdup"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_strdup"); break; } te = find_tree_entry(s->tree, te_name, fsl_strlen(te_name)); if (te == NULL) { @@ -9894,11 +7247,11 @@ if (slash) subpath = fsl_strndup(path, slash - path); else subpath = fsl_strdup(path); if (subpath == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_strdup"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_strdup"); break; } rc = tree_builder(repo, &tree, subpath + 1 /* Leading slash */); if (rc) @@ -9935,16 +7288,16 @@ const fsl_card_F *cf = NULL; int rc = 0; ptr = fsl_malloc(sizeof(struct fnc_repository_tree)); if (ptr == NULL) - return RC(FSL_RC_ERROR, "fsl_malloc"); + return RC(FSL_RC_ERROR, "%s", "fsl_malloc"); memset(ptr, 0, sizeof(struct fnc_repository_tree)); rc = fsl_deck_load_rid(f, &d, rid, FSL_SATYPE_CHECKIN); if (rc) - return RC(rc, "fsl_deck_load_rid(%d) [%s]", rid, *id); + return RC(rc, "fsl_deck_load_rid(%d) [%s]", rid, id); rc = fsl_deck_F_rewind(&d); if (rc) goto end; rc = fsl_deck_F_next(&d, &cf); if (rc) @@ -9954,16 +7307,16 @@ char *filename = NULL, *uuid = NULL; fsl_time_t mtime; filename = fsl_strdup(cf->name); if (filename == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_strdup"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_strdup"); goto end; } uuid = fsl_strdup(cf->uuid); if (uuid == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_strdup"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_strdup"); goto end; } rc = fsl_mtime_of_F_card(f, rid, cf, &mtime); if (!rc) rc = link_tree_node(ptr, filename, uuid, @@ -9996,11 +7349,11 @@ int i = 0; *tree = NULL; *tree = fsl_malloc(sizeof(**tree)); if (*tree == NULL) - return RC(FSL_RC_ERROR, "fsl_malloc"); + return RC(FSL_RC_ERROR, "%s", "fsl_malloc"); memset(*tree, 0, sizeof(**tree)); /* * Count how many elements will comprise the tree to be allocated. * If dir is the root of the repository tree (i.e., "/"), only tree @@ -10013,11 +7366,11 @@ continue; ++i; } (*tree)->entries = calloc(i, sizeof(struct fnc_tree_entry)); if ((*tree)->entries == NULL) - return RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), "calloc"); + return RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), "%s", "calloc"); /* Construct the tree to be displayed. */ for(tn = repo->head, i = 0; tn; tn = tn->next) { if ((!tn->parent_dir && fsl_strcmp(dir, "/")) || (tn->parent_dir && fsl_strcmp(dir, tn->parent_dir->path))) continue; @@ -10024,17 +7377,17 @@ te = &(*tree)->entries[i]; te->mode = tn->mode; te->mtime = tn->mtime; te->basename = fsl_strdup(tn->basename); if (te->basename == NULL) - return RC(FSL_RC_ERROR, "fsl_strdup"); + return RC(FSL_RC_ERROR, "%s", "fsl_strdup"); te->path = fsl_strdup(tn->path); if (te->path == NULL) - return RC(FSL_RC_ERROR, "fsl_strdup"); + return RC(FSL_RC_ERROR, "%s", "fsl_strdup"); te->uuid = fsl_strdup(tn->uuid); if (te->uuid == NULL && !S_ISDIR(te->mode)) - return RC(FSL_RC_ERROR, "fsl_strdup"); + return RC(FSL_RC_ERROR, "%s", "fsl_strdup"); te->idx = i++; } (*tree)->nentries = i; return 0; @@ -10113,11 +7466,11 @@ */ if (uuid != 0 && path[i] == '\0') nodesz += FSL_STRLEN_K256 + 1; /* NUL */ tn = fsl_malloc(nodesz); if (tn == NULL) - return RC(FSL_RC_ERROR, "fsl_malloc"); + return RC(FSL_RC_ERROR, "%s", "fsl_malloc"); memset(tn, 0, sizeof(*tn)); tn->path = (char *)&tn[1]; memcpy(tn->path, path, i); tn->path[i] = '\0'; @@ -10222,31 +7575,31 @@ if (te) len += strlen(te->basename); *path = calloc(1, len); if (path == NULL) - return RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), "calloc"); + return RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), "%s", "calloc"); (*path)[0] = '/'; /* Make it absolute from the repository root. */ pt = TAILQ_LAST(parents, fnc_parent_trees); while (pt) { const char *name = pt->selected_entry->basename; if (strlcat(*path, name, len) >= len) { - rc = RC(FSL_RC_RANGE, "strlcat(%s, %s, %lu)", + rc = RC(FSL_RC_RANGE, "strlcat(%s, %s, %d)", *path, name, len); goto end; } if (strlcat(*path, "/", len) >= len) { - rc = RC(FSL_RC_RANGE, "strlcat(%s, \"/\", %lu)", + rc = RC(FSL_RC_RANGE, "strlcat(%s, \"/\", %d)", *path, len); goto end; } pt = TAILQ_PREV(pt, fnc_parent_trees, entry); } if (te) { if (strlcat(*path, te->basename, len) >= len) { - rc = RC(FSL_RC_RANGE, "strlcat(%s, %s, %lu)", + rc = RC(FSL_RC_RANGE, "strlcat(%s, %s, %d)", *path, te->basename, len); goto end; } } end: @@ -10367,20 +7720,21 @@ if (s->show_id) { idstr = fsl_strdup(te->uuid); /* Directories don't have UUIDs; pad with "..." dots. */ if (idstr == NULL && !S_ISDIR(mode)) - return RC(FSL_RC_ERROR, "fsl_strdup"); + return RC(FSL_RC_ERROR, "%s", "fsl_strdup"); /* If needed, pad SHA1 hash to align w/ SHA3 hashes. */ if (idstr == NULL || fsl_strlen(idstr) < hashlen) { char buf[hashlen], pad = '.'; buf[hashlen] = '\0'; idstr = fsl_mprintf("%s%s", idstr ? idstr : "", (char *)memset(buf, pad, hashlen - fsl_strlen(idstr))); if (idstr == NULL) - return RC(FSL_RC_RANGE, "fsl_mprintf"); + return RC(FSL_RC_RANGE, + "%s", "fsl_mprintf"); idstr[hashlen] = '\0'; /* idstr = fsl_mprintf("%*c", hashlen, ' '); */ } } if (S_ISLNK(mode)) { @@ -10413,12 +7767,12 @@ *iso8601 ? iso8601 : "", te->basename, modestr, targetlnk ? " -> ": "", targetlnk ? targetlnk : ""); fsl_free(idstr); fsl_free(targetlnk); if (rc || line == NULL) - return rc ? RC(rc, "fsl_julian_to_iso8601") : - RC(FSL_RC_RANGE, "fsl_mprintf"); + return RC(rc ? rc : FSL_RC_RANGE, "%s", + rc ? "fsl_julian_to_iso8601" : "fsl_mprintf"); rc = formatln(&wcstr, &wstrlen, line, view->ncols, 0, false); if (rc) { fsl_free(line); break; } @@ -10469,11 +7823,11 @@ } bufsz = s.st_size ? (s.st_size + 1 /* NUL */) : PATH_MAX; buf = fsl_malloc(bufsz); if (buf == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_malloc"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_malloc"); goto end; } nbytes = readlink(fsl_buffer_cstr(&fb), buf, bufsz); if (nbytes == -1) { @@ -10522,11 +7876,11 @@ if (view_is_parent(view)) start_col = view_split_start_col(view->start_col); branch_view = view_open(view->nlines, view->ncols, view->start_ln, start_col, FNC_VIEW_BRANCH); if (branch_view == NULL) - return RC(FSL_RC_ERROR, "view_open"); + return RC(FSL_RC_ERROR, "%s", "view_open"); rc = open_branch_view(branch_view, BRANCH_LS_OPEN_CLOSED, NULL, 0, 0); if (rc) { view_close(branch_view); return rc; @@ -10719,12 +8073,12 @@ rc = fsl_content_get(f, fid, &buf); if (rc) goto end; if (fsl_looks_like_binary(&buf)) - sitrep(view, SR_UPDATE | SR_SLEEP, - "-- cannot blame binary file --"); + sitrep(view, "-- cannot blame binary file --", + SR_UPDATE | SR_SLEEP); else rc = request_view(new_view, view, FNC_VIEW_BLAME); end: fsl_buffer_clear(&buf); return rc; @@ -10740,11 +8094,11 @@ *new_view = NULL; timeline_view = view_open(0, 0, 0, start_col, FNC_VIEW_TIMELINE); if (timeline_view == NULL) - return RC(FSL_RC_ERROR, "view_open"); + return RC(FSL_RC_ERROR, "%s", "view_open"); /* Construct repository relative path for timeline query. */ rc = tree_entry_path(&path, &s->parents, s->selected_entry); if (rc) return rc; @@ -10811,11 +8165,11 @@ { struct fnc_parent_tree *parent; parent = calloc(1, sizeof(*parent)); if (parent == NULL) - return RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), "calloc"); + return RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), "%s", "calloc"); parent->tree = s->tree; parent->first_entry_onscreen = s->first_entry_onscreen; parent->selected_entry = s->selected_entry; parent->selected = s->selected; @@ -10842,11 +8196,11 @@ if (rc) return rc; blame_view = view_open(0, 0, start_ln, start_col, FNC_VIEW_BLAME); if (blame_view == NULL) { - rc = RC(FSL_RC_ERROR, "view_open"); + rc = RC(FSL_RC_ERROR, "%s", "view_open"); goto end; } rc = open_blame_view(blame_view, path, commit_id, 0, 0, NULL); if (rc) @@ -11046,12 +8400,11 @@ const char *opt = NULL, *value = NULL; char *prev, *v; enum fnc_opt_id setid; int rc = FSL_RC_OK; - rc = init_unveil(((const char *[]){REPODIR, CKOUTDIR, P_tmpdir, - gettzfile()}), ((const char *[]){"rwc", "rwc", "rwc", "r"}), 4, true); + rc = init_unveil(REPODIR, CKOUTDIR, true); if (rc) return rc; rc = fcli_process_flags(argv->flags); if (rc || (rc = fcli_has_unused_flags(false))) @@ -11059,11 +8412,11 @@ opt = fcli_next_arg(true); if (opt == NULL || fnc_init.lsconf) { if (fnc_init.unset) { fnc_init.err = RC(FSL_RC_MISSING_INFO, - "-u|--unset requires "); + "%s", "-u|--unset requires "); usage(); /* NOT REACHED */ } return fnc_conf_lsopt(fnc_init.lsconf ? false : true); } @@ -11184,12 +8537,12 @@ int rc = FSL_RC_OK; switch (vid) { case FNC_VIEW_DIFF: { static const char *regexp_diff[] = { - "^((checkin|wiki|ticket|technote) [0-9a-f]\\s\\s*$|" - "hash [+-] |\\[[+~>-]] |[+-]{3} )", + "^((checkin|wiki|ticket|technote) " + "[0-9a-f]|hash [+-] |\\[[+~>-]] |[+-]{3} )", "^user:", "^date:", "^tags:", "^-|^[0-9 ]+ -", "^\\+|^[0-9 ]+ \\+", "^@@", /* * XXX Ugly hack to fail matching _DIFF_SBS_EDIT early * until all diff modes use the new line_type interface. @@ -11259,11 +8612,11 @@ rc = set_colour_scheme(s, pairs_branch, regexp_branch, nitems(regexp_branch)); break; } default: - rc = RC(FSL_RC_TYPE, "invalid fnc_view_id: %d", vid); + rc = RC(FSL_RC_TYPE, "invalid fnc_view_id: %s", vid); } init_pair(FNC_COLOUR_HL_SEARCH, init_colour(FNC_COLOUR_HL_SEARCH), -1); return rc; @@ -11278,11 +8631,11 @@ for (idx = 0; idx < n; ++idx) { colour = fsl_malloc(sizeof(*colour)); if (colour == NULL) return RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), - "fsl_malloc"); + "%s", "fsl_malloc"); rc = regcomp(&colour->regex, regexp[idx], REG_EXTENDED | REG_NEWLINE | REG_NOSUB); if (rc) { static char regerr[512]; @@ -11351,11 +8704,11 @@ db = fsl_needs_repo(f); if (!db) { /* Theoretically, this shouldn't happen. */ - RC(FSL_RC_DB, "fsl_needs_repo"); + RC(FSL_RC_DB, "%s", "fsl_needs_repo"); return NULL; } optval = fsl_db_g_text(db, NULL, "SELECT value FROM config WHERE name=%Q", fnc_conf_enum2str(id)); @@ -11415,11 +8768,11 @@ fsl_db *db = NULL; db = fsl_needs_repo(f); if (!db) /* Theoretically, this shouldn't happen. */ - return RC(FSL_RC_DB, "fsl_needs_repo"); + return RC(FSL_RC_DB, "%s", "fsl_needs_repo"); if (unset) return fsl_db_exec(db, "DELETE FROM config WHERE name=%Q", fnc_conf_enum2str(id)); @@ -11544,14 +8897,15 @@ fsl_sym_to_rid(f, "tip", FSL_SATYPE_CHECKIN, &rid); } rc = map_repo_path(&path); if (rc) { - if (rc != FSL_RC_UNKNOWN_RESOURCE || !fnc_init.sym) + if (rc != FSL_RC_NOT_FOUND || !fnc_init.sym) goto end; /* Path may be valid in repository tree of specified commit. */ - RC_RESET(rc); + rc = 0; + fcli_err_reset(); } commit_id = fsl_rid_to_uuid(f, rid); if (rc || (path[0] == '/' && path[1] == '\0')) { rc = rc ? rc : RC(FSL_RC_MISSING_INFO, @@ -11560,18 +8914,17 @@ } rc = init_curses(); if (rc) goto end; - rc = init_unveil(((const char *[]){REPODB, CKOUTDIR, P_tmpdir, - gettzfile()}), ((const char *[]){"rw", "rwc", "rwc", "r"}), 4, true); + rc = init_unveil(REPODB, CKOUTDIR, false); if (rc) goto end; view = view_open(0, 0, 0, 0, FNC_VIEW_BLAME); if (view == NULL) { - rc = RC(FSL_RC_ERROR, "view_open"); + rc = RC(FSL_RC_ERROR, "%s", view_open); goto end; } rc = open_blame_view(view, path, commit_id, tip, nlimit, fnc_init.lineno); @@ -11593,11 +8946,11 @@ CONCAT(STAILQ, _INIT)(&s->blamed_commits); s->path = fsl_strdup(path); if (s->path == NULL) - return RC(FSL_RC_ERROR, "fsl_strdup"); + return RC(FSL_RC_ERROR, "%s", "fsl_strdup"); rc = fnc_commit_qid_alloc(&s->blamed_commit, commit_id); if (rc) { fsl_free(s->path); return rc; @@ -11668,21 +9021,21 @@ } rc = fsl_card_F_content(f, cf, &buf); if (rc) goto end; if (fsl_looks_like_binary(&buf)) { - rc = RC(FSL_RC_DIFF_BINARY, "cannot blame binary file"); + rc = RC(FSL_RC_DIFF_BINARY, "%s", "cannot blame binary file"); goto end; } /* * We load f with the actual file content to map line offsets so we * accurately find tokens when running a search. */ blame->f = tmpfile(); if (blame->f == NULL) { - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), "tmpfile"); + rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), "%s", "tmpfile"); goto end; } opt = &blame->thread_cx.blame_opt; opt->filename = fsl_strdup(filepath); @@ -11720,36 +9073,36 @@ s->gtl = ln; } blame->lines = calloc(blame->nlines, sizeof(*blame->lines)); if (blame->lines == NULL) { - rc = RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), "calloc"); + rc = RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), "%s", "calloc"); goto end; } master = fsl_config_get_text(f, FSL_CONFDB_REPO, "main-branch", NULL); if (master == NULL) { master = fsl_strdup("trunk"); if (master == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_strdup"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_strdup"); goto end; } } root = fsl_mprintf("root:%s", master); rc = fsl_sym_to_uuid(f, root, FSL_SATYPE_CHECKIN, &blame->cb_cx.root_commit, NULL); if (rc) { - rc = RC(rc, "fsl_sym_to_uuid"); + rc = RC(rc, "%s", "fsl_sym_to_uuid"); goto end; } blame->cb_cx.view = view; blame->cb_cx.lines = blame->lines; blame->cb_cx.nlines = blame->nlines; blame->cb_cx.commit_id = fsl_strdup(s->blamed_commit->id); if (blame->cb_cx.commit_id == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_strdup"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_strdup"); goto end; } blame->cb_cx.quit = &s->done; blame->thread_cx.path = s->path; @@ -11807,11 +9160,11 @@ *nlines = 1; nalloc = alloc_chunksz; *line_offsets = calloc(nalloc, sizeof(**line_offsets)); if (*line_offsets == NULL) return RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), - "calloc"); + "%s", "calloc"); /* Consume the first line. */ while (i < len) { if (buf->mem[i] == '\n') break; @@ -11833,21 +9186,22 @@ oldsz = nalloc * sizeof(**line_offsets); newsz = n * sizeof(**line_offsets); if (newsz <= oldsz) { size_t b = oldsz - newsz; if (b < oldsz / 2 && - b < (size_t)sysconf(_SC_PAGESIZE)) { + b < (size_t)getpagesize()) { memset((char *)*line_offsets + newsz, 0, b); goto allocated; } } new = fsl_realloc(*line_offsets, newsz); if (new == NULL) { fsl_free(*line_offsets); *line_offsets = NULL; - return RC(FSL_RC_ERROR, "fsl_realloc"); + return RC(FSL_RC_ERROR, "%s", + "fsl_realloc"); } *line_offsets = new; allocated: nalloc = n; } @@ -11859,15 +9213,15 @@ } } n = fwrite(buf->mem, 1, len, out); if (n != len) return RC(ferror(out) ? fsl_errno_to_rc(errno, FSL_RC_IO) - : FSL_RC_IO, "fwrite"); + : FSL_RC_IO, "%s", "fwrite"); total_len += len; if (fflush(out) != 0) - return RC(fsl_errno_to_rc(errno, FSL_RC_IO), "fflush"); + return RC(fsl_errno_to_rc(errno, FSL_RC_IO), "%s", "fflush"); rewind(out); if (filesz) *filesz = total_len; @@ -11883,11 +9237,11 @@ if (!s->blame.thread_id && !s->blame_complete) { rc = pthread_create(&s->blame.thread_id, NULL, blame_thread, &s->blame.thread_cx); if (rc) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_create"); + "%s", "pthread_create"); halfdelay(1); /* Fast refresh while annotating. */ } if (s->blame_complete) @@ -11909,24 +9263,26 @@ rc = block_main_thread_signals(); if (rc) return (void *)(intptr_t)rc; rc = fsl_annotate(f, &cx->blame_opt); - if (rc && fsl_cx_err_get_e(f)->code == FSL_RC_BREAK) - RC_RESET(rc); + if (rc && fsl_cx_err_get_e(f)->code == FSL_RC_BREAK) { + fcli_err_reset(); + rc = 0; + } rc0 = pthread_mutex_lock(&fnc_mutex); if (rc0) return (void *)(intptr_t)RC(fsl_errno_to_rc(rc0, FSL_RC_ACCESS), - "pthread_mutex_lock"); + "%s", "pthread_mutex_lock"); *cx->complete = true; rc0 = pthread_mutex_unlock(&fnc_mutex); if (rc0 && !rc) rc = RC(fsl_errno_to_rc(rc0, FSL_RC_ACCESS), - "pthread_mutex_unlock"); + "%s", "pthread_mutex_unlock"); return (void *)(intptr_t)rc; } static int @@ -11938,11 +9294,11 @@ int rc = 0; rc = pthread_mutex_lock(&fnc_mutex); if (rc) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_mutex_lock"); + "%s", "pthread_mutex_lock"); if (*cx->quit) { rc = fcli_err_set(FSL_RC_BREAK, "user quit"); goto end; } @@ -11952,11 +9308,11 @@ goto end; if (step->mtime) { line->id = fsl_strdup(step->versionHash); if (line->id == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_strdup"); + rc = RC(FSL_RC_ERROR, "%s", fsl_strdup); goto end; } line->annotated = true; } else line->id = NULL; @@ -11972,11 +9328,11 @@ ++cx->nlines; end: rc = pthread_mutex_unlock(&fnc_mutex); if (rc) rc = RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_mutex_unlock"); + "%s", "pthread_mutex_unlock"); return rc; } static int draw_blame(struct fnc_view *view) @@ -11998,11 +9354,12 @@ rewind(blame->f); werase(view->window); if ((line = fsl_mprintf("checkin %s", s->blamed_commit->id)) == NULL) { - rc = RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), "fsl_mprintf"); + rc = RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), + "%s", "fsl_mprintf"); return rc; } rc = formatln(&wcstr, &width, line, view->ncols, 0, false); fsl_free(line); @@ -12054,11 +9411,11 @@ s->eof = true; break; } fsl_free(line); return RC(ferror(blame->f) ? fsl_errno_to_rc(errno, - FSL_RC_IO) : FSL_RC_IO, "getline"); + FSL_RC_IO) : FSL_RC_IO, "%s", "getline"); } if (++lineno < s->first_line_onscreen) continue; if (s->gtl) if (!gotoline(view, &lineno, &nprinted)) @@ -12079,11 +9436,12 @@ char *id_str; id_str = fsl_strndup(blame_line->id, idfield - 1); if (id_str == NULL) { fsl_free(line); - return RC(FSL_RC_ERROR, "fsl_strdup"); + return RC(FSL_RC_ERROR, "%s", + "fsl_strdup"); } if (s->colour) c = get_colour(&s->colours, FNC_COLOUR_COMMIT); if (c) @@ -12115,11 +9473,11 @@ if (view->ncols <= idfield) { wcstr = wcsdup(L""); if (wcstr == NULL) { rc = RC(fsl_errno_to_rc(errno, FSL_RC_RANGE), - "wcsdup"); + "%s", "wcsdup"); fsl_free(line); return rc; } } else if (s->first_line_onscreen + nprinted == s->matched_line && regmatch->rm_so >= 0 && @@ -12347,25 +9705,30 @@ /* Check file exists in parent check-in. */ rc = fsl_deck_load_sym(f, &d, pid, FSL_SATYPE_CHECKIN); if (rc) { fsl_deck_finalize(&d); fsl_free(pid); - return RC(rc, "fsl_deck_load_sym"); + return RC(rc, "%s", "fsl_deck_load_sym"); } rc = fsl_deck_F_rewind(&d); if (rc) { fsl_deck_finalize(&d); fsl_free(pid); - return RC(rc, "fsl_deck_F_rewind"); + return RC(rc, "%s", "fsl_deck_F_rewind"); } if (fsl_deck_F_search(&d, s->path + (fnc_init.sym ? 0 : 1)) == NULL) { - sitrep(view, SR_ALL ^ SR_RESET, - "-- %s not in [%.12s] --", + char *m = fsl_mprintf("-- %s not in [%.12s] --", s->path + (fnc_init.sym ? 0 : 1), pid); + if (m == NULL) + rc = RC(FSL_RC_ERROR, "%s", + "fsl_mprintf"); + sitrep(view, m, + SR_CLREOL | SR_UPDATE | SR_SLEEP); fsl_deck_finalize(&d); fsl_free(pid); + fsl_free(m); break; } rc = fnc_commit_qid_alloc(&s->blamed_commit, pid); if (rc) return rc; @@ -12411,11 +9774,11 @@ if (view_is_parent(view)) start_col = view_split_start_col(view->start_col); branch_view = view_open(view->nlines, view->ncols, view->start_ln, start_col, FNC_VIEW_BRANCH); if (branch_view == NULL) - return RC(FSL_RC_ERROR, "view_open"); + return RC(FSL_RC_ERROR, "%s", "view_open"); rc = open_branch_view(branch_view, BRANCH_LS_OPEN_CLOSED, NULL, 0, 0); if (rc) { view_close(branch_view); return rc; @@ -12462,15 +9825,15 @@ if (view_is_parent(view)) start_col = view_split_start_col(view->start_col); diff_view = view_open(0, 0, 0, start_col, FNC_VIEW_DIFF); if (diff_view == NULL) { fnc_commit_artifact_close(commit); - rc = RC(FSL_RC_ERROR, "view_open"); + rc = RC(FSL_RC_ERROR, "%s", "view_open"); break; } } - rc = open_diff_view(diff_view, commit, NULL, view, COMMIT_META); + rc = open_diff_view(diff_view, commit, NULL, view, true); s->selected_entry = commit; if (rc) { fnc_commit_artifact_close(commit); view_close(diff_view); break; @@ -12528,15 +9891,15 @@ { int rc = 0; *qid = calloc(1, sizeof(**qid)); if (*qid == NULL) - return RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), "calloc"); + return RC(fsl_errno_to_rc(errno, FSL_RC_ERROR), "%s", "calloc"); (*qid)->id = fsl_strdup(id); if ((*qid)->id == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_strdup"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_strdup"); fnc_commit_qid_free(*qid); *qid = NULL; } return rc; @@ -12573,26 +9936,29 @@ if (blame->thread_id) { intptr_t retval; rc = pthread_mutex_unlock(&fnc_mutex); if (rc) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_mutex_unlock"); + "%s", "pthread_mutex_unlock"); rc = pthread_join(blame->thread_id, (void **)&retval); if (rc) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_join"); + "%s", "pthread_join"); rc = pthread_mutex_lock(&fnc_mutex); if (rc) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_mutex_lock"); - if (!rc && fsl_cx_err_get_e(fcli_cx())->code == FSL_RC_BREAK) - RC_RESET(rc); + "%s", "pthread_mutex_lock"); + if (!rc && fsl_cx_err_get_e(fcli_cx())->code == FSL_RC_BREAK) { + rc = 0; + fcli_err_reset(); + } blame->thread_id = 0; } if (blame->f) { if (fclose(blame->f) == EOF && rc == 0) - rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), "fclose"); + rc = RC(fsl_errno_to_rc(errno, FSL_RC_IO), "%s", + fclose); blame->f = NULL; } if (blame->lines) { for (idx = 0; idx < blame->nlines; ++idx) fsl_free(blame->lines[idx].id); @@ -12616,19 +9982,19 @@ int rc = 0; rc = pthread_mutex_lock(&fnc_mutex); if (rc) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_mutex_unlock"); + "%s", "pthread_mutex_unlock"); if (*done) rc = fcli_err_set(FSL_RC_BREAK, "user quit"); rc = pthread_mutex_unlock(&fnc_mutex); if (rc) return RC(fsl_errno_to_rc(rc, FSL_RC_ACCESS), - "pthread_mutex_lock"); + "%s", "pthread_mutex_lock"); return rc; } static void @@ -12650,11 +10016,11 @@ if (rc || (rc = fcli_has_unused_flags(false))) return rc; branch_flags = BRANCH_LS_OPEN_CLOSED; if (fnc_init.open && fnc_init.closed) - return RC(FSL_RC_MISUSE, + return RC(FSL_RC_MISUSE, "%s", "--open and --close are mutually exclusive options"); else if (fnc_init.open) branch_flags = BRANCH_LS_OPEN_ONLY; else if (fnc_init.closed) branch_flags = BRANCH_LS_CLOSED_ONLY; @@ -12672,11 +10038,11 @@ FLAG_SET(branch_flags, BRANCH_LS_NO_PRIVATE); if (fnc_init.reverse) FLAG_SET(branch_flags, BRANCH_SORT_REVERSE); if (fnc_init.after && fnc_init.before) { - return RC(FSL_RC_MISUSE, + return RC(FSL_RC_MISUSE, "%s", "--before and --after are mutually exclusive options"); } else if (fnc_init.after || fnc_init.before) { const char *d = NULL; d = fnc_init.after ? fnc_init.after : fnc_init.before; when = fnc_init.after ? 1 : -1; @@ -12687,18 +10053,17 @@ glob = fsl_strdup(fcli_next_arg(true)); rc = init_curses(); if (rc) goto end; - rc = init_unveil(((const char *[]){REPODB, CKOUTDIR, P_tmpdir, - gettzfile()}), ((const char *[]){"rw", "rwc", "rwc", "r"}), 4, true); + rc = init_unveil(REPODB, CKOUTDIR, false); if (rc) goto end; view = view_open(0, 0, 0, 0, FNC_VIEW_BRANCH); if (view == NULL) { - rc = RC(FSL_RC_ERROR, "view_open"); + rc = RC(FSL_RC_ERROR, "%s", "view_open"); goto end; } rc = open_branch_view(view, branch_flags, glob, dateline, when); if (!rc) @@ -12809,11 +10174,11 @@ if (rc) goto end; stmt = fsl_stmt_malloc(); if (stmt == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_stmt_malloc"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_stmt_malloc"); goto end; } rc = fsl_cx_prepare(f, stmt, fsl_buffer_cstr(&sql)); if (rc) @@ -12883,14 +10248,15 @@ " AND event.objid=tagxref.rid " "GROUP BY 1;"; int rc = 0; if (!db) - return RC(FSL_RC_NOT_A_CKOUT, "fsl_needs_repo"); + return RC(FSL_RC_NOT_A_CKOUT, "%s", "fsl_needs_repo"); rc = fsl_db_exec(db, tmp_branchlist_table); - return rc ? RC(fsl_cx_uplift_db_error2(f, db, rc), "fsl_db_exec") : rc; + return rc ? RC(fsl_cx_uplift_db_error2(f, db, rc), "%s", "fsl_db_exec") + : rc; } static int alloc_branch(struct fnc_branch **branch, const char *name, double mtime, bool open, bool priv, bool curr) @@ -12899,15 +10265,15 @@ char iso8601[ISO8601_TIMESTAMP], *date = NULL; int rc = 0; *branch = calloc(1, sizeof(**branch)); if (*branch == NULL) - return RC(FSL_RC_ERROR, "calloc"); + return RC(FSL_RC_ERROR, "%s", "calloc"); rc = fsl_sym_to_uuid(fcli_cx(), name, FSL_SATYPE_ANY, &id, NULL); if (rc || id == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_sym_to_uuid"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_sym_to_uuid"); fnc_branch_close(*branch); *branch = NULL; return rc; } @@ -12919,11 +10285,11 @@ (*branch)->date = date; (*branch)->open = open; (*branch)->private = priv; (*branch)->current = curr; if ((*branch)->name == NULL) { - rc = RC(FSL_RC_ERROR, "fsl_strdup"); + rc = RC(FSL_RC_ERROR, "%s", "fsl_strdup"); fnc_branch_close(*branch); *branch = NULL; } return rc; @@ -12937,11 +10303,11 @@ *newp = NULL; new = fsl_malloc(sizeof(*new)); if (new == NULL) - return RC(FSL_RC_ERROR, "fsl_malloc"); + return RC(FSL_RC_ERROR, "%s", "fsl_malloc"); new->branch = branch; *newp = new; be = TAILQ_LAST(branches, fnc_branchlist_head); if (!be) { @@ -12991,11 +10357,11 @@ be = s->first_branch_onscreen; if ((line = fsl_mprintf("branches [%d/%d]", be->idx + s->selected + 1, s->nbranches)) == NULL) - return RC(FSL_RC_ERROR, "fsl_mprintf"); + return RC(FSL_RC_ERROR, "%s", "fsl_mprintf"); rc = formatln(&wline, &width, line, view->ncols, 0, false); if (rc) { fsl_free(line); return rc; @@ -13033,11 +10399,11 @@ s->show_date ? " " : "", be->branch->name, be->branch->private ? "*" : "", be->branch->current ? "@" : ""); if (line == NULL) - return RC(FSL_RC_ERROR, "fsl_mprintf"); + return RC(FSL_RC_ERROR, "%s", "fsl_mprintf"); if (s->colour) c = match_colour(&s->colours, line); rc = formatln(&wline, &width, line, view->ncols, 0, false); @@ -13228,15 +10594,15 @@ *new_view = NULL; rid = fsl_uuid_to_rid(fcli_cx(), be->branch->id); if (rid < 0) - return RC(rc, "fsl_uuid_to_rid"); + return RC(rc, "%s", "fsl_uuid_to_rid"); tree_view = view_open(0, 0, 0, start_col, FNC_VIEW_TREE); if (tree_view == NULL) - return RC(FSL_RC_ERROR, "view_open"); + return RC(FSL_RC_ERROR, "%s", "view_open"); rc = open_tree_view(tree_view, "/", rid); if (!rc) *new_view = tree_view; return rc; @@ -13420,11 +10786,11 @@ if (inserted) *inserted = NULL; new = fsl_malloc(sizeof(*new)); if (new == NULL) - return RC(FSL_RC_ERROR, "fsl_malloc"); + return RC(FSL_RC_ERROR, "%s", "fsl_malloc"); new->path = path; new->pathlen = fsl_strlen(path); new->data = data; /* @@ -13516,11 +10882,11 @@ } static void fnc_show_version(void) { - printf("%s %s", fcli_progname(), PRINT_VERSION); + printf("%s %s\n", fcli_progname(), PRINT_VERSION); } static int strtonumcheck(long *ret, const char *nstr, const int min, const int max) { @@ -13550,13 +10916,14 @@ fnc_prompt_input(struct fnc_view *view, struct input *input) { int rc = FSL_RC_OK; if (input->prompt) - sitrep(view, input->flags, "%s", input->prompt); + sitrep(view, input->prompt, input->flags); - rc = cook_input(input->buf, sizeof(input->buf), view->window); + rc = cook_input(input->buf, sizeof(input->buf), + view ? view->window : stdscr); if (rc || !input->buf[0]) return rc; if (input->type == INPUT_NUMERIC) { long n = 0; @@ -13565,13 +10932,13 @@ min = *(int *)input->data; max = ((int *)input->data)[1]; } rc = strtonumcheck(&n, input->buf, min, max); if (rc == FSL_RC_MISUSE) - rc = sitrep(view, SR_ALL, "-- numeric input only --"); + rc = sitrep(view, "-- numeric input only --", SR_ALL); else if (rc == FSL_RC_RANGE || n < min || n > max) - rc = sitrep(view, SR_ALL, "-- line outside range --"); + rc = sitrep(view, "-- line outside range --", SR_ALL); else input->ret = n; } return rc; @@ -13587,38 +10954,35 @@ rc = wgetnstr(win, ret, sz); cbreak(); noecho(); raw(); - return rc == ERR ? RC(FSL_RC_ERROR, "wgetnstr") : FSL_RC_OK; -} - -static int PRINTFV(3, 4) -sitrep(struct fnc_view *view, int flags, const char *msg, ...) -{ - va_list args; - - va_start(args, msg); - /* vw_printw(view->window, msg, args); */ - wattr_on(view->window, A_BOLD, NULL); - wmove(view->window, view->nlines - 1, 0); - vw_printw(view->window, msg, args); - if (FLAG_CHK(flags, SR_CLREOL)) - wclrtoeol(view->window); - wattr_off(view->window, A_BOLD, NULL); - va_end(args); - if (FLAG_CHK(flags, SR_UPDATE)) { - update_panels(); - doupdate(); - } - if (FLAG_CHK(flags, SR_RESET)) - fcli_err_reset(); - if (FLAG_CHK(flags, SR_SLEEP)) - sleep(1); - - return FSL_RC_OK; - } + return rc == ERR ? FSL_RC_ERROR : FSL_RC_OK; +} + +static int +sitrep(struct fnc_view *view, const char *msg, int flags) +{ + WINDOW *win = view ? view->window : stdscr; + int line = (view ? view->nlines : LINES) - 1; + + wattr_on(win, A_BOLD, NULL); + mvwaddstr(win, line, 0, msg); + if (FLAG_CHK(flags, SR_CLREOL)) + wclrtoeol(win); + wattr_off(win, A_BOLD, NULL); + if (FLAG_CHK(flags, SR_UPDATE)) { + update_panels(); + doupdate(); + } + if (FLAG_CHK(flags, SR_RESET)) + fcli_err_reset(); + if (FLAG_CHK(flags, SR_SLEEP)) + sleep(1); + + return FSL_RC_OK; +} /* * Attempt to parse string d, which must resemble either an ISO8601 formatted * date (e.g., 2021-10-10, 2020-01-01T10:10:10), disgregarding any trailing * garbage or space characters such that "2021-10-10x" or "2020-01-01 10:10:10" @@ -13709,18 +11073,18 @@ *op = fsl_strdup("LIKE"); if (*op == NULL) return RC(FSL_RC_ERROR, "%s", "fsl_strdup"); *glob = fsl_mprintf("%%%%%s%%%%", str); if (*glob == NULL) - return RC(FSL_RC_ERROR, "fsl_mprintf"); + return RC(FSL_RC_ERROR, "%s", "fsl_mprintf"); } else { *op = fsl_strdup("GLOB"); if (*op == NULL) - return RC(FSL_RC_ERROR, "fsl_strdup"); + return RC(FSL_RC_ERROR, "%s", "fsl_strdup"); *glob = fsl_mprintf("*%s*", str); if (*glob == NULL) - return RC(FSL_RC_ERROR, "fsl_mprintf"); + return RC(FSL_RC_ERROR, "%s", "fsl_mprintf"); } return FSL_RC_OK; } @@ -13754,30 +11118,36 @@ * The create permissions for the repository and checkout dirs are (perhaps * unintuitively) needed as fossil(1) creates temporary journal files in both. */ #ifndef HAVE_LANDLOCK static int -init_unveil(const char **paths, const char **perms, int n, bool disable) +init_unveil(const char *repodb, const char *ckoutdir, bool cfg) { #ifdef __OpenBSD__ - int i; - - for (i = 0; i < n; ++i) { - if (unveil(paths[i], perms[i]) == -1) - return RC(fsl_errno_to_rc(errno, FSL_RC_ACCESS), - "unveil(%s, \"%s\")", paths[i], perms[i]); - } - - if (disable) - if (unveil(NULL, NULL) == -1) - return RC(fsl_errno_to_rc(errno, FSL_RC_ACCESS), - "unveil"); + /* wc repo db for 'fnc config' command: fnc_conf_setopt(). */ + if (unveil(repodb, cfg ? "rwc" : "rw") == -1) + return RC(fsl_errno_to_rc(errno, FSL_RC_ACCESS), + "unveil(%s, \"rw\")", repodb); + + /* wc .fslckout for fsl_ckout_changes_scan() in cmd_diff(). */ + if (ckoutdir && unveil(ckoutdir, "rwc") == -1) + return RC(fsl_errno_to_rc(errno, FSL_RC_ACCESS), + "unveil(%s, \"rwc\")", ckoutdir); + + /* rwc /tmp for tmpfile() in help(), create_diff(), and run_blame(). */ + if (unveil(P_tmpdir, "rwc") == -1) + return RC(fsl_errno_to_rc(errno, FSL_RC_ACCESS), + "unveil(%s, \"rwc\")", P_tmpdir); + + if (unveil(NULL, NULL) == -1) + return RC(fsl_errno_to_rc(errno, FSL_RC_ACCESS), + "%s", "unveil"); #endif /* __OpenBSD__ */ return FSL_RC_OK; } -#endif +#else /* HAVE_LANDLOCK */ static const char * gettzfile(void) { static char ret[PATH_MAX]; const char *tzdir, *tz; @@ -13802,11 +11172,10 @@ /* * Sans libc wrappers, use the following shims provided by Landlock authors. * https://www.kernel.org/doc/html/latest/userspace-api/landlock.html */ -#ifdef HAVE_LANDLOCK #ifndef landlock_create_ruleset static inline int landlock_create_ruleset(const struct landlock_ruleset_attr *const attr, const size_t size, const __u32 flags) { @@ -13858,11 +11227,11 @@ if (rfd == -1) { /* Landlock is not supported or disabled by the kernel. */ if (errno == ENOSYS || errno == EOPNOTSUPP) return rc; return RC(fsl_errno_to_rc(errno, FSL_RC_ACCESS), - "landlock: failed to create ruleset"); + "landlock: %s", "failed to create ruleset"); } /* Iterate paths to grant fs permissions. */ for (i = 0; !rc && i < n; ++i) { struct stat sb; @@ -13881,23 +11250,23 @@ path_beneath.allowed_access = LANDLOCK_ACCESS_FS_READ_FILE; if (landlock_add_rule(rfd, LANDLOCK_RULE_PATH_BENEATH, &path_beneath, 0)) rc = RC(fsl_errno_to_rc(errno, FSL_RC_ACCESS), - "landlock: failed to update ruleset"); + "landlock: %s", "failed to update ruleset"); close(path_beneath.parent_fd); } } if (!rc && prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == -1) rc = RC(fsl_errno_to_rc(errno, FSL_RC_ACCESS), - "landlock: failed to restrict privileges"); + "landlock: %s", "failed to restrict privileges"); if (!rc && landlock_restrict_self(rfd, 0)) { rc = RC(fsl_errno_to_rc(errno, FSL_RC_ACCESS), - "landlock: failed to enforce ruleset"); + "landlock: %s", "failed to enforce ruleset"); } close(rfd); return rc; } #endif /* HAVE_LANDLOCK */