| | @@ -1,8 +1,8 @@ |
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | | -** version 3.38.0. By combining all the individual C code files into this |
| 3 | +** version 3.39.0. By combining all the individual C code files into this |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| | @@ -450,13 +450,13 @@ |
| 450 | 450 | ** |
| 451 | 451 | ** See also: [sqlite3_libversion()], |
| 452 | 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 453 | 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 454 | 454 | */ |
| 455 | | -#define SQLITE_VERSION "3.38.0" |
| 456 | | -#define SQLITE_VERSION_NUMBER 3038000 |
| 457 | | -#define SQLITE_SOURCE_ID "2022-01-12 00:28:12 adebb9d7478d092f16fb0ef7d5246ce152b166479d6f949110b5878b89ea2cec" |
| 455 | +#define SQLITE_VERSION "3.39.0" |
| 456 | +#define SQLITE_VERSION_NUMBER 3039000 |
| 457 | +#define SQLITE_SOURCE_ID "2022-03-23 10:04:52 43143ad131f17734fd2eff849e0a1bc2e26daf6a28c7e07d697d38732e6af5fc" |
| 458 | 458 | |
| 459 | 459 | /* |
| 460 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | 462 | ** |
| | @@ -870,11 +870,11 @@ |
| 870 | 870 | #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8)) |
| 871 | 871 | #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) |
| 872 | 872 | #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) |
| 873 | 873 | #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8)) |
| 874 | 874 | #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8)) |
| 875 | | -#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) |
| 875 | +#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */ |
| 876 | 876 | |
| 877 | 877 | /* |
| 878 | 878 | ** CAPI3REF: Flags For File Open Operations |
| 879 | 879 | ** |
| 880 | 880 | ** These bit values are intended for use in the |
| | @@ -4154,11 +4154,11 @@ |
| 4154 | 4154 | ** |
| 4155 | 4155 | ** ^If the most recent error references a specific token in the input |
| 4156 | 4156 | ** SQL, the sqlite3_error_offset() interface returns the byte offset |
| 4157 | 4157 | ** of the start of that token. ^The byte offset returned by |
| 4158 | 4158 | ** sqlite3_error_offset() assumes that the input SQL is UTF8. |
| 4159 | | -** ^If the most error does not reference a specific token in the input |
| 4159 | +** ^If the most recent error does not reference a specific token in the input |
| 4160 | 4160 | ** SQL, then the sqlite3_error_offset() function returns -1. |
| 4161 | 4161 | ** |
| 4162 | 4162 | ** When the serialized [threading mode] is in use, it might be the |
| 4163 | 4163 | ** case that a second error occurs on a separate thread in between |
| 4164 | 4164 | ** the time of the first error and the call to these interfaces. |
| | @@ -4588,10 +4588,14 @@ |
| 4588 | 4588 | ** ^For example, an UPDATE statement might have a WHERE clause that |
| 4589 | 4589 | ** makes it a no-op, but the sqlite3_stmt_readonly() result would still |
| 4590 | 4590 | ** be false. ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a |
| 4591 | 4591 | ** read-only no-op if the table already exists, but |
| 4592 | 4592 | ** sqlite3_stmt_readonly() still returns false for such a statement. |
| 4593 | +** |
| 4594 | +** ^If prepared statement X is an [EXPLAIN] or [EXPLAIN QUERY PLAN] |
| 4595 | +** statement, then sqlite3_stmt_readonly(X) returns the same value as |
| 4596 | +** if the EXPLAIN or EXPLAIN QUERY PLAN prefix were omitted. |
| 4593 | 4597 | */ |
| 4594 | 4598 | SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); |
| 4595 | 4599 | |
| 4596 | 4600 | /* |
| 4597 | 4601 | ** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement |
| | @@ -4656,10 +4660,12 @@ |
| 4656 | 4660 | ** still make the distinction between protected and unprotected |
| 4657 | 4661 | ** sqlite3_value objects even when not strictly required. |
| 4658 | 4662 | ** |
| 4659 | 4663 | ** ^The sqlite3_value objects that are passed as parameters into the |
| 4660 | 4664 | ** implementation of [application-defined SQL functions] are protected. |
| 4665 | +** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()] |
| 4666 | +** are protected. |
| 4661 | 4667 | ** ^The sqlite3_value object returned by |
| 4662 | 4668 | ** [sqlite3_column_value()] is unprotected. |
| 4663 | 4669 | ** Unprotected sqlite3_value objects may only be used as arguments |
| 4664 | 4670 | ** to [sqlite3_result_value()], [sqlite3_bind_value()], and |
| 4665 | 4671 | ** [sqlite3_value_dup()]. |
| | @@ -5276,10 +5282,14 @@ |
| 5276 | 5282 | ** bytes in the string, not the number of characters. |
| 5277 | 5283 | ** |
| 5278 | 5284 | ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(), |
| 5279 | 5285 | ** even empty strings, are always zero-terminated. ^The return |
| 5280 | 5286 | ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer. |
| 5287 | +** |
| 5288 | +** ^Strings returned by sqlite3_column_text16() always have the endianness |
| 5289 | +** which is native to the platform, regardless of the text encoding set |
| 5290 | +** for the database. |
| 5281 | 5291 | ** |
| 5282 | 5292 | ** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an |
| 5283 | 5293 | ** [unprotected sqlite3_value] object. In a multithreaded environment, |
| 5284 | 5294 | ** an unprotected sqlite3_value object may only be used safely with |
| 5285 | 5295 | ** [sqlite3_bind_value()] and [sqlite3_result_value()]. |
| | @@ -5290,11 +5300,11 @@ |
| 5290 | 5300 | ** Hence, the sqlite3_column_value() interface |
| 5291 | 5301 | ** is normally only useful within the implementation of |
| 5292 | 5302 | ** [application-defined SQL functions] or [virtual tables], not within |
| 5293 | 5303 | ** top-level application code. |
| 5294 | 5304 | ** |
| 5295 | | -** The these routines may attempt to convert the datatype of the result. |
| 5305 | +** These routines may attempt to convert the datatype of the result. |
| 5296 | 5306 | ** ^For example, if the internal representation is FLOAT and a text result |
| 5297 | 5307 | ** is requested, [sqlite3_snprintf()] is used internally to perform the |
| 5298 | 5308 | ** conversion automatically. ^(The following table details the conversions |
| 5299 | 5309 | ** that are applied: |
| 5300 | 5310 | ** |
| | @@ -5315,11 +5325,11 @@ |
| 5315 | 5325 | ** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER |
| 5316 | 5326 | ** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL |
| 5317 | 5327 | ** <tr><td> TEXT <td> BLOB <td> No change |
| 5318 | 5328 | ** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER |
| 5319 | 5329 | ** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL |
| 5320 | | -** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed |
| 5330 | +** <tr><td> BLOB <td> TEXT <td> [CAST] to TEXT, ensure zero terminator |
| 5321 | 5331 | ** </table> |
| 5322 | 5332 | ** </blockquote>)^ |
| 5323 | 5333 | ** |
| 5324 | 5334 | ** Note that when type conversions occur, pointers returned by prior |
| 5325 | 5335 | ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or |
| | @@ -5887,11 +5897,12 @@ |
| 5887 | 5897 | ** |
| 5888 | 5898 | ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value] |
| 5889 | 5899 | ** object D and returns a pointer to that copy. ^The [sqlite3_value] returned |
| 5890 | 5900 | ** is a [protected sqlite3_value] object even if the input is not. |
| 5891 | 5901 | ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a |
| 5892 | | -** memory allocation fails. |
| 5902 | +** memory allocation fails. ^If V is a [pointer value], then the result |
| 5903 | +** of sqlite3_value_dup(V) is a NULL value. |
| 5893 | 5904 | ** |
| 5894 | 5905 | ** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object |
| 5895 | 5906 | ** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer |
| 5896 | 5907 | ** then sqlite3_value_free(V) is a harmless no-op. |
| 5897 | 5908 | */ |
| | @@ -7435,28 +7446,60 @@ |
| 7435 | 7446 | /* |
| 7436 | 7447 | ** CAPI3REF: Virtual Table Constraint Operator Codes |
| 7437 | 7448 | ** |
| 7438 | 7449 | ** These macros define the allowed values for the |
| 7439 | 7450 | ** [sqlite3_index_info].aConstraint[].op field. Each value represents |
| 7440 | | -** an operator that is part of a constraint term in the wHERE clause of |
| 7451 | +** an operator that is part of a constraint term in the WHERE clause of |
| 7441 | 7452 | ** a query that uses a [virtual table]. |
| 7453 | +** |
| 7454 | +** ^The left-hand operand of the operator is given by the corresponding |
| 7455 | +** aConstraint[].iColumn field. ^An iColumn of -1 indicates the left-hand |
| 7456 | +** operand is the rowid. |
| 7457 | +** The SQLITE_INDEX_CONSTRAINT_LIMIT and SQLITE_INDEX_CONSTRAINT_OFFSET |
| 7458 | +** operators have no left-hand operand, and so for those operators the |
| 7459 | +** corresponding aConstraint[].iColumn is meaningless and should not be |
| 7460 | +** used. |
| 7461 | +** |
| 7462 | +** All operator values from SQLITE_INDEX_CONSTRAINT_FUNCTION through |
| 7463 | +** value 255 are reserved to represent functions that are overloaded |
| 7464 | +** by the [xFindFunction|xFindFunction method] of the virtual table |
| 7465 | +** implementation. |
| 7466 | +** |
| 7467 | +** The right-hand operands for each constraint might be accessible using |
| 7468 | +** the [sqlite3_vtab_rhs_value()] interface. Usually the right-hand |
| 7469 | +** operand is only available if it appears as a single constant literal |
| 7470 | +** in the input SQL. If the right-hand operand is another column or an |
| 7471 | +** expression (even a constant expression) or a parameter, then the |
| 7472 | +** sqlite3_vtab_rhs_value() probably will not be able to extract it. |
| 7473 | +** ^The SQLITE_INDEX_CONSTRAINT_ISNULL and |
| 7474 | +** SQLITE_INDEX_CONSTRAINT_ISNOTNULL operators have no right-hand operand |
| 7475 | +** and hence calls to sqlite3_vtab_rhs_value() for those operators will |
| 7476 | +** always return SQLITE_NOTFOUND. |
| 7477 | +** |
| 7478 | +** The collating sequence to be used for comparison can be found using |
| 7479 | +** the [sqlite3_vtab_collation()] interface. For most real-world virtual |
| 7480 | +** tables, the collating sequence of constraints does not matter (for example |
| 7481 | +** because the constraints are numeric) and so the sqlite3_vtab_collation() |
| 7482 | +** interface is no commonly needed. |
| 7442 | 7483 | */ |
| 7443 | | -#define SQLITE_INDEX_CONSTRAINT_EQ 2 |
| 7444 | | -#define SQLITE_INDEX_CONSTRAINT_GT 4 |
| 7445 | | -#define SQLITE_INDEX_CONSTRAINT_LE 8 |
| 7446 | | -#define SQLITE_INDEX_CONSTRAINT_LT 16 |
| 7447 | | -#define SQLITE_INDEX_CONSTRAINT_GE 32 |
| 7448 | | -#define SQLITE_INDEX_CONSTRAINT_MATCH 64 |
| 7449 | | -#define SQLITE_INDEX_CONSTRAINT_LIKE 65 |
| 7450 | | -#define SQLITE_INDEX_CONSTRAINT_GLOB 66 |
| 7451 | | -#define SQLITE_INDEX_CONSTRAINT_REGEXP 67 |
| 7452 | | -#define SQLITE_INDEX_CONSTRAINT_NE 68 |
| 7453 | | -#define SQLITE_INDEX_CONSTRAINT_ISNOT 69 |
| 7454 | | -#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70 |
| 7455 | | -#define SQLITE_INDEX_CONSTRAINT_ISNULL 71 |
| 7456 | | -#define SQLITE_INDEX_CONSTRAINT_IS 72 |
| 7457 | | -#define SQLITE_INDEX_CONSTRAINT_FUNCTION 150 |
| 7484 | +#define SQLITE_INDEX_CONSTRAINT_EQ 2 |
| 7485 | +#define SQLITE_INDEX_CONSTRAINT_GT 4 |
| 7486 | +#define SQLITE_INDEX_CONSTRAINT_LE 8 |
| 7487 | +#define SQLITE_INDEX_CONSTRAINT_LT 16 |
| 7488 | +#define SQLITE_INDEX_CONSTRAINT_GE 32 |
| 7489 | +#define SQLITE_INDEX_CONSTRAINT_MATCH 64 |
| 7490 | +#define SQLITE_INDEX_CONSTRAINT_LIKE 65 |
| 7491 | +#define SQLITE_INDEX_CONSTRAINT_GLOB 66 |
| 7492 | +#define SQLITE_INDEX_CONSTRAINT_REGEXP 67 |
| 7493 | +#define SQLITE_INDEX_CONSTRAINT_NE 68 |
| 7494 | +#define SQLITE_INDEX_CONSTRAINT_ISNOT 69 |
| 7495 | +#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70 |
| 7496 | +#define SQLITE_INDEX_CONSTRAINT_ISNULL 71 |
| 7497 | +#define SQLITE_INDEX_CONSTRAINT_IS 72 |
| 7498 | +#define SQLITE_INDEX_CONSTRAINT_LIMIT 73 |
| 7499 | +#define SQLITE_INDEX_CONSTRAINT_OFFSET 74 |
| 7500 | +#define SQLITE_INDEX_CONSTRAINT_FUNCTION 150 |
| 7458 | 7501 | |
| 7459 | 7502 | /* |
| 7460 | 7503 | ** CAPI3REF: Register A Virtual Table Implementation |
| 7461 | 7504 | ** METHOD: sqlite3 |
| 7462 | 7505 | ** |
| | @@ -7481,11 +7524,11 @@ |
| 7481 | 7524 | ** ^The sqlite3_create_module() |
| 7482 | 7525 | ** interface is equivalent to sqlite3_create_module_v2() with a NULL |
| 7483 | 7526 | ** destructor. |
| 7484 | 7527 | ** |
| 7485 | 7528 | ** ^If the third parameter (the pointer to the sqlite3_module object) is |
| 7486 | | -** NULL then no new module is create and any existing modules with the |
| 7529 | +** NULL then no new module is created and any existing modules with the |
| 7487 | 7530 | ** same name are dropped. |
| 7488 | 7531 | ** |
| 7489 | 7532 | ** See also: [sqlite3_drop_modules()] |
| 7490 | 7533 | */ |
| 7491 | 7534 | SQLITE_API int sqlite3_create_module( |
| | @@ -9775,25 +9818,26 @@ |
| 9775 | 9818 | */ |
| 9776 | 9819 | SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*); |
| 9777 | 9820 | |
| 9778 | 9821 | /* |
| 9779 | 9822 | ** CAPI3REF: Determine The Collation For a Virtual Table Constraint |
| 9823 | +** METHOD: sqlite3_index_info |
| 9780 | 9824 | ** |
| 9781 | 9825 | ** This function may only be called from within a call to the [xBestIndex] |
| 9782 | 9826 | ** method of a [virtual table]. This function returns a pointer to a string |
| 9783 | 9827 | ** that is the name of the appropriate collation sequence to use for text |
| 9784 | 9828 | ** comparisons on the constraint identified by its arguments. |
| 9785 | 9829 | ** |
| 9786 | | -** The first argument must be the pointer to the sqlite3_index_info object |
| 9830 | +** The first argument must be the pointer to the [sqlite3_index_info] object |
| 9787 | 9831 | ** that is the first parameter to the xBestIndex() method. The second argument |
| 9788 | 9832 | ** must be an index into the aConstraint[] array belonging to the |
| 9789 | 9833 | ** sqlite3_index_info structure passed to xBestIndex. |
| 9790 | 9834 | ** |
| 9791 | 9835 | ** Important: |
| 9792 | 9836 | ** The first parameter must be the same pointer that is passed into the |
| 9793 | 9837 | ** xBestMethod() method. The first parameter may not be a pointer to a |
| 9794 | | -** different sqlite3_index_info object, even an exact copy. |
| 9838 | +** different [sqlite3_index_info] object, even an exact copy. |
| 9795 | 9839 | ** |
| 9796 | 9840 | ** The return value is computed as follows: |
| 9797 | 9841 | ** |
| 9798 | 9842 | ** <ol> |
| 9799 | 9843 | ** <li><p> If the constraint comes from a WHERE clause expression that contains |
| | @@ -9807,10 +9851,247 @@ |
| 9807 | 9851 | ** <li><p> Otherwise, "BINARY" is returned. |
| 9808 | 9852 | ** </ol> |
| 9809 | 9853 | */ |
| 9810 | 9854 | SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int); |
| 9811 | 9855 | |
| 9856 | +/* |
| 9857 | +** CAPI3REF: Determine if a virtual table query is DISTINCT |
| 9858 | +** METHOD: sqlite3_index_info |
| 9859 | +** |
| 9860 | +** This API may only be used from within an [xBestIndex|xBestIndex method] |
| 9861 | +** of a [virtual table] implementation. The result of calling this |
| 9862 | +** interface from outside of xBestIndex() is undefined and probably harmful. |
| 9863 | +** |
| 9864 | +** ^The sqlite3_vtab_distinct() interface returns an integer between 0 and |
| 9865 | +** 3. The integer returned by sqlite3_vtab_distinct() |
| 9866 | +** gives the virtual table additional information about how the query |
| 9867 | +** planner wants the output to be ordered. As long as the virtual table |
| 9868 | +** can meet the ordering requirements of the query planner, it may set |
| 9869 | +** the "orderByConsumed" flag. |
| 9870 | +** |
| 9871 | +** <ol><li value="0"><p> |
| 9872 | +** ^If the sqlite3_vtab_distinct() interface returns 0, that means |
| 9873 | +** that the query planner needs the virtual table to return all rows in the |
| 9874 | +** sort order defined by the "nOrderBy" and "aOrderBy" fields of the |
| 9875 | +** [sqlite3_index_info] object. This is the default expectation. If the |
| 9876 | +** virtual table outputs all rows in sorted order, then it is always safe for |
| 9877 | +** the xBestIndex method to set the "orderByConsumed" flag, regardless of |
| 9878 | +** the return value from sqlite3_vtab_distinct(). |
| 9879 | +** <li value="1"><p> |
| 9880 | +** ^(If the sqlite3_vtab_distinct() interface returns 1, that means |
| 9881 | +** that the query planner does not need the rows to be returned in sorted order |
| 9882 | +** as long as all rows with the same values in all columns identified by the |
| 9883 | +** "aOrderBy" field are adjacent.)^ This mode is used when the query planner |
| 9884 | +** is doing a GROUP BY. |
| 9885 | +** <li value="2"><p> |
| 9886 | +** ^(If the sqlite3_vtab_distinct() interface returns 2, that means |
| 9887 | +** that the query planner does not need the rows returned in any particular |
| 9888 | +** order, as long as rows with the same values in all "aOrderBy" columns |
| 9889 | +** are adjacent.)^ ^(Furthermore, only a single row for each particular |
| 9890 | +** combination of values in the columns identified by the "aOrderBy" field |
| 9891 | +** needs to be returned.)^ ^It is always ok for two or more rows with the same |
| 9892 | +** values in all "aOrderBy" columns to be returned, as long as all such rows |
| 9893 | +** are adjacent. ^The virtual table may, if it chooses, omit extra rows |
| 9894 | +** that have the same value for all columns identified by "aOrderBy". |
| 9895 | +** ^However omitting the extra rows is optional. |
| 9896 | +** This mode is used for a DISTINCT query. |
| 9897 | +** <li value="3"><p> |
| 9898 | +** ^(If the sqlite3_vtab_distinct() interface returns 3, that means |
| 9899 | +** that the query planner needs only distinct rows but it does need the |
| 9900 | +** rows to be sorted.)^ ^The virtual table implementation is free to omit |
| 9901 | +** rows that are identical in all aOrderBy columns, if it wants to, but |
| 9902 | +** it is not required to omit any rows. This mode is used for queries |
| 9903 | +** that have both DISTINCT and ORDER BY clauses. |
| 9904 | +** </ol> |
| 9905 | +** |
| 9906 | +** ^For the purposes of comparing virtual table output values to see if the |
| 9907 | +** values are same value for sorting purposes, two NULL values are considered |
| 9908 | +** to be the same. In other words, the comparison operator is "IS" |
| 9909 | +** (or "IS NOT DISTINCT FROM") and not "==". |
| 9910 | +** |
| 9911 | +** If a virtual table implementation is unable to meet the requirements |
| 9912 | +** specified above, then it must not set the "orderByConsumed" flag in the |
| 9913 | +** [sqlite3_index_info] object or an incorrect answer may result. |
| 9914 | +** |
| 9915 | +** ^A virtual table implementation is always free to return rows in any order |
| 9916 | +** it wants, as long as the "orderByConsumed" flag is not set. ^When the |
| 9917 | +** the "orderByConsumed" flag is unset, the query planner will add extra |
| 9918 | +** [bytecode] to ensure that the final results returned by the SQL query are |
| 9919 | +** ordered correctly. The use of the "orderByConsumed" flag and the |
| 9920 | +** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful |
| 9921 | +** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed" |
| 9922 | +** flag might help queries against a virtual table to run faster. Being |
| 9923 | +** overly aggressive and setting the "orderByConsumed" flag when it is not |
| 9924 | +** valid to do so, on the other hand, might cause SQLite to return incorrect |
| 9925 | +** results. |
| 9926 | +*/ |
| 9927 | +SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*); |
| 9928 | + |
| 9929 | +/* |
| 9930 | +** CAPI3REF: Identify and handle IN constraints in xBestIndex |
| 9931 | +** |
| 9932 | +** This interface may only be used from within an |
| 9933 | +** [xBestIndex|xBestIndex() method] of a [virtual table] implementation. |
| 9934 | +** The result of invoking this interface from any other context is |
| 9935 | +** undefined and probably harmful. |
| 9936 | +** |
| 9937 | +** ^(A constraint on a virtual table of the form |
| 9938 | +** "[IN operator|column IN (...)]" is |
| 9939 | +** communicated to the xBestIndex method as a |
| 9940 | +** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use |
| 9941 | +** this constraint, it must set the corresponding |
| 9942 | +** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under |
| 9943 | +** the usual mode of handling IN operators, SQLite generates [bytecode] |
| 9944 | +** that invokes the [xFilter|xFilter() method] once for each value |
| 9945 | +** on the right-hand side of the IN operator.)^ Thus the virtual table |
| 9946 | +** only sees a single value from the right-hand side of the IN operator |
| 9947 | +** at a time. |
| 9948 | +** |
| 9949 | +** In some cases, however, it would be advantageous for the virtual |
| 9950 | +** table to see all values on the right-hand of the IN operator all at |
| 9951 | +** once. The sqlite3_vtab_in() interfaces facilitates this in two ways: |
| 9952 | +** |
| 9953 | +** <ol> |
| 9954 | +** <li><p> |
| 9955 | +** ^A call to sqlite3_vtab_in(P,N,-1) will return true (non-zero) |
| 9956 | +** if and only if the [sqlite3_index_info|P->aConstraint][N] constraint |
| 9957 | +** is an [IN operator] that can be processed all at once. ^In other words, |
| 9958 | +** sqlite3_vtab_in() with -1 in the third argument is a mechanism |
| 9959 | +** by which the virtual table can ask SQLite if all-at-once processing |
| 9960 | +** of the IN operator is even possible. |
| 9961 | +** |
| 9962 | +** <li><p> |
| 9963 | +** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates |
| 9964 | +** to SQLite that the virtual table does or does not want to process |
| 9965 | +** the IN operator all-at-once, respectively. ^Thus when the third |
| 9966 | +** parameter (F) is non-negative, this interface is the mechanism by |
| 9967 | +** which the virtual table tells SQLite how it wants to process the |
| 9968 | +** IN operator. |
| 9969 | +** </ol> |
| 9970 | +** |
| 9971 | +** ^The sqlite3_vtab_in(P,N,F) interface can be invoked multiple times |
| 9972 | +** within the same xBestIndex method call. ^For any given P,N pair, |
| 9973 | +** the return value from sqlite3_vtab_in(P,N,F) will always be the same |
| 9974 | +** within the same xBestIndex call. ^If the interface returns true |
| 9975 | +** (non-zero), that means that the constraint is an IN operator |
| 9976 | +** that can be processed all-at-once. ^If the constraint is not an IN |
| 9977 | +** operator or cannot be processed all-at-once, then the interface returns |
| 9978 | +** false. |
| 9979 | +** |
| 9980 | +** ^(All-at-once processing of the IN operator is selected if both of the |
| 9981 | +** following conditions are met: |
| 9982 | +** |
| 9983 | +** <ol> |
| 9984 | +** <li><p> The P->aConstraintUsage[N].argvIndex value is set to a positive |
| 9985 | +** integer. This is how the virtual table tells SQLite that it wants to |
| 9986 | +** use the N-th constraint. |
| 9987 | +** |
| 9988 | +** <li><p> The last call to sqlite3_vtab_in(P,N,F) for which F was |
| 9989 | +** non-negative had F>=1. |
| 9990 | +** </ol>)^ |
| 9991 | +** |
| 9992 | +** ^If either or both of the conditions above are false, then SQLite uses |
| 9993 | +** the traditional one-at-a-time processing strategy for the IN constraint. |
| 9994 | +** ^If both conditions are true, then the argvIndex-th parameter to the |
| 9995 | +** xFilter method will be an [sqlite3_value] that appears to be NULL, |
| 9996 | +** but which can be passed to [sqlite3_vtab_in_first()] and |
| 9997 | +** [sqlite3_vtab_in_next()] to find all values on the right-hand side |
| 9998 | +** of the IN constraint. |
| 9999 | +*/ |
| 10000 | +SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle); |
| 10001 | + |
| 10002 | +/* |
| 10003 | +** CAPI3REF: Find all elements on the right-hand side of an IN constraint. |
| 10004 | +** |
| 10005 | +** These interfaces are only useful from within the |
| 10006 | +** [xFilter|xFilter() method] of a [virtual table] implementation. |
| 10007 | +** The result of invoking these interfaces from any other context |
| 10008 | +** is undefined and probably harmful. |
| 10009 | +** |
| 10010 | +** The X parameter in a call to sqlite3_vtab_in_first(X,P) or |
| 10011 | +** sqlite3_vtab_in_next(X,P) must be one of the parameters to the |
| 10012 | +** xFilter method which invokes these routines, and specifically |
| 10013 | +** a parameter that was previously selected for all-at-once IN constraint |
| 10014 | +** processing use the [sqlite3_vtab_in()] interface in the |
| 10015 | +** [xBestIndex|xBestIndex method]. ^(If the X parameter is not |
| 10016 | +** an xFilter argument that was selected for all-at-once IN constraint |
| 10017 | +** processing, then these routines return [SQLITE_MISUSE])^ or perhaps |
| 10018 | +** exhibit some other undefined or harmful behavior. |
| 10019 | +** |
| 10020 | +** ^(Use these routines to access all values on the right-hand side |
| 10021 | +** of the IN constraint using code like the following: |
| 10022 | +** |
| 10023 | +** <blockquote><pre> |
| 10024 | +** for(rc=sqlite3_vtab_in_first(pList, &pVal); |
| 10025 | +** rc==SQLITE_OK && pVal |
| 10026 | +** rc=sqlite3_vtab_in_next(pList, &pVal) |
| 10027 | +** ){ |
| 10028 | +** // do something with pVal |
| 10029 | +** } |
| 10030 | +** if( rc!=SQLITE_OK ){ |
| 10031 | +** // an error has occurred |
| 10032 | +** } |
| 10033 | +** </pre></blockquote>)^ |
| 10034 | +** |
| 10035 | +** ^On success, the sqlite3_vtab_in_first(X,P) and sqlite3_vtab_in_next(X,P) |
| 10036 | +** routines return SQLITE_OK and set *P to point to the first or next value |
| 10037 | +** on the RHS of the IN constraint. ^If there are no more values on the |
| 10038 | +** right hand side of the IN constraint, then *P is set to NULL and these |
| 10039 | +** routines return [SQLITE_DONE]. ^The return value might be |
| 10040 | +** some other value, such as SQLITE_NOMEM, in the event of a malfunction. |
| 10041 | +** |
| 10042 | +** The *ppOut values returned by these routines are only valid until the |
| 10043 | +** next call to either of these routines or until the end of the xFilter |
| 10044 | +** method from which these routines were called. If the virtual table |
| 10045 | +** implementation needs to retain the *ppOut values for longer, it must make |
| 10046 | +** copies. The *ppOut values are [protected sqlite3_value|protected]. |
| 10047 | +*/ |
| 10048 | +SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut); |
| 10049 | +SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut); |
| 10050 | + |
| 10051 | +/* |
| 10052 | +** CAPI3REF: Constraint values in xBestIndex() |
| 10053 | +** METHOD: sqlite3_index_info |
| 10054 | +** |
| 10055 | +** This API may only be used from within the [xBestIndex|xBestIndex method] |
| 10056 | +** of a [virtual table] implementation. The result of calling this interface |
| 10057 | +** from outside of an xBestIndex method are undefined and probably harmful. |
| 10058 | +** |
| 10059 | +** ^When the sqlite3_vtab_rhs_value(P,J,V) interface is invoked from within |
| 10060 | +** the [xBestIndex] method of a [virtual table] implementation, with P being |
| 10061 | +** a copy of the [sqlite3_index_info] object pointer passed into xBestIndex and |
| 10062 | +** J being a 0-based index into P->aConstraint[], then this routine |
| 10063 | +** attempts to set *V to the value of the right-hand operand of |
| 10064 | +** that constraint if the right-hand operand is known. ^If the |
| 10065 | +** right-hand operand is not known, then *V is set to a NULL pointer. |
| 10066 | +** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if |
| 10067 | +** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V) |
| 10068 | +** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th |
| 10069 | +** constraint is not available. ^The sqlite3_vtab_rhs_value() interface |
| 10070 | +** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if |
| 10071 | +** something goes wrong. |
| 10072 | +** |
| 10073 | +** The sqlite3_vtab_rhs_value() interface is usually only successful if |
| 10074 | +** the right-hand operand of a constraint is a literal value in the original |
| 10075 | +** SQL statement. If the right-hand operand is an expression or a reference |
| 10076 | +** to some other column or a [host parameter], then sqlite3_vtab_rhs_value() |
| 10077 | +** will probably return [SQLITE_NOTFOUND]. |
| 10078 | +** |
| 10079 | +** ^(Some constraints, such as [SQLITE_INDEX_CONSTRAINT_ISNULL] and |
| 10080 | +** [SQLITE_INDEX_CONSTRAINT_ISNOTNULL], have no right-hand operand. For such |
| 10081 | +** constraints, sqlite3_vtab_rhs_value() always returns SQLITE_NOTFOUND.)^ |
| 10082 | +** |
| 10083 | +** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value |
| 10084 | +** and remains valid for the duration of the xBestIndex method call. |
| 10085 | +** ^When xBestIndex returns, the sqlite3_value object returned by |
| 10086 | +** sqlite3_vtab_rhs_value() is automatically deallocated. |
| 10087 | +** |
| 10088 | +** The "_rhs_" in the name of this routine is an abbreviation for |
| 10089 | +** "Right-Hand Side". |
| 10090 | +*/ |
| 10091 | +SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal); |
| 10092 | + |
| 9812 | 10093 | /* |
| 9813 | 10094 | ** CAPI3REF: Conflict resolution modes |
| 9814 | 10095 | ** KEYWORDS: {conflict resolution mode} |
| 9815 | 10096 | ** |
| 9816 | 10097 | ** These constants are returned by [sqlite3_vtab_on_conflict()] to |
| | @@ -14246,11 +14527,11 @@ |
| 14246 | 14527 | ** one parameter that destructors normally want. So we have to introduce |
| 14247 | 14528 | ** this magic value that the code knows to handle differently. Any |
| 14248 | 14529 | ** pointer will work here as long as it is distinct from SQLITE_STATIC |
| 14249 | 14530 | ** and SQLITE_TRANSIENT. |
| 14250 | 14531 | */ |
| 14251 | | -#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3OomFault) |
| 14532 | +#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3OomClear) |
| 14252 | 14533 | |
| 14253 | 14534 | /* |
| 14254 | 14535 | ** When SQLITE_OMIT_WSD is defined, it means that the target platform does |
| 14255 | 14536 | ** not support Writable Static Data (WSD) such as global and static variables. |
| 14256 | 14537 | ** All variables must either be on the stack or dynamically allocated from |
| | @@ -14374,14 +14655,15 @@ |
| 14374 | 14655 | #define BMS ((int)(sizeof(Bitmask)*8)) |
| 14375 | 14656 | |
| 14376 | 14657 | /* |
| 14377 | 14658 | ** A bit in a Bitmask |
| 14378 | 14659 | */ |
| 14379 | | -#define MASKBIT(n) (((Bitmask)1)<<(n)) |
| 14380 | | -#define MASKBIT64(n) (((u64)1)<<(n)) |
| 14381 | | -#define MASKBIT32(n) (((unsigned int)1)<<(n)) |
| 14382 | | -#define ALLBITS ((Bitmask)-1) |
| 14660 | +#define MASKBIT(n) (((Bitmask)1)<<(n)) |
| 14661 | +#define MASKBIT64(n) (((u64)1)<<(n)) |
| 14662 | +#define MASKBIT32(n) (((unsigned int)1)<<(n)) |
| 14663 | +#define SMASKBIT32(n) ((n)<=31?((unsigned int)1)<<(n):0) |
| 14664 | +#define ALLBITS ((Bitmask)-1) |
| 14383 | 14665 | |
| 14384 | 14666 | /* A VList object records a mapping between parameters/variables/wildcards |
| 14385 | 14667 | ** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer |
| 14386 | 14668 | ** variable number associated with that parameter. See the format description |
| 14387 | 14669 | ** on the sqlite3VListAdd() routine for more information. A VList is really |
| | @@ -14439,18 +14721,19 @@ |
| 14439 | 14721 | ** Handle type for pages. |
| 14440 | 14722 | */ |
| 14441 | 14723 | typedef struct PgHdr DbPage; |
| 14442 | 14724 | |
| 14443 | 14725 | /* |
| 14444 | | -** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is |
| 14726 | +** Page number PAGER_SJ_PGNO is never used in an SQLite database (it is |
| 14445 | 14727 | ** reserved for working around a windows/posix incompatibility). It is |
| 14446 | 14728 | ** used in the journal to signify that the remainder of the journal file |
| 14447 | 14729 | ** is devoted to storing a super-journal name - there are no more pages to |
| 14448 | 14730 | ** roll back. See comments for function writeSuperJournal() in pager.c |
| 14449 | 14731 | ** for details. |
| 14450 | 14732 | */ |
| 14451 | | -#define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1)) |
| 14733 | +#define PAGER_SJ_PGNO_COMPUTED(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1)) |
| 14734 | +#define PAGER_SJ_PGNO(x) ((x)->lckPgno) |
| 14452 | 14735 | |
| 14453 | 14736 | /* |
| 14454 | 14737 | ** Allowed values for the flags parameter to sqlite3PagerOpen(). |
| 14455 | 14738 | ** |
| 14456 | 14739 | ** NOTE: These values must match the corresponding BTREE_ values in btree.h. |
| | @@ -15123,11 +15406,10 @@ |
| 15123 | 15406 | SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */ |
| 15124 | 15407 | Table *pTab; /* Used when p4type is P4_TABLE */ |
| 15125 | 15408 | #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 15126 | 15409 | Expr *pExpr; /* Used when p4type is P4_EXPR */ |
| 15127 | 15410 | #endif |
| 15128 | | - int (*xAdvance)(BtCursor *, int); |
| 15129 | 15411 | } p4; |
| 15130 | 15412 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 15131 | 15413 | char *zComment; /* Comment to improve readability */ |
| 15132 | 15414 | #endif |
| 15133 | 15415 | #ifdef VDBE_PROFILE |
| | @@ -15174,25 +15456,23 @@ |
| 15174 | 15456 | #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */ |
| 15175 | 15457 | #define P4_STATIC (-1) /* Pointer to a static string */ |
| 15176 | 15458 | #define P4_COLLSEQ (-2) /* P4 is a pointer to a CollSeq structure */ |
| 15177 | 15459 | #define P4_INT32 (-3) /* P4 is a 32-bit signed integer */ |
| 15178 | 15460 | #define P4_SUBPROGRAM (-4) /* P4 is a pointer to a SubProgram structure */ |
| 15179 | | -#define P4_ADVANCE (-5) /* P4 is a pointer to BtreeNext() or BtreePrev() */ |
| 15180 | | -#define P4_TABLE (-6) /* P4 is a pointer to a Table structure */ |
| 15461 | +#define P4_TABLE (-5) /* P4 is a pointer to a Table structure */ |
| 15181 | 15462 | /* Above do not own any resources. Must free those below */ |
| 15182 | | -#define P4_FREE_IF_LE (-7) |
| 15183 | | -#define P4_DYNAMIC (-7) /* Pointer to memory from sqliteMalloc() */ |
| 15184 | | -#define P4_FUNCDEF (-8) /* P4 is a pointer to a FuncDef structure */ |
| 15185 | | -#define P4_KEYINFO (-9) /* P4 is a pointer to a KeyInfo structure */ |
| 15186 | | -#define P4_EXPR (-10) /* P4 is a pointer to an Expr tree */ |
| 15187 | | -#define P4_MEM (-11) /* P4 is a pointer to a Mem* structure */ |
| 15188 | | -#define P4_VTAB (-12) /* P4 is a pointer to an sqlite3_vtab structure */ |
| 15189 | | -#define P4_REAL (-13) /* P4 is a 64-bit floating point value */ |
| 15190 | | -#define P4_INT64 (-14) /* P4 is a 64-bit signed integer */ |
| 15191 | | -#define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */ |
| 15192 | | -#define P4_FUNCCTX (-16) /* P4 is a pointer to an sqlite3_context object */ |
| 15193 | | -#define P4_DYNBLOB (-17) /* Pointer to memory from sqliteMalloc() */ |
| 15463 | +#define P4_FREE_IF_LE (-6) |
| 15464 | +#define P4_DYNAMIC (-6) /* Pointer to memory from sqliteMalloc() */ |
| 15465 | +#define P4_FUNCDEF (-7) /* P4 is a pointer to a FuncDef structure */ |
| 15466 | +#define P4_KEYINFO (-8) /* P4 is a pointer to a KeyInfo structure */ |
| 15467 | +#define P4_EXPR (-9) /* P4 is a pointer to an Expr tree */ |
| 15468 | +#define P4_MEM (-10) /* P4 is a pointer to a Mem* structure */ |
| 15469 | +#define P4_VTAB (-11) /* P4 is a pointer to an sqlite3_vtab structure */ |
| 15470 | +#define P4_REAL (-12) /* P4 is a 64-bit floating point value */ |
| 15471 | +#define P4_INT64 (-13) /* P4 is a 64-bit signed integer */ |
| 15472 | +#define P4_INTARRAY (-14) /* P4 is a vector of 32-bit integers */ |
| 15473 | +#define P4_FUNCCTX (-15) /* P4 is a pointer to an sqlite3_context object */ |
| 15194 | 15474 | |
| 15195 | 15475 | /* Error message codes for OP_Halt */ |
| 15196 | 15476 | #define P5_ConstraintNotNull 1 |
| 15197 | 15477 | #define P5_ConstraintUnique 2 |
| 15198 | 15478 | #define P5_ConstraintCheck 3 |
| | @@ -15233,46 +15513,46 @@ |
| 15233 | 15513 | /* Automatically generated. Do not edit */ |
| 15234 | 15514 | /* See the tool/mkopcodeh.tcl script for details */ |
| 15235 | 15515 | #define OP_Savepoint 0 |
| 15236 | 15516 | #define OP_AutoCommit 1 |
| 15237 | 15517 | #define OP_Transaction 2 |
| 15238 | | -#define OP_SorterNext 3 /* jump */ |
| 15239 | | -#define OP_Prev 4 /* jump */ |
| 15240 | | -#define OP_Next 5 /* jump */ |
| 15241 | | -#define OP_Checkpoint 6 |
| 15242 | | -#define OP_JournalMode 7 |
| 15243 | | -#define OP_Vacuum 8 |
| 15244 | | -#define OP_VFilter 9 /* jump, synopsis: iplan=r[P3] zplan='P4' */ |
| 15245 | | -#define OP_VUpdate 10 /* synopsis: data=r[P3@P2] */ |
| 15246 | | -#define OP_Goto 11 /* jump */ |
| 15247 | | -#define OP_Gosub 12 /* jump */ |
| 15248 | | -#define OP_InitCoroutine 13 /* jump */ |
| 15249 | | -#define OP_Yield 14 /* jump */ |
| 15250 | | -#define OP_MustBeInt 15 /* jump */ |
| 15251 | | -#define OP_Jump 16 /* jump */ |
| 15252 | | -#define OP_Once 17 /* jump */ |
| 15253 | | -#define OP_If 18 /* jump */ |
| 15518 | +#define OP_Checkpoint 3 |
| 15519 | +#define OP_JournalMode 4 |
| 15520 | +#define OP_Vacuum 5 |
| 15521 | +#define OP_VFilter 6 /* jump, synopsis: iplan=r[P3] zplan='P4' */ |
| 15522 | +#define OP_VUpdate 7 /* synopsis: data=r[P3@P2] */ |
| 15523 | +#define OP_Goto 8 /* jump */ |
| 15524 | +#define OP_Gosub 9 /* jump */ |
| 15525 | +#define OP_InitCoroutine 10 /* jump */ |
| 15526 | +#define OP_Yield 11 /* jump */ |
| 15527 | +#define OP_MustBeInt 12 /* jump */ |
| 15528 | +#define OP_Jump 13 /* jump */ |
| 15529 | +#define OP_Once 14 /* jump */ |
| 15530 | +#define OP_If 15 /* jump */ |
| 15531 | +#define OP_IfNot 16 /* jump */ |
| 15532 | +#define OP_IsNullOrType 17 /* jump, synopsis: if typeof(r[P1]) IN (P3,5) goto P2 */ |
| 15533 | +#define OP_IfNullRow 18 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */ |
| 15254 | 15534 | #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */ |
| 15255 | | -#define OP_IfNot 20 /* jump */ |
| 15256 | | -#define OP_IsNullOrType 21 /* jump, synopsis: if typeof(r[P1]) IN (P3,5) goto P2 */ |
| 15257 | | -#define OP_IfNullRow 22 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */ |
| 15258 | | -#define OP_SeekLT 23 /* jump, synopsis: key=r[P3@P4] */ |
| 15259 | | -#define OP_SeekLE 24 /* jump, synopsis: key=r[P3@P4] */ |
| 15260 | | -#define OP_SeekGE 25 /* jump, synopsis: key=r[P3@P4] */ |
| 15261 | | -#define OP_SeekGT 26 /* jump, synopsis: key=r[P3@P4] */ |
| 15262 | | -#define OP_IfNotOpen 27 /* jump, synopsis: if( !csr[P1] ) goto P2 */ |
| 15263 | | -#define OP_IfNoHope 28 /* jump, synopsis: key=r[P3@P4] */ |
| 15264 | | -#define OP_NoConflict 29 /* jump, synopsis: key=r[P3@P4] */ |
| 15265 | | -#define OP_NotFound 30 /* jump, synopsis: key=r[P3@P4] */ |
| 15266 | | -#define OP_Found 31 /* jump, synopsis: key=r[P3@P4] */ |
| 15267 | | -#define OP_SeekRowid 32 /* jump, synopsis: intkey=r[P3] */ |
| 15268 | | -#define OP_NotExists 33 /* jump, synopsis: intkey=r[P3] */ |
| 15269 | | -#define OP_Last 34 /* jump */ |
| 15270 | | -#define OP_IfSmaller 35 /* jump */ |
| 15271 | | -#define OP_SorterSort 36 /* jump */ |
| 15272 | | -#define OP_Sort 37 /* jump */ |
| 15273 | | -#define OP_Rewind 38 /* jump */ |
| 15535 | +#define OP_SeekLT 20 /* jump, synopsis: key=r[P3@P4] */ |
| 15536 | +#define OP_SeekLE 21 /* jump, synopsis: key=r[P3@P4] */ |
| 15537 | +#define OP_SeekGE 22 /* jump, synopsis: key=r[P3@P4] */ |
| 15538 | +#define OP_SeekGT 23 /* jump, synopsis: key=r[P3@P4] */ |
| 15539 | +#define OP_IfNotOpen 24 /* jump, synopsis: if( !csr[P1] ) goto P2 */ |
| 15540 | +#define OP_IfNoHope 25 /* jump, synopsis: key=r[P3@P4] */ |
| 15541 | +#define OP_NoConflict 26 /* jump, synopsis: key=r[P3@P4] */ |
| 15542 | +#define OP_NotFound 27 /* jump, synopsis: key=r[P3@P4] */ |
| 15543 | +#define OP_Found 28 /* jump, synopsis: key=r[P3@P4] */ |
| 15544 | +#define OP_SeekRowid 29 /* jump, synopsis: intkey=r[P3] */ |
| 15545 | +#define OP_NotExists 30 /* jump, synopsis: intkey=r[P3] */ |
| 15546 | +#define OP_Last 31 /* jump */ |
| 15547 | +#define OP_IfSmaller 32 /* jump */ |
| 15548 | +#define OP_SorterSort 33 /* jump */ |
| 15549 | +#define OP_Sort 34 /* jump */ |
| 15550 | +#define OP_Rewind 35 /* jump */ |
| 15551 | +#define OP_SorterNext 36 /* jump */ |
| 15552 | +#define OP_Prev 37 /* jump */ |
| 15553 | +#define OP_Next 38 /* jump */ |
| 15274 | 15554 | #define OP_IdxLE 39 /* jump, synopsis: key=r[P3@P4] */ |
| 15275 | 15555 | #define OP_IdxGT 40 /* jump, synopsis: key=r[P3@P4] */ |
| 15276 | 15556 | #define OP_IdxLT 41 /* jump, synopsis: key=r[P3@P4] */ |
| 15277 | 15557 | #define OP_IdxGE 42 /* jump, synopsis: key=r[P3@P4] */ |
| 15278 | 15558 | #define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */ |
| | @@ -15301,41 +15581,41 @@ |
| 15301 | 15581 | #define OP_Function 66 /* synopsis: r[P3]=func(r[P2@NP]) */ |
| 15302 | 15582 | #define OP_Return 67 |
| 15303 | 15583 | #define OP_EndCoroutine 68 |
| 15304 | 15584 | #define OP_HaltIfNull 69 /* synopsis: if r[P3]=null halt */ |
| 15305 | 15585 | #define OP_Halt 70 |
| 15306 | | -#define OP_Integer 71 /* synopsis: r[P2]=P1 */ |
| 15307 | | -#define OP_Int64 72 /* synopsis: r[P2]=P4 */ |
| 15308 | | -#define OP_String 73 /* synopsis: r[P2]='P4' (len=P1) */ |
| 15309 | | -#define OP_Null 74 /* synopsis: r[P2..P3]=NULL */ |
| 15310 | | -#define OP_SoftNull 75 /* synopsis: r[P1]=NULL */ |
| 15311 | | -#define OP_Blob 76 /* synopsis: r[P2]=P4 (len=P1) */ |
| 15312 | | -#define OP_Variable 77 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 15313 | | -#define OP_Move 78 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 15314 | | -#define OP_Copy 79 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ |
| 15315 | | -#define OP_SCopy 80 /* synopsis: r[P2]=r[P1] */ |
| 15316 | | -#define OP_IntCopy 81 /* synopsis: r[P2]=r[P1] */ |
| 15317 | | -#define OP_FkCheck 82 |
| 15318 | | -#define OP_ResultRow 83 /* synopsis: output=r[P1@P2] */ |
| 15319 | | -#define OP_CollSeq 84 |
| 15320 | | -#define OP_AddImm 85 /* synopsis: r[P1]=r[P1]+P2 */ |
| 15321 | | -#define OP_RealAffinity 86 |
| 15322 | | -#define OP_Cast 87 /* synopsis: affinity(r[P1]) */ |
| 15323 | | -#define OP_Permutation 88 |
| 15324 | | -#define OP_Compare 89 /* synopsis: r[P1@P3] <-> r[P2@P3] */ |
| 15325 | | -#define OP_IsTrue 90 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */ |
| 15326 | | -#define OP_ZeroOrNull 91 /* synopsis: r[P2] = 0 OR NULL */ |
| 15327 | | -#define OP_Offset 92 /* synopsis: r[P3] = sqlite_offset(P1) */ |
| 15328 | | -#define OP_Column 93 /* synopsis: r[P3]=PX */ |
| 15329 | | -#define OP_TypeCheck 94 /* synopsis: typecheck(r[P1@P2]) */ |
| 15330 | | -#define OP_Affinity 95 /* synopsis: affinity(r[P1@P2]) */ |
| 15331 | | -#define OP_MakeRecord 96 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ |
| 15332 | | -#define OP_Count 97 /* synopsis: r[P2]=count() */ |
| 15333 | | -#define OP_ReadCookie 98 |
| 15334 | | -#define OP_SetCookie 99 |
| 15335 | | -#define OP_ReopenIdx 100 /* synopsis: root=P2 iDb=P3 */ |
| 15336 | | -#define OP_OpenRead 101 /* synopsis: root=P2 iDb=P3 */ |
| 15586 | +#define OP_BeginSubrtn 71 /* synopsis: r[P2]=P1 */ |
| 15587 | +#define OP_Integer 72 /* synopsis: r[P2]=P1 */ |
| 15588 | +#define OP_Int64 73 /* synopsis: r[P2]=P4 */ |
| 15589 | +#define OP_String 74 /* synopsis: r[P2]='P4' (len=P1) */ |
| 15590 | +#define OP_Null 75 /* synopsis: r[P2..P3]=NULL */ |
| 15591 | +#define OP_SoftNull 76 /* synopsis: r[P1]=NULL */ |
| 15592 | +#define OP_Blob 77 /* synopsis: r[P2]=P4 (len=P1) */ |
| 15593 | +#define OP_Variable 78 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 15594 | +#define OP_Move 79 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 15595 | +#define OP_Copy 80 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ |
| 15596 | +#define OP_SCopy 81 /* synopsis: r[P2]=r[P1] */ |
| 15597 | +#define OP_IntCopy 82 /* synopsis: r[P2]=r[P1] */ |
| 15598 | +#define OP_FkCheck 83 |
| 15599 | +#define OP_ResultRow 84 /* synopsis: output=r[P1@P2] */ |
| 15600 | +#define OP_CollSeq 85 |
| 15601 | +#define OP_AddImm 86 /* synopsis: r[P1]=r[P1]+P2 */ |
| 15602 | +#define OP_RealAffinity 87 |
| 15603 | +#define OP_Cast 88 /* synopsis: affinity(r[P1]) */ |
| 15604 | +#define OP_Permutation 89 |
| 15605 | +#define OP_Compare 90 /* synopsis: r[P1@P3] <-> r[P2@P3] */ |
| 15606 | +#define OP_IsTrue 91 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */ |
| 15607 | +#define OP_ZeroOrNull 92 /* synopsis: r[P2] = 0 OR NULL */ |
| 15608 | +#define OP_Offset 93 /* synopsis: r[P3] = sqlite_offset(P1) */ |
| 15609 | +#define OP_Column 94 /* synopsis: r[P3]=PX */ |
| 15610 | +#define OP_TypeCheck 95 /* synopsis: typecheck(r[P1@P2]) */ |
| 15611 | +#define OP_Affinity 96 /* synopsis: affinity(r[P1@P2]) */ |
| 15612 | +#define OP_MakeRecord 97 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ |
| 15613 | +#define OP_Count 98 /* synopsis: r[P2]=count() */ |
| 15614 | +#define OP_ReadCookie 99 |
| 15615 | +#define OP_SetCookie 100 |
| 15616 | +#define OP_ReopenIdx 101 /* synopsis: root=P2 iDb=P3 */ |
| 15337 | 15617 | #define OP_BitAnd 102 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */ |
| 15338 | 15618 | #define OP_BitOr 103 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */ |
| 15339 | 15619 | #define OP_ShiftLeft 104 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */ |
| 15340 | 15620 | #define OP_ShiftRight 105 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */ |
| 15341 | 15621 | #define OP_Add 106 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */ |
| | @@ -15342,82 +15622,84 @@ |
| 15342 | 15622 | #define OP_Subtract 107 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */ |
| 15343 | 15623 | #define OP_Multiply 108 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */ |
| 15344 | 15624 | #define OP_Divide 109 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */ |
| 15345 | 15625 | #define OP_Remainder 110 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */ |
| 15346 | 15626 | #define OP_Concat 111 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */ |
| 15347 | | -#define OP_OpenWrite 112 /* synopsis: root=P2 iDb=P3 */ |
| 15348 | | -#define OP_OpenDup 113 |
| 15627 | +#define OP_OpenRead 112 /* synopsis: root=P2 iDb=P3 */ |
| 15628 | +#define OP_OpenWrite 113 /* synopsis: root=P2 iDb=P3 */ |
| 15349 | 15629 | #define OP_BitNot 114 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */ |
| 15350 | | -#define OP_OpenAutoindex 115 /* synopsis: nColumn=P2 */ |
| 15351 | | -#define OP_OpenEphemeral 116 /* synopsis: nColumn=P2 */ |
| 15630 | +#define OP_OpenDup 115 |
| 15631 | +#define OP_OpenAutoindex 116 /* synopsis: nColumn=P2 */ |
| 15352 | 15632 | #define OP_String8 117 /* same as TK_STRING, synopsis: r[P2]='P4' */ |
| 15353 | | -#define OP_SorterOpen 118 |
| 15354 | | -#define OP_SequenceTest 119 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ |
| 15355 | | -#define OP_OpenPseudo 120 /* synopsis: P3 columns in r[P2] */ |
| 15356 | | -#define OP_Close 121 |
| 15357 | | -#define OP_ColumnsUsed 122 |
| 15358 | | -#define OP_SeekScan 123 /* synopsis: Scan-ahead up to P1 rows */ |
| 15359 | | -#define OP_SeekHit 124 /* synopsis: set P2<=seekHit<=P3 */ |
| 15360 | | -#define OP_Sequence 125 /* synopsis: r[P2]=cursor[P1].ctr++ */ |
| 15361 | | -#define OP_NewRowid 126 /* synopsis: r[P2]=rowid */ |
| 15362 | | -#define OP_Insert 127 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 15363 | | -#define OP_RowCell 128 |
| 15364 | | -#define OP_Delete 129 |
| 15365 | | -#define OP_ResetCount 130 |
| 15366 | | -#define OP_SorterCompare 131 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ |
| 15367 | | -#define OP_SorterData 132 /* synopsis: r[P2]=data */ |
| 15368 | | -#define OP_RowData 133 /* synopsis: r[P2]=data */ |
| 15369 | | -#define OP_Rowid 134 /* synopsis: r[P2]=rowid */ |
| 15370 | | -#define OP_NullRow 135 |
| 15371 | | -#define OP_SeekEnd 136 |
| 15372 | | -#define OP_IdxInsert 137 /* synopsis: key=r[P2] */ |
| 15373 | | -#define OP_SorterInsert 138 /* synopsis: key=r[P2] */ |
| 15374 | | -#define OP_IdxDelete 139 /* synopsis: key=r[P2@P3] */ |
| 15375 | | -#define OP_DeferredSeek 140 /* synopsis: Move P3 to P1.rowid if needed */ |
| 15376 | | -#define OP_IdxRowid 141 /* synopsis: r[P2]=rowid */ |
| 15377 | | -#define OP_FinishSeek 142 |
| 15378 | | -#define OP_Destroy 143 |
| 15379 | | -#define OP_Clear 144 |
| 15380 | | -#define OP_ResetSorter 145 |
| 15381 | | -#define OP_CreateBtree 146 /* synopsis: r[P2]=root iDb=P1 flags=P3 */ |
| 15382 | | -#define OP_SqlExec 147 |
| 15383 | | -#define OP_ParseSchema 148 |
| 15384 | | -#define OP_LoadAnalysis 149 |
| 15385 | | -#define OP_DropTable 150 |
| 15386 | | -#define OP_DropIndex 151 |
| 15387 | | -#define OP_DropTrigger 152 |
| 15633 | +#define OP_OpenEphemeral 118 /* synopsis: nColumn=P2 */ |
| 15634 | +#define OP_SorterOpen 119 |
| 15635 | +#define OP_SequenceTest 120 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ |
| 15636 | +#define OP_OpenPseudo 121 /* synopsis: P3 columns in r[P2] */ |
| 15637 | +#define OP_Close 122 |
| 15638 | +#define OP_ColumnsUsed 123 |
| 15639 | +#define OP_SeekScan 124 /* synopsis: Scan-ahead up to P1 rows */ |
| 15640 | +#define OP_SeekHit 125 /* synopsis: set P2<=seekHit<=P3 */ |
| 15641 | +#define OP_Sequence 126 /* synopsis: r[P2]=cursor[P1].ctr++ */ |
| 15642 | +#define OP_NewRowid 127 /* synopsis: r[P2]=rowid */ |
| 15643 | +#define OP_Insert 128 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 15644 | +#define OP_RowCell 129 |
| 15645 | +#define OP_Delete 130 |
| 15646 | +#define OP_ResetCount 131 |
| 15647 | +#define OP_SorterCompare 132 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ |
| 15648 | +#define OP_SorterData 133 /* synopsis: r[P2]=data */ |
| 15649 | +#define OP_RowData 134 /* synopsis: r[P2]=data */ |
| 15650 | +#define OP_Rowid 135 /* synopsis: r[P2]=rowid */ |
| 15651 | +#define OP_NullRow 136 |
| 15652 | +#define OP_SeekEnd 137 |
| 15653 | +#define OP_IdxInsert 138 /* synopsis: key=r[P2] */ |
| 15654 | +#define OP_SorterInsert 139 /* synopsis: key=r[P2] */ |
| 15655 | +#define OP_IdxDelete 140 /* synopsis: key=r[P2@P3] */ |
| 15656 | +#define OP_DeferredSeek 141 /* synopsis: Move P3 to P1.rowid if needed */ |
| 15657 | +#define OP_IdxRowid 142 /* synopsis: r[P2]=rowid */ |
| 15658 | +#define OP_FinishSeek 143 |
| 15659 | +#define OP_Destroy 144 |
| 15660 | +#define OP_Clear 145 |
| 15661 | +#define OP_ResetSorter 146 |
| 15662 | +#define OP_CreateBtree 147 /* synopsis: r[P2]=root iDb=P1 flags=P3 */ |
| 15663 | +#define OP_SqlExec 148 |
| 15664 | +#define OP_ParseSchema 149 |
| 15665 | +#define OP_LoadAnalysis 150 |
| 15666 | +#define OP_DropTable 151 |
| 15667 | +#define OP_DropIndex 152 |
| 15388 | 15668 | #define OP_Real 153 /* same as TK_FLOAT, synopsis: r[P2]=P4 */ |
| 15389 | | -#define OP_IntegrityCk 154 |
| 15390 | | -#define OP_RowSetAdd 155 /* synopsis: rowset(P1)=r[P2] */ |
| 15391 | | -#define OP_Param 156 |
| 15392 | | -#define OP_FkCounter 157 /* synopsis: fkctr[P1]+=P2 */ |
| 15393 | | -#define OP_MemMax 158 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 15394 | | -#define OP_OffsetLimit 159 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ |
| 15395 | | -#define OP_AggInverse 160 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */ |
| 15396 | | -#define OP_AggStep 161 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 15397 | | -#define OP_AggStep1 162 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 15398 | | -#define OP_AggValue 163 /* synopsis: r[P3]=value N=P2 */ |
| 15399 | | -#define OP_AggFinal 164 /* synopsis: accum=r[P1] N=P2 */ |
| 15400 | | -#define OP_Expire 165 |
| 15401 | | -#define OP_CursorLock 166 |
| 15402 | | -#define OP_CursorUnlock 167 |
| 15403 | | -#define OP_TableLock 168 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 15404 | | -#define OP_VBegin 169 |
| 15405 | | -#define OP_VCreate 170 |
| 15406 | | -#define OP_VDestroy 171 |
| 15407 | | -#define OP_VOpen 172 |
| 15408 | | -#define OP_VColumn 173 /* synopsis: r[P3]=vcolumn(P2) */ |
| 15409 | | -#define OP_VRename 174 |
| 15410 | | -#define OP_Pagecount 175 |
| 15411 | | -#define OP_MaxPgcnt 176 |
| 15412 | | -#define OP_FilterAdd 177 /* synopsis: filter(P1) += key(P3@P4) */ |
| 15413 | | -#define OP_Trace 178 |
| 15414 | | -#define OP_CursorHint 179 |
| 15415 | | -#define OP_ReleaseReg 180 /* synopsis: release r[P1@P2] mask P3 */ |
| 15416 | | -#define OP_Noop 181 |
| 15417 | | -#define OP_Explain 182 |
| 15418 | | -#define OP_Abortable 183 |
| 15669 | +#define OP_DropTrigger 154 |
| 15670 | +#define OP_IntegrityCk 155 |
| 15671 | +#define OP_RowSetAdd 156 /* synopsis: rowset(P1)=r[P2] */ |
| 15672 | +#define OP_Param 157 |
| 15673 | +#define OP_FkCounter 158 /* synopsis: fkctr[P1]+=P2 */ |
| 15674 | +#define OP_MemMax 159 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 15675 | +#define OP_OffsetLimit 160 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ |
| 15676 | +#define OP_AggInverse 161 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */ |
| 15677 | +#define OP_AggStep 162 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 15678 | +#define OP_AggStep1 163 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 15679 | +#define OP_AggValue 164 /* synopsis: r[P3]=value N=P2 */ |
| 15680 | +#define OP_AggFinal 165 /* synopsis: accum=r[P1] N=P2 */ |
| 15681 | +#define OP_Expire 166 |
| 15682 | +#define OP_CursorLock 167 |
| 15683 | +#define OP_CursorUnlock 168 |
| 15684 | +#define OP_TableLock 169 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 15685 | +#define OP_VBegin 170 |
| 15686 | +#define OP_VCreate 171 |
| 15687 | +#define OP_VDestroy 172 |
| 15688 | +#define OP_VOpen 173 |
| 15689 | +#define OP_VInitIn 174 /* synopsis: r[P2]=ValueList(P1,P3) */ |
| 15690 | +#define OP_VColumn 175 /* synopsis: r[P3]=vcolumn(P2) */ |
| 15691 | +#define OP_VRename 176 |
| 15692 | +#define OP_Pagecount 177 |
| 15693 | +#define OP_MaxPgcnt 178 |
| 15694 | +#define OP_FilterAdd 179 /* synopsis: filter(P1) += key(P3@P4) */ |
| 15695 | +#define OP_Trace 180 |
| 15696 | +#define OP_CursorHint 181 |
| 15697 | +#define OP_ReleaseReg 182 /* synopsis: release r[P1@P2] mask P3 */ |
| 15698 | +#define OP_Noop 183 |
| 15699 | +#define OP_Explain 184 |
| 15700 | +#define OP_Abortable 185 |
| 15419 | 15701 | |
| 15420 | 15702 | /* Properties such as "out2" or "jump" that are specified in |
| 15421 | 15703 | ** comments following the "case" for each opcode in the vdbe.c |
| 15422 | 15704 | ** are encoded into bitvectors as follows: |
| 15423 | 15705 | */ |
| | @@ -15426,34 +15708,34 @@ |
| 15426 | 15708 | #define OPFLG_IN2 0x04 /* in2: P2 is an input */ |
| 15427 | 15709 | #define OPFLG_IN3 0x08 /* in3: P3 is an input */ |
| 15428 | 15710 | #define OPFLG_OUT2 0x10 /* out2: P2 is an output */ |
| 15429 | 15711 | #define OPFLG_OUT3 0x20 /* out3: P3 is an output */ |
| 15430 | 15712 | #define OPFLG_INITIALIZER {\ |
| 15431 | | -/* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x10,\ |
| 15432 | | -/* 8 */ 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03,\ |
| 15433 | | -/* 16 */ 0x01, 0x01, 0x03, 0x12, 0x03, 0x03, 0x01, 0x09,\ |
| 15434 | | -/* 24 */ 0x09, 0x09, 0x09, 0x01, 0x09, 0x09, 0x09, 0x09,\ |
| 15435 | | -/* 32 */ 0x09, 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\ |
| 15713 | +/* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\ |
| 15714 | +/* 8 */ 0x01, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0x03,\ |
| 15715 | +/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x09, 0x09, 0x09, 0x09,\ |
| 15716 | +/* 24 */ 0x01, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x01,\ |
| 15717 | +/* 32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\ |
| 15436 | 15718 | /* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x23, 0x0b, 0x01,\ |
| 15437 | 15719 | /* 48 */ 0x01, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\ |
| 15438 | 15720 | /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x01, 0x01, 0x01,\ |
| 15439 | | -/* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\ |
| 15440 | | -/* 72 */ 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00,\ |
| 15441 | | -/* 80 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02,\ |
| 15442 | | -/* 88 */ 0x00, 0x00, 0x12, 0x1e, 0x20, 0x00, 0x00, 0x00,\ |
| 15443 | | -/* 96 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x26, 0x26,\ |
| 15721 | +/* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x00,\ |
| 15722 | +/* 72 */ 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00,\ |
| 15723 | +/* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02,\ |
| 15724 | +/* 88 */ 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x00, 0x00,\ |
| 15725 | +/* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x26, 0x26,\ |
| 15444 | 15726 | /* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\ |
| 15445 | 15727 | /* 112 */ 0x00, 0x00, 0x12, 0x00, 0x00, 0x10, 0x00, 0x00,\ |
| 15446 | | -/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\ |
| 15447 | | -/* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\ |
| 15448 | | -/* 136 */ 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00, 0x10,\ |
| 15449 | | -/* 144 */ 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 15450 | | -/* 152 */ 0x00, 0x10, 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a,\ |
| 15451 | | -/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 15452 | | -/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\ |
| 15453 | | -/* 176 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 15454 | | -} |
| 15728 | +/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\ |
| 15729 | +/* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\ |
| 15730 | +/* 136 */ 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00,\ |
| 15731 | +/* 144 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\ |
| 15732 | +/* 152 */ 0x00, 0x10, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\ |
| 15733 | +/* 160 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 15734 | +/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\ |
| 15735 | +/* 176 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 15736 | +/* 184 */ 0x00, 0x00,} |
| 15455 | 15737 | |
| 15456 | 15738 | /* The resolve3P2Values() routine is able to run faster if it knows |
| 15457 | 15739 | ** the value of the largest JUMP opcode. The smaller the maximum |
| 15458 | 15740 | ** JUMP opcode the better, so the mkopcodeh.tcl script that |
| 15459 | 15741 | ** generated this include file strives to group all JUMP opcodes |
| | @@ -17507,10 +17789,15 @@ |
| 17507 | 17789 | ** b-tree. |
| 17508 | 17790 | */ |
| 17509 | 17791 | struct UnpackedRecord { |
| 17510 | 17792 | KeyInfo *pKeyInfo; /* Collation and sort-order information */ |
| 17511 | 17793 | Mem *aMem; /* Values */ |
| 17794 | + union { |
| 17795 | + char *z; /* Cache of aMem[0].z for vdbeRecordCompareString() */ |
| 17796 | + i64 i; /* Cache of aMem[0].u.i for vdbeRecordCompareInt() */ |
| 17797 | + } u; |
| 17798 | + int n; /* Cache of aMem[0].n used by vdbeRecordCompareString() */ |
| 17512 | 17799 | u16 nField; /* Number of entries in apMem[] */ |
| 17513 | 17800 | i8 default_rc; /* Comparison result if keys are equal */ |
| 17514 | 17801 | u8 errCode; /* Error detected by xRecordCompare (CORRUPT or NOMEM) */ |
| 17515 | 17802 | i8 r1; /* Value to return if (lhs < rhs) */ |
| 17516 | 17803 | i8 r2; /* Value to return if (lhs > rhs) */ |
| | @@ -17814,11 +18101,14 @@ |
| 17814 | 18101 | ** TK_SELECT: 1st register of result vector */ |
| 17815 | 18102 | ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid. |
| 17816 | 18103 | ** TK_VARIABLE: variable number (always >= 1). |
| 17817 | 18104 | ** TK_SELECT_COLUMN: column of the result vector */ |
| 17818 | 18105 | i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */ |
| 17819 | | - int iRightJoinTable; /* If EP_FromJoin, the right table of the join */ |
| 18106 | + union { |
| 18107 | + int iRightJoinTable; /* If EP_FromJoin, the right table of the join */ |
| 18108 | + int iOfst; /* else: start of token from start of statement */ |
| 18109 | + } w; |
| 17820 | 18110 | AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */ |
| 17821 | 18111 | union { |
| 17822 | 18112 | Table *pTab; /* TK_COLUMN: Table containing column. Can be NULL |
| 17823 | 18113 | ** for a column of an index on an expression */ |
| 17824 | 18114 | Window *pWin; /* EP_WinFunc: Window/Filter defn for a function */ |
| | @@ -18576,10 +18866,11 @@ |
| 18576 | 18866 | ** initialized as they will be set before being used. The boundary is |
| 18577 | 18867 | ** determined by offsetof(Parse,aTempReg). |
| 18578 | 18868 | **************************************************************************/ |
| 18579 | 18869 | |
| 18580 | 18870 | int aTempReg[8]; /* Holding area for temporary registers */ |
| 18871 | + Parse *pOuterParse; /* Outer Parse object when nested */ |
| 18581 | 18872 | Token sNameToken; /* Token with unqualified schema object name */ |
| 18582 | 18873 | |
| 18583 | 18874 | /************************************************************************ |
| 18584 | 18875 | ** Above is constant between recursions. Below is reset before and after |
| 18585 | 18876 | ** each recursion. The boundary between these two regions is determined |
| | @@ -18626,11 +18917,12 @@ |
| 18626 | 18917 | #define PARSE_MODE_UNMAP 3 |
| 18627 | 18918 | |
| 18628 | 18919 | /* |
| 18629 | 18920 | ** Sizes and pointers of various parts of the Parse object. |
| 18630 | 18921 | */ |
| 18631 | | -#define PARSE_HDR_SZ offsetof(Parse,aTempReg) /* Recursive part w/o aColCache*/ |
| 18922 | +#define PARSE_HDR(X) (((char*)(X))+offsetof(Parse,zErrMsg)) |
| 18923 | +#define PARSE_HDR_SZ (offsetof(Parse,aTempReg)-offsetof(Parse,zErrMsg)) /* Recursive part w/o aColCache*/ |
| 18632 | 18924 | #define PARSE_RECURSE_SZ offsetof(Parse,sLastToken) /* Recursive part */ |
| 18633 | 18925 | #define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */ |
| 18634 | 18926 | #define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */ |
| 18635 | 18927 | |
| 18636 | 18928 | /* |
| | @@ -18921,10 +19213,11 @@ |
| 18921 | 19213 | #endif |
| 18922 | 19214 | #ifndef SQLITE_UNTESTABLE |
| 18923 | 19215 | int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */ |
| 18924 | 19216 | #endif |
| 18925 | 19217 | int bLocaltimeFault; /* True to fail localtime() calls */ |
| 19218 | + int (*xAltLocaltime)(const void*,void*); /* Alternative localtime() routine */ |
| 18926 | 19219 | int iOnceResetThreshold; /* When to reset OP_Once counters */ |
| 18927 | 19220 | u32 szSorterRef; /* Min size in bytes to use sorter-refs */ |
| 18928 | 19221 | unsigned int iPrngSeed; /* Alternative fixed seed for the PRNG */ |
| 18929 | 19222 | /* vvvv--- must be last ---vvv */ |
| 18930 | 19223 | #ifdef SQLITE_DEBUG |
| | @@ -19125,11 +19418,11 @@ |
| 19125 | 19418 | Expr *pStart; /* Expression for "<expr> PRECEDING" */ |
| 19126 | 19419 | Expr *pEnd; /* Expression for "<expr> FOLLOWING" */ |
| 19127 | 19420 | Window **ppThis; /* Pointer to this object in Select.pWin list */ |
| 19128 | 19421 | Window *pNextWin; /* Next window function belonging to this SELECT */ |
| 19129 | 19422 | Expr *pFilter; /* The FILTER expression */ |
| 19130 | | - FuncDef *pFunc; /* The function */ |
| 19423 | + FuncDef *pWFunc; /* The function */ |
| 19131 | 19424 | int iEphCsr; /* Partition buffer or Peer buffer */ |
| 19132 | 19425 | int regAccum; /* Accumulator */ |
| 19133 | 19426 | int regResult; /* Interim result */ |
| 19134 | 19427 | int csrApp; /* Function cursor (used by min/max) */ |
| 19135 | 19428 | int regApp; /* Function register (also used by min/max) */ |
| | @@ -19566,11 +19859,12 @@ |
| 19566 | 19859 | #endif |
| 19567 | 19860 | SQLITE_PRIVATE void sqlite3CodeChangeCount(Vdbe*,int,const char*); |
| 19568 | 19861 | SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*, ExprList*, Expr*); |
| 19569 | 19862 | SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*,Expr*,int,ExprList*,Expr*, |
| 19570 | 19863 | Upsert*); |
| 19571 | | -SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,ExprList*,u16,int); |
| 19864 | +SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*, |
| 19865 | + ExprList*,Select*,u16,int); |
| 19572 | 19866 | SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*); |
| 19573 | 19867 | SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo*); |
| 19574 | 19868 | SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*); |
| 19575 | 19869 | SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*); |
| 19576 | 19870 | SQLITE_PRIVATE int sqlite3WhereOrderByLimitOptLabel(WhereInfo*); |
| | @@ -19966,11 +20260,11 @@ |
| 19966 | 20260 | void (*)(sqlite3_context*), |
| 19967 | 20261 | void (*)(sqlite3_context*,int,sqlite3_value **), |
| 19968 | 20262 | FuncDestructor *pDestructor |
| 19969 | 20263 | ); |
| 19970 | 20264 | SQLITE_PRIVATE void sqlite3NoopDestructor(void*); |
| 19971 | | -SQLITE_PRIVATE void sqlite3OomFault(sqlite3*); |
| 20265 | +SQLITE_PRIVATE void *sqlite3OomFault(sqlite3*); |
| 19972 | 20266 | SQLITE_PRIVATE void sqlite3OomClear(sqlite3*); |
| 19973 | 20267 | SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int); |
| 19974 | 20268 | SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *); |
| 19975 | 20269 | |
| 19976 | 20270 | SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int); |
| | @@ -19979,10 +20273,11 @@ |
| 19979 | 20273 | SQLITE_PRIVATE void sqlite3StrAccumSetError(StrAccum*, u8); |
| 19980 | 20274 | SQLITE_PRIVATE void sqlite3ResultStrAccum(sqlite3_context*,StrAccum*); |
| 19981 | 20275 | SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int); |
| 19982 | 20276 | SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int); |
| 19983 | 20277 | SQLITE_PRIVATE void sqlite3RecordErrorByteOffset(sqlite3*,const char*); |
| 20278 | +SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3*,const Expr*); |
| 19984 | 20279 | |
| 19985 | 20280 | SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *); |
| 19986 | 20281 | SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *); |
| 19987 | 20282 | |
| 19988 | 20283 | #ifndef SQLITE_OMIT_SUBQUERY |
| | @@ -20083,15 +20378,21 @@ |
| 20083 | 20378 | SQLITE_PRIVATE void sqlite3VtabArgExtend(Parse*, Token*); |
| 20084 | 20379 | SQLITE_PRIVATE int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **); |
| 20085 | 20380 | SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse*, Table*); |
| 20086 | 20381 | SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3*, int, const char *); |
| 20087 | 20382 | SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, VTable *); |
| 20383 | + |
| 20088 | 20384 | SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*); |
| 20385 | +#if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \ |
| 20386 | + && !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 20387 | +SQLITE_PRIVATE void sqlite3VtabWriteAll(sqlite3_index_info*); |
| 20388 | +#endif |
| 20089 | 20389 | SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*); |
| 20090 | 20390 | SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int); |
| 20091 | 20391 | SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *); |
| 20092 | | -SQLITE_PRIVATE void sqlite3ParserReset(Parse*); |
| 20392 | +SQLITE_PRIVATE void sqlite3ParseObjectInit(Parse*,sqlite3*); |
| 20393 | +SQLITE_PRIVATE void sqlite3ParseObjectReset(Parse*); |
| 20093 | 20394 | SQLITE_PRIVATE void *sqlite3ParserAddCleanup(Parse*,void(*)(sqlite3*,void*),void*); |
| 20094 | 20395 | #ifdef SQLITE_ENABLE_NORMALIZE |
| 20095 | 20396 | SQLITE_PRIVATE char *sqlite3Normalize(Vdbe*, const char*); |
| 20096 | 20397 | #endif |
| 20097 | 20398 | SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*); |
| | @@ -20520,10 +20821,18 @@ |
| 20520 | 20821 | |
| 20521 | 20822 | #endif /* !defined(_OS_COMMON_H_) */ |
| 20522 | 20823 | |
| 20523 | 20824 | /************** End of os_common.h *******************************************/ |
| 20524 | 20825 | /************** Begin file ctime.c *******************************************/ |
| 20826 | +/* DO NOT EDIT! |
| 20827 | +** This file is automatically generated by the script in the canonical |
| 20828 | +** SQLite source tree at tool/mkctimec.tcl. |
| 20829 | +** |
| 20830 | +** To modify this header, edit any of the various lists in that script |
| 20831 | +** which specify categories of generated conditionals in this file. |
| 20832 | +*/ |
| 20833 | + |
| 20525 | 20834 | /* |
| 20526 | 20835 | ** 2010 February 23 |
| 20527 | 20836 | ** |
| 20528 | 20837 | ** The author disclaims copyright to this source code. In place of |
| 20529 | 20838 | ** a legal notice, here is a blessing: |
| | @@ -20568,13 +20877,10 @@ |
| 20568 | 20877 | ** only a handful of compile-time options, so most times this array is usually |
| 20569 | 20878 | ** rather short and uses little memory space. |
| 20570 | 20879 | */ |
| 20571 | 20880 | static const char * const sqlite3azCompileOpt[] = { |
| 20572 | 20881 | |
| 20573 | | -/* |
| 20574 | | -** BEGIN CODE GENERATED BY tool/mkctime.tcl |
| 20575 | | -*/ |
| 20576 | 20882 | #ifdef SQLITE_32BIT_ROWID |
| 20577 | 20883 | "32BIT_ROWID", |
| 20578 | 20884 | #endif |
| 20579 | 20885 | #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC |
| 20580 | 20886 | "4_BYTE_ALIGNED_MALLOC", |
| | @@ -20701,13 +21007,10 @@ |
| 20701 | 21007 | "DISABLE_FTS4_DEFERRED", |
| 20702 | 21008 | #endif |
| 20703 | 21009 | #ifdef SQLITE_DISABLE_INTRINSIC |
| 20704 | 21010 | "DISABLE_INTRINSIC", |
| 20705 | 21011 | #endif |
| 20706 | | -#ifdef SQLITE_DISABLE_JSON |
| 20707 | | - "DISABLE_JSON", |
| 20708 | | -#endif |
| 20709 | 21012 | #ifdef SQLITE_DISABLE_LFS |
| 20710 | 21013 | "DISABLE_LFS", |
| 20711 | 21014 | #endif |
| 20712 | 21015 | #ifdef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS |
| 20713 | 21016 | "DISABLE_PAGECACHE_OVERFLOW_STATS", |
| | @@ -21104,10 +21407,13 @@ |
| 21104 | 21407 | #ifdef SQLITE_OMIT_INTEGRITY_CHECK |
| 21105 | 21408 | "OMIT_INTEGRITY_CHECK", |
| 21106 | 21409 | #endif |
| 21107 | 21410 | #ifdef SQLITE_OMIT_INTROSPECTION_PRAGMAS |
| 21108 | 21411 | "OMIT_INTROSPECTION_PRAGMAS", |
| 21412 | +#endif |
| 21413 | +#ifdef SQLITE_OMIT_JSON |
| 21414 | + "OMIT_JSON", |
| 21109 | 21415 | #endif |
| 21110 | 21416 | #ifdef SQLITE_OMIT_LIKE_OPTIMIZATION |
| 21111 | 21417 | "OMIT_LIKE_OPTIMIZATION", |
| 21112 | 21418 | #endif |
| 21113 | 21419 | #ifdef SQLITE_OMIT_LOAD_EXTENSION |
| | @@ -21293,14 +21599,12 @@ |
| 21293 | 21599 | "WIN32_MALLOC", |
| 21294 | 21600 | #endif |
| 21295 | 21601 | #ifdef SQLITE_ZERO_MALLOC |
| 21296 | 21602 | "ZERO_MALLOC", |
| 21297 | 21603 | #endif |
| 21298 | | -/* |
| 21299 | | -** END CODE GENERATED BY tool/mkctime.tcl |
| 21300 | | -*/ |
| 21301 | | -}; |
| 21604 | + |
| 21605 | +} ; |
| 21302 | 21606 | |
| 21303 | 21607 | SQLITE_PRIVATE const char **sqlite3CompileOptions(int *pnOpt){ |
| 21304 | 21608 | *pnOpt = sizeof(sqlite3azCompileOpt) / sizeof(sqlite3azCompileOpt[0]); |
| 21305 | 21609 | return (const char**)sqlite3azCompileOpt; |
| 21306 | 21610 | } |
| | @@ -21595,13 +21899,17 @@ |
| 21595 | 21899 | #endif |
| 21596 | 21900 | #ifndef SQLITE_UNTESTABLE |
| 21597 | 21901 | 0, /* xTestCallback */ |
| 21598 | 21902 | #endif |
| 21599 | 21903 | 0, /* bLocaltimeFault */ |
| 21904 | + 0, /* xAltLocaltime */ |
| 21600 | 21905 | 0x7ffffffe, /* iOnceResetThreshold */ |
| 21601 | 21906 | SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */ |
| 21602 | 21907 | 0, /* iPrngSeed */ |
| 21908 | +#ifdef SQLITE_DEBUG |
| 21909 | + {0,0,0,0,0,0} /* aTune */ |
| 21910 | +#endif |
| 21603 | 21911 | }; |
| 21604 | 21912 | |
| 21605 | 21913 | /* |
| 21606 | 21914 | ** Hash table for global functions - functions common to all |
| 21607 | 21915 | ** database connections. After initialization, this table is |
| | @@ -21941,20 +22249,20 @@ |
| 21941 | 22249 | i64 i; /* Integer value used when MEM_Int is set in flags */ |
| 21942 | 22250 | int nZero; /* Extra zero bytes when MEM_Zero and MEM_Blob set */ |
| 21943 | 22251 | const char *zPType; /* Pointer type when MEM_Term|MEM_Subtype|MEM_Null */ |
| 21944 | 22252 | FuncDef *pDef; /* Used only when flags==MEM_Agg */ |
| 21945 | 22253 | } u; |
| 22254 | + char *z; /* String or BLOB value */ |
| 22255 | + int n; /* Number of characters in string value, excluding '\0' */ |
| 21946 | 22256 | u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */ |
| 21947 | 22257 | u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */ |
| 21948 | 22258 | u8 eSubtype; /* Subtype for this value */ |
| 21949 | | - int n; /* Number of characters in string value, excluding '\0' */ |
| 21950 | | - char *z; /* String or BLOB value */ |
| 21951 | 22259 | /* ShallowCopy only needs to copy the information above */ |
| 21952 | | - char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */ |
| 22260 | + sqlite3 *db; /* The associated database connection */ |
| 21953 | 22261 | int szMalloc; /* Size of the zMalloc allocation */ |
| 21954 | 22262 | u32 uTemp; /* Transient storage for serial_type in OP_MakeRecord */ |
| 21955 | | - sqlite3 *db; /* The associated database connection */ |
| 22263 | + char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */ |
| 21956 | 22264 | void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */ |
| 21957 | 22265 | #ifdef SQLITE_DEBUG |
| 21958 | 22266 | Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */ |
| 21959 | 22267 | u16 mScopyFlags; /* flags value immediately after the shallow copy */ |
| 21960 | 22268 | #endif |
| | @@ -21962,15 +22270,47 @@ |
| 21962 | 22270 | |
| 21963 | 22271 | /* |
| 21964 | 22272 | ** Size of struct Mem not including the Mem.zMalloc member or anything that |
| 21965 | 22273 | ** follows. |
| 21966 | 22274 | */ |
| 21967 | | -#define MEMCELLSIZE offsetof(Mem,zMalloc) |
| 22275 | +#define MEMCELLSIZE offsetof(Mem,db) |
| 21968 | 22276 | |
| 21969 | | -/* One or more of the following flags are set to indicate the validOK |
| 22277 | +/* One or more of the following flags are set to indicate the |
| 21970 | 22278 | ** representations of the value stored in the Mem struct. |
| 21971 | 22279 | ** |
| 22280 | +** * MEM_Null An SQL NULL value |
| 22281 | +** |
| 22282 | +** * MEM_Null|MEM_Zero An SQL NULL with the virtual table |
| 22283 | +** UPDATE no-change flag set |
| 22284 | +** |
| 22285 | +** * MEM_Null|MEM_Term| An SQL NULL, but also contains a |
| 22286 | +** MEM_Subtype pointer accessible using |
| 22287 | +** sqlite3_value_pointer(). |
| 22288 | +** |
| 22289 | +** * MEM_Null|MEM_Cleared Special SQL NULL that compares non-equal |
| 22290 | +** to other NULLs even using the IS operator. |
| 22291 | +** |
| 22292 | +** * MEM_Str A string, stored in Mem.z with |
| 22293 | +** length Mem.n. Zero-terminated if |
| 22294 | +** MEM_Term is set. This flag is |
| 22295 | +** incompatible with MEM_Blob and |
| 22296 | +** MEM_Null, but can appear with MEM_Int, |
| 22297 | +** MEM_Real, and MEM_IntReal. |
| 22298 | +** |
| 22299 | +** * MEM_Blob A blob, stored in Mem.z length Mem.n. |
| 22300 | +** Incompatible with MEM_Str, MEM_Null, |
| 22301 | +** MEM_Int, MEM_Real, and MEM_IntReal. |
| 22302 | +** |
| 22303 | +** * MEM_Blob|MEM_Zero A blob in Mem.z of length Mem.n plus |
| 22304 | +** MEM.u.i extra 0x00 bytes at the end. |
| 22305 | +** |
| 22306 | +** * MEM_Int Integer stored in Mem.u.i. |
| 22307 | +** |
| 22308 | +** * MEM_Real Real stored in Mem.u.r. |
| 22309 | +** |
| 22310 | +** * MEM_IntReal Real stored as an integer in Mem.u.i. |
| 22311 | +** |
| 21972 | 22312 | ** If the MEM_Null flag is set, then the value is an SQL NULL value. |
| 21973 | 22313 | ** For a pointer type created using sqlite3_bind_pointer() or |
| 21974 | 22314 | ** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set. |
| 21975 | 22315 | ** |
| 21976 | 22316 | ** If the MEM_Str flag is set then Mem.z points at a string representation. |
| | @@ -21977,39 +22317,36 @@ |
| 21977 | 22317 | ** Usually this is encoded in the same unicode encoding as the main |
| 21978 | 22318 | ** database (see below for exceptions). If the MEM_Term flag is also |
| 21979 | 22319 | ** set, then the string is nul terminated. The MEM_Int and MEM_Real |
| 21980 | 22320 | ** flags may coexist with the MEM_Str flag. |
| 21981 | 22321 | */ |
| 22322 | +#define MEM_Undefined 0x0000 /* Value is undefined */ |
| 21982 | 22323 | #define MEM_Null 0x0001 /* Value is NULL (or a pointer) */ |
| 21983 | 22324 | #define MEM_Str 0x0002 /* Value is a string */ |
| 21984 | 22325 | #define MEM_Int 0x0004 /* Value is an integer */ |
| 21985 | 22326 | #define MEM_Real 0x0008 /* Value is a real number */ |
| 21986 | 22327 | #define MEM_Blob 0x0010 /* Value is a BLOB */ |
| 21987 | 22328 | #define MEM_IntReal 0x0020 /* MEM_Int that stringifies like MEM_Real */ |
| 21988 | 22329 | #define MEM_AffMask 0x003f /* Mask of affinity bits */ |
| 22330 | + |
| 22331 | +/* Extra bits that modify the meanings of the core datatypes above |
| 22332 | +*/ |
| 21989 | 22333 | #define MEM_FromBind 0x0040 /* Value originates from sqlite3_bind() */ |
| 21990 | | -#define MEM_Undefined 0x0080 /* Value is undefined */ |
| 22334 | + /* 0x0080 // Available */ |
| 21991 | 22335 | #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */ |
| 21992 | | -#define MEM_TypeMask 0xc1bf /* Mask of type bits */ |
| 21993 | | - |
| 21994 | | - |
| 21995 | | -/* Whenever Mem contains a valid string or blob representation, one of |
| 21996 | | -** the following flags must be set to determine the memory management |
| 21997 | | -** policy for Mem.z. The MEM_Term flag tells us whether or not the |
| 21998 | | -** string is \000 or \u0000 terminated |
| 21999 | | -*/ |
| 22000 | 22336 | #define MEM_Term 0x0200 /* String in Mem.z is zero terminated */ |
| 22001 | | -#define MEM_Dyn 0x0400 /* Need to call Mem.xDel() on Mem.z */ |
| 22002 | | -#define MEM_Static 0x0800 /* Mem.z points to a static string */ |
| 22003 | | -#define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */ |
| 22004 | | -#define MEM_Agg 0x2000 /* Mem.z points to an agg function context */ |
| 22005 | | -#define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */ |
| 22006 | | -#define MEM_Subtype 0x8000 /* Mem.eSubtype is valid */ |
| 22007 | | -#ifdef SQLITE_OMIT_INCRBLOB |
| 22008 | | - #undef MEM_Zero |
| 22009 | | - #define MEM_Zero 0x0000 |
| 22010 | | -#endif |
| 22337 | +#define MEM_Zero 0x0400 /* Mem.i contains count of 0s appended to blob */ |
| 22338 | +#define MEM_Subtype 0x0800 /* Mem.eSubtype is valid */ |
| 22339 | +#define MEM_TypeMask 0x0dbf /* Mask of type bits */ |
| 22340 | + |
| 22341 | +/* Bits that determine the storage for Mem.z for a string or blob or |
| 22342 | +** aggregate accumulator. |
| 22343 | +*/ |
| 22344 | +#define MEM_Dyn 0x1000 /* Need to call Mem.xDel() on Mem.z */ |
| 22345 | +#define MEM_Static 0x2000 /* Mem.z points to a static string */ |
| 22346 | +#define MEM_Ephem 0x4000 /* Mem.z points to an ephemeral string */ |
| 22347 | +#define MEM_Agg 0x8000 /* Mem.z points to an agg function context */ |
| 22011 | 22348 | |
| 22012 | 22349 | /* Return TRUE if Mem X contains dynamically allocated content - anything |
| 22013 | 22350 | ** that needs to be deallocated to avoid a leak. |
| 22014 | 22351 | */ |
| 22015 | 22352 | #define VdbeMemDynamic(X) \ |
| | @@ -22027,15 +22364,19 @@ |
| 22027 | 22364 | #define MemNullNochng(X) \ |
| 22028 | 22365 | (((X)->flags&MEM_TypeMask)==(MEM_Null|MEM_Zero) \ |
| 22029 | 22366 | && (X)->n==0 && (X)->u.nZero==0) |
| 22030 | 22367 | |
| 22031 | 22368 | /* |
| 22032 | | -** Return true if a memory cell is not marked as invalid. This macro |
| 22369 | +** Return true if a memory cell has been initialized and is valid. |
| 22033 | 22370 | ** is for use inside assert() statements only. |
| 22371 | +** |
| 22372 | +** A Memory cell is initialized if at least one of the |
| 22373 | +** MEM_Null, MEM_Str, MEM_Int, MEM_Real, MEM_Blob, or MEM_IntReal bits |
| 22374 | +** is set. It is "undefined" if all those bits are zero. |
| 22034 | 22375 | */ |
| 22035 | 22376 | #ifdef SQLITE_DEBUG |
| 22036 | | -#define memIsValid(M) ((M)->flags & MEM_Undefined)==0 |
| 22377 | +#define memIsValid(M) ((M)->flags & MEM_AffMask)!=0 |
| 22037 | 22378 | #endif |
| 22038 | 22379 | |
| 22039 | 22380 | /* |
| 22040 | 22381 | ** Each auxiliary data pointer stored by a user defined function |
| 22041 | 22382 | ** implementation calling sqlite3_set_auxdata() is stored in an instance |
| | @@ -22215,18 +22556,36 @@ |
| 22215 | 22556 | Mem *aNew; /* Array of new.* values */ |
| 22216 | 22557 | Table *pTab; /* Schema object being upated */ |
| 22217 | 22558 | Index *pPk; /* PK index if pTab is WITHOUT ROWID */ |
| 22218 | 22559 | }; |
| 22219 | 22560 | |
| 22561 | +/* |
| 22562 | +** An instance of this object is used to pass an vector of values into |
| 22563 | +** OP_VFilter, the xFilter method of a virtual table. The vector is the |
| 22564 | +** set of values on the right-hand side of an IN constraint. |
| 22565 | +** |
| 22566 | +** The value as passed into xFilter is an sqlite3_value with a "pointer" |
| 22567 | +** type, such as is generated by sqlite3_result_pointer() and read by |
| 22568 | +** sqlite3_value_pointer. Such values have MEM_Term|MEM_Subtype|MEM_Null |
| 22569 | +** and a subtype of 'p'. The sqlite3_vtab_in_first() and _next() interfaces |
| 22570 | +** know how to use this object to step through all the values in the |
| 22571 | +** right operand of the IN constraint. |
| 22572 | +*/ |
| 22573 | +typedef struct ValueList ValueList; |
| 22574 | +struct ValueList { |
| 22575 | + BtCursor *pCsr; /* An ephemeral table holding all values */ |
| 22576 | + sqlite3_value *pOut; /* Register to hold each decoded output value */ |
| 22577 | +}; |
| 22578 | + |
| 22220 | 22579 | /* |
| 22221 | 22580 | ** Function prototypes |
| 22222 | 22581 | */ |
| 22223 | 22582 | SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...); |
| 22224 | 22583 | SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*); |
| 22225 | 22584 | void sqliteVdbePopStack(Vdbe*,int); |
| 22585 | +SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeHandleMovedCursor(VdbeCursor *p); |
| 22226 | 22586 | SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*); |
| 22227 | | -SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor**, u32*); |
| 22228 | 22587 | SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*); |
| 22229 | 22588 | SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32); |
| 22230 | 22589 | SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8); |
| 22231 | 22590 | SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32); |
| 22232 | 22591 | SQLITE_PRIVATE void sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); |
| | @@ -22284,10 +22643,11 @@ |
| 22284 | 22643 | SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*); |
| 22285 | 22644 | SQLITE_PRIVATE int sqlite3VdbeMemCast(Mem*,u8,u8); |
| 22286 | 22645 | SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*); |
| 22287 | 22646 | SQLITE_PRIVATE int sqlite3VdbeMemFromBtreeZeroOffset(BtCursor*,u32,Mem*); |
| 22288 | 22647 | SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p); |
| 22648 | +SQLITE_PRIVATE void sqlite3VdbeMemReleaseMalloc(Mem*p); |
| 22289 | 22649 | SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*); |
| 22290 | 22650 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 22291 | 22651 | SQLITE_PRIVATE int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*); |
| 22292 | 22652 | #endif |
| 22293 | 22653 | #if !defined(SQLITE_OMIT_EXPLAIN) || defined(SQLITE_ENABLE_BYTECODE_VTAB) |
| | @@ -23251,12 +23611,14 @@ |
| 23251 | 23611 | ** The following routine implements the rough equivalent of localtime_r() |
| 23252 | 23612 | ** using whatever operating-system specific localtime facility that |
| 23253 | 23613 | ** is available. This routine returns 0 on success and |
| 23254 | 23614 | ** non-zero on any kind of error. |
| 23255 | 23615 | ** |
| 23256 | | -** If the sqlite3GlobalConfig.bLocaltimeFault variable is true then this |
| 23257 | | -** routine will always fail. |
| 23616 | +** If the sqlite3GlobalConfig.bLocaltimeFault variable is non-zero then this |
| 23617 | +** routine will always fail. If bLocaltimeFault is nonzero and |
| 23618 | +** sqlite3GlobalConfig.xAltLocaltime is not NULL, then xAltLocaltime() is |
| 23619 | +** invoked in place of the OS-defined localtime() function. |
| 23258 | 23620 | ** |
| 23259 | 23621 | ** EVIDENCE-OF: R-62172-00036 In this implementation, the standard C |
| 23260 | 23622 | ** library function localtime_r() is used to assist in the calculation of |
| 23261 | 23623 | ** local time. |
| 23262 | 23624 | */ |
| | @@ -23268,20 +23630,34 @@ |
| 23268 | 23630 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); |
| 23269 | 23631 | #endif |
| 23270 | 23632 | sqlite3_mutex_enter(mutex); |
| 23271 | 23633 | pX = localtime(t); |
| 23272 | 23634 | #ifndef SQLITE_UNTESTABLE |
| 23273 | | - if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0; |
| 23635 | + if( sqlite3GlobalConfig.bLocaltimeFault ){ |
| 23636 | + if( sqlite3GlobalConfig.xAltLocaltime!=0 |
| 23637 | + && 0==sqlite3GlobalConfig.xAltLocaltime((const void*)t,(void*)pTm) |
| 23638 | + ){ |
| 23639 | + pX = pTm; |
| 23640 | + }else{ |
| 23641 | + pX = 0; |
| 23642 | + } |
| 23643 | + } |
| 23274 | 23644 | #endif |
| 23275 | 23645 | if( pX ) *pTm = *pX; |
| 23276 | 23646 | #if SQLITE_THREADSAFE>0 |
| 23277 | 23647 | sqlite3_mutex_leave(mutex); |
| 23278 | 23648 | #endif |
| 23279 | 23649 | rc = pX==0; |
| 23280 | 23650 | #else |
| 23281 | 23651 | #ifndef SQLITE_UNTESTABLE |
| 23282 | | - if( sqlite3GlobalConfig.bLocaltimeFault ) return 1; |
| 23652 | + if( sqlite3GlobalConfig.bLocaltimeFault ){ |
| 23653 | + if( sqlite3GlobalConfig.xAltLocaltime!=0 ){ |
| 23654 | + return sqlite3GlobalConfig.xAltLocaltime((const void*)t,(void*)pTm); |
| 23655 | + }else{ |
| 23656 | + return 1; |
| 23657 | + } |
| 23658 | + } |
| 23283 | 23659 | #endif |
| 23284 | 23660 | #if HAVE_LOCALTIME_R |
| 23285 | 23661 | rc = localtime_r(t, pTm)==0; |
| 23286 | 23662 | #else |
| 23287 | 23663 | rc = localtime_s(pTm, t); |
| | @@ -23292,71 +23668,60 @@ |
| 23292 | 23668 | #endif /* SQLITE_OMIT_LOCALTIME */ |
| 23293 | 23669 | |
| 23294 | 23670 | |
| 23295 | 23671 | #ifndef SQLITE_OMIT_LOCALTIME |
| 23296 | 23672 | /* |
| 23297 | | -** Compute the difference (in milliseconds) between localtime and UTC |
| 23298 | | -** (a.k.a. GMT) for the time value p where p is in UTC. If no error occurs, |
| 23299 | | -** return this value and set *pRc to SQLITE_OK. |
| 23300 | | -** |
| 23301 | | -** Or, if an error does occur, set *pRc to SQLITE_ERROR. The returned value |
| 23302 | | -** is undefined in this case. |
| 23673 | +** Assuming the input DateTime is UTC, move it to its localtime equivalent. |
| 23303 | 23674 | */ |
| 23304 | | -static sqlite3_int64 localtimeOffset( |
| 23305 | | - DateTime *p, /* Date at which to calculate offset */ |
| 23306 | | - sqlite3_context *pCtx, /* Write error here if one occurs */ |
| 23307 | | - int *pRc /* OUT: Error code. SQLITE_OK or ERROR */ |
| 23675 | +static int toLocaltime( |
| 23676 | + DateTime *p, /* Date at which to calculate offset */ |
| 23677 | + sqlite3_context *pCtx /* Write error here if one occurs */ |
| 23308 | 23678 | ){ |
| 23309 | | - DateTime x, y; |
| 23310 | 23679 | time_t t; |
| 23311 | 23680 | struct tm sLocal; |
| 23681 | + int iYearDiff; |
| 23312 | 23682 | |
| 23313 | 23683 | /* Initialize the contents of sLocal to avoid a compiler warning. */ |
| 23314 | 23684 | memset(&sLocal, 0, sizeof(sLocal)); |
| 23315 | 23685 | |
| 23316 | | - x = *p; |
| 23317 | | - computeYMD_HMS(&x); |
| 23318 | | - if( x.Y<1971 || x.Y>=2038 ){ |
| 23686 | + computeJD(p); |
| 23687 | + if( p->iJD<2108667600*(i64)100000 /* 1970-01-01 */ |
| 23688 | + || p->iJD>2130141456*(i64)100000 /* 2038-01-18 */ |
| 23689 | + ){ |
| 23319 | 23690 | /* EVIDENCE-OF: R-55269-29598 The localtime_r() C function normally only |
| 23320 | 23691 | ** works for years between 1970 and 2037. For dates outside this range, |
| 23321 | 23692 | ** SQLite attempts to map the year into an equivalent year within this |
| 23322 | 23693 | ** range, do the calculation, then map the year back. |
| 23323 | 23694 | */ |
| 23324 | | - x.Y = 2000; |
| 23325 | | - x.M = 1; |
| 23326 | | - x.D = 1; |
| 23327 | | - x.h = 0; |
| 23328 | | - x.m = 0; |
| 23329 | | - x.s = 0.0; |
| 23330 | | - } else { |
| 23331 | | - int s = (int)(x.s + 0.5); |
| 23332 | | - x.s = s; |
| 23333 | | - } |
| 23334 | | - x.tz = 0; |
| 23335 | | - x.validJD = 0; |
| 23336 | | - computeJD(&x); |
| 23337 | | - t = (time_t)(x.iJD/1000 - 21086676*(i64)10000); |
| 23695 | + DateTime x = *p; |
| 23696 | + computeYMD_HMS(&x); |
| 23697 | + iYearDiff = (2000 + x.Y%4) - x.Y; |
| 23698 | + x.Y += iYearDiff; |
| 23699 | + x.validJD = 0; |
| 23700 | + computeJD(&x); |
| 23701 | + t = (time_t)(x.iJD/1000 - 21086676*(i64)10000); |
| 23702 | + }else{ |
| 23703 | + iYearDiff = 0; |
| 23704 | + t = (time_t)(p->iJD/1000 - 21086676*(i64)10000); |
| 23705 | + } |
| 23338 | 23706 | if( osLocaltime(&t, &sLocal) ){ |
| 23339 | 23707 | sqlite3_result_error(pCtx, "local time unavailable", -1); |
| 23340 | | - *pRc = SQLITE_ERROR; |
| 23341 | | - return 0; |
| 23342 | | - } |
| 23343 | | - y.Y = sLocal.tm_year + 1900; |
| 23344 | | - y.M = sLocal.tm_mon + 1; |
| 23345 | | - y.D = sLocal.tm_mday; |
| 23346 | | - y.h = sLocal.tm_hour; |
| 23347 | | - y.m = sLocal.tm_min; |
| 23348 | | - y.s = sLocal.tm_sec; |
| 23349 | | - y.validYMD = 1; |
| 23350 | | - y.validHMS = 1; |
| 23351 | | - y.validJD = 0; |
| 23352 | | - y.rawS = 0; |
| 23353 | | - y.validTZ = 0; |
| 23354 | | - y.isError = 0; |
| 23355 | | - computeJD(&y); |
| 23356 | | - *pRc = SQLITE_OK; |
| 23357 | | - return y.iJD - x.iJD; |
| 23708 | + return SQLITE_ERROR; |
| 23709 | + } |
| 23710 | + p->Y = sLocal.tm_year + 1900 - iYearDiff; |
| 23711 | + p->M = sLocal.tm_mon + 1; |
| 23712 | + p->D = sLocal.tm_mday; |
| 23713 | + p->h = sLocal.tm_hour; |
| 23714 | + p->m = sLocal.tm_min; |
| 23715 | + p->s = sLocal.tm_sec + (p->iJD%1000)*0.001; |
| 23716 | + p->validYMD = 1; |
| 23717 | + p->validHMS = 1; |
| 23718 | + p->validJD = 0; |
| 23719 | + p->rawS = 0; |
| 23720 | + p->validTZ = 0; |
| 23721 | + p->isError = 0; |
| 23722 | + return SQLITE_OK; |
| 23358 | 23723 | } |
| 23359 | 23724 | #endif /* SQLITE_OMIT_LOCALTIME */ |
| 23360 | 23725 | |
| 23361 | 23726 | /* |
| 23362 | 23727 | ** The following table defines various date transformations of the form |
| | @@ -23406,11 +23771,12 @@ |
| 23406 | 23771 | */ |
| 23407 | 23772 | static int parseModifier( |
| 23408 | 23773 | sqlite3_context *pCtx, /* Function context */ |
| 23409 | 23774 | const char *z, /* The text of the modifier */ |
| 23410 | 23775 | int n, /* Length of zMod in bytes */ |
| 23411 | | - DateTime *p /* The date/time value to be modified */ |
| 23776 | + DateTime *p, /* The date/time value to be modified */ |
| 23777 | + int idx /* Parameter index of the modifier */ |
| 23412 | 23778 | ){ |
| 23413 | 23779 | int rc = 1; |
| 23414 | 23780 | double r; |
| 23415 | 23781 | switch(sqlite3UpperToLower[(u8)z[0]] ){ |
| 23416 | 23782 | case 'a': { |
| | @@ -23419,14 +23785,17 @@ |
| 23419 | 23785 | ** |
| 23420 | 23786 | ** If rawS is available, then interpret as a julian day number, or |
| 23421 | 23787 | ** a unix timestamp, depending on its magnitude. |
| 23422 | 23788 | */ |
| 23423 | 23789 | if( sqlite3_stricmp(z, "auto")==0 ){ |
| 23790 | + if( idx>1 ) return 1; /* IMP: R-33611-57934 */ |
| 23424 | 23791 | if( !p->rawS || p->validJD ){ |
| 23425 | 23792 | rc = 0; |
| 23426 | 23793 | p->rawS = 0; |
| 23427 | | - }else if( p->s>=-210866760000 && p->s<=253402300799 ){ |
| 23794 | + }else if( p->s>=-21086676*(i64)10000 /* -4713-11-24 12:00:00 */ |
| 23795 | + && p->s<=(25340230*(i64)10000)+799 /* 9999-12-31 23:59:59 */ |
| 23796 | + ){ |
| 23428 | 23797 | r = p->s*1000.0 + 210866760000000.0; |
| 23429 | 23798 | clearYMD_HMS_TZ(p); |
| 23430 | 23799 | p->iJD = (sqlite3_int64)(r + 0.5); |
| 23431 | 23800 | p->validJD = 1; |
| 23432 | 23801 | p->rawS = 0; |
| | @@ -23443,10 +23812,11 @@ |
| 23443 | 23812 | ** is not the first modifier, or if the prior argument is not a numeric |
| 23444 | 23813 | ** value in the allowed range of julian day numbers understood by |
| 23445 | 23814 | ** SQLite (0..5373484.5) then the result will be NULL. |
| 23446 | 23815 | */ |
| 23447 | 23816 | if( sqlite3_stricmp(z, "julianday")==0 ){ |
| 23817 | + if( idx>1 ) return 1; /* IMP: R-31176-64601 */ |
| 23448 | 23818 | if( p->validJD && p->rawS ){ |
| 23449 | 23819 | rc = 0; |
| 23450 | 23820 | p->rawS = 0; |
| 23451 | 23821 | } |
| 23452 | 23822 | } |
| | @@ -23458,13 +23828,11 @@ |
| 23458 | 23828 | ** |
| 23459 | 23829 | ** Assuming the current time value is UTC (a.k.a. GMT), shift it to |
| 23460 | 23830 | ** show local time. |
| 23461 | 23831 | */ |
| 23462 | 23832 | if( sqlite3_stricmp(z, "localtime")==0 && sqlite3NotPureFunc(pCtx) ){ |
| 23463 | | - computeJD(p); |
| 23464 | | - p->iJD += localtimeOffset(p, pCtx, &rc); |
| 23465 | | - clearYMD_HMS_TZ(p); |
| 23833 | + rc = toLocaltime(p, pCtx); |
| 23466 | 23834 | } |
| 23467 | 23835 | break; |
| 23468 | 23836 | } |
| 23469 | 23837 | #endif |
| 23470 | 23838 | case 'u': { |
| | @@ -23473,10 +23841,11 @@ |
| 23473 | 23841 | ** |
| 23474 | 23842 | ** Treat the current value of p->s as the number of |
| 23475 | 23843 | ** seconds since 1970. Convert to a real julian day number. |
| 23476 | 23844 | */ |
| 23477 | 23845 | if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){ |
| 23846 | + if( idx>1 ) return 1; /* IMP: R-49255-55373 */ |
| 23478 | 23847 | r = p->s*1000.0 + 210866760000000.0; |
| 23479 | 23848 | if( r>=0.0 && r<464269060800000.0 ){ |
| 23480 | 23849 | clearYMD_HMS_TZ(p); |
| 23481 | 23850 | p->iJD = (sqlite3_int64)(r + 0.5); |
| 23482 | 23851 | p->validJD = 1; |
| | @@ -23485,22 +23854,35 @@ |
| 23485 | 23854 | } |
| 23486 | 23855 | } |
| 23487 | 23856 | #ifndef SQLITE_OMIT_LOCALTIME |
| 23488 | 23857 | else if( sqlite3_stricmp(z, "utc")==0 && sqlite3NotPureFunc(pCtx) ){ |
| 23489 | 23858 | if( p->tzSet==0 ){ |
| 23490 | | - sqlite3_int64 c1; |
| 23859 | + i64 iOrigJD; /* Original localtime */ |
| 23860 | + i64 iGuess; /* Guess at the corresponding utc time */ |
| 23861 | + int cnt = 0; /* Safety to prevent infinite loop */ |
| 23862 | + int iErr; /* Guess is off by this much */ |
| 23863 | + |
| 23491 | 23864 | computeJD(p); |
| 23492 | | - c1 = localtimeOffset(p, pCtx, &rc); |
| 23493 | | - if( rc==SQLITE_OK ){ |
| 23494 | | - p->iJD -= c1; |
| 23495 | | - clearYMD_HMS_TZ(p); |
| 23496 | | - p->iJD += c1 - localtimeOffset(p, pCtx, &rc); |
| 23497 | | - } |
| 23865 | + iGuess = iOrigJD = p->iJD; |
| 23866 | + iErr = 0; |
| 23867 | + do{ |
| 23868 | + DateTime new; |
| 23869 | + memset(&new, 0, sizeof(new)); |
| 23870 | + iGuess -= iErr; |
| 23871 | + new.iJD = iGuess; |
| 23872 | + new.validJD = 1; |
| 23873 | + rc = toLocaltime(&new, pCtx); |
| 23874 | + if( rc ) return rc; |
| 23875 | + computeJD(&new); |
| 23876 | + iErr = new.iJD - iOrigJD; |
| 23877 | + }while( iErr && cnt++<3 ); |
| 23878 | + memset(p, 0, sizeof(*p)); |
| 23879 | + p->iJD = iGuess; |
| 23880 | + p->validJD = 1; |
| 23498 | 23881 | p->tzSet = 1; |
| 23499 | | - }else{ |
| 23500 | | - rc = SQLITE_OK; |
| 23501 | 23882 | } |
| 23883 | + rc = SQLITE_OK; |
| 23502 | 23884 | } |
| 23503 | 23885 | #endif |
| 23504 | 23886 | break; |
| 23505 | 23887 | } |
| 23506 | 23888 | case 'w': { |
| | @@ -23686,11 +24068,11 @@ |
| 23686 | 24068 | } |
| 23687 | 24069 | } |
| 23688 | 24070 | for(i=1; i<argc; i++){ |
| 23689 | 24071 | z = sqlite3_value_text(argv[i]); |
| 23690 | 24072 | n = sqlite3_value_bytes(argv[i]); |
| 23691 | | - if( z==0 || parseModifier(context, (char*)z, n, p) ) return 1; |
| 24073 | + if( z==0 || parseModifier(context, (char*)z, n, p, i) ) return 1; |
| 23692 | 24074 | } |
| 23693 | 24075 | computeJD(p); |
| 23694 | 24076 | if( p->isError || !validJulianDay(p->iJD) ) return 1; |
| 23695 | 24077 | return 0; |
| 23696 | 24078 | } |
| | @@ -23746,15 +24128,42 @@ |
| 23746 | 24128 | int argc, |
| 23747 | 24129 | sqlite3_value **argv |
| 23748 | 24130 | ){ |
| 23749 | 24131 | DateTime x; |
| 23750 | 24132 | if( isDate(context, argc, argv, &x)==0 ){ |
| 23751 | | - char zBuf[100]; |
| 24133 | + int Y, s; |
| 24134 | + char zBuf[24]; |
| 23752 | 24135 | computeYMD_HMS(&x); |
| 23753 | | - sqlite3_snprintf(sizeof(zBuf), zBuf, "%04d-%02d-%02d %02d:%02d:%02d", |
| 23754 | | - x.Y, x.M, x.D, x.h, x.m, (int)(x.s)); |
| 23755 | | - sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); |
| 24136 | + Y = x.Y; |
| 24137 | + if( Y<0 ) Y = -Y; |
| 24138 | + zBuf[1] = '0' + (Y/1000)%10; |
| 24139 | + zBuf[2] = '0' + (Y/100)%10; |
| 24140 | + zBuf[3] = '0' + (Y/10)%10; |
| 24141 | + zBuf[4] = '0' + (Y)%10; |
| 24142 | + zBuf[5] = '-'; |
| 24143 | + zBuf[6] = '0' + (x.M/10)%10; |
| 24144 | + zBuf[7] = '0' + (x.M)%10; |
| 24145 | + zBuf[8] = '-'; |
| 24146 | + zBuf[9] = '0' + (x.D/10)%10; |
| 24147 | + zBuf[10] = '0' + (x.D)%10; |
| 24148 | + zBuf[11] = ' '; |
| 24149 | + zBuf[12] = '0' + (x.h/10)%10; |
| 24150 | + zBuf[13] = '0' + (x.h)%10; |
| 24151 | + zBuf[14] = ':'; |
| 24152 | + zBuf[15] = '0' + (x.m/10)%10; |
| 24153 | + zBuf[16] = '0' + (x.m)%10; |
| 24154 | + zBuf[17] = ':'; |
| 24155 | + s = (int)x.s; |
| 24156 | + zBuf[18] = '0' + (s/10)%10; |
| 24157 | + zBuf[19] = '0' + (s)%10; |
| 24158 | + zBuf[20] = 0; |
| 24159 | + if( x.Y<0 ){ |
| 24160 | + zBuf[0] = '-'; |
| 24161 | + sqlite3_result_text(context, zBuf, 20, SQLITE_TRANSIENT); |
| 24162 | + }else{ |
| 24163 | + sqlite3_result_text(context, &zBuf[1], 19, SQLITE_TRANSIENT); |
| 24164 | + } |
| 23756 | 24165 | } |
| 23757 | 24166 | } |
| 23758 | 24167 | |
| 23759 | 24168 | /* |
| 23760 | 24169 | ** time( TIMESTRING, MOD, MOD, ...) |
| | @@ -23766,14 +24175,24 @@ |
| 23766 | 24175 | int argc, |
| 23767 | 24176 | sqlite3_value **argv |
| 23768 | 24177 | ){ |
| 23769 | 24178 | DateTime x; |
| 23770 | 24179 | if( isDate(context, argc, argv, &x)==0 ){ |
| 23771 | | - char zBuf[100]; |
| 24180 | + int s; |
| 24181 | + char zBuf[16]; |
| 23772 | 24182 | computeHMS(&x); |
| 23773 | | - sqlite3_snprintf(sizeof(zBuf), zBuf, "%02d:%02d:%02d", x.h, x.m, (int)x.s); |
| 23774 | | - sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); |
| 24183 | + zBuf[0] = '0' + (x.h/10)%10; |
| 24184 | + zBuf[1] = '0' + (x.h)%10; |
| 24185 | + zBuf[2] = ':'; |
| 24186 | + zBuf[3] = '0' + (x.m/10)%10; |
| 24187 | + zBuf[4] = '0' + (x.m)%10; |
| 24188 | + zBuf[5] = ':'; |
| 24189 | + s = (int)x.s; |
| 24190 | + zBuf[6] = '0' + (s/10)%10; |
| 24191 | + zBuf[7] = '0' + (s)%10; |
| 24192 | + zBuf[8] = 0; |
| 24193 | + sqlite3_result_text(context, zBuf, 8, SQLITE_TRANSIENT); |
| 23775 | 24194 | } |
| 23776 | 24195 | } |
| 23777 | 24196 | |
| 23778 | 24197 | /* |
| 23779 | 24198 | ** date( TIMESTRING, MOD, MOD, ...) |
| | @@ -23785,14 +24204,32 @@ |
| 23785 | 24204 | int argc, |
| 23786 | 24205 | sqlite3_value **argv |
| 23787 | 24206 | ){ |
| 23788 | 24207 | DateTime x; |
| 23789 | 24208 | if( isDate(context, argc, argv, &x)==0 ){ |
| 23790 | | - char zBuf[100]; |
| 24209 | + int Y; |
| 24210 | + char zBuf[16]; |
| 23791 | 24211 | computeYMD(&x); |
| 23792 | | - sqlite3_snprintf(sizeof(zBuf), zBuf, "%04d-%02d-%02d", x.Y, x.M, x.D); |
| 23793 | | - sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); |
| 24212 | + Y = x.Y; |
| 24213 | + if( Y<0 ) Y = -Y; |
| 24214 | + zBuf[1] = '0' + (Y/1000)%10; |
| 24215 | + zBuf[2] = '0' + (Y/100)%10; |
| 24216 | + zBuf[3] = '0' + (Y/10)%10; |
| 24217 | + zBuf[4] = '0' + (Y)%10; |
| 24218 | + zBuf[5] = '-'; |
| 24219 | + zBuf[6] = '0' + (x.M/10)%10; |
| 24220 | + zBuf[7] = '0' + (x.M)%10; |
| 24221 | + zBuf[8] = '-'; |
| 24222 | + zBuf[9] = '0' + (x.D/10)%10; |
| 24223 | + zBuf[10] = '0' + (x.D)%10; |
| 24224 | + zBuf[11] = 0; |
| 24225 | + if( x.Y<0 ){ |
| 24226 | + zBuf[0] = '-'; |
| 24227 | + sqlite3_result_text(context, zBuf, 11, SQLITE_TRANSIENT); |
| 24228 | + }else{ |
| 24229 | + sqlite3_result_text(context, &zBuf[1], 10, SQLITE_TRANSIENT); |
| 24230 | + } |
| 23794 | 24231 | } |
| 23795 | 24232 | } |
| 23796 | 24233 | |
| 23797 | 24234 | /* |
| 23798 | 24235 | ** strftime( FORMAT, TIMESTRING, MOD, MOD, ...) |
| | @@ -28956,22 +29393,31 @@ |
| 28956 | 29393 | /* |
| 28957 | 29394 | ** Call this routine to record the fact that an OOM (out-of-memory) error |
| 28958 | 29395 | ** has happened. This routine will set db->mallocFailed, and also |
| 28959 | 29396 | ** temporarily disable the lookaside memory allocator and interrupt |
| 28960 | 29397 | ** any running VDBEs. |
| 29398 | +** |
| 29399 | +** Always return a NULL pointer so that this routine can be invoked using |
| 29400 | +** |
| 29401 | +** return sqlite3OomFault(db); |
| 29402 | +** |
| 29403 | +** and thereby avoid unnecessary stack frame allocations for the overwhelmingly |
| 29404 | +** common case where no OOM occurs. |
| 28961 | 29405 | */ |
| 28962 | | -SQLITE_PRIVATE void sqlite3OomFault(sqlite3 *db){ |
| 29406 | +SQLITE_PRIVATE void *sqlite3OomFault(sqlite3 *db){ |
| 28963 | 29407 | if( db->mallocFailed==0 && db->bBenignMalloc==0 ){ |
| 28964 | 29408 | db->mallocFailed = 1; |
| 28965 | 29409 | if( db->nVdbeExec>0 ){ |
| 28966 | 29410 | AtomicStore(&db->u1.isInterrupted, 1); |
| 28967 | 29411 | } |
| 28968 | 29412 | DisableLookaside; |
| 28969 | 29413 | if( db->pParse ){ |
| 29414 | + sqlite3ErrorMsg(db->pParse, "out of memory"); |
| 28970 | 29415 | db->pParse->rc = SQLITE_NOMEM_BKPT; |
| 28971 | 29416 | } |
| 28972 | 29417 | } |
| 29418 | + return 0; |
| 28973 | 29419 | } |
| 28974 | 29420 | |
| 28975 | 29421 | /* |
| 28976 | 29422 | ** This routine reactivates the memory allocator and clears the |
| 28977 | 29423 | ** db->mallocFailed flag as necessary. |
| | @@ -29876,17 +30322,26 @@ |
| 29876 | 30322 | bufpt[j] = 0; |
| 29877 | 30323 | length = j; |
| 29878 | 30324 | goto adjust_width_for_utf8; |
| 29879 | 30325 | } |
| 29880 | 30326 | case etTOKEN: { |
| 29881 | | - Token *pToken; |
| 29882 | 30327 | if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return; |
| 29883 | | - pToken = va_arg(ap, Token*); |
| 29884 | | - assert( bArgList==0 ); |
| 29885 | | - if( pToken && pToken->n ){ |
| 29886 | | - sqlite3_str_append(pAccum, (const char*)pToken->z, pToken->n); |
| 29887 | | - sqlite3RecordErrorByteOffset(pAccum->db, pToken->z); |
| 30328 | + if( flag_alternateform ){ |
| 30329 | + /* %#T means an Expr pointer that uses Expr.u.zToken */ |
| 30330 | + Expr *pExpr = va_arg(ap,Expr*); |
| 30331 | + if( ALWAYS(pExpr) && ALWAYS(!ExprHasProperty(pExpr,EP_IntValue)) ){ |
| 30332 | + sqlite3_str_appendall(pAccum, (const char*)pExpr->u.zToken); |
| 30333 | + sqlite3RecordErrorOffsetOfExpr(pAccum->db, pExpr); |
| 30334 | + } |
| 30335 | + }else{ |
| 30336 | + /* %T means a Token pointer */ |
| 30337 | + Token *pToken = va_arg(ap, Token*); |
| 30338 | + assert( bArgList==0 ); |
| 30339 | + if( pToken && pToken->n ){ |
| 30340 | + sqlite3_str_append(pAccum, (const char*)pToken->z, pToken->n); |
| 30341 | + sqlite3RecordErrorByteOffset(pAccum->db, pToken->z); |
| 30342 | + } |
| 29888 | 30343 | } |
| 29889 | 30344 | length = width = 0; |
| 29890 | 30345 | break; |
| 29891 | 30346 | } |
| 29892 | 30347 | case etSRCITEM: { |
| | @@ -29960,10 +30415,22 @@ |
| 29960 | 30415 | zEnd = &zText[strlen(zText)]; |
| 29961 | 30416 | if( SQLITE_WITHIN(z,zText,zEnd) ){ |
| 29962 | 30417 | db->errByteOffset = (int)(z-zText); |
| 29963 | 30418 | } |
| 29964 | 30419 | } |
| 30420 | + |
| 30421 | +/* |
| 30422 | +** If pExpr has a byte offset for the start of a token, record that as |
| 30423 | +** as the error offset. |
| 30424 | +*/ |
| 30425 | +SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3 *db, const Expr *pExpr){ |
| 30426 | + while( pExpr && (ExprHasProperty(pExpr,EP_FromJoin) || pExpr->w.iOfst<=0) ){ |
| 30427 | + pExpr = pExpr->pLeft; |
| 30428 | + } |
| 30429 | + if( pExpr==0 ) return; |
| 30430 | + db->errByteOffset = pExpr->w.iOfst; |
| 30431 | +} |
| 29965 | 30432 | |
| 29966 | 30433 | /* |
| 29967 | 30434 | ** Enlarge the memory allocation on a StrAccum object so that it is |
| 29968 | 30435 | ** able to accept at least N more bytes of text. |
| 29969 | 30436 | ** |
| | @@ -30423,11 +30890,11 @@ |
| 30423 | 30890 | memset(p, 0, sizeof(*p)); |
| 30424 | 30891 | }else{ |
| 30425 | 30892 | p->iLevel++; |
| 30426 | 30893 | } |
| 30427 | 30894 | assert( moreToFollow==0 || moreToFollow==1 ); |
| 30428 | | - if( p->iLevel<sizeof(p->bLine) ) p->bLine[p->iLevel] = moreToFollow; |
| 30895 | + if( p->iLevel<(int)sizeof(p->bLine) ) p->bLine[p->iLevel] = moreToFollow; |
| 30429 | 30896 | return p; |
| 30430 | 30897 | } |
| 30431 | 30898 | |
| 30432 | 30899 | /* |
| 30433 | 30900 | ** Finished with one layer of the tree |
| | @@ -30447,11 +30914,11 @@ |
| 30447 | 30914 | int i; |
| 30448 | 30915 | StrAccum acc; |
| 30449 | 30916 | char zBuf[500]; |
| 30450 | 30917 | sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); |
| 30451 | 30918 | if( p ){ |
| 30452 | | - for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){ |
| 30919 | + for(i=0; i<p->iLevel && i<(int)sizeof(p->bLine)-1; i++){ |
| 30453 | 30920 | sqlite3_str_append(&acc, p->bLine[i] ? "| " : " ", 4); |
| 30454 | 30921 | } |
| 30455 | 30922 | sqlite3_str_append(&acc, p->bLine[i] ? "|-- " : "'-- ", 4); |
| 30456 | 30923 | } |
| 30457 | 30924 | if( zFormat!=0 ){ |
| | @@ -30777,11 +31244,11 @@ |
| 30777 | 31244 | ** Generate a human-readable explanation for a Window Function object |
| 30778 | 31245 | */ |
| 30779 | 31246 | SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){ |
| 30780 | 31247 | pView = sqlite3TreeViewPush(pView, more); |
| 30781 | 31248 | sqlite3TreeViewLine(pView, "WINFUNC %s(%d)", |
| 30782 | | - pWin->pFunc->zName, pWin->pFunc->nArg); |
| 31249 | + pWin->pWFunc->zName, pWin->pWFunc->nArg); |
| 30783 | 31250 | sqlite3TreeViewWindow(pView, pWin, 0); |
| 30784 | 31251 | sqlite3TreeViewPop(pView); |
| 30785 | 31252 | } |
| 30786 | 31253 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 30787 | 31254 | |
| | @@ -30802,11 +31269,11 @@ |
| 30802 | 31269 | StrAccum x; |
| 30803 | 31270 | sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0); |
| 30804 | 31271 | sqlite3_str_appendf(&x, " fg.af=%x.%c", |
| 30805 | 31272 | pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n'); |
| 30806 | 31273 | if( ExprHasProperty(pExpr, EP_FromJoin) ){ |
| 30807 | | - sqlite3_str_appendf(&x, " iRJT=%d", pExpr->iRightJoinTable); |
| 31274 | + sqlite3_str_appendf(&x, " iRJT=%d", pExpr->w.iRightJoinTable); |
| 30808 | 31275 | } |
| 30809 | 31276 | if( ExprHasProperty(pExpr, EP_FromDDL) ){ |
| 30810 | 31277 | sqlite3_str_appendf(&x, " DDL"); |
| 30811 | 31278 | } |
| 30812 | 31279 | if( ExprHasVVAProperty(pExpr, EP_Immutable) ){ |
| | @@ -32356,17 +32823,23 @@ |
| 32356 | 32823 | */ |
| 32357 | 32824 | SQLITE_PRIVATE void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){ |
| 32358 | 32825 | char *zMsg; |
| 32359 | 32826 | va_list ap; |
| 32360 | 32827 | sqlite3 *db = pParse->db; |
| 32828 | + assert( db!=0 ); |
| 32829 | + assert( db->pParse==pParse ); |
| 32361 | 32830 | db->errByteOffset = -2; |
| 32362 | 32831 | va_start(ap, zFormat); |
| 32363 | 32832 | zMsg = sqlite3VMPrintf(db, zFormat, ap); |
| 32364 | 32833 | va_end(ap); |
| 32365 | 32834 | if( db->errByteOffset<-1 ) db->errByteOffset = -1; |
| 32366 | 32835 | if( db->suppressErr ){ |
| 32367 | 32836 | sqlite3DbFree(db, zMsg); |
| 32837 | + if( db->mallocFailed ){ |
| 32838 | + pParse->nErr++; |
| 32839 | + pParse->rc = SQLITE_NOMEM; |
| 32840 | + } |
| 32368 | 32841 | }else{ |
| 32369 | 32842 | pParse->nErr++; |
| 32370 | 32843 | sqlite3DbFree(db, pParse->zErrMsg); |
| 32371 | 32844 | pParse->zErrMsg = zMsg; |
| 32372 | 32845 | pParse->rc = SQLITE_ERROR; |
| | @@ -34164,46 +34637,46 @@ |
| 34164 | 34637 | SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){ |
| 34165 | 34638 | static const char *const azName[] = { |
| 34166 | 34639 | /* 0 */ "Savepoint" OpHelp(""), |
| 34167 | 34640 | /* 1 */ "AutoCommit" OpHelp(""), |
| 34168 | 34641 | /* 2 */ "Transaction" OpHelp(""), |
| 34169 | | - /* 3 */ "SorterNext" OpHelp(""), |
| 34170 | | - /* 4 */ "Prev" OpHelp(""), |
| 34171 | | - /* 5 */ "Next" OpHelp(""), |
| 34172 | | - /* 6 */ "Checkpoint" OpHelp(""), |
| 34173 | | - /* 7 */ "JournalMode" OpHelp(""), |
| 34174 | | - /* 8 */ "Vacuum" OpHelp(""), |
| 34175 | | - /* 9 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"), |
| 34176 | | - /* 10 */ "VUpdate" OpHelp("data=r[P3@P2]"), |
| 34177 | | - /* 11 */ "Goto" OpHelp(""), |
| 34178 | | - /* 12 */ "Gosub" OpHelp(""), |
| 34179 | | - /* 13 */ "InitCoroutine" OpHelp(""), |
| 34180 | | - /* 14 */ "Yield" OpHelp(""), |
| 34181 | | - /* 15 */ "MustBeInt" OpHelp(""), |
| 34182 | | - /* 16 */ "Jump" OpHelp(""), |
| 34183 | | - /* 17 */ "Once" OpHelp(""), |
| 34184 | | - /* 18 */ "If" OpHelp(""), |
| 34642 | + /* 3 */ "Checkpoint" OpHelp(""), |
| 34643 | + /* 4 */ "JournalMode" OpHelp(""), |
| 34644 | + /* 5 */ "Vacuum" OpHelp(""), |
| 34645 | + /* 6 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"), |
| 34646 | + /* 7 */ "VUpdate" OpHelp("data=r[P3@P2]"), |
| 34647 | + /* 8 */ "Goto" OpHelp(""), |
| 34648 | + /* 9 */ "Gosub" OpHelp(""), |
| 34649 | + /* 10 */ "InitCoroutine" OpHelp(""), |
| 34650 | + /* 11 */ "Yield" OpHelp(""), |
| 34651 | + /* 12 */ "MustBeInt" OpHelp(""), |
| 34652 | + /* 13 */ "Jump" OpHelp(""), |
| 34653 | + /* 14 */ "Once" OpHelp(""), |
| 34654 | + /* 15 */ "If" OpHelp(""), |
| 34655 | + /* 16 */ "IfNot" OpHelp(""), |
| 34656 | + /* 17 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"), |
| 34657 | + /* 18 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"), |
| 34185 | 34658 | /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"), |
| 34186 | | - /* 20 */ "IfNot" OpHelp(""), |
| 34187 | | - /* 21 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"), |
| 34188 | | - /* 22 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"), |
| 34189 | | - /* 23 */ "SeekLT" OpHelp("key=r[P3@P4]"), |
| 34190 | | - /* 24 */ "SeekLE" OpHelp("key=r[P3@P4]"), |
| 34191 | | - /* 25 */ "SeekGE" OpHelp("key=r[P3@P4]"), |
| 34192 | | - /* 26 */ "SeekGT" OpHelp("key=r[P3@P4]"), |
| 34193 | | - /* 27 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"), |
| 34194 | | - /* 28 */ "IfNoHope" OpHelp("key=r[P3@P4]"), |
| 34195 | | - /* 29 */ "NoConflict" OpHelp("key=r[P3@P4]"), |
| 34196 | | - /* 30 */ "NotFound" OpHelp("key=r[P3@P4]"), |
| 34197 | | - /* 31 */ "Found" OpHelp("key=r[P3@P4]"), |
| 34198 | | - /* 32 */ "SeekRowid" OpHelp("intkey=r[P3]"), |
| 34199 | | - /* 33 */ "NotExists" OpHelp("intkey=r[P3]"), |
| 34200 | | - /* 34 */ "Last" OpHelp(""), |
| 34201 | | - /* 35 */ "IfSmaller" OpHelp(""), |
| 34202 | | - /* 36 */ "SorterSort" OpHelp(""), |
| 34203 | | - /* 37 */ "Sort" OpHelp(""), |
| 34204 | | - /* 38 */ "Rewind" OpHelp(""), |
| 34659 | + /* 20 */ "SeekLT" OpHelp("key=r[P3@P4]"), |
| 34660 | + /* 21 */ "SeekLE" OpHelp("key=r[P3@P4]"), |
| 34661 | + /* 22 */ "SeekGE" OpHelp("key=r[P3@P4]"), |
| 34662 | + /* 23 */ "SeekGT" OpHelp("key=r[P3@P4]"), |
| 34663 | + /* 24 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"), |
| 34664 | + /* 25 */ "IfNoHope" OpHelp("key=r[P3@P4]"), |
| 34665 | + /* 26 */ "NoConflict" OpHelp("key=r[P3@P4]"), |
| 34666 | + /* 27 */ "NotFound" OpHelp("key=r[P3@P4]"), |
| 34667 | + /* 28 */ "Found" OpHelp("key=r[P3@P4]"), |
| 34668 | + /* 29 */ "SeekRowid" OpHelp("intkey=r[P3]"), |
| 34669 | + /* 30 */ "NotExists" OpHelp("intkey=r[P3]"), |
| 34670 | + /* 31 */ "Last" OpHelp(""), |
| 34671 | + /* 32 */ "IfSmaller" OpHelp(""), |
| 34672 | + /* 33 */ "SorterSort" OpHelp(""), |
| 34673 | + /* 34 */ "Sort" OpHelp(""), |
| 34674 | + /* 35 */ "Rewind" OpHelp(""), |
| 34675 | + /* 36 */ "SorterNext" OpHelp(""), |
| 34676 | + /* 37 */ "Prev" OpHelp(""), |
| 34677 | + /* 38 */ "Next" OpHelp(""), |
| 34205 | 34678 | /* 39 */ "IdxLE" OpHelp("key=r[P3@P4]"), |
| 34206 | 34679 | /* 40 */ "IdxGT" OpHelp("key=r[P3@P4]"), |
| 34207 | 34680 | /* 41 */ "IdxLT" OpHelp("key=r[P3@P4]"), |
| 34208 | 34681 | /* 42 */ "IdxGE" OpHelp("key=r[P3@P4]"), |
| 34209 | 34682 | /* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"), |
| | @@ -34232,41 +34705,41 @@ |
| 34232 | 34705 | /* 66 */ "Function" OpHelp("r[P3]=func(r[P2@NP])"), |
| 34233 | 34706 | /* 67 */ "Return" OpHelp(""), |
| 34234 | 34707 | /* 68 */ "EndCoroutine" OpHelp(""), |
| 34235 | 34708 | /* 69 */ "HaltIfNull" OpHelp("if r[P3]=null halt"), |
| 34236 | 34709 | /* 70 */ "Halt" OpHelp(""), |
| 34237 | | - /* 71 */ "Integer" OpHelp("r[P2]=P1"), |
| 34238 | | - /* 72 */ "Int64" OpHelp("r[P2]=P4"), |
| 34239 | | - /* 73 */ "String" OpHelp("r[P2]='P4' (len=P1)"), |
| 34240 | | - /* 74 */ "Null" OpHelp("r[P2..P3]=NULL"), |
| 34241 | | - /* 75 */ "SoftNull" OpHelp("r[P1]=NULL"), |
| 34242 | | - /* 76 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), |
| 34243 | | - /* 77 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), |
| 34244 | | - /* 78 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 34245 | | - /* 79 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), |
| 34246 | | - /* 80 */ "SCopy" OpHelp("r[P2]=r[P1]"), |
| 34247 | | - /* 81 */ "IntCopy" OpHelp("r[P2]=r[P1]"), |
| 34248 | | - /* 82 */ "FkCheck" OpHelp(""), |
| 34249 | | - /* 83 */ "ResultRow" OpHelp("output=r[P1@P2]"), |
| 34250 | | - /* 84 */ "CollSeq" OpHelp(""), |
| 34251 | | - /* 85 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), |
| 34252 | | - /* 86 */ "RealAffinity" OpHelp(""), |
| 34253 | | - /* 87 */ "Cast" OpHelp("affinity(r[P1])"), |
| 34254 | | - /* 88 */ "Permutation" OpHelp(""), |
| 34255 | | - /* 89 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"), |
| 34256 | | - /* 90 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"), |
| 34257 | | - /* 91 */ "ZeroOrNull" OpHelp("r[P2] = 0 OR NULL"), |
| 34258 | | - /* 92 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"), |
| 34259 | | - /* 93 */ "Column" OpHelp("r[P3]=PX"), |
| 34260 | | - /* 94 */ "TypeCheck" OpHelp("typecheck(r[P1@P2])"), |
| 34261 | | - /* 95 */ "Affinity" OpHelp("affinity(r[P1@P2])"), |
| 34262 | | - /* 96 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), |
| 34263 | | - /* 97 */ "Count" OpHelp("r[P2]=count()"), |
| 34264 | | - /* 98 */ "ReadCookie" OpHelp(""), |
| 34265 | | - /* 99 */ "SetCookie" OpHelp(""), |
| 34266 | | - /* 100 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), |
| 34267 | | - /* 101 */ "OpenRead" OpHelp("root=P2 iDb=P3"), |
| 34710 | + /* 71 */ "BeginSubrtn" OpHelp("r[P2]=P1"), |
| 34711 | + /* 72 */ "Integer" OpHelp("r[P2]=P1"), |
| 34712 | + /* 73 */ "Int64" OpHelp("r[P2]=P4"), |
| 34713 | + /* 74 */ "String" OpHelp("r[P2]='P4' (len=P1)"), |
| 34714 | + /* 75 */ "Null" OpHelp("r[P2..P3]=NULL"), |
| 34715 | + /* 76 */ "SoftNull" OpHelp("r[P1]=NULL"), |
| 34716 | + /* 77 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), |
| 34717 | + /* 78 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), |
| 34718 | + /* 79 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 34719 | + /* 80 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), |
| 34720 | + /* 81 */ "SCopy" OpHelp("r[P2]=r[P1]"), |
| 34721 | + /* 82 */ "IntCopy" OpHelp("r[P2]=r[P1]"), |
| 34722 | + /* 83 */ "FkCheck" OpHelp(""), |
| 34723 | + /* 84 */ "ResultRow" OpHelp("output=r[P1@P2]"), |
| 34724 | + /* 85 */ "CollSeq" OpHelp(""), |
| 34725 | + /* 86 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), |
| 34726 | + /* 87 */ "RealAffinity" OpHelp(""), |
| 34727 | + /* 88 */ "Cast" OpHelp("affinity(r[P1])"), |
| 34728 | + /* 89 */ "Permutation" OpHelp(""), |
| 34729 | + /* 90 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"), |
| 34730 | + /* 91 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"), |
| 34731 | + /* 92 */ "ZeroOrNull" OpHelp("r[P2] = 0 OR NULL"), |
| 34732 | + /* 93 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"), |
| 34733 | + /* 94 */ "Column" OpHelp("r[P3]=PX"), |
| 34734 | + /* 95 */ "TypeCheck" OpHelp("typecheck(r[P1@P2])"), |
| 34735 | + /* 96 */ "Affinity" OpHelp("affinity(r[P1@P2])"), |
| 34736 | + /* 97 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), |
| 34737 | + /* 98 */ "Count" OpHelp("r[P2]=count()"), |
| 34738 | + /* 99 */ "ReadCookie" OpHelp(""), |
| 34739 | + /* 100 */ "SetCookie" OpHelp(""), |
| 34740 | + /* 101 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), |
| 34268 | 34741 | /* 102 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"), |
| 34269 | 34742 | /* 103 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"), |
| 34270 | 34743 | /* 104 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"), |
| 34271 | 34744 | /* 105 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"), |
| 34272 | 34745 | /* 106 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"), |
| | @@ -34273,82 +34746,84 @@ |
| 34273 | 34746 | /* 107 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"), |
| 34274 | 34747 | /* 108 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"), |
| 34275 | 34748 | /* 109 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"), |
| 34276 | 34749 | /* 110 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"), |
| 34277 | 34750 | /* 111 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"), |
| 34278 | | - /* 112 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), |
| 34279 | | - /* 113 */ "OpenDup" OpHelp(""), |
| 34751 | + /* 112 */ "OpenRead" OpHelp("root=P2 iDb=P3"), |
| 34752 | + /* 113 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), |
| 34280 | 34753 | /* 114 */ "BitNot" OpHelp("r[P2]= ~r[P1]"), |
| 34281 | | - /* 115 */ "OpenAutoindex" OpHelp("nColumn=P2"), |
| 34282 | | - /* 116 */ "OpenEphemeral" OpHelp("nColumn=P2"), |
| 34754 | + /* 115 */ "OpenDup" OpHelp(""), |
| 34755 | + /* 116 */ "OpenAutoindex" OpHelp("nColumn=P2"), |
| 34283 | 34756 | /* 117 */ "String8" OpHelp("r[P2]='P4'"), |
| 34284 | | - /* 118 */ "SorterOpen" OpHelp(""), |
| 34285 | | - /* 119 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), |
| 34286 | | - /* 120 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), |
| 34287 | | - /* 121 */ "Close" OpHelp(""), |
| 34288 | | - /* 122 */ "ColumnsUsed" OpHelp(""), |
| 34289 | | - /* 123 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"), |
| 34290 | | - /* 124 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"), |
| 34291 | | - /* 125 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), |
| 34292 | | - /* 126 */ "NewRowid" OpHelp("r[P2]=rowid"), |
| 34293 | | - /* 127 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), |
| 34294 | | - /* 128 */ "RowCell" OpHelp(""), |
| 34295 | | - /* 129 */ "Delete" OpHelp(""), |
| 34296 | | - /* 130 */ "ResetCount" OpHelp(""), |
| 34297 | | - /* 131 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), |
| 34298 | | - /* 132 */ "SorterData" OpHelp("r[P2]=data"), |
| 34299 | | - /* 133 */ "RowData" OpHelp("r[P2]=data"), |
| 34300 | | - /* 134 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 34301 | | - /* 135 */ "NullRow" OpHelp(""), |
| 34302 | | - /* 136 */ "SeekEnd" OpHelp(""), |
| 34303 | | - /* 137 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 34304 | | - /* 138 */ "SorterInsert" OpHelp("key=r[P2]"), |
| 34305 | | - /* 139 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 34306 | | - /* 140 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), |
| 34307 | | - /* 141 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 34308 | | - /* 142 */ "FinishSeek" OpHelp(""), |
| 34309 | | - /* 143 */ "Destroy" OpHelp(""), |
| 34310 | | - /* 144 */ "Clear" OpHelp(""), |
| 34311 | | - /* 145 */ "ResetSorter" OpHelp(""), |
| 34312 | | - /* 146 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"), |
| 34313 | | - /* 147 */ "SqlExec" OpHelp(""), |
| 34314 | | - /* 148 */ "ParseSchema" OpHelp(""), |
| 34315 | | - /* 149 */ "LoadAnalysis" OpHelp(""), |
| 34316 | | - /* 150 */ "DropTable" OpHelp(""), |
| 34317 | | - /* 151 */ "DropIndex" OpHelp(""), |
| 34318 | | - /* 152 */ "DropTrigger" OpHelp(""), |
| 34757 | + /* 118 */ "OpenEphemeral" OpHelp("nColumn=P2"), |
| 34758 | + /* 119 */ "SorterOpen" OpHelp(""), |
| 34759 | + /* 120 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), |
| 34760 | + /* 121 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), |
| 34761 | + /* 122 */ "Close" OpHelp(""), |
| 34762 | + /* 123 */ "ColumnsUsed" OpHelp(""), |
| 34763 | + /* 124 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"), |
| 34764 | + /* 125 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"), |
| 34765 | + /* 126 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), |
| 34766 | + /* 127 */ "NewRowid" OpHelp("r[P2]=rowid"), |
| 34767 | + /* 128 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), |
| 34768 | + /* 129 */ "RowCell" OpHelp(""), |
| 34769 | + /* 130 */ "Delete" OpHelp(""), |
| 34770 | + /* 131 */ "ResetCount" OpHelp(""), |
| 34771 | + /* 132 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), |
| 34772 | + /* 133 */ "SorterData" OpHelp("r[P2]=data"), |
| 34773 | + /* 134 */ "RowData" OpHelp("r[P2]=data"), |
| 34774 | + /* 135 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 34775 | + /* 136 */ "NullRow" OpHelp(""), |
| 34776 | + /* 137 */ "SeekEnd" OpHelp(""), |
| 34777 | + /* 138 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 34778 | + /* 139 */ "SorterInsert" OpHelp("key=r[P2]"), |
| 34779 | + /* 140 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 34780 | + /* 141 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), |
| 34781 | + /* 142 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 34782 | + /* 143 */ "FinishSeek" OpHelp(""), |
| 34783 | + /* 144 */ "Destroy" OpHelp(""), |
| 34784 | + /* 145 */ "Clear" OpHelp(""), |
| 34785 | + /* 146 */ "ResetSorter" OpHelp(""), |
| 34786 | + /* 147 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"), |
| 34787 | + /* 148 */ "SqlExec" OpHelp(""), |
| 34788 | + /* 149 */ "ParseSchema" OpHelp(""), |
| 34789 | + /* 150 */ "LoadAnalysis" OpHelp(""), |
| 34790 | + /* 151 */ "DropTable" OpHelp(""), |
| 34791 | + /* 152 */ "DropIndex" OpHelp(""), |
| 34319 | 34792 | /* 153 */ "Real" OpHelp("r[P2]=P4"), |
| 34320 | | - /* 154 */ "IntegrityCk" OpHelp(""), |
| 34321 | | - /* 155 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 34322 | | - /* 156 */ "Param" OpHelp(""), |
| 34323 | | - /* 157 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 34324 | | - /* 158 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 34325 | | - /* 159 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), |
| 34326 | | - /* 160 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"), |
| 34327 | | - /* 161 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 34328 | | - /* 162 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 34329 | | - /* 163 */ "AggValue" OpHelp("r[P3]=value N=P2"), |
| 34330 | | - /* 164 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 34331 | | - /* 165 */ "Expire" OpHelp(""), |
| 34332 | | - /* 166 */ "CursorLock" OpHelp(""), |
| 34333 | | - /* 167 */ "CursorUnlock" OpHelp(""), |
| 34334 | | - /* 168 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 34335 | | - /* 169 */ "VBegin" OpHelp(""), |
| 34336 | | - /* 170 */ "VCreate" OpHelp(""), |
| 34337 | | - /* 171 */ "VDestroy" OpHelp(""), |
| 34338 | | - /* 172 */ "VOpen" OpHelp(""), |
| 34339 | | - /* 173 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 34340 | | - /* 174 */ "VRename" OpHelp(""), |
| 34341 | | - /* 175 */ "Pagecount" OpHelp(""), |
| 34342 | | - /* 176 */ "MaxPgcnt" OpHelp(""), |
| 34343 | | - /* 177 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"), |
| 34344 | | - /* 178 */ "Trace" OpHelp(""), |
| 34345 | | - /* 179 */ "CursorHint" OpHelp(""), |
| 34346 | | - /* 180 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"), |
| 34347 | | - /* 181 */ "Noop" OpHelp(""), |
| 34348 | | - /* 182 */ "Explain" OpHelp(""), |
| 34349 | | - /* 183 */ "Abortable" OpHelp(""), |
| 34793 | + /* 154 */ "DropTrigger" OpHelp(""), |
| 34794 | + /* 155 */ "IntegrityCk" OpHelp(""), |
| 34795 | + /* 156 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 34796 | + /* 157 */ "Param" OpHelp(""), |
| 34797 | + /* 158 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 34798 | + /* 159 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 34799 | + /* 160 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), |
| 34800 | + /* 161 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"), |
| 34801 | + /* 162 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 34802 | + /* 163 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 34803 | + /* 164 */ "AggValue" OpHelp("r[P3]=value N=P2"), |
| 34804 | + /* 165 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 34805 | + /* 166 */ "Expire" OpHelp(""), |
| 34806 | + /* 167 */ "CursorLock" OpHelp(""), |
| 34807 | + /* 168 */ "CursorUnlock" OpHelp(""), |
| 34808 | + /* 169 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 34809 | + /* 170 */ "VBegin" OpHelp(""), |
| 34810 | + /* 171 */ "VCreate" OpHelp(""), |
| 34811 | + /* 172 */ "VDestroy" OpHelp(""), |
| 34812 | + /* 173 */ "VOpen" OpHelp(""), |
| 34813 | + /* 174 */ "VInitIn" OpHelp("r[P2]=ValueList(P1,P3)"), |
| 34814 | + /* 175 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 34815 | + /* 176 */ "VRename" OpHelp(""), |
| 34816 | + /* 177 */ "Pagecount" OpHelp(""), |
| 34817 | + /* 178 */ "MaxPgcnt" OpHelp(""), |
| 34818 | + /* 179 */ "FilterAdd" OpHelp("filter(P1) += key(P3@P4)"), |
| 34819 | + /* 180 */ "Trace" OpHelp(""), |
| 34820 | + /* 181 */ "CursorHint" OpHelp(""), |
| 34821 | + /* 182 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"), |
| 34822 | + /* 183 */ "Noop" OpHelp(""), |
| 34823 | + /* 184 */ "Explain" OpHelp(""), |
| 34824 | + /* 185 */ "Abortable" OpHelp(""), |
| 34350 | 34825 | }; |
| 34351 | 34826 | return azName[i]; |
| 34352 | 34827 | } |
| 34353 | 34828 | #endif |
| 34354 | 34829 | |
| | @@ -39264,15 +39739,21 @@ |
| 39264 | 39739 | int ofst, /* First lock to acquire or release */ |
| 39265 | 39740 | int n, /* Number of locks to acquire or release */ |
| 39266 | 39741 | int flags /* What to do with the lock */ |
| 39267 | 39742 | ){ |
| 39268 | 39743 | unixFile *pDbFd = (unixFile*)fd; /* Connection holding shared memory */ |
| 39269 | | - unixShm *p = pDbFd->pShm; /* The shared memory being locked */ |
| 39270 | | - unixShmNode *pShmNode = p->pShmNode; /* The underlying file iNode */ |
| 39744 | + unixShm *p; /* The shared memory being locked */ |
| 39745 | + unixShmNode *pShmNode; /* The underlying file iNode */ |
| 39271 | 39746 | int rc = SQLITE_OK; /* Result code */ |
| 39272 | 39747 | u16 mask; /* Mask of locks to take or release */ |
| 39273 | | - int *aLock = pShmNode->aLock; |
| 39748 | + int *aLock; |
| 39749 | + |
| 39750 | + p = pDbFd->pShm; |
| 39751 | + if( p==0 ) return SQLITE_IOERR_SHMLOCK; |
| 39752 | + pShmNode = p->pShmNode; |
| 39753 | + if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK; |
| 39754 | + aLock = pShmNode->aLock; |
| 39274 | 39755 | |
| 39275 | 39756 | assert( pShmNode==pDbFd->pInode->pShmNode ); |
| 39276 | 39757 | assert( pShmNode->pInode==pDbFd->pInode ); |
| 39277 | 39758 | assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK ); |
| 39278 | 39759 | assert( n>=1 ); |
| | @@ -40365,24 +40846,27 @@ |
| 40365 | 40846 | ** "<path to db>-journalNN" |
| 40366 | 40847 | ** "<path to db>-walNN" |
| 40367 | 40848 | ** |
| 40368 | 40849 | ** where NN is a decimal number. The NN naming schemes are |
| 40369 | 40850 | ** used by the test_multiplex.c module. |
| 40851 | + ** |
| 40852 | + ** In normal operation, the journal file name will always contain |
| 40853 | + ** a '-' character. However in 8+3 filename mode, or if a corrupt |
| 40854 | + ** rollback journal specifies a super-journal with a goofy name, then |
| 40855 | + ** the '-' might be missing or the '-' might be the first character in |
| 40856 | + ** the filename. In that case, just return SQLITE_OK with *pMode==0. |
| 40370 | 40857 | */ |
| 40371 | 40858 | nDb = sqlite3Strlen30(zPath) - 1; |
| 40372 | | - while( zPath[nDb]!='-' ){ |
| 40373 | | - /* In normal operation, the journal file name will always contain |
| 40374 | | - ** a '-' character. However in 8+3 filename mode, or if a corrupt |
| 40375 | | - ** rollback journal specifies a super-journal with a goofy name, then |
| 40376 | | - ** the '-' might be missing. */ |
| 40377 | | - if( nDb==0 || zPath[nDb]=='.' ) return SQLITE_OK; |
| 40859 | + while( nDb>0 && zPath[nDb]!='.' ){ |
| 40860 | + if( zPath[nDb]=='-' ){ |
| 40861 | + memcpy(zDb, zPath, nDb); |
| 40862 | + zDb[nDb] = '\0'; |
| 40863 | + rc = getFileMode(zDb, pMode, pUid, pGid); |
| 40864 | + break; |
| 40865 | + } |
| 40378 | 40866 | nDb--; |
| 40379 | 40867 | } |
| 40380 | | - memcpy(zDb, zPath, nDb); |
| 40381 | | - zDb[nDb] = '\0'; |
| 40382 | | - |
| 40383 | | - rc = getFileMode(zDb, pMode, pUid, pGid); |
| 40384 | 40868 | }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){ |
| 40385 | 40869 | *pMode = 0600; |
| 40386 | 40870 | }else if( flags & SQLITE_OPEN_URI ){ |
| 40387 | 40871 | /* If this is a main database file and the file was opened using a URI |
| 40388 | 40872 | ** filename, check for the "modeof" parameter. If present, interpret |
| | @@ -46556,14 +47040,18 @@ |
| 46556 | 47040 | int flags /* What to do with the lock */ |
| 46557 | 47041 | ){ |
| 46558 | 47042 | winFile *pDbFd = (winFile*)fd; /* Connection holding shared memory */ |
| 46559 | 47043 | winShm *p = pDbFd->pShm; /* The shared memory being locked */ |
| 46560 | 47044 | winShm *pX; /* For looping over all siblings */ |
| 46561 | | - winShmNode *pShmNode = p->pShmNode; |
| 47045 | + winShmNode *pShmNode; |
| 46562 | 47046 | int rc = SQLITE_OK; /* Result code */ |
| 46563 | 47047 | u16 mask; /* Mask of locks to take or release */ |
| 46564 | 47048 | |
| 47049 | + if( p==0 ) return SQLITE_IOERR_SHMLOCK; |
| 47050 | + pShmNode = p->pShmNode; |
| 47051 | + if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK; |
| 47052 | + |
| 46565 | 47053 | assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK ); |
| 46566 | 47054 | assert( n>=1 ); |
| 46567 | 47055 | assert( flags==(SQLITE_SHM_LOCK | SQLITE_SHM_SHARED) |
| 46568 | 47056 | || flags==(SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE) |
| 46569 | 47057 | || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED) |
| | @@ -53458,10 +53946,11 @@ |
| 53458 | 53946 | u16 nExtra; /* Add this many bytes to each in-memory page */ |
| 53459 | 53947 | i16 nReserve; /* Number of unused bytes at end of each page */ |
| 53460 | 53948 | u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */ |
| 53461 | 53949 | u32 sectorSize; /* Assumed sector size during rollback */ |
| 53462 | 53950 | Pgno mxPgno; /* Maximum allowed size of the database */ |
| 53951 | + Pgno lckPgno; /* Page number for the locking page */ |
| 53463 | 53952 | i64 pageSize; /* Number of bytes in a page */ |
| 53464 | 53953 | i64 journalSizeLimit; /* Size limit for persistent journal files */ |
| 53465 | 53954 | char *zFilename; /* Name of the database file */ |
| 53466 | 53955 | char *zJournal; /* Name of the journal file */ |
| 53467 | 53956 | int (*xBusyHandler)(void*); /* Function to call when busy */ |
| | @@ -54444,11 +54933,11 @@ |
| 54444 | 54933 | ** pPager at the current location. The super-journal name must be the last |
| 54445 | 54934 | ** thing written to a journal file. If the pager is in full-sync mode, the |
| 54446 | 54935 | ** journal file descriptor is advanced to the next sector boundary before |
| 54447 | 54936 | ** anything is written. The format is: |
| 54448 | 54937 | ** |
| 54449 | | -** + 4 bytes: PAGER_MJ_PGNO. |
| 54938 | +** + 4 bytes: PAGER_SJ_PGNO. |
| 54450 | 54939 | ** + N bytes: super-journal filename in utf-8. |
| 54451 | 54940 | ** + 4 bytes: N (length of super-journal name in bytes, no nul-terminator). |
| 54452 | 54941 | ** + 4 bytes: super-journal name checksum. |
| 54453 | 54942 | ** + 8 bytes: aJournalMagic[]. |
| 54454 | 54943 | ** |
| | @@ -54492,11 +54981,11 @@ |
| 54492 | 54981 | iHdrOff = pPager->journalOff; |
| 54493 | 54982 | |
| 54494 | 54983 | /* Write the super-journal data to the end of the journal file. If |
| 54495 | 54984 | ** an error occurs, return the error code to the caller. |
| 54496 | 54985 | */ |
| 54497 | | - if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_MJ_PGNO(pPager)))) |
| 54986 | + if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_SJ_PGNO(pPager)))) |
| 54498 | 54987 | || (0 != (rc = sqlite3OsWrite(pPager->jfd, zSuper, nSuper, iHdrOff+4))) |
| 54499 | 54988 | || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper, nSuper))) |
| 54500 | 54989 | || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper+4, cksum))) |
| 54501 | 54990 | || (0 != (rc = sqlite3OsWrite(pPager->jfd, aJournalMagic, 8, |
| 54502 | 54991 | iHdrOff+4+nSuper+8))) |
| | @@ -55002,11 +55491,11 @@ |
| 55002 | 55491 | ** to the database file, then the IO error code is returned. If data |
| 55003 | 55492 | ** is successfully read from the (sub-)journal file but appears to be |
| 55004 | 55493 | ** corrupted, SQLITE_DONE is returned. Data is considered corrupted in |
| 55005 | 55494 | ** two circumstances: |
| 55006 | 55495 | ** |
| 55007 | | -** * If the record page-number is illegal (0 or PAGER_MJ_PGNO), or |
| 55496 | +** * If the record page-number is illegal (0 or PAGER_SJ_PGNO), or |
| 55008 | 55497 | ** * If the record is being rolled back from the main journal file |
| 55009 | 55498 | ** and the checksum field does not match the record content. |
| 55010 | 55499 | ** |
| 55011 | 55500 | ** Neither of these two scenarios are possible during a savepoint rollback. |
| 55012 | 55501 | ** |
| | @@ -55062,11 +55551,11 @@ |
| 55062 | 55551 | /* Sanity checking on the page. This is more important that I originally |
| 55063 | 55552 | ** thought. If a power failure occurs while the journal is being written, |
| 55064 | 55553 | ** it could cause invalid data to be written into the journal. We need to |
| 55065 | 55554 | ** detect this invalid data (with high probability) and ignore it. |
| 55066 | 55555 | */ |
| 55067 | | - if( pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){ |
| 55556 | + if( pgno==0 || pgno==PAGER_SJ_PGNO(pPager) ){ |
| 55068 | 55557 | assert( !isSavepnt ); |
| 55069 | 55558 | return SQLITE_DONE; |
| 55070 | 55559 | } |
| 55071 | 55560 | if( pgno>(Pgno)pPager->dbSize || sqlite3BitvecTest(pDone, pgno) ){ |
| 55072 | 55561 | return SQLITE_OK; |
| | @@ -55621,10 +56110,13 @@ |
| 55621 | 56110 | rc = pager_truncate(pPager, mxPg); |
| 55622 | 56111 | if( rc!=SQLITE_OK ){ |
| 55623 | 56112 | goto end_playback; |
| 55624 | 56113 | } |
| 55625 | 56114 | pPager->dbSize = mxPg; |
| 56115 | + if( pPager->mxPgno<mxPg ){ |
| 56116 | + pPager->mxPgno = mxPg; |
| 56117 | + } |
| 55626 | 56118 | } |
| 55627 | 56119 | |
| 55628 | 56120 | /* Copy original pages out of the journal and back into the |
| 55629 | 56121 | ** database file and/or page cache. |
| 55630 | 56122 | */ |
| | @@ -56517,10 +57009,11 @@ |
| 56517 | 57009 | if( rc==SQLITE_OK ){ |
| 56518 | 57010 | sqlite3PageFree(pPager->pTmpSpace); |
| 56519 | 57011 | pPager->pTmpSpace = pNew; |
| 56520 | 57012 | pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize); |
| 56521 | 57013 | pPager->pageSize = pageSize; |
| 57014 | + pPager->lckPgno = (Pgno)(PENDING_BYTE/pageSize) + 1; |
| 56522 | 57015 | }else{ |
| 56523 | 57016 | sqlite3PageFree(pNew); |
| 56524 | 57017 | } |
| 56525 | 57018 | } |
| 56526 | 57019 | |
| | @@ -56723,11 +57216,10 @@ |
| 56723 | 57216 | ** rolled back or committed. It is not safe to call this function and |
| 56724 | 57217 | ** then continue writing to the database. |
| 56725 | 57218 | */ |
| 56726 | 57219 | SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){ |
| 56727 | 57220 | assert( pPager->dbSize>=nPage || CORRUPT_DB ); |
| 56728 | | - testcase( pPager->dbSize<nPage ); |
| 56729 | 57221 | assert( pPager->eState>=PAGER_WRITER_CACHEMOD ); |
| 56730 | 57222 | pPager->dbSize = nPage; |
| 56731 | 57223 | |
| 56732 | 57224 | /* At one point the code here called assertTruncateConstraint() to |
| 56733 | 57225 | ** ensure that all pages being truncated away by this operation are, |
| | @@ -58287,11 +58779,11 @@ |
| 58287 | 58779 | |
| 58288 | 58780 | noContent = (flags & PAGER_GET_NOCONTENT)!=0; |
| 58289 | 58781 | if( pPg->pPager && !noContent ){ |
| 58290 | 58782 | /* In this case the pcache already contains an initialized copy of |
| 58291 | 58783 | ** the page. Return without further ado. */ |
| 58292 | | - assert( pgno!=PAGER_MJ_PGNO(pPager) ); |
| 58784 | + assert( pgno!=PAGER_SJ_PGNO(pPager) ); |
| 58293 | 58785 | pPager->aStat[PAGER_STAT_HIT]++; |
| 58294 | 58786 | return SQLITE_OK; |
| 58295 | 58787 | |
| 58296 | 58788 | }else{ |
| 58297 | 58789 | /* The pager cache has created a new page. Its content needs to |
| | @@ -58298,11 +58790,11 @@ |
| 58298 | 58790 | ** be initialized. But first some error checks: |
| 58299 | 58791 | ** |
| 58300 | 58792 | ** (*) obsolete. Was: maximum page number is 2^31 |
| 58301 | 58793 | ** (2) Never try to fetch the locking page |
| 58302 | 58794 | */ |
| 58303 | | - if( pgno==PAGER_MJ_PGNO(pPager) ){ |
| 58795 | + if( pgno==PAGER_SJ_PGNO(pPager) ){ |
| 58304 | 58796 | rc = SQLITE_CORRUPT_BKPT; |
| 58305 | 58797 | goto pager_acquire_err; |
| 58306 | 58798 | } |
| 58307 | 58799 | |
| 58308 | 58800 | pPg->pPager = pPager; |
| | @@ -58697,11 +59189,11 @@ |
| 58697 | 59189 | i64 iOff = pPager->journalOff; |
| 58698 | 59190 | |
| 58699 | 59191 | /* We should never write to the journal file the page that |
| 58700 | 59192 | ** contains the database locks. The following assert verifies |
| 58701 | 59193 | ** that we do not. */ |
| 58702 | | - assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) ); |
| 59194 | + assert( pPg->pgno!=PAGER_SJ_PGNO(pPager) ); |
| 58703 | 59195 | |
| 58704 | 59196 | assert( pPager->journalHdr<=pPager->journalOff ); |
| 58705 | 59197 | pData2 = pPg->pData; |
| 58706 | 59198 | cksum = pager_cksum(pPager, (u8*)pData2); |
| 58707 | 59199 | |
| | @@ -58876,11 +59368,11 @@ |
| 58876 | 59368 | |
| 58877 | 59369 | for(ii=0; ii<nPage && rc==SQLITE_OK; ii++){ |
| 58878 | 59370 | Pgno pg = pg1+ii; |
| 58879 | 59371 | PgHdr *pPage; |
| 58880 | 59372 | if( pg==pPg->pgno || !sqlite3BitvecTest(pPager->pInJournal, pg) ){ |
| 58881 | | - if( pg!=PAGER_MJ_PGNO(pPager) ){ |
| 59373 | + if( pg!=PAGER_SJ_PGNO(pPager) ){ |
| 58882 | 59374 | rc = sqlite3PagerGet(pPager, pg, &pPage, 0); |
| 58883 | 59375 | if( rc==SQLITE_OK ){ |
| 58884 | 59376 | rc = pager_write(pPage); |
| 58885 | 59377 | if( pPage->flags&PGHDR_NEED_SYNC ){ |
| 58886 | 59378 | needSync = 1; |
| | @@ -59354,11 +59846,11 @@ |
| 59354 | 59846 | ** image was extended as part of the current transaction and then the |
| 59355 | 59847 | ** last page in the db image moved to the free-list. In this case the |
| 59356 | 59848 | ** last page is never written out to disk, leaving the database file |
| 59357 | 59849 | ** undersized. Fix this now if it is the case. */ |
| 59358 | 59850 | if( pPager->dbSize>pPager->dbFileSize ){ |
| 59359 | | - Pgno nNew = pPager->dbSize - (pPager->dbSize==PAGER_MJ_PGNO(pPager)); |
| 59851 | + Pgno nNew = pPager->dbSize - (pPager->dbSize==PAGER_SJ_PGNO(pPager)); |
| 59360 | 59852 | assert( pPager->eState==PAGER_WRITER_DBMOD ); |
| 59361 | 59853 | rc = pager_truncate(pPager, nNew); |
| 59362 | 59854 | if( rc!=SQLITE_OK ) goto commit_phase_one_exit; |
| 59363 | 59855 | } |
| 59364 | 59856 | |
| | @@ -60203,10 +60695,22 @@ |
| 60203 | 60695 | int eMode, /* Type of checkpoint */ |
| 60204 | 60696 | int *pnLog, /* OUT: Final number of frames in log */ |
| 60205 | 60697 | int *pnCkpt /* OUT: Final number of checkpointed frames */ |
| 60206 | 60698 | ){ |
| 60207 | 60699 | int rc = SQLITE_OK; |
| 60700 | + if( pPager->pWal==0 && pPager->journalMode==PAGER_JOURNALMODE_WAL ){ |
| 60701 | + /* This only happens when a database file is zero bytes in size opened and |
| 60702 | + ** then "PRAGMA journal_mode=WAL" is run and then sqlite3_wal_checkpoint() |
| 60703 | + ** is invoked without any intervening transactions. We need to start |
| 60704 | + ** a transaction to initialize pWal. The PRAGMA table_list statement is |
| 60705 | + ** used for this since it starts transactions on every database file, |
| 60706 | + ** including all ATTACHed databases. This seems expensive for a single |
| 60707 | + ** sqlite3_wal_checkpoint() call, but it happens very rarely. |
| 60708 | + ** https://sqlite.org/forum/forumpost/fd0f19d229156939 |
| 60709 | + */ |
| 60710 | + sqlite3_exec(db, "PRAGMA table_list",0,0,0); |
| 60711 | + } |
| 60208 | 60712 | if( pPager->pWal ){ |
| 60209 | 60713 | rc = sqlite3WalCheckpoint(pPager->pWal, db, eMode, |
| 60210 | 60714 | (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler), |
| 60211 | 60715 | pPager->pBusyHandlerArg, |
| 60212 | 60716 | pPager->walSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace, |
| | @@ -63102,11 +63606,13 @@ |
| 63102 | 63606 | rc = WAL_RETRY; |
| 63103 | 63607 | goto begin_unreliable_shm_out; |
| 63104 | 63608 | } |
| 63105 | 63609 | |
| 63106 | 63610 | /* Allocate a buffer to read frames into */ |
| 63107 | | - szFrame = pWal->hdr.szPage + WAL_FRAME_HDRSIZE; |
| 63611 | + assert( (pWal->szPage & (pWal->szPage-1))==0 ); |
| 63612 | + assert( pWal->szPage>=512 && pWal->szPage<=65536 ); |
| 63613 | + szFrame = pWal->szPage + WAL_FRAME_HDRSIZE; |
| 63108 | 63614 | aFrame = (u8 *)sqlite3_malloc64(szFrame); |
| 63109 | 63615 | if( aFrame==0 ){ |
| 63110 | 63616 | rc = SQLITE_NOMEM_BKPT; |
| 63111 | 63617 | goto begin_unreliable_shm_out; |
| 63112 | 63618 | } |
| | @@ -63116,11 +63622,11 @@ |
| 63116 | 63622 | ** wal file since the heap-memory wal-index was created. If so, the |
| 63117 | 63623 | ** heap-memory wal-index is discarded and WAL_RETRY returned to |
| 63118 | 63624 | ** the caller. */ |
| 63119 | 63625 | aSaveCksum[0] = pWal->hdr.aFrameCksum[0]; |
| 63120 | 63626 | aSaveCksum[1] = pWal->hdr.aFrameCksum[1]; |
| 63121 | | - for(iOffset=walFrameOffset(pWal->hdr.mxFrame+1, pWal->hdr.szPage); |
| 63627 | + for(iOffset=walFrameOffset(pWal->hdr.mxFrame+1, pWal->szPage); |
| 63122 | 63628 | iOffset+szFrame<=szWal; |
| 63123 | 63629 | iOffset+=szFrame |
| 63124 | 63630 | ){ |
| 63125 | 63631 | u32 pgno; /* Database page number for frame */ |
| 63126 | 63632 | u32 nTruncate; /* dbsize field from frame header */ |
| | @@ -64967,11 +65473,13 @@ |
| 64967 | 65473 | u16 aiOvfl[4]; /* Insert the i-th overflow cell before the aiOvfl-th |
| 64968 | 65474 | ** non-overflow cell */ |
| 64969 | 65475 | u8 *apOvfl[4]; /* Pointers to the body of overflow cells */ |
| 64970 | 65476 | BtShared *pBt; /* Pointer to BtShared that this page is part of */ |
| 64971 | 65477 | u8 *aData; /* Pointer to disk image of the page data */ |
| 64972 | | - u8 *aDataEnd; /* One byte past the end of usable data */ |
| 65478 | + u8 *aDataEnd; /* One byte past the end of the entire page - not just |
| 65479 | + ** the usable space, the entire page. Used to prevent |
| 65480 | + ** corruption-induced buffer overflow. */ |
| 64973 | 65481 | u8 *aCellIdx; /* The cell index area */ |
| 64974 | 65482 | u8 *aDataOfst; /* Same as aData for leaves. aData+4 for interior */ |
| 64975 | 65483 | DbPage *pDbPage; /* Pager page handle */ |
| 64976 | 65484 | u16 (*xCellSize)(MemPage*,u8*); /* cellSizePtr method */ |
| 64977 | 65485 | void (*xParseCell)(MemPage*,u8*,CellInfo*); /* btreeParseCell method */ |
| | @@ -65272,11 +65780,11 @@ |
| 65272 | 65780 | #define CURSOR_FAULT 4 |
| 65273 | 65781 | |
| 65274 | 65782 | /* |
| 65275 | 65783 | ** The database page the PENDING_BYTE occupies. This page is never used. |
| 65276 | 65784 | */ |
| 65277 | | -# define PENDING_BYTE_PAGE(pBt) PAGER_MJ_PGNO(pBt) |
| 65785 | +#define PENDING_BYTE_PAGE(pBt) ((Pgno)((PENDING_BYTE/((pBt)->pageSize))+1)) |
| 65278 | 65786 | |
| 65279 | 65787 | /* |
| 65280 | 65788 | ** These macros define the location of the pointer-map entry for a |
| 65281 | 65789 | ** database page. The first argument to each is the number of usable |
| 65282 | 65790 | ** bytes on each page of the database (often 1024). The second is the |
| | @@ -65913,11 +66421,11 @@ |
| 65913 | 66421 | if( isIndex ){ |
| 65914 | 66422 | HashElem *p; |
| 65915 | 66423 | int bSeen = 0; |
| 65916 | 66424 | for(p=sqliteHashFirst(&pSchema->idxHash); p; p=sqliteHashNext(p)){ |
| 65917 | 66425 | Index *pIdx = (Index *)sqliteHashData(p); |
| 65918 | | - if( pIdx->tnum==(int)iRoot ){ |
| 66426 | + if( pIdx->tnum==iRoot ){ |
| 65919 | 66427 | if( bSeen ){ |
| 65920 | 66428 | /* Two or more indexes share the same root page. There must |
| 65921 | 66429 | ** be imposter tables. So just return true. The assert is not |
| 65922 | 66430 | ** useful in that case. */ |
| 65923 | 66431 | return 1; |
| | @@ -66506,11 +67014,11 @@ |
| 66506 | 67014 | } |
| 66507 | 67015 | |
| 66508 | 67016 | /* |
| 66509 | 67017 | ** In this version of BtreeMoveto, pKey is a packed index record |
| 66510 | 67018 | ** such as is generated by the OP_MakeRecord opcode. Unpack the |
| 66511 | | -** record and then call BtreeMovetoUnpacked() to do the work. |
| 67019 | +** record and then call sqlite3BtreeIndexMoveto() to do the work. |
| 66512 | 67020 | */ |
| 66513 | 67021 | static int btreeMoveto( |
| 66514 | 67022 | BtCursor *pCur, /* Cursor open on the btree to be searched */ |
| 66515 | 67023 | const void *pKey, /* Packed key if the btree is an index */ |
| 66516 | 67024 | i64 nKey, /* Integer key for tables. Size of pKey for indices */ |
| | @@ -67026,10 +67534,11 @@ |
| 67026 | 67534 | ** data area of the btree-page. The return number includes the cell |
| 67027 | 67535 | ** data header and the local payload, but not any overflow page or |
| 67028 | 67536 | ** the space used by the cell pointer. |
| 67029 | 67537 | ** |
| 67030 | 67538 | ** cellSizePtrNoPayload() => table internal nodes |
| 67539 | +** cellSizePtrTableLeaf() => table leaf nodes |
| 67031 | 67540 | ** cellSizePtr() => all index nodes & table leaf nodes |
| 67032 | 67541 | */ |
| 67033 | 67542 | static u16 cellSizePtr(MemPage *pPage, u8 *pCell){ |
| 67034 | 67543 | u8 *pIter = pCell + pPage->childPtrSize; /* For looping over bytes of pCell */ |
| 67035 | 67544 | u8 *pEnd; /* End mark for a varint */ |
| | @@ -67051,17 +67560,10 @@ |
| 67051 | 67560 | do{ |
| 67052 | 67561 | nSize = (nSize<<7) | (*++pIter & 0x7f); |
| 67053 | 67562 | }while( *(pIter)>=0x80 && pIter<pEnd ); |
| 67054 | 67563 | } |
| 67055 | 67564 | pIter++; |
| 67056 | | - if( pPage->intKey ){ |
| 67057 | | - /* pIter now points at the 64-bit integer key value, a variable length |
| 67058 | | - ** integer. The following block moves pIter to point at the first byte |
| 67059 | | - ** past the end of the key value. */ |
| 67060 | | - pEnd = &pIter[9]; |
| 67061 | | - while( (*pIter++)&0x80 && pIter<pEnd ); |
| 67062 | | - } |
| 67063 | 67565 | testcase( nSize==pPage->maxLocal ); |
| 67064 | 67566 | testcase( nSize==(u32)pPage->maxLocal+1 ); |
| 67065 | 67567 | if( nSize<=pPage->maxLocal ){ |
| 67066 | 67568 | nSize += (u32)(pIter - pCell); |
| 67067 | 67569 | if( nSize<4 ) nSize = 4; |
| | @@ -67097,10 +67599,62 @@ |
| 67097 | 67599 | pEnd = pIter + 9; |
| 67098 | 67600 | while( (*pIter++)&0x80 && pIter<pEnd ); |
| 67099 | 67601 | assert( debuginfo.nSize==(u16)(pIter - pCell) || CORRUPT_DB ); |
| 67100 | 67602 | return (u16)(pIter - pCell); |
| 67101 | 67603 | } |
| 67604 | +static u16 cellSizePtrTableLeaf(MemPage *pPage, u8 *pCell){ |
| 67605 | + u8 *pIter = pCell; /* For looping over bytes of pCell */ |
| 67606 | + u8 *pEnd; /* End mark for a varint */ |
| 67607 | + u32 nSize; /* Size value to return */ |
| 67608 | + |
| 67609 | +#ifdef SQLITE_DEBUG |
| 67610 | + /* The value returned by this function should always be the same as |
| 67611 | + ** the (CellInfo.nSize) value found by doing a full parse of the |
| 67612 | + ** cell. If SQLITE_DEBUG is defined, an assert() at the bottom of |
| 67613 | + ** this function verifies that this invariant is not violated. */ |
| 67614 | + CellInfo debuginfo; |
| 67615 | + pPage->xParseCell(pPage, pCell, &debuginfo); |
| 67616 | +#endif |
| 67617 | + |
| 67618 | + nSize = *pIter; |
| 67619 | + if( nSize>=0x80 ){ |
| 67620 | + pEnd = &pIter[8]; |
| 67621 | + nSize &= 0x7f; |
| 67622 | + do{ |
| 67623 | + nSize = (nSize<<7) | (*++pIter & 0x7f); |
| 67624 | + }while( *(pIter)>=0x80 && pIter<pEnd ); |
| 67625 | + } |
| 67626 | + pIter++; |
| 67627 | + /* pIter now points at the 64-bit integer key value, a variable length |
| 67628 | + ** integer. The following block moves pIter to point at the first byte |
| 67629 | + ** past the end of the key value. */ |
| 67630 | + if( (*pIter++)&0x80 |
| 67631 | + && (*pIter++)&0x80 |
| 67632 | + && (*pIter++)&0x80 |
| 67633 | + && (*pIter++)&0x80 |
| 67634 | + && (*pIter++)&0x80 |
| 67635 | + && (*pIter++)&0x80 |
| 67636 | + && (*pIter++)&0x80 |
| 67637 | + && (*pIter++)&0x80 ){ pIter++; } |
| 67638 | + testcase( nSize==pPage->maxLocal ); |
| 67639 | + testcase( nSize==(u32)pPage->maxLocal+1 ); |
| 67640 | + if( nSize<=pPage->maxLocal ){ |
| 67641 | + nSize += (u32)(pIter - pCell); |
| 67642 | + if( nSize<4 ) nSize = 4; |
| 67643 | + }else{ |
| 67644 | + int minLocal = pPage->minLocal; |
| 67645 | + nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4); |
| 67646 | + testcase( nSize==pPage->maxLocal ); |
| 67647 | + testcase( nSize==(u32)pPage->maxLocal+1 ); |
| 67648 | + if( nSize>pPage->maxLocal ){ |
| 67649 | + nSize = minLocal; |
| 67650 | + } |
| 67651 | + nSize += 4 + (u16)(pIter - pCell); |
| 67652 | + } |
| 67653 | + assert( nSize==debuginfo.nSize || CORRUPT_DB ); |
| 67654 | + return (u16)nSize; |
| 67655 | +} |
| 67102 | 67656 | |
| 67103 | 67657 | |
| 67104 | 67658 | #ifdef SQLITE_DEBUG |
| 67105 | 67659 | /* This variation on cellSizePtr() is used inside of assert() statements |
| 67106 | 67660 | ** only. */ |
| | @@ -67110,11 +67664,11 @@ |
| 67110 | 67664 | #endif |
| 67111 | 67665 | |
| 67112 | 67666 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 67113 | 67667 | /* |
| 67114 | 67668 | ** The cell pCell is currently part of page pSrc but will ultimately be part |
| 67115 | | -** of pPage. (pSrc and pPager are often the same.) If pCell contains a |
| 67669 | +** of pPage. (pSrc and pPage are often the same.) If pCell contains a |
| 67116 | 67670 | ** pointer to an overflow page, insert an entry into the pointer-map for |
| 67117 | 67671 | ** the overflow page that will be valid after pCell has been moved to pPage. |
| 67118 | 67672 | */ |
| 67119 | 67673 | static void ptrmapPutOvflPtr(MemPage *pPage, MemPage *pSrc, u8 *pCell,int *pRC){ |
| 67120 | 67674 | CellInfo info; |
| | @@ -67285,21 +67839,23 @@ |
| 67285 | 67839 | */ |
| 67286 | 67840 | static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){ |
| 67287 | 67841 | const int hdr = pPg->hdrOffset; /* Offset to page header */ |
| 67288 | 67842 | u8 * const aData = pPg->aData; /* Page data */ |
| 67289 | 67843 | int iAddr = hdr + 1; /* Address of ptr to pc */ |
| 67290 | | - int pc = get2byte(&aData[iAddr]); /* Address of a free slot */ |
| 67844 | + u8 *pTmp = &aData[iAddr]; /* Temporary ptr into aData[] */ |
| 67845 | + int pc = get2byte(pTmp); /* Address of a free slot */ |
| 67291 | 67846 | int x; /* Excess size of the slot */ |
| 67292 | 67847 | int maxPC = pPg->pBt->usableSize - nByte; /* Max address for a usable slot */ |
| 67293 | 67848 | int size; /* Size of the free slot */ |
| 67294 | 67849 | |
| 67295 | 67850 | assert( pc>0 ); |
| 67296 | 67851 | while( pc<=maxPC ){ |
| 67297 | 67852 | /* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each |
| 67298 | 67853 | ** freeblock form a big-endian integer which is the size of the freeblock |
| 67299 | 67854 | ** in bytes, including the 4-byte header. */ |
| 67300 | | - size = get2byte(&aData[pc+2]); |
| 67855 | + pTmp = &aData[pc+2]; |
| 67856 | + size = get2byte(pTmp); |
| 67301 | 67857 | if( (x = size - nByte)>=0 ){ |
| 67302 | 67858 | testcase( x==4 ); |
| 67303 | 67859 | testcase( x==3 ); |
| 67304 | 67860 | if( x<4 ){ |
| 67305 | 67861 | /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total |
| | @@ -67320,11 +67876,12 @@ |
| 67320 | 67876 | put2byte(&aData[pc+2], x); |
| 67321 | 67877 | } |
| 67322 | 67878 | return &aData[pc + x]; |
| 67323 | 67879 | } |
| 67324 | 67880 | iAddr = pc; |
| 67325 | | - pc = get2byte(&aData[pc]); |
| 67881 | + pTmp = &aData[pc]; |
| 67882 | + pc = get2byte(pTmp); |
| 67326 | 67883 | if( pc<=iAddr+size ){ |
| 67327 | 67884 | if( pc ){ |
| 67328 | 67885 | /* The next slot in the chain is not past the end of the current slot */ |
| 67329 | 67886 | *pRc = SQLITE_CORRUPT_PAGE(pPg); |
| 67330 | 67887 | } |
| | @@ -67354,10 +67911,11 @@ |
| 67354 | 67911 | static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ |
| 67355 | 67912 | const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */ |
| 67356 | 67913 | u8 * const data = pPage->aData; /* Local cache of pPage->aData */ |
| 67357 | 67914 | int top; /* First byte of cell content area */ |
| 67358 | 67915 | int rc = SQLITE_OK; /* Integer return code */ |
| 67916 | + u8 *pTmp; /* Temp ptr into data[] */ |
| 67359 | 67917 | int gap; /* First byte of gap between cell pointers and cell content */ |
| 67360 | 67918 | |
| 67361 | 67919 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 67362 | 67920 | assert( pPage->pBt ); |
| 67363 | 67921 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| | @@ -67372,11 +67930,12 @@ |
| 67372 | 67930 | /* EVIDENCE-OF: R-29356-02391 If the database uses a 65536-byte page size |
| 67373 | 67931 | ** and the reserved space is zero (the usual value for reserved space) |
| 67374 | 67932 | ** then the cell content offset of an empty page wants to be 65536. |
| 67375 | 67933 | ** However, that integer is too large to be stored in a 2-byte unsigned |
| 67376 | 67934 | ** integer, so a value of 0 is used in its place. */ |
| 67377 | | - top = get2byte(&data[hdr+5]); |
| 67935 | + pTmp = &data[hdr+5]; |
| 67936 | + top = get2byte(pTmp); |
| 67378 | 67937 | assert( top<=(int)pPage->pBt->usableSize ); /* by btreeComputeFreeSpace() */ |
| 67379 | 67938 | if( gap>top ){ |
| 67380 | 67939 | if( top==0 && pPage->pBt->usableSize==65536 ){ |
| 67381 | 67940 | top = 65536; |
| 67382 | 67941 | }else{ |
| | @@ -67454,10 +68013,11 @@ |
| 67454 | 68013 | u8 nFrag = 0; /* Reduction in fragmentation */ |
| 67455 | 68014 | u16 iOrigSize = iSize; /* Original value of iSize */ |
| 67456 | 68015 | u16 x; /* Offset to cell content area */ |
| 67457 | 68016 | u32 iEnd = iStart + iSize; /* First byte past the iStart buffer */ |
| 67458 | 68017 | unsigned char *data = pPage->aData; /* Page content */ |
| 68018 | + u8 *pTmp; /* Temporary ptr into data[] */ |
| 67459 | 68019 | |
| 67460 | 68020 | assert( pPage->pBt!=0 ); |
| 67461 | 68021 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 67462 | 68022 | assert( CORRUPT_DB || iStart>=pPage->hdrOffset+6+pPage->childPtrSize ); |
| 67463 | 68023 | assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize ); |
| | @@ -67481,11 +68041,11 @@ |
| 67481 | 68041 | iPtr = iFreeBlk; |
| 67482 | 68042 | } |
| 67483 | 68043 | if( iFreeBlk>pPage->pBt->usableSize-4 ){ /* TH3: corrupt081.100 */ |
| 67484 | 68044 | return SQLITE_CORRUPT_PAGE(pPage); |
| 67485 | 68045 | } |
| 67486 | | - assert( iFreeBlk>iPtr || iFreeBlk==0 ); |
| 68046 | + assert( iFreeBlk>iPtr || iFreeBlk==0 || CORRUPT_DB ); |
| 67487 | 68047 | |
| 67488 | 68048 | /* At this point: |
| 67489 | 68049 | ** iFreeBlk: First freeblock after iStart, or zero if none |
| 67490 | 68050 | ** iPtr: The address of a pointer to iFreeBlk |
| 67491 | 68051 | ** |
| | @@ -67516,11 +68076,12 @@ |
| 67516 | 68076 | } |
| 67517 | 68077 | } |
| 67518 | 68078 | if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PAGE(pPage); |
| 67519 | 68079 | data[hdr+7] -= nFrag; |
| 67520 | 68080 | } |
| 67521 | | - x = get2byte(&data[hdr+5]); |
| 68081 | + pTmp = &data[hdr+5]; |
| 68082 | + x = get2byte(pTmp); |
| 67522 | 68083 | if( iStart<=x ){ |
| 67523 | 68084 | /* The new freeblock is at the beginning of the cell content area, |
| 67524 | 68085 | ** so just extend the cell content area rather than create another |
| 67525 | 68086 | ** freelist entry */ |
| 67526 | 68087 | if( iStart<x ) return SQLITE_CORRUPT_PAGE(pPage); |
| | @@ -67560,11 +68121,10 @@ |
| 67560 | 68121 | assert( pPage->hdrOffset==(pPage->pgno==1 ? 100 : 0) ); |
| 67561 | 68122 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 67562 | 68123 | pPage->leaf = (u8)(flagByte>>3); assert( PTF_LEAF == 1<<3 ); |
| 67563 | 68124 | flagByte &= ~PTF_LEAF; |
| 67564 | 68125 | pPage->childPtrSize = 4-4*pPage->leaf; |
| 67565 | | - pPage->xCellSize = cellSizePtr; |
| 67566 | 68126 | pBt = pPage->pBt; |
| 67567 | 68127 | if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){ |
| 67568 | 68128 | /* EVIDENCE-OF: R-07291-35328 A value of 5 (0x05) means the page is an |
| 67569 | 68129 | ** interior table b-tree page. */ |
| 67570 | 68130 | assert( (PTF_LEAFDATA|PTF_INTKEY)==5 ); |
| | @@ -67572,10 +68132,11 @@ |
| 67572 | 68132 | ** leaf table b-tree page. */ |
| 67573 | 68133 | assert( (PTF_LEAFDATA|PTF_INTKEY|PTF_LEAF)==13 ); |
| 67574 | 68134 | pPage->intKey = 1; |
| 67575 | 68135 | if( pPage->leaf ){ |
| 67576 | 68136 | pPage->intKeyLeaf = 1; |
| 68137 | + pPage->xCellSize = cellSizePtrTableLeaf; |
| 67577 | 68138 | pPage->xParseCell = btreeParseCellPtr; |
| 67578 | 68139 | }else{ |
| 67579 | 68140 | pPage->intKeyLeaf = 0; |
| 67580 | 68141 | pPage->xCellSize = cellSizePtrNoPayload; |
| 67581 | 68142 | pPage->xParseCell = btreeParseCellPtrNoPayload; |
| | @@ -67589,16 +68150,21 @@ |
| 67589 | 68150 | /* EVIDENCE-OF: R-59615-42828 A value of 10 (0x0a) means the page is a |
| 67590 | 68151 | ** leaf index b-tree page. */ |
| 67591 | 68152 | assert( (PTF_ZERODATA|PTF_LEAF)==10 ); |
| 67592 | 68153 | pPage->intKey = 0; |
| 67593 | 68154 | pPage->intKeyLeaf = 0; |
| 68155 | + pPage->xCellSize = cellSizePtr; |
| 67594 | 68156 | pPage->xParseCell = btreeParseCellPtrIndex; |
| 67595 | 68157 | pPage->maxLocal = pBt->maxLocal; |
| 67596 | 68158 | pPage->minLocal = pBt->minLocal; |
| 67597 | 68159 | }else{ |
| 67598 | 68160 | /* EVIDENCE-OF: R-47608-56469 Any other value for the b-tree page type is |
| 67599 | 68161 | ** an error. */ |
| 68162 | + pPage->intKey = 0; |
| 68163 | + pPage->intKeyLeaf = 0; |
| 68164 | + pPage->xCellSize = cellSizePtr; |
| 68165 | + pPage->xParseCell = btreeParseCellPtrIndex; |
| 67600 | 68166 | return SQLITE_CORRUPT_PAGE(pPage); |
| 67601 | 68167 | } |
| 67602 | 68168 | pPage->max1bytePayload = pBt->max1bytePayload; |
| 67603 | 68169 | return SQLITE_OK; |
| 67604 | 68170 | } |
| | @@ -67752,11 +68318,11 @@ |
| 67752 | 68318 | assert( pBt->pageSize>=512 && pBt->pageSize<=65536 ); |
| 67753 | 68319 | pPage->maskPage = (u16)(pBt->pageSize - 1); |
| 67754 | 68320 | pPage->nOverflow = 0; |
| 67755 | 68321 | pPage->cellOffset = pPage->hdrOffset + 8 + pPage->childPtrSize; |
| 67756 | 68322 | pPage->aCellIdx = data + pPage->childPtrSize + 8; |
| 67757 | | - pPage->aDataEnd = pPage->aData + pBt->usableSize; |
| 68323 | + pPage->aDataEnd = pPage->aData + pBt->pageSize; |
| 67758 | 68324 | pPage->aDataOfst = pPage->aData + pPage->childPtrSize; |
| 67759 | 68325 | /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the |
| 67760 | 68326 | ** number of cells on the page. */ |
| 67761 | 68327 | pPage->nCell = get2byte(&data[3]); |
| 67762 | 68328 | if( pPage->nCell>MX_CELL(pBt) ){ |
| | @@ -67787,11 +68353,11 @@ |
| 67787 | 68353 | unsigned char *data = pPage->aData; |
| 67788 | 68354 | BtShared *pBt = pPage->pBt; |
| 67789 | 68355 | u8 hdr = pPage->hdrOffset; |
| 67790 | 68356 | u16 first; |
| 67791 | 68357 | |
| 67792 | | - assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno ); |
| 68358 | + assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno || CORRUPT_DB ); |
| 67793 | 68359 | assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage ); |
| 67794 | 68360 | assert( sqlite3PagerGetData(pPage->pDbPage) == data ); |
| 67795 | 68361 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 67796 | 68362 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 67797 | 68363 | if( pBt->btsFlags & BTS_FAST_SECURE ){ |
| | @@ -67803,11 +68369,11 @@ |
| 67803 | 68369 | data[hdr+7] = 0; |
| 67804 | 68370 | put2byte(&data[hdr+5], pBt->usableSize); |
| 67805 | 68371 | pPage->nFree = (u16)(pBt->usableSize - first); |
| 67806 | 68372 | decodeFlags(pPage, flags); |
| 67807 | 68373 | pPage->cellOffset = first; |
| 67808 | | - pPage->aDataEnd = &data[pBt->usableSize]; |
| 68374 | + pPage->aDataEnd = &data[pBt->pageSize]; |
| 67809 | 68375 | pPage->aCellIdx = &data[first]; |
| 67810 | 68376 | pPage->aDataOfst = &data[pPage->childPtrSize]; |
| 67811 | 68377 | pPage->nOverflow = 0; |
| 67812 | 68378 | assert( pBt->pageSize>=512 && pBt->pageSize<=65536 ); |
| 67813 | 68379 | pPage->maskPage = (u16)(pBt->pageSize - 1); |
| | @@ -67929,11 +68495,11 @@ |
| 67929 | 68495 | rc = btreeInitPage(*ppPage); |
| 67930 | 68496 | if( rc!=SQLITE_OK ){ |
| 67931 | 68497 | goto getAndInitPage_error2; |
| 67932 | 68498 | } |
| 67933 | 68499 | } |
| 67934 | | - assert( (*ppPage)->pgno==pgno ); |
| 68500 | + assert( (*ppPage)->pgno==pgno || CORRUPT_DB ); |
| 67935 | 68501 | assert( (*ppPage)->aData==sqlite3PagerGetData(pDbPage) ); |
| 67936 | 68502 | |
| 67937 | 68503 | /* If obtaining a child page for a cursor, we must verify that the page is |
| 67938 | 68504 | ** compatible with the root page. */ |
| 67939 | 68505 | if( pCur && ((*ppPage)->nCell<1 || (*ppPage)->intKey!=pCur->curIntKey) ){ |
| | @@ -67948,11 +68514,13 @@ |
| 67948 | 68514 | if( pCur ){ |
| 67949 | 68515 | pCur->iPage--; |
| 67950 | 68516 | pCur->pPage = pCur->apPage[pCur->iPage]; |
| 67951 | 68517 | } |
| 67952 | 68518 | testcase( pgno==0 ); |
| 67953 | | - assert( pgno!=0 || rc==SQLITE_CORRUPT ); |
| 68519 | + assert( pgno!=0 || rc==SQLITE_CORRUPT |
| 68520 | + || rc==SQLITE_IOERR_NOMEM |
| 68521 | + || rc==SQLITE_NOMEM ); |
| 67954 | 68522 | return rc; |
| 67955 | 68523 | } |
| 67956 | 68524 | |
| 67957 | 68525 | /* |
| 67958 | 68526 | ** Release a MemPage. This should be called once for each prior |
| | @@ -68934,13 +69502,17 @@ |
| 68934 | 69502 | freeTempSpace(pBt); |
| 68935 | 69503 | rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, |
| 68936 | 69504 | pageSize-usableSize); |
| 68937 | 69505 | return rc; |
| 68938 | 69506 | } |
| 68939 | | - if( sqlite3WritableSchema(pBt->db)==0 && nPage>nPageFile ){ |
| 68940 | | - rc = SQLITE_CORRUPT_BKPT; |
| 68941 | | - goto page1_init_failed; |
| 69507 | + if( nPage>nPageFile ){ |
| 69508 | + if( sqlite3WritableSchema(pBt->db)==0 ){ |
| 69509 | + rc = SQLITE_CORRUPT_BKPT; |
| 69510 | + goto page1_init_failed; |
| 69511 | + }else{ |
| 69512 | + nPage = nPageFile; |
| 69513 | + } |
| 68942 | 69514 | } |
| 68943 | 69515 | /* EVIDENCE-OF: R-28312-64704 However, the usable size is not allowed to |
| 68944 | 69516 | ** be less than 480. In other words, if the page size is 512, then the |
| 68945 | 69517 | ** reserved space size cannot exceed 32. */ |
| 68946 | 69518 | if( usableSize<480 ){ |
| | @@ -71012,11 +71584,11 @@ |
| 71012 | 71584 | } |
| 71013 | 71585 | pCur->iPage = 0; |
| 71014 | 71586 | pCur->curIntKey = pCur->pPage->intKey; |
| 71015 | 71587 | } |
| 71016 | 71588 | pRoot = pCur->pPage; |
| 71017 | | - assert( pRoot->pgno==pCur->pgnoRoot ); |
| 71589 | + assert( pRoot->pgno==pCur->pgnoRoot || CORRUPT_DB ); |
| 71018 | 71590 | |
| 71019 | 71591 | /* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor |
| 71020 | 71592 | ** expected to open it on an index b-tree. Otherwise, if pKeyInfo is |
| 71021 | 71593 | ** NULL, the caller expects a table b-tree. If this is not the case, |
| 71022 | 71594 | ** return an SQLITE_CORRUPT error. |
| | @@ -71332,10 +71904,73 @@ |
| 71332 | 71904 | moveto_table_finish: |
| 71333 | 71905 | pCur->info.nSize = 0; |
| 71334 | 71906 | assert( (pCur->curFlags & BTCF_ValidOvfl)==0 ); |
| 71335 | 71907 | return rc; |
| 71336 | 71908 | } |
| 71909 | + |
| 71910 | +/* |
| 71911 | +** Compare the "idx"-th cell on the page the cursor pCur is currently |
| 71912 | +** pointing to to pIdxKey using xRecordCompare. Return negative or |
| 71913 | +** zero if the cell is less than or equal pIdxKey. Return positive |
| 71914 | +** if unknown. |
| 71915 | +** |
| 71916 | +** Return value negative: Cell at pCur[idx] less than pIdxKey |
| 71917 | +** |
| 71918 | +** Return value is zero: Cell at pCur[idx] equals pIdxKey |
| 71919 | +** |
| 71920 | +** Return value positive: Nothing is known about the relationship |
| 71921 | +** of the cell at pCur[idx] and pIdxKey. |
| 71922 | +** |
| 71923 | +** This routine is part of an optimization. It is always safe to return |
| 71924 | +** a positive value as that will cause the optimization to be skipped. |
| 71925 | +*/ |
| 71926 | +static int indexCellCompare( |
| 71927 | + BtCursor *pCur, |
| 71928 | + int idx, |
| 71929 | + UnpackedRecord *pIdxKey, |
| 71930 | + RecordCompare xRecordCompare |
| 71931 | +){ |
| 71932 | + MemPage *pPage = pCur->pPage; |
| 71933 | + int c; |
| 71934 | + int nCell; /* Size of the pCell cell in bytes */ |
| 71935 | + u8 *pCell = findCellPastPtr(pPage, idx); |
| 71936 | + |
| 71937 | + nCell = pCell[0]; |
| 71938 | + if( nCell<=pPage->max1bytePayload ){ |
| 71939 | + /* This branch runs if the record-size field of the cell is a |
| 71940 | + ** single byte varint and the record fits entirely on the main |
| 71941 | + ** b-tree page. */ |
| 71942 | + testcase( pCell+nCell+1==pPage->aDataEnd ); |
| 71943 | + c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey); |
| 71944 | + }else if( !(pCell[1] & 0x80) |
| 71945 | + && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal |
| 71946 | + ){ |
| 71947 | + /* The record-size field is a 2 byte varint and the record |
| 71948 | + ** fits entirely on the main b-tree page. */ |
| 71949 | + testcase( pCell+nCell+2==pPage->aDataEnd ); |
| 71950 | + c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey); |
| 71951 | + }else{ |
| 71952 | + /* If the record extends into overflow pages, do not attempt |
| 71953 | + ** the optimization. */ |
| 71954 | + c = 99; |
| 71955 | + } |
| 71956 | + return c; |
| 71957 | +} |
| 71958 | + |
| 71959 | +/* |
| 71960 | +** Return true (non-zero) if pCur is current pointing to the last |
| 71961 | +** page of a table. |
| 71962 | +*/ |
| 71963 | +static int cursorOnLastPage(BtCursor *pCur){ |
| 71964 | + int i; |
| 71965 | + assert( pCur->eState==CURSOR_VALID ); |
| 71966 | + for(i=0; i<pCur->iPage; i++){ |
| 71967 | + MemPage *pPage = pCur->apPage[i]; |
| 71968 | + if( pCur->aiIdx[i]<pPage->nCell ) return 0; |
| 71969 | + } |
| 71970 | + return 1; |
| 71971 | +} |
| 71337 | 71972 | |
| 71338 | 71973 | /* Move the cursor so that it points to an entry in an index table |
| 71339 | 71974 | ** near the key pIdxKey. Return a success code. |
| 71340 | 71975 | ** |
| 71341 | 71976 | ** If an exact match is not found, then the cursor is always |
| | @@ -71383,25 +72018,61 @@ |
| 71383 | 72018 | assert( pIdxKey->default_rc==1 |
| 71384 | 72019 | || pIdxKey->default_rc==0 |
| 71385 | 72020 | || pIdxKey->default_rc==-1 |
| 71386 | 72021 | ); |
| 71387 | 72022 | |
| 72023 | + |
| 72024 | + /* Check to see if we can skip a lot of work. Two cases: |
| 72025 | + ** |
| 72026 | + ** (1) If the cursor is already pointing to the very last cell |
| 72027 | + ** in the table and the pIdxKey search key is greater than or |
| 72028 | + ** equal to that last cell, then no movement is required. |
| 72029 | + ** |
| 72030 | + ** (2) If the cursor is on the last page of the table and the first |
| 72031 | + ** cell on that last page is less than or equal to the pIdxKey |
| 72032 | + ** search key, then we can start the search on the current page |
| 72033 | + ** without needing to go back to root. |
| 72034 | + */ |
| 72035 | + if( pCur->eState==CURSOR_VALID |
| 72036 | + && pCur->pPage->leaf |
| 72037 | + && cursorOnLastPage(pCur) |
| 72038 | + ){ |
| 72039 | + int c; |
| 72040 | + if( pCur->ix==pCur->pPage->nCell-1 |
| 72041 | + && (c = indexCellCompare(pCur, pCur->ix, pIdxKey, xRecordCompare))<=0 |
| 72042 | + && pIdxKey->errCode==SQLITE_OK |
| 72043 | + ){ |
| 72044 | + *pRes = c; |
| 72045 | + return SQLITE_OK; /* Cursor already pointing at the correct spot */ |
| 72046 | + } |
| 72047 | + if( pCur->iPage>0 |
| 72048 | + && indexCellCompare(pCur, 0, pIdxKey, xRecordCompare)<=0 |
| 72049 | + && pIdxKey->errCode==SQLITE_OK |
| 72050 | + ){ |
| 72051 | + pCur->curFlags &= ~BTCF_ValidOvfl; |
| 72052 | + goto bypass_moveto_root; /* Start search on the current page */ |
| 72053 | + } |
| 72054 | + pIdxKey->errCode = SQLITE_OK; |
| 72055 | + } |
| 72056 | + |
| 71388 | 72057 | rc = moveToRoot(pCur); |
| 71389 | 72058 | if( rc ){ |
| 71390 | 72059 | if( rc==SQLITE_EMPTY ){ |
| 71391 | 72060 | assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 ); |
| 71392 | 72061 | *pRes = -1; |
| 71393 | 72062 | return SQLITE_OK; |
| 71394 | 72063 | } |
| 71395 | 72064 | return rc; |
| 71396 | 72065 | } |
| 72066 | + |
| 72067 | +bypass_moveto_root: |
| 71397 | 72068 | assert( pCur->pPage ); |
| 71398 | 72069 | assert( pCur->pPage->isInit ); |
| 71399 | 72070 | assert( pCur->eState==CURSOR_VALID ); |
| 71400 | 72071 | assert( pCur->pPage->nCell > 0 ); |
| 71401 | | - assert( pCur->iPage==0 || pCur->apPage[0]->intKey==pCur->curIntKey ); |
| 71402 | | - assert( pCur->curIntKey || pIdxKey ); |
| 72072 | + assert( pCur->curIntKey==0 ); |
| 72073 | + assert( pIdxKey!=0 ); |
| 71403 | 72074 | for(;;){ |
| 71404 | 72075 | int lwr, upr, idx, c; |
| 71405 | 72076 | Pgno chldPg; |
| 71406 | 72077 | MemPage *pPage = pCur->pPage; |
| 71407 | 72078 | u8 *pCell; /* Pointer to current cell in pPage */ |
| | @@ -71411,11 +72082,11 @@ |
| 71411 | 72082 | ** not run. If this is not the root-page, then the moveToChild() routine |
| 71412 | 72083 | ** would have already detected db corruption. Similarly, pPage must |
| 71413 | 72084 | ** be the right kind (index or table) of b-tree page. Otherwise |
| 71414 | 72085 | ** a moveToChild() or moveToRoot() call would have detected corruption. */ |
| 71415 | 72086 | assert( pPage->nCell>0 ); |
| 71416 | | - assert( pPage->intKey==(pIdxKey==0) ); |
| 72087 | + assert( pPage->intKey==0 ); |
| 71417 | 72088 | lwr = 0; |
| 71418 | 72089 | upr = pPage->nCell-1; |
| 71419 | 72090 | idx = upr>>1; /* idx = (lwr+upr)/2; */ |
| 71420 | 72091 | for(;;){ |
| 71421 | 72092 | int nCell; /* Size of the pCell cell in bytes */ |
| | @@ -72106,11 +72777,11 @@ |
| 72106 | 72777 | |
| 72107 | 72778 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 72108 | 72779 | assert( CORRUPT_DB || iPage>1 ); |
| 72109 | 72780 | assert( !pMemPage || pMemPage->pgno==iPage ); |
| 72110 | 72781 | |
| 72111 | | - if( NEVER(iPage<2) || iPage>pBt->nPage ){ |
| 72782 | + if( iPage<2 || iPage>pBt->nPage ){ |
| 72112 | 72783 | return SQLITE_CORRUPT_BKPT; |
| 72113 | 72784 | } |
| 72114 | 72785 | if( pMemPage ){ |
| 72115 | 72786 | pPage = pMemPage; |
| 72116 | 72787 | sqlite3PagerRef(pPage->pDbPage); |
| | @@ -72541,10 +73212,16 @@ |
| 72541 | 73212 | data = pPage->aData; |
| 72542 | 73213 | ptr = &pPage->aCellIdx[2*idx]; |
| 72543 | 73214 | assert( pPage->pBt->usableSize > (u32)(ptr-data) ); |
| 72544 | 73215 | pc = get2byte(ptr); |
| 72545 | 73216 | hdr = pPage->hdrOffset; |
| 73217 | +#if 0 /* Not required. Omit for efficiency */ |
| 73218 | + if( pc<hdr+pPage->nCell*2 ){ |
| 73219 | + *pRC = SQLITE_CORRUPT_BKPT; |
| 73220 | + return; |
| 73221 | + } |
| 73222 | +#endif |
| 72546 | 73223 | testcase( pc==(u32)get2byte(&data[hdr+5]) ); |
| 72547 | 73224 | testcase( pc+sz==pPage->pBt->usableSize ); |
| 72548 | 73225 | if( pc+sz > pPage->pBt->usableSize ){ |
| 72549 | 73226 | *pRC = SQLITE_CORRUPT_BKPT; |
| 72550 | 73227 | return; |
| | @@ -74504,11 +75181,11 @@ |
| 74504 | 75181 | ** For an index btree (used for indexes and WITHOUT ROWID tables), the |
| 74505 | 75182 | ** key is an arbitrary byte sequence stored in pX.pKey,nKey. The |
| 74506 | 75183 | ** pX.pData,nData,nZero fields must be zero. |
| 74507 | 75184 | ** |
| 74508 | 75185 | ** If the seekResult parameter is non-zero, then a successful call to |
| 74509 | | -** MovetoUnpacked() to seek cursor pCur to (pKey,nKey) has already |
| 75186 | +** sqlite3BtreeIndexMoveto() to seek cursor pCur to (pKey,nKey) has already |
| 74510 | 75187 | ** been performed. In other words, if seekResult!=0 then the cursor |
| 74511 | 75188 | ** is currently pointing to a cell that will be adjacent to the cell |
| 74512 | 75189 | ** to be inserted. If seekResult<0 then pCur points to a cell that is |
| 74513 | 75190 | ** smaller then (pKey,nKey). If seekResult>0 then pCur points to a cell |
| 74514 | 75191 | ** that is larger than (pKey,nKey). |
| | @@ -74522,11 +75199,11 @@ |
| 74522 | 75199 | */ |
| 74523 | 75200 | SQLITE_PRIVATE int sqlite3BtreeInsert( |
| 74524 | 75201 | BtCursor *pCur, /* Insert data into the table of this cursor */ |
| 74525 | 75202 | const BtreePayload *pX, /* Content of the row to be inserted */ |
| 74526 | 75203 | int flags, /* True if this is likely an append */ |
| 74527 | | - int seekResult /* Result of prior MovetoUnpacked() call */ |
| 75204 | + int seekResult /* Result of prior IndexMoveto() call */ |
| 74528 | 75205 | ){ |
| 74529 | 75206 | int rc; |
| 74530 | 75207 | int loc = seekResult; /* -1: before desired location +1: after */ |
| 74531 | 75208 | int szNew = 0; |
| 74532 | 75209 | int idx; |
| | @@ -74537,28 +75214,10 @@ |
| 74537 | 75214 | unsigned char *newCell = 0; |
| 74538 | 75215 | |
| 74539 | 75216 | assert( (flags & (BTREE_SAVEPOSITION|BTREE_APPEND|BTREE_PREFORMAT))==flags ); |
| 74540 | 75217 | assert( (flags & BTREE_PREFORMAT)==0 || seekResult || pCur->pKeyInfo==0 ); |
| 74541 | 75218 | |
| 74542 | | - if( pCur->eState==CURSOR_FAULT ){ |
| 74543 | | - assert( pCur->skipNext!=SQLITE_OK ); |
| 74544 | | - return pCur->skipNext; |
| 74545 | | - } |
| 74546 | | - |
| 74547 | | - assert( cursorOwnsBtShared(pCur) ); |
| 74548 | | - assert( (pCur->curFlags & BTCF_WriteFlag)!=0 |
| 74549 | | - && pBt->inTransaction==TRANS_WRITE |
| 74550 | | - && (pBt->btsFlags & BTS_READ_ONLY)==0 ); |
| 74551 | | - assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) ); |
| 74552 | | - |
| 74553 | | - /* Assert that the caller has been consistent. If this cursor was opened |
| 74554 | | - ** expecting an index b-tree, then the caller should be inserting blob |
| 74555 | | - ** keys with no associated data. If the cursor was opened expecting an |
| 74556 | | - ** intkey table, the caller should be inserting integer keys with a |
| 74557 | | - ** blob of associated data. */ |
| 74558 | | - assert( (flags & BTREE_PREFORMAT) || (pX->pKey==0)==(pCur->pKeyInfo==0) ); |
| 74559 | | - |
| 74560 | 75219 | /* Save the positions of any other cursors open on this table. |
| 74561 | 75220 | ** |
| 74562 | 75221 | ** In some cases, the call to btreeMoveto() below is a no-op. For |
| 74563 | 75222 | ** example, when inserting data into a table with auto-generated integer |
| 74564 | 75223 | ** keys, the VDBE layer invokes sqlite3BtreeLast() to figure out the |
| | @@ -74579,10 +75238,33 @@ |
| 74579 | 75238 | ** set the flag, load the schema, and then unset the flag. */ |
| 74580 | 75239 | return SQLITE_CORRUPT_BKPT; |
| 74581 | 75240 | } |
| 74582 | 75241 | } |
| 74583 | 75242 | |
| 75243 | + /* Ensure that the cursor is not in the CURSOR_FAULT state and that it |
| 75244 | + ** points to a valid cell. |
| 75245 | + */ |
| 75246 | + if( pCur->eState>=CURSOR_REQUIRESEEK ){ |
| 75247 | + testcase( pCur->eState==CURSOR_REQUIRESEEK ); |
| 75248 | + testcase( pCur->eState==CURSOR_FAULT ); |
| 75249 | + rc = moveToRoot(pCur); |
| 75250 | + if( rc && rc!=SQLITE_EMPTY ) return rc; |
| 75251 | + } |
| 75252 | + |
| 75253 | + assert( cursorOwnsBtShared(pCur) ); |
| 75254 | + assert( (pCur->curFlags & BTCF_WriteFlag)!=0 |
| 75255 | + && pBt->inTransaction==TRANS_WRITE |
| 75256 | + && (pBt->btsFlags & BTS_READ_ONLY)==0 ); |
| 75257 | + assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) ); |
| 75258 | + |
| 75259 | + /* Assert that the caller has been consistent. If this cursor was opened |
| 75260 | + ** expecting an index b-tree, then the caller should be inserting blob |
| 75261 | + ** keys with no associated data. If the cursor was opened expecting an |
| 75262 | + ** intkey table, the caller should be inserting integer keys with a |
| 75263 | + ** blob of associated data. */ |
| 75264 | + assert( (flags & BTREE_PREFORMAT) || (pX->pKey==0)==(pCur->pKeyInfo==0) ); |
| 75265 | + |
| 74584 | 75266 | if( pCur->pKeyInfo==0 ){ |
| 74585 | 75267 | assert( pX->pKey==0 ); |
| 74586 | 75268 | /* If this is an insert into a table b-tree, invalidate any incrblob |
| 74587 | 75269 | ** cursors open on the row being replaced */ |
| 74588 | 75270 | if( p->hasIncrblobCur ){ |
| | @@ -74667,18 +75349,18 @@ |
| 74667 | 75349 | return btreeOverwriteCell(pCur, &x2); |
| 74668 | 75350 | } |
| 74669 | 75351 | } |
| 74670 | 75352 | } |
| 74671 | 75353 | assert( pCur->eState==CURSOR_VALID |
| 74672 | | - || (pCur->eState==CURSOR_INVALID && loc) |
| 74673 | | - || CORRUPT_DB ); |
| 75354 | + || (pCur->eState==CURSOR_INVALID && loc) ); |
| 74674 | 75355 | |
| 74675 | 75356 | pPage = pCur->pPage; |
| 74676 | 75357 | assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) ); |
| 74677 | 75358 | assert( pPage->leaf || !pPage->intKey ); |
| 74678 | 75359 | if( pPage->nFree<0 ){ |
| 74679 | 75360 | if( NEVER(pCur->eState>CURSOR_INVALID) ){ |
| 75361 | + /* ^^^^^--- due to the moveToRoot() call above */ |
| 74680 | 75362 | rc = SQLITE_CORRUPT_BKPT; |
| 74681 | 75363 | }else{ |
| 74682 | 75364 | rc = btreeComputeFreeSpace(pPage); |
| 74683 | 75365 | } |
| 74684 | 75366 | if( rc ) return rc; |
| | @@ -74955,16 +75637,20 @@ |
| 74955 | 75637 | assert( (pBt->btsFlags & BTS_READ_ONLY)==0 ); |
| 74956 | 75638 | assert( pCur->curFlags & BTCF_WriteFlag ); |
| 74957 | 75639 | assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) ); |
| 74958 | 75640 | assert( !hasReadConflicts(p, pCur->pgnoRoot) ); |
| 74959 | 75641 | assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 ); |
| 74960 | | - if( pCur->eState==CURSOR_REQUIRESEEK ){ |
| 74961 | | - rc = btreeRestoreCursorPosition(pCur); |
| 74962 | | - assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID ); |
| 74963 | | - if( rc || pCur->eState!=CURSOR_VALID ) return rc; |
| 75642 | + if( pCur->eState!=CURSOR_VALID ){ |
| 75643 | + if( pCur->eState>=CURSOR_REQUIRESEEK ){ |
| 75644 | + rc = btreeRestoreCursorPosition(pCur); |
| 75645 | + assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID ); |
| 75646 | + if( rc || pCur->eState!=CURSOR_VALID ) return rc; |
| 75647 | + }else{ |
| 75648 | + return SQLITE_CORRUPT_BKPT; |
| 75649 | + } |
| 74964 | 75650 | } |
| 74965 | | - assert( CORRUPT_DB || pCur->eState==CURSOR_VALID ); |
| 75651 | + assert( pCur->eState==CURSOR_VALID ); |
| 74966 | 75652 | |
| 74967 | 75653 | iCellDepth = pCur->iPage; |
| 74968 | 75654 | iCellIdx = pCur->ix; |
| 74969 | 75655 | pPage = pCur->pPage; |
| 74970 | 75656 | if( pPage->nCell<=iCellIdx ){ |
| | @@ -74992,11 +75678,12 @@ |
| 74992 | 75678 | ** bPreserve==2 Cursor won't move. Set CURSOR_SKIPNEXT. |
| 74993 | 75679 | */ |
| 74994 | 75680 | bPreserve = (flags & BTREE_SAVEPOSITION)!=0; |
| 74995 | 75681 | if( bPreserve ){ |
| 74996 | 75682 | if( !pPage->leaf |
| 74997 | | - || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3) |
| 75683 | + || (pPage->nFree+pPage->xCellSize(pPage,pCell)+2) > |
| 75684 | + (int)(pBt->usableSize*2/3) |
| 74998 | 75685 | || pPage->nCell==1 /* See dbfuzz001.test for a test case */ |
| 74999 | 75686 | ){ |
| 75000 | 75687 | /* A b-tree rebalance will be required after deleting this entry. |
| 75001 | 75688 | ** Save the cursor key. */ |
| 75002 | 75689 | rc = saveCursorKey(pCur); |
| | @@ -75311,11 +75998,11 @@ |
| 75311 | 75998 | return SQLITE_CORRUPT_BKPT; |
| 75312 | 75999 | } |
| 75313 | 76000 | rc = getAndInitPage(pBt, pgno, &pPage, 0, 0); |
| 75314 | 76001 | if( rc ) return rc; |
| 75315 | 76002 | if( (pBt->openFlags & BTREE_SINGLE)==0 |
| 75316 | | - && sqlite3PagerPageRefcount(pPage->pDbPage)!=1 |
| 76003 | + && sqlite3PagerPageRefcount(pPage->pDbPage) != (1 + (pgno==1)) |
| 75317 | 76004 | ){ |
| 75318 | 76005 | rc = SQLITE_CORRUPT_BKPT; |
| 75319 | 76006 | goto cleardatabasepage_out; |
| 75320 | 76007 | } |
| 75321 | 76008 | hdr = pPage->hdrOffset; |
| | @@ -76691,18 +77378,17 @@ |
| 76691 | 77378 | int i = sqlite3FindDbName(pDb, zDb); |
| 76692 | 77379 | |
| 76693 | 77380 | if( i==1 ){ |
| 76694 | 77381 | Parse sParse; |
| 76695 | 77382 | int rc = 0; |
| 76696 | | - memset(&sParse, 0, sizeof(sParse)); |
| 76697 | | - sParse.db = pDb; |
| 77383 | + sqlite3ParseObjectInit(&sParse,pDb); |
| 76698 | 77384 | if( sqlite3OpenTempDatabase(&sParse) ){ |
| 76699 | 77385 | sqlite3ErrorWithMsg(pErrorDb, sParse.rc, "%s", sParse.zErrMsg); |
| 76700 | 77386 | rc = SQLITE_ERROR; |
| 76701 | 77387 | } |
| 76702 | 77388 | sqlite3DbFree(pErrorDb, sParse.zErrMsg); |
| 76703 | | - sqlite3ParserReset(&sParse); |
| 77389 | + sqlite3ParseObjectReset(&sParse); |
| 76704 | 77390 | if( rc ){ |
| 76705 | 77391 | return 0; |
| 76706 | 77392 | } |
| 76707 | 77393 | } |
| 76708 | 77394 | |
| | @@ -77934,10 +78620,18 @@ |
| 77934 | 78620 | assert( sqlite3VdbeCheckMemInvariants(p) ); |
| 77935 | 78621 | if( VdbeMemDynamic(p) || p->szMalloc ){ |
| 77936 | 78622 | vdbeMemClear(p); |
| 77937 | 78623 | } |
| 77938 | 78624 | } |
| 78625 | + |
| 78626 | +/* Like sqlite3VdbeMemRelease() but faster for cases where we |
| 78627 | +** know in advance that the Mem is not MEM_Dyn or MEM_Agg. |
| 78628 | +*/ |
| 78629 | +SQLITE_PRIVATE void sqlite3VdbeMemReleaseMalloc(Mem *p){ |
| 78630 | + assert( !VdbeMemDynamic(p) ); |
| 78631 | + if( p->szMalloc ) vdbeMemClear(p); |
| 78632 | +} |
| 77939 | 78633 | |
| 77940 | 78634 | /* |
| 77941 | 78635 | ** Convert a 64-bit IEEE double into a 64-bit signed integer. |
| 77942 | 78636 | ** If the double is out of range of a 64-bit signed integer then |
| 77943 | 78637 | ** return the closest available 64-bit signed integer. |
| | @@ -78296,10 +78990,11 @@ |
| 78296 | 78990 | void *pPtr, |
| 78297 | 78991 | const char *zPType, |
| 78298 | 78992 | void (*xDestructor)(void*) |
| 78299 | 78993 | ){ |
| 78300 | 78994 | assert( pMem->flags==MEM_Null ); |
| 78995 | + vdbeMemClear(pMem); |
| 78301 | 78996 | pMem->u.zPType = zPType ? zPType : ""; |
| 78302 | 78997 | pMem->z = pPtr; |
| 78303 | 78998 | pMem->flags = MEM_Null|MEM_Dyn|MEM_Subtype|MEM_Term; |
| 78304 | 78999 | pMem->eSubtype = 'p'; |
| 78305 | 79000 | pMem->xDel = xDestructor ? xDestructor : sqlite3NoopDestructor; |
| | @@ -78910,15 +79605,11 @@ |
| 78910 | 79605 | const char *zNeg = ""; |
| 78911 | 79606 | int rc = SQLITE_OK; |
| 78912 | 79607 | |
| 78913 | 79608 | assert( pExpr!=0 ); |
| 78914 | 79609 | while( (op = pExpr->op)==TK_UPLUS || op==TK_SPAN ) pExpr = pExpr->pLeft; |
| 78915 | | -#if defined(SQLITE_ENABLE_STAT4) |
| 78916 | 79610 | if( op==TK_REGISTER ) op = pExpr->op2; |
| 78917 | | -#else |
| 78918 | | - if( NEVER(op==TK_REGISTER) ) op = pExpr->op2; |
| 78919 | | -#endif |
| 78920 | 79611 | |
| 78921 | 79612 | /* Compressed expressions only appear when parsing the DEFAULT clause |
| 78922 | 79613 | ** on a table column definition, and hence only when pCtx==0. This |
| 78923 | 79614 | ** check ensures that an EP_TokenOnly expression is never passed down |
| 78924 | 79615 | ** into valueFromFunction(). */ |
| | @@ -79029,11 +79720,11 @@ |
| 79029 | 79720 | *ppVal = pVal; |
| 79030 | 79721 | return rc; |
| 79031 | 79722 | |
| 79032 | 79723 | no_mem: |
| 79033 | 79724 | #ifdef SQLITE_ENABLE_STAT4 |
| 79034 | | - if( pCtx==0 || pCtx->pParse->nErr==0 ) |
| 79725 | + if( pCtx==0 || NEVER(pCtx->pParse->nErr==0) ) |
| 79035 | 79726 | #endif |
| 79036 | 79727 | sqlite3OomFault(db); |
| 79037 | 79728 | sqlite3DbFree(db, zVal); |
| 79038 | 79729 | assert( *ppVal==0 ); |
| 79039 | 79730 | #ifdef SQLITE_ENABLE_STAT4 |
| | @@ -79509,11 +80200,11 @@ |
| 79509 | 80200 | if( nNew > p->db->aLimit[SQLITE_LIMIT_VDBE_OP] ){ |
| 79510 | 80201 | sqlite3OomFault(p->db); |
| 79511 | 80202 | return SQLITE_NOMEM; |
| 79512 | 80203 | } |
| 79513 | 80204 | |
| 79514 | | - assert( nOp<=(1024/sizeof(Op)) ); |
| 80205 | + assert( nOp<=(int)(1024/sizeof(Op)) ); |
| 79515 | 80206 | assert( nNew>=(v->nOpAlloc+nOp) ); |
| 79516 | 80207 | pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op)); |
| 79517 | 80208 | if( pNew ){ |
| 79518 | 80209 | p->szOpAlloc = sqlite3DbMallocSize(p->db, pNew); |
| 79519 | 80210 | v->nOpAlloc = p->szOpAlloc/sizeof(Op); |
| | @@ -80111,11 +80802,11 @@ |
| 80111 | 80802 | ** and store that value in *pMaxFuncArgs. |
| 80112 | 80803 | ** |
| 80113 | 80804 | ** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately |
| 80114 | 80805 | ** indicate what the prepared statement actually does. |
| 80115 | 80806 | ** |
| 80116 | | -** (4) Initialize the p4.xAdvance pointer on opcodes that use it. |
| 80807 | +** (4) (discontinued) |
| 80117 | 80808 | ** |
| 80118 | 80809 | ** (5) Reclaim the memory allocated for storing labels. |
| 80119 | 80810 | ** |
| 80120 | 80811 | ** This routine will only function correctly if the mkopcodeh.tcl generator |
| 80121 | 80812 | ** script numbers the opcodes correctly. Changes to this routine must be |
| | @@ -80157,29 +80848,10 @@ |
| 80157 | 80848 | case OP_JournalMode: { |
| 80158 | 80849 | p->readOnly = 0; |
| 80159 | 80850 | p->bIsReader = 1; |
| 80160 | 80851 | break; |
| 80161 | 80852 | } |
| 80162 | | - case OP_Next: |
| 80163 | | - case OP_SorterNext: { |
| 80164 | | - pOp->p4.xAdvance = sqlite3BtreeNext; |
| 80165 | | - pOp->p4type = P4_ADVANCE; |
| 80166 | | - /* The code generator never codes any of these opcodes as a jump |
| 80167 | | - ** to a label. They are always coded as a jump backwards to a |
| 80168 | | - ** known address */ |
| 80169 | | - assert( pOp->p2>=0 ); |
| 80170 | | - break; |
| 80171 | | - } |
| 80172 | | - case OP_Prev: { |
| 80173 | | - pOp->p4.xAdvance = sqlite3BtreePrevious; |
| 80174 | | - pOp->p4type = P4_ADVANCE; |
| 80175 | | - /* The code generator never codes any of these opcodes as a jump |
| 80176 | | - ** to a label. They are always coded as a jump backwards to a |
| 80177 | | - ** known address */ |
| 80178 | | - assert( pOp->p2>=0 ); |
| 80179 | | - break; |
| 80180 | | - } |
| 80181 | 80853 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 80182 | 80854 | case OP_VUpdate: { |
| 80183 | 80855 | if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2; |
| 80184 | 80856 | break; |
| 80185 | 80857 | } |
| | @@ -80459,11 +81131,10 @@ |
| 80459 | 81131 | break; |
| 80460 | 81132 | } |
| 80461 | 81133 | case P4_REAL: |
| 80462 | 81134 | case P4_INT64: |
| 80463 | 81135 | case P4_DYNAMIC: |
| 80464 | | - case P4_DYNBLOB: |
| 80465 | 81136 | case P4_INTARRAY: { |
| 80466 | 81137 | sqlite3DbFree(db, p4); |
| 80467 | 81138 | break; |
| 80468 | 81139 | } |
| 80469 | 81140 | case P4_KEYINFO: { |
| | @@ -80707,12 +81378,11 @@ |
| 80707 | 81378 | ** makes the code easier to read during debugging. None of this happens |
| 80708 | 81379 | ** in a production build. |
| 80709 | 81380 | */ |
| 80710 | 81381 | static void vdbeVComment(Vdbe *p, const char *zFormat, va_list ap){ |
| 80711 | 81382 | assert( p->nOp>0 || p->aOp==0 ); |
| 80712 | | - assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed |
| 80713 | | - || p->pParse->nErr>0 ); |
| 81383 | + assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->pParse->nErr>0 ); |
| 80714 | 81384 | if( p->nOp ){ |
| 80715 | 81385 | assert( p->aOp ); |
| 80716 | 81386 | sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment); |
| 80717 | 81387 | p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap); |
| 80718 | 81388 | } |
| | @@ -81057,14 +81727,10 @@ |
| 81057 | 81727 | } |
| 81058 | 81728 | case P4_SUBPROGRAM: { |
| 81059 | 81729 | zP4 = "program"; |
| 81060 | 81730 | break; |
| 81061 | 81731 | } |
| 81062 | | - case P4_DYNBLOB: |
| 81063 | | - case P4_ADVANCE: { |
| 81064 | | - break; |
| 81065 | | - } |
| 81066 | 81732 | case P4_TABLE: { |
| 81067 | 81733 | zP4 = pOp->p4.pTab->zName; |
| 81068 | 81734 | break; |
| 81069 | 81735 | } |
| 81070 | 81736 | default: { |
| | @@ -81192,25 +81858,44 @@ |
| 81192 | 81858 | } |
| 81193 | 81859 | #endif |
| 81194 | 81860 | |
| 81195 | 81861 | /* |
| 81196 | 81862 | ** Initialize an array of N Mem element. |
| 81863 | +** |
| 81864 | +** This is a high-runner, so only those fields that really do need to |
| 81865 | +** be initialized are set. The Mem structure is organized so that |
| 81866 | +** the fields that get initialized are nearby and hopefully on the same |
| 81867 | +** cache line. |
| 81868 | +** |
| 81869 | +** Mem.flags = flags |
| 81870 | +** Mem.db = db |
| 81871 | +** Mem.szMalloc = 0 |
| 81872 | +** |
| 81873 | +** All other fields of Mem can safely remain uninitialized for now. They |
| 81874 | +** will be initialized before use. |
| 81197 | 81875 | */ |
| 81198 | 81876 | static void initMemArray(Mem *p, int N, sqlite3 *db, u16 flags){ |
| 81199 | | - while( (N--)>0 ){ |
| 81200 | | - p->db = db; |
| 81201 | | - p->flags = flags; |
| 81202 | | - p->szMalloc = 0; |
| 81877 | + if( N>0 ){ |
| 81878 | + do{ |
| 81879 | + p->flags = flags; |
| 81880 | + p->db = db; |
| 81881 | + p->szMalloc = 0; |
| 81203 | 81882 | #ifdef SQLITE_DEBUG |
| 81204 | | - p->pScopyFrom = 0; |
| 81883 | + p->pScopyFrom = 0; |
| 81205 | 81884 | #endif |
| 81206 | | - p++; |
| 81885 | + p++; |
| 81886 | + }while( (--N)>0 ); |
| 81207 | 81887 | } |
| 81208 | 81888 | } |
| 81209 | 81889 | |
| 81210 | 81890 | /* |
| 81211 | | -** Release an array of N Mem elements |
| 81891 | +** Release auxiliary memory held in an array of N Mem elements. |
| 81892 | +** |
| 81893 | +** After this routine returns, all Mem elements in the array will still |
| 81894 | +** be valid. Those Mem elements that were not holding auxiliary resources |
| 81895 | +** will be unchanged. Mem elements which had something freed will be |
| 81896 | +** set to MEM_Undefined. |
| 81212 | 81897 | */ |
| 81213 | 81898 | static void releaseMemArray(Mem *p, int N){ |
| 81214 | 81899 | if( p && N ){ |
| 81215 | 81900 | Mem *pEnd = &p[N]; |
| 81216 | 81901 | sqlite3 *db = p->db; |
| | @@ -81239,16 +81924,21 @@ |
| 81239 | 81924 | testcase( p->flags & MEM_Agg ); |
| 81240 | 81925 | testcase( p->flags & MEM_Dyn ); |
| 81241 | 81926 | if( p->flags&(MEM_Agg|MEM_Dyn) ){ |
| 81242 | 81927 | testcase( (p->flags & MEM_Dyn)!=0 && p->xDel==sqlite3VdbeFrameMemDel ); |
| 81243 | 81928 | sqlite3VdbeMemRelease(p); |
| 81929 | + p->flags = MEM_Undefined; |
| 81244 | 81930 | }else if( p->szMalloc ){ |
| 81245 | 81931 | sqlite3DbFreeNN(db, p->zMalloc); |
| 81246 | 81932 | p->szMalloc = 0; |
| 81933 | + p->flags = MEM_Undefined; |
| 81247 | 81934 | } |
| 81248 | | - |
| 81249 | | - p->flags = MEM_Undefined; |
| 81935 | +#ifdef SQLITE_DEBUG |
| 81936 | + else{ |
| 81937 | + p->flags = MEM_Undefined; |
| 81938 | + } |
| 81939 | +#endif |
| 81250 | 81940 | }while( (++p)<pEnd ); |
| 81251 | 81941 | } |
| 81252 | 81942 | } |
| 81253 | 81943 | |
| 81254 | 81944 | #ifdef SQLITE_DEBUG |
| | @@ -82324,11 +83014,11 @@ |
| 82324 | 83014 | || (!deferred && p->nFkConstraint>0) |
| 82325 | 83015 | ){ |
| 82326 | 83016 | p->rc = SQLITE_CONSTRAINT_FOREIGNKEY; |
| 82327 | 83017 | p->errorAction = OE_Abort; |
| 82328 | 83018 | sqlite3VdbeError(p, "FOREIGN KEY constraint failed"); |
| 82329 | | - return SQLITE_ERROR; |
| 83019 | + return SQLITE_CONSTRAINT_FOREIGNKEY; |
| 82330 | 83020 | } |
| 82331 | 83021 | return SQLITE_OK; |
| 82332 | 83022 | } |
| 82333 | 83023 | #endif |
| 82334 | 83024 | |
| | @@ -82579,10 +83269,11 @@ |
| 82579 | 83269 | db->bBenignMalloc--; |
| 82580 | 83270 | }else if( db->pErr ){ |
| 82581 | 83271 | sqlite3ValueSetNull(db->pErr); |
| 82582 | 83272 | } |
| 82583 | 83273 | db->errCode = rc; |
| 83274 | + db->errByteOffset = -1; |
| 82584 | 83275 | return rc; |
| 82585 | 83276 | } |
| 82586 | 83277 | |
| 82587 | 83278 | #ifdef SQLITE_ENABLE_SQLLOG |
| 82588 | 83279 | /* |
| | @@ -82858,11 +83549,11 @@ |
| 82858 | 83549 | ** pointed to was deleted out from under it. Or maybe the btree was |
| 82859 | 83550 | ** rebalanced. Whatever the cause, try to restore "p" to the place it |
| 82860 | 83551 | ** is supposed to be pointing. If the row was deleted out from under the |
| 82861 | 83552 | ** cursor, set the cursor to point to a NULL row. |
| 82862 | 83553 | */ |
| 82863 | | -static int SQLITE_NOINLINE handleMovedCursor(VdbeCursor *p){ |
| 83554 | +SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeHandleMovedCursor(VdbeCursor *p){ |
| 82864 | 83555 | int isDifferentRow, rc; |
| 82865 | 83556 | assert( p->eCurType==CURTYPE_BTREE ); |
| 82866 | 83557 | assert( p->uc.pCursor!=0 ); |
| 82867 | 83558 | assert( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ); |
| 82868 | 83559 | rc = sqlite3BtreeCursorRestore(p->uc.pCursor, &isDifferentRow); |
| | @@ -82876,43 +83567,11 @@ |
| 82876 | 83567 | ** if need be. Return any I/O error from the restore operation. |
| 82877 | 83568 | */ |
| 82878 | 83569 | SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor *p){ |
| 82879 | 83570 | assert( p->eCurType==CURTYPE_BTREE ); |
| 82880 | 83571 | if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){ |
| 82881 | | - return handleMovedCursor(p); |
| 82882 | | - } |
| 82883 | | - return SQLITE_OK; |
| 82884 | | -} |
| 82885 | | - |
| 82886 | | -/* |
| 82887 | | -** Make sure the cursor p is ready to read or write the row to which it |
| 82888 | | -** was last positioned. Return an error code if an OOM fault or I/O error |
| 82889 | | -** prevents us from positioning the cursor to its correct position. |
| 82890 | | -** |
| 82891 | | -** If a MoveTo operation is pending on the given cursor, then do that |
| 82892 | | -** MoveTo now. If no move is pending, check to see if the row has been |
| 82893 | | -** deleted out from under the cursor and if it has, mark the row as |
| 82894 | | -** a NULL row. |
| 82895 | | -** |
| 82896 | | -** If the cursor is already pointing to the correct row and that row has |
| 82897 | | -** not been deleted out from under the cursor, then this routine is a no-op. |
| 82898 | | -*/ |
| 82899 | | -SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **pp, u32 *piCol){ |
| 82900 | | - VdbeCursor *p = *pp; |
| 82901 | | - assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO ); |
| 82902 | | - if( p->deferredMoveto ){ |
| 82903 | | - u32 iMap; |
| 82904 | | - assert( !p->isEphemeral ); |
| 82905 | | - if( p->ub.aAltMap && (iMap = p->ub.aAltMap[1+*piCol])>0 && !p->nullRow ){ |
| 82906 | | - *pp = p->pAltCursor; |
| 82907 | | - *piCol = iMap - 1; |
| 82908 | | - return SQLITE_OK; |
| 82909 | | - } |
| 82910 | | - return sqlite3VdbeFinishMoveto(p); |
| 82911 | | - } |
| 82912 | | - if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){ |
| 82913 | | - return handleMovedCursor(p); |
| 83572 | + return sqlite3VdbeHandleMovedCursor(p); |
| 82914 | 83573 | } |
| 82915 | 83574 | return SQLITE_OK; |
| 82916 | 83575 | } |
| 82917 | 83576 | |
| 82918 | 83577 | /* |
| | @@ -83570,12 +84229,12 @@ |
| 83570 | 84229 | if( prcErr ) *prcErr = SQLITE_NOMEM_BKPT; |
| 83571 | 84230 | rc = 0; |
| 83572 | 84231 | }else{ |
| 83573 | 84232 | rc = pColl->xCmp(pColl->pUser, c1.n, v1, c2.n, v2); |
| 83574 | 84233 | } |
| 83575 | | - sqlite3VdbeMemRelease(&c1); |
| 83576 | | - sqlite3VdbeMemRelease(&c2); |
| 84234 | + sqlite3VdbeMemReleaseMalloc(&c1); |
| 84235 | + sqlite3VdbeMemReleaseMalloc(&c2); |
| 83577 | 84236 | return rc; |
| 83578 | 84237 | } |
| 83579 | 84238 | } |
| 83580 | 84239 | |
| 83581 | 84240 | /* |
| | @@ -84095,11 +84754,12 @@ |
| 84095 | 84754 | |
| 84096 | 84755 | default: |
| 84097 | 84756 | return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2); |
| 84098 | 84757 | } |
| 84099 | 84758 | |
| 84100 | | - v = pPKey2->aMem[0].u.i; |
| 84759 | + assert( pPKey2->u.i == pPKey2->aMem[0].u.i ); |
| 84760 | + v = pPKey2->u.i; |
| 84101 | 84761 | if( v>lhs ){ |
| 84102 | 84762 | res = pPKey2->r1; |
| 84103 | 84763 | }else if( v<lhs ){ |
| 84104 | 84764 | res = pPKey2->r2; |
| 84105 | 84765 | }else if( pPKey2->nField>1 ){ |
| | @@ -84130,16 +84790,22 @@ |
| 84130 | 84790 | const u8 *aKey1 = (const u8*)pKey1; |
| 84131 | 84791 | int serial_type; |
| 84132 | 84792 | int res; |
| 84133 | 84793 | |
| 84134 | 84794 | assert( pPKey2->aMem[0].flags & MEM_Str ); |
| 84795 | + assert( pPKey2->aMem[0].n == pPKey2->n ); |
| 84796 | + assert( pPKey2->aMem[0].z == pPKey2->u.z ); |
| 84135 | 84797 | vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo); |
| 84136 | | - serial_type = (u8)(aKey1[1]); |
| 84137 | | - if( serial_type >= 0x80 ){ |
| 84138 | | - sqlite3GetVarint32(&aKey1[1], (u32*)&serial_type); |
| 84139 | | - } |
| 84798 | + serial_type = (signed char)(aKey1[1]); |
| 84799 | + |
| 84800 | +vrcs_restart: |
| 84140 | 84801 | if( serial_type<12 ){ |
| 84802 | + if( serial_type<0 ){ |
| 84803 | + sqlite3GetVarint32(&aKey1[1], (u32*)&serial_type); |
| 84804 | + if( serial_type>=12 ) goto vrcs_restart; |
| 84805 | + assert( CORRUPT_DB ); |
| 84806 | + } |
| 84141 | 84807 | res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */ |
| 84142 | 84808 | }else if( !(serial_type & 0x01) ){ |
| 84143 | 84809 | res = pPKey2->r2; /* (pKey1/nKey1) is a blob */ |
| 84144 | 84810 | }else{ |
| 84145 | 84811 | int nCmp; |
| | @@ -84149,19 +84815,19 @@ |
| 84149 | 84815 | nStr = (serial_type-12) / 2; |
| 84150 | 84816 | if( (szHdr + nStr) > nKey1 ){ |
| 84151 | 84817 | pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT; |
| 84152 | 84818 | return 0; /* Corruption */ |
| 84153 | 84819 | } |
| 84154 | | - nCmp = MIN( pPKey2->aMem[0].n, nStr ); |
| 84155 | | - res = memcmp(&aKey1[szHdr], pPKey2->aMem[0].z, nCmp); |
| 84820 | + nCmp = MIN( pPKey2->n, nStr ); |
| 84821 | + res = memcmp(&aKey1[szHdr], pPKey2->u.z, nCmp); |
| 84156 | 84822 | |
| 84157 | 84823 | if( res>0 ){ |
| 84158 | 84824 | res = pPKey2->r2; |
| 84159 | 84825 | }else if( res<0 ){ |
| 84160 | 84826 | res = pPKey2->r1; |
| 84161 | 84827 | }else{ |
| 84162 | | - res = nStr - pPKey2->aMem[0].n; |
| 84828 | + res = nStr - pPKey2->n; |
| 84163 | 84829 | if( res==0 ){ |
| 84164 | 84830 | if( pPKey2->nField>1 ){ |
| 84165 | 84831 | res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); |
| 84166 | 84832 | }else{ |
| 84167 | 84833 | res = pPKey2->default_rc; |
| | @@ -84212,19 +84878,22 @@ |
| 84212 | 84878 | }else{ |
| 84213 | 84879 | p->r1 = -1; |
| 84214 | 84880 | p->r2 = 1; |
| 84215 | 84881 | } |
| 84216 | 84882 | if( (flags & MEM_Int) ){ |
| 84883 | + p->u.i = p->aMem[0].u.i; |
| 84217 | 84884 | return vdbeRecordCompareInt; |
| 84218 | 84885 | } |
| 84219 | 84886 | testcase( flags & MEM_Real ); |
| 84220 | 84887 | testcase( flags & MEM_Null ); |
| 84221 | 84888 | testcase( flags & MEM_Blob ); |
| 84222 | 84889 | if( (flags & (MEM_Real|MEM_IntReal|MEM_Null|MEM_Blob))==0 |
| 84223 | 84890 | && p->pKeyInfo->aColl[0]==0 |
| 84224 | 84891 | ){ |
| 84225 | 84892 | assert( flags & MEM_Str ); |
| 84893 | + p->u.z = p->aMem[0].z; |
| 84894 | + p->n = p->aMem[0].n; |
| 84226 | 84895 | return vdbeRecordCompareString; |
| 84227 | 84896 | } |
| 84228 | 84897 | } |
| 84229 | 84898 | |
| 84230 | 84899 | return sqlite3VdbeRecordCompare; |
| | @@ -84293,18 +84962,18 @@ |
| 84293 | 84962 | } |
| 84294 | 84963 | |
| 84295 | 84964 | /* Fetch the integer off the end of the index record */ |
| 84296 | 84965 | sqlite3VdbeSerialGet((u8*)&m.z[m.n-lenRowid], typeRowid, &v); |
| 84297 | 84966 | *rowid = v.u.i; |
| 84298 | | - sqlite3VdbeMemRelease(&m); |
| 84967 | + sqlite3VdbeMemReleaseMalloc(&m); |
| 84299 | 84968 | return SQLITE_OK; |
| 84300 | 84969 | |
| 84301 | 84970 | /* Jump here if database corruption is detected after m has been |
| 84302 | 84971 | ** allocated. Free the m object and return SQLITE_CORRUPT. */ |
| 84303 | 84972 | idx_rowid_corruption: |
| 84304 | 84973 | testcase( m.szMalloc!=0 ); |
| 84305 | | - sqlite3VdbeMemRelease(&m); |
| 84974 | + sqlite3VdbeMemReleaseMalloc(&m); |
| 84306 | 84975 | return SQLITE_CORRUPT_BKPT; |
| 84307 | 84976 | } |
| 84308 | 84977 | |
| 84309 | 84978 | /* |
| 84310 | 84979 | ** Compare the key of the index entry that cursor pC is pointing to against |
| | @@ -84342,11 +85011,11 @@ |
| 84342 | 85011 | rc = sqlite3VdbeMemFromBtreeZeroOffset(pCur, (u32)nCellKey, &m); |
| 84343 | 85012 | if( rc ){ |
| 84344 | 85013 | return rc; |
| 84345 | 85014 | } |
| 84346 | 85015 | *res = sqlite3VdbeRecordCompareWithSkip(m.n, m.z, pUnpacked, 0); |
| 84347 | | - sqlite3VdbeMemRelease(&m); |
| 85016 | + sqlite3VdbeMemReleaseMalloc(&m); |
| 84348 | 85017 | return SQLITE_OK; |
| 84349 | 85018 | } |
| 84350 | 85019 | |
| 84351 | 85020 | /* |
| 84352 | 85021 | ** This routine sets the value to be returned by subsequent calls to |
| | @@ -84509,11 +85178,11 @@ |
| 84509 | 85178 | static void vdbeFreeUnpacked(sqlite3 *db, int nField, UnpackedRecord *p){ |
| 84510 | 85179 | if( p ){ |
| 84511 | 85180 | int i; |
| 84512 | 85181 | for(i=0; i<nField; i++){ |
| 84513 | 85182 | Mem *pMem = &p->aMem[i]; |
| 84514 | | - if( pMem->zMalloc ) sqlite3VdbeMemRelease(pMem); |
| 85183 | + if( pMem->zMalloc ) sqlite3VdbeMemReleaseMalloc(pMem); |
| 84515 | 85184 | } |
| 84516 | 85185 | sqlite3DbFreeNN(db, p); |
| 84517 | 85186 | } |
| 84518 | 85187 | } |
| 84519 | 85188 | #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */ |
| | @@ -84936,10 +85605,13 @@ |
| 84936 | 85605 | pNew->flags |= MEM_Ephem; |
| 84937 | 85606 | if( sqlite3VdbeMemMakeWriteable(pNew)!=SQLITE_OK ){ |
| 84938 | 85607 | sqlite3ValueFree(pNew); |
| 84939 | 85608 | pNew = 0; |
| 84940 | 85609 | } |
| 85610 | + }else if( pNew->flags & MEM_Null ){ |
| 85611 | + /* Do not duplicate pointer values */ |
| 85612 | + pNew->flags &= ~(MEM_Term|MEM_Subtype); |
| 84941 | 85613 | } |
| 84942 | 85614 | return pNew; |
| 84943 | 85615 | } |
| 84944 | 85616 | |
| 84945 | 85617 | /* Destroy an sqlite3_value object previously obtained from |
| | @@ -85436,10 +86108,74 @@ |
| 85436 | 86108 | */ |
| 85437 | 86109 | SQLITE_API int sqlite3_vtab_nochange(sqlite3_context *p){ |
| 85438 | 86110 | assert( p ); |
| 85439 | 86111 | return sqlite3_value_nochange(p->pOut); |
| 85440 | 86112 | } |
| 86113 | + |
| 86114 | +/* |
| 86115 | +** Implementation of sqlite3_vtab_in_first() (if bNext==0) and |
| 86116 | +** sqlite3_vtab_in_next() (if bNext!=0). |
| 86117 | +*/ |
| 86118 | +static int valueFromValueList( |
| 86119 | + sqlite3_value *pVal, /* Pointer to the ValueList object */ |
| 86120 | + sqlite3_value **ppOut, /* Store the next value from the list here */ |
| 86121 | + int bNext /* 1 for _next(). 0 for _first() */ |
| 86122 | +){ |
| 86123 | + int rc; |
| 86124 | + ValueList *pRhs; |
| 86125 | + |
| 86126 | + *ppOut = 0; |
| 86127 | + if( pVal==0 ) return SQLITE_MISUSE; |
| 86128 | + pRhs = (ValueList*)sqlite3_value_pointer(pVal, "ValueList"); |
| 86129 | + if( pRhs==0 ) return SQLITE_MISUSE; |
| 86130 | + if( bNext ){ |
| 86131 | + rc = sqlite3BtreeNext(pRhs->pCsr, 0); |
| 86132 | + }else{ |
| 86133 | + int dummy = 0; |
| 86134 | + rc = sqlite3BtreeFirst(pRhs->pCsr, &dummy); |
| 86135 | + assert( rc==SQLITE_OK || sqlite3BtreeEof(pRhs->pCsr) ); |
| 86136 | + if( sqlite3BtreeEof(pRhs->pCsr) ) rc = SQLITE_DONE; |
| 86137 | + } |
| 86138 | + if( rc==SQLITE_OK ){ |
| 86139 | + u32 sz; /* Size of current row in bytes */ |
| 86140 | + Mem sMem; /* Raw content of current row */ |
| 86141 | + memset(&sMem, 0, sizeof(sMem)); |
| 86142 | + sz = sqlite3BtreePayloadSize(pRhs->pCsr); |
| 86143 | + rc = sqlite3VdbeMemFromBtreeZeroOffset(pRhs->pCsr,(int)sz,&sMem); |
| 86144 | + if( rc==SQLITE_OK ){ |
| 86145 | + u8 *zBuf = (u8*)sMem.z; |
| 86146 | + u32 iSerial; |
| 86147 | + sqlite3_value *pOut = pRhs->pOut; |
| 86148 | + int iOff = 1 + getVarint32(&zBuf[1], iSerial); |
| 86149 | + sqlite3VdbeSerialGet(&zBuf[iOff], iSerial, pOut); |
| 86150 | + pOut->enc = ENC(pOut->db); |
| 86151 | + if( (pOut->flags & MEM_Ephem)!=0 && sqlite3VdbeMemMakeWriteable(pOut) ){ |
| 86152 | + rc = SQLITE_NOMEM; |
| 86153 | + }else{ |
| 86154 | + *ppOut = pOut; |
| 86155 | + } |
| 86156 | + } |
| 86157 | + sqlite3VdbeMemRelease(&sMem); |
| 86158 | + } |
| 86159 | + return rc; |
| 86160 | +} |
| 86161 | + |
| 86162 | +/* |
| 86163 | +** Set the iterator value pVal to point to the first value in the set. |
| 86164 | +** Set (*ppOut) to point to this value before returning. |
| 86165 | +*/ |
| 86166 | +SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut){ |
| 86167 | + return valueFromValueList(pVal, ppOut, 0); |
| 86168 | +} |
| 86169 | + |
| 86170 | +/* |
| 86171 | +** Set the iterator value pVal to point to the next value in the set. |
| 86172 | +** Set (*ppOut) to point to this value before returning. |
| 86173 | +*/ |
| 86174 | +SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut){ |
| 86175 | + return valueFromValueList(pVal, ppOut, 1); |
| 86176 | +} |
| 85441 | 86177 | |
| 85442 | 86178 | /* |
| 85443 | 86179 | ** Return the current time for a statement. If the current time |
| 85444 | 86180 | ** is requested more than once within the same run of a single prepared |
| 85445 | 86181 | ** statement, the exact same time is returned for each invocation regardless |
| | @@ -85631,19 +86367,19 @@ |
| 85631 | 86367 | #if defined(SQLITE_DEBUG) && defined(__GNUC__) |
| 85632 | 86368 | __attribute__((aligned(8))) |
| 85633 | 86369 | #endif |
| 85634 | 86370 | = { |
| 85635 | 86371 | /* .u = */ {0}, |
| 86372 | + /* .z = */ (char*)0, |
| 86373 | + /* .n = */ (int)0, |
| 85636 | 86374 | /* .flags = */ (u16)MEM_Null, |
| 85637 | 86375 | /* .enc = */ (u8)0, |
| 85638 | 86376 | /* .eSubtype = */ (u8)0, |
| 85639 | | - /* .n = */ (int)0, |
| 85640 | | - /* .z = */ (char*)0, |
| 85641 | | - /* .zMalloc = */ (char*)0, |
| 86377 | + /* .db = */ (sqlite3*)0, |
| 85642 | 86378 | /* .szMalloc = */ (int)0, |
| 85643 | 86379 | /* .uTemp = */ (u32)0, |
| 85644 | | - /* .db = */ (sqlite3*)0, |
| 86380 | + /* .zMalloc = */ (char*)0, |
| 85645 | 86381 | /* .xDel = */ (void(*)(void*))0, |
| 85646 | 86382 | #ifdef SQLITE_DEBUG |
| 85647 | 86383 | /* .pScopyFrom = */ (Mem*)0, |
| 85648 | 86384 | /* .mScopyFlags= */ 0, |
| 85649 | 86385 | #endif |
| | @@ -86121,11 +86857,14 @@ |
| 86121 | 86857 | case SQLITE_INTEGER: { |
| 86122 | 86858 | rc = sqlite3_bind_int64(pStmt, i, pValue->u.i); |
| 86123 | 86859 | break; |
| 86124 | 86860 | } |
| 86125 | 86861 | case SQLITE_FLOAT: { |
| 86126 | | - rc = sqlite3_bind_double(pStmt, i, pValue->u.r); |
| 86862 | + assert( pValue->flags & (MEM_Real|MEM_IntReal) ); |
| 86863 | + rc = sqlite3_bind_double(pStmt, i, |
| 86864 | + (pValue->flags & MEM_Real) ? pValue->u.r : (double)pValue->u.i |
| 86865 | + ); |
| 86127 | 86866 | break; |
| 86128 | 86867 | } |
| 86129 | 86868 | case SQLITE_BLOB: { |
| 86130 | 86869 | if( pValue->flags & MEM_Zero ){ |
| 86131 | 86870 | rc = sqlite3_bind_zeroblob(pStmt, i, pValue->u.nZero); |
| | @@ -87537,11 +88276,10 @@ |
| 87537 | 88276 | */ |
| 87538 | 88277 | static u64 filterHash(const Mem *aMem, const Op *pOp){ |
| 87539 | 88278 | int i, mx; |
| 87540 | 88279 | u64 h = 0; |
| 87541 | 88280 | |
| 87542 | | - i = pOp->p3; |
| 87543 | 88281 | assert( pOp->p4type==P4_INT32 ); |
| 87544 | 88282 | for(i=pOp->p3, mx=i+pOp->p4.i; i<mx; i++){ |
| 87545 | 88283 | const Mem *p = &aMem[i]; |
| 87546 | 88284 | if( p->flags & (MEM_Int|MEM_IntReal) ){ |
| 87547 | 88285 | h += p->u.i; |
| | @@ -87852,14 +88590,18 @@ |
| 87852 | 88590 | jump_to_p2: |
| 87853 | 88591 | pOp = &aOp[pOp->p2 - 1]; |
| 87854 | 88592 | break; |
| 87855 | 88593 | } |
| 87856 | 88594 | |
| 87857 | | -/* Opcode: Return P1 * * * * |
| 88595 | +/* Opcode: Return P1 * P3 * * |
| 87858 | 88596 | ** |
| 87859 | 88597 | ** Jump to the next instruction after the address in register P1. After |
| 87860 | 88598 | ** the jump, register P1 becomes undefined. |
| 88599 | +** |
| 88600 | +** P3 is not used by the byte-code engine. However, the code generator |
| 88601 | +** sets P3 to address of the associated OP_BeginSubrtn opcode, if there is |
| 88602 | +** one. |
| 87861 | 88603 | */ |
| 87862 | 88604 | case OP_Return: { /* in1 */ |
| 87863 | 88605 | pIn1 = &aMem[pOp->p1]; |
| 87864 | 88606 | assert( pIn1->flags==MEM_Int ); |
| 87865 | 88607 | pOp = &aOp[pIn1->u.i]; |
| | @@ -88043,15 +88785,26 @@ |
| 88043 | 88785 | rc = p->rc ? SQLITE_ERROR : SQLITE_DONE; |
| 88044 | 88786 | } |
| 88045 | 88787 | goto vdbe_return; |
| 88046 | 88788 | } |
| 88047 | 88789 | |
| 88790 | +/* Opcode: BeginSubrtn P1 P2 * * * |
| 88791 | +** Synopsis: r[P2]=P1 |
| 88792 | +** |
| 88793 | +** Mark the beginning of a subroutine by loading the integer value P1 |
| 88794 | +** into register r[P2]. The P2 register is used to store the return |
| 88795 | +** address of the subroutine call. |
| 88796 | +** |
| 88797 | +** This opcode is identical to OP_Integer. It has a different name |
| 88798 | +** only to make the byte code easier to read and verify. |
| 88799 | +*/ |
| 88048 | 88800 | /* Opcode: Integer P1 P2 * * * |
| 88049 | 88801 | ** Synopsis: r[P2]=P1 |
| 88050 | 88802 | ** |
| 88051 | 88803 | ** The 32-bit integer value P1 is written into register P2. |
| 88052 | 88804 | */ |
| 88805 | +case OP_BeginSubrtn: |
| 88053 | 88806 | case OP_Integer: { /* out2 */ |
| 88054 | 88807 | pOut = out2Prerelease(p, pOp); |
| 88055 | 88808 | pOut->u.i = pOp->p1; |
| 88056 | 88809 | break; |
| 88057 | 88810 | } |
| | @@ -89020,11 +89773,11 @@ |
| 89020 | 89773 | testcase( pIn1->flags & MEM_Real ); |
| 89021 | 89774 | testcase( pIn1->flags & MEM_IntReal ); |
| 89022 | 89775 | sqlite3VdbeMemStringify(pIn1, encoding, 1); |
| 89023 | 89776 | testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) ); |
| 89024 | 89777 | flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask); |
| 89025 | | - if( NEVER(pIn1==pIn3) ) flags3 = flags1 | MEM_Str; |
| 89778 | + if( pIn1==pIn3 ) flags3 = flags1 | MEM_Str; |
| 89026 | 89779 | } |
| 89027 | 89780 | if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){ |
| 89028 | 89781 | testcase( pIn3->flags & MEM_Int ); |
| 89029 | 89782 | testcase( pIn3->flags & MEM_Real ); |
| 89030 | 89783 | testcase( pIn3->flags & MEM_IntReal ); |
| | @@ -89488,14 +90241,22 @@ |
| 89488 | 90241 | case OP_Offset: { /* out3 */ |
| 89489 | 90242 | VdbeCursor *pC; /* The VDBE cursor */ |
| 89490 | 90243 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 89491 | 90244 | pC = p->apCsr[pOp->p1]; |
| 89492 | 90245 | pOut = &p->aMem[pOp->p3]; |
| 89493 | | - if( NEVER(pC==0) || pC->eCurType!=CURTYPE_BTREE ){ |
| 90246 | + if( pC==0 || pC->eCurType!=CURTYPE_BTREE ){ |
| 89494 | 90247 | sqlite3VdbeMemSetNull(pOut); |
| 89495 | 90248 | }else{ |
| 89496 | | - sqlite3VdbeMemSetInt64(pOut, sqlite3BtreeOffset(pC->uc.pCursor)); |
| 90249 | + if( pC->deferredMoveto ){ |
| 90250 | + rc = sqlite3VdbeFinishMoveto(pC); |
| 90251 | + if( rc ) goto abort_due_to_error; |
| 90252 | + } |
| 90253 | + if( sqlite3BtreeEof(pC->uc.pCursor) ){ |
| 90254 | + sqlite3VdbeMemSetNull(pOut); |
| 90255 | + }else{ |
| 90256 | + sqlite3VdbeMemSetInt64(pOut, sqlite3BtreeOffset(pC->uc.pCursor)); |
| 90257 | + } |
| 89497 | 90258 | } |
| 89498 | 90259 | break; |
| 89499 | 90260 | } |
| 89500 | 90261 | #endif /* SQLITE_ENABLE_OFFSET_SQL_FUNC */ |
| 89501 | 90262 | |
| | @@ -89520,11 +90281,11 @@ |
| 89520 | 90281 | ** skipped for length() and all content loading can be skipped for typeof(). |
| 89521 | 90282 | */ |
| 89522 | 90283 | case OP_Column: { |
| 89523 | 90284 | u32 p2; /* column number to retrieve */ |
| 89524 | 90285 | VdbeCursor *pC; /* The VDBE cursor */ |
| 89525 | | - BtCursor *pCrsr; /* The BTree cursor */ |
| 90286 | + BtCursor *pCrsr; /* The B-Tree cursor corresponding to pC */ |
| 89526 | 90287 | u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */ |
| 89527 | 90288 | int len; /* The length of the serialized data for the column */ |
| 89528 | 90289 | int i; /* Loop counter */ |
| 89529 | 90290 | Mem *pDest; /* Where to write the extracted value */ |
| 89530 | 90291 | Mem sMem; /* For storing the record being decoded */ |
| | @@ -89534,23 +90295,15 @@ |
| 89534 | 90295 | u64 offset64; /* 64-bit offset */ |
| 89535 | 90296 | u32 t; /* A type code from the record header */ |
| 89536 | 90297 | Mem *pReg; /* PseudoTable input register */ |
| 89537 | 90298 | |
| 89538 | 90299 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 90300 | + assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) ); |
| 89539 | 90301 | pC = p->apCsr[pOp->p1]; |
| 89540 | | - assert( pC!=0 ); |
| 89541 | 90302 | p2 = (u32)pOp->p2; |
| 89542 | 90303 | |
| 89543 | | - /* If the cursor cache is stale (meaning it is not currently point at |
| 89544 | | - ** the correct row) then bring it up-to-date by doing the necessary |
| 89545 | | - ** B-Tree seek. */ |
| 89546 | | - rc = sqlite3VdbeCursorMoveto(&pC, &p2); |
| 89547 | | - if( rc ) goto abort_due_to_error; |
| 89548 | | - |
| 89549 | | - assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) ); |
| 89550 | | - pDest = &aMem[pOp->p3]; |
| 89551 | | - memAboutToChange(p, pDest); |
| 90304 | +op_column_restart: |
| 89552 | 90305 | assert( pC!=0 ); |
| 89553 | 90306 | assert( p2<(u32)pC->nField ); |
| 89554 | 90307 | aOffset = pC->aOffset; |
| 89555 | 90308 | assert( aOffset==pC->aType+pC->nField ); |
| 89556 | 90309 | assert( pC->eCurType!=CURTYPE_VTAB ); |
| | @@ -89567,30 +90320,43 @@ |
| 89567 | 90320 | assert( pReg->flags & MEM_Blob ); |
| 89568 | 90321 | assert( memIsValid(pReg) ); |
| 89569 | 90322 | pC->payloadSize = pC->szRow = pReg->n; |
| 89570 | 90323 | pC->aRow = (u8*)pReg->z; |
| 89571 | 90324 | }else{ |
| 90325 | + pDest = &aMem[pOp->p3]; |
| 90326 | + memAboutToChange(p, pDest); |
| 89572 | 90327 | sqlite3VdbeMemSetNull(pDest); |
| 89573 | 90328 | goto op_column_out; |
| 89574 | 90329 | } |
| 89575 | 90330 | }else{ |
| 89576 | 90331 | pCrsr = pC->uc.pCursor; |
| 90332 | + if( pC->deferredMoveto ){ |
| 90333 | + u32 iMap; |
| 90334 | + assert( !pC->isEphemeral ); |
| 90335 | + if( pC->ub.aAltMap && (iMap = pC->ub.aAltMap[1+p2])>0 ){ |
| 90336 | + pC = pC->pAltCursor; |
| 90337 | + p2 = iMap - 1; |
| 90338 | + goto op_column_restart; |
| 90339 | + } |
| 90340 | + rc = sqlite3VdbeFinishMoveto(pC); |
| 90341 | + if( rc ) goto abort_due_to_error; |
| 90342 | + }else if( sqlite3BtreeCursorHasMoved(pCrsr) ){ |
| 90343 | + rc = sqlite3VdbeHandleMovedCursor(pC); |
| 90344 | + if( rc ) goto abort_due_to_error; |
| 90345 | + goto op_column_restart; |
| 90346 | + } |
| 89577 | 90347 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 89578 | 90348 | assert( pCrsr ); |
| 89579 | 90349 | assert( sqlite3BtreeCursorIsValid(pCrsr) ); |
| 89580 | 90350 | pC->payloadSize = sqlite3BtreePayloadSize(pCrsr); |
| 89581 | 90351 | pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &pC->szRow); |
| 89582 | 90352 | assert( pC->szRow<=pC->payloadSize ); |
| 89583 | 90353 | assert( pC->szRow<=65536 ); /* Maximum page size is 64KiB */ |
| 89584 | | - if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 89585 | | - goto too_big; |
| 89586 | | - } |
| 89587 | 90354 | } |
| 89588 | 90355 | pC->cacheStatus = p->cacheCtr; |
| 89589 | 90356 | pC->iHdrOffset = getVarint32(pC->aRow, aOffset[0]); |
| 89590 | 90357 | pC->nHdrParsed = 0; |
| 89591 | | - |
| 89592 | 90358 | |
| 89593 | 90359 | if( pC->szRow<aOffset[0] ){ /*OPTIMIZATION-IF-FALSE*/ |
| 89594 | 90360 | /* pC->aRow does not have to hold the entire row, but it does at least |
| 89595 | 90361 | ** need to cover the header of the record. If pC->aRow does not contain |
| 89596 | 90362 | ** the complete header, then set it to zero, forcing the header to be |
| | @@ -89627,10 +90393,14 @@ |
| 89627 | 90393 | zData = pC->aRow; |
| 89628 | 90394 | assert( pC->nHdrParsed<=p2 ); /* Conditional skipped */ |
| 89629 | 90395 | testcase( aOffset[0]==0 ); |
| 89630 | 90396 | goto op_column_read_header; |
| 89631 | 90397 | } |
| 90398 | + }else if( sqlite3BtreeCursorHasMoved(pC->uc.pCursor) ){ |
| 90399 | + rc = sqlite3VdbeHandleMovedCursor(pC); |
| 90400 | + if( rc ) goto abort_due_to_error; |
| 90401 | + goto op_column_restart; |
| 89632 | 90402 | } |
| 89633 | 90403 | |
| 89634 | 90404 | /* Make sure at least the first p2+1 entries of the header have been |
| 89635 | 90405 | ** parsed and valid information is in aOffset[] and pC->aType[]. |
| 89636 | 90406 | */ |
| | @@ -89695,10 +90465,12 @@ |
| 89695 | 90465 | /* If after trying to extract new entries from the header, nHdrParsed is |
| 89696 | 90466 | ** still not up to p2, that means that the record has fewer than p2 |
| 89697 | 90467 | ** columns. So the result will be either the default value or a NULL. |
| 89698 | 90468 | */ |
| 89699 | 90469 | if( pC->nHdrParsed<=p2 ){ |
| 90470 | + pDest = &aMem[pOp->p3]; |
| 90471 | + memAboutToChange(p, pDest); |
| 89700 | 90472 | if( pOp->p4type==P4_MEM ){ |
| 89701 | 90473 | sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static); |
| 89702 | 90474 | }else{ |
| 89703 | 90475 | sqlite3VdbeMemSetNull(pDest); |
| 89704 | 90476 | } |
| | @@ -89712,10 +90484,12 @@ |
| 89712 | 90484 | ** reach this point if aOffset[p2], aOffset[p2+1], and pC->aType[p2] are |
| 89713 | 90485 | ** all valid. |
| 89714 | 90486 | */ |
| 89715 | 90487 | assert( p2<pC->nHdrParsed ); |
| 89716 | 90488 | assert( rc==SQLITE_OK ); |
| 90489 | + pDest = &aMem[pOp->p3]; |
| 90490 | + memAboutToChange(p, pDest); |
| 89717 | 90491 | assert( sqlite3VdbeCheckMemInvariants(pDest) ); |
| 89718 | 90492 | if( VdbeMemDynamic(pDest) ){ |
| 89719 | 90493 | sqlite3VdbeMemSetNull(pDest); |
| 89720 | 90494 | } |
| 89721 | 90495 | assert( t==pC->aType[p2] ); |
| | @@ -89732,10 +90506,11 @@ |
| 89732 | 90506 | */ |
| 89733 | 90507 | static const u16 aFlag[] = { MEM_Blob, MEM_Str|MEM_Term }; |
| 89734 | 90508 | pDest->n = len = (t-12)/2; |
| 89735 | 90509 | pDest->enc = encoding; |
| 89736 | 90510 | if( pDest->szMalloc < len+2 ){ |
| 90511 | + if( len>db->aLimit[SQLITE_LIMIT_LENGTH] ) goto too_big; |
| 89737 | 90512 | pDest->flags = MEM_Null; |
| 89738 | 90513 | if( sqlite3VdbeMemGrow(pDest, len+2, 0) ) goto no_mem; |
| 89739 | 90514 | }else{ |
| 89740 | 90515 | pDest->z = pDest->zMalloc; |
| 89741 | 90516 | } |
| | @@ -89764,10 +90539,11 @@ |
| 89764 | 90539 | ** as that array is 256 bytes long (plenty for VdbeMemPrettyPrint()) |
| 89765 | 90540 | ** and it begins with a bunch of zeros. |
| 89766 | 90541 | */ |
| 89767 | 90542 | sqlite3VdbeSerialGet((u8*)sqlite3CtypeMap, t, pDest); |
| 89768 | 90543 | }else{ |
| 90544 | + if( len>db->aLimit[SQLITE_LIMIT_LENGTH] ) goto too_big; |
| 89769 | 90545 | rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest); |
| 89770 | 90546 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 89771 | 90547 | sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest); |
| 89772 | 90548 | pDest->flags &= ~MEM_Ephem; |
| 89773 | 90549 | } |
| | @@ -89846,10 +90622,12 @@ |
| 89846 | 90622 | case COLTYPE_TEXT: { |
| 89847 | 90623 | if( (pIn1->flags & MEM_Str)==0 ) goto vdbe_type_error; |
| 89848 | 90624 | break; |
| 89849 | 90625 | } |
| 89850 | 90626 | case COLTYPE_REAL: { |
| 90627 | + testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_Real ); |
| 90628 | + testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_IntReal ); |
| 89851 | 90629 | if( pIn1->flags & MEM_Int ){ |
| 89852 | 90630 | /* When applying REAL affinity, if the result is still an MEM_Int |
| 89853 | 90631 | ** that will fit in 6 bytes, then change the type to MEM_IntReal |
| 89854 | 90632 | ** so that we keep the high-resolution integer value but know that |
| 89855 | 90633 | ** the type really wants to be REAL. */ |
| | @@ -89863,11 +90641,11 @@ |
| 89863 | 90641 | }else{ |
| 89864 | 90642 | pIn1->u.r = (double)pIn1->u.i; |
| 89865 | 90643 | pIn1->flags |= MEM_Real; |
| 89866 | 90644 | pIn1->flags &= ~MEM_Int; |
| 89867 | 90645 | } |
| 89868 | | - }else if( (pIn1->flags & MEM_Real)==0 ){ |
| 90646 | + }else if( (pIn1->flags & (MEM_Real|MEM_IntReal))==0 ){ |
| 89869 | 90647 | goto vdbe_type_error; |
| 89870 | 90648 | } |
| 89871 | 90649 | break; |
| 89872 | 90650 | } |
| 89873 | 90651 | default: { |
| | @@ -89974,11 +90752,10 @@ |
| 89974 | 90752 | u32 serial_type; /* Type field */ |
| 89975 | 90753 | Mem *pData0; /* First field to be combined into the record */ |
| 89976 | 90754 | Mem *pLast; /* Last field of the record */ |
| 89977 | 90755 | int nField; /* Number of fields in the record */ |
| 89978 | 90756 | char *zAffinity; /* The affinity string for the record */ |
| 89979 | | - int file_format; /* File format to use for encoding */ |
| 89980 | 90757 | u32 len; /* Length of a field */ |
| 89981 | 90758 | u8 *zHdr; /* Where to write next byte of the header */ |
| 89982 | 90759 | u8 *zPayload; /* Where to write next byte of the payload */ |
| 89983 | 90760 | |
| 89984 | 90761 | /* Assuming the record contains N fields, the record format looks |
| | @@ -90003,11 +90780,10 @@ |
| 90003 | 90780 | zAffinity = pOp->p4.z; |
| 90004 | 90781 | assert( nField>0 && pOp->p2>0 && pOp->p2+nField<=(p->nMem+1 - p->nCursor)+1 ); |
| 90005 | 90782 | pData0 = &aMem[nField]; |
| 90006 | 90783 | nField = pOp->p2; |
| 90007 | 90784 | pLast = &pData0[nField-1]; |
| 90008 | | - file_format = p->minWriteFileFormat; |
| 90009 | 90785 | |
| 90010 | 90786 | /* Identify the output register */ |
| 90011 | 90787 | assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 ); |
| 90012 | 90788 | pOut = &aMem[pOp->p3]; |
| 90013 | 90789 | memAboutToChange(p, pOut); |
| | @@ -90102,14 +90878,14 @@ |
| 90102 | 90878 | } |
| 90103 | 90879 | nHdr++; |
| 90104 | 90880 | testcase( uu==127 ); testcase( uu==128 ); |
| 90105 | 90881 | testcase( uu==32767 ); testcase( uu==32768 ); |
| 90106 | 90882 | testcase( uu==8388607 ); testcase( uu==8388608 ); |
| 90107 | | - testcase( uu==2147483647 ); testcase( uu==2147483648 ); |
| 90883 | + testcase( uu==2147483647 ); testcase( uu==2147483648LL ); |
| 90108 | 90884 | testcase( uu==140737488355327LL ); testcase( uu==140737488355328LL ); |
| 90109 | 90885 | if( uu<=127 ){ |
| 90110 | | - if( (i&1)==i && file_format>=4 ){ |
| 90886 | + if( (i&1)==i && p->minWriteFileFormat>=4 ){ |
| 90111 | 90887 | pRec->uTemp = 8+(u32)uu; |
| 90112 | 90888 | }else{ |
| 90113 | 90889 | nData++; |
| 90114 | 90890 | pRec->uTemp = 1; |
| 90115 | 90891 | } |
| | @@ -92568,10 +93344,14 @@ |
| 92568 | 93344 | /* Opcode: NullRow P1 * * * * |
| 92569 | 93345 | ** |
| 92570 | 93346 | ** Move the cursor P1 to a null row. Any OP_Column operations |
| 92571 | 93347 | ** that occur while the cursor is on the null row will always |
| 92572 | 93348 | ** write a NULL. |
| 93349 | +** |
| 93350 | +** Or, if P1 is a Pseudo-Cursor (a cursor opened using OP_OpenPseudo) |
| 93351 | +** just reset the cache for that cursor. This causes the row of |
| 93352 | +** content held by the pseudo-cursor to be reparsed. |
| 92573 | 93353 | */ |
| 92574 | 93354 | case OP_NullRow: { |
| 92575 | 93355 | VdbeCursor *pC; |
| 92576 | 93356 | |
| 92577 | 93357 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| | @@ -92747,11 +93527,11 @@ |
| 92747 | 93527 | VdbeBranchTaken(res!=0,2); |
| 92748 | 93528 | if( res ) goto jump_to_p2; |
| 92749 | 93529 | break; |
| 92750 | 93530 | } |
| 92751 | 93531 | |
| 92752 | | -/* Opcode: Next P1 P2 P3 P4 P5 |
| 93532 | +/* Opcode: Next P1 P2 P3 * P5 |
| 92753 | 93533 | ** |
| 92754 | 93534 | ** Advance cursor P1 so that it points to the next key/data pair in its |
| 92755 | 93535 | ** table or index. If there are no more key/value pairs then fall through |
| 92756 | 93536 | ** to the following instruction. But if the cursor advance was successful, |
| 92757 | 93537 | ** jump immediately to P2. |
| | @@ -92766,19 +93546,16 @@ |
| 92766 | 93546 | ** The P3 value is a hint to the btree implementation. If P3==1, that |
| 92767 | 93547 | ** means P1 is an SQL index and that this instruction could have been |
| 92768 | 93548 | ** omitted if that index had been unique. P3 is usually 0. P3 is |
| 92769 | 93549 | ** always either 0 or 1. |
| 92770 | 93550 | ** |
| 92771 | | -** P4 is always of type P4_ADVANCE. The function pointer points to |
| 92772 | | -** sqlite3BtreeNext(). |
| 92773 | | -** |
| 92774 | 93551 | ** If P5 is positive and the jump is taken, then event counter |
| 92775 | 93552 | ** number P5-1 in the prepared statement is incremented. |
| 92776 | 93553 | ** |
| 92777 | 93554 | ** See also: Prev |
| 92778 | 93555 | */ |
| 92779 | | -/* Opcode: Prev P1 P2 P3 P4 P5 |
| 93556 | +/* Opcode: Prev P1 P2 P3 * P5 |
| 92780 | 93557 | ** |
| 92781 | 93558 | ** Back up cursor P1 so that it points to the previous key/data pair in its |
| 92782 | 93559 | ** table or index. If there is no previous key/value pairs then fall through |
| 92783 | 93560 | ** to the following instruction. But if the cursor backup was successful, |
| 92784 | 93561 | ** jump immediately to P2. |
| | @@ -92794,13 +93571,10 @@ |
| 92794 | 93571 | ** The P3 value is a hint to the btree implementation. If P3==1, that |
| 92795 | 93572 | ** means P1 is an SQL index and that this instruction could have been |
| 92796 | 93573 | ** omitted if that index had been unique. P3 is usually 0. P3 is |
| 92797 | 93574 | ** always either 0 or 1. |
| 92798 | 93575 | ** |
| 92799 | | -** P4 is always of type P4_ADVANCE. The function pointer points to |
| 92800 | | -** sqlite3BtreePrevious(). |
| 92801 | | -** |
| 92802 | 93576 | ** If P5 is positive and the jump is taken, then event counter |
| 92803 | 93577 | ** number P5-1 in the prepared statement is incremented. |
| 92804 | 93578 | */ |
| 92805 | 93579 | /* Opcode: SorterNext P1 P2 * * P5 |
| 92806 | 93580 | ** |
| | @@ -92814,34 +93588,37 @@ |
| 92814 | 93588 | |
| 92815 | 93589 | pC = p->apCsr[pOp->p1]; |
| 92816 | 93590 | assert( isSorter(pC) ); |
| 92817 | 93591 | rc = sqlite3VdbeSorterNext(db, pC); |
| 92818 | 93592 | goto next_tail; |
| 93593 | + |
| 92819 | 93594 | case OP_Prev: /* jump */ |
| 93595 | + assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 93596 | + assert( pOp->p5<ArraySize(p->aCounter) ); |
| 93597 | + pC = p->apCsr[pOp->p1]; |
| 93598 | + assert( pC!=0 ); |
| 93599 | + assert( pC->deferredMoveto==0 ); |
| 93600 | + assert( pC->eCurType==CURTYPE_BTREE ); |
| 93601 | + assert( pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE |
| 93602 | + || pC->seekOp==OP_Last || pC->seekOp==OP_IfNoHope |
| 93603 | + || pC->seekOp==OP_NullRow); |
| 93604 | + rc = sqlite3BtreePrevious(pC->uc.pCursor, pOp->p3); |
| 93605 | + goto next_tail; |
| 93606 | + |
| 92820 | 93607 | case OP_Next: /* jump */ |
| 92821 | 93608 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 92822 | 93609 | assert( pOp->p5<ArraySize(p->aCounter) ); |
| 92823 | 93610 | pC = p->apCsr[pOp->p1]; |
| 92824 | 93611 | assert( pC!=0 ); |
| 92825 | 93612 | assert( pC->deferredMoveto==0 ); |
| 92826 | 93613 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 92827 | | - assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 92828 | | - assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious ); |
| 92829 | | - |
| 92830 | | - /* The Next opcode is only used after SeekGT, SeekGE, Rewind, and Found. |
| 92831 | | - ** The Prev opcode is only used after SeekLT, SeekLE, and Last. */ |
| 92832 | | - assert( pOp->opcode!=OP_Next |
| 92833 | | - || pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE |
| 93614 | + assert( pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE |
| 92834 | 93615 | || pC->seekOp==OP_Rewind || pC->seekOp==OP_Found |
| 92835 | 93616 | || pC->seekOp==OP_NullRow|| pC->seekOp==OP_SeekRowid |
| 92836 | 93617 | || pC->seekOp==OP_IfNoHope); |
| 92837 | | - assert( pOp->opcode!=OP_Prev |
| 92838 | | - || pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE |
| 92839 | | - || pC->seekOp==OP_Last || pC->seekOp==OP_IfNoHope |
| 92840 | | - || pC->seekOp==OP_NullRow); |
| 93618 | + rc = sqlite3BtreeNext(pC->uc.pCursor, pOp->p3); |
| 92841 | 93619 | |
| 92842 | | - rc = pOp->p4.xAdvance(pC->uc.pCursor, pOp->p3); |
| 92843 | 93620 | next_tail: |
| 92844 | 93621 | pC->cacheStatus = CACHE_STALE; |
| 92845 | 93622 | VdbeBranchTaken(rc==SQLITE_OK,2); |
| 92846 | 93623 | if( rc==SQLITE_OK ){ |
| 92847 | 93624 | pC->nullRow = 0; |
| | @@ -93055,10 +93832,11 @@ |
| 93055 | 93832 | assert( pTabCur->uc.pCursor!=0 ); |
| 93056 | 93833 | assert( pTabCur->isTable ); |
| 93057 | 93834 | pTabCur->nullRow = 0; |
| 93058 | 93835 | pTabCur->movetoTarget = rowid; |
| 93059 | 93836 | pTabCur->deferredMoveto = 1; |
| 93837 | + pTabCur->cacheStatus = CACHE_STALE; |
| 93060 | 93838 | assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 ); |
| 93061 | 93839 | assert( !pTabCur->isEphemeral ); |
| 93062 | 93840 | pTabCur->ub.aAltMap = pOp->p4.ai; |
| 93063 | 93841 | assert( !pC->isEphemeral ); |
| 93064 | 93842 | pTabCur->pAltCursor = pC; |
| | @@ -93189,11 +93967,11 @@ |
| 93189 | 93967 | } |
| 93190 | 93968 | sqlite3VdbeMemInit(&m, db, 0); |
| 93191 | 93969 | rc = sqlite3VdbeMemFromBtreeZeroOffset(pCur, (u32)nCellKey, &m); |
| 93192 | 93970 | if( rc ) goto abort_due_to_error; |
| 93193 | 93971 | res = sqlite3VdbeRecordCompareWithSkip(m.n, m.z, &r, 0); |
| 93194 | | - sqlite3VdbeMemRelease(&m); |
| 93972 | + sqlite3VdbeMemReleaseMalloc(&m); |
| 93195 | 93973 | } |
| 93196 | 93974 | /* End of inlined sqlite3VdbeIdxKeyCompare() */ |
| 93197 | 93975 | |
| 93198 | 93976 | assert( (OP_IdxLE&1)==(OP_IdxLT&1) && (OP_IdxGE&1)==(OP_IdxGT&1) ); |
| 93199 | 93977 | if( (pOp->opcode&1)==(OP_IdxLT&1) ){ |
| | @@ -94592,10 +95370,38 @@ |
| 94592 | 95370 | goto no_mem; |
| 94593 | 95371 | } |
| 94594 | 95372 | break; |
| 94595 | 95373 | } |
| 94596 | 95374 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 95375 | + |
| 95376 | +#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 95377 | +/* Opcode: VInitIn P1 P2 P3 * * |
| 95378 | +** Synopsis: r[P2]=ValueList(P1,P3) |
| 95379 | +** |
| 95380 | +** Set register P2 to be a pointer to a ValueList object for cursor P1 |
| 95381 | +** with cache register P3 and output register P3+1. This ValueList object |
| 95382 | +** can be used as the first argument to sqlite3_vtab_in_first() and |
| 95383 | +** sqlite3_vtab_in_next() to extract all of the values stored in the P1 |
| 95384 | +** cursor. Register P3 is used to hold the values returned by |
| 95385 | +** sqlite3_vtab_in_first() and sqlite3_vtab_in_next(). |
| 95386 | +*/ |
| 95387 | +case OP_VInitIn: { /* out2 */ |
| 95388 | + VdbeCursor *pC; /* The cursor containing the RHS values */ |
| 95389 | + ValueList *pRhs; /* New ValueList object to put in reg[P2] */ |
| 95390 | + |
| 95391 | + pC = p->apCsr[pOp->p1]; |
| 95392 | + pRhs = sqlite3_malloc64( sizeof(*pRhs) ); |
| 95393 | + if( pRhs==0 ) goto no_mem; |
| 95394 | + pRhs->pCsr = pC->uc.pCursor; |
| 95395 | + pRhs->pOut = &aMem[pOp->p3]; |
| 95396 | + pOut = out2Prerelease(p, pOp); |
| 95397 | + pOut->flags = MEM_Null; |
| 95398 | + sqlite3VdbeMemSetPointer(pOut, pRhs, "ValueList", sqlite3_free); |
| 95399 | + break; |
| 95400 | +} |
| 95401 | +#endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 95402 | + |
| 94597 | 95403 | |
| 94598 | 95404 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 94599 | 95405 | /* Opcode: VFilter P1 P2 P3 P4 * |
| 94600 | 95406 | ** Synopsis: iplan=r[P3] zplan='P4' |
| 94601 | 95407 | ** |
| | @@ -95579,14 +96385,13 @@ |
| 95579 | 96385 | wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */ |
| 95580 | 96386 | |
| 95581 | 96387 | sqlite3_mutex_enter(db->mutex); |
| 95582 | 96388 | |
| 95583 | 96389 | pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob)); |
| 95584 | | - do { |
| 95585 | | - memset(&sParse, 0, sizeof(Parse)); |
| 96390 | + while(1){ |
| 96391 | + sqlite3ParseObjectInit(&sParse,db); |
| 95586 | 96392 | if( !pBlob ) goto blob_open_out; |
| 95587 | | - sParse.db = db; |
| 95588 | 96393 | sqlite3DbFree(db, zErr); |
| 95589 | 96394 | zErr = 0; |
| 95590 | 96395 | |
| 95591 | 96396 | sqlite3BtreeEnterAll(db); |
| 95592 | 96397 | pTab = sqlite3LocateTable(&sParse, 0, zTable, zDb); |
| | @@ -95759,11 +96564,13 @@ |
| 95759 | 96564 | sqlite3BtreeLeaveAll(db); |
| 95760 | 96565 | if( db->mallocFailed ){ |
| 95761 | 96566 | goto blob_open_out; |
| 95762 | 96567 | } |
| 95763 | 96568 | rc = blobSeekToRow(pBlob, iRow, &zErr); |
| 95764 | | - } while( (++nAttempt)<SQLITE_MAX_SCHEMA_RETRY && rc==SQLITE_SCHEMA ); |
| 96569 | + if( (++nAttempt)>=SQLITE_MAX_SCHEMA_RETRY || rc!=SQLITE_SCHEMA ) break; |
| 96570 | + sqlite3ParseObjectReset(&sParse); |
| 96571 | + } |
| 95765 | 96572 | |
| 95766 | 96573 | blob_open_out: |
| 95767 | 96574 | if( rc==SQLITE_OK && db->mallocFailed==0 ){ |
| 95768 | 96575 | *ppBlob = (sqlite3_blob *)pBlob; |
| 95769 | 96576 | }else{ |
| | @@ -95770,11 +96577,11 @@ |
| 95770 | 96577 | if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt); |
| 95771 | 96578 | sqlite3DbFree(db, pBlob); |
| 95772 | 96579 | } |
| 95773 | 96580 | sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr); |
| 95774 | 96581 | sqlite3DbFree(db, zErr); |
| 95775 | | - sqlite3ParserReset(&sParse); |
| 96582 | + sqlite3ParseObjectReset(&sParse); |
| 95776 | 96583 | rc = sqlite3ApiExit(db, rc); |
| 95777 | 96584 | sqlite3_mutex_leave(db->mutex); |
| 95778 | 96585 | return rc; |
| 95779 | 96586 | } |
| 95780 | 96587 | |
| | @@ -99319,10 +100126,13 @@ |
| 99319 | 100126 | } |
| 99320 | 100127 | return rc; |
| 99321 | 100128 | } |
| 99322 | 100129 | |
| 99323 | 100130 | |
| 100131 | +/* Forward reference */ |
| 100132 | +static int memjrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size); |
| 100133 | + |
| 99324 | 100134 | /* |
| 99325 | 100135 | ** Write data to the file. |
| 99326 | 100136 | */ |
| 99327 | 100137 | static int memjrnlWrite( |
| 99328 | 100138 | sqlite3_file *pJfd, /* The journal file into which to write */ |
| | @@ -99349,26 +100159,24 @@ |
| 99349 | 100159 | /* An in-memory journal file should only ever be appended to. Random |
| 99350 | 100160 | ** access writes are not required. The only exception to this is when |
| 99351 | 100161 | ** the in-memory journal is being used by a connection using the |
| 99352 | 100162 | ** atomic-write optimization. In this case the first 28 bytes of the |
| 99353 | 100163 | ** journal file may be written as part of committing the transaction. */ |
| 99354 | | - assert( iOfst==p->endpoint.iOffset || iOfst==0 ); |
| 99355 | | -#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \ |
| 99356 | | - || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE) |
| 100164 | + assert( iOfst<=p->endpoint.iOffset ); |
| 100165 | + if( iOfst>0 && iOfst!=p->endpoint.iOffset ){ |
| 100166 | + memjrnlTruncate(pJfd, iOfst); |
| 100167 | + } |
| 99357 | 100168 | if( iOfst==0 && p->pFirst ){ |
| 99358 | 100169 | assert( p->nChunkSize>iAmt ); |
| 99359 | 100170 | memcpy((u8*)p->pFirst->zChunk, zBuf, iAmt); |
| 99360 | | - }else |
| 99361 | | -#else |
| 99362 | | - assert( iOfst>0 || p->pFirst==0 ); |
| 99363 | | -#endif |
| 99364 | | - { |
| 100171 | + }else{ |
| 99365 | 100172 | while( nWrite>0 ){ |
| 99366 | 100173 | FileChunk *pChunk = p->endpoint.pChunk; |
| 99367 | 100174 | int iChunkOffset = (int)(p->endpoint.iOffset%p->nChunkSize); |
| 99368 | 100175 | int iSpace = MIN(nWrite, p->nChunkSize - iChunkOffset); |
| 99369 | 100176 | |
| 100177 | + assert( pChunk!=0 || iChunkOffset==0 ); |
| 99370 | 100178 | if( iChunkOffset==0 ){ |
| 99371 | 100179 | /* New chunk is required to extend the file. */ |
| 99372 | 100180 | FileChunk *pNew = sqlite3_malloc(fileChunkSize(p->nChunkSize)); |
| 99373 | 100181 | if( !pNew ){ |
| 99374 | 100182 | return SQLITE_IOERR_NOMEM_BKPT; |
| | @@ -99379,14 +100187,15 @@ |
| 99379 | 100187 | pChunk->pNext = pNew; |
| 99380 | 100188 | }else{ |
| 99381 | 100189 | assert( !p->pFirst ); |
| 99382 | 100190 | p->pFirst = pNew; |
| 99383 | 100191 | } |
| 99384 | | - p->endpoint.pChunk = pNew; |
| 100192 | + pChunk = p->endpoint.pChunk = pNew; |
| 99385 | 100193 | } |
| 99386 | 100194 | |
| 99387 | | - memcpy((u8*)p->endpoint.pChunk->zChunk + iChunkOffset, zWrite, iSpace); |
| 100195 | + assert( pChunk!=0 ); |
| 100196 | + memcpy((u8*)pChunk->zChunk + iChunkOffset, zWrite, iSpace); |
| 99388 | 100197 | zWrite += iSpace; |
| 99389 | 100198 | nWrite -= iSpace; |
| 99390 | 100199 | p->endpoint.iOffset += iSpace; |
| 99391 | 100200 | } |
| 99392 | 100201 | } |
| | @@ -100460,10 +101269,11 @@ |
| 100460 | 101269 | }else if( zTab ){ |
| 100461 | 101270 | sqlite3ErrorMsg(pParse, "%s: %s.%s", zErr, zTab, zCol); |
| 100462 | 101271 | }else{ |
| 100463 | 101272 | sqlite3ErrorMsg(pParse, "%s: %s", zErr, zCol); |
| 100464 | 101273 | } |
| 101274 | + sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr); |
| 100465 | 101275 | pParse->checkSchema = 1; |
| 100466 | 101276 | pTopNC->nNcErr++; |
| 100467 | 101277 | } |
| 100468 | 101278 | |
| 100469 | 101279 | /* If a column from a table in pSrcList is referenced, then record |
| | @@ -100568,11 +101378,12 @@ |
| 100568 | 101378 | */ |
| 100569 | 101379 | static void notValidImpl( |
| 100570 | 101380 | Parse *pParse, /* Leave error message here */ |
| 100571 | 101381 | NameContext *pNC, /* The name context */ |
| 100572 | 101382 | const char *zMsg, /* Type of error */ |
| 100573 | | - Expr *pExpr /* Invalidate this expression on error */ |
| 101383 | + Expr *pExpr, /* Invalidate this expression on error */ |
| 101384 | + Expr *pError /* Associate error with this expression */ |
| 100574 | 101385 | ){ |
| 100575 | 101386 | const char *zIn = "partial index WHERE clauses"; |
| 100576 | 101387 | if( pNC->ncFlags & NC_IdxExpr ) zIn = "index expressions"; |
| 100577 | 101388 | #ifndef SQLITE_OMIT_CHECK |
| 100578 | 101389 | else if( pNC->ncFlags & NC_IsCheck ) zIn = "CHECK constraints"; |
| | @@ -100580,14 +101391,15 @@ |
| 100580 | 101391 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 100581 | 101392 | else if( pNC->ncFlags & NC_GenCol ) zIn = "generated columns"; |
| 100582 | 101393 | #endif |
| 100583 | 101394 | sqlite3ErrorMsg(pParse, "%s prohibited in %s", zMsg, zIn); |
| 100584 | 101395 | if( pExpr ) pExpr->op = TK_NULL; |
| 101396 | + sqlite3RecordErrorOffsetOfExpr(pParse->db, pError); |
| 100585 | 101397 | } |
| 100586 | | -#define sqlite3ResolveNotValid(P,N,M,X,E) \ |
| 101398 | +#define sqlite3ResolveNotValid(P,N,M,X,E,R) \ |
| 100587 | 101399 | assert( ((X)&~(NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol))==0 ); \ |
| 100588 | | - if( ((N)->ncFlags & (X))!=0 ) notValidImpl(P,N,M,E); |
| 101400 | + if( ((N)->ncFlags & (X))!=0 ) notValidImpl(P,N,M,E,R); |
| 100589 | 101401 | |
| 100590 | 101402 | /* |
| 100591 | 101403 | ** Expression p should encode a floating point value between 1.0 and 0.0. |
| 100592 | 101404 | ** Return 1024 times this value. Or return -1 if p is not a floating point |
| 100593 | 101405 | ** value between 1.0 and 0.0. |
| | @@ -100718,11 +101530,11 @@ |
| 100718 | 101530 | }else{ |
| 100719 | 101531 | Expr *pLeft = pExpr->pLeft; |
| 100720 | 101532 | testcase( pNC->ncFlags & NC_IdxExpr ); |
| 100721 | 101533 | testcase( pNC->ncFlags & NC_GenCol ); |
| 100722 | 101534 | sqlite3ResolveNotValid(pParse, pNC, "the \".\" operator", |
| 100723 | | - NC_IdxExpr|NC_GenCol, 0); |
| 101535 | + NC_IdxExpr|NC_GenCol, 0, pExpr); |
| 100724 | 101536 | pRight = pExpr->pRight; |
| 100725 | 101537 | if( pRight->op==TK_ID ){ |
| 100726 | 101538 | zDb = 0; |
| 100727 | 101539 | }else{ |
| 100728 | 101540 | assert( pRight->op==TK_DOT ); |
| | @@ -100749,21 +101561,19 @@ |
| 100749 | 101561 | ExprList *pList = pExpr->x.pList; /* The argument list */ |
| 100750 | 101562 | int n = pList ? pList->nExpr : 0; /* Number of arguments */ |
| 100751 | 101563 | int no_such_func = 0; /* True if no such function exists */ |
| 100752 | 101564 | int wrong_num_args = 0; /* True if wrong number of arguments */ |
| 100753 | 101565 | int is_agg = 0; /* True if is an aggregate function */ |
| 100754 | | - int nId; /* Number of characters in function name */ |
| 100755 | 101566 | const char *zId; /* The function name. */ |
| 100756 | 101567 | FuncDef *pDef; /* Information about the function */ |
| 100757 | 101568 | u8 enc = ENC(pParse->db); /* The database encoding */ |
| 100758 | 101569 | int savedAllowFlags = (pNC->ncFlags & (NC_AllowAgg | NC_AllowWin)); |
| 100759 | 101570 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 100760 | 101571 | Window *pWin = (IsWindowFunc(pExpr) ? pExpr->y.pWin : 0); |
| 100761 | 101572 | #endif |
| 100762 | 101573 | assert( !ExprHasProperty(pExpr, EP_xIsSelect|EP_IntValue) ); |
| 100763 | 101574 | zId = pExpr->u.zToken; |
| 100764 | | - nId = sqlite3Strlen30(zId); |
| 100765 | 101575 | pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0); |
| 100766 | 101576 | if( pDef==0 ){ |
| 100767 | 101577 | pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0); |
| 100768 | 101578 | if( pDef==0 ){ |
| 100769 | 101579 | no_such_func = 1; |
| | @@ -100776,12 +101586,12 @@ |
| 100776 | 101586 | ExprSetProperty(pExpr, EP_Unlikely); |
| 100777 | 101587 | if( n==2 ){ |
| 100778 | 101588 | pExpr->iTable = exprProbability(pList->a[1].pExpr); |
| 100779 | 101589 | if( pExpr->iTable<0 ){ |
| 100780 | 101590 | sqlite3ErrorMsg(pParse, |
| 100781 | | - "second argument to likelihood() must be a " |
| 100782 | | - "constant between 0.0 and 1.0"); |
| 101591 | + "second argument to %#T() must be a " |
| 101592 | + "constant between 0.0 and 1.0", pExpr); |
| 100783 | 101593 | pNC->nNcErr++; |
| 100784 | 101594 | } |
| 100785 | 101595 | }else{ |
| 100786 | 101596 | /* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is |
| 100787 | 101597 | ** equivalent to likelihood(X, 0.0625). |
| | @@ -100798,12 +101608,12 @@ |
| 100798 | 101608 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 100799 | 101609 | { |
| 100800 | 101610 | int auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0,pDef->zName,0); |
| 100801 | 101611 | if( auth!=SQLITE_OK ){ |
| 100802 | 101612 | if( auth==SQLITE_DENY ){ |
| 100803 | | - sqlite3ErrorMsg(pParse, "not authorized to use function: %s", |
| 100804 | | - pDef->zName); |
| 101613 | + sqlite3ErrorMsg(pParse, "not authorized to use function: %#T", |
| 101614 | + pExpr); |
| 100805 | 101615 | pNC->nNcErr++; |
| 100806 | 101616 | } |
| 100807 | 101617 | pExpr->op = TK_NULL; |
| 100808 | 101618 | return WRC_Prune; |
| 100809 | 101619 | } |
| | @@ -100822,11 +101632,11 @@ |
| 100822 | 101632 | ** sqlite_version() that might change over time cannot be used |
| 100823 | 101633 | ** in an index or generated column. Curiously, they can be used |
| 100824 | 101634 | ** in a CHECK constraint. SQLServer, MySQL, and PostgreSQL all |
| 100825 | 101635 | ** all this. */ |
| 100826 | 101636 | sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions", |
| 100827 | | - NC_IdxExpr|NC_PartIdx|NC_GenCol, 0); |
| 101637 | + NC_IdxExpr|NC_PartIdx|NC_GenCol, 0, pExpr); |
| 100828 | 101638 | }else{ |
| 100829 | 101639 | assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */ |
| 100830 | 101640 | pExpr->op2 = pNC->ncFlags & NC_SelfRef; |
| 100831 | 101641 | if( pNC->ncFlags & NC_FromDDL ) ExprSetProperty(pExpr, EP_FromDDL); |
| 100832 | 101642 | } |
| | @@ -100835,11 +101645,11 @@ |
| 100835 | 101645 | && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0 |
| 100836 | 101646 | ){ |
| 100837 | 101647 | /* Internal-use-only functions are disallowed unless the |
| 100838 | 101648 | ** SQL is being compiled using sqlite3NestedParse() or |
| 100839 | 101649 | ** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be |
| 100840 | | - ** used to activate internal functionsn for testing purposes */ |
| 101650 | + ** used to activate internal functions for testing purposes */ |
| 100841 | 101651 | no_such_func = 1; |
| 100842 | 101652 | pDef = 0; |
| 100843 | 101653 | }else |
| 100844 | 101654 | if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0 |
| 100845 | 101655 | && !IN_RENAME_OBJECT |
| | @@ -100854,11 +101664,11 @@ |
| 100854 | 101664 | || (pDef->xValue==0 && pDef->xInverse==0) |
| 100855 | 101665 | || (pDef->xValue && pDef->xInverse && pDef->xSFunc && pDef->xFinalize) |
| 100856 | 101666 | ); |
| 100857 | 101667 | if( pDef && pDef->xValue==0 && pWin ){ |
| 100858 | 101668 | sqlite3ErrorMsg(pParse, |
| 100859 | | - "%.*s() may not be used as a window function", nId, zId |
| 101669 | + "%#T() may not be used as a window function", pExpr |
| 100860 | 101670 | ); |
| 100861 | 101671 | pNC->nNcErr++; |
| 100862 | 101672 | }else if( |
| 100863 | 101673 | (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) |
| 100864 | 101674 | || (is_agg && (pDef->funcFlags&SQLITE_FUNC_WINDOW) && !pWin) |
| | @@ -100868,38 +101678,38 @@ |
| 100868 | 101678 | if( (pDef->funcFlags & SQLITE_FUNC_WINDOW) || pWin ){ |
| 100869 | 101679 | zType = "window"; |
| 100870 | 101680 | }else{ |
| 100871 | 101681 | zType = "aggregate"; |
| 100872 | 101682 | } |
| 100873 | | - sqlite3ErrorMsg(pParse, "misuse of %s function %.*s()",zType,nId,zId); |
| 101683 | + sqlite3ErrorMsg(pParse, "misuse of %s function %#T()",zType,pExpr); |
| 100874 | 101684 | pNC->nNcErr++; |
| 100875 | 101685 | is_agg = 0; |
| 100876 | 101686 | } |
| 100877 | 101687 | #else |
| 100878 | 101688 | if( (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) ){ |
| 100879 | | - sqlite3ErrorMsg(pParse,"misuse of aggregate function %.*s()",nId,zId); |
| 101689 | + sqlite3ErrorMsg(pParse,"misuse of aggregate function %#T()",pExpr); |
| 100880 | 101690 | pNC->nNcErr++; |
| 100881 | 101691 | is_agg = 0; |
| 100882 | 101692 | } |
| 100883 | 101693 | #endif |
| 100884 | 101694 | else if( no_such_func && pParse->db->init.busy==0 |
| 100885 | 101695 | #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION |
| 100886 | 101696 | && pParse->explain==0 |
| 100887 | 101697 | #endif |
| 100888 | 101698 | ){ |
| 100889 | | - sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId); |
| 101699 | + sqlite3ErrorMsg(pParse, "no such function: %#T", pExpr); |
| 100890 | 101700 | pNC->nNcErr++; |
| 100891 | 101701 | }else if( wrong_num_args ){ |
| 100892 | | - sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()", |
| 100893 | | - nId, zId); |
| 101702 | + sqlite3ErrorMsg(pParse,"wrong number of arguments to function %#T()", |
| 101703 | + pExpr); |
| 100894 | 101704 | pNC->nNcErr++; |
| 100895 | 101705 | } |
| 100896 | 101706 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 100897 | 101707 | else if( is_agg==0 && ExprHasProperty(pExpr, EP_WinFunc) ){ |
| 100898 | 101708 | sqlite3ErrorMsg(pParse, |
| 100899 | | - "FILTER may not be used with non-aggregate %.*s()", |
| 100900 | | - nId, zId |
| 101709 | + "FILTER may not be used with non-aggregate %#T()", |
| 101710 | + pExpr |
| 100901 | 101711 | ); |
| 100902 | 101712 | pNC->nNcErr++; |
| 100903 | 101713 | } |
| 100904 | 101714 | #endif |
| 100905 | 101715 | if( is_agg ){ |
| | @@ -100980,11 +101790,11 @@ |
| 100980 | 101790 | testcase( pNC->ncFlags & NC_IsCheck ); |
| 100981 | 101791 | testcase( pNC->ncFlags & NC_PartIdx ); |
| 100982 | 101792 | testcase( pNC->ncFlags & NC_IdxExpr ); |
| 100983 | 101793 | testcase( pNC->ncFlags & NC_GenCol ); |
| 100984 | 101794 | if( pNC->ncFlags & NC_SelfRef ){ |
| 100985 | | - notValidImpl(pParse, pNC, "subqueries", pExpr); |
| 101795 | + notValidImpl(pParse, pNC, "subqueries", pExpr, pExpr); |
| 100986 | 101796 | }else{ |
| 100987 | 101797 | sqlite3WalkSelect(pWalker, pExpr->x.pSelect); |
| 100988 | 101798 | } |
| 100989 | 101799 | assert( pNC->nRef>=nRef ); |
| 100990 | 101800 | if( nRef!=pNC->nRef ){ |
| | @@ -100998,11 +101808,11 @@ |
| 100998 | 101808 | testcase( pNC->ncFlags & NC_IsCheck ); |
| 100999 | 101809 | testcase( pNC->ncFlags & NC_PartIdx ); |
| 101000 | 101810 | testcase( pNC->ncFlags & NC_IdxExpr ); |
| 101001 | 101811 | testcase( pNC->ncFlags & NC_GenCol ); |
| 101002 | 101812 | sqlite3ResolveNotValid(pParse, pNC, "parameters", |
| 101003 | | - NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol, pExpr); |
| 101813 | + NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol, pExpr, pExpr); |
| 101004 | 101814 | break; |
| 101005 | 101815 | } |
| 101006 | 101816 | case TK_IS: |
| 101007 | 101817 | case TK_ISNOT: { |
| 101008 | 101818 | Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight); |
| | @@ -101050,15 +101860,17 @@ |
| 101050 | 101860 | testcase( pExpr->op==TK_GE ); |
| 101051 | 101861 | testcase( pExpr->op==TK_IS ); |
| 101052 | 101862 | testcase( pExpr->op==TK_ISNOT ); |
| 101053 | 101863 | testcase( pExpr->op==TK_BETWEEN ); |
| 101054 | 101864 | sqlite3ErrorMsg(pParse, "row value misused"); |
| 101865 | + sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr); |
| 101055 | 101866 | } |
| 101056 | 101867 | break; |
| 101057 | 101868 | } |
| 101058 | 101869 | } |
| 101059 | | - return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue; |
| 101870 | + assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 ); |
| 101871 | + return pParse->nErr ? WRC_Abort : WRC_Continue; |
| 101060 | 101872 | } |
| 101061 | 101873 | |
| 101062 | 101874 | /* |
| 101063 | 101875 | ** pEList is a list of expressions which are really the result set of the |
| 101064 | 101876 | ** a SELECT statement. pE is a term in an ORDER BY or GROUP BY clause. |
| | @@ -101162,15 +101974,17 @@ |
| 101162 | 101974 | */ |
| 101163 | 101975 | static void resolveOutOfRangeError( |
| 101164 | 101976 | Parse *pParse, /* The error context into which to write the error */ |
| 101165 | 101977 | const char *zType, /* "ORDER" or "GROUP" */ |
| 101166 | 101978 | int i, /* The index (1-based) of the term out of range */ |
| 101167 | | - int mx /* Largest permissible value of i */ |
| 101979 | + int mx, /* Largest permissible value of i */ |
| 101980 | + Expr *pError /* Associate the error with the expression */ |
| 101168 | 101981 | ){ |
| 101169 | 101982 | sqlite3ErrorMsg(pParse, |
| 101170 | 101983 | "%r %s BY term out of range - should be " |
| 101171 | 101984 | "between 1 and %d", i, zType, mx); |
| 101985 | + sqlite3RecordErrorOffsetOfExpr(pParse->db, pError); |
| 101172 | 101986 | } |
| 101173 | 101987 | |
| 101174 | 101988 | /* |
| 101175 | 101989 | ** Analyze the ORDER BY clause in a compound SELECT statement. Modify |
| 101176 | 101990 | ** each term of the ORDER BY clause is a constant integer between 1 |
| | @@ -101222,11 +102036,11 @@ |
| 101222 | 102036 | if( pItem->done ) continue; |
| 101223 | 102037 | pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr); |
| 101224 | 102038 | if( NEVER(pE==0) ) continue; |
| 101225 | 102039 | if( sqlite3ExprIsInteger(pE, &iCol) ){ |
| 101226 | 102040 | if( iCol<=0 || iCol>pEList->nExpr ){ |
| 101227 | | - resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr); |
| 102041 | + resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr, pE); |
| 101228 | 102042 | return 1; |
| 101229 | 102043 | } |
| 101230 | 102044 | }else{ |
| 101231 | 102045 | iCol = resolveAsName(pParse, pEList, pE); |
| 101232 | 102046 | if( iCol==0 ){ |
| | @@ -101318,11 +102132,11 @@ |
| 101318 | 102132 | pEList = pSelect->pEList; |
| 101319 | 102133 | assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */ |
| 101320 | 102134 | for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){ |
| 101321 | 102135 | if( pItem->u.x.iOrderByCol ){ |
| 101322 | 102136 | if( pItem->u.x.iOrderByCol>pEList->nExpr ){ |
| 101323 | | - resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr); |
| 102137 | + resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr, 0); |
| 101324 | 102138 | return 1; |
| 101325 | 102139 | } |
| 101326 | 102140 | resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr,0); |
| 101327 | 102141 | } |
| 101328 | 102142 | } |
| | @@ -101410,11 +102224,11 @@ |
| 101410 | 102224 | if( sqlite3ExprIsInteger(pE2, &iCol) ){ |
| 101411 | 102225 | /* The ORDER BY term is an integer constant. Again, set the column |
| 101412 | 102226 | ** number so that sqlite3ResolveOrderGroupBy() will convert the |
| 101413 | 102227 | ** order-by term to a copy of the result-set expression */ |
| 101414 | 102228 | if( iCol<1 || iCol>0xffff ){ |
| 101415 | | - resolveOutOfRangeError(pParse, zType, i+1, nResult); |
| 102229 | + resolveOutOfRangeError(pParse, zType, i+1, nResult, pE2); |
| 101416 | 102230 | return 1; |
| 101417 | 102231 | } |
| 101418 | 102232 | pItem->u.x.iOrderByCol = (u16)iCol; |
| 101419 | 102233 | continue; |
| 101420 | 102234 | } |
| | @@ -101468,11 +102282,11 @@ |
| 101468 | 102282 | ** sqlite3SelectPrep() will invoke both sqlite3SelectExpand() and |
| 101469 | 102283 | ** this routine in the correct order. |
| 101470 | 102284 | */ |
| 101471 | 102285 | if( (p->selFlags & SF_Expanded)==0 ){ |
| 101472 | 102286 | sqlite3SelectPrep(pParse, p, pOuterNC); |
| 101473 | | - return (pParse->nErr || db->mallocFailed) ? WRC_Abort : WRC_Prune; |
| 102287 | + return pParse->nErr ? WRC_Abort : WRC_Prune; |
| 101474 | 102288 | } |
| 101475 | 102289 | |
| 101476 | 102290 | isCompound = p->pPrior!=0; |
| 101477 | 102291 | nCompound = 0; |
| 101478 | 102292 | pLeftmost = p; |
| | @@ -101516,11 +102330,12 @@ |
| 101516 | 102330 | const char *zSavedContext = pParse->zAuthContext; |
| 101517 | 102331 | |
| 101518 | 102332 | if( pItem->zName ) pParse->zAuthContext = pItem->zName; |
| 101519 | 102333 | sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC); |
| 101520 | 102334 | pParse->zAuthContext = zSavedContext; |
| 101521 | | - if( pParse->nErr || db->mallocFailed ) return WRC_Abort; |
| 102335 | + if( pParse->nErr ) return WRC_Abort; |
| 102336 | + assert( db->mallocFailed==0 ); |
| 101522 | 102337 | |
| 101523 | 102338 | /* If the number of references to the outer context changed when |
| 101524 | 102339 | ** expressions in the sub-select were resolved, the sub-select |
| 101525 | 102340 | ** is correlated. It is not required to check the refcount on any |
| 101526 | 102341 | ** but the innermost outer context object, as lookupName() increments |
| | @@ -102662,13 +103477,12 @@ |
| 102662 | 103477 | ** |
| 102663 | 103478 | ** Also propagate EP_Propagate flags up from Expr.x.pList to Expr.flags, |
| 102664 | 103479 | ** if appropriate. |
| 102665 | 103480 | */ |
| 102666 | 103481 | static void exprSetHeight(Expr *p){ |
| 102667 | | - int nHeight = 0; |
| 102668 | | - heightOfExpr(p->pLeft, &nHeight); |
| 102669 | | - heightOfExpr(p->pRight, &nHeight); |
| 103482 | + int nHeight = p->pLeft ? p->pLeft->nHeight : 0; |
| 103483 | + if( p->pRight && p->pRight->nHeight>nHeight ) nHeight = p->pRight->nHeight; |
| 102670 | 103484 | if( ExprUseXSelect(p) ){ |
| 102671 | 103485 | heightOfSelect(p->x.pSelect, &nHeight); |
| 102672 | 103486 | }else if( p->x.pList ){ |
| 102673 | 103487 | heightOfExprList(p->x.pList, &nHeight); |
| 102674 | 103488 | p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList); |
| | @@ -102963,10 +103777,11 @@ |
| 102963 | 103777 | pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1); |
| 102964 | 103778 | if( pNew==0 ){ |
| 102965 | 103779 | sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */ |
| 102966 | 103780 | return 0; |
| 102967 | 103781 | } |
| 103782 | + pNew->w.iOfst = (int)(pToken->z - pParse->zTail); |
| 102968 | 103783 | if( pList |
| 102969 | 103784 | && pList->nExpr > pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] |
| 102970 | 103785 | && !pParse->nested |
| 102971 | 103786 | ){ |
| 102972 | 103787 | sqlite3ErrorMsg(pParse, "too many arguments on function %T", pToken); |
| | @@ -103006,11 +103821,11 @@ |
| 103006 | 103821 | ** (2) not tagged with SQLITE_INNOCUOUS (which means it |
| 103007 | 103822 | ** is tagged with SQLITE_FUNC_UNSAFE) and |
| 103008 | 103823 | ** SQLITE_DBCONFIG_TRUSTED_SCHEMA is off (meaning |
| 103009 | 103824 | ** that the schema is possibly tainted). |
| 103010 | 103825 | */ |
| 103011 | | - sqlite3ErrorMsg(pParse, "unsafe use of %s()", pDef->zName); |
| 103826 | + sqlite3ErrorMsg(pParse, "unsafe use of %#T()", pExpr); |
| 103012 | 103827 | } |
| 103013 | 103828 | } |
| 103014 | 103829 | } |
| 103015 | 103830 | |
| 103016 | 103831 | /* |
| | @@ -103062,10 +103877,11 @@ |
| 103062 | 103877 | testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 ); |
| 103063 | 103878 | testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ); |
| 103064 | 103879 | if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){ |
| 103065 | 103880 | sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d", |
| 103066 | 103881 | db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]); |
| 103882 | + sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr); |
| 103067 | 103883 | return; |
| 103068 | 103884 | } |
| 103069 | 103885 | x = (ynVar)i; |
| 103070 | 103886 | if( x>pParse->nVar ){ |
| 103071 | 103887 | pParse->nVar = (int)x; |
| | @@ -103089,10 +103905,11 @@ |
| 103089 | 103905 | } |
| 103090 | 103906 | } |
| 103091 | 103907 | pExpr->iColumn = x; |
| 103092 | 103908 | if( x>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){ |
| 103093 | 103909 | sqlite3ErrorMsg(pParse, "too many SQL variables"); |
| 103910 | + sqlite3RecordErrorOffsetOfExpr(pParse->db, pExpr); |
| 103094 | 103911 | } |
| 103095 | 103912 | } |
| 103096 | 103913 | |
| 103097 | 103914 | /* |
| 103098 | 103915 | ** Recursively delete an expression tree. |
| | @@ -104696,12 +105513,11 @@ |
| 104696 | 105513 | Expr *pLhs = sqlite3VectorFieldSubexpr(pX->pLeft, i); |
| 104697 | 105514 | Expr *pRhs = pEList->a[i].pExpr; |
| 104698 | 105515 | CollSeq *pReq = sqlite3BinaryCompareCollSeq(pParse, pLhs, pRhs); |
| 104699 | 105516 | int j; |
| 104700 | 105517 | |
| 104701 | | - assert( pReq!=0 || pRhs->iColumn==XN_ROWID |
| 104702 | | - || pParse->nErr || db->mallocFailed ); |
| 105518 | + assert( pReq!=0 || pRhs->iColumn==XN_ROWID || pParse->nErr ); |
| 104703 | 105519 | for(j=0; j<nExpr; j++){ |
| 104704 | 105520 | if( pIdx->aiColumn[j]!=pRhs->iColumn ) continue; |
| 104705 | 105521 | assert( pIdx->azColl[j] ); |
| 104706 | 105522 | if( pReq!=0 && sqlite3StrICmp(pReq->zName, pIdx->azColl[j])!=0 ){ |
| 104707 | 105523 | continue; |
| | @@ -104932,12 +105748,11 @@ |
| 104932 | 105748 | assert( !ExprUseYWin(pExpr) ); |
| 104933 | 105749 | ExprSetProperty(pExpr, EP_Subrtn); |
| 104934 | 105750 | assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) ); |
| 104935 | 105751 | pExpr->y.sub.regReturn = ++pParse->nMem; |
| 104936 | 105752 | pExpr->y.sub.iAddr = |
| 104937 | | - sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1; |
| 104938 | | - VdbeComment((v, "return address")); |
| 105753 | + sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pExpr->y.sub.regReturn) + 1; |
| 104939 | 105754 | |
| 104940 | 105755 | addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v); |
| 104941 | 105756 | } |
| 104942 | 105757 | |
| 104943 | 105758 | /* Check to see if this is a vector IN operator */ |
| | @@ -105035,10 +105850,11 @@ |
| 105035 | 105850 | ** disable the test that was generated above that makes sure |
| 105036 | 105851 | ** this code only executes once. Because for a non-constant |
| 105037 | 105852 | ** expression we need to rerun this code each time. |
| 105038 | 105853 | */ |
| 105039 | 105854 | if( addrOnce && !sqlite3ExprIsConstant(pE2) ){ |
| 105855 | + sqlite3VdbeChangeToNoop(v, addrOnce-1); |
| 105040 | 105856 | sqlite3VdbeChangeToNoop(v, addrOnce); |
| 105041 | 105857 | ExprClearProperty(pExpr, EP_Subrtn); |
| 105042 | 105858 | addrOnce = 0; |
| 105043 | 105859 | } |
| 105044 | 105860 | |
| | @@ -105055,11 +105871,14 @@ |
| 105055 | 105871 | } |
| 105056 | 105872 | if( addrOnce ){ |
| 105057 | 105873 | sqlite3VdbeJumpHere(v, addrOnce); |
| 105058 | 105874 | /* Subroutine return */ |
| 105059 | 105875 | assert( ExprUseYSub(pExpr) ); |
| 105060 | | - sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn); |
| 105876 | + assert( sqlite3VdbeGetOp(v,pExpr->y.sub.iAddr-1)->opcode==OP_BeginSubrtn |
| 105877 | + || pParse->nErr ); |
| 105878 | + sqlite3VdbeAddOp3(v, OP_Return, pExpr->y.sub.regReturn, 0, |
| 105879 | + pExpr->y.sub.iAddr-1); |
| 105061 | 105880 | sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1); |
| 105062 | 105881 | sqlite3ClearTempRegCache(pParse); |
| 105063 | 105882 | } |
| 105064 | 105883 | } |
| 105065 | 105884 | #endif /* SQLITE_OMIT_SUBQUERY */ |
| | @@ -105110,13 +105929,11 @@ |
| 105110 | 105929 | assert( !ExprUseYWin(pExpr) ); |
| 105111 | 105930 | assert( !ExprHasProperty(pExpr, EP_Reduced|EP_TokenOnly) ); |
| 105112 | 105931 | ExprSetProperty(pExpr, EP_Subrtn); |
| 105113 | 105932 | pExpr->y.sub.regReturn = ++pParse->nMem; |
| 105114 | 105933 | pExpr->y.sub.iAddr = |
| 105115 | | - sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1; |
| 105116 | | - VdbeComment((v, "return address")); |
| 105117 | | - |
| 105934 | + sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pExpr->y.sub.regReturn) + 1; |
| 105118 | 105935 | |
| 105119 | 105936 | /* The evaluation of the EXISTS/SELECT must be repeated every time it |
| 105120 | 105937 | ** is encountered if any of the following is true: |
| 105121 | 105938 | ** |
| 105122 | 105939 | ** * The right-hand side is a correlated subquery |
| | @@ -105173,14 +105990,12 @@ |
| 105173 | 105990 | pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1"); |
| 105174 | 105991 | pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0); |
| 105175 | 105992 | } |
| 105176 | 105993 | pSel->iLimit = 0; |
| 105177 | 105994 | if( sqlite3Select(pParse, pSel, &dest) ){ |
| 105178 | | - if( pParse->nErr ){ |
| 105179 | | - pExpr->op2 = pExpr->op; |
| 105180 | | - pExpr->op = TK_ERROR; |
| 105181 | | - } |
| 105995 | + pExpr->op2 = pExpr->op; |
| 105996 | + pExpr->op = TK_ERROR; |
| 105182 | 105997 | return 0; |
| 105183 | 105998 | } |
| 105184 | 105999 | pExpr->iTable = rReg = dest.iSDParm; |
| 105185 | 106000 | ExprSetVVAProperty(pExpr, EP_NoReduce); |
| 105186 | 106001 | if( addrOnce ){ |
| | @@ -105187,11 +106002,14 @@ |
| 105187 | 106002 | sqlite3VdbeJumpHere(v, addrOnce); |
| 105188 | 106003 | } |
| 105189 | 106004 | |
| 105190 | 106005 | /* Subroutine return */ |
| 105191 | 106006 | assert( ExprUseYSub(pExpr) ); |
| 105192 | | - sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn); |
| 106007 | + assert( sqlite3VdbeGetOp(v,pExpr->y.sub.iAddr-1)->opcode==OP_BeginSubrtn |
| 106008 | + || pParse->nErr ); |
| 106009 | + sqlite3VdbeAddOp3(v, OP_Return, pExpr->y.sub.regReturn, 0, |
| 106010 | + pExpr->y.sub.iAddr-1); |
| 105193 | 106011 | sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1); |
| 105194 | 106012 | sqlite3ClearTempRegCache(pParse); |
| 105195 | 106013 | return rReg; |
| 105196 | 106014 | } |
| 105197 | 106015 | #endif /* SQLITE_OMIT_SUBQUERY */ |
| | @@ -105393,14 +106211,13 @@ |
| 105393 | 106211 | if( destIfNull==destIfFalse ){ |
| 105394 | 106212 | destStep2 = destIfFalse; |
| 105395 | 106213 | }else{ |
| 105396 | 106214 | destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse); |
| 105397 | 106215 | } |
| 105398 | | - if( pParse->nErr ) goto sqlite3ExprCodeIN_finished; |
| 105399 | 106216 | for(i=0; i<nVector; i++){ |
| 105400 | 106217 | Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i); |
| 105401 | | - if( pParse->db->mallocFailed ) goto sqlite3ExprCodeIN_oom_error; |
| 106218 | + if( pParse->nErr ) goto sqlite3ExprCodeIN_oom_error; |
| 105402 | 106219 | if( sqlite3ExprCanBeNull(p) ){ |
| 105403 | 106220 | sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2); |
| 105404 | 106221 | VdbeCoverage(v); |
| 105405 | 106222 | } |
| 105406 | 106223 | } |
| | @@ -105534,15 +106351,16 @@ |
| 105534 | 106351 | const char *z = pExpr->u.zToken; |
| 105535 | 106352 | assert( z!=0 ); |
| 105536 | 106353 | c = sqlite3DecOrHexToI64(z, &value); |
| 105537 | 106354 | if( (c==3 && !negFlag) || (c==2) || (negFlag && value==SMALLEST_INT64)){ |
| 105538 | 106355 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 105539 | | - sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z); |
| 106356 | + sqlite3ErrorMsg(pParse, "oversized integer: %s%#T", negFlag?"-":"",pExpr); |
| 105540 | 106357 | #else |
| 105541 | 106358 | #ifndef SQLITE_OMIT_HEX_INTEGER |
| 105542 | 106359 | if( sqlite3_strnicmp(z,"0x",2)==0 ){ |
| 105543 | | - sqlite3ErrorMsg(pParse, "hex literal too big: %s%s", negFlag?"-":"",z); |
| 106360 | + sqlite3ErrorMsg(pParse, "hex literal too big: %s%#T", |
| 106361 | + negFlag?"-":"",pExpr); |
| 105544 | 106362 | }else |
| 105545 | 106363 | #endif |
| 105546 | 106364 | { |
| 105547 | 106365 | codeReal(v, z, negFlag, iMem); |
| 105548 | 106366 | } |
| | @@ -106214,11 +107032,11 @@ |
| 106214 | 107032 | if( pInfo==0 |
| 106215 | 107033 | || NEVER(pExpr->iAgg<0) |
| 106216 | 107034 | || NEVER(pExpr->iAgg>=pInfo->nFunc) |
| 106217 | 107035 | ){ |
| 106218 | 107036 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 106219 | | - sqlite3ErrorMsg(pParse, "misuse of aggregate: %s()", pExpr->u.zToken); |
| 107037 | + sqlite3ErrorMsg(pParse, "misuse of aggregate: %#T()", pExpr); |
| 106220 | 107038 | }else{ |
| 106221 | 107039 | return pInfo->aFunc[pExpr->iAgg].iMem; |
| 106222 | 107040 | } |
| 106223 | 107041 | break; |
| 106224 | 107042 | } |
| | @@ -106255,11 +107073,11 @@ |
| 106255 | 107073 | if( pDef==0 && pParse->explain ){ |
| 106256 | 107074 | pDef = sqlite3FindFunction(db, "unknown", nFarg, enc, 0); |
| 106257 | 107075 | } |
| 106258 | 107076 | #endif |
| 106259 | 107077 | if( pDef==0 || pDef->xFinalize!=0 ){ |
| 106260 | | - sqlite3ErrorMsg(pParse, "unknown function: %s()", zId); |
| 107078 | + sqlite3ErrorMsg(pParse, "unknown function: %#T()", pExpr); |
| 106261 | 107079 | break; |
| 106262 | 107080 | } |
| 106263 | 107081 | if( pDef->funcFlags & SQLITE_FUNC_INLINE ){ |
| 106264 | 107082 | assert( (pDef->funcFlags & SQLITE_FUNC_UNSAFE)==0 ); |
| 106265 | 107083 | assert( (pDef->funcFlags & SQLITE_FUNC_DIRECT)==0 ); |
| | @@ -108571,11 +109389,13 @@ |
| 108571 | 109389 | sqlite3 *db; /* The database connection; */ |
| 108572 | 109390 | Vdbe *v; /* The prepared statement under construction */ |
| 108573 | 109391 | int r1; /* Temporary registers */ |
| 108574 | 109392 | |
| 108575 | 109393 | db = pParse->db; |
| 108576 | | - if( pParse->nErr || db->mallocFailed ) return; |
| 109394 | + assert( db->pParse==pParse ); |
| 109395 | + if( pParse->nErr ) return; |
| 109396 | + assert( db->mallocFailed==0 ); |
| 108577 | 109397 | pNew = pParse->pNewTable; |
| 108578 | 109398 | assert( pNew ); |
| 108579 | 109399 | |
| 108580 | 109400 | assert( sqlite3BtreeHoldsAllMutexes(db) ); |
| 108581 | 109401 | iDb = sqlite3SchemaToIndex(db, pNew->pSchema); |
| | @@ -108697,11 +109517,11 @@ |
| 108697 | 109517 | sqlite3NestedParse(pParse, |
| 108698 | 109518 | "SELECT CASE WHEN quick_check GLOB 'CHECK*'" |
| 108699 | 109519 | " THEN raise(ABORT,'CHECK constraint failed')" |
| 108700 | 109520 | " ELSE raise(ABORT,'NOT NULL constraint failed')" |
| 108701 | 109521 | " END" |
| 108702 | | - " FROM pragma_quick_check(\"%w\",\"%w\")" |
| 109522 | + " FROM pragma_quick_check(%Q,%Q)" |
| 108703 | 109523 | " WHERE quick_check GLOB 'CHECK*' OR quick_check GLOB 'NULL*'", |
| 108704 | 109524 | zTab, zDb |
| 108705 | 109525 | ); |
| 108706 | 109526 | } |
| 108707 | 109527 | } |
| | @@ -108876,11 +109696,11 @@ |
| 108876 | 109696 | if( !zOld ) goto exit_rename_column; |
| 108877 | 109697 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 108878 | 109698 | if( 0==sqlite3StrICmp(pTab->aCol[iCol].zCnName, zOld) ) break; |
| 108879 | 109699 | } |
| 108880 | 109700 | if( iCol==pTab->nCol ){ |
| 108881 | | - sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zOld); |
| 109701 | + sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pOld); |
| 108882 | 109702 | goto exit_rename_column; |
| 108883 | 109703 | } |
| 108884 | 109704 | |
| 108885 | 109705 | /* Ensure the schema contains no double-quoted strings */ |
| 108886 | 109706 | renameTestSchema(pParse, zDb, iSchema==1, "", 0); |
| | @@ -108982,11 +109802,13 @@ |
| 108982 | 109802 | ** |
| 108983 | 109803 | ** Technically, as x no longer points into a valid object or to the byte |
| 108984 | 109804 | ** following a valid object, it may not be used in comparison operations. |
| 108985 | 109805 | */ |
| 108986 | 109806 | static void renameTokenCheckAll(Parse *pParse, const void *pPtr){ |
| 108987 | | - if( pParse->nErr==0 && pParse->db->mallocFailed==0 ){ |
| 109807 | + assert( pParse==pParse->db->pParse ); |
| 109808 | + assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 ); |
| 109809 | + if( pParse->nErr==0 ){ |
| 108988 | 109810 | const RenameToken *p; |
| 108989 | 109811 | u8 i = 0; |
| 108990 | 109812 | for(p=pParse->pRename; p; p=p->pNext){ |
| 108991 | 109813 | if( p->p ){ |
| 108992 | 109814 | assert( p->p!=pPtr ); |
| | @@ -109304,16 +110126,16 @@ |
| 109304 | 110126 | ){ |
| 109305 | 110127 | const char *zT = (const char*)sqlite3_value_text(pType); |
| 109306 | 110128 | const char *zN = (const char*)sqlite3_value_text(pObject); |
| 109307 | 110129 | char *zErr; |
| 109308 | 110130 | |
| 109309 | | - zErr = sqlite3_mprintf("error in %s %s%s%s: %s", |
| 110131 | + zErr = sqlite3MPrintf(pParse->db, "error in %s %s%s%s: %s", |
| 109310 | 110132 | zT, zN, (zWhen[0] ? " " : ""), zWhen, |
| 109311 | 110133 | pParse->zErrMsg |
| 109312 | 110134 | ); |
| 109313 | 110135 | sqlite3_result_error(pCtx, zErr, -1); |
| 109314 | | - sqlite3_free(zErr); |
| 110136 | + sqlite3DbFree(pParse->db, zErr); |
| 109315 | 110137 | } |
| 109316 | 110138 | |
| 109317 | 110139 | /* |
| 109318 | 110140 | ** For each name in the the expression-list pEList (i.e. each |
| 109319 | 110141 | ** pEList->a[i].zName) that matches the string in zOld, extract the |
| | @@ -109374,23 +110196,25 @@ |
| 109374 | 110196 | const char *zSql, /* SQL to parse */ |
| 109375 | 110197 | int bTemp /* True if SQL is from temp schema */ |
| 109376 | 110198 | ){ |
| 109377 | 110199 | int rc; |
| 109378 | 110200 | |
| 110201 | + sqlite3ParseObjectInit(p, db); |
| 110202 | + if( zSql==0 ){ |
| 110203 | + return SQLITE_NOMEM; |
| 110204 | + } |
| 110205 | + if( sqlite3StrNICmp(zSql,"CREATE ",7)!=0 ){ |
| 110206 | + return SQLITE_CORRUPT_BKPT; |
| 110207 | + } |
| 109379 | 110208 | db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb); |
| 109380 | | - |
| 109381 | | - /* Parse the SQL statement passed as the first argument. If no error |
| 109382 | | - ** occurs and the parse does not result in a new table, index or |
| 109383 | | - ** trigger object, the database must be corrupt. */ |
| 109384 | | - memset(p, 0, sizeof(Parse)); |
| 109385 | 110209 | p->eParseMode = PARSE_MODE_RENAME; |
| 109386 | 110210 | p->db = db; |
| 109387 | 110211 | p->nQueryLoop = 1; |
| 109388 | | - rc = zSql ? sqlite3RunParser(p, zSql) : SQLITE_NOMEM; |
| 110212 | + rc = sqlite3RunParser(p, zSql); |
| 109389 | 110213 | if( db->mallocFailed ) rc = SQLITE_NOMEM; |
| 109390 | 110214 | if( rc==SQLITE_OK |
| 109391 | | - && p->pNewTable==0 && p->pNewIndex==0 && p->pNewTrigger==0 |
| 110215 | + && NEVER(p->pNewTable==0 && p->pNewIndex==0 && p->pNewTrigger==0) |
| 109392 | 110216 | ){ |
| 109393 | 110217 | rc = SQLITE_CORRUPT_BKPT; |
| 109394 | 110218 | } |
| 109395 | 110219 | |
| 109396 | 110220 | #ifdef SQLITE_DEBUG |
| | @@ -109664,17 +110488,17 @@ |
| 109664 | 110488 | sqlite3FreeIndex(db, pIdx); |
| 109665 | 110489 | } |
| 109666 | 110490 | sqlite3DeleteTrigger(db, pParse->pNewTrigger); |
| 109667 | 110491 | sqlite3DbFree(db, pParse->zErrMsg); |
| 109668 | 110492 | renameTokenFree(db, pParse->pRename); |
| 109669 | | - sqlite3ParserReset(pParse); |
| 110493 | + sqlite3ParseObjectReset(pParse); |
| 109670 | 110494 | } |
| 109671 | 110495 | |
| 109672 | 110496 | /* |
| 109673 | 110497 | ** SQL function: |
| 109674 | 110498 | ** |
| 109675 | | -** sqlite_rename_column(zSql, iCol, bQuote, zNew, zTable, zOld) |
| 110499 | +** sqlite_rename_column(SQL,TYPE,OBJ,DB,TABLE,COL,NEWNAME,QUOTE,TEMP) |
| 109676 | 110500 | ** |
| 109677 | 110501 | ** 0. zSql: SQL statement to rewrite |
| 109678 | 110502 | ** 1. type: Type of object ("table", "view" etc.) |
| 109679 | 110503 | ** 2. object: Name of object |
| 109680 | 110504 | ** 3. Database: Database name (e.g. "main") |
| | @@ -109688,11 +110512,12 @@ |
| 109688 | 110512 | ** The iCol-th column (left-most is 0) of table zTable is renamed from zCol |
| 109689 | 110513 | ** into zNew. The name should be quoted if bQuote is true. |
| 109690 | 110514 | ** |
| 109691 | 110515 | ** This function is used internally by the ALTER TABLE RENAME COLUMN command. |
| 109692 | 110516 | ** It is only accessible to SQL created using sqlite3NestedParse(). It is |
| 109693 | | -** not reachable from ordinary SQL passed into sqlite3_prepare(). |
| 110517 | +** not reachable from ordinary SQL passed into sqlite3_prepare() unless the |
| 110518 | +** SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test setting is enabled. |
| 109694 | 110519 | */ |
| 109695 | 110520 | static void renameColumnFunc( |
| 109696 | 110521 | sqlite3_context *context, |
| 109697 | 110522 | int NotUsed, |
| 109698 | 110523 | sqlite3_value **argv |
| | @@ -109837,11 +110662,13 @@ |
| 109837 | 110662 | assert( rc==SQLITE_OK ); |
| 109838 | 110663 | rc = renameEditSql(context, &sCtx, zSql, zNew, bQuote); |
| 109839 | 110664 | |
| 109840 | 110665 | renameColumnFunc_done: |
| 109841 | 110666 | if( rc!=SQLITE_OK ){ |
| 109842 | | - if( sParse.zErrMsg ){ |
| 110667 | + if( rc==SQLITE_ERROR && sqlite3WritableSchema(db) ){ |
| 110668 | + sqlite3_result_value(context, argv[0]); |
| 110669 | + }else if( sParse.zErrMsg ){ |
| 109843 | 110670 | renameColumnParseError(context, "", argv[1], argv[2], &sParse); |
| 109844 | 110671 | }else{ |
| 109845 | 110672 | sqlite3_result_error_code(context, rc); |
| 109846 | 110673 | } |
| 109847 | 110674 | } |
| | @@ -110036,11 +110863,13 @@ |
| 110036 | 110863 | |
| 110037 | 110864 | if( rc==SQLITE_OK ){ |
| 110038 | 110865 | rc = renameEditSql(context, &sCtx, zInput, zNew, bQuote); |
| 110039 | 110866 | } |
| 110040 | 110867 | if( rc!=SQLITE_OK ){ |
| 110041 | | - if( sParse.zErrMsg ){ |
| 110868 | + if( rc==SQLITE_ERROR && sqlite3WritableSchema(db) ){ |
| 110869 | + sqlite3_result_value(context, argv[3]); |
| 110870 | + }else if( sParse.zErrMsg ){ |
| 110042 | 110871 | renameColumnParseError(context, "", argv[1], argv[2], &sParse); |
| 110043 | 110872 | }else{ |
| 110044 | 110873 | sqlite3_result_error_code(context, rc); |
| 110045 | 110874 | } |
| 110046 | 110875 | } |
| | @@ -110061,14 +110890,14 @@ |
| 110061 | 110890 | renameTokenFind(pWalker->pParse, pWalker->u.pRename, (const void*)pExpr); |
| 110062 | 110891 | } |
| 110063 | 110892 | return WRC_Continue; |
| 110064 | 110893 | } |
| 110065 | 110894 | |
| 110066 | | -/* |
| 110067 | | -** The implementation of an SQL scalar function that rewrites DDL statements |
| 110068 | | -** so that any string literals that use double-quotes are modified so that |
| 110069 | | -** they use single quotes. |
| 110895 | +/* SQL function: sqlite_rename_quotefix(DB,SQL) |
| 110896 | +** |
| 110897 | +** Rewrite the DDL statement "SQL" so that any string literals that use |
| 110898 | +** double-quotes use single quotes instead. |
| 110070 | 110899 | ** |
| 110071 | 110900 | ** Two arguments must be passed: |
| 110072 | 110901 | ** |
| 110073 | 110902 | ** 0: Database name ("main", "temp" etc.). |
| 110074 | 110903 | ** 1: SQL statement to edit. |
| | @@ -110083,10 +110912,14 @@ |
| 110083 | 110912 | ** ); |
| 110084 | 110913 | ** |
| 110085 | 110914 | ** returns the string: |
| 110086 | 110915 | ** |
| 110087 | 110916 | ** CREATE VIEW v1 AS SELECT "a", 'string' FROM t1 |
| 110917 | +** |
| 110918 | +** If there is a error in the input SQL, then raise an error, except |
| 110919 | +** if PRAGMA writable_schema=ON, then just return the input string |
| 110920 | +** unmodified following an error. |
| 110088 | 110921 | */ |
| 110089 | 110922 | static void renameQuotefixFunc( |
| 110090 | 110923 | sqlite3_context *context, |
| 110091 | 110924 | int NotUsed, |
| 110092 | 110925 | sqlite3_value **argv |
| | @@ -110157,11 +110990,15 @@ |
| 110157 | 110990 | rc = renameEditSql(context, &sCtx, zInput, 0, 0); |
| 110158 | 110991 | } |
| 110159 | 110992 | renameTokenFree(db, sCtx.pList); |
| 110160 | 110993 | } |
| 110161 | 110994 | if( rc!=SQLITE_OK ){ |
| 110162 | | - sqlite3_result_error_code(context, rc); |
| 110995 | + if( sqlite3WritableSchema(db) && rc==SQLITE_ERROR ){ |
| 110996 | + sqlite3_result_value(context, argv[1]); |
| 110997 | + }else{ |
| 110998 | + sqlite3_result_error_code(context, rc); |
| 110999 | + } |
| 110163 | 111000 | } |
| 110164 | 111001 | renameParseCleanup(&sParse); |
| 110165 | 111002 | } |
| 110166 | 111003 | |
| 110167 | 111004 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| | @@ -110169,11 +111006,12 @@ |
| 110169 | 111006 | #endif |
| 110170 | 111007 | |
| 110171 | 111008 | sqlite3BtreeLeaveAll(db); |
| 110172 | 111009 | } |
| 110173 | 111010 | |
| 110174 | | -/* |
| 111011 | +/* Function: sqlite_rename_test(DB,SQL,TYPE,NAME,ISTEMP,WHEN,DQS) |
| 111012 | +** |
| 110175 | 111013 | ** An SQL user function that checks that there are no parse or symbol |
| 110176 | 111014 | ** resolution problems in a CREATE TRIGGER|TABLE|VIEW|INDEX statement. |
| 110177 | 111015 | ** After an ALTER TABLE .. RENAME operation is performed and the schema |
| 110178 | 111016 | ** reloaded, this function is called on each SQL statement in the schema |
| 110179 | 111017 | ** to ensure that it is still usable. |
| | @@ -110184,15 +111022,17 @@ |
| 110184 | 111022 | ** 3: Object name. |
| 110185 | 111023 | ** 4: True if object is from temp schema. |
| 110186 | 111024 | ** 5: "when" part of error message. |
| 110187 | 111025 | ** 6: True to disable the DQS quirk when parsing SQL. |
| 110188 | 111026 | ** |
| 110189 | | -** Unless it finds an error, this function normally returns NULL. However, it |
| 110190 | | -** returns integer value 1 if: |
| 111027 | +** The return value is computed as follows: |
| 110191 | 111028 | ** |
| 110192 | | -** * the SQL argument creates a trigger, and |
| 110193 | | -** * the table that the trigger is attached to is in database zDb. |
| 111029 | +** A. If an error is seen and not in PRAGMA writable_schema=ON mode, |
| 111030 | +** then raise the error. |
| 111031 | +** B. Else if a trigger is created and the the table that the trigger is |
| 111032 | +** attached to is in database zDb, then return 1. |
| 111033 | +** C. Otherwise return NULL. |
| 110194 | 111034 | */ |
| 110195 | 111035 | static void renameTableTest( |
| 110196 | 111036 | sqlite3_context *context, |
| 110197 | 111037 | int NotUsed, |
| 110198 | 111038 | sqlite3_value **argv |
| | @@ -110233,16 +111073,20 @@ |
| 110233 | 111073 | rc = renameResolveTrigger(&sParse); |
| 110234 | 111074 | } |
| 110235 | 111075 | if( rc==SQLITE_OK ){ |
| 110236 | 111076 | int i1 = sqlite3SchemaToIndex(db, sParse.pNewTrigger->pTabSchema); |
| 110237 | 111077 | int i2 = sqlite3FindDbName(db, zDb); |
| 110238 | | - if( i1==i2 ) sqlite3_result_int(context, 1); |
| 111078 | + if( i1==i2 ){ |
| 111079 | + /* Handle output case B */ |
| 111080 | + sqlite3_result_int(context, 1); |
| 111081 | + } |
| 110239 | 111082 | } |
| 110240 | 111083 | } |
| 110241 | 111084 | } |
| 110242 | 111085 | |
| 110243 | | - if( rc!=SQLITE_OK && zWhen ){ |
| 111086 | + if( rc!=SQLITE_OK && zWhen && !sqlite3WritableSchema(db) ){ |
| 111087 | + /* Output case A */ |
| 110244 | 111088 | renameColumnParseError(context, zWhen, argv[2], argv[3],&sParse); |
| 110245 | 111089 | } |
| 110246 | 111090 | renameParseCleanup(&sParse); |
| 110247 | 111091 | } |
| 110248 | 111092 | |
| | @@ -110354,11 +111198,11 @@ |
| 110354 | 111198 | assert( db->mallocFailed ); |
| 110355 | 111199 | goto exit_drop_column; |
| 110356 | 111200 | } |
| 110357 | 111201 | iCol = sqlite3ColumnIndex(pTab, zCol); |
| 110358 | 111202 | if( iCol<0 ){ |
| 110359 | | - sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zCol); |
| 111203 | + sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pName); |
| 110360 | 111204 | goto exit_drop_column; |
| 110361 | 111205 | } |
| 110362 | 111206 | |
| 110363 | 111207 | /* Do not allow the user to drop a PRIMARY KEY column or a column |
| 110364 | 111208 | ** constrained by a UNIQUE constraint. */ |
| | @@ -110378,10 +111222,16 @@ |
| 110378 | 111222 | |
| 110379 | 111223 | /* Edit the sqlite_schema table */ |
| 110380 | 111224 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 110381 | 111225 | assert( iDb>=0 ); |
| 110382 | 111226 | zDb = db->aDb[iDb].zDbSName; |
| 111227 | +#ifndef SQLITE_OMIT_AUTHORIZATION |
| 111228 | + /* Invoke the authorization callback. */ |
| 111229 | + if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, zCol) ){ |
| 111230 | + goto exit_drop_column; |
| 111231 | + } |
| 111232 | +#endif |
| 110383 | 111233 | renameTestSchema(pParse, zDb, iDb==1, "", 0); |
| 110384 | 111234 | renameFixQuotes(pParse, zDb, iDb==1); |
| 110385 | 111235 | sqlite3NestedParse(pParse, |
| 110386 | 111236 | "UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET " |
| 110387 | 111237 | "sql = sqlite_drop_column(%d, sql, %d) " |
| | @@ -111501,11 +112351,11 @@ |
| 111501 | 112351 | if( pStat1==0 ) return; |
| 111502 | 112352 | pStat1->zName = (char*)&pStat1[1]; |
| 111503 | 112353 | memcpy(pStat1->zName, "sqlite_stat1", 13); |
| 111504 | 112354 | pStat1->nCol = 3; |
| 111505 | 112355 | pStat1->iPKey = -1; |
| 111506 | | - sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNBLOB); |
| 112356 | + sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNAMIC); |
| 111507 | 112357 | } |
| 111508 | 112358 | #endif |
| 111509 | 112359 | |
| 111510 | 112360 | /* Establish a read-lock on the table at the shared-cache level. |
| 111511 | 112361 | ** Open a read-only cursor on the table. Also allocate a cursor number |
| | @@ -112765,11 +113615,11 @@ |
| 112765 | 113615 | ){ |
| 112766 | 113616 | goto attach_end; |
| 112767 | 113617 | } |
| 112768 | 113618 | |
| 112769 | 113619 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 112770 | | - if( pAuthArg ){ |
| 113620 | + if( ALWAYS(pAuthArg) ){ |
| 112771 | 113621 | char *zAuthArg; |
| 112772 | 113622 | if( pAuthArg->op==TK_STRING ){ |
| 112773 | 113623 | assert( !ExprHasProperty(pAuthArg, EP_IntValue) ); |
| 112774 | 113624 | zAuthArg = pAuthArg->u.zToken; |
| 112775 | 113625 | }else{ |
| | @@ -113426,15 +114276,17 @@ |
| 113426 | 114276 | sqlite3 *db; |
| 113427 | 114277 | Vdbe *v; |
| 113428 | 114278 | |
| 113429 | 114279 | assert( pParse->pToplevel==0 ); |
| 113430 | 114280 | db = pParse->db; |
| 114281 | + assert( db->pParse==pParse ); |
| 113431 | 114282 | if( pParse->nested ) return; |
| 113432 | | - if( db->mallocFailed || pParse->nErr ){ |
| 113433 | | - if( pParse->rc==SQLITE_OK ) pParse->rc = SQLITE_ERROR; |
| 114283 | + if( pParse->nErr ){ |
| 114284 | + if( db->mallocFailed ) pParse->rc = SQLITE_NOMEM; |
| 113434 | 114285 | return; |
| 113435 | 114286 | } |
| 114287 | + assert( db->mallocFailed==0 ); |
| 113436 | 114288 | |
| 113437 | 114289 | /* Begin by generating some termination code at the end of the |
| 113438 | 114290 | ** vdbe program |
| 113439 | 114291 | */ |
| 113440 | 114292 | v = pParse->pVdbe; |
| | @@ -113563,11 +114415,13 @@ |
| 113563 | 114415 | } |
| 113564 | 114416 | } |
| 113565 | 114417 | |
| 113566 | 114418 | /* Get the VDBE program ready for execution |
| 113567 | 114419 | */ |
| 113568 | | - if( v && pParse->nErr==0 && !db->mallocFailed ){ |
| 114420 | + assert( v!=0 || pParse->nErr ); |
| 114421 | + assert( db->mallocFailed==0 || pParse->nErr ); |
| 114422 | + if( pParse->nErr==0 ){ |
| 113569 | 114423 | /* A minimum of one cursor is required if autoincrement is used |
| 113570 | 114424 | * See ticket [a696379c1f08866] */ |
| 113571 | 114425 | assert( pParse->pAinc==0 || pParse->nTab>0 ); |
| 113572 | 114426 | sqlite3VdbeMakeReady(v, pParse); |
| 113573 | 114427 | pParse->rc = SQLITE_DONE; |
| | @@ -113612,10 +114466,12 @@ |
| 113612 | 114466 | pParse->nested++; |
| 113613 | 114467 | memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ); |
| 113614 | 114468 | memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ); |
| 113615 | 114469 | db->mDbFlags |= DBFLAG_PreferBuiltin; |
| 113616 | 114470 | sqlite3RunParser(pParse, zSql); |
| 114471 | + sqlite3DbFree(db, pParse->zErrMsg); |
| 114472 | + pParse->zErrMsg = 0; |
| 113617 | 114473 | db->mDbFlags = savedDbFlags; |
| 113618 | 114474 | sqlite3DbFree(db, zSql); |
| 113619 | 114475 | memcpy(PARSE_TAIL(pParse), saveBuf, PARSE_TAIL_SZ); |
| 113620 | 114476 | pParse->nested--; |
| 113621 | 114477 | } |
| | @@ -114572,11 +115428,12 @@ |
| 114572 | 115428 | goto begin_table_error; |
| 114573 | 115429 | } |
| 114574 | 115430 | pTable = sqlite3FindTable(db, zName, zDb); |
| 114575 | 115431 | if( pTable ){ |
| 114576 | 115432 | if( !noErr ){ |
| 114577 | | - sqlite3ErrorMsg(pParse, "table %T already exists", pName); |
| 115433 | + sqlite3ErrorMsg(pParse, "%s %T already exists", |
| 115434 | + (IsView(pTable)? "view" : "table"), pName); |
| 114578 | 115435 | }else{ |
| 114579 | 115436 | assert( !db->init.busy || CORRUPT_DB ); |
| 114580 | 115437 | sqlite3CodeVerifySchema(pParse, iDb); |
| 114581 | 115438 | sqlite3ForceNotReadOnly(pParse); |
| 114582 | 115439 | } |
| | @@ -115667,14 +116524,15 @@ |
| 115667 | 116524 | pList->a[0].sortFlags = pParse->iPkSortOrder; |
| 115668 | 116525 | assert( pParse->pNewTable==pTab ); |
| 115669 | 116526 | pTab->iPKey = -1; |
| 115670 | 116527 | sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0, |
| 115671 | 116528 | SQLITE_IDXTYPE_PRIMARYKEY); |
| 115672 | | - if( db->mallocFailed || pParse->nErr ){ |
| 116529 | + if( pParse->nErr ){ |
| 115673 | 116530 | pTab->tabFlags &= ~TF_WithoutRowid; |
| 115674 | 116531 | return; |
| 115675 | 116532 | } |
| 116533 | + assert( db->mallocFailed==0 ); |
| 115676 | 116534 | pPk = sqlite3PrimaryKeyIndex(pTab); |
| 115677 | 116535 | assert( pPk->nKeyCol==1 ); |
| 115678 | 116536 | }else{ |
| 115679 | 116537 | pPk = sqlite3PrimaryKeyIndex(pTab); |
| 115680 | 116538 | assert( pPk!=0 ); |
| | @@ -116101,10 +116959,15 @@ |
| 116101 | 116959 | int regRec; /* A record to be insert into the new table */ |
| 116102 | 116960 | int regRowid; /* Rowid of the next row to insert */ |
| 116103 | 116961 | int addrInsLoop; /* Top of the loop for inserting rows */ |
| 116104 | 116962 | Table *pSelTab; /* A table that describes the SELECT results */ |
| 116105 | 116963 | |
| 116964 | + if( IN_SPECIAL_PARSE ){ |
| 116965 | + pParse->rc = SQLITE_ERROR; |
| 116966 | + pParse->nErr++; |
| 116967 | + return; |
| 116968 | + } |
| 116106 | 116969 | regYield = ++pParse->nMem; |
| 116107 | 116970 | regRec = ++pParse->nMem; |
| 116108 | 116971 | regRowid = ++pParse->nMem; |
| 116109 | 116972 | assert(pParse->nTab==1); |
| 116110 | 116973 | sqlite3MayAbort(pParse); |
| | @@ -116411,14 +117274,14 @@ |
| 116411 | 117274 | ** normally holds CHECK constraints on an ordinary table, but for |
| 116412 | 117275 | ** a VIEW it holds the list of column names. |
| 116413 | 117276 | */ |
| 116414 | 117277 | sqlite3ColumnsFromExprList(pParse, pTable->pCheck, |
| 116415 | 117278 | &pTable->nCol, &pTable->aCol); |
| 116416 | | - if( db->mallocFailed==0 |
| 116417 | | - && pParse->nErr==0 |
| 117279 | + if( pParse->nErr==0 |
| 116418 | 117280 | && pTable->nCol==pSel->pEList->nExpr |
| 116419 | 117281 | ){ |
| 117282 | + assert( db->mallocFailed==0 ); |
| 116420 | 117283 | sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel, |
| 116421 | 117284 | SQLITE_AFF_NONE); |
| 116422 | 117285 | } |
| 116423 | 117286 | }else{ |
| 116424 | 117287 | /* CREATE VIEW name AS... without an argument list. Construct |
| | @@ -117033,11 +117896,11 @@ |
| 117033 | 117896 | tnum = (Pgno)memRootPage; |
| 117034 | 117897 | }else{ |
| 117035 | 117898 | tnum = pIndex->tnum; |
| 117036 | 117899 | } |
| 117037 | 117900 | pKey = sqlite3KeyInfoOfIndex(pParse, pIndex); |
| 117038 | | - assert( pKey!=0 || db->mallocFailed || pParse->nErr ); |
| 117901 | + assert( pKey!=0 || pParse->nErr ); |
| 117039 | 117902 | |
| 117040 | 117903 | /* Open the sorter cursor if we are to use one. */ |
| 117041 | 117904 | iSorter = pParse->nTab++; |
| 117042 | 117905 | sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, pIndex->nKeyCol, (char*) |
| 117043 | 117906 | sqlite3KeyInfoRef(pKey), P4_KEYINFO); |
| | @@ -117197,13 +118060,15 @@ |
| 117197 | 118060 | int nExtra = 0; /* Space allocated for zExtra[] */ |
| 117198 | 118061 | int nExtraCol; /* Number of extra columns needed */ |
| 117199 | 118062 | char *zExtra = 0; /* Extra space after the Index object */ |
| 117200 | 118063 | Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */ |
| 117201 | 118064 | |
| 117202 | | - if( db->mallocFailed || pParse->nErr>0 ){ |
| 118065 | + assert( db->pParse==pParse ); |
| 118066 | + if( pParse->nErr ){ |
| 117203 | 118067 | goto exit_create_index; |
| 117204 | 118068 | } |
| 118069 | + assert( db->mallocFailed==0 ); |
| 117205 | 118070 | if( IN_DECLARE_VTAB && idxType!=SQLITE_IDXTYPE_PRIMARYKEY ){ |
| 117206 | 118071 | goto exit_create_index; |
| 117207 | 118072 | } |
| 117208 | 118073 | if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){ |
| 117209 | 118074 | goto exit_create_index; |
| | @@ -117263,11 +118128,10 @@ |
| 117263 | 118128 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 117264 | 118129 | } |
| 117265 | 118130 | pDb = &db->aDb[iDb]; |
| 117266 | 118131 | |
| 117267 | 118132 | assert( pTab!=0 ); |
| 117268 | | - assert( pParse->nErr==0 ); |
| 117269 | 118133 | if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 |
| 117270 | 118134 | && db->init.busy==0 |
| 117271 | 118135 | && pTblName!=0 |
| 117272 | 118136 | #if SQLITE_USER_AUTHENTICATION |
| 117273 | 118137 | && sqlite3UserAuthTable(pTab->zName)==0 |
| | @@ -117827,14 +118691,14 @@ |
| 117827 | 118691 | Index *pIndex; |
| 117828 | 118692 | Vdbe *v; |
| 117829 | 118693 | sqlite3 *db = pParse->db; |
| 117830 | 118694 | int iDb; |
| 117831 | 118695 | |
| 117832 | | - assert( pParse->nErr==0 ); /* Never called with prior errors */ |
| 117833 | 118696 | if( db->mallocFailed ){ |
| 117834 | 118697 | goto exit_drop_index; |
| 117835 | 118698 | } |
| 118699 | + assert( pParse->nErr==0 ); /* Never called with prior non-OOM errors */ |
| 117836 | 118700 | assert( pName->nSrc==1 ); |
| 117837 | 118701 | if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){ |
| 117838 | 118702 | goto exit_drop_index; |
| 117839 | 118703 | } |
| 117840 | 118704 | pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase); |
| | @@ -119746,13 +120610,15 @@ |
| 119746 | 120610 | Trigger *pTrigger; /* List of table triggers, if required */ |
| 119747 | 120611 | #endif |
| 119748 | 120612 | |
| 119749 | 120613 | memset(&sContext, 0, sizeof(sContext)); |
| 119750 | 120614 | db = pParse->db; |
| 119751 | | - if( pParse->nErr || db->mallocFailed ){ |
| 120615 | + assert( db->pParse==pParse ); |
| 120616 | + if( pParse->nErr ){ |
| 119752 | 120617 | goto delete_from_cleanup; |
| 119753 | 120618 | } |
| 120619 | + assert( db->mallocFailed==0 ); |
| 119754 | 120620 | assert( pTabList->nSrc==1 ); |
| 119755 | 120621 | |
| 119756 | 120622 | |
| 119757 | 120623 | /* Locate the table which we want to delete. This table has to be |
| 119758 | 120624 | ** put in an SrcList structure because some of the subroutines we |
| | @@ -119929,11 +120795,11 @@ |
| 119929 | 120795 | ** |
| 119930 | 120796 | ** ONEPASS_OFF: Two-pass approach - use a FIFO for rowids/PK values. |
| 119931 | 120797 | ** ONEPASS_SINGLE: One-pass approach - at most one row deleted. |
| 119932 | 120798 | ** ONEPASS_MULTI: One-pass approach - any number of rows may be deleted. |
| 119933 | 120799 | */ |
| 119934 | | - pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, wcf, iTabCur+1); |
| 120800 | + pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,0,wcf,iTabCur+1); |
| 119935 | 120801 | if( pWInfo==0 ) goto delete_from_cleanup; |
| 119936 | 120802 | eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass); |
| 119937 | 120803 | assert( IsVirtual(pTab)==0 || eOnePass!=ONEPASS_MULTI ); |
| 119938 | 120804 | assert( IsVirtual(pTab) || bComplex || eOnePass!=ONEPASS_OFF ); |
| 119939 | 120805 | if( eOnePass!=ONEPASS_SINGLE ) sqlite3MultiWrite(pParse); |
| | @@ -120542,10 +121408,11 @@ |
| 120542 | 121408 | static void subtypeFunc( |
| 120543 | 121409 | sqlite3_context *context, |
| 120544 | 121410 | int argc, |
| 120545 | 121411 | sqlite3_value **argv |
| 120546 | 121412 | ){ |
| 121413 | + UNUSED_PARAMETER(argc); |
| 120547 | 121414 | sqlite3_result_int(context, sqlite3_value_subtype(argv[0])); |
| 120548 | 121415 | } |
| 120549 | 121416 | |
| 120550 | 121417 | /* |
| 120551 | 121418 | ** Implementation of the length() function |
| | @@ -121555,12 +122422,13 @@ |
| 121555 | 122422 | UNUSED_PARAMETER(argc); |
| 121556 | 122423 | sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 121557 | 122424 | sqlite3QuoteValue(&str,argv[0]); |
| 121558 | 122425 | sqlite3_result_text(context, sqlite3StrAccumFinish(&str), str.nChar, |
| 121559 | 122426 | SQLITE_DYNAMIC); |
| 121560 | | - if( str.accError==SQLITE_NOMEM ){ |
| 121561 | | - sqlite3_result_error_nomem(context); |
| 122427 | + if( str.accError!=SQLITE_OK ){ |
| 122428 | + sqlite3_result_null(context); |
| 122429 | + sqlite3_result_error_code(context, str.accError); |
| 121562 | 122430 | } |
| 121563 | 122431 | } |
| 121564 | 122432 | |
| 121565 | 122433 | /* |
| 121566 | 122434 | ** The unicode() function. Return the integer unicode code-point value |
| | @@ -122675,12 +123543,12 @@ |
| 122675 | 123543 | #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 122676 | 123544 | INLINE_FUNC(unlikely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY), |
| 122677 | 123545 | INLINE_FUNC(likelihood, 2, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY), |
| 122678 | 123546 | INLINE_FUNC(likely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY), |
| 122679 | 123547 | #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC |
| 122680 | | - FUNCTION2(sqlite_offset, 1, 0, 0, noopFunc, SQLITE_FUNC_OFFSET| |
| 122681 | | - SQLITE_FUNC_TYPEOF), |
| 123548 | + {1, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_OFFSET|SQLITE_FUNC_TYPEOF, |
| 123549 | + 0, 0, noopFunc, 0, 0, 0, "sqlite_offset", {0} }, |
| 122682 | 123550 | #endif |
| 122683 | 123551 | FUNCTION(ltrim, 1, 1, 0, trimFunc ), |
| 122684 | 123552 | FUNCTION(ltrim, 2, 1, 0, trimFunc ), |
| 122685 | 123553 | FUNCTION(rtrim, 1, 2, 0, trimFunc ), |
| 122686 | 123554 | FUNCTION(rtrim, 2, 2, 0, trimFunc ), |
| | @@ -123472,11 +124340,11 @@ |
| 123472 | 124340 | |
| 123473 | 124341 | /* Create VDBE to loop through the entries in pSrc that match the WHERE |
| 123474 | 124342 | ** clause. For each row found, increment either the deferred or immediate |
| 123475 | 124343 | ** foreign key constraint counter. */ |
| 123476 | 124344 | if( pParse->nErr==0 ){ |
| 123477 | | - pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0); |
| 124345 | + pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0, 0); |
| 123478 | 124346 | sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr); |
| 123479 | 124347 | if( pWInfo ){ |
| 123480 | 124348 | sqlite3WhereEnd(pWInfo); |
| 123481 | 124349 | } |
| 123482 | 124350 | } |
| | @@ -124480,11 +125348,11 @@ |
| 124480 | 125348 | sqlite3OomFault(db); |
| 124481 | 125349 | return; |
| 124482 | 125350 | } |
| 124483 | 125351 | |
| 124484 | 125352 | for(i=j=0; i<pTab->nCol; i++){ |
| 124485 | | - assert( pTab->aCol[i].affinity!=0 ); |
| 125353 | + assert( pTab->aCol[i].affinity!=0 || sqlite3VdbeParser(v)->nErr>0 ); |
| 124486 | 125354 | if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){ |
| 124487 | 125355 | zColAff[j++] = pTab->aCol[i].affinity; |
| 124488 | 125356 | } |
| 124489 | 125357 | } |
| 124490 | 125358 | do{ |
| | @@ -125014,13 +125882,15 @@ |
| 125014 | 125882 | Trigger *pTrigger; /* List of triggers on pTab, if required */ |
| 125015 | 125883 | int tmask; /* Mask of trigger times */ |
| 125016 | 125884 | #endif |
| 125017 | 125885 | |
| 125018 | 125886 | db = pParse->db; |
| 125019 | | - if( pParse->nErr || db->mallocFailed ){ |
| 125887 | + assert( db->pParse==pParse ); |
| 125888 | + if( pParse->nErr ){ |
| 125020 | 125889 | goto insert_cleanup; |
| 125021 | 125890 | } |
| 125891 | + assert( db->mallocFailed==0 ); |
| 125022 | 125892 | dest.iSDParm = 0; /* Suppress a harmless compiler warning */ |
| 125023 | 125893 | |
| 125024 | 125894 | /* If the Select object is really just a simple VALUES() list with a |
| 125025 | 125895 | ** single row (the common case) then keep that one row of values |
| 125026 | 125896 | ** and discard the other (unused) parts of the pSelect object |
| | @@ -125092,11 +125962,15 @@ |
| 125092 | 125962 | ** Then special optimizations can be applied that make the transfer |
| 125093 | 125963 | ** very fast and which reduce fragmentation of indices. |
| 125094 | 125964 | ** |
| 125095 | 125965 | ** This is the 2nd template. |
| 125096 | 125966 | */ |
| 125097 | | - if( pColumn==0 && xferOptimization(pParse, pTab, pSelect, onError, iDb) ){ |
| 125967 | + if( pColumn==0 |
| 125968 | + && pSelect!=0 |
| 125969 | + && pTrigger==0 |
| 125970 | + && xferOptimization(pParse, pTab, pSelect, onError, iDb) |
| 125971 | + ){ |
| 125098 | 125972 | assert( !pTrigger ); |
| 125099 | 125973 | assert( pList==0 ); |
| 125100 | 125974 | goto insert_end; |
| 125101 | 125975 | } |
| 125102 | 125976 | #endif /* SQLITE_OMIT_XFER_OPT */ |
| | @@ -125192,11 +126066,13 @@ |
| 125192 | 126066 | sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield); |
| 125193 | 126067 | dest.iSdst = bIdListInOrder ? regData : 0; |
| 125194 | 126068 | dest.nSdst = pTab->nCol; |
| 125195 | 126069 | rc = sqlite3Select(pParse, pSelect, &dest); |
| 125196 | 126070 | regFromSelect = dest.iSdst; |
| 125197 | | - if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup; |
| 126071 | + assert( db->pParse==pParse ); |
| 126072 | + if( rc || pParse->nErr ) goto insert_cleanup; |
| 126073 | + assert( db->mallocFailed==0 ); |
| 125198 | 126074 | sqlite3VdbeEndCoroutine(v, regYield); |
| 125199 | 126075 | sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */ |
| 125200 | 126076 | assert( pSelect->pEList ); |
| 125201 | 126077 | nColumn = pSelect->pEList->nExpr; |
| 125202 | 126078 | |
| | @@ -126573,11 +127449,11 @@ |
| 126573 | 127449 | } |
| 126574 | 127450 | } |
| 126575 | 127451 | if( isUpdate ){ |
| 126576 | 127452 | /* If currently processing the PRIMARY KEY of a WITHOUT ROWID |
| 126577 | 127453 | ** table, only conflict if the new PRIMARY KEY values are actually |
| 126578 | | - ** different from the old. |
| 127454 | + ** different from the old. See TH3 withoutrowid04.test. |
| 126579 | 127455 | ** |
| 126580 | 127456 | ** For a UNIQUE index, only conflict if the PRIMARY KEY values |
| 126581 | 127457 | ** of the matched index row are different from the original PRIMARY |
| 126582 | 127458 | ** KEY values of this row before the update. */ |
| 126583 | 127459 | int addrJump = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol; |
| | @@ -127061,22 +127937,17 @@ |
| 127061 | 127937 | Vdbe *v; /* The VDBE we are building */ |
| 127062 | 127938 | int regAutoinc; /* Memory register used by AUTOINC */ |
| 127063 | 127939 | int destHasUniqueIdx = 0; /* True if pDest has a UNIQUE index */ |
| 127064 | 127940 | int regData, regRowid; /* Registers holding data and rowid */ |
| 127065 | 127941 | |
| 127066 | | - if( pSelect==0 ){ |
| 127067 | | - return 0; /* Must be of the form INSERT INTO ... SELECT ... */ |
| 127068 | | - } |
| 127942 | + assert( pSelect!=0 ); |
| 127069 | 127943 | if( pParse->pWith || pSelect->pWith ){ |
| 127070 | 127944 | /* Do not attempt to process this query if there are an WITH clauses |
| 127071 | 127945 | ** attached to it. Proceeding may generate a false "no such table: xxx" |
| 127072 | 127946 | ** error if pSelect reads from a CTE named "xxx". */ |
| 127073 | 127947 | return 0; |
| 127074 | 127948 | } |
| 127075 | | - if( sqlite3TriggerList(pParse, pDest) ){ |
| 127076 | | - return 0; /* tab1 must not have triggers */ |
| 127077 | | - } |
| 127078 | 127949 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 127079 | 127950 | if( IsVirtual(pDest) ){ |
| 127080 | 127951 | return 0; /* tab1 must not be a virtual table */ |
| 127081 | 127952 | } |
| 127082 | 127953 | #endif |
| | @@ -127937,10 +128808,20 @@ |
| 127937 | 128808 | int (*autovacuum_pages)(sqlite3*, |
| 127938 | 128809 | unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int), |
| 127939 | 128810 | void*, void(*)(void*)); |
| 127940 | 128811 | /* Version 3.38.0 and later */ |
| 127941 | 128812 | int (*error_offset)(sqlite3*); |
| 128813 | + int (*vtab_rhs_value)(sqlite3_index_info*,int,sqlite3_value**); |
| 128814 | + int (*vtab_distinct)(sqlite3_index_info*); |
| 128815 | + int (*vtab_in)(sqlite3_index_info*,int,int); |
| 128816 | + int (*vtab_in_first)(sqlite3_value*,sqlite3_value**); |
| 128817 | + int (*vtab_in_next)(sqlite3_value*,sqlite3_value**); |
| 128818 | + /* Version 3.39.0 and later */ |
| 128819 | + int (*deserialize)(sqlite3*,const char*,unsigned char*, |
| 128820 | + sqlite3_int64,sqlite3_int64,unsigned); |
| 128821 | + unsigned char *(*serialize)(sqlite3*,const char *,sqlite3_int64*, |
| 128822 | + unsigned int); |
| 127942 | 128823 | }; |
| 127943 | 128824 | |
| 127944 | 128825 | /* |
| 127945 | 128826 | ** This is the function signature used for all extension entry points. It |
| 127946 | 128827 | ** is also defined in the file "loadext.c". |
| | @@ -128250,10 +129131,19 @@ |
| 128250 | 129131 | #define sqlite3_total_changes64 sqlite3_api->total_changes64 |
| 128251 | 129132 | /* Version 3.37.0 and later */ |
| 128252 | 129133 | #define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages |
| 128253 | 129134 | /* Version 3.38.0 and later */ |
| 128254 | 129135 | #define sqlite3_error_offset sqlite3_api->error_offset |
| 129136 | +#define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value |
| 129137 | +#define sqlite3_vtab_distinct sqlite3_api->vtab_distinct |
| 129138 | +#define sqlite3_vtab_in sqlite3_api->vtab_in |
| 129139 | +#define sqlite3_vtab_in_first sqlite3_api->vtab_in_first |
| 129140 | +#define sqlite3_vtab_in_next sqlite3_api->vtab_in_next |
| 129141 | +#ifndef SQLITE_OMIT_DESERIALIZE |
| 129142 | +#define sqlite3_deserialize sqlite3_api->deserialize |
| 129143 | +#define sqlite3_serialize sqlite3_api->serialize |
| 129144 | +#endif |
| 128255 | 129145 | #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ |
| 128256 | 129146 | |
| 128257 | 129147 | #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 128258 | 129148 | /* This case when the file really is being compiled as a loadable |
| 128259 | 129149 | ** extension */ |
| | @@ -128741,10 +129631,23 @@ |
| 128741 | 129631 | sqlite3_total_changes64, |
| 128742 | 129632 | /* Version 3.37.0 and later */ |
| 128743 | 129633 | sqlite3_autovacuum_pages, |
| 128744 | 129634 | /* Version 3.38.0 and later */ |
| 128745 | 129635 | sqlite3_error_offset, |
| 129636 | + sqlite3_vtab_rhs_value, |
| 129637 | + sqlite3_vtab_distinct, |
| 129638 | + sqlite3_vtab_in, |
| 129639 | + sqlite3_vtab_in_first, |
| 129640 | + sqlite3_vtab_in_next, |
| 129641 | + /* Version 3.39.0 and later */ |
| 129642 | +#ifndef SQLITE_OMIT_DESERIALIZE |
| 129643 | + sqlite3_deserialize, |
| 129644 | + sqlite3_serialize |
| 129645 | +#else |
| 129646 | + 0, |
| 129647 | + 0 |
| 129648 | +#endif |
| 128746 | 129649 | }; |
| 128747 | 129650 | |
| 128748 | 129651 | /* True if x is the directory separator character |
| 128749 | 129652 | */ |
| 128750 | 129653 | #if SQLITE_OS_WIN |
| | @@ -129411,11 +130314,11 @@ |
| 129411 | 130314 | /* iArg: */ BTREE_DATA_VERSION }, |
| 129412 | 130315 | #endif |
| 129413 | 130316 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 129414 | 130317 | {/* zName: */ "database_list", |
| 129415 | 130318 | /* ePragTyp: */ PragTyp_DATABASE_LIST, |
| 129416 | | - /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0, |
| 130319 | + /* ePragFlg: */ PragFlg_Result0, |
| 129417 | 130320 | /* ColNames: */ 47, 3, |
| 129418 | 130321 | /* iArg: */ 0 }, |
| 129419 | 130322 | #endif |
| 129420 | 130323 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) |
| 129421 | 130324 | {/* zName: */ "default_cache_size", |
| | @@ -130099,19 +131002,20 @@ |
| 130099 | 131002 | Vdbe *v, /* The prepared statement being created */ |
| 130100 | 131003 | FuncDef *p, /* A particular function definition */ |
| 130101 | 131004 | int isBuiltin, /* True if this is a built-in function */ |
| 130102 | 131005 | int showInternFuncs /* True if showing internal functions */ |
| 130103 | 131006 | ){ |
| 131007 | + u32 mask = |
| 131008 | + SQLITE_DETERMINISTIC | |
| 131009 | + SQLITE_DIRECTONLY | |
| 131010 | + SQLITE_SUBTYPE | |
| 131011 | + SQLITE_INNOCUOUS | |
| 131012 | + SQLITE_FUNC_INTERNAL |
| 131013 | + ; |
| 131014 | + if( showInternFuncs ) mask = 0xffffffff; |
| 130104 | 131015 | for(; p; p=p->pNext){ |
| 130105 | 131016 | const char *zType; |
| 130106 | | - static const u32 mask = |
| 130107 | | - SQLITE_DETERMINISTIC | |
| 130108 | | - SQLITE_DIRECTONLY | |
| 130109 | | - SQLITE_SUBTYPE | |
| 130110 | | - SQLITE_INNOCUOUS | |
| 130111 | | - SQLITE_FUNC_INTERNAL |
| 130112 | | - ; |
| 130113 | 131017 | static const char *azEnc[] = { 0, "utf8", "utf16le", "utf16be" }; |
| 130114 | 131018 | |
| 130115 | 131019 | assert( SQLITE_FUNC_ENCMASK==0x3 ); |
| 130116 | 131020 | assert( strcmp(azEnc[SQLITE_UTF8],"utf8")==0 ); |
| 130117 | 131021 | assert( strcmp(azEnc[SQLITE_UTF16LE],"utf16le")==0 ); |
| | @@ -131042,10 +131946,14 @@ |
| 131042 | 131946 | sqlite3_stmt *pDummy = 0; |
| 131043 | 131947 | (void)sqlite3_prepare(db, zSql, -1, &pDummy, 0); |
| 131044 | 131948 | (void)sqlite3_finalize(pDummy); |
| 131045 | 131949 | sqlite3DbFree(db, zSql); |
| 131046 | 131950 | } |
| 131951 | + if( db->mallocFailed ){ |
| 131952 | + sqlite3ErrorMsg(db->pParse, "out of memory"); |
| 131953 | + db->pParse->rc = SQLITE_NOMEM_BKPT; |
| 131954 | + } |
| 131047 | 131955 | pHash = &db->aDb[ii].pSchema->tblHash; |
| 131048 | 131956 | break; |
| 131049 | 131957 | } |
| 131050 | 131958 | } |
| 131051 | 131959 | } |
| | @@ -133078,12 +133986,14 @@ |
| 133078 | 133986 | } |
| 133079 | 133987 | |
| 133080 | 133988 | /* |
| 133081 | 133989 | ** Free all memory allocations in the pParse object |
| 133082 | 133990 | */ |
| 133083 | | -SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){ |
| 133991 | +SQLITE_PRIVATE void sqlite3ParseObjectReset(Parse *pParse){ |
| 133084 | 133992 | sqlite3 *db = pParse->db; |
| 133993 | + assert( db!=0 ); |
| 133994 | + assert( db->pParse==pParse ); |
| 133085 | 133995 | assert( pParse->nested==0 ); |
| 133086 | 133996 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 133087 | 133997 | sqlite3DbFree(db, pParse->aTableLock); |
| 133088 | 133998 | #endif |
| 133089 | 133999 | while( pParse->pCleanup ){ |
| | @@ -133094,15 +134004,16 @@ |
| 133094 | 134004 | } |
| 133095 | 134005 | sqlite3DbFree(db, pParse->aLabel); |
| 133096 | 134006 | if( pParse->pConstExpr ){ |
| 133097 | 134007 | sqlite3ExprListDelete(db, pParse->pConstExpr); |
| 133098 | 134008 | } |
| 133099 | | - if( db ){ |
| 133100 | | - assert( db->lookaside.bDisable >= pParse->disableLookaside ); |
| 133101 | | - db->lookaside.bDisable -= pParse->disableLookaside; |
| 133102 | | - db->lookaside.sz = db->lookaside.bDisable ? 0 : db->lookaside.szTrue; |
| 133103 | | - } |
| 134009 | + assert( db->lookaside.bDisable >= pParse->disableLookaside ); |
| 134010 | + db->lookaside.bDisable -= pParse->disableLookaside; |
| 134011 | + db->lookaside.sz = db->lookaside.bDisable ? 0 : db->lookaside.szTrue; |
| 134012 | + assert( pParse->db->pParse==pParse ); |
| 134013 | + db->pParse = pParse->pOuterParse; |
| 134014 | + pParse->db = 0; |
| 133104 | 134015 | pParse->disableLookaside = 0; |
| 133105 | 134016 | } |
| 133106 | 134017 | |
| 133107 | 134018 | /* |
| 133108 | 134019 | ** Add a new cleanup operation to a Parser. The cleanup should happen when |
| | @@ -133111,11 +134022,11 @@ |
| 133111 | 134022 | ** |
| 133112 | 134023 | ** Use this mechanism for uncommon cleanups. There is a higher setup |
| 133113 | 134024 | ** cost for this mechansim (an extra malloc), so it should not be used |
| 133114 | 134025 | ** for common cleanups that happen on most calls. But for less |
| 133115 | 134026 | ** common cleanups, we save a single NULL-pointer comparison in |
| 133116 | | -** sqlite3ParserReset(), which reduces the total CPU cycle count. |
| 134027 | +** sqlite3ParseObjectReset(), which reduces the total CPU cycle count. |
| 133117 | 134028 | ** |
| 133118 | 134029 | ** If a memory allocation error occurs, then the cleanup happens immediately. |
| 133119 | 134030 | ** When either SQLITE_DEBUG or SQLITE_COVERAGE_TEST are defined, the |
| 133120 | 134031 | ** pParse->earlyCleanup flag is set in that case. Calling code show verify |
| 133121 | 134032 | ** that test cases exist for which this happens, to guard against possible |
| | @@ -133150,10 +134061,29 @@ |
| 133150 | 134061 | pParse->earlyCleanup = 1; |
| 133151 | 134062 | #endif |
| 133152 | 134063 | } |
| 133153 | 134064 | return pPtr; |
| 133154 | 134065 | } |
| 134066 | + |
| 134067 | +/* |
| 134068 | +** Turn bulk memory into a valid Parse object and link that Parse object |
| 134069 | +** into database connection db. |
| 134070 | +** |
| 134071 | +** Call sqlite3ParseObjectReset() to undo this operation. |
| 134072 | +** |
| 134073 | +** Caution: Do not confuse this routine with sqlite3ParseObjectInit() which |
| 134074 | +** is generated by Lemon. |
| 134075 | +*/ |
| 134076 | +SQLITE_PRIVATE void sqlite3ParseObjectInit(Parse *pParse, sqlite3 *db){ |
| 134077 | + memset(PARSE_HDR(pParse), 0, PARSE_HDR_SZ); |
| 134078 | + memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ); |
| 134079 | + assert( db->pParse!=pParse ); |
| 134080 | + pParse->pOuterParse = db->pParse; |
| 134081 | + db->pParse = pParse; |
| 134082 | + pParse->db = db; |
| 134083 | + if( db->mallocFailed ) sqlite3ErrorMsg(pParse, "out of memory"); |
| 134084 | +} |
| 133155 | 134085 | |
| 133156 | 134086 | /* |
| 133157 | 134087 | ** Compile the UTF-8 encoded SQL statement zSql into a statement handle. |
| 133158 | 134088 | */ |
| 133159 | 134089 | static int sqlite3Prepare( |
| | @@ -133167,15 +134097,19 @@ |
| 133167 | 134097 | ){ |
| 133168 | 134098 | int rc = SQLITE_OK; /* Result code */ |
| 133169 | 134099 | int i; /* Loop counter */ |
| 133170 | 134100 | Parse sParse; /* Parsing context */ |
| 133171 | 134101 | |
| 133172 | | - memset(&sParse, 0, PARSE_HDR_SZ); |
| 134102 | + /* sqlite3ParseObjectInit(&sParse, db); // inlined for performance */ |
| 134103 | + memset(PARSE_HDR(&sParse), 0, PARSE_HDR_SZ); |
| 133173 | 134104 | memset(PARSE_TAIL(&sParse), 0, PARSE_TAIL_SZ); |
| 134105 | + sParse.pOuterParse = db->pParse; |
| 134106 | + db->pParse = &sParse; |
| 134107 | + sParse.db = db; |
| 133174 | 134108 | sParse.pReprepare = pReprepare; |
| 133175 | 134109 | assert( ppStmt && *ppStmt==0 ); |
| 133176 | | - /* assert( !db->mallocFailed ); // not true with SQLITE_USE_ALLOCA */ |
| 134110 | + if( db->mallocFailed ) sqlite3ErrorMsg(&sParse, "out of memory"); |
| 133177 | 134111 | assert( sqlite3_mutex_held(db->mutex) ); |
| 133178 | 134112 | |
| 133179 | 134113 | /* For a long-term use prepared statement avoid the use of |
| 133180 | 134114 | ** lookaside memory. |
| 133181 | 134115 | */ |
| | @@ -133224,11 +134158,10 @@ |
| 133224 | 134158 | } |
| 133225 | 134159 | } |
| 133226 | 134160 | |
| 133227 | 134161 | sqlite3VtabUnlockList(db); |
| 133228 | 134162 | |
| 133229 | | - sParse.db = db; |
| 133230 | 134163 | if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){ |
| 133231 | 134164 | char *zSqlCopy; |
| 133232 | 134165 | int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH]; |
| 133233 | 134166 | testcase( nBytes==mxLen ); |
| 133234 | 134167 | testcase( nBytes==mxLen+1 ); |
| | @@ -133291,11 +134224,11 @@ |
| 133291 | 134224 | sqlite3DbFree(db, pT); |
| 133292 | 134225 | } |
| 133293 | 134226 | |
| 133294 | 134227 | end_prepare: |
| 133295 | 134228 | |
| 133296 | | - sqlite3ParserReset(&sParse); |
| 134229 | + sqlite3ParseObjectReset(&sParse); |
| 133297 | 134230 | return rc; |
| 133298 | 134231 | } |
| 133299 | 134232 | static int sqlite3LockAndPrepare( |
| 133300 | 134233 | sqlite3 *db, /* Database handle. */ |
| 133301 | 134234 | const char *zSql, /* UTF-8 encoded SQL statement. */ |
| | @@ -133563,11 +134496,11 @@ |
| 133563 | 134496 | ** how to process the DISTINCT keyword, to simplify passing that information |
| 133564 | 134497 | ** into the selectInnerLoop() routine. |
| 133565 | 134498 | */ |
| 133566 | 134499 | typedef struct DistinctCtx DistinctCtx; |
| 133567 | 134500 | struct DistinctCtx { |
| 133568 | | - u8 isTnct; /* True if the DISTINCT keyword is present */ |
| 134501 | + u8 isTnct; /* 0: Not distinct. 1: DISTICT 2: DISTINCT and ORDER BY */ |
| 133569 | 134502 | u8 eTnctType; /* One of the WHERE_DISTINCT_* operators */ |
| 133570 | 134503 | int tabTnct; /* Ephemeral table used for DISTINCT processing */ |
| 133571 | 134504 | int addrTnct; /* Address of OP_OpenEphemeral opcode for tabTnct */ |
| 133572 | 134505 | }; |
| 133573 | 134506 | |
| | @@ -133896,29 +134829,29 @@ |
| 133896 | 134829 | ** sqlite3PExpr(). */ |
| 133897 | 134830 | if( pEq && isOuterJoin ){ |
| 133898 | 134831 | ExprSetProperty(pEq, EP_FromJoin); |
| 133899 | 134832 | assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) ); |
| 133900 | 134833 | ExprSetVVAProperty(pEq, EP_NoReduce); |
| 133901 | | - pEq->iRightJoinTable = pE2->iTable; |
| 134834 | + pEq->w.iRightJoinTable = pE2->iTable; |
| 133902 | 134835 | } |
| 133903 | 134836 | *ppWhere = sqlite3ExprAnd(pParse, *ppWhere, pEq); |
| 133904 | 134837 | } |
| 133905 | 134838 | |
| 133906 | 134839 | /* |
| 133907 | 134840 | ** Set the EP_FromJoin property on all terms of the given expression. |
| 133908 | | -** And set the Expr.iRightJoinTable to iTable for every term in the |
| 134841 | +** And set the Expr.w.iRightJoinTable to iTable for every term in the |
| 133909 | 134842 | ** expression. |
| 133910 | 134843 | ** |
| 133911 | 134844 | ** The EP_FromJoin property is used on terms of an expression to tell |
| 133912 | 134845 | ** the LEFT OUTER JOIN processing logic that this term is part of the |
| 133913 | 134846 | ** join restriction specified in the ON or USING clause and not a part |
| 133914 | 134847 | ** of the more general WHERE clause. These terms are moved over to the |
| 133915 | 134848 | ** WHERE clause during join processing but we need to remember that they |
| 133916 | 134849 | ** originated in the ON or USING clause. |
| 133917 | 134850 | ** |
| 133918 | | -** The Expr.iRightJoinTable tells the WHERE clause processing that the |
| 133919 | | -** expression depends on table iRightJoinTable even if that table is not |
| 134851 | +** The Expr.w.iRightJoinTable tells the WHERE clause processing that the |
| 134852 | +** expression depends on table w.iRightJoinTable even if that table is not |
| 133920 | 134853 | ** explicitly mentioned in the expression. That information is needed |
| 133921 | 134854 | ** for cases like this: |
| 133922 | 134855 | ** |
| 133923 | 134856 | ** SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.b AND t1.x=5 |
| 133924 | 134857 | ** |
| | @@ -133932,11 +134865,11 @@ |
| 133932 | 134865 | SQLITE_PRIVATE void sqlite3SetJoinExpr(Expr *p, int iTable){ |
| 133933 | 134866 | while( p ){ |
| 133934 | 134867 | ExprSetProperty(p, EP_FromJoin); |
| 133935 | 134868 | assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) ); |
| 133936 | 134869 | ExprSetVVAProperty(p, EP_NoReduce); |
| 133937 | | - p->iRightJoinTable = iTable; |
| 134870 | + p->w.iRightJoinTable = iTable; |
| 133938 | 134871 | if( p->op==TK_FUNCTION ){ |
| 133939 | 134872 | assert( ExprUseXList(p) ); |
| 133940 | 134873 | if( p->x.pList ){ |
| 133941 | 134874 | int i; |
| 133942 | 134875 | for(i=0; i<p->x.pList->nExpr; i++){ |
| | @@ -133948,19 +134881,19 @@ |
| 133948 | 134881 | p = p->pRight; |
| 133949 | 134882 | } |
| 133950 | 134883 | } |
| 133951 | 134884 | |
| 133952 | 134885 | /* Undo the work of sqlite3SetJoinExpr(). In the expression p, convert every |
| 133953 | | -** term that is marked with EP_FromJoin and iRightJoinTable==iTable into |
| 134886 | +** term that is marked with EP_FromJoin and w.iRightJoinTable==iTable into |
| 133954 | 134887 | ** an ordinary term that omits the EP_FromJoin mark. |
| 133955 | 134888 | ** |
| 133956 | 134889 | ** This happens when a LEFT JOIN is simplified into an ordinary JOIN. |
| 133957 | 134890 | */ |
| 133958 | 134891 | static void unsetJoinExpr(Expr *p, int iTable){ |
| 133959 | 134892 | while( p ){ |
| 133960 | 134893 | if( ExprHasProperty(p, EP_FromJoin) |
| 133961 | | - && (iTable<0 || p->iRightJoinTable==iTable) ){ |
| 134894 | + && (iTable<0 || p->w.iRightJoinTable==iTable) ){ |
| 133962 | 134895 | ExprClearProperty(p, EP_FromJoin); |
| 133963 | 134896 | } |
| 133964 | 134897 | if( p->op==TK_COLUMN && p->iTable==iTable ){ |
| 133965 | 134898 | ExprClearProperty(p, EP_CanBeNull); |
| 133966 | 134899 | } |
| | @@ -134946,11 +135879,11 @@ |
| 134946 | 135879 | p->enc = ENC(db); |
| 134947 | 135880 | p->db = db; |
| 134948 | 135881 | p->nRef = 1; |
| 134949 | 135882 | memset(&p[1], 0, nExtra); |
| 134950 | 135883 | }else{ |
| 134951 | | - sqlite3OomFault(db); |
| 135884 | + return (KeyInfo*)sqlite3OomFault(db); |
| 134952 | 135885 | } |
| 134953 | 135886 | return p; |
| 134954 | 135887 | } |
| 134955 | 135888 | |
| 134956 | 135889 | /* |
| | @@ -135117,10 +136050,13 @@ |
| 135117 | 136050 | } |
| 135118 | 136051 | #endif |
| 135119 | 136052 | |
| 135120 | 136053 | iTab = pSort->iECursor; |
| 135121 | 136054 | if( eDest==SRT_Output || eDest==SRT_Coroutine || eDest==SRT_Mem ){ |
| 136055 | + if( eDest==SRT_Mem && p->iOffset ){ |
| 136056 | + sqlite3VdbeAddOp2(v, OP_Null, 0, pDest->iSdst); |
| 136057 | + } |
| 135122 | 136058 | regRowid = 0; |
| 135123 | 136059 | regRow = pDest->iSdst; |
| 135124 | 136060 | }else{ |
| 135125 | 136061 | regRowid = sqlite3GetTempReg(pParse); |
| 135126 | 136062 | if( eDest==SRT_EphemTab || eDest==SRT_Table ){ |
| | @@ -136162,11 +137098,11 @@ |
| 136162 | 137098 | ** (3) There is no ORDER BY clause |
| 136163 | 137099 | ** |
| 136164 | 137100 | ** The "LIMIT of exactly 1" case of condition (1) comes about when a VALUES |
| 136165 | 137101 | ** clause occurs within scalar expression (ex: "SELECT (VALUES(1),(2),(3))"). |
| 136166 | 137102 | ** The sqlite3CodeSubselect will have added the LIMIT 1 clause in tht case. |
| 136167 | | -** Since the limit is exactly 1, we only need to evalutes the left-most VALUES. |
| 137103 | +** Since the limit is exactly 1, we only need to evaluate the left-most VALUES. |
| 136168 | 137104 | */ |
| 136169 | 137105 | static int multiSelectValues( |
| 136170 | 137106 | Parse *pParse, /* Parsing context */ |
| 136171 | 137107 | Select *p, /* The right-most of SELECTs to be coded */ |
| 136172 | 137108 | SelectDest *pDest /* What to do with query results */ |
| | @@ -136975,10 +137911,11 @@ |
| 136975 | 137911 | }else{ |
| 136976 | 137912 | pSplit = p; |
| 136977 | 137913 | for(i=2; i<nSelect; i+=2){ pSplit = pSplit->pPrior; } |
| 136978 | 137914 | } |
| 136979 | 137915 | pPrior = pSplit->pPrior; |
| 137916 | + assert( pPrior!=0 ); |
| 136980 | 137917 | pSplit->pPrior = 0; |
| 136981 | 137918 | pPrior->pNext = 0; |
| 136982 | 137919 | assert( p->pOrderBy == pOrderBy ); |
| 136983 | 137920 | assert( pOrderBy!=0 || db->mallocFailed ); |
| 136984 | 137921 | pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0); |
| | @@ -137186,13 +138123,13 @@ |
| 137186 | 138123 | SubstContext *pSubst, /* Description of the substitution */ |
| 137187 | 138124 | Expr *pExpr /* Expr in which substitution occurs */ |
| 137188 | 138125 | ){ |
| 137189 | 138126 | if( pExpr==0 ) return 0; |
| 137190 | 138127 | if( ExprHasProperty(pExpr, EP_FromJoin) |
| 137191 | | - && pExpr->iRightJoinTable==pSubst->iTable |
| 138128 | + && pExpr->w.iRightJoinTable==pSubst->iTable |
| 137192 | 138129 | ){ |
| 137193 | | - pExpr->iRightJoinTable = pSubst->iNewTable; |
| 138130 | + pExpr->w.iRightJoinTable = pSubst->iNewTable; |
| 137194 | 138131 | } |
| 137195 | 138132 | if( pExpr->op==TK_COLUMN |
| 137196 | 138133 | && pExpr->iTable==pSubst->iTable |
| 137197 | 138134 | && !ExprHasProperty(pExpr, EP_FixedCol) |
| 137198 | 138135 | ){ |
| | @@ -137227,11 +138164,11 @@ |
| 137227 | 138164 | } |
| 137228 | 138165 | if( pSubst->isLeftJoin ){ |
| 137229 | 138166 | ExprSetProperty(pNew, EP_CanBeNull); |
| 137230 | 138167 | } |
| 137231 | 138168 | if( ExprHasProperty(pExpr,EP_FromJoin) ){ |
| 137232 | | - sqlite3SetJoinExpr(pNew, pExpr->iRightJoinTable); |
| 138169 | + sqlite3SetJoinExpr(pNew, pExpr->w.iRightJoinTable); |
| 137233 | 138170 | } |
| 137234 | 138171 | sqlite3ExprDelete(db, pExpr); |
| 137235 | 138172 | pExpr = pNew; |
| 137236 | 138173 | |
| 137237 | 138174 | /* Ensure that the expression now has an implicit collation sequence, |
| | @@ -137392,11 +138329,11 @@ |
| 137392 | 138329 | int op = pExpr->op; |
| 137393 | 138330 | if( op==TK_COLUMN || op==TK_IF_NULL_ROW ){ |
| 137394 | 138331 | renumberCursorDoMapping(pWalker, &pExpr->iTable); |
| 137395 | 138332 | } |
| 137396 | 138333 | if( ExprHasProperty(pExpr, EP_FromJoin) ){ |
| 137397 | | - renumberCursorDoMapping(pWalker, &pExpr->iRightJoinTable); |
| 138334 | + renumberCursorDoMapping(pWalker, &pExpr->w.iRightJoinTable); |
| 137398 | 138335 | } |
| 137399 | 138336 | return WRC_Continue; |
| 137400 | 138337 | } |
| 137401 | 138338 | |
| 137402 | 138339 | /* |
| | @@ -138402,15 +139339,17 @@ |
| 138402 | 139339 | iCursor, isLeftJoin); |
| 138403 | 139340 | pWhere = pWhere->pLeft; |
| 138404 | 139341 | } |
| 138405 | 139342 | if( isLeftJoin |
| 138406 | 139343 | && (ExprHasProperty(pWhere,EP_FromJoin)==0 |
| 138407 | | - || pWhere->iRightJoinTable!=iCursor) |
| 139344 | + || pWhere->w.iRightJoinTable!=iCursor) |
| 138408 | 139345 | ){ |
| 138409 | 139346 | return 0; /* restriction (4) */ |
| 138410 | 139347 | } |
| 138411 | | - if( ExprHasProperty(pWhere,EP_FromJoin) && pWhere->iRightJoinTable!=iCursor ){ |
| 139348 | + if( ExprHasProperty(pWhere,EP_FromJoin) |
| 139349 | + && pWhere->w.iRightJoinTable!=iCursor |
| 139350 | + ){ |
| 138412 | 139351 | return 0; /* restriction (5) */ |
| 138413 | 139352 | } |
| 138414 | 139353 | if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){ |
| 138415 | 139354 | nChng++; |
| 138416 | 139355 | pSubq->selFlags |= SF_PushDown; |
| | @@ -139126,11 +140065,12 @@ |
| 139126 | 140065 | } |
| 139127 | 140066 | } |
| 139128 | 140067 | |
| 139129 | 140068 | /* Process NATURAL keywords, and ON and USING clauses of joins. |
| 139130 | 140069 | */ |
| 139131 | | - if( pParse->nErr || db->mallocFailed || sqliteProcessJoin(pParse, p) ){ |
| 140070 | + assert( db->mallocFailed==0 || pParse->nErr!=0 ); |
| 140071 | + if( pParse->nErr || sqliteProcessJoin(pParse, p) ){ |
| 139132 | 140072 | return WRC_Abort; |
| 139133 | 140073 | } |
| 139134 | 140074 | |
| 139135 | 140075 | /* For every "*" that occurs in the column list, insert the names of |
| 139136 | 140076 | ** all columns in all tables. And for every TABLE.* insert the names |
| | @@ -139423,16 +140363,17 @@ |
| 139423 | 140363 | Parse *pParse, /* The parser context */ |
| 139424 | 140364 | Select *p, /* The SELECT statement being coded. */ |
| 139425 | 140365 | NameContext *pOuterNC /* Name context for container */ |
| 139426 | 140366 | ){ |
| 139427 | 140367 | assert( p!=0 || pParse->db->mallocFailed ); |
| 140368 | + assert( pParse->db->pParse==pParse ); |
| 139428 | 140369 | if( pParse->db->mallocFailed ) return; |
| 139429 | 140370 | if( p->selFlags & SF_HasTypeInfo ) return; |
| 139430 | 140371 | sqlite3SelectExpand(pParse, p); |
| 139431 | | - if( pParse->nErr || pParse->db->mallocFailed ) return; |
| 140372 | + if( pParse->nErr ) return; |
| 139432 | 140373 | sqlite3ResolveSelectNames(pParse, p, pOuterNC); |
| 139433 | | - if( pParse->nErr || pParse->db->mallocFailed ) return; |
| 140374 | + if( pParse->nErr ) return; |
| 139434 | 140375 | sqlite3SelectAddTypeInfo(pParse, p); |
| 139435 | 140376 | } |
| 139436 | 140377 | |
| 139437 | 140378 | /* |
| 139438 | 140379 | ** Reset the aggregate accumulator. |
| | @@ -139445,12 +140386,14 @@ |
| 139445 | 140386 | static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){ |
| 139446 | 140387 | Vdbe *v = pParse->pVdbe; |
| 139447 | 140388 | int i; |
| 139448 | 140389 | struct AggInfo_func *pFunc; |
| 139449 | 140390 | int nReg = pAggInfo->nFunc + pAggInfo->nColumn; |
| 140391 | + assert( pParse->db->pParse==pParse ); |
| 140392 | + assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 ); |
| 139450 | 140393 | if( nReg==0 ) return; |
| 139451 | | - if( pParse->nErr || pParse->db->mallocFailed ) return; |
| 140394 | + if( pParse->nErr ) return; |
| 139452 | 140395 | #ifdef SQLITE_DEBUG |
| 139453 | 140396 | /* Verify that all AggInfo registers are within the range specified by |
| 139454 | 140397 | ** AggInfo.mnReg..AggInfo.mxReg */ |
| 139455 | 140398 | assert( nReg==pAggInfo->mxReg-pAggInfo->mnReg+1 ); |
| 139456 | 140399 | for(i=0; i<pAggInfo->nColumn; i++){ |
| | @@ -139869,14 +140812,16 @@ |
| 139869 | 140812 | sqlite3 *db; /* The database connection */ |
| 139870 | 140813 | ExprList *pMinMaxOrderBy = 0; /* Added ORDER BY for min/max queries */ |
| 139871 | 140814 | u8 minMaxFlag; /* Flag for min/max queries */ |
| 139872 | 140815 | |
| 139873 | 140816 | db = pParse->db; |
| 140817 | + assert( pParse==db->pParse ); |
| 139874 | 140818 | v = sqlite3GetVdbe(pParse); |
| 139875 | | - if( p==0 || db->mallocFailed || pParse->nErr ){ |
| 140819 | + if( p==0 || pParse->nErr ){ |
| 139876 | 140820 | return 1; |
| 139877 | 140821 | } |
| 140822 | + assert( db->mallocFailed==0 ); |
| 139878 | 140823 | if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1; |
| 139879 | 140824 | #if SELECTTRACE_ENABLED |
| 139880 | 140825 | SELECTTRACE(1,pParse,p, ("begin processing:\n", pParse->addrExplain)); |
| 139881 | 140826 | if( sqlite3SelectTrace & 0x100 ){ |
| 139882 | 140827 | sqlite3TreeViewSelect(0, p, 0); |
| | @@ -139907,13 +140852,14 @@ |
| 139907 | 140852 | } |
| 139908 | 140853 | p->selFlags &= ~SF_Distinct; |
| 139909 | 140854 | p->selFlags |= SF_NoopOrderBy; |
| 139910 | 140855 | } |
| 139911 | 140856 | sqlite3SelectPrep(pParse, p, 0); |
| 139912 | | - if( pParse->nErr || db->mallocFailed ){ |
| 140857 | + if( pParse->nErr ){ |
| 139913 | 140858 | goto select_end; |
| 139914 | 140859 | } |
| 140860 | + assert( db->mallocFailed==0 ); |
| 139915 | 140861 | assert( p->pEList!=0 ); |
| 139916 | 140862 | #if SELECTTRACE_ENABLED |
| 139917 | 140863 | if( sqlite3SelectTrace & 0x104 ){ |
| 139918 | 140864 | SELECTTRACE(0x104,pParse,p, ("after name resolution:\n")); |
| 139919 | 140865 | sqlite3TreeViewSelect(0, p, 0); |
| | @@ -139953,11 +140899,11 @@ |
| 139953 | 140899 | sqlite3GenerateColumnNames(pParse, p); |
| 139954 | 140900 | } |
| 139955 | 140901 | |
| 139956 | 140902 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 139957 | 140903 | if( sqlite3WindowRewrite(pParse, p) ){ |
| 139958 | | - assert( db->mallocFailed || pParse->nErr>0 ); |
| 140904 | + assert( pParse->nErr ); |
| 139959 | 140905 | goto select_end; |
| 139960 | 140906 | } |
| 139961 | 140907 | #if SELECTTRACE_ENABLED |
| 139962 | 140908 | if( p->pWin && (sqlite3SelectTrace & 0x108)!=0 ){ |
| 139963 | 140909 | SELECTTRACE(0x104,pParse,p, ("after window rewrite:\n")); |
| | @@ -140350,10 +141296,11 @@ |
| 140350 | 141296 | p->selFlags |= SF_Aggregate; |
| 140351 | 141297 | /* Notice that even thought SF_Distinct has been cleared from p->selFlags, |
| 140352 | 141298 | ** the sDistinct.isTnct is still set. Hence, isTnct represents the |
| 140353 | 141299 | ** original setting of the SF_Distinct flag, not the current setting */ |
| 140354 | 141300 | assert( sDistinct.isTnct ); |
| 141301 | + sDistinct.isTnct = 2; |
| 140355 | 141302 | |
| 140356 | 141303 | #if SELECTTRACE_ENABLED |
| 140357 | 141304 | if( sqlite3SelectTrace & 0x400 ){ |
| 140358 | 141305 | SELECTTRACE(0x400,pParse,p,("Transform DISTINCT into GROUP BY:\n")); |
| 140359 | 141306 | sqlite3TreeViewSelect(0, p, 0); |
| | @@ -140429,11 +141376,11 @@ |
| 140429 | 141376 | |
| 140430 | 141377 | |
| 140431 | 141378 | /* Begin the database scan. */ |
| 140432 | 141379 | SELECTTRACE(1,pParse,p,("WhereBegin\n")); |
| 140433 | 141380 | pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, sSort.pOrderBy, |
| 140434 | | - p->pEList, wctrlFlags, p->nSelectRow); |
| 141381 | + p->pEList, p, wctrlFlags, p->nSelectRow); |
| 140435 | 141382 | if( pWInfo==0 ) goto select_end; |
| 140436 | 141383 | if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){ |
| 140437 | 141384 | p->nSelectRow = sqlite3WhereOutputRowCount(pWInfo); |
| 140438 | 141385 | } |
| 140439 | 141386 | if( sDistinct.isTnct && sqlite3WhereIsDistinct(pWInfo) ){ |
| | @@ -140693,11 +141640,12 @@ |
| 140693 | 141640 | ** in the right order to begin with. |
| 140694 | 141641 | */ |
| 140695 | 141642 | sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset); |
| 140696 | 141643 | SELECTTRACE(1,pParse,p,("WhereBegin\n")); |
| 140697 | 141644 | pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct, |
| 140698 | | - WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0 |
| 141645 | + 0, (sDistinct.isTnct==2 ? WHERE_DISTINCTBY : WHERE_GROUPBY) |
| 141646 | + | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0 |
| 140699 | 141647 | ); |
| 140700 | 141648 | if( pWInfo==0 ){ |
| 140701 | 141649 | sqlite3ExprListDelete(db, pDistinct); |
| 140702 | 141650 | goto select_end; |
| 140703 | 141651 | } |
| | @@ -140875,11 +141823,11 @@ |
| 140875 | 141823 | resetAccumulator(pParse, pAggInfo); |
| 140876 | 141824 | sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag); |
| 140877 | 141825 | VdbeComment((v, "indicate accumulator empty")); |
| 140878 | 141826 | sqlite3VdbeAddOp1(v, OP_Return, regReset); |
| 140879 | 141827 | |
| 140880 | | - if( eDist!=WHERE_DISTINCT_NOOP ){ |
| 141828 | + if( distFlag!=0 && eDist!=WHERE_DISTINCT_NOOP ){ |
| 140881 | 141829 | struct AggInfo_func *pF = &pAggInfo->aFunc[0]; |
| 140882 | 141830 | fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr); |
| 140883 | 141831 | } |
| 140884 | 141832 | } /* endif pGroupBy. Begin aggregate queries without GROUP BY: */ |
| 140885 | 141833 | else { |
| | @@ -140991,11 +141939,11 @@ |
| 140991 | 141939 | assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 ); |
| 140992 | 141940 | assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 ); |
| 140993 | 141941 | |
| 140994 | 141942 | SELECTTRACE(1,pParse,p,("WhereBegin\n")); |
| 140995 | 141943 | pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy, |
| 140996 | | - pDistinct, minMaxFlag|distFlag, 0); |
| 141944 | + pDistinct, 0, minMaxFlag|distFlag, 0); |
| 140997 | 141945 | if( pWInfo==0 ){ |
| 140998 | 141946 | goto select_end; |
| 140999 | 141947 | } |
| 141000 | 141948 | SELECTTRACE(1,pParse,p,("WhereBegin returns\n")); |
| 141001 | 141949 | eDist = sqlite3WhereIsDistinct(pWInfo); |
| | @@ -141048,11 +141996,11 @@ |
| 141048 | 141996 | /* Control jumps to here if an error is encountered above, or upon |
| 141049 | 141997 | ** successful coding of the SELECT. |
| 141050 | 141998 | */ |
| 141051 | 141999 | select_end: |
| 141052 | 142000 | assert( db->mallocFailed==0 || db->mallocFailed==1 ); |
| 141053 | | - pParse->nErr += db->mallocFailed; |
| 142001 | + assert( db->mallocFailed==0 || pParse->nErr!=0 ); |
| 141054 | 142002 | sqlite3ExprListDelete(db, pMinMaxOrderBy); |
| 141055 | 142003 | #ifdef SQLITE_DEBUG |
| 141056 | 142004 | if( pAggInfo && !db->mallocFailed ){ |
| 141057 | 142005 | for(i=0; i<pAggInfo->nColumn; i++){ |
| 141058 | 142006 | Expr *pExpr = pAggInfo->aCol[i].pCExpr; |
| | @@ -141349,15 +142297,14 @@ |
| 141349 | 142297 | && 0==sqlite3StrICmp(pTrig->table, pTab->zName) |
| 141350 | 142298 | && pTrig->pTabSchema!=pTmpSchema |
| 141351 | 142299 | ){ |
| 141352 | 142300 | pTrig->pNext = pList; |
| 141353 | 142301 | pList = pTrig; |
| 141354 | | - }else if( pTrig->op==TK_RETURNING |
| 142302 | + }else if( pTrig->op==TK_RETURNING ){ |
| 141355 | 142303 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 141356 | | - && pParse->db->pVtabCtx==0 |
| 142304 | + assert( pParse->db->pVtabCtx==0 ); |
| 141357 | 142305 | #endif |
| 141358 | | - ){ |
| 141359 | 142306 | assert( pParse->bReturning ); |
| 141360 | 142307 | assert( &(pParse->u1.pReturning->retTrig) == pTrig ); |
| 141361 | 142308 | pTrig->table = pTab->zName; |
| 141362 | 142309 | pTrig->pTabSchema = pTab->pSchema; |
| 141363 | 142310 | pTrig->pNext = pList; |
| | @@ -141728,10 +142675,11 @@ |
| 141728 | 142675 | const char *zEnd /* End of SQL text */ |
| 141729 | 142676 | ){ |
| 141730 | 142677 | sqlite3 *db = pParse->db; |
| 141731 | 142678 | TriggerStep *pTriggerStep; |
| 141732 | 142679 | |
| 142680 | + if( pParse->nErr ) return 0; |
| 141733 | 142681 | pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep) + pName->n + 1); |
| 141734 | 142682 | if( pTriggerStep ){ |
| 141735 | 142683 | char *z = (char*)&pTriggerStep[1]; |
| 141736 | 142684 | memcpy(z, pName->z, pName->n); |
| 141737 | 142685 | sqlite3Dequote(z); |
| | @@ -142200,10 +143148,11 @@ |
| 142200 | 143148 | Select sSelect; |
| 142201 | 143149 | SrcList sFrom; |
| 142202 | 143150 | |
| 142203 | 143151 | assert( v!=0 ); |
| 142204 | 143152 | assert( pParse->bReturning ); |
| 143153 | + assert( db->pParse==pParse ); |
| 142205 | 143154 | pReturning = pParse->u1.pReturning; |
| 142206 | 143155 | assert( pTrigger == &(pReturning->retTrig) ); |
| 142207 | 143156 | memset(&sSelect, 0, sizeof(sSelect)); |
| 142208 | 143157 | memset(&sFrom, 0, sizeof(sFrom)); |
| 142209 | 143158 | sSelect.pEList = sqlite3ExprListDup(db, pReturning->pReturnEL, 0); |
| | @@ -142210,11 +143159,12 @@ |
| 142210 | 143159 | sSelect.pSrc = &sFrom; |
| 142211 | 143160 | sFrom.nSrc = 1; |
| 142212 | 143161 | sFrom.a[0].pTab = pTab; |
| 142213 | 143162 | sFrom.a[0].iCursor = -1; |
| 142214 | 143163 | sqlite3SelectPrep(pParse, &sSelect, 0); |
| 142215 | | - if( db->mallocFailed==0 && pParse->nErr==0 ){ |
| 143164 | + if( pParse->nErr==0 ){ |
| 143165 | + assert( db->mallocFailed==0 ); |
| 142216 | 143166 | sqlite3GenerateColumnNames(pParse, &sSelect); |
| 142217 | 143167 | } |
| 142218 | 143168 | sqlite3ExprListDelete(db, sSelect.pEList); |
| 142219 | 143169 | pNew = sqlite3ExpandReturning(pParse, pReturning->pReturnEL, pTab); |
| 142220 | 143170 | if( !db->mallocFailed ){ |
| | @@ -142228,11 +143178,11 @@ |
| 142228 | 143178 | sNC.uNC.iBaseReg = regIn; |
| 142229 | 143179 | sNC.ncFlags = NC_UBaseReg; |
| 142230 | 143180 | pParse->eTriggerOp = pTrigger->op; |
| 142231 | 143181 | pParse->pTriggerTab = pTab; |
| 142232 | 143182 | if( sqlite3ResolveExprListNames(&sNC, pNew)==SQLITE_OK |
| 142233 | | - && !db->mallocFailed |
| 143183 | + && ALWAYS(!db->mallocFailed) |
| 142234 | 143184 | ){ |
| 142235 | 143185 | int i; |
| 142236 | 143186 | int nCol = pNew->nExpr; |
| 142237 | 143187 | int reg = pParse->nMem+1; |
| 142238 | 143188 | pParse->nMem += nCol+2; |
| | @@ -142392,12 +143342,12 @@ |
| 142392 | 143342 | TriggerPrg *pPrg; /* Value to return */ |
| 142393 | 143343 | Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */ |
| 142394 | 143344 | Vdbe *v; /* Temporary VM */ |
| 142395 | 143345 | NameContext sNC; /* Name context for sub-vdbe */ |
| 142396 | 143346 | SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */ |
| 142397 | | - Parse *pSubParse; /* Parse context for sub-vdbe */ |
| 142398 | 143347 | int iEndTrigger = 0; /* Label to jump to if WHEN is false */ |
| 143348 | + Parse sSubParse; /* Parse context for sub-vdbe */ |
| 142399 | 143349 | |
| 142400 | 143350 | assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) ); |
| 142401 | 143351 | assert( pTop->pVdbe ); |
| 142402 | 143352 | |
| 142403 | 143353 | /* Allocate the TriggerPrg and SubProgram objects. To ensure that they |
| | @@ -142415,23 +143365,21 @@ |
| 142415 | 143365 | pPrg->aColmask[0] = 0xffffffff; |
| 142416 | 143366 | pPrg->aColmask[1] = 0xffffffff; |
| 142417 | 143367 | |
| 142418 | 143368 | /* Allocate and populate a new Parse context to use for coding the |
| 142419 | 143369 | ** trigger sub-program. */ |
| 142420 | | - pSubParse = sqlite3StackAllocZero(db, sizeof(Parse)); |
| 142421 | | - if( !pSubParse ) return 0; |
| 143370 | + sqlite3ParseObjectInit(&sSubParse, db); |
| 142422 | 143371 | memset(&sNC, 0, sizeof(sNC)); |
| 142423 | | - sNC.pParse = pSubParse; |
| 142424 | | - pSubParse->db = db; |
| 142425 | | - pSubParse->pTriggerTab = pTab; |
| 142426 | | - pSubParse->pToplevel = pTop; |
| 142427 | | - pSubParse->zAuthContext = pTrigger->zName; |
| 142428 | | - pSubParse->eTriggerOp = pTrigger->op; |
| 142429 | | - pSubParse->nQueryLoop = pParse->nQueryLoop; |
| 142430 | | - pSubParse->disableVtab = pParse->disableVtab; |
| 142431 | | - |
| 142432 | | - v = sqlite3GetVdbe(pSubParse); |
| 143372 | + sNC.pParse = &sSubParse; |
| 143373 | + sSubParse.pTriggerTab = pTab; |
| 143374 | + sSubParse.pToplevel = pTop; |
| 143375 | + sSubParse.zAuthContext = pTrigger->zName; |
| 143376 | + sSubParse.eTriggerOp = pTrigger->op; |
| 143377 | + sSubParse.nQueryLoop = pParse->nQueryLoop; |
| 143378 | + sSubParse.disableVtab = pParse->disableVtab; |
| 143379 | + |
| 143380 | + v = sqlite3GetVdbe(&sSubParse); |
| 142433 | 143381 | if( v ){ |
| 142434 | 143382 | VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)", |
| 142435 | 143383 | pTrigger->zName, onErrorText(orconf), |
| 142436 | 143384 | (pTrigger->tr_tm==TRIGGER_BEFORE ? "BEFORE" : "AFTER"), |
| 142437 | 143385 | (pTrigger->op==TK_UPDATE ? "UPDATE" : ""), |
| | @@ -142453,42 +143401,43 @@ |
| 142453 | 143401 | if( pTrigger->pWhen ){ |
| 142454 | 143402 | pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0); |
| 142455 | 143403 | if( db->mallocFailed==0 |
| 142456 | 143404 | && SQLITE_OK==sqlite3ResolveExprNames(&sNC, pWhen) |
| 142457 | 143405 | ){ |
| 142458 | | - iEndTrigger = sqlite3VdbeMakeLabel(pSubParse); |
| 142459 | | - sqlite3ExprIfFalse(pSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL); |
| 143406 | + iEndTrigger = sqlite3VdbeMakeLabel(&sSubParse); |
| 143407 | + sqlite3ExprIfFalse(&sSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL); |
| 142460 | 143408 | } |
| 142461 | 143409 | sqlite3ExprDelete(db, pWhen); |
| 142462 | 143410 | } |
| 142463 | 143411 | |
| 142464 | 143412 | /* Code the trigger program into the sub-vdbe. */ |
| 142465 | | - codeTriggerProgram(pSubParse, pTrigger->step_list, orconf); |
| 143413 | + codeTriggerProgram(&sSubParse, pTrigger->step_list, orconf); |
| 142466 | 143414 | |
| 142467 | 143415 | /* Insert an OP_Halt at the end of the sub-program. */ |
| 142468 | 143416 | if( iEndTrigger ){ |
| 142469 | 143417 | sqlite3VdbeResolveLabel(v, iEndTrigger); |
| 142470 | 143418 | } |
| 142471 | 143419 | sqlite3VdbeAddOp0(v, OP_Halt); |
| 142472 | 143420 | VdbeComment((v, "End: %s.%s", pTrigger->zName, onErrorText(orconf))); |
| 143421 | + transferParseError(pParse, &sSubParse); |
| 142473 | 143422 | |
| 142474 | | - transferParseError(pParse, pSubParse); |
| 142475 | | - if( db->mallocFailed==0 && pParse->nErr==0 ){ |
| 143423 | + if( pParse->nErr==0 ){ |
| 143424 | + assert( db->mallocFailed==0 ); |
| 142476 | 143425 | pProgram->aOp = sqlite3VdbeTakeOpArray(v, &pProgram->nOp, &pTop->nMaxArg); |
| 142477 | 143426 | } |
| 142478 | | - pProgram->nMem = pSubParse->nMem; |
| 142479 | | - pProgram->nCsr = pSubParse->nTab; |
| 143427 | + pProgram->nMem = sSubParse.nMem; |
| 143428 | + pProgram->nCsr = sSubParse.nTab; |
| 142480 | 143429 | pProgram->token = (void *)pTrigger; |
| 142481 | | - pPrg->aColmask[0] = pSubParse->oldmask; |
| 142482 | | - pPrg->aColmask[1] = pSubParse->newmask; |
| 143430 | + pPrg->aColmask[0] = sSubParse.oldmask; |
| 143431 | + pPrg->aColmask[1] = sSubParse.newmask; |
| 142483 | 143432 | sqlite3VdbeDelete(v); |
| 143433 | + }else{ |
| 143434 | + transferParseError(pParse, &sSubParse); |
| 142484 | 143435 | } |
| 142485 | 143436 | |
| 142486 | | - assert( !pSubParse->pTriggerPrg && !pSubParse->nMaxArg ); |
| 142487 | | - sqlite3ParserReset(pSubParse); |
| 142488 | | - sqlite3StackFree(db, pSubParse); |
| 142489 | | - |
| 143437 | + assert( !sSubParse.pTriggerPrg && !sSubParse.nMaxArg ); |
| 143438 | + sqlite3ParseObjectReset(&sSubParse); |
| 142490 | 143439 | return pPrg; |
| 142491 | 143440 | } |
| 142492 | 143441 | |
| 142493 | 143442 | /* |
| 142494 | 143443 | ** Return a pointer to a TriggerPrg object containing the sub-program for |
| | @@ -142517,10 +143466,11 @@ |
| 142517 | 143466 | ); |
| 142518 | 143467 | |
| 142519 | 143468 | /* If an existing TriggerPrg could not be located, create a new one. */ |
| 142520 | 143469 | if( !pPrg ){ |
| 142521 | 143470 | pPrg = codeRowTrigger(pParse, pTrigger, pTab, orconf); |
| 143471 | + pParse->db->errByteOffset = -1; |
| 142522 | 143472 | } |
| 142523 | 143473 | |
| 142524 | 143474 | return pPrg; |
| 142525 | 143475 | } |
| 142526 | 143476 | |
| | @@ -142539,11 +143489,11 @@ |
| 142539 | 143489 | int ignoreJump /* Instruction to jump to for RAISE(IGNORE) */ |
| 142540 | 143490 | ){ |
| 142541 | 143491 | Vdbe *v = sqlite3GetVdbe(pParse); /* Main VM */ |
| 142542 | 143492 | TriggerPrg *pPrg; |
| 142543 | 143493 | pPrg = getRowTrigger(pParse, p, pTab, orconf); |
| 142544 | | - assert( pPrg || pParse->nErr || pParse->db->mallocFailed ); |
| 143494 | + assert( pPrg || pParse->nErr ); |
| 142545 | 143495 | |
| 142546 | 143496 | /* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program |
| 142547 | 143497 | ** is a pointer to the sub-vdbe containing the trigger program. */ |
| 142548 | 143498 | if( pPrg ){ |
| 142549 | 143499 | int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers)); |
| | @@ -143057,13 +144007,15 @@ |
| 143057 | 144007 | int regRowSet = 0; /* Rowset of rows to be updated */ |
| 143058 | 144008 | int regKey = 0; /* composite PRIMARY KEY value */ |
| 143059 | 144009 | |
| 143060 | 144010 | memset(&sContext, 0, sizeof(sContext)); |
| 143061 | 144011 | db = pParse->db; |
| 143062 | | - if( pParse->nErr || db->mallocFailed ){ |
| 144012 | + assert( db->pParse==pParse ); |
| 144013 | + if( pParse->nErr ){ |
| 143063 | 144014 | goto update_cleanup; |
| 143064 | 144015 | } |
| 144016 | + assert( db->mallocFailed==0 ); |
| 143065 | 144017 | |
| 143066 | 144018 | /* Locate the table which we want to update. |
| 143067 | 144019 | */ |
| 143068 | 144020 | pTab = sqlite3SrcListLookup(pParse, pTabList); |
| 143069 | 144021 | if( pTab==0 ) goto update_cleanup; |
| | @@ -143431,11 +144383,11 @@ |
| 143431 | 144383 | ** or index, causing a single-pass approach to malfunction. */ |
| 143432 | 144384 | flags = WHERE_ONEPASS_DESIRED; |
| 143433 | 144385 | if( !pParse->nested && !pTrigger && !hasFK && !chngKey && !bReplace ){ |
| 143434 | 144386 | flags |= WHERE_ONEPASS_MULTIROW; |
| 143435 | 144387 | } |
| 143436 | | - pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, flags,iIdxCur); |
| 144388 | + pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere,0,0,0,flags,iIdxCur); |
| 143437 | 144389 | if( pWInfo==0 ) goto update_cleanup; |
| 143438 | 144390 | |
| 143439 | 144391 | /* A one-pass strategy that might update more than one row may not |
| 143440 | 144392 | ** be used if any column of the index used for the scan is being |
| 143441 | 144393 | ** updated. Otherwise, if there is an index on "b", statements like |
| | @@ -143953,11 +144905,13 @@ |
| 143953 | 144905 | }else{ |
| 143954 | 144906 | regRec = ++pParse->nMem; |
| 143955 | 144907 | regRowid = ++pParse->nMem; |
| 143956 | 144908 | |
| 143957 | 144909 | /* Start scanning the virtual table */ |
| 143958 | | - pWInfo = sqlite3WhereBegin(pParse, pSrc,pWhere,0,0,WHERE_ONEPASS_DESIRED,0); |
| 144910 | + pWInfo = sqlite3WhereBegin( |
| 144911 | + pParse, pSrc, pWhere, 0, 0, 0, WHERE_ONEPASS_DESIRED, 0 |
| 144912 | + ); |
| 143959 | 144913 | if( pWInfo==0 ) return; |
| 143960 | 144914 | |
| 143961 | 144915 | /* Populate the argument registers. */ |
| 143962 | 144916 | for(i=0; i<pTab->nCol; i++){ |
| 143963 | 144917 | assert( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 ); |
| | @@ -145598,13 +146552,13 @@ |
| 145598 | 146552 | return SQLITE_MISUSE_BKPT; |
| 145599 | 146553 | } |
| 145600 | 146554 | pTab = pCtx->pTab; |
| 145601 | 146555 | assert( IsVirtual(pTab) ); |
| 145602 | 146556 | |
| 145603 | | - memset(&sParse, 0, sizeof(sParse)); |
| 146557 | + sqlite3ParseObjectInit(&sParse, db); |
| 145604 | 146558 | sParse.eParseMode = PARSE_MODE_DECLARE_VTAB; |
| 145605 | | - sParse.db = db; |
| 146559 | + sParse.disableTriggers = 1; |
| 145606 | 146560 | /* We should never be able to reach this point while loading the |
| 145607 | 146561 | ** schema. Nevertheless, defend against that (turn off db->init.busy) |
| 145608 | 146562 | ** in case a bug arises. */ |
| 145609 | 146563 | assert( db->init.busy==0 ); |
| 145610 | 146564 | initBusy = db->init.busy; |
| | @@ -145654,11 +146608,11 @@ |
| 145654 | 146608 | |
| 145655 | 146609 | if( sParse.pVdbe ){ |
| 145656 | 146610 | sqlite3VdbeFinalize(sParse.pVdbe); |
| 145657 | 146611 | } |
| 145658 | 146612 | sqlite3DeleteTable(db, sParse.pNewTable); |
| 145659 | | - sqlite3ParserReset(&sParse); |
| 146613 | + sqlite3ParseObjectReset(&sParse); |
| 145660 | 146614 | db->init.busy = initBusy; |
| 145661 | 146615 | |
| 145662 | 146616 | assert( (rc&0xff)==rc ); |
| 145663 | 146617 | rc = sqlite3ApiExit(db, rc); |
| 145664 | 146618 | sqlite3_mutex_leave(db->mutex); |
| | @@ -146265,14 +147219,16 @@ |
| 146265 | 147219 | u16 nDistinctCol; /* Index columns used to sort for DISTINCT */ |
| 146266 | 147220 | Index *pIndex; /* Index used, or NULL */ |
| 146267 | 147221 | } btree; |
| 146268 | 147222 | struct { /* Information for virtual tables */ |
| 146269 | 147223 | int idxNum; /* Index number */ |
| 146270 | | - u8 needFree; /* True if sqlite3_free(idxStr) is needed */ |
| 147224 | + u32 needFree : 1; /* True if sqlite3_free(idxStr) is needed */ |
| 147225 | + u32 bOmitOffset : 1; /* True to let virtual table handle offset */ |
| 146271 | 147226 | i8 isOrdered; /* True if satisfies ORDER BY */ |
| 146272 | 147227 | u16 omitMask; /* Terms that may be omitted */ |
| 146273 | 147228 | char *idxStr; /* Index identifier string */ |
| 147229 | + u32 mHandleIn; /* Terms to handle as IN(...) instead of == */ |
| 146274 | 147230 | } vtab; |
| 146275 | 147231 | } u; |
| 146276 | 147232 | u32 wsFlags; /* WHERE_* flags describing the plan */ |
| 146277 | 147233 | u16 nLTerm; /* Number of entries in aLTerm[] */ |
| 146278 | 147234 | u16 nSkip; /* Number of NULL aLTerm[] entries */ |
| | @@ -146425,10 +147381,11 @@ |
| 146425 | 147381 | #ifdef SQLITE_ENABLE_STAT4 |
| 146426 | 147382 | # define TERM_HIGHTRUTH 0x4000 /* Term excludes few rows */ |
| 146427 | 147383 | #else |
| 146428 | 147384 | # define TERM_HIGHTRUTH 0 /* Only used with STAT4 */ |
| 146429 | 147385 | #endif |
| 147386 | +#define TERM_SLICE 0x8000 /* One slice of a row-value/vector comparison */ |
| 146430 | 147387 | |
| 146431 | 147388 | /* |
| 146432 | 147389 | ** An instance of the WhereScan object is used as an iterator for locating |
| 146433 | 147390 | ** terms in the WHERE clause that are useful to the query planner. |
| 146434 | 147391 | */ |
| | @@ -146528,11 +147485,10 @@ |
| 146528 | 147485 | ** to construct WhereLoop objects for a particular query. |
| 146529 | 147486 | */ |
| 146530 | 147487 | struct WhereLoopBuilder { |
| 146531 | 147488 | WhereInfo *pWInfo; /* Information about this WHERE */ |
| 146532 | 147489 | WhereClause *pWC; /* WHERE clause terms */ |
| 146533 | | - ExprList *pOrderBy; /* ORDER BY clause */ |
| 146534 | 147490 | WhereLoop *pNew; /* Template WhereLoop */ |
| 146535 | 147491 | WhereOrSet *pOrSet; /* Record best loops here, if not NULL */ |
| 146536 | 147492 | #ifdef SQLITE_ENABLE_STAT4 |
| 146537 | 147493 | UnpackedRecord *pRec; /* Probe for stat4 (if required) */ |
| 146538 | 147494 | int nRecValid; /* Number of valid fields currently in pRec */ |
| | @@ -146596,10 +147552,13 @@ |
| 146596 | 147552 | Parse *pParse; /* Parsing and code generating context */ |
| 146597 | 147553 | SrcList *pTabList; /* List of tables in the join */ |
| 146598 | 147554 | ExprList *pOrderBy; /* The ORDER BY clause or NULL */ |
| 146599 | 147555 | ExprList *pResultSet; /* Result set of the query */ |
| 146600 | 147556 | Expr *pWhere; /* The complete WHERE clause */ |
| 147557 | +#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 147558 | + Select *pLimit; /* Used to access LIMIT expr/registers for vtabs */ |
| 147559 | +#endif |
| 146601 | 147560 | int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */ |
| 146602 | 147561 | int iContinue; /* Jump here to continue with next record */ |
| 146603 | 147562 | int iBreak; /* Jump here to break out of the loop */ |
| 146604 | 147563 | int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */ |
| 146605 | 147564 | u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */ |
| | @@ -146681,10 +147640,11 @@ |
| 146681 | 147640 | |
| 146682 | 147641 | /* whereexpr.c: */ |
| 146683 | 147642 | SQLITE_PRIVATE void sqlite3WhereClauseInit(WhereClause*,WhereInfo*); |
| 146684 | 147643 | SQLITE_PRIVATE void sqlite3WhereClauseClear(WhereClause*); |
| 146685 | 147644 | SQLITE_PRIVATE void sqlite3WhereSplit(WhereClause*,Expr*,u8); |
| 147645 | +SQLITE_PRIVATE void sqlite3WhereAddLimit(WhereClause*, Select*); |
| 146686 | 147646 | SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet*, Expr*); |
| 146687 | 147647 | SQLITE_PRIVATE Bitmask sqlite3WhereExprUsageNN(WhereMaskSet*, Expr*); |
| 146688 | 147648 | SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet*, ExprList*); |
| 146689 | 147649 | SQLITE_PRIVATE void sqlite3WhereExprAnalyze(SrcList*, WhereClause*); |
| 146690 | 147650 | SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(Parse*, SrcItem*, WhereClause*); |
| | @@ -146751,10 +147711,11 @@ |
| 146751 | 147711 | #define WHERE_BIGNULL_SORT 0x00080000 /* Column nEq of index is BIGNULL */ |
| 146752 | 147712 | #define WHERE_IN_SEEKSCAN 0x00100000 /* Seek-scan optimization for IN */ |
| 146753 | 147713 | #define WHERE_TRANSCONS 0x00200000 /* Uses a transitive constraint */ |
| 146754 | 147714 | #define WHERE_BLOOMFILTER 0x00400000 /* Consider using a Bloom-filter */ |
| 146755 | 147715 | #define WHERE_SELFCULL 0x00800000 /* nOut reduced by extra WHERE terms */ |
| 147716 | +#define WHERE_OMIT_OFFSET 0x01000000 /* Set offset counter to zero */ |
| 146756 | 147717 | |
| 146757 | 147718 | #endif /* !defined(SQLITE_WHEREINT_H) */ |
| 146758 | 147719 | |
| 146759 | 147720 | /************** End of whereInt.h ********************************************/ |
| 146760 | 147721 | /************** Continuing where we left off in wherecode.c ******************/ |
| | @@ -147529,10 +148490,11 @@ |
| 147529 | 148490 | sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur); |
| 147530 | 148491 | VdbeCoverageIf(v, bRev==0); |
| 147531 | 148492 | VdbeCoverageIf(v, bRev!=0); |
| 147532 | 148493 | VdbeComment((v, "begin skip-scan on %s", pIdx->zName)); |
| 147533 | 148494 | j = sqlite3VdbeAddOp0(v, OP_Goto); |
| 148495 | + assert( pLevel->addrSkip==0 ); |
| 147534 | 148496 | pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLT:OP_SeekGT), |
| 147535 | 148497 | iIdxCur, 0, regBase, nSkip); |
| 147536 | 148498 | VdbeCoverageIf(v, bRev==0); |
| 147537 | 148499 | VdbeCoverageIf(v, bRev!=0); |
| 147538 | 148500 | sqlite3VdbeJumpHere(v, j); |
| | @@ -147561,10 +148523,13 @@ |
| 147561 | 148523 | regBase = r1; |
| 147562 | 148524 | }else{ |
| 147563 | 148525 | sqlite3VdbeAddOp2(v, OP_Copy, r1, regBase+j); |
| 147564 | 148526 | } |
| 147565 | 148527 | } |
| 148528 | + } |
| 148529 | + for(j=nSkip; j<nEq; j++){ |
| 148530 | + pTerm = pLoop->aLTerm[j]; |
| 147566 | 148531 | if( pTerm->eOperator & WO_IN ){ |
| 147567 | 148532 | if( pTerm->pExpr->flags & EP_xIsSelect ){ |
| 147568 | 148533 | /* No affinity ever needs to be (or should be) applied to a value |
| 147569 | 148534 | ** from the RHS of an "? IN (SELECT ...)" expression. The |
| 147570 | 148535 | ** sqlite3FindInIndex() routine has already ensured that the |
| | @@ -147575,11 +148540,12 @@ |
| 147575 | 148540 | Expr *pRight = pTerm->pExpr->pRight; |
| 147576 | 148541 | if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){ |
| 147577 | 148542 | sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk); |
| 147578 | 148543 | VdbeCoverage(v); |
| 147579 | 148544 | } |
| 147580 | | - if( pParse->db->mallocFailed==0 && pParse->nErr==0 ){ |
| 148545 | + if( pParse->nErr==0 ){ |
| 148546 | + assert( pParse->db->mallocFailed==0 ); |
| 147581 | 148547 | if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_BLOB ){ |
| 147582 | 148548 | zAff[j] = SQLITE_AFF_BLOB; |
| 147583 | 148549 | } |
| 147584 | 148550 | if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){ |
| 147585 | 148551 | zAff[j] = SQLITE_AFF_BLOB; |
| | @@ -147795,11 +148761,11 @@ |
| 147795 | 148761 | ** are also excluded. See codeCursorHintIsOrFunction() for details. |
| 147796 | 148762 | */ |
| 147797 | 148763 | if( pTabItem->fg.jointype & JT_LEFT ){ |
| 147798 | 148764 | Expr *pExpr = pTerm->pExpr; |
| 147799 | 148765 | if( !ExprHasProperty(pExpr, EP_FromJoin) |
| 147800 | | - || pExpr->iRightJoinTable!=pTabItem->iCursor |
| 148766 | + || pExpr->w.iRightJoinTable!=pTabItem->iCursor |
| 147801 | 148767 | ){ |
| 147802 | 148768 | sWalker.eCode = 0; |
| 147803 | 148769 | sWalker.xExprCallback = codeCursorHintIsOrFunction; |
| 147804 | 148770 | sqlite3WalkExpr(&sWalker, pTerm->pExpr); |
| 147805 | 148771 | if( sWalker.eCode ) continue; |
| | @@ -147850,18 +148816,26 @@ |
| 147850 | 148816 | ** rowid stored in register iRowid. |
| 147851 | 148817 | ** |
| 147852 | 148818 | ** Normally, this is just: |
| 147853 | 148819 | ** |
| 147854 | 148820 | ** OP_DeferredSeek $iCur $iRowid |
| 148821 | +** |
| 148822 | +** Which causes a seek on $iCur to the row with rowid $iRowid. |
| 147855 | 148823 | ** |
| 147856 | 148824 | ** However, if the scan currently being coded is a branch of an OR-loop and |
| 147857 | | -** the statement currently being coded is a SELECT, then P3 of OP_DeferredSeek |
| 147858 | | -** is set to iIdxCur and P4 is set to point to an array of integers |
| 147859 | | -** containing one entry for each column of the table cursor iCur is open |
| 147860 | | -** on. For each table column, if the column is the i'th column of the |
| 147861 | | -** index, then the corresponding array entry is set to (i+1). If the column |
| 147862 | | -** does not appear in the index at all, the array entry is set to 0. |
| 148825 | +** the statement currently being coded is a SELECT, then additional information |
| 148826 | +** is added that might allow OP_Column to omit the seek and instead do its |
| 148827 | +** lookup on the index, thus avoiding an expensive seek operation. To |
| 148828 | +** enable this optimization, the P3 of OP_DeferredSeek is set to iIdxCur |
| 148829 | +** and P4 is set to an array of integers containing one entry for each column |
| 148830 | +** in the table. For each table column, if the column is the i'th |
| 148831 | +** column of the index, then the corresponding array entry is set to (i+1). |
| 148832 | +** If the column does not appear in the index at all, the array entry is set |
| 148833 | +** to 0. The OP_Column opcode can check this array to see if the column it |
| 148834 | +** wants is in the index and if it is, it will substitute the index cursor |
| 148835 | +** and column number and continue with those new values, rather than seeking |
| 148836 | +** the table cursor. |
| 147863 | 148837 | */ |
| 147864 | 148838 | static void codeDeferredSeek( |
| 147865 | 148839 | WhereInfo *pWInfo, /* Where clause context */ |
| 147866 | 148840 | Index *pIdx, /* Index scan is using */ |
| 147867 | 148841 | int iCur, /* Cursor for IPK b-tree */ |
| | @@ -148122,10 +149096,11 @@ |
| 148122 | 149096 | ){ |
| 148123 | 149097 | while( ++iLevel < pWInfo->nLevel ){ |
| 148124 | 149098 | WhereLevel *pLevel = &pWInfo->a[iLevel]; |
| 148125 | 149099 | WhereLoop *pLoop = pLevel->pWLoop; |
| 148126 | 149100 | if( pLevel->regFilter==0 ) continue; |
| 149101 | + if( pLevel->pWLoop->nSkip ) continue; |
| 148127 | 149102 | /* ,--- Because sqlite3ConstructBloomFilter() has will not have set |
| 148128 | 149103 | ** vvvvv--' pLevel->regFilter if this were true. */ |
| 148129 | 149104 | if( NEVER(pLoop->prereq & notReady) ) continue; |
| 148130 | 149105 | if( pLoop->wsFlags & WHERE_IPK ){ |
| 148131 | 149106 | WhereTerm *pTerm = pLoop->aLTerm[0]; |
| | @@ -148256,24 +149231,39 @@ |
| 148256 | 149231 | ** to access the data. |
| 148257 | 149232 | */ |
| 148258 | 149233 | int iReg; /* P3 Value for OP_VFilter */ |
| 148259 | 149234 | int addrNotFound; |
| 148260 | 149235 | int nConstraint = pLoop->nLTerm; |
| 148261 | | - int iIn; /* Counter for IN constraints */ |
| 148262 | 149236 | |
| 148263 | 149237 | iReg = sqlite3GetTempRange(pParse, nConstraint+2); |
| 148264 | 149238 | addrNotFound = pLevel->addrBrk; |
| 148265 | 149239 | for(j=0; j<nConstraint; j++){ |
| 148266 | 149240 | int iTarget = iReg+j+2; |
| 148267 | 149241 | pTerm = pLoop->aLTerm[j]; |
| 148268 | 149242 | if( NEVER(pTerm==0) ) continue; |
| 148269 | 149243 | if( pTerm->eOperator & WO_IN ){ |
| 148270 | | - codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, iTarget); |
| 148271 | | - addrNotFound = pLevel->addrNxt; |
| 149244 | + if( SMASKBIT32(j) & pLoop->u.vtab.mHandleIn ){ |
| 149245 | + int iTab = pParse->nTab++; |
| 149246 | + int iCache = ++pParse->nMem; |
| 149247 | + sqlite3CodeRhsOfIN(pParse, pTerm->pExpr, iTab); |
| 149248 | + sqlite3VdbeAddOp3(v, OP_VInitIn, iTab, iTarget, iCache); |
| 149249 | + }else{ |
| 149250 | + codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, iTarget); |
| 149251 | + addrNotFound = pLevel->addrNxt; |
| 149252 | + } |
| 148272 | 149253 | }else{ |
| 148273 | 149254 | Expr *pRight = pTerm->pExpr->pRight; |
| 148274 | 149255 | codeExprOrVector(pParse, pRight, iTarget, 1); |
| 149256 | + if( pTerm->eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET |
| 149257 | + && pLoop->u.vtab.bOmitOffset |
| 149258 | + ){ |
| 149259 | + assert( pTerm->eOperator==WO_AUX ); |
| 149260 | + assert( pWInfo->pLimit!=0 ); |
| 149261 | + assert( pWInfo->pLimit->iOffset>0 ); |
| 149262 | + sqlite3VdbeAddOp2(v, OP_Integer, 0, pWInfo->pLimit->iOffset); |
| 149263 | + VdbeComment((v,"Zero OFFSET counter")); |
| 149264 | + } |
| 148275 | 149265 | } |
| 148276 | 149266 | } |
| 148277 | 149267 | sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg); |
| 148278 | 149268 | sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1); |
| 148279 | 149269 | sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg, |
| | @@ -148286,61 +149276,71 @@ |
| 148286 | 149276 | if( db->mallocFailed ) pLoop->u.vtab.idxStr = 0; |
| 148287 | 149277 | pLevel->p1 = iCur; |
| 148288 | 149278 | pLevel->op = pWInfo->eOnePass ? OP_Noop : OP_VNext; |
| 148289 | 149279 | pLevel->p2 = sqlite3VdbeCurrentAddr(v); |
| 148290 | 149280 | assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 ); |
| 148291 | | - if( pLoop->wsFlags & WHERE_IN_ABLE ){ |
| 148292 | | - iIn = pLevel->u.in.nIn; |
| 148293 | | - }else{ |
| 148294 | | - iIn = 0; |
| 148295 | | - } |
| 148296 | | - for(j=nConstraint-1; j>=0; j--){ |
| 149281 | + |
| 149282 | + for(j=0; j<nConstraint; j++){ |
| 148297 | 149283 | pTerm = pLoop->aLTerm[j]; |
| 148298 | | - if( (pTerm->eOperator & WO_IN)!=0 ) iIn--; |
| 148299 | 149284 | if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){ |
| 148300 | 149285 | disableTerm(pLevel, pTerm); |
| 148301 | | - }else if( (pTerm->eOperator & WO_IN)!=0 |
| 148302 | | - && sqlite3ExprVectorSize(pTerm->pExpr->pLeft)==1 |
| 149286 | + continue; |
| 149287 | + } |
| 149288 | + if( (pTerm->eOperator & WO_IN)!=0 |
| 149289 | + && (SMASKBIT32(j) & pLoop->u.vtab.mHandleIn)==0 |
| 149290 | + && !db->mallocFailed |
| 148303 | 149291 | ){ |
| 148304 | 149292 | Expr *pCompare; /* The comparison operator */ |
| 148305 | 149293 | Expr *pRight; /* RHS of the comparison */ |
| 148306 | 149294 | VdbeOp *pOp; /* Opcode to access the value of the IN constraint */ |
| 149295 | + int iIn; /* IN loop corresponding to the j-th constraint */ |
| 148307 | 149296 | |
| 148308 | 149297 | /* Reload the constraint value into reg[iReg+j+2]. The same value |
| 148309 | 149298 | ** was loaded into the same register prior to the OP_VFilter, but |
| 148310 | 149299 | ** the xFilter implementation might have changed the datatype or |
| 148311 | | - ** encoding of the value in the register, so it *must* be reloaded. */ |
| 148312 | | - assert( pLevel->u.in.aInLoop!=0 || db->mallocFailed ); |
| 148313 | | - if( !db->mallocFailed ){ |
| 148314 | | - assert( iIn>=0 && iIn<pLevel->u.in.nIn ); |
| 149300 | + ** encoding of the value in the register, so it *must* be reloaded. |
| 149301 | + */ |
| 149302 | + for(iIn=0; ALWAYS(iIn<pLevel->u.in.nIn); iIn++){ |
| 148315 | 149303 | pOp = sqlite3VdbeGetOp(v, pLevel->u.in.aInLoop[iIn].addrInTop); |
| 148316 | | - assert( pOp->opcode==OP_Column || pOp->opcode==OP_Rowid ); |
| 148317 | | - assert( pOp->opcode!=OP_Column || pOp->p3==iReg+j+2 ); |
| 148318 | | - assert( pOp->opcode!=OP_Rowid || pOp->p2==iReg+j+2 ); |
| 148319 | | - testcase( pOp->opcode==OP_Rowid ); |
| 148320 | | - sqlite3VdbeAddOp3(v, pOp->opcode, pOp->p1, pOp->p2, pOp->p3); |
| 149304 | + if( (pOp->opcode==OP_Column && pOp->p3==iReg+j+2) |
| 149305 | + || (pOp->opcode==OP_Rowid && pOp->p2==iReg+j+2) |
| 149306 | + ){ |
| 149307 | + testcase( pOp->opcode==OP_Rowid ); |
| 149308 | + sqlite3VdbeAddOp3(v, pOp->opcode, pOp->p1, pOp->p2, pOp->p3); |
| 149309 | + break; |
| 149310 | + } |
| 148321 | 149311 | } |
| 148322 | 149312 | |
| 148323 | 149313 | /* Generate code that will continue to the next row if |
| 148324 | | - ** the IN constraint is not satisfied */ |
| 149314 | + ** the IN constraint is not satisfied |
| 149315 | + */ |
| 148325 | 149316 | pCompare = sqlite3PExpr(pParse, TK_EQ, 0, 0); |
| 148326 | | - assert( pCompare!=0 || db->mallocFailed ); |
| 148327 | | - if( pCompare ){ |
| 148328 | | - pCompare->pLeft = pTerm->pExpr->pLeft; |
| 149317 | + if( !db->mallocFailed ){ |
| 149318 | + int iFld = pTerm->u.x.iField; |
| 149319 | + Expr *pLeft = pTerm->pExpr->pLeft; |
| 149320 | + assert( pLeft!=0 ); |
| 149321 | + if( iFld>0 ){ |
| 149322 | + assert( pLeft->op==TK_VECTOR ); |
| 149323 | + assert( ExprUseXList(pLeft) ); |
| 149324 | + assert( iFld<=pLeft->x.pList->nExpr ); |
| 149325 | + pCompare->pLeft = pLeft->x.pList->a[iFld-1].pExpr; |
| 149326 | + }else{ |
| 149327 | + pCompare->pLeft = pLeft; |
| 149328 | + } |
| 148329 | 149329 | pCompare->pRight = pRight = sqlite3Expr(db, TK_REGISTER, 0); |
| 148330 | 149330 | if( pRight ){ |
| 148331 | 149331 | pRight->iTable = iReg+j+2; |
| 148332 | 149332 | sqlite3ExprIfFalse( |
| 148333 | 149333 | pParse, pCompare, pLevel->addrCont, SQLITE_JUMPIFNULL |
| 148334 | 149334 | ); |
| 148335 | 149335 | } |
| 148336 | 149336 | pCompare->pLeft = 0; |
| 148337 | | - sqlite3ExprDelete(db, pCompare); |
| 148338 | 149337 | } |
| 149338 | + sqlite3ExprDelete(db, pCompare); |
| 148339 | 149339 | } |
| 148340 | 149340 | } |
| 148341 | | - assert( iIn==0 || db->mallocFailed ); |
| 149341 | + |
| 148342 | 149342 | /* These registers need to be preserved in case there is an IN operator |
| 148343 | 149343 | ** loop. So we could deallocate the registers here (and potentially |
| 148344 | 149344 | ** reuse them later) if (pLoop->wsFlags & WHERE_IN_ABLE)==0. But it seems |
| 148345 | 149345 | ** simpler and safer to simply not reuse the registers. |
| 148346 | 149346 | ** |
| | @@ -149028,11 +150028,11 @@ |
| 149028 | 150028 | regRowid = ++pParse->nMem; |
| 149029 | 150029 | } |
| 149030 | 150030 | iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn); |
| 149031 | 150031 | |
| 149032 | 150032 | /* If the original WHERE clause is z of the form: (x1 OR x2 OR ...) AND y |
| 149033 | | - ** Then for every term xN, evaluate as the subexpression: xN AND z |
| 150033 | + ** Then for every term xN, evaluate as the subexpression: xN AND y |
| 149034 | 150034 | ** That way, terms in y that are factored into the disjunction will |
| 149035 | 150035 | ** be picked up by the recursive calls to sqlite3WhereBegin() below. |
| 149036 | 150036 | ** |
| 149037 | 150037 | ** Actually, each subexpression is converted to "xN AND w" where w is |
| 149038 | 150038 | ** the "interesting" terms of z - terms that did not originate in the |
| | @@ -149040,21 +150040,38 @@ |
| 149040 | 150040 | ** indices. |
| 149041 | 150041 | ** |
| 149042 | 150042 | ** This optimization also only applies if the (x1 OR x2 OR ...) term |
| 149043 | 150043 | ** is not contained in the ON clause of a LEFT JOIN. |
| 149044 | 150044 | ** See ticket http://www.sqlite.org/src/info/f2369304e4 |
| 150045 | + ** |
| 150046 | + ** 2022-02-04: Do not push down slices of a row-value comparison. |
| 150047 | + ** In other words, "w" or "y" may not be a slice of a vector. Otherwise, |
| 150048 | + ** the initialization of the right-hand operand of the vector comparison |
| 150049 | + ** might not occur, or might occur only in an OR branch that is not |
| 150050 | + ** taken. dbsqlfuzz 80a9fade844b4fb43564efc972bcb2c68270f5d1. |
| 150051 | + ** |
| 150052 | + ** 2022-03-03: Do not push down expressions that involve subqueries. |
| 150053 | + ** The subquery might get coded as a subroutine. Any table-references |
| 150054 | + ** in the subquery might be resolved to index-references for the index on |
| 150055 | + ** the OR branch in which the subroutine is coded. But if the subroutine |
| 150056 | + ** is invoked from a different OR branch that uses a different index, such |
| 150057 | + ** index-references will not work. tag-20220303a |
| 150058 | + ** https://sqlite.org/forum/forumpost/36937b197273d403 |
| 149045 | 150059 | */ |
| 149046 | 150060 | if( pWC->nTerm>1 ){ |
| 149047 | 150061 | int iTerm; |
| 149048 | 150062 | for(iTerm=0; iTerm<pWC->nTerm; iTerm++){ |
| 149049 | 150063 | Expr *pExpr = pWC->a[iTerm].pExpr; |
| 149050 | 150064 | if( &pWC->a[iTerm] == pTerm ) continue; |
| 149051 | 150065 | testcase( pWC->a[iTerm].wtFlags & TERM_VIRTUAL ); |
| 149052 | 150066 | testcase( pWC->a[iTerm].wtFlags & TERM_CODED ); |
| 149053 | | - if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED))!=0 ) continue; |
| 150067 | + testcase( pWC->a[iTerm].wtFlags & TERM_SLICE ); |
| 150068 | + if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED|TERM_SLICE))!=0 ){ |
| 150069 | + continue; |
| 150070 | + } |
| 149054 | 150071 | if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue; |
| 149055 | | - testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO ); |
| 150072 | + if( ExprHasProperty(pExpr, EP_Subquery) ) continue; /* tag-20220303a */ |
| 149056 | 150073 | pExpr = sqlite3ExprDup(db, pExpr, 0); |
| 149057 | 150074 | pAndExpr = sqlite3ExprAnd(pParse, pAndExpr, pExpr); |
| 149058 | 150075 | } |
| 149059 | 150076 | if( pAndExpr ){ |
| 149060 | 150077 | /* The extra 0x10000 bit on the opcode is masked off and does not |
| | @@ -149091,13 +150108,13 @@ |
| 149091 | 150108 | pOrExpr = pAndExpr; |
| 149092 | 150109 | } |
| 149093 | 150110 | /* Loop through table entries that match term pOrTerm. */ |
| 149094 | 150111 | ExplainQueryPlan((pParse, 1, "INDEX %d", ii+1)); |
| 149095 | 150112 | WHERETRACE(0xffff, ("Subplan for OR-clause:\n")); |
| 149096 | | - pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0, |
| 150113 | + pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0, 0, |
| 149097 | 150114 | WHERE_OR_SUBCLAUSE, iCovCur); |
| 149098 | | - assert( pSubWInfo || pParse->nErr || db->mallocFailed ); |
| 150115 | + assert( pSubWInfo || pParse->nErr ); |
| 149099 | 150116 | if( pSubWInfo ){ |
| 149100 | 150117 | WhereLoop *pSubLoop; |
| 149101 | 150118 | int addrExplain = sqlite3WhereExplainOneScan( |
| 149102 | 150119 | pParse, pOrTab, &pSubWInfo->a[0], 0 |
| 149103 | 150120 | ); |
| | @@ -149831,11 +150848,11 @@ |
| 149831 | 150848 | void *pNotUsed; |
| 149832 | 150849 | pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab; |
| 149833 | 150850 | assert( pVtab!=0 ); |
| 149834 | 150851 | assert( pVtab->pModule!=0 ); |
| 149835 | 150852 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 149836 | | - pMod = (sqlite3_module *)pVtab->pModule; |
| 150853 | + pMod = (sqlite3_module *)pVtab->pModule; |
| 149837 | 150854 | if( pMod->xFindFunction!=0 ){ |
| 149838 | 150855 | i = pMod->xFindFunction(pVtab,2, pExpr->u.zToken, &xNotUsed, &pNotUsed); |
| 149839 | 150856 | if( i>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){ |
| 149840 | 150857 | *peOp2 = i; |
| 149841 | 150858 | *ppRight = pList->a[1].pExpr; |
| | @@ -149875,11 +150892,11 @@ |
| 149875 | 150892 | ** a join, then transfer the appropriate markings over to derived. |
| 149876 | 150893 | */ |
| 149877 | 150894 | static void transferJoinMarkings(Expr *pDerived, Expr *pBase){ |
| 149878 | 150895 | if( pDerived ){ |
| 149879 | 150896 | pDerived->flags |= pBase->flags & EP_FromJoin; |
| 149880 | | - pDerived->iRightJoinTable = pBase->iRightJoinTable; |
| 150897 | + pDerived->w.iRightJoinTable = pBase->w.iRightJoinTable; |
| 149881 | 150898 | } |
| 149882 | 150899 | } |
| 149883 | 150900 | |
| 149884 | 150901 | /* |
| 149885 | 150902 | ** Mark term iChild as being a child of term iParent |
| | @@ -150520,11 +151537,11 @@ |
| 150520 | 151537 | abort(); |
| 150521 | 151538 | } |
| 150522 | 151539 | #endif |
| 150523 | 151540 | |
| 150524 | 151541 | if( ExprHasProperty(pExpr, EP_FromJoin) ){ |
| 150525 | | - Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->iRightJoinTable); |
| 151542 | + Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->w.iRightJoinTable); |
| 150526 | 151543 | prereqAll |= x; |
| 150527 | 151544 | extraRight = x-1; /* ON clause terms may not be used with an index |
| 150528 | 151545 | ** on left table of a LEFT JOIN. Ticket #3015 */ |
| 150529 | 151546 | if( (prereqAll>>1)>=x ){ |
| 150530 | 151547 | sqlite3ErrorMsg(pParse, "ON clause references tables to its right"); |
| | @@ -150788,11 +151805,14 @@ |
| 150788 | 151805 | ** new terms for each component comparison - "a = ?" and "b = ?". The |
| 150789 | 151806 | ** new terms completely replace the original vector comparison, which is |
| 150790 | 151807 | ** no longer used. |
| 150791 | 151808 | ** |
| 150792 | 151809 | ** This is only required if at least one side of the comparison operation |
| 150793 | | - ** is not a sub-select. */ |
| 151810 | + ** is not a sub-select. |
| 151811 | + ** |
| 151812 | + ** tag-20220128a |
| 151813 | + */ |
| 150794 | 151814 | if( (pExpr->op==TK_EQ || pExpr->op==TK_IS) |
| 150795 | 151815 | && (nLeft = sqlite3ExprVectorSize(pExpr->pLeft))>1 |
| 150796 | 151816 | && sqlite3ExprVectorSize(pExpr->pRight)==nLeft |
| 150797 | 151817 | && ( (pExpr->pLeft->flags & EP_xIsSelect)==0 |
| 150798 | 151818 | || (pExpr->pRight->flags & EP_xIsSelect)==0) |
| | @@ -150805,11 +151825,11 @@ |
| 150805 | 151825 | Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i, nLeft); |
| 150806 | 151826 | Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i, nLeft); |
| 150807 | 151827 | |
| 150808 | 151828 | pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight); |
| 150809 | 151829 | transferJoinMarkings(pNew, pExpr); |
| 150810 | | - idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC); |
| 151830 | + idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC|TERM_SLICE); |
| 150811 | 151831 | exprAnalyze(pSrc, pWC, idxNew); |
| 150812 | 151832 | } |
| 150813 | 151833 | pTerm = &pWC->a[idxTerm]; |
| 150814 | 151834 | pTerm->wtFlags |= TERM_CODED|TERM_VIRTUAL; /* Disable the original */ |
| 150815 | 151835 | pTerm->eOperator = 0; |
| | @@ -150835,11 +151855,11 @@ |
| 150835 | 151855 | && pWC->op==TK_AND |
| 150836 | 151856 | ){ |
| 150837 | 151857 | int i; |
| 150838 | 151858 | for(i=0; i<sqlite3ExprVectorSize(pExpr->pLeft); i++){ |
| 150839 | 151859 | int idxNew; |
| 150840 | | - idxNew = whereClauseInsert(pWC, pExpr, TERM_VIRTUAL); |
| 151860 | + idxNew = whereClauseInsert(pWC, pExpr, TERM_VIRTUAL|TERM_SLICE); |
| 150841 | 151861 | pWC->a[idxNew].u.x.iField = i+1; |
| 150842 | 151862 | exprAnalyze(pSrc, pWC, idxNew); |
| 150843 | 151863 | markTermAsChild(pWC, idxNew, idxTerm); |
| 150844 | 151864 | } |
| 150845 | 151865 | } |
| | @@ -150868,11 +151888,11 @@ |
| 150868 | 151888 | Expr *pNewExpr; |
| 150869 | 151889 | pNewExpr = sqlite3PExpr(pParse, TK_MATCH, |
| 150870 | 151890 | 0, sqlite3ExprDup(db, pRight, 0)); |
| 150871 | 151891 | if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){ |
| 150872 | 151892 | ExprSetProperty(pNewExpr, EP_FromJoin); |
| 150873 | | - pNewExpr->iRightJoinTable = pExpr->iRightJoinTable; |
| 151893 | + pNewExpr->w.iRightJoinTable = pExpr->w.iRightJoinTable; |
| 150874 | 151894 | } |
| 150875 | 151895 | idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC); |
| 150876 | 151896 | testcase( idxNew==0 ); |
| 150877 | 151897 | pNewTerm = &pWC->a[idxNew]; |
| 150878 | 151898 | pNewTerm->prereqRight = prereqExpr; |
| | @@ -150930,10 +151950,117 @@ |
| 150930 | 151950 | }else{ |
| 150931 | 151951 | sqlite3WhereSplit(pWC, pE2->pLeft, op); |
| 150932 | 151952 | sqlite3WhereSplit(pWC, pE2->pRight, op); |
| 150933 | 151953 | } |
| 150934 | 151954 | } |
| 151955 | + |
| 151956 | +/* |
| 151957 | +** Add either a LIMIT (if eMatchOp==SQLITE_INDEX_CONSTRAINT_LIMIT) or |
| 151958 | +** OFFSET (if eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET) term to the |
| 151959 | +** where-clause passed as the first argument. The value for the term |
| 151960 | +** is found in register iReg. |
| 151961 | +** |
| 151962 | +** In the common case where the value is a simple integer |
| 151963 | +** (example: "LIMIT 5 OFFSET 10") then the expression codes as a |
| 151964 | +** TK_INTEGER so that it will be available to sqlite3_vtab_rhs_value(). |
| 151965 | +** If not, then it codes as a TK_REGISTER expression. |
| 151966 | +*/ |
| 151967 | +static void whereAddLimitExpr( |
| 151968 | + WhereClause *pWC, /* Add the constraint to this WHERE clause */ |
| 151969 | + int iReg, /* Register that will hold value of the limit/offset */ |
| 151970 | + Expr *pExpr, /* Expression that defines the limit/offset */ |
| 151971 | + int iCsr, /* Cursor to which the constraint applies */ |
| 151972 | + int eMatchOp /* SQLITE_INDEX_CONSTRAINT_LIMIT or _OFFSET */ |
| 151973 | +){ |
| 151974 | + Parse *pParse = pWC->pWInfo->pParse; |
| 151975 | + sqlite3 *db = pParse->db; |
| 151976 | + Expr *pNew; |
| 151977 | + int iVal = 0; |
| 151978 | + |
| 151979 | + if( sqlite3ExprIsInteger(pExpr, &iVal) && iVal>=0 ){ |
| 151980 | + Expr *pVal = sqlite3Expr(db, TK_INTEGER, 0); |
| 151981 | + if( pVal==0 ) return; |
| 151982 | + ExprSetProperty(pVal, EP_IntValue); |
| 151983 | + pVal->u.iValue = iVal; |
| 151984 | + pNew = sqlite3PExpr(pParse, TK_MATCH, 0, pVal); |
| 151985 | + }else{ |
| 151986 | + Expr *pVal = sqlite3Expr(db, TK_REGISTER, 0); |
| 151987 | + if( pVal==0 ) return; |
| 151988 | + pVal->iTable = iReg; |
| 151989 | + pNew = sqlite3PExpr(pParse, TK_MATCH, 0, pVal); |
| 151990 | + } |
| 151991 | + if( pNew ){ |
| 151992 | + WhereTerm *pTerm; |
| 151993 | + int idx; |
| 151994 | + idx = whereClauseInsert(pWC, pNew, TERM_DYNAMIC|TERM_VIRTUAL); |
| 151995 | + pTerm = &pWC->a[idx]; |
| 151996 | + pTerm->leftCursor = iCsr; |
| 151997 | + pTerm->eOperator = WO_AUX; |
| 151998 | + pTerm->eMatchOp = eMatchOp; |
| 151999 | + } |
| 152000 | +} |
| 152001 | + |
| 152002 | +/* |
| 152003 | +** Possibly add terms corresponding to the LIMIT and OFFSET clauses of the |
| 152004 | +** SELECT statement passed as the second argument. These terms are only |
| 152005 | +** added if: |
| 152006 | +** |
| 152007 | +** 1. The SELECT statement has a LIMIT clause, and |
| 152008 | +** 2. The SELECT statement is not an aggregate or DISTINCT query, and |
| 152009 | +** 3. The SELECT statement has exactly one object in its from clause, and |
| 152010 | +** that object is a virtual table, and |
| 152011 | +** 4. There are no terms in the WHERE clause that will not be passed |
| 152012 | +** to the virtual table xBestIndex method. |
| 152013 | +** 5. The ORDER BY clause, if any, will be made available to the xBestIndex |
| 152014 | +** method. |
| 152015 | +** |
| 152016 | +** LIMIT and OFFSET terms are ignored by most of the planner code. They |
| 152017 | +** exist only so that they may be passed to the xBestIndex method of the |
| 152018 | +** single virtual table in the FROM clause of the SELECT. |
| 152019 | +*/ |
| 152020 | +SQLITE_PRIVATE void sqlite3WhereAddLimit(WhereClause *pWC, Select *p){ |
| 152021 | + assert( p==0 || (p->pGroupBy==0 && (p->selFlags & SF_Aggregate)==0) ); |
| 152022 | + if( (p && p->pLimit) /* 1 */ |
| 152023 | + && (p->selFlags & (SF_Distinct|SF_Aggregate))==0 /* 2 */ |
| 152024 | + && (p->pSrc->nSrc==1 && IsVirtual(p->pSrc->a[0].pTab)) /* 3 */ |
| 152025 | + ){ |
| 152026 | + ExprList *pOrderBy = p->pOrderBy; |
| 152027 | + int iCsr = p->pSrc->a[0].iCursor; |
| 152028 | + int ii; |
| 152029 | + |
| 152030 | + /* Check condition (4). Return early if it is not met. */ |
| 152031 | + for(ii=0; ii<pWC->nTerm; ii++){ |
| 152032 | + if( pWC->a[ii].wtFlags & TERM_CODED ){ |
| 152033 | + /* This term is a vector operation that has been decomposed into |
| 152034 | + ** other, subsequent terms. It can be ignored. See tag-20220128a */ |
| 152035 | + assert( pWC->a[ii].wtFlags & TERM_VIRTUAL ); |
| 152036 | + assert( pWC->a[ii].eOperator==0 ); |
| 152037 | + continue; |
| 152038 | + } |
| 152039 | + if( pWC->a[ii].leftCursor!=iCsr ) return; |
| 152040 | + } |
| 152041 | + |
| 152042 | + /* Check condition (5). Return early if it is not met. */ |
| 152043 | + if( pOrderBy ){ |
| 152044 | + for(ii=0; ii<pOrderBy->nExpr; ii++){ |
| 152045 | + Expr *pExpr = pOrderBy->a[ii].pExpr; |
| 152046 | + if( pExpr->op!=TK_COLUMN ) return; |
| 152047 | + if( pExpr->iTable!=iCsr ) return; |
| 152048 | + if( pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_BIGNULL ) return; |
| 152049 | + } |
| 152050 | + } |
| 152051 | + |
| 152052 | + /* All conditions are met. Add the terms to the where-clause object. */ |
| 152053 | + assert( p->pLimit->op==TK_LIMIT ); |
| 152054 | + whereAddLimitExpr(pWC, p->iLimit, p->pLimit->pLeft, |
| 152055 | + iCsr, SQLITE_INDEX_CONSTRAINT_LIMIT); |
| 152056 | + if( p->iOffset>0 ){ |
| 152057 | + whereAddLimitExpr(pWC, p->iOffset, p->pLimit->pRight, |
| 152058 | + iCsr, SQLITE_INDEX_CONSTRAINT_OFFSET); |
| 152059 | + } |
| 152060 | + } |
| 152061 | +} |
| 150935 | 152062 | |
| 150936 | 152063 | /* |
| 150937 | 152064 | ** Initialize a preallocated WhereClause structure. |
| 150938 | 152065 | */ |
| 150939 | 152066 | SQLITE_PRIVATE void sqlite3WhereClauseInit( |
| | @@ -150966,10 +152093,11 @@ |
| 150966 | 152093 | for(i=pWC->nBase; i<pWC->nTerm; i++){ |
| 150967 | 152094 | assert( (pWC->a[i].wtFlags & TERM_VIRTUAL)!=0 ); |
| 150968 | 152095 | } |
| 150969 | 152096 | #endif |
| 150970 | 152097 | while(1){ |
| 152098 | + assert( a->eMatchOp==0 || a->eOperator==WO_AUX ); |
| 150971 | 152099 | if( a->wtFlags & TERM_DYNAMIC ){ |
| 150972 | 152100 | sqlite3ExprDelete(db, a->pExpr); |
| 150973 | 152101 | } |
| 150974 | 152102 | if( a->wtFlags & (TERM_ORINFO|TERM_ANDINFO) ){ |
| 150975 | 152103 | if( a->wtFlags & TERM_ORINFO ){ |
| | @@ -151123,10 +152251,11 @@ |
| 151123 | 152251 | if( pColRef==0 ) return; |
| 151124 | 152252 | pColRef->iTable = pItem->iCursor; |
| 151125 | 152253 | pColRef->iColumn = k++; |
| 151126 | 152254 | assert( ExprUseYTab(pColRef) ); |
| 151127 | 152255 | pColRef->y.pTab = pTab; |
| 152256 | + pItem->colUsed |= sqlite3ExprColUsed(pColRef); |
| 151128 | 152257 | pRhs = sqlite3PExpr(pParse, TK_UPLUS, |
| 151129 | 152258 | sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0); |
| 151130 | 152259 | pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs); |
| 151131 | 152260 | if( pItem->fg.jointype & JT_LEFT ){ |
| 151132 | 152261 | sqlite3SetJoinExpr(pTerm, pItem->iCursor); |
| | @@ -151167,12 +152296,18 @@ |
| 151167 | 152296 | ** next. As long as allocateIndexInfo() and sqlite3_vtab_collation() |
| 151168 | 152297 | ** agree on the structure, all will be well. |
| 151169 | 152298 | */ |
| 151170 | 152299 | typedef struct HiddenIndexInfo HiddenIndexInfo; |
| 151171 | 152300 | struct HiddenIndexInfo { |
| 151172 | | - WhereClause *pWC; /* The Where clause being analyzed */ |
| 151173 | | - Parse *pParse; /* The parsing context */ |
| 152301 | + WhereClause *pWC; /* The Where clause being analyzed */ |
| 152302 | + Parse *pParse; /* The parsing context */ |
| 152303 | + int eDistinct; /* Value to return from sqlite3_vtab_distinct() */ |
| 152304 | + u32 mIn; /* Mask of terms that are <col> IN (...) */ |
| 152305 | + u32 mHandleIn; /* Terms that vtab will handle as <col> IN (...) */ |
| 152306 | + sqlite3_value *aRhs[1]; /* RHS values for constraints. MUST BE LAST |
| 152307 | + ** because extra space is allocated to hold up |
| 152308 | + ** to nTerm such values */ |
| 151174 | 152309 | }; |
| 151175 | 152310 | |
| 151176 | 152311 | /* Forward declaration of methods */ |
| 151177 | 152312 | static int whereLoopResize(sqlite3*, WhereLoop*, int); |
| 151178 | 152313 | |
| | @@ -152209,11 +153344,14 @@ |
| 152209 | 153344 | VdbeCoverage(v); |
| 152210 | 153345 | sqlite3VdbeJumpHere(v, addrTop); |
| 152211 | 153346 | pLoop->wsFlags &= ~WHERE_BLOOMFILTER; |
| 152212 | 153347 | if( OptimizationDisabled(pParse->db, SQLITE_BloomPulldown) ) break; |
| 152213 | 153348 | while( ++iLevel < pWInfo->nLevel ){ |
| 153349 | + const SrcItem *pTabItem; |
| 152214 | 153350 | pLevel = &pWInfo->a[iLevel]; |
| 153351 | + pTabItem = &pWInfo->pTabList->a[pLevel->iFrom]; |
| 153352 | + if( pTabItem->fg.jointype & JT_LEFT ) continue; |
| 152215 | 153353 | pLoop = pLevel->pWLoop; |
| 152216 | 153354 | if( NEVER(pLoop==0) ) continue; |
| 152217 | 153355 | if( pLoop->prereq & notReady ) continue; |
| 152218 | 153356 | if( (pLoop->wsFlags & (WHERE_BLOOMFILTER|WHERE_COLUMN_IN)) |
| 152219 | 153357 | ==WHERE_BLOOMFILTER |
| | @@ -152232,31 +153370,33 @@ |
| 152232 | 153370 | |
| 152233 | 153371 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 152234 | 153372 | /* |
| 152235 | 153373 | ** Allocate and populate an sqlite3_index_info structure. It is the |
| 152236 | 153374 | ** responsibility of the caller to eventually release the structure |
| 152237 | | -** by passing the pointer returned by this function to sqlite3_free(). |
| 153375 | +** by passing the pointer returned by this function to freeIndexInfo(). |
| 152238 | 153376 | */ |
| 152239 | 153377 | static sqlite3_index_info *allocateIndexInfo( |
| 152240 | | - Parse *pParse, /* The parsing context */ |
| 153378 | + WhereInfo *pWInfo, /* The WHERE clause */ |
| 152241 | 153379 | WhereClause *pWC, /* The WHERE clause being analyzed */ |
| 152242 | 153380 | Bitmask mUnusable, /* Ignore terms with these prereqs */ |
| 152243 | 153381 | SrcItem *pSrc, /* The FROM clause term that is the vtab */ |
| 152244 | | - ExprList *pOrderBy, /* The ORDER BY clause */ |
| 152245 | 153382 | u16 *pmNoOmit /* Mask of terms not to omit */ |
| 152246 | 153383 | ){ |
| 152247 | 153384 | int i, j; |
| 152248 | 153385 | int nTerm; |
| 153386 | + Parse *pParse = pWInfo->pParse; |
| 152249 | 153387 | struct sqlite3_index_constraint *pIdxCons; |
| 152250 | 153388 | struct sqlite3_index_orderby *pIdxOrderBy; |
| 152251 | 153389 | struct sqlite3_index_constraint_usage *pUsage; |
| 152252 | 153390 | struct HiddenIndexInfo *pHidden; |
| 152253 | 153391 | WhereTerm *pTerm; |
| 152254 | 153392 | int nOrderBy; |
| 152255 | 153393 | sqlite3_index_info *pIdxInfo; |
| 152256 | 153394 | u16 mNoOmit = 0; |
| 152257 | 153395 | const Table *pTab; |
| 153396 | + int eDistinct = 0; |
| 153397 | + ExprList *pOrderBy = pWInfo->pOrderBy; |
| 152258 | 153398 | |
| 152259 | 153399 | assert( pSrc!=0 ); |
| 152260 | 153400 | pTab = pSrc->pTab; |
| 152261 | 153401 | assert( pTab!=0 ); |
| 152262 | 153402 | assert( IsVirtual(pTab) ); |
| | @@ -152274,10 +153414,11 @@ |
| 152274 | 153414 | testcase( pTerm->eOperator & WO_ISNULL ); |
| 152275 | 153415 | testcase( pTerm->eOperator & WO_IS ); |
| 152276 | 153416 | testcase( pTerm->eOperator & WO_ALL ); |
| 152277 | 153417 | if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue; |
| 152278 | 153418 | if( pTerm->wtFlags & TERM_VNULL ) continue; |
| 153419 | + |
| 152279 | 153420 | assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 152280 | 153421 | assert( pTerm->u.x.leftColumn>=XN_ROWID ); |
| 152281 | 153422 | assert( pTerm->u.x.leftColumn<pTab->nCol ); |
| 152282 | 153423 | |
| 152283 | 153424 | /* tag-20191211-002: WHERE-clause constraints are not useful to the |
| | @@ -152335,40 +153476,53 @@ |
| 152335 | 153476 | } |
| 152336 | 153477 | |
| 152337 | 153478 | /* No matches cause a break out of the loop */ |
| 152338 | 153479 | break; |
| 152339 | 153480 | } |
| 152340 | | - if( i==n){ |
| 153481 | + if( i==n ){ |
| 152341 | 153482 | nOrderBy = n; |
| 153483 | + if( (pWInfo->wctrlFlags & WHERE_DISTINCTBY) ){ |
| 153484 | + eDistinct = 2 + ((pWInfo->wctrlFlags & WHERE_SORTBYGROUP)!=0); |
| 153485 | + }else if( pWInfo->wctrlFlags & WHERE_GROUPBY ){ |
| 153486 | + eDistinct = 1; |
| 153487 | + } |
| 152342 | 153488 | } |
| 152343 | 153489 | } |
| 152344 | 153490 | |
| 152345 | 153491 | /* Allocate the sqlite3_index_info structure |
| 152346 | 153492 | */ |
| 152347 | 153493 | pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo) |
| 152348 | 153494 | + (sizeof(*pIdxCons) + sizeof(*pUsage))*nTerm |
| 152349 | | - + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden) ); |
| 153495 | + + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden) |
| 153496 | + + sizeof(sqlite3_value*)*nTerm ); |
| 152350 | 153497 | if( pIdxInfo==0 ){ |
| 152351 | 153498 | sqlite3ErrorMsg(pParse, "out of memory"); |
| 152352 | 153499 | return 0; |
| 152353 | 153500 | } |
| 152354 | 153501 | pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1]; |
| 152355 | | - pIdxCons = (struct sqlite3_index_constraint*)&pHidden[1]; |
| 153502 | + pIdxCons = (struct sqlite3_index_constraint*)&pHidden->aRhs[nTerm]; |
| 152356 | 153503 | pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm]; |
| 152357 | 153504 | pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy]; |
| 152358 | 153505 | pIdxInfo->aConstraint = pIdxCons; |
| 152359 | 153506 | pIdxInfo->aOrderBy = pIdxOrderBy; |
| 152360 | 153507 | pIdxInfo->aConstraintUsage = pUsage; |
| 152361 | 153508 | pHidden->pWC = pWC; |
| 152362 | 153509 | pHidden->pParse = pParse; |
| 153510 | + pHidden->eDistinct = eDistinct; |
| 153511 | + pHidden->mIn = 0; |
| 152363 | 153512 | for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){ |
| 152364 | 153513 | u16 op; |
| 152365 | 153514 | if( (pTerm->wtFlags & TERM_OK)==0 ) continue; |
| 152366 | 153515 | pIdxCons[j].iColumn = pTerm->u.x.leftColumn; |
| 152367 | 153516 | pIdxCons[j].iTermOffset = i; |
| 152368 | 153517 | op = pTerm->eOperator & WO_ALL; |
| 152369 | | - if( op==WO_IN ) op = WO_EQ; |
| 153518 | + if( op==WO_IN ){ |
| 153519 | + if( (pTerm->wtFlags & TERM_SLICE)==0 ){ |
| 153520 | + pHidden->mIn |= SMASKBIT32(j); |
| 153521 | + } |
| 153522 | + op = WO_EQ; |
| 153523 | + } |
| 152370 | 153524 | if( op==WO_AUX ){ |
| 152371 | 153525 | pIdxCons[j].op = pTerm->eMatchOp; |
| 152372 | 153526 | }else if( op & (WO_ISNULL|WO_IS) ){ |
| 152373 | 153527 | if( op==WO_ISNULL ){ |
| 152374 | 153528 | pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_ISNULL; |
| | @@ -152414,10 +153568,28 @@ |
| 152414 | 153568 | pIdxInfo->nOrderBy = j; |
| 152415 | 153569 | |
| 152416 | 153570 | *pmNoOmit = mNoOmit; |
| 152417 | 153571 | return pIdxInfo; |
| 152418 | 153572 | } |
| 153573 | + |
| 153574 | +/* |
| 153575 | +** Free an sqlite3_index_info structure allocated by allocateIndexInfo() |
| 153576 | +** and possibly modified by xBestIndex methods. |
| 153577 | +*/ |
| 153578 | +static void freeIndexInfo(sqlite3 *db, sqlite3_index_info *pIdxInfo){ |
| 153579 | + HiddenIndexInfo *pHidden; |
| 153580 | + int i; |
| 153581 | + assert( pIdxInfo!=0 ); |
| 153582 | + pHidden = (HiddenIndexInfo*)&pIdxInfo[1]; |
| 153583 | + assert( pHidden->pParse!=0 ); |
| 153584 | + assert( pHidden->pParse->db==db ); |
| 153585 | + for(i=0; i<pIdxInfo->nConstraint; i++){ |
| 153586 | + sqlite3ValueFree(pHidden->aRhs[i]); /* IMP: R-14553-25174 */ |
| 153587 | + pHidden->aRhs[i] = 0; |
| 153588 | + } |
| 153589 | + sqlite3DbFree(db, pIdxInfo); |
| 153590 | +} |
| 152419 | 153591 | |
| 152420 | 153592 | /* |
| 152421 | 153593 | ** The table object reference passed as the second argument to this function |
| 152422 | 153594 | ** must represent a virtual table. This function invokes the xBestIndex() |
| 152423 | 153595 | ** method of the virtual table with the sqlite3_index_info object that |
| | @@ -152436,11 +153608,13 @@ |
| 152436 | 153608 | static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){ |
| 152437 | 153609 | sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab; |
| 152438 | 153610 | int rc; |
| 152439 | 153611 | |
| 152440 | 153612 | whereTraceIndexInfoInputs(p); |
| 153613 | + pParse->db->nSchemaLock++; |
| 152441 | 153614 | rc = pVtab->pModule->xBestIndex(pVtab, p); |
| 153615 | + pParse->db->nSchemaLock--; |
| 152442 | 153616 | whereTraceIndexInfoOutputs(p); |
| 152443 | 153617 | |
| 152444 | 153618 | if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){ |
| 152445 | 153619 | if( rc==SQLITE_NOMEM ){ |
| 152446 | 153620 | sqlite3OomFault(pParse->db); |
| | @@ -154265,11 +155439,11 @@ |
| 154265 | 155439 | } |
| 154266 | 155440 | if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0; |
| 154267 | 155441 | for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){ |
| 154268 | 155442 | Expr *pExpr; |
| 154269 | 155443 | pExpr = pTerm->pExpr; |
| 154270 | | - if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab) |
| 155444 | + if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->w.iRightJoinTable==iTab) |
| 154271 | 155445 | && (isLeft==0 || ExprHasProperty(pExpr, EP_FromJoin)) |
| 154272 | 155446 | && sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab) |
| 154273 | 155447 | && (pTerm->wtFlags & TERM_VNULL)==0 |
| 154274 | 155448 | ){ |
| 154275 | 155449 | return 1; |
| | @@ -154566,10 +155740,19 @@ |
| 154566 | 155740 | } |
| 154567 | 155741 | return rc; |
| 154568 | 155742 | } |
| 154569 | 155743 | |
| 154570 | 155744 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 155745 | + |
| 155746 | +/* |
| 155747 | +** Return true if pTerm is a virtual table LIMIT or OFFSET term. |
| 155748 | +*/ |
| 155749 | +static int isLimitTerm(WhereTerm *pTerm){ |
| 155750 | + assert( pTerm->eOperator==WO_AUX || pTerm->eMatchOp==0 ); |
| 155751 | + return pTerm->eMatchOp>=SQLITE_INDEX_CONSTRAINT_LIMIT |
| 155752 | + && pTerm->eMatchOp<=SQLITE_INDEX_CONSTRAINT_OFFSET; |
| 155753 | +} |
| 154571 | 155754 | |
| 154572 | 155755 | /* |
| 154573 | 155756 | ** Argument pIdxInfo is already populated with all constraints that may |
| 154574 | 155757 | ** be used by the virtual table identified by pBuilder->pNew->iTab. This |
| 154575 | 155758 | ** function marks a subset of those constraints usable, invokes the |
| | @@ -154594,13 +155777,15 @@ |
| 154594 | 155777 | Bitmask mPrereq, /* Mask of tables that must be used. */ |
| 154595 | 155778 | Bitmask mUsable, /* Mask of usable tables */ |
| 154596 | 155779 | u16 mExclude, /* Exclude terms using these operators */ |
| 154597 | 155780 | sqlite3_index_info *pIdxInfo, /* Populated object for xBestIndex */ |
| 154598 | 155781 | u16 mNoOmit, /* Do not omit these constraints */ |
| 154599 | | - int *pbIn /* OUT: True if plan uses an IN(...) op */ |
| 155782 | + int *pbIn, /* OUT: True if plan uses an IN(...) op */ |
| 155783 | + int *pbRetryLimit /* OUT: Retry without LIMIT/OFFSET */ |
| 154600 | 155784 | ){ |
| 154601 | 155785 | WhereClause *pWC = pBuilder->pWC; |
| 155786 | + HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1]; |
| 154602 | 155787 | struct sqlite3_index_constraint *pIdxCons; |
| 154603 | 155788 | struct sqlite3_index_constraint_usage *pUsage = pIdxInfo->aConstraintUsage; |
| 154604 | 155789 | int i; |
| 154605 | 155790 | int mxTerm; |
| 154606 | 155791 | int rc = SQLITE_OK; |
| | @@ -154619,10 +155804,11 @@ |
| 154619 | 155804 | for(i=0; i<nConstraint; i++, pIdxCons++){ |
| 154620 | 155805 | WhereTerm *pTerm = &pWC->a[pIdxCons->iTermOffset]; |
| 154621 | 155806 | pIdxCons->usable = 0; |
| 154622 | 155807 | if( (pTerm->prereqRight & mUsable)==pTerm->prereqRight |
| 154623 | 155808 | && (pTerm->eOperator & mExclude)==0 |
| 155809 | + && (pbRetryLimit || !isLimitTerm(pTerm)) |
| 154624 | 155810 | ){ |
| 154625 | 155811 | pIdxCons->usable = 1; |
| 154626 | 155812 | } |
| 154627 | 155813 | } |
| 154628 | 155814 | |
| | @@ -154634,10 +155820,11 @@ |
| 154634 | 155820 | pIdxInfo->orderByConsumed = 0; |
| 154635 | 155821 | pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2; |
| 154636 | 155822 | pIdxInfo->estimatedRows = 25; |
| 154637 | 155823 | pIdxInfo->idxFlags = 0; |
| 154638 | 155824 | pIdxInfo->colUsed = (sqlite3_int64)pSrc->colUsed; |
| 155825 | + pHidden->mHandleIn = 0; |
| 154639 | 155826 | |
| 154640 | 155827 | /* Invoke the virtual table xBestIndex() method */ |
| 154641 | 155828 | rc = vtabBestIndex(pParse, pSrc->pTab, pIdxInfo); |
| 154642 | 155829 | if( rc ){ |
| 154643 | 155830 | if( rc==SQLITE_CONSTRAINT ){ |
| | @@ -154651,12 +155838,12 @@ |
| 154651 | 155838 | return rc; |
| 154652 | 155839 | } |
| 154653 | 155840 | |
| 154654 | 155841 | mxTerm = -1; |
| 154655 | 155842 | assert( pNew->nLSlot>=nConstraint ); |
| 154656 | | - for(i=0; i<nConstraint; i++) pNew->aLTerm[i] = 0; |
| 154657 | | - pNew->u.vtab.omitMask = 0; |
| 155843 | + memset(pNew->aLTerm, 0, sizeof(pNew->aLTerm[0])*nConstraint ); |
| 155844 | + memset(&pNew->u.vtab, 0, sizeof(pNew->u.vtab)); |
| 154658 | 155845 | pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint; |
| 154659 | 155846 | for(i=0; i<nConstraint; i++, pIdxCons++){ |
| 154660 | 155847 | int iTerm; |
| 154661 | 155848 | if( (iTerm = pUsage[i].argvIndex - 1)>=0 ){ |
| 154662 | 155849 | WhereTerm *pTerm; |
| | @@ -154686,21 +155873,41 @@ |
| 154686 | 155873 | testcase( i!=iTerm ); |
| 154687 | 155874 | pNew->u.vtab.omitMask |= 1<<iTerm; |
| 154688 | 155875 | }else{ |
| 154689 | 155876 | testcase( i!=iTerm ); |
| 154690 | 155877 | } |
| 155878 | + if( pTerm->eMatchOp==SQLITE_INDEX_CONSTRAINT_OFFSET ){ |
| 155879 | + pNew->u.vtab.bOmitOffset = 1; |
| 155880 | + } |
| 154691 | 155881 | } |
| 154692 | | - if( (pTerm->eOperator & WO_IN)!=0 ){ |
| 155882 | + if( SMASKBIT32(i) & pHidden->mHandleIn ){ |
| 155883 | + pNew->u.vtab.mHandleIn |= MASKBIT32(iTerm); |
| 155884 | + }else if( (pTerm->eOperator & WO_IN)!=0 ){ |
| 154693 | 155885 | /* A virtual table that is constrained by an IN clause may not |
| 154694 | 155886 | ** consume the ORDER BY clause because (1) the order of IN terms |
| 154695 | 155887 | ** is not necessarily related to the order of output terms and |
| 154696 | 155888 | ** (2) Multiple outputs from a single IN value will not merge |
| 154697 | 155889 | ** together. */ |
| 154698 | 155890 | pIdxInfo->orderByConsumed = 0; |
| 154699 | 155891 | pIdxInfo->idxFlags &= ~SQLITE_INDEX_SCAN_UNIQUE; |
| 154700 | 155892 | *pbIn = 1; assert( (mExclude & WO_IN)==0 ); |
| 154701 | 155893 | } |
| 155894 | + |
| 155895 | + if( isLimitTerm(pTerm) && *pbIn ){ |
| 155896 | + /* If there is an IN(...) term handled as an == (separate call to |
| 155897 | + ** xFilter for each value on the RHS of the IN) and a LIMIT or |
| 155898 | + ** OFFSET term handled as well, the plan is unusable. Set output |
| 155899 | + ** variable *pbRetryLimit to true to tell the caller to retry with |
| 155900 | + ** LIMIT and OFFSET disabled. */ |
| 155901 | + if( pIdxInfo->needToFreeIdxStr ){ |
| 155902 | + sqlite3_free(pIdxInfo->idxStr); |
| 155903 | + pIdxInfo->idxStr = 0; |
| 155904 | + pIdxInfo->needToFreeIdxStr = 0; |
| 155905 | + } |
| 155906 | + *pbRetryLimit = 1; |
| 155907 | + return SQLITE_OK; |
| 155908 | + } |
| 154702 | 155909 | } |
| 154703 | 155910 | } |
| 154704 | 155911 | |
| 154705 | 155912 | pNew->nLTerm = mxTerm+1; |
| 154706 | 155913 | for(i=0; i<=mxTerm; i++){ |
| | @@ -154770,10 +155977,90 @@ |
| 154770 | 155977 | zRet = (pC ? pC->zName : sqlite3StrBINARY); |
| 154771 | 155978 | } |
| 154772 | 155979 | return zRet; |
| 154773 | 155980 | } |
| 154774 | 155981 | |
| 155982 | +/* |
| 155983 | +** Return true if constraint iCons is really an IN(...) constraint, or |
| 155984 | +** false otherwise. If iCons is an IN(...) constraint, set (if bHandle!=0) |
| 155985 | +** or clear (if bHandle==0) the flag to handle it using an iterator. |
| 155986 | +*/ |
| 155987 | +SQLITE_API int sqlite3_vtab_in(sqlite3_index_info *pIdxInfo, int iCons, int bHandle){ |
| 155988 | + HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1]; |
| 155989 | + u32 m = SMASKBIT32(iCons); |
| 155990 | + if( m & pHidden->mIn ){ |
| 155991 | + if( bHandle==0 ){ |
| 155992 | + pHidden->mHandleIn &= ~m; |
| 155993 | + }else if( bHandle>0 ){ |
| 155994 | + pHidden->mHandleIn |= m; |
| 155995 | + } |
| 155996 | + return 1; |
| 155997 | + } |
| 155998 | + return 0; |
| 155999 | +} |
| 156000 | + |
| 156001 | +/* |
| 156002 | +** This interface is callable from within the xBestIndex callback only. |
| 156003 | +** |
| 156004 | +** If possible, set (*ppVal) to point to an object containing the value |
| 156005 | +** on the right-hand-side of constraint iCons. |
| 156006 | +*/ |
| 156007 | +SQLITE_API int sqlite3_vtab_rhs_value( |
| 156008 | + sqlite3_index_info *pIdxInfo, /* Copy of first argument to xBestIndex */ |
| 156009 | + int iCons, /* Constraint for which RHS is wanted */ |
| 156010 | + sqlite3_value **ppVal /* Write value extracted here */ |
| 156011 | +){ |
| 156012 | + HiddenIndexInfo *pH = (HiddenIndexInfo*)&pIdxInfo[1]; |
| 156013 | + sqlite3_value *pVal = 0; |
| 156014 | + int rc = SQLITE_OK; |
| 156015 | + if( iCons<0 || iCons>=pIdxInfo->nConstraint ){ |
| 156016 | + rc = SQLITE_MISUSE; /* EV: R-30545-25046 */ |
| 156017 | + }else{ |
| 156018 | + if( pH->aRhs[iCons]==0 ){ |
| 156019 | + WhereTerm *pTerm = &pH->pWC->a[pIdxInfo->aConstraint[iCons].iTermOffset]; |
| 156020 | + rc = sqlite3ValueFromExpr( |
| 156021 | + pH->pParse->db, pTerm->pExpr->pRight, ENC(pH->pParse->db), |
| 156022 | + SQLITE_AFF_BLOB, &pH->aRhs[iCons] |
| 156023 | + ); |
| 156024 | + testcase( rc!=SQLITE_OK ); |
| 156025 | + } |
| 156026 | + pVal = pH->aRhs[iCons]; |
| 156027 | + } |
| 156028 | + *ppVal = pVal; |
| 156029 | + |
| 156030 | + if( rc==SQLITE_OK && pVal==0 ){ /* IMP: R-19933-32160 */ |
| 156031 | + rc = SQLITE_NOTFOUND; /* IMP: R-36424-56542 */ |
| 156032 | + } |
| 156033 | + |
| 156034 | + return rc; |
| 156035 | +} |
| 156036 | + |
| 156037 | +/* |
| 156038 | +** Return true if ORDER BY clause may be handled as DISTINCT. |
| 156039 | +*/ |
| 156040 | +SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info *pIdxInfo){ |
| 156041 | + HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1]; |
| 156042 | + assert( pHidden->eDistinct>=0 && pHidden->eDistinct<=3 ); |
| 156043 | + return pHidden->eDistinct; |
| 156044 | +} |
| 156045 | + |
| 156046 | +#if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \ |
| 156047 | + && !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 156048 | +/* |
| 156049 | +** Cause the prepared statement that is associated with a call to |
| 156050 | +** xBestIndex to open write transactions on all attached schemas. |
| 156051 | +** This is used by the (built-in) sqlite_dbpage virtual table. |
| 156052 | +*/ |
| 156053 | +SQLITE_PRIVATE void sqlite3VtabWriteAll(sqlite3_index_info *pIdxInfo){ |
| 156054 | + HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1]; |
| 156055 | + Parse *pParse = pHidden->pParse; |
| 156056 | + int nDb = pParse->db->nDb; |
| 156057 | + int i; |
| 156058 | + for(i=0; i<nDb; i++) sqlite3BeginWriteOperation(pParse, 0, i); |
| 156059 | +} |
| 156060 | +#endif |
| 156061 | + |
| 154775 | 156062 | /* |
| 154776 | 156063 | ** Add all WhereLoop objects for a table of the join identified by |
| 154777 | 156064 | ** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table. |
| 154778 | 156065 | ** |
| 154779 | 156066 | ** If there are no LEFT or CROSS JOIN joins in the query, both mPrereq and |
| | @@ -154811,35 +156098,43 @@ |
| 154811 | 156098 | int nConstraint; /* Number of constraints in p */ |
| 154812 | 156099 | int bIn; /* True if plan uses IN(...) operator */ |
| 154813 | 156100 | WhereLoop *pNew; |
| 154814 | 156101 | Bitmask mBest; /* Tables used by best possible plan */ |
| 154815 | 156102 | u16 mNoOmit; |
| 156103 | + int bRetry = 0; /* True to retry with LIMIT/OFFSET disabled */ |
| 154816 | 156104 | |
| 154817 | 156105 | assert( (mPrereq & mUnusable)==0 ); |
| 154818 | 156106 | pWInfo = pBuilder->pWInfo; |
| 154819 | 156107 | pParse = pWInfo->pParse; |
| 154820 | 156108 | pWC = pBuilder->pWC; |
| 154821 | 156109 | pNew = pBuilder->pNew; |
| 154822 | 156110 | pSrc = &pWInfo->pTabList->a[pNew->iTab]; |
| 154823 | 156111 | assert( IsVirtual(pSrc->pTab) ); |
| 154824 | | - p = allocateIndexInfo(pParse, pWC, mUnusable, pSrc, pBuilder->pOrderBy, |
| 154825 | | - &mNoOmit); |
| 156112 | + p = allocateIndexInfo(pWInfo, pWC, mUnusable, pSrc, &mNoOmit); |
| 154826 | 156113 | if( p==0 ) return SQLITE_NOMEM_BKPT; |
| 154827 | 156114 | pNew->rSetup = 0; |
| 154828 | 156115 | pNew->wsFlags = WHERE_VIRTUALTABLE; |
| 154829 | 156116 | pNew->nLTerm = 0; |
| 154830 | 156117 | pNew->u.vtab.needFree = 0; |
| 154831 | 156118 | nConstraint = p->nConstraint; |
| 154832 | 156119 | if( whereLoopResize(pParse->db, pNew, nConstraint) ){ |
| 154833 | | - sqlite3DbFree(pParse->db, p); |
| 156120 | + freeIndexInfo(pParse->db, p); |
| 154834 | 156121 | return SQLITE_NOMEM_BKPT; |
| 154835 | 156122 | } |
| 154836 | 156123 | |
| 154837 | 156124 | /* First call xBestIndex() with all constraints usable. */ |
| 154838 | 156125 | WHERETRACE(0x800, ("BEGIN %s.addVirtual()\n", pSrc->pTab->zName)); |
| 154839 | 156126 | WHERETRACE(0x40, (" VirtualOne: all usable\n")); |
| 154840 | | - rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn); |
| 156127 | + rc = whereLoopAddVirtualOne( |
| 156128 | + pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn, &bRetry |
| 156129 | + ); |
| 156130 | + if( bRetry ){ |
| 156131 | + assert( rc==SQLITE_OK ); |
| 156132 | + rc = whereLoopAddVirtualOne( |
| 156133 | + pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn, 0 |
| 156134 | + ); |
| 156135 | + } |
| 154841 | 156136 | |
| 154842 | 156137 | /* If the call to xBestIndex() with all terms enabled produced a plan |
| 154843 | 156138 | ** that does not require any source tables (IOW: a plan with mBest==0) |
| 154844 | 156139 | ** and does not use an IN(...) operator, then there is no point in making |
| 154845 | 156140 | ** any further calls to xBestIndex() since they will all return the same |
| | @@ -154853,11 +156148,11 @@ |
| 154853 | 156148 | /* If the plan produced by the earlier call uses an IN(...) term, call |
| 154854 | 156149 | ** xBestIndex again, this time with IN(...) terms disabled. */ |
| 154855 | 156150 | if( bIn ){ |
| 154856 | 156151 | WHERETRACE(0x40, (" VirtualOne: all usable w/o IN\n")); |
| 154857 | 156152 | rc = whereLoopAddVirtualOne( |
| 154858 | | - pBuilder, mPrereq, ALLBITS, WO_IN, p, mNoOmit, &bIn); |
| 156153 | + pBuilder, mPrereq, ALLBITS, WO_IN, p, mNoOmit, &bIn, 0); |
| 154859 | 156154 | assert( bIn==0 ); |
| 154860 | 156155 | mBestNoIn = pNew->prereq & ~mPrereq; |
| 154861 | 156156 | if( mBestNoIn==0 ){ |
| 154862 | 156157 | seenZero = 1; |
| 154863 | 156158 | seenZeroNoIN = 1; |
| | @@ -154880,11 +156175,11 @@ |
| 154880 | 156175 | if( mNext==ALLBITS ) break; |
| 154881 | 156176 | if( mNext==mBest || mNext==mBestNoIn ) continue; |
| 154882 | 156177 | WHERETRACE(0x40, (" VirtualOne: mPrev=%04llx mNext=%04llx\n", |
| 154883 | 156178 | (sqlite3_uint64)mPrev, (sqlite3_uint64)mNext)); |
| 154884 | 156179 | rc = whereLoopAddVirtualOne( |
| 154885 | | - pBuilder, mPrereq, mNext|mPrereq, 0, p, mNoOmit, &bIn); |
| 156180 | + pBuilder, mPrereq, mNext|mPrereq, 0, p, mNoOmit, &bIn, 0); |
| 154886 | 156181 | if( pNew->prereq==mPrereq ){ |
| 154887 | 156182 | seenZero = 1; |
| 154888 | 156183 | if( bIn==0 ) seenZeroNoIN = 1; |
| 154889 | 156184 | } |
| 154890 | 156185 | } |
| | @@ -154893,26 +156188,26 @@ |
| 154893 | 156188 | ** that requires no source tables at all (i.e. one guaranteed to be |
| 154894 | 156189 | ** usable), make a call here with all source tables disabled */ |
| 154895 | 156190 | if( rc==SQLITE_OK && seenZero==0 ){ |
| 154896 | 156191 | WHERETRACE(0x40, (" VirtualOne: all disabled\n")); |
| 154897 | 156192 | rc = whereLoopAddVirtualOne( |
| 154898 | | - pBuilder, mPrereq, mPrereq, 0, p, mNoOmit, &bIn); |
| 156193 | + pBuilder, mPrereq, mPrereq, 0, p, mNoOmit, &bIn, 0); |
| 154899 | 156194 | if( bIn==0 ) seenZeroNoIN = 1; |
| 154900 | 156195 | } |
| 154901 | 156196 | |
| 154902 | 156197 | /* If the calls to xBestIndex() have so far failed to find a plan |
| 154903 | 156198 | ** that requires no source tables at all and does not use an IN(...) |
| 154904 | 156199 | ** operator, make a final call to obtain one here. */ |
| 154905 | 156200 | if( rc==SQLITE_OK && seenZeroNoIN==0 ){ |
| 154906 | 156201 | WHERETRACE(0x40, (" VirtualOne: all disabled and w/o IN\n")); |
| 154907 | 156202 | rc = whereLoopAddVirtualOne( |
| 154908 | | - pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn); |
| 156203 | + pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn, 0); |
| 154909 | 156204 | } |
| 154910 | 156205 | } |
| 154911 | 156206 | |
| 154912 | 156207 | if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr); |
| 154913 | | - sqlite3DbFreeNN(pParse->db, p); |
| 156208 | + freeIndexInfo(pParse->db, p); |
| 154914 | 156209 | WHERETRACE(0x800, ("END %s.addVirtual(), rc=%d\n", pSrc->pTab->zName, rc)); |
| 154915 | 156210 | return rc; |
| 154916 | 156211 | } |
| 154917 | 156212 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 154918 | 156213 | |
| | @@ -154952,11 +156247,10 @@ |
| 154952 | 156247 | WhereTerm *pOrTerm; |
| 154953 | 156248 | int once = 1; |
| 154954 | 156249 | int i, j; |
| 154955 | 156250 | |
| 154956 | 156251 | sSubBuild = *pBuilder; |
| 154957 | | - sSubBuild.pOrderBy = 0; |
| 154958 | 156252 | sSubBuild.pOrSet = &sCur; |
| 154959 | 156253 | |
| 154960 | 156254 | WHERETRACE(0x200, ("Begin processing OR-clause %p\n", pTerm)); |
| 154961 | 156255 | for(pOrTerm=pOrWC->a; pOrTerm<pOrWCEnd; pOrTerm++){ |
| 154962 | 156256 | if( (pOrTerm->eOperator & WO_AND)!=0 ){ |
| | @@ -155202,11 +156496,13 @@ |
| 155202 | 156496 | if( wctrlFlags & WHERE_ORDERBY_LIMIT ) continue; |
| 155203 | 156497 | }else{ |
| 155204 | 156498 | pLoop = pLast; |
| 155205 | 156499 | } |
| 155206 | 156500 | if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){ |
| 155207 | | - if( pLoop->u.vtab.isOrdered && (wctrlFlags & WHERE_DISTINCTBY)==0 ){ |
| 156501 | + if( pLoop->u.vtab.isOrdered |
| 156502 | + && ((wctrlFlags&(WHERE_DISTINCTBY|WHERE_SORTBYGROUP))!=WHERE_DISTINCTBY) |
| 156503 | + ){ |
| 155208 | 156504 | obSat = obDone; |
| 155209 | 156505 | } |
| 155210 | 156506 | break; |
| 155211 | 156507 | }else if( wctrlFlags & WHERE_DISTINCTBY ){ |
| 155212 | 156508 | pLoop->u.btree.nDistinctCol = 0; |
| | @@ -155469,11 +156765,11 @@ |
| 155469 | 156765 | ** |
| 155470 | 156766 | ** SELECT * FROM t1 GROUP BY x,y ORDER BY x,y; -- IsSorted()==1 |
| 155471 | 156767 | ** SELECT * FROM t1 GROUP BY y,x ORDER BY y,x; -- IsSorted()==0 |
| 155472 | 156768 | */ |
| 155473 | 156769 | SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo *pWInfo){ |
| 155474 | | - assert( pWInfo->wctrlFlags & WHERE_GROUPBY ); |
| 156770 | + assert( pWInfo->wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY) ); |
| 155475 | 156771 | assert( pWInfo->wctrlFlags & WHERE_SORTBYGROUP ); |
| 155476 | 156772 | return pWInfo->sorted; |
| 155477 | 156773 | } |
| 155478 | 156774 | |
| 155479 | 156775 | #ifdef WHERETRACE_ENABLED |
| | @@ -155870,16 +157166,16 @@ |
| 155870 | 157166 | pWInfo->eDistinct = WHERE_DISTINCT_ORDERED; |
| 155871 | 157167 | } |
| 155872 | 157168 | } |
| 155873 | 157169 | pWInfo->bOrderedInnerLoop = 0; |
| 155874 | 157170 | if( pWInfo->pOrderBy ){ |
| 157171 | + pWInfo->nOBSat = pFrom->isOrdered; |
| 155875 | 157172 | if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){ |
| 155876 | 157173 | if( pFrom->isOrdered==pWInfo->pOrderBy->nExpr ){ |
| 155877 | 157174 | pWInfo->eDistinct = WHERE_DISTINCT_ORDERED; |
| 155878 | 157175 | } |
| 155879 | 157176 | }else{ |
| 155880 | | - pWInfo->nOBSat = pFrom->isOrdered; |
| 155881 | 157177 | pWInfo->revMask = pFrom->revLoop; |
| 155882 | 157178 | if( pWInfo->nOBSat<=0 ){ |
| 155883 | 157179 | pWInfo->nOBSat = 0; |
| 155884 | 157180 | if( nLoop>0 ){ |
| 155885 | 157181 | u32 wsFlags = pFrom->aLoop[nLoop-1]->wsFlags; |
| | @@ -156138,11 +157434,11 @@ |
| 156138 | 157434 | if( (tabUsed & pLoop->maskSelf)!=0 ) continue; |
| 156139 | 157435 | pEnd = pWInfo->sWC.a + pWInfo->sWC.nTerm; |
| 156140 | 157436 | for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){ |
| 156141 | 157437 | if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){ |
| 156142 | 157438 | if( !ExprHasProperty(pTerm->pExpr, EP_FromJoin) |
| 156143 | | - || pTerm->pExpr->iRightJoinTable!=pItem->iCursor |
| 157439 | + || pTerm->pExpr->w.iRightJoinTable!=pItem->iCursor |
| 156144 | 157440 | ){ |
| 156145 | 157441 | break; |
| 156146 | 157442 | } |
| 156147 | 157443 | } |
| 156148 | 157444 | } |
| | @@ -156310,10 +157606,11 @@ |
| 156310 | 157606 | Parse *pParse, /* The parser context */ |
| 156311 | 157607 | SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */ |
| 156312 | 157608 | Expr *pWhere, /* The WHERE clause */ |
| 156313 | 157609 | ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */ |
| 156314 | 157610 | ExprList *pResultSet, /* Query result set. Req'd for DISTINCT */ |
| 157611 | + Select *pLimit, /* Use this LIMIT/OFFSET clause, if any */ |
| 156315 | 157612 | u16 wctrlFlags, /* The WHERE_* flags defined in sqliteInt.h */ |
| 156316 | 157613 | int iAuxArg /* If WHERE_OR_SUBCLAUSE is set, index cursor number |
| 156317 | 157614 | ** If WHERE_USE_LIMIT, then the limit amount */ |
| 156318 | 157615 | ){ |
| 156319 | 157616 | int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */ |
| | @@ -156344,11 +157641,10 @@ |
| 156344 | 157641 | memset(&sWLB, 0, sizeof(sWLB)); |
| 156345 | 157642 | |
| 156346 | 157643 | /* An ORDER/GROUP BY clause of more than 63 terms cannot be optimized */ |
| 156347 | 157644 | testcase( pOrderBy && pOrderBy->nExpr==BMS-1 ); |
| 156348 | 157645 | if( pOrderBy && pOrderBy->nExpr>=BMS ) pOrderBy = 0; |
| 156349 | | - sWLB.pOrderBy = pOrderBy; |
| 156350 | 157646 | |
| 156351 | 157647 | /* The number of tables in the FROM clause is limited by the number of |
| 156352 | 157648 | ** bits in a Bitmask |
| 156353 | 157649 | */ |
| 156354 | 157650 | testcase( pTabList->nSrc==BMS ); |
| | @@ -156387,10 +157683,13 @@ |
| 156387 | 157683 | pWInfo->nLevel = nTabList; |
| 156388 | 157684 | pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(pParse); |
| 156389 | 157685 | pWInfo->wctrlFlags = wctrlFlags; |
| 156390 | 157686 | pWInfo->iLimit = iAuxArg; |
| 156391 | 157687 | pWInfo->savedNQueryLoop = pParse->nQueryLoop; |
| 157688 | +#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 157689 | + pWInfo->pLimit = pLimit; |
| 157690 | +#endif |
| 156392 | 157691 | memset(&pWInfo->nOBSat, 0, |
| 156393 | 157692 | offsetof(WhereInfo,sWC) - offsetof(WhereInfo,nOBSat)); |
| 156394 | 157693 | memset(&pWInfo->a[0], 0, sizeof(WhereLoop)+nTabList*sizeof(WhereLevel)); |
| 156395 | 157694 | assert( pWInfo->eOnePass==ONEPASS_OFF ); /* ONEPASS defaults to OFF */ |
| 156396 | 157695 | pMaskSet = &pWInfo->sMaskSet; |
| | @@ -156455,10 +157754,11 @@ |
| 156455 | 157754 | #endif |
| 156456 | 157755 | } |
| 156457 | 157756 | |
| 156458 | 157757 | /* Analyze all of the subexpressions. */ |
| 156459 | 157758 | sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC); |
| 157759 | + sqlite3WhereAddLimit(&pWInfo->sWC, pLimit); |
| 156460 | 157760 | if( db->mallocFailed ) goto whereBeginError; |
| 156461 | 157761 | |
| 156462 | 157762 | /* Special case: WHERE terms that do not refer to any tables in the join |
| 156463 | 157763 | ** (constant expressions). Evaluate each such term, and jump over all the |
| 156464 | 157764 | ** generated code if the result is not true. |
| | @@ -156554,13 +157854,14 @@ |
| 156554 | 157854 | } |
| 156555 | 157855 | } |
| 156556 | 157856 | if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){ |
| 156557 | 157857 | pWInfo->revMask = ALLBITS; |
| 156558 | 157858 | } |
| 156559 | | - if( pParse->nErr || db->mallocFailed ){ |
| 157859 | + if( pParse->nErr ){ |
| 156560 | 157860 | goto whereBeginError; |
| 156561 | 157861 | } |
| 157862 | + assert( db->mallocFailed==0 ); |
| 156562 | 157863 | #ifdef WHERETRACE_ENABLED |
| 156563 | 157864 | if( sqlite3WhereTrace ){ |
| 156564 | 157865 | sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut); |
| 156565 | 157866 | if( pWInfo->nOBSat>0 ){ |
| 156566 | 157867 | sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask); |
| | @@ -156700,10 +158001,11 @@ |
| 156700 | 158001 | testcase( pWInfo->eOnePass==ONEPASS_OFF && pTab->nCol==BMS-1 ); |
| 156701 | 158002 | testcase( pWInfo->eOnePass==ONEPASS_OFF && pTab->nCol==BMS ); |
| 156702 | 158003 | if( pWInfo->eOnePass==ONEPASS_OFF |
| 156703 | 158004 | && pTab->nCol<BMS |
| 156704 | 158005 | && (pTab->tabFlags & (TF_HasGenerated|TF_WithoutRowid))==0 |
| 158006 | + && (pLoop->wsFlags & (WHERE_AUTO_INDEX|WHERE_BLOOMFILTER))==0 |
| 156705 | 158007 | ){ |
| 156706 | 158008 | /* If we know that only a prefix of the record will be used, |
| 156707 | 158009 | ** it is advantageous to reduce the "column count" field in |
| 156708 | 158010 | ** the P4 operand of the OP_OpenRead/Write opcode. */ |
| 156709 | 158011 | Bitmask b = pTabItem->colUsed; |
| | @@ -156860,10 +158162,30 @@ |
| 156860 | 158162 | if( (db->flags & SQLITE_VdbeAddopTrace)==0 ) return; |
| 156861 | 158163 | sqlite3VdbePrintOp(0, pc, pOp); |
| 156862 | 158164 | } |
| 156863 | 158165 | #endif |
| 156864 | 158166 | |
| 158167 | +#ifdef SQLITE_DEBUG |
| 158168 | +/* |
| 158169 | +** Return true if cursor iCur is opened by instruction k of the |
| 158170 | +** bytecode. Used inside of assert() only. |
| 158171 | +*/ |
| 158172 | +static int cursorIsOpen(Vdbe *v, int iCur, int k){ |
| 158173 | + while( k>=0 ){ |
| 158174 | + VdbeOp *pOp = sqlite3VdbeGetOp(v,k--); |
| 158175 | + if( pOp->p1!=iCur ) continue; |
| 158176 | + if( pOp->opcode==OP_Close ) return 0; |
| 158177 | + if( pOp->opcode==OP_OpenRead ) return 1; |
| 158178 | + if( pOp->opcode==OP_OpenWrite ) return 1; |
| 158179 | + if( pOp->opcode==OP_OpenDup ) return 1; |
| 158180 | + if( pOp->opcode==OP_OpenAutoindex ) return 1; |
| 158181 | + if( pOp->opcode==OP_OpenEphemeral ) return 1; |
| 158182 | + } |
| 158183 | + return 0; |
| 158184 | +} |
| 158185 | +#endif /* SQLITE_DEBUG */ |
| 158186 | + |
| 156865 | 158187 | /* |
| 156866 | 158188 | ** Generate the end of the WHERE loop. See comments on |
| 156867 | 158189 | ** sqlite3WhereBegin() for additional information. |
| 156868 | 158190 | */ |
| 156869 | 158191 | SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){ |
| | @@ -157112,10 +158434,15 @@ |
| 157112 | 158434 | || pOp->opcode==OP_Offset |
| 157113 | 158435 | #endif |
| 157114 | 158436 | ){ |
| 157115 | 158437 | int x = pOp->p2; |
| 157116 | 158438 | assert( pIdx->pTable==pTab ); |
| 158439 | +#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC |
| 158440 | + if( pOp->opcode==OP_Offset ){ |
| 158441 | + /* Do not need to translate the column number */ |
| 158442 | + }else |
| 158443 | +#endif |
| 157117 | 158444 | if( !HasRowid(pTab) ){ |
| 157118 | 158445 | Index *pPk = sqlite3PrimaryKeyIndex(pTab); |
| 157119 | 158446 | x = pPk->aiColumn[x]; |
| 157120 | 158447 | assert( x>=0 ); |
| 157121 | 158448 | }else{ |
| | @@ -157125,13 +158452,26 @@ |
| 157125 | 158452 | x = sqlite3TableColumnToIndex(pIdx, x); |
| 157126 | 158453 | if( x>=0 ){ |
| 157127 | 158454 | pOp->p2 = x; |
| 157128 | 158455 | pOp->p1 = pLevel->iIdxCur; |
| 157129 | 158456 | OpcodeRewriteTrace(db, k, pOp); |
| 158457 | + }else{ |
| 158458 | + /* Unable to translate the table reference into an index |
| 158459 | + ** reference. Verify that this is harmless - that the |
| 158460 | + ** table being referenced really is open. |
| 158461 | + */ |
| 158462 | +#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC |
| 158463 | + assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 |
| 158464 | + || cursorIsOpen(v,pOp->p1,k) |
| 158465 | + || pOp->opcode==OP_Offset |
| 158466 | + ); |
| 158467 | +#else |
| 158468 | + assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 |
| 158469 | + || cursorIsOpen(v,pOp->p1,k) |
| 158470 | + ); |
| 158471 | +#endif |
| 157130 | 158472 | } |
| 157131 | | - assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0 |
| 157132 | | - || pWInfo->eOnePass ); |
| 157133 | 158473 | }else if( pOp->opcode==OP_Rowid ){ |
| 157134 | 158474 | pOp->p1 = pLevel->iIdxCur; |
| 157135 | 158475 | pOp->opcode = OP_IdxRowid; |
| 157136 | 158476 | OpcodeRewriteTrace(db, k, pOp); |
| 157137 | 158477 | }else if( pOp->opcode==OP_IfNullRow ){ |
| | @@ -157882,11 +159222,11 @@ |
| 157882 | 159222 | break; |
| 157883 | 159223 | } |
| 157884 | 159224 | } |
| 157885 | 159225 | } |
| 157886 | 159226 | } |
| 157887 | | - pWin->pFunc = pFunc; |
| 159227 | + pWin->pWFunc = pFunc; |
| 157888 | 159228 | } |
| 157889 | 159229 | |
| 157890 | 159230 | /* |
| 157891 | 159231 | ** Context object passed through sqlite3WalkExprList() to |
| 157892 | 159232 | ** selectWindowRewriteExprCb() by selectWindowRewriteEList(). |
| | @@ -158115,11 +159455,15 @@ |
| 158115 | 159455 | ** are invoked in the correct order as described under "SELECT REWRITING" |
| 158116 | 159456 | ** at the top of this file. |
| 158117 | 159457 | */ |
| 158118 | 159458 | SQLITE_PRIVATE int sqlite3WindowRewrite(Parse *pParse, Select *p){ |
| 158119 | 159459 | int rc = SQLITE_OK; |
| 158120 | | - if( p->pWin && p->pPrior==0 && ALWAYS((p->selFlags & SF_WinRewrite)==0) ){ |
| 159460 | + if( p->pWin |
| 159461 | + && p->pPrior==0 |
| 159462 | + && ALWAYS((p->selFlags & SF_WinRewrite)==0) |
| 159463 | + && ALWAYS(!IN_RENAME_OBJECT) |
| 159464 | + ){ |
| 158121 | 159465 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 158122 | 159466 | sqlite3 *db = pParse->db; |
| 158123 | 159467 | Select *pSub = 0; /* The subquery */ |
| 158124 | 159468 | SrcList *pSrc = p->pSrc; |
| 158125 | 159469 | Expr *pWhere = p->pWhere; |
| | @@ -158190,12 +159534,13 @@ |
| 158190 | 159534 | ** window function - one for the accumulator, another for interim |
| 158191 | 159535 | ** results. */ |
| 158192 | 159536 | for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ |
| 158193 | 159537 | ExprList *pArgs; |
| 158194 | 159538 | assert( ExprUseXList(pWin->pOwner) ); |
| 159539 | + assert( pWin->pWFunc!=0 ); |
| 158195 | 159540 | pArgs = pWin->pOwner->x.pList; |
| 158196 | | - if( pWin->pFunc->funcFlags & SQLITE_FUNC_SUBTYPE ){ |
| 159541 | + if( pWin->pWFunc->funcFlags & SQLITE_FUNC_SUBTYPE ){ |
| 158197 | 159542 | selectWindowRewriteEList(pParse, pMWin, pSrc, pArgs, pTab, &pSublist); |
| 158198 | 159543 | pWin->iArgCol = (pSublist ? pSublist->nExpr : 0); |
| 158199 | 159544 | pWin->bExprArgs = 1; |
| 158200 | 159545 | }else{ |
| 158201 | 159546 | pWin->iArgCol = (pSublist ? pSublist->nExpr : 0); |
| | @@ -158264,16 +159609,11 @@ |
| 158264 | 159609 | ** there could still be references to that table embedded in the |
| 158265 | 159610 | ** result-set or ORDER BY clause of the SELECT statement p. */ |
| 158266 | 159611 | sqlite3ParserAddCleanup(pParse, sqlite3DbFree, pTab); |
| 158267 | 159612 | } |
| 158268 | 159613 | |
| 158269 | | - if( rc ){ |
| 158270 | | - if( pParse->nErr==0 ){ |
| 158271 | | - assert( pParse->db->mallocFailed ); |
| 158272 | | - sqlite3ErrorToParser(pParse->db, SQLITE_NOMEM); |
| 158273 | | - } |
| 158274 | | - } |
| 159614 | + assert( rc==SQLITE_OK || pParse->nErr!=0 ); |
| 158275 | 159615 | return rc; |
| 158276 | 159616 | } |
| 158277 | 159617 | |
| 158278 | 159618 | /* |
| 158279 | 159619 | ** Unlink the Window object from the Select to which it is attached, |
| | @@ -158578,11 +159918,11 @@ |
| 158578 | 159918 | sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->csrApp, pMWin->iEphCsr); |
| 158579 | 159919 | return; |
| 158580 | 159920 | } |
| 158581 | 159921 | |
| 158582 | 159922 | for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ |
| 158583 | | - FuncDef *p = pWin->pFunc; |
| 159923 | + FuncDef *p = pWin->pWFunc; |
| 158584 | 159924 | if( (p->funcFlags & SQLITE_FUNC_MINMAX) && pWin->eStart!=TK_UNBOUNDED ){ |
| 158585 | 159925 | /* The inline versions of min() and max() require a single ephemeral |
| 158586 | 159926 | ** table and 3 registers. The registers are used as follows: |
| 158587 | 159927 | ** |
| 158588 | 159928 | ** regApp+0: slot to copy min()/max() argument to for MakeRecord |
| | @@ -158595,11 +159935,11 @@ |
| 158595 | 159935 | pList = pWin->pOwner->x.pList; |
| 158596 | 159936 | pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0); |
| 158597 | 159937 | pWin->csrApp = pParse->nTab++; |
| 158598 | 159938 | pWin->regApp = pParse->nMem+1; |
| 158599 | 159939 | pParse->nMem += 3; |
| 158600 | | - if( pKeyInfo && pWin->pFunc->zName[1]=='i' ){ |
| 159940 | + if( pKeyInfo && pWin->pWFunc->zName[1]=='i' ){ |
| 158601 | 159941 | assert( pKeyInfo->aSortFlags[0]==0 ); |
| 158602 | 159942 | pKeyInfo->aSortFlags[0] = KEYINFO_ORDER_DESC; |
| 158603 | 159943 | } |
| 158604 | 159944 | sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pWin->csrApp, 2); |
| 158605 | 159945 | sqlite3VdbeAppendP4(v, pKeyInfo, P4_KEYINFO); |
| | @@ -158818,11 +160158,11 @@ |
| 158818 | 160158 | ){ |
| 158819 | 160159 | Parse *pParse = p->pParse; |
| 158820 | 160160 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 158821 | 160161 | Window *pWin; |
| 158822 | 160162 | for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ |
| 158823 | | - FuncDef *pFunc = pWin->pFunc; |
| 160163 | + FuncDef *pFunc = pWin->pWFunc; |
| 158824 | 160164 | int regArg; |
| 158825 | 160165 | int nArg = pWin->bExprArgs ? 0 : windowArgCount(pWin); |
| 158826 | 160166 | int i; |
| 158827 | 160167 | |
| 158828 | 160168 | assert( bInverse==0 || pWin->eStart!=TK_UNBOUNDED ); |
| | @@ -158932,11 +160272,11 @@ |
| 158932 | 160272 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 158933 | 160273 | Window *pWin; |
| 158934 | 160274 | |
| 158935 | 160275 | for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ |
| 158936 | 160276 | if( pMWin->regStartRowid==0 |
| 158937 | | - && (pWin->pFunc->funcFlags & SQLITE_FUNC_MINMAX) |
| 160277 | + && (pWin->pWFunc->funcFlags & SQLITE_FUNC_MINMAX) |
| 158938 | 160278 | && (pWin->eStart!=TK_UNBOUNDED) |
| 158939 | 160279 | ){ |
| 158940 | 160280 | sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult); |
| 158941 | 160281 | sqlite3VdbeAddOp1(v, OP_Last, pWin->csrApp); |
| 158942 | 160282 | VdbeCoverage(v); |
| | @@ -158946,16 +160286,16 @@ |
| 158946 | 160286 | assert( pMWin->regStartRowid==0 ); |
| 158947 | 160287 | }else{ |
| 158948 | 160288 | int nArg = windowArgCount(pWin); |
| 158949 | 160289 | if( bFin ){ |
| 158950 | 160290 | sqlite3VdbeAddOp2(v, OP_AggFinal, pWin->regAccum, nArg); |
| 158951 | | - sqlite3VdbeAppendP4(v, pWin->pFunc, P4_FUNCDEF); |
| 160291 | + sqlite3VdbeAppendP4(v, pWin->pWFunc, P4_FUNCDEF); |
| 158952 | 160292 | sqlite3VdbeAddOp2(v, OP_Copy, pWin->regAccum, pWin->regResult); |
| 158953 | 160293 | sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum); |
| 158954 | 160294 | }else{ |
| 158955 | 160295 | sqlite3VdbeAddOp3(v, OP_AggValue,pWin->regAccum,nArg,pWin->regResult); |
| 158956 | | - sqlite3VdbeAppendP4(v, pWin->pFunc, P4_FUNCDEF); |
| 160296 | + sqlite3VdbeAppendP4(v, pWin->pWFunc, P4_FUNCDEF); |
| 158957 | 160297 | } |
| 158958 | 160298 | } |
| 158959 | 160299 | } |
| 158960 | 160300 | } |
| 158961 | 160301 | |
| | @@ -159080,11 +160420,11 @@ |
| 159080 | 160420 | }else{ |
| 159081 | 160421 | Parse *pParse = p->pParse; |
| 159082 | 160422 | Window *pWin; |
| 159083 | 160423 | |
| 159084 | 160424 | for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ |
| 159085 | | - FuncDef *pFunc = pWin->pFunc; |
| 160425 | + FuncDef *pFunc = pWin->pWFunc; |
| 159086 | 160426 | assert( ExprUseXList(pWin->pOwner) ); |
| 159087 | 160427 | if( pFunc->zName==nth_valueName |
| 159088 | 160428 | || pFunc->zName==first_valueName |
| 159089 | 160429 | ){ |
| 159090 | 160430 | int csr = pWin->csrApp; |
| | @@ -159152,11 +160492,11 @@ |
| 159152 | 160492 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 159153 | 160493 | int regArg; |
| 159154 | 160494 | int nArg = 0; |
| 159155 | 160495 | Window *pWin; |
| 159156 | 160496 | for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ |
| 159157 | | - FuncDef *pFunc = pWin->pFunc; |
| 160497 | + FuncDef *pFunc = pWin->pWFunc; |
| 159158 | 160498 | assert( pWin->regAccum ); |
| 159159 | 160499 | sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum); |
| 159160 | 160500 | nArg = MAX(nArg, windowArgCount(pWin)); |
| 159161 | 160501 | if( pMWin->regStartRowid==0 ){ |
| 159162 | 160502 | if( pFunc->zName==nth_valueName || pFunc->zName==first_valueName ){ |
| | @@ -159182,11 +160522,11 @@ |
| 159182 | 160522 | */ |
| 159183 | 160523 | static int windowCacheFrame(Window *pMWin){ |
| 159184 | 160524 | Window *pWin; |
| 159185 | 160525 | if( pMWin->regStartRowid ) return 1; |
| 159186 | 160526 | for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ |
| 159187 | | - FuncDef *pFunc = pWin->pFunc; |
| 160527 | + FuncDef *pFunc = pWin->pWFunc; |
| 159188 | 160528 | if( (pFunc->zName==nth_valueName) |
| 159189 | 160529 | || (pFunc->zName==first_valueName) |
| 159190 | 160530 | || (pFunc->zName==leadName) |
| 159191 | 160531 | || (pFunc->zName==lagName) |
| 159192 | 160532 | ){ |
| | @@ -159540,11 +160880,11 @@ |
| 159540 | 160880 | pNew = sqlite3DbMallocZero(db, sizeof(Window)); |
| 159541 | 160881 | if( pNew ){ |
| 159542 | 160882 | pNew->zName = sqlite3DbStrDup(db, p->zName); |
| 159543 | 160883 | pNew->zBase = sqlite3DbStrDup(db, p->zBase); |
| 159544 | 160884 | pNew->pFilter = sqlite3ExprDup(db, p->pFilter, 0); |
| 159545 | | - pNew->pFunc = p->pFunc; |
| 160885 | + pNew->pWFunc = p->pWFunc; |
| 159546 | 160886 | pNew->pPartition = sqlite3ExprListDup(db, p->pPartition, 0); |
| 159547 | 160887 | pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, 0); |
| 159548 | 160888 | pNew->eFrmType = p->eFrmType; |
| 159549 | 160889 | pNew->eEnd = p->eEnd; |
| 159550 | 160890 | pNew->eStart = p->eStart; |
| | @@ -160417,14 +161757,11 @@ |
| 160417 | 161757 | } |
| 160418 | 161758 | return pSelect; |
| 160419 | 161759 | } |
| 160420 | 161760 | |
| 160421 | 161761 | |
| 160422 | | - /* Construct a new Expr object from a single identifier. Use the |
| 160423 | | - ** new Expr to populate pOut. Set the span of pOut to be the identifier |
| 160424 | | - ** that created the expression. |
| 160425 | | - */ |
| 161762 | + /* Construct a new Expr object from a single token */ |
| 160426 | 161763 | static Expr *tokenExpr(Parse *pParse, int op, Token t){ |
| 160427 | 161764 | Expr *p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)+t.n+1); |
| 160428 | 161765 | if( p ){ |
| 160429 | 161766 | /* memset(p, 0, sizeof(Expr)); */ |
| 160430 | 161767 | p->op = (u8)op; |
| | @@ -160440,10 +161777,11 @@ |
| 160440 | 161777 | p->iTable = 0; |
| 160441 | 161778 | p->iColumn = 0; |
| 160442 | 161779 | p->u.zToken = (char*)&p[1]; |
| 160443 | 161780 | memcpy(p->u.zToken, t.z, t.n); |
| 160444 | 161781 | p->u.zToken[t.n] = 0; |
| 161782 | + p->w.iOfst = (int)(t.z - pParse->zTail); |
| 160445 | 161783 | if( sqlite3Isquote(p->u.zToken[0]) ){ |
| 160446 | 161784 | sqlite3DequoteExpr(p); |
| 160447 | 161785 | } |
| 160448 | 161786 | #if SQLITE_MAX_EXPR_DEPTH>0 |
| 160449 | 161787 | p->nHeight = 1; |
| | @@ -164251,11 +165589,11 @@ |
| 164251 | 165589 | } |
| 164252 | 165590 | break; |
| 164253 | 165591 | case 102: /* selcollist ::= sclp scanpt nm DOT STAR */ |
| 164254 | 165592 | { |
| 164255 | 165593 | Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0); |
| 164256 | | - Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1); |
| 165594 | + Expr *pLeft = tokenExpr(pParse, TK_ID, yymsp[-2].minor.yy0); |
| 164257 | 165595 | Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight); |
| 164258 | 165596 | yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, pDot); |
| 164259 | 165597 | } |
| 164260 | 165598 | break; |
| 164261 | 165599 | case 103: /* as ::= AS nm */ |
| | @@ -164536,29 +165874,24 @@ |
| 164536 | 165874 | case 179: /* expr ::= JOIN_KW */ yytestcase(yyruleno==179); |
| 164537 | 165875 | {yymsp[0].minor.yy528=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/} |
| 164538 | 165876 | break; |
| 164539 | 165877 | case 180: /* expr ::= nm DOT nm */ |
| 164540 | 165878 | { |
| 164541 | | - Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1); |
| 164542 | | - Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1); |
| 164543 | | - if( IN_RENAME_OBJECT ){ |
| 164544 | | - sqlite3RenameTokenMap(pParse, (void*)temp2, &yymsp[0].minor.yy0); |
| 164545 | | - sqlite3RenameTokenMap(pParse, (void*)temp1, &yymsp[-2].minor.yy0); |
| 164546 | | - } |
| 165879 | + Expr *temp1 = tokenExpr(pParse,TK_ID,yymsp[-2].minor.yy0); |
| 165880 | + Expr *temp2 = tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); |
| 164547 | 165881 | yylhsminor.yy528 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2); |
| 164548 | 165882 | } |
| 164549 | 165883 | yymsp[-2].minor.yy528 = yylhsminor.yy528; |
| 164550 | 165884 | break; |
| 164551 | 165885 | case 181: /* expr ::= nm DOT nm DOT nm */ |
| 164552 | 165886 | { |
| 164553 | | - Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-4].minor.yy0, 1); |
| 164554 | | - Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1); |
| 164555 | | - Expr *temp3 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1); |
| 165887 | + Expr *temp1 = tokenExpr(pParse,TK_ID,yymsp[-4].minor.yy0); |
| 165888 | + Expr *temp2 = tokenExpr(pParse,TK_ID,yymsp[-2].minor.yy0); |
| 165889 | + Expr *temp3 = tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); |
| 164556 | 165890 | Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3); |
| 164557 | 165891 | if( IN_RENAME_OBJECT ){ |
| 164558 | | - sqlite3RenameTokenMap(pParse, (void*)temp3, &yymsp[0].minor.yy0); |
| 164559 | | - sqlite3RenameTokenMap(pParse, (void*)temp2, &yymsp[-2].minor.yy0); |
| 165892 | + sqlite3RenameTokenRemap(pParse, 0, temp1); |
| 164560 | 165893 | } |
| 164561 | 165894 | yylhsminor.yy528 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4); |
| 164562 | 165895 | } |
| 164563 | 165896 | yymsp[-4].minor.yy528 = yylhsminor.yy528; |
| 164564 | 165897 | break; |
| | @@ -164567,10 +165900,11 @@ |
| 164567 | 165900 | {yymsp[0].minor.yy528=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/} |
| 164568 | 165901 | break; |
| 164569 | 165902 | case 184: /* term ::= INTEGER */ |
| 164570 | 165903 | { |
| 164571 | 165904 | yylhsminor.yy528 = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1); |
| 165905 | + if( yylhsminor.yy528 ) yylhsminor.yy528->w.iOfst = (int)(yymsp[0].minor.yy0.z - pParse->zTail); |
| 164572 | 165906 | } |
| 164573 | 165907 | yymsp[0].minor.yy528 = yylhsminor.yy528; |
| 164574 | 165908 | break; |
| 164575 | 165909 | case 185: /* expr ::= VARIABLE */ |
| 164576 | 165910 | { |
| | @@ -166811,11 +168145,14 @@ |
| 166811 | 168145 | }else if( tokenType==TK_FILTER ){ |
| 166812 | 168146 | assert( n==6 ); |
| 166813 | 168147 | tokenType = analyzeFilterKeyword((const u8*)&zSql[6], lastTokenParsed); |
| 166814 | 168148 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 166815 | 168149 | }else{ |
| 166816 | | - sqlite3ErrorMsg(pParse, "unrecognized token: \"%.*s\"", n, zSql); |
| 168150 | + Token x; |
| 168151 | + x.z = zSql; |
| 168152 | + x.n = n; |
| 168153 | + sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"", &x); |
| 166817 | 168154 | break; |
| 166818 | 168155 | } |
| 166819 | 168156 | } |
| 166820 | 168157 | pParse->sLastToken.z = zSql; |
| 166821 | 168158 | pParse->sLastToken.n = n; |
| | @@ -171422,16 +172759,20 @@ |
| 171422 | 172759 | ** is called immediately after installing the new callback and the return |
| 171423 | 172760 | ** value from sqlite3FaultSim(0) becomes the return from |
| 171424 | 172761 | ** sqlite3_test_control(). |
| 171425 | 172762 | */ |
| 171426 | 172763 | case SQLITE_TESTCTRL_FAULT_INSTALL: { |
| 171427 | | - /* MSVC is picky about pulling func ptrs from va lists. |
| 171428 | | - ** http://support.microsoft.com/kb/47961 |
| 172764 | + /* A bug in MSVC prevents it from understanding pointers to functions |
| 172765 | + ** types in the second argument to va_arg(). Work around the problem |
| 172766 | + ** using a typedef. |
| 172767 | + ** http://support.microsoft.com/kb/47961 <-- dead hyperlink |
| 172768 | + ** Search at http://web.archive.org/ to find the 2015-03-16 archive |
| 172769 | + ** of the link above to see the original text. |
| 171429 | 172770 | ** sqlite3GlobalConfig.xTestCallback = va_arg(ap, int(*)(int)); |
| 171430 | 172771 | */ |
| 171431 | | - typedef int(*TESTCALLBACKFUNC_t)(int); |
| 171432 | | - sqlite3GlobalConfig.xTestCallback = va_arg(ap, TESTCALLBACKFUNC_t); |
| 172772 | + typedef int(*sqlite3FaultFuncType)(int); |
| 172773 | + sqlite3GlobalConfig.xTestCallback = va_arg(ap, sqlite3FaultFuncType); |
| 171433 | 172774 | rc = sqlite3FaultSim(0); |
| 171434 | 172775 | break; |
| 171435 | 172776 | } |
| 171436 | 172777 | |
| 171437 | 172778 | /* |
| | @@ -171554,17 +172895,31 @@ |
| 171554 | 172895 | sqlite3 *db = va_arg(ap, sqlite3*); |
| 171555 | 172896 | db->dbOptFlags = va_arg(ap, u32); |
| 171556 | 172897 | break; |
| 171557 | 172898 | } |
| 171558 | 172899 | |
| 171559 | | - /* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, int onoff); |
| 172900 | + /* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, onoff, xAlt); |
| 172901 | + ** |
| 172902 | + ** If parameter onoff is 1, subsequent calls to localtime() fail. |
| 172903 | + ** If 2, then invoke xAlt() instead of localtime(). If 0, normal |
| 172904 | + ** processing. |
| 172905 | + ** |
| 172906 | + ** xAlt arguments are void pointers, but they really want to be: |
| 172907 | + ** |
| 172908 | + ** int xAlt(const time_t*, struct tm*); |
| 171560 | 172909 | ** |
| 171561 | | - ** If parameter onoff is non-zero, subsequent calls to localtime() |
| 171562 | | - ** and its variants fail. If onoff is zero, undo this setting. |
| 172910 | + ** xAlt should write results in to struct tm object of its 2nd argument |
| 172911 | + ** and return zero on success, or return non-zero on failure. |
| 171563 | 172912 | */ |
| 171564 | 172913 | case SQLITE_TESTCTRL_LOCALTIME_FAULT: { |
| 171565 | 172914 | sqlite3GlobalConfig.bLocaltimeFault = va_arg(ap, int); |
| 172915 | + if( sqlite3GlobalConfig.bLocaltimeFault==2 ){ |
| 172916 | + typedef int(*sqlite3LocaltimeType)(const void*,void*); |
| 172917 | + sqlite3GlobalConfig.xAltLocaltime = va_arg(ap, sqlite3LocaltimeType); |
| 172918 | + }else{ |
| 172919 | + sqlite3GlobalConfig.xAltLocaltime = 0; |
| 172920 | + } |
| 171566 | 172921 | break; |
| 171567 | 172922 | } |
| 171568 | 172923 | |
| 171569 | 172924 | /* sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, sqlite3*); |
| 171570 | 172925 | ** |
| | @@ -171762,14 +173117,16 @@ |
| 171762 | 173117 | ** Test access for the LogEst conversion routines. |
| 171763 | 173118 | */ |
| 171764 | 173119 | case SQLITE_TESTCTRL_LOGEST: { |
| 171765 | 173120 | double rIn = va_arg(ap, double); |
| 171766 | 173121 | LogEst rLogEst = sqlite3LogEstFromDouble(rIn); |
| 171767 | | - u64 iInt = sqlite3LogEstToInt(rLogEst); |
| 171768 | | - va_arg(ap, int*)[0] = rLogEst; |
| 171769 | | - va_arg(ap, u64*)[0] = iInt; |
| 171770 | | - va_arg(ap, int*)[0] = sqlite3LogEst(iInt); |
| 173122 | + int *pI1 = va_arg(ap,int*); |
| 173123 | + u64 *pU64 = va_arg(ap,u64*); |
| 173124 | + int *pI2 = va_arg(ap,int*); |
| 173125 | + *pI1 = rLogEst; |
| 173126 | + *pU64 = sqlite3LogEstToInt(rLogEst); |
| 173127 | + *pI2 = sqlite3LogEst(*pU64); |
| 171771 | 173128 | break; |
| 171772 | 173129 | } |
| 171773 | 173130 | |
| 171774 | 173131 | |
| 171775 | 173132 | #if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_WSD) |
| | @@ -193696,11 +195053,11 @@ |
| 193696 | 195053 | u32 iRoot; |
| 193697 | 195054 | JsonNode *pTarget; |
| 193698 | 195055 | if( pPatch->eType!=JSON_OBJECT ){ |
| 193699 | 195056 | return pPatch; |
| 193700 | 195057 | } |
| 193701 | | - assert( iTarget>=0 && iTarget<pParse->nNode ); |
| 195058 | + assert( iTarget<pParse->nNode ); |
| 193702 | 195059 | pTarget = &pParse->aNode[iTarget]; |
| 193703 | 195060 | assert( (pPatch->jnFlags & JNODE_APPEND)==0 ); |
| 193704 | 195061 | if( pTarget->eType!=JSON_OBJECT ){ |
| 193705 | 195062 | jsonRemoveAllNulls(pPatch); |
| 193706 | 195063 | return pPatch; |
| | @@ -193955,12 +195312,12 @@ |
| 193955 | 195312 | sqlite3_result_error_nomem(ctx); |
| 193956 | 195313 | goto jsonSetDone; |
| 193957 | 195314 | }else if( x.nErr ){ |
| 193958 | 195315 | goto jsonSetDone; |
| 193959 | 195316 | }else if( pNode && (bApnd || bIsSet) ){ |
| 193960 | | - testcase( pNode->eU!=0 && pNode->eU!=1 && pNode->eU!=4 ); |
| 193961 | | - assert( pNode->eU!=3 || pNode->eU!=5 ); |
| 195317 | + testcase( pNode->eU!=0 && pNode->eU!=1 ); |
| 195318 | + assert( pNode->eU!=3 && pNode->eU!=5 ); |
| 193962 | 195319 | VVA( pNode->eU = 4 ); |
| 193963 | 195320 | pNode->jnFlags |= (u8)JNODE_REPLACE; |
| 193964 | 195321 | pNode->u.iReplace = i + 1; |
| 193965 | 195322 | } |
| 193966 | 195323 | } |
| | @@ -194737,11 +196094,11 @@ |
| 194737 | 196094 | sqlite3_module *pModule; |
| 194738 | 196095 | } aMod[] = { |
| 194739 | 196096 | { "json_each", &jsonEachModule }, |
| 194740 | 196097 | { "json_tree", &jsonTreeModule }, |
| 194741 | 196098 | }; |
| 194742 | | - int i; |
| 196099 | + unsigned int i; |
| 194743 | 196100 | for(i=0; i<sizeof(aMod)/sizeof(aMod[0]) && rc==SQLITE_OK; i++){ |
| 194744 | 196101 | rc = sqlite3_create_module(db, aMod[i].zName, aMod[i].pModule, 0); |
| 194745 | 196102 | } |
| 194746 | 196103 | return rc; |
| 194747 | 196104 | } |
| | @@ -208991,10 +210348,11 @@ |
| 208991 | 210348 | && pIdxInfo->aOrderBy[0].iColumn<=0 |
| 208992 | 210349 | && pIdxInfo->aOrderBy[0].desc==0 |
| 208993 | 210350 | ){ |
| 208994 | 210351 | pIdxInfo->orderByConsumed = 1; |
| 208995 | 210352 | } |
| 210353 | + sqlite3VtabWriteAll(pIdxInfo); |
| 208996 | 210354 | return SQLITE_OK; |
| 208997 | 210355 | } |
| 208998 | 210356 | |
| 208999 | 210357 | /* |
| 209000 | 210358 | ** Open a new dbpagevfs cursor. |
| | @@ -209168,11 +210526,11 @@ |
| 209168 | 210526 | if( iDb<0 ){ |
| 209169 | 210527 | zErr = "no such schema"; |
| 209170 | 210528 | goto update_fail; |
| 209171 | 210529 | } |
| 209172 | 210530 | pBt = pTab->db->aDb[iDb].pBt; |
| 209173 | | - if( pgno<1 || pBt==0 || pgno>(int)sqlite3BtreeLastPage(pBt) ){ |
| 210531 | + if( pgno<1 || pBt==0 || pgno>sqlite3BtreeLastPage(pBt) ){ |
| 209174 | 210532 | zErr = "bad page number"; |
| 209175 | 210533 | goto update_fail; |
| 209176 | 210534 | } |
| 209177 | 210535 | szPage = sqlite3BtreeGetPageSize(pBt); |
| 209178 | 210536 | if( sqlite3_value_type(argv[3])!=SQLITE_BLOB |
| | @@ -231345,11 +232703,11 @@ |
| 231345 | 232703 | int rc; |
| 231346 | 232704 | |
| 231347 | 232705 | rc = sqlite3_step(pSorter->pStmt); |
| 231348 | 232706 | if( rc==SQLITE_DONE ){ |
| 231349 | 232707 | rc = SQLITE_OK; |
| 231350 | | - CsrFlagSet(pCsr, FTS5CSR_EOF); |
| 232708 | + CsrFlagSet(pCsr, FTS5CSR_EOF|FTS5CSR_REQUIRE_CONTENT); |
| 231351 | 232709 | }else if( rc==SQLITE_ROW ){ |
| 231352 | 232710 | const u8 *a; |
| 231353 | 232711 | const u8 *aBlob; |
| 231354 | 232712 | int nBlob; |
| 231355 | 232713 | int i; |
| | @@ -233334,11 +234692,11 @@ |
| 233334 | 234692 | int nArg, /* Number of args */ |
| 233335 | 234693 | sqlite3_value **apUnused /* Function arguments */ |
| 233336 | 234694 | ){ |
| 233337 | 234695 | assert( nArg==0 ); |
| 233338 | 234696 | UNUSED_PARAM2(nArg, apUnused); |
| 233339 | | - sqlite3_result_text(pCtx, "fts5: 2022-01-12 00:28:12 adebb9d7478d092f16fb0ef7d5246ce152b166479d6f949110b5878b89ea2cec", -1, SQLITE_TRANSIENT); |
| 234697 | + sqlite3_result_text(pCtx, "fts5: 2022-03-14 20:31:57 387ab17b8a0a4b87903aab52abc7da79098b882aff2ab687a554d5794e9d183e", -1, SQLITE_TRANSIENT); |
| 233340 | 234698 | } |
| 233341 | 234699 | |
| 233342 | 234700 | /* |
| 233343 | 234701 | ** Return true if zName is the extension on one of the shadow tables used |
| 233344 | 234702 | ** by this module. |
| 233345 | 234703 | |